]>
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 | ||
c5121837 | 69 | |
1c6edec6 JM |
70 | #ifdef ANDROID |
71 | /* system/core/libnl_2 does not include nl_socket_set_nonblocking() */ | |
1c6edec6 JM |
72 | #undef nl_socket_set_nonblocking |
73 | #define nl_socket_set_nonblocking(h) android_nl_socket_set_nonblocking(h) | |
70a96c81 | 74 | |
1c6edec6 JM |
75 | #endif /* ANDROID */ |
76 | ||
77 | ||
25ebd538 | 78 | static struct nl_sock * nl_create_handle(struct nl_cb *cb, const char *dbg) |
a92dfde8 | 79 | { |
25ebd538 | 80 | struct nl_sock *handle; |
a92dfde8 | 81 | |
25ebd538 | 82 | handle = nl_socket_alloc_cb(cb); |
481234cf | 83 | if (handle == NULL) { |
a92dfde8 JB |
84 | wpa_printf(MSG_ERROR, "nl80211: Failed to allocate netlink " |
85 | "callbacks (%s)", dbg); | |
481234cf | 86 | return NULL; |
a92dfde8 JB |
87 | } |
88 | ||
481234cf | 89 | if (genl_connect(handle)) { |
a92dfde8 JB |
90 | wpa_printf(MSG_ERROR, "nl80211: Failed to connect to generic " |
91 | "netlink (%s)", dbg); | |
25ebd538 | 92 | nl_socket_free(handle); |
481234cf | 93 | return NULL; |
a92dfde8 JB |
94 | } |
95 | ||
481234cf | 96 | return handle; |
a92dfde8 JB |
97 | } |
98 | ||
99 | ||
25ebd538 | 100 | static void nl_destroy_handles(struct nl_sock **handle) |
a92dfde8 | 101 | { |
481234cf | 102 | if (*handle == NULL) |
a92dfde8 | 103 | return; |
25ebd538 | 104 | nl_socket_free(*handle); |
481234cf | 105 | *handle = NULL; |
a92dfde8 JB |
106 | } |
107 | ||
108 | ||
10b85921 JB |
109 | #if __WORDSIZE == 64 |
110 | #define ELOOP_SOCKET_INVALID (intptr_t) 0x8888888888888889ULL | |
111 | #else | |
112 | #define ELOOP_SOCKET_INVALID (intptr_t) 0x88888889ULL | |
113 | #endif | |
114 | ||
25ebd538 | 115 | static void nl80211_register_eloop_read(struct nl_sock **handle, |
5f65e9f7 | 116 | eloop_sock_handler handler, |
40a68f33 | 117 | void *eloop_data, int persist) |
5f65e9f7 | 118 | { |
630b3230 JM |
119 | /* |
120 | * libnl uses a pretty small buffer (32 kB that gets converted to 64 kB) | |
121 | * by default. It is possible to hit that limit in some cases where | |
122 | * operations are blocked, e.g., with a burst of Deauthentication frames | |
123 | * to hostapd and STA entry deletion. Try to increase the buffer to make | |
124 | * this less likely to occur. | |
125 | */ | |
3ea58a05 JM |
126 | int err; |
127 | ||
128 | err = nl_socket_set_buffer_size(*handle, 262144, 0); | |
129 | if (err < 0) { | |
630b3230 JM |
130 | wpa_printf(MSG_DEBUG, |
131 | "nl80211: Could not set nl_socket RX buffer size: %s", | |
3ea58a05 | 132 | nl_geterror(err)); |
630b3230 JM |
133 | /* continue anyway with the default (smaller) buffer */ |
134 | } | |
135 | ||
10b85921 | 136 | nl_socket_set_nonblocking(*handle); |
5f65e9f7 JB |
137 | eloop_register_read_sock(nl_socket_get_fd(*handle), handler, |
138 | eloop_data, *handle); | |
40a68f33 SD |
139 | if (!persist) |
140 | *handle = (void *) (((intptr_t) *handle) ^ | |
141 | ELOOP_SOCKET_INVALID); | |
5f65e9f7 JB |
142 | } |
143 | ||
144 | ||
25ebd538 | 145 | static void nl80211_destroy_eloop_handle(struct nl_sock **handle, int persist) |
5f65e9f7 | 146 | { |
40a68f33 SD |
147 | if (!persist) |
148 | *handle = (void *) (((intptr_t) *handle) ^ | |
149 | ELOOP_SOCKET_INVALID); | |
5f65e9f7 JB |
150 | eloop_unregister_read_sock(nl_socket_get_fd(*handle)); |
151 | nl_destroy_handles(handle); | |
152 | } | |
153 | ||
154 | ||
36d84860 | 155 | static void nl80211_global_deinit(void *priv); |
f51f54a0 | 156 | static void nl80211_check_global(struct nl80211_global *global); |
36d84860 | 157 | |
9ebce9c5 | 158 | static void wpa_driver_nl80211_deinit(struct i802_bss *bss); |
4ec68377 JD |
159 | static int wpa_driver_nl80211_set_mode_ibss(struct i802_bss *bss, |
160 | struct hostapd_freq_params *freq); | |
3c5d34e3 | 161 | |
362f781e | 162 | static int |
0d547d5f | 163 | wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data *drv, |
0ecff8d7 JM |
164 | const u8 *set_addr, int first, |
165 | const char *driver_params); | |
88df0ef7 | 166 | static int nl80211_send_frame_cmd(struct i802_bss *bss, |
5dfca53f | 167 | unsigned int freq, unsigned int wait, |
5ad372cc JM |
168 | const u8 *buf, size_t buf_len, |
169 | int save_cookie, | |
2d3943ce AO |
170 | int no_cck, int no_ack, int offchanok, |
171 | const u16 *csa_offs, size_t csa_offs_len); | |
9ebce9c5 JM |
172 | static int wpa_driver_nl80211_probe_req_report(struct i802_bss *bss, |
173 | int report); | |
0915d02c | 174 | |
732b1d20 MB |
175 | #define IFIDX_ANY -1 |
176 | ||
177 | static void add_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, | |
178 | int ifidx_reason); | |
179 | static void del_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, | |
180 | int ifidx_reason); | |
181 | static int have_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, | |
182 | int ifidx_reason); | |
072ad14c | 183 | |
e87ef751 PX |
184 | static int nl80211_set_channel(struct i802_bss *bss, |
185 | struct hostapd_freq_params *freq, int set_chan); | |
4e5cb1a3 JM |
186 | static int nl80211_disable_11b_rates(struct wpa_driver_nl80211_data *drv, |
187 | int ifindex, int disabled); | |
504e905c | 188 | |
666e508c JM |
189 | static int nl80211_leave_ibss(struct wpa_driver_nl80211_data *drv, |
190 | int reset_mode); | |
21bdbe38 | 191 | |
bf83eab5 | 192 | static int i802_set_iface_flags(struct i802_bss *bss, int up); |
0ecff8d7 | 193 | static int nl80211_set_param(void *priv, const char *param); |
052b8d38 MH |
194 | #ifdef CONFIG_MESH |
195 | static int nl80211_put_mesh_config(struct nl_msg *msg, | |
196 | struct wpa_driver_mesh_bss_params *params); | |
197 | #endif /* CONFIG_MESH */ | |
05e5e615 | 198 | static int i802_sta_disassoc(void *priv, const u8 *own_addr, const u8 *addr, |
4be17ffb | 199 | u16 reason); |
bf83eab5 | 200 | |
3f5285e8 | 201 | |
8d1fdde7 | 202 | /* Converts nl80211_chan_width to a common format */ |
f3407c66 | 203 | enum chan_width convert2width(int width) |
8d1fdde7 JD |
204 | { |
205 | switch (width) { | |
206 | case NL80211_CHAN_WIDTH_20_NOHT: | |
207 | return CHAN_WIDTH_20_NOHT; | |
208 | case NL80211_CHAN_WIDTH_20: | |
209 | return CHAN_WIDTH_20; | |
210 | case NL80211_CHAN_WIDTH_40: | |
211 | return CHAN_WIDTH_40; | |
212 | case NL80211_CHAN_WIDTH_80: | |
213 | return CHAN_WIDTH_80; | |
214 | case NL80211_CHAN_WIDTH_80P80: | |
215 | return CHAN_WIDTH_80P80; | |
216 | case NL80211_CHAN_WIDTH_160: | |
217 | return CHAN_WIDTH_160; | |
218 | } | |
219 | return CHAN_WIDTH_UNKNOWN; | |
220 | } | |
221 | ||
222 | ||
f3407c66 | 223 | int is_ap_interface(enum nl80211_iftype nlmode) |
b1f625e0 | 224 | { |
0e80ea2c JM |
225 | return nlmode == NL80211_IFTYPE_AP || |
226 | nlmode == NL80211_IFTYPE_P2P_GO; | |
b1f625e0 EP |
227 | } |
228 | ||
229 | ||
477af8f8 | 230 | int is_sta_interface(enum nl80211_iftype nlmode) |
b1f625e0 | 231 | { |
0e80ea2c JM |
232 | return nlmode == NL80211_IFTYPE_STATION || |
233 | nlmode == NL80211_IFTYPE_P2P_CLIENT; | |
b1f625e0 EP |
234 | } |
235 | ||
236 | ||
6a71413e | 237 | static int is_p2p_net_interface(enum nl80211_iftype nlmode) |
b3af99d2 | 238 | { |
0e80ea2c JM |
239 | return nlmode == NL80211_IFTYPE_P2P_CLIENT || |
240 | nlmode == NL80211_IFTYPE_P2P_GO; | |
b3af99d2 JM |
241 | } |
242 | ||
243 | ||
f3407c66 JM |
244 | struct i802_bss * get_bss_ifindex(struct wpa_driver_nl80211_data *drv, |
245 | int ifindex) | |
5dfbd725 JM |
246 | { |
247 | struct i802_bss *bss; | |
248 | ||
249 | for (bss = drv->first_bss; bss; bss = bss->next) { | |
250 | if (bss->ifindex == ifindex) | |
251 | return bss; | |
252 | } | |
253 | ||
254 | return NULL; | |
255 | } | |
256 | ||
257 | ||
afb0550a BC |
258 | static int is_mesh_interface(enum nl80211_iftype nlmode) |
259 | { | |
260 | return nlmode == NL80211_IFTYPE_MESH_POINT; | |
261 | } | |
262 | ||
263 | ||
f3407c66 | 264 | void nl80211_mark_disconnected(struct wpa_driver_nl80211_data *drv) |
add9b7a4 JM |
265 | { |
266 | if (drv->associated) | |
267 | os_memcpy(drv->prev_bssid, drv->bssid, ETH_ALEN); | |
268 | drv->associated = 0; | |
269 | os_memset(drv->bssid, 0, ETH_ALEN); | |
091c2277 | 270 | drv->first_bss->freq = 0; |
add9b7a4 JM |
271 | } |
272 | ||
273 | ||
6241fcb1 JM |
274 | /* nl80211 code */ |
275 | static int ack_handler(struct nl_msg *msg, void *arg) | |
276 | { | |
277 | int *err = arg; | |
278 | *err = 0; | |
279 | return NL_STOP; | |
280 | } | |
281 | ||
282 | static int finish_handler(struct nl_msg *msg, void *arg) | |
283 | { | |
8e8df255 JM |
284 | int *ret = arg; |
285 | *ret = 0; | |
6241fcb1 JM |
286 | return NL_SKIP; |
287 | } | |
288 | ||
289 | static int error_handler(struct sockaddr_nl *nla, struct nlmsgerr *err, | |
290 | void *arg) | |
291 | { | |
40432e6e JB |
292 | struct nlmsghdr *nlh = (struct nlmsghdr *) err - 1; |
293 | int len = nlh->nlmsg_len; | |
294 | struct nlattr *attrs; | |
295 | struct nlattr *tb[NLMSGERR_ATTR_MAX + 1]; | |
6241fcb1 | 296 | int *ret = arg; |
40432e6e JB |
297 | int ack_len = sizeof(*nlh) + sizeof(int) + sizeof(*nlh); |
298 | ||
6241fcb1 | 299 | *ret = err->error; |
40432e6e JB |
300 | |
301 | if (!(nlh->nlmsg_flags & NLM_F_ACK_TLVS)) | |
302 | return NL_SKIP; | |
303 | ||
304 | if (!(nlh->nlmsg_flags & NLM_F_CAPPED)) | |
305 | ack_len += err->msg.nlmsg_len - sizeof(*nlh); | |
306 | ||
307 | if (len <= ack_len) | |
308 | return NL_STOP; | |
309 | ||
310 | attrs = (void *) ((unsigned char *) nlh + ack_len); | |
311 | len -= ack_len; | |
312 | ||
313 | nla_parse(tb, NLMSGERR_ATTR_MAX, attrs, len, NULL); | |
314 | if (tb[NLMSGERR_ATTR_MSG]) { | |
315 | len = strnlen((char *) nla_data(tb[NLMSGERR_ATTR_MSG]), | |
316 | nla_len(tb[NLMSGERR_ATTR_MSG])); | |
317 | wpa_printf(MSG_ERROR, "nl80211: kernel reports: %*s", | |
318 | len, (char *) nla_data(tb[NLMSGERR_ATTR_MSG])); | |
319 | } | |
320 | ||
6241fcb1 JM |
321 | return NL_SKIP; |
322 | } | |
323 | ||
5b7b85f6 JM |
324 | |
325 | static int no_seq_check(struct nl_msg *msg, void *arg) | |
326 | { | |
327 | return NL_OK; | |
328 | } | |
329 | ||
330 | ||
bbd89bfc JM |
331 | static void nl80211_nlmsg_clear(struct nl_msg *msg) |
332 | { | |
333 | /* | |
334 | * Clear nlmsg data, e.g., to make sure key material is not left in | |
335 | * heap memory for unnecessarily long time. | |
336 | */ | |
337 | if (msg) { | |
338 | struct nlmsghdr *hdr = nlmsg_hdr(msg); | |
339 | void *data = nlmsg_data(hdr); | |
d58ade21 JM |
340 | /* |
341 | * This would use nlmsg_datalen() or the older nlmsg_len() if | |
342 | * only libnl were to maintain a stable API.. Neither will work | |
343 | * with all released versions, so just calculate the length | |
344 | * here. | |
345 | */ | |
346 | int len = hdr->nlmsg_len - NLMSG_HDRLEN; | |
bbd89bfc JM |
347 | |
348 | os_memset(data, 0, len); | |
349 | } | |
350 | } | |
351 | ||
352 | ||
d6c9aab8 | 353 | static int send_and_recv(struct nl80211_global *global, |
25ebd538 | 354 | struct nl_sock *nl_handle, struct nl_msg *msg, |
58f6fbe0 JM |
355 | int (*valid_handler)(struct nl_msg *, void *), |
356 | void *valid_data) | |
6241fcb1 JM |
357 | { |
358 | struct nl_cb *cb; | |
40432e6e | 359 | int err = -ENOMEM, opt; |
6241fcb1 | 360 | |
9725b784 JM |
361 | if (!msg) |
362 | return -ENOMEM; | |
363 | ||
d6c9aab8 | 364 | cb = nl_cb_clone(global->nl_cb); |
6241fcb1 JM |
365 | if (!cb) |
366 | goto out; | |
367 | ||
40432e6e JB |
368 | /* try to set NETLINK_EXT_ACK to 1, ignoring errors */ |
369 | opt = 1; | |
370 | setsockopt(nl_socket_get_fd(nl_handle), SOL_NETLINK, | |
371 | NETLINK_EXT_ACK, &opt, sizeof(opt)); | |
372 | ||
b14e8ea1 JM |
373 | /* try to set NETLINK_CAP_ACK to 1, ignoring errors */ |
374 | opt = 1; | |
375 | setsockopt(nl_socket_get_fd(nl_handle), SOL_NETLINK, | |
376 | NETLINK_CAP_ACK, &opt, sizeof(opt)); | |
377 | ||
58f6fbe0 | 378 | err = nl_send_auto_complete(nl_handle, msg); |
3ea58a05 JM |
379 | if (err < 0) { |
380 | wpa_printf(MSG_INFO, | |
381 | "nl80211: nl_send_auto_complete() failed: %s", | |
382 | nl_geterror(err)); | |
383 | /* Need to convert libnl error code to an errno value. For now, | |
384 | * just hardcode this to EBADF; the real error reason is shown | |
385 | * in that error print above. */ | |
386 | err = -EBADF; | |
6241fcb1 | 387 | goto out; |
3ea58a05 | 388 | } |
6241fcb1 JM |
389 | |
390 | err = 1; | |
391 | ||
392 | nl_cb_err(cb, NL_CB_CUSTOM, error_handler, &err); | |
8e8df255 | 393 | nl_cb_set(cb, NL_CB_FINISH, NL_CB_CUSTOM, finish_handler, &err); |
6241fcb1 JM |
394 | nl_cb_set(cb, NL_CB_ACK, NL_CB_CUSTOM, ack_handler, &err); |
395 | ||
396 | if (valid_handler) | |
397 | nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, | |
398 | valid_handler, valid_data); | |
399 | ||
34068ac3 JM |
400 | while (err > 0) { |
401 | int res = nl_recvmsgs(nl_handle, cb); | |
16a26672 JM |
402 | |
403 | if (res == -NLE_DUMP_INTR) { | |
404 | /* Most likely one of the nl80211 dump routines hit a | |
405 | * case where internal results changed while the dump | |
406 | * was being sent. The most common known case for this | |
407 | * is scan results fetching while associated were every | |
408 | * received Beacon frame from the AP may end up | |
409 | * incrementing bss_generation. This | |
410 | * NL80211_CMD_GET_SCAN case tries again in the caller; | |
411 | * other cases (of which there are no known common ones) | |
412 | * will stop and return an error. */ | |
413 | wpa_printf(MSG_DEBUG, "nl80211: %s; convert to -EAGAIN", | |
414 | nl_geterror(res)); | |
415 | err = -EAGAIN; | |
416 | } else if (res < 0) { | |
34068ac3 | 417 | wpa_printf(MSG_INFO, |
3ea58a05 JM |
418 | "nl80211: %s->nl_recvmsgs failed: %d (%s)", |
419 | __func__, res, nl_geterror(res)); | |
34068ac3 JM |
420 | } |
421 | } | |
6241fcb1 JM |
422 | out: |
423 | nl_cb_put(cb); | |
bbd89bfc JM |
424 | if (!valid_handler && valid_data == (void *) -1) |
425 | nl80211_nlmsg_clear(msg); | |
6241fcb1 JM |
426 | nlmsg_free(msg); |
427 | return err; | |
428 | } | |
429 | ||
430 | ||
f3407c66 JM |
431 | int send_and_recv_msgs(struct wpa_driver_nl80211_data *drv, |
432 | struct nl_msg *msg, | |
433 | int (*valid_handler)(struct nl_msg *, void *), | |
434 | void *valid_data) | |
58f6fbe0 | 435 | { |
481234cf | 436 | return send_and_recv(drv->global, drv->global->nl, msg, |
d6c9aab8 | 437 | valid_handler, valid_data); |
58f6fbe0 JM |
438 | } |
439 | ||
440 | ||
97865538 JM |
441 | struct family_data { |
442 | const char *group; | |
443 | int id; | |
444 | }; | |
445 | ||
446 | ||
447 | static int family_handler(struct nl_msg *msg, void *arg) | |
448 | { | |
449 | struct family_data *res = arg; | |
450 | struct nlattr *tb[CTRL_ATTR_MAX + 1]; | |
451 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
452 | struct nlattr *mcgrp; | |
453 | int i; | |
454 | ||
455 | nla_parse(tb, CTRL_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
456 | genlmsg_attrlen(gnlh, 0), NULL); | |
457 | if (!tb[CTRL_ATTR_MCAST_GROUPS]) | |
458 | return NL_SKIP; | |
459 | ||
460 | nla_for_each_nested(mcgrp, tb[CTRL_ATTR_MCAST_GROUPS], i) { | |
461 | struct nlattr *tb2[CTRL_ATTR_MCAST_GRP_MAX + 1]; | |
462 | nla_parse(tb2, CTRL_ATTR_MCAST_GRP_MAX, nla_data(mcgrp), | |
463 | nla_len(mcgrp), NULL); | |
464 | if (!tb2[CTRL_ATTR_MCAST_GRP_NAME] || | |
465 | !tb2[CTRL_ATTR_MCAST_GRP_ID] || | |
466 | os_strncmp(nla_data(tb2[CTRL_ATTR_MCAST_GRP_NAME]), | |
467 | res->group, | |
468 | nla_len(tb2[CTRL_ATTR_MCAST_GRP_NAME])) != 0) | |
469 | continue; | |
470 | res->id = nla_get_u32(tb2[CTRL_ATTR_MCAST_GRP_ID]); | |
471 | break; | |
472 | }; | |
473 | ||
474 | return NL_SKIP; | |
475 | } | |
476 | ||
477 | ||
d6c9aab8 | 478 | static int nl_get_multicast_id(struct nl80211_global *global, |
97865538 JM |
479 | const char *family, const char *group) |
480 | { | |
481 | struct nl_msg *msg; | |
a862e4a3 | 482 | int ret; |
97865538 JM |
483 | struct family_data res = { group, -ENOENT }; |
484 | ||
485 | msg = nlmsg_alloc(); | |
486 | if (!msg) | |
487 | return -ENOMEM; | |
a862e4a3 JM |
488 | if (!genlmsg_put(msg, 0, 0, genl_ctrl_resolve(global->nl, "nlctrl"), |
489 | 0, 0, CTRL_CMD_GETFAMILY, 0) || | |
490 | nla_put_string(msg, CTRL_ATTR_FAMILY_NAME, family)) { | |
491 | nlmsg_free(msg); | |
492 | return -1; | |
493 | } | |
97865538 | 494 | |
1033315f | 495 | ret = send_and_recv(global, global->nl, msg, family_handler, &res); |
97865538 JM |
496 | if (ret == 0) |
497 | ret = res.id; | |
97865538 JM |
498 | return ret; |
499 | } | |
500 | ||
501 | ||
f3407c66 JM |
502 | void * nl80211_cmd(struct wpa_driver_nl80211_data *drv, |
503 | struct nl_msg *msg, int flags, uint8_t cmd) | |
9fb04070 | 504 | { |
a5a187b0 JM |
505 | if (TEST_FAIL()) |
506 | return NULL; | |
335d42b1 | 507 | return genlmsg_put(msg, 0, 0, drv->global->nl80211_id, |
276e2d67 | 508 | 0, flags, cmd, 0); |
9fb04070 JM |
509 | } |
510 | ||
511 | ||
350acc35 JM |
512 | static int nl80211_set_iface_id(struct nl_msg *msg, struct i802_bss *bss) |
513 | { | |
514 | if (bss->wdev_id_set) | |
515 | return nla_put_u64(msg, NL80211_ATTR_WDEV, bss->wdev_id); | |
516 | return nla_put_u32(msg, NL80211_ATTR_IFINDEX, bss->ifindex); | |
517 | } | |
518 | ||
519 | ||
07c7757c JM |
520 | struct nl_msg * nl80211_cmd_msg(struct i802_bss *bss, int flags, uint8_t cmd) |
521 | { | |
522 | struct nl_msg *msg; | |
523 | ||
524 | msg = nlmsg_alloc(); | |
525 | if (!msg) | |
526 | return NULL; | |
527 | ||
528 | if (!nl80211_cmd(bss->drv, msg, flags, cmd) || | |
529 | nl80211_set_iface_id(msg, bss) < 0) { | |
530 | nlmsg_free(msg); | |
531 | return NULL; | |
532 | } | |
533 | ||
534 | return msg; | |
535 | } | |
536 | ||
537 | ||
538 | static struct nl_msg * | |
539 | nl80211_ifindex_msg(struct wpa_driver_nl80211_data *drv, int ifindex, | |
540 | int flags, uint8_t cmd) | |
541 | { | |
542 | struct nl_msg *msg; | |
543 | ||
544 | msg = nlmsg_alloc(); | |
545 | if (!msg) | |
546 | return NULL; | |
547 | ||
548 | if (!nl80211_cmd(drv, msg, flags, cmd) || | |
549 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex)) { | |
550 | nlmsg_free(msg); | |
551 | return NULL; | |
552 | } | |
553 | ||
554 | return msg; | |
555 | } | |
556 | ||
557 | ||
558 | struct nl_msg * nl80211_drv_msg(struct wpa_driver_nl80211_data *drv, int flags, | |
559 | uint8_t cmd) | |
560 | { | |
561 | return nl80211_ifindex_msg(drv, drv->ifindex, flags, cmd); | |
562 | } | |
563 | ||
564 | ||
565 | struct nl_msg * nl80211_bss_msg(struct i802_bss *bss, int flags, uint8_t cmd) | |
566 | { | |
567 | return nl80211_ifindex_msg(bss->drv, bss->ifindex, flags, cmd); | |
568 | } | |
569 | ||
570 | ||
e32ad281 JB |
571 | struct wiphy_idx_data { |
572 | int wiphy_idx; | |
01517c8b | 573 | enum nl80211_iftype nlmode; |
597b94f5 | 574 | u8 *macaddr; |
e32ad281 JB |
575 | }; |
576 | ||
577 | ||
578 | static int netdev_info_handler(struct nl_msg *msg, void *arg) | |
579 | { | |
580 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
581 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
582 | struct wiphy_idx_data *info = arg; | |
583 | ||
584 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
585 | genlmsg_attrlen(gnlh, 0), NULL); | |
586 | ||
587 | if (tb[NL80211_ATTR_WIPHY]) | |
588 | info->wiphy_idx = nla_get_u32(tb[NL80211_ATTR_WIPHY]); | |
589 | ||
01517c8b JB |
590 | if (tb[NL80211_ATTR_IFTYPE]) |
591 | info->nlmode = nla_get_u32(tb[NL80211_ATTR_IFTYPE]); | |
592 | ||
597b94f5 AS |
593 | if (tb[NL80211_ATTR_MAC] && info->macaddr) |
594 | os_memcpy(info->macaddr, nla_data(tb[NL80211_ATTR_MAC]), | |
595 | ETH_ALEN); | |
596 | ||
e32ad281 JB |
597 | return NL_SKIP; |
598 | } | |
599 | ||
600 | ||
f3407c66 | 601 | int nl80211_get_wiphy_index(struct i802_bss *bss) |
e32ad281 JB |
602 | { |
603 | struct nl_msg *msg; | |
604 | struct wiphy_idx_data data = { | |
605 | .wiphy_idx = -1, | |
597b94f5 | 606 | .macaddr = NULL, |
e32ad281 JB |
607 | }; |
608 | ||
56f77852 | 609 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_GET_INTERFACE))) |
a862e4a3 | 610 | return -1; |
e32ad281 JB |
611 | |
612 | if (send_and_recv_msgs(bss->drv, msg, netdev_info_handler, &data) == 0) | |
613 | return data.wiphy_idx; | |
e32ad281 JB |
614 | return -1; |
615 | } | |
616 | ||
617 | ||
01517c8b JB |
618 | static enum nl80211_iftype nl80211_get_ifmode(struct i802_bss *bss) |
619 | { | |
620 | struct nl_msg *msg; | |
621 | struct wiphy_idx_data data = { | |
597b94f5 AS |
622 | .nlmode = NL80211_IFTYPE_UNSPECIFIED, |
623 | .macaddr = NULL, | |
01517c8b JB |
624 | }; |
625 | ||
56f77852 | 626 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_GET_INTERFACE))) |
a862e4a3 | 627 | return NL80211_IFTYPE_UNSPECIFIED; |
01517c8b JB |
628 | |
629 | if (send_and_recv_msgs(bss->drv, msg, netdev_info_handler, &data) == 0) | |
630 | return data.nlmode; | |
01517c8b JB |
631 | return NL80211_IFTYPE_UNSPECIFIED; |
632 | } | |
01517c8b JB |
633 | |
634 | ||
597b94f5 AS |
635 | static int nl80211_get_macaddr(struct i802_bss *bss) |
636 | { | |
637 | struct nl_msg *msg; | |
638 | struct wiphy_idx_data data = { | |
639 | .macaddr = bss->addr, | |
640 | }; | |
641 | ||
56f77852 | 642 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_GET_INTERFACE))) |
a862e4a3 | 643 | return -1; |
597b94f5 | 644 | |
597b94f5 | 645 | return send_and_recv_msgs(bss->drv, msg, netdev_info_handler, &data); |
597b94f5 | 646 | } |
597b94f5 AS |
647 | |
648 | ||
e32ad281 JB |
649 | static int nl80211_register_beacons(struct wpa_driver_nl80211_data *drv, |
650 | struct nl80211_wiphy_data *w) | |
651 | { | |
652 | struct nl_msg *msg; | |
a862e4a3 | 653 | int ret; |
e32ad281 JB |
654 | |
655 | msg = nlmsg_alloc(); | |
656 | if (!msg) | |
657 | return -1; | |
658 | ||
a862e4a3 JM |
659 | if (!nl80211_cmd(drv, msg, 0, NL80211_CMD_REGISTER_BEACONS) || |
660 | nla_put_u32(msg, NL80211_ATTR_WIPHY, w->wiphy_idx)) { | |
661 | nlmsg_free(msg); | |
662 | return -1; | |
663 | } | |
e32ad281 | 664 | |
481234cf | 665 | ret = send_and_recv(drv->global, w->nl_beacons, msg, NULL, NULL); |
e32ad281 JB |
666 | if (ret) { |
667 | wpa_printf(MSG_DEBUG, "nl80211: Register beacons command " | |
668 | "failed: ret=%d (%s)", | |
669 | ret, strerror(-ret)); | |
e32ad281 | 670 | } |
e32ad281 JB |
671 | return ret; |
672 | } | |
673 | ||
674 | ||
675 | static void nl80211_recv_beacons(int sock, void *eloop_ctx, void *handle) | |
676 | { | |
677 | struct nl80211_wiphy_data *w = eloop_ctx; | |
34068ac3 | 678 | int res; |
e32ad281 | 679 | |
ee9fc67a | 680 | wpa_printf(MSG_EXCESSIVE, "nl80211: Beacon event message available"); |
e32ad281 | 681 | |
34068ac3 | 682 | res = nl_recvmsgs(handle, w->nl_cb); |
d3d04831 | 683 | if (res < 0) { |
34068ac3 JM |
684 | wpa_printf(MSG_INFO, "nl80211: %s->nl_recvmsgs failed: %d", |
685 | __func__, res); | |
686 | } | |
e32ad281 JB |
687 | } |
688 | ||
689 | ||
690 | static int process_beacon_event(struct nl_msg *msg, void *arg) | |
691 | { | |
692 | struct nl80211_wiphy_data *w = arg; | |
693 | struct wpa_driver_nl80211_data *drv; | |
694 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
695 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
696 | union wpa_event_data event; | |
697 | ||
698 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
699 | genlmsg_attrlen(gnlh, 0), NULL); | |
700 | ||
701 | if (gnlh->cmd != NL80211_CMD_FRAME) { | |
702 | wpa_printf(MSG_DEBUG, "nl80211: Unexpected beacon event? (%d)", | |
703 | gnlh->cmd); | |
704 | return NL_SKIP; | |
705 | } | |
706 | ||
707 | if (!tb[NL80211_ATTR_FRAME]) | |
708 | return NL_SKIP; | |
709 | ||
710 | dl_list_for_each(drv, &w->drvs, struct wpa_driver_nl80211_data, | |
711 | wiphy_list) { | |
712 | os_memset(&event, 0, sizeof(event)); | |
713 | event.rx_mgmt.frame = nla_data(tb[NL80211_ATTR_FRAME]); | |
714 | event.rx_mgmt.frame_len = nla_len(tb[NL80211_ATTR_FRAME]); | |
715 | wpa_supplicant_event(drv->ctx, EVENT_RX_MGMT, &event); | |
716 | } | |
717 | ||
718 | return NL_SKIP; | |
719 | } | |
720 | ||
721 | ||
722 | static struct nl80211_wiphy_data * | |
723 | nl80211_get_wiphy_data_ap(struct i802_bss *bss) | |
724 | { | |
725 | static DEFINE_DL_LIST(nl80211_wiphys); | |
726 | struct nl80211_wiphy_data *w; | |
727 | int wiphy_idx, found = 0; | |
728 | struct i802_bss *tmp_bss; | |
a70cd0db | 729 | u8 channel; |
e32ad281 JB |
730 | |
731 | if (bss->wiphy_data != NULL) | |
732 | return bss->wiphy_data; | |
733 | ||
734 | wiphy_idx = nl80211_get_wiphy_index(bss); | |
735 | ||
736 | dl_list_for_each(w, &nl80211_wiphys, struct nl80211_wiphy_data, list) { | |
737 | if (w->wiphy_idx == wiphy_idx) | |
738 | goto add; | |
739 | } | |
740 | ||
741 | /* alloc new one */ | |
742 | w = os_zalloc(sizeof(*w)); | |
743 | if (w == NULL) | |
744 | return NULL; | |
745 | w->wiphy_idx = wiphy_idx; | |
746 | dl_list_init(&w->bsss); | |
747 | dl_list_init(&w->drvs); | |
748 | ||
a70cd0db DL |
749 | /* Beacon frames not supported in IEEE 802.11ad */ |
750 | if (ieee80211_freq_to_chan(bss->freq, &channel) != | |
751 | HOSTAPD_MODE_IEEE80211AD) { | |
752 | w->nl_cb = nl_cb_alloc(NL_CB_DEFAULT); | |
753 | if (!w->nl_cb) { | |
754 | os_free(w); | |
755 | return NULL; | |
756 | } | |
757 | nl_cb_set(w->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, | |
758 | no_seq_check, NULL); | |
759 | nl_cb_set(w->nl_cb, NL_CB_VALID, NL_CB_CUSTOM, | |
760 | process_beacon_event, w); | |
761 | ||
762 | w->nl_beacons = nl_create_handle(bss->drv->global->nl_cb, | |
763 | "wiphy beacons"); | |
764 | if (w->nl_beacons == NULL) { | |
765 | os_free(w); | |
766 | return NULL; | |
767 | } | |
e32ad281 | 768 | |
a70cd0db DL |
769 | if (nl80211_register_beacons(bss->drv, w)) { |
770 | nl_destroy_handles(&w->nl_beacons); | |
771 | os_free(w); | |
772 | return NULL; | |
773 | } | |
e32ad281 | 774 | |
a70cd0db | 775 | nl80211_register_eloop_read(&w->nl_beacons, |
40a68f33 | 776 | nl80211_recv_beacons, w, 0); |
e32ad281 JB |
777 | } |
778 | ||
e32ad281 JB |
779 | dl_list_add(&nl80211_wiphys, &w->list); |
780 | ||
781 | add: | |
782 | /* drv entry for this bss already there? */ | |
783 | dl_list_for_each(tmp_bss, &w->bsss, struct i802_bss, wiphy_list) { | |
784 | if (tmp_bss->drv == bss->drv) { | |
785 | found = 1; | |
786 | break; | |
787 | } | |
788 | } | |
789 | /* if not add it */ | |
790 | if (!found) | |
791 | dl_list_add(&w->drvs, &bss->drv->wiphy_list); | |
792 | ||
793 | dl_list_add(&w->bsss, &bss->wiphy_list); | |
794 | bss->wiphy_data = w; | |
795 | return w; | |
796 | } | |
797 | ||
798 | ||
799 | static void nl80211_put_wiphy_data_ap(struct i802_bss *bss) | |
800 | { | |
801 | struct nl80211_wiphy_data *w = bss->wiphy_data; | |
802 | struct i802_bss *tmp_bss; | |
803 | int found = 0; | |
804 | ||
805 | if (w == NULL) | |
806 | return; | |
807 | bss->wiphy_data = NULL; | |
808 | dl_list_del(&bss->wiphy_list); | |
809 | ||
810 | /* still any for this drv present? */ | |
811 | dl_list_for_each(tmp_bss, &w->bsss, struct i802_bss, wiphy_list) { | |
812 | if (tmp_bss->drv == bss->drv) { | |
813 | found = 1; | |
814 | break; | |
815 | } | |
816 | } | |
817 | /* if not remove it */ | |
818 | if (!found) | |
819 | dl_list_del(&bss->drv->wiphy_list); | |
820 | ||
821 | if (!dl_list_empty(&w->bsss)) | |
822 | return; | |
823 | ||
a70cd0db | 824 | if (w->nl_beacons) |
40a68f33 | 825 | nl80211_destroy_eloop_handle(&w->nl_beacons, 0); |
e32ad281 JB |
826 | |
827 | nl_cb_put(w->nl_cb); | |
e32ad281 JB |
828 | dl_list_del(&w->list); |
829 | os_free(w); | |
830 | } | |
831 | ||
832 | ||
45e3fc72 RM |
833 | static unsigned int nl80211_get_ifindex(void *priv) |
834 | { | |
835 | struct i802_bss *bss = priv; | |
836 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
837 | ||
838 | return drv->ifindex; | |
839 | } | |
840 | ||
841 | ||
3f5285e8 JM |
842 | static int wpa_driver_nl80211_get_bssid(void *priv, u8 *bssid) |
843 | { | |
a2e40bb6 FF |
844 | struct i802_bss *bss = priv; |
845 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
c2a04078 JM |
846 | if (!drv->associated) |
847 | return -1; | |
848 | os_memcpy(bssid, drv->bssid, ETH_ALEN); | |
849 | return 0; | |
3f5285e8 JM |
850 | } |
851 | ||
852 | ||
3f5285e8 JM |
853 | static int wpa_driver_nl80211_get_ssid(void *priv, u8 *ssid) |
854 | { | |
a2e40bb6 FF |
855 | struct i802_bss *bss = priv; |
856 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
fd05d64e JM |
857 | if (!drv->associated) |
858 | return -1; | |
859 | os_memcpy(ssid, drv->ssid, drv->ssid_len); | |
860 | return drv->ssid_len; | |
3f5285e8 JM |
861 | } |
862 | ||
863 | ||
90a545cc | 864 | static void wpa_driver_nl80211_event_newlink( |
45e3fc72 RM |
865 | struct nl80211_global *global, struct wpa_driver_nl80211_data *drv, |
866 | int ifindex, const char *ifname) | |
3f5285e8 JM |
867 | { |
868 | union wpa_event_data event; | |
869 | ||
45e3fc72 | 870 | if (drv && os_strcmp(drv->first_bss->ifname, ifname) == 0) { |
90a545cc JM |
871 | if (if_nametoindex(drv->first_bss->ifname) == 0) { |
872 | wpa_printf(MSG_DEBUG, "nl80211: Interface %s does not exist - ignore RTM_NEWLINK", | |
873 | drv->first_bss->ifname); | |
874 | return; | |
875 | } | |
876 | if (!drv->if_removed) | |
877 | return; | |
878 | wpa_printf(MSG_DEBUG, "nl80211: Mark if_removed=0 for %s based on RTM_NEWLINK event", | |
879 | drv->first_bss->ifname); | |
880 | drv->if_removed = 0; | |
881 | } | |
882 | ||
3f5285e8 | 883 | os_memset(&event, 0, sizeof(event)); |
45e3fc72 | 884 | event.interface_status.ifindex = ifindex; |
90a545cc JM |
885 | os_strlcpy(event.interface_status.ifname, ifname, |
886 | sizeof(event.interface_status.ifname)); | |
887 | event.interface_status.ievent = EVENT_INTERFACE_ADDED; | |
45e3fc72 RM |
888 | if (drv) |
889 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_STATUS, &event); | |
890 | else | |
891 | wpa_supplicant_event_global(global->ctx, EVENT_INTERFACE_STATUS, | |
892 | &event); | |
90a545cc JM |
893 | } |
894 | ||
895 | ||
896 | static void wpa_driver_nl80211_event_dellink( | |
45e3fc72 RM |
897 | struct nl80211_global *global, struct wpa_driver_nl80211_data *drv, |
898 | int ifindex, const char *ifname) | |
90a545cc JM |
899 | { |
900 | union wpa_event_data event; | |
901 | ||
45e3fc72 | 902 | if (drv && os_strcmp(drv->first_bss->ifname, ifname) == 0) { |
90a545cc JM |
903 | if (drv->if_removed) { |
904 | wpa_printf(MSG_DEBUG, "nl80211: if_removed already set - ignore RTM_DELLINK event for %s", | |
905 | ifname); | |
906 | return; | |
d1f4942b | 907 | } |
90a545cc JM |
908 | wpa_printf(MSG_DEBUG, "RTM_DELLINK: Interface '%s' removed - mark if_removed=1", |
909 | ifname); | |
910 | drv->if_removed = 1; | |
911 | } else { | |
912 | wpa_printf(MSG_DEBUG, "RTM_DELLINK: Interface '%s' removed", | |
913 | ifname); | |
7524cfb1 JM |
914 | } |
915 | ||
90a545cc | 916 | os_memset(&event, 0, sizeof(event)); |
45e3fc72 | 917 | event.interface_status.ifindex = ifindex; |
90a545cc JM |
918 | os_strlcpy(event.interface_status.ifname, ifname, |
919 | sizeof(event.interface_status.ifname)); | |
920 | event.interface_status.ievent = EVENT_INTERFACE_REMOVED; | |
45e3fc72 RM |
921 | if (drv) |
922 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_STATUS, &event); | |
923 | else | |
924 | wpa_supplicant_event_global(global->ctx, EVENT_INTERFACE_STATUS, | |
925 | &event); | |
3f5285e8 JM |
926 | } |
927 | ||
928 | ||
7524cfb1 | 929 | static int wpa_driver_nl80211_own_ifname(struct wpa_driver_nl80211_data *drv, |
62d680c3 | 930 | u8 *buf, size_t len) |
7524cfb1 | 931 | { |
62d680c3 | 932 | int attrlen, rta_len; |
7524cfb1 JM |
933 | struct rtattr *attr; |
934 | ||
62d680c3 JM |
935 | attrlen = len; |
936 | attr = (struct rtattr *) buf; | |
7524cfb1 JM |
937 | |
938 | rta_len = RTA_ALIGN(sizeof(struct rtattr)); | |
939 | while (RTA_OK(attr, attrlen)) { | |
940 | if (attr->rta_type == IFLA_IFNAME) { | |
834ee56f KP |
941 | if (os_strcmp(((char *) attr) + rta_len, |
942 | drv->first_bss->ifname) == 0) | |
7524cfb1 JM |
943 | return 1; |
944 | else | |
945 | break; | |
946 | } | |
947 | attr = RTA_NEXT(attr, attrlen); | |
948 | } | |
949 | ||
950 | return 0; | |
951 | } | |
952 | ||
953 | ||
954 | static int wpa_driver_nl80211_own_ifindex(struct wpa_driver_nl80211_data *drv, | |
62d680c3 | 955 | int ifindex, u8 *buf, size_t len) |
7524cfb1 JM |
956 | { |
957 | if (drv->ifindex == ifindex) | |
958 | return 1; | |
959 | ||
62d680c3 | 960 | if (drv->if_removed && wpa_driver_nl80211_own_ifname(drv, buf, len)) { |
f51f54a0 | 961 | nl80211_check_global(drv->global); |
7524cfb1 JM |
962 | wpa_printf(MSG_DEBUG, "nl80211: Update ifindex for a removed " |
963 | "interface"); | |
5e0c20ff JM |
964 | if (wpa_driver_nl80211_finish_drv_init(drv, NULL, 0, NULL) < 0) |
965 | return -1; | |
7524cfb1 JM |
966 | return 1; |
967 | } | |
968 | ||
969 | return 0; | |
970 | } | |
971 | ||
972 | ||
36d84860 | 973 | static struct wpa_driver_nl80211_data * |
5e0c20ff JM |
974 | nl80211_find_drv(struct nl80211_global *global, int idx, u8 *buf, size_t len, |
975 | int *init_failed) | |
36d84860 BG |
976 | { |
977 | struct wpa_driver_nl80211_data *drv; | |
5e0c20ff JM |
978 | int res; |
979 | ||
980 | if (init_failed) | |
981 | *init_failed = 0; | |
36d84860 BG |
982 | dl_list_for_each(drv, &global->interfaces, |
983 | struct wpa_driver_nl80211_data, list) { | |
5e0c20ff JM |
984 | res = wpa_driver_nl80211_own_ifindex(drv, idx, buf, len); |
985 | if (res < 0) { | |
986 | wpa_printf(MSG_DEBUG, | |
987 | "nl80211: Found matching own interface, but failed to complete reinitialization"); | |
988 | if (init_failed) | |
989 | *init_failed = 1; | |
990 | return drv; | |
991 | } | |
992 | if (res > 0 || have_ifidx(drv, idx, IFIDX_ANY)) | |
36d84860 BG |
993 | return drv; |
994 | } | |
995 | return NULL; | |
996 | } | |
997 | ||
998 | ||
290834df | 999 | static void nl80211_refresh_mac(struct wpa_driver_nl80211_data *drv, |
77a020a1 | 1000 | int ifindex, int notify) |
290834df BG |
1001 | { |
1002 | struct i802_bss *bss; | |
1003 | u8 addr[ETH_ALEN]; | |
1004 | ||
1005 | bss = get_bss_ifindex(drv, ifindex); | |
1006 | if (bss && | |
1007 | linux_get_ifhwaddr(drv->global->ioctl_sock, | |
1008 | bss->ifname, addr) < 0) { | |
1009 | wpa_printf(MSG_DEBUG, | |
1010 | "nl80211: %s: failed to re-read MAC address", | |
1011 | bss->ifname); | |
1012 | } else if (bss && os_memcmp(addr, bss->addr, ETH_ALEN) != 0) { | |
1013 | wpa_printf(MSG_DEBUG, | |
1014 | "nl80211: Own MAC address on ifindex %d (%s) changed from " | |
1015 | MACSTR " to " MACSTR, | |
1016 | ifindex, bss->ifname, | |
1017 | MAC2STR(bss->addr), MAC2STR(addr)); | |
1018 | os_memcpy(bss->addr, addr, ETH_ALEN); | |
77a020a1 BG |
1019 | if (notify) |
1020 | wpa_supplicant_event(drv->ctx, | |
1021 | EVENT_INTERFACE_MAC_CHANGED, NULL); | |
290834df BG |
1022 | } |
1023 | } | |
1024 | ||
1025 | ||
62d680c3 JM |
1026 | static void wpa_driver_nl80211_event_rtm_newlink(void *ctx, |
1027 | struct ifinfomsg *ifi, | |
1028 | u8 *buf, size_t len) | |
3f5285e8 | 1029 | { |
36d84860 BG |
1030 | struct nl80211_global *global = ctx; |
1031 | struct wpa_driver_nl80211_data *drv; | |
90a545cc | 1032 | int attrlen; |
62d680c3 | 1033 | struct rtattr *attr; |
97cfcf64 | 1034 | u32 brid = 0; |
aef85ba2 | 1035 | char namebuf[IFNAMSIZ]; |
90a545cc JM |
1036 | char ifname[IFNAMSIZ + 1]; |
1037 | char extra[100], *pos, *end; | |
5e0c20ff | 1038 | int init_failed; |
3f5285e8 | 1039 | |
90a545cc JM |
1040 | extra[0] = '\0'; |
1041 | pos = extra; | |
1042 | end = pos + sizeof(extra); | |
1043 | ifname[0] = '\0'; | |
1044 | ||
1045 | attrlen = len; | |
1046 | attr = (struct rtattr *) buf; | |
1047 | while (RTA_OK(attr, attrlen)) { | |
1048 | switch (attr->rta_type) { | |
1049 | case IFLA_IFNAME: | |
1050 | if (RTA_PAYLOAD(attr) >= IFNAMSIZ) | |
1051 | break; | |
1052 | os_memcpy(ifname, RTA_DATA(attr), RTA_PAYLOAD(attr)); | |
1053 | ifname[RTA_PAYLOAD(attr)] = '\0'; | |
1054 | break; | |
1055 | case IFLA_MASTER: | |
1056 | brid = nla_get_u32((struct nlattr *) attr); | |
1057 | pos += os_snprintf(pos, end - pos, " master=%u", brid); | |
1058 | break; | |
1059 | case IFLA_WIRELESS: | |
1060 | pos += os_snprintf(pos, end - pos, " wext"); | |
1061 | break; | |
1062 | case IFLA_OPERSTATE: | |
1063 | pos += os_snprintf(pos, end - pos, " operstate=%u", | |
1064 | nla_get_u32((struct nlattr *) attr)); | |
1065 | break; | |
1066 | case IFLA_LINKMODE: | |
1067 | pos += os_snprintf(pos, end - pos, " linkmode=%u", | |
1068 | nla_get_u32((struct nlattr *) attr)); | |
1069 | break; | |
1070 | } | |
1071 | attr = RTA_NEXT(attr, attrlen); | |
1072 | } | |
1073 | extra[sizeof(extra) - 1] = '\0'; | |
1074 | ||
f2e90835 JM |
1075 | wpa_printf(MSG_DEBUG, "RTM_NEWLINK: ifi_index=%d ifname=%s%s ifi_family=%d ifi_flags=0x%x (%s%s%s%s)", |
1076 | ifi->ifi_index, ifname, extra, ifi->ifi_family, | |
1077 | ifi->ifi_flags, | |
3f5285e8 JM |
1078 | (ifi->ifi_flags & IFF_UP) ? "[UP]" : "", |
1079 | (ifi->ifi_flags & IFF_RUNNING) ? "[RUNNING]" : "", | |
1080 | (ifi->ifi_flags & IFF_LOWER_UP) ? "[LOWER_UP]" : "", | |
1081 | (ifi->ifi_flags & IFF_DORMANT) ? "[DORMANT]" : ""); | |
a63063b4 | 1082 | |
5e0c20ff | 1083 | drv = nl80211_find_drv(global, ifi->ifi_index, buf, len, &init_failed); |
45e3fc72 RM |
1084 | if (!drv) |
1085 | goto event_newlink; | |
5e0c20ff JM |
1086 | if (init_failed) |
1087 | return; /* do not update interface state */ | |
45e3fc72 | 1088 | |
a63063b4 | 1089 | if (!drv->if_disabled && !(ifi->ifi_flags & IFF_UP)) { |
106fa1e9 | 1090 | namebuf[0] = '\0'; |
59d24925 | 1091 | if (if_indextoname(ifi->ifi_index, namebuf) && |
106fa1e9 | 1092 | linux_iface_up(drv->global->ioctl_sock, namebuf) > 0) { |
59d24925 JM |
1093 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface down " |
1094 | "event since interface %s is up", namebuf); | |
7a94120e | 1095 | drv->ignore_if_down_event = 0; |
77a020a1 BG |
1096 | /* Re-read MAC address as it may have changed */ |
1097 | nl80211_refresh_mac(drv, ifi->ifi_index, 1); | |
59d24925 JM |
1098 | return; |
1099 | } | |
106fa1e9 JM |
1100 | wpa_printf(MSG_DEBUG, "nl80211: Interface down (%s/%s)", |
1101 | namebuf, ifname); | |
1102 | if (os_strcmp(drv->first_bss->ifname, ifname) != 0) { | |
1103 | wpa_printf(MSG_DEBUG, | |
1104 | "nl80211: Not the main interface (%s) - do not indicate interface down", | |
1105 | drv->first_bss->ifname); | |
1106 | } else if (drv->ignore_if_down_event) { | |
7d9c3698 JM |
1107 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface down " |
1108 | "event generated by mode change"); | |
1109 | drv->ignore_if_down_event = 0; | |
1110 | } else { | |
1111 | drv->if_disabled = 1; | |
1112 | wpa_supplicant_event(drv->ctx, | |
1113 | EVENT_INTERFACE_DISABLED, NULL); | |
819f096f AO |
1114 | |
1115 | /* | |
1116 | * Try to get drv again, since it may be removed as | |
1117 | * part of the EVENT_INTERFACE_DISABLED handling for | |
1118 | * dynamic interfaces | |
1119 | */ | |
1120 | drv = nl80211_find_drv(global, ifi->ifi_index, | |
5e0c20ff | 1121 | buf, len, NULL); |
819f096f AO |
1122 | if (!drv) |
1123 | return; | |
7d9c3698 | 1124 | } |
a63063b4 JM |
1125 | } |
1126 | ||
1127 | if (drv->if_disabled && (ifi->ifi_flags & IFF_UP)) { | |
8a9950f7 | 1128 | namebuf[0] = '\0'; |
aef85ba2 | 1129 | if (if_indextoname(ifi->ifi_index, namebuf) && |
106fa1e9 | 1130 | linux_iface_up(drv->global->ioctl_sock, namebuf) == 0) { |
aef85ba2 JM |
1131 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up " |
1132 | "event since interface %s is down", | |
1133 | namebuf); | |
8a9950f7 HW |
1134 | return; |
1135 | } | |
1136 | wpa_printf(MSG_DEBUG, "nl80211: Interface up (%s/%s)", | |
1137 | namebuf, ifname); | |
1138 | if (os_strcmp(drv->first_bss->ifname, ifname) != 0) { | |
1139 | wpa_printf(MSG_DEBUG, | |
1140 | "nl80211: Not the main interface (%s) - do not indicate interface up", | |
1141 | drv->first_bss->ifname); | |
834ee56f | 1142 | } else if (if_nametoindex(drv->first_bss->ifname) == 0) { |
d1f4942b JM |
1143 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up " |
1144 | "event since interface %s does not exist", | |
834ee56f | 1145 | drv->first_bss->ifname); |
d1f4942b JM |
1146 | } else if (drv->if_removed) { |
1147 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up " | |
1148 | "event since interface %s is marked " | |
834ee56f | 1149 | "removed", drv->first_bss->ifname); |
aef85ba2 | 1150 | } else { |
3e0272ca | 1151 | /* Re-read MAC address as it may have changed */ |
77a020a1 | 1152 | nl80211_refresh_mac(drv, ifi->ifi_index, 0); |
3e0272ca | 1153 | |
aef85ba2 JM |
1154 | drv->if_disabled = 0; |
1155 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_ENABLED, | |
1156 | NULL); | |
1157 | } | |
a63063b4 JM |
1158 | } |
1159 | ||
3f5285e8 JM |
1160 | /* |
1161 | * Some drivers send the association event before the operup event--in | |
1162 | * this case, lifting operstate in wpa_driver_nl80211_set_operstate() | |
1163 | * fails. This will hit us when wpa_supplicant does not need to do | |
1164 | * IEEE 802.1X authentication | |
1165 | */ | |
1166 | if (drv->operstate == 1 && | |
1167 | (ifi->ifi_flags & (IFF_LOWER_UP | IFF_DORMANT)) == IFF_LOWER_UP && | |
90a545cc JM |
1168 | !(ifi->ifi_flags & IFF_RUNNING)) { |
1169 | wpa_printf(MSG_DEBUG, "nl80211: Set IF_OPER_UP again based on ifi_flags and expected operstate"); | |
36d84860 | 1170 | netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, |
e2d02c29 | 1171 | -1, IF_OPER_UP); |
3f5285e8 | 1172 | } |
97cfcf64 | 1173 | |
45e3fc72 | 1174 | event_newlink: |
90a545cc | 1175 | if (ifname[0]) |
45e3fc72 RM |
1176 | wpa_driver_nl80211_event_newlink(global, drv, ifi->ifi_index, |
1177 | ifname); | |
90a545cc | 1178 | |
45e3fc72 | 1179 | if (ifi->ifi_family == AF_BRIDGE && brid && drv) { |
392dfd37 JM |
1180 | struct i802_bss *bss; |
1181 | ||
97cfcf64 | 1182 | /* device has been added to bridge */ |
40e76396 JM |
1183 | if (!if_indextoname(brid, namebuf)) { |
1184 | wpa_printf(MSG_DEBUG, | |
1185 | "nl80211: Could not find bridge ifname for ifindex %u", | |
1186 | brid); | |
1187 | return; | |
1188 | } | |
97cfcf64 B |
1189 | wpa_printf(MSG_DEBUG, "nl80211: Add ifindex %u for bridge %s", |
1190 | brid, namebuf); | |
732b1d20 | 1191 | add_ifidx(drv, brid, ifi->ifi_index); |
392dfd37 JM |
1192 | |
1193 | for (bss = drv->first_bss; bss; bss = bss->next) { | |
1194 | if (os_strcmp(ifname, bss->ifname) == 0) { | |
1195 | os_strlcpy(bss->brname, namebuf, IFNAMSIZ); | |
1196 | break; | |
1197 | } | |
1198 | } | |
97cfcf64 | 1199 | } |
3f5285e8 JM |
1200 | } |
1201 | ||
1202 | ||
62d680c3 JM |
1203 | static void wpa_driver_nl80211_event_rtm_dellink(void *ctx, |
1204 | struct ifinfomsg *ifi, | |
1205 | u8 *buf, size_t len) | |
3f5285e8 | 1206 | { |
36d84860 BG |
1207 | struct nl80211_global *global = ctx; |
1208 | struct wpa_driver_nl80211_data *drv; | |
90a545cc | 1209 | int attrlen; |
62d680c3 | 1210 | struct rtattr *attr; |
97cfcf64 | 1211 | u32 brid = 0; |
90a545cc | 1212 | char ifname[IFNAMSIZ + 1]; |
f2e90835 | 1213 | char extra[100], *pos, *end; |
3f5285e8 | 1214 | |
f2e90835 JM |
1215 | extra[0] = '\0'; |
1216 | pos = extra; | |
1217 | end = pos + sizeof(extra); | |
90a545cc JM |
1218 | ifname[0] = '\0'; |
1219 | ||
62d680c3 JM |
1220 | attrlen = len; |
1221 | attr = (struct rtattr *) buf; | |
3f5285e8 | 1222 | while (RTA_OK(attr, attrlen)) { |
90a545cc JM |
1223 | switch (attr->rta_type) { |
1224 | case IFLA_IFNAME: | |
1225 | if (RTA_PAYLOAD(attr) >= IFNAMSIZ) | |
1226 | break; | |
1227 | os_memcpy(ifname, RTA_DATA(attr), RTA_PAYLOAD(attr)); | |
1228 | ifname[RTA_PAYLOAD(attr)] = '\0'; | |
1229 | break; | |
1230 | case IFLA_MASTER: | |
97cfcf64 | 1231 | brid = nla_get_u32((struct nlattr *) attr); |
f2e90835 JM |
1232 | pos += os_snprintf(pos, end - pos, " master=%u", brid); |
1233 | break; | |
1234 | case IFLA_OPERSTATE: | |
1235 | pos += os_snprintf(pos, end - pos, " operstate=%u", | |
1236 | nla_get_u32((struct nlattr *) attr)); | |
1237 | break; | |
1238 | case IFLA_LINKMODE: | |
1239 | pos += os_snprintf(pos, end - pos, " linkmode=%u", | |
1240 | nla_get_u32((struct nlattr *) attr)); | |
90a545cc JM |
1241 | break; |
1242 | } | |
3f5285e8 JM |
1243 | attr = RTA_NEXT(attr, attrlen); |
1244 | } | |
f2e90835 JM |
1245 | extra[sizeof(extra) - 1] = '\0'; |
1246 | ||
1247 | wpa_printf(MSG_DEBUG, "RTM_DELLINK: ifi_index=%d ifname=%s%s ifi_family=%d ifi_flags=0x%x (%s%s%s%s)", | |
1248 | ifi->ifi_index, ifname, extra, ifi->ifi_family, | |
1249 | ifi->ifi_flags, | |
1250 | (ifi->ifi_flags & IFF_UP) ? "[UP]" : "", | |
1251 | (ifi->ifi_flags & IFF_RUNNING) ? "[RUNNING]" : "", | |
1252 | (ifi->ifi_flags & IFF_LOWER_UP) ? "[LOWER_UP]" : "", | |
1253 | (ifi->ifi_flags & IFF_DORMANT) ? "[DORMANT]" : ""); | |
97cfcf64 | 1254 | |
5e0c20ff | 1255 | drv = nl80211_find_drv(global, ifi->ifi_index, buf, len, NULL); |
90a545cc | 1256 | |
45e3fc72 | 1257 | if (ifi->ifi_family == AF_BRIDGE && brid && drv) { |
97cfcf64 B |
1258 | /* device has been removed from bridge */ |
1259 | char namebuf[IFNAMSIZ]; | |
40e76396 JM |
1260 | |
1261 | if (!if_indextoname(brid, namebuf)) { | |
1262 | wpa_printf(MSG_DEBUG, | |
1263 | "nl80211: Could not find bridge ifname for ifindex %u", | |
1264 | brid); | |
1265 | } else { | |
1266 | wpa_printf(MSG_DEBUG, | |
1267 | "nl80211: Remove ifindex %u for bridge %s", | |
1268 | brid, namebuf); | |
1269 | } | |
732b1d20 | 1270 | del_ifidx(drv, brid, ifi->ifi_index); |
97cfcf64 | 1271 | } |
45e3fc72 RM |
1272 | |
1273 | if (ifi->ifi_family != AF_BRIDGE || !brid) | |
1274 | wpa_driver_nl80211_event_dellink(global, drv, ifi->ifi_index, | |
1275 | ifname); | |
3f5285e8 JM |
1276 | } |
1277 | ||
1278 | ||
a1fce391 JM |
1279 | struct nl80211_get_assoc_freq_arg { |
1280 | struct wpa_driver_nl80211_data *drv; | |
1281 | unsigned int assoc_freq; | |
1282 | unsigned int ibss_freq; | |
1283 | u8 assoc_bssid[ETH_ALEN]; | |
ed0a4ddc NW |
1284 | u8 assoc_ssid[SSID_MAX_LEN]; |
1285 | u8 assoc_ssid_len; | |
a1fce391 JM |
1286 | }; |
1287 | ||
1288 | static int nl80211_get_assoc_freq_handler(struct nl_msg *msg, void *arg) | |
1289 | { | |
1290 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
1291 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
1292 | struct nlattr *bss[NL80211_BSS_MAX + 1]; | |
1293 | static struct nla_policy bss_policy[NL80211_BSS_MAX + 1] = { | |
1294 | [NL80211_BSS_BSSID] = { .type = NLA_UNSPEC }, | |
1295 | [NL80211_BSS_FREQUENCY] = { .type = NLA_U32 }, | |
ed0a4ddc | 1296 | [NL80211_BSS_INFORMATION_ELEMENTS] = { .type = NLA_UNSPEC }, |
a1fce391 JM |
1297 | [NL80211_BSS_STATUS] = { .type = NLA_U32 }, |
1298 | }; | |
1299 | struct nl80211_get_assoc_freq_arg *ctx = arg; | |
1300 | enum nl80211_bss_status status; | |
1301 | ||
1302 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
1303 | genlmsg_attrlen(gnlh, 0), NULL); | |
1304 | if (!tb[NL80211_ATTR_BSS] || | |
1305 | nla_parse_nested(bss, NL80211_BSS_MAX, tb[NL80211_ATTR_BSS], | |
1306 | bss_policy) || | |
1307 | !bss[NL80211_BSS_STATUS]) | |
1308 | return NL_SKIP; | |
1309 | ||
1310 | status = nla_get_u32(bss[NL80211_BSS_STATUS]); | |
1311 | if (status == NL80211_BSS_STATUS_ASSOCIATED && | |
1312 | bss[NL80211_BSS_FREQUENCY]) { | |
1313 | ctx->assoc_freq = nla_get_u32(bss[NL80211_BSS_FREQUENCY]); | |
1314 | wpa_printf(MSG_DEBUG, "nl80211: Associated on %u MHz", | |
1315 | ctx->assoc_freq); | |
1316 | } | |
1317 | if (status == NL80211_BSS_STATUS_IBSS_JOINED && | |
1318 | bss[NL80211_BSS_FREQUENCY]) { | |
1319 | ctx->ibss_freq = nla_get_u32(bss[NL80211_BSS_FREQUENCY]); | |
1320 | wpa_printf(MSG_DEBUG, "nl80211: IBSS-joined on %u MHz", | |
1321 | ctx->ibss_freq); | |
1322 | } | |
1323 | if (status == NL80211_BSS_STATUS_ASSOCIATED && | |
1324 | bss[NL80211_BSS_BSSID]) { | |
1325 | os_memcpy(ctx->assoc_bssid, | |
1326 | nla_data(bss[NL80211_BSS_BSSID]), ETH_ALEN); | |
1327 | wpa_printf(MSG_DEBUG, "nl80211: Associated with " | |
1328 | MACSTR, MAC2STR(ctx->assoc_bssid)); | |
1329 | } | |
1330 | ||
ed0a4ddc NW |
1331 | if (status == NL80211_BSS_STATUS_ASSOCIATED && |
1332 | bss[NL80211_BSS_INFORMATION_ELEMENTS]) { | |
1333 | const u8 *ie, *ssid; | |
1334 | size_t ie_len; | |
1335 | ||
1336 | ie = nla_data(bss[NL80211_BSS_INFORMATION_ELEMENTS]); | |
1337 | ie_len = nla_len(bss[NL80211_BSS_INFORMATION_ELEMENTS]); | |
1338 | ssid = get_ie(ie, ie_len, WLAN_EID_SSID); | |
1339 | if (ssid && ssid[1] > 0 && ssid[1] <= SSID_MAX_LEN) { | |
1340 | ctx->assoc_ssid_len = ssid[1]; | |
1341 | os_memcpy(ctx->assoc_ssid, ssid + 2, ssid[1]); | |
1342 | } | |
1343 | } | |
1344 | ||
a1fce391 JM |
1345 | return NL_SKIP; |
1346 | } | |
1347 | ||
1348 | ||
ed0a4ddc NW |
1349 | int nl80211_get_assoc_ssid(struct wpa_driver_nl80211_data *drv, u8 *ssid) |
1350 | { | |
1351 | struct nl_msg *msg; | |
1352 | int ret; | |
1353 | struct nl80211_get_assoc_freq_arg arg; | |
16a26672 | 1354 | int count = 0; |
ed0a4ddc | 1355 | |
16a26672 | 1356 | try_again: |
ed0a4ddc NW |
1357 | msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SCAN); |
1358 | os_memset(&arg, 0, sizeof(arg)); | |
1359 | arg.drv = drv; | |
1360 | ret = send_and_recv_msgs(drv, msg, nl80211_get_assoc_freq_handler, | |
1361 | &arg); | |
16a26672 JM |
1362 | if (ret == -EAGAIN) { |
1363 | count++; | |
1364 | if (count >= 10) { | |
1365 | wpa_printf(MSG_INFO, | |
1366 | "nl80211: Failed to receive consistent scan result dump for get_assoc_ssid"); | |
1367 | } else { | |
1368 | wpa_printf(MSG_DEBUG, | |
1369 | "nl80211: Failed to receive consistent scan result dump for get_assoc_ssid - try again"); | |
1370 | goto try_again; | |
1371 | } | |
1372 | } | |
ed0a4ddc NW |
1373 | if (ret == 0) { |
1374 | os_memcpy(ssid, arg.assoc_ssid, arg.assoc_ssid_len); | |
1375 | return arg.assoc_ssid_len; | |
1376 | } | |
1377 | wpa_printf(MSG_DEBUG, "nl80211: Scan result fetch failed: ret=%d (%s)", | |
1378 | ret, strerror(-ret)); | |
1379 | return ret; | |
1380 | } | |
1381 | ||
1382 | ||
f3407c66 | 1383 | unsigned int nl80211_get_assoc_freq(struct wpa_driver_nl80211_data *drv) |
f5a8d422 JM |
1384 | { |
1385 | struct nl_msg *msg; | |
1386 | int ret; | |
a1fce391 | 1387 | struct nl80211_get_assoc_freq_arg arg; |
16a26672 | 1388 | int count = 0; |
f5a8d422 | 1389 | |
16a26672 | 1390 | try_again: |
9725b784 | 1391 | msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SCAN); |
f5a8d422 | 1392 | os_memset(&arg, 0, sizeof(arg)); |
f5a8d422 | 1393 | arg.drv = drv; |
a1fce391 JM |
1394 | ret = send_and_recv_msgs(drv, msg, nl80211_get_assoc_freq_handler, |
1395 | &arg); | |
16a26672 JM |
1396 | if (ret == -EAGAIN) { |
1397 | count++; | |
1398 | if (count >= 10) { | |
1399 | wpa_printf(MSG_INFO, | |
1400 | "nl80211: Failed to receive consistent scan result dump for get_assoc_freq"); | |
1401 | } else { | |
1402 | wpa_printf(MSG_DEBUG, | |
1403 | "nl80211: Failed to receive consistent scan result dump for get_assoc_freq - try again"); | |
1404 | goto try_again; | |
1405 | } | |
1406 | } | |
f5a8d422 | 1407 | if (ret == 0) { |
c7caac56 JM |
1408 | unsigned int freq = drv->nlmode == NL80211_IFTYPE_ADHOC ? |
1409 | arg.ibss_freq : arg.assoc_freq; | |
f5a8d422 | 1410 | wpa_printf(MSG_DEBUG, "nl80211: Operating frequency for the " |
c7caac56 JM |
1411 | "associated BSS from scan results: %u MHz", freq); |
1412 | if (freq) | |
1413 | drv->assoc_freq = freq; | |
30158a0d | 1414 | return drv->assoc_freq; |
f5a8d422 JM |
1415 | } |
1416 | wpa_printf(MSG_DEBUG, "nl80211: Scan result fetch failed: ret=%d " | |
1417 | "(%s)", ret, strerror(-ret)); | |
f5a8d422 JM |
1418 | return drv->assoc_freq; |
1419 | } | |
1420 | ||
1421 | ||
60a972a6 JM |
1422 | static int get_link_signal(struct nl_msg *msg, void *arg) |
1423 | { | |
1424 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
1425 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
1426 | struct nlattr *sinfo[NL80211_STA_INFO_MAX + 1]; | |
1427 | static struct nla_policy policy[NL80211_STA_INFO_MAX + 1] = { | |
1428 | [NL80211_STA_INFO_SIGNAL] = { .type = NLA_U8 }, | |
95783298 | 1429 | [NL80211_STA_INFO_SIGNAL_AVG] = { .type = NLA_U8 }, |
74fa78b2 | 1430 | [NL80211_STA_INFO_BEACON_SIGNAL_AVG] = { .type = NLA_U8 }, |
60a972a6 | 1431 | }; |
7ee35bf3 PS |
1432 | struct nlattr *rinfo[NL80211_RATE_INFO_MAX + 1]; |
1433 | static struct nla_policy rate_policy[NL80211_RATE_INFO_MAX + 1] = { | |
1434 | [NL80211_RATE_INFO_BITRATE] = { .type = NLA_U16 }, | |
1435 | [NL80211_RATE_INFO_MCS] = { .type = NLA_U8 }, | |
1436 | [NL80211_RATE_INFO_40_MHZ_WIDTH] = { .type = NLA_FLAG }, | |
1437 | [NL80211_RATE_INFO_SHORT_GI] = { .type = NLA_FLAG }, | |
1438 | }; | |
1c5c7273 | 1439 | struct wpa_signal_info *sig_change = arg; |
60a972a6 JM |
1440 | |
1441 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
1442 | genlmsg_attrlen(gnlh, 0), NULL); | |
1443 | if (!tb[NL80211_ATTR_STA_INFO] || | |
1444 | nla_parse_nested(sinfo, NL80211_STA_INFO_MAX, | |
1445 | tb[NL80211_ATTR_STA_INFO], policy)) | |
1446 | return NL_SKIP; | |
1447 | if (!sinfo[NL80211_STA_INFO_SIGNAL]) | |
1448 | return NL_SKIP; | |
1449 | ||
7ee35bf3 PS |
1450 | sig_change->current_signal = |
1451 | (s8) nla_get_u8(sinfo[NL80211_STA_INFO_SIGNAL]); | |
1452 | ||
95783298 AO |
1453 | if (sinfo[NL80211_STA_INFO_SIGNAL_AVG]) |
1454 | sig_change->avg_signal = | |
1455 | (s8) nla_get_u8(sinfo[NL80211_STA_INFO_SIGNAL_AVG]); | |
1456 | else | |
1457 | sig_change->avg_signal = 0; | |
1458 | ||
74fa78b2 JM |
1459 | if (sinfo[NL80211_STA_INFO_BEACON_SIGNAL_AVG]) |
1460 | sig_change->avg_beacon_signal = | |
1461 | (s8) | |
1462 | nla_get_u8(sinfo[NL80211_STA_INFO_BEACON_SIGNAL_AVG]); | |
1463 | else | |
1464 | sig_change->avg_beacon_signal = 0; | |
1465 | ||
7ee35bf3 PS |
1466 | if (sinfo[NL80211_STA_INFO_TX_BITRATE]) { |
1467 | if (nla_parse_nested(rinfo, NL80211_RATE_INFO_MAX, | |
1468 | sinfo[NL80211_STA_INFO_TX_BITRATE], | |
1469 | rate_policy)) { | |
1470 | sig_change->current_txrate = 0; | |
1471 | } else { | |
1472 | if (rinfo[NL80211_RATE_INFO_BITRATE]) { | |
1473 | sig_change->current_txrate = | |
1474 | nla_get_u16(rinfo[ | |
1475 | NL80211_RATE_INFO_BITRATE]) * 100; | |
1476 | } | |
1477 | } | |
1478 | } | |
1479 | ||
60a972a6 JM |
1480 | return NL_SKIP; |
1481 | } | |
1482 | ||
1483 | ||
f3407c66 JM |
1484 | int nl80211_get_link_signal(struct wpa_driver_nl80211_data *drv, |
1485 | struct wpa_signal_info *sig) | |
60a972a6 JM |
1486 | { |
1487 | struct nl_msg *msg; | |
1488 | ||
941807f6 | 1489 | sig->current_signal = -WPA_INVALID_NOISE; |
7ee35bf3 | 1490 | sig->current_txrate = 0; |
60a972a6 | 1491 | |
9725b784 | 1492 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_GET_STATION)) || |
a862e4a3 JM |
1493 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, drv->bssid)) { |
1494 | nlmsg_free(msg); | |
1495 | return -ENOBUFS; | |
1496 | } | |
60a972a6 JM |
1497 | |
1498 | return send_and_recv_msgs(drv, msg, get_link_signal, sig); | |
60a972a6 JM |
1499 | } |
1500 | ||
1501 | ||
7ee35bf3 PS |
1502 | static int get_link_noise(struct nl_msg *msg, void *arg) |
1503 | { | |
1504 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
1505 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
1506 | struct nlattr *sinfo[NL80211_SURVEY_INFO_MAX + 1]; | |
1507 | static struct nla_policy survey_policy[NL80211_SURVEY_INFO_MAX + 1] = { | |
1508 | [NL80211_SURVEY_INFO_FREQUENCY] = { .type = NLA_U32 }, | |
1509 | [NL80211_SURVEY_INFO_NOISE] = { .type = NLA_U8 }, | |
1510 | }; | |
1c5c7273 | 1511 | struct wpa_signal_info *sig_change = arg; |
7ee35bf3 PS |
1512 | |
1513 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
1514 | genlmsg_attrlen(gnlh, 0), NULL); | |
1515 | ||
1516 | if (!tb[NL80211_ATTR_SURVEY_INFO]) { | |
1517 | wpa_printf(MSG_DEBUG, "nl80211: survey data missing!"); | |
1518 | return NL_SKIP; | |
1519 | } | |
1520 | ||
1521 | if (nla_parse_nested(sinfo, NL80211_SURVEY_INFO_MAX, | |
1522 | tb[NL80211_ATTR_SURVEY_INFO], | |
1523 | survey_policy)) { | |
1524 | wpa_printf(MSG_DEBUG, "nl80211: failed to parse nested " | |
1525 | "attributes!"); | |
1526 | return NL_SKIP; | |
1527 | } | |
1528 | ||
1529 | if (!sinfo[NL80211_SURVEY_INFO_FREQUENCY]) | |
1530 | return NL_SKIP; | |
1531 | ||
1532 | if (nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]) != | |
1533 | sig_change->frequency) | |
1534 | return NL_SKIP; | |
1535 | ||
1536 | if (!sinfo[NL80211_SURVEY_INFO_NOISE]) | |
1537 | return NL_SKIP; | |
1538 | ||
1539 | sig_change->current_noise = | |
1540 | (s8) nla_get_u8(sinfo[NL80211_SURVEY_INFO_NOISE]); | |
1541 | ||
1542 | return NL_SKIP; | |
1543 | } | |
1544 | ||
1545 | ||
f3407c66 JM |
1546 | int nl80211_get_link_noise(struct wpa_driver_nl80211_data *drv, |
1547 | struct wpa_signal_info *sig_change) | |
7ee35bf3 PS |
1548 | { |
1549 | struct nl_msg *msg; | |
1550 | ||
941807f6 | 1551 | sig_change->current_noise = WPA_INVALID_NOISE; |
7ee35bf3 PS |
1552 | sig_change->frequency = drv->assoc_freq; |
1553 | ||
9725b784 | 1554 | msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SURVEY); |
7ee35bf3 | 1555 | return send_and_recv_msgs(drv, msg, get_link_noise, sig_change); |
7ee35bf3 PS |
1556 | } |
1557 | ||
1558 | ||
7f00dc6e MV |
1559 | static int get_channel_info(struct nl_msg *msg, void *arg) |
1560 | { | |
1561 | struct nlattr *tb[NL80211_ATTR_MAX + 1] = { 0 }; | |
1562 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
1563 | struct wpa_channel_info *chan_info = arg; | |
1564 | ||
1565 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
1566 | genlmsg_attrlen(gnlh, 0), NULL); | |
1567 | ||
1568 | os_memset(chan_info, 0, sizeof(struct wpa_channel_info)); | |
1569 | chan_info->chanwidth = CHAN_WIDTH_UNKNOWN; | |
1570 | ||
1571 | if (tb[NL80211_ATTR_WIPHY_FREQ]) | |
1572 | chan_info->frequency = | |
1573 | nla_get_u32(tb[NL80211_ATTR_WIPHY_FREQ]); | |
1574 | if (tb[NL80211_ATTR_CHANNEL_WIDTH]) | |
1575 | chan_info->chanwidth = convert2width( | |
1576 | nla_get_u32(tb[NL80211_ATTR_CHANNEL_WIDTH])); | |
1577 | if (tb[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { | |
1578 | enum nl80211_channel_type ct = | |
1579 | nla_get_u32(tb[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); | |
1580 | ||
1581 | switch (ct) { | |
1582 | case NL80211_CHAN_HT40MINUS: | |
1583 | chan_info->sec_channel = -1; | |
1584 | break; | |
1585 | case NL80211_CHAN_HT40PLUS: | |
1586 | chan_info->sec_channel = 1; | |
1587 | break; | |
1588 | default: | |
1589 | chan_info->sec_channel = 0; | |
1590 | break; | |
1591 | } | |
1592 | } | |
1593 | if (tb[NL80211_ATTR_CENTER_FREQ1]) | |
1594 | chan_info->center_frq1 = | |
1595 | nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ1]); | |
1596 | if (tb[NL80211_ATTR_CENTER_FREQ2]) | |
1597 | chan_info->center_frq2 = | |
1598 | nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ2]); | |
1599 | ||
1600 | if (chan_info->center_frq2) { | |
1601 | u8 seg1_idx = 0; | |
1602 | ||
1603 | if (ieee80211_freq_to_chan(chan_info->center_frq2, &seg1_idx) != | |
1604 | NUM_HOSTAPD_MODES) | |
1605 | chan_info->seg1_idx = seg1_idx; | |
1606 | } | |
1607 | ||
1608 | return NL_SKIP; | |
1609 | } | |
1610 | ||
1611 | ||
1612 | static int nl80211_channel_info(void *priv, struct wpa_channel_info *ci) | |
1613 | { | |
1614 | struct i802_bss *bss = priv; | |
1615 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
1616 | struct nl_msg *msg; | |
1617 | ||
1618 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_GET_INTERFACE); | |
1619 | return send_and_recv_msgs(drv, msg, get_channel_info, ci); | |
1620 | } | |
1621 | ||
1622 | ||
97865538 | 1623 | static void wpa_driver_nl80211_event_receive(int sock, void *eloop_ctx, |
5582a5d1 | 1624 | void *handle) |
97865538 | 1625 | { |
a4ae123c | 1626 | struct nl_cb *cb = eloop_ctx; |
34068ac3 | 1627 | int res; |
97865538 | 1628 | |
cc2ada86 | 1629 | wpa_printf(MSG_MSGDUMP, "nl80211: Event message available"); |
97865538 | 1630 | |
34068ac3 | 1631 | res = nl_recvmsgs(handle, cb); |
d3d04831 | 1632 | if (res < 0) { |
34068ac3 JM |
1633 | wpa_printf(MSG_INFO, "nl80211: %s->nl_recvmsgs failed: %d", |
1634 | __func__, res); | |
1635 | } | |
97865538 JM |
1636 | } |
1637 | ||
1638 | ||
6d158490 LR |
1639 | /** |
1640 | * wpa_driver_nl80211_set_country - ask nl80211 to set the regulatory domain | |
1641 | * @priv: driver_nl80211 private data | |
1642 | * @alpha2_arg: country to which to switch to | |
1643 | * Returns: 0 on success, -1 on failure | |
1644 | * | |
1645 | * This asks nl80211 to set the regulatory domain for given | |
1646 | * country ISO / IEC alpha2. | |
1647 | */ | |
1648 | static int wpa_driver_nl80211_set_country(void *priv, const char *alpha2_arg) | |
1649 | { | |
a2e40bb6 FF |
1650 | struct i802_bss *bss = priv; |
1651 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
6d158490 LR |
1652 | char alpha2[3]; |
1653 | struct nl_msg *msg; | |
1654 | ||
1655 | msg = nlmsg_alloc(); | |
1656 | if (!msg) | |
e785c2ba | 1657 | return -ENOMEM; |
6d158490 LR |
1658 | |
1659 | alpha2[0] = alpha2_arg[0]; | |
1660 | alpha2[1] = alpha2_arg[1]; | |
1661 | alpha2[2] = '\0'; | |
1662 | ||
a862e4a3 JM |
1663 | if (!nl80211_cmd(drv, msg, 0, NL80211_CMD_REQ_SET_REG) || |
1664 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, alpha2)) { | |
1665 | nlmsg_free(msg); | |
1666 | return -EINVAL; | |
1667 | } | |
6d158490 LR |
1668 | if (send_and_recv_msgs(drv, msg, NULL, NULL)) |
1669 | return -EINVAL; | |
1670 | return 0; | |
6d158490 LR |
1671 | } |
1672 | ||
1673 | ||
f0793bf1 JM |
1674 | static int nl80211_get_country(struct nl_msg *msg, void *arg) |
1675 | { | |
1676 | char *alpha2 = arg; | |
1677 | struct nlattr *tb_msg[NL80211_ATTR_MAX + 1]; | |
1678 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
1679 | ||
1680 | nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
1681 | genlmsg_attrlen(gnlh, 0), NULL); | |
1682 | if (!tb_msg[NL80211_ATTR_REG_ALPHA2]) { | |
1683 | wpa_printf(MSG_DEBUG, "nl80211: No country information available"); | |
1684 | return NL_SKIP; | |
1685 | } | |
1686 | os_strlcpy(alpha2, nla_data(tb_msg[NL80211_ATTR_REG_ALPHA2]), 3); | |
1687 | return NL_SKIP; | |
1688 | } | |
1689 | ||
1690 | ||
1691 | static int wpa_driver_nl80211_get_country(void *priv, char *alpha2) | |
1692 | { | |
1693 | struct i802_bss *bss = priv; | |
1694 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
1695 | struct nl_msg *msg; | |
1696 | int ret; | |
1697 | ||
1698 | msg = nlmsg_alloc(); | |
1699 | if (!msg) | |
1700 | return -ENOMEM; | |
1701 | ||
1702 | nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_REG); | |
1703 | alpha2[0] = '\0'; | |
1704 | ret = send_and_recv_msgs(drv, msg, nl80211_get_country, alpha2); | |
1705 | if (!alpha2[0]) | |
1706 | ret = -1; | |
1707 | ||
1708 | return ret; | |
1709 | } | |
1710 | ||
1711 | ||
2a7b66f5 BG |
1712 | static int wpa_driver_nl80211_init_nl_global(struct nl80211_global *global) |
1713 | { | |
d6c9aab8 JB |
1714 | int ret; |
1715 | ||
2a7b66f5 BG |
1716 | global->nl_cb = nl_cb_alloc(NL_CB_DEFAULT); |
1717 | if (global->nl_cb == NULL) { | |
1718 | wpa_printf(MSG_ERROR, "nl80211: Failed to allocate netlink " | |
1719 | "callbacks"); | |
1720 | return -1; | |
1721 | } | |
1722 | ||
481234cf JM |
1723 | global->nl = nl_create_handle(global->nl_cb, "nl"); |
1724 | if (global->nl == NULL) | |
d6c9aab8 | 1725 | goto err; |
276e2d67 | 1726 | |
481234cf | 1727 | global->nl80211_id = genl_ctrl_resolve(global->nl, "nl80211"); |
335d42b1 | 1728 | if (global->nl80211_id < 0) { |
276e2d67 BG |
1729 | wpa_printf(MSG_ERROR, "nl80211: 'nl80211' generic netlink not " |
1730 | "found"); | |
d6c9aab8 | 1731 | goto err; |
276e2d67 BG |
1732 | } |
1733 | ||
481234cf JM |
1734 | global->nl_event = nl_create_handle(global->nl_cb, "event"); |
1735 | if (global->nl_event == NULL) | |
d6c9aab8 | 1736 | goto err; |
9fff9fdc | 1737 | |
d6c9aab8 | 1738 | ret = nl_get_multicast_id(global, "nl80211", "scan"); |
97865538 | 1739 | if (ret >= 0) |
481234cf | 1740 | ret = nl_socket_add_membership(global->nl_event, ret); |
97865538 JM |
1741 | if (ret < 0) { |
1742 | wpa_printf(MSG_ERROR, "nl80211: Could not add multicast " | |
1743 | "membership for scan events: %d (%s)", | |
3ea58a05 | 1744 | ret, nl_geterror(ret)); |
d6c9aab8 | 1745 | goto err; |
97865538 | 1746 | } |
c2a04078 | 1747 | |
d6c9aab8 | 1748 | ret = nl_get_multicast_id(global, "nl80211", "mlme"); |
c2a04078 | 1749 | if (ret >= 0) |
481234cf | 1750 | ret = nl_socket_add_membership(global->nl_event, ret); |
c2a04078 JM |
1751 | if (ret < 0) { |
1752 | wpa_printf(MSG_ERROR, "nl80211: Could not add multicast " | |
1753 | "membership for mlme events: %d (%s)", | |
3ea58a05 | 1754 | ret, nl_geterror(ret)); |
d6c9aab8 | 1755 | goto err; |
c2a04078 | 1756 | } |
c2a04078 | 1757 | |
d6c9aab8 | 1758 | ret = nl_get_multicast_id(global, "nl80211", "regulatory"); |
33c5deb8 | 1759 | if (ret >= 0) |
481234cf | 1760 | ret = nl_socket_add_membership(global->nl_event, ret); |
33c5deb8 JM |
1761 | if (ret < 0) { |
1762 | wpa_printf(MSG_DEBUG, "nl80211: Could not add multicast " | |
1763 | "membership for regulatory events: %d (%s)", | |
3ea58a05 | 1764 | ret, nl_geterror(ret)); |
33c5deb8 JM |
1765 | /* Continue without regulatory events */ |
1766 | } | |
1767 | ||
17b79e65 JM |
1768 | ret = nl_get_multicast_id(global, "nl80211", "vendor"); |
1769 | if (ret >= 0) | |
1770 | ret = nl_socket_add_membership(global->nl_event, ret); | |
1771 | if (ret < 0) { | |
1772 | wpa_printf(MSG_DEBUG, "nl80211: Could not add multicast " | |
1773 | "membership for vendor events: %d (%s)", | |
3ea58a05 | 1774 | ret, nl_geterror(ret)); |
17b79e65 JM |
1775 | /* Continue without vendor events */ |
1776 | } | |
1777 | ||
d6c9aab8 JB |
1778 | nl_cb_set(global->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, |
1779 | no_seq_check, NULL); | |
1780 | nl_cb_set(global->nl_cb, NL_CB_VALID, NL_CB_CUSTOM, | |
1781 | process_global_event, global); | |
1782 | ||
5f65e9f7 JB |
1783 | nl80211_register_eloop_read(&global->nl_event, |
1784 | wpa_driver_nl80211_event_receive, | |
40a68f33 | 1785 | global->nl_cb, 0); |
d6c9aab8 JB |
1786 | |
1787 | return 0; | |
1788 | ||
1789 | err: | |
1790 | nl_destroy_handles(&global->nl_event); | |
1791 | nl_destroy_handles(&global->nl); | |
1792 | nl_cb_put(global->nl_cb); | |
671a5039 | 1793 | global->nl_cb = NULL; |
d6c9aab8 JB |
1794 | return -1; |
1795 | } | |
1796 | ||
1797 | ||
f51f54a0 JM |
1798 | static void nl80211_check_global(struct nl80211_global *global) |
1799 | { | |
25ebd538 | 1800 | struct nl_sock *handle; |
f51f54a0 JM |
1801 | const char *groups[] = { "scan", "mlme", "regulatory", "vendor", NULL }; |
1802 | int ret; | |
1803 | unsigned int i; | |
1804 | ||
1805 | /* | |
1806 | * Try to re-add memberships to handle case of cfg80211 getting reloaded | |
1807 | * and all registration having been cleared. | |
1808 | */ | |
1809 | handle = (void *) (((intptr_t) global->nl_event) ^ | |
1810 | ELOOP_SOCKET_INVALID); | |
1811 | ||
1812 | for (i = 0; groups[i]; i++) { | |
1813 | ret = nl_get_multicast_id(global, "nl80211", groups[i]); | |
1814 | if (ret >= 0) | |
1815 | ret = nl_socket_add_membership(handle, ret); | |
1816 | if (ret < 0) { | |
1817 | wpa_printf(MSG_INFO, | |
1818 | "nl80211: Could not re-add multicast membership for %s events: %d (%s)", | |
3ea58a05 | 1819 | groups[i], ret, nl_geterror(ret)); |
f51f54a0 JM |
1820 | } |
1821 | } | |
1822 | } | |
1823 | ||
1824 | ||
8401a6b0 JM |
1825 | static void wpa_driver_nl80211_rfkill_blocked(void *ctx) |
1826 | { | |
6da504a1 IP |
1827 | struct wpa_driver_nl80211_data *drv = ctx; |
1828 | ||
8401a6b0 | 1829 | wpa_printf(MSG_DEBUG, "nl80211: RFKILL blocked"); |
6da504a1 | 1830 | |
a63063b4 | 1831 | /* |
6da504a1 IP |
1832 | * rtnetlink ifdown handler will report interfaces other than the P2P |
1833 | * Device interface as disabled. | |
a63063b4 | 1834 | */ |
6da504a1 IP |
1835 | if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) |
1836 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_DISABLED, NULL); | |
8401a6b0 JM |
1837 | } |
1838 | ||
1839 | ||
1840 | static void wpa_driver_nl80211_rfkill_unblocked(void *ctx) | |
1841 | { | |
1842 | struct wpa_driver_nl80211_data *drv = ctx; | |
1843 | wpa_printf(MSG_DEBUG, "nl80211: RFKILL unblocked"); | |
834ee56f | 1844 | if (i802_set_iface_flags(drv->first_bss, 1)) { |
8401a6b0 JM |
1845 | wpa_printf(MSG_DEBUG, "nl80211: Could not set interface UP " |
1846 | "after rfkill unblock"); | |
1847 | return; | |
1848 | } | |
e8dc205f AO |
1849 | |
1850 | if (is_p2p_net_interface(drv->nlmode)) | |
1851 | nl80211_disable_11b_rates(drv, drv->ifindex, 1); | |
1852 | ||
6da504a1 IP |
1853 | /* |
1854 | * rtnetlink ifup handler will report interfaces other than the P2P | |
1855 | * Device interface as enabled. | |
1856 | */ | |
1857 | if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) | |
1858 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_ENABLED, NULL); | |
8401a6b0 JM |
1859 | } |
1860 | ||
1861 | ||
32ab4855 JB |
1862 | static void wpa_driver_nl80211_handle_eapol_tx_status(int sock, |
1863 | void *eloop_ctx, | |
1864 | void *handle) | |
1865 | { | |
1866 | struct wpa_driver_nl80211_data *drv = eloop_ctx; | |
1867 | u8 data[2048]; | |
1868 | struct msghdr msg; | |
1869 | struct iovec entry; | |
cad0f50e | 1870 | u8 control[512]; |
32ab4855 JB |
1871 | struct cmsghdr *cmsg; |
1872 | int res, found_ee = 0, found_wifi = 0, acked = 0; | |
1873 | union wpa_event_data event; | |
1874 | ||
1875 | memset(&msg, 0, sizeof(msg)); | |
1876 | msg.msg_iov = &entry; | |
1877 | msg.msg_iovlen = 1; | |
1878 | entry.iov_base = data; | |
1879 | entry.iov_len = sizeof(data); | |
1880 | msg.msg_control = &control; | |
1881 | msg.msg_controllen = sizeof(control); | |
1882 | ||
1883 | res = recvmsg(sock, &msg, MSG_ERRQUEUE); | |
1884 | /* if error or not fitting 802.3 header, return */ | |
1885 | if (res < 14) | |
1886 | return; | |
1887 | ||
1888 | for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg)) | |
1889 | { | |
1890 | if (cmsg->cmsg_level == SOL_SOCKET && | |
1891 | cmsg->cmsg_type == SCM_WIFI_STATUS) { | |
1892 | int *ack; | |
1893 | ||
1894 | found_wifi = 1; | |
1895 | ack = (void *)CMSG_DATA(cmsg); | |
1896 | acked = *ack; | |
1897 | } | |
1898 | ||
1899 | if (cmsg->cmsg_level == SOL_PACKET && | |
1900 | cmsg->cmsg_type == PACKET_TX_TIMESTAMP) { | |
1901 | struct sock_extended_err *err = | |
1902 | (struct sock_extended_err *)CMSG_DATA(cmsg); | |
1903 | ||
1904 | if (err->ee_origin == SO_EE_ORIGIN_TXSTATUS) | |
1905 | found_ee = 1; | |
1906 | } | |
1907 | } | |
1908 | ||
1909 | if (!found_ee || !found_wifi) | |
1910 | return; | |
1911 | ||
1912 | memset(&event, 0, sizeof(event)); | |
1913 | event.eapol_tx_status.dst = data; | |
1914 | event.eapol_tx_status.data = data + 14; | |
1915 | event.eapol_tx_status.data_len = res - 14; | |
1916 | event.eapol_tx_status.ack = acked; | |
1917 | wpa_supplicant_event(drv->ctx, EVENT_EAPOL_TX_STATUS, &event); | |
1918 | } | |
1919 | ||
1920 | ||
cc7a48d1 JB |
1921 | static int nl80211_init_bss(struct i802_bss *bss) |
1922 | { | |
1923 | bss->nl_cb = nl_cb_alloc(NL_CB_DEFAULT); | |
1924 | if (!bss->nl_cb) | |
1925 | return -1; | |
1926 | ||
1927 | nl_cb_set(bss->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, | |
1928 | no_seq_check, NULL); | |
1929 | nl_cb_set(bss->nl_cb, NL_CB_VALID, NL_CB_CUSTOM, | |
1930 | process_bss_event, bss); | |
1931 | ||
1932 | return 0; | |
1933 | } | |
1934 | ||
1935 | ||
1936 | static void nl80211_destroy_bss(struct i802_bss *bss) | |
1937 | { | |
1938 | nl_cb_put(bss->nl_cb); | |
1939 | bss->nl_cb = NULL; | |
1940 | } | |
1941 | ||
1942 | ||
0e92fb8f JB |
1943 | static void |
1944 | wpa_driver_nl80211_drv_init_rfkill(struct wpa_driver_nl80211_data *drv) | |
1945 | { | |
1946 | struct rfkill_config *rcfg; | |
1947 | ||
1948 | if (drv->rfkill) | |
1949 | return; | |
1950 | ||
1951 | rcfg = os_zalloc(sizeof(*rcfg)); | |
1952 | if (!rcfg) | |
1953 | return; | |
1954 | ||
1955 | rcfg->ctx = drv; | |
1956 | ||
1957 | /* rfkill uses netdev sysfs for initialization. However, P2P Device is | |
1958 | * not associated with a netdev, so use the name of some other interface | |
1959 | * sharing the same wiphy as the P2P Device interface. | |
1960 | * | |
1961 | * Note: This is valid, as a P2P Device interface is always dynamically | |
1962 | * created and is created only once another wpa_s interface was added. | |
1963 | */ | |
1964 | if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) { | |
1965 | struct nl80211_global *global = drv->global; | |
1966 | struct wpa_driver_nl80211_data *tmp1; | |
1967 | ||
1968 | dl_list_for_each(tmp1, &global->interfaces, | |
1969 | struct wpa_driver_nl80211_data, list) { | |
1970 | if (drv == tmp1 || drv->wiphy_idx != tmp1->wiphy_idx || | |
1971 | !tmp1->rfkill) | |
1972 | continue; | |
1973 | ||
1974 | wpa_printf(MSG_DEBUG, | |
1975 | "nl80211: Use (%s) to initialize P2P Device rfkill", | |
1976 | tmp1->first_bss->ifname); | |
1977 | os_strlcpy(rcfg->ifname, tmp1->first_bss->ifname, | |
1978 | sizeof(rcfg->ifname)); | |
1979 | break; | |
1980 | } | |
1981 | } else { | |
1982 | os_strlcpy(rcfg->ifname, drv->first_bss->ifname, | |
1983 | sizeof(rcfg->ifname)); | |
1984 | } | |
1985 | ||
1986 | rcfg->blocked_cb = wpa_driver_nl80211_rfkill_blocked; | |
1987 | rcfg->unblocked_cb = wpa_driver_nl80211_rfkill_unblocked; | |
1988 | drv->rfkill = rfkill_init(rcfg); | |
1989 | if (!drv->rfkill) { | |
1990 | wpa_printf(MSG_DEBUG, "nl80211: RFKILL status not available"); | |
1991 | os_free(rcfg); | |
1992 | } | |
1993 | } | |
1994 | ||
1995 | ||
0d547d5f JM |
1996 | static void * wpa_driver_nl80211_drv_init(void *ctx, const char *ifname, |
1997 | void *global_priv, int hostapd, | |
0ecff8d7 JM |
1998 | const u8 *set_addr, |
1999 | const char *driver_params) | |
9fff9fdc | 2000 | { |
9fff9fdc | 2001 | struct wpa_driver_nl80211_data *drv; |
a2e40bb6 | 2002 | struct i802_bss *bss; |
9fff9fdc | 2003 | |
a5c696ad JM |
2004 | if (global_priv == NULL) |
2005 | return NULL; | |
9fff9fdc JM |
2006 | drv = os_zalloc(sizeof(*drv)); |
2007 | if (drv == NULL) | |
2008 | return NULL; | |
f2ed8023 | 2009 | drv->global = global_priv; |
9fff9fdc | 2010 | drv->ctx = ctx; |
0d547d5f JM |
2011 | drv->hostapd = !!hostapd; |
2012 | drv->eapol_sock = -1; | |
64ae2447 JM |
2013 | |
2014 | /* | |
2015 | * There is no driver capability flag for this, so assume it is | |
2016 | * supported and disable this on first attempt to use if the driver | |
2017 | * rejects the command due to missing support. | |
2018 | */ | |
2019 | drv->set_rekey_offload = 1; | |
2020 | ||
099224c1 | 2021 | drv->num_if_indices = ARRAY_SIZE(drv->default_if_indices); |
0d547d5f | 2022 | drv->if_indices = drv->default_if_indices; |
834ee56f KP |
2023 | |
2024 | drv->first_bss = os_zalloc(sizeof(*drv->first_bss)); | |
2025 | if (!drv->first_bss) { | |
2026 | os_free(drv); | |
2027 | return NULL; | |
2028 | } | |
2029 | bss = drv->first_bss; | |
a2e40bb6 | 2030 | bss->drv = drv; |
a5e1eb20 SE |
2031 | bss->ctx = ctx; |
2032 | ||
a2e40bb6 | 2033 | os_strlcpy(bss->ifname, ifname, sizeof(bss->ifname)); |
9fff9fdc JM |
2034 | drv->monitor_ifidx = -1; |
2035 | drv->monitor_sock = -1; | |
d12dab4c | 2036 | drv->eapol_tx_sock = -1; |
b1f625e0 | 2037 | drv->ap_scan_as_station = NL80211_IFTYPE_UNSPECIFIED; |
9fff9fdc | 2038 | |
cc7a48d1 JB |
2039 | if (nl80211_init_bss(bss)) |
2040 | goto failed; | |
2041 | ||
0ecff8d7 | 2042 | if (wpa_driver_nl80211_finish_drv_init(drv, set_addr, 1, driver_params)) |
bbaf0837 | 2043 | goto failed; |
7524cfb1 | 2044 | |
d12dab4c | 2045 | drv->eapol_tx_sock = socket(PF_PACKET, SOCK_DGRAM, 0); |
32ab4855 JB |
2046 | if (drv->eapol_tx_sock < 0) |
2047 | goto failed; | |
2048 | ||
2049 | if (drv->data_tx_status) { | |
2050 | int enabled = 1; | |
2051 | ||
2052 | if (setsockopt(drv->eapol_tx_sock, SOL_SOCKET, SO_WIFI_STATUS, | |
2053 | &enabled, sizeof(enabled)) < 0) { | |
2054 | wpa_printf(MSG_DEBUG, | |
2055 | "nl80211: wifi status sockopt failed\n"); | |
2056 | drv->data_tx_status = 0; | |
a11241fa JB |
2057 | if (!drv->use_monitor) |
2058 | drv->capa.flags &= | |
2059 | ~WPA_DRIVER_FLAGS_EAPOL_TX_STATUS; | |
32ab4855 JB |
2060 | } else { |
2061 | eloop_register_read_sock(drv->eapol_tx_sock, | |
2062 | wpa_driver_nl80211_handle_eapol_tx_status, | |
2063 | drv, NULL); | |
2064 | } | |
2065 | } | |
f10bfc9a | 2066 | |
dac12351 | 2067 | if (drv->global) { |
f51f54a0 | 2068 | nl80211_check_global(drv->global); |
c4bb8817 | 2069 | dl_list_add(&drv->global->interfaces, &drv->list); |
dac12351 BG |
2070 | drv->in_interface_list = 1; |
2071 | } | |
c4bb8817 | 2072 | |
a2e40bb6 | 2073 | return bss; |
7524cfb1 | 2074 | |
bbaf0837 | 2075 | failed: |
dac12351 | 2076 | wpa_driver_nl80211_deinit(bss); |
7524cfb1 JM |
2077 | return NULL; |
2078 | } | |
2079 | ||
2080 | ||
0d547d5f JM |
2081 | /** |
2082 | * wpa_driver_nl80211_init - Initialize nl80211 driver interface | |
2083 | * @ctx: context to be used when calling wpa_supplicant functions, | |
2084 | * e.g., wpa_supplicant_event() | |
2085 | * @ifname: interface name, e.g., wlan0 | |
2086 | * @global_priv: private driver global data from global_init() | |
2087 | * Returns: Pointer to private data, %NULL on failure | |
2088 | */ | |
2089 | static void * wpa_driver_nl80211_init(void *ctx, const char *ifname, | |
2090 | void *global_priv) | |
2091 | { | |
0ecff8d7 JM |
2092 | return wpa_driver_nl80211_drv_init(ctx, ifname, global_priv, 0, NULL, |
2093 | NULL); | |
0d547d5f JM |
2094 | } |
2095 | ||
2096 | ||
a11241fa | 2097 | static int nl80211_register_frame(struct i802_bss *bss, |
25ebd538 | 2098 | struct nl_sock *nl_handle, |
bd94971e | 2099 | u16 type, const u8 *match, size_t match_len) |
58f6fbe0 | 2100 | { |
a11241fa | 2101 | struct wpa_driver_nl80211_data *drv = bss->drv; |
58f6fbe0 | 2102 | struct nl_msg *msg; |
a862e4a3 | 2103 | int ret; |
880de885 | 2104 | char buf[30]; |
58f6fbe0 | 2105 | |
880de885 JM |
2106 | buf[0] = '\0'; |
2107 | wpa_snprintf_hex(buf, sizeof(buf), match, match_len); | |
dedfa440 PF |
2108 | wpa_printf(MSG_DEBUG, "nl80211: Register frame type=0x%x (%s) nl_handle=%p match=%s", |
2109 | type, fc2str(type), nl_handle, buf); | |
36488c05 | 2110 | |
d5798e43 | 2111 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_REGISTER_FRAME)) || |
a862e4a3 JM |
2112 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, type) || |
2113 | nla_put(msg, NL80211_ATTR_FRAME_MATCH, match_len, match)) { | |
2114 | nlmsg_free(msg); | |
2115 | return -1; | |
2116 | } | |
58f6fbe0 | 2117 | |
d6c9aab8 | 2118 | ret = send_and_recv(drv->global, nl_handle, msg, NULL, NULL); |
58f6fbe0 | 2119 | if (ret) { |
5582a5d1 JB |
2120 | wpa_printf(MSG_DEBUG, "nl80211: Register frame command " |
2121 | "failed (type=%u): ret=%d (%s)", | |
2122 | type, ret, strerror(-ret)); | |
2123 | wpa_hexdump(MSG_DEBUG, "nl80211: Register frame match", | |
58f6fbe0 | 2124 | match, match_len); |
58f6fbe0 | 2125 | } |
58f6fbe0 JM |
2126 | return ret; |
2127 | } | |
2128 | ||
2129 | ||
a11241fa JB |
2130 | static int nl80211_alloc_mgmt_handle(struct i802_bss *bss) |
2131 | { | |
481234cf | 2132 | if (bss->nl_mgmt) { |
a11241fa | 2133 | wpa_printf(MSG_DEBUG, "nl80211: Mgmt reporting " |
36488c05 | 2134 | "already on! (nl_mgmt=%p)", bss->nl_mgmt); |
a11241fa JB |
2135 | return -1; |
2136 | } | |
2137 | ||
ce20a370 | 2138 | bss->nl_mgmt = nl_create_handle(bss->nl_cb, "mgmt"); |
481234cf | 2139 | if (bss->nl_mgmt == NULL) |
a11241fa JB |
2140 | return -1; |
2141 | ||
a11241fa JB |
2142 | return 0; |
2143 | } | |
2144 | ||
2145 | ||
5f65e9f7 JB |
2146 | static void nl80211_mgmt_handle_register_eloop(struct i802_bss *bss) |
2147 | { | |
2148 | nl80211_register_eloop_read(&bss->nl_mgmt, | |
2149 | wpa_driver_nl80211_event_receive, | |
40a68f33 | 2150 | bss->nl_cb, 0); |
5f65e9f7 JB |
2151 | } |
2152 | ||
2153 | ||
a11241fa | 2154 | static int nl80211_register_action_frame(struct i802_bss *bss, |
bd94971e JB |
2155 | const u8 *match, size_t match_len) |
2156 | { | |
2157 | u16 type = (WLAN_FC_TYPE_MGMT << 2) | (WLAN_FC_STYPE_ACTION << 4); | |
481234cf | 2158 | return nl80211_register_frame(bss, bss->nl_mgmt, |
5582a5d1 | 2159 | type, match, match_len); |
bd94971e JB |
2160 | } |
2161 | ||
2162 | ||
40a68f33 SD |
2163 | static int nl80211_init_connect_handle(struct i802_bss *bss) |
2164 | { | |
2165 | if (bss->nl_connect) { | |
2166 | wpa_printf(MSG_DEBUG, | |
2167 | "nl80211: Connect handle already created (nl_connect=%p)", | |
2168 | bss->nl_connect); | |
2169 | return -1; | |
2170 | } | |
2171 | ||
2172 | bss->nl_connect = nl_create_handle(bss->nl_cb, "connect"); | |
2173 | if (!bss->nl_connect) | |
2174 | return -1; | |
2175 | nl80211_register_eloop_read(&bss->nl_connect, | |
2176 | wpa_driver_nl80211_event_receive, | |
2177 | bss->nl_cb, 1); | |
2178 | return 0; | |
2179 | } | |
2180 | ||
2181 | ||
a11241fa | 2182 | static int nl80211_mgmt_subscribe_non_ap(struct i802_bss *bss) |
58f6fbe0 | 2183 | { |
a11241fa | 2184 | struct wpa_driver_nl80211_data *drv = bss->drv; |
6f06766e | 2185 | int ret = 0; |
a11241fa JB |
2186 | |
2187 | if (nl80211_alloc_mgmt_handle(bss)) | |
2188 | return -1; | |
36488c05 JM |
2189 | wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with non-AP " |
2190 | "handle %p", bss->nl_mgmt); | |
a11241fa | 2191 | |
ba71cb82 SD |
2192 | if (drv->nlmode == NL80211_IFTYPE_ADHOC || |
2193 | ((drv->capa.flags & WPA_DRIVER_FLAGS_SAE) && | |
2194 | !(drv->capa.flags & WPA_DRIVER_FLAGS_SME))) { | |
e8d1168b JB |
2195 | u16 type = (WLAN_FC_TYPE_MGMT << 2) | (WLAN_FC_STYPE_AUTH << 4); |
2196 | ||
2197 | /* register for any AUTH message */ | |
2198 | nl80211_register_frame(bss, bss->nl_mgmt, type, NULL, 0); | |
2199 | } | |
2200 | ||
56f5af48 JM |
2201 | #ifdef CONFIG_INTERWORKING |
2202 | /* QoS Map Configure */ | |
2203 | if (nl80211_register_action_frame(bss, (u8 *) "\x01\x04", 2) < 0) | |
6f06766e | 2204 | ret = -1; |
56f5af48 | 2205 | #endif /* CONFIG_INTERWORKING */ |
00b02149 | 2206 | #if defined(CONFIG_P2P) || defined(CONFIG_INTERWORKING) || defined(CONFIG_DPP) |
046b26a2 | 2207 | /* GAS Initial Request */ |
a11241fa | 2208 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0a", 2) < 0) |
6f06766e | 2209 | ret = -1; |
046b26a2 | 2210 | /* GAS Initial Response */ |
a11241fa | 2211 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0b", 2) < 0) |
6f06766e | 2212 | ret = -1; |
18708aad | 2213 | /* GAS Comeback Request */ |
a11241fa | 2214 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0c", 2) < 0) |
6f06766e | 2215 | ret = -1; |
18708aad | 2216 | /* GAS Comeback Response */ |
a11241fa | 2217 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0d", 2) < 0) |
6f06766e | 2218 | ret = -1; |
c5a64e2d JM |
2219 | /* Protected GAS Initial Request */ |
2220 | if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0a", 2) < 0) | |
2221 | ret = -1; | |
2222 | /* Protected GAS Initial Response */ | |
2223 | if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0b", 2) < 0) | |
2224 | ret = -1; | |
2225 | /* Protected GAS Comeback Request */ | |
2226 | if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0c", 2) < 0) | |
2227 | ret = -1; | |
2228 | /* Protected GAS Comeback Response */ | |
2229 | if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0d", 2) < 0) | |
2230 | ret = -1; | |
00b02149 | 2231 | #endif /* CONFIG_P2P || CONFIG_INTERWORKING || CONFIG_DPP */ |
4fe9fa0d | 2232 | #ifdef CONFIG_P2P |
046b26a2 | 2233 | /* P2P Public Action */ |
a11241fa | 2234 | if (nl80211_register_action_frame(bss, |
046b26a2 JM |
2235 | (u8 *) "\x04\x09\x50\x6f\x9a\x09", |
2236 | 6) < 0) | |
6f06766e | 2237 | ret = -1; |
046b26a2 | 2238 | /* P2P Action */ |
a11241fa | 2239 | if (nl80211_register_action_frame(bss, |
046b26a2 JM |
2240 | (u8 *) "\x7f\x50\x6f\x9a\x09", |
2241 | 5) < 0) | |
6f06766e | 2242 | ret = -1; |
046b26a2 | 2243 | #endif /* CONFIG_P2P */ |
00b02149 JM |
2244 | #ifdef CONFIG_DPP |
2245 | /* DPP Public Action */ | |
2246 | if (nl80211_register_action_frame(bss, | |
2247 | (u8 *) "\x04\x09\x50\x6f\x9a\x1a", | |
2248 | 6) < 0) | |
2249 | ret = -1; | |
2250 | #endif /* CONFIG_DPP */ | |
f9da7505 MV |
2251 | #ifdef CONFIG_OCV |
2252 | /* SA Query Request */ | |
2253 | if (nl80211_register_action_frame(bss, (u8 *) "\x08\x00", 2) < 0) | |
2254 | ret = -1; | |
2255 | #endif /* CONFIG_OCV */ | |
7d878ca7 | 2256 | /* SA Query Response */ |
a11241fa | 2257 | if (nl80211_register_action_frame(bss, (u8 *) "\x08\x01", 2) < 0) |
6f06766e | 2258 | ret = -1; |
35287637 AN |
2259 | #ifdef CONFIG_TDLS |
2260 | if ((drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) { | |
2261 | /* TDLS Discovery Response */ | |
aa543c0c | 2262 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0e", 2) < |
35287637 | 2263 | 0) |
6f06766e | 2264 | ret = -1; |
35287637 AN |
2265 | } |
2266 | #endif /* CONFIG_TDLS */ | |
46ab9b8c AN |
2267 | #ifdef CONFIG_FST |
2268 | /* FST Action frames */ | |
2269 | if (nl80211_register_action_frame(bss, (u8 *) "\x12", 1) < 0) | |
2270 | ret = -1; | |
2271 | #endif /* CONFIG_FST */ | |
046b26a2 | 2272 | |
7b90c16a | 2273 | /* FT Action frames */ |
a11241fa | 2274 | if (nl80211_register_action_frame(bss, (u8 *) "\x06", 1) < 0) |
6f06766e | 2275 | ret = -1; |
7b90c16a JM |
2276 | else |
2277 | drv->capa.key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FT | | |
2278 | WPA_DRIVER_CAPA_KEY_MGMT_FT_PSK; | |
2279 | ||
71269b37 | 2280 | /* WNM - BSS Transition Management Request */ |
a11241fa | 2281 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x07", 2) < 0) |
6f06766e | 2282 | ret = -1; |
bd896433 JM |
2283 | /* WNM-Sleep Mode Response */ |
2284 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x11", 2) < 0) | |
6f06766e | 2285 | ret = -1; |
d514b502 JM |
2286 | #ifdef CONFIG_WNM |
2287 | /* WNM - Collocated Interference Request */ | |
2288 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x0b", 2) < 0) | |
2289 | ret = -1; | |
2290 | #endif /* CONFIG_WNM */ | |
a11241fa | 2291 | |
95a3ea94 JM |
2292 | #ifdef CONFIG_HS20 |
2293 | /* WNM-Notification */ | |
2294 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x1a", 2) < 0) | |
3ee18569 | 2295 | ret = -1; |
95a3ea94 JM |
2296 | #endif /* CONFIG_HS20 */ |
2297 | ||
dfa87878 MB |
2298 | /* WMM-AC ADDTS Response */ |
2299 | if (nl80211_register_action_frame(bss, (u8 *) "\x11\x01", 2) < 0) | |
730a0d16 | 2300 | ret = -1; |
dfa87878 MB |
2301 | |
2302 | /* WMM-AC DELTS */ | |
2303 | if (nl80211_register_action_frame(bss, (u8 *) "\x11\x02", 2) < 0) | |
730a0d16 | 2304 | ret = -1; |
dfa87878 | 2305 | |
2526ccd9 AK |
2306 | /* Radio Measurement - Neighbor Report Response */ |
2307 | if (nl80211_register_action_frame(bss, (u8 *) "\x05\x05", 2) < 0) | |
2308 | ret = -1; | |
2309 | ||
864b9522 DS |
2310 | /* Radio Measurement - Radio Measurement Request */ |
2311 | if (nl80211_register_action_frame(bss, (u8 *) "\x05\x00", 2) < 0) | |
2312 | ret = -1; | |
2313 | ||
7dc03388 AO |
2314 | /* Radio Measurement - Link Measurement Request */ |
2315 | if ((drv->capa.rrm_flags & WPA_DRIVER_FLAGS_TX_POWER_INSERTION) && | |
2316 | (nl80211_register_action_frame(bss, (u8 *) "\x05\x02", 2) < 0)) | |
2317 | ret = -1; | |
2318 | ||
5f65e9f7 JB |
2319 | nl80211_mgmt_handle_register_eloop(bss); |
2320 | ||
6f06766e | 2321 | return ret; |
a11241fa JB |
2322 | } |
2323 | ||
2324 | ||
afb0550a BC |
2325 | static int nl80211_mgmt_subscribe_mesh(struct i802_bss *bss) |
2326 | { | |
2327 | int ret = 0; | |
2328 | ||
2329 | if (nl80211_alloc_mgmt_handle(bss)) | |
2330 | return -1; | |
2331 | ||
2332 | wpa_printf(MSG_DEBUG, | |
2333 | "nl80211: Subscribe to mgmt frames with mesh handle %p", | |
2334 | bss->nl_mgmt); | |
2335 | ||
2336 | /* Auth frames for mesh SAE */ | |
2337 | if (nl80211_register_frame(bss, bss->nl_mgmt, | |
2338 | (WLAN_FC_TYPE_MGMT << 2) | | |
2339 | (WLAN_FC_STYPE_AUTH << 4), | |
2340 | NULL, 0) < 0) | |
2341 | ret = -1; | |
2342 | ||
2343 | /* Mesh peering open */ | |
2344 | if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x01", 2) < 0) | |
2345 | ret = -1; | |
2346 | /* Mesh peering confirm */ | |
2347 | if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x02", 2) < 0) | |
2348 | ret = -1; | |
2349 | /* Mesh peering close */ | |
2350 | if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x03", 2) < 0) | |
2351 | ret = -1; | |
2352 | ||
2353 | nl80211_mgmt_handle_register_eloop(bss); | |
2354 | ||
2355 | return ret; | |
2356 | } | |
2357 | ||
2358 | ||
02bb32c3 JB |
2359 | static int nl80211_register_spurious_class3(struct i802_bss *bss) |
2360 | { | |
02bb32c3 | 2361 | struct nl_msg *msg; |
a862e4a3 | 2362 | int ret; |
02bb32c3 | 2363 | |
13f83980 JM |
2364 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_UNEXPECTED_FRAME); |
2365 | ret = send_and_recv(bss->drv->global, bss->nl_mgmt, msg, NULL, NULL); | |
02bb32c3 JB |
2366 | if (ret) { |
2367 | wpa_printf(MSG_DEBUG, "nl80211: Register spurious class3 " | |
2368 | "failed: ret=%d (%s)", | |
2369 | ret, strerror(-ret)); | |
02bb32c3 | 2370 | } |
02bb32c3 JB |
2371 | return ret; |
2372 | } | |
2373 | ||
2374 | ||
4d916ed6 KV |
2375 | static int nl80211_action_subscribe_ap(struct i802_bss *bss) |
2376 | { | |
2377 | int ret = 0; | |
2378 | ||
2379 | /* Public Action frames */ | |
2380 | if (nl80211_register_action_frame(bss, (u8 *) "\x04", 1) < 0) | |
2381 | ret = -1; | |
2382 | /* RRM Measurement Report */ | |
2383 | if (nl80211_register_action_frame(bss, (u8 *) "\x05\x01", 2) < 0) | |
2384 | ret = -1; | |
e4ec6bbf JM |
2385 | /* RRM Link Measurement Report */ |
2386 | if (nl80211_register_action_frame(bss, (u8 *) "\x05\x03", 2) < 0) | |
2387 | ret = -1; | |
4d916ed6 KV |
2388 | /* RRM Neighbor Report Request */ |
2389 | if (nl80211_register_action_frame(bss, (u8 *) "\x05\x04", 2) < 0) | |
2390 | ret = -1; | |
2391 | /* FT Action frames */ | |
2392 | if (nl80211_register_action_frame(bss, (u8 *) "\x06", 1) < 0) | |
2393 | ret = -1; | |
4d916ed6 KV |
2394 | /* SA Query */ |
2395 | if (nl80211_register_action_frame(bss, (u8 *) "\x08", 1) < 0) | |
2396 | ret = -1; | |
4d916ed6 KV |
2397 | /* Protected Dual of Public Action */ |
2398 | if (nl80211_register_action_frame(bss, (u8 *) "\x09", 1) < 0) | |
2399 | ret = -1; | |
2400 | /* WNM */ | |
2401 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a", 1) < 0) | |
2402 | ret = -1; | |
2403 | /* WMM */ | |
2404 | if (nl80211_register_action_frame(bss, (u8 *) "\x11", 1) < 0) | |
2405 | ret = -1; | |
2406 | #ifdef CONFIG_FST | |
2407 | /* FST Action frames */ | |
2408 | if (nl80211_register_action_frame(bss, (u8 *) "\x12", 1) < 0) | |
2409 | ret = -1; | |
2410 | #endif /* CONFIG_FST */ | |
2411 | /* Vendor-specific */ | |
2412 | if (nl80211_register_action_frame(bss, (u8 *) "\x7f", 1) < 0) | |
2413 | ret = -1; | |
2414 | ||
2415 | return ret; | |
2416 | } | |
2417 | ||
2418 | ||
a11241fa JB |
2419 | static int nl80211_mgmt_subscribe_ap(struct i802_bss *bss) |
2420 | { | |
2421 | static const int stypes[] = { | |
2422 | WLAN_FC_STYPE_AUTH, | |
2423 | WLAN_FC_STYPE_ASSOC_REQ, | |
2424 | WLAN_FC_STYPE_REASSOC_REQ, | |
2425 | WLAN_FC_STYPE_DISASSOC, | |
2426 | WLAN_FC_STYPE_DEAUTH, | |
a11241fa JB |
2427 | WLAN_FC_STYPE_PROBE_REQ, |
2428 | /* Beacon doesn't work as mac80211 doesn't currently allow | |
2429 | * it, but it wouldn't really be the right thing anyway as | |
2430 | * it isn't per interface ... maybe just dump the scan | |
2431 | * results periodically for OLBC? | |
2432 | */ | |
0e80ea2c | 2433 | /* WLAN_FC_STYPE_BEACON, */ |
a11241fa JB |
2434 | }; |
2435 | unsigned int i; | |
2436 | ||
2437 | if (nl80211_alloc_mgmt_handle(bss)) | |
71269b37 | 2438 | return -1; |
36488c05 JM |
2439 | wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with AP " |
2440 | "handle %p", bss->nl_mgmt); | |
71269b37 | 2441 | |
e7ecab4a | 2442 | for (i = 0; i < ARRAY_SIZE(stypes); i++) { |
481234cf | 2443 | if (nl80211_register_frame(bss, bss->nl_mgmt, |
a11241fa JB |
2444 | (WLAN_FC_TYPE_MGMT << 2) | |
2445 | (stypes[i] << 4), | |
2446 | NULL, 0) < 0) { | |
2447 | goto out_err; | |
2448 | } | |
2449 | } | |
2450 | ||
4d916ed6 KV |
2451 | if (nl80211_action_subscribe_ap(bss)) |
2452 | goto out_err; | |
2453 | ||
02bb32c3 JB |
2454 | if (nl80211_register_spurious_class3(bss)) |
2455 | goto out_err; | |
2456 | ||
5f65e9f7 | 2457 | nl80211_mgmt_handle_register_eloop(bss); |
58f6fbe0 | 2458 | return 0; |
a11241fa JB |
2459 | |
2460 | out_err: | |
a11241fa JB |
2461 | nl_destroy_handles(&bss->nl_mgmt); |
2462 | return -1; | |
2463 | } | |
2464 | ||
2465 | ||
a6cc0602 JM |
2466 | static int nl80211_mgmt_subscribe_ap_dev_sme(struct i802_bss *bss) |
2467 | { | |
2468 | if (nl80211_alloc_mgmt_handle(bss)) | |
2469 | return -1; | |
2470 | wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with AP " | |
2471 | "handle %p (device SME)", bss->nl_mgmt); | |
2472 | ||
4d916ed6 | 2473 | if (nl80211_action_subscribe_ap(bss)) |
a6cc0602 JM |
2474 | goto out_err; |
2475 | ||
236e793e SD |
2476 | if (bss->drv->device_ap_sme) { |
2477 | u16 type = (WLAN_FC_TYPE_MGMT << 2) | (WLAN_FC_STYPE_AUTH << 4); | |
2478 | ||
2479 | /* Register for all Authentication frames */ | |
2480 | if (nl80211_register_frame(bss, bss->nl_mgmt, type, NULL, 0) | |
2481 | < 0) | |
2482 | wpa_printf(MSG_DEBUG, | |
2483 | "nl80211: Failed to subscribe to handle Authentication frames - SAE offload may not work"); | |
2484 | } | |
2485 | ||
5f65e9f7 | 2486 | nl80211_mgmt_handle_register_eloop(bss); |
a6cc0602 JM |
2487 | return 0; |
2488 | ||
2489 | out_err: | |
a6cc0602 JM |
2490 | nl_destroy_handles(&bss->nl_mgmt); |
2491 | return -1; | |
2492 | } | |
2493 | ||
2494 | ||
36488c05 | 2495 | static void nl80211_mgmt_unsubscribe(struct i802_bss *bss, const char *reason) |
a11241fa | 2496 | { |
481234cf | 2497 | if (bss->nl_mgmt == NULL) |
a11241fa | 2498 | return; |
36488c05 JM |
2499 | wpa_printf(MSG_DEBUG, "nl80211: Unsubscribe mgmt frames handle %p " |
2500 | "(%s)", bss->nl_mgmt, reason); | |
40a68f33 | 2501 | nl80211_destroy_eloop_handle(&bss->nl_mgmt, 0); |
7813b7c3 MH |
2502 | |
2503 | nl80211_put_wiphy_data_ap(bss); | |
58f6fbe0 JM |
2504 | } |
2505 | ||
2506 | ||
8401a6b0 JM |
2507 | static void wpa_driver_nl80211_send_rfkill(void *eloop_ctx, void *timeout_ctx) |
2508 | { | |
2509 | wpa_supplicant_event(timeout_ctx, EVENT_INTERFACE_DISABLED, NULL); | |
2510 | } | |
2511 | ||
2512 | ||
eb4582f2 AS |
2513 | static void nl80211_del_p2pdev(struct i802_bss *bss) |
2514 | { | |
eb4582f2 AS |
2515 | struct nl_msg *msg; |
2516 | int ret; | |
2517 | ||
a3249fdf JM |
2518 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_DEL_INTERFACE); |
2519 | ret = send_and_recv_msgs(bss->drv, msg, NULL, NULL); | |
eb4582f2 AS |
2520 | |
2521 | wpa_printf(MSG_DEBUG, "nl80211: Delete P2P Device %s (0x%llx): %s", | |
2522 | bss->ifname, (long long unsigned int) bss->wdev_id, | |
6cb4f11d | 2523 | strerror(-ret)); |
eb4582f2 AS |
2524 | } |
2525 | ||
2526 | ||
eb4582f2 | 2527 | static int nl80211_set_p2pdev(struct i802_bss *bss, int start) |
f632e483 | 2528 | { |
f632e483 | 2529 | struct nl_msg *msg; |
a862e4a3 | 2530 | int ret; |
f632e483 | 2531 | |
a3249fdf JM |
2532 | msg = nl80211_cmd_msg(bss, 0, start ? NL80211_CMD_START_P2P_DEVICE : |
2533 | NL80211_CMD_STOP_P2P_DEVICE); | |
2534 | ret = send_and_recv_msgs(bss->drv, msg, NULL, NULL); | |
f632e483 | 2535 | |
eb4582f2 AS |
2536 | wpa_printf(MSG_DEBUG, "nl80211: %s P2P Device %s (0x%llx): %s", |
2537 | start ? "Start" : "Stop", | |
2538 | bss->ifname, (long long unsigned int) bss->wdev_id, | |
6cb4f11d | 2539 | strerror(-ret)); |
f632e483 AS |
2540 | return ret; |
2541 | } | |
f632e483 AS |
2542 | |
2543 | ||
91724d6f AS |
2544 | static int i802_set_iface_flags(struct i802_bss *bss, int up) |
2545 | { | |
2546 | enum nl80211_iftype nlmode; | |
2547 | ||
2548 | nlmode = nl80211_get_ifmode(bss); | |
2549 | if (nlmode != NL80211_IFTYPE_P2P_DEVICE) { | |
2550 | return linux_set_iface_flags(bss->drv->global->ioctl_sock, | |
2551 | bss->ifname, up); | |
2552 | } | |
2553 | ||
2554 | /* P2P Device has start/stop which is equivalent */ | |
2555 | return nl80211_set_p2pdev(bss, up); | |
2556 | } | |
2557 | ||
2558 | ||
1db718b3 JM |
2559 | #ifdef CONFIG_TESTING_OPTIONS |
2560 | static int qca_vendor_test_cmd_handler(struct nl_msg *msg, void *arg) | |
2561 | { | |
2562 | /* struct wpa_driver_nl80211_data *drv = arg; */ | |
2563 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
2564 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
2565 | ||
2566 | ||
2567 | wpa_printf(MSG_DEBUG, | |
2568 | "nl80211: QCA vendor test command response received"); | |
2569 | ||
2570 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
2571 | genlmsg_attrlen(gnlh, 0), NULL); | |
2572 | if (!tb[NL80211_ATTR_VENDOR_DATA]) { | |
2573 | wpa_printf(MSG_DEBUG, "nl80211: No vendor data attribute"); | |
2574 | return NL_SKIP; | |
2575 | } | |
2576 | ||
2577 | wpa_hexdump(MSG_DEBUG, | |
2578 | "nl80211: Received QCA vendor test command response", | |
2579 | nla_data(tb[NL80211_ATTR_VENDOR_DATA]), | |
2580 | nla_len(tb[NL80211_ATTR_VENDOR_DATA])); | |
2581 | ||
2582 | return NL_SKIP; | |
2583 | } | |
2584 | #endif /* CONFIG_TESTING_OPTIONS */ | |
2585 | ||
2586 | ||
2587 | static void qca_vendor_test(struct wpa_driver_nl80211_data *drv) | |
2588 | { | |
2589 | #ifdef CONFIG_TESTING_OPTIONS | |
2590 | struct nl_msg *msg; | |
2591 | struct nlattr *params; | |
2592 | int ret; | |
2593 | ||
2594 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || | |
2595 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || | |
2596 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | |
2597 | QCA_NL80211_VENDOR_SUBCMD_TEST) || | |
2598 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || | |
2599 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TEST, 123)) { | |
2600 | nlmsg_free(msg); | |
2601 | return; | |
2602 | } | |
2603 | nla_nest_end(msg, params); | |
2604 | ||
2605 | ret = send_and_recv_msgs(drv, msg, qca_vendor_test_cmd_handler, drv); | |
2606 | wpa_printf(MSG_DEBUG, | |
2607 | "nl80211: QCA vendor test command returned %d (%s)", | |
2608 | ret, strerror(-ret)); | |
2609 | #endif /* CONFIG_TESTING_OPTIONS */ | |
2610 | } | |
2611 | ||
2612 | ||
362f781e | 2613 | static int |
0d547d5f | 2614 | wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data *drv, |
0ecff8d7 JM |
2615 | const u8 *set_addr, int first, |
2616 | const char *driver_params) | |
7524cfb1 | 2617 | { |
834ee56f | 2618 | struct i802_bss *bss = drv->first_bss; |
8401a6b0 | 2619 | int send_rfkill_event = 0; |
0d547d5f | 2620 | enum nl80211_iftype nlmode; |
a2e40bb6 FF |
2621 | |
2622 | drv->ifindex = if_nametoindex(bss->ifname); | |
f632e483 AS |
2623 | bss->ifindex = drv->ifindex; |
2624 | bss->wdev_id = drv->global->if_add_wdevid; | |
2625 | bss->wdev_id_set = drv->global->if_add_wdevid_set; | |
2626 | ||
60b13c20 IP |
2627 | bss->if_dynamic = drv->ifindex == drv->global->if_add_ifindex; |
2628 | bss->if_dynamic = bss->if_dynamic || drv->global->if_add_wdevid_set; | |
f632e483 AS |
2629 | drv->global->if_add_wdevid_set = 0; |
2630 | ||
bf144cf6 AP |
2631 | if (!bss->if_dynamic && nl80211_get_ifmode(bss) == NL80211_IFTYPE_AP) |
2632 | bss->static_ap = 1; | |
2633 | ||
ef3866ab IP |
2634 | if (first && |
2635 | nl80211_get_ifmode(bss) != NL80211_IFTYPE_P2P_DEVICE && | |
2636 | linux_iface_up(drv->global->ioctl_sock, bss->ifname) > 0) | |
2637 | drv->start_iface_up = 1; | |
2638 | ||
f632e483 AS |
2639 | if (wpa_driver_nl80211_capa(drv)) |
2640 | return -1; | |
a87c9d96 | 2641 | |
0ecff8d7 JM |
2642 | if (driver_params && nl80211_set_param(bss, driver_params) < 0) |
2643 | return -1; | |
2644 | ||
5fbcb45d AS |
2645 | wpa_printf(MSG_DEBUG, "nl80211: interface %s in phy %s", |
2646 | bss->ifname, drv->phyname); | |
2647 | ||
0d547d5f JM |
2648 | if (set_addr && |
2649 | (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 0) || | |
2650 | linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname, | |
2651 | set_addr))) | |
2652 | return -1; | |
2653 | ||
49b4b205 JM |
2654 | if (first && nl80211_get_ifmode(bss) == NL80211_IFTYPE_AP) |
2655 | drv->start_mode_ap = 1; | |
2656 | ||
bf144cf6 | 2657 | if (drv->hostapd || bss->static_ap) |
0d547d5f | 2658 | nlmode = NL80211_IFTYPE_AP; |
4fe726e2 FF |
2659 | else if (bss->if_dynamic || |
2660 | nl80211_get_ifmode(bss) == NL80211_IFTYPE_MESH_POINT) | |
8e12685c | 2661 | nlmode = nl80211_get_ifmode(bss); |
0d547d5f JM |
2662 | else |
2663 | nlmode = NL80211_IFTYPE_STATION; | |
f632e483 | 2664 | |
8e12685c | 2665 | if (wpa_driver_nl80211_set_mode(bss, nlmode) < 0) { |
0d547d5f | 2666 | wpa_printf(MSG_ERROR, "nl80211: Could not configure driver mode"); |
8e12685c | 2667 | return -1; |
a87c9d96 JM |
2668 | } |
2669 | ||
8c06db70 | 2670 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) |
597b94f5 | 2671 | nl80211_get_macaddr(bss); |
f632e483 | 2672 | |
0e92fb8f JB |
2673 | wpa_driver_nl80211_drv_init_rfkill(drv); |
2674 | ||
8c06db70 MB |
2675 | if (!rfkill_is_blocked(drv->rfkill)) { |
2676 | int ret = i802_set_iface_flags(bss, 1); | |
2677 | if (ret) { | |
8401a6b0 JM |
2678 | wpa_printf(MSG_ERROR, "nl80211: Could not set " |
2679 | "interface '%s' UP", bss->ifname); | |
8c06db70 | 2680 | return ret; |
8401a6b0 | 2681 | } |
e8dc205f AO |
2682 | |
2683 | if (is_p2p_net_interface(nlmode)) | |
2684 | nl80211_disable_11b_rates(bss->drv, | |
2685 | bss->drv->ifindex, 1); | |
2686 | ||
8c06db70 MB |
2687 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) |
2688 | return ret; | |
2689 | } else { | |
2690 | wpa_printf(MSG_DEBUG, "nl80211: Could not yet enable " | |
2691 | "interface '%s' due to rfkill", bss->ifname); | |
6da504a1 IP |
2692 | if (nlmode != NL80211_IFTYPE_P2P_DEVICE) |
2693 | drv->if_disabled = 1; | |
2694 | ||
8c06db70 | 2695 | send_rfkill_event = 1; |
362f781e | 2696 | } |
3f5285e8 | 2697 | |
6da504a1 | 2698 | if (!drv->hostapd && nlmode != NL80211_IFTYPE_P2P_DEVICE) |
0d547d5f JM |
2699 | netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, |
2700 | 1, IF_OPER_DORMANT); | |
362f781e | 2701 | |
6da504a1 IP |
2702 | if (nlmode != NL80211_IFTYPE_P2P_DEVICE) { |
2703 | if (linux_get_ifhwaddr(drv->global->ioctl_sock, bss->ifname, | |
2704 | bss->addr)) | |
2705 | return -1; | |
2706 | os_memcpy(drv->perm_addr, bss->addr, ETH_ALEN); | |
2707 | } | |
f2ed8023 | 2708 | |
8401a6b0 JM |
2709 | if (send_rfkill_event) { |
2710 | eloop_register_timeout(0, 0, wpa_driver_nl80211_send_rfkill, | |
2711 | drv, drv->ctx); | |
2712 | } | |
2713 | ||
1db718b3 JM |
2714 | if (drv->vendor_cmd_test_avail) |
2715 | qca_vendor_test(drv); | |
2716 | ||
40a68f33 SD |
2717 | nl80211_init_connect_handle(bss); |
2718 | ||
362f781e | 2719 | return 0; |
3f5285e8 JM |
2720 | } |
2721 | ||
2722 | ||
a70cd0db | 2723 | static int wpa_driver_nl80211_del_beacon(struct i802_bss *bss) |
8a27af5c JM |
2724 | { |
2725 | struct nl_msg *msg; | |
a70cd0db | 2726 | struct wpa_driver_nl80211_data *drv = bss->drv; |
8a27af5c | 2727 | |
08e55ebb JM |
2728 | wpa_printf(MSG_DEBUG, "nl80211: Remove beacon (ifindex=%d)", |
2729 | drv->ifindex); | |
a70cd0db | 2730 | nl80211_put_wiphy_data_ap(bss); |
9725b784 | 2731 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_DEL_BEACON); |
8a27af5c | 2732 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
8a27af5c | 2733 | } |
8a27af5c JM |
2734 | |
2735 | ||
3f5285e8 | 2736 | /** |
7e5ba1b9 | 2737 | * wpa_driver_nl80211_deinit - Deinitialize nl80211 driver interface |
9ebce9c5 | 2738 | * @bss: Pointer to private nl80211 data from wpa_driver_nl80211_init() |
3f5285e8 JM |
2739 | * |
2740 | * Shut down driver interface and processing of driver events. Free | |
2741 | * private data buffer if one was allocated in wpa_driver_nl80211_init(). | |
2742 | */ | |
9ebce9c5 | 2743 | static void wpa_driver_nl80211_deinit(struct i802_bss *bss) |
3f5285e8 | 2744 | { |
a2e40bb6 | 2745 | struct wpa_driver_nl80211_data *drv = bss->drv; |
cc9a2575 | 2746 | unsigned int i; |
3f5285e8 | 2747 | |
3e208481 JM |
2748 | wpa_printf(MSG_INFO, "nl80211: deinit ifname=%s disabled_11b_rates=%d", |
2749 | bss->ifname, drv->disabled_11b_rates); | |
2750 | ||
873d0fcf | 2751 | bss->in_deinit = 1; |
32ab4855 JB |
2752 | if (drv->data_tx_status) |
2753 | eloop_unregister_read_sock(drv->eapol_tx_sock); | |
d12dab4c JB |
2754 | if (drv->eapol_tx_sock >= 0) |
2755 | close(drv->eapol_tx_sock); | |
f10bfc9a | 2756 | |
481234cf | 2757 | if (bss->nl_preq) |
5582a5d1 | 2758 | wpa_driver_nl80211_probe_req_report(bss, 0); |
e17a2477 | 2759 | if (bss->added_if_into_bridge) { |
c81eff1a BG |
2760 | if (linux_br_del_if(drv->global->ioctl_sock, bss->brname, |
2761 | bss->ifname) < 0) | |
94627f6c JM |
2762 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
2763 | "interface %s from bridge %s: %s", | |
e17a2477 | 2764 | bss->ifname, bss->brname, strerror(errno)); |
94627f6c | 2765 | } |
c809756f SM |
2766 | |
2767 | if (drv->rtnl_sk) | |
25ebd538 | 2768 | nl_socket_free(drv->rtnl_sk); |
c809756f | 2769 | |
e17a2477 | 2770 | if (bss->added_bridge) { |
f2535da8 JM |
2771 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->brname, |
2772 | 0) < 0) | |
2773 | wpa_printf(MSG_INFO, | |
2774 | "nl80211: Could not set bridge %s down", | |
2775 | bss->brname); | |
c81eff1a | 2776 | if (linux_br_del(drv->global->ioctl_sock, bss->brname) < 0) |
94627f6c JM |
2777 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
2778 | "bridge %s: %s", | |
e17a2477 | 2779 | bss->brname, strerror(errno)); |
94627f6c JM |
2780 | } |
2781 | ||
460456f8 | 2782 | nl80211_remove_monitor_interface(drv); |
8a27af5c | 2783 | |
b1f625e0 | 2784 | if (is_ap_interface(drv->nlmode)) |
a70cd0db | 2785 | wpa_driver_nl80211_del_beacon(bss); |
0915d02c | 2786 | |
bbaf0837 JM |
2787 | if (drv->eapol_sock >= 0) { |
2788 | eloop_unregister_read_sock(drv->eapol_sock); | |
2789 | close(drv->eapol_sock); | |
2790 | } | |
2791 | ||
2792 | if (drv->if_indices != drv->default_if_indices) | |
2793 | os_free(drv->if_indices); | |
3f5285e8 | 2794 | |
b3af99d2 | 2795 | if (drv->disabled_11b_rates) |
4e5cb1a3 JM |
2796 | nl80211_disable_11b_rates(drv, drv->ifindex, 0); |
2797 | ||
36d84860 BG |
2798 | netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, 0, |
2799 | IF_OPER_UP); | |
e390df05 | 2800 | eloop_cancel_timeout(wpa_driver_nl80211_send_rfkill, drv, drv->ctx); |
8401a6b0 | 2801 | rfkill_deinit(drv->rfkill); |
3f5285e8 | 2802 | |
bbaf0837 JM |
2803 | eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout, drv, drv->ctx); |
2804 | ||
146fa9b3 JM |
2805 | if (!drv->start_iface_up) |
2806 | (void) i802_set_iface_flags(bss, 0); | |
fee354c7 JM |
2807 | |
2808 | if (drv->addr_changed) { | |
93da0498 JM |
2809 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, |
2810 | 0) < 0) { | |
2811 | wpa_printf(MSG_DEBUG, | |
2812 | "nl80211: Could not set interface down to restore permanent MAC address"); | |
2813 | } | |
fee354c7 JM |
2814 | if (linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
2815 | drv->perm_addr) < 0) { | |
2816 | wpa_printf(MSG_DEBUG, | |
2817 | "nl80211: Could not restore permanent MAC address"); | |
2818 | } | |
2819 | } | |
2820 | ||
8e12685c | 2821 | if (drv->nlmode != NL80211_IFTYPE_P2P_DEVICE) { |
49b4b205 JM |
2822 | if (!drv->hostapd || !drv->start_mode_ap) |
2823 | wpa_driver_nl80211_set_mode(bss, | |
2824 | NL80211_IFTYPE_STATION); | |
b378c41f | 2825 | nl80211_mgmt_unsubscribe(bss, "deinit"); |
8e12685c AS |
2826 | } else { |
2827 | nl80211_mgmt_unsubscribe(bss, "deinit"); | |
eb4582f2 | 2828 | nl80211_del_p2pdev(bss); |
8e12685c | 2829 | } |
3f5285e8 | 2830 | |
40a68f33 SD |
2831 | if (bss->nl_connect) |
2832 | nl80211_destroy_eloop_handle(&bss->nl_connect, 1); | |
2833 | ||
834ee56f | 2834 | nl80211_destroy_bss(drv->first_bss); |
cc7a48d1 | 2835 | |
3812464c JM |
2836 | os_free(drv->filter_ssids); |
2837 | ||
536fd62d JM |
2838 | os_free(drv->auth_ie); |
2839 | ||
dac12351 | 2840 | if (drv->in_interface_list) |
f2ed8023 JM |
2841 | dl_list_del(&drv->list); |
2842 | ||
8cd6b7bc JB |
2843 | os_free(drv->extended_capa); |
2844 | os_free(drv->extended_capa_mask); | |
cc9a2575 KV |
2845 | for (i = 0; i < drv->num_iface_ext_capa; i++) { |
2846 | os_free(drv->iface_ext_capa[i].ext_capa); | |
2847 | os_free(drv->iface_ext_capa[i].ext_capa_mask); | |
2848 | } | |
834ee56f | 2849 | os_free(drv->first_bss); |
3f5285e8 JM |
2850 | os_free(drv); |
2851 | } | |
2852 | ||
2853 | ||
de4ed4a8 JM |
2854 | static u32 wpa_alg_to_cipher_suite(enum wpa_alg alg, size_t key_len) |
2855 | { | |
2856 | switch (alg) { | |
2857 | case WPA_ALG_WEP: | |
2858 | if (key_len == 5) | |
a042e39a JM |
2859 | return RSN_CIPHER_SUITE_WEP40; |
2860 | return RSN_CIPHER_SUITE_WEP104; | |
de4ed4a8 | 2861 | case WPA_ALG_TKIP: |
a042e39a | 2862 | return RSN_CIPHER_SUITE_TKIP; |
de4ed4a8 | 2863 | case WPA_ALG_CCMP: |
a042e39a | 2864 | return RSN_CIPHER_SUITE_CCMP; |
de4ed4a8 | 2865 | case WPA_ALG_GCMP: |
a042e39a | 2866 | return RSN_CIPHER_SUITE_GCMP; |
de4ed4a8 | 2867 | case WPA_ALG_CCMP_256: |
a042e39a | 2868 | return RSN_CIPHER_SUITE_CCMP_256; |
de4ed4a8 | 2869 | case WPA_ALG_GCMP_256: |
a042e39a | 2870 | return RSN_CIPHER_SUITE_GCMP_256; |
de4ed4a8 | 2871 | case WPA_ALG_IGTK: |
a042e39a | 2872 | return RSN_CIPHER_SUITE_AES_128_CMAC; |
de4ed4a8 | 2873 | case WPA_ALG_BIP_GMAC_128: |
a042e39a | 2874 | return RSN_CIPHER_SUITE_BIP_GMAC_128; |
de4ed4a8 | 2875 | case WPA_ALG_BIP_GMAC_256: |
a042e39a | 2876 | return RSN_CIPHER_SUITE_BIP_GMAC_256; |
de4ed4a8 | 2877 | case WPA_ALG_BIP_CMAC_256: |
a042e39a | 2878 | return RSN_CIPHER_SUITE_BIP_CMAC_256; |
de4ed4a8 | 2879 | case WPA_ALG_SMS4: |
a042e39a | 2880 | return RSN_CIPHER_SUITE_SMS4; |
de4ed4a8 | 2881 | case WPA_ALG_KRK: |
a042e39a | 2882 | return RSN_CIPHER_SUITE_KRK; |
de4ed4a8 JM |
2883 | case WPA_ALG_NONE: |
2884 | case WPA_ALG_PMK: | |
2885 | wpa_printf(MSG_ERROR, "nl80211: Unexpected encryption algorithm %d", | |
2886 | alg); | |
2887 | return 0; | |
2888 | } | |
2889 | ||
2890 | wpa_printf(MSG_ERROR, "nl80211: Unsupported encryption algorithm %d", | |
2891 | alg); | |
2892 | return 0; | |
2893 | } | |
2894 | ||
2895 | ||
2896 | static u32 wpa_cipher_to_cipher_suite(unsigned int cipher) | |
2897 | { | |
2898 | switch (cipher) { | |
2899 | case WPA_CIPHER_CCMP_256: | |
a042e39a | 2900 | return RSN_CIPHER_SUITE_CCMP_256; |
de4ed4a8 | 2901 | case WPA_CIPHER_GCMP_256: |
a042e39a | 2902 | return RSN_CIPHER_SUITE_GCMP_256; |
de4ed4a8 | 2903 | case WPA_CIPHER_CCMP: |
a042e39a | 2904 | return RSN_CIPHER_SUITE_CCMP; |
de4ed4a8 | 2905 | case WPA_CIPHER_GCMP: |
a042e39a | 2906 | return RSN_CIPHER_SUITE_GCMP; |
de4ed4a8 | 2907 | case WPA_CIPHER_TKIP: |
a042e39a | 2908 | return RSN_CIPHER_SUITE_TKIP; |
de4ed4a8 | 2909 | case WPA_CIPHER_WEP104: |
a042e39a | 2910 | return RSN_CIPHER_SUITE_WEP104; |
de4ed4a8 | 2911 | case WPA_CIPHER_WEP40: |
a042e39a | 2912 | return RSN_CIPHER_SUITE_WEP40; |
ae6f9272 | 2913 | case WPA_CIPHER_GTK_NOT_USED: |
a042e39a | 2914 | return RSN_CIPHER_SUITE_NO_GROUP_ADDRESSED; |
de4ed4a8 JM |
2915 | } |
2916 | ||
2917 | return 0; | |
2918 | } | |
2919 | ||
2920 | ||
2921 | static int wpa_cipher_to_cipher_suites(unsigned int ciphers, u32 suites[], | |
2922 | int max_suites) | |
2923 | { | |
2924 | int num_suites = 0; | |
2925 | ||
2926 | if (num_suites < max_suites && ciphers & WPA_CIPHER_CCMP_256) | |
a042e39a | 2927 | suites[num_suites++] = RSN_CIPHER_SUITE_CCMP_256; |
de4ed4a8 | 2928 | if (num_suites < max_suites && ciphers & WPA_CIPHER_GCMP_256) |
a042e39a | 2929 | suites[num_suites++] = RSN_CIPHER_SUITE_GCMP_256; |
de4ed4a8 | 2930 | if (num_suites < max_suites && ciphers & WPA_CIPHER_CCMP) |
a042e39a | 2931 | suites[num_suites++] = RSN_CIPHER_SUITE_CCMP; |
de4ed4a8 | 2932 | if (num_suites < max_suites && ciphers & WPA_CIPHER_GCMP) |
a042e39a | 2933 | suites[num_suites++] = RSN_CIPHER_SUITE_GCMP; |
de4ed4a8 | 2934 | if (num_suites < max_suites && ciphers & WPA_CIPHER_TKIP) |
a042e39a | 2935 | suites[num_suites++] = RSN_CIPHER_SUITE_TKIP; |
de4ed4a8 | 2936 | if (num_suites < max_suites && ciphers & WPA_CIPHER_WEP104) |
a042e39a | 2937 | suites[num_suites++] = RSN_CIPHER_SUITE_WEP104; |
de4ed4a8 | 2938 | if (num_suites < max_suites && ciphers & WPA_CIPHER_WEP40) |
a042e39a | 2939 | suites[num_suites++] = RSN_CIPHER_SUITE_WEP40; |
de4ed4a8 JM |
2940 | |
2941 | return num_suites; | |
2942 | } | |
2943 | ||
2944 | ||
b658547d | 2945 | #ifdef CONFIG_DRIVER_NL80211_QCA |
b41f2684 CL |
2946 | static int issue_key_mgmt_set_key(struct wpa_driver_nl80211_data *drv, |
2947 | const u8 *key, size_t key_len) | |
2948 | { | |
2949 | struct nl_msg *msg; | |
a862e4a3 | 2950 | int ret; |
b41f2684 | 2951 | |
15badebd | 2952 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD)) |
b41f2684 CL |
2953 | return 0; |
2954 | ||
9725b784 | 2955 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
a862e4a3 JM |
2956 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
2957 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | |
2958 | QCA_NL80211_VENDOR_SUBCMD_KEY_MGMT_SET_KEY) || | |
2959 | nla_put(msg, NL80211_ATTR_VENDOR_DATA, key_len, key)) { | |
bbd89bfc | 2960 | nl80211_nlmsg_clear(msg); |
a862e4a3 JM |
2961 | nlmsg_free(msg); |
2962 | return -1; | |
2963 | } | |
bbd89bfc | 2964 | ret = send_and_recv_msgs(drv, msg, NULL, (void *) -1); |
b41f2684 CL |
2965 | if (ret) { |
2966 | wpa_printf(MSG_DEBUG, | |
2967 | "nl80211: Key management set key failed: ret=%d (%s)", | |
2968 | ret, strerror(-ret)); | |
2969 | } | |
2970 | ||
b41f2684 CL |
2971 | return ret; |
2972 | } | |
b658547d | 2973 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
b41f2684 CL |
2974 | |
2975 | ||
05fc7c68 AS |
2976 | static int nl80211_set_pmk(struct wpa_driver_nl80211_data *drv, |
2977 | const u8 *key, size_t key_len, | |
2978 | const u8 *addr) | |
2979 | { | |
2980 | struct nl_msg *msg = NULL; | |
2981 | int ret; | |
2982 | ||
2983 | /* | |
2984 | * If the authenticator address is not set, assume it is | |
2985 | * the current BSSID. | |
2986 | */ | |
2987 | if (!addr && drv->associated) | |
2988 | addr = drv->bssid; | |
2989 | else if (!addr) | |
2990 | return -1; | |
2991 | ||
2992 | wpa_printf(MSG_DEBUG, "nl80211: Set PMK to the driver for " MACSTR, | |
2993 | MAC2STR(addr)); | |
2994 | wpa_hexdump_key(MSG_DEBUG, "nl80211: PMK", key, key_len); | |
2995 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_PMK); | |
2996 | if (!msg || | |
2997 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || | |
2998 | nla_put(msg, NL80211_ATTR_PMK, key_len, key)) { | |
2999 | nl80211_nlmsg_clear(msg); | |
3000 | nlmsg_free(msg); | |
3001 | return -ENOBUFS; | |
3002 | } | |
3003 | ||
3004 | ret = send_and_recv_msgs(drv, msg, NULL, (void *) -1); | |
3005 | if (ret) { | |
3006 | wpa_printf(MSG_DEBUG, "nl80211: Set PMK failed: ret=%d (%s)", | |
3007 | ret, strerror(-ret)); | |
3008 | } | |
3009 | ||
3010 | return ret; | |
3011 | } | |
3012 | ||
3013 | ||
9ebce9c5 | 3014 | static int wpa_driver_nl80211_set_key(const char *ifname, struct i802_bss *bss, |
71934751 JM |
3015 | enum wpa_alg alg, const u8 *addr, |
3016 | int key_idx, int set_tx, | |
642187d6 JM |
3017 | const u8 *seq, size_t seq_len, |
3018 | const u8 *key, size_t key_len) | |
3f5285e8 | 3019 | { |
a2e40bb6 | 3020 | struct wpa_driver_nl80211_data *drv = bss->drv; |
e472e1b4 | 3021 | int ifindex; |
83b83b46 AW |
3022 | struct nl_msg *msg; |
3023 | struct nl_msg *key_msg; | |
1ad1cdc2 | 3024 | int ret; |
dc01de8a | 3025 | int tdls = 0; |
3f5285e8 | 3026 | |
e472e1b4 AS |
3027 | /* Ignore for P2P Device */ |
3028 | if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) | |
3029 | return 0; | |
3030 | ||
3031 | ifindex = if_nametoindex(ifname); | |
8393e1a0 | 3032 | wpa_printf(MSG_DEBUG, "%s: ifindex=%d (%s) alg=%d addr=%p key_idx=%d " |
1ad1cdc2 | 3033 | "set_tx=%d seq_len=%lu key_len=%lu", |
8393e1a0 | 3034 | __func__, ifindex, ifname, alg, addr, key_idx, set_tx, |
3f5285e8 | 3035 | (unsigned long) seq_len, (unsigned long) key_len); |
8c66e185 | 3036 | #ifdef CONFIG_TDLS |
dc01de8a | 3037 | if (key_idx == -1) { |
8c66e185 | 3038 | key_idx = 0; |
dc01de8a JM |
3039 | tdls = 1; |
3040 | } | |
8c66e185 | 3041 | #endif /* CONFIG_TDLS */ |
3f5285e8 | 3042 | |
b658547d | 3043 | #ifdef CONFIG_DRIVER_NL80211_QCA |
15badebd CL |
3044 | if (alg == WPA_ALG_PMK && |
3045 | (drv->capa.flags & WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD)) { | |
b41f2684 CL |
3046 | wpa_printf(MSG_DEBUG, "%s: calling issue_key_mgmt_set_key", |
3047 | __func__); | |
3048 | ret = issue_key_mgmt_set_key(drv, key, key_len); | |
3049 | return ret; | |
3050 | } | |
b658547d | 3051 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
b41f2684 | 3052 | |
05fc7c68 | 3053 | if (alg == WPA_ALG_PMK && |
436ee2fd | 3054 | (drv->capa.flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_8021X)) |
05fc7c68 AS |
3055 | return nl80211_set_pmk(drv, key, key_len, addr); |
3056 | ||
83b83b46 AW |
3057 | key_msg = nlmsg_alloc(); |
3058 | if (!key_msg) | |
3059 | return -ENOBUFS; | |
3060 | ||
3f5285e8 | 3061 | if (alg == WPA_ALG_NONE) { |
95376e1a JM |
3062 | msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_DEL_KEY); |
3063 | if (!msg) | |
83b83b46 | 3064 | goto fail2; |
3f5285e8 | 3065 | } else { |
34651767 JM |
3066 | u32 suite; |
3067 | ||
3068 | suite = wpa_alg_to_cipher_suite(alg, key_len); | |
3069 | if (!suite) | |
83b83b46 | 3070 | goto fail2; |
95376e1a | 3071 | msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_NEW_KEY); |
83b83b46 AW |
3072 | if (!msg) |
3073 | goto fail2; | |
3074 | if (nla_put(key_msg, NL80211_KEY_DATA, key_len, key) || | |
3075 | nla_put_u32(key_msg, NL80211_KEY_CIPHER, suite)) | |
a862e4a3 | 3076 | goto fail; |
e6ef73f1 | 3077 | wpa_hexdump_key(MSG_DEBUG, "nl80211: KEY_DATA", key, key_len); |
3f5285e8 JM |
3078 | } |
3079 | ||
e6ef73f1 | 3080 | if (seq && seq_len) { |
83b83b46 | 3081 | if (nla_put(key_msg, NL80211_KEY_SEQ, seq_len, seq)) |
a862e4a3 | 3082 | goto fail; |
e6ef73f1 JM |
3083 | wpa_hexdump(MSG_DEBUG, "nl80211: KEY_SEQ", seq, seq_len); |
3084 | } | |
1ad1cdc2 | 3085 | |
0382097e | 3086 | if (addr && !is_broadcast_ether_addr(addr)) { |
3f5285e8 | 3087 | wpa_printf(MSG_DEBUG, " addr=" MACSTR, MAC2STR(addr)); |
a862e4a3 JM |
3088 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
3089 | goto fail; | |
89c38e32 JM |
3090 | |
3091 | if (alg != WPA_ALG_WEP && key_idx && !set_tx) { | |
3092 | wpa_printf(MSG_DEBUG, " RSN IBSS RX GTK"); | |
83b83b46 | 3093 | if (nla_put_u32(key_msg, NL80211_KEY_TYPE, |
a862e4a3 JM |
3094 | NL80211_KEYTYPE_GROUP)) |
3095 | goto fail; | |
89c38e32 | 3096 | } |
60ea8187 | 3097 | } else if (addr && is_broadcast_ether_addr(addr)) { |
8970bae8 JB |
3098 | struct nlattr *types; |
3099 | ||
60ea8187 | 3100 | wpa_printf(MSG_DEBUG, " broadcast key"); |
8970bae8 | 3101 | |
83b83b46 | 3102 | types = nla_nest_start(key_msg, NL80211_KEY_DEFAULT_TYPES); |
a862e4a3 | 3103 | if (!types || |
83b83b46 | 3104 | nla_put_flag(key_msg, NL80211_KEY_DEFAULT_TYPE_MULTICAST)) |
a862e4a3 | 3105 | goto fail; |
83b83b46 | 3106 | nla_nest_end(key_msg, types); |
3f5285e8 | 3107 | } |
83b83b46 AW |
3108 | if (nla_put_u8(key_msg, NL80211_KEY_IDX, key_idx) || |
3109 | nla_put_nested(msg, NL80211_ATTR_KEY, key_msg)) | |
a862e4a3 | 3110 | goto fail; |
83b83b46 AW |
3111 | nl80211_nlmsg_clear(key_msg); |
3112 | nlmsg_free(key_msg); | |
3113 | key_msg = NULL; | |
3f5285e8 | 3114 | |
bbd89bfc | 3115 | ret = send_and_recv_msgs(drv, msg, NULL, key ? (void *) -1 : NULL); |
15664ad0 | 3116 | if ((ret == -ENOENT || ret == -ENOLINK) && alg == WPA_ALG_NONE) |
1ad1cdc2 JM |
3117 | ret = 0; |
3118 | if (ret) | |
3119 | wpa_printf(MSG_DEBUG, "nl80211: set_key failed; err=%d %s)", | |
3120 | ret, strerror(-ret)); | |
3f5285e8 | 3121 | |
1ad1cdc2 JM |
3122 | /* |
3123 | * If we failed or don't need to set the default TX key (below), | |
3124 | * we're done here. | |
3125 | */ | |
dc01de8a | 3126 | if (ret || !set_tx || alg == WPA_ALG_NONE || tdls) |
1ad1cdc2 | 3127 | return ret; |
b1f625e0 | 3128 | if (is_ap_interface(drv->nlmode) && addr && |
0382097e | 3129 | !is_broadcast_ether_addr(addr)) |
de12717a | 3130 | return ret; |
3f5285e8 | 3131 | |
83b83b46 AW |
3132 | key_msg = nlmsg_alloc(); |
3133 | if (!key_msg) | |
3134 | return -ENOBUFS; | |
3135 | ||
95376e1a | 3136 | msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_SET_KEY); |
83b83b46 AW |
3137 | if (!msg) |
3138 | goto fail2; | |
3139 | if (!key_msg || | |
3140 | nla_put_u8(key_msg, NL80211_KEY_IDX, key_idx) || | |
3141 | nla_put_flag(key_msg, (alg == WPA_ALG_IGTK || | |
3142 | alg == WPA_ALG_BIP_GMAC_128 || | |
3143 | alg == WPA_ALG_BIP_GMAC_256 || | |
3144 | alg == WPA_ALG_BIP_CMAC_256) ? | |
3145 | NL80211_KEY_DEFAULT_MGMT : | |
3146 | NL80211_KEY_DEFAULT)) | |
a862e4a3 | 3147 | goto fail; |
60ea8187 | 3148 | if (addr && is_broadcast_ether_addr(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_MULTICAST)) |
a862e4a3 | 3154 | goto fail; |
83b83b46 | 3155 | nla_nest_end(key_msg, types); |
60ea8187 | 3156 | } else if (addr) { |
8970bae8 JB |
3157 | struct nlattr *types; |
3158 | ||
83b83b46 | 3159 | types = nla_nest_start(key_msg, NL80211_KEY_DEFAULT_TYPES); |
a862e4a3 | 3160 | if (!types || |
83b83b46 | 3161 | nla_put_flag(key_msg, NL80211_KEY_DEFAULT_TYPE_UNICAST)) |
a862e4a3 | 3162 | goto fail; |
83b83b46 | 3163 | nla_nest_end(key_msg, types); |
60ea8187 | 3164 | } |
3f5285e8 | 3165 | |
83b83b46 AW |
3166 | if (nla_put_nested(msg, NL80211_ATTR_KEY, key_msg)) |
3167 | goto fail; | |
3168 | nl80211_nlmsg_clear(key_msg); | |
3169 | nlmsg_free(key_msg); | |
3170 | key_msg = NULL; | |
3171 | ||
1ad1cdc2 JM |
3172 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
3173 | if (ret == -ENOENT) | |
3174 | ret = 0; | |
3175 | if (ret) | |
3176 | wpa_printf(MSG_DEBUG, "nl80211: set_key default failed; " | |
3177 | "err=%d %s)", ret, strerror(-ret)); | |
3178 | return ret; | |
3f5285e8 | 3179 | |
a862e4a3 | 3180 | fail: |
bbd89bfc | 3181 | nl80211_nlmsg_clear(msg); |
5883168a | 3182 | nlmsg_free(msg); |
83b83b46 AW |
3183 | fail2: |
3184 | nl80211_nlmsg_clear(key_msg); | |
3185 | nlmsg_free(key_msg); | |
6241fcb1 | 3186 | return -ENOBUFS; |
3f5285e8 JM |
3187 | } |
3188 | ||
3189 | ||
71934751 | 3190 | static int nl_add_key(struct nl_msg *msg, enum wpa_alg alg, |
0194fedb JB |
3191 | int key_idx, int defkey, |
3192 | const u8 *seq, size_t seq_len, | |
3193 | const u8 *key, size_t key_len) | |
3194 | { | |
3195 | struct nlattr *key_attr = nla_nest_start(msg, NL80211_ATTR_KEY); | |
34651767 JM |
3196 | u32 suite; |
3197 | ||
0194fedb JB |
3198 | if (!key_attr) |
3199 | return -1; | |
3200 | ||
34651767 JM |
3201 | suite = wpa_alg_to_cipher_suite(alg, key_len); |
3202 | if (!suite) | |
3203 | return -1; | |
3204 | ||
a862e4a3 JM |
3205 | if (defkey && alg == WPA_ALG_IGTK) { |
3206 | if (nla_put_flag(msg, NL80211_KEY_DEFAULT_MGMT)) | |
3207 | return -1; | |
3208 | } else if (defkey) { | |
3209 | if (nla_put_flag(msg, NL80211_KEY_DEFAULT)) | |
3210 | return -1; | |
3211 | } | |
0194fedb | 3212 | |
a862e4a3 | 3213 | if (nla_put_u8(msg, NL80211_KEY_IDX, key_idx) || |
34651767 | 3214 | nla_put_u32(msg, NL80211_KEY_CIPHER, suite) || |
a862e4a3 JM |
3215 | (seq && seq_len && |
3216 | nla_put(msg, NL80211_KEY_SEQ, seq_len, seq)) || | |
3217 | nla_put(msg, NL80211_KEY_DATA, key_len, key)) | |
3218 | return -1; | |
0194fedb JB |
3219 | |
3220 | nla_nest_end(msg, key_attr); | |
3221 | ||
3222 | return 0; | |
0194fedb JB |
3223 | } |
3224 | ||
c811d5bc | 3225 | |
cfaab580 ZY |
3226 | static int nl80211_set_conn_keys(struct wpa_driver_associate_params *params, |
3227 | struct nl_msg *msg) | |
3228 | { | |
3229 | int i, privacy = 0; | |
3230 | struct nlattr *nl_keys, *nl_key; | |
3231 | ||
3232 | for (i = 0; i < 4; i++) { | |
3233 | if (!params->wep_key[i]) | |
3234 | continue; | |
3235 | privacy = 1; | |
3236 | break; | |
3237 | } | |
ce04af5a JM |
3238 | if (params->wps == WPS_MODE_PRIVACY) |
3239 | privacy = 1; | |
3240 | if (params->pairwise_suite && | |
3241 | params->pairwise_suite != WPA_CIPHER_NONE) | |
3242 | privacy = 1; | |
3243 | ||
cfaab580 ZY |
3244 | if (!privacy) |
3245 | return 0; | |
3246 | ||
a862e4a3 JM |
3247 | if (nla_put_flag(msg, NL80211_ATTR_PRIVACY)) |
3248 | return -ENOBUFS; | |
cfaab580 ZY |
3249 | |
3250 | nl_keys = nla_nest_start(msg, NL80211_ATTR_KEYS); | |
3251 | if (!nl_keys) | |
a862e4a3 | 3252 | return -ENOBUFS; |
cfaab580 ZY |
3253 | |
3254 | for (i = 0; i < 4; i++) { | |
3255 | if (!params->wep_key[i]) | |
3256 | continue; | |
3257 | ||
3258 | nl_key = nla_nest_start(msg, i); | |
a862e4a3 JM |
3259 | if (!nl_key || |
3260 | nla_put(msg, NL80211_KEY_DATA, params->wep_key_len[i], | |
3261 | params->wep_key[i]) || | |
3262 | nla_put_u32(msg, NL80211_KEY_CIPHER, | |
3263 | params->wep_key_len[i] == 5 ? | |
a042e39a JM |
3264 | RSN_CIPHER_SUITE_WEP40 : |
3265 | RSN_CIPHER_SUITE_WEP104) || | |
a862e4a3 JM |
3266 | nla_put_u8(msg, NL80211_KEY_IDX, i) || |
3267 | (i == params->wep_tx_keyidx && | |
3268 | nla_put_flag(msg, NL80211_KEY_DEFAULT))) | |
3269 | return -ENOBUFS; | |
cfaab580 ZY |
3270 | |
3271 | nla_nest_end(msg, nl_key); | |
3272 | } | |
3273 | nla_nest_end(msg, nl_keys); | |
3274 | ||
3275 | return 0; | |
cfaab580 ZY |
3276 | } |
3277 | ||
3278 | ||
477af8f8 JM |
3279 | int wpa_driver_nl80211_mlme(struct wpa_driver_nl80211_data *drv, |
3280 | const u8 *addr, int cmd, u16 reason_code, | |
10d32e2c | 3281 | int local_state_change, |
25ebd538 | 3282 | struct nl_sock *nl_connect) |
c2a04078 | 3283 | { |
a862e4a3 | 3284 | int ret; |
c2a04078 JM |
3285 | struct nl_msg *msg; |
3286 | ||
9725b784 | 3287 | if (!(msg = nl80211_drv_msg(drv, 0, cmd)) || |
a862e4a3 JM |
3288 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code) || |
3289 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || | |
3290 | (local_state_change && | |
3291 | nla_put_flag(msg, NL80211_ATTR_LOCAL_STATE_CHANGE))) { | |
3292 | nlmsg_free(msg); | |
3293 | return -1; | |
3294 | } | |
c2a04078 | 3295 | |
10d32e2c CI |
3296 | if (nl_connect) |
3297 | ret = send_and_recv(drv->global, nl_connect, msg, NULL, NULL); | |
3298 | else | |
3299 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
c2a04078 | 3300 | if (ret) { |
3b7ea880 BG |
3301 | wpa_dbg(drv->ctx, MSG_DEBUG, |
3302 | "nl80211: MLME command failed: reason=%u ret=%d (%s)", | |
3303 | reason_code, ret, strerror(-ret)); | |
c2a04078 | 3304 | } |
c2a04078 JM |
3305 | return ret; |
3306 | } | |
3f5285e8 JM |
3307 | |
3308 | ||
cfaab580 | 3309 | static int wpa_driver_nl80211_disconnect(struct wpa_driver_nl80211_data *drv, |
4be17ffb | 3310 | u16 reason_code, |
25ebd538 | 3311 | struct nl_sock *nl_connect) |
cfaab580 | 3312 | { |
3f53c006 | 3313 | int ret; |
b898b655 | 3314 | int drv_associated = drv->associated; |
3f53c006 | 3315 | |
817762d9 | 3316 | wpa_printf(MSG_DEBUG, "%s(reason_code=%d)", __func__, reason_code); |
add9b7a4 | 3317 | nl80211_mark_disconnected(drv); |
817762d9 | 3318 | /* Disconnect command doesn't need BSSID - it uses cached value */ |
3f53c006 | 3319 | ret = wpa_driver_nl80211_mlme(drv, NULL, NL80211_CMD_DISCONNECT, |
10d32e2c | 3320 | reason_code, 0, nl_connect); |
3f53c006 JJ |
3321 | /* |
3322 | * For locally generated disconnect, supplicant already generates a | |
3323 | * DEAUTH event, so ignore the event from NL80211. | |
3324 | */ | |
b898b655 | 3325 | drv->ignore_next_local_disconnect = drv_associated && (ret == 0); |
3f53c006 JJ |
3326 | |
3327 | return ret; | |
cfaab580 ZY |
3328 | } |
3329 | ||
3330 | ||
9ebce9c5 | 3331 | static int wpa_driver_nl80211_deauthenticate(struct i802_bss *bss, |
4be17ffb | 3332 | const u8 *addr, u16 reason_code) |
3f5285e8 | 3333 | { |
a2e40bb6 | 3334 | struct wpa_driver_nl80211_data *drv = bss->drv; |
d6a36f39 | 3335 | int ret; |
b898b655 | 3336 | int drv_associated = drv->associated; |
9392c9be AS |
3337 | |
3338 | if (drv->nlmode == NL80211_IFTYPE_ADHOC) { | |
3339 | nl80211_mark_disconnected(drv); | |
666e508c | 3340 | return nl80211_leave_ibss(drv, 1); |
9392c9be | 3341 | } |
10d32e2c | 3342 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) { |
25ebd538 | 3343 | struct nl_sock *nl_connect = NULL; |
10d32e2c CI |
3344 | |
3345 | if (bss->use_nl_connect) | |
3346 | nl_connect = bss->nl_connect; | |
3347 | return wpa_driver_nl80211_disconnect(drv, reason_code, | |
3348 | nl_connect); | |
3349 | } | |
2e75a2b3 JM |
3350 | wpa_printf(MSG_DEBUG, "%s(addr=" MACSTR " reason_code=%d)", |
3351 | __func__, MAC2STR(addr), reason_code); | |
add9b7a4 | 3352 | nl80211_mark_disconnected(drv); |
d6a36f39 | 3353 | ret = wpa_driver_nl80211_mlme(drv, addr, NL80211_CMD_DEAUTHENTICATE, |
10d32e2c | 3354 | reason_code, 0, NULL); |
d6a36f39 JM |
3355 | /* |
3356 | * For locally generated deauthenticate, supplicant already generates a | |
3357 | * DEAUTH event, so ignore the event from NL80211. | |
3358 | */ | |
b898b655 HW |
3359 | drv->ignore_next_local_deauth = drv_associated && (ret == 0); |
3360 | ||
d6a36f39 | 3361 | return ret; |
3f5285e8 JM |
3362 | } |
3363 | ||
3364 | ||
536fd62d JM |
3365 | static void nl80211_copy_auth_params(struct wpa_driver_nl80211_data *drv, |
3366 | struct wpa_driver_auth_params *params) | |
3367 | { | |
3368 | int i; | |
3369 | ||
3370 | drv->auth_freq = params->freq; | |
3371 | drv->auth_alg = params->auth_alg; | |
3372 | drv->auth_wep_tx_keyidx = params->wep_tx_keyidx; | |
3373 | drv->auth_local_state_change = params->local_state_change; | |
3374 | drv->auth_p2p = params->p2p; | |
3375 | ||
3376 | if (params->bssid) | |
3377 | os_memcpy(drv->auth_bssid_, params->bssid, ETH_ALEN); | |
3378 | else | |
3379 | os_memset(drv->auth_bssid_, 0, ETH_ALEN); | |
3380 | ||
3381 | if (params->ssid) { | |
3382 | os_memcpy(drv->auth_ssid, params->ssid, params->ssid_len); | |
3383 | drv->auth_ssid_len = params->ssid_len; | |
3384 | } else | |
3385 | drv->auth_ssid_len = 0; | |
3386 | ||
3387 | ||
3388 | os_free(drv->auth_ie); | |
3389 | drv->auth_ie = NULL; | |
3390 | drv->auth_ie_len = 0; | |
3391 | if (params->ie) { | |
3392 | drv->auth_ie = os_malloc(params->ie_len); | |
3393 | if (drv->auth_ie) { | |
3394 | os_memcpy(drv->auth_ie, params->ie, params->ie_len); | |
3395 | drv->auth_ie_len = params->ie_len; | |
3396 | } | |
3397 | } | |
3398 | ||
3399 | for (i = 0; i < 4; i++) { | |
3400 | if (params->wep_key[i] && params->wep_key_len[i] && | |
3401 | params->wep_key_len[i] <= 16) { | |
3402 | os_memcpy(drv->auth_wep_key[i], params->wep_key[i], | |
3403 | params->wep_key_len[i]); | |
3404 | drv->auth_wep_key_len[i] = params->wep_key_len[i]; | |
3405 | } else | |
3406 | drv->auth_wep_key_len[i] = 0; | |
3407 | } | |
3408 | } | |
3409 | ||
3410 | ||
4bd71954 JM |
3411 | static void nl80211_unmask_11b_rates(struct i802_bss *bss) |
3412 | { | |
3413 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
3414 | ||
3415 | if (is_p2p_net_interface(drv->nlmode) || !drv->disabled_11b_rates) | |
3416 | return; | |
3417 | ||
3418 | /* | |
3419 | * Looks like we failed to unmask 11b rates previously. This could | |
3420 | * happen, e.g., if the interface was down at the point in time when a | |
3421 | * P2P group was terminated. | |
3422 | */ | |
3423 | wpa_printf(MSG_DEBUG, | |
3424 | "nl80211: Interface %s mode is for non-P2P, but 11b rates were disabled - re-enable them", | |
3425 | bss->ifname); | |
3426 | nl80211_disable_11b_rates(drv, drv->ifindex, 0); | |
3427 | } | |
3428 | ||
3429 | ||
3c67e977 VK |
3430 | static enum nl80211_auth_type get_nl_auth_type(int wpa_auth_alg) |
3431 | { | |
3432 | if (wpa_auth_alg & WPA_AUTH_ALG_OPEN) | |
3433 | return NL80211_AUTHTYPE_OPEN_SYSTEM; | |
3434 | if (wpa_auth_alg & WPA_AUTH_ALG_SHARED) | |
3435 | return NL80211_AUTHTYPE_SHARED_KEY; | |
3436 | if (wpa_auth_alg & WPA_AUTH_ALG_LEAP) | |
3437 | return NL80211_AUTHTYPE_NETWORK_EAP; | |
3438 | if (wpa_auth_alg & WPA_AUTH_ALG_FT) | |
3439 | return NL80211_AUTHTYPE_FT; | |
3440 | if (wpa_auth_alg & WPA_AUTH_ALG_SAE) | |
3441 | return NL80211_AUTHTYPE_SAE; | |
3442 | if (wpa_auth_alg & WPA_AUTH_ALG_FILS) | |
3443 | return NL80211_AUTHTYPE_FILS_SK; | |
3444 | if (wpa_auth_alg & WPA_AUTH_ALG_FILS_SK_PFS) | |
3445 | return NL80211_AUTHTYPE_FILS_SK_PFS; | |
3446 | ||
3447 | return NL80211_AUTHTYPE_MAX; | |
3448 | } | |
3449 | ||
3450 | ||
c2a04078 | 3451 | static int wpa_driver_nl80211_authenticate( |
9ebce9c5 | 3452 | struct i802_bss *bss, struct wpa_driver_auth_params *params) |
c2a04078 | 3453 | { |
a2e40bb6 | 3454 | struct wpa_driver_nl80211_data *drv = bss->drv; |
a0b2f99b | 3455 | int ret = -1, i; |
c2a04078 JM |
3456 | struct nl_msg *msg; |
3457 | enum nl80211_auth_type type; | |
2f4f73b1 | 3458 | enum nl80211_iftype nlmode; |
6d6f4bb8 | 3459 | int count = 0; |
536fd62d JM |
3460 | int is_retry; |
3461 | ||
4bd71954 JM |
3462 | nl80211_unmask_11b_rates(bss); |
3463 | ||
536fd62d JM |
3464 | is_retry = drv->retry_auth; |
3465 | drv->retry_auth = 0; | |
e8d70a73 | 3466 | drv->ignore_deauth_event = 0; |
c2a04078 | 3467 | |
add9b7a4 | 3468 | nl80211_mark_disconnected(drv); |
e6b8efeb | 3469 | os_memset(drv->auth_bssid, 0, ETH_ALEN); |
add9b7a4 JM |
3470 | if (params->bssid) |
3471 | os_memcpy(drv->auth_attempt_bssid, params->bssid, ETH_ALEN); | |
3472 | else | |
3473 | os_memset(drv->auth_attempt_bssid, 0, ETH_ALEN); | |
af473088 | 3474 | /* FIX: IBSS mode */ |
2f4f73b1 EP |
3475 | nlmode = params->p2p ? |
3476 | NL80211_IFTYPE_P2P_CLIENT : NL80211_IFTYPE_STATION; | |
3477 | if (drv->nlmode != nlmode && | |
9ebce9c5 | 3478 | wpa_driver_nl80211_set_mode(bss, nlmode) < 0) |
4a867032 JM |
3479 | return -1; |
3480 | ||
6d6f4bb8 | 3481 | retry: |
c2a04078 JM |
3482 | wpa_printf(MSG_DEBUG, "nl80211: Authenticate (ifindex=%d)", |
3483 | drv->ifindex); | |
a0b2f99b | 3484 | |
9725b784 JM |
3485 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_AUTHENTICATE); |
3486 | if (!msg) | |
3487 | goto fail; | |
0194fedb | 3488 | |
a0b2f99b JM |
3489 | for (i = 0; i < 4; i++) { |
3490 | if (!params->wep_key[i]) | |
3491 | continue; | |
9ebce9c5 | 3492 | wpa_driver_nl80211_set_key(bss->ifname, bss, WPA_ALG_WEP, |
2ea2fcc7 | 3493 | NULL, i, |
a0b2f99b JM |
3494 | i == params->wep_tx_keyidx, NULL, 0, |
3495 | params->wep_key[i], | |
3496 | params->wep_key_len[i]); | |
0194fedb JB |
3497 | if (params->wep_tx_keyidx != i) |
3498 | continue; | |
3499 | if (nl_add_key(msg, WPA_ALG_WEP, i, 1, NULL, 0, | |
9725b784 JM |
3500 | params->wep_key[i], params->wep_key_len[i])) |
3501 | goto fail; | |
a0b2f99b JM |
3502 | } |
3503 | ||
c2a04078 JM |
3504 | if (params->bssid) { |
3505 | wpa_printf(MSG_DEBUG, " * bssid=" MACSTR, | |
3506 | MAC2STR(params->bssid)); | |
a862e4a3 JM |
3507 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid)) |
3508 | goto fail; | |
c2a04078 JM |
3509 | } |
3510 | if (params->freq) { | |
3511 | wpa_printf(MSG_DEBUG, " * freq=%d", params->freq); | |
a862e4a3 JM |
3512 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, params->freq)) |
3513 | goto fail; | |
c2a04078 JM |
3514 | } |
3515 | if (params->ssid) { | |
21cd8f83 JM |
3516 | wpa_printf(MSG_DEBUG, " * SSID=%s", |
3517 | wpa_ssid_txt(params->ssid, params->ssid_len)); | |
a862e4a3 JM |
3518 | if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, |
3519 | params->ssid)) | |
3520 | goto fail; | |
c2a04078 JM |
3521 | } |
3522 | wpa_hexdump(MSG_DEBUG, " * IEs", params->ie, params->ie_len); | |
a862e4a3 JM |
3523 | if (params->ie && |
3524 | nla_put(msg, NL80211_ATTR_IE, params->ie_len, params->ie)) | |
3525 | goto fail; | |
ce16c489 JM |
3526 | if (params->auth_data) { |
3527 | wpa_hexdump(MSG_DEBUG, " * auth_data", params->auth_data, | |
3528 | params->auth_data_len); | |
3529 | if (nla_put(msg, NL80211_ATTR_SAE_DATA, params->auth_data_len, | |
3530 | params->auth_data)) | |
a862e4a3 | 3531 | goto fail; |
569fed90 | 3532 | } |
3c67e977 | 3533 | type = get_nl_auth_type(params->auth_alg); |
c2a04078 | 3534 | wpa_printf(MSG_DEBUG, " * Auth Type %d", type); |
3c67e977 VK |
3535 | if (type == NL80211_AUTHTYPE_MAX || |
3536 | nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, type)) | |
a862e4a3 | 3537 | goto fail; |
77339912 JM |
3538 | if (params->local_state_change) { |
3539 | wpa_printf(MSG_DEBUG, " * Local state change only"); | |
a862e4a3 JM |
3540 | if (nla_put_flag(msg, NL80211_ATTR_LOCAL_STATE_CHANGE)) |
3541 | goto fail; | |
77339912 | 3542 | } |
c2a04078 JM |
3543 | |
3544 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
3545 | msg = NULL; | |
3546 | if (ret) { | |
3b7ea880 | 3547 | wpa_dbg(drv->ctx, MSG_DEBUG, |
f875da04 BG |
3548 | "nl80211: MLME command failed (auth): count=%d ret=%d (%s)", |
3549 | count, ret, strerror(-ret)); | |
6d6f4bb8 | 3550 | count++; |
f875da04 BG |
3551 | if ((ret == -EALREADY || ret == -EEXIST) && count == 1 && |
3552 | params->bssid && !params->local_state_change) { | |
6d6f4bb8 JM |
3553 | /* |
3554 | * mac80211 does not currently accept new | |
3555 | * authentication if we are already authenticated. As a | |
3556 | * workaround, force deauthentication and try again. | |
3557 | */ | |
3558 | wpa_printf(MSG_DEBUG, "nl80211: Retry authentication " | |
3559 | "after forced deauthentication"); | |
e8d70a73 | 3560 | drv->ignore_deauth_event = 1; |
6d6f4bb8 | 3561 | wpa_driver_nl80211_deauthenticate( |
5205c4f9 | 3562 | bss, params->bssid, |
6d6f4bb8 JM |
3563 | WLAN_REASON_PREV_AUTH_NOT_VALID); |
3564 | nlmsg_free(msg); | |
3565 | goto retry; | |
3566 | } | |
536fd62d JM |
3567 | |
3568 | if (ret == -ENOENT && params->freq && !is_retry) { | |
3569 | /* | |
3570 | * cfg80211 has likely expired the BSS entry even | |
3571 | * though it was previously available in our internal | |
3572 | * BSS table. To recover quickly, start a single | |
3573 | * channel scan on the specified channel. | |
3574 | */ | |
3575 | struct wpa_driver_scan_params scan; | |
3576 | int freqs[2]; | |
3577 | ||
3578 | os_memset(&scan, 0, sizeof(scan)); | |
3579 | scan.num_ssids = 1; | |
3580 | if (params->ssid) { | |
3581 | scan.ssids[0].ssid = params->ssid; | |
3582 | scan.ssids[0].ssid_len = params->ssid_len; | |
3583 | } | |
3584 | freqs[0] = params->freq; | |
3585 | freqs[1] = 0; | |
3586 | scan.freqs = freqs; | |
3587 | wpa_printf(MSG_DEBUG, "nl80211: Trigger single " | |
3588 | "channel scan to refresh cfg80211 BSS " | |
3589 | "entry"); | |
3590 | ret = wpa_driver_nl80211_scan(bss, &scan); | |
3591 | if (ret == 0) { | |
3592 | nl80211_copy_auth_params(drv, params); | |
3593 | drv->scan_for_auth = 1; | |
3594 | } | |
8c3ba078 JM |
3595 | } else if (is_retry) { |
3596 | /* | |
3597 | * Need to indicate this with an event since the return | |
3598 | * value from the retry is not delivered to core code. | |
3599 | */ | |
3600 | union wpa_event_data event; | |
3601 | wpa_printf(MSG_DEBUG, "nl80211: Authentication retry " | |
3602 | "failed"); | |
3603 | os_memset(&event, 0, sizeof(event)); | |
3604 | os_memcpy(event.timeout_event.addr, drv->auth_bssid_, | |
3605 | ETH_ALEN); | |
3606 | wpa_supplicant_event(drv->ctx, EVENT_AUTH_TIMED_OUT, | |
3607 | &event); | |
536fd62d | 3608 | } |
a862e4a3 JM |
3609 | } else { |
3610 | wpa_printf(MSG_DEBUG, | |
3611 | "nl80211: Authentication request send successfully"); | |
c2a04078 | 3612 | } |
c2a04078 | 3613 | |
a862e4a3 | 3614 | fail: |
c2a04078 JM |
3615 | nlmsg_free(msg); |
3616 | return ret; | |
3617 | } | |
3618 | ||
3619 | ||
f3407c66 | 3620 | int wpa_driver_nl80211_authenticate_retry(struct wpa_driver_nl80211_data *drv) |
536fd62d JM |
3621 | { |
3622 | struct wpa_driver_auth_params params; | |
834ee56f | 3623 | struct i802_bss *bss = drv->first_bss; |
536fd62d JM |
3624 | int i; |
3625 | ||
3626 | wpa_printf(MSG_DEBUG, "nl80211: Try to authenticate again"); | |
3627 | ||
3628 | os_memset(¶ms, 0, sizeof(params)); | |
3629 | params.freq = drv->auth_freq; | |
3630 | params.auth_alg = drv->auth_alg; | |
3631 | params.wep_tx_keyidx = drv->auth_wep_tx_keyidx; | |
3632 | params.local_state_change = drv->auth_local_state_change; | |
3633 | params.p2p = drv->auth_p2p; | |
3634 | ||
3635 | if (!is_zero_ether_addr(drv->auth_bssid_)) | |
3636 | params.bssid = drv->auth_bssid_; | |
3637 | ||
3638 | if (drv->auth_ssid_len) { | |
3639 | params.ssid = drv->auth_ssid; | |
3640 | params.ssid_len = drv->auth_ssid_len; | |
3641 | } | |
3642 | ||
3643 | params.ie = drv->auth_ie; | |
3644 | params.ie_len = drv->auth_ie_len; | |
3645 | ||
3646 | for (i = 0; i < 4; i++) { | |
3647 | if (drv->auth_wep_key_len[i]) { | |
3648 | params.wep_key[i] = drv->auth_wep_key[i]; | |
3649 | params.wep_key_len[i] = drv->auth_wep_key_len[i]; | |
3650 | } | |
3651 | } | |
3652 | ||
3653 | drv->retry_auth = 1; | |
3654 | return wpa_driver_nl80211_authenticate(bss, ¶ms); | |
3655 | } | |
3656 | ||
3657 | ||
9ebce9c5 JM |
3658 | static int wpa_driver_nl80211_send_mlme(struct i802_bss *bss, const u8 *data, |
3659 | size_t data_len, int noack, | |
3660 | unsigned int freq, int no_cck, | |
3661 | int offchanok, | |
2d3943ce AO |
3662 | unsigned int wait_time, |
3663 | const u16 *csa_offs, | |
27cc06d0 | 3664 | size_t csa_offs_len, int no_encrypt) |
2c2010ac | 3665 | { |
a2e40bb6 | 3666 | struct wpa_driver_nl80211_data *drv = bss->drv; |
2c2010ac | 3667 | struct ieee80211_mgmt *mgmt; |
27cc06d0 | 3668 | int encrypt = !no_encrypt; |
2c2010ac | 3669 | u16 fc; |
5ad372cc | 3670 | int use_cookie = 1; |
0dae4354 | 3671 | int res; |
2c2010ac JM |
3672 | |
3673 | mgmt = (struct ieee80211_mgmt *) data; | |
3674 | fc = le_to_host16(mgmt->frame_control); | |
f95a4524 | 3675 | wpa_printf(MSG_DEBUG, "nl80211: send_mlme - da= " MACSTR |
27cc06d0 | 3676 | " noack=%d freq=%u no_cck=%d offchanok=%d wait_time=%u no_encrypt=%d fc=0x%x (%s) nlmode=%d", |
f95a4524 | 3677 | MAC2STR(mgmt->da), noack, freq, no_cck, offchanok, wait_time, |
27cc06d0 | 3678 | no_encrypt, fc, fc2str(fc), drv->nlmode); |
2c2010ac | 3679 | |
8e12685c AS |
3680 | if ((is_sta_interface(drv->nlmode) || |
3681 | drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) && | |
5582a5d1 JB |
3682 | WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && |
3683 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_PROBE_RESP) { | |
3684 | /* | |
3685 | * The use of last_mgmt_freq is a bit of a hack, | |
3686 | * but it works due to the single-threaded nature | |
3687 | * of wpa_supplicant. | |
3688 | */ | |
af964484 JM |
3689 | if (freq == 0) { |
3690 | wpa_printf(MSG_DEBUG, "nl80211: Use last_mgmt_freq=%d", | |
3691 | drv->last_mgmt_freq); | |
55231068 | 3692 | freq = drv->last_mgmt_freq; |
af964484 | 3693 | } |
5ad372cc JM |
3694 | wait_time = 0; |
3695 | use_cookie = 0; | |
3696 | no_cck = 1; | |
3697 | offchanok = 1; | |
3698 | goto send_frame_cmd; | |
5582a5d1 JB |
3699 | } |
3700 | ||
61cbe2ff | 3701 | if (drv->device_ap_sme && is_ap_interface(drv->nlmode)) { |
af964484 JM |
3702 | if (freq == 0) { |
3703 | wpa_printf(MSG_DEBUG, "nl80211: Use bss->freq=%d", | |
3704 | bss->freq); | |
55231068 | 3705 | freq = bss->freq; |
af964484 | 3706 | } |
5ad372cc JM |
3707 | if ((int) freq == bss->freq) |
3708 | wait_time = 0; | |
3709 | goto send_frame_cmd; | |
86957e62 JM |
3710 | } |
3711 | ||
2c2010ac JM |
3712 | if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && |
3713 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_AUTH) { | |
3714 | /* | |
3715 | * Only one of the authentication frame types is encrypted. | |
3716 | * In order for static WEP encryption to work properly (i.e., | |
3717 | * to not encrypt the frame), we need to tell mac80211 about | |
3718 | * the frames that must not be encrypted. | |
3719 | */ | |
3720 | u16 auth_alg = le_to_host16(mgmt->u.auth.auth_alg); | |
3721 | u16 auth_trans = le_to_host16(mgmt->u.auth.auth_transaction); | |
7a47d567 JB |
3722 | if (auth_alg != WLAN_AUTH_SHARED_KEY || auth_trans != 3) |
3723 | encrypt = 0; | |
2c2010ac JM |
3724 | } |
3725 | ||
0dae4354 JM |
3726 | if (freq == 0 && drv->nlmode == NL80211_IFTYPE_ADHOC) { |
3727 | freq = nl80211_get_assoc_freq(drv); | |
3728 | wpa_printf(MSG_DEBUG, | |
3729 | "nl80211: send_mlme - Use assoc_freq=%u for IBSS", | |
3730 | freq); | |
3731 | } | |
3732 | if (freq == 0) { | |
3733 | wpa_printf(MSG_DEBUG, "nl80211: send_mlme - Use bss->freq=%u", | |
3734 | bss->freq); | |
3735 | freq = bss->freq; | |
3736 | } | |
3737 | ||
3738 | if (drv->use_monitor) { | |
3739 | wpa_printf(MSG_DEBUG, | |
3740 | "nl80211: send_frame(freq=%u bss->freq=%u) -> send_monitor", | |
3741 | freq, bss->freq); | |
3742 | return nl80211_send_monitor(drv, data, data_len, encrypt, | |
3743 | noack); | |
3744 | } | |
3745 | ||
5ad372cc JM |
3746 | if (noack || WLAN_FC_GET_TYPE(fc) != WLAN_FC_TYPE_MGMT || |
3747 | WLAN_FC_GET_STYPE(fc) != WLAN_FC_STYPE_ACTION) | |
3748 | use_cookie = 0; | |
3749 | send_frame_cmd: | |
9bedf900 JM |
3750 | #ifdef CONFIG_TESTING_OPTIONS |
3751 | if (no_encrypt && !encrypt && !drv->use_monitor) { | |
3752 | wpa_printf(MSG_DEBUG, | |
3753 | "nl80211: Request to send an unencrypted frame - use a monitor interface for this"); | |
3754 | if (nl80211_create_monitor_interface(drv) < 0) | |
3755 | return -1; | |
3756 | res = nl80211_send_monitor(drv, data, data_len, encrypt, | |
3757 | noack); | |
3758 | nl80211_remove_monitor_interface(drv); | |
3759 | return res; | |
3760 | } | |
3761 | #endif /* CONFIG_TESTING_OPTIONS */ | |
3762 | ||
0dae4354 JM |
3763 | wpa_printf(MSG_DEBUG, "nl80211: send_mlme -> send_frame_cmd"); |
3764 | res = nl80211_send_frame_cmd(bss, freq, wait_time, data, data_len, | |
5ad372cc | 3765 | use_cookie, no_cck, noack, offchanok, |
0dae4354 | 3766 | csa_offs, csa_offs_len); |
0dae4354 JM |
3767 | |
3768 | return res; | |
55231068 JM |
3769 | } |
3770 | ||
3771 | ||
cae87abd JM |
3772 | static int nl80211_put_basic_rates(struct nl_msg *msg, const int *basic_rates) |
3773 | { | |
3774 | u8 rates[NL80211_MAX_SUPP_RATES]; | |
3775 | u8 rates_len = 0; | |
3776 | int i; | |
3777 | ||
3778 | if (!basic_rates) | |
3779 | return 0; | |
3780 | ||
3781 | for (i = 0; i < NL80211_MAX_SUPP_RATES && basic_rates[i] >= 0; i++) | |
3782 | rates[rates_len++] = basic_rates[i] / 5; | |
3783 | ||
3784 | return nla_put(msg, NL80211_ATTR_BSS_BASIC_RATES, rates_len, rates); | |
3785 | } | |
3786 | ||
3787 | ||
31357268 | 3788 | static int nl80211_set_bss(struct i802_bss *bss, int cts, int preamble, |
e5693c47 | 3789 | int slot, int ht_opmode, int ap_isolate, |
cae87abd | 3790 | const int *basic_rates) |
31357268 JM |
3791 | { |
3792 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
3793 | struct nl_msg *msg; | |
3794 | ||
13f83980 | 3795 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_BSS)) || |
a862e4a3 JM |
3796 | (cts >= 0 && |
3797 | nla_put_u8(msg, NL80211_ATTR_BSS_CTS_PROT, cts)) || | |
3798 | (preamble >= 0 && | |
3799 | nla_put_u8(msg, NL80211_ATTR_BSS_SHORT_PREAMBLE, preamble)) || | |
3800 | (slot >= 0 && | |
3801 | nla_put_u8(msg, NL80211_ATTR_BSS_SHORT_SLOT_TIME, slot)) || | |
3802 | (ht_opmode >= 0 && | |
3803 | nla_put_u16(msg, NL80211_ATTR_BSS_HT_OPMODE, ht_opmode)) || | |
3804 | (ap_isolate >= 0 && | |
cae87abd JM |
3805 | nla_put_u8(msg, NL80211_ATTR_AP_ISOLATE, ap_isolate)) || |
3806 | nl80211_put_basic_rates(msg, basic_rates)) { | |
3807 | nlmsg_free(msg); | |
3808 | return -ENOBUFS; | |
e5693c47 JM |
3809 | } |
3810 | ||
31357268 | 3811 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
31357268 JM |
3812 | } |
3813 | ||
3814 | ||
3c4ca363 VN |
3815 | static int wpa_driver_nl80211_set_acl(void *priv, |
3816 | struct hostapd_acl_params *params) | |
3817 | { | |
3818 | struct i802_bss *bss = priv; | |
3819 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
3820 | struct nl_msg *msg; | |
f429ec44 | 3821 | struct nl_msg *acl; |
3c4ca363 | 3822 | unsigned int i; |
a862e4a3 | 3823 | int ret; |
3c4ca363 VN |
3824 | |
3825 | if (!(drv->capa.max_acl_mac_addrs)) | |
3826 | return -ENOTSUP; | |
3827 | ||
3828 | if (params->num_mac_acl > drv->capa.max_acl_mac_addrs) | |
3829 | return -ENOTSUP; | |
3830 | ||
3c4ca363 VN |
3831 | wpa_printf(MSG_DEBUG, "nl80211: Set %s ACL (num_mac_acl=%u)", |
3832 | params->acl_policy ? "Accept" : "Deny", params->num_mac_acl); | |
3833 | ||
f429ec44 JM |
3834 | acl = nlmsg_alloc(); |
3835 | if (!acl) | |
3836 | return -ENOMEM; | |
3837 | for (i = 0; i < params->num_mac_acl; i++) { | |
3838 | if (nla_put(acl, i + 1, ETH_ALEN, params->mac_acl[i].addr)) { | |
3839 | nlmsg_free(acl); | |
3840 | return -ENOMEM; | |
3841 | } | |
3842 | } | |
3843 | ||
9725b784 | 3844 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_MAC_ACL)) || |
a862e4a3 JM |
3845 | nla_put_u32(msg, NL80211_ATTR_ACL_POLICY, params->acl_policy ? |
3846 | NL80211_ACL_POLICY_DENY_UNLESS_LISTED : | |
3847 | NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED) || | |
f429ec44 | 3848 | nla_put_nested(msg, NL80211_ATTR_MAC_ADDRS, acl)) { |
a862e4a3 | 3849 | nlmsg_free(msg); |
f429ec44 | 3850 | nlmsg_free(acl); |
a862e4a3 JM |
3851 | return -ENOMEM; |
3852 | } | |
f429ec44 | 3853 | nlmsg_free(acl); |
3c4ca363 VN |
3854 | |
3855 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
3c4ca363 VN |
3856 | if (ret) { |
3857 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set MAC ACL: %d (%s)", | |
3858 | ret, strerror(-ret)); | |
3859 | } | |
3860 | ||
3c4ca363 VN |
3861 | return ret; |
3862 | } | |
3863 | ||
3864 | ||
85e1fad8 JM |
3865 | static int nl80211_put_beacon_int(struct nl_msg *msg, int beacon_int) |
3866 | { | |
3867 | if (beacon_int > 0) { | |
3868 | wpa_printf(MSG_DEBUG, " * beacon_int=%d", beacon_int); | |
3869 | return nla_put_u32(msg, NL80211_ATTR_BEACON_INTERVAL, | |
3870 | beacon_int); | |
3871 | } | |
3872 | ||
3873 | return 0; | |
3874 | } | |
3875 | ||
3876 | ||
4ac2ea57 MH |
3877 | static int nl80211_put_dtim_period(struct nl_msg *msg, int dtim_period) |
3878 | { | |
3879 | if (dtim_period > 0) { | |
3880 | wpa_printf(MSG_DEBUG, " * dtim_period=%d", dtim_period); | |
3881 | return nla_put_u32(msg, NL80211_ATTR_DTIM_PERIOD, dtim_period); | |
3882 | } | |
3883 | ||
3884 | return 0; | |
3885 | } | |
3886 | ||
3887 | ||
052b8d38 MH |
3888 | #ifdef CONFIG_MESH |
3889 | static int nl80211_set_mesh_config(void *priv, | |
3890 | struct wpa_driver_mesh_bss_params *params) | |
3891 | { | |
3892 | struct i802_bss *bss = priv; | |
3893 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
3894 | struct nl_msg *msg; | |
3895 | int ret; | |
3896 | ||
3897 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_MESH_CONFIG); | |
3898 | if (!msg) | |
3899 | return -1; | |
3900 | ||
3901 | ret = nl80211_put_mesh_config(msg, params); | |
3902 | if (ret < 0) { | |
3903 | nlmsg_free(msg); | |
3904 | return ret; | |
3905 | } | |
3906 | ||
3907 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
3908 | if (ret) { | |
3909 | wpa_printf(MSG_ERROR, | |
3910 | "nl80211: Mesh config set failed: %d (%s)", | |
3911 | ret, strerror(-ret)); | |
3912 | return ret; | |
3913 | } | |
3914 | return 0; | |
3915 | } | |
3916 | #endif /* CONFIG_MESH */ | |
3917 | ||
3918 | ||
d4f3003c PK |
3919 | static int nl80211_put_beacon_rate(struct nl_msg *msg, const u64 flags, |
3920 | struct wpa_driver_ap_params *params) | |
3921 | { | |
3922 | struct nlattr *bands, *band; | |
3923 | struct nl80211_txrate_vht vht_rate; | |
3924 | ||
3925 | if (!params->freq || | |
3926 | (params->beacon_rate == 0 && | |
3927 | params->rate_type == BEACON_RATE_LEGACY)) | |
3928 | return 0; | |
3929 | ||
3930 | bands = nla_nest_start(msg, NL80211_ATTR_TX_RATES); | |
3931 | if (!bands) | |
3932 | return -1; | |
3933 | ||
3934 | switch (params->freq->mode) { | |
3935 | case HOSTAPD_MODE_IEEE80211B: | |
3936 | case HOSTAPD_MODE_IEEE80211G: | |
3937 | band = nla_nest_start(msg, NL80211_BAND_2GHZ); | |
3938 | break; | |
3939 | case HOSTAPD_MODE_IEEE80211A: | |
3940 | band = nla_nest_start(msg, NL80211_BAND_5GHZ); | |
3941 | break; | |
3942 | case HOSTAPD_MODE_IEEE80211AD: | |
3943 | band = nla_nest_start(msg, NL80211_BAND_60GHZ); | |
3944 | break; | |
3945 | default: | |
3946 | return 0; | |
3947 | } | |
3948 | ||
3949 | if (!band) | |
3950 | return -1; | |
3951 | ||
3952 | os_memset(&vht_rate, 0, sizeof(vht_rate)); | |
3953 | ||
3954 | switch (params->rate_type) { | |
3955 | case BEACON_RATE_LEGACY: | |
3956 | if (!(flags & WPA_DRIVER_FLAGS_BEACON_RATE_LEGACY)) { | |
3957 | wpa_printf(MSG_INFO, | |
3958 | "nl80211: Driver does not support setting Beacon frame rate (legacy)"); | |
3959 | return -1; | |
3960 | } | |
3961 | ||
3962 | if (nla_put_u8(msg, NL80211_TXRATE_LEGACY, | |
3963 | (u8) params->beacon_rate / 5) || | |
3964 | nla_put(msg, NL80211_TXRATE_HT, 0, NULL) || | |
3965 | (params->freq->vht_enabled && | |
3966 | nla_put(msg, NL80211_TXRATE_VHT, sizeof(vht_rate), | |
3967 | &vht_rate))) | |
3968 | return -1; | |
3969 | ||
3970 | wpa_printf(MSG_DEBUG, " * beacon_rate = legacy:%u (* 100 kbps)", | |
3971 | params->beacon_rate); | |
3972 | break; | |
3973 | case BEACON_RATE_HT: | |
3974 | if (!(flags & WPA_DRIVER_FLAGS_BEACON_RATE_HT)) { | |
3975 | wpa_printf(MSG_INFO, | |
3976 | "nl80211: Driver does not support setting Beacon frame rate (HT)"); | |
3977 | return -1; | |
3978 | } | |
3979 | if (nla_put(msg, NL80211_TXRATE_LEGACY, 0, NULL) || | |
3980 | nla_put_u8(msg, NL80211_TXRATE_HT, params->beacon_rate) || | |
3981 | (params->freq->vht_enabled && | |
3982 | nla_put(msg, NL80211_TXRATE_VHT, sizeof(vht_rate), | |
3983 | &vht_rate))) | |
3984 | return -1; | |
3985 | wpa_printf(MSG_DEBUG, " * beacon_rate = HT-MCS %u", | |
3986 | params->beacon_rate); | |
3987 | break; | |
3988 | case BEACON_RATE_VHT: | |
3989 | if (!(flags & WPA_DRIVER_FLAGS_BEACON_RATE_VHT)) { | |
3990 | wpa_printf(MSG_INFO, | |
3991 | "nl80211: Driver does not support setting Beacon frame rate (VHT)"); | |
3992 | return -1; | |
3993 | } | |
3994 | vht_rate.mcs[0] = BIT(params->beacon_rate); | |
3995 | if (nla_put(msg, NL80211_TXRATE_LEGACY, 0, NULL)) | |
3996 | return -1; | |
3997 | if (nla_put(msg, NL80211_TXRATE_HT, 0, NULL)) | |
3998 | return -1; | |
3999 | if (nla_put(msg, NL80211_TXRATE_VHT, sizeof(vht_rate), | |
4000 | &vht_rate)) | |
4001 | return -1; | |
4002 | wpa_printf(MSG_DEBUG, " * beacon_rate = VHT-MCS %u", | |
4003 | params->beacon_rate); | |
4004 | break; | |
4005 | } | |
4006 | ||
4007 | nla_nest_end(msg, band); | |
4008 | nla_nest_end(msg, bands); | |
4009 | ||
4010 | return 0; | |
4011 | } | |
4012 | ||
4013 | ||
34f7c699 MB |
4014 | static int nl80211_set_multicast_to_unicast(struct i802_bss *bss, |
4015 | int multicast_to_unicast) | |
4016 | { | |
4017 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
4018 | struct nl_msg *msg; | |
4019 | int ret; | |
4020 | ||
4021 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_MULTICAST_TO_UNICAST); | |
4022 | if (!msg || | |
4023 | (multicast_to_unicast && | |
4024 | nla_put_flag(msg, NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED))) { | |
4025 | wpa_printf(MSG_ERROR, | |
4026 | "nl80211: Failed to build NL80211_CMD_SET_MULTICAST_TO_UNICAST msg for %s", | |
4027 | bss->ifname); | |
4028 | nlmsg_free(msg); | |
4029 | return -ENOBUFS; | |
4030 | } | |
4031 | ||
4032 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
4033 | ||
4034 | switch (ret) { | |
4035 | case 0: | |
4036 | wpa_printf(MSG_DEBUG, | |
4037 | "nl80211: multicast to unicast %s on interface %s", | |
4038 | multicast_to_unicast ? "enabled" : "disabled", | |
4039 | bss->ifname); | |
4040 | break; | |
4041 | case -EOPNOTSUPP: | |
4042 | if (!multicast_to_unicast) | |
4043 | break; | |
4044 | wpa_printf(MSG_INFO, | |
4045 | "nl80211: multicast to unicast not supported on interface %s", | |
4046 | bss->ifname); | |
4047 | break; | |
4048 | default: | |
4049 | wpa_printf(MSG_ERROR, | |
4050 | "nl80211: %s multicast to unicast failed with %d (%s) on interface %s", | |
4051 | multicast_to_unicast ? "enabling" : "disabling", | |
4052 | ret, strerror(-ret), bss->ifname); | |
4053 | break; | |
4054 | } | |
4055 | ||
4056 | return ret; | |
4057 | } | |
4058 | ||
4059 | ||
19c3b566 JM |
4060 | static int wpa_driver_nl80211_set_ap(void *priv, |
4061 | struct wpa_driver_ap_params *params) | |
d2440ba0 | 4062 | { |
a2e40bb6 FF |
4063 | struct i802_bss *bss = priv; |
4064 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
d2440ba0 JM |
4065 | struct nl_msg *msg; |
4066 | u8 cmd = NL80211_CMD_NEW_BEACON; | |
5b82cdbe | 4067 | int ret = -ENOBUFS; |
b4fd6fab | 4068 | int beacon_set; |
b11d1d64 | 4069 | int num_suites; |
da1080d7 | 4070 | int smps_mode; |
de4ed4a8 | 4071 | u32 suites[10], suite; |
b11d1d64 | 4072 | u32 ver; |
052b8d38 MH |
4073 | #ifdef CONFIG_MESH |
4074 | struct wpa_driver_mesh_bss_params mesh_params; | |
4075 | #endif /* CONFIG_MESH */ | |
b4fd6fab | 4076 | |
f33c8606 | 4077 | beacon_set = params->reenable ? 0 : bss->beacon_set; |
d2440ba0 | 4078 | |
d2440ba0 | 4079 | wpa_printf(MSG_DEBUG, "nl80211: Set beacon (beacon_set=%d)", |
b4fd6fab JM |
4080 | beacon_set); |
4081 | if (beacon_set) | |
d2440ba0 | 4082 | cmd = NL80211_CMD_SET_BEACON; |
89fa633a DL |
4083 | else if (!drv->device_ap_sme && !drv->use_monitor && |
4084 | !nl80211_get_wiphy_data_ap(bss)) | |
a70cd0db | 4085 | return -ENOBUFS; |
d2440ba0 | 4086 | |
b92e08fc JM |
4087 | wpa_hexdump(MSG_DEBUG, "nl80211: Beacon head", |
4088 | params->head, params->head_len); | |
b92e08fc JM |
4089 | wpa_hexdump(MSG_DEBUG, "nl80211: Beacon tail", |
4090 | params->tail, params->tail_len); | |
13f83980 | 4091 | wpa_printf(MSG_DEBUG, "nl80211: ifindex=%d", bss->ifindex); |
b92e08fc | 4092 | wpa_printf(MSG_DEBUG, "nl80211: beacon_int=%d", params->beacon_int); |
d4f3003c PK |
4093 | wpa_printf(MSG_DEBUG, "nl80211: beacon_rate=%u", params->beacon_rate); |
4094 | wpa_printf(MSG_DEBUG, "nl80211: rate_type=%d", params->rate_type); | |
b92e08fc | 4095 | wpa_printf(MSG_DEBUG, "nl80211: dtim_period=%d", params->dtim_period); |
21cd8f83 JM |
4096 | wpa_printf(MSG_DEBUG, "nl80211: ssid=%s", |
4097 | wpa_ssid_txt(params->ssid, params->ssid_len)); | |
13f83980 | 4098 | if (!(msg = nl80211_bss_msg(bss, 0, cmd)) || |
a862e4a3 JM |
4099 | nla_put(msg, NL80211_ATTR_BEACON_HEAD, params->head_len, |
4100 | params->head) || | |
4101 | nla_put(msg, NL80211_ATTR_BEACON_TAIL, params->tail_len, | |
4102 | params->tail) || | |
85e1fad8 | 4103 | nl80211_put_beacon_int(msg, params->beacon_int) || |
d4f3003c | 4104 | nl80211_put_beacon_rate(msg, drv->capa.flags, params) || |
4ac2ea57 | 4105 | nl80211_put_dtim_period(msg, params->dtim_period) || |
a862e4a3 JM |
4106 | nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid)) |
4107 | goto fail; | |
b92e08fc JM |
4108 | if (params->proberesp && params->proberesp_len) { |
4109 | wpa_hexdump(MSG_DEBUG, "nl80211: proberesp (offload)", | |
4110 | params->proberesp, params->proberesp_len); | |
a862e4a3 JM |
4111 | if (nla_put(msg, NL80211_ATTR_PROBE_RESP, params->proberesp_len, |
4112 | params->proberesp)) | |
4113 | goto fail; | |
b92e08fc | 4114 | } |
97a7a0b5 JM |
4115 | switch (params->hide_ssid) { |
4116 | case NO_SSID_HIDING: | |
b92e08fc | 4117 | wpa_printf(MSG_DEBUG, "nl80211: hidden SSID not in use"); |
a862e4a3 JM |
4118 | if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID, |
4119 | NL80211_HIDDEN_SSID_NOT_IN_USE)) | |
4120 | goto fail; | |
97a7a0b5 JM |
4121 | break; |
4122 | case HIDDEN_SSID_ZERO_LEN: | |
b92e08fc | 4123 | wpa_printf(MSG_DEBUG, "nl80211: hidden SSID zero len"); |
a862e4a3 JM |
4124 | if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID, |
4125 | NL80211_HIDDEN_SSID_ZERO_LEN)) | |
4126 | goto fail; | |
97a7a0b5 JM |
4127 | break; |
4128 | case HIDDEN_SSID_ZERO_CONTENTS: | |
b92e08fc | 4129 | wpa_printf(MSG_DEBUG, "nl80211: hidden SSID zero contents"); |
a862e4a3 JM |
4130 | if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID, |
4131 | NL80211_HIDDEN_SSID_ZERO_CONTENTS)) | |
4132 | goto fail; | |
97a7a0b5 JM |
4133 | break; |
4134 | } | |
b92e08fc | 4135 | wpa_printf(MSG_DEBUG, "nl80211: privacy=%d", params->privacy); |
a862e4a3 JM |
4136 | if (params->privacy && |
4137 | nla_put_flag(msg, NL80211_ATTR_PRIVACY)) | |
4138 | goto fail; | |
b92e08fc | 4139 | wpa_printf(MSG_DEBUG, "nl80211: auth_algs=0x%x", params->auth_algs); |
b11d1d64 JM |
4140 | if ((params->auth_algs & (WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED)) == |
4141 | (WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED)) { | |
4142 | /* Leave out the attribute */ | |
a862e4a3 JM |
4143 | } else if (params->auth_algs & WPA_AUTH_ALG_SHARED) { |
4144 | if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, | |
4145 | NL80211_AUTHTYPE_SHARED_KEY)) | |
4146 | goto fail; | |
4147 | } else { | |
4148 | if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, | |
4149 | NL80211_AUTHTYPE_OPEN_SYSTEM)) | |
4150 | goto fail; | |
4151 | } | |
b11d1d64 | 4152 | |
b92e08fc | 4153 | wpa_printf(MSG_DEBUG, "nl80211: wpa_version=0x%x", params->wpa_version); |
b11d1d64 JM |
4154 | ver = 0; |
4155 | if (params->wpa_version & WPA_PROTO_WPA) | |
4156 | ver |= NL80211_WPA_VERSION_1; | |
4157 | if (params->wpa_version & WPA_PROTO_RSN) | |
4158 | ver |= NL80211_WPA_VERSION_2; | |
a862e4a3 JM |
4159 | if (ver && |
4160 | nla_put_u32(msg, NL80211_ATTR_WPA_VERSIONS, ver)) | |
4161 | goto fail; | |
b11d1d64 | 4162 | |
b92e08fc JM |
4163 | wpa_printf(MSG_DEBUG, "nl80211: key_mgmt_suites=0x%x", |
4164 | params->key_mgmt_suites); | |
b11d1d64 JM |
4165 | num_suites = 0; |
4166 | if (params->key_mgmt_suites & WPA_KEY_MGMT_IEEE8021X) | |
3aa24db9 | 4167 | suites[num_suites++] = RSN_AUTH_KEY_MGMT_UNSPEC_802_1X; |
b11d1d64 | 4168 | if (params->key_mgmt_suites & WPA_KEY_MGMT_PSK) |
3aa24db9 | 4169 | suites[num_suites++] = RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X; |
a862e4a3 JM |
4170 | if (num_suites && |
4171 | nla_put(msg, NL80211_ATTR_AKM_SUITES, num_suites * sizeof(u32), | |
4172 | suites)) | |
4173 | goto fail; | |
b11d1d64 | 4174 | |
533fe09b | 4175 | if (params->key_mgmt_suites & WPA_KEY_MGMT_IEEE8021X_NO_WPA && |
e3429c0b JB |
4176 | (!params->pairwise_ciphers || |
4177 | params->pairwise_ciphers & (WPA_CIPHER_WEP104 | WPA_CIPHER_WEP40)) && | |
4178 | (nla_put_u16(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE, ETH_P_PAE) || | |
4179 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT))) | |
a862e4a3 | 4180 | goto fail; |
9f12614b | 4181 | |
c8931afe JM |
4182 | if (drv->device_ap_sme && |
4183 | (params->key_mgmt_suites & WPA_KEY_MGMT_SAE) && | |
4184 | nla_put_flag(msg, NL80211_ATTR_EXTERNAL_AUTH_SUPPORT)) | |
4185 | goto fail; | |
236e793e | 4186 | |
b92e08fc JM |
4187 | wpa_printf(MSG_DEBUG, "nl80211: pairwise_ciphers=0x%x", |
4188 | params->pairwise_ciphers); | |
de4ed4a8 JM |
4189 | num_suites = wpa_cipher_to_cipher_suites(params->pairwise_ciphers, |
4190 | suites, ARRAY_SIZE(suites)); | |
a862e4a3 JM |
4191 | if (num_suites && |
4192 | nla_put(msg, NL80211_ATTR_CIPHER_SUITES_PAIRWISE, | |
4193 | num_suites * sizeof(u32), suites)) | |
4194 | goto fail; | |
b11d1d64 | 4195 | |
b92e08fc JM |
4196 | wpa_printf(MSG_DEBUG, "nl80211: group_cipher=0x%x", |
4197 | params->group_cipher); | |
de4ed4a8 | 4198 | suite = wpa_cipher_to_cipher_suite(params->group_cipher); |
a862e4a3 JM |
4199 | if (suite && |
4200 | nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, suite)) | |
4201 | goto fail; | |
d2440ba0 | 4202 | |
ee298f1b JM |
4203 | if (params->ht_opmode != -1) { |
4204 | switch (params->smps_mode) { | |
4205 | case HT_CAP_INFO_SMPS_DYNAMIC: | |
4206 | wpa_printf(MSG_DEBUG, "nl80211: SMPS mode - dynamic"); | |
4207 | smps_mode = NL80211_SMPS_DYNAMIC; | |
4208 | break; | |
4209 | case HT_CAP_INFO_SMPS_STATIC: | |
4210 | wpa_printf(MSG_DEBUG, "nl80211: SMPS mode - static"); | |
4211 | smps_mode = NL80211_SMPS_STATIC; | |
4212 | break; | |
4213 | default: | |
4214 | /* invalid - fallback to smps off */ | |
4215 | case HT_CAP_INFO_SMPS_DISABLED: | |
4216 | wpa_printf(MSG_DEBUG, "nl80211: SMPS mode - off"); | |
4217 | smps_mode = NL80211_SMPS_OFF; | |
4218 | break; | |
4219 | } | |
a2426829 | 4220 | if (nla_put_u8(msg, NL80211_ATTR_SMPS_MODE, smps_mode)) |
ee298f1b | 4221 | goto fail; |
da1080d7 | 4222 | } |
da1080d7 | 4223 | |
fb91db56 | 4224 | if (params->beacon_ies) { |
b92e08fc JM |
4225 | wpa_hexdump_buf(MSG_DEBUG, "nl80211: beacon_ies", |
4226 | params->beacon_ies); | |
a862e4a3 JM |
4227 | if (nla_put(msg, NL80211_ATTR_IE, |
4228 | wpabuf_len(params->beacon_ies), | |
4229 | wpabuf_head(params->beacon_ies))) | |
4230 | goto fail; | |
fb91db56 JM |
4231 | } |
4232 | if (params->proberesp_ies) { | |
b92e08fc JM |
4233 | wpa_hexdump_buf(MSG_DEBUG, "nl80211: proberesp_ies", |
4234 | params->proberesp_ies); | |
a862e4a3 JM |
4235 | if (nla_put(msg, NL80211_ATTR_IE_PROBE_RESP, |
4236 | wpabuf_len(params->proberesp_ies), | |
4237 | wpabuf_head(params->proberesp_ies))) | |
4238 | goto fail; | |
fb91db56 JM |
4239 | } |
4240 | if (params->assocresp_ies) { | |
b92e08fc JM |
4241 | wpa_hexdump_buf(MSG_DEBUG, "nl80211: assocresp_ies", |
4242 | params->assocresp_ies); | |
a862e4a3 JM |
4243 | if (nla_put(msg, NL80211_ATTR_IE_ASSOC_RESP, |
4244 | wpabuf_len(params->assocresp_ies), | |
4245 | wpabuf_head(params->assocresp_ies))) | |
4246 | goto fail; | |
fb91db56 JM |
4247 | } |
4248 | ||
a0133ee1 | 4249 | if (drv->capa.flags & WPA_DRIVER_FLAGS_INACTIVITY_TIMER) { |
b92e08fc JM |
4250 | wpa_printf(MSG_DEBUG, "nl80211: ap_max_inactivity=%d", |
4251 | params->ap_max_inactivity); | |
a862e4a3 JM |
4252 | if (nla_put_u16(msg, NL80211_ATTR_INACTIVITY_TIMEOUT, |
4253 | params->ap_max_inactivity)) | |
4254 | goto fail; | |
a0133ee1 VT |
4255 | } |
4256 | ||
abb8d08b EP |
4257 | #ifdef CONFIG_P2P |
4258 | if (params->p2p_go_ctwindow > 0) { | |
4259 | if (drv->p2p_go_ctwindow_supported) { | |
4260 | wpa_printf(MSG_DEBUG, "nl80211: P2P GO ctwindow=%d", | |
4261 | params->p2p_go_ctwindow); | |
4262 | if (nla_put_u8(msg, NL80211_ATTR_P2P_CTWINDOW, | |
4263 | params->p2p_go_ctwindow)) | |
4264 | goto fail; | |
4265 | } else { | |
4266 | wpa_printf(MSG_INFO, | |
4267 | "nl80211: Driver does not support CTWindow configuration - ignore this parameter"); | |
4268 | } | |
4269 | } | |
4270 | #endif /* CONFIG_P2P */ | |
4271 | ||
86b5c400 LD |
4272 | if (params->pbss) { |
4273 | wpa_printf(MSG_DEBUG, "nl80211: PBSS"); | |
4274 | if (nla_put_flag(msg, NL80211_ATTR_PBSS)) | |
4275 | goto fail; | |
4276 | } | |
4277 | ||
5b82cdbe JB |
4278 | if (params->ftm_responder) { |
4279 | struct nlattr *ftm; | |
4280 | ||
4281 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_FTM_RESPONDER)) { | |
4282 | ret = -ENOTSUP; | |
4283 | goto fail; | |
4284 | } | |
4285 | ||
4286 | ftm = nla_nest_start(msg, NL80211_ATTR_FTM_RESPONDER); | |
4287 | if (!ftm || | |
4288 | nla_put_flag(msg, NL80211_FTM_RESP_ATTR_ENABLED) || | |
4289 | (params->lci && | |
4290 | nla_put(msg, NL80211_FTM_RESP_ATTR_LCI, | |
4291 | wpabuf_len(params->lci), | |
4292 | wpabuf_head(params->lci))) || | |
4293 | (params->civic && | |
4294 | nla_put(msg, NL80211_FTM_RESP_ATTR_CIVICLOC, | |
4295 | wpabuf_len(params->civic), | |
4296 | wpabuf_head(params->civic)))) | |
4297 | goto fail; | |
4298 | nla_nest_end(msg, ftm); | |
4299 | } | |
4300 | ||
a84bf443 JC |
4301 | #ifdef CONFIG_IEEE80211AX |
4302 | if (params->he_spr) { | |
4303 | struct nlattr *spr; | |
4304 | ||
4305 | spr = nla_nest_start(msg, NL80211_ATTR_HE_OBSS_PD); | |
4306 | wpa_printf(MSG_DEBUG, "nl80211: he_spr=%d", params->he_spr); | |
4307 | ||
4308 | if (nla_put_u8(msg, NL80211_HE_OBSS_PD_ATTR_MIN_OFFSET, | |
4309 | params->he_spr_srg_obss_pd_min_offset) || | |
4310 | nla_put_u8(msg, NL80211_HE_OBSS_PD_ATTR_MAX_OFFSET, | |
4311 | params->he_spr_srg_obss_pd_max_offset)) | |
4312 | goto fail; | |
4313 | ||
4314 | nla_nest_end(msg, spr); | |
4315 | } | |
4316 | #endif /* CONFIG_IEEE80211AX */ | |
4317 | ||
d2440ba0 JM |
4318 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
4319 | if (ret) { | |
4320 | wpa_printf(MSG_DEBUG, "nl80211: Beacon set failed: %d (%s)", | |
4321 | ret, strerror(-ret)); | |
b4fd6fab | 4322 | } else { |
b4fd6fab | 4323 | bss->beacon_set = 1; |
31357268 | 4324 | nl80211_set_bss(bss, params->cts_protect, params->preamble, |
d03e8d11 | 4325 | params->short_slot_time, params->ht_opmode, |
e5693c47 | 4326 | params->isolate, params->basic_rates); |
34f7c699 MB |
4327 | nl80211_set_multicast_to_unicast(bss, |
4328 | params->multicast_to_unicast); | |
e87ef751 PX |
4329 | if (beacon_set && params->freq && |
4330 | params->freq->bandwidth != bss->bandwidth) { | |
4331 | wpa_printf(MSG_DEBUG, | |
4332 | "nl80211: Update BSS %s bandwidth: %d -> %d", | |
4333 | bss->ifname, bss->bandwidth, | |
4334 | params->freq->bandwidth); | |
4335 | ret = nl80211_set_channel(bss, params->freq, 1); | |
4336 | if (ret) { | |
4337 | wpa_printf(MSG_DEBUG, | |
4338 | "nl80211: Frequency set failed: %d (%s)", | |
4339 | ret, strerror(-ret)); | |
4340 | } else { | |
4341 | wpa_printf(MSG_DEBUG, | |
4342 | "nl80211: Frequency set succeeded for ht2040 coex"); | |
4343 | bss->bandwidth = params->freq->bandwidth; | |
4344 | } | |
f5728d0a | 4345 | } else if (!beacon_set && params->freq) { |
e87ef751 PX |
4346 | /* |
4347 | * cfg80211 updates the driver on frequence change in AP | |
4348 | * mode only at the point when beaconing is started, so | |
4349 | * set the initial value here. | |
4350 | */ | |
4351 | bss->bandwidth = params->freq->bandwidth; | |
4352 | } | |
b4fd6fab | 4353 | } |
052b8d38 MH |
4354 | |
4355 | #ifdef CONFIG_MESH | |
4356 | if (is_mesh_interface(drv->nlmode) && params->ht_opmode != -1) { | |
4357 | os_memset(&mesh_params, 0, sizeof(mesh_params)); | |
4358 | mesh_params.flags |= WPA_DRIVER_MESH_CONF_FLAG_HT_OP_MODE; | |
4359 | mesh_params.ht_opmode = params->ht_opmode; | |
4360 | ret = nl80211_set_mesh_config(priv, &mesh_params); | |
4361 | if (ret < 0) | |
4362 | return ret; | |
4363 | } | |
4364 | #endif /* CONFIG_MESH */ | |
4365 | ||
d2440ba0 | 4366 | return ret; |
a862e4a3 | 4367 | fail: |
5883168a | 4368 | nlmsg_free(msg); |
5b82cdbe | 4369 | return ret; |
d2440ba0 JM |
4370 | } |
4371 | ||
4372 | ||
1c4ffa87 | 4373 | static int nl80211_put_freq_params(struct nl_msg *msg, |
72b2605f | 4374 | const struct hostapd_freq_params *freq) |
1581b38b | 4375 | { |
df4f9599 SE |
4376 | enum hostapd_hw_mode hw_mode; |
4377 | int is_24ghz; | |
4378 | u8 channel; | |
4379 | ||
1fc4ab23 | 4380 | wpa_printf(MSG_DEBUG, " * freq=%d", freq->freq); |
a862e4a3 JM |
4381 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq->freq)) |
4382 | return -ENOBUFS; | |
4383 | ||
ad9a1bfe | 4384 | wpa_printf(MSG_DEBUG, " * he_enabled=%d", freq->he_enabled); |
1fc4ab23 JM |
4385 | wpa_printf(MSG_DEBUG, " * vht_enabled=%d", freq->vht_enabled); |
4386 | wpa_printf(MSG_DEBUG, " * ht_enabled=%d", freq->ht_enabled); | |
4387 | ||
df4f9599 SE |
4388 | hw_mode = ieee80211_freq_to_chan(freq->freq, &channel); |
4389 | is_24ghz = hw_mode == HOSTAPD_MODE_IEEE80211G || | |
4390 | hw_mode == HOSTAPD_MODE_IEEE80211B; | |
4391 | ||
4392 | if (freq->vht_enabled || (freq->he_enabled && !is_24ghz)) { | |
a862e4a3 JM |
4393 | enum nl80211_chan_width cw; |
4394 | ||
1fc4ab23 | 4395 | wpa_printf(MSG_DEBUG, " * bandwidth=%d", freq->bandwidth); |
89b800d7 JB |
4396 | switch (freq->bandwidth) { |
4397 | case 20: | |
a862e4a3 | 4398 | cw = NL80211_CHAN_WIDTH_20; |
89b800d7 JB |
4399 | break; |
4400 | case 40: | |
a862e4a3 | 4401 | cw = NL80211_CHAN_WIDTH_40; |
89b800d7 JB |
4402 | break; |
4403 | case 80: | |
4404 | if (freq->center_freq2) | |
a862e4a3 | 4405 | cw = NL80211_CHAN_WIDTH_80P80; |
89b800d7 | 4406 | else |
a862e4a3 | 4407 | cw = NL80211_CHAN_WIDTH_80; |
89b800d7 JB |
4408 | break; |
4409 | case 160: | |
a862e4a3 | 4410 | cw = NL80211_CHAN_WIDTH_160; |
89b800d7 JB |
4411 | break; |
4412 | default: | |
1c4ffa87 | 4413 | return -EINVAL; |
89b800d7 | 4414 | } |
a862e4a3 | 4415 | |
1fc4ab23 JM |
4416 | wpa_printf(MSG_DEBUG, " * channel_width=%d", cw); |
4417 | wpa_printf(MSG_DEBUG, " * center_freq1=%d", | |
4418 | freq->center_freq1); | |
4419 | wpa_printf(MSG_DEBUG, " * center_freq2=%d", | |
4420 | freq->center_freq2); | |
a862e4a3 JM |
4421 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, cw) || |
4422 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, | |
4423 | freq->center_freq1) || | |
4424 | (freq->center_freq2 && | |
4425 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, | |
4426 | freq->center_freq2))) | |
4427 | return -ENOBUFS; | |
89b800d7 | 4428 | } else if (freq->ht_enabled) { |
a862e4a3 JM |
4429 | enum nl80211_channel_type ct; |
4430 | ||
1fc4ab23 JM |
4431 | wpa_printf(MSG_DEBUG, " * sec_channel_offset=%d", |
4432 | freq->sec_channel_offset); | |
89b800d7 | 4433 | switch (freq->sec_channel_offset) { |
f019981a | 4434 | case -1: |
a862e4a3 | 4435 | ct = NL80211_CHAN_HT40MINUS; |
f019981a JM |
4436 | break; |
4437 | case 1: | |
a862e4a3 | 4438 | ct = NL80211_CHAN_HT40PLUS; |
f019981a JM |
4439 | break; |
4440 | default: | |
a862e4a3 | 4441 | ct = NL80211_CHAN_HT20; |
f019981a JM |
4442 | break; |
4443 | } | |
a862e4a3 | 4444 | |
1fc4ab23 | 4445 | wpa_printf(MSG_DEBUG, " * channel_type=%d", ct); |
a862e4a3 JM |
4446 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, ct)) |
4447 | return -ENOBUFS; | |
dda5d9e3 AAL |
4448 | } else if (freq->edmg.channels && freq->edmg.bw_config) { |
4449 | wpa_printf(MSG_DEBUG, | |
4450 | " * EDMG configuration: channels=0x%x bw_config=%d", | |
4451 | freq->edmg.channels, freq->edmg.bw_config); | |
4452 | if (nla_put_u8(msg, NL80211_ATTR_WIPHY_EDMG_CHANNELS, | |
4453 | freq->edmg.channels) || | |
4454 | nla_put_u8(msg, NL80211_ATTR_WIPHY_EDMG_BW_CONFIG, | |
4455 | freq->edmg.bw_config)) | |
4456 | return -1; | |
3388e7b9 MH |
4457 | } else { |
4458 | wpa_printf(MSG_DEBUG, " * channel_type=%d", | |
4459 | NL80211_CHAN_NO_HT); | |
4460 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, | |
4461 | NL80211_CHAN_NO_HT)) | |
4462 | return -ENOBUFS; | |
f019981a | 4463 | } |
1c4ffa87 | 4464 | return 0; |
1c4ffa87 AO |
4465 | } |
4466 | ||
4467 | ||
e87ef751 PX |
4468 | static int nl80211_set_channel(struct i802_bss *bss, |
4469 | struct hostapd_freq_params *freq, int set_chan) | |
1c4ffa87 AO |
4470 | { |
4471 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
4472 | struct nl_msg *msg; | |
4473 | int ret; | |
4474 | ||
4475 | wpa_printf(MSG_DEBUG, | |
ad9a1bfe JC |
4476 | "nl80211: Set freq %d (ht_enabled=%d, vht_enabled=%d, he_enabled=%d, bandwidth=%d MHz, cf1=%d MHz, cf2=%d MHz)", |
4477 | freq->freq, freq->ht_enabled, freq->vht_enabled, freq->he_enabled, | |
1c4ffa87 | 4478 | freq->bandwidth, freq->center_freq1, freq->center_freq2); |
1c4ffa87 | 4479 | |
9725b784 JM |
4480 | msg = nl80211_drv_msg(drv, 0, set_chan ? NL80211_CMD_SET_CHANNEL : |
4481 | NL80211_CMD_SET_WIPHY); | |
4482 | if (!msg || nl80211_put_freq_params(msg, freq) < 0) { | |
a862e4a3 JM |
4483 | nlmsg_free(msg); |
4484 | return -1; | |
4485 | } | |
1581b38b | 4486 | |
d2440ba0 | 4487 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
e4fb2167 | 4488 | if (ret == 0) { |
89b800d7 | 4489 | bss->freq = freq->freq; |
1581b38b | 4490 | return 0; |
e4fb2167 | 4491 | } |
f019981a | 4492 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set channel (freq=%d): " |
89b800d7 | 4493 | "%d (%s)", freq->freq, ret, strerror(-ret)); |
1581b38b JM |
4494 | return -1; |
4495 | } | |
4496 | ||
0f4e8b4f | 4497 | |
95ab6063 AN |
4498 | static u32 sta_flags_nl80211(int flags) |
4499 | { | |
4500 | u32 f = 0; | |
4501 | ||
4502 | if (flags & WPA_STA_AUTHORIZED) | |
4503 | f |= BIT(NL80211_STA_FLAG_AUTHORIZED); | |
4504 | if (flags & WPA_STA_WMM) | |
4505 | f |= BIT(NL80211_STA_FLAG_WME); | |
4506 | if (flags & WPA_STA_SHORT_PREAMBLE) | |
4507 | f |= BIT(NL80211_STA_FLAG_SHORT_PREAMBLE); | |
4508 | if (flags & WPA_STA_MFP) | |
4509 | f |= BIT(NL80211_STA_FLAG_MFP); | |
45b722f1 AN |
4510 | if (flags & WPA_STA_TDLS_PEER) |
4511 | f |= BIT(NL80211_STA_FLAG_TDLS_PEER); | |
7a228b5c BC |
4512 | if (flags & WPA_STA_AUTHENTICATED) |
4513 | f |= BIT(NL80211_STA_FLAG_AUTHENTICATED); | |
dc55b6b6 AB |
4514 | if (flags & WPA_STA_ASSOCIATED) |
4515 | f |= BIT(NL80211_STA_FLAG_ASSOCIATED); | |
95ab6063 AN |
4516 | |
4517 | return f; | |
4518 | } | |
4519 | ||
4520 | ||
7c7e7877 BC |
4521 | #ifdef CONFIG_MESH |
4522 | static u32 sta_plink_state_nl80211(enum mesh_plink_state state) | |
4523 | { | |
4524 | switch (state) { | |
d02e5498 | 4525 | case PLINK_IDLE: |
7c7e7877 | 4526 | return NL80211_PLINK_LISTEN; |
d02e5498 | 4527 | case PLINK_OPN_SNT: |
7c7e7877 | 4528 | return NL80211_PLINK_OPN_SNT; |
d02e5498 | 4529 | case PLINK_OPN_RCVD: |
7c7e7877 BC |
4530 | return NL80211_PLINK_OPN_RCVD; |
4531 | case PLINK_CNF_RCVD: | |
4532 | return NL80211_PLINK_CNF_RCVD; | |
4533 | case PLINK_ESTAB: | |
4534 | return NL80211_PLINK_ESTAB; | |
4535 | case PLINK_HOLDING: | |
4536 | return NL80211_PLINK_HOLDING; | |
4537 | case PLINK_BLOCKED: | |
4538 | return NL80211_PLINK_BLOCKED; | |
4539 | default: | |
4540 | wpa_printf(MSG_ERROR, "nl80211: Invalid mesh plink state %d", | |
4541 | state); | |
4542 | } | |
4543 | return -1; | |
4544 | } | |
4545 | #endif /* CONFIG_MESH */ | |
4546 | ||
4547 | ||
62847751 | 4548 | static int wpa_driver_nl80211_sta_add(void *priv, |
0f4e8b4f JM |
4549 | struct hostapd_sta_add_params *params) |
4550 | { | |
a2e40bb6 FF |
4551 | struct i802_bss *bss = priv; |
4552 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8970bae8 | 4553 | struct nl_msg *msg; |
95ab6063 | 4554 | struct nl80211_sta_flag_update upd; |
0f4e8b4f JM |
4555 | int ret = -ENOBUFS; |
4556 | ||
45b722f1 AN |
4557 | if ((params->flags & WPA_STA_TDLS_PEER) && |
4558 | !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) | |
4559 | return -EOPNOTSUPP; | |
4560 | ||
e4dea253 JM |
4561 | wpa_printf(MSG_DEBUG, "nl80211: %s STA " MACSTR, |
4562 | params->set ? "Set" : "Add", MAC2STR(params->addr)); | |
13f83980 JM |
4563 | msg = nl80211_bss_msg(bss, 0, params->set ? NL80211_CMD_SET_STATION : |
4564 | NL80211_CMD_NEW_STATION); | |
4565 | if (!msg || nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->addr)) | |
a862e4a3 | 4566 | goto fail; |
5551bc9c | 4567 | |
dc55b6b6 AB |
4568 | /* |
4569 | * Set the below properties only in one of the following cases: | |
4570 | * 1. New station is added, already associated. | |
4571 | * 2. Set WPA_STA_TDLS_PEER station. | |
4572 | * 3. Set an already added unassociated station, if driver supports | |
4573 | * full AP client state. (Set these properties after station became | |
4574 | * associated will be rejected by the driver). | |
4575 | */ | |
4576 | if (!params->set || (params->flags & WPA_STA_TDLS_PEER) || | |
4577 | (params->set && FULL_AP_CLIENT_STATE_SUPP(drv->capa.flags) && | |
4578 | (params->flags & WPA_STA_ASSOCIATED))) { | |
5551bc9c BC |
4579 | wpa_hexdump(MSG_DEBUG, " * supported rates", |
4580 | params->supp_rates, params->supp_rates_len); | |
a862e4a3 JM |
4581 | wpa_printf(MSG_DEBUG, " * capability=0x%x", |
4582 | params->capability); | |
4583 | if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_RATES, | |
4584 | params->supp_rates_len, params->supp_rates) || | |
4585 | nla_put_u16(msg, NL80211_ATTR_STA_CAPABILITY, | |
4586 | params->capability)) | |
4587 | goto fail; | |
e503861f JM |
4588 | |
4589 | if (params->ht_capabilities) { | |
4590 | wpa_hexdump(MSG_DEBUG, " * ht_capabilities", | |
4591 | (u8 *) params->ht_capabilities, | |
4592 | sizeof(*params->ht_capabilities)); | |
a862e4a3 JM |
4593 | if (nla_put(msg, NL80211_ATTR_HT_CAPABILITY, |
4594 | sizeof(*params->ht_capabilities), | |
4595 | params->ht_capabilities)) | |
4596 | goto fail; | |
e503861f JM |
4597 | } |
4598 | ||
4599 | if (params->vht_capabilities) { | |
4600 | wpa_hexdump(MSG_DEBUG, " * vht_capabilities", | |
4601 | (u8 *) params->vht_capabilities, | |
4602 | sizeof(*params->vht_capabilities)); | |
a862e4a3 JM |
4603 | if (nla_put(msg, NL80211_ATTR_VHT_CAPABILITY, |
4604 | sizeof(*params->vht_capabilities), | |
4605 | params->vht_capabilities)) | |
4606 | goto fail; | |
e503861f JM |
4607 | } |
4608 | ||
59d9c3a1 JC |
4609 | if (params->he_capab) { |
4610 | wpa_hexdump(MSG_DEBUG, " * he_capab", | |
4611 | params->he_capab, params->he_capab_len); | |
4612 | if (nla_put(msg, NL80211_ATTR_HE_CAPABILITY, | |
4613 | params->he_capab_len, params->he_capab)) | |
4614 | goto fail; | |
4615 | } | |
4616 | ||
e503861f JM |
4617 | if (params->ext_capab) { |
4618 | wpa_hexdump(MSG_DEBUG, " * ext_capab", | |
4619 | params->ext_capab, params->ext_capab_len); | |
a862e4a3 JM |
4620 | if (nla_put(msg, NL80211_ATTR_STA_EXT_CAPABILITY, |
4621 | params->ext_capab_len, params->ext_capab)) | |
4622 | goto fail; | |
e503861f | 4623 | } |
ae33239c AB |
4624 | |
4625 | if (is_ap_interface(drv->nlmode) && | |
4626 | nla_put_u8(msg, NL80211_ATTR_STA_SUPPORT_P2P_PS, | |
4627 | params->support_p2p_ps ? | |
4628 | NL80211_P2P_PS_SUPPORTED : | |
4629 | NL80211_P2P_PS_UNSUPPORTED)) | |
4630 | goto fail; | |
5551bc9c | 4631 | } |
45b722f1 | 4632 | if (!params->set) { |
f11b72c3 JM |
4633 | if (params->aid) { |
4634 | wpa_printf(MSG_DEBUG, " * aid=%u", params->aid); | |
a862e4a3 JM |
4635 | if (nla_put_u16(msg, NL80211_ATTR_STA_AID, params->aid)) |
4636 | goto fail; | |
f11b72c3 JM |
4637 | } else { |
4638 | /* | |
4639 | * cfg80211 validates that AID is non-zero, so we have | |
4640 | * to make this a non-zero value for the TDLS case where | |
dc55b6b6 AB |
4641 | * a dummy STA entry is used for now and for a station |
4642 | * that is still not associated. | |
f11b72c3 | 4643 | */ |
dc55b6b6 AB |
4644 | wpa_printf(MSG_DEBUG, " * aid=1 (%s workaround)", |
4645 | (params->flags & WPA_STA_TDLS_PEER) ? | |
4646 | "TDLS" : "UNASSOC_STA"); | |
a862e4a3 JM |
4647 | if (nla_put_u16(msg, NL80211_ATTR_STA_AID, 1)) |
4648 | goto fail; | |
f11b72c3 | 4649 | } |
e4dea253 JM |
4650 | wpa_printf(MSG_DEBUG, " * listen_interval=%u", |
4651 | params->listen_interval); | |
a862e4a3 JM |
4652 | if (nla_put_u16(msg, NL80211_ATTR_STA_LISTEN_INTERVAL, |
4653 | params->listen_interval)) | |
4654 | goto fail; | |
e112764e JM |
4655 | } else if (params->aid && (params->flags & WPA_STA_TDLS_PEER)) { |
4656 | wpa_printf(MSG_DEBUG, " * peer_aid=%u", params->aid); | |
a862e4a3 JM |
4657 | if (nla_put_u16(msg, NL80211_ATTR_PEER_AID, params->aid)) |
4658 | goto fail; | |
dc55b6b6 AB |
4659 | } else if (FULL_AP_CLIENT_STATE_SUPP(drv->capa.flags) && |
4660 | (params->flags & WPA_STA_ASSOCIATED)) { | |
4661 | wpa_printf(MSG_DEBUG, " * aid=%u", params->aid); | |
4662 | wpa_printf(MSG_DEBUG, " * listen_interval=%u", | |
4663 | params->listen_interval); | |
4664 | if (nla_put_u16(msg, NL80211_ATTR_STA_AID, params->aid) || | |
4665 | nla_put_u16(msg, NL80211_ATTR_STA_LISTEN_INTERVAL, | |
4666 | params->listen_interval)) | |
4667 | goto fail; | |
45b722f1 | 4668 | } |
05a8d422 | 4669 | |
8a458116 MK |
4670 | if (params->vht_opmode_enabled) { |
4671 | wpa_printf(MSG_DEBUG, " * opmode=%u", params->vht_opmode); | |
a862e4a3 JM |
4672 | if (nla_put_u8(msg, NL80211_ATTR_OPMODE_NOTIF, |
4673 | params->vht_opmode)) | |
4674 | goto fail; | |
8a458116 MK |
4675 | } |
4676 | ||
efc64886 SD |
4677 | if (params->supp_channels) { |
4678 | wpa_hexdump(MSG_DEBUG, " * supported channels", | |
4679 | params->supp_channels, params->supp_channels_len); | |
a862e4a3 JM |
4680 | if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_CHANNELS, |
4681 | params->supp_channels_len, params->supp_channels)) | |
4682 | goto fail; | |
efc64886 SD |
4683 | } |
4684 | ||
4685 | if (params->supp_oper_classes) { | |
4686 | wpa_hexdump(MSG_DEBUG, " * supported operating classes", | |
4687 | params->supp_oper_classes, | |
4688 | params->supp_oper_classes_len); | |
a862e4a3 JM |
4689 | if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES, |
4690 | params->supp_oper_classes_len, | |
4691 | params->supp_oper_classes)) | |
4692 | goto fail; | |
efc64886 SD |
4693 | } |
4694 | ||
95ab6063 | 4695 | os_memset(&upd, 0, sizeof(upd)); |
7e31703e BC |
4696 | upd.set = sta_flags_nl80211(params->flags); |
4697 | upd.mask = upd.set | sta_flags_nl80211(params->flags_mask); | |
dc55b6b6 AB |
4698 | |
4699 | /* | |
4700 | * If the driver doesn't support full AP client state, ignore ASSOC/AUTH | |
4701 | * flags, as nl80211 driver moves a new station, by default, into | |
4702 | * associated state. | |
4703 | * | |
4704 | * On the other hand, if the driver supports that feature and the | |
4705 | * station is added in unauthenticated state, set the | |
4706 | * authenticated/associated bits in the mask to prevent moving this | |
4707 | * station to associated state before it is actually associated. | |
4708 | * | |
4709 | * This is irrelevant for mesh mode where the station is added to the | |
4710 | * driver as authenticated already, and ASSOCIATED isn't part of the | |
4711 | * nl80211 API. | |
4712 | */ | |
4713 | if (!is_mesh_interface(drv->nlmode)) { | |
4714 | if (!FULL_AP_CLIENT_STATE_SUPP(drv->capa.flags)) { | |
4715 | wpa_printf(MSG_DEBUG, | |
4716 | "nl80211: Ignore ASSOC/AUTH flags since driver doesn't support full AP client state"); | |
4717 | upd.mask &= ~(BIT(NL80211_STA_FLAG_ASSOCIATED) | | |
4718 | BIT(NL80211_STA_FLAG_AUTHENTICATED)); | |
4719 | } else if (!params->set && | |
4720 | !(params->flags & WPA_STA_TDLS_PEER)) { | |
4721 | if (!(params->flags & WPA_STA_AUTHENTICATED)) | |
4722 | upd.mask |= BIT(NL80211_STA_FLAG_AUTHENTICATED); | |
4723 | if (!(params->flags & WPA_STA_ASSOCIATED)) | |
4724 | upd.mask |= BIT(NL80211_STA_FLAG_ASSOCIATED); | |
4725 | } | |
e347cafe MH |
4726 | #ifdef CONFIG_MESH |
4727 | } else { | |
4728 | if (params->plink_state == PLINK_ESTAB && params->peer_aid) { | |
4729 | ret = nla_put_u16(msg, NL80211_ATTR_MESH_PEER_AID, | |
4730 | params->peer_aid); | |
4731 | if (ret) | |
4732 | goto fail; | |
4733 | } | |
4734 | #endif /* CONFIG_MESH */ | |
dc55b6b6 AB |
4735 | } |
4736 | ||
e4dea253 JM |
4737 | wpa_printf(MSG_DEBUG, " * flags set=0x%x mask=0x%x", |
4738 | upd.set, upd.mask); | |
a862e4a3 JM |
4739 | if (nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd)) |
4740 | goto fail; | |
95ab6063 | 4741 | |
7c7e7877 | 4742 | #ifdef CONFIG_MESH |
a862e4a3 JM |
4743 | if (params->plink_state && |
4744 | nla_put_u8(msg, NL80211_ATTR_STA_PLINK_STATE, | |
4745 | sta_plink_state_nl80211(params->plink_state))) | |
4746 | goto fail; | |
7c7e7877 BC |
4747 | #endif /* CONFIG_MESH */ |
4748 | ||
968520da SD |
4749 | if ((!params->set || (params->flags & WPA_STA_TDLS_PEER) || |
4750 | FULL_AP_CLIENT_STATE_SUPP(drv->capa.flags)) && | |
4751 | (params->flags & WPA_STA_WMM)) { | |
8970bae8 JB |
4752 | struct nlattr *wme = nla_nest_start(msg, NL80211_ATTR_STA_WME); |
4753 | ||
e4dea253 | 4754 | wpa_printf(MSG_DEBUG, " * qosinfo=0x%x", params->qosinfo); |
a862e4a3 JM |
4755 | if (!wme || |
4756 | nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES, | |
4757 | params->qosinfo & WMM_QOSINFO_STA_AC_MASK) || | |
4758 | nla_put_u8(msg, NL80211_STA_WME_MAX_SP, | |
4759 | (params->qosinfo >> WMM_QOSINFO_STA_SP_SHIFT) & | |
4760 | WMM_QOSINFO_STA_SP_MASK)) | |
4761 | goto fail; | |
8970bae8 | 4762 | nla_nest_end(msg, wme); |
774bfa62 EP |
4763 | } |
4764 | ||
0f4e8b4f | 4765 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
5883168a | 4766 | msg = NULL; |
0f4e8b4f | 4767 | if (ret) |
45b722f1 AN |
4768 | wpa_printf(MSG_DEBUG, "nl80211: NL80211_CMD_%s_STATION " |
4769 | "result: %d (%s)", params->set ? "SET" : "NEW", ret, | |
4770 | strerror(-ret)); | |
0f4e8b4f JM |
4771 | if (ret == -EEXIST) |
4772 | ret = 0; | |
a862e4a3 | 4773 | fail: |
5883168a | 4774 | nlmsg_free(msg); |
0f4e8b4f JM |
4775 | return ret; |
4776 | } | |
4777 | ||
4778 | ||
97ed9a06 KP |
4779 | static void rtnl_neigh_delete_fdb_entry(struct i802_bss *bss, const u8 *addr) |
4780 | { | |
4781 | #ifdef CONFIG_LIBNL3_ROUTE | |
4782 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
4783 | struct rtnl_neigh *rn; | |
4784 | struct nl_addr *nl_addr; | |
4785 | int err; | |
4786 | ||
4787 | rn = rtnl_neigh_alloc(); | |
4788 | if (!rn) | |
4789 | return; | |
4790 | ||
4791 | rtnl_neigh_set_family(rn, AF_BRIDGE); | |
4792 | rtnl_neigh_set_ifindex(rn, bss->ifindex); | |
4793 | nl_addr = nl_addr_build(AF_BRIDGE, (void *) addr, ETH_ALEN); | |
4794 | if (!nl_addr) { | |
4795 | rtnl_neigh_put(rn); | |
4796 | return; | |
4797 | } | |
4798 | rtnl_neigh_set_lladdr(rn, nl_addr); | |
4799 | ||
4800 | err = rtnl_neigh_delete(drv->rtnl_sk, rn, 0); | |
4801 | if (err < 0) { | |
4802 | wpa_printf(MSG_DEBUG, "nl80211: bridge FDB entry delete for " | |
4803 | MACSTR " ifindex=%d failed: %s", MAC2STR(addr), | |
4804 | bss->ifindex, nl_geterror(err)); | |
4805 | } else { | |
4806 | wpa_printf(MSG_DEBUG, "nl80211: deleted bridge FDB entry for " | |
4807 | MACSTR, MAC2STR(addr)); | |
4808 | } | |
4809 | ||
4810 | nl_addr_put(nl_addr); | |
4811 | rtnl_neigh_put(rn); | |
4812 | #endif /* CONFIG_LIBNL3_ROUTE */ | |
4813 | } | |
4814 | ||
4815 | ||
59d7148a JM |
4816 | static int wpa_driver_nl80211_sta_remove(struct i802_bss *bss, const u8 *addr, |
4817 | int deauth, u16 reason_code) | |
0f4e8b4f | 4818 | { |
a2e40bb6 | 4819 | struct wpa_driver_nl80211_data *drv = bss->drv; |
0f4e8b4f JM |
4820 | struct nl_msg *msg; |
4821 | int ret; | |
4822 | ||
13f83980 | 4823 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_DEL_STATION)) || |
a862e4a3 JM |
4824 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
4825 | (deauth == 0 && | |
4826 | nla_put_u8(msg, NL80211_ATTR_MGMT_SUBTYPE, | |
4827 | WLAN_FC_STYPE_DISASSOC)) || | |
4828 | (deauth == 1 && | |
4829 | nla_put_u8(msg, NL80211_ATTR_MGMT_SUBTYPE, | |
4830 | WLAN_FC_STYPE_DEAUTH)) || | |
4831 | (reason_code && | |
4832 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) { | |
4833 | nlmsg_free(msg); | |
4834 | return -ENOBUFS; | |
4835 | } | |
0f4e8b4f JM |
4836 | |
4837 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
83e7bb0e JM |
4838 | wpa_printf(MSG_DEBUG, "nl80211: sta_remove -> DEL_STATION %s " MACSTR |
4839 | " --> %d (%s)", | |
4840 | bss->ifname, MAC2STR(addr), ret, strerror(-ret)); | |
97ed9a06 KP |
4841 | |
4842 | if (drv->rtnl_sk) | |
4843 | rtnl_neigh_delete_fdb_entry(bss, addr); | |
4844 | ||
0f4e8b4f JM |
4845 | if (ret == -ENOENT) |
4846 | return 0; | |
4847 | return ret; | |
0f4e8b4f JM |
4848 | } |
4849 | ||
1581b38b | 4850 | |
f3407c66 | 4851 | void nl80211_remove_iface(struct wpa_driver_nl80211_data *drv, int ifidx) |
0915d02c JM |
4852 | { |
4853 | struct nl_msg *msg; | |
de884303 | 4854 | struct wpa_driver_nl80211_data *drv2; |
0915d02c | 4855 | |
c6e8e8e4 JM |
4856 | wpa_printf(MSG_DEBUG, "nl80211: Remove interface ifindex=%d", ifidx); |
4857 | ||
2135f224 | 4858 | /* stop listening for EAPOL on this interface */ |
de884303 JM |
4859 | dl_list_for_each(drv2, &drv->global->interfaces, |
4860 | struct wpa_driver_nl80211_data, list) | |
732b1d20 MB |
4861 | { |
4862 | del_ifidx(drv2, ifidx, IFIDX_ANY); | |
4863 | /* Remove all bridges learned for this iface */ | |
4864 | del_ifidx(drv2, IFIDX_ANY, ifidx); | |
4865 | } | |
2135f224 | 4866 | |
95376e1a | 4867 | msg = nl80211_ifindex_msg(drv, ifidx, 0, NL80211_CMD_DEL_INTERFACE); |
0915d02c JM |
4868 | if (send_and_recv_msgs(drv, msg, NULL, NULL) == 0) |
4869 | return; | |
e748062b | 4870 | wpa_printf(MSG_ERROR, "Failed to remove interface (ifidx=%d)", ifidx); |
0915d02c JM |
4871 | } |
4872 | ||
4873 | ||
cc9a2575 | 4874 | const char * nl80211_iftype_str(enum nl80211_iftype mode) |
a1922f93 JM |
4875 | { |
4876 | switch (mode) { | |
4877 | case NL80211_IFTYPE_ADHOC: | |
4878 | return "ADHOC"; | |
4879 | case NL80211_IFTYPE_STATION: | |
4880 | return "STATION"; | |
4881 | case NL80211_IFTYPE_AP: | |
4882 | return "AP"; | |
1045ec36 JM |
4883 | case NL80211_IFTYPE_AP_VLAN: |
4884 | return "AP_VLAN"; | |
4885 | case NL80211_IFTYPE_WDS: | |
4886 | return "WDS"; | |
a1922f93 JM |
4887 | case NL80211_IFTYPE_MONITOR: |
4888 | return "MONITOR"; | |
1045ec36 JM |
4889 | case NL80211_IFTYPE_MESH_POINT: |
4890 | return "MESH_POINT"; | |
a1922f93 JM |
4891 | case NL80211_IFTYPE_P2P_CLIENT: |
4892 | return "P2P_CLIENT"; | |
4893 | case NL80211_IFTYPE_P2P_GO: | |
4894 | return "P2P_GO"; | |
7aad838c NS |
4895 | case NL80211_IFTYPE_P2P_DEVICE: |
4896 | return "P2P_DEVICE"; | |
a1922f93 JM |
4897 | default: |
4898 | return "unknown"; | |
4899 | } | |
4900 | } | |
4901 | ||
4902 | ||
a35187e7 KH |
4903 | static int nl80211_create_iface_once(struct wpa_driver_nl80211_data *drv, |
4904 | const char *ifname, | |
4905 | enum nl80211_iftype iftype, | |
d6dcfcda DS |
4906 | const u8 *addr, int wds, |
4907 | int (*handler)(struct nl_msg *, void *), | |
4908 | void *arg) | |
0915d02c | 4909 | { |
8970bae8 | 4910 | struct nl_msg *msg; |
0915d02c JM |
4911 | int ifidx; |
4912 | int ret = -ENOBUFS; | |
4913 | ||
a1922f93 JM |
4914 | wpa_printf(MSG_DEBUG, "nl80211: Create interface iftype %d (%s)", |
4915 | iftype, nl80211_iftype_str(iftype)); | |
4916 | ||
56f77852 JM |
4917 | msg = nl80211_cmd_msg(drv->first_bss, 0, NL80211_CMD_NEW_INTERFACE); |
4918 | if (!msg || | |
a862e4a3 JM |
4919 | nla_put_string(msg, NL80211_ATTR_IFNAME, ifname) || |
4920 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, iftype)) | |
4921 | goto fail; | |
0915d02c JM |
4922 | |
4923 | if (iftype == NL80211_IFTYPE_MONITOR) { | |
8970bae8 | 4924 | struct nlattr *flags; |
0915d02c | 4925 | |
8970bae8 | 4926 | flags = nla_nest_start(msg, NL80211_ATTR_MNTR_FLAGS); |
a862e4a3 JM |
4927 | if (!flags || |
4928 | nla_put_flag(msg, NL80211_MNTR_FLAG_COOK_FRAMES)) | |
4929 | goto fail; | |
0915d02c | 4930 | |
8970bae8 | 4931 | nla_nest_end(msg, flags); |
fbbfcbac | 4932 | } else if (wds) { |
a862e4a3 JM |
4933 | if (nla_put_u8(msg, NL80211_ATTR_4ADDR, wds)) |
4934 | goto fail; | |
0915d02c JM |
4935 | } |
4936 | ||
52f5877a IP |
4937 | /* |
4938 | * Tell cfg80211 that the interface belongs to the socket that created | |
4939 | * it, and the interface should be deleted when the socket is closed. | |
4940 | */ | |
a862e4a3 JM |
4941 | if (nla_put_flag(msg, NL80211_ATTR_IFACE_SOCKET_OWNER)) |
4942 | goto fail; | |
52f5877a | 4943 | |
d6dcfcda | 4944 | ret = send_and_recv_msgs(drv, msg, handler, arg); |
5883168a | 4945 | msg = NULL; |
0915d02c | 4946 | if (ret) { |
a862e4a3 | 4947 | fail: |
5883168a | 4948 | nlmsg_free(msg); |
a35187e7 KH |
4949 | wpa_printf(MSG_ERROR, "Failed to create interface %s: %d (%s)", |
4950 | ifname, ret, strerror(-ret)); | |
0915d02c JM |
4951 | return ret; |
4952 | } | |
4953 | ||
f632e483 | 4954 | if (iftype == NL80211_IFTYPE_P2P_DEVICE) |
6bae92e0 | 4955 | return 0; |
6bae92e0 | 4956 | |
0915d02c | 4957 | ifidx = if_nametoindex(ifname); |
c6e8e8e4 JM |
4958 | wpa_printf(MSG_DEBUG, "nl80211: New interface %s created: ifindex=%d", |
4959 | ifname, ifidx); | |
0915d02c JM |
4960 | |
4961 | if (ifidx <= 0) | |
4962 | return -1; | |
4963 | ||
147848ec JM |
4964 | /* |
4965 | * Some virtual interfaces need to process EAPOL packets and events on | |
4966 | * the parent interface. This is used mainly with hostapd. | |
4967 | */ | |
4968 | if (drv->hostapd || | |
4969 | iftype == NL80211_IFTYPE_AP_VLAN || | |
4970 | iftype == NL80211_IFTYPE_WDS || | |
4971 | iftype == NL80211_IFTYPE_MONITOR) { | |
4972 | /* start listening for EAPOL on this interface */ | |
732b1d20 | 4973 | add_ifidx(drv, ifidx, IFIDX_ANY); |
147848ec | 4974 | } |
2135f224 | 4975 | |
7bfc47c3 | 4976 | if (addr && iftype != NL80211_IFTYPE_MONITOR && |
c81eff1a | 4977 | linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, addr)) { |
41d931ee JM |
4978 | nl80211_remove_iface(drv, ifidx); |
4979 | return -1; | |
2135f224 | 4980 | } |
2135f224 | 4981 | |
0915d02c JM |
4982 | return ifidx; |
4983 | } | |
22a7c9d7 JM |
4984 | |
4985 | ||
f3407c66 JM |
4986 | int nl80211_create_iface(struct wpa_driver_nl80211_data *drv, |
4987 | const char *ifname, enum nl80211_iftype iftype, | |
4988 | const u8 *addr, int wds, | |
4989 | int (*handler)(struct nl_msg *, void *), | |
4990 | void *arg, int use_existing) | |
a35187e7 KH |
4991 | { |
4992 | int ret; | |
4993 | ||
d6dcfcda DS |
4994 | ret = nl80211_create_iface_once(drv, ifname, iftype, addr, wds, handler, |
4995 | arg); | |
a35187e7 | 4996 | |
ffbf1eaa | 4997 | /* if error occurred and interface exists already */ |
a35187e7 | 4998 | if (ret == -ENFILE && if_nametoindex(ifname)) { |
2aec4f3c JM |
4999 | if (use_existing) { |
5000 | wpa_printf(MSG_DEBUG, "nl80211: Continue using existing interface %s", | |
5001 | ifname); | |
6997f8ba JM |
5002 | if (addr && iftype != NL80211_IFTYPE_MONITOR && |
5003 | linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, | |
5004 | addr) < 0 && | |
5005 | (linux_set_iface_flags(drv->global->ioctl_sock, | |
5006 | ifname, 0) < 0 || | |
5007 | linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, | |
5008 | addr) < 0 || | |
5009 | linux_set_iface_flags(drv->global->ioctl_sock, | |
5010 | ifname, 1) < 0)) | |
5011 | return -1; | |
2aec4f3c JM |
5012 | return -ENFILE; |
5013 | } | |
a35187e7 KH |
5014 | wpa_printf(MSG_INFO, "Try to remove and re-create %s", ifname); |
5015 | ||
5016 | /* Try to remove the interface that was already there. */ | |
5017 | nl80211_remove_iface(drv, if_nametoindex(ifname)); | |
5018 | ||
5019 | /* Try to create the interface again */ | |
fbbfcbac | 5020 | ret = nl80211_create_iface_once(drv, ifname, iftype, addr, |
d6dcfcda | 5021 | wds, handler, arg); |
a35187e7 KH |
5022 | } |
5023 | ||
3e208481 JM |
5024 | if (ret >= 0 && is_p2p_net_interface(iftype)) { |
5025 | wpa_printf(MSG_DEBUG, | |
5026 | "nl80211: Interface %s created for P2P - disable 11b rates", | |
5027 | ifname); | |
4e5cb1a3 | 5028 | nl80211_disable_11b_rates(drv, ret, 1); |
3e208481 | 5029 | } |
4e5cb1a3 | 5030 | |
a35187e7 KH |
5031 | return ret; |
5032 | } | |
0915d02c | 5033 | |
2135f224 | 5034 | |
3fd1cefb JB |
5035 | static int nl80211_setup_ap(struct i802_bss *bss) |
5036 | { | |
5037 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
5038 | ||
748c0ac0 JM |
5039 | wpa_printf(MSG_DEBUG, "nl80211: Setup AP(%s) - device_ap_sme=%d use_monitor=%d", |
5040 | bss->ifname, drv->device_ap_sme, drv->use_monitor); | |
36488c05 | 5041 | |
a11241fa JB |
5042 | /* |
5043 | * Disable Probe Request reporting unless we need it in this way for | |
5044 | * devices that include the AP SME, in the other case (unless using | |
5045 | * monitor iface) we'll get it through the nl_mgmt socket instead. | |
5046 | */ | |
5047 | if (!drv->device_ap_sme) | |
5048 | wpa_driver_nl80211_probe_req_report(bss, 0); | |
5049 | ||
5050 | if (!drv->device_ap_sme && !drv->use_monitor) | |
5051 | if (nl80211_mgmt_subscribe_ap(bss)) | |
5052 | return -1; | |
5053 | ||
a6cc0602 JM |
5054 | if (drv->device_ap_sme && !drv->use_monitor) |
5055 | if (nl80211_mgmt_subscribe_ap_dev_sme(bss)) | |
f4830bed RM |
5056 | wpa_printf(MSG_DEBUG, |
5057 | "nl80211: Failed to subscribe for mgmt frames from SME driver - trying to run without it"); | |
a6cc0602 | 5058 | |
a11241fa | 5059 | if (!drv->device_ap_sme && drv->use_monitor && |
ea19b39f RM |
5060 | nl80211_create_monitor_interface(drv) && |
5061 | !drv->device_ap_sme) | |
3fd1cefb JB |
5062 | return -1; |
5063 | ||
5064 | if (drv->device_ap_sme && | |
5065 | wpa_driver_nl80211_probe_req_report(bss, 1) < 0) { | |
5066 | wpa_printf(MSG_DEBUG, "nl80211: Failed to enable " | |
5067 | "Probe Request frame reporting in AP mode"); | |
5068 | /* Try to survive without this */ | |
5069 | } | |
5070 | ||
5071 | return 0; | |
5072 | } | |
5073 | ||
5074 | ||
5075 | static void nl80211_teardown_ap(struct i802_bss *bss) | |
5076 | { | |
5077 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
5078 | ||
748c0ac0 JM |
5079 | wpa_printf(MSG_DEBUG, "nl80211: Teardown AP(%s) - device_ap_sme=%d use_monitor=%d", |
5080 | bss->ifname, drv->device_ap_sme, drv->use_monitor); | |
a6cc0602 | 5081 | if (drv->device_ap_sme) { |
3fd1cefb | 5082 | wpa_driver_nl80211_probe_req_report(bss, 0); |
a6cc0602 JM |
5083 | if (!drv->use_monitor) |
5084 | nl80211_mgmt_unsubscribe(bss, "AP teardown (dev SME)"); | |
5085 | } else if (drv->use_monitor) | |
3fd1cefb | 5086 | nl80211_remove_monitor_interface(drv); |
a11241fa | 5087 | else |
36488c05 | 5088 | nl80211_mgmt_unsubscribe(bss, "AP teardown"); |
a11241fa | 5089 | |
a70cd0db | 5090 | nl80211_put_wiphy_data_ap(bss); |
3fd1cefb JB |
5091 | bss->beacon_set = 0; |
5092 | } | |
5093 | ||
5094 | ||
f10bfc9a JM |
5095 | static int nl80211_send_eapol_data(struct i802_bss *bss, |
5096 | const u8 *addr, const u8 *data, | |
d12dab4c | 5097 | size_t data_len) |
f10bfc9a | 5098 | { |
d12dab4c JB |
5099 | struct sockaddr_ll ll; |
5100 | int ret; | |
5101 | ||
5102 | if (bss->drv->eapol_tx_sock < 0) { | |
5103 | wpa_printf(MSG_DEBUG, "nl80211: No socket to send EAPOL"); | |
f10bfc9a JM |
5104 | return -1; |
5105 | } | |
5106 | ||
d12dab4c JB |
5107 | os_memset(&ll, 0, sizeof(ll)); |
5108 | ll.sll_family = AF_PACKET; | |
5109 | ll.sll_ifindex = bss->ifindex; | |
5110 | ll.sll_protocol = htons(ETH_P_PAE); | |
5111 | ll.sll_halen = ETH_ALEN; | |
5112 | os_memcpy(ll.sll_addr, addr, ETH_ALEN); | |
5113 | ret = sendto(bss->drv->eapol_tx_sock, data, data_len, 0, | |
5114 | (struct sockaddr *) &ll, sizeof(ll)); | |
5115 | if (ret < 0) | |
5116 | wpa_printf(MSG_ERROR, "nl80211: EAPOL TX: %s", | |
5117 | strerror(errno)); | |
5118 | ||
5119 | return ret; | |
f10bfc9a | 5120 | } |
5fb1a232 | 5121 | |
f10bfc9a | 5122 | |
db149ac9 JM |
5123 | static const u8 rfc1042_header[6] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 }; |
5124 | ||
5125 | static int wpa_driver_nl80211_hapd_send_eapol( | |
5126 | void *priv, const u8 *addr, const u8 *data, | |
4378fc14 | 5127 | size_t data_len, int encrypt, const u8 *own_addr, u32 flags) |
db149ac9 | 5128 | { |
a2e40bb6 FF |
5129 | struct i802_bss *bss = priv; |
5130 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
db149ac9 JM |
5131 | struct ieee80211_hdr *hdr; |
5132 | size_t len; | |
5133 | u8 *pos; | |
5134 | int res; | |
4378fc14 | 5135 | int qos = flags & WPA_STA_WMM; |
db149ac9 | 5136 | |
a11241fa | 5137 | if (drv->device_ap_sme || !drv->use_monitor) |
d12dab4c | 5138 | return nl80211_send_eapol_data(bss, addr, data, data_len); |
f10bfc9a | 5139 | |
db149ac9 JM |
5140 | len = sizeof(*hdr) + (qos ? 2 : 0) + sizeof(rfc1042_header) + 2 + |
5141 | data_len; | |
5142 | hdr = os_zalloc(len); | |
5143 | if (hdr == NULL) { | |
7ac3616d JM |
5144 | wpa_printf(MSG_INFO, "nl80211: Failed to allocate EAPOL buffer(len=%lu)", |
5145 | (unsigned long) len); | |
db149ac9 JM |
5146 | return -1; |
5147 | } | |
5148 | ||
5149 | hdr->frame_control = | |
5150 | IEEE80211_FC(WLAN_FC_TYPE_DATA, WLAN_FC_STYPE_DATA); | |
5151 | hdr->frame_control |= host_to_le16(WLAN_FC_FROMDS); | |
5152 | if (encrypt) | |
5153 | hdr->frame_control |= host_to_le16(WLAN_FC_ISWEP); | |
db149ac9 JM |
5154 | if (qos) { |
5155 | hdr->frame_control |= | |
5156 | host_to_le16(WLAN_FC_STYPE_QOS_DATA << 4); | |
5157 | } | |
db149ac9 JM |
5158 | |
5159 | memcpy(hdr->IEEE80211_DA_FROMDS, addr, ETH_ALEN); | |
5160 | memcpy(hdr->IEEE80211_BSSID_FROMDS, own_addr, ETH_ALEN); | |
5161 | memcpy(hdr->IEEE80211_SA_FROMDS, own_addr, ETH_ALEN); | |
5162 | pos = (u8 *) (hdr + 1); | |
5163 | ||
db149ac9 | 5164 | if (qos) { |
92d521d8 FF |
5165 | /* Set highest priority in QoS header */ |
5166 | pos[0] = 7; | |
db149ac9 JM |
5167 | pos[1] = 0; |
5168 | pos += 2; | |
5169 | } | |
db149ac9 JM |
5170 | |
5171 | memcpy(pos, rfc1042_header, sizeof(rfc1042_header)); | |
5172 | pos += sizeof(rfc1042_header); | |
5173 | WPA_PUT_BE16(pos, ETH_P_PAE); | |
5174 | pos += 2; | |
5175 | memcpy(pos, data, data_len); | |
5176 | ||
14cc3d10 | 5177 | res = nl80211_send_monitor(drv, hdr, len, encrypt, 0); |
db149ac9 JM |
5178 | if (res < 0) { |
5179 | wpa_printf(MSG_ERROR, "i802_send_eapol - packet len: %lu - " | |
5180 | "failed: %d (%s)", | |
3ea58a05 | 5181 | (unsigned long) len, res, strerror(res)); |
db149ac9 | 5182 | } |
7bf12757 | 5183 | os_free(hdr); |
db149ac9 JM |
5184 | |
5185 | return res; | |
5186 | } | |
5187 | ||
a8d6ffa4 | 5188 | |
3234cba4 | 5189 | static int wpa_driver_nl80211_sta_set_flags(void *priv, const u8 *addr, |
f97e3ce4 JM |
5190 | unsigned int total_flags, |
5191 | unsigned int flags_or, | |
5192 | unsigned int flags_and) | |
a8d6ffa4 | 5193 | { |
a2e40bb6 | 5194 | struct i802_bss *bss = priv; |
8970bae8 JB |
5195 | struct nl_msg *msg; |
5196 | struct nlattr *flags; | |
7e76ee9c | 5197 | struct nl80211_sta_flag_update upd; |
a8d6ffa4 | 5198 | |
0cd9846c JM |
5199 | wpa_printf(MSG_DEBUG, "nl80211: Set STA flags - ifname=%s addr=" MACSTR |
5200 | " total_flags=0x%x flags_or=0x%x flags_and=0x%x authorized=%d", | |
5201 | bss->ifname, MAC2STR(addr), total_flags, flags_or, flags_and, | |
5202 | !!(total_flags & WPA_STA_AUTHORIZED)); | |
5203 | ||
13f83980 | 5204 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) || |
a862e4a3 JM |
5205 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
5206 | goto fail; | |
a8d6ffa4 | 5207 | |
7e76ee9c JM |
5208 | /* |
5209 | * Backwards compatibility version using NL80211_ATTR_STA_FLAGS. This | |
5210 | * can be removed eventually. | |
5211 | */ | |
8970bae8 | 5212 | flags = nla_nest_start(msg, NL80211_ATTR_STA_FLAGS); |
a862e4a3 JM |
5213 | if (!flags || |
5214 | ((total_flags & WPA_STA_AUTHORIZED) && | |
5215 | nla_put_flag(msg, NL80211_STA_FLAG_AUTHORIZED)) || | |
5216 | ((total_flags & WPA_STA_WMM) && | |
5217 | nla_put_flag(msg, NL80211_STA_FLAG_WME)) || | |
5218 | ((total_flags & WPA_STA_SHORT_PREAMBLE) && | |
5219 | nla_put_flag(msg, NL80211_STA_FLAG_SHORT_PREAMBLE)) || | |
5220 | ((total_flags & WPA_STA_MFP) && | |
5221 | nla_put_flag(msg, NL80211_STA_FLAG_MFP)) || | |
5222 | ((total_flags & WPA_STA_TDLS_PEER) && | |
5223 | nla_put_flag(msg, NL80211_STA_FLAG_TDLS_PEER))) | |
5224 | goto fail; | |
45b722f1 | 5225 | |
8970bae8 | 5226 | nla_nest_end(msg, flags); |
a8d6ffa4 | 5227 | |
7e76ee9c JM |
5228 | os_memset(&upd, 0, sizeof(upd)); |
5229 | upd.mask = sta_flags_nl80211(flags_or | ~flags_and); | |
5230 | upd.set = sta_flags_nl80211(flags_or); | |
a862e4a3 JM |
5231 | if (nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd)) |
5232 | goto fail; | |
7e76ee9c | 5233 | |
13f83980 | 5234 | return send_and_recv_msgs(bss->drv, msg, NULL, NULL); |
a862e4a3 | 5235 | fail: |
5883168a | 5236 | nlmsg_free(msg); |
a8d6ffa4 JM |
5237 | return -ENOBUFS; |
5238 | } | |
5239 | ||
0915d02c | 5240 | |
6720b948 THJ |
5241 | static int driver_nl80211_sta_set_airtime_weight(void *priv, const u8 *addr, |
5242 | unsigned int weight) | |
5243 | { | |
5244 | struct i802_bss *bss = priv; | |
5245 | struct nl_msg *msg; | |
5246 | ||
5247 | wpa_printf(MSG_DEBUG, | |
5248 | "nl80211: Set STA airtime weight - ifname=%s addr=" MACSTR | |
5249 | " weight=%u", bss->ifname, MAC2STR(addr), weight); | |
5250 | ||
5251 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) || | |
5252 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || | |
5253 | nla_put_u16(msg, NL80211_ATTR_AIRTIME_WEIGHT, weight)) | |
5254 | goto fail; | |
5255 | ||
5256 | return send_and_recv_msgs(bss->drv, msg, NULL, NULL); | |
5257 | fail: | |
5258 | nlmsg_free(msg); | |
5259 | return -ENOBUFS; | |
5260 | } | |
5261 | ||
5262 | ||
1581b38b JM |
5263 | static int wpa_driver_nl80211_ap(struct wpa_driver_nl80211_data *drv, |
5264 | struct wpa_driver_associate_params *params) | |
5265 | { | |
708bc8e0 | 5266 | enum nl80211_iftype nlmode, old_mode; |
b1f625e0 EP |
5267 | |
5268 | if (params->p2p) { | |
046b26a2 JM |
5269 | wpa_printf(MSG_DEBUG, "nl80211: Setup AP operations for P2P " |
5270 | "group (GO)"); | |
b1f625e0 EP |
5271 | nlmode = NL80211_IFTYPE_P2P_GO; |
5272 | } else | |
5273 | nlmode = NL80211_IFTYPE_AP; | |
5274 | ||
708bc8e0 | 5275 | old_mode = drv->nlmode; |
834ee56f | 5276 | if (wpa_driver_nl80211_set_mode(drv->first_bss, nlmode)) { |
708bc8e0 JM |
5277 | nl80211_remove_monitor_interface(drv); |
5278 | return -1; | |
5279 | } | |
5280 | ||
6e9023ea JM |
5281 | if (params->freq.freq && |
5282 | nl80211_set_channel(drv->first_bss, ¶ms->freq, 0)) { | |
708bc8e0 | 5283 | if (old_mode != nlmode) |
834ee56f | 5284 | wpa_driver_nl80211_set_mode(drv->first_bss, old_mode); |
460456f8 | 5285 | nl80211_remove_monitor_interface(drv); |
1581b38b | 5286 | return -1; |
0915d02c | 5287 | } |
1581b38b | 5288 | |
1581b38b JM |
5289 | return 0; |
5290 | } | |
1581b38b JM |
5291 | |
5292 | ||
666e508c JM |
5293 | static int nl80211_leave_ibss(struct wpa_driver_nl80211_data *drv, |
5294 | int reset_mode) | |
5cc4d64b JM |
5295 | { |
5296 | struct nl_msg *msg; | |
9725b784 | 5297 | int ret; |
a862e4a3 | 5298 | |
9725b784 | 5299 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_LEAVE_IBSS); |
5cc4d64b | 5300 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
5cc4d64b JM |
5301 | if (ret) { |
5302 | wpa_printf(MSG_DEBUG, "nl80211: Leave IBSS failed: ret=%d " | |
5303 | "(%s)", ret, strerror(-ret)); | |
9725b784 JM |
5304 | } else { |
5305 | wpa_printf(MSG_DEBUG, | |
5306 | "nl80211: Leave IBSS request sent successfully"); | |
5cc4d64b JM |
5307 | } |
5308 | ||
666e508c JM |
5309 | if (reset_mode && |
5310 | wpa_driver_nl80211_set_mode(drv->first_bss, | |
5d4c78fb JM |
5311 | NL80211_IFTYPE_STATION)) { |
5312 | wpa_printf(MSG_INFO, "nl80211: Failed to set interface into " | |
5313 | "station mode"); | |
5314 | } | |
5315 | ||
5cc4d64b JM |
5316 | return ret; |
5317 | } | |
5318 | ||
5319 | ||
95ff3069 JD |
5320 | static int nl80211_ht_vht_overrides(struct nl_msg *msg, |
5321 | struct wpa_driver_associate_params *params) | |
5322 | { | |
5323 | if (params->disable_ht && nla_put_flag(msg, NL80211_ATTR_DISABLE_HT)) | |
5324 | return -1; | |
5325 | ||
5326 | if (params->htcaps && params->htcaps_mask) { | |
5327 | int sz = sizeof(struct ieee80211_ht_capabilities); | |
5328 | wpa_hexdump(MSG_DEBUG, " * htcaps", params->htcaps, sz); | |
5329 | wpa_hexdump(MSG_DEBUG, " * htcaps_mask", | |
5330 | params->htcaps_mask, sz); | |
5331 | if (nla_put(msg, NL80211_ATTR_HT_CAPABILITY, sz, | |
5332 | params->htcaps) || | |
5333 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, sz, | |
5334 | params->htcaps_mask)) | |
5335 | return -1; | |
5336 | } | |
5337 | ||
5338 | #ifdef CONFIG_VHT_OVERRIDES | |
5339 | if (params->disable_vht) { | |
5340 | wpa_printf(MSG_DEBUG, " * VHT disabled"); | |
5341 | if (nla_put_flag(msg, NL80211_ATTR_DISABLE_VHT)) | |
5342 | return -1; | |
5343 | } | |
5344 | ||
5345 | if (params->vhtcaps && params->vhtcaps_mask) { | |
5346 | int sz = sizeof(struct ieee80211_vht_capabilities); | |
5347 | wpa_hexdump(MSG_DEBUG, " * vhtcaps", params->vhtcaps, sz); | |
5348 | wpa_hexdump(MSG_DEBUG, " * vhtcaps_mask", | |
5349 | params->vhtcaps_mask, sz); | |
5350 | if (nla_put(msg, NL80211_ATTR_VHT_CAPABILITY, sz, | |
5351 | params->vhtcaps) || | |
5352 | nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, sz, | |
5353 | params->vhtcaps_mask)) | |
5354 | return -1; | |
5355 | } | |
5356 | #endif /* CONFIG_VHT_OVERRIDES */ | |
5357 | ||
5358 | return 0; | |
5359 | } | |
5360 | ||
5361 | ||
5cc4d64b JM |
5362 | static int wpa_driver_nl80211_ibss(struct wpa_driver_nl80211_data *drv, |
5363 | struct wpa_driver_associate_params *params) | |
5364 | { | |
5365 | struct nl_msg *msg; | |
5366 | int ret = -1; | |
5367 | int count = 0; | |
5368 | ||
5369 | wpa_printf(MSG_DEBUG, "nl80211: Join IBSS (ifindex=%d)", drv->ifindex); | |
5370 | ||
4ec68377 | 5371 | if (wpa_driver_nl80211_set_mode_ibss(drv->first_bss, ¶ms->freq)) { |
5cc4d64b JM |
5372 | wpa_printf(MSG_INFO, "nl80211: Failed to set interface into " |
5373 | "IBSS mode"); | |
5374 | return -1; | |
5375 | } | |
5376 | ||
5377 | retry: | |
9725b784 | 5378 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_JOIN_IBSS)) || |
a862e4a3 JM |
5379 | params->ssid == NULL || params->ssid_len > sizeof(drv->ssid)) |
5380 | goto fail; | |
5cc4d64b | 5381 | |
21cd8f83 JM |
5382 | wpa_printf(MSG_DEBUG, " * SSID=%s", |
5383 | wpa_ssid_txt(params->ssid, params->ssid_len)); | |
a862e4a3 JM |
5384 | if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid)) |
5385 | goto fail; | |
5cc4d64b JM |
5386 | os_memcpy(drv->ssid, params->ssid, params->ssid_len); |
5387 | drv->ssid_len = params->ssid_len; | |
5388 | ||
85e1fad8 JM |
5389 | if (nl80211_put_freq_params(msg, ¶ms->freq) < 0 || |
5390 | nl80211_put_beacon_int(msg, params->beacon_int)) | |
a862e4a3 | 5391 | goto fail; |
5cc4d64b JM |
5392 | |
5393 | ret = nl80211_set_conn_keys(params, msg); | |
5394 | if (ret) | |
a862e4a3 | 5395 | goto fail; |
5cc4d64b | 5396 | |
913e3cf7 NC |
5397 | if (params->bssid && params->fixed_bssid) { |
5398 | wpa_printf(MSG_DEBUG, " * BSSID=" MACSTR, | |
5399 | MAC2STR(params->bssid)); | |
a862e4a3 JM |
5400 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid)) |
5401 | goto fail; | |
913e3cf7 NC |
5402 | } |
5403 | ||
4d9e6fba JD |
5404 | if (params->fixed_freq) { |
5405 | wpa_printf(MSG_DEBUG, " * fixed_freq"); | |
5406 | if (nla_put_flag(msg, NL80211_ATTR_FREQ_FIXED)) | |
5407 | goto fail; | |
5408 | } | |
5409 | ||
4848a38d JM |
5410 | if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X || |
5411 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK || | |
5412 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SHA256 || | |
5413 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256) { | |
e640888c | 5414 | wpa_printf(MSG_DEBUG, " * control port"); |
a862e4a3 JM |
5415 | if (nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT)) |
5416 | goto fail; | |
e640888c AQ |
5417 | } |
5418 | ||
a95795ad JM |
5419 | if (params->wpa_ie) { |
5420 | wpa_hexdump(MSG_DEBUG, | |
5421 | " * Extra IEs for Beacon/Probe Response frames", | |
5422 | params->wpa_ie, params->wpa_ie_len); | |
a862e4a3 JM |
5423 | if (nla_put(msg, NL80211_ATTR_IE, params->wpa_ie_len, |
5424 | params->wpa_ie)) | |
5425 | goto fail; | |
a95795ad JM |
5426 | } |
5427 | ||
e15dcf6d PK |
5428 | ret = nl80211_ht_vht_overrides(msg, params); |
5429 | if (ret < 0) | |
5430 | goto fail; | |
95ff3069 | 5431 | |
5cc4d64b JM |
5432 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
5433 | msg = NULL; | |
5434 | if (ret) { | |
5435 | wpa_printf(MSG_DEBUG, "nl80211: Join IBSS failed: ret=%d (%s)", | |
5436 | ret, strerror(-ret)); | |
5437 | count++; | |
5438 | if (ret == -EALREADY && count == 1) { | |
5439 | wpa_printf(MSG_DEBUG, "nl80211: Retry IBSS join after " | |
5440 | "forced leave"); | |
666e508c | 5441 | nl80211_leave_ibss(drv, 0); |
5cc4d64b JM |
5442 | nlmsg_free(msg); |
5443 | goto retry; | |
5444 | } | |
a862e4a3 JM |
5445 | } else { |
5446 | wpa_printf(MSG_DEBUG, | |
5447 | "nl80211: Join IBSS request sent successfully"); | |
5cc4d64b | 5448 | } |
5cc4d64b | 5449 | |
a862e4a3 | 5450 | fail: |
5cc4d64b JM |
5451 | nlmsg_free(msg); |
5452 | return ret; | |
5453 | } | |
5454 | ||
5455 | ||
ad295f3b VK |
5456 | static int nl80211_put_fils_connect_params(struct wpa_driver_nl80211_data *drv, |
5457 | struct wpa_driver_associate_params *params, | |
5458 | struct nl_msg *msg) | |
5459 | { | |
5460 | if (params->fils_erp_username_len) { | |
5461 | wpa_hexdump_ascii(MSG_DEBUG, " * FILS ERP EMSKname/username", | |
5462 | params->fils_erp_username, | |
5463 | params->fils_erp_username_len); | |
5464 | if (nla_put(msg, NL80211_ATTR_FILS_ERP_USERNAME, | |
5465 | params->fils_erp_username_len, | |
5466 | params->fils_erp_username)) | |
5467 | return -1; | |
5468 | } | |
5469 | ||
5470 | if (params->fils_erp_realm_len) { | |
5471 | wpa_hexdump_ascii(MSG_DEBUG, " * FILS ERP Realm", | |
5472 | params->fils_erp_realm, | |
5473 | params->fils_erp_realm_len); | |
5474 | if (nla_put(msg, NL80211_ATTR_FILS_ERP_REALM, | |
5475 | params->fils_erp_realm_len, params->fils_erp_realm)) | |
5476 | return -1; | |
5477 | } | |
5478 | ||
5479 | wpa_printf(MSG_DEBUG, " * FILS ERP next seq %u", | |
5480 | params->fils_erp_next_seq_num); | |
5481 | if (nla_put_u16(msg, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM, | |
5482 | params->fils_erp_next_seq_num)) | |
5483 | return -1; | |
5484 | ||
5485 | if (params->fils_erp_rrk_len) { | |
5486 | wpa_printf(MSG_DEBUG, " * FILS ERP rRK (len=%lu)", | |
5487 | (unsigned long) params->fils_erp_rrk_len); | |
5488 | if (nla_put(msg, NL80211_ATTR_FILS_ERP_RRK, | |
5489 | params->fils_erp_rrk_len, params->fils_erp_rrk)) | |
5490 | return -1; | |
5491 | } | |
5492 | ||
5493 | return 0; | |
5494 | } | |
5495 | ||
5496 | ||
a0bdd191 JM |
5497 | static int nl80211_connect_common(struct wpa_driver_nl80211_data *drv, |
5498 | struct wpa_driver_associate_params *params, | |
5499 | struct nl_msg *msg) | |
cfaab580 | 5500 | { |
c85dfc6f JM |
5501 | if (nla_put_flag(msg, NL80211_ATTR_IFACE_SOCKET_OWNER)) |
5502 | return -1; | |
5503 | ||
cfaab580 ZY |
5504 | if (params->bssid) { |
5505 | wpa_printf(MSG_DEBUG, " * bssid=" MACSTR, | |
5506 | MAC2STR(params->bssid)); | |
a862e4a3 JM |
5507 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid)) |
5508 | return -1; | |
cfaab580 | 5509 | } |
a0bdd191 | 5510 | |
7ac7fd43 DS |
5511 | if (params->bssid_hint) { |
5512 | wpa_printf(MSG_DEBUG, " * bssid_hint=" MACSTR, | |
5513 | MAC2STR(params->bssid_hint)); | |
a862e4a3 JM |
5514 | if (nla_put(msg, NL80211_ATTR_MAC_HINT, ETH_ALEN, |
5515 | params->bssid_hint)) | |
5516 | return -1; | |
7ac7fd43 DS |
5517 | } |
5518 | ||
4ec68377 JD |
5519 | if (params->freq.freq) { |
5520 | wpa_printf(MSG_DEBUG, " * freq=%d", params->freq.freq); | |
a862e4a3 JM |
5521 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
5522 | params->freq.freq)) | |
5523 | return -1; | |
4ec68377 | 5524 | drv->assoc_freq = params->freq.freq; |
30158a0d SD |
5525 | } else |
5526 | drv->assoc_freq = 0; | |
a0bdd191 | 5527 | |
7ac7fd43 DS |
5528 | if (params->freq_hint) { |
5529 | wpa_printf(MSG_DEBUG, " * freq_hint=%d", params->freq_hint); | |
a862e4a3 JM |
5530 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ_HINT, |
5531 | params->freq_hint)) | |
5532 | return -1; | |
7ac7fd43 DS |
5533 | } |
5534 | ||
dda5d9e3 AAL |
5535 | if (params->freq.edmg.channels && params->freq.edmg.bw_config) { |
5536 | wpa_printf(MSG_DEBUG, | |
5537 | " * EDMG configuration: channels=0x%x bw_config=%d", | |
5538 | params->freq.edmg.channels, | |
5539 | params->freq.edmg.bw_config); | |
5540 | if (nla_put_u8(msg, NL80211_ATTR_WIPHY_EDMG_CHANNELS, | |
5541 | params->freq.edmg.channels) || | |
5542 | nla_put_u8(msg, NL80211_ATTR_WIPHY_EDMG_BW_CONFIG, | |
5543 | params->freq.edmg.bw_config)) | |
5544 | return -1; | |
5545 | } | |
5546 | ||
1f6c0ab8 BS |
5547 | if (params->bg_scan_period >= 0) { |
5548 | wpa_printf(MSG_DEBUG, " * bg scan period=%d", | |
5549 | params->bg_scan_period); | |
a862e4a3 JM |
5550 | if (nla_put_u16(msg, NL80211_ATTR_BG_SCAN_PERIOD, |
5551 | params->bg_scan_period)) | |
5552 | return -1; | |
1f6c0ab8 | 5553 | } |
a0bdd191 | 5554 | |
cfaab580 | 5555 | if (params->ssid) { |
21cd8f83 JM |
5556 | wpa_printf(MSG_DEBUG, " * SSID=%s", |
5557 | wpa_ssid_txt(params->ssid, params->ssid_len)); | |
a862e4a3 JM |
5558 | if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, |
5559 | params->ssid)) | |
5560 | return -1; | |
cfaab580 | 5561 | if (params->ssid_len > sizeof(drv->ssid)) |
a862e4a3 | 5562 | return -1; |
cfaab580 ZY |
5563 | os_memcpy(drv->ssid, params->ssid, params->ssid_len); |
5564 | drv->ssid_len = params->ssid_len; | |
5565 | } | |
a0bdd191 | 5566 | |
cfaab580 | 5567 | wpa_hexdump(MSG_DEBUG, " * IEs", params->wpa_ie, params->wpa_ie_len); |
a862e4a3 JM |
5568 | if (params->wpa_ie && |
5569 | nla_put(msg, NL80211_ATTR_IE, params->wpa_ie_len, params->wpa_ie)) | |
5570 | return -1; | |
cfaab580 | 5571 | |
64fa840a JM |
5572 | if (params->wpa_proto) { |
5573 | enum nl80211_wpa_versions ver = 0; | |
cfaab580 | 5574 | |
64fa840a JM |
5575 | if (params->wpa_proto & WPA_PROTO_WPA) |
5576 | ver |= NL80211_WPA_VERSION_1; | |
5577 | if (params->wpa_proto & WPA_PROTO_RSN) | |
5578 | ver |= NL80211_WPA_VERSION_2; | |
cfaab580 | 5579 | |
64fa840a | 5580 | wpa_printf(MSG_DEBUG, " * WPA Versions 0x%x", ver); |
a862e4a3 JM |
5581 | if (nla_put_u32(msg, NL80211_ATTR_WPA_VERSIONS, ver)) |
5582 | return -1; | |
cfaab580 ZY |
5583 | } |
5584 | ||
4848a38d | 5585 | if (params->pairwise_suite != WPA_CIPHER_NONE) { |
a0bdd191 JM |
5586 | u32 cipher = wpa_cipher_to_cipher_suite(params->pairwise_suite); |
5587 | wpa_printf(MSG_DEBUG, " * pairwise=0x%x", cipher); | |
a862e4a3 JM |
5588 | if (nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITES_PAIRWISE, |
5589 | cipher)) | |
5590 | return -1; | |
cfaab580 ZY |
5591 | } |
5592 | ||
ae6f9272 JM |
5593 | if (params->group_suite == WPA_CIPHER_GTK_NOT_USED && |
5594 | !(drv->capa.enc & WPA_DRIVER_CAPA_ENC_GTK_NOT_USED)) { | |
5595 | /* | |
5596 | * This is likely to work even though many drivers do not | |
5597 | * advertise support for operations without GTK. | |
5598 | */ | |
5599 | wpa_printf(MSG_DEBUG, " * skip group cipher configuration for GTK_NOT_USED due to missing driver support advertisement"); | |
5600 | } else if (params->group_suite != WPA_CIPHER_NONE) { | |
a0bdd191 JM |
5601 | u32 cipher = wpa_cipher_to_cipher_suite(params->group_suite); |
5602 | wpa_printf(MSG_DEBUG, " * group=0x%x", cipher); | |
a862e4a3 JM |
5603 | if (nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, cipher)) |
5604 | return -1; | |
cfaab580 ZY |
5605 | } |
5606 | ||
4848a38d JM |
5607 | if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X || |
5608 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK || | |
5609 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_IEEE8021X || | |
5610 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_PSK || | |
163f801e | 5611 | params->key_mgmt_suite == WPA_KEY_MGMT_CCKM || |
8802326f JJ |
5612 | params->key_mgmt_suite == WPA_KEY_MGMT_OSEN || |
5613 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SHA256 || | |
666497c8 | 5614 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256 || |
005585d6 AB |
5615 | params->key_mgmt_suite == WPA_KEY_MGMT_SAE || |
5616 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_SAE || | |
5e3b5197 | 5617 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SUITE_B || |
ad295f3b | 5618 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SUITE_B_192 || |
005585d6 | 5619 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_IEEE8021X_SHA384 || |
ad295f3b VK |
5620 | params->key_mgmt_suite == WPA_KEY_MGMT_FILS_SHA256 || |
5621 | params->key_mgmt_suite == WPA_KEY_MGMT_FILS_SHA384 || | |
5622 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_FILS_SHA256 || | |
e005725a SD |
5623 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_FILS_SHA384 || |
5624 | params->key_mgmt_suite == WPA_KEY_MGMT_OWE || | |
5625 | params->key_mgmt_suite == WPA_KEY_MGMT_DPP) { | |
3aa24db9 | 5626 | int mgmt = RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X; |
cfaab580 ZY |
5627 | |
5628 | switch (params->key_mgmt_suite) { | |
4848a38d | 5629 | case WPA_KEY_MGMT_CCKM: |
3aa24db9 | 5630 | mgmt = RSN_AUTH_KEY_MGMT_CCKM; |
369c8d7b | 5631 | break; |
4848a38d | 5632 | case WPA_KEY_MGMT_IEEE8021X: |
3aa24db9 | 5633 | mgmt = RSN_AUTH_KEY_MGMT_UNSPEC_802_1X; |
cfaab580 | 5634 | break; |
4848a38d | 5635 | case WPA_KEY_MGMT_FT_IEEE8021X: |
3aa24db9 | 5636 | mgmt = RSN_AUTH_KEY_MGMT_FT_802_1X; |
6a1ce395 | 5637 | break; |
4848a38d | 5638 | case WPA_KEY_MGMT_FT_PSK: |
3aa24db9 | 5639 | mgmt = RSN_AUTH_KEY_MGMT_FT_PSK; |
6a1ce395 | 5640 | break; |
8802326f | 5641 | case WPA_KEY_MGMT_IEEE8021X_SHA256: |
3aa24db9 | 5642 | mgmt = RSN_AUTH_KEY_MGMT_802_1X_SHA256; |
8802326f JJ |
5643 | break; |
5644 | case WPA_KEY_MGMT_PSK_SHA256: | |
3aa24db9 | 5645 | mgmt = RSN_AUTH_KEY_MGMT_PSK_SHA256; |
8802326f | 5646 | break; |
163f801e | 5647 | case WPA_KEY_MGMT_OSEN: |
3aa24db9 | 5648 | mgmt = RSN_AUTH_KEY_MGMT_OSEN; |
163f801e | 5649 | break; |
005585d6 AB |
5650 | case WPA_KEY_MGMT_SAE: |
5651 | mgmt = RSN_AUTH_KEY_MGMT_SAE; | |
5652 | break; | |
5653 | case WPA_KEY_MGMT_FT_SAE: | |
5654 | mgmt = RSN_AUTH_KEY_MGMT_FT_SAE; | |
5655 | break; | |
666497c8 | 5656 | case WPA_KEY_MGMT_IEEE8021X_SUITE_B: |
3aa24db9 | 5657 | mgmt = RSN_AUTH_KEY_MGMT_802_1X_SUITE_B; |
666497c8 | 5658 | break; |
5e3b5197 | 5659 | case WPA_KEY_MGMT_IEEE8021X_SUITE_B_192: |
3aa24db9 | 5660 | mgmt = RSN_AUTH_KEY_MGMT_802_1X_SUITE_B_192; |
5e3b5197 | 5661 | break; |
005585d6 AB |
5662 | case WPA_KEY_MGMT_FT_IEEE8021X_SHA384: |
5663 | mgmt = RSN_AUTH_KEY_MGMT_FT_802_1X_SHA384; | |
5664 | break; | |
ad295f3b VK |
5665 | case WPA_KEY_MGMT_FILS_SHA256: |
5666 | mgmt = RSN_AUTH_KEY_MGMT_FILS_SHA256; | |
5667 | break; | |
5668 | case WPA_KEY_MGMT_FILS_SHA384: | |
5669 | mgmt = RSN_AUTH_KEY_MGMT_FILS_SHA384; | |
5670 | break; | |
5671 | case WPA_KEY_MGMT_FT_FILS_SHA256: | |
5672 | mgmt = RSN_AUTH_KEY_MGMT_FT_FILS_SHA256; | |
5673 | break; | |
5674 | case WPA_KEY_MGMT_FT_FILS_SHA384: | |
5675 | mgmt = RSN_AUTH_KEY_MGMT_FT_FILS_SHA384; | |
5676 | break; | |
e005725a SD |
5677 | case WPA_KEY_MGMT_OWE: |
5678 | mgmt = RSN_AUTH_KEY_MGMT_OWE; | |
5679 | break; | |
5680 | case WPA_KEY_MGMT_DPP: | |
5681 | mgmt = RSN_AUTH_KEY_MGMT_DPP; | |
5682 | break; | |
4848a38d | 5683 | case WPA_KEY_MGMT_PSK: |
cfaab580 | 5684 | default: |
3aa24db9 | 5685 | mgmt = RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X; |
cfaab580 ZY |
5686 | break; |
5687 | } | |
163f801e | 5688 | wpa_printf(MSG_DEBUG, " * akm=0x%x", mgmt); |
a862e4a3 JM |
5689 | if (nla_put_u32(msg, NL80211_ATTR_AKM_SUITES, mgmt)) |
5690 | return -1; | |
cfaab580 ZY |
5691 | } |
5692 | ||
cb28bd52 | 5693 | if (params->req_handshake_offload && |
d896874f AS |
5694 | (drv->capa.flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_8021X)) { |
5695 | wpa_printf(MSG_DEBUG, " * WANT_1X_4WAY_HS"); | |
5696 | if (nla_put_flag(msg, NL80211_ATTR_WANT_1X_4WAY_HS)) | |
5697 | return -1; | |
5698 | } | |
5699 | ||
730c5a1d EP |
5700 | /* Add PSK in case of 4-way handshake offload */ |
5701 | if (params->psk && | |
436ee2fd | 5702 | (drv->capa.flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK)) { |
730c5a1d EP |
5703 | wpa_hexdump_key(MSG_DEBUG, " * PSK", params->psk, 32); |
5704 | if (nla_put(msg, NL80211_ATTR_PMK, 32, params->psk)) | |
5705 | return -1; | |
5706 | } | |
5707 | ||
a862e4a3 JM |
5708 | if (nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT)) |
5709 | return -1; | |
a0bdd191 | 5710 | |
e3429c0b JB |
5711 | if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_NO_WPA && |
5712 | (params->pairwise_suite == WPA_CIPHER_NONE || | |
5713 | params->pairwise_suite == WPA_CIPHER_WEP104 || | |
5714 | params->pairwise_suite == WPA_CIPHER_WEP40) && | |
5715 | (nla_put_u16(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE, ETH_P_PAE) || | |
5716 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT))) | |
5717 | return -1; | |
5718 | ||
58162adf AK |
5719 | if (params->rrm_used) { |
5720 | u32 drv_rrm_flags = drv->capa.rrm_flags; | |
b5d172e5 BL |
5721 | if ((!((drv_rrm_flags & |
5722 | WPA_DRIVER_FLAGS_DS_PARAM_SET_IE_IN_PROBES) && | |
5723 | (drv_rrm_flags & WPA_DRIVER_FLAGS_QUIET)) && | |
5724 | !(drv_rrm_flags & WPA_DRIVER_FLAGS_SUPPORT_RRM)) || | |
a862e4a3 JM |
5725 | nla_put_flag(msg, NL80211_ATTR_USE_RRM)) |
5726 | return -1; | |
58162adf AK |
5727 | } |
5728 | ||
95ff3069 | 5729 | if (nl80211_ht_vht_overrides(msg, params) < 0) |
a862e4a3 | 5730 | return -1; |
80e8a5ee | 5731 | |
a0bdd191 JM |
5732 | if (params->p2p) |
5733 | wpa_printf(MSG_DEBUG, " * P2P group"); | |
5734 | ||
86b5c400 LD |
5735 | if (params->pbss) { |
5736 | wpa_printf(MSG_DEBUG, " * PBSS"); | |
5737 | if (nla_put_flag(msg, NL80211_ATTR_PBSS)) | |
5738 | return -1; | |
5739 | } | |
5740 | ||
1126c078 | 5741 | drv->connect_reassoc = 0; |
00c3c4ac JM |
5742 | if (params->prev_bssid) { |
5743 | wpa_printf(MSG_DEBUG, " * prev_bssid=" MACSTR, | |
5744 | MAC2STR(params->prev_bssid)); | |
5745 | if (nla_put(msg, NL80211_ATTR_PREV_BSSID, ETH_ALEN, | |
5746 | params->prev_bssid)) | |
5747 | return -1; | |
1126c078 | 5748 | drv->connect_reassoc = 1; |
00c3c4ac JM |
5749 | } |
5750 | ||
ad295f3b VK |
5751 | if ((params->auth_alg & WPA_AUTH_ALG_FILS) && |
5752 | nl80211_put_fils_connect_params(drv, params, msg) != 0) | |
5753 | return -1; | |
5754 | ||
1317ea2c SD |
5755 | if ((params->key_mgmt_suite == WPA_KEY_MGMT_SAE || |
5756 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_SAE) && | |
ba71cb82 SD |
5757 | (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) && |
5758 | nla_put_flag(msg, NL80211_ATTR_EXTERNAL_AUTH_SUPPORT)) | |
5759 | return -1; | |
5760 | ||
a0bdd191 | 5761 | return 0; |
a0bdd191 JM |
5762 | } |
5763 | ||
5764 | ||
5765 | static int wpa_driver_nl80211_try_connect( | |
5766 | struct wpa_driver_nl80211_data *drv, | |
40a68f33 | 5767 | struct wpa_driver_associate_params *params, |
25ebd538 | 5768 | struct nl_sock *nl_connect) |
a0bdd191 JM |
5769 | { |
5770 | struct nl_msg *msg; | |
5771 | enum nl80211_auth_type type; | |
5772 | int ret; | |
5773 | int algs; | |
5774 | ||
b658547d | 5775 | #ifdef CONFIG_DRIVER_NL80211_QCA |
b41f2684 CL |
5776 | if (params->req_key_mgmt_offload && params->psk && |
5777 | (params->key_mgmt_suite == WPA_KEY_MGMT_PSK || | |
5778 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256 || | |
5779 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_PSK)) { | |
5780 | wpa_printf(MSG_DEBUG, "nl80211: Key management set PSK"); | |
5781 | ret = issue_key_mgmt_set_key(drv, params->psk, 32); | |
5782 | if (ret) | |
5783 | return ret; | |
5784 | } | |
b658547d | 5785 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
b41f2684 | 5786 | |
9725b784 JM |
5787 | wpa_printf(MSG_DEBUG, "nl80211: Connect (ifindex=%d)", drv->ifindex); |
5788 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_CONNECT); | |
a0bdd191 JM |
5789 | if (!msg) |
5790 | return -1; | |
5791 | ||
a0bdd191 JM |
5792 | ret = nl80211_connect_common(drv, params, msg); |
5793 | if (ret) | |
a862e4a3 | 5794 | goto fail; |
a0bdd191 | 5795 | |
299d21e8 EG |
5796 | if (params->mgmt_frame_protection == MGMT_FRAME_PROTECTION_REQUIRED && |
5797 | nla_put_u32(msg, NL80211_ATTR_USE_MFP, NL80211_MFP_REQUIRED)) | |
5798 | goto fail; | |
5799 | ||
5800 | if (params->mgmt_frame_protection == MGMT_FRAME_PROTECTION_OPTIONAL && | |
5801 | (drv->capa.flags & WPA_DRIVER_FLAGS_MFP_OPTIONAL) && | |
5802 | nla_put_u32(msg, NL80211_ATTR_USE_MFP, NL80211_MFP_OPTIONAL)) | |
5803 | goto fail; | |
5804 | ||
a0bdd191 JM |
5805 | algs = 0; |
5806 | if (params->auth_alg & WPA_AUTH_ALG_OPEN) | |
5807 | algs++; | |
5808 | if (params->auth_alg & WPA_AUTH_ALG_SHARED) | |
5809 | algs++; | |
5810 | if (params->auth_alg & WPA_AUTH_ALG_LEAP) | |
5811 | algs++; | |
64a0a75b JM |
5812 | if (params->auth_alg & WPA_AUTH_ALG_FILS) |
5813 | algs++; | |
86c998d3 AM |
5814 | if (params->auth_alg & WPA_AUTH_ALG_FT) |
5815 | algs++; | |
a0bdd191 JM |
5816 | if (algs > 1) { |
5817 | wpa_printf(MSG_DEBUG, " * Leave out Auth Type for automatic " | |
5818 | "selection"); | |
5819 | goto skip_auth_type; | |
5820 | } | |
5821 | ||
3c67e977 | 5822 | type = get_nl_auth_type(params->auth_alg); |
a0bdd191 | 5823 | wpa_printf(MSG_DEBUG, " * Auth Type %d", type); |
3c67e977 VK |
5824 | if (type == NL80211_AUTHTYPE_MAX || |
5825 | nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, type)) | |
a862e4a3 | 5826 | goto fail; |
a0bdd191 JM |
5827 | |
5828 | skip_auth_type: | |
cfaab580 ZY |
5829 | ret = nl80211_set_conn_keys(params, msg); |
5830 | if (ret) | |
a862e4a3 | 5831 | goto fail; |
cfaab580 | 5832 | |
40a68f33 | 5833 | if (nl_connect) |
0fa33e05 JM |
5834 | ret = send_and_recv(drv->global, nl_connect, msg, |
5835 | NULL, (void *) -1); | |
40a68f33 | 5836 | else |
0fa33e05 | 5837 | ret = send_and_recv_msgs(drv, msg, NULL, (void *) -1); |
40a68f33 | 5838 | |
cfaab580 ZY |
5839 | msg = NULL; |
5840 | if (ret) { | |
5841 | wpa_printf(MSG_DEBUG, "nl80211: MLME connect failed: ret=%d " | |
5842 | "(%s)", ret, strerror(-ret)); | |
a862e4a3 JM |
5843 | } else { |
5844 | wpa_printf(MSG_DEBUG, | |
5845 | "nl80211: Connect request send successfully"); | |
cfaab580 | 5846 | } |
cfaab580 | 5847 | |
a862e4a3 | 5848 | fail: |
0fa33e05 | 5849 | nl80211_nlmsg_clear(msg); |
cfaab580 ZY |
5850 | nlmsg_free(msg); |
5851 | return ret; | |
5852 | ||
5853 | } | |
5854 | ||
5855 | ||
a8c5b43a CW |
5856 | static int wpa_driver_nl80211_connect( |
5857 | struct wpa_driver_nl80211_data *drv, | |
40a68f33 | 5858 | struct wpa_driver_associate_params *params, |
25ebd538 | 5859 | struct nl_sock *nl_connect) |
a8c5b43a | 5860 | { |
0d4e3d1d JJ |
5861 | int ret; |
5862 | ||
5863 | /* Store the connection attempted bssid for future use */ | |
5864 | if (params->bssid) | |
5865 | os_memcpy(drv->auth_attempt_bssid, params->bssid, ETH_ALEN); | |
5866 | else | |
5867 | os_memset(drv->auth_attempt_bssid, 0, ETH_ALEN); | |
5868 | ||
40a68f33 | 5869 | ret = wpa_driver_nl80211_try_connect(drv, params, nl_connect); |
a8c5b43a CW |
5870 | if (ret == -EALREADY) { |
5871 | /* | |
5872 | * cfg80211 does not currently accept new connections if | |
5873 | * we are already connected. As a workaround, force | |
5874 | * disconnection and try again. | |
5875 | */ | |
5876 | wpa_printf(MSG_DEBUG, "nl80211: Explicitly " | |
5877 | "disconnecting before reassociation " | |
5878 | "attempt"); | |
5879 | if (wpa_driver_nl80211_disconnect( | |
10d32e2c | 5880 | drv, WLAN_REASON_PREV_AUTH_NOT_VALID, nl_connect)) |
a8c5b43a | 5881 | return -1; |
40a68f33 | 5882 | ret = wpa_driver_nl80211_try_connect(drv, params, nl_connect); |
a8c5b43a CW |
5883 | } |
5884 | return ret; | |
5885 | } | |
5886 | ||
5887 | ||
c2a04078 JM |
5888 | static int wpa_driver_nl80211_associate( |
5889 | void *priv, struct wpa_driver_associate_params *params) | |
5890 | { | |
a2e40bb6 FF |
5891 | struct i802_bss *bss = priv; |
5892 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
a862e4a3 | 5893 | int ret = -1; |
c2a04078 JM |
5894 | struct nl_msg *msg; |
5895 | ||
4bd71954 JM |
5896 | nl80211_unmask_11b_rates(bss); |
5897 | ||
5cc4d64b | 5898 | if (params->mode == IEEE80211_MODE_AP) |
1581b38b | 5899 | return wpa_driver_nl80211_ap(drv, params); |
1581b38b | 5900 | |
5cc4d64b JM |
5901 | if (params->mode == IEEE80211_MODE_IBSS) |
5902 | return wpa_driver_nl80211_ibss(drv, params); | |
5903 | ||
4a867032 | 5904 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) { |
b1f625e0 EP |
5905 | enum nl80211_iftype nlmode = params->p2p ? |
5906 | NL80211_IFTYPE_P2P_CLIENT : NL80211_IFTYPE_STATION; | |
25ebd538 | 5907 | struct nl_sock *nl_connect = NULL; |
b1f625e0 EP |
5908 | |
5909 | if (wpa_driver_nl80211_set_mode(priv, nlmode) < 0) | |
4a867032 | 5910 | return -1; |
1317ea2c SD |
5911 | if (params->key_mgmt_suite == WPA_KEY_MGMT_SAE || |
5912 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_SAE) { | |
40a68f33 | 5913 | nl_connect = bss->nl_connect; |
10d32e2c CI |
5914 | bss->use_nl_connect = 1; |
5915 | } else { | |
5916 | bss->use_nl_connect = 0; | |
5917 | } | |
5918 | ||
40a68f33 | 5919 | return wpa_driver_nl80211_connect(drv, params, nl_connect); |
4a867032 | 5920 | } |
cfaab580 | 5921 | |
add9b7a4 | 5922 | nl80211_mark_disconnected(drv); |
c2a04078 | 5923 | |
c2a04078 JM |
5924 | wpa_printf(MSG_DEBUG, "nl80211: Associate (ifindex=%d)", |
5925 | drv->ifindex); | |
9725b784 JM |
5926 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_ASSOCIATE); |
5927 | if (!msg) | |
5928 | return -1; | |
c2a04078 | 5929 | |
a0bdd191 JM |
5930 | ret = nl80211_connect_common(drv, params, msg); |
5931 | if (ret) | |
a862e4a3 | 5932 | goto fail; |
01652550 | 5933 | |
299d21e8 EG |
5934 | if (params->mgmt_frame_protection == MGMT_FRAME_PROTECTION_REQUIRED && |
5935 | nla_put_u32(msg, NL80211_ATTR_USE_MFP, NL80211_MFP_REQUIRED)) | |
5936 | goto fail; | |
5937 | ||
40a45727 JM |
5938 | if (params->fils_kek) { |
5939 | wpa_printf(MSG_DEBUG, " * FILS KEK (len=%u)", | |
5940 | (unsigned int) params->fils_kek_len); | |
5941 | if (nla_put(msg, NL80211_ATTR_FILS_KEK, params->fils_kek_len, | |
5942 | params->fils_kek)) | |
5943 | goto fail; | |
5944 | } | |
5945 | if (params->fils_nonces) { | |
5946 | wpa_hexdump(MSG_DEBUG, " * FILS nonces (for AAD)", | |
5947 | params->fils_nonces, | |
5948 | params->fils_nonces_len); | |
5949 | if (nla_put(msg, NL80211_ATTR_FILS_NONCES, | |
5950 | params->fils_nonces_len, params->fils_nonces)) | |
5951 | goto fail; | |
5952 | } | |
5953 | ||
c2a04078 JM |
5954 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
5955 | msg = NULL; | |
5956 | if (ret) { | |
3b7ea880 BG |
5957 | wpa_dbg(drv->ctx, MSG_DEBUG, |
5958 | "nl80211: MLME command failed (assoc): ret=%d (%s)", | |
5959 | ret, strerror(-ret)); | |
8856462d | 5960 | nl80211_dump_scan(drv); |
a862e4a3 JM |
5961 | } else { |
5962 | wpa_printf(MSG_DEBUG, | |
5963 | "nl80211: Association request send successfully"); | |
c2a04078 | 5964 | } |
c2a04078 | 5965 | |
a862e4a3 | 5966 | fail: |
c2a04078 JM |
5967 | nlmsg_free(msg); |
5968 | return ret; | |
5969 | } | |
3f5285e8 JM |
5970 | |
5971 | ||
ad1e68e6 | 5972 | static int nl80211_set_mode(struct wpa_driver_nl80211_data *drv, |
a1922f93 | 5973 | int ifindex, enum nl80211_iftype mode) |
3f5285e8 | 5974 | { |
3f5285e8 | 5975 | struct nl_msg *msg; |
ad1e68e6 JM |
5976 | int ret = -ENOBUFS; |
5977 | ||
a1922f93 JM |
5978 | wpa_printf(MSG_DEBUG, "nl80211: Set mode ifindex %d iftype %d (%s)", |
5979 | ifindex, mode, nl80211_iftype_str(mode)); | |
5980 | ||
56f77852 JM |
5981 | msg = nl80211_cmd_msg(drv->first_bss, 0, NL80211_CMD_SET_INTERFACE); |
5982 | if (!msg || nla_put_u32(msg, NL80211_ATTR_IFTYPE, mode)) | |
a862e4a3 | 5983 | goto fail; |
ad1e68e6 JM |
5984 | |
5985 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
5883168a | 5986 | msg = NULL; |
ad1e68e6 JM |
5987 | if (!ret) |
5988 | return 0; | |
a862e4a3 | 5989 | fail: |
5883168a | 5990 | nlmsg_free(msg); |
ad1e68e6 JM |
5991 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set interface %d to mode %d:" |
5992 | " %d (%s)", ifindex, mode, ret, strerror(-ret)); | |
5993 | return ret; | |
5994 | } | |
5995 | ||
5996 | ||
3c5d34e3 CW |
5997 | static int wpa_driver_nl80211_set_mode_impl( |
5998 | struct i802_bss *bss, | |
5999 | enum nl80211_iftype nlmode, | |
6000 | struct hostapd_freq_params *desired_freq_params) | |
ad1e68e6 | 6001 | { |
a2e40bb6 | 6002 | struct wpa_driver_nl80211_data *drv = bss->drv; |
ad1e68e6 | 6003 | int ret = -1; |
26af9dca | 6004 | int i; |
86957e62 | 6005 | int was_ap = is_ap_interface(drv->nlmode); |
671a5039 | 6006 | int res; |
ebffdbc4 | 6007 | int mode_switch_res; |
1581b38b | 6008 | |
a5a187b0 JM |
6009 | if (TEST_FAIL()) |
6010 | return -1; | |
6011 | ||
ebffdbc4 CW |
6012 | mode_switch_res = nl80211_set_mode(drv, drv->ifindex, nlmode); |
6013 | if (mode_switch_res && nlmode == nl80211_get_ifmode(bss)) | |
6014 | mode_switch_res = 0; | |
8e12685c | 6015 | |
ebffdbc4 | 6016 | if (mode_switch_res == 0) { |
ad1e68e6 | 6017 | drv->nlmode = nlmode; |
460456f8 JM |
6018 | ret = 0; |
6019 | goto done; | |
ad1e68e6 | 6020 | } |
3f5285e8 | 6021 | |
ebffdbc4 | 6022 | if (mode_switch_res == -ENODEV) |
671a5039 JM |
6023 | return -1; |
6024 | ||
460456f8 | 6025 | if (nlmode == drv->nlmode) { |
c6e8e8e4 JM |
6026 | wpa_printf(MSG_DEBUG, "nl80211: Interface already in " |
6027 | "requested mode - ignore error"); | |
460456f8 JM |
6028 | ret = 0; |
6029 | goto done; /* Already in the requested mode */ | |
6030 | } | |
3f5285e8 | 6031 | |
3f5285e8 JM |
6032 | /* mac80211 doesn't allow mode changes while the device is up, so |
6033 | * take the device down, try to set the mode again, and bring the | |
6034 | * device back up. | |
6035 | */ | |
26af9dca JM |
6036 | wpa_printf(MSG_DEBUG, "nl80211: Try mode change after setting " |
6037 | "interface down"); | |
6038 | for (i = 0; i < 10; i++) { | |
91724d6f | 6039 | res = i802_set_iface_flags(bss, 0); |
6e8183d7 JM |
6040 | if (res == -EACCES || res == -ENODEV) |
6041 | break; | |
ebffdbc4 | 6042 | if (res != 0) { |
26af9dca JM |
6043 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set " |
6044 | "interface down"); | |
ebffdbc4 CW |
6045 | os_sleep(0, 100000); |
6046 | continue; | |
6047 | } | |
3c5d34e3 CW |
6048 | |
6049 | /* | |
6050 | * Setting the mode will fail for some drivers if the phy is | |
6051 | * on a frequency that the mode is disallowed in. | |
6052 | */ | |
6053 | if (desired_freq_params) { | |
bdf5ccb2 | 6054 | res = nl80211_set_channel(bss, desired_freq_params, 0); |
3c5d34e3 CW |
6055 | if (res) { |
6056 | wpa_printf(MSG_DEBUG, | |
6057 | "nl80211: Failed to set frequency on interface"); | |
6058 | } | |
6059 | } | |
6060 | ||
ebffdbc4 CW |
6061 | /* Try to set the mode again while the interface is down */ |
6062 | mode_switch_res = nl80211_set_mode(drv, drv->ifindex, nlmode); | |
6063 | if (mode_switch_res == -EBUSY) { | |
6064 | wpa_printf(MSG_DEBUG, | |
6065 | "nl80211: Delaying mode set while interface going down"); | |
6066 | os_sleep(0, 100000); | |
6067 | continue; | |
6068 | } | |
6069 | ret = mode_switch_res; | |
6070 | break; | |
3f5285e8 JM |
6071 | } |
6072 | ||
c6e8e8e4 JM |
6073 | if (!ret) { |
6074 | wpa_printf(MSG_DEBUG, "nl80211: Mode change succeeded while " | |
6075 | "interface is down"); | |
ad1e68e6 | 6076 | drv->nlmode = nlmode; |
7d9c3698 | 6077 | drv->ignore_if_down_event = 1; |
c6e8e8e4 | 6078 | } |
ad1e68e6 | 6079 | |
ebffdbc4 CW |
6080 | /* Bring the interface back up */ |
6081 | res = linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 1); | |
6082 | if (res != 0) { | |
6083 | wpa_printf(MSG_DEBUG, | |
6084 | "nl80211: Failed to set interface up after switching mode"); | |
6085 | ret = -1; | |
6086 | } | |
6087 | ||
460456f8 | 6088 | done: |
3fd1cefb JB |
6089 | if (ret) { |
6090 | wpa_printf(MSG_DEBUG, "nl80211: Interface mode change to %d " | |
6091 | "from %d failed", nlmode, drv->nlmode); | |
6092 | return ret; | |
6093 | } | |
6094 | ||
3e208481 JM |
6095 | if (is_p2p_net_interface(nlmode)) { |
6096 | wpa_printf(MSG_DEBUG, | |
6097 | "nl80211: Interface %s mode change to P2P - disable 11b rates", | |
6098 | bss->ifname); | |
edb9bfba | 6099 | nl80211_disable_11b_rates(drv, drv->ifindex, 1); |
3e208481 JM |
6100 | } else if (drv->disabled_11b_rates) { |
6101 | wpa_printf(MSG_DEBUG, | |
6102 | "nl80211: Interface %s mode changed to non-P2P - re-enable 11b rates", | |
6103 | bss->ifname); | |
1d0c6fb1 | 6104 | nl80211_disable_11b_rates(drv, drv->ifindex, 0); |
3e208481 | 6105 | } |
edb9bfba | 6106 | |
3fd1cefb | 6107 | if (is_ap_interface(nlmode)) { |
36488c05 | 6108 | nl80211_mgmt_unsubscribe(bss, "start AP"); |
460456f8 | 6109 | /* Setup additional AP mode functionality if needed */ |
3fd1cefb | 6110 | if (nl80211_setup_ap(bss)) |
460456f8 | 6111 | return -1; |
3fd1cefb | 6112 | } else if (was_ap) { |
460456f8 | 6113 | /* Remove additional AP mode functionality */ |
3fd1cefb | 6114 | nl80211_teardown_ap(bss); |
a11241fa | 6115 | } else { |
36488c05 | 6116 | nl80211_mgmt_unsubscribe(bss, "mode change"); |
460456f8 | 6117 | } |
460456f8 | 6118 | |
afb0550a BC |
6119 | if (is_mesh_interface(nlmode) && |
6120 | nl80211_mgmt_subscribe_mesh(bss)) | |
6121 | return -1; | |
6122 | ||
873d0fcf | 6123 | if (!bss->in_deinit && !is_ap_interface(nlmode) && |
afb0550a | 6124 | !is_mesh_interface(nlmode) && |
a11241fa JB |
6125 | nl80211_mgmt_subscribe_non_ap(bss) < 0) |
6126 | wpa_printf(MSG_DEBUG, "nl80211: Failed to register Action " | |
6127 | "frame processing - ignore for now"); | |
08359050 | 6128 | |
3fd1cefb | 6129 | return 0; |
3f5285e8 JM |
6130 | } |
6131 | ||
6132 | ||
f3407c66 JM |
6133 | int wpa_driver_nl80211_set_mode(struct i802_bss *bss, |
6134 | enum nl80211_iftype nlmode) | |
3c5d34e3 CW |
6135 | { |
6136 | return wpa_driver_nl80211_set_mode_impl(bss, nlmode, NULL); | |
6137 | } | |
6138 | ||
6139 | ||
4ec68377 JD |
6140 | static int wpa_driver_nl80211_set_mode_ibss(struct i802_bss *bss, |
6141 | struct hostapd_freq_params *freq) | |
3c5d34e3 | 6142 | { |
3c5d34e3 | 6143 | return wpa_driver_nl80211_set_mode_impl(bss, NL80211_IFTYPE_ADHOC, |
4ec68377 | 6144 | freq); |
3c5d34e3 | 6145 | } |
65d645ce AS |
6146 | |
6147 | ||
3f5285e8 JM |
6148 | static int wpa_driver_nl80211_get_capa(void *priv, |
6149 | struct wpa_driver_capa *capa) | |
6150 | { | |
a2e40bb6 FF |
6151 | struct i802_bss *bss = priv; |
6152 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
65d645ce | 6153 | |
3f5285e8 JM |
6154 | if (!drv->has_capability) |
6155 | return -1; | |
6156 | os_memcpy(capa, &drv->capa, sizeof(*capa)); | |
8cd6b7bc JB |
6157 | if (drv->extended_capa && drv->extended_capa_mask) { |
6158 | capa->extended_capa = drv->extended_capa; | |
6159 | capa->extended_capa_mask = drv->extended_capa_mask; | |
6160 | capa->extended_capa_len = drv->extended_capa_len; | |
6161 | } | |
851b0c55 | 6162 | |
906bc4c7 | 6163 | return 0; |
3f5285e8 JM |
6164 | } |
6165 | ||
6166 | ||
6167 | static int wpa_driver_nl80211_set_operstate(void *priv, int state) | |
6168 | { | |
a2e40bb6 FF |
6169 | struct i802_bss *bss = priv; |
6170 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
3f5285e8 | 6171 | |
90a545cc JM |
6172 | wpa_printf(MSG_DEBUG, "nl80211: Set %s operstate %d->%d (%s)", |
6173 | bss->ifname, drv->operstate, state, | |
6174 | state ? "UP" : "DORMANT"); | |
3f5285e8 | 6175 | drv->operstate = state; |
36d84860 | 6176 | return netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, -1, |
e2d02c29 | 6177 | state ? IF_OPER_UP : IF_OPER_DORMANT); |
3f5285e8 JM |
6178 | } |
6179 | ||
01652550 JM |
6180 | |
6181 | static int wpa_driver_nl80211_set_supp_port(void *priv, int authorized) | |
6182 | { | |
a2e40bb6 FF |
6183 | struct i802_bss *bss = priv; |
6184 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
01652550 JM |
6185 | struct nl_msg *msg; |
6186 | struct nl80211_sta_flag_update upd; | |
a862e4a3 | 6187 | int ret; |
2eef5177 JM |
6188 | |
6189 | if (!drv->associated && is_zero_ether_addr(drv->bssid) && !authorized) { | |
6190 | wpa_printf(MSG_DEBUG, "nl80211: Skip set_supp_port(unauthorized) while not associated"); | |
6191 | return 0; | |
6192 | } | |
01652550 | 6193 | |
1ba51ec0 JM |
6194 | wpa_printf(MSG_DEBUG, "nl80211: Set supplicant port %sauthorized for " |
6195 | MACSTR, authorized ? "" : "un", MAC2STR(drv->bssid)); | |
6196 | ||
01652550 JM |
6197 | os_memset(&upd, 0, sizeof(upd)); |
6198 | upd.mask = BIT(NL80211_STA_FLAG_AUTHORIZED); | |
6199 | if (authorized) | |
6200 | upd.set = BIT(NL80211_STA_FLAG_AUTHORIZED); | |
a862e4a3 | 6201 | |
13f83980 | 6202 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) || |
a862e4a3 JM |
6203 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, drv->bssid) || |
6204 | nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd)) { | |
6205 | nlmsg_free(msg); | |
6206 | return -ENOBUFS; | |
6207 | } | |
01652550 | 6208 | |
2eef5177 | 6209 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
2eef5177 JM |
6210 | if (!ret) |
6211 | return 0; | |
2eef5177 JM |
6212 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set STA flag: %d (%s)", |
6213 | ret, strerror(-ret)); | |
6214 | return ret; | |
01652550 JM |
6215 | } |
6216 | ||
3f5285e8 | 6217 | |
f07ead6a JM |
6218 | /* Set kernel driver on given frequency (MHz) */ |
6219 | static int i802_set_freq(void *priv, struct hostapd_freq_params *freq) | |
c5121837 | 6220 | { |
f07ead6a | 6221 | struct i802_bss *bss = priv; |
13a524a3 | 6222 | return nl80211_set_channel(bss, freq, 0); |
c5121837 JM |
6223 | } |
6224 | ||
f7b3920c | 6225 | |
c5121837 JM |
6226 | static inline int min_int(int a, int b) |
6227 | { | |
6228 | if (a < b) | |
6229 | return a; | |
6230 | return b; | |
6231 | } | |
6232 | ||
6233 | ||
6234 | static int get_key_handler(struct nl_msg *msg, void *arg) | |
6235 | { | |
6236 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
6237 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
6238 | ||
6239 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
6240 | genlmsg_attrlen(gnlh, 0), NULL); | |
6241 | ||
6242 | /* | |
6243 | * TODO: validate the key index and mac address! | |
6244 | * Otherwise, there's a race condition as soon as | |
6245 | * the kernel starts sending key notifications. | |
6246 | */ | |
6247 | ||
6248 | if (tb[NL80211_ATTR_KEY_SEQ]) | |
6249 | memcpy(arg, nla_data(tb[NL80211_ATTR_KEY_SEQ]), | |
6250 | min_int(nla_len(tb[NL80211_ATTR_KEY_SEQ]), 6)); | |
4efade31 | 6251 | nl80211_nlmsg_clear(msg); |
c5121837 JM |
6252 | return NL_SKIP; |
6253 | } | |
6254 | ||
6255 | ||
6256 | static int i802_get_seqnum(const char *iface, void *priv, const u8 *addr, | |
6257 | int idx, u8 *seq) | |
6258 | { | |
a2e40bb6 FF |
6259 | struct i802_bss *bss = priv; |
6260 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
c5121837 JM |
6261 | struct nl_msg *msg; |
6262 | ||
95376e1a JM |
6263 | msg = nl80211_ifindex_msg(drv, if_nametoindex(iface), 0, |
6264 | NL80211_CMD_GET_KEY); | |
6265 | if (!msg || | |
a862e4a3 | 6266 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
95376e1a | 6267 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, idx)) { |
a862e4a3 JM |
6268 | nlmsg_free(msg); |
6269 | return -ENOBUFS; | |
6270 | } | |
c5121837 JM |
6271 | |
6272 | memset(seq, 0, 6); | |
6273 | ||
6274 | return send_and_recv_msgs(drv, msg, get_key_handler, seq); | |
c5121837 JM |
6275 | } |
6276 | ||
6277 | ||
c5121837 JM |
6278 | static int i802_set_rts(void *priv, int rts) |
6279 | { | |
a2e40bb6 FF |
6280 | struct i802_bss *bss = priv; |
6281 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
ad649451 | 6282 | struct nl_msg *msg; |
a862e4a3 | 6283 | int ret; |
ad649451 | 6284 | u32 val; |
c5121837 | 6285 | |
bf0021ed | 6286 | if (rts >= 2347 || rts == -1) |
ad649451 JM |
6287 | val = (u32) -1; |
6288 | else | |
6289 | val = rts; | |
c5121837 | 6290 | |
9725b784 | 6291 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_WIPHY)) || |
a862e4a3 JM |
6292 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, val)) { |
6293 | nlmsg_free(msg); | |
6294 | return -ENOBUFS; | |
6295 | } | |
ad649451 JM |
6296 | |
6297 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
6298 | if (!ret) | |
6299 | return 0; | |
ad649451 JM |
6300 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set RTS threshold %d: " |
6301 | "%d (%s)", rts, ret, strerror(-ret)); | |
6302 | return ret; | |
c5121837 JM |
6303 | } |
6304 | ||
6305 | ||
6306 | static int i802_set_frag(void *priv, int frag) | |
6307 | { | |
a2e40bb6 FF |
6308 | struct i802_bss *bss = priv; |
6309 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
ad649451 | 6310 | struct nl_msg *msg; |
a862e4a3 | 6311 | int ret; |
ad649451 | 6312 | u32 val; |
c5121837 | 6313 | |
bf0021ed | 6314 | if (frag >= 2346 || frag == -1) |
ad649451 JM |
6315 | val = (u32) -1; |
6316 | else | |
6317 | val = frag; | |
c5121837 | 6318 | |
9725b784 | 6319 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_WIPHY)) || |
a862e4a3 JM |
6320 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, val)) { |
6321 | nlmsg_free(msg); | |
6322 | return -ENOBUFS; | |
6323 | } | |
ad649451 JM |
6324 | |
6325 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
6326 | if (!ret) | |
6327 | return 0; | |
ad649451 JM |
6328 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set fragmentation threshold " |
6329 | "%d: %d (%s)", frag, ret, strerror(-ret)); | |
6330 | return ret; | |
c5121837 JM |
6331 | } |
6332 | ||
6333 | ||
c5121837 JM |
6334 | static int i802_flush(void *priv) |
6335 | { | |
a2e40bb6 | 6336 | struct i802_bss *bss = priv; |
c5121837 | 6337 | struct nl_msg *msg; |
82554b10 | 6338 | int res; |
c5121837 | 6339 | |
83e7bb0e JM |
6340 | wpa_printf(MSG_DEBUG, "nl80211: flush -> DEL_STATION %s (all)", |
6341 | bss->ifname); | |
c5121837 JM |
6342 | |
6343 | /* | |
6344 | * XXX: FIX! this needs to flush all VLANs too | |
6345 | */ | |
13f83980 JM |
6346 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_DEL_STATION); |
6347 | res = send_and_recv_msgs(bss->drv, msg, NULL, NULL); | |
82554b10 JM |
6348 | if (res) { |
6349 | wpa_printf(MSG_DEBUG, "nl80211: Station flush failed: ret=%d " | |
6350 | "(%s)", res, strerror(-res)); | |
6351 | } | |
6352 | return res; | |
c5121837 JM |
6353 | } |
6354 | ||
6355 | ||
1d6f6385 THJ |
6356 | static void get_sta_tid_stats(struct hostap_sta_driver_data *data, |
6357 | struct nlattr *attr) | |
6358 | { | |
6359 | struct nlattr *tid_stats[NL80211_TID_STATS_MAX + 1], *tidattr; | |
6360 | struct nlattr *txq_stats[NL80211_TXQ_STATS_MAX + 1]; | |
6361 | static struct nla_policy txq_stats_policy[NL80211_TXQ_STATS_MAX + 1] = { | |
6362 | [NL80211_TXQ_STATS_BACKLOG_BYTES] = { .type = NLA_U32 }, | |
6363 | [NL80211_TXQ_STATS_BACKLOG_PACKETS] = { .type = NLA_U32 }, | |
6364 | }; | |
6365 | int rem; | |
6366 | ||
6367 | nla_for_each_nested(tidattr, attr, rem) { | |
6368 | if (nla_parse_nested(tid_stats, NL80211_TID_STATS_MAX, | |
6369 | tidattr, NULL) != 0 || | |
6370 | !tid_stats[NL80211_TID_STATS_TXQ_STATS] || | |
6371 | nla_parse_nested(txq_stats, NL80211_TXQ_STATS_MAX, | |
6372 | tid_stats[NL80211_TID_STATS_TXQ_STATS], | |
6373 | txq_stats_policy) != 0) | |
6374 | continue; | |
6375 | /* sum the backlogs over all TIDs for station */ | |
6376 | if (txq_stats[NL80211_TXQ_STATS_BACKLOG_BYTES]) | |
6377 | data->backlog_bytes += nla_get_u32( | |
6378 | txq_stats[NL80211_TXQ_STATS_BACKLOG_BYTES]); | |
6379 | if (txq_stats[NL80211_TXQ_STATS_BACKLOG_PACKETS]) | |
6380 | data->backlog_bytes += nla_get_u32( | |
6381 | txq_stats[NL80211_TXQ_STATS_BACKLOG_PACKETS]); | |
6382 | } | |
6383 | } | |
6384 | ||
6385 | ||
c5121837 JM |
6386 | static int get_sta_handler(struct nl_msg *msg, void *arg) |
6387 | { | |
6388 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
6389 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
6390 | struct hostap_sta_driver_data *data = arg; | |
6391 | struct nlattr *stats[NL80211_STA_INFO_MAX + 1]; | |
6392 | static struct nla_policy stats_policy[NL80211_STA_INFO_MAX + 1] = { | |
6393 | [NL80211_STA_INFO_INACTIVE_TIME] = { .type = NLA_U32 }, | |
6394 | [NL80211_STA_INFO_RX_BYTES] = { .type = NLA_U32 }, | |
6395 | [NL80211_STA_INFO_TX_BYTES] = { .type = NLA_U32 }, | |
6396 | [NL80211_STA_INFO_RX_PACKETS] = { .type = NLA_U32 }, | |
6397 | [NL80211_STA_INFO_TX_PACKETS] = { .type = NLA_U32 }, | |
dc7785f8 | 6398 | [NL80211_STA_INFO_TX_FAILED] = { .type = NLA_U32 }, |
43022abd NL |
6399 | [NL80211_STA_INFO_RX_BYTES64] = { .type = NLA_U64 }, |
6400 | [NL80211_STA_INFO_TX_BYTES64] = { .type = NLA_U64 }, | |
3567641e | 6401 | [NL80211_STA_INFO_SIGNAL] = { .type = NLA_U8 }, |
72123a84 | 6402 | [NL80211_STA_INFO_ACK_SIGNAL] = { .type = NLA_U8 }, |
58d4c236 THJ |
6403 | [NL80211_STA_INFO_RX_DURATION] = { .type = NLA_U64 }, |
6404 | [NL80211_STA_INFO_TX_DURATION] = { .type = NLA_U64 }, | |
3567641e | 6405 | }; |
6406 | struct nlattr *rate[NL80211_RATE_INFO_MAX + 1]; | |
6407 | static struct nla_policy rate_policy[NL80211_RATE_INFO_MAX + 1] = { | |
6408 | [NL80211_RATE_INFO_BITRATE] = { .type = NLA_U16 }, | |
6409 | [NL80211_RATE_INFO_BITRATE32] = { .type = NLA_U32 }, | |
6410 | [NL80211_RATE_INFO_MCS] = { .type = NLA_U8 }, | |
6411 | [NL80211_RATE_INFO_VHT_MCS] = { .type = NLA_U8 }, | |
6412 | [NL80211_RATE_INFO_SHORT_GI] = { .type = NLA_FLAG }, | |
6413 | [NL80211_RATE_INFO_VHT_NSS] = { .type = NLA_U8 }, | |
c5121837 JM |
6414 | }; |
6415 | ||
6416 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
6417 | genlmsg_attrlen(gnlh, 0), NULL); | |
6418 | ||
6419 | /* | |
6420 | * TODO: validate the interface and mac address! | |
6421 | * Otherwise, there's a race condition as soon as | |
6422 | * the kernel starts sending station notifications. | |
6423 | */ | |
6424 | ||
6425 | if (!tb[NL80211_ATTR_STA_INFO]) { | |
6426 | wpa_printf(MSG_DEBUG, "sta stats missing!"); | |
6427 | return NL_SKIP; | |
6428 | } | |
6429 | if (nla_parse_nested(stats, NL80211_STA_INFO_MAX, | |
6430 | tb[NL80211_ATTR_STA_INFO], | |
6431 | stats_policy)) { | |
6432 | wpa_printf(MSG_DEBUG, "failed to parse nested attributes!"); | |
6433 | return NL_SKIP; | |
6434 | } | |
6435 | ||
6436 | if (stats[NL80211_STA_INFO_INACTIVE_TIME]) | |
6437 | data->inactive_msec = | |
6438 | nla_get_u32(stats[NL80211_STA_INFO_INACTIVE_TIME]); | |
43022abd | 6439 | /* For backwards compatibility, fetch the 32-bit counters first. */ |
c5121837 JM |
6440 | if (stats[NL80211_STA_INFO_RX_BYTES]) |
6441 | data->rx_bytes = nla_get_u32(stats[NL80211_STA_INFO_RX_BYTES]); | |
6442 | if (stats[NL80211_STA_INFO_TX_BYTES]) | |
6443 | data->tx_bytes = nla_get_u32(stats[NL80211_STA_INFO_TX_BYTES]); | |
43022abd NL |
6444 | if (stats[NL80211_STA_INFO_RX_BYTES64] && |
6445 | stats[NL80211_STA_INFO_TX_BYTES64]) { | |
6446 | /* | |
6447 | * The driver supports 64-bit counters, so use them to override | |
6448 | * the 32-bit values. | |
6449 | */ | |
6450 | data->rx_bytes = | |
6451 | nla_get_u64(stats[NL80211_STA_INFO_RX_BYTES64]); | |
6452 | data->tx_bytes = | |
6453 | nla_get_u64(stats[NL80211_STA_INFO_TX_BYTES64]); | |
6454 | data->bytes_64bit = 1; | |
6455 | } | |
c5121837 JM |
6456 | if (stats[NL80211_STA_INFO_RX_PACKETS]) |
6457 | data->rx_packets = | |
6458 | nla_get_u32(stats[NL80211_STA_INFO_RX_PACKETS]); | |
6459 | if (stats[NL80211_STA_INFO_TX_PACKETS]) | |
6460 | data->tx_packets = | |
6461 | nla_get_u32(stats[NL80211_STA_INFO_TX_PACKETS]); | |
58d4c236 THJ |
6462 | if (stats[NL80211_STA_INFO_RX_DURATION]) |
6463 | data->rx_airtime = | |
6464 | nla_get_u64(stats[NL80211_STA_INFO_RX_DURATION]); | |
6465 | if (stats[NL80211_STA_INFO_TX_DURATION]) | |
6466 | data->tx_airtime = | |
6467 | nla_get_u64(stats[NL80211_STA_INFO_TX_DURATION]); | |
dc7785f8 YZ |
6468 | if (stats[NL80211_STA_INFO_TX_FAILED]) |
6469 | data->tx_retry_failed = | |
6470 | nla_get_u32(stats[NL80211_STA_INFO_TX_FAILED]); | |
3567641e | 6471 | if (stats[NL80211_STA_INFO_SIGNAL]) |
6472 | data->signal = nla_get_u8(stats[NL80211_STA_INFO_SIGNAL]); | |
72123a84 BP |
6473 | if (stats[NL80211_STA_INFO_ACK_SIGNAL]) { |
6474 | data->last_ack_rssi = | |
6475 | nla_get_u8(stats[NL80211_STA_INFO_ACK_SIGNAL]); | |
6476 | data->flags |= STA_DRV_DATA_LAST_ACK_RSSI; | |
6477 | } | |
3567641e | 6478 | |
6479 | if (stats[NL80211_STA_INFO_TX_BITRATE] && | |
6480 | nla_parse_nested(rate, NL80211_RATE_INFO_MAX, | |
6481 | stats[NL80211_STA_INFO_TX_BITRATE], | |
6482 | rate_policy) == 0) { | |
6483 | if (rate[NL80211_RATE_INFO_BITRATE32]) | |
6484 | data->current_tx_rate = | |
6485 | nla_get_u32(rate[NL80211_RATE_INFO_BITRATE32]); | |
6486 | else if (rate[NL80211_RATE_INFO_BITRATE]) | |
6487 | data->current_tx_rate = | |
6488 | nla_get_u16(rate[NL80211_RATE_INFO_BITRATE]); | |
6489 | ||
6490 | if (rate[NL80211_RATE_INFO_MCS]) { | |
6491 | data->tx_mcs = nla_get_u8(rate[NL80211_RATE_INFO_MCS]); | |
6492 | data->flags |= STA_DRV_DATA_TX_MCS; | |
6493 | } | |
6494 | if (rate[NL80211_RATE_INFO_VHT_MCS]) { | |
6495 | data->tx_vhtmcs = | |
6496 | nla_get_u8(rate[NL80211_RATE_INFO_VHT_MCS]); | |
6497 | data->flags |= STA_DRV_DATA_TX_VHT_MCS; | |
6498 | } | |
6499 | if (rate[NL80211_RATE_INFO_SHORT_GI]) | |
6500 | data->flags |= STA_DRV_DATA_TX_SHORT_GI; | |
6501 | if (rate[NL80211_RATE_INFO_VHT_NSS]) { | |
6502 | data->tx_vht_nss = | |
6503 | nla_get_u8(rate[NL80211_RATE_INFO_VHT_NSS]); | |
6504 | data->flags |= STA_DRV_DATA_TX_VHT_NSS; | |
6505 | } | |
6506 | } | |
6507 | ||
6508 | if (stats[NL80211_STA_INFO_RX_BITRATE] && | |
6509 | nla_parse_nested(rate, NL80211_RATE_INFO_MAX, | |
6510 | stats[NL80211_STA_INFO_RX_BITRATE], | |
6511 | rate_policy) == 0) { | |
6512 | if (rate[NL80211_RATE_INFO_BITRATE32]) | |
6513 | data->current_rx_rate = | |
6514 | nla_get_u32(rate[NL80211_RATE_INFO_BITRATE32]); | |
6515 | else if (rate[NL80211_RATE_INFO_BITRATE]) | |
6516 | data->current_rx_rate = | |
6517 | nla_get_u16(rate[NL80211_RATE_INFO_BITRATE]); | |
6518 | ||
6519 | if (rate[NL80211_RATE_INFO_MCS]) { | |
6520 | data->rx_mcs = | |
6521 | nla_get_u8(rate[NL80211_RATE_INFO_MCS]); | |
6522 | data->flags |= STA_DRV_DATA_RX_MCS; | |
6523 | } | |
6524 | if (rate[NL80211_RATE_INFO_VHT_MCS]) { | |
6525 | data->rx_vhtmcs = | |
6526 | nla_get_u8(rate[NL80211_RATE_INFO_VHT_MCS]); | |
6527 | data->flags |= STA_DRV_DATA_RX_VHT_MCS; | |
6528 | } | |
6529 | if (rate[NL80211_RATE_INFO_SHORT_GI]) | |
6530 | data->flags |= STA_DRV_DATA_RX_SHORT_GI; | |
6531 | if (rate[NL80211_RATE_INFO_VHT_NSS]) { | |
6532 | data->rx_vht_nss = | |
6533 | nla_get_u8(rate[NL80211_RATE_INFO_VHT_NSS]); | |
6534 | data->flags |= STA_DRV_DATA_RX_VHT_NSS; | |
6535 | } | |
6536 | } | |
c5121837 | 6537 | |
1d6f6385 THJ |
6538 | if (stats[NL80211_STA_INFO_TID_STATS]) |
6539 | get_sta_tid_stats(data, stats[NL80211_STA_INFO_TID_STATS]); | |
6540 | ||
c5121837 JM |
6541 | return NL_SKIP; |
6542 | } | |
6543 | ||
9ebce9c5 JM |
6544 | static int i802_read_sta_data(struct i802_bss *bss, |
6545 | struct hostap_sta_driver_data *data, | |
c5121837 JM |
6546 | const u8 *addr) |
6547 | { | |
c5121837 JM |
6548 | struct nl_msg *msg; |
6549 | ||
13f83980 JM |
6550 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_GET_STATION)) || |
6551 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { | |
a862e4a3 JM |
6552 | nlmsg_free(msg); |
6553 | return -ENOBUFS; | |
6554 | } | |
c5121837 | 6555 | |
13f83980 | 6556 | return send_and_recv_msgs(bss->drv, msg, get_sta_handler, data); |
c5121837 JM |
6557 | } |
6558 | ||
6559 | ||
c5121837 JM |
6560 | static int i802_set_tx_queue_params(void *priv, int queue, int aifs, |
6561 | int cw_min, int cw_max, int burst_time) | |
6562 | { | |
a2e40bb6 FF |
6563 | struct i802_bss *bss = priv; |
6564 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
c5121837 JM |
6565 | struct nl_msg *msg; |
6566 | struct nlattr *txq, *params; | |
bd512469 | 6567 | int res; |
c5121837 | 6568 | |
13f83980 | 6569 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_WIPHY); |
c5121837 JM |
6570 | if (!msg) |
6571 | return -1; | |
6572 | ||
c5121837 JM |
6573 | txq = nla_nest_start(msg, NL80211_ATTR_WIPHY_TXQ_PARAMS); |
6574 | if (!txq) | |
a862e4a3 | 6575 | goto fail; |
c5121837 JM |
6576 | |
6577 | /* We are only sending parameters for a single TXQ at a time */ | |
6578 | params = nla_nest_start(msg, 1); | |
6579 | if (!params) | |
a862e4a3 | 6580 | goto fail; |
c5121837 | 6581 | |
7e3c1781 JM |
6582 | switch (queue) { |
6583 | case 0: | |
a862e4a3 JM |
6584 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_VO)) |
6585 | goto fail; | |
7e3c1781 JM |
6586 | break; |
6587 | case 1: | |
a862e4a3 JM |
6588 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_VI)) |
6589 | goto fail; | |
7e3c1781 JM |
6590 | break; |
6591 | case 2: | |
a862e4a3 JM |
6592 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_BE)) |
6593 | goto fail; | |
7e3c1781 JM |
6594 | break; |
6595 | case 3: | |
a862e4a3 JM |
6596 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_BK)) |
6597 | goto fail; | |
7e3c1781 JM |
6598 | break; |
6599 | } | |
c5121837 JM |
6600 | /* Burst time is configured in units of 0.1 msec and TXOP parameter in |
6601 | * 32 usec, so need to convert the value here. */ | |
a862e4a3 JM |
6602 | if (nla_put_u16(msg, NL80211_TXQ_ATTR_TXOP, |
6603 | (burst_time * 100 + 16) / 32) || | |
6604 | nla_put_u16(msg, NL80211_TXQ_ATTR_CWMIN, cw_min) || | |
6605 | nla_put_u16(msg, NL80211_TXQ_ATTR_CWMAX, cw_max) || | |
6606 | nla_put_u8(msg, NL80211_TXQ_ATTR_AIFS, aifs)) | |
6607 | goto fail; | |
c5121837 JM |
6608 | |
6609 | nla_nest_end(msg, params); | |
6610 | ||
6611 | nla_nest_end(msg, txq); | |
6612 | ||
bd512469 JM |
6613 | res = send_and_recv_msgs(drv, msg, NULL, NULL); |
6614 | wpa_printf(MSG_DEBUG, | |
6615 | "nl80211: TX queue param set: queue=%d aifs=%d cw_min=%d cw_max=%d burst_time=%d --> res=%d", | |
6616 | queue, aifs, cw_min, cw_max, burst_time, res); | |
6617 | if (res == 0) | |
c5121837 | 6618 | return 0; |
9e088e74 | 6619 | msg = NULL; |
a862e4a3 | 6620 | fail: |
9e088e74 | 6621 | nlmsg_free(msg); |
c5121837 JM |
6622 | return -1; |
6623 | } | |
6624 | ||
6625 | ||
9ebce9c5 | 6626 | static int i802_set_sta_vlan(struct i802_bss *bss, const u8 *addr, |
c5121837 JM |
6627 | const char *ifname, int vlan_id) |
6628 | { | |
a2e40bb6 | 6629 | struct wpa_driver_nl80211_data *drv = bss->drv; |
c5121837 | 6630 | struct nl_msg *msg; |
a862e4a3 | 6631 | int ret; |
c5121837 | 6632 | |
bbc706a3 JM |
6633 | wpa_printf(MSG_DEBUG, "nl80211: %s[%d]: set_sta_vlan(" MACSTR |
6634 | ", ifname=%s[%d], vlan_id=%d)", | |
6635 | bss->ifname, if_nametoindex(bss->ifname), | |
6636 | MAC2STR(addr), ifname, if_nametoindex(ifname), vlan_id); | |
13f83980 | 6637 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) || |
a862e4a3 JM |
6638 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
6639 | nla_put_u32(msg, NL80211_ATTR_STA_VLAN, if_nametoindex(ifname))) { | |
6640 | nlmsg_free(msg); | |
6641 | return -ENOBUFS; | |
6642 | } | |
c5121837 | 6643 | |
cd1d72c1 JM |
6644 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
6645 | if (ret < 0) { | |
6646 | wpa_printf(MSG_ERROR, "nl80211: NL80211_ATTR_STA_VLAN (addr=" | |
6647 | MACSTR " ifname=%s vlan_id=%d) failed: %d (%s)", | |
6648 | MAC2STR(addr), ifname, vlan_id, ret, | |
6649 | strerror(-ret)); | |
6650 | } | |
cd1d72c1 | 6651 | return ret; |
c5121837 JM |
6652 | } |
6653 | ||
fbbfcbac | 6654 | |
c5121837 JM |
6655 | static int i802_get_inact_sec(void *priv, const u8 *addr) |
6656 | { | |
6657 | struct hostap_sta_driver_data data; | |
6658 | int ret; | |
6659 | ||
7824bf77 | 6660 | os_memset(&data, 0, sizeof(data)); |
c5121837 JM |
6661 | data.inactive_msec = (unsigned long) -1; |
6662 | ret = i802_read_sta_data(priv, &data, addr); | |
b9749bac MH |
6663 | if (ret == -ENOENT) |
6664 | return -ENOENT; | |
c5121837 JM |
6665 | if (ret || data.inactive_msec == (unsigned long) -1) |
6666 | return -1; | |
6667 | return data.inactive_msec / 1000; | |
6668 | } | |
6669 | ||
6670 | ||
6671 | static int i802_sta_clear_stats(void *priv, const u8 *addr) | |
6672 | { | |
6673 | #if 0 | |
6674 | /* TODO */ | |
6675 | #endif | |
6676 | return 0; | |
6677 | } | |
6678 | ||
6679 | ||
731723a5 | 6680 | static int i802_sta_deauth(void *priv, const u8 *own_addr, const u8 *addr, |
4be17ffb | 6681 | u16 reason) |
c5121837 | 6682 | { |
a2e40bb6 | 6683 | struct i802_bss *bss = priv; |
e1bd4e19 | 6684 | struct wpa_driver_nl80211_data *drv = bss->drv; |
c5121837 | 6685 | struct ieee80211_mgmt mgmt; |
05e5e615 DL |
6686 | u8 channel; |
6687 | ||
6688 | if (ieee80211_freq_to_chan(bss->freq, &channel) == | |
6689 | HOSTAPD_MODE_IEEE80211AD) { | |
6690 | /* Deauthentication is not used in DMG/IEEE 802.11ad; | |
6691 | * disassociate the STA instead. */ | |
6692 | return i802_sta_disassoc(priv, own_addr, addr, reason); | |
6693 | } | |
c5121837 | 6694 | |
0d391b03 BC |
6695 | if (is_mesh_interface(drv->nlmode)) |
6696 | return -1; | |
6697 | ||
e1bd4e19 | 6698 | if (drv->device_ap_sme) |
59d7148a | 6699 | return wpa_driver_nl80211_sta_remove(bss, addr, 1, reason); |
e1bd4e19 | 6700 | |
c5121837 JM |
6701 | memset(&mgmt, 0, sizeof(mgmt)); |
6702 | mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, | |
6703 | WLAN_FC_STYPE_DEAUTH); | |
6704 | memcpy(mgmt.da, addr, ETH_ALEN); | |
731723a5 JM |
6705 | memcpy(mgmt.sa, own_addr, ETH_ALEN); |
6706 | memcpy(mgmt.bssid, own_addr, ETH_ALEN); | |
c5121837 | 6707 | mgmt.u.deauth.reason_code = host_to_le16(reason); |
a2e40bb6 | 6708 | return wpa_driver_nl80211_send_mlme(bss, (u8 *) &mgmt, |
9f324b61 | 6709 | IEEE80211_HDRLEN + |
9ebce9c5 | 6710 | sizeof(mgmt.u.deauth), 0, 0, 0, 0, |
27cc06d0 | 6711 | 0, NULL, 0, 0); |
c5121837 JM |
6712 | } |
6713 | ||
6714 | ||
731723a5 | 6715 | static int i802_sta_disassoc(void *priv, const u8 *own_addr, const u8 *addr, |
4be17ffb | 6716 | u16 reason) |
c5121837 | 6717 | { |
a2e40bb6 | 6718 | struct i802_bss *bss = priv; |
e1bd4e19 | 6719 | struct wpa_driver_nl80211_data *drv = bss->drv; |
c5121837 JM |
6720 | struct ieee80211_mgmt mgmt; |
6721 | ||
0d391b03 BC |
6722 | if (is_mesh_interface(drv->nlmode)) |
6723 | return -1; | |
6724 | ||
e1bd4e19 | 6725 | if (drv->device_ap_sme) |
59d7148a | 6726 | return wpa_driver_nl80211_sta_remove(bss, addr, 0, reason); |
e1bd4e19 | 6727 | |
c5121837 JM |
6728 | memset(&mgmt, 0, sizeof(mgmt)); |
6729 | mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, | |
6730 | WLAN_FC_STYPE_DISASSOC); | |
6731 | memcpy(mgmt.da, addr, ETH_ALEN); | |
731723a5 JM |
6732 | memcpy(mgmt.sa, own_addr, ETH_ALEN); |
6733 | memcpy(mgmt.bssid, own_addr, ETH_ALEN); | |
c5121837 | 6734 | mgmt.u.disassoc.reason_code = host_to_le16(reason); |
a2e40bb6 | 6735 | return wpa_driver_nl80211_send_mlme(bss, (u8 *) &mgmt, |
9f324b61 | 6736 | IEEE80211_HDRLEN + |
9ebce9c5 | 6737 | sizeof(mgmt.u.disassoc), 0, 0, 0, 0, |
27cc06d0 | 6738 | 0, NULL, 0, 0); |
c5121837 JM |
6739 | } |
6740 | ||
6741 | ||
9b4d9c8b JM |
6742 | static void dump_ifidx(struct wpa_driver_nl80211_data *drv) |
6743 | { | |
6744 | char buf[200], *pos, *end; | |
6745 | int i, res; | |
6746 | ||
6747 | pos = buf; | |
6748 | end = pos + sizeof(buf); | |
6749 | ||
6750 | for (i = 0; i < drv->num_if_indices; i++) { | |
099224c1 | 6751 | if (!drv->if_indices[i].ifindex) |
9b4d9c8b | 6752 | continue; |
732b1d20 | 6753 | res = os_snprintf(pos, end - pos, " %d(%d)", |
099224c1 JM |
6754 | drv->if_indices[i].ifindex, |
6755 | drv->if_indices[i].reason); | |
d85e1fc8 | 6756 | if (os_snprintf_error(end - pos, res)) |
9b4d9c8b JM |
6757 | break; |
6758 | pos += res; | |
6759 | } | |
6760 | *pos = '\0'; | |
6761 | ||
6762 | wpa_printf(MSG_DEBUG, "nl80211: if_indices[%d]:%s", | |
6763 | drv->num_if_indices, buf); | |
6764 | } | |
6765 | ||
6766 | ||
732b1d20 MB |
6767 | static void add_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, |
6768 | int ifidx_reason) | |
f07ead6a JM |
6769 | { |
6770 | int i; | |
099224c1 | 6771 | struct drv_nl80211_if_info *old; |
f07ead6a | 6772 | |
732b1d20 MB |
6773 | wpa_printf(MSG_DEBUG, |
6774 | "nl80211: Add own interface ifindex %d (ifidx_reason %d)", | |
6775 | ifidx, ifidx_reason); | |
6776 | if (have_ifidx(drv, ifidx, ifidx_reason)) { | |
b36935be MB |
6777 | wpa_printf(MSG_DEBUG, "nl80211: ifindex %d already in the list", |
6778 | ifidx); | |
6779 | return; | |
6780 | } | |
f07ead6a | 6781 | for (i = 0; i < drv->num_if_indices; i++) { |
099224c1 JM |
6782 | if (drv->if_indices[i].ifindex == 0) { |
6783 | drv->if_indices[i].ifindex = ifidx; | |
6784 | drv->if_indices[i].reason = ifidx_reason; | |
9b4d9c8b | 6785 | dump_ifidx(drv); |
f07ead6a JM |
6786 | return; |
6787 | } | |
6788 | } | |
6789 | ||
6790 | if (drv->if_indices != drv->default_if_indices) | |
6791 | old = drv->if_indices; | |
6792 | else | |
6793 | old = NULL; | |
6794 | ||
067ffa26 | 6795 | drv->if_indices = os_realloc_array(old, drv->num_if_indices + 1, |
099224c1 | 6796 | sizeof(*old)); |
f07ead6a JM |
6797 | if (!drv->if_indices) { |
6798 | if (!old) | |
6799 | drv->if_indices = drv->default_if_indices; | |
6800 | else | |
6801 | drv->if_indices = old; | |
6802 | wpa_printf(MSG_ERROR, "Failed to reallocate memory for " | |
6803 | "interfaces"); | |
6804 | wpa_printf(MSG_ERROR, "Ignoring EAPOL on interface %d", ifidx); | |
6805 | return; | |
732b1d20 MB |
6806 | } |
6807 | if (!old) | |
f07ead6a JM |
6808 | os_memcpy(drv->if_indices, drv->default_if_indices, |
6809 | sizeof(drv->default_if_indices)); | |
099224c1 JM |
6810 | drv->if_indices[drv->num_if_indices].ifindex = ifidx; |
6811 | drv->if_indices[drv->num_if_indices].reason = ifidx_reason; | |
f07ead6a | 6812 | drv->num_if_indices++; |
9b4d9c8b | 6813 | dump_ifidx(drv); |
f07ead6a JM |
6814 | } |
6815 | ||
6816 | ||
732b1d20 MB |
6817 | static void del_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, |
6818 | int ifidx_reason) | |
f07ead6a JM |
6819 | { |
6820 | int i; | |
6821 | ||
6822 | for (i = 0; i < drv->num_if_indices; i++) { | |
099224c1 JM |
6823 | if ((drv->if_indices[i].ifindex == ifidx || |
6824 | ifidx == IFIDX_ANY) && | |
6825 | (drv->if_indices[i].reason == ifidx_reason || | |
732b1d20 | 6826 | ifidx_reason == IFIDX_ANY)) { |
099224c1 JM |
6827 | drv->if_indices[i].ifindex = 0; |
6828 | drv->if_indices[i].reason = 0; | |
f07ead6a JM |
6829 | break; |
6830 | } | |
6831 | } | |
9b4d9c8b | 6832 | dump_ifidx(drv); |
f07ead6a JM |
6833 | } |
6834 | ||
6835 | ||
732b1d20 MB |
6836 | static int have_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, |
6837 | int ifidx_reason) | |
f07ead6a JM |
6838 | { |
6839 | int i; | |
6840 | ||
6841 | for (i = 0; i < drv->num_if_indices; i++) | |
099224c1 JM |
6842 | if (drv->if_indices[i].ifindex == ifidx && |
6843 | (drv->if_indices[i].reason == ifidx_reason || | |
732b1d20 | 6844 | ifidx_reason == IFIDX_ANY)) |
f07ead6a JM |
6845 | return 1; |
6846 | ||
6847 | return 0; | |
6848 | } | |
6849 | ||
6850 | ||
6851 | static int i802_set_wds_sta(void *priv, const u8 *addr, int aid, int val, | |
0e80ea2c | 6852 | const char *bridge_ifname, char *ifname_wds) |
f07ead6a JM |
6853 | { |
6854 | struct i802_bss *bss = priv; | |
6855 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
6856 | char name[IFNAMSIZ + 1]; | |
1952b626 | 6857 | union wpa_event_data event; |
d577f7f3 AO |
6858 | int ret; |
6859 | ||
6860 | ret = os_snprintf(name, sizeof(name), "%s.sta%d", bss->ifname, aid); | |
6861 | if (ret >= (int) sizeof(name)) | |
6862 | wpa_printf(MSG_WARNING, | |
6863 | "nl80211: WDS interface name was truncated"); | |
6864 | else if (ret < 0) | |
6865 | return ret; | |
f07ead6a | 6866 | |
69dd2967 SM |
6867 | if (ifname_wds) |
6868 | os_strlcpy(ifname_wds, name, IFNAMSIZ + 1); | |
6869 | ||
f07ead6a JM |
6870 | wpa_printf(MSG_DEBUG, "nl80211: Set WDS STA addr=" MACSTR |
6871 | " aid=%d val=%d name=%s", MAC2STR(addr), aid, val, name); | |
6872 | if (val) { | |
6873 | if (!if_nametoindex(name)) { | |
6874 | if (nl80211_create_iface(drv, name, | |
6875 | NL80211_IFTYPE_AP_VLAN, | |
2aec4f3c JM |
6876 | bss->addr, 1, NULL, NULL, 0) < |
6877 | 0) | |
f07ead6a JM |
6878 | return -1; |
6879 | if (bridge_ifname && | |
c81eff1a BG |
6880 | linux_br_add_if(drv->global->ioctl_sock, |
6881 | bridge_ifname, name) < 0) | |
f07ead6a | 6882 | return -1; |
1952b626 BP |
6883 | |
6884 | os_memset(&event, 0, sizeof(event)); | |
6885 | event.wds_sta_interface.sta_addr = addr; | |
6886 | event.wds_sta_interface.ifname = name; | |
6887 | event.wds_sta_interface.istatus = INTERFACE_ADDED; | |
8bfbb295 | 6888 | wpa_supplicant_event(bss->ctx, |
1952b626 BP |
6889 | EVENT_WDS_STA_INTERFACE_STATUS, |
6890 | &event); | |
f07ead6a | 6891 | } |
75227f3a JM |
6892 | if (linux_set_iface_flags(drv->global->ioctl_sock, name, 1)) { |
6893 | wpa_printf(MSG_ERROR, "nl80211: Failed to set WDS STA " | |
6894 | "interface %s up", name); | |
6895 | } | |
f07ead6a JM |
6896 | return i802_set_sta_vlan(priv, addr, name, 0); |
6897 | } else { | |
f9052d6e JM |
6898 | if (bridge_ifname && |
6899 | linux_br_del_if(drv->global->ioctl_sock, bridge_ifname, | |
6900 | name) < 0) | |
6901 | wpa_printf(MSG_INFO, | |
6902 | "nl80211: Failed to remove interface %s from bridge %s: %s", | |
6903 | name, bridge_ifname, strerror(errno)); | |
c34e618d | 6904 | |
f07ead6a | 6905 | i802_set_sta_vlan(priv, addr, bss->ifname, 0); |
d0595b25 | 6906 | nl80211_remove_iface(drv, if_nametoindex(name)); |
1952b626 BP |
6907 | os_memset(&event, 0, sizeof(event)); |
6908 | event.wds_sta_interface.sta_addr = addr; | |
6909 | event.wds_sta_interface.ifname = name; | |
6910 | event.wds_sta_interface.istatus = INTERFACE_REMOVED; | |
8bfbb295 | 6911 | wpa_supplicant_event(bss->ctx, EVENT_WDS_STA_INTERFACE_STATUS, |
1952b626 | 6912 | &event); |
d0595b25 | 6913 | return 0; |
f07ead6a JM |
6914 | } |
6915 | } | |
6916 | ||
6917 | ||
6918 | static void handle_eapol(int sock, void *eloop_ctx, void *sock_ctx) | |
6919 | { | |
6920 | struct wpa_driver_nl80211_data *drv = eloop_ctx; | |
6921 | struct sockaddr_ll lladdr; | |
6922 | unsigned char buf[3000]; | |
6923 | int len; | |
6924 | socklen_t fromlen = sizeof(lladdr); | |
6925 | ||
6926 | len = recvfrom(sock, buf, sizeof(buf), 0, | |
6927 | (struct sockaddr *)&lladdr, &fromlen); | |
6928 | if (len < 0) { | |
7ac3616d JM |
6929 | wpa_printf(MSG_ERROR, "nl80211: EAPOL recv failed: %s", |
6930 | strerror(errno)); | |
f07ead6a JM |
6931 | return; |
6932 | } | |
6933 | ||
732b1d20 | 6934 | if (have_ifidx(drv, lladdr.sll_ifindex, IFIDX_ANY)) |
f07ead6a JM |
6935 | drv_event_eapol_rx(drv->ctx, lladdr.sll_addr, buf, len); |
6936 | } | |
6937 | ||
6938 | ||
94627f6c | 6939 | static int i802_check_bridge(struct wpa_driver_nl80211_data *drv, |
e17a2477 | 6940 | struct i802_bss *bss, |
94627f6c JM |
6941 | const char *brname, const char *ifname) |
6942 | { | |
6c6678e7 | 6943 | int br_ifindex; |
94627f6c JM |
6944 | char in_br[IFNAMSIZ]; |
6945 | ||
e17a2477 | 6946 | os_strlcpy(bss->brname, brname, IFNAMSIZ); |
6c6678e7 | 6947 | br_ifindex = if_nametoindex(brname); |
6c6678e7 | 6948 | if (br_ifindex == 0) { |
94627f6c JM |
6949 | /* |
6950 | * Bridge was configured, but the bridge device does | |
6951 | * not exist. Try to add it now. | |
6952 | */ | |
c81eff1a | 6953 | if (linux_br_add(drv->global->ioctl_sock, brname) < 0) { |
94627f6c JM |
6954 | wpa_printf(MSG_ERROR, "nl80211: Failed to add the " |
6955 | "bridge interface %s: %s", | |
6956 | brname, strerror(errno)); | |
6957 | return -1; | |
6958 | } | |
e17a2477 | 6959 | bss->added_bridge = 1; |
8997613c | 6960 | br_ifindex = if_nametoindex(brname); |
732b1d20 | 6961 | add_ifidx(drv, br_ifindex, drv->ifindex); |
94627f6c | 6962 | } |
8997613c | 6963 | bss->br_ifindex = br_ifindex; |
94627f6c JM |
6964 | |
6965 | if (linux_br_get(in_br, ifname) == 0) { | |
c809756f SM |
6966 | if (os_strcmp(in_br, brname) == 0) { |
6967 | bss->already_in_bridge = 1; | |
94627f6c | 6968 | return 0; /* already in the bridge */ |
c809756f | 6969 | } |
94627f6c JM |
6970 | |
6971 | wpa_printf(MSG_DEBUG, "nl80211: Removing interface %s from " | |
6972 | "bridge %s", ifname, in_br); | |
c81eff1a BG |
6973 | if (linux_br_del_if(drv->global->ioctl_sock, in_br, ifname) < |
6974 | 0) { | |
94627f6c JM |
6975 | wpa_printf(MSG_ERROR, "nl80211: Failed to " |
6976 | "remove interface %s from bridge " | |
6977 | "%s: %s", | |
fdbfb63e | 6978 | ifname, in_br, strerror(errno)); |
94627f6c JM |
6979 | return -1; |
6980 | } | |
6981 | } | |
6982 | ||
6983 | wpa_printf(MSG_DEBUG, "nl80211: Adding interface %s into bridge %s", | |
6984 | ifname, brname); | |
c81eff1a | 6985 | if (linux_br_add_if(drv->global->ioctl_sock, brname, ifname) < 0) { |
8e111157 MK |
6986 | wpa_printf(MSG_WARNING, |
6987 | "nl80211: Failed to add interface %s into bridge %s: %s", | |
94627f6c | 6988 | ifname, brname, strerror(errno)); |
8e111157 MK |
6989 | /* Try to continue without the interface being in a bridge. This |
6990 | * may be needed for some cases, e.g., with Open vSwitch, where | |
6991 | * an external component will need to handle bridge | |
6992 | * configuration. */ | |
6993 | return 0; | |
94627f6c | 6994 | } |
e17a2477 | 6995 | bss->added_if_into_bridge = 1; |
94627f6c JM |
6996 | |
6997 | return 0; | |
6998 | } | |
6999 | ||
7000 | ||
92f475b4 JM |
7001 | static void *i802_init(struct hostapd_data *hapd, |
7002 | struct wpa_init_params *params) | |
c5121837 JM |
7003 | { |
7004 | struct wpa_driver_nl80211_data *drv; | |
a2e40bb6 | 7005 | struct i802_bss *bss; |
c5121837 | 7006 | size_t i; |
cb05808c AN |
7007 | char master_ifname[IFNAMSIZ]; |
7008 | int ifindex, br_ifindex = 0; | |
94627f6c | 7009 | int br_added = 0; |
c5121837 | 7010 | |
0d547d5f JM |
7011 | bss = wpa_driver_nl80211_drv_init(hapd, params->ifname, |
7012 | params->global_priv, 1, | |
0ecff8d7 | 7013 | params->bssid, params->driver_params); |
a2e40bb6 | 7014 | if (bss == NULL) |
c5121837 | 7015 | return NULL; |
c5121837 | 7016 | |
a2e40bb6 | 7017 | drv = bss->drv; |
7635bfb0 | 7018 | |
cb05808c | 7019 | if (linux_br_get(master_ifname, params->ifname) == 0) { |
94627f6c | 7020 | wpa_printf(MSG_DEBUG, "nl80211: Interface %s is in bridge %s", |
cb05808c AN |
7021 | params->ifname, master_ifname); |
7022 | br_ifindex = if_nametoindex(master_ifname); | |
7023 | os_strlcpy(bss->brname, master_ifname, IFNAMSIZ); | |
7024 | } else if ((params->num_bridge == 0 || !params->bridge[0]) && | |
7025 | linux_master_get(master_ifname, params->ifname) == 0) { | |
7026 | wpa_printf(MSG_DEBUG, "nl80211: Interface %s is in master %s", | |
7027 | params->ifname, master_ifname); | |
7028 | /* start listening for EAPOL on the master interface */ | |
732b1d20 | 7029 | add_ifidx(drv, if_nametoindex(master_ifname), drv->ifindex); |
f2d6c17a DL |
7030 | |
7031 | /* check if master itself is under bridge */ | |
7032 | if (linux_br_get(master_ifname, master_ifname) == 0) { | |
7033 | wpa_printf(MSG_DEBUG, "nl80211: which is in bridge %s", | |
7034 | master_ifname); | |
7035 | br_ifindex = if_nametoindex(master_ifname); | |
7036 | os_strlcpy(bss->brname, master_ifname, IFNAMSIZ); | |
7037 | } | |
94627f6c | 7038 | } else { |
cb05808c | 7039 | master_ifname[0] = '\0'; |
94627f6c | 7040 | } |
cb05808c | 7041 | |
6c6678e7 | 7042 | bss->br_ifindex = br_ifindex; |
94627f6c | 7043 | |
92f475b4 | 7044 | for (i = 0; i < params->num_bridge; i++) { |
94627f6c JM |
7045 | if (params->bridge[i]) { |
7046 | ifindex = if_nametoindex(params->bridge[i]); | |
7047 | if (ifindex) | |
732b1d20 | 7048 | add_ifidx(drv, ifindex, drv->ifindex); |
94627f6c JM |
7049 | if (ifindex == br_ifindex) |
7050 | br_added = 1; | |
7051 | } | |
c5121837 | 7052 | } |
c5121837 | 7053 | |
ad1e68e6 | 7054 | /* start listening for EAPOL on the default AP interface */ |
732b1d20 | 7055 | add_ifidx(drv, drv->ifindex, IFIDX_ANY); |
ad1e68e6 | 7056 | |
5ef8e39f JM |
7057 | if (params->num_bridge && params->bridge[0]) { |
7058 | if (i802_check_bridge(drv, bss, params->bridge[0], | |
7059 | params->ifname) < 0) | |
7060 | goto failed; | |
cb05808c | 7061 | if (os_strcmp(params->bridge[0], master_ifname) != 0) |
5ef8e39f JM |
7062 | br_added = 1; |
7063 | } | |
7064 | ||
7065 | if (!br_added && br_ifindex && | |
7066 | (params->num_bridge == 0 || !params->bridge[0])) | |
732b1d20 | 7067 | add_ifidx(drv, br_ifindex, drv->ifindex); |
94627f6c | 7068 | |
97ed9a06 | 7069 | #ifdef CONFIG_LIBNL3_ROUTE |
c809756f | 7070 | if (bss->added_if_into_bridge || bss->already_in_bridge) { |
3ea58a05 JM |
7071 | int err; |
7072 | ||
97ed9a06 KP |
7073 | drv->rtnl_sk = nl_socket_alloc(); |
7074 | if (drv->rtnl_sk == NULL) { | |
7075 | wpa_printf(MSG_ERROR, "nl80211: Failed to allocate nl_sock"); | |
7076 | goto failed; | |
7077 | } | |
7078 | ||
3ea58a05 JM |
7079 | err = nl_connect(drv->rtnl_sk, NETLINK_ROUTE); |
7080 | if (err) { | |
97ed9a06 | 7081 | wpa_printf(MSG_ERROR, "nl80211: Failed to connect nl_sock to NETLINK_ROUTE: %s", |
3ea58a05 | 7082 | nl_geterror(err)); |
97ed9a06 KP |
7083 | goto failed; |
7084 | } | |
7085 | } | |
7086 | #endif /* CONFIG_LIBNL3_ROUTE */ | |
7087 | ||
ad1e68e6 JM |
7088 | drv->eapol_sock = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_PAE)); |
7089 | if (drv->eapol_sock < 0) { | |
7ac3616d JM |
7090 | wpa_printf(MSG_ERROR, "nl80211: socket(PF_PACKET, SOCK_DGRAM, ETH_P_PAE) failed: %s", |
7091 | strerror(errno)); | |
bbaf0837 | 7092 | goto failed; |
ad1e68e6 JM |
7093 | } |
7094 | ||
7095 | if (eloop_register_read_sock(drv->eapol_sock, handle_eapol, drv, NULL)) | |
7096 | { | |
7ac3616d | 7097 | wpa_printf(MSG_INFO, "nl80211: Could not register read socket for eapol"); |
c5121837 | 7098 | goto failed; |
ad1e68e6 JM |
7099 | } |
7100 | ||
c81eff1a BG |
7101 | if (linux_get_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
7102 | params->own_addr)) | |
bbaf0837 | 7103 | goto failed; |
fee354c7 | 7104 | os_memcpy(drv->perm_addr, params->own_addr, ETH_ALEN); |
c5121837 | 7105 | |
341eebee JB |
7106 | memcpy(bss->addr, params->own_addr, ETH_ALEN); |
7107 | ||
a2e40bb6 | 7108 | return bss; |
c5121837 JM |
7109 | |
7110 | failed: | |
7635bfb0 | 7111 | wpa_driver_nl80211_deinit(bss); |
bbaf0837 JM |
7112 | return NULL; |
7113 | } | |
c5121837 | 7114 | |
c5121837 | 7115 | |
bbaf0837 JM |
7116 | static void i802_deinit(void *priv) |
7117 | { | |
9ebce9c5 JM |
7118 | struct i802_bss *bss = priv; |
7119 | wpa_driver_nl80211_deinit(bss); | |
c5121837 JM |
7120 | } |
7121 | ||
c5121837 | 7122 | |
22a7c9d7 JM |
7123 | static enum nl80211_iftype wpa_driver_nl80211_if_type( |
7124 | enum wpa_driver_if_type type) | |
7125 | { | |
7126 | switch (type) { | |
7127 | case WPA_IF_STATION: | |
9f51b113 | 7128 | return NL80211_IFTYPE_STATION; |
75bde05d JM |
7129 | case WPA_IF_P2P_CLIENT: |
7130 | case WPA_IF_P2P_GROUP: | |
9f51b113 | 7131 | return NL80211_IFTYPE_P2P_CLIENT; |
22a7c9d7 JM |
7132 | case WPA_IF_AP_VLAN: |
7133 | return NL80211_IFTYPE_AP_VLAN; | |
7134 | case WPA_IF_AP_BSS: | |
7135 | return NL80211_IFTYPE_AP; | |
9f51b113 JB |
7136 | case WPA_IF_P2P_GO: |
7137 | return NL80211_IFTYPE_P2P_GO; | |
7aad838c NS |
7138 | case WPA_IF_P2P_DEVICE: |
7139 | return NL80211_IFTYPE_P2P_DEVICE; | |
5b78493f MH |
7140 | case WPA_IF_MESH: |
7141 | return NL80211_IFTYPE_MESH_POINT; | |
98342208 AK |
7142 | default: |
7143 | return -1; | |
22a7c9d7 | 7144 | } |
22a7c9d7 JM |
7145 | } |
7146 | ||
7147 | ||
f2ed8023 JM |
7148 | static int nl80211_addr_in_use(struct nl80211_global *global, const u8 *addr) |
7149 | { | |
7150 | struct wpa_driver_nl80211_data *drv; | |
7151 | dl_list_for_each(drv, &global->interfaces, | |
7152 | struct wpa_driver_nl80211_data, list) { | |
834ee56f | 7153 | if (os_memcmp(addr, drv->first_bss->addr, ETH_ALEN) == 0) |
f2ed8023 JM |
7154 | return 1; |
7155 | } | |
7156 | return 0; | |
7157 | } | |
7158 | ||
7159 | ||
5b78493f | 7160 | static int nl80211_vif_addr(struct wpa_driver_nl80211_data *drv, u8 *new_addr) |
f2ed8023 JM |
7161 | { |
7162 | unsigned int idx; | |
7163 | ||
7164 | if (!drv->global) | |
7165 | return -1; | |
7166 | ||
834ee56f | 7167 | os_memcpy(new_addr, drv->first_bss->addr, ETH_ALEN); |
f2ed8023 | 7168 | for (idx = 0; idx < 64; idx++) { |
834ee56f | 7169 | new_addr[0] = drv->first_bss->addr[0] | 0x02; |
f2ed8023 JM |
7170 | new_addr[0] ^= idx << 2; |
7171 | if (!nl80211_addr_in_use(drv->global, new_addr)) | |
7172 | break; | |
7173 | } | |
7174 | if (idx == 64) | |
7175 | return -1; | |
7176 | ||
5b78493f | 7177 | wpa_printf(MSG_DEBUG, "nl80211: Assigned new virtual interface address " |
f2ed8023 JM |
7178 | MACSTR, MAC2STR(new_addr)); |
7179 | ||
7180 | return 0; | |
7181 | } | |
7182 | ||
7183 | ||
f632e483 AS |
7184 | struct wdev_info { |
7185 | u64 wdev_id; | |
7186 | int wdev_id_set; | |
7187 | u8 macaddr[ETH_ALEN]; | |
7188 | }; | |
7189 | ||
7190 | static int nl80211_wdev_handler(struct nl_msg *msg, void *arg) | |
e472e1b4 AS |
7191 | { |
7192 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
7193 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
f632e483 | 7194 | struct wdev_info *wi = arg; |
e472e1b4 AS |
7195 | |
7196 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
7197 | genlmsg_attrlen(gnlh, 0), NULL); | |
7198 | if (tb[NL80211_ATTR_WDEV]) { | |
f632e483 AS |
7199 | wi->wdev_id = nla_get_u64(tb[NL80211_ATTR_WDEV]); |
7200 | wi->wdev_id_set = 1; | |
e472e1b4 AS |
7201 | } |
7202 | ||
7203 | if (tb[NL80211_ATTR_MAC]) | |
f632e483 | 7204 | os_memcpy(wi->macaddr, nla_data(tb[NL80211_ATTR_MAC]), |
e472e1b4 AS |
7205 | ETH_ALEN); |
7206 | ||
7207 | return NL_SKIP; | |
7208 | } | |
7209 | ||
7210 | ||
7ab68865 | 7211 | static int wpa_driver_nl80211_if_add(void *priv, enum wpa_driver_if_type type, |
8043e725 | 7212 | const char *ifname, const u8 *addr, |
f3585c8a | 7213 | void *bss_ctx, void **drv_priv, |
e17a2477 | 7214 | char *force_ifname, u8 *if_addr, |
d8a3b66d AS |
7215 | const char *bridge, int use_existing, |
7216 | int setup_ap) | |
22a7c9d7 | 7217 | { |
e472e1b4 | 7218 | enum nl80211_iftype nlmode; |
a2e40bb6 FF |
7219 | struct i802_bss *bss = priv; |
7220 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
22a7c9d7 | 7221 | int ifidx; |
2aec4f3c | 7222 | int added = 1; |
22a7c9d7 | 7223 | |
f3585c8a JM |
7224 | if (addr) |
7225 | os_memcpy(if_addr, addr, ETH_ALEN); | |
e472e1b4 AS |
7226 | nlmode = wpa_driver_nl80211_if_type(type); |
7227 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) { | |
f632e483 AS |
7228 | struct wdev_info p2pdev_info; |
7229 | ||
7230 | os_memset(&p2pdev_info, 0, sizeof(p2pdev_info)); | |
e472e1b4 | 7231 | ifidx = nl80211_create_iface(drv, ifname, nlmode, addr, |
f632e483 | 7232 | 0, nl80211_wdev_handler, |
2aec4f3c | 7233 | &p2pdev_info, use_existing); |
f632e483 | 7234 | if (!p2pdev_info.wdev_id_set || ifidx != 0) { |
e472e1b4 AS |
7235 | wpa_printf(MSG_ERROR, "nl80211: Failed to create a P2P Device interface %s", |
7236 | ifname); | |
e472e1b4 AS |
7237 | return -1; |
7238 | } | |
f632e483 AS |
7239 | |
7240 | drv->global->if_add_wdevid = p2pdev_info.wdev_id; | |
7241 | drv->global->if_add_wdevid_set = p2pdev_info.wdev_id_set; | |
7242 | if (!is_zero_ether_addr(p2pdev_info.macaddr)) | |
7243 | os_memcpy(if_addr, p2pdev_info.macaddr, ETH_ALEN); | |
7244 | wpa_printf(MSG_DEBUG, "nl80211: New P2P Device interface %s (0x%llx) created", | |
7245 | ifname, | |
7246 | (long long unsigned int) p2pdev_info.wdev_id); | |
e472e1b4 AS |
7247 | } else { |
7248 | ifidx = nl80211_create_iface(drv, ifname, nlmode, addr, | |
2aec4f3c JM |
7249 | 0, NULL, NULL, use_existing); |
7250 | if (use_existing && ifidx == -ENFILE) { | |
7251 | added = 0; | |
7252 | ifidx = if_nametoindex(ifname); | |
7253 | } else if (ifidx < 0) { | |
e472e1b4 AS |
7254 | return -1; |
7255 | } | |
22a7c9d7 JM |
7256 | } |
7257 | ||
ab7a1add | 7258 | if (!addr) { |
8ea8a89c | 7259 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) |
ab7a1add AS |
7260 | os_memcpy(if_addr, bss->addr, ETH_ALEN); |
7261 | else if (linux_get_ifhwaddr(drv->global->ioctl_sock, | |
8ea8a89c | 7262 | ifname, if_addr) < 0) { |
2aec4f3c JM |
7263 | if (added) |
7264 | nl80211_remove_iface(drv, ifidx); | |
ab7a1add AS |
7265 | return -1; |
7266 | } | |
c55f774d JM |
7267 | } |
7268 | ||
c55f774d JM |
7269 | if (!addr && |
7270 | (type == WPA_IF_P2P_CLIENT || type == WPA_IF_P2P_GROUP || | |
8ea8a89c JM |
7271 | type == WPA_IF_P2P_GO || type == WPA_IF_MESH || |
7272 | type == WPA_IF_STATION)) { | |
7273 | /* Enforce unique address */ | |
ab7a1add | 7274 | u8 new_addr[ETH_ALEN]; |
c55f774d | 7275 | |
ab7a1add | 7276 | if (linux_get_ifhwaddr(drv->global->ioctl_sock, ifname, |
c81eff1a | 7277 | new_addr) < 0) { |
ea39367c MK |
7278 | if (added) |
7279 | nl80211_remove_iface(drv, ifidx); | |
c55f774d JM |
7280 | return -1; |
7281 | } | |
f608081c | 7282 | if (nl80211_addr_in_use(drv->global, new_addr)) { |
c55f774d | 7283 | wpa_printf(MSG_DEBUG, "nl80211: Allocate new address " |
8ea8a89c | 7284 | "for interface %s type %d", ifname, type); |
5b78493f | 7285 | if (nl80211_vif_addr(drv, new_addr) < 0) { |
ea39367c MK |
7286 | if (added) |
7287 | nl80211_remove_iface(drv, ifidx); | |
c55f774d JM |
7288 | return -1; |
7289 | } | |
c81eff1a | 7290 | if (linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, |
c55f774d | 7291 | new_addr) < 0) { |
ea39367c MK |
7292 | if (added) |
7293 | nl80211_remove_iface(drv, ifidx); | |
c55f774d JM |
7294 | return -1; |
7295 | } | |
c55f774d | 7296 | } |
f67eeb5c | 7297 | os_memcpy(if_addr, new_addr, ETH_ALEN); |
c55f774d | 7298 | } |
f3585c8a | 7299 | |
d8a3b66d | 7300 | if (type == WPA_IF_AP_BSS && setup_ap) { |
f5eb9da3 JM |
7301 | struct i802_bss *new_bss = os_zalloc(sizeof(*new_bss)); |
7302 | if (new_bss == NULL) { | |
2aec4f3c JM |
7303 | if (added) |
7304 | nl80211_remove_iface(drv, ifidx); | |
f5eb9da3 JM |
7305 | return -1; |
7306 | } | |
7307 | ||
7308 | if (bridge && | |
7309 | i802_check_bridge(drv, new_bss, bridge, ifname) < 0) { | |
7310 | wpa_printf(MSG_ERROR, "nl80211: Failed to add the new " | |
7311 | "interface %s to a bridge %s", | |
7312 | ifname, bridge); | |
2aec4f3c JM |
7313 | if (added) |
7314 | nl80211_remove_iface(drv, ifidx); | |
f5eb9da3 JM |
7315 | os_free(new_bss); |
7316 | return -1; | |
7317 | } | |
7318 | ||
c81eff1a BG |
7319 | if (linux_set_iface_flags(drv->global->ioctl_sock, ifname, 1)) |
7320 | { | |
ea39367c MK |
7321 | if (added) |
7322 | nl80211_remove_iface(drv, ifidx); | |
07179987 | 7323 | os_free(new_bss); |
22a7c9d7 JM |
7324 | return -1; |
7325 | } | |
a2e40bb6 | 7326 | os_strlcpy(new_bss->ifname, ifname, IFNAMSIZ); |
341eebee | 7327 | os_memcpy(new_bss->addr, if_addr, ETH_ALEN); |
a2e40bb6 FF |
7328 | new_bss->ifindex = ifidx; |
7329 | new_bss->drv = drv; | |
834ee56f KP |
7330 | new_bss->next = drv->first_bss->next; |
7331 | new_bss->freq = drv->first_bss->freq; | |
a5e1eb20 | 7332 | new_bss->ctx = bss_ctx; |
2aec4f3c | 7333 | new_bss->added_if = added; |
834ee56f | 7334 | drv->first_bss->next = new_bss; |
a2e40bb6 FF |
7335 | if (drv_priv) |
7336 | *drv_priv = new_bss; | |
cc7a48d1 | 7337 | nl80211_init_bss(new_bss); |
3dd1d890 YAP |
7338 | |
7339 | /* Subscribe management frames for this WPA_IF_AP_BSS */ | |
7340 | if (nl80211_setup_ap(new_bss)) | |
7341 | return -1; | |
22a7c9d7 | 7342 | } |
22a7c9d7 | 7343 | |
ff6a158b JM |
7344 | if (drv->global) |
7345 | drv->global->if_add_ifindex = ifidx; | |
7346 | ||
d1bb7aed JJ |
7347 | /* |
7348 | * Some virtual interfaces need to process EAPOL packets and events on | |
7349 | * the parent interface. This is used mainly with hostapd. | |
7350 | */ | |
7351 | if (ifidx > 0 && | |
7352 | (drv->hostapd || | |
7353 | nlmode == NL80211_IFTYPE_AP_VLAN || | |
7354 | nlmode == NL80211_IFTYPE_WDS || | |
7355 | nlmode == NL80211_IFTYPE_MONITOR)) | |
732b1d20 | 7356 | add_ifidx(drv, ifidx, IFIDX_ANY); |
b36935be | 7357 | |
22a7c9d7 JM |
7358 | return 0; |
7359 | } | |
7360 | ||
7361 | ||
9ebce9c5 | 7362 | static int wpa_driver_nl80211_if_remove(struct i802_bss *bss, |
22a7c9d7 JM |
7363 | enum wpa_driver_if_type type, |
7364 | const char *ifname) | |
7365 | { | |
a2e40bb6 | 7366 | struct wpa_driver_nl80211_data *drv = bss->drv; |
22a7c9d7 JM |
7367 | int ifindex = if_nametoindex(ifname); |
7368 | ||
2aec4f3c JM |
7369 | wpa_printf(MSG_DEBUG, "nl80211: %s(type=%d ifname=%s) ifindex=%d added_if=%d", |
7370 | __func__, type, ifname, ifindex, bss->added_if); | |
158b090c | 7371 | if (ifindex > 0 && (bss->added_if || bss->ifindex != ifindex)) |
2b72df63 | 7372 | nl80211_remove_iface(drv, ifindex); |
de884303 JM |
7373 | else if (ifindex > 0 && !bss->added_if) { |
7374 | struct wpa_driver_nl80211_data *drv2; | |
7375 | dl_list_for_each(drv2, &drv->global->interfaces, | |
732b1d20 MB |
7376 | struct wpa_driver_nl80211_data, list) { |
7377 | del_ifidx(drv2, ifindex, IFIDX_ANY); | |
7378 | del_ifidx(drv2, IFIDX_ANY, ifindex); | |
7379 | } | |
de884303 | 7380 | } |
c34e618d | 7381 | |
c34e618d FF |
7382 | if (type != WPA_IF_AP_BSS) |
7383 | return 0; | |
7384 | ||
e17a2477 | 7385 | if (bss->added_if_into_bridge) { |
c81eff1a BG |
7386 | if (linux_br_del_if(drv->global->ioctl_sock, bss->brname, |
7387 | bss->ifname) < 0) | |
e17a2477 JM |
7388 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
7389 | "interface %s from bridge %s: %s", | |
7390 | bss->ifname, bss->brname, strerror(errno)); | |
7391 | } | |
7392 | if (bss->added_bridge) { | |
c81eff1a | 7393 | if (linux_br_del(drv->global->ioctl_sock, bss->brname) < 0) |
e17a2477 JM |
7394 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
7395 | "bridge %s: %s", | |
7396 | bss->brname, strerror(errno)); | |
7397 | } | |
a2e40bb6 | 7398 | |
834ee56f | 7399 | if (bss != drv->first_bss) { |
8546ea19 | 7400 | struct i802_bss *tbss; |
a2e40bb6 | 7401 | |
2aec4f3c | 7402 | wpa_printf(MSG_DEBUG, "nl80211: Not the first BSS - remove it"); |
834ee56f | 7403 | for (tbss = drv->first_bss; tbss; tbss = tbss->next) { |
8546ea19 JM |
7404 | if (tbss->next == bss) { |
7405 | tbss->next = bss->next; | |
3dd1d890 YAP |
7406 | /* Unsubscribe management frames */ |
7407 | nl80211_teardown_ap(bss); | |
cc7a48d1 | 7408 | nl80211_destroy_bss(bss); |
5c9da160 MB |
7409 | if (!bss->added_if) |
7410 | i802_set_iface_flags(bss, 0); | |
8546ea19 JM |
7411 | os_free(bss); |
7412 | bss = NULL; | |
7413 | break; | |
7414 | } | |
22a7c9d7 | 7415 | } |
8546ea19 JM |
7416 | if (bss) |
7417 | wpa_printf(MSG_INFO, "nl80211: %s - could not find " | |
7418 | "BSS %p in the list", __func__, bss); | |
390e489c | 7419 | } else { |
2aec4f3c | 7420 | wpa_printf(MSG_DEBUG, "nl80211: First BSS - reassign context"); |
390e489c | 7421 | nl80211_teardown_ap(bss); |
2aec4f3c | 7422 | if (!bss->added_if && !drv->first_bss->next) |
a70cd0db | 7423 | wpa_driver_nl80211_del_beacon(bss); |
390e489c | 7424 | nl80211_destroy_bss(bss); |
2aec4f3c JM |
7425 | if (!bss->added_if) |
7426 | i802_set_iface_flags(bss, 0); | |
390e489c KP |
7427 | if (drv->first_bss->next) { |
7428 | drv->first_bss = drv->first_bss->next; | |
7429 | drv->ctx = drv->first_bss->ctx; | |
7430 | os_free(bss); | |
7431 | } else { | |
7432 | wpa_printf(MSG_DEBUG, "nl80211: No second BSS to reassign context to"); | |
7433 | } | |
22a7c9d7 | 7434 | } |
22a7c9d7 JM |
7435 | |
7436 | return 0; | |
7437 | } | |
7438 | ||
7439 | ||
55777702 JM |
7440 | static int cookie_handler(struct nl_msg *msg, void *arg) |
7441 | { | |
7442 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
7443 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
7444 | u64 *cookie = arg; | |
7445 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
7446 | genlmsg_attrlen(gnlh, 0), NULL); | |
7447 | if (tb[NL80211_ATTR_COOKIE]) | |
7448 | *cookie = nla_get_u64(tb[NL80211_ATTR_COOKIE]); | |
7449 | return NL_SKIP; | |
7450 | } | |
7451 | ||
7452 | ||
88df0ef7 | 7453 | static int nl80211_send_frame_cmd(struct i802_bss *bss, |
5dfca53f JB |
7454 | unsigned int freq, unsigned int wait, |
7455 | const u8 *buf, size_t buf_len, | |
5ad372cc | 7456 | int save_cookie, int no_cck, int no_ack, |
2d3943ce AO |
7457 | int offchanok, const u16 *csa_offs, |
7458 | size_t csa_offs_len) | |
9884f9cc | 7459 | { |
88df0ef7 | 7460 | struct wpa_driver_nl80211_data *drv = bss->drv; |
9884f9cc JB |
7461 | struct nl_msg *msg; |
7462 | u64 cookie; | |
7463 | int ret = -1; | |
7464 | ||
cc2ada86 | 7465 | wpa_printf(MSG_MSGDUMP, "nl80211: CMD_FRAME freq=%u wait=%u no_cck=%d " |
2e3e4566 JM |
7466 | "no_ack=%d offchanok=%d", |
7467 | freq, wait, no_cck, no_ack, offchanok); | |
c91f796f | 7468 | wpa_hexdump(MSG_MSGDUMP, "CMD_FRAME", buf, buf_len); |
9884f9cc | 7469 | |
56f77852 | 7470 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_FRAME)) || |
a862e4a3 JM |
7471 | (freq && nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || |
7472 | (wait && nla_put_u32(msg, NL80211_ATTR_DURATION, wait)) || | |
7473 | (offchanok && ((drv->capa.flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX) || | |
7474 | drv->test_use_roc_tx) && | |
7475 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) || | |
7476 | (no_cck && nla_put_flag(msg, NL80211_ATTR_TX_NO_CCK_RATE)) || | |
7477 | (no_ack && nla_put_flag(msg, NL80211_ATTR_DONT_WAIT_FOR_ACK)) || | |
2d3943ce AO |
7478 | (csa_offs && nla_put(msg, NL80211_ATTR_CSA_C_OFFSETS_TX, |
7479 | csa_offs_len * sizeof(u16), csa_offs)) || | |
a862e4a3 JM |
7480 | nla_put(msg, NL80211_ATTR_FRAME, buf_len, buf)) |
7481 | goto fail; | |
9884f9cc JB |
7482 | |
7483 | cookie = 0; | |
7484 | ret = send_and_recv_msgs(drv, msg, cookie_handler, &cookie); | |
7485 | msg = NULL; | |
7486 | if (ret) { | |
7487 | wpa_printf(MSG_DEBUG, "nl80211: Frame command failed: ret=%d " | |
a05225c8 JM |
7488 | "(%s) (freq=%u wait=%u)", ret, strerror(-ret), |
7489 | freq, wait); | |
a862e4a3 JM |
7490 | } else { |
7491 | wpa_printf(MSG_MSGDUMP, "nl80211: Frame TX command accepted%s; " | |
7492 | "cookie 0x%llx", no_ack ? " (no ACK)" : "", | |
7493 | (long long unsigned int) cookie); | |
9884f9cc | 7494 | |
5ad372cc | 7495 | if (save_cookie) |
81ae8820 | 7496 | drv->send_frame_cookie = no_ack ? (u64) -1 : cookie; |
759a8a3a | 7497 | |
81ae8820 | 7498 | if (drv->num_send_frame_cookies == MAX_SEND_FRAME_COOKIES) { |
759a8a3a | 7499 | wpa_printf(MSG_DEBUG, |
81ae8820 | 7500 | "nl80211: Drop oldest pending send frame cookie 0x%llx", |
759a8a3a | 7501 | (long long unsigned int) |
81ae8820 JM |
7502 | drv->send_frame_cookies[0]); |
7503 | os_memmove(&drv->send_frame_cookies[0], | |
7504 | &drv->send_frame_cookies[1], | |
7505 | (MAX_SEND_FRAME_COOKIES - 1) * | |
759a8a3a | 7506 | sizeof(u64)); |
81ae8820 | 7507 | drv->num_send_frame_cookies--; |
759a8a3a | 7508 | } |
81ae8820 JM |
7509 | drv->send_frame_cookies[drv->num_send_frame_cookies] = cookie; |
7510 | drv->num_send_frame_cookies++; | |
a862e4a3 | 7511 | } |
9884f9cc | 7512 | |
a862e4a3 | 7513 | fail: |
9884f9cc JB |
7514 | nlmsg_free(msg); |
7515 | return ret; | |
7516 | } | |
7517 | ||
7518 | ||
9ebce9c5 JM |
7519 | static int wpa_driver_nl80211_send_action(struct i802_bss *bss, |
7520 | unsigned int freq, | |
190b9062 | 7521 | unsigned int wait_time, |
58f6fbe0 JM |
7522 | const u8 *dst, const u8 *src, |
7523 | const u8 *bssid, | |
b106173a JM |
7524 | const u8 *data, size_t data_len, |
7525 | int no_cck) | |
58f6fbe0 | 7526 | { |
a2e40bb6 | 7527 | struct wpa_driver_nl80211_data *drv = bss->drv; |
58f6fbe0 | 7528 | int ret = -1; |
58f6fbe0 JM |
7529 | u8 *buf; |
7530 | struct ieee80211_hdr *hdr; | |
ff774311 BG |
7531 | int offchanok = 1; |
7532 | ||
7533 | if (is_ap_interface(drv->nlmode) && (int) freq == bss->freq) | |
7534 | offchanok = 0; | |
58f6fbe0 | 7535 | |
5dfca53f | 7536 | wpa_printf(MSG_DEBUG, "nl80211: Send Action frame (ifindex=%d, " |
ff774311 BG |
7537 | "freq=%u MHz wait=%d ms no_cck=%d offchanok=%d)", |
7538 | drv->ifindex, freq, wait_time, no_cck, offchanok); | |
58f6fbe0 JM |
7539 | |
7540 | buf = os_zalloc(24 + data_len); | |
7541 | if (buf == NULL) | |
7542 | return ret; | |
7543 | os_memcpy(buf + 24, data, data_len); | |
7544 | hdr = (struct ieee80211_hdr *) buf; | |
7545 | hdr->frame_control = | |
7546 | IEEE80211_FC(WLAN_FC_TYPE_MGMT, WLAN_FC_STYPE_ACTION); | |
7547 | os_memcpy(hdr->addr1, dst, ETH_ALEN); | |
7548 | os_memcpy(hdr->addr2, src, ETH_ALEN); | |
7549 | os_memcpy(hdr->addr3, bssid, ETH_ALEN); | |
7550 | ||
8331c9b3 VK |
7551 | if (os_memcmp(bss->addr, src, ETH_ALEN) != 0) { |
7552 | wpa_printf(MSG_DEBUG, "nl80211: Use random TA " MACSTR, | |
7553 | MAC2STR(src)); | |
7554 | os_memcpy(bss->rand_addr, src, ETH_ALEN); | |
7555 | } else { | |
7556 | os_memset(bss->rand_addr, 0, ETH_ALEN); | |
7557 | } | |
7558 | ||
f78f2785 JM |
7559 | if (is_ap_interface(drv->nlmode) && |
7560 | (!(drv->capa.flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX) || | |
7561 | (int) freq == bss->freq || drv->device_ap_sme || | |
7562 | !drv->use_monitor)) | |
9ebce9c5 | 7563 | ret = wpa_driver_nl80211_send_mlme(bss, buf, 24 + data_len, |
ff774311 | 7564 | 0, freq, no_cck, offchanok, |
27cc06d0 | 7565 | wait_time, NULL, 0, 0); |
9884f9cc | 7566 | else |
88df0ef7 | 7567 | ret = nl80211_send_frame_cmd(bss, freq, wait_time, buf, |
5dfca53f | 7568 | 24 + data_len, |
ff774311 | 7569 | 1, no_cck, 0, offchanok, NULL, 0); |
58f6fbe0 | 7570 | |
f8bf1421 | 7571 | os_free(buf); |
58f6fbe0 JM |
7572 | return ret; |
7573 | } | |
7574 | ||
7575 | ||
759a8a3a | 7576 | static void nl80211_frame_wait_cancel(struct i802_bss *bss, u64 cookie) |
5dfca53f | 7577 | { |
5dfca53f JB |
7578 | struct wpa_driver_nl80211_data *drv = bss->drv; |
7579 | struct nl_msg *msg; | |
7580 | int ret; | |
7581 | ||
316a9e4d | 7582 | wpa_printf(MSG_DEBUG, "nl80211: Cancel TX frame wait: cookie=0x%llx", |
759a8a3a | 7583 | (long long unsigned int) cookie); |
56f77852 | 7584 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_FRAME_WAIT_CANCEL)) || |
759a8a3a | 7585 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) { |
a862e4a3 JM |
7586 | nlmsg_free(msg); |
7587 | return; | |
7588 | } | |
5dfca53f JB |
7589 | |
7590 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
5dfca53f JB |
7591 | if (ret) |
7592 | wpa_printf(MSG_DEBUG, "nl80211: wait cancel failed: ret=%d " | |
7593 | "(%s)", ret, strerror(-ret)); | |
5dfca53f JB |
7594 | } |
7595 | ||
7596 | ||
759a8a3a JM |
7597 | static void wpa_driver_nl80211_send_action_cancel_wait(void *priv) |
7598 | { | |
7599 | struct i802_bss *bss = priv; | |
7600 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
7601 | unsigned int i; | |
7602 | u64 cookie; | |
7603 | ||
7604 | /* Cancel the last pending TX cookie */ | |
81ae8820 | 7605 | nl80211_frame_wait_cancel(bss, drv->send_frame_cookie); |
759a8a3a JM |
7606 | |
7607 | /* | |
7608 | * Cancel the other pending TX cookies, if any. This is needed since | |
7609 | * the driver may keep a list of all pending offchannel TX operations | |
7610 | * and free up the radio only once they have expired or cancelled. | |
7611 | */ | |
81ae8820 JM |
7612 | for (i = drv->num_send_frame_cookies; i > 0; i--) { |
7613 | cookie = drv->send_frame_cookies[i - 1]; | |
7614 | if (cookie != drv->send_frame_cookie) | |
759a8a3a JM |
7615 | nl80211_frame_wait_cancel(bss, cookie); |
7616 | } | |
81ae8820 | 7617 | drv->num_send_frame_cookies = 0; |
759a8a3a JM |
7618 | } |
7619 | ||
7620 | ||
55777702 JM |
7621 | static int wpa_driver_nl80211_remain_on_channel(void *priv, unsigned int freq, |
7622 | unsigned int duration) | |
7623 | { | |
a2e40bb6 FF |
7624 | struct i802_bss *bss = priv; |
7625 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
55777702 JM |
7626 | struct nl_msg *msg; |
7627 | int ret; | |
7628 | u64 cookie; | |
7629 | ||
56f77852 | 7630 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_REMAIN_ON_CHANNEL)) || |
a862e4a3 JM |
7631 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
7632 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) { | |
7633 | nlmsg_free(msg); | |
7634 | return -1; | |
7635 | } | |
55777702 JM |
7636 | |
7637 | cookie = 0; | |
7638 | ret = send_and_recv_msgs(drv, msg, cookie_handler, &cookie); | |
7639 | if (ret == 0) { | |
7640 | wpa_printf(MSG_DEBUG, "nl80211: Remain-on-channel cookie " | |
7641 | "0x%llx for freq=%u MHz duration=%u", | |
7642 | (long long unsigned int) cookie, freq, duration); | |
7643 | drv->remain_on_chan_cookie = cookie; | |
531f0331 | 7644 | drv->pending_remain_on_chan = 1; |
55777702 JM |
7645 | return 0; |
7646 | } | |
7647 | wpa_printf(MSG_DEBUG, "nl80211: Failed to request remain-on-channel " | |
15ed5535 JM |
7648 | "(freq=%d duration=%u): %d (%s)", |
7649 | freq, duration, ret, strerror(-ret)); | |
55777702 JM |
7650 | return -1; |
7651 | } | |
7652 | ||
7653 | ||
7654 | static int wpa_driver_nl80211_cancel_remain_on_channel(void *priv) | |
7655 | { | |
a2e40bb6 FF |
7656 | struct i802_bss *bss = priv; |
7657 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
55777702 JM |
7658 | struct nl_msg *msg; |
7659 | int ret; | |
7660 | ||
7661 | if (!drv->pending_remain_on_chan) { | |
7662 | wpa_printf(MSG_DEBUG, "nl80211: No pending remain-on-channel " | |
7663 | "to cancel"); | |
7664 | return -1; | |
7665 | } | |
7666 | ||
7667 | wpa_printf(MSG_DEBUG, "nl80211: Cancel remain-on-channel with cookie " | |
7668 | "0x%llx", | |
7669 | (long long unsigned int) drv->remain_on_chan_cookie); | |
7670 | ||
56f77852 JM |
7671 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL); |
7672 | if (!msg || | |
a862e4a3 JM |
7673 | nla_put_u64(msg, NL80211_ATTR_COOKIE, drv->remain_on_chan_cookie)) { |
7674 | nlmsg_free(msg); | |
7675 | return -1; | |
7676 | } | |
55777702 JM |
7677 | |
7678 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
7679 | if (ret == 0) | |
7680 | return 0; | |
7681 | wpa_printf(MSG_DEBUG, "nl80211: Failed to cancel remain-on-channel: " | |
7682 | "%d (%s)", ret, strerror(-ret)); | |
55777702 JM |
7683 | return -1; |
7684 | } | |
7685 | ||
7686 | ||
9ebce9c5 | 7687 | static int wpa_driver_nl80211_probe_req_report(struct i802_bss *bss, int report) |
504e905c | 7688 | { |
a2e40bb6 | 7689 | struct wpa_driver_nl80211_data *drv = bss->drv; |
504e905c | 7690 | |
5582a5d1 | 7691 | if (!report) { |
0d891981 | 7692 | if (bss->nl_preq && drv->device_ap_sme && |
b8d87ed2 AP |
7693 | is_ap_interface(drv->nlmode) && !bss->in_deinit && |
7694 | !bss->static_ap) { | |
0d891981 JM |
7695 | /* |
7696 | * Do not disable Probe Request reporting that was | |
7697 | * enabled in nl80211_setup_ap(). | |
7698 | */ | |
7699 | wpa_printf(MSG_DEBUG, "nl80211: Skip disabling of " | |
7700 | "Probe Request reporting nl_preq=%p while " | |
7701 | "in AP mode", bss->nl_preq); | |
7702 | } else if (bss->nl_preq) { | |
36488c05 JM |
7703 | wpa_printf(MSG_DEBUG, "nl80211: Disable Probe Request " |
7704 | "reporting nl_preq=%p", bss->nl_preq); | |
40a68f33 | 7705 | nl80211_destroy_eloop_handle(&bss->nl_preq, 0); |
5582a5d1 JB |
7706 | } |
7707 | return 0; | |
7708 | } | |
7709 | ||
481234cf | 7710 | if (bss->nl_preq) { |
5582a5d1 | 7711 | wpa_printf(MSG_DEBUG, "nl80211: Probe Request reporting " |
36488c05 | 7712 | "already on! nl_preq=%p", bss->nl_preq); |
5582a5d1 JB |
7713 | return 0; |
7714 | } | |
7715 | ||
481234cf JM |
7716 | bss->nl_preq = nl_create_handle(drv->global->nl_cb, "preq"); |
7717 | if (bss->nl_preq == NULL) | |
5582a5d1 | 7718 | return -1; |
36488c05 JM |
7719 | wpa_printf(MSG_DEBUG, "nl80211: Enable Probe Request " |
7720 | "reporting nl_preq=%p", bss->nl_preq); | |
5582a5d1 | 7721 | |
481234cf | 7722 | if (nl80211_register_frame(bss, bss->nl_preq, |
5582a5d1 JB |
7723 | (WLAN_FC_TYPE_MGMT << 2) | |
7724 | (WLAN_FC_STYPE_PROBE_REQ << 4), | |
a92dfde8 JB |
7725 | NULL, 0) < 0) |
7726 | goto out_err; | |
5582a5d1 | 7727 | |
5f65e9f7 JB |
7728 | nl80211_register_eloop_read(&bss->nl_preq, |
7729 | wpa_driver_nl80211_event_receive, | |
40a68f33 | 7730 | bss->nl_cb, 0); |
5582a5d1 | 7731 | |
504e905c | 7732 | return 0; |
5582a5d1 | 7733 | |
a92dfde8 | 7734 | out_err: |
221a59c9 | 7735 | nl_destroy_handles(&bss->nl_preq); |
5582a5d1 | 7736 | return -1; |
504e905c JM |
7737 | } |
7738 | ||
7739 | ||
4e5cb1a3 JM |
7740 | static int nl80211_disable_11b_rates(struct wpa_driver_nl80211_data *drv, |
7741 | int ifindex, int disabled) | |
7742 | { | |
7743 | struct nl_msg *msg; | |
7744 | struct nlattr *bands, *band; | |
7745 | int ret; | |
7746 | ||
3e208481 JM |
7747 | wpa_printf(MSG_DEBUG, |
7748 | "nl80211: NL80211_CMD_SET_TX_BITRATE_MASK (ifindex=%d %s)", | |
7749 | ifindex, disabled ? "NL80211_TXRATE_LEGACY=OFDM-only" : | |
7750 | "no NL80211_TXRATE_LEGACY constraint"); | |
7751 | ||
95376e1a JM |
7752 | msg = nl80211_ifindex_msg(drv, ifindex, 0, |
7753 | NL80211_CMD_SET_TX_BITRATE_MASK); | |
4e5cb1a3 JM |
7754 | if (!msg) |
7755 | return -1; | |
7756 | ||
4e5cb1a3 JM |
7757 | bands = nla_nest_start(msg, NL80211_ATTR_TX_RATES); |
7758 | if (!bands) | |
a862e4a3 | 7759 | goto fail; |
4e5cb1a3 JM |
7760 | |
7761 | /* | |
7762 | * Disable 2 GHz rates 1, 2, 5.5, 11 Mbps by masking out everything | |
7763 | * else apart from 6, 9, 12, 18, 24, 36, 48, 54 Mbps from non-MCS | |
7764 | * rates. All 5 GHz rates are left enabled. | |
7765 | */ | |
7766 | band = nla_nest_start(msg, NL80211_BAND_2GHZ); | |
a862e4a3 JM |
7767 | if (!band || |
7768 | (disabled && nla_put(msg, NL80211_TXRATE_LEGACY, 8, | |
7769 | "\x0c\x12\x18\x24\x30\x48\x60\x6c"))) | |
7770 | goto fail; | |
4e5cb1a3 JM |
7771 | nla_nest_end(msg, band); |
7772 | ||
7773 | nla_nest_end(msg, bands); | |
7774 | ||
7775 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
4e5cb1a3 JM |
7776 | if (ret) { |
7777 | wpa_printf(MSG_DEBUG, "nl80211: Set TX rates failed: ret=%d " | |
7778 | "(%s)", ret, strerror(-ret)); | |
1d0c6fb1 JM |
7779 | } else |
7780 | drv->disabled_11b_rates = disabled; | |
4e5cb1a3 JM |
7781 | |
7782 | return ret; | |
7783 | ||
a862e4a3 | 7784 | fail: |
4e5cb1a3 JM |
7785 | nlmsg_free(msg); |
7786 | return -1; | |
7787 | } | |
7788 | ||
7789 | ||
af473088 JM |
7790 | static int wpa_driver_nl80211_deinit_ap(void *priv) |
7791 | { | |
a2e40bb6 FF |
7792 | struct i802_bss *bss = priv; |
7793 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
b1f625e0 | 7794 | if (!is_ap_interface(drv->nlmode)) |
af473088 | 7795 | return -1; |
a70cd0db | 7796 | wpa_driver_nl80211_del_beacon(bss); |
9bc5cfa3 | 7797 | bss->beacon_set = 0; |
60b13c20 IP |
7798 | |
7799 | /* | |
7800 | * If the P2P GO interface was dynamically added, then it is | |
7801 | * possible that the interface change to station is not possible. | |
7802 | */ | |
7803 | if (drv->nlmode == NL80211_IFTYPE_P2P_GO && bss->if_dynamic) | |
7804 | return 0; | |
7805 | ||
b1f625e0 | 7806 | return wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_STATION); |
af473088 JM |
7807 | } |
7808 | ||
7809 | ||
695c7038 SW |
7810 | static int wpa_driver_nl80211_stop_ap(void *priv) |
7811 | { | |
7812 | struct i802_bss *bss = priv; | |
7813 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
7814 | if (!is_ap_interface(drv->nlmode)) | |
7815 | return -1; | |
a70cd0db | 7816 | wpa_driver_nl80211_del_beacon(bss); |
695c7038 SW |
7817 | bss->beacon_set = 0; |
7818 | return 0; | |
7819 | } | |
7820 | ||
7821 | ||
3c29244e EP |
7822 | static int wpa_driver_nl80211_deinit_p2p_cli(void *priv) |
7823 | { | |
7824 | struct i802_bss *bss = priv; | |
7825 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
7826 | if (drv->nlmode != NL80211_IFTYPE_P2P_CLIENT) | |
7827 | return -1; | |
60b13c20 IP |
7828 | |
7829 | /* | |
7830 | * If the P2P Client interface was dynamically added, then it is | |
7831 | * possible that the interface change to station is not possible. | |
7832 | */ | |
7833 | if (bss->if_dynamic) | |
7834 | return 0; | |
7835 | ||
3c29244e EP |
7836 | return wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_STATION); |
7837 | } | |
7838 | ||
7839 | ||
207ef3fb JM |
7840 | static void wpa_driver_nl80211_resume(void *priv) |
7841 | { | |
a2e40bb6 | 7842 | struct i802_bss *bss = priv; |
e8dc205f | 7843 | enum nl80211_iftype nlmode = nl80211_get_ifmode(bss); |
91724d6f AS |
7844 | |
7845 | if (i802_set_iface_flags(bss, 1)) | |
7846 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set interface up on resume event"); | |
e8dc205f AO |
7847 | |
7848 | if (is_p2p_net_interface(nlmode)) | |
7849 | nl80211_disable_11b_rates(bss->drv, bss->drv->ifindex, 1); | |
207ef3fb JM |
7850 | } |
7851 | ||
7852 | ||
b625473c JM |
7853 | static int nl80211_signal_monitor(void *priv, int threshold, int hysteresis) |
7854 | { | |
7855 | struct i802_bss *bss = priv; | |
7856 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8970bae8 JB |
7857 | struct nl_msg *msg; |
7858 | struct nlattr *cqm; | |
b625473c JM |
7859 | |
7860 | wpa_printf(MSG_DEBUG, "nl80211: Signal monitor threshold=%d " | |
7861 | "hysteresis=%d", threshold, hysteresis); | |
7862 | ||
13f83980 | 7863 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_CQM)) || |
a862e4a3 JM |
7864 | !(cqm = nla_nest_start(msg, NL80211_ATTR_CQM)) || |
7865 | nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THOLD, threshold) || | |
7866 | nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_HYST, hysteresis)) { | |
7867 | nlmsg_free(msg); | |
7868 | return -1; | |
7869 | } | |
8970bae8 | 7870 | nla_nest_end(msg, cqm); |
21270bb4 | 7871 | |
a862e4a3 | 7872 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
b625473c JM |
7873 | } |
7874 | ||
7875 | ||
2cc8d8f4 AO |
7876 | static int get_channel_width(struct nl_msg *msg, void *arg) |
7877 | { | |
7878 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
7879 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
7880 | struct wpa_signal_info *sig_change = arg; | |
7881 | ||
7882 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
7883 | genlmsg_attrlen(gnlh, 0), NULL); | |
7884 | ||
7885 | sig_change->center_frq1 = -1; | |
7886 | sig_change->center_frq2 = -1; | |
7887 | sig_change->chanwidth = CHAN_WIDTH_UNKNOWN; | |
7888 | ||
7889 | if (tb[NL80211_ATTR_CHANNEL_WIDTH]) { | |
7890 | sig_change->chanwidth = convert2width( | |
7891 | nla_get_u32(tb[NL80211_ATTR_CHANNEL_WIDTH])); | |
7892 | if (tb[NL80211_ATTR_CENTER_FREQ1]) | |
7893 | sig_change->center_frq1 = | |
7894 | nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ1]); | |
7895 | if (tb[NL80211_ATTR_CENTER_FREQ2]) | |
7896 | sig_change->center_frq2 = | |
7897 | nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ2]); | |
7898 | } | |
7899 | ||
7900 | return NL_SKIP; | |
7901 | } | |
7902 | ||
7903 | ||
7904 | static int nl80211_get_channel_width(struct wpa_driver_nl80211_data *drv, | |
7905 | struct wpa_signal_info *sig) | |
7906 | { | |
7907 | struct nl_msg *msg; | |
7908 | ||
9725b784 | 7909 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_GET_INTERFACE); |
2cc8d8f4 | 7910 | return send_and_recv_msgs(drv, msg, get_channel_width, sig); |
2cc8d8f4 AO |
7911 | } |
7912 | ||
7913 | ||
1c5c7273 PS |
7914 | static int nl80211_signal_poll(void *priv, struct wpa_signal_info *si) |
7915 | { | |
7916 | struct i802_bss *bss = priv; | |
7917 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
7918 | int res; | |
7919 | ||
7920 | os_memset(si, 0, sizeof(*si)); | |
7921 | res = nl80211_get_link_signal(drv, si); | |
1d6955e6 JM |
7922 | if (res) { |
7923 | if (drv->nlmode != NL80211_IFTYPE_ADHOC && | |
7924 | drv->nlmode != NL80211_IFTYPE_MESH_POINT) | |
7925 | return res; | |
7926 | si->current_signal = 0; | |
7927 | } | |
1c5c7273 | 7928 | |
2cc8d8f4 AO |
7929 | res = nl80211_get_channel_width(drv, si); |
7930 | if (res != 0) | |
7931 | return res; | |
7932 | ||
1c5c7273 PS |
7933 | return nl80211_get_link_noise(drv, si); |
7934 | } | |
7935 | ||
7936 | ||
c55f774d JM |
7937 | static int nl80211_set_param(void *priv, const char *param) |
7938 | { | |
ef24ad3e JM |
7939 | struct i802_bss *bss = priv; |
7940 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
7941 | ||
c55f774d JM |
7942 | if (param == NULL) |
7943 | return 0; | |
99a94f55 | 7944 | wpa_printf(MSG_DEBUG, "nl80211: driver param='%s'", param); |
c55f774d JM |
7945 | |
7946 | #ifdef CONFIG_P2P | |
7947 | if (os_strstr(param, "use_p2p_group_interface=1")) { | |
7948 | wpa_printf(MSG_DEBUG, "nl80211: Use separate P2P group " | |
7949 | "interface"); | |
7950 | drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_CONCURRENT; | |
7951 | drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_MGMT_AND_NON_P2P; | |
7952 | } | |
7953 | #endif /* CONFIG_P2P */ | |
7954 | ||
ef24ad3e | 7955 | if (os_strstr(param, "use_monitor=1")) |
327b01d3 | 7956 | drv->use_monitor = 1; |
327b01d3 JM |
7957 | |
7958 | if (os_strstr(param, "force_connect_cmd=1")) { | |
327b01d3 | 7959 | drv->capa.flags &= ~WPA_DRIVER_FLAGS_SME; |
b497a212 | 7960 | drv->force_connect_cmd = 1; |
327b01d3 JM |
7961 | } |
7962 | ||
ef24ad3e | 7963 | if (os_strstr(param, "force_bss_selection=1")) |
4d584d8c | 7964 | drv->capa.flags |= WPA_DRIVER_FLAGS_BSS_SELECTION; |
4d584d8c | 7965 | |
64abb725 | 7966 | if (os_strstr(param, "no_offchannel_tx=1")) { |
64abb725 JM |
7967 | drv->capa.flags &= ~WPA_DRIVER_FLAGS_OFFCHANNEL_TX; |
7968 | drv->test_use_roc_tx = 1; | |
7969 | } | |
7970 | ||
c55f774d JM |
7971 | return 0; |
7972 | } | |
7973 | ||
7974 | ||
45e3fc72 | 7975 | static void * nl80211_global_init(void *ctx) |
f2ed8023 JM |
7976 | { |
7977 | struct nl80211_global *global; | |
36d84860 BG |
7978 | struct netlink_config *cfg; |
7979 | ||
f2ed8023 JM |
7980 | global = os_zalloc(sizeof(*global)); |
7981 | if (global == NULL) | |
7982 | return NULL; | |
45e3fc72 | 7983 | global->ctx = ctx; |
c81eff1a | 7984 | global->ioctl_sock = -1; |
f2ed8023 | 7985 | dl_list_init(&global->interfaces); |
ff6a158b | 7986 | global->if_add_ifindex = -1; |
36d84860 BG |
7987 | |
7988 | cfg = os_zalloc(sizeof(*cfg)); | |
7989 | if (cfg == NULL) | |
7990 | goto err; | |
7991 | ||
7992 | cfg->ctx = global; | |
7993 | cfg->newlink_cb = wpa_driver_nl80211_event_rtm_newlink; | |
7994 | cfg->dellink_cb = wpa_driver_nl80211_event_rtm_dellink; | |
7995 | global->netlink = netlink_init(cfg); | |
7996 | if (global->netlink == NULL) { | |
7997 | os_free(cfg); | |
7998 | goto err; | |
7999 | } | |
8000 | ||
2a7b66f5 BG |
8001 | if (wpa_driver_nl80211_init_nl_global(global) < 0) |
8002 | goto err; | |
8003 | ||
c81eff1a BG |
8004 | global->ioctl_sock = socket(PF_INET, SOCK_DGRAM, 0); |
8005 | if (global->ioctl_sock < 0) { | |
7ac3616d JM |
8006 | wpa_printf(MSG_ERROR, "nl80211: socket(PF_INET,SOCK_DGRAM) failed: %s", |
8007 | strerror(errno)); | |
c81eff1a BG |
8008 | goto err; |
8009 | } | |
8010 | ||
f2ed8023 | 8011 | return global; |
36d84860 BG |
8012 | |
8013 | err: | |
8014 | nl80211_global_deinit(global); | |
8015 | return NULL; | |
f2ed8023 JM |
8016 | } |
8017 | ||
8018 | ||
8019 | static void nl80211_global_deinit(void *priv) | |
8020 | { | |
8021 | struct nl80211_global *global = priv; | |
8022 | if (global == NULL) | |
8023 | return; | |
8024 | if (!dl_list_empty(&global->interfaces)) { | |
8025 | wpa_printf(MSG_ERROR, "nl80211: %u interface(s) remain at " | |
8026 | "nl80211_global_deinit", | |
8027 | dl_list_len(&global->interfaces)); | |
8028 | } | |
36d84860 BG |
8029 | |
8030 | if (global->netlink) | |
8031 | netlink_deinit(global->netlink); | |
8032 | ||
276e2d67 BG |
8033 | nl_destroy_handles(&global->nl); |
8034 | ||
5f65e9f7 | 8035 | if (global->nl_event) |
40a68f33 | 8036 | nl80211_destroy_eloop_handle(&global->nl_event, 0); |
d6c9aab8 JB |
8037 | |
8038 | nl_cb_put(global->nl_cb); | |
2a7b66f5 | 8039 | |
c81eff1a BG |
8040 | if (global->ioctl_sock >= 0) |
8041 | close(global->ioctl_sock); | |
8042 | ||
f2ed8023 JM |
8043 | os_free(global); |
8044 | } | |
8045 | ||
8046 | ||
6859f1cb BG |
8047 | static const char * nl80211_get_radio_name(void *priv) |
8048 | { | |
8049 | struct i802_bss *bss = priv; | |
8050 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8051 | return drv->phyname; | |
8052 | } | |
8053 | ||
8054 | ||
061a3d3d VK |
8055 | static int nl80211_pmkid(struct i802_bss *bss, int cmd, |
8056 | struct wpa_pmkid_params *params) | |
a6efc65d JM |
8057 | { |
8058 | struct nl_msg *msg; | |
0887215d | 8059 | const size_t PMK_MAX_LEN = 48; /* current cfg80211 limit */ |
a6efc65d | 8060 | |
13f83980 | 8061 | if (!(msg = nl80211_bss_msg(bss, 0, cmd)) || |
061a3d3d VK |
8062 | (params->pmkid && |
8063 | nla_put(msg, NL80211_ATTR_PMKID, 16, params->pmkid)) || | |
8064 | (params->bssid && | |
8065 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid)) || | |
8066 | (params->ssid_len && | |
8067 | nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid)) || | |
8068 | (params->fils_cache_id && | |
8069 | nla_put(msg, NL80211_ATTR_FILS_CACHE_ID, 2, | |
8070 | params->fils_cache_id)) || | |
c6ec9759 | 8071 | (cmd != NL80211_CMD_DEL_PMKSA && |
8072 | params->pmk_len && params->pmk_len <= PMK_MAX_LEN && | |
061a3d3d | 8073 | nla_put(msg, NL80211_ATTR_PMK, params->pmk_len, params->pmk))) { |
6110753b | 8074 | nl80211_nlmsg_clear(msg); |
a862e4a3 JM |
8075 | nlmsg_free(msg); |
8076 | return -ENOBUFS; | |
8077 | } | |
a6efc65d | 8078 | |
6110753b | 8079 | return send_and_recv_msgs(bss->drv, msg, NULL, (void *) -1); |
a6efc65d JM |
8080 | } |
8081 | ||
8082 | ||
6fbb5414 | 8083 | static int nl80211_add_pmkid(void *priv, struct wpa_pmkid_params *params) |
a6efc65d JM |
8084 | { |
8085 | struct i802_bss *bss = priv; | |
e7f6e6ee | 8086 | int ret; |
061a3d3d VK |
8087 | |
8088 | if (params->bssid) | |
8089 | wpa_printf(MSG_DEBUG, "nl80211: Add PMKID for " MACSTR, | |
8090 | MAC2STR(params->bssid)); | |
8091 | else if (params->fils_cache_id && params->ssid_len) { | |
8092 | wpa_printf(MSG_DEBUG, | |
8093 | "nl80211: Add PMKSA for cache id %02x%02x SSID %s", | |
8094 | params->fils_cache_id[0], params->fils_cache_id[1], | |
8095 | wpa_ssid_txt(params->ssid, params->ssid_len)); | |
8096 | } | |
8097 | ||
e7f6e6ee JM |
8098 | ret = nl80211_pmkid(bss, NL80211_CMD_SET_PMKSA, params); |
8099 | if (ret < 0) { | |
8100 | wpa_printf(MSG_DEBUG, | |
8101 | "nl80211: NL80211_CMD_SET_PMKSA failed: %d (%s)", | |
8102 | ret, strerror(-ret)); | |
8103 | } | |
8104 | ||
8105 | return ret; | |
a6efc65d JM |
8106 | } |
8107 | ||
8108 | ||
6fbb5414 | 8109 | static int nl80211_remove_pmkid(void *priv, struct wpa_pmkid_params *params) |
a6efc65d JM |
8110 | { |
8111 | struct i802_bss *bss = priv; | |
e7f6e6ee | 8112 | int ret; |
061a3d3d VK |
8113 | |
8114 | if (params->bssid) | |
8115 | wpa_printf(MSG_DEBUG, "nl80211: Delete PMKID for " MACSTR, | |
8116 | MAC2STR(params->bssid)); | |
8117 | else if (params->fils_cache_id && params->ssid_len) { | |
8118 | wpa_printf(MSG_DEBUG, | |
8119 | "nl80211: Delete PMKSA for cache id %02x%02x SSID %s", | |
8120 | params->fils_cache_id[0], params->fils_cache_id[1], | |
8121 | wpa_ssid_txt(params->ssid, params->ssid_len)); | |
8122 | } | |
8123 | ||
e7f6e6ee JM |
8124 | ret = nl80211_pmkid(bss, NL80211_CMD_DEL_PMKSA, params); |
8125 | if (ret < 0) { | |
8126 | wpa_printf(MSG_DEBUG, | |
8127 | "nl80211: NL80211_CMD_DEL_PMKSA failed: %d (%s)", | |
8128 | ret, strerror(-ret)); | |
8129 | } | |
8130 | ||
8131 | return ret; | |
a6efc65d JM |
8132 | } |
8133 | ||
8134 | ||
8135 | static int nl80211_flush_pmkid(void *priv) | |
8136 | { | |
8137 | struct i802_bss *bss = priv; | |
061a3d3d VK |
8138 | struct nl_msg *msg; |
8139 | ||
a6efc65d | 8140 | wpa_printf(MSG_DEBUG, "nl80211: Flush PMKIDs"); |
061a3d3d VK |
8141 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_FLUSH_PMKSA); |
8142 | if (!msg) | |
8143 | return -ENOBUFS; | |
8144 | return send_and_recv_msgs(bss->drv, msg, NULL, NULL); | |
a6efc65d JM |
8145 | } |
8146 | ||
8147 | ||
0185007c MK |
8148 | static void clean_survey_results(struct survey_results *survey_results) |
8149 | { | |
8150 | struct freq_survey *survey, *tmp; | |
8151 | ||
8152 | if (dl_list_empty(&survey_results->survey_list)) | |
8153 | return; | |
8154 | ||
8155 | dl_list_for_each_safe(survey, tmp, &survey_results->survey_list, | |
8156 | struct freq_survey, list) { | |
8157 | dl_list_del(&survey->list); | |
8158 | os_free(survey); | |
8159 | } | |
8160 | } | |
8161 | ||
8162 | ||
8163 | static void add_survey(struct nlattr **sinfo, u32 ifidx, | |
8164 | struct dl_list *survey_list) | |
8165 | { | |
8166 | struct freq_survey *survey; | |
8167 | ||
8168 | survey = os_zalloc(sizeof(struct freq_survey)); | |
8169 | if (!survey) | |
8170 | return; | |
8171 | ||
8172 | survey->ifidx = ifidx; | |
8173 | survey->freq = nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]); | |
8174 | survey->filled = 0; | |
8175 | ||
8176 | if (sinfo[NL80211_SURVEY_INFO_NOISE]) { | |
8177 | survey->nf = (int8_t) | |
8178 | nla_get_u8(sinfo[NL80211_SURVEY_INFO_NOISE]); | |
8179 | survey->filled |= SURVEY_HAS_NF; | |
8180 | } | |
8181 | ||
8182 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME]) { | |
8183 | survey->channel_time = | |
8184 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME]); | |
8185 | survey->filled |= SURVEY_HAS_CHAN_TIME; | |
8186 | } | |
8187 | ||
8188 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY]) { | |
8189 | survey->channel_time_busy = | |
8190 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY]); | |
8191 | survey->filled |= SURVEY_HAS_CHAN_TIME_BUSY; | |
8192 | } | |
8193 | ||
8194 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_RX]) { | |
8195 | survey->channel_time_rx = | |
8196 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_RX]); | |
8197 | survey->filled |= SURVEY_HAS_CHAN_TIME_RX; | |
8198 | } | |
8199 | ||
8200 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_TX]) { | |
8201 | survey->channel_time_tx = | |
8202 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_TX]); | |
8203 | survey->filled |= SURVEY_HAS_CHAN_TIME_TX; | |
8204 | } | |
8205 | ||
8206 | 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)", | |
8207 | survey->freq, | |
8208 | survey->nf, | |
8209 | (unsigned long int) survey->channel_time, | |
8210 | (unsigned long int) survey->channel_time_busy, | |
8211 | (unsigned long int) survey->channel_time_tx, | |
8212 | (unsigned long int) survey->channel_time_rx, | |
8213 | survey->filled); | |
8214 | ||
8215 | dl_list_add_tail(survey_list, &survey->list); | |
8216 | } | |
8217 | ||
8218 | ||
8219 | static int check_survey_ok(struct nlattr **sinfo, u32 surveyed_freq, | |
8220 | unsigned int freq_filter) | |
8221 | { | |
8222 | if (!freq_filter) | |
8223 | return 1; | |
8224 | ||
8225 | return freq_filter == surveyed_freq; | |
8226 | } | |
8227 | ||
8228 | ||
8229 | static int survey_handler(struct nl_msg *msg, void *arg) | |
8230 | { | |
8231 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
8232 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
8233 | struct nlattr *sinfo[NL80211_SURVEY_INFO_MAX + 1]; | |
8234 | struct survey_results *survey_results; | |
8235 | u32 surveyed_freq = 0; | |
8236 | u32 ifidx; | |
8237 | ||
8238 | static struct nla_policy survey_policy[NL80211_SURVEY_INFO_MAX + 1] = { | |
8239 | [NL80211_SURVEY_INFO_FREQUENCY] = { .type = NLA_U32 }, | |
8240 | [NL80211_SURVEY_INFO_NOISE] = { .type = NLA_U8 }, | |
8241 | }; | |
8242 | ||
8243 | survey_results = (struct survey_results *) arg; | |
8244 | ||
8245 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
8246 | genlmsg_attrlen(gnlh, 0), NULL); | |
8247 | ||
e28f39b7 SJ |
8248 | if (!tb[NL80211_ATTR_IFINDEX]) |
8249 | return NL_SKIP; | |
8250 | ||
0185007c MK |
8251 | ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); |
8252 | ||
8253 | if (!tb[NL80211_ATTR_SURVEY_INFO]) | |
8254 | return NL_SKIP; | |
8255 | ||
8256 | if (nla_parse_nested(sinfo, NL80211_SURVEY_INFO_MAX, | |
8257 | tb[NL80211_ATTR_SURVEY_INFO], | |
8258 | survey_policy)) | |
8259 | return NL_SKIP; | |
8260 | ||
8261 | if (!sinfo[NL80211_SURVEY_INFO_FREQUENCY]) { | |
8262 | wpa_printf(MSG_ERROR, "nl80211: Invalid survey data"); | |
8263 | return NL_SKIP; | |
8264 | } | |
8265 | ||
8266 | surveyed_freq = nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]); | |
8267 | ||
8268 | if (!check_survey_ok(sinfo, surveyed_freq, | |
8269 | survey_results->freq_filter)) | |
8270 | return NL_SKIP; | |
8271 | ||
8272 | if (survey_results->freq_filter && | |
8273 | survey_results->freq_filter != surveyed_freq) { | |
8274 | wpa_printf(MSG_EXCESSIVE, "nl80211: Ignoring survey data for freq %d MHz", | |
8275 | surveyed_freq); | |
8276 | return NL_SKIP; | |
8277 | } | |
8278 | ||
8279 | add_survey(sinfo, ifidx, &survey_results->survey_list); | |
8280 | ||
8281 | return NL_SKIP; | |
8282 | } | |
8283 | ||
8284 | ||
8285 | static int wpa_driver_nl80211_get_survey(void *priv, unsigned int freq) | |
8286 | { | |
8287 | struct i802_bss *bss = priv; | |
8288 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8289 | struct nl_msg *msg; | |
9725b784 | 8290 | int err; |
0185007c MK |
8291 | union wpa_event_data data; |
8292 | struct survey_results *survey_results; | |
8293 | ||
8294 | os_memset(&data, 0, sizeof(data)); | |
8295 | survey_results = &data.survey_results; | |
8296 | ||
8297 | dl_list_init(&survey_results->survey_list); | |
8298 | ||
9725b784 | 8299 | msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SURVEY); |
0185007c | 8300 | if (!msg) |
a862e4a3 | 8301 | return -ENOBUFS; |
0185007c | 8302 | |
0185007c MK |
8303 | if (freq) |
8304 | data.survey_results.freq_filter = freq; | |
8305 | ||
8306 | do { | |
8307 | wpa_printf(MSG_DEBUG, "nl80211: Fetch survey data"); | |
8308 | err = send_and_recv_msgs(drv, msg, survey_handler, | |
8309 | survey_results); | |
8310 | } while (err > 0); | |
8311 | ||
a862e4a3 | 8312 | if (err) |
0185007c | 8313 | wpa_printf(MSG_ERROR, "nl80211: Failed to process survey data"); |
a862e4a3 JM |
8314 | else |
8315 | wpa_supplicant_event(drv->ctx, EVENT_SURVEY, &data); | |
0185007c | 8316 | |
0185007c | 8317 | clean_survey_results(survey_results); |
0185007c MK |
8318 | return err; |
8319 | } | |
8320 | ||
8321 | ||
98cd3d1c JM |
8322 | static void nl80211_set_rekey_info(void *priv, const u8 *kek, size_t kek_len, |
8323 | const u8 *kck, size_t kck_len, | |
b14a210c JB |
8324 | const u8 *replay_ctr) |
8325 | { | |
8326 | struct i802_bss *bss = priv; | |
8327 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8328 | struct nlattr *replay_nested; | |
8329 | struct nl_msg *msg; | |
64ae2447 | 8330 | int ret; |
b14a210c | 8331 | |
64ae2447 JM |
8332 | if (!drv->set_rekey_offload) |
8333 | return; | |
8334 | ||
8335 | wpa_printf(MSG_DEBUG, "nl80211: Set rekey offload"); | |
13f83980 | 8336 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_REKEY_OFFLOAD)) || |
a862e4a3 | 8337 | !(replay_nested = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA)) || |
98cd3d1c | 8338 | nla_put(msg, NL80211_REKEY_DATA_KEK, kek_len, kek) || |
b6ea7642 | 8339 | (kck_len && nla_put(msg, NL80211_REKEY_DATA_KCK, kck_len, kck)) || |
a862e4a3 JM |
8340 | nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, NL80211_REPLAY_CTR_LEN, |
8341 | replay_ctr)) { | |
bbd89bfc | 8342 | nl80211_nlmsg_clear(msg); |
a862e4a3 JM |
8343 | nlmsg_free(msg); |
8344 | return; | |
8345 | } | |
b14a210c JB |
8346 | |
8347 | nla_nest_end(msg, replay_nested); | |
8348 | ||
64ae2447 JM |
8349 | ret = send_and_recv_msgs(drv, msg, NULL, (void *) -1); |
8350 | if (ret == -EOPNOTSUPP) { | |
8351 | wpa_printf(MSG_DEBUG, | |
8352 | "nl80211: Driver does not support rekey offload"); | |
8353 | drv->set_rekey_offload = 0; | |
8354 | } | |
b14a210c JB |
8355 | } |
8356 | ||
8357 | ||
39718852 JB |
8358 | static void nl80211_send_null_frame(struct i802_bss *bss, const u8 *own_addr, |
8359 | const u8 *addr, int qos) | |
bcf24348 | 8360 | { |
39718852 JB |
8361 | /* send data frame to poll STA and check whether |
8362 | * this frame is ACKed */ | |
bcf24348 JB |
8363 | struct { |
8364 | struct ieee80211_hdr hdr; | |
8365 | u16 qos_ctl; | |
8366 | } STRUCT_PACKED nulldata; | |
8367 | size_t size; | |
8368 | ||
8369 | /* Send data frame to poll STA and check whether this frame is ACKed */ | |
8370 | ||
8371 | os_memset(&nulldata, 0, sizeof(nulldata)); | |
8372 | ||
8373 | if (qos) { | |
8374 | nulldata.hdr.frame_control = | |
8375 | IEEE80211_FC(WLAN_FC_TYPE_DATA, | |
8376 | WLAN_FC_STYPE_QOS_NULL); | |
8377 | size = sizeof(nulldata); | |
8378 | } else { | |
8379 | nulldata.hdr.frame_control = | |
8380 | IEEE80211_FC(WLAN_FC_TYPE_DATA, | |
8381 | WLAN_FC_STYPE_NULLFUNC); | |
8382 | size = sizeof(struct ieee80211_hdr); | |
8383 | } | |
8384 | ||
8385 | nulldata.hdr.frame_control |= host_to_le16(WLAN_FC_FROMDS); | |
8386 | os_memcpy(nulldata.hdr.IEEE80211_DA_FROMDS, addr, ETH_ALEN); | |
8387 | os_memcpy(nulldata.hdr.IEEE80211_BSSID_FROMDS, own_addr, ETH_ALEN); | |
8388 | os_memcpy(nulldata.hdr.IEEE80211_SA_FROMDS, own_addr, ETH_ALEN); | |
8389 | ||
9ebce9c5 | 8390 | if (wpa_driver_nl80211_send_mlme(bss, (u8 *) &nulldata, size, 0, 0, 0, |
27cc06d0 | 8391 | 0, 0, NULL, 0, 0) < 0) |
bcf24348 JB |
8392 | wpa_printf(MSG_DEBUG, "nl80211_send_null_frame: Failed to " |
8393 | "send poll frame"); | |
8394 | } | |
8395 | ||
39718852 JB |
8396 | static void nl80211_poll_client(void *priv, const u8 *own_addr, const u8 *addr, |
8397 | int qos) | |
8398 | { | |
8399 | struct i802_bss *bss = priv; | |
8400 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8401 | struct nl_msg *msg; | |
323a51cc | 8402 | u64 cookie; |
fc99fab7 | 8403 | int ret; |
39718852 JB |
8404 | |
8405 | if (!drv->poll_command_supported) { | |
8406 | nl80211_send_null_frame(bss, own_addr, addr, qos); | |
8407 | return; | |
8408 | } | |
8409 | ||
13f83980 | 8410 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_PROBE_CLIENT)) || |
a862e4a3 JM |
8411 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { |
8412 | nlmsg_free(msg); | |
8413 | return; | |
8414 | } | |
39718852 | 8415 | |
323a51cc | 8416 | ret = send_and_recv_msgs(drv, msg, cookie_handler, &cookie); |
fc99fab7 JM |
8417 | if (ret < 0) { |
8418 | wpa_printf(MSG_DEBUG, "nl80211: Client probe request for " | |
8419 | MACSTR " failed: ret=%d (%s)", | |
8420 | MAC2STR(addr), ret, strerror(-ret)); | |
323a51cc IP |
8421 | } else { |
8422 | wpa_printf(MSG_DEBUG, | |
8423 | "nl80211: Client probe request addr=" MACSTR | |
8424 | " cookie=%llu", MAC2STR(addr), | |
8425 | (long long unsigned int) cookie); | |
fc99fab7 | 8426 | } |
39718852 JB |
8427 | } |
8428 | ||
bcf24348 | 8429 | |
29f338af JM |
8430 | static int nl80211_set_power_save(struct i802_bss *bss, int enabled) |
8431 | { | |
8432 | struct nl_msg *msg; | |
1baa130b | 8433 | int ret; |
29f338af | 8434 | |
13f83980 | 8435 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_POWER_SAVE)) || |
a862e4a3 JM |
8436 | nla_put_u32(msg, NL80211_ATTR_PS_STATE, |
8437 | enabled ? NL80211_PS_ENABLED : NL80211_PS_DISABLED)) { | |
8438 | nlmsg_free(msg); | |
8439 | return -ENOBUFS; | |
8440 | } | |
1baa130b JM |
8441 | |
8442 | ret = send_and_recv_msgs(bss->drv, msg, NULL, NULL); | |
8443 | if (ret < 0) { | |
8444 | wpa_printf(MSG_DEBUG, | |
8445 | "nl80211: Setting PS state %s failed: %d (%s)", | |
8446 | enabled ? "enabled" : "disabled", | |
8447 | ret, strerror(-ret)); | |
8448 | } | |
8449 | return ret; | |
29f338af JM |
8450 | } |
8451 | ||
8452 | ||
8453 | static int nl80211_set_p2p_powersave(void *priv, int legacy_ps, int opp_ps, | |
8454 | int ctwindow) | |
8455 | { | |
8456 | struct i802_bss *bss = priv; | |
8457 | ||
8458 | wpa_printf(MSG_DEBUG, "nl80211: set_p2p_powersave (legacy_ps=%d " | |
8459 | "opp_ps=%d ctwindow=%d)", legacy_ps, opp_ps, ctwindow); | |
8460 | ||
0de38036 JM |
8461 | if (opp_ps != -1 || ctwindow != -1) { |
8462 | #ifdef ANDROID_P2P | |
8463 | wpa_driver_set_p2p_ps(priv, legacy_ps, opp_ps, ctwindow); | |
8464 | #else /* ANDROID_P2P */ | |
29f338af | 8465 | return -1; /* Not yet supported */ |
0de38036 JM |
8466 | #endif /* ANDROID_P2P */ |
8467 | } | |
29f338af JM |
8468 | |
8469 | if (legacy_ps == -1) | |
8470 | return 0; | |
8471 | if (legacy_ps != 0 && legacy_ps != 1) | |
8472 | return -1; /* Not yet supported */ | |
8473 | ||
8474 | return nl80211_set_power_save(bss, legacy_ps); | |
8475 | } | |
8476 | ||
8477 | ||
04e8003c JD |
8478 | static int nl80211_start_radar_detection(void *priv, |
8479 | struct hostapd_freq_params *freq) | |
f90e9c1c SW |
8480 | { |
8481 | struct i802_bss *bss = priv; | |
8482 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8483 | struct nl_msg *msg; | |
8484 | int ret; | |
8485 | ||
ad9a1bfe JC |
8486 | 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)", |
8487 | freq->freq, freq->ht_enabled, freq->vht_enabled, freq->he_enabled, | |
04e8003c JD |
8488 | freq->bandwidth, freq->center_freq1, freq->center_freq2); |
8489 | ||
f90e9c1c SW |
8490 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_RADAR)) { |
8491 | wpa_printf(MSG_DEBUG, "nl80211: Driver does not support radar " | |
8492 | "detection"); | |
8493 | return -1; | |
8494 | } | |
8495 | ||
9725b784 | 8496 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_RADAR_DETECT)) || |
a862e4a3 JM |
8497 | nl80211_put_freq_params(msg, freq) < 0) { |
8498 | nlmsg_free(msg); | |
8499 | return -1; | |
8500 | } | |
f90e9c1c SW |
8501 | |
8502 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
8503 | if (ret == 0) | |
8504 | return 0; | |
8505 | wpa_printf(MSG_DEBUG, "nl80211: Failed to start radar detection: " | |
8506 | "%d (%s)", ret, strerror(-ret)); | |
f90e9c1c SW |
8507 | return -1; |
8508 | } | |
8509 | ||
03ea1786 AN |
8510 | #ifdef CONFIG_TDLS |
8511 | ||
8512 | static int nl80211_send_tdls_mgmt(void *priv, const u8 *dst, u8 action_code, | |
8513 | u8 dialog_token, u16 status_code, | |
984dadc2 AN |
8514 | u32 peer_capab, int initiator, const u8 *buf, |
8515 | size_t len) | |
03ea1786 AN |
8516 | { |
8517 | struct i802_bss *bss = priv; | |
8518 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8519 | struct nl_msg *msg; | |
8520 | ||
8521 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) | |
8522 | return -EOPNOTSUPP; | |
8523 | ||
8524 | if (!dst) | |
8525 | return -EINVAL; | |
8526 | ||
9725b784 | 8527 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_TDLS_MGMT)) || |
a862e4a3 JM |
8528 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || |
8529 | nla_put_u8(msg, NL80211_ATTR_TDLS_ACTION, action_code) || | |
8530 | nla_put_u8(msg, NL80211_ATTR_TDLS_DIALOG_TOKEN, dialog_token) || | |
8531 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status_code)) | |
8532 | goto fail; | |
96ecea5e SD |
8533 | if (peer_capab) { |
8534 | /* | |
8535 | * The internal enum tdls_peer_capability definition is | |
8536 | * currently identical with the nl80211 enum | |
8537 | * nl80211_tdls_peer_capability, so no conversion is needed | |
8538 | * here. | |
8539 | */ | |
a862e4a3 JM |
8540 | if (nla_put_u32(msg, NL80211_ATTR_TDLS_PEER_CAPABILITY, |
8541 | peer_capab)) | |
8542 | goto fail; | |
96ecea5e | 8543 | } |
a862e4a3 JM |
8544 | if ((initiator && |
8545 | nla_put_flag(msg, NL80211_ATTR_TDLS_INITIATOR)) || | |
8546 | nla_put(msg, NL80211_ATTR_IE, len, buf)) | |
8547 | goto fail; | |
03ea1786 AN |
8548 | |
8549 | return send_and_recv_msgs(drv, msg, NULL, NULL); | |
8550 | ||
a862e4a3 | 8551 | fail: |
03ea1786 AN |
8552 | nlmsg_free(msg); |
8553 | return -ENOBUFS; | |
8554 | } | |
8555 | ||
8556 | ||
8557 | static int nl80211_tdls_oper(void *priv, enum tdls_oper oper, const u8 *peer) | |
8558 | { | |
8559 | struct i802_bss *bss = priv; | |
8560 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8561 | struct nl_msg *msg; | |
8562 | enum nl80211_tdls_operation nl80211_oper; | |
b2442f25 | 8563 | int res; |
03ea1786 AN |
8564 | |
8565 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) | |
8566 | return -EOPNOTSUPP; | |
8567 | ||
8568 | switch (oper) { | |
8569 | case TDLS_DISCOVERY_REQ: | |
8570 | nl80211_oper = NL80211_TDLS_DISCOVERY_REQ; | |
8571 | break; | |
8572 | case TDLS_SETUP: | |
8573 | nl80211_oper = NL80211_TDLS_SETUP; | |
8574 | break; | |
8575 | case TDLS_TEARDOWN: | |
8576 | nl80211_oper = NL80211_TDLS_TEARDOWN; | |
8577 | break; | |
8578 | case TDLS_ENABLE_LINK: | |
8579 | nl80211_oper = NL80211_TDLS_ENABLE_LINK; | |
8580 | break; | |
8581 | case TDLS_DISABLE_LINK: | |
8582 | nl80211_oper = NL80211_TDLS_DISABLE_LINK; | |
8583 | break; | |
8584 | case TDLS_ENABLE: | |
8585 | return 0; | |
8586 | case TDLS_DISABLE: | |
8587 | return 0; | |
8588 | default: | |
8589 | return -EINVAL; | |
8590 | } | |
8591 | ||
9725b784 | 8592 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_TDLS_OPER)) || |
a862e4a3 | 8593 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, nl80211_oper) || |
a862e4a3 JM |
8594 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) { |
8595 | nlmsg_free(msg); | |
8596 | return -ENOBUFS; | |
8597 | } | |
03ea1786 | 8598 | |
b2442f25 JM |
8599 | res = send_and_recv_msgs(drv, msg, NULL, NULL); |
8600 | wpa_printf(MSG_DEBUG, "nl80211: TDLS_OPER: oper=%d mac=" MACSTR | |
8601 | " --> res=%d (%s)", nl80211_oper, MAC2STR(peer), res, | |
8602 | strerror(-res)); | |
8603 | return res; | |
03ea1786 AN |
8604 | } |
8605 | ||
72b2605f AN |
8606 | |
8607 | static int | |
8608 | nl80211_tdls_enable_channel_switch(void *priv, const u8 *addr, u8 oper_class, | |
8609 | const struct hostapd_freq_params *params) | |
8610 | { | |
8611 | struct i802_bss *bss = priv; | |
8612 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8613 | struct nl_msg *msg; | |
8614 | int ret = -ENOBUFS; | |
8615 | ||
8616 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT) || | |
8617 | !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH)) | |
8618 | return -EOPNOTSUPP; | |
8619 | ||
8620 | wpa_printf(MSG_DEBUG, "nl80211: Enable TDLS channel switch " MACSTR | |
8621 | " oper_class=%u freq=%u", | |
8622 | MAC2STR(addr), oper_class, params->freq); | |
8623 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_TDLS_CHANNEL_SWITCH); | |
8624 | if (!msg || | |
8625 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || | |
8626 | nla_put_u8(msg, NL80211_ATTR_OPER_CLASS, oper_class) || | |
8627 | (ret = nl80211_put_freq_params(msg, params))) { | |
8628 | nlmsg_free(msg); | |
8629 | wpa_printf(MSG_DEBUG, "nl80211: Could not build TDLS chan switch"); | |
8630 | return ret; | |
8631 | } | |
8632 | ||
8633 | return send_and_recv_msgs(drv, msg, NULL, NULL); | |
8634 | } | |
8635 | ||
8636 | ||
8637 | static int | |
8638 | nl80211_tdls_disable_channel_switch(void *priv, const u8 *addr) | |
8639 | { | |
8640 | struct i802_bss *bss = priv; | |
8641 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8642 | struct nl_msg *msg; | |
8643 | ||
8644 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT) || | |
8645 | !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH)) | |
8646 | return -EOPNOTSUPP; | |
8647 | ||
8648 | wpa_printf(MSG_DEBUG, "nl80211: Disable TDLS channel switch " MACSTR, | |
8649 | MAC2STR(addr)); | |
8650 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH); | |
8651 | if (!msg || | |
8652 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { | |
8653 | nlmsg_free(msg); | |
8654 | wpa_printf(MSG_DEBUG, | |
8655 | "nl80211: Could not build TDLS cancel chan switch"); | |
8656 | return -ENOBUFS; | |
8657 | } | |
8658 | ||
8659 | return send_and_recv_msgs(drv, msg, NULL, NULL); | |
8660 | } | |
8661 | ||
03ea1786 AN |
8662 | #endif /* CONFIG TDLS */ |
8663 | ||
8664 | ||
9ebce9c5 JM |
8665 | static int driver_nl80211_set_key(const char *ifname, void *priv, |
8666 | enum wpa_alg alg, const u8 *addr, | |
8667 | int key_idx, int set_tx, | |
8668 | const u8 *seq, size_t seq_len, | |
8669 | const u8 *key, size_t key_len) | |
8670 | { | |
8671 | struct i802_bss *bss = priv; | |
8672 | return wpa_driver_nl80211_set_key(ifname, bss, alg, addr, key_idx, | |
8673 | set_tx, seq, seq_len, key, key_len); | |
8674 | } | |
8675 | ||
8676 | ||
8677 | static int driver_nl80211_scan2(void *priv, | |
8678 | struct wpa_driver_scan_params *params) | |
8679 | { | |
8680 | struct i802_bss *bss = priv; | |
b658547d | 8681 | #ifdef CONFIG_DRIVER_NL80211_QCA |
adcd7c4b KV |
8682 | struct wpa_driver_nl80211_data *drv = bss->drv; |
8683 | ||
8684 | /* | |
8685 | * Do a vendor specific scan if possible. If only_new_results is | |
8686 | * set, do a normal scan since a kernel (cfg80211) BSS cache flush | |
8687 | * cannot be achieved through a vendor scan. The below condition may | |
8688 | * need to be modified if new scan flags are added in the future whose | |
8689 | * functionality can only be achieved through a normal scan. | |
8690 | */ | |
8691 | if (drv->scan_vendor_cmd_avail && !params->only_new_results) | |
8692 | return wpa_driver_nl80211_vendor_scan(bss, params); | |
b658547d | 8693 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
9ebce9c5 JM |
8694 | return wpa_driver_nl80211_scan(bss, params); |
8695 | } | |
8696 | ||
8697 | ||
8698 | static int driver_nl80211_deauthenticate(void *priv, const u8 *addr, | |
4be17ffb | 8699 | u16 reason_code) |
9ebce9c5 JM |
8700 | { |
8701 | struct i802_bss *bss = priv; | |
8702 | return wpa_driver_nl80211_deauthenticate(bss, addr, reason_code); | |
8703 | } | |
8704 | ||
8705 | ||
8706 | static int driver_nl80211_authenticate(void *priv, | |
8707 | struct wpa_driver_auth_params *params) | |
8708 | { | |
8709 | struct i802_bss *bss = priv; | |
8710 | return wpa_driver_nl80211_authenticate(bss, params); | |
8711 | } | |
8712 | ||
8713 | ||
8714 | static void driver_nl80211_deinit(void *priv) | |
8715 | { | |
8716 | struct i802_bss *bss = priv; | |
8717 | wpa_driver_nl80211_deinit(bss); | |
8718 | } | |
8719 | ||
8720 | ||
8721 | static int driver_nl80211_if_remove(void *priv, enum wpa_driver_if_type type, | |
8722 | const char *ifname) | |
8723 | { | |
8724 | struct i802_bss *bss = priv; | |
8725 | return wpa_driver_nl80211_if_remove(bss, type, ifname); | |
8726 | } | |
8727 | ||
8728 | ||
8729 | static int driver_nl80211_send_mlme(void *priv, const u8 *data, | |
5d180a77 | 8730 | size_t data_len, int noack, |
2d3943ce | 8731 | unsigned int freq, |
665a3007 JM |
8732 | const u16 *csa_offs, size_t csa_offs_len, |
8733 | int no_encrypt) | |
9ebce9c5 JM |
8734 | { |
8735 | struct i802_bss *bss = priv; | |
8736 | return wpa_driver_nl80211_send_mlme(bss, data, data_len, noack, | |
2d3943ce | 8737 | freq, 0, 0, 0, csa_offs, |
27cc06d0 | 8738 | csa_offs_len, no_encrypt); |
9ebce9c5 JM |
8739 | } |
8740 | ||
8741 | ||
8742 | static int driver_nl80211_sta_remove(void *priv, const u8 *addr) | |
8743 | { | |
8744 | struct i802_bss *bss = priv; | |
59d7148a | 8745 | return wpa_driver_nl80211_sta_remove(bss, addr, -1, 0); |
9ebce9c5 JM |
8746 | } |
8747 | ||
8748 | ||
9ebce9c5 JM |
8749 | static int driver_nl80211_set_sta_vlan(void *priv, const u8 *addr, |
8750 | const char *ifname, int vlan_id) | |
8751 | { | |
8752 | struct i802_bss *bss = priv; | |
8753 | return i802_set_sta_vlan(bss, addr, ifname, vlan_id); | |
8754 | } | |
9ebce9c5 JM |
8755 | |
8756 | ||
8757 | static int driver_nl80211_read_sta_data(void *priv, | |
8758 | struct hostap_sta_driver_data *data, | |
8759 | const u8 *addr) | |
8760 | { | |
8761 | struct i802_bss *bss = priv; | |
7824bf77 JC |
8762 | |
8763 | os_memset(data, 0, sizeof(*data)); | |
9ebce9c5 JM |
8764 | return i802_read_sta_data(bss, data, addr); |
8765 | } | |
8766 | ||
8767 | ||
8768 | static int driver_nl80211_send_action(void *priv, unsigned int freq, | |
8769 | unsigned int wait_time, | |
8770 | const u8 *dst, const u8 *src, | |
8771 | const u8 *bssid, | |
8772 | const u8 *data, size_t data_len, | |
8773 | int no_cck) | |
8774 | { | |
8775 | struct i802_bss *bss = priv; | |
8776 | return wpa_driver_nl80211_send_action(bss, freq, wait_time, dst, src, | |
8777 | bssid, data, data_len, no_cck); | |
8778 | } | |
8779 | ||
8780 | ||
8781 | static int driver_nl80211_probe_req_report(void *priv, int report) | |
8782 | { | |
8783 | struct i802_bss *bss = priv; | |
8784 | return wpa_driver_nl80211_probe_req_report(bss, report); | |
8785 | } | |
8786 | ||
8787 | ||
6a1ce395 DG |
8788 | static int wpa_driver_nl80211_update_ft_ies(void *priv, const u8 *md, |
8789 | const u8 *ies, size_t ies_len) | |
8790 | { | |
8791 | int ret; | |
8792 | struct nl_msg *msg; | |
8793 | struct i802_bss *bss = priv; | |
8794 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8795 | u16 mdid = WPA_GET_LE16(md); | |
8796 | ||
6a1ce395 | 8797 | wpa_printf(MSG_DEBUG, "nl80211: Updating FT IEs"); |
9725b784 | 8798 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_UPDATE_FT_IES)) || |
a862e4a3 JM |
8799 | nla_put(msg, NL80211_ATTR_IE, ies_len, ies) || |
8800 | nla_put_u16(msg, NL80211_ATTR_MDID, mdid)) { | |
8801 | nlmsg_free(msg); | |
8802 | return -ENOBUFS; | |
8803 | } | |
6a1ce395 DG |
8804 | |
8805 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
8806 | if (ret) { | |
8807 | wpa_printf(MSG_DEBUG, "nl80211: update_ft_ies failed " | |
8808 | "err=%d (%s)", ret, strerror(-ret)); | |
8809 | } | |
8810 | ||
8811 | return ret; | |
6a1ce395 DG |
8812 | } |
8813 | ||
8814 | ||
d1836e23 LD |
8815 | static int nl80211_update_dh_ie(void *priv, const u8 *peer_mac, |
8816 | u16 reason_code, const u8 *ie, size_t ie_len) | |
8817 | { | |
8818 | int ret; | |
8819 | struct nl_msg *msg; | |
8820 | struct i802_bss *bss = priv; | |
8821 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8822 | ||
8823 | wpa_printf(MSG_DEBUG, "nl80211: Updating DH IE peer: " MACSTR | |
8824 | " reason %u", MAC2STR(peer_mac), reason_code); | |
8825 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_UPDATE_OWE_INFO)) || | |
8826 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer_mac) || | |
8827 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, reason_code) || | |
8828 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) { | |
8829 | nlmsg_free(msg); | |
8830 | return -ENOBUFS; | |
8831 | } | |
8832 | ||
8833 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
8834 | if (ret) { | |
8835 | wpa_printf(MSG_DEBUG, | |
8836 | "nl80211: update_dh_ie failed err=%d (%s)", | |
8837 | ret, strerror(-ret)); | |
8838 | } | |
8839 | ||
8840 | return ret; | |
8841 | } | |
8842 | ||
8843 | ||
47754718 | 8844 | static const u8 * wpa_driver_nl80211_get_macaddr(void *priv) |
597b94f5 AS |
8845 | { |
8846 | struct i802_bss *bss = priv; | |
8847 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8848 | ||
8849 | if (drv->nlmode != NL80211_IFTYPE_P2P_DEVICE) | |
8850 | return NULL; | |
8851 | ||
8852 | return bss->addr; | |
8853 | } | |
8854 | ||
8855 | ||
a771c07d JM |
8856 | static const char * scan_state_str(enum scan_states scan_state) |
8857 | { | |
8858 | switch (scan_state) { | |
8859 | case NO_SCAN: | |
8860 | return "NO_SCAN"; | |
8861 | case SCAN_REQUESTED: | |
8862 | return "SCAN_REQUESTED"; | |
8863 | case SCAN_STARTED: | |
8864 | return "SCAN_STARTED"; | |
8865 | case SCAN_COMPLETED: | |
8866 | return "SCAN_COMPLETED"; | |
8867 | case SCAN_ABORTED: | |
8868 | return "SCAN_ABORTED"; | |
8869 | case SCHED_SCAN_STARTED: | |
8870 | return "SCHED_SCAN_STARTED"; | |
8871 | case SCHED_SCAN_STOPPED: | |
8872 | return "SCHED_SCAN_STOPPED"; | |
8873 | case SCHED_SCAN_RESULTS: | |
8874 | return "SCHED_SCAN_RESULTS"; | |
8875 | } | |
8876 | ||
8877 | return "??"; | |
8878 | } | |
8879 | ||
8880 | ||
8881 | static int wpa_driver_nl80211_status(void *priv, char *buf, size_t buflen) | |
8882 | { | |
8883 | struct i802_bss *bss = priv; | |
8884 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8885 | int res; | |
8886 | char *pos, *end; | |
fea49f8f JM |
8887 | struct nl_msg *msg; |
8888 | char alpha2[3] = { 0, 0, 0 }; | |
a771c07d JM |
8889 | |
8890 | pos = buf; | |
8891 | end = buf + buflen; | |
8892 | ||
8893 | res = os_snprintf(pos, end - pos, | |
8894 | "ifindex=%d\n" | |
8895 | "ifname=%s\n" | |
8896 | "brname=%s\n" | |
8897 | "addr=" MACSTR "\n" | |
8898 | "freq=%d\n" | |
c809756f | 8899 | "%s%s%s%s%s%s", |
a771c07d JM |
8900 | bss->ifindex, |
8901 | bss->ifname, | |
8902 | bss->brname, | |
8903 | MAC2STR(bss->addr), | |
8904 | bss->freq, | |
8905 | bss->beacon_set ? "beacon_set=1\n" : "", | |
8906 | bss->added_if_into_bridge ? | |
8907 | "added_if_into_bridge=1\n" : "", | |
c809756f | 8908 | bss->already_in_bridge ? "already_in_bridge=1\n" : "", |
a771c07d JM |
8909 | bss->added_bridge ? "added_bridge=1\n" : "", |
8910 | bss->in_deinit ? "in_deinit=1\n" : "", | |
8911 | bss->if_dynamic ? "if_dynamic=1\n" : ""); | |
d85e1fc8 | 8912 | if (os_snprintf_error(end - pos, res)) |
a771c07d JM |
8913 | return pos - buf; |
8914 | pos += res; | |
8915 | ||
8916 | if (bss->wdev_id_set) { | |
8917 | res = os_snprintf(pos, end - pos, "wdev_id=%llu\n", | |
8918 | (unsigned long long) bss->wdev_id); | |
d85e1fc8 | 8919 | if (os_snprintf_error(end - pos, res)) |
a771c07d JM |
8920 | return pos - buf; |
8921 | pos += res; | |
8922 | } | |
8923 | ||
8924 | res = os_snprintf(pos, end - pos, | |
8925 | "phyname=%s\n" | |
fee354c7 | 8926 | "perm_addr=" MACSTR "\n" |
a771c07d JM |
8927 | "drv_ifindex=%d\n" |
8928 | "operstate=%d\n" | |
8929 | "scan_state=%s\n" | |
8930 | "auth_bssid=" MACSTR "\n" | |
8931 | "auth_attempt_bssid=" MACSTR "\n" | |
8932 | "bssid=" MACSTR "\n" | |
8933 | "prev_bssid=" MACSTR "\n" | |
8934 | "associated=%d\n" | |
8935 | "assoc_freq=%u\n" | |
8936 | "monitor_sock=%d\n" | |
8937 | "monitor_ifidx=%d\n" | |
8938 | "monitor_refcount=%d\n" | |
8939 | "last_mgmt_freq=%u\n" | |
8940 | "eapol_tx_sock=%d\n" | |
97752f79 | 8941 | "%s%s%s%s%s%s%s%s%s%s%s%s%s", |
a771c07d | 8942 | drv->phyname, |
fee354c7 | 8943 | MAC2STR(drv->perm_addr), |
a771c07d JM |
8944 | drv->ifindex, |
8945 | drv->operstate, | |
8946 | scan_state_str(drv->scan_state), | |
8947 | MAC2STR(drv->auth_bssid), | |
8948 | MAC2STR(drv->auth_attempt_bssid), | |
8949 | MAC2STR(drv->bssid), | |
8950 | MAC2STR(drv->prev_bssid), | |
8951 | drv->associated, | |
8952 | drv->assoc_freq, | |
8953 | drv->monitor_sock, | |
8954 | drv->monitor_ifidx, | |
8955 | drv->monitor_refcount, | |
8956 | drv->last_mgmt_freq, | |
8957 | drv->eapol_tx_sock, | |
8958 | drv->ignore_if_down_event ? | |
8959 | "ignore_if_down_event=1\n" : "", | |
8960 | drv->scan_complete_events ? | |
8961 | "scan_complete_events=1\n" : "", | |
8962 | drv->disabled_11b_rates ? | |
8963 | "disabled_11b_rates=1\n" : "", | |
8964 | drv->pending_remain_on_chan ? | |
8965 | "pending_remain_on_chan=1\n" : "", | |
8966 | drv->in_interface_list ? "in_interface_list=1\n" : "", | |
8967 | drv->device_ap_sme ? "device_ap_sme=1\n" : "", | |
8968 | drv->poll_command_supported ? | |
8969 | "poll_command_supported=1\n" : "", | |
8970 | drv->data_tx_status ? "data_tx_status=1\n" : "", | |
8971 | drv->scan_for_auth ? "scan_for_auth=1\n" : "", | |
8972 | drv->retry_auth ? "retry_auth=1\n" : "", | |
8973 | drv->use_monitor ? "use_monitor=1\n" : "", | |
8974 | drv->ignore_next_local_disconnect ? | |
8975 | "ignore_next_local_disconnect=1\n" : "", | |
d6a36f39 | 8976 | drv->ignore_next_local_deauth ? |
97752f79 | 8977 | "ignore_next_local_deauth=1\n" : ""); |
d85e1fc8 | 8978 | if (os_snprintf_error(end - pos, res)) |
a771c07d JM |
8979 | return pos - buf; |
8980 | pos += res; | |
8981 | ||
8982 | if (drv->has_capability) { | |
8983 | res = os_snprintf(pos, end - pos, | |
8984 | "capa.key_mgmt=0x%x\n" | |
8985 | "capa.enc=0x%x\n" | |
8986 | "capa.auth=0x%x\n" | |
24bd4e0b | 8987 | "capa.flags=0x%llx\n" |
a0a34d53 | 8988 | "capa.rrm_flags=0x%x\n" |
a771c07d JM |
8989 | "capa.max_scan_ssids=%d\n" |
8990 | "capa.max_sched_scan_ssids=%d\n" | |
8991 | "capa.sched_scan_supported=%d\n" | |
8992 | "capa.max_match_sets=%d\n" | |
8993 | "capa.max_remain_on_chan=%u\n" | |
8994 | "capa.max_stations=%u\n" | |
8995 | "capa.probe_resp_offloads=0x%x\n" | |
8996 | "capa.max_acl_mac_addrs=%u\n" | |
86056fea IP |
8997 | "capa.num_multichan_concurrent=%u\n" |
8998 | "capa.mac_addr_rand_sched_scan_supported=%d\n" | |
079a28f7 AK |
8999 | "capa.mac_addr_rand_scan_supported=%d\n" |
9000 | "capa.conc_capab=%u\n" | |
9001 | "capa.max_conc_chan_2_4=%u\n" | |
09ea4309 AS |
9002 | "capa.max_conc_chan_5_0=%u\n" |
9003 | "capa.max_sched_scan_plans=%u\n" | |
9004 | "capa.max_sched_scan_plan_interval=%u\n" | |
9005 | "capa.max_sched_scan_plan_iterations=%u\n", | |
a771c07d JM |
9006 | drv->capa.key_mgmt, |
9007 | drv->capa.enc, | |
9008 | drv->capa.auth, | |
24bd4e0b | 9009 | (unsigned long long) drv->capa.flags, |
a0a34d53 | 9010 | drv->capa.rrm_flags, |
a771c07d JM |
9011 | drv->capa.max_scan_ssids, |
9012 | drv->capa.max_sched_scan_ssids, | |
9013 | drv->capa.sched_scan_supported, | |
9014 | drv->capa.max_match_sets, | |
9015 | drv->capa.max_remain_on_chan, | |
9016 | drv->capa.max_stations, | |
9017 | drv->capa.probe_resp_offloads, | |
9018 | drv->capa.max_acl_mac_addrs, | |
86056fea IP |
9019 | drv->capa.num_multichan_concurrent, |
9020 | drv->capa.mac_addr_rand_sched_scan_supported, | |
079a28f7 AK |
9021 | drv->capa.mac_addr_rand_scan_supported, |
9022 | drv->capa.conc_capab, | |
9023 | drv->capa.max_conc_chan_2_4, | |
09ea4309 AS |
9024 | drv->capa.max_conc_chan_5_0, |
9025 | drv->capa.max_sched_scan_plans, | |
9026 | drv->capa.max_sched_scan_plan_interval, | |
9027 | drv->capa.max_sched_scan_plan_iterations); | |
d85e1fc8 | 9028 | if (os_snprintf_error(end - pos, res)) |
a771c07d JM |
9029 | return pos - buf; |
9030 | pos += res; | |
9031 | } | |
9032 | ||
fea49f8f JM |
9033 | msg = nlmsg_alloc(); |
9034 | if (msg && | |
9035 | nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_REG) && | |
9036 | nla_put_u32(msg, NL80211_ATTR_WIPHY, drv->wiphy_idx) == 0) { | |
9037 | if (send_and_recv_msgs(drv, msg, nl80211_get_country, | |
9038 | alpha2) == 0 && | |
9039 | alpha2[0]) { | |
9040 | res = os_snprintf(pos, end - pos, "country=%s\n", | |
9041 | alpha2); | |
9042 | if (os_snprintf_error(end - pos, res)) | |
9043 | return pos - buf; | |
9044 | pos += res; | |
9045 | } | |
9046 | } else { | |
9047 | nlmsg_free(msg); | |
9048 | } | |
9049 | ||
a771c07d JM |
9050 | return pos - buf; |
9051 | } | |
9052 | ||
9053 | ||
1c4ffa87 AO |
9054 | static int set_beacon_data(struct nl_msg *msg, struct beacon_data *settings) |
9055 | { | |
a862e4a3 JM |
9056 | if ((settings->head && |
9057 | nla_put(msg, NL80211_ATTR_BEACON_HEAD, | |
9058 | settings->head_len, settings->head)) || | |
9059 | (settings->tail && | |
9060 | nla_put(msg, NL80211_ATTR_BEACON_TAIL, | |
9061 | settings->tail_len, settings->tail)) || | |
9062 | (settings->beacon_ies && | |
9063 | nla_put(msg, NL80211_ATTR_IE, | |
9064 | settings->beacon_ies_len, settings->beacon_ies)) || | |
9065 | (settings->proberesp_ies && | |
9066 | nla_put(msg, NL80211_ATTR_IE_PROBE_RESP, | |
9067 | settings->proberesp_ies_len, settings->proberesp_ies)) || | |
9068 | (settings->assocresp_ies && | |
9069 | nla_put(msg, NL80211_ATTR_IE_ASSOC_RESP, | |
9070 | settings->assocresp_ies_len, settings->assocresp_ies)) || | |
9071 | (settings->probe_resp && | |
9072 | nla_put(msg, NL80211_ATTR_PROBE_RESP, | |
9073 | settings->probe_resp_len, settings->probe_resp))) | |
9074 | return -ENOBUFS; | |
1c4ffa87 AO |
9075 | |
9076 | return 0; | |
1c4ffa87 AO |
9077 | } |
9078 | ||
9079 | ||
9080 | static int nl80211_switch_channel(void *priv, struct csa_settings *settings) | |
9081 | { | |
9082 | struct nl_msg *msg; | |
9083 | struct i802_bss *bss = priv; | |
9084 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
9085 | struct nlattr *beacon_csa; | |
9086 | int ret = -ENOBUFS; | |
366179d2 AO |
9087 | int csa_off_len = 0; |
9088 | int i; | |
1c4ffa87 | 9089 | |
8d1fdde7 | 9090 | wpa_printf(MSG_DEBUG, "nl80211: Channel switch request (cs_count=%u block_tx=%u freq=%d width=%d cf1=%d cf2=%d)", |
1c4ffa87 | 9091 | settings->cs_count, settings->block_tx, |
8d1fdde7 JD |
9092 | settings->freq_params.freq, settings->freq_params.bandwidth, |
9093 | settings->freq_params.center_freq1, | |
9094 | settings->freq_params.center_freq2); | |
1c4ffa87 | 9095 | |
991aa9c7 | 9096 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_AP_CSA)) { |
1c4ffa87 AO |
9097 | wpa_printf(MSG_DEBUG, "nl80211: Driver does not support channel switch command"); |
9098 | return -EOPNOTSUPP; | |
9099 | } | |
9100 | ||
0928b629 PO |
9101 | if (drv->nlmode != NL80211_IFTYPE_AP && |
9102 | drv->nlmode != NL80211_IFTYPE_P2P_GO && | |
9103 | drv->nlmode != NL80211_IFTYPE_MESH_POINT) | |
1c4ffa87 AO |
9104 | return -EOPNOTSUPP; |
9105 | ||
366179d2 AO |
9106 | /* |
9107 | * Remove empty counters, assuming Probe Response and Beacon frame | |
9108 | * counters match. This implementation assumes that there are only two | |
9109 | * counters. | |
9110 | */ | |
9111 | if (settings->counter_offset_beacon[0] && | |
9112 | !settings->counter_offset_beacon[1]) { | |
9113 | csa_off_len = 1; | |
9114 | } else if (settings->counter_offset_beacon[1] && | |
9115 | !settings->counter_offset_beacon[0]) { | |
9116 | csa_off_len = 1; | |
9117 | settings->counter_offset_beacon[0] = | |
9118 | settings->counter_offset_beacon[1]; | |
9119 | settings->counter_offset_presp[0] = | |
9120 | settings->counter_offset_presp[1]; | |
9121 | } else if (settings->counter_offset_beacon[1] && | |
9122 | settings->counter_offset_beacon[0]) { | |
9123 | csa_off_len = 2; | |
9124 | } else { | |
9125 | wpa_printf(MSG_ERROR, "nl80211: No CSA counters provided"); | |
9126 | return -EINVAL; | |
9127 | } | |
9128 | ||
9129 | /* Check CSA counters validity */ | |
9130 | if (drv->capa.max_csa_counters && | |
9131 | csa_off_len > drv->capa.max_csa_counters) { | |
9132 | wpa_printf(MSG_ERROR, | |
9133 | "nl80211: Too many CSA counters provided"); | |
1c4ffa87 | 9134 | return -EINVAL; |
366179d2 | 9135 | } |
1c4ffa87 | 9136 | |
366179d2 | 9137 | if (!settings->beacon_csa.tail) |
1c4ffa87 AO |
9138 | return -EINVAL; |
9139 | ||
366179d2 AO |
9140 | for (i = 0; i < csa_off_len; i++) { |
9141 | u16 csa_c_off_bcn = settings->counter_offset_beacon[i]; | |
9142 | u16 csa_c_off_presp = settings->counter_offset_presp[i]; | |
9143 | ||
9144 | if ((settings->beacon_csa.tail_len <= csa_c_off_bcn) || | |
9145 | (settings->beacon_csa.tail[csa_c_off_bcn] != | |
9146 | settings->cs_count)) | |
9147 | return -EINVAL; | |
9148 | ||
9149 | if (settings->beacon_csa.probe_resp && | |
9150 | ((settings->beacon_csa.probe_resp_len <= | |
9151 | csa_c_off_presp) || | |
9152 | (settings->beacon_csa.probe_resp[csa_c_off_presp] != | |
9153 | settings->cs_count))) | |
9154 | return -EINVAL; | |
9155 | } | |
9156 | ||
13f83980 | 9157 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_CHANNEL_SWITCH)) || |
a862e4a3 JM |
9158 | nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, |
9159 | settings->cs_count) || | |
9160 | (ret = nl80211_put_freq_params(msg, &settings->freq_params)) || | |
9161 | (settings->block_tx && | |
9162 | nla_put_flag(msg, NL80211_ATTR_CH_SWITCH_BLOCK_TX))) | |
1c4ffa87 AO |
9163 | goto error; |
9164 | ||
1c4ffa87 AO |
9165 | /* beacon_after params */ |
9166 | ret = set_beacon_data(msg, &settings->beacon_after); | |
9167 | if (ret) | |
9168 | goto error; | |
9169 | ||
9170 | /* beacon_csa params */ | |
9171 | beacon_csa = nla_nest_start(msg, NL80211_ATTR_CSA_IES); | |
9172 | if (!beacon_csa) | |
a862e4a3 | 9173 | goto fail; |
1c4ffa87 AO |
9174 | |
9175 | ret = set_beacon_data(msg, &settings->beacon_csa); | |
9176 | if (ret) | |
9177 | goto error; | |
9178 | ||
366179d2 AO |
9179 | if (nla_put(msg, NL80211_ATTR_CSA_C_OFF_BEACON, |
9180 | csa_off_len * sizeof(u16), | |
9181 | settings->counter_offset_beacon) || | |
a862e4a3 | 9182 | (settings->beacon_csa.probe_resp && |
366179d2 AO |
9183 | nla_put(msg, NL80211_ATTR_CSA_C_OFF_PRESP, |
9184 | csa_off_len * sizeof(u16), | |
9185 | settings->counter_offset_presp))) | |
a862e4a3 | 9186 | goto fail; |
1c4ffa87 AO |
9187 | |
9188 | nla_nest_end(msg, beacon_csa); | |
9189 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
9190 | if (ret) { | |
9191 | wpa_printf(MSG_DEBUG, "nl80211: switch_channel failed err=%d (%s)", | |
9192 | ret, strerror(-ret)); | |
9193 | } | |
9194 | return ret; | |
9195 | ||
a862e4a3 | 9196 | fail: |
1c4ffa87 AO |
9197 | ret = -ENOBUFS; |
9198 | error: | |
9199 | nlmsg_free(msg); | |
9200 | wpa_printf(MSG_DEBUG, "nl80211: Could not build channel switch request"); | |
9201 | return ret; | |
9202 | } | |
9203 | ||
9204 | ||
dfa87878 MB |
9205 | static int nl80211_add_ts(void *priv, u8 tsid, const u8 *addr, |
9206 | u8 user_priority, u16 admitted_time) | |
9207 | { | |
9208 | struct i802_bss *bss = priv; | |
9209 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
9210 | struct nl_msg *msg; | |
9211 | int ret; | |
9212 | ||
9213 | wpa_printf(MSG_DEBUG, | |
9214 | "nl80211: add_ts request: tsid=%u admitted_time=%u up=%d", | |
9215 | tsid, admitted_time, user_priority); | |
9216 | ||
9217 | if (!is_sta_interface(drv->nlmode)) | |
9218 | return -ENOTSUP; | |
9219 | ||
56f77852 JM |
9220 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_ADD_TX_TS); |
9221 | if (!msg || | |
a862e4a3 JM |
9222 | nla_put_u8(msg, NL80211_ATTR_TSID, tsid) || |
9223 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || | |
9224 | nla_put_u8(msg, NL80211_ATTR_USER_PRIO, user_priority) || | |
9225 | nla_put_u16(msg, NL80211_ATTR_ADMITTED_TIME, admitted_time)) { | |
9226 | nlmsg_free(msg); | |
9227 | return -ENOBUFS; | |
9228 | } | |
dfa87878 MB |
9229 | |
9230 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
9231 | if (ret) | |
9232 | wpa_printf(MSG_DEBUG, "nl80211: add_ts failed err=%d (%s)", | |
9233 | ret, strerror(-ret)); | |
9234 | return ret; | |
dfa87878 MB |
9235 | } |
9236 | ||
9237 | ||
9238 | static int nl80211_del_ts(void *priv, u8 tsid, const u8 *addr) | |
9239 | { | |
9240 | struct i802_bss *bss = priv; | |
9241 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
9242 | struct nl_msg *msg; | |
9243 | int ret; | |
9244 | ||
9245 | wpa_printf(MSG_DEBUG, "nl80211: del_ts request: tsid=%u", tsid); | |
9246 | ||
9247 | if (!is_sta_interface(drv->nlmode)) | |
9248 | return -ENOTSUP; | |
9249 | ||
56f77852 | 9250 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_DEL_TX_TS)) || |
a862e4a3 JM |
9251 | nla_put_u8(msg, NL80211_ATTR_TSID, tsid) || |
9252 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { | |
9253 | nlmsg_free(msg); | |
9254 | return -ENOBUFS; | |
9255 | } | |
dfa87878 MB |
9256 | |
9257 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
9258 | if (ret) | |
9259 | wpa_printf(MSG_DEBUG, "nl80211: del_ts failed err=%d (%s)", | |
9260 | ret, strerror(-ret)); | |
9261 | return ret; | |
dfa87878 MB |
9262 | } |
9263 | ||
9264 | ||
6b9f7af6 JM |
9265 | #ifdef CONFIG_TESTING_OPTIONS |
9266 | static int cmd_reply_handler(struct nl_msg *msg, void *arg) | |
9267 | { | |
9268 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
9269 | struct wpabuf *buf = arg; | |
9270 | ||
9271 | if (!buf) | |
9272 | return NL_SKIP; | |
9273 | ||
9274 | if ((size_t) genlmsg_attrlen(gnlh, 0) > wpabuf_tailroom(buf)) { | |
9275 | wpa_printf(MSG_INFO, "nl80211: insufficient buffer space for reply"); | |
9276 | return NL_SKIP; | |
9277 | } | |
9278 | ||
9279 | wpabuf_put_data(buf, genlmsg_attrdata(gnlh, 0), | |
9280 | genlmsg_attrlen(gnlh, 0)); | |
9281 | ||
9282 | return NL_SKIP; | |
9283 | } | |
9284 | #endif /* CONFIG_TESTING_OPTIONS */ | |
9285 | ||
9286 | ||
adef8948 BL |
9287 | static int vendor_reply_handler(struct nl_msg *msg, void *arg) |
9288 | { | |
9289 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
9290 | struct nlattr *nl_vendor_reply, *nl; | |
9291 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
9292 | struct wpabuf *buf = arg; | |
9293 | int rem; | |
9294 | ||
9295 | if (!buf) | |
9296 | return NL_SKIP; | |
9297 | ||
9298 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
9299 | genlmsg_attrlen(gnlh, 0), NULL); | |
9300 | nl_vendor_reply = tb[NL80211_ATTR_VENDOR_DATA]; | |
9301 | ||
9302 | if (!nl_vendor_reply) | |
9303 | return NL_SKIP; | |
9304 | ||
9305 | if ((size_t) nla_len(nl_vendor_reply) > wpabuf_tailroom(buf)) { | |
9306 | wpa_printf(MSG_INFO, "nl80211: Vendor command: insufficient buffer space for reply"); | |
9307 | return NL_SKIP; | |
9308 | } | |
9309 | ||
9310 | nla_for_each_nested(nl, nl_vendor_reply, rem) { | |
9311 | wpabuf_put_data(buf, nla_data(nl), nla_len(nl)); | |
9312 | } | |
9313 | ||
9314 | return NL_SKIP; | |
9315 | } | |
9316 | ||
9317 | ||
9318 | static int nl80211_vendor_cmd(void *priv, unsigned int vendor_id, | |
9319 | unsigned int subcmd, const u8 *data, | |
9320 | size_t data_len, struct wpabuf *buf) | |
9321 | { | |
9322 | struct i802_bss *bss = priv; | |
9323 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
9324 | struct nl_msg *msg; | |
9325 | int ret; | |
9326 | ||
6b9f7af6 JM |
9327 | #ifdef CONFIG_TESTING_OPTIONS |
9328 | if (vendor_id == 0xffffffff) { | |
56f77852 JM |
9329 | msg = nlmsg_alloc(); |
9330 | if (!msg) | |
9331 | return -ENOMEM; | |
9332 | ||
6b9f7af6 JM |
9333 | nl80211_cmd(drv, msg, 0, subcmd); |
9334 | if (nlmsg_append(msg, (void *) data, data_len, NLMSG_ALIGNTO) < | |
9335 | 0) | |
a862e4a3 | 9336 | goto fail; |
6b9f7af6 JM |
9337 | ret = send_and_recv_msgs(drv, msg, cmd_reply_handler, buf); |
9338 | if (ret) | |
9339 | wpa_printf(MSG_DEBUG, "nl80211: command failed err=%d", | |
9340 | ret); | |
9341 | return ret; | |
9342 | } | |
9343 | #endif /* CONFIG_TESTING_OPTIONS */ | |
9344 | ||
56f77852 | 9345 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_VENDOR)) || |
a862e4a3 JM |
9346 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, vendor_id) || |
9347 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, subcmd) || | |
9348 | (data && | |
9349 | nla_put(msg, NL80211_ATTR_VENDOR_DATA, data_len, data))) | |
9350 | goto fail; | |
adef8948 BL |
9351 | |
9352 | ret = send_and_recv_msgs(drv, msg, vendor_reply_handler, buf); | |
9353 | if (ret) | |
9354 | wpa_printf(MSG_DEBUG, "nl80211: vendor command failed err=%d", | |
9355 | ret); | |
9356 | return ret; | |
9357 | ||
a862e4a3 | 9358 | fail: |
adef8948 BL |
9359 | nlmsg_free(msg); |
9360 | return -ENOBUFS; | |
9361 | } | |
9362 | ||
9363 | ||
049105b4 KP |
9364 | static int nl80211_set_qos_map(void *priv, const u8 *qos_map_set, |
9365 | u8 qos_map_set_len) | |
9366 | { | |
9367 | struct i802_bss *bss = priv; | |
9368 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
9369 | struct nl_msg *msg; | |
9370 | int ret; | |
9371 | ||
049105b4 KP |
9372 | wpa_hexdump(MSG_DEBUG, "nl80211: Setting QoS Map", |
9373 | qos_map_set, qos_map_set_len); | |
9374 | ||
9725b784 | 9375 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_QOS_MAP)) || |
a862e4a3 JM |
9376 | nla_put(msg, NL80211_ATTR_QOS_MAP, qos_map_set_len, qos_map_set)) { |
9377 | nlmsg_free(msg); | |
9378 | return -ENOBUFS; | |
9379 | } | |
049105b4 KP |
9380 | |
9381 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
9382 | if (ret) | |
9383 | wpa_printf(MSG_DEBUG, "nl80211: Setting QoS Map failed"); | |
9384 | ||
9385 | return ret; | |
049105b4 KP |
9386 | } |
9387 | ||
9388 | ||
82ba4f2d MC |
9389 | static int get_wowlan_handler(struct nl_msg *msg, void *arg) |
9390 | { | |
9391 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
9392 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
9393 | int *wowlan_enabled = arg; | |
9394 | ||
9395 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
9396 | genlmsg_attrlen(gnlh, 0), NULL); | |
9397 | ||
9398 | *wowlan_enabled = !!tb[NL80211_ATTR_WOWLAN_TRIGGERS]; | |
9399 | ||
9400 | return NL_SKIP; | |
9401 | } | |
9402 | ||
9403 | ||
9404 | static int nl80211_get_wowlan(void *priv) | |
9405 | { | |
9406 | struct i802_bss *bss = priv; | |
9407 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
9408 | struct nl_msg *msg; | |
9409 | int wowlan_enabled; | |
9410 | int ret; | |
9411 | ||
9412 | wpa_printf(MSG_DEBUG, "nl80211: Getting wowlan status"); | |
9413 | ||
9414 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_GET_WOWLAN); | |
9415 | ||
9416 | ret = send_and_recv_msgs(drv, msg, get_wowlan_handler, &wowlan_enabled); | |
9417 | if (ret) { | |
9418 | wpa_printf(MSG_DEBUG, "nl80211: Getting wowlan status failed"); | |
9419 | return 0; | |
9420 | } | |
9421 | ||
9422 | wpa_printf(MSG_DEBUG, "nl80211: wowlan is %s", | |
9423 | wowlan_enabled ? "enabled" : "disabled"); | |
9424 | ||
9425 | return wowlan_enabled; | |
9426 | } | |
9427 | ||
9428 | ||
e4fa8b12 EP |
9429 | static int nl80211_set_wowlan(void *priv, |
9430 | const struct wowlan_triggers *triggers) | |
9431 | { | |
9432 | struct i802_bss *bss = priv; | |
9433 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
9434 | struct nl_msg *msg; | |
9435 | struct nlattr *wowlan_triggers; | |
9436 | int ret; | |
9437 | ||
e4fa8b12 EP |
9438 | wpa_printf(MSG_DEBUG, "nl80211: Setting wowlan"); |
9439 | ||
1ac977bd | 9440 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_SET_WOWLAN)) || |
a862e4a3 JM |
9441 | !(wowlan_triggers = nla_nest_start(msg, |
9442 | NL80211_ATTR_WOWLAN_TRIGGERS)) || | |
9443 | (triggers->any && | |
9444 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || | |
9445 | (triggers->disconnect && | |
9446 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || | |
9447 | (triggers->magic_pkt && | |
9448 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || | |
9449 | (triggers->gtk_rekey_failure && | |
9450 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || | |
9451 | (triggers->eap_identity_req && | |
9452 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || | |
9453 | (triggers->four_way_handshake && | |
9454 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || | |
9455 | (triggers->rfkill_release && | |
9456 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) { | |
9457 | nlmsg_free(msg); | |
9458 | return -ENOBUFS; | |
9459 | } | |
e4fa8b12 EP |
9460 | |
9461 | nla_nest_end(msg, wowlan_triggers); | |
9462 | ||
9463 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
9464 | if (ret) | |
9465 | wpa_printf(MSG_DEBUG, "nl80211: Setting wowlan failed"); | |
9466 | ||
9467 | return ret; | |
e4fa8b12 EP |
9468 | } |
9469 | ||
9470 | ||
b658547d | 9471 | #ifdef CONFIG_DRIVER_NL80211_QCA |
0800f9ee JM |
9472 | static int nl80211_roaming(void *priv, int allowed, const u8 *bssid) |
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: Roaming policy: allowed=%d", allowed); | |
9480 | ||
9481 | if (!drv->roaming_vendor_cmd_avail) { | |
9482 | wpa_printf(MSG_DEBUG, | |
9483 | "nl80211: Ignore roaming policy change since driver does not provide command for setting it"); | |
9484 | return -1; | |
9485 | } | |
9486 | ||
9725b784 | 9487 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
a862e4a3 JM |
9488 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
9489 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | |
9490 | QCA_NL80211_VENDOR_SUBCMD_ROAMING) || | |
9491 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || | |
9492 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_ROAMING_POLICY, | |
9493 | allowed ? QCA_ROAMING_ALLOWED_WITHIN_ESS : | |
9494 | QCA_ROAMING_NOT_ALLOWED) || | |
9495 | (bssid && | |
9496 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_MAC_ADDR, ETH_ALEN, bssid))) { | |
9497 | nlmsg_free(msg); | |
9498 | return -1; | |
9499 | } | |
0800f9ee JM |
9500 | nla_nest_end(msg, params); |
9501 | ||
9502 | return send_and_recv_msgs(drv, msg, NULL, NULL); | |
0800f9ee | 9503 | } |
b04854ce AP |
9504 | |
9505 | ||
d98038bb | 9506 | static int nl80211_disable_fils(void *priv, int disable) |
9507 | { | |
9508 | struct i802_bss *bss = priv; | |
9509 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
9510 | struct nl_msg *msg; | |
9511 | struct nlattr *params; | |
9512 | ||
9513 | wpa_printf(MSG_DEBUG, "nl80211: Disable FILS=%d", disable); | |
9514 | ||
9515 | if (!drv->set_wifi_conf_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_SET_WIFI_CONFIGURATION) || | |
9522 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || | |
9523 | nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_DISABLE_FILS, | |
9524 | disable)) { | |
9525 | nlmsg_free(msg); | |
9526 | return -1; | |
9527 | } | |
9528 | nla_nest_end(msg, params); | |
9529 | ||
9530 | return send_and_recv_msgs(drv, msg, NULL, NULL); | |
9531 | } | |
9532 | ||
9533 | ||
b04854ce AP |
9534 | /* Reserved QCA_WLAN_VENDOR_ATTR_ROAMING_REQ_ID value for wpa_supplicant */ |
9535 | #define WPA_SUPPLICANT_CLIENT_ID 1 | |
9536 | ||
9537 | static int nl80211_set_bssid_blacklist(void *priv, unsigned int num_bssid, | |
9538 | const u8 *bssid) | |
9539 | { | |
9540 | struct i802_bss *bss = priv; | |
9541 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
9542 | struct nl_msg *msg; | |
9543 | struct nlattr *params, *nlbssids, *attr; | |
9544 | unsigned int i; | |
9545 | ||
9546 | wpa_printf(MSG_DEBUG, "nl80211: Set blacklist BSSID (num=%u)", | |
9547 | num_bssid); | |
9548 | ||
9549 | if (!drv->roam_vendor_cmd_avail) | |
9550 | return -1; | |
9551 | ||
9552 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || | |
9553 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || | |
9554 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | |
9555 | QCA_NL80211_VENDOR_SUBCMD_ROAM) || | |
9556 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || | |
9557 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_ROAMING_SUBCMD, | |
1425caac | 9558 | QCA_WLAN_VENDOR_ROAMING_SUBCMD_SET_BLACKLIST_BSSID) || |
b04854ce AP |
9559 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_ROAMING_REQ_ID, |
9560 | WPA_SUPPLICANT_CLIENT_ID) || | |
9561 | nla_put_u32(msg, | |
9562 | QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_SET_BSSID_PARAMS_NUM_BSSID, | |
9563 | num_bssid)) | |
9564 | goto fail; | |
9565 | ||
9566 | nlbssids = nla_nest_start( | |
9567 | msg, QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_SET_BSSID_PARAMS); | |
9568 | if (!nlbssids) | |
9569 | goto fail; | |
9570 | ||
9571 | for (i = 0; i < num_bssid; i++) { | |
9572 | attr = nla_nest_start(msg, i); | |
9573 | if (!attr) | |
9574 | goto fail; | |
9575 | if (nla_put(msg, | |
9576 | QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_SET_BSSID_PARAMS_BSSID, | |
9577 | ETH_ALEN, &bssid[i * ETH_ALEN])) | |
9578 | goto fail; | |
9579 | wpa_printf(MSG_DEBUG, "nl80211: BSSID[%u]: " MACSTR, i, | |
9580 | MAC2STR(&bssid[i * ETH_ALEN])); | |
9581 | nla_nest_end(msg, attr); | |
9582 | } | |
9583 | nla_nest_end(msg, nlbssids); | |
9584 | nla_nest_end(msg, params); | |
9585 | ||
9586 | return send_and_recv_msgs(drv, msg, NULL, NULL); | |
9587 | ||
9588 | fail: | |
9589 | nlmsg_free(msg); | |
9590 | return -1; | |
9591 | } | |
9592 | ||
df3b2e22 SSG |
9593 | |
9594 | static int nl80211_add_sta_node(void *priv, const u8 *addr, u16 auth_alg) | |
9595 | { | |
9596 | struct i802_bss *bss = priv; | |
9597 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
9598 | struct nl_msg *msg; | |
9599 | struct nlattr *params; | |
9600 | ||
9601 | if (!drv->add_sta_node_vendor_cmd_avail) | |
9602 | return -EOPNOTSUPP; | |
9603 | ||
9604 | wpa_printf(MSG_DEBUG, "nl80211: Add STA node"); | |
9605 | ||
9606 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || | |
9607 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || | |
9608 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | |
9609 | QCA_NL80211_VENDOR_SUBCMD_ADD_STA_NODE) || | |
9610 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || | |
9611 | (addr && | |
9612 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_ADD_STA_NODE_MAC_ADDR, ETH_ALEN, | |
9613 | addr)) || | |
9614 | nla_put_u16(msg, QCA_WLAN_VENDOR_ATTR_ADD_STA_NODE_AUTH_ALGO, | |
9615 | auth_alg)) { | |
9616 | nlmsg_free(msg); | |
9617 | wpa_printf(MSG_ERROR, | |
9618 | "%s: err in adding vendor_cmd and vendor_data", | |
9619 | __func__); | |
9620 | return -1; | |
9621 | } | |
9622 | nla_nest_end(msg, params); | |
9623 | ||
9624 | return send_and_recv_msgs(drv, msg, NULL, NULL); | |
9625 | } | |
9626 | ||
b658547d | 9627 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
0800f9ee JM |
9628 | |
9629 | ||
fee354c7 JM |
9630 | static int nl80211_set_mac_addr(void *priv, const u8 *addr) |
9631 | { | |
9632 | struct i802_bss *bss = priv; | |
9633 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
9634 | int new_addr = addr != NULL; | |
9635 | ||
9ce3e610 JM |
9636 | if (TEST_FAIL()) |
9637 | return -1; | |
9638 | ||
fee354c7 JM |
9639 | if (!addr) |
9640 | addr = drv->perm_addr; | |
9641 | ||
9642 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 0) < 0) | |
9643 | return -1; | |
9644 | ||
9645 | if (linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname, addr) < 0) | |
9646 | { | |
9647 | wpa_printf(MSG_DEBUG, | |
9648 | "nl80211: failed to set_mac_addr for %s to " MACSTR, | |
9649 | bss->ifname, MAC2STR(addr)); | |
9650 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, | |
9651 | 1) < 0) { | |
9652 | wpa_printf(MSG_DEBUG, | |
9653 | "nl80211: Could not restore interface UP after failed set_mac_addr"); | |
9654 | } | |
9655 | return -1; | |
9656 | } | |
9657 | ||
9658 | wpa_printf(MSG_DEBUG, "nl80211: set_mac_addr for %s to " MACSTR, | |
9659 | bss->ifname, MAC2STR(addr)); | |
9660 | drv->addr_changed = new_addr; | |
9661 | os_memcpy(bss->addr, addr, ETH_ALEN); | |
9662 | ||
9663 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 1) < 0) | |
9664 | { | |
9665 | wpa_printf(MSG_DEBUG, | |
9666 | "nl80211: Could not restore interface UP after set_mac_addr"); | |
9667 | } | |
9668 | ||
9669 | return 0; | |
9670 | } | |
9671 | ||
9672 | ||
6c1664f6 BC |
9673 | #ifdef CONFIG_MESH |
9674 | ||
9675 | static int wpa_driver_nl80211_init_mesh(void *priv) | |
9676 | { | |
9677 | if (wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_MESH_POINT)) { | |
9678 | wpa_printf(MSG_INFO, | |
9679 | "nl80211: Failed to set interface into mesh mode"); | |
9680 | return -1; | |
9681 | } | |
9682 | return 0; | |
9683 | } | |
9684 | ||
9685 | ||
21c74e84 JM |
9686 | static int nl80211_put_mesh_id(struct nl_msg *msg, const u8 *mesh_id, |
9687 | size_t mesh_id_len) | |
9688 | { | |
9689 | if (mesh_id) { | |
21cd8f83 JM |
9690 | wpa_printf(MSG_DEBUG, " * Mesh ID (SSID)=%s", |
9691 | wpa_ssid_txt(mesh_id, mesh_id_len)); | |
21c74e84 JM |
9692 | return nla_put(msg, NL80211_ATTR_MESH_ID, mesh_id_len, mesh_id); |
9693 | } | |
9694 | ||
9695 | return 0; | |
9696 | } | |
9697 | ||
9698 | ||
4ffb3f87 MH |
9699 | static int nl80211_put_mesh_config(struct nl_msg *msg, |
9700 | struct wpa_driver_mesh_bss_params *params) | |
9701 | { | |
9702 | struct nlattr *container; | |
9703 | ||
9704 | container = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); | |
9705 | if (!container) | |
9706 | return -1; | |
9707 | ||
2bd62171 | 9708 | if (((params->flags & WPA_DRIVER_MESH_CONF_FLAG_AUTO_PLINKS) && |
963d3149 JM |
9709 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
9710 | params->auto_plinks)) || | |
2bd62171 MH |
9711 | ((params->flags & WPA_DRIVER_MESH_CONF_FLAG_MAX_PEER_LINKS) && |
9712 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, | |
31a856a1 MH |
9713 | params->max_peer_links)) || |
9714 | ((params->flags & WPA_DRIVER_MESH_CONF_FLAG_RSSI_THRESHOLD) && | |
9715 | nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, | |
9716 | params->rssi_threshold))) | |
4ffb3f87 MH |
9717 | return -1; |
9718 | ||
9719 | /* | |
9720 | * Set NL80211_MESHCONF_PLINK_TIMEOUT even if user mpm is used because | |
9721 | * the timer could disconnect stations even in that case. | |
9722 | */ | |
2bd62171 MH |
9723 | if ((params->flags & WPA_DRIVER_MESH_CONF_FLAG_PEER_LINK_TIMEOUT) && |
9724 | nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, | |
4ffb3f87 MH |
9725 | params->peer_link_timeout)) { |
9726 | wpa_printf(MSG_ERROR, "nl80211: Failed to set PLINK_TIMEOUT"); | |
9727 | return -1; | |
9728 | } | |
9729 | ||
052b8d38 MH |
9730 | if ((params->flags & WPA_DRIVER_MESH_CONF_FLAG_HT_OP_MODE) && |
9731 | nla_put_u16(msg, NL80211_MESHCONF_HT_OPMODE, params->ht_opmode)) { | |
9732 | wpa_printf(MSG_ERROR, "nl80211: Failed to set HT_OP_MODE"); | |
9733 | return -1; | |
9734 | } | |
9735 | ||
4ffb3f87 MH |
9736 | nla_nest_end(msg, container); |
9737 | ||
9738 | return 0; | |
9739 | } | |
9740 | ||
9741 | ||
0cb5f8d9 | 9742 | static int nl80211_join_mesh(struct i802_bss *bss, |
6c1664f6 BC |
9743 | struct wpa_driver_mesh_join_params *params) |
9744 | { | |
6c1664f6 BC |
9745 | struct wpa_driver_nl80211_data *drv = bss->drv; |
9746 | struct nl_msg *msg; | |
9747 | struct nlattr *container; | |
7451a217 | 9748 | int ret = -1; |
6c1664f6 | 9749 | |
6c1664f6 | 9750 | wpa_printf(MSG_DEBUG, "nl80211: mesh join (ifindex=%d)", drv->ifindex); |
9725b784 | 9751 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_JOIN_MESH); |
f7e889fa JM |
9752 | if (!msg || |
9753 | nl80211_put_freq_params(msg, ¶ms->freq) || | |
21c74e84 JM |
9754 | nl80211_put_basic_rates(msg, params->basic_rates) || |
9755 | nl80211_put_mesh_id(msg, params->meshid, params->meshid_len) || | |
4ac2ea57 MH |
9756 | nl80211_put_beacon_int(msg, params->beacon_int) || |
9757 | nl80211_put_dtim_period(msg, params->dtim_period)) | |
85e1fad8 | 9758 | goto fail; |
9c58c5f7 | 9759 | |
6c1664f6 BC |
9760 | wpa_printf(MSG_DEBUG, " * flags=%08X", params->flags); |
9761 | ||
9762 | container = nla_nest_start(msg, NL80211_ATTR_MESH_SETUP); | |
9763 | if (!container) | |
a862e4a3 | 9764 | goto fail; |
6c1664f6 BC |
9765 | |
9766 | if (params->ies) { | |
9767 | wpa_hexdump(MSG_DEBUG, " * IEs", params->ies, params->ie_len); | |
a862e4a3 JM |
9768 | if (nla_put(msg, NL80211_MESH_SETUP_IE, params->ie_len, |
9769 | params->ies)) | |
9770 | goto fail; | |
6c1664f6 BC |
9771 | } |
9772 | /* WPA_DRIVER_MESH_FLAG_OPEN_AUTH is treated as default by nl80211 */ | |
9773 | if (params->flags & WPA_DRIVER_MESH_FLAG_SAE_AUTH) { | |
a862e4a3 JM |
9774 | if (nla_put_u8(msg, NL80211_MESH_SETUP_AUTH_PROTOCOL, 0x1) || |
9775 | nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_AUTH)) | |
9776 | goto fail; | |
6c1664f6 | 9777 | } |
a862e4a3 JM |
9778 | if ((params->flags & WPA_DRIVER_MESH_FLAG_AMPE) && |
9779 | nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_AMPE)) | |
9780 | goto fail; | |
9781 | if ((params->flags & WPA_DRIVER_MESH_FLAG_USER_MPM) && | |
9782 | nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_MPM)) | |
9783 | goto fail; | |
6c1664f6 BC |
9784 | nla_nest_end(msg, container); |
9785 | ||
2bd62171 MH |
9786 | params->conf.flags |= WPA_DRIVER_MESH_CONF_FLAG_AUTO_PLINKS; |
9787 | params->conf.flags |= WPA_DRIVER_MESH_CONF_FLAG_PEER_LINK_TIMEOUT; | |
9788 | params->conf.flags |= WPA_DRIVER_MESH_CONF_FLAG_MAX_PEER_LINKS; | |
4ffb3f87 | 9789 | if (nl80211_put_mesh_config(msg, ¶ms->conf) < 0) |
5a2a6de6 | 9790 | goto fail; |
6c1664f6 BC |
9791 | |
9792 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
9793 | msg = NULL; | |
9794 | if (ret) { | |
9795 | wpa_printf(MSG_DEBUG, "nl80211: mesh join failed: ret=%d (%s)", | |
9796 | ret, strerror(-ret)); | |
a862e4a3 | 9797 | goto fail; |
6c1664f6 BC |
9798 | } |
9799 | ret = 0; | |
92a515b8 | 9800 | drv->assoc_freq = bss->freq = params->freq.freq; |
6c1664f6 BC |
9801 | wpa_printf(MSG_DEBUG, "nl80211: mesh join request send successfully"); |
9802 | ||
a862e4a3 | 9803 | fail: |
6c1664f6 BC |
9804 | nlmsg_free(msg); |
9805 | return ret; | |
9806 | } | |
9807 | ||
9808 | ||
0cb5f8d9 MH |
9809 | static int |
9810 | wpa_driver_nl80211_join_mesh(void *priv, | |
9811 | struct wpa_driver_mesh_join_params *params) | |
9812 | { | |
9813 | struct i802_bss *bss = priv; | |
9814 | int ret, timeout; | |
9815 | ||
9816 | timeout = params->conf.peer_link_timeout; | |
9817 | ||
9818 | /* Disable kernel inactivity timer */ | |
9819 | if (params->flags & WPA_DRIVER_MESH_FLAG_USER_MPM) | |
9820 | params->conf.peer_link_timeout = 0; | |
9821 | ||
9822 | ret = nl80211_join_mesh(bss, params); | |
9823 | if (ret == -EINVAL && params->conf.peer_link_timeout == 0) { | |
9824 | wpa_printf(MSG_DEBUG, | |
9825 | "nl80211: Mesh join retry for peer_link_timeout"); | |
9826 | /* | |
9827 | * Old kernel does not support setting | |
9828 | * NL80211_MESHCONF_PLINK_TIMEOUT to zero, so set 60 seconds | |
9829 | * into future from peer_link_timeout. | |
9830 | */ | |
9831 | params->conf.peer_link_timeout = timeout + 60; | |
9832 | ret = nl80211_join_mesh(priv, params); | |
9833 | } | |
9834 | ||
9835 | params->conf.peer_link_timeout = timeout; | |
9836 | return ret; | |
9837 | } | |
9838 | ||
9839 | ||
6c1664f6 BC |
9840 | static int wpa_driver_nl80211_leave_mesh(void *priv) |
9841 | { | |
9842 | struct i802_bss *bss = priv; | |
9843 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
9844 | struct nl_msg *msg; | |
9725b784 | 9845 | int ret; |
6c1664f6 BC |
9846 | |
9847 | wpa_printf(MSG_DEBUG, "nl80211: mesh leave (ifindex=%d)", drv->ifindex); | |
9725b784 | 9848 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_LEAVE_MESH); |
6c1664f6 | 9849 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
6c1664f6 BC |
9850 | if (ret) { |
9851 | wpa_printf(MSG_DEBUG, "nl80211: mesh leave failed: ret=%d (%s)", | |
9852 | ret, strerror(-ret)); | |
a862e4a3 JM |
9853 | } else { |
9854 | wpa_printf(MSG_DEBUG, | |
9855 | "nl80211: mesh leave request send successfully"); | |
6c1664f6 | 9856 | } |
6c1664f6 | 9857 | |
f33c82d2 JM |
9858 | if (wpa_driver_nl80211_set_mode(drv->first_bss, |
9859 | NL80211_IFTYPE_STATION)) { | |
9860 | wpa_printf(MSG_INFO, | |
9861 | "nl80211: Failed to set interface into station mode"); | |
9862 | } | |
6c1664f6 BC |
9863 | return ret; |
9864 | } | |
9865 | ||
c36109e4 PKC |
9866 | |
9867 | static int nl80211_probe_mesh_link(void *priv, const u8 *addr, const u8 *eth, | |
9868 | size_t len) | |
9869 | { | |
9870 | struct i802_bss *bss = priv; | |
9871 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
9872 | struct nl_msg *msg; | |
9873 | int ret; | |
9874 | ||
9875 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_PROBE_MESH_LINK); | |
9876 | if (!msg || | |
9877 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || | |
9878 | nla_put(msg, NL80211_ATTR_FRAME, len, eth)) { | |
9879 | nlmsg_free(msg); | |
9880 | return -ENOBUFS; | |
9881 | } | |
9882 | ||
9883 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
9884 | if (ret) { | |
9885 | wpa_printf(MSG_DEBUG, "nl80211: mesh link probe to " MACSTR | |
9886 | " failed: ret=%d (%s)", | |
9887 | MAC2STR(addr), ret, strerror(-ret)); | |
9888 | } else { | |
9889 | wpa_printf(MSG_DEBUG, "nl80211: Mesh link to " MACSTR | |
9890 | " probed successfully", MAC2STR(addr)); | |
9891 | } | |
9892 | ||
9893 | return ret; | |
9894 | } | |
9895 | ||
6c1664f6 BC |
9896 | #endif /* CONFIG_MESH */ |
9897 | ||
9898 | ||
ed4ddb6d KP |
9899 | static int wpa_driver_br_add_ip_neigh(void *priv, u8 version, |
9900 | const u8 *ipaddr, int prefixlen, | |
9901 | const u8 *addr) | |
71103bed KP |
9902 | { |
9903 | #ifdef CONFIG_LIBNL3_ROUTE | |
9904 | struct i802_bss *bss = priv; | |
9905 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
9906 | struct rtnl_neigh *rn; | |
9907 | struct nl_addr *nl_ipaddr = NULL; | |
9908 | struct nl_addr *nl_lladdr = NULL; | |
ed4ddb6d | 9909 | int family, addrsize; |
71103bed KP |
9910 | int res; |
9911 | ||
ed4ddb6d | 9912 | if (!ipaddr || prefixlen == 0 || !addr) |
71103bed KP |
9913 | return -EINVAL; |
9914 | ||
9915 | if (bss->br_ifindex == 0) { | |
9916 | wpa_printf(MSG_DEBUG, | |
9917 | "nl80211: bridge must be set before adding an ip neigh to it"); | |
9918 | return -1; | |
9919 | } | |
9920 | ||
9921 | if (!drv->rtnl_sk) { | |
9922 | wpa_printf(MSG_DEBUG, | |
9923 | "nl80211: nl_sock for NETLINK_ROUTE is not initialized"); | |
9924 | return -1; | |
9925 | } | |
9926 | ||
ed4ddb6d KP |
9927 | if (version == 4) { |
9928 | family = AF_INET; | |
9929 | addrsize = 4; | |
9930 | } else if (version == 6) { | |
9931 | family = AF_INET6; | |
9932 | addrsize = 16; | |
9933 | } else { | |
9934 | return -EINVAL; | |
9935 | } | |
9936 | ||
71103bed KP |
9937 | rn = rtnl_neigh_alloc(); |
9938 | if (rn == NULL) | |
9939 | return -ENOMEM; | |
9940 | ||
9941 | /* set the destination ip address for neigh */ | |
ed4ddb6d | 9942 | nl_ipaddr = nl_addr_build(family, (void *) ipaddr, addrsize); |
71103bed KP |
9943 | if (nl_ipaddr == NULL) { |
9944 | wpa_printf(MSG_DEBUG, "nl80211: nl_ipaddr build failed"); | |
9945 | res = -ENOMEM; | |
9946 | goto errout; | |
9947 | } | |
9948 | nl_addr_set_prefixlen(nl_ipaddr, prefixlen); | |
9949 | res = rtnl_neigh_set_dst(rn, nl_ipaddr); | |
9950 | if (res) { | |
9951 | wpa_printf(MSG_DEBUG, | |
9952 | "nl80211: neigh set destination addr failed"); | |
9953 | goto errout; | |
9954 | } | |
9955 | ||
9956 | /* set the corresponding lladdr for neigh */ | |
9957 | nl_lladdr = nl_addr_build(AF_BRIDGE, (u8 *) addr, ETH_ALEN); | |
9958 | if (nl_lladdr == NULL) { | |
9959 | wpa_printf(MSG_DEBUG, "nl80211: neigh set lladdr failed"); | |
9960 | res = -ENOMEM; | |
9961 | goto errout; | |
9962 | } | |
9963 | rtnl_neigh_set_lladdr(rn, nl_lladdr); | |
9964 | ||
9965 | rtnl_neigh_set_ifindex(rn, bss->br_ifindex); | |
9966 | rtnl_neigh_set_state(rn, NUD_PERMANENT); | |
9967 | ||
9968 | res = rtnl_neigh_add(drv->rtnl_sk, rn, NLM_F_CREATE); | |
9969 | if (res) { | |
9970 | wpa_printf(MSG_DEBUG, | |
9971 | "nl80211: Adding bridge ip neigh failed: %s", | |
3ea58a05 | 9972 | nl_geterror(res)); |
71103bed KP |
9973 | } |
9974 | errout: | |
9975 | if (nl_lladdr) | |
9976 | nl_addr_put(nl_lladdr); | |
9977 | if (nl_ipaddr) | |
9978 | nl_addr_put(nl_ipaddr); | |
9979 | if (rn) | |
9980 | rtnl_neigh_put(rn); | |
9981 | return res; | |
9982 | #else /* CONFIG_LIBNL3_ROUTE */ | |
9983 | return -1; | |
9984 | #endif /* CONFIG_LIBNL3_ROUTE */ | |
9985 | } | |
9986 | ||
9987 | ||
ed4ddb6d KP |
9988 | static int wpa_driver_br_delete_ip_neigh(void *priv, u8 version, |
9989 | const u8 *ipaddr) | |
71103bed KP |
9990 | { |
9991 | #ifdef CONFIG_LIBNL3_ROUTE | |
9992 | struct i802_bss *bss = priv; | |
9993 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
9994 | struct rtnl_neigh *rn; | |
9995 | struct nl_addr *nl_ipaddr; | |
ed4ddb6d | 9996 | int family, addrsize; |
71103bed KP |
9997 | int res; |
9998 | ||
ed4ddb6d | 9999 | if (!ipaddr) |
71103bed KP |
10000 | return -EINVAL; |
10001 | ||
ed4ddb6d KP |
10002 | if (version == 4) { |
10003 | family = AF_INET; | |
10004 | addrsize = 4; | |
10005 | } else if (version == 6) { | |
10006 | family = AF_INET6; | |
10007 | addrsize = 16; | |
10008 | } else { | |
10009 | return -EINVAL; | |
10010 | } | |
10011 | ||
71103bed KP |
10012 | if (bss->br_ifindex == 0) { |
10013 | wpa_printf(MSG_DEBUG, | |
10014 | "nl80211: bridge must be set to delete an ip neigh"); | |
10015 | return -1; | |
10016 | } | |
10017 | ||
10018 | if (!drv->rtnl_sk) { | |
10019 | wpa_printf(MSG_DEBUG, | |
10020 | "nl80211: nl_sock for NETLINK_ROUTE is not initialized"); | |
10021 | return -1; | |
10022 | } | |
10023 | ||
10024 | rn = rtnl_neigh_alloc(); | |
10025 | if (rn == NULL) | |
10026 | return -ENOMEM; | |
10027 | ||
10028 | /* set the destination ip address for neigh */ | |
ed4ddb6d | 10029 | nl_ipaddr = nl_addr_build(family, (void *) ipaddr, addrsize); |
71103bed KP |
10030 | if (nl_ipaddr == NULL) { |
10031 | wpa_printf(MSG_DEBUG, "nl80211: nl_ipaddr build failed"); | |
10032 | res = -ENOMEM; | |
10033 | goto errout; | |
10034 | } | |
10035 | res = rtnl_neigh_set_dst(rn, nl_ipaddr); | |
10036 | if (res) { | |
10037 | wpa_printf(MSG_DEBUG, | |
10038 | "nl80211: neigh set destination addr failed"); | |
10039 | goto errout; | |
10040 | } | |
10041 | ||
10042 | rtnl_neigh_set_ifindex(rn, bss->br_ifindex); | |
10043 | ||
10044 | res = rtnl_neigh_delete(drv->rtnl_sk, rn, 0); | |
10045 | if (res) { | |
10046 | wpa_printf(MSG_DEBUG, | |
10047 | "nl80211: Deleting bridge ip neigh failed: %s", | |
3ea58a05 | 10048 | nl_geterror(res)); |
71103bed KP |
10049 | } |
10050 | errout: | |
10051 | if (nl_ipaddr) | |
10052 | nl_addr_put(nl_ipaddr); | |
10053 | if (rn) | |
10054 | rtnl_neigh_put(rn); | |
10055 | return res; | |
10056 | #else /* CONFIG_LIBNL3_ROUTE */ | |
10057 | return -1; | |
10058 | #endif /* CONFIG_LIBNL3_ROUTE */ | |
10059 | } | |
10060 | ||
10061 | ||
73d2294f KP |
10062 | static int linux_write_system_file(const char *path, unsigned int val) |
10063 | { | |
10064 | char buf[50]; | |
10065 | int fd, len; | |
10066 | ||
10067 | len = os_snprintf(buf, sizeof(buf), "%u\n", val); | |
a9aaacbb | 10068 | if (os_snprintf_error(sizeof(buf), len)) |
73d2294f KP |
10069 | return -1; |
10070 | ||
10071 | fd = open(path, O_WRONLY); | |
10072 | if (fd < 0) | |
10073 | return -1; | |
10074 | ||
10075 | if (write(fd, buf, len) < 0) { | |
10076 | wpa_printf(MSG_DEBUG, | |
10077 | "nl80211: Failed to write Linux system file: %s with the value of %d", | |
10078 | path, val); | |
10079 | close(fd); | |
10080 | return -1; | |
10081 | } | |
10082 | close(fd); | |
10083 | ||
10084 | return 0; | |
10085 | } | |
10086 | ||
10087 | ||
10088 | static const char * drv_br_port_attr_str(enum drv_br_port_attr attr) | |
10089 | { | |
10090 | switch (attr) { | |
10091 | case DRV_BR_PORT_ATTR_PROXYARP: | |
bea8d9a3 | 10092 | return "proxyarp_wifi"; |
73d2294f KP |
10093 | case DRV_BR_PORT_ATTR_HAIRPIN_MODE: |
10094 | return "hairpin_mode"; | |
10095 | } | |
10096 | ||
10097 | return NULL; | |
10098 | } | |
10099 | ||
10100 | ||
10101 | static int wpa_driver_br_port_set_attr(void *priv, enum drv_br_port_attr attr, | |
10102 | unsigned int val) | |
10103 | { | |
10104 | struct i802_bss *bss = priv; | |
10105 | char path[128]; | |
10106 | const char *attr_txt; | |
10107 | ||
10108 | attr_txt = drv_br_port_attr_str(attr); | |
10109 | if (attr_txt == NULL) | |
10110 | return -EINVAL; | |
10111 | ||
10112 | os_snprintf(path, sizeof(path), "/sys/class/net/%s/brport/%s", | |
10113 | bss->ifname, attr_txt); | |
10114 | ||
10115 | if (linux_write_system_file(path, val)) | |
10116 | return -1; | |
10117 | ||
10118 | return 0; | |
10119 | } | |
10120 | ||
10121 | ||
7565752d KP |
10122 | static const char * drv_br_net_param_str(enum drv_br_net_param param) |
10123 | { | |
10124 | switch (param) { | |
10125 | case DRV_BR_NET_PARAM_GARP_ACCEPT: | |
10126 | return "arp_accept"; | |
60eb9e17 JM |
10127 | default: |
10128 | return NULL; | |
7565752d | 10129 | } |
7565752d KP |
10130 | } |
10131 | ||
10132 | ||
10133 | static int wpa_driver_br_set_net_param(void *priv, enum drv_br_net_param param, | |
10134 | unsigned int val) | |
10135 | { | |
10136 | struct i802_bss *bss = priv; | |
10137 | char path[128]; | |
10138 | const char *param_txt; | |
10139 | int ip_version = 4; | |
10140 | ||
60eb9e17 JM |
10141 | if (param == DRV_BR_MULTICAST_SNOOPING) { |
10142 | os_snprintf(path, sizeof(path), | |
10143 | "/sys/devices/virtual/net/%s/bridge/multicast_snooping", | |
10144 | bss->brname); | |
10145 | goto set_val; | |
10146 | } | |
10147 | ||
7565752d KP |
10148 | param_txt = drv_br_net_param_str(param); |
10149 | if (param_txt == NULL) | |
10150 | return -EINVAL; | |
10151 | ||
10152 | switch (param) { | |
10153 | case DRV_BR_NET_PARAM_GARP_ACCEPT: | |
10154 | ip_version = 4; | |
10155 | break; | |
10156 | default: | |
10157 | return -EINVAL; | |
10158 | } | |
10159 | ||
10160 | os_snprintf(path, sizeof(path), "/proc/sys/net/ipv%d/conf/%s/%s", | |
10161 | ip_version, bss->brname, param_txt); | |
10162 | ||
60eb9e17 | 10163 | set_val: |
7565752d KP |
10164 | if (linux_write_system_file(path, val)) |
10165 | return -1; | |
10166 | ||
10167 | return 0; | |
10168 | } | |
10169 | ||
10170 | ||
b658547d JM |
10171 | #ifdef CONFIG_DRIVER_NL80211_QCA |
10172 | ||
16689c7c PX |
10173 | static int hw_mode_to_qca_acs(enum hostapd_hw_mode hw_mode) |
10174 | { | |
10175 | switch (hw_mode) { | |
10176 | case HOSTAPD_MODE_IEEE80211B: | |
10177 | return QCA_ACS_MODE_IEEE80211B; | |
10178 | case HOSTAPD_MODE_IEEE80211G: | |
10179 | return QCA_ACS_MODE_IEEE80211G; | |
10180 | case HOSTAPD_MODE_IEEE80211A: | |
10181 | return QCA_ACS_MODE_IEEE80211A; | |
10182 | case HOSTAPD_MODE_IEEE80211AD: | |
10183 | return QCA_ACS_MODE_IEEE80211AD; | |
3784c058 PX |
10184 | case HOSTAPD_MODE_IEEE80211ANY: |
10185 | return QCA_ACS_MODE_IEEE80211ANY; | |
16689c7c PX |
10186 | default: |
10187 | return -1; | |
10188 | } | |
10189 | } | |
10190 | ||
10191 | ||
e86ba912 AB |
10192 | static int add_acs_ch_list(struct nl_msg *msg, const int *freq_list) |
10193 | { | |
10194 | int num_channels = 0, num_freqs; | |
10195 | u8 *ch_list; | |
10196 | enum hostapd_hw_mode hw_mode; | |
10197 | int ret = 0; | |
10198 | int i; | |
10199 | ||
10200 | if (!freq_list) | |
10201 | return 0; | |
10202 | ||
10203 | num_freqs = int_array_len(freq_list); | |
10204 | ch_list = os_malloc(sizeof(u8) * num_freqs); | |
10205 | if (!ch_list) | |
10206 | return -1; | |
10207 | ||
10208 | for (i = 0; i < num_freqs; i++) { | |
10209 | const int freq = freq_list[i]; | |
10210 | ||
10211 | if (freq == 0) | |
10212 | break; | |
10213 | /* Send 2.4 GHz and 5 GHz channels with | |
10214 | * QCA_WLAN_VENDOR_ATTR_ACS_CH_LIST to maintain backwards | |
10215 | * compatibility. | |
10216 | */ | |
10217 | if (!(freq >= 2412 && freq <= 2484) && | |
10218 | !(freq >= 5180 && freq <= 5900)) | |
10219 | continue; | |
10220 | hw_mode = ieee80211_freq_to_chan(freq, &ch_list[num_channels]); | |
10221 | if (hw_mode != NUM_HOSTAPD_MODES) | |
10222 | num_channels++; | |
10223 | } | |
10224 | ||
10225 | if (num_channels) | |
10226 | ret = nla_put(msg, QCA_WLAN_VENDOR_ATTR_ACS_CH_LIST, | |
10227 | num_channels, ch_list); | |
10228 | ||
10229 | os_free(ch_list); | |
10230 | return ret; | |
10231 | } | |
10232 | ||
10233 | ||
d0cdccd3 PX |
10234 | static int add_acs_freq_list(struct nl_msg *msg, const int *freq_list) |
10235 | { | |
10236 | int i, len, ret; | |
10237 | u32 *freqs; | |
10238 | ||
10239 | if (!freq_list) | |
10240 | return 0; | |
10241 | len = int_array_len(freq_list); | |
10242 | freqs = os_malloc(sizeof(u32) * len); | |
10243 | if (!freqs) | |
10244 | return -1; | |
10245 | for (i = 0; i < len; i++) | |
10246 | freqs[i] = freq_list[i]; | |
10247 | ret = nla_put(msg, QCA_WLAN_VENDOR_ATTR_ACS_FREQ_LIST, | |
10248 | sizeof(u32) * len, freqs); | |
10249 | os_free(freqs); | |
10250 | return ret; | |
10251 | } | |
10252 | ||
10253 | ||
16689c7c PX |
10254 | static int wpa_driver_do_acs(void *priv, struct drv_acs_params *params) |
10255 | { | |
10256 | struct i802_bss *bss = priv; | |
10257 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
10258 | struct nl_msg *msg; | |
10259 | struct nlattr *data; | |
a862e4a3 | 10260 | int ret; |
16689c7c PX |
10261 | int mode; |
10262 | ||
10263 | mode = hw_mode_to_qca_acs(params->hw_mode); | |
10264 | if (mode < 0) | |
10265 | return -1; | |
10266 | ||
9725b784 | 10267 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
a862e4a3 JM |
10268 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
10269 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | |
10270 | QCA_NL80211_VENDOR_SUBCMD_DO_ACS) || | |
10271 | !(data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || | |
10272 | nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_ACS_HW_MODE, mode) || | |
10273 | (params->ht_enabled && | |
10274 | nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_HT_ENABLED)) || | |
10275 | (params->ht40_enabled && | |
857d9422 MM |
10276 | nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_HT40_ENABLED)) || |
10277 | (params->vht_enabled && | |
10278 | nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_VHT_ENABLED)) || | |
10279 | nla_put_u16(msg, QCA_WLAN_VENDOR_ATTR_ACS_CHWIDTH, | |
10280 | params->ch_width) || | |
e86ba912 | 10281 | add_acs_ch_list(msg, params->freq_list) || |
d0cdccd3 | 10282 | add_acs_freq_list(msg, params->freq_list)) { |
a862e4a3 JM |
10283 | nlmsg_free(msg); |
10284 | return -ENOBUFS; | |
10285 | } | |
16689c7c PX |
10286 | nla_nest_end(msg, data); |
10287 | ||
857d9422 | 10288 | wpa_printf(MSG_DEBUG, |
e86ba912 | 10289 | "nl80211: ACS Params: HW_MODE: %d HT: %d HT40: %d VHT: %d BW: %d", |
857d9422 | 10290 | params->hw_mode, params->ht_enabled, params->ht40_enabled, |
e86ba912 | 10291 | params->vht_enabled, params->ch_width); |
857d9422 | 10292 | |
16689c7c | 10293 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
16689c7c PX |
10294 | if (ret) { |
10295 | wpa_printf(MSG_DEBUG, | |
10296 | "nl80211: Failed to invoke driver ACS function: %s", | |
3ea58a05 | 10297 | strerror(-ret)); |
16689c7c | 10298 | } |
16689c7c PX |
10299 | return ret; |
10300 | } | |
10301 | ||
10302 | ||
844dfeb8 SD |
10303 | static int nl80211_set_band(void *priv, enum set_band band) |
10304 | { | |
10305 | struct i802_bss *bss = priv; | |
10306 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
10307 | struct nl_msg *msg; | |
10308 | struct nlattr *data; | |
10309 | int ret; | |
10310 | enum qca_set_band qca_band; | |
10311 | ||
10312 | if (!drv->setband_vendor_cmd_avail) | |
10313 | return -1; | |
10314 | ||
10315 | switch (band) { | |
10316 | case WPA_SETBAND_AUTO: | |
10317 | qca_band = QCA_SETBAND_AUTO; | |
10318 | break; | |
10319 | case WPA_SETBAND_5G: | |
10320 | qca_band = QCA_SETBAND_5G; | |
10321 | break; | |
10322 | case WPA_SETBAND_2G: | |
10323 | qca_band = QCA_SETBAND_2G; | |
10324 | break; | |
10325 | default: | |
10326 | return -1; | |
10327 | } | |
10328 | ||
10329 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || | |
10330 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || | |
10331 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | |
10332 | QCA_NL80211_VENDOR_SUBCMD_SETBAND) || | |
10333 | !(data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || | |
10334 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_SETBAND_VALUE, qca_band)) { | |
10335 | nlmsg_free(msg); | |
10336 | return -ENOBUFS; | |
10337 | } | |
10338 | nla_nest_end(msg, data); | |
10339 | ||
10340 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
10341 | if (ret) { | |
10342 | wpa_printf(MSG_DEBUG, | |
10343 | "nl80211: Driver setband function failed: %s", | |
3ea58a05 | 10344 | strerror(-ret)); |
844dfeb8 SD |
10345 | } |
10346 | return ret; | |
10347 | } | |
10348 | ||
10349 | ||
98342208 AK |
10350 | struct nl80211_pcl { |
10351 | unsigned int num; | |
10352 | unsigned int *freq_list; | |
10353 | }; | |
10354 | ||
10355 | static int preferred_freq_info_handler(struct nl_msg *msg, void *arg) | |
10356 | { | |
10357 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
10358 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
10359 | struct nl80211_pcl *param = arg; | |
10360 | struct nlattr *nl_vend, *attr; | |
10361 | enum qca_iface_type iface_type; | |
10362 | struct nlattr *tb_vendor[QCA_WLAN_VENDOR_ATTR_MAX + 1]; | |
10363 | unsigned int num, max_num; | |
10364 | u32 *freqs; | |
10365 | ||
10366 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
10367 | genlmsg_attrlen(gnlh, 0), NULL); | |
10368 | ||
10369 | nl_vend = tb[NL80211_ATTR_VENDOR_DATA]; | |
10370 | if (!nl_vend) | |
10371 | return NL_SKIP; | |
10372 | ||
10373 | nla_parse(tb_vendor, QCA_WLAN_VENDOR_ATTR_MAX, | |
10374 | nla_data(nl_vend), nla_len(nl_vend), NULL); | |
10375 | ||
10376 | attr = tb_vendor[ | |
10377 | QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST_IFACE_TYPE]; | |
10378 | if (!attr) { | |
10379 | wpa_printf(MSG_ERROR, "nl80211: iface_type couldn't be found"); | |
10380 | param->num = 0; | |
10381 | return NL_SKIP; | |
10382 | } | |
10383 | ||
10384 | iface_type = (enum qca_iface_type) nla_get_u32(attr); | |
10385 | wpa_printf(MSG_DEBUG, "nl80211: Driver returned iface_type=%d", | |
10386 | iface_type); | |
10387 | ||
10388 | attr = tb_vendor[QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST]; | |
10389 | if (!attr) { | |
10390 | wpa_printf(MSG_ERROR, | |
10391 | "nl80211: preferred_freq_list couldn't be found"); | |
10392 | param->num = 0; | |
10393 | return NL_SKIP; | |
10394 | } | |
10395 | ||
10396 | /* | |
10397 | * param->num has the maximum number of entries for which there | |
10398 | * is room in the freq_list provided by the caller. | |
10399 | */ | |
10400 | freqs = nla_data(attr); | |
10401 | max_num = nla_len(attr) / sizeof(u32); | |
10402 | if (max_num > param->num) | |
10403 | max_num = param->num; | |
10404 | for (num = 0; num < max_num; num++) | |
10405 | param->freq_list[num] = freqs[num]; | |
10406 | param->num = num; | |
10407 | ||
10408 | return NL_SKIP; | |
10409 | } | |
10410 | ||
10411 | ||
10412 | static int nl80211_get_pref_freq_list(void *priv, | |
10413 | enum wpa_driver_if_type if_type, | |
10414 | unsigned int *num, | |
10415 | unsigned int *freq_list) | |
10416 | { | |
10417 | struct i802_bss *bss = priv; | |
10418 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
10419 | struct nl_msg *msg; | |
10420 | int ret; | |
10421 | unsigned int i; | |
10422 | struct nlattr *params; | |
10423 | struct nl80211_pcl param; | |
10424 | enum qca_iface_type iface_type; | |
10425 | ||
10426 | if (!drv->get_pref_freq_list) | |
10427 | return -1; | |
10428 | ||
10429 | switch (if_type) { | |
10430 | case WPA_IF_STATION: | |
10431 | iface_type = QCA_IFACE_TYPE_STA; | |
10432 | break; | |
10433 | case WPA_IF_AP_BSS: | |
10434 | iface_type = QCA_IFACE_TYPE_AP; | |
10435 | break; | |
10436 | case WPA_IF_P2P_GO: | |
10437 | iface_type = QCA_IFACE_TYPE_P2P_GO; | |
10438 | break; | |
10439 | case WPA_IF_P2P_CLIENT: | |
10440 | iface_type = QCA_IFACE_TYPE_P2P_CLIENT; | |
10441 | break; | |
10442 | case WPA_IF_IBSS: | |
10443 | iface_type = QCA_IFACE_TYPE_IBSS; | |
10444 | break; | |
10445 | case WPA_IF_TDLS: | |
10446 | iface_type = QCA_IFACE_TYPE_TDLS; | |
10447 | break; | |
10448 | default: | |
10449 | return -1; | |
10450 | } | |
10451 | ||
10452 | param.num = *num; | |
10453 | param.freq_list = freq_list; | |
10454 | ||
10455 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || | |
10456 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, drv->ifindex) || | |
10457 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || | |
10458 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | |
10459 | QCA_NL80211_VENDOR_SUBCMD_GET_PREFERRED_FREQ_LIST) || | |
10460 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || | |
10461 | nla_put_u32(msg, | |
10462 | QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST_IFACE_TYPE, | |
10463 | iface_type)) { | |
10464 | wpa_printf(MSG_ERROR, | |
10465 | "%s: err in adding vendor_cmd and vendor_data", | |
10466 | __func__); | |
10467 | nlmsg_free(msg); | |
10468 | return -1; | |
10469 | } | |
10470 | nla_nest_end(msg, params); | |
10471 | ||
10472 | os_memset(freq_list, 0, *num * sizeof(freq_list[0])); | |
10473 | ret = send_and_recv_msgs(drv, msg, preferred_freq_info_handler, ¶m); | |
10474 | if (ret) { | |
10475 | wpa_printf(MSG_ERROR, | |
10476 | "%s: err in send_and_recv_msgs", __func__); | |
10477 | return ret; | |
10478 | } | |
10479 | ||
10480 | *num = param.num; | |
10481 | ||
10482 | for (i = 0; i < *num; i++) { | |
10483 | wpa_printf(MSG_DEBUG, "nl80211: preferred_channel_list[%d]=%d", | |
10484 | i, freq_list[i]); | |
10485 | } | |
10486 | ||
10487 | return 0; | |
10488 | } | |
10489 | ||
10490 | ||
7c813acf AK |
10491 | static int nl80211_set_prob_oper_freq(void *priv, unsigned int freq) |
10492 | { | |
10493 | struct i802_bss *bss = priv; | |
10494 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
10495 | struct nl_msg *msg; | |
10496 | int ret; | |
10497 | struct nlattr *params; | |
10498 | ||
10499 | if (!drv->set_prob_oper_freq) | |
10500 | return -1; | |
10501 | ||
10502 | wpa_printf(MSG_DEBUG, | |
10503 | "nl80211: Set P2P probable operating freq %u for ifindex %d", | |
10504 | freq, bss->ifindex); | |
10505 | ||
10506 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || | |
10507 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || | |
10508 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | |
10509 | QCA_NL80211_VENDOR_SUBCMD_SET_PROBABLE_OPER_CHANNEL) || | |
10510 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || | |
10511 | nla_put_u32(msg, | |
10512 | QCA_WLAN_VENDOR_ATTR_PROBABLE_OPER_CHANNEL_IFACE_TYPE, | |
10513 | QCA_IFACE_TYPE_P2P_CLIENT) || | |
10514 | nla_put_u32(msg, | |
10515 | QCA_WLAN_VENDOR_ATTR_PROBABLE_OPER_CHANNEL_FREQ, | |
10516 | freq)) { | |
10517 | wpa_printf(MSG_ERROR, | |
10518 | "%s: err in adding vendor_cmd and vendor_data", | |
10519 | __func__); | |
10520 | nlmsg_free(msg); | |
10521 | return -1; | |
10522 | } | |
10523 | nla_nest_end(msg, params); | |
10524 | ||
10525 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
10526 | msg = NULL; | |
10527 | if (ret) { | |
10528 | wpa_printf(MSG_ERROR, "%s: err in send_and_recv_msgs", | |
10529 | __func__); | |
10530 | return ret; | |
10531 | } | |
10532 | nlmsg_free(msg); | |
10533 | return 0; | |
10534 | } | |
10535 | ||
a6f5b193 PX |
10536 | |
10537 | static int nl80211_p2p_lo_start(void *priv, unsigned int freq, | |
10538 | unsigned int period, unsigned int interval, | |
10539 | unsigned int count, const u8 *device_types, | |
10540 | size_t dev_types_len, | |
10541 | const u8 *ies, size_t ies_len) | |
10542 | { | |
10543 | struct i802_bss *bss = priv; | |
10544 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
10545 | struct nl_msg *msg; | |
10546 | struct nlattr *container; | |
10547 | int ret; | |
10548 | ||
10549 | wpa_printf(MSG_DEBUG, | |
10550 | "nl80211: Start P2P Listen offload: freq=%u, period=%u, interval=%u, count=%u", | |
10551 | freq, period, interval, count); | |
10552 | ||
10553 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_P2P_LISTEN_OFFLOAD)) | |
10554 | return -1; | |
10555 | ||
10556 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || | |
10557 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || | |
10558 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | |
10559 | QCA_NL80211_VENDOR_SUBCMD_P2P_LISTEN_OFFLOAD_START)) | |
10560 | goto fail; | |
10561 | ||
10562 | container = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); | |
10563 | if (!container) | |
10564 | goto fail; | |
10565 | ||
10566 | if (nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_CHANNEL, | |
10567 | freq) || | |
10568 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_PERIOD, | |
10569 | period) || | |
10570 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_INTERVAL, | |
10571 | interval) || | |
10572 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_COUNT, | |
10573 | count) || | |
10574 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_DEVICE_TYPES, | |
10575 | dev_types_len, device_types) || | |
10576 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_VENDOR_IE, | |
10577 | ies_len, ies)) | |
10578 | goto fail; | |
10579 | ||
10580 | nla_nest_end(msg, container); | |
10581 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
10582 | msg = NULL; | |
10583 | if (ret) { | |
10584 | wpa_printf(MSG_DEBUG, | |
10585 | "nl80211: Failed to send P2P Listen offload vendor command"); | |
10586 | goto fail; | |
10587 | } | |
10588 | ||
10589 | return 0; | |
10590 | ||
10591 | fail: | |
10592 | nlmsg_free(msg); | |
10593 | return -1; | |
10594 | } | |
10595 | ||
10596 | ||
10597 | static int nl80211_p2p_lo_stop(void *priv) | |
10598 | { | |
10599 | struct i802_bss *bss = priv; | |
10600 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
10601 | struct nl_msg *msg; | |
10602 | ||
10603 | wpa_printf(MSG_DEBUG, "nl80211: Stop P2P Listen offload"); | |
10604 | ||
10605 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_P2P_LISTEN_OFFLOAD)) | |
10606 | return -1; | |
10607 | ||
10608 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || | |
10609 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || | |
10610 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | |
10611 | QCA_NL80211_VENDOR_SUBCMD_P2P_LISTEN_OFFLOAD_STOP)) { | |
10612 | nlmsg_free(msg); | |
10613 | return -1; | |
10614 | } | |
10615 | ||
10616 | return send_and_recv_msgs(drv, msg, NULL, NULL); | |
10617 | } | |
10618 | ||
2e4e4fb7 SD |
10619 | |
10620 | static int nl80211_set_tdls_mode(void *priv, int tdls_external_control) | |
10621 | { | |
10622 | struct i802_bss *bss = priv; | |
10623 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
10624 | struct nl_msg *msg; | |
10625 | struct nlattr *params; | |
10626 | int ret; | |
10627 | u32 tdls_mode; | |
10628 | ||
10629 | wpa_printf(MSG_DEBUG, | |
10630 | "nl80211: Set TDKS mode: tdls_external_control=%d", | |
10631 | tdls_external_control); | |
10632 | ||
10633 | if (tdls_external_control == 1) | |
10634 | tdls_mode = QCA_WLAN_VENDOR_TDLS_TRIGGER_MODE_IMPLICIT | | |
10635 | QCA_WLAN_VENDOR_TDLS_TRIGGER_MODE_EXTERNAL; | |
10636 | else | |
10637 | tdls_mode = QCA_WLAN_VENDOR_TDLS_TRIGGER_MODE_EXPLICIT; | |
10638 | ||
10639 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || | |
10640 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || | |
10641 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | |
10642 | QCA_NL80211_VENDOR_SUBCMD_CONFIGURE_TDLS)) | |
10643 | goto fail; | |
10644 | ||
10645 | params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); | |
10646 | if (!params) | |
10647 | goto fail; | |
10648 | ||
10649 | if (nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TDLS_CONFIG_TRIGGER_MODE, | |
10650 | tdls_mode)) | |
10651 | goto fail; | |
10652 | ||
10653 | nla_nest_end(msg, params); | |
10654 | ||
10655 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
10656 | msg = NULL; | |
10657 | if (ret) { | |
10658 | wpa_printf(MSG_ERROR, | |
10659 | "nl80211: Set TDLS mode failed: ret=%d (%s)", | |
10660 | ret, strerror(-ret)); | |
10661 | goto fail; | |
10662 | } | |
10663 | return 0; | |
10664 | fail: | |
10665 | nlmsg_free(msg); | |
10666 | return -1; | |
10667 | } | |
10668 | ||
3ab48492 KV |
10669 | |
10670 | #ifdef CONFIG_MBO | |
10671 | ||
10672 | static enum mbo_transition_reject_reason | |
10673 | nl80211_mbo_reject_reason_mapping(enum qca_wlan_btm_candidate_status status) | |
10674 | { | |
10675 | switch (status) { | |
10676 | case QCA_STATUS_REJECT_EXCESSIVE_FRAME_LOSS_EXPECTED: | |
10677 | return MBO_TRANSITION_REJECT_REASON_FRAME_LOSS; | |
10678 | case QCA_STATUS_REJECT_EXCESSIVE_DELAY_EXPECTED: | |
10679 | return MBO_TRANSITION_REJECT_REASON_DELAY; | |
10680 | case QCA_STATUS_REJECT_INSUFFICIENT_QOS_CAPACITY: | |
10681 | return MBO_TRANSITION_REJECT_REASON_QOS_CAPACITY; | |
10682 | case QCA_STATUS_REJECT_LOW_RSSI: | |
10683 | return MBO_TRANSITION_REJECT_REASON_RSSI; | |
10684 | case QCA_STATUS_REJECT_HIGH_INTERFERENCE: | |
10685 | return MBO_TRANSITION_REJECT_REASON_INTERFERENCE; | |
10686 | case QCA_STATUS_REJECT_UNKNOWN: | |
10687 | default: | |
10688 | return MBO_TRANSITION_REJECT_REASON_UNSPECIFIED; | |
10689 | } | |
10690 | } | |
10691 | ||
10692 | ||
10693 | static void nl80211_parse_btm_candidate_info(struct candidate_list *candidate, | |
10694 | struct nlattr *tb[], int num) | |
10695 | { | |
10696 | enum qca_wlan_btm_candidate_status status; | |
10697 | char buf[50]; | |
10698 | ||
10699 | os_memcpy(candidate->bssid, | |
10700 | nla_data(tb[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_BSSID]), | |
10701 | ETH_ALEN); | |
10702 | ||
10703 | status = nla_get_u32( | |
10704 | tb[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_STATUS]); | |
10705 | candidate->is_accept = status == QCA_STATUS_ACCEPT; | |
10706 | candidate->reject_reason = nl80211_mbo_reject_reason_mapping(status); | |
10707 | ||
10708 | if (candidate->is_accept) | |
10709 | os_snprintf(buf, sizeof(buf), "Accepted"); | |
10710 | else | |
10711 | os_snprintf(buf, sizeof(buf), | |
10712 | "Rejected, Reject_reason: %d", | |
10713 | candidate->reject_reason); | |
10714 | wpa_printf(MSG_DEBUG, "nl80211: BSSID[%d]: " MACSTR " %s", | |
10715 | num, MAC2STR(candidate->bssid), buf); | |
10716 | } | |
10717 | ||
10718 | ||
10719 | static int | |
10720 | nl80211_get_bss_transition_status_handler(struct nl_msg *msg, void *arg) | |
10721 | { | |
10722 | struct wpa_bss_candidate_info *info = arg; | |
10723 | struct candidate_list *candidate = info->candidates; | |
10724 | struct nlattr *tb_msg[NL80211_ATTR_MAX + 1]; | |
10725 | struct nlattr *tb_vendor[QCA_WLAN_VENDOR_ATTR_MAX + 1]; | |
10726 | struct nlattr *tb[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_MAX + 1]; | |
10727 | static struct nla_policy policy[ | |
10728 | QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_MAX + 1] = { | |
10729 | [QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_BSSID] = { | |
10730 | .minlen = ETH_ALEN | |
10731 | }, | |
10732 | [QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_STATUS] = { | |
10733 | .type = NLA_U32, | |
10734 | }, | |
10735 | }; | |
10736 | struct nlattr *attr; | |
10737 | int rem; | |
10738 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
10739 | u8 num; | |
10740 | ||
10741 | num = info->num; /* number of candidates sent to driver */ | |
10742 | info->num = 0; | |
10743 | nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
10744 | genlmsg_attrlen(gnlh, 0), NULL); | |
10745 | ||
10746 | if (!tb_msg[NL80211_ATTR_VENDOR_DATA] || | |
10747 | nla_parse_nested(tb_vendor, QCA_WLAN_VENDOR_ATTR_MAX, | |
10748 | tb_msg[NL80211_ATTR_VENDOR_DATA], NULL) || | |
10749 | !tb_vendor[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO]) | |
10750 | return NL_SKIP; | |
10751 | ||
10752 | wpa_printf(MSG_DEBUG, | |
10753 | "nl80211: WNM Candidate list received from driver"); | |
10754 | nla_for_each_nested(attr, | |
10755 | tb_vendor[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO], | |
10756 | rem) { | |
10757 | if (info->num >= num || | |
10758 | nla_parse_nested( | |
10759 | tb, QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_MAX, | |
10760 | attr, policy) || | |
10761 | !tb[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_BSSID] || | |
10762 | !tb[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_STATUS]) | |
10763 | break; | |
10764 | ||
10765 | nl80211_parse_btm_candidate_info(candidate, tb, info->num); | |
10766 | ||
10767 | candidate++; | |
10768 | info->num++; | |
10769 | } | |
10770 | ||
10771 | return NL_SKIP; | |
10772 | } | |
10773 | ||
10774 | ||
10775 | static struct wpa_bss_candidate_info * | |
10776 | nl80211_get_bss_transition_status(void *priv, struct wpa_bss_trans_info *params) | |
10777 | { | |
10778 | struct i802_bss *bss = priv; | |
10779 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
10780 | struct nl_msg *msg; | |
10781 | struct nlattr *attr, *attr1, *attr2; | |
10782 | struct wpa_bss_candidate_info *info; | |
10783 | u8 i; | |
10784 | int ret; | |
10785 | u8 *pos; | |
10786 | ||
10787 | if (!drv->fetch_bss_trans_status) | |
10788 | return NULL; | |
10789 | ||
10790 | info = os_zalloc(sizeof(*info)); | |
10791 | if (!info) | |
10792 | return NULL; | |
10793 | /* Allocate memory for number of candidates sent to driver */ | |
10794 | info->candidates = os_calloc(params->n_candidates, | |
10795 | sizeof(*info->candidates)); | |
10796 | if (!info->candidates) { | |
10797 | os_free(info); | |
10798 | return NULL; | |
10799 | } | |
10800 | ||
10801 | /* Copy the number of candidates being sent to driver. This is used in | |
10802 | * nl80211_get_bss_transition_status_handler() to limit the number of | |
10803 | * candidates that can be populated in info->candidates and will be | |
10804 | * later overwritten with the actual number of candidates received from | |
10805 | * the driver. | |
10806 | */ | |
10807 | info->num = params->n_candidates; | |
10808 | ||
10809 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || | |
10810 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || | |
10811 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | |
10812 | QCA_NL80211_VENDOR_SUBCMD_FETCH_BSS_TRANSITION_STATUS)) | |
10813 | goto fail; | |
10814 | ||
10815 | attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); | |
10816 | if (!attr) | |
10817 | goto fail; | |
10818 | ||
10819 | if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_BTM_MBO_TRANSITION_REASON, | |
10820 | params->mbo_transition_reason)) | |
10821 | goto fail; | |
10822 | ||
10823 | attr1 = nla_nest_start(msg, QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO); | |
10824 | if (!attr1) | |
10825 | goto fail; | |
10826 | ||
10827 | wpa_printf(MSG_DEBUG, | |
10828 | "nl80211: WNM Candidate list info sending to driver: mbo_transition_reason: %d n_candidates: %d", | |
10829 | params->mbo_transition_reason, params->n_candidates); | |
10830 | pos = params->bssid; | |
10831 | for (i = 0; i < params->n_candidates; i++) { | |
10832 | wpa_printf(MSG_DEBUG, "nl80211: BSSID[%d]: " MACSTR, i, | |
10833 | MAC2STR(pos)); | |
10834 | attr2 = nla_nest_start(msg, i); | |
10835 | if (!attr2 || | |
10836 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_BSSID, | |
10837 | ETH_ALEN, pos)) | |
10838 | goto fail; | |
10839 | pos += ETH_ALEN; | |
10840 | nla_nest_end(msg, attr2); | |
10841 | } | |
10842 | ||
10843 | nla_nest_end(msg, attr1); | |
10844 | nla_nest_end(msg, attr); | |
10845 | ||
10846 | ret = send_and_recv_msgs(drv, msg, | |
10847 | nl80211_get_bss_transition_status_handler, | |
10848 | info); | |
10849 | msg = NULL; | |
10850 | if (ret) { | |
10851 | wpa_printf(MSG_ERROR, | |
10852 | "nl80211: WNM Get BSS transition status failed: ret=%d (%s)", | |
10853 | ret, strerror(-ret)); | |
10854 | goto fail; | |
10855 | } | |
10856 | return info; | |
10857 | ||
10858 | fail: | |
10859 | nlmsg_free(msg); | |
10860 | os_free(info->candidates); | |
10861 | os_free(info); | |
10862 | return NULL; | |
10863 | } | |
10864 | ||
178553b7 VK |
10865 | |
10866 | /** | |
10867 | * nl80211_ignore_assoc_disallow - Configure driver to ignore assoc_disallow | |
10868 | * @priv: Pointer to private driver data from wpa_driver_nl80211_init() | |
10869 | * @ignore_assoc_disallow: 0 to not ignore, 1 to ignore | |
10870 | * Returns: 0 on success, -1 on failure | |
10871 | */ | |
10872 | static int nl80211_ignore_assoc_disallow(void *priv, int ignore_disallow) | |
10873 | { | |
10874 | struct i802_bss *bss = priv; | |
10875 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
10876 | struct nl_msg *msg; | |
10877 | struct nlattr *attr; | |
10878 | int ret = -1; | |
10879 | ||
10880 | if (!drv->set_wifi_conf_vendor_cmd_avail) | |
10881 | return -1; | |
10882 | ||
10883 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || | |
10884 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || | |
10885 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | |
10886 | QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION)) | |
10887 | goto fail; | |
10888 | ||
10889 | attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); | |
10890 | if (!attr) | |
10891 | goto fail; | |
10892 | ||
10893 | wpa_printf(MSG_DEBUG, "nl80211: Set ignore_assoc_disallow %d", | |
10894 | ignore_disallow); | |
10895 | if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_IGNORE_ASSOC_DISALLOWED, | |
10896 | ignore_disallow)) | |
10897 | goto fail; | |
10898 | ||
10899 | nla_nest_end(msg, attr); | |
10900 | ||
10901 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
10902 | msg = NULL; | |
10903 | if (ret) { | |
10904 | wpa_printf(MSG_ERROR, | |
10905 | "nl80211: Set ignore_assoc_disallow failed: ret=%d (%s)", | |
10906 | ret, strerror(-ret)); | |
10907 | goto fail; | |
10908 | } | |
10909 | ||
10910 | fail: | |
10911 | nlmsg_free(msg); | |
10912 | return ret; | |
10913 | } | |
10914 | ||
3ab48492 KV |
10915 | #endif /* CONFIG_MBO */ |
10916 | ||
b658547d JM |
10917 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
10918 | ||
7c813acf | 10919 | |
6922d440 IP |
10920 | static int nl80211_write_to_file(const char *name, unsigned int val) |
10921 | { | |
10922 | int fd, len; | |
10923 | char tmp[128]; | |
3b726df8 | 10924 | int ret = 0; |
6922d440 IP |
10925 | |
10926 | fd = open(name, O_RDWR); | |
10927 | if (fd < 0) { | |
3b726df8 BN |
10928 | int level; |
10929 | /* | |
10930 | * Flags may not exist on older kernels, or while we're tearing | |
10931 | * down a disappearing device. | |
10932 | */ | |
10933 | if (errno == ENOENT) { | |
10934 | ret = 0; | |
10935 | level = MSG_DEBUG; | |
10936 | } else { | |
10937 | ret = -1; | |
10938 | level = MSG_ERROR; | |
10939 | } | |
10940 | wpa_printf(level, "nl80211: Failed to open %s: %s", | |
6922d440 | 10941 | name, strerror(errno)); |
3b726df8 | 10942 | return ret; |
6922d440 IP |
10943 | } |
10944 | ||
10945 | len = os_snprintf(tmp, sizeof(tmp), "%u\n", val); | |
10946 | len = write(fd, tmp, len); | |
3b726df8 BN |
10947 | if (len < 0) { |
10948 | ret = -1; | |
6922d440 IP |
10949 | wpa_printf(MSG_ERROR, "nl80211: Failed to write to %s: %s", |
10950 | name, strerror(errno)); | |
3b726df8 | 10951 | } |
6922d440 IP |
10952 | close(fd); |
10953 | ||
3b726df8 | 10954 | return ret; |
6922d440 IP |
10955 | } |
10956 | ||
10957 | ||
10958 | static int nl80211_configure_data_frame_filters(void *priv, u32 filter_flags) | |
10959 | { | |
10960 | struct i802_bss *bss = priv; | |
10961 | char path[128]; | |
10962 | int ret; | |
10963 | ||
10964 | wpa_printf(MSG_DEBUG, "nl80211: Data frame filter flags=0x%x", | |
10965 | filter_flags); | |
10966 | ||
10967 | /* Configure filtering of unicast frame encrypted using GTK */ | |
10968 | ret = os_snprintf(path, sizeof(path), | |
10969 | "/proc/sys/net/ipv4/conf/%s/drop_unicast_in_l2_multicast", | |
10970 | bss->ifname); | |
bd86ea08 JM |
10971 | if (os_snprintf_error(sizeof(path), ret)) |
10972 | return -1; | |
6922d440 IP |
10973 | |
10974 | ret = nl80211_write_to_file(path, | |
10975 | !!(filter_flags & | |
10976 | WPA_DATA_FRAME_FILTER_FLAG_GTK)); | |
10977 | if (ret) { | |
10978 | wpa_printf(MSG_ERROR, | |
10979 | "nl80211: Failed to set IPv4 unicast in multicast filter"); | |
10980 | return ret; | |
10981 | } | |
10982 | ||
10983 | os_snprintf(path, sizeof(path), | |
10984 | "/proc/sys/net/ipv6/conf/%s/drop_unicast_in_l2_multicast", | |
10985 | bss->ifname); | |
10986 | ret = nl80211_write_to_file(path, | |
10987 | !!(filter_flags & | |
10988 | WPA_DATA_FRAME_FILTER_FLAG_GTK)); | |
10989 | ||
10990 | if (ret) { | |
10991 | wpa_printf(MSG_ERROR, | |
10992 | "nl80211: Failed to set IPv6 unicast in multicast filter"); | |
10993 | return ret; | |
10994 | } | |
10995 | ||
10996 | /* Configure filtering of unicast frame encrypted using GTK */ | |
10997 | os_snprintf(path, sizeof(path), | |
10998 | "/proc/sys/net/ipv4/conf/%s/drop_gratuitous_arp", | |
10999 | bss->ifname); | |
11000 | ret = nl80211_write_to_file(path, | |
11001 | !!(filter_flags & | |
11002 | WPA_DATA_FRAME_FILTER_FLAG_ARP)); | |
11003 | if (ret) { | |
11004 | wpa_printf(MSG_ERROR, | |
11005 | "nl80211: Failed set gratuitous ARP filter"); | |
11006 | return ret; | |
11007 | } | |
11008 | ||
11009 | /* Configure filtering of IPv6 NA frames */ | |
11010 | os_snprintf(path, sizeof(path), | |
11011 | "/proc/sys/net/ipv6/conf/%s/drop_unsolicited_na", | |
11012 | bss->ifname); | |
11013 | ret = nl80211_write_to_file(path, | |
11014 | !!(filter_flags & | |
11015 | WPA_DATA_FRAME_FILTER_FLAG_NA)); | |
11016 | if (ret) { | |
11017 | wpa_printf(MSG_ERROR, | |
11018 | "nl80211: Failed to set unsolicited NA filter"); | |
11019 | return ret; | |
11020 | } | |
11021 | ||
11022 | return 0; | |
11023 | } | |
11024 | ||
11025 | ||
cc9a2575 KV |
11026 | static int nl80211_get_ext_capab(void *priv, enum wpa_driver_if_type type, |
11027 | const u8 **ext_capa, const u8 **ext_capa_mask, | |
11028 | unsigned int *ext_capa_len) | |
11029 | { | |
11030 | struct i802_bss *bss = priv; | |
11031 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
11032 | enum nl80211_iftype nlmode; | |
11033 | unsigned int i; | |
11034 | ||
11035 | if (!ext_capa || !ext_capa_mask || !ext_capa_len) | |
11036 | return -1; | |
11037 | ||
11038 | nlmode = wpa_driver_nl80211_if_type(type); | |
11039 | ||
11040 | /* By default, use the per-radio values */ | |
11041 | *ext_capa = drv->extended_capa; | |
11042 | *ext_capa_mask = drv->extended_capa_mask; | |
11043 | *ext_capa_len = drv->extended_capa_len; | |
11044 | ||
11045 | /* Replace the default value if a per-interface type value exists */ | |
11046 | for (i = 0; i < drv->num_iface_ext_capa; i++) { | |
11047 | if (nlmode == drv->iface_ext_capa[i].iftype) { | |
11048 | *ext_capa = drv->iface_ext_capa[i].ext_capa; | |
11049 | *ext_capa_mask = drv->iface_ext_capa[i].ext_capa_mask; | |
11050 | *ext_capa_len = drv->iface_ext_capa[i].ext_capa_len; | |
11051 | break; | |
11052 | } | |
11053 | } | |
11054 | ||
11055 | return 0; | |
11056 | } | |
11057 | ||
11058 | ||
3c67e977 VK |
11059 | static int nl80211_update_connection_params( |
11060 | void *priv, struct wpa_driver_associate_params *params, | |
11061 | enum wpa_drv_update_connect_params_mask mask) | |
11062 | { | |
11063 | struct i802_bss *bss = priv; | |
11064 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
11065 | struct nl_msg *msg; | |
11066 | int ret = -1; | |
11067 | enum nl80211_auth_type type; | |
11068 | ||
c574a3ff SD |
11069 | /* Update Connection Params is intended for drivers that implement |
11070 | * internal SME and expect these updated connection params from | |
11071 | * wpa_supplicant. Do not send this request for the drivers using | |
11072 | * SME from wpa_supplicant. | |
11073 | */ | |
11074 | if (drv->capa.flags & WPA_DRIVER_FLAGS_SME) | |
11075 | return 0; | |
11076 | ||
3c67e977 VK |
11077 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_UPDATE_CONNECT_PARAMS); |
11078 | if (!msg) | |
11079 | goto fail; | |
11080 | ||
11081 | wpa_printf(MSG_DEBUG, "nl80211: Update connection params (ifindex=%d)", | |
11082 | drv->ifindex); | |
11083 | ||
11084 | if ((mask & WPA_DRV_UPDATE_ASSOC_IES) && params->wpa_ie) { | |
11085 | if (nla_put(msg, NL80211_ATTR_IE, params->wpa_ie_len, | |
11086 | params->wpa_ie)) | |
11087 | goto fail; | |
11088 | wpa_hexdump(MSG_DEBUG, " * IEs", params->wpa_ie, | |
11089 | params->wpa_ie_len); | |
11090 | } | |
11091 | ||
11092 | if (mask & WPA_DRV_UPDATE_AUTH_TYPE) { | |
11093 | type = get_nl_auth_type(params->auth_alg); | |
11094 | if (type == NL80211_AUTHTYPE_MAX || | |
11095 | nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, type)) | |
11096 | goto fail; | |
11097 | wpa_printf(MSG_DEBUG, " * Auth Type %d", type); | |
11098 | } | |
11099 | ||
11100 | if ((mask & WPA_DRV_UPDATE_FILS_ERP_INFO) && | |
11101 | nl80211_put_fils_connect_params(drv, params, msg)) | |
11102 | goto fail; | |
11103 | ||
11104 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
11105 | msg = NULL; | |
11106 | if (ret) | |
11107 | wpa_dbg(drv->ctx, MSG_DEBUG, | |
11108 | "nl80211: Update connect params command failed: ret=%d (%s)", | |
11109 | ret, strerror(-ret)); | |
11110 | ||
11111 | fail: | |
11112 | nlmsg_free(msg); | |
11113 | return ret; | |
11114 | } | |
11115 | ||
11116 | ||
ba71cb82 SD |
11117 | static int nl80211_send_external_auth_status(void *priv, |
11118 | struct external_auth *params) | |
11119 | { | |
11120 | struct i802_bss *bss = priv; | |
11121 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
11122 | struct nl_msg *msg = NULL; | |
11123 | int ret = -1; | |
11124 | ||
236e793e | 11125 | /* External auth command/status is intended for drivers that implement |
1730a6a5 JM |
11126 | * internal SME but want to offload authentication processing (e.g., |
11127 | * SAE) to hostapd/wpa_supplicant. Do not send the status to drivers | |
236e793e SD |
11128 | * which do not support AP SME or use wpa_supplicant/hostapd SME. |
11129 | */ | |
2552a373 | 11130 | if ((is_ap_interface(drv->nlmode) && !bss->drv->device_ap_sme) || |
236e793e SD |
11131 | (drv->capa.flags & WPA_DRIVER_FLAGS_SME)) |
11132 | return -1; | |
11133 | ||
ba71cb82 SD |
11134 | wpa_dbg(drv->ctx, MSG_DEBUG, |
11135 | "nl80211: External auth status: %u", params->status); | |
11136 | ||
11137 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_EXTERNAL_AUTH); | |
11138 | if (!msg || | |
11139 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, params->status) || | |
dd1a8cef | 11140 | (params->ssid && params->ssid_len && |
236e793e SD |
11141 | nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid)) || |
11142 | (params->pmkid && | |
11143 | nla_put(msg, NL80211_ATTR_PMKID, PMKID_LEN, params->pmkid)) || | |
dd1a8cef JM |
11144 | (params->bssid && |
11145 | nla_put(msg, NL80211_ATTR_BSSID, ETH_ALEN, params->bssid))) | |
ba71cb82 SD |
11146 | goto fail; |
11147 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
11148 | msg = NULL; | |
11149 | if (ret) { | |
11150 | wpa_printf(MSG_DEBUG, | |
11151 | "nl80211: External Auth status update failed: ret=%d (%s)", | |
11152 | ret, strerror(-ret)); | |
11153 | goto fail; | |
11154 | } | |
11155 | fail: | |
11156 | nlmsg_free(msg); | |
11157 | return ret; | |
11158 | } | |
11159 | ||
11160 | ||
5abc7823 VN |
11161 | static int nl80211_set_4addr_mode(void *priv, const char *bridge_ifname, |
11162 | int val) | |
11163 | { | |
11164 | struct i802_bss *bss = priv; | |
11165 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
11166 | struct nl_msg *msg; | |
11167 | int ret = -ENOBUFS; | |
11168 | ||
11169 | wpa_printf(MSG_DEBUG, "nl80211: %s 4addr mode (bridge_ifname: %s)", | |
11170 | val ? "Enable" : "Disable", bridge_ifname); | |
11171 | ||
11172 | msg = nl80211_cmd_msg(drv->first_bss, 0, NL80211_CMD_SET_INTERFACE); | |
11173 | if (!msg || nla_put_u8(msg, NL80211_ATTR_4ADDR, val)) | |
11174 | goto fail; | |
11175 | ||
11176 | if (bridge_ifname[0] && bss->added_if_into_bridge && !val) { | |
11177 | if (linux_br_del_if(drv->global->ioctl_sock, | |
11178 | bridge_ifname, bss->ifname)) { | |
11179 | wpa_printf(MSG_ERROR, | |
11180 | "nl80211: Failed to remove interface %s from bridge %s", | |
11181 | bss->ifname, bridge_ifname); | |
11182 | return -1; | |
11183 | } | |
11184 | bss->added_if_into_bridge = 0; | |
11185 | } | |
11186 | ||
11187 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
11188 | msg = NULL; | |
11189 | if (!ret) { | |
11190 | if (bridge_ifname[0] && val && | |
11191 | i802_check_bridge(drv, bss, bridge_ifname, bss->ifname) < 0) | |
11192 | return -1; | |
11193 | return 0; | |
11194 | } | |
11195 | ||
11196 | fail: | |
11197 | nlmsg_free(msg); | |
11198 | wpa_printf(MSG_ERROR, "nl80211: Failed to enable/disable 4addr"); | |
11199 | ||
11200 | return ret; | |
11201 | } | |
11202 | ||
11203 | ||
3f5285e8 JM |
11204 | const struct wpa_driver_ops wpa_driver_nl80211_ops = { |
11205 | .name = "nl80211", | |
11206 | .desc = "Linux nl80211/cfg80211", | |
11207 | .get_bssid = wpa_driver_nl80211_get_bssid, | |
11208 | .get_ssid = wpa_driver_nl80211_get_ssid, | |
9ebce9c5 JM |
11209 | .set_key = driver_nl80211_set_key, |
11210 | .scan2 = driver_nl80211_scan2, | |
d21c63b9 LC |
11211 | .sched_scan = wpa_driver_nl80211_sched_scan, |
11212 | .stop_sched_scan = wpa_driver_nl80211_stop_sched_scan, | |
3f5285e8 | 11213 | .get_scan_results2 = wpa_driver_nl80211_get_scan_results, |
4f30addb | 11214 | .abort_scan = wpa_driver_nl80211_abort_scan, |
9ebce9c5 JM |
11215 | .deauthenticate = driver_nl80211_deauthenticate, |
11216 | .authenticate = driver_nl80211_authenticate, | |
3f5285e8 | 11217 | .associate = wpa_driver_nl80211_associate, |
f2ed8023 JM |
11218 | .global_init = nl80211_global_init, |
11219 | .global_deinit = nl80211_global_deinit, | |
11220 | .init2 = wpa_driver_nl80211_init, | |
9ebce9c5 | 11221 | .deinit = driver_nl80211_deinit, |
3f5285e8 JM |
11222 | .get_capa = wpa_driver_nl80211_get_capa, |
11223 | .set_operstate = wpa_driver_nl80211_set_operstate, | |
01652550 | 11224 | .set_supp_port = wpa_driver_nl80211_set_supp_port, |
6d158490 | 11225 | .set_country = wpa_driver_nl80211_set_country, |
f0793bf1 | 11226 | .get_country = wpa_driver_nl80211_get_country, |
19c3b566 | 11227 | .set_ap = wpa_driver_nl80211_set_ap, |
3c4ca363 | 11228 | .set_acl = wpa_driver_nl80211_set_acl, |
22a7c9d7 | 11229 | .if_add = wpa_driver_nl80211_if_add, |
9ebce9c5 JM |
11230 | .if_remove = driver_nl80211_if_remove, |
11231 | .send_mlme = driver_nl80211_send_mlme, | |
0fafeb54 | 11232 | .get_hw_feature_data = nl80211_get_hw_feature_data, |
0f4e8b4f | 11233 | .sta_add = wpa_driver_nl80211_sta_add, |
9ebce9c5 | 11234 | .sta_remove = driver_nl80211_sta_remove, |
db149ac9 | 11235 | .hapd_send_eapol = wpa_driver_nl80211_hapd_send_eapol, |
a8d6ffa4 | 11236 | .sta_set_flags = wpa_driver_nl80211_sta_set_flags, |
1d6f6385 | 11237 | .sta_set_airtime_weight = driver_nl80211_sta_set_airtime_weight, |
c5121837 | 11238 | .hapd_init = i802_init, |
c5121837 | 11239 | .hapd_deinit = i802_deinit, |
f7b3920c | 11240 | .set_wds_sta = i802_set_wds_sta, |
c5121837 JM |
11241 | .get_seqnum = i802_get_seqnum, |
11242 | .flush = i802_flush, | |
c5121837 JM |
11243 | .get_inact_sec = i802_get_inact_sec, |
11244 | .sta_clear_stats = i802_sta_clear_stats, | |
c5121837 JM |
11245 | .set_rts = i802_set_rts, |
11246 | .set_frag = i802_set_frag, | |
c5121837 | 11247 | .set_tx_queue_params = i802_set_tx_queue_params, |
9ebce9c5 | 11248 | .set_sta_vlan = driver_nl80211_set_sta_vlan, |
ee7ab173 JB |
11249 | .sta_deauth = i802_sta_deauth, |
11250 | .sta_disassoc = i802_sta_disassoc, | |
9ebce9c5 | 11251 | .read_sta_data = driver_nl80211_read_sta_data, |
e3802622 | 11252 | .set_freq = i802_set_freq, |
9ebce9c5 | 11253 | .send_action = driver_nl80211_send_action, |
5dfca53f | 11254 | .send_action_cancel_wait = wpa_driver_nl80211_send_action_cancel_wait, |
55777702 JM |
11255 | .remain_on_channel = wpa_driver_nl80211_remain_on_channel, |
11256 | .cancel_remain_on_channel = | |
11257 | wpa_driver_nl80211_cancel_remain_on_channel, | |
9ebce9c5 | 11258 | .probe_req_report = driver_nl80211_probe_req_report, |
af473088 | 11259 | .deinit_ap = wpa_driver_nl80211_deinit_ap, |
3c29244e | 11260 | .deinit_p2p_cli = wpa_driver_nl80211_deinit_p2p_cli, |
207ef3fb | 11261 | .resume = wpa_driver_nl80211_resume, |
b625473c | 11262 | .signal_monitor = nl80211_signal_monitor, |
1c5c7273 | 11263 | .signal_poll = nl80211_signal_poll, |
7f00dc6e | 11264 | .channel_info = nl80211_channel_info, |
c55f774d | 11265 | .set_param = nl80211_set_param, |
6859f1cb | 11266 | .get_radio_name = nl80211_get_radio_name, |
a6efc65d JM |
11267 | .add_pmkid = nl80211_add_pmkid, |
11268 | .remove_pmkid = nl80211_remove_pmkid, | |
11269 | .flush_pmkid = nl80211_flush_pmkid, | |
b14a210c | 11270 | .set_rekey_info = nl80211_set_rekey_info, |
bcf24348 | 11271 | .poll_client = nl80211_poll_client, |
29f338af | 11272 | .set_p2p_powersave = nl80211_set_p2p_powersave, |
f90e9c1c | 11273 | .start_dfs_cac = nl80211_start_radar_detection, |
695c7038 | 11274 | .stop_ap = wpa_driver_nl80211_stop_ap, |
03ea1786 AN |
11275 | #ifdef CONFIG_TDLS |
11276 | .send_tdls_mgmt = nl80211_send_tdls_mgmt, | |
11277 | .tdls_oper = nl80211_tdls_oper, | |
72b2605f AN |
11278 | .tdls_enable_channel_switch = nl80211_tdls_enable_channel_switch, |
11279 | .tdls_disable_channel_switch = nl80211_tdls_disable_channel_switch, | |
03ea1786 | 11280 | #endif /* CONFIG_TDLS */ |
6a1ce395 | 11281 | .update_ft_ies = wpa_driver_nl80211_update_ft_ies, |
d1836e23 | 11282 | .update_dh_ie = nl80211_update_dh_ie, |
597b94f5 | 11283 | .get_mac_addr = wpa_driver_nl80211_get_macaddr, |
0185007c | 11284 | .get_survey = wpa_driver_nl80211_get_survey, |
a771c07d | 11285 | .status = wpa_driver_nl80211_status, |
1c4ffa87 | 11286 | .switch_channel = nl80211_switch_channel, |
0de38036 JM |
11287 | #ifdef ANDROID_P2P |
11288 | .set_noa = wpa_driver_set_p2p_noa, | |
11289 | .get_noa = wpa_driver_get_p2p_noa, | |
11290 | .set_ap_wps_ie = wpa_driver_set_ap_wps_p2p_ie, | |
11291 | #endif /* ANDROID_P2P */ | |
5e2c3490 | 11292 | #ifdef ANDROID |
ded14ce9 | 11293 | #ifndef ANDROID_LIB_STUB |
5e2c3490 | 11294 | .driver_cmd = wpa_driver_nl80211_driver_cmd, |
ded14ce9 | 11295 | #endif /* !ANDROID_LIB_STUB */ |
5e2c3490 | 11296 | #endif /* ANDROID */ |
adef8948 | 11297 | .vendor_cmd = nl80211_vendor_cmd, |
049105b4 | 11298 | .set_qos_map = nl80211_set_qos_map, |
82ba4f2d | 11299 | .get_wowlan = nl80211_get_wowlan, |
e4fa8b12 | 11300 | .set_wowlan = nl80211_set_wowlan, |
fee354c7 | 11301 | .set_mac_addr = nl80211_set_mac_addr, |
6c1664f6 BC |
11302 | #ifdef CONFIG_MESH |
11303 | .init_mesh = wpa_driver_nl80211_init_mesh, | |
11304 | .join_mesh = wpa_driver_nl80211_join_mesh, | |
11305 | .leave_mesh = wpa_driver_nl80211_leave_mesh, | |
c36109e4 | 11306 | .probe_mesh_link = nl80211_probe_mesh_link, |
6c1664f6 | 11307 | #endif /* CONFIG_MESH */ |
71103bed KP |
11308 | .br_add_ip_neigh = wpa_driver_br_add_ip_neigh, |
11309 | .br_delete_ip_neigh = wpa_driver_br_delete_ip_neigh, | |
73d2294f | 11310 | .br_port_set_attr = wpa_driver_br_port_set_attr, |
7565752d | 11311 | .br_set_net_param = wpa_driver_br_set_net_param, |
dfa87878 MB |
11312 | .add_tx_ts = nl80211_add_ts, |
11313 | .del_tx_ts = nl80211_del_ts, | |
45e3fc72 | 11314 | .get_ifindex = nl80211_get_ifindex, |
b658547d | 11315 | #ifdef CONFIG_DRIVER_NL80211_QCA |
9607a1ae | 11316 | .roaming = nl80211_roaming, |
d98038bb | 11317 | .disable_fils = nl80211_disable_fils, |
16689c7c | 11318 | .do_acs = wpa_driver_do_acs, |
844dfeb8 | 11319 | .set_band = nl80211_set_band, |
98342208 | 11320 | .get_pref_freq_list = nl80211_get_pref_freq_list, |
7c813acf | 11321 | .set_prob_oper_freq = nl80211_set_prob_oper_freq, |
a6f5b193 PX |
11322 | .p2p_lo_start = nl80211_p2p_lo_start, |
11323 | .p2p_lo_stop = nl80211_p2p_lo_stop, | |
cc9985d1 | 11324 | .set_default_scan_ies = nl80211_set_default_scan_ies, |
2e4e4fb7 | 11325 | .set_tdls_mode = nl80211_set_tdls_mode, |
3ab48492 KV |
11326 | #ifdef CONFIG_MBO |
11327 | .get_bss_transition_status = nl80211_get_bss_transition_status, | |
178553b7 | 11328 | .ignore_assoc_disallow = nl80211_ignore_assoc_disallow, |
3ab48492 | 11329 | #endif /* CONFIG_MBO */ |
b04854ce | 11330 | .set_bssid_blacklist = nl80211_set_bssid_blacklist, |
df3b2e22 | 11331 | .add_sta_node = nl80211_add_sta_node, |
b658547d | 11332 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
6922d440 | 11333 | .configure_data_frame_filters = nl80211_configure_data_frame_filters, |
cc9a2575 | 11334 | .get_ext_capab = nl80211_get_ext_capab, |
3c67e977 | 11335 | .update_connect_params = nl80211_update_connection_params, |
ba71cb82 | 11336 | .send_external_auth_status = nl80211_send_external_auth_status, |
5abc7823 | 11337 | .set_4addr_mode = nl80211_set_4addr_mode, |
3f5285e8 | 11338 | }; |