]>
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 | |
2135f224 JM |
184 | static void add_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx); |
185 | static void del_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx); | |
97cfcf64 | 186 | static int have_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx); |
072ad14c | 187 | |
e87ef751 PX |
188 | static int nl80211_set_channel(struct i802_bss *bss, |
189 | struct hostapd_freq_params *freq, int set_chan); | |
4e5cb1a3 JM |
190 | static int nl80211_disable_11b_rates(struct wpa_driver_nl80211_data *drv, |
191 | int ifindex, int disabled); | |
504e905c | 192 | |
666e508c JM |
193 | static int nl80211_leave_ibss(struct wpa_driver_nl80211_data *drv, |
194 | int reset_mode); | |
21bdbe38 | 195 | |
bf83eab5 | 196 | static int i802_set_iface_flags(struct i802_bss *bss, int up); |
0ecff8d7 | 197 | static int nl80211_set_param(void *priv, const char *param); |
bf83eab5 | 198 | |
3f5285e8 | 199 | |
8d1fdde7 | 200 | /* Converts nl80211_chan_width to a common format */ |
f3407c66 | 201 | enum chan_width convert2width(int width) |
8d1fdde7 JD |
202 | { |
203 | switch (width) { | |
204 | case NL80211_CHAN_WIDTH_20_NOHT: | |
205 | return CHAN_WIDTH_20_NOHT; | |
206 | case NL80211_CHAN_WIDTH_20: | |
207 | return CHAN_WIDTH_20; | |
208 | case NL80211_CHAN_WIDTH_40: | |
209 | return CHAN_WIDTH_40; | |
210 | case NL80211_CHAN_WIDTH_80: | |
211 | return CHAN_WIDTH_80; | |
212 | case NL80211_CHAN_WIDTH_80P80: | |
213 | return CHAN_WIDTH_80P80; | |
214 | case NL80211_CHAN_WIDTH_160: | |
215 | return CHAN_WIDTH_160; | |
216 | } | |
217 | return CHAN_WIDTH_UNKNOWN; | |
218 | } | |
219 | ||
220 | ||
f3407c66 | 221 | int is_ap_interface(enum nl80211_iftype nlmode) |
b1f625e0 | 222 | { |
0e80ea2c JM |
223 | return nlmode == NL80211_IFTYPE_AP || |
224 | nlmode == NL80211_IFTYPE_P2P_GO; | |
b1f625e0 EP |
225 | } |
226 | ||
227 | ||
477af8f8 | 228 | int is_sta_interface(enum nl80211_iftype nlmode) |
b1f625e0 | 229 | { |
0e80ea2c JM |
230 | return nlmode == NL80211_IFTYPE_STATION || |
231 | nlmode == NL80211_IFTYPE_P2P_CLIENT; | |
b1f625e0 EP |
232 | } |
233 | ||
234 | ||
6a71413e | 235 | static int is_p2p_net_interface(enum nl80211_iftype nlmode) |
b3af99d2 | 236 | { |
0e80ea2c JM |
237 | return nlmode == NL80211_IFTYPE_P2P_CLIENT || |
238 | nlmode == NL80211_IFTYPE_P2P_GO; | |
b3af99d2 JM |
239 | } |
240 | ||
241 | ||
f3407c66 JM |
242 | struct i802_bss * get_bss_ifindex(struct wpa_driver_nl80211_data *drv, |
243 | int ifindex) | |
5dfbd725 JM |
244 | { |
245 | struct i802_bss *bss; | |
246 | ||
247 | for (bss = drv->first_bss; bss; bss = bss->next) { | |
248 | if (bss->ifindex == ifindex) | |
249 | return bss; | |
250 | } | |
251 | ||
252 | return NULL; | |
253 | } | |
254 | ||
255 | ||
afb0550a BC |
256 | static int is_mesh_interface(enum nl80211_iftype nlmode) |
257 | { | |
258 | return nlmode == NL80211_IFTYPE_MESH_POINT; | |
259 | } | |
260 | ||
261 | ||
f3407c66 | 262 | void nl80211_mark_disconnected(struct wpa_driver_nl80211_data *drv) |
add9b7a4 JM |
263 | { |
264 | if (drv->associated) | |
265 | os_memcpy(drv->prev_bssid, drv->bssid, ETH_ALEN); | |
266 | drv->associated = 0; | |
267 | os_memset(drv->bssid, 0, ETH_ALEN); | |
268 | } | |
269 | ||
270 | ||
6241fcb1 JM |
271 | /* nl80211 code */ |
272 | static int ack_handler(struct nl_msg *msg, void *arg) | |
273 | { | |
274 | int *err = arg; | |
275 | *err = 0; | |
276 | return NL_STOP; | |
277 | } | |
278 | ||
279 | static int finish_handler(struct nl_msg *msg, void *arg) | |
280 | { | |
8e8df255 JM |
281 | int *ret = arg; |
282 | *ret = 0; | |
6241fcb1 JM |
283 | return NL_SKIP; |
284 | } | |
285 | ||
286 | static int error_handler(struct sockaddr_nl *nla, struct nlmsgerr *err, | |
287 | void *arg) | |
288 | { | |
289 | int *ret = arg; | |
290 | *ret = err->error; | |
291 | return NL_SKIP; | |
292 | } | |
293 | ||
5b7b85f6 JM |
294 | |
295 | static int no_seq_check(struct nl_msg *msg, void *arg) | |
296 | { | |
297 | return NL_OK; | |
298 | } | |
299 | ||
300 | ||
bbd89bfc JM |
301 | static void nl80211_nlmsg_clear(struct nl_msg *msg) |
302 | { | |
303 | /* | |
304 | * Clear nlmsg data, e.g., to make sure key material is not left in | |
305 | * heap memory for unnecessarily long time. | |
306 | */ | |
307 | if (msg) { | |
308 | struct nlmsghdr *hdr = nlmsg_hdr(msg); | |
309 | void *data = nlmsg_data(hdr); | |
d58ade21 JM |
310 | /* |
311 | * This would use nlmsg_datalen() or the older nlmsg_len() if | |
312 | * only libnl were to maintain a stable API.. Neither will work | |
313 | * with all released versions, so just calculate the length | |
314 | * here. | |
315 | */ | |
316 | int len = hdr->nlmsg_len - NLMSG_HDRLEN; | |
bbd89bfc JM |
317 | |
318 | os_memset(data, 0, len); | |
319 | } | |
320 | } | |
321 | ||
322 | ||
d6c9aab8 | 323 | static int send_and_recv(struct nl80211_global *global, |
58f6fbe0 JM |
324 | struct nl_handle *nl_handle, struct nl_msg *msg, |
325 | int (*valid_handler)(struct nl_msg *, void *), | |
326 | void *valid_data) | |
6241fcb1 JM |
327 | { |
328 | struct nl_cb *cb; | |
329 | int err = -ENOMEM; | |
330 | ||
9725b784 JM |
331 | if (!msg) |
332 | return -ENOMEM; | |
333 | ||
d6c9aab8 | 334 | cb = nl_cb_clone(global->nl_cb); |
6241fcb1 JM |
335 | if (!cb) |
336 | goto out; | |
337 | ||
58f6fbe0 | 338 | err = nl_send_auto_complete(nl_handle, msg); |
6241fcb1 JM |
339 | if (err < 0) |
340 | goto out; | |
341 | ||
342 | err = 1; | |
343 | ||
344 | nl_cb_err(cb, NL_CB_CUSTOM, error_handler, &err); | |
8e8df255 | 345 | nl_cb_set(cb, NL_CB_FINISH, NL_CB_CUSTOM, finish_handler, &err); |
6241fcb1 JM |
346 | nl_cb_set(cb, NL_CB_ACK, NL_CB_CUSTOM, ack_handler, &err); |
347 | ||
348 | if (valid_handler) | |
349 | nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, | |
350 | valid_handler, valid_data); | |
351 | ||
34068ac3 JM |
352 | while (err > 0) { |
353 | int res = nl_recvmsgs(nl_handle, cb); | |
d3d04831 | 354 | if (res < 0) { |
34068ac3 JM |
355 | wpa_printf(MSG_INFO, |
356 | "nl80211: %s->nl_recvmsgs failed: %d", | |
357 | __func__, res); | |
358 | } | |
359 | } | |
6241fcb1 JM |
360 | out: |
361 | nl_cb_put(cb); | |
bbd89bfc JM |
362 | if (!valid_handler && valid_data == (void *) -1) |
363 | nl80211_nlmsg_clear(msg); | |
6241fcb1 JM |
364 | nlmsg_free(msg); |
365 | return err; | |
366 | } | |
367 | ||
368 | ||
f3407c66 JM |
369 | int send_and_recv_msgs(struct wpa_driver_nl80211_data *drv, |
370 | struct nl_msg *msg, | |
371 | int (*valid_handler)(struct nl_msg *, void *), | |
372 | void *valid_data) | |
58f6fbe0 | 373 | { |
481234cf | 374 | return send_and_recv(drv->global, drv->global->nl, msg, |
d6c9aab8 | 375 | valid_handler, valid_data); |
58f6fbe0 JM |
376 | } |
377 | ||
378 | ||
97865538 JM |
379 | struct family_data { |
380 | const char *group; | |
381 | int id; | |
382 | }; | |
383 | ||
384 | ||
385 | static int family_handler(struct nl_msg *msg, void *arg) | |
386 | { | |
387 | struct family_data *res = arg; | |
388 | struct nlattr *tb[CTRL_ATTR_MAX + 1]; | |
389 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
390 | struct nlattr *mcgrp; | |
391 | int i; | |
392 | ||
393 | nla_parse(tb, CTRL_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
394 | genlmsg_attrlen(gnlh, 0), NULL); | |
395 | if (!tb[CTRL_ATTR_MCAST_GROUPS]) | |
396 | return NL_SKIP; | |
397 | ||
398 | nla_for_each_nested(mcgrp, tb[CTRL_ATTR_MCAST_GROUPS], i) { | |
399 | struct nlattr *tb2[CTRL_ATTR_MCAST_GRP_MAX + 1]; | |
400 | nla_parse(tb2, CTRL_ATTR_MCAST_GRP_MAX, nla_data(mcgrp), | |
401 | nla_len(mcgrp), NULL); | |
402 | if (!tb2[CTRL_ATTR_MCAST_GRP_NAME] || | |
403 | !tb2[CTRL_ATTR_MCAST_GRP_ID] || | |
404 | os_strncmp(nla_data(tb2[CTRL_ATTR_MCAST_GRP_NAME]), | |
405 | res->group, | |
406 | nla_len(tb2[CTRL_ATTR_MCAST_GRP_NAME])) != 0) | |
407 | continue; | |
408 | res->id = nla_get_u32(tb2[CTRL_ATTR_MCAST_GRP_ID]); | |
409 | break; | |
410 | }; | |
411 | ||
412 | return NL_SKIP; | |
413 | } | |
414 | ||
415 | ||
d6c9aab8 | 416 | static int nl_get_multicast_id(struct nl80211_global *global, |
97865538 JM |
417 | const char *family, const char *group) |
418 | { | |
419 | struct nl_msg *msg; | |
a862e4a3 | 420 | int ret; |
97865538 JM |
421 | struct family_data res = { group, -ENOENT }; |
422 | ||
423 | msg = nlmsg_alloc(); | |
424 | if (!msg) | |
425 | return -ENOMEM; | |
a862e4a3 JM |
426 | if (!genlmsg_put(msg, 0, 0, genl_ctrl_resolve(global->nl, "nlctrl"), |
427 | 0, 0, CTRL_CMD_GETFAMILY, 0) || | |
428 | nla_put_string(msg, CTRL_ATTR_FAMILY_NAME, family)) { | |
429 | nlmsg_free(msg); | |
430 | return -1; | |
431 | } | |
97865538 | 432 | |
1033315f | 433 | ret = send_and_recv(global, global->nl, msg, family_handler, &res); |
97865538 JM |
434 | if (ret == 0) |
435 | ret = res.id; | |
97865538 JM |
436 | return ret; |
437 | } | |
438 | ||
439 | ||
f3407c66 JM |
440 | void * nl80211_cmd(struct wpa_driver_nl80211_data *drv, |
441 | struct nl_msg *msg, int flags, uint8_t cmd) | |
9fb04070 | 442 | { |
335d42b1 | 443 | return genlmsg_put(msg, 0, 0, drv->global->nl80211_id, |
276e2d67 | 444 | 0, flags, cmd, 0); |
9fb04070 JM |
445 | } |
446 | ||
447 | ||
350acc35 JM |
448 | static int nl80211_set_iface_id(struct nl_msg *msg, struct i802_bss *bss) |
449 | { | |
450 | if (bss->wdev_id_set) | |
451 | return nla_put_u64(msg, NL80211_ATTR_WDEV, bss->wdev_id); | |
452 | return nla_put_u32(msg, NL80211_ATTR_IFINDEX, bss->ifindex); | |
453 | } | |
454 | ||
455 | ||
07c7757c JM |
456 | struct nl_msg * nl80211_cmd_msg(struct i802_bss *bss, int flags, uint8_t cmd) |
457 | { | |
458 | struct nl_msg *msg; | |
459 | ||
460 | msg = nlmsg_alloc(); | |
461 | if (!msg) | |
462 | return NULL; | |
463 | ||
464 | if (!nl80211_cmd(bss->drv, msg, flags, cmd) || | |
465 | nl80211_set_iface_id(msg, bss) < 0) { | |
466 | nlmsg_free(msg); | |
467 | return NULL; | |
468 | } | |
469 | ||
470 | return msg; | |
471 | } | |
472 | ||
473 | ||
474 | static struct nl_msg * | |
475 | nl80211_ifindex_msg(struct wpa_driver_nl80211_data *drv, int ifindex, | |
476 | int flags, uint8_t cmd) | |
477 | { | |
478 | struct nl_msg *msg; | |
479 | ||
480 | msg = nlmsg_alloc(); | |
481 | if (!msg) | |
482 | return NULL; | |
483 | ||
484 | if (!nl80211_cmd(drv, msg, flags, cmd) || | |
485 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex)) { | |
486 | nlmsg_free(msg); | |
487 | return NULL; | |
488 | } | |
489 | ||
490 | return msg; | |
491 | } | |
492 | ||
493 | ||
494 | struct nl_msg * nl80211_drv_msg(struct wpa_driver_nl80211_data *drv, int flags, | |
495 | uint8_t cmd) | |
496 | { | |
497 | return nl80211_ifindex_msg(drv, drv->ifindex, flags, cmd); | |
498 | } | |
499 | ||
500 | ||
501 | struct nl_msg * nl80211_bss_msg(struct i802_bss *bss, int flags, uint8_t cmd) | |
502 | { | |
503 | return nl80211_ifindex_msg(bss->drv, bss->ifindex, flags, cmd); | |
504 | } | |
505 | ||
506 | ||
e32ad281 JB |
507 | struct wiphy_idx_data { |
508 | int wiphy_idx; | |
01517c8b | 509 | enum nl80211_iftype nlmode; |
597b94f5 | 510 | u8 *macaddr; |
e32ad281 JB |
511 | }; |
512 | ||
513 | ||
514 | static int netdev_info_handler(struct nl_msg *msg, void *arg) | |
515 | { | |
516 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
517 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
518 | struct wiphy_idx_data *info = arg; | |
519 | ||
520 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
521 | genlmsg_attrlen(gnlh, 0), NULL); | |
522 | ||
523 | if (tb[NL80211_ATTR_WIPHY]) | |
524 | info->wiphy_idx = nla_get_u32(tb[NL80211_ATTR_WIPHY]); | |
525 | ||
01517c8b JB |
526 | if (tb[NL80211_ATTR_IFTYPE]) |
527 | info->nlmode = nla_get_u32(tb[NL80211_ATTR_IFTYPE]); | |
528 | ||
597b94f5 AS |
529 | if (tb[NL80211_ATTR_MAC] && info->macaddr) |
530 | os_memcpy(info->macaddr, nla_data(tb[NL80211_ATTR_MAC]), | |
531 | ETH_ALEN); | |
532 | ||
e32ad281 JB |
533 | return NL_SKIP; |
534 | } | |
535 | ||
536 | ||
f3407c66 | 537 | int nl80211_get_wiphy_index(struct i802_bss *bss) |
e32ad281 JB |
538 | { |
539 | struct nl_msg *msg; | |
540 | struct wiphy_idx_data data = { | |
541 | .wiphy_idx = -1, | |
597b94f5 | 542 | .macaddr = NULL, |
e32ad281 JB |
543 | }; |
544 | ||
56f77852 | 545 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_GET_INTERFACE))) |
a862e4a3 | 546 | return -1; |
e32ad281 JB |
547 | |
548 | if (send_and_recv_msgs(bss->drv, msg, netdev_info_handler, &data) == 0) | |
549 | return data.wiphy_idx; | |
e32ad281 JB |
550 | return -1; |
551 | } | |
552 | ||
553 | ||
01517c8b JB |
554 | static enum nl80211_iftype nl80211_get_ifmode(struct i802_bss *bss) |
555 | { | |
556 | struct nl_msg *msg; | |
557 | struct wiphy_idx_data data = { | |
597b94f5 AS |
558 | .nlmode = NL80211_IFTYPE_UNSPECIFIED, |
559 | .macaddr = NULL, | |
01517c8b JB |
560 | }; |
561 | ||
56f77852 | 562 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_GET_INTERFACE))) |
a862e4a3 | 563 | return NL80211_IFTYPE_UNSPECIFIED; |
01517c8b JB |
564 | |
565 | if (send_and_recv_msgs(bss->drv, msg, netdev_info_handler, &data) == 0) | |
566 | return data.nlmode; | |
01517c8b JB |
567 | return NL80211_IFTYPE_UNSPECIFIED; |
568 | } | |
01517c8b JB |
569 | |
570 | ||
597b94f5 AS |
571 | static int nl80211_get_macaddr(struct i802_bss *bss) |
572 | { | |
573 | struct nl_msg *msg; | |
574 | struct wiphy_idx_data data = { | |
575 | .macaddr = bss->addr, | |
576 | }; | |
577 | ||
56f77852 | 578 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_GET_INTERFACE))) |
a862e4a3 | 579 | return -1; |
597b94f5 | 580 | |
597b94f5 | 581 | return send_and_recv_msgs(bss->drv, msg, netdev_info_handler, &data); |
597b94f5 | 582 | } |
597b94f5 AS |
583 | |
584 | ||
e32ad281 JB |
585 | static int nl80211_register_beacons(struct wpa_driver_nl80211_data *drv, |
586 | struct nl80211_wiphy_data *w) | |
587 | { | |
588 | struct nl_msg *msg; | |
a862e4a3 | 589 | int ret; |
e32ad281 JB |
590 | |
591 | msg = nlmsg_alloc(); | |
592 | if (!msg) | |
593 | return -1; | |
594 | ||
a862e4a3 JM |
595 | if (!nl80211_cmd(drv, msg, 0, NL80211_CMD_REGISTER_BEACONS) || |
596 | nla_put_u32(msg, NL80211_ATTR_WIPHY, w->wiphy_idx)) { | |
597 | nlmsg_free(msg); | |
598 | return -1; | |
599 | } | |
e32ad281 | 600 | |
481234cf | 601 | ret = send_and_recv(drv->global, w->nl_beacons, msg, NULL, NULL); |
e32ad281 JB |
602 | if (ret) { |
603 | wpa_printf(MSG_DEBUG, "nl80211: Register beacons command " | |
604 | "failed: ret=%d (%s)", | |
605 | ret, strerror(-ret)); | |
e32ad281 | 606 | } |
e32ad281 JB |
607 | return ret; |
608 | } | |
609 | ||
610 | ||
611 | static void nl80211_recv_beacons(int sock, void *eloop_ctx, void *handle) | |
612 | { | |
613 | struct nl80211_wiphy_data *w = eloop_ctx; | |
34068ac3 | 614 | int res; |
e32ad281 | 615 | |
ee9fc67a | 616 | wpa_printf(MSG_EXCESSIVE, "nl80211: Beacon event message available"); |
e32ad281 | 617 | |
34068ac3 | 618 | res = nl_recvmsgs(handle, w->nl_cb); |
d3d04831 | 619 | if (res < 0) { |
34068ac3 JM |
620 | wpa_printf(MSG_INFO, "nl80211: %s->nl_recvmsgs failed: %d", |
621 | __func__, res); | |
622 | } | |
e32ad281 JB |
623 | } |
624 | ||
625 | ||
626 | static int process_beacon_event(struct nl_msg *msg, void *arg) | |
627 | { | |
628 | struct nl80211_wiphy_data *w = arg; | |
629 | struct wpa_driver_nl80211_data *drv; | |
630 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
631 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
632 | union wpa_event_data event; | |
633 | ||
634 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
635 | genlmsg_attrlen(gnlh, 0), NULL); | |
636 | ||
637 | if (gnlh->cmd != NL80211_CMD_FRAME) { | |
638 | wpa_printf(MSG_DEBUG, "nl80211: Unexpected beacon event? (%d)", | |
639 | gnlh->cmd); | |
640 | return NL_SKIP; | |
641 | } | |
642 | ||
643 | if (!tb[NL80211_ATTR_FRAME]) | |
644 | return NL_SKIP; | |
645 | ||
646 | dl_list_for_each(drv, &w->drvs, struct wpa_driver_nl80211_data, | |
647 | wiphy_list) { | |
648 | os_memset(&event, 0, sizeof(event)); | |
649 | event.rx_mgmt.frame = nla_data(tb[NL80211_ATTR_FRAME]); | |
650 | event.rx_mgmt.frame_len = nla_len(tb[NL80211_ATTR_FRAME]); | |
651 | wpa_supplicant_event(drv->ctx, EVENT_RX_MGMT, &event); | |
652 | } | |
653 | ||
654 | return NL_SKIP; | |
655 | } | |
656 | ||
657 | ||
658 | static struct nl80211_wiphy_data * | |
659 | nl80211_get_wiphy_data_ap(struct i802_bss *bss) | |
660 | { | |
661 | static DEFINE_DL_LIST(nl80211_wiphys); | |
662 | struct nl80211_wiphy_data *w; | |
663 | int wiphy_idx, found = 0; | |
664 | struct i802_bss *tmp_bss; | |
665 | ||
666 | if (bss->wiphy_data != NULL) | |
667 | return bss->wiphy_data; | |
668 | ||
669 | wiphy_idx = nl80211_get_wiphy_index(bss); | |
670 | ||
671 | dl_list_for_each(w, &nl80211_wiphys, struct nl80211_wiphy_data, list) { | |
672 | if (w->wiphy_idx == wiphy_idx) | |
673 | goto add; | |
674 | } | |
675 | ||
676 | /* alloc new one */ | |
677 | w = os_zalloc(sizeof(*w)); | |
678 | if (w == NULL) | |
679 | return NULL; | |
680 | w->wiphy_idx = wiphy_idx; | |
681 | dl_list_init(&w->bsss); | |
682 | dl_list_init(&w->drvs); | |
683 | ||
684 | w->nl_cb = nl_cb_alloc(NL_CB_DEFAULT); | |
685 | if (!w->nl_cb) { | |
686 | os_free(w); | |
687 | return NULL; | |
688 | } | |
689 | nl_cb_set(w->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, no_seq_check, NULL); | |
690 | nl_cb_set(w->nl_cb, NL_CB_VALID, NL_CB_CUSTOM, process_beacon_event, | |
691 | w); | |
692 | ||
481234cf JM |
693 | w->nl_beacons = nl_create_handle(bss->drv->global->nl_cb, |
694 | "wiphy beacons"); | |
695 | if (w->nl_beacons == NULL) { | |
e32ad281 JB |
696 | os_free(w); |
697 | return NULL; | |
698 | } | |
699 | ||
700 | if (nl80211_register_beacons(bss->drv, w)) { | |
701 | nl_destroy_handles(&w->nl_beacons); | |
702 | os_free(w); | |
703 | return NULL; | |
704 | } | |
705 | ||
5f65e9f7 | 706 | nl80211_register_eloop_read(&w->nl_beacons, nl80211_recv_beacons, w); |
e32ad281 JB |
707 | |
708 | dl_list_add(&nl80211_wiphys, &w->list); | |
709 | ||
710 | add: | |
711 | /* drv entry for this bss already there? */ | |
712 | dl_list_for_each(tmp_bss, &w->bsss, struct i802_bss, wiphy_list) { | |
713 | if (tmp_bss->drv == bss->drv) { | |
714 | found = 1; | |
715 | break; | |
716 | } | |
717 | } | |
718 | /* if not add it */ | |
719 | if (!found) | |
720 | dl_list_add(&w->drvs, &bss->drv->wiphy_list); | |
721 | ||
722 | dl_list_add(&w->bsss, &bss->wiphy_list); | |
723 | bss->wiphy_data = w; | |
724 | return w; | |
725 | } | |
726 | ||
727 | ||
728 | static void nl80211_put_wiphy_data_ap(struct i802_bss *bss) | |
729 | { | |
730 | struct nl80211_wiphy_data *w = bss->wiphy_data; | |
731 | struct i802_bss *tmp_bss; | |
732 | int found = 0; | |
733 | ||
734 | if (w == NULL) | |
735 | return; | |
736 | bss->wiphy_data = NULL; | |
737 | dl_list_del(&bss->wiphy_list); | |
738 | ||
739 | /* still any for this drv present? */ | |
740 | dl_list_for_each(tmp_bss, &w->bsss, struct i802_bss, wiphy_list) { | |
741 | if (tmp_bss->drv == bss->drv) { | |
742 | found = 1; | |
743 | break; | |
744 | } | |
745 | } | |
746 | /* if not remove it */ | |
747 | if (!found) | |
748 | dl_list_del(&bss->drv->wiphy_list); | |
749 | ||
750 | if (!dl_list_empty(&w->bsss)) | |
751 | return; | |
752 | ||
5f65e9f7 | 753 | nl80211_destroy_eloop_handle(&w->nl_beacons); |
e32ad281 JB |
754 | |
755 | nl_cb_put(w->nl_cb); | |
e32ad281 JB |
756 | dl_list_del(&w->list); |
757 | os_free(w); | |
758 | } | |
759 | ||
760 | ||
3f5285e8 JM |
761 | static int wpa_driver_nl80211_get_bssid(void *priv, u8 *bssid) |
762 | { | |
a2e40bb6 FF |
763 | struct i802_bss *bss = priv; |
764 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
c2a04078 JM |
765 | if (!drv->associated) |
766 | return -1; | |
767 | os_memcpy(bssid, drv->bssid, ETH_ALEN); | |
768 | return 0; | |
3f5285e8 JM |
769 | } |
770 | ||
771 | ||
3f5285e8 JM |
772 | static int wpa_driver_nl80211_get_ssid(void *priv, u8 *ssid) |
773 | { | |
a2e40bb6 FF |
774 | struct i802_bss *bss = priv; |
775 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
fd05d64e JM |
776 | if (!drv->associated) |
777 | return -1; | |
778 | os_memcpy(ssid, drv->ssid, drv->ssid_len); | |
779 | return drv->ssid_len; | |
3f5285e8 JM |
780 | } |
781 | ||
782 | ||
90a545cc | 783 | static void wpa_driver_nl80211_event_newlink( |
40e76396 | 784 | struct wpa_driver_nl80211_data *drv, const char *ifname) |
3f5285e8 JM |
785 | { |
786 | union wpa_event_data event; | |
787 | ||
90a545cc JM |
788 | if (os_strcmp(drv->first_bss->ifname, ifname) == 0) { |
789 | if (if_nametoindex(drv->first_bss->ifname) == 0) { | |
790 | wpa_printf(MSG_DEBUG, "nl80211: Interface %s does not exist - ignore RTM_NEWLINK", | |
791 | drv->first_bss->ifname); | |
792 | return; | |
793 | } | |
794 | if (!drv->if_removed) | |
795 | return; | |
796 | wpa_printf(MSG_DEBUG, "nl80211: Mark if_removed=0 for %s based on RTM_NEWLINK event", | |
797 | drv->first_bss->ifname); | |
798 | drv->if_removed = 0; | |
799 | } | |
800 | ||
3f5285e8 | 801 | os_memset(&event, 0, sizeof(event)); |
90a545cc JM |
802 | os_strlcpy(event.interface_status.ifname, ifname, |
803 | sizeof(event.interface_status.ifname)); | |
804 | event.interface_status.ievent = EVENT_INTERFACE_ADDED; | |
805 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_STATUS, &event); | |
806 | } | |
807 | ||
808 | ||
809 | static void wpa_driver_nl80211_event_dellink( | |
40e76396 | 810 | struct wpa_driver_nl80211_data *drv, const char *ifname) |
90a545cc JM |
811 | { |
812 | union wpa_event_data event; | |
813 | ||
814 | if (os_strcmp(drv->first_bss->ifname, ifname) == 0) { | |
815 | if (drv->if_removed) { | |
816 | wpa_printf(MSG_DEBUG, "nl80211: if_removed already set - ignore RTM_DELLINK event for %s", | |
817 | ifname); | |
818 | return; | |
d1f4942b | 819 | } |
90a545cc JM |
820 | wpa_printf(MSG_DEBUG, "RTM_DELLINK: Interface '%s' removed - mark if_removed=1", |
821 | ifname); | |
822 | drv->if_removed = 1; | |
823 | } else { | |
824 | wpa_printf(MSG_DEBUG, "RTM_DELLINK: Interface '%s' removed", | |
825 | ifname); | |
7524cfb1 JM |
826 | } |
827 | ||
90a545cc JM |
828 | os_memset(&event, 0, sizeof(event)); |
829 | os_strlcpy(event.interface_status.ifname, ifname, | |
830 | sizeof(event.interface_status.ifname)); | |
831 | event.interface_status.ievent = EVENT_INTERFACE_REMOVED; | |
08063178 | 832 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_STATUS, &event); |
3f5285e8 JM |
833 | } |
834 | ||
835 | ||
7524cfb1 | 836 | static int wpa_driver_nl80211_own_ifname(struct wpa_driver_nl80211_data *drv, |
62d680c3 | 837 | u8 *buf, size_t len) |
7524cfb1 | 838 | { |
62d680c3 | 839 | int attrlen, rta_len; |
7524cfb1 JM |
840 | struct rtattr *attr; |
841 | ||
62d680c3 JM |
842 | attrlen = len; |
843 | attr = (struct rtattr *) buf; | |
7524cfb1 JM |
844 | |
845 | rta_len = RTA_ALIGN(sizeof(struct rtattr)); | |
846 | while (RTA_OK(attr, attrlen)) { | |
847 | if (attr->rta_type == IFLA_IFNAME) { | |
834ee56f KP |
848 | if (os_strcmp(((char *) attr) + rta_len, |
849 | drv->first_bss->ifname) == 0) | |
7524cfb1 JM |
850 | return 1; |
851 | else | |
852 | break; | |
853 | } | |
854 | attr = RTA_NEXT(attr, attrlen); | |
855 | } | |
856 | ||
857 | return 0; | |
858 | } | |
859 | ||
860 | ||
861 | static int wpa_driver_nl80211_own_ifindex(struct wpa_driver_nl80211_data *drv, | |
62d680c3 | 862 | int ifindex, u8 *buf, size_t len) |
7524cfb1 JM |
863 | { |
864 | if (drv->ifindex == ifindex) | |
865 | return 1; | |
866 | ||
62d680c3 | 867 | if (drv->if_removed && wpa_driver_nl80211_own_ifname(drv, buf, len)) { |
f51f54a0 | 868 | nl80211_check_global(drv->global); |
7524cfb1 JM |
869 | wpa_printf(MSG_DEBUG, "nl80211: Update ifindex for a removed " |
870 | "interface"); | |
0ecff8d7 | 871 | wpa_driver_nl80211_finish_drv_init(drv, NULL, 0, NULL); |
7524cfb1 JM |
872 | return 1; |
873 | } | |
874 | ||
875 | return 0; | |
876 | } | |
877 | ||
878 | ||
36d84860 BG |
879 | static struct wpa_driver_nl80211_data * |
880 | nl80211_find_drv(struct nl80211_global *global, int idx, u8 *buf, size_t len) | |
881 | { | |
882 | struct wpa_driver_nl80211_data *drv; | |
883 | dl_list_for_each(drv, &global->interfaces, | |
884 | struct wpa_driver_nl80211_data, list) { | |
885 | if (wpa_driver_nl80211_own_ifindex(drv, idx, buf, len) || | |
886 | have_ifidx(drv, idx)) | |
887 | return drv; | |
888 | } | |
889 | return NULL; | |
890 | } | |
891 | ||
892 | ||
62d680c3 JM |
893 | static void wpa_driver_nl80211_event_rtm_newlink(void *ctx, |
894 | struct ifinfomsg *ifi, | |
895 | u8 *buf, size_t len) | |
3f5285e8 | 896 | { |
36d84860 BG |
897 | struct nl80211_global *global = ctx; |
898 | struct wpa_driver_nl80211_data *drv; | |
90a545cc | 899 | int attrlen; |
62d680c3 | 900 | struct rtattr *attr; |
97cfcf64 | 901 | u32 brid = 0; |
aef85ba2 | 902 | char namebuf[IFNAMSIZ]; |
90a545cc JM |
903 | char ifname[IFNAMSIZ + 1]; |
904 | char extra[100], *pos, *end; | |
3f5285e8 | 905 | |
36d84860 BG |
906 | drv = nl80211_find_drv(global, ifi->ifi_index, buf, len); |
907 | if (!drv) { | |
90a545cc JM |
908 | wpa_printf(MSG_DEBUG, "nl80211: Ignore RTM_NEWLINK event for foreign ifindex %d", |
909 | ifi->ifi_index); | |
3f5285e8 JM |
910 | return; |
911 | } | |
912 | ||
90a545cc JM |
913 | extra[0] = '\0'; |
914 | pos = extra; | |
915 | end = pos + sizeof(extra); | |
916 | ifname[0] = '\0'; | |
917 | ||
918 | attrlen = len; | |
919 | attr = (struct rtattr *) buf; | |
920 | while (RTA_OK(attr, attrlen)) { | |
921 | switch (attr->rta_type) { | |
922 | case IFLA_IFNAME: | |
923 | if (RTA_PAYLOAD(attr) >= IFNAMSIZ) | |
924 | break; | |
925 | os_memcpy(ifname, RTA_DATA(attr), RTA_PAYLOAD(attr)); | |
926 | ifname[RTA_PAYLOAD(attr)] = '\0'; | |
927 | break; | |
928 | case IFLA_MASTER: | |
929 | brid = nla_get_u32((struct nlattr *) attr); | |
930 | pos += os_snprintf(pos, end - pos, " master=%u", brid); | |
931 | break; | |
932 | case IFLA_WIRELESS: | |
933 | pos += os_snprintf(pos, end - pos, " wext"); | |
934 | break; | |
935 | case IFLA_OPERSTATE: | |
936 | pos += os_snprintf(pos, end - pos, " operstate=%u", | |
937 | nla_get_u32((struct nlattr *) attr)); | |
938 | break; | |
939 | case IFLA_LINKMODE: | |
940 | pos += os_snprintf(pos, end - pos, " linkmode=%u", | |
941 | nla_get_u32((struct nlattr *) attr)); | |
942 | break; | |
943 | } | |
944 | attr = RTA_NEXT(attr, attrlen); | |
945 | } | |
946 | extra[sizeof(extra) - 1] = '\0'; | |
947 | ||
f2e90835 JM |
948 | wpa_printf(MSG_DEBUG, "RTM_NEWLINK: ifi_index=%d ifname=%s%s ifi_family=%d ifi_flags=0x%x (%s%s%s%s)", |
949 | ifi->ifi_index, ifname, extra, ifi->ifi_family, | |
950 | ifi->ifi_flags, | |
3f5285e8 JM |
951 | (ifi->ifi_flags & IFF_UP) ? "[UP]" : "", |
952 | (ifi->ifi_flags & IFF_RUNNING) ? "[RUNNING]" : "", | |
953 | (ifi->ifi_flags & IFF_LOWER_UP) ? "[LOWER_UP]" : "", | |
954 | (ifi->ifi_flags & IFF_DORMANT) ? "[DORMANT]" : ""); | |
a63063b4 JM |
955 | |
956 | if (!drv->if_disabled && !(ifi->ifi_flags & IFF_UP)) { | |
106fa1e9 | 957 | namebuf[0] = '\0'; |
59d24925 | 958 | if (if_indextoname(ifi->ifi_index, namebuf) && |
106fa1e9 | 959 | linux_iface_up(drv->global->ioctl_sock, namebuf) > 0) { |
59d24925 JM |
960 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface down " |
961 | "event since interface %s is up", namebuf); | |
7a94120e | 962 | drv->ignore_if_down_event = 0; |
59d24925 JM |
963 | return; |
964 | } | |
106fa1e9 JM |
965 | wpa_printf(MSG_DEBUG, "nl80211: Interface down (%s/%s)", |
966 | namebuf, ifname); | |
967 | if (os_strcmp(drv->first_bss->ifname, ifname) != 0) { | |
968 | wpa_printf(MSG_DEBUG, | |
969 | "nl80211: Not the main interface (%s) - do not indicate interface down", | |
970 | drv->first_bss->ifname); | |
971 | } else if (drv->ignore_if_down_event) { | |
7d9c3698 JM |
972 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface down " |
973 | "event generated by mode change"); | |
974 | drv->ignore_if_down_event = 0; | |
975 | } else { | |
976 | drv->if_disabled = 1; | |
977 | wpa_supplicant_event(drv->ctx, | |
978 | EVENT_INTERFACE_DISABLED, NULL); | |
819f096f AO |
979 | |
980 | /* | |
981 | * Try to get drv again, since it may be removed as | |
982 | * part of the EVENT_INTERFACE_DISABLED handling for | |
983 | * dynamic interfaces | |
984 | */ | |
985 | drv = nl80211_find_drv(global, ifi->ifi_index, | |
986 | buf, len); | |
987 | if (!drv) | |
988 | return; | |
7d9c3698 | 989 | } |
a63063b4 JM |
990 | } |
991 | ||
992 | if (drv->if_disabled && (ifi->ifi_flags & IFF_UP)) { | |
aef85ba2 | 993 | if (if_indextoname(ifi->ifi_index, namebuf) && |
106fa1e9 | 994 | linux_iface_up(drv->global->ioctl_sock, namebuf) == 0) { |
aef85ba2 JM |
995 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up " |
996 | "event since interface %s is down", | |
997 | namebuf); | |
834ee56f | 998 | } else if (if_nametoindex(drv->first_bss->ifname) == 0) { |
d1f4942b JM |
999 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up " |
1000 | "event since interface %s does not exist", | |
834ee56f | 1001 | drv->first_bss->ifname); |
d1f4942b JM |
1002 | } else if (drv->if_removed) { |
1003 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up " | |
1004 | "event since interface %s is marked " | |
834ee56f | 1005 | "removed", drv->first_bss->ifname); |
aef85ba2 | 1006 | } else { |
3e0272ca DW |
1007 | struct i802_bss *bss; |
1008 | u8 addr[ETH_ALEN]; | |
1009 | ||
1010 | /* Re-read MAC address as it may have changed */ | |
1011 | bss = get_bss_ifindex(drv, ifi->ifi_index); | |
1012 | if (bss && | |
1013 | linux_get_ifhwaddr(drv->global->ioctl_sock, | |
1014 | bss->ifname, addr) < 0) { | |
1015 | wpa_printf(MSG_DEBUG, | |
1016 | "nl80211: %s: failed to re-read MAC address", | |
1017 | bss->ifname); | |
1018 | } else if (bss && | |
1019 | os_memcmp(addr, bss->addr, ETH_ALEN) != 0) { | |
1020 | wpa_printf(MSG_DEBUG, | |
1021 | "nl80211: Own MAC address on ifindex %d (%s) changed from " | |
1022 | MACSTR " to " MACSTR, | |
1023 | ifi->ifi_index, bss->ifname, | |
1024 | MAC2STR(bss->addr), | |
1025 | MAC2STR(addr)); | |
1026 | os_memcpy(bss->addr, addr, ETH_ALEN); | |
1027 | } | |
1028 | ||
aef85ba2 JM |
1029 | wpa_printf(MSG_DEBUG, "nl80211: Interface up"); |
1030 | drv->if_disabled = 0; | |
1031 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_ENABLED, | |
1032 | NULL); | |
1033 | } | |
a63063b4 JM |
1034 | } |
1035 | ||
3f5285e8 JM |
1036 | /* |
1037 | * Some drivers send the association event before the operup event--in | |
1038 | * this case, lifting operstate in wpa_driver_nl80211_set_operstate() | |
1039 | * fails. This will hit us when wpa_supplicant does not need to do | |
1040 | * IEEE 802.1X authentication | |
1041 | */ | |
1042 | if (drv->operstate == 1 && | |
1043 | (ifi->ifi_flags & (IFF_LOWER_UP | IFF_DORMANT)) == IFF_LOWER_UP && | |
90a545cc JM |
1044 | !(ifi->ifi_flags & IFF_RUNNING)) { |
1045 | wpa_printf(MSG_DEBUG, "nl80211: Set IF_OPER_UP again based on ifi_flags and expected operstate"); | |
36d84860 | 1046 | netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, |
e2d02c29 | 1047 | -1, IF_OPER_UP); |
3f5285e8 | 1048 | } |
97cfcf64 | 1049 | |
90a545cc JM |
1050 | if (ifname[0]) |
1051 | wpa_driver_nl80211_event_newlink(drv, ifname); | |
1052 | ||
97cfcf64 | 1053 | if (ifi->ifi_family == AF_BRIDGE && brid) { |
392dfd37 JM |
1054 | struct i802_bss *bss; |
1055 | ||
97cfcf64 | 1056 | /* device has been added to bridge */ |
40e76396 JM |
1057 | if (!if_indextoname(brid, namebuf)) { |
1058 | wpa_printf(MSG_DEBUG, | |
1059 | "nl80211: Could not find bridge ifname for ifindex %u", | |
1060 | brid); | |
1061 | return; | |
1062 | } | |
97cfcf64 B |
1063 | wpa_printf(MSG_DEBUG, "nl80211: Add ifindex %u for bridge %s", |
1064 | brid, namebuf); | |
1065 | add_ifidx(drv, brid); | |
392dfd37 JM |
1066 | |
1067 | for (bss = drv->first_bss; bss; bss = bss->next) { | |
1068 | if (os_strcmp(ifname, bss->ifname) == 0) { | |
1069 | os_strlcpy(bss->brname, namebuf, IFNAMSIZ); | |
1070 | break; | |
1071 | } | |
1072 | } | |
97cfcf64 | 1073 | } |
3f5285e8 JM |
1074 | } |
1075 | ||
1076 | ||
62d680c3 JM |
1077 | static void wpa_driver_nl80211_event_rtm_dellink(void *ctx, |
1078 | struct ifinfomsg *ifi, | |
1079 | u8 *buf, size_t len) | |
3f5285e8 | 1080 | { |
36d84860 BG |
1081 | struct nl80211_global *global = ctx; |
1082 | struct wpa_driver_nl80211_data *drv; | |
90a545cc | 1083 | int attrlen; |
62d680c3 | 1084 | struct rtattr *attr; |
97cfcf64 | 1085 | u32 brid = 0; |
90a545cc | 1086 | char ifname[IFNAMSIZ + 1]; |
f2e90835 | 1087 | char extra[100], *pos, *end; |
3f5285e8 | 1088 | |
36d84860 BG |
1089 | drv = nl80211_find_drv(global, ifi->ifi_index, buf, len); |
1090 | if (!drv) { | |
90a545cc JM |
1091 | wpa_printf(MSG_DEBUG, "nl80211: Ignore RTM_DELLINK event for foreign ifindex %d", |
1092 | ifi->ifi_index); | |
36d84860 BG |
1093 | return; |
1094 | } | |
1095 | ||
f2e90835 JM |
1096 | extra[0] = '\0'; |
1097 | pos = extra; | |
1098 | end = pos + sizeof(extra); | |
90a545cc JM |
1099 | ifname[0] = '\0'; |
1100 | ||
62d680c3 JM |
1101 | attrlen = len; |
1102 | attr = (struct rtattr *) buf; | |
3f5285e8 | 1103 | while (RTA_OK(attr, attrlen)) { |
90a545cc JM |
1104 | switch (attr->rta_type) { |
1105 | case IFLA_IFNAME: | |
1106 | if (RTA_PAYLOAD(attr) >= IFNAMSIZ) | |
1107 | break; | |
1108 | os_memcpy(ifname, RTA_DATA(attr), RTA_PAYLOAD(attr)); | |
1109 | ifname[RTA_PAYLOAD(attr)] = '\0'; | |
1110 | break; | |
1111 | case IFLA_MASTER: | |
97cfcf64 | 1112 | brid = nla_get_u32((struct nlattr *) attr); |
f2e90835 JM |
1113 | pos += os_snprintf(pos, end - pos, " master=%u", brid); |
1114 | break; | |
1115 | case IFLA_OPERSTATE: | |
1116 | pos += os_snprintf(pos, end - pos, " operstate=%u", | |
1117 | nla_get_u32((struct nlattr *) attr)); | |
1118 | break; | |
1119 | case IFLA_LINKMODE: | |
1120 | pos += os_snprintf(pos, end - pos, " linkmode=%u", | |
1121 | nla_get_u32((struct nlattr *) attr)); | |
90a545cc JM |
1122 | break; |
1123 | } | |
3f5285e8 JM |
1124 | attr = RTA_NEXT(attr, attrlen); |
1125 | } | |
f2e90835 JM |
1126 | extra[sizeof(extra) - 1] = '\0'; |
1127 | ||
1128 | wpa_printf(MSG_DEBUG, "RTM_DELLINK: ifi_index=%d ifname=%s%s ifi_family=%d ifi_flags=0x%x (%s%s%s%s)", | |
1129 | ifi->ifi_index, ifname, extra, ifi->ifi_family, | |
1130 | ifi->ifi_flags, | |
1131 | (ifi->ifi_flags & IFF_UP) ? "[UP]" : "", | |
1132 | (ifi->ifi_flags & IFF_RUNNING) ? "[RUNNING]" : "", | |
1133 | (ifi->ifi_flags & IFF_LOWER_UP) ? "[LOWER_UP]" : "", | |
1134 | (ifi->ifi_flags & IFF_DORMANT) ? "[DORMANT]" : ""); | |
97cfcf64 | 1135 | |
728ff2f4 | 1136 | if (ifname[0] && (ifi->ifi_family != AF_BRIDGE || !brid)) |
90a545cc JM |
1137 | wpa_driver_nl80211_event_dellink(drv, ifname); |
1138 | ||
97cfcf64 B |
1139 | if (ifi->ifi_family == AF_BRIDGE && brid) { |
1140 | /* device has been removed from bridge */ | |
1141 | char namebuf[IFNAMSIZ]; | |
40e76396 JM |
1142 | |
1143 | if (!if_indextoname(brid, namebuf)) { | |
1144 | wpa_printf(MSG_DEBUG, | |
1145 | "nl80211: Could not find bridge ifname for ifindex %u", | |
1146 | brid); | |
1147 | } else { | |
1148 | wpa_printf(MSG_DEBUG, | |
1149 | "nl80211: Remove ifindex %u for bridge %s", | |
1150 | brid, namebuf); | |
1151 | } | |
97cfcf64 B |
1152 | del_ifidx(drv, brid); |
1153 | } | |
3f5285e8 JM |
1154 | } |
1155 | ||
1156 | ||
f3407c66 | 1157 | unsigned int nl80211_get_assoc_freq(struct wpa_driver_nl80211_data *drv) |
f5a8d422 JM |
1158 | { |
1159 | struct nl_msg *msg; | |
1160 | int ret; | |
1161 | struct nl80211_bss_info_arg arg; | |
1162 | ||
9725b784 | 1163 | msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SCAN); |
f5a8d422 | 1164 | os_memset(&arg, 0, sizeof(arg)); |
f5a8d422 JM |
1165 | arg.drv = drv; |
1166 | ret = send_and_recv_msgs(drv, msg, bss_info_handler, &arg); | |
f5a8d422 | 1167 | if (ret == 0) { |
c7caac56 JM |
1168 | unsigned int freq = drv->nlmode == NL80211_IFTYPE_ADHOC ? |
1169 | arg.ibss_freq : arg.assoc_freq; | |
f5a8d422 | 1170 | wpa_printf(MSG_DEBUG, "nl80211: Operating frequency for the " |
c7caac56 JM |
1171 | "associated BSS from scan results: %u MHz", freq); |
1172 | if (freq) | |
1173 | drv->assoc_freq = freq; | |
30158a0d | 1174 | return drv->assoc_freq; |
f5a8d422 JM |
1175 | } |
1176 | wpa_printf(MSG_DEBUG, "nl80211: Scan result fetch failed: ret=%d " | |
1177 | "(%s)", ret, strerror(-ret)); | |
f5a8d422 JM |
1178 | return drv->assoc_freq; |
1179 | } | |
1180 | ||
1181 | ||
60a972a6 JM |
1182 | static int get_link_signal(struct nl_msg *msg, void *arg) |
1183 | { | |
1184 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
1185 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
1186 | struct nlattr *sinfo[NL80211_STA_INFO_MAX + 1]; | |
1187 | static struct nla_policy policy[NL80211_STA_INFO_MAX + 1] = { | |
1188 | [NL80211_STA_INFO_SIGNAL] = { .type = NLA_U8 }, | |
95783298 | 1189 | [NL80211_STA_INFO_SIGNAL_AVG] = { .type = NLA_U8 }, |
74fa78b2 | 1190 | [NL80211_STA_INFO_BEACON_SIGNAL_AVG] = { .type = NLA_U8 }, |
60a972a6 | 1191 | }; |
7ee35bf3 PS |
1192 | struct nlattr *rinfo[NL80211_RATE_INFO_MAX + 1]; |
1193 | static struct nla_policy rate_policy[NL80211_RATE_INFO_MAX + 1] = { | |
1194 | [NL80211_RATE_INFO_BITRATE] = { .type = NLA_U16 }, | |
1195 | [NL80211_RATE_INFO_MCS] = { .type = NLA_U8 }, | |
1196 | [NL80211_RATE_INFO_40_MHZ_WIDTH] = { .type = NLA_FLAG }, | |
1197 | [NL80211_RATE_INFO_SHORT_GI] = { .type = NLA_FLAG }, | |
1198 | }; | |
1c5c7273 | 1199 | struct wpa_signal_info *sig_change = arg; |
60a972a6 JM |
1200 | |
1201 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
1202 | genlmsg_attrlen(gnlh, 0), NULL); | |
1203 | if (!tb[NL80211_ATTR_STA_INFO] || | |
1204 | nla_parse_nested(sinfo, NL80211_STA_INFO_MAX, | |
1205 | tb[NL80211_ATTR_STA_INFO], policy)) | |
1206 | return NL_SKIP; | |
1207 | if (!sinfo[NL80211_STA_INFO_SIGNAL]) | |
1208 | return NL_SKIP; | |
1209 | ||
7ee35bf3 PS |
1210 | sig_change->current_signal = |
1211 | (s8) nla_get_u8(sinfo[NL80211_STA_INFO_SIGNAL]); | |
1212 | ||
95783298 AO |
1213 | if (sinfo[NL80211_STA_INFO_SIGNAL_AVG]) |
1214 | sig_change->avg_signal = | |
1215 | (s8) nla_get_u8(sinfo[NL80211_STA_INFO_SIGNAL_AVG]); | |
1216 | else | |
1217 | sig_change->avg_signal = 0; | |
1218 | ||
74fa78b2 JM |
1219 | if (sinfo[NL80211_STA_INFO_BEACON_SIGNAL_AVG]) |
1220 | sig_change->avg_beacon_signal = | |
1221 | (s8) | |
1222 | nla_get_u8(sinfo[NL80211_STA_INFO_BEACON_SIGNAL_AVG]); | |
1223 | else | |
1224 | sig_change->avg_beacon_signal = 0; | |
1225 | ||
7ee35bf3 PS |
1226 | if (sinfo[NL80211_STA_INFO_TX_BITRATE]) { |
1227 | if (nla_parse_nested(rinfo, NL80211_RATE_INFO_MAX, | |
1228 | sinfo[NL80211_STA_INFO_TX_BITRATE], | |
1229 | rate_policy)) { | |
1230 | sig_change->current_txrate = 0; | |
1231 | } else { | |
1232 | if (rinfo[NL80211_RATE_INFO_BITRATE]) { | |
1233 | sig_change->current_txrate = | |
1234 | nla_get_u16(rinfo[ | |
1235 | NL80211_RATE_INFO_BITRATE]) * 100; | |
1236 | } | |
1237 | } | |
1238 | } | |
1239 | ||
60a972a6 JM |
1240 | return NL_SKIP; |
1241 | } | |
1242 | ||
1243 | ||
f3407c66 JM |
1244 | int nl80211_get_link_signal(struct wpa_driver_nl80211_data *drv, |
1245 | struct wpa_signal_info *sig) | |
60a972a6 JM |
1246 | { |
1247 | struct nl_msg *msg; | |
1248 | ||
7ee35bf3 PS |
1249 | sig->current_signal = -9999; |
1250 | sig->current_txrate = 0; | |
60a972a6 | 1251 | |
9725b784 | 1252 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_GET_STATION)) || |
a862e4a3 JM |
1253 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, drv->bssid)) { |
1254 | nlmsg_free(msg); | |
1255 | return -ENOBUFS; | |
1256 | } | |
60a972a6 JM |
1257 | |
1258 | return send_and_recv_msgs(drv, msg, get_link_signal, sig); | |
60a972a6 JM |
1259 | } |
1260 | ||
1261 | ||
7ee35bf3 PS |
1262 | static int get_link_noise(struct nl_msg *msg, void *arg) |
1263 | { | |
1264 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
1265 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
1266 | struct nlattr *sinfo[NL80211_SURVEY_INFO_MAX + 1]; | |
1267 | static struct nla_policy survey_policy[NL80211_SURVEY_INFO_MAX + 1] = { | |
1268 | [NL80211_SURVEY_INFO_FREQUENCY] = { .type = NLA_U32 }, | |
1269 | [NL80211_SURVEY_INFO_NOISE] = { .type = NLA_U8 }, | |
1270 | }; | |
1c5c7273 | 1271 | struct wpa_signal_info *sig_change = arg; |
7ee35bf3 PS |
1272 | |
1273 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
1274 | genlmsg_attrlen(gnlh, 0), NULL); | |
1275 | ||
1276 | if (!tb[NL80211_ATTR_SURVEY_INFO]) { | |
1277 | wpa_printf(MSG_DEBUG, "nl80211: survey data missing!"); | |
1278 | return NL_SKIP; | |
1279 | } | |
1280 | ||
1281 | if (nla_parse_nested(sinfo, NL80211_SURVEY_INFO_MAX, | |
1282 | tb[NL80211_ATTR_SURVEY_INFO], | |
1283 | survey_policy)) { | |
1284 | wpa_printf(MSG_DEBUG, "nl80211: failed to parse nested " | |
1285 | "attributes!"); | |
1286 | return NL_SKIP; | |
1287 | } | |
1288 | ||
1289 | if (!sinfo[NL80211_SURVEY_INFO_FREQUENCY]) | |
1290 | return NL_SKIP; | |
1291 | ||
1292 | if (nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]) != | |
1293 | sig_change->frequency) | |
1294 | return NL_SKIP; | |
1295 | ||
1296 | if (!sinfo[NL80211_SURVEY_INFO_NOISE]) | |
1297 | return NL_SKIP; | |
1298 | ||
1299 | sig_change->current_noise = | |
1300 | (s8) nla_get_u8(sinfo[NL80211_SURVEY_INFO_NOISE]); | |
1301 | ||
1302 | return NL_SKIP; | |
1303 | } | |
1304 | ||
1305 | ||
f3407c66 JM |
1306 | int nl80211_get_link_noise(struct wpa_driver_nl80211_data *drv, |
1307 | struct wpa_signal_info *sig_change) | |
7ee35bf3 PS |
1308 | { |
1309 | struct nl_msg *msg; | |
1310 | ||
1311 | sig_change->current_noise = 9999; | |
1312 | sig_change->frequency = drv->assoc_freq; | |
1313 | ||
9725b784 | 1314 | msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SURVEY); |
7ee35bf3 | 1315 | return send_and_recv_msgs(drv, msg, get_link_noise, sig_change); |
7ee35bf3 PS |
1316 | } |
1317 | ||
1318 | ||
97865538 | 1319 | static void wpa_driver_nl80211_event_receive(int sock, void *eloop_ctx, |
5582a5d1 | 1320 | void *handle) |
97865538 | 1321 | { |
a4ae123c | 1322 | struct nl_cb *cb = eloop_ctx; |
34068ac3 | 1323 | int res; |
97865538 | 1324 | |
cc2ada86 | 1325 | wpa_printf(MSG_MSGDUMP, "nl80211: Event message available"); |
97865538 | 1326 | |
34068ac3 | 1327 | res = nl_recvmsgs(handle, cb); |
d3d04831 | 1328 | if (res < 0) { |
34068ac3 JM |
1329 | wpa_printf(MSG_INFO, "nl80211: %s->nl_recvmsgs failed: %d", |
1330 | __func__, res); | |
1331 | } | |
97865538 JM |
1332 | } |
1333 | ||
1334 | ||
6d158490 LR |
1335 | /** |
1336 | * wpa_driver_nl80211_set_country - ask nl80211 to set the regulatory domain | |
1337 | * @priv: driver_nl80211 private data | |
1338 | * @alpha2_arg: country to which to switch to | |
1339 | * Returns: 0 on success, -1 on failure | |
1340 | * | |
1341 | * This asks nl80211 to set the regulatory domain for given | |
1342 | * country ISO / IEC alpha2. | |
1343 | */ | |
1344 | static int wpa_driver_nl80211_set_country(void *priv, const char *alpha2_arg) | |
1345 | { | |
a2e40bb6 FF |
1346 | struct i802_bss *bss = priv; |
1347 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
6d158490 LR |
1348 | char alpha2[3]; |
1349 | struct nl_msg *msg; | |
1350 | ||
1351 | msg = nlmsg_alloc(); | |
1352 | if (!msg) | |
e785c2ba | 1353 | return -ENOMEM; |
6d158490 LR |
1354 | |
1355 | alpha2[0] = alpha2_arg[0]; | |
1356 | alpha2[1] = alpha2_arg[1]; | |
1357 | alpha2[2] = '\0'; | |
1358 | ||
a862e4a3 JM |
1359 | if (!nl80211_cmd(drv, msg, 0, NL80211_CMD_REQ_SET_REG) || |
1360 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, alpha2)) { | |
1361 | nlmsg_free(msg); | |
1362 | return -EINVAL; | |
1363 | } | |
6d158490 LR |
1364 | if (send_and_recv_msgs(drv, msg, NULL, NULL)) |
1365 | return -EINVAL; | |
1366 | return 0; | |
6d158490 LR |
1367 | } |
1368 | ||
1369 | ||
f0793bf1 JM |
1370 | static int nl80211_get_country(struct nl_msg *msg, void *arg) |
1371 | { | |
1372 | char *alpha2 = arg; | |
1373 | struct nlattr *tb_msg[NL80211_ATTR_MAX + 1]; | |
1374 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
1375 | ||
1376 | nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
1377 | genlmsg_attrlen(gnlh, 0), NULL); | |
1378 | if (!tb_msg[NL80211_ATTR_REG_ALPHA2]) { | |
1379 | wpa_printf(MSG_DEBUG, "nl80211: No country information available"); | |
1380 | return NL_SKIP; | |
1381 | } | |
1382 | os_strlcpy(alpha2, nla_data(tb_msg[NL80211_ATTR_REG_ALPHA2]), 3); | |
1383 | return NL_SKIP; | |
1384 | } | |
1385 | ||
1386 | ||
1387 | static int wpa_driver_nl80211_get_country(void *priv, char *alpha2) | |
1388 | { | |
1389 | struct i802_bss *bss = priv; | |
1390 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
1391 | struct nl_msg *msg; | |
1392 | int ret; | |
1393 | ||
1394 | msg = nlmsg_alloc(); | |
1395 | if (!msg) | |
1396 | return -ENOMEM; | |
1397 | ||
1398 | nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_REG); | |
1399 | alpha2[0] = '\0'; | |
1400 | ret = send_and_recv_msgs(drv, msg, nl80211_get_country, alpha2); | |
1401 | if (!alpha2[0]) | |
1402 | ret = -1; | |
1403 | ||
1404 | return ret; | |
1405 | } | |
1406 | ||
1407 | ||
2a7b66f5 BG |
1408 | static int wpa_driver_nl80211_init_nl_global(struct nl80211_global *global) |
1409 | { | |
d6c9aab8 JB |
1410 | int ret; |
1411 | ||
2a7b66f5 BG |
1412 | global->nl_cb = nl_cb_alloc(NL_CB_DEFAULT); |
1413 | if (global->nl_cb == NULL) { | |
1414 | wpa_printf(MSG_ERROR, "nl80211: Failed to allocate netlink " | |
1415 | "callbacks"); | |
1416 | return -1; | |
1417 | } | |
1418 | ||
481234cf JM |
1419 | global->nl = nl_create_handle(global->nl_cb, "nl"); |
1420 | if (global->nl == NULL) | |
d6c9aab8 | 1421 | goto err; |
276e2d67 | 1422 | |
481234cf | 1423 | global->nl80211_id = genl_ctrl_resolve(global->nl, "nl80211"); |
335d42b1 | 1424 | if (global->nl80211_id < 0) { |
276e2d67 BG |
1425 | wpa_printf(MSG_ERROR, "nl80211: 'nl80211' generic netlink not " |
1426 | "found"); | |
d6c9aab8 | 1427 | goto err; |
276e2d67 BG |
1428 | } |
1429 | ||
481234cf JM |
1430 | global->nl_event = nl_create_handle(global->nl_cb, "event"); |
1431 | if (global->nl_event == NULL) | |
d6c9aab8 | 1432 | goto err; |
9fff9fdc | 1433 | |
d6c9aab8 | 1434 | ret = nl_get_multicast_id(global, "nl80211", "scan"); |
97865538 | 1435 | if (ret >= 0) |
481234cf | 1436 | ret = nl_socket_add_membership(global->nl_event, ret); |
97865538 JM |
1437 | if (ret < 0) { |
1438 | wpa_printf(MSG_ERROR, "nl80211: Could not add multicast " | |
1439 | "membership for scan events: %d (%s)", | |
1440 | ret, strerror(-ret)); | |
d6c9aab8 | 1441 | goto err; |
97865538 | 1442 | } |
c2a04078 | 1443 | |
d6c9aab8 | 1444 | ret = nl_get_multicast_id(global, "nl80211", "mlme"); |
c2a04078 | 1445 | if (ret >= 0) |
481234cf | 1446 | ret = nl_socket_add_membership(global->nl_event, ret); |
c2a04078 JM |
1447 | if (ret < 0) { |
1448 | wpa_printf(MSG_ERROR, "nl80211: Could not add multicast " | |
1449 | "membership for mlme events: %d (%s)", | |
1450 | ret, strerror(-ret)); | |
d6c9aab8 | 1451 | goto err; |
c2a04078 | 1452 | } |
c2a04078 | 1453 | |
d6c9aab8 | 1454 | ret = nl_get_multicast_id(global, "nl80211", "regulatory"); |
33c5deb8 | 1455 | if (ret >= 0) |
481234cf | 1456 | ret = nl_socket_add_membership(global->nl_event, ret); |
33c5deb8 JM |
1457 | if (ret < 0) { |
1458 | wpa_printf(MSG_DEBUG, "nl80211: Could not add multicast " | |
1459 | "membership for regulatory events: %d (%s)", | |
1460 | ret, strerror(-ret)); | |
1461 | /* Continue without regulatory events */ | |
1462 | } | |
1463 | ||
17b79e65 JM |
1464 | ret = nl_get_multicast_id(global, "nl80211", "vendor"); |
1465 | if (ret >= 0) | |
1466 | ret = nl_socket_add_membership(global->nl_event, ret); | |
1467 | if (ret < 0) { | |
1468 | wpa_printf(MSG_DEBUG, "nl80211: Could not add multicast " | |
1469 | "membership for vendor events: %d (%s)", | |
1470 | ret, strerror(-ret)); | |
1471 | /* Continue without vendor events */ | |
1472 | } | |
1473 | ||
d6c9aab8 JB |
1474 | nl_cb_set(global->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, |
1475 | no_seq_check, NULL); | |
1476 | nl_cb_set(global->nl_cb, NL_CB_VALID, NL_CB_CUSTOM, | |
1477 | process_global_event, global); | |
1478 | ||
5f65e9f7 JB |
1479 | nl80211_register_eloop_read(&global->nl_event, |
1480 | wpa_driver_nl80211_event_receive, | |
1481 | global->nl_cb); | |
d6c9aab8 JB |
1482 | |
1483 | return 0; | |
1484 | ||
1485 | err: | |
1486 | nl_destroy_handles(&global->nl_event); | |
1487 | nl_destroy_handles(&global->nl); | |
1488 | nl_cb_put(global->nl_cb); | |
671a5039 | 1489 | global->nl_cb = NULL; |
d6c9aab8 JB |
1490 | return -1; |
1491 | } | |
1492 | ||
1493 | ||
f51f54a0 JM |
1494 | static void nl80211_check_global(struct nl80211_global *global) |
1495 | { | |
1496 | struct nl_handle *handle; | |
1497 | const char *groups[] = { "scan", "mlme", "regulatory", "vendor", NULL }; | |
1498 | int ret; | |
1499 | unsigned int i; | |
1500 | ||
1501 | /* | |
1502 | * Try to re-add memberships to handle case of cfg80211 getting reloaded | |
1503 | * and all registration having been cleared. | |
1504 | */ | |
1505 | handle = (void *) (((intptr_t) global->nl_event) ^ | |
1506 | ELOOP_SOCKET_INVALID); | |
1507 | ||
1508 | for (i = 0; groups[i]; i++) { | |
1509 | ret = nl_get_multicast_id(global, "nl80211", groups[i]); | |
1510 | if (ret >= 0) | |
1511 | ret = nl_socket_add_membership(handle, ret); | |
1512 | if (ret < 0) { | |
1513 | wpa_printf(MSG_INFO, | |
1514 | "nl80211: Could not re-add multicast membership for %s events: %d (%s)", | |
1515 | groups[i], ret, strerror(-ret)); | |
1516 | } | |
1517 | } | |
1518 | } | |
1519 | ||
1520 | ||
8401a6b0 JM |
1521 | static void wpa_driver_nl80211_rfkill_blocked(void *ctx) |
1522 | { | |
8401a6b0 | 1523 | wpa_printf(MSG_DEBUG, "nl80211: RFKILL blocked"); |
a63063b4 JM |
1524 | /* |
1525 | * This may be for any interface; use ifdown event to disable | |
1526 | * interface. | |
1527 | */ | |
8401a6b0 JM |
1528 | } |
1529 | ||
1530 | ||
1531 | static void wpa_driver_nl80211_rfkill_unblocked(void *ctx) | |
1532 | { | |
1533 | struct wpa_driver_nl80211_data *drv = ctx; | |
1534 | wpa_printf(MSG_DEBUG, "nl80211: RFKILL unblocked"); | |
834ee56f | 1535 | if (i802_set_iface_flags(drv->first_bss, 1)) { |
8401a6b0 JM |
1536 | wpa_printf(MSG_DEBUG, "nl80211: Could not set interface UP " |
1537 | "after rfkill unblock"); | |
1538 | return; | |
1539 | } | |
e8dc205f AO |
1540 | |
1541 | if (is_p2p_net_interface(drv->nlmode)) | |
1542 | nl80211_disable_11b_rates(drv, drv->ifindex, 1); | |
1543 | ||
a63063b4 | 1544 | /* rtnetlink ifup handler will report interface as enabled */ |
8401a6b0 JM |
1545 | } |
1546 | ||
1547 | ||
32ab4855 JB |
1548 | static void wpa_driver_nl80211_handle_eapol_tx_status(int sock, |
1549 | void *eloop_ctx, | |
1550 | void *handle) | |
1551 | { | |
1552 | struct wpa_driver_nl80211_data *drv = eloop_ctx; | |
1553 | u8 data[2048]; | |
1554 | struct msghdr msg; | |
1555 | struct iovec entry; | |
cad0f50e | 1556 | u8 control[512]; |
32ab4855 JB |
1557 | struct cmsghdr *cmsg; |
1558 | int res, found_ee = 0, found_wifi = 0, acked = 0; | |
1559 | union wpa_event_data event; | |
1560 | ||
1561 | memset(&msg, 0, sizeof(msg)); | |
1562 | msg.msg_iov = &entry; | |
1563 | msg.msg_iovlen = 1; | |
1564 | entry.iov_base = data; | |
1565 | entry.iov_len = sizeof(data); | |
1566 | msg.msg_control = &control; | |
1567 | msg.msg_controllen = sizeof(control); | |
1568 | ||
1569 | res = recvmsg(sock, &msg, MSG_ERRQUEUE); | |
1570 | /* if error or not fitting 802.3 header, return */ | |
1571 | if (res < 14) | |
1572 | return; | |
1573 | ||
1574 | for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg)) | |
1575 | { | |
1576 | if (cmsg->cmsg_level == SOL_SOCKET && | |
1577 | cmsg->cmsg_type == SCM_WIFI_STATUS) { | |
1578 | int *ack; | |
1579 | ||
1580 | found_wifi = 1; | |
1581 | ack = (void *)CMSG_DATA(cmsg); | |
1582 | acked = *ack; | |
1583 | } | |
1584 | ||
1585 | if (cmsg->cmsg_level == SOL_PACKET && | |
1586 | cmsg->cmsg_type == PACKET_TX_TIMESTAMP) { | |
1587 | struct sock_extended_err *err = | |
1588 | (struct sock_extended_err *)CMSG_DATA(cmsg); | |
1589 | ||
1590 | if (err->ee_origin == SO_EE_ORIGIN_TXSTATUS) | |
1591 | found_ee = 1; | |
1592 | } | |
1593 | } | |
1594 | ||
1595 | if (!found_ee || !found_wifi) | |
1596 | return; | |
1597 | ||
1598 | memset(&event, 0, sizeof(event)); | |
1599 | event.eapol_tx_status.dst = data; | |
1600 | event.eapol_tx_status.data = data + 14; | |
1601 | event.eapol_tx_status.data_len = res - 14; | |
1602 | event.eapol_tx_status.ack = acked; | |
1603 | wpa_supplicant_event(drv->ctx, EVENT_EAPOL_TX_STATUS, &event); | |
1604 | } | |
1605 | ||
1606 | ||
cc7a48d1 JB |
1607 | static int nl80211_init_bss(struct i802_bss *bss) |
1608 | { | |
1609 | bss->nl_cb = nl_cb_alloc(NL_CB_DEFAULT); | |
1610 | if (!bss->nl_cb) | |
1611 | return -1; | |
1612 | ||
1613 | nl_cb_set(bss->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, | |
1614 | no_seq_check, NULL); | |
1615 | nl_cb_set(bss->nl_cb, NL_CB_VALID, NL_CB_CUSTOM, | |
1616 | process_bss_event, bss); | |
1617 | ||
1618 | return 0; | |
1619 | } | |
1620 | ||
1621 | ||
1622 | static void nl80211_destroy_bss(struct i802_bss *bss) | |
1623 | { | |
1624 | nl_cb_put(bss->nl_cb); | |
1625 | bss->nl_cb = NULL; | |
1626 | } | |
1627 | ||
1628 | ||
0d547d5f JM |
1629 | static void * wpa_driver_nl80211_drv_init(void *ctx, const char *ifname, |
1630 | void *global_priv, int hostapd, | |
0ecff8d7 JM |
1631 | const u8 *set_addr, |
1632 | const char *driver_params) | |
9fff9fdc | 1633 | { |
9fff9fdc | 1634 | struct wpa_driver_nl80211_data *drv; |
8401a6b0 | 1635 | struct rfkill_config *rcfg; |
a2e40bb6 | 1636 | struct i802_bss *bss; |
9fff9fdc | 1637 | |
a5c696ad JM |
1638 | if (global_priv == NULL) |
1639 | return NULL; | |
9fff9fdc JM |
1640 | drv = os_zalloc(sizeof(*drv)); |
1641 | if (drv == NULL) | |
1642 | return NULL; | |
f2ed8023 | 1643 | drv->global = global_priv; |
9fff9fdc | 1644 | drv->ctx = ctx; |
0d547d5f JM |
1645 | drv->hostapd = !!hostapd; |
1646 | drv->eapol_sock = -1; | |
64ae2447 JM |
1647 | |
1648 | /* | |
1649 | * There is no driver capability flag for this, so assume it is | |
1650 | * supported and disable this on first attempt to use if the driver | |
1651 | * rejects the command due to missing support. | |
1652 | */ | |
1653 | drv->set_rekey_offload = 1; | |
1654 | ||
0d547d5f JM |
1655 | drv->num_if_indices = sizeof(drv->default_if_indices) / sizeof(int); |
1656 | drv->if_indices = drv->default_if_indices; | |
834ee56f KP |
1657 | |
1658 | drv->first_bss = os_zalloc(sizeof(*drv->first_bss)); | |
1659 | if (!drv->first_bss) { | |
1660 | os_free(drv); | |
1661 | return NULL; | |
1662 | } | |
1663 | bss = drv->first_bss; | |
a2e40bb6 | 1664 | bss->drv = drv; |
a5e1eb20 SE |
1665 | bss->ctx = ctx; |
1666 | ||
a2e40bb6 | 1667 | os_strlcpy(bss->ifname, ifname, sizeof(bss->ifname)); |
9fff9fdc JM |
1668 | drv->monitor_ifidx = -1; |
1669 | drv->monitor_sock = -1; | |
d12dab4c | 1670 | drv->eapol_tx_sock = -1; |
b1f625e0 | 1671 | drv->ap_scan_as_station = NL80211_IFTYPE_UNSPECIFIED; |
9fff9fdc | 1672 | |
cc7a48d1 JB |
1673 | if (nl80211_init_bss(bss)) |
1674 | goto failed; | |
1675 | ||
8401a6b0 JM |
1676 | rcfg = os_zalloc(sizeof(*rcfg)); |
1677 | if (rcfg == NULL) | |
1678 | goto failed; | |
1679 | rcfg->ctx = drv; | |
1680 | os_strlcpy(rcfg->ifname, ifname, sizeof(rcfg->ifname)); | |
1681 | rcfg->blocked_cb = wpa_driver_nl80211_rfkill_blocked; | |
1682 | rcfg->unblocked_cb = wpa_driver_nl80211_rfkill_unblocked; | |
1683 | drv->rfkill = rfkill_init(rcfg); | |
52169389 | 1684 | if (drv->rfkill == NULL) { |
8401a6b0 | 1685 | wpa_printf(MSG_DEBUG, "nl80211: RFKILL status not available"); |
52169389 JM |
1686 | os_free(rcfg); |
1687 | } | |
8401a6b0 | 1688 | |
146fa9b3 JM |
1689 | if (linux_iface_up(drv->global->ioctl_sock, ifname) > 0) |
1690 | drv->start_iface_up = 1; | |
1691 | ||
0ecff8d7 | 1692 | if (wpa_driver_nl80211_finish_drv_init(drv, set_addr, 1, driver_params)) |
bbaf0837 | 1693 | goto failed; |
7524cfb1 | 1694 | |
d12dab4c | 1695 | drv->eapol_tx_sock = socket(PF_PACKET, SOCK_DGRAM, 0); |
32ab4855 JB |
1696 | if (drv->eapol_tx_sock < 0) |
1697 | goto failed; | |
1698 | ||
1699 | if (drv->data_tx_status) { | |
1700 | int enabled = 1; | |
1701 | ||
1702 | if (setsockopt(drv->eapol_tx_sock, SOL_SOCKET, SO_WIFI_STATUS, | |
1703 | &enabled, sizeof(enabled)) < 0) { | |
1704 | wpa_printf(MSG_DEBUG, | |
1705 | "nl80211: wifi status sockopt failed\n"); | |
1706 | drv->data_tx_status = 0; | |
a11241fa JB |
1707 | if (!drv->use_monitor) |
1708 | drv->capa.flags &= | |
1709 | ~WPA_DRIVER_FLAGS_EAPOL_TX_STATUS; | |
32ab4855 JB |
1710 | } else { |
1711 | eloop_register_read_sock(drv->eapol_tx_sock, | |
1712 | wpa_driver_nl80211_handle_eapol_tx_status, | |
1713 | drv, NULL); | |
1714 | } | |
1715 | } | |
f10bfc9a | 1716 | |
dac12351 | 1717 | if (drv->global) { |
f51f54a0 | 1718 | nl80211_check_global(drv->global); |
c4bb8817 | 1719 | dl_list_add(&drv->global->interfaces, &drv->list); |
dac12351 BG |
1720 | drv->in_interface_list = 1; |
1721 | } | |
c4bb8817 | 1722 | |
a2e40bb6 | 1723 | return bss; |
7524cfb1 | 1724 | |
bbaf0837 | 1725 | failed: |
dac12351 | 1726 | wpa_driver_nl80211_deinit(bss); |
7524cfb1 JM |
1727 | return NULL; |
1728 | } | |
1729 | ||
1730 | ||
0d547d5f JM |
1731 | /** |
1732 | * wpa_driver_nl80211_init - Initialize nl80211 driver interface | |
1733 | * @ctx: context to be used when calling wpa_supplicant functions, | |
1734 | * e.g., wpa_supplicant_event() | |
1735 | * @ifname: interface name, e.g., wlan0 | |
1736 | * @global_priv: private driver global data from global_init() | |
1737 | * Returns: Pointer to private data, %NULL on failure | |
1738 | */ | |
1739 | static void * wpa_driver_nl80211_init(void *ctx, const char *ifname, | |
1740 | void *global_priv) | |
1741 | { | |
0ecff8d7 JM |
1742 | return wpa_driver_nl80211_drv_init(ctx, ifname, global_priv, 0, NULL, |
1743 | NULL); | |
0d547d5f JM |
1744 | } |
1745 | ||
1746 | ||
a11241fa | 1747 | static int nl80211_register_frame(struct i802_bss *bss, |
5582a5d1 | 1748 | struct nl_handle *nl_handle, |
bd94971e | 1749 | u16 type, const u8 *match, size_t match_len) |
58f6fbe0 | 1750 | { |
a11241fa | 1751 | struct wpa_driver_nl80211_data *drv = bss->drv; |
58f6fbe0 | 1752 | struct nl_msg *msg; |
a862e4a3 | 1753 | int ret; |
880de885 | 1754 | char buf[30]; |
58f6fbe0 | 1755 | |
880de885 JM |
1756 | buf[0] = '\0'; |
1757 | wpa_snprintf_hex(buf, sizeof(buf), match, match_len); | |
dedfa440 PF |
1758 | wpa_printf(MSG_DEBUG, "nl80211: Register frame type=0x%x (%s) nl_handle=%p match=%s", |
1759 | type, fc2str(type), nl_handle, buf); | |
36488c05 | 1760 | |
56f77852 | 1761 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_REGISTER_ACTION)) || |
a862e4a3 JM |
1762 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, type) || |
1763 | nla_put(msg, NL80211_ATTR_FRAME_MATCH, match_len, match)) { | |
1764 | nlmsg_free(msg); | |
1765 | return -1; | |
1766 | } | |
58f6fbe0 | 1767 | |
d6c9aab8 | 1768 | ret = send_and_recv(drv->global, nl_handle, msg, NULL, NULL); |
58f6fbe0 | 1769 | if (ret) { |
5582a5d1 JB |
1770 | wpa_printf(MSG_DEBUG, "nl80211: Register frame command " |
1771 | "failed (type=%u): ret=%d (%s)", | |
1772 | type, ret, strerror(-ret)); | |
1773 | wpa_hexdump(MSG_DEBUG, "nl80211: Register frame match", | |
58f6fbe0 | 1774 | match, match_len); |
58f6fbe0 | 1775 | } |
58f6fbe0 JM |
1776 | return ret; |
1777 | } | |
1778 | ||
1779 | ||
a11241fa JB |
1780 | static int nl80211_alloc_mgmt_handle(struct i802_bss *bss) |
1781 | { | |
481234cf | 1782 | if (bss->nl_mgmt) { |
a11241fa | 1783 | wpa_printf(MSG_DEBUG, "nl80211: Mgmt reporting " |
36488c05 | 1784 | "already on! (nl_mgmt=%p)", bss->nl_mgmt); |
a11241fa JB |
1785 | return -1; |
1786 | } | |
1787 | ||
ce20a370 | 1788 | bss->nl_mgmt = nl_create_handle(bss->nl_cb, "mgmt"); |
481234cf | 1789 | if (bss->nl_mgmt == NULL) |
a11241fa JB |
1790 | return -1; |
1791 | ||
a11241fa JB |
1792 | return 0; |
1793 | } | |
1794 | ||
1795 | ||
5f65e9f7 JB |
1796 | static void nl80211_mgmt_handle_register_eloop(struct i802_bss *bss) |
1797 | { | |
1798 | nl80211_register_eloop_read(&bss->nl_mgmt, | |
1799 | wpa_driver_nl80211_event_receive, | |
1800 | bss->nl_cb); | |
1801 | } | |
1802 | ||
1803 | ||
a11241fa | 1804 | static int nl80211_register_action_frame(struct i802_bss *bss, |
bd94971e JB |
1805 | const u8 *match, size_t match_len) |
1806 | { | |
1807 | u16 type = (WLAN_FC_TYPE_MGMT << 2) | (WLAN_FC_STYPE_ACTION << 4); | |
481234cf | 1808 | return nl80211_register_frame(bss, bss->nl_mgmt, |
5582a5d1 | 1809 | type, match, match_len); |
bd94971e JB |
1810 | } |
1811 | ||
1812 | ||
a11241fa | 1813 | static int nl80211_mgmt_subscribe_non_ap(struct i802_bss *bss) |
58f6fbe0 | 1814 | { |
a11241fa | 1815 | struct wpa_driver_nl80211_data *drv = bss->drv; |
6f06766e | 1816 | int ret = 0; |
a11241fa JB |
1817 | |
1818 | if (nl80211_alloc_mgmt_handle(bss)) | |
1819 | return -1; | |
36488c05 JM |
1820 | wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with non-AP " |
1821 | "handle %p", bss->nl_mgmt); | |
a11241fa | 1822 | |
e8d1168b JB |
1823 | if (drv->nlmode == NL80211_IFTYPE_ADHOC) { |
1824 | u16 type = (WLAN_FC_TYPE_MGMT << 2) | (WLAN_FC_STYPE_AUTH << 4); | |
1825 | ||
1826 | /* register for any AUTH message */ | |
1827 | nl80211_register_frame(bss, bss->nl_mgmt, type, NULL, 0); | |
1828 | } | |
1829 | ||
56f5af48 JM |
1830 | #ifdef CONFIG_INTERWORKING |
1831 | /* QoS Map Configure */ | |
1832 | if (nl80211_register_action_frame(bss, (u8 *) "\x01\x04", 2) < 0) | |
6f06766e | 1833 | ret = -1; |
56f5af48 | 1834 | #endif /* CONFIG_INTERWORKING */ |
4fe9fa0d | 1835 | #if defined(CONFIG_P2P) || defined(CONFIG_INTERWORKING) |
046b26a2 | 1836 | /* GAS Initial Request */ |
a11241fa | 1837 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0a", 2) < 0) |
6f06766e | 1838 | ret = -1; |
046b26a2 | 1839 | /* GAS Initial Response */ |
a11241fa | 1840 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0b", 2) < 0) |
6f06766e | 1841 | ret = -1; |
18708aad | 1842 | /* GAS Comeback Request */ |
a11241fa | 1843 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0c", 2) < 0) |
6f06766e | 1844 | ret = -1; |
18708aad | 1845 | /* GAS Comeback Response */ |
a11241fa | 1846 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0d", 2) < 0) |
6f06766e | 1847 | ret = -1; |
c5a64e2d JM |
1848 | /* Protected GAS Initial Request */ |
1849 | if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0a", 2) < 0) | |
1850 | ret = -1; | |
1851 | /* Protected GAS Initial Response */ | |
1852 | if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0b", 2) < 0) | |
1853 | ret = -1; | |
1854 | /* Protected GAS Comeback Request */ | |
1855 | if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0c", 2) < 0) | |
1856 | ret = -1; | |
1857 | /* Protected GAS Comeback Response */ | |
1858 | if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0d", 2) < 0) | |
1859 | ret = -1; | |
4fe9fa0d JM |
1860 | #endif /* CONFIG_P2P || CONFIG_INTERWORKING */ |
1861 | #ifdef CONFIG_P2P | |
046b26a2 | 1862 | /* P2P Public Action */ |
a11241fa | 1863 | if (nl80211_register_action_frame(bss, |
046b26a2 JM |
1864 | (u8 *) "\x04\x09\x50\x6f\x9a\x09", |
1865 | 6) < 0) | |
6f06766e | 1866 | ret = -1; |
046b26a2 | 1867 | /* P2P Action */ |
a11241fa | 1868 | if (nl80211_register_action_frame(bss, |
046b26a2 JM |
1869 | (u8 *) "\x7f\x50\x6f\x9a\x09", |
1870 | 5) < 0) | |
6f06766e | 1871 | ret = -1; |
046b26a2 | 1872 | #endif /* CONFIG_P2P */ |
7d878ca7 JM |
1873 | #ifdef CONFIG_IEEE80211W |
1874 | /* SA Query Response */ | |
a11241fa | 1875 | if (nl80211_register_action_frame(bss, (u8 *) "\x08\x01", 2) < 0) |
6f06766e | 1876 | ret = -1; |
7d878ca7 | 1877 | #endif /* CONFIG_IEEE80211W */ |
35287637 AN |
1878 | #ifdef CONFIG_TDLS |
1879 | if ((drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) { | |
1880 | /* TDLS Discovery Response */ | |
aa543c0c | 1881 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0e", 2) < |
35287637 | 1882 | 0) |
6f06766e | 1883 | ret = -1; |
35287637 AN |
1884 | } |
1885 | #endif /* CONFIG_TDLS */ | |
46ab9b8c AN |
1886 | #ifdef CONFIG_FST |
1887 | /* FST Action frames */ | |
1888 | if (nl80211_register_action_frame(bss, (u8 *) "\x12", 1) < 0) | |
1889 | ret = -1; | |
1890 | #endif /* CONFIG_FST */ | |
046b26a2 | 1891 | |
7b90c16a | 1892 | /* FT Action frames */ |
a11241fa | 1893 | if (nl80211_register_action_frame(bss, (u8 *) "\x06", 1) < 0) |
6f06766e | 1894 | ret = -1; |
7b90c16a JM |
1895 | else |
1896 | drv->capa.key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FT | | |
1897 | WPA_DRIVER_CAPA_KEY_MGMT_FT_PSK; | |
1898 | ||
71269b37 | 1899 | /* WNM - BSS Transition Management Request */ |
a11241fa | 1900 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x07", 2) < 0) |
6f06766e | 1901 | ret = -1; |
bd896433 JM |
1902 | /* WNM-Sleep Mode Response */ |
1903 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x11", 2) < 0) | |
6f06766e | 1904 | ret = -1; |
a11241fa | 1905 | |
95a3ea94 JM |
1906 | #ifdef CONFIG_HS20 |
1907 | /* WNM-Notification */ | |
1908 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x1a", 2) < 0) | |
3ee18569 | 1909 | ret = -1; |
95a3ea94 JM |
1910 | #endif /* CONFIG_HS20 */ |
1911 | ||
dfa87878 MB |
1912 | /* WMM-AC ADDTS Response */ |
1913 | if (nl80211_register_action_frame(bss, (u8 *) "\x11\x01", 2) < 0) | |
730a0d16 | 1914 | ret = -1; |
dfa87878 MB |
1915 | |
1916 | /* WMM-AC DELTS */ | |
1917 | if (nl80211_register_action_frame(bss, (u8 *) "\x11\x02", 2) < 0) | |
730a0d16 | 1918 | ret = -1; |
dfa87878 | 1919 | |
2526ccd9 AK |
1920 | /* Radio Measurement - Neighbor Report Response */ |
1921 | if (nl80211_register_action_frame(bss, (u8 *) "\x05\x05", 2) < 0) | |
1922 | ret = -1; | |
1923 | ||
7dc03388 AO |
1924 | /* Radio Measurement - Link Measurement Request */ |
1925 | if ((drv->capa.rrm_flags & WPA_DRIVER_FLAGS_TX_POWER_INSERTION) && | |
1926 | (nl80211_register_action_frame(bss, (u8 *) "\x05\x02", 2) < 0)) | |
1927 | ret = -1; | |
1928 | ||
5f65e9f7 JB |
1929 | nl80211_mgmt_handle_register_eloop(bss); |
1930 | ||
6f06766e | 1931 | return ret; |
a11241fa JB |
1932 | } |
1933 | ||
1934 | ||
afb0550a BC |
1935 | static int nl80211_mgmt_subscribe_mesh(struct i802_bss *bss) |
1936 | { | |
1937 | int ret = 0; | |
1938 | ||
1939 | if (nl80211_alloc_mgmt_handle(bss)) | |
1940 | return -1; | |
1941 | ||
1942 | wpa_printf(MSG_DEBUG, | |
1943 | "nl80211: Subscribe to mgmt frames with mesh handle %p", | |
1944 | bss->nl_mgmt); | |
1945 | ||
1946 | /* Auth frames for mesh SAE */ | |
1947 | if (nl80211_register_frame(bss, bss->nl_mgmt, | |
1948 | (WLAN_FC_TYPE_MGMT << 2) | | |
1949 | (WLAN_FC_STYPE_AUTH << 4), | |
1950 | NULL, 0) < 0) | |
1951 | ret = -1; | |
1952 | ||
1953 | /* Mesh peering open */ | |
1954 | if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x01", 2) < 0) | |
1955 | ret = -1; | |
1956 | /* Mesh peering confirm */ | |
1957 | if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x02", 2) < 0) | |
1958 | ret = -1; | |
1959 | /* Mesh peering close */ | |
1960 | if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x03", 2) < 0) | |
1961 | ret = -1; | |
1962 | ||
1963 | nl80211_mgmt_handle_register_eloop(bss); | |
1964 | ||
1965 | return ret; | |
1966 | } | |
1967 | ||
1968 | ||
02bb32c3 JB |
1969 | static int nl80211_register_spurious_class3(struct i802_bss *bss) |
1970 | { | |
02bb32c3 | 1971 | struct nl_msg *msg; |
a862e4a3 | 1972 | int ret; |
02bb32c3 | 1973 | |
13f83980 JM |
1974 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_UNEXPECTED_FRAME); |
1975 | ret = send_and_recv(bss->drv->global, bss->nl_mgmt, msg, NULL, NULL); | |
02bb32c3 JB |
1976 | if (ret) { |
1977 | wpa_printf(MSG_DEBUG, "nl80211: Register spurious class3 " | |
1978 | "failed: ret=%d (%s)", | |
1979 | ret, strerror(-ret)); | |
02bb32c3 | 1980 | } |
02bb32c3 JB |
1981 | return ret; |
1982 | } | |
1983 | ||
1984 | ||
a11241fa JB |
1985 | static int nl80211_mgmt_subscribe_ap(struct i802_bss *bss) |
1986 | { | |
1987 | static const int stypes[] = { | |
1988 | WLAN_FC_STYPE_AUTH, | |
1989 | WLAN_FC_STYPE_ASSOC_REQ, | |
1990 | WLAN_FC_STYPE_REASSOC_REQ, | |
1991 | WLAN_FC_STYPE_DISASSOC, | |
1992 | WLAN_FC_STYPE_DEAUTH, | |
1993 | WLAN_FC_STYPE_ACTION, | |
1994 | WLAN_FC_STYPE_PROBE_REQ, | |
1995 | /* Beacon doesn't work as mac80211 doesn't currently allow | |
1996 | * it, but it wouldn't really be the right thing anyway as | |
1997 | * it isn't per interface ... maybe just dump the scan | |
1998 | * results periodically for OLBC? | |
1999 | */ | |
0e80ea2c | 2000 | /* WLAN_FC_STYPE_BEACON, */ |
a11241fa JB |
2001 | }; |
2002 | unsigned int i; | |
2003 | ||
2004 | if (nl80211_alloc_mgmt_handle(bss)) | |
71269b37 | 2005 | return -1; |
36488c05 JM |
2006 | wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with AP " |
2007 | "handle %p", bss->nl_mgmt); | |
71269b37 | 2008 | |
e7ecab4a | 2009 | for (i = 0; i < ARRAY_SIZE(stypes); i++) { |
481234cf | 2010 | if (nl80211_register_frame(bss, bss->nl_mgmt, |
a11241fa JB |
2011 | (WLAN_FC_TYPE_MGMT << 2) | |
2012 | (stypes[i] << 4), | |
2013 | NULL, 0) < 0) { | |
2014 | goto out_err; | |
2015 | } | |
2016 | } | |
2017 | ||
02bb32c3 JB |
2018 | if (nl80211_register_spurious_class3(bss)) |
2019 | goto out_err; | |
2020 | ||
e32ad281 JB |
2021 | if (nl80211_get_wiphy_data_ap(bss) == NULL) |
2022 | goto out_err; | |
2023 | ||
5f65e9f7 | 2024 | nl80211_mgmt_handle_register_eloop(bss); |
58f6fbe0 | 2025 | return 0; |
a11241fa JB |
2026 | |
2027 | out_err: | |
a11241fa JB |
2028 | nl_destroy_handles(&bss->nl_mgmt); |
2029 | return -1; | |
2030 | } | |
2031 | ||
2032 | ||
a6cc0602 JM |
2033 | static int nl80211_mgmt_subscribe_ap_dev_sme(struct i802_bss *bss) |
2034 | { | |
2035 | if (nl80211_alloc_mgmt_handle(bss)) | |
2036 | return -1; | |
2037 | wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with AP " | |
2038 | "handle %p (device SME)", bss->nl_mgmt); | |
2039 | ||
2040 | if (nl80211_register_frame(bss, bss->nl_mgmt, | |
2041 | (WLAN_FC_TYPE_MGMT << 2) | | |
2042 | (WLAN_FC_STYPE_ACTION << 4), | |
2043 | NULL, 0) < 0) | |
2044 | goto out_err; | |
2045 | ||
5f65e9f7 | 2046 | nl80211_mgmt_handle_register_eloop(bss); |
a6cc0602 JM |
2047 | return 0; |
2048 | ||
2049 | out_err: | |
a6cc0602 JM |
2050 | nl_destroy_handles(&bss->nl_mgmt); |
2051 | return -1; | |
2052 | } | |
2053 | ||
2054 | ||
36488c05 | 2055 | static void nl80211_mgmt_unsubscribe(struct i802_bss *bss, const char *reason) |
a11241fa | 2056 | { |
481234cf | 2057 | if (bss->nl_mgmt == NULL) |
a11241fa | 2058 | return; |
36488c05 JM |
2059 | wpa_printf(MSG_DEBUG, "nl80211: Unsubscribe mgmt frames handle %p " |
2060 | "(%s)", bss->nl_mgmt, reason); | |
5f65e9f7 | 2061 | nl80211_destroy_eloop_handle(&bss->nl_mgmt); |
e32ad281 JB |
2062 | |
2063 | nl80211_put_wiphy_data_ap(bss); | |
58f6fbe0 JM |
2064 | } |
2065 | ||
2066 | ||
8401a6b0 JM |
2067 | static void wpa_driver_nl80211_send_rfkill(void *eloop_ctx, void *timeout_ctx) |
2068 | { | |
2069 | wpa_supplicant_event(timeout_ctx, EVENT_INTERFACE_DISABLED, NULL); | |
2070 | } | |
2071 | ||
2072 | ||
eb4582f2 AS |
2073 | static void nl80211_del_p2pdev(struct i802_bss *bss) |
2074 | { | |
eb4582f2 AS |
2075 | struct nl_msg *msg; |
2076 | int ret; | |
2077 | ||
a3249fdf JM |
2078 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_DEL_INTERFACE); |
2079 | ret = send_and_recv_msgs(bss->drv, msg, NULL, NULL); | |
eb4582f2 AS |
2080 | |
2081 | wpa_printf(MSG_DEBUG, "nl80211: Delete P2P Device %s (0x%llx): %s", | |
2082 | bss->ifname, (long long unsigned int) bss->wdev_id, | |
6cb4f11d | 2083 | strerror(-ret)); |
eb4582f2 AS |
2084 | } |
2085 | ||
2086 | ||
eb4582f2 | 2087 | static int nl80211_set_p2pdev(struct i802_bss *bss, int start) |
f632e483 | 2088 | { |
f632e483 | 2089 | struct nl_msg *msg; |
a862e4a3 | 2090 | int ret; |
f632e483 | 2091 | |
a3249fdf JM |
2092 | msg = nl80211_cmd_msg(bss, 0, start ? NL80211_CMD_START_P2P_DEVICE : |
2093 | NL80211_CMD_STOP_P2P_DEVICE); | |
2094 | ret = send_and_recv_msgs(bss->drv, msg, NULL, NULL); | |
f632e483 | 2095 | |
eb4582f2 AS |
2096 | wpa_printf(MSG_DEBUG, "nl80211: %s P2P Device %s (0x%llx): %s", |
2097 | start ? "Start" : "Stop", | |
2098 | bss->ifname, (long long unsigned int) bss->wdev_id, | |
6cb4f11d | 2099 | strerror(-ret)); |
f632e483 AS |
2100 | return ret; |
2101 | } | |
f632e483 AS |
2102 | |
2103 | ||
91724d6f AS |
2104 | static int i802_set_iface_flags(struct i802_bss *bss, int up) |
2105 | { | |
2106 | enum nl80211_iftype nlmode; | |
2107 | ||
2108 | nlmode = nl80211_get_ifmode(bss); | |
2109 | if (nlmode != NL80211_IFTYPE_P2P_DEVICE) { | |
2110 | return linux_set_iface_flags(bss->drv->global->ioctl_sock, | |
2111 | bss->ifname, up); | |
2112 | } | |
2113 | ||
2114 | /* P2P Device has start/stop which is equivalent */ | |
2115 | return nl80211_set_p2pdev(bss, up); | |
2116 | } | |
2117 | ||
2118 | ||
1db718b3 JM |
2119 | #ifdef CONFIG_TESTING_OPTIONS |
2120 | static int qca_vendor_test_cmd_handler(struct nl_msg *msg, void *arg) | |
2121 | { | |
2122 | /* struct wpa_driver_nl80211_data *drv = arg; */ | |
2123 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
2124 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
2125 | ||
2126 | ||
2127 | wpa_printf(MSG_DEBUG, | |
2128 | "nl80211: QCA vendor test command response received"); | |
2129 | ||
2130 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
2131 | genlmsg_attrlen(gnlh, 0), NULL); | |
2132 | if (!tb[NL80211_ATTR_VENDOR_DATA]) { | |
2133 | wpa_printf(MSG_DEBUG, "nl80211: No vendor data attribute"); | |
2134 | return NL_SKIP; | |
2135 | } | |
2136 | ||
2137 | wpa_hexdump(MSG_DEBUG, | |
2138 | "nl80211: Received QCA vendor test command response", | |
2139 | nla_data(tb[NL80211_ATTR_VENDOR_DATA]), | |
2140 | nla_len(tb[NL80211_ATTR_VENDOR_DATA])); | |
2141 | ||
2142 | return NL_SKIP; | |
2143 | } | |
2144 | #endif /* CONFIG_TESTING_OPTIONS */ | |
2145 | ||
2146 | ||
2147 | static void qca_vendor_test(struct wpa_driver_nl80211_data *drv) | |
2148 | { | |
2149 | #ifdef CONFIG_TESTING_OPTIONS | |
2150 | struct nl_msg *msg; | |
2151 | struct nlattr *params; | |
2152 | int ret; | |
2153 | ||
2154 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || | |
2155 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || | |
2156 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | |
2157 | QCA_NL80211_VENDOR_SUBCMD_TEST) || | |
2158 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || | |
2159 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TEST, 123)) { | |
2160 | nlmsg_free(msg); | |
2161 | return; | |
2162 | } | |
2163 | nla_nest_end(msg, params); | |
2164 | ||
2165 | ret = send_and_recv_msgs(drv, msg, qca_vendor_test_cmd_handler, drv); | |
2166 | wpa_printf(MSG_DEBUG, | |
2167 | "nl80211: QCA vendor test command returned %d (%s)", | |
2168 | ret, strerror(-ret)); | |
2169 | #endif /* CONFIG_TESTING_OPTIONS */ | |
2170 | } | |
2171 | ||
2172 | ||
362f781e | 2173 | static int |
0d547d5f | 2174 | wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data *drv, |
0ecff8d7 JM |
2175 | const u8 *set_addr, int first, |
2176 | const char *driver_params) | |
7524cfb1 | 2177 | { |
834ee56f | 2178 | struct i802_bss *bss = drv->first_bss; |
8401a6b0 | 2179 | int send_rfkill_event = 0; |
0d547d5f | 2180 | enum nl80211_iftype nlmode; |
a2e40bb6 FF |
2181 | |
2182 | drv->ifindex = if_nametoindex(bss->ifname); | |
f632e483 AS |
2183 | bss->ifindex = drv->ifindex; |
2184 | bss->wdev_id = drv->global->if_add_wdevid; | |
2185 | bss->wdev_id_set = drv->global->if_add_wdevid_set; | |
2186 | ||
60b13c20 IP |
2187 | bss->if_dynamic = drv->ifindex == drv->global->if_add_ifindex; |
2188 | bss->if_dynamic = bss->if_dynamic || drv->global->if_add_wdevid_set; | |
f632e483 AS |
2189 | drv->global->if_add_wdevid_set = 0; |
2190 | ||
bf144cf6 AP |
2191 | if (!bss->if_dynamic && nl80211_get_ifmode(bss) == NL80211_IFTYPE_AP) |
2192 | bss->static_ap = 1; | |
2193 | ||
f632e483 AS |
2194 | if (wpa_driver_nl80211_capa(drv)) |
2195 | return -1; | |
a87c9d96 | 2196 | |
0ecff8d7 JM |
2197 | if (driver_params && nl80211_set_param(bss, driver_params) < 0) |
2198 | return -1; | |
2199 | ||
5fbcb45d AS |
2200 | wpa_printf(MSG_DEBUG, "nl80211: interface %s in phy %s", |
2201 | bss->ifname, drv->phyname); | |
2202 | ||
0d547d5f JM |
2203 | if (set_addr && |
2204 | (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 0) || | |
2205 | linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname, | |
2206 | set_addr))) | |
2207 | return -1; | |
2208 | ||
49b4b205 JM |
2209 | if (first && nl80211_get_ifmode(bss) == NL80211_IFTYPE_AP) |
2210 | drv->start_mode_ap = 1; | |
2211 | ||
bf144cf6 | 2212 | if (drv->hostapd || bss->static_ap) |
0d547d5f JM |
2213 | nlmode = NL80211_IFTYPE_AP; |
2214 | else if (bss->if_dynamic) | |
8e12685c | 2215 | nlmode = nl80211_get_ifmode(bss); |
0d547d5f JM |
2216 | else |
2217 | nlmode = NL80211_IFTYPE_STATION; | |
f632e483 | 2218 | |
8e12685c | 2219 | if (wpa_driver_nl80211_set_mode(bss, nlmode) < 0) { |
0d547d5f | 2220 | wpa_printf(MSG_ERROR, "nl80211: Could not configure driver mode"); |
8e12685c | 2221 | return -1; |
a87c9d96 JM |
2222 | } |
2223 | ||
8c06db70 | 2224 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) |
597b94f5 | 2225 | nl80211_get_macaddr(bss); |
f632e483 | 2226 | |
8c06db70 MB |
2227 | if (!rfkill_is_blocked(drv->rfkill)) { |
2228 | int ret = i802_set_iface_flags(bss, 1); | |
2229 | if (ret) { | |
8401a6b0 JM |
2230 | wpa_printf(MSG_ERROR, "nl80211: Could not set " |
2231 | "interface '%s' UP", bss->ifname); | |
8c06db70 | 2232 | return ret; |
8401a6b0 | 2233 | } |
e8dc205f AO |
2234 | |
2235 | if (is_p2p_net_interface(nlmode)) | |
2236 | nl80211_disable_11b_rates(bss->drv, | |
2237 | bss->drv->ifindex, 1); | |
2238 | ||
8c06db70 MB |
2239 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) |
2240 | return ret; | |
2241 | } else { | |
2242 | wpa_printf(MSG_DEBUG, "nl80211: Could not yet enable " | |
2243 | "interface '%s' due to rfkill", bss->ifname); | |
2244 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) | |
2245 | return 0; | |
2246 | drv->if_disabled = 1; | |
2247 | send_rfkill_event = 1; | |
362f781e | 2248 | } |
3f5285e8 | 2249 | |
0d547d5f JM |
2250 | if (!drv->hostapd) |
2251 | netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, | |
2252 | 1, IF_OPER_DORMANT); | |
362f781e | 2253 | |
c81eff1a | 2254 | if (linux_get_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
341eebee | 2255 | bss->addr)) |
2136f480 | 2256 | return -1; |
fee354c7 | 2257 | os_memcpy(drv->perm_addr, bss->addr, ETH_ALEN); |
f2ed8023 | 2258 | |
8401a6b0 JM |
2259 | if (send_rfkill_event) { |
2260 | eloop_register_timeout(0, 0, wpa_driver_nl80211_send_rfkill, | |
2261 | drv, drv->ctx); | |
2262 | } | |
2263 | ||
1db718b3 JM |
2264 | if (drv->vendor_cmd_test_avail) |
2265 | qca_vendor_test(drv); | |
2266 | ||
362f781e | 2267 | return 0; |
3f5285e8 JM |
2268 | } |
2269 | ||
2270 | ||
8a27af5c JM |
2271 | static int wpa_driver_nl80211_del_beacon(struct wpa_driver_nl80211_data *drv) |
2272 | { | |
2273 | struct nl_msg *msg; | |
2274 | ||
08e55ebb JM |
2275 | wpa_printf(MSG_DEBUG, "nl80211: Remove beacon (ifindex=%d)", |
2276 | drv->ifindex); | |
9725b784 | 2277 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_DEL_BEACON); |
8a27af5c | 2278 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
8a27af5c | 2279 | } |
8a27af5c JM |
2280 | |
2281 | ||
3f5285e8 | 2282 | /** |
7e5ba1b9 | 2283 | * wpa_driver_nl80211_deinit - Deinitialize nl80211 driver interface |
9ebce9c5 | 2284 | * @bss: Pointer to private nl80211 data from wpa_driver_nl80211_init() |
3f5285e8 JM |
2285 | * |
2286 | * Shut down driver interface and processing of driver events. Free | |
2287 | * private data buffer if one was allocated in wpa_driver_nl80211_init(). | |
2288 | */ | |
9ebce9c5 | 2289 | static void wpa_driver_nl80211_deinit(struct i802_bss *bss) |
3f5285e8 | 2290 | { |
a2e40bb6 | 2291 | struct wpa_driver_nl80211_data *drv = bss->drv; |
3f5285e8 | 2292 | |
3e208481 JM |
2293 | wpa_printf(MSG_INFO, "nl80211: deinit ifname=%s disabled_11b_rates=%d", |
2294 | bss->ifname, drv->disabled_11b_rates); | |
2295 | ||
873d0fcf | 2296 | bss->in_deinit = 1; |
32ab4855 JB |
2297 | if (drv->data_tx_status) |
2298 | eloop_unregister_read_sock(drv->eapol_tx_sock); | |
d12dab4c JB |
2299 | if (drv->eapol_tx_sock >= 0) |
2300 | close(drv->eapol_tx_sock); | |
f10bfc9a | 2301 | |
481234cf | 2302 | if (bss->nl_preq) |
5582a5d1 | 2303 | wpa_driver_nl80211_probe_req_report(bss, 0); |
e17a2477 | 2304 | if (bss->added_if_into_bridge) { |
c81eff1a BG |
2305 | if (linux_br_del_if(drv->global->ioctl_sock, bss->brname, |
2306 | bss->ifname) < 0) | |
94627f6c JM |
2307 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
2308 | "interface %s from bridge %s: %s", | |
e17a2477 | 2309 | bss->ifname, bss->brname, strerror(errno)); |
97ed9a06 | 2310 | if (drv->rtnl_sk) |
ca3c6b4d | 2311 | nl80211_handle_destroy(drv->rtnl_sk); |
94627f6c | 2312 | } |
e17a2477 | 2313 | if (bss->added_bridge) { |
f2535da8 JM |
2314 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->brname, |
2315 | 0) < 0) | |
2316 | wpa_printf(MSG_INFO, | |
2317 | "nl80211: Could not set bridge %s down", | |
2318 | bss->brname); | |
c81eff1a | 2319 | if (linux_br_del(drv->global->ioctl_sock, bss->brname) < 0) |
94627f6c JM |
2320 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
2321 | "bridge %s: %s", | |
e17a2477 | 2322 | bss->brname, strerror(errno)); |
94627f6c JM |
2323 | } |
2324 | ||
460456f8 | 2325 | nl80211_remove_monitor_interface(drv); |
8a27af5c | 2326 | |
b1f625e0 | 2327 | if (is_ap_interface(drv->nlmode)) |
8a27af5c | 2328 | wpa_driver_nl80211_del_beacon(drv); |
0915d02c | 2329 | |
bbaf0837 JM |
2330 | if (drv->eapol_sock >= 0) { |
2331 | eloop_unregister_read_sock(drv->eapol_sock); | |
2332 | close(drv->eapol_sock); | |
2333 | } | |
2334 | ||
2335 | if (drv->if_indices != drv->default_if_indices) | |
2336 | os_free(drv->if_indices); | |
3f5285e8 | 2337 | |
b3af99d2 | 2338 | if (drv->disabled_11b_rates) |
4e5cb1a3 JM |
2339 | nl80211_disable_11b_rates(drv, drv->ifindex, 0); |
2340 | ||
36d84860 BG |
2341 | netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, 0, |
2342 | IF_OPER_UP); | |
e390df05 | 2343 | eloop_cancel_timeout(wpa_driver_nl80211_send_rfkill, drv, drv->ctx); |
8401a6b0 | 2344 | rfkill_deinit(drv->rfkill); |
3f5285e8 | 2345 | |
bbaf0837 JM |
2346 | eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout, drv, drv->ctx); |
2347 | ||
146fa9b3 JM |
2348 | if (!drv->start_iface_up) |
2349 | (void) i802_set_iface_flags(bss, 0); | |
fee354c7 JM |
2350 | |
2351 | if (drv->addr_changed) { | |
93da0498 JM |
2352 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, |
2353 | 0) < 0) { | |
2354 | wpa_printf(MSG_DEBUG, | |
2355 | "nl80211: Could not set interface down to restore permanent MAC address"); | |
2356 | } | |
fee354c7 JM |
2357 | if (linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
2358 | drv->perm_addr) < 0) { | |
2359 | wpa_printf(MSG_DEBUG, | |
2360 | "nl80211: Could not restore permanent MAC address"); | |
2361 | } | |
2362 | } | |
2363 | ||
8e12685c | 2364 | if (drv->nlmode != NL80211_IFTYPE_P2P_DEVICE) { |
49b4b205 JM |
2365 | if (!drv->hostapd || !drv->start_mode_ap) |
2366 | wpa_driver_nl80211_set_mode(bss, | |
2367 | NL80211_IFTYPE_STATION); | |
b378c41f | 2368 | nl80211_mgmt_unsubscribe(bss, "deinit"); |
8e12685c AS |
2369 | } else { |
2370 | nl80211_mgmt_unsubscribe(bss, "deinit"); | |
eb4582f2 | 2371 | nl80211_del_p2pdev(bss); |
8e12685c | 2372 | } |
3f5285e8 | 2373 | |
834ee56f | 2374 | nl80211_destroy_bss(drv->first_bss); |
cc7a48d1 | 2375 | |
3812464c JM |
2376 | os_free(drv->filter_ssids); |
2377 | ||
536fd62d JM |
2378 | os_free(drv->auth_ie); |
2379 | ||
dac12351 | 2380 | if (drv->in_interface_list) |
f2ed8023 JM |
2381 | dl_list_del(&drv->list); |
2382 | ||
8cd6b7bc JB |
2383 | os_free(drv->extended_capa); |
2384 | os_free(drv->extended_capa_mask); | |
834ee56f | 2385 | os_free(drv->first_bss); |
3f5285e8 JM |
2386 | os_free(drv); |
2387 | } | |
2388 | ||
2389 | ||
de4ed4a8 JM |
2390 | static u32 wpa_alg_to_cipher_suite(enum wpa_alg alg, size_t key_len) |
2391 | { | |
2392 | switch (alg) { | |
2393 | case WPA_ALG_WEP: | |
2394 | if (key_len == 5) | |
2395 | return WLAN_CIPHER_SUITE_WEP40; | |
2396 | return WLAN_CIPHER_SUITE_WEP104; | |
2397 | case WPA_ALG_TKIP: | |
2398 | return WLAN_CIPHER_SUITE_TKIP; | |
2399 | case WPA_ALG_CCMP: | |
2400 | return WLAN_CIPHER_SUITE_CCMP; | |
2401 | case WPA_ALG_GCMP: | |
2402 | return WLAN_CIPHER_SUITE_GCMP; | |
2403 | case WPA_ALG_CCMP_256: | |
2404 | return WLAN_CIPHER_SUITE_CCMP_256; | |
2405 | case WPA_ALG_GCMP_256: | |
2406 | return WLAN_CIPHER_SUITE_GCMP_256; | |
2407 | case WPA_ALG_IGTK: | |
2408 | return WLAN_CIPHER_SUITE_AES_CMAC; | |
2409 | case WPA_ALG_BIP_GMAC_128: | |
2410 | return WLAN_CIPHER_SUITE_BIP_GMAC_128; | |
2411 | case WPA_ALG_BIP_GMAC_256: | |
2412 | return WLAN_CIPHER_SUITE_BIP_GMAC_256; | |
2413 | case WPA_ALG_BIP_CMAC_256: | |
2414 | return WLAN_CIPHER_SUITE_BIP_CMAC_256; | |
2415 | case WPA_ALG_SMS4: | |
2416 | return WLAN_CIPHER_SUITE_SMS4; | |
2417 | case WPA_ALG_KRK: | |
2418 | return WLAN_CIPHER_SUITE_KRK; | |
2419 | case WPA_ALG_NONE: | |
2420 | case WPA_ALG_PMK: | |
2421 | wpa_printf(MSG_ERROR, "nl80211: Unexpected encryption algorithm %d", | |
2422 | alg); | |
2423 | return 0; | |
2424 | } | |
2425 | ||
2426 | wpa_printf(MSG_ERROR, "nl80211: Unsupported encryption algorithm %d", | |
2427 | alg); | |
2428 | return 0; | |
2429 | } | |
2430 | ||
2431 | ||
2432 | static u32 wpa_cipher_to_cipher_suite(unsigned int cipher) | |
2433 | { | |
2434 | switch (cipher) { | |
2435 | case WPA_CIPHER_CCMP_256: | |
2436 | return WLAN_CIPHER_SUITE_CCMP_256; | |
2437 | case WPA_CIPHER_GCMP_256: | |
2438 | return WLAN_CIPHER_SUITE_GCMP_256; | |
2439 | case WPA_CIPHER_CCMP: | |
2440 | return WLAN_CIPHER_SUITE_CCMP; | |
2441 | case WPA_CIPHER_GCMP: | |
2442 | return WLAN_CIPHER_SUITE_GCMP; | |
2443 | case WPA_CIPHER_TKIP: | |
2444 | return WLAN_CIPHER_SUITE_TKIP; | |
2445 | case WPA_CIPHER_WEP104: | |
2446 | return WLAN_CIPHER_SUITE_WEP104; | |
2447 | case WPA_CIPHER_WEP40: | |
2448 | return WLAN_CIPHER_SUITE_WEP40; | |
ae6f9272 JM |
2449 | case WPA_CIPHER_GTK_NOT_USED: |
2450 | return WLAN_CIPHER_SUITE_NO_GROUP_ADDR; | |
de4ed4a8 JM |
2451 | } |
2452 | ||
2453 | return 0; | |
2454 | } | |
2455 | ||
2456 | ||
2457 | static int wpa_cipher_to_cipher_suites(unsigned int ciphers, u32 suites[], | |
2458 | int max_suites) | |
2459 | { | |
2460 | int num_suites = 0; | |
2461 | ||
2462 | if (num_suites < max_suites && ciphers & WPA_CIPHER_CCMP_256) | |
2463 | suites[num_suites++] = WLAN_CIPHER_SUITE_CCMP_256; | |
2464 | if (num_suites < max_suites && ciphers & WPA_CIPHER_GCMP_256) | |
2465 | suites[num_suites++] = WLAN_CIPHER_SUITE_GCMP_256; | |
2466 | if (num_suites < max_suites && ciphers & WPA_CIPHER_CCMP) | |
2467 | suites[num_suites++] = WLAN_CIPHER_SUITE_CCMP; | |
2468 | if (num_suites < max_suites && ciphers & WPA_CIPHER_GCMP) | |
2469 | suites[num_suites++] = WLAN_CIPHER_SUITE_GCMP; | |
2470 | if (num_suites < max_suites && ciphers & WPA_CIPHER_TKIP) | |
2471 | suites[num_suites++] = WLAN_CIPHER_SUITE_TKIP; | |
2472 | if (num_suites < max_suites && ciphers & WPA_CIPHER_WEP104) | |
2473 | suites[num_suites++] = WLAN_CIPHER_SUITE_WEP104; | |
2474 | if (num_suites < max_suites && ciphers & WPA_CIPHER_WEP40) | |
2475 | suites[num_suites++] = WLAN_CIPHER_SUITE_WEP40; | |
2476 | ||
2477 | return num_suites; | |
2478 | } | |
2479 | ||
2480 | ||
b658547d | 2481 | #ifdef CONFIG_DRIVER_NL80211_QCA |
b41f2684 CL |
2482 | static int issue_key_mgmt_set_key(struct wpa_driver_nl80211_data *drv, |
2483 | const u8 *key, size_t key_len) | |
2484 | { | |
2485 | struct nl_msg *msg; | |
a862e4a3 | 2486 | int ret; |
b41f2684 | 2487 | |
15badebd | 2488 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD)) |
b41f2684 CL |
2489 | return 0; |
2490 | ||
9725b784 | 2491 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
a862e4a3 JM |
2492 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
2493 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | |
2494 | QCA_NL80211_VENDOR_SUBCMD_KEY_MGMT_SET_KEY) || | |
2495 | nla_put(msg, NL80211_ATTR_VENDOR_DATA, key_len, key)) { | |
bbd89bfc | 2496 | nl80211_nlmsg_clear(msg); |
a862e4a3 JM |
2497 | nlmsg_free(msg); |
2498 | return -1; | |
2499 | } | |
bbd89bfc | 2500 | ret = send_and_recv_msgs(drv, msg, NULL, (void *) -1); |
b41f2684 CL |
2501 | if (ret) { |
2502 | wpa_printf(MSG_DEBUG, | |
2503 | "nl80211: Key management set key failed: ret=%d (%s)", | |
2504 | ret, strerror(-ret)); | |
2505 | } | |
2506 | ||
b41f2684 CL |
2507 | return ret; |
2508 | } | |
b658547d | 2509 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
b41f2684 CL |
2510 | |
2511 | ||
9ebce9c5 | 2512 | static int wpa_driver_nl80211_set_key(const char *ifname, struct i802_bss *bss, |
71934751 JM |
2513 | enum wpa_alg alg, const u8 *addr, |
2514 | int key_idx, int set_tx, | |
642187d6 JM |
2515 | const u8 *seq, size_t seq_len, |
2516 | const u8 *key, size_t key_len) | |
3f5285e8 | 2517 | { |
a2e40bb6 | 2518 | struct wpa_driver_nl80211_data *drv = bss->drv; |
e472e1b4 | 2519 | int ifindex; |
34651767 | 2520 | struct nl_msg *msg = NULL; |
1ad1cdc2 | 2521 | int ret; |
dc01de8a | 2522 | int tdls = 0; |
3f5285e8 | 2523 | |
e472e1b4 AS |
2524 | /* Ignore for P2P Device */ |
2525 | if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) | |
2526 | return 0; | |
2527 | ||
2528 | ifindex = if_nametoindex(ifname); | |
8393e1a0 | 2529 | wpa_printf(MSG_DEBUG, "%s: ifindex=%d (%s) alg=%d addr=%p key_idx=%d " |
1ad1cdc2 | 2530 | "set_tx=%d seq_len=%lu key_len=%lu", |
8393e1a0 | 2531 | __func__, ifindex, ifname, alg, addr, key_idx, set_tx, |
3f5285e8 | 2532 | (unsigned long) seq_len, (unsigned long) key_len); |
8c66e185 | 2533 | #ifdef CONFIG_TDLS |
dc01de8a | 2534 | if (key_idx == -1) { |
8c66e185 | 2535 | key_idx = 0; |
dc01de8a JM |
2536 | tdls = 1; |
2537 | } | |
8c66e185 | 2538 | #endif /* CONFIG_TDLS */ |
3f5285e8 | 2539 | |
b658547d | 2540 | #ifdef CONFIG_DRIVER_NL80211_QCA |
15badebd CL |
2541 | if (alg == WPA_ALG_PMK && |
2542 | (drv->capa.flags & WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD)) { | |
b41f2684 CL |
2543 | wpa_printf(MSG_DEBUG, "%s: calling issue_key_mgmt_set_key", |
2544 | __func__); | |
2545 | ret = issue_key_mgmt_set_key(drv, key, key_len); | |
2546 | return ret; | |
2547 | } | |
b658547d | 2548 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
b41f2684 | 2549 | |
3f5285e8 | 2550 | if (alg == WPA_ALG_NONE) { |
95376e1a JM |
2551 | msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_DEL_KEY); |
2552 | if (!msg) | |
2553 | return -ENOBUFS; | |
3f5285e8 | 2554 | } else { |
34651767 JM |
2555 | u32 suite; |
2556 | ||
2557 | suite = wpa_alg_to_cipher_suite(alg, key_len); | |
2558 | if (!suite) | |
2559 | goto fail; | |
95376e1a JM |
2560 | msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_NEW_KEY); |
2561 | if (!msg || | |
a862e4a3 | 2562 | nla_put(msg, NL80211_ATTR_KEY_DATA, key_len, key) || |
34651767 | 2563 | nla_put_u32(msg, NL80211_ATTR_KEY_CIPHER, suite)) |
a862e4a3 | 2564 | goto fail; |
e6ef73f1 | 2565 | wpa_hexdump_key(MSG_DEBUG, "nl80211: KEY_DATA", key, key_len); |
3f5285e8 JM |
2566 | } |
2567 | ||
e6ef73f1 | 2568 | if (seq && seq_len) { |
a862e4a3 JM |
2569 | if (nla_put(msg, NL80211_ATTR_KEY_SEQ, seq_len, seq)) |
2570 | goto fail; | |
e6ef73f1 JM |
2571 | wpa_hexdump(MSG_DEBUG, "nl80211: KEY_SEQ", seq, seq_len); |
2572 | } | |
1ad1cdc2 | 2573 | |
0382097e | 2574 | if (addr && !is_broadcast_ether_addr(addr)) { |
3f5285e8 | 2575 | wpa_printf(MSG_DEBUG, " addr=" MACSTR, MAC2STR(addr)); |
a862e4a3 JM |
2576 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
2577 | goto fail; | |
89c38e32 JM |
2578 | |
2579 | if (alg != WPA_ALG_WEP && key_idx && !set_tx) { | |
2580 | wpa_printf(MSG_DEBUG, " RSN IBSS RX GTK"); | |
a862e4a3 JM |
2581 | if (nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, |
2582 | NL80211_KEYTYPE_GROUP)) | |
2583 | goto fail; | |
89c38e32 | 2584 | } |
60ea8187 | 2585 | } else if (addr && is_broadcast_ether_addr(addr)) { |
8970bae8 JB |
2586 | struct nlattr *types; |
2587 | ||
60ea8187 | 2588 | wpa_printf(MSG_DEBUG, " broadcast key"); |
8970bae8 JB |
2589 | |
2590 | types = nla_nest_start(msg, NL80211_ATTR_KEY_DEFAULT_TYPES); | |
a862e4a3 JM |
2591 | if (!types || |
2592 | nla_put_flag(msg, NL80211_KEY_DEFAULT_TYPE_MULTICAST)) | |
2593 | goto fail; | |
8970bae8 | 2594 | nla_nest_end(msg, types); |
3f5285e8 | 2595 | } |
95376e1a | 2596 | if (nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) |
a862e4a3 | 2597 | goto fail; |
3f5285e8 | 2598 | |
bbd89bfc | 2599 | ret = send_and_recv_msgs(drv, msg, NULL, key ? (void *) -1 : NULL); |
15664ad0 | 2600 | if ((ret == -ENOENT || ret == -ENOLINK) && alg == WPA_ALG_NONE) |
1ad1cdc2 JM |
2601 | ret = 0; |
2602 | if (ret) | |
2603 | wpa_printf(MSG_DEBUG, "nl80211: set_key failed; err=%d %s)", | |
2604 | ret, strerror(-ret)); | |
3f5285e8 | 2605 | |
1ad1cdc2 JM |
2606 | /* |
2607 | * If we failed or don't need to set the default TX key (below), | |
2608 | * we're done here. | |
2609 | */ | |
dc01de8a | 2610 | if (ret || !set_tx || alg == WPA_ALG_NONE || tdls) |
1ad1cdc2 | 2611 | return ret; |
b1f625e0 | 2612 | if (is_ap_interface(drv->nlmode) && addr && |
0382097e | 2613 | !is_broadcast_ether_addr(addr)) |
de12717a | 2614 | return ret; |
3f5285e8 | 2615 | |
95376e1a JM |
2616 | msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_SET_KEY); |
2617 | if (!msg || | |
a862e4a3 | 2618 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx) || |
86f9b1c7 JM |
2619 | nla_put_flag(msg, (alg == WPA_ALG_IGTK || |
2620 | alg == WPA_ALG_BIP_GMAC_128 || | |
2621 | alg == WPA_ALG_BIP_GMAC_256 || | |
2622 | alg == WPA_ALG_BIP_CMAC_256) ? | |
a862e4a3 JM |
2623 | NL80211_ATTR_KEY_DEFAULT_MGMT : |
2624 | NL80211_ATTR_KEY_DEFAULT)) | |
2625 | goto fail; | |
60ea8187 | 2626 | if (addr && is_broadcast_ether_addr(addr)) { |
8970bae8 JB |
2627 | struct nlattr *types; |
2628 | ||
2629 | types = nla_nest_start(msg, NL80211_ATTR_KEY_DEFAULT_TYPES); | |
a862e4a3 JM |
2630 | if (!types || |
2631 | nla_put_flag(msg, NL80211_KEY_DEFAULT_TYPE_MULTICAST)) | |
2632 | goto fail; | |
8970bae8 | 2633 | nla_nest_end(msg, types); |
60ea8187 | 2634 | } else if (addr) { |
8970bae8 JB |
2635 | struct nlattr *types; |
2636 | ||
2637 | types = nla_nest_start(msg, NL80211_ATTR_KEY_DEFAULT_TYPES); | |
a862e4a3 JM |
2638 | if (!types || |
2639 | nla_put_flag(msg, NL80211_KEY_DEFAULT_TYPE_UNICAST)) | |
2640 | goto fail; | |
8970bae8 | 2641 | nla_nest_end(msg, types); |
60ea8187 | 2642 | } |
3f5285e8 | 2643 | |
1ad1cdc2 JM |
2644 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
2645 | if (ret == -ENOENT) | |
2646 | ret = 0; | |
2647 | if (ret) | |
2648 | wpa_printf(MSG_DEBUG, "nl80211: set_key default failed; " | |
2649 | "err=%d %s)", ret, strerror(-ret)); | |
2650 | return ret; | |
3f5285e8 | 2651 | |
a862e4a3 | 2652 | fail: |
bbd89bfc | 2653 | nl80211_nlmsg_clear(msg); |
5883168a | 2654 | nlmsg_free(msg); |
6241fcb1 | 2655 | return -ENOBUFS; |
3f5285e8 JM |
2656 | } |
2657 | ||
2658 | ||
71934751 | 2659 | static int nl_add_key(struct nl_msg *msg, enum wpa_alg alg, |
0194fedb JB |
2660 | int key_idx, int defkey, |
2661 | const u8 *seq, size_t seq_len, | |
2662 | const u8 *key, size_t key_len) | |
2663 | { | |
2664 | struct nlattr *key_attr = nla_nest_start(msg, NL80211_ATTR_KEY); | |
34651767 JM |
2665 | u32 suite; |
2666 | ||
0194fedb JB |
2667 | if (!key_attr) |
2668 | return -1; | |
2669 | ||
34651767 JM |
2670 | suite = wpa_alg_to_cipher_suite(alg, key_len); |
2671 | if (!suite) | |
2672 | return -1; | |
2673 | ||
a862e4a3 JM |
2674 | if (defkey && alg == WPA_ALG_IGTK) { |
2675 | if (nla_put_flag(msg, NL80211_KEY_DEFAULT_MGMT)) | |
2676 | return -1; | |
2677 | } else if (defkey) { | |
2678 | if (nla_put_flag(msg, NL80211_KEY_DEFAULT)) | |
2679 | return -1; | |
2680 | } | |
0194fedb | 2681 | |
a862e4a3 | 2682 | if (nla_put_u8(msg, NL80211_KEY_IDX, key_idx) || |
34651767 | 2683 | nla_put_u32(msg, NL80211_KEY_CIPHER, suite) || |
a862e4a3 JM |
2684 | (seq && seq_len && |
2685 | nla_put(msg, NL80211_KEY_SEQ, seq_len, seq)) || | |
2686 | nla_put(msg, NL80211_KEY_DATA, key_len, key)) | |
2687 | return -1; | |
0194fedb JB |
2688 | |
2689 | nla_nest_end(msg, key_attr); | |
2690 | ||
2691 | return 0; | |
0194fedb JB |
2692 | } |
2693 | ||
c811d5bc | 2694 | |
cfaab580 ZY |
2695 | static int nl80211_set_conn_keys(struct wpa_driver_associate_params *params, |
2696 | struct nl_msg *msg) | |
2697 | { | |
2698 | int i, privacy = 0; | |
2699 | struct nlattr *nl_keys, *nl_key; | |
2700 | ||
2701 | for (i = 0; i < 4; i++) { | |
2702 | if (!params->wep_key[i]) | |
2703 | continue; | |
2704 | privacy = 1; | |
2705 | break; | |
2706 | } | |
ce04af5a JM |
2707 | if (params->wps == WPS_MODE_PRIVACY) |
2708 | privacy = 1; | |
2709 | if (params->pairwise_suite && | |
2710 | params->pairwise_suite != WPA_CIPHER_NONE) | |
2711 | privacy = 1; | |
2712 | ||
cfaab580 ZY |
2713 | if (!privacy) |
2714 | return 0; | |
2715 | ||
a862e4a3 JM |
2716 | if (nla_put_flag(msg, NL80211_ATTR_PRIVACY)) |
2717 | return -ENOBUFS; | |
cfaab580 ZY |
2718 | |
2719 | nl_keys = nla_nest_start(msg, NL80211_ATTR_KEYS); | |
2720 | if (!nl_keys) | |
a862e4a3 | 2721 | return -ENOBUFS; |
cfaab580 ZY |
2722 | |
2723 | for (i = 0; i < 4; i++) { | |
2724 | if (!params->wep_key[i]) | |
2725 | continue; | |
2726 | ||
2727 | nl_key = nla_nest_start(msg, i); | |
a862e4a3 JM |
2728 | if (!nl_key || |
2729 | nla_put(msg, NL80211_KEY_DATA, params->wep_key_len[i], | |
2730 | params->wep_key[i]) || | |
2731 | nla_put_u32(msg, NL80211_KEY_CIPHER, | |
2732 | params->wep_key_len[i] == 5 ? | |
2733 | WLAN_CIPHER_SUITE_WEP40 : | |
2734 | WLAN_CIPHER_SUITE_WEP104) || | |
2735 | nla_put_u8(msg, NL80211_KEY_IDX, i) || | |
2736 | (i == params->wep_tx_keyidx && | |
2737 | nla_put_flag(msg, NL80211_KEY_DEFAULT))) | |
2738 | return -ENOBUFS; | |
cfaab580 ZY |
2739 | |
2740 | nla_nest_end(msg, nl_key); | |
2741 | } | |
2742 | nla_nest_end(msg, nl_keys); | |
2743 | ||
2744 | return 0; | |
cfaab580 ZY |
2745 | } |
2746 | ||
2747 | ||
477af8f8 JM |
2748 | int wpa_driver_nl80211_mlme(struct wpa_driver_nl80211_data *drv, |
2749 | const u8 *addr, int cmd, u16 reason_code, | |
2750 | int local_state_change) | |
c2a04078 | 2751 | { |
a862e4a3 | 2752 | int ret; |
c2a04078 JM |
2753 | struct nl_msg *msg; |
2754 | ||
9725b784 | 2755 | if (!(msg = nl80211_drv_msg(drv, 0, cmd)) || |
a862e4a3 JM |
2756 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code) || |
2757 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || | |
2758 | (local_state_change && | |
2759 | nla_put_flag(msg, NL80211_ATTR_LOCAL_STATE_CHANGE))) { | |
2760 | nlmsg_free(msg); | |
2761 | return -1; | |
2762 | } | |
c2a04078 JM |
2763 | |
2764 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
c2a04078 | 2765 | if (ret) { |
3b7ea880 BG |
2766 | wpa_dbg(drv->ctx, MSG_DEBUG, |
2767 | "nl80211: MLME command failed: reason=%u ret=%d (%s)", | |
2768 | reason_code, ret, strerror(-ret)); | |
c2a04078 | 2769 | } |
c2a04078 JM |
2770 | return ret; |
2771 | } | |
3f5285e8 JM |
2772 | |
2773 | ||
cfaab580 | 2774 | static int wpa_driver_nl80211_disconnect(struct wpa_driver_nl80211_data *drv, |
817762d9 | 2775 | int reason_code) |
cfaab580 | 2776 | { |
3f53c006 JJ |
2777 | int ret; |
2778 | ||
817762d9 | 2779 | wpa_printf(MSG_DEBUG, "%s(reason_code=%d)", __func__, reason_code); |
add9b7a4 | 2780 | nl80211_mark_disconnected(drv); |
817762d9 | 2781 | /* Disconnect command doesn't need BSSID - it uses cached value */ |
3f53c006 JJ |
2782 | ret = wpa_driver_nl80211_mlme(drv, NULL, NL80211_CMD_DISCONNECT, |
2783 | reason_code, 0); | |
2784 | /* | |
2785 | * For locally generated disconnect, supplicant already generates a | |
2786 | * DEAUTH event, so ignore the event from NL80211. | |
2787 | */ | |
2788 | drv->ignore_next_local_disconnect = ret == 0; | |
2789 | ||
2790 | return ret; | |
cfaab580 ZY |
2791 | } |
2792 | ||
2793 | ||
9ebce9c5 JM |
2794 | static int wpa_driver_nl80211_deauthenticate(struct i802_bss *bss, |
2795 | const u8 *addr, int reason_code) | |
3f5285e8 | 2796 | { |
a2e40bb6 | 2797 | struct wpa_driver_nl80211_data *drv = bss->drv; |
d6a36f39 | 2798 | int ret; |
9392c9be AS |
2799 | |
2800 | if (drv->nlmode == NL80211_IFTYPE_ADHOC) { | |
2801 | nl80211_mark_disconnected(drv); | |
666e508c | 2802 | return nl80211_leave_ibss(drv, 1); |
9392c9be | 2803 | } |
cfaab580 | 2804 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) |
817762d9 | 2805 | return wpa_driver_nl80211_disconnect(drv, reason_code); |
2e75a2b3 JM |
2806 | wpa_printf(MSG_DEBUG, "%s(addr=" MACSTR " reason_code=%d)", |
2807 | __func__, MAC2STR(addr), reason_code); | |
add9b7a4 | 2808 | nl80211_mark_disconnected(drv); |
d6a36f39 JM |
2809 | ret = wpa_driver_nl80211_mlme(drv, addr, NL80211_CMD_DEAUTHENTICATE, |
2810 | reason_code, 0); | |
2811 | /* | |
2812 | * For locally generated deauthenticate, supplicant already generates a | |
2813 | * DEAUTH event, so ignore the event from NL80211. | |
2814 | */ | |
2815 | drv->ignore_next_local_deauth = ret == 0; | |
2816 | return ret; | |
3f5285e8 JM |
2817 | } |
2818 | ||
2819 | ||
536fd62d JM |
2820 | static void nl80211_copy_auth_params(struct wpa_driver_nl80211_data *drv, |
2821 | struct wpa_driver_auth_params *params) | |
2822 | { | |
2823 | int i; | |
2824 | ||
2825 | drv->auth_freq = params->freq; | |
2826 | drv->auth_alg = params->auth_alg; | |
2827 | drv->auth_wep_tx_keyidx = params->wep_tx_keyidx; | |
2828 | drv->auth_local_state_change = params->local_state_change; | |
2829 | drv->auth_p2p = params->p2p; | |
2830 | ||
2831 | if (params->bssid) | |
2832 | os_memcpy(drv->auth_bssid_, params->bssid, ETH_ALEN); | |
2833 | else | |
2834 | os_memset(drv->auth_bssid_, 0, ETH_ALEN); | |
2835 | ||
2836 | if (params->ssid) { | |
2837 | os_memcpy(drv->auth_ssid, params->ssid, params->ssid_len); | |
2838 | drv->auth_ssid_len = params->ssid_len; | |
2839 | } else | |
2840 | drv->auth_ssid_len = 0; | |
2841 | ||
2842 | ||
2843 | os_free(drv->auth_ie); | |
2844 | drv->auth_ie = NULL; | |
2845 | drv->auth_ie_len = 0; | |
2846 | if (params->ie) { | |
2847 | drv->auth_ie = os_malloc(params->ie_len); | |
2848 | if (drv->auth_ie) { | |
2849 | os_memcpy(drv->auth_ie, params->ie, params->ie_len); | |
2850 | drv->auth_ie_len = params->ie_len; | |
2851 | } | |
2852 | } | |
2853 | ||
2854 | for (i = 0; i < 4; i++) { | |
2855 | if (params->wep_key[i] && params->wep_key_len[i] && | |
2856 | params->wep_key_len[i] <= 16) { | |
2857 | os_memcpy(drv->auth_wep_key[i], params->wep_key[i], | |
2858 | params->wep_key_len[i]); | |
2859 | drv->auth_wep_key_len[i] = params->wep_key_len[i]; | |
2860 | } else | |
2861 | drv->auth_wep_key_len[i] = 0; | |
2862 | } | |
2863 | } | |
2864 | ||
2865 | ||
4bd71954 JM |
2866 | static void nl80211_unmask_11b_rates(struct i802_bss *bss) |
2867 | { | |
2868 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
2869 | ||
2870 | if (is_p2p_net_interface(drv->nlmode) || !drv->disabled_11b_rates) | |
2871 | return; | |
2872 | ||
2873 | /* | |
2874 | * Looks like we failed to unmask 11b rates previously. This could | |
2875 | * happen, e.g., if the interface was down at the point in time when a | |
2876 | * P2P group was terminated. | |
2877 | */ | |
2878 | wpa_printf(MSG_DEBUG, | |
2879 | "nl80211: Interface %s mode is for non-P2P, but 11b rates were disabled - re-enable them", | |
2880 | bss->ifname); | |
2881 | nl80211_disable_11b_rates(drv, drv->ifindex, 0); | |
2882 | } | |
2883 | ||
2884 | ||
c2a04078 | 2885 | static int wpa_driver_nl80211_authenticate( |
9ebce9c5 | 2886 | struct i802_bss *bss, struct wpa_driver_auth_params *params) |
c2a04078 | 2887 | { |
a2e40bb6 | 2888 | struct wpa_driver_nl80211_data *drv = bss->drv; |
a0b2f99b | 2889 | int ret = -1, i; |
c2a04078 JM |
2890 | struct nl_msg *msg; |
2891 | enum nl80211_auth_type type; | |
2f4f73b1 | 2892 | enum nl80211_iftype nlmode; |
6d6f4bb8 | 2893 | int count = 0; |
536fd62d JM |
2894 | int is_retry; |
2895 | ||
4bd71954 JM |
2896 | nl80211_unmask_11b_rates(bss); |
2897 | ||
536fd62d JM |
2898 | is_retry = drv->retry_auth; |
2899 | drv->retry_auth = 0; | |
e8d70a73 | 2900 | drv->ignore_deauth_event = 0; |
c2a04078 | 2901 | |
add9b7a4 | 2902 | nl80211_mark_disconnected(drv); |
e6b8efeb | 2903 | os_memset(drv->auth_bssid, 0, ETH_ALEN); |
add9b7a4 JM |
2904 | if (params->bssid) |
2905 | os_memcpy(drv->auth_attempt_bssid, params->bssid, ETH_ALEN); | |
2906 | else | |
2907 | os_memset(drv->auth_attempt_bssid, 0, ETH_ALEN); | |
af473088 | 2908 | /* FIX: IBSS mode */ |
2f4f73b1 EP |
2909 | nlmode = params->p2p ? |
2910 | NL80211_IFTYPE_P2P_CLIENT : NL80211_IFTYPE_STATION; | |
2911 | if (drv->nlmode != nlmode && | |
9ebce9c5 | 2912 | wpa_driver_nl80211_set_mode(bss, nlmode) < 0) |
4a867032 JM |
2913 | return -1; |
2914 | ||
6d6f4bb8 | 2915 | retry: |
c2a04078 JM |
2916 | wpa_printf(MSG_DEBUG, "nl80211: Authenticate (ifindex=%d)", |
2917 | drv->ifindex); | |
a0b2f99b | 2918 | |
9725b784 JM |
2919 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_AUTHENTICATE); |
2920 | if (!msg) | |
2921 | goto fail; | |
0194fedb | 2922 | |
a0b2f99b JM |
2923 | for (i = 0; i < 4; i++) { |
2924 | if (!params->wep_key[i]) | |
2925 | continue; | |
9ebce9c5 | 2926 | wpa_driver_nl80211_set_key(bss->ifname, bss, WPA_ALG_WEP, |
2ea2fcc7 | 2927 | NULL, i, |
a0b2f99b JM |
2928 | i == params->wep_tx_keyidx, NULL, 0, |
2929 | params->wep_key[i], | |
2930 | params->wep_key_len[i]); | |
0194fedb JB |
2931 | if (params->wep_tx_keyidx != i) |
2932 | continue; | |
2933 | if (nl_add_key(msg, WPA_ALG_WEP, i, 1, NULL, 0, | |
9725b784 JM |
2934 | params->wep_key[i], params->wep_key_len[i])) |
2935 | goto fail; | |
a0b2f99b JM |
2936 | } |
2937 | ||
c2a04078 JM |
2938 | if (params->bssid) { |
2939 | wpa_printf(MSG_DEBUG, " * bssid=" MACSTR, | |
2940 | MAC2STR(params->bssid)); | |
a862e4a3 JM |
2941 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid)) |
2942 | goto fail; | |
c2a04078 JM |
2943 | } |
2944 | if (params->freq) { | |
2945 | wpa_printf(MSG_DEBUG, " * freq=%d", params->freq); | |
a862e4a3 JM |
2946 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, params->freq)) |
2947 | goto fail; | |
c2a04078 JM |
2948 | } |
2949 | if (params->ssid) { | |
2950 | wpa_hexdump_ascii(MSG_DEBUG, " * SSID", | |
2951 | params->ssid, params->ssid_len); | |
a862e4a3 JM |
2952 | if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, |
2953 | params->ssid)) | |
2954 | goto fail; | |
c2a04078 JM |
2955 | } |
2956 | wpa_hexdump(MSG_DEBUG, " * IEs", params->ie, params->ie_len); | |
a862e4a3 JM |
2957 | if (params->ie && |
2958 | nla_put(msg, NL80211_ATTR_IE, params->ie_len, params->ie)) | |
2959 | goto fail; | |
569fed90 JM |
2960 | if (params->sae_data) { |
2961 | wpa_hexdump(MSG_DEBUG, " * SAE data", params->sae_data, | |
2962 | params->sae_data_len); | |
a862e4a3 JM |
2963 | if (nla_put(msg, NL80211_ATTR_SAE_DATA, params->sae_data_len, |
2964 | params->sae_data)) | |
2965 | goto fail; | |
569fed90 | 2966 | } |
abd9fafa | 2967 | if (params->auth_alg & WPA_AUTH_ALG_OPEN) |
c2a04078 | 2968 | type = NL80211_AUTHTYPE_OPEN_SYSTEM; |
abd9fafa | 2969 | else if (params->auth_alg & WPA_AUTH_ALG_SHARED) |
c2a04078 | 2970 | type = NL80211_AUTHTYPE_SHARED_KEY; |
abd9fafa | 2971 | else if (params->auth_alg & WPA_AUTH_ALG_LEAP) |
c2a04078 | 2972 | type = NL80211_AUTHTYPE_NETWORK_EAP; |
abd9fafa | 2973 | else if (params->auth_alg & WPA_AUTH_ALG_FT) |
c2a04078 | 2974 | type = NL80211_AUTHTYPE_FT; |
569fed90 JM |
2975 | else if (params->auth_alg & WPA_AUTH_ALG_SAE) |
2976 | type = NL80211_AUTHTYPE_SAE; | |
c2a04078 | 2977 | else |
a862e4a3 | 2978 | goto fail; |
c2a04078 | 2979 | wpa_printf(MSG_DEBUG, " * Auth Type %d", type); |
a862e4a3 JM |
2980 | if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, type)) |
2981 | goto fail; | |
77339912 JM |
2982 | if (params->local_state_change) { |
2983 | wpa_printf(MSG_DEBUG, " * Local state change only"); | |
a862e4a3 JM |
2984 | if (nla_put_flag(msg, NL80211_ATTR_LOCAL_STATE_CHANGE)) |
2985 | goto fail; | |
77339912 | 2986 | } |
c2a04078 JM |
2987 | |
2988 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
2989 | msg = NULL; | |
2990 | if (ret) { | |
3b7ea880 BG |
2991 | wpa_dbg(drv->ctx, MSG_DEBUG, |
2992 | "nl80211: MLME command failed (auth): ret=%d (%s)", | |
2993 | ret, strerror(-ret)); | |
6d6f4bb8 | 2994 | count++; |
77339912 JM |
2995 | if (ret == -EALREADY && count == 1 && params->bssid && |
2996 | !params->local_state_change) { | |
6d6f4bb8 JM |
2997 | /* |
2998 | * mac80211 does not currently accept new | |
2999 | * authentication if we are already authenticated. As a | |
3000 | * workaround, force deauthentication and try again. | |
3001 | */ | |
3002 | wpa_printf(MSG_DEBUG, "nl80211: Retry authentication " | |
3003 | "after forced deauthentication"); | |
e8d70a73 | 3004 | drv->ignore_deauth_event = 1; |
6d6f4bb8 | 3005 | wpa_driver_nl80211_deauthenticate( |
5205c4f9 | 3006 | bss, params->bssid, |
6d6f4bb8 JM |
3007 | WLAN_REASON_PREV_AUTH_NOT_VALID); |
3008 | nlmsg_free(msg); | |
3009 | goto retry; | |
3010 | } | |
536fd62d JM |
3011 | |
3012 | if (ret == -ENOENT && params->freq && !is_retry) { | |
3013 | /* | |
3014 | * cfg80211 has likely expired the BSS entry even | |
3015 | * though it was previously available in our internal | |
3016 | * BSS table. To recover quickly, start a single | |
3017 | * channel scan on the specified channel. | |
3018 | */ | |
3019 | struct wpa_driver_scan_params scan; | |
3020 | int freqs[2]; | |
3021 | ||
3022 | os_memset(&scan, 0, sizeof(scan)); | |
3023 | scan.num_ssids = 1; | |
3024 | if (params->ssid) { | |
3025 | scan.ssids[0].ssid = params->ssid; | |
3026 | scan.ssids[0].ssid_len = params->ssid_len; | |
3027 | } | |
3028 | freqs[0] = params->freq; | |
3029 | freqs[1] = 0; | |
3030 | scan.freqs = freqs; | |
3031 | wpa_printf(MSG_DEBUG, "nl80211: Trigger single " | |
3032 | "channel scan to refresh cfg80211 BSS " | |
3033 | "entry"); | |
3034 | ret = wpa_driver_nl80211_scan(bss, &scan); | |
3035 | if (ret == 0) { | |
3036 | nl80211_copy_auth_params(drv, params); | |
3037 | drv->scan_for_auth = 1; | |
3038 | } | |
8c3ba078 JM |
3039 | } else if (is_retry) { |
3040 | /* | |
3041 | * Need to indicate this with an event since the return | |
3042 | * value from the retry is not delivered to core code. | |
3043 | */ | |
3044 | union wpa_event_data event; | |
3045 | wpa_printf(MSG_DEBUG, "nl80211: Authentication retry " | |
3046 | "failed"); | |
3047 | os_memset(&event, 0, sizeof(event)); | |
3048 | os_memcpy(event.timeout_event.addr, drv->auth_bssid_, | |
3049 | ETH_ALEN); | |
3050 | wpa_supplicant_event(drv->ctx, EVENT_AUTH_TIMED_OUT, | |
3051 | &event); | |
536fd62d | 3052 | } |
a862e4a3 JM |
3053 | } else { |
3054 | wpa_printf(MSG_DEBUG, | |
3055 | "nl80211: Authentication request send successfully"); | |
c2a04078 | 3056 | } |
c2a04078 | 3057 | |
a862e4a3 | 3058 | fail: |
c2a04078 JM |
3059 | nlmsg_free(msg); |
3060 | return ret; | |
3061 | } | |
3062 | ||
3063 | ||
f3407c66 | 3064 | int wpa_driver_nl80211_authenticate_retry(struct wpa_driver_nl80211_data *drv) |
536fd62d JM |
3065 | { |
3066 | struct wpa_driver_auth_params params; | |
834ee56f | 3067 | struct i802_bss *bss = drv->first_bss; |
536fd62d JM |
3068 | int i; |
3069 | ||
3070 | wpa_printf(MSG_DEBUG, "nl80211: Try to authenticate again"); | |
3071 | ||
3072 | os_memset(¶ms, 0, sizeof(params)); | |
3073 | params.freq = drv->auth_freq; | |
3074 | params.auth_alg = drv->auth_alg; | |
3075 | params.wep_tx_keyidx = drv->auth_wep_tx_keyidx; | |
3076 | params.local_state_change = drv->auth_local_state_change; | |
3077 | params.p2p = drv->auth_p2p; | |
3078 | ||
3079 | if (!is_zero_ether_addr(drv->auth_bssid_)) | |
3080 | params.bssid = drv->auth_bssid_; | |
3081 | ||
3082 | if (drv->auth_ssid_len) { | |
3083 | params.ssid = drv->auth_ssid; | |
3084 | params.ssid_len = drv->auth_ssid_len; | |
3085 | } | |
3086 | ||
3087 | params.ie = drv->auth_ie; | |
3088 | params.ie_len = drv->auth_ie_len; | |
3089 | ||
3090 | for (i = 0; i < 4; i++) { | |
3091 | if (drv->auth_wep_key_len[i]) { | |
3092 | params.wep_key[i] = drv->auth_wep_key[i]; | |
3093 | params.wep_key_len[i] = drv->auth_wep_key_len[i]; | |
3094 | } | |
3095 | } | |
3096 | ||
3097 | drv->retry_auth = 1; | |
3098 | return wpa_driver_nl80211_authenticate(bss, ¶ms); | |
3099 | } | |
3100 | ||
3101 | ||
a11241fa JB |
3102 | static int wpa_driver_nl80211_send_frame(struct i802_bss *bss, |
3103 | const void *data, size_t len, | |
55231068 JM |
3104 | int encrypt, int noack, |
3105 | unsigned int freq, int no_cck, | |
2d3943ce AO |
3106 | int offchanok, unsigned int wait_time, |
3107 | const u16 *csa_offs, | |
3108 | size_t csa_offs_len) | |
a11241fa JB |
3109 | { |
3110 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
3111 | u64 cookie; | |
41cc50d1 | 3112 | int res; |
a11241fa | 3113 | |
c7caac56 JM |
3114 | if (freq == 0 && drv->nlmode == NL80211_IFTYPE_ADHOC) { |
3115 | freq = nl80211_get_assoc_freq(drv); | |
3116 | wpa_printf(MSG_DEBUG, | |
3117 | "nl80211: send_frame - Use assoc_freq=%u for IBSS", | |
3118 | freq); | |
3119 | } | |
af964484 JM |
3120 | if (freq == 0) { |
3121 | wpa_printf(MSG_DEBUG, "nl80211: send_frame - Use bss->freq=%u", | |
3122 | bss->freq); | |
55231068 | 3123 | freq = bss->freq; |
af964484 | 3124 | } |
55231068 | 3125 | |
739faee2 | 3126 | if (drv->use_monitor) { |
981cf85a | 3127 | wpa_printf(MSG_DEBUG, "nl80211: send_frame(freq=%u bss->freq=%u) -> send_monitor", |
739faee2 | 3128 | freq, bss->freq); |
981cf85a | 3129 | return nl80211_send_monitor(drv, data, len, encrypt, noack); |
739faee2 | 3130 | } |
a11241fa | 3131 | |
739faee2 | 3132 | wpa_printf(MSG_DEBUG, "nl80211: send_frame -> send_frame_cmd"); |
41cc50d1 | 3133 | res = nl80211_send_frame_cmd(bss, freq, wait_time, data, len, |
2d3943ce AO |
3134 | &cookie, no_cck, noack, offchanok, |
3135 | csa_offs, csa_offs_len); | |
41cc50d1 JM |
3136 | if (res == 0 && !noack) { |
3137 | const struct ieee80211_mgmt *mgmt; | |
3138 | u16 fc; | |
3139 | ||
3140 | mgmt = (const struct ieee80211_mgmt *) data; | |
3141 | fc = le_to_host16(mgmt->frame_control); | |
3142 | if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && | |
3143 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_ACTION) { | |
3144 | wpa_printf(MSG_MSGDUMP, | |
3145 | "nl80211: Update send_action_cookie from 0x%llx to 0x%llx", | |
3146 | (long long unsigned int) | |
3147 | drv->send_action_cookie, | |
3148 | (long long unsigned int) cookie); | |
3149 | drv->send_action_cookie = cookie; | |
3150 | } | |
3151 | } | |
3152 | ||
3153 | return res; | |
a11241fa JB |
3154 | } |
3155 | ||
3156 | ||
9ebce9c5 JM |
3157 | static int wpa_driver_nl80211_send_mlme(struct i802_bss *bss, const u8 *data, |
3158 | size_t data_len, int noack, | |
3159 | unsigned int freq, int no_cck, | |
3160 | int offchanok, | |
2d3943ce AO |
3161 | unsigned int wait_time, |
3162 | const u16 *csa_offs, | |
3163 | size_t csa_offs_len) | |
2c2010ac | 3164 | { |
a2e40bb6 | 3165 | struct wpa_driver_nl80211_data *drv = bss->drv; |
2c2010ac | 3166 | struct ieee80211_mgmt *mgmt; |
7a47d567 | 3167 | int encrypt = 1; |
2c2010ac JM |
3168 | u16 fc; |
3169 | ||
3170 | mgmt = (struct ieee80211_mgmt *) data; | |
3171 | fc = le_to_host16(mgmt->frame_control); | |
f95a4524 PF |
3172 | wpa_printf(MSG_DEBUG, "nl80211: send_mlme - da= " MACSTR |
3173 | " noack=%d freq=%u no_cck=%d offchanok=%d wait_time=%u fc=0x%x (%s) nlmode=%d", | |
3174 | MAC2STR(mgmt->da), noack, freq, no_cck, offchanok, wait_time, | |
3175 | fc, fc2str(fc), drv->nlmode); | |
2c2010ac | 3176 | |
8e12685c AS |
3177 | if ((is_sta_interface(drv->nlmode) || |
3178 | drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) && | |
5582a5d1 JB |
3179 | WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && |
3180 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_PROBE_RESP) { | |
3181 | /* | |
3182 | * The use of last_mgmt_freq is a bit of a hack, | |
3183 | * but it works due to the single-threaded nature | |
3184 | * of wpa_supplicant. | |
3185 | */ | |
af964484 JM |
3186 | if (freq == 0) { |
3187 | wpa_printf(MSG_DEBUG, "nl80211: Use last_mgmt_freq=%d", | |
3188 | drv->last_mgmt_freq); | |
55231068 | 3189 | freq = drv->last_mgmt_freq; |
af964484 | 3190 | } |
55231068 | 3191 | return nl80211_send_frame_cmd(bss, freq, 0, |
88df0ef7 | 3192 | data, data_len, NULL, 1, noack, |
2d3943ce | 3193 | 1, csa_offs, csa_offs_len); |
5582a5d1 JB |
3194 | } |
3195 | ||
61cbe2ff | 3196 | if (drv->device_ap_sme && is_ap_interface(drv->nlmode)) { |
af964484 JM |
3197 | if (freq == 0) { |
3198 | wpa_printf(MSG_DEBUG, "nl80211: Use bss->freq=%d", | |
3199 | bss->freq); | |
55231068 | 3200 | freq = bss->freq; |
af964484 | 3201 | } |
b5671498 JM |
3202 | return nl80211_send_frame_cmd(bss, freq, |
3203 | (int) freq == bss->freq ? 0 : | |
3204 | wait_time, | |
d8d6b32e DG |
3205 | data, data_len, |
3206 | &drv->send_action_cookie, | |
2d3943ce AO |
3207 | no_cck, noack, offchanok, |
3208 | csa_offs, csa_offs_len); | |
86957e62 JM |
3209 | } |
3210 | ||
2c2010ac JM |
3211 | if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && |
3212 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_AUTH) { | |
3213 | /* | |
3214 | * Only one of the authentication frame types is encrypted. | |
3215 | * In order for static WEP encryption to work properly (i.e., | |
3216 | * to not encrypt the frame), we need to tell mac80211 about | |
3217 | * the frames that must not be encrypted. | |
3218 | */ | |
3219 | u16 auth_alg = le_to_host16(mgmt->u.auth.auth_alg); | |
3220 | u16 auth_trans = le_to_host16(mgmt->u.auth.auth_transaction); | |
7a47d567 JB |
3221 | if (auth_alg != WLAN_AUTH_SHARED_KEY || auth_trans != 3) |
3222 | encrypt = 0; | |
2c2010ac JM |
3223 | } |
3224 | ||
739faee2 | 3225 | wpa_printf(MSG_DEBUG, "nl80211: send_mlme -> send_frame"); |
a11241fa | 3226 | return wpa_driver_nl80211_send_frame(bss, data, data_len, encrypt, |
55231068 | 3227 | noack, freq, no_cck, offchanok, |
2d3943ce AO |
3228 | wait_time, csa_offs, |
3229 | csa_offs_len); | |
55231068 JM |
3230 | } |
3231 | ||
3232 | ||
cae87abd JM |
3233 | static int nl80211_put_basic_rates(struct nl_msg *msg, const int *basic_rates) |
3234 | { | |
3235 | u8 rates[NL80211_MAX_SUPP_RATES]; | |
3236 | u8 rates_len = 0; | |
3237 | int i; | |
3238 | ||
3239 | if (!basic_rates) | |
3240 | return 0; | |
3241 | ||
3242 | for (i = 0; i < NL80211_MAX_SUPP_RATES && basic_rates[i] >= 0; i++) | |
3243 | rates[rates_len++] = basic_rates[i] / 5; | |
3244 | ||
3245 | return nla_put(msg, NL80211_ATTR_BSS_BASIC_RATES, rates_len, rates); | |
3246 | } | |
3247 | ||
3248 | ||
31357268 | 3249 | static int nl80211_set_bss(struct i802_bss *bss, int cts, int preamble, |
e5693c47 | 3250 | int slot, int ht_opmode, int ap_isolate, |
cae87abd | 3251 | const int *basic_rates) |
31357268 JM |
3252 | { |
3253 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
3254 | struct nl_msg *msg; | |
3255 | ||
13f83980 | 3256 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_BSS)) || |
a862e4a3 JM |
3257 | (cts >= 0 && |
3258 | nla_put_u8(msg, NL80211_ATTR_BSS_CTS_PROT, cts)) || | |
3259 | (preamble >= 0 && | |
3260 | nla_put_u8(msg, NL80211_ATTR_BSS_SHORT_PREAMBLE, preamble)) || | |
3261 | (slot >= 0 && | |
3262 | nla_put_u8(msg, NL80211_ATTR_BSS_SHORT_SLOT_TIME, slot)) || | |
3263 | (ht_opmode >= 0 && | |
3264 | nla_put_u16(msg, NL80211_ATTR_BSS_HT_OPMODE, ht_opmode)) || | |
3265 | (ap_isolate >= 0 && | |
cae87abd JM |
3266 | nla_put_u8(msg, NL80211_ATTR_AP_ISOLATE, ap_isolate)) || |
3267 | nl80211_put_basic_rates(msg, basic_rates)) { | |
3268 | nlmsg_free(msg); | |
3269 | return -ENOBUFS; | |
e5693c47 JM |
3270 | } |
3271 | ||
31357268 | 3272 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
31357268 JM |
3273 | } |
3274 | ||
3275 | ||
3c4ca363 VN |
3276 | static int wpa_driver_nl80211_set_acl(void *priv, |
3277 | struct hostapd_acl_params *params) | |
3278 | { | |
3279 | struct i802_bss *bss = priv; | |
3280 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
3281 | struct nl_msg *msg; | |
f429ec44 | 3282 | struct nl_msg *acl; |
3c4ca363 | 3283 | unsigned int i; |
a862e4a3 | 3284 | int ret; |
3c4ca363 VN |
3285 | |
3286 | if (!(drv->capa.max_acl_mac_addrs)) | |
3287 | return -ENOTSUP; | |
3288 | ||
3289 | if (params->num_mac_acl > drv->capa.max_acl_mac_addrs) | |
3290 | return -ENOTSUP; | |
3291 | ||
3c4ca363 VN |
3292 | wpa_printf(MSG_DEBUG, "nl80211: Set %s ACL (num_mac_acl=%u)", |
3293 | params->acl_policy ? "Accept" : "Deny", params->num_mac_acl); | |
3294 | ||
f429ec44 JM |
3295 | acl = nlmsg_alloc(); |
3296 | if (!acl) | |
3297 | return -ENOMEM; | |
3298 | for (i = 0; i < params->num_mac_acl; i++) { | |
3299 | if (nla_put(acl, i + 1, ETH_ALEN, params->mac_acl[i].addr)) { | |
3300 | nlmsg_free(acl); | |
3301 | return -ENOMEM; | |
3302 | } | |
3303 | } | |
3304 | ||
9725b784 | 3305 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_MAC_ACL)) || |
a862e4a3 JM |
3306 | nla_put_u32(msg, NL80211_ATTR_ACL_POLICY, params->acl_policy ? |
3307 | NL80211_ACL_POLICY_DENY_UNLESS_LISTED : | |
3308 | NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED) || | |
f429ec44 | 3309 | nla_put_nested(msg, NL80211_ATTR_MAC_ADDRS, acl)) { |
a862e4a3 | 3310 | nlmsg_free(msg); |
f429ec44 | 3311 | nlmsg_free(acl); |
a862e4a3 JM |
3312 | return -ENOMEM; |
3313 | } | |
f429ec44 | 3314 | nlmsg_free(acl); |
3c4ca363 VN |
3315 | |
3316 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
3c4ca363 VN |
3317 | if (ret) { |
3318 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set MAC ACL: %d (%s)", | |
3319 | ret, strerror(-ret)); | |
3320 | } | |
3321 | ||
3c4ca363 VN |
3322 | return ret; |
3323 | } | |
3324 | ||
3325 | ||
85e1fad8 JM |
3326 | static int nl80211_put_beacon_int(struct nl_msg *msg, int beacon_int) |
3327 | { | |
3328 | if (beacon_int > 0) { | |
3329 | wpa_printf(MSG_DEBUG, " * beacon_int=%d", beacon_int); | |
3330 | return nla_put_u32(msg, NL80211_ATTR_BEACON_INTERVAL, | |
3331 | beacon_int); | |
3332 | } | |
3333 | ||
3334 | return 0; | |
3335 | } | |
3336 | ||
3337 | ||
19c3b566 JM |
3338 | static int wpa_driver_nl80211_set_ap(void *priv, |
3339 | struct wpa_driver_ap_params *params) | |
d2440ba0 | 3340 | { |
a2e40bb6 FF |
3341 | struct i802_bss *bss = priv; |
3342 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
d2440ba0 JM |
3343 | struct nl_msg *msg; |
3344 | u8 cmd = NL80211_CMD_NEW_BEACON; | |
3345 | int ret; | |
b4fd6fab | 3346 | int beacon_set; |
b11d1d64 | 3347 | int num_suites; |
da1080d7 | 3348 | int smps_mode; |
de4ed4a8 | 3349 | u32 suites[10], suite; |
b11d1d64 | 3350 | u32 ver; |
b4fd6fab | 3351 | |
f33c8606 | 3352 | beacon_set = params->reenable ? 0 : bss->beacon_set; |
d2440ba0 | 3353 | |
d2440ba0 | 3354 | wpa_printf(MSG_DEBUG, "nl80211: Set beacon (beacon_set=%d)", |
b4fd6fab JM |
3355 | beacon_set); |
3356 | if (beacon_set) | |
d2440ba0 JM |
3357 | cmd = NL80211_CMD_SET_BEACON; |
3358 | ||
b92e08fc JM |
3359 | wpa_hexdump(MSG_DEBUG, "nl80211: Beacon head", |
3360 | params->head, params->head_len); | |
b92e08fc JM |
3361 | wpa_hexdump(MSG_DEBUG, "nl80211: Beacon tail", |
3362 | params->tail, params->tail_len); | |
13f83980 | 3363 | wpa_printf(MSG_DEBUG, "nl80211: ifindex=%d", bss->ifindex); |
b92e08fc | 3364 | wpa_printf(MSG_DEBUG, "nl80211: beacon_int=%d", params->beacon_int); |
b92e08fc | 3365 | wpa_printf(MSG_DEBUG, "nl80211: dtim_period=%d", params->dtim_period); |
b92e08fc JM |
3366 | wpa_hexdump_ascii(MSG_DEBUG, "nl80211: ssid", |
3367 | params->ssid, params->ssid_len); | |
13f83980 | 3368 | if (!(msg = nl80211_bss_msg(bss, 0, cmd)) || |
a862e4a3 JM |
3369 | nla_put(msg, NL80211_ATTR_BEACON_HEAD, params->head_len, |
3370 | params->head) || | |
3371 | nla_put(msg, NL80211_ATTR_BEACON_TAIL, params->tail_len, | |
3372 | params->tail) || | |
85e1fad8 | 3373 | nl80211_put_beacon_int(msg, params->beacon_int) || |
a862e4a3 JM |
3374 | nla_put_u32(msg, NL80211_ATTR_DTIM_PERIOD, params->dtim_period) || |
3375 | nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid)) | |
3376 | goto fail; | |
b92e08fc JM |
3377 | if (params->proberesp && params->proberesp_len) { |
3378 | wpa_hexdump(MSG_DEBUG, "nl80211: proberesp (offload)", | |
3379 | params->proberesp, params->proberesp_len); | |
a862e4a3 JM |
3380 | if (nla_put(msg, NL80211_ATTR_PROBE_RESP, params->proberesp_len, |
3381 | params->proberesp)) | |
3382 | goto fail; | |
b92e08fc | 3383 | } |
97a7a0b5 JM |
3384 | switch (params->hide_ssid) { |
3385 | case NO_SSID_HIDING: | |
b92e08fc | 3386 | wpa_printf(MSG_DEBUG, "nl80211: hidden SSID not in use"); |
a862e4a3 JM |
3387 | if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID, |
3388 | NL80211_HIDDEN_SSID_NOT_IN_USE)) | |
3389 | goto fail; | |
97a7a0b5 JM |
3390 | break; |
3391 | case HIDDEN_SSID_ZERO_LEN: | |
b92e08fc | 3392 | wpa_printf(MSG_DEBUG, "nl80211: hidden SSID zero len"); |
a862e4a3 JM |
3393 | if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID, |
3394 | NL80211_HIDDEN_SSID_ZERO_LEN)) | |
3395 | goto fail; | |
97a7a0b5 JM |
3396 | break; |
3397 | case HIDDEN_SSID_ZERO_CONTENTS: | |
b92e08fc | 3398 | wpa_printf(MSG_DEBUG, "nl80211: hidden SSID zero contents"); |
a862e4a3 JM |
3399 | if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID, |
3400 | NL80211_HIDDEN_SSID_ZERO_CONTENTS)) | |
3401 | goto fail; | |
97a7a0b5 JM |
3402 | break; |
3403 | } | |
b92e08fc | 3404 | wpa_printf(MSG_DEBUG, "nl80211: privacy=%d", params->privacy); |
a862e4a3 JM |
3405 | if (params->privacy && |
3406 | nla_put_flag(msg, NL80211_ATTR_PRIVACY)) | |
3407 | goto fail; | |
b92e08fc | 3408 | wpa_printf(MSG_DEBUG, "nl80211: auth_algs=0x%x", params->auth_algs); |
b11d1d64 JM |
3409 | if ((params->auth_algs & (WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED)) == |
3410 | (WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED)) { | |
3411 | /* Leave out the attribute */ | |
a862e4a3 JM |
3412 | } else if (params->auth_algs & WPA_AUTH_ALG_SHARED) { |
3413 | if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, | |
3414 | NL80211_AUTHTYPE_SHARED_KEY)) | |
3415 | goto fail; | |
3416 | } else { | |
3417 | if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, | |
3418 | NL80211_AUTHTYPE_OPEN_SYSTEM)) | |
3419 | goto fail; | |
3420 | } | |
b11d1d64 | 3421 | |
b92e08fc | 3422 | wpa_printf(MSG_DEBUG, "nl80211: wpa_version=0x%x", params->wpa_version); |
b11d1d64 JM |
3423 | ver = 0; |
3424 | if (params->wpa_version & WPA_PROTO_WPA) | |
3425 | ver |= NL80211_WPA_VERSION_1; | |
3426 | if (params->wpa_version & WPA_PROTO_RSN) | |
3427 | ver |= NL80211_WPA_VERSION_2; | |
a862e4a3 JM |
3428 | if (ver && |
3429 | nla_put_u32(msg, NL80211_ATTR_WPA_VERSIONS, ver)) | |
3430 | goto fail; | |
b11d1d64 | 3431 | |
b92e08fc JM |
3432 | wpa_printf(MSG_DEBUG, "nl80211: key_mgmt_suites=0x%x", |
3433 | params->key_mgmt_suites); | |
b11d1d64 JM |
3434 | num_suites = 0; |
3435 | if (params->key_mgmt_suites & WPA_KEY_MGMT_IEEE8021X) | |
3436 | suites[num_suites++] = WLAN_AKM_SUITE_8021X; | |
3437 | if (params->key_mgmt_suites & WPA_KEY_MGMT_PSK) | |
3438 | suites[num_suites++] = WLAN_AKM_SUITE_PSK; | |
a862e4a3 JM |
3439 | if (num_suites && |
3440 | nla_put(msg, NL80211_ATTR_AKM_SUITES, num_suites * sizeof(u32), | |
3441 | suites)) | |
3442 | goto fail; | |
b11d1d64 | 3443 | |
533fe09b | 3444 | if (params->key_mgmt_suites & WPA_KEY_MGMT_IEEE8021X_NO_WPA && |
a862e4a3 JM |
3445 | params->pairwise_ciphers & (WPA_CIPHER_WEP104 | WPA_CIPHER_WEP40) && |
3446 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT)) | |
3447 | goto fail; | |
9f12614b | 3448 | |
b92e08fc JM |
3449 | wpa_printf(MSG_DEBUG, "nl80211: pairwise_ciphers=0x%x", |
3450 | params->pairwise_ciphers); | |
de4ed4a8 JM |
3451 | num_suites = wpa_cipher_to_cipher_suites(params->pairwise_ciphers, |
3452 | suites, ARRAY_SIZE(suites)); | |
a862e4a3 JM |
3453 | if (num_suites && |
3454 | nla_put(msg, NL80211_ATTR_CIPHER_SUITES_PAIRWISE, | |
3455 | num_suites * sizeof(u32), suites)) | |
3456 | goto fail; | |
b11d1d64 | 3457 | |
b92e08fc JM |
3458 | wpa_printf(MSG_DEBUG, "nl80211: group_cipher=0x%x", |
3459 | params->group_cipher); | |
de4ed4a8 | 3460 | suite = wpa_cipher_to_cipher_suite(params->group_cipher); |
a862e4a3 JM |
3461 | if (suite && |
3462 | nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, suite)) | |
3463 | goto fail; | |
d2440ba0 | 3464 | |
da1080d7 EP |
3465 | switch (params->smps_mode) { |
3466 | case HT_CAP_INFO_SMPS_DYNAMIC: | |
3467 | wpa_printf(MSG_DEBUG, "nl80211: SMPS mode - dynamic"); | |
3468 | smps_mode = NL80211_SMPS_DYNAMIC; | |
3469 | break; | |
3470 | case HT_CAP_INFO_SMPS_STATIC: | |
3471 | wpa_printf(MSG_DEBUG, "nl80211: SMPS mode - static"); | |
3472 | smps_mode = NL80211_SMPS_STATIC; | |
3473 | break; | |
3474 | default: | |
3475 | /* invalid - fallback to smps off */ | |
3476 | case HT_CAP_INFO_SMPS_DISABLED: | |
3477 | wpa_printf(MSG_DEBUG, "nl80211: SMPS mode - off"); | |
3478 | smps_mode = NL80211_SMPS_OFF; | |
3479 | break; | |
3480 | } | |
a862e4a3 JM |
3481 | if (nla_put_u32(msg, NL80211_ATTR_SMPS_MODE, smps_mode)) |
3482 | goto fail; | |
da1080d7 | 3483 | |
fb91db56 | 3484 | if (params->beacon_ies) { |
b92e08fc JM |
3485 | wpa_hexdump_buf(MSG_DEBUG, "nl80211: beacon_ies", |
3486 | params->beacon_ies); | |
a862e4a3 JM |
3487 | if (nla_put(msg, NL80211_ATTR_IE, |
3488 | wpabuf_len(params->beacon_ies), | |
3489 | wpabuf_head(params->beacon_ies))) | |
3490 | goto fail; | |
fb91db56 JM |
3491 | } |
3492 | if (params->proberesp_ies) { | |
b92e08fc JM |
3493 | wpa_hexdump_buf(MSG_DEBUG, "nl80211: proberesp_ies", |
3494 | params->proberesp_ies); | |
a862e4a3 JM |
3495 | if (nla_put(msg, NL80211_ATTR_IE_PROBE_RESP, |
3496 | wpabuf_len(params->proberesp_ies), | |
3497 | wpabuf_head(params->proberesp_ies))) | |
3498 | goto fail; | |
fb91db56 JM |
3499 | } |
3500 | if (params->assocresp_ies) { | |
b92e08fc JM |
3501 | wpa_hexdump_buf(MSG_DEBUG, "nl80211: assocresp_ies", |
3502 | params->assocresp_ies); | |
a862e4a3 JM |
3503 | if (nla_put(msg, NL80211_ATTR_IE_ASSOC_RESP, |
3504 | wpabuf_len(params->assocresp_ies), | |
3505 | wpabuf_head(params->assocresp_ies))) | |
3506 | goto fail; | |
fb91db56 JM |
3507 | } |
3508 | ||
a0133ee1 | 3509 | if (drv->capa.flags & WPA_DRIVER_FLAGS_INACTIVITY_TIMER) { |
b92e08fc JM |
3510 | wpa_printf(MSG_DEBUG, "nl80211: ap_max_inactivity=%d", |
3511 | params->ap_max_inactivity); | |
a862e4a3 JM |
3512 | if (nla_put_u16(msg, NL80211_ATTR_INACTIVITY_TIMEOUT, |
3513 | params->ap_max_inactivity)) | |
3514 | goto fail; | |
a0133ee1 VT |
3515 | } |
3516 | ||
abb8d08b EP |
3517 | #ifdef CONFIG_P2P |
3518 | if (params->p2p_go_ctwindow > 0) { | |
3519 | if (drv->p2p_go_ctwindow_supported) { | |
3520 | wpa_printf(MSG_DEBUG, "nl80211: P2P GO ctwindow=%d", | |
3521 | params->p2p_go_ctwindow); | |
3522 | if (nla_put_u8(msg, NL80211_ATTR_P2P_CTWINDOW, | |
3523 | params->p2p_go_ctwindow)) | |
3524 | goto fail; | |
3525 | } else { | |
3526 | wpa_printf(MSG_INFO, | |
3527 | "nl80211: Driver does not support CTWindow configuration - ignore this parameter"); | |
3528 | } | |
3529 | } | |
3530 | #endif /* CONFIG_P2P */ | |
3531 | ||
d2440ba0 JM |
3532 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
3533 | if (ret) { | |
3534 | wpa_printf(MSG_DEBUG, "nl80211: Beacon set failed: %d (%s)", | |
3535 | ret, strerror(-ret)); | |
b4fd6fab | 3536 | } else { |
b4fd6fab | 3537 | bss->beacon_set = 1; |
31357268 | 3538 | nl80211_set_bss(bss, params->cts_protect, params->preamble, |
d03e8d11 | 3539 | params->short_slot_time, params->ht_opmode, |
e5693c47 | 3540 | params->isolate, params->basic_rates); |
e87ef751 PX |
3541 | if (beacon_set && params->freq && |
3542 | params->freq->bandwidth != bss->bandwidth) { | |
3543 | wpa_printf(MSG_DEBUG, | |
3544 | "nl80211: Update BSS %s bandwidth: %d -> %d", | |
3545 | bss->ifname, bss->bandwidth, | |
3546 | params->freq->bandwidth); | |
3547 | ret = nl80211_set_channel(bss, params->freq, 1); | |
3548 | if (ret) { | |
3549 | wpa_printf(MSG_DEBUG, | |
3550 | "nl80211: Frequency set failed: %d (%s)", | |
3551 | ret, strerror(-ret)); | |
3552 | } else { | |
3553 | wpa_printf(MSG_DEBUG, | |
3554 | "nl80211: Frequency set succeeded for ht2040 coex"); | |
3555 | bss->bandwidth = params->freq->bandwidth; | |
3556 | } | |
3557 | } else if (!beacon_set) { | |
3558 | /* | |
3559 | * cfg80211 updates the driver on frequence change in AP | |
3560 | * mode only at the point when beaconing is started, so | |
3561 | * set the initial value here. | |
3562 | */ | |
3563 | bss->bandwidth = params->freq->bandwidth; | |
3564 | } | |
b4fd6fab | 3565 | } |
d2440ba0 | 3566 | return ret; |
a862e4a3 | 3567 | fail: |
5883168a | 3568 | nlmsg_free(msg); |
d2440ba0 JM |
3569 | return -ENOBUFS; |
3570 | } | |
3571 | ||
3572 | ||
1c4ffa87 | 3573 | static int nl80211_put_freq_params(struct nl_msg *msg, |
72b2605f | 3574 | const struct hostapd_freq_params *freq) |
1581b38b | 3575 | { |
1fc4ab23 | 3576 | wpa_printf(MSG_DEBUG, " * freq=%d", freq->freq); |
a862e4a3 JM |
3577 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq->freq)) |
3578 | return -ENOBUFS; | |
3579 | ||
1fc4ab23 JM |
3580 | wpa_printf(MSG_DEBUG, " * vht_enabled=%d", freq->vht_enabled); |
3581 | wpa_printf(MSG_DEBUG, " * ht_enabled=%d", freq->ht_enabled); | |
3582 | ||
89b800d7 | 3583 | if (freq->vht_enabled) { |
a862e4a3 JM |
3584 | enum nl80211_chan_width cw; |
3585 | ||
1fc4ab23 | 3586 | wpa_printf(MSG_DEBUG, " * bandwidth=%d", freq->bandwidth); |
89b800d7 JB |
3587 | switch (freq->bandwidth) { |
3588 | case 20: | |
a862e4a3 | 3589 | cw = NL80211_CHAN_WIDTH_20; |
89b800d7 JB |
3590 | break; |
3591 | case 40: | |
a862e4a3 | 3592 | cw = NL80211_CHAN_WIDTH_40; |
89b800d7 JB |
3593 | break; |
3594 | case 80: | |
3595 | if (freq->center_freq2) | |
a862e4a3 | 3596 | cw = NL80211_CHAN_WIDTH_80P80; |
89b800d7 | 3597 | else |
a862e4a3 | 3598 | cw = NL80211_CHAN_WIDTH_80; |
89b800d7 JB |
3599 | break; |
3600 | case 160: | |
a862e4a3 | 3601 | cw = NL80211_CHAN_WIDTH_160; |
89b800d7 JB |
3602 | break; |
3603 | default: | |
1c4ffa87 | 3604 | return -EINVAL; |
89b800d7 | 3605 | } |
a862e4a3 | 3606 | |
1fc4ab23 JM |
3607 | wpa_printf(MSG_DEBUG, " * channel_width=%d", cw); |
3608 | wpa_printf(MSG_DEBUG, " * center_freq1=%d", | |
3609 | freq->center_freq1); | |
3610 | wpa_printf(MSG_DEBUG, " * center_freq2=%d", | |
3611 | freq->center_freq2); | |
a862e4a3 JM |
3612 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, cw) || |
3613 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, | |
3614 | freq->center_freq1) || | |
3615 | (freq->center_freq2 && | |
3616 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, | |
3617 | freq->center_freq2))) | |
3618 | return -ENOBUFS; | |
89b800d7 | 3619 | } else if (freq->ht_enabled) { |
a862e4a3 JM |
3620 | enum nl80211_channel_type ct; |
3621 | ||
1fc4ab23 JM |
3622 | wpa_printf(MSG_DEBUG, " * sec_channel_offset=%d", |
3623 | freq->sec_channel_offset); | |
89b800d7 | 3624 | switch (freq->sec_channel_offset) { |
f019981a | 3625 | case -1: |
a862e4a3 | 3626 | ct = NL80211_CHAN_HT40MINUS; |
f019981a JM |
3627 | break; |
3628 | case 1: | |
a862e4a3 | 3629 | ct = NL80211_CHAN_HT40PLUS; |
f019981a JM |
3630 | break; |
3631 | default: | |
a862e4a3 | 3632 | ct = NL80211_CHAN_HT20; |
f019981a JM |
3633 | break; |
3634 | } | |
a862e4a3 | 3635 | |
1fc4ab23 | 3636 | wpa_printf(MSG_DEBUG, " * channel_type=%d", ct); |
a862e4a3 JM |
3637 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, ct)) |
3638 | return -ENOBUFS; | |
f019981a | 3639 | } |
1c4ffa87 | 3640 | return 0; |
1c4ffa87 AO |
3641 | } |
3642 | ||
3643 | ||
e87ef751 PX |
3644 | static int nl80211_set_channel(struct i802_bss *bss, |
3645 | struct hostapd_freq_params *freq, int set_chan) | |
1c4ffa87 AO |
3646 | { |
3647 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
3648 | struct nl_msg *msg; | |
3649 | int ret; | |
3650 | ||
3651 | wpa_printf(MSG_DEBUG, | |
3652 | "nl80211: Set freq %d (ht_enabled=%d, vht_enabled=%d, bandwidth=%d MHz, cf1=%d MHz, cf2=%d MHz)", | |
3653 | freq->freq, freq->ht_enabled, freq->vht_enabled, | |
3654 | freq->bandwidth, freq->center_freq1, freq->center_freq2); | |
1c4ffa87 | 3655 | |
9725b784 JM |
3656 | msg = nl80211_drv_msg(drv, 0, set_chan ? NL80211_CMD_SET_CHANNEL : |
3657 | NL80211_CMD_SET_WIPHY); | |
3658 | if (!msg || nl80211_put_freq_params(msg, freq) < 0) { | |
a862e4a3 JM |
3659 | nlmsg_free(msg); |
3660 | return -1; | |
3661 | } | |
1581b38b | 3662 | |
d2440ba0 | 3663 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
e4fb2167 | 3664 | if (ret == 0) { |
89b800d7 | 3665 | bss->freq = freq->freq; |
1581b38b | 3666 | return 0; |
e4fb2167 | 3667 | } |
f019981a | 3668 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set channel (freq=%d): " |
89b800d7 | 3669 | "%d (%s)", freq->freq, ret, strerror(-ret)); |
1581b38b JM |
3670 | return -1; |
3671 | } | |
3672 | ||
0f4e8b4f | 3673 | |
95ab6063 AN |
3674 | static u32 sta_flags_nl80211(int flags) |
3675 | { | |
3676 | u32 f = 0; | |
3677 | ||
3678 | if (flags & WPA_STA_AUTHORIZED) | |
3679 | f |= BIT(NL80211_STA_FLAG_AUTHORIZED); | |
3680 | if (flags & WPA_STA_WMM) | |
3681 | f |= BIT(NL80211_STA_FLAG_WME); | |
3682 | if (flags & WPA_STA_SHORT_PREAMBLE) | |
3683 | f |= BIT(NL80211_STA_FLAG_SHORT_PREAMBLE); | |
3684 | if (flags & WPA_STA_MFP) | |
3685 | f |= BIT(NL80211_STA_FLAG_MFP); | |
45b722f1 AN |
3686 | if (flags & WPA_STA_TDLS_PEER) |
3687 | f |= BIT(NL80211_STA_FLAG_TDLS_PEER); | |
7a228b5c BC |
3688 | if (flags & WPA_STA_AUTHENTICATED) |
3689 | f |= BIT(NL80211_STA_FLAG_AUTHENTICATED); | |
95ab6063 AN |
3690 | |
3691 | return f; | |
3692 | } | |
3693 | ||
3694 | ||
7c7e7877 BC |
3695 | #ifdef CONFIG_MESH |
3696 | static u32 sta_plink_state_nl80211(enum mesh_plink_state state) | |
3697 | { | |
3698 | switch (state) { | |
3699 | case PLINK_LISTEN: | |
3700 | return NL80211_PLINK_LISTEN; | |
3701 | case PLINK_OPEN_SENT: | |
3702 | return NL80211_PLINK_OPN_SNT; | |
3703 | case PLINK_OPEN_RCVD: | |
3704 | return NL80211_PLINK_OPN_RCVD; | |
3705 | case PLINK_CNF_RCVD: | |
3706 | return NL80211_PLINK_CNF_RCVD; | |
3707 | case PLINK_ESTAB: | |
3708 | return NL80211_PLINK_ESTAB; | |
3709 | case PLINK_HOLDING: | |
3710 | return NL80211_PLINK_HOLDING; | |
3711 | case PLINK_BLOCKED: | |
3712 | return NL80211_PLINK_BLOCKED; | |
3713 | default: | |
3714 | wpa_printf(MSG_ERROR, "nl80211: Invalid mesh plink state %d", | |
3715 | state); | |
3716 | } | |
3717 | return -1; | |
3718 | } | |
3719 | #endif /* CONFIG_MESH */ | |
3720 | ||
3721 | ||
62847751 | 3722 | static int wpa_driver_nl80211_sta_add(void *priv, |
0f4e8b4f JM |
3723 | struct hostapd_sta_add_params *params) |
3724 | { | |
a2e40bb6 FF |
3725 | struct i802_bss *bss = priv; |
3726 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8970bae8 | 3727 | struct nl_msg *msg; |
95ab6063 | 3728 | struct nl80211_sta_flag_update upd; |
0f4e8b4f JM |
3729 | int ret = -ENOBUFS; |
3730 | ||
45b722f1 AN |
3731 | if ((params->flags & WPA_STA_TDLS_PEER) && |
3732 | !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) | |
3733 | return -EOPNOTSUPP; | |
3734 | ||
e4dea253 JM |
3735 | wpa_printf(MSG_DEBUG, "nl80211: %s STA " MACSTR, |
3736 | params->set ? "Set" : "Add", MAC2STR(params->addr)); | |
13f83980 JM |
3737 | msg = nl80211_bss_msg(bss, 0, params->set ? NL80211_CMD_SET_STATION : |
3738 | NL80211_CMD_NEW_STATION); | |
3739 | if (!msg || nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->addr)) | |
a862e4a3 | 3740 | goto fail; |
5551bc9c BC |
3741 | |
3742 | if (!params->set || (params->flags & WPA_STA_TDLS_PEER)) { | |
5551bc9c BC |
3743 | wpa_hexdump(MSG_DEBUG, " * supported rates", |
3744 | params->supp_rates, params->supp_rates_len); | |
a862e4a3 JM |
3745 | wpa_printf(MSG_DEBUG, " * capability=0x%x", |
3746 | params->capability); | |
3747 | if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_RATES, | |
3748 | params->supp_rates_len, params->supp_rates) || | |
3749 | nla_put_u16(msg, NL80211_ATTR_STA_CAPABILITY, | |
3750 | params->capability)) | |
3751 | goto fail; | |
e503861f JM |
3752 | |
3753 | if (params->ht_capabilities) { | |
3754 | wpa_hexdump(MSG_DEBUG, " * ht_capabilities", | |
3755 | (u8 *) params->ht_capabilities, | |
3756 | sizeof(*params->ht_capabilities)); | |
a862e4a3 JM |
3757 | if (nla_put(msg, NL80211_ATTR_HT_CAPABILITY, |
3758 | sizeof(*params->ht_capabilities), | |
3759 | params->ht_capabilities)) | |
3760 | goto fail; | |
e503861f JM |
3761 | } |
3762 | ||
3763 | if (params->vht_capabilities) { | |
3764 | wpa_hexdump(MSG_DEBUG, " * vht_capabilities", | |
3765 | (u8 *) params->vht_capabilities, | |
3766 | sizeof(*params->vht_capabilities)); | |
a862e4a3 JM |
3767 | if (nla_put(msg, NL80211_ATTR_VHT_CAPABILITY, |
3768 | sizeof(*params->vht_capabilities), | |
3769 | params->vht_capabilities)) | |
3770 | goto fail; | |
e503861f JM |
3771 | } |
3772 | ||
e503861f JM |
3773 | if (params->ext_capab) { |
3774 | wpa_hexdump(MSG_DEBUG, " * ext_capab", | |
3775 | params->ext_capab, params->ext_capab_len); | |
a862e4a3 JM |
3776 | if (nla_put(msg, NL80211_ATTR_STA_EXT_CAPABILITY, |
3777 | params->ext_capab_len, params->ext_capab)) | |
3778 | goto fail; | |
e503861f | 3779 | } |
5551bc9c | 3780 | } |
45b722f1 | 3781 | if (!params->set) { |
f11b72c3 JM |
3782 | if (params->aid) { |
3783 | wpa_printf(MSG_DEBUG, " * aid=%u", params->aid); | |
a862e4a3 JM |
3784 | if (nla_put_u16(msg, NL80211_ATTR_STA_AID, params->aid)) |
3785 | goto fail; | |
f11b72c3 JM |
3786 | } else { |
3787 | /* | |
3788 | * cfg80211 validates that AID is non-zero, so we have | |
3789 | * to make this a non-zero value for the TDLS case where | |
3790 | * a dummy STA entry is used for now. | |
3791 | */ | |
3792 | wpa_printf(MSG_DEBUG, " * aid=1 (TDLS workaround)"); | |
a862e4a3 JM |
3793 | if (nla_put_u16(msg, NL80211_ATTR_STA_AID, 1)) |
3794 | goto fail; | |
f11b72c3 | 3795 | } |
e4dea253 JM |
3796 | wpa_printf(MSG_DEBUG, " * listen_interval=%u", |
3797 | params->listen_interval); | |
a862e4a3 JM |
3798 | if (nla_put_u16(msg, NL80211_ATTR_STA_LISTEN_INTERVAL, |
3799 | params->listen_interval)) | |
3800 | goto fail; | |
e112764e JM |
3801 | } else if (params->aid && (params->flags & WPA_STA_TDLS_PEER)) { |
3802 | wpa_printf(MSG_DEBUG, " * peer_aid=%u", params->aid); | |
a862e4a3 JM |
3803 | if (nla_put_u16(msg, NL80211_ATTR_PEER_AID, params->aid)) |
3804 | goto fail; | |
45b722f1 | 3805 | } |
05a8d422 | 3806 | |
8a458116 MK |
3807 | if (params->vht_opmode_enabled) { |
3808 | wpa_printf(MSG_DEBUG, " * opmode=%u", params->vht_opmode); | |
a862e4a3 JM |
3809 | if (nla_put_u8(msg, NL80211_ATTR_OPMODE_NOTIF, |
3810 | params->vht_opmode)) | |
3811 | goto fail; | |
8a458116 MK |
3812 | } |
3813 | ||
efc64886 SD |
3814 | if (params->supp_channels) { |
3815 | wpa_hexdump(MSG_DEBUG, " * supported channels", | |
3816 | params->supp_channels, params->supp_channels_len); | |
a862e4a3 JM |
3817 | if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_CHANNELS, |
3818 | params->supp_channels_len, params->supp_channels)) | |
3819 | goto fail; | |
efc64886 SD |
3820 | } |
3821 | ||
3822 | if (params->supp_oper_classes) { | |
3823 | wpa_hexdump(MSG_DEBUG, " * supported operating classes", | |
3824 | params->supp_oper_classes, | |
3825 | params->supp_oper_classes_len); | |
a862e4a3 JM |
3826 | if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES, |
3827 | params->supp_oper_classes_len, | |
3828 | params->supp_oper_classes)) | |
3829 | goto fail; | |
efc64886 SD |
3830 | } |
3831 | ||
95ab6063 | 3832 | os_memset(&upd, 0, sizeof(upd)); |
7e31703e BC |
3833 | upd.set = sta_flags_nl80211(params->flags); |
3834 | upd.mask = upd.set | sta_flags_nl80211(params->flags_mask); | |
e4dea253 JM |
3835 | wpa_printf(MSG_DEBUG, " * flags set=0x%x mask=0x%x", |
3836 | upd.set, upd.mask); | |
a862e4a3 JM |
3837 | if (nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd)) |
3838 | goto fail; | |
95ab6063 | 3839 | |
7c7e7877 | 3840 | #ifdef CONFIG_MESH |
a862e4a3 JM |
3841 | if (params->plink_state && |
3842 | nla_put_u8(msg, NL80211_ATTR_STA_PLINK_STATE, | |
3843 | sta_plink_state_nl80211(params->plink_state))) | |
3844 | goto fail; | |
7c7e7877 BC |
3845 | #endif /* CONFIG_MESH */ |
3846 | ||
774bfa62 | 3847 | if (params->flags & WPA_STA_WMM) { |
8970bae8 JB |
3848 | struct nlattr *wme = nla_nest_start(msg, NL80211_ATTR_STA_WME); |
3849 | ||
e4dea253 | 3850 | wpa_printf(MSG_DEBUG, " * qosinfo=0x%x", params->qosinfo); |
a862e4a3 JM |
3851 | if (!wme || |
3852 | nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES, | |
3853 | params->qosinfo & WMM_QOSINFO_STA_AC_MASK) || | |
3854 | nla_put_u8(msg, NL80211_STA_WME_MAX_SP, | |
3855 | (params->qosinfo >> WMM_QOSINFO_STA_SP_SHIFT) & | |
3856 | WMM_QOSINFO_STA_SP_MASK)) | |
3857 | goto fail; | |
8970bae8 | 3858 | nla_nest_end(msg, wme); |
774bfa62 EP |
3859 | } |
3860 | ||
0f4e8b4f | 3861 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
5883168a | 3862 | msg = NULL; |
0f4e8b4f | 3863 | if (ret) |
45b722f1 AN |
3864 | wpa_printf(MSG_DEBUG, "nl80211: NL80211_CMD_%s_STATION " |
3865 | "result: %d (%s)", params->set ? "SET" : "NEW", ret, | |
3866 | strerror(-ret)); | |
0f4e8b4f JM |
3867 | if (ret == -EEXIST) |
3868 | ret = 0; | |
a862e4a3 | 3869 | fail: |
5883168a | 3870 | nlmsg_free(msg); |
0f4e8b4f JM |
3871 | return ret; |
3872 | } | |
3873 | ||
3874 | ||
97ed9a06 KP |
3875 | static void rtnl_neigh_delete_fdb_entry(struct i802_bss *bss, const u8 *addr) |
3876 | { | |
3877 | #ifdef CONFIG_LIBNL3_ROUTE | |
3878 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
3879 | struct rtnl_neigh *rn; | |
3880 | struct nl_addr *nl_addr; | |
3881 | int err; | |
3882 | ||
3883 | rn = rtnl_neigh_alloc(); | |
3884 | if (!rn) | |
3885 | return; | |
3886 | ||
3887 | rtnl_neigh_set_family(rn, AF_BRIDGE); | |
3888 | rtnl_neigh_set_ifindex(rn, bss->ifindex); | |
3889 | nl_addr = nl_addr_build(AF_BRIDGE, (void *) addr, ETH_ALEN); | |
3890 | if (!nl_addr) { | |
3891 | rtnl_neigh_put(rn); | |
3892 | return; | |
3893 | } | |
3894 | rtnl_neigh_set_lladdr(rn, nl_addr); | |
3895 | ||
3896 | err = rtnl_neigh_delete(drv->rtnl_sk, rn, 0); | |
3897 | if (err < 0) { | |
3898 | wpa_printf(MSG_DEBUG, "nl80211: bridge FDB entry delete for " | |
3899 | MACSTR " ifindex=%d failed: %s", MAC2STR(addr), | |
3900 | bss->ifindex, nl_geterror(err)); | |
3901 | } else { | |
3902 | wpa_printf(MSG_DEBUG, "nl80211: deleted bridge FDB entry for " | |
3903 | MACSTR, MAC2STR(addr)); | |
3904 | } | |
3905 | ||
3906 | nl_addr_put(nl_addr); | |
3907 | rtnl_neigh_put(rn); | |
3908 | #endif /* CONFIG_LIBNL3_ROUTE */ | |
3909 | } | |
3910 | ||
3911 | ||
59d7148a JM |
3912 | static int wpa_driver_nl80211_sta_remove(struct i802_bss *bss, const u8 *addr, |
3913 | int deauth, u16 reason_code) | |
0f4e8b4f | 3914 | { |
a2e40bb6 | 3915 | struct wpa_driver_nl80211_data *drv = bss->drv; |
0f4e8b4f JM |
3916 | struct nl_msg *msg; |
3917 | int ret; | |
3918 | ||
13f83980 | 3919 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_DEL_STATION)) || |
a862e4a3 JM |
3920 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
3921 | (deauth == 0 && | |
3922 | nla_put_u8(msg, NL80211_ATTR_MGMT_SUBTYPE, | |
3923 | WLAN_FC_STYPE_DISASSOC)) || | |
3924 | (deauth == 1 && | |
3925 | nla_put_u8(msg, NL80211_ATTR_MGMT_SUBTYPE, | |
3926 | WLAN_FC_STYPE_DEAUTH)) || | |
3927 | (reason_code && | |
3928 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) { | |
3929 | nlmsg_free(msg); | |
3930 | return -ENOBUFS; | |
3931 | } | |
0f4e8b4f JM |
3932 | |
3933 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
83e7bb0e JM |
3934 | wpa_printf(MSG_DEBUG, "nl80211: sta_remove -> DEL_STATION %s " MACSTR |
3935 | " --> %d (%s)", | |
3936 | bss->ifname, MAC2STR(addr), ret, strerror(-ret)); | |
97ed9a06 KP |
3937 | |
3938 | if (drv->rtnl_sk) | |
3939 | rtnl_neigh_delete_fdb_entry(bss, addr); | |
3940 | ||
0f4e8b4f JM |
3941 | if (ret == -ENOENT) |
3942 | return 0; | |
3943 | return ret; | |
0f4e8b4f JM |
3944 | } |
3945 | ||
1581b38b | 3946 | |
f3407c66 | 3947 | void nl80211_remove_iface(struct wpa_driver_nl80211_data *drv, int ifidx) |
0915d02c JM |
3948 | { |
3949 | struct nl_msg *msg; | |
de884303 | 3950 | struct wpa_driver_nl80211_data *drv2; |
0915d02c | 3951 | |
c6e8e8e4 JM |
3952 | wpa_printf(MSG_DEBUG, "nl80211: Remove interface ifindex=%d", ifidx); |
3953 | ||
2135f224 | 3954 | /* stop listening for EAPOL on this interface */ |
de884303 JM |
3955 | dl_list_for_each(drv2, &drv->global->interfaces, |
3956 | struct wpa_driver_nl80211_data, list) | |
3957 | del_ifidx(drv2, ifidx); | |
2135f224 | 3958 | |
95376e1a | 3959 | msg = nl80211_ifindex_msg(drv, ifidx, 0, NL80211_CMD_DEL_INTERFACE); |
0915d02c JM |
3960 | if (send_and_recv_msgs(drv, msg, NULL, NULL) == 0) |
3961 | return; | |
e748062b | 3962 | wpa_printf(MSG_ERROR, "Failed to remove interface (ifidx=%d)", ifidx); |
0915d02c JM |
3963 | } |
3964 | ||
3965 | ||
a1922f93 JM |
3966 | static const char * nl80211_iftype_str(enum nl80211_iftype mode) |
3967 | { | |
3968 | switch (mode) { | |
3969 | case NL80211_IFTYPE_ADHOC: | |
3970 | return "ADHOC"; | |
3971 | case NL80211_IFTYPE_STATION: | |
3972 | return "STATION"; | |
3973 | case NL80211_IFTYPE_AP: | |
3974 | return "AP"; | |
1045ec36 JM |
3975 | case NL80211_IFTYPE_AP_VLAN: |
3976 | return "AP_VLAN"; | |
3977 | case NL80211_IFTYPE_WDS: | |
3978 | return "WDS"; | |
a1922f93 JM |
3979 | case NL80211_IFTYPE_MONITOR: |
3980 | return "MONITOR"; | |
1045ec36 JM |
3981 | case NL80211_IFTYPE_MESH_POINT: |
3982 | return "MESH_POINT"; | |
a1922f93 JM |
3983 | case NL80211_IFTYPE_P2P_CLIENT: |
3984 | return "P2P_CLIENT"; | |
3985 | case NL80211_IFTYPE_P2P_GO: | |
3986 | return "P2P_GO"; | |
7aad838c NS |
3987 | case NL80211_IFTYPE_P2P_DEVICE: |
3988 | return "P2P_DEVICE"; | |
a1922f93 JM |
3989 | default: |
3990 | return "unknown"; | |
3991 | } | |
3992 | } | |
3993 | ||
3994 | ||
a35187e7 KH |
3995 | static int nl80211_create_iface_once(struct wpa_driver_nl80211_data *drv, |
3996 | const char *ifname, | |
3997 | enum nl80211_iftype iftype, | |
d6dcfcda DS |
3998 | const u8 *addr, int wds, |
3999 | int (*handler)(struct nl_msg *, void *), | |
4000 | void *arg) | |
0915d02c | 4001 | { |
8970bae8 | 4002 | struct nl_msg *msg; |
0915d02c JM |
4003 | int ifidx; |
4004 | int ret = -ENOBUFS; | |
4005 | ||
a1922f93 JM |
4006 | wpa_printf(MSG_DEBUG, "nl80211: Create interface iftype %d (%s)", |
4007 | iftype, nl80211_iftype_str(iftype)); | |
4008 | ||
56f77852 JM |
4009 | msg = nl80211_cmd_msg(drv->first_bss, 0, NL80211_CMD_NEW_INTERFACE); |
4010 | if (!msg || | |
a862e4a3 JM |
4011 | nla_put_string(msg, NL80211_ATTR_IFNAME, ifname) || |
4012 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, iftype)) | |
4013 | goto fail; | |
0915d02c JM |
4014 | |
4015 | if (iftype == NL80211_IFTYPE_MONITOR) { | |
8970bae8 | 4016 | struct nlattr *flags; |
0915d02c | 4017 | |
8970bae8 | 4018 | flags = nla_nest_start(msg, NL80211_ATTR_MNTR_FLAGS); |
a862e4a3 JM |
4019 | if (!flags || |
4020 | nla_put_flag(msg, NL80211_MNTR_FLAG_COOK_FRAMES)) | |
4021 | goto fail; | |
0915d02c | 4022 | |
8970bae8 | 4023 | nla_nest_end(msg, flags); |
fbbfcbac | 4024 | } else if (wds) { |
a862e4a3 JM |
4025 | if (nla_put_u8(msg, NL80211_ATTR_4ADDR, wds)) |
4026 | goto fail; | |
0915d02c JM |
4027 | } |
4028 | ||
52f5877a IP |
4029 | /* |
4030 | * Tell cfg80211 that the interface belongs to the socket that created | |
4031 | * it, and the interface should be deleted when the socket is closed. | |
4032 | */ | |
a862e4a3 JM |
4033 | if (nla_put_flag(msg, NL80211_ATTR_IFACE_SOCKET_OWNER)) |
4034 | goto fail; | |
52f5877a | 4035 | |
d6dcfcda | 4036 | ret = send_and_recv_msgs(drv, msg, handler, arg); |
5883168a | 4037 | msg = NULL; |
0915d02c | 4038 | if (ret) { |
a862e4a3 | 4039 | fail: |
5883168a | 4040 | nlmsg_free(msg); |
a35187e7 KH |
4041 | wpa_printf(MSG_ERROR, "Failed to create interface %s: %d (%s)", |
4042 | ifname, ret, strerror(-ret)); | |
0915d02c JM |
4043 | return ret; |
4044 | } | |
4045 | ||
f632e483 | 4046 | if (iftype == NL80211_IFTYPE_P2P_DEVICE) |
6bae92e0 | 4047 | return 0; |
6bae92e0 | 4048 | |
0915d02c | 4049 | ifidx = if_nametoindex(ifname); |
c6e8e8e4 JM |
4050 | wpa_printf(MSG_DEBUG, "nl80211: New interface %s created: ifindex=%d", |
4051 | ifname, ifidx); | |
0915d02c JM |
4052 | |
4053 | if (ifidx <= 0) | |
4054 | return -1; | |
4055 | ||
147848ec JM |
4056 | /* |
4057 | * Some virtual interfaces need to process EAPOL packets and events on | |
4058 | * the parent interface. This is used mainly with hostapd. | |
4059 | */ | |
4060 | if (drv->hostapd || | |
4061 | iftype == NL80211_IFTYPE_AP_VLAN || | |
4062 | iftype == NL80211_IFTYPE_WDS || | |
4063 | iftype == NL80211_IFTYPE_MONITOR) { | |
4064 | /* start listening for EAPOL on this interface */ | |
4065 | add_ifidx(drv, ifidx); | |
4066 | } | |
2135f224 | 4067 | |
7bfc47c3 | 4068 | if (addr && iftype != NL80211_IFTYPE_MONITOR && |
c81eff1a | 4069 | linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, addr)) { |
41d931ee JM |
4070 | nl80211_remove_iface(drv, ifidx); |
4071 | return -1; | |
2135f224 | 4072 | } |
2135f224 | 4073 | |
0915d02c JM |
4074 | return ifidx; |
4075 | } | |
22a7c9d7 JM |
4076 | |
4077 | ||
f3407c66 JM |
4078 | int nl80211_create_iface(struct wpa_driver_nl80211_data *drv, |
4079 | const char *ifname, enum nl80211_iftype iftype, | |
4080 | const u8 *addr, int wds, | |
4081 | int (*handler)(struct nl_msg *, void *), | |
4082 | void *arg, int use_existing) | |
a35187e7 KH |
4083 | { |
4084 | int ret; | |
4085 | ||
d6dcfcda DS |
4086 | ret = nl80211_create_iface_once(drv, ifname, iftype, addr, wds, handler, |
4087 | arg); | |
a35187e7 | 4088 | |
ffbf1eaa | 4089 | /* if error occurred and interface exists already */ |
a35187e7 | 4090 | if (ret == -ENFILE && if_nametoindex(ifname)) { |
2aec4f3c JM |
4091 | if (use_existing) { |
4092 | wpa_printf(MSG_DEBUG, "nl80211: Continue using existing interface %s", | |
4093 | ifname); | |
6997f8ba JM |
4094 | if (addr && iftype != NL80211_IFTYPE_MONITOR && |
4095 | linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, | |
4096 | addr) < 0 && | |
4097 | (linux_set_iface_flags(drv->global->ioctl_sock, | |
4098 | ifname, 0) < 0 || | |
4099 | linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, | |
4100 | addr) < 0 || | |
4101 | linux_set_iface_flags(drv->global->ioctl_sock, | |
4102 | ifname, 1) < 0)) | |
4103 | return -1; | |
2aec4f3c JM |
4104 | return -ENFILE; |
4105 | } | |
a35187e7 KH |
4106 | wpa_printf(MSG_INFO, "Try to remove and re-create %s", ifname); |
4107 | ||
4108 | /* Try to remove the interface that was already there. */ | |
4109 | nl80211_remove_iface(drv, if_nametoindex(ifname)); | |
4110 | ||
4111 | /* Try to create the interface again */ | |
fbbfcbac | 4112 | ret = nl80211_create_iface_once(drv, ifname, iftype, addr, |
d6dcfcda | 4113 | wds, handler, arg); |
a35187e7 KH |
4114 | } |
4115 | ||
3e208481 JM |
4116 | if (ret >= 0 && is_p2p_net_interface(iftype)) { |
4117 | wpa_printf(MSG_DEBUG, | |
4118 | "nl80211: Interface %s created for P2P - disable 11b rates", | |
4119 | ifname); | |
4e5cb1a3 | 4120 | nl80211_disable_11b_rates(drv, ret, 1); |
3e208481 | 4121 | } |
4e5cb1a3 | 4122 | |
a35187e7 KH |
4123 | return ret; |
4124 | } | |
0915d02c | 4125 | |
2135f224 | 4126 | |
3fd1cefb JB |
4127 | static int nl80211_setup_ap(struct i802_bss *bss) |
4128 | { | |
4129 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
4130 | ||
748c0ac0 JM |
4131 | wpa_printf(MSG_DEBUG, "nl80211: Setup AP(%s) - device_ap_sme=%d use_monitor=%d", |
4132 | bss->ifname, drv->device_ap_sme, drv->use_monitor); | |
36488c05 | 4133 | |
a11241fa JB |
4134 | /* |
4135 | * Disable Probe Request reporting unless we need it in this way for | |
4136 | * devices that include the AP SME, in the other case (unless using | |
4137 | * monitor iface) we'll get it through the nl_mgmt socket instead. | |
4138 | */ | |
4139 | if (!drv->device_ap_sme) | |
4140 | wpa_driver_nl80211_probe_req_report(bss, 0); | |
4141 | ||
4142 | if (!drv->device_ap_sme && !drv->use_monitor) | |
4143 | if (nl80211_mgmt_subscribe_ap(bss)) | |
4144 | return -1; | |
4145 | ||
a6cc0602 JM |
4146 | if (drv->device_ap_sme && !drv->use_monitor) |
4147 | if (nl80211_mgmt_subscribe_ap_dev_sme(bss)) | |
4148 | return -1; | |
4149 | ||
a11241fa | 4150 | if (!drv->device_ap_sme && drv->use_monitor && |
3fd1cefb JB |
4151 | nl80211_create_monitor_interface(drv) && |
4152 | !drv->device_ap_sme) | |
4153 | return -1; | |
4154 | ||
4155 | if (drv->device_ap_sme && | |
4156 | wpa_driver_nl80211_probe_req_report(bss, 1) < 0) { | |
4157 | wpa_printf(MSG_DEBUG, "nl80211: Failed to enable " | |
4158 | "Probe Request frame reporting in AP mode"); | |
4159 | /* Try to survive without this */ | |
4160 | } | |
4161 | ||
4162 | return 0; | |
4163 | } | |
4164 | ||
4165 | ||
4166 | static void nl80211_teardown_ap(struct i802_bss *bss) | |
4167 | { | |
4168 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
4169 | ||
748c0ac0 JM |
4170 | wpa_printf(MSG_DEBUG, "nl80211: Teardown AP(%s) - device_ap_sme=%d use_monitor=%d", |
4171 | bss->ifname, drv->device_ap_sme, drv->use_monitor); | |
a6cc0602 | 4172 | if (drv->device_ap_sme) { |
3fd1cefb | 4173 | wpa_driver_nl80211_probe_req_report(bss, 0); |
a6cc0602 JM |
4174 | if (!drv->use_monitor) |
4175 | nl80211_mgmt_unsubscribe(bss, "AP teardown (dev SME)"); | |
4176 | } else if (drv->use_monitor) | |
3fd1cefb | 4177 | nl80211_remove_monitor_interface(drv); |
a11241fa | 4178 | else |
36488c05 | 4179 | nl80211_mgmt_unsubscribe(bss, "AP teardown"); |
a11241fa | 4180 | |
3fd1cefb JB |
4181 | bss->beacon_set = 0; |
4182 | } | |
4183 | ||
4184 | ||
f10bfc9a JM |
4185 | static int nl80211_send_eapol_data(struct i802_bss *bss, |
4186 | const u8 *addr, const u8 *data, | |
d12dab4c | 4187 | size_t data_len) |
f10bfc9a | 4188 | { |
d12dab4c JB |
4189 | struct sockaddr_ll ll; |
4190 | int ret; | |
4191 | ||
4192 | if (bss->drv->eapol_tx_sock < 0) { | |
4193 | wpa_printf(MSG_DEBUG, "nl80211: No socket to send EAPOL"); | |
f10bfc9a JM |
4194 | return -1; |
4195 | } | |
4196 | ||
d12dab4c JB |
4197 | os_memset(&ll, 0, sizeof(ll)); |
4198 | ll.sll_family = AF_PACKET; | |
4199 | ll.sll_ifindex = bss->ifindex; | |
4200 | ll.sll_protocol = htons(ETH_P_PAE); | |
4201 | ll.sll_halen = ETH_ALEN; | |
4202 | os_memcpy(ll.sll_addr, addr, ETH_ALEN); | |
4203 | ret = sendto(bss->drv->eapol_tx_sock, data, data_len, 0, | |
4204 | (struct sockaddr *) &ll, sizeof(ll)); | |
4205 | if (ret < 0) | |
4206 | wpa_printf(MSG_ERROR, "nl80211: EAPOL TX: %s", | |
4207 | strerror(errno)); | |
4208 | ||
4209 | return ret; | |
f10bfc9a | 4210 | } |
5fb1a232 | 4211 | |
f10bfc9a | 4212 | |
db149ac9 JM |
4213 | static const u8 rfc1042_header[6] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 }; |
4214 | ||
4215 | static int wpa_driver_nl80211_hapd_send_eapol( | |
4216 | void *priv, const u8 *addr, const u8 *data, | |
4378fc14 | 4217 | size_t data_len, int encrypt, const u8 *own_addr, u32 flags) |
db149ac9 | 4218 | { |
a2e40bb6 FF |
4219 | struct i802_bss *bss = priv; |
4220 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
db149ac9 JM |
4221 | struct ieee80211_hdr *hdr; |
4222 | size_t len; | |
4223 | u8 *pos; | |
4224 | int res; | |
4378fc14 | 4225 | int qos = flags & WPA_STA_WMM; |
db149ac9 | 4226 | |
a11241fa | 4227 | if (drv->device_ap_sme || !drv->use_monitor) |
d12dab4c | 4228 | return nl80211_send_eapol_data(bss, addr, data, data_len); |
f10bfc9a | 4229 | |
db149ac9 JM |
4230 | len = sizeof(*hdr) + (qos ? 2 : 0) + sizeof(rfc1042_header) + 2 + |
4231 | data_len; | |
4232 | hdr = os_zalloc(len); | |
4233 | if (hdr == NULL) { | |
7ac3616d JM |
4234 | wpa_printf(MSG_INFO, "nl80211: Failed to allocate EAPOL buffer(len=%lu)", |
4235 | (unsigned long) len); | |
db149ac9 JM |
4236 | return -1; |
4237 | } | |
4238 | ||
4239 | hdr->frame_control = | |
4240 | IEEE80211_FC(WLAN_FC_TYPE_DATA, WLAN_FC_STYPE_DATA); | |
4241 | hdr->frame_control |= host_to_le16(WLAN_FC_FROMDS); | |
4242 | if (encrypt) | |
4243 | hdr->frame_control |= host_to_le16(WLAN_FC_ISWEP); | |
db149ac9 JM |
4244 | if (qos) { |
4245 | hdr->frame_control |= | |
4246 | host_to_le16(WLAN_FC_STYPE_QOS_DATA << 4); | |
4247 | } | |
db149ac9 JM |
4248 | |
4249 | memcpy(hdr->IEEE80211_DA_FROMDS, addr, ETH_ALEN); | |
4250 | memcpy(hdr->IEEE80211_BSSID_FROMDS, own_addr, ETH_ALEN); | |
4251 | memcpy(hdr->IEEE80211_SA_FROMDS, own_addr, ETH_ALEN); | |
4252 | pos = (u8 *) (hdr + 1); | |
4253 | ||
db149ac9 | 4254 | if (qos) { |
92d521d8 FF |
4255 | /* Set highest priority in QoS header */ |
4256 | pos[0] = 7; | |
db149ac9 JM |
4257 | pos[1] = 0; |
4258 | pos += 2; | |
4259 | } | |
db149ac9 JM |
4260 | |
4261 | memcpy(pos, rfc1042_header, sizeof(rfc1042_header)); | |
4262 | pos += sizeof(rfc1042_header); | |
4263 | WPA_PUT_BE16(pos, ETH_P_PAE); | |
4264 | pos += 2; | |
4265 | memcpy(pos, data, data_len); | |
4266 | ||
55231068 | 4267 | res = wpa_driver_nl80211_send_frame(bss, (u8 *) hdr, len, encrypt, 0, |
2d3943ce | 4268 | 0, 0, 0, 0, NULL, 0); |
db149ac9 JM |
4269 | if (res < 0) { |
4270 | wpa_printf(MSG_ERROR, "i802_send_eapol - packet len: %lu - " | |
4271 | "failed: %d (%s)", | |
4272 | (unsigned long) len, errno, strerror(errno)); | |
4273 | } | |
7bf12757 | 4274 | os_free(hdr); |
db149ac9 JM |
4275 | |
4276 | return res; | |
4277 | } | |
4278 | ||
a8d6ffa4 | 4279 | |
3234cba4 | 4280 | static int wpa_driver_nl80211_sta_set_flags(void *priv, const u8 *addr, |
f97e3ce4 JM |
4281 | unsigned int total_flags, |
4282 | unsigned int flags_or, | |
4283 | unsigned int flags_and) | |
a8d6ffa4 | 4284 | { |
a2e40bb6 | 4285 | struct i802_bss *bss = priv; |
8970bae8 JB |
4286 | struct nl_msg *msg; |
4287 | struct nlattr *flags; | |
7e76ee9c | 4288 | struct nl80211_sta_flag_update upd; |
a8d6ffa4 | 4289 | |
0cd9846c JM |
4290 | wpa_printf(MSG_DEBUG, "nl80211: Set STA flags - ifname=%s addr=" MACSTR |
4291 | " total_flags=0x%x flags_or=0x%x flags_and=0x%x authorized=%d", | |
4292 | bss->ifname, MAC2STR(addr), total_flags, flags_or, flags_and, | |
4293 | !!(total_flags & WPA_STA_AUTHORIZED)); | |
4294 | ||
13f83980 | 4295 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) || |
a862e4a3 JM |
4296 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
4297 | goto fail; | |
a8d6ffa4 | 4298 | |
7e76ee9c JM |
4299 | /* |
4300 | * Backwards compatibility version using NL80211_ATTR_STA_FLAGS. This | |
4301 | * can be removed eventually. | |
4302 | */ | |
8970bae8 | 4303 | flags = nla_nest_start(msg, NL80211_ATTR_STA_FLAGS); |
a862e4a3 JM |
4304 | if (!flags || |
4305 | ((total_flags & WPA_STA_AUTHORIZED) && | |
4306 | nla_put_flag(msg, NL80211_STA_FLAG_AUTHORIZED)) || | |
4307 | ((total_flags & WPA_STA_WMM) && | |
4308 | nla_put_flag(msg, NL80211_STA_FLAG_WME)) || | |
4309 | ((total_flags & WPA_STA_SHORT_PREAMBLE) && | |
4310 | nla_put_flag(msg, NL80211_STA_FLAG_SHORT_PREAMBLE)) || | |
4311 | ((total_flags & WPA_STA_MFP) && | |
4312 | nla_put_flag(msg, NL80211_STA_FLAG_MFP)) || | |
4313 | ((total_flags & WPA_STA_TDLS_PEER) && | |
4314 | nla_put_flag(msg, NL80211_STA_FLAG_TDLS_PEER))) | |
4315 | goto fail; | |
45b722f1 | 4316 | |
8970bae8 | 4317 | nla_nest_end(msg, flags); |
a8d6ffa4 | 4318 | |
7e76ee9c JM |
4319 | os_memset(&upd, 0, sizeof(upd)); |
4320 | upd.mask = sta_flags_nl80211(flags_or | ~flags_and); | |
4321 | upd.set = sta_flags_nl80211(flags_or); | |
a862e4a3 JM |
4322 | if (nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd)) |
4323 | goto fail; | |
7e76ee9c | 4324 | |
13f83980 | 4325 | return send_and_recv_msgs(bss->drv, msg, NULL, NULL); |
a862e4a3 | 4326 | fail: |
5883168a | 4327 | nlmsg_free(msg); |
a8d6ffa4 JM |
4328 | return -ENOBUFS; |
4329 | } | |
4330 | ||
0915d02c | 4331 | |
1581b38b JM |
4332 | static int wpa_driver_nl80211_ap(struct wpa_driver_nl80211_data *drv, |
4333 | struct wpa_driver_associate_params *params) | |
4334 | { | |
708bc8e0 | 4335 | enum nl80211_iftype nlmode, old_mode; |
b1f625e0 EP |
4336 | |
4337 | if (params->p2p) { | |
046b26a2 JM |
4338 | wpa_printf(MSG_DEBUG, "nl80211: Setup AP operations for P2P " |
4339 | "group (GO)"); | |
b1f625e0 EP |
4340 | nlmode = NL80211_IFTYPE_P2P_GO; |
4341 | } else | |
4342 | nlmode = NL80211_IFTYPE_AP; | |
4343 | ||
708bc8e0 | 4344 | old_mode = drv->nlmode; |
834ee56f | 4345 | if (wpa_driver_nl80211_set_mode(drv->first_bss, nlmode)) { |
708bc8e0 JM |
4346 | nl80211_remove_monitor_interface(drv); |
4347 | return -1; | |
4348 | } | |
4349 | ||
6e9023ea JM |
4350 | if (params->freq.freq && |
4351 | nl80211_set_channel(drv->first_bss, ¶ms->freq, 0)) { | |
708bc8e0 | 4352 | if (old_mode != nlmode) |
834ee56f | 4353 | wpa_driver_nl80211_set_mode(drv->first_bss, old_mode); |
460456f8 | 4354 | nl80211_remove_monitor_interface(drv); |
1581b38b | 4355 | return -1; |
0915d02c | 4356 | } |
1581b38b | 4357 | |
1581b38b JM |
4358 | return 0; |
4359 | } | |
1581b38b JM |
4360 | |
4361 | ||
666e508c JM |
4362 | static int nl80211_leave_ibss(struct wpa_driver_nl80211_data *drv, |
4363 | int reset_mode) | |
5cc4d64b JM |
4364 | { |
4365 | struct nl_msg *msg; | |
9725b784 | 4366 | int ret; |
a862e4a3 | 4367 | |
9725b784 | 4368 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_LEAVE_IBSS); |
5cc4d64b | 4369 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
5cc4d64b JM |
4370 | if (ret) { |
4371 | wpa_printf(MSG_DEBUG, "nl80211: Leave IBSS failed: ret=%d " | |
4372 | "(%s)", ret, strerror(-ret)); | |
9725b784 JM |
4373 | } else { |
4374 | wpa_printf(MSG_DEBUG, | |
4375 | "nl80211: Leave IBSS request sent successfully"); | |
5cc4d64b JM |
4376 | } |
4377 | ||
666e508c JM |
4378 | if (reset_mode && |
4379 | wpa_driver_nl80211_set_mode(drv->first_bss, | |
5d4c78fb JM |
4380 | NL80211_IFTYPE_STATION)) { |
4381 | wpa_printf(MSG_INFO, "nl80211: Failed to set interface into " | |
4382 | "station mode"); | |
4383 | } | |
4384 | ||
5cc4d64b JM |
4385 | return ret; |
4386 | } | |
4387 | ||
4388 | ||
95ff3069 JD |
4389 | static int nl80211_ht_vht_overrides(struct nl_msg *msg, |
4390 | struct wpa_driver_associate_params *params) | |
4391 | { | |
4392 | if (params->disable_ht && nla_put_flag(msg, NL80211_ATTR_DISABLE_HT)) | |
4393 | return -1; | |
4394 | ||
4395 | if (params->htcaps && params->htcaps_mask) { | |
4396 | int sz = sizeof(struct ieee80211_ht_capabilities); | |
4397 | wpa_hexdump(MSG_DEBUG, " * htcaps", params->htcaps, sz); | |
4398 | wpa_hexdump(MSG_DEBUG, " * htcaps_mask", | |
4399 | params->htcaps_mask, sz); | |
4400 | if (nla_put(msg, NL80211_ATTR_HT_CAPABILITY, sz, | |
4401 | params->htcaps) || | |
4402 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, sz, | |
4403 | params->htcaps_mask)) | |
4404 | return -1; | |
4405 | } | |
4406 | ||
4407 | #ifdef CONFIG_VHT_OVERRIDES | |
4408 | if (params->disable_vht) { | |
4409 | wpa_printf(MSG_DEBUG, " * VHT disabled"); | |
4410 | if (nla_put_flag(msg, NL80211_ATTR_DISABLE_VHT)) | |
4411 | return -1; | |
4412 | } | |
4413 | ||
4414 | if (params->vhtcaps && params->vhtcaps_mask) { | |
4415 | int sz = sizeof(struct ieee80211_vht_capabilities); | |
4416 | wpa_hexdump(MSG_DEBUG, " * vhtcaps", params->vhtcaps, sz); | |
4417 | wpa_hexdump(MSG_DEBUG, " * vhtcaps_mask", | |
4418 | params->vhtcaps_mask, sz); | |
4419 | if (nla_put(msg, NL80211_ATTR_VHT_CAPABILITY, sz, | |
4420 | params->vhtcaps) || | |
4421 | nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, sz, | |
4422 | params->vhtcaps_mask)) | |
4423 | return -1; | |
4424 | } | |
4425 | #endif /* CONFIG_VHT_OVERRIDES */ | |
4426 | ||
4427 | return 0; | |
4428 | } | |
4429 | ||
4430 | ||
5cc4d64b JM |
4431 | static int wpa_driver_nl80211_ibss(struct wpa_driver_nl80211_data *drv, |
4432 | struct wpa_driver_associate_params *params) | |
4433 | { | |
4434 | struct nl_msg *msg; | |
4435 | int ret = -1; | |
4436 | int count = 0; | |
4437 | ||
4438 | wpa_printf(MSG_DEBUG, "nl80211: Join IBSS (ifindex=%d)", drv->ifindex); | |
4439 | ||
4ec68377 | 4440 | if (wpa_driver_nl80211_set_mode_ibss(drv->first_bss, ¶ms->freq)) { |
5cc4d64b JM |
4441 | wpa_printf(MSG_INFO, "nl80211: Failed to set interface into " |
4442 | "IBSS mode"); | |
4443 | return -1; | |
4444 | } | |
4445 | ||
4446 | retry: | |
9725b784 | 4447 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_JOIN_IBSS)) || |
a862e4a3 JM |
4448 | params->ssid == NULL || params->ssid_len > sizeof(drv->ssid)) |
4449 | goto fail; | |
5cc4d64b JM |
4450 | |
4451 | wpa_hexdump_ascii(MSG_DEBUG, " * SSID", | |
4452 | params->ssid, params->ssid_len); | |
a862e4a3 JM |
4453 | if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid)) |
4454 | goto fail; | |
5cc4d64b JM |
4455 | os_memcpy(drv->ssid, params->ssid, params->ssid_len); |
4456 | drv->ssid_len = params->ssid_len; | |
4457 | ||
85e1fad8 JM |
4458 | if (nl80211_put_freq_params(msg, ¶ms->freq) < 0 || |
4459 | nl80211_put_beacon_int(msg, params->beacon_int)) | |
a862e4a3 | 4460 | goto fail; |
5cc4d64b JM |
4461 | |
4462 | ret = nl80211_set_conn_keys(params, msg); | |
4463 | if (ret) | |
a862e4a3 | 4464 | goto fail; |
5cc4d64b | 4465 | |
913e3cf7 NC |
4466 | if (params->bssid && params->fixed_bssid) { |
4467 | wpa_printf(MSG_DEBUG, " * BSSID=" MACSTR, | |
4468 | MAC2STR(params->bssid)); | |
a862e4a3 JM |
4469 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid)) |
4470 | goto fail; | |
913e3cf7 NC |
4471 | } |
4472 | ||
4d9e6fba JD |
4473 | if (params->fixed_freq) { |
4474 | wpa_printf(MSG_DEBUG, " * fixed_freq"); | |
4475 | if (nla_put_flag(msg, NL80211_ATTR_FREQ_FIXED)) | |
4476 | goto fail; | |
4477 | } | |
4478 | ||
4848a38d JM |
4479 | if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X || |
4480 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK || | |
4481 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SHA256 || | |
4482 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256) { | |
e640888c | 4483 | wpa_printf(MSG_DEBUG, " * control port"); |
a862e4a3 JM |
4484 | if (nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT)) |
4485 | goto fail; | |
e640888c AQ |
4486 | } |
4487 | ||
a95795ad JM |
4488 | if (params->wpa_ie) { |
4489 | wpa_hexdump(MSG_DEBUG, | |
4490 | " * Extra IEs for Beacon/Probe Response frames", | |
4491 | params->wpa_ie, params->wpa_ie_len); | |
a862e4a3 JM |
4492 | if (nla_put(msg, NL80211_ATTR_IE, params->wpa_ie_len, |
4493 | params->wpa_ie)) | |
4494 | goto fail; | |
a95795ad JM |
4495 | } |
4496 | ||
95ff3069 JD |
4497 | if (nl80211_ht_vht_overrides(msg, params) < 0) |
4498 | return -1; | |
4499 | ||
5cc4d64b JM |
4500 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
4501 | msg = NULL; | |
4502 | if (ret) { | |
4503 | wpa_printf(MSG_DEBUG, "nl80211: Join IBSS failed: ret=%d (%s)", | |
4504 | ret, strerror(-ret)); | |
4505 | count++; | |
4506 | if (ret == -EALREADY && count == 1) { | |
4507 | wpa_printf(MSG_DEBUG, "nl80211: Retry IBSS join after " | |
4508 | "forced leave"); | |
666e508c | 4509 | nl80211_leave_ibss(drv, 0); |
5cc4d64b JM |
4510 | nlmsg_free(msg); |
4511 | goto retry; | |
4512 | } | |
a862e4a3 JM |
4513 | } else { |
4514 | wpa_printf(MSG_DEBUG, | |
4515 | "nl80211: Join IBSS request sent successfully"); | |
5cc4d64b | 4516 | } |
5cc4d64b | 4517 | |
a862e4a3 | 4518 | fail: |
5cc4d64b JM |
4519 | nlmsg_free(msg); |
4520 | return ret; | |
4521 | } | |
4522 | ||
4523 | ||
a0bdd191 JM |
4524 | static int nl80211_connect_common(struct wpa_driver_nl80211_data *drv, |
4525 | struct wpa_driver_associate_params *params, | |
4526 | struct nl_msg *msg) | |
cfaab580 | 4527 | { |
cfaab580 ZY |
4528 | if (params->bssid) { |
4529 | wpa_printf(MSG_DEBUG, " * bssid=" MACSTR, | |
4530 | MAC2STR(params->bssid)); | |
a862e4a3 JM |
4531 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid)) |
4532 | return -1; | |
cfaab580 | 4533 | } |
a0bdd191 | 4534 | |
7ac7fd43 DS |
4535 | if (params->bssid_hint) { |
4536 | wpa_printf(MSG_DEBUG, " * bssid_hint=" MACSTR, | |
4537 | MAC2STR(params->bssid_hint)); | |
a862e4a3 JM |
4538 | if (nla_put(msg, NL80211_ATTR_MAC_HINT, ETH_ALEN, |
4539 | params->bssid_hint)) | |
4540 | return -1; | |
7ac7fd43 DS |
4541 | } |
4542 | ||
4ec68377 JD |
4543 | if (params->freq.freq) { |
4544 | wpa_printf(MSG_DEBUG, " * freq=%d", params->freq.freq); | |
a862e4a3 JM |
4545 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
4546 | params->freq.freq)) | |
4547 | return -1; | |
4ec68377 | 4548 | drv->assoc_freq = params->freq.freq; |
30158a0d SD |
4549 | } else |
4550 | drv->assoc_freq = 0; | |
a0bdd191 | 4551 | |
7ac7fd43 DS |
4552 | if (params->freq_hint) { |
4553 | wpa_printf(MSG_DEBUG, " * freq_hint=%d", params->freq_hint); | |
a862e4a3 JM |
4554 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ_HINT, |
4555 | params->freq_hint)) | |
4556 | return -1; | |
7ac7fd43 DS |
4557 | } |
4558 | ||
1f6c0ab8 BS |
4559 | if (params->bg_scan_period >= 0) { |
4560 | wpa_printf(MSG_DEBUG, " * bg scan period=%d", | |
4561 | params->bg_scan_period); | |
a862e4a3 JM |
4562 | if (nla_put_u16(msg, NL80211_ATTR_BG_SCAN_PERIOD, |
4563 | params->bg_scan_period)) | |
4564 | return -1; | |
1f6c0ab8 | 4565 | } |
a0bdd191 | 4566 | |
cfaab580 ZY |
4567 | if (params->ssid) { |
4568 | wpa_hexdump_ascii(MSG_DEBUG, " * SSID", | |
4569 | params->ssid, params->ssid_len); | |
a862e4a3 JM |
4570 | if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, |
4571 | params->ssid)) | |
4572 | return -1; | |
cfaab580 | 4573 | if (params->ssid_len > sizeof(drv->ssid)) |
a862e4a3 | 4574 | return -1; |
cfaab580 ZY |
4575 | os_memcpy(drv->ssid, params->ssid, params->ssid_len); |
4576 | drv->ssid_len = params->ssid_len; | |
4577 | } | |
a0bdd191 | 4578 | |
cfaab580 | 4579 | wpa_hexdump(MSG_DEBUG, " * IEs", params->wpa_ie, params->wpa_ie_len); |
a862e4a3 JM |
4580 | if (params->wpa_ie && |
4581 | nla_put(msg, NL80211_ATTR_IE, params->wpa_ie_len, params->wpa_ie)) | |
4582 | return -1; | |
cfaab580 | 4583 | |
64fa840a JM |
4584 | if (params->wpa_proto) { |
4585 | enum nl80211_wpa_versions ver = 0; | |
cfaab580 | 4586 | |
64fa840a JM |
4587 | if (params->wpa_proto & WPA_PROTO_WPA) |
4588 | ver |= NL80211_WPA_VERSION_1; | |
4589 | if (params->wpa_proto & WPA_PROTO_RSN) | |
4590 | ver |= NL80211_WPA_VERSION_2; | |
cfaab580 | 4591 | |
64fa840a | 4592 | wpa_printf(MSG_DEBUG, " * WPA Versions 0x%x", ver); |
a862e4a3 JM |
4593 | if (nla_put_u32(msg, NL80211_ATTR_WPA_VERSIONS, ver)) |
4594 | return -1; | |
cfaab580 ZY |
4595 | } |
4596 | ||
4848a38d | 4597 | if (params->pairwise_suite != WPA_CIPHER_NONE) { |
a0bdd191 JM |
4598 | u32 cipher = wpa_cipher_to_cipher_suite(params->pairwise_suite); |
4599 | wpa_printf(MSG_DEBUG, " * pairwise=0x%x", cipher); | |
a862e4a3 JM |
4600 | if (nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITES_PAIRWISE, |
4601 | cipher)) | |
4602 | return -1; | |
cfaab580 ZY |
4603 | } |
4604 | ||
ae6f9272 JM |
4605 | if (params->group_suite == WPA_CIPHER_GTK_NOT_USED && |
4606 | !(drv->capa.enc & WPA_DRIVER_CAPA_ENC_GTK_NOT_USED)) { | |
4607 | /* | |
4608 | * This is likely to work even though many drivers do not | |
4609 | * advertise support for operations without GTK. | |
4610 | */ | |
4611 | wpa_printf(MSG_DEBUG, " * skip group cipher configuration for GTK_NOT_USED due to missing driver support advertisement"); | |
4612 | } else if (params->group_suite != WPA_CIPHER_NONE) { | |
a0bdd191 JM |
4613 | u32 cipher = wpa_cipher_to_cipher_suite(params->group_suite); |
4614 | wpa_printf(MSG_DEBUG, " * group=0x%x", cipher); | |
a862e4a3 JM |
4615 | if (nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, cipher)) |
4616 | return -1; | |
cfaab580 ZY |
4617 | } |
4618 | ||
4848a38d JM |
4619 | if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X || |
4620 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK || | |
4621 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_IEEE8021X || | |
4622 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_PSK || | |
163f801e | 4623 | params->key_mgmt_suite == WPA_KEY_MGMT_CCKM || |
8802326f JJ |
4624 | params->key_mgmt_suite == WPA_KEY_MGMT_OSEN || |
4625 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SHA256 || | |
666497c8 | 4626 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256 || |
5e3b5197 JM |
4627 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SUITE_B || |
4628 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SUITE_B_192) { | |
cfaab580 ZY |
4629 | int mgmt = WLAN_AKM_SUITE_PSK; |
4630 | ||
4631 | switch (params->key_mgmt_suite) { | |
4848a38d | 4632 | case WPA_KEY_MGMT_CCKM: |
369c8d7b JM |
4633 | mgmt = WLAN_AKM_SUITE_CCKM; |
4634 | break; | |
4848a38d | 4635 | case WPA_KEY_MGMT_IEEE8021X: |
cfaab580 ZY |
4636 | mgmt = WLAN_AKM_SUITE_8021X; |
4637 | break; | |
4848a38d | 4638 | case WPA_KEY_MGMT_FT_IEEE8021X: |
6a1ce395 DG |
4639 | mgmt = WLAN_AKM_SUITE_FT_8021X; |
4640 | break; | |
4848a38d | 4641 | case WPA_KEY_MGMT_FT_PSK: |
6a1ce395 DG |
4642 | mgmt = WLAN_AKM_SUITE_FT_PSK; |
4643 | break; | |
8802326f JJ |
4644 | case WPA_KEY_MGMT_IEEE8021X_SHA256: |
4645 | mgmt = WLAN_AKM_SUITE_8021X_SHA256; | |
4646 | break; | |
4647 | case WPA_KEY_MGMT_PSK_SHA256: | |
4648 | mgmt = WLAN_AKM_SUITE_PSK_SHA256; | |
4649 | break; | |
163f801e JM |
4650 | case WPA_KEY_MGMT_OSEN: |
4651 | mgmt = WLAN_AKM_SUITE_OSEN; | |
4652 | break; | |
666497c8 JM |
4653 | case WPA_KEY_MGMT_IEEE8021X_SUITE_B: |
4654 | mgmt = WLAN_AKM_SUITE_8021X_SUITE_B; | |
4655 | break; | |
5e3b5197 JM |
4656 | case WPA_KEY_MGMT_IEEE8021X_SUITE_B_192: |
4657 | mgmt = WLAN_AKM_SUITE_8021X_SUITE_B_192; | |
4658 | break; | |
4848a38d | 4659 | case WPA_KEY_MGMT_PSK: |
cfaab580 ZY |
4660 | default: |
4661 | mgmt = WLAN_AKM_SUITE_PSK; | |
4662 | break; | |
4663 | } | |
163f801e | 4664 | wpa_printf(MSG_DEBUG, " * akm=0x%x", mgmt); |
a862e4a3 JM |
4665 | if (nla_put_u32(msg, NL80211_ATTR_AKM_SUITES, mgmt)) |
4666 | return -1; | |
cfaab580 ZY |
4667 | } |
4668 | ||
a862e4a3 JM |
4669 | if (nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT)) |
4670 | return -1; | |
a0bdd191 | 4671 | |
a862e4a3 JM |
4672 | if (params->mgmt_frame_protection == MGMT_FRAME_PROTECTION_REQUIRED && |
4673 | nla_put_u32(msg, NL80211_ATTR_USE_MFP, NL80211_MFP_REQUIRED)) | |
4674 | return -1; | |
a565084f | 4675 | |
58162adf AK |
4676 | if (params->rrm_used) { |
4677 | u32 drv_rrm_flags = drv->capa.rrm_flags; | |
4678 | if (!(drv_rrm_flags & | |
4679 | WPA_DRIVER_FLAGS_DS_PARAM_SET_IE_IN_PROBES) || | |
a862e4a3 JM |
4680 | !(drv_rrm_flags & WPA_DRIVER_FLAGS_QUIET) || |
4681 | nla_put_flag(msg, NL80211_ATTR_USE_RRM)) | |
4682 | return -1; | |
58162adf AK |
4683 | } |
4684 | ||
95ff3069 | 4685 | if (nl80211_ht_vht_overrides(msg, params) < 0) |
a862e4a3 | 4686 | return -1; |
80e8a5ee | 4687 | |
a0bdd191 JM |
4688 | if (params->p2p) |
4689 | wpa_printf(MSG_DEBUG, " * P2P group"); | |
4690 | ||
4691 | return 0; | |
a0bdd191 JM |
4692 | } |
4693 | ||
4694 | ||
4695 | static int wpa_driver_nl80211_try_connect( | |
4696 | struct wpa_driver_nl80211_data *drv, | |
4697 | struct wpa_driver_associate_params *params) | |
4698 | { | |
4699 | struct nl_msg *msg; | |
4700 | enum nl80211_auth_type type; | |
4701 | int ret; | |
4702 | int algs; | |
4703 | ||
b658547d | 4704 | #ifdef CONFIG_DRIVER_NL80211_QCA |
b41f2684 CL |
4705 | if (params->req_key_mgmt_offload && params->psk && |
4706 | (params->key_mgmt_suite == WPA_KEY_MGMT_PSK || | |
4707 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256 || | |
4708 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_PSK)) { | |
4709 | wpa_printf(MSG_DEBUG, "nl80211: Key management set PSK"); | |
4710 | ret = issue_key_mgmt_set_key(drv, params->psk, 32); | |
4711 | if (ret) | |
4712 | return ret; | |
4713 | } | |
b658547d | 4714 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
b41f2684 | 4715 | |
9725b784 JM |
4716 | wpa_printf(MSG_DEBUG, "nl80211: Connect (ifindex=%d)", drv->ifindex); |
4717 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_CONNECT); | |
a0bdd191 JM |
4718 | if (!msg) |
4719 | return -1; | |
4720 | ||
a0bdd191 JM |
4721 | ret = nl80211_connect_common(drv, params, msg); |
4722 | if (ret) | |
a862e4a3 | 4723 | goto fail; |
a0bdd191 JM |
4724 | |
4725 | algs = 0; | |
4726 | if (params->auth_alg & WPA_AUTH_ALG_OPEN) | |
4727 | algs++; | |
4728 | if (params->auth_alg & WPA_AUTH_ALG_SHARED) | |
4729 | algs++; | |
4730 | if (params->auth_alg & WPA_AUTH_ALG_LEAP) | |
4731 | algs++; | |
4732 | if (algs > 1) { | |
4733 | wpa_printf(MSG_DEBUG, " * Leave out Auth Type for automatic " | |
4734 | "selection"); | |
4735 | goto skip_auth_type; | |
4736 | } | |
4737 | ||
4738 | if (params->auth_alg & WPA_AUTH_ALG_OPEN) | |
4739 | type = NL80211_AUTHTYPE_OPEN_SYSTEM; | |
4740 | else if (params->auth_alg & WPA_AUTH_ALG_SHARED) | |
4741 | type = NL80211_AUTHTYPE_SHARED_KEY; | |
4742 | else if (params->auth_alg & WPA_AUTH_ALG_LEAP) | |
4743 | type = NL80211_AUTHTYPE_NETWORK_EAP; | |
4744 | else if (params->auth_alg & WPA_AUTH_ALG_FT) | |
4745 | type = NL80211_AUTHTYPE_FT; | |
4746 | else | |
a862e4a3 | 4747 | goto fail; |
a0bdd191 JM |
4748 | |
4749 | wpa_printf(MSG_DEBUG, " * Auth Type %d", type); | |
a862e4a3 JM |
4750 | if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, type)) |
4751 | goto fail; | |
a0bdd191 JM |
4752 | |
4753 | skip_auth_type: | |
cfaab580 ZY |
4754 | ret = nl80211_set_conn_keys(params, msg); |
4755 | if (ret) | |
a862e4a3 | 4756 | goto fail; |
cfaab580 ZY |
4757 | |
4758 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
4759 | msg = NULL; | |
4760 | if (ret) { | |
4761 | wpa_printf(MSG_DEBUG, "nl80211: MLME connect failed: ret=%d " | |
4762 | "(%s)", ret, strerror(-ret)); | |
a862e4a3 JM |
4763 | } else { |
4764 | wpa_printf(MSG_DEBUG, | |
4765 | "nl80211: Connect request send successfully"); | |
cfaab580 | 4766 | } |
cfaab580 | 4767 | |
a862e4a3 | 4768 | fail: |
cfaab580 ZY |
4769 | nlmsg_free(msg); |
4770 | return ret; | |
4771 | ||
4772 | } | |
4773 | ||
4774 | ||
a8c5b43a CW |
4775 | static int wpa_driver_nl80211_connect( |
4776 | struct wpa_driver_nl80211_data *drv, | |
4777 | struct wpa_driver_associate_params *params) | |
4778 | { | |
0d4e3d1d JJ |
4779 | int ret; |
4780 | ||
4781 | /* Store the connection attempted bssid for future use */ | |
4782 | if (params->bssid) | |
4783 | os_memcpy(drv->auth_attempt_bssid, params->bssid, ETH_ALEN); | |
4784 | else | |
4785 | os_memset(drv->auth_attempt_bssid, 0, ETH_ALEN); | |
4786 | ||
4787 | ret = wpa_driver_nl80211_try_connect(drv, params); | |
a8c5b43a CW |
4788 | if (ret == -EALREADY) { |
4789 | /* | |
4790 | * cfg80211 does not currently accept new connections if | |
4791 | * we are already connected. As a workaround, force | |
4792 | * disconnection and try again. | |
4793 | */ | |
4794 | wpa_printf(MSG_DEBUG, "nl80211: Explicitly " | |
4795 | "disconnecting before reassociation " | |
4796 | "attempt"); | |
4797 | if (wpa_driver_nl80211_disconnect( | |
4798 | drv, WLAN_REASON_PREV_AUTH_NOT_VALID)) | |
4799 | return -1; | |
a8c5b43a CW |
4800 | ret = wpa_driver_nl80211_try_connect(drv, params); |
4801 | } | |
4802 | return ret; | |
4803 | } | |
4804 | ||
4805 | ||
c2a04078 JM |
4806 | static int wpa_driver_nl80211_associate( |
4807 | void *priv, struct wpa_driver_associate_params *params) | |
4808 | { | |
a2e40bb6 FF |
4809 | struct i802_bss *bss = priv; |
4810 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
a862e4a3 | 4811 | int ret = -1; |
c2a04078 JM |
4812 | struct nl_msg *msg; |
4813 | ||
4bd71954 JM |
4814 | nl80211_unmask_11b_rates(bss); |
4815 | ||
5cc4d64b | 4816 | if (params->mode == IEEE80211_MODE_AP) |
1581b38b | 4817 | return wpa_driver_nl80211_ap(drv, params); |
1581b38b | 4818 | |
5cc4d64b JM |
4819 | if (params->mode == IEEE80211_MODE_IBSS) |
4820 | return wpa_driver_nl80211_ibss(drv, params); | |
4821 | ||
4a867032 | 4822 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) { |
b1f625e0 EP |
4823 | enum nl80211_iftype nlmode = params->p2p ? |
4824 | NL80211_IFTYPE_P2P_CLIENT : NL80211_IFTYPE_STATION; | |
4825 | ||
4826 | if (wpa_driver_nl80211_set_mode(priv, nlmode) < 0) | |
4a867032 | 4827 | return -1; |
cfaab580 | 4828 | return wpa_driver_nl80211_connect(drv, params); |
4a867032 | 4829 | } |
cfaab580 | 4830 | |
add9b7a4 | 4831 | nl80211_mark_disconnected(drv); |
c2a04078 | 4832 | |
c2a04078 JM |
4833 | wpa_printf(MSG_DEBUG, "nl80211: Associate (ifindex=%d)", |
4834 | drv->ifindex); | |
9725b784 JM |
4835 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_ASSOCIATE); |
4836 | if (!msg) | |
4837 | return -1; | |
c2a04078 | 4838 | |
a0bdd191 JM |
4839 | ret = nl80211_connect_common(drv, params, msg); |
4840 | if (ret) | |
a862e4a3 | 4841 | goto fail; |
01652550 | 4842 | |
62fa124c JM |
4843 | if (params->prev_bssid) { |
4844 | wpa_printf(MSG_DEBUG, " * prev_bssid=" MACSTR, | |
4845 | MAC2STR(params->prev_bssid)); | |
a862e4a3 JM |
4846 | if (nla_put(msg, NL80211_ATTR_PREV_BSSID, ETH_ALEN, |
4847 | params->prev_bssid)) | |
4848 | goto fail; | |
62fa124c JM |
4849 | } |
4850 | ||
c2a04078 JM |
4851 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
4852 | msg = NULL; | |
4853 | if (ret) { | |
3b7ea880 BG |
4854 | wpa_dbg(drv->ctx, MSG_DEBUG, |
4855 | "nl80211: MLME command failed (assoc): ret=%d (%s)", | |
4856 | ret, strerror(-ret)); | |
8856462d | 4857 | nl80211_dump_scan(drv); |
a862e4a3 JM |
4858 | } else { |
4859 | wpa_printf(MSG_DEBUG, | |
4860 | "nl80211: Association request send successfully"); | |
c2a04078 | 4861 | } |
c2a04078 | 4862 | |
a862e4a3 | 4863 | fail: |
c2a04078 JM |
4864 | nlmsg_free(msg); |
4865 | return ret; | |
4866 | } | |
3f5285e8 JM |
4867 | |
4868 | ||
ad1e68e6 | 4869 | static int nl80211_set_mode(struct wpa_driver_nl80211_data *drv, |
a1922f93 | 4870 | int ifindex, enum nl80211_iftype mode) |
3f5285e8 | 4871 | { |
3f5285e8 | 4872 | struct nl_msg *msg; |
ad1e68e6 JM |
4873 | int ret = -ENOBUFS; |
4874 | ||
a1922f93 JM |
4875 | wpa_printf(MSG_DEBUG, "nl80211: Set mode ifindex %d iftype %d (%s)", |
4876 | ifindex, mode, nl80211_iftype_str(mode)); | |
4877 | ||
56f77852 JM |
4878 | msg = nl80211_cmd_msg(drv->first_bss, 0, NL80211_CMD_SET_INTERFACE); |
4879 | if (!msg || nla_put_u32(msg, NL80211_ATTR_IFTYPE, mode)) | |
a862e4a3 | 4880 | goto fail; |
ad1e68e6 JM |
4881 | |
4882 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
5883168a | 4883 | msg = NULL; |
ad1e68e6 JM |
4884 | if (!ret) |
4885 | return 0; | |
a862e4a3 | 4886 | fail: |
5883168a | 4887 | nlmsg_free(msg); |
ad1e68e6 JM |
4888 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set interface %d to mode %d:" |
4889 | " %d (%s)", ifindex, mode, ret, strerror(-ret)); | |
4890 | return ret; | |
4891 | } | |
4892 | ||
4893 | ||
3c5d34e3 CW |
4894 | static int wpa_driver_nl80211_set_mode_impl( |
4895 | struct i802_bss *bss, | |
4896 | enum nl80211_iftype nlmode, | |
4897 | struct hostapd_freq_params *desired_freq_params) | |
ad1e68e6 | 4898 | { |
a2e40bb6 | 4899 | struct wpa_driver_nl80211_data *drv = bss->drv; |
ad1e68e6 | 4900 | int ret = -1; |
26af9dca | 4901 | int i; |
86957e62 | 4902 | int was_ap = is_ap_interface(drv->nlmode); |
671a5039 | 4903 | int res; |
ebffdbc4 | 4904 | int mode_switch_res; |
1581b38b | 4905 | |
ebffdbc4 CW |
4906 | mode_switch_res = nl80211_set_mode(drv, drv->ifindex, nlmode); |
4907 | if (mode_switch_res && nlmode == nl80211_get_ifmode(bss)) | |
4908 | mode_switch_res = 0; | |
8e12685c | 4909 | |
ebffdbc4 | 4910 | if (mode_switch_res == 0) { |
ad1e68e6 | 4911 | drv->nlmode = nlmode; |
460456f8 JM |
4912 | ret = 0; |
4913 | goto done; | |
ad1e68e6 | 4914 | } |
3f5285e8 | 4915 | |
ebffdbc4 | 4916 | if (mode_switch_res == -ENODEV) |
671a5039 JM |
4917 | return -1; |
4918 | ||
460456f8 | 4919 | if (nlmode == drv->nlmode) { |
c6e8e8e4 JM |
4920 | wpa_printf(MSG_DEBUG, "nl80211: Interface already in " |
4921 | "requested mode - ignore error"); | |
460456f8 JM |
4922 | ret = 0; |
4923 | goto done; /* Already in the requested mode */ | |
4924 | } | |
3f5285e8 | 4925 | |
3f5285e8 JM |
4926 | /* mac80211 doesn't allow mode changes while the device is up, so |
4927 | * take the device down, try to set the mode again, and bring the | |
4928 | * device back up. | |
4929 | */ | |
26af9dca JM |
4930 | wpa_printf(MSG_DEBUG, "nl80211: Try mode change after setting " |
4931 | "interface down"); | |
4932 | for (i = 0; i < 10; i++) { | |
91724d6f | 4933 | res = i802_set_iface_flags(bss, 0); |
6e8183d7 JM |
4934 | if (res == -EACCES || res == -ENODEV) |
4935 | break; | |
ebffdbc4 | 4936 | if (res != 0) { |
26af9dca JM |
4937 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set " |
4938 | "interface down"); | |
ebffdbc4 CW |
4939 | os_sleep(0, 100000); |
4940 | continue; | |
4941 | } | |
3c5d34e3 CW |
4942 | |
4943 | /* | |
4944 | * Setting the mode will fail for some drivers if the phy is | |
4945 | * on a frequency that the mode is disallowed in. | |
4946 | */ | |
4947 | if (desired_freq_params) { | |
bdf5ccb2 | 4948 | res = nl80211_set_channel(bss, desired_freq_params, 0); |
3c5d34e3 CW |
4949 | if (res) { |
4950 | wpa_printf(MSG_DEBUG, | |
4951 | "nl80211: Failed to set frequency on interface"); | |
4952 | } | |
4953 | } | |
4954 | ||
ebffdbc4 CW |
4955 | /* Try to set the mode again while the interface is down */ |
4956 | mode_switch_res = nl80211_set_mode(drv, drv->ifindex, nlmode); | |
4957 | if (mode_switch_res == -EBUSY) { | |
4958 | wpa_printf(MSG_DEBUG, | |
4959 | "nl80211: Delaying mode set while interface going down"); | |
4960 | os_sleep(0, 100000); | |
4961 | continue; | |
4962 | } | |
4963 | ret = mode_switch_res; | |
4964 | break; | |
3f5285e8 JM |
4965 | } |
4966 | ||
c6e8e8e4 JM |
4967 | if (!ret) { |
4968 | wpa_printf(MSG_DEBUG, "nl80211: Mode change succeeded while " | |
4969 | "interface is down"); | |
ad1e68e6 | 4970 | drv->nlmode = nlmode; |
7d9c3698 | 4971 | drv->ignore_if_down_event = 1; |
c6e8e8e4 | 4972 | } |
ad1e68e6 | 4973 | |
ebffdbc4 CW |
4974 | /* Bring the interface back up */ |
4975 | res = linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 1); | |
4976 | if (res != 0) { | |
4977 | wpa_printf(MSG_DEBUG, | |
4978 | "nl80211: Failed to set interface up after switching mode"); | |
4979 | ret = -1; | |
4980 | } | |
4981 | ||
460456f8 | 4982 | done: |
3fd1cefb JB |
4983 | if (ret) { |
4984 | wpa_printf(MSG_DEBUG, "nl80211: Interface mode change to %d " | |
4985 | "from %d failed", nlmode, drv->nlmode); | |
4986 | return ret; | |
4987 | } | |
4988 | ||
3e208481 JM |
4989 | if (is_p2p_net_interface(nlmode)) { |
4990 | wpa_printf(MSG_DEBUG, | |
4991 | "nl80211: Interface %s mode change to P2P - disable 11b rates", | |
4992 | bss->ifname); | |
edb9bfba | 4993 | nl80211_disable_11b_rates(drv, drv->ifindex, 1); |
3e208481 JM |
4994 | } else if (drv->disabled_11b_rates) { |
4995 | wpa_printf(MSG_DEBUG, | |
4996 | "nl80211: Interface %s mode changed to non-P2P - re-enable 11b rates", | |
4997 | bss->ifname); | |
1d0c6fb1 | 4998 | nl80211_disable_11b_rates(drv, drv->ifindex, 0); |
3e208481 | 4999 | } |
edb9bfba | 5000 | |
3fd1cefb | 5001 | if (is_ap_interface(nlmode)) { |
36488c05 | 5002 | nl80211_mgmt_unsubscribe(bss, "start AP"); |
460456f8 | 5003 | /* Setup additional AP mode functionality if needed */ |
3fd1cefb | 5004 | if (nl80211_setup_ap(bss)) |
460456f8 | 5005 | return -1; |
3fd1cefb | 5006 | } else if (was_ap) { |
460456f8 | 5007 | /* Remove additional AP mode functionality */ |
3fd1cefb | 5008 | nl80211_teardown_ap(bss); |
a11241fa | 5009 | } else { |
36488c05 | 5010 | nl80211_mgmt_unsubscribe(bss, "mode change"); |
460456f8 | 5011 | } |
460456f8 | 5012 | |
afb0550a BC |
5013 | if (is_mesh_interface(nlmode) && |
5014 | nl80211_mgmt_subscribe_mesh(bss)) | |
5015 | return -1; | |
5016 | ||
873d0fcf | 5017 | if (!bss->in_deinit && !is_ap_interface(nlmode) && |
afb0550a | 5018 | !is_mesh_interface(nlmode) && |
a11241fa JB |
5019 | nl80211_mgmt_subscribe_non_ap(bss) < 0) |
5020 | wpa_printf(MSG_DEBUG, "nl80211: Failed to register Action " | |
5021 | "frame processing - ignore for now"); | |
08359050 | 5022 | |
3fd1cefb | 5023 | return 0; |
3f5285e8 JM |
5024 | } |
5025 | ||
5026 | ||
f3407c66 JM |
5027 | int wpa_driver_nl80211_set_mode(struct i802_bss *bss, |
5028 | enum nl80211_iftype nlmode) | |
3c5d34e3 CW |
5029 | { |
5030 | return wpa_driver_nl80211_set_mode_impl(bss, nlmode, NULL); | |
5031 | } | |
5032 | ||
5033 | ||
4ec68377 JD |
5034 | static int wpa_driver_nl80211_set_mode_ibss(struct i802_bss *bss, |
5035 | struct hostapd_freq_params *freq) | |
3c5d34e3 | 5036 | { |
3c5d34e3 | 5037 | return wpa_driver_nl80211_set_mode_impl(bss, NL80211_IFTYPE_ADHOC, |
4ec68377 | 5038 | freq); |
3c5d34e3 | 5039 | } |
65d645ce AS |
5040 | |
5041 | ||
3f5285e8 JM |
5042 | static int wpa_driver_nl80211_get_capa(void *priv, |
5043 | struct wpa_driver_capa *capa) | |
5044 | { | |
a2e40bb6 FF |
5045 | struct i802_bss *bss = priv; |
5046 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
65d645ce | 5047 | |
3f5285e8 JM |
5048 | if (!drv->has_capability) |
5049 | return -1; | |
5050 | os_memcpy(capa, &drv->capa, sizeof(*capa)); | |
8cd6b7bc JB |
5051 | if (drv->extended_capa && drv->extended_capa_mask) { |
5052 | capa->extended_capa = drv->extended_capa; | |
5053 | capa->extended_capa_mask = drv->extended_capa_mask; | |
5054 | capa->extended_capa_len = drv->extended_capa_len; | |
5055 | } | |
851b0c55 | 5056 | |
906bc4c7 | 5057 | return 0; |
3f5285e8 JM |
5058 | } |
5059 | ||
5060 | ||
5061 | static int wpa_driver_nl80211_set_operstate(void *priv, int state) | |
5062 | { | |
a2e40bb6 FF |
5063 | struct i802_bss *bss = priv; |
5064 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
3f5285e8 | 5065 | |
90a545cc JM |
5066 | wpa_printf(MSG_DEBUG, "nl80211: Set %s operstate %d->%d (%s)", |
5067 | bss->ifname, drv->operstate, state, | |
5068 | state ? "UP" : "DORMANT"); | |
3f5285e8 | 5069 | drv->operstate = state; |
36d84860 | 5070 | return netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, -1, |
e2d02c29 | 5071 | state ? IF_OPER_UP : IF_OPER_DORMANT); |
3f5285e8 JM |
5072 | } |
5073 | ||
01652550 JM |
5074 | |
5075 | static int wpa_driver_nl80211_set_supp_port(void *priv, int authorized) | |
5076 | { | |
a2e40bb6 FF |
5077 | struct i802_bss *bss = priv; |
5078 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
01652550 JM |
5079 | struct nl_msg *msg; |
5080 | struct nl80211_sta_flag_update upd; | |
a862e4a3 | 5081 | int ret; |
2eef5177 JM |
5082 | |
5083 | if (!drv->associated && is_zero_ether_addr(drv->bssid) && !authorized) { | |
5084 | wpa_printf(MSG_DEBUG, "nl80211: Skip set_supp_port(unauthorized) while not associated"); | |
5085 | return 0; | |
5086 | } | |
01652550 | 5087 | |
1ba51ec0 JM |
5088 | wpa_printf(MSG_DEBUG, "nl80211: Set supplicant port %sauthorized for " |
5089 | MACSTR, authorized ? "" : "un", MAC2STR(drv->bssid)); | |
5090 | ||
01652550 JM |
5091 | os_memset(&upd, 0, sizeof(upd)); |
5092 | upd.mask = BIT(NL80211_STA_FLAG_AUTHORIZED); | |
5093 | if (authorized) | |
5094 | upd.set = BIT(NL80211_STA_FLAG_AUTHORIZED); | |
a862e4a3 | 5095 | |
13f83980 | 5096 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) || |
a862e4a3 JM |
5097 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, drv->bssid) || |
5098 | nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd)) { | |
5099 | nlmsg_free(msg); | |
5100 | return -ENOBUFS; | |
5101 | } | |
01652550 | 5102 | |
2eef5177 | 5103 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
2eef5177 JM |
5104 | if (!ret) |
5105 | return 0; | |
2eef5177 JM |
5106 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set STA flag: %d (%s)", |
5107 | ret, strerror(-ret)); | |
5108 | return ret; | |
01652550 JM |
5109 | } |
5110 | ||
3f5285e8 | 5111 | |
f07ead6a JM |
5112 | /* Set kernel driver on given frequency (MHz) */ |
5113 | static int i802_set_freq(void *priv, struct hostapd_freq_params *freq) | |
c5121837 | 5114 | { |
f07ead6a | 5115 | struct i802_bss *bss = priv; |
13a524a3 | 5116 | return nl80211_set_channel(bss, freq, 0); |
c5121837 JM |
5117 | } |
5118 | ||
f7b3920c | 5119 | |
c5121837 JM |
5120 | static inline int min_int(int a, int b) |
5121 | { | |
5122 | if (a < b) | |
5123 | return a; | |
5124 | return b; | |
5125 | } | |
5126 | ||
5127 | ||
5128 | static int get_key_handler(struct nl_msg *msg, void *arg) | |
5129 | { | |
5130 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
5131 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
5132 | ||
5133 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
5134 | genlmsg_attrlen(gnlh, 0), NULL); | |
5135 | ||
5136 | /* | |
5137 | * TODO: validate the key index and mac address! | |
5138 | * Otherwise, there's a race condition as soon as | |
5139 | * the kernel starts sending key notifications. | |
5140 | */ | |
5141 | ||
5142 | if (tb[NL80211_ATTR_KEY_SEQ]) | |
5143 | memcpy(arg, nla_data(tb[NL80211_ATTR_KEY_SEQ]), | |
5144 | min_int(nla_len(tb[NL80211_ATTR_KEY_SEQ]), 6)); | |
5145 | return NL_SKIP; | |
5146 | } | |
5147 | ||
5148 | ||
5149 | static int i802_get_seqnum(const char *iface, void *priv, const u8 *addr, | |
5150 | int idx, u8 *seq) | |
5151 | { | |
a2e40bb6 FF |
5152 | struct i802_bss *bss = priv; |
5153 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
c5121837 JM |
5154 | struct nl_msg *msg; |
5155 | ||
95376e1a JM |
5156 | msg = nl80211_ifindex_msg(drv, if_nametoindex(iface), 0, |
5157 | NL80211_CMD_GET_KEY); | |
5158 | if (!msg || | |
a862e4a3 | 5159 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
95376e1a | 5160 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, idx)) { |
a862e4a3 JM |
5161 | nlmsg_free(msg); |
5162 | return -ENOBUFS; | |
5163 | } | |
c5121837 JM |
5164 | |
5165 | memset(seq, 0, 6); | |
5166 | ||
5167 | return send_and_recv_msgs(drv, msg, get_key_handler, seq); | |
c5121837 JM |
5168 | } |
5169 | ||
5170 | ||
c5121837 JM |
5171 | static int i802_set_rts(void *priv, int rts) |
5172 | { | |
a2e40bb6 FF |
5173 | struct i802_bss *bss = priv; |
5174 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
ad649451 | 5175 | struct nl_msg *msg; |
a862e4a3 | 5176 | int ret; |
ad649451 | 5177 | u32 val; |
c5121837 | 5178 | |
ad649451 JM |
5179 | if (rts >= 2347) |
5180 | val = (u32) -1; | |
5181 | else | |
5182 | val = rts; | |
c5121837 | 5183 | |
9725b784 | 5184 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_WIPHY)) || |
a862e4a3 JM |
5185 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, val)) { |
5186 | nlmsg_free(msg); | |
5187 | return -ENOBUFS; | |
5188 | } | |
ad649451 JM |
5189 | |
5190 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
5191 | if (!ret) | |
5192 | return 0; | |
ad649451 JM |
5193 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set RTS threshold %d: " |
5194 | "%d (%s)", rts, ret, strerror(-ret)); | |
5195 | return ret; | |
c5121837 JM |
5196 | } |
5197 | ||
5198 | ||
5199 | static int i802_set_frag(void *priv, int frag) | |
5200 | { | |
a2e40bb6 FF |
5201 | struct i802_bss *bss = priv; |
5202 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
ad649451 | 5203 | struct nl_msg *msg; |
a862e4a3 | 5204 | int ret; |
ad649451 | 5205 | u32 val; |
c5121837 | 5206 | |
ad649451 JM |
5207 | if (frag >= 2346) |
5208 | val = (u32) -1; | |
5209 | else | |
5210 | val = frag; | |
c5121837 | 5211 | |
9725b784 | 5212 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_WIPHY)) || |
a862e4a3 JM |
5213 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, val)) { |
5214 | nlmsg_free(msg); | |
5215 | return -ENOBUFS; | |
5216 | } | |
ad649451 JM |
5217 | |
5218 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
5219 | if (!ret) | |
5220 | return 0; | |
ad649451 JM |
5221 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set fragmentation threshold " |
5222 | "%d: %d (%s)", frag, ret, strerror(-ret)); | |
5223 | return ret; | |
c5121837 JM |
5224 | } |
5225 | ||
5226 | ||
c5121837 JM |
5227 | static int i802_flush(void *priv) |
5228 | { | |
a2e40bb6 | 5229 | struct i802_bss *bss = priv; |
c5121837 | 5230 | struct nl_msg *msg; |
82554b10 | 5231 | int res; |
c5121837 | 5232 | |
83e7bb0e JM |
5233 | wpa_printf(MSG_DEBUG, "nl80211: flush -> DEL_STATION %s (all)", |
5234 | bss->ifname); | |
c5121837 JM |
5235 | |
5236 | /* | |
5237 | * XXX: FIX! this needs to flush all VLANs too | |
5238 | */ | |
13f83980 JM |
5239 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_DEL_STATION); |
5240 | res = send_and_recv_msgs(bss->drv, msg, NULL, NULL); | |
82554b10 JM |
5241 | if (res) { |
5242 | wpa_printf(MSG_DEBUG, "nl80211: Station flush failed: ret=%d " | |
5243 | "(%s)", res, strerror(-res)); | |
5244 | } | |
5245 | return res; | |
c5121837 JM |
5246 | } |
5247 | ||
5248 | ||
5249 | static int get_sta_handler(struct nl_msg *msg, void *arg) | |
5250 | { | |
5251 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
5252 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
5253 | struct hostap_sta_driver_data *data = arg; | |
5254 | struct nlattr *stats[NL80211_STA_INFO_MAX + 1]; | |
5255 | static struct nla_policy stats_policy[NL80211_STA_INFO_MAX + 1] = { | |
5256 | [NL80211_STA_INFO_INACTIVE_TIME] = { .type = NLA_U32 }, | |
5257 | [NL80211_STA_INFO_RX_BYTES] = { .type = NLA_U32 }, | |
5258 | [NL80211_STA_INFO_TX_BYTES] = { .type = NLA_U32 }, | |
5259 | [NL80211_STA_INFO_RX_PACKETS] = { .type = NLA_U32 }, | |
5260 | [NL80211_STA_INFO_TX_PACKETS] = { .type = NLA_U32 }, | |
dc7785f8 | 5261 | [NL80211_STA_INFO_TX_FAILED] = { .type = NLA_U32 }, |
c5121837 JM |
5262 | }; |
5263 | ||
5264 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
5265 | genlmsg_attrlen(gnlh, 0), NULL); | |
5266 | ||
5267 | /* | |
5268 | * TODO: validate the interface and mac address! | |
5269 | * Otherwise, there's a race condition as soon as | |
5270 | * the kernel starts sending station notifications. | |
5271 | */ | |
5272 | ||
5273 | if (!tb[NL80211_ATTR_STA_INFO]) { | |
5274 | wpa_printf(MSG_DEBUG, "sta stats missing!"); | |
5275 | return NL_SKIP; | |
5276 | } | |
5277 | if (nla_parse_nested(stats, NL80211_STA_INFO_MAX, | |
5278 | tb[NL80211_ATTR_STA_INFO], | |
5279 | stats_policy)) { | |
5280 | wpa_printf(MSG_DEBUG, "failed to parse nested attributes!"); | |
5281 | return NL_SKIP; | |
5282 | } | |
5283 | ||
5284 | if (stats[NL80211_STA_INFO_INACTIVE_TIME]) | |
5285 | data->inactive_msec = | |
5286 | nla_get_u32(stats[NL80211_STA_INFO_INACTIVE_TIME]); | |
5287 | if (stats[NL80211_STA_INFO_RX_BYTES]) | |
5288 | data->rx_bytes = nla_get_u32(stats[NL80211_STA_INFO_RX_BYTES]); | |
5289 | if (stats[NL80211_STA_INFO_TX_BYTES]) | |
5290 | data->tx_bytes = nla_get_u32(stats[NL80211_STA_INFO_TX_BYTES]); | |
5291 | if (stats[NL80211_STA_INFO_RX_PACKETS]) | |
5292 | data->rx_packets = | |
5293 | nla_get_u32(stats[NL80211_STA_INFO_RX_PACKETS]); | |
5294 | if (stats[NL80211_STA_INFO_TX_PACKETS]) | |
5295 | data->tx_packets = | |
5296 | nla_get_u32(stats[NL80211_STA_INFO_TX_PACKETS]); | |
dc7785f8 YZ |
5297 | if (stats[NL80211_STA_INFO_TX_FAILED]) |
5298 | data->tx_retry_failed = | |
5299 | nla_get_u32(stats[NL80211_STA_INFO_TX_FAILED]); | |
c5121837 JM |
5300 | |
5301 | return NL_SKIP; | |
5302 | } | |
5303 | ||
9ebce9c5 JM |
5304 | static int i802_read_sta_data(struct i802_bss *bss, |
5305 | struct hostap_sta_driver_data *data, | |
c5121837 JM |
5306 | const u8 *addr) |
5307 | { | |
c5121837 JM |
5308 | struct nl_msg *msg; |
5309 | ||
5310 | os_memset(data, 0, sizeof(*data)); | |
c5121837 | 5311 | |
13f83980 JM |
5312 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_GET_STATION)) || |
5313 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { | |
a862e4a3 JM |
5314 | nlmsg_free(msg); |
5315 | return -ENOBUFS; | |
5316 | } | |
c5121837 | 5317 | |
13f83980 | 5318 | return send_and_recv_msgs(bss->drv, msg, get_sta_handler, data); |
c5121837 JM |
5319 | } |
5320 | ||
5321 | ||
c5121837 JM |
5322 | static int i802_set_tx_queue_params(void *priv, int queue, int aifs, |
5323 | int cw_min, int cw_max, int burst_time) | |
5324 | { | |
a2e40bb6 FF |
5325 | struct i802_bss *bss = priv; |
5326 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
c5121837 JM |
5327 | struct nl_msg *msg; |
5328 | struct nlattr *txq, *params; | |
5329 | ||
13f83980 | 5330 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_WIPHY); |
c5121837 JM |
5331 | if (!msg) |
5332 | return -1; | |
5333 | ||
c5121837 JM |
5334 | txq = nla_nest_start(msg, NL80211_ATTR_WIPHY_TXQ_PARAMS); |
5335 | if (!txq) | |
a862e4a3 | 5336 | goto fail; |
c5121837 JM |
5337 | |
5338 | /* We are only sending parameters for a single TXQ at a time */ | |
5339 | params = nla_nest_start(msg, 1); | |
5340 | if (!params) | |
a862e4a3 | 5341 | goto fail; |
c5121837 | 5342 | |
7e3c1781 JM |
5343 | switch (queue) { |
5344 | case 0: | |
a862e4a3 JM |
5345 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_VO)) |
5346 | goto fail; | |
7e3c1781 JM |
5347 | break; |
5348 | case 1: | |
a862e4a3 JM |
5349 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_VI)) |
5350 | goto fail; | |
7e3c1781 JM |
5351 | break; |
5352 | case 2: | |
a862e4a3 JM |
5353 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_BE)) |
5354 | goto fail; | |
7e3c1781 JM |
5355 | break; |
5356 | case 3: | |
a862e4a3 JM |
5357 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_BK)) |
5358 | goto fail; | |
7e3c1781 JM |
5359 | break; |
5360 | } | |
c5121837 JM |
5361 | /* Burst time is configured in units of 0.1 msec and TXOP parameter in |
5362 | * 32 usec, so need to convert the value here. */ | |
a862e4a3 JM |
5363 | if (nla_put_u16(msg, NL80211_TXQ_ATTR_TXOP, |
5364 | (burst_time * 100 + 16) / 32) || | |
5365 | nla_put_u16(msg, NL80211_TXQ_ATTR_CWMIN, cw_min) || | |
5366 | nla_put_u16(msg, NL80211_TXQ_ATTR_CWMAX, cw_max) || | |
5367 | nla_put_u8(msg, NL80211_TXQ_ATTR_AIFS, aifs)) | |
5368 | goto fail; | |
c5121837 JM |
5369 | |
5370 | nla_nest_end(msg, params); | |
5371 | ||
5372 | nla_nest_end(msg, txq); | |
5373 | ||
5374 | if (send_and_recv_msgs(drv, msg, NULL, NULL) == 0) | |
5375 | return 0; | |
9e088e74 | 5376 | msg = NULL; |
a862e4a3 | 5377 | fail: |
9e088e74 | 5378 | nlmsg_free(msg); |
c5121837 JM |
5379 | return -1; |
5380 | } | |
5381 | ||
5382 | ||
9ebce9c5 | 5383 | static int i802_set_sta_vlan(struct i802_bss *bss, const u8 *addr, |
c5121837 JM |
5384 | const char *ifname, int vlan_id) |
5385 | { | |
a2e40bb6 | 5386 | struct wpa_driver_nl80211_data *drv = bss->drv; |
c5121837 | 5387 | struct nl_msg *msg; |
a862e4a3 | 5388 | int ret; |
c5121837 | 5389 | |
bbc706a3 JM |
5390 | wpa_printf(MSG_DEBUG, "nl80211: %s[%d]: set_sta_vlan(" MACSTR |
5391 | ", ifname=%s[%d], vlan_id=%d)", | |
5392 | bss->ifname, if_nametoindex(bss->ifname), | |
5393 | MAC2STR(addr), ifname, if_nametoindex(ifname), vlan_id); | |
13f83980 | 5394 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) || |
a862e4a3 JM |
5395 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
5396 | nla_put_u32(msg, NL80211_ATTR_STA_VLAN, if_nametoindex(ifname))) { | |
5397 | nlmsg_free(msg); | |
5398 | return -ENOBUFS; | |
5399 | } | |
c5121837 | 5400 | |
cd1d72c1 JM |
5401 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
5402 | if (ret < 0) { | |
5403 | wpa_printf(MSG_ERROR, "nl80211: NL80211_ATTR_STA_VLAN (addr=" | |
5404 | MACSTR " ifname=%s vlan_id=%d) failed: %d (%s)", | |
5405 | MAC2STR(addr), ifname, vlan_id, ret, | |
5406 | strerror(-ret)); | |
5407 | } | |
cd1d72c1 | 5408 | return ret; |
c5121837 JM |
5409 | } |
5410 | ||
fbbfcbac | 5411 | |
c5121837 JM |
5412 | static int i802_get_inact_sec(void *priv, const u8 *addr) |
5413 | { | |
5414 | struct hostap_sta_driver_data data; | |
5415 | int ret; | |
5416 | ||
5417 | data.inactive_msec = (unsigned long) -1; | |
5418 | ret = i802_read_sta_data(priv, &data, addr); | |
b9749bac MH |
5419 | if (ret == -ENOENT) |
5420 | return -ENOENT; | |
c5121837 JM |
5421 | if (ret || data.inactive_msec == (unsigned long) -1) |
5422 | return -1; | |
5423 | return data.inactive_msec / 1000; | |
5424 | } | |
5425 | ||
5426 | ||
5427 | static int i802_sta_clear_stats(void *priv, const u8 *addr) | |
5428 | { | |
5429 | #if 0 | |
5430 | /* TODO */ | |
5431 | #endif | |
5432 | return 0; | |
5433 | } | |
5434 | ||
5435 | ||
731723a5 JM |
5436 | static int i802_sta_deauth(void *priv, const u8 *own_addr, const u8 *addr, |
5437 | int reason) | |
c5121837 | 5438 | { |
a2e40bb6 | 5439 | struct i802_bss *bss = priv; |
e1bd4e19 | 5440 | struct wpa_driver_nl80211_data *drv = bss->drv; |
c5121837 JM |
5441 | struct ieee80211_mgmt mgmt; |
5442 | ||
0d391b03 BC |
5443 | if (is_mesh_interface(drv->nlmode)) |
5444 | return -1; | |
5445 | ||
e1bd4e19 | 5446 | if (drv->device_ap_sme) |
59d7148a | 5447 | return wpa_driver_nl80211_sta_remove(bss, addr, 1, reason); |
e1bd4e19 | 5448 | |
c5121837 JM |
5449 | memset(&mgmt, 0, sizeof(mgmt)); |
5450 | mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, | |
5451 | WLAN_FC_STYPE_DEAUTH); | |
5452 | memcpy(mgmt.da, addr, ETH_ALEN); | |
731723a5 JM |
5453 | memcpy(mgmt.sa, own_addr, ETH_ALEN); |
5454 | memcpy(mgmt.bssid, own_addr, ETH_ALEN); | |
c5121837 | 5455 | mgmt.u.deauth.reason_code = host_to_le16(reason); |
a2e40bb6 | 5456 | return wpa_driver_nl80211_send_mlme(bss, (u8 *) &mgmt, |
9f324b61 | 5457 | IEEE80211_HDRLEN + |
9ebce9c5 | 5458 | sizeof(mgmt.u.deauth), 0, 0, 0, 0, |
2d3943ce | 5459 | 0, NULL, 0); |
c5121837 JM |
5460 | } |
5461 | ||
5462 | ||
731723a5 JM |
5463 | static int i802_sta_disassoc(void *priv, const u8 *own_addr, const u8 *addr, |
5464 | int reason) | |
c5121837 | 5465 | { |
a2e40bb6 | 5466 | struct i802_bss *bss = priv; |
e1bd4e19 | 5467 | struct wpa_driver_nl80211_data *drv = bss->drv; |
c5121837 JM |
5468 | struct ieee80211_mgmt mgmt; |
5469 | ||
0d391b03 BC |
5470 | if (is_mesh_interface(drv->nlmode)) |
5471 | return -1; | |
5472 | ||
e1bd4e19 | 5473 | if (drv->device_ap_sme) |
59d7148a | 5474 | return wpa_driver_nl80211_sta_remove(bss, addr, 0, reason); |
e1bd4e19 | 5475 | |
c5121837 JM |
5476 | memset(&mgmt, 0, sizeof(mgmt)); |
5477 | mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, | |
5478 | WLAN_FC_STYPE_DISASSOC); | |
5479 | memcpy(mgmt.da, addr, ETH_ALEN); | |
731723a5 JM |
5480 | memcpy(mgmt.sa, own_addr, ETH_ALEN); |
5481 | memcpy(mgmt.bssid, own_addr, ETH_ALEN); | |
c5121837 | 5482 | mgmt.u.disassoc.reason_code = host_to_le16(reason); |
a2e40bb6 | 5483 | return wpa_driver_nl80211_send_mlme(bss, (u8 *) &mgmt, |
9f324b61 | 5484 | IEEE80211_HDRLEN + |
9ebce9c5 | 5485 | sizeof(mgmt.u.disassoc), 0, 0, 0, 0, |
2d3943ce | 5486 | 0, NULL, 0); |
c5121837 JM |
5487 | } |
5488 | ||
5489 | ||
9b4d9c8b JM |
5490 | static void dump_ifidx(struct wpa_driver_nl80211_data *drv) |
5491 | { | |
5492 | char buf[200], *pos, *end; | |
5493 | int i, res; | |
5494 | ||
5495 | pos = buf; | |
5496 | end = pos + sizeof(buf); | |
5497 | ||
5498 | for (i = 0; i < drv->num_if_indices; i++) { | |
5499 | if (!drv->if_indices[i]) | |
5500 | continue; | |
5501 | res = os_snprintf(pos, end - pos, " %d", drv->if_indices[i]); | |
d85e1fc8 | 5502 | if (os_snprintf_error(end - pos, res)) |
9b4d9c8b JM |
5503 | break; |
5504 | pos += res; | |
5505 | } | |
5506 | *pos = '\0'; | |
5507 | ||
5508 | wpa_printf(MSG_DEBUG, "nl80211: if_indices[%d]:%s", | |
5509 | drv->num_if_indices, buf); | |
5510 | } | |
5511 | ||
5512 | ||
f07ead6a JM |
5513 | static void add_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx) |
5514 | { | |
5515 | int i; | |
5516 | int *old; | |
5517 | ||
5518 | wpa_printf(MSG_DEBUG, "nl80211: Add own interface ifindex %d", | |
5519 | ifidx); | |
b36935be MB |
5520 | if (have_ifidx(drv, ifidx)) { |
5521 | wpa_printf(MSG_DEBUG, "nl80211: ifindex %d already in the list", | |
5522 | ifidx); | |
5523 | return; | |
5524 | } | |
f07ead6a JM |
5525 | for (i = 0; i < drv->num_if_indices; i++) { |
5526 | if (drv->if_indices[i] == 0) { | |
5527 | drv->if_indices[i] = ifidx; | |
9b4d9c8b | 5528 | dump_ifidx(drv); |
f07ead6a JM |
5529 | return; |
5530 | } | |
5531 | } | |
5532 | ||
5533 | if (drv->if_indices != drv->default_if_indices) | |
5534 | old = drv->if_indices; | |
5535 | else | |
5536 | old = NULL; | |
5537 | ||
067ffa26 JM |
5538 | drv->if_indices = os_realloc_array(old, drv->num_if_indices + 1, |
5539 | sizeof(int)); | |
f07ead6a JM |
5540 | if (!drv->if_indices) { |
5541 | if (!old) | |
5542 | drv->if_indices = drv->default_if_indices; | |
5543 | else | |
5544 | drv->if_indices = old; | |
5545 | wpa_printf(MSG_ERROR, "Failed to reallocate memory for " | |
5546 | "interfaces"); | |
5547 | wpa_printf(MSG_ERROR, "Ignoring EAPOL on interface %d", ifidx); | |
5548 | return; | |
5549 | } else if (!old) | |
5550 | os_memcpy(drv->if_indices, drv->default_if_indices, | |
5551 | sizeof(drv->default_if_indices)); | |
5552 | drv->if_indices[drv->num_if_indices] = ifidx; | |
5553 | drv->num_if_indices++; | |
9b4d9c8b | 5554 | dump_ifidx(drv); |
f07ead6a JM |
5555 | } |
5556 | ||
5557 | ||
5558 | static void del_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx) | |
5559 | { | |
5560 | int i; | |
5561 | ||
5562 | for (i = 0; i < drv->num_if_indices; i++) { | |
5563 | if (drv->if_indices[i] == ifidx) { | |
5564 | drv->if_indices[i] = 0; | |
5565 | break; | |
5566 | } | |
5567 | } | |
9b4d9c8b | 5568 | dump_ifidx(drv); |
f07ead6a JM |
5569 | } |
5570 | ||
5571 | ||
5572 | static int have_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx) | |
5573 | { | |
5574 | int i; | |
5575 | ||
5576 | for (i = 0; i < drv->num_if_indices; i++) | |
5577 | if (drv->if_indices[i] == ifidx) | |
5578 | return 1; | |
5579 | ||
5580 | return 0; | |
5581 | } | |
5582 | ||
5583 | ||
5584 | static int i802_set_wds_sta(void *priv, const u8 *addr, int aid, int val, | |
0e80ea2c | 5585 | const char *bridge_ifname, char *ifname_wds) |
f07ead6a JM |
5586 | { |
5587 | struct i802_bss *bss = priv; | |
5588 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
5589 | char name[IFNAMSIZ + 1]; | |
5590 | ||
5591 | os_snprintf(name, sizeof(name), "%s.sta%d", bss->ifname, aid); | |
69dd2967 SM |
5592 | if (ifname_wds) |
5593 | os_strlcpy(ifname_wds, name, IFNAMSIZ + 1); | |
5594 | ||
f07ead6a JM |
5595 | wpa_printf(MSG_DEBUG, "nl80211: Set WDS STA addr=" MACSTR |
5596 | " aid=%d val=%d name=%s", MAC2STR(addr), aid, val, name); | |
5597 | if (val) { | |
5598 | if (!if_nametoindex(name)) { | |
5599 | if (nl80211_create_iface(drv, name, | |
5600 | NL80211_IFTYPE_AP_VLAN, | |
2aec4f3c JM |
5601 | bss->addr, 1, NULL, NULL, 0) < |
5602 | 0) | |
f07ead6a JM |
5603 | return -1; |
5604 | if (bridge_ifname && | |
c81eff1a BG |
5605 | linux_br_add_if(drv->global->ioctl_sock, |
5606 | bridge_ifname, name) < 0) | |
f07ead6a JM |
5607 | return -1; |
5608 | } | |
75227f3a JM |
5609 | if (linux_set_iface_flags(drv->global->ioctl_sock, name, 1)) { |
5610 | wpa_printf(MSG_ERROR, "nl80211: Failed to set WDS STA " | |
5611 | "interface %s up", name); | |
5612 | } | |
f07ead6a JM |
5613 | return i802_set_sta_vlan(priv, addr, name, 0); |
5614 | } else { | |
c34e618d FF |
5615 | if (bridge_ifname) |
5616 | linux_br_del_if(drv->global->ioctl_sock, bridge_ifname, | |
5617 | name); | |
5618 | ||
f07ead6a | 5619 | i802_set_sta_vlan(priv, addr, bss->ifname, 0); |
d0595b25 FF |
5620 | nl80211_remove_iface(drv, if_nametoindex(name)); |
5621 | return 0; | |
f07ead6a JM |
5622 | } |
5623 | } | |
5624 | ||
5625 | ||
5626 | static void handle_eapol(int sock, void *eloop_ctx, void *sock_ctx) | |
5627 | { | |
5628 | struct wpa_driver_nl80211_data *drv = eloop_ctx; | |
5629 | struct sockaddr_ll lladdr; | |
5630 | unsigned char buf[3000]; | |
5631 | int len; | |
5632 | socklen_t fromlen = sizeof(lladdr); | |
5633 | ||
5634 | len = recvfrom(sock, buf, sizeof(buf), 0, | |
5635 | (struct sockaddr *)&lladdr, &fromlen); | |
5636 | if (len < 0) { | |
7ac3616d JM |
5637 | wpa_printf(MSG_ERROR, "nl80211: EAPOL recv failed: %s", |
5638 | strerror(errno)); | |
f07ead6a JM |
5639 | return; |
5640 | } | |
5641 | ||
5642 | if (have_ifidx(drv, lladdr.sll_ifindex)) | |
5643 | drv_event_eapol_rx(drv->ctx, lladdr.sll_addr, buf, len); | |
5644 | } | |
5645 | ||
5646 | ||
94627f6c | 5647 | static int i802_check_bridge(struct wpa_driver_nl80211_data *drv, |
e17a2477 | 5648 | struct i802_bss *bss, |
94627f6c JM |
5649 | const char *brname, const char *ifname) |
5650 | { | |
6c6678e7 | 5651 | int br_ifindex; |
94627f6c JM |
5652 | char in_br[IFNAMSIZ]; |
5653 | ||
e17a2477 | 5654 | os_strlcpy(bss->brname, brname, IFNAMSIZ); |
6c6678e7 | 5655 | br_ifindex = if_nametoindex(brname); |
6c6678e7 | 5656 | if (br_ifindex == 0) { |
94627f6c JM |
5657 | /* |
5658 | * Bridge was configured, but the bridge device does | |
5659 | * not exist. Try to add it now. | |
5660 | */ | |
c81eff1a | 5661 | if (linux_br_add(drv->global->ioctl_sock, brname) < 0) { |
94627f6c JM |
5662 | wpa_printf(MSG_ERROR, "nl80211: Failed to add the " |
5663 | "bridge interface %s: %s", | |
5664 | brname, strerror(errno)); | |
5665 | return -1; | |
5666 | } | |
e17a2477 | 5667 | bss->added_bridge = 1; |
8997613c JM |
5668 | br_ifindex = if_nametoindex(brname); |
5669 | add_ifidx(drv, br_ifindex); | |
94627f6c | 5670 | } |
8997613c | 5671 | bss->br_ifindex = br_ifindex; |
94627f6c JM |
5672 | |
5673 | if (linux_br_get(in_br, ifname) == 0) { | |
5674 | if (os_strcmp(in_br, brname) == 0) | |
5675 | return 0; /* already in the bridge */ | |
5676 | ||
5677 | wpa_printf(MSG_DEBUG, "nl80211: Removing interface %s from " | |
5678 | "bridge %s", ifname, in_br); | |
c81eff1a BG |
5679 | if (linux_br_del_if(drv->global->ioctl_sock, in_br, ifname) < |
5680 | 0) { | |
94627f6c JM |
5681 | wpa_printf(MSG_ERROR, "nl80211: Failed to " |
5682 | "remove interface %s from bridge " | |
5683 | "%s: %s", | |
5684 | ifname, brname, strerror(errno)); | |
5685 | return -1; | |
5686 | } | |
5687 | } | |
5688 | ||
5689 | wpa_printf(MSG_DEBUG, "nl80211: Adding interface %s into bridge %s", | |
5690 | ifname, brname); | |
c81eff1a | 5691 | if (linux_br_add_if(drv->global->ioctl_sock, brname, ifname) < 0) { |
94627f6c JM |
5692 | wpa_printf(MSG_ERROR, "nl80211: Failed to add interface %s " |
5693 | "into bridge %s: %s", | |
5694 | ifname, brname, strerror(errno)); | |
5695 | return -1; | |
5696 | } | |
e17a2477 | 5697 | bss->added_if_into_bridge = 1; |
94627f6c JM |
5698 | |
5699 | return 0; | |
5700 | } | |
5701 | ||
5702 | ||
92f475b4 JM |
5703 | static void *i802_init(struct hostapd_data *hapd, |
5704 | struct wpa_init_params *params) | |
c5121837 JM |
5705 | { |
5706 | struct wpa_driver_nl80211_data *drv; | |
a2e40bb6 | 5707 | struct i802_bss *bss; |
c5121837 | 5708 | size_t i; |
cb05808c AN |
5709 | char master_ifname[IFNAMSIZ]; |
5710 | int ifindex, br_ifindex = 0; | |
94627f6c | 5711 | int br_added = 0; |
c5121837 | 5712 | |
0d547d5f JM |
5713 | bss = wpa_driver_nl80211_drv_init(hapd, params->ifname, |
5714 | params->global_priv, 1, | |
0ecff8d7 | 5715 | params->bssid, params->driver_params); |
a2e40bb6 | 5716 | if (bss == NULL) |
c5121837 | 5717 | return NULL; |
c5121837 | 5718 | |
a2e40bb6 | 5719 | drv = bss->drv; |
7635bfb0 | 5720 | |
cb05808c | 5721 | if (linux_br_get(master_ifname, params->ifname) == 0) { |
94627f6c | 5722 | wpa_printf(MSG_DEBUG, "nl80211: Interface %s is in bridge %s", |
cb05808c AN |
5723 | params->ifname, master_ifname); |
5724 | br_ifindex = if_nametoindex(master_ifname); | |
5725 | os_strlcpy(bss->brname, master_ifname, IFNAMSIZ); | |
5726 | } else if ((params->num_bridge == 0 || !params->bridge[0]) && | |
5727 | linux_master_get(master_ifname, params->ifname) == 0) { | |
5728 | wpa_printf(MSG_DEBUG, "nl80211: Interface %s is in master %s", | |
5729 | params->ifname, master_ifname); | |
5730 | /* start listening for EAPOL on the master interface */ | |
5731 | add_ifidx(drv, if_nametoindex(master_ifname)); | |
94627f6c | 5732 | } else { |
cb05808c | 5733 | master_ifname[0] = '\0'; |
94627f6c | 5734 | } |
cb05808c | 5735 | |
6c6678e7 | 5736 | bss->br_ifindex = br_ifindex; |
94627f6c | 5737 | |
92f475b4 | 5738 | for (i = 0; i < params->num_bridge; i++) { |
94627f6c JM |
5739 | if (params->bridge[i]) { |
5740 | ifindex = if_nametoindex(params->bridge[i]); | |
5741 | if (ifindex) | |
5742 | add_ifidx(drv, ifindex); | |
5743 | if (ifindex == br_ifindex) | |
5744 | br_added = 1; | |
5745 | } | |
c5121837 | 5746 | } |
c5121837 | 5747 | |
ad1e68e6 JM |
5748 | /* start listening for EAPOL on the default AP interface */ |
5749 | add_ifidx(drv, drv->ifindex); | |
5750 | ||
5ef8e39f JM |
5751 | if (params->num_bridge && params->bridge[0]) { |
5752 | if (i802_check_bridge(drv, bss, params->bridge[0], | |
5753 | params->ifname) < 0) | |
5754 | goto failed; | |
cb05808c | 5755 | if (os_strcmp(params->bridge[0], master_ifname) != 0) |
5ef8e39f JM |
5756 | br_added = 1; |
5757 | } | |
5758 | ||
5759 | if (!br_added && br_ifindex && | |
5760 | (params->num_bridge == 0 || !params->bridge[0])) | |
5761 | add_ifidx(drv, br_ifindex); | |
94627f6c | 5762 | |
97ed9a06 KP |
5763 | #ifdef CONFIG_LIBNL3_ROUTE |
5764 | if (bss->added_if_into_bridge) { | |
5765 | drv->rtnl_sk = nl_socket_alloc(); | |
5766 | if (drv->rtnl_sk == NULL) { | |
5767 | wpa_printf(MSG_ERROR, "nl80211: Failed to allocate nl_sock"); | |
5768 | goto failed; | |
5769 | } | |
5770 | ||
5771 | if (nl_connect(drv->rtnl_sk, NETLINK_ROUTE)) { | |
5772 | wpa_printf(MSG_ERROR, "nl80211: Failed to connect nl_sock to NETLINK_ROUTE: %s", | |
5773 | strerror(errno)); | |
5774 | goto failed; | |
5775 | } | |
5776 | } | |
5777 | #endif /* CONFIG_LIBNL3_ROUTE */ | |
5778 | ||
ad1e68e6 JM |
5779 | drv->eapol_sock = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_PAE)); |
5780 | if (drv->eapol_sock < 0) { | |
7ac3616d JM |
5781 | wpa_printf(MSG_ERROR, "nl80211: socket(PF_PACKET, SOCK_DGRAM, ETH_P_PAE) failed: %s", |
5782 | strerror(errno)); | |
bbaf0837 | 5783 | goto failed; |
ad1e68e6 JM |
5784 | } |
5785 | ||
5786 | if (eloop_register_read_sock(drv->eapol_sock, handle_eapol, drv, NULL)) | |
5787 | { | |
7ac3616d | 5788 | wpa_printf(MSG_INFO, "nl80211: Could not register read socket for eapol"); |
c5121837 | 5789 | goto failed; |
ad1e68e6 JM |
5790 | } |
5791 | ||
c81eff1a BG |
5792 | if (linux_get_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
5793 | params->own_addr)) | |
bbaf0837 | 5794 | goto failed; |
fee354c7 | 5795 | os_memcpy(drv->perm_addr, params->own_addr, ETH_ALEN); |
c5121837 | 5796 | |
341eebee JB |
5797 | memcpy(bss->addr, params->own_addr, ETH_ALEN); |
5798 | ||
a2e40bb6 | 5799 | return bss; |
c5121837 JM |
5800 | |
5801 | failed: | |
7635bfb0 | 5802 | wpa_driver_nl80211_deinit(bss); |
bbaf0837 JM |
5803 | return NULL; |
5804 | } | |
c5121837 | 5805 | |
c5121837 | 5806 | |
bbaf0837 JM |
5807 | static void i802_deinit(void *priv) |
5808 | { | |
9ebce9c5 JM |
5809 | struct i802_bss *bss = priv; |
5810 | wpa_driver_nl80211_deinit(bss); | |
c5121837 JM |
5811 | } |
5812 | ||
c5121837 | 5813 | |
22a7c9d7 JM |
5814 | static enum nl80211_iftype wpa_driver_nl80211_if_type( |
5815 | enum wpa_driver_if_type type) | |
5816 | { | |
5817 | switch (type) { | |
5818 | case WPA_IF_STATION: | |
9f51b113 | 5819 | return NL80211_IFTYPE_STATION; |
75bde05d JM |
5820 | case WPA_IF_P2P_CLIENT: |
5821 | case WPA_IF_P2P_GROUP: | |
9f51b113 | 5822 | return NL80211_IFTYPE_P2P_CLIENT; |
22a7c9d7 JM |
5823 | case WPA_IF_AP_VLAN: |
5824 | return NL80211_IFTYPE_AP_VLAN; | |
5825 | case WPA_IF_AP_BSS: | |
5826 | return NL80211_IFTYPE_AP; | |
9f51b113 JB |
5827 | case WPA_IF_P2P_GO: |
5828 | return NL80211_IFTYPE_P2P_GO; | |
7aad838c NS |
5829 | case WPA_IF_P2P_DEVICE: |
5830 | return NL80211_IFTYPE_P2P_DEVICE; | |
5b78493f MH |
5831 | case WPA_IF_MESH: |
5832 | return NL80211_IFTYPE_MESH_POINT; | |
98342208 AK |
5833 | default: |
5834 | return -1; | |
22a7c9d7 | 5835 | } |
22a7c9d7 JM |
5836 | } |
5837 | ||
5838 | ||
f2ed8023 JM |
5839 | static int nl80211_addr_in_use(struct nl80211_global *global, const u8 *addr) |
5840 | { | |
5841 | struct wpa_driver_nl80211_data *drv; | |
5842 | dl_list_for_each(drv, &global->interfaces, | |
5843 | struct wpa_driver_nl80211_data, list) { | |
834ee56f | 5844 | if (os_memcmp(addr, drv->first_bss->addr, ETH_ALEN) == 0) |
f2ed8023 JM |
5845 | return 1; |
5846 | } | |
5847 | return 0; | |
5848 | } | |
5849 | ||
5850 | ||
5b78493f | 5851 | static int nl80211_vif_addr(struct wpa_driver_nl80211_data *drv, u8 *new_addr) |
f2ed8023 JM |
5852 | { |
5853 | unsigned int idx; | |
5854 | ||
5855 | if (!drv->global) | |
5856 | return -1; | |
5857 | ||
834ee56f | 5858 | os_memcpy(new_addr, drv->first_bss->addr, ETH_ALEN); |
f2ed8023 | 5859 | for (idx = 0; idx < 64; idx++) { |
834ee56f | 5860 | new_addr[0] = drv->first_bss->addr[0] | 0x02; |
f2ed8023 JM |
5861 | new_addr[0] ^= idx << 2; |
5862 | if (!nl80211_addr_in_use(drv->global, new_addr)) | |
5863 | break; | |
5864 | } | |
5865 | if (idx == 64) | |
5866 | return -1; | |
5867 | ||
5b78493f | 5868 | wpa_printf(MSG_DEBUG, "nl80211: Assigned new virtual interface address " |
f2ed8023 JM |
5869 | MACSTR, MAC2STR(new_addr)); |
5870 | ||
5871 | return 0; | |
5872 | } | |
5873 | ||
5874 | ||
f632e483 AS |
5875 | struct wdev_info { |
5876 | u64 wdev_id; | |
5877 | int wdev_id_set; | |
5878 | u8 macaddr[ETH_ALEN]; | |
5879 | }; | |
5880 | ||
5881 | static int nl80211_wdev_handler(struct nl_msg *msg, void *arg) | |
e472e1b4 AS |
5882 | { |
5883 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
5884 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
f632e483 | 5885 | struct wdev_info *wi = arg; |
e472e1b4 AS |
5886 | |
5887 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
5888 | genlmsg_attrlen(gnlh, 0), NULL); | |
5889 | if (tb[NL80211_ATTR_WDEV]) { | |
f632e483 AS |
5890 | wi->wdev_id = nla_get_u64(tb[NL80211_ATTR_WDEV]); |
5891 | wi->wdev_id_set = 1; | |
e472e1b4 AS |
5892 | } |
5893 | ||
5894 | if (tb[NL80211_ATTR_MAC]) | |
f632e483 | 5895 | os_memcpy(wi->macaddr, nla_data(tb[NL80211_ATTR_MAC]), |
e472e1b4 AS |
5896 | ETH_ALEN); |
5897 | ||
5898 | return NL_SKIP; | |
5899 | } | |
5900 | ||
5901 | ||
7ab68865 | 5902 | static int wpa_driver_nl80211_if_add(void *priv, enum wpa_driver_if_type type, |
8043e725 | 5903 | const char *ifname, const u8 *addr, |
f3585c8a | 5904 | void *bss_ctx, void **drv_priv, |
e17a2477 | 5905 | char *force_ifname, u8 *if_addr, |
d8a3b66d AS |
5906 | const char *bridge, int use_existing, |
5907 | int setup_ap) | |
22a7c9d7 | 5908 | { |
e472e1b4 | 5909 | enum nl80211_iftype nlmode; |
a2e40bb6 FF |
5910 | struct i802_bss *bss = priv; |
5911 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
22a7c9d7 | 5912 | int ifidx; |
2aec4f3c | 5913 | int added = 1; |
22a7c9d7 | 5914 | |
f3585c8a JM |
5915 | if (addr) |
5916 | os_memcpy(if_addr, addr, ETH_ALEN); | |
e472e1b4 AS |
5917 | nlmode = wpa_driver_nl80211_if_type(type); |
5918 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) { | |
f632e483 AS |
5919 | struct wdev_info p2pdev_info; |
5920 | ||
5921 | os_memset(&p2pdev_info, 0, sizeof(p2pdev_info)); | |
e472e1b4 | 5922 | ifidx = nl80211_create_iface(drv, ifname, nlmode, addr, |
f632e483 | 5923 | 0, nl80211_wdev_handler, |
2aec4f3c | 5924 | &p2pdev_info, use_existing); |
f632e483 | 5925 | if (!p2pdev_info.wdev_id_set || ifidx != 0) { |
e472e1b4 AS |
5926 | wpa_printf(MSG_ERROR, "nl80211: Failed to create a P2P Device interface %s", |
5927 | ifname); | |
e472e1b4 AS |
5928 | return -1; |
5929 | } | |
f632e483 AS |
5930 | |
5931 | drv->global->if_add_wdevid = p2pdev_info.wdev_id; | |
5932 | drv->global->if_add_wdevid_set = p2pdev_info.wdev_id_set; | |
5933 | if (!is_zero_ether_addr(p2pdev_info.macaddr)) | |
5934 | os_memcpy(if_addr, p2pdev_info.macaddr, ETH_ALEN); | |
5935 | wpa_printf(MSG_DEBUG, "nl80211: New P2P Device interface %s (0x%llx) created", | |
5936 | ifname, | |
5937 | (long long unsigned int) p2pdev_info.wdev_id); | |
e472e1b4 AS |
5938 | } else { |
5939 | ifidx = nl80211_create_iface(drv, ifname, nlmode, addr, | |
2aec4f3c JM |
5940 | 0, NULL, NULL, use_existing); |
5941 | if (use_existing && ifidx == -ENFILE) { | |
5942 | added = 0; | |
5943 | ifidx = if_nametoindex(ifname); | |
5944 | } else if (ifidx < 0) { | |
e472e1b4 AS |
5945 | return -1; |
5946 | } | |
22a7c9d7 JM |
5947 | } |
5948 | ||
ab7a1add | 5949 | if (!addr) { |
8ea8a89c | 5950 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) |
ab7a1add AS |
5951 | os_memcpy(if_addr, bss->addr, ETH_ALEN); |
5952 | else if (linux_get_ifhwaddr(drv->global->ioctl_sock, | |
8ea8a89c | 5953 | ifname, if_addr) < 0) { |
2aec4f3c JM |
5954 | if (added) |
5955 | nl80211_remove_iface(drv, ifidx); | |
ab7a1add AS |
5956 | return -1; |
5957 | } | |
c55f774d JM |
5958 | } |
5959 | ||
c55f774d JM |
5960 | if (!addr && |
5961 | (type == WPA_IF_P2P_CLIENT || type == WPA_IF_P2P_GROUP || | |
8ea8a89c JM |
5962 | type == WPA_IF_P2P_GO || type == WPA_IF_MESH || |
5963 | type == WPA_IF_STATION)) { | |
5964 | /* Enforce unique address */ | |
ab7a1add | 5965 | u8 new_addr[ETH_ALEN]; |
c55f774d | 5966 | |
ab7a1add | 5967 | if (linux_get_ifhwaddr(drv->global->ioctl_sock, ifname, |
c81eff1a | 5968 | new_addr) < 0) { |
ea39367c MK |
5969 | if (added) |
5970 | nl80211_remove_iface(drv, ifidx); | |
c55f774d JM |
5971 | return -1; |
5972 | } | |
f608081c | 5973 | if (nl80211_addr_in_use(drv->global, new_addr)) { |
c55f774d | 5974 | wpa_printf(MSG_DEBUG, "nl80211: Allocate new address " |
8ea8a89c | 5975 | "for interface %s type %d", ifname, type); |
5b78493f | 5976 | if (nl80211_vif_addr(drv, new_addr) < 0) { |
ea39367c MK |
5977 | if (added) |
5978 | nl80211_remove_iface(drv, ifidx); | |
c55f774d JM |
5979 | return -1; |
5980 | } | |
c81eff1a | 5981 | if (linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, |
c55f774d | 5982 | new_addr) < 0) { |
ea39367c MK |
5983 | if (added) |
5984 | nl80211_remove_iface(drv, ifidx); | |
c55f774d JM |
5985 | return -1; |
5986 | } | |
c55f774d | 5987 | } |
f67eeb5c | 5988 | os_memcpy(if_addr, new_addr, ETH_ALEN); |
c55f774d | 5989 | } |
f3585c8a | 5990 | |
d8a3b66d | 5991 | if (type == WPA_IF_AP_BSS && setup_ap) { |
f5eb9da3 JM |
5992 | struct i802_bss *new_bss = os_zalloc(sizeof(*new_bss)); |
5993 | if (new_bss == NULL) { | |
2aec4f3c JM |
5994 | if (added) |
5995 | nl80211_remove_iface(drv, ifidx); | |
f5eb9da3 JM |
5996 | return -1; |
5997 | } | |
5998 | ||
5999 | if (bridge && | |
6000 | i802_check_bridge(drv, new_bss, bridge, ifname) < 0) { | |
6001 | wpa_printf(MSG_ERROR, "nl80211: Failed to add the new " | |
6002 | "interface %s to a bridge %s", | |
6003 | ifname, bridge); | |
2aec4f3c JM |
6004 | if (added) |
6005 | nl80211_remove_iface(drv, ifidx); | |
f5eb9da3 JM |
6006 | os_free(new_bss); |
6007 | return -1; | |
6008 | } | |
6009 | ||
c81eff1a BG |
6010 | if (linux_set_iface_flags(drv->global->ioctl_sock, ifname, 1)) |
6011 | { | |
ea39367c MK |
6012 | if (added) |
6013 | nl80211_remove_iface(drv, ifidx); | |
07179987 | 6014 | os_free(new_bss); |
22a7c9d7 JM |
6015 | return -1; |
6016 | } | |
a2e40bb6 | 6017 | os_strlcpy(new_bss->ifname, ifname, IFNAMSIZ); |
341eebee | 6018 | os_memcpy(new_bss->addr, if_addr, ETH_ALEN); |
a2e40bb6 FF |
6019 | new_bss->ifindex = ifidx; |
6020 | new_bss->drv = drv; | |
834ee56f KP |
6021 | new_bss->next = drv->first_bss->next; |
6022 | new_bss->freq = drv->first_bss->freq; | |
a5e1eb20 | 6023 | new_bss->ctx = bss_ctx; |
2aec4f3c | 6024 | new_bss->added_if = added; |
834ee56f | 6025 | drv->first_bss->next = new_bss; |
a2e40bb6 FF |
6026 | if (drv_priv) |
6027 | *drv_priv = new_bss; | |
cc7a48d1 | 6028 | nl80211_init_bss(new_bss); |
3dd1d890 YAP |
6029 | |
6030 | /* Subscribe management frames for this WPA_IF_AP_BSS */ | |
6031 | if (nl80211_setup_ap(new_bss)) | |
6032 | return -1; | |
22a7c9d7 | 6033 | } |
22a7c9d7 | 6034 | |
ff6a158b JM |
6035 | if (drv->global) |
6036 | drv->global->if_add_ifindex = ifidx; | |
6037 | ||
d1bb7aed JJ |
6038 | /* |
6039 | * Some virtual interfaces need to process EAPOL packets and events on | |
6040 | * the parent interface. This is used mainly with hostapd. | |
6041 | */ | |
6042 | if (ifidx > 0 && | |
6043 | (drv->hostapd || | |
6044 | nlmode == NL80211_IFTYPE_AP_VLAN || | |
6045 | nlmode == NL80211_IFTYPE_WDS || | |
6046 | nlmode == NL80211_IFTYPE_MONITOR)) | |
b36935be MB |
6047 | add_ifidx(drv, ifidx); |
6048 | ||
22a7c9d7 JM |
6049 | return 0; |
6050 | } | |
6051 | ||
6052 | ||
9ebce9c5 | 6053 | static int wpa_driver_nl80211_if_remove(struct i802_bss *bss, |
22a7c9d7 JM |
6054 | enum wpa_driver_if_type type, |
6055 | const char *ifname) | |
6056 | { | |
a2e40bb6 | 6057 | struct wpa_driver_nl80211_data *drv = bss->drv; |
22a7c9d7 JM |
6058 | int ifindex = if_nametoindex(ifname); |
6059 | ||
2aec4f3c JM |
6060 | wpa_printf(MSG_DEBUG, "nl80211: %s(type=%d ifname=%s) ifindex=%d added_if=%d", |
6061 | __func__, type, ifname, ifindex, bss->added_if); | |
158b090c | 6062 | if (ifindex > 0 && (bss->added_if || bss->ifindex != ifindex)) |
2b72df63 | 6063 | nl80211_remove_iface(drv, ifindex); |
de884303 JM |
6064 | else if (ifindex > 0 && !bss->added_if) { |
6065 | struct wpa_driver_nl80211_data *drv2; | |
6066 | dl_list_for_each(drv2, &drv->global->interfaces, | |
6067 | struct wpa_driver_nl80211_data, list) | |
6068 | del_ifidx(drv2, ifindex); | |
6069 | } | |
c34e618d | 6070 | |
c34e618d FF |
6071 | if (type != WPA_IF_AP_BSS) |
6072 | return 0; | |
6073 | ||
e17a2477 | 6074 | if (bss->added_if_into_bridge) { |
c81eff1a BG |
6075 | if (linux_br_del_if(drv->global->ioctl_sock, bss->brname, |
6076 | bss->ifname) < 0) | |
e17a2477 JM |
6077 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
6078 | "interface %s from bridge %s: %s", | |
6079 | bss->ifname, bss->brname, strerror(errno)); | |
6080 | } | |
6081 | if (bss->added_bridge) { | |
c81eff1a | 6082 | if (linux_br_del(drv->global->ioctl_sock, bss->brname) < 0) |
e17a2477 JM |
6083 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
6084 | "bridge %s: %s", | |
6085 | bss->brname, strerror(errno)); | |
6086 | } | |
a2e40bb6 | 6087 | |
834ee56f | 6088 | if (bss != drv->first_bss) { |
8546ea19 | 6089 | struct i802_bss *tbss; |
a2e40bb6 | 6090 | |
2aec4f3c | 6091 | wpa_printf(MSG_DEBUG, "nl80211: Not the first BSS - remove it"); |
834ee56f | 6092 | for (tbss = drv->first_bss; tbss; tbss = tbss->next) { |
8546ea19 JM |
6093 | if (tbss->next == bss) { |
6094 | tbss->next = bss->next; | |
3dd1d890 YAP |
6095 | /* Unsubscribe management frames */ |
6096 | nl80211_teardown_ap(bss); | |
cc7a48d1 | 6097 | nl80211_destroy_bss(bss); |
5c9da160 MB |
6098 | if (!bss->added_if) |
6099 | i802_set_iface_flags(bss, 0); | |
8546ea19 JM |
6100 | os_free(bss); |
6101 | bss = NULL; | |
6102 | break; | |
6103 | } | |
22a7c9d7 | 6104 | } |
8546ea19 JM |
6105 | if (bss) |
6106 | wpa_printf(MSG_INFO, "nl80211: %s - could not find " | |
6107 | "BSS %p in the list", __func__, bss); | |
390e489c | 6108 | } else { |
2aec4f3c | 6109 | wpa_printf(MSG_DEBUG, "nl80211: First BSS - reassign context"); |
390e489c | 6110 | nl80211_teardown_ap(bss); |
2aec4f3c JM |
6111 | if (!bss->added_if && !drv->first_bss->next) |
6112 | wpa_driver_nl80211_del_beacon(drv); | |
390e489c | 6113 | nl80211_destroy_bss(bss); |
2aec4f3c JM |
6114 | if (!bss->added_if) |
6115 | i802_set_iface_flags(bss, 0); | |
390e489c KP |
6116 | if (drv->first_bss->next) { |
6117 | drv->first_bss = drv->first_bss->next; | |
6118 | drv->ctx = drv->first_bss->ctx; | |
6119 | os_free(bss); | |
6120 | } else { | |
6121 | wpa_printf(MSG_DEBUG, "nl80211: No second BSS to reassign context to"); | |
6122 | } | |
22a7c9d7 | 6123 | } |
22a7c9d7 JM |
6124 | |
6125 | return 0; | |
6126 | } | |
6127 | ||
6128 | ||
55777702 JM |
6129 | static int cookie_handler(struct nl_msg *msg, void *arg) |
6130 | { | |
6131 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
6132 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
6133 | u64 *cookie = arg; | |
6134 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
6135 | genlmsg_attrlen(gnlh, 0), NULL); | |
6136 | if (tb[NL80211_ATTR_COOKIE]) | |
6137 | *cookie = nla_get_u64(tb[NL80211_ATTR_COOKIE]); | |
6138 | return NL_SKIP; | |
6139 | } | |
6140 | ||
6141 | ||
88df0ef7 | 6142 | static int nl80211_send_frame_cmd(struct i802_bss *bss, |
5dfca53f JB |
6143 | unsigned int freq, unsigned int wait, |
6144 | const u8 *buf, size_t buf_len, | |
88df0ef7 | 6145 | u64 *cookie_out, int no_cck, int no_ack, |
2d3943ce AO |
6146 | int offchanok, const u16 *csa_offs, |
6147 | size_t csa_offs_len) | |
9884f9cc | 6148 | { |
88df0ef7 | 6149 | struct wpa_driver_nl80211_data *drv = bss->drv; |
9884f9cc JB |
6150 | struct nl_msg *msg; |
6151 | u64 cookie; | |
6152 | int ret = -1; | |
6153 | ||
cc2ada86 | 6154 | wpa_printf(MSG_MSGDUMP, "nl80211: CMD_FRAME freq=%u wait=%u no_cck=%d " |
2e3e4566 JM |
6155 | "no_ack=%d offchanok=%d", |
6156 | freq, wait, no_cck, no_ack, offchanok); | |
c91f796f | 6157 | wpa_hexdump(MSG_MSGDUMP, "CMD_FRAME", buf, buf_len); |
9884f9cc | 6158 | |
56f77852 | 6159 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_FRAME)) || |
a862e4a3 JM |
6160 | (freq && nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || |
6161 | (wait && nla_put_u32(msg, NL80211_ATTR_DURATION, wait)) || | |
6162 | (offchanok && ((drv->capa.flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX) || | |
6163 | drv->test_use_roc_tx) && | |
6164 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) || | |
6165 | (no_cck && nla_put_flag(msg, NL80211_ATTR_TX_NO_CCK_RATE)) || | |
6166 | (no_ack && nla_put_flag(msg, NL80211_ATTR_DONT_WAIT_FOR_ACK)) || | |
2d3943ce AO |
6167 | (csa_offs && nla_put(msg, NL80211_ATTR_CSA_C_OFFSETS_TX, |
6168 | csa_offs_len * sizeof(u16), csa_offs)) || | |
a862e4a3 JM |
6169 | nla_put(msg, NL80211_ATTR_FRAME, buf_len, buf)) |
6170 | goto fail; | |
9884f9cc JB |
6171 | |
6172 | cookie = 0; | |
6173 | ret = send_and_recv_msgs(drv, msg, cookie_handler, &cookie); | |
6174 | msg = NULL; | |
6175 | if (ret) { | |
6176 | wpa_printf(MSG_DEBUG, "nl80211: Frame command failed: ret=%d " | |
a05225c8 JM |
6177 | "(%s) (freq=%u wait=%u)", ret, strerror(-ret), |
6178 | freq, wait); | |
a862e4a3 JM |
6179 | } else { |
6180 | wpa_printf(MSG_MSGDUMP, "nl80211: Frame TX command accepted%s; " | |
6181 | "cookie 0x%llx", no_ack ? " (no ACK)" : "", | |
6182 | (long long unsigned int) cookie); | |
9884f9cc | 6183 | |
a862e4a3 JM |
6184 | if (cookie_out) |
6185 | *cookie_out = no_ack ? (u64) -1 : cookie; | |
6186 | } | |
9884f9cc | 6187 | |
a862e4a3 | 6188 | fail: |
9884f9cc JB |
6189 | nlmsg_free(msg); |
6190 | return ret; | |
6191 | } | |
6192 | ||
6193 | ||
9ebce9c5 JM |
6194 | static int wpa_driver_nl80211_send_action(struct i802_bss *bss, |
6195 | unsigned int freq, | |
190b9062 | 6196 | unsigned int wait_time, |
58f6fbe0 JM |
6197 | const u8 *dst, const u8 *src, |
6198 | const u8 *bssid, | |
b106173a JM |
6199 | const u8 *data, size_t data_len, |
6200 | int no_cck) | |
58f6fbe0 | 6201 | { |
a2e40bb6 | 6202 | struct wpa_driver_nl80211_data *drv = bss->drv; |
58f6fbe0 | 6203 | int ret = -1; |
58f6fbe0 JM |
6204 | u8 *buf; |
6205 | struct ieee80211_hdr *hdr; | |
58f6fbe0 | 6206 | |
5dfca53f | 6207 | wpa_printf(MSG_DEBUG, "nl80211: Send Action frame (ifindex=%d, " |
55231068 JM |
6208 | "freq=%u MHz wait=%d ms no_cck=%d)", |
6209 | drv->ifindex, freq, wait_time, no_cck); | |
58f6fbe0 JM |
6210 | |
6211 | buf = os_zalloc(24 + data_len); | |
6212 | if (buf == NULL) | |
6213 | return ret; | |
6214 | os_memcpy(buf + 24, data, data_len); | |
6215 | hdr = (struct ieee80211_hdr *) buf; | |
6216 | hdr->frame_control = | |
6217 | IEEE80211_FC(WLAN_FC_TYPE_MGMT, WLAN_FC_STYPE_ACTION); | |
6218 | os_memcpy(hdr->addr1, dst, ETH_ALEN); | |
6219 | os_memcpy(hdr->addr2, src, ETH_ALEN); | |
6220 | os_memcpy(hdr->addr3, bssid, ETH_ALEN); | |
6221 | ||
f78f2785 JM |
6222 | if (is_ap_interface(drv->nlmode) && |
6223 | (!(drv->capa.flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX) || | |
6224 | (int) freq == bss->freq || drv->device_ap_sme || | |
6225 | !drv->use_monitor)) | |
9ebce9c5 JM |
6226 | ret = wpa_driver_nl80211_send_mlme(bss, buf, 24 + data_len, |
6227 | 0, freq, no_cck, 1, | |
2d3943ce | 6228 | wait_time, NULL, 0); |
9884f9cc | 6229 | else |
88df0ef7 | 6230 | ret = nl80211_send_frame_cmd(bss, freq, wait_time, buf, |
5dfca53f | 6231 | 24 + data_len, |
b106173a | 6232 | &drv->send_action_cookie, |
2d3943ce | 6233 | no_cck, 0, 1, NULL, 0); |
58f6fbe0 | 6234 | |
f8bf1421 | 6235 | os_free(buf); |
58f6fbe0 JM |
6236 | return ret; |
6237 | } | |
6238 | ||
6239 | ||
5dfca53f JB |
6240 | static void wpa_driver_nl80211_send_action_cancel_wait(void *priv) |
6241 | { | |
6242 | struct i802_bss *bss = priv; | |
6243 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
6244 | struct nl_msg *msg; | |
6245 | int ret; | |
6246 | ||
316a9e4d JM |
6247 | wpa_printf(MSG_DEBUG, "nl80211: Cancel TX frame wait: cookie=0x%llx", |
6248 | (long long unsigned int) drv->send_action_cookie); | |
56f77852 | 6249 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_FRAME_WAIT_CANCEL)) || |
a862e4a3 JM |
6250 | nla_put_u64(msg, NL80211_ATTR_COOKIE, drv->send_action_cookie)) { |
6251 | nlmsg_free(msg); | |
6252 | return; | |
6253 | } | |
5dfca53f JB |
6254 | |
6255 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
5dfca53f JB |
6256 | if (ret) |
6257 | wpa_printf(MSG_DEBUG, "nl80211: wait cancel failed: ret=%d " | |
6258 | "(%s)", ret, strerror(-ret)); | |
5dfca53f JB |
6259 | } |
6260 | ||
6261 | ||
55777702 JM |
6262 | static int wpa_driver_nl80211_remain_on_channel(void *priv, unsigned int freq, |
6263 | unsigned int duration) | |
6264 | { | |
a2e40bb6 FF |
6265 | struct i802_bss *bss = priv; |
6266 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
55777702 JM |
6267 | struct nl_msg *msg; |
6268 | int ret; | |
6269 | u64 cookie; | |
6270 | ||
56f77852 | 6271 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_REMAIN_ON_CHANNEL)) || |
a862e4a3 JM |
6272 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
6273 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) { | |
6274 | nlmsg_free(msg); | |
6275 | return -1; | |
6276 | } | |
55777702 JM |
6277 | |
6278 | cookie = 0; | |
6279 | ret = send_and_recv_msgs(drv, msg, cookie_handler, &cookie); | |
6280 | if (ret == 0) { | |
6281 | wpa_printf(MSG_DEBUG, "nl80211: Remain-on-channel cookie " | |
6282 | "0x%llx for freq=%u MHz duration=%u", | |
6283 | (long long unsigned int) cookie, freq, duration); | |
6284 | drv->remain_on_chan_cookie = cookie; | |
531f0331 | 6285 | drv->pending_remain_on_chan = 1; |
55777702 JM |
6286 | return 0; |
6287 | } | |
6288 | wpa_printf(MSG_DEBUG, "nl80211: Failed to request remain-on-channel " | |
15ed5535 JM |
6289 | "(freq=%d duration=%u): %d (%s)", |
6290 | freq, duration, ret, strerror(-ret)); | |
55777702 JM |
6291 | return -1; |
6292 | } | |
6293 | ||
6294 | ||
6295 | static int wpa_driver_nl80211_cancel_remain_on_channel(void *priv) | |
6296 | { | |
a2e40bb6 FF |
6297 | struct i802_bss *bss = priv; |
6298 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
55777702 JM |
6299 | struct nl_msg *msg; |
6300 | int ret; | |
6301 | ||
6302 | if (!drv->pending_remain_on_chan) { | |
6303 | wpa_printf(MSG_DEBUG, "nl80211: No pending remain-on-channel " | |
6304 | "to cancel"); | |
6305 | return -1; | |
6306 | } | |
6307 | ||
6308 | wpa_printf(MSG_DEBUG, "nl80211: Cancel remain-on-channel with cookie " | |
6309 | "0x%llx", | |
6310 | (long long unsigned int) drv->remain_on_chan_cookie); | |
6311 | ||
56f77852 JM |
6312 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL); |
6313 | if (!msg || | |
a862e4a3 JM |
6314 | nla_put_u64(msg, NL80211_ATTR_COOKIE, drv->remain_on_chan_cookie)) { |
6315 | nlmsg_free(msg); | |
6316 | return -1; | |
6317 | } | |
55777702 JM |
6318 | |
6319 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
6320 | if (ret == 0) | |
6321 | return 0; | |
6322 | wpa_printf(MSG_DEBUG, "nl80211: Failed to cancel remain-on-channel: " | |
6323 | "%d (%s)", ret, strerror(-ret)); | |
55777702 JM |
6324 | return -1; |
6325 | } | |
6326 | ||
6327 | ||
9ebce9c5 | 6328 | static int wpa_driver_nl80211_probe_req_report(struct i802_bss *bss, int report) |
504e905c | 6329 | { |
a2e40bb6 | 6330 | struct wpa_driver_nl80211_data *drv = bss->drv; |
504e905c | 6331 | |
5582a5d1 | 6332 | if (!report) { |
0d891981 | 6333 | if (bss->nl_preq && drv->device_ap_sme && |
b8d87ed2 AP |
6334 | is_ap_interface(drv->nlmode) && !bss->in_deinit && |
6335 | !bss->static_ap) { | |
0d891981 JM |
6336 | /* |
6337 | * Do not disable Probe Request reporting that was | |
6338 | * enabled in nl80211_setup_ap(). | |
6339 | */ | |
6340 | wpa_printf(MSG_DEBUG, "nl80211: Skip disabling of " | |
6341 | "Probe Request reporting nl_preq=%p while " | |
6342 | "in AP mode", bss->nl_preq); | |
6343 | } else if (bss->nl_preq) { | |
36488c05 JM |
6344 | wpa_printf(MSG_DEBUG, "nl80211: Disable Probe Request " |
6345 | "reporting nl_preq=%p", bss->nl_preq); | |
5f65e9f7 | 6346 | nl80211_destroy_eloop_handle(&bss->nl_preq); |
5582a5d1 JB |
6347 | } |
6348 | return 0; | |
6349 | } | |
6350 | ||
481234cf | 6351 | if (bss->nl_preq) { |
5582a5d1 | 6352 | wpa_printf(MSG_DEBUG, "nl80211: Probe Request reporting " |
36488c05 | 6353 | "already on! nl_preq=%p", bss->nl_preq); |
5582a5d1 JB |
6354 | return 0; |
6355 | } | |
6356 | ||
481234cf JM |
6357 | bss->nl_preq = nl_create_handle(drv->global->nl_cb, "preq"); |
6358 | if (bss->nl_preq == NULL) | |
5582a5d1 | 6359 | return -1; |
36488c05 JM |
6360 | wpa_printf(MSG_DEBUG, "nl80211: Enable Probe Request " |
6361 | "reporting nl_preq=%p", bss->nl_preq); | |
5582a5d1 | 6362 | |
481234cf | 6363 | if (nl80211_register_frame(bss, bss->nl_preq, |
5582a5d1 JB |
6364 | (WLAN_FC_TYPE_MGMT << 2) | |
6365 | (WLAN_FC_STYPE_PROBE_REQ << 4), | |
a92dfde8 JB |
6366 | NULL, 0) < 0) |
6367 | goto out_err; | |
5582a5d1 | 6368 | |
5f65e9f7 JB |
6369 | nl80211_register_eloop_read(&bss->nl_preq, |
6370 | wpa_driver_nl80211_event_receive, | |
6371 | bss->nl_cb); | |
5582a5d1 | 6372 | |
504e905c | 6373 | return 0; |
5582a5d1 | 6374 | |
a92dfde8 | 6375 | out_err: |
221a59c9 | 6376 | nl_destroy_handles(&bss->nl_preq); |
5582a5d1 | 6377 | return -1; |
504e905c JM |
6378 | } |
6379 | ||
6380 | ||
4e5cb1a3 JM |
6381 | static int nl80211_disable_11b_rates(struct wpa_driver_nl80211_data *drv, |
6382 | int ifindex, int disabled) | |
6383 | { | |
6384 | struct nl_msg *msg; | |
6385 | struct nlattr *bands, *band; | |
6386 | int ret; | |
6387 | ||
3e208481 JM |
6388 | wpa_printf(MSG_DEBUG, |
6389 | "nl80211: NL80211_CMD_SET_TX_BITRATE_MASK (ifindex=%d %s)", | |
6390 | ifindex, disabled ? "NL80211_TXRATE_LEGACY=OFDM-only" : | |
6391 | "no NL80211_TXRATE_LEGACY constraint"); | |
6392 | ||
95376e1a JM |
6393 | msg = nl80211_ifindex_msg(drv, ifindex, 0, |
6394 | NL80211_CMD_SET_TX_BITRATE_MASK); | |
4e5cb1a3 JM |
6395 | if (!msg) |
6396 | return -1; | |
6397 | ||
4e5cb1a3 JM |
6398 | bands = nla_nest_start(msg, NL80211_ATTR_TX_RATES); |
6399 | if (!bands) | |
a862e4a3 | 6400 | goto fail; |
4e5cb1a3 JM |
6401 | |
6402 | /* | |
6403 | * Disable 2 GHz rates 1, 2, 5.5, 11 Mbps by masking out everything | |
6404 | * else apart from 6, 9, 12, 18, 24, 36, 48, 54 Mbps from non-MCS | |
6405 | * rates. All 5 GHz rates are left enabled. | |
6406 | */ | |
6407 | band = nla_nest_start(msg, NL80211_BAND_2GHZ); | |
a862e4a3 JM |
6408 | if (!band || |
6409 | (disabled && nla_put(msg, NL80211_TXRATE_LEGACY, 8, | |
6410 | "\x0c\x12\x18\x24\x30\x48\x60\x6c"))) | |
6411 | goto fail; | |
4e5cb1a3 JM |
6412 | nla_nest_end(msg, band); |
6413 | ||
6414 | nla_nest_end(msg, bands); | |
6415 | ||
6416 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
4e5cb1a3 JM |
6417 | if (ret) { |
6418 | wpa_printf(MSG_DEBUG, "nl80211: Set TX rates failed: ret=%d " | |
6419 | "(%s)", ret, strerror(-ret)); | |
1d0c6fb1 JM |
6420 | } else |
6421 | drv->disabled_11b_rates = disabled; | |
4e5cb1a3 JM |
6422 | |
6423 | return ret; | |
6424 | ||
a862e4a3 | 6425 | fail: |
4e5cb1a3 JM |
6426 | nlmsg_free(msg); |
6427 | return -1; | |
6428 | } | |
6429 | ||
6430 | ||
af473088 JM |
6431 | static int wpa_driver_nl80211_deinit_ap(void *priv) |
6432 | { | |
a2e40bb6 FF |
6433 | struct i802_bss *bss = priv; |
6434 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
b1f625e0 | 6435 | if (!is_ap_interface(drv->nlmode)) |
af473088 JM |
6436 | return -1; |
6437 | wpa_driver_nl80211_del_beacon(drv); | |
9bc5cfa3 | 6438 | bss->beacon_set = 0; |
60b13c20 IP |
6439 | |
6440 | /* | |
6441 | * If the P2P GO interface was dynamically added, then it is | |
6442 | * possible that the interface change to station is not possible. | |
6443 | */ | |
6444 | if (drv->nlmode == NL80211_IFTYPE_P2P_GO && bss->if_dynamic) | |
6445 | return 0; | |
6446 | ||
b1f625e0 | 6447 | return wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_STATION); |
af473088 JM |
6448 | } |
6449 | ||
6450 | ||
695c7038 SW |
6451 | static int wpa_driver_nl80211_stop_ap(void *priv) |
6452 | { | |
6453 | struct i802_bss *bss = priv; | |
6454 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
6455 | if (!is_ap_interface(drv->nlmode)) | |
6456 | return -1; | |
6457 | wpa_driver_nl80211_del_beacon(drv); | |
6458 | bss->beacon_set = 0; | |
6459 | return 0; | |
6460 | } | |
6461 | ||
6462 | ||
3c29244e EP |
6463 | static int wpa_driver_nl80211_deinit_p2p_cli(void *priv) |
6464 | { | |
6465 | struct i802_bss *bss = priv; | |
6466 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
6467 | if (drv->nlmode != NL80211_IFTYPE_P2P_CLIENT) | |
6468 | return -1; | |
60b13c20 IP |
6469 | |
6470 | /* | |
6471 | * If the P2P Client interface was dynamically added, then it is | |
6472 | * possible that the interface change to station is not possible. | |
6473 | */ | |
6474 | if (bss->if_dynamic) | |
6475 | return 0; | |
6476 | ||
3c29244e EP |
6477 | return wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_STATION); |
6478 | } | |
6479 | ||
6480 | ||
207ef3fb JM |
6481 | static void wpa_driver_nl80211_resume(void *priv) |
6482 | { | |
a2e40bb6 | 6483 | struct i802_bss *bss = priv; |
e8dc205f | 6484 | enum nl80211_iftype nlmode = nl80211_get_ifmode(bss); |
91724d6f AS |
6485 | |
6486 | if (i802_set_iface_flags(bss, 1)) | |
6487 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set interface up on resume event"); | |
e8dc205f AO |
6488 | |
6489 | if (is_p2p_net_interface(nlmode)) | |
6490 | nl80211_disable_11b_rates(bss->drv, bss->drv->ifindex, 1); | |
207ef3fb JM |
6491 | } |
6492 | ||
6493 | ||
b625473c JM |
6494 | static int nl80211_signal_monitor(void *priv, int threshold, int hysteresis) |
6495 | { | |
6496 | struct i802_bss *bss = priv; | |
6497 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8970bae8 JB |
6498 | struct nl_msg *msg; |
6499 | struct nlattr *cqm; | |
b625473c JM |
6500 | |
6501 | wpa_printf(MSG_DEBUG, "nl80211: Signal monitor threshold=%d " | |
6502 | "hysteresis=%d", threshold, hysteresis); | |
6503 | ||
13f83980 | 6504 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_CQM)) || |
a862e4a3 JM |
6505 | !(cqm = nla_nest_start(msg, NL80211_ATTR_CQM)) || |
6506 | nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THOLD, threshold) || | |
6507 | nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_HYST, hysteresis)) { | |
6508 | nlmsg_free(msg); | |
6509 | return -1; | |
6510 | } | |
8970bae8 | 6511 | nla_nest_end(msg, cqm); |
21270bb4 | 6512 | |
a862e4a3 | 6513 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
b625473c JM |
6514 | } |
6515 | ||
6516 | ||
2cc8d8f4 AO |
6517 | static int get_channel_width(struct nl_msg *msg, void *arg) |
6518 | { | |
6519 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
6520 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
6521 | struct wpa_signal_info *sig_change = arg; | |
6522 | ||
6523 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
6524 | genlmsg_attrlen(gnlh, 0), NULL); | |
6525 | ||
6526 | sig_change->center_frq1 = -1; | |
6527 | sig_change->center_frq2 = -1; | |
6528 | sig_change->chanwidth = CHAN_WIDTH_UNKNOWN; | |
6529 | ||
6530 | if (tb[NL80211_ATTR_CHANNEL_WIDTH]) { | |
6531 | sig_change->chanwidth = convert2width( | |
6532 | nla_get_u32(tb[NL80211_ATTR_CHANNEL_WIDTH])); | |
6533 | if (tb[NL80211_ATTR_CENTER_FREQ1]) | |
6534 | sig_change->center_frq1 = | |
6535 | nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ1]); | |
6536 | if (tb[NL80211_ATTR_CENTER_FREQ2]) | |
6537 | sig_change->center_frq2 = | |
6538 | nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ2]); | |
6539 | } | |
6540 | ||
6541 | return NL_SKIP; | |
6542 | } | |
6543 | ||
6544 | ||
6545 | static int nl80211_get_channel_width(struct wpa_driver_nl80211_data *drv, | |
6546 | struct wpa_signal_info *sig) | |
6547 | { | |
6548 | struct nl_msg *msg; | |
6549 | ||
9725b784 | 6550 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_GET_INTERFACE); |
2cc8d8f4 | 6551 | return send_and_recv_msgs(drv, msg, get_channel_width, sig); |
2cc8d8f4 AO |
6552 | } |
6553 | ||
6554 | ||
1c5c7273 PS |
6555 | static int nl80211_signal_poll(void *priv, struct wpa_signal_info *si) |
6556 | { | |
6557 | struct i802_bss *bss = priv; | |
6558 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
6559 | int res; | |
6560 | ||
6561 | os_memset(si, 0, sizeof(*si)); | |
6562 | res = nl80211_get_link_signal(drv, si); | |
1d6955e6 JM |
6563 | if (res) { |
6564 | if (drv->nlmode != NL80211_IFTYPE_ADHOC && | |
6565 | drv->nlmode != NL80211_IFTYPE_MESH_POINT) | |
6566 | return res; | |
6567 | si->current_signal = 0; | |
6568 | } | |
1c5c7273 | 6569 | |
2cc8d8f4 AO |
6570 | res = nl80211_get_channel_width(drv, si); |
6571 | if (res != 0) | |
6572 | return res; | |
6573 | ||
1c5c7273 PS |
6574 | return nl80211_get_link_noise(drv, si); |
6575 | } | |
6576 | ||
6577 | ||
b91ab76e JM |
6578 | static int nl80211_send_frame(void *priv, const u8 *data, size_t data_len, |
6579 | int encrypt) | |
6580 | { | |
6581 | struct i802_bss *bss = priv; | |
55231068 | 6582 | return wpa_driver_nl80211_send_frame(bss, data, data_len, encrypt, 0, |
2d3943ce | 6583 | 0, 0, 0, 0, NULL, 0); |
b91ab76e JM |
6584 | } |
6585 | ||
6586 | ||
c55f774d JM |
6587 | static int nl80211_set_param(void *priv, const char *param) |
6588 | { | |
c55f774d JM |
6589 | wpa_printf(MSG_DEBUG, "nl80211: driver param='%s'", param); |
6590 | if (param == NULL) | |
6591 | return 0; | |
6592 | ||
6593 | #ifdef CONFIG_P2P | |
6594 | if (os_strstr(param, "use_p2p_group_interface=1")) { | |
482856c8 JM |
6595 | struct i802_bss *bss = priv; |
6596 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
6597 | ||
c55f774d JM |
6598 | wpa_printf(MSG_DEBUG, "nl80211: Use separate P2P group " |
6599 | "interface"); | |
6600 | drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_CONCURRENT; | |
6601 | drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_MGMT_AND_NON_P2P; | |
6602 | } | |
6603 | #endif /* CONFIG_P2P */ | |
6604 | ||
327b01d3 JM |
6605 | if (os_strstr(param, "use_monitor=1")) { |
6606 | struct i802_bss *bss = priv; | |
6607 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
6608 | drv->use_monitor = 1; | |
6609 | } | |
6610 | ||
6611 | if (os_strstr(param, "force_connect_cmd=1")) { | |
6612 | struct i802_bss *bss = priv; | |
6613 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
6614 | drv->capa.flags &= ~WPA_DRIVER_FLAGS_SME; | |
b497a212 | 6615 | drv->force_connect_cmd = 1; |
327b01d3 JM |
6616 | } |
6617 | ||
64abb725 JM |
6618 | if (os_strstr(param, "no_offchannel_tx=1")) { |
6619 | struct i802_bss *bss = priv; | |
6620 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
6621 | drv->capa.flags &= ~WPA_DRIVER_FLAGS_OFFCHANNEL_TX; | |
6622 | drv->test_use_roc_tx = 1; | |
6623 | } | |
6624 | ||
c55f774d JM |
6625 | return 0; |
6626 | } | |
6627 | ||
6628 | ||
f2ed8023 JM |
6629 | static void * nl80211_global_init(void) |
6630 | { | |
6631 | struct nl80211_global *global; | |
36d84860 BG |
6632 | struct netlink_config *cfg; |
6633 | ||
f2ed8023 JM |
6634 | global = os_zalloc(sizeof(*global)); |
6635 | if (global == NULL) | |
6636 | return NULL; | |
c81eff1a | 6637 | global->ioctl_sock = -1; |
f2ed8023 | 6638 | dl_list_init(&global->interfaces); |
ff6a158b | 6639 | global->if_add_ifindex = -1; |
36d84860 BG |
6640 | |
6641 | cfg = os_zalloc(sizeof(*cfg)); | |
6642 | if (cfg == NULL) | |
6643 | goto err; | |
6644 | ||
6645 | cfg->ctx = global; | |
6646 | cfg->newlink_cb = wpa_driver_nl80211_event_rtm_newlink; | |
6647 | cfg->dellink_cb = wpa_driver_nl80211_event_rtm_dellink; | |
6648 | global->netlink = netlink_init(cfg); | |
6649 | if (global->netlink == NULL) { | |
6650 | os_free(cfg); | |
6651 | goto err; | |
6652 | } | |
6653 | ||
2a7b66f5 BG |
6654 | if (wpa_driver_nl80211_init_nl_global(global) < 0) |
6655 | goto err; | |
6656 | ||
c81eff1a BG |
6657 | global->ioctl_sock = socket(PF_INET, SOCK_DGRAM, 0); |
6658 | if (global->ioctl_sock < 0) { | |
7ac3616d JM |
6659 | wpa_printf(MSG_ERROR, "nl80211: socket(PF_INET,SOCK_DGRAM) failed: %s", |
6660 | strerror(errno)); | |
c81eff1a BG |
6661 | goto err; |
6662 | } | |
6663 | ||
f2ed8023 | 6664 | return global; |
36d84860 BG |
6665 | |
6666 | err: | |
6667 | nl80211_global_deinit(global); | |
6668 | return NULL; | |
f2ed8023 JM |
6669 | } |
6670 | ||
6671 | ||
6672 | static void nl80211_global_deinit(void *priv) | |
6673 | { | |
6674 | struct nl80211_global *global = priv; | |
6675 | if (global == NULL) | |
6676 | return; | |
6677 | if (!dl_list_empty(&global->interfaces)) { | |
6678 | wpa_printf(MSG_ERROR, "nl80211: %u interface(s) remain at " | |
6679 | "nl80211_global_deinit", | |
6680 | dl_list_len(&global->interfaces)); | |
6681 | } | |
36d84860 BG |
6682 | |
6683 | if (global->netlink) | |
6684 | netlink_deinit(global->netlink); | |
6685 | ||
276e2d67 BG |
6686 | nl_destroy_handles(&global->nl); |
6687 | ||
5f65e9f7 JB |
6688 | if (global->nl_event) |
6689 | nl80211_destroy_eloop_handle(&global->nl_event); | |
d6c9aab8 JB |
6690 | |
6691 | nl_cb_put(global->nl_cb); | |
2a7b66f5 | 6692 | |
c81eff1a BG |
6693 | if (global->ioctl_sock >= 0) |
6694 | close(global->ioctl_sock); | |
6695 | ||
f2ed8023 JM |
6696 | os_free(global); |
6697 | } | |
6698 | ||
6699 | ||
6859f1cb BG |
6700 | static const char * nl80211_get_radio_name(void *priv) |
6701 | { | |
6702 | struct i802_bss *bss = priv; | |
6703 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
6704 | return drv->phyname; | |
6705 | } | |
6706 | ||
6707 | ||
a6efc65d JM |
6708 | static int nl80211_pmkid(struct i802_bss *bss, int cmd, const u8 *bssid, |
6709 | const u8 *pmkid) | |
6710 | { | |
6711 | struct nl_msg *msg; | |
6712 | ||
13f83980 | 6713 | if (!(msg = nl80211_bss_msg(bss, 0, cmd)) || |
a862e4a3 JM |
6714 | (pmkid && nla_put(msg, NL80211_ATTR_PMKID, 16, pmkid)) || |
6715 | (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))) { | |
6716 | nlmsg_free(msg); | |
6717 | return -ENOBUFS; | |
6718 | } | |
a6efc65d JM |
6719 | |
6720 | return send_and_recv_msgs(bss->drv, msg, NULL, NULL); | |
a6efc65d JM |
6721 | } |
6722 | ||
6723 | ||
6724 | static int nl80211_add_pmkid(void *priv, const u8 *bssid, const u8 *pmkid) | |
6725 | { | |
6726 | struct i802_bss *bss = priv; | |
6727 | wpa_printf(MSG_DEBUG, "nl80211: Add PMKID for " MACSTR, MAC2STR(bssid)); | |
6728 | return nl80211_pmkid(bss, NL80211_CMD_SET_PMKSA, bssid, pmkid); | |
6729 | } | |
6730 | ||
6731 | ||
6732 | static int nl80211_remove_pmkid(void *priv, const u8 *bssid, const u8 *pmkid) | |
6733 | { | |
6734 | struct i802_bss *bss = priv; | |
6735 | wpa_printf(MSG_DEBUG, "nl80211: Delete PMKID for " MACSTR, | |
6736 | MAC2STR(bssid)); | |
6737 | return nl80211_pmkid(bss, NL80211_CMD_DEL_PMKSA, bssid, pmkid); | |
6738 | } | |
6739 | ||
6740 | ||
6741 | static int nl80211_flush_pmkid(void *priv) | |
6742 | { | |
6743 | struct i802_bss *bss = priv; | |
6744 | wpa_printf(MSG_DEBUG, "nl80211: Flush PMKIDs"); | |
6745 | return nl80211_pmkid(bss, NL80211_CMD_FLUSH_PMKSA, NULL, NULL); | |
6746 | } | |
6747 | ||
6748 | ||
0185007c MK |
6749 | static void clean_survey_results(struct survey_results *survey_results) |
6750 | { | |
6751 | struct freq_survey *survey, *tmp; | |
6752 | ||
6753 | if (dl_list_empty(&survey_results->survey_list)) | |
6754 | return; | |
6755 | ||
6756 | dl_list_for_each_safe(survey, tmp, &survey_results->survey_list, | |
6757 | struct freq_survey, list) { | |
6758 | dl_list_del(&survey->list); | |
6759 | os_free(survey); | |
6760 | } | |
6761 | } | |
6762 | ||
6763 | ||
6764 | static void add_survey(struct nlattr **sinfo, u32 ifidx, | |
6765 | struct dl_list *survey_list) | |
6766 | { | |
6767 | struct freq_survey *survey; | |
6768 | ||
6769 | survey = os_zalloc(sizeof(struct freq_survey)); | |
6770 | if (!survey) | |
6771 | return; | |
6772 | ||
6773 | survey->ifidx = ifidx; | |
6774 | survey->freq = nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]); | |
6775 | survey->filled = 0; | |
6776 | ||
6777 | if (sinfo[NL80211_SURVEY_INFO_NOISE]) { | |
6778 | survey->nf = (int8_t) | |
6779 | nla_get_u8(sinfo[NL80211_SURVEY_INFO_NOISE]); | |
6780 | survey->filled |= SURVEY_HAS_NF; | |
6781 | } | |
6782 | ||
6783 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME]) { | |
6784 | survey->channel_time = | |
6785 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME]); | |
6786 | survey->filled |= SURVEY_HAS_CHAN_TIME; | |
6787 | } | |
6788 | ||
6789 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY]) { | |
6790 | survey->channel_time_busy = | |
6791 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY]); | |
6792 | survey->filled |= SURVEY_HAS_CHAN_TIME_BUSY; | |
6793 | } | |
6794 | ||
6795 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_RX]) { | |
6796 | survey->channel_time_rx = | |
6797 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_RX]); | |
6798 | survey->filled |= SURVEY_HAS_CHAN_TIME_RX; | |
6799 | } | |
6800 | ||
6801 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_TX]) { | |
6802 | survey->channel_time_tx = | |
6803 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_TX]); | |
6804 | survey->filled |= SURVEY_HAS_CHAN_TIME_TX; | |
6805 | } | |
6806 | ||
6807 | 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)", | |
6808 | survey->freq, | |
6809 | survey->nf, | |
6810 | (unsigned long int) survey->channel_time, | |
6811 | (unsigned long int) survey->channel_time_busy, | |
6812 | (unsigned long int) survey->channel_time_tx, | |
6813 | (unsigned long int) survey->channel_time_rx, | |
6814 | survey->filled); | |
6815 | ||
6816 | dl_list_add_tail(survey_list, &survey->list); | |
6817 | } | |
6818 | ||
6819 | ||
6820 | static int check_survey_ok(struct nlattr **sinfo, u32 surveyed_freq, | |
6821 | unsigned int freq_filter) | |
6822 | { | |
6823 | if (!freq_filter) | |
6824 | return 1; | |
6825 | ||
6826 | return freq_filter == surveyed_freq; | |
6827 | } | |
6828 | ||
6829 | ||
6830 | static int survey_handler(struct nl_msg *msg, void *arg) | |
6831 | { | |
6832 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
6833 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
6834 | struct nlattr *sinfo[NL80211_SURVEY_INFO_MAX + 1]; | |
6835 | struct survey_results *survey_results; | |
6836 | u32 surveyed_freq = 0; | |
6837 | u32 ifidx; | |
6838 | ||
6839 | static struct nla_policy survey_policy[NL80211_SURVEY_INFO_MAX + 1] = { | |
6840 | [NL80211_SURVEY_INFO_FREQUENCY] = { .type = NLA_U32 }, | |
6841 | [NL80211_SURVEY_INFO_NOISE] = { .type = NLA_U8 }, | |
6842 | }; | |
6843 | ||
6844 | survey_results = (struct survey_results *) arg; | |
6845 | ||
6846 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
6847 | genlmsg_attrlen(gnlh, 0), NULL); | |
6848 | ||
e28f39b7 SJ |
6849 | if (!tb[NL80211_ATTR_IFINDEX]) |
6850 | return NL_SKIP; | |
6851 | ||
0185007c MK |
6852 | ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); |
6853 | ||
6854 | if (!tb[NL80211_ATTR_SURVEY_INFO]) | |
6855 | return NL_SKIP; | |
6856 | ||
6857 | if (nla_parse_nested(sinfo, NL80211_SURVEY_INFO_MAX, | |
6858 | tb[NL80211_ATTR_SURVEY_INFO], | |
6859 | survey_policy)) | |
6860 | return NL_SKIP; | |
6861 | ||
6862 | if (!sinfo[NL80211_SURVEY_INFO_FREQUENCY]) { | |
6863 | wpa_printf(MSG_ERROR, "nl80211: Invalid survey data"); | |
6864 | return NL_SKIP; | |
6865 | } | |
6866 | ||
6867 | surveyed_freq = nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]); | |
6868 | ||
6869 | if (!check_survey_ok(sinfo, surveyed_freq, | |
6870 | survey_results->freq_filter)) | |
6871 | return NL_SKIP; | |
6872 | ||
6873 | if (survey_results->freq_filter && | |
6874 | survey_results->freq_filter != surveyed_freq) { | |
6875 | wpa_printf(MSG_EXCESSIVE, "nl80211: Ignoring survey data for freq %d MHz", | |
6876 | surveyed_freq); | |
6877 | return NL_SKIP; | |
6878 | } | |
6879 | ||
6880 | add_survey(sinfo, ifidx, &survey_results->survey_list); | |
6881 | ||
6882 | return NL_SKIP; | |
6883 | } | |
6884 | ||
6885 | ||
6886 | static int wpa_driver_nl80211_get_survey(void *priv, unsigned int freq) | |
6887 | { | |
6888 | struct i802_bss *bss = priv; | |
6889 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
6890 | struct nl_msg *msg; | |
9725b784 | 6891 | int err; |
0185007c MK |
6892 | union wpa_event_data data; |
6893 | struct survey_results *survey_results; | |
6894 | ||
6895 | os_memset(&data, 0, sizeof(data)); | |
6896 | survey_results = &data.survey_results; | |
6897 | ||
6898 | dl_list_init(&survey_results->survey_list); | |
6899 | ||
9725b784 | 6900 | msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SURVEY); |
0185007c | 6901 | if (!msg) |
a862e4a3 | 6902 | return -ENOBUFS; |
0185007c | 6903 | |
0185007c MK |
6904 | if (freq) |
6905 | data.survey_results.freq_filter = freq; | |
6906 | ||
6907 | do { | |
6908 | wpa_printf(MSG_DEBUG, "nl80211: Fetch survey data"); | |
6909 | err = send_and_recv_msgs(drv, msg, survey_handler, | |
6910 | survey_results); | |
6911 | } while (err > 0); | |
6912 | ||
a862e4a3 | 6913 | if (err) |
0185007c | 6914 | wpa_printf(MSG_ERROR, "nl80211: Failed to process survey data"); |
a862e4a3 JM |
6915 | else |
6916 | wpa_supplicant_event(drv->ctx, EVENT_SURVEY, &data); | |
0185007c | 6917 | |
0185007c | 6918 | clean_survey_results(survey_results); |
0185007c MK |
6919 | return err; |
6920 | } | |
6921 | ||
6922 | ||
98cd3d1c JM |
6923 | static void nl80211_set_rekey_info(void *priv, const u8 *kek, size_t kek_len, |
6924 | const u8 *kck, size_t kck_len, | |
b14a210c JB |
6925 | const u8 *replay_ctr) |
6926 | { | |
6927 | struct i802_bss *bss = priv; | |
6928 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
6929 | struct nlattr *replay_nested; | |
6930 | struct nl_msg *msg; | |
64ae2447 | 6931 | int ret; |
b14a210c | 6932 | |
64ae2447 JM |
6933 | if (!drv->set_rekey_offload) |
6934 | return; | |
6935 | ||
6936 | wpa_printf(MSG_DEBUG, "nl80211: Set rekey offload"); | |
13f83980 | 6937 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_REKEY_OFFLOAD)) || |
a862e4a3 | 6938 | !(replay_nested = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA)) || |
98cd3d1c JM |
6939 | nla_put(msg, NL80211_REKEY_DATA_KEK, kek_len, kek) || |
6940 | nla_put(msg, NL80211_REKEY_DATA_KCK, kck_len, kck) || | |
a862e4a3 JM |
6941 | nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, NL80211_REPLAY_CTR_LEN, |
6942 | replay_ctr)) { | |
bbd89bfc | 6943 | nl80211_nlmsg_clear(msg); |
a862e4a3 JM |
6944 | nlmsg_free(msg); |
6945 | return; | |
6946 | } | |
b14a210c JB |
6947 | |
6948 | nla_nest_end(msg, replay_nested); | |
6949 | ||
64ae2447 JM |
6950 | ret = send_and_recv_msgs(drv, msg, NULL, (void *) -1); |
6951 | if (ret == -EOPNOTSUPP) { | |
6952 | wpa_printf(MSG_DEBUG, | |
6953 | "nl80211: Driver does not support rekey offload"); | |
6954 | drv->set_rekey_offload = 0; | |
6955 | } | |
b14a210c JB |
6956 | } |
6957 | ||
6958 | ||
39718852 JB |
6959 | static void nl80211_send_null_frame(struct i802_bss *bss, const u8 *own_addr, |
6960 | const u8 *addr, int qos) | |
bcf24348 | 6961 | { |
39718852 JB |
6962 | /* send data frame to poll STA and check whether |
6963 | * this frame is ACKed */ | |
bcf24348 JB |
6964 | struct { |
6965 | struct ieee80211_hdr hdr; | |
6966 | u16 qos_ctl; | |
6967 | } STRUCT_PACKED nulldata; | |
6968 | size_t size; | |
6969 | ||
6970 | /* Send data frame to poll STA and check whether this frame is ACKed */ | |
6971 | ||
6972 | os_memset(&nulldata, 0, sizeof(nulldata)); | |
6973 | ||
6974 | if (qos) { | |
6975 | nulldata.hdr.frame_control = | |
6976 | IEEE80211_FC(WLAN_FC_TYPE_DATA, | |
6977 | WLAN_FC_STYPE_QOS_NULL); | |
6978 | size = sizeof(nulldata); | |
6979 | } else { | |
6980 | nulldata.hdr.frame_control = | |
6981 | IEEE80211_FC(WLAN_FC_TYPE_DATA, | |
6982 | WLAN_FC_STYPE_NULLFUNC); | |
6983 | size = sizeof(struct ieee80211_hdr); | |
6984 | } | |
6985 | ||
6986 | nulldata.hdr.frame_control |= host_to_le16(WLAN_FC_FROMDS); | |
6987 | os_memcpy(nulldata.hdr.IEEE80211_DA_FROMDS, addr, ETH_ALEN); | |
6988 | os_memcpy(nulldata.hdr.IEEE80211_BSSID_FROMDS, own_addr, ETH_ALEN); | |
6989 | os_memcpy(nulldata.hdr.IEEE80211_SA_FROMDS, own_addr, ETH_ALEN); | |
6990 | ||
9ebce9c5 | 6991 | if (wpa_driver_nl80211_send_mlme(bss, (u8 *) &nulldata, size, 0, 0, 0, |
2d3943ce | 6992 | 0, 0, NULL, 0) < 0) |
bcf24348 JB |
6993 | wpa_printf(MSG_DEBUG, "nl80211_send_null_frame: Failed to " |
6994 | "send poll frame"); | |
6995 | } | |
6996 | ||
39718852 JB |
6997 | static void nl80211_poll_client(void *priv, const u8 *own_addr, const u8 *addr, |
6998 | int qos) | |
6999 | { | |
7000 | struct i802_bss *bss = priv; | |
7001 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
7002 | struct nl_msg *msg; | |
fc99fab7 | 7003 | int ret; |
39718852 JB |
7004 | |
7005 | if (!drv->poll_command_supported) { | |
7006 | nl80211_send_null_frame(bss, own_addr, addr, qos); | |
7007 | return; | |
7008 | } | |
7009 | ||
13f83980 | 7010 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_PROBE_CLIENT)) || |
a862e4a3 JM |
7011 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { |
7012 | nlmsg_free(msg); | |
7013 | return; | |
7014 | } | |
39718852 | 7015 | |
fc99fab7 JM |
7016 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
7017 | if (ret < 0) { | |
7018 | wpa_printf(MSG_DEBUG, "nl80211: Client probe request for " | |
7019 | MACSTR " failed: ret=%d (%s)", | |
7020 | MAC2STR(addr), ret, strerror(-ret)); | |
7021 | } | |
39718852 JB |
7022 | } |
7023 | ||
bcf24348 | 7024 | |
29f338af JM |
7025 | static int nl80211_set_power_save(struct i802_bss *bss, int enabled) |
7026 | { | |
7027 | struct nl_msg *msg; | |
7028 | ||
13f83980 | 7029 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_POWER_SAVE)) || |
a862e4a3 JM |
7030 | nla_put_u32(msg, NL80211_ATTR_PS_STATE, |
7031 | enabled ? NL80211_PS_ENABLED : NL80211_PS_DISABLED)) { | |
7032 | nlmsg_free(msg); | |
7033 | return -ENOBUFS; | |
7034 | } | |
29f338af | 7035 | return send_and_recv_msgs(bss->drv, msg, NULL, NULL); |
29f338af JM |
7036 | } |
7037 | ||
7038 | ||
7039 | static int nl80211_set_p2p_powersave(void *priv, int legacy_ps, int opp_ps, | |
7040 | int ctwindow) | |
7041 | { | |
7042 | struct i802_bss *bss = priv; | |
7043 | ||
7044 | wpa_printf(MSG_DEBUG, "nl80211: set_p2p_powersave (legacy_ps=%d " | |
7045 | "opp_ps=%d ctwindow=%d)", legacy_ps, opp_ps, ctwindow); | |
7046 | ||
0de38036 JM |
7047 | if (opp_ps != -1 || ctwindow != -1) { |
7048 | #ifdef ANDROID_P2P | |
7049 | wpa_driver_set_p2p_ps(priv, legacy_ps, opp_ps, ctwindow); | |
7050 | #else /* ANDROID_P2P */ | |
29f338af | 7051 | return -1; /* Not yet supported */ |
0de38036 JM |
7052 | #endif /* ANDROID_P2P */ |
7053 | } | |
29f338af JM |
7054 | |
7055 | if (legacy_ps == -1) | |
7056 | return 0; | |
7057 | if (legacy_ps != 0 && legacy_ps != 1) | |
7058 | return -1; /* Not yet supported */ | |
7059 | ||
7060 | return nl80211_set_power_save(bss, legacy_ps); | |
7061 | } | |
7062 | ||
7063 | ||
04e8003c JD |
7064 | static int nl80211_start_radar_detection(void *priv, |
7065 | struct hostapd_freq_params *freq) | |
f90e9c1c SW |
7066 | { |
7067 | struct i802_bss *bss = priv; | |
7068 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
7069 | struct nl_msg *msg; | |
7070 | int ret; | |
7071 | ||
04e8003c JD |
7072 | 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)", |
7073 | freq->freq, freq->ht_enabled, freq->vht_enabled, | |
7074 | freq->bandwidth, freq->center_freq1, freq->center_freq2); | |
7075 | ||
f90e9c1c SW |
7076 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_RADAR)) { |
7077 | wpa_printf(MSG_DEBUG, "nl80211: Driver does not support radar " | |
7078 | "detection"); | |
7079 | return -1; | |
7080 | } | |
7081 | ||
9725b784 | 7082 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_RADAR_DETECT)) || |
a862e4a3 JM |
7083 | nl80211_put_freq_params(msg, freq) < 0) { |
7084 | nlmsg_free(msg); | |
7085 | return -1; | |
7086 | } | |
f90e9c1c SW |
7087 | |
7088 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
7089 | if (ret == 0) | |
7090 | return 0; | |
7091 | wpa_printf(MSG_DEBUG, "nl80211: Failed to start radar detection: " | |
7092 | "%d (%s)", ret, strerror(-ret)); | |
f90e9c1c SW |
7093 | return -1; |
7094 | } | |
7095 | ||
03ea1786 AN |
7096 | #ifdef CONFIG_TDLS |
7097 | ||
7098 | static int nl80211_send_tdls_mgmt(void *priv, const u8 *dst, u8 action_code, | |
7099 | u8 dialog_token, u16 status_code, | |
984dadc2 AN |
7100 | u32 peer_capab, int initiator, const u8 *buf, |
7101 | size_t len) | |
03ea1786 AN |
7102 | { |
7103 | struct i802_bss *bss = priv; | |
7104 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
7105 | struct nl_msg *msg; | |
7106 | ||
7107 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) | |
7108 | return -EOPNOTSUPP; | |
7109 | ||
7110 | if (!dst) | |
7111 | return -EINVAL; | |
7112 | ||
9725b784 | 7113 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_TDLS_MGMT)) || |
a862e4a3 JM |
7114 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || |
7115 | nla_put_u8(msg, NL80211_ATTR_TDLS_ACTION, action_code) || | |
7116 | nla_put_u8(msg, NL80211_ATTR_TDLS_DIALOG_TOKEN, dialog_token) || | |
7117 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status_code)) | |
7118 | goto fail; | |
96ecea5e SD |
7119 | if (peer_capab) { |
7120 | /* | |
7121 | * The internal enum tdls_peer_capability definition is | |
7122 | * currently identical with the nl80211 enum | |
7123 | * nl80211_tdls_peer_capability, so no conversion is needed | |
7124 | * here. | |
7125 | */ | |
a862e4a3 JM |
7126 | if (nla_put_u32(msg, NL80211_ATTR_TDLS_PEER_CAPABILITY, |
7127 | peer_capab)) | |
7128 | goto fail; | |
96ecea5e | 7129 | } |
a862e4a3 JM |
7130 | if ((initiator && |
7131 | nla_put_flag(msg, NL80211_ATTR_TDLS_INITIATOR)) || | |
7132 | nla_put(msg, NL80211_ATTR_IE, len, buf)) | |
7133 | goto fail; | |
03ea1786 AN |
7134 | |
7135 | return send_and_recv_msgs(drv, msg, NULL, NULL); | |
7136 | ||
a862e4a3 | 7137 | fail: |
03ea1786 AN |
7138 | nlmsg_free(msg); |
7139 | return -ENOBUFS; | |
7140 | } | |
7141 | ||
7142 | ||
7143 | static int nl80211_tdls_oper(void *priv, enum tdls_oper oper, const u8 *peer) | |
7144 | { | |
7145 | struct i802_bss *bss = priv; | |
7146 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
7147 | struct nl_msg *msg; | |
7148 | enum nl80211_tdls_operation nl80211_oper; | |
7149 | ||
7150 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) | |
7151 | return -EOPNOTSUPP; | |
7152 | ||
7153 | switch (oper) { | |
7154 | case TDLS_DISCOVERY_REQ: | |
7155 | nl80211_oper = NL80211_TDLS_DISCOVERY_REQ; | |
7156 | break; | |
7157 | case TDLS_SETUP: | |
7158 | nl80211_oper = NL80211_TDLS_SETUP; | |
7159 | break; | |
7160 | case TDLS_TEARDOWN: | |
7161 | nl80211_oper = NL80211_TDLS_TEARDOWN; | |
7162 | break; | |
7163 | case TDLS_ENABLE_LINK: | |
7164 | nl80211_oper = NL80211_TDLS_ENABLE_LINK; | |
7165 | break; | |
7166 | case TDLS_DISABLE_LINK: | |
7167 | nl80211_oper = NL80211_TDLS_DISABLE_LINK; | |
7168 | break; | |
7169 | case TDLS_ENABLE: | |
7170 | return 0; | |
7171 | case TDLS_DISABLE: | |
7172 | return 0; | |
7173 | default: | |
7174 | return -EINVAL; | |
7175 | } | |
7176 | ||
9725b784 | 7177 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_TDLS_OPER)) || |
a862e4a3 | 7178 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, nl80211_oper) || |
a862e4a3 JM |
7179 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) { |
7180 | nlmsg_free(msg); | |
7181 | return -ENOBUFS; | |
7182 | } | |
03ea1786 AN |
7183 | |
7184 | return send_and_recv_msgs(drv, msg, NULL, NULL); | |
03ea1786 AN |
7185 | } |
7186 | ||
72b2605f AN |
7187 | |
7188 | static int | |
7189 | nl80211_tdls_enable_channel_switch(void *priv, const u8 *addr, u8 oper_class, | |
7190 | const struct hostapd_freq_params *params) | |
7191 | { | |
7192 | struct i802_bss *bss = priv; | |
7193 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
7194 | struct nl_msg *msg; | |
7195 | int ret = -ENOBUFS; | |
7196 | ||
7197 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT) || | |
7198 | !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH)) | |
7199 | return -EOPNOTSUPP; | |
7200 | ||
7201 | wpa_printf(MSG_DEBUG, "nl80211: Enable TDLS channel switch " MACSTR | |
7202 | " oper_class=%u freq=%u", | |
7203 | MAC2STR(addr), oper_class, params->freq); | |
7204 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_TDLS_CHANNEL_SWITCH); | |
7205 | if (!msg || | |
7206 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || | |
7207 | nla_put_u8(msg, NL80211_ATTR_OPER_CLASS, oper_class) || | |
7208 | (ret = nl80211_put_freq_params(msg, params))) { | |
7209 | nlmsg_free(msg); | |
7210 | wpa_printf(MSG_DEBUG, "nl80211: Could not build TDLS chan switch"); | |
7211 | return ret; | |
7212 | } | |
7213 | ||
7214 | return send_and_recv_msgs(drv, msg, NULL, NULL); | |
7215 | } | |
7216 | ||
7217 | ||
7218 | static int | |
7219 | nl80211_tdls_disable_channel_switch(void *priv, const u8 *addr) | |
7220 | { | |
7221 | struct i802_bss *bss = priv; | |
7222 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
7223 | struct nl_msg *msg; | |
7224 | ||
7225 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT) || | |
7226 | !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH)) | |
7227 | return -EOPNOTSUPP; | |
7228 | ||
7229 | wpa_printf(MSG_DEBUG, "nl80211: Disable TDLS channel switch " MACSTR, | |
7230 | MAC2STR(addr)); | |
7231 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH); | |
7232 | if (!msg || | |
7233 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { | |
7234 | nlmsg_free(msg); | |
7235 | wpa_printf(MSG_DEBUG, | |
7236 | "nl80211: Could not build TDLS cancel chan switch"); | |
7237 | return -ENOBUFS; | |
7238 | } | |
7239 | ||
7240 | return send_and_recv_msgs(drv, msg, NULL, NULL); | |
7241 | } | |
7242 | ||
03ea1786 AN |
7243 | #endif /* CONFIG TDLS */ |
7244 | ||
7245 | ||
9ebce9c5 JM |
7246 | static int driver_nl80211_set_key(const char *ifname, void *priv, |
7247 | enum wpa_alg alg, const u8 *addr, | |
7248 | int key_idx, int set_tx, | |
7249 | const u8 *seq, size_t seq_len, | |
7250 | const u8 *key, size_t key_len) | |
7251 | { | |
7252 | struct i802_bss *bss = priv; | |
7253 | return wpa_driver_nl80211_set_key(ifname, bss, alg, addr, key_idx, | |
7254 | set_tx, seq, seq_len, key, key_len); | |
7255 | } | |
7256 | ||
7257 | ||
7258 | static int driver_nl80211_scan2(void *priv, | |
7259 | struct wpa_driver_scan_params *params) | |
7260 | { | |
7261 | struct i802_bss *bss = priv; | |
b658547d | 7262 | #ifdef CONFIG_DRIVER_NL80211_QCA |
adcd7c4b KV |
7263 | struct wpa_driver_nl80211_data *drv = bss->drv; |
7264 | ||
7265 | /* | |
7266 | * Do a vendor specific scan if possible. If only_new_results is | |
7267 | * set, do a normal scan since a kernel (cfg80211) BSS cache flush | |
7268 | * cannot be achieved through a vendor scan. The below condition may | |
7269 | * need to be modified if new scan flags are added in the future whose | |
7270 | * functionality can only be achieved through a normal scan. | |
7271 | */ | |
7272 | if (drv->scan_vendor_cmd_avail && !params->only_new_results) | |
7273 | return wpa_driver_nl80211_vendor_scan(bss, params); | |
b658547d | 7274 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
9ebce9c5 JM |
7275 | return wpa_driver_nl80211_scan(bss, params); |
7276 | } | |
7277 | ||
7278 | ||
7279 | static int driver_nl80211_deauthenticate(void *priv, const u8 *addr, | |
7280 | int reason_code) | |
7281 | { | |
7282 | struct i802_bss *bss = priv; | |
7283 | return wpa_driver_nl80211_deauthenticate(bss, addr, reason_code); | |
7284 | } | |
7285 | ||
7286 | ||
7287 | static int driver_nl80211_authenticate(void *priv, | |
7288 | struct wpa_driver_auth_params *params) | |
7289 | { | |
7290 | struct i802_bss *bss = priv; | |
7291 | return wpa_driver_nl80211_authenticate(bss, params); | |
7292 | } | |
7293 | ||
7294 | ||
7295 | static void driver_nl80211_deinit(void *priv) | |
7296 | { | |
7297 | struct i802_bss *bss = priv; | |
7298 | wpa_driver_nl80211_deinit(bss); | |
7299 | } | |
7300 | ||
7301 | ||
7302 | static int driver_nl80211_if_remove(void *priv, enum wpa_driver_if_type type, | |
7303 | const char *ifname) | |
7304 | { | |
7305 | struct i802_bss *bss = priv; | |
7306 | return wpa_driver_nl80211_if_remove(bss, type, ifname); | |
7307 | } | |
7308 | ||
7309 | ||
7310 | static int driver_nl80211_send_mlme(void *priv, const u8 *data, | |
5d180a77 | 7311 | size_t data_len, int noack, |
2d3943ce AO |
7312 | unsigned int freq, |
7313 | const u16 *csa_offs, size_t csa_offs_len) | |
9ebce9c5 JM |
7314 | { |
7315 | struct i802_bss *bss = priv; | |
7316 | return wpa_driver_nl80211_send_mlme(bss, data, data_len, noack, | |
2d3943ce AO |
7317 | freq, 0, 0, 0, csa_offs, |
7318 | csa_offs_len); | |
9ebce9c5 JM |
7319 | } |
7320 | ||
7321 | ||
7322 | static int driver_nl80211_sta_remove(void *priv, const u8 *addr) | |
7323 | { | |
7324 | struct i802_bss *bss = priv; | |
59d7148a | 7325 | return wpa_driver_nl80211_sta_remove(bss, addr, -1, 0); |
9ebce9c5 JM |
7326 | } |
7327 | ||
7328 | ||
9ebce9c5 JM |
7329 | static int driver_nl80211_set_sta_vlan(void *priv, const u8 *addr, |
7330 | const char *ifname, int vlan_id) | |
7331 | { | |
7332 | struct i802_bss *bss = priv; | |
7333 | return i802_set_sta_vlan(bss, addr, ifname, vlan_id); | |
7334 | } | |
9ebce9c5 JM |
7335 | |
7336 | ||
7337 | static int driver_nl80211_read_sta_data(void *priv, | |
7338 | struct hostap_sta_driver_data *data, | |
7339 | const u8 *addr) | |
7340 | { | |
7341 | struct i802_bss *bss = priv; | |
7342 | return i802_read_sta_data(bss, data, addr); | |
7343 | } | |
7344 | ||
7345 | ||
7346 | static int driver_nl80211_send_action(void *priv, unsigned int freq, | |
7347 | unsigned int wait_time, | |
7348 | const u8 *dst, const u8 *src, | |
7349 | const u8 *bssid, | |
7350 | const u8 *data, size_t data_len, | |
7351 | int no_cck) | |
7352 | { | |
7353 | struct i802_bss *bss = priv; | |
7354 | return wpa_driver_nl80211_send_action(bss, freq, wait_time, dst, src, | |
7355 | bssid, data, data_len, no_cck); | |
7356 | } | |
7357 | ||
7358 | ||
7359 | static int driver_nl80211_probe_req_report(void *priv, int report) | |
7360 | { | |
7361 | struct i802_bss *bss = priv; | |
7362 | return wpa_driver_nl80211_probe_req_report(bss, report); | |
7363 | } | |
7364 | ||
7365 | ||
6a1ce395 DG |
7366 | static int wpa_driver_nl80211_update_ft_ies(void *priv, const u8 *md, |
7367 | const u8 *ies, size_t ies_len) | |
7368 | { | |
7369 | int ret; | |
7370 | struct nl_msg *msg; | |
7371 | struct i802_bss *bss = priv; | |
7372 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
7373 | u16 mdid = WPA_GET_LE16(md); | |
7374 | ||
6a1ce395 | 7375 | wpa_printf(MSG_DEBUG, "nl80211: Updating FT IEs"); |
9725b784 | 7376 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_UPDATE_FT_IES)) || |
a862e4a3 JM |
7377 | nla_put(msg, NL80211_ATTR_IE, ies_len, ies) || |
7378 | nla_put_u16(msg, NL80211_ATTR_MDID, mdid)) { | |
7379 | nlmsg_free(msg); | |
7380 | return -ENOBUFS; | |
7381 | } | |
6a1ce395 DG |
7382 | |
7383 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
7384 | if (ret) { | |
7385 | wpa_printf(MSG_DEBUG, "nl80211: update_ft_ies failed " | |
7386 | "err=%d (%s)", ret, strerror(-ret)); | |
7387 | } | |
7388 | ||
7389 | return ret; | |
6a1ce395 DG |
7390 | } |
7391 | ||
7392 | ||
597b94f5 AS |
7393 | const u8 * wpa_driver_nl80211_get_macaddr(void *priv) |
7394 | { | |
7395 | struct i802_bss *bss = priv; | |
7396 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
7397 | ||
7398 | if (drv->nlmode != NL80211_IFTYPE_P2P_DEVICE) | |
7399 | return NULL; | |
7400 | ||
7401 | return bss->addr; | |
7402 | } | |
7403 | ||
7404 | ||
a771c07d JM |
7405 | static const char * scan_state_str(enum scan_states scan_state) |
7406 | { | |
7407 | switch (scan_state) { | |
7408 | case NO_SCAN: | |
7409 | return "NO_SCAN"; | |
7410 | case SCAN_REQUESTED: | |
7411 | return "SCAN_REQUESTED"; | |
7412 | case SCAN_STARTED: | |
7413 | return "SCAN_STARTED"; | |
7414 | case SCAN_COMPLETED: | |
7415 | return "SCAN_COMPLETED"; | |
7416 | case SCAN_ABORTED: | |
7417 | return "SCAN_ABORTED"; | |
7418 | case SCHED_SCAN_STARTED: | |
7419 | return "SCHED_SCAN_STARTED"; | |
7420 | case SCHED_SCAN_STOPPED: | |
7421 | return "SCHED_SCAN_STOPPED"; | |
7422 | case SCHED_SCAN_RESULTS: | |
7423 | return "SCHED_SCAN_RESULTS"; | |
7424 | } | |
7425 | ||
7426 | return "??"; | |
7427 | } | |
7428 | ||
7429 | ||
7430 | static int wpa_driver_nl80211_status(void *priv, char *buf, size_t buflen) | |
7431 | { | |
7432 | struct i802_bss *bss = priv; | |
7433 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
7434 | int res; | |
7435 | char *pos, *end; | |
7436 | ||
7437 | pos = buf; | |
7438 | end = buf + buflen; | |
7439 | ||
7440 | res = os_snprintf(pos, end - pos, | |
7441 | "ifindex=%d\n" | |
7442 | "ifname=%s\n" | |
7443 | "brname=%s\n" | |
7444 | "addr=" MACSTR "\n" | |
7445 | "freq=%d\n" | |
7446 | "%s%s%s%s%s", | |
7447 | bss->ifindex, | |
7448 | bss->ifname, | |
7449 | bss->brname, | |
7450 | MAC2STR(bss->addr), | |
7451 | bss->freq, | |
7452 | bss->beacon_set ? "beacon_set=1\n" : "", | |
7453 | bss->added_if_into_bridge ? | |
7454 | "added_if_into_bridge=1\n" : "", | |
7455 | bss->added_bridge ? "added_bridge=1\n" : "", | |
7456 | bss->in_deinit ? "in_deinit=1\n" : "", | |
7457 | bss->if_dynamic ? "if_dynamic=1\n" : ""); | |
d85e1fc8 | 7458 | if (os_snprintf_error(end - pos, res)) |
a771c07d JM |
7459 | return pos - buf; |
7460 | pos += res; | |
7461 | ||
7462 | if (bss->wdev_id_set) { | |
7463 | res = os_snprintf(pos, end - pos, "wdev_id=%llu\n", | |
7464 | (unsigned long long) bss->wdev_id); | |
d85e1fc8 | 7465 | if (os_snprintf_error(end - pos, res)) |
a771c07d JM |
7466 | return pos - buf; |
7467 | pos += res; | |
7468 | } | |
7469 | ||
7470 | res = os_snprintf(pos, end - pos, | |
7471 | "phyname=%s\n" | |
fee354c7 | 7472 | "perm_addr=" MACSTR "\n" |
a771c07d JM |
7473 | "drv_ifindex=%d\n" |
7474 | "operstate=%d\n" | |
7475 | "scan_state=%s\n" | |
7476 | "auth_bssid=" MACSTR "\n" | |
7477 | "auth_attempt_bssid=" MACSTR "\n" | |
7478 | "bssid=" MACSTR "\n" | |
7479 | "prev_bssid=" MACSTR "\n" | |
7480 | "associated=%d\n" | |
7481 | "assoc_freq=%u\n" | |
7482 | "monitor_sock=%d\n" | |
7483 | "monitor_ifidx=%d\n" | |
7484 | "monitor_refcount=%d\n" | |
7485 | "last_mgmt_freq=%u\n" | |
7486 | "eapol_tx_sock=%d\n" | |
97752f79 | 7487 | "%s%s%s%s%s%s%s%s%s%s%s%s%s", |
a771c07d | 7488 | drv->phyname, |
fee354c7 | 7489 | MAC2STR(drv->perm_addr), |
a771c07d JM |
7490 | drv->ifindex, |
7491 | drv->operstate, | |
7492 | scan_state_str(drv->scan_state), | |
7493 | MAC2STR(drv->auth_bssid), | |
7494 | MAC2STR(drv->auth_attempt_bssid), | |
7495 | MAC2STR(drv->bssid), | |
7496 | MAC2STR(drv->prev_bssid), | |
7497 | drv->associated, | |
7498 | drv->assoc_freq, | |
7499 | drv->monitor_sock, | |
7500 | drv->monitor_ifidx, | |
7501 | drv->monitor_refcount, | |
7502 | drv->last_mgmt_freq, | |
7503 | drv->eapol_tx_sock, | |
7504 | drv->ignore_if_down_event ? | |
7505 | "ignore_if_down_event=1\n" : "", | |
7506 | drv->scan_complete_events ? | |
7507 | "scan_complete_events=1\n" : "", | |
7508 | drv->disabled_11b_rates ? | |
7509 | "disabled_11b_rates=1\n" : "", | |
7510 | drv->pending_remain_on_chan ? | |
7511 | "pending_remain_on_chan=1\n" : "", | |
7512 | drv->in_interface_list ? "in_interface_list=1\n" : "", | |
7513 | drv->device_ap_sme ? "device_ap_sme=1\n" : "", | |
7514 | drv->poll_command_supported ? | |
7515 | "poll_command_supported=1\n" : "", | |
7516 | drv->data_tx_status ? "data_tx_status=1\n" : "", | |
7517 | drv->scan_for_auth ? "scan_for_auth=1\n" : "", | |
7518 | drv->retry_auth ? "retry_auth=1\n" : "", | |
7519 | drv->use_monitor ? "use_monitor=1\n" : "", | |
7520 | drv->ignore_next_local_disconnect ? | |
7521 | "ignore_next_local_disconnect=1\n" : "", | |
d6a36f39 | 7522 | drv->ignore_next_local_deauth ? |
97752f79 | 7523 | "ignore_next_local_deauth=1\n" : ""); |
d85e1fc8 | 7524 | if (os_snprintf_error(end - pos, res)) |
a771c07d JM |
7525 | return pos - buf; |
7526 | pos += res; | |
7527 | ||
7528 | if (drv->has_capability) { | |
7529 | res = os_snprintf(pos, end - pos, | |
7530 | "capa.key_mgmt=0x%x\n" | |
7531 | "capa.enc=0x%x\n" | |
7532 | "capa.auth=0x%x\n" | |
24bd4e0b | 7533 | "capa.flags=0x%llx\n" |
a0a34d53 | 7534 | "capa.rrm_flags=0x%x\n" |
a771c07d JM |
7535 | "capa.max_scan_ssids=%d\n" |
7536 | "capa.max_sched_scan_ssids=%d\n" | |
7537 | "capa.sched_scan_supported=%d\n" | |
7538 | "capa.max_match_sets=%d\n" | |
7539 | "capa.max_remain_on_chan=%u\n" | |
7540 | "capa.max_stations=%u\n" | |
7541 | "capa.probe_resp_offloads=0x%x\n" | |
7542 | "capa.max_acl_mac_addrs=%u\n" | |
86056fea IP |
7543 | "capa.num_multichan_concurrent=%u\n" |
7544 | "capa.mac_addr_rand_sched_scan_supported=%d\n" | |
079a28f7 AK |
7545 | "capa.mac_addr_rand_scan_supported=%d\n" |
7546 | "capa.conc_capab=%u\n" | |
7547 | "capa.max_conc_chan_2_4=%u\n" | |
7548 | "capa.max_conc_chan_5_0=%u\n", | |
a771c07d JM |
7549 | drv->capa.key_mgmt, |
7550 | drv->capa.enc, | |
7551 | drv->capa.auth, | |
24bd4e0b | 7552 | (unsigned long long) drv->capa.flags, |
a0a34d53 | 7553 | drv->capa.rrm_flags, |
a771c07d JM |
7554 | drv->capa.max_scan_ssids, |
7555 | drv->capa.max_sched_scan_ssids, | |
7556 | drv->capa.sched_scan_supported, | |
7557 | drv->capa.max_match_sets, | |
7558 | drv->capa.max_remain_on_chan, | |
7559 | drv->capa.max_stations, | |
7560 | drv->capa.probe_resp_offloads, | |
7561 | drv->capa.max_acl_mac_addrs, | |
86056fea IP |
7562 | drv->capa.num_multichan_concurrent, |
7563 | drv->capa.mac_addr_rand_sched_scan_supported, | |
079a28f7 AK |
7564 | drv->capa.mac_addr_rand_scan_supported, |
7565 | drv->capa.conc_capab, | |
7566 | drv->capa.max_conc_chan_2_4, | |
7567 | drv->capa.max_conc_chan_5_0); | |
d85e1fc8 | 7568 | if (os_snprintf_error(end - pos, res)) |
a771c07d JM |
7569 | return pos - buf; |
7570 | pos += res; | |
7571 | } | |
7572 | ||
7573 | return pos - buf; | |
7574 | } | |
7575 | ||
7576 | ||
1c4ffa87 AO |
7577 | static int set_beacon_data(struct nl_msg *msg, struct beacon_data *settings) |
7578 | { | |
a862e4a3 JM |
7579 | if ((settings->head && |
7580 | nla_put(msg, NL80211_ATTR_BEACON_HEAD, | |
7581 | settings->head_len, settings->head)) || | |
7582 | (settings->tail && | |
7583 | nla_put(msg, NL80211_ATTR_BEACON_TAIL, | |
7584 | settings->tail_len, settings->tail)) || | |
7585 | (settings->beacon_ies && | |
7586 | nla_put(msg, NL80211_ATTR_IE, | |
7587 | settings->beacon_ies_len, settings->beacon_ies)) || | |
7588 | (settings->proberesp_ies && | |
7589 | nla_put(msg, NL80211_ATTR_IE_PROBE_RESP, | |
7590 | settings->proberesp_ies_len, settings->proberesp_ies)) || | |
7591 | (settings->assocresp_ies && | |
7592 | nla_put(msg, NL80211_ATTR_IE_ASSOC_RESP, | |
7593 | settings->assocresp_ies_len, settings->assocresp_ies)) || | |
7594 | (settings->probe_resp && | |
7595 | nla_put(msg, NL80211_ATTR_PROBE_RESP, | |
7596 | settings->probe_resp_len, settings->probe_resp))) | |
7597 | return -ENOBUFS; | |
1c4ffa87 AO |
7598 | |
7599 | return 0; | |
1c4ffa87 AO |
7600 | } |
7601 | ||
7602 | ||
7603 | static int nl80211_switch_channel(void *priv, struct csa_settings *settings) | |
7604 | { | |
7605 | struct nl_msg *msg; | |
7606 | struct i802_bss *bss = priv; | |
7607 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
7608 | struct nlattr *beacon_csa; | |
7609 | int ret = -ENOBUFS; | |
366179d2 AO |
7610 | int csa_off_len = 0; |
7611 | int i; | |
1c4ffa87 | 7612 | |
8d1fdde7 | 7613 | wpa_printf(MSG_DEBUG, "nl80211: Channel switch request (cs_count=%u block_tx=%u freq=%d width=%d cf1=%d cf2=%d)", |
1c4ffa87 | 7614 | settings->cs_count, settings->block_tx, |
8d1fdde7 JD |
7615 | settings->freq_params.freq, settings->freq_params.bandwidth, |
7616 | settings->freq_params.center_freq1, | |
7617 | settings->freq_params.center_freq2); | |
1c4ffa87 | 7618 | |
991aa9c7 | 7619 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_AP_CSA)) { |
1c4ffa87 AO |
7620 | wpa_printf(MSG_DEBUG, "nl80211: Driver does not support channel switch command"); |
7621 | return -EOPNOTSUPP; | |
7622 | } | |
7623 | ||
7624 | if ((drv->nlmode != NL80211_IFTYPE_AP) && | |
7625 | (drv->nlmode != NL80211_IFTYPE_P2P_GO)) | |
7626 | return -EOPNOTSUPP; | |
7627 | ||
366179d2 AO |
7628 | /* |
7629 | * Remove empty counters, assuming Probe Response and Beacon frame | |
7630 | * counters match. This implementation assumes that there are only two | |
7631 | * counters. | |
7632 | */ | |
7633 | if (settings->counter_offset_beacon[0] && | |
7634 | !settings->counter_offset_beacon[1]) { | |
7635 | csa_off_len = 1; | |
7636 | } else if (settings->counter_offset_beacon[1] && | |
7637 | !settings->counter_offset_beacon[0]) { | |
7638 | csa_off_len = 1; | |
7639 | settings->counter_offset_beacon[0] = | |
7640 | settings->counter_offset_beacon[1]; | |
7641 | settings->counter_offset_presp[0] = | |
7642 | settings->counter_offset_presp[1]; | |
7643 | } else if (settings->counter_offset_beacon[1] && | |
7644 | settings->counter_offset_beacon[0]) { | |
7645 | csa_off_len = 2; | |
7646 | } else { | |
7647 | wpa_printf(MSG_ERROR, "nl80211: No CSA counters provided"); | |
7648 | return -EINVAL; | |
7649 | } | |
7650 | ||
7651 | /* Check CSA counters validity */ | |
7652 | if (drv->capa.max_csa_counters && | |
7653 | csa_off_len > drv->capa.max_csa_counters) { | |
7654 | wpa_printf(MSG_ERROR, | |
7655 | "nl80211: Too many CSA counters provided"); | |
1c4ffa87 | 7656 | return -EINVAL; |
366179d2 | 7657 | } |
1c4ffa87 | 7658 | |
366179d2 | 7659 | if (!settings->beacon_csa.tail) |
1c4ffa87 AO |
7660 | return -EINVAL; |
7661 | ||
366179d2 AO |
7662 | for (i = 0; i < csa_off_len; i++) { |
7663 | u16 csa_c_off_bcn = settings->counter_offset_beacon[i]; | |
7664 | u16 csa_c_off_presp = settings->counter_offset_presp[i]; | |
7665 | ||
7666 | if ((settings->beacon_csa.tail_len <= csa_c_off_bcn) || | |
7667 | (settings->beacon_csa.tail[csa_c_off_bcn] != | |
7668 | settings->cs_count)) | |
7669 | return -EINVAL; | |
7670 | ||
7671 | if (settings->beacon_csa.probe_resp && | |
7672 | ((settings->beacon_csa.probe_resp_len <= | |
7673 | csa_c_off_presp) || | |
7674 | (settings->beacon_csa.probe_resp[csa_c_off_presp] != | |
7675 | settings->cs_count))) | |
7676 | return -EINVAL; | |
7677 | } | |
7678 | ||
13f83980 | 7679 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_CHANNEL_SWITCH)) || |
a862e4a3 JM |
7680 | nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, |
7681 | settings->cs_count) || | |
7682 | (ret = nl80211_put_freq_params(msg, &settings->freq_params)) || | |
7683 | (settings->block_tx && | |
7684 | nla_put_flag(msg, NL80211_ATTR_CH_SWITCH_BLOCK_TX))) | |
1c4ffa87 AO |
7685 | goto error; |
7686 | ||
1c4ffa87 AO |
7687 | /* beacon_after params */ |
7688 | ret = set_beacon_data(msg, &settings->beacon_after); | |
7689 | if (ret) | |
7690 | goto error; | |
7691 | ||
7692 | /* beacon_csa params */ | |
7693 | beacon_csa = nla_nest_start(msg, NL80211_ATTR_CSA_IES); | |
7694 | if (!beacon_csa) | |
a862e4a3 | 7695 | goto fail; |
1c4ffa87 AO |
7696 | |
7697 | ret = set_beacon_data(msg, &settings->beacon_csa); | |
7698 | if (ret) | |
7699 | goto error; | |
7700 | ||
366179d2 AO |
7701 | if (nla_put(msg, NL80211_ATTR_CSA_C_OFF_BEACON, |
7702 | csa_off_len * sizeof(u16), | |
7703 | settings->counter_offset_beacon) || | |
a862e4a3 | 7704 | (settings->beacon_csa.probe_resp && |
366179d2 AO |
7705 | nla_put(msg, NL80211_ATTR_CSA_C_OFF_PRESP, |
7706 | csa_off_len * sizeof(u16), | |
7707 | settings->counter_offset_presp))) | |
a862e4a3 | 7708 | goto fail; |
1c4ffa87 AO |
7709 | |
7710 | nla_nest_end(msg, beacon_csa); | |
7711 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
7712 | if (ret) { | |
7713 | wpa_printf(MSG_DEBUG, "nl80211: switch_channel failed err=%d (%s)", | |
7714 | ret, strerror(-ret)); | |
7715 | } | |
7716 | return ret; | |
7717 | ||
a862e4a3 | 7718 | fail: |
1c4ffa87 AO |
7719 | ret = -ENOBUFS; |
7720 | error: | |
7721 | nlmsg_free(msg); | |
7722 | wpa_printf(MSG_DEBUG, "nl80211: Could not build channel switch request"); | |
7723 | return ret; | |
7724 | } | |
7725 | ||
7726 | ||
dfa87878 MB |
7727 | static int nl80211_add_ts(void *priv, u8 tsid, const u8 *addr, |
7728 | u8 user_priority, u16 admitted_time) | |
7729 | { | |
7730 | struct i802_bss *bss = priv; | |
7731 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
7732 | struct nl_msg *msg; | |
7733 | int ret; | |
7734 | ||
7735 | wpa_printf(MSG_DEBUG, | |
7736 | "nl80211: add_ts request: tsid=%u admitted_time=%u up=%d", | |
7737 | tsid, admitted_time, user_priority); | |
7738 | ||
7739 | if (!is_sta_interface(drv->nlmode)) | |
7740 | return -ENOTSUP; | |
7741 | ||
56f77852 JM |
7742 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_ADD_TX_TS); |
7743 | if (!msg || | |
a862e4a3 JM |
7744 | nla_put_u8(msg, NL80211_ATTR_TSID, tsid) || |
7745 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || | |
7746 | nla_put_u8(msg, NL80211_ATTR_USER_PRIO, user_priority) || | |
7747 | nla_put_u16(msg, NL80211_ATTR_ADMITTED_TIME, admitted_time)) { | |
7748 | nlmsg_free(msg); | |
7749 | return -ENOBUFS; | |
7750 | } | |
dfa87878 MB |
7751 | |
7752 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
7753 | if (ret) | |
7754 | wpa_printf(MSG_DEBUG, "nl80211: add_ts failed err=%d (%s)", | |
7755 | ret, strerror(-ret)); | |
7756 | return ret; | |
dfa87878 MB |
7757 | } |
7758 | ||
7759 | ||
7760 | static int nl80211_del_ts(void *priv, u8 tsid, const u8 *addr) | |
7761 | { | |
7762 | struct i802_bss *bss = priv; | |
7763 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
7764 | struct nl_msg *msg; | |
7765 | int ret; | |
7766 | ||
7767 | wpa_printf(MSG_DEBUG, "nl80211: del_ts request: tsid=%u", tsid); | |
7768 | ||
7769 | if (!is_sta_interface(drv->nlmode)) | |
7770 | return -ENOTSUP; | |
7771 | ||
56f77852 | 7772 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_DEL_TX_TS)) || |
a862e4a3 JM |
7773 | nla_put_u8(msg, NL80211_ATTR_TSID, tsid) || |
7774 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { | |
7775 | nlmsg_free(msg); | |
7776 | return -ENOBUFS; | |
7777 | } | |
dfa87878 MB |
7778 | |
7779 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
7780 | if (ret) | |
7781 | wpa_printf(MSG_DEBUG, "nl80211: del_ts failed err=%d (%s)", | |
7782 | ret, strerror(-ret)); | |
7783 | return ret; | |
dfa87878 MB |
7784 | } |
7785 | ||
7786 | ||
6b9f7af6 JM |
7787 | #ifdef CONFIG_TESTING_OPTIONS |
7788 | static int cmd_reply_handler(struct nl_msg *msg, void *arg) | |
7789 | { | |
7790 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
7791 | struct wpabuf *buf = arg; | |
7792 | ||
7793 | if (!buf) | |
7794 | return NL_SKIP; | |
7795 | ||
7796 | if ((size_t) genlmsg_attrlen(gnlh, 0) > wpabuf_tailroom(buf)) { | |
7797 | wpa_printf(MSG_INFO, "nl80211: insufficient buffer space for reply"); | |
7798 | return NL_SKIP; | |
7799 | } | |
7800 | ||
7801 | wpabuf_put_data(buf, genlmsg_attrdata(gnlh, 0), | |
7802 | genlmsg_attrlen(gnlh, 0)); | |
7803 | ||
7804 | return NL_SKIP; | |
7805 | } | |
7806 | #endif /* CONFIG_TESTING_OPTIONS */ | |
7807 | ||
7808 | ||
adef8948 BL |
7809 | static int vendor_reply_handler(struct nl_msg *msg, void *arg) |
7810 | { | |
7811 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
7812 | struct nlattr *nl_vendor_reply, *nl; | |
7813 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
7814 | struct wpabuf *buf = arg; | |
7815 | int rem; | |
7816 | ||
7817 | if (!buf) | |
7818 | return NL_SKIP; | |
7819 | ||
7820 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
7821 | genlmsg_attrlen(gnlh, 0), NULL); | |
7822 | nl_vendor_reply = tb[NL80211_ATTR_VENDOR_DATA]; | |
7823 | ||
7824 | if (!nl_vendor_reply) | |
7825 | return NL_SKIP; | |
7826 | ||
7827 | if ((size_t) nla_len(nl_vendor_reply) > wpabuf_tailroom(buf)) { | |
7828 | wpa_printf(MSG_INFO, "nl80211: Vendor command: insufficient buffer space for reply"); | |
7829 | return NL_SKIP; | |
7830 | } | |
7831 | ||
7832 | nla_for_each_nested(nl, nl_vendor_reply, rem) { | |
7833 | wpabuf_put_data(buf, nla_data(nl), nla_len(nl)); | |
7834 | } | |
7835 | ||
7836 | return NL_SKIP; | |
7837 | } | |
7838 | ||
7839 | ||
7840 | static int nl80211_vendor_cmd(void *priv, unsigned int vendor_id, | |
7841 | unsigned int subcmd, const u8 *data, | |
7842 | size_t data_len, struct wpabuf *buf) | |
7843 | { | |
7844 | struct i802_bss *bss = priv; | |
7845 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
7846 | struct nl_msg *msg; | |
7847 | int ret; | |
7848 | ||
6b9f7af6 JM |
7849 | #ifdef CONFIG_TESTING_OPTIONS |
7850 | if (vendor_id == 0xffffffff) { | |
56f77852 JM |
7851 | msg = nlmsg_alloc(); |
7852 | if (!msg) | |
7853 | return -ENOMEM; | |
7854 | ||
6b9f7af6 JM |
7855 | nl80211_cmd(drv, msg, 0, subcmd); |
7856 | if (nlmsg_append(msg, (void *) data, data_len, NLMSG_ALIGNTO) < | |
7857 | 0) | |
a862e4a3 | 7858 | goto fail; |
6b9f7af6 JM |
7859 | ret = send_and_recv_msgs(drv, msg, cmd_reply_handler, buf); |
7860 | if (ret) | |
7861 | wpa_printf(MSG_DEBUG, "nl80211: command failed err=%d", | |
7862 | ret); | |
7863 | return ret; | |
7864 | } | |
7865 | #endif /* CONFIG_TESTING_OPTIONS */ | |
7866 | ||
56f77852 | 7867 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_VENDOR)) || |
a862e4a3 JM |
7868 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, vendor_id) || |
7869 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, subcmd) || | |
7870 | (data && | |
7871 | nla_put(msg, NL80211_ATTR_VENDOR_DATA, data_len, data))) | |
7872 | goto fail; | |
adef8948 BL |
7873 | |
7874 | ret = send_and_recv_msgs(drv, msg, vendor_reply_handler, buf); | |
7875 | if (ret) | |
7876 | wpa_printf(MSG_DEBUG, "nl80211: vendor command failed err=%d", | |
7877 | ret); | |
7878 | return ret; | |
7879 | ||
a862e4a3 | 7880 | fail: |
adef8948 BL |
7881 | nlmsg_free(msg); |
7882 | return -ENOBUFS; | |
7883 | } | |
7884 | ||
7885 | ||
049105b4 KP |
7886 | static int nl80211_set_qos_map(void *priv, const u8 *qos_map_set, |
7887 | u8 qos_map_set_len) | |
7888 | { | |
7889 | struct i802_bss *bss = priv; | |
7890 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
7891 | struct nl_msg *msg; | |
7892 | int ret; | |
7893 | ||
049105b4 KP |
7894 | wpa_hexdump(MSG_DEBUG, "nl80211: Setting QoS Map", |
7895 | qos_map_set, qos_map_set_len); | |
7896 | ||
9725b784 | 7897 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_QOS_MAP)) || |
a862e4a3 JM |
7898 | nla_put(msg, NL80211_ATTR_QOS_MAP, qos_map_set_len, qos_map_set)) { |
7899 | nlmsg_free(msg); | |
7900 | return -ENOBUFS; | |
7901 | } | |
049105b4 KP |
7902 | |
7903 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
7904 | if (ret) | |
7905 | wpa_printf(MSG_DEBUG, "nl80211: Setting QoS Map failed"); | |
7906 | ||
7907 | return ret; | |
049105b4 KP |
7908 | } |
7909 | ||
7910 | ||
e4fa8b12 EP |
7911 | static int nl80211_set_wowlan(void *priv, |
7912 | const struct wowlan_triggers *triggers) | |
7913 | { | |
7914 | struct i802_bss *bss = priv; | |
7915 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
7916 | struct nl_msg *msg; | |
7917 | struct nlattr *wowlan_triggers; | |
7918 | int ret; | |
7919 | ||
e4fa8b12 EP |
7920 | wpa_printf(MSG_DEBUG, "nl80211: Setting wowlan"); |
7921 | ||
1ac977bd | 7922 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_SET_WOWLAN)) || |
a862e4a3 JM |
7923 | !(wowlan_triggers = nla_nest_start(msg, |
7924 | NL80211_ATTR_WOWLAN_TRIGGERS)) || | |
7925 | (triggers->any && | |
7926 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || | |
7927 | (triggers->disconnect && | |
7928 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || | |
7929 | (triggers->magic_pkt && | |
7930 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || | |
7931 | (triggers->gtk_rekey_failure && | |
7932 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || | |
7933 | (triggers->eap_identity_req && | |
7934 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || | |
7935 | (triggers->four_way_handshake && | |
7936 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || | |
7937 | (triggers->rfkill_release && | |
7938 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) { | |
7939 | nlmsg_free(msg); | |
7940 | return -ENOBUFS; | |
7941 | } | |
e4fa8b12 EP |
7942 | |
7943 | nla_nest_end(msg, wowlan_triggers); | |
7944 | ||
7945 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
7946 | if (ret) | |
7947 | wpa_printf(MSG_DEBUG, "nl80211: Setting wowlan failed"); | |
7948 | ||
7949 | return ret; | |
e4fa8b12 EP |
7950 | } |
7951 | ||
7952 | ||
b658547d | 7953 | #ifdef CONFIG_DRIVER_NL80211_QCA |
0800f9ee JM |
7954 | static int nl80211_roaming(void *priv, int allowed, const u8 *bssid) |
7955 | { | |
7956 | struct i802_bss *bss = priv; | |
7957 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
7958 | struct nl_msg *msg; | |
7959 | struct nlattr *params; | |
7960 | ||
7961 | wpa_printf(MSG_DEBUG, "nl80211: Roaming policy: allowed=%d", allowed); | |
7962 | ||
7963 | if (!drv->roaming_vendor_cmd_avail) { | |
7964 | wpa_printf(MSG_DEBUG, | |
7965 | "nl80211: Ignore roaming policy change since driver does not provide command for setting it"); | |
7966 | return -1; | |
7967 | } | |
7968 | ||
9725b784 | 7969 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
a862e4a3 JM |
7970 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
7971 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | |
7972 | QCA_NL80211_VENDOR_SUBCMD_ROAMING) || | |
7973 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || | |
7974 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_ROAMING_POLICY, | |
7975 | allowed ? QCA_ROAMING_ALLOWED_WITHIN_ESS : | |
7976 | QCA_ROAMING_NOT_ALLOWED) || | |
7977 | (bssid && | |
7978 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_MAC_ADDR, ETH_ALEN, bssid))) { | |
7979 | nlmsg_free(msg); | |
7980 | return -1; | |
7981 | } | |
0800f9ee JM |
7982 | nla_nest_end(msg, params); |
7983 | ||
7984 | return send_and_recv_msgs(drv, msg, NULL, NULL); | |
0800f9ee | 7985 | } |
b658547d | 7986 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
0800f9ee JM |
7987 | |
7988 | ||
fee354c7 JM |
7989 | static int nl80211_set_mac_addr(void *priv, const u8 *addr) |
7990 | { | |
7991 | struct i802_bss *bss = priv; | |
7992 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
7993 | int new_addr = addr != NULL; | |
7994 | ||
7995 | if (!addr) | |
7996 | addr = drv->perm_addr; | |
7997 | ||
7998 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 0) < 0) | |
7999 | return -1; | |
8000 | ||
8001 | if (linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname, addr) < 0) | |
8002 | { | |
8003 | wpa_printf(MSG_DEBUG, | |
8004 | "nl80211: failed to set_mac_addr for %s to " MACSTR, | |
8005 | bss->ifname, MAC2STR(addr)); | |
8006 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, | |
8007 | 1) < 0) { | |
8008 | wpa_printf(MSG_DEBUG, | |
8009 | "nl80211: Could not restore interface UP after failed set_mac_addr"); | |
8010 | } | |
8011 | return -1; | |
8012 | } | |
8013 | ||
8014 | wpa_printf(MSG_DEBUG, "nl80211: set_mac_addr for %s to " MACSTR, | |
8015 | bss->ifname, MAC2STR(addr)); | |
8016 | drv->addr_changed = new_addr; | |
8017 | os_memcpy(bss->addr, addr, ETH_ALEN); | |
8018 | ||
8019 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 1) < 0) | |
8020 | { | |
8021 | wpa_printf(MSG_DEBUG, | |
8022 | "nl80211: Could not restore interface UP after set_mac_addr"); | |
8023 | } | |
8024 | ||
8025 | return 0; | |
8026 | } | |
8027 | ||
8028 | ||
6c1664f6 BC |
8029 | #ifdef CONFIG_MESH |
8030 | ||
8031 | static int wpa_driver_nl80211_init_mesh(void *priv) | |
8032 | { | |
8033 | if (wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_MESH_POINT)) { | |
8034 | wpa_printf(MSG_INFO, | |
8035 | "nl80211: Failed to set interface into mesh mode"); | |
8036 | return -1; | |
8037 | } | |
8038 | return 0; | |
8039 | } | |
8040 | ||
8041 | ||
21c74e84 JM |
8042 | static int nl80211_put_mesh_id(struct nl_msg *msg, const u8 *mesh_id, |
8043 | size_t mesh_id_len) | |
8044 | { | |
8045 | if (mesh_id) { | |
8046 | wpa_hexdump_ascii(MSG_DEBUG, " * Mesh ID (SSID)", | |
8047 | mesh_id, mesh_id_len); | |
8048 | return nla_put(msg, NL80211_ATTR_MESH_ID, mesh_id_len, mesh_id); | |
8049 | } | |
8050 | ||
8051 | return 0; | |
8052 | } | |
8053 | ||
8054 | ||
0cb5f8d9 | 8055 | static int nl80211_join_mesh(struct i802_bss *bss, |
6c1664f6 BC |
8056 | struct wpa_driver_mesh_join_params *params) |
8057 | { | |
6c1664f6 BC |
8058 | struct wpa_driver_nl80211_data *drv = bss->drv; |
8059 | struct nl_msg *msg; | |
8060 | struct nlattr *container; | |
7451a217 | 8061 | int ret = -1; |
6c1664f6 | 8062 | |
6c1664f6 | 8063 | wpa_printf(MSG_DEBUG, "nl80211: mesh join (ifindex=%d)", drv->ifindex); |
9725b784 | 8064 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_JOIN_MESH); |
f7e889fa JM |
8065 | if (!msg || |
8066 | nl80211_put_freq_params(msg, ¶ms->freq) || | |
21c74e84 JM |
8067 | nl80211_put_basic_rates(msg, params->basic_rates) || |
8068 | nl80211_put_mesh_id(msg, params->meshid, params->meshid_len) || | |
8069 | nl80211_put_beacon_int(msg, params->beacon_int)) | |
85e1fad8 | 8070 | goto fail; |
9c58c5f7 | 8071 | |
6c1664f6 BC |
8072 | wpa_printf(MSG_DEBUG, " * flags=%08X", params->flags); |
8073 | ||
8074 | container = nla_nest_start(msg, NL80211_ATTR_MESH_SETUP); | |
8075 | if (!container) | |
a862e4a3 | 8076 | goto fail; |
6c1664f6 BC |
8077 | |
8078 | if (params->ies) { | |
8079 | wpa_hexdump(MSG_DEBUG, " * IEs", params->ies, params->ie_len); | |
a862e4a3 JM |
8080 | if (nla_put(msg, NL80211_MESH_SETUP_IE, params->ie_len, |
8081 | params->ies)) | |
8082 | goto fail; | |
6c1664f6 BC |
8083 | } |
8084 | /* WPA_DRIVER_MESH_FLAG_OPEN_AUTH is treated as default by nl80211 */ | |
8085 | if (params->flags & WPA_DRIVER_MESH_FLAG_SAE_AUTH) { | |
a862e4a3 JM |
8086 | if (nla_put_u8(msg, NL80211_MESH_SETUP_AUTH_PROTOCOL, 0x1) || |
8087 | nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_AUTH)) | |
8088 | goto fail; | |
6c1664f6 | 8089 | } |
a862e4a3 JM |
8090 | if ((params->flags & WPA_DRIVER_MESH_FLAG_AMPE) && |
8091 | nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_AMPE)) | |
8092 | goto fail; | |
8093 | if ((params->flags & WPA_DRIVER_MESH_FLAG_USER_MPM) && | |
8094 | nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_MPM)) | |
8095 | goto fail; | |
6c1664f6 BC |
8096 | nla_nest_end(msg, container); |
8097 | ||
8098 | container = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); | |
8099 | if (!container) | |
a862e4a3 | 8100 | goto fail; |
6c1664f6 | 8101 | |
a862e4a3 JM |
8102 | if (!(params->conf.flags & WPA_DRIVER_MESH_CONF_FLAG_AUTO_PLINKS) && |
8103 | nla_put_u32(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, 0)) | |
8104 | goto fail; | |
4b409368 MH |
8105 | if ((params->conf.flags & WPA_DRIVER_MESH_FLAG_DRIVER_MPM) && |
8106 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, | |
8107 | params->max_peer_links)) | |
8108 | goto fail; | |
5a2a6de6 MH |
8109 | |
8110 | /* | |
8111 | * Set NL80211_MESHCONF_PLINK_TIMEOUT even if user mpm is used because | |
8112 | * the timer could disconnect stations even in that case. | |
5a2a6de6 | 8113 | */ |
0cb5f8d9 MH |
8114 | if (nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, |
8115 | params->conf.peer_link_timeout)) { | |
5a2a6de6 MH |
8116 | wpa_printf(MSG_ERROR, "nl80211: Failed to set PLINK_TIMEOUT"); |
8117 | goto fail; | |
8118 | } | |
8119 | ||
6c1664f6 BC |
8120 | nla_nest_end(msg, container); |
8121 | ||
8122 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
8123 | msg = NULL; | |
8124 | if (ret) { | |
8125 | wpa_printf(MSG_DEBUG, "nl80211: mesh join failed: ret=%d (%s)", | |
8126 | ret, strerror(-ret)); | |
a862e4a3 | 8127 | goto fail; |
6c1664f6 BC |
8128 | } |
8129 | ret = 0; | |
f7e889fa | 8130 | bss->freq = params->freq.freq; |
6c1664f6 BC |
8131 | wpa_printf(MSG_DEBUG, "nl80211: mesh join request send successfully"); |
8132 | ||
a862e4a3 | 8133 | fail: |
6c1664f6 BC |
8134 | nlmsg_free(msg); |
8135 | return ret; | |
8136 | } | |
8137 | ||
8138 | ||
0cb5f8d9 MH |
8139 | static int |
8140 | wpa_driver_nl80211_join_mesh(void *priv, | |
8141 | struct wpa_driver_mesh_join_params *params) | |
8142 | { | |
8143 | struct i802_bss *bss = priv; | |
8144 | int ret, timeout; | |
8145 | ||
8146 | timeout = params->conf.peer_link_timeout; | |
8147 | ||
8148 | /* Disable kernel inactivity timer */ | |
8149 | if (params->flags & WPA_DRIVER_MESH_FLAG_USER_MPM) | |
8150 | params->conf.peer_link_timeout = 0; | |
8151 | ||
8152 | ret = nl80211_join_mesh(bss, params); | |
8153 | if (ret == -EINVAL && params->conf.peer_link_timeout == 0) { | |
8154 | wpa_printf(MSG_DEBUG, | |
8155 | "nl80211: Mesh join retry for peer_link_timeout"); | |
8156 | /* | |
8157 | * Old kernel does not support setting | |
8158 | * NL80211_MESHCONF_PLINK_TIMEOUT to zero, so set 60 seconds | |
8159 | * into future from peer_link_timeout. | |
8160 | */ | |
8161 | params->conf.peer_link_timeout = timeout + 60; | |
8162 | ret = nl80211_join_mesh(priv, params); | |
8163 | } | |
8164 | ||
8165 | params->conf.peer_link_timeout = timeout; | |
8166 | return ret; | |
8167 | } | |
8168 | ||
8169 | ||
6c1664f6 BC |
8170 | static int wpa_driver_nl80211_leave_mesh(void *priv) |
8171 | { | |
8172 | struct i802_bss *bss = priv; | |
8173 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8174 | struct nl_msg *msg; | |
9725b784 | 8175 | int ret; |
6c1664f6 BC |
8176 | |
8177 | wpa_printf(MSG_DEBUG, "nl80211: mesh leave (ifindex=%d)", drv->ifindex); | |
9725b784 | 8178 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_LEAVE_MESH); |
6c1664f6 | 8179 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
6c1664f6 BC |
8180 | if (ret) { |
8181 | wpa_printf(MSG_DEBUG, "nl80211: mesh leave failed: ret=%d (%s)", | |
8182 | ret, strerror(-ret)); | |
a862e4a3 JM |
8183 | } else { |
8184 | wpa_printf(MSG_DEBUG, | |
8185 | "nl80211: mesh leave request send successfully"); | |
6c1664f6 | 8186 | } |
6c1664f6 | 8187 | |
f33c82d2 JM |
8188 | if (wpa_driver_nl80211_set_mode(drv->first_bss, |
8189 | NL80211_IFTYPE_STATION)) { | |
8190 | wpa_printf(MSG_INFO, | |
8191 | "nl80211: Failed to set interface into station mode"); | |
8192 | } | |
6c1664f6 BC |
8193 | return ret; |
8194 | } | |
8195 | ||
8196 | #endif /* CONFIG_MESH */ | |
8197 | ||
8198 | ||
ed4ddb6d KP |
8199 | static int wpa_driver_br_add_ip_neigh(void *priv, u8 version, |
8200 | const u8 *ipaddr, int prefixlen, | |
8201 | const u8 *addr) | |
71103bed KP |
8202 | { |
8203 | #ifdef CONFIG_LIBNL3_ROUTE | |
8204 | struct i802_bss *bss = priv; | |
8205 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8206 | struct rtnl_neigh *rn; | |
8207 | struct nl_addr *nl_ipaddr = NULL; | |
8208 | struct nl_addr *nl_lladdr = NULL; | |
ed4ddb6d | 8209 | int family, addrsize; |
71103bed KP |
8210 | int res; |
8211 | ||
ed4ddb6d | 8212 | if (!ipaddr || prefixlen == 0 || !addr) |
71103bed KP |
8213 | return -EINVAL; |
8214 | ||
8215 | if (bss->br_ifindex == 0) { | |
8216 | wpa_printf(MSG_DEBUG, | |
8217 | "nl80211: bridge must be set before adding an ip neigh to it"); | |
8218 | return -1; | |
8219 | } | |
8220 | ||
8221 | if (!drv->rtnl_sk) { | |
8222 | wpa_printf(MSG_DEBUG, | |
8223 | "nl80211: nl_sock for NETLINK_ROUTE is not initialized"); | |
8224 | return -1; | |
8225 | } | |
8226 | ||
ed4ddb6d KP |
8227 | if (version == 4) { |
8228 | family = AF_INET; | |
8229 | addrsize = 4; | |
8230 | } else if (version == 6) { | |
8231 | family = AF_INET6; | |
8232 | addrsize = 16; | |
8233 | } else { | |
8234 | return -EINVAL; | |
8235 | } | |
8236 | ||
71103bed KP |
8237 | rn = rtnl_neigh_alloc(); |
8238 | if (rn == NULL) | |
8239 | return -ENOMEM; | |
8240 | ||
8241 | /* set the destination ip address for neigh */ | |
ed4ddb6d | 8242 | nl_ipaddr = nl_addr_build(family, (void *) ipaddr, addrsize); |
71103bed KP |
8243 | if (nl_ipaddr == NULL) { |
8244 | wpa_printf(MSG_DEBUG, "nl80211: nl_ipaddr build failed"); | |
8245 | res = -ENOMEM; | |
8246 | goto errout; | |
8247 | } | |
8248 | nl_addr_set_prefixlen(nl_ipaddr, prefixlen); | |
8249 | res = rtnl_neigh_set_dst(rn, nl_ipaddr); | |
8250 | if (res) { | |
8251 | wpa_printf(MSG_DEBUG, | |
8252 | "nl80211: neigh set destination addr failed"); | |
8253 | goto errout; | |
8254 | } | |
8255 | ||
8256 | /* set the corresponding lladdr for neigh */ | |
8257 | nl_lladdr = nl_addr_build(AF_BRIDGE, (u8 *) addr, ETH_ALEN); | |
8258 | if (nl_lladdr == NULL) { | |
8259 | wpa_printf(MSG_DEBUG, "nl80211: neigh set lladdr failed"); | |
8260 | res = -ENOMEM; | |
8261 | goto errout; | |
8262 | } | |
8263 | rtnl_neigh_set_lladdr(rn, nl_lladdr); | |
8264 | ||
8265 | rtnl_neigh_set_ifindex(rn, bss->br_ifindex); | |
8266 | rtnl_neigh_set_state(rn, NUD_PERMANENT); | |
8267 | ||
8268 | res = rtnl_neigh_add(drv->rtnl_sk, rn, NLM_F_CREATE); | |
8269 | if (res) { | |
8270 | wpa_printf(MSG_DEBUG, | |
8271 | "nl80211: Adding bridge ip neigh failed: %s", | |
8272 | strerror(errno)); | |
8273 | } | |
8274 | errout: | |
8275 | if (nl_lladdr) | |
8276 | nl_addr_put(nl_lladdr); | |
8277 | if (nl_ipaddr) | |
8278 | nl_addr_put(nl_ipaddr); | |
8279 | if (rn) | |
8280 | rtnl_neigh_put(rn); | |
8281 | return res; | |
8282 | #else /* CONFIG_LIBNL3_ROUTE */ | |
8283 | return -1; | |
8284 | #endif /* CONFIG_LIBNL3_ROUTE */ | |
8285 | } | |
8286 | ||
8287 | ||
ed4ddb6d KP |
8288 | static int wpa_driver_br_delete_ip_neigh(void *priv, u8 version, |
8289 | const u8 *ipaddr) | |
71103bed KP |
8290 | { |
8291 | #ifdef CONFIG_LIBNL3_ROUTE | |
8292 | struct i802_bss *bss = priv; | |
8293 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8294 | struct rtnl_neigh *rn; | |
8295 | struct nl_addr *nl_ipaddr; | |
ed4ddb6d | 8296 | int family, addrsize; |
71103bed KP |
8297 | int res; |
8298 | ||
ed4ddb6d | 8299 | if (!ipaddr) |
71103bed KP |
8300 | return -EINVAL; |
8301 | ||
ed4ddb6d KP |
8302 | if (version == 4) { |
8303 | family = AF_INET; | |
8304 | addrsize = 4; | |
8305 | } else if (version == 6) { | |
8306 | family = AF_INET6; | |
8307 | addrsize = 16; | |
8308 | } else { | |
8309 | return -EINVAL; | |
8310 | } | |
8311 | ||
71103bed KP |
8312 | if (bss->br_ifindex == 0) { |
8313 | wpa_printf(MSG_DEBUG, | |
8314 | "nl80211: bridge must be set to delete an ip neigh"); | |
8315 | return -1; | |
8316 | } | |
8317 | ||
8318 | if (!drv->rtnl_sk) { | |
8319 | wpa_printf(MSG_DEBUG, | |
8320 | "nl80211: nl_sock for NETLINK_ROUTE is not initialized"); | |
8321 | return -1; | |
8322 | } | |
8323 | ||
8324 | rn = rtnl_neigh_alloc(); | |
8325 | if (rn == NULL) | |
8326 | return -ENOMEM; | |
8327 | ||
8328 | /* set the destination ip address for neigh */ | |
ed4ddb6d | 8329 | nl_ipaddr = nl_addr_build(family, (void *) ipaddr, addrsize); |
71103bed KP |
8330 | if (nl_ipaddr == NULL) { |
8331 | wpa_printf(MSG_DEBUG, "nl80211: nl_ipaddr build failed"); | |
8332 | res = -ENOMEM; | |
8333 | goto errout; | |
8334 | } | |
8335 | res = rtnl_neigh_set_dst(rn, nl_ipaddr); | |
8336 | if (res) { | |
8337 | wpa_printf(MSG_DEBUG, | |
8338 | "nl80211: neigh set destination addr failed"); | |
8339 | goto errout; | |
8340 | } | |
8341 | ||
8342 | rtnl_neigh_set_ifindex(rn, bss->br_ifindex); | |
8343 | ||
8344 | res = rtnl_neigh_delete(drv->rtnl_sk, rn, 0); | |
8345 | if (res) { | |
8346 | wpa_printf(MSG_DEBUG, | |
8347 | "nl80211: Deleting bridge ip neigh failed: %s", | |
8348 | strerror(errno)); | |
8349 | } | |
8350 | errout: | |
8351 | if (nl_ipaddr) | |
8352 | nl_addr_put(nl_ipaddr); | |
8353 | if (rn) | |
8354 | rtnl_neigh_put(rn); | |
8355 | return res; | |
8356 | #else /* CONFIG_LIBNL3_ROUTE */ | |
8357 | return -1; | |
8358 | #endif /* CONFIG_LIBNL3_ROUTE */ | |
8359 | } | |
8360 | ||
8361 | ||
73d2294f KP |
8362 | static int linux_write_system_file(const char *path, unsigned int val) |
8363 | { | |
8364 | char buf[50]; | |
8365 | int fd, len; | |
8366 | ||
8367 | len = os_snprintf(buf, sizeof(buf), "%u\n", val); | |
a9aaacbb | 8368 | if (os_snprintf_error(sizeof(buf), len)) |
73d2294f KP |
8369 | return -1; |
8370 | ||
8371 | fd = open(path, O_WRONLY); | |
8372 | if (fd < 0) | |
8373 | return -1; | |
8374 | ||
8375 | if (write(fd, buf, len) < 0) { | |
8376 | wpa_printf(MSG_DEBUG, | |
8377 | "nl80211: Failed to write Linux system file: %s with the value of %d", | |
8378 | path, val); | |
8379 | close(fd); | |
8380 | return -1; | |
8381 | } | |
8382 | close(fd); | |
8383 | ||
8384 | return 0; | |
8385 | } | |
8386 | ||
8387 | ||
8388 | static const char * drv_br_port_attr_str(enum drv_br_port_attr attr) | |
8389 | { | |
8390 | switch (attr) { | |
8391 | case DRV_BR_PORT_ATTR_PROXYARP: | |
bea8d9a3 | 8392 | return "proxyarp_wifi"; |
73d2294f KP |
8393 | case DRV_BR_PORT_ATTR_HAIRPIN_MODE: |
8394 | return "hairpin_mode"; | |
8395 | } | |
8396 | ||
8397 | return NULL; | |
8398 | } | |
8399 | ||
8400 | ||
8401 | static int wpa_driver_br_port_set_attr(void *priv, enum drv_br_port_attr attr, | |
8402 | unsigned int val) | |
8403 | { | |
8404 | struct i802_bss *bss = priv; | |
8405 | char path[128]; | |
8406 | const char *attr_txt; | |
8407 | ||
8408 | attr_txt = drv_br_port_attr_str(attr); | |
8409 | if (attr_txt == NULL) | |
8410 | return -EINVAL; | |
8411 | ||
8412 | os_snprintf(path, sizeof(path), "/sys/class/net/%s/brport/%s", | |
8413 | bss->ifname, attr_txt); | |
8414 | ||
8415 | if (linux_write_system_file(path, val)) | |
8416 | return -1; | |
8417 | ||
8418 | return 0; | |
8419 | } | |
8420 | ||
8421 | ||
7565752d KP |
8422 | static const char * drv_br_net_param_str(enum drv_br_net_param param) |
8423 | { | |
8424 | switch (param) { | |
8425 | case DRV_BR_NET_PARAM_GARP_ACCEPT: | |
8426 | return "arp_accept"; | |
60eb9e17 JM |
8427 | default: |
8428 | return NULL; | |
7565752d | 8429 | } |
7565752d KP |
8430 | } |
8431 | ||
8432 | ||
8433 | static int wpa_driver_br_set_net_param(void *priv, enum drv_br_net_param param, | |
8434 | unsigned int val) | |
8435 | { | |
8436 | struct i802_bss *bss = priv; | |
8437 | char path[128]; | |
8438 | const char *param_txt; | |
8439 | int ip_version = 4; | |
8440 | ||
60eb9e17 JM |
8441 | if (param == DRV_BR_MULTICAST_SNOOPING) { |
8442 | os_snprintf(path, sizeof(path), | |
8443 | "/sys/devices/virtual/net/%s/bridge/multicast_snooping", | |
8444 | bss->brname); | |
8445 | goto set_val; | |
8446 | } | |
8447 | ||
7565752d KP |
8448 | param_txt = drv_br_net_param_str(param); |
8449 | if (param_txt == NULL) | |
8450 | return -EINVAL; | |
8451 | ||
8452 | switch (param) { | |
8453 | case DRV_BR_NET_PARAM_GARP_ACCEPT: | |
8454 | ip_version = 4; | |
8455 | break; | |
8456 | default: | |
8457 | return -EINVAL; | |
8458 | } | |
8459 | ||
8460 | os_snprintf(path, sizeof(path), "/proc/sys/net/ipv%d/conf/%s/%s", | |
8461 | ip_version, bss->brname, param_txt); | |
8462 | ||
60eb9e17 | 8463 | set_val: |
7565752d KP |
8464 | if (linux_write_system_file(path, val)) |
8465 | return -1; | |
8466 | ||
8467 | return 0; | |
8468 | } | |
8469 | ||
8470 | ||
b658547d JM |
8471 | #ifdef CONFIG_DRIVER_NL80211_QCA |
8472 | ||
16689c7c PX |
8473 | static int hw_mode_to_qca_acs(enum hostapd_hw_mode hw_mode) |
8474 | { | |
8475 | switch (hw_mode) { | |
8476 | case HOSTAPD_MODE_IEEE80211B: | |
8477 | return QCA_ACS_MODE_IEEE80211B; | |
8478 | case HOSTAPD_MODE_IEEE80211G: | |
8479 | return QCA_ACS_MODE_IEEE80211G; | |
8480 | case HOSTAPD_MODE_IEEE80211A: | |
8481 | return QCA_ACS_MODE_IEEE80211A; | |
8482 | case HOSTAPD_MODE_IEEE80211AD: | |
8483 | return QCA_ACS_MODE_IEEE80211AD; | |
3784c058 PX |
8484 | case HOSTAPD_MODE_IEEE80211ANY: |
8485 | return QCA_ACS_MODE_IEEE80211ANY; | |
16689c7c PX |
8486 | default: |
8487 | return -1; | |
8488 | } | |
8489 | } | |
8490 | ||
8491 | ||
d0cdccd3 PX |
8492 | static int add_acs_freq_list(struct nl_msg *msg, const int *freq_list) |
8493 | { | |
8494 | int i, len, ret; | |
8495 | u32 *freqs; | |
8496 | ||
8497 | if (!freq_list) | |
8498 | return 0; | |
8499 | len = int_array_len(freq_list); | |
8500 | freqs = os_malloc(sizeof(u32) * len); | |
8501 | if (!freqs) | |
8502 | return -1; | |
8503 | for (i = 0; i < len; i++) | |
8504 | freqs[i] = freq_list[i]; | |
8505 | ret = nla_put(msg, QCA_WLAN_VENDOR_ATTR_ACS_FREQ_LIST, | |
8506 | sizeof(u32) * len, freqs); | |
8507 | os_free(freqs); | |
8508 | return ret; | |
8509 | } | |
8510 | ||
8511 | ||
16689c7c PX |
8512 | static int wpa_driver_do_acs(void *priv, struct drv_acs_params *params) |
8513 | { | |
8514 | struct i802_bss *bss = priv; | |
8515 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8516 | struct nl_msg *msg; | |
8517 | struct nlattr *data; | |
a862e4a3 | 8518 | int ret; |
16689c7c PX |
8519 | int mode; |
8520 | ||
8521 | mode = hw_mode_to_qca_acs(params->hw_mode); | |
8522 | if (mode < 0) | |
8523 | return -1; | |
8524 | ||
9725b784 | 8525 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
a862e4a3 JM |
8526 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
8527 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | |
8528 | QCA_NL80211_VENDOR_SUBCMD_DO_ACS) || | |
8529 | !(data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || | |
8530 | nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_ACS_HW_MODE, mode) || | |
8531 | (params->ht_enabled && | |
8532 | nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_HT_ENABLED)) || | |
8533 | (params->ht40_enabled && | |
857d9422 MM |
8534 | nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_HT40_ENABLED)) || |
8535 | (params->vht_enabled && | |
8536 | nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_VHT_ENABLED)) || | |
8537 | nla_put_u16(msg, QCA_WLAN_VENDOR_ATTR_ACS_CHWIDTH, | |
8538 | params->ch_width) || | |
8539 | (params->ch_list_len && | |
8540 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_ACS_CH_LIST, params->ch_list_len, | |
d0cdccd3 PX |
8541 | params->ch_list)) || |
8542 | add_acs_freq_list(msg, params->freq_list)) { | |
a862e4a3 JM |
8543 | nlmsg_free(msg); |
8544 | return -ENOBUFS; | |
8545 | } | |
16689c7c PX |
8546 | nla_nest_end(msg, data); |
8547 | ||
857d9422 MM |
8548 | wpa_printf(MSG_DEBUG, |
8549 | "nl80211: ACS Params: HW_MODE: %d HT: %d HT40: %d VHT: %d BW: %d CH_LIST_LEN: %u", | |
8550 | params->hw_mode, params->ht_enabled, params->ht40_enabled, | |
8551 | params->vht_enabled, params->ch_width, params->ch_list_len); | |
8552 | ||
16689c7c | 8553 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
16689c7c PX |
8554 | if (ret) { |
8555 | wpa_printf(MSG_DEBUG, | |
8556 | "nl80211: Failed to invoke driver ACS function: %s", | |
8557 | strerror(errno)); | |
8558 | } | |
16689c7c PX |
8559 | return ret; |
8560 | } | |
8561 | ||
8562 | ||
844dfeb8 SD |
8563 | static int nl80211_set_band(void *priv, enum set_band band) |
8564 | { | |
8565 | struct i802_bss *bss = priv; | |
8566 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8567 | struct nl_msg *msg; | |
8568 | struct nlattr *data; | |
8569 | int ret; | |
8570 | enum qca_set_band qca_band; | |
8571 | ||
8572 | if (!drv->setband_vendor_cmd_avail) | |
8573 | return -1; | |
8574 | ||
8575 | switch (band) { | |
8576 | case WPA_SETBAND_AUTO: | |
8577 | qca_band = QCA_SETBAND_AUTO; | |
8578 | break; | |
8579 | case WPA_SETBAND_5G: | |
8580 | qca_band = QCA_SETBAND_5G; | |
8581 | break; | |
8582 | case WPA_SETBAND_2G: | |
8583 | qca_band = QCA_SETBAND_2G; | |
8584 | break; | |
8585 | default: | |
8586 | return -1; | |
8587 | } | |
8588 | ||
8589 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || | |
8590 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || | |
8591 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | |
8592 | QCA_NL80211_VENDOR_SUBCMD_SETBAND) || | |
8593 | !(data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || | |
8594 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_SETBAND_VALUE, qca_band)) { | |
8595 | nlmsg_free(msg); | |
8596 | return -ENOBUFS; | |
8597 | } | |
8598 | nla_nest_end(msg, data); | |
8599 | ||
8600 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
8601 | if (ret) { | |
8602 | wpa_printf(MSG_DEBUG, | |
8603 | "nl80211: Driver setband function failed: %s", | |
8604 | strerror(errno)); | |
8605 | } | |
8606 | return ret; | |
8607 | } | |
8608 | ||
8609 | ||
98342208 AK |
8610 | struct nl80211_pcl { |
8611 | unsigned int num; | |
8612 | unsigned int *freq_list; | |
8613 | }; | |
8614 | ||
8615 | static int preferred_freq_info_handler(struct nl_msg *msg, void *arg) | |
8616 | { | |
8617 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
8618 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
8619 | struct nl80211_pcl *param = arg; | |
8620 | struct nlattr *nl_vend, *attr; | |
8621 | enum qca_iface_type iface_type; | |
8622 | struct nlattr *tb_vendor[QCA_WLAN_VENDOR_ATTR_MAX + 1]; | |
8623 | unsigned int num, max_num; | |
8624 | u32 *freqs; | |
8625 | ||
8626 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
8627 | genlmsg_attrlen(gnlh, 0), NULL); | |
8628 | ||
8629 | nl_vend = tb[NL80211_ATTR_VENDOR_DATA]; | |
8630 | if (!nl_vend) | |
8631 | return NL_SKIP; | |
8632 | ||
8633 | nla_parse(tb_vendor, QCA_WLAN_VENDOR_ATTR_MAX, | |
8634 | nla_data(nl_vend), nla_len(nl_vend), NULL); | |
8635 | ||
8636 | attr = tb_vendor[ | |
8637 | QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST_IFACE_TYPE]; | |
8638 | if (!attr) { | |
8639 | wpa_printf(MSG_ERROR, "nl80211: iface_type couldn't be found"); | |
8640 | param->num = 0; | |
8641 | return NL_SKIP; | |
8642 | } | |
8643 | ||
8644 | iface_type = (enum qca_iface_type) nla_get_u32(attr); | |
8645 | wpa_printf(MSG_DEBUG, "nl80211: Driver returned iface_type=%d", | |
8646 | iface_type); | |
8647 | ||
8648 | attr = tb_vendor[QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST]; | |
8649 | if (!attr) { | |
8650 | wpa_printf(MSG_ERROR, | |
8651 | "nl80211: preferred_freq_list couldn't be found"); | |
8652 | param->num = 0; | |
8653 | return NL_SKIP; | |
8654 | } | |
8655 | ||
8656 | /* | |
8657 | * param->num has the maximum number of entries for which there | |
8658 | * is room in the freq_list provided by the caller. | |
8659 | */ | |
8660 | freqs = nla_data(attr); | |
8661 | max_num = nla_len(attr) / sizeof(u32); | |
8662 | if (max_num > param->num) | |
8663 | max_num = param->num; | |
8664 | for (num = 0; num < max_num; num++) | |
8665 | param->freq_list[num] = freqs[num]; | |
8666 | param->num = num; | |
8667 | ||
8668 | return NL_SKIP; | |
8669 | } | |
8670 | ||
8671 | ||
8672 | static int nl80211_get_pref_freq_list(void *priv, | |
8673 | enum wpa_driver_if_type if_type, | |
8674 | unsigned int *num, | |
8675 | unsigned int *freq_list) | |
8676 | { | |
8677 | struct i802_bss *bss = priv; | |
8678 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8679 | struct nl_msg *msg; | |
8680 | int ret; | |
8681 | unsigned int i; | |
8682 | struct nlattr *params; | |
8683 | struct nl80211_pcl param; | |
8684 | enum qca_iface_type iface_type; | |
8685 | ||
8686 | if (!drv->get_pref_freq_list) | |
8687 | return -1; | |
8688 | ||
8689 | switch (if_type) { | |
8690 | case WPA_IF_STATION: | |
8691 | iface_type = QCA_IFACE_TYPE_STA; | |
8692 | break; | |
8693 | case WPA_IF_AP_BSS: | |
8694 | iface_type = QCA_IFACE_TYPE_AP; | |
8695 | break; | |
8696 | case WPA_IF_P2P_GO: | |
8697 | iface_type = QCA_IFACE_TYPE_P2P_GO; | |
8698 | break; | |
8699 | case WPA_IF_P2P_CLIENT: | |
8700 | iface_type = QCA_IFACE_TYPE_P2P_CLIENT; | |
8701 | break; | |
8702 | case WPA_IF_IBSS: | |
8703 | iface_type = QCA_IFACE_TYPE_IBSS; | |
8704 | break; | |
8705 | case WPA_IF_TDLS: | |
8706 | iface_type = QCA_IFACE_TYPE_TDLS; | |
8707 | break; | |
8708 | default: | |
8709 | return -1; | |
8710 | } | |
8711 | ||
8712 | param.num = *num; | |
8713 | param.freq_list = freq_list; | |
8714 | ||
8715 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || | |
8716 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, drv->ifindex) || | |
8717 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || | |
8718 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | |
8719 | QCA_NL80211_VENDOR_SUBCMD_GET_PREFERRED_FREQ_LIST) || | |
8720 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || | |
8721 | nla_put_u32(msg, | |
8722 | QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST_IFACE_TYPE, | |
8723 | iface_type)) { | |
8724 | wpa_printf(MSG_ERROR, | |
8725 | "%s: err in adding vendor_cmd and vendor_data", | |
8726 | __func__); | |
8727 | nlmsg_free(msg); | |
8728 | return -1; | |
8729 | } | |
8730 | nla_nest_end(msg, params); | |
8731 | ||
8732 | os_memset(freq_list, 0, *num * sizeof(freq_list[0])); | |
8733 | ret = send_and_recv_msgs(drv, msg, preferred_freq_info_handler, ¶m); | |
8734 | if (ret) { | |
8735 | wpa_printf(MSG_ERROR, | |
8736 | "%s: err in send_and_recv_msgs", __func__); | |
8737 | return ret; | |
8738 | } | |
8739 | ||
8740 | *num = param.num; | |
8741 | ||
8742 | for (i = 0; i < *num; i++) { | |
8743 | wpa_printf(MSG_DEBUG, "nl80211: preferred_channel_list[%d]=%d", | |
8744 | i, freq_list[i]); | |
8745 | } | |
8746 | ||
8747 | return 0; | |
8748 | } | |
8749 | ||
8750 | ||
7c813acf AK |
8751 | static int nl80211_set_prob_oper_freq(void *priv, unsigned int freq) |
8752 | { | |
8753 | struct i802_bss *bss = priv; | |
8754 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8755 | struct nl_msg *msg; | |
8756 | int ret; | |
8757 | struct nlattr *params; | |
8758 | ||
8759 | if (!drv->set_prob_oper_freq) | |
8760 | return -1; | |
8761 | ||
8762 | wpa_printf(MSG_DEBUG, | |
8763 | "nl80211: Set P2P probable operating freq %u for ifindex %d", | |
8764 | freq, bss->ifindex); | |
8765 | ||
8766 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || | |
8767 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || | |
8768 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | |
8769 | QCA_NL80211_VENDOR_SUBCMD_SET_PROBABLE_OPER_CHANNEL) || | |
8770 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || | |
8771 | nla_put_u32(msg, | |
8772 | QCA_WLAN_VENDOR_ATTR_PROBABLE_OPER_CHANNEL_IFACE_TYPE, | |
8773 | QCA_IFACE_TYPE_P2P_CLIENT) || | |
8774 | nla_put_u32(msg, | |
8775 | QCA_WLAN_VENDOR_ATTR_PROBABLE_OPER_CHANNEL_FREQ, | |
8776 | freq)) { | |
8777 | wpa_printf(MSG_ERROR, | |
8778 | "%s: err in adding vendor_cmd and vendor_data", | |
8779 | __func__); | |
8780 | nlmsg_free(msg); | |
8781 | return -1; | |
8782 | } | |
8783 | nla_nest_end(msg, params); | |
8784 | ||
8785 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
8786 | msg = NULL; | |
8787 | if (ret) { | |
8788 | wpa_printf(MSG_ERROR, "%s: err in send_and_recv_msgs", | |
8789 | __func__); | |
8790 | return ret; | |
8791 | } | |
8792 | nlmsg_free(msg); | |
8793 | return 0; | |
8794 | } | |
8795 | ||
b658547d JM |
8796 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
8797 | ||
7c813acf | 8798 | |
3f5285e8 JM |
8799 | const struct wpa_driver_ops wpa_driver_nl80211_ops = { |
8800 | .name = "nl80211", | |
8801 | .desc = "Linux nl80211/cfg80211", | |
8802 | .get_bssid = wpa_driver_nl80211_get_bssid, | |
8803 | .get_ssid = wpa_driver_nl80211_get_ssid, | |
9ebce9c5 JM |
8804 | .set_key = driver_nl80211_set_key, |
8805 | .scan2 = driver_nl80211_scan2, | |
d21c63b9 LC |
8806 | .sched_scan = wpa_driver_nl80211_sched_scan, |
8807 | .stop_sched_scan = wpa_driver_nl80211_stop_sched_scan, | |
3f5285e8 | 8808 | .get_scan_results2 = wpa_driver_nl80211_get_scan_results, |
4f30addb | 8809 | .abort_scan = wpa_driver_nl80211_abort_scan, |
9ebce9c5 JM |
8810 | .deauthenticate = driver_nl80211_deauthenticate, |
8811 | .authenticate = driver_nl80211_authenticate, | |
3f5285e8 | 8812 | .associate = wpa_driver_nl80211_associate, |
f2ed8023 JM |
8813 | .global_init = nl80211_global_init, |
8814 | .global_deinit = nl80211_global_deinit, | |
8815 | .init2 = wpa_driver_nl80211_init, | |
9ebce9c5 | 8816 | .deinit = driver_nl80211_deinit, |
3f5285e8 JM |
8817 | .get_capa = wpa_driver_nl80211_get_capa, |
8818 | .set_operstate = wpa_driver_nl80211_set_operstate, | |
01652550 | 8819 | .set_supp_port = wpa_driver_nl80211_set_supp_port, |
6d158490 | 8820 | .set_country = wpa_driver_nl80211_set_country, |
f0793bf1 | 8821 | .get_country = wpa_driver_nl80211_get_country, |
19c3b566 | 8822 | .set_ap = wpa_driver_nl80211_set_ap, |
3c4ca363 | 8823 | .set_acl = wpa_driver_nl80211_set_acl, |
22a7c9d7 | 8824 | .if_add = wpa_driver_nl80211_if_add, |
9ebce9c5 JM |
8825 | .if_remove = driver_nl80211_if_remove, |
8826 | .send_mlme = driver_nl80211_send_mlme, | |
0fafeb54 | 8827 | .get_hw_feature_data = nl80211_get_hw_feature_data, |
0f4e8b4f | 8828 | .sta_add = wpa_driver_nl80211_sta_add, |
9ebce9c5 | 8829 | .sta_remove = driver_nl80211_sta_remove, |
db149ac9 | 8830 | .hapd_send_eapol = wpa_driver_nl80211_hapd_send_eapol, |
a8d6ffa4 | 8831 | .sta_set_flags = wpa_driver_nl80211_sta_set_flags, |
c5121837 | 8832 | .hapd_init = i802_init, |
c5121837 | 8833 | .hapd_deinit = i802_deinit, |
f7b3920c | 8834 | .set_wds_sta = i802_set_wds_sta, |
c5121837 JM |
8835 | .get_seqnum = i802_get_seqnum, |
8836 | .flush = i802_flush, | |
c5121837 JM |
8837 | .get_inact_sec = i802_get_inact_sec, |
8838 | .sta_clear_stats = i802_sta_clear_stats, | |
c5121837 JM |
8839 | .set_rts = i802_set_rts, |
8840 | .set_frag = i802_set_frag, | |
c5121837 | 8841 | .set_tx_queue_params = i802_set_tx_queue_params, |
9ebce9c5 | 8842 | .set_sta_vlan = driver_nl80211_set_sta_vlan, |
ee7ab173 JB |
8843 | .sta_deauth = i802_sta_deauth, |
8844 | .sta_disassoc = i802_sta_disassoc, | |
9ebce9c5 | 8845 | .read_sta_data = driver_nl80211_read_sta_data, |
e3802622 | 8846 | .set_freq = i802_set_freq, |
9ebce9c5 | 8847 | .send_action = driver_nl80211_send_action, |
5dfca53f | 8848 | .send_action_cancel_wait = wpa_driver_nl80211_send_action_cancel_wait, |
55777702 JM |
8849 | .remain_on_channel = wpa_driver_nl80211_remain_on_channel, |
8850 | .cancel_remain_on_channel = | |
8851 | wpa_driver_nl80211_cancel_remain_on_channel, | |
9ebce9c5 | 8852 | .probe_req_report = driver_nl80211_probe_req_report, |
af473088 | 8853 | .deinit_ap = wpa_driver_nl80211_deinit_ap, |
3c29244e | 8854 | .deinit_p2p_cli = wpa_driver_nl80211_deinit_p2p_cli, |
207ef3fb | 8855 | .resume = wpa_driver_nl80211_resume, |
b625473c | 8856 | .signal_monitor = nl80211_signal_monitor, |
1c5c7273 | 8857 | .signal_poll = nl80211_signal_poll, |
b91ab76e | 8858 | .send_frame = nl80211_send_frame, |
c55f774d | 8859 | .set_param = nl80211_set_param, |
6859f1cb | 8860 | .get_radio_name = nl80211_get_radio_name, |
a6efc65d JM |
8861 | .add_pmkid = nl80211_add_pmkid, |
8862 | .remove_pmkid = nl80211_remove_pmkid, | |
8863 | .flush_pmkid = nl80211_flush_pmkid, | |
b14a210c | 8864 | .set_rekey_info = nl80211_set_rekey_info, |
bcf24348 | 8865 | .poll_client = nl80211_poll_client, |
29f338af | 8866 | .set_p2p_powersave = nl80211_set_p2p_powersave, |
f90e9c1c | 8867 | .start_dfs_cac = nl80211_start_radar_detection, |
695c7038 | 8868 | .stop_ap = wpa_driver_nl80211_stop_ap, |
03ea1786 AN |
8869 | #ifdef CONFIG_TDLS |
8870 | .send_tdls_mgmt = nl80211_send_tdls_mgmt, | |
8871 | .tdls_oper = nl80211_tdls_oper, | |
72b2605f AN |
8872 | .tdls_enable_channel_switch = nl80211_tdls_enable_channel_switch, |
8873 | .tdls_disable_channel_switch = nl80211_tdls_disable_channel_switch, | |
03ea1786 | 8874 | #endif /* CONFIG_TDLS */ |
6a1ce395 | 8875 | .update_ft_ies = wpa_driver_nl80211_update_ft_ies, |
597b94f5 | 8876 | .get_mac_addr = wpa_driver_nl80211_get_macaddr, |
0185007c | 8877 | .get_survey = wpa_driver_nl80211_get_survey, |
a771c07d | 8878 | .status = wpa_driver_nl80211_status, |
1c4ffa87 | 8879 | .switch_channel = nl80211_switch_channel, |
0de38036 JM |
8880 | #ifdef ANDROID_P2P |
8881 | .set_noa = wpa_driver_set_p2p_noa, | |
8882 | .get_noa = wpa_driver_get_p2p_noa, | |
8883 | .set_ap_wps_ie = wpa_driver_set_ap_wps_p2p_ie, | |
8884 | #endif /* ANDROID_P2P */ | |
5e2c3490 | 8885 | #ifdef ANDROID |
ded14ce9 | 8886 | #ifndef ANDROID_LIB_STUB |
5e2c3490 | 8887 | .driver_cmd = wpa_driver_nl80211_driver_cmd, |
ded14ce9 | 8888 | #endif /* !ANDROID_LIB_STUB */ |
5e2c3490 | 8889 | #endif /* ANDROID */ |
adef8948 | 8890 | .vendor_cmd = nl80211_vendor_cmd, |
049105b4 | 8891 | .set_qos_map = nl80211_set_qos_map, |
e4fa8b12 | 8892 | .set_wowlan = nl80211_set_wowlan, |
b658547d | 8893 | #ifdef CONFIG_DRIVER_NL80211_QCA |
0800f9ee | 8894 | .roaming = nl80211_roaming, |
b658547d | 8895 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
fee354c7 | 8896 | .set_mac_addr = nl80211_set_mac_addr, |
6c1664f6 BC |
8897 | #ifdef CONFIG_MESH |
8898 | .init_mesh = wpa_driver_nl80211_init_mesh, | |
8899 | .join_mesh = wpa_driver_nl80211_join_mesh, | |
8900 | .leave_mesh = wpa_driver_nl80211_leave_mesh, | |
8901 | #endif /* CONFIG_MESH */ | |
71103bed KP |
8902 | .br_add_ip_neigh = wpa_driver_br_add_ip_neigh, |
8903 | .br_delete_ip_neigh = wpa_driver_br_delete_ip_neigh, | |
73d2294f | 8904 | .br_port_set_attr = wpa_driver_br_port_set_attr, |
7565752d | 8905 | .br_set_net_param = wpa_driver_br_set_net_param, |
dfa87878 MB |
8906 | .add_tx_ts = nl80211_add_ts, |
8907 | .del_tx_ts = nl80211_del_ts, | |
b658547d | 8908 | #ifdef CONFIG_DRIVER_NL80211_QCA |
16689c7c | 8909 | .do_acs = wpa_driver_do_acs, |
844dfeb8 | 8910 | .set_band = nl80211_set_band, |
98342208 | 8911 | .get_pref_freq_list = nl80211_get_pref_freq_list, |
7c813acf | 8912 | .set_prob_oper_freq = nl80211_set_prob_oper_freq, |
b658547d | 8913 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
3f5285e8 | 8914 | }; |