]>
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" |
f10bfc9a | 32 | #include "l2_packet/l2_packet.h" |
e2d02c29 | 33 | #include "netlink.h" |
1474e6e9 | 34 | #include "linux_defines.h" |
34f2f814 | 35 | #include "linux_ioctl.h" |
e2d02c29 JM |
36 | #include "radiotap.h" |
37 | #include "radiotap_iter.h" | |
8401a6b0 | 38 | #include "rfkill.h" |
1474e6e9 | 39 | #include "driver_nl80211.h" |
32ab4855 | 40 | |
1474e6e9 JM |
41 | |
42 | #ifndef CONFIG_LIBNL20 | |
a65a9aed JB |
43 | /* |
44 | * libnl 1.1 has a bug, it tries to allocate socket numbers densely | |
45 | * but when you free a socket again it will mess up its bitmap and | |
46 | * and use the wrong number the next time it needs a socket ID. | |
47 | * Therefore, we wrap the handle alloc/destroy and add our own pid | |
48 | * accounting. | |
49 | */ | |
50 | static uint32_t port_bitmap[32] = { 0 }; | |
51 | ||
52 | static struct nl_handle *nl80211_handle_alloc(void *cb) | |
53 | { | |
54 | struct nl_handle *handle; | |
55 | uint32_t pid = getpid() & 0x3FFFFF; | |
56 | int i; | |
57 | ||
58 | handle = nl_handle_alloc_cb(cb); | |
59 | ||
60 | for (i = 0; i < 1024; i++) { | |
61 | if (port_bitmap[i / 32] & (1 << (i % 32))) | |
62 | continue; | |
63 | port_bitmap[i / 32] |= 1 << (i % 32); | |
64 | pid += i << 22; | |
65 | break; | |
66 | } | |
67 | ||
68 | nl_socket_set_local_port(handle, pid); | |
69 | ||
70 | return handle; | |
71 | } | |
72 | ||
73 | static void nl80211_handle_destroy(struct nl_handle *handle) | |
74 | { | |
75 | uint32_t port = nl_socket_get_local_port(handle); | |
76 | ||
77 | port >>= 22; | |
78 | port_bitmap[port / 32] &= ~(1 << (port % 32)); | |
79 | ||
80 | nl_handle_destroy(handle); | |
81 | } | |
c5121837 JM |
82 | #endif /* CONFIG_LIBNL20 */ |
83 | ||
c5121837 | 84 | |
1c6edec6 JM |
85 | #ifdef ANDROID |
86 | /* system/core/libnl_2 does not include nl_socket_set_nonblocking() */ | |
1c6edec6 JM |
87 | #undef nl_socket_set_nonblocking |
88 | #define nl_socket_set_nonblocking(h) android_nl_socket_set_nonblocking(h) | |
70a96c81 | 89 | |
1c6edec6 JM |
90 | #endif /* ANDROID */ |
91 | ||
92 | ||
481234cf | 93 | static struct nl_handle * nl_create_handle(struct nl_cb *cb, const char *dbg) |
a92dfde8 | 94 | { |
481234cf | 95 | struct nl_handle *handle; |
a92dfde8 | 96 | |
481234cf JM |
97 | handle = nl80211_handle_alloc(cb); |
98 | if (handle == NULL) { | |
a92dfde8 JB |
99 | wpa_printf(MSG_ERROR, "nl80211: Failed to allocate netlink " |
100 | "callbacks (%s)", dbg); | |
481234cf | 101 | return NULL; |
a92dfde8 JB |
102 | } |
103 | ||
481234cf | 104 | if (genl_connect(handle)) { |
a92dfde8 JB |
105 | wpa_printf(MSG_ERROR, "nl80211: Failed to connect to generic " |
106 | "netlink (%s)", dbg); | |
481234cf JM |
107 | nl80211_handle_destroy(handle); |
108 | return NULL; | |
a92dfde8 JB |
109 | } |
110 | ||
481234cf | 111 | return handle; |
a92dfde8 JB |
112 | } |
113 | ||
114 | ||
481234cf | 115 | static void nl_destroy_handles(struct nl_handle **handle) |
a92dfde8 | 116 | { |
481234cf | 117 | if (*handle == NULL) |
a92dfde8 | 118 | return; |
481234cf JM |
119 | nl80211_handle_destroy(*handle); |
120 | *handle = NULL; | |
a92dfde8 JB |
121 | } |
122 | ||
123 | ||
10b85921 JB |
124 | #if __WORDSIZE == 64 |
125 | #define ELOOP_SOCKET_INVALID (intptr_t) 0x8888888888888889ULL | |
126 | #else | |
127 | #define ELOOP_SOCKET_INVALID (intptr_t) 0x88888889ULL | |
128 | #endif | |
129 | ||
5f65e9f7 JB |
130 | static void nl80211_register_eloop_read(struct nl_handle **handle, |
131 | eloop_sock_handler handler, | |
132 | void *eloop_data) | |
133 | { | |
fa38860c | 134 | #ifdef CONFIG_LIBNL20 |
630b3230 JM |
135 | /* |
136 | * libnl uses a pretty small buffer (32 kB that gets converted to 64 kB) | |
137 | * by default. It is possible to hit that limit in some cases where | |
138 | * operations are blocked, e.g., with a burst of Deauthentication frames | |
139 | * to hostapd and STA entry deletion. Try to increase the buffer to make | |
140 | * this less likely to occur. | |
141 | */ | |
142 | if (nl_socket_set_buffer_size(*handle, 262144, 0) < 0) { | |
143 | wpa_printf(MSG_DEBUG, | |
144 | "nl80211: Could not set nl_socket RX buffer size: %s", | |
145 | strerror(errno)); | |
146 | /* continue anyway with the default (smaller) buffer */ | |
147 | } | |
fa38860c | 148 | #endif /* CONFIG_LIBNL20 */ |
630b3230 | 149 | |
10b85921 | 150 | nl_socket_set_nonblocking(*handle); |
5f65e9f7 JB |
151 | eloop_register_read_sock(nl_socket_get_fd(*handle), handler, |
152 | eloop_data, *handle); | |
10b85921 | 153 | *handle = (void *) (((intptr_t) *handle) ^ ELOOP_SOCKET_INVALID); |
5f65e9f7 JB |
154 | } |
155 | ||
156 | ||
157 | static void nl80211_destroy_eloop_handle(struct nl_handle **handle) | |
158 | { | |
10b85921 | 159 | *handle = (void *) (((intptr_t) *handle) ^ ELOOP_SOCKET_INVALID); |
5f65e9f7 JB |
160 | eloop_unregister_read_sock(nl_socket_get_fd(*handle)); |
161 | nl_destroy_handles(handle); | |
162 | } | |
163 | ||
164 | ||
36d84860 | 165 | static void nl80211_global_deinit(void *priv); |
f51f54a0 | 166 | static void nl80211_check_global(struct nl80211_global *global); |
36d84860 | 167 | |
9ebce9c5 | 168 | static void wpa_driver_nl80211_deinit(struct i802_bss *bss); |
4ec68377 JD |
169 | static int wpa_driver_nl80211_set_mode_ibss(struct i802_bss *bss, |
170 | struct hostapd_freq_params *freq); | |
3c5d34e3 | 171 | |
362f781e | 172 | static int |
0d547d5f | 173 | wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data *drv, |
0ecff8d7 JM |
174 | const u8 *set_addr, int first, |
175 | const char *driver_params); | |
88df0ef7 | 176 | static int nl80211_send_frame_cmd(struct i802_bss *bss, |
5dfca53f | 177 | unsigned int freq, unsigned int wait, |
b106173a | 178 | const u8 *buf, size_t buf_len, u64 *cookie, |
2d3943ce AO |
179 | int no_cck, int no_ack, int offchanok, |
180 | const u16 *csa_offs, size_t csa_offs_len); | |
9ebce9c5 JM |
181 | static int wpa_driver_nl80211_probe_req_report(struct i802_bss *bss, |
182 | int report); | |
0915d02c | 183 | |
732b1d20 MB |
184 | #define IFIDX_ANY -1 |
185 | ||
186 | static void add_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, | |
187 | int ifidx_reason); | |
188 | static void del_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, | |
189 | int ifidx_reason); | |
190 | static int have_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, | |
191 | int ifidx_reason); | |
072ad14c | 192 | |
e87ef751 PX |
193 | static int nl80211_set_channel(struct i802_bss *bss, |
194 | struct hostapd_freq_params *freq, int set_chan); | |
4e5cb1a3 JM |
195 | static int nl80211_disable_11b_rates(struct wpa_driver_nl80211_data *drv, |
196 | int ifindex, int disabled); | |
504e905c | 197 | |
666e508c JM |
198 | static int nl80211_leave_ibss(struct wpa_driver_nl80211_data *drv, |
199 | int reset_mode); | |
21bdbe38 | 200 | |
bf83eab5 | 201 | static int i802_set_iface_flags(struct i802_bss *bss, int up); |
0ecff8d7 | 202 | static int nl80211_set_param(void *priv, const char *param); |
052b8d38 MH |
203 | #ifdef CONFIG_MESH |
204 | static int nl80211_put_mesh_config(struct nl_msg *msg, | |
205 | struct wpa_driver_mesh_bss_params *params); | |
206 | #endif /* CONFIG_MESH */ | |
05e5e615 DL |
207 | static int i802_sta_disassoc(void *priv, const u8 *own_addr, const u8 *addr, |
208 | int reason); | |
bf83eab5 | 209 | |
3f5285e8 | 210 | |
8d1fdde7 | 211 | /* Converts nl80211_chan_width to a common format */ |
f3407c66 | 212 | enum chan_width convert2width(int width) |
8d1fdde7 JD |
213 | { |
214 | switch (width) { | |
215 | case NL80211_CHAN_WIDTH_20_NOHT: | |
216 | return CHAN_WIDTH_20_NOHT; | |
217 | case NL80211_CHAN_WIDTH_20: | |
218 | return CHAN_WIDTH_20; | |
219 | case NL80211_CHAN_WIDTH_40: | |
220 | return CHAN_WIDTH_40; | |
221 | case NL80211_CHAN_WIDTH_80: | |
222 | return CHAN_WIDTH_80; | |
223 | case NL80211_CHAN_WIDTH_80P80: | |
224 | return CHAN_WIDTH_80P80; | |
225 | case NL80211_CHAN_WIDTH_160: | |
226 | return CHAN_WIDTH_160; | |
227 | } | |
228 | return CHAN_WIDTH_UNKNOWN; | |
229 | } | |
230 | ||
231 | ||
f3407c66 | 232 | int is_ap_interface(enum nl80211_iftype nlmode) |
b1f625e0 | 233 | { |
0e80ea2c JM |
234 | return nlmode == NL80211_IFTYPE_AP || |
235 | nlmode == NL80211_IFTYPE_P2P_GO; | |
b1f625e0 EP |
236 | } |
237 | ||
238 | ||
477af8f8 | 239 | int is_sta_interface(enum nl80211_iftype nlmode) |
b1f625e0 | 240 | { |
0e80ea2c JM |
241 | return nlmode == NL80211_IFTYPE_STATION || |
242 | nlmode == NL80211_IFTYPE_P2P_CLIENT; | |
b1f625e0 EP |
243 | } |
244 | ||
245 | ||
6a71413e | 246 | static int is_p2p_net_interface(enum nl80211_iftype nlmode) |
b3af99d2 | 247 | { |
0e80ea2c JM |
248 | return nlmode == NL80211_IFTYPE_P2P_CLIENT || |
249 | nlmode == NL80211_IFTYPE_P2P_GO; | |
b3af99d2 JM |
250 | } |
251 | ||
252 | ||
f3407c66 JM |
253 | struct i802_bss * get_bss_ifindex(struct wpa_driver_nl80211_data *drv, |
254 | int ifindex) | |
5dfbd725 JM |
255 | { |
256 | struct i802_bss *bss; | |
257 | ||
258 | for (bss = drv->first_bss; bss; bss = bss->next) { | |
259 | if (bss->ifindex == ifindex) | |
260 | return bss; | |
261 | } | |
262 | ||
263 | return NULL; | |
264 | } | |
265 | ||
266 | ||
afb0550a BC |
267 | static int is_mesh_interface(enum nl80211_iftype nlmode) |
268 | { | |
269 | return nlmode == NL80211_IFTYPE_MESH_POINT; | |
270 | } | |
271 | ||
272 | ||
f3407c66 | 273 | void nl80211_mark_disconnected(struct wpa_driver_nl80211_data *drv) |
add9b7a4 JM |
274 | { |
275 | if (drv->associated) | |
276 | os_memcpy(drv->prev_bssid, drv->bssid, ETH_ALEN); | |
277 | drv->associated = 0; | |
278 | os_memset(drv->bssid, 0, ETH_ALEN); | |
279 | } | |
280 | ||
281 | ||
6241fcb1 JM |
282 | /* nl80211 code */ |
283 | static int ack_handler(struct nl_msg *msg, void *arg) | |
284 | { | |
285 | int *err = arg; | |
286 | *err = 0; | |
287 | return NL_STOP; | |
288 | } | |
289 | ||
290 | static int finish_handler(struct nl_msg *msg, void *arg) | |
291 | { | |
8e8df255 JM |
292 | int *ret = arg; |
293 | *ret = 0; | |
6241fcb1 JM |
294 | return NL_SKIP; |
295 | } | |
296 | ||
297 | static int error_handler(struct sockaddr_nl *nla, struct nlmsgerr *err, | |
298 | void *arg) | |
299 | { | |
300 | int *ret = arg; | |
301 | *ret = err->error; | |
302 | return NL_SKIP; | |
303 | } | |
304 | ||
5b7b85f6 JM |
305 | |
306 | static int no_seq_check(struct nl_msg *msg, void *arg) | |
307 | { | |
308 | return NL_OK; | |
309 | } | |
310 | ||
311 | ||
bbd89bfc JM |
312 | static void nl80211_nlmsg_clear(struct nl_msg *msg) |
313 | { | |
314 | /* | |
315 | * Clear nlmsg data, e.g., to make sure key material is not left in | |
316 | * heap memory for unnecessarily long time. | |
317 | */ | |
318 | if (msg) { | |
319 | struct nlmsghdr *hdr = nlmsg_hdr(msg); | |
320 | void *data = nlmsg_data(hdr); | |
d58ade21 JM |
321 | /* |
322 | * This would use nlmsg_datalen() or the older nlmsg_len() if | |
323 | * only libnl were to maintain a stable API.. Neither will work | |
324 | * with all released versions, so just calculate the length | |
325 | * here. | |
326 | */ | |
327 | int len = hdr->nlmsg_len - NLMSG_HDRLEN; | |
bbd89bfc JM |
328 | |
329 | os_memset(data, 0, len); | |
330 | } | |
331 | } | |
332 | ||
333 | ||
d6c9aab8 | 334 | static int send_and_recv(struct nl80211_global *global, |
58f6fbe0 JM |
335 | struct nl_handle *nl_handle, struct nl_msg *msg, |
336 | int (*valid_handler)(struct nl_msg *, void *), | |
337 | void *valid_data) | |
6241fcb1 JM |
338 | { |
339 | struct nl_cb *cb; | |
340 | int err = -ENOMEM; | |
341 | ||
9725b784 JM |
342 | if (!msg) |
343 | return -ENOMEM; | |
344 | ||
d6c9aab8 | 345 | cb = nl_cb_clone(global->nl_cb); |
6241fcb1 JM |
346 | if (!cb) |
347 | goto out; | |
348 | ||
58f6fbe0 | 349 | err = nl_send_auto_complete(nl_handle, msg); |
6241fcb1 JM |
350 | if (err < 0) |
351 | goto out; | |
352 | ||
353 | err = 1; | |
354 | ||
355 | nl_cb_err(cb, NL_CB_CUSTOM, error_handler, &err); | |
8e8df255 | 356 | nl_cb_set(cb, NL_CB_FINISH, NL_CB_CUSTOM, finish_handler, &err); |
6241fcb1 JM |
357 | nl_cb_set(cb, NL_CB_ACK, NL_CB_CUSTOM, ack_handler, &err); |
358 | ||
359 | if (valid_handler) | |
360 | nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, | |
361 | valid_handler, valid_data); | |
362 | ||
34068ac3 JM |
363 | while (err > 0) { |
364 | int res = nl_recvmsgs(nl_handle, cb); | |
d3d04831 | 365 | if (res < 0) { |
34068ac3 JM |
366 | wpa_printf(MSG_INFO, |
367 | "nl80211: %s->nl_recvmsgs failed: %d", | |
368 | __func__, res); | |
369 | } | |
370 | } | |
6241fcb1 JM |
371 | out: |
372 | nl_cb_put(cb); | |
bbd89bfc JM |
373 | if (!valid_handler && valid_data == (void *) -1) |
374 | nl80211_nlmsg_clear(msg); | |
6241fcb1 JM |
375 | nlmsg_free(msg); |
376 | return err; | |
377 | } | |
378 | ||
379 | ||
f3407c66 JM |
380 | int send_and_recv_msgs(struct wpa_driver_nl80211_data *drv, |
381 | struct nl_msg *msg, | |
382 | int (*valid_handler)(struct nl_msg *, void *), | |
383 | void *valid_data) | |
58f6fbe0 | 384 | { |
481234cf | 385 | return send_and_recv(drv->global, drv->global->nl, msg, |
d6c9aab8 | 386 | valid_handler, valid_data); |
58f6fbe0 JM |
387 | } |
388 | ||
389 | ||
97865538 JM |
390 | struct family_data { |
391 | const char *group; | |
392 | int id; | |
393 | }; | |
394 | ||
395 | ||
396 | static int family_handler(struct nl_msg *msg, void *arg) | |
397 | { | |
398 | struct family_data *res = arg; | |
399 | struct nlattr *tb[CTRL_ATTR_MAX + 1]; | |
400 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
401 | struct nlattr *mcgrp; | |
402 | int i; | |
403 | ||
404 | nla_parse(tb, CTRL_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
405 | genlmsg_attrlen(gnlh, 0), NULL); | |
406 | if (!tb[CTRL_ATTR_MCAST_GROUPS]) | |
407 | return NL_SKIP; | |
408 | ||
409 | nla_for_each_nested(mcgrp, tb[CTRL_ATTR_MCAST_GROUPS], i) { | |
410 | struct nlattr *tb2[CTRL_ATTR_MCAST_GRP_MAX + 1]; | |
411 | nla_parse(tb2, CTRL_ATTR_MCAST_GRP_MAX, nla_data(mcgrp), | |
412 | nla_len(mcgrp), NULL); | |
413 | if (!tb2[CTRL_ATTR_MCAST_GRP_NAME] || | |
414 | !tb2[CTRL_ATTR_MCAST_GRP_ID] || | |
415 | os_strncmp(nla_data(tb2[CTRL_ATTR_MCAST_GRP_NAME]), | |
416 | res->group, | |
417 | nla_len(tb2[CTRL_ATTR_MCAST_GRP_NAME])) != 0) | |
418 | continue; | |
419 | res->id = nla_get_u32(tb2[CTRL_ATTR_MCAST_GRP_ID]); | |
420 | break; | |
421 | }; | |
422 | ||
423 | return NL_SKIP; | |
424 | } | |
425 | ||
426 | ||
d6c9aab8 | 427 | static int nl_get_multicast_id(struct nl80211_global *global, |
97865538 JM |
428 | const char *family, const char *group) |
429 | { | |
430 | struct nl_msg *msg; | |
a862e4a3 | 431 | int ret; |
97865538 JM |
432 | struct family_data res = { group, -ENOENT }; |
433 | ||
434 | msg = nlmsg_alloc(); | |
435 | if (!msg) | |
436 | return -ENOMEM; | |
a862e4a3 JM |
437 | if (!genlmsg_put(msg, 0, 0, genl_ctrl_resolve(global->nl, "nlctrl"), |
438 | 0, 0, CTRL_CMD_GETFAMILY, 0) || | |
439 | nla_put_string(msg, CTRL_ATTR_FAMILY_NAME, family)) { | |
440 | nlmsg_free(msg); | |
441 | return -1; | |
442 | } | |
97865538 | 443 | |
1033315f | 444 | ret = send_and_recv(global, global->nl, msg, family_handler, &res); |
97865538 JM |
445 | if (ret == 0) |
446 | ret = res.id; | |
97865538 JM |
447 | return ret; |
448 | } | |
449 | ||
450 | ||
f3407c66 JM |
451 | void * nl80211_cmd(struct wpa_driver_nl80211_data *drv, |
452 | struct nl_msg *msg, int flags, uint8_t cmd) | |
9fb04070 | 453 | { |
a5a187b0 JM |
454 | if (TEST_FAIL()) |
455 | return NULL; | |
335d42b1 | 456 | return genlmsg_put(msg, 0, 0, drv->global->nl80211_id, |
276e2d67 | 457 | 0, flags, cmd, 0); |
9fb04070 JM |
458 | } |
459 | ||
460 | ||
350acc35 JM |
461 | static int nl80211_set_iface_id(struct nl_msg *msg, struct i802_bss *bss) |
462 | { | |
463 | if (bss->wdev_id_set) | |
464 | return nla_put_u64(msg, NL80211_ATTR_WDEV, bss->wdev_id); | |
465 | return nla_put_u32(msg, NL80211_ATTR_IFINDEX, bss->ifindex); | |
466 | } | |
467 | ||
468 | ||
07c7757c JM |
469 | struct nl_msg * nl80211_cmd_msg(struct i802_bss *bss, int flags, uint8_t cmd) |
470 | { | |
471 | struct nl_msg *msg; | |
472 | ||
473 | msg = nlmsg_alloc(); | |
474 | if (!msg) | |
475 | return NULL; | |
476 | ||
477 | if (!nl80211_cmd(bss->drv, msg, flags, cmd) || | |
478 | nl80211_set_iface_id(msg, bss) < 0) { | |
479 | nlmsg_free(msg); | |
480 | return NULL; | |
481 | } | |
482 | ||
483 | return msg; | |
484 | } | |
485 | ||
486 | ||
487 | static struct nl_msg * | |
488 | nl80211_ifindex_msg(struct wpa_driver_nl80211_data *drv, int ifindex, | |
489 | int flags, uint8_t cmd) | |
490 | { | |
491 | struct nl_msg *msg; | |
492 | ||
493 | msg = nlmsg_alloc(); | |
494 | if (!msg) | |
495 | return NULL; | |
496 | ||
497 | if (!nl80211_cmd(drv, msg, flags, cmd) || | |
498 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex)) { | |
499 | nlmsg_free(msg); | |
500 | return NULL; | |
501 | } | |
502 | ||
503 | return msg; | |
504 | } | |
505 | ||
506 | ||
507 | struct nl_msg * nl80211_drv_msg(struct wpa_driver_nl80211_data *drv, int flags, | |
508 | uint8_t cmd) | |
509 | { | |
510 | return nl80211_ifindex_msg(drv, drv->ifindex, flags, cmd); | |
511 | } | |
512 | ||
513 | ||
514 | struct nl_msg * nl80211_bss_msg(struct i802_bss *bss, int flags, uint8_t cmd) | |
515 | { | |
516 | return nl80211_ifindex_msg(bss->drv, bss->ifindex, flags, cmd); | |
517 | } | |
518 | ||
519 | ||
e32ad281 JB |
520 | struct wiphy_idx_data { |
521 | int wiphy_idx; | |
01517c8b | 522 | enum nl80211_iftype nlmode; |
597b94f5 | 523 | u8 *macaddr; |
e32ad281 JB |
524 | }; |
525 | ||
526 | ||
527 | static int netdev_info_handler(struct nl_msg *msg, void *arg) | |
528 | { | |
529 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
530 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
531 | struct wiphy_idx_data *info = arg; | |
532 | ||
533 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
534 | genlmsg_attrlen(gnlh, 0), NULL); | |
535 | ||
536 | if (tb[NL80211_ATTR_WIPHY]) | |
537 | info->wiphy_idx = nla_get_u32(tb[NL80211_ATTR_WIPHY]); | |
538 | ||
01517c8b JB |
539 | if (tb[NL80211_ATTR_IFTYPE]) |
540 | info->nlmode = nla_get_u32(tb[NL80211_ATTR_IFTYPE]); | |
541 | ||
597b94f5 AS |
542 | if (tb[NL80211_ATTR_MAC] && info->macaddr) |
543 | os_memcpy(info->macaddr, nla_data(tb[NL80211_ATTR_MAC]), | |
544 | ETH_ALEN); | |
545 | ||
e32ad281 JB |
546 | return NL_SKIP; |
547 | } | |
548 | ||
549 | ||
f3407c66 | 550 | int nl80211_get_wiphy_index(struct i802_bss *bss) |
e32ad281 JB |
551 | { |
552 | struct nl_msg *msg; | |
553 | struct wiphy_idx_data data = { | |
554 | .wiphy_idx = -1, | |
597b94f5 | 555 | .macaddr = NULL, |
e32ad281 JB |
556 | }; |
557 | ||
56f77852 | 558 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_GET_INTERFACE))) |
a862e4a3 | 559 | return -1; |
e32ad281 JB |
560 | |
561 | if (send_and_recv_msgs(bss->drv, msg, netdev_info_handler, &data) == 0) | |
562 | return data.wiphy_idx; | |
e32ad281 JB |
563 | return -1; |
564 | } | |
565 | ||
566 | ||
01517c8b JB |
567 | static enum nl80211_iftype nl80211_get_ifmode(struct i802_bss *bss) |
568 | { | |
569 | struct nl_msg *msg; | |
570 | struct wiphy_idx_data data = { | |
597b94f5 AS |
571 | .nlmode = NL80211_IFTYPE_UNSPECIFIED, |
572 | .macaddr = NULL, | |
01517c8b JB |
573 | }; |
574 | ||
56f77852 | 575 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_GET_INTERFACE))) |
a862e4a3 | 576 | return NL80211_IFTYPE_UNSPECIFIED; |
01517c8b JB |
577 | |
578 | if (send_and_recv_msgs(bss->drv, msg, netdev_info_handler, &data) == 0) | |
579 | return data.nlmode; | |
01517c8b JB |
580 | return NL80211_IFTYPE_UNSPECIFIED; |
581 | } | |
01517c8b JB |
582 | |
583 | ||
597b94f5 AS |
584 | static int nl80211_get_macaddr(struct i802_bss *bss) |
585 | { | |
586 | struct nl_msg *msg; | |
587 | struct wiphy_idx_data data = { | |
588 | .macaddr = bss->addr, | |
589 | }; | |
590 | ||
56f77852 | 591 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_GET_INTERFACE))) |
a862e4a3 | 592 | return -1; |
597b94f5 | 593 | |
597b94f5 | 594 | return send_and_recv_msgs(bss->drv, msg, netdev_info_handler, &data); |
597b94f5 | 595 | } |
597b94f5 AS |
596 | |
597 | ||
e32ad281 JB |
598 | static int nl80211_register_beacons(struct wpa_driver_nl80211_data *drv, |
599 | struct nl80211_wiphy_data *w) | |
600 | { | |
601 | struct nl_msg *msg; | |
a862e4a3 | 602 | int ret; |
e32ad281 JB |
603 | |
604 | msg = nlmsg_alloc(); | |
605 | if (!msg) | |
606 | return -1; | |
607 | ||
a862e4a3 JM |
608 | if (!nl80211_cmd(drv, msg, 0, NL80211_CMD_REGISTER_BEACONS) || |
609 | nla_put_u32(msg, NL80211_ATTR_WIPHY, w->wiphy_idx)) { | |
610 | nlmsg_free(msg); | |
611 | return -1; | |
612 | } | |
e32ad281 | 613 | |
481234cf | 614 | ret = send_and_recv(drv->global, w->nl_beacons, msg, NULL, NULL); |
e32ad281 JB |
615 | if (ret) { |
616 | wpa_printf(MSG_DEBUG, "nl80211: Register beacons command " | |
617 | "failed: ret=%d (%s)", | |
618 | ret, strerror(-ret)); | |
e32ad281 | 619 | } |
e32ad281 JB |
620 | return ret; |
621 | } | |
622 | ||
623 | ||
624 | static void nl80211_recv_beacons(int sock, void *eloop_ctx, void *handle) | |
625 | { | |
626 | struct nl80211_wiphy_data *w = eloop_ctx; | |
34068ac3 | 627 | int res; |
e32ad281 | 628 | |
ee9fc67a | 629 | wpa_printf(MSG_EXCESSIVE, "nl80211: Beacon event message available"); |
e32ad281 | 630 | |
34068ac3 | 631 | res = nl_recvmsgs(handle, w->nl_cb); |
d3d04831 | 632 | if (res < 0) { |
34068ac3 JM |
633 | wpa_printf(MSG_INFO, "nl80211: %s->nl_recvmsgs failed: %d", |
634 | __func__, res); | |
635 | } | |
e32ad281 JB |
636 | } |
637 | ||
638 | ||
639 | static int process_beacon_event(struct nl_msg *msg, void *arg) | |
640 | { | |
641 | struct nl80211_wiphy_data *w = arg; | |
642 | struct wpa_driver_nl80211_data *drv; | |
643 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
644 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
645 | union wpa_event_data event; | |
646 | ||
647 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
648 | genlmsg_attrlen(gnlh, 0), NULL); | |
649 | ||
650 | if (gnlh->cmd != NL80211_CMD_FRAME) { | |
651 | wpa_printf(MSG_DEBUG, "nl80211: Unexpected beacon event? (%d)", | |
652 | gnlh->cmd); | |
653 | return NL_SKIP; | |
654 | } | |
655 | ||
656 | if (!tb[NL80211_ATTR_FRAME]) | |
657 | return NL_SKIP; | |
658 | ||
659 | dl_list_for_each(drv, &w->drvs, struct wpa_driver_nl80211_data, | |
660 | wiphy_list) { | |
661 | os_memset(&event, 0, sizeof(event)); | |
662 | event.rx_mgmt.frame = nla_data(tb[NL80211_ATTR_FRAME]); | |
663 | event.rx_mgmt.frame_len = nla_len(tb[NL80211_ATTR_FRAME]); | |
664 | wpa_supplicant_event(drv->ctx, EVENT_RX_MGMT, &event); | |
665 | } | |
666 | ||
667 | return NL_SKIP; | |
668 | } | |
669 | ||
670 | ||
671 | static struct nl80211_wiphy_data * | |
672 | nl80211_get_wiphy_data_ap(struct i802_bss *bss) | |
673 | { | |
674 | static DEFINE_DL_LIST(nl80211_wiphys); | |
675 | struct nl80211_wiphy_data *w; | |
676 | int wiphy_idx, found = 0; | |
677 | struct i802_bss *tmp_bss; | |
678 | ||
679 | if (bss->wiphy_data != NULL) | |
680 | return bss->wiphy_data; | |
681 | ||
682 | wiphy_idx = nl80211_get_wiphy_index(bss); | |
683 | ||
684 | dl_list_for_each(w, &nl80211_wiphys, struct nl80211_wiphy_data, list) { | |
685 | if (w->wiphy_idx == wiphy_idx) | |
686 | goto add; | |
687 | } | |
688 | ||
689 | /* alloc new one */ | |
690 | w = os_zalloc(sizeof(*w)); | |
691 | if (w == NULL) | |
692 | return NULL; | |
693 | w->wiphy_idx = wiphy_idx; | |
694 | dl_list_init(&w->bsss); | |
695 | dl_list_init(&w->drvs); | |
696 | ||
697 | w->nl_cb = nl_cb_alloc(NL_CB_DEFAULT); | |
698 | if (!w->nl_cb) { | |
699 | os_free(w); | |
700 | return NULL; | |
701 | } | |
702 | nl_cb_set(w->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, no_seq_check, NULL); | |
703 | nl_cb_set(w->nl_cb, NL_CB_VALID, NL_CB_CUSTOM, process_beacon_event, | |
704 | w); | |
705 | ||
481234cf JM |
706 | w->nl_beacons = nl_create_handle(bss->drv->global->nl_cb, |
707 | "wiphy beacons"); | |
708 | if (w->nl_beacons == NULL) { | |
e32ad281 JB |
709 | os_free(w); |
710 | return NULL; | |
711 | } | |
712 | ||
713 | if (nl80211_register_beacons(bss->drv, w)) { | |
714 | nl_destroy_handles(&w->nl_beacons); | |
715 | os_free(w); | |
716 | return NULL; | |
717 | } | |
718 | ||
5f65e9f7 | 719 | nl80211_register_eloop_read(&w->nl_beacons, nl80211_recv_beacons, w); |
e32ad281 JB |
720 | |
721 | dl_list_add(&nl80211_wiphys, &w->list); | |
722 | ||
723 | add: | |
724 | /* drv entry for this bss already there? */ | |
725 | dl_list_for_each(tmp_bss, &w->bsss, struct i802_bss, wiphy_list) { | |
726 | if (tmp_bss->drv == bss->drv) { | |
727 | found = 1; | |
728 | break; | |
729 | } | |
730 | } | |
731 | /* if not add it */ | |
732 | if (!found) | |
733 | dl_list_add(&w->drvs, &bss->drv->wiphy_list); | |
734 | ||
735 | dl_list_add(&w->bsss, &bss->wiphy_list); | |
736 | bss->wiphy_data = w; | |
737 | return w; | |
738 | } | |
739 | ||
740 | ||
741 | static void nl80211_put_wiphy_data_ap(struct i802_bss *bss) | |
742 | { | |
743 | struct nl80211_wiphy_data *w = bss->wiphy_data; | |
744 | struct i802_bss *tmp_bss; | |
745 | int found = 0; | |
746 | ||
747 | if (w == NULL) | |
748 | return; | |
749 | bss->wiphy_data = NULL; | |
750 | dl_list_del(&bss->wiphy_list); | |
751 | ||
752 | /* still any for this drv present? */ | |
753 | dl_list_for_each(tmp_bss, &w->bsss, struct i802_bss, wiphy_list) { | |
754 | if (tmp_bss->drv == bss->drv) { | |
755 | found = 1; | |
756 | break; | |
757 | } | |
758 | } | |
759 | /* if not remove it */ | |
760 | if (!found) | |
761 | dl_list_del(&bss->drv->wiphy_list); | |
762 | ||
763 | if (!dl_list_empty(&w->bsss)) | |
764 | return; | |
765 | ||
5f65e9f7 | 766 | nl80211_destroy_eloop_handle(&w->nl_beacons); |
e32ad281 JB |
767 | |
768 | nl_cb_put(w->nl_cb); | |
e32ad281 JB |
769 | dl_list_del(&w->list); |
770 | os_free(w); | |
771 | } | |
772 | ||
773 | ||
45e3fc72 RM |
774 | static unsigned int nl80211_get_ifindex(void *priv) |
775 | { | |
776 | struct i802_bss *bss = priv; | |
777 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
778 | ||
779 | return drv->ifindex; | |
780 | } | |
781 | ||
782 | ||
3f5285e8 JM |
783 | static int wpa_driver_nl80211_get_bssid(void *priv, u8 *bssid) |
784 | { | |
a2e40bb6 FF |
785 | struct i802_bss *bss = priv; |
786 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
c2a04078 JM |
787 | if (!drv->associated) |
788 | return -1; | |
789 | os_memcpy(bssid, drv->bssid, ETH_ALEN); | |
790 | return 0; | |
3f5285e8 JM |
791 | } |
792 | ||
793 | ||
3f5285e8 JM |
794 | static int wpa_driver_nl80211_get_ssid(void *priv, u8 *ssid) |
795 | { | |
a2e40bb6 FF |
796 | struct i802_bss *bss = priv; |
797 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
fd05d64e JM |
798 | if (!drv->associated) |
799 | return -1; | |
800 | os_memcpy(ssid, drv->ssid, drv->ssid_len); | |
801 | return drv->ssid_len; | |
3f5285e8 JM |
802 | } |
803 | ||
804 | ||
90a545cc | 805 | static void wpa_driver_nl80211_event_newlink( |
45e3fc72 RM |
806 | struct nl80211_global *global, struct wpa_driver_nl80211_data *drv, |
807 | int ifindex, const char *ifname) | |
3f5285e8 JM |
808 | { |
809 | union wpa_event_data event; | |
810 | ||
45e3fc72 | 811 | if (drv && os_strcmp(drv->first_bss->ifname, ifname) == 0) { |
90a545cc JM |
812 | if (if_nametoindex(drv->first_bss->ifname) == 0) { |
813 | wpa_printf(MSG_DEBUG, "nl80211: Interface %s does not exist - ignore RTM_NEWLINK", | |
814 | drv->first_bss->ifname); | |
815 | return; | |
816 | } | |
817 | if (!drv->if_removed) | |
818 | return; | |
819 | wpa_printf(MSG_DEBUG, "nl80211: Mark if_removed=0 for %s based on RTM_NEWLINK event", | |
820 | drv->first_bss->ifname); | |
821 | drv->if_removed = 0; | |
822 | } | |
823 | ||
3f5285e8 | 824 | os_memset(&event, 0, sizeof(event)); |
45e3fc72 | 825 | event.interface_status.ifindex = ifindex; |
90a545cc JM |
826 | os_strlcpy(event.interface_status.ifname, ifname, |
827 | sizeof(event.interface_status.ifname)); | |
828 | event.interface_status.ievent = EVENT_INTERFACE_ADDED; | |
45e3fc72 RM |
829 | if (drv) |
830 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_STATUS, &event); | |
831 | else | |
832 | wpa_supplicant_event_global(global->ctx, EVENT_INTERFACE_STATUS, | |
833 | &event); | |
90a545cc JM |
834 | } |
835 | ||
836 | ||
837 | static void wpa_driver_nl80211_event_dellink( | |
45e3fc72 RM |
838 | struct nl80211_global *global, struct wpa_driver_nl80211_data *drv, |
839 | int ifindex, const char *ifname) | |
90a545cc JM |
840 | { |
841 | union wpa_event_data event; | |
842 | ||
45e3fc72 | 843 | if (drv && os_strcmp(drv->first_bss->ifname, ifname) == 0) { |
90a545cc JM |
844 | if (drv->if_removed) { |
845 | wpa_printf(MSG_DEBUG, "nl80211: if_removed already set - ignore RTM_DELLINK event for %s", | |
846 | ifname); | |
847 | return; | |
d1f4942b | 848 | } |
90a545cc JM |
849 | wpa_printf(MSG_DEBUG, "RTM_DELLINK: Interface '%s' removed - mark if_removed=1", |
850 | ifname); | |
851 | drv->if_removed = 1; | |
852 | } else { | |
853 | wpa_printf(MSG_DEBUG, "RTM_DELLINK: Interface '%s' removed", | |
854 | ifname); | |
7524cfb1 JM |
855 | } |
856 | ||
90a545cc | 857 | os_memset(&event, 0, sizeof(event)); |
45e3fc72 | 858 | event.interface_status.ifindex = ifindex; |
90a545cc JM |
859 | os_strlcpy(event.interface_status.ifname, ifname, |
860 | sizeof(event.interface_status.ifname)); | |
861 | event.interface_status.ievent = EVENT_INTERFACE_REMOVED; | |
45e3fc72 RM |
862 | if (drv) |
863 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_STATUS, &event); | |
864 | else | |
865 | wpa_supplicant_event_global(global->ctx, EVENT_INTERFACE_STATUS, | |
866 | &event); | |
3f5285e8 JM |
867 | } |
868 | ||
869 | ||
7524cfb1 | 870 | static int wpa_driver_nl80211_own_ifname(struct wpa_driver_nl80211_data *drv, |
62d680c3 | 871 | u8 *buf, size_t len) |
7524cfb1 | 872 | { |
62d680c3 | 873 | int attrlen, rta_len; |
7524cfb1 JM |
874 | struct rtattr *attr; |
875 | ||
62d680c3 JM |
876 | attrlen = len; |
877 | attr = (struct rtattr *) buf; | |
7524cfb1 JM |
878 | |
879 | rta_len = RTA_ALIGN(sizeof(struct rtattr)); | |
880 | while (RTA_OK(attr, attrlen)) { | |
881 | if (attr->rta_type == IFLA_IFNAME) { | |
834ee56f KP |
882 | if (os_strcmp(((char *) attr) + rta_len, |
883 | drv->first_bss->ifname) == 0) | |
7524cfb1 JM |
884 | return 1; |
885 | else | |
886 | break; | |
887 | } | |
888 | attr = RTA_NEXT(attr, attrlen); | |
889 | } | |
890 | ||
891 | return 0; | |
892 | } | |
893 | ||
894 | ||
895 | static int wpa_driver_nl80211_own_ifindex(struct wpa_driver_nl80211_data *drv, | |
62d680c3 | 896 | int ifindex, u8 *buf, size_t len) |
7524cfb1 JM |
897 | { |
898 | if (drv->ifindex == ifindex) | |
899 | return 1; | |
900 | ||
62d680c3 | 901 | if (drv->if_removed && wpa_driver_nl80211_own_ifname(drv, buf, len)) { |
f51f54a0 | 902 | nl80211_check_global(drv->global); |
7524cfb1 JM |
903 | wpa_printf(MSG_DEBUG, "nl80211: Update ifindex for a removed " |
904 | "interface"); | |
0ecff8d7 | 905 | wpa_driver_nl80211_finish_drv_init(drv, NULL, 0, NULL); |
7524cfb1 JM |
906 | return 1; |
907 | } | |
908 | ||
909 | return 0; | |
910 | } | |
911 | ||
912 | ||
36d84860 BG |
913 | static struct wpa_driver_nl80211_data * |
914 | nl80211_find_drv(struct nl80211_global *global, int idx, u8 *buf, size_t len) | |
915 | { | |
916 | struct wpa_driver_nl80211_data *drv; | |
917 | dl_list_for_each(drv, &global->interfaces, | |
918 | struct wpa_driver_nl80211_data, list) { | |
919 | if (wpa_driver_nl80211_own_ifindex(drv, idx, buf, len) || | |
732b1d20 | 920 | have_ifidx(drv, idx, IFIDX_ANY)) |
36d84860 BG |
921 | return drv; |
922 | } | |
923 | return NULL; | |
924 | } | |
925 | ||
926 | ||
62d680c3 JM |
927 | static void wpa_driver_nl80211_event_rtm_newlink(void *ctx, |
928 | struct ifinfomsg *ifi, | |
929 | u8 *buf, size_t len) | |
3f5285e8 | 930 | { |
36d84860 BG |
931 | struct nl80211_global *global = ctx; |
932 | struct wpa_driver_nl80211_data *drv; | |
90a545cc | 933 | int attrlen; |
62d680c3 | 934 | struct rtattr *attr; |
97cfcf64 | 935 | u32 brid = 0; |
aef85ba2 | 936 | char namebuf[IFNAMSIZ]; |
90a545cc JM |
937 | char ifname[IFNAMSIZ + 1]; |
938 | char extra[100], *pos, *end; | |
3f5285e8 | 939 | |
90a545cc JM |
940 | extra[0] = '\0'; |
941 | pos = extra; | |
942 | end = pos + sizeof(extra); | |
943 | ifname[0] = '\0'; | |
944 | ||
945 | attrlen = len; | |
946 | attr = (struct rtattr *) buf; | |
947 | while (RTA_OK(attr, attrlen)) { | |
948 | switch (attr->rta_type) { | |
949 | case IFLA_IFNAME: | |
950 | if (RTA_PAYLOAD(attr) >= IFNAMSIZ) | |
951 | break; | |
952 | os_memcpy(ifname, RTA_DATA(attr), RTA_PAYLOAD(attr)); | |
953 | ifname[RTA_PAYLOAD(attr)] = '\0'; | |
954 | break; | |
955 | case IFLA_MASTER: | |
956 | brid = nla_get_u32((struct nlattr *) attr); | |
957 | pos += os_snprintf(pos, end - pos, " master=%u", brid); | |
958 | break; | |
959 | case IFLA_WIRELESS: | |
960 | pos += os_snprintf(pos, end - pos, " wext"); | |
961 | break; | |
962 | case IFLA_OPERSTATE: | |
963 | pos += os_snprintf(pos, end - pos, " operstate=%u", | |
964 | nla_get_u32((struct nlattr *) attr)); | |
965 | break; | |
966 | case IFLA_LINKMODE: | |
967 | pos += os_snprintf(pos, end - pos, " linkmode=%u", | |
968 | nla_get_u32((struct nlattr *) attr)); | |
969 | break; | |
970 | } | |
971 | attr = RTA_NEXT(attr, attrlen); | |
972 | } | |
973 | extra[sizeof(extra) - 1] = '\0'; | |
974 | ||
f2e90835 JM |
975 | wpa_printf(MSG_DEBUG, "RTM_NEWLINK: ifi_index=%d ifname=%s%s ifi_family=%d ifi_flags=0x%x (%s%s%s%s)", |
976 | ifi->ifi_index, ifname, extra, ifi->ifi_family, | |
977 | ifi->ifi_flags, | |
3f5285e8 JM |
978 | (ifi->ifi_flags & IFF_UP) ? "[UP]" : "", |
979 | (ifi->ifi_flags & IFF_RUNNING) ? "[RUNNING]" : "", | |
980 | (ifi->ifi_flags & IFF_LOWER_UP) ? "[LOWER_UP]" : "", | |
981 | (ifi->ifi_flags & IFF_DORMANT) ? "[DORMANT]" : ""); | |
a63063b4 | 982 | |
45e3fc72 RM |
983 | drv = nl80211_find_drv(global, ifi->ifi_index, buf, len); |
984 | if (!drv) | |
985 | goto event_newlink; | |
986 | ||
a63063b4 | 987 | if (!drv->if_disabled && !(ifi->ifi_flags & IFF_UP)) { |
106fa1e9 | 988 | namebuf[0] = '\0'; |
59d24925 | 989 | if (if_indextoname(ifi->ifi_index, namebuf) && |
106fa1e9 | 990 | linux_iface_up(drv->global->ioctl_sock, namebuf) > 0) { |
59d24925 JM |
991 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface down " |
992 | "event since interface %s is up", namebuf); | |
7a94120e | 993 | drv->ignore_if_down_event = 0; |
59d24925 JM |
994 | return; |
995 | } | |
106fa1e9 JM |
996 | wpa_printf(MSG_DEBUG, "nl80211: Interface down (%s/%s)", |
997 | namebuf, ifname); | |
998 | if (os_strcmp(drv->first_bss->ifname, ifname) != 0) { | |
999 | wpa_printf(MSG_DEBUG, | |
1000 | "nl80211: Not the main interface (%s) - do not indicate interface down", | |
1001 | drv->first_bss->ifname); | |
1002 | } else if (drv->ignore_if_down_event) { | |
7d9c3698 JM |
1003 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface down " |
1004 | "event generated by mode change"); | |
1005 | drv->ignore_if_down_event = 0; | |
1006 | } else { | |
1007 | drv->if_disabled = 1; | |
1008 | wpa_supplicant_event(drv->ctx, | |
1009 | EVENT_INTERFACE_DISABLED, NULL); | |
819f096f AO |
1010 | |
1011 | /* | |
1012 | * Try to get drv again, since it may be removed as | |
1013 | * part of the EVENT_INTERFACE_DISABLED handling for | |
1014 | * dynamic interfaces | |
1015 | */ | |
1016 | drv = nl80211_find_drv(global, ifi->ifi_index, | |
1017 | buf, len); | |
1018 | if (!drv) | |
1019 | return; | |
7d9c3698 | 1020 | } |
a63063b4 JM |
1021 | } |
1022 | ||
1023 | if (drv->if_disabled && (ifi->ifi_flags & IFF_UP)) { | |
aef85ba2 | 1024 | if (if_indextoname(ifi->ifi_index, namebuf) && |
106fa1e9 | 1025 | linux_iface_up(drv->global->ioctl_sock, namebuf) == 0) { |
aef85ba2 JM |
1026 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up " |
1027 | "event since interface %s is down", | |
1028 | namebuf); | |
834ee56f | 1029 | } else if (if_nametoindex(drv->first_bss->ifname) == 0) { |
d1f4942b JM |
1030 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up " |
1031 | "event since interface %s does not exist", | |
834ee56f | 1032 | drv->first_bss->ifname); |
d1f4942b JM |
1033 | } else if (drv->if_removed) { |
1034 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up " | |
1035 | "event since interface %s is marked " | |
834ee56f | 1036 | "removed", drv->first_bss->ifname); |
aef85ba2 | 1037 | } else { |
3e0272ca DW |
1038 | struct i802_bss *bss; |
1039 | u8 addr[ETH_ALEN]; | |
1040 | ||
1041 | /* Re-read MAC address as it may have changed */ | |
1042 | bss = get_bss_ifindex(drv, ifi->ifi_index); | |
1043 | if (bss && | |
1044 | linux_get_ifhwaddr(drv->global->ioctl_sock, | |
1045 | bss->ifname, addr) < 0) { | |
1046 | wpa_printf(MSG_DEBUG, | |
1047 | "nl80211: %s: failed to re-read MAC address", | |
1048 | bss->ifname); | |
1049 | } else if (bss && | |
1050 | os_memcmp(addr, bss->addr, ETH_ALEN) != 0) { | |
1051 | wpa_printf(MSG_DEBUG, | |
1052 | "nl80211: Own MAC address on ifindex %d (%s) changed from " | |
1053 | MACSTR " to " MACSTR, | |
1054 | ifi->ifi_index, bss->ifname, | |
1055 | MAC2STR(bss->addr), | |
1056 | MAC2STR(addr)); | |
1057 | os_memcpy(bss->addr, addr, ETH_ALEN); | |
1058 | } | |
1059 | ||
aef85ba2 JM |
1060 | wpa_printf(MSG_DEBUG, "nl80211: Interface up"); |
1061 | drv->if_disabled = 0; | |
1062 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_ENABLED, | |
1063 | NULL); | |
1064 | } | |
a63063b4 JM |
1065 | } |
1066 | ||
3f5285e8 JM |
1067 | /* |
1068 | * Some drivers send the association event before the operup event--in | |
1069 | * this case, lifting operstate in wpa_driver_nl80211_set_operstate() | |
1070 | * fails. This will hit us when wpa_supplicant does not need to do | |
1071 | * IEEE 802.1X authentication | |
1072 | */ | |
1073 | if (drv->operstate == 1 && | |
1074 | (ifi->ifi_flags & (IFF_LOWER_UP | IFF_DORMANT)) == IFF_LOWER_UP && | |
90a545cc JM |
1075 | !(ifi->ifi_flags & IFF_RUNNING)) { |
1076 | wpa_printf(MSG_DEBUG, "nl80211: Set IF_OPER_UP again based on ifi_flags and expected operstate"); | |
36d84860 | 1077 | netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, |
e2d02c29 | 1078 | -1, IF_OPER_UP); |
3f5285e8 | 1079 | } |
97cfcf64 | 1080 | |
45e3fc72 | 1081 | event_newlink: |
90a545cc | 1082 | if (ifname[0]) |
45e3fc72 RM |
1083 | wpa_driver_nl80211_event_newlink(global, drv, ifi->ifi_index, |
1084 | ifname); | |
90a545cc | 1085 | |
45e3fc72 | 1086 | if (ifi->ifi_family == AF_BRIDGE && brid && drv) { |
392dfd37 JM |
1087 | struct i802_bss *bss; |
1088 | ||
97cfcf64 | 1089 | /* device has been added to bridge */ |
40e76396 JM |
1090 | if (!if_indextoname(brid, namebuf)) { |
1091 | wpa_printf(MSG_DEBUG, | |
1092 | "nl80211: Could not find bridge ifname for ifindex %u", | |
1093 | brid); | |
1094 | return; | |
1095 | } | |
97cfcf64 B |
1096 | wpa_printf(MSG_DEBUG, "nl80211: Add ifindex %u for bridge %s", |
1097 | brid, namebuf); | |
732b1d20 | 1098 | add_ifidx(drv, brid, ifi->ifi_index); |
392dfd37 JM |
1099 | |
1100 | for (bss = drv->first_bss; bss; bss = bss->next) { | |
1101 | if (os_strcmp(ifname, bss->ifname) == 0) { | |
1102 | os_strlcpy(bss->brname, namebuf, IFNAMSIZ); | |
1103 | break; | |
1104 | } | |
1105 | } | |
97cfcf64 | 1106 | } |
3f5285e8 JM |
1107 | } |
1108 | ||
1109 | ||
62d680c3 JM |
1110 | static void wpa_driver_nl80211_event_rtm_dellink(void *ctx, |
1111 | struct ifinfomsg *ifi, | |
1112 | u8 *buf, size_t len) | |
3f5285e8 | 1113 | { |
36d84860 BG |
1114 | struct nl80211_global *global = ctx; |
1115 | struct wpa_driver_nl80211_data *drv; | |
90a545cc | 1116 | int attrlen; |
62d680c3 | 1117 | struct rtattr *attr; |
97cfcf64 | 1118 | u32 brid = 0; |
90a545cc | 1119 | char ifname[IFNAMSIZ + 1]; |
f2e90835 | 1120 | char extra[100], *pos, *end; |
3f5285e8 | 1121 | |
f2e90835 JM |
1122 | extra[0] = '\0'; |
1123 | pos = extra; | |
1124 | end = pos + sizeof(extra); | |
90a545cc JM |
1125 | ifname[0] = '\0'; |
1126 | ||
62d680c3 JM |
1127 | attrlen = len; |
1128 | attr = (struct rtattr *) buf; | |
3f5285e8 | 1129 | while (RTA_OK(attr, attrlen)) { |
90a545cc JM |
1130 | switch (attr->rta_type) { |
1131 | case IFLA_IFNAME: | |
1132 | if (RTA_PAYLOAD(attr) >= IFNAMSIZ) | |
1133 | break; | |
1134 | os_memcpy(ifname, RTA_DATA(attr), RTA_PAYLOAD(attr)); | |
1135 | ifname[RTA_PAYLOAD(attr)] = '\0'; | |
1136 | break; | |
1137 | case IFLA_MASTER: | |
97cfcf64 | 1138 | brid = nla_get_u32((struct nlattr *) attr); |
f2e90835 JM |
1139 | pos += os_snprintf(pos, end - pos, " master=%u", brid); |
1140 | break; | |
1141 | case IFLA_OPERSTATE: | |
1142 | pos += os_snprintf(pos, end - pos, " operstate=%u", | |
1143 | nla_get_u32((struct nlattr *) attr)); | |
1144 | break; | |
1145 | case IFLA_LINKMODE: | |
1146 | pos += os_snprintf(pos, end - pos, " linkmode=%u", | |
1147 | nla_get_u32((struct nlattr *) attr)); | |
90a545cc JM |
1148 | break; |
1149 | } | |
3f5285e8 JM |
1150 | attr = RTA_NEXT(attr, attrlen); |
1151 | } | |
f2e90835 JM |
1152 | extra[sizeof(extra) - 1] = '\0'; |
1153 | ||
1154 | wpa_printf(MSG_DEBUG, "RTM_DELLINK: ifi_index=%d ifname=%s%s ifi_family=%d ifi_flags=0x%x (%s%s%s%s)", | |
1155 | ifi->ifi_index, ifname, extra, ifi->ifi_family, | |
1156 | ifi->ifi_flags, | |
1157 | (ifi->ifi_flags & IFF_UP) ? "[UP]" : "", | |
1158 | (ifi->ifi_flags & IFF_RUNNING) ? "[RUNNING]" : "", | |
1159 | (ifi->ifi_flags & IFF_LOWER_UP) ? "[LOWER_UP]" : "", | |
1160 | (ifi->ifi_flags & IFF_DORMANT) ? "[DORMANT]" : ""); | |
97cfcf64 | 1161 | |
45e3fc72 | 1162 | drv = nl80211_find_drv(global, ifi->ifi_index, buf, len); |
90a545cc | 1163 | |
45e3fc72 | 1164 | if (ifi->ifi_family == AF_BRIDGE && brid && drv) { |
97cfcf64 B |
1165 | /* device has been removed from bridge */ |
1166 | char namebuf[IFNAMSIZ]; | |
40e76396 JM |
1167 | |
1168 | if (!if_indextoname(brid, namebuf)) { | |
1169 | wpa_printf(MSG_DEBUG, | |
1170 | "nl80211: Could not find bridge ifname for ifindex %u", | |
1171 | brid); | |
1172 | } else { | |
1173 | wpa_printf(MSG_DEBUG, | |
1174 | "nl80211: Remove ifindex %u for bridge %s", | |
1175 | brid, namebuf); | |
1176 | } | |
732b1d20 | 1177 | del_ifidx(drv, brid, ifi->ifi_index); |
97cfcf64 | 1178 | } |
45e3fc72 RM |
1179 | |
1180 | if (ifi->ifi_family != AF_BRIDGE || !brid) | |
1181 | wpa_driver_nl80211_event_dellink(global, drv, ifi->ifi_index, | |
1182 | ifname); | |
3f5285e8 JM |
1183 | } |
1184 | ||
1185 | ||
a1fce391 JM |
1186 | struct nl80211_get_assoc_freq_arg { |
1187 | struct wpa_driver_nl80211_data *drv; | |
1188 | unsigned int assoc_freq; | |
1189 | unsigned int ibss_freq; | |
1190 | u8 assoc_bssid[ETH_ALEN]; | |
ed0a4ddc NW |
1191 | u8 assoc_ssid[SSID_MAX_LEN]; |
1192 | u8 assoc_ssid_len; | |
a1fce391 JM |
1193 | }; |
1194 | ||
1195 | static int nl80211_get_assoc_freq_handler(struct nl_msg *msg, void *arg) | |
1196 | { | |
1197 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
1198 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
1199 | struct nlattr *bss[NL80211_BSS_MAX + 1]; | |
1200 | static struct nla_policy bss_policy[NL80211_BSS_MAX + 1] = { | |
1201 | [NL80211_BSS_BSSID] = { .type = NLA_UNSPEC }, | |
1202 | [NL80211_BSS_FREQUENCY] = { .type = NLA_U32 }, | |
ed0a4ddc | 1203 | [NL80211_BSS_INFORMATION_ELEMENTS] = { .type = NLA_UNSPEC }, |
a1fce391 JM |
1204 | [NL80211_BSS_STATUS] = { .type = NLA_U32 }, |
1205 | }; | |
1206 | struct nl80211_get_assoc_freq_arg *ctx = arg; | |
1207 | enum nl80211_bss_status status; | |
1208 | ||
1209 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
1210 | genlmsg_attrlen(gnlh, 0), NULL); | |
1211 | if (!tb[NL80211_ATTR_BSS] || | |
1212 | nla_parse_nested(bss, NL80211_BSS_MAX, tb[NL80211_ATTR_BSS], | |
1213 | bss_policy) || | |
1214 | !bss[NL80211_BSS_STATUS]) | |
1215 | return NL_SKIP; | |
1216 | ||
1217 | status = nla_get_u32(bss[NL80211_BSS_STATUS]); | |
1218 | if (status == NL80211_BSS_STATUS_ASSOCIATED && | |
1219 | bss[NL80211_BSS_FREQUENCY]) { | |
1220 | ctx->assoc_freq = nla_get_u32(bss[NL80211_BSS_FREQUENCY]); | |
1221 | wpa_printf(MSG_DEBUG, "nl80211: Associated on %u MHz", | |
1222 | ctx->assoc_freq); | |
1223 | } | |
1224 | if (status == NL80211_BSS_STATUS_IBSS_JOINED && | |
1225 | bss[NL80211_BSS_FREQUENCY]) { | |
1226 | ctx->ibss_freq = nla_get_u32(bss[NL80211_BSS_FREQUENCY]); | |
1227 | wpa_printf(MSG_DEBUG, "nl80211: IBSS-joined on %u MHz", | |
1228 | ctx->ibss_freq); | |
1229 | } | |
1230 | if (status == NL80211_BSS_STATUS_ASSOCIATED && | |
1231 | bss[NL80211_BSS_BSSID]) { | |
1232 | os_memcpy(ctx->assoc_bssid, | |
1233 | nla_data(bss[NL80211_BSS_BSSID]), ETH_ALEN); | |
1234 | wpa_printf(MSG_DEBUG, "nl80211: Associated with " | |
1235 | MACSTR, MAC2STR(ctx->assoc_bssid)); | |
1236 | } | |
1237 | ||
ed0a4ddc NW |
1238 | if (status == NL80211_BSS_STATUS_ASSOCIATED && |
1239 | bss[NL80211_BSS_INFORMATION_ELEMENTS]) { | |
1240 | const u8 *ie, *ssid; | |
1241 | size_t ie_len; | |
1242 | ||
1243 | ie = nla_data(bss[NL80211_BSS_INFORMATION_ELEMENTS]); | |
1244 | ie_len = nla_len(bss[NL80211_BSS_INFORMATION_ELEMENTS]); | |
1245 | ssid = get_ie(ie, ie_len, WLAN_EID_SSID); | |
1246 | if (ssid && ssid[1] > 0 && ssid[1] <= SSID_MAX_LEN) { | |
1247 | ctx->assoc_ssid_len = ssid[1]; | |
1248 | os_memcpy(ctx->assoc_ssid, ssid + 2, ssid[1]); | |
1249 | } | |
1250 | } | |
1251 | ||
a1fce391 JM |
1252 | return NL_SKIP; |
1253 | } | |
1254 | ||
1255 | ||
ed0a4ddc NW |
1256 | int nl80211_get_assoc_ssid(struct wpa_driver_nl80211_data *drv, u8 *ssid) |
1257 | { | |
1258 | struct nl_msg *msg; | |
1259 | int ret; | |
1260 | struct nl80211_get_assoc_freq_arg arg; | |
1261 | ||
1262 | msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SCAN); | |
1263 | os_memset(&arg, 0, sizeof(arg)); | |
1264 | arg.drv = drv; | |
1265 | ret = send_and_recv_msgs(drv, msg, nl80211_get_assoc_freq_handler, | |
1266 | &arg); | |
1267 | if (ret == 0) { | |
1268 | os_memcpy(ssid, arg.assoc_ssid, arg.assoc_ssid_len); | |
1269 | return arg.assoc_ssid_len; | |
1270 | } | |
1271 | wpa_printf(MSG_DEBUG, "nl80211: Scan result fetch failed: ret=%d (%s)", | |
1272 | ret, strerror(-ret)); | |
1273 | return ret; | |
1274 | } | |
1275 | ||
1276 | ||
f3407c66 | 1277 | unsigned int nl80211_get_assoc_freq(struct wpa_driver_nl80211_data *drv) |
f5a8d422 JM |
1278 | { |
1279 | struct nl_msg *msg; | |
1280 | int ret; | |
a1fce391 | 1281 | struct nl80211_get_assoc_freq_arg arg; |
f5a8d422 | 1282 | |
9725b784 | 1283 | msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SCAN); |
f5a8d422 | 1284 | os_memset(&arg, 0, sizeof(arg)); |
f5a8d422 | 1285 | arg.drv = drv; |
a1fce391 JM |
1286 | ret = send_and_recv_msgs(drv, msg, nl80211_get_assoc_freq_handler, |
1287 | &arg); | |
f5a8d422 | 1288 | if (ret == 0) { |
c7caac56 JM |
1289 | unsigned int freq = drv->nlmode == NL80211_IFTYPE_ADHOC ? |
1290 | arg.ibss_freq : arg.assoc_freq; | |
f5a8d422 | 1291 | wpa_printf(MSG_DEBUG, "nl80211: Operating frequency for the " |
c7caac56 JM |
1292 | "associated BSS from scan results: %u MHz", freq); |
1293 | if (freq) | |
1294 | drv->assoc_freq = freq; | |
30158a0d | 1295 | return drv->assoc_freq; |
f5a8d422 JM |
1296 | } |
1297 | wpa_printf(MSG_DEBUG, "nl80211: Scan result fetch failed: ret=%d " | |
1298 | "(%s)", ret, strerror(-ret)); | |
f5a8d422 JM |
1299 | return drv->assoc_freq; |
1300 | } | |
1301 | ||
1302 | ||
60a972a6 JM |
1303 | static int get_link_signal(struct nl_msg *msg, void *arg) |
1304 | { | |
1305 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
1306 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
1307 | struct nlattr *sinfo[NL80211_STA_INFO_MAX + 1]; | |
1308 | static struct nla_policy policy[NL80211_STA_INFO_MAX + 1] = { | |
1309 | [NL80211_STA_INFO_SIGNAL] = { .type = NLA_U8 }, | |
95783298 | 1310 | [NL80211_STA_INFO_SIGNAL_AVG] = { .type = NLA_U8 }, |
74fa78b2 | 1311 | [NL80211_STA_INFO_BEACON_SIGNAL_AVG] = { .type = NLA_U8 }, |
60a972a6 | 1312 | }; |
7ee35bf3 PS |
1313 | struct nlattr *rinfo[NL80211_RATE_INFO_MAX + 1]; |
1314 | static struct nla_policy rate_policy[NL80211_RATE_INFO_MAX + 1] = { | |
1315 | [NL80211_RATE_INFO_BITRATE] = { .type = NLA_U16 }, | |
1316 | [NL80211_RATE_INFO_MCS] = { .type = NLA_U8 }, | |
1317 | [NL80211_RATE_INFO_40_MHZ_WIDTH] = { .type = NLA_FLAG }, | |
1318 | [NL80211_RATE_INFO_SHORT_GI] = { .type = NLA_FLAG }, | |
1319 | }; | |
1c5c7273 | 1320 | struct wpa_signal_info *sig_change = arg; |
60a972a6 JM |
1321 | |
1322 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
1323 | genlmsg_attrlen(gnlh, 0), NULL); | |
1324 | if (!tb[NL80211_ATTR_STA_INFO] || | |
1325 | nla_parse_nested(sinfo, NL80211_STA_INFO_MAX, | |
1326 | tb[NL80211_ATTR_STA_INFO], policy)) | |
1327 | return NL_SKIP; | |
1328 | if (!sinfo[NL80211_STA_INFO_SIGNAL]) | |
1329 | return NL_SKIP; | |
1330 | ||
7ee35bf3 PS |
1331 | sig_change->current_signal = |
1332 | (s8) nla_get_u8(sinfo[NL80211_STA_INFO_SIGNAL]); | |
1333 | ||
95783298 AO |
1334 | if (sinfo[NL80211_STA_INFO_SIGNAL_AVG]) |
1335 | sig_change->avg_signal = | |
1336 | (s8) nla_get_u8(sinfo[NL80211_STA_INFO_SIGNAL_AVG]); | |
1337 | else | |
1338 | sig_change->avg_signal = 0; | |
1339 | ||
74fa78b2 JM |
1340 | if (sinfo[NL80211_STA_INFO_BEACON_SIGNAL_AVG]) |
1341 | sig_change->avg_beacon_signal = | |
1342 | (s8) | |
1343 | nla_get_u8(sinfo[NL80211_STA_INFO_BEACON_SIGNAL_AVG]); | |
1344 | else | |
1345 | sig_change->avg_beacon_signal = 0; | |
1346 | ||
7ee35bf3 PS |
1347 | if (sinfo[NL80211_STA_INFO_TX_BITRATE]) { |
1348 | if (nla_parse_nested(rinfo, NL80211_RATE_INFO_MAX, | |
1349 | sinfo[NL80211_STA_INFO_TX_BITRATE], | |
1350 | rate_policy)) { | |
1351 | sig_change->current_txrate = 0; | |
1352 | } else { | |
1353 | if (rinfo[NL80211_RATE_INFO_BITRATE]) { | |
1354 | sig_change->current_txrate = | |
1355 | nla_get_u16(rinfo[ | |
1356 | NL80211_RATE_INFO_BITRATE]) * 100; | |
1357 | } | |
1358 | } | |
1359 | } | |
1360 | ||
60a972a6 JM |
1361 | return NL_SKIP; |
1362 | } | |
1363 | ||
1364 | ||
f3407c66 JM |
1365 | int nl80211_get_link_signal(struct wpa_driver_nl80211_data *drv, |
1366 | struct wpa_signal_info *sig) | |
60a972a6 JM |
1367 | { |
1368 | struct nl_msg *msg; | |
1369 | ||
7ee35bf3 PS |
1370 | sig->current_signal = -9999; |
1371 | sig->current_txrate = 0; | |
60a972a6 | 1372 | |
9725b784 | 1373 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_GET_STATION)) || |
a862e4a3 JM |
1374 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, drv->bssid)) { |
1375 | nlmsg_free(msg); | |
1376 | return -ENOBUFS; | |
1377 | } | |
60a972a6 JM |
1378 | |
1379 | return send_and_recv_msgs(drv, msg, get_link_signal, sig); | |
60a972a6 JM |
1380 | } |
1381 | ||
1382 | ||
7ee35bf3 PS |
1383 | static int get_link_noise(struct nl_msg *msg, void *arg) |
1384 | { | |
1385 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
1386 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
1387 | struct nlattr *sinfo[NL80211_SURVEY_INFO_MAX + 1]; | |
1388 | static struct nla_policy survey_policy[NL80211_SURVEY_INFO_MAX + 1] = { | |
1389 | [NL80211_SURVEY_INFO_FREQUENCY] = { .type = NLA_U32 }, | |
1390 | [NL80211_SURVEY_INFO_NOISE] = { .type = NLA_U8 }, | |
1391 | }; | |
1c5c7273 | 1392 | struct wpa_signal_info *sig_change = arg; |
7ee35bf3 PS |
1393 | |
1394 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
1395 | genlmsg_attrlen(gnlh, 0), NULL); | |
1396 | ||
1397 | if (!tb[NL80211_ATTR_SURVEY_INFO]) { | |
1398 | wpa_printf(MSG_DEBUG, "nl80211: survey data missing!"); | |
1399 | return NL_SKIP; | |
1400 | } | |
1401 | ||
1402 | if (nla_parse_nested(sinfo, NL80211_SURVEY_INFO_MAX, | |
1403 | tb[NL80211_ATTR_SURVEY_INFO], | |
1404 | survey_policy)) { | |
1405 | wpa_printf(MSG_DEBUG, "nl80211: failed to parse nested " | |
1406 | "attributes!"); | |
1407 | return NL_SKIP; | |
1408 | } | |
1409 | ||
1410 | if (!sinfo[NL80211_SURVEY_INFO_FREQUENCY]) | |
1411 | return NL_SKIP; | |
1412 | ||
1413 | if (nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]) != | |
1414 | sig_change->frequency) | |
1415 | return NL_SKIP; | |
1416 | ||
1417 | if (!sinfo[NL80211_SURVEY_INFO_NOISE]) | |
1418 | return NL_SKIP; | |
1419 | ||
1420 | sig_change->current_noise = | |
1421 | (s8) nla_get_u8(sinfo[NL80211_SURVEY_INFO_NOISE]); | |
1422 | ||
1423 | return NL_SKIP; | |
1424 | } | |
1425 | ||
1426 | ||
f3407c66 JM |
1427 | int nl80211_get_link_noise(struct wpa_driver_nl80211_data *drv, |
1428 | struct wpa_signal_info *sig_change) | |
7ee35bf3 PS |
1429 | { |
1430 | struct nl_msg *msg; | |
1431 | ||
1432 | sig_change->current_noise = 9999; | |
1433 | sig_change->frequency = drv->assoc_freq; | |
1434 | ||
9725b784 | 1435 | msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SURVEY); |
7ee35bf3 | 1436 | return send_and_recv_msgs(drv, msg, get_link_noise, sig_change); |
7ee35bf3 PS |
1437 | } |
1438 | ||
1439 | ||
97865538 | 1440 | static void wpa_driver_nl80211_event_receive(int sock, void *eloop_ctx, |
5582a5d1 | 1441 | void *handle) |
97865538 | 1442 | { |
a4ae123c | 1443 | struct nl_cb *cb = eloop_ctx; |
34068ac3 | 1444 | int res; |
97865538 | 1445 | |
cc2ada86 | 1446 | wpa_printf(MSG_MSGDUMP, "nl80211: Event message available"); |
97865538 | 1447 | |
34068ac3 | 1448 | res = nl_recvmsgs(handle, cb); |
d3d04831 | 1449 | if (res < 0) { |
34068ac3 JM |
1450 | wpa_printf(MSG_INFO, "nl80211: %s->nl_recvmsgs failed: %d", |
1451 | __func__, res); | |
1452 | } | |
97865538 JM |
1453 | } |
1454 | ||
1455 | ||
6d158490 LR |
1456 | /** |
1457 | * wpa_driver_nl80211_set_country - ask nl80211 to set the regulatory domain | |
1458 | * @priv: driver_nl80211 private data | |
1459 | * @alpha2_arg: country to which to switch to | |
1460 | * Returns: 0 on success, -1 on failure | |
1461 | * | |
1462 | * This asks nl80211 to set the regulatory domain for given | |
1463 | * country ISO / IEC alpha2. | |
1464 | */ | |
1465 | static int wpa_driver_nl80211_set_country(void *priv, const char *alpha2_arg) | |
1466 | { | |
a2e40bb6 FF |
1467 | struct i802_bss *bss = priv; |
1468 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
6d158490 LR |
1469 | char alpha2[3]; |
1470 | struct nl_msg *msg; | |
1471 | ||
1472 | msg = nlmsg_alloc(); | |
1473 | if (!msg) | |
e785c2ba | 1474 | return -ENOMEM; |
6d158490 LR |
1475 | |
1476 | alpha2[0] = alpha2_arg[0]; | |
1477 | alpha2[1] = alpha2_arg[1]; | |
1478 | alpha2[2] = '\0'; | |
1479 | ||
a862e4a3 JM |
1480 | if (!nl80211_cmd(drv, msg, 0, NL80211_CMD_REQ_SET_REG) || |
1481 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, alpha2)) { | |
1482 | nlmsg_free(msg); | |
1483 | return -EINVAL; | |
1484 | } | |
6d158490 LR |
1485 | if (send_and_recv_msgs(drv, msg, NULL, NULL)) |
1486 | return -EINVAL; | |
1487 | return 0; | |
6d158490 LR |
1488 | } |
1489 | ||
1490 | ||
f0793bf1 JM |
1491 | static int nl80211_get_country(struct nl_msg *msg, void *arg) |
1492 | { | |
1493 | char *alpha2 = arg; | |
1494 | struct nlattr *tb_msg[NL80211_ATTR_MAX + 1]; | |
1495 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
1496 | ||
1497 | nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
1498 | genlmsg_attrlen(gnlh, 0), NULL); | |
1499 | if (!tb_msg[NL80211_ATTR_REG_ALPHA2]) { | |
1500 | wpa_printf(MSG_DEBUG, "nl80211: No country information available"); | |
1501 | return NL_SKIP; | |
1502 | } | |
1503 | os_strlcpy(alpha2, nla_data(tb_msg[NL80211_ATTR_REG_ALPHA2]), 3); | |
1504 | return NL_SKIP; | |
1505 | } | |
1506 | ||
1507 | ||
1508 | static int wpa_driver_nl80211_get_country(void *priv, char *alpha2) | |
1509 | { | |
1510 | struct i802_bss *bss = priv; | |
1511 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
1512 | struct nl_msg *msg; | |
1513 | int ret; | |
1514 | ||
1515 | msg = nlmsg_alloc(); | |
1516 | if (!msg) | |
1517 | return -ENOMEM; | |
1518 | ||
1519 | nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_REG); | |
1520 | alpha2[0] = '\0'; | |
1521 | ret = send_and_recv_msgs(drv, msg, nl80211_get_country, alpha2); | |
1522 | if (!alpha2[0]) | |
1523 | ret = -1; | |
1524 | ||
1525 | return ret; | |
1526 | } | |
1527 | ||
1528 | ||
2a7b66f5 BG |
1529 | static int wpa_driver_nl80211_init_nl_global(struct nl80211_global *global) |
1530 | { | |
d6c9aab8 JB |
1531 | int ret; |
1532 | ||
2a7b66f5 BG |
1533 | global->nl_cb = nl_cb_alloc(NL_CB_DEFAULT); |
1534 | if (global->nl_cb == NULL) { | |
1535 | wpa_printf(MSG_ERROR, "nl80211: Failed to allocate netlink " | |
1536 | "callbacks"); | |
1537 | return -1; | |
1538 | } | |
1539 | ||
481234cf JM |
1540 | global->nl = nl_create_handle(global->nl_cb, "nl"); |
1541 | if (global->nl == NULL) | |
d6c9aab8 | 1542 | goto err; |
276e2d67 | 1543 | |
481234cf | 1544 | global->nl80211_id = genl_ctrl_resolve(global->nl, "nl80211"); |
335d42b1 | 1545 | if (global->nl80211_id < 0) { |
276e2d67 BG |
1546 | wpa_printf(MSG_ERROR, "nl80211: 'nl80211' generic netlink not " |
1547 | "found"); | |
d6c9aab8 | 1548 | goto err; |
276e2d67 BG |
1549 | } |
1550 | ||
481234cf JM |
1551 | global->nl_event = nl_create_handle(global->nl_cb, "event"); |
1552 | if (global->nl_event == NULL) | |
d6c9aab8 | 1553 | goto err; |
9fff9fdc | 1554 | |
d6c9aab8 | 1555 | ret = nl_get_multicast_id(global, "nl80211", "scan"); |
97865538 | 1556 | if (ret >= 0) |
481234cf | 1557 | ret = nl_socket_add_membership(global->nl_event, ret); |
97865538 JM |
1558 | if (ret < 0) { |
1559 | wpa_printf(MSG_ERROR, "nl80211: Could not add multicast " | |
1560 | "membership for scan events: %d (%s)", | |
1561 | ret, strerror(-ret)); | |
d6c9aab8 | 1562 | goto err; |
97865538 | 1563 | } |
c2a04078 | 1564 | |
d6c9aab8 | 1565 | ret = nl_get_multicast_id(global, "nl80211", "mlme"); |
c2a04078 | 1566 | if (ret >= 0) |
481234cf | 1567 | ret = nl_socket_add_membership(global->nl_event, ret); |
c2a04078 JM |
1568 | if (ret < 0) { |
1569 | wpa_printf(MSG_ERROR, "nl80211: Could not add multicast " | |
1570 | "membership for mlme events: %d (%s)", | |
1571 | ret, strerror(-ret)); | |
d6c9aab8 | 1572 | goto err; |
c2a04078 | 1573 | } |
c2a04078 | 1574 | |
d6c9aab8 | 1575 | ret = nl_get_multicast_id(global, "nl80211", "regulatory"); |
33c5deb8 | 1576 | if (ret >= 0) |
481234cf | 1577 | ret = nl_socket_add_membership(global->nl_event, ret); |
33c5deb8 JM |
1578 | if (ret < 0) { |
1579 | wpa_printf(MSG_DEBUG, "nl80211: Could not add multicast " | |
1580 | "membership for regulatory events: %d (%s)", | |
1581 | ret, strerror(-ret)); | |
1582 | /* Continue without regulatory events */ | |
1583 | } | |
1584 | ||
17b79e65 JM |
1585 | ret = nl_get_multicast_id(global, "nl80211", "vendor"); |
1586 | if (ret >= 0) | |
1587 | ret = nl_socket_add_membership(global->nl_event, ret); | |
1588 | if (ret < 0) { | |
1589 | wpa_printf(MSG_DEBUG, "nl80211: Could not add multicast " | |
1590 | "membership for vendor events: %d (%s)", | |
1591 | ret, strerror(-ret)); | |
1592 | /* Continue without vendor events */ | |
1593 | } | |
1594 | ||
d6c9aab8 JB |
1595 | nl_cb_set(global->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, |
1596 | no_seq_check, NULL); | |
1597 | nl_cb_set(global->nl_cb, NL_CB_VALID, NL_CB_CUSTOM, | |
1598 | process_global_event, global); | |
1599 | ||
5f65e9f7 JB |
1600 | nl80211_register_eloop_read(&global->nl_event, |
1601 | wpa_driver_nl80211_event_receive, | |
1602 | global->nl_cb); | |
d6c9aab8 JB |
1603 | |
1604 | return 0; | |
1605 | ||
1606 | err: | |
1607 | nl_destroy_handles(&global->nl_event); | |
1608 | nl_destroy_handles(&global->nl); | |
1609 | nl_cb_put(global->nl_cb); | |
671a5039 | 1610 | global->nl_cb = NULL; |
d6c9aab8 JB |
1611 | return -1; |
1612 | } | |
1613 | ||
1614 | ||
f51f54a0 JM |
1615 | static void nl80211_check_global(struct nl80211_global *global) |
1616 | { | |
1617 | struct nl_handle *handle; | |
1618 | const char *groups[] = { "scan", "mlme", "regulatory", "vendor", NULL }; | |
1619 | int ret; | |
1620 | unsigned int i; | |
1621 | ||
1622 | /* | |
1623 | * Try to re-add memberships to handle case of cfg80211 getting reloaded | |
1624 | * and all registration having been cleared. | |
1625 | */ | |
1626 | handle = (void *) (((intptr_t) global->nl_event) ^ | |
1627 | ELOOP_SOCKET_INVALID); | |
1628 | ||
1629 | for (i = 0; groups[i]; i++) { | |
1630 | ret = nl_get_multicast_id(global, "nl80211", groups[i]); | |
1631 | if (ret >= 0) | |
1632 | ret = nl_socket_add_membership(handle, ret); | |
1633 | if (ret < 0) { | |
1634 | wpa_printf(MSG_INFO, | |
1635 | "nl80211: Could not re-add multicast membership for %s events: %d (%s)", | |
1636 | groups[i], ret, strerror(-ret)); | |
1637 | } | |
1638 | } | |
1639 | } | |
1640 | ||
1641 | ||
8401a6b0 JM |
1642 | static void wpa_driver_nl80211_rfkill_blocked(void *ctx) |
1643 | { | |
6da504a1 IP |
1644 | struct wpa_driver_nl80211_data *drv = ctx; |
1645 | ||
8401a6b0 | 1646 | wpa_printf(MSG_DEBUG, "nl80211: RFKILL blocked"); |
6da504a1 | 1647 | |
a63063b4 | 1648 | /* |
6da504a1 IP |
1649 | * rtnetlink ifdown handler will report interfaces other than the P2P |
1650 | * Device interface as disabled. | |
a63063b4 | 1651 | */ |
6da504a1 IP |
1652 | if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) |
1653 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_DISABLED, NULL); | |
8401a6b0 JM |
1654 | } |
1655 | ||
1656 | ||
1657 | static void wpa_driver_nl80211_rfkill_unblocked(void *ctx) | |
1658 | { | |
1659 | struct wpa_driver_nl80211_data *drv = ctx; | |
1660 | wpa_printf(MSG_DEBUG, "nl80211: RFKILL unblocked"); | |
834ee56f | 1661 | if (i802_set_iface_flags(drv->first_bss, 1)) { |
8401a6b0 JM |
1662 | wpa_printf(MSG_DEBUG, "nl80211: Could not set interface UP " |
1663 | "after rfkill unblock"); | |
1664 | return; | |
1665 | } | |
e8dc205f AO |
1666 | |
1667 | if (is_p2p_net_interface(drv->nlmode)) | |
1668 | nl80211_disable_11b_rates(drv, drv->ifindex, 1); | |
1669 | ||
6da504a1 IP |
1670 | /* |
1671 | * rtnetlink ifup handler will report interfaces other than the P2P | |
1672 | * Device interface as enabled. | |
1673 | */ | |
1674 | if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) | |
1675 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_ENABLED, NULL); | |
8401a6b0 JM |
1676 | } |
1677 | ||
1678 | ||
32ab4855 JB |
1679 | static void wpa_driver_nl80211_handle_eapol_tx_status(int sock, |
1680 | void *eloop_ctx, | |
1681 | void *handle) | |
1682 | { | |
1683 | struct wpa_driver_nl80211_data *drv = eloop_ctx; | |
1684 | u8 data[2048]; | |
1685 | struct msghdr msg; | |
1686 | struct iovec entry; | |
cad0f50e | 1687 | u8 control[512]; |
32ab4855 JB |
1688 | struct cmsghdr *cmsg; |
1689 | int res, found_ee = 0, found_wifi = 0, acked = 0; | |
1690 | union wpa_event_data event; | |
1691 | ||
1692 | memset(&msg, 0, sizeof(msg)); | |
1693 | msg.msg_iov = &entry; | |
1694 | msg.msg_iovlen = 1; | |
1695 | entry.iov_base = data; | |
1696 | entry.iov_len = sizeof(data); | |
1697 | msg.msg_control = &control; | |
1698 | msg.msg_controllen = sizeof(control); | |
1699 | ||
1700 | res = recvmsg(sock, &msg, MSG_ERRQUEUE); | |
1701 | /* if error or not fitting 802.3 header, return */ | |
1702 | if (res < 14) | |
1703 | return; | |
1704 | ||
1705 | for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg)) | |
1706 | { | |
1707 | if (cmsg->cmsg_level == SOL_SOCKET && | |
1708 | cmsg->cmsg_type == SCM_WIFI_STATUS) { | |
1709 | int *ack; | |
1710 | ||
1711 | found_wifi = 1; | |
1712 | ack = (void *)CMSG_DATA(cmsg); | |
1713 | acked = *ack; | |
1714 | } | |
1715 | ||
1716 | if (cmsg->cmsg_level == SOL_PACKET && | |
1717 | cmsg->cmsg_type == PACKET_TX_TIMESTAMP) { | |
1718 | struct sock_extended_err *err = | |
1719 | (struct sock_extended_err *)CMSG_DATA(cmsg); | |
1720 | ||
1721 | if (err->ee_origin == SO_EE_ORIGIN_TXSTATUS) | |
1722 | found_ee = 1; | |
1723 | } | |
1724 | } | |
1725 | ||
1726 | if (!found_ee || !found_wifi) | |
1727 | return; | |
1728 | ||
1729 | memset(&event, 0, sizeof(event)); | |
1730 | event.eapol_tx_status.dst = data; | |
1731 | event.eapol_tx_status.data = data + 14; | |
1732 | event.eapol_tx_status.data_len = res - 14; | |
1733 | event.eapol_tx_status.ack = acked; | |
1734 | wpa_supplicant_event(drv->ctx, EVENT_EAPOL_TX_STATUS, &event); | |
1735 | } | |
1736 | ||
1737 | ||
cc7a48d1 JB |
1738 | static int nl80211_init_bss(struct i802_bss *bss) |
1739 | { | |
1740 | bss->nl_cb = nl_cb_alloc(NL_CB_DEFAULT); | |
1741 | if (!bss->nl_cb) | |
1742 | return -1; | |
1743 | ||
1744 | nl_cb_set(bss->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, | |
1745 | no_seq_check, NULL); | |
1746 | nl_cb_set(bss->nl_cb, NL_CB_VALID, NL_CB_CUSTOM, | |
1747 | process_bss_event, bss); | |
1748 | ||
1749 | return 0; | |
1750 | } | |
1751 | ||
1752 | ||
1753 | static void nl80211_destroy_bss(struct i802_bss *bss) | |
1754 | { | |
1755 | nl_cb_put(bss->nl_cb); | |
1756 | bss->nl_cb = NULL; | |
1757 | } | |
1758 | ||
1759 | ||
0e92fb8f JB |
1760 | static void |
1761 | wpa_driver_nl80211_drv_init_rfkill(struct wpa_driver_nl80211_data *drv) | |
1762 | { | |
1763 | struct rfkill_config *rcfg; | |
1764 | ||
1765 | if (drv->rfkill) | |
1766 | return; | |
1767 | ||
1768 | rcfg = os_zalloc(sizeof(*rcfg)); | |
1769 | if (!rcfg) | |
1770 | return; | |
1771 | ||
1772 | rcfg->ctx = drv; | |
1773 | ||
1774 | /* rfkill uses netdev sysfs for initialization. However, P2P Device is | |
1775 | * not associated with a netdev, so use the name of some other interface | |
1776 | * sharing the same wiphy as the P2P Device interface. | |
1777 | * | |
1778 | * Note: This is valid, as a P2P Device interface is always dynamically | |
1779 | * created and is created only once another wpa_s interface was added. | |
1780 | */ | |
1781 | if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) { | |
1782 | struct nl80211_global *global = drv->global; | |
1783 | struct wpa_driver_nl80211_data *tmp1; | |
1784 | ||
1785 | dl_list_for_each(tmp1, &global->interfaces, | |
1786 | struct wpa_driver_nl80211_data, list) { | |
1787 | if (drv == tmp1 || drv->wiphy_idx != tmp1->wiphy_idx || | |
1788 | !tmp1->rfkill) | |
1789 | continue; | |
1790 | ||
1791 | wpa_printf(MSG_DEBUG, | |
1792 | "nl80211: Use (%s) to initialize P2P Device rfkill", | |
1793 | tmp1->first_bss->ifname); | |
1794 | os_strlcpy(rcfg->ifname, tmp1->first_bss->ifname, | |
1795 | sizeof(rcfg->ifname)); | |
1796 | break; | |
1797 | } | |
1798 | } else { | |
1799 | os_strlcpy(rcfg->ifname, drv->first_bss->ifname, | |
1800 | sizeof(rcfg->ifname)); | |
1801 | } | |
1802 | ||
1803 | rcfg->blocked_cb = wpa_driver_nl80211_rfkill_blocked; | |
1804 | rcfg->unblocked_cb = wpa_driver_nl80211_rfkill_unblocked; | |
1805 | drv->rfkill = rfkill_init(rcfg); | |
1806 | if (!drv->rfkill) { | |
1807 | wpa_printf(MSG_DEBUG, "nl80211: RFKILL status not available"); | |
1808 | os_free(rcfg); | |
1809 | } | |
1810 | } | |
1811 | ||
1812 | ||
0d547d5f JM |
1813 | static void * wpa_driver_nl80211_drv_init(void *ctx, const char *ifname, |
1814 | void *global_priv, int hostapd, | |
0ecff8d7 JM |
1815 | const u8 *set_addr, |
1816 | const char *driver_params) | |
9fff9fdc | 1817 | { |
9fff9fdc | 1818 | struct wpa_driver_nl80211_data *drv; |
a2e40bb6 | 1819 | struct i802_bss *bss; |
9fff9fdc | 1820 | |
a5c696ad JM |
1821 | if (global_priv == NULL) |
1822 | return NULL; | |
9fff9fdc JM |
1823 | drv = os_zalloc(sizeof(*drv)); |
1824 | if (drv == NULL) | |
1825 | return NULL; | |
f2ed8023 | 1826 | drv->global = global_priv; |
9fff9fdc | 1827 | drv->ctx = ctx; |
0d547d5f JM |
1828 | drv->hostapd = !!hostapd; |
1829 | drv->eapol_sock = -1; | |
64ae2447 JM |
1830 | |
1831 | /* | |
1832 | * There is no driver capability flag for this, so assume it is | |
1833 | * supported and disable this on first attempt to use if the driver | |
1834 | * rejects the command due to missing support. | |
1835 | */ | |
1836 | drv->set_rekey_offload = 1; | |
1837 | ||
0d547d5f JM |
1838 | drv->num_if_indices = sizeof(drv->default_if_indices) / sizeof(int); |
1839 | drv->if_indices = drv->default_if_indices; | |
732b1d20 | 1840 | drv->if_indices_reason = drv->default_if_indices_reason; |
834ee56f KP |
1841 | |
1842 | drv->first_bss = os_zalloc(sizeof(*drv->first_bss)); | |
1843 | if (!drv->first_bss) { | |
1844 | os_free(drv); | |
1845 | return NULL; | |
1846 | } | |
1847 | bss = drv->first_bss; | |
a2e40bb6 | 1848 | bss->drv = drv; |
a5e1eb20 SE |
1849 | bss->ctx = ctx; |
1850 | ||
a2e40bb6 | 1851 | os_strlcpy(bss->ifname, ifname, sizeof(bss->ifname)); |
9fff9fdc JM |
1852 | drv->monitor_ifidx = -1; |
1853 | drv->monitor_sock = -1; | |
d12dab4c | 1854 | drv->eapol_tx_sock = -1; |
b1f625e0 | 1855 | drv->ap_scan_as_station = NL80211_IFTYPE_UNSPECIFIED; |
9fff9fdc | 1856 | |
cc7a48d1 JB |
1857 | if (nl80211_init_bss(bss)) |
1858 | goto failed; | |
1859 | ||
0ecff8d7 | 1860 | if (wpa_driver_nl80211_finish_drv_init(drv, set_addr, 1, driver_params)) |
bbaf0837 | 1861 | goto failed; |
7524cfb1 | 1862 | |
d12dab4c | 1863 | drv->eapol_tx_sock = socket(PF_PACKET, SOCK_DGRAM, 0); |
32ab4855 JB |
1864 | if (drv->eapol_tx_sock < 0) |
1865 | goto failed; | |
1866 | ||
1867 | if (drv->data_tx_status) { | |
1868 | int enabled = 1; | |
1869 | ||
1870 | if (setsockopt(drv->eapol_tx_sock, SOL_SOCKET, SO_WIFI_STATUS, | |
1871 | &enabled, sizeof(enabled)) < 0) { | |
1872 | wpa_printf(MSG_DEBUG, | |
1873 | "nl80211: wifi status sockopt failed\n"); | |
1874 | drv->data_tx_status = 0; | |
a11241fa JB |
1875 | if (!drv->use_monitor) |
1876 | drv->capa.flags &= | |
1877 | ~WPA_DRIVER_FLAGS_EAPOL_TX_STATUS; | |
32ab4855 JB |
1878 | } else { |
1879 | eloop_register_read_sock(drv->eapol_tx_sock, | |
1880 | wpa_driver_nl80211_handle_eapol_tx_status, | |
1881 | drv, NULL); | |
1882 | } | |
1883 | } | |
f10bfc9a | 1884 | |
dac12351 | 1885 | if (drv->global) { |
f51f54a0 | 1886 | nl80211_check_global(drv->global); |
c4bb8817 | 1887 | dl_list_add(&drv->global->interfaces, &drv->list); |
dac12351 BG |
1888 | drv->in_interface_list = 1; |
1889 | } | |
c4bb8817 | 1890 | |
a2e40bb6 | 1891 | return bss; |
7524cfb1 | 1892 | |
bbaf0837 | 1893 | failed: |
dac12351 | 1894 | wpa_driver_nl80211_deinit(bss); |
7524cfb1 JM |
1895 | return NULL; |
1896 | } | |
1897 | ||
1898 | ||
0d547d5f JM |
1899 | /** |
1900 | * wpa_driver_nl80211_init - Initialize nl80211 driver interface | |
1901 | * @ctx: context to be used when calling wpa_supplicant functions, | |
1902 | * e.g., wpa_supplicant_event() | |
1903 | * @ifname: interface name, e.g., wlan0 | |
1904 | * @global_priv: private driver global data from global_init() | |
1905 | * Returns: Pointer to private data, %NULL on failure | |
1906 | */ | |
1907 | static void * wpa_driver_nl80211_init(void *ctx, const char *ifname, | |
1908 | void *global_priv) | |
1909 | { | |
0ecff8d7 JM |
1910 | return wpa_driver_nl80211_drv_init(ctx, ifname, global_priv, 0, NULL, |
1911 | NULL); | |
0d547d5f JM |
1912 | } |
1913 | ||
1914 | ||
a11241fa | 1915 | static int nl80211_register_frame(struct i802_bss *bss, |
5582a5d1 | 1916 | struct nl_handle *nl_handle, |
bd94971e | 1917 | u16 type, const u8 *match, size_t match_len) |
58f6fbe0 | 1918 | { |
a11241fa | 1919 | struct wpa_driver_nl80211_data *drv = bss->drv; |
58f6fbe0 | 1920 | struct nl_msg *msg; |
a862e4a3 | 1921 | int ret; |
880de885 | 1922 | char buf[30]; |
58f6fbe0 | 1923 | |
880de885 JM |
1924 | buf[0] = '\0'; |
1925 | wpa_snprintf_hex(buf, sizeof(buf), match, match_len); | |
dedfa440 PF |
1926 | wpa_printf(MSG_DEBUG, "nl80211: Register frame type=0x%x (%s) nl_handle=%p match=%s", |
1927 | type, fc2str(type), nl_handle, buf); | |
36488c05 | 1928 | |
56f77852 | 1929 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_REGISTER_ACTION)) || |
a862e4a3 JM |
1930 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, type) || |
1931 | nla_put(msg, NL80211_ATTR_FRAME_MATCH, match_len, match)) { | |
1932 | nlmsg_free(msg); | |
1933 | return -1; | |
1934 | } | |
58f6fbe0 | 1935 | |
d6c9aab8 | 1936 | ret = send_and_recv(drv->global, nl_handle, msg, NULL, NULL); |
58f6fbe0 | 1937 | if (ret) { |
5582a5d1 JB |
1938 | wpa_printf(MSG_DEBUG, "nl80211: Register frame command " |
1939 | "failed (type=%u): ret=%d (%s)", | |
1940 | type, ret, strerror(-ret)); | |
1941 | wpa_hexdump(MSG_DEBUG, "nl80211: Register frame match", | |
58f6fbe0 | 1942 | match, match_len); |
58f6fbe0 | 1943 | } |
58f6fbe0 JM |
1944 | return ret; |
1945 | } | |
1946 | ||
1947 | ||
a11241fa JB |
1948 | static int nl80211_alloc_mgmt_handle(struct i802_bss *bss) |
1949 | { | |
481234cf | 1950 | if (bss->nl_mgmt) { |
a11241fa | 1951 | wpa_printf(MSG_DEBUG, "nl80211: Mgmt reporting " |
36488c05 | 1952 | "already on! (nl_mgmt=%p)", bss->nl_mgmt); |
a11241fa JB |
1953 | return -1; |
1954 | } | |
1955 | ||
ce20a370 | 1956 | bss->nl_mgmt = nl_create_handle(bss->nl_cb, "mgmt"); |
481234cf | 1957 | if (bss->nl_mgmt == NULL) |
a11241fa JB |
1958 | return -1; |
1959 | ||
a11241fa JB |
1960 | return 0; |
1961 | } | |
1962 | ||
1963 | ||
5f65e9f7 JB |
1964 | static void nl80211_mgmt_handle_register_eloop(struct i802_bss *bss) |
1965 | { | |
1966 | nl80211_register_eloop_read(&bss->nl_mgmt, | |
1967 | wpa_driver_nl80211_event_receive, | |
1968 | bss->nl_cb); | |
1969 | } | |
1970 | ||
1971 | ||
a11241fa | 1972 | static int nl80211_register_action_frame(struct i802_bss *bss, |
bd94971e JB |
1973 | const u8 *match, size_t match_len) |
1974 | { | |
1975 | u16 type = (WLAN_FC_TYPE_MGMT << 2) | (WLAN_FC_STYPE_ACTION << 4); | |
481234cf | 1976 | return nl80211_register_frame(bss, bss->nl_mgmt, |
5582a5d1 | 1977 | type, match, match_len); |
bd94971e JB |
1978 | } |
1979 | ||
1980 | ||
a11241fa | 1981 | static int nl80211_mgmt_subscribe_non_ap(struct i802_bss *bss) |
58f6fbe0 | 1982 | { |
a11241fa | 1983 | struct wpa_driver_nl80211_data *drv = bss->drv; |
6f06766e | 1984 | int ret = 0; |
a11241fa JB |
1985 | |
1986 | if (nl80211_alloc_mgmt_handle(bss)) | |
1987 | return -1; | |
36488c05 JM |
1988 | wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with non-AP " |
1989 | "handle %p", bss->nl_mgmt); | |
a11241fa | 1990 | |
e8d1168b JB |
1991 | if (drv->nlmode == NL80211_IFTYPE_ADHOC) { |
1992 | u16 type = (WLAN_FC_TYPE_MGMT << 2) | (WLAN_FC_STYPE_AUTH << 4); | |
1993 | ||
1994 | /* register for any AUTH message */ | |
1995 | nl80211_register_frame(bss, bss->nl_mgmt, type, NULL, 0); | |
1996 | } | |
1997 | ||
56f5af48 JM |
1998 | #ifdef CONFIG_INTERWORKING |
1999 | /* QoS Map Configure */ | |
2000 | if (nl80211_register_action_frame(bss, (u8 *) "\x01\x04", 2) < 0) | |
6f06766e | 2001 | ret = -1; |
56f5af48 | 2002 | #endif /* CONFIG_INTERWORKING */ |
4fe9fa0d | 2003 | #if defined(CONFIG_P2P) || defined(CONFIG_INTERWORKING) |
046b26a2 | 2004 | /* GAS Initial Request */ |
a11241fa | 2005 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0a", 2) < 0) |
6f06766e | 2006 | ret = -1; |
046b26a2 | 2007 | /* GAS Initial Response */ |
a11241fa | 2008 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0b", 2) < 0) |
6f06766e | 2009 | ret = -1; |
18708aad | 2010 | /* GAS Comeback Request */ |
a11241fa | 2011 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0c", 2) < 0) |
6f06766e | 2012 | ret = -1; |
18708aad | 2013 | /* GAS Comeback Response */ |
a11241fa | 2014 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0d", 2) < 0) |
6f06766e | 2015 | ret = -1; |
c5a64e2d JM |
2016 | /* Protected GAS Initial Request */ |
2017 | if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0a", 2) < 0) | |
2018 | ret = -1; | |
2019 | /* Protected GAS Initial Response */ | |
2020 | if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0b", 2) < 0) | |
2021 | ret = -1; | |
2022 | /* Protected GAS Comeback Request */ | |
2023 | if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0c", 2) < 0) | |
2024 | ret = -1; | |
2025 | /* Protected GAS Comeback Response */ | |
2026 | if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0d", 2) < 0) | |
2027 | ret = -1; | |
4fe9fa0d JM |
2028 | #endif /* CONFIG_P2P || CONFIG_INTERWORKING */ |
2029 | #ifdef CONFIG_P2P | |
046b26a2 | 2030 | /* P2P Public Action */ |
a11241fa | 2031 | if (nl80211_register_action_frame(bss, |
046b26a2 JM |
2032 | (u8 *) "\x04\x09\x50\x6f\x9a\x09", |
2033 | 6) < 0) | |
6f06766e | 2034 | ret = -1; |
046b26a2 | 2035 | /* P2P Action */ |
a11241fa | 2036 | if (nl80211_register_action_frame(bss, |
046b26a2 JM |
2037 | (u8 *) "\x7f\x50\x6f\x9a\x09", |
2038 | 5) < 0) | |
6f06766e | 2039 | ret = -1; |
046b26a2 | 2040 | #endif /* CONFIG_P2P */ |
7d878ca7 JM |
2041 | #ifdef CONFIG_IEEE80211W |
2042 | /* SA Query Response */ | |
a11241fa | 2043 | if (nl80211_register_action_frame(bss, (u8 *) "\x08\x01", 2) < 0) |
6f06766e | 2044 | ret = -1; |
7d878ca7 | 2045 | #endif /* CONFIG_IEEE80211W */ |
35287637 AN |
2046 | #ifdef CONFIG_TDLS |
2047 | if ((drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) { | |
2048 | /* TDLS Discovery Response */ | |
aa543c0c | 2049 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0e", 2) < |
35287637 | 2050 | 0) |
6f06766e | 2051 | ret = -1; |
35287637 AN |
2052 | } |
2053 | #endif /* CONFIG_TDLS */ | |
46ab9b8c AN |
2054 | #ifdef CONFIG_FST |
2055 | /* FST Action frames */ | |
2056 | if (nl80211_register_action_frame(bss, (u8 *) "\x12", 1) < 0) | |
2057 | ret = -1; | |
2058 | #endif /* CONFIG_FST */ | |
046b26a2 | 2059 | |
7b90c16a | 2060 | /* FT Action frames */ |
a11241fa | 2061 | if (nl80211_register_action_frame(bss, (u8 *) "\x06", 1) < 0) |
6f06766e | 2062 | ret = -1; |
7b90c16a JM |
2063 | else |
2064 | drv->capa.key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FT | | |
2065 | WPA_DRIVER_CAPA_KEY_MGMT_FT_PSK; | |
2066 | ||
71269b37 | 2067 | /* WNM - BSS Transition Management Request */ |
a11241fa | 2068 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x07", 2) < 0) |
6f06766e | 2069 | ret = -1; |
bd896433 JM |
2070 | /* WNM-Sleep Mode Response */ |
2071 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x11", 2) < 0) | |
6f06766e | 2072 | ret = -1; |
a11241fa | 2073 | |
95a3ea94 JM |
2074 | #ifdef CONFIG_HS20 |
2075 | /* WNM-Notification */ | |
2076 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x1a", 2) < 0) | |
3ee18569 | 2077 | ret = -1; |
95a3ea94 JM |
2078 | #endif /* CONFIG_HS20 */ |
2079 | ||
dfa87878 MB |
2080 | /* WMM-AC ADDTS Response */ |
2081 | if (nl80211_register_action_frame(bss, (u8 *) "\x11\x01", 2) < 0) | |
730a0d16 | 2082 | ret = -1; |
dfa87878 MB |
2083 | |
2084 | /* WMM-AC DELTS */ | |
2085 | if (nl80211_register_action_frame(bss, (u8 *) "\x11\x02", 2) < 0) | |
730a0d16 | 2086 | ret = -1; |
dfa87878 | 2087 | |
2526ccd9 AK |
2088 | /* Radio Measurement - Neighbor Report Response */ |
2089 | if (nl80211_register_action_frame(bss, (u8 *) "\x05\x05", 2) < 0) | |
2090 | ret = -1; | |
2091 | ||
864b9522 DS |
2092 | /* Radio Measurement - Radio Measurement Request */ |
2093 | if (nl80211_register_action_frame(bss, (u8 *) "\x05\x00", 2) < 0) | |
2094 | ret = -1; | |
2095 | ||
7dc03388 AO |
2096 | /* Radio Measurement - Link Measurement Request */ |
2097 | if ((drv->capa.rrm_flags & WPA_DRIVER_FLAGS_TX_POWER_INSERTION) && | |
2098 | (nl80211_register_action_frame(bss, (u8 *) "\x05\x02", 2) < 0)) | |
2099 | ret = -1; | |
2100 | ||
5f65e9f7 JB |
2101 | nl80211_mgmt_handle_register_eloop(bss); |
2102 | ||
6f06766e | 2103 | return ret; |
a11241fa JB |
2104 | } |
2105 | ||
2106 | ||
afb0550a BC |
2107 | static int nl80211_mgmt_subscribe_mesh(struct i802_bss *bss) |
2108 | { | |
2109 | int ret = 0; | |
2110 | ||
2111 | if (nl80211_alloc_mgmt_handle(bss)) | |
2112 | return -1; | |
2113 | ||
2114 | wpa_printf(MSG_DEBUG, | |
2115 | "nl80211: Subscribe to mgmt frames with mesh handle %p", | |
2116 | bss->nl_mgmt); | |
2117 | ||
2118 | /* Auth frames for mesh SAE */ | |
2119 | if (nl80211_register_frame(bss, bss->nl_mgmt, | |
2120 | (WLAN_FC_TYPE_MGMT << 2) | | |
2121 | (WLAN_FC_STYPE_AUTH << 4), | |
2122 | NULL, 0) < 0) | |
2123 | ret = -1; | |
2124 | ||
2125 | /* Mesh peering open */ | |
2126 | if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x01", 2) < 0) | |
2127 | ret = -1; | |
2128 | /* Mesh peering confirm */ | |
2129 | if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x02", 2) < 0) | |
2130 | ret = -1; | |
2131 | /* Mesh peering close */ | |
2132 | if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x03", 2) < 0) | |
2133 | ret = -1; | |
2134 | ||
2135 | nl80211_mgmt_handle_register_eloop(bss); | |
2136 | ||
2137 | return ret; | |
2138 | } | |
2139 | ||
2140 | ||
02bb32c3 JB |
2141 | static int nl80211_register_spurious_class3(struct i802_bss *bss) |
2142 | { | |
02bb32c3 | 2143 | struct nl_msg *msg; |
a862e4a3 | 2144 | int ret; |
02bb32c3 | 2145 | |
13f83980 JM |
2146 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_UNEXPECTED_FRAME); |
2147 | ret = send_and_recv(bss->drv->global, bss->nl_mgmt, msg, NULL, NULL); | |
02bb32c3 JB |
2148 | if (ret) { |
2149 | wpa_printf(MSG_DEBUG, "nl80211: Register spurious class3 " | |
2150 | "failed: ret=%d (%s)", | |
2151 | ret, strerror(-ret)); | |
02bb32c3 | 2152 | } |
02bb32c3 JB |
2153 | return ret; |
2154 | } | |
2155 | ||
2156 | ||
4d916ed6 KV |
2157 | static int nl80211_action_subscribe_ap(struct i802_bss *bss) |
2158 | { | |
2159 | int ret = 0; | |
2160 | ||
2161 | /* Public Action frames */ | |
2162 | if (nl80211_register_action_frame(bss, (u8 *) "\x04", 1) < 0) | |
2163 | ret = -1; | |
2164 | /* RRM Measurement Report */ | |
2165 | if (nl80211_register_action_frame(bss, (u8 *) "\x05\x01", 2) < 0) | |
2166 | ret = -1; | |
e4ec6bbf JM |
2167 | /* RRM Link Measurement Report */ |
2168 | if (nl80211_register_action_frame(bss, (u8 *) "\x05\x03", 2) < 0) | |
2169 | ret = -1; | |
4d916ed6 KV |
2170 | /* RRM Neighbor Report Request */ |
2171 | if (nl80211_register_action_frame(bss, (u8 *) "\x05\x04", 2) < 0) | |
2172 | ret = -1; | |
2173 | /* FT Action frames */ | |
2174 | if (nl80211_register_action_frame(bss, (u8 *) "\x06", 1) < 0) | |
2175 | ret = -1; | |
2176 | #ifdef CONFIG_IEEE80211W | |
2177 | /* SA Query */ | |
2178 | if (nl80211_register_action_frame(bss, (u8 *) "\x08", 1) < 0) | |
2179 | ret = -1; | |
2180 | #endif /* CONFIG_IEEE80211W */ | |
2181 | /* Protected Dual of Public Action */ | |
2182 | if (nl80211_register_action_frame(bss, (u8 *) "\x09", 1) < 0) | |
2183 | ret = -1; | |
2184 | /* WNM */ | |
2185 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a", 1) < 0) | |
2186 | ret = -1; | |
2187 | /* WMM */ | |
2188 | if (nl80211_register_action_frame(bss, (u8 *) "\x11", 1) < 0) | |
2189 | ret = -1; | |
2190 | #ifdef CONFIG_FST | |
2191 | /* FST Action frames */ | |
2192 | if (nl80211_register_action_frame(bss, (u8 *) "\x12", 1) < 0) | |
2193 | ret = -1; | |
2194 | #endif /* CONFIG_FST */ | |
2195 | /* Vendor-specific */ | |
2196 | if (nl80211_register_action_frame(bss, (u8 *) "\x7f", 1) < 0) | |
2197 | ret = -1; | |
2198 | ||
2199 | return ret; | |
2200 | } | |
2201 | ||
2202 | ||
a11241fa JB |
2203 | static int nl80211_mgmt_subscribe_ap(struct i802_bss *bss) |
2204 | { | |
2205 | static const int stypes[] = { | |
2206 | WLAN_FC_STYPE_AUTH, | |
2207 | WLAN_FC_STYPE_ASSOC_REQ, | |
2208 | WLAN_FC_STYPE_REASSOC_REQ, | |
2209 | WLAN_FC_STYPE_DISASSOC, | |
2210 | WLAN_FC_STYPE_DEAUTH, | |
a11241fa JB |
2211 | WLAN_FC_STYPE_PROBE_REQ, |
2212 | /* Beacon doesn't work as mac80211 doesn't currently allow | |
2213 | * it, but it wouldn't really be the right thing anyway as | |
2214 | * it isn't per interface ... maybe just dump the scan | |
2215 | * results periodically for OLBC? | |
2216 | */ | |
0e80ea2c | 2217 | /* WLAN_FC_STYPE_BEACON, */ |
a11241fa JB |
2218 | }; |
2219 | unsigned int i; | |
2220 | ||
2221 | if (nl80211_alloc_mgmt_handle(bss)) | |
71269b37 | 2222 | return -1; |
36488c05 JM |
2223 | wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with AP " |
2224 | "handle %p", bss->nl_mgmt); | |
71269b37 | 2225 | |
e7ecab4a | 2226 | for (i = 0; i < ARRAY_SIZE(stypes); i++) { |
481234cf | 2227 | if (nl80211_register_frame(bss, bss->nl_mgmt, |
a11241fa JB |
2228 | (WLAN_FC_TYPE_MGMT << 2) | |
2229 | (stypes[i] << 4), | |
2230 | NULL, 0) < 0) { | |
2231 | goto out_err; | |
2232 | } | |
2233 | } | |
2234 | ||
4d916ed6 KV |
2235 | if (nl80211_action_subscribe_ap(bss)) |
2236 | goto out_err; | |
2237 | ||
02bb32c3 JB |
2238 | if (nl80211_register_spurious_class3(bss)) |
2239 | goto out_err; | |
2240 | ||
e32ad281 JB |
2241 | if (nl80211_get_wiphy_data_ap(bss) == NULL) |
2242 | goto out_err; | |
2243 | ||
5f65e9f7 | 2244 | nl80211_mgmt_handle_register_eloop(bss); |
58f6fbe0 | 2245 | return 0; |
a11241fa JB |
2246 | |
2247 | out_err: | |
a11241fa JB |
2248 | nl_destroy_handles(&bss->nl_mgmt); |
2249 | return -1; | |
2250 | } | |
2251 | ||
2252 | ||
a6cc0602 JM |
2253 | static int nl80211_mgmt_subscribe_ap_dev_sme(struct i802_bss *bss) |
2254 | { | |
2255 | if (nl80211_alloc_mgmt_handle(bss)) | |
2256 | return -1; | |
2257 | wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with AP " | |
2258 | "handle %p (device SME)", bss->nl_mgmt); | |
2259 | ||
4d916ed6 | 2260 | if (nl80211_action_subscribe_ap(bss)) |
a6cc0602 JM |
2261 | goto out_err; |
2262 | ||
5f65e9f7 | 2263 | nl80211_mgmt_handle_register_eloop(bss); |
a6cc0602 JM |
2264 | return 0; |
2265 | ||
2266 | out_err: | |
a6cc0602 JM |
2267 | nl_destroy_handles(&bss->nl_mgmt); |
2268 | return -1; | |
2269 | } | |
2270 | ||
2271 | ||
36488c05 | 2272 | static void nl80211_mgmt_unsubscribe(struct i802_bss *bss, const char *reason) |
a11241fa | 2273 | { |
481234cf | 2274 | if (bss->nl_mgmt == NULL) |
a11241fa | 2275 | return; |
36488c05 JM |
2276 | wpa_printf(MSG_DEBUG, "nl80211: Unsubscribe mgmt frames handle %p " |
2277 | "(%s)", bss->nl_mgmt, reason); | |
5f65e9f7 | 2278 | nl80211_destroy_eloop_handle(&bss->nl_mgmt); |
e32ad281 JB |
2279 | |
2280 | nl80211_put_wiphy_data_ap(bss); | |
58f6fbe0 JM |
2281 | } |
2282 | ||
2283 | ||
8401a6b0 JM |
2284 | static void wpa_driver_nl80211_send_rfkill(void *eloop_ctx, void *timeout_ctx) |
2285 | { | |
2286 | wpa_supplicant_event(timeout_ctx, EVENT_INTERFACE_DISABLED, NULL); | |
2287 | } | |
2288 | ||
2289 | ||
eb4582f2 AS |
2290 | static void nl80211_del_p2pdev(struct i802_bss *bss) |
2291 | { | |
eb4582f2 AS |
2292 | struct nl_msg *msg; |
2293 | int ret; | |
2294 | ||
a3249fdf JM |
2295 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_DEL_INTERFACE); |
2296 | ret = send_and_recv_msgs(bss->drv, msg, NULL, NULL); | |
eb4582f2 AS |
2297 | |
2298 | wpa_printf(MSG_DEBUG, "nl80211: Delete P2P Device %s (0x%llx): %s", | |
2299 | bss->ifname, (long long unsigned int) bss->wdev_id, | |
6cb4f11d | 2300 | strerror(-ret)); |
eb4582f2 AS |
2301 | } |
2302 | ||
2303 | ||
eb4582f2 | 2304 | static int nl80211_set_p2pdev(struct i802_bss *bss, int start) |
f632e483 | 2305 | { |
f632e483 | 2306 | struct nl_msg *msg; |
a862e4a3 | 2307 | int ret; |
f632e483 | 2308 | |
a3249fdf JM |
2309 | msg = nl80211_cmd_msg(bss, 0, start ? NL80211_CMD_START_P2P_DEVICE : |
2310 | NL80211_CMD_STOP_P2P_DEVICE); | |
2311 | ret = send_and_recv_msgs(bss->drv, msg, NULL, NULL); | |
f632e483 | 2312 | |
eb4582f2 AS |
2313 | wpa_printf(MSG_DEBUG, "nl80211: %s P2P Device %s (0x%llx): %s", |
2314 | start ? "Start" : "Stop", | |
2315 | bss->ifname, (long long unsigned int) bss->wdev_id, | |
6cb4f11d | 2316 | strerror(-ret)); |
f632e483 AS |
2317 | return ret; |
2318 | } | |
f632e483 AS |
2319 | |
2320 | ||
91724d6f AS |
2321 | static int i802_set_iface_flags(struct i802_bss *bss, int up) |
2322 | { | |
2323 | enum nl80211_iftype nlmode; | |
2324 | ||
2325 | nlmode = nl80211_get_ifmode(bss); | |
2326 | if (nlmode != NL80211_IFTYPE_P2P_DEVICE) { | |
2327 | return linux_set_iface_flags(bss->drv->global->ioctl_sock, | |
2328 | bss->ifname, up); | |
2329 | } | |
2330 | ||
2331 | /* P2P Device has start/stop which is equivalent */ | |
2332 | return nl80211_set_p2pdev(bss, up); | |
2333 | } | |
2334 | ||
2335 | ||
1db718b3 JM |
2336 | #ifdef CONFIG_TESTING_OPTIONS |
2337 | static int qca_vendor_test_cmd_handler(struct nl_msg *msg, void *arg) | |
2338 | { | |
2339 | /* struct wpa_driver_nl80211_data *drv = arg; */ | |
2340 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
2341 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
2342 | ||
2343 | ||
2344 | wpa_printf(MSG_DEBUG, | |
2345 | "nl80211: QCA vendor test command response received"); | |
2346 | ||
2347 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
2348 | genlmsg_attrlen(gnlh, 0), NULL); | |
2349 | if (!tb[NL80211_ATTR_VENDOR_DATA]) { | |
2350 | wpa_printf(MSG_DEBUG, "nl80211: No vendor data attribute"); | |
2351 | return NL_SKIP; | |
2352 | } | |
2353 | ||
2354 | wpa_hexdump(MSG_DEBUG, | |
2355 | "nl80211: Received QCA vendor test command response", | |
2356 | nla_data(tb[NL80211_ATTR_VENDOR_DATA]), | |
2357 | nla_len(tb[NL80211_ATTR_VENDOR_DATA])); | |
2358 | ||
2359 | return NL_SKIP; | |
2360 | } | |
2361 | #endif /* CONFIG_TESTING_OPTIONS */ | |
2362 | ||
2363 | ||
2364 | static void qca_vendor_test(struct wpa_driver_nl80211_data *drv) | |
2365 | { | |
2366 | #ifdef CONFIG_TESTING_OPTIONS | |
2367 | struct nl_msg *msg; | |
2368 | struct nlattr *params; | |
2369 | int ret; | |
2370 | ||
2371 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || | |
2372 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || | |
2373 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | |
2374 | QCA_NL80211_VENDOR_SUBCMD_TEST) || | |
2375 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || | |
2376 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TEST, 123)) { | |
2377 | nlmsg_free(msg); | |
2378 | return; | |
2379 | } | |
2380 | nla_nest_end(msg, params); | |
2381 | ||
2382 | ret = send_and_recv_msgs(drv, msg, qca_vendor_test_cmd_handler, drv); | |
2383 | wpa_printf(MSG_DEBUG, | |
2384 | "nl80211: QCA vendor test command returned %d (%s)", | |
2385 | ret, strerror(-ret)); | |
2386 | #endif /* CONFIG_TESTING_OPTIONS */ | |
2387 | } | |
2388 | ||
2389 | ||
362f781e | 2390 | static int |
0d547d5f | 2391 | wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data *drv, |
0ecff8d7 JM |
2392 | const u8 *set_addr, int first, |
2393 | const char *driver_params) | |
7524cfb1 | 2394 | { |
834ee56f | 2395 | struct i802_bss *bss = drv->first_bss; |
8401a6b0 | 2396 | int send_rfkill_event = 0; |
0d547d5f | 2397 | enum nl80211_iftype nlmode; |
a2e40bb6 FF |
2398 | |
2399 | drv->ifindex = if_nametoindex(bss->ifname); | |
f632e483 AS |
2400 | bss->ifindex = drv->ifindex; |
2401 | bss->wdev_id = drv->global->if_add_wdevid; | |
2402 | bss->wdev_id_set = drv->global->if_add_wdevid_set; | |
2403 | ||
60b13c20 IP |
2404 | bss->if_dynamic = drv->ifindex == drv->global->if_add_ifindex; |
2405 | bss->if_dynamic = bss->if_dynamic || drv->global->if_add_wdevid_set; | |
f632e483 AS |
2406 | drv->global->if_add_wdevid_set = 0; |
2407 | ||
bf144cf6 AP |
2408 | if (!bss->if_dynamic && nl80211_get_ifmode(bss) == NL80211_IFTYPE_AP) |
2409 | bss->static_ap = 1; | |
2410 | ||
ef3866ab IP |
2411 | if (first && |
2412 | nl80211_get_ifmode(bss) != NL80211_IFTYPE_P2P_DEVICE && | |
2413 | linux_iface_up(drv->global->ioctl_sock, bss->ifname) > 0) | |
2414 | drv->start_iface_up = 1; | |
2415 | ||
f632e483 AS |
2416 | if (wpa_driver_nl80211_capa(drv)) |
2417 | return -1; | |
a87c9d96 | 2418 | |
0ecff8d7 JM |
2419 | if (driver_params && nl80211_set_param(bss, driver_params) < 0) |
2420 | return -1; | |
2421 | ||
5fbcb45d AS |
2422 | wpa_printf(MSG_DEBUG, "nl80211: interface %s in phy %s", |
2423 | bss->ifname, drv->phyname); | |
2424 | ||
0d547d5f JM |
2425 | if (set_addr && |
2426 | (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 0) || | |
2427 | linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname, | |
2428 | set_addr))) | |
2429 | return -1; | |
2430 | ||
49b4b205 JM |
2431 | if (first && nl80211_get_ifmode(bss) == NL80211_IFTYPE_AP) |
2432 | drv->start_mode_ap = 1; | |
2433 | ||
bf144cf6 | 2434 | if (drv->hostapd || bss->static_ap) |
0d547d5f | 2435 | nlmode = NL80211_IFTYPE_AP; |
4fe726e2 FF |
2436 | else if (bss->if_dynamic || |
2437 | nl80211_get_ifmode(bss) == NL80211_IFTYPE_MESH_POINT) | |
8e12685c | 2438 | nlmode = nl80211_get_ifmode(bss); |
0d547d5f JM |
2439 | else |
2440 | nlmode = NL80211_IFTYPE_STATION; | |
f632e483 | 2441 | |
8e12685c | 2442 | if (wpa_driver_nl80211_set_mode(bss, nlmode) < 0) { |
0d547d5f | 2443 | wpa_printf(MSG_ERROR, "nl80211: Could not configure driver mode"); |
8e12685c | 2444 | return -1; |
a87c9d96 JM |
2445 | } |
2446 | ||
8c06db70 | 2447 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) |
597b94f5 | 2448 | nl80211_get_macaddr(bss); |
f632e483 | 2449 | |
0e92fb8f JB |
2450 | wpa_driver_nl80211_drv_init_rfkill(drv); |
2451 | ||
8c06db70 MB |
2452 | if (!rfkill_is_blocked(drv->rfkill)) { |
2453 | int ret = i802_set_iface_flags(bss, 1); | |
2454 | if (ret) { | |
8401a6b0 JM |
2455 | wpa_printf(MSG_ERROR, "nl80211: Could not set " |
2456 | "interface '%s' UP", bss->ifname); | |
8c06db70 | 2457 | return ret; |
8401a6b0 | 2458 | } |
e8dc205f AO |
2459 | |
2460 | if (is_p2p_net_interface(nlmode)) | |
2461 | nl80211_disable_11b_rates(bss->drv, | |
2462 | bss->drv->ifindex, 1); | |
2463 | ||
8c06db70 MB |
2464 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) |
2465 | return ret; | |
2466 | } else { | |
2467 | wpa_printf(MSG_DEBUG, "nl80211: Could not yet enable " | |
2468 | "interface '%s' due to rfkill", bss->ifname); | |
6da504a1 IP |
2469 | if (nlmode != NL80211_IFTYPE_P2P_DEVICE) |
2470 | drv->if_disabled = 1; | |
2471 | ||
8c06db70 | 2472 | send_rfkill_event = 1; |
362f781e | 2473 | } |
3f5285e8 | 2474 | |
6da504a1 | 2475 | if (!drv->hostapd && nlmode != NL80211_IFTYPE_P2P_DEVICE) |
0d547d5f JM |
2476 | netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, |
2477 | 1, IF_OPER_DORMANT); | |
362f781e | 2478 | |
6da504a1 IP |
2479 | if (nlmode != NL80211_IFTYPE_P2P_DEVICE) { |
2480 | if (linux_get_ifhwaddr(drv->global->ioctl_sock, bss->ifname, | |
2481 | bss->addr)) | |
2482 | return -1; | |
2483 | os_memcpy(drv->perm_addr, bss->addr, ETH_ALEN); | |
2484 | } | |
f2ed8023 | 2485 | |
8401a6b0 JM |
2486 | if (send_rfkill_event) { |
2487 | eloop_register_timeout(0, 0, wpa_driver_nl80211_send_rfkill, | |
2488 | drv, drv->ctx); | |
2489 | } | |
2490 | ||
1db718b3 JM |
2491 | if (drv->vendor_cmd_test_avail) |
2492 | qca_vendor_test(drv); | |
2493 | ||
362f781e | 2494 | return 0; |
3f5285e8 JM |
2495 | } |
2496 | ||
2497 | ||
8a27af5c JM |
2498 | static int wpa_driver_nl80211_del_beacon(struct wpa_driver_nl80211_data *drv) |
2499 | { | |
2500 | struct nl_msg *msg; | |
2501 | ||
08e55ebb JM |
2502 | wpa_printf(MSG_DEBUG, "nl80211: Remove beacon (ifindex=%d)", |
2503 | drv->ifindex); | |
9725b784 | 2504 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_DEL_BEACON); |
8a27af5c | 2505 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
8a27af5c | 2506 | } |
8a27af5c JM |
2507 | |
2508 | ||
3f5285e8 | 2509 | /** |
7e5ba1b9 | 2510 | * wpa_driver_nl80211_deinit - Deinitialize nl80211 driver interface |
9ebce9c5 | 2511 | * @bss: Pointer to private nl80211 data from wpa_driver_nl80211_init() |
3f5285e8 JM |
2512 | * |
2513 | * Shut down driver interface and processing of driver events. Free | |
2514 | * private data buffer if one was allocated in wpa_driver_nl80211_init(). | |
2515 | */ | |
9ebce9c5 | 2516 | static void wpa_driver_nl80211_deinit(struct i802_bss *bss) |
3f5285e8 | 2517 | { |
a2e40bb6 | 2518 | struct wpa_driver_nl80211_data *drv = bss->drv; |
cc9a2575 | 2519 | unsigned int i; |
3f5285e8 | 2520 | |
3e208481 JM |
2521 | wpa_printf(MSG_INFO, "nl80211: deinit ifname=%s disabled_11b_rates=%d", |
2522 | bss->ifname, drv->disabled_11b_rates); | |
2523 | ||
873d0fcf | 2524 | bss->in_deinit = 1; |
32ab4855 JB |
2525 | if (drv->data_tx_status) |
2526 | eloop_unregister_read_sock(drv->eapol_tx_sock); | |
d12dab4c JB |
2527 | if (drv->eapol_tx_sock >= 0) |
2528 | close(drv->eapol_tx_sock); | |
f10bfc9a | 2529 | |
481234cf | 2530 | if (bss->nl_preq) |
5582a5d1 | 2531 | wpa_driver_nl80211_probe_req_report(bss, 0); |
e17a2477 | 2532 | if (bss->added_if_into_bridge) { |
c81eff1a BG |
2533 | if (linux_br_del_if(drv->global->ioctl_sock, bss->brname, |
2534 | bss->ifname) < 0) | |
94627f6c JM |
2535 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
2536 | "interface %s from bridge %s: %s", | |
e17a2477 | 2537 | bss->ifname, bss->brname, strerror(errno)); |
97ed9a06 | 2538 | if (drv->rtnl_sk) |
ca3c6b4d | 2539 | nl80211_handle_destroy(drv->rtnl_sk); |
94627f6c | 2540 | } |
e17a2477 | 2541 | if (bss->added_bridge) { |
f2535da8 JM |
2542 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->brname, |
2543 | 0) < 0) | |
2544 | wpa_printf(MSG_INFO, | |
2545 | "nl80211: Could not set bridge %s down", | |
2546 | bss->brname); | |
c81eff1a | 2547 | if (linux_br_del(drv->global->ioctl_sock, bss->brname) < 0) |
94627f6c JM |
2548 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
2549 | "bridge %s: %s", | |
e17a2477 | 2550 | bss->brname, strerror(errno)); |
94627f6c JM |
2551 | } |
2552 | ||
460456f8 | 2553 | nl80211_remove_monitor_interface(drv); |
8a27af5c | 2554 | |
b1f625e0 | 2555 | if (is_ap_interface(drv->nlmode)) |
8a27af5c | 2556 | wpa_driver_nl80211_del_beacon(drv); |
0915d02c | 2557 | |
bbaf0837 JM |
2558 | if (drv->eapol_sock >= 0) { |
2559 | eloop_unregister_read_sock(drv->eapol_sock); | |
2560 | close(drv->eapol_sock); | |
2561 | } | |
2562 | ||
2563 | if (drv->if_indices != drv->default_if_indices) | |
2564 | os_free(drv->if_indices); | |
3f5285e8 | 2565 | |
732b1d20 MB |
2566 | if (drv->if_indices_reason != drv->default_if_indices_reason) |
2567 | os_free(drv->if_indices_reason); | |
2568 | ||
b3af99d2 | 2569 | if (drv->disabled_11b_rates) |
4e5cb1a3 JM |
2570 | nl80211_disable_11b_rates(drv, drv->ifindex, 0); |
2571 | ||
36d84860 BG |
2572 | netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, 0, |
2573 | IF_OPER_UP); | |
e390df05 | 2574 | eloop_cancel_timeout(wpa_driver_nl80211_send_rfkill, drv, drv->ctx); |
8401a6b0 | 2575 | rfkill_deinit(drv->rfkill); |
3f5285e8 | 2576 | |
bbaf0837 JM |
2577 | eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout, drv, drv->ctx); |
2578 | ||
146fa9b3 JM |
2579 | if (!drv->start_iface_up) |
2580 | (void) i802_set_iface_flags(bss, 0); | |
fee354c7 JM |
2581 | |
2582 | if (drv->addr_changed) { | |
93da0498 JM |
2583 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, |
2584 | 0) < 0) { | |
2585 | wpa_printf(MSG_DEBUG, | |
2586 | "nl80211: Could not set interface down to restore permanent MAC address"); | |
2587 | } | |
fee354c7 JM |
2588 | if (linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
2589 | drv->perm_addr) < 0) { | |
2590 | wpa_printf(MSG_DEBUG, | |
2591 | "nl80211: Could not restore permanent MAC address"); | |
2592 | } | |
2593 | } | |
2594 | ||
8e12685c | 2595 | if (drv->nlmode != NL80211_IFTYPE_P2P_DEVICE) { |
49b4b205 JM |
2596 | if (!drv->hostapd || !drv->start_mode_ap) |
2597 | wpa_driver_nl80211_set_mode(bss, | |
2598 | NL80211_IFTYPE_STATION); | |
b378c41f | 2599 | nl80211_mgmt_unsubscribe(bss, "deinit"); |
8e12685c AS |
2600 | } else { |
2601 | nl80211_mgmt_unsubscribe(bss, "deinit"); | |
eb4582f2 | 2602 | nl80211_del_p2pdev(bss); |
8e12685c | 2603 | } |
3f5285e8 | 2604 | |
834ee56f | 2605 | nl80211_destroy_bss(drv->first_bss); |
cc7a48d1 | 2606 | |
3812464c JM |
2607 | os_free(drv->filter_ssids); |
2608 | ||
536fd62d JM |
2609 | os_free(drv->auth_ie); |
2610 | ||
dac12351 | 2611 | if (drv->in_interface_list) |
f2ed8023 JM |
2612 | dl_list_del(&drv->list); |
2613 | ||
8cd6b7bc JB |
2614 | os_free(drv->extended_capa); |
2615 | os_free(drv->extended_capa_mask); | |
cc9a2575 KV |
2616 | for (i = 0; i < drv->num_iface_ext_capa; i++) { |
2617 | os_free(drv->iface_ext_capa[i].ext_capa); | |
2618 | os_free(drv->iface_ext_capa[i].ext_capa_mask); | |
2619 | } | |
834ee56f | 2620 | os_free(drv->first_bss); |
3f5285e8 JM |
2621 | os_free(drv); |
2622 | } | |
2623 | ||
2624 | ||
de4ed4a8 JM |
2625 | static u32 wpa_alg_to_cipher_suite(enum wpa_alg alg, size_t key_len) |
2626 | { | |
2627 | switch (alg) { | |
2628 | case WPA_ALG_WEP: | |
2629 | if (key_len == 5) | |
2630 | return WLAN_CIPHER_SUITE_WEP40; | |
2631 | return WLAN_CIPHER_SUITE_WEP104; | |
2632 | case WPA_ALG_TKIP: | |
2633 | return WLAN_CIPHER_SUITE_TKIP; | |
2634 | case WPA_ALG_CCMP: | |
2635 | return WLAN_CIPHER_SUITE_CCMP; | |
2636 | case WPA_ALG_GCMP: | |
2637 | return WLAN_CIPHER_SUITE_GCMP; | |
2638 | case WPA_ALG_CCMP_256: | |
2639 | return WLAN_CIPHER_SUITE_CCMP_256; | |
2640 | case WPA_ALG_GCMP_256: | |
2641 | return WLAN_CIPHER_SUITE_GCMP_256; | |
2642 | case WPA_ALG_IGTK: | |
2643 | return WLAN_CIPHER_SUITE_AES_CMAC; | |
2644 | case WPA_ALG_BIP_GMAC_128: | |
2645 | return WLAN_CIPHER_SUITE_BIP_GMAC_128; | |
2646 | case WPA_ALG_BIP_GMAC_256: | |
2647 | return WLAN_CIPHER_SUITE_BIP_GMAC_256; | |
2648 | case WPA_ALG_BIP_CMAC_256: | |
2649 | return WLAN_CIPHER_SUITE_BIP_CMAC_256; | |
2650 | case WPA_ALG_SMS4: | |
2651 | return WLAN_CIPHER_SUITE_SMS4; | |
2652 | case WPA_ALG_KRK: | |
2653 | return WLAN_CIPHER_SUITE_KRK; | |
2654 | case WPA_ALG_NONE: | |
2655 | case WPA_ALG_PMK: | |
2656 | wpa_printf(MSG_ERROR, "nl80211: Unexpected encryption algorithm %d", | |
2657 | alg); | |
2658 | return 0; | |
2659 | } | |
2660 | ||
2661 | wpa_printf(MSG_ERROR, "nl80211: Unsupported encryption algorithm %d", | |
2662 | alg); | |
2663 | return 0; | |
2664 | } | |
2665 | ||
2666 | ||
2667 | static u32 wpa_cipher_to_cipher_suite(unsigned int cipher) | |
2668 | { | |
2669 | switch (cipher) { | |
2670 | case WPA_CIPHER_CCMP_256: | |
2671 | return WLAN_CIPHER_SUITE_CCMP_256; | |
2672 | case WPA_CIPHER_GCMP_256: | |
2673 | return WLAN_CIPHER_SUITE_GCMP_256; | |
2674 | case WPA_CIPHER_CCMP: | |
2675 | return WLAN_CIPHER_SUITE_CCMP; | |
2676 | case WPA_CIPHER_GCMP: | |
2677 | return WLAN_CIPHER_SUITE_GCMP; | |
2678 | case WPA_CIPHER_TKIP: | |
2679 | return WLAN_CIPHER_SUITE_TKIP; | |
2680 | case WPA_CIPHER_WEP104: | |
2681 | return WLAN_CIPHER_SUITE_WEP104; | |
2682 | case WPA_CIPHER_WEP40: | |
2683 | return WLAN_CIPHER_SUITE_WEP40; | |
ae6f9272 JM |
2684 | case WPA_CIPHER_GTK_NOT_USED: |
2685 | return WLAN_CIPHER_SUITE_NO_GROUP_ADDR; | |
de4ed4a8 JM |
2686 | } |
2687 | ||
2688 | return 0; | |
2689 | } | |
2690 | ||
2691 | ||
2692 | static int wpa_cipher_to_cipher_suites(unsigned int ciphers, u32 suites[], | |
2693 | int max_suites) | |
2694 | { | |
2695 | int num_suites = 0; | |
2696 | ||
2697 | if (num_suites < max_suites && ciphers & WPA_CIPHER_CCMP_256) | |
2698 | suites[num_suites++] = WLAN_CIPHER_SUITE_CCMP_256; | |
2699 | if (num_suites < max_suites && ciphers & WPA_CIPHER_GCMP_256) | |
2700 | suites[num_suites++] = WLAN_CIPHER_SUITE_GCMP_256; | |
2701 | if (num_suites < max_suites && ciphers & WPA_CIPHER_CCMP) | |
2702 | suites[num_suites++] = WLAN_CIPHER_SUITE_CCMP; | |
2703 | if (num_suites < max_suites && ciphers & WPA_CIPHER_GCMP) | |
2704 | suites[num_suites++] = WLAN_CIPHER_SUITE_GCMP; | |
2705 | if (num_suites < max_suites && ciphers & WPA_CIPHER_TKIP) | |
2706 | suites[num_suites++] = WLAN_CIPHER_SUITE_TKIP; | |
2707 | if (num_suites < max_suites && ciphers & WPA_CIPHER_WEP104) | |
2708 | suites[num_suites++] = WLAN_CIPHER_SUITE_WEP104; | |
2709 | if (num_suites < max_suites && ciphers & WPA_CIPHER_WEP40) | |
2710 | suites[num_suites++] = WLAN_CIPHER_SUITE_WEP40; | |
2711 | ||
2712 | return num_suites; | |
2713 | } | |
2714 | ||
2715 | ||
b658547d | 2716 | #ifdef CONFIG_DRIVER_NL80211_QCA |
b41f2684 CL |
2717 | static int issue_key_mgmt_set_key(struct wpa_driver_nl80211_data *drv, |
2718 | const u8 *key, size_t key_len) | |
2719 | { | |
2720 | struct nl_msg *msg; | |
a862e4a3 | 2721 | int ret; |
b41f2684 | 2722 | |
15badebd | 2723 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD)) |
b41f2684 CL |
2724 | return 0; |
2725 | ||
9725b784 | 2726 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
a862e4a3 JM |
2727 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
2728 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | |
2729 | QCA_NL80211_VENDOR_SUBCMD_KEY_MGMT_SET_KEY) || | |
2730 | nla_put(msg, NL80211_ATTR_VENDOR_DATA, key_len, key)) { | |
bbd89bfc | 2731 | nl80211_nlmsg_clear(msg); |
a862e4a3 JM |
2732 | nlmsg_free(msg); |
2733 | return -1; | |
2734 | } | |
bbd89bfc | 2735 | ret = send_and_recv_msgs(drv, msg, NULL, (void *) -1); |
b41f2684 CL |
2736 | if (ret) { |
2737 | wpa_printf(MSG_DEBUG, | |
2738 | "nl80211: Key management set key failed: ret=%d (%s)", | |
2739 | ret, strerror(-ret)); | |
2740 | } | |
2741 | ||
b41f2684 CL |
2742 | return ret; |
2743 | } | |
b658547d | 2744 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
b41f2684 CL |
2745 | |
2746 | ||
9ebce9c5 | 2747 | static int wpa_driver_nl80211_set_key(const char *ifname, struct i802_bss *bss, |
71934751 JM |
2748 | enum wpa_alg alg, const u8 *addr, |
2749 | int key_idx, int set_tx, | |
642187d6 JM |
2750 | const u8 *seq, size_t seq_len, |
2751 | const u8 *key, size_t key_len) | |
3f5285e8 | 2752 | { |
a2e40bb6 | 2753 | struct wpa_driver_nl80211_data *drv = bss->drv; |
e472e1b4 | 2754 | int ifindex; |
34651767 | 2755 | struct nl_msg *msg = NULL; |
1ad1cdc2 | 2756 | int ret; |
dc01de8a | 2757 | int tdls = 0; |
3f5285e8 | 2758 | |
e472e1b4 AS |
2759 | /* Ignore for P2P Device */ |
2760 | if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) | |
2761 | return 0; | |
2762 | ||
2763 | ifindex = if_nametoindex(ifname); | |
8393e1a0 | 2764 | wpa_printf(MSG_DEBUG, "%s: ifindex=%d (%s) alg=%d addr=%p key_idx=%d " |
1ad1cdc2 | 2765 | "set_tx=%d seq_len=%lu key_len=%lu", |
8393e1a0 | 2766 | __func__, ifindex, ifname, alg, addr, key_idx, set_tx, |
3f5285e8 | 2767 | (unsigned long) seq_len, (unsigned long) key_len); |
8c66e185 | 2768 | #ifdef CONFIG_TDLS |
dc01de8a | 2769 | if (key_idx == -1) { |
8c66e185 | 2770 | key_idx = 0; |
dc01de8a JM |
2771 | tdls = 1; |
2772 | } | |
8c66e185 | 2773 | #endif /* CONFIG_TDLS */ |
3f5285e8 | 2774 | |
b658547d | 2775 | #ifdef CONFIG_DRIVER_NL80211_QCA |
15badebd CL |
2776 | if (alg == WPA_ALG_PMK && |
2777 | (drv->capa.flags & WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD)) { | |
b41f2684 CL |
2778 | wpa_printf(MSG_DEBUG, "%s: calling issue_key_mgmt_set_key", |
2779 | __func__); | |
2780 | ret = issue_key_mgmt_set_key(drv, key, key_len); | |
2781 | return ret; | |
2782 | } | |
b658547d | 2783 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
b41f2684 | 2784 | |
3f5285e8 | 2785 | if (alg == WPA_ALG_NONE) { |
95376e1a JM |
2786 | msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_DEL_KEY); |
2787 | if (!msg) | |
2788 | return -ENOBUFS; | |
3f5285e8 | 2789 | } else { |
34651767 JM |
2790 | u32 suite; |
2791 | ||
2792 | suite = wpa_alg_to_cipher_suite(alg, key_len); | |
2793 | if (!suite) | |
2794 | goto fail; | |
95376e1a JM |
2795 | msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_NEW_KEY); |
2796 | if (!msg || | |
a862e4a3 | 2797 | nla_put(msg, NL80211_ATTR_KEY_DATA, key_len, key) || |
34651767 | 2798 | nla_put_u32(msg, NL80211_ATTR_KEY_CIPHER, suite)) |
a862e4a3 | 2799 | goto fail; |
e6ef73f1 | 2800 | wpa_hexdump_key(MSG_DEBUG, "nl80211: KEY_DATA", key, key_len); |
3f5285e8 JM |
2801 | } |
2802 | ||
e6ef73f1 | 2803 | if (seq && seq_len) { |
a862e4a3 JM |
2804 | if (nla_put(msg, NL80211_ATTR_KEY_SEQ, seq_len, seq)) |
2805 | goto fail; | |
e6ef73f1 JM |
2806 | wpa_hexdump(MSG_DEBUG, "nl80211: KEY_SEQ", seq, seq_len); |
2807 | } | |
1ad1cdc2 | 2808 | |
0382097e | 2809 | if (addr && !is_broadcast_ether_addr(addr)) { |
3f5285e8 | 2810 | wpa_printf(MSG_DEBUG, " addr=" MACSTR, MAC2STR(addr)); |
a862e4a3 JM |
2811 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
2812 | goto fail; | |
89c38e32 JM |
2813 | |
2814 | if (alg != WPA_ALG_WEP && key_idx && !set_tx) { | |
2815 | wpa_printf(MSG_DEBUG, " RSN IBSS RX GTK"); | |
a862e4a3 JM |
2816 | if (nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, |
2817 | NL80211_KEYTYPE_GROUP)) | |
2818 | goto fail; | |
89c38e32 | 2819 | } |
60ea8187 | 2820 | } else if (addr && is_broadcast_ether_addr(addr)) { |
8970bae8 JB |
2821 | struct nlattr *types; |
2822 | ||
60ea8187 | 2823 | wpa_printf(MSG_DEBUG, " broadcast key"); |
8970bae8 JB |
2824 | |
2825 | types = nla_nest_start(msg, NL80211_ATTR_KEY_DEFAULT_TYPES); | |
a862e4a3 JM |
2826 | if (!types || |
2827 | nla_put_flag(msg, NL80211_KEY_DEFAULT_TYPE_MULTICAST)) | |
2828 | goto fail; | |
8970bae8 | 2829 | nla_nest_end(msg, types); |
3f5285e8 | 2830 | } |
95376e1a | 2831 | if (nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) |
a862e4a3 | 2832 | goto fail; |
3f5285e8 | 2833 | |
bbd89bfc | 2834 | ret = send_and_recv_msgs(drv, msg, NULL, key ? (void *) -1 : NULL); |
15664ad0 | 2835 | if ((ret == -ENOENT || ret == -ENOLINK) && alg == WPA_ALG_NONE) |
1ad1cdc2 JM |
2836 | ret = 0; |
2837 | if (ret) | |
2838 | wpa_printf(MSG_DEBUG, "nl80211: set_key failed; err=%d %s)", | |
2839 | ret, strerror(-ret)); | |
3f5285e8 | 2840 | |
1ad1cdc2 JM |
2841 | /* |
2842 | * If we failed or don't need to set the default TX key (below), | |
2843 | * we're done here. | |
2844 | */ | |
dc01de8a | 2845 | if (ret || !set_tx || alg == WPA_ALG_NONE || tdls) |
1ad1cdc2 | 2846 | return ret; |
b1f625e0 | 2847 | if (is_ap_interface(drv->nlmode) && addr && |
0382097e | 2848 | !is_broadcast_ether_addr(addr)) |
de12717a | 2849 | return ret; |
3f5285e8 | 2850 | |
95376e1a JM |
2851 | msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_SET_KEY); |
2852 | if (!msg || | |
a862e4a3 | 2853 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx) || |
86f9b1c7 JM |
2854 | nla_put_flag(msg, (alg == WPA_ALG_IGTK || |
2855 | alg == WPA_ALG_BIP_GMAC_128 || | |
2856 | alg == WPA_ALG_BIP_GMAC_256 || | |
2857 | alg == WPA_ALG_BIP_CMAC_256) ? | |
a862e4a3 JM |
2858 | NL80211_ATTR_KEY_DEFAULT_MGMT : |
2859 | NL80211_ATTR_KEY_DEFAULT)) | |
2860 | goto fail; | |
60ea8187 | 2861 | if (addr && is_broadcast_ether_addr(addr)) { |
8970bae8 JB |
2862 | struct nlattr *types; |
2863 | ||
2864 | types = nla_nest_start(msg, NL80211_ATTR_KEY_DEFAULT_TYPES); | |
a862e4a3 JM |
2865 | if (!types || |
2866 | nla_put_flag(msg, NL80211_KEY_DEFAULT_TYPE_MULTICAST)) | |
2867 | goto fail; | |
8970bae8 | 2868 | nla_nest_end(msg, types); |
60ea8187 | 2869 | } else if (addr) { |
8970bae8 JB |
2870 | struct nlattr *types; |
2871 | ||
2872 | types = nla_nest_start(msg, NL80211_ATTR_KEY_DEFAULT_TYPES); | |
a862e4a3 JM |
2873 | if (!types || |
2874 | nla_put_flag(msg, NL80211_KEY_DEFAULT_TYPE_UNICAST)) | |
2875 | goto fail; | |
8970bae8 | 2876 | nla_nest_end(msg, types); |
60ea8187 | 2877 | } |
3f5285e8 | 2878 | |
1ad1cdc2 JM |
2879 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
2880 | if (ret == -ENOENT) | |
2881 | ret = 0; | |
2882 | if (ret) | |
2883 | wpa_printf(MSG_DEBUG, "nl80211: set_key default failed; " | |
2884 | "err=%d %s)", ret, strerror(-ret)); | |
2885 | return ret; | |
3f5285e8 | 2886 | |
a862e4a3 | 2887 | fail: |
bbd89bfc | 2888 | nl80211_nlmsg_clear(msg); |
5883168a | 2889 | nlmsg_free(msg); |
6241fcb1 | 2890 | return -ENOBUFS; |
3f5285e8 JM |
2891 | } |
2892 | ||
2893 | ||
71934751 | 2894 | static int nl_add_key(struct nl_msg *msg, enum wpa_alg alg, |
0194fedb JB |
2895 | int key_idx, int defkey, |
2896 | const u8 *seq, size_t seq_len, | |
2897 | const u8 *key, size_t key_len) | |
2898 | { | |
2899 | struct nlattr *key_attr = nla_nest_start(msg, NL80211_ATTR_KEY); | |
34651767 JM |
2900 | u32 suite; |
2901 | ||
0194fedb JB |
2902 | if (!key_attr) |
2903 | return -1; | |
2904 | ||
34651767 JM |
2905 | suite = wpa_alg_to_cipher_suite(alg, key_len); |
2906 | if (!suite) | |
2907 | return -1; | |
2908 | ||
a862e4a3 JM |
2909 | if (defkey && alg == WPA_ALG_IGTK) { |
2910 | if (nla_put_flag(msg, NL80211_KEY_DEFAULT_MGMT)) | |
2911 | return -1; | |
2912 | } else if (defkey) { | |
2913 | if (nla_put_flag(msg, NL80211_KEY_DEFAULT)) | |
2914 | return -1; | |
2915 | } | |
0194fedb | 2916 | |
a862e4a3 | 2917 | if (nla_put_u8(msg, NL80211_KEY_IDX, key_idx) || |
34651767 | 2918 | nla_put_u32(msg, NL80211_KEY_CIPHER, suite) || |
a862e4a3 JM |
2919 | (seq && seq_len && |
2920 | nla_put(msg, NL80211_KEY_SEQ, seq_len, seq)) || | |
2921 | nla_put(msg, NL80211_KEY_DATA, key_len, key)) | |
2922 | return -1; | |
0194fedb JB |
2923 | |
2924 | nla_nest_end(msg, key_attr); | |
2925 | ||
2926 | return 0; | |
0194fedb JB |
2927 | } |
2928 | ||
c811d5bc | 2929 | |
cfaab580 ZY |
2930 | static int nl80211_set_conn_keys(struct wpa_driver_associate_params *params, |
2931 | struct nl_msg *msg) | |
2932 | { | |
2933 | int i, privacy = 0; | |
2934 | struct nlattr *nl_keys, *nl_key; | |
2935 | ||
2936 | for (i = 0; i < 4; i++) { | |
2937 | if (!params->wep_key[i]) | |
2938 | continue; | |
2939 | privacy = 1; | |
2940 | break; | |
2941 | } | |
ce04af5a JM |
2942 | if (params->wps == WPS_MODE_PRIVACY) |
2943 | privacy = 1; | |
2944 | if (params->pairwise_suite && | |
2945 | params->pairwise_suite != WPA_CIPHER_NONE) | |
2946 | privacy = 1; | |
2947 | ||
cfaab580 ZY |
2948 | if (!privacy) |
2949 | return 0; | |
2950 | ||
a862e4a3 JM |
2951 | if (nla_put_flag(msg, NL80211_ATTR_PRIVACY)) |
2952 | return -ENOBUFS; | |
cfaab580 ZY |
2953 | |
2954 | nl_keys = nla_nest_start(msg, NL80211_ATTR_KEYS); | |
2955 | if (!nl_keys) | |
a862e4a3 | 2956 | return -ENOBUFS; |
cfaab580 ZY |
2957 | |
2958 | for (i = 0; i < 4; i++) { | |
2959 | if (!params->wep_key[i]) | |
2960 | continue; | |
2961 | ||
2962 | nl_key = nla_nest_start(msg, i); | |
a862e4a3 JM |
2963 | if (!nl_key || |
2964 | nla_put(msg, NL80211_KEY_DATA, params->wep_key_len[i], | |
2965 | params->wep_key[i]) || | |
2966 | nla_put_u32(msg, NL80211_KEY_CIPHER, | |
2967 | params->wep_key_len[i] == 5 ? | |
2968 | WLAN_CIPHER_SUITE_WEP40 : | |
2969 | WLAN_CIPHER_SUITE_WEP104) || | |
2970 | nla_put_u8(msg, NL80211_KEY_IDX, i) || | |
2971 | (i == params->wep_tx_keyidx && | |
2972 | nla_put_flag(msg, NL80211_KEY_DEFAULT))) | |
2973 | return -ENOBUFS; | |
cfaab580 ZY |
2974 | |
2975 | nla_nest_end(msg, nl_key); | |
2976 | } | |
2977 | nla_nest_end(msg, nl_keys); | |
2978 | ||
2979 | return 0; | |
cfaab580 ZY |
2980 | } |
2981 | ||
2982 | ||
477af8f8 JM |
2983 | int wpa_driver_nl80211_mlme(struct wpa_driver_nl80211_data *drv, |
2984 | const u8 *addr, int cmd, u16 reason_code, | |
2985 | int local_state_change) | |
c2a04078 | 2986 | { |
a862e4a3 | 2987 | int ret; |
c2a04078 JM |
2988 | struct nl_msg *msg; |
2989 | ||
9725b784 | 2990 | if (!(msg = nl80211_drv_msg(drv, 0, cmd)) || |
a862e4a3 JM |
2991 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code) || |
2992 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || | |
2993 | (local_state_change && | |
2994 | nla_put_flag(msg, NL80211_ATTR_LOCAL_STATE_CHANGE))) { | |
2995 | nlmsg_free(msg); | |
2996 | return -1; | |
2997 | } | |
c2a04078 JM |
2998 | |
2999 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
c2a04078 | 3000 | if (ret) { |
3b7ea880 BG |
3001 | wpa_dbg(drv->ctx, MSG_DEBUG, |
3002 | "nl80211: MLME command failed: reason=%u ret=%d (%s)", | |
3003 | reason_code, ret, strerror(-ret)); | |
c2a04078 | 3004 | } |
c2a04078 JM |
3005 | return ret; |
3006 | } | |
3f5285e8 JM |
3007 | |
3008 | ||
cfaab580 | 3009 | static int wpa_driver_nl80211_disconnect(struct wpa_driver_nl80211_data *drv, |
817762d9 | 3010 | int reason_code) |
cfaab580 | 3011 | { |
3f53c006 JJ |
3012 | int ret; |
3013 | ||
817762d9 | 3014 | wpa_printf(MSG_DEBUG, "%s(reason_code=%d)", __func__, reason_code); |
add9b7a4 | 3015 | nl80211_mark_disconnected(drv); |
817762d9 | 3016 | /* Disconnect command doesn't need BSSID - it uses cached value */ |
3f53c006 JJ |
3017 | ret = wpa_driver_nl80211_mlme(drv, NULL, NL80211_CMD_DISCONNECT, |
3018 | reason_code, 0); | |
3019 | /* | |
3020 | * For locally generated disconnect, supplicant already generates a | |
3021 | * DEAUTH event, so ignore the event from NL80211. | |
3022 | */ | |
3023 | drv->ignore_next_local_disconnect = ret == 0; | |
3024 | ||
3025 | return ret; | |
cfaab580 ZY |
3026 | } |
3027 | ||
3028 | ||
9ebce9c5 JM |
3029 | static int wpa_driver_nl80211_deauthenticate(struct i802_bss *bss, |
3030 | const u8 *addr, int reason_code) | |
3f5285e8 | 3031 | { |
a2e40bb6 | 3032 | struct wpa_driver_nl80211_data *drv = bss->drv; |
d6a36f39 | 3033 | int ret; |
9392c9be AS |
3034 | |
3035 | if (drv->nlmode == NL80211_IFTYPE_ADHOC) { | |
3036 | nl80211_mark_disconnected(drv); | |
666e508c | 3037 | return nl80211_leave_ibss(drv, 1); |
9392c9be | 3038 | } |
cfaab580 | 3039 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) |
817762d9 | 3040 | return wpa_driver_nl80211_disconnect(drv, reason_code); |
2e75a2b3 JM |
3041 | wpa_printf(MSG_DEBUG, "%s(addr=" MACSTR " reason_code=%d)", |
3042 | __func__, MAC2STR(addr), reason_code); | |
add9b7a4 | 3043 | nl80211_mark_disconnected(drv); |
d6a36f39 JM |
3044 | ret = wpa_driver_nl80211_mlme(drv, addr, NL80211_CMD_DEAUTHENTICATE, |
3045 | reason_code, 0); | |
3046 | /* | |
3047 | * For locally generated deauthenticate, supplicant already generates a | |
3048 | * DEAUTH event, so ignore the event from NL80211. | |
3049 | */ | |
3050 | drv->ignore_next_local_deauth = ret == 0; | |
3051 | return ret; | |
3f5285e8 JM |
3052 | } |
3053 | ||
3054 | ||
536fd62d JM |
3055 | static void nl80211_copy_auth_params(struct wpa_driver_nl80211_data *drv, |
3056 | struct wpa_driver_auth_params *params) | |
3057 | { | |
3058 | int i; | |
3059 | ||
3060 | drv->auth_freq = params->freq; | |
3061 | drv->auth_alg = params->auth_alg; | |
3062 | drv->auth_wep_tx_keyidx = params->wep_tx_keyidx; | |
3063 | drv->auth_local_state_change = params->local_state_change; | |
3064 | drv->auth_p2p = params->p2p; | |
3065 | ||
3066 | if (params->bssid) | |
3067 | os_memcpy(drv->auth_bssid_, params->bssid, ETH_ALEN); | |
3068 | else | |
3069 | os_memset(drv->auth_bssid_, 0, ETH_ALEN); | |
3070 | ||
3071 | if (params->ssid) { | |
3072 | os_memcpy(drv->auth_ssid, params->ssid, params->ssid_len); | |
3073 | drv->auth_ssid_len = params->ssid_len; | |
3074 | } else | |
3075 | drv->auth_ssid_len = 0; | |
3076 | ||
3077 | ||
3078 | os_free(drv->auth_ie); | |
3079 | drv->auth_ie = NULL; | |
3080 | drv->auth_ie_len = 0; | |
3081 | if (params->ie) { | |
3082 | drv->auth_ie = os_malloc(params->ie_len); | |
3083 | if (drv->auth_ie) { | |
3084 | os_memcpy(drv->auth_ie, params->ie, params->ie_len); | |
3085 | drv->auth_ie_len = params->ie_len; | |
3086 | } | |
3087 | } | |
3088 | ||
3089 | for (i = 0; i < 4; i++) { | |
3090 | if (params->wep_key[i] && params->wep_key_len[i] && | |
3091 | params->wep_key_len[i] <= 16) { | |
3092 | os_memcpy(drv->auth_wep_key[i], params->wep_key[i], | |
3093 | params->wep_key_len[i]); | |
3094 | drv->auth_wep_key_len[i] = params->wep_key_len[i]; | |
3095 | } else | |
3096 | drv->auth_wep_key_len[i] = 0; | |
3097 | } | |
3098 | } | |
3099 | ||
3100 | ||
4bd71954 JM |
3101 | static void nl80211_unmask_11b_rates(struct i802_bss *bss) |
3102 | { | |
3103 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
3104 | ||
3105 | if (is_p2p_net_interface(drv->nlmode) || !drv->disabled_11b_rates) | |
3106 | return; | |
3107 | ||
3108 | /* | |
3109 | * Looks like we failed to unmask 11b rates previously. This could | |
3110 | * happen, e.g., if the interface was down at the point in time when a | |
3111 | * P2P group was terminated. | |
3112 | */ | |
3113 | wpa_printf(MSG_DEBUG, | |
3114 | "nl80211: Interface %s mode is for non-P2P, but 11b rates were disabled - re-enable them", | |
3115 | bss->ifname); | |
3116 | nl80211_disable_11b_rates(drv, drv->ifindex, 0); | |
3117 | } | |
3118 | ||
3119 | ||
c2a04078 | 3120 | static int wpa_driver_nl80211_authenticate( |
9ebce9c5 | 3121 | struct i802_bss *bss, struct wpa_driver_auth_params *params) |
c2a04078 | 3122 | { |
a2e40bb6 | 3123 | struct wpa_driver_nl80211_data *drv = bss->drv; |
a0b2f99b | 3124 | int ret = -1, i; |
c2a04078 JM |
3125 | struct nl_msg *msg; |
3126 | enum nl80211_auth_type type; | |
2f4f73b1 | 3127 | enum nl80211_iftype nlmode; |
6d6f4bb8 | 3128 | int count = 0; |
536fd62d JM |
3129 | int is_retry; |
3130 | ||
4bd71954 JM |
3131 | nl80211_unmask_11b_rates(bss); |
3132 | ||
536fd62d JM |
3133 | is_retry = drv->retry_auth; |
3134 | drv->retry_auth = 0; | |
e8d70a73 | 3135 | drv->ignore_deauth_event = 0; |
c2a04078 | 3136 | |
add9b7a4 | 3137 | nl80211_mark_disconnected(drv); |
e6b8efeb | 3138 | os_memset(drv->auth_bssid, 0, ETH_ALEN); |
add9b7a4 JM |
3139 | if (params->bssid) |
3140 | os_memcpy(drv->auth_attempt_bssid, params->bssid, ETH_ALEN); | |
3141 | else | |
3142 | os_memset(drv->auth_attempt_bssid, 0, ETH_ALEN); | |
af473088 | 3143 | /* FIX: IBSS mode */ |
2f4f73b1 EP |
3144 | nlmode = params->p2p ? |
3145 | NL80211_IFTYPE_P2P_CLIENT : NL80211_IFTYPE_STATION; | |
3146 | if (drv->nlmode != nlmode && | |
9ebce9c5 | 3147 | wpa_driver_nl80211_set_mode(bss, nlmode) < 0) |
4a867032 JM |
3148 | return -1; |
3149 | ||
6d6f4bb8 | 3150 | retry: |
c2a04078 JM |
3151 | wpa_printf(MSG_DEBUG, "nl80211: Authenticate (ifindex=%d)", |
3152 | drv->ifindex); | |
a0b2f99b | 3153 | |
9725b784 JM |
3154 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_AUTHENTICATE); |
3155 | if (!msg) | |
3156 | goto fail; | |
0194fedb | 3157 | |
a0b2f99b JM |
3158 | for (i = 0; i < 4; i++) { |
3159 | if (!params->wep_key[i]) | |
3160 | continue; | |
9ebce9c5 | 3161 | wpa_driver_nl80211_set_key(bss->ifname, bss, WPA_ALG_WEP, |
2ea2fcc7 | 3162 | NULL, i, |
a0b2f99b JM |
3163 | i == params->wep_tx_keyidx, NULL, 0, |
3164 | params->wep_key[i], | |
3165 | params->wep_key_len[i]); | |
0194fedb JB |
3166 | if (params->wep_tx_keyidx != i) |
3167 | continue; | |
3168 | if (nl_add_key(msg, WPA_ALG_WEP, i, 1, NULL, 0, | |
9725b784 JM |
3169 | params->wep_key[i], params->wep_key_len[i])) |
3170 | goto fail; | |
a0b2f99b JM |
3171 | } |
3172 | ||
c2a04078 JM |
3173 | if (params->bssid) { |
3174 | wpa_printf(MSG_DEBUG, " * bssid=" MACSTR, | |
3175 | MAC2STR(params->bssid)); | |
a862e4a3 JM |
3176 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid)) |
3177 | goto fail; | |
c2a04078 JM |
3178 | } |
3179 | if (params->freq) { | |
3180 | wpa_printf(MSG_DEBUG, " * freq=%d", params->freq); | |
a862e4a3 JM |
3181 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, params->freq)) |
3182 | goto fail; | |
c2a04078 JM |
3183 | } |
3184 | if (params->ssid) { | |
3185 | wpa_hexdump_ascii(MSG_DEBUG, " * SSID", | |
3186 | params->ssid, params->ssid_len); | |
a862e4a3 JM |
3187 | if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, |
3188 | params->ssid)) | |
3189 | goto fail; | |
c2a04078 JM |
3190 | } |
3191 | wpa_hexdump(MSG_DEBUG, " * IEs", params->ie, params->ie_len); | |
a862e4a3 JM |
3192 | if (params->ie && |
3193 | nla_put(msg, NL80211_ATTR_IE, params->ie_len, params->ie)) | |
3194 | goto fail; | |
ce16c489 JM |
3195 | if (params->auth_data) { |
3196 | wpa_hexdump(MSG_DEBUG, " * auth_data", params->auth_data, | |
3197 | params->auth_data_len); | |
3198 | if (nla_put(msg, NL80211_ATTR_SAE_DATA, params->auth_data_len, | |
3199 | params->auth_data)) | |
a862e4a3 | 3200 | goto fail; |
569fed90 | 3201 | } |
abd9fafa | 3202 | if (params->auth_alg & WPA_AUTH_ALG_OPEN) |
c2a04078 | 3203 | type = NL80211_AUTHTYPE_OPEN_SYSTEM; |
abd9fafa | 3204 | else if (params->auth_alg & WPA_AUTH_ALG_SHARED) |
c2a04078 | 3205 | type = NL80211_AUTHTYPE_SHARED_KEY; |
abd9fafa | 3206 | else if (params->auth_alg & WPA_AUTH_ALG_LEAP) |
c2a04078 | 3207 | type = NL80211_AUTHTYPE_NETWORK_EAP; |
abd9fafa | 3208 | else if (params->auth_alg & WPA_AUTH_ALG_FT) |
c2a04078 | 3209 | type = NL80211_AUTHTYPE_FT; |
569fed90 JM |
3210 | else if (params->auth_alg & WPA_AUTH_ALG_SAE) |
3211 | type = NL80211_AUTHTYPE_SAE; | |
d8f9342d JM |
3212 | else if (params->auth_alg & WPA_AUTH_ALG_FILS) |
3213 | type = NL80211_AUTHTYPE_FILS_SK; | |
c2a04078 | 3214 | else |
a862e4a3 | 3215 | goto fail; |
c2a04078 | 3216 | wpa_printf(MSG_DEBUG, " * Auth Type %d", type); |
a862e4a3 JM |
3217 | if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, type)) |
3218 | goto fail; | |
77339912 JM |
3219 | if (params->local_state_change) { |
3220 | wpa_printf(MSG_DEBUG, " * Local state change only"); | |
a862e4a3 JM |
3221 | if (nla_put_flag(msg, NL80211_ATTR_LOCAL_STATE_CHANGE)) |
3222 | goto fail; | |
77339912 | 3223 | } |
c2a04078 JM |
3224 | |
3225 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
3226 | msg = NULL; | |
3227 | if (ret) { | |
3b7ea880 BG |
3228 | wpa_dbg(drv->ctx, MSG_DEBUG, |
3229 | "nl80211: MLME command failed (auth): ret=%d (%s)", | |
3230 | ret, strerror(-ret)); | |
6d6f4bb8 | 3231 | count++; |
77339912 JM |
3232 | if (ret == -EALREADY && count == 1 && params->bssid && |
3233 | !params->local_state_change) { | |
6d6f4bb8 JM |
3234 | /* |
3235 | * mac80211 does not currently accept new | |
3236 | * authentication if we are already authenticated. As a | |
3237 | * workaround, force deauthentication and try again. | |
3238 | */ | |
3239 | wpa_printf(MSG_DEBUG, "nl80211: Retry authentication " | |
3240 | "after forced deauthentication"); | |
e8d70a73 | 3241 | drv->ignore_deauth_event = 1; |
6d6f4bb8 | 3242 | wpa_driver_nl80211_deauthenticate( |
5205c4f9 | 3243 | bss, params->bssid, |
6d6f4bb8 JM |
3244 | WLAN_REASON_PREV_AUTH_NOT_VALID); |
3245 | nlmsg_free(msg); | |
3246 | goto retry; | |
3247 | } | |
536fd62d JM |
3248 | |
3249 | if (ret == -ENOENT && params->freq && !is_retry) { | |
3250 | /* | |
3251 | * cfg80211 has likely expired the BSS entry even | |
3252 | * though it was previously available in our internal | |
3253 | * BSS table. To recover quickly, start a single | |
3254 | * channel scan on the specified channel. | |
3255 | */ | |
3256 | struct wpa_driver_scan_params scan; | |
3257 | int freqs[2]; | |
3258 | ||
3259 | os_memset(&scan, 0, sizeof(scan)); | |
3260 | scan.num_ssids = 1; | |
3261 | if (params->ssid) { | |
3262 | scan.ssids[0].ssid = params->ssid; | |
3263 | scan.ssids[0].ssid_len = params->ssid_len; | |
3264 | } | |
3265 | freqs[0] = params->freq; | |
3266 | freqs[1] = 0; | |
3267 | scan.freqs = freqs; | |
3268 | wpa_printf(MSG_DEBUG, "nl80211: Trigger single " | |
3269 | "channel scan to refresh cfg80211 BSS " | |
3270 | "entry"); | |
3271 | ret = wpa_driver_nl80211_scan(bss, &scan); | |
3272 | if (ret == 0) { | |
3273 | nl80211_copy_auth_params(drv, params); | |
3274 | drv->scan_for_auth = 1; | |
3275 | } | |
8c3ba078 JM |
3276 | } else if (is_retry) { |
3277 | /* | |
3278 | * Need to indicate this with an event since the return | |
3279 | * value from the retry is not delivered to core code. | |
3280 | */ | |
3281 | union wpa_event_data event; | |
3282 | wpa_printf(MSG_DEBUG, "nl80211: Authentication retry " | |
3283 | "failed"); | |
3284 | os_memset(&event, 0, sizeof(event)); | |
3285 | os_memcpy(event.timeout_event.addr, drv->auth_bssid_, | |
3286 | ETH_ALEN); | |
3287 | wpa_supplicant_event(drv->ctx, EVENT_AUTH_TIMED_OUT, | |
3288 | &event); | |
536fd62d | 3289 | } |
a862e4a3 JM |
3290 | } else { |
3291 | wpa_printf(MSG_DEBUG, | |
3292 | "nl80211: Authentication request send successfully"); | |
c2a04078 | 3293 | } |
c2a04078 | 3294 | |
a862e4a3 | 3295 | fail: |
c2a04078 JM |
3296 | nlmsg_free(msg); |
3297 | return ret; | |
3298 | } | |
3299 | ||
3300 | ||
f3407c66 | 3301 | int wpa_driver_nl80211_authenticate_retry(struct wpa_driver_nl80211_data *drv) |
536fd62d JM |
3302 | { |
3303 | struct wpa_driver_auth_params params; | |
834ee56f | 3304 | struct i802_bss *bss = drv->first_bss; |
536fd62d JM |
3305 | int i; |
3306 | ||
3307 | wpa_printf(MSG_DEBUG, "nl80211: Try to authenticate again"); | |
3308 | ||
3309 | os_memset(¶ms, 0, sizeof(params)); | |
3310 | params.freq = drv->auth_freq; | |
3311 | params.auth_alg = drv->auth_alg; | |
3312 | params.wep_tx_keyidx = drv->auth_wep_tx_keyidx; | |
3313 | params.local_state_change = drv->auth_local_state_change; | |
3314 | params.p2p = drv->auth_p2p; | |
3315 | ||
3316 | if (!is_zero_ether_addr(drv->auth_bssid_)) | |
3317 | params.bssid = drv->auth_bssid_; | |
3318 | ||
3319 | if (drv->auth_ssid_len) { | |
3320 | params.ssid = drv->auth_ssid; | |
3321 | params.ssid_len = drv->auth_ssid_len; | |
3322 | } | |
3323 | ||
3324 | params.ie = drv->auth_ie; | |
3325 | params.ie_len = drv->auth_ie_len; | |
3326 | ||
3327 | for (i = 0; i < 4; i++) { | |
3328 | if (drv->auth_wep_key_len[i]) { | |
3329 | params.wep_key[i] = drv->auth_wep_key[i]; | |
3330 | params.wep_key_len[i] = drv->auth_wep_key_len[i]; | |
3331 | } | |
3332 | } | |
3333 | ||
3334 | drv->retry_auth = 1; | |
3335 | return wpa_driver_nl80211_authenticate(bss, ¶ms); | |
3336 | } | |
3337 | ||
3338 | ||
a11241fa JB |
3339 | static int wpa_driver_nl80211_send_frame(struct i802_bss *bss, |
3340 | const void *data, size_t len, | |
55231068 JM |
3341 | int encrypt, int noack, |
3342 | unsigned int freq, int no_cck, | |
2d3943ce AO |
3343 | int offchanok, unsigned int wait_time, |
3344 | const u16 *csa_offs, | |
3345 | size_t csa_offs_len) | |
a11241fa JB |
3346 | { |
3347 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
3348 | u64 cookie; | |
41cc50d1 | 3349 | int res; |
a11241fa | 3350 | |
c7caac56 JM |
3351 | if (freq == 0 && drv->nlmode == NL80211_IFTYPE_ADHOC) { |
3352 | freq = nl80211_get_assoc_freq(drv); | |
3353 | wpa_printf(MSG_DEBUG, | |
3354 | "nl80211: send_frame - Use assoc_freq=%u for IBSS", | |
3355 | freq); | |
3356 | } | |
af964484 JM |
3357 | if (freq == 0) { |
3358 | wpa_printf(MSG_DEBUG, "nl80211: send_frame - Use bss->freq=%u", | |
3359 | bss->freq); | |
55231068 | 3360 | freq = bss->freq; |
af964484 | 3361 | } |
55231068 | 3362 | |
739faee2 | 3363 | if (drv->use_monitor) { |
981cf85a | 3364 | wpa_printf(MSG_DEBUG, "nl80211: send_frame(freq=%u bss->freq=%u) -> send_monitor", |
739faee2 | 3365 | freq, bss->freq); |
981cf85a | 3366 | return nl80211_send_monitor(drv, data, len, encrypt, noack); |
739faee2 | 3367 | } |
a11241fa | 3368 | |
739faee2 | 3369 | wpa_printf(MSG_DEBUG, "nl80211: send_frame -> send_frame_cmd"); |
41cc50d1 | 3370 | res = nl80211_send_frame_cmd(bss, freq, wait_time, data, len, |
2d3943ce AO |
3371 | &cookie, no_cck, noack, offchanok, |
3372 | csa_offs, csa_offs_len); | |
41cc50d1 JM |
3373 | if (res == 0 && !noack) { |
3374 | const struct ieee80211_mgmt *mgmt; | |
3375 | u16 fc; | |
3376 | ||
3377 | mgmt = (const struct ieee80211_mgmt *) data; | |
3378 | fc = le_to_host16(mgmt->frame_control); | |
3379 | if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && | |
3380 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_ACTION) { | |
3381 | wpa_printf(MSG_MSGDUMP, | |
3382 | "nl80211: Update send_action_cookie from 0x%llx to 0x%llx", | |
3383 | (long long unsigned int) | |
3384 | drv->send_action_cookie, | |
3385 | (long long unsigned int) cookie); | |
3386 | drv->send_action_cookie = cookie; | |
3387 | } | |
3388 | } | |
3389 | ||
3390 | return res; | |
a11241fa JB |
3391 | } |
3392 | ||
3393 | ||
9ebce9c5 JM |
3394 | static int wpa_driver_nl80211_send_mlme(struct i802_bss *bss, const u8 *data, |
3395 | size_t data_len, int noack, | |
3396 | unsigned int freq, int no_cck, | |
3397 | int offchanok, | |
2d3943ce AO |
3398 | unsigned int wait_time, |
3399 | const u16 *csa_offs, | |
3400 | size_t csa_offs_len) | |
2c2010ac | 3401 | { |
a2e40bb6 | 3402 | struct wpa_driver_nl80211_data *drv = bss->drv; |
2c2010ac | 3403 | struct ieee80211_mgmt *mgmt; |
7a47d567 | 3404 | int encrypt = 1; |
2c2010ac JM |
3405 | u16 fc; |
3406 | ||
3407 | mgmt = (struct ieee80211_mgmt *) data; | |
3408 | fc = le_to_host16(mgmt->frame_control); | |
f95a4524 PF |
3409 | wpa_printf(MSG_DEBUG, "nl80211: send_mlme - da= " MACSTR |
3410 | " noack=%d freq=%u no_cck=%d offchanok=%d wait_time=%u fc=0x%x (%s) nlmode=%d", | |
3411 | MAC2STR(mgmt->da), noack, freq, no_cck, offchanok, wait_time, | |
3412 | fc, fc2str(fc), drv->nlmode); | |
2c2010ac | 3413 | |
8e12685c AS |
3414 | if ((is_sta_interface(drv->nlmode) || |
3415 | drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) && | |
5582a5d1 JB |
3416 | WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && |
3417 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_PROBE_RESP) { | |
3418 | /* | |
3419 | * The use of last_mgmt_freq is a bit of a hack, | |
3420 | * but it works due to the single-threaded nature | |
3421 | * of wpa_supplicant. | |
3422 | */ | |
af964484 JM |
3423 | if (freq == 0) { |
3424 | wpa_printf(MSG_DEBUG, "nl80211: Use last_mgmt_freq=%d", | |
3425 | drv->last_mgmt_freq); | |
55231068 | 3426 | freq = drv->last_mgmt_freq; |
af964484 | 3427 | } |
55231068 | 3428 | return nl80211_send_frame_cmd(bss, freq, 0, |
88df0ef7 | 3429 | data, data_len, NULL, 1, noack, |
2d3943ce | 3430 | 1, csa_offs, csa_offs_len); |
5582a5d1 JB |
3431 | } |
3432 | ||
61cbe2ff | 3433 | if (drv->device_ap_sme && is_ap_interface(drv->nlmode)) { |
af964484 JM |
3434 | if (freq == 0) { |
3435 | wpa_printf(MSG_DEBUG, "nl80211: Use bss->freq=%d", | |
3436 | bss->freq); | |
55231068 | 3437 | freq = bss->freq; |
af964484 | 3438 | } |
b5671498 JM |
3439 | return nl80211_send_frame_cmd(bss, freq, |
3440 | (int) freq == bss->freq ? 0 : | |
3441 | wait_time, | |
d8d6b32e DG |
3442 | data, data_len, |
3443 | &drv->send_action_cookie, | |
2d3943ce AO |
3444 | no_cck, noack, offchanok, |
3445 | csa_offs, csa_offs_len); | |
86957e62 JM |
3446 | } |
3447 | ||
2c2010ac JM |
3448 | if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && |
3449 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_AUTH) { | |
3450 | /* | |
3451 | * Only one of the authentication frame types is encrypted. | |
3452 | * In order for static WEP encryption to work properly (i.e., | |
3453 | * to not encrypt the frame), we need to tell mac80211 about | |
3454 | * the frames that must not be encrypted. | |
3455 | */ | |
3456 | u16 auth_alg = le_to_host16(mgmt->u.auth.auth_alg); | |
3457 | u16 auth_trans = le_to_host16(mgmt->u.auth.auth_transaction); | |
7a47d567 JB |
3458 | if (auth_alg != WLAN_AUTH_SHARED_KEY || auth_trans != 3) |
3459 | encrypt = 0; | |
2c2010ac JM |
3460 | } |
3461 | ||
739faee2 | 3462 | wpa_printf(MSG_DEBUG, "nl80211: send_mlme -> send_frame"); |
a11241fa | 3463 | return wpa_driver_nl80211_send_frame(bss, data, data_len, encrypt, |
55231068 | 3464 | noack, freq, no_cck, offchanok, |
2d3943ce AO |
3465 | wait_time, csa_offs, |
3466 | csa_offs_len); | |
55231068 JM |
3467 | } |
3468 | ||
3469 | ||
cae87abd JM |
3470 | static int nl80211_put_basic_rates(struct nl_msg *msg, const int *basic_rates) |
3471 | { | |
3472 | u8 rates[NL80211_MAX_SUPP_RATES]; | |
3473 | u8 rates_len = 0; | |
3474 | int i; | |
3475 | ||
3476 | if (!basic_rates) | |
3477 | return 0; | |
3478 | ||
3479 | for (i = 0; i < NL80211_MAX_SUPP_RATES && basic_rates[i] >= 0; i++) | |
3480 | rates[rates_len++] = basic_rates[i] / 5; | |
3481 | ||
3482 | return nla_put(msg, NL80211_ATTR_BSS_BASIC_RATES, rates_len, rates); | |
3483 | } | |
3484 | ||
3485 | ||
31357268 | 3486 | static int nl80211_set_bss(struct i802_bss *bss, int cts, int preamble, |
e5693c47 | 3487 | int slot, int ht_opmode, int ap_isolate, |
cae87abd | 3488 | const int *basic_rates) |
31357268 JM |
3489 | { |
3490 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
3491 | struct nl_msg *msg; | |
3492 | ||
13f83980 | 3493 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_BSS)) || |
a862e4a3 JM |
3494 | (cts >= 0 && |
3495 | nla_put_u8(msg, NL80211_ATTR_BSS_CTS_PROT, cts)) || | |
3496 | (preamble >= 0 && | |
3497 | nla_put_u8(msg, NL80211_ATTR_BSS_SHORT_PREAMBLE, preamble)) || | |
3498 | (slot >= 0 && | |
3499 | nla_put_u8(msg, NL80211_ATTR_BSS_SHORT_SLOT_TIME, slot)) || | |
3500 | (ht_opmode >= 0 && | |
3501 | nla_put_u16(msg, NL80211_ATTR_BSS_HT_OPMODE, ht_opmode)) || | |
3502 | (ap_isolate >= 0 && | |
cae87abd JM |
3503 | nla_put_u8(msg, NL80211_ATTR_AP_ISOLATE, ap_isolate)) || |
3504 | nl80211_put_basic_rates(msg, basic_rates)) { | |
3505 | nlmsg_free(msg); | |
3506 | return -ENOBUFS; | |
e5693c47 JM |
3507 | } |
3508 | ||
31357268 | 3509 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
31357268 JM |
3510 | } |
3511 | ||
3512 | ||
3c4ca363 VN |
3513 | static int wpa_driver_nl80211_set_acl(void *priv, |
3514 | struct hostapd_acl_params *params) | |
3515 | { | |
3516 | struct i802_bss *bss = priv; | |
3517 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
3518 | struct nl_msg *msg; | |
f429ec44 | 3519 | struct nl_msg *acl; |
3c4ca363 | 3520 | unsigned int i; |
a862e4a3 | 3521 | int ret; |
3c4ca363 VN |
3522 | |
3523 | if (!(drv->capa.max_acl_mac_addrs)) | |
3524 | return -ENOTSUP; | |
3525 | ||
3526 | if (params->num_mac_acl > drv->capa.max_acl_mac_addrs) | |
3527 | return -ENOTSUP; | |
3528 | ||
3c4ca363 VN |
3529 | wpa_printf(MSG_DEBUG, "nl80211: Set %s ACL (num_mac_acl=%u)", |
3530 | params->acl_policy ? "Accept" : "Deny", params->num_mac_acl); | |
3531 | ||
f429ec44 JM |
3532 | acl = nlmsg_alloc(); |
3533 | if (!acl) | |
3534 | return -ENOMEM; | |
3535 | for (i = 0; i < params->num_mac_acl; i++) { | |
3536 | if (nla_put(acl, i + 1, ETH_ALEN, params->mac_acl[i].addr)) { | |
3537 | nlmsg_free(acl); | |
3538 | return -ENOMEM; | |
3539 | } | |
3540 | } | |
3541 | ||
9725b784 | 3542 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_MAC_ACL)) || |
a862e4a3 JM |
3543 | nla_put_u32(msg, NL80211_ATTR_ACL_POLICY, params->acl_policy ? |
3544 | NL80211_ACL_POLICY_DENY_UNLESS_LISTED : | |
3545 | NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED) || | |
f429ec44 | 3546 | nla_put_nested(msg, NL80211_ATTR_MAC_ADDRS, acl)) { |
a862e4a3 | 3547 | nlmsg_free(msg); |
f429ec44 | 3548 | nlmsg_free(acl); |
a862e4a3 JM |
3549 | return -ENOMEM; |
3550 | } | |
f429ec44 | 3551 | nlmsg_free(acl); |
3c4ca363 VN |
3552 | |
3553 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
3c4ca363 VN |
3554 | if (ret) { |
3555 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set MAC ACL: %d (%s)", | |
3556 | ret, strerror(-ret)); | |
3557 | } | |
3558 | ||
3c4ca363 VN |
3559 | return ret; |
3560 | } | |
3561 | ||
3562 | ||
85e1fad8 JM |
3563 | static int nl80211_put_beacon_int(struct nl_msg *msg, int beacon_int) |
3564 | { | |
3565 | if (beacon_int > 0) { | |
3566 | wpa_printf(MSG_DEBUG, " * beacon_int=%d", beacon_int); | |
3567 | return nla_put_u32(msg, NL80211_ATTR_BEACON_INTERVAL, | |
3568 | beacon_int); | |
3569 | } | |
3570 | ||
3571 | return 0; | |
3572 | } | |
3573 | ||
3574 | ||
4ac2ea57 MH |
3575 | static int nl80211_put_dtim_period(struct nl_msg *msg, int dtim_period) |
3576 | { | |
3577 | if (dtim_period > 0) { | |
3578 | wpa_printf(MSG_DEBUG, " * dtim_period=%d", dtim_period); | |
3579 | return nla_put_u32(msg, NL80211_ATTR_DTIM_PERIOD, dtim_period); | |
3580 | } | |
3581 | ||
3582 | return 0; | |
3583 | } | |
3584 | ||
3585 | ||
052b8d38 MH |
3586 | #ifdef CONFIG_MESH |
3587 | static int nl80211_set_mesh_config(void *priv, | |
3588 | struct wpa_driver_mesh_bss_params *params) | |
3589 | { | |
3590 | struct i802_bss *bss = priv; | |
3591 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
3592 | struct nl_msg *msg; | |
3593 | int ret; | |
3594 | ||
3595 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_MESH_CONFIG); | |
3596 | if (!msg) | |
3597 | return -1; | |
3598 | ||
3599 | ret = nl80211_put_mesh_config(msg, params); | |
3600 | if (ret < 0) { | |
3601 | nlmsg_free(msg); | |
3602 | return ret; | |
3603 | } | |
3604 | ||
3605 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
3606 | if (ret) { | |
3607 | wpa_printf(MSG_ERROR, | |
3608 | "nl80211: Mesh config set failed: %d (%s)", | |
3609 | ret, strerror(-ret)); | |
3610 | return ret; | |
3611 | } | |
3612 | return 0; | |
3613 | } | |
3614 | #endif /* CONFIG_MESH */ | |
3615 | ||
3616 | ||
d4f3003c PK |
3617 | static int nl80211_put_beacon_rate(struct nl_msg *msg, const u64 flags, |
3618 | struct wpa_driver_ap_params *params) | |
3619 | { | |
3620 | struct nlattr *bands, *band; | |
3621 | struct nl80211_txrate_vht vht_rate; | |
3622 | ||
3623 | if (!params->freq || | |
3624 | (params->beacon_rate == 0 && | |
3625 | params->rate_type == BEACON_RATE_LEGACY)) | |
3626 | return 0; | |
3627 | ||
3628 | bands = nla_nest_start(msg, NL80211_ATTR_TX_RATES); | |
3629 | if (!bands) | |
3630 | return -1; | |
3631 | ||
3632 | switch (params->freq->mode) { | |
3633 | case HOSTAPD_MODE_IEEE80211B: | |
3634 | case HOSTAPD_MODE_IEEE80211G: | |
3635 | band = nla_nest_start(msg, NL80211_BAND_2GHZ); | |
3636 | break; | |
3637 | case HOSTAPD_MODE_IEEE80211A: | |
3638 | band = nla_nest_start(msg, NL80211_BAND_5GHZ); | |
3639 | break; | |
3640 | case HOSTAPD_MODE_IEEE80211AD: | |
3641 | band = nla_nest_start(msg, NL80211_BAND_60GHZ); | |
3642 | break; | |
3643 | default: | |
3644 | return 0; | |
3645 | } | |
3646 | ||
3647 | if (!band) | |
3648 | return -1; | |
3649 | ||
3650 | os_memset(&vht_rate, 0, sizeof(vht_rate)); | |
3651 | ||
3652 | switch (params->rate_type) { | |
3653 | case BEACON_RATE_LEGACY: | |
3654 | if (!(flags & WPA_DRIVER_FLAGS_BEACON_RATE_LEGACY)) { | |
3655 | wpa_printf(MSG_INFO, | |
3656 | "nl80211: Driver does not support setting Beacon frame rate (legacy)"); | |
3657 | return -1; | |
3658 | } | |
3659 | ||
3660 | if (nla_put_u8(msg, NL80211_TXRATE_LEGACY, | |
3661 | (u8) params->beacon_rate / 5) || | |
3662 | nla_put(msg, NL80211_TXRATE_HT, 0, NULL) || | |
3663 | (params->freq->vht_enabled && | |
3664 | nla_put(msg, NL80211_TXRATE_VHT, sizeof(vht_rate), | |
3665 | &vht_rate))) | |
3666 | return -1; | |
3667 | ||
3668 | wpa_printf(MSG_DEBUG, " * beacon_rate = legacy:%u (* 100 kbps)", | |
3669 | params->beacon_rate); | |
3670 | break; | |
3671 | case BEACON_RATE_HT: | |
3672 | if (!(flags & WPA_DRIVER_FLAGS_BEACON_RATE_HT)) { | |
3673 | wpa_printf(MSG_INFO, | |
3674 | "nl80211: Driver does not support setting Beacon frame rate (HT)"); | |
3675 | return -1; | |
3676 | } | |
3677 | if (nla_put(msg, NL80211_TXRATE_LEGACY, 0, NULL) || | |
3678 | nla_put_u8(msg, NL80211_TXRATE_HT, params->beacon_rate) || | |
3679 | (params->freq->vht_enabled && | |
3680 | nla_put(msg, NL80211_TXRATE_VHT, sizeof(vht_rate), | |
3681 | &vht_rate))) | |
3682 | return -1; | |
3683 | wpa_printf(MSG_DEBUG, " * beacon_rate = HT-MCS %u", | |
3684 | params->beacon_rate); | |
3685 | break; | |
3686 | case BEACON_RATE_VHT: | |
3687 | if (!(flags & WPA_DRIVER_FLAGS_BEACON_RATE_VHT)) { | |
3688 | wpa_printf(MSG_INFO, | |
3689 | "nl80211: Driver does not support setting Beacon frame rate (VHT)"); | |
3690 | return -1; | |
3691 | } | |
3692 | vht_rate.mcs[0] = BIT(params->beacon_rate); | |
3693 | if (nla_put(msg, NL80211_TXRATE_LEGACY, 0, NULL)) | |
3694 | return -1; | |
3695 | if (nla_put(msg, NL80211_TXRATE_HT, 0, NULL)) | |
3696 | return -1; | |
3697 | if (nla_put(msg, NL80211_TXRATE_VHT, sizeof(vht_rate), | |
3698 | &vht_rate)) | |
3699 | return -1; | |
3700 | wpa_printf(MSG_DEBUG, " * beacon_rate = VHT-MCS %u", | |
3701 | params->beacon_rate); | |
3702 | break; | |
3703 | } | |
3704 | ||
3705 | nla_nest_end(msg, band); | |
3706 | nla_nest_end(msg, bands); | |
3707 | ||
3708 | return 0; | |
3709 | } | |
3710 | ||
3711 | ||
34f7c699 MB |
3712 | static int nl80211_set_multicast_to_unicast(struct i802_bss *bss, |
3713 | int multicast_to_unicast) | |
3714 | { | |
3715 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
3716 | struct nl_msg *msg; | |
3717 | int ret; | |
3718 | ||
3719 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_MULTICAST_TO_UNICAST); | |
3720 | if (!msg || | |
3721 | (multicast_to_unicast && | |
3722 | nla_put_flag(msg, NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED))) { | |
3723 | wpa_printf(MSG_ERROR, | |
3724 | "nl80211: Failed to build NL80211_CMD_SET_MULTICAST_TO_UNICAST msg for %s", | |
3725 | bss->ifname); | |
3726 | nlmsg_free(msg); | |
3727 | return -ENOBUFS; | |
3728 | } | |
3729 | ||
3730 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
3731 | ||
3732 | switch (ret) { | |
3733 | case 0: | |
3734 | wpa_printf(MSG_DEBUG, | |
3735 | "nl80211: multicast to unicast %s on interface %s", | |
3736 | multicast_to_unicast ? "enabled" : "disabled", | |
3737 | bss->ifname); | |
3738 | break; | |
3739 | case -EOPNOTSUPP: | |
3740 | if (!multicast_to_unicast) | |
3741 | break; | |
3742 | wpa_printf(MSG_INFO, | |
3743 | "nl80211: multicast to unicast not supported on interface %s", | |
3744 | bss->ifname); | |
3745 | break; | |
3746 | default: | |
3747 | wpa_printf(MSG_ERROR, | |
3748 | "nl80211: %s multicast to unicast failed with %d (%s) on interface %s", | |
3749 | multicast_to_unicast ? "enabling" : "disabling", | |
3750 | ret, strerror(-ret), bss->ifname); | |
3751 | break; | |
3752 | } | |
3753 | ||
3754 | return ret; | |
3755 | } | |
3756 | ||
3757 | ||
19c3b566 JM |
3758 | static int wpa_driver_nl80211_set_ap(void *priv, |
3759 | struct wpa_driver_ap_params *params) | |
d2440ba0 | 3760 | { |
a2e40bb6 FF |
3761 | struct i802_bss *bss = priv; |
3762 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
d2440ba0 JM |
3763 | struct nl_msg *msg; |
3764 | u8 cmd = NL80211_CMD_NEW_BEACON; | |
3765 | int ret; | |
b4fd6fab | 3766 | int beacon_set; |
b11d1d64 | 3767 | int num_suites; |
da1080d7 | 3768 | int smps_mode; |
de4ed4a8 | 3769 | u32 suites[10], suite; |
b11d1d64 | 3770 | u32 ver; |
052b8d38 MH |
3771 | #ifdef CONFIG_MESH |
3772 | struct wpa_driver_mesh_bss_params mesh_params; | |
3773 | #endif /* CONFIG_MESH */ | |
b4fd6fab | 3774 | |
f33c8606 | 3775 | beacon_set = params->reenable ? 0 : bss->beacon_set; |
d2440ba0 | 3776 | |
d2440ba0 | 3777 | wpa_printf(MSG_DEBUG, "nl80211: Set beacon (beacon_set=%d)", |
b4fd6fab JM |
3778 | beacon_set); |
3779 | if (beacon_set) | |
d2440ba0 JM |
3780 | cmd = NL80211_CMD_SET_BEACON; |
3781 | ||
b92e08fc JM |
3782 | wpa_hexdump(MSG_DEBUG, "nl80211: Beacon head", |
3783 | params->head, params->head_len); | |
b92e08fc JM |
3784 | wpa_hexdump(MSG_DEBUG, "nl80211: Beacon tail", |
3785 | params->tail, params->tail_len); | |
13f83980 | 3786 | wpa_printf(MSG_DEBUG, "nl80211: ifindex=%d", bss->ifindex); |
b92e08fc | 3787 | wpa_printf(MSG_DEBUG, "nl80211: beacon_int=%d", params->beacon_int); |
d4f3003c PK |
3788 | wpa_printf(MSG_DEBUG, "nl80211: beacon_rate=%u", params->beacon_rate); |
3789 | wpa_printf(MSG_DEBUG, "nl80211: rate_type=%d", params->rate_type); | |
b92e08fc | 3790 | wpa_printf(MSG_DEBUG, "nl80211: dtim_period=%d", params->dtim_period); |
b92e08fc JM |
3791 | wpa_hexdump_ascii(MSG_DEBUG, "nl80211: ssid", |
3792 | params->ssid, params->ssid_len); | |
13f83980 | 3793 | if (!(msg = nl80211_bss_msg(bss, 0, cmd)) || |
a862e4a3 JM |
3794 | nla_put(msg, NL80211_ATTR_BEACON_HEAD, params->head_len, |
3795 | params->head) || | |
3796 | nla_put(msg, NL80211_ATTR_BEACON_TAIL, params->tail_len, | |
3797 | params->tail) || | |
85e1fad8 | 3798 | nl80211_put_beacon_int(msg, params->beacon_int) || |
d4f3003c | 3799 | nl80211_put_beacon_rate(msg, drv->capa.flags, params) || |
4ac2ea57 | 3800 | nl80211_put_dtim_period(msg, params->dtim_period) || |
a862e4a3 JM |
3801 | nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid)) |
3802 | goto fail; | |
b92e08fc JM |
3803 | if (params->proberesp && params->proberesp_len) { |
3804 | wpa_hexdump(MSG_DEBUG, "nl80211: proberesp (offload)", | |
3805 | params->proberesp, params->proberesp_len); | |
a862e4a3 JM |
3806 | if (nla_put(msg, NL80211_ATTR_PROBE_RESP, params->proberesp_len, |
3807 | params->proberesp)) | |
3808 | goto fail; | |
b92e08fc | 3809 | } |
97a7a0b5 JM |
3810 | switch (params->hide_ssid) { |
3811 | case NO_SSID_HIDING: | |
b92e08fc | 3812 | wpa_printf(MSG_DEBUG, "nl80211: hidden SSID not in use"); |
a862e4a3 JM |
3813 | if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID, |
3814 | NL80211_HIDDEN_SSID_NOT_IN_USE)) | |
3815 | goto fail; | |
97a7a0b5 JM |
3816 | break; |
3817 | case HIDDEN_SSID_ZERO_LEN: | |
b92e08fc | 3818 | wpa_printf(MSG_DEBUG, "nl80211: hidden SSID zero len"); |
a862e4a3 JM |
3819 | if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID, |
3820 | NL80211_HIDDEN_SSID_ZERO_LEN)) | |
3821 | goto fail; | |
97a7a0b5 JM |
3822 | break; |
3823 | case HIDDEN_SSID_ZERO_CONTENTS: | |
b92e08fc | 3824 | wpa_printf(MSG_DEBUG, "nl80211: hidden SSID zero contents"); |
a862e4a3 JM |
3825 | if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID, |
3826 | NL80211_HIDDEN_SSID_ZERO_CONTENTS)) | |
3827 | goto fail; | |
97a7a0b5 JM |
3828 | break; |
3829 | } | |
b92e08fc | 3830 | wpa_printf(MSG_DEBUG, "nl80211: privacy=%d", params->privacy); |
a862e4a3 JM |
3831 | if (params->privacy && |
3832 | nla_put_flag(msg, NL80211_ATTR_PRIVACY)) | |
3833 | goto fail; | |
b92e08fc | 3834 | wpa_printf(MSG_DEBUG, "nl80211: auth_algs=0x%x", params->auth_algs); |
b11d1d64 JM |
3835 | if ((params->auth_algs & (WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED)) == |
3836 | (WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED)) { | |
3837 | /* Leave out the attribute */ | |
a862e4a3 JM |
3838 | } else if (params->auth_algs & WPA_AUTH_ALG_SHARED) { |
3839 | if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, | |
3840 | NL80211_AUTHTYPE_SHARED_KEY)) | |
3841 | goto fail; | |
3842 | } else { | |
3843 | if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, | |
3844 | NL80211_AUTHTYPE_OPEN_SYSTEM)) | |
3845 | goto fail; | |
3846 | } | |
b11d1d64 | 3847 | |
b92e08fc | 3848 | wpa_printf(MSG_DEBUG, "nl80211: wpa_version=0x%x", params->wpa_version); |
b11d1d64 JM |
3849 | ver = 0; |
3850 | if (params->wpa_version & WPA_PROTO_WPA) | |
3851 | ver |= NL80211_WPA_VERSION_1; | |
3852 | if (params->wpa_version & WPA_PROTO_RSN) | |
3853 | ver |= NL80211_WPA_VERSION_2; | |
a862e4a3 JM |
3854 | if (ver && |
3855 | nla_put_u32(msg, NL80211_ATTR_WPA_VERSIONS, ver)) | |
3856 | goto fail; | |
b11d1d64 | 3857 | |
b92e08fc JM |
3858 | wpa_printf(MSG_DEBUG, "nl80211: key_mgmt_suites=0x%x", |
3859 | params->key_mgmt_suites); | |
b11d1d64 JM |
3860 | num_suites = 0; |
3861 | if (params->key_mgmt_suites & WPA_KEY_MGMT_IEEE8021X) | |
3862 | suites[num_suites++] = WLAN_AKM_SUITE_8021X; | |
3863 | if (params->key_mgmt_suites & WPA_KEY_MGMT_PSK) | |
3864 | suites[num_suites++] = WLAN_AKM_SUITE_PSK; | |
a862e4a3 JM |
3865 | if (num_suites && |
3866 | nla_put(msg, NL80211_ATTR_AKM_SUITES, num_suites * sizeof(u32), | |
3867 | suites)) | |
3868 | goto fail; | |
b11d1d64 | 3869 | |
533fe09b | 3870 | if (params->key_mgmt_suites & WPA_KEY_MGMT_IEEE8021X_NO_WPA && |
e3429c0b JB |
3871 | (!params->pairwise_ciphers || |
3872 | params->pairwise_ciphers & (WPA_CIPHER_WEP104 | WPA_CIPHER_WEP40)) && | |
3873 | (nla_put_u16(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE, ETH_P_PAE) || | |
3874 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT))) | |
a862e4a3 | 3875 | goto fail; |
9f12614b | 3876 | |
b92e08fc JM |
3877 | wpa_printf(MSG_DEBUG, "nl80211: pairwise_ciphers=0x%x", |
3878 | params->pairwise_ciphers); | |
de4ed4a8 JM |
3879 | num_suites = wpa_cipher_to_cipher_suites(params->pairwise_ciphers, |
3880 | suites, ARRAY_SIZE(suites)); | |
a862e4a3 JM |
3881 | if (num_suites && |
3882 | nla_put(msg, NL80211_ATTR_CIPHER_SUITES_PAIRWISE, | |
3883 | num_suites * sizeof(u32), suites)) | |
3884 | goto fail; | |
b11d1d64 | 3885 | |
b92e08fc JM |
3886 | wpa_printf(MSG_DEBUG, "nl80211: group_cipher=0x%x", |
3887 | params->group_cipher); | |
de4ed4a8 | 3888 | suite = wpa_cipher_to_cipher_suite(params->group_cipher); |
a862e4a3 JM |
3889 | if (suite && |
3890 | nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, suite)) | |
3891 | goto fail; | |
d2440ba0 | 3892 | |
ee298f1b JM |
3893 | if (params->ht_opmode != -1) { |
3894 | switch (params->smps_mode) { | |
3895 | case HT_CAP_INFO_SMPS_DYNAMIC: | |
3896 | wpa_printf(MSG_DEBUG, "nl80211: SMPS mode - dynamic"); | |
3897 | smps_mode = NL80211_SMPS_DYNAMIC; | |
3898 | break; | |
3899 | case HT_CAP_INFO_SMPS_STATIC: | |
3900 | wpa_printf(MSG_DEBUG, "nl80211: SMPS mode - static"); | |
3901 | smps_mode = NL80211_SMPS_STATIC; | |
3902 | break; | |
3903 | default: | |
3904 | /* invalid - fallback to smps off */ | |
3905 | case HT_CAP_INFO_SMPS_DISABLED: | |
3906 | wpa_printf(MSG_DEBUG, "nl80211: SMPS mode - off"); | |
3907 | smps_mode = NL80211_SMPS_OFF; | |
3908 | break; | |
3909 | } | |
3910 | if (nla_put_u32(msg, NL80211_ATTR_SMPS_MODE, smps_mode)) | |
3911 | goto fail; | |
da1080d7 | 3912 | } |
da1080d7 | 3913 | |
fb91db56 | 3914 | if (params->beacon_ies) { |
b92e08fc JM |
3915 | wpa_hexdump_buf(MSG_DEBUG, "nl80211: beacon_ies", |
3916 | params->beacon_ies); | |
a862e4a3 JM |
3917 | if (nla_put(msg, NL80211_ATTR_IE, |
3918 | wpabuf_len(params->beacon_ies), | |
3919 | wpabuf_head(params->beacon_ies))) | |
3920 | goto fail; | |
fb91db56 JM |
3921 | } |
3922 | if (params->proberesp_ies) { | |
b92e08fc JM |
3923 | wpa_hexdump_buf(MSG_DEBUG, "nl80211: proberesp_ies", |
3924 | params->proberesp_ies); | |
a862e4a3 JM |
3925 | if (nla_put(msg, NL80211_ATTR_IE_PROBE_RESP, |
3926 | wpabuf_len(params->proberesp_ies), | |
3927 | wpabuf_head(params->proberesp_ies))) | |
3928 | goto fail; | |
fb91db56 JM |
3929 | } |
3930 | if (params->assocresp_ies) { | |
b92e08fc JM |
3931 | wpa_hexdump_buf(MSG_DEBUG, "nl80211: assocresp_ies", |
3932 | params->assocresp_ies); | |
a862e4a3 JM |
3933 | if (nla_put(msg, NL80211_ATTR_IE_ASSOC_RESP, |
3934 | wpabuf_len(params->assocresp_ies), | |
3935 | wpabuf_head(params->assocresp_ies))) | |
3936 | goto fail; | |
fb91db56 JM |
3937 | } |
3938 | ||
a0133ee1 | 3939 | if (drv->capa.flags & WPA_DRIVER_FLAGS_INACTIVITY_TIMER) { |
b92e08fc JM |
3940 | wpa_printf(MSG_DEBUG, "nl80211: ap_max_inactivity=%d", |
3941 | params->ap_max_inactivity); | |
a862e4a3 JM |
3942 | if (nla_put_u16(msg, NL80211_ATTR_INACTIVITY_TIMEOUT, |
3943 | params->ap_max_inactivity)) | |
3944 | goto fail; | |
a0133ee1 VT |
3945 | } |
3946 | ||
abb8d08b EP |
3947 | #ifdef CONFIG_P2P |
3948 | if (params->p2p_go_ctwindow > 0) { | |
3949 | if (drv->p2p_go_ctwindow_supported) { | |
3950 | wpa_printf(MSG_DEBUG, "nl80211: P2P GO ctwindow=%d", | |
3951 | params->p2p_go_ctwindow); | |
3952 | if (nla_put_u8(msg, NL80211_ATTR_P2P_CTWINDOW, | |
3953 | params->p2p_go_ctwindow)) | |
3954 | goto fail; | |
3955 | } else { | |
3956 | wpa_printf(MSG_INFO, | |
3957 | "nl80211: Driver does not support CTWindow configuration - ignore this parameter"); | |
3958 | } | |
3959 | } | |
3960 | #endif /* CONFIG_P2P */ | |
3961 | ||
86b5c400 LD |
3962 | if (params->pbss) { |
3963 | wpa_printf(MSG_DEBUG, "nl80211: PBSS"); | |
3964 | if (nla_put_flag(msg, NL80211_ATTR_PBSS)) | |
3965 | goto fail; | |
3966 | } | |
3967 | ||
d2440ba0 JM |
3968 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
3969 | if (ret) { | |
3970 | wpa_printf(MSG_DEBUG, "nl80211: Beacon set failed: %d (%s)", | |
3971 | ret, strerror(-ret)); | |
b4fd6fab | 3972 | } else { |
b4fd6fab | 3973 | bss->beacon_set = 1; |
31357268 | 3974 | nl80211_set_bss(bss, params->cts_protect, params->preamble, |
d03e8d11 | 3975 | params->short_slot_time, params->ht_opmode, |
e5693c47 | 3976 | params->isolate, params->basic_rates); |
34f7c699 MB |
3977 | nl80211_set_multicast_to_unicast(bss, |
3978 | params->multicast_to_unicast); | |
e87ef751 PX |
3979 | if (beacon_set && params->freq && |
3980 | params->freq->bandwidth != bss->bandwidth) { | |
3981 | wpa_printf(MSG_DEBUG, | |
3982 | "nl80211: Update BSS %s bandwidth: %d -> %d", | |
3983 | bss->ifname, bss->bandwidth, | |
3984 | params->freq->bandwidth); | |
3985 | ret = nl80211_set_channel(bss, params->freq, 1); | |
3986 | if (ret) { | |
3987 | wpa_printf(MSG_DEBUG, | |
3988 | "nl80211: Frequency set failed: %d (%s)", | |
3989 | ret, strerror(-ret)); | |
3990 | } else { | |
3991 | wpa_printf(MSG_DEBUG, | |
3992 | "nl80211: Frequency set succeeded for ht2040 coex"); | |
3993 | bss->bandwidth = params->freq->bandwidth; | |
3994 | } | |
f5728d0a | 3995 | } else if (!beacon_set && params->freq) { |
e87ef751 PX |
3996 | /* |
3997 | * cfg80211 updates the driver on frequence change in AP | |
3998 | * mode only at the point when beaconing is started, so | |
3999 | * set the initial value here. | |
4000 | */ | |
4001 | bss->bandwidth = params->freq->bandwidth; | |
4002 | } | |
b4fd6fab | 4003 | } |
052b8d38 MH |
4004 | |
4005 | #ifdef CONFIG_MESH | |
4006 | if (is_mesh_interface(drv->nlmode) && params->ht_opmode != -1) { | |
4007 | os_memset(&mesh_params, 0, sizeof(mesh_params)); | |
4008 | mesh_params.flags |= WPA_DRIVER_MESH_CONF_FLAG_HT_OP_MODE; | |
4009 | mesh_params.ht_opmode = params->ht_opmode; | |
4010 | ret = nl80211_set_mesh_config(priv, &mesh_params); | |
4011 | if (ret < 0) | |
4012 | return ret; | |
4013 | } | |
4014 | #endif /* CONFIG_MESH */ | |
4015 | ||
d2440ba0 | 4016 | return ret; |
a862e4a3 | 4017 | fail: |
5883168a | 4018 | nlmsg_free(msg); |
d2440ba0 JM |
4019 | return -ENOBUFS; |
4020 | } | |
4021 | ||
4022 | ||
1c4ffa87 | 4023 | static int nl80211_put_freq_params(struct nl_msg *msg, |
72b2605f | 4024 | const struct hostapd_freq_params *freq) |
1581b38b | 4025 | { |
1fc4ab23 | 4026 | wpa_printf(MSG_DEBUG, " * freq=%d", freq->freq); |
a862e4a3 JM |
4027 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq->freq)) |
4028 | return -ENOBUFS; | |
4029 | ||
1fc4ab23 JM |
4030 | wpa_printf(MSG_DEBUG, " * vht_enabled=%d", freq->vht_enabled); |
4031 | wpa_printf(MSG_DEBUG, " * ht_enabled=%d", freq->ht_enabled); | |
4032 | ||
89b800d7 | 4033 | if (freq->vht_enabled) { |
a862e4a3 JM |
4034 | enum nl80211_chan_width cw; |
4035 | ||
1fc4ab23 | 4036 | wpa_printf(MSG_DEBUG, " * bandwidth=%d", freq->bandwidth); |
89b800d7 JB |
4037 | switch (freq->bandwidth) { |
4038 | case 20: | |
a862e4a3 | 4039 | cw = NL80211_CHAN_WIDTH_20; |
89b800d7 JB |
4040 | break; |
4041 | case 40: | |
a862e4a3 | 4042 | cw = NL80211_CHAN_WIDTH_40; |
89b800d7 JB |
4043 | break; |
4044 | case 80: | |
4045 | if (freq->center_freq2) | |
a862e4a3 | 4046 | cw = NL80211_CHAN_WIDTH_80P80; |
89b800d7 | 4047 | else |
a862e4a3 | 4048 | cw = NL80211_CHAN_WIDTH_80; |
89b800d7 JB |
4049 | break; |
4050 | case 160: | |
a862e4a3 | 4051 | cw = NL80211_CHAN_WIDTH_160; |
89b800d7 JB |
4052 | break; |
4053 | default: | |
1c4ffa87 | 4054 | return -EINVAL; |
89b800d7 | 4055 | } |
a862e4a3 | 4056 | |
1fc4ab23 JM |
4057 | wpa_printf(MSG_DEBUG, " * channel_width=%d", cw); |
4058 | wpa_printf(MSG_DEBUG, " * center_freq1=%d", | |
4059 | freq->center_freq1); | |
4060 | wpa_printf(MSG_DEBUG, " * center_freq2=%d", | |
4061 | freq->center_freq2); | |
a862e4a3 JM |
4062 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, cw) || |
4063 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, | |
4064 | freq->center_freq1) || | |
4065 | (freq->center_freq2 && | |
4066 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, | |
4067 | freq->center_freq2))) | |
4068 | return -ENOBUFS; | |
89b800d7 | 4069 | } else if (freq->ht_enabled) { |
a862e4a3 JM |
4070 | enum nl80211_channel_type ct; |
4071 | ||
1fc4ab23 JM |
4072 | wpa_printf(MSG_DEBUG, " * sec_channel_offset=%d", |
4073 | freq->sec_channel_offset); | |
89b800d7 | 4074 | switch (freq->sec_channel_offset) { |
f019981a | 4075 | case -1: |
a862e4a3 | 4076 | ct = NL80211_CHAN_HT40MINUS; |
f019981a JM |
4077 | break; |
4078 | case 1: | |
a862e4a3 | 4079 | ct = NL80211_CHAN_HT40PLUS; |
f019981a JM |
4080 | break; |
4081 | default: | |
a862e4a3 | 4082 | ct = NL80211_CHAN_HT20; |
f019981a JM |
4083 | break; |
4084 | } | |
a862e4a3 | 4085 | |
1fc4ab23 | 4086 | wpa_printf(MSG_DEBUG, " * channel_type=%d", ct); |
a862e4a3 JM |
4087 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, ct)) |
4088 | return -ENOBUFS; | |
3388e7b9 MH |
4089 | } else { |
4090 | wpa_printf(MSG_DEBUG, " * channel_type=%d", | |
4091 | NL80211_CHAN_NO_HT); | |
4092 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, | |
4093 | NL80211_CHAN_NO_HT)) | |
4094 | return -ENOBUFS; | |
f019981a | 4095 | } |
1c4ffa87 | 4096 | return 0; |
1c4ffa87 AO |
4097 | } |
4098 | ||
4099 | ||
e87ef751 PX |
4100 | static int nl80211_set_channel(struct i802_bss *bss, |
4101 | struct hostapd_freq_params *freq, int set_chan) | |
1c4ffa87 AO |
4102 | { |
4103 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
4104 | struct nl_msg *msg; | |
4105 | int ret; | |
4106 | ||
4107 | wpa_printf(MSG_DEBUG, | |
4108 | "nl80211: Set freq %d (ht_enabled=%d, vht_enabled=%d, bandwidth=%d MHz, cf1=%d MHz, cf2=%d MHz)", | |
4109 | freq->freq, freq->ht_enabled, freq->vht_enabled, | |
4110 | freq->bandwidth, freq->center_freq1, freq->center_freq2); | |
1c4ffa87 | 4111 | |
9725b784 JM |
4112 | msg = nl80211_drv_msg(drv, 0, set_chan ? NL80211_CMD_SET_CHANNEL : |
4113 | NL80211_CMD_SET_WIPHY); | |
4114 | if (!msg || nl80211_put_freq_params(msg, freq) < 0) { | |
a862e4a3 JM |
4115 | nlmsg_free(msg); |
4116 | return -1; | |
4117 | } | |
1581b38b | 4118 | |
d2440ba0 | 4119 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
e4fb2167 | 4120 | if (ret == 0) { |
89b800d7 | 4121 | bss->freq = freq->freq; |
1581b38b | 4122 | return 0; |
e4fb2167 | 4123 | } |
f019981a | 4124 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set channel (freq=%d): " |
89b800d7 | 4125 | "%d (%s)", freq->freq, ret, strerror(-ret)); |
1581b38b JM |
4126 | return -1; |
4127 | } | |
4128 | ||
0f4e8b4f | 4129 | |
95ab6063 AN |
4130 | static u32 sta_flags_nl80211(int flags) |
4131 | { | |
4132 | u32 f = 0; | |
4133 | ||
4134 | if (flags & WPA_STA_AUTHORIZED) | |
4135 | f |= BIT(NL80211_STA_FLAG_AUTHORIZED); | |
4136 | if (flags & WPA_STA_WMM) | |
4137 | f |= BIT(NL80211_STA_FLAG_WME); | |
4138 | if (flags & WPA_STA_SHORT_PREAMBLE) | |
4139 | f |= BIT(NL80211_STA_FLAG_SHORT_PREAMBLE); | |
4140 | if (flags & WPA_STA_MFP) | |
4141 | f |= BIT(NL80211_STA_FLAG_MFP); | |
45b722f1 AN |
4142 | if (flags & WPA_STA_TDLS_PEER) |
4143 | f |= BIT(NL80211_STA_FLAG_TDLS_PEER); | |
7a228b5c BC |
4144 | if (flags & WPA_STA_AUTHENTICATED) |
4145 | f |= BIT(NL80211_STA_FLAG_AUTHENTICATED); | |
dc55b6b6 AB |
4146 | if (flags & WPA_STA_ASSOCIATED) |
4147 | f |= BIT(NL80211_STA_FLAG_ASSOCIATED); | |
95ab6063 AN |
4148 | |
4149 | return f; | |
4150 | } | |
4151 | ||
4152 | ||
7c7e7877 BC |
4153 | #ifdef CONFIG_MESH |
4154 | static u32 sta_plink_state_nl80211(enum mesh_plink_state state) | |
4155 | { | |
4156 | switch (state) { | |
d02e5498 | 4157 | case PLINK_IDLE: |
7c7e7877 | 4158 | return NL80211_PLINK_LISTEN; |
d02e5498 | 4159 | case PLINK_OPN_SNT: |
7c7e7877 | 4160 | return NL80211_PLINK_OPN_SNT; |
d02e5498 | 4161 | case PLINK_OPN_RCVD: |
7c7e7877 BC |
4162 | return NL80211_PLINK_OPN_RCVD; |
4163 | case PLINK_CNF_RCVD: | |
4164 | return NL80211_PLINK_CNF_RCVD; | |
4165 | case PLINK_ESTAB: | |
4166 | return NL80211_PLINK_ESTAB; | |
4167 | case PLINK_HOLDING: | |
4168 | return NL80211_PLINK_HOLDING; | |
4169 | case PLINK_BLOCKED: | |
4170 | return NL80211_PLINK_BLOCKED; | |
4171 | default: | |
4172 | wpa_printf(MSG_ERROR, "nl80211: Invalid mesh plink state %d", | |
4173 | state); | |
4174 | } | |
4175 | return -1; | |
4176 | } | |
4177 | #endif /* CONFIG_MESH */ | |
4178 | ||
4179 | ||
62847751 | 4180 | static int wpa_driver_nl80211_sta_add(void *priv, |
0f4e8b4f JM |
4181 | struct hostapd_sta_add_params *params) |
4182 | { | |
a2e40bb6 FF |
4183 | struct i802_bss *bss = priv; |
4184 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8970bae8 | 4185 | struct nl_msg *msg; |
95ab6063 | 4186 | struct nl80211_sta_flag_update upd; |
0f4e8b4f JM |
4187 | int ret = -ENOBUFS; |
4188 | ||
45b722f1 AN |
4189 | if ((params->flags & WPA_STA_TDLS_PEER) && |
4190 | !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) | |
4191 | return -EOPNOTSUPP; | |
4192 | ||
e4dea253 JM |
4193 | wpa_printf(MSG_DEBUG, "nl80211: %s STA " MACSTR, |
4194 | params->set ? "Set" : "Add", MAC2STR(params->addr)); | |
13f83980 JM |
4195 | msg = nl80211_bss_msg(bss, 0, params->set ? NL80211_CMD_SET_STATION : |
4196 | NL80211_CMD_NEW_STATION); | |
4197 | if (!msg || nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->addr)) | |
a862e4a3 | 4198 | goto fail; |
5551bc9c | 4199 | |
dc55b6b6 AB |
4200 | /* |
4201 | * Set the below properties only in one of the following cases: | |
4202 | * 1. New station is added, already associated. | |
4203 | * 2. Set WPA_STA_TDLS_PEER station. | |
4204 | * 3. Set an already added unassociated station, if driver supports | |
4205 | * full AP client state. (Set these properties after station became | |
4206 | * associated will be rejected by the driver). | |
4207 | */ | |
4208 | if (!params->set || (params->flags & WPA_STA_TDLS_PEER) || | |
4209 | (params->set && FULL_AP_CLIENT_STATE_SUPP(drv->capa.flags) && | |
4210 | (params->flags & WPA_STA_ASSOCIATED))) { | |
5551bc9c BC |
4211 | wpa_hexdump(MSG_DEBUG, " * supported rates", |
4212 | params->supp_rates, params->supp_rates_len); | |
a862e4a3 JM |
4213 | wpa_printf(MSG_DEBUG, " * capability=0x%x", |
4214 | params->capability); | |
4215 | if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_RATES, | |
4216 | params->supp_rates_len, params->supp_rates) || | |
4217 | nla_put_u16(msg, NL80211_ATTR_STA_CAPABILITY, | |
4218 | params->capability)) | |
4219 | goto fail; | |
e503861f JM |
4220 | |
4221 | if (params->ht_capabilities) { | |
4222 | wpa_hexdump(MSG_DEBUG, " * ht_capabilities", | |
4223 | (u8 *) params->ht_capabilities, | |
4224 | sizeof(*params->ht_capabilities)); | |
a862e4a3 JM |
4225 | if (nla_put(msg, NL80211_ATTR_HT_CAPABILITY, |
4226 | sizeof(*params->ht_capabilities), | |
4227 | params->ht_capabilities)) | |
4228 | goto fail; | |
e503861f JM |
4229 | } |
4230 | ||
4231 | if (params->vht_capabilities) { | |
4232 | wpa_hexdump(MSG_DEBUG, " * vht_capabilities", | |
4233 | (u8 *) params->vht_capabilities, | |
4234 | sizeof(*params->vht_capabilities)); | |
a862e4a3 JM |
4235 | if (nla_put(msg, NL80211_ATTR_VHT_CAPABILITY, |
4236 | sizeof(*params->vht_capabilities), | |
4237 | params->vht_capabilities)) | |
4238 | goto fail; | |
e503861f JM |
4239 | } |
4240 | ||
e503861f JM |
4241 | if (params->ext_capab) { |
4242 | wpa_hexdump(MSG_DEBUG, " * ext_capab", | |
4243 | params->ext_capab, params->ext_capab_len); | |
a862e4a3 JM |
4244 | if (nla_put(msg, NL80211_ATTR_STA_EXT_CAPABILITY, |
4245 | params->ext_capab_len, params->ext_capab)) | |
4246 | goto fail; | |
e503861f | 4247 | } |
ae33239c AB |
4248 | |
4249 | if (is_ap_interface(drv->nlmode) && | |
4250 | nla_put_u8(msg, NL80211_ATTR_STA_SUPPORT_P2P_PS, | |
4251 | params->support_p2p_ps ? | |
4252 | NL80211_P2P_PS_SUPPORTED : | |
4253 | NL80211_P2P_PS_UNSUPPORTED)) | |
4254 | goto fail; | |
5551bc9c | 4255 | } |
45b722f1 | 4256 | if (!params->set) { |
f11b72c3 JM |
4257 | if (params->aid) { |
4258 | wpa_printf(MSG_DEBUG, " * aid=%u", params->aid); | |
a862e4a3 JM |
4259 | if (nla_put_u16(msg, NL80211_ATTR_STA_AID, params->aid)) |
4260 | goto fail; | |
f11b72c3 JM |
4261 | } else { |
4262 | /* | |
4263 | * cfg80211 validates that AID is non-zero, so we have | |
4264 | * to make this a non-zero value for the TDLS case where | |
dc55b6b6 AB |
4265 | * a dummy STA entry is used for now and for a station |
4266 | * that is still not associated. | |
f11b72c3 | 4267 | */ |
dc55b6b6 AB |
4268 | wpa_printf(MSG_DEBUG, " * aid=1 (%s workaround)", |
4269 | (params->flags & WPA_STA_TDLS_PEER) ? | |
4270 | "TDLS" : "UNASSOC_STA"); | |
a862e4a3 JM |
4271 | if (nla_put_u16(msg, NL80211_ATTR_STA_AID, 1)) |
4272 | goto fail; | |
f11b72c3 | 4273 | } |
e4dea253 JM |
4274 | wpa_printf(MSG_DEBUG, " * listen_interval=%u", |
4275 | params->listen_interval); | |
a862e4a3 JM |
4276 | if (nla_put_u16(msg, NL80211_ATTR_STA_LISTEN_INTERVAL, |
4277 | params->listen_interval)) | |
4278 | goto fail; | |
e112764e JM |
4279 | } else if (params->aid && (params->flags & WPA_STA_TDLS_PEER)) { |
4280 | wpa_printf(MSG_DEBUG, " * peer_aid=%u", params->aid); | |
a862e4a3 JM |
4281 | if (nla_put_u16(msg, NL80211_ATTR_PEER_AID, params->aid)) |
4282 | goto fail; | |
dc55b6b6 AB |
4283 | } else if (FULL_AP_CLIENT_STATE_SUPP(drv->capa.flags) && |
4284 | (params->flags & WPA_STA_ASSOCIATED)) { | |
4285 | wpa_printf(MSG_DEBUG, " * aid=%u", params->aid); | |
4286 | wpa_printf(MSG_DEBUG, " * listen_interval=%u", | |
4287 | params->listen_interval); | |
4288 | if (nla_put_u16(msg, NL80211_ATTR_STA_AID, params->aid) || | |
4289 | nla_put_u16(msg, NL80211_ATTR_STA_LISTEN_INTERVAL, | |
4290 | params->listen_interval)) | |
4291 | goto fail; | |
45b722f1 | 4292 | } |
05a8d422 | 4293 | |
8a458116 MK |
4294 | if (params->vht_opmode_enabled) { |
4295 | wpa_printf(MSG_DEBUG, " * opmode=%u", params->vht_opmode); | |
a862e4a3 JM |
4296 | if (nla_put_u8(msg, NL80211_ATTR_OPMODE_NOTIF, |
4297 | params->vht_opmode)) | |
4298 | goto fail; | |
8a458116 MK |
4299 | } |
4300 | ||
efc64886 SD |
4301 | if (params->supp_channels) { |
4302 | wpa_hexdump(MSG_DEBUG, " * supported channels", | |
4303 | params->supp_channels, params->supp_channels_len); | |
a862e4a3 JM |
4304 | if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_CHANNELS, |
4305 | params->supp_channels_len, params->supp_channels)) | |
4306 | goto fail; | |
efc64886 SD |
4307 | } |
4308 | ||
4309 | if (params->supp_oper_classes) { | |
4310 | wpa_hexdump(MSG_DEBUG, " * supported operating classes", | |
4311 | params->supp_oper_classes, | |
4312 | params->supp_oper_classes_len); | |
a862e4a3 JM |
4313 | if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES, |
4314 | params->supp_oper_classes_len, | |
4315 | params->supp_oper_classes)) | |
4316 | goto fail; | |
efc64886 SD |
4317 | } |
4318 | ||
95ab6063 | 4319 | os_memset(&upd, 0, sizeof(upd)); |
7e31703e BC |
4320 | upd.set = sta_flags_nl80211(params->flags); |
4321 | upd.mask = upd.set | sta_flags_nl80211(params->flags_mask); | |
dc55b6b6 AB |
4322 | |
4323 | /* | |
4324 | * If the driver doesn't support full AP client state, ignore ASSOC/AUTH | |
4325 | * flags, as nl80211 driver moves a new station, by default, into | |
4326 | * associated state. | |
4327 | * | |
4328 | * On the other hand, if the driver supports that feature and the | |
4329 | * station is added in unauthenticated state, set the | |
4330 | * authenticated/associated bits in the mask to prevent moving this | |
4331 | * station to associated state before it is actually associated. | |
4332 | * | |
4333 | * This is irrelevant for mesh mode where the station is added to the | |
4334 | * driver as authenticated already, and ASSOCIATED isn't part of the | |
4335 | * nl80211 API. | |
4336 | */ | |
4337 | if (!is_mesh_interface(drv->nlmode)) { | |
4338 | if (!FULL_AP_CLIENT_STATE_SUPP(drv->capa.flags)) { | |
4339 | wpa_printf(MSG_DEBUG, | |
4340 | "nl80211: Ignore ASSOC/AUTH flags since driver doesn't support full AP client state"); | |
4341 | upd.mask &= ~(BIT(NL80211_STA_FLAG_ASSOCIATED) | | |
4342 | BIT(NL80211_STA_FLAG_AUTHENTICATED)); | |
4343 | } else if (!params->set && | |
4344 | !(params->flags & WPA_STA_TDLS_PEER)) { | |
4345 | if (!(params->flags & WPA_STA_AUTHENTICATED)) | |
4346 | upd.mask |= BIT(NL80211_STA_FLAG_AUTHENTICATED); | |
4347 | if (!(params->flags & WPA_STA_ASSOCIATED)) | |
4348 | upd.mask |= BIT(NL80211_STA_FLAG_ASSOCIATED); | |
4349 | } | |
e347cafe MH |
4350 | #ifdef CONFIG_MESH |
4351 | } else { | |
4352 | if (params->plink_state == PLINK_ESTAB && params->peer_aid) { | |
4353 | ret = nla_put_u16(msg, NL80211_ATTR_MESH_PEER_AID, | |
4354 | params->peer_aid); | |
4355 | if (ret) | |
4356 | goto fail; | |
4357 | } | |
4358 | #endif /* CONFIG_MESH */ | |
dc55b6b6 AB |
4359 | } |
4360 | ||
e4dea253 JM |
4361 | wpa_printf(MSG_DEBUG, " * flags set=0x%x mask=0x%x", |
4362 | upd.set, upd.mask); | |
a862e4a3 JM |
4363 | if (nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd)) |
4364 | goto fail; | |
95ab6063 | 4365 | |
7c7e7877 | 4366 | #ifdef CONFIG_MESH |
a862e4a3 JM |
4367 | if (params->plink_state && |
4368 | nla_put_u8(msg, NL80211_ATTR_STA_PLINK_STATE, | |
4369 | sta_plink_state_nl80211(params->plink_state))) | |
4370 | goto fail; | |
7c7e7877 BC |
4371 | #endif /* CONFIG_MESH */ |
4372 | ||
774bfa62 | 4373 | if (params->flags & WPA_STA_WMM) { |
8970bae8 JB |
4374 | struct nlattr *wme = nla_nest_start(msg, NL80211_ATTR_STA_WME); |
4375 | ||
e4dea253 | 4376 | wpa_printf(MSG_DEBUG, " * qosinfo=0x%x", params->qosinfo); |
a862e4a3 JM |
4377 | if (!wme || |
4378 | nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES, | |
4379 | params->qosinfo & WMM_QOSINFO_STA_AC_MASK) || | |
4380 | nla_put_u8(msg, NL80211_STA_WME_MAX_SP, | |
4381 | (params->qosinfo >> WMM_QOSINFO_STA_SP_SHIFT) & | |
4382 | WMM_QOSINFO_STA_SP_MASK)) | |
4383 | goto fail; | |
8970bae8 | 4384 | nla_nest_end(msg, wme); |
774bfa62 EP |
4385 | } |
4386 | ||
0f4e8b4f | 4387 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
5883168a | 4388 | msg = NULL; |
0f4e8b4f | 4389 | if (ret) |
45b722f1 AN |
4390 | wpa_printf(MSG_DEBUG, "nl80211: NL80211_CMD_%s_STATION " |
4391 | "result: %d (%s)", params->set ? "SET" : "NEW", ret, | |
4392 | strerror(-ret)); | |
0f4e8b4f JM |
4393 | if (ret == -EEXIST) |
4394 | ret = 0; | |
a862e4a3 | 4395 | fail: |
5883168a | 4396 | nlmsg_free(msg); |
0f4e8b4f JM |
4397 | return ret; |
4398 | } | |
4399 | ||
4400 | ||
97ed9a06 KP |
4401 | static void rtnl_neigh_delete_fdb_entry(struct i802_bss *bss, const u8 *addr) |
4402 | { | |
4403 | #ifdef CONFIG_LIBNL3_ROUTE | |
4404 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
4405 | struct rtnl_neigh *rn; | |
4406 | struct nl_addr *nl_addr; | |
4407 | int err; | |
4408 | ||
4409 | rn = rtnl_neigh_alloc(); | |
4410 | if (!rn) | |
4411 | return; | |
4412 | ||
4413 | rtnl_neigh_set_family(rn, AF_BRIDGE); | |
4414 | rtnl_neigh_set_ifindex(rn, bss->ifindex); | |
4415 | nl_addr = nl_addr_build(AF_BRIDGE, (void *) addr, ETH_ALEN); | |
4416 | if (!nl_addr) { | |
4417 | rtnl_neigh_put(rn); | |
4418 | return; | |
4419 | } | |
4420 | rtnl_neigh_set_lladdr(rn, nl_addr); | |
4421 | ||
4422 | err = rtnl_neigh_delete(drv->rtnl_sk, rn, 0); | |
4423 | if (err < 0) { | |
4424 | wpa_printf(MSG_DEBUG, "nl80211: bridge FDB entry delete for " | |
4425 | MACSTR " ifindex=%d failed: %s", MAC2STR(addr), | |
4426 | bss->ifindex, nl_geterror(err)); | |
4427 | } else { | |
4428 | wpa_printf(MSG_DEBUG, "nl80211: deleted bridge FDB entry for " | |
4429 | MACSTR, MAC2STR(addr)); | |
4430 | } | |
4431 | ||
4432 | nl_addr_put(nl_addr); | |
4433 | rtnl_neigh_put(rn); | |
4434 | #endif /* CONFIG_LIBNL3_ROUTE */ | |
4435 | } | |
4436 | ||
4437 | ||
59d7148a JM |
4438 | static int wpa_driver_nl80211_sta_remove(struct i802_bss *bss, const u8 *addr, |
4439 | int deauth, u16 reason_code) | |
0f4e8b4f | 4440 | { |
a2e40bb6 | 4441 | struct wpa_driver_nl80211_data *drv = bss->drv; |
0f4e8b4f JM |
4442 | struct nl_msg *msg; |
4443 | int ret; | |
4444 | ||
13f83980 | 4445 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_DEL_STATION)) || |
a862e4a3 JM |
4446 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
4447 | (deauth == 0 && | |
4448 | nla_put_u8(msg, NL80211_ATTR_MGMT_SUBTYPE, | |
4449 | WLAN_FC_STYPE_DISASSOC)) || | |
4450 | (deauth == 1 && | |
4451 | nla_put_u8(msg, NL80211_ATTR_MGMT_SUBTYPE, | |
4452 | WLAN_FC_STYPE_DEAUTH)) || | |
4453 | (reason_code && | |
4454 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) { | |
4455 | nlmsg_free(msg); | |
4456 | return -ENOBUFS; | |
4457 | } | |
0f4e8b4f JM |
4458 | |
4459 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
83e7bb0e JM |
4460 | wpa_printf(MSG_DEBUG, "nl80211: sta_remove -> DEL_STATION %s " MACSTR |
4461 | " --> %d (%s)", | |
4462 | bss->ifname, MAC2STR(addr), ret, strerror(-ret)); | |
97ed9a06 KP |
4463 | |
4464 | if (drv->rtnl_sk) | |
4465 | rtnl_neigh_delete_fdb_entry(bss, addr); | |
4466 | ||
0f4e8b4f JM |
4467 | if (ret == -ENOENT) |
4468 | return 0; | |
4469 | return ret; | |
0f4e8b4f JM |
4470 | } |
4471 | ||
1581b38b | 4472 | |
f3407c66 | 4473 | void nl80211_remove_iface(struct wpa_driver_nl80211_data *drv, int ifidx) |
0915d02c JM |
4474 | { |
4475 | struct nl_msg *msg; | |
de884303 | 4476 | struct wpa_driver_nl80211_data *drv2; |
0915d02c | 4477 | |
c6e8e8e4 JM |
4478 | wpa_printf(MSG_DEBUG, "nl80211: Remove interface ifindex=%d", ifidx); |
4479 | ||
2135f224 | 4480 | /* stop listening for EAPOL on this interface */ |
de884303 JM |
4481 | dl_list_for_each(drv2, &drv->global->interfaces, |
4482 | struct wpa_driver_nl80211_data, list) | |
732b1d20 MB |
4483 | { |
4484 | del_ifidx(drv2, ifidx, IFIDX_ANY); | |
4485 | /* Remove all bridges learned for this iface */ | |
4486 | del_ifidx(drv2, IFIDX_ANY, ifidx); | |
4487 | } | |
2135f224 | 4488 | |
95376e1a | 4489 | msg = nl80211_ifindex_msg(drv, ifidx, 0, NL80211_CMD_DEL_INTERFACE); |
0915d02c JM |
4490 | if (send_and_recv_msgs(drv, msg, NULL, NULL) == 0) |
4491 | return; | |
e748062b | 4492 | wpa_printf(MSG_ERROR, "Failed to remove interface (ifidx=%d)", ifidx); |
0915d02c JM |
4493 | } |
4494 | ||
4495 | ||
cc9a2575 | 4496 | const char * nl80211_iftype_str(enum nl80211_iftype mode) |
a1922f93 JM |
4497 | { |
4498 | switch (mode) { | |
4499 | case NL80211_IFTYPE_ADHOC: | |
4500 | return "ADHOC"; | |
4501 | case NL80211_IFTYPE_STATION: | |
4502 | return "STATION"; | |
4503 | case NL80211_IFTYPE_AP: | |
4504 | return "AP"; | |
1045ec36 JM |
4505 | case NL80211_IFTYPE_AP_VLAN: |
4506 | return "AP_VLAN"; | |
4507 | case NL80211_IFTYPE_WDS: | |
4508 | return "WDS"; | |
a1922f93 JM |
4509 | case NL80211_IFTYPE_MONITOR: |
4510 | return "MONITOR"; | |
1045ec36 JM |
4511 | case NL80211_IFTYPE_MESH_POINT: |
4512 | return "MESH_POINT"; | |
a1922f93 JM |
4513 | case NL80211_IFTYPE_P2P_CLIENT: |
4514 | return "P2P_CLIENT"; | |
4515 | case NL80211_IFTYPE_P2P_GO: | |
4516 | return "P2P_GO"; | |
7aad838c NS |
4517 | case NL80211_IFTYPE_P2P_DEVICE: |
4518 | return "P2P_DEVICE"; | |
a1922f93 JM |
4519 | default: |
4520 | return "unknown"; | |
4521 | } | |
4522 | } | |
4523 | ||
4524 | ||
a35187e7 KH |
4525 | static int nl80211_create_iface_once(struct wpa_driver_nl80211_data *drv, |
4526 | const char *ifname, | |
4527 | enum nl80211_iftype iftype, | |
d6dcfcda DS |
4528 | const u8 *addr, int wds, |
4529 | int (*handler)(struct nl_msg *, void *), | |
4530 | void *arg) | |
0915d02c | 4531 | { |
8970bae8 | 4532 | struct nl_msg *msg; |
0915d02c JM |
4533 | int ifidx; |
4534 | int ret = -ENOBUFS; | |
4535 | ||
a1922f93 JM |
4536 | wpa_printf(MSG_DEBUG, "nl80211: Create interface iftype %d (%s)", |
4537 | iftype, nl80211_iftype_str(iftype)); | |
4538 | ||
56f77852 JM |
4539 | msg = nl80211_cmd_msg(drv->first_bss, 0, NL80211_CMD_NEW_INTERFACE); |
4540 | if (!msg || | |
a862e4a3 JM |
4541 | nla_put_string(msg, NL80211_ATTR_IFNAME, ifname) || |
4542 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, iftype)) | |
4543 | goto fail; | |
0915d02c JM |
4544 | |
4545 | if (iftype == NL80211_IFTYPE_MONITOR) { | |
8970bae8 | 4546 | struct nlattr *flags; |
0915d02c | 4547 | |
8970bae8 | 4548 | flags = nla_nest_start(msg, NL80211_ATTR_MNTR_FLAGS); |
a862e4a3 JM |
4549 | if (!flags || |
4550 | nla_put_flag(msg, NL80211_MNTR_FLAG_COOK_FRAMES)) | |
4551 | goto fail; | |
0915d02c | 4552 | |
8970bae8 | 4553 | nla_nest_end(msg, flags); |
fbbfcbac | 4554 | } else if (wds) { |
a862e4a3 JM |
4555 | if (nla_put_u8(msg, NL80211_ATTR_4ADDR, wds)) |
4556 | goto fail; | |
0915d02c JM |
4557 | } |
4558 | ||
52f5877a IP |
4559 | /* |
4560 | * Tell cfg80211 that the interface belongs to the socket that created | |
4561 | * it, and the interface should be deleted when the socket is closed. | |
4562 | */ | |
a862e4a3 JM |
4563 | if (nla_put_flag(msg, NL80211_ATTR_IFACE_SOCKET_OWNER)) |
4564 | goto fail; | |
52f5877a | 4565 | |
d6dcfcda | 4566 | ret = send_and_recv_msgs(drv, msg, handler, arg); |
5883168a | 4567 | msg = NULL; |
0915d02c | 4568 | if (ret) { |
a862e4a3 | 4569 | fail: |
5883168a | 4570 | nlmsg_free(msg); |
a35187e7 KH |
4571 | wpa_printf(MSG_ERROR, "Failed to create interface %s: %d (%s)", |
4572 | ifname, ret, strerror(-ret)); | |
0915d02c JM |
4573 | return ret; |
4574 | } | |
4575 | ||
f632e483 | 4576 | if (iftype == NL80211_IFTYPE_P2P_DEVICE) |
6bae92e0 | 4577 | return 0; |
6bae92e0 | 4578 | |
0915d02c | 4579 | ifidx = if_nametoindex(ifname); |
c6e8e8e4 JM |
4580 | wpa_printf(MSG_DEBUG, "nl80211: New interface %s created: ifindex=%d", |
4581 | ifname, ifidx); | |
0915d02c JM |
4582 | |
4583 | if (ifidx <= 0) | |
4584 | return -1; | |
4585 | ||
147848ec JM |
4586 | /* |
4587 | * Some virtual interfaces need to process EAPOL packets and events on | |
4588 | * the parent interface. This is used mainly with hostapd. | |
4589 | */ | |
4590 | if (drv->hostapd || | |
4591 | iftype == NL80211_IFTYPE_AP_VLAN || | |
4592 | iftype == NL80211_IFTYPE_WDS || | |
4593 | iftype == NL80211_IFTYPE_MONITOR) { | |
4594 | /* start listening for EAPOL on this interface */ | |
732b1d20 | 4595 | add_ifidx(drv, ifidx, IFIDX_ANY); |
147848ec | 4596 | } |
2135f224 | 4597 | |
7bfc47c3 | 4598 | if (addr && iftype != NL80211_IFTYPE_MONITOR && |
c81eff1a | 4599 | linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, addr)) { |
41d931ee JM |
4600 | nl80211_remove_iface(drv, ifidx); |
4601 | return -1; | |
2135f224 | 4602 | } |
2135f224 | 4603 | |
0915d02c JM |
4604 | return ifidx; |
4605 | } | |
22a7c9d7 JM |
4606 | |
4607 | ||
f3407c66 JM |
4608 | int nl80211_create_iface(struct wpa_driver_nl80211_data *drv, |
4609 | const char *ifname, enum nl80211_iftype iftype, | |
4610 | const u8 *addr, int wds, | |
4611 | int (*handler)(struct nl_msg *, void *), | |
4612 | void *arg, int use_existing) | |
a35187e7 KH |
4613 | { |
4614 | int ret; | |
4615 | ||
d6dcfcda DS |
4616 | ret = nl80211_create_iface_once(drv, ifname, iftype, addr, wds, handler, |
4617 | arg); | |
a35187e7 | 4618 | |
ffbf1eaa | 4619 | /* if error occurred and interface exists already */ |
a35187e7 | 4620 | if (ret == -ENFILE && if_nametoindex(ifname)) { |
2aec4f3c JM |
4621 | if (use_existing) { |
4622 | wpa_printf(MSG_DEBUG, "nl80211: Continue using existing interface %s", | |
4623 | ifname); | |
6997f8ba JM |
4624 | if (addr && iftype != NL80211_IFTYPE_MONITOR && |
4625 | linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, | |
4626 | addr) < 0 && | |
4627 | (linux_set_iface_flags(drv->global->ioctl_sock, | |
4628 | ifname, 0) < 0 || | |
4629 | linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, | |
4630 | addr) < 0 || | |
4631 | linux_set_iface_flags(drv->global->ioctl_sock, | |
4632 | ifname, 1) < 0)) | |
4633 | return -1; | |
2aec4f3c JM |
4634 | return -ENFILE; |
4635 | } | |
a35187e7 KH |
4636 | wpa_printf(MSG_INFO, "Try to remove and re-create %s", ifname); |
4637 | ||
4638 | /* Try to remove the interface that was already there. */ | |
4639 | nl80211_remove_iface(drv, if_nametoindex(ifname)); | |
4640 | ||
4641 | /* Try to create the interface again */ | |
fbbfcbac | 4642 | ret = nl80211_create_iface_once(drv, ifname, iftype, addr, |
d6dcfcda | 4643 | wds, handler, arg); |
a35187e7 KH |
4644 | } |
4645 | ||
3e208481 JM |
4646 | if (ret >= 0 && is_p2p_net_interface(iftype)) { |
4647 | wpa_printf(MSG_DEBUG, | |
4648 | "nl80211: Interface %s created for P2P - disable 11b rates", | |
4649 | ifname); | |
4e5cb1a3 | 4650 | nl80211_disable_11b_rates(drv, ret, 1); |
3e208481 | 4651 | } |
4e5cb1a3 | 4652 | |
a35187e7 KH |
4653 | return ret; |
4654 | } | |
0915d02c | 4655 | |
2135f224 | 4656 | |
3fd1cefb JB |
4657 | static int nl80211_setup_ap(struct i802_bss *bss) |
4658 | { | |
4659 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
4660 | ||
748c0ac0 JM |
4661 | wpa_printf(MSG_DEBUG, "nl80211: Setup AP(%s) - device_ap_sme=%d use_monitor=%d", |
4662 | bss->ifname, drv->device_ap_sme, drv->use_monitor); | |
36488c05 | 4663 | |
a11241fa JB |
4664 | /* |
4665 | * Disable Probe Request reporting unless we need it in this way for | |
4666 | * devices that include the AP SME, in the other case (unless using | |
4667 | * monitor iface) we'll get it through the nl_mgmt socket instead. | |
4668 | */ | |
4669 | if (!drv->device_ap_sme) | |
4670 | wpa_driver_nl80211_probe_req_report(bss, 0); | |
4671 | ||
4672 | if (!drv->device_ap_sme && !drv->use_monitor) | |
4673 | if (nl80211_mgmt_subscribe_ap(bss)) | |
4674 | return -1; | |
4675 | ||
a6cc0602 JM |
4676 | if (drv->device_ap_sme && !drv->use_monitor) |
4677 | if (nl80211_mgmt_subscribe_ap_dev_sme(bss)) | |
f4830bed RM |
4678 | wpa_printf(MSG_DEBUG, |
4679 | "nl80211: Failed to subscribe for mgmt frames from SME driver - trying to run without it"); | |
a6cc0602 | 4680 | |
a11241fa | 4681 | if (!drv->device_ap_sme && drv->use_monitor && |
ea19b39f RM |
4682 | nl80211_create_monitor_interface(drv) && |
4683 | !drv->device_ap_sme) | |
3fd1cefb JB |
4684 | return -1; |
4685 | ||
4686 | if (drv->device_ap_sme && | |
4687 | wpa_driver_nl80211_probe_req_report(bss, 1) < 0) { | |
4688 | wpa_printf(MSG_DEBUG, "nl80211: Failed to enable " | |
4689 | "Probe Request frame reporting in AP mode"); | |
4690 | /* Try to survive without this */ | |
4691 | } | |
4692 | ||
4693 | return 0; | |
4694 | } | |
4695 | ||
4696 | ||
4697 | static void nl80211_teardown_ap(struct i802_bss *bss) | |
4698 | { | |
4699 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
4700 | ||
748c0ac0 JM |
4701 | wpa_printf(MSG_DEBUG, "nl80211: Teardown AP(%s) - device_ap_sme=%d use_monitor=%d", |
4702 | bss->ifname, drv->device_ap_sme, drv->use_monitor); | |
a6cc0602 | 4703 | if (drv->device_ap_sme) { |
3fd1cefb | 4704 | wpa_driver_nl80211_probe_req_report(bss, 0); |
a6cc0602 JM |
4705 | if (!drv->use_monitor) |
4706 | nl80211_mgmt_unsubscribe(bss, "AP teardown (dev SME)"); | |
4707 | } else if (drv->use_monitor) | |
3fd1cefb | 4708 | nl80211_remove_monitor_interface(drv); |
a11241fa | 4709 | else |
36488c05 | 4710 | nl80211_mgmt_unsubscribe(bss, "AP teardown"); |
a11241fa | 4711 | |
3fd1cefb JB |
4712 | bss->beacon_set = 0; |
4713 | } | |
4714 | ||
4715 | ||
f10bfc9a JM |
4716 | static int nl80211_send_eapol_data(struct i802_bss *bss, |
4717 | const u8 *addr, const u8 *data, | |
d12dab4c | 4718 | size_t data_len) |
f10bfc9a | 4719 | { |
d12dab4c JB |
4720 | struct sockaddr_ll ll; |
4721 | int ret; | |
4722 | ||
4723 | if (bss->drv->eapol_tx_sock < 0) { | |
4724 | wpa_printf(MSG_DEBUG, "nl80211: No socket to send EAPOL"); | |
f10bfc9a JM |
4725 | return -1; |
4726 | } | |
4727 | ||
d12dab4c JB |
4728 | os_memset(&ll, 0, sizeof(ll)); |
4729 | ll.sll_family = AF_PACKET; | |
4730 | ll.sll_ifindex = bss->ifindex; | |
4731 | ll.sll_protocol = htons(ETH_P_PAE); | |
4732 | ll.sll_halen = ETH_ALEN; | |
4733 | os_memcpy(ll.sll_addr, addr, ETH_ALEN); | |
4734 | ret = sendto(bss->drv->eapol_tx_sock, data, data_len, 0, | |
4735 | (struct sockaddr *) &ll, sizeof(ll)); | |
4736 | if (ret < 0) | |
4737 | wpa_printf(MSG_ERROR, "nl80211: EAPOL TX: %s", | |
4738 | strerror(errno)); | |
4739 | ||
4740 | return ret; | |
f10bfc9a | 4741 | } |
5fb1a232 | 4742 | |
f10bfc9a | 4743 | |
db149ac9 JM |
4744 | static const u8 rfc1042_header[6] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 }; |
4745 | ||
4746 | static int wpa_driver_nl80211_hapd_send_eapol( | |
4747 | void *priv, const u8 *addr, const u8 *data, | |
4378fc14 | 4748 | size_t data_len, int encrypt, const u8 *own_addr, u32 flags) |
db149ac9 | 4749 | { |
a2e40bb6 FF |
4750 | struct i802_bss *bss = priv; |
4751 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
db149ac9 JM |
4752 | struct ieee80211_hdr *hdr; |
4753 | size_t len; | |
4754 | u8 *pos; | |
4755 | int res; | |
4378fc14 | 4756 | int qos = flags & WPA_STA_WMM; |
db149ac9 | 4757 | |
a11241fa | 4758 | if (drv->device_ap_sme || !drv->use_monitor) |
d12dab4c | 4759 | return nl80211_send_eapol_data(bss, addr, data, data_len); |
f10bfc9a | 4760 | |
db149ac9 JM |
4761 | len = sizeof(*hdr) + (qos ? 2 : 0) + sizeof(rfc1042_header) + 2 + |
4762 | data_len; | |
4763 | hdr = os_zalloc(len); | |
4764 | if (hdr == NULL) { | |
7ac3616d JM |
4765 | wpa_printf(MSG_INFO, "nl80211: Failed to allocate EAPOL buffer(len=%lu)", |
4766 | (unsigned long) len); | |
db149ac9 JM |
4767 | return -1; |
4768 | } | |
4769 | ||
4770 | hdr->frame_control = | |
4771 | IEEE80211_FC(WLAN_FC_TYPE_DATA, WLAN_FC_STYPE_DATA); | |
4772 | hdr->frame_control |= host_to_le16(WLAN_FC_FROMDS); | |
4773 | if (encrypt) | |
4774 | hdr->frame_control |= host_to_le16(WLAN_FC_ISWEP); | |
db149ac9 JM |
4775 | if (qos) { |
4776 | hdr->frame_control |= | |
4777 | host_to_le16(WLAN_FC_STYPE_QOS_DATA << 4); | |
4778 | } | |
db149ac9 JM |
4779 | |
4780 | memcpy(hdr->IEEE80211_DA_FROMDS, addr, ETH_ALEN); | |
4781 | memcpy(hdr->IEEE80211_BSSID_FROMDS, own_addr, ETH_ALEN); | |
4782 | memcpy(hdr->IEEE80211_SA_FROMDS, own_addr, ETH_ALEN); | |
4783 | pos = (u8 *) (hdr + 1); | |
4784 | ||
db149ac9 | 4785 | if (qos) { |
92d521d8 FF |
4786 | /* Set highest priority in QoS header */ |
4787 | pos[0] = 7; | |
db149ac9 JM |
4788 | pos[1] = 0; |
4789 | pos += 2; | |
4790 | } | |
db149ac9 JM |
4791 | |
4792 | memcpy(pos, rfc1042_header, sizeof(rfc1042_header)); | |
4793 | pos += sizeof(rfc1042_header); | |
4794 | WPA_PUT_BE16(pos, ETH_P_PAE); | |
4795 | pos += 2; | |
4796 | memcpy(pos, data, data_len); | |
4797 | ||
55231068 | 4798 | res = wpa_driver_nl80211_send_frame(bss, (u8 *) hdr, len, encrypt, 0, |
2d3943ce | 4799 | 0, 0, 0, 0, NULL, 0); |
db149ac9 JM |
4800 | if (res < 0) { |
4801 | wpa_printf(MSG_ERROR, "i802_send_eapol - packet len: %lu - " | |
4802 | "failed: %d (%s)", | |
4803 | (unsigned long) len, errno, strerror(errno)); | |
4804 | } | |
7bf12757 | 4805 | os_free(hdr); |
db149ac9 JM |
4806 | |
4807 | return res; | |
4808 | } | |
4809 | ||
a8d6ffa4 | 4810 | |
3234cba4 | 4811 | static int wpa_driver_nl80211_sta_set_flags(void *priv, const u8 *addr, |
f97e3ce4 JM |
4812 | unsigned int total_flags, |
4813 | unsigned int flags_or, | |
4814 | unsigned int flags_and) | |
a8d6ffa4 | 4815 | { |
a2e40bb6 | 4816 | struct i802_bss *bss = priv; |
8970bae8 JB |
4817 | struct nl_msg *msg; |
4818 | struct nlattr *flags; | |
7e76ee9c | 4819 | struct nl80211_sta_flag_update upd; |
a8d6ffa4 | 4820 | |
0cd9846c JM |
4821 | wpa_printf(MSG_DEBUG, "nl80211: Set STA flags - ifname=%s addr=" MACSTR |
4822 | " total_flags=0x%x flags_or=0x%x flags_and=0x%x authorized=%d", | |
4823 | bss->ifname, MAC2STR(addr), total_flags, flags_or, flags_and, | |
4824 | !!(total_flags & WPA_STA_AUTHORIZED)); | |
4825 | ||
13f83980 | 4826 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) || |
a862e4a3 JM |
4827 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
4828 | goto fail; | |
a8d6ffa4 | 4829 | |
7e76ee9c JM |
4830 | /* |
4831 | * Backwards compatibility version using NL80211_ATTR_STA_FLAGS. This | |
4832 | * can be removed eventually. | |
4833 | */ | |
8970bae8 | 4834 | flags = nla_nest_start(msg, NL80211_ATTR_STA_FLAGS); |
a862e4a3 JM |
4835 | if (!flags || |
4836 | ((total_flags & WPA_STA_AUTHORIZED) && | |
4837 | nla_put_flag(msg, NL80211_STA_FLAG_AUTHORIZED)) || | |
4838 | ((total_flags & WPA_STA_WMM) && | |
4839 | nla_put_flag(msg, NL80211_STA_FLAG_WME)) || | |
4840 | ((total_flags & WPA_STA_SHORT_PREAMBLE) && | |
4841 | nla_put_flag(msg, NL80211_STA_FLAG_SHORT_PREAMBLE)) || | |
4842 | ((total_flags & WPA_STA_MFP) && | |
4843 | nla_put_flag(msg, NL80211_STA_FLAG_MFP)) || | |
4844 | ((total_flags & WPA_STA_TDLS_PEER) && | |
4845 | nla_put_flag(msg, NL80211_STA_FLAG_TDLS_PEER))) | |
4846 | goto fail; | |
45b722f1 | 4847 | |
8970bae8 | 4848 | nla_nest_end(msg, flags); |
a8d6ffa4 | 4849 | |
7e76ee9c JM |
4850 | os_memset(&upd, 0, sizeof(upd)); |
4851 | upd.mask = sta_flags_nl80211(flags_or | ~flags_and); | |
4852 | upd.set = sta_flags_nl80211(flags_or); | |
a862e4a3 JM |
4853 | if (nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd)) |
4854 | goto fail; | |
7e76ee9c | 4855 | |
13f83980 | 4856 | return send_and_recv_msgs(bss->drv, msg, NULL, NULL); |
a862e4a3 | 4857 | fail: |
5883168a | 4858 | nlmsg_free(msg); |
a8d6ffa4 JM |
4859 | return -ENOBUFS; |
4860 | } | |
4861 | ||
0915d02c | 4862 | |
1581b38b JM |
4863 | static int wpa_driver_nl80211_ap(struct wpa_driver_nl80211_data *drv, |
4864 | struct wpa_driver_associate_params *params) | |
4865 | { | |
708bc8e0 | 4866 | enum nl80211_iftype nlmode, old_mode; |
b1f625e0 EP |
4867 | |
4868 | if (params->p2p) { | |
046b26a2 JM |
4869 | wpa_printf(MSG_DEBUG, "nl80211: Setup AP operations for P2P " |
4870 | "group (GO)"); | |
b1f625e0 EP |
4871 | nlmode = NL80211_IFTYPE_P2P_GO; |
4872 | } else | |
4873 | nlmode = NL80211_IFTYPE_AP; | |
4874 | ||
708bc8e0 | 4875 | old_mode = drv->nlmode; |
834ee56f | 4876 | if (wpa_driver_nl80211_set_mode(drv->first_bss, nlmode)) { |
708bc8e0 JM |
4877 | nl80211_remove_monitor_interface(drv); |
4878 | return -1; | |
4879 | } | |
4880 | ||
6e9023ea JM |
4881 | if (params->freq.freq && |
4882 | nl80211_set_channel(drv->first_bss, ¶ms->freq, 0)) { | |
708bc8e0 | 4883 | if (old_mode != nlmode) |
834ee56f | 4884 | wpa_driver_nl80211_set_mode(drv->first_bss, old_mode); |
460456f8 | 4885 | nl80211_remove_monitor_interface(drv); |
1581b38b | 4886 | return -1; |
0915d02c | 4887 | } |
1581b38b | 4888 | |
1581b38b JM |
4889 | return 0; |
4890 | } | |
1581b38b JM |
4891 | |
4892 | ||
666e508c JM |
4893 | static int nl80211_leave_ibss(struct wpa_driver_nl80211_data *drv, |
4894 | int reset_mode) | |
5cc4d64b JM |
4895 | { |
4896 | struct nl_msg *msg; | |
9725b784 | 4897 | int ret; |
a862e4a3 | 4898 | |
9725b784 | 4899 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_LEAVE_IBSS); |
5cc4d64b | 4900 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
5cc4d64b JM |
4901 | if (ret) { |
4902 | wpa_printf(MSG_DEBUG, "nl80211: Leave IBSS failed: ret=%d " | |
4903 | "(%s)", ret, strerror(-ret)); | |
9725b784 JM |
4904 | } else { |
4905 | wpa_printf(MSG_DEBUG, | |
4906 | "nl80211: Leave IBSS request sent successfully"); | |
5cc4d64b JM |
4907 | } |
4908 | ||
666e508c JM |
4909 | if (reset_mode && |
4910 | wpa_driver_nl80211_set_mode(drv->first_bss, | |
5d4c78fb JM |
4911 | NL80211_IFTYPE_STATION)) { |
4912 | wpa_printf(MSG_INFO, "nl80211: Failed to set interface into " | |
4913 | "station mode"); | |
4914 | } | |
4915 | ||
5cc4d64b JM |
4916 | return ret; |
4917 | } | |
4918 | ||
4919 | ||
95ff3069 JD |
4920 | static int nl80211_ht_vht_overrides(struct nl_msg *msg, |
4921 | struct wpa_driver_associate_params *params) | |
4922 | { | |
4923 | if (params->disable_ht && nla_put_flag(msg, NL80211_ATTR_DISABLE_HT)) | |
4924 | return -1; | |
4925 | ||
4926 | if (params->htcaps && params->htcaps_mask) { | |
4927 | int sz = sizeof(struct ieee80211_ht_capabilities); | |
4928 | wpa_hexdump(MSG_DEBUG, " * htcaps", params->htcaps, sz); | |
4929 | wpa_hexdump(MSG_DEBUG, " * htcaps_mask", | |
4930 | params->htcaps_mask, sz); | |
4931 | if (nla_put(msg, NL80211_ATTR_HT_CAPABILITY, sz, | |
4932 | params->htcaps) || | |
4933 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, sz, | |
4934 | params->htcaps_mask)) | |
4935 | return -1; | |
4936 | } | |
4937 | ||
4938 | #ifdef CONFIG_VHT_OVERRIDES | |
4939 | if (params->disable_vht) { | |
4940 | wpa_printf(MSG_DEBUG, " * VHT disabled"); | |
4941 | if (nla_put_flag(msg, NL80211_ATTR_DISABLE_VHT)) | |
4942 | return -1; | |
4943 | } | |
4944 | ||
4945 | if (params->vhtcaps && params->vhtcaps_mask) { | |
4946 | int sz = sizeof(struct ieee80211_vht_capabilities); | |
4947 | wpa_hexdump(MSG_DEBUG, " * vhtcaps", params->vhtcaps, sz); | |
4948 | wpa_hexdump(MSG_DEBUG, " * vhtcaps_mask", | |
4949 | params->vhtcaps_mask, sz); | |
4950 | if (nla_put(msg, NL80211_ATTR_VHT_CAPABILITY, sz, | |
4951 | params->vhtcaps) || | |
4952 | nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, sz, | |
4953 | params->vhtcaps_mask)) | |
4954 | return -1; | |
4955 | } | |
4956 | #endif /* CONFIG_VHT_OVERRIDES */ | |
4957 | ||
4958 | return 0; | |
4959 | } | |
4960 | ||
4961 | ||
5cc4d64b JM |
4962 | static int wpa_driver_nl80211_ibss(struct wpa_driver_nl80211_data *drv, |
4963 | struct wpa_driver_associate_params *params) | |
4964 | { | |
4965 | struct nl_msg *msg; | |
4966 | int ret = -1; | |
4967 | int count = 0; | |
4968 | ||
4969 | wpa_printf(MSG_DEBUG, "nl80211: Join IBSS (ifindex=%d)", drv->ifindex); | |
4970 | ||
4ec68377 | 4971 | if (wpa_driver_nl80211_set_mode_ibss(drv->first_bss, ¶ms->freq)) { |
5cc4d64b JM |
4972 | wpa_printf(MSG_INFO, "nl80211: Failed to set interface into " |
4973 | "IBSS mode"); | |
4974 | return -1; | |
4975 | } | |
4976 | ||
4977 | retry: | |
9725b784 | 4978 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_JOIN_IBSS)) || |
a862e4a3 JM |
4979 | params->ssid == NULL || params->ssid_len > sizeof(drv->ssid)) |
4980 | goto fail; | |
5cc4d64b JM |
4981 | |
4982 | wpa_hexdump_ascii(MSG_DEBUG, " * SSID", | |
4983 | params->ssid, params->ssid_len); | |
a862e4a3 JM |
4984 | if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid)) |
4985 | goto fail; | |
5cc4d64b JM |
4986 | os_memcpy(drv->ssid, params->ssid, params->ssid_len); |
4987 | drv->ssid_len = params->ssid_len; | |
4988 | ||
85e1fad8 JM |
4989 | if (nl80211_put_freq_params(msg, ¶ms->freq) < 0 || |
4990 | nl80211_put_beacon_int(msg, params->beacon_int)) | |
a862e4a3 | 4991 | goto fail; |
5cc4d64b JM |
4992 | |
4993 | ret = nl80211_set_conn_keys(params, msg); | |
4994 | if (ret) | |
a862e4a3 | 4995 | goto fail; |
5cc4d64b | 4996 | |
913e3cf7 NC |
4997 | if (params->bssid && params->fixed_bssid) { |
4998 | wpa_printf(MSG_DEBUG, " * BSSID=" MACSTR, | |
4999 | MAC2STR(params->bssid)); | |
a862e4a3 JM |
5000 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid)) |
5001 | goto fail; | |
913e3cf7 NC |
5002 | } |
5003 | ||
4d9e6fba JD |
5004 | if (params->fixed_freq) { |
5005 | wpa_printf(MSG_DEBUG, " * fixed_freq"); | |
5006 | if (nla_put_flag(msg, NL80211_ATTR_FREQ_FIXED)) | |
5007 | goto fail; | |
5008 | } | |
5009 | ||
4848a38d JM |
5010 | if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X || |
5011 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK || | |
5012 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SHA256 || | |
5013 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256) { | |
e640888c | 5014 | wpa_printf(MSG_DEBUG, " * control port"); |
a862e4a3 JM |
5015 | if (nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT)) |
5016 | goto fail; | |
e640888c AQ |
5017 | } |
5018 | ||
a95795ad JM |
5019 | if (params->wpa_ie) { |
5020 | wpa_hexdump(MSG_DEBUG, | |
5021 | " * Extra IEs for Beacon/Probe Response frames", | |
5022 | params->wpa_ie, params->wpa_ie_len); | |
a862e4a3 JM |
5023 | if (nla_put(msg, NL80211_ATTR_IE, params->wpa_ie_len, |
5024 | params->wpa_ie)) | |
5025 | goto fail; | |
a95795ad JM |
5026 | } |
5027 | ||
e15dcf6d PK |
5028 | ret = nl80211_ht_vht_overrides(msg, params); |
5029 | if (ret < 0) | |
5030 | goto fail; | |
95ff3069 | 5031 | |
5cc4d64b JM |
5032 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
5033 | msg = NULL; | |
5034 | if (ret) { | |
5035 | wpa_printf(MSG_DEBUG, "nl80211: Join IBSS failed: ret=%d (%s)", | |
5036 | ret, strerror(-ret)); | |
5037 | count++; | |
5038 | if (ret == -EALREADY && count == 1) { | |
5039 | wpa_printf(MSG_DEBUG, "nl80211: Retry IBSS join after " | |
5040 | "forced leave"); | |
666e508c | 5041 | nl80211_leave_ibss(drv, 0); |
5cc4d64b JM |
5042 | nlmsg_free(msg); |
5043 | goto retry; | |
5044 | } | |
a862e4a3 JM |
5045 | } else { |
5046 | wpa_printf(MSG_DEBUG, | |
5047 | "nl80211: Join IBSS request sent successfully"); | |
5cc4d64b | 5048 | } |
5cc4d64b | 5049 | |
a862e4a3 | 5050 | fail: |
5cc4d64b JM |
5051 | nlmsg_free(msg); |
5052 | return ret; | |
5053 | } | |
5054 | ||
5055 | ||
a0bdd191 JM |
5056 | static int nl80211_connect_common(struct wpa_driver_nl80211_data *drv, |
5057 | struct wpa_driver_associate_params *params, | |
5058 | struct nl_msg *msg) | |
cfaab580 | 5059 | { |
cfaab580 ZY |
5060 | if (params->bssid) { |
5061 | wpa_printf(MSG_DEBUG, " * bssid=" MACSTR, | |
5062 | MAC2STR(params->bssid)); | |
a862e4a3 JM |
5063 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid)) |
5064 | return -1; | |
cfaab580 | 5065 | } |
a0bdd191 | 5066 | |
7ac7fd43 DS |
5067 | if (params->bssid_hint) { |
5068 | wpa_printf(MSG_DEBUG, " * bssid_hint=" MACSTR, | |
5069 | MAC2STR(params->bssid_hint)); | |
a862e4a3 JM |
5070 | if (nla_put(msg, NL80211_ATTR_MAC_HINT, ETH_ALEN, |
5071 | params->bssid_hint)) | |
5072 | return -1; | |
7ac7fd43 DS |
5073 | } |
5074 | ||
4ec68377 JD |
5075 | if (params->freq.freq) { |
5076 | wpa_printf(MSG_DEBUG, " * freq=%d", params->freq.freq); | |
a862e4a3 JM |
5077 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
5078 | params->freq.freq)) | |
5079 | return -1; | |
4ec68377 | 5080 | drv->assoc_freq = params->freq.freq; |
30158a0d SD |
5081 | } else |
5082 | drv->assoc_freq = 0; | |
a0bdd191 | 5083 | |
7ac7fd43 DS |
5084 | if (params->freq_hint) { |
5085 | wpa_printf(MSG_DEBUG, " * freq_hint=%d", params->freq_hint); | |
a862e4a3 JM |
5086 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ_HINT, |
5087 | params->freq_hint)) | |
5088 | return -1; | |
7ac7fd43 DS |
5089 | } |
5090 | ||
1f6c0ab8 BS |
5091 | if (params->bg_scan_period >= 0) { |
5092 | wpa_printf(MSG_DEBUG, " * bg scan period=%d", | |
5093 | params->bg_scan_period); | |
a862e4a3 JM |
5094 | if (nla_put_u16(msg, NL80211_ATTR_BG_SCAN_PERIOD, |
5095 | params->bg_scan_period)) | |
5096 | return -1; | |
1f6c0ab8 | 5097 | } |
a0bdd191 | 5098 | |
cfaab580 ZY |
5099 | if (params->ssid) { |
5100 | wpa_hexdump_ascii(MSG_DEBUG, " * SSID", | |
5101 | params->ssid, params->ssid_len); | |
a862e4a3 JM |
5102 | if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, |
5103 | params->ssid)) | |
5104 | return -1; | |
cfaab580 | 5105 | if (params->ssid_len > sizeof(drv->ssid)) |
a862e4a3 | 5106 | return -1; |
cfaab580 ZY |
5107 | os_memcpy(drv->ssid, params->ssid, params->ssid_len); |
5108 | drv->ssid_len = params->ssid_len; | |
5109 | } | |
a0bdd191 | 5110 | |
cfaab580 | 5111 | wpa_hexdump(MSG_DEBUG, " * IEs", params->wpa_ie, params->wpa_ie_len); |
a862e4a3 JM |
5112 | if (params->wpa_ie && |
5113 | nla_put(msg, NL80211_ATTR_IE, params->wpa_ie_len, params->wpa_ie)) | |
5114 | return -1; | |
cfaab580 | 5115 | |
64fa840a JM |
5116 | if (params->wpa_proto) { |
5117 | enum nl80211_wpa_versions ver = 0; | |
cfaab580 | 5118 | |
64fa840a JM |
5119 | if (params->wpa_proto & WPA_PROTO_WPA) |
5120 | ver |= NL80211_WPA_VERSION_1; | |
5121 | if (params->wpa_proto & WPA_PROTO_RSN) | |
5122 | ver |= NL80211_WPA_VERSION_2; | |
cfaab580 | 5123 | |
64fa840a | 5124 | wpa_printf(MSG_DEBUG, " * WPA Versions 0x%x", ver); |
a862e4a3 JM |
5125 | if (nla_put_u32(msg, NL80211_ATTR_WPA_VERSIONS, ver)) |
5126 | return -1; | |
cfaab580 ZY |
5127 | } |
5128 | ||
4848a38d | 5129 | if (params->pairwise_suite != WPA_CIPHER_NONE) { |
a0bdd191 JM |
5130 | u32 cipher = wpa_cipher_to_cipher_suite(params->pairwise_suite); |
5131 | wpa_printf(MSG_DEBUG, " * pairwise=0x%x", cipher); | |
a862e4a3 JM |
5132 | if (nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITES_PAIRWISE, |
5133 | cipher)) | |
5134 | return -1; | |
cfaab580 ZY |
5135 | } |
5136 | ||
ae6f9272 JM |
5137 | if (params->group_suite == WPA_CIPHER_GTK_NOT_USED && |
5138 | !(drv->capa.enc & WPA_DRIVER_CAPA_ENC_GTK_NOT_USED)) { | |
5139 | /* | |
5140 | * This is likely to work even though many drivers do not | |
5141 | * advertise support for operations without GTK. | |
5142 | */ | |
5143 | wpa_printf(MSG_DEBUG, " * skip group cipher configuration for GTK_NOT_USED due to missing driver support advertisement"); | |
5144 | } else if (params->group_suite != WPA_CIPHER_NONE) { | |
a0bdd191 JM |
5145 | u32 cipher = wpa_cipher_to_cipher_suite(params->group_suite); |
5146 | wpa_printf(MSG_DEBUG, " * group=0x%x", cipher); | |
a862e4a3 JM |
5147 | if (nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, cipher)) |
5148 | return -1; | |
cfaab580 ZY |
5149 | } |
5150 | ||
4848a38d JM |
5151 | if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X || |
5152 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK || | |
5153 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_IEEE8021X || | |
5154 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_PSK || | |
163f801e | 5155 | params->key_mgmt_suite == WPA_KEY_MGMT_CCKM || |
8802326f JJ |
5156 | params->key_mgmt_suite == WPA_KEY_MGMT_OSEN || |
5157 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SHA256 || | |
666497c8 | 5158 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256 || |
5e3b5197 JM |
5159 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SUITE_B || |
5160 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SUITE_B_192) { | |
cfaab580 ZY |
5161 | int mgmt = WLAN_AKM_SUITE_PSK; |
5162 | ||
5163 | switch (params->key_mgmt_suite) { | |
4848a38d | 5164 | case WPA_KEY_MGMT_CCKM: |
369c8d7b JM |
5165 | mgmt = WLAN_AKM_SUITE_CCKM; |
5166 | break; | |
4848a38d | 5167 | case WPA_KEY_MGMT_IEEE8021X: |
cfaab580 ZY |
5168 | mgmt = WLAN_AKM_SUITE_8021X; |
5169 | break; | |
4848a38d | 5170 | case WPA_KEY_MGMT_FT_IEEE8021X: |
6a1ce395 DG |
5171 | mgmt = WLAN_AKM_SUITE_FT_8021X; |
5172 | break; | |
4848a38d | 5173 | case WPA_KEY_MGMT_FT_PSK: |
6a1ce395 DG |
5174 | mgmt = WLAN_AKM_SUITE_FT_PSK; |
5175 | break; | |
8802326f JJ |
5176 | case WPA_KEY_MGMT_IEEE8021X_SHA256: |
5177 | mgmt = WLAN_AKM_SUITE_8021X_SHA256; | |
5178 | break; | |
5179 | case WPA_KEY_MGMT_PSK_SHA256: | |
5180 | mgmt = WLAN_AKM_SUITE_PSK_SHA256; | |
5181 | break; | |
163f801e JM |
5182 | case WPA_KEY_MGMT_OSEN: |
5183 | mgmt = WLAN_AKM_SUITE_OSEN; | |
5184 | break; | |
666497c8 JM |
5185 | case WPA_KEY_MGMT_IEEE8021X_SUITE_B: |
5186 | mgmt = WLAN_AKM_SUITE_8021X_SUITE_B; | |
5187 | break; | |
5e3b5197 JM |
5188 | case WPA_KEY_MGMT_IEEE8021X_SUITE_B_192: |
5189 | mgmt = WLAN_AKM_SUITE_8021X_SUITE_B_192; | |
5190 | break; | |
4848a38d | 5191 | case WPA_KEY_MGMT_PSK: |
cfaab580 ZY |
5192 | default: |
5193 | mgmt = WLAN_AKM_SUITE_PSK; | |
5194 | break; | |
5195 | } | |
163f801e | 5196 | wpa_printf(MSG_DEBUG, " * akm=0x%x", mgmt); |
a862e4a3 JM |
5197 | if (nla_put_u32(msg, NL80211_ATTR_AKM_SUITES, mgmt)) |
5198 | return -1; | |
cfaab580 ZY |
5199 | } |
5200 | ||
a862e4a3 JM |
5201 | if (nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT)) |
5202 | return -1; | |
a0bdd191 | 5203 | |
e3429c0b JB |
5204 | if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_NO_WPA && |
5205 | (params->pairwise_suite == WPA_CIPHER_NONE || | |
5206 | params->pairwise_suite == WPA_CIPHER_WEP104 || | |
5207 | params->pairwise_suite == WPA_CIPHER_WEP40) && | |
5208 | (nla_put_u16(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE, ETH_P_PAE) || | |
5209 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT))) | |
5210 | return -1; | |
5211 | ||
a862e4a3 JM |
5212 | if (params->mgmt_frame_protection == MGMT_FRAME_PROTECTION_REQUIRED && |
5213 | nla_put_u32(msg, NL80211_ATTR_USE_MFP, NL80211_MFP_REQUIRED)) | |
5214 | return -1; | |
a565084f | 5215 | |
58162adf AK |
5216 | if (params->rrm_used) { |
5217 | u32 drv_rrm_flags = drv->capa.rrm_flags; | |
b5d172e5 BL |
5218 | if ((!((drv_rrm_flags & |
5219 | WPA_DRIVER_FLAGS_DS_PARAM_SET_IE_IN_PROBES) && | |
5220 | (drv_rrm_flags & WPA_DRIVER_FLAGS_QUIET)) && | |
5221 | !(drv_rrm_flags & WPA_DRIVER_FLAGS_SUPPORT_RRM)) || | |
a862e4a3 JM |
5222 | nla_put_flag(msg, NL80211_ATTR_USE_RRM)) |
5223 | return -1; | |
58162adf AK |
5224 | } |
5225 | ||
95ff3069 | 5226 | if (nl80211_ht_vht_overrides(msg, params) < 0) |
a862e4a3 | 5227 | return -1; |
80e8a5ee | 5228 | |
a0bdd191 JM |
5229 | if (params->p2p) |
5230 | wpa_printf(MSG_DEBUG, " * P2P group"); | |
5231 | ||
86b5c400 LD |
5232 | if (params->pbss) { |
5233 | wpa_printf(MSG_DEBUG, " * PBSS"); | |
5234 | if (nla_put_flag(msg, NL80211_ATTR_PBSS)) | |
5235 | return -1; | |
5236 | } | |
5237 | ||
1126c078 | 5238 | drv->connect_reassoc = 0; |
00c3c4ac JM |
5239 | if (params->prev_bssid) { |
5240 | wpa_printf(MSG_DEBUG, " * prev_bssid=" MACSTR, | |
5241 | MAC2STR(params->prev_bssid)); | |
5242 | if (nla_put(msg, NL80211_ATTR_PREV_BSSID, ETH_ALEN, | |
5243 | params->prev_bssid)) | |
5244 | return -1; | |
1126c078 | 5245 | drv->connect_reassoc = 1; |
00c3c4ac JM |
5246 | } |
5247 | ||
a0bdd191 | 5248 | return 0; |
a0bdd191 JM |
5249 | } |
5250 | ||
5251 | ||
5252 | static int wpa_driver_nl80211_try_connect( | |
5253 | struct wpa_driver_nl80211_data *drv, | |
5254 | struct wpa_driver_associate_params *params) | |
5255 | { | |
5256 | struct nl_msg *msg; | |
5257 | enum nl80211_auth_type type; | |
5258 | int ret; | |
5259 | int algs; | |
5260 | ||
b658547d | 5261 | #ifdef CONFIG_DRIVER_NL80211_QCA |
b41f2684 CL |
5262 | if (params->req_key_mgmt_offload && params->psk && |
5263 | (params->key_mgmt_suite == WPA_KEY_MGMT_PSK || | |
5264 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256 || | |
5265 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_PSK)) { | |
5266 | wpa_printf(MSG_DEBUG, "nl80211: Key management set PSK"); | |
5267 | ret = issue_key_mgmt_set_key(drv, params->psk, 32); | |
5268 | if (ret) | |
5269 | return ret; | |
5270 | } | |
b658547d | 5271 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
b41f2684 | 5272 | |
9725b784 JM |
5273 | wpa_printf(MSG_DEBUG, "nl80211: Connect (ifindex=%d)", drv->ifindex); |
5274 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_CONNECT); | |
a0bdd191 JM |
5275 | if (!msg) |
5276 | return -1; | |
5277 | ||
a0bdd191 JM |
5278 | ret = nl80211_connect_common(drv, params, msg); |
5279 | if (ret) | |
a862e4a3 | 5280 | goto fail; |
a0bdd191 JM |
5281 | |
5282 | algs = 0; | |
5283 | if (params->auth_alg & WPA_AUTH_ALG_OPEN) | |
5284 | algs++; | |
5285 | if (params->auth_alg & WPA_AUTH_ALG_SHARED) | |
5286 | algs++; | |
5287 | if (params->auth_alg & WPA_AUTH_ALG_LEAP) | |
5288 | algs++; | |
5289 | if (algs > 1) { | |
5290 | wpa_printf(MSG_DEBUG, " * Leave out Auth Type for automatic " | |
5291 | "selection"); | |
5292 | goto skip_auth_type; | |
5293 | } | |
5294 | ||
5295 | if (params->auth_alg & WPA_AUTH_ALG_OPEN) | |
5296 | type = NL80211_AUTHTYPE_OPEN_SYSTEM; | |
5297 | else if (params->auth_alg & WPA_AUTH_ALG_SHARED) | |
5298 | type = NL80211_AUTHTYPE_SHARED_KEY; | |
5299 | else if (params->auth_alg & WPA_AUTH_ALG_LEAP) | |
5300 | type = NL80211_AUTHTYPE_NETWORK_EAP; | |
5301 | else if (params->auth_alg & WPA_AUTH_ALG_FT) | |
5302 | type = NL80211_AUTHTYPE_FT; | |
5303 | else | |
a862e4a3 | 5304 | goto fail; |
a0bdd191 JM |
5305 | |
5306 | wpa_printf(MSG_DEBUG, " * Auth Type %d", type); | |
a862e4a3 JM |
5307 | if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, type)) |
5308 | goto fail; | |
a0bdd191 JM |
5309 | |
5310 | skip_auth_type: | |
cfaab580 ZY |
5311 | ret = nl80211_set_conn_keys(params, msg); |
5312 | if (ret) | |
a862e4a3 | 5313 | goto fail; |
cfaab580 ZY |
5314 | |
5315 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
5316 | msg = NULL; | |
5317 | if (ret) { | |
5318 | wpa_printf(MSG_DEBUG, "nl80211: MLME connect failed: ret=%d " | |
5319 | "(%s)", ret, strerror(-ret)); | |
a862e4a3 JM |
5320 | } else { |
5321 | wpa_printf(MSG_DEBUG, | |
5322 | "nl80211: Connect request send successfully"); | |
cfaab580 | 5323 | } |
cfaab580 | 5324 | |
a862e4a3 | 5325 | fail: |
cfaab580 ZY |
5326 | nlmsg_free(msg); |
5327 | return ret; | |
5328 | ||
5329 | } | |
5330 | ||
5331 | ||
a8c5b43a CW |
5332 | static int wpa_driver_nl80211_connect( |
5333 | struct wpa_driver_nl80211_data *drv, | |
5334 | struct wpa_driver_associate_params *params) | |
5335 | { | |
0d4e3d1d JJ |
5336 | int ret; |
5337 | ||
5338 | /* Store the connection attempted bssid for future use */ | |
5339 | if (params->bssid) | |
5340 | os_memcpy(drv->auth_attempt_bssid, params->bssid, ETH_ALEN); | |
5341 | else | |
5342 | os_memset(drv->auth_attempt_bssid, 0, ETH_ALEN); | |
5343 | ||
5344 | ret = wpa_driver_nl80211_try_connect(drv, params); | |
a8c5b43a CW |
5345 | if (ret == -EALREADY) { |
5346 | /* | |
5347 | * cfg80211 does not currently accept new connections if | |
5348 | * we are already connected. As a workaround, force | |
5349 | * disconnection and try again. | |
5350 | */ | |
5351 | wpa_printf(MSG_DEBUG, "nl80211: Explicitly " | |
5352 | "disconnecting before reassociation " | |
5353 | "attempt"); | |
5354 | if (wpa_driver_nl80211_disconnect( | |
5355 | drv, WLAN_REASON_PREV_AUTH_NOT_VALID)) | |
5356 | return -1; | |
a8c5b43a CW |
5357 | ret = wpa_driver_nl80211_try_connect(drv, params); |
5358 | } | |
5359 | return ret; | |
5360 | } | |
5361 | ||
5362 | ||
c2a04078 JM |
5363 | static int wpa_driver_nl80211_associate( |
5364 | void *priv, struct wpa_driver_associate_params *params) | |
5365 | { | |
a2e40bb6 FF |
5366 | struct i802_bss *bss = priv; |
5367 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
a862e4a3 | 5368 | int ret = -1; |
c2a04078 JM |
5369 | struct nl_msg *msg; |
5370 | ||
4bd71954 JM |
5371 | nl80211_unmask_11b_rates(bss); |
5372 | ||
5cc4d64b | 5373 | if (params->mode == IEEE80211_MODE_AP) |
1581b38b | 5374 | return wpa_driver_nl80211_ap(drv, params); |
1581b38b | 5375 | |
5cc4d64b JM |
5376 | if (params->mode == IEEE80211_MODE_IBSS) |
5377 | return wpa_driver_nl80211_ibss(drv, params); | |
5378 | ||
4a867032 | 5379 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) { |
b1f625e0 EP |
5380 | enum nl80211_iftype nlmode = params->p2p ? |
5381 | NL80211_IFTYPE_P2P_CLIENT : NL80211_IFTYPE_STATION; | |
5382 | ||
5383 | if (wpa_driver_nl80211_set_mode(priv, nlmode) < 0) | |
4a867032 | 5384 | return -1; |
cfaab580 | 5385 | return wpa_driver_nl80211_connect(drv, params); |
4a867032 | 5386 | } |
cfaab580 | 5387 | |
add9b7a4 | 5388 | nl80211_mark_disconnected(drv); |
c2a04078 | 5389 | |
c2a04078 JM |
5390 | wpa_printf(MSG_DEBUG, "nl80211: Associate (ifindex=%d)", |
5391 | drv->ifindex); | |
9725b784 JM |
5392 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_ASSOCIATE); |
5393 | if (!msg) | |
5394 | return -1; | |
c2a04078 | 5395 | |
a0bdd191 JM |
5396 | ret = nl80211_connect_common(drv, params, msg); |
5397 | if (ret) | |
a862e4a3 | 5398 | goto fail; |
01652550 | 5399 | |
40a45727 JM |
5400 | if (params->fils_kek) { |
5401 | wpa_printf(MSG_DEBUG, " * FILS KEK (len=%u)", | |
5402 | (unsigned int) params->fils_kek_len); | |
5403 | if (nla_put(msg, NL80211_ATTR_FILS_KEK, params->fils_kek_len, | |
5404 | params->fils_kek)) | |
5405 | goto fail; | |
5406 | } | |
5407 | if (params->fils_nonces) { | |
5408 | wpa_hexdump(MSG_DEBUG, " * FILS nonces (for AAD)", | |
5409 | params->fils_nonces, | |
5410 | params->fils_nonces_len); | |
5411 | if (nla_put(msg, NL80211_ATTR_FILS_NONCES, | |
5412 | params->fils_nonces_len, params->fils_nonces)) | |
5413 | goto fail; | |
5414 | } | |
5415 | ||
c2a04078 JM |
5416 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
5417 | msg = NULL; | |
5418 | if (ret) { | |
3b7ea880 BG |
5419 | wpa_dbg(drv->ctx, MSG_DEBUG, |
5420 | "nl80211: MLME command failed (assoc): ret=%d (%s)", | |
5421 | ret, strerror(-ret)); | |
8856462d | 5422 | nl80211_dump_scan(drv); |
a862e4a3 JM |
5423 | } else { |
5424 | wpa_printf(MSG_DEBUG, | |
5425 | "nl80211: Association request send successfully"); | |
c2a04078 | 5426 | } |
c2a04078 | 5427 | |
a862e4a3 | 5428 | fail: |
c2a04078 JM |
5429 | nlmsg_free(msg); |
5430 | return ret; | |
5431 | } | |
3f5285e8 JM |
5432 | |
5433 | ||
ad1e68e6 | 5434 | static int nl80211_set_mode(struct wpa_driver_nl80211_data *drv, |
a1922f93 | 5435 | int ifindex, enum nl80211_iftype mode) |
3f5285e8 | 5436 | { |
3f5285e8 | 5437 | struct nl_msg *msg; |
ad1e68e6 JM |
5438 | int ret = -ENOBUFS; |
5439 | ||
a1922f93 JM |
5440 | wpa_printf(MSG_DEBUG, "nl80211: Set mode ifindex %d iftype %d (%s)", |
5441 | ifindex, mode, nl80211_iftype_str(mode)); | |
5442 | ||
56f77852 JM |
5443 | msg = nl80211_cmd_msg(drv->first_bss, 0, NL80211_CMD_SET_INTERFACE); |
5444 | if (!msg || nla_put_u32(msg, NL80211_ATTR_IFTYPE, mode)) | |
a862e4a3 | 5445 | goto fail; |
ad1e68e6 JM |
5446 | |
5447 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
5883168a | 5448 | msg = NULL; |
ad1e68e6 JM |
5449 | if (!ret) |
5450 | return 0; | |
a862e4a3 | 5451 | fail: |
5883168a | 5452 | nlmsg_free(msg); |
ad1e68e6 JM |
5453 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set interface %d to mode %d:" |
5454 | " %d (%s)", ifindex, mode, ret, strerror(-ret)); | |
5455 | return ret; | |
5456 | } | |
5457 | ||
5458 | ||
3c5d34e3 CW |
5459 | static int wpa_driver_nl80211_set_mode_impl( |
5460 | struct i802_bss *bss, | |
5461 | enum nl80211_iftype nlmode, | |
5462 | struct hostapd_freq_params *desired_freq_params) | |
ad1e68e6 | 5463 | { |
a2e40bb6 | 5464 | struct wpa_driver_nl80211_data *drv = bss->drv; |
ad1e68e6 | 5465 | int ret = -1; |
26af9dca | 5466 | int i; |
86957e62 | 5467 | int was_ap = is_ap_interface(drv->nlmode); |
671a5039 | 5468 | int res; |
ebffdbc4 | 5469 | int mode_switch_res; |
1581b38b | 5470 | |
a5a187b0 JM |
5471 | if (TEST_FAIL()) |
5472 | return -1; | |
5473 | ||
ebffdbc4 CW |
5474 | mode_switch_res = nl80211_set_mode(drv, drv->ifindex, nlmode); |
5475 | if (mode_switch_res && nlmode == nl80211_get_ifmode(bss)) | |
5476 | mode_switch_res = 0; | |
8e12685c | 5477 | |
ebffdbc4 | 5478 | if (mode_switch_res == 0) { |
ad1e68e6 | 5479 | drv->nlmode = nlmode; |
460456f8 JM |
5480 | ret = 0; |
5481 | goto done; | |
ad1e68e6 | 5482 | } |
3f5285e8 | 5483 | |
ebffdbc4 | 5484 | if (mode_switch_res == -ENODEV) |
671a5039 JM |
5485 | return -1; |
5486 | ||
460456f8 | 5487 | if (nlmode == drv->nlmode) { |
c6e8e8e4 JM |
5488 | wpa_printf(MSG_DEBUG, "nl80211: Interface already in " |
5489 | "requested mode - ignore error"); | |
460456f8 JM |
5490 | ret = 0; |
5491 | goto done; /* Already in the requested mode */ | |
5492 | } | |
3f5285e8 | 5493 | |
3f5285e8 JM |
5494 | /* mac80211 doesn't allow mode changes while the device is up, so |
5495 | * take the device down, try to set the mode again, and bring the | |
5496 | * device back up. | |
5497 | */ | |
26af9dca JM |
5498 | wpa_printf(MSG_DEBUG, "nl80211: Try mode change after setting " |
5499 | "interface down"); | |
5500 | for (i = 0; i < 10; i++) { | |
91724d6f | 5501 | res = i802_set_iface_flags(bss, 0); |
6e8183d7 JM |
5502 | if (res == -EACCES || res == -ENODEV) |
5503 | break; | |
ebffdbc4 | 5504 | if (res != 0) { |
26af9dca JM |
5505 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set " |
5506 | "interface down"); | |
ebffdbc4 CW |
5507 | os_sleep(0, 100000); |
5508 | continue; | |
5509 | } | |
3c5d34e3 CW |
5510 | |
5511 | /* | |
5512 | * Setting the mode will fail for some drivers if the phy is | |
5513 | * on a frequency that the mode is disallowed in. | |
5514 | */ | |
5515 | if (desired_freq_params) { | |
bdf5ccb2 | 5516 | res = nl80211_set_channel(bss, desired_freq_params, 0); |
3c5d34e3 CW |
5517 | if (res) { |
5518 | wpa_printf(MSG_DEBUG, | |
5519 | "nl80211: Failed to set frequency on interface"); | |
5520 | } | |
5521 | } | |
5522 | ||
ebffdbc4 CW |
5523 | /* Try to set the mode again while the interface is down */ |
5524 | mode_switch_res = nl80211_set_mode(drv, drv->ifindex, nlmode); | |
5525 | if (mode_switch_res == -EBUSY) { | |
5526 | wpa_printf(MSG_DEBUG, | |
5527 | "nl80211: Delaying mode set while interface going down"); | |
5528 | os_sleep(0, 100000); | |
5529 | continue; | |
5530 | } | |
5531 | ret = mode_switch_res; | |
5532 | break; | |
3f5285e8 JM |
5533 | } |
5534 | ||
c6e8e8e4 JM |
5535 | if (!ret) { |
5536 | wpa_printf(MSG_DEBUG, "nl80211: Mode change succeeded while " | |
5537 | "interface is down"); | |
ad1e68e6 | 5538 | drv->nlmode = nlmode; |
7d9c3698 | 5539 | drv->ignore_if_down_event = 1; |
c6e8e8e4 | 5540 | } |
ad1e68e6 | 5541 | |
ebffdbc4 CW |
5542 | /* Bring the interface back up */ |
5543 | res = linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 1); | |
5544 | if (res != 0) { | |
5545 | wpa_printf(MSG_DEBUG, | |
5546 | "nl80211: Failed to set interface up after switching mode"); | |
5547 | ret = -1; | |
5548 | } | |
5549 | ||
460456f8 | 5550 | done: |
3fd1cefb JB |
5551 | if (ret) { |
5552 | wpa_printf(MSG_DEBUG, "nl80211: Interface mode change to %d " | |
5553 | "from %d failed", nlmode, drv->nlmode); | |
5554 | return ret; | |
5555 | } | |
5556 | ||
3e208481 JM |
5557 | if (is_p2p_net_interface(nlmode)) { |
5558 | wpa_printf(MSG_DEBUG, | |
5559 | "nl80211: Interface %s mode change to P2P - disable 11b rates", | |
5560 | bss->ifname); | |
edb9bfba | 5561 | nl80211_disable_11b_rates(drv, drv->ifindex, 1); |
3e208481 JM |
5562 | } else if (drv->disabled_11b_rates) { |
5563 | wpa_printf(MSG_DEBUG, | |
5564 | "nl80211: Interface %s mode changed to non-P2P - re-enable 11b rates", | |
5565 | bss->ifname); | |
1d0c6fb1 | 5566 | nl80211_disable_11b_rates(drv, drv->ifindex, 0); |
3e208481 | 5567 | } |
edb9bfba | 5568 | |
3fd1cefb | 5569 | if (is_ap_interface(nlmode)) { |
36488c05 | 5570 | nl80211_mgmt_unsubscribe(bss, "start AP"); |
460456f8 | 5571 | /* Setup additional AP mode functionality if needed */ |
3fd1cefb | 5572 | if (nl80211_setup_ap(bss)) |
460456f8 | 5573 | return -1; |
3fd1cefb | 5574 | } else if (was_ap) { |
460456f8 | 5575 | /* Remove additional AP mode functionality */ |
3fd1cefb | 5576 | nl80211_teardown_ap(bss); |
a11241fa | 5577 | } else { |
36488c05 | 5578 | nl80211_mgmt_unsubscribe(bss, "mode change"); |
460456f8 | 5579 | } |
460456f8 | 5580 | |
afb0550a BC |
5581 | if (is_mesh_interface(nlmode) && |
5582 | nl80211_mgmt_subscribe_mesh(bss)) | |
5583 | return -1; | |
5584 | ||
873d0fcf | 5585 | if (!bss->in_deinit && !is_ap_interface(nlmode) && |
afb0550a | 5586 | !is_mesh_interface(nlmode) && |
a11241fa JB |
5587 | nl80211_mgmt_subscribe_non_ap(bss) < 0) |
5588 | wpa_printf(MSG_DEBUG, "nl80211: Failed to register Action " | |
5589 | "frame processing - ignore for now"); | |
08359050 | 5590 | |
3fd1cefb | 5591 | return 0; |
3f5285e8 JM |
5592 | } |
5593 | ||
5594 | ||
f3407c66 JM |
5595 | int wpa_driver_nl80211_set_mode(struct i802_bss *bss, |
5596 | enum nl80211_iftype nlmode) | |
3c5d34e3 CW |
5597 | { |
5598 | return wpa_driver_nl80211_set_mode_impl(bss, nlmode, NULL); | |
5599 | } | |
5600 | ||
5601 | ||
4ec68377 JD |
5602 | static int wpa_driver_nl80211_set_mode_ibss(struct i802_bss *bss, |
5603 | struct hostapd_freq_params *freq) | |
3c5d34e3 | 5604 | { |
3c5d34e3 | 5605 | return wpa_driver_nl80211_set_mode_impl(bss, NL80211_IFTYPE_ADHOC, |
4ec68377 | 5606 | freq); |
3c5d34e3 | 5607 | } |
65d645ce AS |
5608 | |
5609 | ||
3f5285e8 JM |
5610 | static int wpa_driver_nl80211_get_capa(void *priv, |
5611 | struct wpa_driver_capa *capa) | |
5612 | { | |
a2e40bb6 FF |
5613 | struct i802_bss *bss = priv; |
5614 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
65d645ce | 5615 | |
3f5285e8 JM |
5616 | if (!drv->has_capability) |
5617 | return -1; | |
5618 | os_memcpy(capa, &drv->capa, sizeof(*capa)); | |
8cd6b7bc JB |
5619 | if (drv->extended_capa && drv->extended_capa_mask) { |
5620 | capa->extended_capa = drv->extended_capa; | |
5621 | capa->extended_capa_mask = drv->extended_capa_mask; | |
5622 | capa->extended_capa_len = drv->extended_capa_len; | |
5623 | } | |
851b0c55 | 5624 | |
906bc4c7 | 5625 | return 0; |
3f5285e8 JM |
5626 | } |
5627 | ||
5628 | ||
5629 | static int wpa_driver_nl80211_set_operstate(void *priv, int state) | |
5630 | { | |
a2e40bb6 FF |
5631 | struct i802_bss *bss = priv; |
5632 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
3f5285e8 | 5633 | |
90a545cc JM |
5634 | wpa_printf(MSG_DEBUG, "nl80211: Set %s operstate %d->%d (%s)", |
5635 | bss->ifname, drv->operstate, state, | |
5636 | state ? "UP" : "DORMANT"); | |
3f5285e8 | 5637 | drv->operstate = state; |
36d84860 | 5638 | return netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, -1, |
e2d02c29 | 5639 | state ? IF_OPER_UP : IF_OPER_DORMANT); |
3f5285e8 JM |
5640 | } |
5641 | ||
01652550 JM |
5642 | |
5643 | static int wpa_driver_nl80211_set_supp_port(void *priv, int authorized) | |
5644 | { | |
a2e40bb6 FF |
5645 | struct i802_bss *bss = priv; |
5646 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
01652550 JM |
5647 | struct nl_msg *msg; |
5648 | struct nl80211_sta_flag_update upd; | |
a862e4a3 | 5649 | int ret; |
2eef5177 JM |
5650 | |
5651 | if (!drv->associated && is_zero_ether_addr(drv->bssid) && !authorized) { | |
5652 | wpa_printf(MSG_DEBUG, "nl80211: Skip set_supp_port(unauthorized) while not associated"); | |
5653 | return 0; | |
5654 | } | |
01652550 | 5655 | |
1ba51ec0 JM |
5656 | wpa_printf(MSG_DEBUG, "nl80211: Set supplicant port %sauthorized for " |
5657 | MACSTR, authorized ? "" : "un", MAC2STR(drv->bssid)); | |
5658 | ||
01652550 JM |
5659 | os_memset(&upd, 0, sizeof(upd)); |
5660 | upd.mask = BIT(NL80211_STA_FLAG_AUTHORIZED); | |
5661 | if (authorized) | |
5662 | upd.set = BIT(NL80211_STA_FLAG_AUTHORIZED); | |
a862e4a3 | 5663 | |
13f83980 | 5664 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) || |
a862e4a3 JM |
5665 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, drv->bssid) || |
5666 | nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd)) { | |
5667 | nlmsg_free(msg); | |
5668 | return -ENOBUFS; | |
5669 | } | |
01652550 | 5670 | |
2eef5177 | 5671 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
2eef5177 JM |
5672 | if (!ret) |
5673 | return 0; | |
2eef5177 JM |
5674 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set STA flag: %d (%s)", |
5675 | ret, strerror(-ret)); | |
5676 | return ret; | |
01652550 JM |
5677 | } |
5678 | ||
3f5285e8 | 5679 | |
f07ead6a JM |
5680 | /* Set kernel driver on given frequency (MHz) */ |
5681 | static int i802_set_freq(void *priv, struct hostapd_freq_params *freq) | |
c5121837 | 5682 | { |
f07ead6a | 5683 | struct i802_bss *bss = priv; |
13a524a3 | 5684 | return nl80211_set_channel(bss, freq, 0); |
c5121837 JM |
5685 | } |
5686 | ||
f7b3920c | 5687 | |
c5121837 JM |
5688 | static inline int min_int(int a, int b) |
5689 | { | |
5690 | if (a < b) | |
5691 | return a; | |
5692 | return b; | |
5693 | } | |
5694 | ||
5695 | ||
5696 | static int get_key_handler(struct nl_msg *msg, void *arg) | |
5697 | { | |
5698 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
5699 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
5700 | ||
5701 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
5702 | genlmsg_attrlen(gnlh, 0), NULL); | |
5703 | ||
5704 | /* | |
5705 | * TODO: validate the key index and mac address! | |
5706 | * Otherwise, there's a race condition as soon as | |
5707 | * the kernel starts sending key notifications. | |
5708 | */ | |
5709 | ||
5710 | if (tb[NL80211_ATTR_KEY_SEQ]) | |
5711 | memcpy(arg, nla_data(tb[NL80211_ATTR_KEY_SEQ]), | |
5712 | min_int(nla_len(tb[NL80211_ATTR_KEY_SEQ]), 6)); | |
5713 | return NL_SKIP; | |
5714 | } | |
5715 | ||
5716 | ||
5717 | static int i802_get_seqnum(const char *iface, void *priv, const u8 *addr, | |
5718 | int idx, u8 *seq) | |
5719 | { | |
a2e40bb6 FF |
5720 | struct i802_bss *bss = priv; |
5721 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
c5121837 JM |
5722 | struct nl_msg *msg; |
5723 | ||
95376e1a JM |
5724 | msg = nl80211_ifindex_msg(drv, if_nametoindex(iface), 0, |
5725 | NL80211_CMD_GET_KEY); | |
5726 | if (!msg || | |
a862e4a3 | 5727 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
95376e1a | 5728 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, idx)) { |
a862e4a3 JM |
5729 | nlmsg_free(msg); |
5730 | return -ENOBUFS; | |
5731 | } | |
c5121837 JM |
5732 | |
5733 | memset(seq, 0, 6); | |
5734 | ||
5735 | return send_and_recv_msgs(drv, msg, get_key_handler, seq); | |
c5121837 JM |
5736 | } |
5737 | ||
5738 | ||
c5121837 JM |
5739 | static int i802_set_rts(void *priv, int rts) |
5740 | { | |
a2e40bb6 FF |
5741 | struct i802_bss *bss = priv; |
5742 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
ad649451 | 5743 | struct nl_msg *msg; |
a862e4a3 | 5744 | int ret; |
ad649451 | 5745 | u32 val; |
c5121837 | 5746 | |
ad649451 JM |
5747 | if (rts >= 2347) |
5748 | val = (u32) -1; | |
5749 | else | |
5750 | val = rts; | |
c5121837 | 5751 | |
9725b784 | 5752 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_WIPHY)) || |
a862e4a3 JM |
5753 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, val)) { |
5754 | nlmsg_free(msg); | |
5755 | return -ENOBUFS; | |
5756 | } | |
ad649451 JM |
5757 | |
5758 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
5759 | if (!ret) | |
5760 | return 0; | |
ad649451 JM |
5761 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set RTS threshold %d: " |
5762 | "%d (%s)", rts, ret, strerror(-ret)); | |
5763 | return ret; | |
c5121837 JM |
5764 | } |
5765 | ||
5766 | ||
5767 | static int i802_set_frag(void *priv, int frag) | |
5768 | { | |
a2e40bb6 FF |
5769 | struct i802_bss *bss = priv; |
5770 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
ad649451 | 5771 | struct nl_msg *msg; |
a862e4a3 | 5772 | int ret; |
ad649451 | 5773 | u32 val; |
c5121837 | 5774 | |
ad649451 JM |
5775 | if (frag >= 2346) |
5776 | val = (u32) -1; | |
5777 | else | |
5778 | val = frag; | |
c5121837 | 5779 | |
9725b784 | 5780 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_WIPHY)) || |
a862e4a3 JM |
5781 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, val)) { |
5782 | nlmsg_free(msg); | |
5783 | return -ENOBUFS; | |
5784 | } | |
ad649451 JM |
5785 | |
5786 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
5787 | if (!ret) | |
5788 | return 0; | |
ad649451 JM |
5789 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set fragmentation threshold " |
5790 | "%d: %d (%s)", frag, ret, strerror(-ret)); | |
5791 | return ret; | |
c5121837 JM |
5792 | } |
5793 | ||
5794 | ||
c5121837 JM |
5795 | static int i802_flush(void *priv) |
5796 | { | |
a2e40bb6 | 5797 | struct i802_bss *bss = priv; |
c5121837 | 5798 | struct nl_msg *msg; |
82554b10 | 5799 | int res; |
c5121837 | 5800 | |
83e7bb0e JM |
5801 | wpa_printf(MSG_DEBUG, "nl80211: flush -> DEL_STATION %s (all)", |
5802 | bss->ifname); | |
c5121837 JM |
5803 | |
5804 | /* | |
5805 | * XXX: FIX! this needs to flush all VLANs too | |
5806 | */ | |
13f83980 JM |
5807 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_DEL_STATION); |
5808 | res = send_and_recv_msgs(bss->drv, msg, NULL, NULL); | |
82554b10 JM |
5809 | if (res) { |
5810 | wpa_printf(MSG_DEBUG, "nl80211: Station flush failed: ret=%d " | |
5811 | "(%s)", res, strerror(-res)); | |
5812 | } | |
5813 | return res; | |
c5121837 JM |
5814 | } |
5815 | ||
5816 | ||
5817 | static int get_sta_handler(struct nl_msg *msg, void *arg) | |
5818 | { | |
5819 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
5820 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
5821 | struct hostap_sta_driver_data *data = arg; | |
5822 | struct nlattr *stats[NL80211_STA_INFO_MAX + 1]; | |
5823 | static struct nla_policy stats_policy[NL80211_STA_INFO_MAX + 1] = { | |
5824 | [NL80211_STA_INFO_INACTIVE_TIME] = { .type = NLA_U32 }, | |
5825 | [NL80211_STA_INFO_RX_BYTES] = { .type = NLA_U32 }, | |
5826 | [NL80211_STA_INFO_TX_BYTES] = { .type = NLA_U32 }, | |
5827 | [NL80211_STA_INFO_RX_PACKETS] = { .type = NLA_U32 }, | |
5828 | [NL80211_STA_INFO_TX_PACKETS] = { .type = NLA_U32 }, | |
dc7785f8 | 5829 | [NL80211_STA_INFO_TX_FAILED] = { .type = NLA_U32 }, |
43022abd NL |
5830 | [NL80211_STA_INFO_RX_BYTES64] = { .type = NLA_U64 }, |
5831 | [NL80211_STA_INFO_TX_BYTES64] = { .type = NLA_U64 }, | |
c5121837 JM |
5832 | }; |
5833 | ||
5834 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
5835 | genlmsg_attrlen(gnlh, 0), NULL); | |
5836 | ||
5837 | /* | |
5838 | * TODO: validate the interface and mac address! | |
5839 | * Otherwise, there's a race condition as soon as | |
5840 | * the kernel starts sending station notifications. | |
5841 | */ | |
5842 | ||
5843 | if (!tb[NL80211_ATTR_STA_INFO]) { | |
5844 | wpa_printf(MSG_DEBUG, "sta stats missing!"); | |
5845 | return NL_SKIP; | |
5846 | } | |
5847 | if (nla_parse_nested(stats, NL80211_STA_INFO_MAX, | |
5848 | tb[NL80211_ATTR_STA_INFO], | |
5849 | stats_policy)) { | |
5850 | wpa_printf(MSG_DEBUG, "failed to parse nested attributes!"); | |
5851 | return NL_SKIP; | |
5852 | } | |
5853 | ||
5854 | if (stats[NL80211_STA_INFO_INACTIVE_TIME]) | |
5855 | data->inactive_msec = | |
5856 | nla_get_u32(stats[NL80211_STA_INFO_INACTIVE_TIME]); | |
43022abd | 5857 | /* For backwards compatibility, fetch the 32-bit counters first. */ |
c5121837 JM |
5858 | if (stats[NL80211_STA_INFO_RX_BYTES]) |
5859 | data->rx_bytes = nla_get_u32(stats[NL80211_STA_INFO_RX_BYTES]); | |
5860 | if (stats[NL80211_STA_INFO_TX_BYTES]) | |
5861 | data->tx_bytes = nla_get_u32(stats[NL80211_STA_INFO_TX_BYTES]); | |
43022abd NL |
5862 | if (stats[NL80211_STA_INFO_RX_BYTES64] && |
5863 | stats[NL80211_STA_INFO_TX_BYTES64]) { | |
5864 | /* | |
5865 | * The driver supports 64-bit counters, so use them to override | |
5866 | * the 32-bit values. | |
5867 | */ | |
5868 | data->rx_bytes = | |
5869 | nla_get_u64(stats[NL80211_STA_INFO_RX_BYTES64]); | |
5870 | data->tx_bytes = | |
5871 | nla_get_u64(stats[NL80211_STA_INFO_TX_BYTES64]); | |
5872 | data->bytes_64bit = 1; | |
5873 | } | |
c5121837 JM |
5874 | if (stats[NL80211_STA_INFO_RX_PACKETS]) |
5875 | data->rx_packets = | |
5876 | nla_get_u32(stats[NL80211_STA_INFO_RX_PACKETS]); | |
5877 | if (stats[NL80211_STA_INFO_TX_PACKETS]) | |
5878 | data->tx_packets = | |
5879 | nla_get_u32(stats[NL80211_STA_INFO_TX_PACKETS]); | |
dc7785f8 YZ |
5880 | if (stats[NL80211_STA_INFO_TX_FAILED]) |
5881 | data->tx_retry_failed = | |
5882 | nla_get_u32(stats[NL80211_STA_INFO_TX_FAILED]); | |
c5121837 JM |
5883 | |
5884 | return NL_SKIP; | |
5885 | } | |
5886 | ||
9ebce9c5 JM |
5887 | static int i802_read_sta_data(struct i802_bss *bss, |
5888 | struct hostap_sta_driver_data *data, | |
c5121837 JM |
5889 | const u8 *addr) |
5890 | { | |
c5121837 JM |
5891 | struct nl_msg *msg; |
5892 | ||
13f83980 JM |
5893 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_GET_STATION)) || |
5894 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { | |
a862e4a3 JM |
5895 | nlmsg_free(msg); |
5896 | return -ENOBUFS; | |
5897 | } | |
c5121837 | 5898 | |
13f83980 | 5899 | return send_and_recv_msgs(bss->drv, msg, get_sta_handler, data); |
c5121837 JM |
5900 | } |
5901 | ||
5902 | ||
c5121837 JM |
5903 | static int i802_set_tx_queue_params(void *priv, int queue, int aifs, |
5904 | int cw_min, int cw_max, int burst_time) | |
5905 | { | |
a2e40bb6 FF |
5906 | struct i802_bss *bss = priv; |
5907 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
c5121837 JM |
5908 | struct nl_msg *msg; |
5909 | struct nlattr *txq, *params; | |
5910 | ||
13f83980 | 5911 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_WIPHY); |
c5121837 JM |
5912 | if (!msg) |
5913 | return -1; | |
5914 | ||
c5121837 JM |
5915 | txq = nla_nest_start(msg, NL80211_ATTR_WIPHY_TXQ_PARAMS); |
5916 | if (!txq) | |
a862e4a3 | 5917 | goto fail; |
c5121837 JM |
5918 | |
5919 | /* We are only sending parameters for a single TXQ at a time */ | |
5920 | params = nla_nest_start(msg, 1); | |
5921 | if (!params) | |
a862e4a3 | 5922 | goto fail; |
c5121837 | 5923 | |
7e3c1781 JM |
5924 | switch (queue) { |
5925 | case 0: | |
a862e4a3 JM |
5926 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_VO)) |
5927 | goto fail; | |
7e3c1781 JM |
5928 | break; |
5929 | case 1: | |
a862e4a3 JM |
5930 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_VI)) |
5931 | goto fail; | |
7e3c1781 JM |
5932 | break; |
5933 | case 2: | |
a862e4a3 JM |
5934 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_BE)) |
5935 | goto fail; | |
7e3c1781 JM |
5936 | break; |
5937 | case 3: | |
a862e4a3 JM |
5938 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_BK)) |
5939 | goto fail; | |
7e3c1781 JM |
5940 | break; |
5941 | } | |
c5121837 JM |
5942 | /* Burst time is configured in units of 0.1 msec and TXOP parameter in |
5943 | * 32 usec, so need to convert the value here. */ | |
a862e4a3 JM |
5944 | if (nla_put_u16(msg, NL80211_TXQ_ATTR_TXOP, |
5945 | (burst_time * 100 + 16) / 32) || | |
5946 | nla_put_u16(msg, NL80211_TXQ_ATTR_CWMIN, cw_min) || | |
5947 | nla_put_u16(msg, NL80211_TXQ_ATTR_CWMAX, cw_max) || | |
5948 | nla_put_u8(msg, NL80211_TXQ_ATTR_AIFS, aifs)) | |
5949 | goto fail; | |
c5121837 JM |
5950 | |
5951 | nla_nest_end(msg, params); | |
5952 | ||
5953 | nla_nest_end(msg, txq); | |
5954 | ||
5955 | if (send_and_recv_msgs(drv, msg, NULL, NULL) == 0) | |
5956 | return 0; | |
9e088e74 | 5957 | msg = NULL; |
a862e4a3 | 5958 | fail: |
9e088e74 | 5959 | nlmsg_free(msg); |
c5121837 JM |
5960 | return -1; |
5961 | } | |
5962 | ||
5963 | ||
9ebce9c5 | 5964 | static int i802_set_sta_vlan(struct i802_bss *bss, const u8 *addr, |
c5121837 JM |
5965 | const char *ifname, int vlan_id) |
5966 | { | |
a2e40bb6 | 5967 | struct wpa_driver_nl80211_data *drv = bss->drv; |
c5121837 | 5968 | struct nl_msg *msg; |
a862e4a3 | 5969 | int ret; |
c5121837 | 5970 | |
bbc706a3 JM |
5971 | wpa_printf(MSG_DEBUG, "nl80211: %s[%d]: set_sta_vlan(" MACSTR |
5972 | ", ifname=%s[%d], vlan_id=%d)", | |
5973 | bss->ifname, if_nametoindex(bss->ifname), | |
5974 | MAC2STR(addr), ifname, if_nametoindex(ifname), vlan_id); | |
13f83980 | 5975 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) || |
a862e4a3 JM |
5976 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
5977 | nla_put_u32(msg, NL80211_ATTR_STA_VLAN, if_nametoindex(ifname))) { | |
5978 | nlmsg_free(msg); | |
5979 | return -ENOBUFS; | |
5980 | } | |
c5121837 | 5981 | |
cd1d72c1 JM |
5982 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
5983 | if (ret < 0) { | |
5984 | wpa_printf(MSG_ERROR, "nl80211: NL80211_ATTR_STA_VLAN (addr=" | |
5985 | MACSTR " ifname=%s vlan_id=%d) failed: %d (%s)", | |
5986 | MAC2STR(addr), ifname, vlan_id, ret, | |
5987 | strerror(-ret)); | |
5988 | } | |
cd1d72c1 | 5989 | return ret; |
c5121837 JM |
5990 | } |
5991 | ||
fbbfcbac | 5992 | |
c5121837 JM |
5993 | static int i802_get_inact_sec(void *priv, const u8 *addr) |
5994 | { | |
5995 | struct hostap_sta_driver_data data; | |
5996 | int ret; | |
5997 | ||
7824bf77 | 5998 | os_memset(&data, 0, sizeof(data)); |
c5121837 JM |
5999 | data.inactive_msec = (unsigned long) -1; |
6000 | ret = i802_read_sta_data(priv, &data, addr); | |
b9749bac MH |
6001 | if (ret == -ENOENT) |
6002 | return -ENOENT; | |
c5121837 JM |
6003 | if (ret || data.inactive_msec == (unsigned long) -1) |
6004 | return -1; | |
6005 | return data.inactive_msec / 1000; | |
6006 | } | |
6007 | ||
6008 | ||
6009 | static int i802_sta_clear_stats(void *priv, const u8 *addr) | |
6010 | { | |
6011 | #if 0 | |
6012 | /* TODO */ | |
6013 | #endif | |
6014 | return 0; | |
6015 | } | |
6016 | ||
6017 | ||
731723a5 JM |
6018 | static int i802_sta_deauth(void *priv, const u8 *own_addr, const u8 *addr, |
6019 | int reason) | |
c5121837 | 6020 | { |
a2e40bb6 | 6021 | struct i802_bss *bss = priv; |
e1bd4e19 | 6022 | struct wpa_driver_nl80211_data *drv = bss->drv; |
c5121837 | 6023 | struct ieee80211_mgmt mgmt; |
05e5e615 DL |
6024 | u8 channel; |
6025 | ||
6026 | if (ieee80211_freq_to_chan(bss->freq, &channel) == | |
6027 | HOSTAPD_MODE_IEEE80211AD) { | |
6028 | /* Deauthentication is not used in DMG/IEEE 802.11ad; | |
6029 | * disassociate the STA instead. */ | |
6030 | return i802_sta_disassoc(priv, own_addr, addr, reason); | |
6031 | } | |
c5121837 | 6032 | |
0d391b03 BC |
6033 | if (is_mesh_interface(drv->nlmode)) |
6034 | return -1; | |
6035 | ||
e1bd4e19 | 6036 | if (drv->device_ap_sme) |
59d7148a | 6037 | return wpa_driver_nl80211_sta_remove(bss, addr, 1, reason); |
e1bd4e19 | 6038 | |
c5121837 JM |
6039 | memset(&mgmt, 0, sizeof(mgmt)); |
6040 | mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, | |
6041 | WLAN_FC_STYPE_DEAUTH); | |
6042 | memcpy(mgmt.da, addr, ETH_ALEN); | |
731723a5 JM |
6043 | memcpy(mgmt.sa, own_addr, ETH_ALEN); |
6044 | memcpy(mgmt.bssid, own_addr, ETH_ALEN); | |
c5121837 | 6045 | mgmt.u.deauth.reason_code = host_to_le16(reason); |
a2e40bb6 | 6046 | return wpa_driver_nl80211_send_mlme(bss, (u8 *) &mgmt, |
9f324b61 | 6047 | IEEE80211_HDRLEN + |
9ebce9c5 | 6048 | sizeof(mgmt.u.deauth), 0, 0, 0, 0, |
2d3943ce | 6049 | 0, NULL, 0); |
c5121837 JM |
6050 | } |
6051 | ||
6052 | ||
731723a5 JM |
6053 | static int i802_sta_disassoc(void *priv, const u8 *own_addr, const u8 *addr, |
6054 | int reason) | |
c5121837 | 6055 | { |
a2e40bb6 | 6056 | struct i802_bss *bss = priv; |
e1bd4e19 | 6057 | struct wpa_driver_nl80211_data *drv = bss->drv; |
c5121837 JM |
6058 | struct ieee80211_mgmt mgmt; |
6059 | ||
0d391b03 BC |
6060 | if (is_mesh_interface(drv->nlmode)) |
6061 | return -1; | |
6062 | ||
e1bd4e19 | 6063 | if (drv->device_ap_sme) |
59d7148a | 6064 | return wpa_driver_nl80211_sta_remove(bss, addr, 0, reason); |
e1bd4e19 | 6065 | |
c5121837 JM |
6066 | memset(&mgmt, 0, sizeof(mgmt)); |
6067 | mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, | |
6068 | WLAN_FC_STYPE_DISASSOC); | |
6069 | memcpy(mgmt.da, addr, ETH_ALEN); | |
731723a5 JM |
6070 | memcpy(mgmt.sa, own_addr, ETH_ALEN); |
6071 | memcpy(mgmt.bssid, own_addr, ETH_ALEN); | |
c5121837 | 6072 | mgmt.u.disassoc.reason_code = host_to_le16(reason); |
a2e40bb6 | 6073 | return wpa_driver_nl80211_send_mlme(bss, (u8 *) &mgmt, |
9f324b61 | 6074 | IEEE80211_HDRLEN + |
9ebce9c5 | 6075 | sizeof(mgmt.u.disassoc), 0, 0, 0, 0, |
2d3943ce | 6076 | 0, NULL, 0); |
c5121837 JM |
6077 | } |
6078 | ||
6079 | ||
9b4d9c8b JM |
6080 | static void dump_ifidx(struct wpa_driver_nl80211_data *drv) |
6081 | { | |
6082 | char buf[200], *pos, *end; | |
6083 | int i, res; | |
6084 | ||
6085 | pos = buf; | |
6086 | end = pos + sizeof(buf); | |
6087 | ||
6088 | for (i = 0; i < drv->num_if_indices; i++) { | |
6089 | if (!drv->if_indices[i]) | |
6090 | continue; | |
732b1d20 MB |
6091 | res = os_snprintf(pos, end - pos, " %d(%d)", |
6092 | drv->if_indices[i], | |
6093 | drv->if_indices_reason[i]); | |
d85e1fc8 | 6094 | if (os_snprintf_error(end - pos, res)) |
9b4d9c8b JM |
6095 | break; |
6096 | pos += res; | |
6097 | } | |
6098 | *pos = '\0'; | |
6099 | ||
6100 | wpa_printf(MSG_DEBUG, "nl80211: if_indices[%d]:%s", | |
6101 | drv->num_if_indices, buf); | |
6102 | } | |
6103 | ||
6104 | ||
732b1d20 MB |
6105 | static void add_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, |
6106 | int ifidx_reason) | |
f07ead6a JM |
6107 | { |
6108 | int i; | |
732b1d20 | 6109 | int *old, *old_reason; |
f07ead6a | 6110 | |
732b1d20 MB |
6111 | wpa_printf(MSG_DEBUG, |
6112 | "nl80211: Add own interface ifindex %d (ifidx_reason %d)", | |
6113 | ifidx, ifidx_reason); | |
6114 | if (have_ifidx(drv, ifidx, ifidx_reason)) { | |
b36935be MB |
6115 | wpa_printf(MSG_DEBUG, "nl80211: ifindex %d already in the list", |
6116 | ifidx); | |
6117 | return; | |
6118 | } | |
f07ead6a JM |
6119 | for (i = 0; i < drv->num_if_indices; i++) { |
6120 | if (drv->if_indices[i] == 0) { | |
6121 | drv->if_indices[i] = ifidx; | |
732b1d20 | 6122 | drv->if_indices_reason[i] = ifidx_reason; |
9b4d9c8b | 6123 | dump_ifidx(drv); |
f07ead6a JM |
6124 | return; |
6125 | } | |
6126 | } | |
6127 | ||
6128 | if (drv->if_indices != drv->default_if_indices) | |
6129 | old = drv->if_indices; | |
6130 | else | |
6131 | old = NULL; | |
6132 | ||
732b1d20 MB |
6133 | if (drv->if_indices_reason != drv->default_if_indices_reason) |
6134 | old_reason = drv->if_indices_reason; | |
6135 | else | |
6136 | old_reason = NULL; | |
6137 | ||
067ffa26 JM |
6138 | drv->if_indices = os_realloc_array(old, drv->num_if_indices + 1, |
6139 | sizeof(int)); | |
732b1d20 MB |
6140 | drv->if_indices_reason = os_realloc_array(old_reason, |
6141 | drv->num_if_indices + 1, | |
6142 | sizeof(int)); | |
f07ead6a JM |
6143 | if (!drv->if_indices) { |
6144 | if (!old) | |
6145 | drv->if_indices = drv->default_if_indices; | |
6146 | else | |
6147 | drv->if_indices = old; | |
732b1d20 MB |
6148 | } |
6149 | if (!drv->if_indices_reason) { | |
6150 | if (!old_reason) | |
6151 | drv->if_indices_reason = drv->default_if_indices_reason; | |
6152 | else | |
29eddc3d | 6153 | drv->if_indices_reason = old_reason; |
732b1d20 MB |
6154 | } |
6155 | if (!drv->if_indices || !drv->if_indices_reason) { | |
f07ead6a JM |
6156 | wpa_printf(MSG_ERROR, "Failed to reallocate memory for " |
6157 | "interfaces"); | |
6158 | wpa_printf(MSG_ERROR, "Ignoring EAPOL on interface %d", ifidx); | |
6159 | return; | |
732b1d20 MB |
6160 | } |
6161 | if (!old) | |
f07ead6a JM |
6162 | os_memcpy(drv->if_indices, drv->default_if_indices, |
6163 | sizeof(drv->default_if_indices)); | |
732b1d20 MB |
6164 | if (!old_reason) |
6165 | os_memcpy(drv->if_indices_reason, | |
6166 | drv->default_if_indices_reason, | |
6167 | sizeof(drv->default_if_indices_reason)); | |
f07ead6a | 6168 | drv->if_indices[drv->num_if_indices] = ifidx; |
732b1d20 | 6169 | drv->if_indices_reason[drv->num_if_indices] = ifidx_reason; |
f07ead6a | 6170 | drv->num_if_indices++; |
9b4d9c8b | 6171 | dump_ifidx(drv); |
f07ead6a JM |
6172 | } |
6173 | ||
6174 | ||
732b1d20 MB |
6175 | static void del_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, |
6176 | int ifidx_reason) | |
f07ead6a JM |
6177 | { |
6178 | int i; | |
6179 | ||
6180 | for (i = 0; i < drv->num_if_indices; i++) { | |
732b1d20 MB |
6181 | if ((drv->if_indices[i] == ifidx || ifidx == IFIDX_ANY) && |
6182 | (drv->if_indices_reason[i] == ifidx_reason || | |
6183 | ifidx_reason == IFIDX_ANY)) { | |
f07ead6a JM |
6184 | drv->if_indices[i] = 0; |
6185 | break; | |
6186 | } | |
6187 | } | |
9b4d9c8b | 6188 | dump_ifidx(drv); |
f07ead6a JM |
6189 | } |
6190 | ||
6191 | ||
732b1d20 MB |
6192 | static int have_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, |
6193 | int ifidx_reason) | |
f07ead6a JM |
6194 | { |
6195 | int i; | |
6196 | ||
6197 | for (i = 0; i < drv->num_if_indices; i++) | |
732b1d20 MB |
6198 | if (drv->if_indices[i] == ifidx && |
6199 | (drv->if_indices_reason[i] == ifidx_reason || | |
6200 | ifidx_reason == IFIDX_ANY)) | |
f07ead6a JM |
6201 | return 1; |
6202 | ||
6203 | return 0; | |
6204 | } | |
6205 | ||
6206 | ||
6207 | static int i802_set_wds_sta(void *priv, const u8 *addr, int aid, int val, | |
0e80ea2c | 6208 | const char *bridge_ifname, char *ifname_wds) |
f07ead6a JM |
6209 | { |
6210 | struct i802_bss *bss = priv; | |
6211 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
6212 | char name[IFNAMSIZ + 1]; | |
6213 | ||
6214 | os_snprintf(name, sizeof(name), "%s.sta%d", bss->ifname, aid); | |
69dd2967 SM |
6215 | if (ifname_wds) |
6216 | os_strlcpy(ifname_wds, name, IFNAMSIZ + 1); | |
6217 | ||
f07ead6a JM |
6218 | wpa_printf(MSG_DEBUG, "nl80211: Set WDS STA addr=" MACSTR |
6219 | " aid=%d val=%d name=%s", MAC2STR(addr), aid, val, name); | |
6220 | if (val) { | |
6221 | if (!if_nametoindex(name)) { | |
6222 | if (nl80211_create_iface(drv, name, | |
6223 | NL80211_IFTYPE_AP_VLAN, | |
2aec4f3c JM |
6224 | bss->addr, 1, NULL, NULL, 0) < |
6225 | 0) | |
f07ead6a JM |
6226 | return -1; |
6227 | if (bridge_ifname && | |
c81eff1a BG |
6228 | linux_br_add_if(drv->global->ioctl_sock, |
6229 | bridge_ifname, name) < 0) | |
f07ead6a JM |
6230 | return -1; |
6231 | } | |
75227f3a JM |
6232 | if (linux_set_iface_flags(drv->global->ioctl_sock, name, 1)) { |
6233 | wpa_printf(MSG_ERROR, "nl80211: Failed to set WDS STA " | |
6234 | "interface %s up", name); | |
6235 | } | |
f07ead6a JM |
6236 | return i802_set_sta_vlan(priv, addr, name, 0); |
6237 | } else { | |
c34e618d FF |
6238 | if (bridge_ifname) |
6239 | linux_br_del_if(drv->global->ioctl_sock, bridge_ifname, | |
6240 | name); | |
6241 | ||
f07ead6a | 6242 | i802_set_sta_vlan(priv, addr, bss->ifname, 0); |
d0595b25 FF |
6243 | nl80211_remove_iface(drv, if_nametoindex(name)); |
6244 | return 0; | |
f07ead6a JM |
6245 | } |
6246 | } | |
6247 | ||
6248 | ||
6249 | static void handle_eapol(int sock, void *eloop_ctx, void *sock_ctx) | |
6250 | { | |
6251 | struct wpa_driver_nl80211_data *drv = eloop_ctx; | |
6252 | struct sockaddr_ll lladdr; | |
6253 | unsigned char buf[3000]; | |
6254 | int len; | |
6255 | socklen_t fromlen = sizeof(lladdr); | |
6256 | ||
6257 | len = recvfrom(sock, buf, sizeof(buf), 0, | |
6258 | (struct sockaddr *)&lladdr, &fromlen); | |
6259 | if (len < 0) { | |
7ac3616d JM |
6260 | wpa_printf(MSG_ERROR, "nl80211: EAPOL recv failed: %s", |
6261 | strerror(errno)); | |
f07ead6a JM |
6262 | return; |
6263 | } | |
6264 | ||
732b1d20 | 6265 | if (have_ifidx(drv, lladdr.sll_ifindex, IFIDX_ANY)) |
f07ead6a JM |
6266 | drv_event_eapol_rx(drv->ctx, lladdr.sll_addr, buf, len); |
6267 | } | |
6268 | ||
6269 | ||
94627f6c | 6270 | static int i802_check_bridge(struct wpa_driver_nl80211_data *drv, |
e17a2477 | 6271 | struct i802_bss *bss, |
94627f6c JM |
6272 | const char *brname, const char *ifname) |
6273 | { | |
6c6678e7 | 6274 | int br_ifindex; |
94627f6c JM |
6275 | char in_br[IFNAMSIZ]; |
6276 | ||
e17a2477 | 6277 | os_strlcpy(bss->brname, brname, IFNAMSIZ); |
6c6678e7 | 6278 | br_ifindex = if_nametoindex(brname); |
6c6678e7 | 6279 | if (br_ifindex == 0) { |
94627f6c JM |
6280 | /* |
6281 | * Bridge was configured, but the bridge device does | |
6282 | * not exist. Try to add it now. | |
6283 | */ | |
c81eff1a | 6284 | if (linux_br_add(drv->global->ioctl_sock, brname) < 0) { |
94627f6c JM |
6285 | wpa_printf(MSG_ERROR, "nl80211: Failed to add the " |
6286 | "bridge interface %s: %s", | |
6287 | brname, strerror(errno)); | |
6288 | return -1; | |
6289 | } | |
e17a2477 | 6290 | bss->added_bridge = 1; |
8997613c | 6291 | br_ifindex = if_nametoindex(brname); |
732b1d20 | 6292 | add_ifidx(drv, br_ifindex, drv->ifindex); |
94627f6c | 6293 | } |
8997613c | 6294 | bss->br_ifindex = br_ifindex; |
94627f6c JM |
6295 | |
6296 | if (linux_br_get(in_br, ifname) == 0) { | |
6297 | if (os_strcmp(in_br, brname) == 0) | |
6298 | return 0; /* already in the bridge */ | |
6299 | ||
6300 | wpa_printf(MSG_DEBUG, "nl80211: Removing interface %s from " | |
6301 | "bridge %s", ifname, in_br); | |
c81eff1a BG |
6302 | if (linux_br_del_if(drv->global->ioctl_sock, in_br, ifname) < |
6303 | 0) { | |
94627f6c JM |
6304 | wpa_printf(MSG_ERROR, "nl80211: Failed to " |
6305 | "remove interface %s from bridge " | |
6306 | "%s: %s", | |
6307 | ifname, brname, strerror(errno)); | |
6308 | return -1; | |
6309 | } | |
6310 | } | |
6311 | ||
6312 | wpa_printf(MSG_DEBUG, "nl80211: Adding interface %s into bridge %s", | |
6313 | ifname, brname); | |
c81eff1a | 6314 | if (linux_br_add_if(drv->global->ioctl_sock, brname, ifname) < 0) { |
94627f6c JM |
6315 | wpa_printf(MSG_ERROR, "nl80211: Failed to add interface %s " |
6316 | "into bridge %s: %s", | |
6317 | ifname, brname, strerror(errno)); | |
6318 | return -1; | |
6319 | } | |
e17a2477 | 6320 | bss->added_if_into_bridge = 1; |
94627f6c JM |
6321 | |
6322 | return 0; | |
6323 | } | |
6324 | ||
6325 | ||
92f475b4 JM |
6326 | static void *i802_init(struct hostapd_data *hapd, |
6327 | struct wpa_init_params *params) | |
c5121837 JM |
6328 | { |
6329 | struct wpa_driver_nl80211_data *drv; | |
a2e40bb6 | 6330 | struct i802_bss *bss; |
c5121837 | 6331 | size_t i; |
cb05808c AN |
6332 | char master_ifname[IFNAMSIZ]; |
6333 | int ifindex, br_ifindex = 0; | |
94627f6c | 6334 | int br_added = 0; |
c5121837 | 6335 | |
0d547d5f JM |
6336 | bss = wpa_driver_nl80211_drv_init(hapd, params->ifname, |
6337 | params->global_priv, 1, | |
0ecff8d7 | 6338 | params->bssid, params->driver_params); |
a2e40bb6 | 6339 | if (bss == NULL) |
c5121837 | 6340 | return NULL; |
c5121837 | 6341 | |
a2e40bb6 | 6342 | drv = bss->drv; |
7635bfb0 | 6343 | |
cb05808c | 6344 | if (linux_br_get(master_ifname, params->ifname) == 0) { |
94627f6c | 6345 | wpa_printf(MSG_DEBUG, "nl80211: Interface %s is in bridge %s", |
cb05808c AN |
6346 | params->ifname, master_ifname); |
6347 | br_ifindex = if_nametoindex(master_ifname); | |
6348 | os_strlcpy(bss->brname, master_ifname, IFNAMSIZ); | |
6349 | } else if ((params->num_bridge == 0 || !params->bridge[0]) && | |
6350 | linux_master_get(master_ifname, params->ifname) == 0) { | |
6351 | wpa_printf(MSG_DEBUG, "nl80211: Interface %s is in master %s", | |
6352 | params->ifname, master_ifname); | |
6353 | /* start listening for EAPOL on the master interface */ | |
732b1d20 | 6354 | add_ifidx(drv, if_nametoindex(master_ifname), drv->ifindex); |
f2d6c17a DL |
6355 | |
6356 | /* check if master itself is under bridge */ | |
6357 | if (linux_br_get(master_ifname, master_ifname) == 0) { | |
6358 | wpa_printf(MSG_DEBUG, "nl80211: which is in bridge %s", | |
6359 | master_ifname); | |
6360 | br_ifindex = if_nametoindex(master_ifname); | |
6361 | os_strlcpy(bss->brname, master_ifname, IFNAMSIZ); | |
6362 | } | |
94627f6c | 6363 | } else { |
cb05808c | 6364 | master_ifname[0] = '\0'; |
94627f6c | 6365 | } |
cb05808c | 6366 | |
6c6678e7 | 6367 | bss->br_ifindex = br_ifindex; |
94627f6c | 6368 | |
92f475b4 | 6369 | for (i = 0; i < params->num_bridge; i++) { |
94627f6c JM |
6370 | if (params->bridge[i]) { |
6371 | ifindex = if_nametoindex(params->bridge[i]); | |
6372 | if (ifindex) | |
732b1d20 | 6373 | add_ifidx(drv, ifindex, drv->ifindex); |
94627f6c JM |
6374 | if (ifindex == br_ifindex) |
6375 | br_added = 1; | |
6376 | } | |
c5121837 | 6377 | } |
c5121837 | 6378 | |
ad1e68e6 | 6379 | /* start listening for EAPOL on the default AP interface */ |
732b1d20 | 6380 | add_ifidx(drv, drv->ifindex, IFIDX_ANY); |
ad1e68e6 | 6381 | |
5ef8e39f JM |
6382 | if (params->num_bridge && params->bridge[0]) { |
6383 | if (i802_check_bridge(drv, bss, params->bridge[0], | |
6384 | params->ifname) < 0) | |
6385 | goto failed; | |
cb05808c | 6386 | if (os_strcmp(params->bridge[0], master_ifname) != 0) |
5ef8e39f JM |
6387 | br_added = 1; |
6388 | } | |
6389 | ||
6390 | if (!br_added && br_ifindex && | |
6391 | (params->num_bridge == 0 || !params->bridge[0])) | |
732b1d20 | 6392 | add_ifidx(drv, br_ifindex, drv->ifindex); |
94627f6c | 6393 | |
97ed9a06 KP |
6394 | #ifdef CONFIG_LIBNL3_ROUTE |
6395 | if (bss->added_if_into_bridge) { | |
6396 | drv->rtnl_sk = nl_socket_alloc(); | |
6397 | if (drv->rtnl_sk == NULL) { | |
6398 | wpa_printf(MSG_ERROR, "nl80211: Failed to allocate nl_sock"); | |
6399 | goto failed; | |
6400 | } | |
6401 | ||
6402 | if (nl_connect(drv->rtnl_sk, NETLINK_ROUTE)) { | |
6403 | wpa_printf(MSG_ERROR, "nl80211: Failed to connect nl_sock to NETLINK_ROUTE: %s", | |
6404 | strerror(errno)); | |
6405 | goto failed; | |
6406 | } | |
6407 | } | |
6408 | #endif /* CONFIG_LIBNL3_ROUTE */ | |
6409 | ||
ad1e68e6 JM |
6410 | drv->eapol_sock = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_PAE)); |
6411 | if (drv->eapol_sock < 0) { | |
7ac3616d JM |
6412 | wpa_printf(MSG_ERROR, "nl80211: socket(PF_PACKET, SOCK_DGRAM, ETH_P_PAE) failed: %s", |
6413 | strerror(errno)); | |
bbaf0837 | 6414 | goto failed; |
ad1e68e6 JM |
6415 | } |
6416 | ||
6417 | if (eloop_register_read_sock(drv->eapol_sock, handle_eapol, drv, NULL)) | |
6418 | { | |
7ac3616d | 6419 | wpa_printf(MSG_INFO, "nl80211: Could not register read socket for eapol"); |
c5121837 | 6420 | goto failed; |
ad1e68e6 JM |
6421 | } |
6422 | ||
c81eff1a BG |
6423 | if (linux_get_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
6424 | params->own_addr)) | |
bbaf0837 | 6425 | goto failed; |
fee354c7 | 6426 | os_memcpy(drv->perm_addr, params->own_addr, ETH_ALEN); |
c5121837 | 6427 | |
341eebee JB |
6428 | memcpy(bss->addr, params->own_addr, ETH_ALEN); |
6429 | ||
a2e40bb6 | 6430 | return bss; |
c5121837 JM |
6431 | |
6432 | failed: | |
7635bfb0 | 6433 | wpa_driver_nl80211_deinit(bss); |
bbaf0837 JM |
6434 | return NULL; |
6435 | } | |
c5121837 | 6436 | |
c5121837 | 6437 | |
bbaf0837 JM |
6438 | static void i802_deinit(void *priv) |
6439 | { | |
9ebce9c5 JM |
6440 | struct i802_bss *bss = priv; |
6441 | wpa_driver_nl80211_deinit(bss); | |
c5121837 JM |
6442 | } |
6443 | ||
c5121837 | 6444 | |
22a7c9d7 JM |
6445 | static enum nl80211_iftype wpa_driver_nl80211_if_type( |
6446 | enum wpa_driver_if_type type) | |
6447 | { | |
6448 | switch (type) { | |
6449 | case WPA_IF_STATION: | |
9f51b113 | 6450 | return NL80211_IFTYPE_STATION; |
75bde05d JM |
6451 | case WPA_IF_P2P_CLIENT: |
6452 | case WPA_IF_P2P_GROUP: | |
9f51b113 | 6453 | return NL80211_IFTYPE_P2P_CLIENT; |
22a7c9d7 JM |
6454 | case WPA_IF_AP_VLAN: |
6455 | return NL80211_IFTYPE_AP_VLAN; | |
6456 | case WPA_IF_AP_BSS: | |
6457 | return NL80211_IFTYPE_AP; | |
9f51b113 JB |
6458 | case WPA_IF_P2P_GO: |
6459 | return NL80211_IFTYPE_P2P_GO; | |
7aad838c NS |
6460 | case WPA_IF_P2P_DEVICE: |
6461 | return NL80211_IFTYPE_P2P_DEVICE; | |
5b78493f MH |
6462 | case WPA_IF_MESH: |
6463 | return NL80211_IFTYPE_MESH_POINT; | |
98342208 AK |
6464 | default: |
6465 | return -1; | |
22a7c9d7 | 6466 | } |
22a7c9d7 JM |
6467 | } |
6468 | ||
6469 | ||
f2ed8023 JM |
6470 | static int nl80211_addr_in_use(struct nl80211_global *global, const u8 *addr) |
6471 | { | |
6472 | struct wpa_driver_nl80211_data *drv; | |
6473 | dl_list_for_each(drv, &global->interfaces, | |
6474 | struct wpa_driver_nl80211_data, list) { | |
834ee56f | 6475 | if (os_memcmp(addr, drv->first_bss->addr, ETH_ALEN) == 0) |
f2ed8023 JM |
6476 | return 1; |
6477 | } | |
6478 | return 0; | |
6479 | } | |
6480 | ||
6481 | ||
5b78493f | 6482 | static int nl80211_vif_addr(struct wpa_driver_nl80211_data *drv, u8 *new_addr) |
f2ed8023 JM |
6483 | { |
6484 | unsigned int idx; | |
6485 | ||
6486 | if (!drv->global) | |
6487 | return -1; | |
6488 | ||
834ee56f | 6489 | os_memcpy(new_addr, drv->first_bss->addr, ETH_ALEN); |
f2ed8023 | 6490 | for (idx = 0; idx < 64; idx++) { |
834ee56f | 6491 | new_addr[0] = drv->first_bss->addr[0] | 0x02; |
f2ed8023 JM |
6492 | new_addr[0] ^= idx << 2; |
6493 | if (!nl80211_addr_in_use(drv->global, new_addr)) | |
6494 | break; | |
6495 | } | |
6496 | if (idx == 64) | |
6497 | return -1; | |
6498 | ||
5b78493f | 6499 | wpa_printf(MSG_DEBUG, "nl80211: Assigned new virtual interface address " |
f2ed8023 JM |
6500 | MACSTR, MAC2STR(new_addr)); |
6501 | ||
6502 | return 0; | |
6503 | } | |
6504 | ||
6505 | ||
f632e483 AS |
6506 | struct wdev_info { |
6507 | u64 wdev_id; | |
6508 | int wdev_id_set; | |
6509 | u8 macaddr[ETH_ALEN]; | |
6510 | }; | |
6511 | ||
6512 | static int nl80211_wdev_handler(struct nl_msg *msg, void *arg) | |
e472e1b4 AS |
6513 | { |
6514 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
6515 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
f632e483 | 6516 | struct wdev_info *wi = arg; |
e472e1b4 AS |
6517 | |
6518 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
6519 | genlmsg_attrlen(gnlh, 0), NULL); | |
6520 | if (tb[NL80211_ATTR_WDEV]) { | |
f632e483 AS |
6521 | wi->wdev_id = nla_get_u64(tb[NL80211_ATTR_WDEV]); |
6522 | wi->wdev_id_set = 1; | |
e472e1b4 AS |
6523 | } |
6524 | ||
6525 | if (tb[NL80211_ATTR_MAC]) | |
f632e483 | 6526 | os_memcpy(wi->macaddr, nla_data(tb[NL80211_ATTR_MAC]), |
e472e1b4 AS |
6527 | ETH_ALEN); |
6528 | ||
6529 | return NL_SKIP; | |
6530 | } | |
6531 | ||
6532 | ||
7ab68865 | 6533 | static int wpa_driver_nl80211_if_add(void *priv, enum wpa_driver_if_type type, |
8043e725 | 6534 | const char *ifname, const u8 *addr, |
f3585c8a | 6535 | void *bss_ctx, void **drv_priv, |
e17a2477 | 6536 | char *force_ifname, u8 *if_addr, |
d8a3b66d AS |
6537 | const char *bridge, int use_existing, |
6538 | int setup_ap) | |
22a7c9d7 | 6539 | { |
e472e1b4 | 6540 | enum nl80211_iftype nlmode; |
a2e40bb6 FF |
6541 | struct i802_bss *bss = priv; |
6542 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
22a7c9d7 | 6543 | int ifidx; |
2aec4f3c | 6544 | int added = 1; |
22a7c9d7 | 6545 | |
f3585c8a JM |
6546 | if (addr) |
6547 | os_memcpy(if_addr, addr, ETH_ALEN); | |
e472e1b4 AS |
6548 | nlmode = wpa_driver_nl80211_if_type(type); |
6549 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) { | |
f632e483 AS |
6550 | struct wdev_info p2pdev_info; |
6551 | ||
6552 | os_memset(&p2pdev_info, 0, sizeof(p2pdev_info)); | |
e472e1b4 | 6553 | ifidx = nl80211_create_iface(drv, ifname, nlmode, addr, |
f632e483 | 6554 | 0, nl80211_wdev_handler, |
2aec4f3c | 6555 | &p2pdev_info, use_existing); |
f632e483 | 6556 | if (!p2pdev_info.wdev_id_set || ifidx != 0) { |
e472e1b4 AS |
6557 | wpa_printf(MSG_ERROR, "nl80211: Failed to create a P2P Device interface %s", |
6558 | ifname); | |
e472e1b4 AS |
6559 | return -1; |
6560 | } | |
f632e483 AS |
6561 | |
6562 | drv->global->if_add_wdevid = p2pdev_info.wdev_id; | |
6563 | drv->global->if_add_wdevid_set = p2pdev_info.wdev_id_set; | |
6564 | if (!is_zero_ether_addr(p2pdev_info.macaddr)) | |
6565 | os_memcpy(if_addr, p2pdev_info.macaddr, ETH_ALEN); | |
6566 | wpa_printf(MSG_DEBUG, "nl80211: New P2P Device interface %s (0x%llx) created", | |
6567 | ifname, | |
6568 | (long long unsigned int) p2pdev_info.wdev_id); | |
e472e1b4 AS |
6569 | } else { |
6570 | ifidx = nl80211_create_iface(drv, ifname, nlmode, addr, | |
2aec4f3c JM |
6571 | 0, NULL, NULL, use_existing); |
6572 | if (use_existing && ifidx == -ENFILE) { | |
6573 | added = 0; | |
6574 | ifidx = if_nametoindex(ifname); | |
6575 | } else if (ifidx < 0) { | |
e472e1b4 AS |
6576 | return -1; |
6577 | } | |
22a7c9d7 JM |
6578 | } |
6579 | ||
ab7a1add | 6580 | if (!addr) { |
8ea8a89c | 6581 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) |
ab7a1add AS |
6582 | os_memcpy(if_addr, bss->addr, ETH_ALEN); |
6583 | else if (linux_get_ifhwaddr(drv->global->ioctl_sock, | |
8ea8a89c | 6584 | ifname, if_addr) < 0) { |
2aec4f3c JM |
6585 | if (added) |
6586 | nl80211_remove_iface(drv, ifidx); | |
ab7a1add AS |
6587 | return -1; |
6588 | } | |
c55f774d JM |
6589 | } |
6590 | ||
c55f774d JM |
6591 | if (!addr && |
6592 | (type == WPA_IF_P2P_CLIENT || type == WPA_IF_P2P_GROUP || | |
8ea8a89c JM |
6593 | type == WPA_IF_P2P_GO || type == WPA_IF_MESH || |
6594 | type == WPA_IF_STATION)) { | |
6595 | /* Enforce unique address */ | |
ab7a1add | 6596 | u8 new_addr[ETH_ALEN]; |
c55f774d | 6597 | |
ab7a1add | 6598 | if (linux_get_ifhwaddr(drv->global->ioctl_sock, ifname, |
c81eff1a | 6599 | new_addr) < 0) { |
ea39367c MK |
6600 | if (added) |
6601 | nl80211_remove_iface(drv, ifidx); | |
c55f774d JM |
6602 | return -1; |
6603 | } | |
f608081c | 6604 | if (nl80211_addr_in_use(drv->global, new_addr)) { |
c55f774d | 6605 | wpa_printf(MSG_DEBUG, "nl80211: Allocate new address " |
8ea8a89c | 6606 | "for interface %s type %d", ifname, type); |
5b78493f | 6607 | if (nl80211_vif_addr(drv, new_addr) < 0) { |
ea39367c MK |
6608 | if (added) |
6609 | nl80211_remove_iface(drv, ifidx); | |
c55f774d JM |
6610 | return -1; |
6611 | } | |
c81eff1a | 6612 | if (linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, |
c55f774d | 6613 | new_addr) < 0) { |
ea39367c MK |
6614 | if (added) |
6615 | nl80211_remove_iface(drv, ifidx); | |
c55f774d JM |
6616 | return -1; |
6617 | } | |
c55f774d | 6618 | } |
f67eeb5c | 6619 | os_memcpy(if_addr, new_addr, ETH_ALEN); |
c55f774d | 6620 | } |
f3585c8a | 6621 | |
d8a3b66d | 6622 | if (type == WPA_IF_AP_BSS && setup_ap) { |
f5eb9da3 JM |
6623 | struct i802_bss *new_bss = os_zalloc(sizeof(*new_bss)); |
6624 | if (new_bss == NULL) { | |
2aec4f3c JM |
6625 | if (added) |
6626 | nl80211_remove_iface(drv, ifidx); | |
f5eb9da3 JM |
6627 | return -1; |
6628 | } | |
6629 | ||
6630 | if (bridge && | |
6631 | i802_check_bridge(drv, new_bss, bridge, ifname) < 0) { | |
6632 | wpa_printf(MSG_ERROR, "nl80211: Failed to add the new " | |
6633 | "interface %s to a bridge %s", | |
6634 | ifname, bridge); | |
2aec4f3c JM |
6635 | if (added) |
6636 | nl80211_remove_iface(drv, ifidx); | |
f5eb9da3 JM |
6637 | os_free(new_bss); |
6638 | return -1; | |
6639 | } | |
6640 | ||
c81eff1a BG |
6641 | if (linux_set_iface_flags(drv->global->ioctl_sock, ifname, 1)) |
6642 | { | |
ea39367c MK |
6643 | if (added) |
6644 | nl80211_remove_iface(drv, ifidx); | |
07179987 | 6645 | os_free(new_bss); |
22a7c9d7 JM |
6646 | return -1; |
6647 | } | |
a2e40bb6 | 6648 | os_strlcpy(new_bss->ifname, ifname, IFNAMSIZ); |
341eebee | 6649 | os_memcpy(new_bss->addr, if_addr, ETH_ALEN); |
a2e40bb6 FF |
6650 | new_bss->ifindex = ifidx; |
6651 | new_bss->drv = drv; | |
834ee56f KP |
6652 | new_bss->next = drv->first_bss->next; |
6653 | new_bss->freq = drv->first_bss->freq; | |
a5e1eb20 | 6654 | new_bss->ctx = bss_ctx; |
2aec4f3c | 6655 | new_bss->added_if = added; |
834ee56f | 6656 | drv->first_bss->next = new_bss; |
a2e40bb6 FF |
6657 | if (drv_priv) |
6658 | *drv_priv = new_bss; | |
cc7a48d1 | 6659 | nl80211_init_bss(new_bss); |
3dd1d890 YAP |
6660 | |
6661 | /* Subscribe management frames for this WPA_IF_AP_BSS */ | |
6662 | if (nl80211_setup_ap(new_bss)) | |
6663 | return -1; | |
22a7c9d7 | 6664 | } |
22a7c9d7 | 6665 | |
ff6a158b JM |
6666 | if (drv->global) |
6667 | drv->global->if_add_ifindex = ifidx; | |
6668 | ||
d1bb7aed JJ |
6669 | /* |
6670 | * Some virtual interfaces need to process EAPOL packets and events on | |
6671 | * the parent interface. This is used mainly with hostapd. | |
6672 | */ | |
6673 | if (ifidx > 0 && | |
6674 | (drv->hostapd || | |
6675 | nlmode == NL80211_IFTYPE_AP_VLAN || | |
6676 | nlmode == NL80211_IFTYPE_WDS || | |
6677 | nlmode == NL80211_IFTYPE_MONITOR)) | |
732b1d20 | 6678 | add_ifidx(drv, ifidx, IFIDX_ANY); |
b36935be | 6679 | |
22a7c9d7 JM |
6680 | return 0; |
6681 | } | |
6682 | ||
6683 | ||
9ebce9c5 | 6684 | static int wpa_driver_nl80211_if_remove(struct i802_bss *bss, |
22a7c9d7 JM |
6685 | enum wpa_driver_if_type type, |
6686 | const char *ifname) | |
6687 | { | |
a2e40bb6 | 6688 | struct wpa_driver_nl80211_data *drv = bss->drv; |
22a7c9d7 JM |
6689 | int ifindex = if_nametoindex(ifname); |
6690 | ||
2aec4f3c JM |
6691 | wpa_printf(MSG_DEBUG, "nl80211: %s(type=%d ifname=%s) ifindex=%d added_if=%d", |
6692 | __func__, type, ifname, ifindex, bss->added_if); | |
158b090c | 6693 | if (ifindex > 0 && (bss->added_if || bss->ifindex != ifindex)) |
2b72df63 | 6694 | nl80211_remove_iface(drv, ifindex); |
de884303 JM |
6695 | else if (ifindex > 0 && !bss->added_if) { |
6696 | struct wpa_driver_nl80211_data *drv2; | |
6697 | dl_list_for_each(drv2, &drv->global->interfaces, | |
732b1d20 MB |
6698 | struct wpa_driver_nl80211_data, list) { |
6699 | del_ifidx(drv2, ifindex, IFIDX_ANY); | |
6700 | del_ifidx(drv2, IFIDX_ANY, ifindex); | |
6701 | } | |
de884303 | 6702 | } |
c34e618d | 6703 | |
c34e618d FF |
6704 | if (type != WPA_IF_AP_BSS) |
6705 | return 0; | |
6706 | ||
e17a2477 | 6707 | if (bss->added_if_into_bridge) { |
c81eff1a BG |
6708 | if (linux_br_del_if(drv->global->ioctl_sock, bss->brname, |
6709 | bss->ifname) < 0) | |
e17a2477 JM |
6710 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
6711 | "interface %s from bridge %s: %s", | |
6712 | bss->ifname, bss->brname, strerror(errno)); | |
6713 | } | |
6714 | if (bss->added_bridge) { | |
c81eff1a | 6715 | if (linux_br_del(drv->global->ioctl_sock, bss->brname) < 0) |
e17a2477 JM |
6716 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
6717 | "bridge %s: %s", | |
6718 | bss->brname, strerror(errno)); | |
6719 | } | |
a2e40bb6 | 6720 | |
834ee56f | 6721 | if (bss != drv->first_bss) { |
8546ea19 | 6722 | struct i802_bss *tbss; |
a2e40bb6 | 6723 | |
2aec4f3c | 6724 | wpa_printf(MSG_DEBUG, "nl80211: Not the first BSS - remove it"); |
834ee56f | 6725 | for (tbss = drv->first_bss; tbss; tbss = tbss->next) { |
8546ea19 JM |
6726 | if (tbss->next == bss) { |
6727 | tbss->next = bss->next; | |
3dd1d890 YAP |
6728 | /* Unsubscribe management frames */ |
6729 | nl80211_teardown_ap(bss); | |
cc7a48d1 | 6730 | nl80211_destroy_bss(bss); |
5c9da160 MB |
6731 | if (!bss->added_if) |
6732 | i802_set_iface_flags(bss, 0); | |
8546ea19 JM |
6733 | os_free(bss); |
6734 | bss = NULL; | |
6735 | break; | |
6736 | } | |
22a7c9d7 | 6737 | } |
8546ea19 JM |
6738 | if (bss) |
6739 | wpa_printf(MSG_INFO, "nl80211: %s - could not find " | |
6740 | "BSS %p in the list", __func__, bss); | |
390e489c | 6741 | } else { |
2aec4f3c | 6742 | wpa_printf(MSG_DEBUG, "nl80211: First BSS - reassign context"); |
390e489c | 6743 | nl80211_teardown_ap(bss); |
2aec4f3c JM |
6744 | if (!bss->added_if && !drv->first_bss->next) |
6745 | wpa_driver_nl80211_del_beacon(drv); | |
390e489c | 6746 | nl80211_destroy_bss(bss); |
2aec4f3c JM |
6747 | if (!bss->added_if) |
6748 | i802_set_iface_flags(bss, 0); | |
390e489c KP |
6749 | if (drv->first_bss->next) { |
6750 | drv->first_bss = drv->first_bss->next; | |
6751 | drv->ctx = drv->first_bss->ctx; | |
6752 | os_free(bss); | |
6753 | } else { | |
6754 | wpa_printf(MSG_DEBUG, "nl80211: No second BSS to reassign context to"); | |
6755 | } | |
22a7c9d7 | 6756 | } |
22a7c9d7 JM |
6757 | |
6758 | return 0; | |
6759 | } | |
6760 | ||
6761 | ||
55777702 JM |
6762 | static int cookie_handler(struct nl_msg *msg, void *arg) |
6763 | { | |
6764 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
6765 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
6766 | u64 *cookie = arg; | |
6767 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
6768 | genlmsg_attrlen(gnlh, 0), NULL); | |
6769 | if (tb[NL80211_ATTR_COOKIE]) | |
6770 | *cookie = nla_get_u64(tb[NL80211_ATTR_COOKIE]); | |
6771 | return NL_SKIP; | |
6772 | } | |
6773 | ||
6774 | ||
88df0ef7 | 6775 | static int nl80211_send_frame_cmd(struct i802_bss *bss, |
5dfca53f JB |
6776 | unsigned int freq, unsigned int wait, |
6777 | const u8 *buf, size_t buf_len, | |
88df0ef7 | 6778 | u64 *cookie_out, int no_cck, int no_ack, |
2d3943ce AO |
6779 | int offchanok, const u16 *csa_offs, |
6780 | size_t csa_offs_len) | |
9884f9cc | 6781 | { |
88df0ef7 | 6782 | struct wpa_driver_nl80211_data *drv = bss->drv; |
9884f9cc JB |
6783 | struct nl_msg *msg; |
6784 | u64 cookie; | |
6785 | int ret = -1; | |
6786 | ||
cc2ada86 | 6787 | wpa_printf(MSG_MSGDUMP, "nl80211: CMD_FRAME freq=%u wait=%u no_cck=%d " |
2e3e4566 JM |
6788 | "no_ack=%d offchanok=%d", |
6789 | freq, wait, no_cck, no_ack, offchanok); | |
c91f796f | 6790 | wpa_hexdump(MSG_MSGDUMP, "CMD_FRAME", buf, buf_len); |
9884f9cc | 6791 | |
56f77852 | 6792 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_FRAME)) || |
a862e4a3 JM |
6793 | (freq && nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || |
6794 | (wait && nla_put_u32(msg, NL80211_ATTR_DURATION, wait)) || | |
6795 | (offchanok && ((drv->capa.flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX) || | |
6796 | drv->test_use_roc_tx) && | |
6797 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) || | |
6798 | (no_cck && nla_put_flag(msg, NL80211_ATTR_TX_NO_CCK_RATE)) || | |
6799 | (no_ack && nla_put_flag(msg, NL80211_ATTR_DONT_WAIT_FOR_ACK)) || | |
2d3943ce AO |
6800 | (csa_offs && nla_put(msg, NL80211_ATTR_CSA_C_OFFSETS_TX, |
6801 | csa_offs_len * sizeof(u16), csa_offs)) || | |
a862e4a3 JM |
6802 | nla_put(msg, NL80211_ATTR_FRAME, buf_len, buf)) |
6803 | goto fail; | |
9884f9cc JB |
6804 | |
6805 | cookie = 0; | |
6806 | ret = send_and_recv_msgs(drv, msg, cookie_handler, &cookie); | |
6807 | msg = NULL; | |
6808 | if (ret) { | |
6809 | wpa_printf(MSG_DEBUG, "nl80211: Frame command failed: ret=%d " | |
a05225c8 JM |
6810 | "(%s) (freq=%u wait=%u)", ret, strerror(-ret), |
6811 | freq, wait); | |
a862e4a3 JM |
6812 | } else { |
6813 | wpa_printf(MSG_MSGDUMP, "nl80211: Frame TX command accepted%s; " | |
6814 | "cookie 0x%llx", no_ack ? " (no ACK)" : "", | |
6815 | (long long unsigned int) cookie); | |
9884f9cc | 6816 | |
a862e4a3 JM |
6817 | if (cookie_out) |
6818 | *cookie_out = no_ack ? (u64) -1 : cookie; | |
759a8a3a JM |
6819 | |
6820 | if (drv->num_send_action_cookies == MAX_SEND_ACTION_COOKIES) { | |
6821 | wpa_printf(MSG_DEBUG, | |
6822 | "nl80211: Drop oldest pending send action cookie 0x%llx", | |
6823 | (long long unsigned int) | |
6824 | drv->send_action_cookies[0]); | |
6825 | os_memmove(&drv->send_action_cookies[0], | |
6826 | &drv->send_action_cookies[1], | |
6827 | (MAX_SEND_ACTION_COOKIES - 1) * | |
6828 | sizeof(u64)); | |
6829 | drv->num_send_action_cookies--; | |
6830 | } | |
6831 | drv->send_action_cookies[drv->num_send_action_cookies] = cookie; | |
6832 | drv->num_send_action_cookies++; | |
a862e4a3 | 6833 | } |
9884f9cc | 6834 | |
a862e4a3 | 6835 | fail: |
9884f9cc JB |
6836 | nlmsg_free(msg); |
6837 | return ret; | |
6838 | } | |
6839 | ||
6840 | ||
9ebce9c5 JM |
6841 | static int wpa_driver_nl80211_send_action(struct i802_bss *bss, |
6842 | unsigned int freq, | |
190b9062 | 6843 | unsigned int wait_time, |
58f6fbe0 JM |
6844 | const u8 *dst, const u8 *src, |
6845 | const u8 *bssid, | |
b106173a JM |
6846 | const u8 *data, size_t data_len, |
6847 | int no_cck) | |
58f6fbe0 | 6848 | { |
a2e40bb6 | 6849 | struct wpa_driver_nl80211_data *drv = bss->drv; |
58f6fbe0 | 6850 | int ret = -1; |
58f6fbe0 JM |
6851 | u8 *buf; |
6852 | struct ieee80211_hdr *hdr; | |
58f6fbe0 | 6853 | |
5dfca53f | 6854 | wpa_printf(MSG_DEBUG, "nl80211: Send Action frame (ifindex=%d, " |
55231068 JM |
6855 | "freq=%u MHz wait=%d ms no_cck=%d)", |
6856 | drv->ifindex, freq, wait_time, no_cck); | |
58f6fbe0 JM |
6857 | |
6858 | buf = os_zalloc(24 + data_len); | |
6859 | if (buf == NULL) | |
6860 | return ret; | |
6861 | os_memcpy(buf + 24, data, data_len); | |
6862 | hdr = (struct ieee80211_hdr *) buf; | |
6863 | hdr->frame_control = | |
6864 | IEEE80211_FC(WLAN_FC_TYPE_MGMT, WLAN_FC_STYPE_ACTION); | |
6865 | os_memcpy(hdr->addr1, dst, ETH_ALEN); | |
6866 | os_memcpy(hdr->addr2, src, ETH_ALEN); | |
6867 | os_memcpy(hdr->addr3, bssid, ETH_ALEN); | |
6868 | ||
f78f2785 JM |
6869 | if (is_ap_interface(drv->nlmode) && |
6870 | (!(drv->capa.flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX) || | |
6871 | (int) freq == bss->freq || drv->device_ap_sme || | |
6872 | !drv->use_monitor)) | |
9ebce9c5 JM |
6873 | ret = wpa_driver_nl80211_send_mlme(bss, buf, 24 + data_len, |
6874 | 0, freq, no_cck, 1, | |
2d3943ce | 6875 | wait_time, NULL, 0); |
9884f9cc | 6876 | else |
88df0ef7 | 6877 | ret = nl80211_send_frame_cmd(bss, freq, wait_time, buf, |
5dfca53f | 6878 | 24 + data_len, |
b106173a | 6879 | &drv->send_action_cookie, |
2d3943ce | 6880 | no_cck, 0, 1, NULL, 0); |
58f6fbe0 | 6881 | |
f8bf1421 | 6882 | os_free(buf); |
58f6fbe0 JM |
6883 | return ret; |
6884 | } | |
6885 | ||
6886 | ||
759a8a3a | 6887 | static void nl80211_frame_wait_cancel(struct i802_bss *bss, u64 cookie) |
5dfca53f | 6888 | { |
5dfca53f JB |
6889 | struct wpa_driver_nl80211_data *drv = bss->drv; |
6890 | struct nl_msg *msg; | |
6891 | int ret; | |
6892 | ||
316a9e4d | 6893 | wpa_printf(MSG_DEBUG, "nl80211: Cancel TX frame wait: cookie=0x%llx", |
759a8a3a | 6894 | (long long unsigned int) cookie); |
56f77852 | 6895 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_FRAME_WAIT_CANCEL)) || |
759a8a3a | 6896 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) { |
a862e4a3 JM |
6897 | nlmsg_free(msg); |
6898 | return; | |
6899 | } | |
5dfca53f JB |
6900 | |
6901 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
5dfca53f JB |
6902 | if (ret) |
6903 | wpa_printf(MSG_DEBUG, "nl80211: wait cancel failed: ret=%d " | |
6904 | "(%s)", ret, strerror(-ret)); | |
5dfca53f JB |
6905 | } |
6906 | ||
6907 | ||
759a8a3a JM |
6908 | static void wpa_driver_nl80211_send_action_cancel_wait(void *priv) |
6909 | { | |
6910 | struct i802_bss *bss = priv; | |
6911 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
6912 | unsigned int i; | |
6913 | u64 cookie; | |
6914 | ||
6915 | /* Cancel the last pending TX cookie */ | |
6916 | nl80211_frame_wait_cancel(bss, drv->send_action_cookie); | |
6917 | ||
6918 | /* | |
6919 | * Cancel the other pending TX cookies, if any. This is needed since | |
6920 | * the driver may keep a list of all pending offchannel TX operations | |
6921 | * and free up the radio only once they have expired or cancelled. | |
6922 | */ | |
6923 | for (i = drv->num_send_action_cookies; i > 0; i--) { | |
6924 | cookie = drv->send_action_cookies[i - 1]; | |
6925 | if (cookie != drv->send_action_cookie) | |
6926 | nl80211_frame_wait_cancel(bss, cookie); | |
6927 | } | |
6928 | drv->num_send_action_cookies = 0; | |
6929 | } | |
6930 | ||
6931 | ||
55777702 JM |
6932 | static int wpa_driver_nl80211_remain_on_channel(void *priv, unsigned int freq, |
6933 | unsigned int duration) | |
6934 | { | |
a2e40bb6 FF |
6935 | struct i802_bss *bss = priv; |
6936 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
55777702 JM |
6937 | struct nl_msg *msg; |
6938 | int ret; | |
6939 | u64 cookie; | |
6940 | ||
56f77852 | 6941 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_REMAIN_ON_CHANNEL)) || |
a862e4a3 JM |
6942 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
6943 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) { | |
6944 | nlmsg_free(msg); | |
6945 | return -1; | |
6946 | } | |
55777702 JM |
6947 | |
6948 | cookie = 0; | |
6949 | ret = send_and_recv_msgs(drv, msg, cookie_handler, &cookie); | |
6950 | if (ret == 0) { | |
6951 | wpa_printf(MSG_DEBUG, "nl80211: Remain-on-channel cookie " | |
6952 | "0x%llx for freq=%u MHz duration=%u", | |
6953 | (long long unsigned int) cookie, freq, duration); | |
6954 | drv->remain_on_chan_cookie = cookie; | |
531f0331 | 6955 | drv->pending_remain_on_chan = 1; |
55777702 JM |
6956 | return 0; |
6957 | } | |
6958 | wpa_printf(MSG_DEBUG, "nl80211: Failed to request remain-on-channel " | |
15ed5535 JM |
6959 | "(freq=%d duration=%u): %d (%s)", |
6960 | freq, duration, ret, strerror(-ret)); | |
55777702 JM |
6961 | return -1; |
6962 | } | |
6963 | ||
6964 | ||
6965 | static int wpa_driver_nl80211_cancel_remain_on_channel(void *priv) | |
6966 | { | |
a2e40bb6 FF |
6967 | struct i802_bss *bss = priv; |
6968 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
55777702 JM |
6969 | struct nl_msg *msg; |
6970 | int ret; | |
6971 | ||
6972 | if (!drv->pending_remain_on_chan) { | |
6973 | wpa_printf(MSG_DEBUG, "nl80211: No pending remain-on-channel " | |
6974 | "to cancel"); | |
6975 | return -1; | |
6976 | } | |
6977 | ||
6978 | wpa_printf(MSG_DEBUG, "nl80211: Cancel remain-on-channel with cookie " | |
6979 | "0x%llx", | |
6980 | (long long unsigned int) drv->remain_on_chan_cookie); | |
6981 | ||
56f77852 JM |
6982 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL); |
6983 | if (!msg || | |
a862e4a3 JM |
6984 | nla_put_u64(msg, NL80211_ATTR_COOKIE, drv->remain_on_chan_cookie)) { |
6985 | nlmsg_free(msg); | |
6986 | return -1; | |
6987 | } | |
55777702 JM |
6988 | |
6989 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
6990 | if (ret == 0) | |
6991 | return 0; | |
6992 | wpa_printf(MSG_DEBUG, "nl80211: Failed to cancel remain-on-channel: " | |
6993 | "%d (%s)", ret, strerror(-ret)); | |
55777702 JM |
6994 | return -1; |
6995 | } | |
6996 | ||
6997 | ||
9ebce9c5 | 6998 | static int wpa_driver_nl80211_probe_req_report(struct i802_bss *bss, int report) |
504e905c | 6999 | { |
a2e40bb6 | 7000 | struct wpa_driver_nl80211_data *drv = bss->drv; |
504e905c | 7001 | |
5582a5d1 | 7002 | if (!report) { |
0d891981 | 7003 | if (bss->nl_preq && drv->device_ap_sme && |
b8d87ed2 AP |
7004 | is_ap_interface(drv->nlmode) && !bss->in_deinit && |
7005 | !bss->static_ap) { | |
0d891981 JM |
7006 | /* |
7007 | * Do not disable Probe Request reporting that was | |
7008 | * enabled in nl80211_setup_ap(). | |
7009 | */ | |
7010 | wpa_printf(MSG_DEBUG, "nl80211: Skip disabling of " | |
7011 | "Probe Request reporting nl_preq=%p while " | |
7012 | "in AP mode", bss->nl_preq); | |
7013 | } else if (bss->nl_preq) { | |
36488c05 JM |
7014 | wpa_printf(MSG_DEBUG, "nl80211: Disable Probe Request " |
7015 | "reporting nl_preq=%p", bss->nl_preq); | |
5f65e9f7 | 7016 | nl80211_destroy_eloop_handle(&bss->nl_preq); |
5582a5d1 JB |
7017 | } |
7018 | return 0; | |
7019 | } | |
7020 | ||
481234cf | 7021 | if (bss->nl_preq) { |
5582a5d1 | 7022 | wpa_printf(MSG_DEBUG, "nl80211: Probe Request reporting " |
36488c05 | 7023 | "already on! nl_preq=%p", bss->nl_preq); |
5582a5d1 JB |
7024 | return 0; |
7025 | } | |
7026 | ||
481234cf JM |
7027 | bss->nl_preq = nl_create_handle(drv->global->nl_cb, "preq"); |
7028 | if (bss->nl_preq == NULL) | |
5582a5d1 | 7029 | return -1; |
36488c05 JM |
7030 | wpa_printf(MSG_DEBUG, "nl80211: Enable Probe Request " |
7031 | "reporting nl_preq=%p", bss->nl_preq); | |
5582a5d1 | 7032 | |
481234cf | 7033 | if (nl80211_register_frame(bss, bss->nl_preq, |
5582a5d1 JB |
7034 | (WLAN_FC_TYPE_MGMT << 2) | |
7035 | (WLAN_FC_STYPE_PROBE_REQ << 4), | |
a92dfde8 JB |
7036 | NULL, 0) < 0) |
7037 | goto out_err; | |
5582a5d1 | 7038 | |
5f65e9f7 JB |
7039 | nl80211_register_eloop_read(&bss->nl_preq, |
7040 | wpa_driver_nl80211_event_receive, | |
7041 | bss->nl_cb); | |
5582a5d1 | 7042 | |
504e905c | 7043 | return 0; |
5582a5d1 | 7044 | |
a92dfde8 | 7045 | out_err: |
221a59c9 | 7046 | nl_destroy_handles(&bss->nl_preq); |
5582a5d1 | 7047 | return -1; |
504e905c JM |
7048 | } |
7049 | ||
7050 | ||
4e5cb1a3 JM |
7051 | static int nl80211_disable_11b_rates(struct wpa_driver_nl80211_data *drv, |
7052 | int ifindex, int disabled) | |
7053 | { | |
7054 | struct nl_msg *msg; | |
7055 | struct nlattr *bands, *band; | |
7056 | int ret; | |
7057 | ||
3e208481 JM |
7058 | wpa_printf(MSG_DEBUG, |
7059 | "nl80211: NL80211_CMD_SET_TX_BITRATE_MASK (ifindex=%d %s)", | |
7060 | ifindex, disabled ? "NL80211_TXRATE_LEGACY=OFDM-only" : | |
7061 | "no NL80211_TXRATE_LEGACY constraint"); | |
7062 | ||
95376e1a JM |
7063 | msg = nl80211_ifindex_msg(drv, ifindex, 0, |
7064 | NL80211_CMD_SET_TX_BITRATE_MASK); | |
4e5cb1a3 JM |
7065 | if (!msg) |
7066 | return -1; | |
7067 | ||
4e5cb1a3 JM |
7068 | bands = nla_nest_start(msg, NL80211_ATTR_TX_RATES); |
7069 | if (!bands) | |
a862e4a3 | 7070 | goto fail; |
4e5cb1a3 JM |
7071 | |
7072 | /* | |
7073 | * Disable 2 GHz rates 1, 2, 5.5, 11 Mbps by masking out everything | |
7074 | * else apart from 6, 9, 12, 18, 24, 36, 48, 54 Mbps from non-MCS | |
7075 | * rates. All 5 GHz rates are left enabled. | |
7076 | */ | |
7077 | band = nla_nest_start(msg, NL80211_BAND_2GHZ); | |
a862e4a3 JM |
7078 | if (!band || |
7079 | (disabled && nla_put(msg, NL80211_TXRATE_LEGACY, 8, | |
7080 | "\x0c\x12\x18\x24\x30\x48\x60\x6c"))) | |
7081 | goto fail; | |
4e5cb1a3 JM |
7082 | nla_nest_end(msg, band); |
7083 | ||
7084 | nla_nest_end(msg, bands); | |
7085 | ||
7086 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
4e5cb1a3 JM |
7087 | if (ret) { |
7088 | wpa_printf(MSG_DEBUG, "nl80211: Set TX rates failed: ret=%d " | |
7089 | "(%s)", ret, strerror(-ret)); | |
1d0c6fb1 JM |
7090 | } else |
7091 | drv->disabled_11b_rates = disabled; | |
4e5cb1a3 JM |
7092 | |
7093 | return ret; | |
7094 | ||
a862e4a3 | 7095 | fail: |
4e5cb1a3 JM |
7096 | nlmsg_free(msg); |
7097 | return -1; | |
7098 | } | |
7099 | ||
7100 | ||
af473088 JM |
7101 | static int wpa_driver_nl80211_deinit_ap(void *priv) |
7102 | { | |
a2e40bb6 FF |
7103 | struct i802_bss *bss = priv; |
7104 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
b1f625e0 | 7105 | if (!is_ap_interface(drv->nlmode)) |
af473088 JM |
7106 | return -1; |
7107 | wpa_driver_nl80211_del_beacon(drv); | |
9bc5cfa3 | 7108 | bss->beacon_set = 0; |
60b13c20 IP |
7109 | |
7110 | /* | |
7111 | * If the P2P GO interface was dynamically added, then it is | |
7112 | * possible that the interface change to station is not possible. | |
7113 | */ | |
7114 | if (drv->nlmode == NL80211_IFTYPE_P2P_GO && bss->if_dynamic) | |
7115 | return 0; | |
7116 | ||
b1f625e0 | 7117 | return wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_STATION); |
af473088 JM |
7118 | } |
7119 | ||
7120 | ||
695c7038 SW |
7121 | static int wpa_driver_nl80211_stop_ap(void *priv) |
7122 | { | |
7123 | struct i802_bss *bss = priv; | |
7124 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
7125 | if (!is_ap_interface(drv->nlmode)) | |
7126 | return -1; | |
7127 | wpa_driver_nl80211_del_beacon(drv); | |
7128 | bss->beacon_set = 0; | |
7129 | return 0; | |
7130 | } | |
7131 | ||
7132 | ||
3c29244e EP |
7133 | static int wpa_driver_nl80211_deinit_p2p_cli(void *priv) |
7134 | { | |
7135 | struct i802_bss *bss = priv; | |
7136 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
7137 | if (drv->nlmode != NL80211_IFTYPE_P2P_CLIENT) | |
7138 | return -1; | |
60b13c20 IP |
7139 | |
7140 | /* | |
7141 | * If the P2P Client interface was dynamically added, then it is | |
7142 | * possible that the interface change to station is not possible. | |
7143 | */ | |
7144 | if (bss->if_dynamic) | |
7145 | return 0; | |
7146 | ||
3c29244e EP |
7147 | return wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_STATION); |
7148 | } | |
7149 | ||
7150 | ||
207ef3fb JM |
7151 | static void wpa_driver_nl80211_resume(void *priv) |
7152 | { | |
a2e40bb6 | 7153 | struct i802_bss *bss = priv; |
e8dc205f | 7154 | enum nl80211_iftype nlmode = nl80211_get_ifmode(bss); |
91724d6f AS |
7155 | |
7156 | if (i802_set_iface_flags(bss, 1)) | |
7157 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set interface up on resume event"); | |
e8dc205f AO |
7158 | |
7159 | if (is_p2p_net_interface(nlmode)) | |
7160 | nl80211_disable_11b_rates(bss->drv, bss->drv->ifindex, 1); | |
207ef3fb JM |
7161 | } |
7162 | ||
7163 | ||
b625473c JM |
7164 | static int nl80211_signal_monitor(void *priv, int threshold, int hysteresis) |
7165 | { | |
7166 | struct i802_bss *bss = priv; | |
7167 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8970bae8 JB |
7168 | struct nl_msg *msg; |
7169 | struct nlattr *cqm; | |
b625473c JM |
7170 | |
7171 | wpa_printf(MSG_DEBUG, "nl80211: Signal monitor threshold=%d " | |
7172 | "hysteresis=%d", threshold, hysteresis); | |
7173 | ||
13f83980 | 7174 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_CQM)) || |
a862e4a3 JM |
7175 | !(cqm = nla_nest_start(msg, NL80211_ATTR_CQM)) || |
7176 | nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THOLD, threshold) || | |
7177 | nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_HYST, hysteresis)) { | |
7178 | nlmsg_free(msg); | |
7179 | return -1; | |
7180 | } | |
8970bae8 | 7181 | nla_nest_end(msg, cqm); |
21270bb4 | 7182 | |
a862e4a3 | 7183 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
b625473c JM |
7184 | } |
7185 | ||
7186 | ||
2cc8d8f4 AO |
7187 | static int get_channel_width(struct nl_msg *msg, void *arg) |
7188 | { | |
7189 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
7190 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
7191 | struct wpa_signal_info *sig_change = arg; | |
7192 | ||
7193 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
7194 | genlmsg_attrlen(gnlh, 0), NULL); | |
7195 | ||
7196 | sig_change->center_frq1 = -1; | |
7197 | sig_change->center_frq2 = -1; | |
7198 | sig_change->chanwidth = CHAN_WIDTH_UNKNOWN; | |
7199 | ||
7200 | if (tb[NL80211_ATTR_CHANNEL_WIDTH]) { | |
7201 | sig_change->chanwidth = convert2width( | |
7202 | nla_get_u32(tb[NL80211_ATTR_CHANNEL_WIDTH])); | |
7203 | if (tb[NL80211_ATTR_CENTER_FREQ1]) | |
7204 | sig_change->center_frq1 = | |
7205 | nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ1]); | |
7206 | if (tb[NL80211_ATTR_CENTER_FREQ2]) | |
7207 | sig_change->center_frq2 = | |
7208 | nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ2]); | |
7209 | } | |
7210 | ||
7211 | return NL_SKIP; | |
7212 | } | |
7213 | ||
7214 | ||
7215 | static int nl80211_get_channel_width(struct wpa_driver_nl80211_data *drv, | |
7216 | struct wpa_signal_info *sig) | |
7217 | { | |
7218 | struct nl_msg *msg; | |
7219 | ||
9725b784 | 7220 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_GET_INTERFACE); |
2cc8d8f4 | 7221 | return send_and_recv_msgs(drv, msg, get_channel_width, sig); |
2cc8d8f4 AO |
7222 | } |
7223 | ||
7224 | ||
1c5c7273 PS |
7225 | static int nl80211_signal_poll(void *priv, struct wpa_signal_info *si) |
7226 | { | |
7227 | struct i802_bss *bss = priv; | |
7228 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
7229 | int res; | |
7230 | ||
7231 | os_memset(si, 0, sizeof(*si)); | |
7232 | res = nl80211_get_link_signal(drv, si); | |
1d6955e6 JM |
7233 | if (res) { |
7234 | if (drv->nlmode != NL80211_IFTYPE_ADHOC && | |
7235 | drv->nlmode != NL80211_IFTYPE_MESH_POINT) | |
7236 | return res; | |
7237 | si->current_signal = 0; | |
7238 | } | |
1c5c7273 | 7239 | |
2cc8d8f4 AO |
7240 | res = nl80211_get_channel_width(drv, si); |
7241 | if (res != 0) | |
7242 | return res; | |
7243 | ||
1c5c7273 PS |
7244 | return nl80211_get_link_noise(drv, si); |
7245 | } | |
7246 | ||
7247 | ||
b91ab76e JM |
7248 | static int nl80211_send_frame(void *priv, const u8 *data, size_t data_len, |
7249 | int encrypt) | |
7250 | { | |
7251 | struct i802_bss *bss = priv; | |
55231068 | 7252 | return wpa_driver_nl80211_send_frame(bss, data, data_len, encrypt, 0, |
2d3943ce | 7253 | 0, 0, 0, 0, NULL, 0); |
b91ab76e JM |
7254 | } |
7255 | ||
7256 | ||
c55f774d JM |
7257 | static int nl80211_set_param(void *priv, const char *param) |
7258 | { | |
ef24ad3e JM |
7259 | struct i802_bss *bss = priv; |
7260 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
7261 | ||
c55f774d JM |
7262 | if (param == NULL) |
7263 | return 0; | |
99a94f55 | 7264 | wpa_printf(MSG_DEBUG, "nl80211: driver param='%s'", param); |
c55f774d JM |
7265 | |
7266 | #ifdef CONFIG_P2P | |
7267 | if (os_strstr(param, "use_p2p_group_interface=1")) { | |
7268 | wpa_printf(MSG_DEBUG, "nl80211: Use separate P2P group " | |
7269 | "interface"); | |
7270 | drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_CONCURRENT; | |
7271 | drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_MGMT_AND_NON_P2P; | |
7272 | } | |
7273 | #endif /* CONFIG_P2P */ | |
7274 | ||
ef24ad3e | 7275 | if (os_strstr(param, "use_monitor=1")) |
327b01d3 | 7276 | drv->use_monitor = 1; |
327b01d3 JM |
7277 | |
7278 | if (os_strstr(param, "force_connect_cmd=1")) { | |
327b01d3 | 7279 | drv->capa.flags &= ~WPA_DRIVER_FLAGS_SME; |
b497a212 | 7280 | drv->force_connect_cmd = 1; |
327b01d3 JM |
7281 | } |
7282 | ||
ef24ad3e | 7283 | if (os_strstr(param, "force_bss_selection=1")) |
4d584d8c | 7284 | drv->capa.flags |= WPA_DRIVER_FLAGS_BSS_SELECTION; |
4d584d8c | 7285 | |
64abb725 | 7286 | if (os_strstr(param, "no_offchannel_tx=1")) { |
64abb725 JM |
7287 | drv->capa.flags &= ~WPA_DRIVER_FLAGS_OFFCHANNEL_TX; |
7288 | drv->test_use_roc_tx = 1; | |
7289 | } | |
7290 | ||
c55f774d JM |
7291 | return 0; |
7292 | } | |
7293 | ||
7294 | ||
45e3fc72 | 7295 | static void * nl80211_global_init(void *ctx) |
f2ed8023 JM |
7296 | { |
7297 | struct nl80211_global *global; | |
36d84860 BG |
7298 | struct netlink_config *cfg; |
7299 | ||
f2ed8023 JM |
7300 | global = os_zalloc(sizeof(*global)); |
7301 | if (global == NULL) | |
7302 | return NULL; | |
45e3fc72 | 7303 | global->ctx = ctx; |
c81eff1a | 7304 | global->ioctl_sock = -1; |
f2ed8023 | 7305 | dl_list_init(&global->interfaces); |
ff6a158b | 7306 | global->if_add_ifindex = -1; |
36d84860 BG |
7307 | |
7308 | cfg = os_zalloc(sizeof(*cfg)); | |
7309 | if (cfg == NULL) | |
7310 | goto err; | |
7311 | ||
7312 | cfg->ctx = global; | |
7313 | cfg->newlink_cb = wpa_driver_nl80211_event_rtm_newlink; | |
7314 | cfg->dellink_cb = wpa_driver_nl80211_event_rtm_dellink; | |
7315 | global->netlink = netlink_init(cfg); | |
7316 | if (global->netlink == NULL) { | |
7317 | os_free(cfg); | |
7318 | goto err; | |
7319 | } | |
7320 | ||
2a7b66f5 BG |
7321 | if (wpa_driver_nl80211_init_nl_global(global) < 0) |
7322 | goto err; | |
7323 | ||
c81eff1a BG |
7324 | global->ioctl_sock = socket(PF_INET, SOCK_DGRAM, 0); |
7325 | if (global->ioctl_sock < 0) { | |
7ac3616d JM |
7326 | wpa_printf(MSG_ERROR, "nl80211: socket(PF_INET,SOCK_DGRAM) failed: %s", |
7327 | strerror(errno)); | |
c81eff1a BG |
7328 | goto err; |
7329 | } | |
7330 | ||
f2ed8023 | 7331 | return global; |
36d84860 BG |
7332 | |
7333 | err: | |
7334 | nl80211_global_deinit(global); | |
7335 | return NULL; | |
f2ed8023 JM |
7336 | } |
7337 | ||
7338 | ||
7339 | static void nl80211_global_deinit(void *priv) | |
7340 | { | |
7341 | struct nl80211_global *global = priv; | |
7342 | if (global == NULL) | |
7343 | return; | |
7344 | if (!dl_list_empty(&global->interfaces)) { | |
7345 | wpa_printf(MSG_ERROR, "nl80211: %u interface(s) remain at " | |
7346 | "nl80211_global_deinit", | |
7347 | dl_list_len(&global->interfaces)); | |
7348 | } | |
36d84860 BG |
7349 | |
7350 | if (global->netlink) | |
7351 | netlink_deinit(global->netlink); | |
7352 | ||
276e2d67 BG |
7353 | nl_destroy_handles(&global->nl); |
7354 | ||
5f65e9f7 JB |
7355 | if (global->nl_event) |
7356 | nl80211_destroy_eloop_handle(&global->nl_event); | |
d6c9aab8 JB |
7357 | |
7358 | nl_cb_put(global->nl_cb); | |
2a7b66f5 | 7359 | |
c81eff1a BG |
7360 | if (global->ioctl_sock >= 0) |
7361 | close(global->ioctl_sock); | |
7362 | ||
f2ed8023 JM |
7363 | os_free(global); |
7364 | } | |
7365 | ||
7366 | ||
6859f1cb BG |
7367 | static const char * nl80211_get_radio_name(void *priv) |
7368 | { | |
7369 | struct i802_bss *bss = priv; | |
7370 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
7371 | return drv->phyname; | |
7372 | } | |
7373 | ||
7374 | ||
a6efc65d JM |
7375 | static int nl80211_pmkid(struct i802_bss *bss, int cmd, const u8 *bssid, |
7376 | const u8 *pmkid) | |
7377 | { | |
7378 | struct nl_msg *msg; | |
7379 | ||
13f83980 | 7380 | if (!(msg = nl80211_bss_msg(bss, 0, cmd)) || |
a862e4a3 JM |
7381 | (pmkid && nla_put(msg, NL80211_ATTR_PMKID, 16, pmkid)) || |
7382 | (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))) { | |
7383 | nlmsg_free(msg); | |
7384 | return -ENOBUFS; | |
7385 | } | |
a6efc65d JM |
7386 | |
7387 | return send_and_recv_msgs(bss->drv, msg, NULL, NULL); | |
a6efc65d JM |
7388 | } |
7389 | ||
7390 | ||
7391 | static int nl80211_add_pmkid(void *priv, const u8 *bssid, const u8 *pmkid) | |
7392 | { | |
7393 | struct i802_bss *bss = priv; | |
7394 | wpa_printf(MSG_DEBUG, "nl80211: Add PMKID for " MACSTR, MAC2STR(bssid)); | |
7395 | return nl80211_pmkid(bss, NL80211_CMD_SET_PMKSA, bssid, pmkid); | |
7396 | } | |
7397 | ||
7398 | ||
7399 | static int nl80211_remove_pmkid(void *priv, const u8 *bssid, const u8 *pmkid) | |
7400 | { | |
7401 | struct i802_bss *bss = priv; | |
7402 | wpa_printf(MSG_DEBUG, "nl80211: Delete PMKID for " MACSTR, | |
7403 | MAC2STR(bssid)); | |
7404 | return nl80211_pmkid(bss, NL80211_CMD_DEL_PMKSA, bssid, pmkid); | |
7405 | } | |
7406 | ||
7407 | ||
7408 | static int nl80211_flush_pmkid(void *priv) | |
7409 | { | |
7410 | struct i802_bss *bss = priv; | |
7411 | wpa_printf(MSG_DEBUG, "nl80211: Flush PMKIDs"); | |
7412 | return nl80211_pmkid(bss, NL80211_CMD_FLUSH_PMKSA, NULL, NULL); | |
7413 | } | |
7414 | ||
7415 | ||
0185007c MK |
7416 | static void clean_survey_results(struct survey_results *survey_results) |
7417 | { | |
7418 | struct freq_survey *survey, *tmp; | |
7419 | ||
7420 | if (dl_list_empty(&survey_results->survey_list)) | |
7421 | return; | |
7422 | ||
7423 | dl_list_for_each_safe(survey, tmp, &survey_results->survey_list, | |
7424 | struct freq_survey, list) { | |
7425 | dl_list_del(&survey->list); | |
7426 | os_free(survey); | |
7427 | } | |
7428 | } | |
7429 | ||
7430 | ||
7431 | static void add_survey(struct nlattr **sinfo, u32 ifidx, | |
7432 | struct dl_list *survey_list) | |
7433 | { | |
7434 | struct freq_survey *survey; | |
7435 | ||
7436 | survey = os_zalloc(sizeof(struct freq_survey)); | |
7437 | if (!survey) | |
7438 | return; | |
7439 | ||
7440 | survey->ifidx = ifidx; | |
7441 | survey->freq = nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]); | |
7442 | survey->filled = 0; | |
7443 | ||
7444 | if (sinfo[NL80211_SURVEY_INFO_NOISE]) { | |
7445 | survey->nf = (int8_t) | |
7446 | nla_get_u8(sinfo[NL80211_SURVEY_INFO_NOISE]); | |
7447 | survey->filled |= SURVEY_HAS_NF; | |
7448 | } | |
7449 | ||
7450 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME]) { | |
7451 | survey->channel_time = | |
7452 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME]); | |
7453 | survey->filled |= SURVEY_HAS_CHAN_TIME; | |
7454 | } | |
7455 | ||
7456 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY]) { | |
7457 | survey->channel_time_busy = | |
7458 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY]); | |
7459 | survey->filled |= SURVEY_HAS_CHAN_TIME_BUSY; | |
7460 | } | |
7461 | ||
7462 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_RX]) { | |
7463 | survey->channel_time_rx = | |
7464 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_RX]); | |
7465 | survey->filled |= SURVEY_HAS_CHAN_TIME_RX; | |
7466 | } | |
7467 | ||
7468 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_TX]) { | |
7469 | survey->channel_time_tx = | |
7470 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_TX]); | |
7471 | survey->filled |= SURVEY_HAS_CHAN_TIME_TX; | |
7472 | } | |
7473 | ||
7474 | 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)", | |
7475 | survey->freq, | |
7476 | survey->nf, | |
7477 | (unsigned long int) survey->channel_time, | |
7478 | (unsigned long int) survey->channel_time_busy, | |
7479 | (unsigned long int) survey->channel_time_tx, | |
7480 | (unsigned long int) survey->channel_time_rx, | |
7481 | survey->filled); | |
7482 | ||
7483 | dl_list_add_tail(survey_list, &survey->list); | |
7484 | } | |
7485 | ||
7486 | ||
7487 | static int check_survey_ok(struct nlattr **sinfo, u32 surveyed_freq, | |
7488 | unsigned int freq_filter) | |
7489 | { | |
7490 | if (!freq_filter) | |
7491 | return 1; | |
7492 | ||
7493 | return freq_filter == surveyed_freq; | |
7494 | } | |
7495 | ||
7496 | ||
7497 | static int survey_handler(struct nl_msg *msg, void *arg) | |
7498 | { | |
7499 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
7500 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
7501 | struct nlattr *sinfo[NL80211_SURVEY_INFO_MAX + 1]; | |
7502 | struct survey_results *survey_results; | |
7503 | u32 surveyed_freq = 0; | |
7504 | u32 ifidx; | |
7505 | ||
7506 | static struct nla_policy survey_policy[NL80211_SURVEY_INFO_MAX + 1] = { | |
7507 | [NL80211_SURVEY_INFO_FREQUENCY] = { .type = NLA_U32 }, | |
7508 | [NL80211_SURVEY_INFO_NOISE] = { .type = NLA_U8 }, | |
7509 | }; | |
7510 | ||
7511 | survey_results = (struct survey_results *) arg; | |
7512 | ||
7513 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
7514 | genlmsg_attrlen(gnlh, 0), NULL); | |
7515 | ||
e28f39b7 SJ |
7516 | if (!tb[NL80211_ATTR_IFINDEX]) |
7517 | return NL_SKIP; | |
7518 | ||
0185007c MK |
7519 | ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); |
7520 | ||
7521 | if (!tb[NL80211_ATTR_SURVEY_INFO]) | |
7522 | return NL_SKIP; | |
7523 | ||
7524 | if (nla_parse_nested(sinfo, NL80211_SURVEY_INFO_MAX, | |
7525 | tb[NL80211_ATTR_SURVEY_INFO], | |
7526 | survey_policy)) | |
7527 | return NL_SKIP; | |
7528 | ||
7529 | if (!sinfo[NL80211_SURVEY_INFO_FREQUENCY]) { | |
7530 | wpa_printf(MSG_ERROR, "nl80211: Invalid survey data"); | |
7531 | return NL_SKIP; | |
7532 | } | |
7533 | ||
7534 | surveyed_freq = nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]); | |
7535 | ||
7536 | if (!check_survey_ok(sinfo, surveyed_freq, | |
7537 | survey_results->freq_filter)) | |
7538 | return NL_SKIP; | |
7539 | ||
7540 | if (survey_results->freq_filter && | |
7541 | survey_results->freq_filter != surveyed_freq) { | |
7542 | wpa_printf(MSG_EXCESSIVE, "nl80211: Ignoring survey data for freq %d MHz", | |
7543 | surveyed_freq); | |
7544 | return NL_SKIP; | |
7545 | } | |
7546 | ||
7547 | add_survey(sinfo, ifidx, &survey_results->survey_list); | |
7548 | ||
7549 | return NL_SKIP; | |
7550 | } | |
7551 | ||
7552 | ||
7553 | static int wpa_driver_nl80211_get_survey(void *priv, unsigned int freq) | |
7554 | { | |
7555 | struct i802_bss *bss = priv; | |
7556 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
7557 | struct nl_msg *msg; | |
9725b784 | 7558 | int err; |
0185007c MK |
7559 | union wpa_event_data data; |
7560 | struct survey_results *survey_results; | |
7561 | ||
7562 | os_memset(&data, 0, sizeof(data)); | |
7563 | survey_results = &data.survey_results; | |
7564 | ||
7565 | dl_list_init(&survey_results->survey_list); | |
7566 | ||
9725b784 | 7567 | msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SURVEY); |
0185007c | 7568 | if (!msg) |
a862e4a3 | 7569 | return -ENOBUFS; |
0185007c | 7570 | |
0185007c MK |
7571 | if (freq) |
7572 | data.survey_results.freq_filter = freq; | |
7573 | ||
7574 | do { | |
7575 | wpa_printf(MSG_DEBUG, "nl80211: Fetch survey data"); | |
7576 | err = send_and_recv_msgs(drv, msg, survey_handler, | |
7577 | survey_results); | |
7578 | } while (err > 0); | |
7579 | ||
a862e4a3 | 7580 | if (err) |
0185007c | 7581 | wpa_printf(MSG_ERROR, "nl80211: Failed to process survey data"); |
a862e4a3 JM |
7582 | else |
7583 | wpa_supplicant_event(drv->ctx, EVENT_SURVEY, &data); | |
0185007c | 7584 | |
0185007c | 7585 | clean_survey_results(survey_results); |
0185007c MK |
7586 | return err; |
7587 | } | |
7588 | ||
7589 | ||
98cd3d1c JM |
7590 | static void nl80211_set_rekey_info(void *priv, const u8 *kek, size_t kek_len, |
7591 | const u8 *kck, size_t kck_len, | |
b14a210c JB |
7592 | const u8 *replay_ctr) |
7593 | { | |
7594 | struct i802_bss *bss = priv; | |
7595 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
7596 | struct nlattr *replay_nested; | |
7597 | struct nl_msg *msg; | |
64ae2447 | 7598 | int ret; |
b14a210c | 7599 | |
64ae2447 JM |
7600 | if (!drv->set_rekey_offload) |
7601 | return; | |
7602 | ||
7603 | wpa_printf(MSG_DEBUG, "nl80211: Set rekey offload"); | |
13f83980 | 7604 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_REKEY_OFFLOAD)) || |
a862e4a3 | 7605 | !(replay_nested = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA)) || |
98cd3d1c JM |
7606 | nla_put(msg, NL80211_REKEY_DATA_KEK, kek_len, kek) || |
7607 | nla_put(msg, NL80211_REKEY_DATA_KCK, kck_len, kck) || | |
a862e4a3 JM |
7608 | nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, NL80211_REPLAY_CTR_LEN, |
7609 | replay_ctr)) { | |
bbd89bfc | 7610 | nl80211_nlmsg_clear(msg); |
a862e4a3 JM |
7611 | nlmsg_free(msg); |
7612 | return; | |
7613 | } | |
b14a210c JB |
7614 | |
7615 | nla_nest_end(msg, replay_nested); | |
7616 | ||
64ae2447 JM |
7617 | ret = send_and_recv_msgs(drv, msg, NULL, (void *) -1); |
7618 | if (ret == -EOPNOTSUPP) { | |
7619 | wpa_printf(MSG_DEBUG, | |
7620 | "nl80211: Driver does not support rekey offload"); | |
7621 | drv->set_rekey_offload = 0; | |
7622 | } | |
b14a210c JB |
7623 | } |
7624 | ||
7625 | ||
39718852 JB |
7626 | static void nl80211_send_null_frame(struct i802_bss *bss, const u8 *own_addr, |
7627 | const u8 *addr, int qos) | |
bcf24348 | 7628 | { |
39718852 JB |
7629 | /* send data frame to poll STA and check whether |
7630 | * this frame is ACKed */ | |
bcf24348 JB |
7631 | struct { |
7632 | struct ieee80211_hdr hdr; | |
7633 | u16 qos_ctl; | |
7634 | } STRUCT_PACKED nulldata; | |
7635 | size_t size; | |
7636 | ||
7637 | /* Send data frame to poll STA and check whether this frame is ACKed */ | |
7638 | ||
7639 | os_memset(&nulldata, 0, sizeof(nulldata)); | |
7640 | ||
7641 | if (qos) { | |
7642 | nulldata.hdr.frame_control = | |
7643 | IEEE80211_FC(WLAN_FC_TYPE_DATA, | |
7644 | WLAN_FC_STYPE_QOS_NULL); | |
7645 | size = sizeof(nulldata); | |
7646 | } else { | |
7647 | nulldata.hdr.frame_control = | |
7648 | IEEE80211_FC(WLAN_FC_TYPE_DATA, | |
7649 | WLAN_FC_STYPE_NULLFUNC); | |
7650 | size = sizeof(struct ieee80211_hdr); | |
7651 | } | |
7652 | ||
7653 | nulldata.hdr.frame_control |= host_to_le16(WLAN_FC_FROMDS); | |
7654 | os_memcpy(nulldata.hdr.IEEE80211_DA_FROMDS, addr, ETH_ALEN); | |
7655 | os_memcpy(nulldata.hdr.IEEE80211_BSSID_FROMDS, own_addr, ETH_ALEN); | |
7656 | os_memcpy(nulldata.hdr.IEEE80211_SA_FROMDS, own_addr, ETH_ALEN); | |
7657 | ||
9ebce9c5 | 7658 | if (wpa_driver_nl80211_send_mlme(bss, (u8 *) &nulldata, size, 0, 0, 0, |
2d3943ce | 7659 | 0, 0, NULL, 0) < 0) |
bcf24348 JB |
7660 | wpa_printf(MSG_DEBUG, "nl80211_send_null_frame: Failed to " |
7661 | "send poll frame"); | |
7662 | } | |
7663 | ||
39718852 JB |
7664 | static void nl80211_poll_client(void *priv, const u8 *own_addr, const u8 *addr, |
7665 | int qos) | |
7666 | { | |
7667 | struct i802_bss *bss = priv; | |
7668 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
7669 | struct nl_msg *msg; | |
fc99fab7 | 7670 | int ret; |
39718852 JB |
7671 | |
7672 | if (!drv->poll_command_supported) { | |
7673 | nl80211_send_null_frame(bss, own_addr, addr, qos); | |
7674 | return; | |
7675 | } | |
7676 | ||
13f83980 | 7677 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_PROBE_CLIENT)) || |
a862e4a3 JM |
7678 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { |
7679 | nlmsg_free(msg); | |
7680 | return; | |
7681 | } | |
39718852 | 7682 | |
fc99fab7 JM |
7683 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
7684 | if (ret < 0) { | |
7685 | wpa_printf(MSG_DEBUG, "nl80211: Client probe request for " | |
7686 | MACSTR " failed: ret=%d (%s)", | |
7687 | MAC2STR(addr), ret, strerror(-ret)); | |
7688 | } | |
39718852 JB |
7689 | } |
7690 | ||
bcf24348 | 7691 | |
29f338af JM |
7692 | static int nl80211_set_power_save(struct i802_bss *bss, int enabled) |
7693 | { | |
7694 | struct nl_msg *msg; | |
7695 | ||
13f83980 | 7696 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_POWER_SAVE)) || |
a862e4a3 JM |
7697 | nla_put_u32(msg, NL80211_ATTR_PS_STATE, |
7698 | enabled ? NL80211_PS_ENABLED : NL80211_PS_DISABLED)) { | |
7699 | nlmsg_free(msg); | |
7700 | return -ENOBUFS; | |
7701 | } | |
29f338af | 7702 | return send_and_recv_msgs(bss->drv, msg, NULL, NULL); |
29f338af JM |
7703 | } |
7704 | ||
7705 | ||
7706 | static int nl80211_set_p2p_powersave(void *priv, int legacy_ps, int opp_ps, | |
7707 | int ctwindow) | |
7708 | { | |
7709 | struct i802_bss *bss = priv; | |
7710 | ||
7711 | wpa_printf(MSG_DEBUG, "nl80211: set_p2p_powersave (legacy_ps=%d " | |
7712 | "opp_ps=%d ctwindow=%d)", legacy_ps, opp_ps, ctwindow); | |
7713 | ||
0de38036 JM |
7714 | if (opp_ps != -1 || ctwindow != -1) { |
7715 | #ifdef ANDROID_P2P | |
7716 | wpa_driver_set_p2p_ps(priv, legacy_ps, opp_ps, ctwindow); | |
7717 | #else /* ANDROID_P2P */ | |
29f338af | 7718 | return -1; /* Not yet supported */ |
0de38036 JM |
7719 | #endif /* ANDROID_P2P */ |
7720 | } | |
29f338af JM |
7721 | |
7722 | if (legacy_ps == -1) | |
7723 | return 0; | |
7724 | if (legacy_ps != 0 && legacy_ps != 1) | |
7725 | return -1; /* Not yet supported */ | |
7726 | ||
7727 | return nl80211_set_power_save(bss, legacy_ps); | |
7728 | } | |
7729 | ||
7730 | ||
04e8003c JD |
7731 | static int nl80211_start_radar_detection(void *priv, |
7732 | struct hostapd_freq_params *freq) | |
f90e9c1c SW |
7733 | { |
7734 | struct i802_bss *bss = priv; | |
7735 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
7736 | struct nl_msg *msg; | |
7737 | int ret; | |
7738 | ||
04e8003c JD |
7739 | 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)", |
7740 | freq->freq, freq->ht_enabled, freq->vht_enabled, | |
7741 | freq->bandwidth, freq->center_freq1, freq->center_freq2); | |
7742 | ||
f90e9c1c SW |
7743 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_RADAR)) { |
7744 | wpa_printf(MSG_DEBUG, "nl80211: Driver does not support radar " | |
7745 | "detection"); | |
7746 | return -1; | |
7747 | } | |
7748 | ||
9725b784 | 7749 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_RADAR_DETECT)) || |
a862e4a3 JM |
7750 | nl80211_put_freq_params(msg, freq) < 0) { |
7751 | nlmsg_free(msg); | |
7752 | return -1; | |
7753 | } | |
f90e9c1c SW |
7754 | |
7755 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
7756 | if (ret == 0) | |
7757 | return 0; | |
7758 | wpa_printf(MSG_DEBUG, "nl80211: Failed to start radar detection: " | |
7759 | "%d (%s)", ret, strerror(-ret)); | |
f90e9c1c SW |
7760 | return -1; |
7761 | } | |
7762 | ||
03ea1786 AN |
7763 | #ifdef CONFIG_TDLS |
7764 | ||
7765 | static int nl80211_send_tdls_mgmt(void *priv, const u8 *dst, u8 action_code, | |
7766 | u8 dialog_token, u16 status_code, | |
984dadc2 AN |
7767 | u32 peer_capab, int initiator, const u8 *buf, |
7768 | size_t len) | |
03ea1786 AN |
7769 | { |
7770 | struct i802_bss *bss = priv; | |
7771 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
7772 | struct nl_msg *msg; | |
7773 | ||
7774 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) | |
7775 | return -EOPNOTSUPP; | |
7776 | ||
7777 | if (!dst) | |
7778 | return -EINVAL; | |
7779 | ||
9725b784 | 7780 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_TDLS_MGMT)) || |
a862e4a3 JM |
7781 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || |
7782 | nla_put_u8(msg, NL80211_ATTR_TDLS_ACTION, action_code) || | |
7783 | nla_put_u8(msg, NL80211_ATTR_TDLS_DIALOG_TOKEN, dialog_token) || | |
7784 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status_code)) | |
7785 | goto fail; | |
96ecea5e SD |
7786 | if (peer_capab) { |
7787 | /* | |
7788 | * The internal enum tdls_peer_capability definition is | |
7789 | * currently identical with the nl80211 enum | |
7790 | * nl80211_tdls_peer_capability, so no conversion is needed | |
7791 | * here. | |
7792 | */ | |
a862e4a3 JM |
7793 | if (nla_put_u32(msg, NL80211_ATTR_TDLS_PEER_CAPABILITY, |
7794 | peer_capab)) | |
7795 | goto fail; | |
96ecea5e | 7796 | } |
a862e4a3 JM |
7797 | if ((initiator && |
7798 | nla_put_flag(msg, NL80211_ATTR_TDLS_INITIATOR)) || | |
7799 | nla_put(msg, NL80211_ATTR_IE, len, buf)) | |
7800 | goto fail; | |
03ea1786 AN |
7801 | |
7802 | return send_and_recv_msgs(drv, msg, NULL, NULL); | |
7803 | ||
a862e4a3 | 7804 | fail: |
03ea1786 AN |
7805 | nlmsg_free(msg); |
7806 | return -ENOBUFS; | |
7807 | } | |
7808 | ||
7809 | ||
7810 | static int nl80211_tdls_oper(void *priv, enum tdls_oper oper, const u8 *peer) | |
7811 | { | |
7812 | struct i802_bss *bss = priv; | |
7813 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
7814 | struct nl_msg *msg; | |
7815 | enum nl80211_tdls_operation nl80211_oper; | |
7816 | ||
7817 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) | |
7818 | return -EOPNOTSUPP; | |
7819 | ||
7820 | switch (oper) { | |
7821 | case TDLS_DISCOVERY_REQ: | |
7822 | nl80211_oper = NL80211_TDLS_DISCOVERY_REQ; | |
7823 | break; | |
7824 | case TDLS_SETUP: | |
7825 | nl80211_oper = NL80211_TDLS_SETUP; | |
7826 | break; | |
7827 | case TDLS_TEARDOWN: | |
7828 | nl80211_oper = NL80211_TDLS_TEARDOWN; | |
7829 | break; | |
7830 | case TDLS_ENABLE_LINK: | |
7831 | nl80211_oper = NL80211_TDLS_ENABLE_LINK; | |
7832 | break; | |
7833 | case TDLS_DISABLE_LINK: | |
7834 | nl80211_oper = NL80211_TDLS_DISABLE_LINK; | |
7835 | break; | |
7836 | case TDLS_ENABLE: | |
7837 | return 0; | |
7838 | case TDLS_DISABLE: | |
7839 | return 0; | |
7840 | default: | |
7841 | return -EINVAL; | |
7842 | } | |
7843 | ||
9725b784 | 7844 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_TDLS_OPER)) || |
a862e4a3 | 7845 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, nl80211_oper) || |
a862e4a3 JM |
7846 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) { |
7847 | nlmsg_free(msg); | |
7848 | return -ENOBUFS; | |
7849 | } | |
03ea1786 AN |
7850 | |
7851 | return send_and_recv_msgs(drv, msg, NULL, NULL); | |
03ea1786 AN |
7852 | } |
7853 | ||
72b2605f AN |
7854 | |
7855 | static int | |
7856 | nl80211_tdls_enable_channel_switch(void *priv, const u8 *addr, u8 oper_class, | |
7857 | const struct hostapd_freq_params *params) | |
7858 | { | |
7859 | struct i802_bss *bss = priv; | |
7860 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
7861 | struct nl_msg *msg; | |
7862 | int ret = -ENOBUFS; | |
7863 | ||
7864 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT) || | |
7865 | !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH)) | |
7866 | return -EOPNOTSUPP; | |
7867 | ||
7868 | wpa_printf(MSG_DEBUG, "nl80211: Enable TDLS channel switch " MACSTR | |
7869 | " oper_class=%u freq=%u", | |
7870 | MAC2STR(addr), oper_class, params->freq); | |
7871 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_TDLS_CHANNEL_SWITCH); | |
7872 | if (!msg || | |
7873 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || | |
7874 | nla_put_u8(msg, NL80211_ATTR_OPER_CLASS, oper_class) || | |
7875 | (ret = nl80211_put_freq_params(msg, params))) { | |
7876 | nlmsg_free(msg); | |
7877 | wpa_printf(MSG_DEBUG, "nl80211: Could not build TDLS chan switch"); | |
7878 | return ret; | |
7879 | } | |
7880 | ||
7881 | return send_and_recv_msgs(drv, msg, NULL, NULL); | |
7882 | } | |
7883 | ||
7884 | ||
7885 | static int | |
7886 | nl80211_tdls_disable_channel_switch(void *priv, const u8 *addr) | |
7887 | { | |
7888 | struct i802_bss *bss = priv; | |
7889 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
7890 | struct nl_msg *msg; | |
7891 | ||
7892 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT) || | |
7893 | !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH)) | |
7894 | return -EOPNOTSUPP; | |
7895 | ||
7896 | wpa_printf(MSG_DEBUG, "nl80211: Disable TDLS channel switch " MACSTR, | |
7897 | MAC2STR(addr)); | |
7898 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH); | |
7899 | if (!msg || | |
7900 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { | |
7901 | nlmsg_free(msg); | |
7902 | wpa_printf(MSG_DEBUG, | |
7903 | "nl80211: Could not build TDLS cancel chan switch"); | |
7904 | return -ENOBUFS; | |
7905 | } | |
7906 | ||
7907 | return send_and_recv_msgs(drv, msg, NULL, NULL); | |
7908 | } | |
7909 | ||
03ea1786 AN |
7910 | #endif /* CONFIG TDLS */ |
7911 | ||
7912 | ||
9ebce9c5 JM |
7913 | static int driver_nl80211_set_key(const char *ifname, void *priv, |
7914 | enum wpa_alg alg, const u8 *addr, | |
7915 | int key_idx, int set_tx, | |
7916 | const u8 *seq, size_t seq_len, | |
7917 | const u8 *key, size_t key_len) | |
7918 | { | |
7919 | struct i802_bss *bss = priv; | |
7920 | return wpa_driver_nl80211_set_key(ifname, bss, alg, addr, key_idx, | |
7921 | set_tx, seq, seq_len, key, key_len); | |
7922 | } | |
7923 | ||
7924 | ||
7925 | static int driver_nl80211_scan2(void *priv, | |
7926 | struct wpa_driver_scan_params *params) | |
7927 | { | |
7928 | struct i802_bss *bss = priv; | |
b658547d | 7929 | #ifdef CONFIG_DRIVER_NL80211_QCA |
adcd7c4b KV |
7930 | struct wpa_driver_nl80211_data *drv = bss->drv; |
7931 | ||
7932 | /* | |
7933 | * Do a vendor specific scan if possible. If only_new_results is | |
7934 | * set, do a normal scan since a kernel (cfg80211) BSS cache flush | |
7935 | * cannot be achieved through a vendor scan. The below condition may | |
7936 | * need to be modified if new scan flags are added in the future whose | |
7937 | * functionality can only be achieved through a normal scan. | |
7938 | */ | |
7939 | if (drv->scan_vendor_cmd_avail && !params->only_new_results) | |
7940 | return wpa_driver_nl80211_vendor_scan(bss, params); | |
b658547d | 7941 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
9ebce9c5 JM |
7942 | return wpa_driver_nl80211_scan(bss, params); |
7943 | } | |
7944 | ||
7945 | ||
7946 | static int driver_nl80211_deauthenticate(void *priv, const u8 *addr, | |
7947 | int reason_code) | |
7948 | { | |
7949 | struct i802_bss *bss = priv; | |
7950 | return wpa_driver_nl80211_deauthenticate(bss, addr, reason_code); | |
7951 | } | |
7952 | ||
7953 | ||
7954 | static int driver_nl80211_authenticate(void *priv, | |
7955 | struct wpa_driver_auth_params *params) | |
7956 | { | |
7957 | struct i802_bss *bss = priv; | |
7958 | return wpa_driver_nl80211_authenticate(bss, params); | |
7959 | } | |
7960 | ||
7961 | ||
7962 | static void driver_nl80211_deinit(void *priv) | |
7963 | { | |
7964 | struct i802_bss *bss = priv; | |
7965 | wpa_driver_nl80211_deinit(bss); | |
7966 | } | |
7967 | ||
7968 | ||
7969 | static int driver_nl80211_if_remove(void *priv, enum wpa_driver_if_type type, | |
7970 | const char *ifname) | |
7971 | { | |
7972 | struct i802_bss *bss = priv; | |
7973 | return wpa_driver_nl80211_if_remove(bss, type, ifname); | |
7974 | } | |
7975 | ||
7976 | ||
7977 | static int driver_nl80211_send_mlme(void *priv, const u8 *data, | |
5d180a77 | 7978 | size_t data_len, int noack, |
2d3943ce AO |
7979 | unsigned int freq, |
7980 | const u16 *csa_offs, size_t csa_offs_len) | |
9ebce9c5 JM |
7981 | { |
7982 | struct i802_bss *bss = priv; | |
7983 | return wpa_driver_nl80211_send_mlme(bss, data, data_len, noack, | |
2d3943ce AO |
7984 | freq, 0, 0, 0, csa_offs, |
7985 | csa_offs_len); | |
9ebce9c5 JM |
7986 | } |
7987 | ||
7988 | ||
7989 | static int driver_nl80211_sta_remove(void *priv, const u8 *addr) | |
7990 | { | |
7991 | struct i802_bss *bss = priv; | |
59d7148a | 7992 | return wpa_driver_nl80211_sta_remove(bss, addr, -1, 0); |
9ebce9c5 JM |
7993 | } |
7994 | ||
7995 | ||
9ebce9c5 JM |
7996 | static int driver_nl80211_set_sta_vlan(void *priv, const u8 *addr, |
7997 | const char *ifname, int vlan_id) | |
7998 | { | |
7999 | struct i802_bss *bss = priv; | |
8000 | return i802_set_sta_vlan(bss, addr, ifname, vlan_id); | |
8001 | } | |
9ebce9c5 JM |
8002 | |
8003 | ||
8004 | static int driver_nl80211_read_sta_data(void *priv, | |
8005 | struct hostap_sta_driver_data *data, | |
8006 | const u8 *addr) | |
8007 | { | |
8008 | struct i802_bss *bss = priv; | |
7824bf77 JC |
8009 | |
8010 | os_memset(data, 0, sizeof(*data)); | |
9ebce9c5 JM |
8011 | return i802_read_sta_data(bss, data, addr); |
8012 | } | |
8013 | ||
8014 | ||
8015 | static int driver_nl80211_send_action(void *priv, unsigned int freq, | |
8016 | unsigned int wait_time, | |
8017 | const u8 *dst, const u8 *src, | |
8018 | const u8 *bssid, | |
8019 | const u8 *data, size_t data_len, | |
8020 | int no_cck) | |
8021 | { | |
8022 | struct i802_bss *bss = priv; | |
8023 | return wpa_driver_nl80211_send_action(bss, freq, wait_time, dst, src, | |
8024 | bssid, data, data_len, no_cck); | |
8025 | } | |
8026 | ||
8027 | ||
8028 | static int driver_nl80211_probe_req_report(void *priv, int report) | |
8029 | { | |
8030 | struct i802_bss *bss = priv; | |
8031 | return wpa_driver_nl80211_probe_req_report(bss, report); | |
8032 | } | |
8033 | ||
8034 | ||
6a1ce395 DG |
8035 | static int wpa_driver_nl80211_update_ft_ies(void *priv, const u8 *md, |
8036 | const u8 *ies, size_t ies_len) | |
8037 | { | |
8038 | int ret; | |
8039 | struct nl_msg *msg; | |
8040 | struct i802_bss *bss = priv; | |
8041 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8042 | u16 mdid = WPA_GET_LE16(md); | |
8043 | ||
6a1ce395 | 8044 | wpa_printf(MSG_DEBUG, "nl80211: Updating FT IEs"); |
9725b784 | 8045 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_UPDATE_FT_IES)) || |
a862e4a3 JM |
8046 | nla_put(msg, NL80211_ATTR_IE, ies_len, ies) || |
8047 | nla_put_u16(msg, NL80211_ATTR_MDID, mdid)) { | |
8048 | nlmsg_free(msg); | |
8049 | return -ENOBUFS; | |
8050 | } | |
6a1ce395 DG |
8051 | |
8052 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
8053 | if (ret) { | |
8054 | wpa_printf(MSG_DEBUG, "nl80211: update_ft_ies failed " | |
8055 | "err=%d (%s)", ret, strerror(-ret)); | |
8056 | } | |
8057 | ||
8058 | return ret; | |
6a1ce395 DG |
8059 | } |
8060 | ||
8061 | ||
47754718 | 8062 | static const u8 * wpa_driver_nl80211_get_macaddr(void *priv) |
597b94f5 AS |
8063 | { |
8064 | struct i802_bss *bss = priv; | |
8065 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8066 | ||
8067 | if (drv->nlmode != NL80211_IFTYPE_P2P_DEVICE) | |
8068 | return NULL; | |
8069 | ||
8070 | return bss->addr; | |
8071 | } | |
8072 | ||
8073 | ||
a771c07d JM |
8074 | static const char * scan_state_str(enum scan_states scan_state) |
8075 | { | |
8076 | switch (scan_state) { | |
8077 | case NO_SCAN: | |
8078 | return "NO_SCAN"; | |
8079 | case SCAN_REQUESTED: | |
8080 | return "SCAN_REQUESTED"; | |
8081 | case SCAN_STARTED: | |
8082 | return "SCAN_STARTED"; | |
8083 | case SCAN_COMPLETED: | |
8084 | return "SCAN_COMPLETED"; | |
8085 | case SCAN_ABORTED: | |
8086 | return "SCAN_ABORTED"; | |
8087 | case SCHED_SCAN_STARTED: | |
8088 | return "SCHED_SCAN_STARTED"; | |
8089 | case SCHED_SCAN_STOPPED: | |
8090 | return "SCHED_SCAN_STOPPED"; | |
8091 | case SCHED_SCAN_RESULTS: | |
8092 | return "SCHED_SCAN_RESULTS"; | |
8093 | } | |
8094 | ||
8095 | return "??"; | |
8096 | } | |
8097 | ||
8098 | ||
8099 | static int wpa_driver_nl80211_status(void *priv, char *buf, size_t buflen) | |
8100 | { | |
8101 | struct i802_bss *bss = priv; | |
8102 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8103 | int res; | |
8104 | char *pos, *end; | |
8105 | ||
8106 | pos = buf; | |
8107 | end = buf + buflen; | |
8108 | ||
8109 | res = os_snprintf(pos, end - pos, | |
8110 | "ifindex=%d\n" | |
8111 | "ifname=%s\n" | |
8112 | "brname=%s\n" | |
8113 | "addr=" MACSTR "\n" | |
8114 | "freq=%d\n" | |
8115 | "%s%s%s%s%s", | |
8116 | bss->ifindex, | |
8117 | bss->ifname, | |
8118 | bss->brname, | |
8119 | MAC2STR(bss->addr), | |
8120 | bss->freq, | |
8121 | bss->beacon_set ? "beacon_set=1\n" : "", | |
8122 | bss->added_if_into_bridge ? | |
8123 | "added_if_into_bridge=1\n" : "", | |
8124 | bss->added_bridge ? "added_bridge=1\n" : "", | |
8125 | bss->in_deinit ? "in_deinit=1\n" : "", | |
8126 | bss->if_dynamic ? "if_dynamic=1\n" : ""); | |
d85e1fc8 | 8127 | if (os_snprintf_error(end - pos, res)) |
a771c07d JM |
8128 | return pos - buf; |
8129 | pos += res; | |
8130 | ||
8131 | if (bss->wdev_id_set) { | |
8132 | res = os_snprintf(pos, end - pos, "wdev_id=%llu\n", | |
8133 | (unsigned long long) bss->wdev_id); | |
d85e1fc8 | 8134 | if (os_snprintf_error(end - pos, res)) |
a771c07d JM |
8135 | return pos - buf; |
8136 | pos += res; | |
8137 | } | |
8138 | ||
8139 | res = os_snprintf(pos, end - pos, | |
8140 | "phyname=%s\n" | |
fee354c7 | 8141 | "perm_addr=" MACSTR "\n" |
a771c07d JM |
8142 | "drv_ifindex=%d\n" |
8143 | "operstate=%d\n" | |
8144 | "scan_state=%s\n" | |
8145 | "auth_bssid=" MACSTR "\n" | |
8146 | "auth_attempt_bssid=" MACSTR "\n" | |
8147 | "bssid=" MACSTR "\n" | |
8148 | "prev_bssid=" MACSTR "\n" | |
8149 | "associated=%d\n" | |
8150 | "assoc_freq=%u\n" | |
8151 | "monitor_sock=%d\n" | |
8152 | "monitor_ifidx=%d\n" | |
8153 | "monitor_refcount=%d\n" | |
8154 | "last_mgmt_freq=%u\n" | |
8155 | "eapol_tx_sock=%d\n" | |
97752f79 | 8156 | "%s%s%s%s%s%s%s%s%s%s%s%s%s", |
a771c07d | 8157 | drv->phyname, |
fee354c7 | 8158 | MAC2STR(drv->perm_addr), |
a771c07d JM |
8159 | drv->ifindex, |
8160 | drv->operstate, | |
8161 | scan_state_str(drv->scan_state), | |
8162 | MAC2STR(drv->auth_bssid), | |
8163 | MAC2STR(drv->auth_attempt_bssid), | |
8164 | MAC2STR(drv->bssid), | |
8165 | MAC2STR(drv->prev_bssid), | |
8166 | drv->associated, | |
8167 | drv->assoc_freq, | |
8168 | drv->monitor_sock, | |
8169 | drv->monitor_ifidx, | |
8170 | drv->monitor_refcount, | |
8171 | drv->last_mgmt_freq, | |
8172 | drv->eapol_tx_sock, | |
8173 | drv->ignore_if_down_event ? | |
8174 | "ignore_if_down_event=1\n" : "", | |
8175 | drv->scan_complete_events ? | |
8176 | "scan_complete_events=1\n" : "", | |
8177 | drv->disabled_11b_rates ? | |
8178 | "disabled_11b_rates=1\n" : "", | |
8179 | drv->pending_remain_on_chan ? | |
8180 | "pending_remain_on_chan=1\n" : "", | |
8181 | drv->in_interface_list ? "in_interface_list=1\n" : "", | |
8182 | drv->device_ap_sme ? "device_ap_sme=1\n" : "", | |
8183 | drv->poll_command_supported ? | |
8184 | "poll_command_supported=1\n" : "", | |
8185 | drv->data_tx_status ? "data_tx_status=1\n" : "", | |
8186 | drv->scan_for_auth ? "scan_for_auth=1\n" : "", | |
8187 | drv->retry_auth ? "retry_auth=1\n" : "", | |
8188 | drv->use_monitor ? "use_monitor=1\n" : "", | |
8189 | drv->ignore_next_local_disconnect ? | |
8190 | "ignore_next_local_disconnect=1\n" : "", | |
d6a36f39 | 8191 | drv->ignore_next_local_deauth ? |
97752f79 | 8192 | "ignore_next_local_deauth=1\n" : ""); |
d85e1fc8 | 8193 | if (os_snprintf_error(end - pos, res)) |
a771c07d JM |
8194 | return pos - buf; |
8195 | pos += res; | |
8196 | ||
8197 | if (drv->has_capability) { | |
8198 | res = os_snprintf(pos, end - pos, | |
8199 | "capa.key_mgmt=0x%x\n" | |
8200 | "capa.enc=0x%x\n" | |
8201 | "capa.auth=0x%x\n" | |
24bd4e0b | 8202 | "capa.flags=0x%llx\n" |
a0a34d53 | 8203 | "capa.rrm_flags=0x%x\n" |
a771c07d JM |
8204 | "capa.max_scan_ssids=%d\n" |
8205 | "capa.max_sched_scan_ssids=%d\n" | |
8206 | "capa.sched_scan_supported=%d\n" | |
8207 | "capa.max_match_sets=%d\n" | |
8208 | "capa.max_remain_on_chan=%u\n" | |
8209 | "capa.max_stations=%u\n" | |
8210 | "capa.probe_resp_offloads=0x%x\n" | |
8211 | "capa.max_acl_mac_addrs=%u\n" | |
86056fea IP |
8212 | "capa.num_multichan_concurrent=%u\n" |
8213 | "capa.mac_addr_rand_sched_scan_supported=%d\n" | |
079a28f7 AK |
8214 | "capa.mac_addr_rand_scan_supported=%d\n" |
8215 | "capa.conc_capab=%u\n" | |
8216 | "capa.max_conc_chan_2_4=%u\n" | |
09ea4309 AS |
8217 | "capa.max_conc_chan_5_0=%u\n" |
8218 | "capa.max_sched_scan_plans=%u\n" | |
8219 | "capa.max_sched_scan_plan_interval=%u\n" | |
8220 | "capa.max_sched_scan_plan_iterations=%u\n", | |
a771c07d JM |
8221 | drv->capa.key_mgmt, |
8222 | drv->capa.enc, | |
8223 | drv->capa.auth, | |
24bd4e0b | 8224 | (unsigned long long) drv->capa.flags, |
a0a34d53 | 8225 | drv->capa.rrm_flags, |
a771c07d JM |
8226 | drv->capa.max_scan_ssids, |
8227 | drv->capa.max_sched_scan_ssids, | |
8228 | drv->capa.sched_scan_supported, | |
8229 | drv->capa.max_match_sets, | |
8230 | drv->capa.max_remain_on_chan, | |
8231 | drv->capa.max_stations, | |
8232 | drv->capa.probe_resp_offloads, | |
8233 | drv->capa.max_acl_mac_addrs, | |
86056fea IP |
8234 | drv->capa.num_multichan_concurrent, |
8235 | drv->capa.mac_addr_rand_sched_scan_supported, | |
079a28f7 AK |
8236 | drv->capa.mac_addr_rand_scan_supported, |
8237 | drv->capa.conc_capab, | |
8238 | drv->capa.max_conc_chan_2_4, | |
09ea4309 AS |
8239 | drv->capa.max_conc_chan_5_0, |
8240 | drv->capa.max_sched_scan_plans, | |
8241 | drv->capa.max_sched_scan_plan_interval, | |
8242 | drv->capa.max_sched_scan_plan_iterations); | |
d85e1fc8 | 8243 | if (os_snprintf_error(end - pos, res)) |
a771c07d JM |
8244 | return pos - buf; |
8245 | pos += res; | |
8246 | } | |
8247 | ||
8248 | return pos - buf; | |
8249 | } | |
8250 | ||
8251 | ||
1c4ffa87 AO |
8252 | static int set_beacon_data(struct nl_msg *msg, struct beacon_data *settings) |
8253 | { | |
a862e4a3 JM |
8254 | if ((settings->head && |
8255 | nla_put(msg, NL80211_ATTR_BEACON_HEAD, | |
8256 | settings->head_len, settings->head)) || | |
8257 | (settings->tail && | |
8258 | nla_put(msg, NL80211_ATTR_BEACON_TAIL, | |
8259 | settings->tail_len, settings->tail)) || | |
8260 | (settings->beacon_ies && | |
8261 | nla_put(msg, NL80211_ATTR_IE, | |
8262 | settings->beacon_ies_len, settings->beacon_ies)) || | |
8263 | (settings->proberesp_ies && | |
8264 | nla_put(msg, NL80211_ATTR_IE_PROBE_RESP, | |
8265 | settings->proberesp_ies_len, settings->proberesp_ies)) || | |
8266 | (settings->assocresp_ies && | |
8267 | nla_put(msg, NL80211_ATTR_IE_ASSOC_RESP, | |
8268 | settings->assocresp_ies_len, settings->assocresp_ies)) || | |
8269 | (settings->probe_resp && | |
8270 | nla_put(msg, NL80211_ATTR_PROBE_RESP, | |
8271 | settings->probe_resp_len, settings->probe_resp))) | |
8272 | return -ENOBUFS; | |
1c4ffa87 AO |
8273 | |
8274 | return 0; | |
1c4ffa87 AO |
8275 | } |
8276 | ||
8277 | ||
8278 | static int nl80211_switch_channel(void *priv, struct csa_settings *settings) | |
8279 | { | |
8280 | struct nl_msg *msg; | |
8281 | struct i802_bss *bss = priv; | |
8282 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8283 | struct nlattr *beacon_csa; | |
8284 | int ret = -ENOBUFS; | |
366179d2 AO |
8285 | int csa_off_len = 0; |
8286 | int i; | |
1c4ffa87 | 8287 | |
8d1fdde7 | 8288 | wpa_printf(MSG_DEBUG, "nl80211: Channel switch request (cs_count=%u block_tx=%u freq=%d width=%d cf1=%d cf2=%d)", |
1c4ffa87 | 8289 | settings->cs_count, settings->block_tx, |
8d1fdde7 JD |
8290 | settings->freq_params.freq, settings->freq_params.bandwidth, |
8291 | settings->freq_params.center_freq1, | |
8292 | settings->freq_params.center_freq2); | |
1c4ffa87 | 8293 | |
991aa9c7 | 8294 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_AP_CSA)) { |
1c4ffa87 AO |
8295 | wpa_printf(MSG_DEBUG, "nl80211: Driver does not support channel switch command"); |
8296 | return -EOPNOTSUPP; | |
8297 | } | |
8298 | ||
8299 | if ((drv->nlmode != NL80211_IFTYPE_AP) && | |
8300 | (drv->nlmode != NL80211_IFTYPE_P2P_GO)) | |
8301 | return -EOPNOTSUPP; | |
8302 | ||
366179d2 AO |
8303 | /* |
8304 | * Remove empty counters, assuming Probe Response and Beacon frame | |
8305 | * counters match. This implementation assumes that there are only two | |
8306 | * counters. | |
8307 | */ | |
8308 | if (settings->counter_offset_beacon[0] && | |
8309 | !settings->counter_offset_beacon[1]) { | |
8310 | csa_off_len = 1; | |
8311 | } else if (settings->counter_offset_beacon[1] && | |
8312 | !settings->counter_offset_beacon[0]) { | |
8313 | csa_off_len = 1; | |
8314 | settings->counter_offset_beacon[0] = | |
8315 | settings->counter_offset_beacon[1]; | |
8316 | settings->counter_offset_presp[0] = | |
8317 | settings->counter_offset_presp[1]; | |
8318 | } else if (settings->counter_offset_beacon[1] && | |
8319 | settings->counter_offset_beacon[0]) { | |
8320 | csa_off_len = 2; | |
8321 | } else { | |
8322 | wpa_printf(MSG_ERROR, "nl80211: No CSA counters provided"); | |
8323 | return -EINVAL; | |
8324 | } | |
8325 | ||
8326 | /* Check CSA counters validity */ | |
8327 | if (drv->capa.max_csa_counters && | |
8328 | csa_off_len > drv->capa.max_csa_counters) { | |
8329 | wpa_printf(MSG_ERROR, | |
8330 | "nl80211: Too many CSA counters provided"); | |
1c4ffa87 | 8331 | return -EINVAL; |
366179d2 | 8332 | } |
1c4ffa87 | 8333 | |
366179d2 | 8334 | if (!settings->beacon_csa.tail) |
1c4ffa87 AO |
8335 | return -EINVAL; |
8336 | ||
366179d2 AO |
8337 | for (i = 0; i < csa_off_len; i++) { |
8338 | u16 csa_c_off_bcn = settings->counter_offset_beacon[i]; | |
8339 | u16 csa_c_off_presp = settings->counter_offset_presp[i]; | |
8340 | ||
8341 | if ((settings->beacon_csa.tail_len <= csa_c_off_bcn) || | |
8342 | (settings->beacon_csa.tail[csa_c_off_bcn] != | |
8343 | settings->cs_count)) | |
8344 | return -EINVAL; | |
8345 | ||
8346 | if (settings->beacon_csa.probe_resp && | |
8347 | ((settings->beacon_csa.probe_resp_len <= | |
8348 | csa_c_off_presp) || | |
8349 | (settings->beacon_csa.probe_resp[csa_c_off_presp] != | |
8350 | settings->cs_count))) | |
8351 | return -EINVAL; | |
8352 | } | |
8353 | ||
13f83980 | 8354 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_CHANNEL_SWITCH)) || |
a862e4a3 JM |
8355 | nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, |
8356 | settings->cs_count) || | |
8357 | (ret = nl80211_put_freq_params(msg, &settings->freq_params)) || | |
8358 | (settings->block_tx && | |
8359 | nla_put_flag(msg, NL80211_ATTR_CH_SWITCH_BLOCK_TX))) | |
1c4ffa87 AO |
8360 | goto error; |
8361 | ||
1c4ffa87 AO |
8362 | /* beacon_after params */ |
8363 | ret = set_beacon_data(msg, &settings->beacon_after); | |
8364 | if (ret) | |
8365 | goto error; | |
8366 | ||
8367 | /* beacon_csa params */ | |
8368 | beacon_csa = nla_nest_start(msg, NL80211_ATTR_CSA_IES); | |
8369 | if (!beacon_csa) | |
a862e4a3 | 8370 | goto fail; |
1c4ffa87 AO |
8371 | |
8372 | ret = set_beacon_data(msg, &settings->beacon_csa); | |
8373 | if (ret) | |
8374 | goto error; | |
8375 | ||
366179d2 AO |
8376 | if (nla_put(msg, NL80211_ATTR_CSA_C_OFF_BEACON, |
8377 | csa_off_len * sizeof(u16), | |
8378 | settings->counter_offset_beacon) || | |
a862e4a3 | 8379 | (settings->beacon_csa.probe_resp && |
366179d2 AO |
8380 | nla_put(msg, NL80211_ATTR_CSA_C_OFF_PRESP, |
8381 | csa_off_len * sizeof(u16), | |
8382 | settings->counter_offset_presp))) | |
a862e4a3 | 8383 | goto fail; |
1c4ffa87 AO |
8384 | |
8385 | nla_nest_end(msg, beacon_csa); | |
8386 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
8387 | if (ret) { | |
8388 | wpa_printf(MSG_DEBUG, "nl80211: switch_channel failed err=%d (%s)", | |
8389 | ret, strerror(-ret)); | |
8390 | } | |
8391 | return ret; | |
8392 | ||
a862e4a3 | 8393 | fail: |
1c4ffa87 AO |
8394 | ret = -ENOBUFS; |
8395 | error: | |
8396 | nlmsg_free(msg); | |
8397 | wpa_printf(MSG_DEBUG, "nl80211: Could not build channel switch request"); | |
8398 | return ret; | |
8399 | } | |
8400 | ||
8401 | ||
dfa87878 MB |
8402 | static int nl80211_add_ts(void *priv, u8 tsid, const u8 *addr, |
8403 | u8 user_priority, u16 admitted_time) | |
8404 | { | |
8405 | struct i802_bss *bss = priv; | |
8406 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8407 | struct nl_msg *msg; | |
8408 | int ret; | |
8409 | ||
8410 | wpa_printf(MSG_DEBUG, | |
8411 | "nl80211: add_ts request: tsid=%u admitted_time=%u up=%d", | |
8412 | tsid, admitted_time, user_priority); | |
8413 | ||
8414 | if (!is_sta_interface(drv->nlmode)) | |
8415 | return -ENOTSUP; | |
8416 | ||
56f77852 JM |
8417 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_ADD_TX_TS); |
8418 | if (!msg || | |
a862e4a3 JM |
8419 | nla_put_u8(msg, NL80211_ATTR_TSID, tsid) || |
8420 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || | |
8421 | nla_put_u8(msg, NL80211_ATTR_USER_PRIO, user_priority) || | |
8422 | nla_put_u16(msg, NL80211_ATTR_ADMITTED_TIME, admitted_time)) { | |
8423 | nlmsg_free(msg); | |
8424 | return -ENOBUFS; | |
8425 | } | |
dfa87878 MB |
8426 | |
8427 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
8428 | if (ret) | |
8429 | wpa_printf(MSG_DEBUG, "nl80211: add_ts failed err=%d (%s)", | |
8430 | ret, strerror(-ret)); | |
8431 | return ret; | |
dfa87878 MB |
8432 | } |
8433 | ||
8434 | ||
8435 | static int nl80211_del_ts(void *priv, u8 tsid, const u8 *addr) | |
8436 | { | |
8437 | struct i802_bss *bss = priv; | |
8438 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8439 | struct nl_msg *msg; | |
8440 | int ret; | |
8441 | ||
8442 | wpa_printf(MSG_DEBUG, "nl80211: del_ts request: tsid=%u", tsid); | |
8443 | ||
8444 | if (!is_sta_interface(drv->nlmode)) | |
8445 | return -ENOTSUP; | |
8446 | ||
56f77852 | 8447 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_DEL_TX_TS)) || |
a862e4a3 JM |
8448 | nla_put_u8(msg, NL80211_ATTR_TSID, tsid) || |
8449 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { | |
8450 | nlmsg_free(msg); | |
8451 | return -ENOBUFS; | |
8452 | } | |
dfa87878 MB |
8453 | |
8454 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
8455 | if (ret) | |
8456 | wpa_printf(MSG_DEBUG, "nl80211: del_ts failed err=%d (%s)", | |
8457 | ret, strerror(-ret)); | |
8458 | return ret; | |
dfa87878 MB |
8459 | } |
8460 | ||
8461 | ||
6b9f7af6 JM |
8462 | #ifdef CONFIG_TESTING_OPTIONS |
8463 | static int cmd_reply_handler(struct nl_msg *msg, void *arg) | |
8464 | { | |
8465 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
8466 | struct wpabuf *buf = arg; | |
8467 | ||
8468 | if (!buf) | |
8469 | return NL_SKIP; | |
8470 | ||
8471 | if ((size_t) genlmsg_attrlen(gnlh, 0) > wpabuf_tailroom(buf)) { | |
8472 | wpa_printf(MSG_INFO, "nl80211: insufficient buffer space for reply"); | |
8473 | return NL_SKIP; | |
8474 | } | |
8475 | ||
8476 | wpabuf_put_data(buf, genlmsg_attrdata(gnlh, 0), | |
8477 | genlmsg_attrlen(gnlh, 0)); | |
8478 | ||
8479 | return NL_SKIP; | |
8480 | } | |
8481 | #endif /* CONFIG_TESTING_OPTIONS */ | |
8482 | ||
8483 | ||
adef8948 BL |
8484 | static int vendor_reply_handler(struct nl_msg *msg, void *arg) |
8485 | { | |
8486 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
8487 | struct nlattr *nl_vendor_reply, *nl; | |
8488 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
8489 | struct wpabuf *buf = arg; | |
8490 | int rem; | |
8491 | ||
8492 | if (!buf) | |
8493 | return NL_SKIP; | |
8494 | ||
8495 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
8496 | genlmsg_attrlen(gnlh, 0), NULL); | |
8497 | nl_vendor_reply = tb[NL80211_ATTR_VENDOR_DATA]; | |
8498 | ||
8499 | if (!nl_vendor_reply) | |
8500 | return NL_SKIP; | |
8501 | ||
8502 | if ((size_t) nla_len(nl_vendor_reply) > wpabuf_tailroom(buf)) { | |
8503 | wpa_printf(MSG_INFO, "nl80211: Vendor command: insufficient buffer space for reply"); | |
8504 | return NL_SKIP; | |
8505 | } | |
8506 | ||
8507 | nla_for_each_nested(nl, nl_vendor_reply, rem) { | |
8508 | wpabuf_put_data(buf, nla_data(nl), nla_len(nl)); | |
8509 | } | |
8510 | ||
8511 | return NL_SKIP; | |
8512 | } | |
8513 | ||
8514 | ||
8515 | static int nl80211_vendor_cmd(void *priv, unsigned int vendor_id, | |
8516 | unsigned int subcmd, const u8 *data, | |
8517 | size_t data_len, struct wpabuf *buf) | |
8518 | { | |
8519 | struct i802_bss *bss = priv; | |
8520 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8521 | struct nl_msg *msg; | |
8522 | int ret; | |
8523 | ||
6b9f7af6 JM |
8524 | #ifdef CONFIG_TESTING_OPTIONS |
8525 | if (vendor_id == 0xffffffff) { | |
56f77852 JM |
8526 | msg = nlmsg_alloc(); |
8527 | if (!msg) | |
8528 | return -ENOMEM; | |
8529 | ||
6b9f7af6 JM |
8530 | nl80211_cmd(drv, msg, 0, subcmd); |
8531 | if (nlmsg_append(msg, (void *) data, data_len, NLMSG_ALIGNTO) < | |
8532 | 0) | |
a862e4a3 | 8533 | goto fail; |
6b9f7af6 JM |
8534 | ret = send_and_recv_msgs(drv, msg, cmd_reply_handler, buf); |
8535 | if (ret) | |
8536 | wpa_printf(MSG_DEBUG, "nl80211: command failed err=%d", | |
8537 | ret); | |
8538 | return ret; | |
8539 | } | |
8540 | #endif /* CONFIG_TESTING_OPTIONS */ | |
8541 | ||
56f77852 | 8542 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_VENDOR)) || |
a862e4a3 JM |
8543 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, vendor_id) || |
8544 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, subcmd) || | |
8545 | (data && | |
8546 | nla_put(msg, NL80211_ATTR_VENDOR_DATA, data_len, data))) | |
8547 | goto fail; | |
adef8948 BL |
8548 | |
8549 | ret = send_and_recv_msgs(drv, msg, vendor_reply_handler, buf); | |
8550 | if (ret) | |
8551 | wpa_printf(MSG_DEBUG, "nl80211: vendor command failed err=%d", | |
8552 | ret); | |
8553 | return ret; | |
8554 | ||
a862e4a3 | 8555 | fail: |
adef8948 BL |
8556 | nlmsg_free(msg); |
8557 | return -ENOBUFS; | |
8558 | } | |
8559 | ||
8560 | ||
049105b4 KP |
8561 | static int nl80211_set_qos_map(void *priv, const u8 *qos_map_set, |
8562 | u8 qos_map_set_len) | |
8563 | { | |
8564 | struct i802_bss *bss = priv; | |
8565 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8566 | struct nl_msg *msg; | |
8567 | int ret; | |
8568 | ||
049105b4 KP |
8569 | wpa_hexdump(MSG_DEBUG, "nl80211: Setting QoS Map", |
8570 | qos_map_set, qos_map_set_len); | |
8571 | ||
9725b784 | 8572 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_QOS_MAP)) || |
a862e4a3 JM |
8573 | nla_put(msg, NL80211_ATTR_QOS_MAP, qos_map_set_len, qos_map_set)) { |
8574 | nlmsg_free(msg); | |
8575 | return -ENOBUFS; | |
8576 | } | |
049105b4 KP |
8577 | |
8578 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
8579 | if (ret) | |
8580 | wpa_printf(MSG_DEBUG, "nl80211: Setting QoS Map failed"); | |
8581 | ||
8582 | return ret; | |
049105b4 KP |
8583 | } |
8584 | ||
8585 | ||
e4fa8b12 EP |
8586 | static int nl80211_set_wowlan(void *priv, |
8587 | const struct wowlan_triggers *triggers) | |
8588 | { | |
8589 | struct i802_bss *bss = priv; | |
8590 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8591 | struct nl_msg *msg; | |
8592 | struct nlattr *wowlan_triggers; | |
8593 | int ret; | |
8594 | ||
e4fa8b12 EP |
8595 | wpa_printf(MSG_DEBUG, "nl80211: Setting wowlan"); |
8596 | ||
1ac977bd | 8597 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_SET_WOWLAN)) || |
a862e4a3 JM |
8598 | !(wowlan_triggers = nla_nest_start(msg, |
8599 | NL80211_ATTR_WOWLAN_TRIGGERS)) || | |
8600 | (triggers->any && | |
8601 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || | |
8602 | (triggers->disconnect && | |
8603 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || | |
8604 | (triggers->magic_pkt && | |
8605 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || | |
8606 | (triggers->gtk_rekey_failure && | |
8607 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || | |
8608 | (triggers->eap_identity_req && | |
8609 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || | |
8610 | (triggers->four_way_handshake && | |
8611 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || | |
8612 | (triggers->rfkill_release && | |
8613 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) { | |
8614 | nlmsg_free(msg); | |
8615 | return -ENOBUFS; | |
8616 | } | |
e4fa8b12 EP |
8617 | |
8618 | nla_nest_end(msg, wowlan_triggers); | |
8619 | ||
8620 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
8621 | if (ret) | |
8622 | wpa_printf(MSG_DEBUG, "nl80211: Setting wowlan failed"); | |
8623 | ||
8624 | return ret; | |
e4fa8b12 EP |
8625 | } |
8626 | ||
8627 | ||
b658547d | 8628 | #ifdef CONFIG_DRIVER_NL80211_QCA |
0800f9ee JM |
8629 | static int nl80211_roaming(void *priv, int allowed, const u8 *bssid) |
8630 | { | |
8631 | struct i802_bss *bss = priv; | |
8632 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8633 | struct nl_msg *msg; | |
8634 | struct nlattr *params; | |
8635 | ||
8636 | wpa_printf(MSG_DEBUG, "nl80211: Roaming policy: allowed=%d", allowed); | |
8637 | ||
8638 | if (!drv->roaming_vendor_cmd_avail) { | |
8639 | wpa_printf(MSG_DEBUG, | |
8640 | "nl80211: Ignore roaming policy change since driver does not provide command for setting it"); | |
8641 | return -1; | |
8642 | } | |
8643 | ||
9725b784 | 8644 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
a862e4a3 JM |
8645 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
8646 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | |
8647 | QCA_NL80211_VENDOR_SUBCMD_ROAMING) || | |
8648 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || | |
8649 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_ROAMING_POLICY, | |
8650 | allowed ? QCA_ROAMING_ALLOWED_WITHIN_ESS : | |
8651 | QCA_ROAMING_NOT_ALLOWED) || | |
8652 | (bssid && | |
8653 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_MAC_ADDR, ETH_ALEN, bssid))) { | |
8654 | nlmsg_free(msg); | |
8655 | return -1; | |
8656 | } | |
0800f9ee JM |
8657 | nla_nest_end(msg, params); |
8658 | ||
8659 | return send_and_recv_msgs(drv, msg, NULL, NULL); | |
0800f9ee | 8660 | } |
b658547d | 8661 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
0800f9ee JM |
8662 | |
8663 | ||
fee354c7 JM |
8664 | static int nl80211_set_mac_addr(void *priv, const u8 *addr) |
8665 | { | |
8666 | struct i802_bss *bss = priv; | |
8667 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8668 | int new_addr = addr != NULL; | |
8669 | ||
9ce3e610 JM |
8670 | if (TEST_FAIL()) |
8671 | return -1; | |
8672 | ||
fee354c7 JM |
8673 | if (!addr) |
8674 | addr = drv->perm_addr; | |
8675 | ||
8676 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 0) < 0) | |
8677 | return -1; | |
8678 | ||
8679 | if (linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname, addr) < 0) | |
8680 | { | |
8681 | wpa_printf(MSG_DEBUG, | |
8682 | "nl80211: failed to set_mac_addr for %s to " MACSTR, | |
8683 | bss->ifname, MAC2STR(addr)); | |
8684 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, | |
8685 | 1) < 0) { | |
8686 | wpa_printf(MSG_DEBUG, | |
8687 | "nl80211: Could not restore interface UP after failed set_mac_addr"); | |
8688 | } | |
8689 | return -1; | |
8690 | } | |
8691 | ||
8692 | wpa_printf(MSG_DEBUG, "nl80211: set_mac_addr for %s to " MACSTR, | |
8693 | bss->ifname, MAC2STR(addr)); | |
8694 | drv->addr_changed = new_addr; | |
8695 | os_memcpy(bss->addr, addr, ETH_ALEN); | |
8696 | ||
8697 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 1) < 0) | |
8698 | { | |
8699 | wpa_printf(MSG_DEBUG, | |
8700 | "nl80211: Could not restore interface UP after set_mac_addr"); | |
8701 | } | |
8702 | ||
8703 | return 0; | |
8704 | } | |
8705 | ||
8706 | ||
6c1664f6 BC |
8707 | #ifdef CONFIG_MESH |
8708 | ||
8709 | static int wpa_driver_nl80211_init_mesh(void *priv) | |
8710 | { | |
8711 | if (wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_MESH_POINT)) { | |
8712 | wpa_printf(MSG_INFO, | |
8713 | "nl80211: Failed to set interface into mesh mode"); | |
8714 | return -1; | |
8715 | } | |
8716 | return 0; | |
8717 | } | |
8718 | ||
8719 | ||
21c74e84 JM |
8720 | static int nl80211_put_mesh_id(struct nl_msg *msg, const u8 *mesh_id, |
8721 | size_t mesh_id_len) | |
8722 | { | |
8723 | if (mesh_id) { | |
8724 | wpa_hexdump_ascii(MSG_DEBUG, " * Mesh ID (SSID)", | |
8725 | mesh_id, mesh_id_len); | |
8726 | return nla_put(msg, NL80211_ATTR_MESH_ID, mesh_id_len, mesh_id); | |
8727 | } | |
8728 | ||
8729 | return 0; | |
8730 | } | |
8731 | ||
8732 | ||
4ffb3f87 MH |
8733 | static int nl80211_put_mesh_config(struct nl_msg *msg, |
8734 | struct wpa_driver_mesh_bss_params *params) | |
8735 | { | |
8736 | struct nlattr *container; | |
8737 | ||
8738 | container = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); | |
8739 | if (!container) | |
8740 | return -1; | |
8741 | ||
2bd62171 MH |
8742 | if (((params->flags & WPA_DRIVER_MESH_CONF_FLAG_AUTO_PLINKS) && |
8743 | nla_put_u32(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, | |
8744 | params->auto_plinks)) || | |
8745 | ((params->flags & WPA_DRIVER_MESH_CONF_FLAG_MAX_PEER_LINKS) && | |
8746 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, | |
8747 | params->max_peer_links))) | |
4ffb3f87 MH |
8748 | return -1; |
8749 | ||
8750 | /* | |
8751 | * Set NL80211_MESHCONF_PLINK_TIMEOUT even if user mpm is used because | |
8752 | * the timer could disconnect stations even in that case. | |
8753 | */ | |
2bd62171 MH |
8754 | if ((params->flags & WPA_DRIVER_MESH_CONF_FLAG_PEER_LINK_TIMEOUT) && |
8755 | nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, | |
4ffb3f87 MH |
8756 | params->peer_link_timeout)) { |
8757 | wpa_printf(MSG_ERROR, "nl80211: Failed to set PLINK_TIMEOUT"); | |
8758 | return -1; | |
8759 | } | |
8760 | ||
052b8d38 MH |
8761 | if ((params->flags & WPA_DRIVER_MESH_CONF_FLAG_HT_OP_MODE) && |
8762 | nla_put_u16(msg, NL80211_MESHCONF_HT_OPMODE, params->ht_opmode)) { | |
8763 | wpa_printf(MSG_ERROR, "nl80211: Failed to set HT_OP_MODE"); | |
8764 | return -1; | |
8765 | } | |
8766 | ||
4ffb3f87 MH |
8767 | nla_nest_end(msg, container); |
8768 | ||
8769 | return 0; | |
8770 | } | |
8771 | ||
8772 | ||
0cb5f8d9 | 8773 | static int nl80211_join_mesh(struct i802_bss *bss, |
6c1664f6 BC |
8774 | struct wpa_driver_mesh_join_params *params) |
8775 | { | |
6c1664f6 BC |
8776 | struct wpa_driver_nl80211_data *drv = bss->drv; |
8777 | struct nl_msg *msg; | |
8778 | struct nlattr *container; | |
7451a217 | 8779 | int ret = -1; |
6c1664f6 | 8780 | |
6c1664f6 | 8781 | wpa_printf(MSG_DEBUG, "nl80211: mesh join (ifindex=%d)", drv->ifindex); |
9725b784 | 8782 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_JOIN_MESH); |
f7e889fa JM |
8783 | if (!msg || |
8784 | nl80211_put_freq_params(msg, ¶ms->freq) || | |
21c74e84 JM |
8785 | nl80211_put_basic_rates(msg, params->basic_rates) || |
8786 | nl80211_put_mesh_id(msg, params->meshid, params->meshid_len) || | |
4ac2ea57 MH |
8787 | nl80211_put_beacon_int(msg, params->beacon_int) || |
8788 | nl80211_put_dtim_period(msg, params->dtim_period)) | |
85e1fad8 | 8789 | goto fail; |
9c58c5f7 | 8790 | |
6c1664f6 BC |
8791 | wpa_printf(MSG_DEBUG, " * flags=%08X", params->flags); |
8792 | ||
8793 | container = nla_nest_start(msg, NL80211_ATTR_MESH_SETUP); | |
8794 | if (!container) | |
a862e4a3 | 8795 | goto fail; |
6c1664f6 BC |
8796 | |
8797 | if (params->ies) { | |
8798 | wpa_hexdump(MSG_DEBUG, " * IEs", params->ies, params->ie_len); | |
a862e4a3 JM |
8799 | if (nla_put(msg, NL80211_MESH_SETUP_IE, params->ie_len, |
8800 | params->ies)) | |
8801 | goto fail; | |
6c1664f6 BC |
8802 | } |
8803 | /* WPA_DRIVER_MESH_FLAG_OPEN_AUTH is treated as default by nl80211 */ | |
8804 | if (params->flags & WPA_DRIVER_MESH_FLAG_SAE_AUTH) { | |
a862e4a3 JM |
8805 | if (nla_put_u8(msg, NL80211_MESH_SETUP_AUTH_PROTOCOL, 0x1) || |
8806 | nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_AUTH)) | |
8807 | goto fail; | |
6c1664f6 | 8808 | } |
a862e4a3 JM |
8809 | if ((params->flags & WPA_DRIVER_MESH_FLAG_AMPE) && |
8810 | nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_AMPE)) | |
8811 | goto fail; | |
8812 | if ((params->flags & WPA_DRIVER_MESH_FLAG_USER_MPM) && | |
8813 | nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_MPM)) | |
8814 | goto fail; | |
6c1664f6 BC |
8815 | nla_nest_end(msg, container); |
8816 | ||
2bd62171 MH |
8817 | params->conf.flags |= WPA_DRIVER_MESH_CONF_FLAG_AUTO_PLINKS; |
8818 | params->conf.flags |= WPA_DRIVER_MESH_CONF_FLAG_PEER_LINK_TIMEOUT; | |
8819 | params->conf.flags |= WPA_DRIVER_MESH_CONF_FLAG_MAX_PEER_LINKS; | |
4ffb3f87 | 8820 | if (nl80211_put_mesh_config(msg, ¶ms->conf) < 0) |
5a2a6de6 | 8821 | goto fail; |
6c1664f6 BC |
8822 | |
8823 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
8824 | msg = NULL; | |
8825 | if (ret) { | |
8826 | wpa_printf(MSG_DEBUG, "nl80211: mesh join failed: ret=%d (%s)", | |
8827 | ret, strerror(-ret)); | |
a862e4a3 | 8828 | goto fail; |
6c1664f6 BC |
8829 | } |
8830 | ret = 0; | |
92a515b8 | 8831 | drv->assoc_freq = bss->freq = params->freq.freq; |
6c1664f6 BC |
8832 | wpa_printf(MSG_DEBUG, "nl80211: mesh join request send successfully"); |
8833 | ||
a862e4a3 | 8834 | fail: |
6c1664f6 BC |
8835 | nlmsg_free(msg); |
8836 | return ret; | |
8837 | } | |
8838 | ||
8839 | ||
0cb5f8d9 MH |
8840 | static int |
8841 | wpa_driver_nl80211_join_mesh(void *priv, | |
8842 | struct wpa_driver_mesh_join_params *params) | |
8843 | { | |
8844 | struct i802_bss *bss = priv; | |
8845 | int ret, timeout; | |
8846 | ||
8847 | timeout = params->conf.peer_link_timeout; | |
8848 | ||
8849 | /* Disable kernel inactivity timer */ | |
8850 | if (params->flags & WPA_DRIVER_MESH_FLAG_USER_MPM) | |
8851 | params->conf.peer_link_timeout = 0; | |
8852 | ||
8853 | ret = nl80211_join_mesh(bss, params); | |
8854 | if (ret == -EINVAL && params->conf.peer_link_timeout == 0) { | |
8855 | wpa_printf(MSG_DEBUG, | |
8856 | "nl80211: Mesh join retry for peer_link_timeout"); | |
8857 | /* | |
8858 | * Old kernel does not support setting | |
8859 | * NL80211_MESHCONF_PLINK_TIMEOUT to zero, so set 60 seconds | |
8860 | * into future from peer_link_timeout. | |
8861 | */ | |
8862 | params->conf.peer_link_timeout = timeout + 60; | |
8863 | ret = nl80211_join_mesh(priv, params); | |
8864 | } | |
8865 | ||
8866 | params->conf.peer_link_timeout = timeout; | |
8867 | return ret; | |
8868 | } | |
8869 | ||
8870 | ||
6c1664f6 BC |
8871 | static int wpa_driver_nl80211_leave_mesh(void *priv) |
8872 | { | |
8873 | struct i802_bss *bss = priv; | |
8874 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8875 | struct nl_msg *msg; | |
9725b784 | 8876 | int ret; |
6c1664f6 BC |
8877 | |
8878 | wpa_printf(MSG_DEBUG, "nl80211: mesh leave (ifindex=%d)", drv->ifindex); | |
9725b784 | 8879 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_LEAVE_MESH); |
6c1664f6 | 8880 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
6c1664f6 BC |
8881 | if (ret) { |
8882 | wpa_printf(MSG_DEBUG, "nl80211: mesh leave failed: ret=%d (%s)", | |
8883 | ret, strerror(-ret)); | |
a862e4a3 JM |
8884 | } else { |
8885 | wpa_printf(MSG_DEBUG, | |
8886 | "nl80211: mesh leave request send successfully"); | |
6c1664f6 | 8887 | } |
6c1664f6 | 8888 | |
f33c82d2 JM |
8889 | if (wpa_driver_nl80211_set_mode(drv->first_bss, |
8890 | NL80211_IFTYPE_STATION)) { | |
8891 | wpa_printf(MSG_INFO, | |
8892 | "nl80211: Failed to set interface into station mode"); | |
8893 | } | |
6c1664f6 BC |
8894 | return ret; |
8895 | } | |
8896 | ||
8897 | #endif /* CONFIG_MESH */ | |
8898 | ||
8899 | ||
ed4ddb6d KP |
8900 | static int wpa_driver_br_add_ip_neigh(void *priv, u8 version, |
8901 | const u8 *ipaddr, int prefixlen, | |
8902 | const u8 *addr) | |
71103bed KP |
8903 | { |
8904 | #ifdef CONFIG_LIBNL3_ROUTE | |
8905 | struct i802_bss *bss = priv; | |
8906 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8907 | struct rtnl_neigh *rn; | |
8908 | struct nl_addr *nl_ipaddr = NULL; | |
8909 | struct nl_addr *nl_lladdr = NULL; | |
ed4ddb6d | 8910 | int family, addrsize; |
71103bed KP |
8911 | int res; |
8912 | ||
ed4ddb6d | 8913 | if (!ipaddr || prefixlen == 0 || !addr) |
71103bed KP |
8914 | return -EINVAL; |
8915 | ||
8916 | if (bss->br_ifindex == 0) { | |
8917 | wpa_printf(MSG_DEBUG, | |
8918 | "nl80211: bridge must be set before adding an ip neigh to it"); | |
8919 | return -1; | |
8920 | } | |
8921 | ||
8922 | if (!drv->rtnl_sk) { | |
8923 | wpa_printf(MSG_DEBUG, | |
8924 | "nl80211: nl_sock for NETLINK_ROUTE is not initialized"); | |
8925 | return -1; | |
8926 | } | |
8927 | ||
ed4ddb6d KP |
8928 | if (version == 4) { |
8929 | family = AF_INET; | |
8930 | addrsize = 4; | |
8931 | } else if (version == 6) { | |
8932 | family = AF_INET6; | |
8933 | addrsize = 16; | |
8934 | } else { | |
8935 | return -EINVAL; | |
8936 | } | |
8937 | ||
71103bed KP |
8938 | rn = rtnl_neigh_alloc(); |
8939 | if (rn == NULL) | |
8940 | return -ENOMEM; | |
8941 | ||
8942 | /* set the destination ip address for neigh */ | |
ed4ddb6d | 8943 | nl_ipaddr = nl_addr_build(family, (void *) ipaddr, addrsize); |
71103bed KP |
8944 | if (nl_ipaddr == NULL) { |
8945 | wpa_printf(MSG_DEBUG, "nl80211: nl_ipaddr build failed"); | |
8946 | res = -ENOMEM; | |
8947 | goto errout; | |
8948 | } | |
8949 | nl_addr_set_prefixlen(nl_ipaddr, prefixlen); | |
8950 | res = rtnl_neigh_set_dst(rn, nl_ipaddr); | |
8951 | if (res) { | |
8952 | wpa_printf(MSG_DEBUG, | |
8953 | "nl80211: neigh set destination addr failed"); | |
8954 | goto errout; | |
8955 | } | |
8956 | ||
8957 | /* set the corresponding lladdr for neigh */ | |
8958 | nl_lladdr = nl_addr_build(AF_BRIDGE, (u8 *) addr, ETH_ALEN); | |
8959 | if (nl_lladdr == NULL) { | |
8960 | wpa_printf(MSG_DEBUG, "nl80211: neigh set lladdr failed"); | |
8961 | res = -ENOMEM; | |
8962 | goto errout; | |
8963 | } | |
8964 | rtnl_neigh_set_lladdr(rn, nl_lladdr); | |
8965 | ||
8966 | rtnl_neigh_set_ifindex(rn, bss->br_ifindex); | |
8967 | rtnl_neigh_set_state(rn, NUD_PERMANENT); | |
8968 | ||
8969 | res = rtnl_neigh_add(drv->rtnl_sk, rn, NLM_F_CREATE); | |
8970 | if (res) { | |
8971 | wpa_printf(MSG_DEBUG, | |
8972 | "nl80211: Adding bridge ip neigh failed: %s", | |
8973 | strerror(errno)); | |
8974 | } | |
8975 | errout: | |
8976 | if (nl_lladdr) | |
8977 | nl_addr_put(nl_lladdr); | |
8978 | if (nl_ipaddr) | |
8979 | nl_addr_put(nl_ipaddr); | |
8980 | if (rn) | |
8981 | rtnl_neigh_put(rn); | |
8982 | return res; | |
8983 | #else /* CONFIG_LIBNL3_ROUTE */ | |
8984 | return -1; | |
8985 | #endif /* CONFIG_LIBNL3_ROUTE */ | |
8986 | } | |
8987 | ||
8988 | ||
ed4ddb6d KP |
8989 | static int wpa_driver_br_delete_ip_neigh(void *priv, u8 version, |
8990 | const u8 *ipaddr) | |
71103bed KP |
8991 | { |
8992 | #ifdef CONFIG_LIBNL3_ROUTE | |
8993 | struct i802_bss *bss = priv; | |
8994 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8995 | struct rtnl_neigh *rn; | |
8996 | struct nl_addr *nl_ipaddr; | |
ed4ddb6d | 8997 | int family, addrsize; |
71103bed KP |
8998 | int res; |
8999 | ||
ed4ddb6d | 9000 | if (!ipaddr) |
71103bed KP |
9001 | return -EINVAL; |
9002 | ||
ed4ddb6d KP |
9003 | if (version == 4) { |
9004 | family = AF_INET; | |
9005 | addrsize = 4; | |
9006 | } else if (version == 6) { | |
9007 | family = AF_INET6; | |
9008 | addrsize = 16; | |
9009 | } else { | |
9010 | return -EINVAL; | |
9011 | } | |
9012 | ||
71103bed KP |
9013 | if (bss->br_ifindex == 0) { |
9014 | wpa_printf(MSG_DEBUG, | |
9015 | "nl80211: bridge must be set to delete an ip neigh"); | |
9016 | return -1; | |
9017 | } | |
9018 | ||
9019 | if (!drv->rtnl_sk) { | |
9020 | wpa_printf(MSG_DEBUG, | |
9021 | "nl80211: nl_sock for NETLINK_ROUTE is not initialized"); | |
9022 | return -1; | |
9023 | } | |
9024 | ||
9025 | rn = rtnl_neigh_alloc(); | |
9026 | if (rn == NULL) | |
9027 | return -ENOMEM; | |
9028 | ||
9029 | /* set the destination ip address for neigh */ | |
ed4ddb6d | 9030 | nl_ipaddr = nl_addr_build(family, (void *) ipaddr, addrsize); |
71103bed KP |
9031 | if (nl_ipaddr == NULL) { |
9032 | wpa_printf(MSG_DEBUG, "nl80211: nl_ipaddr build failed"); | |
9033 | res = -ENOMEM; | |
9034 | goto errout; | |
9035 | } | |
9036 | res = rtnl_neigh_set_dst(rn, nl_ipaddr); | |
9037 | if (res) { | |
9038 | wpa_printf(MSG_DEBUG, | |
9039 | "nl80211: neigh set destination addr failed"); | |
9040 | goto errout; | |
9041 | } | |
9042 | ||
9043 | rtnl_neigh_set_ifindex(rn, bss->br_ifindex); | |
9044 | ||
9045 | res = rtnl_neigh_delete(drv->rtnl_sk, rn, 0); | |
9046 | if (res) { | |
9047 | wpa_printf(MSG_DEBUG, | |
9048 | "nl80211: Deleting bridge ip neigh failed: %s", | |
9049 | strerror(errno)); | |
9050 | } | |
9051 | errout: | |
9052 | if (nl_ipaddr) | |
9053 | nl_addr_put(nl_ipaddr); | |
9054 | if (rn) | |
9055 | rtnl_neigh_put(rn); | |
9056 | return res; | |
9057 | #else /* CONFIG_LIBNL3_ROUTE */ | |
9058 | return -1; | |
9059 | #endif /* CONFIG_LIBNL3_ROUTE */ | |
9060 | } | |
9061 | ||
9062 | ||
73d2294f KP |
9063 | static int linux_write_system_file(const char *path, unsigned int val) |
9064 | { | |
9065 | char buf[50]; | |
9066 | int fd, len; | |
9067 | ||
9068 | len = os_snprintf(buf, sizeof(buf), "%u\n", val); | |
a9aaacbb | 9069 | if (os_snprintf_error(sizeof(buf), len)) |
73d2294f KP |
9070 | return -1; |
9071 | ||
9072 | fd = open(path, O_WRONLY); | |
9073 | if (fd < 0) | |
9074 | return -1; | |
9075 | ||
9076 | if (write(fd, buf, len) < 0) { | |
9077 | wpa_printf(MSG_DEBUG, | |
9078 | "nl80211: Failed to write Linux system file: %s with the value of %d", | |
9079 | path, val); | |
9080 | close(fd); | |
9081 | return -1; | |
9082 | } | |
9083 | close(fd); | |
9084 | ||
9085 | return 0; | |
9086 | } | |
9087 | ||
9088 | ||
9089 | static const char * drv_br_port_attr_str(enum drv_br_port_attr attr) | |
9090 | { | |
9091 | switch (attr) { | |
9092 | case DRV_BR_PORT_ATTR_PROXYARP: | |
bea8d9a3 | 9093 | return "proxyarp_wifi"; |
73d2294f KP |
9094 | case DRV_BR_PORT_ATTR_HAIRPIN_MODE: |
9095 | return "hairpin_mode"; | |
9096 | } | |
9097 | ||
9098 | return NULL; | |
9099 | } | |
9100 | ||
9101 | ||
9102 | static int wpa_driver_br_port_set_attr(void *priv, enum drv_br_port_attr attr, | |
9103 | unsigned int val) | |
9104 | { | |
9105 | struct i802_bss *bss = priv; | |
9106 | char path[128]; | |
9107 | const char *attr_txt; | |
9108 | ||
9109 | attr_txt = drv_br_port_attr_str(attr); | |
9110 | if (attr_txt == NULL) | |
9111 | return -EINVAL; | |
9112 | ||
9113 | os_snprintf(path, sizeof(path), "/sys/class/net/%s/brport/%s", | |
9114 | bss->ifname, attr_txt); | |
9115 | ||
9116 | if (linux_write_system_file(path, val)) | |
9117 | return -1; | |
9118 | ||
9119 | return 0; | |
9120 | } | |
9121 | ||
9122 | ||
7565752d KP |
9123 | static const char * drv_br_net_param_str(enum drv_br_net_param param) |
9124 | { | |
9125 | switch (param) { | |
9126 | case DRV_BR_NET_PARAM_GARP_ACCEPT: | |
9127 | return "arp_accept"; | |
60eb9e17 JM |
9128 | default: |
9129 | return NULL; | |
7565752d | 9130 | } |
7565752d KP |
9131 | } |
9132 | ||
9133 | ||
9134 | static int wpa_driver_br_set_net_param(void *priv, enum drv_br_net_param param, | |
9135 | unsigned int val) | |
9136 | { | |
9137 | struct i802_bss *bss = priv; | |
9138 | char path[128]; | |
9139 | const char *param_txt; | |
9140 | int ip_version = 4; | |
9141 | ||
60eb9e17 JM |
9142 | if (param == DRV_BR_MULTICAST_SNOOPING) { |
9143 | os_snprintf(path, sizeof(path), | |
9144 | "/sys/devices/virtual/net/%s/bridge/multicast_snooping", | |
9145 | bss->brname); | |
9146 | goto set_val; | |
9147 | } | |
9148 | ||
7565752d KP |
9149 | param_txt = drv_br_net_param_str(param); |
9150 | if (param_txt == NULL) | |
9151 | return -EINVAL; | |
9152 | ||
9153 | switch (param) { | |
9154 | case DRV_BR_NET_PARAM_GARP_ACCEPT: | |
9155 | ip_version = 4; | |
9156 | break; | |
9157 | default: | |
9158 | return -EINVAL; | |
9159 | } | |
9160 | ||
9161 | os_snprintf(path, sizeof(path), "/proc/sys/net/ipv%d/conf/%s/%s", | |
9162 | ip_version, bss->brname, param_txt); | |
9163 | ||
60eb9e17 | 9164 | set_val: |
7565752d KP |
9165 | if (linux_write_system_file(path, val)) |
9166 | return -1; | |
9167 | ||
9168 | return 0; | |
9169 | } | |
9170 | ||
9171 | ||
b658547d JM |
9172 | #ifdef CONFIG_DRIVER_NL80211_QCA |
9173 | ||
16689c7c PX |
9174 | static int hw_mode_to_qca_acs(enum hostapd_hw_mode hw_mode) |
9175 | { | |
9176 | switch (hw_mode) { | |
9177 | case HOSTAPD_MODE_IEEE80211B: | |
9178 | return QCA_ACS_MODE_IEEE80211B; | |
9179 | case HOSTAPD_MODE_IEEE80211G: | |
9180 | return QCA_ACS_MODE_IEEE80211G; | |
9181 | case HOSTAPD_MODE_IEEE80211A: | |
9182 | return QCA_ACS_MODE_IEEE80211A; | |
9183 | case HOSTAPD_MODE_IEEE80211AD: | |
9184 | return QCA_ACS_MODE_IEEE80211AD; | |
3784c058 PX |
9185 | case HOSTAPD_MODE_IEEE80211ANY: |
9186 | return QCA_ACS_MODE_IEEE80211ANY; | |
16689c7c PX |
9187 | default: |
9188 | return -1; | |
9189 | } | |
9190 | } | |
9191 | ||
9192 | ||
d0cdccd3 PX |
9193 | static int add_acs_freq_list(struct nl_msg *msg, const int *freq_list) |
9194 | { | |
9195 | int i, len, ret; | |
9196 | u32 *freqs; | |
9197 | ||
9198 | if (!freq_list) | |
9199 | return 0; | |
9200 | len = int_array_len(freq_list); | |
9201 | freqs = os_malloc(sizeof(u32) * len); | |
9202 | if (!freqs) | |
9203 | return -1; | |
9204 | for (i = 0; i < len; i++) | |
9205 | freqs[i] = freq_list[i]; | |
9206 | ret = nla_put(msg, QCA_WLAN_VENDOR_ATTR_ACS_FREQ_LIST, | |
9207 | sizeof(u32) * len, freqs); | |
9208 | os_free(freqs); | |
9209 | return ret; | |
9210 | } | |
9211 | ||
9212 | ||
16689c7c PX |
9213 | static int wpa_driver_do_acs(void *priv, struct drv_acs_params *params) |
9214 | { | |
9215 | struct i802_bss *bss = priv; | |
9216 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
9217 | struct nl_msg *msg; | |
9218 | struct nlattr *data; | |
a862e4a3 | 9219 | int ret; |
16689c7c PX |
9220 | int mode; |
9221 | ||
9222 | mode = hw_mode_to_qca_acs(params->hw_mode); | |
9223 | if (mode < 0) | |
9224 | return -1; | |
9225 | ||
9725b784 | 9226 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
a862e4a3 JM |
9227 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
9228 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | |
9229 | QCA_NL80211_VENDOR_SUBCMD_DO_ACS) || | |
9230 | !(data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || | |
9231 | nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_ACS_HW_MODE, mode) || | |
9232 | (params->ht_enabled && | |
9233 | nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_HT_ENABLED)) || | |
9234 | (params->ht40_enabled && | |
857d9422 MM |
9235 | nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_HT40_ENABLED)) || |
9236 | (params->vht_enabled && | |
9237 | nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_VHT_ENABLED)) || | |
9238 | nla_put_u16(msg, QCA_WLAN_VENDOR_ATTR_ACS_CHWIDTH, | |
9239 | params->ch_width) || | |
9240 | (params->ch_list_len && | |
9241 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_ACS_CH_LIST, params->ch_list_len, | |
d0cdccd3 PX |
9242 | params->ch_list)) || |
9243 | add_acs_freq_list(msg, params->freq_list)) { | |
a862e4a3 JM |
9244 | nlmsg_free(msg); |
9245 | return -ENOBUFS; | |
9246 | } | |
16689c7c PX |
9247 | nla_nest_end(msg, data); |
9248 | ||
857d9422 MM |
9249 | wpa_printf(MSG_DEBUG, |
9250 | "nl80211: ACS Params: HW_MODE: %d HT: %d HT40: %d VHT: %d BW: %d CH_LIST_LEN: %u", | |
9251 | params->hw_mode, params->ht_enabled, params->ht40_enabled, | |
9252 | params->vht_enabled, params->ch_width, params->ch_list_len); | |
9253 | ||
16689c7c | 9254 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
16689c7c PX |
9255 | if (ret) { |
9256 | wpa_printf(MSG_DEBUG, | |
9257 | "nl80211: Failed to invoke driver ACS function: %s", | |
9258 | strerror(errno)); | |
9259 | } | |
16689c7c PX |
9260 | return ret; |
9261 | } | |
9262 | ||
9263 | ||
844dfeb8 SD |
9264 | static int nl80211_set_band(void *priv, enum set_band band) |
9265 | { | |
9266 | struct i802_bss *bss = priv; | |
9267 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
9268 | struct nl_msg *msg; | |
9269 | struct nlattr *data; | |
9270 | int ret; | |
9271 | enum qca_set_band qca_band; | |
9272 | ||
9273 | if (!drv->setband_vendor_cmd_avail) | |
9274 | return -1; | |
9275 | ||
9276 | switch (band) { | |
9277 | case WPA_SETBAND_AUTO: | |
9278 | qca_band = QCA_SETBAND_AUTO; | |
9279 | break; | |
9280 | case WPA_SETBAND_5G: | |
9281 | qca_band = QCA_SETBAND_5G; | |
9282 | break; | |
9283 | case WPA_SETBAND_2G: | |
9284 | qca_band = QCA_SETBAND_2G; | |
9285 | break; | |
9286 | default: | |
9287 | return -1; | |
9288 | } | |
9289 | ||
9290 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || | |
9291 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || | |
9292 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | |
9293 | QCA_NL80211_VENDOR_SUBCMD_SETBAND) || | |
9294 | !(data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || | |
9295 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_SETBAND_VALUE, qca_band)) { | |
9296 | nlmsg_free(msg); | |
9297 | return -ENOBUFS; | |
9298 | } | |
9299 | nla_nest_end(msg, data); | |
9300 | ||
9301 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
9302 | if (ret) { | |
9303 | wpa_printf(MSG_DEBUG, | |
9304 | "nl80211: Driver setband function failed: %s", | |
9305 | strerror(errno)); | |
9306 | } | |
9307 | return ret; | |
9308 | } | |
9309 | ||
9310 | ||
98342208 AK |
9311 | struct nl80211_pcl { |
9312 | unsigned int num; | |
9313 | unsigned int *freq_list; | |
9314 | }; | |
9315 | ||
9316 | static int preferred_freq_info_handler(struct nl_msg *msg, void *arg) | |
9317 | { | |
9318 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
9319 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
9320 | struct nl80211_pcl *param = arg; | |
9321 | struct nlattr *nl_vend, *attr; | |
9322 | enum qca_iface_type iface_type; | |
9323 | struct nlattr *tb_vendor[QCA_WLAN_VENDOR_ATTR_MAX + 1]; | |
9324 | unsigned int num, max_num; | |
9325 | u32 *freqs; | |
9326 | ||
9327 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
9328 | genlmsg_attrlen(gnlh, 0), NULL); | |
9329 | ||
9330 | nl_vend = tb[NL80211_ATTR_VENDOR_DATA]; | |
9331 | if (!nl_vend) | |
9332 | return NL_SKIP; | |
9333 | ||
9334 | nla_parse(tb_vendor, QCA_WLAN_VENDOR_ATTR_MAX, | |
9335 | nla_data(nl_vend), nla_len(nl_vend), NULL); | |
9336 | ||
9337 | attr = tb_vendor[ | |
9338 | QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST_IFACE_TYPE]; | |
9339 | if (!attr) { | |
9340 | wpa_printf(MSG_ERROR, "nl80211: iface_type couldn't be found"); | |
9341 | param->num = 0; | |
9342 | return NL_SKIP; | |
9343 | } | |
9344 | ||
9345 | iface_type = (enum qca_iface_type) nla_get_u32(attr); | |
9346 | wpa_printf(MSG_DEBUG, "nl80211: Driver returned iface_type=%d", | |
9347 | iface_type); | |
9348 | ||
9349 | attr = tb_vendor[QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST]; | |
9350 | if (!attr) { | |
9351 | wpa_printf(MSG_ERROR, | |
9352 | "nl80211: preferred_freq_list couldn't be found"); | |
9353 | param->num = 0; | |
9354 | return NL_SKIP; | |
9355 | } | |
9356 | ||
9357 | /* | |
9358 | * param->num has the maximum number of entries for which there | |
9359 | * is room in the freq_list provided by the caller. | |
9360 | */ | |
9361 | freqs = nla_data(attr); | |
9362 | max_num = nla_len(attr) / sizeof(u32); | |
9363 | if (max_num > param->num) | |
9364 | max_num = param->num; | |
9365 | for (num = 0; num < max_num; num++) | |
9366 | param->freq_list[num] = freqs[num]; | |
9367 | param->num = num; | |
9368 | ||
9369 | return NL_SKIP; | |
9370 | } | |
9371 | ||
9372 | ||
9373 | static int nl80211_get_pref_freq_list(void *priv, | |
9374 | enum wpa_driver_if_type if_type, | |
9375 | unsigned int *num, | |
9376 | unsigned int *freq_list) | |
9377 | { | |
9378 | struct i802_bss *bss = priv; | |
9379 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
9380 | struct nl_msg *msg; | |
9381 | int ret; | |
9382 | unsigned int i; | |
9383 | struct nlattr *params; | |
9384 | struct nl80211_pcl param; | |
9385 | enum qca_iface_type iface_type; | |
9386 | ||
9387 | if (!drv->get_pref_freq_list) | |
9388 | return -1; | |
9389 | ||
9390 | switch (if_type) { | |
9391 | case WPA_IF_STATION: | |
9392 | iface_type = QCA_IFACE_TYPE_STA; | |
9393 | break; | |
9394 | case WPA_IF_AP_BSS: | |
9395 | iface_type = QCA_IFACE_TYPE_AP; | |
9396 | break; | |
9397 | case WPA_IF_P2P_GO: | |
9398 | iface_type = QCA_IFACE_TYPE_P2P_GO; | |
9399 | break; | |
9400 | case WPA_IF_P2P_CLIENT: | |
9401 | iface_type = QCA_IFACE_TYPE_P2P_CLIENT; | |
9402 | break; | |
9403 | case WPA_IF_IBSS: | |
9404 | iface_type = QCA_IFACE_TYPE_IBSS; | |
9405 | break; | |
9406 | case WPA_IF_TDLS: | |
9407 | iface_type = QCA_IFACE_TYPE_TDLS; | |
9408 | break; | |
9409 | default: | |
9410 | return -1; | |
9411 | } | |
9412 | ||
9413 | param.num = *num; | |
9414 | param.freq_list = freq_list; | |
9415 | ||
9416 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || | |
9417 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, drv->ifindex) || | |
9418 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || | |
9419 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | |
9420 | QCA_NL80211_VENDOR_SUBCMD_GET_PREFERRED_FREQ_LIST) || | |
9421 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || | |
9422 | nla_put_u32(msg, | |
9423 | QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST_IFACE_TYPE, | |
9424 | iface_type)) { | |
9425 | wpa_printf(MSG_ERROR, | |
9426 | "%s: err in adding vendor_cmd and vendor_data", | |
9427 | __func__); | |
9428 | nlmsg_free(msg); | |
9429 | return -1; | |
9430 | } | |
9431 | nla_nest_end(msg, params); | |
9432 | ||
9433 | os_memset(freq_list, 0, *num * sizeof(freq_list[0])); | |
9434 | ret = send_and_recv_msgs(drv, msg, preferred_freq_info_handler, ¶m); | |
9435 | if (ret) { | |
9436 | wpa_printf(MSG_ERROR, | |
9437 | "%s: err in send_and_recv_msgs", __func__); | |
9438 | return ret; | |
9439 | } | |
9440 | ||
9441 | *num = param.num; | |
9442 | ||
9443 | for (i = 0; i < *num; i++) { | |
9444 | wpa_printf(MSG_DEBUG, "nl80211: preferred_channel_list[%d]=%d", | |
9445 | i, freq_list[i]); | |
9446 | } | |
9447 | ||
9448 | return 0; | |
9449 | } | |
9450 | ||
9451 | ||
7c813acf AK |
9452 | static int nl80211_set_prob_oper_freq(void *priv, unsigned int freq) |
9453 | { | |
9454 | struct i802_bss *bss = priv; | |
9455 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
9456 | struct nl_msg *msg; | |
9457 | int ret; | |
9458 | struct nlattr *params; | |
9459 | ||
9460 | if (!drv->set_prob_oper_freq) | |
9461 | return -1; | |
9462 | ||
9463 | wpa_printf(MSG_DEBUG, | |
9464 | "nl80211: Set P2P probable operating freq %u for ifindex %d", | |
9465 | freq, bss->ifindex); | |
9466 | ||
9467 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || | |
9468 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || | |
9469 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | |
9470 | QCA_NL80211_VENDOR_SUBCMD_SET_PROBABLE_OPER_CHANNEL) || | |
9471 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || | |
9472 | nla_put_u32(msg, | |
9473 | QCA_WLAN_VENDOR_ATTR_PROBABLE_OPER_CHANNEL_IFACE_TYPE, | |
9474 | QCA_IFACE_TYPE_P2P_CLIENT) || | |
9475 | nla_put_u32(msg, | |
9476 | QCA_WLAN_VENDOR_ATTR_PROBABLE_OPER_CHANNEL_FREQ, | |
9477 | freq)) { | |
9478 | wpa_printf(MSG_ERROR, | |
9479 | "%s: err in adding vendor_cmd and vendor_data", | |
9480 | __func__); | |
9481 | nlmsg_free(msg); | |
9482 | return -1; | |
9483 | } | |
9484 | nla_nest_end(msg, params); | |
9485 | ||
9486 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
9487 | msg = NULL; | |
9488 | if (ret) { | |
9489 | wpa_printf(MSG_ERROR, "%s: err in send_and_recv_msgs", | |
9490 | __func__); | |
9491 | return ret; | |
9492 | } | |
9493 | nlmsg_free(msg); | |
9494 | return 0; | |
9495 | } | |
9496 | ||
a6f5b193 PX |
9497 | |
9498 | static int nl80211_p2p_lo_start(void *priv, unsigned int freq, | |
9499 | unsigned int period, unsigned int interval, | |
9500 | unsigned int count, const u8 *device_types, | |
9501 | size_t dev_types_len, | |
9502 | const u8 *ies, size_t ies_len) | |
9503 | { | |
9504 | struct i802_bss *bss = priv; | |
9505 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
9506 | struct nl_msg *msg; | |
9507 | struct nlattr *container; | |
9508 | int ret; | |
9509 | ||
9510 | wpa_printf(MSG_DEBUG, | |
9511 | "nl80211: Start P2P Listen offload: freq=%u, period=%u, interval=%u, count=%u", | |
9512 | freq, period, interval, count); | |
9513 | ||
9514 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_P2P_LISTEN_OFFLOAD)) | |
9515 | return -1; | |
9516 | ||
9517 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || | |
9518 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || | |
9519 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | |
9520 | QCA_NL80211_VENDOR_SUBCMD_P2P_LISTEN_OFFLOAD_START)) | |
9521 | goto fail; | |
9522 | ||
9523 | container = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); | |
9524 | if (!container) | |
9525 | goto fail; | |
9526 | ||
9527 | if (nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_CHANNEL, | |
9528 | freq) || | |
9529 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_PERIOD, | |
9530 | period) || | |
9531 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_INTERVAL, | |
9532 | interval) || | |
9533 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_COUNT, | |
9534 | count) || | |
9535 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_DEVICE_TYPES, | |
9536 | dev_types_len, device_types) || | |
9537 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_VENDOR_IE, | |
9538 | ies_len, ies)) | |
9539 | goto fail; | |
9540 | ||
9541 | nla_nest_end(msg, container); | |
9542 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
9543 | msg = NULL; | |
9544 | if (ret) { | |
9545 | wpa_printf(MSG_DEBUG, | |
9546 | "nl80211: Failed to send P2P Listen offload vendor command"); | |
9547 | goto fail; | |
9548 | } | |
9549 | ||
9550 | return 0; | |
9551 | ||
9552 | fail: | |
9553 | nlmsg_free(msg); | |
9554 | return -1; | |
9555 | } | |
9556 | ||
9557 | ||
9558 | static int nl80211_p2p_lo_stop(void *priv) | |
9559 | { | |
9560 | struct i802_bss *bss = priv; | |
9561 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
9562 | struct nl_msg *msg; | |
9563 | ||
9564 | wpa_printf(MSG_DEBUG, "nl80211: Stop P2P Listen offload"); | |
9565 | ||
9566 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_P2P_LISTEN_OFFLOAD)) | |
9567 | return -1; | |
9568 | ||
9569 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || | |
9570 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || | |
9571 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | |
9572 | QCA_NL80211_VENDOR_SUBCMD_P2P_LISTEN_OFFLOAD_STOP)) { | |
9573 | nlmsg_free(msg); | |
9574 | return -1; | |
9575 | } | |
9576 | ||
9577 | return send_and_recv_msgs(drv, msg, NULL, NULL); | |
9578 | } | |
9579 | ||
2e4e4fb7 SD |
9580 | |
9581 | static int nl80211_set_tdls_mode(void *priv, int tdls_external_control) | |
9582 | { | |
9583 | struct i802_bss *bss = priv; | |
9584 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
9585 | struct nl_msg *msg; | |
9586 | struct nlattr *params; | |
9587 | int ret; | |
9588 | u32 tdls_mode; | |
9589 | ||
9590 | wpa_printf(MSG_DEBUG, | |
9591 | "nl80211: Set TDKS mode: tdls_external_control=%d", | |
9592 | tdls_external_control); | |
9593 | ||
9594 | if (tdls_external_control == 1) | |
9595 | tdls_mode = QCA_WLAN_VENDOR_TDLS_TRIGGER_MODE_IMPLICIT | | |
9596 | QCA_WLAN_VENDOR_TDLS_TRIGGER_MODE_EXTERNAL; | |
9597 | else | |
9598 | tdls_mode = QCA_WLAN_VENDOR_TDLS_TRIGGER_MODE_EXPLICIT; | |
9599 | ||
9600 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || | |
9601 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || | |
9602 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | |
9603 | QCA_NL80211_VENDOR_SUBCMD_CONFIGURE_TDLS)) | |
9604 | goto fail; | |
9605 | ||
9606 | params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); | |
9607 | if (!params) | |
9608 | goto fail; | |
9609 | ||
9610 | if (nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TDLS_CONFIG_TRIGGER_MODE, | |
9611 | tdls_mode)) | |
9612 | goto fail; | |
9613 | ||
9614 | nla_nest_end(msg, params); | |
9615 | ||
9616 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
9617 | msg = NULL; | |
9618 | if (ret) { | |
9619 | wpa_printf(MSG_ERROR, | |
9620 | "nl80211: Set TDLS mode failed: ret=%d (%s)", | |
9621 | ret, strerror(-ret)); | |
9622 | goto fail; | |
9623 | } | |
9624 | return 0; | |
9625 | fail: | |
9626 | nlmsg_free(msg); | |
9627 | return -1; | |
9628 | } | |
9629 | ||
b658547d JM |
9630 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
9631 | ||
7c813acf | 9632 | |
6922d440 IP |
9633 | static int nl80211_write_to_file(const char *name, unsigned int val) |
9634 | { | |
9635 | int fd, len; | |
9636 | char tmp[128]; | |
9637 | ||
9638 | fd = open(name, O_RDWR); | |
9639 | if (fd < 0) { | |
9640 | wpa_printf(MSG_ERROR, "nl80211: Failed to open %s: %s", | |
9641 | name, strerror(errno)); | |
9642 | return fd; | |
9643 | } | |
9644 | ||
9645 | len = os_snprintf(tmp, sizeof(tmp), "%u\n", val); | |
9646 | len = write(fd, tmp, len); | |
9647 | if (len < 0) | |
9648 | wpa_printf(MSG_ERROR, "nl80211: Failed to write to %s: %s", | |
9649 | name, strerror(errno)); | |
9650 | close(fd); | |
9651 | ||
9652 | return 0; | |
9653 | } | |
9654 | ||
9655 | ||
9656 | static int nl80211_configure_data_frame_filters(void *priv, u32 filter_flags) | |
9657 | { | |
9658 | struct i802_bss *bss = priv; | |
9659 | char path[128]; | |
9660 | int ret; | |
9661 | ||
9662 | wpa_printf(MSG_DEBUG, "nl80211: Data frame filter flags=0x%x", | |
9663 | filter_flags); | |
9664 | ||
9665 | /* Configure filtering of unicast frame encrypted using GTK */ | |
9666 | ret = os_snprintf(path, sizeof(path), | |
9667 | "/proc/sys/net/ipv4/conf/%s/drop_unicast_in_l2_multicast", | |
9668 | bss->ifname); | |
bd86ea08 JM |
9669 | if (os_snprintf_error(sizeof(path), ret)) |
9670 | return -1; | |
6922d440 IP |
9671 | |
9672 | ret = nl80211_write_to_file(path, | |
9673 | !!(filter_flags & | |
9674 | WPA_DATA_FRAME_FILTER_FLAG_GTK)); | |
9675 | if (ret) { | |
9676 | wpa_printf(MSG_ERROR, | |
9677 | "nl80211: Failed to set IPv4 unicast in multicast filter"); | |
9678 | return ret; | |
9679 | } | |
9680 | ||
9681 | os_snprintf(path, sizeof(path), | |
9682 | "/proc/sys/net/ipv6/conf/%s/drop_unicast_in_l2_multicast", | |
9683 | bss->ifname); | |
9684 | ret = nl80211_write_to_file(path, | |
9685 | !!(filter_flags & | |
9686 | WPA_DATA_FRAME_FILTER_FLAG_GTK)); | |
9687 | ||
9688 | if (ret) { | |
9689 | wpa_printf(MSG_ERROR, | |
9690 | "nl80211: Failed to set IPv6 unicast in multicast filter"); | |
9691 | return ret; | |
9692 | } | |
9693 | ||
9694 | /* Configure filtering of unicast frame encrypted using GTK */ | |
9695 | os_snprintf(path, sizeof(path), | |
9696 | "/proc/sys/net/ipv4/conf/%s/drop_gratuitous_arp", | |
9697 | bss->ifname); | |
9698 | ret = nl80211_write_to_file(path, | |
9699 | !!(filter_flags & | |
9700 | WPA_DATA_FRAME_FILTER_FLAG_ARP)); | |
9701 | if (ret) { | |
9702 | wpa_printf(MSG_ERROR, | |
9703 | "nl80211: Failed set gratuitous ARP filter"); | |
9704 | return ret; | |
9705 | } | |
9706 | ||
9707 | /* Configure filtering of IPv6 NA frames */ | |
9708 | os_snprintf(path, sizeof(path), | |
9709 | "/proc/sys/net/ipv6/conf/%s/drop_unsolicited_na", | |
9710 | bss->ifname); | |
9711 | ret = nl80211_write_to_file(path, | |
9712 | !!(filter_flags & | |
9713 | WPA_DATA_FRAME_FILTER_FLAG_NA)); | |
9714 | if (ret) { | |
9715 | wpa_printf(MSG_ERROR, | |
9716 | "nl80211: Failed to set unsolicited NA filter"); | |
9717 | return ret; | |
9718 | } | |
9719 | ||
9720 | return 0; | |
9721 | } | |
9722 | ||
9723 | ||
cc9a2575 KV |
9724 | static int nl80211_get_ext_capab(void *priv, enum wpa_driver_if_type type, |
9725 | const u8 **ext_capa, const u8 **ext_capa_mask, | |
9726 | unsigned int *ext_capa_len) | |
9727 | { | |
9728 | struct i802_bss *bss = priv; | |
9729 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
9730 | enum nl80211_iftype nlmode; | |
9731 | unsigned int i; | |
9732 | ||
9733 | if (!ext_capa || !ext_capa_mask || !ext_capa_len) | |
9734 | return -1; | |
9735 | ||
9736 | nlmode = wpa_driver_nl80211_if_type(type); | |
9737 | ||
9738 | /* By default, use the per-radio values */ | |
9739 | *ext_capa = drv->extended_capa; | |
9740 | *ext_capa_mask = drv->extended_capa_mask; | |
9741 | *ext_capa_len = drv->extended_capa_len; | |
9742 | ||
9743 | /* Replace the default value if a per-interface type value exists */ | |
9744 | for (i = 0; i < drv->num_iface_ext_capa; i++) { | |
9745 | if (nlmode == drv->iface_ext_capa[i].iftype) { | |
9746 | *ext_capa = drv->iface_ext_capa[i].ext_capa; | |
9747 | *ext_capa_mask = drv->iface_ext_capa[i].ext_capa_mask; | |
9748 | *ext_capa_len = drv->iface_ext_capa[i].ext_capa_len; | |
9749 | break; | |
9750 | } | |
9751 | } | |
9752 | ||
9753 | return 0; | |
9754 | } | |
9755 | ||
9756 | ||
3f5285e8 JM |
9757 | const struct wpa_driver_ops wpa_driver_nl80211_ops = { |
9758 | .name = "nl80211", | |
9759 | .desc = "Linux nl80211/cfg80211", | |
9760 | .get_bssid = wpa_driver_nl80211_get_bssid, | |
9761 | .get_ssid = wpa_driver_nl80211_get_ssid, | |
9ebce9c5 JM |
9762 | .set_key = driver_nl80211_set_key, |
9763 | .scan2 = driver_nl80211_scan2, | |
d21c63b9 LC |
9764 | .sched_scan = wpa_driver_nl80211_sched_scan, |
9765 | .stop_sched_scan = wpa_driver_nl80211_stop_sched_scan, | |
3f5285e8 | 9766 | .get_scan_results2 = wpa_driver_nl80211_get_scan_results, |
4f30addb | 9767 | .abort_scan = wpa_driver_nl80211_abort_scan, |
9ebce9c5 JM |
9768 | .deauthenticate = driver_nl80211_deauthenticate, |
9769 | .authenticate = driver_nl80211_authenticate, | |
3f5285e8 | 9770 | .associate = wpa_driver_nl80211_associate, |
f2ed8023 JM |
9771 | .global_init = nl80211_global_init, |
9772 | .global_deinit = nl80211_global_deinit, | |
9773 | .init2 = wpa_driver_nl80211_init, | |
9ebce9c5 | 9774 | .deinit = driver_nl80211_deinit, |
3f5285e8 JM |
9775 | .get_capa = wpa_driver_nl80211_get_capa, |
9776 | .set_operstate = wpa_driver_nl80211_set_operstate, | |
01652550 | 9777 | .set_supp_port = wpa_driver_nl80211_set_supp_port, |
6d158490 | 9778 | .set_country = wpa_driver_nl80211_set_country, |
f0793bf1 | 9779 | .get_country = wpa_driver_nl80211_get_country, |
19c3b566 | 9780 | .set_ap = wpa_driver_nl80211_set_ap, |
3c4ca363 | 9781 | .set_acl = wpa_driver_nl80211_set_acl, |
22a7c9d7 | 9782 | .if_add = wpa_driver_nl80211_if_add, |
9ebce9c5 JM |
9783 | .if_remove = driver_nl80211_if_remove, |
9784 | .send_mlme = driver_nl80211_send_mlme, | |
0fafeb54 | 9785 | .get_hw_feature_data = nl80211_get_hw_feature_data, |
0f4e8b4f | 9786 | .sta_add = wpa_driver_nl80211_sta_add, |
9ebce9c5 | 9787 | .sta_remove = driver_nl80211_sta_remove, |
db149ac9 | 9788 | .hapd_send_eapol = wpa_driver_nl80211_hapd_send_eapol, |
a8d6ffa4 | 9789 | .sta_set_flags = wpa_driver_nl80211_sta_set_flags, |
c5121837 | 9790 | .hapd_init = i802_init, |
c5121837 | 9791 | .hapd_deinit = i802_deinit, |
f7b3920c | 9792 | .set_wds_sta = i802_set_wds_sta, |
c5121837 JM |
9793 | .get_seqnum = i802_get_seqnum, |
9794 | .flush = i802_flush, | |
c5121837 JM |
9795 | .get_inact_sec = i802_get_inact_sec, |
9796 | .sta_clear_stats = i802_sta_clear_stats, | |
c5121837 JM |
9797 | .set_rts = i802_set_rts, |
9798 | .set_frag = i802_set_frag, | |
c5121837 | 9799 | .set_tx_queue_params = i802_set_tx_queue_params, |
9ebce9c5 | 9800 | .set_sta_vlan = driver_nl80211_set_sta_vlan, |
ee7ab173 JB |
9801 | .sta_deauth = i802_sta_deauth, |
9802 | .sta_disassoc = i802_sta_disassoc, | |
9ebce9c5 | 9803 | .read_sta_data = driver_nl80211_read_sta_data, |
e3802622 | 9804 | .set_freq = i802_set_freq, |
9ebce9c5 | 9805 | .send_action = driver_nl80211_send_action, |
5dfca53f | 9806 | .send_action_cancel_wait = wpa_driver_nl80211_send_action_cancel_wait, |
55777702 JM |
9807 | .remain_on_channel = wpa_driver_nl80211_remain_on_channel, |
9808 | .cancel_remain_on_channel = | |
9809 | wpa_driver_nl80211_cancel_remain_on_channel, | |
9ebce9c5 | 9810 | .probe_req_report = driver_nl80211_probe_req_report, |
af473088 | 9811 | .deinit_ap = wpa_driver_nl80211_deinit_ap, |
3c29244e | 9812 | .deinit_p2p_cli = wpa_driver_nl80211_deinit_p2p_cli, |
207ef3fb | 9813 | .resume = wpa_driver_nl80211_resume, |
b625473c | 9814 | .signal_monitor = nl80211_signal_monitor, |
1c5c7273 | 9815 | .signal_poll = nl80211_signal_poll, |
b91ab76e | 9816 | .send_frame = nl80211_send_frame, |
c55f774d | 9817 | .set_param = nl80211_set_param, |
6859f1cb | 9818 | .get_radio_name = nl80211_get_radio_name, |
a6efc65d JM |
9819 | .add_pmkid = nl80211_add_pmkid, |
9820 | .remove_pmkid = nl80211_remove_pmkid, | |
9821 | .flush_pmkid = nl80211_flush_pmkid, | |
b14a210c | 9822 | .set_rekey_info = nl80211_set_rekey_info, |
bcf24348 | 9823 | .poll_client = nl80211_poll_client, |
29f338af | 9824 | .set_p2p_powersave = nl80211_set_p2p_powersave, |
f90e9c1c | 9825 | .start_dfs_cac = nl80211_start_radar_detection, |
695c7038 | 9826 | .stop_ap = wpa_driver_nl80211_stop_ap, |
03ea1786 AN |
9827 | #ifdef CONFIG_TDLS |
9828 | .send_tdls_mgmt = nl80211_send_tdls_mgmt, | |
9829 | .tdls_oper = nl80211_tdls_oper, | |
72b2605f AN |
9830 | .tdls_enable_channel_switch = nl80211_tdls_enable_channel_switch, |
9831 | .tdls_disable_channel_switch = nl80211_tdls_disable_channel_switch, | |
03ea1786 | 9832 | #endif /* CONFIG_TDLS */ |
6a1ce395 | 9833 | .update_ft_ies = wpa_driver_nl80211_update_ft_ies, |
597b94f5 | 9834 | .get_mac_addr = wpa_driver_nl80211_get_macaddr, |
0185007c | 9835 | .get_survey = wpa_driver_nl80211_get_survey, |
a771c07d | 9836 | .status = wpa_driver_nl80211_status, |
1c4ffa87 | 9837 | .switch_channel = nl80211_switch_channel, |
0de38036 JM |
9838 | #ifdef ANDROID_P2P |
9839 | .set_noa = wpa_driver_set_p2p_noa, | |
9840 | .get_noa = wpa_driver_get_p2p_noa, | |
9841 | .set_ap_wps_ie = wpa_driver_set_ap_wps_p2p_ie, | |
9842 | #endif /* ANDROID_P2P */ | |
5e2c3490 | 9843 | #ifdef ANDROID |
ded14ce9 | 9844 | #ifndef ANDROID_LIB_STUB |
5e2c3490 | 9845 | .driver_cmd = wpa_driver_nl80211_driver_cmd, |
ded14ce9 | 9846 | #endif /* !ANDROID_LIB_STUB */ |
5e2c3490 | 9847 | #endif /* ANDROID */ |
adef8948 | 9848 | .vendor_cmd = nl80211_vendor_cmd, |
049105b4 | 9849 | .set_qos_map = nl80211_set_qos_map, |
e4fa8b12 | 9850 | .set_wowlan = nl80211_set_wowlan, |
fee354c7 | 9851 | .set_mac_addr = nl80211_set_mac_addr, |
6c1664f6 BC |
9852 | #ifdef CONFIG_MESH |
9853 | .init_mesh = wpa_driver_nl80211_init_mesh, | |
9854 | .join_mesh = wpa_driver_nl80211_join_mesh, | |
9855 | .leave_mesh = wpa_driver_nl80211_leave_mesh, | |
9856 | #endif /* CONFIG_MESH */ | |
71103bed KP |
9857 | .br_add_ip_neigh = wpa_driver_br_add_ip_neigh, |
9858 | .br_delete_ip_neigh = wpa_driver_br_delete_ip_neigh, | |
73d2294f | 9859 | .br_port_set_attr = wpa_driver_br_port_set_attr, |
7565752d | 9860 | .br_set_net_param = wpa_driver_br_set_net_param, |
dfa87878 MB |
9861 | .add_tx_ts = nl80211_add_ts, |
9862 | .del_tx_ts = nl80211_del_ts, | |
45e3fc72 | 9863 | .get_ifindex = nl80211_get_ifindex, |
b658547d | 9864 | #ifdef CONFIG_DRIVER_NL80211_QCA |
9607a1ae | 9865 | .roaming = nl80211_roaming, |
16689c7c | 9866 | .do_acs = wpa_driver_do_acs, |
844dfeb8 | 9867 | .set_band = nl80211_set_band, |
98342208 | 9868 | .get_pref_freq_list = nl80211_get_pref_freq_list, |
7c813acf | 9869 | .set_prob_oper_freq = nl80211_set_prob_oper_freq, |
a6f5b193 PX |
9870 | .p2p_lo_start = nl80211_p2p_lo_start, |
9871 | .p2p_lo_stop = nl80211_p2p_lo_stop, | |
cc9985d1 | 9872 | .set_default_scan_ies = nl80211_set_default_scan_ies, |
2e4e4fb7 | 9873 | .set_tdls_mode = nl80211_set_tdls_mode, |
b658547d | 9874 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
6922d440 | 9875 | .configure_data_frame_filters = nl80211_configure_data_frame_filters, |
cc9a2575 | 9876 | .get_ext_capab = nl80211_get_ext_capab, |
3f5285e8 | 9877 | }; |