]>
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; | |
2167 | /* RRM Neighbor Report Request */ | |
2168 | if (nl80211_register_action_frame(bss, (u8 *) "\x05\x04", 2) < 0) | |
2169 | ret = -1; | |
2170 | /* FT Action frames */ | |
2171 | if (nl80211_register_action_frame(bss, (u8 *) "\x06", 1) < 0) | |
2172 | ret = -1; | |
2173 | #ifdef CONFIG_IEEE80211W | |
2174 | /* SA Query */ | |
2175 | if (nl80211_register_action_frame(bss, (u8 *) "\x08", 1) < 0) | |
2176 | ret = -1; | |
2177 | #endif /* CONFIG_IEEE80211W */ | |
2178 | /* Protected Dual of Public Action */ | |
2179 | if (nl80211_register_action_frame(bss, (u8 *) "\x09", 1) < 0) | |
2180 | ret = -1; | |
2181 | /* WNM */ | |
2182 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a", 1) < 0) | |
2183 | ret = -1; | |
2184 | /* WMM */ | |
2185 | if (nl80211_register_action_frame(bss, (u8 *) "\x11", 1) < 0) | |
2186 | ret = -1; | |
2187 | #ifdef CONFIG_FST | |
2188 | /* FST Action frames */ | |
2189 | if (nl80211_register_action_frame(bss, (u8 *) "\x12", 1) < 0) | |
2190 | ret = -1; | |
2191 | #endif /* CONFIG_FST */ | |
2192 | /* Vendor-specific */ | |
2193 | if (nl80211_register_action_frame(bss, (u8 *) "\x7f", 1) < 0) | |
2194 | ret = -1; | |
2195 | ||
2196 | return ret; | |
2197 | } | |
2198 | ||
2199 | ||
a11241fa JB |
2200 | static int nl80211_mgmt_subscribe_ap(struct i802_bss *bss) |
2201 | { | |
2202 | static const int stypes[] = { | |
2203 | WLAN_FC_STYPE_AUTH, | |
2204 | WLAN_FC_STYPE_ASSOC_REQ, | |
2205 | WLAN_FC_STYPE_REASSOC_REQ, | |
2206 | WLAN_FC_STYPE_DISASSOC, | |
2207 | WLAN_FC_STYPE_DEAUTH, | |
a11241fa JB |
2208 | WLAN_FC_STYPE_PROBE_REQ, |
2209 | /* Beacon doesn't work as mac80211 doesn't currently allow | |
2210 | * it, but it wouldn't really be the right thing anyway as | |
2211 | * it isn't per interface ... maybe just dump the scan | |
2212 | * results periodically for OLBC? | |
2213 | */ | |
0e80ea2c | 2214 | /* WLAN_FC_STYPE_BEACON, */ |
a11241fa JB |
2215 | }; |
2216 | unsigned int i; | |
2217 | ||
2218 | if (nl80211_alloc_mgmt_handle(bss)) | |
71269b37 | 2219 | return -1; |
36488c05 JM |
2220 | wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with AP " |
2221 | "handle %p", bss->nl_mgmt); | |
71269b37 | 2222 | |
e7ecab4a | 2223 | for (i = 0; i < ARRAY_SIZE(stypes); i++) { |
481234cf | 2224 | if (nl80211_register_frame(bss, bss->nl_mgmt, |
a11241fa JB |
2225 | (WLAN_FC_TYPE_MGMT << 2) | |
2226 | (stypes[i] << 4), | |
2227 | NULL, 0) < 0) { | |
2228 | goto out_err; | |
2229 | } | |
2230 | } | |
2231 | ||
4d916ed6 KV |
2232 | if (nl80211_action_subscribe_ap(bss)) |
2233 | goto out_err; | |
2234 | ||
02bb32c3 JB |
2235 | if (nl80211_register_spurious_class3(bss)) |
2236 | goto out_err; | |
2237 | ||
e32ad281 JB |
2238 | if (nl80211_get_wiphy_data_ap(bss) == NULL) |
2239 | goto out_err; | |
2240 | ||
5f65e9f7 | 2241 | nl80211_mgmt_handle_register_eloop(bss); |
58f6fbe0 | 2242 | return 0; |
a11241fa JB |
2243 | |
2244 | out_err: | |
a11241fa JB |
2245 | nl_destroy_handles(&bss->nl_mgmt); |
2246 | return -1; | |
2247 | } | |
2248 | ||
2249 | ||
a6cc0602 JM |
2250 | static int nl80211_mgmt_subscribe_ap_dev_sme(struct i802_bss *bss) |
2251 | { | |
2252 | if (nl80211_alloc_mgmt_handle(bss)) | |
2253 | return -1; | |
2254 | wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with AP " | |
2255 | "handle %p (device SME)", bss->nl_mgmt); | |
2256 | ||
4d916ed6 | 2257 | if (nl80211_action_subscribe_ap(bss)) |
a6cc0602 JM |
2258 | goto out_err; |
2259 | ||
5f65e9f7 | 2260 | nl80211_mgmt_handle_register_eloop(bss); |
a6cc0602 JM |
2261 | return 0; |
2262 | ||
2263 | out_err: | |
a6cc0602 JM |
2264 | nl_destroy_handles(&bss->nl_mgmt); |
2265 | return -1; | |
2266 | } | |
2267 | ||
2268 | ||
36488c05 | 2269 | static void nl80211_mgmt_unsubscribe(struct i802_bss *bss, const char *reason) |
a11241fa | 2270 | { |
481234cf | 2271 | if (bss->nl_mgmt == NULL) |
a11241fa | 2272 | return; |
36488c05 JM |
2273 | wpa_printf(MSG_DEBUG, "nl80211: Unsubscribe mgmt frames handle %p " |
2274 | "(%s)", bss->nl_mgmt, reason); | |
5f65e9f7 | 2275 | nl80211_destroy_eloop_handle(&bss->nl_mgmt); |
e32ad281 JB |
2276 | |
2277 | nl80211_put_wiphy_data_ap(bss); | |
58f6fbe0 JM |
2278 | } |
2279 | ||
2280 | ||
8401a6b0 JM |
2281 | static void wpa_driver_nl80211_send_rfkill(void *eloop_ctx, void *timeout_ctx) |
2282 | { | |
2283 | wpa_supplicant_event(timeout_ctx, EVENT_INTERFACE_DISABLED, NULL); | |
2284 | } | |
2285 | ||
2286 | ||
eb4582f2 AS |
2287 | static void nl80211_del_p2pdev(struct i802_bss *bss) |
2288 | { | |
eb4582f2 AS |
2289 | struct nl_msg *msg; |
2290 | int ret; | |
2291 | ||
a3249fdf JM |
2292 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_DEL_INTERFACE); |
2293 | ret = send_and_recv_msgs(bss->drv, msg, NULL, NULL); | |
eb4582f2 AS |
2294 | |
2295 | wpa_printf(MSG_DEBUG, "nl80211: Delete P2P Device %s (0x%llx): %s", | |
2296 | bss->ifname, (long long unsigned int) bss->wdev_id, | |
6cb4f11d | 2297 | strerror(-ret)); |
eb4582f2 AS |
2298 | } |
2299 | ||
2300 | ||
eb4582f2 | 2301 | static int nl80211_set_p2pdev(struct i802_bss *bss, int start) |
f632e483 | 2302 | { |
f632e483 | 2303 | struct nl_msg *msg; |
a862e4a3 | 2304 | int ret; |
f632e483 | 2305 | |
a3249fdf JM |
2306 | msg = nl80211_cmd_msg(bss, 0, start ? NL80211_CMD_START_P2P_DEVICE : |
2307 | NL80211_CMD_STOP_P2P_DEVICE); | |
2308 | ret = send_and_recv_msgs(bss->drv, msg, NULL, NULL); | |
f632e483 | 2309 | |
eb4582f2 AS |
2310 | wpa_printf(MSG_DEBUG, "nl80211: %s P2P Device %s (0x%llx): %s", |
2311 | start ? "Start" : "Stop", | |
2312 | bss->ifname, (long long unsigned int) bss->wdev_id, | |
6cb4f11d | 2313 | strerror(-ret)); |
f632e483 AS |
2314 | return ret; |
2315 | } | |
f632e483 AS |
2316 | |
2317 | ||
91724d6f AS |
2318 | static int i802_set_iface_flags(struct i802_bss *bss, int up) |
2319 | { | |
2320 | enum nl80211_iftype nlmode; | |
2321 | ||
2322 | nlmode = nl80211_get_ifmode(bss); | |
2323 | if (nlmode != NL80211_IFTYPE_P2P_DEVICE) { | |
2324 | return linux_set_iface_flags(bss->drv->global->ioctl_sock, | |
2325 | bss->ifname, up); | |
2326 | } | |
2327 | ||
2328 | /* P2P Device has start/stop which is equivalent */ | |
2329 | return nl80211_set_p2pdev(bss, up); | |
2330 | } | |
2331 | ||
2332 | ||
1db718b3 JM |
2333 | #ifdef CONFIG_TESTING_OPTIONS |
2334 | static int qca_vendor_test_cmd_handler(struct nl_msg *msg, void *arg) | |
2335 | { | |
2336 | /* struct wpa_driver_nl80211_data *drv = arg; */ | |
2337 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
2338 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
2339 | ||
2340 | ||
2341 | wpa_printf(MSG_DEBUG, | |
2342 | "nl80211: QCA vendor test command response received"); | |
2343 | ||
2344 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
2345 | genlmsg_attrlen(gnlh, 0), NULL); | |
2346 | if (!tb[NL80211_ATTR_VENDOR_DATA]) { | |
2347 | wpa_printf(MSG_DEBUG, "nl80211: No vendor data attribute"); | |
2348 | return NL_SKIP; | |
2349 | } | |
2350 | ||
2351 | wpa_hexdump(MSG_DEBUG, | |
2352 | "nl80211: Received QCA vendor test command response", | |
2353 | nla_data(tb[NL80211_ATTR_VENDOR_DATA]), | |
2354 | nla_len(tb[NL80211_ATTR_VENDOR_DATA])); | |
2355 | ||
2356 | return NL_SKIP; | |
2357 | } | |
2358 | #endif /* CONFIG_TESTING_OPTIONS */ | |
2359 | ||
2360 | ||
2361 | static void qca_vendor_test(struct wpa_driver_nl80211_data *drv) | |
2362 | { | |
2363 | #ifdef CONFIG_TESTING_OPTIONS | |
2364 | struct nl_msg *msg; | |
2365 | struct nlattr *params; | |
2366 | int ret; | |
2367 | ||
2368 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || | |
2369 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || | |
2370 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | |
2371 | QCA_NL80211_VENDOR_SUBCMD_TEST) || | |
2372 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || | |
2373 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TEST, 123)) { | |
2374 | nlmsg_free(msg); | |
2375 | return; | |
2376 | } | |
2377 | nla_nest_end(msg, params); | |
2378 | ||
2379 | ret = send_and_recv_msgs(drv, msg, qca_vendor_test_cmd_handler, drv); | |
2380 | wpa_printf(MSG_DEBUG, | |
2381 | "nl80211: QCA vendor test command returned %d (%s)", | |
2382 | ret, strerror(-ret)); | |
2383 | #endif /* CONFIG_TESTING_OPTIONS */ | |
2384 | } | |
2385 | ||
2386 | ||
362f781e | 2387 | static int |
0d547d5f | 2388 | wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data *drv, |
0ecff8d7 JM |
2389 | const u8 *set_addr, int first, |
2390 | const char *driver_params) | |
7524cfb1 | 2391 | { |
834ee56f | 2392 | struct i802_bss *bss = drv->first_bss; |
8401a6b0 | 2393 | int send_rfkill_event = 0; |
0d547d5f | 2394 | enum nl80211_iftype nlmode; |
a2e40bb6 FF |
2395 | |
2396 | drv->ifindex = if_nametoindex(bss->ifname); | |
f632e483 AS |
2397 | bss->ifindex = drv->ifindex; |
2398 | bss->wdev_id = drv->global->if_add_wdevid; | |
2399 | bss->wdev_id_set = drv->global->if_add_wdevid_set; | |
2400 | ||
60b13c20 IP |
2401 | bss->if_dynamic = drv->ifindex == drv->global->if_add_ifindex; |
2402 | bss->if_dynamic = bss->if_dynamic || drv->global->if_add_wdevid_set; | |
f632e483 AS |
2403 | drv->global->if_add_wdevid_set = 0; |
2404 | ||
bf144cf6 AP |
2405 | if (!bss->if_dynamic && nl80211_get_ifmode(bss) == NL80211_IFTYPE_AP) |
2406 | bss->static_ap = 1; | |
2407 | ||
ef3866ab IP |
2408 | if (first && |
2409 | nl80211_get_ifmode(bss) != NL80211_IFTYPE_P2P_DEVICE && | |
2410 | linux_iface_up(drv->global->ioctl_sock, bss->ifname) > 0) | |
2411 | drv->start_iface_up = 1; | |
2412 | ||
f632e483 AS |
2413 | if (wpa_driver_nl80211_capa(drv)) |
2414 | return -1; | |
a87c9d96 | 2415 | |
0ecff8d7 JM |
2416 | if (driver_params && nl80211_set_param(bss, driver_params) < 0) |
2417 | return -1; | |
2418 | ||
5fbcb45d AS |
2419 | wpa_printf(MSG_DEBUG, "nl80211: interface %s in phy %s", |
2420 | bss->ifname, drv->phyname); | |
2421 | ||
0d547d5f JM |
2422 | if (set_addr && |
2423 | (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 0) || | |
2424 | linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname, | |
2425 | set_addr))) | |
2426 | return -1; | |
2427 | ||
49b4b205 JM |
2428 | if (first && nl80211_get_ifmode(bss) == NL80211_IFTYPE_AP) |
2429 | drv->start_mode_ap = 1; | |
2430 | ||
bf144cf6 | 2431 | if (drv->hostapd || bss->static_ap) |
0d547d5f | 2432 | nlmode = NL80211_IFTYPE_AP; |
4fe726e2 FF |
2433 | else if (bss->if_dynamic || |
2434 | nl80211_get_ifmode(bss) == NL80211_IFTYPE_MESH_POINT) | |
8e12685c | 2435 | nlmode = nl80211_get_ifmode(bss); |
0d547d5f JM |
2436 | else |
2437 | nlmode = NL80211_IFTYPE_STATION; | |
f632e483 | 2438 | |
8e12685c | 2439 | if (wpa_driver_nl80211_set_mode(bss, nlmode) < 0) { |
0d547d5f | 2440 | wpa_printf(MSG_ERROR, "nl80211: Could not configure driver mode"); |
8e12685c | 2441 | return -1; |
a87c9d96 JM |
2442 | } |
2443 | ||
8c06db70 | 2444 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) |
597b94f5 | 2445 | nl80211_get_macaddr(bss); |
f632e483 | 2446 | |
0e92fb8f JB |
2447 | wpa_driver_nl80211_drv_init_rfkill(drv); |
2448 | ||
8c06db70 MB |
2449 | if (!rfkill_is_blocked(drv->rfkill)) { |
2450 | int ret = i802_set_iface_flags(bss, 1); | |
2451 | if (ret) { | |
8401a6b0 JM |
2452 | wpa_printf(MSG_ERROR, "nl80211: Could not set " |
2453 | "interface '%s' UP", bss->ifname); | |
8c06db70 | 2454 | return ret; |
8401a6b0 | 2455 | } |
e8dc205f AO |
2456 | |
2457 | if (is_p2p_net_interface(nlmode)) | |
2458 | nl80211_disable_11b_rates(bss->drv, | |
2459 | bss->drv->ifindex, 1); | |
2460 | ||
8c06db70 MB |
2461 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) |
2462 | return ret; | |
2463 | } else { | |
2464 | wpa_printf(MSG_DEBUG, "nl80211: Could not yet enable " | |
2465 | "interface '%s' due to rfkill", bss->ifname); | |
6da504a1 IP |
2466 | if (nlmode != NL80211_IFTYPE_P2P_DEVICE) |
2467 | drv->if_disabled = 1; | |
2468 | ||
8c06db70 | 2469 | send_rfkill_event = 1; |
362f781e | 2470 | } |
3f5285e8 | 2471 | |
6da504a1 | 2472 | if (!drv->hostapd && nlmode != NL80211_IFTYPE_P2P_DEVICE) |
0d547d5f JM |
2473 | netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, |
2474 | 1, IF_OPER_DORMANT); | |
362f781e | 2475 | |
6da504a1 IP |
2476 | if (nlmode != NL80211_IFTYPE_P2P_DEVICE) { |
2477 | if (linux_get_ifhwaddr(drv->global->ioctl_sock, bss->ifname, | |
2478 | bss->addr)) | |
2479 | return -1; | |
2480 | os_memcpy(drv->perm_addr, bss->addr, ETH_ALEN); | |
2481 | } | |
f2ed8023 | 2482 | |
8401a6b0 JM |
2483 | if (send_rfkill_event) { |
2484 | eloop_register_timeout(0, 0, wpa_driver_nl80211_send_rfkill, | |
2485 | drv, drv->ctx); | |
2486 | } | |
2487 | ||
1db718b3 JM |
2488 | if (drv->vendor_cmd_test_avail) |
2489 | qca_vendor_test(drv); | |
2490 | ||
362f781e | 2491 | return 0; |
3f5285e8 JM |
2492 | } |
2493 | ||
2494 | ||
8a27af5c JM |
2495 | static int wpa_driver_nl80211_del_beacon(struct wpa_driver_nl80211_data *drv) |
2496 | { | |
2497 | struct nl_msg *msg; | |
2498 | ||
08e55ebb JM |
2499 | wpa_printf(MSG_DEBUG, "nl80211: Remove beacon (ifindex=%d)", |
2500 | drv->ifindex); | |
9725b784 | 2501 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_DEL_BEACON); |
8a27af5c | 2502 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
8a27af5c | 2503 | } |
8a27af5c JM |
2504 | |
2505 | ||
3f5285e8 | 2506 | /** |
7e5ba1b9 | 2507 | * wpa_driver_nl80211_deinit - Deinitialize nl80211 driver interface |
9ebce9c5 | 2508 | * @bss: Pointer to private nl80211 data from wpa_driver_nl80211_init() |
3f5285e8 JM |
2509 | * |
2510 | * Shut down driver interface and processing of driver events. Free | |
2511 | * private data buffer if one was allocated in wpa_driver_nl80211_init(). | |
2512 | */ | |
9ebce9c5 | 2513 | static void wpa_driver_nl80211_deinit(struct i802_bss *bss) |
3f5285e8 | 2514 | { |
a2e40bb6 | 2515 | struct wpa_driver_nl80211_data *drv = bss->drv; |
cc9a2575 | 2516 | unsigned int i; |
3f5285e8 | 2517 | |
3e208481 JM |
2518 | wpa_printf(MSG_INFO, "nl80211: deinit ifname=%s disabled_11b_rates=%d", |
2519 | bss->ifname, drv->disabled_11b_rates); | |
2520 | ||
873d0fcf | 2521 | bss->in_deinit = 1; |
32ab4855 JB |
2522 | if (drv->data_tx_status) |
2523 | eloop_unregister_read_sock(drv->eapol_tx_sock); | |
d12dab4c JB |
2524 | if (drv->eapol_tx_sock >= 0) |
2525 | close(drv->eapol_tx_sock); | |
f10bfc9a | 2526 | |
481234cf | 2527 | if (bss->nl_preq) |
5582a5d1 | 2528 | wpa_driver_nl80211_probe_req_report(bss, 0); |
e17a2477 | 2529 | if (bss->added_if_into_bridge) { |
c81eff1a BG |
2530 | if (linux_br_del_if(drv->global->ioctl_sock, bss->brname, |
2531 | bss->ifname) < 0) | |
94627f6c JM |
2532 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
2533 | "interface %s from bridge %s: %s", | |
e17a2477 | 2534 | bss->ifname, bss->brname, strerror(errno)); |
97ed9a06 | 2535 | if (drv->rtnl_sk) |
ca3c6b4d | 2536 | nl80211_handle_destroy(drv->rtnl_sk); |
94627f6c | 2537 | } |
e17a2477 | 2538 | if (bss->added_bridge) { |
f2535da8 JM |
2539 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->brname, |
2540 | 0) < 0) | |
2541 | wpa_printf(MSG_INFO, | |
2542 | "nl80211: Could not set bridge %s down", | |
2543 | bss->brname); | |
c81eff1a | 2544 | if (linux_br_del(drv->global->ioctl_sock, bss->brname) < 0) |
94627f6c JM |
2545 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
2546 | "bridge %s: %s", | |
e17a2477 | 2547 | bss->brname, strerror(errno)); |
94627f6c JM |
2548 | } |
2549 | ||
460456f8 | 2550 | nl80211_remove_monitor_interface(drv); |
8a27af5c | 2551 | |
b1f625e0 | 2552 | if (is_ap_interface(drv->nlmode)) |
8a27af5c | 2553 | wpa_driver_nl80211_del_beacon(drv); |
0915d02c | 2554 | |
bbaf0837 JM |
2555 | if (drv->eapol_sock >= 0) { |
2556 | eloop_unregister_read_sock(drv->eapol_sock); | |
2557 | close(drv->eapol_sock); | |
2558 | } | |
2559 | ||
2560 | if (drv->if_indices != drv->default_if_indices) | |
2561 | os_free(drv->if_indices); | |
3f5285e8 | 2562 | |
732b1d20 MB |
2563 | if (drv->if_indices_reason != drv->default_if_indices_reason) |
2564 | os_free(drv->if_indices_reason); | |
2565 | ||
b3af99d2 | 2566 | if (drv->disabled_11b_rates) |
4e5cb1a3 JM |
2567 | nl80211_disable_11b_rates(drv, drv->ifindex, 0); |
2568 | ||
36d84860 BG |
2569 | netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, 0, |
2570 | IF_OPER_UP); | |
e390df05 | 2571 | eloop_cancel_timeout(wpa_driver_nl80211_send_rfkill, drv, drv->ctx); |
8401a6b0 | 2572 | rfkill_deinit(drv->rfkill); |
3f5285e8 | 2573 | |
bbaf0837 JM |
2574 | eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout, drv, drv->ctx); |
2575 | ||
146fa9b3 JM |
2576 | if (!drv->start_iface_up) |
2577 | (void) i802_set_iface_flags(bss, 0); | |
fee354c7 JM |
2578 | |
2579 | if (drv->addr_changed) { | |
93da0498 JM |
2580 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, |
2581 | 0) < 0) { | |
2582 | wpa_printf(MSG_DEBUG, | |
2583 | "nl80211: Could not set interface down to restore permanent MAC address"); | |
2584 | } | |
fee354c7 JM |
2585 | if (linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
2586 | drv->perm_addr) < 0) { | |
2587 | wpa_printf(MSG_DEBUG, | |
2588 | "nl80211: Could not restore permanent MAC address"); | |
2589 | } | |
2590 | } | |
2591 | ||
8e12685c | 2592 | if (drv->nlmode != NL80211_IFTYPE_P2P_DEVICE) { |
49b4b205 JM |
2593 | if (!drv->hostapd || !drv->start_mode_ap) |
2594 | wpa_driver_nl80211_set_mode(bss, | |
2595 | NL80211_IFTYPE_STATION); | |
b378c41f | 2596 | nl80211_mgmt_unsubscribe(bss, "deinit"); |
8e12685c AS |
2597 | } else { |
2598 | nl80211_mgmt_unsubscribe(bss, "deinit"); | |
eb4582f2 | 2599 | nl80211_del_p2pdev(bss); |
8e12685c | 2600 | } |
3f5285e8 | 2601 | |
834ee56f | 2602 | nl80211_destroy_bss(drv->first_bss); |
cc7a48d1 | 2603 | |
3812464c JM |
2604 | os_free(drv->filter_ssids); |
2605 | ||
536fd62d JM |
2606 | os_free(drv->auth_ie); |
2607 | ||
dac12351 | 2608 | if (drv->in_interface_list) |
f2ed8023 JM |
2609 | dl_list_del(&drv->list); |
2610 | ||
8cd6b7bc JB |
2611 | os_free(drv->extended_capa); |
2612 | os_free(drv->extended_capa_mask); | |
cc9a2575 KV |
2613 | for (i = 0; i < drv->num_iface_ext_capa; i++) { |
2614 | os_free(drv->iface_ext_capa[i].ext_capa); | |
2615 | os_free(drv->iface_ext_capa[i].ext_capa_mask); | |
2616 | } | |
834ee56f | 2617 | os_free(drv->first_bss); |
3f5285e8 JM |
2618 | os_free(drv); |
2619 | } | |
2620 | ||
2621 | ||
de4ed4a8 JM |
2622 | static u32 wpa_alg_to_cipher_suite(enum wpa_alg alg, size_t key_len) |
2623 | { | |
2624 | switch (alg) { | |
2625 | case WPA_ALG_WEP: | |
2626 | if (key_len == 5) | |
2627 | return WLAN_CIPHER_SUITE_WEP40; | |
2628 | return WLAN_CIPHER_SUITE_WEP104; | |
2629 | case WPA_ALG_TKIP: | |
2630 | return WLAN_CIPHER_SUITE_TKIP; | |
2631 | case WPA_ALG_CCMP: | |
2632 | return WLAN_CIPHER_SUITE_CCMP; | |
2633 | case WPA_ALG_GCMP: | |
2634 | return WLAN_CIPHER_SUITE_GCMP; | |
2635 | case WPA_ALG_CCMP_256: | |
2636 | return WLAN_CIPHER_SUITE_CCMP_256; | |
2637 | case WPA_ALG_GCMP_256: | |
2638 | return WLAN_CIPHER_SUITE_GCMP_256; | |
2639 | case WPA_ALG_IGTK: | |
2640 | return WLAN_CIPHER_SUITE_AES_CMAC; | |
2641 | case WPA_ALG_BIP_GMAC_128: | |
2642 | return WLAN_CIPHER_SUITE_BIP_GMAC_128; | |
2643 | case WPA_ALG_BIP_GMAC_256: | |
2644 | return WLAN_CIPHER_SUITE_BIP_GMAC_256; | |
2645 | case WPA_ALG_BIP_CMAC_256: | |
2646 | return WLAN_CIPHER_SUITE_BIP_CMAC_256; | |
2647 | case WPA_ALG_SMS4: | |
2648 | return WLAN_CIPHER_SUITE_SMS4; | |
2649 | case WPA_ALG_KRK: | |
2650 | return WLAN_CIPHER_SUITE_KRK; | |
2651 | case WPA_ALG_NONE: | |
2652 | case WPA_ALG_PMK: | |
2653 | wpa_printf(MSG_ERROR, "nl80211: Unexpected encryption algorithm %d", | |
2654 | alg); | |
2655 | return 0; | |
2656 | } | |
2657 | ||
2658 | wpa_printf(MSG_ERROR, "nl80211: Unsupported encryption algorithm %d", | |
2659 | alg); | |
2660 | return 0; | |
2661 | } | |
2662 | ||
2663 | ||
2664 | static u32 wpa_cipher_to_cipher_suite(unsigned int cipher) | |
2665 | { | |
2666 | switch (cipher) { | |
2667 | case WPA_CIPHER_CCMP_256: | |
2668 | return WLAN_CIPHER_SUITE_CCMP_256; | |
2669 | case WPA_CIPHER_GCMP_256: | |
2670 | return WLAN_CIPHER_SUITE_GCMP_256; | |
2671 | case WPA_CIPHER_CCMP: | |
2672 | return WLAN_CIPHER_SUITE_CCMP; | |
2673 | case WPA_CIPHER_GCMP: | |
2674 | return WLAN_CIPHER_SUITE_GCMP; | |
2675 | case WPA_CIPHER_TKIP: | |
2676 | return WLAN_CIPHER_SUITE_TKIP; | |
2677 | case WPA_CIPHER_WEP104: | |
2678 | return WLAN_CIPHER_SUITE_WEP104; | |
2679 | case WPA_CIPHER_WEP40: | |
2680 | return WLAN_CIPHER_SUITE_WEP40; | |
ae6f9272 JM |
2681 | case WPA_CIPHER_GTK_NOT_USED: |
2682 | return WLAN_CIPHER_SUITE_NO_GROUP_ADDR; | |
de4ed4a8 JM |
2683 | } |
2684 | ||
2685 | return 0; | |
2686 | } | |
2687 | ||
2688 | ||
2689 | static int wpa_cipher_to_cipher_suites(unsigned int ciphers, u32 suites[], | |
2690 | int max_suites) | |
2691 | { | |
2692 | int num_suites = 0; | |
2693 | ||
2694 | if (num_suites < max_suites && ciphers & WPA_CIPHER_CCMP_256) | |
2695 | suites[num_suites++] = WLAN_CIPHER_SUITE_CCMP_256; | |
2696 | if (num_suites < max_suites && ciphers & WPA_CIPHER_GCMP_256) | |
2697 | suites[num_suites++] = WLAN_CIPHER_SUITE_GCMP_256; | |
2698 | if (num_suites < max_suites && ciphers & WPA_CIPHER_CCMP) | |
2699 | suites[num_suites++] = WLAN_CIPHER_SUITE_CCMP; | |
2700 | if (num_suites < max_suites && ciphers & WPA_CIPHER_GCMP) | |
2701 | suites[num_suites++] = WLAN_CIPHER_SUITE_GCMP; | |
2702 | if (num_suites < max_suites && ciphers & WPA_CIPHER_TKIP) | |
2703 | suites[num_suites++] = WLAN_CIPHER_SUITE_TKIP; | |
2704 | if (num_suites < max_suites && ciphers & WPA_CIPHER_WEP104) | |
2705 | suites[num_suites++] = WLAN_CIPHER_SUITE_WEP104; | |
2706 | if (num_suites < max_suites && ciphers & WPA_CIPHER_WEP40) | |
2707 | suites[num_suites++] = WLAN_CIPHER_SUITE_WEP40; | |
2708 | ||
2709 | return num_suites; | |
2710 | } | |
2711 | ||
2712 | ||
b658547d | 2713 | #ifdef CONFIG_DRIVER_NL80211_QCA |
b41f2684 CL |
2714 | static int issue_key_mgmt_set_key(struct wpa_driver_nl80211_data *drv, |
2715 | const u8 *key, size_t key_len) | |
2716 | { | |
2717 | struct nl_msg *msg; | |
a862e4a3 | 2718 | int ret; |
b41f2684 | 2719 | |
15badebd | 2720 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD)) |
b41f2684 CL |
2721 | return 0; |
2722 | ||
9725b784 | 2723 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
a862e4a3 JM |
2724 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
2725 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | |
2726 | QCA_NL80211_VENDOR_SUBCMD_KEY_MGMT_SET_KEY) || | |
2727 | nla_put(msg, NL80211_ATTR_VENDOR_DATA, key_len, key)) { | |
bbd89bfc | 2728 | nl80211_nlmsg_clear(msg); |
a862e4a3 JM |
2729 | nlmsg_free(msg); |
2730 | return -1; | |
2731 | } | |
bbd89bfc | 2732 | ret = send_and_recv_msgs(drv, msg, NULL, (void *) -1); |
b41f2684 CL |
2733 | if (ret) { |
2734 | wpa_printf(MSG_DEBUG, | |
2735 | "nl80211: Key management set key failed: ret=%d (%s)", | |
2736 | ret, strerror(-ret)); | |
2737 | } | |
2738 | ||
b41f2684 CL |
2739 | return ret; |
2740 | } | |
b658547d | 2741 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
b41f2684 CL |
2742 | |
2743 | ||
9ebce9c5 | 2744 | static int wpa_driver_nl80211_set_key(const char *ifname, struct i802_bss *bss, |
71934751 JM |
2745 | enum wpa_alg alg, const u8 *addr, |
2746 | int key_idx, int set_tx, | |
642187d6 JM |
2747 | const u8 *seq, size_t seq_len, |
2748 | const u8 *key, size_t key_len) | |
3f5285e8 | 2749 | { |
a2e40bb6 | 2750 | struct wpa_driver_nl80211_data *drv = bss->drv; |
e472e1b4 | 2751 | int ifindex; |
34651767 | 2752 | struct nl_msg *msg = NULL; |
1ad1cdc2 | 2753 | int ret; |
dc01de8a | 2754 | int tdls = 0; |
3f5285e8 | 2755 | |
e472e1b4 AS |
2756 | /* Ignore for P2P Device */ |
2757 | if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) | |
2758 | return 0; | |
2759 | ||
2760 | ifindex = if_nametoindex(ifname); | |
8393e1a0 | 2761 | wpa_printf(MSG_DEBUG, "%s: ifindex=%d (%s) alg=%d addr=%p key_idx=%d " |
1ad1cdc2 | 2762 | "set_tx=%d seq_len=%lu key_len=%lu", |
8393e1a0 | 2763 | __func__, ifindex, ifname, alg, addr, key_idx, set_tx, |
3f5285e8 | 2764 | (unsigned long) seq_len, (unsigned long) key_len); |
8c66e185 | 2765 | #ifdef CONFIG_TDLS |
dc01de8a | 2766 | if (key_idx == -1) { |
8c66e185 | 2767 | key_idx = 0; |
dc01de8a JM |
2768 | tdls = 1; |
2769 | } | |
8c66e185 | 2770 | #endif /* CONFIG_TDLS */ |
3f5285e8 | 2771 | |
b658547d | 2772 | #ifdef CONFIG_DRIVER_NL80211_QCA |
15badebd CL |
2773 | if (alg == WPA_ALG_PMK && |
2774 | (drv->capa.flags & WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD)) { | |
b41f2684 CL |
2775 | wpa_printf(MSG_DEBUG, "%s: calling issue_key_mgmt_set_key", |
2776 | __func__); | |
2777 | ret = issue_key_mgmt_set_key(drv, key, key_len); | |
2778 | return ret; | |
2779 | } | |
b658547d | 2780 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
b41f2684 | 2781 | |
3f5285e8 | 2782 | if (alg == WPA_ALG_NONE) { |
95376e1a JM |
2783 | msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_DEL_KEY); |
2784 | if (!msg) | |
2785 | return -ENOBUFS; | |
3f5285e8 | 2786 | } else { |
34651767 JM |
2787 | u32 suite; |
2788 | ||
2789 | suite = wpa_alg_to_cipher_suite(alg, key_len); | |
2790 | if (!suite) | |
2791 | goto fail; | |
95376e1a JM |
2792 | msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_NEW_KEY); |
2793 | if (!msg || | |
a862e4a3 | 2794 | nla_put(msg, NL80211_ATTR_KEY_DATA, key_len, key) || |
34651767 | 2795 | nla_put_u32(msg, NL80211_ATTR_KEY_CIPHER, suite)) |
a862e4a3 | 2796 | goto fail; |
e6ef73f1 | 2797 | wpa_hexdump_key(MSG_DEBUG, "nl80211: KEY_DATA", key, key_len); |
3f5285e8 JM |
2798 | } |
2799 | ||
e6ef73f1 | 2800 | if (seq && seq_len) { |
a862e4a3 JM |
2801 | if (nla_put(msg, NL80211_ATTR_KEY_SEQ, seq_len, seq)) |
2802 | goto fail; | |
e6ef73f1 JM |
2803 | wpa_hexdump(MSG_DEBUG, "nl80211: KEY_SEQ", seq, seq_len); |
2804 | } | |
1ad1cdc2 | 2805 | |
0382097e | 2806 | if (addr && !is_broadcast_ether_addr(addr)) { |
3f5285e8 | 2807 | wpa_printf(MSG_DEBUG, " addr=" MACSTR, MAC2STR(addr)); |
a862e4a3 JM |
2808 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
2809 | goto fail; | |
89c38e32 JM |
2810 | |
2811 | if (alg != WPA_ALG_WEP && key_idx && !set_tx) { | |
2812 | wpa_printf(MSG_DEBUG, " RSN IBSS RX GTK"); | |
a862e4a3 JM |
2813 | if (nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, |
2814 | NL80211_KEYTYPE_GROUP)) | |
2815 | goto fail; | |
89c38e32 | 2816 | } |
60ea8187 | 2817 | } else if (addr && is_broadcast_ether_addr(addr)) { |
8970bae8 JB |
2818 | struct nlattr *types; |
2819 | ||
60ea8187 | 2820 | wpa_printf(MSG_DEBUG, " broadcast key"); |
8970bae8 JB |
2821 | |
2822 | types = nla_nest_start(msg, NL80211_ATTR_KEY_DEFAULT_TYPES); | |
a862e4a3 JM |
2823 | if (!types || |
2824 | nla_put_flag(msg, NL80211_KEY_DEFAULT_TYPE_MULTICAST)) | |
2825 | goto fail; | |
8970bae8 | 2826 | nla_nest_end(msg, types); |
3f5285e8 | 2827 | } |
95376e1a | 2828 | if (nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) |
a862e4a3 | 2829 | goto fail; |
3f5285e8 | 2830 | |
bbd89bfc | 2831 | ret = send_and_recv_msgs(drv, msg, NULL, key ? (void *) -1 : NULL); |
15664ad0 | 2832 | if ((ret == -ENOENT || ret == -ENOLINK) && alg == WPA_ALG_NONE) |
1ad1cdc2 JM |
2833 | ret = 0; |
2834 | if (ret) | |
2835 | wpa_printf(MSG_DEBUG, "nl80211: set_key failed; err=%d %s)", | |
2836 | ret, strerror(-ret)); | |
3f5285e8 | 2837 | |
1ad1cdc2 JM |
2838 | /* |
2839 | * If we failed or don't need to set the default TX key (below), | |
2840 | * we're done here. | |
2841 | */ | |
dc01de8a | 2842 | if (ret || !set_tx || alg == WPA_ALG_NONE || tdls) |
1ad1cdc2 | 2843 | return ret; |
b1f625e0 | 2844 | if (is_ap_interface(drv->nlmode) && addr && |
0382097e | 2845 | !is_broadcast_ether_addr(addr)) |
de12717a | 2846 | return ret; |
3f5285e8 | 2847 | |
95376e1a JM |
2848 | msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_SET_KEY); |
2849 | if (!msg || | |
a862e4a3 | 2850 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx) || |
86f9b1c7 JM |
2851 | nla_put_flag(msg, (alg == WPA_ALG_IGTK || |
2852 | alg == WPA_ALG_BIP_GMAC_128 || | |
2853 | alg == WPA_ALG_BIP_GMAC_256 || | |
2854 | alg == WPA_ALG_BIP_CMAC_256) ? | |
a862e4a3 JM |
2855 | NL80211_ATTR_KEY_DEFAULT_MGMT : |
2856 | NL80211_ATTR_KEY_DEFAULT)) | |
2857 | goto fail; | |
60ea8187 | 2858 | if (addr && is_broadcast_ether_addr(addr)) { |
8970bae8 JB |
2859 | struct nlattr *types; |
2860 | ||
2861 | types = nla_nest_start(msg, NL80211_ATTR_KEY_DEFAULT_TYPES); | |
a862e4a3 JM |
2862 | if (!types || |
2863 | nla_put_flag(msg, NL80211_KEY_DEFAULT_TYPE_MULTICAST)) | |
2864 | goto fail; | |
8970bae8 | 2865 | nla_nest_end(msg, types); |
60ea8187 | 2866 | } else if (addr) { |
8970bae8 JB |
2867 | struct nlattr *types; |
2868 | ||
2869 | types = nla_nest_start(msg, NL80211_ATTR_KEY_DEFAULT_TYPES); | |
a862e4a3 JM |
2870 | if (!types || |
2871 | nla_put_flag(msg, NL80211_KEY_DEFAULT_TYPE_UNICAST)) | |
2872 | goto fail; | |
8970bae8 | 2873 | nla_nest_end(msg, types); |
60ea8187 | 2874 | } |
3f5285e8 | 2875 | |
1ad1cdc2 JM |
2876 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
2877 | if (ret == -ENOENT) | |
2878 | ret = 0; | |
2879 | if (ret) | |
2880 | wpa_printf(MSG_DEBUG, "nl80211: set_key default failed; " | |
2881 | "err=%d %s)", ret, strerror(-ret)); | |
2882 | return ret; | |
3f5285e8 | 2883 | |
a862e4a3 | 2884 | fail: |
bbd89bfc | 2885 | nl80211_nlmsg_clear(msg); |
5883168a | 2886 | nlmsg_free(msg); |
6241fcb1 | 2887 | return -ENOBUFS; |
3f5285e8 JM |
2888 | } |
2889 | ||
2890 | ||
71934751 | 2891 | static int nl_add_key(struct nl_msg *msg, enum wpa_alg alg, |
0194fedb JB |
2892 | int key_idx, int defkey, |
2893 | const u8 *seq, size_t seq_len, | |
2894 | const u8 *key, size_t key_len) | |
2895 | { | |
2896 | struct nlattr *key_attr = nla_nest_start(msg, NL80211_ATTR_KEY); | |
34651767 JM |
2897 | u32 suite; |
2898 | ||
0194fedb JB |
2899 | if (!key_attr) |
2900 | return -1; | |
2901 | ||
34651767 JM |
2902 | suite = wpa_alg_to_cipher_suite(alg, key_len); |
2903 | if (!suite) | |
2904 | return -1; | |
2905 | ||
a862e4a3 JM |
2906 | if (defkey && alg == WPA_ALG_IGTK) { |
2907 | if (nla_put_flag(msg, NL80211_KEY_DEFAULT_MGMT)) | |
2908 | return -1; | |
2909 | } else if (defkey) { | |
2910 | if (nla_put_flag(msg, NL80211_KEY_DEFAULT)) | |
2911 | return -1; | |
2912 | } | |
0194fedb | 2913 | |
a862e4a3 | 2914 | if (nla_put_u8(msg, NL80211_KEY_IDX, key_idx) || |
34651767 | 2915 | nla_put_u32(msg, NL80211_KEY_CIPHER, suite) || |
a862e4a3 JM |
2916 | (seq && seq_len && |
2917 | nla_put(msg, NL80211_KEY_SEQ, seq_len, seq)) || | |
2918 | nla_put(msg, NL80211_KEY_DATA, key_len, key)) | |
2919 | return -1; | |
0194fedb JB |
2920 | |
2921 | nla_nest_end(msg, key_attr); | |
2922 | ||
2923 | return 0; | |
0194fedb JB |
2924 | } |
2925 | ||
c811d5bc | 2926 | |
cfaab580 ZY |
2927 | static int nl80211_set_conn_keys(struct wpa_driver_associate_params *params, |
2928 | struct nl_msg *msg) | |
2929 | { | |
2930 | int i, privacy = 0; | |
2931 | struct nlattr *nl_keys, *nl_key; | |
2932 | ||
2933 | for (i = 0; i < 4; i++) { | |
2934 | if (!params->wep_key[i]) | |
2935 | continue; | |
2936 | privacy = 1; | |
2937 | break; | |
2938 | } | |
ce04af5a JM |
2939 | if (params->wps == WPS_MODE_PRIVACY) |
2940 | privacy = 1; | |
2941 | if (params->pairwise_suite && | |
2942 | params->pairwise_suite != WPA_CIPHER_NONE) | |
2943 | privacy = 1; | |
2944 | ||
cfaab580 ZY |
2945 | if (!privacy) |
2946 | return 0; | |
2947 | ||
a862e4a3 JM |
2948 | if (nla_put_flag(msg, NL80211_ATTR_PRIVACY)) |
2949 | return -ENOBUFS; | |
cfaab580 ZY |
2950 | |
2951 | nl_keys = nla_nest_start(msg, NL80211_ATTR_KEYS); | |
2952 | if (!nl_keys) | |
a862e4a3 | 2953 | return -ENOBUFS; |
cfaab580 ZY |
2954 | |
2955 | for (i = 0; i < 4; i++) { | |
2956 | if (!params->wep_key[i]) | |
2957 | continue; | |
2958 | ||
2959 | nl_key = nla_nest_start(msg, i); | |
a862e4a3 JM |
2960 | if (!nl_key || |
2961 | nla_put(msg, NL80211_KEY_DATA, params->wep_key_len[i], | |
2962 | params->wep_key[i]) || | |
2963 | nla_put_u32(msg, NL80211_KEY_CIPHER, | |
2964 | params->wep_key_len[i] == 5 ? | |
2965 | WLAN_CIPHER_SUITE_WEP40 : | |
2966 | WLAN_CIPHER_SUITE_WEP104) || | |
2967 | nla_put_u8(msg, NL80211_KEY_IDX, i) || | |
2968 | (i == params->wep_tx_keyidx && | |
2969 | nla_put_flag(msg, NL80211_KEY_DEFAULT))) | |
2970 | return -ENOBUFS; | |
cfaab580 ZY |
2971 | |
2972 | nla_nest_end(msg, nl_key); | |
2973 | } | |
2974 | nla_nest_end(msg, nl_keys); | |
2975 | ||
2976 | return 0; | |
cfaab580 ZY |
2977 | } |
2978 | ||
2979 | ||
477af8f8 JM |
2980 | int wpa_driver_nl80211_mlme(struct wpa_driver_nl80211_data *drv, |
2981 | const u8 *addr, int cmd, u16 reason_code, | |
2982 | int local_state_change) | |
c2a04078 | 2983 | { |
a862e4a3 | 2984 | int ret; |
c2a04078 JM |
2985 | struct nl_msg *msg; |
2986 | ||
9725b784 | 2987 | if (!(msg = nl80211_drv_msg(drv, 0, cmd)) || |
a862e4a3 JM |
2988 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code) || |
2989 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || | |
2990 | (local_state_change && | |
2991 | nla_put_flag(msg, NL80211_ATTR_LOCAL_STATE_CHANGE))) { | |
2992 | nlmsg_free(msg); | |
2993 | return -1; | |
2994 | } | |
c2a04078 JM |
2995 | |
2996 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
c2a04078 | 2997 | if (ret) { |
3b7ea880 BG |
2998 | wpa_dbg(drv->ctx, MSG_DEBUG, |
2999 | "nl80211: MLME command failed: reason=%u ret=%d (%s)", | |
3000 | reason_code, ret, strerror(-ret)); | |
c2a04078 | 3001 | } |
c2a04078 JM |
3002 | return ret; |
3003 | } | |
3f5285e8 JM |
3004 | |
3005 | ||
cfaab580 | 3006 | static int wpa_driver_nl80211_disconnect(struct wpa_driver_nl80211_data *drv, |
817762d9 | 3007 | int reason_code) |
cfaab580 | 3008 | { |
3f53c006 JJ |
3009 | int ret; |
3010 | ||
817762d9 | 3011 | wpa_printf(MSG_DEBUG, "%s(reason_code=%d)", __func__, reason_code); |
add9b7a4 | 3012 | nl80211_mark_disconnected(drv); |
817762d9 | 3013 | /* Disconnect command doesn't need BSSID - it uses cached value */ |
3f53c006 JJ |
3014 | ret = wpa_driver_nl80211_mlme(drv, NULL, NL80211_CMD_DISCONNECT, |
3015 | reason_code, 0); | |
3016 | /* | |
3017 | * For locally generated disconnect, supplicant already generates a | |
3018 | * DEAUTH event, so ignore the event from NL80211. | |
3019 | */ | |
3020 | drv->ignore_next_local_disconnect = ret == 0; | |
3021 | ||
3022 | return ret; | |
cfaab580 ZY |
3023 | } |
3024 | ||
3025 | ||
9ebce9c5 JM |
3026 | static int wpa_driver_nl80211_deauthenticate(struct i802_bss *bss, |
3027 | const u8 *addr, int reason_code) | |
3f5285e8 | 3028 | { |
a2e40bb6 | 3029 | struct wpa_driver_nl80211_data *drv = bss->drv; |
d6a36f39 | 3030 | int ret; |
9392c9be AS |
3031 | |
3032 | if (drv->nlmode == NL80211_IFTYPE_ADHOC) { | |
3033 | nl80211_mark_disconnected(drv); | |
666e508c | 3034 | return nl80211_leave_ibss(drv, 1); |
9392c9be | 3035 | } |
cfaab580 | 3036 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) |
817762d9 | 3037 | return wpa_driver_nl80211_disconnect(drv, reason_code); |
2e75a2b3 JM |
3038 | wpa_printf(MSG_DEBUG, "%s(addr=" MACSTR " reason_code=%d)", |
3039 | __func__, MAC2STR(addr), reason_code); | |
add9b7a4 | 3040 | nl80211_mark_disconnected(drv); |
d6a36f39 JM |
3041 | ret = wpa_driver_nl80211_mlme(drv, addr, NL80211_CMD_DEAUTHENTICATE, |
3042 | reason_code, 0); | |
3043 | /* | |
3044 | * For locally generated deauthenticate, supplicant already generates a | |
3045 | * DEAUTH event, so ignore the event from NL80211. | |
3046 | */ | |
3047 | drv->ignore_next_local_deauth = ret == 0; | |
3048 | return ret; | |
3f5285e8 JM |
3049 | } |
3050 | ||
3051 | ||
536fd62d JM |
3052 | static void nl80211_copy_auth_params(struct wpa_driver_nl80211_data *drv, |
3053 | struct wpa_driver_auth_params *params) | |
3054 | { | |
3055 | int i; | |
3056 | ||
3057 | drv->auth_freq = params->freq; | |
3058 | drv->auth_alg = params->auth_alg; | |
3059 | drv->auth_wep_tx_keyidx = params->wep_tx_keyidx; | |
3060 | drv->auth_local_state_change = params->local_state_change; | |
3061 | drv->auth_p2p = params->p2p; | |
3062 | ||
3063 | if (params->bssid) | |
3064 | os_memcpy(drv->auth_bssid_, params->bssid, ETH_ALEN); | |
3065 | else | |
3066 | os_memset(drv->auth_bssid_, 0, ETH_ALEN); | |
3067 | ||
3068 | if (params->ssid) { | |
3069 | os_memcpy(drv->auth_ssid, params->ssid, params->ssid_len); | |
3070 | drv->auth_ssid_len = params->ssid_len; | |
3071 | } else | |
3072 | drv->auth_ssid_len = 0; | |
3073 | ||
3074 | ||
3075 | os_free(drv->auth_ie); | |
3076 | drv->auth_ie = NULL; | |
3077 | drv->auth_ie_len = 0; | |
3078 | if (params->ie) { | |
3079 | drv->auth_ie = os_malloc(params->ie_len); | |
3080 | if (drv->auth_ie) { | |
3081 | os_memcpy(drv->auth_ie, params->ie, params->ie_len); | |
3082 | drv->auth_ie_len = params->ie_len; | |
3083 | } | |
3084 | } | |
3085 | ||
3086 | for (i = 0; i < 4; i++) { | |
3087 | if (params->wep_key[i] && params->wep_key_len[i] && | |
3088 | params->wep_key_len[i] <= 16) { | |
3089 | os_memcpy(drv->auth_wep_key[i], params->wep_key[i], | |
3090 | params->wep_key_len[i]); | |
3091 | drv->auth_wep_key_len[i] = params->wep_key_len[i]; | |
3092 | } else | |
3093 | drv->auth_wep_key_len[i] = 0; | |
3094 | } | |
3095 | } | |
3096 | ||
3097 | ||
4bd71954 JM |
3098 | static void nl80211_unmask_11b_rates(struct i802_bss *bss) |
3099 | { | |
3100 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
3101 | ||
3102 | if (is_p2p_net_interface(drv->nlmode) || !drv->disabled_11b_rates) | |
3103 | return; | |
3104 | ||
3105 | /* | |
3106 | * Looks like we failed to unmask 11b rates previously. This could | |
3107 | * happen, e.g., if the interface was down at the point in time when a | |
3108 | * P2P group was terminated. | |
3109 | */ | |
3110 | wpa_printf(MSG_DEBUG, | |
3111 | "nl80211: Interface %s mode is for non-P2P, but 11b rates were disabled - re-enable them", | |
3112 | bss->ifname); | |
3113 | nl80211_disable_11b_rates(drv, drv->ifindex, 0); | |
3114 | } | |
3115 | ||
3116 | ||
c2a04078 | 3117 | static int wpa_driver_nl80211_authenticate( |
9ebce9c5 | 3118 | struct i802_bss *bss, struct wpa_driver_auth_params *params) |
c2a04078 | 3119 | { |
a2e40bb6 | 3120 | struct wpa_driver_nl80211_data *drv = bss->drv; |
a0b2f99b | 3121 | int ret = -1, i; |
c2a04078 JM |
3122 | struct nl_msg *msg; |
3123 | enum nl80211_auth_type type; | |
2f4f73b1 | 3124 | enum nl80211_iftype nlmode; |
6d6f4bb8 | 3125 | int count = 0; |
536fd62d JM |
3126 | int is_retry; |
3127 | ||
4bd71954 JM |
3128 | nl80211_unmask_11b_rates(bss); |
3129 | ||
536fd62d JM |
3130 | is_retry = drv->retry_auth; |
3131 | drv->retry_auth = 0; | |
e8d70a73 | 3132 | drv->ignore_deauth_event = 0; |
c2a04078 | 3133 | |
add9b7a4 | 3134 | nl80211_mark_disconnected(drv); |
e6b8efeb | 3135 | os_memset(drv->auth_bssid, 0, ETH_ALEN); |
add9b7a4 JM |
3136 | if (params->bssid) |
3137 | os_memcpy(drv->auth_attempt_bssid, params->bssid, ETH_ALEN); | |
3138 | else | |
3139 | os_memset(drv->auth_attempt_bssid, 0, ETH_ALEN); | |
af473088 | 3140 | /* FIX: IBSS mode */ |
2f4f73b1 EP |
3141 | nlmode = params->p2p ? |
3142 | NL80211_IFTYPE_P2P_CLIENT : NL80211_IFTYPE_STATION; | |
3143 | if (drv->nlmode != nlmode && | |
9ebce9c5 | 3144 | wpa_driver_nl80211_set_mode(bss, nlmode) < 0) |
4a867032 JM |
3145 | return -1; |
3146 | ||
6d6f4bb8 | 3147 | retry: |
c2a04078 JM |
3148 | wpa_printf(MSG_DEBUG, "nl80211: Authenticate (ifindex=%d)", |
3149 | drv->ifindex); | |
a0b2f99b | 3150 | |
9725b784 JM |
3151 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_AUTHENTICATE); |
3152 | if (!msg) | |
3153 | goto fail; | |
0194fedb | 3154 | |
a0b2f99b JM |
3155 | for (i = 0; i < 4; i++) { |
3156 | if (!params->wep_key[i]) | |
3157 | continue; | |
9ebce9c5 | 3158 | wpa_driver_nl80211_set_key(bss->ifname, bss, WPA_ALG_WEP, |
2ea2fcc7 | 3159 | NULL, i, |
a0b2f99b JM |
3160 | i == params->wep_tx_keyidx, NULL, 0, |
3161 | params->wep_key[i], | |
3162 | params->wep_key_len[i]); | |
0194fedb JB |
3163 | if (params->wep_tx_keyidx != i) |
3164 | continue; | |
3165 | if (nl_add_key(msg, WPA_ALG_WEP, i, 1, NULL, 0, | |
9725b784 JM |
3166 | params->wep_key[i], params->wep_key_len[i])) |
3167 | goto fail; | |
a0b2f99b JM |
3168 | } |
3169 | ||
c2a04078 JM |
3170 | if (params->bssid) { |
3171 | wpa_printf(MSG_DEBUG, " * bssid=" MACSTR, | |
3172 | MAC2STR(params->bssid)); | |
a862e4a3 JM |
3173 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid)) |
3174 | goto fail; | |
c2a04078 JM |
3175 | } |
3176 | if (params->freq) { | |
3177 | wpa_printf(MSG_DEBUG, " * freq=%d", params->freq); | |
a862e4a3 JM |
3178 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, params->freq)) |
3179 | goto fail; | |
c2a04078 JM |
3180 | } |
3181 | if (params->ssid) { | |
3182 | wpa_hexdump_ascii(MSG_DEBUG, " * SSID", | |
3183 | params->ssid, params->ssid_len); | |
a862e4a3 JM |
3184 | if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, |
3185 | params->ssid)) | |
3186 | goto fail; | |
c2a04078 JM |
3187 | } |
3188 | wpa_hexdump(MSG_DEBUG, " * IEs", params->ie, params->ie_len); | |
a862e4a3 JM |
3189 | if (params->ie && |
3190 | nla_put(msg, NL80211_ATTR_IE, params->ie_len, params->ie)) | |
3191 | goto fail; | |
ce16c489 JM |
3192 | if (params->auth_data) { |
3193 | wpa_hexdump(MSG_DEBUG, " * auth_data", params->auth_data, | |
3194 | params->auth_data_len); | |
3195 | if (nla_put(msg, NL80211_ATTR_SAE_DATA, params->auth_data_len, | |
3196 | params->auth_data)) | |
a862e4a3 | 3197 | goto fail; |
569fed90 | 3198 | } |
abd9fafa | 3199 | if (params->auth_alg & WPA_AUTH_ALG_OPEN) |
c2a04078 | 3200 | type = NL80211_AUTHTYPE_OPEN_SYSTEM; |
abd9fafa | 3201 | else if (params->auth_alg & WPA_AUTH_ALG_SHARED) |
c2a04078 | 3202 | type = NL80211_AUTHTYPE_SHARED_KEY; |
abd9fafa | 3203 | else if (params->auth_alg & WPA_AUTH_ALG_LEAP) |
c2a04078 | 3204 | type = NL80211_AUTHTYPE_NETWORK_EAP; |
abd9fafa | 3205 | else if (params->auth_alg & WPA_AUTH_ALG_FT) |
c2a04078 | 3206 | type = NL80211_AUTHTYPE_FT; |
569fed90 JM |
3207 | else if (params->auth_alg & WPA_AUTH_ALG_SAE) |
3208 | type = NL80211_AUTHTYPE_SAE; | |
d8f9342d JM |
3209 | else if (params->auth_alg & WPA_AUTH_ALG_FILS) |
3210 | type = NL80211_AUTHTYPE_FILS_SK; | |
c2a04078 | 3211 | else |
a862e4a3 | 3212 | goto fail; |
c2a04078 | 3213 | wpa_printf(MSG_DEBUG, " * Auth Type %d", type); |
a862e4a3 JM |
3214 | if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, type)) |
3215 | goto fail; | |
77339912 JM |
3216 | if (params->local_state_change) { |
3217 | wpa_printf(MSG_DEBUG, " * Local state change only"); | |
a862e4a3 JM |
3218 | if (nla_put_flag(msg, NL80211_ATTR_LOCAL_STATE_CHANGE)) |
3219 | goto fail; | |
77339912 | 3220 | } |
c2a04078 JM |
3221 | |
3222 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
3223 | msg = NULL; | |
3224 | if (ret) { | |
3b7ea880 BG |
3225 | wpa_dbg(drv->ctx, MSG_DEBUG, |
3226 | "nl80211: MLME command failed (auth): ret=%d (%s)", | |
3227 | ret, strerror(-ret)); | |
6d6f4bb8 | 3228 | count++; |
77339912 JM |
3229 | if (ret == -EALREADY && count == 1 && params->bssid && |
3230 | !params->local_state_change) { | |
6d6f4bb8 JM |
3231 | /* |
3232 | * mac80211 does not currently accept new | |
3233 | * authentication if we are already authenticated. As a | |
3234 | * workaround, force deauthentication and try again. | |
3235 | */ | |
3236 | wpa_printf(MSG_DEBUG, "nl80211: Retry authentication " | |
3237 | "after forced deauthentication"); | |
e8d70a73 | 3238 | drv->ignore_deauth_event = 1; |
6d6f4bb8 | 3239 | wpa_driver_nl80211_deauthenticate( |
5205c4f9 | 3240 | bss, params->bssid, |
6d6f4bb8 JM |
3241 | WLAN_REASON_PREV_AUTH_NOT_VALID); |
3242 | nlmsg_free(msg); | |
3243 | goto retry; | |
3244 | } | |
536fd62d JM |
3245 | |
3246 | if (ret == -ENOENT && params->freq && !is_retry) { | |
3247 | /* | |
3248 | * cfg80211 has likely expired the BSS entry even | |
3249 | * though it was previously available in our internal | |
3250 | * BSS table. To recover quickly, start a single | |
3251 | * channel scan on the specified channel. | |
3252 | */ | |
3253 | struct wpa_driver_scan_params scan; | |
3254 | int freqs[2]; | |
3255 | ||
3256 | os_memset(&scan, 0, sizeof(scan)); | |
3257 | scan.num_ssids = 1; | |
3258 | if (params->ssid) { | |
3259 | scan.ssids[0].ssid = params->ssid; | |
3260 | scan.ssids[0].ssid_len = params->ssid_len; | |
3261 | } | |
3262 | freqs[0] = params->freq; | |
3263 | freqs[1] = 0; | |
3264 | scan.freqs = freqs; | |
3265 | wpa_printf(MSG_DEBUG, "nl80211: Trigger single " | |
3266 | "channel scan to refresh cfg80211 BSS " | |
3267 | "entry"); | |
3268 | ret = wpa_driver_nl80211_scan(bss, &scan); | |
3269 | if (ret == 0) { | |
3270 | nl80211_copy_auth_params(drv, params); | |
3271 | drv->scan_for_auth = 1; | |
3272 | } | |
8c3ba078 JM |
3273 | } else if (is_retry) { |
3274 | /* | |
3275 | * Need to indicate this with an event since the return | |
3276 | * value from the retry is not delivered to core code. | |
3277 | */ | |
3278 | union wpa_event_data event; | |
3279 | wpa_printf(MSG_DEBUG, "nl80211: Authentication retry " | |
3280 | "failed"); | |
3281 | os_memset(&event, 0, sizeof(event)); | |
3282 | os_memcpy(event.timeout_event.addr, drv->auth_bssid_, | |
3283 | ETH_ALEN); | |
3284 | wpa_supplicant_event(drv->ctx, EVENT_AUTH_TIMED_OUT, | |
3285 | &event); | |
536fd62d | 3286 | } |
a862e4a3 JM |
3287 | } else { |
3288 | wpa_printf(MSG_DEBUG, | |
3289 | "nl80211: Authentication request send successfully"); | |
c2a04078 | 3290 | } |
c2a04078 | 3291 | |
a862e4a3 | 3292 | fail: |
c2a04078 JM |
3293 | nlmsg_free(msg); |
3294 | return ret; | |
3295 | } | |
3296 | ||
3297 | ||
f3407c66 | 3298 | int wpa_driver_nl80211_authenticate_retry(struct wpa_driver_nl80211_data *drv) |
536fd62d JM |
3299 | { |
3300 | struct wpa_driver_auth_params params; | |
834ee56f | 3301 | struct i802_bss *bss = drv->first_bss; |
536fd62d JM |
3302 | int i; |
3303 | ||
3304 | wpa_printf(MSG_DEBUG, "nl80211: Try to authenticate again"); | |
3305 | ||
3306 | os_memset(¶ms, 0, sizeof(params)); | |
3307 | params.freq = drv->auth_freq; | |
3308 | params.auth_alg = drv->auth_alg; | |
3309 | params.wep_tx_keyidx = drv->auth_wep_tx_keyidx; | |
3310 | params.local_state_change = drv->auth_local_state_change; | |
3311 | params.p2p = drv->auth_p2p; | |
3312 | ||
3313 | if (!is_zero_ether_addr(drv->auth_bssid_)) | |
3314 | params.bssid = drv->auth_bssid_; | |
3315 | ||
3316 | if (drv->auth_ssid_len) { | |
3317 | params.ssid = drv->auth_ssid; | |
3318 | params.ssid_len = drv->auth_ssid_len; | |
3319 | } | |
3320 | ||
3321 | params.ie = drv->auth_ie; | |
3322 | params.ie_len = drv->auth_ie_len; | |
3323 | ||
3324 | for (i = 0; i < 4; i++) { | |
3325 | if (drv->auth_wep_key_len[i]) { | |
3326 | params.wep_key[i] = drv->auth_wep_key[i]; | |
3327 | params.wep_key_len[i] = drv->auth_wep_key_len[i]; | |
3328 | } | |
3329 | } | |
3330 | ||
3331 | drv->retry_auth = 1; | |
3332 | return wpa_driver_nl80211_authenticate(bss, ¶ms); | |
3333 | } | |
3334 | ||
3335 | ||
a11241fa JB |
3336 | static int wpa_driver_nl80211_send_frame(struct i802_bss *bss, |
3337 | const void *data, size_t len, | |
55231068 JM |
3338 | int encrypt, int noack, |
3339 | unsigned int freq, int no_cck, | |
2d3943ce AO |
3340 | int offchanok, unsigned int wait_time, |
3341 | const u16 *csa_offs, | |
3342 | size_t csa_offs_len) | |
a11241fa JB |
3343 | { |
3344 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
3345 | u64 cookie; | |
41cc50d1 | 3346 | int res; |
a11241fa | 3347 | |
c7caac56 JM |
3348 | if (freq == 0 && drv->nlmode == NL80211_IFTYPE_ADHOC) { |
3349 | freq = nl80211_get_assoc_freq(drv); | |
3350 | wpa_printf(MSG_DEBUG, | |
3351 | "nl80211: send_frame - Use assoc_freq=%u for IBSS", | |
3352 | freq); | |
3353 | } | |
af964484 JM |
3354 | if (freq == 0) { |
3355 | wpa_printf(MSG_DEBUG, "nl80211: send_frame - Use bss->freq=%u", | |
3356 | bss->freq); | |
55231068 | 3357 | freq = bss->freq; |
af964484 | 3358 | } |
55231068 | 3359 | |
739faee2 | 3360 | if (drv->use_monitor) { |
981cf85a | 3361 | wpa_printf(MSG_DEBUG, "nl80211: send_frame(freq=%u bss->freq=%u) -> send_monitor", |
739faee2 | 3362 | freq, bss->freq); |
981cf85a | 3363 | return nl80211_send_monitor(drv, data, len, encrypt, noack); |
739faee2 | 3364 | } |
a11241fa | 3365 | |
739faee2 | 3366 | wpa_printf(MSG_DEBUG, "nl80211: send_frame -> send_frame_cmd"); |
41cc50d1 | 3367 | res = nl80211_send_frame_cmd(bss, freq, wait_time, data, len, |
2d3943ce AO |
3368 | &cookie, no_cck, noack, offchanok, |
3369 | csa_offs, csa_offs_len); | |
41cc50d1 JM |
3370 | if (res == 0 && !noack) { |
3371 | const struct ieee80211_mgmt *mgmt; | |
3372 | u16 fc; | |
3373 | ||
3374 | mgmt = (const struct ieee80211_mgmt *) data; | |
3375 | fc = le_to_host16(mgmt->frame_control); | |
3376 | if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && | |
3377 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_ACTION) { | |
3378 | wpa_printf(MSG_MSGDUMP, | |
3379 | "nl80211: Update send_action_cookie from 0x%llx to 0x%llx", | |
3380 | (long long unsigned int) | |
3381 | drv->send_action_cookie, | |
3382 | (long long unsigned int) cookie); | |
3383 | drv->send_action_cookie = cookie; | |
3384 | } | |
3385 | } | |
3386 | ||
3387 | return res; | |
a11241fa JB |
3388 | } |
3389 | ||
3390 | ||
9ebce9c5 JM |
3391 | static int wpa_driver_nl80211_send_mlme(struct i802_bss *bss, const u8 *data, |
3392 | size_t data_len, int noack, | |
3393 | unsigned int freq, int no_cck, | |
3394 | int offchanok, | |
2d3943ce AO |
3395 | unsigned int wait_time, |
3396 | const u16 *csa_offs, | |
3397 | size_t csa_offs_len) | |
2c2010ac | 3398 | { |
a2e40bb6 | 3399 | struct wpa_driver_nl80211_data *drv = bss->drv; |
2c2010ac | 3400 | struct ieee80211_mgmt *mgmt; |
7a47d567 | 3401 | int encrypt = 1; |
2c2010ac JM |
3402 | u16 fc; |
3403 | ||
3404 | mgmt = (struct ieee80211_mgmt *) data; | |
3405 | fc = le_to_host16(mgmt->frame_control); | |
f95a4524 PF |
3406 | wpa_printf(MSG_DEBUG, "nl80211: send_mlme - da= " MACSTR |
3407 | " noack=%d freq=%u no_cck=%d offchanok=%d wait_time=%u fc=0x%x (%s) nlmode=%d", | |
3408 | MAC2STR(mgmt->da), noack, freq, no_cck, offchanok, wait_time, | |
3409 | fc, fc2str(fc), drv->nlmode); | |
2c2010ac | 3410 | |
8e12685c AS |
3411 | if ((is_sta_interface(drv->nlmode) || |
3412 | drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) && | |
5582a5d1 JB |
3413 | WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && |
3414 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_PROBE_RESP) { | |
3415 | /* | |
3416 | * The use of last_mgmt_freq is a bit of a hack, | |
3417 | * but it works due to the single-threaded nature | |
3418 | * of wpa_supplicant. | |
3419 | */ | |
af964484 JM |
3420 | if (freq == 0) { |
3421 | wpa_printf(MSG_DEBUG, "nl80211: Use last_mgmt_freq=%d", | |
3422 | drv->last_mgmt_freq); | |
55231068 | 3423 | freq = drv->last_mgmt_freq; |
af964484 | 3424 | } |
55231068 | 3425 | return nl80211_send_frame_cmd(bss, freq, 0, |
88df0ef7 | 3426 | data, data_len, NULL, 1, noack, |
2d3943ce | 3427 | 1, csa_offs, csa_offs_len); |
5582a5d1 JB |
3428 | } |
3429 | ||
61cbe2ff | 3430 | if (drv->device_ap_sme && is_ap_interface(drv->nlmode)) { |
af964484 JM |
3431 | if (freq == 0) { |
3432 | wpa_printf(MSG_DEBUG, "nl80211: Use bss->freq=%d", | |
3433 | bss->freq); | |
55231068 | 3434 | freq = bss->freq; |
af964484 | 3435 | } |
b5671498 JM |
3436 | return nl80211_send_frame_cmd(bss, freq, |
3437 | (int) freq == bss->freq ? 0 : | |
3438 | wait_time, | |
d8d6b32e DG |
3439 | data, data_len, |
3440 | &drv->send_action_cookie, | |
2d3943ce AO |
3441 | no_cck, noack, offchanok, |
3442 | csa_offs, csa_offs_len); | |
86957e62 JM |
3443 | } |
3444 | ||
2c2010ac JM |
3445 | if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && |
3446 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_AUTH) { | |
3447 | /* | |
3448 | * Only one of the authentication frame types is encrypted. | |
3449 | * In order for static WEP encryption to work properly (i.e., | |
3450 | * to not encrypt the frame), we need to tell mac80211 about | |
3451 | * the frames that must not be encrypted. | |
3452 | */ | |
3453 | u16 auth_alg = le_to_host16(mgmt->u.auth.auth_alg); | |
3454 | u16 auth_trans = le_to_host16(mgmt->u.auth.auth_transaction); | |
7a47d567 JB |
3455 | if (auth_alg != WLAN_AUTH_SHARED_KEY || auth_trans != 3) |
3456 | encrypt = 0; | |
2c2010ac JM |
3457 | } |
3458 | ||
739faee2 | 3459 | wpa_printf(MSG_DEBUG, "nl80211: send_mlme -> send_frame"); |
a11241fa | 3460 | return wpa_driver_nl80211_send_frame(bss, data, data_len, encrypt, |
55231068 | 3461 | noack, freq, no_cck, offchanok, |
2d3943ce AO |
3462 | wait_time, csa_offs, |
3463 | csa_offs_len); | |
55231068 JM |
3464 | } |
3465 | ||
3466 | ||
cae87abd JM |
3467 | static int nl80211_put_basic_rates(struct nl_msg *msg, const int *basic_rates) |
3468 | { | |
3469 | u8 rates[NL80211_MAX_SUPP_RATES]; | |
3470 | u8 rates_len = 0; | |
3471 | int i; | |
3472 | ||
3473 | if (!basic_rates) | |
3474 | return 0; | |
3475 | ||
3476 | for (i = 0; i < NL80211_MAX_SUPP_RATES && basic_rates[i] >= 0; i++) | |
3477 | rates[rates_len++] = basic_rates[i] / 5; | |
3478 | ||
3479 | return nla_put(msg, NL80211_ATTR_BSS_BASIC_RATES, rates_len, rates); | |
3480 | } | |
3481 | ||
3482 | ||
31357268 | 3483 | static int nl80211_set_bss(struct i802_bss *bss, int cts, int preamble, |
e5693c47 | 3484 | int slot, int ht_opmode, int ap_isolate, |
cae87abd | 3485 | const int *basic_rates) |
31357268 JM |
3486 | { |
3487 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
3488 | struct nl_msg *msg; | |
3489 | ||
13f83980 | 3490 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_BSS)) || |
a862e4a3 JM |
3491 | (cts >= 0 && |
3492 | nla_put_u8(msg, NL80211_ATTR_BSS_CTS_PROT, cts)) || | |
3493 | (preamble >= 0 && | |
3494 | nla_put_u8(msg, NL80211_ATTR_BSS_SHORT_PREAMBLE, preamble)) || | |
3495 | (slot >= 0 && | |
3496 | nla_put_u8(msg, NL80211_ATTR_BSS_SHORT_SLOT_TIME, slot)) || | |
3497 | (ht_opmode >= 0 && | |
3498 | nla_put_u16(msg, NL80211_ATTR_BSS_HT_OPMODE, ht_opmode)) || | |
3499 | (ap_isolate >= 0 && | |
cae87abd JM |
3500 | nla_put_u8(msg, NL80211_ATTR_AP_ISOLATE, ap_isolate)) || |
3501 | nl80211_put_basic_rates(msg, basic_rates)) { | |
3502 | nlmsg_free(msg); | |
3503 | return -ENOBUFS; | |
e5693c47 JM |
3504 | } |
3505 | ||
31357268 | 3506 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
31357268 JM |
3507 | } |
3508 | ||
3509 | ||
3c4ca363 VN |
3510 | static int wpa_driver_nl80211_set_acl(void *priv, |
3511 | struct hostapd_acl_params *params) | |
3512 | { | |
3513 | struct i802_bss *bss = priv; | |
3514 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
3515 | struct nl_msg *msg; | |
f429ec44 | 3516 | struct nl_msg *acl; |
3c4ca363 | 3517 | unsigned int i; |
a862e4a3 | 3518 | int ret; |
3c4ca363 VN |
3519 | |
3520 | if (!(drv->capa.max_acl_mac_addrs)) | |
3521 | return -ENOTSUP; | |
3522 | ||
3523 | if (params->num_mac_acl > drv->capa.max_acl_mac_addrs) | |
3524 | return -ENOTSUP; | |
3525 | ||
3c4ca363 VN |
3526 | wpa_printf(MSG_DEBUG, "nl80211: Set %s ACL (num_mac_acl=%u)", |
3527 | params->acl_policy ? "Accept" : "Deny", params->num_mac_acl); | |
3528 | ||
f429ec44 JM |
3529 | acl = nlmsg_alloc(); |
3530 | if (!acl) | |
3531 | return -ENOMEM; | |
3532 | for (i = 0; i < params->num_mac_acl; i++) { | |
3533 | if (nla_put(acl, i + 1, ETH_ALEN, params->mac_acl[i].addr)) { | |
3534 | nlmsg_free(acl); | |
3535 | return -ENOMEM; | |
3536 | } | |
3537 | } | |
3538 | ||
9725b784 | 3539 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_MAC_ACL)) || |
a862e4a3 JM |
3540 | nla_put_u32(msg, NL80211_ATTR_ACL_POLICY, params->acl_policy ? |
3541 | NL80211_ACL_POLICY_DENY_UNLESS_LISTED : | |
3542 | NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED) || | |
f429ec44 | 3543 | nla_put_nested(msg, NL80211_ATTR_MAC_ADDRS, acl)) { |
a862e4a3 | 3544 | nlmsg_free(msg); |
f429ec44 | 3545 | nlmsg_free(acl); |
a862e4a3 JM |
3546 | return -ENOMEM; |
3547 | } | |
f429ec44 | 3548 | nlmsg_free(acl); |
3c4ca363 VN |
3549 | |
3550 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
3c4ca363 VN |
3551 | if (ret) { |
3552 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set MAC ACL: %d (%s)", | |
3553 | ret, strerror(-ret)); | |
3554 | } | |
3555 | ||
3c4ca363 VN |
3556 | return ret; |
3557 | } | |
3558 | ||
3559 | ||
85e1fad8 JM |
3560 | static int nl80211_put_beacon_int(struct nl_msg *msg, int beacon_int) |
3561 | { | |
3562 | if (beacon_int > 0) { | |
3563 | wpa_printf(MSG_DEBUG, " * beacon_int=%d", beacon_int); | |
3564 | return nla_put_u32(msg, NL80211_ATTR_BEACON_INTERVAL, | |
3565 | beacon_int); | |
3566 | } | |
3567 | ||
3568 | return 0; | |
3569 | } | |
3570 | ||
3571 | ||
4ac2ea57 MH |
3572 | static int nl80211_put_dtim_period(struct nl_msg *msg, int dtim_period) |
3573 | { | |
3574 | if (dtim_period > 0) { | |
3575 | wpa_printf(MSG_DEBUG, " * dtim_period=%d", dtim_period); | |
3576 | return nla_put_u32(msg, NL80211_ATTR_DTIM_PERIOD, dtim_period); | |
3577 | } | |
3578 | ||
3579 | return 0; | |
3580 | } | |
3581 | ||
3582 | ||
052b8d38 MH |
3583 | #ifdef CONFIG_MESH |
3584 | static int nl80211_set_mesh_config(void *priv, | |
3585 | struct wpa_driver_mesh_bss_params *params) | |
3586 | { | |
3587 | struct i802_bss *bss = priv; | |
3588 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
3589 | struct nl_msg *msg; | |
3590 | int ret; | |
3591 | ||
3592 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_MESH_CONFIG); | |
3593 | if (!msg) | |
3594 | return -1; | |
3595 | ||
3596 | ret = nl80211_put_mesh_config(msg, params); | |
3597 | if (ret < 0) { | |
3598 | nlmsg_free(msg); | |
3599 | return ret; | |
3600 | } | |
3601 | ||
3602 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
3603 | if (ret) { | |
3604 | wpa_printf(MSG_ERROR, | |
3605 | "nl80211: Mesh config set failed: %d (%s)", | |
3606 | ret, strerror(-ret)); | |
3607 | return ret; | |
3608 | } | |
3609 | return 0; | |
3610 | } | |
3611 | #endif /* CONFIG_MESH */ | |
3612 | ||
3613 | ||
d4f3003c PK |
3614 | static int nl80211_put_beacon_rate(struct nl_msg *msg, const u64 flags, |
3615 | struct wpa_driver_ap_params *params) | |
3616 | { | |
3617 | struct nlattr *bands, *band; | |
3618 | struct nl80211_txrate_vht vht_rate; | |
3619 | ||
3620 | if (!params->freq || | |
3621 | (params->beacon_rate == 0 && | |
3622 | params->rate_type == BEACON_RATE_LEGACY)) | |
3623 | return 0; | |
3624 | ||
3625 | bands = nla_nest_start(msg, NL80211_ATTR_TX_RATES); | |
3626 | if (!bands) | |
3627 | return -1; | |
3628 | ||
3629 | switch (params->freq->mode) { | |
3630 | case HOSTAPD_MODE_IEEE80211B: | |
3631 | case HOSTAPD_MODE_IEEE80211G: | |
3632 | band = nla_nest_start(msg, NL80211_BAND_2GHZ); | |
3633 | break; | |
3634 | case HOSTAPD_MODE_IEEE80211A: | |
3635 | band = nla_nest_start(msg, NL80211_BAND_5GHZ); | |
3636 | break; | |
3637 | case HOSTAPD_MODE_IEEE80211AD: | |
3638 | band = nla_nest_start(msg, NL80211_BAND_60GHZ); | |
3639 | break; | |
3640 | default: | |
3641 | return 0; | |
3642 | } | |
3643 | ||
3644 | if (!band) | |
3645 | return -1; | |
3646 | ||
3647 | os_memset(&vht_rate, 0, sizeof(vht_rate)); | |
3648 | ||
3649 | switch (params->rate_type) { | |
3650 | case BEACON_RATE_LEGACY: | |
3651 | if (!(flags & WPA_DRIVER_FLAGS_BEACON_RATE_LEGACY)) { | |
3652 | wpa_printf(MSG_INFO, | |
3653 | "nl80211: Driver does not support setting Beacon frame rate (legacy)"); | |
3654 | return -1; | |
3655 | } | |
3656 | ||
3657 | if (nla_put_u8(msg, NL80211_TXRATE_LEGACY, | |
3658 | (u8) params->beacon_rate / 5) || | |
3659 | nla_put(msg, NL80211_TXRATE_HT, 0, NULL) || | |
3660 | (params->freq->vht_enabled && | |
3661 | nla_put(msg, NL80211_TXRATE_VHT, sizeof(vht_rate), | |
3662 | &vht_rate))) | |
3663 | return -1; | |
3664 | ||
3665 | wpa_printf(MSG_DEBUG, " * beacon_rate = legacy:%u (* 100 kbps)", | |
3666 | params->beacon_rate); | |
3667 | break; | |
3668 | case BEACON_RATE_HT: | |
3669 | if (!(flags & WPA_DRIVER_FLAGS_BEACON_RATE_HT)) { | |
3670 | wpa_printf(MSG_INFO, | |
3671 | "nl80211: Driver does not support setting Beacon frame rate (HT)"); | |
3672 | return -1; | |
3673 | } | |
3674 | if (nla_put(msg, NL80211_TXRATE_LEGACY, 0, NULL) || | |
3675 | nla_put_u8(msg, NL80211_TXRATE_HT, params->beacon_rate) || | |
3676 | (params->freq->vht_enabled && | |
3677 | nla_put(msg, NL80211_TXRATE_VHT, sizeof(vht_rate), | |
3678 | &vht_rate))) | |
3679 | return -1; | |
3680 | wpa_printf(MSG_DEBUG, " * beacon_rate = HT-MCS %u", | |
3681 | params->beacon_rate); | |
3682 | break; | |
3683 | case BEACON_RATE_VHT: | |
3684 | if (!(flags & WPA_DRIVER_FLAGS_BEACON_RATE_VHT)) { | |
3685 | wpa_printf(MSG_INFO, | |
3686 | "nl80211: Driver does not support setting Beacon frame rate (VHT)"); | |
3687 | return -1; | |
3688 | } | |
3689 | vht_rate.mcs[0] = BIT(params->beacon_rate); | |
3690 | if (nla_put(msg, NL80211_TXRATE_LEGACY, 0, NULL)) | |
3691 | return -1; | |
3692 | if (nla_put(msg, NL80211_TXRATE_HT, 0, NULL)) | |
3693 | return -1; | |
3694 | if (nla_put(msg, NL80211_TXRATE_VHT, sizeof(vht_rate), | |
3695 | &vht_rate)) | |
3696 | return -1; | |
3697 | wpa_printf(MSG_DEBUG, " * beacon_rate = VHT-MCS %u", | |
3698 | params->beacon_rate); | |
3699 | break; | |
3700 | } | |
3701 | ||
3702 | nla_nest_end(msg, band); | |
3703 | nla_nest_end(msg, bands); | |
3704 | ||
3705 | return 0; | |
3706 | } | |
3707 | ||
3708 | ||
34f7c699 MB |
3709 | static int nl80211_set_multicast_to_unicast(struct i802_bss *bss, |
3710 | int multicast_to_unicast) | |
3711 | { | |
3712 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
3713 | struct nl_msg *msg; | |
3714 | int ret; | |
3715 | ||
3716 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_MULTICAST_TO_UNICAST); | |
3717 | if (!msg || | |
3718 | (multicast_to_unicast && | |
3719 | nla_put_flag(msg, NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED))) { | |
3720 | wpa_printf(MSG_ERROR, | |
3721 | "nl80211: Failed to build NL80211_CMD_SET_MULTICAST_TO_UNICAST msg for %s", | |
3722 | bss->ifname); | |
3723 | nlmsg_free(msg); | |
3724 | return -ENOBUFS; | |
3725 | } | |
3726 | ||
3727 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
3728 | ||
3729 | switch (ret) { | |
3730 | case 0: | |
3731 | wpa_printf(MSG_DEBUG, | |
3732 | "nl80211: multicast to unicast %s on interface %s", | |
3733 | multicast_to_unicast ? "enabled" : "disabled", | |
3734 | bss->ifname); | |
3735 | break; | |
3736 | case -EOPNOTSUPP: | |
3737 | if (!multicast_to_unicast) | |
3738 | break; | |
3739 | wpa_printf(MSG_INFO, | |
3740 | "nl80211: multicast to unicast not supported on interface %s", | |
3741 | bss->ifname); | |
3742 | break; | |
3743 | default: | |
3744 | wpa_printf(MSG_ERROR, | |
3745 | "nl80211: %s multicast to unicast failed with %d (%s) on interface %s", | |
3746 | multicast_to_unicast ? "enabling" : "disabling", | |
3747 | ret, strerror(-ret), bss->ifname); | |
3748 | break; | |
3749 | } | |
3750 | ||
3751 | return ret; | |
3752 | } | |
3753 | ||
3754 | ||
19c3b566 JM |
3755 | static int wpa_driver_nl80211_set_ap(void *priv, |
3756 | struct wpa_driver_ap_params *params) | |
d2440ba0 | 3757 | { |
a2e40bb6 FF |
3758 | struct i802_bss *bss = priv; |
3759 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
d2440ba0 JM |
3760 | struct nl_msg *msg; |
3761 | u8 cmd = NL80211_CMD_NEW_BEACON; | |
3762 | int ret; | |
b4fd6fab | 3763 | int beacon_set; |
b11d1d64 | 3764 | int num_suites; |
da1080d7 | 3765 | int smps_mode; |
de4ed4a8 | 3766 | u32 suites[10], suite; |
b11d1d64 | 3767 | u32 ver; |
052b8d38 MH |
3768 | #ifdef CONFIG_MESH |
3769 | struct wpa_driver_mesh_bss_params mesh_params; | |
3770 | #endif /* CONFIG_MESH */ | |
b4fd6fab | 3771 | |
f33c8606 | 3772 | beacon_set = params->reenable ? 0 : bss->beacon_set; |
d2440ba0 | 3773 | |
d2440ba0 | 3774 | wpa_printf(MSG_DEBUG, "nl80211: Set beacon (beacon_set=%d)", |
b4fd6fab JM |
3775 | beacon_set); |
3776 | if (beacon_set) | |
d2440ba0 JM |
3777 | cmd = NL80211_CMD_SET_BEACON; |
3778 | ||
b92e08fc JM |
3779 | wpa_hexdump(MSG_DEBUG, "nl80211: Beacon head", |
3780 | params->head, params->head_len); | |
b92e08fc JM |
3781 | wpa_hexdump(MSG_DEBUG, "nl80211: Beacon tail", |
3782 | params->tail, params->tail_len); | |
13f83980 | 3783 | wpa_printf(MSG_DEBUG, "nl80211: ifindex=%d", bss->ifindex); |
b92e08fc | 3784 | wpa_printf(MSG_DEBUG, "nl80211: beacon_int=%d", params->beacon_int); |
d4f3003c PK |
3785 | wpa_printf(MSG_DEBUG, "nl80211: beacon_rate=%u", params->beacon_rate); |
3786 | wpa_printf(MSG_DEBUG, "nl80211: rate_type=%d", params->rate_type); | |
b92e08fc | 3787 | wpa_printf(MSG_DEBUG, "nl80211: dtim_period=%d", params->dtim_period); |
b92e08fc JM |
3788 | wpa_hexdump_ascii(MSG_DEBUG, "nl80211: ssid", |
3789 | params->ssid, params->ssid_len); | |
13f83980 | 3790 | if (!(msg = nl80211_bss_msg(bss, 0, cmd)) || |
a862e4a3 JM |
3791 | nla_put(msg, NL80211_ATTR_BEACON_HEAD, params->head_len, |
3792 | params->head) || | |
3793 | nla_put(msg, NL80211_ATTR_BEACON_TAIL, params->tail_len, | |
3794 | params->tail) || | |
85e1fad8 | 3795 | nl80211_put_beacon_int(msg, params->beacon_int) || |
d4f3003c | 3796 | nl80211_put_beacon_rate(msg, drv->capa.flags, params) || |
4ac2ea57 | 3797 | nl80211_put_dtim_period(msg, params->dtim_period) || |
a862e4a3 JM |
3798 | nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid)) |
3799 | goto fail; | |
b92e08fc JM |
3800 | if (params->proberesp && params->proberesp_len) { |
3801 | wpa_hexdump(MSG_DEBUG, "nl80211: proberesp (offload)", | |
3802 | params->proberesp, params->proberesp_len); | |
a862e4a3 JM |
3803 | if (nla_put(msg, NL80211_ATTR_PROBE_RESP, params->proberesp_len, |
3804 | params->proberesp)) | |
3805 | goto fail; | |
b92e08fc | 3806 | } |
97a7a0b5 JM |
3807 | switch (params->hide_ssid) { |
3808 | case NO_SSID_HIDING: | |
b92e08fc | 3809 | wpa_printf(MSG_DEBUG, "nl80211: hidden SSID not in use"); |
a862e4a3 JM |
3810 | if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID, |
3811 | NL80211_HIDDEN_SSID_NOT_IN_USE)) | |
3812 | goto fail; | |
97a7a0b5 JM |
3813 | break; |
3814 | case HIDDEN_SSID_ZERO_LEN: | |
b92e08fc | 3815 | wpa_printf(MSG_DEBUG, "nl80211: hidden SSID zero len"); |
a862e4a3 JM |
3816 | if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID, |
3817 | NL80211_HIDDEN_SSID_ZERO_LEN)) | |
3818 | goto fail; | |
97a7a0b5 JM |
3819 | break; |
3820 | case HIDDEN_SSID_ZERO_CONTENTS: | |
b92e08fc | 3821 | wpa_printf(MSG_DEBUG, "nl80211: hidden SSID zero contents"); |
a862e4a3 JM |
3822 | if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID, |
3823 | NL80211_HIDDEN_SSID_ZERO_CONTENTS)) | |
3824 | goto fail; | |
97a7a0b5 JM |
3825 | break; |
3826 | } | |
b92e08fc | 3827 | wpa_printf(MSG_DEBUG, "nl80211: privacy=%d", params->privacy); |
a862e4a3 JM |
3828 | if (params->privacy && |
3829 | nla_put_flag(msg, NL80211_ATTR_PRIVACY)) | |
3830 | goto fail; | |
b92e08fc | 3831 | wpa_printf(MSG_DEBUG, "nl80211: auth_algs=0x%x", params->auth_algs); |
b11d1d64 JM |
3832 | if ((params->auth_algs & (WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED)) == |
3833 | (WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED)) { | |
3834 | /* Leave out the attribute */ | |
a862e4a3 JM |
3835 | } else if (params->auth_algs & WPA_AUTH_ALG_SHARED) { |
3836 | if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, | |
3837 | NL80211_AUTHTYPE_SHARED_KEY)) | |
3838 | goto fail; | |
3839 | } else { | |
3840 | if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, | |
3841 | NL80211_AUTHTYPE_OPEN_SYSTEM)) | |
3842 | goto fail; | |
3843 | } | |
b11d1d64 | 3844 | |
b92e08fc | 3845 | wpa_printf(MSG_DEBUG, "nl80211: wpa_version=0x%x", params->wpa_version); |
b11d1d64 JM |
3846 | ver = 0; |
3847 | if (params->wpa_version & WPA_PROTO_WPA) | |
3848 | ver |= NL80211_WPA_VERSION_1; | |
3849 | if (params->wpa_version & WPA_PROTO_RSN) | |
3850 | ver |= NL80211_WPA_VERSION_2; | |
a862e4a3 JM |
3851 | if (ver && |
3852 | nla_put_u32(msg, NL80211_ATTR_WPA_VERSIONS, ver)) | |
3853 | goto fail; | |
b11d1d64 | 3854 | |
b92e08fc JM |
3855 | wpa_printf(MSG_DEBUG, "nl80211: key_mgmt_suites=0x%x", |
3856 | params->key_mgmt_suites); | |
b11d1d64 JM |
3857 | num_suites = 0; |
3858 | if (params->key_mgmt_suites & WPA_KEY_MGMT_IEEE8021X) | |
3859 | suites[num_suites++] = WLAN_AKM_SUITE_8021X; | |
3860 | if (params->key_mgmt_suites & WPA_KEY_MGMT_PSK) | |
3861 | suites[num_suites++] = WLAN_AKM_SUITE_PSK; | |
a862e4a3 JM |
3862 | if (num_suites && |
3863 | nla_put(msg, NL80211_ATTR_AKM_SUITES, num_suites * sizeof(u32), | |
3864 | suites)) | |
3865 | goto fail; | |
b11d1d64 | 3866 | |
533fe09b | 3867 | if (params->key_mgmt_suites & WPA_KEY_MGMT_IEEE8021X_NO_WPA && |
e3429c0b JB |
3868 | (!params->pairwise_ciphers || |
3869 | params->pairwise_ciphers & (WPA_CIPHER_WEP104 | WPA_CIPHER_WEP40)) && | |
3870 | (nla_put_u16(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE, ETH_P_PAE) || | |
3871 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT))) | |
a862e4a3 | 3872 | goto fail; |
9f12614b | 3873 | |
b92e08fc JM |
3874 | wpa_printf(MSG_DEBUG, "nl80211: pairwise_ciphers=0x%x", |
3875 | params->pairwise_ciphers); | |
de4ed4a8 JM |
3876 | num_suites = wpa_cipher_to_cipher_suites(params->pairwise_ciphers, |
3877 | suites, ARRAY_SIZE(suites)); | |
a862e4a3 JM |
3878 | if (num_suites && |
3879 | nla_put(msg, NL80211_ATTR_CIPHER_SUITES_PAIRWISE, | |
3880 | num_suites * sizeof(u32), suites)) | |
3881 | goto fail; | |
b11d1d64 | 3882 | |
b92e08fc JM |
3883 | wpa_printf(MSG_DEBUG, "nl80211: group_cipher=0x%x", |
3884 | params->group_cipher); | |
de4ed4a8 | 3885 | suite = wpa_cipher_to_cipher_suite(params->group_cipher); |
a862e4a3 JM |
3886 | if (suite && |
3887 | nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, suite)) | |
3888 | goto fail; | |
d2440ba0 | 3889 | |
ee298f1b JM |
3890 | if (params->ht_opmode != -1) { |
3891 | switch (params->smps_mode) { | |
3892 | case HT_CAP_INFO_SMPS_DYNAMIC: | |
3893 | wpa_printf(MSG_DEBUG, "nl80211: SMPS mode - dynamic"); | |
3894 | smps_mode = NL80211_SMPS_DYNAMIC; | |
3895 | break; | |
3896 | case HT_CAP_INFO_SMPS_STATIC: | |
3897 | wpa_printf(MSG_DEBUG, "nl80211: SMPS mode - static"); | |
3898 | smps_mode = NL80211_SMPS_STATIC; | |
3899 | break; | |
3900 | default: | |
3901 | /* invalid - fallback to smps off */ | |
3902 | case HT_CAP_INFO_SMPS_DISABLED: | |
3903 | wpa_printf(MSG_DEBUG, "nl80211: SMPS mode - off"); | |
3904 | smps_mode = NL80211_SMPS_OFF; | |
3905 | break; | |
3906 | } | |
3907 | if (nla_put_u32(msg, NL80211_ATTR_SMPS_MODE, smps_mode)) | |
3908 | goto fail; | |
da1080d7 | 3909 | } |
da1080d7 | 3910 | |
fb91db56 | 3911 | if (params->beacon_ies) { |
b92e08fc JM |
3912 | wpa_hexdump_buf(MSG_DEBUG, "nl80211: beacon_ies", |
3913 | params->beacon_ies); | |
a862e4a3 JM |
3914 | if (nla_put(msg, NL80211_ATTR_IE, |
3915 | wpabuf_len(params->beacon_ies), | |
3916 | wpabuf_head(params->beacon_ies))) | |
3917 | goto fail; | |
fb91db56 JM |
3918 | } |
3919 | if (params->proberesp_ies) { | |
b92e08fc JM |
3920 | wpa_hexdump_buf(MSG_DEBUG, "nl80211: proberesp_ies", |
3921 | params->proberesp_ies); | |
a862e4a3 JM |
3922 | if (nla_put(msg, NL80211_ATTR_IE_PROBE_RESP, |
3923 | wpabuf_len(params->proberesp_ies), | |
3924 | wpabuf_head(params->proberesp_ies))) | |
3925 | goto fail; | |
fb91db56 JM |
3926 | } |
3927 | if (params->assocresp_ies) { | |
b92e08fc JM |
3928 | wpa_hexdump_buf(MSG_DEBUG, "nl80211: assocresp_ies", |
3929 | params->assocresp_ies); | |
a862e4a3 JM |
3930 | if (nla_put(msg, NL80211_ATTR_IE_ASSOC_RESP, |
3931 | wpabuf_len(params->assocresp_ies), | |
3932 | wpabuf_head(params->assocresp_ies))) | |
3933 | goto fail; | |
fb91db56 JM |
3934 | } |
3935 | ||
a0133ee1 | 3936 | if (drv->capa.flags & WPA_DRIVER_FLAGS_INACTIVITY_TIMER) { |
b92e08fc JM |
3937 | wpa_printf(MSG_DEBUG, "nl80211: ap_max_inactivity=%d", |
3938 | params->ap_max_inactivity); | |
a862e4a3 JM |
3939 | if (nla_put_u16(msg, NL80211_ATTR_INACTIVITY_TIMEOUT, |
3940 | params->ap_max_inactivity)) | |
3941 | goto fail; | |
a0133ee1 VT |
3942 | } |
3943 | ||
abb8d08b EP |
3944 | #ifdef CONFIG_P2P |
3945 | if (params->p2p_go_ctwindow > 0) { | |
3946 | if (drv->p2p_go_ctwindow_supported) { | |
3947 | wpa_printf(MSG_DEBUG, "nl80211: P2P GO ctwindow=%d", | |
3948 | params->p2p_go_ctwindow); | |
3949 | if (nla_put_u8(msg, NL80211_ATTR_P2P_CTWINDOW, | |
3950 | params->p2p_go_ctwindow)) | |
3951 | goto fail; | |
3952 | } else { | |
3953 | wpa_printf(MSG_INFO, | |
3954 | "nl80211: Driver does not support CTWindow configuration - ignore this parameter"); | |
3955 | } | |
3956 | } | |
3957 | #endif /* CONFIG_P2P */ | |
3958 | ||
86b5c400 LD |
3959 | if (params->pbss) { |
3960 | wpa_printf(MSG_DEBUG, "nl80211: PBSS"); | |
3961 | if (nla_put_flag(msg, NL80211_ATTR_PBSS)) | |
3962 | goto fail; | |
3963 | } | |
3964 | ||
d2440ba0 JM |
3965 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
3966 | if (ret) { | |
3967 | wpa_printf(MSG_DEBUG, "nl80211: Beacon set failed: %d (%s)", | |
3968 | ret, strerror(-ret)); | |
b4fd6fab | 3969 | } else { |
b4fd6fab | 3970 | bss->beacon_set = 1; |
31357268 | 3971 | nl80211_set_bss(bss, params->cts_protect, params->preamble, |
d03e8d11 | 3972 | params->short_slot_time, params->ht_opmode, |
e5693c47 | 3973 | params->isolate, params->basic_rates); |
34f7c699 MB |
3974 | nl80211_set_multicast_to_unicast(bss, |
3975 | params->multicast_to_unicast); | |
e87ef751 PX |
3976 | if (beacon_set && params->freq && |
3977 | params->freq->bandwidth != bss->bandwidth) { | |
3978 | wpa_printf(MSG_DEBUG, | |
3979 | "nl80211: Update BSS %s bandwidth: %d -> %d", | |
3980 | bss->ifname, bss->bandwidth, | |
3981 | params->freq->bandwidth); | |
3982 | ret = nl80211_set_channel(bss, params->freq, 1); | |
3983 | if (ret) { | |
3984 | wpa_printf(MSG_DEBUG, | |
3985 | "nl80211: Frequency set failed: %d (%s)", | |
3986 | ret, strerror(-ret)); | |
3987 | } else { | |
3988 | wpa_printf(MSG_DEBUG, | |
3989 | "nl80211: Frequency set succeeded for ht2040 coex"); | |
3990 | bss->bandwidth = params->freq->bandwidth; | |
3991 | } | |
f5728d0a | 3992 | } else if (!beacon_set && params->freq) { |
e87ef751 PX |
3993 | /* |
3994 | * cfg80211 updates the driver on frequence change in AP | |
3995 | * mode only at the point when beaconing is started, so | |
3996 | * set the initial value here. | |
3997 | */ | |
3998 | bss->bandwidth = params->freq->bandwidth; | |
3999 | } | |
b4fd6fab | 4000 | } |
052b8d38 MH |
4001 | |
4002 | #ifdef CONFIG_MESH | |
4003 | if (is_mesh_interface(drv->nlmode) && params->ht_opmode != -1) { | |
4004 | os_memset(&mesh_params, 0, sizeof(mesh_params)); | |
4005 | mesh_params.flags |= WPA_DRIVER_MESH_CONF_FLAG_HT_OP_MODE; | |
4006 | mesh_params.ht_opmode = params->ht_opmode; | |
4007 | ret = nl80211_set_mesh_config(priv, &mesh_params); | |
4008 | if (ret < 0) | |
4009 | return ret; | |
4010 | } | |
4011 | #endif /* CONFIG_MESH */ | |
4012 | ||
d2440ba0 | 4013 | return ret; |
a862e4a3 | 4014 | fail: |
5883168a | 4015 | nlmsg_free(msg); |
d2440ba0 JM |
4016 | return -ENOBUFS; |
4017 | } | |
4018 | ||
4019 | ||
1c4ffa87 | 4020 | static int nl80211_put_freq_params(struct nl_msg *msg, |
72b2605f | 4021 | const struct hostapd_freq_params *freq) |
1581b38b | 4022 | { |
1fc4ab23 | 4023 | wpa_printf(MSG_DEBUG, " * freq=%d", freq->freq); |
a862e4a3 JM |
4024 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq->freq)) |
4025 | return -ENOBUFS; | |
4026 | ||
1fc4ab23 JM |
4027 | wpa_printf(MSG_DEBUG, " * vht_enabled=%d", freq->vht_enabled); |
4028 | wpa_printf(MSG_DEBUG, " * ht_enabled=%d", freq->ht_enabled); | |
4029 | ||
89b800d7 | 4030 | if (freq->vht_enabled) { |
a862e4a3 JM |
4031 | enum nl80211_chan_width cw; |
4032 | ||
1fc4ab23 | 4033 | wpa_printf(MSG_DEBUG, " * bandwidth=%d", freq->bandwidth); |
89b800d7 JB |
4034 | switch (freq->bandwidth) { |
4035 | case 20: | |
a862e4a3 | 4036 | cw = NL80211_CHAN_WIDTH_20; |
89b800d7 JB |
4037 | break; |
4038 | case 40: | |
a862e4a3 | 4039 | cw = NL80211_CHAN_WIDTH_40; |
89b800d7 JB |
4040 | break; |
4041 | case 80: | |
4042 | if (freq->center_freq2) | |
a862e4a3 | 4043 | cw = NL80211_CHAN_WIDTH_80P80; |
89b800d7 | 4044 | else |
a862e4a3 | 4045 | cw = NL80211_CHAN_WIDTH_80; |
89b800d7 JB |
4046 | break; |
4047 | case 160: | |
a862e4a3 | 4048 | cw = NL80211_CHAN_WIDTH_160; |
89b800d7 JB |
4049 | break; |
4050 | default: | |
1c4ffa87 | 4051 | return -EINVAL; |
89b800d7 | 4052 | } |
a862e4a3 | 4053 | |
1fc4ab23 JM |
4054 | wpa_printf(MSG_DEBUG, " * channel_width=%d", cw); |
4055 | wpa_printf(MSG_DEBUG, " * center_freq1=%d", | |
4056 | freq->center_freq1); | |
4057 | wpa_printf(MSG_DEBUG, " * center_freq2=%d", | |
4058 | freq->center_freq2); | |
a862e4a3 JM |
4059 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, cw) || |
4060 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, | |
4061 | freq->center_freq1) || | |
4062 | (freq->center_freq2 && | |
4063 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, | |
4064 | freq->center_freq2))) | |
4065 | return -ENOBUFS; | |
89b800d7 | 4066 | } else if (freq->ht_enabled) { |
a862e4a3 JM |
4067 | enum nl80211_channel_type ct; |
4068 | ||
1fc4ab23 JM |
4069 | wpa_printf(MSG_DEBUG, " * sec_channel_offset=%d", |
4070 | freq->sec_channel_offset); | |
89b800d7 | 4071 | switch (freq->sec_channel_offset) { |
f019981a | 4072 | case -1: |
a862e4a3 | 4073 | ct = NL80211_CHAN_HT40MINUS; |
f019981a JM |
4074 | break; |
4075 | case 1: | |
a862e4a3 | 4076 | ct = NL80211_CHAN_HT40PLUS; |
f019981a JM |
4077 | break; |
4078 | default: | |
a862e4a3 | 4079 | ct = NL80211_CHAN_HT20; |
f019981a JM |
4080 | break; |
4081 | } | |
a862e4a3 | 4082 | |
1fc4ab23 | 4083 | wpa_printf(MSG_DEBUG, " * channel_type=%d", ct); |
a862e4a3 JM |
4084 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, ct)) |
4085 | return -ENOBUFS; | |
3388e7b9 MH |
4086 | } else { |
4087 | wpa_printf(MSG_DEBUG, " * channel_type=%d", | |
4088 | NL80211_CHAN_NO_HT); | |
4089 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, | |
4090 | NL80211_CHAN_NO_HT)) | |
4091 | return -ENOBUFS; | |
f019981a | 4092 | } |
1c4ffa87 | 4093 | return 0; |
1c4ffa87 AO |
4094 | } |
4095 | ||
4096 | ||
e87ef751 PX |
4097 | static int nl80211_set_channel(struct i802_bss *bss, |
4098 | struct hostapd_freq_params *freq, int set_chan) | |
1c4ffa87 AO |
4099 | { |
4100 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
4101 | struct nl_msg *msg; | |
4102 | int ret; | |
4103 | ||
4104 | wpa_printf(MSG_DEBUG, | |
4105 | "nl80211: Set freq %d (ht_enabled=%d, vht_enabled=%d, bandwidth=%d MHz, cf1=%d MHz, cf2=%d MHz)", | |
4106 | freq->freq, freq->ht_enabled, freq->vht_enabled, | |
4107 | freq->bandwidth, freq->center_freq1, freq->center_freq2); | |
1c4ffa87 | 4108 | |
9725b784 JM |
4109 | msg = nl80211_drv_msg(drv, 0, set_chan ? NL80211_CMD_SET_CHANNEL : |
4110 | NL80211_CMD_SET_WIPHY); | |
4111 | if (!msg || nl80211_put_freq_params(msg, freq) < 0) { | |
a862e4a3 JM |
4112 | nlmsg_free(msg); |
4113 | return -1; | |
4114 | } | |
1581b38b | 4115 | |
d2440ba0 | 4116 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
e4fb2167 | 4117 | if (ret == 0) { |
89b800d7 | 4118 | bss->freq = freq->freq; |
1581b38b | 4119 | return 0; |
e4fb2167 | 4120 | } |
f019981a | 4121 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set channel (freq=%d): " |
89b800d7 | 4122 | "%d (%s)", freq->freq, ret, strerror(-ret)); |
1581b38b JM |
4123 | return -1; |
4124 | } | |
4125 | ||
0f4e8b4f | 4126 | |
95ab6063 AN |
4127 | static u32 sta_flags_nl80211(int flags) |
4128 | { | |
4129 | u32 f = 0; | |
4130 | ||
4131 | if (flags & WPA_STA_AUTHORIZED) | |
4132 | f |= BIT(NL80211_STA_FLAG_AUTHORIZED); | |
4133 | if (flags & WPA_STA_WMM) | |
4134 | f |= BIT(NL80211_STA_FLAG_WME); | |
4135 | if (flags & WPA_STA_SHORT_PREAMBLE) | |
4136 | f |= BIT(NL80211_STA_FLAG_SHORT_PREAMBLE); | |
4137 | if (flags & WPA_STA_MFP) | |
4138 | f |= BIT(NL80211_STA_FLAG_MFP); | |
45b722f1 AN |
4139 | if (flags & WPA_STA_TDLS_PEER) |
4140 | f |= BIT(NL80211_STA_FLAG_TDLS_PEER); | |
7a228b5c BC |
4141 | if (flags & WPA_STA_AUTHENTICATED) |
4142 | f |= BIT(NL80211_STA_FLAG_AUTHENTICATED); | |
dc55b6b6 AB |
4143 | if (flags & WPA_STA_ASSOCIATED) |
4144 | f |= BIT(NL80211_STA_FLAG_ASSOCIATED); | |
95ab6063 AN |
4145 | |
4146 | return f; | |
4147 | } | |
4148 | ||
4149 | ||
7c7e7877 BC |
4150 | #ifdef CONFIG_MESH |
4151 | static u32 sta_plink_state_nl80211(enum mesh_plink_state state) | |
4152 | { | |
4153 | switch (state) { | |
d02e5498 | 4154 | case PLINK_IDLE: |
7c7e7877 | 4155 | return NL80211_PLINK_LISTEN; |
d02e5498 | 4156 | case PLINK_OPN_SNT: |
7c7e7877 | 4157 | return NL80211_PLINK_OPN_SNT; |
d02e5498 | 4158 | case PLINK_OPN_RCVD: |
7c7e7877 BC |
4159 | return NL80211_PLINK_OPN_RCVD; |
4160 | case PLINK_CNF_RCVD: | |
4161 | return NL80211_PLINK_CNF_RCVD; | |
4162 | case PLINK_ESTAB: | |
4163 | return NL80211_PLINK_ESTAB; | |
4164 | case PLINK_HOLDING: | |
4165 | return NL80211_PLINK_HOLDING; | |
4166 | case PLINK_BLOCKED: | |
4167 | return NL80211_PLINK_BLOCKED; | |
4168 | default: | |
4169 | wpa_printf(MSG_ERROR, "nl80211: Invalid mesh plink state %d", | |
4170 | state); | |
4171 | } | |
4172 | return -1; | |
4173 | } | |
4174 | #endif /* CONFIG_MESH */ | |
4175 | ||
4176 | ||
62847751 | 4177 | static int wpa_driver_nl80211_sta_add(void *priv, |
0f4e8b4f JM |
4178 | struct hostapd_sta_add_params *params) |
4179 | { | |
a2e40bb6 FF |
4180 | struct i802_bss *bss = priv; |
4181 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8970bae8 | 4182 | struct nl_msg *msg; |
95ab6063 | 4183 | struct nl80211_sta_flag_update upd; |
0f4e8b4f JM |
4184 | int ret = -ENOBUFS; |
4185 | ||
45b722f1 AN |
4186 | if ((params->flags & WPA_STA_TDLS_PEER) && |
4187 | !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) | |
4188 | return -EOPNOTSUPP; | |
4189 | ||
e4dea253 JM |
4190 | wpa_printf(MSG_DEBUG, "nl80211: %s STA " MACSTR, |
4191 | params->set ? "Set" : "Add", MAC2STR(params->addr)); | |
13f83980 JM |
4192 | msg = nl80211_bss_msg(bss, 0, params->set ? NL80211_CMD_SET_STATION : |
4193 | NL80211_CMD_NEW_STATION); | |
4194 | if (!msg || nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->addr)) | |
a862e4a3 | 4195 | goto fail; |
5551bc9c | 4196 | |
dc55b6b6 AB |
4197 | /* |
4198 | * Set the below properties only in one of the following cases: | |
4199 | * 1. New station is added, already associated. | |
4200 | * 2. Set WPA_STA_TDLS_PEER station. | |
4201 | * 3. Set an already added unassociated station, if driver supports | |
4202 | * full AP client state. (Set these properties after station became | |
4203 | * associated will be rejected by the driver). | |
4204 | */ | |
4205 | if (!params->set || (params->flags & WPA_STA_TDLS_PEER) || | |
4206 | (params->set && FULL_AP_CLIENT_STATE_SUPP(drv->capa.flags) && | |
4207 | (params->flags & WPA_STA_ASSOCIATED))) { | |
5551bc9c BC |
4208 | wpa_hexdump(MSG_DEBUG, " * supported rates", |
4209 | params->supp_rates, params->supp_rates_len); | |
a862e4a3 JM |
4210 | wpa_printf(MSG_DEBUG, " * capability=0x%x", |
4211 | params->capability); | |
4212 | if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_RATES, | |
4213 | params->supp_rates_len, params->supp_rates) || | |
4214 | nla_put_u16(msg, NL80211_ATTR_STA_CAPABILITY, | |
4215 | params->capability)) | |
4216 | goto fail; | |
e503861f JM |
4217 | |
4218 | if (params->ht_capabilities) { | |
4219 | wpa_hexdump(MSG_DEBUG, " * ht_capabilities", | |
4220 | (u8 *) params->ht_capabilities, | |
4221 | sizeof(*params->ht_capabilities)); | |
a862e4a3 JM |
4222 | if (nla_put(msg, NL80211_ATTR_HT_CAPABILITY, |
4223 | sizeof(*params->ht_capabilities), | |
4224 | params->ht_capabilities)) | |
4225 | goto fail; | |
e503861f JM |
4226 | } |
4227 | ||
4228 | if (params->vht_capabilities) { | |
4229 | wpa_hexdump(MSG_DEBUG, " * vht_capabilities", | |
4230 | (u8 *) params->vht_capabilities, | |
4231 | sizeof(*params->vht_capabilities)); | |
a862e4a3 JM |
4232 | if (nla_put(msg, NL80211_ATTR_VHT_CAPABILITY, |
4233 | sizeof(*params->vht_capabilities), | |
4234 | params->vht_capabilities)) | |
4235 | goto fail; | |
e503861f JM |
4236 | } |
4237 | ||
e503861f JM |
4238 | if (params->ext_capab) { |
4239 | wpa_hexdump(MSG_DEBUG, " * ext_capab", | |
4240 | params->ext_capab, params->ext_capab_len); | |
a862e4a3 JM |
4241 | if (nla_put(msg, NL80211_ATTR_STA_EXT_CAPABILITY, |
4242 | params->ext_capab_len, params->ext_capab)) | |
4243 | goto fail; | |
e503861f | 4244 | } |
ae33239c AB |
4245 | |
4246 | if (is_ap_interface(drv->nlmode) && | |
4247 | nla_put_u8(msg, NL80211_ATTR_STA_SUPPORT_P2P_PS, | |
4248 | params->support_p2p_ps ? | |
4249 | NL80211_P2P_PS_SUPPORTED : | |
4250 | NL80211_P2P_PS_UNSUPPORTED)) | |
4251 | goto fail; | |
5551bc9c | 4252 | } |
45b722f1 | 4253 | if (!params->set) { |
f11b72c3 JM |
4254 | if (params->aid) { |
4255 | wpa_printf(MSG_DEBUG, " * aid=%u", params->aid); | |
a862e4a3 JM |
4256 | if (nla_put_u16(msg, NL80211_ATTR_STA_AID, params->aid)) |
4257 | goto fail; | |
f11b72c3 JM |
4258 | } else { |
4259 | /* | |
4260 | * cfg80211 validates that AID is non-zero, so we have | |
4261 | * to make this a non-zero value for the TDLS case where | |
dc55b6b6 AB |
4262 | * a dummy STA entry is used for now and for a station |
4263 | * that is still not associated. | |
f11b72c3 | 4264 | */ |
dc55b6b6 AB |
4265 | wpa_printf(MSG_DEBUG, " * aid=1 (%s workaround)", |
4266 | (params->flags & WPA_STA_TDLS_PEER) ? | |
4267 | "TDLS" : "UNASSOC_STA"); | |
a862e4a3 JM |
4268 | if (nla_put_u16(msg, NL80211_ATTR_STA_AID, 1)) |
4269 | goto fail; | |
f11b72c3 | 4270 | } |
e4dea253 JM |
4271 | wpa_printf(MSG_DEBUG, " * listen_interval=%u", |
4272 | params->listen_interval); | |
a862e4a3 JM |
4273 | if (nla_put_u16(msg, NL80211_ATTR_STA_LISTEN_INTERVAL, |
4274 | params->listen_interval)) | |
4275 | goto fail; | |
e112764e JM |
4276 | } else if (params->aid && (params->flags & WPA_STA_TDLS_PEER)) { |
4277 | wpa_printf(MSG_DEBUG, " * peer_aid=%u", params->aid); | |
a862e4a3 JM |
4278 | if (nla_put_u16(msg, NL80211_ATTR_PEER_AID, params->aid)) |
4279 | goto fail; | |
dc55b6b6 AB |
4280 | } else if (FULL_AP_CLIENT_STATE_SUPP(drv->capa.flags) && |
4281 | (params->flags & WPA_STA_ASSOCIATED)) { | |
4282 | wpa_printf(MSG_DEBUG, " * aid=%u", params->aid); | |
4283 | wpa_printf(MSG_DEBUG, " * listen_interval=%u", | |
4284 | params->listen_interval); | |
4285 | if (nla_put_u16(msg, NL80211_ATTR_STA_AID, params->aid) || | |
4286 | nla_put_u16(msg, NL80211_ATTR_STA_LISTEN_INTERVAL, | |
4287 | params->listen_interval)) | |
4288 | goto fail; | |
45b722f1 | 4289 | } |
05a8d422 | 4290 | |
8a458116 MK |
4291 | if (params->vht_opmode_enabled) { |
4292 | wpa_printf(MSG_DEBUG, " * opmode=%u", params->vht_opmode); | |
a862e4a3 JM |
4293 | if (nla_put_u8(msg, NL80211_ATTR_OPMODE_NOTIF, |
4294 | params->vht_opmode)) | |
4295 | goto fail; | |
8a458116 MK |
4296 | } |
4297 | ||
efc64886 SD |
4298 | if (params->supp_channels) { |
4299 | wpa_hexdump(MSG_DEBUG, " * supported channels", | |
4300 | params->supp_channels, params->supp_channels_len); | |
a862e4a3 JM |
4301 | if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_CHANNELS, |
4302 | params->supp_channels_len, params->supp_channels)) | |
4303 | goto fail; | |
efc64886 SD |
4304 | } |
4305 | ||
4306 | if (params->supp_oper_classes) { | |
4307 | wpa_hexdump(MSG_DEBUG, " * supported operating classes", | |
4308 | params->supp_oper_classes, | |
4309 | params->supp_oper_classes_len); | |
a862e4a3 JM |
4310 | if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES, |
4311 | params->supp_oper_classes_len, | |
4312 | params->supp_oper_classes)) | |
4313 | goto fail; | |
efc64886 SD |
4314 | } |
4315 | ||
95ab6063 | 4316 | os_memset(&upd, 0, sizeof(upd)); |
7e31703e BC |
4317 | upd.set = sta_flags_nl80211(params->flags); |
4318 | upd.mask = upd.set | sta_flags_nl80211(params->flags_mask); | |
dc55b6b6 AB |
4319 | |
4320 | /* | |
4321 | * If the driver doesn't support full AP client state, ignore ASSOC/AUTH | |
4322 | * flags, as nl80211 driver moves a new station, by default, into | |
4323 | * associated state. | |
4324 | * | |
4325 | * On the other hand, if the driver supports that feature and the | |
4326 | * station is added in unauthenticated state, set the | |
4327 | * authenticated/associated bits in the mask to prevent moving this | |
4328 | * station to associated state before it is actually associated. | |
4329 | * | |
4330 | * This is irrelevant for mesh mode where the station is added to the | |
4331 | * driver as authenticated already, and ASSOCIATED isn't part of the | |
4332 | * nl80211 API. | |
4333 | */ | |
4334 | if (!is_mesh_interface(drv->nlmode)) { | |
4335 | if (!FULL_AP_CLIENT_STATE_SUPP(drv->capa.flags)) { | |
4336 | wpa_printf(MSG_DEBUG, | |
4337 | "nl80211: Ignore ASSOC/AUTH flags since driver doesn't support full AP client state"); | |
4338 | upd.mask &= ~(BIT(NL80211_STA_FLAG_ASSOCIATED) | | |
4339 | BIT(NL80211_STA_FLAG_AUTHENTICATED)); | |
4340 | } else if (!params->set && | |
4341 | !(params->flags & WPA_STA_TDLS_PEER)) { | |
4342 | if (!(params->flags & WPA_STA_AUTHENTICATED)) | |
4343 | upd.mask |= BIT(NL80211_STA_FLAG_AUTHENTICATED); | |
4344 | if (!(params->flags & WPA_STA_ASSOCIATED)) | |
4345 | upd.mask |= BIT(NL80211_STA_FLAG_ASSOCIATED); | |
4346 | } | |
e347cafe MH |
4347 | #ifdef CONFIG_MESH |
4348 | } else { | |
4349 | if (params->plink_state == PLINK_ESTAB && params->peer_aid) { | |
4350 | ret = nla_put_u16(msg, NL80211_ATTR_MESH_PEER_AID, | |
4351 | params->peer_aid); | |
4352 | if (ret) | |
4353 | goto fail; | |
4354 | } | |
4355 | #endif /* CONFIG_MESH */ | |
dc55b6b6 AB |
4356 | } |
4357 | ||
e4dea253 JM |
4358 | wpa_printf(MSG_DEBUG, " * flags set=0x%x mask=0x%x", |
4359 | upd.set, upd.mask); | |
a862e4a3 JM |
4360 | if (nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd)) |
4361 | goto fail; | |
95ab6063 | 4362 | |
7c7e7877 | 4363 | #ifdef CONFIG_MESH |
a862e4a3 JM |
4364 | if (params->plink_state && |
4365 | nla_put_u8(msg, NL80211_ATTR_STA_PLINK_STATE, | |
4366 | sta_plink_state_nl80211(params->plink_state))) | |
4367 | goto fail; | |
7c7e7877 BC |
4368 | #endif /* CONFIG_MESH */ |
4369 | ||
774bfa62 | 4370 | if (params->flags & WPA_STA_WMM) { |
8970bae8 JB |
4371 | struct nlattr *wme = nla_nest_start(msg, NL80211_ATTR_STA_WME); |
4372 | ||
e4dea253 | 4373 | wpa_printf(MSG_DEBUG, " * qosinfo=0x%x", params->qosinfo); |
a862e4a3 JM |
4374 | if (!wme || |
4375 | nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES, | |
4376 | params->qosinfo & WMM_QOSINFO_STA_AC_MASK) || | |
4377 | nla_put_u8(msg, NL80211_STA_WME_MAX_SP, | |
4378 | (params->qosinfo >> WMM_QOSINFO_STA_SP_SHIFT) & | |
4379 | WMM_QOSINFO_STA_SP_MASK)) | |
4380 | goto fail; | |
8970bae8 | 4381 | nla_nest_end(msg, wme); |
774bfa62 EP |
4382 | } |
4383 | ||
0f4e8b4f | 4384 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
5883168a | 4385 | msg = NULL; |
0f4e8b4f | 4386 | if (ret) |
45b722f1 AN |
4387 | wpa_printf(MSG_DEBUG, "nl80211: NL80211_CMD_%s_STATION " |
4388 | "result: %d (%s)", params->set ? "SET" : "NEW", ret, | |
4389 | strerror(-ret)); | |
0f4e8b4f JM |
4390 | if (ret == -EEXIST) |
4391 | ret = 0; | |
a862e4a3 | 4392 | fail: |
5883168a | 4393 | nlmsg_free(msg); |
0f4e8b4f JM |
4394 | return ret; |
4395 | } | |
4396 | ||
4397 | ||
97ed9a06 KP |
4398 | static void rtnl_neigh_delete_fdb_entry(struct i802_bss *bss, const u8 *addr) |
4399 | { | |
4400 | #ifdef CONFIG_LIBNL3_ROUTE | |
4401 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
4402 | struct rtnl_neigh *rn; | |
4403 | struct nl_addr *nl_addr; | |
4404 | int err; | |
4405 | ||
4406 | rn = rtnl_neigh_alloc(); | |
4407 | if (!rn) | |
4408 | return; | |
4409 | ||
4410 | rtnl_neigh_set_family(rn, AF_BRIDGE); | |
4411 | rtnl_neigh_set_ifindex(rn, bss->ifindex); | |
4412 | nl_addr = nl_addr_build(AF_BRIDGE, (void *) addr, ETH_ALEN); | |
4413 | if (!nl_addr) { | |
4414 | rtnl_neigh_put(rn); | |
4415 | return; | |
4416 | } | |
4417 | rtnl_neigh_set_lladdr(rn, nl_addr); | |
4418 | ||
4419 | err = rtnl_neigh_delete(drv->rtnl_sk, rn, 0); | |
4420 | if (err < 0) { | |
4421 | wpa_printf(MSG_DEBUG, "nl80211: bridge FDB entry delete for " | |
4422 | MACSTR " ifindex=%d failed: %s", MAC2STR(addr), | |
4423 | bss->ifindex, nl_geterror(err)); | |
4424 | } else { | |
4425 | wpa_printf(MSG_DEBUG, "nl80211: deleted bridge FDB entry for " | |
4426 | MACSTR, MAC2STR(addr)); | |
4427 | } | |
4428 | ||
4429 | nl_addr_put(nl_addr); | |
4430 | rtnl_neigh_put(rn); | |
4431 | #endif /* CONFIG_LIBNL3_ROUTE */ | |
4432 | } | |
4433 | ||
4434 | ||
59d7148a JM |
4435 | static int wpa_driver_nl80211_sta_remove(struct i802_bss *bss, const u8 *addr, |
4436 | int deauth, u16 reason_code) | |
0f4e8b4f | 4437 | { |
a2e40bb6 | 4438 | struct wpa_driver_nl80211_data *drv = bss->drv; |
0f4e8b4f JM |
4439 | struct nl_msg *msg; |
4440 | int ret; | |
4441 | ||
13f83980 | 4442 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_DEL_STATION)) || |
a862e4a3 JM |
4443 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
4444 | (deauth == 0 && | |
4445 | nla_put_u8(msg, NL80211_ATTR_MGMT_SUBTYPE, | |
4446 | WLAN_FC_STYPE_DISASSOC)) || | |
4447 | (deauth == 1 && | |
4448 | nla_put_u8(msg, NL80211_ATTR_MGMT_SUBTYPE, | |
4449 | WLAN_FC_STYPE_DEAUTH)) || | |
4450 | (reason_code && | |
4451 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) { | |
4452 | nlmsg_free(msg); | |
4453 | return -ENOBUFS; | |
4454 | } | |
0f4e8b4f JM |
4455 | |
4456 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
83e7bb0e JM |
4457 | wpa_printf(MSG_DEBUG, "nl80211: sta_remove -> DEL_STATION %s " MACSTR |
4458 | " --> %d (%s)", | |
4459 | bss->ifname, MAC2STR(addr), ret, strerror(-ret)); | |
97ed9a06 KP |
4460 | |
4461 | if (drv->rtnl_sk) | |
4462 | rtnl_neigh_delete_fdb_entry(bss, addr); | |
4463 | ||
0f4e8b4f JM |
4464 | if (ret == -ENOENT) |
4465 | return 0; | |
4466 | return ret; | |
0f4e8b4f JM |
4467 | } |
4468 | ||
1581b38b | 4469 | |
f3407c66 | 4470 | void nl80211_remove_iface(struct wpa_driver_nl80211_data *drv, int ifidx) |
0915d02c JM |
4471 | { |
4472 | struct nl_msg *msg; | |
de884303 | 4473 | struct wpa_driver_nl80211_data *drv2; |
0915d02c | 4474 | |
c6e8e8e4 JM |
4475 | wpa_printf(MSG_DEBUG, "nl80211: Remove interface ifindex=%d", ifidx); |
4476 | ||
2135f224 | 4477 | /* stop listening for EAPOL on this interface */ |
de884303 JM |
4478 | dl_list_for_each(drv2, &drv->global->interfaces, |
4479 | struct wpa_driver_nl80211_data, list) | |
732b1d20 MB |
4480 | { |
4481 | del_ifidx(drv2, ifidx, IFIDX_ANY); | |
4482 | /* Remove all bridges learned for this iface */ | |
4483 | del_ifidx(drv2, IFIDX_ANY, ifidx); | |
4484 | } | |
2135f224 | 4485 | |
95376e1a | 4486 | msg = nl80211_ifindex_msg(drv, ifidx, 0, NL80211_CMD_DEL_INTERFACE); |
0915d02c JM |
4487 | if (send_and_recv_msgs(drv, msg, NULL, NULL) == 0) |
4488 | return; | |
e748062b | 4489 | wpa_printf(MSG_ERROR, "Failed to remove interface (ifidx=%d)", ifidx); |
0915d02c JM |
4490 | } |
4491 | ||
4492 | ||
cc9a2575 | 4493 | const char * nl80211_iftype_str(enum nl80211_iftype mode) |
a1922f93 JM |
4494 | { |
4495 | switch (mode) { | |
4496 | case NL80211_IFTYPE_ADHOC: | |
4497 | return "ADHOC"; | |
4498 | case NL80211_IFTYPE_STATION: | |
4499 | return "STATION"; | |
4500 | case NL80211_IFTYPE_AP: | |
4501 | return "AP"; | |
1045ec36 JM |
4502 | case NL80211_IFTYPE_AP_VLAN: |
4503 | return "AP_VLAN"; | |
4504 | case NL80211_IFTYPE_WDS: | |
4505 | return "WDS"; | |
a1922f93 JM |
4506 | case NL80211_IFTYPE_MONITOR: |
4507 | return "MONITOR"; | |
1045ec36 JM |
4508 | case NL80211_IFTYPE_MESH_POINT: |
4509 | return "MESH_POINT"; | |
a1922f93 JM |
4510 | case NL80211_IFTYPE_P2P_CLIENT: |
4511 | return "P2P_CLIENT"; | |
4512 | case NL80211_IFTYPE_P2P_GO: | |
4513 | return "P2P_GO"; | |
7aad838c NS |
4514 | case NL80211_IFTYPE_P2P_DEVICE: |
4515 | return "P2P_DEVICE"; | |
a1922f93 JM |
4516 | default: |
4517 | return "unknown"; | |
4518 | } | |
4519 | } | |
4520 | ||
4521 | ||
a35187e7 KH |
4522 | static int nl80211_create_iface_once(struct wpa_driver_nl80211_data *drv, |
4523 | const char *ifname, | |
4524 | enum nl80211_iftype iftype, | |
d6dcfcda DS |
4525 | const u8 *addr, int wds, |
4526 | int (*handler)(struct nl_msg *, void *), | |
4527 | void *arg) | |
0915d02c | 4528 | { |
8970bae8 | 4529 | struct nl_msg *msg; |
0915d02c JM |
4530 | int ifidx; |
4531 | int ret = -ENOBUFS; | |
4532 | ||
a1922f93 JM |
4533 | wpa_printf(MSG_DEBUG, "nl80211: Create interface iftype %d (%s)", |
4534 | iftype, nl80211_iftype_str(iftype)); | |
4535 | ||
56f77852 JM |
4536 | msg = nl80211_cmd_msg(drv->first_bss, 0, NL80211_CMD_NEW_INTERFACE); |
4537 | if (!msg || | |
a862e4a3 JM |
4538 | nla_put_string(msg, NL80211_ATTR_IFNAME, ifname) || |
4539 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, iftype)) | |
4540 | goto fail; | |
0915d02c JM |
4541 | |
4542 | if (iftype == NL80211_IFTYPE_MONITOR) { | |
8970bae8 | 4543 | struct nlattr *flags; |
0915d02c | 4544 | |
8970bae8 | 4545 | flags = nla_nest_start(msg, NL80211_ATTR_MNTR_FLAGS); |
a862e4a3 JM |
4546 | if (!flags || |
4547 | nla_put_flag(msg, NL80211_MNTR_FLAG_COOK_FRAMES)) | |
4548 | goto fail; | |
0915d02c | 4549 | |
8970bae8 | 4550 | nla_nest_end(msg, flags); |
fbbfcbac | 4551 | } else if (wds) { |
a862e4a3 JM |
4552 | if (nla_put_u8(msg, NL80211_ATTR_4ADDR, wds)) |
4553 | goto fail; | |
0915d02c JM |
4554 | } |
4555 | ||
52f5877a IP |
4556 | /* |
4557 | * Tell cfg80211 that the interface belongs to the socket that created | |
4558 | * it, and the interface should be deleted when the socket is closed. | |
4559 | */ | |
a862e4a3 JM |
4560 | if (nla_put_flag(msg, NL80211_ATTR_IFACE_SOCKET_OWNER)) |
4561 | goto fail; | |
52f5877a | 4562 | |
d6dcfcda | 4563 | ret = send_and_recv_msgs(drv, msg, handler, arg); |
5883168a | 4564 | msg = NULL; |
0915d02c | 4565 | if (ret) { |
a862e4a3 | 4566 | fail: |
5883168a | 4567 | nlmsg_free(msg); |
a35187e7 KH |
4568 | wpa_printf(MSG_ERROR, "Failed to create interface %s: %d (%s)", |
4569 | ifname, ret, strerror(-ret)); | |
0915d02c JM |
4570 | return ret; |
4571 | } | |
4572 | ||
f632e483 | 4573 | if (iftype == NL80211_IFTYPE_P2P_DEVICE) |
6bae92e0 | 4574 | return 0; |
6bae92e0 | 4575 | |
0915d02c | 4576 | ifidx = if_nametoindex(ifname); |
c6e8e8e4 JM |
4577 | wpa_printf(MSG_DEBUG, "nl80211: New interface %s created: ifindex=%d", |
4578 | ifname, ifidx); | |
0915d02c JM |
4579 | |
4580 | if (ifidx <= 0) | |
4581 | return -1; | |
4582 | ||
147848ec JM |
4583 | /* |
4584 | * Some virtual interfaces need to process EAPOL packets and events on | |
4585 | * the parent interface. This is used mainly with hostapd. | |
4586 | */ | |
4587 | if (drv->hostapd || | |
4588 | iftype == NL80211_IFTYPE_AP_VLAN || | |
4589 | iftype == NL80211_IFTYPE_WDS || | |
4590 | iftype == NL80211_IFTYPE_MONITOR) { | |
4591 | /* start listening for EAPOL on this interface */ | |
732b1d20 | 4592 | add_ifidx(drv, ifidx, IFIDX_ANY); |
147848ec | 4593 | } |
2135f224 | 4594 | |
7bfc47c3 | 4595 | if (addr && iftype != NL80211_IFTYPE_MONITOR && |
c81eff1a | 4596 | linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, addr)) { |
41d931ee JM |
4597 | nl80211_remove_iface(drv, ifidx); |
4598 | return -1; | |
2135f224 | 4599 | } |
2135f224 | 4600 | |
0915d02c JM |
4601 | return ifidx; |
4602 | } | |
22a7c9d7 JM |
4603 | |
4604 | ||
f3407c66 JM |
4605 | int nl80211_create_iface(struct wpa_driver_nl80211_data *drv, |
4606 | const char *ifname, enum nl80211_iftype iftype, | |
4607 | const u8 *addr, int wds, | |
4608 | int (*handler)(struct nl_msg *, void *), | |
4609 | void *arg, int use_existing) | |
a35187e7 KH |
4610 | { |
4611 | int ret; | |
4612 | ||
d6dcfcda DS |
4613 | ret = nl80211_create_iface_once(drv, ifname, iftype, addr, wds, handler, |
4614 | arg); | |
a35187e7 | 4615 | |
ffbf1eaa | 4616 | /* if error occurred and interface exists already */ |
a35187e7 | 4617 | if (ret == -ENFILE && if_nametoindex(ifname)) { |
2aec4f3c JM |
4618 | if (use_existing) { |
4619 | wpa_printf(MSG_DEBUG, "nl80211: Continue using existing interface %s", | |
4620 | ifname); | |
6997f8ba JM |
4621 | if (addr && iftype != NL80211_IFTYPE_MONITOR && |
4622 | linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, | |
4623 | addr) < 0 && | |
4624 | (linux_set_iface_flags(drv->global->ioctl_sock, | |
4625 | ifname, 0) < 0 || | |
4626 | linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, | |
4627 | addr) < 0 || | |
4628 | linux_set_iface_flags(drv->global->ioctl_sock, | |
4629 | ifname, 1) < 0)) | |
4630 | return -1; | |
2aec4f3c JM |
4631 | return -ENFILE; |
4632 | } | |
a35187e7 KH |
4633 | wpa_printf(MSG_INFO, "Try to remove and re-create %s", ifname); |
4634 | ||
4635 | /* Try to remove the interface that was already there. */ | |
4636 | nl80211_remove_iface(drv, if_nametoindex(ifname)); | |
4637 | ||
4638 | /* Try to create the interface again */ | |
fbbfcbac | 4639 | ret = nl80211_create_iface_once(drv, ifname, iftype, addr, |
d6dcfcda | 4640 | wds, handler, arg); |
a35187e7 KH |
4641 | } |
4642 | ||
3e208481 JM |
4643 | if (ret >= 0 && is_p2p_net_interface(iftype)) { |
4644 | wpa_printf(MSG_DEBUG, | |
4645 | "nl80211: Interface %s created for P2P - disable 11b rates", | |
4646 | ifname); | |
4e5cb1a3 | 4647 | nl80211_disable_11b_rates(drv, ret, 1); |
3e208481 | 4648 | } |
4e5cb1a3 | 4649 | |
a35187e7 KH |
4650 | return ret; |
4651 | } | |
0915d02c | 4652 | |
2135f224 | 4653 | |
3fd1cefb JB |
4654 | static int nl80211_setup_ap(struct i802_bss *bss) |
4655 | { | |
4656 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
4657 | ||
748c0ac0 JM |
4658 | wpa_printf(MSG_DEBUG, "nl80211: Setup AP(%s) - device_ap_sme=%d use_monitor=%d", |
4659 | bss->ifname, drv->device_ap_sme, drv->use_monitor); | |
36488c05 | 4660 | |
a11241fa JB |
4661 | /* |
4662 | * Disable Probe Request reporting unless we need it in this way for | |
4663 | * devices that include the AP SME, in the other case (unless using | |
4664 | * monitor iface) we'll get it through the nl_mgmt socket instead. | |
4665 | */ | |
4666 | if (!drv->device_ap_sme) | |
4667 | wpa_driver_nl80211_probe_req_report(bss, 0); | |
4668 | ||
4669 | if (!drv->device_ap_sme && !drv->use_monitor) | |
4670 | if (nl80211_mgmt_subscribe_ap(bss)) | |
4671 | return -1; | |
4672 | ||
a6cc0602 JM |
4673 | if (drv->device_ap_sme && !drv->use_monitor) |
4674 | if (nl80211_mgmt_subscribe_ap_dev_sme(bss)) | |
f4830bed RM |
4675 | wpa_printf(MSG_DEBUG, |
4676 | "nl80211: Failed to subscribe for mgmt frames from SME driver - trying to run without it"); | |
a6cc0602 | 4677 | |
a11241fa | 4678 | if (!drv->device_ap_sme && drv->use_monitor && |
ea19b39f RM |
4679 | nl80211_create_monitor_interface(drv) && |
4680 | !drv->device_ap_sme) | |
3fd1cefb JB |
4681 | return -1; |
4682 | ||
4683 | if (drv->device_ap_sme && | |
4684 | wpa_driver_nl80211_probe_req_report(bss, 1) < 0) { | |
4685 | wpa_printf(MSG_DEBUG, "nl80211: Failed to enable " | |
4686 | "Probe Request frame reporting in AP mode"); | |
4687 | /* Try to survive without this */ | |
4688 | } | |
4689 | ||
4690 | return 0; | |
4691 | } | |
4692 | ||
4693 | ||
4694 | static void nl80211_teardown_ap(struct i802_bss *bss) | |
4695 | { | |
4696 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
4697 | ||
748c0ac0 JM |
4698 | wpa_printf(MSG_DEBUG, "nl80211: Teardown AP(%s) - device_ap_sme=%d use_monitor=%d", |
4699 | bss->ifname, drv->device_ap_sme, drv->use_monitor); | |
a6cc0602 | 4700 | if (drv->device_ap_sme) { |
3fd1cefb | 4701 | wpa_driver_nl80211_probe_req_report(bss, 0); |
a6cc0602 JM |
4702 | if (!drv->use_monitor) |
4703 | nl80211_mgmt_unsubscribe(bss, "AP teardown (dev SME)"); | |
4704 | } else if (drv->use_monitor) | |
3fd1cefb | 4705 | nl80211_remove_monitor_interface(drv); |
a11241fa | 4706 | else |
36488c05 | 4707 | nl80211_mgmt_unsubscribe(bss, "AP teardown"); |
a11241fa | 4708 | |
3fd1cefb JB |
4709 | bss->beacon_set = 0; |
4710 | } | |
4711 | ||
4712 | ||
f10bfc9a JM |
4713 | static int nl80211_send_eapol_data(struct i802_bss *bss, |
4714 | const u8 *addr, const u8 *data, | |
d12dab4c | 4715 | size_t data_len) |
f10bfc9a | 4716 | { |
d12dab4c JB |
4717 | struct sockaddr_ll ll; |
4718 | int ret; | |
4719 | ||
4720 | if (bss->drv->eapol_tx_sock < 0) { | |
4721 | wpa_printf(MSG_DEBUG, "nl80211: No socket to send EAPOL"); | |
f10bfc9a JM |
4722 | return -1; |
4723 | } | |
4724 | ||
d12dab4c JB |
4725 | os_memset(&ll, 0, sizeof(ll)); |
4726 | ll.sll_family = AF_PACKET; | |
4727 | ll.sll_ifindex = bss->ifindex; | |
4728 | ll.sll_protocol = htons(ETH_P_PAE); | |
4729 | ll.sll_halen = ETH_ALEN; | |
4730 | os_memcpy(ll.sll_addr, addr, ETH_ALEN); | |
4731 | ret = sendto(bss->drv->eapol_tx_sock, data, data_len, 0, | |
4732 | (struct sockaddr *) &ll, sizeof(ll)); | |
4733 | if (ret < 0) | |
4734 | wpa_printf(MSG_ERROR, "nl80211: EAPOL TX: %s", | |
4735 | strerror(errno)); | |
4736 | ||
4737 | return ret; | |
f10bfc9a | 4738 | } |
5fb1a232 | 4739 | |
f10bfc9a | 4740 | |
db149ac9 JM |
4741 | static const u8 rfc1042_header[6] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 }; |
4742 | ||
4743 | static int wpa_driver_nl80211_hapd_send_eapol( | |
4744 | void *priv, const u8 *addr, const u8 *data, | |
4378fc14 | 4745 | size_t data_len, int encrypt, const u8 *own_addr, u32 flags) |
db149ac9 | 4746 | { |
a2e40bb6 FF |
4747 | struct i802_bss *bss = priv; |
4748 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
db149ac9 JM |
4749 | struct ieee80211_hdr *hdr; |
4750 | size_t len; | |
4751 | u8 *pos; | |
4752 | int res; | |
4378fc14 | 4753 | int qos = flags & WPA_STA_WMM; |
db149ac9 | 4754 | |
a11241fa | 4755 | if (drv->device_ap_sme || !drv->use_monitor) |
d12dab4c | 4756 | return nl80211_send_eapol_data(bss, addr, data, data_len); |
f10bfc9a | 4757 | |
db149ac9 JM |
4758 | len = sizeof(*hdr) + (qos ? 2 : 0) + sizeof(rfc1042_header) + 2 + |
4759 | data_len; | |
4760 | hdr = os_zalloc(len); | |
4761 | if (hdr == NULL) { | |
7ac3616d JM |
4762 | wpa_printf(MSG_INFO, "nl80211: Failed to allocate EAPOL buffer(len=%lu)", |
4763 | (unsigned long) len); | |
db149ac9 JM |
4764 | return -1; |
4765 | } | |
4766 | ||
4767 | hdr->frame_control = | |
4768 | IEEE80211_FC(WLAN_FC_TYPE_DATA, WLAN_FC_STYPE_DATA); | |
4769 | hdr->frame_control |= host_to_le16(WLAN_FC_FROMDS); | |
4770 | if (encrypt) | |
4771 | hdr->frame_control |= host_to_le16(WLAN_FC_ISWEP); | |
db149ac9 JM |
4772 | if (qos) { |
4773 | hdr->frame_control |= | |
4774 | host_to_le16(WLAN_FC_STYPE_QOS_DATA << 4); | |
4775 | } | |
db149ac9 JM |
4776 | |
4777 | memcpy(hdr->IEEE80211_DA_FROMDS, addr, ETH_ALEN); | |
4778 | memcpy(hdr->IEEE80211_BSSID_FROMDS, own_addr, ETH_ALEN); | |
4779 | memcpy(hdr->IEEE80211_SA_FROMDS, own_addr, ETH_ALEN); | |
4780 | pos = (u8 *) (hdr + 1); | |
4781 | ||
db149ac9 | 4782 | if (qos) { |
92d521d8 FF |
4783 | /* Set highest priority in QoS header */ |
4784 | pos[0] = 7; | |
db149ac9 JM |
4785 | pos[1] = 0; |
4786 | pos += 2; | |
4787 | } | |
db149ac9 JM |
4788 | |
4789 | memcpy(pos, rfc1042_header, sizeof(rfc1042_header)); | |
4790 | pos += sizeof(rfc1042_header); | |
4791 | WPA_PUT_BE16(pos, ETH_P_PAE); | |
4792 | pos += 2; | |
4793 | memcpy(pos, data, data_len); | |
4794 | ||
55231068 | 4795 | res = wpa_driver_nl80211_send_frame(bss, (u8 *) hdr, len, encrypt, 0, |
2d3943ce | 4796 | 0, 0, 0, 0, NULL, 0); |
db149ac9 JM |
4797 | if (res < 0) { |
4798 | wpa_printf(MSG_ERROR, "i802_send_eapol - packet len: %lu - " | |
4799 | "failed: %d (%s)", | |
4800 | (unsigned long) len, errno, strerror(errno)); | |
4801 | } | |
7bf12757 | 4802 | os_free(hdr); |
db149ac9 JM |
4803 | |
4804 | return res; | |
4805 | } | |
4806 | ||
a8d6ffa4 | 4807 | |
3234cba4 | 4808 | static int wpa_driver_nl80211_sta_set_flags(void *priv, const u8 *addr, |
f97e3ce4 JM |
4809 | unsigned int total_flags, |
4810 | unsigned int flags_or, | |
4811 | unsigned int flags_and) | |
a8d6ffa4 | 4812 | { |
a2e40bb6 | 4813 | struct i802_bss *bss = priv; |
8970bae8 JB |
4814 | struct nl_msg *msg; |
4815 | struct nlattr *flags; | |
7e76ee9c | 4816 | struct nl80211_sta_flag_update upd; |
a8d6ffa4 | 4817 | |
0cd9846c JM |
4818 | wpa_printf(MSG_DEBUG, "nl80211: Set STA flags - ifname=%s addr=" MACSTR |
4819 | " total_flags=0x%x flags_or=0x%x flags_and=0x%x authorized=%d", | |
4820 | bss->ifname, MAC2STR(addr), total_flags, flags_or, flags_and, | |
4821 | !!(total_flags & WPA_STA_AUTHORIZED)); | |
4822 | ||
13f83980 | 4823 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) || |
a862e4a3 JM |
4824 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
4825 | goto fail; | |
a8d6ffa4 | 4826 | |
7e76ee9c JM |
4827 | /* |
4828 | * Backwards compatibility version using NL80211_ATTR_STA_FLAGS. This | |
4829 | * can be removed eventually. | |
4830 | */ | |
8970bae8 | 4831 | flags = nla_nest_start(msg, NL80211_ATTR_STA_FLAGS); |
a862e4a3 JM |
4832 | if (!flags || |
4833 | ((total_flags & WPA_STA_AUTHORIZED) && | |
4834 | nla_put_flag(msg, NL80211_STA_FLAG_AUTHORIZED)) || | |
4835 | ((total_flags & WPA_STA_WMM) && | |
4836 | nla_put_flag(msg, NL80211_STA_FLAG_WME)) || | |
4837 | ((total_flags & WPA_STA_SHORT_PREAMBLE) && | |
4838 | nla_put_flag(msg, NL80211_STA_FLAG_SHORT_PREAMBLE)) || | |
4839 | ((total_flags & WPA_STA_MFP) && | |
4840 | nla_put_flag(msg, NL80211_STA_FLAG_MFP)) || | |
4841 | ((total_flags & WPA_STA_TDLS_PEER) && | |
4842 | nla_put_flag(msg, NL80211_STA_FLAG_TDLS_PEER))) | |
4843 | goto fail; | |
45b722f1 | 4844 | |
8970bae8 | 4845 | nla_nest_end(msg, flags); |
a8d6ffa4 | 4846 | |
7e76ee9c JM |
4847 | os_memset(&upd, 0, sizeof(upd)); |
4848 | upd.mask = sta_flags_nl80211(flags_or | ~flags_and); | |
4849 | upd.set = sta_flags_nl80211(flags_or); | |
a862e4a3 JM |
4850 | if (nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd)) |
4851 | goto fail; | |
7e76ee9c | 4852 | |
13f83980 | 4853 | return send_and_recv_msgs(bss->drv, msg, NULL, NULL); |
a862e4a3 | 4854 | fail: |
5883168a | 4855 | nlmsg_free(msg); |
a8d6ffa4 JM |
4856 | return -ENOBUFS; |
4857 | } | |
4858 | ||
0915d02c | 4859 | |
1581b38b JM |
4860 | static int wpa_driver_nl80211_ap(struct wpa_driver_nl80211_data *drv, |
4861 | struct wpa_driver_associate_params *params) | |
4862 | { | |
708bc8e0 | 4863 | enum nl80211_iftype nlmode, old_mode; |
b1f625e0 EP |
4864 | |
4865 | if (params->p2p) { | |
046b26a2 JM |
4866 | wpa_printf(MSG_DEBUG, "nl80211: Setup AP operations for P2P " |
4867 | "group (GO)"); | |
b1f625e0 EP |
4868 | nlmode = NL80211_IFTYPE_P2P_GO; |
4869 | } else | |
4870 | nlmode = NL80211_IFTYPE_AP; | |
4871 | ||
708bc8e0 | 4872 | old_mode = drv->nlmode; |
834ee56f | 4873 | if (wpa_driver_nl80211_set_mode(drv->first_bss, nlmode)) { |
708bc8e0 JM |
4874 | nl80211_remove_monitor_interface(drv); |
4875 | return -1; | |
4876 | } | |
4877 | ||
6e9023ea JM |
4878 | if (params->freq.freq && |
4879 | nl80211_set_channel(drv->first_bss, ¶ms->freq, 0)) { | |
708bc8e0 | 4880 | if (old_mode != nlmode) |
834ee56f | 4881 | wpa_driver_nl80211_set_mode(drv->first_bss, old_mode); |
460456f8 | 4882 | nl80211_remove_monitor_interface(drv); |
1581b38b | 4883 | return -1; |
0915d02c | 4884 | } |
1581b38b | 4885 | |
1581b38b JM |
4886 | return 0; |
4887 | } | |
1581b38b JM |
4888 | |
4889 | ||
666e508c JM |
4890 | static int nl80211_leave_ibss(struct wpa_driver_nl80211_data *drv, |
4891 | int reset_mode) | |
5cc4d64b JM |
4892 | { |
4893 | struct nl_msg *msg; | |
9725b784 | 4894 | int ret; |
a862e4a3 | 4895 | |
9725b784 | 4896 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_LEAVE_IBSS); |
5cc4d64b | 4897 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
5cc4d64b JM |
4898 | if (ret) { |
4899 | wpa_printf(MSG_DEBUG, "nl80211: Leave IBSS failed: ret=%d " | |
4900 | "(%s)", ret, strerror(-ret)); | |
9725b784 JM |
4901 | } else { |
4902 | wpa_printf(MSG_DEBUG, | |
4903 | "nl80211: Leave IBSS request sent successfully"); | |
5cc4d64b JM |
4904 | } |
4905 | ||
666e508c JM |
4906 | if (reset_mode && |
4907 | wpa_driver_nl80211_set_mode(drv->first_bss, | |
5d4c78fb JM |
4908 | NL80211_IFTYPE_STATION)) { |
4909 | wpa_printf(MSG_INFO, "nl80211: Failed to set interface into " | |
4910 | "station mode"); | |
4911 | } | |
4912 | ||
5cc4d64b JM |
4913 | return ret; |
4914 | } | |
4915 | ||
4916 | ||
95ff3069 JD |
4917 | static int nl80211_ht_vht_overrides(struct nl_msg *msg, |
4918 | struct wpa_driver_associate_params *params) | |
4919 | { | |
4920 | if (params->disable_ht && nla_put_flag(msg, NL80211_ATTR_DISABLE_HT)) | |
4921 | return -1; | |
4922 | ||
4923 | if (params->htcaps && params->htcaps_mask) { | |
4924 | int sz = sizeof(struct ieee80211_ht_capabilities); | |
4925 | wpa_hexdump(MSG_DEBUG, " * htcaps", params->htcaps, sz); | |
4926 | wpa_hexdump(MSG_DEBUG, " * htcaps_mask", | |
4927 | params->htcaps_mask, sz); | |
4928 | if (nla_put(msg, NL80211_ATTR_HT_CAPABILITY, sz, | |
4929 | params->htcaps) || | |
4930 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, sz, | |
4931 | params->htcaps_mask)) | |
4932 | return -1; | |
4933 | } | |
4934 | ||
4935 | #ifdef CONFIG_VHT_OVERRIDES | |
4936 | if (params->disable_vht) { | |
4937 | wpa_printf(MSG_DEBUG, " * VHT disabled"); | |
4938 | if (nla_put_flag(msg, NL80211_ATTR_DISABLE_VHT)) | |
4939 | return -1; | |
4940 | } | |
4941 | ||
4942 | if (params->vhtcaps && params->vhtcaps_mask) { | |
4943 | int sz = sizeof(struct ieee80211_vht_capabilities); | |
4944 | wpa_hexdump(MSG_DEBUG, " * vhtcaps", params->vhtcaps, sz); | |
4945 | wpa_hexdump(MSG_DEBUG, " * vhtcaps_mask", | |
4946 | params->vhtcaps_mask, sz); | |
4947 | if (nla_put(msg, NL80211_ATTR_VHT_CAPABILITY, sz, | |
4948 | params->vhtcaps) || | |
4949 | nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, sz, | |
4950 | params->vhtcaps_mask)) | |
4951 | return -1; | |
4952 | } | |
4953 | #endif /* CONFIG_VHT_OVERRIDES */ | |
4954 | ||
4955 | return 0; | |
4956 | } | |
4957 | ||
4958 | ||
5cc4d64b JM |
4959 | static int wpa_driver_nl80211_ibss(struct wpa_driver_nl80211_data *drv, |
4960 | struct wpa_driver_associate_params *params) | |
4961 | { | |
4962 | struct nl_msg *msg; | |
4963 | int ret = -1; | |
4964 | int count = 0; | |
4965 | ||
4966 | wpa_printf(MSG_DEBUG, "nl80211: Join IBSS (ifindex=%d)", drv->ifindex); | |
4967 | ||
4ec68377 | 4968 | if (wpa_driver_nl80211_set_mode_ibss(drv->first_bss, ¶ms->freq)) { |
5cc4d64b JM |
4969 | wpa_printf(MSG_INFO, "nl80211: Failed to set interface into " |
4970 | "IBSS mode"); | |
4971 | return -1; | |
4972 | } | |
4973 | ||
4974 | retry: | |
9725b784 | 4975 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_JOIN_IBSS)) || |
a862e4a3 JM |
4976 | params->ssid == NULL || params->ssid_len > sizeof(drv->ssid)) |
4977 | goto fail; | |
5cc4d64b JM |
4978 | |
4979 | wpa_hexdump_ascii(MSG_DEBUG, " * SSID", | |
4980 | params->ssid, params->ssid_len); | |
a862e4a3 JM |
4981 | if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid)) |
4982 | goto fail; | |
5cc4d64b JM |
4983 | os_memcpy(drv->ssid, params->ssid, params->ssid_len); |
4984 | drv->ssid_len = params->ssid_len; | |
4985 | ||
85e1fad8 JM |
4986 | if (nl80211_put_freq_params(msg, ¶ms->freq) < 0 || |
4987 | nl80211_put_beacon_int(msg, params->beacon_int)) | |
a862e4a3 | 4988 | goto fail; |
5cc4d64b JM |
4989 | |
4990 | ret = nl80211_set_conn_keys(params, msg); | |
4991 | if (ret) | |
a862e4a3 | 4992 | goto fail; |
5cc4d64b | 4993 | |
913e3cf7 NC |
4994 | if (params->bssid && params->fixed_bssid) { |
4995 | wpa_printf(MSG_DEBUG, " * BSSID=" MACSTR, | |
4996 | MAC2STR(params->bssid)); | |
a862e4a3 JM |
4997 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid)) |
4998 | goto fail; | |
913e3cf7 NC |
4999 | } |
5000 | ||
4d9e6fba JD |
5001 | if (params->fixed_freq) { |
5002 | wpa_printf(MSG_DEBUG, " * fixed_freq"); | |
5003 | if (nla_put_flag(msg, NL80211_ATTR_FREQ_FIXED)) | |
5004 | goto fail; | |
5005 | } | |
5006 | ||
4848a38d JM |
5007 | if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X || |
5008 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK || | |
5009 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SHA256 || | |
5010 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256) { | |
e640888c | 5011 | wpa_printf(MSG_DEBUG, " * control port"); |
a862e4a3 JM |
5012 | if (nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT)) |
5013 | goto fail; | |
e640888c AQ |
5014 | } |
5015 | ||
a95795ad JM |
5016 | if (params->wpa_ie) { |
5017 | wpa_hexdump(MSG_DEBUG, | |
5018 | " * Extra IEs for Beacon/Probe Response frames", | |
5019 | params->wpa_ie, params->wpa_ie_len); | |
a862e4a3 JM |
5020 | if (nla_put(msg, NL80211_ATTR_IE, params->wpa_ie_len, |
5021 | params->wpa_ie)) | |
5022 | goto fail; | |
a95795ad JM |
5023 | } |
5024 | ||
e15dcf6d PK |
5025 | ret = nl80211_ht_vht_overrides(msg, params); |
5026 | if (ret < 0) | |
5027 | goto fail; | |
95ff3069 | 5028 | |
5cc4d64b JM |
5029 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
5030 | msg = NULL; | |
5031 | if (ret) { | |
5032 | wpa_printf(MSG_DEBUG, "nl80211: Join IBSS failed: ret=%d (%s)", | |
5033 | ret, strerror(-ret)); | |
5034 | count++; | |
5035 | if (ret == -EALREADY && count == 1) { | |
5036 | wpa_printf(MSG_DEBUG, "nl80211: Retry IBSS join after " | |
5037 | "forced leave"); | |
666e508c | 5038 | nl80211_leave_ibss(drv, 0); |
5cc4d64b JM |
5039 | nlmsg_free(msg); |
5040 | goto retry; | |
5041 | } | |
a862e4a3 JM |
5042 | } else { |
5043 | wpa_printf(MSG_DEBUG, | |
5044 | "nl80211: Join IBSS request sent successfully"); | |
5cc4d64b | 5045 | } |
5cc4d64b | 5046 | |
a862e4a3 | 5047 | fail: |
5cc4d64b JM |
5048 | nlmsg_free(msg); |
5049 | return ret; | |
5050 | } | |
5051 | ||
5052 | ||
a0bdd191 JM |
5053 | static int nl80211_connect_common(struct wpa_driver_nl80211_data *drv, |
5054 | struct wpa_driver_associate_params *params, | |
5055 | struct nl_msg *msg) | |
cfaab580 | 5056 | { |
cfaab580 ZY |
5057 | if (params->bssid) { |
5058 | wpa_printf(MSG_DEBUG, " * bssid=" MACSTR, | |
5059 | MAC2STR(params->bssid)); | |
a862e4a3 JM |
5060 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid)) |
5061 | return -1; | |
cfaab580 | 5062 | } |
a0bdd191 | 5063 | |
7ac7fd43 DS |
5064 | if (params->bssid_hint) { |
5065 | wpa_printf(MSG_DEBUG, " * bssid_hint=" MACSTR, | |
5066 | MAC2STR(params->bssid_hint)); | |
a862e4a3 JM |
5067 | if (nla_put(msg, NL80211_ATTR_MAC_HINT, ETH_ALEN, |
5068 | params->bssid_hint)) | |
5069 | return -1; | |
7ac7fd43 DS |
5070 | } |
5071 | ||
4ec68377 JD |
5072 | if (params->freq.freq) { |
5073 | wpa_printf(MSG_DEBUG, " * freq=%d", params->freq.freq); | |
a862e4a3 JM |
5074 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
5075 | params->freq.freq)) | |
5076 | return -1; | |
4ec68377 | 5077 | drv->assoc_freq = params->freq.freq; |
30158a0d SD |
5078 | } else |
5079 | drv->assoc_freq = 0; | |
a0bdd191 | 5080 | |
7ac7fd43 DS |
5081 | if (params->freq_hint) { |
5082 | wpa_printf(MSG_DEBUG, " * freq_hint=%d", params->freq_hint); | |
a862e4a3 JM |
5083 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ_HINT, |
5084 | params->freq_hint)) | |
5085 | return -1; | |
7ac7fd43 DS |
5086 | } |
5087 | ||
1f6c0ab8 BS |
5088 | if (params->bg_scan_period >= 0) { |
5089 | wpa_printf(MSG_DEBUG, " * bg scan period=%d", | |
5090 | params->bg_scan_period); | |
a862e4a3 JM |
5091 | if (nla_put_u16(msg, NL80211_ATTR_BG_SCAN_PERIOD, |
5092 | params->bg_scan_period)) | |
5093 | return -1; | |
1f6c0ab8 | 5094 | } |
a0bdd191 | 5095 | |
cfaab580 ZY |
5096 | if (params->ssid) { |
5097 | wpa_hexdump_ascii(MSG_DEBUG, " * SSID", | |
5098 | params->ssid, params->ssid_len); | |
a862e4a3 JM |
5099 | if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, |
5100 | params->ssid)) | |
5101 | return -1; | |
cfaab580 | 5102 | if (params->ssid_len > sizeof(drv->ssid)) |
a862e4a3 | 5103 | return -1; |
cfaab580 ZY |
5104 | os_memcpy(drv->ssid, params->ssid, params->ssid_len); |
5105 | drv->ssid_len = params->ssid_len; | |
5106 | } | |
a0bdd191 | 5107 | |
cfaab580 | 5108 | wpa_hexdump(MSG_DEBUG, " * IEs", params->wpa_ie, params->wpa_ie_len); |
a862e4a3 JM |
5109 | if (params->wpa_ie && |
5110 | nla_put(msg, NL80211_ATTR_IE, params->wpa_ie_len, params->wpa_ie)) | |
5111 | return -1; | |
cfaab580 | 5112 | |
64fa840a JM |
5113 | if (params->wpa_proto) { |
5114 | enum nl80211_wpa_versions ver = 0; | |
cfaab580 | 5115 | |
64fa840a JM |
5116 | if (params->wpa_proto & WPA_PROTO_WPA) |
5117 | ver |= NL80211_WPA_VERSION_1; | |
5118 | if (params->wpa_proto & WPA_PROTO_RSN) | |
5119 | ver |= NL80211_WPA_VERSION_2; | |
cfaab580 | 5120 | |
64fa840a | 5121 | wpa_printf(MSG_DEBUG, " * WPA Versions 0x%x", ver); |
a862e4a3 JM |
5122 | if (nla_put_u32(msg, NL80211_ATTR_WPA_VERSIONS, ver)) |
5123 | return -1; | |
cfaab580 ZY |
5124 | } |
5125 | ||
4848a38d | 5126 | if (params->pairwise_suite != WPA_CIPHER_NONE) { |
a0bdd191 JM |
5127 | u32 cipher = wpa_cipher_to_cipher_suite(params->pairwise_suite); |
5128 | wpa_printf(MSG_DEBUG, " * pairwise=0x%x", cipher); | |
a862e4a3 JM |
5129 | if (nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITES_PAIRWISE, |
5130 | cipher)) | |
5131 | return -1; | |
cfaab580 ZY |
5132 | } |
5133 | ||
ae6f9272 JM |
5134 | if (params->group_suite == WPA_CIPHER_GTK_NOT_USED && |
5135 | !(drv->capa.enc & WPA_DRIVER_CAPA_ENC_GTK_NOT_USED)) { | |
5136 | /* | |
5137 | * This is likely to work even though many drivers do not | |
5138 | * advertise support for operations without GTK. | |
5139 | */ | |
5140 | wpa_printf(MSG_DEBUG, " * skip group cipher configuration for GTK_NOT_USED due to missing driver support advertisement"); | |
5141 | } else if (params->group_suite != WPA_CIPHER_NONE) { | |
a0bdd191 JM |
5142 | u32 cipher = wpa_cipher_to_cipher_suite(params->group_suite); |
5143 | wpa_printf(MSG_DEBUG, " * group=0x%x", cipher); | |
a862e4a3 JM |
5144 | if (nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, cipher)) |
5145 | return -1; | |
cfaab580 ZY |
5146 | } |
5147 | ||
4848a38d JM |
5148 | if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X || |
5149 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK || | |
5150 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_IEEE8021X || | |
5151 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_PSK || | |
163f801e | 5152 | params->key_mgmt_suite == WPA_KEY_MGMT_CCKM || |
8802326f JJ |
5153 | params->key_mgmt_suite == WPA_KEY_MGMT_OSEN || |
5154 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SHA256 || | |
666497c8 | 5155 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256 || |
5e3b5197 JM |
5156 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SUITE_B || |
5157 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SUITE_B_192) { | |
cfaab580 ZY |
5158 | int mgmt = WLAN_AKM_SUITE_PSK; |
5159 | ||
5160 | switch (params->key_mgmt_suite) { | |
4848a38d | 5161 | case WPA_KEY_MGMT_CCKM: |
369c8d7b JM |
5162 | mgmt = WLAN_AKM_SUITE_CCKM; |
5163 | break; | |
4848a38d | 5164 | case WPA_KEY_MGMT_IEEE8021X: |
cfaab580 ZY |
5165 | mgmt = WLAN_AKM_SUITE_8021X; |
5166 | break; | |
4848a38d | 5167 | case WPA_KEY_MGMT_FT_IEEE8021X: |
6a1ce395 DG |
5168 | mgmt = WLAN_AKM_SUITE_FT_8021X; |
5169 | break; | |
4848a38d | 5170 | case WPA_KEY_MGMT_FT_PSK: |
6a1ce395 DG |
5171 | mgmt = WLAN_AKM_SUITE_FT_PSK; |
5172 | break; | |
8802326f JJ |
5173 | case WPA_KEY_MGMT_IEEE8021X_SHA256: |
5174 | mgmt = WLAN_AKM_SUITE_8021X_SHA256; | |
5175 | break; | |
5176 | case WPA_KEY_MGMT_PSK_SHA256: | |
5177 | mgmt = WLAN_AKM_SUITE_PSK_SHA256; | |
5178 | break; | |
163f801e JM |
5179 | case WPA_KEY_MGMT_OSEN: |
5180 | mgmt = WLAN_AKM_SUITE_OSEN; | |
5181 | break; | |
666497c8 JM |
5182 | case WPA_KEY_MGMT_IEEE8021X_SUITE_B: |
5183 | mgmt = WLAN_AKM_SUITE_8021X_SUITE_B; | |
5184 | break; | |
5e3b5197 JM |
5185 | case WPA_KEY_MGMT_IEEE8021X_SUITE_B_192: |
5186 | mgmt = WLAN_AKM_SUITE_8021X_SUITE_B_192; | |
5187 | break; | |
4848a38d | 5188 | case WPA_KEY_MGMT_PSK: |
cfaab580 ZY |
5189 | default: |
5190 | mgmt = WLAN_AKM_SUITE_PSK; | |
5191 | break; | |
5192 | } | |
163f801e | 5193 | wpa_printf(MSG_DEBUG, " * akm=0x%x", mgmt); |
a862e4a3 JM |
5194 | if (nla_put_u32(msg, NL80211_ATTR_AKM_SUITES, mgmt)) |
5195 | return -1; | |
cfaab580 ZY |
5196 | } |
5197 | ||
a862e4a3 JM |
5198 | if (nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT)) |
5199 | return -1; | |
a0bdd191 | 5200 | |
e3429c0b JB |
5201 | if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_NO_WPA && |
5202 | (params->pairwise_suite == WPA_CIPHER_NONE || | |
5203 | params->pairwise_suite == WPA_CIPHER_WEP104 || | |
5204 | params->pairwise_suite == WPA_CIPHER_WEP40) && | |
5205 | (nla_put_u16(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE, ETH_P_PAE) || | |
5206 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT))) | |
5207 | return -1; | |
5208 | ||
a862e4a3 JM |
5209 | if (params->mgmt_frame_protection == MGMT_FRAME_PROTECTION_REQUIRED && |
5210 | nla_put_u32(msg, NL80211_ATTR_USE_MFP, NL80211_MFP_REQUIRED)) | |
5211 | return -1; | |
a565084f | 5212 | |
58162adf AK |
5213 | if (params->rrm_used) { |
5214 | u32 drv_rrm_flags = drv->capa.rrm_flags; | |
b5d172e5 BL |
5215 | if ((!((drv_rrm_flags & |
5216 | WPA_DRIVER_FLAGS_DS_PARAM_SET_IE_IN_PROBES) && | |
5217 | (drv_rrm_flags & WPA_DRIVER_FLAGS_QUIET)) && | |
5218 | !(drv_rrm_flags & WPA_DRIVER_FLAGS_SUPPORT_RRM)) || | |
a862e4a3 JM |
5219 | nla_put_flag(msg, NL80211_ATTR_USE_RRM)) |
5220 | return -1; | |
58162adf AK |
5221 | } |
5222 | ||
95ff3069 | 5223 | if (nl80211_ht_vht_overrides(msg, params) < 0) |
a862e4a3 | 5224 | return -1; |
80e8a5ee | 5225 | |
a0bdd191 JM |
5226 | if (params->p2p) |
5227 | wpa_printf(MSG_DEBUG, " * P2P group"); | |
5228 | ||
86b5c400 LD |
5229 | if (params->pbss) { |
5230 | wpa_printf(MSG_DEBUG, " * PBSS"); | |
5231 | if (nla_put_flag(msg, NL80211_ATTR_PBSS)) | |
5232 | return -1; | |
5233 | } | |
5234 | ||
1126c078 | 5235 | drv->connect_reassoc = 0; |
00c3c4ac JM |
5236 | if (params->prev_bssid) { |
5237 | wpa_printf(MSG_DEBUG, " * prev_bssid=" MACSTR, | |
5238 | MAC2STR(params->prev_bssid)); | |
5239 | if (nla_put(msg, NL80211_ATTR_PREV_BSSID, ETH_ALEN, | |
5240 | params->prev_bssid)) | |
5241 | return -1; | |
1126c078 | 5242 | drv->connect_reassoc = 1; |
00c3c4ac JM |
5243 | } |
5244 | ||
a0bdd191 | 5245 | return 0; |
a0bdd191 JM |
5246 | } |
5247 | ||
5248 | ||
5249 | static int wpa_driver_nl80211_try_connect( | |
5250 | struct wpa_driver_nl80211_data *drv, | |
5251 | struct wpa_driver_associate_params *params) | |
5252 | { | |
5253 | struct nl_msg *msg; | |
5254 | enum nl80211_auth_type type; | |
5255 | int ret; | |
5256 | int algs; | |
5257 | ||
b658547d | 5258 | #ifdef CONFIG_DRIVER_NL80211_QCA |
b41f2684 CL |
5259 | if (params->req_key_mgmt_offload && params->psk && |
5260 | (params->key_mgmt_suite == WPA_KEY_MGMT_PSK || | |
5261 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256 || | |
5262 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_PSK)) { | |
5263 | wpa_printf(MSG_DEBUG, "nl80211: Key management set PSK"); | |
5264 | ret = issue_key_mgmt_set_key(drv, params->psk, 32); | |
5265 | if (ret) | |
5266 | return ret; | |
5267 | } | |
b658547d | 5268 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
b41f2684 | 5269 | |
9725b784 JM |
5270 | wpa_printf(MSG_DEBUG, "nl80211: Connect (ifindex=%d)", drv->ifindex); |
5271 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_CONNECT); | |
a0bdd191 JM |
5272 | if (!msg) |
5273 | return -1; | |
5274 | ||
a0bdd191 JM |
5275 | ret = nl80211_connect_common(drv, params, msg); |
5276 | if (ret) | |
a862e4a3 | 5277 | goto fail; |
a0bdd191 JM |
5278 | |
5279 | algs = 0; | |
5280 | if (params->auth_alg & WPA_AUTH_ALG_OPEN) | |
5281 | algs++; | |
5282 | if (params->auth_alg & WPA_AUTH_ALG_SHARED) | |
5283 | algs++; | |
5284 | if (params->auth_alg & WPA_AUTH_ALG_LEAP) | |
5285 | algs++; | |
5286 | if (algs > 1) { | |
5287 | wpa_printf(MSG_DEBUG, " * Leave out Auth Type for automatic " | |
5288 | "selection"); | |
5289 | goto skip_auth_type; | |
5290 | } | |
5291 | ||
5292 | if (params->auth_alg & WPA_AUTH_ALG_OPEN) | |
5293 | type = NL80211_AUTHTYPE_OPEN_SYSTEM; | |
5294 | else if (params->auth_alg & WPA_AUTH_ALG_SHARED) | |
5295 | type = NL80211_AUTHTYPE_SHARED_KEY; | |
5296 | else if (params->auth_alg & WPA_AUTH_ALG_LEAP) | |
5297 | type = NL80211_AUTHTYPE_NETWORK_EAP; | |
5298 | else if (params->auth_alg & WPA_AUTH_ALG_FT) | |
5299 | type = NL80211_AUTHTYPE_FT; | |
5300 | else | |
a862e4a3 | 5301 | goto fail; |
a0bdd191 JM |
5302 | |
5303 | wpa_printf(MSG_DEBUG, " * Auth Type %d", type); | |
a862e4a3 JM |
5304 | if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, type)) |
5305 | goto fail; | |
a0bdd191 JM |
5306 | |
5307 | skip_auth_type: | |
cfaab580 ZY |
5308 | ret = nl80211_set_conn_keys(params, msg); |
5309 | if (ret) | |
a862e4a3 | 5310 | goto fail; |
cfaab580 ZY |
5311 | |
5312 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
5313 | msg = NULL; | |
5314 | if (ret) { | |
5315 | wpa_printf(MSG_DEBUG, "nl80211: MLME connect failed: ret=%d " | |
5316 | "(%s)", ret, strerror(-ret)); | |
a862e4a3 JM |
5317 | } else { |
5318 | wpa_printf(MSG_DEBUG, | |
5319 | "nl80211: Connect request send successfully"); | |
cfaab580 | 5320 | } |
cfaab580 | 5321 | |
a862e4a3 | 5322 | fail: |
cfaab580 ZY |
5323 | nlmsg_free(msg); |
5324 | return ret; | |
5325 | ||
5326 | } | |
5327 | ||
5328 | ||
a8c5b43a CW |
5329 | static int wpa_driver_nl80211_connect( |
5330 | struct wpa_driver_nl80211_data *drv, | |
5331 | struct wpa_driver_associate_params *params) | |
5332 | { | |
0d4e3d1d JJ |
5333 | int ret; |
5334 | ||
5335 | /* Store the connection attempted bssid for future use */ | |
5336 | if (params->bssid) | |
5337 | os_memcpy(drv->auth_attempt_bssid, params->bssid, ETH_ALEN); | |
5338 | else | |
5339 | os_memset(drv->auth_attempt_bssid, 0, ETH_ALEN); | |
5340 | ||
5341 | ret = wpa_driver_nl80211_try_connect(drv, params); | |
a8c5b43a CW |
5342 | if (ret == -EALREADY) { |
5343 | /* | |
5344 | * cfg80211 does not currently accept new connections if | |
5345 | * we are already connected. As a workaround, force | |
5346 | * disconnection and try again. | |
5347 | */ | |
5348 | wpa_printf(MSG_DEBUG, "nl80211: Explicitly " | |
5349 | "disconnecting before reassociation " | |
5350 | "attempt"); | |
5351 | if (wpa_driver_nl80211_disconnect( | |
5352 | drv, WLAN_REASON_PREV_AUTH_NOT_VALID)) | |
5353 | return -1; | |
a8c5b43a CW |
5354 | ret = wpa_driver_nl80211_try_connect(drv, params); |
5355 | } | |
5356 | return ret; | |
5357 | } | |
5358 | ||
5359 | ||
c2a04078 JM |
5360 | static int wpa_driver_nl80211_associate( |
5361 | void *priv, struct wpa_driver_associate_params *params) | |
5362 | { | |
a2e40bb6 FF |
5363 | struct i802_bss *bss = priv; |
5364 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
a862e4a3 | 5365 | int ret = -1; |
c2a04078 JM |
5366 | struct nl_msg *msg; |
5367 | ||
4bd71954 JM |
5368 | nl80211_unmask_11b_rates(bss); |
5369 | ||
5cc4d64b | 5370 | if (params->mode == IEEE80211_MODE_AP) |
1581b38b | 5371 | return wpa_driver_nl80211_ap(drv, params); |
1581b38b | 5372 | |
5cc4d64b JM |
5373 | if (params->mode == IEEE80211_MODE_IBSS) |
5374 | return wpa_driver_nl80211_ibss(drv, params); | |
5375 | ||
4a867032 | 5376 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) { |
b1f625e0 EP |
5377 | enum nl80211_iftype nlmode = params->p2p ? |
5378 | NL80211_IFTYPE_P2P_CLIENT : NL80211_IFTYPE_STATION; | |
5379 | ||
5380 | if (wpa_driver_nl80211_set_mode(priv, nlmode) < 0) | |
4a867032 | 5381 | return -1; |
cfaab580 | 5382 | return wpa_driver_nl80211_connect(drv, params); |
4a867032 | 5383 | } |
cfaab580 | 5384 | |
add9b7a4 | 5385 | nl80211_mark_disconnected(drv); |
c2a04078 | 5386 | |
c2a04078 JM |
5387 | wpa_printf(MSG_DEBUG, "nl80211: Associate (ifindex=%d)", |
5388 | drv->ifindex); | |
9725b784 JM |
5389 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_ASSOCIATE); |
5390 | if (!msg) | |
5391 | return -1; | |
c2a04078 | 5392 | |
a0bdd191 JM |
5393 | ret = nl80211_connect_common(drv, params, msg); |
5394 | if (ret) | |
a862e4a3 | 5395 | goto fail; |
01652550 | 5396 | |
40a45727 JM |
5397 | if (params->fils_kek) { |
5398 | wpa_printf(MSG_DEBUG, " * FILS KEK (len=%u)", | |
5399 | (unsigned int) params->fils_kek_len); | |
5400 | if (nla_put(msg, NL80211_ATTR_FILS_KEK, params->fils_kek_len, | |
5401 | params->fils_kek)) | |
5402 | goto fail; | |
5403 | } | |
5404 | if (params->fils_nonces) { | |
5405 | wpa_hexdump(MSG_DEBUG, " * FILS nonces (for AAD)", | |
5406 | params->fils_nonces, | |
5407 | params->fils_nonces_len); | |
5408 | if (nla_put(msg, NL80211_ATTR_FILS_NONCES, | |
5409 | params->fils_nonces_len, params->fils_nonces)) | |
5410 | goto fail; | |
5411 | } | |
5412 | ||
c2a04078 JM |
5413 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
5414 | msg = NULL; | |
5415 | if (ret) { | |
3b7ea880 BG |
5416 | wpa_dbg(drv->ctx, MSG_DEBUG, |
5417 | "nl80211: MLME command failed (assoc): ret=%d (%s)", | |
5418 | ret, strerror(-ret)); | |
8856462d | 5419 | nl80211_dump_scan(drv); |
a862e4a3 JM |
5420 | } else { |
5421 | wpa_printf(MSG_DEBUG, | |
5422 | "nl80211: Association request send successfully"); | |
c2a04078 | 5423 | } |
c2a04078 | 5424 | |
a862e4a3 | 5425 | fail: |
c2a04078 JM |
5426 | nlmsg_free(msg); |
5427 | return ret; | |
5428 | } | |
3f5285e8 JM |
5429 | |
5430 | ||
ad1e68e6 | 5431 | static int nl80211_set_mode(struct wpa_driver_nl80211_data *drv, |
a1922f93 | 5432 | int ifindex, enum nl80211_iftype mode) |
3f5285e8 | 5433 | { |
3f5285e8 | 5434 | struct nl_msg *msg; |
ad1e68e6 JM |
5435 | int ret = -ENOBUFS; |
5436 | ||
a1922f93 JM |
5437 | wpa_printf(MSG_DEBUG, "nl80211: Set mode ifindex %d iftype %d (%s)", |
5438 | ifindex, mode, nl80211_iftype_str(mode)); | |
5439 | ||
56f77852 JM |
5440 | msg = nl80211_cmd_msg(drv->first_bss, 0, NL80211_CMD_SET_INTERFACE); |
5441 | if (!msg || nla_put_u32(msg, NL80211_ATTR_IFTYPE, mode)) | |
a862e4a3 | 5442 | goto fail; |
ad1e68e6 JM |
5443 | |
5444 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
5883168a | 5445 | msg = NULL; |
ad1e68e6 JM |
5446 | if (!ret) |
5447 | return 0; | |
a862e4a3 | 5448 | fail: |
5883168a | 5449 | nlmsg_free(msg); |
ad1e68e6 JM |
5450 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set interface %d to mode %d:" |
5451 | " %d (%s)", ifindex, mode, ret, strerror(-ret)); | |
5452 | return ret; | |
5453 | } | |
5454 | ||
5455 | ||
3c5d34e3 CW |
5456 | static int wpa_driver_nl80211_set_mode_impl( |
5457 | struct i802_bss *bss, | |
5458 | enum nl80211_iftype nlmode, | |
5459 | struct hostapd_freq_params *desired_freq_params) | |
ad1e68e6 | 5460 | { |
a2e40bb6 | 5461 | struct wpa_driver_nl80211_data *drv = bss->drv; |
ad1e68e6 | 5462 | int ret = -1; |
26af9dca | 5463 | int i; |
86957e62 | 5464 | int was_ap = is_ap_interface(drv->nlmode); |
671a5039 | 5465 | int res; |
ebffdbc4 | 5466 | int mode_switch_res; |
1581b38b | 5467 | |
a5a187b0 JM |
5468 | if (TEST_FAIL()) |
5469 | return -1; | |
5470 | ||
ebffdbc4 CW |
5471 | mode_switch_res = nl80211_set_mode(drv, drv->ifindex, nlmode); |
5472 | if (mode_switch_res && nlmode == nl80211_get_ifmode(bss)) | |
5473 | mode_switch_res = 0; | |
8e12685c | 5474 | |
ebffdbc4 | 5475 | if (mode_switch_res == 0) { |
ad1e68e6 | 5476 | drv->nlmode = nlmode; |
460456f8 JM |
5477 | ret = 0; |
5478 | goto done; | |
ad1e68e6 | 5479 | } |
3f5285e8 | 5480 | |
ebffdbc4 | 5481 | if (mode_switch_res == -ENODEV) |
671a5039 JM |
5482 | return -1; |
5483 | ||
460456f8 | 5484 | if (nlmode == drv->nlmode) { |
c6e8e8e4 JM |
5485 | wpa_printf(MSG_DEBUG, "nl80211: Interface already in " |
5486 | "requested mode - ignore error"); | |
460456f8 JM |
5487 | ret = 0; |
5488 | goto done; /* Already in the requested mode */ | |
5489 | } | |
3f5285e8 | 5490 | |
3f5285e8 JM |
5491 | /* mac80211 doesn't allow mode changes while the device is up, so |
5492 | * take the device down, try to set the mode again, and bring the | |
5493 | * device back up. | |
5494 | */ | |
26af9dca JM |
5495 | wpa_printf(MSG_DEBUG, "nl80211: Try mode change after setting " |
5496 | "interface down"); | |
5497 | for (i = 0; i < 10; i++) { | |
91724d6f | 5498 | res = i802_set_iface_flags(bss, 0); |
6e8183d7 JM |
5499 | if (res == -EACCES || res == -ENODEV) |
5500 | break; | |
ebffdbc4 | 5501 | if (res != 0) { |
26af9dca JM |
5502 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set " |
5503 | "interface down"); | |
ebffdbc4 CW |
5504 | os_sleep(0, 100000); |
5505 | continue; | |
5506 | } | |
3c5d34e3 CW |
5507 | |
5508 | /* | |
5509 | * Setting the mode will fail for some drivers if the phy is | |
5510 | * on a frequency that the mode is disallowed in. | |
5511 | */ | |
5512 | if (desired_freq_params) { | |
bdf5ccb2 | 5513 | res = nl80211_set_channel(bss, desired_freq_params, 0); |
3c5d34e3 CW |
5514 | if (res) { |
5515 | wpa_printf(MSG_DEBUG, | |
5516 | "nl80211: Failed to set frequency on interface"); | |
5517 | } | |
5518 | } | |
5519 | ||
ebffdbc4 CW |
5520 | /* Try to set the mode again while the interface is down */ |
5521 | mode_switch_res = nl80211_set_mode(drv, drv->ifindex, nlmode); | |
5522 | if (mode_switch_res == -EBUSY) { | |
5523 | wpa_printf(MSG_DEBUG, | |
5524 | "nl80211: Delaying mode set while interface going down"); | |
5525 | os_sleep(0, 100000); | |
5526 | continue; | |
5527 | } | |
5528 | ret = mode_switch_res; | |
5529 | break; | |
3f5285e8 JM |
5530 | } |
5531 | ||
c6e8e8e4 JM |
5532 | if (!ret) { |
5533 | wpa_printf(MSG_DEBUG, "nl80211: Mode change succeeded while " | |
5534 | "interface is down"); | |
ad1e68e6 | 5535 | drv->nlmode = nlmode; |
7d9c3698 | 5536 | drv->ignore_if_down_event = 1; |
c6e8e8e4 | 5537 | } |
ad1e68e6 | 5538 | |
ebffdbc4 CW |
5539 | /* Bring the interface back up */ |
5540 | res = linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 1); | |
5541 | if (res != 0) { | |
5542 | wpa_printf(MSG_DEBUG, | |
5543 | "nl80211: Failed to set interface up after switching mode"); | |
5544 | ret = -1; | |
5545 | } | |
5546 | ||
460456f8 | 5547 | done: |
3fd1cefb JB |
5548 | if (ret) { |
5549 | wpa_printf(MSG_DEBUG, "nl80211: Interface mode change to %d " | |
5550 | "from %d failed", nlmode, drv->nlmode); | |
5551 | return ret; | |
5552 | } | |
5553 | ||
3e208481 JM |
5554 | if (is_p2p_net_interface(nlmode)) { |
5555 | wpa_printf(MSG_DEBUG, | |
5556 | "nl80211: Interface %s mode change to P2P - disable 11b rates", | |
5557 | bss->ifname); | |
edb9bfba | 5558 | nl80211_disable_11b_rates(drv, drv->ifindex, 1); |
3e208481 JM |
5559 | } else if (drv->disabled_11b_rates) { |
5560 | wpa_printf(MSG_DEBUG, | |
5561 | "nl80211: Interface %s mode changed to non-P2P - re-enable 11b rates", | |
5562 | bss->ifname); | |
1d0c6fb1 | 5563 | nl80211_disable_11b_rates(drv, drv->ifindex, 0); |
3e208481 | 5564 | } |
edb9bfba | 5565 | |
3fd1cefb | 5566 | if (is_ap_interface(nlmode)) { |
36488c05 | 5567 | nl80211_mgmt_unsubscribe(bss, "start AP"); |
460456f8 | 5568 | /* Setup additional AP mode functionality if needed */ |
3fd1cefb | 5569 | if (nl80211_setup_ap(bss)) |
460456f8 | 5570 | return -1; |
3fd1cefb | 5571 | } else if (was_ap) { |
460456f8 | 5572 | /* Remove additional AP mode functionality */ |
3fd1cefb | 5573 | nl80211_teardown_ap(bss); |
a11241fa | 5574 | } else { |
36488c05 | 5575 | nl80211_mgmt_unsubscribe(bss, "mode change"); |
460456f8 | 5576 | } |
460456f8 | 5577 | |
afb0550a BC |
5578 | if (is_mesh_interface(nlmode) && |
5579 | nl80211_mgmt_subscribe_mesh(bss)) | |
5580 | return -1; | |
5581 | ||
873d0fcf | 5582 | if (!bss->in_deinit && !is_ap_interface(nlmode) && |
afb0550a | 5583 | !is_mesh_interface(nlmode) && |
a11241fa JB |
5584 | nl80211_mgmt_subscribe_non_ap(bss) < 0) |
5585 | wpa_printf(MSG_DEBUG, "nl80211: Failed to register Action " | |
5586 | "frame processing - ignore for now"); | |
08359050 | 5587 | |
3fd1cefb | 5588 | return 0; |
3f5285e8 JM |
5589 | } |
5590 | ||
5591 | ||
f3407c66 JM |
5592 | int wpa_driver_nl80211_set_mode(struct i802_bss *bss, |
5593 | enum nl80211_iftype nlmode) | |
3c5d34e3 CW |
5594 | { |
5595 | return wpa_driver_nl80211_set_mode_impl(bss, nlmode, NULL); | |
5596 | } | |
5597 | ||
5598 | ||
4ec68377 JD |
5599 | static int wpa_driver_nl80211_set_mode_ibss(struct i802_bss *bss, |
5600 | struct hostapd_freq_params *freq) | |
3c5d34e3 | 5601 | { |
3c5d34e3 | 5602 | return wpa_driver_nl80211_set_mode_impl(bss, NL80211_IFTYPE_ADHOC, |
4ec68377 | 5603 | freq); |
3c5d34e3 | 5604 | } |
65d645ce AS |
5605 | |
5606 | ||
3f5285e8 JM |
5607 | static int wpa_driver_nl80211_get_capa(void *priv, |
5608 | struct wpa_driver_capa *capa) | |
5609 | { | |
a2e40bb6 FF |
5610 | struct i802_bss *bss = priv; |
5611 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
65d645ce | 5612 | |
3f5285e8 JM |
5613 | if (!drv->has_capability) |
5614 | return -1; | |
5615 | os_memcpy(capa, &drv->capa, sizeof(*capa)); | |
8cd6b7bc JB |
5616 | if (drv->extended_capa && drv->extended_capa_mask) { |
5617 | capa->extended_capa = drv->extended_capa; | |
5618 | capa->extended_capa_mask = drv->extended_capa_mask; | |
5619 | capa->extended_capa_len = drv->extended_capa_len; | |
5620 | } | |
851b0c55 | 5621 | |
906bc4c7 | 5622 | return 0; |
3f5285e8 JM |
5623 | } |
5624 | ||
5625 | ||
5626 | static int wpa_driver_nl80211_set_operstate(void *priv, int state) | |
5627 | { | |
a2e40bb6 FF |
5628 | struct i802_bss *bss = priv; |
5629 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
3f5285e8 | 5630 | |
90a545cc JM |
5631 | wpa_printf(MSG_DEBUG, "nl80211: Set %s operstate %d->%d (%s)", |
5632 | bss->ifname, drv->operstate, state, | |
5633 | state ? "UP" : "DORMANT"); | |
3f5285e8 | 5634 | drv->operstate = state; |
36d84860 | 5635 | return netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, -1, |
e2d02c29 | 5636 | state ? IF_OPER_UP : IF_OPER_DORMANT); |
3f5285e8 JM |
5637 | } |
5638 | ||
01652550 JM |
5639 | |
5640 | static int wpa_driver_nl80211_set_supp_port(void *priv, int authorized) | |
5641 | { | |
a2e40bb6 FF |
5642 | struct i802_bss *bss = priv; |
5643 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
01652550 JM |
5644 | struct nl_msg *msg; |
5645 | struct nl80211_sta_flag_update upd; | |
a862e4a3 | 5646 | int ret; |
2eef5177 JM |
5647 | |
5648 | if (!drv->associated && is_zero_ether_addr(drv->bssid) && !authorized) { | |
5649 | wpa_printf(MSG_DEBUG, "nl80211: Skip set_supp_port(unauthorized) while not associated"); | |
5650 | return 0; | |
5651 | } | |
01652550 | 5652 | |
1ba51ec0 JM |
5653 | wpa_printf(MSG_DEBUG, "nl80211: Set supplicant port %sauthorized for " |
5654 | MACSTR, authorized ? "" : "un", MAC2STR(drv->bssid)); | |
5655 | ||
01652550 JM |
5656 | os_memset(&upd, 0, sizeof(upd)); |
5657 | upd.mask = BIT(NL80211_STA_FLAG_AUTHORIZED); | |
5658 | if (authorized) | |
5659 | upd.set = BIT(NL80211_STA_FLAG_AUTHORIZED); | |
a862e4a3 | 5660 | |
13f83980 | 5661 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) || |
a862e4a3 JM |
5662 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, drv->bssid) || |
5663 | nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd)) { | |
5664 | nlmsg_free(msg); | |
5665 | return -ENOBUFS; | |
5666 | } | |
01652550 | 5667 | |
2eef5177 | 5668 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
2eef5177 JM |
5669 | if (!ret) |
5670 | return 0; | |
2eef5177 JM |
5671 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set STA flag: %d (%s)", |
5672 | ret, strerror(-ret)); | |
5673 | return ret; | |
01652550 JM |
5674 | } |
5675 | ||
3f5285e8 | 5676 | |
f07ead6a JM |
5677 | /* Set kernel driver on given frequency (MHz) */ |
5678 | static int i802_set_freq(void *priv, struct hostapd_freq_params *freq) | |
c5121837 | 5679 | { |
f07ead6a | 5680 | struct i802_bss *bss = priv; |
13a524a3 | 5681 | return nl80211_set_channel(bss, freq, 0); |
c5121837 JM |
5682 | } |
5683 | ||
f7b3920c | 5684 | |
c5121837 JM |
5685 | static inline int min_int(int a, int b) |
5686 | { | |
5687 | if (a < b) | |
5688 | return a; | |
5689 | return b; | |
5690 | } | |
5691 | ||
5692 | ||
5693 | static int get_key_handler(struct nl_msg *msg, void *arg) | |
5694 | { | |
5695 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
5696 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
5697 | ||
5698 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
5699 | genlmsg_attrlen(gnlh, 0), NULL); | |
5700 | ||
5701 | /* | |
5702 | * TODO: validate the key index and mac address! | |
5703 | * Otherwise, there's a race condition as soon as | |
5704 | * the kernel starts sending key notifications. | |
5705 | */ | |
5706 | ||
5707 | if (tb[NL80211_ATTR_KEY_SEQ]) | |
5708 | memcpy(arg, nla_data(tb[NL80211_ATTR_KEY_SEQ]), | |
5709 | min_int(nla_len(tb[NL80211_ATTR_KEY_SEQ]), 6)); | |
5710 | return NL_SKIP; | |
5711 | } | |
5712 | ||
5713 | ||
5714 | static int i802_get_seqnum(const char *iface, void *priv, const u8 *addr, | |
5715 | int idx, u8 *seq) | |
5716 | { | |
a2e40bb6 FF |
5717 | struct i802_bss *bss = priv; |
5718 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
c5121837 JM |
5719 | struct nl_msg *msg; |
5720 | ||
95376e1a JM |
5721 | msg = nl80211_ifindex_msg(drv, if_nametoindex(iface), 0, |
5722 | NL80211_CMD_GET_KEY); | |
5723 | if (!msg || | |
a862e4a3 | 5724 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
95376e1a | 5725 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, idx)) { |
a862e4a3 JM |
5726 | nlmsg_free(msg); |
5727 | return -ENOBUFS; | |
5728 | } | |
c5121837 JM |
5729 | |
5730 | memset(seq, 0, 6); | |
5731 | ||
5732 | return send_and_recv_msgs(drv, msg, get_key_handler, seq); | |
c5121837 JM |
5733 | } |
5734 | ||
5735 | ||
c5121837 JM |
5736 | static int i802_set_rts(void *priv, int rts) |
5737 | { | |
a2e40bb6 FF |
5738 | struct i802_bss *bss = priv; |
5739 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
ad649451 | 5740 | struct nl_msg *msg; |
a862e4a3 | 5741 | int ret; |
ad649451 | 5742 | u32 val; |
c5121837 | 5743 | |
ad649451 JM |
5744 | if (rts >= 2347) |
5745 | val = (u32) -1; | |
5746 | else | |
5747 | val = rts; | |
c5121837 | 5748 | |
9725b784 | 5749 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_WIPHY)) || |
a862e4a3 JM |
5750 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, val)) { |
5751 | nlmsg_free(msg); | |
5752 | return -ENOBUFS; | |
5753 | } | |
ad649451 JM |
5754 | |
5755 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
5756 | if (!ret) | |
5757 | return 0; | |
ad649451 JM |
5758 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set RTS threshold %d: " |
5759 | "%d (%s)", rts, ret, strerror(-ret)); | |
5760 | return ret; | |
c5121837 JM |
5761 | } |
5762 | ||
5763 | ||
5764 | static int i802_set_frag(void *priv, int frag) | |
5765 | { | |
a2e40bb6 FF |
5766 | struct i802_bss *bss = priv; |
5767 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
ad649451 | 5768 | struct nl_msg *msg; |
a862e4a3 | 5769 | int ret; |
ad649451 | 5770 | u32 val; |
c5121837 | 5771 | |
ad649451 JM |
5772 | if (frag >= 2346) |
5773 | val = (u32) -1; | |
5774 | else | |
5775 | val = frag; | |
c5121837 | 5776 | |
9725b784 | 5777 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_WIPHY)) || |
a862e4a3 JM |
5778 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, val)) { |
5779 | nlmsg_free(msg); | |
5780 | return -ENOBUFS; | |
5781 | } | |
ad649451 JM |
5782 | |
5783 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
5784 | if (!ret) | |
5785 | return 0; | |
ad649451 JM |
5786 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set fragmentation threshold " |
5787 | "%d: %d (%s)", frag, ret, strerror(-ret)); | |
5788 | return ret; | |
c5121837 JM |
5789 | } |
5790 | ||
5791 | ||
c5121837 JM |
5792 | static int i802_flush(void *priv) |
5793 | { | |
a2e40bb6 | 5794 | struct i802_bss *bss = priv; |
c5121837 | 5795 | struct nl_msg *msg; |
82554b10 | 5796 | int res; |
c5121837 | 5797 | |
83e7bb0e JM |
5798 | wpa_printf(MSG_DEBUG, "nl80211: flush -> DEL_STATION %s (all)", |
5799 | bss->ifname); | |
c5121837 JM |
5800 | |
5801 | /* | |
5802 | * XXX: FIX! this needs to flush all VLANs too | |
5803 | */ | |
13f83980 JM |
5804 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_DEL_STATION); |
5805 | res = send_and_recv_msgs(bss->drv, msg, NULL, NULL); | |
82554b10 JM |
5806 | if (res) { |
5807 | wpa_printf(MSG_DEBUG, "nl80211: Station flush failed: ret=%d " | |
5808 | "(%s)", res, strerror(-res)); | |
5809 | } | |
5810 | return res; | |
c5121837 JM |
5811 | } |
5812 | ||
5813 | ||
5814 | static int get_sta_handler(struct nl_msg *msg, void *arg) | |
5815 | { | |
5816 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
5817 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
5818 | struct hostap_sta_driver_data *data = arg; | |
5819 | struct nlattr *stats[NL80211_STA_INFO_MAX + 1]; | |
5820 | static struct nla_policy stats_policy[NL80211_STA_INFO_MAX + 1] = { | |
5821 | [NL80211_STA_INFO_INACTIVE_TIME] = { .type = NLA_U32 }, | |
5822 | [NL80211_STA_INFO_RX_BYTES] = { .type = NLA_U32 }, | |
5823 | [NL80211_STA_INFO_TX_BYTES] = { .type = NLA_U32 }, | |
5824 | [NL80211_STA_INFO_RX_PACKETS] = { .type = NLA_U32 }, | |
5825 | [NL80211_STA_INFO_TX_PACKETS] = { .type = NLA_U32 }, | |
dc7785f8 | 5826 | [NL80211_STA_INFO_TX_FAILED] = { .type = NLA_U32 }, |
43022abd NL |
5827 | [NL80211_STA_INFO_RX_BYTES64] = { .type = NLA_U64 }, |
5828 | [NL80211_STA_INFO_TX_BYTES64] = { .type = NLA_U64 }, | |
c5121837 JM |
5829 | }; |
5830 | ||
5831 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
5832 | genlmsg_attrlen(gnlh, 0), NULL); | |
5833 | ||
5834 | /* | |
5835 | * TODO: validate the interface and mac address! | |
5836 | * Otherwise, there's a race condition as soon as | |
5837 | * the kernel starts sending station notifications. | |
5838 | */ | |
5839 | ||
5840 | if (!tb[NL80211_ATTR_STA_INFO]) { | |
5841 | wpa_printf(MSG_DEBUG, "sta stats missing!"); | |
5842 | return NL_SKIP; | |
5843 | } | |
5844 | if (nla_parse_nested(stats, NL80211_STA_INFO_MAX, | |
5845 | tb[NL80211_ATTR_STA_INFO], | |
5846 | stats_policy)) { | |
5847 | wpa_printf(MSG_DEBUG, "failed to parse nested attributes!"); | |
5848 | return NL_SKIP; | |
5849 | } | |
5850 | ||
5851 | if (stats[NL80211_STA_INFO_INACTIVE_TIME]) | |
5852 | data->inactive_msec = | |
5853 | nla_get_u32(stats[NL80211_STA_INFO_INACTIVE_TIME]); | |
43022abd | 5854 | /* For backwards compatibility, fetch the 32-bit counters first. */ |
c5121837 JM |
5855 | if (stats[NL80211_STA_INFO_RX_BYTES]) |
5856 | data->rx_bytes = nla_get_u32(stats[NL80211_STA_INFO_RX_BYTES]); | |
5857 | if (stats[NL80211_STA_INFO_TX_BYTES]) | |
5858 | data->tx_bytes = nla_get_u32(stats[NL80211_STA_INFO_TX_BYTES]); | |
43022abd NL |
5859 | if (stats[NL80211_STA_INFO_RX_BYTES64] && |
5860 | stats[NL80211_STA_INFO_TX_BYTES64]) { | |
5861 | /* | |
5862 | * The driver supports 64-bit counters, so use them to override | |
5863 | * the 32-bit values. | |
5864 | */ | |
5865 | data->rx_bytes = | |
5866 | nla_get_u64(stats[NL80211_STA_INFO_RX_BYTES64]); | |
5867 | data->tx_bytes = | |
5868 | nla_get_u64(stats[NL80211_STA_INFO_TX_BYTES64]); | |
5869 | data->bytes_64bit = 1; | |
5870 | } | |
c5121837 JM |
5871 | if (stats[NL80211_STA_INFO_RX_PACKETS]) |
5872 | data->rx_packets = | |
5873 | nla_get_u32(stats[NL80211_STA_INFO_RX_PACKETS]); | |
5874 | if (stats[NL80211_STA_INFO_TX_PACKETS]) | |
5875 | data->tx_packets = | |
5876 | nla_get_u32(stats[NL80211_STA_INFO_TX_PACKETS]); | |
dc7785f8 YZ |
5877 | if (stats[NL80211_STA_INFO_TX_FAILED]) |
5878 | data->tx_retry_failed = | |
5879 | nla_get_u32(stats[NL80211_STA_INFO_TX_FAILED]); | |
c5121837 JM |
5880 | |
5881 | return NL_SKIP; | |
5882 | } | |
5883 | ||
9ebce9c5 JM |
5884 | static int i802_read_sta_data(struct i802_bss *bss, |
5885 | struct hostap_sta_driver_data *data, | |
c5121837 JM |
5886 | const u8 *addr) |
5887 | { | |
c5121837 JM |
5888 | struct nl_msg *msg; |
5889 | ||
13f83980 JM |
5890 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_GET_STATION)) || |
5891 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { | |
a862e4a3 JM |
5892 | nlmsg_free(msg); |
5893 | return -ENOBUFS; | |
5894 | } | |
c5121837 | 5895 | |
13f83980 | 5896 | return send_and_recv_msgs(bss->drv, msg, get_sta_handler, data); |
c5121837 JM |
5897 | } |
5898 | ||
5899 | ||
c5121837 JM |
5900 | static int i802_set_tx_queue_params(void *priv, int queue, int aifs, |
5901 | int cw_min, int cw_max, int burst_time) | |
5902 | { | |
a2e40bb6 FF |
5903 | struct i802_bss *bss = priv; |
5904 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
c5121837 JM |
5905 | struct nl_msg *msg; |
5906 | struct nlattr *txq, *params; | |
5907 | ||
13f83980 | 5908 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_WIPHY); |
c5121837 JM |
5909 | if (!msg) |
5910 | return -1; | |
5911 | ||
c5121837 JM |
5912 | txq = nla_nest_start(msg, NL80211_ATTR_WIPHY_TXQ_PARAMS); |
5913 | if (!txq) | |
a862e4a3 | 5914 | goto fail; |
c5121837 JM |
5915 | |
5916 | /* We are only sending parameters for a single TXQ at a time */ | |
5917 | params = nla_nest_start(msg, 1); | |
5918 | if (!params) | |
a862e4a3 | 5919 | goto fail; |
c5121837 | 5920 | |
7e3c1781 JM |
5921 | switch (queue) { |
5922 | case 0: | |
a862e4a3 JM |
5923 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_VO)) |
5924 | goto fail; | |
7e3c1781 JM |
5925 | break; |
5926 | case 1: | |
a862e4a3 JM |
5927 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_VI)) |
5928 | goto fail; | |
7e3c1781 JM |
5929 | break; |
5930 | case 2: | |
a862e4a3 JM |
5931 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_BE)) |
5932 | goto fail; | |
7e3c1781 JM |
5933 | break; |
5934 | case 3: | |
a862e4a3 JM |
5935 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_BK)) |
5936 | goto fail; | |
7e3c1781 JM |
5937 | break; |
5938 | } | |
c5121837 JM |
5939 | /* Burst time is configured in units of 0.1 msec and TXOP parameter in |
5940 | * 32 usec, so need to convert the value here. */ | |
a862e4a3 JM |
5941 | if (nla_put_u16(msg, NL80211_TXQ_ATTR_TXOP, |
5942 | (burst_time * 100 + 16) / 32) || | |
5943 | nla_put_u16(msg, NL80211_TXQ_ATTR_CWMIN, cw_min) || | |
5944 | nla_put_u16(msg, NL80211_TXQ_ATTR_CWMAX, cw_max) || | |
5945 | nla_put_u8(msg, NL80211_TXQ_ATTR_AIFS, aifs)) | |
5946 | goto fail; | |
c5121837 JM |
5947 | |
5948 | nla_nest_end(msg, params); | |
5949 | ||
5950 | nla_nest_end(msg, txq); | |
5951 | ||
5952 | if (send_and_recv_msgs(drv, msg, NULL, NULL) == 0) | |
5953 | return 0; | |
9e088e74 | 5954 | msg = NULL; |
a862e4a3 | 5955 | fail: |
9e088e74 | 5956 | nlmsg_free(msg); |
c5121837 JM |
5957 | return -1; |
5958 | } | |
5959 | ||
5960 | ||
9ebce9c5 | 5961 | static int i802_set_sta_vlan(struct i802_bss *bss, const u8 *addr, |
c5121837 JM |
5962 | const char *ifname, int vlan_id) |
5963 | { | |
a2e40bb6 | 5964 | struct wpa_driver_nl80211_data *drv = bss->drv; |
c5121837 | 5965 | struct nl_msg *msg; |
a862e4a3 | 5966 | int ret; |
c5121837 | 5967 | |
bbc706a3 JM |
5968 | wpa_printf(MSG_DEBUG, "nl80211: %s[%d]: set_sta_vlan(" MACSTR |
5969 | ", ifname=%s[%d], vlan_id=%d)", | |
5970 | bss->ifname, if_nametoindex(bss->ifname), | |
5971 | MAC2STR(addr), ifname, if_nametoindex(ifname), vlan_id); | |
13f83980 | 5972 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) || |
a862e4a3 JM |
5973 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
5974 | nla_put_u32(msg, NL80211_ATTR_STA_VLAN, if_nametoindex(ifname))) { | |
5975 | nlmsg_free(msg); | |
5976 | return -ENOBUFS; | |
5977 | } | |
c5121837 | 5978 | |
cd1d72c1 JM |
5979 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
5980 | if (ret < 0) { | |
5981 | wpa_printf(MSG_ERROR, "nl80211: NL80211_ATTR_STA_VLAN (addr=" | |
5982 | MACSTR " ifname=%s vlan_id=%d) failed: %d (%s)", | |
5983 | MAC2STR(addr), ifname, vlan_id, ret, | |
5984 | strerror(-ret)); | |
5985 | } | |
cd1d72c1 | 5986 | return ret; |
c5121837 JM |
5987 | } |
5988 | ||
fbbfcbac | 5989 | |
c5121837 JM |
5990 | static int i802_get_inact_sec(void *priv, const u8 *addr) |
5991 | { | |
5992 | struct hostap_sta_driver_data data; | |
5993 | int ret; | |
5994 | ||
7824bf77 | 5995 | os_memset(&data, 0, sizeof(data)); |
c5121837 JM |
5996 | data.inactive_msec = (unsigned long) -1; |
5997 | ret = i802_read_sta_data(priv, &data, addr); | |
b9749bac MH |
5998 | if (ret == -ENOENT) |
5999 | return -ENOENT; | |
c5121837 JM |
6000 | if (ret || data.inactive_msec == (unsigned long) -1) |
6001 | return -1; | |
6002 | return data.inactive_msec / 1000; | |
6003 | } | |
6004 | ||
6005 | ||
6006 | static int i802_sta_clear_stats(void *priv, const u8 *addr) | |
6007 | { | |
6008 | #if 0 | |
6009 | /* TODO */ | |
6010 | #endif | |
6011 | return 0; | |
6012 | } | |
6013 | ||
6014 | ||
731723a5 JM |
6015 | static int i802_sta_deauth(void *priv, const u8 *own_addr, const u8 *addr, |
6016 | int reason) | |
c5121837 | 6017 | { |
a2e40bb6 | 6018 | struct i802_bss *bss = priv; |
e1bd4e19 | 6019 | struct wpa_driver_nl80211_data *drv = bss->drv; |
c5121837 | 6020 | struct ieee80211_mgmt mgmt; |
05e5e615 DL |
6021 | u8 channel; |
6022 | ||
6023 | if (ieee80211_freq_to_chan(bss->freq, &channel) == | |
6024 | HOSTAPD_MODE_IEEE80211AD) { | |
6025 | /* Deauthentication is not used in DMG/IEEE 802.11ad; | |
6026 | * disassociate the STA instead. */ | |
6027 | return i802_sta_disassoc(priv, own_addr, addr, reason); | |
6028 | } | |
c5121837 | 6029 | |
0d391b03 BC |
6030 | if (is_mesh_interface(drv->nlmode)) |
6031 | return -1; | |
6032 | ||
e1bd4e19 | 6033 | if (drv->device_ap_sme) |
59d7148a | 6034 | return wpa_driver_nl80211_sta_remove(bss, addr, 1, reason); |
e1bd4e19 | 6035 | |
c5121837 JM |
6036 | memset(&mgmt, 0, sizeof(mgmt)); |
6037 | mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, | |
6038 | WLAN_FC_STYPE_DEAUTH); | |
6039 | memcpy(mgmt.da, addr, ETH_ALEN); | |
731723a5 JM |
6040 | memcpy(mgmt.sa, own_addr, ETH_ALEN); |
6041 | memcpy(mgmt.bssid, own_addr, ETH_ALEN); | |
c5121837 | 6042 | mgmt.u.deauth.reason_code = host_to_le16(reason); |
a2e40bb6 | 6043 | return wpa_driver_nl80211_send_mlme(bss, (u8 *) &mgmt, |
9f324b61 | 6044 | IEEE80211_HDRLEN + |
9ebce9c5 | 6045 | sizeof(mgmt.u.deauth), 0, 0, 0, 0, |
2d3943ce | 6046 | 0, NULL, 0); |
c5121837 JM |
6047 | } |
6048 | ||
6049 | ||
731723a5 JM |
6050 | static int i802_sta_disassoc(void *priv, const u8 *own_addr, const u8 *addr, |
6051 | int reason) | |
c5121837 | 6052 | { |
a2e40bb6 | 6053 | struct i802_bss *bss = priv; |
e1bd4e19 | 6054 | struct wpa_driver_nl80211_data *drv = bss->drv; |
c5121837 JM |
6055 | struct ieee80211_mgmt mgmt; |
6056 | ||
0d391b03 BC |
6057 | if (is_mesh_interface(drv->nlmode)) |
6058 | return -1; | |
6059 | ||
e1bd4e19 | 6060 | if (drv->device_ap_sme) |
59d7148a | 6061 | return wpa_driver_nl80211_sta_remove(bss, addr, 0, reason); |
e1bd4e19 | 6062 | |
c5121837 JM |
6063 | memset(&mgmt, 0, sizeof(mgmt)); |
6064 | mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, | |
6065 | WLAN_FC_STYPE_DISASSOC); | |
6066 | memcpy(mgmt.da, addr, ETH_ALEN); | |
731723a5 JM |
6067 | memcpy(mgmt.sa, own_addr, ETH_ALEN); |
6068 | memcpy(mgmt.bssid, own_addr, ETH_ALEN); | |
c5121837 | 6069 | mgmt.u.disassoc.reason_code = host_to_le16(reason); |
a2e40bb6 | 6070 | return wpa_driver_nl80211_send_mlme(bss, (u8 *) &mgmt, |
9f324b61 | 6071 | IEEE80211_HDRLEN + |
9ebce9c5 | 6072 | sizeof(mgmt.u.disassoc), 0, 0, 0, 0, |
2d3943ce | 6073 | 0, NULL, 0); |
c5121837 JM |
6074 | } |
6075 | ||
6076 | ||
9b4d9c8b JM |
6077 | static void dump_ifidx(struct wpa_driver_nl80211_data *drv) |
6078 | { | |
6079 | char buf[200], *pos, *end; | |
6080 | int i, res; | |
6081 | ||
6082 | pos = buf; | |
6083 | end = pos + sizeof(buf); | |
6084 | ||
6085 | for (i = 0; i < drv->num_if_indices; i++) { | |
6086 | if (!drv->if_indices[i]) | |
6087 | continue; | |
732b1d20 MB |
6088 | res = os_snprintf(pos, end - pos, " %d(%d)", |
6089 | drv->if_indices[i], | |
6090 | drv->if_indices_reason[i]); | |
d85e1fc8 | 6091 | if (os_snprintf_error(end - pos, res)) |
9b4d9c8b JM |
6092 | break; |
6093 | pos += res; | |
6094 | } | |
6095 | *pos = '\0'; | |
6096 | ||
6097 | wpa_printf(MSG_DEBUG, "nl80211: if_indices[%d]:%s", | |
6098 | drv->num_if_indices, buf); | |
6099 | } | |
6100 | ||
6101 | ||
732b1d20 MB |
6102 | static void add_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, |
6103 | int ifidx_reason) | |
f07ead6a JM |
6104 | { |
6105 | int i; | |
732b1d20 | 6106 | int *old, *old_reason; |
f07ead6a | 6107 | |
732b1d20 MB |
6108 | wpa_printf(MSG_DEBUG, |
6109 | "nl80211: Add own interface ifindex %d (ifidx_reason %d)", | |
6110 | ifidx, ifidx_reason); | |
6111 | if (have_ifidx(drv, ifidx, ifidx_reason)) { | |
b36935be MB |
6112 | wpa_printf(MSG_DEBUG, "nl80211: ifindex %d already in the list", |
6113 | ifidx); | |
6114 | return; | |
6115 | } | |
f07ead6a JM |
6116 | for (i = 0; i < drv->num_if_indices; i++) { |
6117 | if (drv->if_indices[i] == 0) { | |
6118 | drv->if_indices[i] = ifidx; | |
732b1d20 | 6119 | drv->if_indices_reason[i] = ifidx_reason; |
9b4d9c8b | 6120 | dump_ifidx(drv); |
f07ead6a JM |
6121 | return; |
6122 | } | |
6123 | } | |
6124 | ||
6125 | if (drv->if_indices != drv->default_if_indices) | |
6126 | old = drv->if_indices; | |
6127 | else | |
6128 | old = NULL; | |
6129 | ||
732b1d20 MB |
6130 | if (drv->if_indices_reason != drv->default_if_indices_reason) |
6131 | old_reason = drv->if_indices_reason; | |
6132 | else | |
6133 | old_reason = NULL; | |
6134 | ||
067ffa26 JM |
6135 | drv->if_indices = os_realloc_array(old, drv->num_if_indices + 1, |
6136 | sizeof(int)); | |
732b1d20 MB |
6137 | drv->if_indices_reason = os_realloc_array(old_reason, |
6138 | drv->num_if_indices + 1, | |
6139 | sizeof(int)); | |
f07ead6a JM |
6140 | if (!drv->if_indices) { |
6141 | if (!old) | |
6142 | drv->if_indices = drv->default_if_indices; | |
6143 | else | |
6144 | drv->if_indices = old; | |
732b1d20 MB |
6145 | } |
6146 | if (!drv->if_indices_reason) { | |
6147 | if (!old_reason) | |
6148 | drv->if_indices_reason = drv->default_if_indices_reason; | |
6149 | else | |
29eddc3d | 6150 | drv->if_indices_reason = old_reason; |
732b1d20 MB |
6151 | } |
6152 | if (!drv->if_indices || !drv->if_indices_reason) { | |
f07ead6a JM |
6153 | wpa_printf(MSG_ERROR, "Failed to reallocate memory for " |
6154 | "interfaces"); | |
6155 | wpa_printf(MSG_ERROR, "Ignoring EAPOL on interface %d", ifidx); | |
6156 | return; | |
732b1d20 MB |
6157 | } |
6158 | if (!old) | |
f07ead6a JM |
6159 | os_memcpy(drv->if_indices, drv->default_if_indices, |
6160 | sizeof(drv->default_if_indices)); | |
732b1d20 MB |
6161 | if (!old_reason) |
6162 | os_memcpy(drv->if_indices_reason, | |
6163 | drv->default_if_indices_reason, | |
6164 | sizeof(drv->default_if_indices_reason)); | |
f07ead6a | 6165 | drv->if_indices[drv->num_if_indices] = ifidx; |
732b1d20 | 6166 | drv->if_indices_reason[drv->num_if_indices] = ifidx_reason; |
f07ead6a | 6167 | drv->num_if_indices++; |
9b4d9c8b | 6168 | dump_ifidx(drv); |
f07ead6a JM |
6169 | } |
6170 | ||
6171 | ||
732b1d20 MB |
6172 | static void del_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, |
6173 | int ifidx_reason) | |
f07ead6a JM |
6174 | { |
6175 | int i; | |
6176 | ||
6177 | for (i = 0; i < drv->num_if_indices; i++) { | |
732b1d20 MB |
6178 | if ((drv->if_indices[i] == ifidx || ifidx == IFIDX_ANY) && |
6179 | (drv->if_indices_reason[i] == ifidx_reason || | |
6180 | ifidx_reason == IFIDX_ANY)) { | |
f07ead6a JM |
6181 | drv->if_indices[i] = 0; |
6182 | break; | |
6183 | } | |
6184 | } | |
9b4d9c8b | 6185 | dump_ifidx(drv); |
f07ead6a JM |
6186 | } |
6187 | ||
6188 | ||
732b1d20 MB |
6189 | static int have_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, |
6190 | int ifidx_reason) | |
f07ead6a JM |
6191 | { |
6192 | int i; | |
6193 | ||
6194 | for (i = 0; i < drv->num_if_indices; i++) | |
732b1d20 MB |
6195 | if (drv->if_indices[i] == ifidx && |
6196 | (drv->if_indices_reason[i] == ifidx_reason || | |
6197 | ifidx_reason == IFIDX_ANY)) | |
f07ead6a JM |
6198 | return 1; |
6199 | ||
6200 | return 0; | |
6201 | } | |
6202 | ||
6203 | ||
6204 | static int i802_set_wds_sta(void *priv, const u8 *addr, int aid, int val, | |
0e80ea2c | 6205 | const char *bridge_ifname, char *ifname_wds) |
f07ead6a JM |
6206 | { |
6207 | struct i802_bss *bss = priv; | |
6208 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
6209 | char name[IFNAMSIZ + 1]; | |
6210 | ||
6211 | os_snprintf(name, sizeof(name), "%s.sta%d", bss->ifname, aid); | |
69dd2967 SM |
6212 | if (ifname_wds) |
6213 | os_strlcpy(ifname_wds, name, IFNAMSIZ + 1); | |
6214 | ||
f07ead6a JM |
6215 | wpa_printf(MSG_DEBUG, "nl80211: Set WDS STA addr=" MACSTR |
6216 | " aid=%d val=%d name=%s", MAC2STR(addr), aid, val, name); | |
6217 | if (val) { | |
6218 | if (!if_nametoindex(name)) { | |
6219 | if (nl80211_create_iface(drv, name, | |
6220 | NL80211_IFTYPE_AP_VLAN, | |
2aec4f3c JM |
6221 | bss->addr, 1, NULL, NULL, 0) < |
6222 | 0) | |
f07ead6a JM |
6223 | return -1; |
6224 | if (bridge_ifname && | |
c81eff1a BG |
6225 | linux_br_add_if(drv->global->ioctl_sock, |
6226 | bridge_ifname, name) < 0) | |
f07ead6a JM |
6227 | return -1; |
6228 | } | |
75227f3a JM |
6229 | if (linux_set_iface_flags(drv->global->ioctl_sock, name, 1)) { |
6230 | wpa_printf(MSG_ERROR, "nl80211: Failed to set WDS STA " | |
6231 | "interface %s up", name); | |
6232 | } | |
f07ead6a JM |
6233 | return i802_set_sta_vlan(priv, addr, name, 0); |
6234 | } else { | |
c34e618d FF |
6235 | if (bridge_ifname) |
6236 | linux_br_del_if(drv->global->ioctl_sock, bridge_ifname, | |
6237 | name); | |
6238 | ||
f07ead6a | 6239 | i802_set_sta_vlan(priv, addr, bss->ifname, 0); |
d0595b25 FF |
6240 | nl80211_remove_iface(drv, if_nametoindex(name)); |
6241 | return 0; | |
f07ead6a JM |
6242 | } |
6243 | } | |
6244 | ||
6245 | ||
6246 | static void handle_eapol(int sock, void *eloop_ctx, void *sock_ctx) | |
6247 | { | |
6248 | struct wpa_driver_nl80211_data *drv = eloop_ctx; | |
6249 | struct sockaddr_ll lladdr; | |
6250 | unsigned char buf[3000]; | |
6251 | int len; | |
6252 | socklen_t fromlen = sizeof(lladdr); | |
6253 | ||
6254 | len = recvfrom(sock, buf, sizeof(buf), 0, | |
6255 | (struct sockaddr *)&lladdr, &fromlen); | |
6256 | if (len < 0) { | |
7ac3616d JM |
6257 | wpa_printf(MSG_ERROR, "nl80211: EAPOL recv failed: %s", |
6258 | strerror(errno)); | |
f07ead6a JM |
6259 | return; |
6260 | } | |
6261 | ||
732b1d20 | 6262 | if (have_ifidx(drv, lladdr.sll_ifindex, IFIDX_ANY)) |
f07ead6a JM |
6263 | drv_event_eapol_rx(drv->ctx, lladdr.sll_addr, buf, len); |
6264 | } | |
6265 | ||
6266 | ||
94627f6c | 6267 | static int i802_check_bridge(struct wpa_driver_nl80211_data *drv, |
e17a2477 | 6268 | struct i802_bss *bss, |
94627f6c JM |
6269 | const char *brname, const char *ifname) |
6270 | { | |
6c6678e7 | 6271 | int br_ifindex; |
94627f6c JM |
6272 | char in_br[IFNAMSIZ]; |
6273 | ||
e17a2477 | 6274 | os_strlcpy(bss->brname, brname, IFNAMSIZ); |
6c6678e7 | 6275 | br_ifindex = if_nametoindex(brname); |
6c6678e7 | 6276 | if (br_ifindex == 0) { |
94627f6c JM |
6277 | /* |
6278 | * Bridge was configured, but the bridge device does | |
6279 | * not exist. Try to add it now. | |
6280 | */ | |
c81eff1a | 6281 | if (linux_br_add(drv->global->ioctl_sock, brname) < 0) { |
94627f6c JM |
6282 | wpa_printf(MSG_ERROR, "nl80211: Failed to add the " |
6283 | "bridge interface %s: %s", | |
6284 | brname, strerror(errno)); | |
6285 | return -1; | |
6286 | } | |
e17a2477 | 6287 | bss->added_bridge = 1; |
8997613c | 6288 | br_ifindex = if_nametoindex(brname); |
732b1d20 | 6289 | add_ifidx(drv, br_ifindex, drv->ifindex); |
94627f6c | 6290 | } |
8997613c | 6291 | bss->br_ifindex = br_ifindex; |
94627f6c JM |
6292 | |
6293 | if (linux_br_get(in_br, ifname) == 0) { | |
6294 | if (os_strcmp(in_br, brname) == 0) | |
6295 | return 0; /* already in the bridge */ | |
6296 | ||
6297 | wpa_printf(MSG_DEBUG, "nl80211: Removing interface %s from " | |
6298 | "bridge %s", ifname, in_br); | |
c81eff1a BG |
6299 | if (linux_br_del_if(drv->global->ioctl_sock, in_br, ifname) < |
6300 | 0) { | |
94627f6c JM |
6301 | wpa_printf(MSG_ERROR, "nl80211: Failed to " |
6302 | "remove interface %s from bridge " | |
6303 | "%s: %s", | |
6304 | ifname, brname, strerror(errno)); | |
6305 | return -1; | |
6306 | } | |
6307 | } | |
6308 | ||
6309 | wpa_printf(MSG_DEBUG, "nl80211: Adding interface %s into bridge %s", | |
6310 | ifname, brname); | |
c81eff1a | 6311 | if (linux_br_add_if(drv->global->ioctl_sock, brname, ifname) < 0) { |
94627f6c JM |
6312 | wpa_printf(MSG_ERROR, "nl80211: Failed to add interface %s " |
6313 | "into bridge %s: %s", | |
6314 | ifname, brname, strerror(errno)); | |
6315 | return -1; | |
6316 | } | |
e17a2477 | 6317 | bss->added_if_into_bridge = 1; |
94627f6c JM |
6318 | |
6319 | return 0; | |
6320 | } | |
6321 | ||
6322 | ||
92f475b4 JM |
6323 | static void *i802_init(struct hostapd_data *hapd, |
6324 | struct wpa_init_params *params) | |
c5121837 JM |
6325 | { |
6326 | struct wpa_driver_nl80211_data *drv; | |
a2e40bb6 | 6327 | struct i802_bss *bss; |
c5121837 | 6328 | size_t i; |
cb05808c AN |
6329 | char master_ifname[IFNAMSIZ]; |
6330 | int ifindex, br_ifindex = 0; | |
94627f6c | 6331 | int br_added = 0; |
c5121837 | 6332 | |
0d547d5f JM |
6333 | bss = wpa_driver_nl80211_drv_init(hapd, params->ifname, |
6334 | params->global_priv, 1, | |
0ecff8d7 | 6335 | params->bssid, params->driver_params); |
a2e40bb6 | 6336 | if (bss == NULL) |
c5121837 | 6337 | return NULL; |
c5121837 | 6338 | |
a2e40bb6 | 6339 | drv = bss->drv; |
7635bfb0 | 6340 | |
cb05808c | 6341 | if (linux_br_get(master_ifname, params->ifname) == 0) { |
94627f6c | 6342 | wpa_printf(MSG_DEBUG, "nl80211: Interface %s is in bridge %s", |
cb05808c AN |
6343 | params->ifname, master_ifname); |
6344 | br_ifindex = if_nametoindex(master_ifname); | |
6345 | os_strlcpy(bss->brname, master_ifname, IFNAMSIZ); | |
6346 | } else if ((params->num_bridge == 0 || !params->bridge[0]) && | |
6347 | linux_master_get(master_ifname, params->ifname) == 0) { | |
6348 | wpa_printf(MSG_DEBUG, "nl80211: Interface %s is in master %s", | |
6349 | params->ifname, master_ifname); | |
6350 | /* start listening for EAPOL on the master interface */ | |
732b1d20 | 6351 | add_ifidx(drv, if_nametoindex(master_ifname), drv->ifindex); |
f2d6c17a DL |
6352 | |
6353 | /* check if master itself is under bridge */ | |
6354 | if (linux_br_get(master_ifname, master_ifname) == 0) { | |
6355 | wpa_printf(MSG_DEBUG, "nl80211: which is in bridge %s", | |
6356 | master_ifname); | |
6357 | br_ifindex = if_nametoindex(master_ifname); | |
6358 | os_strlcpy(bss->brname, master_ifname, IFNAMSIZ); | |
6359 | } | |
94627f6c | 6360 | } else { |
cb05808c | 6361 | master_ifname[0] = '\0'; |
94627f6c | 6362 | } |
cb05808c | 6363 | |
6c6678e7 | 6364 | bss->br_ifindex = br_ifindex; |
94627f6c | 6365 | |
92f475b4 | 6366 | for (i = 0; i < params->num_bridge; i++) { |
94627f6c JM |
6367 | if (params->bridge[i]) { |
6368 | ifindex = if_nametoindex(params->bridge[i]); | |
6369 | if (ifindex) | |
732b1d20 | 6370 | add_ifidx(drv, ifindex, drv->ifindex); |
94627f6c JM |
6371 | if (ifindex == br_ifindex) |
6372 | br_added = 1; | |
6373 | } | |
c5121837 | 6374 | } |
c5121837 | 6375 | |
ad1e68e6 | 6376 | /* start listening for EAPOL on the default AP interface */ |
732b1d20 | 6377 | add_ifidx(drv, drv->ifindex, IFIDX_ANY); |
ad1e68e6 | 6378 | |
5ef8e39f JM |
6379 | if (params->num_bridge && params->bridge[0]) { |
6380 | if (i802_check_bridge(drv, bss, params->bridge[0], | |
6381 | params->ifname) < 0) | |
6382 | goto failed; | |
cb05808c | 6383 | if (os_strcmp(params->bridge[0], master_ifname) != 0) |
5ef8e39f JM |
6384 | br_added = 1; |
6385 | } | |
6386 | ||
6387 | if (!br_added && br_ifindex && | |
6388 | (params->num_bridge == 0 || !params->bridge[0])) | |
732b1d20 | 6389 | add_ifidx(drv, br_ifindex, drv->ifindex); |
94627f6c | 6390 | |
97ed9a06 KP |
6391 | #ifdef CONFIG_LIBNL3_ROUTE |
6392 | if (bss->added_if_into_bridge) { | |
6393 | drv->rtnl_sk = nl_socket_alloc(); | |
6394 | if (drv->rtnl_sk == NULL) { | |
6395 | wpa_printf(MSG_ERROR, "nl80211: Failed to allocate nl_sock"); | |
6396 | goto failed; | |
6397 | } | |
6398 | ||
6399 | if (nl_connect(drv->rtnl_sk, NETLINK_ROUTE)) { | |
6400 | wpa_printf(MSG_ERROR, "nl80211: Failed to connect nl_sock to NETLINK_ROUTE: %s", | |
6401 | strerror(errno)); | |
6402 | goto failed; | |
6403 | } | |
6404 | } | |
6405 | #endif /* CONFIG_LIBNL3_ROUTE */ | |
6406 | ||
ad1e68e6 JM |
6407 | drv->eapol_sock = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_PAE)); |
6408 | if (drv->eapol_sock < 0) { | |
7ac3616d JM |
6409 | wpa_printf(MSG_ERROR, "nl80211: socket(PF_PACKET, SOCK_DGRAM, ETH_P_PAE) failed: %s", |
6410 | strerror(errno)); | |
bbaf0837 | 6411 | goto failed; |
ad1e68e6 JM |
6412 | } |
6413 | ||
6414 | if (eloop_register_read_sock(drv->eapol_sock, handle_eapol, drv, NULL)) | |
6415 | { | |
7ac3616d | 6416 | wpa_printf(MSG_INFO, "nl80211: Could not register read socket for eapol"); |
c5121837 | 6417 | goto failed; |
ad1e68e6 JM |
6418 | } |
6419 | ||
c81eff1a BG |
6420 | if (linux_get_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
6421 | params->own_addr)) | |
bbaf0837 | 6422 | goto failed; |
fee354c7 | 6423 | os_memcpy(drv->perm_addr, params->own_addr, ETH_ALEN); |
c5121837 | 6424 | |
341eebee JB |
6425 | memcpy(bss->addr, params->own_addr, ETH_ALEN); |
6426 | ||
a2e40bb6 | 6427 | return bss; |
c5121837 JM |
6428 | |
6429 | failed: | |
7635bfb0 | 6430 | wpa_driver_nl80211_deinit(bss); |
bbaf0837 JM |
6431 | return NULL; |
6432 | } | |
c5121837 | 6433 | |
c5121837 | 6434 | |
bbaf0837 JM |
6435 | static void i802_deinit(void *priv) |
6436 | { | |
9ebce9c5 JM |
6437 | struct i802_bss *bss = priv; |
6438 | wpa_driver_nl80211_deinit(bss); | |
c5121837 JM |
6439 | } |
6440 | ||
c5121837 | 6441 | |
22a7c9d7 JM |
6442 | static enum nl80211_iftype wpa_driver_nl80211_if_type( |
6443 | enum wpa_driver_if_type type) | |
6444 | { | |
6445 | switch (type) { | |
6446 | case WPA_IF_STATION: | |
9f51b113 | 6447 | return NL80211_IFTYPE_STATION; |
75bde05d JM |
6448 | case WPA_IF_P2P_CLIENT: |
6449 | case WPA_IF_P2P_GROUP: | |
9f51b113 | 6450 | return NL80211_IFTYPE_P2P_CLIENT; |
22a7c9d7 JM |
6451 | case WPA_IF_AP_VLAN: |
6452 | return NL80211_IFTYPE_AP_VLAN; | |
6453 | case WPA_IF_AP_BSS: | |
6454 | return NL80211_IFTYPE_AP; | |
9f51b113 JB |
6455 | case WPA_IF_P2P_GO: |
6456 | return NL80211_IFTYPE_P2P_GO; | |
7aad838c NS |
6457 | case WPA_IF_P2P_DEVICE: |
6458 | return NL80211_IFTYPE_P2P_DEVICE; | |
5b78493f MH |
6459 | case WPA_IF_MESH: |
6460 | return NL80211_IFTYPE_MESH_POINT; | |
98342208 AK |
6461 | default: |
6462 | return -1; | |
22a7c9d7 | 6463 | } |
22a7c9d7 JM |
6464 | } |
6465 | ||
6466 | ||
f2ed8023 JM |
6467 | static int nl80211_addr_in_use(struct nl80211_global *global, const u8 *addr) |
6468 | { | |
6469 | struct wpa_driver_nl80211_data *drv; | |
6470 | dl_list_for_each(drv, &global->interfaces, | |
6471 | struct wpa_driver_nl80211_data, list) { | |
834ee56f | 6472 | if (os_memcmp(addr, drv->first_bss->addr, ETH_ALEN) == 0) |
f2ed8023 JM |
6473 | return 1; |
6474 | } | |
6475 | return 0; | |
6476 | } | |
6477 | ||
6478 | ||
5b78493f | 6479 | static int nl80211_vif_addr(struct wpa_driver_nl80211_data *drv, u8 *new_addr) |
f2ed8023 JM |
6480 | { |
6481 | unsigned int idx; | |
6482 | ||
6483 | if (!drv->global) | |
6484 | return -1; | |
6485 | ||
834ee56f | 6486 | os_memcpy(new_addr, drv->first_bss->addr, ETH_ALEN); |
f2ed8023 | 6487 | for (idx = 0; idx < 64; idx++) { |
834ee56f | 6488 | new_addr[0] = drv->first_bss->addr[0] | 0x02; |
f2ed8023 JM |
6489 | new_addr[0] ^= idx << 2; |
6490 | if (!nl80211_addr_in_use(drv->global, new_addr)) | |
6491 | break; | |
6492 | } | |
6493 | if (idx == 64) | |
6494 | return -1; | |
6495 | ||
5b78493f | 6496 | wpa_printf(MSG_DEBUG, "nl80211: Assigned new virtual interface address " |
f2ed8023 JM |
6497 | MACSTR, MAC2STR(new_addr)); |
6498 | ||
6499 | return 0; | |
6500 | } | |
6501 | ||
6502 | ||
f632e483 AS |
6503 | struct wdev_info { |
6504 | u64 wdev_id; | |
6505 | int wdev_id_set; | |
6506 | u8 macaddr[ETH_ALEN]; | |
6507 | }; | |
6508 | ||
6509 | static int nl80211_wdev_handler(struct nl_msg *msg, void *arg) | |
e472e1b4 AS |
6510 | { |
6511 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
6512 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
f632e483 | 6513 | struct wdev_info *wi = arg; |
e472e1b4 AS |
6514 | |
6515 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
6516 | genlmsg_attrlen(gnlh, 0), NULL); | |
6517 | if (tb[NL80211_ATTR_WDEV]) { | |
f632e483 AS |
6518 | wi->wdev_id = nla_get_u64(tb[NL80211_ATTR_WDEV]); |
6519 | wi->wdev_id_set = 1; | |
e472e1b4 AS |
6520 | } |
6521 | ||
6522 | if (tb[NL80211_ATTR_MAC]) | |
f632e483 | 6523 | os_memcpy(wi->macaddr, nla_data(tb[NL80211_ATTR_MAC]), |
e472e1b4 AS |
6524 | ETH_ALEN); |
6525 | ||
6526 | return NL_SKIP; | |
6527 | } | |
6528 | ||
6529 | ||
7ab68865 | 6530 | static int wpa_driver_nl80211_if_add(void *priv, enum wpa_driver_if_type type, |
8043e725 | 6531 | const char *ifname, const u8 *addr, |
f3585c8a | 6532 | void *bss_ctx, void **drv_priv, |
e17a2477 | 6533 | char *force_ifname, u8 *if_addr, |
d8a3b66d AS |
6534 | const char *bridge, int use_existing, |
6535 | int setup_ap) | |
22a7c9d7 | 6536 | { |
e472e1b4 | 6537 | enum nl80211_iftype nlmode; |
a2e40bb6 FF |
6538 | struct i802_bss *bss = priv; |
6539 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
22a7c9d7 | 6540 | int ifidx; |
2aec4f3c | 6541 | int added = 1; |
22a7c9d7 | 6542 | |
f3585c8a JM |
6543 | if (addr) |
6544 | os_memcpy(if_addr, addr, ETH_ALEN); | |
e472e1b4 AS |
6545 | nlmode = wpa_driver_nl80211_if_type(type); |
6546 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) { | |
f632e483 AS |
6547 | struct wdev_info p2pdev_info; |
6548 | ||
6549 | os_memset(&p2pdev_info, 0, sizeof(p2pdev_info)); | |
e472e1b4 | 6550 | ifidx = nl80211_create_iface(drv, ifname, nlmode, addr, |
f632e483 | 6551 | 0, nl80211_wdev_handler, |
2aec4f3c | 6552 | &p2pdev_info, use_existing); |
f632e483 | 6553 | if (!p2pdev_info.wdev_id_set || ifidx != 0) { |
e472e1b4 AS |
6554 | wpa_printf(MSG_ERROR, "nl80211: Failed to create a P2P Device interface %s", |
6555 | ifname); | |
e472e1b4 AS |
6556 | return -1; |
6557 | } | |
f632e483 AS |
6558 | |
6559 | drv->global->if_add_wdevid = p2pdev_info.wdev_id; | |
6560 | drv->global->if_add_wdevid_set = p2pdev_info.wdev_id_set; | |
6561 | if (!is_zero_ether_addr(p2pdev_info.macaddr)) | |
6562 | os_memcpy(if_addr, p2pdev_info.macaddr, ETH_ALEN); | |
6563 | wpa_printf(MSG_DEBUG, "nl80211: New P2P Device interface %s (0x%llx) created", | |
6564 | ifname, | |
6565 | (long long unsigned int) p2pdev_info.wdev_id); | |
e472e1b4 AS |
6566 | } else { |
6567 | ifidx = nl80211_create_iface(drv, ifname, nlmode, addr, | |
2aec4f3c JM |
6568 | 0, NULL, NULL, use_existing); |
6569 | if (use_existing && ifidx == -ENFILE) { | |
6570 | added = 0; | |
6571 | ifidx = if_nametoindex(ifname); | |
6572 | } else if (ifidx < 0) { | |
e472e1b4 AS |
6573 | return -1; |
6574 | } | |
22a7c9d7 JM |
6575 | } |
6576 | ||
ab7a1add | 6577 | if (!addr) { |
8ea8a89c | 6578 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) |
ab7a1add AS |
6579 | os_memcpy(if_addr, bss->addr, ETH_ALEN); |
6580 | else if (linux_get_ifhwaddr(drv->global->ioctl_sock, | |
8ea8a89c | 6581 | ifname, if_addr) < 0) { |
2aec4f3c JM |
6582 | if (added) |
6583 | nl80211_remove_iface(drv, ifidx); | |
ab7a1add AS |
6584 | return -1; |
6585 | } | |
c55f774d JM |
6586 | } |
6587 | ||
c55f774d JM |
6588 | if (!addr && |
6589 | (type == WPA_IF_P2P_CLIENT || type == WPA_IF_P2P_GROUP || | |
8ea8a89c JM |
6590 | type == WPA_IF_P2P_GO || type == WPA_IF_MESH || |
6591 | type == WPA_IF_STATION)) { | |
6592 | /* Enforce unique address */ | |
ab7a1add | 6593 | u8 new_addr[ETH_ALEN]; |
c55f774d | 6594 | |
ab7a1add | 6595 | if (linux_get_ifhwaddr(drv->global->ioctl_sock, ifname, |
c81eff1a | 6596 | new_addr) < 0) { |
ea39367c MK |
6597 | if (added) |
6598 | nl80211_remove_iface(drv, ifidx); | |
c55f774d JM |
6599 | return -1; |
6600 | } | |
f608081c | 6601 | if (nl80211_addr_in_use(drv->global, new_addr)) { |
c55f774d | 6602 | wpa_printf(MSG_DEBUG, "nl80211: Allocate new address " |
8ea8a89c | 6603 | "for interface %s type %d", ifname, type); |
5b78493f | 6604 | if (nl80211_vif_addr(drv, new_addr) < 0) { |
ea39367c MK |
6605 | if (added) |
6606 | nl80211_remove_iface(drv, ifidx); | |
c55f774d JM |
6607 | return -1; |
6608 | } | |
c81eff1a | 6609 | if (linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, |
c55f774d | 6610 | new_addr) < 0) { |
ea39367c MK |
6611 | if (added) |
6612 | nl80211_remove_iface(drv, ifidx); | |
c55f774d JM |
6613 | return -1; |
6614 | } | |
c55f774d | 6615 | } |
f67eeb5c | 6616 | os_memcpy(if_addr, new_addr, ETH_ALEN); |
c55f774d | 6617 | } |
f3585c8a | 6618 | |
d8a3b66d | 6619 | if (type == WPA_IF_AP_BSS && setup_ap) { |
f5eb9da3 JM |
6620 | struct i802_bss *new_bss = os_zalloc(sizeof(*new_bss)); |
6621 | if (new_bss == NULL) { | |
2aec4f3c JM |
6622 | if (added) |
6623 | nl80211_remove_iface(drv, ifidx); | |
f5eb9da3 JM |
6624 | return -1; |
6625 | } | |
6626 | ||
6627 | if (bridge && | |
6628 | i802_check_bridge(drv, new_bss, bridge, ifname) < 0) { | |
6629 | wpa_printf(MSG_ERROR, "nl80211: Failed to add the new " | |
6630 | "interface %s to a bridge %s", | |
6631 | ifname, bridge); | |
2aec4f3c JM |
6632 | if (added) |
6633 | nl80211_remove_iface(drv, ifidx); | |
f5eb9da3 JM |
6634 | os_free(new_bss); |
6635 | return -1; | |
6636 | } | |
6637 | ||
c81eff1a BG |
6638 | if (linux_set_iface_flags(drv->global->ioctl_sock, ifname, 1)) |
6639 | { | |
ea39367c MK |
6640 | if (added) |
6641 | nl80211_remove_iface(drv, ifidx); | |
07179987 | 6642 | os_free(new_bss); |
22a7c9d7 JM |
6643 | return -1; |
6644 | } | |
a2e40bb6 | 6645 | os_strlcpy(new_bss->ifname, ifname, IFNAMSIZ); |
341eebee | 6646 | os_memcpy(new_bss->addr, if_addr, ETH_ALEN); |
a2e40bb6 FF |
6647 | new_bss->ifindex = ifidx; |
6648 | new_bss->drv = drv; | |
834ee56f KP |
6649 | new_bss->next = drv->first_bss->next; |
6650 | new_bss->freq = drv->first_bss->freq; | |
a5e1eb20 | 6651 | new_bss->ctx = bss_ctx; |
2aec4f3c | 6652 | new_bss->added_if = added; |
834ee56f | 6653 | drv->first_bss->next = new_bss; |
a2e40bb6 FF |
6654 | if (drv_priv) |
6655 | *drv_priv = new_bss; | |
cc7a48d1 | 6656 | nl80211_init_bss(new_bss); |
3dd1d890 YAP |
6657 | |
6658 | /* Subscribe management frames for this WPA_IF_AP_BSS */ | |
6659 | if (nl80211_setup_ap(new_bss)) | |
6660 | return -1; | |
22a7c9d7 | 6661 | } |
22a7c9d7 | 6662 | |
ff6a158b JM |
6663 | if (drv->global) |
6664 | drv->global->if_add_ifindex = ifidx; | |
6665 | ||
d1bb7aed JJ |
6666 | /* |
6667 | * Some virtual interfaces need to process EAPOL packets and events on | |
6668 | * the parent interface. This is used mainly with hostapd. | |
6669 | */ | |
6670 | if (ifidx > 0 && | |
6671 | (drv->hostapd || | |
6672 | nlmode == NL80211_IFTYPE_AP_VLAN || | |
6673 | nlmode == NL80211_IFTYPE_WDS || | |
6674 | nlmode == NL80211_IFTYPE_MONITOR)) | |
732b1d20 | 6675 | add_ifidx(drv, ifidx, IFIDX_ANY); |
b36935be | 6676 | |
22a7c9d7 JM |
6677 | return 0; |
6678 | } | |
6679 | ||
6680 | ||
9ebce9c5 | 6681 | static int wpa_driver_nl80211_if_remove(struct i802_bss *bss, |
22a7c9d7 JM |
6682 | enum wpa_driver_if_type type, |
6683 | const char *ifname) | |
6684 | { | |
a2e40bb6 | 6685 | struct wpa_driver_nl80211_data *drv = bss->drv; |
22a7c9d7 JM |
6686 | int ifindex = if_nametoindex(ifname); |
6687 | ||
2aec4f3c JM |
6688 | wpa_printf(MSG_DEBUG, "nl80211: %s(type=%d ifname=%s) ifindex=%d added_if=%d", |
6689 | __func__, type, ifname, ifindex, bss->added_if); | |
158b090c | 6690 | if (ifindex > 0 && (bss->added_if || bss->ifindex != ifindex)) |
2b72df63 | 6691 | nl80211_remove_iface(drv, ifindex); |
de884303 JM |
6692 | else if (ifindex > 0 && !bss->added_if) { |
6693 | struct wpa_driver_nl80211_data *drv2; | |
6694 | dl_list_for_each(drv2, &drv->global->interfaces, | |
732b1d20 MB |
6695 | struct wpa_driver_nl80211_data, list) { |
6696 | del_ifidx(drv2, ifindex, IFIDX_ANY); | |
6697 | del_ifidx(drv2, IFIDX_ANY, ifindex); | |
6698 | } | |
de884303 | 6699 | } |
c34e618d | 6700 | |
c34e618d FF |
6701 | if (type != WPA_IF_AP_BSS) |
6702 | return 0; | |
6703 | ||
e17a2477 | 6704 | if (bss->added_if_into_bridge) { |
c81eff1a BG |
6705 | if (linux_br_del_if(drv->global->ioctl_sock, bss->brname, |
6706 | bss->ifname) < 0) | |
e17a2477 JM |
6707 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
6708 | "interface %s from bridge %s: %s", | |
6709 | bss->ifname, bss->brname, strerror(errno)); | |
6710 | } | |
6711 | if (bss->added_bridge) { | |
c81eff1a | 6712 | if (linux_br_del(drv->global->ioctl_sock, bss->brname) < 0) |
e17a2477 JM |
6713 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
6714 | "bridge %s: %s", | |
6715 | bss->brname, strerror(errno)); | |
6716 | } | |
a2e40bb6 | 6717 | |
834ee56f | 6718 | if (bss != drv->first_bss) { |
8546ea19 | 6719 | struct i802_bss *tbss; |
a2e40bb6 | 6720 | |
2aec4f3c | 6721 | wpa_printf(MSG_DEBUG, "nl80211: Not the first BSS - remove it"); |
834ee56f | 6722 | for (tbss = drv->first_bss; tbss; tbss = tbss->next) { |
8546ea19 JM |
6723 | if (tbss->next == bss) { |
6724 | tbss->next = bss->next; | |
3dd1d890 YAP |
6725 | /* Unsubscribe management frames */ |
6726 | nl80211_teardown_ap(bss); | |
cc7a48d1 | 6727 | nl80211_destroy_bss(bss); |
5c9da160 MB |
6728 | if (!bss->added_if) |
6729 | i802_set_iface_flags(bss, 0); | |
8546ea19 JM |
6730 | os_free(bss); |
6731 | bss = NULL; | |
6732 | break; | |
6733 | } | |
22a7c9d7 | 6734 | } |
8546ea19 JM |
6735 | if (bss) |
6736 | wpa_printf(MSG_INFO, "nl80211: %s - could not find " | |
6737 | "BSS %p in the list", __func__, bss); | |
390e489c | 6738 | } else { |
2aec4f3c | 6739 | wpa_printf(MSG_DEBUG, "nl80211: First BSS - reassign context"); |
390e489c | 6740 | nl80211_teardown_ap(bss); |
2aec4f3c JM |
6741 | if (!bss->added_if && !drv->first_bss->next) |
6742 | wpa_driver_nl80211_del_beacon(drv); | |
390e489c | 6743 | nl80211_destroy_bss(bss); |
2aec4f3c JM |
6744 | if (!bss->added_if) |
6745 | i802_set_iface_flags(bss, 0); | |
390e489c KP |
6746 | if (drv->first_bss->next) { |
6747 | drv->first_bss = drv->first_bss->next; | |
6748 | drv->ctx = drv->first_bss->ctx; | |
6749 | os_free(bss); | |
6750 | } else { | |
6751 | wpa_printf(MSG_DEBUG, "nl80211: No second BSS to reassign context to"); | |
6752 | } | |
22a7c9d7 | 6753 | } |
22a7c9d7 JM |
6754 | |
6755 | return 0; | |
6756 | } | |
6757 | ||
6758 | ||
55777702 JM |
6759 | static int cookie_handler(struct nl_msg *msg, void *arg) |
6760 | { | |
6761 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
6762 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
6763 | u64 *cookie = arg; | |
6764 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
6765 | genlmsg_attrlen(gnlh, 0), NULL); | |
6766 | if (tb[NL80211_ATTR_COOKIE]) | |
6767 | *cookie = nla_get_u64(tb[NL80211_ATTR_COOKIE]); | |
6768 | return NL_SKIP; | |
6769 | } | |
6770 | ||
6771 | ||
88df0ef7 | 6772 | static int nl80211_send_frame_cmd(struct i802_bss *bss, |
5dfca53f JB |
6773 | unsigned int freq, unsigned int wait, |
6774 | const u8 *buf, size_t buf_len, | |
88df0ef7 | 6775 | u64 *cookie_out, int no_cck, int no_ack, |
2d3943ce AO |
6776 | int offchanok, const u16 *csa_offs, |
6777 | size_t csa_offs_len) | |
9884f9cc | 6778 | { |
88df0ef7 | 6779 | struct wpa_driver_nl80211_data *drv = bss->drv; |
9884f9cc JB |
6780 | struct nl_msg *msg; |
6781 | u64 cookie; | |
6782 | int ret = -1; | |
6783 | ||
cc2ada86 | 6784 | wpa_printf(MSG_MSGDUMP, "nl80211: CMD_FRAME freq=%u wait=%u no_cck=%d " |
2e3e4566 JM |
6785 | "no_ack=%d offchanok=%d", |
6786 | freq, wait, no_cck, no_ack, offchanok); | |
c91f796f | 6787 | wpa_hexdump(MSG_MSGDUMP, "CMD_FRAME", buf, buf_len); |
9884f9cc | 6788 | |
56f77852 | 6789 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_FRAME)) || |
a862e4a3 JM |
6790 | (freq && nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || |
6791 | (wait && nla_put_u32(msg, NL80211_ATTR_DURATION, wait)) || | |
6792 | (offchanok && ((drv->capa.flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX) || | |
6793 | drv->test_use_roc_tx) && | |
6794 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) || | |
6795 | (no_cck && nla_put_flag(msg, NL80211_ATTR_TX_NO_CCK_RATE)) || | |
6796 | (no_ack && nla_put_flag(msg, NL80211_ATTR_DONT_WAIT_FOR_ACK)) || | |
2d3943ce AO |
6797 | (csa_offs && nla_put(msg, NL80211_ATTR_CSA_C_OFFSETS_TX, |
6798 | csa_offs_len * sizeof(u16), csa_offs)) || | |
a862e4a3 JM |
6799 | nla_put(msg, NL80211_ATTR_FRAME, buf_len, buf)) |
6800 | goto fail; | |
9884f9cc JB |
6801 | |
6802 | cookie = 0; | |
6803 | ret = send_and_recv_msgs(drv, msg, cookie_handler, &cookie); | |
6804 | msg = NULL; | |
6805 | if (ret) { | |
6806 | wpa_printf(MSG_DEBUG, "nl80211: Frame command failed: ret=%d " | |
a05225c8 JM |
6807 | "(%s) (freq=%u wait=%u)", ret, strerror(-ret), |
6808 | freq, wait); | |
a862e4a3 JM |
6809 | } else { |
6810 | wpa_printf(MSG_MSGDUMP, "nl80211: Frame TX command accepted%s; " | |
6811 | "cookie 0x%llx", no_ack ? " (no ACK)" : "", | |
6812 | (long long unsigned int) cookie); | |
9884f9cc | 6813 | |
a862e4a3 JM |
6814 | if (cookie_out) |
6815 | *cookie_out = no_ack ? (u64) -1 : cookie; | |
759a8a3a JM |
6816 | |
6817 | if (drv->num_send_action_cookies == MAX_SEND_ACTION_COOKIES) { | |
6818 | wpa_printf(MSG_DEBUG, | |
6819 | "nl80211: Drop oldest pending send action cookie 0x%llx", | |
6820 | (long long unsigned int) | |
6821 | drv->send_action_cookies[0]); | |
6822 | os_memmove(&drv->send_action_cookies[0], | |
6823 | &drv->send_action_cookies[1], | |
6824 | (MAX_SEND_ACTION_COOKIES - 1) * | |
6825 | sizeof(u64)); | |
6826 | drv->num_send_action_cookies--; | |
6827 | } | |
6828 | drv->send_action_cookies[drv->num_send_action_cookies] = cookie; | |
6829 | drv->num_send_action_cookies++; | |
a862e4a3 | 6830 | } |
9884f9cc | 6831 | |
a862e4a3 | 6832 | fail: |
9884f9cc JB |
6833 | nlmsg_free(msg); |
6834 | return ret; | |
6835 | } | |
6836 | ||
6837 | ||
9ebce9c5 JM |
6838 | static int wpa_driver_nl80211_send_action(struct i802_bss *bss, |
6839 | unsigned int freq, | |
190b9062 | 6840 | unsigned int wait_time, |
58f6fbe0 JM |
6841 | const u8 *dst, const u8 *src, |
6842 | const u8 *bssid, | |
b106173a JM |
6843 | const u8 *data, size_t data_len, |
6844 | int no_cck) | |
58f6fbe0 | 6845 | { |
a2e40bb6 | 6846 | struct wpa_driver_nl80211_data *drv = bss->drv; |
58f6fbe0 | 6847 | int ret = -1; |
58f6fbe0 JM |
6848 | u8 *buf; |
6849 | struct ieee80211_hdr *hdr; | |
58f6fbe0 | 6850 | |
5dfca53f | 6851 | wpa_printf(MSG_DEBUG, "nl80211: Send Action frame (ifindex=%d, " |
55231068 JM |
6852 | "freq=%u MHz wait=%d ms no_cck=%d)", |
6853 | drv->ifindex, freq, wait_time, no_cck); | |
58f6fbe0 JM |
6854 | |
6855 | buf = os_zalloc(24 + data_len); | |
6856 | if (buf == NULL) | |
6857 | return ret; | |
6858 | os_memcpy(buf + 24, data, data_len); | |
6859 | hdr = (struct ieee80211_hdr *) buf; | |
6860 | hdr->frame_control = | |
6861 | IEEE80211_FC(WLAN_FC_TYPE_MGMT, WLAN_FC_STYPE_ACTION); | |
6862 | os_memcpy(hdr->addr1, dst, ETH_ALEN); | |
6863 | os_memcpy(hdr->addr2, src, ETH_ALEN); | |
6864 | os_memcpy(hdr->addr3, bssid, ETH_ALEN); | |
6865 | ||
f78f2785 JM |
6866 | if (is_ap_interface(drv->nlmode) && |
6867 | (!(drv->capa.flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX) || | |
6868 | (int) freq == bss->freq || drv->device_ap_sme || | |
6869 | !drv->use_monitor)) | |
9ebce9c5 JM |
6870 | ret = wpa_driver_nl80211_send_mlme(bss, buf, 24 + data_len, |
6871 | 0, freq, no_cck, 1, | |
2d3943ce | 6872 | wait_time, NULL, 0); |
9884f9cc | 6873 | else |
88df0ef7 | 6874 | ret = nl80211_send_frame_cmd(bss, freq, wait_time, buf, |
5dfca53f | 6875 | 24 + data_len, |
b106173a | 6876 | &drv->send_action_cookie, |
2d3943ce | 6877 | no_cck, 0, 1, NULL, 0); |
58f6fbe0 | 6878 | |
f8bf1421 | 6879 | os_free(buf); |
58f6fbe0 JM |
6880 | return ret; |
6881 | } | |
6882 | ||
6883 | ||
759a8a3a | 6884 | static void nl80211_frame_wait_cancel(struct i802_bss *bss, u64 cookie) |
5dfca53f | 6885 | { |
5dfca53f JB |
6886 | struct wpa_driver_nl80211_data *drv = bss->drv; |
6887 | struct nl_msg *msg; | |
6888 | int ret; | |
6889 | ||
316a9e4d | 6890 | wpa_printf(MSG_DEBUG, "nl80211: Cancel TX frame wait: cookie=0x%llx", |
759a8a3a | 6891 | (long long unsigned int) cookie); |
56f77852 | 6892 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_FRAME_WAIT_CANCEL)) || |
759a8a3a | 6893 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) { |
a862e4a3 JM |
6894 | nlmsg_free(msg); |
6895 | return; | |
6896 | } | |
5dfca53f JB |
6897 | |
6898 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
5dfca53f JB |
6899 | if (ret) |
6900 | wpa_printf(MSG_DEBUG, "nl80211: wait cancel failed: ret=%d " | |
6901 | "(%s)", ret, strerror(-ret)); | |
5dfca53f JB |
6902 | } |
6903 | ||
6904 | ||
759a8a3a JM |
6905 | static void wpa_driver_nl80211_send_action_cancel_wait(void *priv) |
6906 | { | |
6907 | struct i802_bss *bss = priv; | |
6908 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
6909 | unsigned int i; | |
6910 | u64 cookie; | |
6911 | ||
6912 | /* Cancel the last pending TX cookie */ | |
6913 | nl80211_frame_wait_cancel(bss, drv->send_action_cookie); | |
6914 | ||
6915 | /* | |
6916 | * Cancel the other pending TX cookies, if any. This is needed since | |
6917 | * the driver may keep a list of all pending offchannel TX operations | |
6918 | * and free up the radio only once they have expired or cancelled. | |
6919 | */ | |
6920 | for (i = drv->num_send_action_cookies; i > 0; i--) { | |
6921 | cookie = drv->send_action_cookies[i - 1]; | |
6922 | if (cookie != drv->send_action_cookie) | |
6923 | nl80211_frame_wait_cancel(bss, cookie); | |
6924 | } | |
6925 | drv->num_send_action_cookies = 0; | |
6926 | } | |
6927 | ||
6928 | ||
55777702 JM |
6929 | static int wpa_driver_nl80211_remain_on_channel(void *priv, unsigned int freq, |
6930 | unsigned int duration) | |
6931 | { | |
a2e40bb6 FF |
6932 | struct i802_bss *bss = priv; |
6933 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
55777702 JM |
6934 | struct nl_msg *msg; |
6935 | int ret; | |
6936 | u64 cookie; | |
6937 | ||
56f77852 | 6938 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_REMAIN_ON_CHANNEL)) || |
a862e4a3 JM |
6939 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
6940 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) { | |
6941 | nlmsg_free(msg); | |
6942 | return -1; | |
6943 | } | |
55777702 JM |
6944 | |
6945 | cookie = 0; | |
6946 | ret = send_and_recv_msgs(drv, msg, cookie_handler, &cookie); | |
6947 | if (ret == 0) { | |
6948 | wpa_printf(MSG_DEBUG, "nl80211: Remain-on-channel cookie " | |
6949 | "0x%llx for freq=%u MHz duration=%u", | |
6950 | (long long unsigned int) cookie, freq, duration); | |
6951 | drv->remain_on_chan_cookie = cookie; | |
531f0331 | 6952 | drv->pending_remain_on_chan = 1; |
55777702 JM |
6953 | return 0; |
6954 | } | |
6955 | wpa_printf(MSG_DEBUG, "nl80211: Failed to request remain-on-channel " | |
15ed5535 JM |
6956 | "(freq=%d duration=%u): %d (%s)", |
6957 | freq, duration, ret, strerror(-ret)); | |
55777702 JM |
6958 | return -1; |
6959 | } | |
6960 | ||
6961 | ||
6962 | static int wpa_driver_nl80211_cancel_remain_on_channel(void *priv) | |
6963 | { | |
a2e40bb6 FF |
6964 | struct i802_bss *bss = priv; |
6965 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
55777702 JM |
6966 | struct nl_msg *msg; |
6967 | int ret; | |
6968 | ||
6969 | if (!drv->pending_remain_on_chan) { | |
6970 | wpa_printf(MSG_DEBUG, "nl80211: No pending remain-on-channel " | |
6971 | "to cancel"); | |
6972 | return -1; | |
6973 | } | |
6974 | ||
6975 | wpa_printf(MSG_DEBUG, "nl80211: Cancel remain-on-channel with cookie " | |
6976 | "0x%llx", | |
6977 | (long long unsigned int) drv->remain_on_chan_cookie); | |
6978 | ||
56f77852 JM |
6979 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL); |
6980 | if (!msg || | |
a862e4a3 JM |
6981 | nla_put_u64(msg, NL80211_ATTR_COOKIE, drv->remain_on_chan_cookie)) { |
6982 | nlmsg_free(msg); | |
6983 | return -1; | |
6984 | } | |
55777702 JM |
6985 | |
6986 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
6987 | if (ret == 0) | |
6988 | return 0; | |
6989 | wpa_printf(MSG_DEBUG, "nl80211: Failed to cancel remain-on-channel: " | |
6990 | "%d (%s)", ret, strerror(-ret)); | |
55777702 JM |
6991 | return -1; |
6992 | } | |
6993 | ||
6994 | ||
9ebce9c5 | 6995 | static int wpa_driver_nl80211_probe_req_report(struct i802_bss *bss, int report) |
504e905c | 6996 | { |
a2e40bb6 | 6997 | struct wpa_driver_nl80211_data *drv = bss->drv; |
504e905c | 6998 | |
5582a5d1 | 6999 | if (!report) { |
0d891981 | 7000 | if (bss->nl_preq && drv->device_ap_sme && |
b8d87ed2 AP |
7001 | is_ap_interface(drv->nlmode) && !bss->in_deinit && |
7002 | !bss->static_ap) { | |
0d891981 JM |
7003 | /* |
7004 | * Do not disable Probe Request reporting that was | |
7005 | * enabled in nl80211_setup_ap(). | |
7006 | */ | |
7007 | wpa_printf(MSG_DEBUG, "nl80211: Skip disabling of " | |
7008 | "Probe Request reporting nl_preq=%p while " | |
7009 | "in AP mode", bss->nl_preq); | |
7010 | } else if (bss->nl_preq) { | |
36488c05 JM |
7011 | wpa_printf(MSG_DEBUG, "nl80211: Disable Probe Request " |
7012 | "reporting nl_preq=%p", bss->nl_preq); | |
5f65e9f7 | 7013 | nl80211_destroy_eloop_handle(&bss->nl_preq); |
5582a5d1 JB |
7014 | } |
7015 | return 0; | |
7016 | } | |
7017 | ||
481234cf | 7018 | if (bss->nl_preq) { |
5582a5d1 | 7019 | wpa_printf(MSG_DEBUG, "nl80211: Probe Request reporting " |
36488c05 | 7020 | "already on! nl_preq=%p", bss->nl_preq); |
5582a5d1 JB |
7021 | return 0; |
7022 | } | |
7023 | ||
481234cf JM |
7024 | bss->nl_preq = nl_create_handle(drv->global->nl_cb, "preq"); |
7025 | if (bss->nl_preq == NULL) | |
5582a5d1 | 7026 | return -1; |
36488c05 JM |
7027 | wpa_printf(MSG_DEBUG, "nl80211: Enable Probe Request " |
7028 | "reporting nl_preq=%p", bss->nl_preq); | |
5582a5d1 | 7029 | |
481234cf | 7030 | if (nl80211_register_frame(bss, bss->nl_preq, |
5582a5d1 JB |
7031 | (WLAN_FC_TYPE_MGMT << 2) | |
7032 | (WLAN_FC_STYPE_PROBE_REQ << 4), | |
a92dfde8 JB |
7033 | NULL, 0) < 0) |
7034 | goto out_err; | |
5582a5d1 | 7035 | |
5f65e9f7 JB |
7036 | nl80211_register_eloop_read(&bss->nl_preq, |
7037 | wpa_driver_nl80211_event_receive, | |
7038 | bss->nl_cb); | |
5582a5d1 | 7039 | |
504e905c | 7040 | return 0; |
5582a5d1 | 7041 | |
a92dfde8 | 7042 | out_err: |
221a59c9 | 7043 | nl_destroy_handles(&bss->nl_preq); |
5582a5d1 | 7044 | return -1; |
504e905c JM |
7045 | } |
7046 | ||
7047 | ||
4e5cb1a3 JM |
7048 | static int nl80211_disable_11b_rates(struct wpa_driver_nl80211_data *drv, |
7049 | int ifindex, int disabled) | |
7050 | { | |
7051 | struct nl_msg *msg; | |
7052 | struct nlattr *bands, *band; | |
7053 | int ret; | |
7054 | ||
3e208481 JM |
7055 | wpa_printf(MSG_DEBUG, |
7056 | "nl80211: NL80211_CMD_SET_TX_BITRATE_MASK (ifindex=%d %s)", | |
7057 | ifindex, disabled ? "NL80211_TXRATE_LEGACY=OFDM-only" : | |
7058 | "no NL80211_TXRATE_LEGACY constraint"); | |
7059 | ||
95376e1a JM |
7060 | msg = nl80211_ifindex_msg(drv, ifindex, 0, |
7061 | NL80211_CMD_SET_TX_BITRATE_MASK); | |
4e5cb1a3 JM |
7062 | if (!msg) |
7063 | return -1; | |
7064 | ||
4e5cb1a3 JM |
7065 | bands = nla_nest_start(msg, NL80211_ATTR_TX_RATES); |
7066 | if (!bands) | |
a862e4a3 | 7067 | goto fail; |
4e5cb1a3 JM |
7068 | |
7069 | /* | |
7070 | * Disable 2 GHz rates 1, 2, 5.5, 11 Mbps by masking out everything | |
7071 | * else apart from 6, 9, 12, 18, 24, 36, 48, 54 Mbps from non-MCS | |
7072 | * rates. All 5 GHz rates are left enabled. | |
7073 | */ | |
7074 | band = nla_nest_start(msg, NL80211_BAND_2GHZ); | |
a862e4a3 JM |
7075 | if (!band || |
7076 | (disabled && nla_put(msg, NL80211_TXRATE_LEGACY, 8, | |
7077 | "\x0c\x12\x18\x24\x30\x48\x60\x6c"))) | |
7078 | goto fail; | |
4e5cb1a3 JM |
7079 | nla_nest_end(msg, band); |
7080 | ||
7081 | nla_nest_end(msg, bands); | |
7082 | ||
7083 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
4e5cb1a3 JM |
7084 | if (ret) { |
7085 | wpa_printf(MSG_DEBUG, "nl80211: Set TX rates failed: ret=%d " | |
7086 | "(%s)", ret, strerror(-ret)); | |
1d0c6fb1 JM |
7087 | } else |
7088 | drv->disabled_11b_rates = disabled; | |
4e5cb1a3 JM |
7089 | |
7090 | return ret; | |
7091 | ||
a862e4a3 | 7092 | fail: |
4e5cb1a3 JM |
7093 | nlmsg_free(msg); |
7094 | return -1; | |
7095 | } | |
7096 | ||
7097 | ||
af473088 JM |
7098 | static int wpa_driver_nl80211_deinit_ap(void *priv) |
7099 | { | |
a2e40bb6 FF |
7100 | struct i802_bss *bss = priv; |
7101 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
b1f625e0 | 7102 | if (!is_ap_interface(drv->nlmode)) |
af473088 JM |
7103 | return -1; |
7104 | wpa_driver_nl80211_del_beacon(drv); | |
9bc5cfa3 | 7105 | bss->beacon_set = 0; |
60b13c20 IP |
7106 | |
7107 | /* | |
7108 | * If the P2P GO interface was dynamically added, then it is | |
7109 | * possible that the interface change to station is not possible. | |
7110 | */ | |
7111 | if (drv->nlmode == NL80211_IFTYPE_P2P_GO && bss->if_dynamic) | |
7112 | return 0; | |
7113 | ||
b1f625e0 | 7114 | return wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_STATION); |
af473088 JM |
7115 | } |
7116 | ||
7117 | ||
695c7038 SW |
7118 | static int wpa_driver_nl80211_stop_ap(void *priv) |
7119 | { | |
7120 | struct i802_bss *bss = priv; | |
7121 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
7122 | if (!is_ap_interface(drv->nlmode)) | |
7123 | return -1; | |
7124 | wpa_driver_nl80211_del_beacon(drv); | |
7125 | bss->beacon_set = 0; | |
7126 | return 0; | |
7127 | } | |
7128 | ||
7129 | ||
3c29244e EP |
7130 | static int wpa_driver_nl80211_deinit_p2p_cli(void *priv) |
7131 | { | |
7132 | struct i802_bss *bss = priv; | |
7133 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
7134 | if (drv->nlmode != NL80211_IFTYPE_P2P_CLIENT) | |
7135 | return -1; | |
60b13c20 IP |
7136 | |
7137 | /* | |
7138 | * If the P2P Client interface was dynamically added, then it is | |
7139 | * possible that the interface change to station is not possible. | |
7140 | */ | |
7141 | if (bss->if_dynamic) | |
7142 | return 0; | |
7143 | ||
3c29244e EP |
7144 | return wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_STATION); |
7145 | } | |
7146 | ||
7147 | ||
207ef3fb JM |
7148 | static void wpa_driver_nl80211_resume(void *priv) |
7149 | { | |
a2e40bb6 | 7150 | struct i802_bss *bss = priv; |
e8dc205f | 7151 | enum nl80211_iftype nlmode = nl80211_get_ifmode(bss); |
91724d6f AS |
7152 | |
7153 | if (i802_set_iface_flags(bss, 1)) | |
7154 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set interface up on resume event"); | |
e8dc205f AO |
7155 | |
7156 | if (is_p2p_net_interface(nlmode)) | |
7157 | nl80211_disable_11b_rates(bss->drv, bss->drv->ifindex, 1); | |
207ef3fb JM |
7158 | } |
7159 | ||
7160 | ||
b625473c JM |
7161 | static int nl80211_signal_monitor(void *priv, int threshold, int hysteresis) |
7162 | { | |
7163 | struct i802_bss *bss = priv; | |
7164 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8970bae8 JB |
7165 | struct nl_msg *msg; |
7166 | struct nlattr *cqm; | |
b625473c JM |
7167 | |
7168 | wpa_printf(MSG_DEBUG, "nl80211: Signal monitor threshold=%d " | |
7169 | "hysteresis=%d", threshold, hysteresis); | |
7170 | ||
13f83980 | 7171 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_CQM)) || |
a862e4a3 JM |
7172 | !(cqm = nla_nest_start(msg, NL80211_ATTR_CQM)) || |
7173 | nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THOLD, threshold) || | |
7174 | nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_HYST, hysteresis)) { | |
7175 | nlmsg_free(msg); | |
7176 | return -1; | |
7177 | } | |
8970bae8 | 7178 | nla_nest_end(msg, cqm); |
21270bb4 | 7179 | |
a862e4a3 | 7180 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
b625473c JM |
7181 | } |
7182 | ||
7183 | ||
2cc8d8f4 AO |
7184 | static int get_channel_width(struct nl_msg *msg, void *arg) |
7185 | { | |
7186 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
7187 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
7188 | struct wpa_signal_info *sig_change = arg; | |
7189 | ||
7190 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
7191 | genlmsg_attrlen(gnlh, 0), NULL); | |
7192 | ||
7193 | sig_change->center_frq1 = -1; | |
7194 | sig_change->center_frq2 = -1; | |
7195 | sig_change->chanwidth = CHAN_WIDTH_UNKNOWN; | |
7196 | ||
7197 | if (tb[NL80211_ATTR_CHANNEL_WIDTH]) { | |
7198 | sig_change->chanwidth = convert2width( | |
7199 | nla_get_u32(tb[NL80211_ATTR_CHANNEL_WIDTH])); | |
7200 | if (tb[NL80211_ATTR_CENTER_FREQ1]) | |
7201 | sig_change->center_frq1 = | |
7202 | nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ1]); | |
7203 | if (tb[NL80211_ATTR_CENTER_FREQ2]) | |
7204 | sig_change->center_frq2 = | |
7205 | nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ2]); | |
7206 | } | |
7207 | ||
7208 | return NL_SKIP; | |
7209 | } | |
7210 | ||
7211 | ||
7212 | static int nl80211_get_channel_width(struct wpa_driver_nl80211_data *drv, | |
7213 | struct wpa_signal_info *sig) | |
7214 | { | |
7215 | struct nl_msg *msg; | |
7216 | ||
9725b784 | 7217 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_GET_INTERFACE); |
2cc8d8f4 | 7218 | return send_and_recv_msgs(drv, msg, get_channel_width, sig); |
2cc8d8f4 AO |
7219 | } |
7220 | ||
7221 | ||
1c5c7273 PS |
7222 | static int nl80211_signal_poll(void *priv, struct wpa_signal_info *si) |
7223 | { | |
7224 | struct i802_bss *bss = priv; | |
7225 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
7226 | int res; | |
7227 | ||
7228 | os_memset(si, 0, sizeof(*si)); | |
7229 | res = nl80211_get_link_signal(drv, si); | |
1d6955e6 JM |
7230 | if (res) { |
7231 | if (drv->nlmode != NL80211_IFTYPE_ADHOC && | |
7232 | drv->nlmode != NL80211_IFTYPE_MESH_POINT) | |
7233 | return res; | |
7234 | si->current_signal = 0; | |
7235 | } | |
1c5c7273 | 7236 | |
2cc8d8f4 AO |
7237 | res = nl80211_get_channel_width(drv, si); |
7238 | if (res != 0) | |
7239 | return res; | |
7240 | ||
1c5c7273 PS |
7241 | return nl80211_get_link_noise(drv, si); |
7242 | } | |
7243 | ||
7244 | ||
b91ab76e JM |
7245 | static int nl80211_send_frame(void *priv, const u8 *data, size_t data_len, |
7246 | int encrypt) | |
7247 | { | |
7248 | struct i802_bss *bss = priv; | |
55231068 | 7249 | return wpa_driver_nl80211_send_frame(bss, data, data_len, encrypt, 0, |
2d3943ce | 7250 | 0, 0, 0, 0, NULL, 0); |
b91ab76e JM |
7251 | } |
7252 | ||
7253 | ||
c55f774d JM |
7254 | static int nl80211_set_param(void *priv, const char *param) |
7255 | { | |
ef24ad3e JM |
7256 | struct i802_bss *bss = priv; |
7257 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
7258 | ||
c55f774d JM |
7259 | if (param == NULL) |
7260 | return 0; | |
99a94f55 | 7261 | wpa_printf(MSG_DEBUG, "nl80211: driver param='%s'", param); |
c55f774d JM |
7262 | |
7263 | #ifdef CONFIG_P2P | |
7264 | if (os_strstr(param, "use_p2p_group_interface=1")) { | |
7265 | wpa_printf(MSG_DEBUG, "nl80211: Use separate P2P group " | |
7266 | "interface"); | |
7267 | drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_CONCURRENT; | |
7268 | drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_MGMT_AND_NON_P2P; | |
7269 | } | |
7270 | #endif /* CONFIG_P2P */ | |
7271 | ||
ef24ad3e | 7272 | if (os_strstr(param, "use_monitor=1")) |
327b01d3 | 7273 | drv->use_monitor = 1; |
327b01d3 JM |
7274 | |
7275 | if (os_strstr(param, "force_connect_cmd=1")) { | |
327b01d3 | 7276 | drv->capa.flags &= ~WPA_DRIVER_FLAGS_SME; |
b497a212 | 7277 | drv->force_connect_cmd = 1; |
327b01d3 JM |
7278 | } |
7279 | ||
ef24ad3e | 7280 | if (os_strstr(param, "force_bss_selection=1")) |
4d584d8c | 7281 | drv->capa.flags |= WPA_DRIVER_FLAGS_BSS_SELECTION; |
4d584d8c | 7282 | |
64abb725 | 7283 | if (os_strstr(param, "no_offchannel_tx=1")) { |
64abb725 JM |
7284 | drv->capa.flags &= ~WPA_DRIVER_FLAGS_OFFCHANNEL_TX; |
7285 | drv->test_use_roc_tx = 1; | |
7286 | } | |
7287 | ||
c55f774d JM |
7288 | return 0; |
7289 | } | |
7290 | ||
7291 | ||
45e3fc72 | 7292 | static void * nl80211_global_init(void *ctx) |
f2ed8023 JM |
7293 | { |
7294 | struct nl80211_global *global; | |
36d84860 BG |
7295 | struct netlink_config *cfg; |
7296 | ||
f2ed8023 JM |
7297 | global = os_zalloc(sizeof(*global)); |
7298 | if (global == NULL) | |
7299 | return NULL; | |
45e3fc72 | 7300 | global->ctx = ctx; |
c81eff1a | 7301 | global->ioctl_sock = -1; |
f2ed8023 | 7302 | dl_list_init(&global->interfaces); |
ff6a158b | 7303 | global->if_add_ifindex = -1; |
36d84860 BG |
7304 | |
7305 | cfg = os_zalloc(sizeof(*cfg)); | |
7306 | if (cfg == NULL) | |
7307 | goto err; | |
7308 | ||
7309 | cfg->ctx = global; | |
7310 | cfg->newlink_cb = wpa_driver_nl80211_event_rtm_newlink; | |
7311 | cfg->dellink_cb = wpa_driver_nl80211_event_rtm_dellink; | |
7312 | global->netlink = netlink_init(cfg); | |
7313 | if (global->netlink == NULL) { | |
7314 | os_free(cfg); | |
7315 | goto err; | |
7316 | } | |
7317 | ||
2a7b66f5 BG |
7318 | if (wpa_driver_nl80211_init_nl_global(global) < 0) |
7319 | goto err; | |
7320 | ||
c81eff1a BG |
7321 | global->ioctl_sock = socket(PF_INET, SOCK_DGRAM, 0); |
7322 | if (global->ioctl_sock < 0) { | |
7ac3616d JM |
7323 | wpa_printf(MSG_ERROR, "nl80211: socket(PF_INET,SOCK_DGRAM) failed: %s", |
7324 | strerror(errno)); | |
c81eff1a BG |
7325 | goto err; |
7326 | } | |
7327 | ||
f2ed8023 | 7328 | return global; |
36d84860 BG |
7329 | |
7330 | err: | |
7331 | nl80211_global_deinit(global); | |
7332 | return NULL; | |
f2ed8023 JM |
7333 | } |
7334 | ||
7335 | ||
7336 | static void nl80211_global_deinit(void *priv) | |
7337 | { | |
7338 | struct nl80211_global *global = priv; | |
7339 | if (global == NULL) | |
7340 | return; | |
7341 | if (!dl_list_empty(&global->interfaces)) { | |
7342 | wpa_printf(MSG_ERROR, "nl80211: %u interface(s) remain at " | |
7343 | "nl80211_global_deinit", | |
7344 | dl_list_len(&global->interfaces)); | |
7345 | } | |
36d84860 BG |
7346 | |
7347 | if (global->netlink) | |
7348 | netlink_deinit(global->netlink); | |
7349 | ||
276e2d67 BG |
7350 | nl_destroy_handles(&global->nl); |
7351 | ||
5f65e9f7 JB |
7352 | if (global->nl_event) |
7353 | nl80211_destroy_eloop_handle(&global->nl_event); | |
d6c9aab8 JB |
7354 | |
7355 | nl_cb_put(global->nl_cb); | |
2a7b66f5 | 7356 | |
c81eff1a BG |
7357 | if (global->ioctl_sock >= 0) |
7358 | close(global->ioctl_sock); | |
7359 | ||
f2ed8023 JM |
7360 | os_free(global); |
7361 | } | |
7362 | ||
7363 | ||
6859f1cb BG |
7364 | static const char * nl80211_get_radio_name(void *priv) |
7365 | { | |
7366 | struct i802_bss *bss = priv; | |
7367 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
7368 | return drv->phyname; | |
7369 | } | |
7370 | ||
7371 | ||
a6efc65d JM |
7372 | static int nl80211_pmkid(struct i802_bss *bss, int cmd, const u8 *bssid, |
7373 | const u8 *pmkid) | |
7374 | { | |
7375 | struct nl_msg *msg; | |
7376 | ||
13f83980 | 7377 | if (!(msg = nl80211_bss_msg(bss, 0, cmd)) || |
a862e4a3 JM |
7378 | (pmkid && nla_put(msg, NL80211_ATTR_PMKID, 16, pmkid)) || |
7379 | (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))) { | |
7380 | nlmsg_free(msg); | |
7381 | return -ENOBUFS; | |
7382 | } | |
a6efc65d JM |
7383 | |
7384 | return send_and_recv_msgs(bss->drv, msg, NULL, NULL); | |
a6efc65d JM |
7385 | } |
7386 | ||
7387 | ||
7388 | static int nl80211_add_pmkid(void *priv, const u8 *bssid, const u8 *pmkid) | |
7389 | { | |
7390 | struct i802_bss *bss = priv; | |
7391 | wpa_printf(MSG_DEBUG, "nl80211: Add PMKID for " MACSTR, MAC2STR(bssid)); | |
7392 | return nl80211_pmkid(bss, NL80211_CMD_SET_PMKSA, bssid, pmkid); | |
7393 | } | |
7394 | ||
7395 | ||
7396 | static int nl80211_remove_pmkid(void *priv, const u8 *bssid, const u8 *pmkid) | |
7397 | { | |
7398 | struct i802_bss *bss = priv; | |
7399 | wpa_printf(MSG_DEBUG, "nl80211: Delete PMKID for " MACSTR, | |
7400 | MAC2STR(bssid)); | |
7401 | return nl80211_pmkid(bss, NL80211_CMD_DEL_PMKSA, bssid, pmkid); | |
7402 | } | |
7403 | ||
7404 | ||
7405 | static int nl80211_flush_pmkid(void *priv) | |
7406 | { | |
7407 | struct i802_bss *bss = priv; | |
7408 | wpa_printf(MSG_DEBUG, "nl80211: Flush PMKIDs"); | |
7409 | return nl80211_pmkid(bss, NL80211_CMD_FLUSH_PMKSA, NULL, NULL); | |
7410 | } | |
7411 | ||
7412 | ||
0185007c MK |
7413 | static void clean_survey_results(struct survey_results *survey_results) |
7414 | { | |
7415 | struct freq_survey *survey, *tmp; | |
7416 | ||
7417 | if (dl_list_empty(&survey_results->survey_list)) | |
7418 | return; | |
7419 | ||
7420 | dl_list_for_each_safe(survey, tmp, &survey_results->survey_list, | |
7421 | struct freq_survey, list) { | |
7422 | dl_list_del(&survey->list); | |
7423 | os_free(survey); | |
7424 | } | |
7425 | } | |
7426 | ||
7427 | ||
7428 | static void add_survey(struct nlattr **sinfo, u32 ifidx, | |
7429 | struct dl_list *survey_list) | |
7430 | { | |
7431 | struct freq_survey *survey; | |
7432 | ||
7433 | survey = os_zalloc(sizeof(struct freq_survey)); | |
7434 | if (!survey) | |
7435 | return; | |
7436 | ||
7437 | survey->ifidx = ifidx; | |
7438 | survey->freq = nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]); | |
7439 | survey->filled = 0; | |
7440 | ||
7441 | if (sinfo[NL80211_SURVEY_INFO_NOISE]) { | |
7442 | survey->nf = (int8_t) | |
7443 | nla_get_u8(sinfo[NL80211_SURVEY_INFO_NOISE]); | |
7444 | survey->filled |= SURVEY_HAS_NF; | |
7445 | } | |
7446 | ||
7447 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME]) { | |
7448 | survey->channel_time = | |
7449 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME]); | |
7450 | survey->filled |= SURVEY_HAS_CHAN_TIME; | |
7451 | } | |
7452 | ||
7453 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY]) { | |
7454 | survey->channel_time_busy = | |
7455 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY]); | |
7456 | survey->filled |= SURVEY_HAS_CHAN_TIME_BUSY; | |
7457 | } | |
7458 | ||
7459 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_RX]) { | |
7460 | survey->channel_time_rx = | |
7461 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_RX]); | |
7462 | survey->filled |= SURVEY_HAS_CHAN_TIME_RX; | |
7463 | } | |
7464 | ||
7465 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_TX]) { | |
7466 | survey->channel_time_tx = | |
7467 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_TX]); | |
7468 | survey->filled |= SURVEY_HAS_CHAN_TIME_TX; | |
7469 | } | |
7470 | ||
7471 | 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)", | |
7472 | survey->freq, | |
7473 | survey->nf, | |
7474 | (unsigned long int) survey->channel_time, | |
7475 | (unsigned long int) survey->channel_time_busy, | |
7476 | (unsigned long int) survey->channel_time_tx, | |
7477 | (unsigned long int) survey->channel_time_rx, | |
7478 | survey->filled); | |
7479 | ||
7480 | dl_list_add_tail(survey_list, &survey->list); | |
7481 | } | |
7482 | ||
7483 | ||
7484 | static int check_survey_ok(struct nlattr **sinfo, u32 surveyed_freq, | |
7485 | unsigned int freq_filter) | |
7486 | { | |
7487 | if (!freq_filter) | |
7488 | return 1; | |
7489 | ||
7490 | return freq_filter == surveyed_freq; | |
7491 | } | |
7492 | ||
7493 | ||
7494 | static int survey_handler(struct nl_msg *msg, void *arg) | |
7495 | { | |
7496 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
7497 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
7498 | struct nlattr *sinfo[NL80211_SURVEY_INFO_MAX + 1]; | |
7499 | struct survey_results *survey_results; | |
7500 | u32 surveyed_freq = 0; | |
7501 | u32 ifidx; | |
7502 | ||
7503 | static struct nla_policy survey_policy[NL80211_SURVEY_INFO_MAX + 1] = { | |
7504 | [NL80211_SURVEY_INFO_FREQUENCY] = { .type = NLA_U32 }, | |
7505 | [NL80211_SURVEY_INFO_NOISE] = { .type = NLA_U8 }, | |
7506 | }; | |
7507 | ||
7508 | survey_results = (struct survey_results *) arg; | |
7509 | ||
7510 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
7511 | genlmsg_attrlen(gnlh, 0), NULL); | |
7512 | ||
e28f39b7 SJ |
7513 | if (!tb[NL80211_ATTR_IFINDEX]) |
7514 | return NL_SKIP; | |
7515 | ||
0185007c MK |
7516 | ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); |
7517 | ||
7518 | if (!tb[NL80211_ATTR_SURVEY_INFO]) | |
7519 | return NL_SKIP; | |
7520 | ||
7521 | if (nla_parse_nested(sinfo, NL80211_SURVEY_INFO_MAX, | |
7522 | tb[NL80211_ATTR_SURVEY_INFO], | |
7523 | survey_policy)) | |
7524 | return NL_SKIP; | |
7525 | ||
7526 | if (!sinfo[NL80211_SURVEY_INFO_FREQUENCY]) { | |
7527 | wpa_printf(MSG_ERROR, "nl80211: Invalid survey data"); | |
7528 | return NL_SKIP; | |
7529 | } | |
7530 | ||
7531 | surveyed_freq = nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]); | |
7532 | ||
7533 | if (!check_survey_ok(sinfo, surveyed_freq, | |
7534 | survey_results->freq_filter)) | |
7535 | return NL_SKIP; | |
7536 | ||
7537 | if (survey_results->freq_filter && | |
7538 | survey_results->freq_filter != surveyed_freq) { | |
7539 | wpa_printf(MSG_EXCESSIVE, "nl80211: Ignoring survey data for freq %d MHz", | |
7540 | surveyed_freq); | |
7541 | return NL_SKIP; | |
7542 | } | |
7543 | ||
7544 | add_survey(sinfo, ifidx, &survey_results->survey_list); | |
7545 | ||
7546 | return NL_SKIP; | |
7547 | } | |
7548 | ||
7549 | ||
7550 | static int wpa_driver_nl80211_get_survey(void *priv, unsigned int freq) | |
7551 | { | |
7552 | struct i802_bss *bss = priv; | |
7553 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
7554 | struct nl_msg *msg; | |
9725b784 | 7555 | int err; |
0185007c MK |
7556 | union wpa_event_data data; |
7557 | struct survey_results *survey_results; | |
7558 | ||
7559 | os_memset(&data, 0, sizeof(data)); | |
7560 | survey_results = &data.survey_results; | |
7561 | ||
7562 | dl_list_init(&survey_results->survey_list); | |
7563 | ||
9725b784 | 7564 | msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SURVEY); |
0185007c | 7565 | if (!msg) |
a862e4a3 | 7566 | return -ENOBUFS; |
0185007c | 7567 | |
0185007c MK |
7568 | if (freq) |
7569 | data.survey_results.freq_filter = freq; | |
7570 | ||
7571 | do { | |
7572 | wpa_printf(MSG_DEBUG, "nl80211: Fetch survey data"); | |
7573 | err = send_and_recv_msgs(drv, msg, survey_handler, | |
7574 | survey_results); | |
7575 | } while (err > 0); | |
7576 | ||
a862e4a3 | 7577 | if (err) |
0185007c | 7578 | wpa_printf(MSG_ERROR, "nl80211: Failed to process survey data"); |
a862e4a3 JM |
7579 | else |
7580 | wpa_supplicant_event(drv->ctx, EVENT_SURVEY, &data); | |
0185007c | 7581 | |
0185007c | 7582 | clean_survey_results(survey_results); |
0185007c MK |
7583 | return err; |
7584 | } | |
7585 | ||
7586 | ||
98cd3d1c JM |
7587 | static void nl80211_set_rekey_info(void *priv, const u8 *kek, size_t kek_len, |
7588 | const u8 *kck, size_t kck_len, | |
b14a210c JB |
7589 | const u8 *replay_ctr) |
7590 | { | |
7591 | struct i802_bss *bss = priv; | |
7592 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
7593 | struct nlattr *replay_nested; | |
7594 | struct nl_msg *msg; | |
64ae2447 | 7595 | int ret; |
b14a210c | 7596 | |
64ae2447 JM |
7597 | if (!drv->set_rekey_offload) |
7598 | return; | |
7599 | ||
7600 | wpa_printf(MSG_DEBUG, "nl80211: Set rekey offload"); | |
13f83980 | 7601 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_REKEY_OFFLOAD)) || |
a862e4a3 | 7602 | !(replay_nested = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA)) || |
98cd3d1c JM |
7603 | nla_put(msg, NL80211_REKEY_DATA_KEK, kek_len, kek) || |
7604 | nla_put(msg, NL80211_REKEY_DATA_KCK, kck_len, kck) || | |
a862e4a3 JM |
7605 | nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, NL80211_REPLAY_CTR_LEN, |
7606 | replay_ctr)) { | |
bbd89bfc | 7607 | nl80211_nlmsg_clear(msg); |
a862e4a3 JM |
7608 | nlmsg_free(msg); |
7609 | return; | |
7610 | } | |
b14a210c JB |
7611 | |
7612 | nla_nest_end(msg, replay_nested); | |
7613 | ||
64ae2447 JM |
7614 | ret = send_and_recv_msgs(drv, msg, NULL, (void *) -1); |
7615 | if (ret == -EOPNOTSUPP) { | |
7616 | wpa_printf(MSG_DEBUG, | |
7617 | "nl80211: Driver does not support rekey offload"); | |
7618 | drv->set_rekey_offload = 0; | |
7619 | } | |
b14a210c JB |
7620 | } |
7621 | ||
7622 | ||
39718852 JB |
7623 | static void nl80211_send_null_frame(struct i802_bss *bss, const u8 *own_addr, |
7624 | const u8 *addr, int qos) | |
bcf24348 | 7625 | { |
39718852 JB |
7626 | /* send data frame to poll STA and check whether |
7627 | * this frame is ACKed */ | |
bcf24348 JB |
7628 | struct { |
7629 | struct ieee80211_hdr hdr; | |
7630 | u16 qos_ctl; | |
7631 | } STRUCT_PACKED nulldata; | |
7632 | size_t size; | |
7633 | ||
7634 | /* Send data frame to poll STA and check whether this frame is ACKed */ | |
7635 | ||
7636 | os_memset(&nulldata, 0, sizeof(nulldata)); | |
7637 | ||
7638 | if (qos) { | |
7639 | nulldata.hdr.frame_control = | |
7640 | IEEE80211_FC(WLAN_FC_TYPE_DATA, | |
7641 | WLAN_FC_STYPE_QOS_NULL); | |
7642 | size = sizeof(nulldata); | |
7643 | } else { | |
7644 | nulldata.hdr.frame_control = | |
7645 | IEEE80211_FC(WLAN_FC_TYPE_DATA, | |
7646 | WLAN_FC_STYPE_NULLFUNC); | |
7647 | size = sizeof(struct ieee80211_hdr); | |
7648 | } | |
7649 | ||
7650 | nulldata.hdr.frame_control |= host_to_le16(WLAN_FC_FROMDS); | |
7651 | os_memcpy(nulldata.hdr.IEEE80211_DA_FROMDS, addr, ETH_ALEN); | |
7652 | os_memcpy(nulldata.hdr.IEEE80211_BSSID_FROMDS, own_addr, ETH_ALEN); | |
7653 | os_memcpy(nulldata.hdr.IEEE80211_SA_FROMDS, own_addr, ETH_ALEN); | |
7654 | ||
9ebce9c5 | 7655 | if (wpa_driver_nl80211_send_mlme(bss, (u8 *) &nulldata, size, 0, 0, 0, |
2d3943ce | 7656 | 0, 0, NULL, 0) < 0) |
bcf24348 JB |
7657 | wpa_printf(MSG_DEBUG, "nl80211_send_null_frame: Failed to " |
7658 | "send poll frame"); | |
7659 | } | |
7660 | ||
39718852 JB |
7661 | static void nl80211_poll_client(void *priv, const u8 *own_addr, const u8 *addr, |
7662 | int qos) | |
7663 | { | |
7664 | struct i802_bss *bss = priv; | |
7665 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
7666 | struct nl_msg *msg; | |
fc99fab7 | 7667 | int ret; |
39718852 JB |
7668 | |
7669 | if (!drv->poll_command_supported) { | |
7670 | nl80211_send_null_frame(bss, own_addr, addr, qos); | |
7671 | return; | |
7672 | } | |
7673 | ||
13f83980 | 7674 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_PROBE_CLIENT)) || |
a862e4a3 JM |
7675 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { |
7676 | nlmsg_free(msg); | |
7677 | return; | |
7678 | } | |
39718852 | 7679 | |
fc99fab7 JM |
7680 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
7681 | if (ret < 0) { | |
7682 | wpa_printf(MSG_DEBUG, "nl80211: Client probe request for " | |
7683 | MACSTR " failed: ret=%d (%s)", | |
7684 | MAC2STR(addr), ret, strerror(-ret)); | |
7685 | } | |
39718852 JB |
7686 | } |
7687 | ||
bcf24348 | 7688 | |
29f338af JM |
7689 | static int nl80211_set_power_save(struct i802_bss *bss, int enabled) |
7690 | { | |
7691 | struct nl_msg *msg; | |
7692 | ||
13f83980 | 7693 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_POWER_SAVE)) || |
a862e4a3 JM |
7694 | nla_put_u32(msg, NL80211_ATTR_PS_STATE, |
7695 | enabled ? NL80211_PS_ENABLED : NL80211_PS_DISABLED)) { | |
7696 | nlmsg_free(msg); | |
7697 | return -ENOBUFS; | |
7698 | } | |
29f338af | 7699 | return send_and_recv_msgs(bss->drv, msg, NULL, NULL); |
29f338af JM |
7700 | } |
7701 | ||
7702 | ||
7703 | static int nl80211_set_p2p_powersave(void *priv, int legacy_ps, int opp_ps, | |
7704 | int ctwindow) | |
7705 | { | |
7706 | struct i802_bss *bss = priv; | |
7707 | ||
7708 | wpa_printf(MSG_DEBUG, "nl80211: set_p2p_powersave (legacy_ps=%d " | |
7709 | "opp_ps=%d ctwindow=%d)", legacy_ps, opp_ps, ctwindow); | |
7710 | ||
0de38036 JM |
7711 | if (opp_ps != -1 || ctwindow != -1) { |
7712 | #ifdef ANDROID_P2P | |
7713 | wpa_driver_set_p2p_ps(priv, legacy_ps, opp_ps, ctwindow); | |
7714 | #else /* ANDROID_P2P */ | |
29f338af | 7715 | return -1; /* Not yet supported */ |
0de38036 JM |
7716 | #endif /* ANDROID_P2P */ |
7717 | } | |
29f338af JM |
7718 | |
7719 | if (legacy_ps == -1) | |
7720 | return 0; | |
7721 | if (legacy_ps != 0 && legacy_ps != 1) | |
7722 | return -1; /* Not yet supported */ | |
7723 | ||
7724 | return nl80211_set_power_save(bss, legacy_ps); | |
7725 | } | |
7726 | ||
7727 | ||
04e8003c JD |
7728 | static int nl80211_start_radar_detection(void *priv, |
7729 | struct hostapd_freq_params *freq) | |
f90e9c1c SW |
7730 | { |
7731 | struct i802_bss *bss = priv; | |
7732 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
7733 | struct nl_msg *msg; | |
7734 | int ret; | |
7735 | ||
04e8003c JD |
7736 | 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)", |
7737 | freq->freq, freq->ht_enabled, freq->vht_enabled, | |
7738 | freq->bandwidth, freq->center_freq1, freq->center_freq2); | |
7739 | ||
f90e9c1c SW |
7740 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_RADAR)) { |
7741 | wpa_printf(MSG_DEBUG, "nl80211: Driver does not support radar " | |
7742 | "detection"); | |
7743 | return -1; | |
7744 | } | |
7745 | ||
9725b784 | 7746 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_RADAR_DETECT)) || |
a862e4a3 JM |
7747 | nl80211_put_freq_params(msg, freq) < 0) { |
7748 | nlmsg_free(msg); | |
7749 | return -1; | |
7750 | } | |
f90e9c1c SW |
7751 | |
7752 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
7753 | if (ret == 0) | |
7754 | return 0; | |
7755 | wpa_printf(MSG_DEBUG, "nl80211: Failed to start radar detection: " | |
7756 | "%d (%s)", ret, strerror(-ret)); | |
f90e9c1c SW |
7757 | return -1; |
7758 | } | |
7759 | ||
03ea1786 AN |
7760 | #ifdef CONFIG_TDLS |
7761 | ||
7762 | static int nl80211_send_tdls_mgmt(void *priv, const u8 *dst, u8 action_code, | |
7763 | u8 dialog_token, u16 status_code, | |
984dadc2 AN |
7764 | u32 peer_capab, int initiator, const u8 *buf, |
7765 | size_t len) | |
03ea1786 AN |
7766 | { |
7767 | struct i802_bss *bss = priv; | |
7768 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
7769 | struct nl_msg *msg; | |
7770 | ||
7771 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) | |
7772 | return -EOPNOTSUPP; | |
7773 | ||
7774 | if (!dst) | |
7775 | return -EINVAL; | |
7776 | ||
9725b784 | 7777 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_TDLS_MGMT)) || |
a862e4a3 JM |
7778 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || |
7779 | nla_put_u8(msg, NL80211_ATTR_TDLS_ACTION, action_code) || | |
7780 | nla_put_u8(msg, NL80211_ATTR_TDLS_DIALOG_TOKEN, dialog_token) || | |
7781 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status_code)) | |
7782 | goto fail; | |
96ecea5e SD |
7783 | if (peer_capab) { |
7784 | /* | |
7785 | * The internal enum tdls_peer_capability definition is | |
7786 | * currently identical with the nl80211 enum | |
7787 | * nl80211_tdls_peer_capability, so no conversion is needed | |
7788 | * here. | |
7789 | */ | |
a862e4a3 JM |
7790 | if (nla_put_u32(msg, NL80211_ATTR_TDLS_PEER_CAPABILITY, |
7791 | peer_capab)) | |
7792 | goto fail; | |
96ecea5e | 7793 | } |
a862e4a3 JM |
7794 | if ((initiator && |
7795 | nla_put_flag(msg, NL80211_ATTR_TDLS_INITIATOR)) || | |
7796 | nla_put(msg, NL80211_ATTR_IE, len, buf)) | |
7797 | goto fail; | |
03ea1786 AN |
7798 | |
7799 | return send_and_recv_msgs(drv, msg, NULL, NULL); | |
7800 | ||
a862e4a3 | 7801 | fail: |
03ea1786 AN |
7802 | nlmsg_free(msg); |
7803 | return -ENOBUFS; | |
7804 | } | |
7805 | ||
7806 | ||
7807 | static int nl80211_tdls_oper(void *priv, enum tdls_oper oper, const u8 *peer) | |
7808 | { | |
7809 | struct i802_bss *bss = priv; | |
7810 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
7811 | struct nl_msg *msg; | |
7812 | enum nl80211_tdls_operation nl80211_oper; | |
7813 | ||
7814 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) | |
7815 | return -EOPNOTSUPP; | |
7816 | ||
7817 | switch (oper) { | |
7818 | case TDLS_DISCOVERY_REQ: | |
7819 | nl80211_oper = NL80211_TDLS_DISCOVERY_REQ; | |
7820 | break; | |
7821 | case TDLS_SETUP: | |
7822 | nl80211_oper = NL80211_TDLS_SETUP; | |
7823 | break; | |
7824 | case TDLS_TEARDOWN: | |
7825 | nl80211_oper = NL80211_TDLS_TEARDOWN; | |
7826 | break; | |
7827 | case TDLS_ENABLE_LINK: | |
7828 | nl80211_oper = NL80211_TDLS_ENABLE_LINK; | |
7829 | break; | |
7830 | case TDLS_DISABLE_LINK: | |
7831 | nl80211_oper = NL80211_TDLS_DISABLE_LINK; | |
7832 | break; | |
7833 | case TDLS_ENABLE: | |
7834 | return 0; | |
7835 | case TDLS_DISABLE: | |
7836 | return 0; | |
7837 | default: | |
7838 | return -EINVAL; | |
7839 | } | |
7840 | ||
9725b784 | 7841 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_TDLS_OPER)) || |
a862e4a3 | 7842 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, nl80211_oper) || |
a862e4a3 JM |
7843 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) { |
7844 | nlmsg_free(msg); | |
7845 | return -ENOBUFS; | |
7846 | } | |
03ea1786 AN |
7847 | |
7848 | return send_and_recv_msgs(drv, msg, NULL, NULL); | |
03ea1786 AN |
7849 | } |
7850 | ||
72b2605f AN |
7851 | |
7852 | static int | |
7853 | nl80211_tdls_enable_channel_switch(void *priv, const u8 *addr, u8 oper_class, | |
7854 | const struct hostapd_freq_params *params) | |
7855 | { | |
7856 | struct i802_bss *bss = priv; | |
7857 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
7858 | struct nl_msg *msg; | |
7859 | int ret = -ENOBUFS; | |
7860 | ||
7861 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT) || | |
7862 | !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH)) | |
7863 | return -EOPNOTSUPP; | |
7864 | ||
7865 | wpa_printf(MSG_DEBUG, "nl80211: Enable TDLS channel switch " MACSTR | |
7866 | " oper_class=%u freq=%u", | |
7867 | MAC2STR(addr), oper_class, params->freq); | |
7868 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_TDLS_CHANNEL_SWITCH); | |
7869 | if (!msg || | |
7870 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || | |
7871 | nla_put_u8(msg, NL80211_ATTR_OPER_CLASS, oper_class) || | |
7872 | (ret = nl80211_put_freq_params(msg, params))) { | |
7873 | nlmsg_free(msg); | |
7874 | wpa_printf(MSG_DEBUG, "nl80211: Could not build TDLS chan switch"); | |
7875 | return ret; | |
7876 | } | |
7877 | ||
7878 | return send_and_recv_msgs(drv, msg, NULL, NULL); | |
7879 | } | |
7880 | ||
7881 | ||
7882 | static int | |
7883 | nl80211_tdls_disable_channel_switch(void *priv, const u8 *addr) | |
7884 | { | |
7885 | struct i802_bss *bss = priv; | |
7886 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
7887 | struct nl_msg *msg; | |
7888 | ||
7889 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT) || | |
7890 | !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH)) | |
7891 | return -EOPNOTSUPP; | |
7892 | ||
7893 | wpa_printf(MSG_DEBUG, "nl80211: Disable TDLS channel switch " MACSTR, | |
7894 | MAC2STR(addr)); | |
7895 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH); | |
7896 | if (!msg || | |
7897 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { | |
7898 | nlmsg_free(msg); | |
7899 | wpa_printf(MSG_DEBUG, | |
7900 | "nl80211: Could not build TDLS cancel chan switch"); | |
7901 | return -ENOBUFS; | |
7902 | } | |
7903 | ||
7904 | return send_and_recv_msgs(drv, msg, NULL, NULL); | |
7905 | } | |
7906 | ||
03ea1786 AN |
7907 | #endif /* CONFIG TDLS */ |
7908 | ||
7909 | ||
9ebce9c5 JM |
7910 | static int driver_nl80211_set_key(const char *ifname, void *priv, |
7911 | enum wpa_alg alg, const u8 *addr, | |
7912 | int key_idx, int set_tx, | |
7913 | const u8 *seq, size_t seq_len, | |
7914 | const u8 *key, size_t key_len) | |
7915 | { | |
7916 | struct i802_bss *bss = priv; | |
7917 | return wpa_driver_nl80211_set_key(ifname, bss, alg, addr, key_idx, | |
7918 | set_tx, seq, seq_len, key, key_len); | |
7919 | } | |
7920 | ||
7921 | ||
7922 | static int driver_nl80211_scan2(void *priv, | |
7923 | struct wpa_driver_scan_params *params) | |
7924 | { | |
7925 | struct i802_bss *bss = priv; | |
b658547d | 7926 | #ifdef CONFIG_DRIVER_NL80211_QCA |
adcd7c4b KV |
7927 | struct wpa_driver_nl80211_data *drv = bss->drv; |
7928 | ||
7929 | /* | |
7930 | * Do a vendor specific scan if possible. If only_new_results is | |
7931 | * set, do a normal scan since a kernel (cfg80211) BSS cache flush | |
7932 | * cannot be achieved through a vendor scan. The below condition may | |
7933 | * need to be modified if new scan flags are added in the future whose | |
7934 | * functionality can only be achieved through a normal scan. | |
7935 | */ | |
7936 | if (drv->scan_vendor_cmd_avail && !params->only_new_results) | |
7937 | return wpa_driver_nl80211_vendor_scan(bss, params); | |
b658547d | 7938 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
9ebce9c5 JM |
7939 | return wpa_driver_nl80211_scan(bss, params); |
7940 | } | |
7941 | ||
7942 | ||
7943 | static int driver_nl80211_deauthenticate(void *priv, const u8 *addr, | |
7944 | int reason_code) | |
7945 | { | |
7946 | struct i802_bss *bss = priv; | |
7947 | return wpa_driver_nl80211_deauthenticate(bss, addr, reason_code); | |
7948 | } | |
7949 | ||
7950 | ||
7951 | static int driver_nl80211_authenticate(void *priv, | |
7952 | struct wpa_driver_auth_params *params) | |
7953 | { | |
7954 | struct i802_bss *bss = priv; | |
7955 | return wpa_driver_nl80211_authenticate(bss, params); | |
7956 | } | |
7957 | ||
7958 | ||
7959 | static void driver_nl80211_deinit(void *priv) | |
7960 | { | |
7961 | struct i802_bss *bss = priv; | |
7962 | wpa_driver_nl80211_deinit(bss); | |
7963 | } | |
7964 | ||
7965 | ||
7966 | static int driver_nl80211_if_remove(void *priv, enum wpa_driver_if_type type, | |
7967 | const char *ifname) | |
7968 | { | |
7969 | struct i802_bss *bss = priv; | |
7970 | return wpa_driver_nl80211_if_remove(bss, type, ifname); | |
7971 | } | |
7972 | ||
7973 | ||
7974 | static int driver_nl80211_send_mlme(void *priv, const u8 *data, | |
5d180a77 | 7975 | size_t data_len, int noack, |
2d3943ce AO |
7976 | unsigned int freq, |
7977 | const u16 *csa_offs, size_t csa_offs_len) | |
9ebce9c5 JM |
7978 | { |
7979 | struct i802_bss *bss = priv; | |
7980 | return wpa_driver_nl80211_send_mlme(bss, data, data_len, noack, | |
2d3943ce AO |
7981 | freq, 0, 0, 0, csa_offs, |
7982 | csa_offs_len); | |
9ebce9c5 JM |
7983 | } |
7984 | ||
7985 | ||
7986 | static int driver_nl80211_sta_remove(void *priv, const u8 *addr) | |
7987 | { | |
7988 | struct i802_bss *bss = priv; | |
59d7148a | 7989 | return wpa_driver_nl80211_sta_remove(bss, addr, -1, 0); |
9ebce9c5 JM |
7990 | } |
7991 | ||
7992 | ||
9ebce9c5 JM |
7993 | static int driver_nl80211_set_sta_vlan(void *priv, const u8 *addr, |
7994 | const char *ifname, int vlan_id) | |
7995 | { | |
7996 | struct i802_bss *bss = priv; | |
7997 | return i802_set_sta_vlan(bss, addr, ifname, vlan_id); | |
7998 | } | |
9ebce9c5 JM |
7999 | |
8000 | ||
8001 | static int driver_nl80211_read_sta_data(void *priv, | |
8002 | struct hostap_sta_driver_data *data, | |
8003 | const u8 *addr) | |
8004 | { | |
8005 | struct i802_bss *bss = priv; | |
7824bf77 JC |
8006 | |
8007 | os_memset(data, 0, sizeof(*data)); | |
9ebce9c5 JM |
8008 | return i802_read_sta_data(bss, data, addr); |
8009 | } | |
8010 | ||
8011 | ||
8012 | static int driver_nl80211_send_action(void *priv, unsigned int freq, | |
8013 | unsigned int wait_time, | |
8014 | const u8 *dst, const u8 *src, | |
8015 | const u8 *bssid, | |
8016 | const u8 *data, size_t data_len, | |
8017 | int no_cck) | |
8018 | { | |
8019 | struct i802_bss *bss = priv; | |
8020 | return wpa_driver_nl80211_send_action(bss, freq, wait_time, dst, src, | |
8021 | bssid, data, data_len, no_cck); | |
8022 | } | |
8023 | ||
8024 | ||
8025 | static int driver_nl80211_probe_req_report(void *priv, int report) | |
8026 | { | |
8027 | struct i802_bss *bss = priv; | |
8028 | return wpa_driver_nl80211_probe_req_report(bss, report); | |
8029 | } | |
8030 | ||
8031 | ||
6a1ce395 DG |
8032 | static int wpa_driver_nl80211_update_ft_ies(void *priv, const u8 *md, |
8033 | const u8 *ies, size_t ies_len) | |
8034 | { | |
8035 | int ret; | |
8036 | struct nl_msg *msg; | |
8037 | struct i802_bss *bss = priv; | |
8038 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8039 | u16 mdid = WPA_GET_LE16(md); | |
8040 | ||
6a1ce395 | 8041 | wpa_printf(MSG_DEBUG, "nl80211: Updating FT IEs"); |
9725b784 | 8042 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_UPDATE_FT_IES)) || |
a862e4a3 JM |
8043 | nla_put(msg, NL80211_ATTR_IE, ies_len, ies) || |
8044 | nla_put_u16(msg, NL80211_ATTR_MDID, mdid)) { | |
8045 | nlmsg_free(msg); | |
8046 | return -ENOBUFS; | |
8047 | } | |
6a1ce395 DG |
8048 | |
8049 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
8050 | if (ret) { | |
8051 | wpa_printf(MSG_DEBUG, "nl80211: update_ft_ies failed " | |
8052 | "err=%d (%s)", ret, strerror(-ret)); | |
8053 | } | |
8054 | ||
8055 | return ret; | |
6a1ce395 DG |
8056 | } |
8057 | ||
8058 | ||
47754718 | 8059 | static const u8 * wpa_driver_nl80211_get_macaddr(void *priv) |
597b94f5 AS |
8060 | { |
8061 | struct i802_bss *bss = priv; | |
8062 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8063 | ||
8064 | if (drv->nlmode != NL80211_IFTYPE_P2P_DEVICE) | |
8065 | return NULL; | |
8066 | ||
8067 | return bss->addr; | |
8068 | } | |
8069 | ||
8070 | ||
a771c07d JM |
8071 | static const char * scan_state_str(enum scan_states scan_state) |
8072 | { | |
8073 | switch (scan_state) { | |
8074 | case NO_SCAN: | |
8075 | return "NO_SCAN"; | |
8076 | case SCAN_REQUESTED: | |
8077 | return "SCAN_REQUESTED"; | |
8078 | case SCAN_STARTED: | |
8079 | return "SCAN_STARTED"; | |
8080 | case SCAN_COMPLETED: | |
8081 | return "SCAN_COMPLETED"; | |
8082 | case SCAN_ABORTED: | |
8083 | return "SCAN_ABORTED"; | |
8084 | case SCHED_SCAN_STARTED: | |
8085 | return "SCHED_SCAN_STARTED"; | |
8086 | case SCHED_SCAN_STOPPED: | |
8087 | return "SCHED_SCAN_STOPPED"; | |
8088 | case SCHED_SCAN_RESULTS: | |
8089 | return "SCHED_SCAN_RESULTS"; | |
8090 | } | |
8091 | ||
8092 | return "??"; | |
8093 | } | |
8094 | ||
8095 | ||
8096 | static int wpa_driver_nl80211_status(void *priv, char *buf, size_t buflen) | |
8097 | { | |
8098 | struct i802_bss *bss = priv; | |
8099 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8100 | int res; | |
8101 | char *pos, *end; | |
8102 | ||
8103 | pos = buf; | |
8104 | end = buf + buflen; | |
8105 | ||
8106 | res = os_snprintf(pos, end - pos, | |
8107 | "ifindex=%d\n" | |
8108 | "ifname=%s\n" | |
8109 | "brname=%s\n" | |
8110 | "addr=" MACSTR "\n" | |
8111 | "freq=%d\n" | |
8112 | "%s%s%s%s%s", | |
8113 | bss->ifindex, | |
8114 | bss->ifname, | |
8115 | bss->brname, | |
8116 | MAC2STR(bss->addr), | |
8117 | bss->freq, | |
8118 | bss->beacon_set ? "beacon_set=1\n" : "", | |
8119 | bss->added_if_into_bridge ? | |
8120 | "added_if_into_bridge=1\n" : "", | |
8121 | bss->added_bridge ? "added_bridge=1\n" : "", | |
8122 | bss->in_deinit ? "in_deinit=1\n" : "", | |
8123 | bss->if_dynamic ? "if_dynamic=1\n" : ""); | |
d85e1fc8 | 8124 | if (os_snprintf_error(end - pos, res)) |
a771c07d JM |
8125 | return pos - buf; |
8126 | pos += res; | |
8127 | ||
8128 | if (bss->wdev_id_set) { | |
8129 | res = os_snprintf(pos, end - pos, "wdev_id=%llu\n", | |
8130 | (unsigned long long) bss->wdev_id); | |
d85e1fc8 | 8131 | if (os_snprintf_error(end - pos, res)) |
a771c07d JM |
8132 | return pos - buf; |
8133 | pos += res; | |
8134 | } | |
8135 | ||
8136 | res = os_snprintf(pos, end - pos, | |
8137 | "phyname=%s\n" | |
fee354c7 | 8138 | "perm_addr=" MACSTR "\n" |
a771c07d JM |
8139 | "drv_ifindex=%d\n" |
8140 | "operstate=%d\n" | |
8141 | "scan_state=%s\n" | |
8142 | "auth_bssid=" MACSTR "\n" | |
8143 | "auth_attempt_bssid=" MACSTR "\n" | |
8144 | "bssid=" MACSTR "\n" | |
8145 | "prev_bssid=" MACSTR "\n" | |
8146 | "associated=%d\n" | |
8147 | "assoc_freq=%u\n" | |
8148 | "monitor_sock=%d\n" | |
8149 | "monitor_ifidx=%d\n" | |
8150 | "monitor_refcount=%d\n" | |
8151 | "last_mgmt_freq=%u\n" | |
8152 | "eapol_tx_sock=%d\n" | |
97752f79 | 8153 | "%s%s%s%s%s%s%s%s%s%s%s%s%s", |
a771c07d | 8154 | drv->phyname, |
fee354c7 | 8155 | MAC2STR(drv->perm_addr), |
a771c07d JM |
8156 | drv->ifindex, |
8157 | drv->operstate, | |
8158 | scan_state_str(drv->scan_state), | |
8159 | MAC2STR(drv->auth_bssid), | |
8160 | MAC2STR(drv->auth_attempt_bssid), | |
8161 | MAC2STR(drv->bssid), | |
8162 | MAC2STR(drv->prev_bssid), | |
8163 | drv->associated, | |
8164 | drv->assoc_freq, | |
8165 | drv->monitor_sock, | |
8166 | drv->monitor_ifidx, | |
8167 | drv->monitor_refcount, | |
8168 | drv->last_mgmt_freq, | |
8169 | drv->eapol_tx_sock, | |
8170 | drv->ignore_if_down_event ? | |
8171 | "ignore_if_down_event=1\n" : "", | |
8172 | drv->scan_complete_events ? | |
8173 | "scan_complete_events=1\n" : "", | |
8174 | drv->disabled_11b_rates ? | |
8175 | "disabled_11b_rates=1\n" : "", | |
8176 | drv->pending_remain_on_chan ? | |
8177 | "pending_remain_on_chan=1\n" : "", | |
8178 | drv->in_interface_list ? "in_interface_list=1\n" : "", | |
8179 | drv->device_ap_sme ? "device_ap_sme=1\n" : "", | |
8180 | drv->poll_command_supported ? | |
8181 | "poll_command_supported=1\n" : "", | |
8182 | drv->data_tx_status ? "data_tx_status=1\n" : "", | |
8183 | drv->scan_for_auth ? "scan_for_auth=1\n" : "", | |
8184 | drv->retry_auth ? "retry_auth=1\n" : "", | |
8185 | drv->use_monitor ? "use_monitor=1\n" : "", | |
8186 | drv->ignore_next_local_disconnect ? | |
8187 | "ignore_next_local_disconnect=1\n" : "", | |
d6a36f39 | 8188 | drv->ignore_next_local_deauth ? |
97752f79 | 8189 | "ignore_next_local_deauth=1\n" : ""); |
d85e1fc8 | 8190 | if (os_snprintf_error(end - pos, res)) |
a771c07d JM |
8191 | return pos - buf; |
8192 | pos += res; | |
8193 | ||
8194 | if (drv->has_capability) { | |
8195 | res = os_snprintf(pos, end - pos, | |
8196 | "capa.key_mgmt=0x%x\n" | |
8197 | "capa.enc=0x%x\n" | |
8198 | "capa.auth=0x%x\n" | |
24bd4e0b | 8199 | "capa.flags=0x%llx\n" |
a0a34d53 | 8200 | "capa.rrm_flags=0x%x\n" |
a771c07d JM |
8201 | "capa.max_scan_ssids=%d\n" |
8202 | "capa.max_sched_scan_ssids=%d\n" | |
8203 | "capa.sched_scan_supported=%d\n" | |
8204 | "capa.max_match_sets=%d\n" | |
8205 | "capa.max_remain_on_chan=%u\n" | |
8206 | "capa.max_stations=%u\n" | |
8207 | "capa.probe_resp_offloads=0x%x\n" | |
8208 | "capa.max_acl_mac_addrs=%u\n" | |
86056fea IP |
8209 | "capa.num_multichan_concurrent=%u\n" |
8210 | "capa.mac_addr_rand_sched_scan_supported=%d\n" | |
079a28f7 AK |
8211 | "capa.mac_addr_rand_scan_supported=%d\n" |
8212 | "capa.conc_capab=%u\n" | |
8213 | "capa.max_conc_chan_2_4=%u\n" | |
09ea4309 AS |
8214 | "capa.max_conc_chan_5_0=%u\n" |
8215 | "capa.max_sched_scan_plans=%u\n" | |
8216 | "capa.max_sched_scan_plan_interval=%u\n" | |
8217 | "capa.max_sched_scan_plan_iterations=%u\n", | |
a771c07d JM |
8218 | drv->capa.key_mgmt, |
8219 | drv->capa.enc, | |
8220 | drv->capa.auth, | |
24bd4e0b | 8221 | (unsigned long long) drv->capa.flags, |
a0a34d53 | 8222 | drv->capa.rrm_flags, |
a771c07d JM |
8223 | drv->capa.max_scan_ssids, |
8224 | drv->capa.max_sched_scan_ssids, | |
8225 | drv->capa.sched_scan_supported, | |
8226 | drv->capa.max_match_sets, | |
8227 | drv->capa.max_remain_on_chan, | |
8228 | drv->capa.max_stations, | |
8229 | drv->capa.probe_resp_offloads, | |
8230 | drv->capa.max_acl_mac_addrs, | |
86056fea IP |
8231 | drv->capa.num_multichan_concurrent, |
8232 | drv->capa.mac_addr_rand_sched_scan_supported, | |
079a28f7 AK |
8233 | drv->capa.mac_addr_rand_scan_supported, |
8234 | drv->capa.conc_capab, | |
8235 | drv->capa.max_conc_chan_2_4, | |
09ea4309 AS |
8236 | drv->capa.max_conc_chan_5_0, |
8237 | drv->capa.max_sched_scan_plans, | |
8238 | drv->capa.max_sched_scan_plan_interval, | |
8239 | drv->capa.max_sched_scan_plan_iterations); | |
d85e1fc8 | 8240 | if (os_snprintf_error(end - pos, res)) |
a771c07d JM |
8241 | return pos - buf; |
8242 | pos += res; | |
8243 | } | |
8244 | ||
8245 | return pos - buf; | |
8246 | } | |
8247 | ||
8248 | ||
1c4ffa87 AO |
8249 | static int set_beacon_data(struct nl_msg *msg, struct beacon_data *settings) |
8250 | { | |
a862e4a3 JM |
8251 | if ((settings->head && |
8252 | nla_put(msg, NL80211_ATTR_BEACON_HEAD, | |
8253 | settings->head_len, settings->head)) || | |
8254 | (settings->tail && | |
8255 | nla_put(msg, NL80211_ATTR_BEACON_TAIL, | |
8256 | settings->tail_len, settings->tail)) || | |
8257 | (settings->beacon_ies && | |
8258 | nla_put(msg, NL80211_ATTR_IE, | |
8259 | settings->beacon_ies_len, settings->beacon_ies)) || | |
8260 | (settings->proberesp_ies && | |
8261 | nla_put(msg, NL80211_ATTR_IE_PROBE_RESP, | |
8262 | settings->proberesp_ies_len, settings->proberesp_ies)) || | |
8263 | (settings->assocresp_ies && | |
8264 | nla_put(msg, NL80211_ATTR_IE_ASSOC_RESP, | |
8265 | settings->assocresp_ies_len, settings->assocresp_ies)) || | |
8266 | (settings->probe_resp && | |
8267 | nla_put(msg, NL80211_ATTR_PROBE_RESP, | |
8268 | settings->probe_resp_len, settings->probe_resp))) | |
8269 | return -ENOBUFS; | |
1c4ffa87 AO |
8270 | |
8271 | return 0; | |
1c4ffa87 AO |
8272 | } |
8273 | ||
8274 | ||
8275 | static int nl80211_switch_channel(void *priv, struct csa_settings *settings) | |
8276 | { | |
8277 | struct nl_msg *msg; | |
8278 | struct i802_bss *bss = priv; | |
8279 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8280 | struct nlattr *beacon_csa; | |
8281 | int ret = -ENOBUFS; | |
366179d2 AO |
8282 | int csa_off_len = 0; |
8283 | int i; | |
1c4ffa87 | 8284 | |
8d1fdde7 | 8285 | wpa_printf(MSG_DEBUG, "nl80211: Channel switch request (cs_count=%u block_tx=%u freq=%d width=%d cf1=%d cf2=%d)", |
1c4ffa87 | 8286 | settings->cs_count, settings->block_tx, |
8d1fdde7 JD |
8287 | settings->freq_params.freq, settings->freq_params.bandwidth, |
8288 | settings->freq_params.center_freq1, | |
8289 | settings->freq_params.center_freq2); | |
1c4ffa87 | 8290 | |
991aa9c7 | 8291 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_AP_CSA)) { |
1c4ffa87 AO |
8292 | wpa_printf(MSG_DEBUG, "nl80211: Driver does not support channel switch command"); |
8293 | return -EOPNOTSUPP; | |
8294 | } | |
8295 | ||
8296 | if ((drv->nlmode != NL80211_IFTYPE_AP) && | |
8297 | (drv->nlmode != NL80211_IFTYPE_P2P_GO)) | |
8298 | return -EOPNOTSUPP; | |
8299 | ||
366179d2 AO |
8300 | /* |
8301 | * Remove empty counters, assuming Probe Response and Beacon frame | |
8302 | * counters match. This implementation assumes that there are only two | |
8303 | * counters. | |
8304 | */ | |
8305 | if (settings->counter_offset_beacon[0] && | |
8306 | !settings->counter_offset_beacon[1]) { | |
8307 | csa_off_len = 1; | |
8308 | } else if (settings->counter_offset_beacon[1] && | |
8309 | !settings->counter_offset_beacon[0]) { | |
8310 | csa_off_len = 1; | |
8311 | settings->counter_offset_beacon[0] = | |
8312 | settings->counter_offset_beacon[1]; | |
8313 | settings->counter_offset_presp[0] = | |
8314 | settings->counter_offset_presp[1]; | |
8315 | } else if (settings->counter_offset_beacon[1] && | |
8316 | settings->counter_offset_beacon[0]) { | |
8317 | csa_off_len = 2; | |
8318 | } else { | |
8319 | wpa_printf(MSG_ERROR, "nl80211: No CSA counters provided"); | |
8320 | return -EINVAL; | |
8321 | } | |
8322 | ||
8323 | /* Check CSA counters validity */ | |
8324 | if (drv->capa.max_csa_counters && | |
8325 | csa_off_len > drv->capa.max_csa_counters) { | |
8326 | wpa_printf(MSG_ERROR, | |
8327 | "nl80211: Too many CSA counters provided"); | |
1c4ffa87 | 8328 | return -EINVAL; |
366179d2 | 8329 | } |
1c4ffa87 | 8330 | |
366179d2 | 8331 | if (!settings->beacon_csa.tail) |
1c4ffa87 AO |
8332 | return -EINVAL; |
8333 | ||
366179d2 AO |
8334 | for (i = 0; i < csa_off_len; i++) { |
8335 | u16 csa_c_off_bcn = settings->counter_offset_beacon[i]; | |
8336 | u16 csa_c_off_presp = settings->counter_offset_presp[i]; | |
8337 | ||
8338 | if ((settings->beacon_csa.tail_len <= csa_c_off_bcn) || | |
8339 | (settings->beacon_csa.tail[csa_c_off_bcn] != | |
8340 | settings->cs_count)) | |
8341 | return -EINVAL; | |
8342 | ||
8343 | if (settings->beacon_csa.probe_resp && | |
8344 | ((settings->beacon_csa.probe_resp_len <= | |
8345 | csa_c_off_presp) || | |
8346 | (settings->beacon_csa.probe_resp[csa_c_off_presp] != | |
8347 | settings->cs_count))) | |
8348 | return -EINVAL; | |
8349 | } | |
8350 | ||
13f83980 | 8351 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_CHANNEL_SWITCH)) || |
a862e4a3 JM |
8352 | nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, |
8353 | settings->cs_count) || | |
8354 | (ret = nl80211_put_freq_params(msg, &settings->freq_params)) || | |
8355 | (settings->block_tx && | |
8356 | nla_put_flag(msg, NL80211_ATTR_CH_SWITCH_BLOCK_TX))) | |
1c4ffa87 AO |
8357 | goto error; |
8358 | ||
1c4ffa87 AO |
8359 | /* beacon_after params */ |
8360 | ret = set_beacon_data(msg, &settings->beacon_after); | |
8361 | if (ret) | |
8362 | goto error; | |
8363 | ||
8364 | /* beacon_csa params */ | |
8365 | beacon_csa = nla_nest_start(msg, NL80211_ATTR_CSA_IES); | |
8366 | if (!beacon_csa) | |
a862e4a3 | 8367 | goto fail; |
1c4ffa87 AO |
8368 | |
8369 | ret = set_beacon_data(msg, &settings->beacon_csa); | |
8370 | if (ret) | |
8371 | goto error; | |
8372 | ||
366179d2 AO |
8373 | if (nla_put(msg, NL80211_ATTR_CSA_C_OFF_BEACON, |
8374 | csa_off_len * sizeof(u16), | |
8375 | settings->counter_offset_beacon) || | |
a862e4a3 | 8376 | (settings->beacon_csa.probe_resp && |
366179d2 AO |
8377 | nla_put(msg, NL80211_ATTR_CSA_C_OFF_PRESP, |
8378 | csa_off_len * sizeof(u16), | |
8379 | settings->counter_offset_presp))) | |
a862e4a3 | 8380 | goto fail; |
1c4ffa87 AO |
8381 | |
8382 | nla_nest_end(msg, beacon_csa); | |
8383 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
8384 | if (ret) { | |
8385 | wpa_printf(MSG_DEBUG, "nl80211: switch_channel failed err=%d (%s)", | |
8386 | ret, strerror(-ret)); | |
8387 | } | |
8388 | return ret; | |
8389 | ||
a862e4a3 | 8390 | fail: |
1c4ffa87 AO |
8391 | ret = -ENOBUFS; |
8392 | error: | |
8393 | nlmsg_free(msg); | |
8394 | wpa_printf(MSG_DEBUG, "nl80211: Could not build channel switch request"); | |
8395 | return ret; | |
8396 | } | |
8397 | ||
8398 | ||
dfa87878 MB |
8399 | static int nl80211_add_ts(void *priv, u8 tsid, const u8 *addr, |
8400 | u8 user_priority, u16 admitted_time) | |
8401 | { | |
8402 | struct i802_bss *bss = priv; | |
8403 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8404 | struct nl_msg *msg; | |
8405 | int ret; | |
8406 | ||
8407 | wpa_printf(MSG_DEBUG, | |
8408 | "nl80211: add_ts request: tsid=%u admitted_time=%u up=%d", | |
8409 | tsid, admitted_time, user_priority); | |
8410 | ||
8411 | if (!is_sta_interface(drv->nlmode)) | |
8412 | return -ENOTSUP; | |
8413 | ||
56f77852 JM |
8414 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_ADD_TX_TS); |
8415 | if (!msg || | |
a862e4a3 JM |
8416 | nla_put_u8(msg, NL80211_ATTR_TSID, tsid) || |
8417 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || | |
8418 | nla_put_u8(msg, NL80211_ATTR_USER_PRIO, user_priority) || | |
8419 | nla_put_u16(msg, NL80211_ATTR_ADMITTED_TIME, admitted_time)) { | |
8420 | nlmsg_free(msg); | |
8421 | return -ENOBUFS; | |
8422 | } | |
dfa87878 MB |
8423 | |
8424 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
8425 | if (ret) | |
8426 | wpa_printf(MSG_DEBUG, "nl80211: add_ts failed err=%d (%s)", | |
8427 | ret, strerror(-ret)); | |
8428 | return ret; | |
dfa87878 MB |
8429 | } |
8430 | ||
8431 | ||
8432 | static int nl80211_del_ts(void *priv, u8 tsid, const u8 *addr) | |
8433 | { | |
8434 | struct i802_bss *bss = priv; | |
8435 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8436 | struct nl_msg *msg; | |
8437 | int ret; | |
8438 | ||
8439 | wpa_printf(MSG_DEBUG, "nl80211: del_ts request: tsid=%u", tsid); | |
8440 | ||
8441 | if (!is_sta_interface(drv->nlmode)) | |
8442 | return -ENOTSUP; | |
8443 | ||
56f77852 | 8444 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_DEL_TX_TS)) || |
a862e4a3 JM |
8445 | nla_put_u8(msg, NL80211_ATTR_TSID, tsid) || |
8446 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { | |
8447 | nlmsg_free(msg); | |
8448 | return -ENOBUFS; | |
8449 | } | |
dfa87878 MB |
8450 | |
8451 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
8452 | if (ret) | |
8453 | wpa_printf(MSG_DEBUG, "nl80211: del_ts failed err=%d (%s)", | |
8454 | ret, strerror(-ret)); | |
8455 | return ret; | |
dfa87878 MB |
8456 | } |
8457 | ||
8458 | ||
6b9f7af6 JM |
8459 | #ifdef CONFIG_TESTING_OPTIONS |
8460 | static int cmd_reply_handler(struct nl_msg *msg, void *arg) | |
8461 | { | |
8462 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
8463 | struct wpabuf *buf = arg; | |
8464 | ||
8465 | if (!buf) | |
8466 | return NL_SKIP; | |
8467 | ||
8468 | if ((size_t) genlmsg_attrlen(gnlh, 0) > wpabuf_tailroom(buf)) { | |
8469 | wpa_printf(MSG_INFO, "nl80211: insufficient buffer space for reply"); | |
8470 | return NL_SKIP; | |
8471 | } | |
8472 | ||
8473 | wpabuf_put_data(buf, genlmsg_attrdata(gnlh, 0), | |
8474 | genlmsg_attrlen(gnlh, 0)); | |
8475 | ||
8476 | return NL_SKIP; | |
8477 | } | |
8478 | #endif /* CONFIG_TESTING_OPTIONS */ | |
8479 | ||
8480 | ||
adef8948 BL |
8481 | static int vendor_reply_handler(struct nl_msg *msg, void *arg) |
8482 | { | |
8483 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
8484 | struct nlattr *nl_vendor_reply, *nl; | |
8485 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
8486 | struct wpabuf *buf = arg; | |
8487 | int rem; | |
8488 | ||
8489 | if (!buf) | |
8490 | return NL_SKIP; | |
8491 | ||
8492 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
8493 | genlmsg_attrlen(gnlh, 0), NULL); | |
8494 | nl_vendor_reply = tb[NL80211_ATTR_VENDOR_DATA]; | |
8495 | ||
8496 | if (!nl_vendor_reply) | |
8497 | return NL_SKIP; | |
8498 | ||
8499 | if ((size_t) nla_len(nl_vendor_reply) > wpabuf_tailroom(buf)) { | |
8500 | wpa_printf(MSG_INFO, "nl80211: Vendor command: insufficient buffer space for reply"); | |
8501 | return NL_SKIP; | |
8502 | } | |
8503 | ||
8504 | nla_for_each_nested(nl, nl_vendor_reply, rem) { | |
8505 | wpabuf_put_data(buf, nla_data(nl), nla_len(nl)); | |
8506 | } | |
8507 | ||
8508 | return NL_SKIP; | |
8509 | } | |
8510 | ||
8511 | ||
8512 | static int nl80211_vendor_cmd(void *priv, unsigned int vendor_id, | |
8513 | unsigned int subcmd, const u8 *data, | |
8514 | size_t data_len, struct wpabuf *buf) | |
8515 | { | |
8516 | struct i802_bss *bss = priv; | |
8517 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8518 | struct nl_msg *msg; | |
8519 | int ret; | |
8520 | ||
6b9f7af6 JM |
8521 | #ifdef CONFIG_TESTING_OPTIONS |
8522 | if (vendor_id == 0xffffffff) { | |
56f77852 JM |
8523 | msg = nlmsg_alloc(); |
8524 | if (!msg) | |
8525 | return -ENOMEM; | |
8526 | ||
6b9f7af6 JM |
8527 | nl80211_cmd(drv, msg, 0, subcmd); |
8528 | if (nlmsg_append(msg, (void *) data, data_len, NLMSG_ALIGNTO) < | |
8529 | 0) | |
a862e4a3 | 8530 | goto fail; |
6b9f7af6 JM |
8531 | ret = send_and_recv_msgs(drv, msg, cmd_reply_handler, buf); |
8532 | if (ret) | |
8533 | wpa_printf(MSG_DEBUG, "nl80211: command failed err=%d", | |
8534 | ret); | |
8535 | return ret; | |
8536 | } | |
8537 | #endif /* CONFIG_TESTING_OPTIONS */ | |
8538 | ||
56f77852 | 8539 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_VENDOR)) || |
a862e4a3 JM |
8540 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, vendor_id) || |
8541 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, subcmd) || | |
8542 | (data && | |
8543 | nla_put(msg, NL80211_ATTR_VENDOR_DATA, data_len, data))) | |
8544 | goto fail; | |
adef8948 BL |
8545 | |
8546 | ret = send_and_recv_msgs(drv, msg, vendor_reply_handler, buf); | |
8547 | if (ret) | |
8548 | wpa_printf(MSG_DEBUG, "nl80211: vendor command failed err=%d", | |
8549 | ret); | |
8550 | return ret; | |
8551 | ||
a862e4a3 | 8552 | fail: |
adef8948 BL |
8553 | nlmsg_free(msg); |
8554 | return -ENOBUFS; | |
8555 | } | |
8556 | ||
8557 | ||
049105b4 KP |
8558 | static int nl80211_set_qos_map(void *priv, const u8 *qos_map_set, |
8559 | u8 qos_map_set_len) | |
8560 | { | |
8561 | struct i802_bss *bss = priv; | |
8562 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8563 | struct nl_msg *msg; | |
8564 | int ret; | |
8565 | ||
049105b4 KP |
8566 | wpa_hexdump(MSG_DEBUG, "nl80211: Setting QoS Map", |
8567 | qos_map_set, qos_map_set_len); | |
8568 | ||
9725b784 | 8569 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_QOS_MAP)) || |
a862e4a3 JM |
8570 | nla_put(msg, NL80211_ATTR_QOS_MAP, qos_map_set_len, qos_map_set)) { |
8571 | nlmsg_free(msg); | |
8572 | return -ENOBUFS; | |
8573 | } | |
049105b4 KP |
8574 | |
8575 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
8576 | if (ret) | |
8577 | wpa_printf(MSG_DEBUG, "nl80211: Setting QoS Map failed"); | |
8578 | ||
8579 | return ret; | |
049105b4 KP |
8580 | } |
8581 | ||
8582 | ||
e4fa8b12 EP |
8583 | static int nl80211_set_wowlan(void *priv, |
8584 | const struct wowlan_triggers *triggers) | |
8585 | { | |
8586 | struct i802_bss *bss = priv; | |
8587 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8588 | struct nl_msg *msg; | |
8589 | struct nlattr *wowlan_triggers; | |
8590 | int ret; | |
8591 | ||
e4fa8b12 EP |
8592 | wpa_printf(MSG_DEBUG, "nl80211: Setting wowlan"); |
8593 | ||
1ac977bd | 8594 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_SET_WOWLAN)) || |
a862e4a3 JM |
8595 | !(wowlan_triggers = nla_nest_start(msg, |
8596 | NL80211_ATTR_WOWLAN_TRIGGERS)) || | |
8597 | (triggers->any && | |
8598 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || | |
8599 | (triggers->disconnect && | |
8600 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || | |
8601 | (triggers->magic_pkt && | |
8602 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || | |
8603 | (triggers->gtk_rekey_failure && | |
8604 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || | |
8605 | (triggers->eap_identity_req && | |
8606 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || | |
8607 | (triggers->four_way_handshake && | |
8608 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || | |
8609 | (triggers->rfkill_release && | |
8610 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) { | |
8611 | nlmsg_free(msg); | |
8612 | return -ENOBUFS; | |
8613 | } | |
e4fa8b12 EP |
8614 | |
8615 | nla_nest_end(msg, wowlan_triggers); | |
8616 | ||
8617 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
8618 | if (ret) | |
8619 | wpa_printf(MSG_DEBUG, "nl80211: Setting wowlan failed"); | |
8620 | ||
8621 | return ret; | |
e4fa8b12 EP |
8622 | } |
8623 | ||
8624 | ||
b658547d | 8625 | #ifdef CONFIG_DRIVER_NL80211_QCA |
0800f9ee JM |
8626 | static int nl80211_roaming(void *priv, int allowed, const u8 *bssid) |
8627 | { | |
8628 | struct i802_bss *bss = priv; | |
8629 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8630 | struct nl_msg *msg; | |
8631 | struct nlattr *params; | |
8632 | ||
8633 | wpa_printf(MSG_DEBUG, "nl80211: Roaming policy: allowed=%d", allowed); | |
8634 | ||
8635 | if (!drv->roaming_vendor_cmd_avail) { | |
8636 | wpa_printf(MSG_DEBUG, | |
8637 | "nl80211: Ignore roaming policy change since driver does not provide command for setting it"); | |
8638 | return -1; | |
8639 | } | |
8640 | ||
9725b784 | 8641 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
a862e4a3 JM |
8642 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
8643 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | |
8644 | QCA_NL80211_VENDOR_SUBCMD_ROAMING) || | |
8645 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || | |
8646 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_ROAMING_POLICY, | |
8647 | allowed ? QCA_ROAMING_ALLOWED_WITHIN_ESS : | |
8648 | QCA_ROAMING_NOT_ALLOWED) || | |
8649 | (bssid && | |
8650 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_MAC_ADDR, ETH_ALEN, bssid))) { | |
8651 | nlmsg_free(msg); | |
8652 | return -1; | |
8653 | } | |
0800f9ee JM |
8654 | nla_nest_end(msg, params); |
8655 | ||
8656 | return send_and_recv_msgs(drv, msg, NULL, NULL); | |
0800f9ee | 8657 | } |
b658547d | 8658 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
0800f9ee JM |
8659 | |
8660 | ||
fee354c7 JM |
8661 | static int nl80211_set_mac_addr(void *priv, const u8 *addr) |
8662 | { | |
8663 | struct i802_bss *bss = priv; | |
8664 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8665 | int new_addr = addr != NULL; | |
8666 | ||
9ce3e610 JM |
8667 | if (TEST_FAIL()) |
8668 | return -1; | |
8669 | ||
fee354c7 JM |
8670 | if (!addr) |
8671 | addr = drv->perm_addr; | |
8672 | ||
8673 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 0) < 0) | |
8674 | return -1; | |
8675 | ||
8676 | if (linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname, addr) < 0) | |
8677 | { | |
8678 | wpa_printf(MSG_DEBUG, | |
8679 | "nl80211: failed to set_mac_addr for %s to " MACSTR, | |
8680 | bss->ifname, MAC2STR(addr)); | |
8681 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, | |
8682 | 1) < 0) { | |
8683 | wpa_printf(MSG_DEBUG, | |
8684 | "nl80211: Could not restore interface UP after failed set_mac_addr"); | |
8685 | } | |
8686 | return -1; | |
8687 | } | |
8688 | ||
8689 | wpa_printf(MSG_DEBUG, "nl80211: set_mac_addr for %s to " MACSTR, | |
8690 | bss->ifname, MAC2STR(addr)); | |
8691 | drv->addr_changed = new_addr; | |
8692 | os_memcpy(bss->addr, addr, ETH_ALEN); | |
8693 | ||
8694 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 1) < 0) | |
8695 | { | |
8696 | wpa_printf(MSG_DEBUG, | |
8697 | "nl80211: Could not restore interface UP after set_mac_addr"); | |
8698 | } | |
8699 | ||
8700 | return 0; | |
8701 | } | |
8702 | ||
8703 | ||
6c1664f6 BC |
8704 | #ifdef CONFIG_MESH |
8705 | ||
8706 | static int wpa_driver_nl80211_init_mesh(void *priv) | |
8707 | { | |
8708 | if (wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_MESH_POINT)) { | |
8709 | wpa_printf(MSG_INFO, | |
8710 | "nl80211: Failed to set interface into mesh mode"); | |
8711 | return -1; | |
8712 | } | |
8713 | return 0; | |
8714 | } | |
8715 | ||
8716 | ||
21c74e84 JM |
8717 | static int nl80211_put_mesh_id(struct nl_msg *msg, const u8 *mesh_id, |
8718 | size_t mesh_id_len) | |
8719 | { | |
8720 | if (mesh_id) { | |
8721 | wpa_hexdump_ascii(MSG_DEBUG, " * Mesh ID (SSID)", | |
8722 | mesh_id, mesh_id_len); | |
8723 | return nla_put(msg, NL80211_ATTR_MESH_ID, mesh_id_len, mesh_id); | |
8724 | } | |
8725 | ||
8726 | return 0; | |
8727 | } | |
8728 | ||
8729 | ||
4ffb3f87 MH |
8730 | static int nl80211_put_mesh_config(struct nl_msg *msg, |
8731 | struct wpa_driver_mesh_bss_params *params) | |
8732 | { | |
8733 | struct nlattr *container; | |
8734 | ||
8735 | container = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); | |
8736 | if (!container) | |
8737 | return -1; | |
8738 | ||
2bd62171 MH |
8739 | if (((params->flags & WPA_DRIVER_MESH_CONF_FLAG_AUTO_PLINKS) && |
8740 | nla_put_u32(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, | |
8741 | params->auto_plinks)) || | |
8742 | ((params->flags & WPA_DRIVER_MESH_CONF_FLAG_MAX_PEER_LINKS) && | |
8743 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, | |
8744 | params->max_peer_links))) | |
4ffb3f87 MH |
8745 | return -1; |
8746 | ||
8747 | /* | |
8748 | * Set NL80211_MESHCONF_PLINK_TIMEOUT even if user mpm is used because | |
8749 | * the timer could disconnect stations even in that case. | |
8750 | */ | |
2bd62171 MH |
8751 | if ((params->flags & WPA_DRIVER_MESH_CONF_FLAG_PEER_LINK_TIMEOUT) && |
8752 | nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, | |
4ffb3f87 MH |
8753 | params->peer_link_timeout)) { |
8754 | wpa_printf(MSG_ERROR, "nl80211: Failed to set PLINK_TIMEOUT"); | |
8755 | return -1; | |
8756 | } | |
8757 | ||
052b8d38 MH |
8758 | if ((params->flags & WPA_DRIVER_MESH_CONF_FLAG_HT_OP_MODE) && |
8759 | nla_put_u16(msg, NL80211_MESHCONF_HT_OPMODE, params->ht_opmode)) { | |
8760 | wpa_printf(MSG_ERROR, "nl80211: Failed to set HT_OP_MODE"); | |
8761 | return -1; | |
8762 | } | |
8763 | ||
4ffb3f87 MH |
8764 | nla_nest_end(msg, container); |
8765 | ||
8766 | return 0; | |
8767 | } | |
8768 | ||
8769 | ||
0cb5f8d9 | 8770 | static int nl80211_join_mesh(struct i802_bss *bss, |
6c1664f6 BC |
8771 | struct wpa_driver_mesh_join_params *params) |
8772 | { | |
6c1664f6 BC |
8773 | struct wpa_driver_nl80211_data *drv = bss->drv; |
8774 | struct nl_msg *msg; | |
8775 | struct nlattr *container; | |
7451a217 | 8776 | int ret = -1; |
6c1664f6 | 8777 | |
6c1664f6 | 8778 | wpa_printf(MSG_DEBUG, "nl80211: mesh join (ifindex=%d)", drv->ifindex); |
9725b784 | 8779 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_JOIN_MESH); |
f7e889fa JM |
8780 | if (!msg || |
8781 | nl80211_put_freq_params(msg, ¶ms->freq) || | |
21c74e84 JM |
8782 | nl80211_put_basic_rates(msg, params->basic_rates) || |
8783 | nl80211_put_mesh_id(msg, params->meshid, params->meshid_len) || | |
4ac2ea57 MH |
8784 | nl80211_put_beacon_int(msg, params->beacon_int) || |
8785 | nl80211_put_dtim_period(msg, params->dtim_period)) | |
85e1fad8 | 8786 | goto fail; |
9c58c5f7 | 8787 | |
6c1664f6 BC |
8788 | wpa_printf(MSG_DEBUG, " * flags=%08X", params->flags); |
8789 | ||
8790 | container = nla_nest_start(msg, NL80211_ATTR_MESH_SETUP); | |
8791 | if (!container) | |
a862e4a3 | 8792 | goto fail; |
6c1664f6 BC |
8793 | |
8794 | if (params->ies) { | |
8795 | wpa_hexdump(MSG_DEBUG, " * IEs", params->ies, params->ie_len); | |
a862e4a3 JM |
8796 | if (nla_put(msg, NL80211_MESH_SETUP_IE, params->ie_len, |
8797 | params->ies)) | |
8798 | goto fail; | |
6c1664f6 BC |
8799 | } |
8800 | /* WPA_DRIVER_MESH_FLAG_OPEN_AUTH is treated as default by nl80211 */ | |
8801 | if (params->flags & WPA_DRIVER_MESH_FLAG_SAE_AUTH) { | |
a862e4a3 JM |
8802 | if (nla_put_u8(msg, NL80211_MESH_SETUP_AUTH_PROTOCOL, 0x1) || |
8803 | nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_AUTH)) | |
8804 | goto fail; | |
6c1664f6 | 8805 | } |
a862e4a3 JM |
8806 | if ((params->flags & WPA_DRIVER_MESH_FLAG_AMPE) && |
8807 | nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_AMPE)) | |
8808 | goto fail; | |
8809 | if ((params->flags & WPA_DRIVER_MESH_FLAG_USER_MPM) && | |
8810 | nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_MPM)) | |
8811 | goto fail; | |
6c1664f6 BC |
8812 | nla_nest_end(msg, container); |
8813 | ||
2bd62171 MH |
8814 | params->conf.flags |= WPA_DRIVER_MESH_CONF_FLAG_AUTO_PLINKS; |
8815 | params->conf.flags |= WPA_DRIVER_MESH_CONF_FLAG_PEER_LINK_TIMEOUT; | |
8816 | params->conf.flags |= WPA_DRIVER_MESH_CONF_FLAG_MAX_PEER_LINKS; | |
4ffb3f87 | 8817 | if (nl80211_put_mesh_config(msg, ¶ms->conf) < 0) |
5a2a6de6 | 8818 | goto fail; |
6c1664f6 BC |
8819 | |
8820 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
8821 | msg = NULL; | |
8822 | if (ret) { | |
8823 | wpa_printf(MSG_DEBUG, "nl80211: mesh join failed: ret=%d (%s)", | |
8824 | ret, strerror(-ret)); | |
a862e4a3 | 8825 | goto fail; |
6c1664f6 BC |
8826 | } |
8827 | ret = 0; | |
92a515b8 | 8828 | drv->assoc_freq = bss->freq = params->freq.freq; |
6c1664f6 BC |
8829 | wpa_printf(MSG_DEBUG, "nl80211: mesh join request send successfully"); |
8830 | ||
a862e4a3 | 8831 | fail: |
6c1664f6 BC |
8832 | nlmsg_free(msg); |
8833 | return ret; | |
8834 | } | |
8835 | ||
8836 | ||
0cb5f8d9 MH |
8837 | static int |
8838 | wpa_driver_nl80211_join_mesh(void *priv, | |
8839 | struct wpa_driver_mesh_join_params *params) | |
8840 | { | |
8841 | struct i802_bss *bss = priv; | |
8842 | int ret, timeout; | |
8843 | ||
8844 | timeout = params->conf.peer_link_timeout; | |
8845 | ||
8846 | /* Disable kernel inactivity timer */ | |
8847 | if (params->flags & WPA_DRIVER_MESH_FLAG_USER_MPM) | |
8848 | params->conf.peer_link_timeout = 0; | |
8849 | ||
8850 | ret = nl80211_join_mesh(bss, params); | |
8851 | if (ret == -EINVAL && params->conf.peer_link_timeout == 0) { | |
8852 | wpa_printf(MSG_DEBUG, | |
8853 | "nl80211: Mesh join retry for peer_link_timeout"); | |
8854 | /* | |
8855 | * Old kernel does not support setting | |
8856 | * NL80211_MESHCONF_PLINK_TIMEOUT to zero, so set 60 seconds | |
8857 | * into future from peer_link_timeout. | |
8858 | */ | |
8859 | params->conf.peer_link_timeout = timeout + 60; | |
8860 | ret = nl80211_join_mesh(priv, params); | |
8861 | } | |
8862 | ||
8863 | params->conf.peer_link_timeout = timeout; | |
8864 | return ret; | |
8865 | } | |
8866 | ||
8867 | ||
6c1664f6 BC |
8868 | static int wpa_driver_nl80211_leave_mesh(void *priv) |
8869 | { | |
8870 | struct i802_bss *bss = priv; | |
8871 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8872 | struct nl_msg *msg; | |
9725b784 | 8873 | int ret; |
6c1664f6 BC |
8874 | |
8875 | wpa_printf(MSG_DEBUG, "nl80211: mesh leave (ifindex=%d)", drv->ifindex); | |
9725b784 | 8876 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_LEAVE_MESH); |
6c1664f6 | 8877 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
6c1664f6 BC |
8878 | if (ret) { |
8879 | wpa_printf(MSG_DEBUG, "nl80211: mesh leave failed: ret=%d (%s)", | |
8880 | ret, strerror(-ret)); | |
a862e4a3 JM |
8881 | } else { |
8882 | wpa_printf(MSG_DEBUG, | |
8883 | "nl80211: mesh leave request send successfully"); | |
6c1664f6 | 8884 | } |
6c1664f6 | 8885 | |
f33c82d2 JM |
8886 | if (wpa_driver_nl80211_set_mode(drv->first_bss, |
8887 | NL80211_IFTYPE_STATION)) { | |
8888 | wpa_printf(MSG_INFO, | |
8889 | "nl80211: Failed to set interface into station mode"); | |
8890 | } | |
6c1664f6 BC |
8891 | return ret; |
8892 | } | |
8893 | ||
8894 | #endif /* CONFIG_MESH */ | |
8895 | ||
8896 | ||
ed4ddb6d KP |
8897 | static int wpa_driver_br_add_ip_neigh(void *priv, u8 version, |
8898 | const u8 *ipaddr, int prefixlen, | |
8899 | const u8 *addr) | |
71103bed KP |
8900 | { |
8901 | #ifdef CONFIG_LIBNL3_ROUTE | |
8902 | struct i802_bss *bss = priv; | |
8903 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8904 | struct rtnl_neigh *rn; | |
8905 | struct nl_addr *nl_ipaddr = NULL; | |
8906 | struct nl_addr *nl_lladdr = NULL; | |
ed4ddb6d | 8907 | int family, addrsize; |
71103bed KP |
8908 | int res; |
8909 | ||
ed4ddb6d | 8910 | if (!ipaddr || prefixlen == 0 || !addr) |
71103bed KP |
8911 | return -EINVAL; |
8912 | ||
8913 | if (bss->br_ifindex == 0) { | |
8914 | wpa_printf(MSG_DEBUG, | |
8915 | "nl80211: bridge must be set before adding an ip neigh to it"); | |
8916 | return -1; | |
8917 | } | |
8918 | ||
8919 | if (!drv->rtnl_sk) { | |
8920 | wpa_printf(MSG_DEBUG, | |
8921 | "nl80211: nl_sock for NETLINK_ROUTE is not initialized"); | |
8922 | return -1; | |
8923 | } | |
8924 | ||
ed4ddb6d KP |
8925 | if (version == 4) { |
8926 | family = AF_INET; | |
8927 | addrsize = 4; | |
8928 | } else if (version == 6) { | |
8929 | family = AF_INET6; | |
8930 | addrsize = 16; | |
8931 | } else { | |
8932 | return -EINVAL; | |
8933 | } | |
8934 | ||
71103bed KP |
8935 | rn = rtnl_neigh_alloc(); |
8936 | if (rn == NULL) | |
8937 | return -ENOMEM; | |
8938 | ||
8939 | /* set the destination ip address for neigh */ | |
ed4ddb6d | 8940 | nl_ipaddr = nl_addr_build(family, (void *) ipaddr, addrsize); |
71103bed KP |
8941 | if (nl_ipaddr == NULL) { |
8942 | wpa_printf(MSG_DEBUG, "nl80211: nl_ipaddr build failed"); | |
8943 | res = -ENOMEM; | |
8944 | goto errout; | |
8945 | } | |
8946 | nl_addr_set_prefixlen(nl_ipaddr, prefixlen); | |
8947 | res = rtnl_neigh_set_dst(rn, nl_ipaddr); | |
8948 | if (res) { | |
8949 | wpa_printf(MSG_DEBUG, | |
8950 | "nl80211: neigh set destination addr failed"); | |
8951 | goto errout; | |
8952 | } | |
8953 | ||
8954 | /* set the corresponding lladdr for neigh */ | |
8955 | nl_lladdr = nl_addr_build(AF_BRIDGE, (u8 *) addr, ETH_ALEN); | |
8956 | if (nl_lladdr == NULL) { | |
8957 | wpa_printf(MSG_DEBUG, "nl80211: neigh set lladdr failed"); | |
8958 | res = -ENOMEM; | |
8959 | goto errout; | |
8960 | } | |
8961 | rtnl_neigh_set_lladdr(rn, nl_lladdr); | |
8962 | ||
8963 | rtnl_neigh_set_ifindex(rn, bss->br_ifindex); | |
8964 | rtnl_neigh_set_state(rn, NUD_PERMANENT); | |
8965 | ||
8966 | res = rtnl_neigh_add(drv->rtnl_sk, rn, NLM_F_CREATE); | |
8967 | if (res) { | |
8968 | wpa_printf(MSG_DEBUG, | |
8969 | "nl80211: Adding bridge ip neigh failed: %s", | |
8970 | strerror(errno)); | |
8971 | } | |
8972 | errout: | |
8973 | if (nl_lladdr) | |
8974 | nl_addr_put(nl_lladdr); | |
8975 | if (nl_ipaddr) | |
8976 | nl_addr_put(nl_ipaddr); | |
8977 | if (rn) | |
8978 | rtnl_neigh_put(rn); | |
8979 | return res; | |
8980 | #else /* CONFIG_LIBNL3_ROUTE */ | |
8981 | return -1; | |
8982 | #endif /* CONFIG_LIBNL3_ROUTE */ | |
8983 | } | |
8984 | ||
8985 | ||
ed4ddb6d KP |
8986 | static int wpa_driver_br_delete_ip_neigh(void *priv, u8 version, |
8987 | const u8 *ipaddr) | |
71103bed KP |
8988 | { |
8989 | #ifdef CONFIG_LIBNL3_ROUTE | |
8990 | struct i802_bss *bss = priv; | |
8991 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8992 | struct rtnl_neigh *rn; | |
8993 | struct nl_addr *nl_ipaddr; | |
ed4ddb6d | 8994 | int family, addrsize; |
71103bed KP |
8995 | int res; |
8996 | ||
ed4ddb6d | 8997 | if (!ipaddr) |
71103bed KP |
8998 | return -EINVAL; |
8999 | ||
ed4ddb6d KP |
9000 | if (version == 4) { |
9001 | family = AF_INET; | |
9002 | addrsize = 4; | |
9003 | } else if (version == 6) { | |
9004 | family = AF_INET6; | |
9005 | addrsize = 16; | |
9006 | } else { | |
9007 | return -EINVAL; | |
9008 | } | |
9009 | ||
71103bed KP |
9010 | if (bss->br_ifindex == 0) { |
9011 | wpa_printf(MSG_DEBUG, | |
9012 | "nl80211: bridge must be set to delete an ip neigh"); | |
9013 | return -1; | |
9014 | } | |
9015 | ||
9016 | if (!drv->rtnl_sk) { | |
9017 | wpa_printf(MSG_DEBUG, | |
9018 | "nl80211: nl_sock for NETLINK_ROUTE is not initialized"); | |
9019 | return -1; | |
9020 | } | |
9021 | ||
9022 | rn = rtnl_neigh_alloc(); | |
9023 | if (rn == NULL) | |
9024 | return -ENOMEM; | |
9025 | ||
9026 | /* set the destination ip address for neigh */ | |
ed4ddb6d | 9027 | nl_ipaddr = nl_addr_build(family, (void *) ipaddr, addrsize); |
71103bed KP |
9028 | if (nl_ipaddr == NULL) { |
9029 | wpa_printf(MSG_DEBUG, "nl80211: nl_ipaddr build failed"); | |
9030 | res = -ENOMEM; | |
9031 | goto errout; | |
9032 | } | |
9033 | res = rtnl_neigh_set_dst(rn, nl_ipaddr); | |
9034 | if (res) { | |
9035 | wpa_printf(MSG_DEBUG, | |
9036 | "nl80211: neigh set destination addr failed"); | |
9037 | goto errout; | |
9038 | } | |
9039 | ||
9040 | rtnl_neigh_set_ifindex(rn, bss->br_ifindex); | |
9041 | ||
9042 | res = rtnl_neigh_delete(drv->rtnl_sk, rn, 0); | |
9043 | if (res) { | |
9044 | wpa_printf(MSG_DEBUG, | |
9045 | "nl80211: Deleting bridge ip neigh failed: %s", | |
9046 | strerror(errno)); | |
9047 | } | |
9048 | errout: | |
9049 | if (nl_ipaddr) | |
9050 | nl_addr_put(nl_ipaddr); | |
9051 | if (rn) | |
9052 | rtnl_neigh_put(rn); | |
9053 | return res; | |
9054 | #else /* CONFIG_LIBNL3_ROUTE */ | |
9055 | return -1; | |
9056 | #endif /* CONFIG_LIBNL3_ROUTE */ | |
9057 | } | |
9058 | ||
9059 | ||
73d2294f KP |
9060 | static int linux_write_system_file(const char *path, unsigned int val) |
9061 | { | |
9062 | char buf[50]; | |
9063 | int fd, len; | |
9064 | ||
9065 | len = os_snprintf(buf, sizeof(buf), "%u\n", val); | |
a9aaacbb | 9066 | if (os_snprintf_error(sizeof(buf), len)) |
73d2294f KP |
9067 | return -1; |
9068 | ||
9069 | fd = open(path, O_WRONLY); | |
9070 | if (fd < 0) | |
9071 | return -1; | |
9072 | ||
9073 | if (write(fd, buf, len) < 0) { | |
9074 | wpa_printf(MSG_DEBUG, | |
9075 | "nl80211: Failed to write Linux system file: %s with the value of %d", | |
9076 | path, val); | |
9077 | close(fd); | |
9078 | return -1; | |
9079 | } | |
9080 | close(fd); | |
9081 | ||
9082 | return 0; | |
9083 | } | |
9084 | ||
9085 | ||
9086 | static const char * drv_br_port_attr_str(enum drv_br_port_attr attr) | |
9087 | { | |
9088 | switch (attr) { | |
9089 | case DRV_BR_PORT_ATTR_PROXYARP: | |
bea8d9a3 | 9090 | return "proxyarp_wifi"; |
73d2294f KP |
9091 | case DRV_BR_PORT_ATTR_HAIRPIN_MODE: |
9092 | return "hairpin_mode"; | |
9093 | } | |
9094 | ||
9095 | return NULL; | |
9096 | } | |
9097 | ||
9098 | ||
9099 | static int wpa_driver_br_port_set_attr(void *priv, enum drv_br_port_attr attr, | |
9100 | unsigned int val) | |
9101 | { | |
9102 | struct i802_bss *bss = priv; | |
9103 | char path[128]; | |
9104 | const char *attr_txt; | |
9105 | ||
9106 | attr_txt = drv_br_port_attr_str(attr); | |
9107 | if (attr_txt == NULL) | |
9108 | return -EINVAL; | |
9109 | ||
9110 | os_snprintf(path, sizeof(path), "/sys/class/net/%s/brport/%s", | |
9111 | bss->ifname, attr_txt); | |
9112 | ||
9113 | if (linux_write_system_file(path, val)) | |
9114 | return -1; | |
9115 | ||
9116 | return 0; | |
9117 | } | |
9118 | ||
9119 | ||
7565752d KP |
9120 | static const char * drv_br_net_param_str(enum drv_br_net_param param) |
9121 | { | |
9122 | switch (param) { | |
9123 | case DRV_BR_NET_PARAM_GARP_ACCEPT: | |
9124 | return "arp_accept"; | |
60eb9e17 JM |
9125 | default: |
9126 | return NULL; | |
7565752d | 9127 | } |
7565752d KP |
9128 | } |
9129 | ||
9130 | ||
9131 | static int wpa_driver_br_set_net_param(void *priv, enum drv_br_net_param param, | |
9132 | unsigned int val) | |
9133 | { | |
9134 | struct i802_bss *bss = priv; | |
9135 | char path[128]; | |
9136 | const char *param_txt; | |
9137 | int ip_version = 4; | |
9138 | ||
60eb9e17 JM |
9139 | if (param == DRV_BR_MULTICAST_SNOOPING) { |
9140 | os_snprintf(path, sizeof(path), | |
9141 | "/sys/devices/virtual/net/%s/bridge/multicast_snooping", | |
9142 | bss->brname); | |
9143 | goto set_val; | |
9144 | } | |
9145 | ||
7565752d KP |
9146 | param_txt = drv_br_net_param_str(param); |
9147 | if (param_txt == NULL) | |
9148 | return -EINVAL; | |
9149 | ||
9150 | switch (param) { | |
9151 | case DRV_BR_NET_PARAM_GARP_ACCEPT: | |
9152 | ip_version = 4; | |
9153 | break; | |
9154 | default: | |
9155 | return -EINVAL; | |
9156 | } | |
9157 | ||
9158 | os_snprintf(path, sizeof(path), "/proc/sys/net/ipv%d/conf/%s/%s", | |
9159 | ip_version, bss->brname, param_txt); | |
9160 | ||
60eb9e17 | 9161 | set_val: |
7565752d KP |
9162 | if (linux_write_system_file(path, val)) |
9163 | return -1; | |
9164 | ||
9165 | return 0; | |
9166 | } | |
9167 | ||
9168 | ||
b658547d JM |
9169 | #ifdef CONFIG_DRIVER_NL80211_QCA |
9170 | ||
16689c7c PX |
9171 | static int hw_mode_to_qca_acs(enum hostapd_hw_mode hw_mode) |
9172 | { | |
9173 | switch (hw_mode) { | |
9174 | case HOSTAPD_MODE_IEEE80211B: | |
9175 | return QCA_ACS_MODE_IEEE80211B; | |
9176 | case HOSTAPD_MODE_IEEE80211G: | |
9177 | return QCA_ACS_MODE_IEEE80211G; | |
9178 | case HOSTAPD_MODE_IEEE80211A: | |
9179 | return QCA_ACS_MODE_IEEE80211A; | |
9180 | case HOSTAPD_MODE_IEEE80211AD: | |
9181 | return QCA_ACS_MODE_IEEE80211AD; | |
3784c058 PX |
9182 | case HOSTAPD_MODE_IEEE80211ANY: |
9183 | return QCA_ACS_MODE_IEEE80211ANY; | |
16689c7c PX |
9184 | default: |
9185 | return -1; | |
9186 | } | |
9187 | } | |
9188 | ||
9189 | ||
d0cdccd3 PX |
9190 | static int add_acs_freq_list(struct nl_msg *msg, const int *freq_list) |
9191 | { | |
9192 | int i, len, ret; | |
9193 | u32 *freqs; | |
9194 | ||
9195 | if (!freq_list) | |
9196 | return 0; | |
9197 | len = int_array_len(freq_list); | |
9198 | freqs = os_malloc(sizeof(u32) * len); | |
9199 | if (!freqs) | |
9200 | return -1; | |
9201 | for (i = 0; i < len; i++) | |
9202 | freqs[i] = freq_list[i]; | |
9203 | ret = nla_put(msg, QCA_WLAN_VENDOR_ATTR_ACS_FREQ_LIST, | |
9204 | sizeof(u32) * len, freqs); | |
9205 | os_free(freqs); | |
9206 | return ret; | |
9207 | } | |
9208 | ||
9209 | ||
16689c7c PX |
9210 | static int wpa_driver_do_acs(void *priv, struct drv_acs_params *params) |
9211 | { | |
9212 | struct i802_bss *bss = priv; | |
9213 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
9214 | struct nl_msg *msg; | |
9215 | struct nlattr *data; | |
a862e4a3 | 9216 | int ret; |
16689c7c PX |
9217 | int mode; |
9218 | ||
9219 | mode = hw_mode_to_qca_acs(params->hw_mode); | |
9220 | if (mode < 0) | |
9221 | return -1; | |
9222 | ||
9725b784 | 9223 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
a862e4a3 JM |
9224 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
9225 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | |
9226 | QCA_NL80211_VENDOR_SUBCMD_DO_ACS) || | |
9227 | !(data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || | |
9228 | nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_ACS_HW_MODE, mode) || | |
9229 | (params->ht_enabled && | |
9230 | nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_HT_ENABLED)) || | |
9231 | (params->ht40_enabled && | |
857d9422 MM |
9232 | nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_HT40_ENABLED)) || |
9233 | (params->vht_enabled && | |
9234 | nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_VHT_ENABLED)) || | |
9235 | nla_put_u16(msg, QCA_WLAN_VENDOR_ATTR_ACS_CHWIDTH, | |
9236 | params->ch_width) || | |
9237 | (params->ch_list_len && | |
9238 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_ACS_CH_LIST, params->ch_list_len, | |
d0cdccd3 PX |
9239 | params->ch_list)) || |
9240 | add_acs_freq_list(msg, params->freq_list)) { | |
a862e4a3 JM |
9241 | nlmsg_free(msg); |
9242 | return -ENOBUFS; | |
9243 | } | |
16689c7c PX |
9244 | nla_nest_end(msg, data); |
9245 | ||
857d9422 MM |
9246 | wpa_printf(MSG_DEBUG, |
9247 | "nl80211: ACS Params: HW_MODE: %d HT: %d HT40: %d VHT: %d BW: %d CH_LIST_LEN: %u", | |
9248 | params->hw_mode, params->ht_enabled, params->ht40_enabled, | |
9249 | params->vht_enabled, params->ch_width, params->ch_list_len); | |
9250 | ||
16689c7c | 9251 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
16689c7c PX |
9252 | if (ret) { |
9253 | wpa_printf(MSG_DEBUG, | |
9254 | "nl80211: Failed to invoke driver ACS function: %s", | |
9255 | strerror(errno)); | |
9256 | } | |
16689c7c PX |
9257 | return ret; |
9258 | } | |
9259 | ||
9260 | ||
844dfeb8 SD |
9261 | static int nl80211_set_band(void *priv, enum set_band band) |
9262 | { | |
9263 | struct i802_bss *bss = priv; | |
9264 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
9265 | struct nl_msg *msg; | |
9266 | struct nlattr *data; | |
9267 | int ret; | |
9268 | enum qca_set_band qca_band; | |
9269 | ||
9270 | if (!drv->setband_vendor_cmd_avail) | |
9271 | return -1; | |
9272 | ||
9273 | switch (band) { | |
9274 | case WPA_SETBAND_AUTO: | |
9275 | qca_band = QCA_SETBAND_AUTO; | |
9276 | break; | |
9277 | case WPA_SETBAND_5G: | |
9278 | qca_band = QCA_SETBAND_5G; | |
9279 | break; | |
9280 | case WPA_SETBAND_2G: | |
9281 | qca_band = QCA_SETBAND_2G; | |
9282 | break; | |
9283 | default: | |
9284 | return -1; | |
9285 | } | |
9286 | ||
9287 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || | |
9288 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || | |
9289 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | |
9290 | QCA_NL80211_VENDOR_SUBCMD_SETBAND) || | |
9291 | !(data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || | |
9292 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_SETBAND_VALUE, qca_band)) { | |
9293 | nlmsg_free(msg); | |
9294 | return -ENOBUFS; | |
9295 | } | |
9296 | nla_nest_end(msg, data); | |
9297 | ||
9298 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
9299 | if (ret) { | |
9300 | wpa_printf(MSG_DEBUG, | |
9301 | "nl80211: Driver setband function failed: %s", | |
9302 | strerror(errno)); | |
9303 | } | |
9304 | return ret; | |
9305 | } | |
9306 | ||
9307 | ||
98342208 AK |
9308 | struct nl80211_pcl { |
9309 | unsigned int num; | |
9310 | unsigned int *freq_list; | |
9311 | }; | |
9312 | ||
9313 | static int preferred_freq_info_handler(struct nl_msg *msg, void *arg) | |
9314 | { | |
9315 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
9316 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
9317 | struct nl80211_pcl *param = arg; | |
9318 | struct nlattr *nl_vend, *attr; | |
9319 | enum qca_iface_type iface_type; | |
9320 | struct nlattr *tb_vendor[QCA_WLAN_VENDOR_ATTR_MAX + 1]; | |
9321 | unsigned int num, max_num; | |
9322 | u32 *freqs; | |
9323 | ||
9324 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
9325 | genlmsg_attrlen(gnlh, 0), NULL); | |
9326 | ||
9327 | nl_vend = tb[NL80211_ATTR_VENDOR_DATA]; | |
9328 | if (!nl_vend) | |
9329 | return NL_SKIP; | |
9330 | ||
9331 | nla_parse(tb_vendor, QCA_WLAN_VENDOR_ATTR_MAX, | |
9332 | nla_data(nl_vend), nla_len(nl_vend), NULL); | |
9333 | ||
9334 | attr = tb_vendor[ | |
9335 | QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST_IFACE_TYPE]; | |
9336 | if (!attr) { | |
9337 | wpa_printf(MSG_ERROR, "nl80211: iface_type couldn't be found"); | |
9338 | param->num = 0; | |
9339 | return NL_SKIP; | |
9340 | } | |
9341 | ||
9342 | iface_type = (enum qca_iface_type) nla_get_u32(attr); | |
9343 | wpa_printf(MSG_DEBUG, "nl80211: Driver returned iface_type=%d", | |
9344 | iface_type); | |
9345 | ||
9346 | attr = tb_vendor[QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST]; | |
9347 | if (!attr) { | |
9348 | wpa_printf(MSG_ERROR, | |
9349 | "nl80211: preferred_freq_list couldn't be found"); | |
9350 | param->num = 0; | |
9351 | return NL_SKIP; | |
9352 | } | |
9353 | ||
9354 | /* | |
9355 | * param->num has the maximum number of entries for which there | |
9356 | * is room in the freq_list provided by the caller. | |
9357 | */ | |
9358 | freqs = nla_data(attr); | |
9359 | max_num = nla_len(attr) / sizeof(u32); | |
9360 | if (max_num > param->num) | |
9361 | max_num = param->num; | |
9362 | for (num = 0; num < max_num; num++) | |
9363 | param->freq_list[num] = freqs[num]; | |
9364 | param->num = num; | |
9365 | ||
9366 | return NL_SKIP; | |
9367 | } | |
9368 | ||
9369 | ||
9370 | static int nl80211_get_pref_freq_list(void *priv, | |
9371 | enum wpa_driver_if_type if_type, | |
9372 | unsigned int *num, | |
9373 | unsigned int *freq_list) | |
9374 | { | |
9375 | struct i802_bss *bss = priv; | |
9376 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
9377 | struct nl_msg *msg; | |
9378 | int ret; | |
9379 | unsigned int i; | |
9380 | struct nlattr *params; | |
9381 | struct nl80211_pcl param; | |
9382 | enum qca_iface_type iface_type; | |
9383 | ||
9384 | if (!drv->get_pref_freq_list) | |
9385 | return -1; | |
9386 | ||
9387 | switch (if_type) { | |
9388 | case WPA_IF_STATION: | |
9389 | iface_type = QCA_IFACE_TYPE_STA; | |
9390 | break; | |
9391 | case WPA_IF_AP_BSS: | |
9392 | iface_type = QCA_IFACE_TYPE_AP; | |
9393 | break; | |
9394 | case WPA_IF_P2P_GO: | |
9395 | iface_type = QCA_IFACE_TYPE_P2P_GO; | |
9396 | break; | |
9397 | case WPA_IF_P2P_CLIENT: | |
9398 | iface_type = QCA_IFACE_TYPE_P2P_CLIENT; | |
9399 | break; | |
9400 | case WPA_IF_IBSS: | |
9401 | iface_type = QCA_IFACE_TYPE_IBSS; | |
9402 | break; | |
9403 | case WPA_IF_TDLS: | |
9404 | iface_type = QCA_IFACE_TYPE_TDLS; | |
9405 | break; | |
9406 | default: | |
9407 | return -1; | |
9408 | } | |
9409 | ||
9410 | param.num = *num; | |
9411 | param.freq_list = freq_list; | |
9412 | ||
9413 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || | |
9414 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, drv->ifindex) || | |
9415 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || | |
9416 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | |
9417 | QCA_NL80211_VENDOR_SUBCMD_GET_PREFERRED_FREQ_LIST) || | |
9418 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || | |
9419 | nla_put_u32(msg, | |
9420 | QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST_IFACE_TYPE, | |
9421 | iface_type)) { | |
9422 | wpa_printf(MSG_ERROR, | |
9423 | "%s: err in adding vendor_cmd and vendor_data", | |
9424 | __func__); | |
9425 | nlmsg_free(msg); | |
9426 | return -1; | |
9427 | } | |
9428 | nla_nest_end(msg, params); | |
9429 | ||
9430 | os_memset(freq_list, 0, *num * sizeof(freq_list[0])); | |
9431 | ret = send_and_recv_msgs(drv, msg, preferred_freq_info_handler, ¶m); | |
9432 | if (ret) { | |
9433 | wpa_printf(MSG_ERROR, | |
9434 | "%s: err in send_and_recv_msgs", __func__); | |
9435 | return ret; | |
9436 | } | |
9437 | ||
9438 | *num = param.num; | |
9439 | ||
9440 | for (i = 0; i < *num; i++) { | |
9441 | wpa_printf(MSG_DEBUG, "nl80211: preferred_channel_list[%d]=%d", | |
9442 | i, freq_list[i]); | |
9443 | } | |
9444 | ||
9445 | return 0; | |
9446 | } | |
9447 | ||
9448 | ||
7c813acf AK |
9449 | static int nl80211_set_prob_oper_freq(void *priv, unsigned int freq) |
9450 | { | |
9451 | struct i802_bss *bss = priv; | |
9452 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
9453 | struct nl_msg *msg; | |
9454 | int ret; | |
9455 | struct nlattr *params; | |
9456 | ||
9457 | if (!drv->set_prob_oper_freq) | |
9458 | return -1; | |
9459 | ||
9460 | wpa_printf(MSG_DEBUG, | |
9461 | "nl80211: Set P2P probable operating freq %u for ifindex %d", | |
9462 | freq, bss->ifindex); | |
9463 | ||
9464 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || | |
9465 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || | |
9466 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | |
9467 | QCA_NL80211_VENDOR_SUBCMD_SET_PROBABLE_OPER_CHANNEL) || | |
9468 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || | |
9469 | nla_put_u32(msg, | |
9470 | QCA_WLAN_VENDOR_ATTR_PROBABLE_OPER_CHANNEL_IFACE_TYPE, | |
9471 | QCA_IFACE_TYPE_P2P_CLIENT) || | |
9472 | nla_put_u32(msg, | |
9473 | QCA_WLAN_VENDOR_ATTR_PROBABLE_OPER_CHANNEL_FREQ, | |
9474 | freq)) { | |
9475 | wpa_printf(MSG_ERROR, | |
9476 | "%s: err in adding vendor_cmd and vendor_data", | |
9477 | __func__); | |
9478 | nlmsg_free(msg); | |
9479 | return -1; | |
9480 | } | |
9481 | nla_nest_end(msg, params); | |
9482 | ||
9483 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
9484 | msg = NULL; | |
9485 | if (ret) { | |
9486 | wpa_printf(MSG_ERROR, "%s: err in send_and_recv_msgs", | |
9487 | __func__); | |
9488 | return ret; | |
9489 | } | |
9490 | nlmsg_free(msg); | |
9491 | return 0; | |
9492 | } | |
9493 | ||
a6f5b193 PX |
9494 | |
9495 | static int nl80211_p2p_lo_start(void *priv, unsigned int freq, | |
9496 | unsigned int period, unsigned int interval, | |
9497 | unsigned int count, const u8 *device_types, | |
9498 | size_t dev_types_len, | |
9499 | const u8 *ies, size_t ies_len) | |
9500 | { | |
9501 | struct i802_bss *bss = priv; | |
9502 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
9503 | struct nl_msg *msg; | |
9504 | struct nlattr *container; | |
9505 | int ret; | |
9506 | ||
9507 | wpa_printf(MSG_DEBUG, | |
9508 | "nl80211: Start P2P Listen offload: freq=%u, period=%u, interval=%u, count=%u", | |
9509 | freq, period, interval, count); | |
9510 | ||
9511 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_P2P_LISTEN_OFFLOAD)) | |
9512 | return -1; | |
9513 | ||
9514 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || | |
9515 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || | |
9516 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | |
9517 | QCA_NL80211_VENDOR_SUBCMD_P2P_LISTEN_OFFLOAD_START)) | |
9518 | goto fail; | |
9519 | ||
9520 | container = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); | |
9521 | if (!container) | |
9522 | goto fail; | |
9523 | ||
9524 | if (nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_CHANNEL, | |
9525 | freq) || | |
9526 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_PERIOD, | |
9527 | period) || | |
9528 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_INTERVAL, | |
9529 | interval) || | |
9530 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_COUNT, | |
9531 | count) || | |
9532 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_DEVICE_TYPES, | |
9533 | dev_types_len, device_types) || | |
9534 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_VENDOR_IE, | |
9535 | ies_len, ies)) | |
9536 | goto fail; | |
9537 | ||
9538 | nla_nest_end(msg, container); | |
9539 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
9540 | msg = NULL; | |
9541 | if (ret) { | |
9542 | wpa_printf(MSG_DEBUG, | |
9543 | "nl80211: Failed to send P2P Listen offload vendor command"); | |
9544 | goto fail; | |
9545 | } | |
9546 | ||
9547 | return 0; | |
9548 | ||
9549 | fail: | |
9550 | nlmsg_free(msg); | |
9551 | return -1; | |
9552 | } | |
9553 | ||
9554 | ||
9555 | static int nl80211_p2p_lo_stop(void *priv) | |
9556 | { | |
9557 | struct i802_bss *bss = priv; | |
9558 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
9559 | struct nl_msg *msg; | |
9560 | ||
9561 | wpa_printf(MSG_DEBUG, "nl80211: Stop P2P Listen offload"); | |
9562 | ||
9563 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_P2P_LISTEN_OFFLOAD)) | |
9564 | return -1; | |
9565 | ||
9566 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || | |
9567 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || | |
9568 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | |
9569 | QCA_NL80211_VENDOR_SUBCMD_P2P_LISTEN_OFFLOAD_STOP)) { | |
9570 | nlmsg_free(msg); | |
9571 | return -1; | |
9572 | } | |
9573 | ||
9574 | return send_and_recv_msgs(drv, msg, NULL, NULL); | |
9575 | } | |
9576 | ||
2e4e4fb7 SD |
9577 | |
9578 | static int nl80211_set_tdls_mode(void *priv, int tdls_external_control) | |
9579 | { | |
9580 | struct i802_bss *bss = priv; | |
9581 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
9582 | struct nl_msg *msg; | |
9583 | struct nlattr *params; | |
9584 | int ret; | |
9585 | u32 tdls_mode; | |
9586 | ||
9587 | wpa_printf(MSG_DEBUG, | |
9588 | "nl80211: Set TDKS mode: tdls_external_control=%d", | |
9589 | tdls_external_control); | |
9590 | ||
9591 | if (tdls_external_control == 1) | |
9592 | tdls_mode = QCA_WLAN_VENDOR_TDLS_TRIGGER_MODE_IMPLICIT | | |
9593 | QCA_WLAN_VENDOR_TDLS_TRIGGER_MODE_EXTERNAL; | |
9594 | else | |
9595 | tdls_mode = QCA_WLAN_VENDOR_TDLS_TRIGGER_MODE_EXPLICIT; | |
9596 | ||
9597 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || | |
9598 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || | |
9599 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | |
9600 | QCA_NL80211_VENDOR_SUBCMD_CONFIGURE_TDLS)) | |
9601 | goto fail; | |
9602 | ||
9603 | params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); | |
9604 | if (!params) | |
9605 | goto fail; | |
9606 | ||
9607 | if (nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TDLS_CONFIG_TRIGGER_MODE, | |
9608 | tdls_mode)) | |
9609 | goto fail; | |
9610 | ||
9611 | nla_nest_end(msg, params); | |
9612 | ||
9613 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
9614 | msg = NULL; | |
9615 | if (ret) { | |
9616 | wpa_printf(MSG_ERROR, | |
9617 | "nl80211: Set TDLS mode failed: ret=%d (%s)", | |
9618 | ret, strerror(-ret)); | |
9619 | goto fail; | |
9620 | } | |
9621 | return 0; | |
9622 | fail: | |
9623 | nlmsg_free(msg); | |
9624 | return -1; | |
9625 | } | |
9626 | ||
b658547d JM |
9627 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
9628 | ||
7c813acf | 9629 | |
6922d440 IP |
9630 | static int nl80211_write_to_file(const char *name, unsigned int val) |
9631 | { | |
9632 | int fd, len; | |
9633 | char tmp[128]; | |
9634 | ||
9635 | fd = open(name, O_RDWR); | |
9636 | if (fd < 0) { | |
9637 | wpa_printf(MSG_ERROR, "nl80211: Failed to open %s: %s", | |
9638 | name, strerror(errno)); | |
9639 | return fd; | |
9640 | } | |
9641 | ||
9642 | len = os_snprintf(tmp, sizeof(tmp), "%u\n", val); | |
9643 | len = write(fd, tmp, len); | |
9644 | if (len < 0) | |
9645 | wpa_printf(MSG_ERROR, "nl80211: Failed to write to %s: %s", | |
9646 | name, strerror(errno)); | |
9647 | close(fd); | |
9648 | ||
9649 | return 0; | |
9650 | } | |
9651 | ||
9652 | ||
9653 | static int nl80211_configure_data_frame_filters(void *priv, u32 filter_flags) | |
9654 | { | |
9655 | struct i802_bss *bss = priv; | |
9656 | char path[128]; | |
9657 | int ret; | |
9658 | ||
9659 | wpa_printf(MSG_DEBUG, "nl80211: Data frame filter flags=0x%x", | |
9660 | filter_flags); | |
9661 | ||
9662 | /* Configure filtering of unicast frame encrypted using GTK */ | |
9663 | ret = os_snprintf(path, sizeof(path), | |
9664 | "/proc/sys/net/ipv4/conf/%s/drop_unicast_in_l2_multicast", | |
9665 | bss->ifname); | |
bd86ea08 JM |
9666 | if (os_snprintf_error(sizeof(path), ret)) |
9667 | return -1; | |
6922d440 IP |
9668 | |
9669 | ret = nl80211_write_to_file(path, | |
9670 | !!(filter_flags & | |
9671 | WPA_DATA_FRAME_FILTER_FLAG_GTK)); | |
9672 | if (ret) { | |
9673 | wpa_printf(MSG_ERROR, | |
9674 | "nl80211: Failed to set IPv4 unicast in multicast filter"); | |
9675 | return ret; | |
9676 | } | |
9677 | ||
9678 | os_snprintf(path, sizeof(path), | |
9679 | "/proc/sys/net/ipv6/conf/%s/drop_unicast_in_l2_multicast", | |
9680 | bss->ifname); | |
9681 | ret = nl80211_write_to_file(path, | |
9682 | !!(filter_flags & | |
9683 | WPA_DATA_FRAME_FILTER_FLAG_GTK)); | |
9684 | ||
9685 | if (ret) { | |
9686 | wpa_printf(MSG_ERROR, | |
9687 | "nl80211: Failed to set IPv6 unicast in multicast filter"); | |
9688 | return ret; | |
9689 | } | |
9690 | ||
9691 | /* Configure filtering of unicast frame encrypted using GTK */ | |
9692 | os_snprintf(path, sizeof(path), | |
9693 | "/proc/sys/net/ipv4/conf/%s/drop_gratuitous_arp", | |
9694 | bss->ifname); | |
9695 | ret = nl80211_write_to_file(path, | |
9696 | !!(filter_flags & | |
9697 | WPA_DATA_FRAME_FILTER_FLAG_ARP)); | |
9698 | if (ret) { | |
9699 | wpa_printf(MSG_ERROR, | |
9700 | "nl80211: Failed set gratuitous ARP filter"); | |
9701 | return ret; | |
9702 | } | |
9703 | ||
9704 | /* Configure filtering of IPv6 NA frames */ | |
9705 | os_snprintf(path, sizeof(path), | |
9706 | "/proc/sys/net/ipv6/conf/%s/drop_unsolicited_na", | |
9707 | bss->ifname); | |
9708 | ret = nl80211_write_to_file(path, | |
9709 | !!(filter_flags & | |
9710 | WPA_DATA_FRAME_FILTER_FLAG_NA)); | |
9711 | if (ret) { | |
9712 | wpa_printf(MSG_ERROR, | |
9713 | "nl80211: Failed to set unsolicited NA filter"); | |
9714 | return ret; | |
9715 | } | |
9716 | ||
9717 | return 0; | |
9718 | } | |
9719 | ||
9720 | ||
cc9a2575 KV |
9721 | static int nl80211_get_ext_capab(void *priv, enum wpa_driver_if_type type, |
9722 | const u8 **ext_capa, const u8 **ext_capa_mask, | |
9723 | unsigned int *ext_capa_len) | |
9724 | { | |
9725 | struct i802_bss *bss = priv; | |
9726 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
9727 | enum nl80211_iftype nlmode; | |
9728 | unsigned int i; | |
9729 | ||
9730 | if (!ext_capa || !ext_capa_mask || !ext_capa_len) | |
9731 | return -1; | |
9732 | ||
9733 | nlmode = wpa_driver_nl80211_if_type(type); | |
9734 | ||
9735 | /* By default, use the per-radio values */ | |
9736 | *ext_capa = drv->extended_capa; | |
9737 | *ext_capa_mask = drv->extended_capa_mask; | |
9738 | *ext_capa_len = drv->extended_capa_len; | |
9739 | ||
9740 | /* Replace the default value if a per-interface type value exists */ | |
9741 | for (i = 0; i < drv->num_iface_ext_capa; i++) { | |
9742 | if (nlmode == drv->iface_ext_capa[i].iftype) { | |
9743 | *ext_capa = drv->iface_ext_capa[i].ext_capa; | |
9744 | *ext_capa_mask = drv->iface_ext_capa[i].ext_capa_mask; | |
9745 | *ext_capa_len = drv->iface_ext_capa[i].ext_capa_len; | |
9746 | break; | |
9747 | } | |
9748 | } | |
9749 | ||
9750 | return 0; | |
9751 | } | |
9752 | ||
9753 | ||
3f5285e8 JM |
9754 | const struct wpa_driver_ops wpa_driver_nl80211_ops = { |
9755 | .name = "nl80211", | |
9756 | .desc = "Linux nl80211/cfg80211", | |
9757 | .get_bssid = wpa_driver_nl80211_get_bssid, | |
9758 | .get_ssid = wpa_driver_nl80211_get_ssid, | |
9ebce9c5 JM |
9759 | .set_key = driver_nl80211_set_key, |
9760 | .scan2 = driver_nl80211_scan2, | |
d21c63b9 LC |
9761 | .sched_scan = wpa_driver_nl80211_sched_scan, |
9762 | .stop_sched_scan = wpa_driver_nl80211_stop_sched_scan, | |
3f5285e8 | 9763 | .get_scan_results2 = wpa_driver_nl80211_get_scan_results, |
4f30addb | 9764 | .abort_scan = wpa_driver_nl80211_abort_scan, |
9ebce9c5 JM |
9765 | .deauthenticate = driver_nl80211_deauthenticate, |
9766 | .authenticate = driver_nl80211_authenticate, | |
3f5285e8 | 9767 | .associate = wpa_driver_nl80211_associate, |
f2ed8023 JM |
9768 | .global_init = nl80211_global_init, |
9769 | .global_deinit = nl80211_global_deinit, | |
9770 | .init2 = wpa_driver_nl80211_init, | |
9ebce9c5 | 9771 | .deinit = driver_nl80211_deinit, |
3f5285e8 JM |
9772 | .get_capa = wpa_driver_nl80211_get_capa, |
9773 | .set_operstate = wpa_driver_nl80211_set_operstate, | |
01652550 | 9774 | .set_supp_port = wpa_driver_nl80211_set_supp_port, |
6d158490 | 9775 | .set_country = wpa_driver_nl80211_set_country, |
f0793bf1 | 9776 | .get_country = wpa_driver_nl80211_get_country, |
19c3b566 | 9777 | .set_ap = wpa_driver_nl80211_set_ap, |
3c4ca363 | 9778 | .set_acl = wpa_driver_nl80211_set_acl, |
22a7c9d7 | 9779 | .if_add = wpa_driver_nl80211_if_add, |
9ebce9c5 JM |
9780 | .if_remove = driver_nl80211_if_remove, |
9781 | .send_mlme = driver_nl80211_send_mlme, | |
0fafeb54 | 9782 | .get_hw_feature_data = nl80211_get_hw_feature_data, |
0f4e8b4f | 9783 | .sta_add = wpa_driver_nl80211_sta_add, |
9ebce9c5 | 9784 | .sta_remove = driver_nl80211_sta_remove, |
db149ac9 | 9785 | .hapd_send_eapol = wpa_driver_nl80211_hapd_send_eapol, |
a8d6ffa4 | 9786 | .sta_set_flags = wpa_driver_nl80211_sta_set_flags, |
c5121837 | 9787 | .hapd_init = i802_init, |
c5121837 | 9788 | .hapd_deinit = i802_deinit, |
f7b3920c | 9789 | .set_wds_sta = i802_set_wds_sta, |
c5121837 JM |
9790 | .get_seqnum = i802_get_seqnum, |
9791 | .flush = i802_flush, | |
c5121837 JM |
9792 | .get_inact_sec = i802_get_inact_sec, |
9793 | .sta_clear_stats = i802_sta_clear_stats, | |
c5121837 JM |
9794 | .set_rts = i802_set_rts, |
9795 | .set_frag = i802_set_frag, | |
c5121837 | 9796 | .set_tx_queue_params = i802_set_tx_queue_params, |
9ebce9c5 | 9797 | .set_sta_vlan = driver_nl80211_set_sta_vlan, |
ee7ab173 JB |
9798 | .sta_deauth = i802_sta_deauth, |
9799 | .sta_disassoc = i802_sta_disassoc, | |
9ebce9c5 | 9800 | .read_sta_data = driver_nl80211_read_sta_data, |
e3802622 | 9801 | .set_freq = i802_set_freq, |
9ebce9c5 | 9802 | .send_action = driver_nl80211_send_action, |
5dfca53f | 9803 | .send_action_cancel_wait = wpa_driver_nl80211_send_action_cancel_wait, |
55777702 JM |
9804 | .remain_on_channel = wpa_driver_nl80211_remain_on_channel, |
9805 | .cancel_remain_on_channel = | |
9806 | wpa_driver_nl80211_cancel_remain_on_channel, | |
9ebce9c5 | 9807 | .probe_req_report = driver_nl80211_probe_req_report, |
af473088 | 9808 | .deinit_ap = wpa_driver_nl80211_deinit_ap, |
3c29244e | 9809 | .deinit_p2p_cli = wpa_driver_nl80211_deinit_p2p_cli, |
207ef3fb | 9810 | .resume = wpa_driver_nl80211_resume, |
b625473c | 9811 | .signal_monitor = nl80211_signal_monitor, |
1c5c7273 | 9812 | .signal_poll = nl80211_signal_poll, |
b91ab76e | 9813 | .send_frame = nl80211_send_frame, |
c55f774d | 9814 | .set_param = nl80211_set_param, |
6859f1cb | 9815 | .get_radio_name = nl80211_get_radio_name, |
a6efc65d JM |
9816 | .add_pmkid = nl80211_add_pmkid, |
9817 | .remove_pmkid = nl80211_remove_pmkid, | |
9818 | .flush_pmkid = nl80211_flush_pmkid, | |
b14a210c | 9819 | .set_rekey_info = nl80211_set_rekey_info, |
bcf24348 | 9820 | .poll_client = nl80211_poll_client, |
29f338af | 9821 | .set_p2p_powersave = nl80211_set_p2p_powersave, |
f90e9c1c | 9822 | .start_dfs_cac = nl80211_start_radar_detection, |
695c7038 | 9823 | .stop_ap = wpa_driver_nl80211_stop_ap, |
03ea1786 AN |
9824 | #ifdef CONFIG_TDLS |
9825 | .send_tdls_mgmt = nl80211_send_tdls_mgmt, | |
9826 | .tdls_oper = nl80211_tdls_oper, | |
72b2605f AN |
9827 | .tdls_enable_channel_switch = nl80211_tdls_enable_channel_switch, |
9828 | .tdls_disable_channel_switch = nl80211_tdls_disable_channel_switch, | |
03ea1786 | 9829 | #endif /* CONFIG_TDLS */ |
6a1ce395 | 9830 | .update_ft_ies = wpa_driver_nl80211_update_ft_ies, |
597b94f5 | 9831 | .get_mac_addr = wpa_driver_nl80211_get_macaddr, |
0185007c | 9832 | .get_survey = wpa_driver_nl80211_get_survey, |
a771c07d | 9833 | .status = wpa_driver_nl80211_status, |
1c4ffa87 | 9834 | .switch_channel = nl80211_switch_channel, |
0de38036 JM |
9835 | #ifdef ANDROID_P2P |
9836 | .set_noa = wpa_driver_set_p2p_noa, | |
9837 | .get_noa = wpa_driver_get_p2p_noa, | |
9838 | .set_ap_wps_ie = wpa_driver_set_ap_wps_p2p_ie, | |
9839 | #endif /* ANDROID_P2P */ | |
5e2c3490 | 9840 | #ifdef ANDROID |
ded14ce9 | 9841 | #ifndef ANDROID_LIB_STUB |
5e2c3490 | 9842 | .driver_cmd = wpa_driver_nl80211_driver_cmd, |
ded14ce9 | 9843 | #endif /* !ANDROID_LIB_STUB */ |
5e2c3490 | 9844 | #endif /* ANDROID */ |
adef8948 | 9845 | .vendor_cmd = nl80211_vendor_cmd, |
049105b4 | 9846 | .set_qos_map = nl80211_set_qos_map, |
e4fa8b12 | 9847 | .set_wowlan = nl80211_set_wowlan, |
fee354c7 | 9848 | .set_mac_addr = nl80211_set_mac_addr, |
6c1664f6 BC |
9849 | #ifdef CONFIG_MESH |
9850 | .init_mesh = wpa_driver_nl80211_init_mesh, | |
9851 | .join_mesh = wpa_driver_nl80211_join_mesh, | |
9852 | .leave_mesh = wpa_driver_nl80211_leave_mesh, | |
9853 | #endif /* CONFIG_MESH */ | |
71103bed KP |
9854 | .br_add_ip_neigh = wpa_driver_br_add_ip_neigh, |
9855 | .br_delete_ip_neigh = wpa_driver_br_delete_ip_neigh, | |
73d2294f | 9856 | .br_port_set_attr = wpa_driver_br_port_set_attr, |
7565752d | 9857 | .br_set_net_param = wpa_driver_br_set_net_param, |
dfa87878 MB |
9858 | .add_tx_ts = nl80211_add_ts, |
9859 | .del_tx_ts = nl80211_del_ts, | |
45e3fc72 | 9860 | .get_ifindex = nl80211_get_ifindex, |
b658547d | 9861 | #ifdef CONFIG_DRIVER_NL80211_QCA |
9607a1ae | 9862 | .roaming = nl80211_roaming, |
16689c7c | 9863 | .do_acs = wpa_driver_do_acs, |
844dfeb8 | 9864 | .set_band = nl80211_set_band, |
98342208 | 9865 | .get_pref_freq_list = nl80211_get_pref_freq_list, |
7c813acf | 9866 | .set_prob_oper_freq = nl80211_set_prob_oper_freq, |
a6f5b193 PX |
9867 | .p2p_lo_start = nl80211_p2p_lo_start, |
9868 | .p2p_lo_stop = nl80211_p2p_lo_stop, | |
cc9985d1 | 9869 | .set_default_scan_ies = nl80211_set_default_scan_ies, |
2e4e4fb7 | 9870 | .set_tdls_mode = nl80211_set_tdls_mode, |
b658547d | 9871 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
6922d440 | 9872 | .configure_data_frame_filters = nl80211_configure_data_frame_filters, |
cc9a2575 | 9873 | .get_ext_capab = nl80211_get_ext_capab, |
3f5285e8 | 9874 | }; |