]>
Commit | Line | Data |
---|---|---|
3f5285e8 | 1 | /* |
c5121837 | 2 | * Driver interaction with Linux nl80211/cfg80211 |
98cd3d1c | 3 | * Copyright (c) 2002-2015, Jouni Malinen <j@w1.fi> |
072ad14c JM |
4 | * Copyright (c) 2003-2004, Instant802 Networks, Inc. |
5 | * Copyright (c) 2005-2006, Devicescape Software, Inc. | |
6 | * Copyright (c) 2007, Johannes Berg <johannes@sipsolutions.net> | |
58f6fbe0 | 7 | * Copyright (c) 2009-2010, Atheros Communications |
3f5285e8 | 8 | * |
0f3d578e JM |
9 | * This software may be distributed under the terms of the BSD license. |
10 | * See README for more details. | |
3f5285e8 JM |
11 | */ |
12 | ||
13 | #include "includes.h" | |
6859f1cb | 14 | #include <sys/types.h> |
73d2294f | 15 | #include <fcntl.h> |
37b7d082 | 16 | #include <net/if.h> |
3f5285e8 | 17 | #include <netlink/genl/genl.h> |
3f5285e8 | 18 | #include <netlink/genl/ctrl.h> |
97ed9a06 KP |
19 | #ifdef CONFIG_LIBNL3_ROUTE |
20 | #include <netlink/route/neighbour.h> | |
21 | #endif /* CONFIG_LIBNL3_ROUTE */ | |
8602b0f2 | 22 | #include <linux/rtnetlink.h> |
1b648c7e | 23 | #include <netpacket/packet.h> |
32ab4855 | 24 | #include <linux/errqueue.h> |
625f587b | 25 | |
3f5285e8 | 26 | #include "common.h" |
1b648c7e | 27 | #include "eloop.h" |
1682c623 | 28 | #include "common/qca-vendor.h" |
a26582cb | 29 | #include "common/qca-vendor-attr.h" |
1b648c7e | 30 | #include "common/ieee802_11_defs.h" |
9b90955e | 31 | #include "common/ieee802_11_common.h" |
3aa24db9 | 32 | #include "common/wpa_common.h" |
f10bfc9a | 33 | #include "l2_packet/l2_packet.h" |
e2d02c29 | 34 | #include "netlink.h" |
1474e6e9 | 35 | #include "linux_defines.h" |
34f2f814 | 36 | #include "linux_ioctl.h" |
e2d02c29 JM |
37 | #include "radiotap.h" |
38 | #include "radiotap_iter.h" | |
8401a6b0 | 39 | #include "rfkill.h" |
1474e6e9 | 40 | #include "driver_nl80211.h" |
32ab4855 | 41 | |
1474e6e9 JM |
42 | |
43 | #ifndef CONFIG_LIBNL20 | |
a65a9aed JB |
44 | /* |
45 | * libnl 1.1 has a bug, it tries to allocate socket numbers densely | |
46 | * but when you free a socket again it will mess up its bitmap and | |
47 | * and use the wrong number the next time it needs a socket ID. | |
48 | * Therefore, we wrap the handle alloc/destroy and add our own pid | |
49 | * accounting. | |
50 | */ | |
51 | static uint32_t port_bitmap[32] = { 0 }; | |
52 | ||
53 | static struct nl_handle *nl80211_handle_alloc(void *cb) | |
54 | { | |
55 | struct nl_handle *handle; | |
56 | uint32_t pid = getpid() & 0x3FFFFF; | |
57 | int i; | |
58 | ||
59 | handle = nl_handle_alloc_cb(cb); | |
60 | ||
61 | for (i = 0; i < 1024; i++) { | |
62 | if (port_bitmap[i / 32] & (1 << (i % 32))) | |
63 | continue; | |
64 | port_bitmap[i / 32] |= 1 << (i % 32); | |
65 | pid += i << 22; | |
66 | break; | |
67 | } | |
68 | ||
69 | nl_socket_set_local_port(handle, pid); | |
70 | ||
71 | return handle; | |
72 | } | |
73 | ||
74 | static void nl80211_handle_destroy(struct nl_handle *handle) | |
75 | { | |
76 | uint32_t port = nl_socket_get_local_port(handle); | |
77 | ||
78 | port >>= 22; | |
79 | port_bitmap[port / 32] &= ~(1 << (port % 32)); | |
80 | ||
81 | nl_handle_destroy(handle); | |
82 | } | |
c5121837 JM |
83 | #endif /* CONFIG_LIBNL20 */ |
84 | ||
c5121837 | 85 | |
1c6edec6 JM |
86 | #ifdef ANDROID |
87 | /* system/core/libnl_2 does not include nl_socket_set_nonblocking() */ | |
1c6edec6 JM |
88 | #undef nl_socket_set_nonblocking |
89 | #define nl_socket_set_nonblocking(h) android_nl_socket_set_nonblocking(h) | |
70a96c81 | 90 | |
1c6edec6 JM |
91 | #endif /* ANDROID */ |
92 | ||
93 | ||
481234cf | 94 | static struct nl_handle * nl_create_handle(struct nl_cb *cb, const char *dbg) |
a92dfde8 | 95 | { |
481234cf | 96 | struct nl_handle *handle; |
a92dfde8 | 97 | |
481234cf JM |
98 | handle = nl80211_handle_alloc(cb); |
99 | if (handle == NULL) { | |
a92dfde8 JB |
100 | wpa_printf(MSG_ERROR, "nl80211: Failed to allocate netlink " |
101 | "callbacks (%s)", dbg); | |
481234cf | 102 | return NULL; |
a92dfde8 JB |
103 | } |
104 | ||
481234cf | 105 | if (genl_connect(handle)) { |
a92dfde8 JB |
106 | wpa_printf(MSG_ERROR, "nl80211: Failed to connect to generic " |
107 | "netlink (%s)", dbg); | |
481234cf JM |
108 | nl80211_handle_destroy(handle); |
109 | return NULL; | |
a92dfde8 JB |
110 | } |
111 | ||
481234cf | 112 | return handle; |
a92dfde8 JB |
113 | } |
114 | ||
115 | ||
481234cf | 116 | static void nl_destroy_handles(struct nl_handle **handle) |
a92dfde8 | 117 | { |
481234cf | 118 | if (*handle == NULL) |
a92dfde8 | 119 | return; |
481234cf JM |
120 | nl80211_handle_destroy(*handle); |
121 | *handle = NULL; | |
a92dfde8 JB |
122 | } |
123 | ||
124 | ||
10b85921 JB |
125 | #if __WORDSIZE == 64 |
126 | #define ELOOP_SOCKET_INVALID (intptr_t) 0x8888888888888889ULL | |
127 | #else | |
128 | #define ELOOP_SOCKET_INVALID (intptr_t) 0x88888889ULL | |
129 | #endif | |
130 | ||
5f65e9f7 JB |
131 | static void nl80211_register_eloop_read(struct nl_handle **handle, |
132 | eloop_sock_handler handler, | |
133 | void *eloop_data) | |
134 | { | |
fa38860c | 135 | #ifdef CONFIG_LIBNL20 |
630b3230 JM |
136 | /* |
137 | * libnl uses a pretty small buffer (32 kB that gets converted to 64 kB) | |
138 | * by default. It is possible to hit that limit in some cases where | |
139 | * operations are blocked, e.g., with a burst of Deauthentication frames | |
140 | * to hostapd and STA entry deletion. Try to increase the buffer to make | |
141 | * this less likely to occur. | |
142 | */ | |
143 | if (nl_socket_set_buffer_size(*handle, 262144, 0) < 0) { | |
144 | wpa_printf(MSG_DEBUG, | |
145 | "nl80211: Could not set nl_socket RX buffer size: %s", | |
146 | strerror(errno)); | |
147 | /* continue anyway with the default (smaller) buffer */ | |
148 | } | |
fa38860c | 149 | #endif /* CONFIG_LIBNL20 */ |
630b3230 | 150 | |
10b85921 | 151 | nl_socket_set_nonblocking(*handle); |
5f65e9f7 JB |
152 | eloop_register_read_sock(nl_socket_get_fd(*handle), handler, |
153 | eloop_data, *handle); | |
10b85921 | 154 | *handle = (void *) (((intptr_t) *handle) ^ ELOOP_SOCKET_INVALID); |
5f65e9f7 JB |
155 | } |
156 | ||
157 | ||
158 | static void nl80211_destroy_eloop_handle(struct nl_handle **handle) | |
159 | { | |
10b85921 | 160 | *handle = (void *) (((intptr_t) *handle) ^ ELOOP_SOCKET_INVALID); |
5f65e9f7 JB |
161 | eloop_unregister_read_sock(nl_socket_get_fd(*handle)); |
162 | nl_destroy_handles(handle); | |
163 | } | |
164 | ||
165 | ||
36d84860 | 166 | static void nl80211_global_deinit(void *priv); |
f51f54a0 | 167 | static void nl80211_check_global(struct nl80211_global *global); |
36d84860 | 168 | |
9ebce9c5 | 169 | static void wpa_driver_nl80211_deinit(struct i802_bss *bss); |
4ec68377 JD |
170 | static int wpa_driver_nl80211_set_mode_ibss(struct i802_bss *bss, |
171 | struct hostapd_freq_params *freq); | |
3c5d34e3 | 172 | |
362f781e | 173 | static int |
0d547d5f | 174 | wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data *drv, |
0ecff8d7 JM |
175 | const u8 *set_addr, int first, |
176 | const char *driver_params); | |
88df0ef7 | 177 | static int nl80211_send_frame_cmd(struct i802_bss *bss, |
5dfca53f | 178 | unsigned int freq, unsigned int wait, |
b106173a | 179 | const u8 *buf, size_t buf_len, u64 *cookie, |
2d3943ce AO |
180 | int no_cck, int no_ack, int offchanok, |
181 | const u16 *csa_offs, size_t csa_offs_len); | |
9ebce9c5 JM |
182 | static int wpa_driver_nl80211_probe_req_report(struct i802_bss *bss, |
183 | int report); | |
0915d02c | 184 | |
732b1d20 MB |
185 | #define IFIDX_ANY -1 |
186 | ||
187 | static void add_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, | |
188 | int ifidx_reason); | |
189 | static void del_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, | |
190 | int ifidx_reason); | |
191 | static int have_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, | |
192 | int ifidx_reason); | |
072ad14c | 193 | |
e87ef751 PX |
194 | static int nl80211_set_channel(struct i802_bss *bss, |
195 | struct hostapd_freq_params *freq, int set_chan); | |
4e5cb1a3 JM |
196 | static int nl80211_disable_11b_rates(struct wpa_driver_nl80211_data *drv, |
197 | int ifindex, int disabled); | |
504e905c | 198 | |
666e508c JM |
199 | static int nl80211_leave_ibss(struct wpa_driver_nl80211_data *drv, |
200 | int reset_mode); | |
21bdbe38 | 201 | |
bf83eab5 | 202 | static int i802_set_iface_flags(struct i802_bss *bss, int up); |
0ecff8d7 | 203 | static int nl80211_set_param(void *priv, const char *param); |
052b8d38 MH |
204 | #ifdef CONFIG_MESH |
205 | static int nl80211_put_mesh_config(struct nl_msg *msg, | |
206 | struct wpa_driver_mesh_bss_params *params); | |
207 | #endif /* CONFIG_MESH */ | |
05e5e615 DL |
208 | static int i802_sta_disassoc(void *priv, const u8 *own_addr, const u8 *addr, |
209 | int reason); | |
bf83eab5 | 210 | |
3f5285e8 | 211 | |
8d1fdde7 | 212 | /* Converts nl80211_chan_width to a common format */ |
f3407c66 | 213 | enum chan_width convert2width(int width) |
8d1fdde7 JD |
214 | { |
215 | switch (width) { | |
216 | case NL80211_CHAN_WIDTH_20_NOHT: | |
217 | return CHAN_WIDTH_20_NOHT; | |
218 | case NL80211_CHAN_WIDTH_20: | |
219 | return CHAN_WIDTH_20; | |
220 | case NL80211_CHAN_WIDTH_40: | |
221 | return CHAN_WIDTH_40; | |
222 | case NL80211_CHAN_WIDTH_80: | |
223 | return CHAN_WIDTH_80; | |
224 | case NL80211_CHAN_WIDTH_80P80: | |
225 | return CHAN_WIDTH_80P80; | |
226 | case NL80211_CHAN_WIDTH_160: | |
227 | return CHAN_WIDTH_160; | |
228 | } | |
229 | return CHAN_WIDTH_UNKNOWN; | |
230 | } | |
231 | ||
232 | ||
f3407c66 | 233 | int is_ap_interface(enum nl80211_iftype nlmode) |
b1f625e0 | 234 | { |
0e80ea2c JM |
235 | return nlmode == NL80211_IFTYPE_AP || |
236 | nlmode == NL80211_IFTYPE_P2P_GO; | |
b1f625e0 EP |
237 | } |
238 | ||
239 | ||
477af8f8 | 240 | int is_sta_interface(enum nl80211_iftype nlmode) |
b1f625e0 | 241 | { |
0e80ea2c JM |
242 | return nlmode == NL80211_IFTYPE_STATION || |
243 | nlmode == NL80211_IFTYPE_P2P_CLIENT; | |
b1f625e0 EP |
244 | } |
245 | ||
246 | ||
6a71413e | 247 | static int is_p2p_net_interface(enum nl80211_iftype nlmode) |
b3af99d2 | 248 | { |
0e80ea2c JM |
249 | return nlmode == NL80211_IFTYPE_P2P_CLIENT || |
250 | nlmode == NL80211_IFTYPE_P2P_GO; | |
b3af99d2 JM |
251 | } |
252 | ||
253 | ||
f3407c66 JM |
254 | struct i802_bss * get_bss_ifindex(struct wpa_driver_nl80211_data *drv, |
255 | int ifindex) | |
5dfbd725 JM |
256 | { |
257 | struct i802_bss *bss; | |
258 | ||
259 | for (bss = drv->first_bss; bss; bss = bss->next) { | |
260 | if (bss->ifindex == ifindex) | |
261 | return bss; | |
262 | } | |
263 | ||
264 | return NULL; | |
265 | } | |
266 | ||
267 | ||
afb0550a BC |
268 | static int is_mesh_interface(enum nl80211_iftype nlmode) |
269 | { | |
270 | return nlmode == NL80211_IFTYPE_MESH_POINT; | |
271 | } | |
272 | ||
273 | ||
f3407c66 | 274 | void nl80211_mark_disconnected(struct wpa_driver_nl80211_data *drv) |
add9b7a4 JM |
275 | { |
276 | if (drv->associated) | |
277 | os_memcpy(drv->prev_bssid, drv->bssid, ETH_ALEN); | |
278 | drv->associated = 0; | |
279 | os_memset(drv->bssid, 0, ETH_ALEN); | |
280 | } | |
281 | ||
282 | ||
6241fcb1 JM |
283 | /* nl80211 code */ |
284 | static int ack_handler(struct nl_msg *msg, void *arg) | |
285 | { | |
286 | int *err = arg; | |
287 | *err = 0; | |
288 | return NL_STOP; | |
289 | } | |
290 | ||
291 | static int finish_handler(struct nl_msg *msg, void *arg) | |
292 | { | |
8e8df255 JM |
293 | int *ret = arg; |
294 | *ret = 0; | |
6241fcb1 JM |
295 | return NL_SKIP; |
296 | } | |
297 | ||
298 | static int error_handler(struct sockaddr_nl *nla, struct nlmsgerr *err, | |
299 | void *arg) | |
300 | { | |
301 | int *ret = arg; | |
302 | *ret = err->error; | |
303 | return NL_SKIP; | |
304 | } | |
305 | ||
5b7b85f6 JM |
306 | |
307 | static int no_seq_check(struct nl_msg *msg, void *arg) | |
308 | { | |
309 | return NL_OK; | |
310 | } | |
311 | ||
312 | ||
bbd89bfc JM |
313 | static void nl80211_nlmsg_clear(struct nl_msg *msg) |
314 | { | |
315 | /* | |
316 | * Clear nlmsg data, e.g., to make sure key material is not left in | |
317 | * heap memory for unnecessarily long time. | |
318 | */ | |
319 | if (msg) { | |
320 | struct nlmsghdr *hdr = nlmsg_hdr(msg); | |
321 | void *data = nlmsg_data(hdr); | |
d58ade21 JM |
322 | /* |
323 | * This would use nlmsg_datalen() or the older nlmsg_len() if | |
324 | * only libnl were to maintain a stable API.. Neither will work | |
325 | * with all released versions, so just calculate the length | |
326 | * here. | |
327 | */ | |
328 | int len = hdr->nlmsg_len - NLMSG_HDRLEN; | |
bbd89bfc JM |
329 | |
330 | os_memset(data, 0, len); | |
331 | } | |
332 | } | |
333 | ||
334 | ||
d6c9aab8 | 335 | static int send_and_recv(struct nl80211_global *global, |
58f6fbe0 JM |
336 | struct nl_handle *nl_handle, struct nl_msg *msg, |
337 | int (*valid_handler)(struct nl_msg *, void *), | |
338 | void *valid_data) | |
6241fcb1 JM |
339 | { |
340 | struct nl_cb *cb; | |
341 | int err = -ENOMEM; | |
342 | ||
9725b784 JM |
343 | if (!msg) |
344 | return -ENOMEM; | |
345 | ||
d6c9aab8 | 346 | cb = nl_cb_clone(global->nl_cb); |
6241fcb1 JM |
347 | if (!cb) |
348 | goto out; | |
349 | ||
58f6fbe0 | 350 | err = nl_send_auto_complete(nl_handle, msg); |
6241fcb1 JM |
351 | if (err < 0) |
352 | goto out; | |
353 | ||
354 | err = 1; | |
355 | ||
356 | nl_cb_err(cb, NL_CB_CUSTOM, error_handler, &err); | |
8e8df255 | 357 | nl_cb_set(cb, NL_CB_FINISH, NL_CB_CUSTOM, finish_handler, &err); |
6241fcb1 JM |
358 | nl_cb_set(cb, NL_CB_ACK, NL_CB_CUSTOM, ack_handler, &err); |
359 | ||
360 | if (valid_handler) | |
361 | nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, | |
362 | valid_handler, valid_data); | |
363 | ||
34068ac3 JM |
364 | while (err > 0) { |
365 | int res = nl_recvmsgs(nl_handle, cb); | |
d3d04831 | 366 | if (res < 0) { |
34068ac3 JM |
367 | wpa_printf(MSG_INFO, |
368 | "nl80211: %s->nl_recvmsgs failed: %d", | |
369 | __func__, res); | |
370 | } | |
371 | } | |
6241fcb1 JM |
372 | out: |
373 | nl_cb_put(cb); | |
bbd89bfc JM |
374 | if (!valid_handler && valid_data == (void *) -1) |
375 | nl80211_nlmsg_clear(msg); | |
6241fcb1 JM |
376 | nlmsg_free(msg); |
377 | return err; | |
378 | } | |
379 | ||
380 | ||
f3407c66 JM |
381 | int send_and_recv_msgs(struct wpa_driver_nl80211_data *drv, |
382 | struct nl_msg *msg, | |
383 | int (*valid_handler)(struct nl_msg *, void *), | |
384 | void *valid_data) | |
58f6fbe0 | 385 | { |
481234cf | 386 | return send_and_recv(drv->global, drv->global->nl, msg, |
d6c9aab8 | 387 | valid_handler, valid_data); |
58f6fbe0 JM |
388 | } |
389 | ||
390 | ||
97865538 JM |
391 | struct family_data { |
392 | const char *group; | |
393 | int id; | |
394 | }; | |
395 | ||
396 | ||
397 | static int family_handler(struct nl_msg *msg, void *arg) | |
398 | { | |
399 | struct family_data *res = arg; | |
400 | struct nlattr *tb[CTRL_ATTR_MAX + 1]; | |
401 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
402 | struct nlattr *mcgrp; | |
403 | int i; | |
404 | ||
405 | nla_parse(tb, CTRL_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
406 | genlmsg_attrlen(gnlh, 0), NULL); | |
407 | if (!tb[CTRL_ATTR_MCAST_GROUPS]) | |
408 | return NL_SKIP; | |
409 | ||
410 | nla_for_each_nested(mcgrp, tb[CTRL_ATTR_MCAST_GROUPS], i) { | |
411 | struct nlattr *tb2[CTRL_ATTR_MCAST_GRP_MAX + 1]; | |
412 | nla_parse(tb2, CTRL_ATTR_MCAST_GRP_MAX, nla_data(mcgrp), | |
413 | nla_len(mcgrp), NULL); | |
414 | if (!tb2[CTRL_ATTR_MCAST_GRP_NAME] || | |
415 | !tb2[CTRL_ATTR_MCAST_GRP_ID] || | |
416 | os_strncmp(nla_data(tb2[CTRL_ATTR_MCAST_GRP_NAME]), | |
417 | res->group, | |
418 | nla_len(tb2[CTRL_ATTR_MCAST_GRP_NAME])) != 0) | |
419 | continue; | |
420 | res->id = nla_get_u32(tb2[CTRL_ATTR_MCAST_GRP_ID]); | |
421 | break; | |
422 | }; | |
423 | ||
424 | return NL_SKIP; | |
425 | } | |
426 | ||
427 | ||
d6c9aab8 | 428 | static int nl_get_multicast_id(struct nl80211_global *global, |
97865538 JM |
429 | const char *family, const char *group) |
430 | { | |
431 | struct nl_msg *msg; | |
a862e4a3 | 432 | int ret; |
97865538 JM |
433 | struct family_data res = { group, -ENOENT }; |
434 | ||
435 | msg = nlmsg_alloc(); | |
436 | if (!msg) | |
437 | return -ENOMEM; | |
a862e4a3 JM |
438 | if (!genlmsg_put(msg, 0, 0, genl_ctrl_resolve(global->nl, "nlctrl"), |
439 | 0, 0, CTRL_CMD_GETFAMILY, 0) || | |
440 | nla_put_string(msg, CTRL_ATTR_FAMILY_NAME, family)) { | |
441 | nlmsg_free(msg); | |
442 | return -1; | |
443 | } | |
97865538 | 444 | |
1033315f | 445 | ret = send_and_recv(global, global->nl, msg, family_handler, &res); |
97865538 JM |
446 | if (ret == 0) |
447 | ret = res.id; | |
97865538 JM |
448 | return ret; |
449 | } | |
450 | ||
451 | ||
f3407c66 JM |
452 | void * nl80211_cmd(struct wpa_driver_nl80211_data *drv, |
453 | struct nl_msg *msg, int flags, uint8_t cmd) | |
9fb04070 | 454 | { |
a5a187b0 JM |
455 | if (TEST_FAIL()) |
456 | return NULL; | |
335d42b1 | 457 | return genlmsg_put(msg, 0, 0, drv->global->nl80211_id, |
276e2d67 | 458 | 0, flags, cmd, 0); |
9fb04070 JM |
459 | } |
460 | ||
461 | ||
350acc35 JM |
462 | static int nl80211_set_iface_id(struct nl_msg *msg, struct i802_bss *bss) |
463 | { | |
464 | if (bss->wdev_id_set) | |
465 | return nla_put_u64(msg, NL80211_ATTR_WDEV, bss->wdev_id); | |
466 | return nla_put_u32(msg, NL80211_ATTR_IFINDEX, bss->ifindex); | |
467 | } | |
468 | ||
469 | ||
07c7757c JM |
470 | struct nl_msg * nl80211_cmd_msg(struct i802_bss *bss, int flags, uint8_t cmd) |
471 | { | |
472 | struct nl_msg *msg; | |
473 | ||
474 | msg = nlmsg_alloc(); | |
475 | if (!msg) | |
476 | return NULL; | |
477 | ||
478 | if (!nl80211_cmd(bss->drv, msg, flags, cmd) || | |
479 | nl80211_set_iface_id(msg, bss) < 0) { | |
480 | nlmsg_free(msg); | |
481 | return NULL; | |
482 | } | |
483 | ||
484 | return msg; | |
485 | } | |
486 | ||
487 | ||
488 | static struct nl_msg * | |
489 | nl80211_ifindex_msg(struct wpa_driver_nl80211_data *drv, int ifindex, | |
490 | int flags, uint8_t cmd) | |
491 | { | |
492 | struct nl_msg *msg; | |
493 | ||
494 | msg = nlmsg_alloc(); | |
495 | if (!msg) | |
496 | return NULL; | |
497 | ||
498 | if (!nl80211_cmd(drv, msg, flags, cmd) || | |
499 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex)) { | |
500 | nlmsg_free(msg); | |
501 | return NULL; | |
502 | } | |
503 | ||
504 | return msg; | |
505 | } | |
506 | ||
507 | ||
508 | struct nl_msg * nl80211_drv_msg(struct wpa_driver_nl80211_data *drv, int flags, | |
509 | uint8_t cmd) | |
510 | { | |
511 | return nl80211_ifindex_msg(drv, drv->ifindex, flags, cmd); | |
512 | } | |
513 | ||
514 | ||
515 | struct nl_msg * nl80211_bss_msg(struct i802_bss *bss, int flags, uint8_t cmd) | |
516 | { | |
517 | return nl80211_ifindex_msg(bss->drv, bss->ifindex, flags, cmd); | |
518 | } | |
519 | ||
520 | ||
e32ad281 JB |
521 | struct wiphy_idx_data { |
522 | int wiphy_idx; | |
01517c8b | 523 | enum nl80211_iftype nlmode; |
597b94f5 | 524 | u8 *macaddr; |
e32ad281 JB |
525 | }; |
526 | ||
527 | ||
528 | static int netdev_info_handler(struct nl_msg *msg, void *arg) | |
529 | { | |
530 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
531 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
532 | struct wiphy_idx_data *info = arg; | |
533 | ||
534 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
535 | genlmsg_attrlen(gnlh, 0), NULL); | |
536 | ||
537 | if (tb[NL80211_ATTR_WIPHY]) | |
538 | info->wiphy_idx = nla_get_u32(tb[NL80211_ATTR_WIPHY]); | |
539 | ||
01517c8b JB |
540 | if (tb[NL80211_ATTR_IFTYPE]) |
541 | info->nlmode = nla_get_u32(tb[NL80211_ATTR_IFTYPE]); | |
542 | ||
597b94f5 AS |
543 | if (tb[NL80211_ATTR_MAC] && info->macaddr) |
544 | os_memcpy(info->macaddr, nla_data(tb[NL80211_ATTR_MAC]), | |
545 | ETH_ALEN); | |
546 | ||
e32ad281 JB |
547 | return NL_SKIP; |
548 | } | |
549 | ||
550 | ||
f3407c66 | 551 | int nl80211_get_wiphy_index(struct i802_bss *bss) |
e32ad281 JB |
552 | { |
553 | struct nl_msg *msg; | |
554 | struct wiphy_idx_data data = { | |
555 | .wiphy_idx = -1, | |
597b94f5 | 556 | .macaddr = NULL, |
e32ad281 JB |
557 | }; |
558 | ||
56f77852 | 559 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_GET_INTERFACE))) |
a862e4a3 | 560 | return -1; |
e32ad281 JB |
561 | |
562 | if (send_and_recv_msgs(bss->drv, msg, netdev_info_handler, &data) == 0) | |
563 | return data.wiphy_idx; | |
e32ad281 JB |
564 | return -1; |
565 | } | |
566 | ||
567 | ||
01517c8b JB |
568 | static enum nl80211_iftype nl80211_get_ifmode(struct i802_bss *bss) |
569 | { | |
570 | struct nl_msg *msg; | |
571 | struct wiphy_idx_data data = { | |
597b94f5 AS |
572 | .nlmode = NL80211_IFTYPE_UNSPECIFIED, |
573 | .macaddr = NULL, | |
01517c8b JB |
574 | }; |
575 | ||
56f77852 | 576 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_GET_INTERFACE))) |
a862e4a3 | 577 | return NL80211_IFTYPE_UNSPECIFIED; |
01517c8b JB |
578 | |
579 | if (send_and_recv_msgs(bss->drv, msg, netdev_info_handler, &data) == 0) | |
580 | return data.nlmode; | |
01517c8b JB |
581 | return NL80211_IFTYPE_UNSPECIFIED; |
582 | } | |
01517c8b JB |
583 | |
584 | ||
597b94f5 AS |
585 | static int nl80211_get_macaddr(struct i802_bss *bss) |
586 | { | |
587 | struct nl_msg *msg; | |
588 | struct wiphy_idx_data data = { | |
589 | .macaddr = bss->addr, | |
590 | }; | |
591 | ||
56f77852 | 592 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_GET_INTERFACE))) |
a862e4a3 | 593 | return -1; |
597b94f5 | 594 | |
597b94f5 | 595 | return send_and_recv_msgs(bss->drv, msg, netdev_info_handler, &data); |
597b94f5 | 596 | } |
597b94f5 AS |
597 | |
598 | ||
e32ad281 JB |
599 | static int nl80211_register_beacons(struct wpa_driver_nl80211_data *drv, |
600 | struct nl80211_wiphy_data *w) | |
601 | { | |
602 | struct nl_msg *msg; | |
a862e4a3 | 603 | int ret; |
e32ad281 JB |
604 | |
605 | msg = nlmsg_alloc(); | |
606 | if (!msg) | |
607 | return -1; | |
608 | ||
a862e4a3 JM |
609 | if (!nl80211_cmd(drv, msg, 0, NL80211_CMD_REGISTER_BEACONS) || |
610 | nla_put_u32(msg, NL80211_ATTR_WIPHY, w->wiphy_idx)) { | |
611 | nlmsg_free(msg); | |
612 | return -1; | |
613 | } | |
e32ad281 | 614 | |
481234cf | 615 | ret = send_and_recv(drv->global, w->nl_beacons, msg, NULL, NULL); |
e32ad281 JB |
616 | if (ret) { |
617 | wpa_printf(MSG_DEBUG, "nl80211: Register beacons command " | |
618 | "failed: ret=%d (%s)", | |
619 | ret, strerror(-ret)); | |
e32ad281 | 620 | } |
e32ad281 JB |
621 | return ret; |
622 | } | |
623 | ||
624 | ||
625 | static void nl80211_recv_beacons(int sock, void *eloop_ctx, void *handle) | |
626 | { | |
627 | struct nl80211_wiphy_data *w = eloop_ctx; | |
34068ac3 | 628 | int res; |
e32ad281 | 629 | |
ee9fc67a | 630 | wpa_printf(MSG_EXCESSIVE, "nl80211: Beacon event message available"); |
e32ad281 | 631 | |
34068ac3 | 632 | res = nl_recvmsgs(handle, w->nl_cb); |
d3d04831 | 633 | if (res < 0) { |
34068ac3 JM |
634 | wpa_printf(MSG_INFO, "nl80211: %s->nl_recvmsgs failed: %d", |
635 | __func__, res); | |
636 | } | |
e32ad281 JB |
637 | } |
638 | ||
639 | ||
640 | static int process_beacon_event(struct nl_msg *msg, void *arg) | |
641 | { | |
642 | struct nl80211_wiphy_data *w = arg; | |
643 | struct wpa_driver_nl80211_data *drv; | |
644 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
645 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
646 | union wpa_event_data event; | |
647 | ||
648 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
649 | genlmsg_attrlen(gnlh, 0), NULL); | |
650 | ||
651 | if (gnlh->cmd != NL80211_CMD_FRAME) { | |
652 | wpa_printf(MSG_DEBUG, "nl80211: Unexpected beacon event? (%d)", | |
653 | gnlh->cmd); | |
654 | return NL_SKIP; | |
655 | } | |
656 | ||
657 | if (!tb[NL80211_ATTR_FRAME]) | |
658 | return NL_SKIP; | |
659 | ||
660 | dl_list_for_each(drv, &w->drvs, struct wpa_driver_nl80211_data, | |
661 | wiphy_list) { | |
662 | os_memset(&event, 0, sizeof(event)); | |
663 | event.rx_mgmt.frame = nla_data(tb[NL80211_ATTR_FRAME]); | |
664 | event.rx_mgmt.frame_len = nla_len(tb[NL80211_ATTR_FRAME]); | |
665 | wpa_supplicant_event(drv->ctx, EVENT_RX_MGMT, &event); | |
666 | } | |
667 | ||
668 | return NL_SKIP; | |
669 | } | |
670 | ||
671 | ||
672 | static struct nl80211_wiphy_data * | |
673 | nl80211_get_wiphy_data_ap(struct i802_bss *bss) | |
674 | { | |
675 | static DEFINE_DL_LIST(nl80211_wiphys); | |
676 | struct nl80211_wiphy_data *w; | |
677 | int wiphy_idx, found = 0; | |
678 | struct i802_bss *tmp_bss; | |
a70cd0db | 679 | u8 channel; |
e32ad281 JB |
680 | |
681 | if (bss->wiphy_data != NULL) | |
682 | return bss->wiphy_data; | |
683 | ||
684 | wiphy_idx = nl80211_get_wiphy_index(bss); | |
685 | ||
686 | dl_list_for_each(w, &nl80211_wiphys, struct nl80211_wiphy_data, list) { | |
687 | if (w->wiphy_idx == wiphy_idx) | |
688 | goto add; | |
689 | } | |
690 | ||
691 | /* alloc new one */ | |
692 | w = os_zalloc(sizeof(*w)); | |
693 | if (w == NULL) | |
694 | return NULL; | |
695 | w->wiphy_idx = wiphy_idx; | |
696 | dl_list_init(&w->bsss); | |
697 | dl_list_init(&w->drvs); | |
698 | ||
a70cd0db DL |
699 | /* Beacon frames not supported in IEEE 802.11ad */ |
700 | if (ieee80211_freq_to_chan(bss->freq, &channel) != | |
701 | HOSTAPD_MODE_IEEE80211AD) { | |
702 | w->nl_cb = nl_cb_alloc(NL_CB_DEFAULT); | |
703 | if (!w->nl_cb) { | |
704 | os_free(w); | |
705 | return NULL; | |
706 | } | |
707 | nl_cb_set(w->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, | |
708 | no_seq_check, NULL); | |
709 | nl_cb_set(w->nl_cb, NL_CB_VALID, NL_CB_CUSTOM, | |
710 | process_beacon_event, w); | |
711 | ||
712 | w->nl_beacons = nl_create_handle(bss->drv->global->nl_cb, | |
713 | "wiphy beacons"); | |
714 | if (w->nl_beacons == NULL) { | |
715 | os_free(w); | |
716 | return NULL; | |
717 | } | |
e32ad281 | 718 | |
a70cd0db DL |
719 | if (nl80211_register_beacons(bss->drv, w)) { |
720 | nl_destroy_handles(&w->nl_beacons); | |
721 | os_free(w); | |
722 | return NULL; | |
723 | } | |
e32ad281 | 724 | |
a70cd0db DL |
725 | nl80211_register_eloop_read(&w->nl_beacons, |
726 | nl80211_recv_beacons, w); | |
e32ad281 JB |
727 | } |
728 | ||
e32ad281 JB |
729 | dl_list_add(&nl80211_wiphys, &w->list); |
730 | ||
731 | add: | |
732 | /* drv entry for this bss already there? */ | |
733 | dl_list_for_each(tmp_bss, &w->bsss, struct i802_bss, wiphy_list) { | |
734 | if (tmp_bss->drv == bss->drv) { | |
735 | found = 1; | |
736 | break; | |
737 | } | |
738 | } | |
739 | /* if not add it */ | |
740 | if (!found) | |
741 | dl_list_add(&w->drvs, &bss->drv->wiphy_list); | |
742 | ||
743 | dl_list_add(&w->bsss, &bss->wiphy_list); | |
744 | bss->wiphy_data = w; | |
745 | return w; | |
746 | } | |
747 | ||
748 | ||
749 | static void nl80211_put_wiphy_data_ap(struct i802_bss *bss) | |
750 | { | |
751 | struct nl80211_wiphy_data *w = bss->wiphy_data; | |
752 | struct i802_bss *tmp_bss; | |
753 | int found = 0; | |
754 | ||
755 | if (w == NULL) | |
756 | return; | |
757 | bss->wiphy_data = NULL; | |
758 | dl_list_del(&bss->wiphy_list); | |
759 | ||
760 | /* still any for this drv present? */ | |
761 | dl_list_for_each(tmp_bss, &w->bsss, struct i802_bss, wiphy_list) { | |
762 | if (tmp_bss->drv == bss->drv) { | |
763 | found = 1; | |
764 | break; | |
765 | } | |
766 | } | |
767 | /* if not remove it */ | |
768 | if (!found) | |
769 | dl_list_del(&bss->drv->wiphy_list); | |
770 | ||
771 | if (!dl_list_empty(&w->bsss)) | |
772 | return; | |
773 | ||
a70cd0db DL |
774 | if (w->nl_beacons) |
775 | nl80211_destroy_eloop_handle(&w->nl_beacons); | |
e32ad281 JB |
776 | |
777 | nl_cb_put(w->nl_cb); | |
e32ad281 JB |
778 | dl_list_del(&w->list); |
779 | os_free(w); | |
780 | } | |
781 | ||
782 | ||
45e3fc72 RM |
783 | static unsigned int nl80211_get_ifindex(void *priv) |
784 | { | |
785 | struct i802_bss *bss = priv; | |
786 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
787 | ||
788 | return drv->ifindex; | |
789 | } | |
790 | ||
791 | ||
3f5285e8 JM |
792 | static int wpa_driver_nl80211_get_bssid(void *priv, u8 *bssid) |
793 | { | |
a2e40bb6 FF |
794 | struct i802_bss *bss = priv; |
795 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
c2a04078 JM |
796 | if (!drv->associated) |
797 | return -1; | |
798 | os_memcpy(bssid, drv->bssid, ETH_ALEN); | |
799 | return 0; | |
3f5285e8 JM |
800 | } |
801 | ||
802 | ||
3f5285e8 JM |
803 | static int wpa_driver_nl80211_get_ssid(void *priv, u8 *ssid) |
804 | { | |
a2e40bb6 FF |
805 | struct i802_bss *bss = priv; |
806 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
fd05d64e JM |
807 | if (!drv->associated) |
808 | return -1; | |
809 | os_memcpy(ssid, drv->ssid, drv->ssid_len); | |
810 | return drv->ssid_len; | |
3f5285e8 JM |
811 | } |
812 | ||
813 | ||
90a545cc | 814 | static void wpa_driver_nl80211_event_newlink( |
45e3fc72 RM |
815 | struct nl80211_global *global, struct wpa_driver_nl80211_data *drv, |
816 | int ifindex, const char *ifname) | |
3f5285e8 JM |
817 | { |
818 | union wpa_event_data event; | |
819 | ||
45e3fc72 | 820 | if (drv && os_strcmp(drv->first_bss->ifname, ifname) == 0) { |
90a545cc JM |
821 | if (if_nametoindex(drv->first_bss->ifname) == 0) { |
822 | wpa_printf(MSG_DEBUG, "nl80211: Interface %s does not exist - ignore RTM_NEWLINK", | |
823 | drv->first_bss->ifname); | |
824 | return; | |
825 | } | |
826 | if (!drv->if_removed) | |
827 | return; | |
828 | wpa_printf(MSG_DEBUG, "nl80211: Mark if_removed=0 for %s based on RTM_NEWLINK event", | |
829 | drv->first_bss->ifname); | |
830 | drv->if_removed = 0; | |
831 | } | |
832 | ||
3f5285e8 | 833 | os_memset(&event, 0, sizeof(event)); |
45e3fc72 | 834 | event.interface_status.ifindex = ifindex; |
90a545cc JM |
835 | os_strlcpy(event.interface_status.ifname, ifname, |
836 | sizeof(event.interface_status.ifname)); | |
837 | event.interface_status.ievent = EVENT_INTERFACE_ADDED; | |
45e3fc72 RM |
838 | if (drv) |
839 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_STATUS, &event); | |
840 | else | |
841 | wpa_supplicant_event_global(global->ctx, EVENT_INTERFACE_STATUS, | |
842 | &event); | |
90a545cc JM |
843 | } |
844 | ||
845 | ||
846 | static void wpa_driver_nl80211_event_dellink( | |
45e3fc72 RM |
847 | struct nl80211_global *global, struct wpa_driver_nl80211_data *drv, |
848 | int ifindex, const char *ifname) | |
90a545cc JM |
849 | { |
850 | union wpa_event_data event; | |
851 | ||
45e3fc72 | 852 | if (drv && os_strcmp(drv->first_bss->ifname, ifname) == 0) { |
90a545cc JM |
853 | if (drv->if_removed) { |
854 | wpa_printf(MSG_DEBUG, "nl80211: if_removed already set - ignore RTM_DELLINK event for %s", | |
855 | ifname); | |
856 | return; | |
d1f4942b | 857 | } |
90a545cc JM |
858 | wpa_printf(MSG_DEBUG, "RTM_DELLINK: Interface '%s' removed - mark if_removed=1", |
859 | ifname); | |
860 | drv->if_removed = 1; | |
861 | } else { | |
862 | wpa_printf(MSG_DEBUG, "RTM_DELLINK: Interface '%s' removed", | |
863 | ifname); | |
7524cfb1 JM |
864 | } |
865 | ||
90a545cc | 866 | os_memset(&event, 0, sizeof(event)); |
45e3fc72 | 867 | event.interface_status.ifindex = ifindex; |
90a545cc JM |
868 | os_strlcpy(event.interface_status.ifname, ifname, |
869 | sizeof(event.interface_status.ifname)); | |
870 | event.interface_status.ievent = EVENT_INTERFACE_REMOVED; | |
45e3fc72 RM |
871 | if (drv) |
872 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_STATUS, &event); | |
873 | else | |
874 | wpa_supplicant_event_global(global->ctx, EVENT_INTERFACE_STATUS, | |
875 | &event); | |
3f5285e8 JM |
876 | } |
877 | ||
878 | ||
7524cfb1 | 879 | static int wpa_driver_nl80211_own_ifname(struct wpa_driver_nl80211_data *drv, |
62d680c3 | 880 | u8 *buf, size_t len) |
7524cfb1 | 881 | { |
62d680c3 | 882 | int attrlen, rta_len; |
7524cfb1 JM |
883 | struct rtattr *attr; |
884 | ||
62d680c3 JM |
885 | attrlen = len; |
886 | attr = (struct rtattr *) buf; | |
7524cfb1 JM |
887 | |
888 | rta_len = RTA_ALIGN(sizeof(struct rtattr)); | |
889 | while (RTA_OK(attr, attrlen)) { | |
890 | if (attr->rta_type == IFLA_IFNAME) { | |
834ee56f KP |
891 | if (os_strcmp(((char *) attr) + rta_len, |
892 | drv->first_bss->ifname) == 0) | |
7524cfb1 JM |
893 | return 1; |
894 | else | |
895 | break; | |
896 | } | |
897 | attr = RTA_NEXT(attr, attrlen); | |
898 | } | |
899 | ||
900 | return 0; | |
901 | } | |
902 | ||
903 | ||
904 | static int wpa_driver_nl80211_own_ifindex(struct wpa_driver_nl80211_data *drv, | |
62d680c3 | 905 | int ifindex, u8 *buf, size_t len) |
7524cfb1 JM |
906 | { |
907 | if (drv->ifindex == ifindex) | |
908 | return 1; | |
909 | ||
62d680c3 | 910 | if (drv->if_removed && wpa_driver_nl80211_own_ifname(drv, buf, len)) { |
f51f54a0 | 911 | nl80211_check_global(drv->global); |
7524cfb1 JM |
912 | wpa_printf(MSG_DEBUG, "nl80211: Update ifindex for a removed " |
913 | "interface"); | |
5e0c20ff JM |
914 | if (wpa_driver_nl80211_finish_drv_init(drv, NULL, 0, NULL) < 0) |
915 | return -1; | |
7524cfb1 JM |
916 | return 1; |
917 | } | |
918 | ||
919 | return 0; | |
920 | } | |
921 | ||
922 | ||
36d84860 | 923 | static struct wpa_driver_nl80211_data * |
5e0c20ff JM |
924 | nl80211_find_drv(struct nl80211_global *global, int idx, u8 *buf, size_t len, |
925 | int *init_failed) | |
36d84860 BG |
926 | { |
927 | struct wpa_driver_nl80211_data *drv; | |
5e0c20ff JM |
928 | int res; |
929 | ||
930 | if (init_failed) | |
931 | *init_failed = 0; | |
36d84860 BG |
932 | dl_list_for_each(drv, &global->interfaces, |
933 | struct wpa_driver_nl80211_data, list) { | |
5e0c20ff JM |
934 | res = wpa_driver_nl80211_own_ifindex(drv, idx, buf, len); |
935 | if (res < 0) { | |
936 | wpa_printf(MSG_DEBUG, | |
937 | "nl80211: Found matching own interface, but failed to complete reinitialization"); | |
938 | if (init_failed) | |
939 | *init_failed = 1; | |
940 | return drv; | |
941 | } | |
942 | if (res > 0 || have_ifidx(drv, idx, IFIDX_ANY)) | |
36d84860 BG |
943 | return drv; |
944 | } | |
945 | return NULL; | |
946 | } | |
947 | ||
948 | ||
290834df BG |
949 | static void nl80211_refresh_mac(struct wpa_driver_nl80211_data *drv, |
950 | int ifindex) | |
951 | { | |
952 | struct i802_bss *bss; | |
953 | u8 addr[ETH_ALEN]; | |
954 | ||
955 | bss = get_bss_ifindex(drv, ifindex); | |
956 | if (bss && | |
957 | linux_get_ifhwaddr(drv->global->ioctl_sock, | |
958 | bss->ifname, addr) < 0) { | |
959 | wpa_printf(MSG_DEBUG, | |
960 | "nl80211: %s: failed to re-read MAC address", | |
961 | bss->ifname); | |
962 | } else if (bss && os_memcmp(addr, bss->addr, ETH_ALEN) != 0) { | |
963 | wpa_printf(MSG_DEBUG, | |
964 | "nl80211: Own MAC address on ifindex %d (%s) changed from " | |
965 | MACSTR " to " MACSTR, | |
966 | ifindex, bss->ifname, | |
967 | MAC2STR(bss->addr), MAC2STR(addr)); | |
968 | os_memcpy(bss->addr, addr, ETH_ALEN); | |
969 | } | |
970 | } | |
971 | ||
972 | ||
62d680c3 JM |
973 | static void wpa_driver_nl80211_event_rtm_newlink(void *ctx, |
974 | struct ifinfomsg *ifi, | |
975 | u8 *buf, size_t len) | |
3f5285e8 | 976 | { |
36d84860 BG |
977 | struct nl80211_global *global = ctx; |
978 | struct wpa_driver_nl80211_data *drv; | |
90a545cc | 979 | int attrlen; |
62d680c3 | 980 | struct rtattr *attr; |
97cfcf64 | 981 | u32 brid = 0; |
aef85ba2 | 982 | char namebuf[IFNAMSIZ]; |
90a545cc JM |
983 | char ifname[IFNAMSIZ + 1]; |
984 | char extra[100], *pos, *end; | |
5e0c20ff | 985 | int init_failed; |
3f5285e8 | 986 | |
90a545cc JM |
987 | extra[0] = '\0'; |
988 | pos = extra; | |
989 | end = pos + sizeof(extra); | |
990 | ifname[0] = '\0'; | |
991 | ||
992 | attrlen = len; | |
993 | attr = (struct rtattr *) buf; | |
994 | while (RTA_OK(attr, attrlen)) { | |
995 | switch (attr->rta_type) { | |
996 | case IFLA_IFNAME: | |
997 | if (RTA_PAYLOAD(attr) >= IFNAMSIZ) | |
998 | break; | |
999 | os_memcpy(ifname, RTA_DATA(attr), RTA_PAYLOAD(attr)); | |
1000 | ifname[RTA_PAYLOAD(attr)] = '\0'; | |
1001 | break; | |
1002 | case IFLA_MASTER: | |
1003 | brid = nla_get_u32((struct nlattr *) attr); | |
1004 | pos += os_snprintf(pos, end - pos, " master=%u", brid); | |
1005 | break; | |
1006 | case IFLA_WIRELESS: | |
1007 | pos += os_snprintf(pos, end - pos, " wext"); | |
1008 | break; | |
1009 | case IFLA_OPERSTATE: | |
1010 | pos += os_snprintf(pos, end - pos, " operstate=%u", | |
1011 | nla_get_u32((struct nlattr *) attr)); | |
1012 | break; | |
1013 | case IFLA_LINKMODE: | |
1014 | pos += os_snprintf(pos, end - pos, " linkmode=%u", | |
1015 | nla_get_u32((struct nlattr *) attr)); | |
1016 | break; | |
1017 | } | |
1018 | attr = RTA_NEXT(attr, attrlen); | |
1019 | } | |
1020 | extra[sizeof(extra) - 1] = '\0'; | |
1021 | ||
f2e90835 JM |
1022 | wpa_printf(MSG_DEBUG, "RTM_NEWLINK: ifi_index=%d ifname=%s%s ifi_family=%d ifi_flags=0x%x (%s%s%s%s)", |
1023 | ifi->ifi_index, ifname, extra, ifi->ifi_family, | |
1024 | ifi->ifi_flags, | |
3f5285e8 JM |
1025 | (ifi->ifi_flags & IFF_UP) ? "[UP]" : "", |
1026 | (ifi->ifi_flags & IFF_RUNNING) ? "[RUNNING]" : "", | |
1027 | (ifi->ifi_flags & IFF_LOWER_UP) ? "[LOWER_UP]" : "", | |
1028 | (ifi->ifi_flags & IFF_DORMANT) ? "[DORMANT]" : ""); | |
a63063b4 | 1029 | |
5e0c20ff | 1030 | drv = nl80211_find_drv(global, ifi->ifi_index, buf, len, &init_failed); |
45e3fc72 RM |
1031 | if (!drv) |
1032 | goto event_newlink; | |
5e0c20ff JM |
1033 | if (init_failed) |
1034 | return; /* do not update interface state */ | |
45e3fc72 | 1035 | |
a63063b4 | 1036 | if (!drv->if_disabled && !(ifi->ifi_flags & IFF_UP)) { |
106fa1e9 | 1037 | namebuf[0] = '\0'; |
59d24925 | 1038 | if (if_indextoname(ifi->ifi_index, namebuf) && |
106fa1e9 | 1039 | linux_iface_up(drv->global->ioctl_sock, namebuf) > 0) { |
290834df BG |
1040 | /* Re-read MAC address as it may have changed */ |
1041 | nl80211_refresh_mac(drv, ifi->ifi_index); | |
59d24925 JM |
1042 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface down " |
1043 | "event since interface %s is up", namebuf); | |
7a94120e | 1044 | drv->ignore_if_down_event = 0; |
59d24925 JM |
1045 | return; |
1046 | } | |
106fa1e9 JM |
1047 | wpa_printf(MSG_DEBUG, "nl80211: Interface down (%s/%s)", |
1048 | namebuf, ifname); | |
1049 | if (os_strcmp(drv->first_bss->ifname, ifname) != 0) { | |
1050 | wpa_printf(MSG_DEBUG, | |
1051 | "nl80211: Not the main interface (%s) - do not indicate interface down", | |
1052 | drv->first_bss->ifname); | |
1053 | } else if (drv->ignore_if_down_event) { | |
7d9c3698 JM |
1054 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface down " |
1055 | "event generated by mode change"); | |
1056 | drv->ignore_if_down_event = 0; | |
1057 | } else { | |
1058 | drv->if_disabled = 1; | |
1059 | wpa_supplicant_event(drv->ctx, | |
1060 | EVENT_INTERFACE_DISABLED, NULL); | |
819f096f AO |
1061 | |
1062 | /* | |
1063 | * Try to get drv again, since it may be removed as | |
1064 | * part of the EVENT_INTERFACE_DISABLED handling for | |
1065 | * dynamic interfaces | |
1066 | */ | |
1067 | drv = nl80211_find_drv(global, ifi->ifi_index, | |
5e0c20ff | 1068 | buf, len, NULL); |
819f096f AO |
1069 | if (!drv) |
1070 | return; | |
7d9c3698 | 1071 | } |
a63063b4 JM |
1072 | } |
1073 | ||
1074 | if (drv->if_disabled && (ifi->ifi_flags & IFF_UP)) { | |
aef85ba2 | 1075 | if (if_indextoname(ifi->ifi_index, namebuf) && |
106fa1e9 | 1076 | linux_iface_up(drv->global->ioctl_sock, namebuf) == 0) { |
aef85ba2 JM |
1077 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up " |
1078 | "event since interface %s is down", | |
1079 | namebuf); | |
834ee56f | 1080 | } else if (if_nametoindex(drv->first_bss->ifname) == 0) { |
d1f4942b JM |
1081 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up " |
1082 | "event since interface %s does not exist", | |
834ee56f | 1083 | drv->first_bss->ifname); |
d1f4942b JM |
1084 | } else if (drv->if_removed) { |
1085 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up " | |
1086 | "event since interface %s is marked " | |
834ee56f | 1087 | "removed", drv->first_bss->ifname); |
aef85ba2 | 1088 | } else { |
3e0272ca | 1089 | /* Re-read MAC address as it may have changed */ |
290834df | 1090 | nl80211_refresh_mac(drv, ifi->ifi_index); |
3e0272ca | 1091 | |
aef85ba2 JM |
1092 | wpa_printf(MSG_DEBUG, "nl80211: Interface up"); |
1093 | drv->if_disabled = 0; | |
1094 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_ENABLED, | |
1095 | NULL); | |
1096 | } | |
a63063b4 JM |
1097 | } |
1098 | ||
3f5285e8 JM |
1099 | /* |
1100 | * Some drivers send the association event before the operup event--in | |
1101 | * this case, lifting operstate in wpa_driver_nl80211_set_operstate() | |
1102 | * fails. This will hit us when wpa_supplicant does not need to do | |
1103 | * IEEE 802.1X authentication | |
1104 | */ | |
1105 | if (drv->operstate == 1 && | |
1106 | (ifi->ifi_flags & (IFF_LOWER_UP | IFF_DORMANT)) == IFF_LOWER_UP && | |
90a545cc JM |
1107 | !(ifi->ifi_flags & IFF_RUNNING)) { |
1108 | wpa_printf(MSG_DEBUG, "nl80211: Set IF_OPER_UP again based on ifi_flags and expected operstate"); | |
36d84860 | 1109 | netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, |
e2d02c29 | 1110 | -1, IF_OPER_UP); |
3f5285e8 | 1111 | } |
97cfcf64 | 1112 | |
45e3fc72 | 1113 | event_newlink: |
90a545cc | 1114 | if (ifname[0]) |
45e3fc72 RM |
1115 | wpa_driver_nl80211_event_newlink(global, drv, ifi->ifi_index, |
1116 | ifname); | |
90a545cc | 1117 | |
45e3fc72 | 1118 | if (ifi->ifi_family == AF_BRIDGE && brid && drv) { |
392dfd37 JM |
1119 | struct i802_bss *bss; |
1120 | ||
97cfcf64 | 1121 | /* device has been added to bridge */ |
40e76396 JM |
1122 | if (!if_indextoname(brid, namebuf)) { |
1123 | wpa_printf(MSG_DEBUG, | |
1124 | "nl80211: Could not find bridge ifname for ifindex %u", | |
1125 | brid); | |
1126 | return; | |
1127 | } | |
97cfcf64 B |
1128 | wpa_printf(MSG_DEBUG, "nl80211: Add ifindex %u for bridge %s", |
1129 | brid, namebuf); | |
732b1d20 | 1130 | add_ifidx(drv, brid, ifi->ifi_index); |
392dfd37 JM |
1131 | |
1132 | for (bss = drv->first_bss; bss; bss = bss->next) { | |
1133 | if (os_strcmp(ifname, bss->ifname) == 0) { | |
1134 | os_strlcpy(bss->brname, namebuf, IFNAMSIZ); | |
1135 | break; | |
1136 | } | |
1137 | } | |
97cfcf64 | 1138 | } |
3f5285e8 JM |
1139 | } |
1140 | ||
1141 | ||
62d680c3 JM |
1142 | static void wpa_driver_nl80211_event_rtm_dellink(void *ctx, |
1143 | struct ifinfomsg *ifi, | |
1144 | u8 *buf, size_t len) | |
3f5285e8 | 1145 | { |
36d84860 BG |
1146 | struct nl80211_global *global = ctx; |
1147 | struct wpa_driver_nl80211_data *drv; | |
90a545cc | 1148 | int attrlen; |
62d680c3 | 1149 | struct rtattr *attr; |
97cfcf64 | 1150 | u32 brid = 0; |
90a545cc | 1151 | char ifname[IFNAMSIZ + 1]; |
f2e90835 | 1152 | char extra[100], *pos, *end; |
3f5285e8 | 1153 | |
f2e90835 JM |
1154 | extra[0] = '\0'; |
1155 | pos = extra; | |
1156 | end = pos + sizeof(extra); | |
90a545cc JM |
1157 | ifname[0] = '\0'; |
1158 | ||
62d680c3 JM |
1159 | attrlen = len; |
1160 | attr = (struct rtattr *) buf; | |
3f5285e8 | 1161 | while (RTA_OK(attr, attrlen)) { |
90a545cc JM |
1162 | switch (attr->rta_type) { |
1163 | case IFLA_IFNAME: | |
1164 | if (RTA_PAYLOAD(attr) >= IFNAMSIZ) | |
1165 | break; | |
1166 | os_memcpy(ifname, RTA_DATA(attr), RTA_PAYLOAD(attr)); | |
1167 | ifname[RTA_PAYLOAD(attr)] = '\0'; | |
1168 | break; | |
1169 | case IFLA_MASTER: | |
97cfcf64 | 1170 | brid = nla_get_u32((struct nlattr *) attr); |
f2e90835 JM |
1171 | pos += os_snprintf(pos, end - pos, " master=%u", brid); |
1172 | break; | |
1173 | case IFLA_OPERSTATE: | |
1174 | pos += os_snprintf(pos, end - pos, " operstate=%u", | |
1175 | nla_get_u32((struct nlattr *) attr)); | |
1176 | break; | |
1177 | case IFLA_LINKMODE: | |
1178 | pos += os_snprintf(pos, end - pos, " linkmode=%u", | |
1179 | nla_get_u32((struct nlattr *) attr)); | |
90a545cc JM |
1180 | break; |
1181 | } | |
3f5285e8 JM |
1182 | attr = RTA_NEXT(attr, attrlen); |
1183 | } | |
f2e90835 JM |
1184 | extra[sizeof(extra) - 1] = '\0'; |
1185 | ||
1186 | wpa_printf(MSG_DEBUG, "RTM_DELLINK: ifi_index=%d ifname=%s%s ifi_family=%d ifi_flags=0x%x (%s%s%s%s)", | |
1187 | ifi->ifi_index, ifname, extra, ifi->ifi_family, | |
1188 | ifi->ifi_flags, | |
1189 | (ifi->ifi_flags & IFF_UP) ? "[UP]" : "", | |
1190 | (ifi->ifi_flags & IFF_RUNNING) ? "[RUNNING]" : "", | |
1191 | (ifi->ifi_flags & IFF_LOWER_UP) ? "[LOWER_UP]" : "", | |
1192 | (ifi->ifi_flags & IFF_DORMANT) ? "[DORMANT]" : ""); | |
97cfcf64 | 1193 | |
5e0c20ff | 1194 | drv = nl80211_find_drv(global, ifi->ifi_index, buf, len, NULL); |
90a545cc | 1195 | |
45e3fc72 | 1196 | if (ifi->ifi_family == AF_BRIDGE && brid && drv) { |
97cfcf64 B |
1197 | /* device has been removed from bridge */ |
1198 | char namebuf[IFNAMSIZ]; | |
40e76396 JM |
1199 | |
1200 | if (!if_indextoname(brid, namebuf)) { | |
1201 | wpa_printf(MSG_DEBUG, | |
1202 | "nl80211: Could not find bridge ifname for ifindex %u", | |
1203 | brid); | |
1204 | } else { | |
1205 | wpa_printf(MSG_DEBUG, | |
1206 | "nl80211: Remove ifindex %u for bridge %s", | |
1207 | brid, namebuf); | |
1208 | } | |
732b1d20 | 1209 | del_ifidx(drv, brid, ifi->ifi_index); |
97cfcf64 | 1210 | } |
45e3fc72 RM |
1211 | |
1212 | if (ifi->ifi_family != AF_BRIDGE || !brid) | |
1213 | wpa_driver_nl80211_event_dellink(global, drv, ifi->ifi_index, | |
1214 | ifname); | |
3f5285e8 JM |
1215 | } |
1216 | ||
1217 | ||
a1fce391 JM |
1218 | struct nl80211_get_assoc_freq_arg { |
1219 | struct wpa_driver_nl80211_data *drv; | |
1220 | unsigned int assoc_freq; | |
1221 | unsigned int ibss_freq; | |
1222 | u8 assoc_bssid[ETH_ALEN]; | |
ed0a4ddc NW |
1223 | u8 assoc_ssid[SSID_MAX_LEN]; |
1224 | u8 assoc_ssid_len; | |
a1fce391 JM |
1225 | }; |
1226 | ||
1227 | static int nl80211_get_assoc_freq_handler(struct nl_msg *msg, void *arg) | |
1228 | { | |
1229 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
1230 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
1231 | struct nlattr *bss[NL80211_BSS_MAX + 1]; | |
1232 | static struct nla_policy bss_policy[NL80211_BSS_MAX + 1] = { | |
1233 | [NL80211_BSS_BSSID] = { .type = NLA_UNSPEC }, | |
1234 | [NL80211_BSS_FREQUENCY] = { .type = NLA_U32 }, | |
ed0a4ddc | 1235 | [NL80211_BSS_INFORMATION_ELEMENTS] = { .type = NLA_UNSPEC }, |
a1fce391 JM |
1236 | [NL80211_BSS_STATUS] = { .type = NLA_U32 }, |
1237 | }; | |
1238 | struct nl80211_get_assoc_freq_arg *ctx = arg; | |
1239 | enum nl80211_bss_status status; | |
1240 | ||
1241 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
1242 | genlmsg_attrlen(gnlh, 0), NULL); | |
1243 | if (!tb[NL80211_ATTR_BSS] || | |
1244 | nla_parse_nested(bss, NL80211_BSS_MAX, tb[NL80211_ATTR_BSS], | |
1245 | bss_policy) || | |
1246 | !bss[NL80211_BSS_STATUS]) | |
1247 | return NL_SKIP; | |
1248 | ||
1249 | status = nla_get_u32(bss[NL80211_BSS_STATUS]); | |
1250 | if (status == NL80211_BSS_STATUS_ASSOCIATED && | |
1251 | bss[NL80211_BSS_FREQUENCY]) { | |
1252 | ctx->assoc_freq = nla_get_u32(bss[NL80211_BSS_FREQUENCY]); | |
1253 | wpa_printf(MSG_DEBUG, "nl80211: Associated on %u MHz", | |
1254 | ctx->assoc_freq); | |
1255 | } | |
1256 | if (status == NL80211_BSS_STATUS_IBSS_JOINED && | |
1257 | bss[NL80211_BSS_FREQUENCY]) { | |
1258 | ctx->ibss_freq = nla_get_u32(bss[NL80211_BSS_FREQUENCY]); | |
1259 | wpa_printf(MSG_DEBUG, "nl80211: IBSS-joined on %u MHz", | |
1260 | ctx->ibss_freq); | |
1261 | } | |
1262 | if (status == NL80211_BSS_STATUS_ASSOCIATED && | |
1263 | bss[NL80211_BSS_BSSID]) { | |
1264 | os_memcpy(ctx->assoc_bssid, | |
1265 | nla_data(bss[NL80211_BSS_BSSID]), ETH_ALEN); | |
1266 | wpa_printf(MSG_DEBUG, "nl80211: Associated with " | |
1267 | MACSTR, MAC2STR(ctx->assoc_bssid)); | |
1268 | } | |
1269 | ||
ed0a4ddc NW |
1270 | if (status == NL80211_BSS_STATUS_ASSOCIATED && |
1271 | bss[NL80211_BSS_INFORMATION_ELEMENTS]) { | |
1272 | const u8 *ie, *ssid; | |
1273 | size_t ie_len; | |
1274 | ||
1275 | ie = nla_data(bss[NL80211_BSS_INFORMATION_ELEMENTS]); | |
1276 | ie_len = nla_len(bss[NL80211_BSS_INFORMATION_ELEMENTS]); | |
1277 | ssid = get_ie(ie, ie_len, WLAN_EID_SSID); | |
1278 | if (ssid && ssid[1] > 0 && ssid[1] <= SSID_MAX_LEN) { | |
1279 | ctx->assoc_ssid_len = ssid[1]; | |
1280 | os_memcpy(ctx->assoc_ssid, ssid + 2, ssid[1]); | |
1281 | } | |
1282 | } | |
1283 | ||
a1fce391 JM |
1284 | return NL_SKIP; |
1285 | } | |
1286 | ||
1287 | ||
ed0a4ddc NW |
1288 | int nl80211_get_assoc_ssid(struct wpa_driver_nl80211_data *drv, u8 *ssid) |
1289 | { | |
1290 | struct nl_msg *msg; | |
1291 | int ret; | |
1292 | struct nl80211_get_assoc_freq_arg arg; | |
1293 | ||
1294 | msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SCAN); | |
1295 | os_memset(&arg, 0, sizeof(arg)); | |
1296 | arg.drv = drv; | |
1297 | ret = send_and_recv_msgs(drv, msg, nl80211_get_assoc_freq_handler, | |
1298 | &arg); | |
1299 | if (ret == 0) { | |
1300 | os_memcpy(ssid, arg.assoc_ssid, arg.assoc_ssid_len); | |
1301 | return arg.assoc_ssid_len; | |
1302 | } | |
1303 | wpa_printf(MSG_DEBUG, "nl80211: Scan result fetch failed: ret=%d (%s)", | |
1304 | ret, strerror(-ret)); | |
1305 | return ret; | |
1306 | } | |
1307 | ||
1308 | ||
f3407c66 | 1309 | unsigned int nl80211_get_assoc_freq(struct wpa_driver_nl80211_data *drv) |
f5a8d422 JM |
1310 | { |
1311 | struct nl_msg *msg; | |
1312 | int ret; | |
a1fce391 | 1313 | struct nl80211_get_assoc_freq_arg arg; |
f5a8d422 | 1314 | |
9725b784 | 1315 | msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SCAN); |
f5a8d422 | 1316 | os_memset(&arg, 0, sizeof(arg)); |
f5a8d422 | 1317 | arg.drv = drv; |
a1fce391 JM |
1318 | ret = send_and_recv_msgs(drv, msg, nl80211_get_assoc_freq_handler, |
1319 | &arg); | |
f5a8d422 | 1320 | if (ret == 0) { |
c7caac56 JM |
1321 | unsigned int freq = drv->nlmode == NL80211_IFTYPE_ADHOC ? |
1322 | arg.ibss_freq : arg.assoc_freq; | |
f5a8d422 | 1323 | wpa_printf(MSG_DEBUG, "nl80211: Operating frequency for the " |
c7caac56 JM |
1324 | "associated BSS from scan results: %u MHz", freq); |
1325 | if (freq) | |
1326 | drv->assoc_freq = freq; | |
30158a0d | 1327 | return drv->assoc_freq; |
f5a8d422 JM |
1328 | } |
1329 | wpa_printf(MSG_DEBUG, "nl80211: Scan result fetch failed: ret=%d " | |
1330 | "(%s)", ret, strerror(-ret)); | |
f5a8d422 JM |
1331 | return drv->assoc_freq; |
1332 | } | |
1333 | ||
1334 | ||
60a972a6 JM |
1335 | static int get_link_signal(struct nl_msg *msg, void *arg) |
1336 | { | |
1337 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
1338 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
1339 | struct nlattr *sinfo[NL80211_STA_INFO_MAX + 1]; | |
1340 | static struct nla_policy policy[NL80211_STA_INFO_MAX + 1] = { | |
1341 | [NL80211_STA_INFO_SIGNAL] = { .type = NLA_U8 }, | |
95783298 | 1342 | [NL80211_STA_INFO_SIGNAL_AVG] = { .type = NLA_U8 }, |
74fa78b2 | 1343 | [NL80211_STA_INFO_BEACON_SIGNAL_AVG] = { .type = NLA_U8 }, |
60a972a6 | 1344 | }; |
7ee35bf3 PS |
1345 | struct nlattr *rinfo[NL80211_RATE_INFO_MAX + 1]; |
1346 | static struct nla_policy rate_policy[NL80211_RATE_INFO_MAX + 1] = { | |
1347 | [NL80211_RATE_INFO_BITRATE] = { .type = NLA_U16 }, | |
1348 | [NL80211_RATE_INFO_MCS] = { .type = NLA_U8 }, | |
1349 | [NL80211_RATE_INFO_40_MHZ_WIDTH] = { .type = NLA_FLAG }, | |
1350 | [NL80211_RATE_INFO_SHORT_GI] = { .type = NLA_FLAG }, | |
1351 | }; | |
1c5c7273 | 1352 | struct wpa_signal_info *sig_change = arg; |
60a972a6 JM |
1353 | |
1354 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
1355 | genlmsg_attrlen(gnlh, 0), NULL); | |
1356 | if (!tb[NL80211_ATTR_STA_INFO] || | |
1357 | nla_parse_nested(sinfo, NL80211_STA_INFO_MAX, | |
1358 | tb[NL80211_ATTR_STA_INFO], policy)) | |
1359 | return NL_SKIP; | |
1360 | if (!sinfo[NL80211_STA_INFO_SIGNAL]) | |
1361 | return NL_SKIP; | |
1362 | ||
7ee35bf3 PS |
1363 | sig_change->current_signal = |
1364 | (s8) nla_get_u8(sinfo[NL80211_STA_INFO_SIGNAL]); | |
1365 | ||
95783298 AO |
1366 | if (sinfo[NL80211_STA_INFO_SIGNAL_AVG]) |
1367 | sig_change->avg_signal = | |
1368 | (s8) nla_get_u8(sinfo[NL80211_STA_INFO_SIGNAL_AVG]); | |
1369 | else | |
1370 | sig_change->avg_signal = 0; | |
1371 | ||
74fa78b2 JM |
1372 | if (sinfo[NL80211_STA_INFO_BEACON_SIGNAL_AVG]) |
1373 | sig_change->avg_beacon_signal = | |
1374 | (s8) | |
1375 | nla_get_u8(sinfo[NL80211_STA_INFO_BEACON_SIGNAL_AVG]); | |
1376 | else | |
1377 | sig_change->avg_beacon_signal = 0; | |
1378 | ||
7ee35bf3 PS |
1379 | if (sinfo[NL80211_STA_INFO_TX_BITRATE]) { |
1380 | if (nla_parse_nested(rinfo, NL80211_RATE_INFO_MAX, | |
1381 | sinfo[NL80211_STA_INFO_TX_BITRATE], | |
1382 | rate_policy)) { | |
1383 | sig_change->current_txrate = 0; | |
1384 | } else { | |
1385 | if (rinfo[NL80211_RATE_INFO_BITRATE]) { | |
1386 | sig_change->current_txrate = | |
1387 | nla_get_u16(rinfo[ | |
1388 | NL80211_RATE_INFO_BITRATE]) * 100; | |
1389 | } | |
1390 | } | |
1391 | } | |
1392 | ||
60a972a6 JM |
1393 | return NL_SKIP; |
1394 | } | |
1395 | ||
1396 | ||
f3407c66 JM |
1397 | int nl80211_get_link_signal(struct wpa_driver_nl80211_data *drv, |
1398 | struct wpa_signal_info *sig) | |
60a972a6 JM |
1399 | { |
1400 | struct nl_msg *msg; | |
1401 | ||
7ee35bf3 PS |
1402 | sig->current_signal = -9999; |
1403 | sig->current_txrate = 0; | |
60a972a6 | 1404 | |
9725b784 | 1405 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_GET_STATION)) || |
a862e4a3 JM |
1406 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, drv->bssid)) { |
1407 | nlmsg_free(msg); | |
1408 | return -ENOBUFS; | |
1409 | } | |
60a972a6 JM |
1410 | |
1411 | return send_and_recv_msgs(drv, msg, get_link_signal, sig); | |
60a972a6 JM |
1412 | } |
1413 | ||
1414 | ||
7ee35bf3 PS |
1415 | static int get_link_noise(struct nl_msg *msg, void *arg) |
1416 | { | |
1417 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
1418 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
1419 | struct nlattr *sinfo[NL80211_SURVEY_INFO_MAX + 1]; | |
1420 | static struct nla_policy survey_policy[NL80211_SURVEY_INFO_MAX + 1] = { | |
1421 | [NL80211_SURVEY_INFO_FREQUENCY] = { .type = NLA_U32 }, | |
1422 | [NL80211_SURVEY_INFO_NOISE] = { .type = NLA_U8 }, | |
1423 | }; | |
1c5c7273 | 1424 | struct wpa_signal_info *sig_change = arg; |
7ee35bf3 PS |
1425 | |
1426 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
1427 | genlmsg_attrlen(gnlh, 0), NULL); | |
1428 | ||
1429 | if (!tb[NL80211_ATTR_SURVEY_INFO]) { | |
1430 | wpa_printf(MSG_DEBUG, "nl80211: survey data missing!"); | |
1431 | return NL_SKIP; | |
1432 | } | |
1433 | ||
1434 | if (nla_parse_nested(sinfo, NL80211_SURVEY_INFO_MAX, | |
1435 | tb[NL80211_ATTR_SURVEY_INFO], | |
1436 | survey_policy)) { | |
1437 | wpa_printf(MSG_DEBUG, "nl80211: failed to parse nested " | |
1438 | "attributes!"); | |
1439 | return NL_SKIP; | |
1440 | } | |
1441 | ||
1442 | if (!sinfo[NL80211_SURVEY_INFO_FREQUENCY]) | |
1443 | return NL_SKIP; | |
1444 | ||
1445 | if (nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]) != | |
1446 | sig_change->frequency) | |
1447 | return NL_SKIP; | |
1448 | ||
1449 | if (!sinfo[NL80211_SURVEY_INFO_NOISE]) | |
1450 | return NL_SKIP; | |
1451 | ||
1452 | sig_change->current_noise = | |
1453 | (s8) nla_get_u8(sinfo[NL80211_SURVEY_INFO_NOISE]); | |
1454 | ||
1455 | return NL_SKIP; | |
1456 | } | |
1457 | ||
1458 | ||
f3407c66 JM |
1459 | int nl80211_get_link_noise(struct wpa_driver_nl80211_data *drv, |
1460 | struct wpa_signal_info *sig_change) | |
7ee35bf3 PS |
1461 | { |
1462 | struct nl_msg *msg; | |
1463 | ||
1464 | sig_change->current_noise = 9999; | |
1465 | sig_change->frequency = drv->assoc_freq; | |
1466 | ||
9725b784 | 1467 | msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SURVEY); |
7ee35bf3 | 1468 | return send_and_recv_msgs(drv, msg, get_link_noise, sig_change); |
7ee35bf3 PS |
1469 | } |
1470 | ||
1471 | ||
97865538 | 1472 | static void wpa_driver_nl80211_event_receive(int sock, void *eloop_ctx, |
5582a5d1 | 1473 | void *handle) |
97865538 | 1474 | { |
a4ae123c | 1475 | struct nl_cb *cb = eloop_ctx; |
34068ac3 | 1476 | int res; |
97865538 | 1477 | |
cc2ada86 | 1478 | wpa_printf(MSG_MSGDUMP, "nl80211: Event message available"); |
97865538 | 1479 | |
34068ac3 | 1480 | res = nl_recvmsgs(handle, cb); |
d3d04831 | 1481 | if (res < 0) { |
34068ac3 JM |
1482 | wpa_printf(MSG_INFO, "nl80211: %s->nl_recvmsgs failed: %d", |
1483 | __func__, res); | |
1484 | } | |
97865538 JM |
1485 | } |
1486 | ||
1487 | ||
6d158490 LR |
1488 | /** |
1489 | * wpa_driver_nl80211_set_country - ask nl80211 to set the regulatory domain | |
1490 | * @priv: driver_nl80211 private data | |
1491 | * @alpha2_arg: country to which to switch to | |
1492 | * Returns: 0 on success, -1 on failure | |
1493 | * | |
1494 | * This asks nl80211 to set the regulatory domain for given | |
1495 | * country ISO / IEC alpha2. | |
1496 | */ | |
1497 | static int wpa_driver_nl80211_set_country(void *priv, const char *alpha2_arg) | |
1498 | { | |
a2e40bb6 FF |
1499 | struct i802_bss *bss = priv; |
1500 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
6d158490 LR |
1501 | char alpha2[3]; |
1502 | struct nl_msg *msg; | |
1503 | ||
1504 | msg = nlmsg_alloc(); | |
1505 | if (!msg) | |
e785c2ba | 1506 | return -ENOMEM; |
6d158490 LR |
1507 | |
1508 | alpha2[0] = alpha2_arg[0]; | |
1509 | alpha2[1] = alpha2_arg[1]; | |
1510 | alpha2[2] = '\0'; | |
1511 | ||
a862e4a3 JM |
1512 | if (!nl80211_cmd(drv, msg, 0, NL80211_CMD_REQ_SET_REG) || |
1513 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, alpha2)) { | |
1514 | nlmsg_free(msg); | |
1515 | return -EINVAL; | |
1516 | } | |
6d158490 LR |
1517 | if (send_and_recv_msgs(drv, msg, NULL, NULL)) |
1518 | return -EINVAL; | |
1519 | return 0; | |
6d158490 LR |
1520 | } |
1521 | ||
1522 | ||
f0793bf1 JM |
1523 | static int nl80211_get_country(struct nl_msg *msg, void *arg) |
1524 | { | |
1525 | char *alpha2 = arg; | |
1526 | struct nlattr *tb_msg[NL80211_ATTR_MAX + 1]; | |
1527 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
1528 | ||
1529 | nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
1530 | genlmsg_attrlen(gnlh, 0), NULL); | |
1531 | if (!tb_msg[NL80211_ATTR_REG_ALPHA2]) { | |
1532 | wpa_printf(MSG_DEBUG, "nl80211: No country information available"); | |
1533 | return NL_SKIP; | |
1534 | } | |
1535 | os_strlcpy(alpha2, nla_data(tb_msg[NL80211_ATTR_REG_ALPHA2]), 3); | |
1536 | return NL_SKIP; | |
1537 | } | |
1538 | ||
1539 | ||
1540 | static int wpa_driver_nl80211_get_country(void *priv, char *alpha2) | |
1541 | { | |
1542 | struct i802_bss *bss = priv; | |
1543 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
1544 | struct nl_msg *msg; | |
1545 | int ret; | |
1546 | ||
1547 | msg = nlmsg_alloc(); | |
1548 | if (!msg) | |
1549 | return -ENOMEM; | |
1550 | ||
1551 | nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_REG); | |
1552 | alpha2[0] = '\0'; | |
1553 | ret = send_and_recv_msgs(drv, msg, nl80211_get_country, alpha2); | |
1554 | if (!alpha2[0]) | |
1555 | ret = -1; | |
1556 | ||
1557 | return ret; | |
1558 | } | |
1559 | ||
1560 | ||
2a7b66f5 BG |
1561 | static int wpa_driver_nl80211_init_nl_global(struct nl80211_global *global) |
1562 | { | |
d6c9aab8 JB |
1563 | int ret; |
1564 | ||
2a7b66f5 BG |
1565 | global->nl_cb = nl_cb_alloc(NL_CB_DEFAULT); |
1566 | if (global->nl_cb == NULL) { | |
1567 | wpa_printf(MSG_ERROR, "nl80211: Failed to allocate netlink " | |
1568 | "callbacks"); | |
1569 | return -1; | |
1570 | } | |
1571 | ||
481234cf JM |
1572 | global->nl = nl_create_handle(global->nl_cb, "nl"); |
1573 | if (global->nl == NULL) | |
d6c9aab8 | 1574 | goto err; |
276e2d67 | 1575 | |
481234cf | 1576 | global->nl80211_id = genl_ctrl_resolve(global->nl, "nl80211"); |
335d42b1 | 1577 | if (global->nl80211_id < 0) { |
276e2d67 BG |
1578 | wpa_printf(MSG_ERROR, "nl80211: 'nl80211' generic netlink not " |
1579 | "found"); | |
d6c9aab8 | 1580 | goto err; |
276e2d67 BG |
1581 | } |
1582 | ||
481234cf JM |
1583 | global->nl_event = nl_create_handle(global->nl_cb, "event"); |
1584 | if (global->nl_event == NULL) | |
d6c9aab8 | 1585 | goto err; |
9fff9fdc | 1586 | |
d6c9aab8 | 1587 | ret = nl_get_multicast_id(global, "nl80211", "scan"); |
97865538 | 1588 | if (ret >= 0) |
481234cf | 1589 | ret = nl_socket_add_membership(global->nl_event, ret); |
97865538 JM |
1590 | if (ret < 0) { |
1591 | wpa_printf(MSG_ERROR, "nl80211: Could not add multicast " | |
1592 | "membership for scan events: %d (%s)", | |
1593 | ret, strerror(-ret)); | |
d6c9aab8 | 1594 | goto err; |
97865538 | 1595 | } |
c2a04078 | 1596 | |
d6c9aab8 | 1597 | ret = nl_get_multicast_id(global, "nl80211", "mlme"); |
c2a04078 | 1598 | if (ret >= 0) |
481234cf | 1599 | ret = nl_socket_add_membership(global->nl_event, ret); |
c2a04078 JM |
1600 | if (ret < 0) { |
1601 | wpa_printf(MSG_ERROR, "nl80211: Could not add multicast " | |
1602 | "membership for mlme events: %d (%s)", | |
1603 | ret, strerror(-ret)); | |
d6c9aab8 | 1604 | goto err; |
c2a04078 | 1605 | } |
c2a04078 | 1606 | |
d6c9aab8 | 1607 | ret = nl_get_multicast_id(global, "nl80211", "regulatory"); |
33c5deb8 | 1608 | if (ret >= 0) |
481234cf | 1609 | ret = nl_socket_add_membership(global->nl_event, ret); |
33c5deb8 JM |
1610 | if (ret < 0) { |
1611 | wpa_printf(MSG_DEBUG, "nl80211: Could not add multicast " | |
1612 | "membership for regulatory events: %d (%s)", | |
1613 | ret, strerror(-ret)); | |
1614 | /* Continue without regulatory events */ | |
1615 | } | |
1616 | ||
17b79e65 JM |
1617 | ret = nl_get_multicast_id(global, "nl80211", "vendor"); |
1618 | if (ret >= 0) | |
1619 | ret = nl_socket_add_membership(global->nl_event, ret); | |
1620 | if (ret < 0) { | |
1621 | wpa_printf(MSG_DEBUG, "nl80211: Could not add multicast " | |
1622 | "membership for vendor events: %d (%s)", | |
1623 | ret, strerror(-ret)); | |
1624 | /* Continue without vendor events */ | |
1625 | } | |
1626 | ||
d6c9aab8 JB |
1627 | nl_cb_set(global->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, |
1628 | no_seq_check, NULL); | |
1629 | nl_cb_set(global->nl_cb, NL_CB_VALID, NL_CB_CUSTOM, | |
1630 | process_global_event, global); | |
1631 | ||
5f65e9f7 JB |
1632 | nl80211_register_eloop_read(&global->nl_event, |
1633 | wpa_driver_nl80211_event_receive, | |
1634 | global->nl_cb); | |
d6c9aab8 JB |
1635 | |
1636 | return 0; | |
1637 | ||
1638 | err: | |
1639 | nl_destroy_handles(&global->nl_event); | |
1640 | nl_destroy_handles(&global->nl); | |
1641 | nl_cb_put(global->nl_cb); | |
671a5039 | 1642 | global->nl_cb = NULL; |
d6c9aab8 JB |
1643 | return -1; |
1644 | } | |
1645 | ||
1646 | ||
f51f54a0 JM |
1647 | static void nl80211_check_global(struct nl80211_global *global) |
1648 | { | |
1649 | struct nl_handle *handle; | |
1650 | const char *groups[] = { "scan", "mlme", "regulatory", "vendor", NULL }; | |
1651 | int ret; | |
1652 | unsigned int i; | |
1653 | ||
1654 | /* | |
1655 | * Try to re-add memberships to handle case of cfg80211 getting reloaded | |
1656 | * and all registration having been cleared. | |
1657 | */ | |
1658 | handle = (void *) (((intptr_t) global->nl_event) ^ | |
1659 | ELOOP_SOCKET_INVALID); | |
1660 | ||
1661 | for (i = 0; groups[i]; i++) { | |
1662 | ret = nl_get_multicast_id(global, "nl80211", groups[i]); | |
1663 | if (ret >= 0) | |
1664 | ret = nl_socket_add_membership(handle, ret); | |
1665 | if (ret < 0) { | |
1666 | wpa_printf(MSG_INFO, | |
1667 | "nl80211: Could not re-add multicast membership for %s events: %d (%s)", | |
1668 | groups[i], ret, strerror(-ret)); | |
1669 | } | |
1670 | } | |
1671 | } | |
1672 | ||
1673 | ||
8401a6b0 JM |
1674 | static void wpa_driver_nl80211_rfkill_blocked(void *ctx) |
1675 | { | |
6da504a1 IP |
1676 | struct wpa_driver_nl80211_data *drv = ctx; |
1677 | ||
8401a6b0 | 1678 | wpa_printf(MSG_DEBUG, "nl80211: RFKILL blocked"); |
6da504a1 | 1679 | |
a63063b4 | 1680 | /* |
6da504a1 IP |
1681 | * rtnetlink ifdown handler will report interfaces other than the P2P |
1682 | * Device interface as disabled. | |
a63063b4 | 1683 | */ |
6da504a1 IP |
1684 | if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) |
1685 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_DISABLED, NULL); | |
8401a6b0 JM |
1686 | } |
1687 | ||
1688 | ||
1689 | static void wpa_driver_nl80211_rfkill_unblocked(void *ctx) | |
1690 | { | |
1691 | struct wpa_driver_nl80211_data *drv = ctx; | |
1692 | wpa_printf(MSG_DEBUG, "nl80211: RFKILL unblocked"); | |
834ee56f | 1693 | if (i802_set_iface_flags(drv->first_bss, 1)) { |
8401a6b0 JM |
1694 | wpa_printf(MSG_DEBUG, "nl80211: Could not set interface UP " |
1695 | "after rfkill unblock"); | |
1696 | return; | |
1697 | } | |
e8dc205f AO |
1698 | |
1699 | if (is_p2p_net_interface(drv->nlmode)) | |
1700 | nl80211_disable_11b_rates(drv, drv->ifindex, 1); | |
1701 | ||
6da504a1 IP |
1702 | /* |
1703 | * rtnetlink ifup handler will report interfaces other than the P2P | |
1704 | * Device interface as enabled. | |
1705 | */ | |
1706 | if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) | |
1707 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_ENABLED, NULL); | |
8401a6b0 JM |
1708 | } |
1709 | ||
1710 | ||
32ab4855 JB |
1711 | static void wpa_driver_nl80211_handle_eapol_tx_status(int sock, |
1712 | void *eloop_ctx, | |
1713 | void *handle) | |
1714 | { | |
1715 | struct wpa_driver_nl80211_data *drv = eloop_ctx; | |
1716 | u8 data[2048]; | |
1717 | struct msghdr msg; | |
1718 | struct iovec entry; | |
cad0f50e | 1719 | u8 control[512]; |
32ab4855 JB |
1720 | struct cmsghdr *cmsg; |
1721 | int res, found_ee = 0, found_wifi = 0, acked = 0; | |
1722 | union wpa_event_data event; | |
1723 | ||
1724 | memset(&msg, 0, sizeof(msg)); | |
1725 | msg.msg_iov = &entry; | |
1726 | msg.msg_iovlen = 1; | |
1727 | entry.iov_base = data; | |
1728 | entry.iov_len = sizeof(data); | |
1729 | msg.msg_control = &control; | |
1730 | msg.msg_controllen = sizeof(control); | |
1731 | ||
1732 | res = recvmsg(sock, &msg, MSG_ERRQUEUE); | |
1733 | /* if error or not fitting 802.3 header, return */ | |
1734 | if (res < 14) | |
1735 | return; | |
1736 | ||
1737 | for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg)) | |
1738 | { | |
1739 | if (cmsg->cmsg_level == SOL_SOCKET && | |
1740 | cmsg->cmsg_type == SCM_WIFI_STATUS) { | |
1741 | int *ack; | |
1742 | ||
1743 | found_wifi = 1; | |
1744 | ack = (void *)CMSG_DATA(cmsg); | |
1745 | acked = *ack; | |
1746 | } | |
1747 | ||
1748 | if (cmsg->cmsg_level == SOL_PACKET && | |
1749 | cmsg->cmsg_type == PACKET_TX_TIMESTAMP) { | |
1750 | struct sock_extended_err *err = | |
1751 | (struct sock_extended_err *)CMSG_DATA(cmsg); | |
1752 | ||
1753 | if (err->ee_origin == SO_EE_ORIGIN_TXSTATUS) | |
1754 | found_ee = 1; | |
1755 | } | |
1756 | } | |
1757 | ||
1758 | if (!found_ee || !found_wifi) | |
1759 | return; | |
1760 | ||
1761 | memset(&event, 0, sizeof(event)); | |
1762 | event.eapol_tx_status.dst = data; | |
1763 | event.eapol_tx_status.data = data + 14; | |
1764 | event.eapol_tx_status.data_len = res - 14; | |
1765 | event.eapol_tx_status.ack = acked; | |
1766 | wpa_supplicant_event(drv->ctx, EVENT_EAPOL_TX_STATUS, &event); | |
1767 | } | |
1768 | ||
1769 | ||
cc7a48d1 JB |
1770 | static int nl80211_init_bss(struct i802_bss *bss) |
1771 | { | |
1772 | bss->nl_cb = nl_cb_alloc(NL_CB_DEFAULT); | |
1773 | if (!bss->nl_cb) | |
1774 | return -1; | |
1775 | ||
1776 | nl_cb_set(bss->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, | |
1777 | no_seq_check, NULL); | |
1778 | nl_cb_set(bss->nl_cb, NL_CB_VALID, NL_CB_CUSTOM, | |
1779 | process_bss_event, bss); | |
1780 | ||
1781 | return 0; | |
1782 | } | |
1783 | ||
1784 | ||
1785 | static void nl80211_destroy_bss(struct i802_bss *bss) | |
1786 | { | |
1787 | nl_cb_put(bss->nl_cb); | |
1788 | bss->nl_cb = NULL; | |
1789 | } | |
1790 | ||
1791 | ||
0e92fb8f JB |
1792 | static void |
1793 | wpa_driver_nl80211_drv_init_rfkill(struct wpa_driver_nl80211_data *drv) | |
1794 | { | |
1795 | struct rfkill_config *rcfg; | |
1796 | ||
1797 | if (drv->rfkill) | |
1798 | return; | |
1799 | ||
1800 | rcfg = os_zalloc(sizeof(*rcfg)); | |
1801 | if (!rcfg) | |
1802 | return; | |
1803 | ||
1804 | rcfg->ctx = drv; | |
1805 | ||
1806 | /* rfkill uses netdev sysfs for initialization. However, P2P Device is | |
1807 | * not associated with a netdev, so use the name of some other interface | |
1808 | * sharing the same wiphy as the P2P Device interface. | |
1809 | * | |
1810 | * Note: This is valid, as a P2P Device interface is always dynamically | |
1811 | * created and is created only once another wpa_s interface was added. | |
1812 | */ | |
1813 | if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) { | |
1814 | struct nl80211_global *global = drv->global; | |
1815 | struct wpa_driver_nl80211_data *tmp1; | |
1816 | ||
1817 | dl_list_for_each(tmp1, &global->interfaces, | |
1818 | struct wpa_driver_nl80211_data, list) { | |
1819 | if (drv == tmp1 || drv->wiphy_idx != tmp1->wiphy_idx || | |
1820 | !tmp1->rfkill) | |
1821 | continue; | |
1822 | ||
1823 | wpa_printf(MSG_DEBUG, | |
1824 | "nl80211: Use (%s) to initialize P2P Device rfkill", | |
1825 | tmp1->first_bss->ifname); | |
1826 | os_strlcpy(rcfg->ifname, tmp1->first_bss->ifname, | |
1827 | sizeof(rcfg->ifname)); | |
1828 | break; | |
1829 | } | |
1830 | } else { | |
1831 | os_strlcpy(rcfg->ifname, drv->first_bss->ifname, | |
1832 | sizeof(rcfg->ifname)); | |
1833 | } | |
1834 | ||
1835 | rcfg->blocked_cb = wpa_driver_nl80211_rfkill_blocked; | |
1836 | rcfg->unblocked_cb = wpa_driver_nl80211_rfkill_unblocked; | |
1837 | drv->rfkill = rfkill_init(rcfg); | |
1838 | if (!drv->rfkill) { | |
1839 | wpa_printf(MSG_DEBUG, "nl80211: RFKILL status not available"); | |
1840 | os_free(rcfg); | |
1841 | } | |
1842 | } | |
1843 | ||
1844 | ||
0d547d5f JM |
1845 | static void * wpa_driver_nl80211_drv_init(void *ctx, const char *ifname, |
1846 | void *global_priv, int hostapd, | |
0ecff8d7 JM |
1847 | const u8 *set_addr, |
1848 | const char *driver_params) | |
9fff9fdc | 1849 | { |
9fff9fdc | 1850 | struct wpa_driver_nl80211_data *drv; |
a2e40bb6 | 1851 | struct i802_bss *bss; |
9fff9fdc | 1852 | |
a5c696ad JM |
1853 | if (global_priv == NULL) |
1854 | return NULL; | |
9fff9fdc JM |
1855 | drv = os_zalloc(sizeof(*drv)); |
1856 | if (drv == NULL) | |
1857 | return NULL; | |
f2ed8023 | 1858 | drv->global = global_priv; |
9fff9fdc | 1859 | drv->ctx = ctx; |
0d547d5f JM |
1860 | drv->hostapd = !!hostapd; |
1861 | drv->eapol_sock = -1; | |
64ae2447 JM |
1862 | |
1863 | /* | |
1864 | * There is no driver capability flag for this, so assume it is | |
1865 | * supported and disable this on first attempt to use if the driver | |
1866 | * rejects the command due to missing support. | |
1867 | */ | |
1868 | drv->set_rekey_offload = 1; | |
1869 | ||
0d547d5f JM |
1870 | drv->num_if_indices = sizeof(drv->default_if_indices) / sizeof(int); |
1871 | drv->if_indices = drv->default_if_indices; | |
732b1d20 | 1872 | drv->if_indices_reason = drv->default_if_indices_reason; |
834ee56f KP |
1873 | |
1874 | drv->first_bss = os_zalloc(sizeof(*drv->first_bss)); | |
1875 | if (!drv->first_bss) { | |
1876 | os_free(drv); | |
1877 | return NULL; | |
1878 | } | |
1879 | bss = drv->first_bss; | |
a2e40bb6 | 1880 | bss->drv = drv; |
a5e1eb20 SE |
1881 | bss->ctx = ctx; |
1882 | ||
a2e40bb6 | 1883 | os_strlcpy(bss->ifname, ifname, sizeof(bss->ifname)); |
9fff9fdc JM |
1884 | drv->monitor_ifidx = -1; |
1885 | drv->monitor_sock = -1; | |
d12dab4c | 1886 | drv->eapol_tx_sock = -1; |
b1f625e0 | 1887 | drv->ap_scan_as_station = NL80211_IFTYPE_UNSPECIFIED; |
9fff9fdc | 1888 | |
cc7a48d1 JB |
1889 | if (nl80211_init_bss(bss)) |
1890 | goto failed; | |
1891 | ||
0ecff8d7 | 1892 | if (wpa_driver_nl80211_finish_drv_init(drv, set_addr, 1, driver_params)) |
bbaf0837 | 1893 | goto failed; |
7524cfb1 | 1894 | |
d12dab4c | 1895 | drv->eapol_tx_sock = socket(PF_PACKET, SOCK_DGRAM, 0); |
32ab4855 JB |
1896 | if (drv->eapol_tx_sock < 0) |
1897 | goto failed; | |
1898 | ||
1899 | if (drv->data_tx_status) { | |
1900 | int enabled = 1; | |
1901 | ||
1902 | if (setsockopt(drv->eapol_tx_sock, SOL_SOCKET, SO_WIFI_STATUS, | |
1903 | &enabled, sizeof(enabled)) < 0) { | |
1904 | wpa_printf(MSG_DEBUG, | |
1905 | "nl80211: wifi status sockopt failed\n"); | |
1906 | drv->data_tx_status = 0; | |
a11241fa JB |
1907 | if (!drv->use_monitor) |
1908 | drv->capa.flags &= | |
1909 | ~WPA_DRIVER_FLAGS_EAPOL_TX_STATUS; | |
32ab4855 JB |
1910 | } else { |
1911 | eloop_register_read_sock(drv->eapol_tx_sock, | |
1912 | wpa_driver_nl80211_handle_eapol_tx_status, | |
1913 | drv, NULL); | |
1914 | } | |
1915 | } | |
f10bfc9a | 1916 | |
dac12351 | 1917 | if (drv->global) { |
f51f54a0 | 1918 | nl80211_check_global(drv->global); |
c4bb8817 | 1919 | dl_list_add(&drv->global->interfaces, &drv->list); |
dac12351 BG |
1920 | drv->in_interface_list = 1; |
1921 | } | |
c4bb8817 | 1922 | |
a2e40bb6 | 1923 | return bss; |
7524cfb1 | 1924 | |
bbaf0837 | 1925 | failed: |
dac12351 | 1926 | wpa_driver_nl80211_deinit(bss); |
7524cfb1 JM |
1927 | return NULL; |
1928 | } | |
1929 | ||
1930 | ||
0d547d5f JM |
1931 | /** |
1932 | * wpa_driver_nl80211_init - Initialize nl80211 driver interface | |
1933 | * @ctx: context to be used when calling wpa_supplicant functions, | |
1934 | * e.g., wpa_supplicant_event() | |
1935 | * @ifname: interface name, e.g., wlan0 | |
1936 | * @global_priv: private driver global data from global_init() | |
1937 | * Returns: Pointer to private data, %NULL on failure | |
1938 | */ | |
1939 | static void * wpa_driver_nl80211_init(void *ctx, const char *ifname, | |
1940 | void *global_priv) | |
1941 | { | |
0ecff8d7 JM |
1942 | return wpa_driver_nl80211_drv_init(ctx, ifname, global_priv, 0, NULL, |
1943 | NULL); | |
0d547d5f JM |
1944 | } |
1945 | ||
1946 | ||
a11241fa | 1947 | static int nl80211_register_frame(struct i802_bss *bss, |
5582a5d1 | 1948 | struct nl_handle *nl_handle, |
bd94971e | 1949 | u16 type, const u8 *match, size_t match_len) |
58f6fbe0 | 1950 | { |
a11241fa | 1951 | struct wpa_driver_nl80211_data *drv = bss->drv; |
58f6fbe0 | 1952 | struct nl_msg *msg; |
a862e4a3 | 1953 | int ret; |
880de885 | 1954 | char buf[30]; |
58f6fbe0 | 1955 | |
880de885 JM |
1956 | buf[0] = '\0'; |
1957 | wpa_snprintf_hex(buf, sizeof(buf), match, match_len); | |
dedfa440 PF |
1958 | wpa_printf(MSG_DEBUG, "nl80211: Register frame type=0x%x (%s) nl_handle=%p match=%s", |
1959 | type, fc2str(type), nl_handle, buf); | |
36488c05 | 1960 | |
56f77852 | 1961 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_REGISTER_ACTION)) || |
a862e4a3 JM |
1962 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, type) || |
1963 | nla_put(msg, NL80211_ATTR_FRAME_MATCH, match_len, match)) { | |
1964 | nlmsg_free(msg); | |
1965 | return -1; | |
1966 | } | |
58f6fbe0 | 1967 | |
d6c9aab8 | 1968 | ret = send_and_recv(drv->global, nl_handle, msg, NULL, NULL); |
58f6fbe0 | 1969 | if (ret) { |
5582a5d1 JB |
1970 | wpa_printf(MSG_DEBUG, "nl80211: Register frame command " |
1971 | "failed (type=%u): ret=%d (%s)", | |
1972 | type, ret, strerror(-ret)); | |
1973 | wpa_hexdump(MSG_DEBUG, "nl80211: Register frame match", | |
58f6fbe0 | 1974 | match, match_len); |
58f6fbe0 | 1975 | } |
58f6fbe0 JM |
1976 | return ret; |
1977 | } | |
1978 | ||
1979 | ||
a11241fa JB |
1980 | static int nl80211_alloc_mgmt_handle(struct i802_bss *bss) |
1981 | { | |
481234cf | 1982 | if (bss->nl_mgmt) { |
a11241fa | 1983 | wpa_printf(MSG_DEBUG, "nl80211: Mgmt reporting " |
36488c05 | 1984 | "already on! (nl_mgmt=%p)", bss->nl_mgmt); |
a11241fa JB |
1985 | return -1; |
1986 | } | |
1987 | ||
ce20a370 | 1988 | bss->nl_mgmt = nl_create_handle(bss->nl_cb, "mgmt"); |
481234cf | 1989 | if (bss->nl_mgmt == NULL) |
a11241fa JB |
1990 | return -1; |
1991 | ||
a11241fa JB |
1992 | return 0; |
1993 | } | |
1994 | ||
1995 | ||
5f65e9f7 JB |
1996 | static void nl80211_mgmt_handle_register_eloop(struct i802_bss *bss) |
1997 | { | |
1998 | nl80211_register_eloop_read(&bss->nl_mgmt, | |
1999 | wpa_driver_nl80211_event_receive, | |
2000 | bss->nl_cb); | |
2001 | } | |
2002 | ||
2003 | ||
a11241fa | 2004 | static int nl80211_register_action_frame(struct i802_bss *bss, |
bd94971e JB |
2005 | const u8 *match, size_t match_len) |
2006 | { | |
2007 | u16 type = (WLAN_FC_TYPE_MGMT << 2) | (WLAN_FC_STYPE_ACTION << 4); | |
481234cf | 2008 | return nl80211_register_frame(bss, bss->nl_mgmt, |
5582a5d1 | 2009 | type, match, match_len); |
bd94971e JB |
2010 | } |
2011 | ||
2012 | ||
a11241fa | 2013 | static int nl80211_mgmt_subscribe_non_ap(struct i802_bss *bss) |
58f6fbe0 | 2014 | { |
a11241fa | 2015 | struct wpa_driver_nl80211_data *drv = bss->drv; |
6f06766e | 2016 | int ret = 0; |
a11241fa JB |
2017 | |
2018 | if (nl80211_alloc_mgmt_handle(bss)) | |
2019 | return -1; | |
36488c05 JM |
2020 | wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with non-AP " |
2021 | "handle %p", bss->nl_mgmt); | |
a11241fa | 2022 | |
e8d1168b JB |
2023 | if (drv->nlmode == NL80211_IFTYPE_ADHOC) { |
2024 | u16 type = (WLAN_FC_TYPE_MGMT << 2) | (WLAN_FC_STYPE_AUTH << 4); | |
2025 | ||
2026 | /* register for any AUTH message */ | |
2027 | nl80211_register_frame(bss, bss->nl_mgmt, type, NULL, 0); | |
2028 | } | |
2029 | ||
56f5af48 JM |
2030 | #ifdef CONFIG_INTERWORKING |
2031 | /* QoS Map Configure */ | |
2032 | if (nl80211_register_action_frame(bss, (u8 *) "\x01\x04", 2) < 0) | |
6f06766e | 2033 | ret = -1; |
56f5af48 | 2034 | #endif /* CONFIG_INTERWORKING */ |
00b02149 | 2035 | #if defined(CONFIG_P2P) || defined(CONFIG_INTERWORKING) || defined(CONFIG_DPP) |
046b26a2 | 2036 | /* GAS Initial Request */ |
a11241fa | 2037 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0a", 2) < 0) |
6f06766e | 2038 | ret = -1; |
046b26a2 | 2039 | /* GAS Initial Response */ |
a11241fa | 2040 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0b", 2) < 0) |
6f06766e | 2041 | ret = -1; |
18708aad | 2042 | /* GAS Comeback Request */ |
a11241fa | 2043 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0c", 2) < 0) |
6f06766e | 2044 | ret = -1; |
18708aad | 2045 | /* GAS Comeback Response */ |
a11241fa | 2046 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0d", 2) < 0) |
6f06766e | 2047 | ret = -1; |
c5a64e2d JM |
2048 | /* Protected GAS Initial Request */ |
2049 | if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0a", 2) < 0) | |
2050 | ret = -1; | |
2051 | /* Protected GAS Initial Response */ | |
2052 | if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0b", 2) < 0) | |
2053 | ret = -1; | |
2054 | /* Protected GAS Comeback Request */ | |
2055 | if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0c", 2) < 0) | |
2056 | ret = -1; | |
2057 | /* Protected GAS Comeback Response */ | |
2058 | if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0d", 2) < 0) | |
2059 | ret = -1; | |
00b02149 | 2060 | #endif /* CONFIG_P2P || CONFIG_INTERWORKING || CONFIG_DPP */ |
4fe9fa0d | 2061 | #ifdef CONFIG_P2P |
046b26a2 | 2062 | /* P2P Public Action */ |
a11241fa | 2063 | if (nl80211_register_action_frame(bss, |
046b26a2 JM |
2064 | (u8 *) "\x04\x09\x50\x6f\x9a\x09", |
2065 | 6) < 0) | |
6f06766e | 2066 | ret = -1; |
046b26a2 | 2067 | /* P2P Action */ |
a11241fa | 2068 | if (nl80211_register_action_frame(bss, |
046b26a2 JM |
2069 | (u8 *) "\x7f\x50\x6f\x9a\x09", |
2070 | 5) < 0) | |
6f06766e | 2071 | ret = -1; |
046b26a2 | 2072 | #endif /* CONFIG_P2P */ |
00b02149 JM |
2073 | #ifdef CONFIG_DPP |
2074 | /* DPP Public Action */ | |
2075 | if (nl80211_register_action_frame(bss, | |
2076 | (u8 *) "\x04\x09\x50\x6f\x9a\x1a", | |
2077 | 6) < 0) | |
2078 | ret = -1; | |
2079 | #endif /* CONFIG_DPP */ | |
7d878ca7 JM |
2080 | #ifdef CONFIG_IEEE80211W |
2081 | /* SA Query Response */ | |
a11241fa | 2082 | if (nl80211_register_action_frame(bss, (u8 *) "\x08\x01", 2) < 0) |
6f06766e | 2083 | ret = -1; |
7d878ca7 | 2084 | #endif /* CONFIG_IEEE80211W */ |
35287637 AN |
2085 | #ifdef CONFIG_TDLS |
2086 | if ((drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) { | |
2087 | /* TDLS Discovery Response */ | |
aa543c0c | 2088 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0e", 2) < |
35287637 | 2089 | 0) |
6f06766e | 2090 | ret = -1; |
35287637 AN |
2091 | } |
2092 | #endif /* CONFIG_TDLS */ | |
46ab9b8c AN |
2093 | #ifdef CONFIG_FST |
2094 | /* FST Action frames */ | |
2095 | if (nl80211_register_action_frame(bss, (u8 *) "\x12", 1) < 0) | |
2096 | ret = -1; | |
2097 | #endif /* CONFIG_FST */ | |
046b26a2 | 2098 | |
7b90c16a | 2099 | /* FT Action frames */ |
a11241fa | 2100 | if (nl80211_register_action_frame(bss, (u8 *) "\x06", 1) < 0) |
6f06766e | 2101 | ret = -1; |
7b90c16a JM |
2102 | else |
2103 | drv->capa.key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FT | | |
2104 | WPA_DRIVER_CAPA_KEY_MGMT_FT_PSK; | |
2105 | ||
71269b37 | 2106 | /* WNM - BSS Transition Management Request */ |
a11241fa | 2107 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x07", 2) < 0) |
6f06766e | 2108 | ret = -1; |
bd896433 JM |
2109 | /* WNM-Sleep Mode Response */ |
2110 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x11", 2) < 0) | |
6f06766e | 2111 | ret = -1; |
a11241fa | 2112 | |
95a3ea94 JM |
2113 | #ifdef CONFIG_HS20 |
2114 | /* WNM-Notification */ | |
2115 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x1a", 2) < 0) | |
3ee18569 | 2116 | ret = -1; |
95a3ea94 JM |
2117 | #endif /* CONFIG_HS20 */ |
2118 | ||
dfa87878 MB |
2119 | /* WMM-AC ADDTS Response */ |
2120 | if (nl80211_register_action_frame(bss, (u8 *) "\x11\x01", 2) < 0) | |
730a0d16 | 2121 | ret = -1; |
dfa87878 MB |
2122 | |
2123 | /* WMM-AC DELTS */ | |
2124 | if (nl80211_register_action_frame(bss, (u8 *) "\x11\x02", 2) < 0) | |
730a0d16 | 2125 | ret = -1; |
dfa87878 | 2126 | |
2526ccd9 AK |
2127 | /* Radio Measurement - Neighbor Report Response */ |
2128 | if (nl80211_register_action_frame(bss, (u8 *) "\x05\x05", 2) < 0) | |
2129 | ret = -1; | |
2130 | ||
864b9522 DS |
2131 | /* Radio Measurement - Radio Measurement Request */ |
2132 | if (nl80211_register_action_frame(bss, (u8 *) "\x05\x00", 2) < 0) | |
2133 | ret = -1; | |
2134 | ||
7dc03388 AO |
2135 | /* Radio Measurement - Link Measurement Request */ |
2136 | if ((drv->capa.rrm_flags & WPA_DRIVER_FLAGS_TX_POWER_INSERTION) && | |
2137 | (nl80211_register_action_frame(bss, (u8 *) "\x05\x02", 2) < 0)) | |
2138 | ret = -1; | |
2139 | ||
5f65e9f7 JB |
2140 | nl80211_mgmt_handle_register_eloop(bss); |
2141 | ||
6f06766e | 2142 | return ret; |
a11241fa JB |
2143 | } |
2144 | ||
2145 | ||
afb0550a BC |
2146 | static int nl80211_mgmt_subscribe_mesh(struct i802_bss *bss) |
2147 | { | |
2148 | int ret = 0; | |
2149 | ||
2150 | if (nl80211_alloc_mgmt_handle(bss)) | |
2151 | return -1; | |
2152 | ||
2153 | wpa_printf(MSG_DEBUG, | |
2154 | "nl80211: Subscribe to mgmt frames with mesh handle %p", | |
2155 | bss->nl_mgmt); | |
2156 | ||
2157 | /* Auth frames for mesh SAE */ | |
2158 | if (nl80211_register_frame(bss, bss->nl_mgmt, | |
2159 | (WLAN_FC_TYPE_MGMT << 2) | | |
2160 | (WLAN_FC_STYPE_AUTH << 4), | |
2161 | NULL, 0) < 0) | |
2162 | ret = -1; | |
2163 | ||
2164 | /* Mesh peering open */ | |
2165 | if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x01", 2) < 0) | |
2166 | ret = -1; | |
2167 | /* Mesh peering confirm */ | |
2168 | if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x02", 2) < 0) | |
2169 | ret = -1; | |
2170 | /* Mesh peering close */ | |
2171 | if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x03", 2) < 0) | |
2172 | ret = -1; | |
2173 | ||
2174 | nl80211_mgmt_handle_register_eloop(bss); | |
2175 | ||
2176 | return ret; | |
2177 | } | |
2178 | ||
2179 | ||
02bb32c3 JB |
2180 | static int nl80211_register_spurious_class3(struct i802_bss *bss) |
2181 | { | |
02bb32c3 | 2182 | struct nl_msg *msg; |
a862e4a3 | 2183 | int ret; |
02bb32c3 | 2184 | |
13f83980 JM |
2185 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_UNEXPECTED_FRAME); |
2186 | ret = send_and_recv(bss->drv->global, bss->nl_mgmt, msg, NULL, NULL); | |
02bb32c3 JB |
2187 | if (ret) { |
2188 | wpa_printf(MSG_DEBUG, "nl80211: Register spurious class3 " | |
2189 | "failed: ret=%d (%s)", | |
2190 | ret, strerror(-ret)); | |
02bb32c3 | 2191 | } |
02bb32c3 JB |
2192 | return ret; |
2193 | } | |
2194 | ||
2195 | ||
4d916ed6 KV |
2196 | static int nl80211_action_subscribe_ap(struct i802_bss *bss) |
2197 | { | |
2198 | int ret = 0; | |
2199 | ||
2200 | /* Public Action frames */ | |
2201 | if (nl80211_register_action_frame(bss, (u8 *) "\x04", 1) < 0) | |
2202 | ret = -1; | |
2203 | /* RRM Measurement Report */ | |
2204 | if (nl80211_register_action_frame(bss, (u8 *) "\x05\x01", 2) < 0) | |
2205 | ret = -1; | |
e4ec6bbf JM |
2206 | /* RRM Link Measurement Report */ |
2207 | if (nl80211_register_action_frame(bss, (u8 *) "\x05\x03", 2) < 0) | |
2208 | ret = -1; | |
4d916ed6 KV |
2209 | /* RRM Neighbor Report Request */ |
2210 | if (nl80211_register_action_frame(bss, (u8 *) "\x05\x04", 2) < 0) | |
2211 | ret = -1; | |
2212 | /* FT Action frames */ | |
2213 | if (nl80211_register_action_frame(bss, (u8 *) "\x06", 1) < 0) | |
2214 | ret = -1; | |
2215 | #ifdef CONFIG_IEEE80211W | |
2216 | /* SA Query */ | |
2217 | if (nl80211_register_action_frame(bss, (u8 *) "\x08", 1) < 0) | |
2218 | ret = -1; | |
2219 | #endif /* CONFIG_IEEE80211W */ | |
2220 | /* Protected Dual of Public Action */ | |
2221 | if (nl80211_register_action_frame(bss, (u8 *) "\x09", 1) < 0) | |
2222 | ret = -1; | |
2223 | /* WNM */ | |
2224 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a", 1) < 0) | |
2225 | ret = -1; | |
2226 | /* WMM */ | |
2227 | if (nl80211_register_action_frame(bss, (u8 *) "\x11", 1) < 0) | |
2228 | ret = -1; | |
2229 | #ifdef CONFIG_FST | |
2230 | /* FST Action frames */ | |
2231 | if (nl80211_register_action_frame(bss, (u8 *) "\x12", 1) < 0) | |
2232 | ret = -1; | |
2233 | #endif /* CONFIG_FST */ | |
2234 | /* Vendor-specific */ | |
2235 | if (nl80211_register_action_frame(bss, (u8 *) "\x7f", 1) < 0) | |
2236 | ret = -1; | |
2237 | ||
2238 | return ret; | |
2239 | } | |
2240 | ||
2241 | ||
a11241fa JB |
2242 | static int nl80211_mgmt_subscribe_ap(struct i802_bss *bss) |
2243 | { | |
2244 | static const int stypes[] = { | |
2245 | WLAN_FC_STYPE_AUTH, | |
2246 | WLAN_FC_STYPE_ASSOC_REQ, | |
2247 | WLAN_FC_STYPE_REASSOC_REQ, | |
2248 | WLAN_FC_STYPE_DISASSOC, | |
2249 | WLAN_FC_STYPE_DEAUTH, | |
a11241fa JB |
2250 | WLAN_FC_STYPE_PROBE_REQ, |
2251 | /* Beacon doesn't work as mac80211 doesn't currently allow | |
2252 | * it, but it wouldn't really be the right thing anyway as | |
2253 | * it isn't per interface ... maybe just dump the scan | |
2254 | * results periodically for OLBC? | |
2255 | */ | |
0e80ea2c | 2256 | /* WLAN_FC_STYPE_BEACON, */ |
a11241fa JB |
2257 | }; |
2258 | unsigned int i; | |
2259 | ||
2260 | if (nl80211_alloc_mgmt_handle(bss)) | |
71269b37 | 2261 | return -1; |
36488c05 JM |
2262 | wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with AP " |
2263 | "handle %p", bss->nl_mgmt); | |
71269b37 | 2264 | |
e7ecab4a | 2265 | for (i = 0; i < ARRAY_SIZE(stypes); i++) { |
481234cf | 2266 | if (nl80211_register_frame(bss, bss->nl_mgmt, |
a11241fa JB |
2267 | (WLAN_FC_TYPE_MGMT << 2) | |
2268 | (stypes[i] << 4), | |
2269 | NULL, 0) < 0) { | |
2270 | goto out_err; | |
2271 | } | |
2272 | } | |
2273 | ||
4d916ed6 KV |
2274 | if (nl80211_action_subscribe_ap(bss)) |
2275 | goto out_err; | |
2276 | ||
02bb32c3 JB |
2277 | if (nl80211_register_spurious_class3(bss)) |
2278 | goto out_err; | |
2279 | ||
5f65e9f7 | 2280 | nl80211_mgmt_handle_register_eloop(bss); |
58f6fbe0 | 2281 | return 0; |
a11241fa JB |
2282 | |
2283 | out_err: | |
a11241fa JB |
2284 | nl_destroy_handles(&bss->nl_mgmt); |
2285 | return -1; | |
2286 | } | |
2287 | ||
2288 | ||
a6cc0602 JM |
2289 | static int nl80211_mgmt_subscribe_ap_dev_sme(struct i802_bss *bss) |
2290 | { | |
2291 | if (nl80211_alloc_mgmt_handle(bss)) | |
2292 | return -1; | |
2293 | wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with AP " | |
2294 | "handle %p (device SME)", bss->nl_mgmt); | |
2295 | ||
4d916ed6 | 2296 | if (nl80211_action_subscribe_ap(bss)) |
a6cc0602 JM |
2297 | goto out_err; |
2298 | ||
5f65e9f7 | 2299 | nl80211_mgmt_handle_register_eloop(bss); |
a6cc0602 JM |
2300 | return 0; |
2301 | ||
2302 | out_err: | |
a6cc0602 JM |
2303 | nl_destroy_handles(&bss->nl_mgmt); |
2304 | return -1; | |
2305 | } | |
2306 | ||
2307 | ||
36488c05 | 2308 | static void nl80211_mgmt_unsubscribe(struct i802_bss *bss, const char *reason) |
a11241fa | 2309 | { |
481234cf | 2310 | if (bss->nl_mgmt == NULL) |
a11241fa | 2311 | return; |
36488c05 JM |
2312 | wpa_printf(MSG_DEBUG, "nl80211: Unsubscribe mgmt frames handle %p " |
2313 | "(%s)", bss->nl_mgmt, reason); | |
5f65e9f7 | 2314 | nl80211_destroy_eloop_handle(&bss->nl_mgmt); |
7813b7c3 MH |
2315 | |
2316 | nl80211_put_wiphy_data_ap(bss); | |
58f6fbe0 JM |
2317 | } |
2318 | ||
2319 | ||
8401a6b0 JM |
2320 | static void wpa_driver_nl80211_send_rfkill(void *eloop_ctx, void *timeout_ctx) |
2321 | { | |
2322 | wpa_supplicant_event(timeout_ctx, EVENT_INTERFACE_DISABLED, NULL); | |
2323 | } | |
2324 | ||
2325 | ||
eb4582f2 AS |
2326 | static void nl80211_del_p2pdev(struct i802_bss *bss) |
2327 | { | |
eb4582f2 AS |
2328 | struct nl_msg *msg; |
2329 | int ret; | |
2330 | ||
a3249fdf JM |
2331 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_DEL_INTERFACE); |
2332 | ret = send_and_recv_msgs(bss->drv, msg, NULL, NULL); | |
eb4582f2 AS |
2333 | |
2334 | wpa_printf(MSG_DEBUG, "nl80211: Delete P2P Device %s (0x%llx): %s", | |
2335 | bss->ifname, (long long unsigned int) bss->wdev_id, | |
6cb4f11d | 2336 | strerror(-ret)); |
eb4582f2 AS |
2337 | } |
2338 | ||
2339 | ||
eb4582f2 | 2340 | static int nl80211_set_p2pdev(struct i802_bss *bss, int start) |
f632e483 | 2341 | { |
f632e483 | 2342 | struct nl_msg *msg; |
a862e4a3 | 2343 | int ret; |
f632e483 | 2344 | |
a3249fdf JM |
2345 | msg = nl80211_cmd_msg(bss, 0, start ? NL80211_CMD_START_P2P_DEVICE : |
2346 | NL80211_CMD_STOP_P2P_DEVICE); | |
2347 | ret = send_and_recv_msgs(bss->drv, msg, NULL, NULL); | |
f632e483 | 2348 | |
eb4582f2 AS |
2349 | wpa_printf(MSG_DEBUG, "nl80211: %s P2P Device %s (0x%llx): %s", |
2350 | start ? "Start" : "Stop", | |
2351 | bss->ifname, (long long unsigned int) bss->wdev_id, | |
6cb4f11d | 2352 | strerror(-ret)); |
f632e483 AS |
2353 | return ret; |
2354 | } | |
f632e483 AS |
2355 | |
2356 | ||
91724d6f AS |
2357 | static int i802_set_iface_flags(struct i802_bss *bss, int up) |
2358 | { | |
2359 | enum nl80211_iftype nlmode; | |
2360 | ||
2361 | nlmode = nl80211_get_ifmode(bss); | |
2362 | if (nlmode != NL80211_IFTYPE_P2P_DEVICE) { | |
2363 | return linux_set_iface_flags(bss->drv->global->ioctl_sock, | |
2364 | bss->ifname, up); | |
2365 | } | |
2366 | ||
2367 | /* P2P Device has start/stop which is equivalent */ | |
2368 | return nl80211_set_p2pdev(bss, up); | |
2369 | } | |
2370 | ||
2371 | ||
1db718b3 JM |
2372 | #ifdef CONFIG_TESTING_OPTIONS |
2373 | static int qca_vendor_test_cmd_handler(struct nl_msg *msg, void *arg) | |
2374 | { | |
2375 | /* struct wpa_driver_nl80211_data *drv = arg; */ | |
2376 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
2377 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
2378 | ||
2379 | ||
2380 | wpa_printf(MSG_DEBUG, | |
2381 | "nl80211: QCA vendor test command response received"); | |
2382 | ||
2383 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
2384 | genlmsg_attrlen(gnlh, 0), NULL); | |
2385 | if (!tb[NL80211_ATTR_VENDOR_DATA]) { | |
2386 | wpa_printf(MSG_DEBUG, "nl80211: No vendor data attribute"); | |
2387 | return NL_SKIP; | |
2388 | } | |
2389 | ||
2390 | wpa_hexdump(MSG_DEBUG, | |
2391 | "nl80211: Received QCA vendor test command response", | |
2392 | nla_data(tb[NL80211_ATTR_VENDOR_DATA]), | |
2393 | nla_len(tb[NL80211_ATTR_VENDOR_DATA])); | |
2394 | ||
2395 | return NL_SKIP; | |
2396 | } | |
2397 | #endif /* CONFIG_TESTING_OPTIONS */ | |
2398 | ||
2399 | ||
2400 | static void qca_vendor_test(struct wpa_driver_nl80211_data *drv) | |
2401 | { | |
2402 | #ifdef CONFIG_TESTING_OPTIONS | |
2403 | struct nl_msg *msg; | |
2404 | struct nlattr *params; | |
2405 | int ret; | |
2406 | ||
2407 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || | |
2408 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || | |
2409 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | |
2410 | QCA_NL80211_VENDOR_SUBCMD_TEST) || | |
2411 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || | |
2412 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TEST, 123)) { | |
2413 | nlmsg_free(msg); | |
2414 | return; | |
2415 | } | |
2416 | nla_nest_end(msg, params); | |
2417 | ||
2418 | ret = send_and_recv_msgs(drv, msg, qca_vendor_test_cmd_handler, drv); | |
2419 | wpa_printf(MSG_DEBUG, | |
2420 | "nl80211: QCA vendor test command returned %d (%s)", | |
2421 | ret, strerror(-ret)); | |
2422 | #endif /* CONFIG_TESTING_OPTIONS */ | |
2423 | } | |
2424 | ||
2425 | ||
362f781e | 2426 | static int |
0d547d5f | 2427 | wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data *drv, |
0ecff8d7 JM |
2428 | const u8 *set_addr, int first, |
2429 | const char *driver_params) | |
7524cfb1 | 2430 | { |
834ee56f | 2431 | struct i802_bss *bss = drv->first_bss; |
8401a6b0 | 2432 | int send_rfkill_event = 0; |
0d547d5f | 2433 | enum nl80211_iftype nlmode; |
a2e40bb6 FF |
2434 | |
2435 | drv->ifindex = if_nametoindex(bss->ifname); | |
f632e483 AS |
2436 | bss->ifindex = drv->ifindex; |
2437 | bss->wdev_id = drv->global->if_add_wdevid; | |
2438 | bss->wdev_id_set = drv->global->if_add_wdevid_set; | |
2439 | ||
60b13c20 IP |
2440 | bss->if_dynamic = drv->ifindex == drv->global->if_add_ifindex; |
2441 | bss->if_dynamic = bss->if_dynamic || drv->global->if_add_wdevid_set; | |
f632e483 AS |
2442 | drv->global->if_add_wdevid_set = 0; |
2443 | ||
bf144cf6 AP |
2444 | if (!bss->if_dynamic && nl80211_get_ifmode(bss) == NL80211_IFTYPE_AP) |
2445 | bss->static_ap = 1; | |
2446 | ||
ef3866ab IP |
2447 | if (first && |
2448 | nl80211_get_ifmode(bss) != NL80211_IFTYPE_P2P_DEVICE && | |
2449 | linux_iface_up(drv->global->ioctl_sock, bss->ifname) > 0) | |
2450 | drv->start_iface_up = 1; | |
2451 | ||
f632e483 AS |
2452 | if (wpa_driver_nl80211_capa(drv)) |
2453 | return -1; | |
a87c9d96 | 2454 | |
0ecff8d7 JM |
2455 | if (driver_params && nl80211_set_param(bss, driver_params) < 0) |
2456 | return -1; | |
2457 | ||
5fbcb45d AS |
2458 | wpa_printf(MSG_DEBUG, "nl80211: interface %s in phy %s", |
2459 | bss->ifname, drv->phyname); | |
2460 | ||
0d547d5f JM |
2461 | if (set_addr && |
2462 | (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 0) || | |
2463 | linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname, | |
2464 | set_addr))) | |
2465 | return -1; | |
2466 | ||
49b4b205 JM |
2467 | if (first && nl80211_get_ifmode(bss) == NL80211_IFTYPE_AP) |
2468 | drv->start_mode_ap = 1; | |
2469 | ||
bf144cf6 | 2470 | if (drv->hostapd || bss->static_ap) |
0d547d5f | 2471 | nlmode = NL80211_IFTYPE_AP; |
4fe726e2 FF |
2472 | else if (bss->if_dynamic || |
2473 | nl80211_get_ifmode(bss) == NL80211_IFTYPE_MESH_POINT) | |
8e12685c | 2474 | nlmode = nl80211_get_ifmode(bss); |
0d547d5f JM |
2475 | else |
2476 | nlmode = NL80211_IFTYPE_STATION; | |
f632e483 | 2477 | |
8e12685c | 2478 | if (wpa_driver_nl80211_set_mode(bss, nlmode) < 0) { |
0d547d5f | 2479 | wpa_printf(MSG_ERROR, "nl80211: Could not configure driver mode"); |
8e12685c | 2480 | return -1; |
a87c9d96 JM |
2481 | } |
2482 | ||
8c06db70 | 2483 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) |
597b94f5 | 2484 | nl80211_get_macaddr(bss); |
f632e483 | 2485 | |
0e92fb8f JB |
2486 | wpa_driver_nl80211_drv_init_rfkill(drv); |
2487 | ||
8c06db70 MB |
2488 | if (!rfkill_is_blocked(drv->rfkill)) { |
2489 | int ret = i802_set_iface_flags(bss, 1); | |
2490 | if (ret) { | |
8401a6b0 JM |
2491 | wpa_printf(MSG_ERROR, "nl80211: Could not set " |
2492 | "interface '%s' UP", bss->ifname); | |
8c06db70 | 2493 | return ret; |
8401a6b0 | 2494 | } |
e8dc205f AO |
2495 | |
2496 | if (is_p2p_net_interface(nlmode)) | |
2497 | nl80211_disable_11b_rates(bss->drv, | |
2498 | bss->drv->ifindex, 1); | |
2499 | ||
8c06db70 MB |
2500 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) |
2501 | return ret; | |
2502 | } else { | |
2503 | wpa_printf(MSG_DEBUG, "nl80211: Could not yet enable " | |
2504 | "interface '%s' due to rfkill", bss->ifname); | |
6da504a1 IP |
2505 | if (nlmode != NL80211_IFTYPE_P2P_DEVICE) |
2506 | drv->if_disabled = 1; | |
2507 | ||
8c06db70 | 2508 | send_rfkill_event = 1; |
362f781e | 2509 | } |
3f5285e8 | 2510 | |
6da504a1 | 2511 | if (!drv->hostapd && nlmode != NL80211_IFTYPE_P2P_DEVICE) |
0d547d5f JM |
2512 | netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, |
2513 | 1, IF_OPER_DORMANT); | |
362f781e | 2514 | |
6da504a1 IP |
2515 | if (nlmode != NL80211_IFTYPE_P2P_DEVICE) { |
2516 | if (linux_get_ifhwaddr(drv->global->ioctl_sock, bss->ifname, | |
2517 | bss->addr)) | |
2518 | return -1; | |
2519 | os_memcpy(drv->perm_addr, bss->addr, ETH_ALEN); | |
2520 | } | |
f2ed8023 | 2521 | |
8401a6b0 JM |
2522 | if (send_rfkill_event) { |
2523 | eloop_register_timeout(0, 0, wpa_driver_nl80211_send_rfkill, | |
2524 | drv, drv->ctx); | |
2525 | } | |
2526 | ||
1db718b3 JM |
2527 | if (drv->vendor_cmd_test_avail) |
2528 | qca_vendor_test(drv); | |
2529 | ||
362f781e | 2530 | return 0; |
3f5285e8 JM |
2531 | } |
2532 | ||
2533 | ||
a70cd0db | 2534 | static int wpa_driver_nl80211_del_beacon(struct i802_bss *bss) |
8a27af5c JM |
2535 | { |
2536 | struct nl_msg *msg; | |
a70cd0db | 2537 | struct wpa_driver_nl80211_data *drv = bss->drv; |
8a27af5c | 2538 | |
08e55ebb JM |
2539 | wpa_printf(MSG_DEBUG, "nl80211: Remove beacon (ifindex=%d)", |
2540 | drv->ifindex); | |
a70cd0db | 2541 | nl80211_put_wiphy_data_ap(bss); |
9725b784 | 2542 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_DEL_BEACON); |
8a27af5c | 2543 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
8a27af5c | 2544 | } |
8a27af5c JM |
2545 | |
2546 | ||
3f5285e8 | 2547 | /** |
7e5ba1b9 | 2548 | * wpa_driver_nl80211_deinit - Deinitialize nl80211 driver interface |
9ebce9c5 | 2549 | * @bss: Pointer to private nl80211 data from wpa_driver_nl80211_init() |
3f5285e8 JM |
2550 | * |
2551 | * Shut down driver interface and processing of driver events. Free | |
2552 | * private data buffer if one was allocated in wpa_driver_nl80211_init(). | |
2553 | */ | |
9ebce9c5 | 2554 | static void wpa_driver_nl80211_deinit(struct i802_bss *bss) |
3f5285e8 | 2555 | { |
a2e40bb6 | 2556 | struct wpa_driver_nl80211_data *drv = bss->drv; |
cc9a2575 | 2557 | unsigned int i; |
3f5285e8 | 2558 | |
3e208481 JM |
2559 | wpa_printf(MSG_INFO, "nl80211: deinit ifname=%s disabled_11b_rates=%d", |
2560 | bss->ifname, drv->disabled_11b_rates); | |
2561 | ||
873d0fcf | 2562 | bss->in_deinit = 1; |
32ab4855 JB |
2563 | if (drv->data_tx_status) |
2564 | eloop_unregister_read_sock(drv->eapol_tx_sock); | |
d12dab4c JB |
2565 | if (drv->eapol_tx_sock >= 0) |
2566 | close(drv->eapol_tx_sock); | |
f10bfc9a | 2567 | |
481234cf | 2568 | if (bss->nl_preq) |
5582a5d1 | 2569 | wpa_driver_nl80211_probe_req_report(bss, 0); |
e17a2477 | 2570 | if (bss->added_if_into_bridge) { |
c81eff1a BG |
2571 | if (linux_br_del_if(drv->global->ioctl_sock, bss->brname, |
2572 | bss->ifname) < 0) | |
94627f6c JM |
2573 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
2574 | "interface %s from bridge %s: %s", | |
e17a2477 | 2575 | bss->ifname, bss->brname, strerror(errno)); |
97ed9a06 | 2576 | if (drv->rtnl_sk) |
ca3c6b4d | 2577 | nl80211_handle_destroy(drv->rtnl_sk); |
94627f6c | 2578 | } |
e17a2477 | 2579 | if (bss->added_bridge) { |
f2535da8 JM |
2580 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->brname, |
2581 | 0) < 0) | |
2582 | wpa_printf(MSG_INFO, | |
2583 | "nl80211: Could not set bridge %s down", | |
2584 | bss->brname); | |
c81eff1a | 2585 | if (linux_br_del(drv->global->ioctl_sock, bss->brname) < 0) |
94627f6c JM |
2586 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
2587 | "bridge %s: %s", | |
e17a2477 | 2588 | bss->brname, strerror(errno)); |
94627f6c JM |
2589 | } |
2590 | ||
460456f8 | 2591 | nl80211_remove_monitor_interface(drv); |
8a27af5c | 2592 | |
b1f625e0 | 2593 | if (is_ap_interface(drv->nlmode)) |
a70cd0db | 2594 | wpa_driver_nl80211_del_beacon(bss); |
0915d02c | 2595 | |
bbaf0837 JM |
2596 | if (drv->eapol_sock >= 0) { |
2597 | eloop_unregister_read_sock(drv->eapol_sock); | |
2598 | close(drv->eapol_sock); | |
2599 | } | |
2600 | ||
2601 | if (drv->if_indices != drv->default_if_indices) | |
2602 | os_free(drv->if_indices); | |
3f5285e8 | 2603 | |
732b1d20 MB |
2604 | if (drv->if_indices_reason != drv->default_if_indices_reason) |
2605 | os_free(drv->if_indices_reason); | |
2606 | ||
b3af99d2 | 2607 | if (drv->disabled_11b_rates) |
4e5cb1a3 JM |
2608 | nl80211_disable_11b_rates(drv, drv->ifindex, 0); |
2609 | ||
36d84860 BG |
2610 | netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, 0, |
2611 | IF_OPER_UP); | |
e390df05 | 2612 | eloop_cancel_timeout(wpa_driver_nl80211_send_rfkill, drv, drv->ctx); |
8401a6b0 | 2613 | rfkill_deinit(drv->rfkill); |
3f5285e8 | 2614 | |
bbaf0837 JM |
2615 | eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout, drv, drv->ctx); |
2616 | ||
146fa9b3 JM |
2617 | if (!drv->start_iface_up) |
2618 | (void) i802_set_iface_flags(bss, 0); | |
fee354c7 JM |
2619 | |
2620 | if (drv->addr_changed) { | |
93da0498 JM |
2621 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, |
2622 | 0) < 0) { | |
2623 | wpa_printf(MSG_DEBUG, | |
2624 | "nl80211: Could not set interface down to restore permanent MAC address"); | |
2625 | } | |
fee354c7 JM |
2626 | if (linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
2627 | drv->perm_addr) < 0) { | |
2628 | wpa_printf(MSG_DEBUG, | |
2629 | "nl80211: Could not restore permanent MAC address"); | |
2630 | } | |
2631 | } | |
2632 | ||
8e12685c | 2633 | if (drv->nlmode != NL80211_IFTYPE_P2P_DEVICE) { |
49b4b205 JM |
2634 | if (!drv->hostapd || !drv->start_mode_ap) |
2635 | wpa_driver_nl80211_set_mode(bss, | |
2636 | NL80211_IFTYPE_STATION); | |
b378c41f | 2637 | nl80211_mgmt_unsubscribe(bss, "deinit"); |
8e12685c AS |
2638 | } else { |
2639 | nl80211_mgmt_unsubscribe(bss, "deinit"); | |
eb4582f2 | 2640 | nl80211_del_p2pdev(bss); |
8e12685c | 2641 | } |
3f5285e8 | 2642 | |
834ee56f | 2643 | nl80211_destroy_bss(drv->first_bss); |
cc7a48d1 | 2644 | |
3812464c JM |
2645 | os_free(drv->filter_ssids); |
2646 | ||
536fd62d JM |
2647 | os_free(drv->auth_ie); |
2648 | ||
dac12351 | 2649 | if (drv->in_interface_list) |
f2ed8023 JM |
2650 | dl_list_del(&drv->list); |
2651 | ||
8cd6b7bc JB |
2652 | os_free(drv->extended_capa); |
2653 | os_free(drv->extended_capa_mask); | |
cc9a2575 KV |
2654 | for (i = 0; i < drv->num_iface_ext_capa; i++) { |
2655 | os_free(drv->iface_ext_capa[i].ext_capa); | |
2656 | os_free(drv->iface_ext_capa[i].ext_capa_mask); | |
2657 | } | |
834ee56f | 2658 | os_free(drv->first_bss); |
3f5285e8 JM |
2659 | os_free(drv); |
2660 | } | |
2661 | ||
2662 | ||
de4ed4a8 JM |
2663 | static u32 wpa_alg_to_cipher_suite(enum wpa_alg alg, size_t key_len) |
2664 | { | |
2665 | switch (alg) { | |
2666 | case WPA_ALG_WEP: | |
2667 | if (key_len == 5) | |
a042e39a JM |
2668 | return RSN_CIPHER_SUITE_WEP40; |
2669 | return RSN_CIPHER_SUITE_WEP104; | |
de4ed4a8 | 2670 | case WPA_ALG_TKIP: |
a042e39a | 2671 | return RSN_CIPHER_SUITE_TKIP; |
de4ed4a8 | 2672 | case WPA_ALG_CCMP: |
a042e39a | 2673 | return RSN_CIPHER_SUITE_CCMP; |
de4ed4a8 | 2674 | case WPA_ALG_GCMP: |
a042e39a | 2675 | return RSN_CIPHER_SUITE_GCMP; |
de4ed4a8 | 2676 | case WPA_ALG_CCMP_256: |
a042e39a | 2677 | return RSN_CIPHER_SUITE_CCMP_256; |
de4ed4a8 | 2678 | case WPA_ALG_GCMP_256: |
a042e39a | 2679 | return RSN_CIPHER_SUITE_GCMP_256; |
de4ed4a8 | 2680 | case WPA_ALG_IGTK: |
a042e39a | 2681 | return RSN_CIPHER_SUITE_AES_128_CMAC; |
de4ed4a8 | 2682 | case WPA_ALG_BIP_GMAC_128: |
a042e39a | 2683 | return RSN_CIPHER_SUITE_BIP_GMAC_128; |
de4ed4a8 | 2684 | case WPA_ALG_BIP_GMAC_256: |
a042e39a | 2685 | return RSN_CIPHER_SUITE_BIP_GMAC_256; |
de4ed4a8 | 2686 | case WPA_ALG_BIP_CMAC_256: |
a042e39a | 2687 | return RSN_CIPHER_SUITE_BIP_CMAC_256; |
de4ed4a8 | 2688 | case WPA_ALG_SMS4: |
a042e39a | 2689 | return RSN_CIPHER_SUITE_SMS4; |
de4ed4a8 | 2690 | case WPA_ALG_KRK: |
a042e39a | 2691 | return RSN_CIPHER_SUITE_KRK; |
de4ed4a8 JM |
2692 | case WPA_ALG_NONE: |
2693 | case WPA_ALG_PMK: | |
2694 | wpa_printf(MSG_ERROR, "nl80211: Unexpected encryption algorithm %d", | |
2695 | alg); | |
2696 | return 0; | |
2697 | } | |
2698 | ||
2699 | wpa_printf(MSG_ERROR, "nl80211: Unsupported encryption algorithm %d", | |
2700 | alg); | |
2701 | return 0; | |
2702 | } | |
2703 | ||
2704 | ||
2705 | static u32 wpa_cipher_to_cipher_suite(unsigned int cipher) | |
2706 | { | |
2707 | switch (cipher) { | |
2708 | case WPA_CIPHER_CCMP_256: | |
a042e39a | 2709 | return RSN_CIPHER_SUITE_CCMP_256; |
de4ed4a8 | 2710 | case WPA_CIPHER_GCMP_256: |
a042e39a | 2711 | return RSN_CIPHER_SUITE_GCMP_256; |
de4ed4a8 | 2712 | case WPA_CIPHER_CCMP: |
a042e39a | 2713 | return RSN_CIPHER_SUITE_CCMP; |
de4ed4a8 | 2714 | case WPA_CIPHER_GCMP: |
a042e39a | 2715 | return RSN_CIPHER_SUITE_GCMP; |
de4ed4a8 | 2716 | case WPA_CIPHER_TKIP: |
a042e39a | 2717 | return RSN_CIPHER_SUITE_TKIP; |
de4ed4a8 | 2718 | case WPA_CIPHER_WEP104: |
a042e39a | 2719 | return RSN_CIPHER_SUITE_WEP104; |
de4ed4a8 | 2720 | case WPA_CIPHER_WEP40: |
a042e39a | 2721 | return RSN_CIPHER_SUITE_WEP40; |
ae6f9272 | 2722 | case WPA_CIPHER_GTK_NOT_USED: |
a042e39a | 2723 | return RSN_CIPHER_SUITE_NO_GROUP_ADDRESSED; |
de4ed4a8 JM |
2724 | } |
2725 | ||
2726 | return 0; | |
2727 | } | |
2728 | ||
2729 | ||
2730 | static int wpa_cipher_to_cipher_suites(unsigned int ciphers, u32 suites[], | |
2731 | int max_suites) | |
2732 | { | |
2733 | int num_suites = 0; | |
2734 | ||
2735 | if (num_suites < max_suites && ciphers & WPA_CIPHER_CCMP_256) | |
a042e39a | 2736 | suites[num_suites++] = RSN_CIPHER_SUITE_CCMP_256; |
de4ed4a8 | 2737 | if (num_suites < max_suites && ciphers & WPA_CIPHER_GCMP_256) |
a042e39a | 2738 | suites[num_suites++] = RSN_CIPHER_SUITE_GCMP_256; |
de4ed4a8 | 2739 | if (num_suites < max_suites && ciphers & WPA_CIPHER_CCMP) |
a042e39a | 2740 | suites[num_suites++] = RSN_CIPHER_SUITE_CCMP; |
de4ed4a8 | 2741 | if (num_suites < max_suites && ciphers & WPA_CIPHER_GCMP) |
a042e39a | 2742 | suites[num_suites++] = RSN_CIPHER_SUITE_GCMP; |
de4ed4a8 | 2743 | if (num_suites < max_suites && ciphers & WPA_CIPHER_TKIP) |
a042e39a | 2744 | suites[num_suites++] = RSN_CIPHER_SUITE_TKIP; |
de4ed4a8 | 2745 | if (num_suites < max_suites && ciphers & WPA_CIPHER_WEP104) |
a042e39a | 2746 | suites[num_suites++] = RSN_CIPHER_SUITE_WEP104; |
de4ed4a8 | 2747 | if (num_suites < max_suites && ciphers & WPA_CIPHER_WEP40) |
a042e39a | 2748 | suites[num_suites++] = RSN_CIPHER_SUITE_WEP40; |
de4ed4a8 JM |
2749 | |
2750 | return num_suites; | |
2751 | } | |
2752 | ||
2753 | ||
b658547d | 2754 | #ifdef CONFIG_DRIVER_NL80211_QCA |
b41f2684 CL |
2755 | static int issue_key_mgmt_set_key(struct wpa_driver_nl80211_data *drv, |
2756 | const u8 *key, size_t key_len) | |
2757 | { | |
2758 | struct nl_msg *msg; | |
a862e4a3 | 2759 | int ret; |
b41f2684 | 2760 | |
15badebd | 2761 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD)) |
b41f2684 CL |
2762 | return 0; |
2763 | ||
9725b784 | 2764 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
a862e4a3 JM |
2765 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
2766 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | |
2767 | QCA_NL80211_VENDOR_SUBCMD_KEY_MGMT_SET_KEY) || | |
2768 | nla_put(msg, NL80211_ATTR_VENDOR_DATA, key_len, key)) { | |
bbd89bfc | 2769 | nl80211_nlmsg_clear(msg); |
a862e4a3 JM |
2770 | nlmsg_free(msg); |
2771 | return -1; | |
2772 | } | |
bbd89bfc | 2773 | ret = send_and_recv_msgs(drv, msg, NULL, (void *) -1); |
b41f2684 CL |
2774 | if (ret) { |
2775 | wpa_printf(MSG_DEBUG, | |
2776 | "nl80211: Key management set key failed: ret=%d (%s)", | |
2777 | ret, strerror(-ret)); | |
2778 | } | |
2779 | ||
b41f2684 CL |
2780 | return ret; |
2781 | } | |
b658547d | 2782 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
b41f2684 CL |
2783 | |
2784 | ||
9ebce9c5 | 2785 | static int wpa_driver_nl80211_set_key(const char *ifname, struct i802_bss *bss, |
71934751 JM |
2786 | enum wpa_alg alg, const u8 *addr, |
2787 | int key_idx, int set_tx, | |
642187d6 JM |
2788 | const u8 *seq, size_t seq_len, |
2789 | const u8 *key, size_t key_len) | |
3f5285e8 | 2790 | { |
a2e40bb6 | 2791 | struct wpa_driver_nl80211_data *drv = bss->drv; |
e472e1b4 | 2792 | int ifindex; |
34651767 | 2793 | struct nl_msg *msg = NULL; |
1ad1cdc2 | 2794 | int ret; |
dc01de8a | 2795 | int tdls = 0; |
3f5285e8 | 2796 | |
e472e1b4 AS |
2797 | /* Ignore for P2P Device */ |
2798 | if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) | |
2799 | return 0; | |
2800 | ||
2801 | ifindex = if_nametoindex(ifname); | |
8393e1a0 | 2802 | wpa_printf(MSG_DEBUG, "%s: ifindex=%d (%s) alg=%d addr=%p key_idx=%d " |
1ad1cdc2 | 2803 | "set_tx=%d seq_len=%lu key_len=%lu", |
8393e1a0 | 2804 | __func__, ifindex, ifname, alg, addr, key_idx, set_tx, |
3f5285e8 | 2805 | (unsigned long) seq_len, (unsigned long) key_len); |
8c66e185 | 2806 | #ifdef CONFIG_TDLS |
dc01de8a | 2807 | if (key_idx == -1) { |
8c66e185 | 2808 | key_idx = 0; |
dc01de8a JM |
2809 | tdls = 1; |
2810 | } | |
8c66e185 | 2811 | #endif /* CONFIG_TDLS */ |
3f5285e8 | 2812 | |
b658547d | 2813 | #ifdef CONFIG_DRIVER_NL80211_QCA |
15badebd CL |
2814 | if (alg == WPA_ALG_PMK && |
2815 | (drv->capa.flags & WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD)) { | |
b41f2684 CL |
2816 | wpa_printf(MSG_DEBUG, "%s: calling issue_key_mgmt_set_key", |
2817 | __func__); | |
2818 | ret = issue_key_mgmt_set_key(drv, key, key_len); | |
2819 | return ret; | |
2820 | } | |
b658547d | 2821 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
b41f2684 | 2822 | |
3f5285e8 | 2823 | if (alg == WPA_ALG_NONE) { |
95376e1a JM |
2824 | msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_DEL_KEY); |
2825 | if (!msg) | |
2826 | return -ENOBUFS; | |
3f5285e8 | 2827 | } else { |
34651767 JM |
2828 | u32 suite; |
2829 | ||
2830 | suite = wpa_alg_to_cipher_suite(alg, key_len); | |
2831 | if (!suite) | |
2832 | goto fail; | |
95376e1a JM |
2833 | msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_NEW_KEY); |
2834 | if (!msg || | |
a862e4a3 | 2835 | nla_put(msg, NL80211_ATTR_KEY_DATA, key_len, key) || |
34651767 | 2836 | nla_put_u32(msg, NL80211_ATTR_KEY_CIPHER, suite)) |
a862e4a3 | 2837 | goto fail; |
e6ef73f1 | 2838 | wpa_hexdump_key(MSG_DEBUG, "nl80211: KEY_DATA", key, key_len); |
3f5285e8 JM |
2839 | } |
2840 | ||
e6ef73f1 | 2841 | if (seq && seq_len) { |
a862e4a3 JM |
2842 | if (nla_put(msg, NL80211_ATTR_KEY_SEQ, seq_len, seq)) |
2843 | goto fail; | |
e6ef73f1 JM |
2844 | wpa_hexdump(MSG_DEBUG, "nl80211: KEY_SEQ", seq, seq_len); |
2845 | } | |
1ad1cdc2 | 2846 | |
0382097e | 2847 | if (addr && !is_broadcast_ether_addr(addr)) { |
3f5285e8 | 2848 | wpa_printf(MSG_DEBUG, " addr=" MACSTR, MAC2STR(addr)); |
a862e4a3 JM |
2849 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
2850 | goto fail; | |
89c38e32 JM |
2851 | |
2852 | if (alg != WPA_ALG_WEP && key_idx && !set_tx) { | |
2853 | wpa_printf(MSG_DEBUG, " RSN IBSS RX GTK"); | |
a862e4a3 JM |
2854 | if (nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, |
2855 | NL80211_KEYTYPE_GROUP)) | |
2856 | goto fail; | |
89c38e32 | 2857 | } |
60ea8187 | 2858 | } else if (addr && is_broadcast_ether_addr(addr)) { |
8970bae8 JB |
2859 | struct nlattr *types; |
2860 | ||
60ea8187 | 2861 | wpa_printf(MSG_DEBUG, " broadcast key"); |
8970bae8 JB |
2862 | |
2863 | types = nla_nest_start(msg, NL80211_ATTR_KEY_DEFAULT_TYPES); | |
a862e4a3 JM |
2864 | if (!types || |
2865 | nla_put_flag(msg, NL80211_KEY_DEFAULT_TYPE_MULTICAST)) | |
2866 | goto fail; | |
8970bae8 | 2867 | nla_nest_end(msg, types); |
3f5285e8 | 2868 | } |
95376e1a | 2869 | if (nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) |
a862e4a3 | 2870 | goto fail; |
3f5285e8 | 2871 | |
bbd89bfc | 2872 | ret = send_and_recv_msgs(drv, msg, NULL, key ? (void *) -1 : NULL); |
15664ad0 | 2873 | if ((ret == -ENOENT || ret == -ENOLINK) && alg == WPA_ALG_NONE) |
1ad1cdc2 JM |
2874 | ret = 0; |
2875 | if (ret) | |
2876 | wpa_printf(MSG_DEBUG, "nl80211: set_key failed; err=%d %s)", | |
2877 | ret, strerror(-ret)); | |
3f5285e8 | 2878 | |
1ad1cdc2 JM |
2879 | /* |
2880 | * If we failed or don't need to set the default TX key (below), | |
2881 | * we're done here. | |
2882 | */ | |
dc01de8a | 2883 | if (ret || !set_tx || alg == WPA_ALG_NONE || tdls) |
1ad1cdc2 | 2884 | return ret; |
b1f625e0 | 2885 | if (is_ap_interface(drv->nlmode) && addr && |
0382097e | 2886 | !is_broadcast_ether_addr(addr)) |
de12717a | 2887 | return ret; |
3f5285e8 | 2888 | |
95376e1a JM |
2889 | msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_SET_KEY); |
2890 | if (!msg || | |
a862e4a3 | 2891 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx) || |
86f9b1c7 JM |
2892 | nla_put_flag(msg, (alg == WPA_ALG_IGTK || |
2893 | alg == WPA_ALG_BIP_GMAC_128 || | |
2894 | alg == WPA_ALG_BIP_GMAC_256 || | |
2895 | alg == WPA_ALG_BIP_CMAC_256) ? | |
a862e4a3 JM |
2896 | NL80211_ATTR_KEY_DEFAULT_MGMT : |
2897 | NL80211_ATTR_KEY_DEFAULT)) | |
2898 | goto fail; | |
60ea8187 | 2899 | if (addr && is_broadcast_ether_addr(addr)) { |
8970bae8 JB |
2900 | struct nlattr *types; |
2901 | ||
2902 | types = nla_nest_start(msg, NL80211_ATTR_KEY_DEFAULT_TYPES); | |
a862e4a3 JM |
2903 | if (!types || |
2904 | nla_put_flag(msg, NL80211_KEY_DEFAULT_TYPE_MULTICAST)) | |
2905 | goto fail; | |
8970bae8 | 2906 | nla_nest_end(msg, types); |
60ea8187 | 2907 | } else if (addr) { |
8970bae8 JB |
2908 | struct nlattr *types; |
2909 | ||
2910 | types = nla_nest_start(msg, NL80211_ATTR_KEY_DEFAULT_TYPES); | |
a862e4a3 JM |
2911 | if (!types || |
2912 | nla_put_flag(msg, NL80211_KEY_DEFAULT_TYPE_UNICAST)) | |
2913 | goto fail; | |
8970bae8 | 2914 | nla_nest_end(msg, types); |
60ea8187 | 2915 | } |
3f5285e8 | 2916 | |
1ad1cdc2 JM |
2917 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
2918 | if (ret == -ENOENT) | |
2919 | ret = 0; | |
2920 | if (ret) | |
2921 | wpa_printf(MSG_DEBUG, "nl80211: set_key default failed; " | |
2922 | "err=%d %s)", ret, strerror(-ret)); | |
2923 | return ret; | |
3f5285e8 | 2924 | |
a862e4a3 | 2925 | fail: |
bbd89bfc | 2926 | nl80211_nlmsg_clear(msg); |
5883168a | 2927 | nlmsg_free(msg); |
6241fcb1 | 2928 | return -ENOBUFS; |
3f5285e8 JM |
2929 | } |
2930 | ||
2931 | ||
71934751 | 2932 | static int nl_add_key(struct nl_msg *msg, enum wpa_alg alg, |
0194fedb JB |
2933 | int key_idx, int defkey, |
2934 | const u8 *seq, size_t seq_len, | |
2935 | const u8 *key, size_t key_len) | |
2936 | { | |
2937 | struct nlattr *key_attr = nla_nest_start(msg, NL80211_ATTR_KEY); | |
34651767 JM |
2938 | u32 suite; |
2939 | ||
0194fedb JB |
2940 | if (!key_attr) |
2941 | return -1; | |
2942 | ||
34651767 JM |
2943 | suite = wpa_alg_to_cipher_suite(alg, key_len); |
2944 | if (!suite) | |
2945 | return -1; | |
2946 | ||
a862e4a3 JM |
2947 | if (defkey && alg == WPA_ALG_IGTK) { |
2948 | if (nla_put_flag(msg, NL80211_KEY_DEFAULT_MGMT)) | |
2949 | return -1; | |
2950 | } else if (defkey) { | |
2951 | if (nla_put_flag(msg, NL80211_KEY_DEFAULT)) | |
2952 | return -1; | |
2953 | } | |
0194fedb | 2954 | |
a862e4a3 | 2955 | if (nla_put_u8(msg, NL80211_KEY_IDX, key_idx) || |
34651767 | 2956 | nla_put_u32(msg, NL80211_KEY_CIPHER, suite) || |
a862e4a3 JM |
2957 | (seq && seq_len && |
2958 | nla_put(msg, NL80211_KEY_SEQ, seq_len, seq)) || | |
2959 | nla_put(msg, NL80211_KEY_DATA, key_len, key)) | |
2960 | return -1; | |
0194fedb JB |
2961 | |
2962 | nla_nest_end(msg, key_attr); | |
2963 | ||
2964 | return 0; | |
0194fedb JB |
2965 | } |
2966 | ||
c811d5bc | 2967 | |
cfaab580 ZY |
2968 | static int nl80211_set_conn_keys(struct wpa_driver_associate_params *params, |
2969 | struct nl_msg *msg) | |
2970 | { | |
2971 | int i, privacy = 0; | |
2972 | struct nlattr *nl_keys, *nl_key; | |
2973 | ||
2974 | for (i = 0; i < 4; i++) { | |
2975 | if (!params->wep_key[i]) | |
2976 | continue; | |
2977 | privacy = 1; | |
2978 | break; | |
2979 | } | |
ce04af5a JM |
2980 | if (params->wps == WPS_MODE_PRIVACY) |
2981 | privacy = 1; | |
2982 | if (params->pairwise_suite && | |
2983 | params->pairwise_suite != WPA_CIPHER_NONE) | |
2984 | privacy = 1; | |
2985 | ||
cfaab580 ZY |
2986 | if (!privacy) |
2987 | return 0; | |
2988 | ||
a862e4a3 JM |
2989 | if (nla_put_flag(msg, NL80211_ATTR_PRIVACY)) |
2990 | return -ENOBUFS; | |
cfaab580 ZY |
2991 | |
2992 | nl_keys = nla_nest_start(msg, NL80211_ATTR_KEYS); | |
2993 | if (!nl_keys) | |
a862e4a3 | 2994 | return -ENOBUFS; |
cfaab580 ZY |
2995 | |
2996 | for (i = 0; i < 4; i++) { | |
2997 | if (!params->wep_key[i]) | |
2998 | continue; | |
2999 | ||
3000 | nl_key = nla_nest_start(msg, i); | |
a862e4a3 JM |
3001 | if (!nl_key || |
3002 | nla_put(msg, NL80211_KEY_DATA, params->wep_key_len[i], | |
3003 | params->wep_key[i]) || | |
3004 | nla_put_u32(msg, NL80211_KEY_CIPHER, | |
3005 | params->wep_key_len[i] == 5 ? | |
a042e39a JM |
3006 | RSN_CIPHER_SUITE_WEP40 : |
3007 | RSN_CIPHER_SUITE_WEP104) || | |
a862e4a3 JM |
3008 | nla_put_u8(msg, NL80211_KEY_IDX, i) || |
3009 | (i == params->wep_tx_keyidx && | |
3010 | nla_put_flag(msg, NL80211_KEY_DEFAULT))) | |
3011 | return -ENOBUFS; | |
cfaab580 ZY |
3012 | |
3013 | nla_nest_end(msg, nl_key); | |
3014 | } | |
3015 | nla_nest_end(msg, nl_keys); | |
3016 | ||
3017 | return 0; | |
cfaab580 ZY |
3018 | } |
3019 | ||
3020 | ||
477af8f8 JM |
3021 | int wpa_driver_nl80211_mlme(struct wpa_driver_nl80211_data *drv, |
3022 | const u8 *addr, int cmd, u16 reason_code, | |
3023 | int local_state_change) | |
c2a04078 | 3024 | { |
a862e4a3 | 3025 | int ret; |
c2a04078 JM |
3026 | struct nl_msg *msg; |
3027 | ||
9725b784 | 3028 | if (!(msg = nl80211_drv_msg(drv, 0, cmd)) || |
a862e4a3 JM |
3029 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code) || |
3030 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || | |
3031 | (local_state_change && | |
3032 | nla_put_flag(msg, NL80211_ATTR_LOCAL_STATE_CHANGE))) { | |
3033 | nlmsg_free(msg); | |
3034 | return -1; | |
3035 | } | |
c2a04078 JM |
3036 | |
3037 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
c2a04078 | 3038 | if (ret) { |
3b7ea880 BG |
3039 | wpa_dbg(drv->ctx, MSG_DEBUG, |
3040 | "nl80211: MLME command failed: reason=%u ret=%d (%s)", | |
3041 | reason_code, ret, strerror(-ret)); | |
c2a04078 | 3042 | } |
c2a04078 JM |
3043 | return ret; |
3044 | } | |
3f5285e8 JM |
3045 | |
3046 | ||
cfaab580 | 3047 | static int wpa_driver_nl80211_disconnect(struct wpa_driver_nl80211_data *drv, |
817762d9 | 3048 | int reason_code) |
cfaab580 | 3049 | { |
3f53c006 JJ |
3050 | int ret; |
3051 | ||
817762d9 | 3052 | wpa_printf(MSG_DEBUG, "%s(reason_code=%d)", __func__, reason_code); |
add9b7a4 | 3053 | nl80211_mark_disconnected(drv); |
817762d9 | 3054 | /* Disconnect command doesn't need BSSID - it uses cached value */ |
3f53c006 JJ |
3055 | ret = wpa_driver_nl80211_mlme(drv, NULL, NL80211_CMD_DISCONNECT, |
3056 | reason_code, 0); | |
3057 | /* | |
3058 | * For locally generated disconnect, supplicant already generates a | |
3059 | * DEAUTH event, so ignore the event from NL80211. | |
3060 | */ | |
3061 | drv->ignore_next_local_disconnect = ret == 0; | |
3062 | ||
3063 | return ret; | |
cfaab580 ZY |
3064 | } |
3065 | ||
3066 | ||
9ebce9c5 JM |
3067 | static int wpa_driver_nl80211_deauthenticate(struct i802_bss *bss, |
3068 | const u8 *addr, int reason_code) | |
3f5285e8 | 3069 | { |
a2e40bb6 | 3070 | struct wpa_driver_nl80211_data *drv = bss->drv; |
d6a36f39 | 3071 | int ret; |
9392c9be AS |
3072 | |
3073 | if (drv->nlmode == NL80211_IFTYPE_ADHOC) { | |
3074 | nl80211_mark_disconnected(drv); | |
666e508c | 3075 | return nl80211_leave_ibss(drv, 1); |
9392c9be | 3076 | } |
cfaab580 | 3077 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) |
817762d9 | 3078 | return wpa_driver_nl80211_disconnect(drv, reason_code); |
2e75a2b3 JM |
3079 | wpa_printf(MSG_DEBUG, "%s(addr=" MACSTR " reason_code=%d)", |
3080 | __func__, MAC2STR(addr), reason_code); | |
add9b7a4 | 3081 | nl80211_mark_disconnected(drv); |
d6a36f39 JM |
3082 | ret = wpa_driver_nl80211_mlme(drv, addr, NL80211_CMD_DEAUTHENTICATE, |
3083 | reason_code, 0); | |
3084 | /* | |
3085 | * For locally generated deauthenticate, supplicant already generates a | |
3086 | * DEAUTH event, so ignore the event from NL80211. | |
3087 | */ | |
3088 | drv->ignore_next_local_deauth = ret == 0; | |
3089 | return ret; | |
3f5285e8 JM |
3090 | } |
3091 | ||
3092 | ||
536fd62d JM |
3093 | static void nl80211_copy_auth_params(struct wpa_driver_nl80211_data *drv, |
3094 | struct wpa_driver_auth_params *params) | |
3095 | { | |
3096 | int i; | |
3097 | ||
3098 | drv->auth_freq = params->freq; | |
3099 | drv->auth_alg = params->auth_alg; | |
3100 | drv->auth_wep_tx_keyidx = params->wep_tx_keyidx; | |
3101 | drv->auth_local_state_change = params->local_state_change; | |
3102 | drv->auth_p2p = params->p2p; | |
3103 | ||
3104 | if (params->bssid) | |
3105 | os_memcpy(drv->auth_bssid_, params->bssid, ETH_ALEN); | |
3106 | else | |
3107 | os_memset(drv->auth_bssid_, 0, ETH_ALEN); | |
3108 | ||
3109 | if (params->ssid) { | |
3110 | os_memcpy(drv->auth_ssid, params->ssid, params->ssid_len); | |
3111 | drv->auth_ssid_len = params->ssid_len; | |
3112 | } else | |
3113 | drv->auth_ssid_len = 0; | |
3114 | ||
3115 | ||
3116 | os_free(drv->auth_ie); | |
3117 | drv->auth_ie = NULL; | |
3118 | drv->auth_ie_len = 0; | |
3119 | if (params->ie) { | |
3120 | drv->auth_ie = os_malloc(params->ie_len); | |
3121 | if (drv->auth_ie) { | |
3122 | os_memcpy(drv->auth_ie, params->ie, params->ie_len); | |
3123 | drv->auth_ie_len = params->ie_len; | |
3124 | } | |
3125 | } | |
3126 | ||
3127 | for (i = 0; i < 4; i++) { | |
3128 | if (params->wep_key[i] && params->wep_key_len[i] && | |
3129 | params->wep_key_len[i] <= 16) { | |
3130 | os_memcpy(drv->auth_wep_key[i], params->wep_key[i], | |
3131 | params->wep_key_len[i]); | |
3132 | drv->auth_wep_key_len[i] = params->wep_key_len[i]; | |
3133 | } else | |
3134 | drv->auth_wep_key_len[i] = 0; | |
3135 | } | |
3136 | } | |
3137 | ||
3138 | ||
4bd71954 JM |
3139 | static void nl80211_unmask_11b_rates(struct i802_bss *bss) |
3140 | { | |
3141 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
3142 | ||
3143 | if (is_p2p_net_interface(drv->nlmode) || !drv->disabled_11b_rates) | |
3144 | return; | |
3145 | ||
3146 | /* | |
3147 | * Looks like we failed to unmask 11b rates previously. This could | |
3148 | * happen, e.g., if the interface was down at the point in time when a | |
3149 | * P2P group was terminated. | |
3150 | */ | |
3151 | wpa_printf(MSG_DEBUG, | |
3152 | "nl80211: Interface %s mode is for non-P2P, but 11b rates were disabled - re-enable them", | |
3153 | bss->ifname); | |
3154 | nl80211_disable_11b_rates(drv, drv->ifindex, 0); | |
3155 | } | |
3156 | ||
3157 | ||
3c67e977 VK |
3158 | static enum nl80211_auth_type get_nl_auth_type(int wpa_auth_alg) |
3159 | { | |
3160 | if (wpa_auth_alg & WPA_AUTH_ALG_OPEN) | |
3161 | return NL80211_AUTHTYPE_OPEN_SYSTEM; | |
3162 | if (wpa_auth_alg & WPA_AUTH_ALG_SHARED) | |
3163 | return NL80211_AUTHTYPE_SHARED_KEY; | |
3164 | if (wpa_auth_alg & WPA_AUTH_ALG_LEAP) | |
3165 | return NL80211_AUTHTYPE_NETWORK_EAP; | |
3166 | if (wpa_auth_alg & WPA_AUTH_ALG_FT) | |
3167 | return NL80211_AUTHTYPE_FT; | |
3168 | if (wpa_auth_alg & WPA_AUTH_ALG_SAE) | |
3169 | return NL80211_AUTHTYPE_SAE; | |
3170 | if (wpa_auth_alg & WPA_AUTH_ALG_FILS) | |
3171 | return NL80211_AUTHTYPE_FILS_SK; | |
3172 | if (wpa_auth_alg & WPA_AUTH_ALG_FILS_SK_PFS) | |
3173 | return NL80211_AUTHTYPE_FILS_SK_PFS; | |
3174 | ||
3175 | return NL80211_AUTHTYPE_MAX; | |
3176 | } | |
3177 | ||
3178 | ||
c2a04078 | 3179 | static int wpa_driver_nl80211_authenticate( |
9ebce9c5 | 3180 | struct i802_bss *bss, struct wpa_driver_auth_params *params) |
c2a04078 | 3181 | { |
a2e40bb6 | 3182 | struct wpa_driver_nl80211_data *drv = bss->drv; |
a0b2f99b | 3183 | int ret = -1, i; |
c2a04078 JM |
3184 | struct nl_msg *msg; |
3185 | enum nl80211_auth_type type; | |
2f4f73b1 | 3186 | enum nl80211_iftype nlmode; |
6d6f4bb8 | 3187 | int count = 0; |
536fd62d JM |
3188 | int is_retry; |
3189 | ||
4bd71954 JM |
3190 | nl80211_unmask_11b_rates(bss); |
3191 | ||
536fd62d JM |
3192 | is_retry = drv->retry_auth; |
3193 | drv->retry_auth = 0; | |
e8d70a73 | 3194 | drv->ignore_deauth_event = 0; |
c2a04078 | 3195 | |
add9b7a4 | 3196 | nl80211_mark_disconnected(drv); |
e6b8efeb | 3197 | os_memset(drv->auth_bssid, 0, ETH_ALEN); |
add9b7a4 JM |
3198 | if (params->bssid) |
3199 | os_memcpy(drv->auth_attempt_bssid, params->bssid, ETH_ALEN); | |
3200 | else | |
3201 | os_memset(drv->auth_attempt_bssid, 0, ETH_ALEN); | |
af473088 | 3202 | /* FIX: IBSS mode */ |
2f4f73b1 EP |
3203 | nlmode = params->p2p ? |
3204 | NL80211_IFTYPE_P2P_CLIENT : NL80211_IFTYPE_STATION; | |
3205 | if (drv->nlmode != nlmode && | |
9ebce9c5 | 3206 | wpa_driver_nl80211_set_mode(bss, nlmode) < 0) |
4a867032 JM |
3207 | return -1; |
3208 | ||
6d6f4bb8 | 3209 | retry: |
c2a04078 JM |
3210 | wpa_printf(MSG_DEBUG, "nl80211: Authenticate (ifindex=%d)", |
3211 | drv->ifindex); | |
a0b2f99b | 3212 | |
9725b784 JM |
3213 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_AUTHENTICATE); |
3214 | if (!msg) | |
3215 | goto fail; | |
0194fedb | 3216 | |
a0b2f99b JM |
3217 | for (i = 0; i < 4; i++) { |
3218 | if (!params->wep_key[i]) | |
3219 | continue; | |
9ebce9c5 | 3220 | wpa_driver_nl80211_set_key(bss->ifname, bss, WPA_ALG_WEP, |
2ea2fcc7 | 3221 | NULL, i, |
a0b2f99b JM |
3222 | i == params->wep_tx_keyidx, NULL, 0, |
3223 | params->wep_key[i], | |
3224 | params->wep_key_len[i]); | |
0194fedb JB |
3225 | if (params->wep_tx_keyidx != i) |
3226 | continue; | |
3227 | if (nl_add_key(msg, WPA_ALG_WEP, i, 1, NULL, 0, | |
9725b784 JM |
3228 | params->wep_key[i], params->wep_key_len[i])) |
3229 | goto fail; | |
a0b2f99b JM |
3230 | } |
3231 | ||
c2a04078 JM |
3232 | if (params->bssid) { |
3233 | wpa_printf(MSG_DEBUG, " * bssid=" MACSTR, | |
3234 | MAC2STR(params->bssid)); | |
a862e4a3 JM |
3235 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid)) |
3236 | goto fail; | |
c2a04078 JM |
3237 | } |
3238 | if (params->freq) { | |
3239 | wpa_printf(MSG_DEBUG, " * freq=%d", params->freq); | |
a862e4a3 JM |
3240 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, params->freq)) |
3241 | goto fail; | |
c2a04078 JM |
3242 | } |
3243 | if (params->ssid) { | |
3244 | wpa_hexdump_ascii(MSG_DEBUG, " * SSID", | |
3245 | params->ssid, params->ssid_len); | |
a862e4a3 JM |
3246 | if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, |
3247 | params->ssid)) | |
3248 | goto fail; | |
c2a04078 JM |
3249 | } |
3250 | wpa_hexdump(MSG_DEBUG, " * IEs", params->ie, params->ie_len); | |
a862e4a3 JM |
3251 | if (params->ie && |
3252 | nla_put(msg, NL80211_ATTR_IE, params->ie_len, params->ie)) | |
3253 | goto fail; | |
ce16c489 JM |
3254 | if (params->auth_data) { |
3255 | wpa_hexdump(MSG_DEBUG, " * auth_data", params->auth_data, | |
3256 | params->auth_data_len); | |
3257 | if (nla_put(msg, NL80211_ATTR_SAE_DATA, params->auth_data_len, | |
3258 | params->auth_data)) | |
a862e4a3 | 3259 | goto fail; |
569fed90 | 3260 | } |
3c67e977 | 3261 | type = get_nl_auth_type(params->auth_alg); |
c2a04078 | 3262 | wpa_printf(MSG_DEBUG, " * Auth Type %d", type); |
3c67e977 VK |
3263 | if (type == NL80211_AUTHTYPE_MAX || |
3264 | nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, type)) | |
a862e4a3 | 3265 | goto fail; |
77339912 JM |
3266 | if (params->local_state_change) { |
3267 | wpa_printf(MSG_DEBUG, " * Local state change only"); | |
a862e4a3 JM |
3268 | if (nla_put_flag(msg, NL80211_ATTR_LOCAL_STATE_CHANGE)) |
3269 | goto fail; | |
77339912 | 3270 | } |
c2a04078 JM |
3271 | |
3272 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
3273 | msg = NULL; | |
3274 | if (ret) { | |
3b7ea880 BG |
3275 | wpa_dbg(drv->ctx, MSG_DEBUG, |
3276 | "nl80211: MLME command failed (auth): ret=%d (%s)", | |
3277 | ret, strerror(-ret)); | |
6d6f4bb8 | 3278 | count++; |
77339912 JM |
3279 | if (ret == -EALREADY && count == 1 && params->bssid && |
3280 | !params->local_state_change) { | |
6d6f4bb8 JM |
3281 | /* |
3282 | * mac80211 does not currently accept new | |
3283 | * authentication if we are already authenticated. As a | |
3284 | * workaround, force deauthentication and try again. | |
3285 | */ | |
3286 | wpa_printf(MSG_DEBUG, "nl80211: Retry authentication " | |
3287 | "after forced deauthentication"); | |
e8d70a73 | 3288 | drv->ignore_deauth_event = 1; |
6d6f4bb8 | 3289 | wpa_driver_nl80211_deauthenticate( |
5205c4f9 | 3290 | bss, params->bssid, |
6d6f4bb8 JM |
3291 | WLAN_REASON_PREV_AUTH_NOT_VALID); |
3292 | nlmsg_free(msg); | |
3293 | goto retry; | |
3294 | } | |
536fd62d JM |
3295 | |
3296 | if (ret == -ENOENT && params->freq && !is_retry) { | |
3297 | /* | |
3298 | * cfg80211 has likely expired the BSS entry even | |
3299 | * though it was previously available in our internal | |
3300 | * BSS table. To recover quickly, start a single | |
3301 | * channel scan on the specified channel. | |
3302 | */ | |
3303 | struct wpa_driver_scan_params scan; | |
3304 | int freqs[2]; | |
3305 | ||
3306 | os_memset(&scan, 0, sizeof(scan)); | |
3307 | scan.num_ssids = 1; | |
3308 | if (params->ssid) { | |
3309 | scan.ssids[0].ssid = params->ssid; | |
3310 | scan.ssids[0].ssid_len = params->ssid_len; | |
3311 | } | |
3312 | freqs[0] = params->freq; | |
3313 | freqs[1] = 0; | |
3314 | scan.freqs = freqs; | |
3315 | wpa_printf(MSG_DEBUG, "nl80211: Trigger single " | |
3316 | "channel scan to refresh cfg80211 BSS " | |
3317 | "entry"); | |
3318 | ret = wpa_driver_nl80211_scan(bss, &scan); | |
3319 | if (ret == 0) { | |
3320 | nl80211_copy_auth_params(drv, params); | |
3321 | drv->scan_for_auth = 1; | |
3322 | } | |
8c3ba078 JM |
3323 | } else if (is_retry) { |
3324 | /* | |
3325 | * Need to indicate this with an event since the return | |
3326 | * value from the retry is not delivered to core code. | |
3327 | */ | |
3328 | union wpa_event_data event; | |
3329 | wpa_printf(MSG_DEBUG, "nl80211: Authentication retry " | |
3330 | "failed"); | |
3331 | os_memset(&event, 0, sizeof(event)); | |
3332 | os_memcpy(event.timeout_event.addr, drv->auth_bssid_, | |
3333 | ETH_ALEN); | |
3334 | wpa_supplicant_event(drv->ctx, EVENT_AUTH_TIMED_OUT, | |
3335 | &event); | |
536fd62d | 3336 | } |
a862e4a3 JM |
3337 | } else { |
3338 | wpa_printf(MSG_DEBUG, | |
3339 | "nl80211: Authentication request send successfully"); | |
c2a04078 | 3340 | } |
c2a04078 | 3341 | |
a862e4a3 | 3342 | fail: |
c2a04078 JM |
3343 | nlmsg_free(msg); |
3344 | return ret; | |
3345 | } | |
3346 | ||
3347 | ||
f3407c66 | 3348 | int wpa_driver_nl80211_authenticate_retry(struct wpa_driver_nl80211_data *drv) |
536fd62d JM |
3349 | { |
3350 | struct wpa_driver_auth_params params; | |
834ee56f | 3351 | struct i802_bss *bss = drv->first_bss; |
536fd62d JM |
3352 | int i; |
3353 | ||
3354 | wpa_printf(MSG_DEBUG, "nl80211: Try to authenticate again"); | |
3355 | ||
3356 | os_memset(¶ms, 0, sizeof(params)); | |
3357 | params.freq = drv->auth_freq; | |
3358 | params.auth_alg = drv->auth_alg; | |
3359 | params.wep_tx_keyidx = drv->auth_wep_tx_keyidx; | |
3360 | params.local_state_change = drv->auth_local_state_change; | |
3361 | params.p2p = drv->auth_p2p; | |
3362 | ||
3363 | if (!is_zero_ether_addr(drv->auth_bssid_)) | |
3364 | params.bssid = drv->auth_bssid_; | |
3365 | ||
3366 | if (drv->auth_ssid_len) { | |
3367 | params.ssid = drv->auth_ssid; | |
3368 | params.ssid_len = drv->auth_ssid_len; | |
3369 | } | |
3370 | ||
3371 | params.ie = drv->auth_ie; | |
3372 | params.ie_len = drv->auth_ie_len; | |
3373 | ||
3374 | for (i = 0; i < 4; i++) { | |
3375 | if (drv->auth_wep_key_len[i]) { | |
3376 | params.wep_key[i] = drv->auth_wep_key[i]; | |
3377 | params.wep_key_len[i] = drv->auth_wep_key_len[i]; | |
3378 | } | |
3379 | } | |
3380 | ||
3381 | drv->retry_auth = 1; | |
3382 | return wpa_driver_nl80211_authenticate(bss, ¶ms); | |
3383 | } | |
3384 | ||
3385 | ||
a11241fa JB |
3386 | static int wpa_driver_nl80211_send_frame(struct i802_bss *bss, |
3387 | const void *data, size_t len, | |
55231068 JM |
3388 | int encrypt, int noack, |
3389 | unsigned int freq, int no_cck, | |
2d3943ce AO |
3390 | int offchanok, unsigned int wait_time, |
3391 | const u16 *csa_offs, | |
3392 | size_t csa_offs_len) | |
a11241fa JB |
3393 | { |
3394 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
3395 | u64 cookie; | |
41cc50d1 | 3396 | int res; |
a11241fa | 3397 | |
c7caac56 JM |
3398 | if (freq == 0 && drv->nlmode == NL80211_IFTYPE_ADHOC) { |
3399 | freq = nl80211_get_assoc_freq(drv); | |
3400 | wpa_printf(MSG_DEBUG, | |
3401 | "nl80211: send_frame - Use assoc_freq=%u for IBSS", | |
3402 | freq); | |
3403 | } | |
af964484 JM |
3404 | if (freq == 0) { |
3405 | wpa_printf(MSG_DEBUG, "nl80211: send_frame - Use bss->freq=%u", | |
3406 | bss->freq); | |
55231068 | 3407 | freq = bss->freq; |
af964484 | 3408 | } |
55231068 | 3409 | |
739faee2 | 3410 | if (drv->use_monitor) { |
981cf85a | 3411 | wpa_printf(MSG_DEBUG, "nl80211: send_frame(freq=%u bss->freq=%u) -> send_monitor", |
739faee2 | 3412 | freq, bss->freq); |
981cf85a | 3413 | return nl80211_send_monitor(drv, data, len, encrypt, noack); |
739faee2 | 3414 | } |
a11241fa | 3415 | |
739faee2 | 3416 | wpa_printf(MSG_DEBUG, "nl80211: send_frame -> send_frame_cmd"); |
41cc50d1 | 3417 | res = nl80211_send_frame_cmd(bss, freq, wait_time, data, len, |
2d3943ce AO |
3418 | &cookie, no_cck, noack, offchanok, |
3419 | csa_offs, csa_offs_len); | |
41cc50d1 JM |
3420 | if (res == 0 && !noack) { |
3421 | const struct ieee80211_mgmt *mgmt; | |
3422 | u16 fc; | |
3423 | ||
3424 | mgmt = (const struct ieee80211_mgmt *) data; | |
3425 | fc = le_to_host16(mgmt->frame_control); | |
3426 | if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && | |
3427 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_ACTION) { | |
3428 | wpa_printf(MSG_MSGDUMP, | |
3429 | "nl80211: Update send_action_cookie from 0x%llx to 0x%llx", | |
3430 | (long long unsigned int) | |
3431 | drv->send_action_cookie, | |
3432 | (long long unsigned int) cookie); | |
3433 | drv->send_action_cookie = cookie; | |
3434 | } | |
3435 | } | |
3436 | ||
3437 | return res; | |
a11241fa JB |
3438 | } |
3439 | ||
3440 | ||
9ebce9c5 JM |
3441 | static int wpa_driver_nl80211_send_mlme(struct i802_bss *bss, const u8 *data, |
3442 | size_t data_len, int noack, | |
3443 | unsigned int freq, int no_cck, | |
3444 | int offchanok, | |
2d3943ce AO |
3445 | unsigned int wait_time, |
3446 | const u16 *csa_offs, | |
3447 | size_t csa_offs_len) | |
2c2010ac | 3448 | { |
a2e40bb6 | 3449 | struct wpa_driver_nl80211_data *drv = bss->drv; |
2c2010ac | 3450 | struct ieee80211_mgmt *mgmt; |
7a47d567 | 3451 | int encrypt = 1; |
2c2010ac JM |
3452 | u16 fc; |
3453 | ||
3454 | mgmt = (struct ieee80211_mgmt *) data; | |
3455 | fc = le_to_host16(mgmt->frame_control); | |
f95a4524 PF |
3456 | wpa_printf(MSG_DEBUG, "nl80211: send_mlme - da= " MACSTR |
3457 | " noack=%d freq=%u no_cck=%d offchanok=%d wait_time=%u fc=0x%x (%s) nlmode=%d", | |
3458 | MAC2STR(mgmt->da), noack, freq, no_cck, offchanok, wait_time, | |
3459 | fc, fc2str(fc), drv->nlmode); | |
2c2010ac | 3460 | |
8e12685c AS |
3461 | if ((is_sta_interface(drv->nlmode) || |
3462 | drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) && | |
5582a5d1 JB |
3463 | WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && |
3464 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_PROBE_RESP) { | |
3465 | /* | |
3466 | * The use of last_mgmt_freq is a bit of a hack, | |
3467 | * but it works due to the single-threaded nature | |
3468 | * of wpa_supplicant. | |
3469 | */ | |
af964484 JM |
3470 | if (freq == 0) { |
3471 | wpa_printf(MSG_DEBUG, "nl80211: Use last_mgmt_freq=%d", | |
3472 | drv->last_mgmt_freq); | |
55231068 | 3473 | freq = drv->last_mgmt_freq; |
af964484 | 3474 | } |
55231068 | 3475 | return nl80211_send_frame_cmd(bss, freq, 0, |
88df0ef7 | 3476 | data, data_len, NULL, 1, noack, |
2d3943ce | 3477 | 1, csa_offs, csa_offs_len); |
5582a5d1 JB |
3478 | } |
3479 | ||
61cbe2ff | 3480 | if (drv->device_ap_sme && is_ap_interface(drv->nlmode)) { |
af964484 JM |
3481 | if (freq == 0) { |
3482 | wpa_printf(MSG_DEBUG, "nl80211: Use bss->freq=%d", | |
3483 | bss->freq); | |
55231068 | 3484 | freq = bss->freq; |
af964484 | 3485 | } |
b5671498 JM |
3486 | return nl80211_send_frame_cmd(bss, freq, |
3487 | (int) freq == bss->freq ? 0 : | |
3488 | wait_time, | |
d8d6b32e DG |
3489 | data, data_len, |
3490 | &drv->send_action_cookie, | |
2d3943ce AO |
3491 | no_cck, noack, offchanok, |
3492 | csa_offs, csa_offs_len); | |
86957e62 JM |
3493 | } |
3494 | ||
2c2010ac JM |
3495 | if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && |
3496 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_AUTH) { | |
3497 | /* | |
3498 | * Only one of the authentication frame types is encrypted. | |
3499 | * In order for static WEP encryption to work properly (i.e., | |
3500 | * to not encrypt the frame), we need to tell mac80211 about | |
3501 | * the frames that must not be encrypted. | |
3502 | */ | |
3503 | u16 auth_alg = le_to_host16(mgmt->u.auth.auth_alg); | |
3504 | u16 auth_trans = le_to_host16(mgmt->u.auth.auth_transaction); | |
7a47d567 JB |
3505 | if (auth_alg != WLAN_AUTH_SHARED_KEY || auth_trans != 3) |
3506 | encrypt = 0; | |
2c2010ac JM |
3507 | } |
3508 | ||
739faee2 | 3509 | wpa_printf(MSG_DEBUG, "nl80211: send_mlme -> send_frame"); |
a11241fa | 3510 | return wpa_driver_nl80211_send_frame(bss, data, data_len, encrypt, |
55231068 | 3511 | noack, freq, no_cck, offchanok, |
2d3943ce AO |
3512 | wait_time, csa_offs, |
3513 | csa_offs_len); | |
55231068 JM |
3514 | } |
3515 | ||
3516 | ||
cae87abd JM |
3517 | static int nl80211_put_basic_rates(struct nl_msg *msg, const int *basic_rates) |
3518 | { | |
3519 | u8 rates[NL80211_MAX_SUPP_RATES]; | |
3520 | u8 rates_len = 0; | |
3521 | int i; | |
3522 | ||
3523 | if (!basic_rates) | |
3524 | return 0; | |
3525 | ||
3526 | for (i = 0; i < NL80211_MAX_SUPP_RATES && basic_rates[i] >= 0; i++) | |
3527 | rates[rates_len++] = basic_rates[i] / 5; | |
3528 | ||
3529 | return nla_put(msg, NL80211_ATTR_BSS_BASIC_RATES, rates_len, rates); | |
3530 | } | |
3531 | ||
3532 | ||
31357268 | 3533 | static int nl80211_set_bss(struct i802_bss *bss, int cts, int preamble, |
e5693c47 | 3534 | int slot, int ht_opmode, int ap_isolate, |
cae87abd | 3535 | const int *basic_rates) |
31357268 JM |
3536 | { |
3537 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
3538 | struct nl_msg *msg; | |
3539 | ||
13f83980 | 3540 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_BSS)) || |
a862e4a3 JM |
3541 | (cts >= 0 && |
3542 | nla_put_u8(msg, NL80211_ATTR_BSS_CTS_PROT, cts)) || | |
3543 | (preamble >= 0 && | |
3544 | nla_put_u8(msg, NL80211_ATTR_BSS_SHORT_PREAMBLE, preamble)) || | |
3545 | (slot >= 0 && | |
3546 | nla_put_u8(msg, NL80211_ATTR_BSS_SHORT_SLOT_TIME, slot)) || | |
3547 | (ht_opmode >= 0 && | |
3548 | nla_put_u16(msg, NL80211_ATTR_BSS_HT_OPMODE, ht_opmode)) || | |
3549 | (ap_isolate >= 0 && | |
cae87abd JM |
3550 | nla_put_u8(msg, NL80211_ATTR_AP_ISOLATE, ap_isolate)) || |
3551 | nl80211_put_basic_rates(msg, basic_rates)) { | |
3552 | nlmsg_free(msg); | |
3553 | return -ENOBUFS; | |
e5693c47 JM |
3554 | } |
3555 | ||
31357268 | 3556 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
31357268 JM |
3557 | } |
3558 | ||
3559 | ||
3c4ca363 VN |
3560 | static int wpa_driver_nl80211_set_acl(void *priv, |
3561 | struct hostapd_acl_params *params) | |
3562 | { | |
3563 | struct i802_bss *bss = priv; | |
3564 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
3565 | struct nl_msg *msg; | |
f429ec44 | 3566 | struct nl_msg *acl; |
3c4ca363 | 3567 | unsigned int i; |
a862e4a3 | 3568 | int ret; |
3c4ca363 VN |
3569 | |
3570 | if (!(drv->capa.max_acl_mac_addrs)) | |
3571 | return -ENOTSUP; | |
3572 | ||
3573 | if (params->num_mac_acl > drv->capa.max_acl_mac_addrs) | |
3574 | return -ENOTSUP; | |
3575 | ||
3c4ca363 VN |
3576 | wpa_printf(MSG_DEBUG, "nl80211: Set %s ACL (num_mac_acl=%u)", |
3577 | params->acl_policy ? "Accept" : "Deny", params->num_mac_acl); | |
3578 | ||
f429ec44 JM |
3579 | acl = nlmsg_alloc(); |
3580 | if (!acl) | |
3581 | return -ENOMEM; | |
3582 | for (i = 0; i < params->num_mac_acl; i++) { | |
3583 | if (nla_put(acl, i + 1, ETH_ALEN, params->mac_acl[i].addr)) { | |
3584 | nlmsg_free(acl); | |
3585 | return -ENOMEM; | |
3586 | } | |
3587 | } | |
3588 | ||
9725b784 | 3589 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_MAC_ACL)) || |
a862e4a3 JM |
3590 | nla_put_u32(msg, NL80211_ATTR_ACL_POLICY, params->acl_policy ? |
3591 | NL80211_ACL_POLICY_DENY_UNLESS_LISTED : | |
3592 | NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED) || | |
f429ec44 | 3593 | nla_put_nested(msg, NL80211_ATTR_MAC_ADDRS, acl)) { |
a862e4a3 | 3594 | nlmsg_free(msg); |
f429ec44 | 3595 | nlmsg_free(acl); |
a862e4a3 JM |
3596 | return -ENOMEM; |
3597 | } | |
f429ec44 | 3598 | nlmsg_free(acl); |
3c4ca363 VN |
3599 | |
3600 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
3c4ca363 VN |
3601 | if (ret) { |
3602 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set MAC ACL: %d (%s)", | |
3603 | ret, strerror(-ret)); | |
3604 | } | |
3605 | ||
3c4ca363 VN |
3606 | return ret; |
3607 | } | |
3608 | ||
3609 | ||
85e1fad8 JM |
3610 | static int nl80211_put_beacon_int(struct nl_msg *msg, int beacon_int) |
3611 | { | |
3612 | if (beacon_int > 0) { | |
3613 | wpa_printf(MSG_DEBUG, " * beacon_int=%d", beacon_int); | |
3614 | return nla_put_u32(msg, NL80211_ATTR_BEACON_INTERVAL, | |
3615 | beacon_int); | |
3616 | } | |
3617 | ||
3618 | return 0; | |
3619 | } | |
3620 | ||
3621 | ||
4ac2ea57 MH |
3622 | static int nl80211_put_dtim_period(struct nl_msg *msg, int dtim_period) |
3623 | { | |
3624 | if (dtim_period > 0) { | |
3625 | wpa_printf(MSG_DEBUG, " * dtim_period=%d", dtim_period); | |
3626 | return nla_put_u32(msg, NL80211_ATTR_DTIM_PERIOD, dtim_period); | |
3627 | } | |
3628 | ||
3629 | return 0; | |
3630 | } | |
3631 | ||
3632 | ||
052b8d38 MH |
3633 | #ifdef CONFIG_MESH |
3634 | static int nl80211_set_mesh_config(void *priv, | |
3635 | struct wpa_driver_mesh_bss_params *params) | |
3636 | { | |
3637 | struct i802_bss *bss = priv; | |
3638 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
3639 | struct nl_msg *msg; | |
3640 | int ret; | |
3641 | ||
3642 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_MESH_CONFIG); | |
3643 | if (!msg) | |
3644 | return -1; | |
3645 | ||
3646 | ret = nl80211_put_mesh_config(msg, params); | |
3647 | if (ret < 0) { | |
3648 | nlmsg_free(msg); | |
3649 | return ret; | |
3650 | } | |
3651 | ||
3652 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
3653 | if (ret) { | |
3654 | wpa_printf(MSG_ERROR, | |
3655 | "nl80211: Mesh config set failed: %d (%s)", | |
3656 | ret, strerror(-ret)); | |
3657 | return ret; | |
3658 | } | |
3659 | return 0; | |
3660 | } | |
3661 | #endif /* CONFIG_MESH */ | |
3662 | ||
3663 | ||
d4f3003c PK |
3664 | static int nl80211_put_beacon_rate(struct nl_msg *msg, const u64 flags, |
3665 | struct wpa_driver_ap_params *params) | |
3666 | { | |
3667 | struct nlattr *bands, *band; | |
3668 | struct nl80211_txrate_vht vht_rate; | |
3669 | ||
3670 | if (!params->freq || | |
3671 | (params->beacon_rate == 0 && | |
3672 | params->rate_type == BEACON_RATE_LEGACY)) | |
3673 | return 0; | |
3674 | ||
3675 | bands = nla_nest_start(msg, NL80211_ATTR_TX_RATES); | |
3676 | if (!bands) | |
3677 | return -1; | |
3678 | ||
3679 | switch (params->freq->mode) { | |
3680 | case HOSTAPD_MODE_IEEE80211B: | |
3681 | case HOSTAPD_MODE_IEEE80211G: | |
3682 | band = nla_nest_start(msg, NL80211_BAND_2GHZ); | |
3683 | break; | |
3684 | case HOSTAPD_MODE_IEEE80211A: | |
3685 | band = nla_nest_start(msg, NL80211_BAND_5GHZ); | |
3686 | break; | |
3687 | case HOSTAPD_MODE_IEEE80211AD: | |
3688 | band = nla_nest_start(msg, NL80211_BAND_60GHZ); | |
3689 | break; | |
3690 | default: | |
3691 | return 0; | |
3692 | } | |
3693 | ||
3694 | if (!band) | |
3695 | return -1; | |
3696 | ||
3697 | os_memset(&vht_rate, 0, sizeof(vht_rate)); | |
3698 | ||
3699 | switch (params->rate_type) { | |
3700 | case BEACON_RATE_LEGACY: | |
3701 | if (!(flags & WPA_DRIVER_FLAGS_BEACON_RATE_LEGACY)) { | |
3702 | wpa_printf(MSG_INFO, | |
3703 | "nl80211: Driver does not support setting Beacon frame rate (legacy)"); | |
3704 | return -1; | |
3705 | } | |
3706 | ||
3707 | if (nla_put_u8(msg, NL80211_TXRATE_LEGACY, | |
3708 | (u8) params->beacon_rate / 5) || | |
3709 | nla_put(msg, NL80211_TXRATE_HT, 0, NULL) || | |
3710 | (params->freq->vht_enabled && | |
3711 | nla_put(msg, NL80211_TXRATE_VHT, sizeof(vht_rate), | |
3712 | &vht_rate))) | |
3713 | return -1; | |
3714 | ||
3715 | wpa_printf(MSG_DEBUG, " * beacon_rate = legacy:%u (* 100 kbps)", | |
3716 | params->beacon_rate); | |
3717 | break; | |
3718 | case BEACON_RATE_HT: | |
3719 | if (!(flags & WPA_DRIVER_FLAGS_BEACON_RATE_HT)) { | |
3720 | wpa_printf(MSG_INFO, | |
3721 | "nl80211: Driver does not support setting Beacon frame rate (HT)"); | |
3722 | return -1; | |
3723 | } | |
3724 | if (nla_put(msg, NL80211_TXRATE_LEGACY, 0, NULL) || | |
3725 | nla_put_u8(msg, NL80211_TXRATE_HT, params->beacon_rate) || | |
3726 | (params->freq->vht_enabled && | |
3727 | nla_put(msg, NL80211_TXRATE_VHT, sizeof(vht_rate), | |
3728 | &vht_rate))) | |
3729 | return -1; | |
3730 | wpa_printf(MSG_DEBUG, " * beacon_rate = HT-MCS %u", | |
3731 | params->beacon_rate); | |
3732 | break; | |
3733 | case BEACON_RATE_VHT: | |
3734 | if (!(flags & WPA_DRIVER_FLAGS_BEACON_RATE_VHT)) { | |
3735 | wpa_printf(MSG_INFO, | |
3736 | "nl80211: Driver does not support setting Beacon frame rate (VHT)"); | |
3737 | return -1; | |
3738 | } | |
3739 | vht_rate.mcs[0] = BIT(params->beacon_rate); | |
3740 | if (nla_put(msg, NL80211_TXRATE_LEGACY, 0, NULL)) | |
3741 | return -1; | |
3742 | if (nla_put(msg, NL80211_TXRATE_HT, 0, NULL)) | |
3743 | return -1; | |
3744 | if (nla_put(msg, NL80211_TXRATE_VHT, sizeof(vht_rate), | |
3745 | &vht_rate)) | |
3746 | return -1; | |
3747 | wpa_printf(MSG_DEBUG, " * beacon_rate = VHT-MCS %u", | |
3748 | params->beacon_rate); | |
3749 | break; | |
3750 | } | |
3751 | ||
3752 | nla_nest_end(msg, band); | |
3753 | nla_nest_end(msg, bands); | |
3754 | ||
3755 | return 0; | |
3756 | } | |
3757 | ||
3758 | ||
34f7c699 MB |
3759 | static int nl80211_set_multicast_to_unicast(struct i802_bss *bss, |
3760 | int multicast_to_unicast) | |
3761 | { | |
3762 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
3763 | struct nl_msg *msg; | |
3764 | int ret; | |
3765 | ||
3766 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_MULTICAST_TO_UNICAST); | |
3767 | if (!msg || | |
3768 | (multicast_to_unicast && | |
3769 | nla_put_flag(msg, NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED))) { | |
3770 | wpa_printf(MSG_ERROR, | |
3771 | "nl80211: Failed to build NL80211_CMD_SET_MULTICAST_TO_UNICAST msg for %s", | |
3772 | bss->ifname); | |
3773 | nlmsg_free(msg); | |
3774 | return -ENOBUFS; | |
3775 | } | |
3776 | ||
3777 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
3778 | ||
3779 | switch (ret) { | |
3780 | case 0: | |
3781 | wpa_printf(MSG_DEBUG, | |
3782 | "nl80211: multicast to unicast %s on interface %s", | |
3783 | multicast_to_unicast ? "enabled" : "disabled", | |
3784 | bss->ifname); | |
3785 | break; | |
3786 | case -EOPNOTSUPP: | |
3787 | if (!multicast_to_unicast) | |
3788 | break; | |
3789 | wpa_printf(MSG_INFO, | |
3790 | "nl80211: multicast to unicast not supported on interface %s", | |
3791 | bss->ifname); | |
3792 | break; | |
3793 | default: | |
3794 | wpa_printf(MSG_ERROR, | |
3795 | "nl80211: %s multicast to unicast failed with %d (%s) on interface %s", | |
3796 | multicast_to_unicast ? "enabling" : "disabling", | |
3797 | ret, strerror(-ret), bss->ifname); | |
3798 | break; | |
3799 | } | |
3800 | ||
3801 | return ret; | |
3802 | } | |
3803 | ||
3804 | ||
19c3b566 JM |
3805 | static int wpa_driver_nl80211_set_ap(void *priv, |
3806 | struct wpa_driver_ap_params *params) | |
d2440ba0 | 3807 | { |
a2e40bb6 FF |
3808 | struct i802_bss *bss = priv; |
3809 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
d2440ba0 JM |
3810 | struct nl_msg *msg; |
3811 | u8 cmd = NL80211_CMD_NEW_BEACON; | |
3812 | int ret; | |
b4fd6fab | 3813 | int beacon_set; |
b11d1d64 | 3814 | int num_suites; |
da1080d7 | 3815 | int smps_mode; |
de4ed4a8 | 3816 | u32 suites[10], suite; |
b11d1d64 | 3817 | u32 ver; |
052b8d38 MH |
3818 | #ifdef CONFIG_MESH |
3819 | struct wpa_driver_mesh_bss_params mesh_params; | |
3820 | #endif /* CONFIG_MESH */ | |
b4fd6fab | 3821 | |
f33c8606 | 3822 | beacon_set = params->reenable ? 0 : bss->beacon_set; |
d2440ba0 | 3823 | |
d2440ba0 | 3824 | wpa_printf(MSG_DEBUG, "nl80211: Set beacon (beacon_set=%d)", |
b4fd6fab JM |
3825 | beacon_set); |
3826 | if (beacon_set) | |
d2440ba0 | 3827 | cmd = NL80211_CMD_SET_BEACON; |
89fa633a DL |
3828 | else if (!drv->device_ap_sme && !drv->use_monitor && |
3829 | !nl80211_get_wiphy_data_ap(bss)) | |
a70cd0db | 3830 | return -ENOBUFS; |
d2440ba0 | 3831 | |
b92e08fc JM |
3832 | wpa_hexdump(MSG_DEBUG, "nl80211: Beacon head", |
3833 | params->head, params->head_len); | |
b92e08fc JM |
3834 | wpa_hexdump(MSG_DEBUG, "nl80211: Beacon tail", |
3835 | params->tail, params->tail_len); | |
13f83980 | 3836 | wpa_printf(MSG_DEBUG, "nl80211: ifindex=%d", bss->ifindex); |
b92e08fc | 3837 | wpa_printf(MSG_DEBUG, "nl80211: beacon_int=%d", params->beacon_int); |
d4f3003c PK |
3838 | wpa_printf(MSG_DEBUG, "nl80211: beacon_rate=%u", params->beacon_rate); |
3839 | wpa_printf(MSG_DEBUG, "nl80211: rate_type=%d", params->rate_type); | |
b92e08fc | 3840 | wpa_printf(MSG_DEBUG, "nl80211: dtim_period=%d", params->dtim_period); |
b92e08fc JM |
3841 | wpa_hexdump_ascii(MSG_DEBUG, "nl80211: ssid", |
3842 | params->ssid, params->ssid_len); | |
13f83980 | 3843 | if (!(msg = nl80211_bss_msg(bss, 0, cmd)) || |
a862e4a3 JM |
3844 | nla_put(msg, NL80211_ATTR_BEACON_HEAD, params->head_len, |
3845 | params->head) || | |
3846 | nla_put(msg, NL80211_ATTR_BEACON_TAIL, params->tail_len, | |
3847 | params->tail) || | |
85e1fad8 | 3848 | nl80211_put_beacon_int(msg, params->beacon_int) || |
d4f3003c | 3849 | nl80211_put_beacon_rate(msg, drv->capa.flags, params) || |
4ac2ea57 | 3850 | nl80211_put_dtim_period(msg, params->dtim_period) || |
a862e4a3 JM |
3851 | nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid)) |
3852 | goto fail; | |
b92e08fc JM |
3853 | if (params->proberesp && params->proberesp_len) { |
3854 | wpa_hexdump(MSG_DEBUG, "nl80211: proberesp (offload)", | |
3855 | params->proberesp, params->proberesp_len); | |
a862e4a3 JM |
3856 | if (nla_put(msg, NL80211_ATTR_PROBE_RESP, params->proberesp_len, |
3857 | params->proberesp)) | |
3858 | goto fail; | |
b92e08fc | 3859 | } |
97a7a0b5 JM |
3860 | switch (params->hide_ssid) { |
3861 | case NO_SSID_HIDING: | |
b92e08fc | 3862 | wpa_printf(MSG_DEBUG, "nl80211: hidden SSID not in use"); |
a862e4a3 JM |
3863 | if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID, |
3864 | NL80211_HIDDEN_SSID_NOT_IN_USE)) | |
3865 | goto fail; | |
97a7a0b5 JM |
3866 | break; |
3867 | case HIDDEN_SSID_ZERO_LEN: | |
b92e08fc | 3868 | wpa_printf(MSG_DEBUG, "nl80211: hidden SSID zero len"); |
a862e4a3 JM |
3869 | if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID, |
3870 | NL80211_HIDDEN_SSID_ZERO_LEN)) | |
3871 | goto fail; | |
97a7a0b5 JM |
3872 | break; |
3873 | case HIDDEN_SSID_ZERO_CONTENTS: | |
b92e08fc | 3874 | wpa_printf(MSG_DEBUG, "nl80211: hidden SSID zero contents"); |
a862e4a3 JM |
3875 | if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID, |
3876 | NL80211_HIDDEN_SSID_ZERO_CONTENTS)) | |
3877 | goto fail; | |
97a7a0b5 JM |
3878 | break; |
3879 | } | |
b92e08fc | 3880 | wpa_printf(MSG_DEBUG, "nl80211: privacy=%d", params->privacy); |
a862e4a3 JM |
3881 | if (params->privacy && |
3882 | nla_put_flag(msg, NL80211_ATTR_PRIVACY)) | |
3883 | goto fail; | |
b92e08fc | 3884 | wpa_printf(MSG_DEBUG, "nl80211: auth_algs=0x%x", params->auth_algs); |
b11d1d64 JM |
3885 | if ((params->auth_algs & (WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED)) == |
3886 | (WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED)) { | |
3887 | /* Leave out the attribute */ | |
a862e4a3 JM |
3888 | } else if (params->auth_algs & WPA_AUTH_ALG_SHARED) { |
3889 | if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, | |
3890 | NL80211_AUTHTYPE_SHARED_KEY)) | |
3891 | goto fail; | |
3892 | } else { | |
3893 | if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, | |
3894 | NL80211_AUTHTYPE_OPEN_SYSTEM)) | |
3895 | goto fail; | |
3896 | } | |
b11d1d64 | 3897 | |
b92e08fc | 3898 | wpa_printf(MSG_DEBUG, "nl80211: wpa_version=0x%x", params->wpa_version); |
b11d1d64 JM |
3899 | ver = 0; |
3900 | if (params->wpa_version & WPA_PROTO_WPA) | |
3901 | ver |= NL80211_WPA_VERSION_1; | |
3902 | if (params->wpa_version & WPA_PROTO_RSN) | |
3903 | ver |= NL80211_WPA_VERSION_2; | |
a862e4a3 JM |
3904 | if (ver && |
3905 | nla_put_u32(msg, NL80211_ATTR_WPA_VERSIONS, ver)) | |
3906 | goto fail; | |
b11d1d64 | 3907 | |
b92e08fc JM |
3908 | wpa_printf(MSG_DEBUG, "nl80211: key_mgmt_suites=0x%x", |
3909 | params->key_mgmt_suites); | |
b11d1d64 JM |
3910 | num_suites = 0; |
3911 | if (params->key_mgmt_suites & WPA_KEY_MGMT_IEEE8021X) | |
3aa24db9 | 3912 | suites[num_suites++] = RSN_AUTH_KEY_MGMT_UNSPEC_802_1X; |
b11d1d64 | 3913 | if (params->key_mgmt_suites & WPA_KEY_MGMT_PSK) |
3aa24db9 | 3914 | suites[num_suites++] = RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X; |
a862e4a3 JM |
3915 | if (num_suites && |
3916 | nla_put(msg, NL80211_ATTR_AKM_SUITES, num_suites * sizeof(u32), | |
3917 | suites)) | |
3918 | goto fail; | |
b11d1d64 | 3919 | |
533fe09b | 3920 | if (params->key_mgmt_suites & WPA_KEY_MGMT_IEEE8021X_NO_WPA && |
e3429c0b JB |
3921 | (!params->pairwise_ciphers || |
3922 | params->pairwise_ciphers & (WPA_CIPHER_WEP104 | WPA_CIPHER_WEP40)) && | |
3923 | (nla_put_u16(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE, ETH_P_PAE) || | |
3924 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT))) | |
a862e4a3 | 3925 | goto fail; |
9f12614b | 3926 | |
b92e08fc JM |
3927 | wpa_printf(MSG_DEBUG, "nl80211: pairwise_ciphers=0x%x", |
3928 | params->pairwise_ciphers); | |
de4ed4a8 JM |
3929 | num_suites = wpa_cipher_to_cipher_suites(params->pairwise_ciphers, |
3930 | suites, ARRAY_SIZE(suites)); | |
a862e4a3 JM |
3931 | if (num_suites && |
3932 | nla_put(msg, NL80211_ATTR_CIPHER_SUITES_PAIRWISE, | |
3933 | num_suites * sizeof(u32), suites)) | |
3934 | goto fail; | |
b11d1d64 | 3935 | |
b92e08fc JM |
3936 | wpa_printf(MSG_DEBUG, "nl80211: group_cipher=0x%x", |
3937 | params->group_cipher); | |
de4ed4a8 | 3938 | suite = wpa_cipher_to_cipher_suite(params->group_cipher); |
a862e4a3 JM |
3939 | if (suite && |
3940 | nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, suite)) | |
3941 | goto fail; | |
d2440ba0 | 3942 | |
ee298f1b JM |
3943 | if (params->ht_opmode != -1) { |
3944 | switch (params->smps_mode) { | |
3945 | case HT_CAP_INFO_SMPS_DYNAMIC: | |
3946 | wpa_printf(MSG_DEBUG, "nl80211: SMPS mode - dynamic"); | |
3947 | smps_mode = NL80211_SMPS_DYNAMIC; | |
3948 | break; | |
3949 | case HT_CAP_INFO_SMPS_STATIC: | |
3950 | wpa_printf(MSG_DEBUG, "nl80211: SMPS mode - static"); | |
3951 | smps_mode = NL80211_SMPS_STATIC; | |
3952 | break; | |
3953 | default: | |
3954 | /* invalid - fallback to smps off */ | |
3955 | case HT_CAP_INFO_SMPS_DISABLED: | |
3956 | wpa_printf(MSG_DEBUG, "nl80211: SMPS mode - off"); | |
3957 | smps_mode = NL80211_SMPS_OFF; | |
3958 | break; | |
3959 | } | |
a2426829 | 3960 | if (nla_put_u8(msg, NL80211_ATTR_SMPS_MODE, smps_mode)) |
ee298f1b | 3961 | goto fail; |
da1080d7 | 3962 | } |
da1080d7 | 3963 | |
fb91db56 | 3964 | if (params->beacon_ies) { |
b92e08fc JM |
3965 | wpa_hexdump_buf(MSG_DEBUG, "nl80211: beacon_ies", |
3966 | params->beacon_ies); | |
a862e4a3 JM |
3967 | if (nla_put(msg, NL80211_ATTR_IE, |
3968 | wpabuf_len(params->beacon_ies), | |
3969 | wpabuf_head(params->beacon_ies))) | |
3970 | goto fail; | |
fb91db56 JM |
3971 | } |
3972 | if (params->proberesp_ies) { | |
b92e08fc JM |
3973 | wpa_hexdump_buf(MSG_DEBUG, "nl80211: proberesp_ies", |
3974 | params->proberesp_ies); | |
a862e4a3 JM |
3975 | if (nla_put(msg, NL80211_ATTR_IE_PROBE_RESP, |
3976 | wpabuf_len(params->proberesp_ies), | |
3977 | wpabuf_head(params->proberesp_ies))) | |
3978 | goto fail; | |
fb91db56 JM |
3979 | } |
3980 | if (params->assocresp_ies) { | |
b92e08fc JM |
3981 | wpa_hexdump_buf(MSG_DEBUG, "nl80211: assocresp_ies", |
3982 | params->assocresp_ies); | |
a862e4a3 JM |
3983 | if (nla_put(msg, NL80211_ATTR_IE_ASSOC_RESP, |
3984 | wpabuf_len(params->assocresp_ies), | |
3985 | wpabuf_head(params->assocresp_ies))) | |
3986 | goto fail; | |
fb91db56 JM |
3987 | } |
3988 | ||
a0133ee1 | 3989 | if (drv->capa.flags & WPA_DRIVER_FLAGS_INACTIVITY_TIMER) { |
b92e08fc JM |
3990 | wpa_printf(MSG_DEBUG, "nl80211: ap_max_inactivity=%d", |
3991 | params->ap_max_inactivity); | |
a862e4a3 JM |
3992 | if (nla_put_u16(msg, NL80211_ATTR_INACTIVITY_TIMEOUT, |
3993 | params->ap_max_inactivity)) | |
3994 | goto fail; | |
a0133ee1 VT |
3995 | } |
3996 | ||
abb8d08b EP |
3997 | #ifdef CONFIG_P2P |
3998 | if (params->p2p_go_ctwindow > 0) { | |
3999 | if (drv->p2p_go_ctwindow_supported) { | |
4000 | wpa_printf(MSG_DEBUG, "nl80211: P2P GO ctwindow=%d", | |
4001 | params->p2p_go_ctwindow); | |
4002 | if (nla_put_u8(msg, NL80211_ATTR_P2P_CTWINDOW, | |
4003 | params->p2p_go_ctwindow)) | |
4004 | goto fail; | |
4005 | } else { | |
4006 | wpa_printf(MSG_INFO, | |
4007 | "nl80211: Driver does not support CTWindow configuration - ignore this parameter"); | |
4008 | } | |
4009 | } | |
4010 | #endif /* CONFIG_P2P */ | |
4011 | ||
86b5c400 LD |
4012 | if (params->pbss) { |
4013 | wpa_printf(MSG_DEBUG, "nl80211: PBSS"); | |
4014 | if (nla_put_flag(msg, NL80211_ATTR_PBSS)) | |
4015 | goto fail; | |
4016 | } | |
4017 | ||
d2440ba0 JM |
4018 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
4019 | if (ret) { | |
4020 | wpa_printf(MSG_DEBUG, "nl80211: Beacon set failed: %d (%s)", | |
4021 | ret, strerror(-ret)); | |
b4fd6fab | 4022 | } else { |
b4fd6fab | 4023 | bss->beacon_set = 1; |
31357268 | 4024 | nl80211_set_bss(bss, params->cts_protect, params->preamble, |
d03e8d11 | 4025 | params->short_slot_time, params->ht_opmode, |
e5693c47 | 4026 | params->isolate, params->basic_rates); |
34f7c699 MB |
4027 | nl80211_set_multicast_to_unicast(bss, |
4028 | params->multicast_to_unicast); | |
e87ef751 PX |
4029 | if (beacon_set && params->freq && |
4030 | params->freq->bandwidth != bss->bandwidth) { | |
4031 | wpa_printf(MSG_DEBUG, | |
4032 | "nl80211: Update BSS %s bandwidth: %d -> %d", | |
4033 | bss->ifname, bss->bandwidth, | |
4034 | params->freq->bandwidth); | |
4035 | ret = nl80211_set_channel(bss, params->freq, 1); | |
4036 | if (ret) { | |
4037 | wpa_printf(MSG_DEBUG, | |
4038 | "nl80211: Frequency set failed: %d (%s)", | |
4039 | ret, strerror(-ret)); | |
4040 | } else { | |
4041 | wpa_printf(MSG_DEBUG, | |
4042 | "nl80211: Frequency set succeeded for ht2040 coex"); | |
4043 | bss->bandwidth = params->freq->bandwidth; | |
4044 | } | |
f5728d0a | 4045 | } else if (!beacon_set && params->freq) { |
e87ef751 PX |
4046 | /* |
4047 | * cfg80211 updates the driver on frequence change in AP | |
4048 | * mode only at the point when beaconing is started, so | |
4049 | * set the initial value here. | |
4050 | */ | |
4051 | bss->bandwidth = params->freq->bandwidth; | |
4052 | } | |
b4fd6fab | 4053 | } |
052b8d38 MH |
4054 | |
4055 | #ifdef CONFIG_MESH | |
4056 | if (is_mesh_interface(drv->nlmode) && params->ht_opmode != -1) { | |
4057 | os_memset(&mesh_params, 0, sizeof(mesh_params)); | |
4058 | mesh_params.flags |= WPA_DRIVER_MESH_CONF_FLAG_HT_OP_MODE; | |
4059 | mesh_params.ht_opmode = params->ht_opmode; | |
4060 | ret = nl80211_set_mesh_config(priv, &mesh_params); | |
4061 | if (ret < 0) | |
4062 | return ret; | |
4063 | } | |
4064 | #endif /* CONFIG_MESH */ | |
4065 | ||
d2440ba0 | 4066 | return ret; |
a862e4a3 | 4067 | fail: |
5883168a | 4068 | nlmsg_free(msg); |
d2440ba0 JM |
4069 | return -ENOBUFS; |
4070 | } | |
4071 | ||
4072 | ||
1c4ffa87 | 4073 | static int nl80211_put_freq_params(struct nl_msg *msg, |
72b2605f | 4074 | const struct hostapd_freq_params *freq) |
1581b38b | 4075 | { |
1fc4ab23 | 4076 | wpa_printf(MSG_DEBUG, " * freq=%d", freq->freq); |
a862e4a3 JM |
4077 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq->freq)) |
4078 | return -ENOBUFS; | |
4079 | ||
1fc4ab23 JM |
4080 | wpa_printf(MSG_DEBUG, " * vht_enabled=%d", freq->vht_enabled); |
4081 | wpa_printf(MSG_DEBUG, " * ht_enabled=%d", freq->ht_enabled); | |
4082 | ||
89b800d7 | 4083 | if (freq->vht_enabled) { |
a862e4a3 JM |
4084 | enum nl80211_chan_width cw; |
4085 | ||
1fc4ab23 | 4086 | wpa_printf(MSG_DEBUG, " * bandwidth=%d", freq->bandwidth); |
89b800d7 JB |
4087 | switch (freq->bandwidth) { |
4088 | case 20: | |
a862e4a3 | 4089 | cw = NL80211_CHAN_WIDTH_20; |
89b800d7 JB |
4090 | break; |
4091 | case 40: | |
a862e4a3 | 4092 | cw = NL80211_CHAN_WIDTH_40; |
89b800d7 JB |
4093 | break; |
4094 | case 80: | |
4095 | if (freq->center_freq2) | |
a862e4a3 | 4096 | cw = NL80211_CHAN_WIDTH_80P80; |
89b800d7 | 4097 | else |
a862e4a3 | 4098 | cw = NL80211_CHAN_WIDTH_80; |
89b800d7 JB |
4099 | break; |
4100 | case 160: | |
a862e4a3 | 4101 | cw = NL80211_CHAN_WIDTH_160; |
89b800d7 JB |
4102 | break; |
4103 | default: | |
1c4ffa87 | 4104 | return -EINVAL; |
89b800d7 | 4105 | } |
a862e4a3 | 4106 | |
1fc4ab23 JM |
4107 | wpa_printf(MSG_DEBUG, " * channel_width=%d", cw); |
4108 | wpa_printf(MSG_DEBUG, " * center_freq1=%d", | |
4109 | freq->center_freq1); | |
4110 | wpa_printf(MSG_DEBUG, " * center_freq2=%d", | |
4111 | freq->center_freq2); | |
a862e4a3 JM |
4112 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, cw) || |
4113 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, | |
4114 | freq->center_freq1) || | |
4115 | (freq->center_freq2 && | |
4116 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, | |
4117 | freq->center_freq2))) | |
4118 | return -ENOBUFS; | |
89b800d7 | 4119 | } else if (freq->ht_enabled) { |
a862e4a3 JM |
4120 | enum nl80211_channel_type ct; |
4121 | ||
1fc4ab23 JM |
4122 | wpa_printf(MSG_DEBUG, " * sec_channel_offset=%d", |
4123 | freq->sec_channel_offset); | |
89b800d7 | 4124 | switch (freq->sec_channel_offset) { |
f019981a | 4125 | case -1: |
a862e4a3 | 4126 | ct = NL80211_CHAN_HT40MINUS; |
f019981a JM |
4127 | break; |
4128 | case 1: | |
a862e4a3 | 4129 | ct = NL80211_CHAN_HT40PLUS; |
f019981a JM |
4130 | break; |
4131 | default: | |
a862e4a3 | 4132 | ct = NL80211_CHAN_HT20; |
f019981a JM |
4133 | break; |
4134 | } | |
a862e4a3 | 4135 | |
1fc4ab23 | 4136 | wpa_printf(MSG_DEBUG, " * channel_type=%d", ct); |
a862e4a3 JM |
4137 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, ct)) |
4138 | return -ENOBUFS; | |
3388e7b9 MH |
4139 | } else { |
4140 | wpa_printf(MSG_DEBUG, " * channel_type=%d", | |
4141 | NL80211_CHAN_NO_HT); | |
4142 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, | |
4143 | NL80211_CHAN_NO_HT)) | |
4144 | return -ENOBUFS; | |
f019981a | 4145 | } |
1c4ffa87 | 4146 | return 0; |
1c4ffa87 AO |
4147 | } |
4148 | ||
4149 | ||
e87ef751 PX |
4150 | static int nl80211_set_channel(struct i802_bss *bss, |
4151 | struct hostapd_freq_params *freq, int set_chan) | |
1c4ffa87 AO |
4152 | { |
4153 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
4154 | struct nl_msg *msg; | |
4155 | int ret; | |
4156 | ||
4157 | wpa_printf(MSG_DEBUG, | |
4158 | "nl80211: Set freq %d (ht_enabled=%d, vht_enabled=%d, bandwidth=%d MHz, cf1=%d MHz, cf2=%d MHz)", | |
4159 | freq->freq, freq->ht_enabled, freq->vht_enabled, | |
4160 | freq->bandwidth, freq->center_freq1, freq->center_freq2); | |
1c4ffa87 | 4161 | |
9725b784 JM |
4162 | msg = nl80211_drv_msg(drv, 0, set_chan ? NL80211_CMD_SET_CHANNEL : |
4163 | NL80211_CMD_SET_WIPHY); | |
4164 | if (!msg || nl80211_put_freq_params(msg, freq) < 0) { | |
a862e4a3 JM |
4165 | nlmsg_free(msg); |
4166 | return -1; | |
4167 | } | |
1581b38b | 4168 | |
d2440ba0 | 4169 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
e4fb2167 | 4170 | if (ret == 0) { |
89b800d7 | 4171 | bss->freq = freq->freq; |
1581b38b | 4172 | return 0; |
e4fb2167 | 4173 | } |
f019981a | 4174 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set channel (freq=%d): " |
89b800d7 | 4175 | "%d (%s)", freq->freq, ret, strerror(-ret)); |
1581b38b JM |
4176 | return -1; |
4177 | } | |
4178 | ||
0f4e8b4f | 4179 | |
95ab6063 AN |
4180 | static u32 sta_flags_nl80211(int flags) |
4181 | { | |
4182 | u32 f = 0; | |
4183 | ||
4184 | if (flags & WPA_STA_AUTHORIZED) | |
4185 | f |= BIT(NL80211_STA_FLAG_AUTHORIZED); | |
4186 | if (flags & WPA_STA_WMM) | |
4187 | f |= BIT(NL80211_STA_FLAG_WME); | |
4188 | if (flags & WPA_STA_SHORT_PREAMBLE) | |
4189 | f |= BIT(NL80211_STA_FLAG_SHORT_PREAMBLE); | |
4190 | if (flags & WPA_STA_MFP) | |
4191 | f |= BIT(NL80211_STA_FLAG_MFP); | |
45b722f1 AN |
4192 | if (flags & WPA_STA_TDLS_PEER) |
4193 | f |= BIT(NL80211_STA_FLAG_TDLS_PEER); | |
7a228b5c BC |
4194 | if (flags & WPA_STA_AUTHENTICATED) |
4195 | f |= BIT(NL80211_STA_FLAG_AUTHENTICATED); | |
dc55b6b6 AB |
4196 | if (flags & WPA_STA_ASSOCIATED) |
4197 | f |= BIT(NL80211_STA_FLAG_ASSOCIATED); | |
95ab6063 AN |
4198 | |
4199 | return f; | |
4200 | } | |
4201 | ||
4202 | ||
7c7e7877 BC |
4203 | #ifdef CONFIG_MESH |
4204 | static u32 sta_plink_state_nl80211(enum mesh_plink_state state) | |
4205 | { | |
4206 | switch (state) { | |
d02e5498 | 4207 | case PLINK_IDLE: |
7c7e7877 | 4208 | return NL80211_PLINK_LISTEN; |
d02e5498 | 4209 | case PLINK_OPN_SNT: |
7c7e7877 | 4210 | return NL80211_PLINK_OPN_SNT; |
d02e5498 | 4211 | case PLINK_OPN_RCVD: |
7c7e7877 BC |
4212 | return NL80211_PLINK_OPN_RCVD; |
4213 | case PLINK_CNF_RCVD: | |
4214 | return NL80211_PLINK_CNF_RCVD; | |
4215 | case PLINK_ESTAB: | |
4216 | return NL80211_PLINK_ESTAB; | |
4217 | case PLINK_HOLDING: | |
4218 | return NL80211_PLINK_HOLDING; | |
4219 | case PLINK_BLOCKED: | |
4220 | return NL80211_PLINK_BLOCKED; | |
4221 | default: | |
4222 | wpa_printf(MSG_ERROR, "nl80211: Invalid mesh plink state %d", | |
4223 | state); | |
4224 | } | |
4225 | return -1; | |
4226 | } | |
4227 | #endif /* CONFIG_MESH */ | |
4228 | ||
4229 | ||
62847751 | 4230 | static int wpa_driver_nl80211_sta_add(void *priv, |
0f4e8b4f JM |
4231 | struct hostapd_sta_add_params *params) |
4232 | { | |
a2e40bb6 FF |
4233 | struct i802_bss *bss = priv; |
4234 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8970bae8 | 4235 | struct nl_msg *msg; |
95ab6063 | 4236 | struct nl80211_sta_flag_update upd; |
0f4e8b4f JM |
4237 | int ret = -ENOBUFS; |
4238 | ||
45b722f1 AN |
4239 | if ((params->flags & WPA_STA_TDLS_PEER) && |
4240 | !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) | |
4241 | return -EOPNOTSUPP; | |
4242 | ||
e4dea253 JM |
4243 | wpa_printf(MSG_DEBUG, "nl80211: %s STA " MACSTR, |
4244 | params->set ? "Set" : "Add", MAC2STR(params->addr)); | |
13f83980 JM |
4245 | msg = nl80211_bss_msg(bss, 0, params->set ? NL80211_CMD_SET_STATION : |
4246 | NL80211_CMD_NEW_STATION); | |
4247 | if (!msg || nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->addr)) | |
a862e4a3 | 4248 | goto fail; |
5551bc9c | 4249 | |
dc55b6b6 AB |
4250 | /* |
4251 | * Set the below properties only in one of the following cases: | |
4252 | * 1. New station is added, already associated. | |
4253 | * 2. Set WPA_STA_TDLS_PEER station. | |
4254 | * 3. Set an already added unassociated station, if driver supports | |
4255 | * full AP client state. (Set these properties after station became | |
4256 | * associated will be rejected by the driver). | |
4257 | */ | |
4258 | if (!params->set || (params->flags & WPA_STA_TDLS_PEER) || | |
4259 | (params->set && FULL_AP_CLIENT_STATE_SUPP(drv->capa.flags) && | |
4260 | (params->flags & WPA_STA_ASSOCIATED))) { | |
5551bc9c BC |
4261 | wpa_hexdump(MSG_DEBUG, " * supported rates", |
4262 | params->supp_rates, params->supp_rates_len); | |
a862e4a3 JM |
4263 | wpa_printf(MSG_DEBUG, " * capability=0x%x", |
4264 | params->capability); | |
4265 | if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_RATES, | |
4266 | params->supp_rates_len, params->supp_rates) || | |
4267 | nla_put_u16(msg, NL80211_ATTR_STA_CAPABILITY, | |
4268 | params->capability)) | |
4269 | goto fail; | |
e503861f JM |
4270 | |
4271 | if (params->ht_capabilities) { | |
4272 | wpa_hexdump(MSG_DEBUG, " * ht_capabilities", | |
4273 | (u8 *) params->ht_capabilities, | |
4274 | sizeof(*params->ht_capabilities)); | |
a862e4a3 JM |
4275 | if (nla_put(msg, NL80211_ATTR_HT_CAPABILITY, |
4276 | sizeof(*params->ht_capabilities), | |
4277 | params->ht_capabilities)) | |
4278 | goto fail; | |
e503861f JM |
4279 | } |
4280 | ||
4281 | if (params->vht_capabilities) { | |
4282 | wpa_hexdump(MSG_DEBUG, " * vht_capabilities", | |
4283 | (u8 *) params->vht_capabilities, | |
4284 | sizeof(*params->vht_capabilities)); | |
a862e4a3 JM |
4285 | if (nla_put(msg, NL80211_ATTR_VHT_CAPABILITY, |
4286 | sizeof(*params->vht_capabilities), | |
4287 | params->vht_capabilities)) | |
4288 | goto fail; | |
e503861f JM |
4289 | } |
4290 | ||
e503861f JM |
4291 | if (params->ext_capab) { |
4292 | wpa_hexdump(MSG_DEBUG, " * ext_capab", | |
4293 | params->ext_capab, params->ext_capab_len); | |
a862e4a3 JM |
4294 | if (nla_put(msg, NL80211_ATTR_STA_EXT_CAPABILITY, |
4295 | params->ext_capab_len, params->ext_capab)) | |
4296 | goto fail; | |
e503861f | 4297 | } |
ae33239c AB |
4298 | |
4299 | if (is_ap_interface(drv->nlmode) && | |
4300 | nla_put_u8(msg, NL80211_ATTR_STA_SUPPORT_P2P_PS, | |
4301 | params->support_p2p_ps ? | |
4302 | NL80211_P2P_PS_SUPPORTED : | |
4303 | NL80211_P2P_PS_UNSUPPORTED)) | |
4304 | goto fail; | |
5551bc9c | 4305 | } |
45b722f1 | 4306 | if (!params->set) { |
f11b72c3 JM |
4307 | if (params->aid) { |
4308 | wpa_printf(MSG_DEBUG, " * aid=%u", params->aid); | |
a862e4a3 JM |
4309 | if (nla_put_u16(msg, NL80211_ATTR_STA_AID, params->aid)) |
4310 | goto fail; | |
f11b72c3 JM |
4311 | } else { |
4312 | /* | |
4313 | * cfg80211 validates that AID is non-zero, so we have | |
4314 | * to make this a non-zero value for the TDLS case where | |
dc55b6b6 AB |
4315 | * a dummy STA entry is used for now and for a station |
4316 | * that is still not associated. | |
f11b72c3 | 4317 | */ |
dc55b6b6 AB |
4318 | wpa_printf(MSG_DEBUG, " * aid=1 (%s workaround)", |
4319 | (params->flags & WPA_STA_TDLS_PEER) ? | |
4320 | "TDLS" : "UNASSOC_STA"); | |
a862e4a3 JM |
4321 | if (nla_put_u16(msg, NL80211_ATTR_STA_AID, 1)) |
4322 | goto fail; | |
f11b72c3 | 4323 | } |
e4dea253 JM |
4324 | wpa_printf(MSG_DEBUG, " * listen_interval=%u", |
4325 | params->listen_interval); | |
a862e4a3 JM |
4326 | if (nla_put_u16(msg, NL80211_ATTR_STA_LISTEN_INTERVAL, |
4327 | params->listen_interval)) | |
4328 | goto fail; | |
e112764e JM |
4329 | } else if (params->aid && (params->flags & WPA_STA_TDLS_PEER)) { |
4330 | wpa_printf(MSG_DEBUG, " * peer_aid=%u", params->aid); | |
a862e4a3 JM |
4331 | if (nla_put_u16(msg, NL80211_ATTR_PEER_AID, params->aid)) |
4332 | goto fail; | |
dc55b6b6 AB |
4333 | } else if (FULL_AP_CLIENT_STATE_SUPP(drv->capa.flags) && |
4334 | (params->flags & WPA_STA_ASSOCIATED)) { | |
4335 | wpa_printf(MSG_DEBUG, " * aid=%u", params->aid); | |
4336 | wpa_printf(MSG_DEBUG, " * listen_interval=%u", | |
4337 | params->listen_interval); | |
4338 | if (nla_put_u16(msg, NL80211_ATTR_STA_AID, params->aid) || | |
4339 | nla_put_u16(msg, NL80211_ATTR_STA_LISTEN_INTERVAL, | |
4340 | params->listen_interval)) | |
4341 | goto fail; | |
45b722f1 | 4342 | } |
05a8d422 | 4343 | |
8a458116 MK |
4344 | if (params->vht_opmode_enabled) { |
4345 | wpa_printf(MSG_DEBUG, " * opmode=%u", params->vht_opmode); | |
a862e4a3 JM |
4346 | if (nla_put_u8(msg, NL80211_ATTR_OPMODE_NOTIF, |
4347 | params->vht_opmode)) | |
4348 | goto fail; | |
8a458116 MK |
4349 | } |
4350 | ||
efc64886 SD |
4351 | if (params->supp_channels) { |
4352 | wpa_hexdump(MSG_DEBUG, " * supported channels", | |
4353 | params->supp_channels, params->supp_channels_len); | |
a862e4a3 JM |
4354 | if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_CHANNELS, |
4355 | params->supp_channels_len, params->supp_channels)) | |
4356 | goto fail; | |
efc64886 SD |
4357 | } |
4358 | ||
4359 | if (params->supp_oper_classes) { | |
4360 | wpa_hexdump(MSG_DEBUG, " * supported operating classes", | |
4361 | params->supp_oper_classes, | |
4362 | params->supp_oper_classes_len); | |
a862e4a3 JM |
4363 | if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES, |
4364 | params->supp_oper_classes_len, | |
4365 | params->supp_oper_classes)) | |
4366 | goto fail; | |
efc64886 SD |
4367 | } |
4368 | ||
95ab6063 | 4369 | os_memset(&upd, 0, sizeof(upd)); |
7e31703e BC |
4370 | upd.set = sta_flags_nl80211(params->flags); |
4371 | upd.mask = upd.set | sta_flags_nl80211(params->flags_mask); | |
dc55b6b6 AB |
4372 | |
4373 | /* | |
4374 | * If the driver doesn't support full AP client state, ignore ASSOC/AUTH | |
4375 | * flags, as nl80211 driver moves a new station, by default, into | |
4376 | * associated state. | |
4377 | * | |
4378 | * On the other hand, if the driver supports that feature and the | |
4379 | * station is added in unauthenticated state, set the | |
4380 | * authenticated/associated bits in the mask to prevent moving this | |
4381 | * station to associated state before it is actually associated. | |
4382 | * | |
4383 | * This is irrelevant for mesh mode where the station is added to the | |
4384 | * driver as authenticated already, and ASSOCIATED isn't part of the | |
4385 | * nl80211 API. | |
4386 | */ | |
4387 | if (!is_mesh_interface(drv->nlmode)) { | |
4388 | if (!FULL_AP_CLIENT_STATE_SUPP(drv->capa.flags)) { | |
4389 | wpa_printf(MSG_DEBUG, | |
4390 | "nl80211: Ignore ASSOC/AUTH flags since driver doesn't support full AP client state"); | |
4391 | upd.mask &= ~(BIT(NL80211_STA_FLAG_ASSOCIATED) | | |
4392 | BIT(NL80211_STA_FLAG_AUTHENTICATED)); | |
4393 | } else if (!params->set && | |
4394 | !(params->flags & WPA_STA_TDLS_PEER)) { | |
4395 | if (!(params->flags & WPA_STA_AUTHENTICATED)) | |
4396 | upd.mask |= BIT(NL80211_STA_FLAG_AUTHENTICATED); | |
4397 | if (!(params->flags & WPA_STA_ASSOCIATED)) | |
4398 | upd.mask |= BIT(NL80211_STA_FLAG_ASSOCIATED); | |
4399 | } | |
e347cafe MH |
4400 | #ifdef CONFIG_MESH |
4401 | } else { | |
4402 | if (params->plink_state == PLINK_ESTAB && params->peer_aid) { | |
4403 | ret = nla_put_u16(msg, NL80211_ATTR_MESH_PEER_AID, | |
4404 | params->peer_aid); | |
4405 | if (ret) | |
4406 | goto fail; | |
4407 | } | |
4408 | #endif /* CONFIG_MESH */ | |
dc55b6b6 AB |
4409 | } |
4410 | ||
e4dea253 JM |
4411 | wpa_printf(MSG_DEBUG, " * flags set=0x%x mask=0x%x", |
4412 | upd.set, upd.mask); | |
a862e4a3 JM |
4413 | if (nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd)) |
4414 | goto fail; | |
95ab6063 | 4415 | |
7c7e7877 | 4416 | #ifdef CONFIG_MESH |
a862e4a3 JM |
4417 | if (params->plink_state && |
4418 | nla_put_u8(msg, NL80211_ATTR_STA_PLINK_STATE, | |
4419 | sta_plink_state_nl80211(params->plink_state))) | |
4420 | goto fail; | |
7c7e7877 BC |
4421 | #endif /* CONFIG_MESH */ |
4422 | ||
774bfa62 | 4423 | if (params->flags & WPA_STA_WMM) { |
8970bae8 JB |
4424 | struct nlattr *wme = nla_nest_start(msg, NL80211_ATTR_STA_WME); |
4425 | ||
e4dea253 | 4426 | wpa_printf(MSG_DEBUG, " * qosinfo=0x%x", params->qosinfo); |
a862e4a3 JM |
4427 | if (!wme || |
4428 | nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES, | |
4429 | params->qosinfo & WMM_QOSINFO_STA_AC_MASK) || | |
4430 | nla_put_u8(msg, NL80211_STA_WME_MAX_SP, | |
4431 | (params->qosinfo >> WMM_QOSINFO_STA_SP_SHIFT) & | |
4432 | WMM_QOSINFO_STA_SP_MASK)) | |
4433 | goto fail; | |
8970bae8 | 4434 | nla_nest_end(msg, wme); |
774bfa62 EP |
4435 | } |
4436 | ||
0f4e8b4f | 4437 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
5883168a | 4438 | msg = NULL; |
0f4e8b4f | 4439 | if (ret) |
45b722f1 AN |
4440 | wpa_printf(MSG_DEBUG, "nl80211: NL80211_CMD_%s_STATION " |
4441 | "result: %d (%s)", params->set ? "SET" : "NEW", ret, | |
4442 | strerror(-ret)); | |
0f4e8b4f JM |
4443 | if (ret == -EEXIST) |
4444 | ret = 0; | |
a862e4a3 | 4445 | fail: |
5883168a | 4446 | nlmsg_free(msg); |
0f4e8b4f JM |
4447 | return ret; |
4448 | } | |
4449 | ||
4450 | ||
97ed9a06 KP |
4451 | static void rtnl_neigh_delete_fdb_entry(struct i802_bss *bss, const u8 *addr) |
4452 | { | |
4453 | #ifdef CONFIG_LIBNL3_ROUTE | |
4454 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
4455 | struct rtnl_neigh *rn; | |
4456 | struct nl_addr *nl_addr; | |
4457 | int err; | |
4458 | ||
4459 | rn = rtnl_neigh_alloc(); | |
4460 | if (!rn) | |
4461 | return; | |
4462 | ||
4463 | rtnl_neigh_set_family(rn, AF_BRIDGE); | |
4464 | rtnl_neigh_set_ifindex(rn, bss->ifindex); | |
4465 | nl_addr = nl_addr_build(AF_BRIDGE, (void *) addr, ETH_ALEN); | |
4466 | if (!nl_addr) { | |
4467 | rtnl_neigh_put(rn); | |
4468 | return; | |
4469 | } | |
4470 | rtnl_neigh_set_lladdr(rn, nl_addr); | |
4471 | ||
4472 | err = rtnl_neigh_delete(drv->rtnl_sk, rn, 0); | |
4473 | if (err < 0) { | |
4474 | wpa_printf(MSG_DEBUG, "nl80211: bridge FDB entry delete for " | |
4475 | MACSTR " ifindex=%d failed: %s", MAC2STR(addr), | |
4476 | bss->ifindex, nl_geterror(err)); | |
4477 | } else { | |
4478 | wpa_printf(MSG_DEBUG, "nl80211: deleted bridge FDB entry for " | |
4479 | MACSTR, MAC2STR(addr)); | |
4480 | } | |
4481 | ||
4482 | nl_addr_put(nl_addr); | |
4483 | rtnl_neigh_put(rn); | |
4484 | #endif /* CONFIG_LIBNL3_ROUTE */ | |
4485 | } | |
4486 | ||
4487 | ||
59d7148a JM |
4488 | static int wpa_driver_nl80211_sta_remove(struct i802_bss *bss, const u8 *addr, |
4489 | int deauth, u16 reason_code) | |
0f4e8b4f | 4490 | { |
a2e40bb6 | 4491 | struct wpa_driver_nl80211_data *drv = bss->drv; |
0f4e8b4f JM |
4492 | struct nl_msg *msg; |
4493 | int ret; | |
4494 | ||
13f83980 | 4495 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_DEL_STATION)) || |
a862e4a3 JM |
4496 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
4497 | (deauth == 0 && | |
4498 | nla_put_u8(msg, NL80211_ATTR_MGMT_SUBTYPE, | |
4499 | WLAN_FC_STYPE_DISASSOC)) || | |
4500 | (deauth == 1 && | |
4501 | nla_put_u8(msg, NL80211_ATTR_MGMT_SUBTYPE, | |
4502 | WLAN_FC_STYPE_DEAUTH)) || | |
4503 | (reason_code && | |
4504 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) { | |
4505 | nlmsg_free(msg); | |
4506 | return -ENOBUFS; | |
4507 | } | |
0f4e8b4f JM |
4508 | |
4509 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
83e7bb0e JM |
4510 | wpa_printf(MSG_DEBUG, "nl80211: sta_remove -> DEL_STATION %s " MACSTR |
4511 | " --> %d (%s)", | |
4512 | bss->ifname, MAC2STR(addr), ret, strerror(-ret)); | |
97ed9a06 KP |
4513 | |
4514 | if (drv->rtnl_sk) | |
4515 | rtnl_neigh_delete_fdb_entry(bss, addr); | |
4516 | ||
0f4e8b4f JM |
4517 | if (ret == -ENOENT) |
4518 | return 0; | |
4519 | return ret; | |
0f4e8b4f JM |
4520 | } |
4521 | ||
1581b38b | 4522 | |
f3407c66 | 4523 | void nl80211_remove_iface(struct wpa_driver_nl80211_data *drv, int ifidx) |
0915d02c JM |
4524 | { |
4525 | struct nl_msg *msg; | |
de884303 | 4526 | struct wpa_driver_nl80211_data *drv2; |
0915d02c | 4527 | |
c6e8e8e4 JM |
4528 | wpa_printf(MSG_DEBUG, "nl80211: Remove interface ifindex=%d", ifidx); |
4529 | ||
2135f224 | 4530 | /* stop listening for EAPOL on this interface */ |
de884303 JM |
4531 | dl_list_for_each(drv2, &drv->global->interfaces, |
4532 | struct wpa_driver_nl80211_data, list) | |
732b1d20 MB |
4533 | { |
4534 | del_ifidx(drv2, ifidx, IFIDX_ANY); | |
4535 | /* Remove all bridges learned for this iface */ | |
4536 | del_ifidx(drv2, IFIDX_ANY, ifidx); | |
4537 | } | |
2135f224 | 4538 | |
95376e1a | 4539 | msg = nl80211_ifindex_msg(drv, ifidx, 0, NL80211_CMD_DEL_INTERFACE); |
0915d02c JM |
4540 | if (send_and_recv_msgs(drv, msg, NULL, NULL) == 0) |
4541 | return; | |
e748062b | 4542 | wpa_printf(MSG_ERROR, "Failed to remove interface (ifidx=%d)", ifidx); |
0915d02c JM |
4543 | } |
4544 | ||
4545 | ||
cc9a2575 | 4546 | const char * nl80211_iftype_str(enum nl80211_iftype mode) |
a1922f93 JM |
4547 | { |
4548 | switch (mode) { | |
4549 | case NL80211_IFTYPE_ADHOC: | |
4550 | return "ADHOC"; | |
4551 | case NL80211_IFTYPE_STATION: | |
4552 | return "STATION"; | |
4553 | case NL80211_IFTYPE_AP: | |
4554 | return "AP"; | |
1045ec36 JM |
4555 | case NL80211_IFTYPE_AP_VLAN: |
4556 | return "AP_VLAN"; | |
4557 | case NL80211_IFTYPE_WDS: | |
4558 | return "WDS"; | |
a1922f93 JM |
4559 | case NL80211_IFTYPE_MONITOR: |
4560 | return "MONITOR"; | |
1045ec36 JM |
4561 | case NL80211_IFTYPE_MESH_POINT: |
4562 | return "MESH_POINT"; | |
a1922f93 JM |
4563 | case NL80211_IFTYPE_P2P_CLIENT: |
4564 | return "P2P_CLIENT"; | |
4565 | case NL80211_IFTYPE_P2P_GO: | |
4566 | return "P2P_GO"; | |
7aad838c NS |
4567 | case NL80211_IFTYPE_P2P_DEVICE: |
4568 | return "P2P_DEVICE"; | |
a1922f93 JM |
4569 | default: |
4570 | return "unknown"; | |
4571 | } | |
4572 | } | |
4573 | ||
4574 | ||
a35187e7 KH |
4575 | static int nl80211_create_iface_once(struct wpa_driver_nl80211_data *drv, |
4576 | const char *ifname, | |
4577 | enum nl80211_iftype iftype, | |
d6dcfcda DS |
4578 | const u8 *addr, int wds, |
4579 | int (*handler)(struct nl_msg *, void *), | |
4580 | void *arg) | |
0915d02c | 4581 | { |
8970bae8 | 4582 | struct nl_msg *msg; |
0915d02c JM |
4583 | int ifidx; |
4584 | int ret = -ENOBUFS; | |
4585 | ||
a1922f93 JM |
4586 | wpa_printf(MSG_DEBUG, "nl80211: Create interface iftype %d (%s)", |
4587 | iftype, nl80211_iftype_str(iftype)); | |
4588 | ||
56f77852 JM |
4589 | msg = nl80211_cmd_msg(drv->first_bss, 0, NL80211_CMD_NEW_INTERFACE); |
4590 | if (!msg || | |
a862e4a3 JM |
4591 | nla_put_string(msg, NL80211_ATTR_IFNAME, ifname) || |
4592 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, iftype)) | |
4593 | goto fail; | |
0915d02c JM |
4594 | |
4595 | if (iftype == NL80211_IFTYPE_MONITOR) { | |
8970bae8 | 4596 | struct nlattr *flags; |
0915d02c | 4597 | |
8970bae8 | 4598 | flags = nla_nest_start(msg, NL80211_ATTR_MNTR_FLAGS); |
a862e4a3 JM |
4599 | if (!flags || |
4600 | nla_put_flag(msg, NL80211_MNTR_FLAG_COOK_FRAMES)) | |
4601 | goto fail; | |
0915d02c | 4602 | |
8970bae8 | 4603 | nla_nest_end(msg, flags); |
fbbfcbac | 4604 | } else if (wds) { |
a862e4a3 JM |
4605 | if (nla_put_u8(msg, NL80211_ATTR_4ADDR, wds)) |
4606 | goto fail; | |
0915d02c JM |
4607 | } |
4608 | ||
52f5877a IP |
4609 | /* |
4610 | * Tell cfg80211 that the interface belongs to the socket that created | |
4611 | * it, and the interface should be deleted when the socket is closed. | |
4612 | */ | |
a862e4a3 JM |
4613 | if (nla_put_flag(msg, NL80211_ATTR_IFACE_SOCKET_OWNER)) |
4614 | goto fail; | |
52f5877a | 4615 | |
d6dcfcda | 4616 | ret = send_and_recv_msgs(drv, msg, handler, arg); |
5883168a | 4617 | msg = NULL; |
0915d02c | 4618 | if (ret) { |
a862e4a3 | 4619 | fail: |
5883168a | 4620 | nlmsg_free(msg); |
a35187e7 KH |
4621 | wpa_printf(MSG_ERROR, "Failed to create interface %s: %d (%s)", |
4622 | ifname, ret, strerror(-ret)); | |
0915d02c JM |
4623 | return ret; |
4624 | } | |
4625 | ||
f632e483 | 4626 | if (iftype == NL80211_IFTYPE_P2P_DEVICE) |
6bae92e0 | 4627 | return 0; |
6bae92e0 | 4628 | |
0915d02c | 4629 | ifidx = if_nametoindex(ifname); |
c6e8e8e4 JM |
4630 | wpa_printf(MSG_DEBUG, "nl80211: New interface %s created: ifindex=%d", |
4631 | ifname, ifidx); | |
0915d02c JM |
4632 | |
4633 | if (ifidx <= 0) | |
4634 | return -1; | |
4635 | ||
147848ec JM |
4636 | /* |
4637 | * Some virtual interfaces need to process EAPOL packets and events on | |
4638 | * the parent interface. This is used mainly with hostapd. | |
4639 | */ | |
4640 | if (drv->hostapd || | |
4641 | iftype == NL80211_IFTYPE_AP_VLAN || | |
4642 | iftype == NL80211_IFTYPE_WDS || | |
4643 | iftype == NL80211_IFTYPE_MONITOR) { | |
4644 | /* start listening for EAPOL on this interface */ | |
732b1d20 | 4645 | add_ifidx(drv, ifidx, IFIDX_ANY); |
147848ec | 4646 | } |
2135f224 | 4647 | |
7bfc47c3 | 4648 | if (addr && iftype != NL80211_IFTYPE_MONITOR && |
c81eff1a | 4649 | linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, addr)) { |
41d931ee JM |
4650 | nl80211_remove_iface(drv, ifidx); |
4651 | return -1; | |
2135f224 | 4652 | } |
2135f224 | 4653 | |
0915d02c JM |
4654 | return ifidx; |
4655 | } | |
22a7c9d7 JM |
4656 | |
4657 | ||
f3407c66 JM |
4658 | int nl80211_create_iface(struct wpa_driver_nl80211_data *drv, |
4659 | const char *ifname, enum nl80211_iftype iftype, | |
4660 | const u8 *addr, int wds, | |
4661 | int (*handler)(struct nl_msg *, void *), | |
4662 | void *arg, int use_existing) | |
a35187e7 KH |
4663 | { |
4664 | int ret; | |
4665 | ||
d6dcfcda DS |
4666 | ret = nl80211_create_iface_once(drv, ifname, iftype, addr, wds, handler, |
4667 | arg); | |
a35187e7 | 4668 | |
ffbf1eaa | 4669 | /* if error occurred and interface exists already */ |
a35187e7 | 4670 | if (ret == -ENFILE && if_nametoindex(ifname)) { |
2aec4f3c JM |
4671 | if (use_existing) { |
4672 | wpa_printf(MSG_DEBUG, "nl80211: Continue using existing interface %s", | |
4673 | ifname); | |
6997f8ba JM |
4674 | if (addr && iftype != NL80211_IFTYPE_MONITOR && |
4675 | linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, | |
4676 | addr) < 0 && | |
4677 | (linux_set_iface_flags(drv->global->ioctl_sock, | |
4678 | ifname, 0) < 0 || | |
4679 | linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, | |
4680 | addr) < 0 || | |
4681 | linux_set_iface_flags(drv->global->ioctl_sock, | |
4682 | ifname, 1) < 0)) | |
4683 | return -1; | |
2aec4f3c JM |
4684 | return -ENFILE; |
4685 | } | |
a35187e7 KH |
4686 | wpa_printf(MSG_INFO, "Try to remove and re-create %s", ifname); |
4687 | ||
4688 | /* Try to remove the interface that was already there. */ | |
4689 | nl80211_remove_iface(drv, if_nametoindex(ifname)); | |
4690 | ||
4691 | /* Try to create the interface again */ | |
fbbfcbac | 4692 | ret = nl80211_create_iface_once(drv, ifname, iftype, addr, |
d6dcfcda | 4693 | wds, handler, arg); |
a35187e7 KH |
4694 | } |
4695 | ||
3e208481 JM |
4696 | if (ret >= 0 && is_p2p_net_interface(iftype)) { |
4697 | wpa_printf(MSG_DEBUG, | |
4698 | "nl80211: Interface %s created for P2P - disable 11b rates", | |
4699 | ifname); | |
4e5cb1a3 | 4700 | nl80211_disable_11b_rates(drv, ret, 1); |
3e208481 | 4701 | } |
4e5cb1a3 | 4702 | |
a35187e7 KH |
4703 | return ret; |
4704 | } | |
0915d02c | 4705 | |
2135f224 | 4706 | |
3fd1cefb JB |
4707 | static int nl80211_setup_ap(struct i802_bss *bss) |
4708 | { | |
4709 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
4710 | ||
748c0ac0 JM |
4711 | wpa_printf(MSG_DEBUG, "nl80211: Setup AP(%s) - device_ap_sme=%d use_monitor=%d", |
4712 | bss->ifname, drv->device_ap_sme, drv->use_monitor); | |
36488c05 | 4713 | |
a11241fa JB |
4714 | /* |
4715 | * Disable Probe Request reporting unless we need it in this way for | |
4716 | * devices that include the AP SME, in the other case (unless using | |
4717 | * monitor iface) we'll get it through the nl_mgmt socket instead. | |
4718 | */ | |
4719 | if (!drv->device_ap_sme) | |
4720 | wpa_driver_nl80211_probe_req_report(bss, 0); | |
4721 | ||
4722 | if (!drv->device_ap_sme && !drv->use_monitor) | |
4723 | if (nl80211_mgmt_subscribe_ap(bss)) | |
4724 | return -1; | |
4725 | ||
a6cc0602 JM |
4726 | if (drv->device_ap_sme && !drv->use_monitor) |
4727 | if (nl80211_mgmt_subscribe_ap_dev_sme(bss)) | |
f4830bed RM |
4728 | wpa_printf(MSG_DEBUG, |
4729 | "nl80211: Failed to subscribe for mgmt frames from SME driver - trying to run without it"); | |
a6cc0602 | 4730 | |
a11241fa | 4731 | if (!drv->device_ap_sme && drv->use_monitor && |
ea19b39f RM |
4732 | nl80211_create_monitor_interface(drv) && |
4733 | !drv->device_ap_sme) | |
3fd1cefb JB |
4734 | return -1; |
4735 | ||
4736 | if (drv->device_ap_sme && | |
4737 | wpa_driver_nl80211_probe_req_report(bss, 1) < 0) { | |
4738 | wpa_printf(MSG_DEBUG, "nl80211: Failed to enable " | |
4739 | "Probe Request frame reporting in AP mode"); | |
4740 | /* Try to survive without this */ | |
4741 | } | |
4742 | ||
4743 | return 0; | |
4744 | } | |
4745 | ||
4746 | ||
4747 | static void nl80211_teardown_ap(struct i802_bss *bss) | |
4748 | { | |
4749 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
4750 | ||
748c0ac0 JM |
4751 | wpa_printf(MSG_DEBUG, "nl80211: Teardown AP(%s) - device_ap_sme=%d use_monitor=%d", |
4752 | bss->ifname, drv->device_ap_sme, drv->use_monitor); | |
a6cc0602 | 4753 | if (drv->device_ap_sme) { |
3fd1cefb | 4754 | wpa_driver_nl80211_probe_req_report(bss, 0); |
a6cc0602 JM |
4755 | if (!drv->use_monitor) |
4756 | nl80211_mgmt_unsubscribe(bss, "AP teardown (dev SME)"); | |
4757 | } else if (drv->use_monitor) | |
3fd1cefb | 4758 | nl80211_remove_monitor_interface(drv); |
a11241fa | 4759 | else |
36488c05 | 4760 | nl80211_mgmt_unsubscribe(bss, "AP teardown"); |
a11241fa | 4761 | |
a70cd0db | 4762 | nl80211_put_wiphy_data_ap(bss); |
3fd1cefb JB |
4763 | bss->beacon_set = 0; |
4764 | } | |
4765 | ||
4766 | ||
f10bfc9a JM |
4767 | static int nl80211_send_eapol_data(struct i802_bss *bss, |
4768 | const u8 *addr, const u8 *data, | |
d12dab4c | 4769 | size_t data_len) |
f10bfc9a | 4770 | { |
d12dab4c JB |
4771 | struct sockaddr_ll ll; |
4772 | int ret; | |
4773 | ||
4774 | if (bss->drv->eapol_tx_sock < 0) { | |
4775 | wpa_printf(MSG_DEBUG, "nl80211: No socket to send EAPOL"); | |
f10bfc9a JM |
4776 | return -1; |
4777 | } | |
4778 | ||
d12dab4c JB |
4779 | os_memset(&ll, 0, sizeof(ll)); |
4780 | ll.sll_family = AF_PACKET; | |
4781 | ll.sll_ifindex = bss->ifindex; | |
4782 | ll.sll_protocol = htons(ETH_P_PAE); | |
4783 | ll.sll_halen = ETH_ALEN; | |
4784 | os_memcpy(ll.sll_addr, addr, ETH_ALEN); | |
4785 | ret = sendto(bss->drv->eapol_tx_sock, data, data_len, 0, | |
4786 | (struct sockaddr *) &ll, sizeof(ll)); | |
4787 | if (ret < 0) | |
4788 | wpa_printf(MSG_ERROR, "nl80211: EAPOL TX: %s", | |
4789 | strerror(errno)); | |
4790 | ||
4791 | return ret; | |
f10bfc9a | 4792 | } |
5fb1a232 | 4793 | |
f10bfc9a | 4794 | |
db149ac9 JM |
4795 | static const u8 rfc1042_header[6] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 }; |
4796 | ||
4797 | static int wpa_driver_nl80211_hapd_send_eapol( | |
4798 | void *priv, const u8 *addr, const u8 *data, | |
4378fc14 | 4799 | size_t data_len, int encrypt, const u8 *own_addr, u32 flags) |
db149ac9 | 4800 | { |
a2e40bb6 FF |
4801 | struct i802_bss *bss = priv; |
4802 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
db149ac9 JM |
4803 | struct ieee80211_hdr *hdr; |
4804 | size_t len; | |
4805 | u8 *pos; | |
4806 | int res; | |
4378fc14 | 4807 | int qos = flags & WPA_STA_WMM; |
db149ac9 | 4808 | |
a11241fa | 4809 | if (drv->device_ap_sme || !drv->use_monitor) |
d12dab4c | 4810 | return nl80211_send_eapol_data(bss, addr, data, data_len); |
f10bfc9a | 4811 | |
db149ac9 JM |
4812 | len = sizeof(*hdr) + (qos ? 2 : 0) + sizeof(rfc1042_header) + 2 + |
4813 | data_len; | |
4814 | hdr = os_zalloc(len); | |
4815 | if (hdr == NULL) { | |
7ac3616d JM |
4816 | wpa_printf(MSG_INFO, "nl80211: Failed to allocate EAPOL buffer(len=%lu)", |
4817 | (unsigned long) len); | |
db149ac9 JM |
4818 | return -1; |
4819 | } | |
4820 | ||
4821 | hdr->frame_control = | |
4822 | IEEE80211_FC(WLAN_FC_TYPE_DATA, WLAN_FC_STYPE_DATA); | |
4823 | hdr->frame_control |= host_to_le16(WLAN_FC_FROMDS); | |
4824 | if (encrypt) | |
4825 | hdr->frame_control |= host_to_le16(WLAN_FC_ISWEP); | |
db149ac9 JM |
4826 | if (qos) { |
4827 | hdr->frame_control |= | |
4828 | host_to_le16(WLAN_FC_STYPE_QOS_DATA << 4); | |
4829 | } | |
db149ac9 JM |
4830 | |
4831 | memcpy(hdr->IEEE80211_DA_FROMDS, addr, ETH_ALEN); | |
4832 | memcpy(hdr->IEEE80211_BSSID_FROMDS, own_addr, ETH_ALEN); | |
4833 | memcpy(hdr->IEEE80211_SA_FROMDS, own_addr, ETH_ALEN); | |
4834 | pos = (u8 *) (hdr + 1); | |
4835 | ||
db149ac9 | 4836 | if (qos) { |
92d521d8 FF |
4837 | /* Set highest priority in QoS header */ |
4838 | pos[0] = 7; | |
db149ac9 JM |
4839 | pos[1] = 0; |
4840 | pos += 2; | |
4841 | } | |
db149ac9 JM |
4842 | |
4843 | memcpy(pos, rfc1042_header, sizeof(rfc1042_header)); | |
4844 | pos += sizeof(rfc1042_header); | |
4845 | WPA_PUT_BE16(pos, ETH_P_PAE); | |
4846 | pos += 2; | |
4847 | memcpy(pos, data, data_len); | |
4848 | ||
55231068 | 4849 | res = wpa_driver_nl80211_send_frame(bss, (u8 *) hdr, len, encrypt, 0, |
2d3943ce | 4850 | 0, 0, 0, 0, NULL, 0); |
db149ac9 JM |
4851 | if (res < 0) { |
4852 | wpa_printf(MSG_ERROR, "i802_send_eapol - packet len: %lu - " | |
4853 | "failed: %d (%s)", | |
4854 | (unsigned long) len, errno, strerror(errno)); | |
4855 | } | |
7bf12757 | 4856 | os_free(hdr); |
db149ac9 JM |
4857 | |
4858 | return res; | |
4859 | } | |
4860 | ||
a8d6ffa4 | 4861 | |
3234cba4 | 4862 | static int wpa_driver_nl80211_sta_set_flags(void *priv, const u8 *addr, |
f97e3ce4 JM |
4863 | unsigned int total_flags, |
4864 | unsigned int flags_or, | |
4865 | unsigned int flags_and) | |
a8d6ffa4 | 4866 | { |
a2e40bb6 | 4867 | struct i802_bss *bss = priv; |
8970bae8 JB |
4868 | struct nl_msg *msg; |
4869 | struct nlattr *flags; | |
7e76ee9c | 4870 | struct nl80211_sta_flag_update upd; |
a8d6ffa4 | 4871 | |
0cd9846c JM |
4872 | wpa_printf(MSG_DEBUG, "nl80211: Set STA flags - ifname=%s addr=" MACSTR |
4873 | " total_flags=0x%x flags_or=0x%x flags_and=0x%x authorized=%d", | |
4874 | bss->ifname, MAC2STR(addr), total_flags, flags_or, flags_and, | |
4875 | !!(total_flags & WPA_STA_AUTHORIZED)); | |
4876 | ||
13f83980 | 4877 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) || |
a862e4a3 JM |
4878 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
4879 | goto fail; | |
a8d6ffa4 | 4880 | |
7e76ee9c JM |
4881 | /* |
4882 | * Backwards compatibility version using NL80211_ATTR_STA_FLAGS. This | |
4883 | * can be removed eventually. | |
4884 | */ | |
8970bae8 | 4885 | flags = nla_nest_start(msg, NL80211_ATTR_STA_FLAGS); |
a862e4a3 JM |
4886 | if (!flags || |
4887 | ((total_flags & WPA_STA_AUTHORIZED) && | |
4888 | nla_put_flag(msg, NL80211_STA_FLAG_AUTHORIZED)) || | |
4889 | ((total_flags & WPA_STA_WMM) && | |
4890 | nla_put_flag(msg, NL80211_STA_FLAG_WME)) || | |
4891 | ((total_flags & WPA_STA_SHORT_PREAMBLE) && | |
4892 | nla_put_flag(msg, NL80211_STA_FLAG_SHORT_PREAMBLE)) || | |
4893 | ((total_flags & WPA_STA_MFP) && | |
4894 | nla_put_flag(msg, NL80211_STA_FLAG_MFP)) || | |
4895 | ((total_flags & WPA_STA_TDLS_PEER) && | |
4896 | nla_put_flag(msg, NL80211_STA_FLAG_TDLS_PEER))) | |
4897 | goto fail; | |
45b722f1 | 4898 | |
8970bae8 | 4899 | nla_nest_end(msg, flags); |
a8d6ffa4 | 4900 | |
7e76ee9c JM |
4901 | os_memset(&upd, 0, sizeof(upd)); |
4902 | upd.mask = sta_flags_nl80211(flags_or | ~flags_and); | |
4903 | upd.set = sta_flags_nl80211(flags_or); | |
a862e4a3 JM |
4904 | if (nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd)) |
4905 | goto fail; | |
7e76ee9c | 4906 | |
13f83980 | 4907 | return send_and_recv_msgs(bss->drv, msg, NULL, NULL); |
a862e4a3 | 4908 | fail: |
5883168a | 4909 | nlmsg_free(msg); |
a8d6ffa4 JM |
4910 | return -ENOBUFS; |
4911 | } | |
4912 | ||
0915d02c | 4913 | |
1581b38b JM |
4914 | static int wpa_driver_nl80211_ap(struct wpa_driver_nl80211_data *drv, |
4915 | struct wpa_driver_associate_params *params) | |
4916 | { | |
708bc8e0 | 4917 | enum nl80211_iftype nlmode, old_mode; |
b1f625e0 EP |
4918 | |
4919 | if (params->p2p) { | |
046b26a2 JM |
4920 | wpa_printf(MSG_DEBUG, "nl80211: Setup AP operations for P2P " |
4921 | "group (GO)"); | |
b1f625e0 EP |
4922 | nlmode = NL80211_IFTYPE_P2P_GO; |
4923 | } else | |
4924 | nlmode = NL80211_IFTYPE_AP; | |
4925 | ||
708bc8e0 | 4926 | old_mode = drv->nlmode; |
834ee56f | 4927 | if (wpa_driver_nl80211_set_mode(drv->first_bss, nlmode)) { |
708bc8e0 JM |
4928 | nl80211_remove_monitor_interface(drv); |
4929 | return -1; | |
4930 | } | |
4931 | ||
6e9023ea JM |
4932 | if (params->freq.freq && |
4933 | nl80211_set_channel(drv->first_bss, ¶ms->freq, 0)) { | |
708bc8e0 | 4934 | if (old_mode != nlmode) |
834ee56f | 4935 | wpa_driver_nl80211_set_mode(drv->first_bss, old_mode); |
460456f8 | 4936 | nl80211_remove_monitor_interface(drv); |
1581b38b | 4937 | return -1; |
0915d02c | 4938 | } |
1581b38b | 4939 | |
1581b38b JM |
4940 | return 0; |
4941 | } | |
1581b38b JM |
4942 | |
4943 | ||
666e508c JM |
4944 | static int nl80211_leave_ibss(struct wpa_driver_nl80211_data *drv, |
4945 | int reset_mode) | |
5cc4d64b JM |
4946 | { |
4947 | struct nl_msg *msg; | |
9725b784 | 4948 | int ret; |
a862e4a3 | 4949 | |
9725b784 | 4950 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_LEAVE_IBSS); |
5cc4d64b | 4951 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
5cc4d64b JM |
4952 | if (ret) { |
4953 | wpa_printf(MSG_DEBUG, "nl80211: Leave IBSS failed: ret=%d " | |
4954 | "(%s)", ret, strerror(-ret)); | |
9725b784 JM |
4955 | } else { |
4956 | wpa_printf(MSG_DEBUG, | |
4957 | "nl80211: Leave IBSS request sent successfully"); | |
5cc4d64b JM |
4958 | } |
4959 | ||
666e508c JM |
4960 | if (reset_mode && |
4961 | wpa_driver_nl80211_set_mode(drv->first_bss, | |
5d4c78fb JM |
4962 | NL80211_IFTYPE_STATION)) { |
4963 | wpa_printf(MSG_INFO, "nl80211: Failed to set interface into " | |
4964 | "station mode"); | |
4965 | } | |
4966 | ||
5cc4d64b JM |
4967 | return ret; |
4968 | } | |
4969 | ||
4970 | ||
95ff3069 JD |
4971 | static int nl80211_ht_vht_overrides(struct nl_msg *msg, |
4972 | struct wpa_driver_associate_params *params) | |
4973 | { | |
4974 | if (params->disable_ht && nla_put_flag(msg, NL80211_ATTR_DISABLE_HT)) | |
4975 | return -1; | |
4976 | ||
4977 | if (params->htcaps && params->htcaps_mask) { | |
4978 | int sz = sizeof(struct ieee80211_ht_capabilities); | |
4979 | wpa_hexdump(MSG_DEBUG, " * htcaps", params->htcaps, sz); | |
4980 | wpa_hexdump(MSG_DEBUG, " * htcaps_mask", | |
4981 | params->htcaps_mask, sz); | |
4982 | if (nla_put(msg, NL80211_ATTR_HT_CAPABILITY, sz, | |
4983 | params->htcaps) || | |
4984 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, sz, | |
4985 | params->htcaps_mask)) | |
4986 | return -1; | |
4987 | } | |
4988 | ||
4989 | #ifdef CONFIG_VHT_OVERRIDES | |
4990 | if (params->disable_vht) { | |
4991 | wpa_printf(MSG_DEBUG, " * VHT disabled"); | |
4992 | if (nla_put_flag(msg, NL80211_ATTR_DISABLE_VHT)) | |
4993 | return -1; | |
4994 | } | |
4995 | ||
4996 | if (params->vhtcaps && params->vhtcaps_mask) { | |
4997 | int sz = sizeof(struct ieee80211_vht_capabilities); | |
4998 | wpa_hexdump(MSG_DEBUG, " * vhtcaps", params->vhtcaps, sz); | |
4999 | wpa_hexdump(MSG_DEBUG, " * vhtcaps_mask", | |
5000 | params->vhtcaps_mask, sz); | |
5001 | if (nla_put(msg, NL80211_ATTR_VHT_CAPABILITY, sz, | |
5002 | params->vhtcaps) || | |
5003 | nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, sz, | |
5004 | params->vhtcaps_mask)) | |
5005 | return -1; | |
5006 | } | |
5007 | #endif /* CONFIG_VHT_OVERRIDES */ | |
5008 | ||
5009 | return 0; | |
5010 | } | |
5011 | ||
5012 | ||
5cc4d64b JM |
5013 | static int wpa_driver_nl80211_ibss(struct wpa_driver_nl80211_data *drv, |
5014 | struct wpa_driver_associate_params *params) | |
5015 | { | |
5016 | struct nl_msg *msg; | |
5017 | int ret = -1; | |
5018 | int count = 0; | |
5019 | ||
5020 | wpa_printf(MSG_DEBUG, "nl80211: Join IBSS (ifindex=%d)", drv->ifindex); | |
5021 | ||
4ec68377 | 5022 | if (wpa_driver_nl80211_set_mode_ibss(drv->first_bss, ¶ms->freq)) { |
5cc4d64b JM |
5023 | wpa_printf(MSG_INFO, "nl80211: Failed to set interface into " |
5024 | "IBSS mode"); | |
5025 | return -1; | |
5026 | } | |
5027 | ||
5028 | retry: | |
9725b784 | 5029 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_JOIN_IBSS)) || |
a862e4a3 JM |
5030 | params->ssid == NULL || params->ssid_len > sizeof(drv->ssid)) |
5031 | goto fail; | |
5cc4d64b JM |
5032 | |
5033 | wpa_hexdump_ascii(MSG_DEBUG, " * SSID", | |
5034 | params->ssid, params->ssid_len); | |
a862e4a3 JM |
5035 | if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid)) |
5036 | goto fail; | |
5cc4d64b JM |
5037 | os_memcpy(drv->ssid, params->ssid, params->ssid_len); |
5038 | drv->ssid_len = params->ssid_len; | |
5039 | ||
85e1fad8 JM |
5040 | if (nl80211_put_freq_params(msg, ¶ms->freq) < 0 || |
5041 | nl80211_put_beacon_int(msg, params->beacon_int)) | |
a862e4a3 | 5042 | goto fail; |
5cc4d64b JM |
5043 | |
5044 | ret = nl80211_set_conn_keys(params, msg); | |
5045 | if (ret) | |
a862e4a3 | 5046 | goto fail; |
5cc4d64b | 5047 | |
913e3cf7 NC |
5048 | if (params->bssid && params->fixed_bssid) { |
5049 | wpa_printf(MSG_DEBUG, " * BSSID=" MACSTR, | |
5050 | MAC2STR(params->bssid)); | |
a862e4a3 JM |
5051 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid)) |
5052 | goto fail; | |
913e3cf7 NC |
5053 | } |
5054 | ||
4d9e6fba JD |
5055 | if (params->fixed_freq) { |
5056 | wpa_printf(MSG_DEBUG, " * fixed_freq"); | |
5057 | if (nla_put_flag(msg, NL80211_ATTR_FREQ_FIXED)) | |
5058 | goto fail; | |
5059 | } | |
5060 | ||
4848a38d JM |
5061 | if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X || |
5062 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK || | |
5063 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SHA256 || | |
5064 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256) { | |
e640888c | 5065 | wpa_printf(MSG_DEBUG, " * control port"); |
a862e4a3 JM |
5066 | if (nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT)) |
5067 | goto fail; | |
e640888c AQ |
5068 | } |
5069 | ||
a95795ad JM |
5070 | if (params->wpa_ie) { |
5071 | wpa_hexdump(MSG_DEBUG, | |
5072 | " * Extra IEs for Beacon/Probe Response frames", | |
5073 | params->wpa_ie, params->wpa_ie_len); | |
a862e4a3 JM |
5074 | if (nla_put(msg, NL80211_ATTR_IE, params->wpa_ie_len, |
5075 | params->wpa_ie)) | |
5076 | goto fail; | |
a95795ad JM |
5077 | } |
5078 | ||
e15dcf6d PK |
5079 | ret = nl80211_ht_vht_overrides(msg, params); |
5080 | if (ret < 0) | |
5081 | goto fail; | |
95ff3069 | 5082 | |
5cc4d64b JM |
5083 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
5084 | msg = NULL; | |
5085 | if (ret) { | |
5086 | wpa_printf(MSG_DEBUG, "nl80211: Join IBSS failed: ret=%d (%s)", | |
5087 | ret, strerror(-ret)); | |
5088 | count++; | |
5089 | if (ret == -EALREADY && count == 1) { | |
5090 | wpa_printf(MSG_DEBUG, "nl80211: Retry IBSS join after " | |
5091 | "forced leave"); | |
666e508c | 5092 | nl80211_leave_ibss(drv, 0); |
5cc4d64b JM |
5093 | nlmsg_free(msg); |
5094 | goto retry; | |
5095 | } | |
a862e4a3 JM |
5096 | } else { |
5097 | wpa_printf(MSG_DEBUG, | |
5098 | "nl80211: Join IBSS request sent successfully"); | |
5cc4d64b | 5099 | } |
5cc4d64b | 5100 | |
a862e4a3 | 5101 | fail: |
5cc4d64b JM |
5102 | nlmsg_free(msg); |
5103 | return ret; | |
5104 | } | |
5105 | ||
5106 | ||
ad295f3b VK |
5107 | static int nl80211_put_fils_connect_params(struct wpa_driver_nl80211_data *drv, |
5108 | struct wpa_driver_associate_params *params, | |
5109 | struct nl_msg *msg) | |
5110 | { | |
5111 | if (params->fils_erp_username_len) { | |
5112 | wpa_hexdump_ascii(MSG_DEBUG, " * FILS ERP EMSKname/username", | |
5113 | params->fils_erp_username, | |
5114 | params->fils_erp_username_len); | |
5115 | if (nla_put(msg, NL80211_ATTR_FILS_ERP_USERNAME, | |
5116 | params->fils_erp_username_len, | |
5117 | params->fils_erp_username)) | |
5118 | return -1; | |
5119 | } | |
5120 | ||
5121 | if (params->fils_erp_realm_len) { | |
5122 | wpa_hexdump_ascii(MSG_DEBUG, " * FILS ERP Realm", | |
5123 | params->fils_erp_realm, | |
5124 | params->fils_erp_realm_len); | |
5125 | if (nla_put(msg, NL80211_ATTR_FILS_ERP_REALM, | |
5126 | params->fils_erp_realm_len, params->fils_erp_realm)) | |
5127 | return -1; | |
5128 | } | |
5129 | ||
5130 | wpa_printf(MSG_DEBUG, " * FILS ERP next seq %u", | |
5131 | params->fils_erp_next_seq_num); | |
5132 | if (nla_put_u16(msg, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM, | |
5133 | params->fils_erp_next_seq_num)) | |
5134 | return -1; | |
5135 | ||
5136 | if (params->fils_erp_rrk_len) { | |
5137 | wpa_printf(MSG_DEBUG, " * FILS ERP rRK (len=%lu)", | |
5138 | (unsigned long) params->fils_erp_rrk_len); | |
5139 | if (nla_put(msg, NL80211_ATTR_FILS_ERP_RRK, | |
5140 | params->fils_erp_rrk_len, params->fils_erp_rrk)) | |
5141 | return -1; | |
5142 | } | |
5143 | ||
5144 | return 0; | |
5145 | } | |
5146 | ||
5147 | ||
a0bdd191 JM |
5148 | static int nl80211_connect_common(struct wpa_driver_nl80211_data *drv, |
5149 | struct wpa_driver_associate_params *params, | |
5150 | struct nl_msg *msg) | |
cfaab580 | 5151 | { |
c85dfc6f JM |
5152 | if (nla_put_flag(msg, NL80211_ATTR_IFACE_SOCKET_OWNER)) |
5153 | return -1; | |
5154 | ||
cfaab580 ZY |
5155 | if (params->bssid) { |
5156 | wpa_printf(MSG_DEBUG, " * bssid=" MACSTR, | |
5157 | MAC2STR(params->bssid)); | |
a862e4a3 JM |
5158 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid)) |
5159 | return -1; | |
cfaab580 | 5160 | } |
a0bdd191 | 5161 | |
7ac7fd43 DS |
5162 | if (params->bssid_hint) { |
5163 | wpa_printf(MSG_DEBUG, " * bssid_hint=" MACSTR, | |
5164 | MAC2STR(params->bssid_hint)); | |
a862e4a3 JM |
5165 | if (nla_put(msg, NL80211_ATTR_MAC_HINT, ETH_ALEN, |
5166 | params->bssid_hint)) | |
5167 | return -1; | |
7ac7fd43 DS |
5168 | } |
5169 | ||
4ec68377 JD |
5170 | if (params->freq.freq) { |
5171 | wpa_printf(MSG_DEBUG, " * freq=%d", params->freq.freq); | |
a862e4a3 JM |
5172 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
5173 | params->freq.freq)) | |
5174 | return -1; | |
4ec68377 | 5175 | drv->assoc_freq = params->freq.freq; |
30158a0d SD |
5176 | } else |
5177 | drv->assoc_freq = 0; | |
a0bdd191 | 5178 | |
7ac7fd43 DS |
5179 | if (params->freq_hint) { |
5180 | wpa_printf(MSG_DEBUG, " * freq_hint=%d", params->freq_hint); | |
a862e4a3 JM |
5181 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ_HINT, |
5182 | params->freq_hint)) | |
5183 | return -1; | |
7ac7fd43 DS |
5184 | } |
5185 | ||
1f6c0ab8 BS |
5186 | if (params->bg_scan_period >= 0) { |
5187 | wpa_printf(MSG_DEBUG, " * bg scan period=%d", | |
5188 | params->bg_scan_period); | |
a862e4a3 JM |
5189 | if (nla_put_u16(msg, NL80211_ATTR_BG_SCAN_PERIOD, |
5190 | params->bg_scan_period)) | |
5191 | return -1; | |
1f6c0ab8 | 5192 | } |
a0bdd191 | 5193 | |
cfaab580 ZY |
5194 | if (params->ssid) { |
5195 | wpa_hexdump_ascii(MSG_DEBUG, " * SSID", | |
5196 | params->ssid, params->ssid_len); | |
a862e4a3 JM |
5197 | if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, |
5198 | params->ssid)) | |
5199 | return -1; | |
cfaab580 | 5200 | if (params->ssid_len > sizeof(drv->ssid)) |
a862e4a3 | 5201 | return -1; |
cfaab580 ZY |
5202 | os_memcpy(drv->ssid, params->ssid, params->ssid_len); |
5203 | drv->ssid_len = params->ssid_len; | |
5204 | } | |
a0bdd191 | 5205 | |
cfaab580 | 5206 | wpa_hexdump(MSG_DEBUG, " * IEs", params->wpa_ie, params->wpa_ie_len); |
a862e4a3 JM |
5207 | if (params->wpa_ie && |
5208 | nla_put(msg, NL80211_ATTR_IE, params->wpa_ie_len, params->wpa_ie)) | |
5209 | return -1; | |
cfaab580 | 5210 | |
64fa840a JM |
5211 | if (params->wpa_proto) { |
5212 | enum nl80211_wpa_versions ver = 0; | |
cfaab580 | 5213 | |
64fa840a JM |
5214 | if (params->wpa_proto & WPA_PROTO_WPA) |
5215 | ver |= NL80211_WPA_VERSION_1; | |
5216 | if (params->wpa_proto & WPA_PROTO_RSN) | |
5217 | ver |= NL80211_WPA_VERSION_2; | |
cfaab580 | 5218 | |
64fa840a | 5219 | wpa_printf(MSG_DEBUG, " * WPA Versions 0x%x", ver); |
a862e4a3 JM |
5220 | if (nla_put_u32(msg, NL80211_ATTR_WPA_VERSIONS, ver)) |
5221 | return -1; | |
cfaab580 ZY |
5222 | } |
5223 | ||
4848a38d | 5224 | if (params->pairwise_suite != WPA_CIPHER_NONE) { |
a0bdd191 JM |
5225 | u32 cipher = wpa_cipher_to_cipher_suite(params->pairwise_suite); |
5226 | wpa_printf(MSG_DEBUG, " * pairwise=0x%x", cipher); | |
a862e4a3 JM |
5227 | if (nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITES_PAIRWISE, |
5228 | cipher)) | |
5229 | return -1; | |
cfaab580 ZY |
5230 | } |
5231 | ||
ae6f9272 JM |
5232 | if (params->group_suite == WPA_CIPHER_GTK_NOT_USED && |
5233 | !(drv->capa.enc & WPA_DRIVER_CAPA_ENC_GTK_NOT_USED)) { | |
5234 | /* | |
5235 | * This is likely to work even though many drivers do not | |
5236 | * advertise support for operations without GTK. | |
5237 | */ | |
5238 | wpa_printf(MSG_DEBUG, " * skip group cipher configuration for GTK_NOT_USED due to missing driver support advertisement"); | |
5239 | } else if (params->group_suite != WPA_CIPHER_NONE) { | |
a0bdd191 JM |
5240 | u32 cipher = wpa_cipher_to_cipher_suite(params->group_suite); |
5241 | wpa_printf(MSG_DEBUG, " * group=0x%x", cipher); | |
a862e4a3 JM |
5242 | if (nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, cipher)) |
5243 | return -1; | |
cfaab580 ZY |
5244 | } |
5245 | ||
4848a38d JM |
5246 | if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X || |
5247 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK || | |
5248 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_IEEE8021X || | |
5249 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_PSK || | |
163f801e | 5250 | params->key_mgmt_suite == WPA_KEY_MGMT_CCKM || |
8802326f JJ |
5251 | params->key_mgmt_suite == WPA_KEY_MGMT_OSEN || |
5252 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SHA256 || | |
666497c8 | 5253 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256 || |
5e3b5197 | 5254 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SUITE_B || |
ad295f3b VK |
5255 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SUITE_B_192 || |
5256 | params->key_mgmt_suite == WPA_KEY_MGMT_FILS_SHA256 || | |
5257 | params->key_mgmt_suite == WPA_KEY_MGMT_FILS_SHA384 || | |
5258 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_FILS_SHA256 || | |
5259 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_FILS_SHA384) { | |
3aa24db9 | 5260 | int mgmt = RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X; |
cfaab580 ZY |
5261 | |
5262 | switch (params->key_mgmt_suite) { | |
4848a38d | 5263 | case WPA_KEY_MGMT_CCKM: |
3aa24db9 | 5264 | mgmt = RSN_AUTH_KEY_MGMT_CCKM; |
369c8d7b | 5265 | break; |
4848a38d | 5266 | case WPA_KEY_MGMT_IEEE8021X: |
3aa24db9 | 5267 | mgmt = RSN_AUTH_KEY_MGMT_UNSPEC_802_1X; |
cfaab580 | 5268 | break; |
4848a38d | 5269 | case WPA_KEY_MGMT_FT_IEEE8021X: |
3aa24db9 | 5270 | mgmt = RSN_AUTH_KEY_MGMT_FT_802_1X; |
6a1ce395 | 5271 | break; |
4848a38d | 5272 | case WPA_KEY_MGMT_FT_PSK: |
3aa24db9 | 5273 | mgmt = RSN_AUTH_KEY_MGMT_FT_PSK; |
6a1ce395 | 5274 | break; |
8802326f | 5275 | case WPA_KEY_MGMT_IEEE8021X_SHA256: |
3aa24db9 | 5276 | mgmt = RSN_AUTH_KEY_MGMT_802_1X_SHA256; |
8802326f JJ |
5277 | break; |
5278 | case WPA_KEY_MGMT_PSK_SHA256: | |
3aa24db9 | 5279 | mgmt = RSN_AUTH_KEY_MGMT_PSK_SHA256; |
8802326f | 5280 | break; |
163f801e | 5281 | case WPA_KEY_MGMT_OSEN: |
3aa24db9 | 5282 | mgmt = RSN_AUTH_KEY_MGMT_OSEN; |
163f801e | 5283 | break; |
666497c8 | 5284 | case WPA_KEY_MGMT_IEEE8021X_SUITE_B: |
3aa24db9 | 5285 | mgmt = RSN_AUTH_KEY_MGMT_802_1X_SUITE_B; |
666497c8 | 5286 | break; |
5e3b5197 | 5287 | case WPA_KEY_MGMT_IEEE8021X_SUITE_B_192: |
3aa24db9 | 5288 | mgmt = RSN_AUTH_KEY_MGMT_802_1X_SUITE_B_192; |
5e3b5197 | 5289 | break; |
ad295f3b VK |
5290 | case WPA_KEY_MGMT_FILS_SHA256: |
5291 | mgmt = RSN_AUTH_KEY_MGMT_FILS_SHA256; | |
5292 | break; | |
5293 | case WPA_KEY_MGMT_FILS_SHA384: | |
5294 | mgmt = RSN_AUTH_KEY_MGMT_FILS_SHA384; | |
5295 | break; | |
5296 | case WPA_KEY_MGMT_FT_FILS_SHA256: | |
5297 | mgmt = RSN_AUTH_KEY_MGMT_FT_FILS_SHA256; | |
5298 | break; | |
5299 | case WPA_KEY_MGMT_FT_FILS_SHA384: | |
5300 | mgmt = RSN_AUTH_KEY_MGMT_FT_FILS_SHA384; | |
5301 | break; | |
4848a38d | 5302 | case WPA_KEY_MGMT_PSK: |
cfaab580 | 5303 | default: |
3aa24db9 | 5304 | mgmt = RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X; |
cfaab580 ZY |
5305 | break; |
5306 | } | |
163f801e | 5307 | wpa_printf(MSG_DEBUG, " * akm=0x%x", mgmt); |
a862e4a3 JM |
5308 | if (nla_put_u32(msg, NL80211_ATTR_AKM_SUITES, mgmt)) |
5309 | return -1; | |
cfaab580 ZY |
5310 | } |
5311 | ||
a862e4a3 JM |
5312 | if (nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT)) |
5313 | return -1; | |
a0bdd191 | 5314 | |
e3429c0b JB |
5315 | if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_NO_WPA && |
5316 | (params->pairwise_suite == WPA_CIPHER_NONE || | |
5317 | params->pairwise_suite == WPA_CIPHER_WEP104 || | |
5318 | params->pairwise_suite == WPA_CIPHER_WEP40) && | |
5319 | (nla_put_u16(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE, ETH_P_PAE) || | |
5320 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT))) | |
5321 | return -1; | |
5322 | ||
a862e4a3 JM |
5323 | if (params->mgmt_frame_protection == MGMT_FRAME_PROTECTION_REQUIRED && |
5324 | nla_put_u32(msg, NL80211_ATTR_USE_MFP, NL80211_MFP_REQUIRED)) | |
5325 | return -1; | |
a565084f | 5326 | |
58162adf AK |
5327 | if (params->rrm_used) { |
5328 | u32 drv_rrm_flags = drv->capa.rrm_flags; | |
b5d172e5 BL |
5329 | if ((!((drv_rrm_flags & |
5330 | WPA_DRIVER_FLAGS_DS_PARAM_SET_IE_IN_PROBES) && | |
5331 | (drv_rrm_flags & WPA_DRIVER_FLAGS_QUIET)) && | |
5332 | !(drv_rrm_flags & WPA_DRIVER_FLAGS_SUPPORT_RRM)) || | |
a862e4a3 JM |
5333 | nla_put_flag(msg, NL80211_ATTR_USE_RRM)) |
5334 | return -1; | |
58162adf AK |
5335 | } |
5336 | ||
95ff3069 | 5337 | if (nl80211_ht_vht_overrides(msg, params) < 0) |
a862e4a3 | 5338 | return -1; |
80e8a5ee | 5339 | |
a0bdd191 JM |
5340 | if (params->p2p) |
5341 | wpa_printf(MSG_DEBUG, " * P2P group"); | |
5342 | ||
86b5c400 LD |
5343 | if (params->pbss) { |
5344 | wpa_printf(MSG_DEBUG, " * PBSS"); | |
5345 | if (nla_put_flag(msg, NL80211_ATTR_PBSS)) | |
5346 | return -1; | |
5347 | } | |
5348 | ||
1126c078 | 5349 | drv->connect_reassoc = 0; |
00c3c4ac JM |
5350 | if (params->prev_bssid) { |
5351 | wpa_printf(MSG_DEBUG, " * prev_bssid=" MACSTR, | |
5352 | MAC2STR(params->prev_bssid)); | |
5353 | if (nla_put(msg, NL80211_ATTR_PREV_BSSID, ETH_ALEN, | |
5354 | params->prev_bssid)) | |
5355 | return -1; | |
1126c078 | 5356 | drv->connect_reassoc = 1; |
00c3c4ac JM |
5357 | } |
5358 | ||
ad295f3b VK |
5359 | if ((params->auth_alg & WPA_AUTH_ALG_FILS) && |
5360 | nl80211_put_fils_connect_params(drv, params, msg) != 0) | |
5361 | return -1; | |
5362 | ||
a0bdd191 | 5363 | return 0; |
a0bdd191 JM |
5364 | } |
5365 | ||
5366 | ||
5367 | static int wpa_driver_nl80211_try_connect( | |
5368 | struct wpa_driver_nl80211_data *drv, | |
5369 | struct wpa_driver_associate_params *params) | |
5370 | { | |
5371 | struct nl_msg *msg; | |
5372 | enum nl80211_auth_type type; | |
5373 | int ret; | |
5374 | int algs; | |
5375 | ||
b658547d | 5376 | #ifdef CONFIG_DRIVER_NL80211_QCA |
b41f2684 CL |
5377 | if (params->req_key_mgmt_offload && params->psk && |
5378 | (params->key_mgmt_suite == WPA_KEY_MGMT_PSK || | |
5379 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256 || | |
5380 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_PSK)) { | |
5381 | wpa_printf(MSG_DEBUG, "nl80211: Key management set PSK"); | |
5382 | ret = issue_key_mgmt_set_key(drv, params->psk, 32); | |
5383 | if (ret) | |
5384 | return ret; | |
5385 | } | |
b658547d | 5386 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
b41f2684 | 5387 | |
9725b784 JM |
5388 | wpa_printf(MSG_DEBUG, "nl80211: Connect (ifindex=%d)", drv->ifindex); |
5389 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_CONNECT); | |
a0bdd191 JM |
5390 | if (!msg) |
5391 | return -1; | |
5392 | ||
a0bdd191 JM |
5393 | ret = nl80211_connect_common(drv, params, msg); |
5394 | if (ret) | |
a862e4a3 | 5395 | goto fail; |
a0bdd191 JM |
5396 | |
5397 | algs = 0; | |
5398 | if (params->auth_alg & WPA_AUTH_ALG_OPEN) | |
5399 | algs++; | |
5400 | if (params->auth_alg & WPA_AUTH_ALG_SHARED) | |
5401 | algs++; | |
5402 | if (params->auth_alg & WPA_AUTH_ALG_LEAP) | |
5403 | algs++; | |
64a0a75b JM |
5404 | if (params->auth_alg & WPA_AUTH_ALG_FILS) |
5405 | algs++; | |
a0bdd191 JM |
5406 | if (algs > 1) { |
5407 | wpa_printf(MSG_DEBUG, " * Leave out Auth Type for automatic " | |
5408 | "selection"); | |
5409 | goto skip_auth_type; | |
5410 | } | |
5411 | ||
3c67e977 | 5412 | type = get_nl_auth_type(params->auth_alg); |
a0bdd191 | 5413 | wpa_printf(MSG_DEBUG, " * Auth Type %d", type); |
3c67e977 VK |
5414 | if (type == NL80211_AUTHTYPE_MAX || |
5415 | nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, type)) | |
a862e4a3 | 5416 | goto fail; |
a0bdd191 JM |
5417 | |
5418 | skip_auth_type: | |
cfaab580 ZY |
5419 | ret = nl80211_set_conn_keys(params, msg); |
5420 | if (ret) | |
a862e4a3 | 5421 | goto fail; |
cfaab580 ZY |
5422 | |
5423 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
5424 | msg = NULL; | |
5425 | if (ret) { | |
5426 | wpa_printf(MSG_DEBUG, "nl80211: MLME connect failed: ret=%d " | |
5427 | "(%s)", ret, strerror(-ret)); | |
a862e4a3 JM |
5428 | } else { |
5429 | wpa_printf(MSG_DEBUG, | |
5430 | "nl80211: Connect request send successfully"); | |
cfaab580 | 5431 | } |
cfaab580 | 5432 | |
a862e4a3 | 5433 | fail: |
cfaab580 ZY |
5434 | nlmsg_free(msg); |
5435 | return ret; | |
5436 | ||
5437 | } | |
5438 | ||
5439 | ||
a8c5b43a CW |
5440 | static int wpa_driver_nl80211_connect( |
5441 | struct wpa_driver_nl80211_data *drv, | |
5442 | struct wpa_driver_associate_params *params) | |
5443 | { | |
0d4e3d1d JJ |
5444 | int ret; |
5445 | ||
5446 | /* Store the connection attempted bssid for future use */ | |
5447 | if (params->bssid) | |
5448 | os_memcpy(drv->auth_attempt_bssid, params->bssid, ETH_ALEN); | |
5449 | else | |
5450 | os_memset(drv->auth_attempt_bssid, 0, ETH_ALEN); | |
5451 | ||
5452 | ret = wpa_driver_nl80211_try_connect(drv, params); | |
a8c5b43a CW |
5453 | if (ret == -EALREADY) { |
5454 | /* | |
5455 | * cfg80211 does not currently accept new connections if | |
5456 | * we are already connected. As a workaround, force | |
5457 | * disconnection and try again. | |
5458 | */ | |
5459 | wpa_printf(MSG_DEBUG, "nl80211: Explicitly " | |
5460 | "disconnecting before reassociation " | |
5461 | "attempt"); | |
5462 | if (wpa_driver_nl80211_disconnect( | |
5463 | drv, WLAN_REASON_PREV_AUTH_NOT_VALID)) | |
5464 | return -1; | |
a8c5b43a CW |
5465 | ret = wpa_driver_nl80211_try_connect(drv, params); |
5466 | } | |
5467 | return ret; | |
5468 | } | |
5469 | ||
5470 | ||
c2a04078 JM |
5471 | static int wpa_driver_nl80211_associate( |
5472 | void *priv, struct wpa_driver_associate_params *params) | |
5473 | { | |
a2e40bb6 FF |
5474 | struct i802_bss *bss = priv; |
5475 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
a862e4a3 | 5476 | int ret = -1; |
c2a04078 JM |
5477 | struct nl_msg *msg; |
5478 | ||
4bd71954 JM |
5479 | nl80211_unmask_11b_rates(bss); |
5480 | ||
5cc4d64b | 5481 | if (params->mode == IEEE80211_MODE_AP) |
1581b38b | 5482 | return wpa_driver_nl80211_ap(drv, params); |
1581b38b | 5483 | |
5cc4d64b JM |
5484 | if (params->mode == IEEE80211_MODE_IBSS) |
5485 | return wpa_driver_nl80211_ibss(drv, params); | |
5486 | ||
4a867032 | 5487 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) { |
b1f625e0 EP |
5488 | enum nl80211_iftype nlmode = params->p2p ? |
5489 | NL80211_IFTYPE_P2P_CLIENT : NL80211_IFTYPE_STATION; | |
5490 | ||
5491 | if (wpa_driver_nl80211_set_mode(priv, nlmode) < 0) | |
4a867032 | 5492 | return -1; |
cfaab580 | 5493 | return wpa_driver_nl80211_connect(drv, params); |
4a867032 | 5494 | } |
cfaab580 | 5495 | |
add9b7a4 | 5496 | nl80211_mark_disconnected(drv); |
c2a04078 | 5497 | |
c2a04078 JM |
5498 | wpa_printf(MSG_DEBUG, "nl80211: Associate (ifindex=%d)", |
5499 | drv->ifindex); | |
9725b784 JM |
5500 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_ASSOCIATE); |
5501 | if (!msg) | |
5502 | return -1; | |
c2a04078 | 5503 | |
a0bdd191 JM |
5504 | ret = nl80211_connect_common(drv, params, msg); |
5505 | if (ret) | |
a862e4a3 | 5506 | goto fail; |
01652550 | 5507 | |
40a45727 JM |
5508 | if (params->fils_kek) { |
5509 | wpa_printf(MSG_DEBUG, " * FILS KEK (len=%u)", | |
5510 | (unsigned int) params->fils_kek_len); | |
5511 | if (nla_put(msg, NL80211_ATTR_FILS_KEK, params->fils_kek_len, | |
5512 | params->fils_kek)) | |
5513 | goto fail; | |
5514 | } | |
5515 | if (params->fils_nonces) { | |
5516 | wpa_hexdump(MSG_DEBUG, " * FILS nonces (for AAD)", | |
5517 | params->fils_nonces, | |
5518 | params->fils_nonces_len); | |
5519 | if (nla_put(msg, NL80211_ATTR_FILS_NONCES, | |
5520 | params->fils_nonces_len, params->fils_nonces)) | |
5521 | goto fail; | |
5522 | } | |
5523 | ||
c2a04078 JM |
5524 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
5525 | msg = NULL; | |
5526 | if (ret) { | |
3b7ea880 BG |
5527 | wpa_dbg(drv->ctx, MSG_DEBUG, |
5528 | "nl80211: MLME command failed (assoc): ret=%d (%s)", | |
5529 | ret, strerror(-ret)); | |
8856462d | 5530 | nl80211_dump_scan(drv); |
a862e4a3 JM |
5531 | } else { |
5532 | wpa_printf(MSG_DEBUG, | |
5533 | "nl80211: Association request send successfully"); | |
c2a04078 | 5534 | } |
c2a04078 | 5535 | |
a862e4a3 | 5536 | fail: |
c2a04078 JM |
5537 | nlmsg_free(msg); |
5538 | return ret; | |
5539 | } | |
3f5285e8 JM |
5540 | |
5541 | ||
ad1e68e6 | 5542 | static int nl80211_set_mode(struct wpa_driver_nl80211_data *drv, |
a1922f93 | 5543 | int ifindex, enum nl80211_iftype mode) |
3f5285e8 | 5544 | { |
3f5285e8 | 5545 | struct nl_msg *msg; |
ad1e68e6 JM |
5546 | int ret = -ENOBUFS; |
5547 | ||
a1922f93 JM |
5548 | wpa_printf(MSG_DEBUG, "nl80211: Set mode ifindex %d iftype %d (%s)", |
5549 | ifindex, mode, nl80211_iftype_str(mode)); | |
5550 | ||
56f77852 JM |
5551 | msg = nl80211_cmd_msg(drv->first_bss, 0, NL80211_CMD_SET_INTERFACE); |
5552 | if (!msg || nla_put_u32(msg, NL80211_ATTR_IFTYPE, mode)) | |
a862e4a3 | 5553 | goto fail; |
ad1e68e6 JM |
5554 | |
5555 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
5883168a | 5556 | msg = NULL; |
ad1e68e6 JM |
5557 | if (!ret) |
5558 | return 0; | |
a862e4a3 | 5559 | fail: |
5883168a | 5560 | nlmsg_free(msg); |
ad1e68e6 JM |
5561 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set interface %d to mode %d:" |
5562 | " %d (%s)", ifindex, mode, ret, strerror(-ret)); | |
5563 | return ret; | |
5564 | } | |
5565 | ||
5566 | ||
3c5d34e3 CW |
5567 | static int wpa_driver_nl80211_set_mode_impl( |
5568 | struct i802_bss *bss, | |
5569 | enum nl80211_iftype nlmode, | |
5570 | struct hostapd_freq_params *desired_freq_params) | |
ad1e68e6 | 5571 | { |
a2e40bb6 | 5572 | struct wpa_driver_nl80211_data *drv = bss->drv; |
ad1e68e6 | 5573 | int ret = -1; |
26af9dca | 5574 | int i; |
86957e62 | 5575 | int was_ap = is_ap_interface(drv->nlmode); |
671a5039 | 5576 | int res; |
ebffdbc4 | 5577 | int mode_switch_res; |
1581b38b | 5578 | |
a5a187b0 JM |
5579 | if (TEST_FAIL()) |
5580 | return -1; | |
5581 | ||
ebffdbc4 CW |
5582 | mode_switch_res = nl80211_set_mode(drv, drv->ifindex, nlmode); |
5583 | if (mode_switch_res && nlmode == nl80211_get_ifmode(bss)) | |
5584 | mode_switch_res = 0; | |
8e12685c | 5585 | |
ebffdbc4 | 5586 | if (mode_switch_res == 0) { |
ad1e68e6 | 5587 | drv->nlmode = nlmode; |
460456f8 JM |
5588 | ret = 0; |
5589 | goto done; | |
ad1e68e6 | 5590 | } |
3f5285e8 | 5591 | |
ebffdbc4 | 5592 | if (mode_switch_res == -ENODEV) |
671a5039 JM |
5593 | return -1; |
5594 | ||
460456f8 | 5595 | if (nlmode == drv->nlmode) { |
c6e8e8e4 JM |
5596 | wpa_printf(MSG_DEBUG, "nl80211: Interface already in " |
5597 | "requested mode - ignore error"); | |
460456f8 JM |
5598 | ret = 0; |
5599 | goto done; /* Already in the requested mode */ | |
5600 | } | |
3f5285e8 | 5601 | |
3f5285e8 JM |
5602 | /* mac80211 doesn't allow mode changes while the device is up, so |
5603 | * take the device down, try to set the mode again, and bring the | |
5604 | * device back up. | |
5605 | */ | |
26af9dca JM |
5606 | wpa_printf(MSG_DEBUG, "nl80211: Try mode change after setting " |
5607 | "interface down"); | |
5608 | for (i = 0; i < 10; i++) { | |
91724d6f | 5609 | res = i802_set_iface_flags(bss, 0); |
6e8183d7 JM |
5610 | if (res == -EACCES || res == -ENODEV) |
5611 | break; | |
ebffdbc4 | 5612 | if (res != 0) { |
26af9dca JM |
5613 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set " |
5614 | "interface down"); | |
ebffdbc4 CW |
5615 | os_sleep(0, 100000); |
5616 | continue; | |
5617 | } | |
3c5d34e3 CW |
5618 | |
5619 | /* | |
5620 | * Setting the mode will fail for some drivers if the phy is | |
5621 | * on a frequency that the mode is disallowed in. | |
5622 | */ | |
5623 | if (desired_freq_params) { | |
bdf5ccb2 | 5624 | res = nl80211_set_channel(bss, desired_freq_params, 0); |
3c5d34e3 CW |
5625 | if (res) { |
5626 | wpa_printf(MSG_DEBUG, | |
5627 | "nl80211: Failed to set frequency on interface"); | |
5628 | } | |
5629 | } | |
5630 | ||
ebffdbc4 CW |
5631 | /* Try to set the mode again while the interface is down */ |
5632 | mode_switch_res = nl80211_set_mode(drv, drv->ifindex, nlmode); | |
5633 | if (mode_switch_res == -EBUSY) { | |
5634 | wpa_printf(MSG_DEBUG, | |
5635 | "nl80211: Delaying mode set while interface going down"); | |
5636 | os_sleep(0, 100000); | |
5637 | continue; | |
5638 | } | |
5639 | ret = mode_switch_res; | |
5640 | break; | |
3f5285e8 JM |
5641 | } |
5642 | ||
c6e8e8e4 JM |
5643 | if (!ret) { |
5644 | wpa_printf(MSG_DEBUG, "nl80211: Mode change succeeded while " | |
5645 | "interface is down"); | |
ad1e68e6 | 5646 | drv->nlmode = nlmode; |
7d9c3698 | 5647 | drv->ignore_if_down_event = 1; |
c6e8e8e4 | 5648 | } |
ad1e68e6 | 5649 | |
ebffdbc4 CW |
5650 | /* Bring the interface back up */ |
5651 | res = linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 1); | |
5652 | if (res != 0) { | |
5653 | wpa_printf(MSG_DEBUG, | |
5654 | "nl80211: Failed to set interface up after switching mode"); | |
5655 | ret = -1; | |
5656 | } | |
5657 | ||
460456f8 | 5658 | done: |
3fd1cefb JB |
5659 | if (ret) { |
5660 | wpa_printf(MSG_DEBUG, "nl80211: Interface mode change to %d " | |
5661 | "from %d failed", nlmode, drv->nlmode); | |
5662 | return ret; | |
5663 | } | |
5664 | ||
3e208481 JM |
5665 | if (is_p2p_net_interface(nlmode)) { |
5666 | wpa_printf(MSG_DEBUG, | |
5667 | "nl80211: Interface %s mode change to P2P - disable 11b rates", | |
5668 | bss->ifname); | |
edb9bfba | 5669 | nl80211_disable_11b_rates(drv, drv->ifindex, 1); |
3e208481 JM |
5670 | } else if (drv->disabled_11b_rates) { |
5671 | wpa_printf(MSG_DEBUG, | |
5672 | "nl80211: Interface %s mode changed to non-P2P - re-enable 11b rates", | |
5673 | bss->ifname); | |
1d0c6fb1 | 5674 | nl80211_disable_11b_rates(drv, drv->ifindex, 0); |
3e208481 | 5675 | } |
edb9bfba | 5676 | |
3fd1cefb | 5677 | if (is_ap_interface(nlmode)) { |
36488c05 | 5678 | nl80211_mgmt_unsubscribe(bss, "start AP"); |
460456f8 | 5679 | /* Setup additional AP mode functionality if needed */ |
3fd1cefb | 5680 | if (nl80211_setup_ap(bss)) |
460456f8 | 5681 | return -1; |
3fd1cefb | 5682 | } else if (was_ap) { |
460456f8 | 5683 | /* Remove additional AP mode functionality */ |
3fd1cefb | 5684 | nl80211_teardown_ap(bss); |
a11241fa | 5685 | } else { |
36488c05 | 5686 | nl80211_mgmt_unsubscribe(bss, "mode change"); |
460456f8 | 5687 | } |
460456f8 | 5688 | |
afb0550a BC |
5689 | if (is_mesh_interface(nlmode) && |
5690 | nl80211_mgmt_subscribe_mesh(bss)) | |
5691 | return -1; | |
5692 | ||
873d0fcf | 5693 | if (!bss->in_deinit && !is_ap_interface(nlmode) && |
afb0550a | 5694 | !is_mesh_interface(nlmode) && |
a11241fa JB |
5695 | nl80211_mgmt_subscribe_non_ap(bss) < 0) |
5696 | wpa_printf(MSG_DEBUG, "nl80211: Failed to register Action " | |
5697 | "frame processing - ignore for now"); | |
08359050 | 5698 | |
3fd1cefb | 5699 | return 0; |
3f5285e8 JM |
5700 | } |
5701 | ||
5702 | ||
f3407c66 JM |
5703 | int wpa_driver_nl80211_set_mode(struct i802_bss *bss, |
5704 | enum nl80211_iftype nlmode) | |
3c5d34e3 CW |
5705 | { |
5706 | return wpa_driver_nl80211_set_mode_impl(bss, nlmode, NULL); | |
5707 | } | |
5708 | ||
5709 | ||
4ec68377 JD |
5710 | static int wpa_driver_nl80211_set_mode_ibss(struct i802_bss *bss, |
5711 | struct hostapd_freq_params *freq) | |
3c5d34e3 | 5712 | { |
3c5d34e3 | 5713 | return wpa_driver_nl80211_set_mode_impl(bss, NL80211_IFTYPE_ADHOC, |
4ec68377 | 5714 | freq); |
3c5d34e3 | 5715 | } |
65d645ce AS |
5716 | |
5717 | ||
3f5285e8 JM |
5718 | static int wpa_driver_nl80211_get_capa(void *priv, |
5719 | struct wpa_driver_capa *capa) | |
5720 | { | |
a2e40bb6 FF |
5721 | struct i802_bss *bss = priv; |
5722 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
65d645ce | 5723 | |
3f5285e8 JM |
5724 | if (!drv->has_capability) |
5725 | return -1; | |
5726 | os_memcpy(capa, &drv->capa, sizeof(*capa)); | |
8cd6b7bc JB |
5727 | if (drv->extended_capa && drv->extended_capa_mask) { |
5728 | capa->extended_capa = drv->extended_capa; | |
5729 | capa->extended_capa_mask = drv->extended_capa_mask; | |
5730 | capa->extended_capa_len = drv->extended_capa_len; | |
5731 | } | |
851b0c55 | 5732 | |
906bc4c7 | 5733 | return 0; |
3f5285e8 JM |
5734 | } |
5735 | ||
5736 | ||
5737 | static int wpa_driver_nl80211_set_operstate(void *priv, int state) | |
5738 | { | |
a2e40bb6 FF |
5739 | struct i802_bss *bss = priv; |
5740 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
3f5285e8 | 5741 | |
90a545cc JM |
5742 | wpa_printf(MSG_DEBUG, "nl80211: Set %s operstate %d->%d (%s)", |
5743 | bss->ifname, drv->operstate, state, | |
5744 | state ? "UP" : "DORMANT"); | |
3f5285e8 | 5745 | drv->operstate = state; |
36d84860 | 5746 | return netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, -1, |
e2d02c29 | 5747 | state ? IF_OPER_UP : IF_OPER_DORMANT); |
3f5285e8 JM |
5748 | } |
5749 | ||
01652550 JM |
5750 | |
5751 | static int wpa_driver_nl80211_set_supp_port(void *priv, int authorized) | |
5752 | { | |
a2e40bb6 FF |
5753 | struct i802_bss *bss = priv; |
5754 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
01652550 JM |
5755 | struct nl_msg *msg; |
5756 | struct nl80211_sta_flag_update upd; | |
a862e4a3 | 5757 | int ret; |
2eef5177 JM |
5758 | |
5759 | if (!drv->associated && is_zero_ether_addr(drv->bssid) && !authorized) { | |
5760 | wpa_printf(MSG_DEBUG, "nl80211: Skip set_supp_port(unauthorized) while not associated"); | |
5761 | return 0; | |
5762 | } | |
01652550 | 5763 | |
1ba51ec0 JM |
5764 | wpa_printf(MSG_DEBUG, "nl80211: Set supplicant port %sauthorized for " |
5765 | MACSTR, authorized ? "" : "un", MAC2STR(drv->bssid)); | |
5766 | ||
01652550 JM |
5767 | os_memset(&upd, 0, sizeof(upd)); |
5768 | upd.mask = BIT(NL80211_STA_FLAG_AUTHORIZED); | |
5769 | if (authorized) | |
5770 | upd.set = BIT(NL80211_STA_FLAG_AUTHORIZED); | |
a862e4a3 | 5771 | |
13f83980 | 5772 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) || |
a862e4a3 JM |
5773 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, drv->bssid) || |
5774 | nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd)) { | |
5775 | nlmsg_free(msg); | |
5776 | return -ENOBUFS; | |
5777 | } | |
01652550 | 5778 | |
2eef5177 | 5779 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
2eef5177 JM |
5780 | if (!ret) |
5781 | return 0; | |
2eef5177 JM |
5782 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set STA flag: %d (%s)", |
5783 | ret, strerror(-ret)); | |
5784 | return ret; | |
01652550 JM |
5785 | } |
5786 | ||
3f5285e8 | 5787 | |
f07ead6a JM |
5788 | /* Set kernel driver on given frequency (MHz) */ |
5789 | static int i802_set_freq(void *priv, struct hostapd_freq_params *freq) | |
c5121837 | 5790 | { |
f07ead6a | 5791 | struct i802_bss *bss = priv; |
13a524a3 | 5792 | return nl80211_set_channel(bss, freq, 0); |
c5121837 JM |
5793 | } |
5794 | ||
f7b3920c | 5795 | |
c5121837 JM |
5796 | static inline int min_int(int a, int b) |
5797 | { | |
5798 | if (a < b) | |
5799 | return a; | |
5800 | return b; | |
5801 | } | |
5802 | ||
5803 | ||
5804 | static int get_key_handler(struct nl_msg *msg, void *arg) | |
5805 | { | |
5806 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
5807 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
5808 | ||
5809 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
5810 | genlmsg_attrlen(gnlh, 0), NULL); | |
5811 | ||
5812 | /* | |
5813 | * TODO: validate the key index and mac address! | |
5814 | * Otherwise, there's a race condition as soon as | |
5815 | * the kernel starts sending key notifications. | |
5816 | */ | |
5817 | ||
5818 | if (tb[NL80211_ATTR_KEY_SEQ]) | |
5819 | memcpy(arg, nla_data(tb[NL80211_ATTR_KEY_SEQ]), | |
5820 | min_int(nla_len(tb[NL80211_ATTR_KEY_SEQ]), 6)); | |
5821 | return NL_SKIP; | |
5822 | } | |
5823 | ||
5824 | ||
5825 | static int i802_get_seqnum(const char *iface, void *priv, const u8 *addr, | |
5826 | int idx, u8 *seq) | |
5827 | { | |
a2e40bb6 FF |
5828 | struct i802_bss *bss = priv; |
5829 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
c5121837 JM |
5830 | struct nl_msg *msg; |
5831 | ||
95376e1a JM |
5832 | msg = nl80211_ifindex_msg(drv, if_nametoindex(iface), 0, |
5833 | NL80211_CMD_GET_KEY); | |
5834 | if (!msg || | |
a862e4a3 | 5835 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
95376e1a | 5836 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, idx)) { |
a862e4a3 JM |
5837 | nlmsg_free(msg); |
5838 | return -ENOBUFS; | |
5839 | } | |
c5121837 JM |
5840 | |
5841 | memset(seq, 0, 6); | |
5842 | ||
5843 | return send_and_recv_msgs(drv, msg, get_key_handler, seq); | |
c5121837 JM |
5844 | } |
5845 | ||
5846 | ||
c5121837 JM |
5847 | static int i802_set_rts(void *priv, int rts) |
5848 | { | |
a2e40bb6 FF |
5849 | struct i802_bss *bss = priv; |
5850 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
ad649451 | 5851 | struct nl_msg *msg; |
a862e4a3 | 5852 | int ret; |
ad649451 | 5853 | u32 val; |
c5121837 | 5854 | |
ad649451 JM |
5855 | if (rts >= 2347) |
5856 | val = (u32) -1; | |
5857 | else | |
5858 | val = rts; | |
c5121837 | 5859 | |
9725b784 | 5860 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_WIPHY)) || |
a862e4a3 JM |
5861 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, val)) { |
5862 | nlmsg_free(msg); | |
5863 | return -ENOBUFS; | |
5864 | } | |
ad649451 JM |
5865 | |
5866 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
5867 | if (!ret) | |
5868 | return 0; | |
ad649451 JM |
5869 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set RTS threshold %d: " |
5870 | "%d (%s)", rts, ret, strerror(-ret)); | |
5871 | return ret; | |
c5121837 JM |
5872 | } |
5873 | ||
5874 | ||
5875 | static int i802_set_frag(void *priv, int frag) | |
5876 | { | |
a2e40bb6 FF |
5877 | struct i802_bss *bss = priv; |
5878 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
ad649451 | 5879 | struct nl_msg *msg; |
a862e4a3 | 5880 | int ret; |
ad649451 | 5881 | u32 val; |
c5121837 | 5882 | |
ad649451 JM |
5883 | if (frag >= 2346) |
5884 | val = (u32) -1; | |
5885 | else | |
5886 | val = frag; | |
c5121837 | 5887 | |
9725b784 | 5888 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_WIPHY)) || |
a862e4a3 JM |
5889 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, val)) { |
5890 | nlmsg_free(msg); | |
5891 | return -ENOBUFS; | |
5892 | } | |
ad649451 JM |
5893 | |
5894 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
5895 | if (!ret) | |
5896 | return 0; | |
ad649451 JM |
5897 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set fragmentation threshold " |
5898 | "%d: %d (%s)", frag, ret, strerror(-ret)); | |
5899 | return ret; | |
c5121837 JM |
5900 | } |
5901 | ||
5902 | ||
c5121837 JM |
5903 | static int i802_flush(void *priv) |
5904 | { | |
a2e40bb6 | 5905 | struct i802_bss *bss = priv; |
c5121837 | 5906 | struct nl_msg *msg; |
82554b10 | 5907 | int res; |
c5121837 | 5908 | |
83e7bb0e JM |
5909 | wpa_printf(MSG_DEBUG, "nl80211: flush -> DEL_STATION %s (all)", |
5910 | bss->ifname); | |
c5121837 JM |
5911 | |
5912 | /* | |
5913 | * XXX: FIX! this needs to flush all VLANs too | |
5914 | */ | |
13f83980 JM |
5915 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_DEL_STATION); |
5916 | res = send_and_recv_msgs(bss->drv, msg, NULL, NULL); | |
82554b10 JM |
5917 | if (res) { |
5918 | wpa_printf(MSG_DEBUG, "nl80211: Station flush failed: ret=%d " | |
5919 | "(%s)", res, strerror(-res)); | |
5920 | } | |
5921 | return res; | |
c5121837 JM |
5922 | } |
5923 | ||
5924 | ||
5925 | static int get_sta_handler(struct nl_msg *msg, void *arg) | |
5926 | { | |
5927 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
5928 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
5929 | struct hostap_sta_driver_data *data = arg; | |
5930 | struct nlattr *stats[NL80211_STA_INFO_MAX + 1]; | |
5931 | static struct nla_policy stats_policy[NL80211_STA_INFO_MAX + 1] = { | |
5932 | [NL80211_STA_INFO_INACTIVE_TIME] = { .type = NLA_U32 }, | |
5933 | [NL80211_STA_INFO_RX_BYTES] = { .type = NLA_U32 }, | |
5934 | [NL80211_STA_INFO_TX_BYTES] = { .type = NLA_U32 }, | |
5935 | [NL80211_STA_INFO_RX_PACKETS] = { .type = NLA_U32 }, | |
5936 | [NL80211_STA_INFO_TX_PACKETS] = { .type = NLA_U32 }, | |
dc7785f8 | 5937 | [NL80211_STA_INFO_TX_FAILED] = { .type = NLA_U32 }, |
43022abd NL |
5938 | [NL80211_STA_INFO_RX_BYTES64] = { .type = NLA_U64 }, |
5939 | [NL80211_STA_INFO_TX_BYTES64] = { .type = NLA_U64 }, | |
3567641e | 5940 | [NL80211_STA_INFO_SIGNAL] = { .type = NLA_U8 }, |
5941 | }; | |
5942 | struct nlattr *rate[NL80211_RATE_INFO_MAX + 1]; | |
5943 | static struct nla_policy rate_policy[NL80211_RATE_INFO_MAX + 1] = { | |
5944 | [NL80211_RATE_INFO_BITRATE] = { .type = NLA_U16 }, | |
5945 | [NL80211_RATE_INFO_BITRATE32] = { .type = NLA_U32 }, | |
5946 | [NL80211_RATE_INFO_MCS] = { .type = NLA_U8 }, | |
5947 | [NL80211_RATE_INFO_VHT_MCS] = { .type = NLA_U8 }, | |
5948 | [NL80211_RATE_INFO_SHORT_GI] = { .type = NLA_FLAG }, | |
5949 | [NL80211_RATE_INFO_VHT_NSS] = { .type = NLA_U8 }, | |
c5121837 JM |
5950 | }; |
5951 | ||
5952 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
5953 | genlmsg_attrlen(gnlh, 0), NULL); | |
5954 | ||
5955 | /* | |
5956 | * TODO: validate the interface and mac address! | |
5957 | * Otherwise, there's a race condition as soon as | |
5958 | * the kernel starts sending station notifications. | |
5959 | */ | |
5960 | ||
5961 | if (!tb[NL80211_ATTR_STA_INFO]) { | |
5962 | wpa_printf(MSG_DEBUG, "sta stats missing!"); | |
5963 | return NL_SKIP; | |
5964 | } | |
5965 | if (nla_parse_nested(stats, NL80211_STA_INFO_MAX, | |
5966 | tb[NL80211_ATTR_STA_INFO], | |
5967 | stats_policy)) { | |
5968 | wpa_printf(MSG_DEBUG, "failed to parse nested attributes!"); | |
5969 | return NL_SKIP; | |
5970 | } | |
5971 | ||
5972 | if (stats[NL80211_STA_INFO_INACTIVE_TIME]) | |
5973 | data->inactive_msec = | |
5974 | nla_get_u32(stats[NL80211_STA_INFO_INACTIVE_TIME]); | |
43022abd | 5975 | /* For backwards compatibility, fetch the 32-bit counters first. */ |
c5121837 JM |
5976 | if (stats[NL80211_STA_INFO_RX_BYTES]) |
5977 | data->rx_bytes = nla_get_u32(stats[NL80211_STA_INFO_RX_BYTES]); | |
5978 | if (stats[NL80211_STA_INFO_TX_BYTES]) | |
5979 | data->tx_bytes = nla_get_u32(stats[NL80211_STA_INFO_TX_BYTES]); | |
43022abd NL |
5980 | if (stats[NL80211_STA_INFO_RX_BYTES64] && |
5981 | stats[NL80211_STA_INFO_TX_BYTES64]) { | |
5982 | /* | |
5983 | * The driver supports 64-bit counters, so use them to override | |
5984 | * the 32-bit values. | |
5985 | */ | |
5986 | data->rx_bytes = | |
5987 | nla_get_u64(stats[NL80211_STA_INFO_RX_BYTES64]); | |
5988 | data->tx_bytes = | |
5989 | nla_get_u64(stats[NL80211_STA_INFO_TX_BYTES64]); | |
5990 | data->bytes_64bit = 1; | |
5991 | } | |
c5121837 JM |
5992 | if (stats[NL80211_STA_INFO_RX_PACKETS]) |
5993 | data->rx_packets = | |
5994 | nla_get_u32(stats[NL80211_STA_INFO_RX_PACKETS]); | |
5995 | if (stats[NL80211_STA_INFO_TX_PACKETS]) | |
5996 | data->tx_packets = | |
5997 | nla_get_u32(stats[NL80211_STA_INFO_TX_PACKETS]); | |
dc7785f8 YZ |
5998 | if (stats[NL80211_STA_INFO_TX_FAILED]) |
5999 | data->tx_retry_failed = | |
6000 | nla_get_u32(stats[NL80211_STA_INFO_TX_FAILED]); | |
3567641e | 6001 | if (stats[NL80211_STA_INFO_SIGNAL]) |
6002 | data->signal = nla_get_u8(stats[NL80211_STA_INFO_SIGNAL]); | |
6003 | ||
6004 | if (stats[NL80211_STA_INFO_TX_BITRATE] && | |
6005 | nla_parse_nested(rate, NL80211_RATE_INFO_MAX, | |
6006 | stats[NL80211_STA_INFO_TX_BITRATE], | |
6007 | rate_policy) == 0) { | |
6008 | if (rate[NL80211_RATE_INFO_BITRATE32]) | |
6009 | data->current_tx_rate = | |
6010 | nla_get_u32(rate[NL80211_RATE_INFO_BITRATE32]); | |
6011 | else if (rate[NL80211_RATE_INFO_BITRATE]) | |
6012 | data->current_tx_rate = | |
6013 | nla_get_u16(rate[NL80211_RATE_INFO_BITRATE]); | |
6014 | ||
6015 | if (rate[NL80211_RATE_INFO_MCS]) { | |
6016 | data->tx_mcs = nla_get_u8(rate[NL80211_RATE_INFO_MCS]); | |
6017 | data->flags |= STA_DRV_DATA_TX_MCS; | |
6018 | } | |
6019 | if (rate[NL80211_RATE_INFO_VHT_MCS]) { | |
6020 | data->tx_vhtmcs = | |
6021 | nla_get_u8(rate[NL80211_RATE_INFO_VHT_MCS]); | |
6022 | data->flags |= STA_DRV_DATA_TX_VHT_MCS; | |
6023 | } | |
6024 | if (rate[NL80211_RATE_INFO_SHORT_GI]) | |
6025 | data->flags |= STA_DRV_DATA_TX_SHORT_GI; | |
6026 | if (rate[NL80211_RATE_INFO_VHT_NSS]) { | |
6027 | data->tx_vht_nss = | |
6028 | nla_get_u8(rate[NL80211_RATE_INFO_VHT_NSS]); | |
6029 | data->flags |= STA_DRV_DATA_TX_VHT_NSS; | |
6030 | } | |
6031 | } | |
6032 | ||
6033 | if (stats[NL80211_STA_INFO_RX_BITRATE] && | |
6034 | nla_parse_nested(rate, NL80211_RATE_INFO_MAX, | |
6035 | stats[NL80211_STA_INFO_RX_BITRATE], | |
6036 | rate_policy) == 0) { | |
6037 | if (rate[NL80211_RATE_INFO_BITRATE32]) | |
6038 | data->current_rx_rate = | |
6039 | nla_get_u32(rate[NL80211_RATE_INFO_BITRATE32]); | |
6040 | else if (rate[NL80211_RATE_INFO_BITRATE]) | |
6041 | data->current_rx_rate = | |
6042 | nla_get_u16(rate[NL80211_RATE_INFO_BITRATE]); | |
6043 | ||
6044 | if (rate[NL80211_RATE_INFO_MCS]) { | |
6045 | data->rx_mcs = | |
6046 | nla_get_u8(rate[NL80211_RATE_INFO_MCS]); | |
6047 | data->flags |= STA_DRV_DATA_RX_MCS; | |
6048 | } | |
6049 | if (rate[NL80211_RATE_INFO_VHT_MCS]) { | |
6050 | data->rx_vhtmcs = | |
6051 | nla_get_u8(rate[NL80211_RATE_INFO_VHT_MCS]); | |
6052 | data->flags |= STA_DRV_DATA_RX_VHT_MCS; | |
6053 | } | |
6054 | if (rate[NL80211_RATE_INFO_SHORT_GI]) | |
6055 | data->flags |= STA_DRV_DATA_RX_SHORT_GI; | |
6056 | if (rate[NL80211_RATE_INFO_VHT_NSS]) { | |
6057 | data->rx_vht_nss = | |
6058 | nla_get_u8(rate[NL80211_RATE_INFO_VHT_NSS]); | |
6059 | data->flags |= STA_DRV_DATA_RX_VHT_NSS; | |
6060 | } | |
6061 | } | |
c5121837 JM |
6062 | |
6063 | return NL_SKIP; | |
6064 | } | |
6065 | ||
9ebce9c5 JM |
6066 | static int i802_read_sta_data(struct i802_bss *bss, |
6067 | struct hostap_sta_driver_data *data, | |
c5121837 JM |
6068 | const u8 *addr) |
6069 | { | |
c5121837 JM |
6070 | struct nl_msg *msg; |
6071 | ||
13f83980 JM |
6072 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_GET_STATION)) || |
6073 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { | |
a862e4a3 JM |
6074 | nlmsg_free(msg); |
6075 | return -ENOBUFS; | |
6076 | } | |
c5121837 | 6077 | |
13f83980 | 6078 | return send_and_recv_msgs(bss->drv, msg, get_sta_handler, data); |
c5121837 JM |
6079 | } |
6080 | ||
6081 | ||
c5121837 JM |
6082 | static int i802_set_tx_queue_params(void *priv, int queue, int aifs, |
6083 | int cw_min, int cw_max, int burst_time) | |
6084 | { | |
a2e40bb6 FF |
6085 | struct i802_bss *bss = priv; |
6086 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
c5121837 JM |
6087 | struct nl_msg *msg; |
6088 | struct nlattr *txq, *params; | |
6089 | ||
13f83980 | 6090 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_WIPHY); |
c5121837 JM |
6091 | if (!msg) |
6092 | return -1; | |
6093 | ||
c5121837 JM |
6094 | txq = nla_nest_start(msg, NL80211_ATTR_WIPHY_TXQ_PARAMS); |
6095 | if (!txq) | |
a862e4a3 | 6096 | goto fail; |
c5121837 JM |
6097 | |
6098 | /* We are only sending parameters for a single TXQ at a time */ | |
6099 | params = nla_nest_start(msg, 1); | |
6100 | if (!params) | |
a862e4a3 | 6101 | goto fail; |
c5121837 | 6102 | |
7e3c1781 JM |
6103 | switch (queue) { |
6104 | case 0: | |
a862e4a3 JM |
6105 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_VO)) |
6106 | goto fail; | |
7e3c1781 JM |
6107 | break; |
6108 | case 1: | |
a862e4a3 JM |
6109 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_VI)) |
6110 | goto fail; | |
7e3c1781 JM |
6111 | break; |
6112 | case 2: | |
a862e4a3 JM |
6113 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_BE)) |
6114 | goto fail; | |
7e3c1781 JM |
6115 | break; |
6116 | case 3: | |
a862e4a3 JM |
6117 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_BK)) |
6118 | goto fail; | |
7e3c1781 JM |
6119 | break; |
6120 | } | |
c5121837 JM |
6121 | /* Burst time is configured in units of 0.1 msec and TXOP parameter in |
6122 | * 32 usec, so need to convert the value here. */ | |
a862e4a3 JM |
6123 | if (nla_put_u16(msg, NL80211_TXQ_ATTR_TXOP, |
6124 | (burst_time * 100 + 16) / 32) || | |
6125 | nla_put_u16(msg, NL80211_TXQ_ATTR_CWMIN, cw_min) || | |
6126 | nla_put_u16(msg, NL80211_TXQ_ATTR_CWMAX, cw_max) || | |
6127 | nla_put_u8(msg, NL80211_TXQ_ATTR_AIFS, aifs)) | |
6128 | goto fail; | |
c5121837 JM |
6129 | |
6130 | nla_nest_end(msg, params); | |
6131 | ||
6132 | nla_nest_end(msg, txq); | |
6133 | ||
6134 | if (send_and_recv_msgs(drv, msg, NULL, NULL) == 0) | |
6135 | return 0; | |
9e088e74 | 6136 | msg = NULL; |
a862e4a3 | 6137 | fail: |
9e088e74 | 6138 | nlmsg_free(msg); |
c5121837 JM |
6139 | return -1; |
6140 | } | |
6141 | ||
6142 | ||
9ebce9c5 | 6143 | static int i802_set_sta_vlan(struct i802_bss *bss, const u8 *addr, |
c5121837 JM |
6144 | const char *ifname, int vlan_id) |
6145 | { | |
a2e40bb6 | 6146 | struct wpa_driver_nl80211_data *drv = bss->drv; |
c5121837 | 6147 | struct nl_msg *msg; |
a862e4a3 | 6148 | int ret; |
c5121837 | 6149 | |
bbc706a3 JM |
6150 | wpa_printf(MSG_DEBUG, "nl80211: %s[%d]: set_sta_vlan(" MACSTR |
6151 | ", ifname=%s[%d], vlan_id=%d)", | |
6152 | bss->ifname, if_nametoindex(bss->ifname), | |
6153 | MAC2STR(addr), ifname, if_nametoindex(ifname), vlan_id); | |
13f83980 | 6154 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) || |
a862e4a3 JM |
6155 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
6156 | nla_put_u32(msg, NL80211_ATTR_STA_VLAN, if_nametoindex(ifname))) { | |
6157 | nlmsg_free(msg); | |
6158 | return -ENOBUFS; | |
6159 | } | |
c5121837 | 6160 | |
cd1d72c1 JM |
6161 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
6162 | if (ret < 0) { | |
6163 | wpa_printf(MSG_ERROR, "nl80211: NL80211_ATTR_STA_VLAN (addr=" | |
6164 | MACSTR " ifname=%s vlan_id=%d) failed: %d (%s)", | |
6165 | MAC2STR(addr), ifname, vlan_id, ret, | |
6166 | strerror(-ret)); | |
6167 | } | |
cd1d72c1 | 6168 | return ret; |
c5121837 JM |
6169 | } |
6170 | ||
fbbfcbac | 6171 | |
c5121837 JM |
6172 | static int i802_get_inact_sec(void *priv, const u8 *addr) |
6173 | { | |
6174 | struct hostap_sta_driver_data data; | |
6175 | int ret; | |
6176 | ||
7824bf77 | 6177 | os_memset(&data, 0, sizeof(data)); |
c5121837 JM |
6178 | data.inactive_msec = (unsigned long) -1; |
6179 | ret = i802_read_sta_data(priv, &data, addr); | |
b9749bac MH |
6180 | if (ret == -ENOENT) |
6181 | return -ENOENT; | |
c5121837 JM |
6182 | if (ret || data.inactive_msec == (unsigned long) -1) |
6183 | return -1; | |
6184 | return data.inactive_msec / 1000; | |
6185 | } | |
6186 | ||
6187 | ||
6188 | static int i802_sta_clear_stats(void *priv, const u8 *addr) | |
6189 | { | |
6190 | #if 0 | |
6191 | /* TODO */ | |
6192 | #endif | |
6193 | return 0; | |
6194 | } | |
6195 | ||
6196 | ||
731723a5 JM |
6197 | static int i802_sta_deauth(void *priv, const u8 *own_addr, const u8 *addr, |
6198 | int reason) | |
c5121837 | 6199 | { |
a2e40bb6 | 6200 | struct i802_bss *bss = priv; |
e1bd4e19 | 6201 | struct wpa_driver_nl80211_data *drv = bss->drv; |
c5121837 | 6202 | struct ieee80211_mgmt mgmt; |
05e5e615 DL |
6203 | u8 channel; |
6204 | ||
6205 | if (ieee80211_freq_to_chan(bss->freq, &channel) == | |
6206 | HOSTAPD_MODE_IEEE80211AD) { | |
6207 | /* Deauthentication is not used in DMG/IEEE 802.11ad; | |
6208 | * disassociate the STA instead. */ | |
6209 | return i802_sta_disassoc(priv, own_addr, addr, reason); | |
6210 | } | |
c5121837 | 6211 | |
0d391b03 BC |
6212 | if (is_mesh_interface(drv->nlmode)) |
6213 | return -1; | |
6214 | ||
e1bd4e19 | 6215 | if (drv->device_ap_sme) |
59d7148a | 6216 | return wpa_driver_nl80211_sta_remove(bss, addr, 1, reason); |
e1bd4e19 | 6217 | |
c5121837 JM |
6218 | memset(&mgmt, 0, sizeof(mgmt)); |
6219 | mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, | |
6220 | WLAN_FC_STYPE_DEAUTH); | |
6221 | memcpy(mgmt.da, addr, ETH_ALEN); | |
731723a5 JM |
6222 | memcpy(mgmt.sa, own_addr, ETH_ALEN); |
6223 | memcpy(mgmt.bssid, own_addr, ETH_ALEN); | |
c5121837 | 6224 | mgmt.u.deauth.reason_code = host_to_le16(reason); |
a2e40bb6 | 6225 | return wpa_driver_nl80211_send_mlme(bss, (u8 *) &mgmt, |
9f324b61 | 6226 | IEEE80211_HDRLEN + |
9ebce9c5 | 6227 | sizeof(mgmt.u.deauth), 0, 0, 0, 0, |
2d3943ce | 6228 | 0, NULL, 0); |
c5121837 JM |
6229 | } |
6230 | ||
6231 | ||
731723a5 JM |
6232 | static int i802_sta_disassoc(void *priv, const u8 *own_addr, const u8 *addr, |
6233 | int reason) | |
c5121837 | 6234 | { |
a2e40bb6 | 6235 | struct i802_bss *bss = priv; |
e1bd4e19 | 6236 | struct wpa_driver_nl80211_data *drv = bss->drv; |
c5121837 JM |
6237 | struct ieee80211_mgmt mgmt; |
6238 | ||
0d391b03 BC |
6239 | if (is_mesh_interface(drv->nlmode)) |
6240 | return -1; | |
6241 | ||
e1bd4e19 | 6242 | if (drv->device_ap_sme) |
59d7148a | 6243 | return wpa_driver_nl80211_sta_remove(bss, addr, 0, reason); |
e1bd4e19 | 6244 | |
c5121837 JM |
6245 | memset(&mgmt, 0, sizeof(mgmt)); |
6246 | mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, | |
6247 | WLAN_FC_STYPE_DISASSOC); | |
6248 | memcpy(mgmt.da, addr, ETH_ALEN); | |
731723a5 JM |
6249 | memcpy(mgmt.sa, own_addr, ETH_ALEN); |
6250 | memcpy(mgmt.bssid, own_addr, ETH_ALEN); | |
c5121837 | 6251 | mgmt.u.disassoc.reason_code = host_to_le16(reason); |
a2e40bb6 | 6252 | return wpa_driver_nl80211_send_mlme(bss, (u8 *) &mgmt, |
9f324b61 | 6253 | IEEE80211_HDRLEN + |
9ebce9c5 | 6254 | sizeof(mgmt.u.disassoc), 0, 0, 0, 0, |
2d3943ce | 6255 | 0, NULL, 0); |
c5121837 JM |
6256 | } |
6257 | ||
6258 | ||
9b4d9c8b JM |
6259 | static void dump_ifidx(struct wpa_driver_nl80211_data *drv) |
6260 | { | |
6261 | char buf[200], *pos, *end; | |
6262 | int i, res; | |
6263 | ||
6264 | pos = buf; | |
6265 | end = pos + sizeof(buf); | |
6266 | ||
6267 | for (i = 0; i < drv->num_if_indices; i++) { | |
6268 | if (!drv->if_indices[i]) | |
6269 | continue; | |
732b1d20 MB |
6270 | res = os_snprintf(pos, end - pos, " %d(%d)", |
6271 | drv->if_indices[i], | |
6272 | drv->if_indices_reason[i]); | |
d85e1fc8 | 6273 | if (os_snprintf_error(end - pos, res)) |
9b4d9c8b JM |
6274 | break; |
6275 | pos += res; | |
6276 | } | |
6277 | *pos = '\0'; | |
6278 | ||
6279 | wpa_printf(MSG_DEBUG, "nl80211: if_indices[%d]:%s", | |
6280 | drv->num_if_indices, buf); | |
6281 | } | |
6282 | ||
6283 | ||
732b1d20 MB |
6284 | static void add_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, |
6285 | int ifidx_reason) | |
f07ead6a JM |
6286 | { |
6287 | int i; | |
732b1d20 | 6288 | int *old, *old_reason; |
f07ead6a | 6289 | |
732b1d20 MB |
6290 | wpa_printf(MSG_DEBUG, |
6291 | "nl80211: Add own interface ifindex %d (ifidx_reason %d)", | |
6292 | ifidx, ifidx_reason); | |
6293 | if (have_ifidx(drv, ifidx, ifidx_reason)) { | |
b36935be MB |
6294 | wpa_printf(MSG_DEBUG, "nl80211: ifindex %d already in the list", |
6295 | ifidx); | |
6296 | return; | |
6297 | } | |
f07ead6a JM |
6298 | for (i = 0; i < drv->num_if_indices; i++) { |
6299 | if (drv->if_indices[i] == 0) { | |
6300 | drv->if_indices[i] = ifidx; | |
732b1d20 | 6301 | drv->if_indices_reason[i] = ifidx_reason; |
9b4d9c8b | 6302 | dump_ifidx(drv); |
f07ead6a JM |
6303 | return; |
6304 | } | |
6305 | } | |
6306 | ||
6307 | if (drv->if_indices != drv->default_if_indices) | |
6308 | old = drv->if_indices; | |
6309 | else | |
6310 | old = NULL; | |
6311 | ||
732b1d20 MB |
6312 | if (drv->if_indices_reason != drv->default_if_indices_reason) |
6313 | old_reason = drv->if_indices_reason; | |
6314 | else | |
6315 | old_reason = NULL; | |
6316 | ||
067ffa26 JM |
6317 | drv->if_indices = os_realloc_array(old, drv->num_if_indices + 1, |
6318 | sizeof(int)); | |
732b1d20 MB |
6319 | drv->if_indices_reason = os_realloc_array(old_reason, |
6320 | drv->num_if_indices + 1, | |
6321 | sizeof(int)); | |
f07ead6a JM |
6322 | if (!drv->if_indices) { |
6323 | if (!old) | |
6324 | drv->if_indices = drv->default_if_indices; | |
6325 | else | |
6326 | drv->if_indices = old; | |
732b1d20 MB |
6327 | } |
6328 | if (!drv->if_indices_reason) { | |
6329 | if (!old_reason) | |
6330 | drv->if_indices_reason = drv->default_if_indices_reason; | |
6331 | else | |
29eddc3d | 6332 | drv->if_indices_reason = old_reason; |
732b1d20 MB |
6333 | } |
6334 | if (!drv->if_indices || !drv->if_indices_reason) { | |
f07ead6a JM |
6335 | wpa_printf(MSG_ERROR, "Failed to reallocate memory for " |
6336 | "interfaces"); | |
6337 | wpa_printf(MSG_ERROR, "Ignoring EAPOL on interface %d", ifidx); | |
6338 | return; | |
732b1d20 MB |
6339 | } |
6340 | if (!old) | |
f07ead6a JM |
6341 | os_memcpy(drv->if_indices, drv->default_if_indices, |
6342 | sizeof(drv->default_if_indices)); | |
732b1d20 MB |
6343 | if (!old_reason) |
6344 | os_memcpy(drv->if_indices_reason, | |
6345 | drv->default_if_indices_reason, | |
6346 | sizeof(drv->default_if_indices_reason)); | |
f07ead6a | 6347 | drv->if_indices[drv->num_if_indices] = ifidx; |
732b1d20 | 6348 | drv->if_indices_reason[drv->num_if_indices] = ifidx_reason; |
f07ead6a | 6349 | drv->num_if_indices++; |
9b4d9c8b | 6350 | dump_ifidx(drv); |
f07ead6a JM |
6351 | } |
6352 | ||
6353 | ||
732b1d20 MB |
6354 | static void del_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, |
6355 | int ifidx_reason) | |
f07ead6a JM |
6356 | { |
6357 | int i; | |
6358 | ||
6359 | for (i = 0; i < drv->num_if_indices; i++) { | |
732b1d20 MB |
6360 | if ((drv->if_indices[i] == ifidx || ifidx == IFIDX_ANY) && |
6361 | (drv->if_indices_reason[i] == ifidx_reason || | |
6362 | ifidx_reason == IFIDX_ANY)) { | |
f07ead6a JM |
6363 | drv->if_indices[i] = 0; |
6364 | break; | |
6365 | } | |
6366 | } | |
9b4d9c8b | 6367 | dump_ifidx(drv); |
f07ead6a JM |
6368 | } |
6369 | ||
6370 | ||
732b1d20 MB |
6371 | static int have_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, |
6372 | int ifidx_reason) | |
f07ead6a JM |
6373 | { |
6374 | int i; | |
6375 | ||
6376 | for (i = 0; i < drv->num_if_indices; i++) | |
732b1d20 MB |
6377 | if (drv->if_indices[i] == ifidx && |
6378 | (drv->if_indices_reason[i] == ifidx_reason || | |
6379 | ifidx_reason == IFIDX_ANY)) | |
f07ead6a JM |
6380 | return 1; |
6381 | ||
6382 | return 0; | |
6383 | } | |
6384 | ||
6385 | ||
6386 | static int i802_set_wds_sta(void *priv, const u8 *addr, int aid, int val, | |
0e80ea2c | 6387 | const char *bridge_ifname, char *ifname_wds) |
f07ead6a JM |
6388 | { |
6389 | struct i802_bss *bss = priv; | |
6390 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
6391 | char name[IFNAMSIZ + 1]; | |
6392 | ||
6393 | os_snprintf(name, sizeof(name), "%s.sta%d", bss->ifname, aid); | |
69dd2967 SM |
6394 | if (ifname_wds) |
6395 | os_strlcpy(ifname_wds, name, IFNAMSIZ + 1); | |
6396 | ||
f07ead6a JM |
6397 | wpa_printf(MSG_DEBUG, "nl80211: Set WDS STA addr=" MACSTR |
6398 | " aid=%d val=%d name=%s", MAC2STR(addr), aid, val, name); | |
6399 | if (val) { | |
6400 | if (!if_nametoindex(name)) { | |
6401 | if (nl80211_create_iface(drv, name, | |
6402 | NL80211_IFTYPE_AP_VLAN, | |
2aec4f3c JM |
6403 | bss->addr, 1, NULL, NULL, 0) < |
6404 | 0) | |
f07ead6a JM |
6405 | return -1; |
6406 | if (bridge_ifname && | |
c81eff1a BG |
6407 | linux_br_add_if(drv->global->ioctl_sock, |
6408 | bridge_ifname, name) < 0) | |
f07ead6a JM |
6409 | return -1; |
6410 | } | |
75227f3a JM |
6411 | if (linux_set_iface_flags(drv->global->ioctl_sock, name, 1)) { |
6412 | wpa_printf(MSG_ERROR, "nl80211: Failed to set WDS STA " | |
6413 | "interface %s up", name); | |
6414 | } | |
f07ead6a JM |
6415 | return i802_set_sta_vlan(priv, addr, name, 0); |
6416 | } else { | |
c34e618d FF |
6417 | if (bridge_ifname) |
6418 | linux_br_del_if(drv->global->ioctl_sock, bridge_ifname, | |
6419 | name); | |
6420 | ||
f07ead6a | 6421 | i802_set_sta_vlan(priv, addr, bss->ifname, 0); |
d0595b25 FF |
6422 | nl80211_remove_iface(drv, if_nametoindex(name)); |
6423 | return 0; | |
f07ead6a JM |
6424 | } |
6425 | } | |
6426 | ||
6427 | ||
6428 | static void handle_eapol(int sock, void *eloop_ctx, void *sock_ctx) | |
6429 | { | |
6430 | struct wpa_driver_nl80211_data *drv = eloop_ctx; | |
6431 | struct sockaddr_ll lladdr; | |
6432 | unsigned char buf[3000]; | |
6433 | int len; | |
6434 | socklen_t fromlen = sizeof(lladdr); | |
6435 | ||
6436 | len = recvfrom(sock, buf, sizeof(buf), 0, | |
6437 | (struct sockaddr *)&lladdr, &fromlen); | |
6438 | if (len < 0) { | |
7ac3616d JM |
6439 | wpa_printf(MSG_ERROR, "nl80211: EAPOL recv failed: %s", |
6440 | strerror(errno)); | |
f07ead6a JM |
6441 | return; |
6442 | } | |
6443 | ||
732b1d20 | 6444 | if (have_ifidx(drv, lladdr.sll_ifindex, IFIDX_ANY)) |
f07ead6a JM |
6445 | drv_event_eapol_rx(drv->ctx, lladdr.sll_addr, buf, len); |
6446 | } | |
6447 | ||
6448 | ||
94627f6c | 6449 | static int i802_check_bridge(struct wpa_driver_nl80211_data *drv, |
e17a2477 | 6450 | struct i802_bss *bss, |
94627f6c JM |
6451 | const char *brname, const char *ifname) |
6452 | { | |
6c6678e7 | 6453 | int br_ifindex; |
94627f6c JM |
6454 | char in_br[IFNAMSIZ]; |
6455 | ||
e17a2477 | 6456 | os_strlcpy(bss->brname, brname, IFNAMSIZ); |
6c6678e7 | 6457 | br_ifindex = if_nametoindex(brname); |
6c6678e7 | 6458 | if (br_ifindex == 0) { |
94627f6c JM |
6459 | /* |
6460 | * Bridge was configured, but the bridge device does | |
6461 | * not exist. Try to add it now. | |
6462 | */ | |
c81eff1a | 6463 | if (linux_br_add(drv->global->ioctl_sock, brname) < 0) { |
94627f6c JM |
6464 | wpa_printf(MSG_ERROR, "nl80211: Failed to add the " |
6465 | "bridge interface %s: %s", | |
6466 | brname, strerror(errno)); | |
6467 | return -1; | |
6468 | } | |
e17a2477 | 6469 | bss->added_bridge = 1; |
8997613c | 6470 | br_ifindex = if_nametoindex(brname); |
732b1d20 | 6471 | add_ifidx(drv, br_ifindex, drv->ifindex); |
94627f6c | 6472 | } |
8997613c | 6473 | bss->br_ifindex = br_ifindex; |
94627f6c JM |
6474 | |
6475 | if (linux_br_get(in_br, ifname) == 0) { | |
6476 | if (os_strcmp(in_br, brname) == 0) | |
6477 | return 0; /* already in the bridge */ | |
6478 | ||
6479 | wpa_printf(MSG_DEBUG, "nl80211: Removing interface %s from " | |
6480 | "bridge %s", ifname, in_br); | |
c81eff1a BG |
6481 | if (linux_br_del_if(drv->global->ioctl_sock, in_br, ifname) < |
6482 | 0) { | |
94627f6c JM |
6483 | wpa_printf(MSG_ERROR, "nl80211: Failed to " |
6484 | "remove interface %s from bridge " | |
6485 | "%s: %s", | |
fdbfb63e | 6486 | ifname, in_br, strerror(errno)); |
94627f6c JM |
6487 | return -1; |
6488 | } | |
6489 | } | |
6490 | ||
6491 | wpa_printf(MSG_DEBUG, "nl80211: Adding interface %s into bridge %s", | |
6492 | ifname, brname); | |
c81eff1a | 6493 | if (linux_br_add_if(drv->global->ioctl_sock, brname, ifname) < 0) { |
94627f6c JM |
6494 | wpa_printf(MSG_ERROR, "nl80211: Failed to add interface %s " |
6495 | "into bridge %s: %s", | |
6496 | ifname, brname, strerror(errno)); | |
6497 | return -1; | |
6498 | } | |
e17a2477 | 6499 | bss->added_if_into_bridge = 1; |
94627f6c JM |
6500 | |
6501 | return 0; | |
6502 | } | |
6503 | ||
6504 | ||
92f475b4 JM |
6505 | static void *i802_init(struct hostapd_data *hapd, |
6506 | struct wpa_init_params *params) | |
c5121837 JM |
6507 | { |
6508 | struct wpa_driver_nl80211_data *drv; | |
a2e40bb6 | 6509 | struct i802_bss *bss; |
c5121837 | 6510 | size_t i; |
cb05808c AN |
6511 | char master_ifname[IFNAMSIZ]; |
6512 | int ifindex, br_ifindex = 0; | |
94627f6c | 6513 | int br_added = 0; |
c5121837 | 6514 | |
0d547d5f JM |
6515 | bss = wpa_driver_nl80211_drv_init(hapd, params->ifname, |
6516 | params->global_priv, 1, | |
0ecff8d7 | 6517 | params->bssid, params->driver_params); |
a2e40bb6 | 6518 | if (bss == NULL) |
c5121837 | 6519 | return NULL; |
c5121837 | 6520 | |
a2e40bb6 | 6521 | drv = bss->drv; |
7635bfb0 | 6522 | |
cb05808c | 6523 | if (linux_br_get(master_ifname, params->ifname) == 0) { |
94627f6c | 6524 | wpa_printf(MSG_DEBUG, "nl80211: Interface %s is in bridge %s", |
cb05808c AN |
6525 | params->ifname, master_ifname); |
6526 | br_ifindex = if_nametoindex(master_ifname); | |
6527 | os_strlcpy(bss->brname, master_ifname, IFNAMSIZ); | |
6528 | } else if ((params->num_bridge == 0 || !params->bridge[0]) && | |
6529 | linux_master_get(master_ifname, params->ifname) == 0) { | |
6530 | wpa_printf(MSG_DEBUG, "nl80211: Interface %s is in master %s", | |
6531 | params->ifname, master_ifname); | |
6532 | /* start listening for EAPOL on the master interface */ | |
732b1d20 | 6533 | add_ifidx(drv, if_nametoindex(master_ifname), drv->ifindex); |
f2d6c17a DL |
6534 | |
6535 | /* check if master itself is under bridge */ | |
6536 | if (linux_br_get(master_ifname, master_ifname) == 0) { | |
6537 | wpa_printf(MSG_DEBUG, "nl80211: which is in bridge %s", | |
6538 | master_ifname); | |
6539 | br_ifindex = if_nametoindex(master_ifname); | |
6540 | os_strlcpy(bss->brname, master_ifname, IFNAMSIZ); | |
6541 | } | |
94627f6c | 6542 | } else { |
cb05808c | 6543 | master_ifname[0] = '\0'; |
94627f6c | 6544 | } |
cb05808c | 6545 | |
6c6678e7 | 6546 | bss->br_ifindex = br_ifindex; |
94627f6c | 6547 | |
92f475b4 | 6548 | for (i = 0; i < params->num_bridge; i++) { |
94627f6c JM |
6549 | if (params->bridge[i]) { |
6550 | ifindex = if_nametoindex(params->bridge[i]); | |
6551 | if (ifindex) | |
732b1d20 | 6552 | add_ifidx(drv, ifindex, drv->ifindex); |
94627f6c JM |
6553 | if (ifindex == br_ifindex) |
6554 | br_added = 1; | |
6555 | } | |
c5121837 | 6556 | } |
c5121837 | 6557 | |
ad1e68e6 | 6558 | /* start listening for EAPOL on the default AP interface */ |
732b1d20 | 6559 | add_ifidx(drv, drv->ifindex, IFIDX_ANY); |
ad1e68e6 | 6560 | |
5ef8e39f JM |
6561 | if (params->num_bridge && params->bridge[0]) { |
6562 | if (i802_check_bridge(drv, bss, params->bridge[0], | |
6563 | params->ifname) < 0) | |
6564 | goto failed; | |
cb05808c | 6565 | if (os_strcmp(params->bridge[0], master_ifname) != 0) |
5ef8e39f JM |
6566 | br_added = 1; |
6567 | } | |
6568 | ||
6569 | if (!br_added && br_ifindex && | |
6570 | (params->num_bridge == 0 || !params->bridge[0])) | |
732b1d20 | 6571 | add_ifidx(drv, br_ifindex, drv->ifindex); |
94627f6c | 6572 | |
97ed9a06 KP |
6573 | #ifdef CONFIG_LIBNL3_ROUTE |
6574 | if (bss->added_if_into_bridge) { | |
6575 | drv->rtnl_sk = nl_socket_alloc(); | |
6576 | if (drv->rtnl_sk == NULL) { | |
6577 | wpa_printf(MSG_ERROR, "nl80211: Failed to allocate nl_sock"); | |
6578 | goto failed; | |
6579 | } | |
6580 | ||
6581 | if (nl_connect(drv->rtnl_sk, NETLINK_ROUTE)) { | |
6582 | wpa_printf(MSG_ERROR, "nl80211: Failed to connect nl_sock to NETLINK_ROUTE: %s", | |
6583 | strerror(errno)); | |
6584 | goto failed; | |
6585 | } | |
6586 | } | |
6587 | #endif /* CONFIG_LIBNL3_ROUTE */ | |
6588 | ||
ad1e68e6 JM |
6589 | drv->eapol_sock = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_PAE)); |
6590 | if (drv->eapol_sock < 0) { | |
7ac3616d JM |
6591 | wpa_printf(MSG_ERROR, "nl80211: socket(PF_PACKET, SOCK_DGRAM, ETH_P_PAE) failed: %s", |
6592 | strerror(errno)); | |
bbaf0837 | 6593 | goto failed; |
ad1e68e6 JM |
6594 | } |
6595 | ||
6596 | if (eloop_register_read_sock(drv->eapol_sock, handle_eapol, drv, NULL)) | |
6597 | { | |
7ac3616d | 6598 | wpa_printf(MSG_INFO, "nl80211: Could not register read socket for eapol"); |
c5121837 | 6599 | goto failed; |
ad1e68e6 JM |
6600 | } |
6601 | ||
c81eff1a BG |
6602 | if (linux_get_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
6603 | params->own_addr)) | |
bbaf0837 | 6604 | goto failed; |
fee354c7 | 6605 | os_memcpy(drv->perm_addr, params->own_addr, ETH_ALEN); |
c5121837 | 6606 | |
341eebee JB |
6607 | memcpy(bss->addr, params->own_addr, ETH_ALEN); |
6608 | ||
a2e40bb6 | 6609 | return bss; |
c5121837 JM |
6610 | |
6611 | failed: | |
7635bfb0 | 6612 | wpa_driver_nl80211_deinit(bss); |
bbaf0837 JM |
6613 | return NULL; |
6614 | } | |
c5121837 | 6615 | |
c5121837 | 6616 | |
bbaf0837 JM |
6617 | static void i802_deinit(void *priv) |
6618 | { | |
9ebce9c5 JM |
6619 | struct i802_bss *bss = priv; |
6620 | wpa_driver_nl80211_deinit(bss); | |
c5121837 JM |
6621 | } |
6622 | ||
c5121837 | 6623 | |
22a7c9d7 JM |
6624 | static enum nl80211_iftype wpa_driver_nl80211_if_type( |
6625 | enum wpa_driver_if_type type) | |
6626 | { | |
6627 | switch (type) { | |
6628 | case WPA_IF_STATION: | |
9f51b113 | 6629 | return NL80211_IFTYPE_STATION; |
75bde05d JM |
6630 | case WPA_IF_P2P_CLIENT: |
6631 | case WPA_IF_P2P_GROUP: | |
9f51b113 | 6632 | return NL80211_IFTYPE_P2P_CLIENT; |
22a7c9d7 JM |
6633 | case WPA_IF_AP_VLAN: |
6634 | return NL80211_IFTYPE_AP_VLAN; | |
6635 | case WPA_IF_AP_BSS: | |
6636 | return NL80211_IFTYPE_AP; | |
9f51b113 JB |
6637 | case WPA_IF_P2P_GO: |
6638 | return NL80211_IFTYPE_P2P_GO; | |
7aad838c NS |
6639 | case WPA_IF_P2P_DEVICE: |
6640 | return NL80211_IFTYPE_P2P_DEVICE; | |
5b78493f MH |
6641 | case WPA_IF_MESH: |
6642 | return NL80211_IFTYPE_MESH_POINT; | |
98342208 AK |
6643 | default: |
6644 | return -1; | |
22a7c9d7 | 6645 | } |
22a7c9d7 JM |
6646 | } |
6647 | ||
6648 | ||
f2ed8023 JM |
6649 | static int nl80211_addr_in_use(struct nl80211_global *global, const u8 *addr) |
6650 | { | |
6651 | struct wpa_driver_nl80211_data *drv; | |
6652 | dl_list_for_each(drv, &global->interfaces, | |
6653 | struct wpa_driver_nl80211_data, list) { | |
834ee56f | 6654 | if (os_memcmp(addr, drv->first_bss->addr, ETH_ALEN) == 0) |
f2ed8023 JM |
6655 | return 1; |
6656 | } | |
6657 | return 0; | |
6658 | } | |
6659 | ||
6660 | ||
5b78493f | 6661 | static int nl80211_vif_addr(struct wpa_driver_nl80211_data *drv, u8 *new_addr) |
f2ed8023 JM |
6662 | { |
6663 | unsigned int idx; | |
6664 | ||
6665 | if (!drv->global) | |
6666 | return -1; | |
6667 | ||
834ee56f | 6668 | os_memcpy(new_addr, drv->first_bss->addr, ETH_ALEN); |
f2ed8023 | 6669 | for (idx = 0; idx < 64; idx++) { |
834ee56f | 6670 | new_addr[0] = drv->first_bss->addr[0] | 0x02; |
f2ed8023 JM |
6671 | new_addr[0] ^= idx << 2; |
6672 | if (!nl80211_addr_in_use(drv->global, new_addr)) | |
6673 | break; | |
6674 | } | |
6675 | if (idx == 64) | |
6676 | return -1; | |
6677 | ||
5b78493f | 6678 | wpa_printf(MSG_DEBUG, "nl80211: Assigned new virtual interface address " |
f2ed8023 JM |
6679 | MACSTR, MAC2STR(new_addr)); |
6680 | ||
6681 | return 0; | |
6682 | } | |
6683 | ||
6684 | ||
f632e483 AS |
6685 | struct wdev_info { |
6686 | u64 wdev_id; | |
6687 | int wdev_id_set; | |
6688 | u8 macaddr[ETH_ALEN]; | |
6689 | }; | |
6690 | ||
6691 | static int nl80211_wdev_handler(struct nl_msg *msg, void *arg) | |
e472e1b4 AS |
6692 | { |
6693 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
6694 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
f632e483 | 6695 | struct wdev_info *wi = arg; |
e472e1b4 AS |
6696 | |
6697 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
6698 | genlmsg_attrlen(gnlh, 0), NULL); | |
6699 | if (tb[NL80211_ATTR_WDEV]) { | |
f632e483 AS |
6700 | wi->wdev_id = nla_get_u64(tb[NL80211_ATTR_WDEV]); |
6701 | wi->wdev_id_set = 1; | |
e472e1b4 AS |
6702 | } |
6703 | ||
6704 | if (tb[NL80211_ATTR_MAC]) | |
f632e483 | 6705 | os_memcpy(wi->macaddr, nla_data(tb[NL80211_ATTR_MAC]), |
e472e1b4 AS |
6706 | ETH_ALEN); |
6707 | ||
6708 | return NL_SKIP; | |
6709 | } | |
6710 | ||
6711 | ||
7ab68865 | 6712 | static int wpa_driver_nl80211_if_add(void *priv, enum wpa_driver_if_type type, |
8043e725 | 6713 | const char *ifname, const u8 *addr, |
f3585c8a | 6714 | void *bss_ctx, void **drv_priv, |
e17a2477 | 6715 | char *force_ifname, u8 *if_addr, |
d8a3b66d AS |
6716 | const char *bridge, int use_existing, |
6717 | int setup_ap) | |
22a7c9d7 | 6718 | { |
e472e1b4 | 6719 | enum nl80211_iftype nlmode; |
a2e40bb6 FF |
6720 | struct i802_bss *bss = priv; |
6721 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
22a7c9d7 | 6722 | int ifidx; |
2aec4f3c | 6723 | int added = 1; |
22a7c9d7 | 6724 | |
f3585c8a JM |
6725 | if (addr) |
6726 | os_memcpy(if_addr, addr, ETH_ALEN); | |
e472e1b4 AS |
6727 | nlmode = wpa_driver_nl80211_if_type(type); |
6728 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) { | |
f632e483 AS |
6729 | struct wdev_info p2pdev_info; |
6730 | ||
6731 | os_memset(&p2pdev_info, 0, sizeof(p2pdev_info)); | |
e472e1b4 | 6732 | ifidx = nl80211_create_iface(drv, ifname, nlmode, addr, |
f632e483 | 6733 | 0, nl80211_wdev_handler, |
2aec4f3c | 6734 | &p2pdev_info, use_existing); |
f632e483 | 6735 | if (!p2pdev_info.wdev_id_set || ifidx != 0) { |
e472e1b4 AS |
6736 | wpa_printf(MSG_ERROR, "nl80211: Failed to create a P2P Device interface %s", |
6737 | ifname); | |
e472e1b4 AS |
6738 | return -1; |
6739 | } | |
f632e483 AS |
6740 | |
6741 | drv->global->if_add_wdevid = p2pdev_info.wdev_id; | |
6742 | drv->global->if_add_wdevid_set = p2pdev_info.wdev_id_set; | |
6743 | if (!is_zero_ether_addr(p2pdev_info.macaddr)) | |
6744 | os_memcpy(if_addr, p2pdev_info.macaddr, ETH_ALEN); | |
6745 | wpa_printf(MSG_DEBUG, "nl80211: New P2P Device interface %s (0x%llx) created", | |
6746 | ifname, | |
6747 | (long long unsigned int) p2pdev_info.wdev_id); | |
e472e1b4 AS |
6748 | } else { |
6749 | ifidx = nl80211_create_iface(drv, ifname, nlmode, addr, | |
2aec4f3c JM |
6750 | 0, NULL, NULL, use_existing); |
6751 | if (use_existing && ifidx == -ENFILE) { | |
6752 | added = 0; | |
6753 | ifidx = if_nametoindex(ifname); | |
6754 | } else if (ifidx < 0) { | |
e472e1b4 AS |
6755 | return -1; |
6756 | } | |
22a7c9d7 JM |
6757 | } |
6758 | ||
ab7a1add | 6759 | if (!addr) { |
8ea8a89c | 6760 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) |
ab7a1add AS |
6761 | os_memcpy(if_addr, bss->addr, ETH_ALEN); |
6762 | else if (linux_get_ifhwaddr(drv->global->ioctl_sock, | |
8ea8a89c | 6763 | ifname, if_addr) < 0) { |
2aec4f3c JM |
6764 | if (added) |
6765 | nl80211_remove_iface(drv, ifidx); | |
ab7a1add AS |
6766 | return -1; |
6767 | } | |
c55f774d JM |
6768 | } |
6769 | ||
c55f774d JM |
6770 | if (!addr && |
6771 | (type == WPA_IF_P2P_CLIENT || type == WPA_IF_P2P_GROUP || | |
8ea8a89c JM |
6772 | type == WPA_IF_P2P_GO || type == WPA_IF_MESH || |
6773 | type == WPA_IF_STATION)) { | |
6774 | /* Enforce unique address */ | |
ab7a1add | 6775 | u8 new_addr[ETH_ALEN]; |
c55f774d | 6776 | |
ab7a1add | 6777 | if (linux_get_ifhwaddr(drv->global->ioctl_sock, ifname, |
c81eff1a | 6778 | new_addr) < 0) { |
ea39367c MK |
6779 | if (added) |
6780 | nl80211_remove_iface(drv, ifidx); | |
c55f774d JM |
6781 | return -1; |
6782 | } | |
f608081c | 6783 | if (nl80211_addr_in_use(drv->global, new_addr)) { |
c55f774d | 6784 | wpa_printf(MSG_DEBUG, "nl80211: Allocate new address " |
8ea8a89c | 6785 | "for interface %s type %d", ifname, type); |
5b78493f | 6786 | if (nl80211_vif_addr(drv, new_addr) < 0) { |
ea39367c MK |
6787 | if (added) |
6788 | nl80211_remove_iface(drv, ifidx); | |
c55f774d JM |
6789 | return -1; |
6790 | } | |
c81eff1a | 6791 | if (linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, |
c55f774d | 6792 | new_addr) < 0) { |
ea39367c MK |
6793 | if (added) |
6794 | nl80211_remove_iface(drv, ifidx); | |
c55f774d JM |
6795 | return -1; |
6796 | } | |
c55f774d | 6797 | } |
f67eeb5c | 6798 | os_memcpy(if_addr, new_addr, ETH_ALEN); |
c55f774d | 6799 | } |
f3585c8a | 6800 | |
d8a3b66d | 6801 | if (type == WPA_IF_AP_BSS && setup_ap) { |
f5eb9da3 JM |
6802 | struct i802_bss *new_bss = os_zalloc(sizeof(*new_bss)); |
6803 | if (new_bss == NULL) { | |
2aec4f3c JM |
6804 | if (added) |
6805 | nl80211_remove_iface(drv, ifidx); | |
f5eb9da3 JM |
6806 | return -1; |
6807 | } | |
6808 | ||
6809 | if (bridge && | |
6810 | i802_check_bridge(drv, new_bss, bridge, ifname) < 0) { | |
6811 | wpa_printf(MSG_ERROR, "nl80211: Failed to add the new " | |
6812 | "interface %s to a bridge %s", | |
6813 | ifname, bridge); | |
2aec4f3c JM |
6814 | if (added) |
6815 | nl80211_remove_iface(drv, ifidx); | |
f5eb9da3 JM |
6816 | os_free(new_bss); |
6817 | return -1; | |
6818 | } | |
6819 | ||
c81eff1a BG |
6820 | if (linux_set_iface_flags(drv->global->ioctl_sock, ifname, 1)) |
6821 | { | |
ea39367c MK |
6822 | if (added) |
6823 | nl80211_remove_iface(drv, ifidx); | |
07179987 | 6824 | os_free(new_bss); |
22a7c9d7 JM |
6825 | return -1; |
6826 | } | |
a2e40bb6 | 6827 | os_strlcpy(new_bss->ifname, ifname, IFNAMSIZ); |
341eebee | 6828 | os_memcpy(new_bss->addr, if_addr, ETH_ALEN); |
a2e40bb6 FF |
6829 | new_bss->ifindex = ifidx; |
6830 | new_bss->drv = drv; | |
834ee56f KP |
6831 | new_bss->next = drv->first_bss->next; |
6832 | new_bss->freq = drv->first_bss->freq; | |
a5e1eb20 | 6833 | new_bss->ctx = bss_ctx; |
2aec4f3c | 6834 | new_bss->added_if = added; |
834ee56f | 6835 | drv->first_bss->next = new_bss; |
a2e40bb6 FF |
6836 | if (drv_priv) |
6837 | *drv_priv = new_bss; | |
cc7a48d1 | 6838 | nl80211_init_bss(new_bss); |
3dd1d890 YAP |
6839 | |
6840 | /* Subscribe management frames for this WPA_IF_AP_BSS */ | |
6841 | if (nl80211_setup_ap(new_bss)) | |
6842 | return -1; | |
22a7c9d7 | 6843 | } |
22a7c9d7 | 6844 | |
ff6a158b JM |
6845 | if (drv->global) |
6846 | drv->global->if_add_ifindex = ifidx; | |
6847 | ||
d1bb7aed JJ |
6848 | /* |
6849 | * Some virtual interfaces need to process EAPOL packets and events on | |
6850 | * the parent interface. This is used mainly with hostapd. | |
6851 | */ | |
6852 | if (ifidx > 0 && | |
6853 | (drv->hostapd || | |
6854 | nlmode == NL80211_IFTYPE_AP_VLAN || | |
6855 | nlmode == NL80211_IFTYPE_WDS || | |
6856 | nlmode == NL80211_IFTYPE_MONITOR)) | |
732b1d20 | 6857 | add_ifidx(drv, ifidx, IFIDX_ANY); |
b36935be | 6858 | |
22a7c9d7 JM |
6859 | return 0; |
6860 | } | |
6861 | ||
6862 | ||
9ebce9c5 | 6863 | static int wpa_driver_nl80211_if_remove(struct i802_bss *bss, |
22a7c9d7 JM |
6864 | enum wpa_driver_if_type type, |
6865 | const char *ifname) | |
6866 | { | |
a2e40bb6 | 6867 | struct wpa_driver_nl80211_data *drv = bss->drv; |
22a7c9d7 JM |
6868 | int ifindex = if_nametoindex(ifname); |
6869 | ||
2aec4f3c JM |
6870 | wpa_printf(MSG_DEBUG, "nl80211: %s(type=%d ifname=%s) ifindex=%d added_if=%d", |
6871 | __func__, type, ifname, ifindex, bss->added_if); | |
158b090c | 6872 | if (ifindex > 0 && (bss->added_if || bss->ifindex != ifindex)) |
2b72df63 | 6873 | nl80211_remove_iface(drv, ifindex); |
de884303 JM |
6874 | else if (ifindex > 0 && !bss->added_if) { |
6875 | struct wpa_driver_nl80211_data *drv2; | |
6876 | dl_list_for_each(drv2, &drv->global->interfaces, | |
732b1d20 MB |
6877 | struct wpa_driver_nl80211_data, list) { |
6878 | del_ifidx(drv2, ifindex, IFIDX_ANY); | |
6879 | del_ifidx(drv2, IFIDX_ANY, ifindex); | |
6880 | } | |
de884303 | 6881 | } |
c34e618d | 6882 | |
c34e618d FF |
6883 | if (type != WPA_IF_AP_BSS) |
6884 | return 0; | |
6885 | ||
e17a2477 | 6886 | if (bss->added_if_into_bridge) { |
c81eff1a BG |
6887 | if (linux_br_del_if(drv->global->ioctl_sock, bss->brname, |
6888 | bss->ifname) < 0) | |
e17a2477 JM |
6889 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
6890 | "interface %s from bridge %s: %s", | |
6891 | bss->ifname, bss->brname, strerror(errno)); | |
6892 | } | |
6893 | if (bss->added_bridge) { | |
c81eff1a | 6894 | if (linux_br_del(drv->global->ioctl_sock, bss->brname) < 0) |
e17a2477 JM |
6895 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
6896 | "bridge %s: %s", | |
6897 | bss->brname, strerror(errno)); | |
6898 | } | |
a2e40bb6 | 6899 | |
834ee56f | 6900 | if (bss != drv->first_bss) { |
8546ea19 | 6901 | struct i802_bss *tbss; |
a2e40bb6 | 6902 | |
2aec4f3c | 6903 | wpa_printf(MSG_DEBUG, "nl80211: Not the first BSS - remove it"); |
834ee56f | 6904 | for (tbss = drv->first_bss; tbss; tbss = tbss->next) { |
8546ea19 JM |
6905 | if (tbss->next == bss) { |
6906 | tbss->next = bss->next; | |
3dd1d890 YAP |
6907 | /* Unsubscribe management frames */ |
6908 | nl80211_teardown_ap(bss); | |
cc7a48d1 | 6909 | nl80211_destroy_bss(bss); |
5c9da160 MB |
6910 | if (!bss->added_if) |
6911 | i802_set_iface_flags(bss, 0); | |
8546ea19 JM |
6912 | os_free(bss); |
6913 | bss = NULL; | |
6914 | break; | |
6915 | } | |
22a7c9d7 | 6916 | } |
8546ea19 JM |
6917 | if (bss) |
6918 | wpa_printf(MSG_INFO, "nl80211: %s - could not find " | |
6919 | "BSS %p in the list", __func__, bss); | |
390e489c | 6920 | } else { |
2aec4f3c | 6921 | wpa_printf(MSG_DEBUG, "nl80211: First BSS - reassign context"); |
390e489c | 6922 | nl80211_teardown_ap(bss); |
2aec4f3c | 6923 | if (!bss->added_if && !drv->first_bss->next) |
a70cd0db | 6924 | wpa_driver_nl80211_del_beacon(bss); |
390e489c | 6925 | nl80211_destroy_bss(bss); |
2aec4f3c JM |
6926 | if (!bss->added_if) |
6927 | i802_set_iface_flags(bss, 0); | |
390e489c KP |
6928 | if (drv->first_bss->next) { |
6929 | drv->first_bss = drv->first_bss->next; | |
6930 | drv->ctx = drv->first_bss->ctx; | |
6931 | os_free(bss); | |
6932 | } else { | |
6933 | wpa_printf(MSG_DEBUG, "nl80211: No second BSS to reassign context to"); | |
6934 | } | |
22a7c9d7 | 6935 | } |
22a7c9d7 JM |
6936 | |
6937 | return 0; | |
6938 | } | |
6939 | ||
6940 | ||
55777702 JM |
6941 | static int cookie_handler(struct nl_msg *msg, void *arg) |
6942 | { | |
6943 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
6944 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
6945 | u64 *cookie = arg; | |
6946 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
6947 | genlmsg_attrlen(gnlh, 0), NULL); | |
6948 | if (tb[NL80211_ATTR_COOKIE]) | |
6949 | *cookie = nla_get_u64(tb[NL80211_ATTR_COOKIE]); | |
6950 | return NL_SKIP; | |
6951 | } | |
6952 | ||
6953 | ||
88df0ef7 | 6954 | static int nl80211_send_frame_cmd(struct i802_bss *bss, |
5dfca53f JB |
6955 | unsigned int freq, unsigned int wait, |
6956 | const u8 *buf, size_t buf_len, | |
88df0ef7 | 6957 | u64 *cookie_out, int no_cck, int no_ack, |
2d3943ce AO |
6958 | int offchanok, const u16 *csa_offs, |
6959 | size_t csa_offs_len) | |
9884f9cc | 6960 | { |
88df0ef7 | 6961 | struct wpa_driver_nl80211_data *drv = bss->drv; |
9884f9cc JB |
6962 | struct nl_msg *msg; |
6963 | u64 cookie; | |
6964 | int ret = -1; | |
6965 | ||
cc2ada86 | 6966 | wpa_printf(MSG_MSGDUMP, "nl80211: CMD_FRAME freq=%u wait=%u no_cck=%d " |
2e3e4566 JM |
6967 | "no_ack=%d offchanok=%d", |
6968 | freq, wait, no_cck, no_ack, offchanok); | |
c91f796f | 6969 | wpa_hexdump(MSG_MSGDUMP, "CMD_FRAME", buf, buf_len); |
9884f9cc | 6970 | |
56f77852 | 6971 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_FRAME)) || |
a862e4a3 JM |
6972 | (freq && nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || |
6973 | (wait && nla_put_u32(msg, NL80211_ATTR_DURATION, wait)) || | |
6974 | (offchanok && ((drv->capa.flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX) || | |
6975 | drv->test_use_roc_tx) && | |
6976 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) || | |
6977 | (no_cck && nla_put_flag(msg, NL80211_ATTR_TX_NO_CCK_RATE)) || | |
6978 | (no_ack && nla_put_flag(msg, NL80211_ATTR_DONT_WAIT_FOR_ACK)) || | |
2d3943ce AO |
6979 | (csa_offs && nla_put(msg, NL80211_ATTR_CSA_C_OFFSETS_TX, |
6980 | csa_offs_len * sizeof(u16), csa_offs)) || | |
a862e4a3 JM |
6981 | nla_put(msg, NL80211_ATTR_FRAME, buf_len, buf)) |
6982 | goto fail; | |
9884f9cc JB |
6983 | |
6984 | cookie = 0; | |
6985 | ret = send_and_recv_msgs(drv, msg, cookie_handler, &cookie); | |
6986 | msg = NULL; | |
6987 | if (ret) { | |
6988 | wpa_printf(MSG_DEBUG, "nl80211: Frame command failed: ret=%d " | |
a05225c8 JM |
6989 | "(%s) (freq=%u wait=%u)", ret, strerror(-ret), |
6990 | freq, wait); | |
a862e4a3 JM |
6991 | } else { |
6992 | wpa_printf(MSG_MSGDUMP, "nl80211: Frame TX command accepted%s; " | |
6993 | "cookie 0x%llx", no_ack ? " (no ACK)" : "", | |
6994 | (long long unsigned int) cookie); | |
9884f9cc | 6995 | |
a862e4a3 JM |
6996 | if (cookie_out) |
6997 | *cookie_out = no_ack ? (u64) -1 : cookie; | |
759a8a3a JM |
6998 | |
6999 | if (drv->num_send_action_cookies == MAX_SEND_ACTION_COOKIES) { | |
7000 | wpa_printf(MSG_DEBUG, | |
7001 | "nl80211: Drop oldest pending send action cookie 0x%llx", | |
7002 | (long long unsigned int) | |
7003 | drv->send_action_cookies[0]); | |
7004 | os_memmove(&drv->send_action_cookies[0], | |
7005 | &drv->send_action_cookies[1], | |
7006 | (MAX_SEND_ACTION_COOKIES - 1) * | |
7007 | sizeof(u64)); | |
7008 | drv->num_send_action_cookies--; | |
7009 | } | |
7010 | drv->send_action_cookies[drv->num_send_action_cookies] = cookie; | |
7011 | drv->num_send_action_cookies++; | |
a862e4a3 | 7012 | } |
9884f9cc | 7013 | |
a862e4a3 | 7014 | fail: |
9884f9cc JB |
7015 | nlmsg_free(msg); |
7016 | return ret; | |
7017 | } | |
7018 | ||
7019 | ||
9ebce9c5 JM |
7020 | static int wpa_driver_nl80211_send_action(struct i802_bss *bss, |
7021 | unsigned int freq, | |
190b9062 | 7022 | unsigned int wait_time, |
58f6fbe0 JM |
7023 | const u8 *dst, const u8 *src, |
7024 | const u8 *bssid, | |
b106173a JM |
7025 | const u8 *data, size_t data_len, |
7026 | int no_cck) | |
58f6fbe0 | 7027 | { |
a2e40bb6 | 7028 | struct wpa_driver_nl80211_data *drv = bss->drv; |
58f6fbe0 | 7029 | int ret = -1; |
58f6fbe0 JM |
7030 | u8 *buf; |
7031 | struct ieee80211_hdr *hdr; | |
58f6fbe0 | 7032 | |
5dfca53f | 7033 | wpa_printf(MSG_DEBUG, "nl80211: Send Action frame (ifindex=%d, " |
55231068 JM |
7034 | "freq=%u MHz wait=%d ms no_cck=%d)", |
7035 | drv->ifindex, freq, wait_time, no_cck); | |
58f6fbe0 JM |
7036 | |
7037 | buf = os_zalloc(24 + data_len); | |
7038 | if (buf == NULL) | |
7039 | return ret; | |
7040 | os_memcpy(buf + 24, data, data_len); | |
7041 | hdr = (struct ieee80211_hdr *) buf; | |
7042 | hdr->frame_control = | |
7043 | IEEE80211_FC(WLAN_FC_TYPE_MGMT, WLAN_FC_STYPE_ACTION); | |
7044 | os_memcpy(hdr->addr1, dst, ETH_ALEN); | |
7045 | os_memcpy(hdr->addr2, src, ETH_ALEN); | |
7046 | os_memcpy(hdr->addr3, bssid, ETH_ALEN); | |
7047 | ||
8331c9b3 VK |
7048 | if (os_memcmp(bss->addr, src, ETH_ALEN) != 0) { |
7049 | wpa_printf(MSG_DEBUG, "nl80211: Use random TA " MACSTR, | |
7050 | MAC2STR(src)); | |
7051 | os_memcpy(bss->rand_addr, src, ETH_ALEN); | |
7052 | } else { | |
7053 | os_memset(bss->rand_addr, 0, ETH_ALEN); | |
7054 | } | |
7055 | ||
f78f2785 JM |
7056 | if (is_ap_interface(drv->nlmode) && |
7057 | (!(drv->capa.flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX) || | |
7058 | (int) freq == bss->freq || drv->device_ap_sme || | |
7059 | !drv->use_monitor)) | |
9ebce9c5 JM |
7060 | ret = wpa_driver_nl80211_send_mlme(bss, buf, 24 + data_len, |
7061 | 0, freq, no_cck, 1, | |
2d3943ce | 7062 | wait_time, NULL, 0); |
9884f9cc | 7063 | else |
88df0ef7 | 7064 | ret = nl80211_send_frame_cmd(bss, freq, wait_time, buf, |
5dfca53f | 7065 | 24 + data_len, |
b106173a | 7066 | &drv->send_action_cookie, |
2d3943ce | 7067 | no_cck, 0, 1, NULL, 0); |
58f6fbe0 | 7068 | |
f8bf1421 | 7069 | os_free(buf); |
58f6fbe0 JM |
7070 | return ret; |
7071 | } | |
7072 | ||
7073 | ||
759a8a3a | 7074 | static void nl80211_frame_wait_cancel(struct i802_bss *bss, u64 cookie) |
5dfca53f | 7075 | { |
5dfca53f JB |
7076 | struct wpa_driver_nl80211_data *drv = bss->drv; |
7077 | struct nl_msg *msg; | |
7078 | int ret; | |
7079 | ||
316a9e4d | 7080 | wpa_printf(MSG_DEBUG, "nl80211: Cancel TX frame wait: cookie=0x%llx", |
759a8a3a | 7081 | (long long unsigned int) cookie); |
56f77852 | 7082 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_FRAME_WAIT_CANCEL)) || |
759a8a3a | 7083 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) { |
a862e4a3 JM |
7084 | nlmsg_free(msg); |
7085 | return; | |
7086 | } | |
5dfca53f JB |
7087 | |
7088 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
5dfca53f JB |
7089 | if (ret) |
7090 | wpa_printf(MSG_DEBUG, "nl80211: wait cancel failed: ret=%d " | |
7091 | "(%s)", ret, strerror(-ret)); | |
5dfca53f JB |
7092 | } |
7093 | ||
7094 | ||
759a8a3a JM |
7095 | static void wpa_driver_nl80211_send_action_cancel_wait(void *priv) |
7096 | { | |
7097 | struct i802_bss *bss = priv; | |
7098 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
7099 | unsigned int i; | |
7100 | u64 cookie; | |
7101 | ||
7102 | /* Cancel the last pending TX cookie */ | |
7103 | nl80211_frame_wait_cancel(bss, drv->send_action_cookie); | |
7104 | ||
7105 | /* | |
7106 | * Cancel the other pending TX cookies, if any. This is needed since | |
7107 | * the driver may keep a list of all pending offchannel TX operations | |
7108 | * and free up the radio only once they have expired or cancelled. | |
7109 | */ | |
7110 | for (i = drv->num_send_action_cookies; i > 0; i--) { | |
7111 | cookie = drv->send_action_cookies[i - 1]; | |
7112 | if (cookie != drv->send_action_cookie) | |
7113 | nl80211_frame_wait_cancel(bss, cookie); | |
7114 | } | |
7115 | drv->num_send_action_cookies = 0; | |
7116 | } | |
7117 | ||
7118 | ||
55777702 JM |
7119 | static int wpa_driver_nl80211_remain_on_channel(void *priv, unsigned int freq, |
7120 | unsigned int duration) | |
7121 | { | |
a2e40bb6 FF |
7122 | struct i802_bss *bss = priv; |
7123 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
55777702 JM |
7124 | struct nl_msg *msg; |
7125 | int ret; | |
7126 | u64 cookie; | |
7127 | ||
56f77852 | 7128 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_REMAIN_ON_CHANNEL)) || |
a862e4a3 JM |
7129 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
7130 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) { | |
7131 | nlmsg_free(msg); | |
7132 | return -1; | |
7133 | } | |
55777702 JM |
7134 | |
7135 | cookie = 0; | |
7136 | ret = send_and_recv_msgs(drv, msg, cookie_handler, &cookie); | |
7137 | if (ret == 0) { | |
7138 | wpa_printf(MSG_DEBUG, "nl80211: Remain-on-channel cookie " | |
7139 | "0x%llx for freq=%u MHz duration=%u", | |
7140 | (long long unsigned int) cookie, freq, duration); | |
7141 | drv->remain_on_chan_cookie = cookie; | |
531f0331 | 7142 | drv->pending_remain_on_chan = 1; |
55777702 JM |
7143 | return 0; |
7144 | } | |
7145 | wpa_printf(MSG_DEBUG, "nl80211: Failed to request remain-on-channel " | |
15ed5535 JM |
7146 | "(freq=%d duration=%u): %d (%s)", |
7147 | freq, duration, ret, strerror(-ret)); | |
55777702 JM |
7148 | return -1; |
7149 | } | |
7150 | ||
7151 | ||
7152 | static int wpa_driver_nl80211_cancel_remain_on_channel(void *priv) | |
7153 | { | |
a2e40bb6 FF |
7154 | struct i802_bss *bss = priv; |
7155 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
55777702 JM |
7156 | struct nl_msg *msg; |
7157 | int ret; | |
7158 | ||
7159 | if (!drv->pending_remain_on_chan) { | |
7160 | wpa_printf(MSG_DEBUG, "nl80211: No pending remain-on-channel " | |
7161 | "to cancel"); | |
7162 | return -1; | |
7163 | } | |
7164 | ||
7165 | wpa_printf(MSG_DEBUG, "nl80211: Cancel remain-on-channel with cookie " | |
7166 | "0x%llx", | |
7167 | (long long unsigned int) drv->remain_on_chan_cookie); | |
7168 | ||
56f77852 JM |
7169 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL); |
7170 | if (!msg || | |
a862e4a3 JM |
7171 | nla_put_u64(msg, NL80211_ATTR_COOKIE, drv->remain_on_chan_cookie)) { |
7172 | nlmsg_free(msg); | |
7173 | return -1; | |
7174 | } | |
55777702 JM |
7175 | |
7176 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
7177 | if (ret == 0) | |
7178 | return 0; | |
7179 | wpa_printf(MSG_DEBUG, "nl80211: Failed to cancel remain-on-channel: " | |
7180 | "%d (%s)", ret, strerror(-ret)); | |
55777702 JM |
7181 | return -1; |
7182 | } | |
7183 | ||
7184 | ||
9ebce9c5 | 7185 | static int wpa_driver_nl80211_probe_req_report(struct i802_bss *bss, int report) |
504e905c | 7186 | { |
a2e40bb6 | 7187 | struct wpa_driver_nl80211_data *drv = bss->drv; |
504e905c | 7188 | |
5582a5d1 | 7189 | if (!report) { |
0d891981 | 7190 | if (bss->nl_preq && drv->device_ap_sme && |
b8d87ed2 AP |
7191 | is_ap_interface(drv->nlmode) && !bss->in_deinit && |
7192 | !bss->static_ap) { | |
0d891981 JM |
7193 | /* |
7194 | * Do not disable Probe Request reporting that was | |
7195 | * enabled in nl80211_setup_ap(). | |
7196 | */ | |
7197 | wpa_printf(MSG_DEBUG, "nl80211: Skip disabling of " | |
7198 | "Probe Request reporting nl_preq=%p while " | |
7199 | "in AP mode", bss->nl_preq); | |
7200 | } else if (bss->nl_preq) { | |
36488c05 JM |
7201 | wpa_printf(MSG_DEBUG, "nl80211: Disable Probe Request " |
7202 | "reporting nl_preq=%p", bss->nl_preq); | |
5f65e9f7 | 7203 | nl80211_destroy_eloop_handle(&bss->nl_preq); |
5582a5d1 JB |
7204 | } |
7205 | return 0; | |
7206 | } | |
7207 | ||
481234cf | 7208 | if (bss->nl_preq) { |
5582a5d1 | 7209 | wpa_printf(MSG_DEBUG, "nl80211: Probe Request reporting " |
36488c05 | 7210 | "already on! nl_preq=%p", bss->nl_preq); |
5582a5d1 JB |
7211 | return 0; |
7212 | } | |
7213 | ||
481234cf JM |
7214 | bss->nl_preq = nl_create_handle(drv->global->nl_cb, "preq"); |
7215 | if (bss->nl_preq == NULL) | |
5582a5d1 | 7216 | return -1; |
36488c05 JM |
7217 | wpa_printf(MSG_DEBUG, "nl80211: Enable Probe Request " |
7218 | "reporting nl_preq=%p", bss->nl_preq); | |
5582a5d1 | 7219 | |
481234cf | 7220 | if (nl80211_register_frame(bss, bss->nl_preq, |
5582a5d1 JB |
7221 | (WLAN_FC_TYPE_MGMT << 2) | |
7222 | (WLAN_FC_STYPE_PROBE_REQ << 4), | |
a92dfde8 JB |
7223 | NULL, 0) < 0) |
7224 | goto out_err; | |
5582a5d1 | 7225 | |
5f65e9f7 JB |
7226 | nl80211_register_eloop_read(&bss->nl_preq, |
7227 | wpa_driver_nl80211_event_receive, | |
7228 | bss->nl_cb); | |
5582a5d1 | 7229 | |
504e905c | 7230 | return 0; |
5582a5d1 | 7231 | |
a92dfde8 | 7232 | out_err: |
221a59c9 | 7233 | nl_destroy_handles(&bss->nl_preq); |
5582a5d1 | 7234 | return -1; |
504e905c JM |
7235 | } |
7236 | ||
7237 | ||
4e5cb1a3 JM |
7238 | static int nl80211_disable_11b_rates(struct wpa_driver_nl80211_data *drv, |
7239 | int ifindex, int disabled) | |
7240 | { | |
7241 | struct nl_msg *msg; | |
7242 | struct nlattr *bands, *band; | |
7243 | int ret; | |
7244 | ||
3e208481 JM |
7245 | wpa_printf(MSG_DEBUG, |
7246 | "nl80211: NL80211_CMD_SET_TX_BITRATE_MASK (ifindex=%d %s)", | |
7247 | ifindex, disabled ? "NL80211_TXRATE_LEGACY=OFDM-only" : | |
7248 | "no NL80211_TXRATE_LEGACY constraint"); | |
7249 | ||
95376e1a JM |
7250 | msg = nl80211_ifindex_msg(drv, ifindex, 0, |
7251 | NL80211_CMD_SET_TX_BITRATE_MASK); | |
4e5cb1a3 JM |
7252 | if (!msg) |
7253 | return -1; | |
7254 | ||
4e5cb1a3 JM |
7255 | bands = nla_nest_start(msg, NL80211_ATTR_TX_RATES); |
7256 | if (!bands) | |
a862e4a3 | 7257 | goto fail; |
4e5cb1a3 JM |
7258 | |
7259 | /* | |
7260 | * Disable 2 GHz rates 1, 2, 5.5, 11 Mbps by masking out everything | |
7261 | * else apart from 6, 9, 12, 18, 24, 36, 48, 54 Mbps from non-MCS | |
7262 | * rates. All 5 GHz rates are left enabled. | |
7263 | */ | |
7264 | band = nla_nest_start(msg, NL80211_BAND_2GHZ); | |
a862e4a3 JM |
7265 | if (!band || |
7266 | (disabled && nla_put(msg, NL80211_TXRATE_LEGACY, 8, | |
7267 | "\x0c\x12\x18\x24\x30\x48\x60\x6c"))) | |
7268 | goto fail; | |
4e5cb1a3 JM |
7269 | nla_nest_end(msg, band); |
7270 | ||
7271 | nla_nest_end(msg, bands); | |
7272 | ||
7273 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
4e5cb1a3 JM |
7274 | if (ret) { |
7275 | wpa_printf(MSG_DEBUG, "nl80211: Set TX rates failed: ret=%d " | |
7276 | "(%s)", ret, strerror(-ret)); | |
1d0c6fb1 JM |
7277 | } else |
7278 | drv->disabled_11b_rates = disabled; | |
4e5cb1a3 JM |
7279 | |
7280 | return ret; | |
7281 | ||
a862e4a3 | 7282 | fail: |
4e5cb1a3 JM |
7283 | nlmsg_free(msg); |
7284 | return -1; | |
7285 | } | |
7286 | ||
7287 | ||
af473088 JM |
7288 | static int wpa_driver_nl80211_deinit_ap(void *priv) |
7289 | { | |
a2e40bb6 FF |
7290 | struct i802_bss *bss = priv; |
7291 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
b1f625e0 | 7292 | if (!is_ap_interface(drv->nlmode)) |
af473088 | 7293 | return -1; |
a70cd0db | 7294 | wpa_driver_nl80211_del_beacon(bss); |
9bc5cfa3 | 7295 | bss->beacon_set = 0; |
60b13c20 IP |
7296 | |
7297 | /* | |
7298 | * If the P2P GO interface was dynamically added, then it is | |
7299 | * possible that the interface change to station is not possible. | |
7300 | */ | |
7301 | if (drv->nlmode == NL80211_IFTYPE_P2P_GO && bss->if_dynamic) | |
7302 | return 0; | |
7303 | ||
b1f625e0 | 7304 | return wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_STATION); |
af473088 JM |
7305 | } |
7306 | ||
7307 | ||
695c7038 SW |
7308 | static int wpa_driver_nl80211_stop_ap(void *priv) |
7309 | { | |
7310 | struct i802_bss *bss = priv; | |
7311 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
7312 | if (!is_ap_interface(drv->nlmode)) | |
7313 | return -1; | |
a70cd0db | 7314 | wpa_driver_nl80211_del_beacon(bss); |
695c7038 SW |
7315 | bss->beacon_set = 0; |
7316 | return 0; | |
7317 | } | |
7318 | ||
7319 | ||
3c29244e EP |
7320 | static int wpa_driver_nl80211_deinit_p2p_cli(void *priv) |
7321 | { | |
7322 | struct i802_bss *bss = priv; | |
7323 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
7324 | if (drv->nlmode != NL80211_IFTYPE_P2P_CLIENT) | |
7325 | return -1; | |
60b13c20 IP |
7326 | |
7327 | /* | |
7328 | * If the P2P Client interface was dynamically added, then it is | |
7329 | * possible that the interface change to station is not possible. | |
7330 | */ | |
7331 | if (bss->if_dynamic) | |
7332 | return 0; | |
7333 | ||
3c29244e EP |
7334 | return wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_STATION); |
7335 | } | |
7336 | ||
7337 | ||
207ef3fb JM |
7338 | static void wpa_driver_nl80211_resume(void *priv) |
7339 | { | |
a2e40bb6 | 7340 | struct i802_bss *bss = priv; |
e8dc205f | 7341 | enum nl80211_iftype nlmode = nl80211_get_ifmode(bss); |
91724d6f AS |
7342 | |
7343 | if (i802_set_iface_flags(bss, 1)) | |
7344 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set interface up on resume event"); | |
e8dc205f AO |
7345 | |
7346 | if (is_p2p_net_interface(nlmode)) | |
7347 | nl80211_disable_11b_rates(bss->drv, bss->drv->ifindex, 1); | |
207ef3fb JM |
7348 | } |
7349 | ||
7350 | ||
b625473c JM |
7351 | static int nl80211_signal_monitor(void *priv, int threshold, int hysteresis) |
7352 | { | |
7353 | struct i802_bss *bss = priv; | |
7354 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8970bae8 JB |
7355 | struct nl_msg *msg; |
7356 | struct nlattr *cqm; | |
b625473c JM |
7357 | |
7358 | wpa_printf(MSG_DEBUG, "nl80211: Signal monitor threshold=%d " | |
7359 | "hysteresis=%d", threshold, hysteresis); | |
7360 | ||
13f83980 | 7361 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_CQM)) || |
a862e4a3 JM |
7362 | !(cqm = nla_nest_start(msg, NL80211_ATTR_CQM)) || |
7363 | nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THOLD, threshold) || | |
7364 | nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_HYST, hysteresis)) { | |
7365 | nlmsg_free(msg); | |
7366 | return -1; | |
7367 | } | |
8970bae8 | 7368 | nla_nest_end(msg, cqm); |
21270bb4 | 7369 | |
a862e4a3 | 7370 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
b625473c JM |
7371 | } |
7372 | ||
7373 | ||
2cc8d8f4 AO |
7374 | static int get_channel_width(struct nl_msg *msg, void *arg) |
7375 | { | |
7376 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
7377 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
7378 | struct wpa_signal_info *sig_change = arg; | |
7379 | ||
7380 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
7381 | genlmsg_attrlen(gnlh, 0), NULL); | |
7382 | ||
7383 | sig_change->center_frq1 = -1; | |
7384 | sig_change->center_frq2 = -1; | |
7385 | sig_change->chanwidth = CHAN_WIDTH_UNKNOWN; | |
7386 | ||
7387 | if (tb[NL80211_ATTR_CHANNEL_WIDTH]) { | |
7388 | sig_change->chanwidth = convert2width( | |
7389 | nla_get_u32(tb[NL80211_ATTR_CHANNEL_WIDTH])); | |
7390 | if (tb[NL80211_ATTR_CENTER_FREQ1]) | |
7391 | sig_change->center_frq1 = | |
7392 | nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ1]); | |
7393 | if (tb[NL80211_ATTR_CENTER_FREQ2]) | |
7394 | sig_change->center_frq2 = | |
7395 | nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ2]); | |
7396 | } | |
7397 | ||
7398 | return NL_SKIP; | |
7399 | } | |
7400 | ||
7401 | ||
7402 | static int nl80211_get_channel_width(struct wpa_driver_nl80211_data *drv, | |
7403 | struct wpa_signal_info *sig) | |
7404 | { | |
7405 | struct nl_msg *msg; | |
7406 | ||
9725b784 | 7407 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_GET_INTERFACE); |
2cc8d8f4 | 7408 | return send_and_recv_msgs(drv, msg, get_channel_width, sig); |
2cc8d8f4 AO |
7409 | } |
7410 | ||
7411 | ||
1c5c7273 PS |
7412 | static int nl80211_signal_poll(void *priv, struct wpa_signal_info *si) |
7413 | { | |
7414 | struct i802_bss *bss = priv; | |
7415 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
7416 | int res; | |
7417 | ||
7418 | os_memset(si, 0, sizeof(*si)); | |
7419 | res = nl80211_get_link_signal(drv, si); | |
1d6955e6 JM |
7420 | if (res) { |
7421 | if (drv->nlmode != NL80211_IFTYPE_ADHOC && | |
7422 | drv->nlmode != NL80211_IFTYPE_MESH_POINT) | |
7423 | return res; | |
7424 | si->current_signal = 0; | |
7425 | } | |
1c5c7273 | 7426 | |
2cc8d8f4 AO |
7427 | res = nl80211_get_channel_width(drv, si); |
7428 | if (res != 0) | |
7429 | return res; | |
7430 | ||
1c5c7273 PS |
7431 | return nl80211_get_link_noise(drv, si); |
7432 | } | |
7433 | ||
7434 | ||
b91ab76e JM |
7435 | static int nl80211_send_frame(void *priv, const u8 *data, size_t data_len, |
7436 | int encrypt) | |
7437 | { | |
7438 | struct i802_bss *bss = priv; | |
55231068 | 7439 | return wpa_driver_nl80211_send_frame(bss, data, data_len, encrypt, 0, |
2d3943ce | 7440 | 0, 0, 0, 0, NULL, 0); |
b91ab76e JM |
7441 | } |
7442 | ||
7443 | ||
c55f774d JM |
7444 | static int nl80211_set_param(void *priv, const char *param) |
7445 | { | |
ef24ad3e JM |
7446 | struct i802_bss *bss = priv; |
7447 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
7448 | ||
c55f774d JM |
7449 | if (param == NULL) |
7450 | return 0; | |
99a94f55 | 7451 | wpa_printf(MSG_DEBUG, "nl80211: driver param='%s'", param); |
c55f774d JM |
7452 | |
7453 | #ifdef CONFIG_P2P | |
7454 | if (os_strstr(param, "use_p2p_group_interface=1")) { | |
7455 | wpa_printf(MSG_DEBUG, "nl80211: Use separate P2P group " | |
7456 | "interface"); | |
7457 | drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_CONCURRENT; | |
7458 | drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_MGMT_AND_NON_P2P; | |
7459 | } | |
7460 | #endif /* CONFIG_P2P */ | |
7461 | ||
ef24ad3e | 7462 | if (os_strstr(param, "use_monitor=1")) |
327b01d3 | 7463 | drv->use_monitor = 1; |
327b01d3 JM |
7464 | |
7465 | if (os_strstr(param, "force_connect_cmd=1")) { | |
327b01d3 | 7466 | drv->capa.flags &= ~WPA_DRIVER_FLAGS_SME; |
b497a212 | 7467 | drv->force_connect_cmd = 1; |
327b01d3 JM |
7468 | } |
7469 | ||
ef24ad3e | 7470 | if (os_strstr(param, "force_bss_selection=1")) |
4d584d8c | 7471 | drv->capa.flags |= WPA_DRIVER_FLAGS_BSS_SELECTION; |
4d584d8c | 7472 | |
64abb725 | 7473 | if (os_strstr(param, "no_offchannel_tx=1")) { |
64abb725 JM |
7474 | drv->capa.flags &= ~WPA_DRIVER_FLAGS_OFFCHANNEL_TX; |
7475 | drv->test_use_roc_tx = 1; | |
7476 | } | |
7477 | ||
c55f774d JM |
7478 | return 0; |
7479 | } | |
7480 | ||
7481 | ||
45e3fc72 | 7482 | static void * nl80211_global_init(void *ctx) |
f2ed8023 JM |
7483 | { |
7484 | struct nl80211_global *global; | |
36d84860 BG |
7485 | struct netlink_config *cfg; |
7486 | ||
f2ed8023 JM |
7487 | global = os_zalloc(sizeof(*global)); |
7488 | if (global == NULL) | |
7489 | return NULL; | |
45e3fc72 | 7490 | global->ctx = ctx; |
c81eff1a | 7491 | global->ioctl_sock = -1; |
f2ed8023 | 7492 | dl_list_init(&global->interfaces); |
ff6a158b | 7493 | global->if_add_ifindex = -1; |
36d84860 BG |
7494 | |
7495 | cfg = os_zalloc(sizeof(*cfg)); | |
7496 | if (cfg == NULL) | |
7497 | goto err; | |
7498 | ||
7499 | cfg->ctx = global; | |
7500 | cfg->newlink_cb = wpa_driver_nl80211_event_rtm_newlink; | |
7501 | cfg->dellink_cb = wpa_driver_nl80211_event_rtm_dellink; | |
7502 | global->netlink = netlink_init(cfg); | |
7503 | if (global->netlink == NULL) { | |
7504 | os_free(cfg); | |
7505 | goto err; | |
7506 | } | |
7507 | ||
2a7b66f5 BG |
7508 | if (wpa_driver_nl80211_init_nl_global(global) < 0) |
7509 | goto err; | |
7510 | ||
c81eff1a BG |
7511 | global->ioctl_sock = socket(PF_INET, SOCK_DGRAM, 0); |
7512 | if (global->ioctl_sock < 0) { | |
7ac3616d JM |
7513 | wpa_printf(MSG_ERROR, "nl80211: socket(PF_INET,SOCK_DGRAM) failed: %s", |
7514 | strerror(errno)); | |
c81eff1a BG |
7515 | goto err; |
7516 | } | |
7517 | ||
f2ed8023 | 7518 | return global; |
36d84860 BG |
7519 | |
7520 | err: | |
7521 | nl80211_global_deinit(global); | |
7522 | return NULL; | |
f2ed8023 JM |
7523 | } |
7524 | ||
7525 | ||
7526 | static void nl80211_global_deinit(void *priv) | |
7527 | { | |
7528 | struct nl80211_global *global = priv; | |
7529 | if (global == NULL) | |
7530 | return; | |
7531 | if (!dl_list_empty(&global->interfaces)) { | |
7532 | wpa_printf(MSG_ERROR, "nl80211: %u interface(s) remain at " | |
7533 | "nl80211_global_deinit", | |
7534 | dl_list_len(&global->interfaces)); | |
7535 | } | |
36d84860 BG |
7536 | |
7537 | if (global->netlink) | |
7538 | netlink_deinit(global->netlink); | |
7539 | ||
276e2d67 BG |
7540 | nl_destroy_handles(&global->nl); |
7541 | ||
5f65e9f7 JB |
7542 | if (global->nl_event) |
7543 | nl80211_destroy_eloop_handle(&global->nl_event); | |
d6c9aab8 JB |
7544 | |
7545 | nl_cb_put(global->nl_cb); | |
2a7b66f5 | 7546 | |
c81eff1a BG |
7547 | if (global->ioctl_sock >= 0) |
7548 | close(global->ioctl_sock); | |
7549 | ||
f2ed8023 JM |
7550 | os_free(global); |
7551 | } | |
7552 | ||
7553 | ||
6859f1cb BG |
7554 | static const char * nl80211_get_radio_name(void *priv) |
7555 | { | |
7556 | struct i802_bss *bss = priv; | |
7557 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
7558 | return drv->phyname; | |
7559 | } | |
7560 | ||
7561 | ||
061a3d3d VK |
7562 | static int nl80211_pmkid(struct i802_bss *bss, int cmd, |
7563 | struct wpa_pmkid_params *params) | |
a6efc65d JM |
7564 | { |
7565 | struct nl_msg *msg; | |
7566 | ||
13f83980 | 7567 | if (!(msg = nl80211_bss_msg(bss, 0, cmd)) || |
061a3d3d VK |
7568 | (params->pmkid && |
7569 | nla_put(msg, NL80211_ATTR_PMKID, 16, params->pmkid)) || | |
7570 | (params->bssid && | |
7571 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid)) || | |
7572 | (params->ssid_len && | |
7573 | nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid)) || | |
7574 | (params->fils_cache_id && | |
7575 | nla_put(msg, NL80211_ATTR_FILS_CACHE_ID, 2, | |
7576 | params->fils_cache_id)) || | |
7577 | (params->pmk_len && | |
7578 | nla_put(msg, NL80211_ATTR_PMK, params->pmk_len, params->pmk))) { | |
a862e4a3 JM |
7579 | nlmsg_free(msg); |
7580 | return -ENOBUFS; | |
7581 | } | |
a6efc65d JM |
7582 | |
7583 | return send_and_recv_msgs(bss->drv, msg, NULL, NULL); | |
a6efc65d JM |
7584 | } |
7585 | ||
7586 | ||
6fbb5414 | 7587 | static int nl80211_add_pmkid(void *priv, struct wpa_pmkid_params *params) |
a6efc65d JM |
7588 | { |
7589 | struct i802_bss *bss = priv; | |
061a3d3d VK |
7590 | |
7591 | if (params->bssid) | |
7592 | wpa_printf(MSG_DEBUG, "nl80211: Add PMKID for " MACSTR, | |
7593 | MAC2STR(params->bssid)); | |
7594 | else if (params->fils_cache_id && params->ssid_len) { | |
7595 | wpa_printf(MSG_DEBUG, | |
7596 | "nl80211: Add PMKSA for cache id %02x%02x SSID %s", | |
7597 | params->fils_cache_id[0], params->fils_cache_id[1], | |
7598 | wpa_ssid_txt(params->ssid, params->ssid_len)); | |
7599 | } | |
7600 | ||
7601 | return nl80211_pmkid(bss, NL80211_CMD_SET_PMKSA, params); | |
a6efc65d JM |
7602 | } |
7603 | ||
7604 | ||
6fbb5414 | 7605 | static int nl80211_remove_pmkid(void *priv, struct wpa_pmkid_params *params) |
a6efc65d JM |
7606 | { |
7607 | struct i802_bss *bss = priv; | |
061a3d3d VK |
7608 | |
7609 | if (params->bssid) | |
7610 | wpa_printf(MSG_DEBUG, "nl80211: Delete PMKID for " MACSTR, | |
7611 | MAC2STR(params->bssid)); | |
7612 | else if (params->fils_cache_id && params->ssid_len) { | |
7613 | wpa_printf(MSG_DEBUG, | |
7614 | "nl80211: Delete PMKSA for cache id %02x%02x SSID %s", | |
7615 | params->fils_cache_id[0], params->fils_cache_id[1], | |
7616 | wpa_ssid_txt(params->ssid, params->ssid_len)); | |
7617 | } | |
7618 | ||
7619 | return nl80211_pmkid(bss, NL80211_CMD_DEL_PMKSA, params); | |
a6efc65d JM |
7620 | } |
7621 | ||
7622 | ||
7623 | static int nl80211_flush_pmkid(void *priv) | |
7624 | { | |
7625 | struct i802_bss *bss = priv; | |
061a3d3d VK |
7626 | struct nl_msg *msg; |
7627 | ||
a6efc65d | 7628 | wpa_printf(MSG_DEBUG, "nl80211: Flush PMKIDs"); |
061a3d3d VK |
7629 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_FLUSH_PMKSA); |
7630 | if (!msg) | |
7631 | return -ENOBUFS; | |
7632 | return send_and_recv_msgs(bss->drv, msg, NULL, NULL); | |
a6efc65d JM |
7633 | } |
7634 | ||
7635 | ||
0185007c MK |
7636 | static void clean_survey_results(struct survey_results *survey_results) |
7637 | { | |
7638 | struct freq_survey *survey, *tmp; | |
7639 | ||
7640 | if (dl_list_empty(&survey_results->survey_list)) | |
7641 | return; | |
7642 | ||
7643 | dl_list_for_each_safe(survey, tmp, &survey_results->survey_list, | |
7644 | struct freq_survey, list) { | |
7645 | dl_list_del(&survey->list); | |
7646 | os_free(survey); | |
7647 | } | |
7648 | } | |
7649 | ||
7650 | ||
7651 | static void add_survey(struct nlattr **sinfo, u32 ifidx, | |
7652 | struct dl_list *survey_list) | |
7653 | { | |
7654 | struct freq_survey *survey; | |
7655 | ||
7656 | survey = os_zalloc(sizeof(struct freq_survey)); | |
7657 | if (!survey) | |
7658 | return; | |
7659 | ||
7660 | survey->ifidx = ifidx; | |
7661 | survey->freq = nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]); | |
7662 | survey->filled = 0; | |
7663 | ||
7664 | if (sinfo[NL80211_SURVEY_INFO_NOISE]) { | |
7665 | survey->nf = (int8_t) | |
7666 | nla_get_u8(sinfo[NL80211_SURVEY_INFO_NOISE]); | |
7667 | survey->filled |= SURVEY_HAS_NF; | |
7668 | } | |
7669 | ||
7670 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME]) { | |
7671 | survey->channel_time = | |
7672 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME]); | |
7673 | survey->filled |= SURVEY_HAS_CHAN_TIME; | |
7674 | } | |
7675 | ||
7676 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY]) { | |
7677 | survey->channel_time_busy = | |
7678 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY]); | |
7679 | survey->filled |= SURVEY_HAS_CHAN_TIME_BUSY; | |
7680 | } | |
7681 | ||
7682 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_RX]) { | |
7683 | survey->channel_time_rx = | |
7684 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_RX]); | |
7685 | survey->filled |= SURVEY_HAS_CHAN_TIME_RX; | |
7686 | } | |
7687 | ||
7688 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_TX]) { | |
7689 | survey->channel_time_tx = | |
7690 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_TX]); | |
7691 | survey->filled |= SURVEY_HAS_CHAN_TIME_TX; | |
7692 | } | |
7693 | ||
7694 | 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)", | |
7695 | survey->freq, | |
7696 | survey->nf, | |
7697 | (unsigned long int) survey->channel_time, | |
7698 | (unsigned long int) survey->channel_time_busy, | |
7699 | (unsigned long int) survey->channel_time_tx, | |
7700 | (unsigned long int) survey->channel_time_rx, | |
7701 | survey->filled); | |
7702 | ||
7703 | dl_list_add_tail(survey_list, &survey->list); | |
7704 | } | |
7705 | ||
7706 | ||
7707 | static int check_survey_ok(struct nlattr **sinfo, u32 surveyed_freq, | |
7708 | unsigned int freq_filter) | |
7709 | { | |
7710 | if (!freq_filter) | |
7711 | return 1; | |
7712 | ||
7713 | return freq_filter == surveyed_freq; | |
7714 | } | |
7715 | ||
7716 | ||
7717 | static int survey_handler(struct nl_msg *msg, void *arg) | |
7718 | { | |
7719 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
7720 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
7721 | struct nlattr *sinfo[NL80211_SURVEY_INFO_MAX + 1]; | |
7722 | struct survey_results *survey_results; | |
7723 | u32 surveyed_freq = 0; | |
7724 | u32 ifidx; | |
7725 | ||
7726 | static struct nla_policy survey_policy[NL80211_SURVEY_INFO_MAX + 1] = { | |
7727 | [NL80211_SURVEY_INFO_FREQUENCY] = { .type = NLA_U32 }, | |
7728 | [NL80211_SURVEY_INFO_NOISE] = { .type = NLA_U8 }, | |
7729 | }; | |
7730 | ||
7731 | survey_results = (struct survey_results *) arg; | |
7732 | ||
7733 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
7734 | genlmsg_attrlen(gnlh, 0), NULL); | |
7735 | ||
e28f39b7 SJ |
7736 | if (!tb[NL80211_ATTR_IFINDEX]) |
7737 | return NL_SKIP; | |
7738 | ||
0185007c MK |
7739 | ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); |
7740 | ||
7741 | if (!tb[NL80211_ATTR_SURVEY_INFO]) | |
7742 | return NL_SKIP; | |
7743 | ||
7744 | if (nla_parse_nested(sinfo, NL80211_SURVEY_INFO_MAX, | |
7745 | tb[NL80211_ATTR_SURVEY_INFO], | |
7746 | survey_policy)) | |
7747 | return NL_SKIP; | |
7748 | ||
7749 | if (!sinfo[NL80211_SURVEY_INFO_FREQUENCY]) { | |
7750 | wpa_printf(MSG_ERROR, "nl80211: Invalid survey data"); | |
7751 | return NL_SKIP; | |
7752 | } | |
7753 | ||
7754 | surveyed_freq = nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]); | |
7755 | ||
7756 | if (!check_survey_ok(sinfo, surveyed_freq, | |
7757 | survey_results->freq_filter)) | |
7758 | return NL_SKIP; | |
7759 | ||
7760 | if (survey_results->freq_filter && | |
7761 | survey_results->freq_filter != surveyed_freq) { | |
7762 | wpa_printf(MSG_EXCESSIVE, "nl80211: Ignoring survey data for freq %d MHz", | |
7763 | surveyed_freq); | |
7764 | return NL_SKIP; | |
7765 | } | |
7766 | ||
7767 | add_survey(sinfo, ifidx, &survey_results->survey_list); | |
7768 | ||
7769 | return NL_SKIP; | |
7770 | } | |
7771 | ||
7772 | ||
7773 | static int wpa_driver_nl80211_get_survey(void *priv, unsigned int freq) | |
7774 | { | |
7775 | struct i802_bss *bss = priv; | |
7776 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
7777 | struct nl_msg *msg; | |
9725b784 | 7778 | int err; |
0185007c MK |
7779 | union wpa_event_data data; |
7780 | struct survey_results *survey_results; | |
7781 | ||
7782 | os_memset(&data, 0, sizeof(data)); | |
7783 | survey_results = &data.survey_results; | |
7784 | ||
7785 | dl_list_init(&survey_results->survey_list); | |
7786 | ||
9725b784 | 7787 | msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SURVEY); |
0185007c | 7788 | if (!msg) |
a862e4a3 | 7789 | return -ENOBUFS; |
0185007c | 7790 | |
0185007c MK |
7791 | if (freq) |
7792 | data.survey_results.freq_filter = freq; | |
7793 | ||
7794 | do { | |
7795 | wpa_printf(MSG_DEBUG, "nl80211: Fetch survey data"); | |
7796 | err = send_and_recv_msgs(drv, msg, survey_handler, | |
7797 | survey_results); | |
7798 | } while (err > 0); | |
7799 | ||
a862e4a3 | 7800 | if (err) |
0185007c | 7801 | wpa_printf(MSG_ERROR, "nl80211: Failed to process survey data"); |
a862e4a3 JM |
7802 | else |
7803 | wpa_supplicant_event(drv->ctx, EVENT_SURVEY, &data); | |
0185007c | 7804 | |
0185007c | 7805 | clean_survey_results(survey_results); |
0185007c MK |
7806 | return err; |
7807 | } | |
7808 | ||
7809 | ||
98cd3d1c JM |
7810 | static void nl80211_set_rekey_info(void *priv, const u8 *kek, size_t kek_len, |
7811 | const u8 *kck, size_t kck_len, | |
b14a210c JB |
7812 | const u8 *replay_ctr) |
7813 | { | |
7814 | struct i802_bss *bss = priv; | |
7815 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
7816 | struct nlattr *replay_nested; | |
7817 | struct nl_msg *msg; | |
64ae2447 | 7818 | int ret; |
b14a210c | 7819 | |
64ae2447 JM |
7820 | if (!drv->set_rekey_offload) |
7821 | return; | |
7822 | ||
7823 | wpa_printf(MSG_DEBUG, "nl80211: Set rekey offload"); | |
13f83980 | 7824 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_REKEY_OFFLOAD)) || |
a862e4a3 | 7825 | !(replay_nested = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA)) || |
98cd3d1c | 7826 | nla_put(msg, NL80211_REKEY_DATA_KEK, kek_len, kek) || |
b6ea7642 | 7827 | (kck_len && nla_put(msg, NL80211_REKEY_DATA_KCK, kck_len, kck)) || |
a862e4a3 JM |
7828 | nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, NL80211_REPLAY_CTR_LEN, |
7829 | replay_ctr)) { | |
bbd89bfc | 7830 | nl80211_nlmsg_clear(msg); |
a862e4a3 JM |
7831 | nlmsg_free(msg); |
7832 | return; | |
7833 | } | |
b14a210c JB |
7834 | |
7835 | nla_nest_end(msg, replay_nested); | |
7836 | ||
64ae2447 JM |
7837 | ret = send_and_recv_msgs(drv, msg, NULL, (void *) -1); |
7838 | if (ret == -EOPNOTSUPP) { | |
7839 | wpa_printf(MSG_DEBUG, | |
7840 | "nl80211: Driver does not support rekey offload"); | |
7841 | drv->set_rekey_offload = 0; | |
7842 | } | |
b14a210c JB |
7843 | } |
7844 | ||
7845 | ||
39718852 JB |
7846 | static void nl80211_send_null_frame(struct i802_bss *bss, const u8 *own_addr, |
7847 | const u8 *addr, int qos) | |
bcf24348 | 7848 | { |
39718852 JB |
7849 | /* send data frame to poll STA and check whether |
7850 | * this frame is ACKed */ | |
bcf24348 JB |
7851 | struct { |
7852 | struct ieee80211_hdr hdr; | |
7853 | u16 qos_ctl; | |
7854 | } STRUCT_PACKED nulldata; | |
7855 | size_t size; | |
7856 | ||
7857 | /* Send data frame to poll STA and check whether this frame is ACKed */ | |
7858 | ||
7859 | os_memset(&nulldata, 0, sizeof(nulldata)); | |
7860 | ||
7861 | if (qos) { | |
7862 | nulldata.hdr.frame_control = | |
7863 | IEEE80211_FC(WLAN_FC_TYPE_DATA, | |
7864 | WLAN_FC_STYPE_QOS_NULL); | |
7865 | size = sizeof(nulldata); | |
7866 | } else { | |
7867 | nulldata.hdr.frame_control = | |
7868 | IEEE80211_FC(WLAN_FC_TYPE_DATA, | |
7869 | WLAN_FC_STYPE_NULLFUNC); | |
7870 | size = sizeof(struct ieee80211_hdr); | |
7871 | } | |
7872 | ||
7873 | nulldata.hdr.frame_control |= host_to_le16(WLAN_FC_FROMDS); | |
7874 | os_memcpy(nulldata.hdr.IEEE80211_DA_FROMDS, addr, ETH_ALEN); | |
7875 | os_memcpy(nulldata.hdr.IEEE80211_BSSID_FROMDS, own_addr, ETH_ALEN); | |
7876 | os_memcpy(nulldata.hdr.IEEE80211_SA_FROMDS, own_addr, ETH_ALEN); | |
7877 | ||
9ebce9c5 | 7878 | if (wpa_driver_nl80211_send_mlme(bss, (u8 *) &nulldata, size, 0, 0, 0, |
2d3943ce | 7879 | 0, 0, NULL, 0) < 0) |
bcf24348 JB |
7880 | wpa_printf(MSG_DEBUG, "nl80211_send_null_frame: Failed to " |
7881 | "send poll frame"); | |
7882 | } | |
7883 | ||
39718852 JB |
7884 | static void nl80211_poll_client(void *priv, const u8 *own_addr, const u8 *addr, |
7885 | int qos) | |
7886 | { | |
7887 | struct i802_bss *bss = priv; | |
7888 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
7889 | struct nl_msg *msg; | |
fc99fab7 | 7890 | int ret; |
39718852 JB |
7891 | |
7892 | if (!drv->poll_command_supported) { | |
7893 | nl80211_send_null_frame(bss, own_addr, addr, qos); | |
7894 | return; | |
7895 | } | |
7896 | ||
13f83980 | 7897 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_PROBE_CLIENT)) || |
a862e4a3 JM |
7898 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { |
7899 | nlmsg_free(msg); | |
7900 | return; | |
7901 | } | |
39718852 | 7902 | |
fc99fab7 JM |
7903 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
7904 | if (ret < 0) { | |
7905 | wpa_printf(MSG_DEBUG, "nl80211: Client probe request for " | |
7906 | MACSTR " failed: ret=%d (%s)", | |
7907 | MAC2STR(addr), ret, strerror(-ret)); | |
7908 | } | |
39718852 JB |
7909 | } |
7910 | ||
bcf24348 | 7911 | |
29f338af JM |
7912 | static int nl80211_set_power_save(struct i802_bss *bss, int enabled) |
7913 | { | |
7914 | struct nl_msg *msg; | |
7915 | ||
13f83980 | 7916 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_POWER_SAVE)) || |
a862e4a3 JM |
7917 | nla_put_u32(msg, NL80211_ATTR_PS_STATE, |
7918 | enabled ? NL80211_PS_ENABLED : NL80211_PS_DISABLED)) { | |
7919 | nlmsg_free(msg); | |
7920 | return -ENOBUFS; | |
7921 | } | |
29f338af | 7922 | return send_and_recv_msgs(bss->drv, msg, NULL, NULL); |
29f338af JM |
7923 | } |
7924 | ||
7925 | ||
7926 | static int nl80211_set_p2p_powersave(void *priv, int legacy_ps, int opp_ps, | |
7927 | int ctwindow) | |
7928 | { | |
7929 | struct i802_bss *bss = priv; | |
7930 | ||
7931 | wpa_printf(MSG_DEBUG, "nl80211: set_p2p_powersave (legacy_ps=%d " | |
7932 | "opp_ps=%d ctwindow=%d)", legacy_ps, opp_ps, ctwindow); | |
7933 | ||
0de38036 JM |
7934 | if (opp_ps != -1 || ctwindow != -1) { |
7935 | #ifdef ANDROID_P2P | |
7936 | wpa_driver_set_p2p_ps(priv, legacy_ps, opp_ps, ctwindow); | |
7937 | #else /* ANDROID_P2P */ | |
29f338af | 7938 | return -1; /* Not yet supported */ |
0de38036 JM |
7939 | #endif /* ANDROID_P2P */ |
7940 | } | |
29f338af JM |
7941 | |
7942 | if (legacy_ps == -1) | |
7943 | return 0; | |
7944 | if (legacy_ps != 0 && legacy_ps != 1) | |
7945 | return -1; /* Not yet supported */ | |
7946 | ||
7947 | return nl80211_set_power_save(bss, legacy_ps); | |
7948 | } | |
7949 | ||
7950 | ||
04e8003c JD |
7951 | static int nl80211_start_radar_detection(void *priv, |
7952 | struct hostapd_freq_params *freq) | |
f90e9c1c SW |
7953 | { |
7954 | struct i802_bss *bss = priv; | |
7955 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
7956 | struct nl_msg *msg; | |
7957 | int ret; | |
7958 | ||
04e8003c JD |
7959 | wpa_printf(MSG_DEBUG, "nl80211: Start radar detection (CAC) %d MHz (ht_enabled=%d, vht_enabled=%d, bandwidth=%d MHz, cf1=%d MHz, cf2=%d MHz)", |
7960 | freq->freq, freq->ht_enabled, freq->vht_enabled, | |
7961 | freq->bandwidth, freq->center_freq1, freq->center_freq2); | |
7962 | ||
f90e9c1c SW |
7963 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_RADAR)) { |
7964 | wpa_printf(MSG_DEBUG, "nl80211: Driver does not support radar " | |
7965 | "detection"); | |
7966 | return -1; | |
7967 | } | |
7968 | ||
9725b784 | 7969 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_RADAR_DETECT)) || |
a862e4a3 JM |
7970 | nl80211_put_freq_params(msg, freq) < 0) { |
7971 | nlmsg_free(msg); | |
7972 | return -1; | |
7973 | } | |
f90e9c1c SW |
7974 | |
7975 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
7976 | if (ret == 0) | |
7977 | return 0; | |
7978 | wpa_printf(MSG_DEBUG, "nl80211: Failed to start radar detection: " | |
7979 | "%d (%s)", ret, strerror(-ret)); | |
f90e9c1c SW |
7980 | return -1; |
7981 | } | |
7982 | ||
03ea1786 AN |
7983 | #ifdef CONFIG_TDLS |
7984 | ||
7985 | static int nl80211_send_tdls_mgmt(void *priv, const u8 *dst, u8 action_code, | |
7986 | u8 dialog_token, u16 status_code, | |
984dadc2 AN |
7987 | u32 peer_capab, int initiator, const u8 *buf, |
7988 | size_t len) | |
03ea1786 AN |
7989 | { |
7990 | struct i802_bss *bss = priv; | |
7991 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
7992 | struct nl_msg *msg; | |
7993 | ||
7994 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) | |
7995 | return -EOPNOTSUPP; | |
7996 | ||
7997 | if (!dst) | |
7998 | return -EINVAL; | |
7999 | ||
9725b784 | 8000 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_TDLS_MGMT)) || |
a862e4a3 JM |
8001 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || |
8002 | nla_put_u8(msg, NL80211_ATTR_TDLS_ACTION, action_code) || | |
8003 | nla_put_u8(msg, NL80211_ATTR_TDLS_DIALOG_TOKEN, dialog_token) || | |
8004 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status_code)) | |
8005 | goto fail; | |
96ecea5e SD |
8006 | if (peer_capab) { |
8007 | /* | |
8008 | * The internal enum tdls_peer_capability definition is | |
8009 | * currently identical with the nl80211 enum | |
8010 | * nl80211_tdls_peer_capability, so no conversion is needed | |
8011 | * here. | |
8012 | */ | |
a862e4a3 JM |
8013 | if (nla_put_u32(msg, NL80211_ATTR_TDLS_PEER_CAPABILITY, |
8014 | peer_capab)) | |
8015 | goto fail; | |
96ecea5e | 8016 | } |
a862e4a3 JM |
8017 | if ((initiator && |
8018 | nla_put_flag(msg, NL80211_ATTR_TDLS_INITIATOR)) || | |
8019 | nla_put(msg, NL80211_ATTR_IE, len, buf)) | |
8020 | goto fail; | |
03ea1786 AN |
8021 | |
8022 | return send_and_recv_msgs(drv, msg, NULL, NULL); | |
8023 | ||
a862e4a3 | 8024 | fail: |
03ea1786 AN |
8025 | nlmsg_free(msg); |
8026 | return -ENOBUFS; | |
8027 | } | |
8028 | ||
8029 | ||
8030 | static int nl80211_tdls_oper(void *priv, enum tdls_oper oper, const u8 *peer) | |
8031 | { | |
8032 | struct i802_bss *bss = priv; | |
8033 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8034 | struct nl_msg *msg; | |
8035 | enum nl80211_tdls_operation nl80211_oper; | |
b2442f25 | 8036 | int res; |
03ea1786 AN |
8037 | |
8038 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) | |
8039 | return -EOPNOTSUPP; | |
8040 | ||
8041 | switch (oper) { | |
8042 | case TDLS_DISCOVERY_REQ: | |
8043 | nl80211_oper = NL80211_TDLS_DISCOVERY_REQ; | |
8044 | break; | |
8045 | case TDLS_SETUP: | |
8046 | nl80211_oper = NL80211_TDLS_SETUP; | |
8047 | break; | |
8048 | case TDLS_TEARDOWN: | |
8049 | nl80211_oper = NL80211_TDLS_TEARDOWN; | |
8050 | break; | |
8051 | case TDLS_ENABLE_LINK: | |
8052 | nl80211_oper = NL80211_TDLS_ENABLE_LINK; | |
8053 | break; | |
8054 | case TDLS_DISABLE_LINK: | |
8055 | nl80211_oper = NL80211_TDLS_DISABLE_LINK; | |
8056 | break; | |
8057 | case TDLS_ENABLE: | |
8058 | return 0; | |
8059 | case TDLS_DISABLE: | |
8060 | return 0; | |
8061 | default: | |
8062 | return -EINVAL; | |
8063 | } | |
8064 | ||
9725b784 | 8065 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_TDLS_OPER)) || |
a862e4a3 | 8066 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, nl80211_oper) || |
a862e4a3 JM |
8067 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) { |
8068 | nlmsg_free(msg); | |
8069 | return -ENOBUFS; | |
8070 | } | |
03ea1786 | 8071 | |
b2442f25 JM |
8072 | res = send_and_recv_msgs(drv, msg, NULL, NULL); |
8073 | wpa_printf(MSG_DEBUG, "nl80211: TDLS_OPER: oper=%d mac=" MACSTR | |
8074 | " --> res=%d (%s)", nl80211_oper, MAC2STR(peer), res, | |
8075 | strerror(-res)); | |
8076 | return res; | |
03ea1786 AN |
8077 | } |
8078 | ||
72b2605f AN |
8079 | |
8080 | static int | |
8081 | nl80211_tdls_enable_channel_switch(void *priv, const u8 *addr, u8 oper_class, | |
8082 | const struct hostapd_freq_params *params) | |
8083 | { | |
8084 | struct i802_bss *bss = priv; | |
8085 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8086 | struct nl_msg *msg; | |
8087 | int ret = -ENOBUFS; | |
8088 | ||
8089 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT) || | |
8090 | !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH)) | |
8091 | return -EOPNOTSUPP; | |
8092 | ||
8093 | wpa_printf(MSG_DEBUG, "nl80211: Enable TDLS channel switch " MACSTR | |
8094 | " oper_class=%u freq=%u", | |
8095 | MAC2STR(addr), oper_class, params->freq); | |
8096 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_TDLS_CHANNEL_SWITCH); | |
8097 | if (!msg || | |
8098 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || | |
8099 | nla_put_u8(msg, NL80211_ATTR_OPER_CLASS, oper_class) || | |
8100 | (ret = nl80211_put_freq_params(msg, params))) { | |
8101 | nlmsg_free(msg); | |
8102 | wpa_printf(MSG_DEBUG, "nl80211: Could not build TDLS chan switch"); | |
8103 | return ret; | |
8104 | } | |
8105 | ||
8106 | return send_and_recv_msgs(drv, msg, NULL, NULL); | |
8107 | } | |
8108 | ||
8109 | ||
8110 | static int | |
8111 | nl80211_tdls_disable_channel_switch(void *priv, const u8 *addr) | |
8112 | { | |
8113 | struct i802_bss *bss = priv; | |
8114 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8115 | struct nl_msg *msg; | |
8116 | ||
8117 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT) || | |
8118 | !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH)) | |
8119 | return -EOPNOTSUPP; | |
8120 | ||
8121 | wpa_printf(MSG_DEBUG, "nl80211: Disable TDLS channel switch " MACSTR, | |
8122 | MAC2STR(addr)); | |
8123 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH); | |
8124 | if (!msg || | |
8125 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { | |
8126 | nlmsg_free(msg); | |
8127 | wpa_printf(MSG_DEBUG, | |
8128 | "nl80211: Could not build TDLS cancel chan switch"); | |
8129 | return -ENOBUFS; | |
8130 | } | |
8131 | ||
8132 | return send_and_recv_msgs(drv, msg, NULL, NULL); | |
8133 | } | |
8134 | ||
03ea1786 AN |
8135 | #endif /* CONFIG TDLS */ |
8136 | ||
8137 | ||
9ebce9c5 JM |
8138 | static int driver_nl80211_set_key(const char *ifname, void *priv, |
8139 | enum wpa_alg alg, const u8 *addr, | |
8140 | int key_idx, int set_tx, | |
8141 | const u8 *seq, size_t seq_len, | |
8142 | const u8 *key, size_t key_len) | |
8143 | { | |
8144 | struct i802_bss *bss = priv; | |
8145 | return wpa_driver_nl80211_set_key(ifname, bss, alg, addr, key_idx, | |
8146 | set_tx, seq, seq_len, key, key_len); | |
8147 | } | |
8148 | ||
8149 | ||
8150 | static int driver_nl80211_scan2(void *priv, | |
8151 | struct wpa_driver_scan_params *params) | |
8152 | { | |
8153 | struct i802_bss *bss = priv; | |
b658547d | 8154 | #ifdef CONFIG_DRIVER_NL80211_QCA |
adcd7c4b KV |
8155 | struct wpa_driver_nl80211_data *drv = bss->drv; |
8156 | ||
8157 | /* | |
8158 | * Do a vendor specific scan if possible. If only_new_results is | |
8159 | * set, do a normal scan since a kernel (cfg80211) BSS cache flush | |
8160 | * cannot be achieved through a vendor scan. The below condition may | |
8161 | * need to be modified if new scan flags are added in the future whose | |
8162 | * functionality can only be achieved through a normal scan. | |
8163 | */ | |
8164 | if (drv->scan_vendor_cmd_avail && !params->only_new_results) | |
8165 | return wpa_driver_nl80211_vendor_scan(bss, params); | |
b658547d | 8166 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
9ebce9c5 JM |
8167 | return wpa_driver_nl80211_scan(bss, params); |
8168 | } | |
8169 | ||
8170 | ||
8171 | static int driver_nl80211_deauthenticate(void *priv, const u8 *addr, | |
8172 | int reason_code) | |
8173 | { | |
8174 | struct i802_bss *bss = priv; | |
8175 | return wpa_driver_nl80211_deauthenticate(bss, addr, reason_code); | |
8176 | } | |
8177 | ||
8178 | ||
8179 | static int driver_nl80211_authenticate(void *priv, | |
8180 | struct wpa_driver_auth_params *params) | |
8181 | { | |
8182 | struct i802_bss *bss = priv; | |
8183 | return wpa_driver_nl80211_authenticate(bss, params); | |
8184 | } | |
8185 | ||
8186 | ||
8187 | static void driver_nl80211_deinit(void *priv) | |
8188 | { | |
8189 | struct i802_bss *bss = priv; | |
8190 | wpa_driver_nl80211_deinit(bss); | |
8191 | } | |
8192 | ||
8193 | ||
8194 | static int driver_nl80211_if_remove(void *priv, enum wpa_driver_if_type type, | |
8195 | const char *ifname) | |
8196 | { | |
8197 | struct i802_bss *bss = priv; | |
8198 | return wpa_driver_nl80211_if_remove(bss, type, ifname); | |
8199 | } | |
8200 | ||
8201 | ||
8202 | static int driver_nl80211_send_mlme(void *priv, const u8 *data, | |
5d180a77 | 8203 | size_t data_len, int noack, |
2d3943ce AO |
8204 | unsigned int freq, |
8205 | const u16 *csa_offs, size_t csa_offs_len) | |
9ebce9c5 JM |
8206 | { |
8207 | struct i802_bss *bss = priv; | |
8208 | return wpa_driver_nl80211_send_mlme(bss, data, data_len, noack, | |
2d3943ce AO |
8209 | freq, 0, 0, 0, csa_offs, |
8210 | csa_offs_len); | |
9ebce9c5 JM |
8211 | } |
8212 | ||
8213 | ||
8214 | static int driver_nl80211_sta_remove(void *priv, const u8 *addr) | |
8215 | { | |
8216 | struct i802_bss *bss = priv; | |
59d7148a | 8217 | return wpa_driver_nl80211_sta_remove(bss, addr, -1, 0); |
9ebce9c5 JM |
8218 | } |
8219 | ||
8220 | ||
9ebce9c5 JM |
8221 | static int driver_nl80211_set_sta_vlan(void *priv, const u8 *addr, |
8222 | const char *ifname, int vlan_id) | |
8223 | { | |
8224 | struct i802_bss *bss = priv; | |
8225 | return i802_set_sta_vlan(bss, addr, ifname, vlan_id); | |
8226 | } | |
9ebce9c5 JM |
8227 | |
8228 | ||
8229 | static int driver_nl80211_read_sta_data(void *priv, | |
8230 | struct hostap_sta_driver_data *data, | |
8231 | const u8 *addr) | |
8232 | { | |
8233 | struct i802_bss *bss = priv; | |
7824bf77 JC |
8234 | |
8235 | os_memset(data, 0, sizeof(*data)); | |
9ebce9c5 JM |
8236 | return i802_read_sta_data(bss, data, addr); |
8237 | } | |
8238 | ||
8239 | ||
8240 | static int driver_nl80211_send_action(void *priv, unsigned int freq, | |
8241 | unsigned int wait_time, | |
8242 | const u8 *dst, const u8 *src, | |
8243 | const u8 *bssid, | |
8244 | const u8 *data, size_t data_len, | |
8245 | int no_cck) | |
8246 | { | |
8247 | struct i802_bss *bss = priv; | |
8248 | return wpa_driver_nl80211_send_action(bss, freq, wait_time, dst, src, | |
8249 | bssid, data, data_len, no_cck); | |
8250 | } | |
8251 | ||
8252 | ||
8253 | static int driver_nl80211_probe_req_report(void *priv, int report) | |
8254 | { | |
8255 | struct i802_bss *bss = priv; | |
8256 | return wpa_driver_nl80211_probe_req_report(bss, report); | |
8257 | } | |
8258 | ||
8259 | ||
6a1ce395 DG |
8260 | static int wpa_driver_nl80211_update_ft_ies(void *priv, const u8 *md, |
8261 | const u8 *ies, size_t ies_len) | |
8262 | { | |
8263 | int ret; | |
8264 | struct nl_msg *msg; | |
8265 | struct i802_bss *bss = priv; | |
8266 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8267 | u16 mdid = WPA_GET_LE16(md); | |
8268 | ||
6a1ce395 | 8269 | wpa_printf(MSG_DEBUG, "nl80211: Updating FT IEs"); |
9725b784 | 8270 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_UPDATE_FT_IES)) || |
a862e4a3 JM |
8271 | nla_put(msg, NL80211_ATTR_IE, ies_len, ies) || |
8272 | nla_put_u16(msg, NL80211_ATTR_MDID, mdid)) { | |
8273 | nlmsg_free(msg); | |
8274 | return -ENOBUFS; | |
8275 | } | |
6a1ce395 DG |
8276 | |
8277 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
8278 | if (ret) { | |
8279 | wpa_printf(MSG_DEBUG, "nl80211: update_ft_ies failed " | |
8280 | "err=%d (%s)", ret, strerror(-ret)); | |
8281 | } | |
8282 | ||
8283 | return ret; | |
6a1ce395 DG |
8284 | } |
8285 | ||
8286 | ||
47754718 | 8287 | static const u8 * wpa_driver_nl80211_get_macaddr(void *priv) |
597b94f5 AS |
8288 | { |
8289 | struct i802_bss *bss = priv; | |
8290 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8291 | ||
8292 | if (drv->nlmode != NL80211_IFTYPE_P2P_DEVICE) | |
8293 | return NULL; | |
8294 | ||
8295 | return bss->addr; | |
8296 | } | |
8297 | ||
8298 | ||
a771c07d JM |
8299 | static const char * scan_state_str(enum scan_states scan_state) |
8300 | { | |
8301 | switch (scan_state) { | |
8302 | case NO_SCAN: | |
8303 | return "NO_SCAN"; | |
8304 | case SCAN_REQUESTED: | |
8305 | return "SCAN_REQUESTED"; | |
8306 | case SCAN_STARTED: | |
8307 | return "SCAN_STARTED"; | |
8308 | case SCAN_COMPLETED: | |
8309 | return "SCAN_COMPLETED"; | |
8310 | case SCAN_ABORTED: | |
8311 | return "SCAN_ABORTED"; | |
8312 | case SCHED_SCAN_STARTED: | |
8313 | return "SCHED_SCAN_STARTED"; | |
8314 | case SCHED_SCAN_STOPPED: | |
8315 | return "SCHED_SCAN_STOPPED"; | |
8316 | case SCHED_SCAN_RESULTS: | |
8317 | return "SCHED_SCAN_RESULTS"; | |
8318 | } | |
8319 | ||
8320 | return "??"; | |
8321 | } | |
8322 | ||
8323 | ||
8324 | static int wpa_driver_nl80211_status(void *priv, char *buf, size_t buflen) | |
8325 | { | |
8326 | struct i802_bss *bss = priv; | |
8327 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8328 | int res; | |
8329 | char *pos, *end; | |
8330 | ||
8331 | pos = buf; | |
8332 | end = buf + buflen; | |
8333 | ||
8334 | res = os_snprintf(pos, end - pos, | |
8335 | "ifindex=%d\n" | |
8336 | "ifname=%s\n" | |
8337 | "brname=%s\n" | |
8338 | "addr=" MACSTR "\n" | |
8339 | "freq=%d\n" | |
8340 | "%s%s%s%s%s", | |
8341 | bss->ifindex, | |
8342 | bss->ifname, | |
8343 | bss->brname, | |
8344 | MAC2STR(bss->addr), | |
8345 | bss->freq, | |
8346 | bss->beacon_set ? "beacon_set=1\n" : "", | |
8347 | bss->added_if_into_bridge ? | |
8348 | "added_if_into_bridge=1\n" : "", | |
8349 | bss->added_bridge ? "added_bridge=1\n" : "", | |
8350 | bss->in_deinit ? "in_deinit=1\n" : "", | |
8351 | bss->if_dynamic ? "if_dynamic=1\n" : ""); | |
d85e1fc8 | 8352 | if (os_snprintf_error(end - pos, res)) |
a771c07d JM |
8353 | return pos - buf; |
8354 | pos += res; | |
8355 | ||
8356 | if (bss->wdev_id_set) { | |
8357 | res = os_snprintf(pos, end - pos, "wdev_id=%llu\n", | |
8358 | (unsigned long long) bss->wdev_id); | |
d85e1fc8 | 8359 | if (os_snprintf_error(end - pos, res)) |
a771c07d JM |
8360 | return pos - buf; |
8361 | pos += res; | |
8362 | } | |
8363 | ||
8364 | res = os_snprintf(pos, end - pos, | |
8365 | "phyname=%s\n" | |
fee354c7 | 8366 | "perm_addr=" MACSTR "\n" |
a771c07d JM |
8367 | "drv_ifindex=%d\n" |
8368 | "operstate=%d\n" | |
8369 | "scan_state=%s\n" | |
8370 | "auth_bssid=" MACSTR "\n" | |
8371 | "auth_attempt_bssid=" MACSTR "\n" | |
8372 | "bssid=" MACSTR "\n" | |
8373 | "prev_bssid=" MACSTR "\n" | |
8374 | "associated=%d\n" | |
8375 | "assoc_freq=%u\n" | |
8376 | "monitor_sock=%d\n" | |
8377 | "monitor_ifidx=%d\n" | |
8378 | "monitor_refcount=%d\n" | |
8379 | "last_mgmt_freq=%u\n" | |
8380 | "eapol_tx_sock=%d\n" | |
97752f79 | 8381 | "%s%s%s%s%s%s%s%s%s%s%s%s%s", |
a771c07d | 8382 | drv->phyname, |
fee354c7 | 8383 | MAC2STR(drv->perm_addr), |
a771c07d JM |
8384 | drv->ifindex, |
8385 | drv->operstate, | |
8386 | scan_state_str(drv->scan_state), | |
8387 | MAC2STR(drv->auth_bssid), | |
8388 | MAC2STR(drv->auth_attempt_bssid), | |
8389 | MAC2STR(drv->bssid), | |
8390 | MAC2STR(drv->prev_bssid), | |
8391 | drv->associated, | |
8392 | drv->assoc_freq, | |
8393 | drv->monitor_sock, | |
8394 | drv->monitor_ifidx, | |
8395 | drv->monitor_refcount, | |
8396 | drv->last_mgmt_freq, | |
8397 | drv->eapol_tx_sock, | |
8398 | drv->ignore_if_down_event ? | |
8399 | "ignore_if_down_event=1\n" : "", | |
8400 | drv->scan_complete_events ? | |
8401 | "scan_complete_events=1\n" : "", | |
8402 | drv->disabled_11b_rates ? | |
8403 | "disabled_11b_rates=1\n" : "", | |
8404 | drv->pending_remain_on_chan ? | |
8405 | "pending_remain_on_chan=1\n" : "", | |
8406 | drv->in_interface_list ? "in_interface_list=1\n" : "", | |
8407 | drv->device_ap_sme ? "device_ap_sme=1\n" : "", | |
8408 | drv->poll_command_supported ? | |
8409 | "poll_command_supported=1\n" : "", | |
8410 | drv->data_tx_status ? "data_tx_status=1\n" : "", | |
8411 | drv->scan_for_auth ? "scan_for_auth=1\n" : "", | |
8412 | drv->retry_auth ? "retry_auth=1\n" : "", | |
8413 | drv->use_monitor ? "use_monitor=1\n" : "", | |
8414 | drv->ignore_next_local_disconnect ? | |
8415 | "ignore_next_local_disconnect=1\n" : "", | |
d6a36f39 | 8416 | drv->ignore_next_local_deauth ? |
97752f79 | 8417 | "ignore_next_local_deauth=1\n" : ""); |
d85e1fc8 | 8418 | if (os_snprintf_error(end - pos, res)) |
a771c07d JM |
8419 | return pos - buf; |
8420 | pos += res; | |
8421 | ||
8422 | if (drv->has_capability) { | |
8423 | res = os_snprintf(pos, end - pos, | |
8424 | "capa.key_mgmt=0x%x\n" | |
8425 | "capa.enc=0x%x\n" | |
8426 | "capa.auth=0x%x\n" | |
24bd4e0b | 8427 | "capa.flags=0x%llx\n" |
a0a34d53 | 8428 | "capa.rrm_flags=0x%x\n" |
a771c07d JM |
8429 | "capa.max_scan_ssids=%d\n" |
8430 | "capa.max_sched_scan_ssids=%d\n" | |
8431 | "capa.sched_scan_supported=%d\n" | |
8432 | "capa.max_match_sets=%d\n" | |
8433 | "capa.max_remain_on_chan=%u\n" | |
8434 | "capa.max_stations=%u\n" | |
8435 | "capa.probe_resp_offloads=0x%x\n" | |
8436 | "capa.max_acl_mac_addrs=%u\n" | |
86056fea IP |
8437 | "capa.num_multichan_concurrent=%u\n" |
8438 | "capa.mac_addr_rand_sched_scan_supported=%d\n" | |
079a28f7 AK |
8439 | "capa.mac_addr_rand_scan_supported=%d\n" |
8440 | "capa.conc_capab=%u\n" | |
8441 | "capa.max_conc_chan_2_4=%u\n" | |
09ea4309 AS |
8442 | "capa.max_conc_chan_5_0=%u\n" |
8443 | "capa.max_sched_scan_plans=%u\n" | |
8444 | "capa.max_sched_scan_plan_interval=%u\n" | |
8445 | "capa.max_sched_scan_plan_iterations=%u\n", | |
a771c07d JM |
8446 | drv->capa.key_mgmt, |
8447 | drv->capa.enc, | |
8448 | drv->capa.auth, | |
24bd4e0b | 8449 | (unsigned long long) drv->capa.flags, |
a0a34d53 | 8450 | drv->capa.rrm_flags, |
a771c07d JM |
8451 | drv->capa.max_scan_ssids, |
8452 | drv->capa.max_sched_scan_ssids, | |
8453 | drv->capa.sched_scan_supported, | |
8454 | drv->capa.max_match_sets, | |
8455 | drv->capa.max_remain_on_chan, | |
8456 | drv->capa.max_stations, | |
8457 | drv->capa.probe_resp_offloads, | |
8458 | drv->capa.max_acl_mac_addrs, | |
86056fea IP |
8459 | drv->capa.num_multichan_concurrent, |
8460 | drv->capa.mac_addr_rand_sched_scan_supported, | |
079a28f7 AK |
8461 | drv->capa.mac_addr_rand_scan_supported, |
8462 | drv->capa.conc_capab, | |
8463 | drv->capa.max_conc_chan_2_4, | |
09ea4309 AS |
8464 | drv->capa.max_conc_chan_5_0, |
8465 | drv->capa.max_sched_scan_plans, | |
8466 | drv->capa.max_sched_scan_plan_interval, | |
8467 | drv->capa.max_sched_scan_plan_iterations); | |
d85e1fc8 | 8468 | if (os_snprintf_error(end - pos, res)) |
a771c07d JM |
8469 | return pos - buf; |
8470 | pos += res; | |
8471 | } | |
8472 | ||
8473 | return pos - buf; | |
8474 | } | |
8475 | ||
8476 | ||
1c4ffa87 AO |
8477 | static int set_beacon_data(struct nl_msg *msg, struct beacon_data *settings) |
8478 | { | |
a862e4a3 JM |
8479 | if ((settings->head && |
8480 | nla_put(msg, NL80211_ATTR_BEACON_HEAD, | |
8481 | settings->head_len, settings->head)) || | |
8482 | (settings->tail && | |
8483 | nla_put(msg, NL80211_ATTR_BEACON_TAIL, | |
8484 | settings->tail_len, settings->tail)) || | |
8485 | (settings->beacon_ies && | |
8486 | nla_put(msg, NL80211_ATTR_IE, | |
8487 | settings->beacon_ies_len, settings->beacon_ies)) || | |
8488 | (settings->proberesp_ies && | |
8489 | nla_put(msg, NL80211_ATTR_IE_PROBE_RESP, | |
8490 | settings->proberesp_ies_len, settings->proberesp_ies)) || | |
8491 | (settings->assocresp_ies && | |
8492 | nla_put(msg, NL80211_ATTR_IE_ASSOC_RESP, | |
8493 | settings->assocresp_ies_len, settings->assocresp_ies)) || | |
8494 | (settings->probe_resp && | |
8495 | nla_put(msg, NL80211_ATTR_PROBE_RESP, | |
8496 | settings->probe_resp_len, settings->probe_resp))) | |
8497 | return -ENOBUFS; | |
1c4ffa87 AO |
8498 | |
8499 | return 0; | |
1c4ffa87 AO |
8500 | } |
8501 | ||
8502 | ||
8503 | static int nl80211_switch_channel(void *priv, struct csa_settings *settings) | |
8504 | { | |
8505 | struct nl_msg *msg; | |
8506 | struct i802_bss *bss = priv; | |
8507 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8508 | struct nlattr *beacon_csa; | |
8509 | int ret = -ENOBUFS; | |
366179d2 AO |
8510 | int csa_off_len = 0; |
8511 | int i; | |
1c4ffa87 | 8512 | |
8d1fdde7 | 8513 | wpa_printf(MSG_DEBUG, "nl80211: Channel switch request (cs_count=%u block_tx=%u freq=%d width=%d cf1=%d cf2=%d)", |
1c4ffa87 | 8514 | settings->cs_count, settings->block_tx, |
8d1fdde7 JD |
8515 | settings->freq_params.freq, settings->freq_params.bandwidth, |
8516 | settings->freq_params.center_freq1, | |
8517 | settings->freq_params.center_freq2); | |
1c4ffa87 | 8518 | |
991aa9c7 | 8519 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_AP_CSA)) { |
1c4ffa87 AO |
8520 | wpa_printf(MSG_DEBUG, "nl80211: Driver does not support channel switch command"); |
8521 | return -EOPNOTSUPP; | |
8522 | } | |
8523 | ||
8524 | if ((drv->nlmode != NL80211_IFTYPE_AP) && | |
8525 | (drv->nlmode != NL80211_IFTYPE_P2P_GO)) | |
8526 | return -EOPNOTSUPP; | |
8527 | ||
366179d2 AO |
8528 | /* |
8529 | * Remove empty counters, assuming Probe Response and Beacon frame | |
8530 | * counters match. This implementation assumes that there are only two | |
8531 | * counters. | |
8532 | */ | |
8533 | if (settings->counter_offset_beacon[0] && | |
8534 | !settings->counter_offset_beacon[1]) { | |
8535 | csa_off_len = 1; | |
8536 | } else if (settings->counter_offset_beacon[1] && | |
8537 | !settings->counter_offset_beacon[0]) { | |
8538 | csa_off_len = 1; | |
8539 | settings->counter_offset_beacon[0] = | |
8540 | settings->counter_offset_beacon[1]; | |
8541 | settings->counter_offset_presp[0] = | |
8542 | settings->counter_offset_presp[1]; | |
8543 | } else if (settings->counter_offset_beacon[1] && | |
8544 | settings->counter_offset_beacon[0]) { | |
8545 | csa_off_len = 2; | |
8546 | } else { | |
8547 | wpa_printf(MSG_ERROR, "nl80211: No CSA counters provided"); | |
8548 | return -EINVAL; | |
8549 | } | |
8550 | ||
8551 | /* Check CSA counters validity */ | |
8552 | if (drv->capa.max_csa_counters && | |
8553 | csa_off_len > drv->capa.max_csa_counters) { | |
8554 | wpa_printf(MSG_ERROR, | |
8555 | "nl80211: Too many CSA counters provided"); | |
1c4ffa87 | 8556 | return -EINVAL; |
366179d2 | 8557 | } |
1c4ffa87 | 8558 | |
366179d2 | 8559 | if (!settings->beacon_csa.tail) |
1c4ffa87 AO |
8560 | return -EINVAL; |
8561 | ||
366179d2 AO |
8562 | for (i = 0; i < csa_off_len; i++) { |
8563 | u16 csa_c_off_bcn = settings->counter_offset_beacon[i]; | |
8564 | u16 csa_c_off_presp = settings->counter_offset_presp[i]; | |
8565 | ||
8566 | if ((settings->beacon_csa.tail_len <= csa_c_off_bcn) || | |
8567 | (settings->beacon_csa.tail[csa_c_off_bcn] != | |
8568 | settings->cs_count)) | |
8569 | return -EINVAL; | |
8570 | ||
8571 | if (settings->beacon_csa.probe_resp && | |
8572 | ((settings->beacon_csa.probe_resp_len <= | |
8573 | csa_c_off_presp) || | |
8574 | (settings->beacon_csa.probe_resp[csa_c_off_presp] != | |
8575 | settings->cs_count))) | |
8576 | return -EINVAL; | |
8577 | } | |
8578 | ||
13f83980 | 8579 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_CHANNEL_SWITCH)) || |
a862e4a3 JM |
8580 | nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, |
8581 | settings->cs_count) || | |
8582 | (ret = nl80211_put_freq_params(msg, &settings->freq_params)) || | |
8583 | (settings->block_tx && | |
8584 | nla_put_flag(msg, NL80211_ATTR_CH_SWITCH_BLOCK_TX))) | |
1c4ffa87 AO |
8585 | goto error; |
8586 | ||
1c4ffa87 AO |
8587 | /* beacon_after params */ |
8588 | ret = set_beacon_data(msg, &settings->beacon_after); | |
8589 | if (ret) | |
8590 | goto error; | |
8591 | ||
8592 | /* beacon_csa params */ | |
8593 | beacon_csa = nla_nest_start(msg, NL80211_ATTR_CSA_IES); | |
8594 | if (!beacon_csa) | |
a862e4a3 | 8595 | goto fail; |
1c4ffa87 AO |
8596 | |
8597 | ret = set_beacon_data(msg, &settings->beacon_csa); | |
8598 | if (ret) | |
8599 | goto error; | |
8600 | ||
366179d2 AO |
8601 | if (nla_put(msg, NL80211_ATTR_CSA_C_OFF_BEACON, |
8602 | csa_off_len * sizeof(u16), | |
8603 | settings->counter_offset_beacon) || | |
a862e4a3 | 8604 | (settings->beacon_csa.probe_resp && |
366179d2 AO |
8605 | nla_put(msg, NL80211_ATTR_CSA_C_OFF_PRESP, |
8606 | csa_off_len * sizeof(u16), | |
8607 | settings->counter_offset_presp))) | |
a862e4a3 | 8608 | goto fail; |
1c4ffa87 AO |
8609 | |
8610 | nla_nest_end(msg, beacon_csa); | |
8611 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
8612 | if (ret) { | |
8613 | wpa_printf(MSG_DEBUG, "nl80211: switch_channel failed err=%d (%s)", | |
8614 | ret, strerror(-ret)); | |
8615 | } | |
8616 | return ret; | |
8617 | ||
a862e4a3 | 8618 | fail: |
1c4ffa87 AO |
8619 | ret = -ENOBUFS; |
8620 | error: | |
8621 | nlmsg_free(msg); | |
8622 | wpa_printf(MSG_DEBUG, "nl80211: Could not build channel switch request"); | |
8623 | return ret; | |
8624 | } | |
8625 | ||
8626 | ||
dfa87878 MB |
8627 | static int nl80211_add_ts(void *priv, u8 tsid, const u8 *addr, |
8628 | u8 user_priority, u16 admitted_time) | |
8629 | { | |
8630 | struct i802_bss *bss = priv; | |
8631 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8632 | struct nl_msg *msg; | |
8633 | int ret; | |
8634 | ||
8635 | wpa_printf(MSG_DEBUG, | |
8636 | "nl80211: add_ts request: tsid=%u admitted_time=%u up=%d", | |
8637 | tsid, admitted_time, user_priority); | |
8638 | ||
8639 | if (!is_sta_interface(drv->nlmode)) | |
8640 | return -ENOTSUP; | |
8641 | ||
56f77852 JM |
8642 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_ADD_TX_TS); |
8643 | if (!msg || | |
a862e4a3 JM |
8644 | nla_put_u8(msg, NL80211_ATTR_TSID, tsid) || |
8645 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || | |
8646 | nla_put_u8(msg, NL80211_ATTR_USER_PRIO, user_priority) || | |
8647 | nla_put_u16(msg, NL80211_ATTR_ADMITTED_TIME, admitted_time)) { | |
8648 | nlmsg_free(msg); | |
8649 | return -ENOBUFS; | |
8650 | } | |
dfa87878 MB |
8651 | |
8652 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
8653 | if (ret) | |
8654 | wpa_printf(MSG_DEBUG, "nl80211: add_ts failed err=%d (%s)", | |
8655 | ret, strerror(-ret)); | |
8656 | return ret; | |
dfa87878 MB |
8657 | } |
8658 | ||
8659 | ||
8660 | static int nl80211_del_ts(void *priv, u8 tsid, const u8 *addr) | |
8661 | { | |
8662 | struct i802_bss *bss = priv; | |
8663 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8664 | struct nl_msg *msg; | |
8665 | int ret; | |
8666 | ||
8667 | wpa_printf(MSG_DEBUG, "nl80211: del_ts request: tsid=%u", tsid); | |
8668 | ||
8669 | if (!is_sta_interface(drv->nlmode)) | |
8670 | return -ENOTSUP; | |
8671 | ||
56f77852 | 8672 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_DEL_TX_TS)) || |
a862e4a3 JM |
8673 | nla_put_u8(msg, NL80211_ATTR_TSID, tsid) || |
8674 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { | |
8675 | nlmsg_free(msg); | |
8676 | return -ENOBUFS; | |
8677 | } | |
dfa87878 MB |
8678 | |
8679 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
8680 | if (ret) | |
8681 | wpa_printf(MSG_DEBUG, "nl80211: del_ts failed err=%d (%s)", | |
8682 | ret, strerror(-ret)); | |
8683 | return ret; | |
dfa87878 MB |
8684 | } |
8685 | ||
8686 | ||
6b9f7af6 JM |
8687 | #ifdef CONFIG_TESTING_OPTIONS |
8688 | static int cmd_reply_handler(struct nl_msg *msg, void *arg) | |
8689 | { | |
8690 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
8691 | struct wpabuf *buf = arg; | |
8692 | ||
8693 | if (!buf) | |
8694 | return NL_SKIP; | |
8695 | ||
8696 | if ((size_t) genlmsg_attrlen(gnlh, 0) > wpabuf_tailroom(buf)) { | |
8697 | wpa_printf(MSG_INFO, "nl80211: insufficient buffer space for reply"); | |
8698 | return NL_SKIP; | |
8699 | } | |
8700 | ||
8701 | wpabuf_put_data(buf, genlmsg_attrdata(gnlh, 0), | |
8702 | genlmsg_attrlen(gnlh, 0)); | |
8703 | ||
8704 | return NL_SKIP; | |
8705 | } | |
8706 | #endif /* CONFIG_TESTING_OPTIONS */ | |
8707 | ||
8708 | ||
adef8948 BL |
8709 | static int vendor_reply_handler(struct nl_msg *msg, void *arg) |
8710 | { | |
8711 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
8712 | struct nlattr *nl_vendor_reply, *nl; | |
8713 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
8714 | struct wpabuf *buf = arg; | |
8715 | int rem; | |
8716 | ||
8717 | if (!buf) | |
8718 | return NL_SKIP; | |
8719 | ||
8720 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
8721 | genlmsg_attrlen(gnlh, 0), NULL); | |
8722 | nl_vendor_reply = tb[NL80211_ATTR_VENDOR_DATA]; | |
8723 | ||
8724 | if (!nl_vendor_reply) | |
8725 | return NL_SKIP; | |
8726 | ||
8727 | if ((size_t) nla_len(nl_vendor_reply) > wpabuf_tailroom(buf)) { | |
8728 | wpa_printf(MSG_INFO, "nl80211: Vendor command: insufficient buffer space for reply"); | |
8729 | return NL_SKIP; | |
8730 | } | |
8731 | ||
8732 | nla_for_each_nested(nl, nl_vendor_reply, rem) { | |
8733 | wpabuf_put_data(buf, nla_data(nl), nla_len(nl)); | |
8734 | } | |
8735 | ||
8736 | return NL_SKIP; | |
8737 | } | |
8738 | ||
8739 | ||
8740 | static int nl80211_vendor_cmd(void *priv, unsigned int vendor_id, | |
8741 | unsigned int subcmd, const u8 *data, | |
8742 | size_t data_len, struct wpabuf *buf) | |
8743 | { | |
8744 | struct i802_bss *bss = priv; | |
8745 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8746 | struct nl_msg *msg; | |
8747 | int ret; | |
8748 | ||
6b9f7af6 JM |
8749 | #ifdef CONFIG_TESTING_OPTIONS |
8750 | if (vendor_id == 0xffffffff) { | |
56f77852 JM |
8751 | msg = nlmsg_alloc(); |
8752 | if (!msg) | |
8753 | return -ENOMEM; | |
8754 | ||
6b9f7af6 JM |
8755 | nl80211_cmd(drv, msg, 0, subcmd); |
8756 | if (nlmsg_append(msg, (void *) data, data_len, NLMSG_ALIGNTO) < | |
8757 | 0) | |
a862e4a3 | 8758 | goto fail; |
6b9f7af6 JM |
8759 | ret = send_and_recv_msgs(drv, msg, cmd_reply_handler, buf); |
8760 | if (ret) | |
8761 | wpa_printf(MSG_DEBUG, "nl80211: command failed err=%d", | |
8762 | ret); | |
8763 | return ret; | |
8764 | } | |
8765 | #endif /* CONFIG_TESTING_OPTIONS */ | |
8766 | ||
56f77852 | 8767 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_VENDOR)) || |
a862e4a3 JM |
8768 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, vendor_id) || |
8769 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, subcmd) || | |
8770 | (data && | |
8771 | nla_put(msg, NL80211_ATTR_VENDOR_DATA, data_len, data))) | |
8772 | goto fail; | |
adef8948 BL |
8773 | |
8774 | ret = send_and_recv_msgs(drv, msg, vendor_reply_handler, buf); | |
8775 | if (ret) | |
8776 | wpa_printf(MSG_DEBUG, "nl80211: vendor command failed err=%d", | |
8777 | ret); | |
8778 | return ret; | |
8779 | ||
a862e4a3 | 8780 | fail: |
adef8948 BL |
8781 | nlmsg_free(msg); |
8782 | return -ENOBUFS; | |
8783 | } | |
8784 | ||
8785 | ||
049105b4 KP |
8786 | static int nl80211_set_qos_map(void *priv, const u8 *qos_map_set, |
8787 | u8 qos_map_set_len) | |
8788 | { | |
8789 | struct i802_bss *bss = priv; | |
8790 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8791 | struct nl_msg *msg; | |
8792 | int ret; | |
8793 | ||
049105b4 KP |
8794 | wpa_hexdump(MSG_DEBUG, "nl80211: Setting QoS Map", |
8795 | qos_map_set, qos_map_set_len); | |
8796 | ||
9725b784 | 8797 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_QOS_MAP)) || |
a862e4a3 JM |
8798 | nla_put(msg, NL80211_ATTR_QOS_MAP, qos_map_set_len, qos_map_set)) { |
8799 | nlmsg_free(msg); | |
8800 | return -ENOBUFS; | |
8801 | } | |
049105b4 KP |
8802 | |
8803 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
8804 | if (ret) | |
8805 | wpa_printf(MSG_DEBUG, "nl80211: Setting QoS Map failed"); | |
8806 | ||
8807 | return ret; | |
049105b4 KP |
8808 | } |
8809 | ||
8810 | ||
e4fa8b12 EP |
8811 | static int nl80211_set_wowlan(void *priv, |
8812 | const struct wowlan_triggers *triggers) | |
8813 | { | |
8814 | struct i802_bss *bss = priv; | |
8815 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8816 | struct nl_msg *msg; | |
8817 | struct nlattr *wowlan_triggers; | |
8818 | int ret; | |
8819 | ||
e4fa8b12 EP |
8820 | wpa_printf(MSG_DEBUG, "nl80211: Setting wowlan"); |
8821 | ||
1ac977bd | 8822 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_SET_WOWLAN)) || |
a862e4a3 JM |
8823 | !(wowlan_triggers = nla_nest_start(msg, |
8824 | NL80211_ATTR_WOWLAN_TRIGGERS)) || | |
8825 | (triggers->any && | |
8826 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || | |
8827 | (triggers->disconnect && | |
8828 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || | |
8829 | (triggers->magic_pkt && | |
8830 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || | |
8831 | (triggers->gtk_rekey_failure && | |
8832 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || | |
8833 | (triggers->eap_identity_req && | |
8834 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || | |
8835 | (triggers->four_way_handshake && | |
8836 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || | |
8837 | (triggers->rfkill_release && | |
8838 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) { | |
8839 | nlmsg_free(msg); | |
8840 | return -ENOBUFS; | |
8841 | } | |
e4fa8b12 EP |
8842 | |
8843 | nla_nest_end(msg, wowlan_triggers); | |
8844 | ||
8845 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
8846 | if (ret) | |
8847 | wpa_printf(MSG_DEBUG, "nl80211: Setting wowlan failed"); | |
8848 | ||
8849 | return ret; | |
e4fa8b12 EP |
8850 | } |
8851 | ||
8852 | ||
b658547d | 8853 | #ifdef CONFIG_DRIVER_NL80211_QCA |
0800f9ee JM |
8854 | static int nl80211_roaming(void *priv, int allowed, const u8 *bssid) |
8855 | { | |
8856 | struct i802_bss *bss = priv; | |
8857 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8858 | struct nl_msg *msg; | |
8859 | struct nlattr *params; | |
8860 | ||
8861 | wpa_printf(MSG_DEBUG, "nl80211: Roaming policy: allowed=%d", allowed); | |
8862 | ||
8863 | if (!drv->roaming_vendor_cmd_avail) { | |
8864 | wpa_printf(MSG_DEBUG, | |
8865 | "nl80211: Ignore roaming policy change since driver does not provide command for setting it"); | |
8866 | return -1; | |
8867 | } | |
8868 | ||
9725b784 | 8869 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
a862e4a3 JM |
8870 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
8871 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | |
8872 | QCA_NL80211_VENDOR_SUBCMD_ROAMING) || | |
8873 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || | |
8874 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_ROAMING_POLICY, | |
8875 | allowed ? QCA_ROAMING_ALLOWED_WITHIN_ESS : | |
8876 | QCA_ROAMING_NOT_ALLOWED) || | |
8877 | (bssid && | |
8878 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_MAC_ADDR, ETH_ALEN, bssid))) { | |
8879 | nlmsg_free(msg); | |
8880 | return -1; | |
8881 | } | |
0800f9ee JM |
8882 | nla_nest_end(msg, params); |
8883 | ||
8884 | return send_and_recv_msgs(drv, msg, NULL, NULL); | |
0800f9ee | 8885 | } |
b04854ce AP |
8886 | |
8887 | ||
d98038bb | 8888 | static int nl80211_disable_fils(void *priv, int disable) |
8889 | { | |
8890 | struct i802_bss *bss = priv; | |
8891 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8892 | struct nl_msg *msg; | |
8893 | struct nlattr *params; | |
8894 | ||
8895 | wpa_printf(MSG_DEBUG, "nl80211: Disable FILS=%d", disable); | |
8896 | ||
8897 | if (!drv->set_wifi_conf_vendor_cmd_avail) | |
8898 | return -1; | |
8899 | ||
8900 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || | |
8901 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || | |
8902 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | |
8903 | QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION) || | |
8904 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || | |
8905 | nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_DISABLE_FILS, | |
8906 | disable)) { | |
8907 | nlmsg_free(msg); | |
8908 | return -1; | |
8909 | } | |
8910 | nla_nest_end(msg, params); | |
8911 | ||
8912 | return send_and_recv_msgs(drv, msg, NULL, NULL); | |
8913 | } | |
8914 | ||
8915 | ||
b04854ce AP |
8916 | /* Reserved QCA_WLAN_VENDOR_ATTR_ROAMING_REQ_ID value for wpa_supplicant */ |
8917 | #define WPA_SUPPLICANT_CLIENT_ID 1 | |
8918 | ||
8919 | static int nl80211_set_bssid_blacklist(void *priv, unsigned int num_bssid, | |
8920 | const u8 *bssid) | |
8921 | { | |
8922 | struct i802_bss *bss = priv; | |
8923 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8924 | struct nl_msg *msg; | |
8925 | struct nlattr *params, *nlbssids, *attr; | |
8926 | unsigned int i; | |
8927 | ||
8928 | wpa_printf(MSG_DEBUG, "nl80211: Set blacklist BSSID (num=%u)", | |
8929 | num_bssid); | |
8930 | ||
8931 | if (!drv->roam_vendor_cmd_avail) | |
8932 | return -1; | |
8933 | ||
8934 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || | |
8935 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || | |
8936 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | |
8937 | QCA_NL80211_VENDOR_SUBCMD_ROAM) || | |
8938 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || | |
8939 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_ROAMING_SUBCMD, | |
8940 | QCA_WLAN_VENDOR_ATTR_ROAM_SUBCMD_SET_BLACKLIST_BSSID) || | |
8941 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_ROAMING_REQ_ID, | |
8942 | WPA_SUPPLICANT_CLIENT_ID) || | |
8943 | nla_put_u32(msg, | |
8944 | QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_SET_BSSID_PARAMS_NUM_BSSID, | |
8945 | num_bssid)) | |
8946 | goto fail; | |
8947 | ||
8948 | nlbssids = nla_nest_start( | |
8949 | msg, QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_SET_BSSID_PARAMS); | |
8950 | if (!nlbssids) | |
8951 | goto fail; | |
8952 | ||
8953 | for (i = 0; i < num_bssid; i++) { | |
8954 | attr = nla_nest_start(msg, i); | |
8955 | if (!attr) | |
8956 | goto fail; | |
8957 | if (nla_put(msg, | |
8958 | QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_SET_BSSID_PARAMS_BSSID, | |
8959 | ETH_ALEN, &bssid[i * ETH_ALEN])) | |
8960 | goto fail; | |
8961 | wpa_printf(MSG_DEBUG, "nl80211: BSSID[%u]: " MACSTR, i, | |
8962 | MAC2STR(&bssid[i * ETH_ALEN])); | |
8963 | nla_nest_end(msg, attr); | |
8964 | } | |
8965 | nla_nest_end(msg, nlbssids); | |
8966 | nla_nest_end(msg, params); | |
8967 | ||
8968 | return send_and_recv_msgs(drv, msg, NULL, NULL); | |
8969 | ||
8970 | fail: | |
8971 | nlmsg_free(msg); | |
8972 | return -1; | |
8973 | } | |
8974 | ||
b658547d | 8975 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
0800f9ee JM |
8976 | |
8977 | ||
fee354c7 JM |
8978 | static int nl80211_set_mac_addr(void *priv, const u8 *addr) |
8979 | { | |
8980 | struct i802_bss *bss = priv; | |
8981 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8982 | int new_addr = addr != NULL; | |
8983 | ||
9ce3e610 JM |
8984 | if (TEST_FAIL()) |
8985 | return -1; | |
8986 | ||
fee354c7 JM |
8987 | if (!addr) |
8988 | addr = drv->perm_addr; | |
8989 | ||
8990 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 0) < 0) | |
8991 | return -1; | |
8992 | ||
8993 | if (linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname, addr) < 0) | |
8994 | { | |
8995 | wpa_printf(MSG_DEBUG, | |
8996 | "nl80211: failed to set_mac_addr for %s to " MACSTR, | |
8997 | bss->ifname, MAC2STR(addr)); | |
8998 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, | |
8999 | 1) < 0) { | |
9000 | wpa_printf(MSG_DEBUG, | |
9001 | "nl80211: Could not restore interface UP after failed set_mac_addr"); | |
9002 | } | |
9003 | return -1; | |
9004 | } | |
9005 | ||
9006 | wpa_printf(MSG_DEBUG, "nl80211: set_mac_addr for %s to " MACSTR, | |
9007 | bss->ifname, MAC2STR(addr)); | |
9008 | drv->addr_changed = new_addr; | |
9009 | os_memcpy(bss->addr, addr, ETH_ALEN); | |
9010 | ||
9011 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 1) < 0) | |
9012 | { | |
9013 | wpa_printf(MSG_DEBUG, | |
9014 | "nl80211: Could not restore interface UP after set_mac_addr"); | |
9015 | } | |
9016 | ||
9017 | return 0; | |
9018 | } | |
9019 | ||
9020 | ||
6c1664f6 BC |
9021 | #ifdef CONFIG_MESH |
9022 | ||
9023 | static int wpa_driver_nl80211_init_mesh(void *priv) | |
9024 | { | |
9025 | if (wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_MESH_POINT)) { | |
9026 | wpa_printf(MSG_INFO, | |
9027 | "nl80211: Failed to set interface into mesh mode"); | |
9028 | return -1; | |
9029 | } | |
9030 | return 0; | |
9031 | } | |
9032 | ||
9033 | ||
21c74e84 JM |
9034 | static int nl80211_put_mesh_id(struct nl_msg *msg, const u8 *mesh_id, |
9035 | size_t mesh_id_len) | |
9036 | { | |
9037 | if (mesh_id) { | |
9038 | wpa_hexdump_ascii(MSG_DEBUG, " * Mesh ID (SSID)", | |
9039 | mesh_id, mesh_id_len); | |
9040 | return nla_put(msg, NL80211_ATTR_MESH_ID, mesh_id_len, mesh_id); | |
9041 | } | |
9042 | ||
9043 | return 0; | |
9044 | } | |
9045 | ||
9046 | ||
4ffb3f87 MH |
9047 | static int nl80211_put_mesh_config(struct nl_msg *msg, |
9048 | struct wpa_driver_mesh_bss_params *params) | |
9049 | { | |
9050 | struct nlattr *container; | |
9051 | ||
9052 | container = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); | |
9053 | if (!container) | |
9054 | return -1; | |
9055 | ||
2bd62171 | 9056 | if (((params->flags & WPA_DRIVER_MESH_CONF_FLAG_AUTO_PLINKS) && |
963d3149 JM |
9057 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
9058 | params->auto_plinks)) || | |
2bd62171 MH |
9059 | ((params->flags & WPA_DRIVER_MESH_CONF_FLAG_MAX_PEER_LINKS) && |
9060 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, | |
31a856a1 MH |
9061 | params->max_peer_links)) || |
9062 | ((params->flags & WPA_DRIVER_MESH_CONF_FLAG_RSSI_THRESHOLD) && | |
9063 | nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, | |
9064 | params->rssi_threshold))) | |
4ffb3f87 MH |
9065 | return -1; |
9066 | ||
9067 | /* | |
9068 | * Set NL80211_MESHCONF_PLINK_TIMEOUT even if user mpm is used because | |
9069 | * the timer could disconnect stations even in that case. | |
9070 | */ | |
2bd62171 MH |
9071 | if ((params->flags & WPA_DRIVER_MESH_CONF_FLAG_PEER_LINK_TIMEOUT) && |
9072 | nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, | |
4ffb3f87 MH |
9073 | params->peer_link_timeout)) { |
9074 | wpa_printf(MSG_ERROR, "nl80211: Failed to set PLINK_TIMEOUT"); | |
9075 | return -1; | |
9076 | } | |
9077 | ||
052b8d38 MH |
9078 | if ((params->flags & WPA_DRIVER_MESH_CONF_FLAG_HT_OP_MODE) && |
9079 | nla_put_u16(msg, NL80211_MESHCONF_HT_OPMODE, params->ht_opmode)) { | |
9080 | wpa_printf(MSG_ERROR, "nl80211: Failed to set HT_OP_MODE"); | |
9081 | return -1; | |
9082 | } | |
9083 | ||
4ffb3f87 MH |
9084 | nla_nest_end(msg, container); |
9085 | ||
9086 | return 0; | |
9087 | } | |
9088 | ||
9089 | ||
0cb5f8d9 | 9090 | static int nl80211_join_mesh(struct i802_bss *bss, |
6c1664f6 BC |
9091 | struct wpa_driver_mesh_join_params *params) |
9092 | { | |
6c1664f6 BC |
9093 | struct wpa_driver_nl80211_data *drv = bss->drv; |
9094 | struct nl_msg *msg; | |
9095 | struct nlattr *container; | |
7451a217 | 9096 | int ret = -1; |
6c1664f6 | 9097 | |
6c1664f6 | 9098 | wpa_printf(MSG_DEBUG, "nl80211: mesh join (ifindex=%d)", drv->ifindex); |
9725b784 | 9099 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_JOIN_MESH); |
f7e889fa JM |
9100 | if (!msg || |
9101 | nl80211_put_freq_params(msg, ¶ms->freq) || | |
21c74e84 JM |
9102 | nl80211_put_basic_rates(msg, params->basic_rates) || |
9103 | nl80211_put_mesh_id(msg, params->meshid, params->meshid_len) || | |
4ac2ea57 MH |
9104 | nl80211_put_beacon_int(msg, params->beacon_int) || |
9105 | nl80211_put_dtim_period(msg, params->dtim_period)) | |
85e1fad8 | 9106 | goto fail; |
9c58c5f7 | 9107 | |
6c1664f6 BC |
9108 | wpa_printf(MSG_DEBUG, " * flags=%08X", params->flags); |
9109 | ||
9110 | container = nla_nest_start(msg, NL80211_ATTR_MESH_SETUP); | |
9111 | if (!container) | |
a862e4a3 | 9112 | goto fail; |
6c1664f6 BC |
9113 | |
9114 | if (params->ies) { | |
9115 | wpa_hexdump(MSG_DEBUG, " * IEs", params->ies, params->ie_len); | |
a862e4a3 JM |
9116 | if (nla_put(msg, NL80211_MESH_SETUP_IE, params->ie_len, |
9117 | params->ies)) | |
9118 | goto fail; | |
6c1664f6 BC |
9119 | } |
9120 | /* WPA_DRIVER_MESH_FLAG_OPEN_AUTH is treated as default by nl80211 */ | |
9121 | if (params->flags & WPA_DRIVER_MESH_FLAG_SAE_AUTH) { | |
a862e4a3 JM |
9122 | if (nla_put_u8(msg, NL80211_MESH_SETUP_AUTH_PROTOCOL, 0x1) || |
9123 | nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_AUTH)) | |
9124 | goto fail; | |
6c1664f6 | 9125 | } |
a862e4a3 JM |
9126 | if ((params->flags & WPA_DRIVER_MESH_FLAG_AMPE) && |
9127 | nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_AMPE)) | |
9128 | goto fail; | |
9129 | if ((params->flags & WPA_DRIVER_MESH_FLAG_USER_MPM) && | |
9130 | nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_MPM)) | |
9131 | goto fail; | |
6c1664f6 BC |
9132 | nla_nest_end(msg, container); |
9133 | ||
2bd62171 MH |
9134 | params->conf.flags |= WPA_DRIVER_MESH_CONF_FLAG_AUTO_PLINKS; |
9135 | params->conf.flags |= WPA_DRIVER_MESH_CONF_FLAG_PEER_LINK_TIMEOUT; | |
9136 | params->conf.flags |= WPA_DRIVER_MESH_CONF_FLAG_MAX_PEER_LINKS; | |
4ffb3f87 | 9137 | if (nl80211_put_mesh_config(msg, ¶ms->conf) < 0) |
5a2a6de6 | 9138 | goto fail; |
6c1664f6 BC |
9139 | |
9140 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
9141 | msg = NULL; | |
9142 | if (ret) { | |
9143 | wpa_printf(MSG_DEBUG, "nl80211: mesh join failed: ret=%d (%s)", | |
9144 | ret, strerror(-ret)); | |
a862e4a3 | 9145 | goto fail; |
6c1664f6 BC |
9146 | } |
9147 | ret = 0; | |
92a515b8 | 9148 | drv->assoc_freq = bss->freq = params->freq.freq; |
6c1664f6 BC |
9149 | wpa_printf(MSG_DEBUG, "nl80211: mesh join request send successfully"); |
9150 | ||
a862e4a3 | 9151 | fail: |
6c1664f6 BC |
9152 | nlmsg_free(msg); |
9153 | return ret; | |
9154 | } | |
9155 | ||
9156 | ||
0cb5f8d9 MH |
9157 | static int |
9158 | wpa_driver_nl80211_join_mesh(void *priv, | |
9159 | struct wpa_driver_mesh_join_params *params) | |
9160 | { | |
9161 | struct i802_bss *bss = priv; | |
9162 | int ret, timeout; | |
9163 | ||
9164 | timeout = params->conf.peer_link_timeout; | |
9165 | ||
9166 | /* Disable kernel inactivity timer */ | |
9167 | if (params->flags & WPA_DRIVER_MESH_FLAG_USER_MPM) | |
9168 | params->conf.peer_link_timeout = 0; | |
9169 | ||
9170 | ret = nl80211_join_mesh(bss, params); | |
9171 | if (ret == -EINVAL && params->conf.peer_link_timeout == 0) { | |
9172 | wpa_printf(MSG_DEBUG, | |
9173 | "nl80211: Mesh join retry for peer_link_timeout"); | |
9174 | /* | |
9175 | * Old kernel does not support setting | |
9176 | * NL80211_MESHCONF_PLINK_TIMEOUT to zero, so set 60 seconds | |
9177 | * into future from peer_link_timeout. | |
9178 | */ | |
9179 | params->conf.peer_link_timeout = timeout + 60; | |
9180 | ret = nl80211_join_mesh(priv, params); | |
9181 | } | |
9182 | ||
9183 | params->conf.peer_link_timeout = timeout; | |
9184 | return ret; | |
9185 | } | |
9186 | ||
9187 | ||
6c1664f6 BC |
9188 | static int wpa_driver_nl80211_leave_mesh(void *priv) |
9189 | { | |
9190 | struct i802_bss *bss = priv; | |
9191 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
9192 | struct nl_msg *msg; | |
9725b784 | 9193 | int ret; |
6c1664f6 BC |
9194 | |
9195 | wpa_printf(MSG_DEBUG, "nl80211: mesh leave (ifindex=%d)", drv->ifindex); | |
9725b784 | 9196 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_LEAVE_MESH); |
6c1664f6 | 9197 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
6c1664f6 BC |
9198 | if (ret) { |
9199 | wpa_printf(MSG_DEBUG, "nl80211: mesh leave failed: ret=%d (%s)", | |
9200 | ret, strerror(-ret)); | |
a862e4a3 JM |
9201 | } else { |
9202 | wpa_printf(MSG_DEBUG, | |
9203 | "nl80211: mesh leave request send successfully"); | |
6c1664f6 | 9204 | } |
6c1664f6 | 9205 | |
f33c82d2 JM |
9206 | if (wpa_driver_nl80211_set_mode(drv->first_bss, |
9207 | NL80211_IFTYPE_STATION)) { | |
9208 | wpa_printf(MSG_INFO, | |
9209 | "nl80211: Failed to set interface into station mode"); | |
9210 | } | |
6c1664f6 BC |
9211 | return ret; |
9212 | } | |
9213 | ||
9214 | #endif /* CONFIG_MESH */ | |
9215 | ||
9216 | ||
ed4ddb6d KP |
9217 | static int wpa_driver_br_add_ip_neigh(void *priv, u8 version, |
9218 | const u8 *ipaddr, int prefixlen, | |
9219 | const u8 *addr) | |
71103bed KP |
9220 | { |
9221 | #ifdef CONFIG_LIBNL3_ROUTE | |
9222 | struct i802_bss *bss = priv; | |
9223 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
9224 | struct rtnl_neigh *rn; | |
9225 | struct nl_addr *nl_ipaddr = NULL; | |
9226 | struct nl_addr *nl_lladdr = NULL; | |
ed4ddb6d | 9227 | int family, addrsize; |
71103bed KP |
9228 | int res; |
9229 | ||
ed4ddb6d | 9230 | if (!ipaddr || prefixlen == 0 || !addr) |
71103bed KP |
9231 | return -EINVAL; |
9232 | ||
9233 | if (bss->br_ifindex == 0) { | |
9234 | wpa_printf(MSG_DEBUG, | |
9235 | "nl80211: bridge must be set before adding an ip neigh to it"); | |
9236 | return -1; | |
9237 | } | |
9238 | ||
9239 | if (!drv->rtnl_sk) { | |
9240 | wpa_printf(MSG_DEBUG, | |
9241 | "nl80211: nl_sock for NETLINK_ROUTE is not initialized"); | |
9242 | return -1; | |
9243 | } | |
9244 | ||
ed4ddb6d KP |
9245 | if (version == 4) { |
9246 | family = AF_INET; | |
9247 | addrsize = 4; | |
9248 | } else if (version == 6) { | |
9249 | family = AF_INET6; | |
9250 | addrsize = 16; | |
9251 | } else { | |
9252 | return -EINVAL; | |
9253 | } | |
9254 | ||
71103bed KP |
9255 | rn = rtnl_neigh_alloc(); |
9256 | if (rn == NULL) | |
9257 | return -ENOMEM; | |
9258 | ||
9259 | /* set the destination ip address for neigh */ | |
ed4ddb6d | 9260 | nl_ipaddr = nl_addr_build(family, (void *) ipaddr, addrsize); |
71103bed KP |
9261 | if (nl_ipaddr == NULL) { |
9262 | wpa_printf(MSG_DEBUG, "nl80211: nl_ipaddr build failed"); | |
9263 | res = -ENOMEM; | |
9264 | goto errout; | |
9265 | } | |
9266 | nl_addr_set_prefixlen(nl_ipaddr, prefixlen); | |
9267 | res = rtnl_neigh_set_dst(rn, nl_ipaddr); | |
9268 | if (res) { | |
9269 | wpa_printf(MSG_DEBUG, | |
9270 | "nl80211: neigh set destination addr failed"); | |
9271 | goto errout; | |
9272 | } | |
9273 | ||
9274 | /* set the corresponding lladdr for neigh */ | |
9275 | nl_lladdr = nl_addr_build(AF_BRIDGE, (u8 *) addr, ETH_ALEN); | |
9276 | if (nl_lladdr == NULL) { | |
9277 | wpa_printf(MSG_DEBUG, "nl80211: neigh set lladdr failed"); | |
9278 | res = -ENOMEM; | |
9279 | goto errout; | |
9280 | } | |
9281 | rtnl_neigh_set_lladdr(rn, nl_lladdr); | |
9282 | ||
9283 | rtnl_neigh_set_ifindex(rn, bss->br_ifindex); | |
9284 | rtnl_neigh_set_state(rn, NUD_PERMANENT); | |
9285 | ||
9286 | res = rtnl_neigh_add(drv->rtnl_sk, rn, NLM_F_CREATE); | |
9287 | if (res) { | |
9288 | wpa_printf(MSG_DEBUG, | |
9289 | "nl80211: Adding bridge ip neigh failed: %s", | |
9290 | strerror(errno)); | |
9291 | } | |
9292 | errout: | |
9293 | if (nl_lladdr) | |
9294 | nl_addr_put(nl_lladdr); | |
9295 | if (nl_ipaddr) | |
9296 | nl_addr_put(nl_ipaddr); | |
9297 | if (rn) | |
9298 | rtnl_neigh_put(rn); | |
9299 | return res; | |
9300 | #else /* CONFIG_LIBNL3_ROUTE */ | |
9301 | return -1; | |
9302 | #endif /* CONFIG_LIBNL3_ROUTE */ | |
9303 | } | |
9304 | ||
9305 | ||
ed4ddb6d KP |
9306 | static int wpa_driver_br_delete_ip_neigh(void *priv, u8 version, |
9307 | const u8 *ipaddr) | |
71103bed KP |
9308 | { |
9309 | #ifdef CONFIG_LIBNL3_ROUTE | |
9310 | struct i802_bss *bss = priv; | |
9311 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
9312 | struct rtnl_neigh *rn; | |
9313 | struct nl_addr *nl_ipaddr; | |
ed4ddb6d | 9314 | int family, addrsize; |
71103bed KP |
9315 | int res; |
9316 | ||
ed4ddb6d | 9317 | if (!ipaddr) |
71103bed KP |
9318 | return -EINVAL; |
9319 | ||
ed4ddb6d KP |
9320 | if (version == 4) { |
9321 | family = AF_INET; | |
9322 | addrsize = 4; | |
9323 | } else if (version == 6) { | |
9324 | family = AF_INET6; | |
9325 | addrsize = 16; | |
9326 | } else { | |
9327 | return -EINVAL; | |
9328 | } | |
9329 | ||
71103bed KP |
9330 | if (bss->br_ifindex == 0) { |
9331 | wpa_printf(MSG_DEBUG, | |
9332 | "nl80211: bridge must be set to delete an ip neigh"); | |
9333 | return -1; | |
9334 | } | |
9335 | ||
9336 | if (!drv->rtnl_sk) { | |
9337 | wpa_printf(MSG_DEBUG, | |
9338 | "nl80211: nl_sock for NETLINK_ROUTE is not initialized"); | |
9339 | return -1; | |
9340 | } | |
9341 | ||
9342 | rn = rtnl_neigh_alloc(); | |
9343 | if (rn == NULL) | |
9344 | return -ENOMEM; | |
9345 | ||
9346 | /* set the destination ip address for neigh */ | |
ed4ddb6d | 9347 | nl_ipaddr = nl_addr_build(family, (void *) ipaddr, addrsize); |
71103bed KP |
9348 | if (nl_ipaddr == NULL) { |
9349 | wpa_printf(MSG_DEBUG, "nl80211: nl_ipaddr build failed"); | |
9350 | res = -ENOMEM; | |
9351 | goto errout; | |
9352 | } | |
9353 | res = rtnl_neigh_set_dst(rn, nl_ipaddr); | |
9354 | if (res) { | |
9355 | wpa_printf(MSG_DEBUG, | |
9356 | "nl80211: neigh set destination addr failed"); | |
9357 | goto errout; | |
9358 | } | |
9359 | ||
9360 | rtnl_neigh_set_ifindex(rn, bss->br_ifindex); | |
9361 | ||
9362 | res = rtnl_neigh_delete(drv->rtnl_sk, rn, 0); | |
9363 | if (res) { | |
9364 | wpa_printf(MSG_DEBUG, | |
9365 | "nl80211: Deleting bridge ip neigh failed: %s", | |
9366 | strerror(errno)); | |
9367 | } | |
9368 | errout: | |
9369 | if (nl_ipaddr) | |
9370 | nl_addr_put(nl_ipaddr); | |
9371 | if (rn) | |
9372 | rtnl_neigh_put(rn); | |
9373 | return res; | |
9374 | #else /* CONFIG_LIBNL3_ROUTE */ | |
9375 | return -1; | |
9376 | #endif /* CONFIG_LIBNL3_ROUTE */ | |
9377 | } | |
9378 | ||
9379 | ||
73d2294f KP |
9380 | static int linux_write_system_file(const char *path, unsigned int val) |
9381 | { | |
9382 | char buf[50]; | |
9383 | int fd, len; | |
9384 | ||
9385 | len = os_snprintf(buf, sizeof(buf), "%u\n", val); | |
a9aaacbb | 9386 | if (os_snprintf_error(sizeof(buf), len)) |
73d2294f KP |
9387 | return -1; |
9388 | ||
9389 | fd = open(path, O_WRONLY); | |
9390 | if (fd < 0) | |
9391 | return -1; | |
9392 | ||
9393 | if (write(fd, buf, len) < 0) { | |
9394 | wpa_printf(MSG_DEBUG, | |
9395 | "nl80211: Failed to write Linux system file: %s with the value of %d", | |
9396 | path, val); | |
9397 | close(fd); | |
9398 | return -1; | |
9399 | } | |
9400 | close(fd); | |
9401 | ||
9402 | return 0; | |
9403 | } | |
9404 | ||
9405 | ||
9406 | static const char * drv_br_port_attr_str(enum drv_br_port_attr attr) | |
9407 | { | |
9408 | switch (attr) { | |
9409 | case DRV_BR_PORT_ATTR_PROXYARP: | |
bea8d9a3 | 9410 | return "proxyarp_wifi"; |
73d2294f KP |
9411 | case DRV_BR_PORT_ATTR_HAIRPIN_MODE: |
9412 | return "hairpin_mode"; | |
9413 | } | |
9414 | ||
9415 | return NULL; | |
9416 | } | |
9417 | ||
9418 | ||
9419 | static int wpa_driver_br_port_set_attr(void *priv, enum drv_br_port_attr attr, | |
9420 | unsigned int val) | |
9421 | { | |
9422 | struct i802_bss *bss = priv; | |
9423 | char path[128]; | |
9424 | const char *attr_txt; | |
9425 | ||
9426 | attr_txt = drv_br_port_attr_str(attr); | |
9427 | if (attr_txt == NULL) | |
9428 | return -EINVAL; | |
9429 | ||
9430 | os_snprintf(path, sizeof(path), "/sys/class/net/%s/brport/%s", | |
9431 | bss->ifname, attr_txt); | |
9432 | ||
9433 | if (linux_write_system_file(path, val)) | |
9434 | return -1; | |
9435 | ||
9436 | return 0; | |
9437 | } | |
9438 | ||
9439 | ||
7565752d KP |
9440 | static const char * drv_br_net_param_str(enum drv_br_net_param param) |
9441 | { | |
9442 | switch (param) { | |
9443 | case DRV_BR_NET_PARAM_GARP_ACCEPT: | |
9444 | return "arp_accept"; | |
60eb9e17 JM |
9445 | default: |
9446 | return NULL; | |
7565752d | 9447 | } |
7565752d KP |
9448 | } |
9449 | ||
9450 | ||
9451 | static int wpa_driver_br_set_net_param(void *priv, enum drv_br_net_param param, | |
9452 | unsigned int val) | |
9453 | { | |
9454 | struct i802_bss *bss = priv; | |
9455 | char path[128]; | |
9456 | const char *param_txt; | |
9457 | int ip_version = 4; | |
9458 | ||
60eb9e17 JM |
9459 | if (param == DRV_BR_MULTICAST_SNOOPING) { |
9460 | os_snprintf(path, sizeof(path), | |
9461 | "/sys/devices/virtual/net/%s/bridge/multicast_snooping", | |
9462 | bss->brname); | |
9463 | goto set_val; | |
9464 | } | |
9465 | ||
7565752d KP |
9466 | param_txt = drv_br_net_param_str(param); |
9467 | if (param_txt == NULL) | |
9468 | return -EINVAL; | |
9469 | ||
9470 | switch (param) { | |
9471 | case DRV_BR_NET_PARAM_GARP_ACCEPT: | |
9472 | ip_version = 4; | |
9473 | break; | |
9474 | default: | |
9475 | return -EINVAL; | |
9476 | } | |
9477 | ||
9478 | os_snprintf(path, sizeof(path), "/proc/sys/net/ipv%d/conf/%s/%s", | |
9479 | ip_version, bss->brname, param_txt); | |
9480 | ||
60eb9e17 | 9481 | set_val: |
7565752d KP |
9482 | if (linux_write_system_file(path, val)) |
9483 | return -1; | |
9484 | ||
9485 | return 0; | |
9486 | } | |
9487 | ||
9488 | ||
b658547d JM |
9489 | #ifdef CONFIG_DRIVER_NL80211_QCA |
9490 | ||
16689c7c PX |
9491 | static int hw_mode_to_qca_acs(enum hostapd_hw_mode hw_mode) |
9492 | { | |
9493 | switch (hw_mode) { | |
9494 | case HOSTAPD_MODE_IEEE80211B: | |
9495 | return QCA_ACS_MODE_IEEE80211B; | |
9496 | case HOSTAPD_MODE_IEEE80211G: | |
9497 | return QCA_ACS_MODE_IEEE80211G; | |
9498 | case HOSTAPD_MODE_IEEE80211A: | |
9499 | return QCA_ACS_MODE_IEEE80211A; | |
9500 | case HOSTAPD_MODE_IEEE80211AD: | |
9501 | return QCA_ACS_MODE_IEEE80211AD; | |
3784c058 PX |
9502 | case HOSTAPD_MODE_IEEE80211ANY: |
9503 | return QCA_ACS_MODE_IEEE80211ANY; | |
16689c7c PX |
9504 | default: |
9505 | return -1; | |
9506 | } | |
9507 | } | |
9508 | ||
9509 | ||
d0cdccd3 PX |
9510 | static int add_acs_freq_list(struct nl_msg *msg, const int *freq_list) |
9511 | { | |
9512 | int i, len, ret; | |
9513 | u32 *freqs; | |
9514 | ||
9515 | if (!freq_list) | |
9516 | return 0; | |
9517 | len = int_array_len(freq_list); | |
9518 | freqs = os_malloc(sizeof(u32) * len); | |
9519 | if (!freqs) | |
9520 | return -1; | |
9521 | for (i = 0; i < len; i++) | |
9522 | freqs[i] = freq_list[i]; | |
9523 | ret = nla_put(msg, QCA_WLAN_VENDOR_ATTR_ACS_FREQ_LIST, | |
9524 | sizeof(u32) * len, freqs); | |
9525 | os_free(freqs); | |
9526 | return ret; | |
9527 | } | |
9528 | ||
9529 | ||
16689c7c PX |
9530 | static int wpa_driver_do_acs(void *priv, struct drv_acs_params *params) |
9531 | { | |
9532 | struct i802_bss *bss = priv; | |
9533 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
9534 | struct nl_msg *msg; | |
9535 | struct nlattr *data; | |
a862e4a3 | 9536 | int ret; |
16689c7c PX |
9537 | int mode; |
9538 | ||
9539 | mode = hw_mode_to_qca_acs(params->hw_mode); | |
9540 | if (mode < 0) | |
9541 | return -1; | |
9542 | ||
9725b784 | 9543 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
a862e4a3 JM |
9544 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
9545 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | |
9546 | QCA_NL80211_VENDOR_SUBCMD_DO_ACS) || | |
9547 | !(data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || | |
9548 | nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_ACS_HW_MODE, mode) || | |
9549 | (params->ht_enabled && | |
9550 | nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_HT_ENABLED)) || | |
9551 | (params->ht40_enabled && | |
857d9422 MM |
9552 | nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_HT40_ENABLED)) || |
9553 | (params->vht_enabled && | |
9554 | nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_VHT_ENABLED)) || | |
9555 | nla_put_u16(msg, QCA_WLAN_VENDOR_ATTR_ACS_CHWIDTH, | |
9556 | params->ch_width) || | |
9557 | (params->ch_list_len && | |
9558 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_ACS_CH_LIST, params->ch_list_len, | |
d0cdccd3 PX |
9559 | params->ch_list)) || |
9560 | add_acs_freq_list(msg, params->freq_list)) { | |
a862e4a3 JM |
9561 | nlmsg_free(msg); |
9562 | return -ENOBUFS; | |
9563 | } | |
16689c7c PX |
9564 | nla_nest_end(msg, data); |
9565 | ||
857d9422 MM |
9566 | wpa_printf(MSG_DEBUG, |
9567 | "nl80211: ACS Params: HW_MODE: %d HT: %d HT40: %d VHT: %d BW: %d CH_LIST_LEN: %u", | |
9568 | params->hw_mode, params->ht_enabled, params->ht40_enabled, | |
9569 | params->vht_enabled, params->ch_width, params->ch_list_len); | |
9570 | ||
16689c7c | 9571 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
16689c7c PX |
9572 | if (ret) { |
9573 | wpa_printf(MSG_DEBUG, | |
9574 | "nl80211: Failed to invoke driver ACS function: %s", | |
9575 | strerror(errno)); | |
9576 | } | |
16689c7c PX |
9577 | return ret; |
9578 | } | |
9579 | ||
9580 | ||
844dfeb8 SD |
9581 | static int nl80211_set_band(void *priv, enum set_band band) |
9582 | { | |
9583 | struct i802_bss *bss = priv; | |
9584 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
9585 | struct nl_msg *msg; | |
9586 | struct nlattr *data; | |
9587 | int ret; | |
9588 | enum qca_set_band qca_band; | |
9589 | ||
9590 | if (!drv->setband_vendor_cmd_avail) | |
9591 | return -1; | |
9592 | ||
9593 | switch (band) { | |
9594 | case WPA_SETBAND_AUTO: | |
9595 | qca_band = QCA_SETBAND_AUTO; | |
9596 | break; | |
9597 | case WPA_SETBAND_5G: | |
9598 | qca_band = QCA_SETBAND_5G; | |
9599 | break; | |
9600 | case WPA_SETBAND_2G: | |
9601 | qca_band = QCA_SETBAND_2G; | |
9602 | break; | |
9603 | default: | |
9604 | return -1; | |
9605 | } | |
9606 | ||
9607 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || | |
9608 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || | |
9609 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | |
9610 | QCA_NL80211_VENDOR_SUBCMD_SETBAND) || | |
9611 | !(data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || | |
9612 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_SETBAND_VALUE, qca_band)) { | |
9613 | nlmsg_free(msg); | |
9614 | return -ENOBUFS; | |
9615 | } | |
9616 | nla_nest_end(msg, data); | |
9617 | ||
9618 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
9619 | if (ret) { | |
9620 | wpa_printf(MSG_DEBUG, | |
9621 | "nl80211: Driver setband function failed: %s", | |
9622 | strerror(errno)); | |
9623 | } | |
9624 | return ret; | |
9625 | } | |
9626 | ||
9627 | ||
98342208 AK |
9628 | struct nl80211_pcl { |
9629 | unsigned int num; | |
9630 | unsigned int *freq_list; | |
9631 | }; | |
9632 | ||
9633 | static int preferred_freq_info_handler(struct nl_msg *msg, void *arg) | |
9634 | { | |
9635 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
9636 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
9637 | struct nl80211_pcl *param = arg; | |
9638 | struct nlattr *nl_vend, *attr; | |
9639 | enum qca_iface_type iface_type; | |
9640 | struct nlattr *tb_vendor[QCA_WLAN_VENDOR_ATTR_MAX + 1]; | |
9641 | unsigned int num, max_num; | |
9642 | u32 *freqs; | |
9643 | ||
9644 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
9645 | genlmsg_attrlen(gnlh, 0), NULL); | |
9646 | ||
9647 | nl_vend = tb[NL80211_ATTR_VENDOR_DATA]; | |
9648 | if (!nl_vend) | |
9649 | return NL_SKIP; | |
9650 | ||
9651 | nla_parse(tb_vendor, QCA_WLAN_VENDOR_ATTR_MAX, | |
9652 | nla_data(nl_vend), nla_len(nl_vend), NULL); | |
9653 | ||
9654 | attr = tb_vendor[ | |
9655 | QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST_IFACE_TYPE]; | |
9656 | if (!attr) { | |
9657 | wpa_printf(MSG_ERROR, "nl80211: iface_type couldn't be found"); | |
9658 | param->num = 0; | |
9659 | return NL_SKIP; | |
9660 | } | |
9661 | ||
9662 | iface_type = (enum qca_iface_type) nla_get_u32(attr); | |
9663 | wpa_printf(MSG_DEBUG, "nl80211: Driver returned iface_type=%d", | |
9664 | iface_type); | |
9665 | ||
9666 | attr = tb_vendor[QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST]; | |
9667 | if (!attr) { | |
9668 | wpa_printf(MSG_ERROR, | |
9669 | "nl80211: preferred_freq_list couldn't be found"); | |
9670 | param->num = 0; | |
9671 | return NL_SKIP; | |
9672 | } | |
9673 | ||
9674 | /* | |
9675 | * param->num has the maximum number of entries for which there | |
9676 | * is room in the freq_list provided by the caller. | |
9677 | */ | |
9678 | freqs = nla_data(attr); | |
9679 | max_num = nla_len(attr) / sizeof(u32); | |
9680 | if (max_num > param->num) | |
9681 | max_num = param->num; | |
9682 | for (num = 0; num < max_num; num++) | |
9683 | param->freq_list[num] = freqs[num]; | |
9684 | param->num = num; | |
9685 | ||
9686 | return NL_SKIP; | |
9687 | } | |
9688 | ||
9689 | ||
9690 | static int nl80211_get_pref_freq_list(void *priv, | |
9691 | enum wpa_driver_if_type if_type, | |
9692 | unsigned int *num, | |
9693 | unsigned int *freq_list) | |
9694 | { | |
9695 | struct i802_bss *bss = priv; | |
9696 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
9697 | struct nl_msg *msg; | |
9698 | int ret; | |
9699 | unsigned int i; | |
9700 | struct nlattr *params; | |
9701 | struct nl80211_pcl param; | |
9702 | enum qca_iface_type iface_type; | |
9703 | ||
9704 | if (!drv->get_pref_freq_list) | |
9705 | return -1; | |
9706 | ||
9707 | switch (if_type) { | |
9708 | case WPA_IF_STATION: | |
9709 | iface_type = QCA_IFACE_TYPE_STA; | |
9710 | break; | |
9711 | case WPA_IF_AP_BSS: | |
9712 | iface_type = QCA_IFACE_TYPE_AP; | |
9713 | break; | |
9714 | case WPA_IF_P2P_GO: | |
9715 | iface_type = QCA_IFACE_TYPE_P2P_GO; | |
9716 | break; | |
9717 | case WPA_IF_P2P_CLIENT: | |
9718 | iface_type = QCA_IFACE_TYPE_P2P_CLIENT; | |
9719 | break; | |
9720 | case WPA_IF_IBSS: | |
9721 | iface_type = QCA_IFACE_TYPE_IBSS; | |
9722 | break; | |
9723 | case WPA_IF_TDLS: | |
9724 | iface_type = QCA_IFACE_TYPE_TDLS; | |
9725 | break; | |
9726 | default: | |
9727 | return -1; | |
9728 | } | |
9729 | ||
9730 | param.num = *num; | |
9731 | param.freq_list = freq_list; | |
9732 | ||
9733 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || | |
9734 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, drv->ifindex) || | |
9735 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || | |
9736 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | |
9737 | QCA_NL80211_VENDOR_SUBCMD_GET_PREFERRED_FREQ_LIST) || | |
9738 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || | |
9739 | nla_put_u32(msg, | |
9740 | QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST_IFACE_TYPE, | |
9741 | iface_type)) { | |
9742 | wpa_printf(MSG_ERROR, | |
9743 | "%s: err in adding vendor_cmd and vendor_data", | |
9744 | __func__); | |
9745 | nlmsg_free(msg); | |
9746 | return -1; | |
9747 | } | |
9748 | nla_nest_end(msg, params); | |
9749 | ||
9750 | os_memset(freq_list, 0, *num * sizeof(freq_list[0])); | |
9751 | ret = send_and_recv_msgs(drv, msg, preferred_freq_info_handler, ¶m); | |
9752 | if (ret) { | |
9753 | wpa_printf(MSG_ERROR, | |
9754 | "%s: err in send_and_recv_msgs", __func__); | |
9755 | return ret; | |
9756 | } | |
9757 | ||
9758 | *num = param.num; | |
9759 | ||
9760 | for (i = 0; i < *num; i++) { | |
9761 | wpa_printf(MSG_DEBUG, "nl80211: preferred_channel_list[%d]=%d", | |
9762 | i, freq_list[i]); | |
9763 | } | |
9764 | ||
9765 | return 0; | |
9766 | } | |
9767 | ||
9768 | ||
7c813acf AK |
9769 | static int nl80211_set_prob_oper_freq(void *priv, unsigned int freq) |
9770 | { | |
9771 | struct i802_bss *bss = priv; | |
9772 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
9773 | struct nl_msg *msg; | |
9774 | int ret; | |
9775 | struct nlattr *params; | |
9776 | ||
9777 | if (!drv->set_prob_oper_freq) | |
9778 | return -1; | |
9779 | ||
9780 | wpa_printf(MSG_DEBUG, | |
9781 | "nl80211: Set P2P probable operating freq %u for ifindex %d", | |
9782 | freq, bss->ifindex); | |
9783 | ||
9784 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || | |
9785 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || | |
9786 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | |
9787 | QCA_NL80211_VENDOR_SUBCMD_SET_PROBABLE_OPER_CHANNEL) || | |
9788 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || | |
9789 | nla_put_u32(msg, | |
9790 | QCA_WLAN_VENDOR_ATTR_PROBABLE_OPER_CHANNEL_IFACE_TYPE, | |
9791 | QCA_IFACE_TYPE_P2P_CLIENT) || | |
9792 | nla_put_u32(msg, | |
9793 | QCA_WLAN_VENDOR_ATTR_PROBABLE_OPER_CHANNEL_FREQ, | |
9794 | freq)) { | |
9795 | wpa_printf(MSG_ERROR, | |
9796 | "%s: err in adding vendor_cmd and vendor_data", | |
9797 | __func__); | |
9798 | nlmsg_free(msg); | |
9799 | return -1; | |
9800 | } | |
9801 | nla_nest_end(msg, params); | |
9802 | ||
9803 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
9804 | msg = NULL; | |
9805 | if (ret) { | |
9806 | wpa_printf(MSG_ERROR, "%s: err in send_and_recv_msgs", | |
9807 | __func__); | |
9808 | return ret; | |
9809 | } | |
9810 | nlmsg_free(msg); | |
9811 | return 0; | |
9812 | } | |
9813 | ||
a6f5b193 PX |
9814 | |
9815 | static int nl80211_p2p_lo_start(void *priv, unsigned int freq, | |
9816 | unsigned int period, unsigned int interval, | |
9817 | unsigned int count, const u8 *device_types, | |
9818 | size_t dev_types_len, | |
9819 | const u8 *ies, size_t ies_len) | |
9820 | { | |
9821 | struct i802_bss *bss = priv; | |
9822 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
9823 | struct nl_msg *msg; | |
9824 | struct nlattr *container; | |
9825 | int ret; | |
9826 | ||
9827 | wpa_printf(MSG_DEBUG, | |
9828 | "nl80211: Start P2P Listen offload: freq=%u, period=%u, interval=%u, count=%u", | |
9829 | freq, period, interval, count); | |
9830 | ||
9831 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_P2P_LISTEN_OFFLOAD)) | |
9832 | return -1; | |
9833 | ||
9834 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || | |
9835 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || | |
9836 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | |
9837 | QCA_NL80211_VENDOR_SUBCMD_P2P_LISTEN_OFFLOAD_START)) | |
9838 | goto fail; | |
9839 | ||
9840 | container = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); | |
9841 | if (!container) | |
9842 | goto fail; | |
9843 | ||
9844 | if (nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_CHANNEL, | |
9845 | freq) || | |
9846 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_PERIOD, | |
9847 | period) || | |
9848 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_INTERVAL, | |
9849 | interval) || | |
9850 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_COUNT, | |
9851 | count) || | |
9852 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_DEVICE_TYPES, | |
9853 | dev_types_len, device_types) || | |
9854 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_VENDOR_IE, | |
9855 | ies_len, ies)) | |
9856 | goto fail; | |
9857 | ||
9858 | nla_nest_end(msg, container); | |
9859 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
9860 | msg = NULL; | |
9861 | if (ret) { | |
9862 | wpa_printf(MSG_DEBUG, | |
9863 | "nl80211: Failed to send P2P Listen offload vendor command"); | |
9864 | goto fail; | |
9865 | } | |
9866 | ||
9867 | return 0; | |
9868 | ||
9869 | fail: | |
9870 | nlmsg_free(msg); | |
9871 | return -1; | |
9872 | } | |
9873 | ||
9874 | ||
9875 | static int nl80211_p2p_lo_stop(void *priv) | |
9876 | { | |
9877 | struct i802_bss *bss = priv; | |
9878 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
9879 | struct nl_msg *msg; | |
9880 | ||
9881 | wpa_printf(MSG_DEBUG, "nl80211: Stop P2P Listen offload"); | |
9882 | ||
9883 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_P2P_LISTEN_OFFLOAD)) | |
9884 | return -1; | |
9885 | ||
9886 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || | |
9887 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || | |
9888 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | |
9889 | QCA_NL80211_VENDOR_SUBCMD_P2P_LISTEN_OFFLOAD_STOP)) { | |
9890 | nlmsg_free(msg); | |
9891 | return -1; | |
9892 | } | |
9893 | ||
9894 | return send_and_recv_msgs(drv, msg, NULL, NULL); | |
9895 | } | |
9896 | ||
2e4e4fb7 SD |
9897 | |
9898 | static int nl80211_set_tdls_mode(void *priv, int tdls_external_control) | |
9899 | { | |
9900 | struct i802_bss *bss = priv; | |
9901 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
9902 | struct nl_msg *msg; | |
9903 | struct nlattr *params; | |
9904 | int ret; | |
9905 | u32 tdls_mode; | |
9906 | ||
9907 | wpa_printf(MSG_DEBUG, | |
9908 | "nl80211: Set TDKS mode: tdls_external_control=%d", | |
9909 | tdls_external_control); | |
9910 | ||
9911 | if (tdls_external_control == 1) | |
9912 | tdls_mode = QCA_WLAN_VENDOR_TDLS_TRIGGER_MODE_IMPLICIT | | |
9913 | QCA_WLAN_VENDOR_TDLS_TRIGGER_MODE_EXTERNAL; | |
9914 | else | |
9915 | tdls_mode = QCA_WLAN_VENDOR_TDLS_TRIGGER_MODE_EXPLICIT; | |
9916 | ||
9917 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || | |
9918 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || | |
9919 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | |
9920 | QCA_NL80211_VENDOR_SUBCMD_CONFIGURE_TDLS)) | |
9921 | goto fail; | |
9922 | ||
9923 | params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); | |
9924 | if (!params) | |
9925 | goto fail; | |
9926 | ||
9927 | if (nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TDLS_CONFIG_TRIGGER_MODE, | |
9928 | tdls_mode)) | |
9929 | goto fail; | |
9930 | ||
9931 | nla_nest_end(msg, params); | |
9932 | ||
9933 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
9934 | msg = NULL; | |
9935 | if (ret) { | |
9936 | wpa_printf(MSG_ERROR, | |
9937 | "nl80211: Set TDLS mode failed: ret=%d (%s)", | |
9938 | ret, strerror(-ret)); | |
9939 | goto fail; | |
9940 | } | |
9941 | return 0; | |
9942 | fail: | |
9943 | nlmsg_free(msg); | |
9944 | return -1; | |
9945 | } | |
9946 | ||
3ab48492 KV |
9947 | |
9948 | #ifdef CONFIG_MBO | |
9949 | ||
9950 | static enum mbo_transition_reject_reason | |
9951 | nl80211_mbo_reject_reason_mapping(enum qca_wlan_btm_candidate_status status) | |
9952 | { | |
9953 | switch (status) { | |
9954 | case QCA_STATUS_REJECT_EXCESSIVE_FRAME_LOSS_EXPECTED: | |
9955 | return MBO_TRANSITION_REJECT_REASON_FRAME_LOSS; | |
9956 | case QCA_STATUS_REJECT_EXCESSIVE_DELAY_EXPECTED: | |
9957 | return MBO_TRANSITION_REJECT_REASON_DELAY; | |
9958 | case QCA_STATUS_REJECT_INSUFFICIENT_QOS_CAPACITY: | |
9959 | return MBO_TRANSITION_REJECT_REASON_QOS_CAPACITY; | |
9960 | case QCA_STATUS_REJECT_LOW_RSSI: | |
9961 | return MBO_TRANSITION_REJECT_REASON_RSSI; | |
9962 | case QCA_STATUS_REJECT_HIGH_INTERFERENCE: | |
9963 | return MBO_TRANSITION_REJECT_REASON_INTERFERENCE; | |
9964 | case QCA_STATUS_REJECT_UNKNOWN: | |
9965 | default: | |
9966 | return MBO_TRANSITION_REJECT_REASON_UNSPECIFIED; | |
9967 | } | |
9968 | } | |
9969 | ||
9970 | ||
9971 | static void nl80211_parse_btm_candidate_info(struct candidate_list *candidate, | |
9972 | struct nlattr *tb[], int num) | |
9973 | { | |
9974 | enum qca_wlan_btm_candidate_status status; | |
9975 | char buf[50]; | |
9976 | ||
9977 | os_memcpy(candidate->bssid, | |
9978 | nla_data(tb[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_BSSID]), | |
9979 | ETH_ALEN); | |
9980 | ||
9981 | status = nla_get_u32( | |
9982 | tb[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_STATUS]); | |
9983 | candidate->is_accept = status == QCA_STATUS_ACCEPT; | |
9984 | candidate->reject_reason = nl80211_mbo_reject_reason_mapping(status); | |
9985 | ||
9986 | if (candidate->is_accept) | |
9987 | os_snprintf(buf, sizeof(buf), "Accepted"); | |
9988 | else | |
9989 | os_snprintf(buf, sizeof(buf), | |
9990 | "Rejected, Reject_reason: %d", | |
9991 | candidate->reject_reason); | |
9992 | wpa_printf(MSG_DEBUG, "nl80211: BSSID[%d]: " MACSTR " %s", | |
9993 | num, MAC2STR(candidate->bssid), buf); | |
9994 | } | |
9995 | ||
9996 | ||
9997 | static int | |
9998 | nl80211_get_bss_transition_status_handler(struct nl_msg *msg, void *arg) | |
9999 | { | |
10000 | struct wpa_bss_candidate_info *info = arg; | |
10001 | struct candidate_list *candidate = info->candidates; | |
10002 | struct nlattr *tb_msg[NL80211_ATTR_MAX + 1]; | |
10003 | struct nlattr *tb_vendor[QCA_WLAN_VENDOR_ATTR_MAX + 1]; | |
10004 | struct nlattr *tb[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_MAX + 1]; | |
10005 | static struct nla_policy policy[ | |
10006 | QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_MAX + 1] = { | |
10007 | [QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_BSSID] = { | |
10008 | .minlen = ETH_ALEN | |
10009 | }, | |
10010 | [QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_STATUS] = { | |
10011 | .type = NLA_U32, | |
10012 | }, | |
10013 | }; | |
10014 | struct nlattr *attr; | |
10015 | int rem; | |
10016 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
10017 | u8 num; | |
10018 | ||
10019 | num = info->num; /* number of candidates sent to driver */ | |
10020 | info->num = 0; | |
10021 | nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
10022 | genlmsg_attrlen(gnlh, 0), NULL); | |
10023 | ||
10024 | if (!tb_msg[NL80211_ATTR_VENDOR_DATA] || | |
10025 | nla_parse_nested(tb_vendor, QCA_WLAN_VENDOR_ATTR_MAX, | |
10026 | tb_msg[NL80211_ATTR_VENDOR_DATA], NULL) || | |
10027 | !tb_vendor[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO]) | |
10028 | return NL_SKIP; | |
10029 | ||
10030 | wpa_printf(MSG_DEBUG, | |
10031 | "nl80211: WNM Candidate list received from driver"); | |
10032 | nla_for_each_nested(attr, | |
10033 | tb_vendor[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO], | |
10034 | rem) { | |
10035 | if (info->num >= num || | |
10036 | nla_parse_nested( | |
10037 | tb, QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_MAX, | |
10038 | attr, policy) || | |
10039 | !tb[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_BSSID] || | |
10040 | !tb[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_STATUS]) | |
10041 | break; | |
10042 | ||
10043 | nl80211_parse_btm_candidate_info(candidate, tb, info->num); | |
10044 | ||
10045 | candidate++; | |
10046 | info->num++; | |
10047 | } | |
10048 | ||
10049 | return NL_SKIP; | |
10050 | } | |
10051 | ||
10052 | ||
10053 | static struct wpa_bss_candidate_info * | |
10054 | nl80211_get_bss_transition_status(void *priv, struct wpa_bss_trans_info *params) | |
10055 | { | |
10056 | struct i802_bss *bss = priv; | |
10057 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
10058 | struct nl_msg *msg; | |
10059 | struct nlattr *attr, *attr1, *attr2; | |
10060 | struct wpa_bss_candidate_info *info; | |
10061 | u8 i; | |
10062 | int ret; | |
10063 | u8 *pos; | |
10064 | ||
10065 | if (!drv->fetch_bss_trans_status) | |
10066 | return NULL; | |
10067 | ||
10068 | info = os_zalloc(sizeof(*info)); | |
10069 | if (!info) | |
10070 | return NULL; | |
10071 | /* Allocate memory for number of candidates sent to driver */ | |
10072 | info->candidates = os_calloc(params->n_candidates, | |
10073 | sizeof(*info->candidates)); | |
10074 | if (!info->candidates) { | |
10075 | os_free(info); | |
10076 | return NULL; | |
10077 | } | |
10078 | ||
10079 | /* Copy the number of candidates being sent to driver. This is used in | |
10080 | * nl80211_get_bss_transition_status_handler() to limit the number of | |
10081 | * candidates that can be populated in info->candidates and will be | |
10082 | * later overwritten with the actual number of candidates received from | |
10083 | * the driver. | |
10084 | */ | |
10085 | info->num = params->n_candidates; | |
10086 | ||
10087 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || | |
10088 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || | |
10089 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | |
10090 | QCA_NL80211_VENDOR_SUBCMD_FETCH_BSS_TRANSITION_STATUS)) | |
10091 | goto fail; | |
10092 | ||
10093 | attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); | |
10094 | if (!attr) | |
10095 | goto fail; | |
10096 | ||
10097 | if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_BTM_MBO_TRANSITION_REASON, | |
10098 | params->mbo_transition_reason)) | |
10099 | goto fail; | |
10100 | ||
10101 | attr1 = nla_nest_start(msg, QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO); | |
10102 | if (!attr1) | |
10103 | goto fail; | |
10104 | ||
10105 | wpa_printf(MSG_DEBUG, | |
10106 | "nl80211: WNM Candidate list info sending to driver: mbo_transition_reason: %d n_candidates: %d", | |
10107 | params->mbo_transition_reason, params->n_candidates); | |
10108 | pos = params->bssid; | |
10109 | for (i = 0; i < params->n_candidates; i++) { | |
10110 | wpa_printf(MSG_DEBUG, "nl80211: BSSID[%d]: " MACSTR, i, | |
10111 | MAC2STR(pos)); | |
10112 | attr2 = nla_nest_start(msg, i); | |
10113 | if (!attr2 || | |
10114 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_BSSID, | |
10115 | ETH_ALEN, pos)) | |
10116 | goto fail; | |
10117 | pos += ETH_ALEN; | |
10118 | nla_nest_end(msg, attr2); | |
10119 | } | |
10120 | ||
10121 | nla_nest_end(msg, attr1); | |
10122 | nla_nest_end(msg, attr); | |
10123 | ||
10124 | ret = send_and_recv_msgs(drv, msg, | |
10125 | nl80211_get_bss_transition_status_handler, | |
10126 | info); | |
10127 | msg = NULL; | |
10128 | if (ret) { | |
10129 | wpa_printf(MSG_ERROR, | |
10130 | "nl80211: WNM Get BSS transition status failed: ret=%d (%s)", | |
10131 | ret, strerror(-ret)); | |
10132 | goto fail; | |
10133 | } | |
10134 | return info; | |
10135 | ||
10136 | fail: | |
10137 | nlmsg_free(msg); | |
10138 | os_free(info->candidates); | |
10139 | os_free(info); | |
10140 | return NULL; | |
10141 | } | |
10142 | ||
178553b7 VK |
10143 | |
10144 | /** | |
10145 | * nl80211_ignore_assoc_disallow - Configure driver to ignore assoc_disallow | |
10146 | * @priv: Pointer to private driver data from wpa_driver_nl80211_init() | |
10147 | * @ignore_assoc_disallow: 0 to not ignore, 1 to ignore | |
10148 | * Returns: 0 on success, -1 on failure | |
10149 | */ | |
10150 | static int nl80211_ignore_assoc_disallow(void *priv, int ignore_disallow) | |
10151 | { | |
10152 | struct i802_bss *bss = priv; | |
10153 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
10154 | struct nl_msg *msg; | |
10155 | struct nlattr *attr; | |
10156 | int ret = -1; | |
10157 | ||
10158 | if (!drv->set_wifi_conf_vendor_cmd_avail) | |
10159 | return -1; | |
10160 | ||
10161 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || | |
10162 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || | |
10163 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | |
10164 | QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION)) | |
10165 | goto fail; | |
10166 | ||
10167 | attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); | |
10168 | if (!attr) | |
10169 | goto fail; | |
10170 | ||
10171 | wpa_printf(MSG_DEBUG, "nl80211: Set ignore_assoc_disallow %d", | |
10172 | ignore_disallow); | |
10173 | if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_IGNORE_ASSOC_DISALLOWED, | |
10174 | ignore_disallow)) | |
10175 | goto fail; | |
10176 | ||
10177 | nla_nest_end(msg, attr); | |
10178 | ||
10179 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
10180 | msg = NULL; | |
10181 | if (ret) { | |
10182 | wpa_printf(MSG_ERROR, | |
10183 | "nl80211: Set ignore_assoc_disallow failed: ret=%d (%s)", | |
10184 | ret, strerror(-ret)); | |
10185 | goto fail; | |
10186 | } | |
10187 | ||
10188 | fail: | |
10189 | nlmsg_free(msg); | |
10190 | return ret; | |
10191 | } | |
10192 | ||
3ab48492 KV |
10193 | #endif /* CONFIG_MBO */ |
10194 | ||
b658547d JM |
10195 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
10196 | ||
7c813acf | 10197 | |
6922d440 IP |
10198 | static int nl80211_write_to_file(const char *name, unsigned int val) |
10199 | { | |
10200 | int fd, len; | |
10201 | char tmp[128]; | |
10202 | ||
10203 | fd = open(name, O_RDWR); | |
10204 | if (fd < 0) { | |
10205 | wpa_printf(MSG_ERROR, "nl80211: Failed to open %s: %s", | |
10206 | name, strerror(errno)); | |
10207 | return fd; | |
10208 | } | |
10209 | ||
10210 | len = os_snprintf(tmp, sizeof(tmp), "%u\n", val); | |
10211 | len = write(fd, tmp, len); | |
10212 | if (len < 0) | |
10213 | wpa_printf(MSG_ERROR, "nl80211: Failed to write to %s: %s", | |
10214 | name, strerror(errno)); | |
10215 | close(fd); | |
10216 | ||
10217 | return 0; | |
10218 | } | |
10219 | ||
10220 | ||
10221 | static int nl80211_configure_data_frame_filters(void *priv, u32 filter_flags) | |
10222 | { | |
10223 | struct i802_bss *bss = priv; | |
10224 | char path[128]; | |
10225 | int ret; | |
10226 | ||
10227 | wpa_printf(MSG_DEBUG, "nl80211: Data frame filter flags=0x%x", | |
10228 | filter_flags); | |
10229 | ||
10230 | /* Configure filtering of unicast frame encrypted using GTK */ | |
10231 | ret = os_snprintf(path, sizeof(path), | |
10232 | "/proc/sys/net/ipv4/conf/%s/drop_unicast_in_l2_multicast", | |
10233 | bss->ifname); | |
bd86ea08 JM |
10234 | if (os_snprintf_error(sizeof(path), ret)) |
10235 | return -1; | |
6922d440 IP |
10236 | |
10237 | ret = nl80211_write_to_file(path, | |
10238 | !!(filter_flags & | |
10239 | WPA_DATA_FRAME_FILTER_FLAG_GTK)); | |
10240 | if (ret) { | |
10241 | wpa_printf(MSG_ERROR, | |
10242 | "nl80211: Failed to set IPv4 unicast in multicast filter"); | |
10243 | return ret; | |
10244 | } | |
10245 | ||
10246 | os_snprintf(path, sizeof(path), | |
10247 | "/proc/sys/net/ipv6/conf/%s/drop_unicast_in_l2_multicast", | |
10248 | bss->ifname); | |
10249 | ret = nl80211_write_to_file(path, | |
10250 | !!(filter_flags & | |
10251 | WPA_DATA_FRAME_FILTER_FLAG_GTK)); | |
10252 | ||
10253 | if (ret) { | |
10254 | wpa_printf(MSG_ERROR, | |
10255 | "nl80211: Failed to set IPv6 unicast in multicast filter"); | |
10256 | return ret; | |
10257 | } | |
10258 | ||
10259 | /* Configure filtering of unicast frame encrypted using GTK */ | |
10260 | os_snprintf(path, sizeof(path), | |
10261 | "/proc/sys/net/ipv4/conf/%s/drop_gratuitous_arp", | |
10262 | bss->ifname); | |
10263 | ret = nl80211_write_to_file(path, | |
10264 | !!(filter_flags & | |
10265 | WPA_DATA_FRAME_FILTER_FLAG_ARP)); | |
10266 | if (ret) { | |
10267 | wpa_printf(MSG_ERROR, | |
10268 | "nl80211: Failed set gratuitous ARP filter"); | |
10269 | return ret; | |
10270 | } | |
10271 | ||
10272 | /* Configure filtering of IPv6 NA frames */ | |
10273 | os_snprintf(path, sizeof(path), | |
10274 | "/proc/sys/net/ipv6/conf/%s/drop_unsolicited_na", | |
10275 | bss->ifname); | |
10276 | ret = nl80211_write_to_file(path, | |
10277 | !!(filter_flags & | |
10278 | WPA_DATA_FRAME_FILTER_FLAG_NA)); | |
10279 | if (ret) { | |
10280 | wpa_printf(MSG_ERROR, | |
10281 | "nl80211: Failed to set unsolicited NA filter"); | |
10282 | return ret; | |
10283 | } | |
10284 | ||
10285 | return 0; | |
10286 | } | |
10287 | ||
10288 | ||
cc9a2575 KV |
10289 | static int nl80211_get_ext_capab(void *priv, enum wpa_driver_if_type type, |
10290 | const u8 **ext_capa, const u8 **ext_capa_mask, | |
10291 | unsigned int *ext_capa_len) | |
10292 | { | |
10293 | struct i802_bss *bss = priv; | |
10294 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
10295 | enum nl80211_iftype nlmode; | |
10296 | unsigned int i; | |
10297 | ||
10298 | if (!ext_capa || !ext_capa_mask || !ext_capa_len) | |
10299 | return -1; | |
10300 | ||
10301 | nlmode = wpa_driver_nl80211_if_type(type); | |
10302 | ||
10303 | /* By default, use the per-radio values */ | |
10304 | *ext_capa = drv->extended_capa; | |
10305 | *ext_capa_mask = drv->extended_capa_mask; | |
10306 | *ext_capa_len = drv->extended_capa_len; | |
10307 | ||
10308 | /* Replace the default value if a per-interface type value exists */ | |
10309 | for (i = 0; i < drv->num_iface_ext_capa; i++) { | |
10310 | if (nlmode == drv->iface_ext_capa[i].iftype) { | |
10311 | *ext_capa = drv->iface_ext_capa[i].ext_capa; | |
10312 | *ext_capa_mask = drv->iface_ext_capa[i].ext_capa_mask; | |
10313 | *ext_capa_len = drv->iface_ext_capa[i].ext_capa_len; | |
10314 | break; | |
10315 | } | |
10316 | } | |
10317 | ||
10318 | return 0; | |
10319 | } | |
10320 | ||
10321 | ||
3c67e977 VK |
10322 | static int nl80211_update_connection_params( |
10323 | void *priv, struct wpa_driver_associate_params *params, | |
10324 | enum wpa_drv_update_connect_params_mask mask) | |
10325 | { | |
10326 | struct i802_bss *bss = priv; | |
10327 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
10328 | struct nl_msg *msg; | |
10329 | int ret = -1; | |
10330 | enum nl80211_auth_type type; | |
10331 | ||
10332 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_UPDATE_CONNECT_PARAMS); | |
10333 | if (!msg) | |
10334 | goto fail; | |
10335 | ||
10336 | wpa_printf(MSG_DEBUG, "nl80211: Update connection params (ifindex=%d)", | |
10337 | drv->ifindex); | |
10338 | ||
10339 | if ((mask & WPA_DRV_UPDATE_ASSOC_IES) && params->wpa_ie) { | |
10340 | if (nla_put(msg, NL80211_ATTR_IE, params->wpa_ie_len, | |
10341 | params->wpa_ie)) | |
10342 | goto fail; | |
10343 | wpa_hexdump(MSG_DEBUG, " * IEs", params->wpa_ie, | |
10344 | params->wpa_ie_len); | |
10345 | } | |
10346 | ||
10347 | if (mask & WPA_DRV_UPDATE_AUTH_TYPE) { | |
10348 | type = get_nl_auth_type(params->auth_alg); | |
10349 | if (type == NL80211_AUTHTYPE_MAX || | |
10350 | nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, type)) | |
10351 | goto fail; | |
10352 | wpa_printf(MSG_DEBUG, " * Auth Type %d", type); | |
10353 | } | |
10354 | ||
10355 | if ((mask & WPA_DRV_UPDATE_FILS_ERP_INFO) && | |
10356 | nl80211_put_fils_connect_params(drv, params, msg)) | |
10357 | goto fail; | |
10358 | ||
10359 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
10360 | msg = NULL; | |
10361 | if (ret) | |
10362 | wpa_dbg(drv->ctx, MSG_DEBUG, | |
10363 | "nl80211: Update connect params command failed: ret=%d (%s)", | |
10364 | ret, strerror(-ret)); | |
10365 | ||
10366 | fail: | |
10367 | nlmsg_free(msg); | |
10368 | return ret; | |
10369 | } | |
10370 | ||
10371 | ||
3f5285e8 JM |
10372 | const struct wpa_driver_ops wpa_driver_nl80211_ops = { |
10373 | .name = "nl80211", | |
10374 | .desc = "Linux nl80211/cfg80211", | |
10375 | .get_bssid = wpa_driver_nl80211_get_bssid, | |
10376 | .get_ssid = wpa_driver_nl80211_get_ssid, | |
9ebce9c5 JM |
10377 | .set_key = driver_nl80211_set_key, |
10378 | .scan2 = driver_nl80211_scan2, | |
d21c63b9 LC |
10379 | .sched_scan = wpa_driver_nl80211_sched_scan, |
10380 | .stop_sched_scan = wpa_driver_nl80211_stop_sched_scan, | |
3f5285e8 | 10381 | .get_scan_results2 = wpa_driver_nl80211_get_scan_results, |
4f30addb | 10382 | .abort_scan = wpa_driver_nl80211_abort_scan, |
9ebce9c5 JM |
10383 | .deauthenticate = driver_nl80211_deauthenticate, |
10384 | .authenticate = driver_nl80211_authenticate, | |
3f5285e8 | 10385 | .associate = wpa_driver_nl80211_associate, |
f2ed8023 JM |
10386 | .global_init = nl80211_global_init, |
10387 | .global_deinit = nl80211_global_deinit, | |
10388 | .init2 = wpa_driver_nl80211_init, | |
9ebce9c5 | 10389 | .deinit = driver_nl80211_deinit, |
3f5285e8 JM |
10390 | .get_capa = wpa_driver_nl80211_get_capa, |
10391 | .set_operstate = wpa_driver_nl80211_set_operstate, | |
01652550 | 10392 | .set_supp_port = wpa_driver_nl80211_set_supp_port, |
6d158490 | 10393 | .set_country = wpa_driver_nl80211_set_country, |
f0793bf1 | 10394 | .get_country = wpa_driver_nl80211_get_country, |
19c3b566 | 10395 | .set_ap = wpa_driver_nl80211_set_ap, |
3c4ca363 | 10396 | .set_acl = wpa_driver_nl80211_set_acl, |
22a7c9d7 | 10397 | .if_add = wpa_driver_nl80211_if_add, |
9ebce9c5 JM |
10398 | .if_remove = driver_nl80211_if_remove, |
10399 | .send_mlme = driver_nl80211_send_mlme, | |
0fafeb54 | 10400 | .get_hw_feature_data = nl80211_get_hw_feature_data, |
0f4e8b4f | 10401 | .sta_add = wpa_driver_nl80211_sta_add, |
9ebce9c5 | 10402 | .sta_remove = driver_nl80211_sta_remove, |
db149ac9 | 10403 | .hapd_send_eapol = wpa_driver_nl80211_hapd_send_eapol, |
a8d6ffa4 | 10404 | .sta_set_flags = wpa_driver_nl80211_sta_set_flags, |
c5121837 | 10405 | .hapd_init = i802_init, |
c5121837 | 10406 | .hapd_deinit = i802_deinit, |
f7b3920c | 10407 | .set_wds_sta = i802_set_wds_sta, |
c5121837 JM |
10408 | .get_seqnum = i802_get_seqnum, |
10409 | .flush = i802_flush, | |
c5121837 JM |
10410 | .get_inact_sec = i802_get_inact_sec, |
10411 | .sta_clear_stats = i802_sta_clear_stats, | |
c5121837 JM |
10412 | .set_rts = i802_set_rts, |
10413 | .set_frag = i802_set_frag, | |
c5121837 | 10414 | .set_tx_queue_params = i802_set_tx_queue_params, |
9ebce9c5 | 10415 | .set_sta_vlan = driver_nl80211_set_sta_vlan, |
ee7ab173 JB |
10416 | .sta_deauth = i802_sta_deauth, |
10417 | .sta_disassoc = i802_sta_disassoc, | |
9ebce9c5 | 10418 | .read_sta_data = driver_nl80211_read_sta_data, |
e3802622 | 10419 | .set_freq = i802_set_freq, |
9ebce9c5 | 10420 | .send_action = driver_nl80211_send_action, |
5dfca53f | 10421 | .send_action_cancel_wait = wpa_driver_nl80211_send_action_cancel_wait, |
55777702 JM |
10422 | .remain_on_channel = wpa_driver_nl80211_remain_on_channel, |
10423 | .cancel_remain_on_channel = | |
10424 | wpa_driver_nl80211_cancel_remain_on_channel, | |
9ebce9c5 | 10425 | .probe_req_report = driver_nl80211_probe_req_report, |
af473088 | 10426 | .deinit_ap = wpa_driver_nl80211_deinit_ap, |
3c29244e | 10427 | .deinit_p2p_cli = wpa_driver_nl80211_deinit_p2p_cli, |
207ef3fb | 10428 | .resume = wpa_driver_nl80211_resume, |
b625473c | 10429 | .signal_monitor = nl80211_signal_monitor, |
1c5c7273 | 10430 | .signal_poll = nl80211_signal_poll, |
b91ab76e | 10431 | .send_frame = nl80211_send_frame, |
c55f774d | 10432 | .set_param = nl80211_set_param, |
6859f1cb | 10433 | .get_radio_name = nl80211_get_radio_name, |
a6efc65d JM |
10434 | .add_pmkid = nl80211_add_pmkid, |
10435 | .remove_pmkid = nl80211_remove_pmkid, | |
10436 | .flush_pmkid = nl80211_flush_pmkid, | |
b14a210c | 10437 | .set_rekey_info = nl80211_set_rekey_info, |
bcf24348 | 10438 | .poll_client = nl80211_poll_client, |
29f338af | 10439 | .set_p2p_powersave = nl80211_set_p2p_powersave, |
f90e9c1c | 10440 | .start_dfs_cac = nl80211_start_radar_detection, |
695c7038 | 10441 | .stop_ap = wpa_driver_nl80211_stop_ap, |
03ea1786 AN |
10442 | #ifdef CONFIG_TDLS |
10443 | .send_tdls_mgmt = nl80211_send_tdls_mgmt, | |
10444 | .tdls_oper = nl80211_tdls_oper, | |
72b2605f AN |
10445 | .tdls_enable_channel_switch = nl80211_tdls_enable_channel_switch, |
10446 | .tdls_disable_channel_switch = nl80211_tdls_disable_channel_switch, | |
03ea1786 | 10447 | #endif /* CONFIG_TDLS */ |
6a1ce395 | 10448 | .update_ft_ies = wpa_driver_nl80211_update_ft_ies, |
597b94f5 | 10449 | .get_mac_addr = wpa_driver_nl80211_get_macaddr, |
0185007c | 10450 | .get_survey = wpa_driver_nl80211_get_survey, |
a771c07d | 10451 | .status = wpa_driver_nl80211_status, |
1c4ffa87 | 10452 | .switch_channel = nl80211_switch_channel, |
0de38036 JM |
10453 | #ifdef ANDROID_P2P |
10454 | .set_noa = wpa_driver_set_p2p_noa, | |
10455 | .get_noa = wpa_driver_get_p2p_noa, | |
10456 | .set_ap_wps_ie = wpa_driver_set_ap_wps_p2p_ie, | |
10457 | #endif /* ANDROID_P2P */ | |
5e2c3490 | 10458 | #ifdef ANDROID |
ded14ce9 | 10459 | #ifndef ANDROID_LIB_STUB |
5e2c3490 | 10460 | .driver_cmd = wpa_driver_nl80211_driver_cmd, |
ded14ce9 | 10461 | #endif /* !ANDROID_LIB_STUB */ |
5e2c3490 | 10462 | #endif /* ANDROID */ |
adef8948 | 10463 | .vendor_cmd = nl80211_vendor_cmd, |
049105b4 | 10464 | .set_qos_map = nl80211_set_qos_map, |
e4fa8b12 | 10465 | .set_wowlan = nl80211_set_wowlan, |
fee354c7 | 10466 | .set_mac_addr = nl80211_set_mac_addr, |
6c1664f6 BC |
10467 | #ifdef CONFIG_MESH |
10468 | .init_mesh = wpa_driver_nl80211_init_mesh, | |
10469 | .join_mesh = wpa_driver_nl80211_join_mesh, | |
10470 | .leave_mesh = wpa_driver_nl80211_leave_mesh, | |
10471 | #endif /* CONFIG_MESH */ | |
71103bed KP |
10472 | .br_add_ip_neigh = wpa_driver_br_add_ip_neigh, |
10473 | .br_delete_ip_neigh = wpa_driver_br_delete_ip_neigh, | |
73d2294f | 10474 | .br_port_set_attr = wpa_driver_br_port_set_attr, |
7565752d | 10475 | .br_set_net_param = wpa_driver_br_set_net_param, |
dfa87878 MB |
10476 | .add_tx_ts = nl80211_add_ts, |
10477 | .del_tx_ts = nl80211_del_ts, | |
45e3fc72 | 10478 | .get_ifindex = nl80211_get_ifindex, |
b658547d | 10479 | #ifdef CONFIG_DRIVER_NL80211_QCA |
9607a1ae | 10480 | .roaming = nl80211_roaming, |
d98038bb | 10481 | .disable_fils = nl80211_disable_fils, |
16689c7c | 10482 | .do_acs = wpa_driver_do_acs, |
844dfeb8 | 10483 | .set_band = nl80211_set_band, |
98342208 | 10484 | .get_pref_freq_list = nl80211_get_pref_freq_list, |
7c813acf | 10485 | .set_prob_oper_freq = nl80211_set_prob_oper_freq, |
a6f5b193 PX |
10486 | .p2p_lo_start = nl80211_p2p_lo_start, |
10487 | .p2p_lo_stop = nl80211_p2p_lo_stop, | |
cc9985d1 | 10488 | .set_default_scan_ies = nl80211_set_default_scan_ies, |
2e4e4fb7 | 10489 | .set_tdls_mode = nl80211_set_tdls_mode, |
3ab48492 KV |
10490 | #ifdef CONFIG_MBO |
10491 | .get_bss_transition_status = nl80211_get_bss_transition_status, | |
178553b7 | 10492 | .ignore_assoc_disallow = nl80211_ignore_assoc_disallow, |
3ab48492 | 10493 | #endif /* CONFIG_MBO */ |
b04854ce | 10494 | .set_bssid_blacklist = nl80211_set_bssid_blacklist, |
b658547d | 10495 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
6922d440 | 10496 | .configure_data_frame_filters = nl80211_configure_data_frame_filters, |
cc9a2575 | 10497 | .get_ext_capab = nl80211_get_ext_capab, |
3c67e977 | 10498 | .update_connect_params = nl80211_update_connection_params, |
3f5285e8 | 10499 | }; |