]>
Commit | Line | Data |
---|---|---|
3f5285e8 | 1 | /* |
c5121837 | 2 | * Driver interaction with Linux nl80211/cfg80211 |
8d923a4a | 3 | * Copyright (c) 2002-2010, 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 JM |
8 | * |
9 | * This program is free software; you can redistribute it and/or modify | |
10 | * it under the terms of the GNU General Public License version 2 as | |
11 | * published by the Free Software Foundation. | |
12 | * | |
13 | * Alternatively, this software may be distributed under the terms of BSD | |
14 | * license. | |
15 | * | |
16 | * See README and COPYING for more details. | |
17 | */ | |
18 | ||
19 | #include "includes.h" | |
20 | #include <sys/ioctl.h> | |
37b7d082 | 21 | #include <net/if.h> |
3f5285e8 JM |
22 | #include <netlink/genl/genl.h> |
23 | #include <netlink/genl/family.h> | |
24 | #include <netlink/genl/ctrl.h> | |
1b648c7e JM |
25 | #include <netpacket/packet.h> |
26 | #include <linux/filter.h> | |
7e45830a | 27 | #include "nl80211_copy.h" |
625f587b | 28 | |
3f5285e8 | 29 | #include "common.h" |
1b648c7e JM |
30 | #include "eloop.h" |
31 | #include "common/ieee802_11_defs.h" | |
e2d02c29 | 32 | #include "netlink.h" |
34f2f814 | 33 | #include "linux_ioctl.h" |
e2d02c29 JM |
34 | #include "radiotap.h" |
35 | #include "radiotap_iter.h" | |
1b648c7e | 36 | #include "driver.h" |
0915d02c | 37 | |
c5121837 JM |
38 | #ifdef CONFIG_LIBNL20 |
39 | /* libnl 2.0 compatibility code */ | |
2e8eac2d | 40 | #define nl_handle nl_sock |
c5121837 JM |
41 | #define nl_handle_alloc_cb nl_socket_alloc_cb |
42 | #define nl_handle_destroy nl_socket_free | |
43 | #endif /* CONFIG_LIBNL20 */ | |
44 | ||
c5121837 | 45 | |
3f5285e8 JM |
46 | #ifndef IFF_LOWER_UP |
47 | #define IFF_LOWER_UP 0x10000 /* driver signals L1 up */ | |
48 | #endif | |
49 | #ifndef IFF_DORMANT | |
50 | #define IFF_DORMANT 0x20000 /* driver signals dormant */ | |
51 | #endif | |
52 | ||
53 | #ifndef IF_OPER_DORMANT | |
54 | #define IF_OPER_DORMANT 5 | |
55 | #endif | |
56 | #ifndef IF_OPER_UP | |
57 | #define IF_OPER_UP 6 | |
58 | #endif | |
59 | ||
c5121837 | 60 | struct i802_bss { |
a2e40bb6 | 61 | struct wpa_driver_nl80211_data *drv; |
c5121837 | 62 | struct i802_bss *next; |
b4fd6fab | 63 | int ifindex; |
a2e40bb6 | 64 | char ifname[IFNAMSIZ + 1]; |
c5121837 JM |
65 | unsigned int beacon_set:1; |
66 | }; | |
3f5285e8 JM |
67 | |
68 | struct wpa_driver_nl80211_data { | |
69 | void *ctx; | |
08063178 | 70 | struct netlink_data *netlink; |
c5121837 | 71 | int ioctl_sock; /* socket for ioctl() use */ |
94627f6c | 72 | char brname[IFNAMSIZ]; |
3f5285e8 | 73 | int ifindex; |
7524cfb1 | 74 | int if_removed; |
c2a04078 JM |
75 | struct wpa_driver_capa capa; |
76 | int has_capability; | |
c2a04078 | 77 | |
3f5285e8 JM |
78 | int operstate; |
79 | ||
3f5285e8 JM |
80 | int scan_complete_events; |
81 | ||
82 | struct nl_handle *nl_handle; | |
335ce76b | 83 | struct nl_handle *nl_handle_event; |
3f5285e8 | 84 | struct nl_cache *nl_cache; |
335ce76b | 85 | struct nl_cache *nl_cache_event; |
3f5285e8 JM |
86 | struct nl_cb *nl_cb; |
87 | struct genl_family *nl80211; | |
1c873584 | 88 | |
e6b8efeb | 89 | u8 auth_bssid[ETH_ALEN]; |
c2a04078 JM |
90 | u8 bssid[ETH_ALEN]; |
91 | int associated; | |
fd05d64e JM |
92 | u8 ssid[32]; |
93 | size_t ssid_len; | |
ad1e68e6 JM |
94 | int nlmode; |
95 | int ap_scan_as_station; | |
4832ecd7 | 96 | unsigned int assoc_freq; |
d2440ba0 | 97 | |
0915d02c JM |
98 | int monitor_sock; |
99 | int monitor_ifidx; | |
504e905c | 100 | int probe_req_report; |
4e5cb1a3 | 101 | int disable_11b_rates; |
7da3abe7 | 102 | |
55777702 | 103 | unsigned int pending_remain_on_chan:1; |
58f6fbe0 | 104 | unsigned int pending_send_action:1; |
94627f6c JM |
105 | unsigned int added_bridge:1; |
106 | unsigned int added_if_into_bridge:1; | |
55777702 JM |
107 | |
108 | u64 remain_on_chan_cookie; | |
58f6fbe0 | 109 | u64 send_action_cookie; |
c5121837 | 110 | |
3812464c JM |
111 | struct wpa_driver_scan_filter *filter_ssids; |
112 | size_t num_filter_ssids; | |
113 | ||
a2e40bb6 FF |
114 | struct i802_bss first_bss; |
115 | ||
c5121837 | 116 | #ifdef HOSTAPD |
c5121837 | 117 | int eapol_sock; /* socket for EAPOL frames */ |
c5121837 JM |
118 | |
119 | int default_if_indices[16]; | |
120 | int *if_indices; | |
121 | int num_if_indices; | |
122 | ||
c5121837 JM |
123 | int last_freq; |
124 | int last_freq_ht; | |
c5121837 | 125 | #endif /* HOSTAPD */ |
3f5285e8 JM |
126 | }; |
127 | ||
128 | ||
129 | static void wpa_driver_nl80211_scan_timeout(void *eloop_ctx, | |
130 | void *timeout_ctx); | |
ad1e68e6 | 131 | static int wpa_driver_nl80211_set_mode(void *priv, int mode); |
362f781e | 132 | static int |
7524cfb1 | 133 | wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data *drv); |
d72aad94 JM |
134 | static int wpa_driver_nl80211_mlme(struct wpa_driver_nl80211_data *drv, |
135 | const u8 *addr, int cmd, u16 reason_code); | |
460456f8 JM |
136 | static void nl80211_remove_monitor_interface( |
137 | struct wpa_driver_nl80211_data *drv); | |
0915d02c | 138 | |
072ad14c | 139 | #ifdef HOSTAPD |
2135f224 JM |
140 | static void add_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx); |
141 | static void del_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx); | |
bbaf0837 | 142 | static int i802_set_freq(void *priv, struct hostapd_freq_params *freq); |
fbbfcbac FF |
143 | static int wpa_driver_nl80211_if_remove(void *priv, |
144 | enum wpa_driver_if_type type, | |
145 | const char *ifname); | |
072ad14c JM |
146 | #endif /* HOSTAPD */ |
147 | ||
504e905c JM |
148 | static void wpa_driver_nl80211_probe_req_report_timeout(void *eloop_ctx, |
149 | void *timeout_ctx); | |
4e5cb1a3 JM |
150 | static int nl80211_disable_11b_rates(struct wpa_driver_nl80211_data *drv, |
151 | int ifindex, int disabled); | |
504e905c | 152 | |
3f5285e8 | 153 | |
6241fcb1 JM |
154 | /* nl80211 code */ |
155 | static int ack_handler(struct nl_msg *msg, void *arg) | |
156 | { | |
157 | int *err = arg; | |
158 | *err = 0; | |
159 | return NL_STOP; | |
160 | } | |
161 | ||
162 | static int finish_handler(struct nl_msg *msg, void *arg) | |
163 | { | |
8e8df255 JM |
164 | int *ret = arg; |
165 | *ret = 0; | |
6241fcb1 JM |
166 | return NL_SKIP; |
167 | } | |
168 | ||
169 | static int error_handler(struct sockaddr_nl *nla, struct nlmsgerr *err, | |
170 | void *arg) | |
171 | { | |
172 | int *ret = arg; | |
173 | *ret = err->error; | |
174 | return NL_SKIP; | |
175 | } | |
176 | ||
5b7b85f6 JM |
177 | |
178 | static int no_seq_check(struct nl_msg *msg, void *arg) | |
179 | { | |
180 | return NL_OK; | |
181 | } | |
182 | ||
183 | ||
58f6fbe0 JM |
184 | static int send_and_recv(struct wpa_driver_nl80211_data *drv, |
185 | struct nl_handle *nl_handle, struct nl_msg *msg, | |
186 | int (*valid_handler)(struct nl_msg *, void *), | |
187 | void *valid_data) | |
6241fcb1 JM |
188 | { |
189 | struct nl_cb *cb; | |
190 | int err = -ENOMEM; | |
191 | ||
192 | cb = nl_cb_clone(drv->nl_cb); | |
193 | if (!cb) | |
194 | goto out; | |
195 | ||
58f6fbe0 | 196 | err = nl_send_auto_complete(nl_handle, msg); |
6241fcb1 JM |
197 | if (err < 0) |
198 | goto out; | |
199 | ||
200 | err = 1; | |
201 | ||
202 | nl_cb_err(cb, NL_CB_CUSTOM, error_handler, &err); | |
8e8df255 | 203 | nl_cb_set(cb, NL_CB_FINISH, NL_CB_CUSTOM, finish_handler, &err); |
6241fcb1 JM |
204 | nl_cb_set(cb, NL_CB_ACK, NL_CB_CUSTOM, ack_handler, &err); |
205 | ||
206 | if (valid_handler) | |
207 | nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, | |
208 | valid_handler, valid_data); | |
209 | ||
210 | while (err > 0) | |
58f6fbe0 | 211 | nl_recvmsgs(nl_handle, cb); |
6241fcb1 JM |
212 | out: |
213 | nl_cb_put(cb); | |
214 | nlmsg_free(msg); | |
215 | return err; | |
216 | } | |
217 | ||
218 | ||
58f6fbe0 JM |
219 | static int send_and_recv_msgs(struct wpa_driver_nl80211_data *drv, |
220 | struct nl_msg *msg, | |
221 | int (*valid_handler)(struct nl_msg *, void *), | |
222 | void *valid_data) | |
223 | { | |
224 | return send_and_recv(drv, drv->nl_handle, msg, valid_handler, | |
225 | valid_data); | |
226 | } | |
227 | ||
228 | ||
97865538 JM |
229 | struct family_data { |
230 | const char *group; | |
231 | int id; | |
232 | }; | |
233 | ||
234 | ||
235 | static int family_handler(struct nl_msg *msg, void *arg) | |
236 | { | |
237 | struct family_data *res = arg; | |
238 | struct nlattr *tb[CTRL_ATTR_MAX + 1]; | |
239 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
240 | struct nlattr *mcgrp; | |
241 | int i; | |
242 | ||
243 | nla_parse(tb, CTRL_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
244 | genlmsg_attrlen(gnlh, 0), NULL); | |
245 | if (!tb[CTRL_ATTR_MCAST_GROUPS]) | |
246 | return NL_SKIP; | |
247 | ||
248 | nla_for_each_nested(mcgrp, tb[CTRL_ATTR_MCAST_GROUPS], i) { | |
249 | struct nlattr *tb2[CTRL_ATTR_MCAST_GRP_MAX + 1]; | |
250 | nla_parse(tb2, CTRL_ATTR_MCAST_GRP_MAX, nla_data(mcgrp), | |
251 | nla_len(mcgrp), NULL); | |
252 | if (!tb2[CTRL_ATTR_MCAST_GRP_NAME] || | |
253 | !tb2[CTRL_ATTR_MCAST_GRP_ID] || | |
254 | os_strncmp(nla_data(tb2[CTRL_ATTR_MCAST_GRP_NAME]), | |
255 | res->group, | |
256 | nla_len(tb2[CTRL_ATTR_MCAST_GRP_NAME])) != 0) | |
257 | continue; | |
258 | res->id = nla_get_u32(tb2[CTRL_ATTR_MCAST_GRP_ID]); | |
259 | break; | |
260 | }; | |
261 | ||
262 | return NL_SKIP; | |
263 | } | |
264 | ||
265 | ||
266 | static int nl_get_multicast_id(struct wpa_driver_nl80211_data *drv, | |
267 | const char *family, const char *group) | |
268 | { | |
269 | struct nl_msg *msg; | |
270 | int ret = -1; | |
271 | struct family_data res = { group, -ENOENT }; | |
272 | ||
273 | msg = nlmsg_alloc(); | |
274 | if (!msg) | |
275 | return -ENOMEM; | |
276 | genlmsg_put(msg, 0, 0, genl_ctrl_resolve(drv->nl_handle, "nlctrl"), | |
277 | 0, 0, CTRL_CMD_GETFAMILY, 0); | |
278 | NLA_PUT_STRING(msg, CTRL_ATTR_FAMILY_NAME, family); | |
279 | ||
280 | ret = send_and_recv_msgs(drv, msg, family_handler, &res); | |
281 | msg = NULL; | |
282 | if (ret == 0) | |
283 | ret = res.id; | |
284 | ||
285 | nla_put_failure: | |
286 | nlmsg_free(msg); | |
287 | return ret; | |
288 | } | |
289 | ||
290 | ||
3f5285e8 JM |
291 | static int wpa_driver_nl80211_get_bssid(void *priv, u8 *bssid) |
292 | { | |
a2e40bb6 FF |
293 | struct i802_bss *bss = priv; |
294 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
c2a04078 JM |
295 | if (!drv->associated) |
296 | return -1; | |
297 | os_memcpy(bssid, drv->bssid, ETH_ALEN); | |
298 | return 0; | |
3f5285e8 JM |
299 | } |
300 | ||
301 | ||
3f5285e8 JM |
302 | static int wpa_driver_nl80211_get_ssid(void *priv, u8 *ssid) |
303 | { | |
a2e40bb6 FF |
304 | struct i802_bss *bss = priv; |
305 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
fd05d64e JM |
306 | if (!drv->associated) |
307 | return -1; | |
308 | os_memcpy(ssid, drv->ssid, drv->ssid_len); | |
309 | return drv->ssid_len; | |
3f5285e8 JM |
310 | } |
311 | ||
312 | ||
7524cfb1 | 313 | static void wpa_driver_nl80211_event_link(struct wpa_driver_nl80211_data *drv, |
08063178 | 314 | char *buf, size_t len, int del) |
3f5285e8 JM |
315 | { |
316 | union wpa_event_data event; | |
317 | ||
318 | os_memset(&event, 0, sizeof(event)); | |
319 | if (len > sizeof(event.interface_status.ifname)) | |
320 | len = sizeof(event.interface_status.ifname) - 1; | |
321 | os_memcpy(event.interface_status.ifname, buf, len); | |
322 | event.interface_status.ievent = del ? EVENT_INTERFACE_REMOVED : | |
323 | EVENT_INTERFACE_ADDED; | |
324 | ||
325 | wpa_printf(MSG_DEBUG, "RTM_%sLINK, IFLA_IFNAME: Interface '%s' %s", | |
326 | del ? "DEL" : "NEW", | |
327 | event.interface_status.ifname, | |
328 | del ? "removed" : "added"); | |
329 | ||
a2e40bb6 | 330 | if (os_strcmp(drv->first_bss.ifname, event.interface_status.ifname) == 0) { |
7524cfb1 JM |
331 | if (del) |
332 | drv->if_removed = 1; | |
333 | else | |
334 | drv->if_removed = 0; | |
335 | } | |
336 | ||
08063178 | 337 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_STATUS, &event); |
3f5285e8 JM |
338 | } |
339 | ||
340 | ||
7524cfb1 | 341 | static int wpa_driver_nl80211_own_ifname(struct wpa_driver_nl80211_data *drv, |
62d680c3 | 342 | u8 *buf, size_t len) |
7524cfb1 | 343 | { |
62d680c3 | 344 | int attrlen, rta_len; |
7524cfb1 JM |
345 | struct rtattr *attr; |
346 | ||
62d680c3 JM |
347 | attrlen = len; |
348 | attr = (struct rtattr *) buf; | |
7524cfb1 JM |
349 | |
350 | rta_len = RTA_ALIGN(sizeof(struct rtattr)); | |
351 | while (RTA_OK(attr, attrlen)) { | |
352 | if (attr->rta_type == IFLA_IFNAME) { | |
a2e40bb6 | 353 | if (os_strcmp(((char *) attr) + rta_len, drv->first_bss.ifname) |
7524cfb1 JM |
354 | == 0) |
355 | return 1; | |
356 | else | |
357 | break; | |
358 | } | |
359 | attr = RTA_NEXT(attr, attrlen); | |
360 | } | |
361 | ||
362 | return 0; | |
363 | } | |
364 | ||
365 | ||
366 | static int wpa_driver_nl80211_own_ifindex(struct wpa_driver_nl80211_data *drv, | |
62d680c3 | 367 | int ifindex, u8 *buf, size_t len) |
7524cfb1 JM |
368 | { |
369 | if (drv->ifindex == ifindex) | |
370 | return 1; | |
371 | ||
62d680c3 | 372 | if (drv->if_removed && wpa_driver_nl80211_own_ifname(drv, buf, len)) { |
a2e40bb6 | 373 | drv->first_bss.ifindex = if_nametoindex(drv->first_bss.ifname); |
7524cfb1 JM |
374 | wpa_printf(MSG_DEBUG, "nl80211: Update ifindex for a removed " |
375 | "interface"); | |
376 | wpa_driver_nl80211_finish_drv_init(drv); | |
377 | return 1; | |
378 | } | |
379 | ||
380 | return 0; | |
381 | } | |
382 | ||
383 | ||
62d680c3 JM |
384 | static void wpa_driver_nl80211_event_rtm_newlink(void *ctx, |
385 | struct ifinfomsg *ifi, | |
386 | u8 *buf, size_t len) | |
3f5285e8 | 387 | { |
08063178 | 388 | struct wpa_driver_nl80211_data *drv = ctx; |
62d680c3 JM |
389 | int attrlen, rta_len; |
390 | struct rtattr *attr; | |
3f5285e8 | 391 | |
62d680c3 | 392 | if (!wpa_driver_nl80211_own_ifindex(drv, ifi->ifi_index, buf, len)) { |
3f5285e8 JM |
393 | wpa_printf(MSG_DEBUG, "Ignore event for foreign ifindex %d", |
394 | ifi->ifi_index); | |
395 | return; | |
396 | } | |
397 | ||
398 | wpa_printf(MSG_DEBUG, "RTM_NEWLINK: operstate=%d ifi_flags=0x%x " | |
399 | "(%s%s%s%s)", | |
400 | drv->operstate, ifi->ifi_flags, | |
401 | (ifi->ifi_flags & IFF_UP) ? "[UP]" : "", | |
402 | (ifi->ifi_flags & IFF_RUNNING) ? "[RUNNING]" : "", | |
403 | (ifi->ifi_flags & IFF_LOWER_UP) ? "[LOWER_UP]" : "", | |
404 | (ifi->ifi_flags & IFF_DORMANT) ? "[DORMANT]" : ""); | |
405 | /* | |
406 | * Some drivers send the association event before the operup event--in | |
407 | * this case, lifting operstate in wpa_driver_nl80211_set_operstate() | |
408 | * fails. This will hit us when wpa_supplicant does not need to do | |
409 | * IEEE 802.1X authentication | |
410 | */ | |
411 | if (drv->operstate == 1 && | |
412 | (ifi->ifi_flags & (IFF_LOWER_UP | IFF_DORMANT)) == IFF_LOWER_UP && | |
413 | !(ifi->ifi_flags & IFF_RUNNING)) | |
08063178 | 414 | netlink_send_oper_ifla(drv->netlink, drv->ifindex, |
e2d02c29 | 415 | -1, IF_OPER_UP); |
3f5285e8 | 416 | |
62d680c3 JM |
417 | attrlen = len; |
418 | attr = (struct rtattr *) buf; | |
3f5285e8 JM |
419 | rta_len = RTA_ALIGN(sizeof(struct rtattr)); |
420 | while (RTA_OK(attr, attrlen)) { | |
d8816397 | 421 | if (attr->rta_type == IFLA_IFNAME) { |
7524cfb1 | 422 | wpa_driver_nl80211_event_link( |
08063178 | 423 | drv, |
7524cfb1 JM |
424 | ((char *) attr) + rta_len, |
425 | attr->rta_len - rta_len, 0); | |
3f5285e8 JM |
426 | } |
427 | attr = RTA_NEXT(attr, attrlen); | |
428 | } | |
429 | } | |
430 | ||
431 | ||
62d680c3 JM |
432 | static void wpa_driver_nl80211_event_rtm_dellink(void *ctx, |
433 | struct ifinfomsg *ifi, | |
434 | u8 *buf, size_t len) | |
3f5285e8 | 435 | { |
08063178 | 436 | struct wpa_driver_nl80211_data *drv = ctx; |
62d680c3 JM |
437 | int attrlen, rta_len; |
438 | struct rtattr *attr; | |
3f5285e8 | 439 | |
62d680c3 JM |
440 | attrlen = len; |
441 | attr = (struct rtattr *) buf; | |
3f5285e8 JM |
442 | |
443 | rta_len = RTA_ALIGN(sizeof(struct rtattr)); | |
444 | while (RTA_OK(attr, attrlen)) { | |
445 | if (attr->rta_type == IFLA_IFNAME) { | |
7524cfb1 | 446 | wpa_driver_nl80211_event_link( |
08063178 | 447 | drv, |
7524cfb1 JM |
448 | ((char *) attr) + rta_len, |
449 | attr->rta_len - rta_len, 1); | |
3f5285e8 JM |
450 | } |
451 | attr = RTA_NEXT(attr, attrlen); | |
452 | } | |
453 | } | |
454 | ||
455 | ||
c2a04078 JM |
456 | static void mlme_event_auth(struct wpa_driver_nl80211_data *drv, |
457 | const u8 *frame, size_t len) | |
458 | { | |
459 | const struct ieee80211_mgmt *mgmt; | |
460 | union wpa_event_data event; | |
461 | ||
462 | mgmt = (const struct ieee80211_mgmt *) frame; | |
463 | if (len < 24 + sizeof(mgmt->u.auth)) { | |
464 | wpa_printf(MSG_DEBUG, "nl80211: Too short association event " | |
465 | "frame"); | |
466 | return; | |
467 | } | |
468 | ||
e6b8efeb | 469 | os_memcpy(drv->auth_bssid, mgmt->sa, ETH_ALEN); |
c2a04078 JM |
470 | os_memset(&event, 0, sizeof(event)); |
471 | os_memcpy(event.auth.peer, mgmt->sa, ETH_ALEN); | |
472 | event.auth.auth_type = le_to_host16(mgmt->u.auth.auth_alg); | |
473 | event.auth.status_code = le_to_host16(mgmt->u.auth.status_code); | |
474 | if (len > 24 + sizeof(mgmt->u.auth)) { | |
475 | event.auth.ies = mgmt->u.auth.variable; | |
476 | event.auth.ies_len = len - 24 - sizeof(mgmt->u.auth); | |
477 | } | |
478 | ||
479 | wpa_supplicant_event(drv->ctx, EVENT_AUTH, &event); | |
480 | } | |
481 | ||
482 | ||
483 | static void mlme_event_assoc(struct wpa_driver_nl80211_data *drv, | |
484 | const u8 *frame, size_t len) | |
485 | { | |
486 | const struct ieee80211_mgmt *mgmt; | |
487 | union wpa_event_data event; | |
488 | u16 status; | |
489 | ||
490 | mgmt = (const struct ieee80211_mgmt *) frame; | |
491 | if (len < 24 + sizeof(mgmt->u.assoc_resp)) { | |
492 | wpa_printf(MSG_DEBUG, "nl80211: Too short association event " | |
493 | "frame"); | |
494 | return; | |
495 | } | |
496 | ||
497 | status = le_to_host16(mgmt->u.assoc_resp.status_code); | |
498 | if (status != WLAN_STATUS_SUCCESS) { | |
efa46078 JM |
499 | os_memset(&event, 0, sizeof(event)); |
500 | if (len > 24 + sizeof(mgmt->u.assoc_resp)) { | |
501 | event.assoc_reject.resp_ies = | |
502 | (u8 *) mgmt->u.assoc_resp.variable; | |
503 | event.assoc_reject.resp_ies_len = | |
504 | len - 24 - sizeof(mgmt->u.assoc_resp); | |
505 | } | |
506 | event.assoc_reject.status_code = status; | |
507 | ||
508 | wpa_supplicant_event(drv->ctx, EVENT_ASSOC_REJECT, &event); | |
c2a04078 JM |
509 | return; |
510 | } | |
511 | ||
512 | drv->associated = 1; | |
513 | os_memcpy(drv->bssid, mgmt->sa, ETH_ALEN); | |
514 | ||
515 | os_memset(&event, 0, sizeof(event)); | |
516 | if (len > 24 + sizeof(mgmt->u.assoc_resp)) { | |
517 | event.assoc_info.resp_ies = (u8 *) mgmt->u.assoc_resp.variable; | |
518 | event.assoc_info.resp_ies_len = | |
efa46078 | 519 | len - 24 - sizeof(mgmt->u.assoc_resp); |
c2a04078 JM |
520 | } |
521 | ||
4832ecd7 JM |
522 | event.assoc_info.freq = drv->assoc_freq; |
523 | ||
c2a04078 JM |
524 | wpa_supplicant_event(drv->ctx, EVENT_ASSOC, &event); |
525 | } | |
526 | ||
c1bb3e0a | 527 | |
da72a1c1 ZY |
528 | static void mlme_event_connect(struct wpa_driver_nl80211_data *drv, |
529 | enum nl80211_commands cmd, struct nlattr *status, | |
530 | struct nlattr *addr, struct nlattr *req_ie, | |
531 | struct nlattr *resp_ie) | |
532 | { | |
533 | union wpa_event_data event; | |
534 | ||
7da2c527 JM |
535 | if (drv->capa.flags & WPA_DRIVER_FLAGS_SME) { |
536 | /* | |
537 | * Avoid reporting two association events that would confuse | |
538 | * the core code. | |
539 | */ | |
540 | wpa_printf(MSG_DEBUG, "nl80211: Ignore connect event (cmd=%d) " | |
541 | "when using userspace SME", cmd); | |
542 | return; | |
543 | } | |
544 | ||
da72a1c1 ZY |
545 | os_memset(&event, 0, sizeof(event)); |
546 | if (cmd == NL80211_CMD_CONNECT && | |
547 | nla_get_u16(status) != WLAN_STATUS_SUCCESS) { | |
548 | if (resp_ie) { | |
549 | event.assoc_reject.resp_ies = nla_data(resp_ie); | |
550 | event.assoc_reject.resp_ies_len = nla_len(resp_ie); | |
551 | } | |
552 | event.assoc_reject.status_code = nla_get_u16(status); | |
553 | wpa_supplicant_event(drv->ctx, EVENT_ASSOC_REJECT, &event); | |
554 | return; | |
555 | } | |
556 | ||
557 | drv->associated = 1; | |
558 | if (addr) | |
559 | os_memcpy(drv->bssid, nla_data(addr), ETH_ALEN); | |
560 | ||
561 | if (req_ie) { | |
562 | event.assoc_info.req_ies = nla_data(req_ie); | |
563 | event.assoc_info.req_ies_len = nla_len(req_ie); | |
564 | } | |
565 | if (resp_ie) { | |
566 | event.assoc_info.resp_ies = nla_data(resp_ie); | |
567 | event.assoc_info.resp_ies_len = nla_len(resp_ie); | |
568 | } | |
569 | ||
570 | wpa_supplicant_event(drv->ctx, EVENT_ASSOC, &event); | |
571 | } | |
c2a04078 | 572 | |
c1bb3e0a | 573 | |
da1fb17c JM |
574 | static void mlme_timeout_event(struct wpa_driver_nl80211_data *drv, |
575 | enum nl80211_commands cmd, struct nlattr *addr) | |
576 | { | |
577 | union wpa_event_data event; | |
578 | enum wpa_event_type ev; | |
579 | ||
580 | if (nla_len(addr) != ETH_ALEN) | |
581 | return; | |
582 | ||
583 | wpa_printf(MSG_DEBUG, "nl80211: MLME event %d; timeout with " MACSTR, | |
584 | cmd, MAC2STR((u8 *) nla_data(addr))); | |
585 | ||
586 | if (cmd == NL80211_CMD_AUTHENTICATE) | |
587 | ev = EVENT_AUTH_TIMED_OUT; | |
588 | else if (cmd == NL80211_CMD_ASSOCIATE) | |
589 | ev = EVENT_ASSOC_TIMED_OUT; | |
590 | else | |
591 | return; | |
592 | ||
593 | os_memset(&event, 0, sizeof(event)); | |
594 | os_memcpy(event.timeout_event.addr, nla_data(addr), ETH_ALEN); | |
595 | wpa_supplicant_event(drv->ctx, ev, &event); | |
596 | } | |
597 | ||
598 | ||
58f6fbe0 JM |
599 | static void mlme_event_action(struct wpa_driver_nl80211_data *drv, |
600 | struct nlattr *freq, const u8 *frame, size_t len) | |
601 | { | |
602 | const struct ieee80211_mgmt *mgmt; | |
603 | union wpa_event_data event; | |
604 | u16 fc, stype; | |
605 | ||
606 | mgmt = (const struct ieee80211_mgmt *) frame; | |
607 | if (len < 24) { | |
608 | wpa_printf(MSG_DEBUG, "nl80211: Too short action frame"); | |
609 | return; | |
610 | } | |
611 | ||
612 | fc = le_to_host16(mgmt->frame_control); | |
613 | stype = WLAN_FC_GET_STYPE(fc); | |
614 | ||
615 | os_memset(&event, 0, sizeof(event)); | |
616 | event.rx_action.da = mgmt->da; | |
617 | event.rx_action.sa = mgmt->sa; | |
618 | event.rx_action.bssid = mgmt->bssid; | |
619 | event.rx_action.category = mgmt->u.action.category; | |
620 | event.rx_action.data = &mgmt->u.action.category + 1; | |
621 | event.rx_action.len = frame + len - event.rx_action.data; | |
622 | if (freq) | |
623 | event.rx_action.freq = nla_get_u32(freq); | |
624 | wpa_supplicant_event(drv->ctx, EVENT_RX_ACTION, &event); | |
625 | } | |
626 | ||
627 | ||
628 | static void mlme_event_action_tx_status(struct wpa_driver_nl80211_data *drv, | |
629 | struct nlattr *cookie, const u8 *frame, | |
630 | size_t len, struct nlattr *ack) | |
631 | { | |
632 | union wpa_event_data event; | |
633 | const struct ieee80211_hdr *hdr; | |
634 | u16 fc; | |
635 | u64 cookie_val; | |
636 | ||
637 | if (!cookie) | |
638 | return; | |
639 | ||
640 | cookie_val = nla_get_u64(cookie); | |
641 | wpa_printf(MSG_DEBUG, "nl80211: Action TX status: cookie=0%llx%s", | |
642 | (long long unsigned int) cookie_val, | |
643 | cookie_val == drv->send_action_cookie ? | |
644 | " (match)" : " (unknown)"); | |
645 | if (cookie_val != drv->send_action_cookie) | |
646 | return; | |
647 | ||
648 | hdr = (const struct ieee80211_hdr *) frame; | |
649 | fc = le_to_host16(hdr->frame_control); | |
650 | ||
651 | os_memset(&event, 0, sizeof(event)); | |
652 | event.tx_status.type = WLAN_FC_GET_TYPE(fc); | |
653 | event.tx_status.stype = WLAN_FC_GET_STYPE(fc); | |
654 | event.tx_status.dst = hdr->addr1; | |
655 | event.tx_status.data = frame; | |
656 | event.tx_status.data_len = len; | |
657 | event.tx_status.ack = ack != NULL; | |
658 | wpa_supplicant_event(drv->ctx, EVENT_TX_STATUS, &event); | |
659 | } | |
660 | ||
661 | ||
c2a04078 | 662 | static void mlme_event(struct wpa_driver_nl80211_data *drv, |
da1fb17c | 663 | enum nl80211_commands cmd, struct nlattr *frame, |
58f6fbe0 JM |
664 | struct nlattr *addr, struct nlattr *timed_out, |
665 | struct nlattr *freq, struct nlattr *ack, | |
666 | struct nlattr *cookie) | |
c2a04078 | 667 | { |
da1fb17c JM |
668 | if (timed_out && addr) { |
669 | mlme_timeout_event(drv, cmd, addr); | |
670 | return; | |
671 | } | |
672 | ||
c2a04078 JM |
673 | if (frame == NULL) { |
674 | wpa_printf(MSG_DEBUG, "nl80211: MLME event %d without frame " | |
675 | "data", cmd); | |
676 | return; | |
677 | } | |
678 | ||
679 | wpa_printf(MSG_DEBUG, "nl80211: MLME event %d", cmd); | |
680 | wpa_hexdump(MSG_MSGDUMP, "nl80211: MLME event frame", | |
681 | nla_data(frame), nla_len(frame)); | |
682 | ||
683 | switch (cmd) { | |
684 | case NL80211_CMD_AUTHENTICATE: | |
685 | mlme_event_auth(drv, nla_data(frame), nla_len(frame)); | |
686 | break; | |
687 | case NL80211_CMD_ASSOCIATE: | |
688 | mlme_event_assoc(drv, nla_data(frame), nla_len(frame)); | |
689 | break; | |
690 | case NL80211_CMD_DEAUTHENTICATE: | |
691 | drv->associated = 0; | |
692 | wpa_supplicant_event(drv->ctx, EVENT_DEAUTH, NULL); | |
693 | break; | |
694 | case NL80211_CMD_DISASSOCIATE: | |
695 | drv->associated = 0; | |
696 | wpa_supplicant_event(drv->ctx, EVENT_DISASSOC, NULL); | |
697 | break; | |
58f6fbe0 JM |
698 | case NL80211_CMD_ACTION: |
699 | mlme_event_action(drv, freq, nla_data(frame), nla_len(frame)); | |
700 | break; | |
701 | case NL80211_CMD_ACTION_TX_STATUS: | |
702 | mlme_event_action_tx_status(drv, cookie, nla_data(frame), | |
703 | nla_len(frame), ack); | |
704 | break; | |
c2a04078 JM |
705 | default: |
706 | break; | |
707 | } | |
708 | } | |
709 | ||
710 | ||
35583f3f JM |
711 | static void mlme_event_michael_mic_failure(struct wpa_driver_nl80211_data *drv, |
712 | struct nlattr *tb[]) | |
713 | { | |
714 | union wpa_event_data data; | |
715 | ||
716 | wpa_printf(MSG_DEBUG, "nl80211: MLME event Michael MIC failure"); | |
717 | os_memset(&data, 0, sizeof(data)); | |
718 | if (tb[NL80211_ATTR_MAC]) { | |
719 | wpa_hexdump(MSG_DEBUG, "nl80211: Source MAC address", | |
720 | nla_data(tb[NL80211_ATTR_MAC]), | |
721 | nla_len(tb[NL80211_ATTR_MAC])); | |
ad1e68e6 | 722 | data.michael_mic_failure.src = nla_data(tb[NL80211_ATTR_MAC]); |
35583f3f JM |
723 | } |
724 | if (tb[NL80211_ATTR_KEY_SEQ]) { | |
725 | wpa_hexdump(MSG_DEBUG, "nl80211: TSC", | |
726 | nla_data(tb[NL80211_ATTR_KEY_SEQ]), | |
727 | nla_len(tb[NL80211_ATTR_KEY_SEQ])); | |
728 | } | |
729 | if (tb[NL80211_ATTR_KEY_TYPE]) { | |
730 | enum nl80211_key_type key_type = | |
731 | nla_get_u32(tb[NL80211_ATTR_KEY_TYPE]); | |
732 | wpa_printf(MSG_DEBUG, "nl80211: Key Type %d", key_type); | |
733 | if (key_type == NL80211_KEYTYPE_PAIRWISE) | |
734 | data.michael_mic_failure.unicast = 1; | |
735 | } else | |
736 | data.michael_mic_failure.unicast = 1; | |
737 | ||
738 | if (tb[NL80211_ATTR_KEY_IDX]) { | |
739 | u8 key_id = nla_get_u8(tb[NL80211_ATTR_KEY_IDX]); | |
740 | wpa_printf(MSG_DEBUG, "nl80211: Key Id %d", key_id); | |
741 | } | |
742 | ||
743 | wpa_supplicant_event(drv->ctx, EVENT_MICHAEL_MIC_FAILURE, &data); | |
744 | } | |
745 | ||
746 | ||
5cc4d64b JM |
747 | static void mlme_event_join_ibss(struct wpa_driver_nl80211_data *drv, |
748 | struct nlattr *tb[]) | |
749 | { | |
750 | if (tb[NL80211_ATTR_MAC] == NULL) { | |
751 | wpa_printf(MSG_DEBUG, "nl80211: No address in IBSS joined " | |
752 | "event"); | |
753 | return; | |
754 | } | |
755 | os_memcpy(drv->bssid, nla_data(tb[NL80211_ATTR_MAC]), ETH_ALEN); | |
756 | drv->associated = 1; | |
757 | wpa_printf(MSG_DEBUG, "nl80211: IBSS " MACSTR " joined", | |
758 | MAC2STR(drv->bssid)); | |
759 | ||
760 | wpa_supplicant_event(drv->ctx, EVENT_ASSOC, NULL); | |
761 | } | |
762 | ||
763 | ||
55777702 JM |
764 | static void mlme_event_remain_on_channel(struct wpa_driver_nl80211_data *drv, |
765 | int cancel_event, struct nlattr *tb[]) | |
766 | { | |
767 | unsigned int freq, chan_type, duration; | |
768 | union wpa_event_data data; | |
769 | u64 cookie; | |
770 | ||
771 | if (tb[NL80211_ATTR_WIPHY_FREQ]) | |
772 | freq = nla_get_u32(tb[NL80211_ATTR_WIPHY_FREQ]); | |
773 | else | |
774 | freq = 0; | |
775 | ||
776 | if (tb[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) | |
777 | chan_type = nla_get_u32(tb[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); | |
778 | else | |
779 | chan_type = 0; | |
780 | ||
781 | if (tb[NL80211_ATTR_DURATION]) | |
782 | duration = nla_get_u32(tb[NL80211_ATTR_DURATION]); | |
783 | else | |
784 | duration = 0; | |
785 | ||
786 | if (tb[NL80211_ATTR_COOKIE]) | |
787 | cookie = nla_get_u64(tb[NL80211_ATTR_COOKIE]); | |
788 | else | |
789 | cookie = 0; | |
790 | ||
791 | wpa_printf(MSG_DEBUG, "nl80211: Remain-on-channel event (cancel=%d " | |
792 | "freq=%u channel_type=%u duration=%u cookie=0x%llx (%s))", | |
793 | cancel_event, freq, chan_type, duration, | |
794 | (long long unsigned int) cookie, | |
795 | cookie == drv->remain_on_chan_cookie ? "match" : "unknown"); | |
796 | ||
797 | if (cookie != drv->remain_on_chan_cookie) | |
798 | return; /* not for us */ | |
799 | ||
800 | drv->pending_remain_on_chan = !cancel_event; | |
801 | ||
802 | os_memset(&data, 0, sizeof(data)); | |
803 | data.remain_on_channel.freq = freq; | |
804 | data.remain_on_channel.duration = duration; | |
805 | wpa_supplicant_event(drv->ctx, cancel_event ? | |
806 | EVENT_CANCEL_REMAIN_ON_CHANNEL : | |
807 | EVENT_REMAIN_ON_CHANNEL, &data); | |
808 | } | |
809 | ||
810 | ||
8d923a4a JM |
811 | static void send_scan_event(struct wpa_driver_nl80211_data *drv, int aborted, |
812 | struct nlattr *tb[]) | |
813 | { | |
814 | union wpa_event_data event; | |
815 | struct nlattr *nl; | |
816 | int rem; | |
817 | struct scan_info *info; | |
818 | #define MAX_REPORT_FREQS 50 | |
819 | int freqs[MAX_REPORT_FREQS]; | |
820 | int num_freqs = 0; | |
821 | ||
822 | os_memset(&event, 0, sizeof(event)); | |
823 | info = &event.scan_info; | |
824 | info->aborted = aborted; | |
825 | ||
826 | if (tb[NL80211_ATTR_SCAN_SSIDS]) { | |
827 | nla_for_each_nested(nl, tb[NL80211_ATTR_SCAN_SSIDS], rem) { | |
828 | struct wpa_driver_scan_ssid *s = | |
829 | &info->ssids[info->num_ssids]; | |
830 | s->ssid = nla_data(nl); | |
831 | s->ssid_len = nla_len(nl); | |
832 | info->num_ssids++; | |
833 | if (info->num_ssids == WPAS_MAX_SCAN_SSIDS) | |
834 | break; | |
835 | } | |
836 | } | |
837 | if (tb[NL80211_ATTR_SCAN_FREQUENCIES]) { | |
838 | nla_for_each_nested(nl, tb[NL80211_ATTR_SCAN_FREQUENCIES], rem) | |
839 | { | |
840 | freqs[num_freqs] = nla_get_u32(nl); | |
841 | num_freqs++; | |
842 | if (num_freqs == MAX_REPORT_FREQS - 1) | |
843 | break; | |
844 | } | |
845 | info->freqs = freqs; | |
846 | info->num_freqs = num_freqs; | |
847 | } | |
848 | wpa_supplicant_event(drv->ctx, EVENT_SCAN_RESULTS, &event); | |
849 | } | |
850 | ||
851 | ||
97865538 JM |
852 | static int process_event(struct nl_msg *msg, void *arg) |
853 | { | |
854 | struct wpa_driver_nl80211_data *drv = arg; | |
855 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
856 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
857 | ||
858 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
859 | genlmsg_attrlen(gnlh, 0), NULL); | |
860 | ||
861 | if (tb[NL80211_ATTR_IFINDEX]) { | |
862 | int ifindex = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); | |
863 | if (ifindex != drv->ifindex) { | |
864 | wpa_printf(MSG_DEBUG, "nl80211: Ignored event (cmd=%d)" | |
865 | " for foreign interface (ifindex %d)", | |
866 | gnlh->cmd, ifindex); | |
867 | return NL_SKIP; | |
868 | } | |
869 | } | |
870 | ||
ad1e68e6 JM |
871 | if (drv->ap_scan_as_station && |
872 | (gnlh->cmd == NL80211_CMD_NEW_SCAN_RESULTS || | |
873 | gnlh->cmd == NL80211_CMD_SCAN_ABORTED)) { | |
a2e40bb6 FF |
874 | wpa_driver_nl80211_set_mode(&drv->first_bss, |
875 | IEEE80211_MODE_AP); | |
ad1e68e6 JM |
876 | drv->ap_scan_as_station = 0; |
877 | } | |
878 | ||
97865538 | 879 | switch (gnlh->cmd) { |
d942a79e JM |
880 | case NL80211_CMD_TRIGGER_SCAN: |
881 | wpa_printf(MSG_DEBUG, "nl80211: Scan trigger"); | |
882 | break; | |
97865538 JM |
883 | case NL80211_CMD_NEW_SCAN_RESULTS: |
884 | wpa_printf(MSG_DEBUG, "nl80211: New scan results available"); | |
885 | drv->scan_complete_events = 1; | |
886 | eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout, drv, | |
887 | drv->ctx); | |
8d923a4a | 888 | send_scan_event(drv, 0, tb); |
97865538 JM |
889 | break; |
890 | case NL80211_CMD_SCAN_ABORTED: | |
891 | wpa_printf(MSG_DEBUG, "nl80211: Scan aborted"); | |
892 | /* | |
893 | * Need to indicate that scan results are available in order | |
894 | * not to make wpa_supplicant stop its scanning. | |
895 | */ | |
896 | eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout, drv, | |
897 | drv->ctx); | |
8d923a4a | 898 | send_scan_event(drv, 1, tb); |
97865538 | 899 | break; |
c2a04078 JM |
900 | case NL80211_CMD_AUTHENTICATE: |
901 | case NL80211_CMD_ASSOCIATE: | |
902 | case NL80211_CMD_DEAUTHENTICATE: | |
903 | case NL80211_CMD_DISASSOCIATE: | |
58f6fbe0 JM |
904 | case NL80211_CMD_ACTION: |
905 | case NL80211_CMD_ACTION_TX_STATUS: | |
da1fb17c | 906 | mlme_event(drv, gnlh->cmd, tb[NL80211_ATTR_FRAME], |
58f6fbe0 JM |
907 | tb[NL80211_ATTR_MAC], tb[NL80211_ATTR_TIMED_OUT], |
908 | tb[NL80211_ATTR_WIPHY_FREQ], tb[NL80211_ATTR_ACK], | |
909 | tb[NL80211_ATTR_COOKIE]); | |
c2a04078 | 910 | break; |
da72a1c1 ZY |
911 | case NL80211_CMD_CONNECT: |
912 | case NL80211_CMD_ROAM: | |
913 | mlme_event_connect(drv, gnlh->cmd, | |
914 | tb[NL80211_ATTR_STATUS_CODE], | |
915 | tb[NL80211_ATTR_MAC], | |
916 | tb[NL80211_ATTR_REQ_IE], | |
917 | tb[NL80211_ATTR_RESP_IE]); | |
918 | break; | |
919 | case NL80211_CMD_DISCONNECT: | |
7da2c527 JM |
920 | if (drv->capa.flags & WPA_DRIVER_FLAGS_SME) { |
921 | /* | |
922 | * Avoid reporting two disassociation events that could | |
923 | * confuse the core code. | |
924 | */ | |
925 | wpa_printf(MSG_DEBUG, "nl80211: Ignore disconnect " | |
926 | "event when using userspace SME"); | |
927 | break; | |
928 | } | |
da72a1c1 ZY |
929 | drv->associated = 0; |
930 | wpa_supplicant_event(drv->ctx, EVENT_DISASSOC, NULL); | |
931 | break; | |
35583f3f JM |
932 | case NL80211_CMD_MICHAEL_MIC_FAILURE: |
933 | mlme_event_michael_mic_failure(drv, tb); | |
934 | break; | |
5cc4d64b JM |
935 | case NL80211_CMD_JOIN_IBSS: |
936 | mlme_event_join_ibss(drv, tb); | |
937 | break; | |
55777702 JM |
938 | case NL80211_CMD_REMAIN_ON_CHANNEL: |
939 | mlme_event_remain_on_channel(drv, 0, tb); | |
940 | break; | |
941 | case NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL: | |
942 | mlme_event_remain_on_channel(drv, 1, tb); | |
943 | break; | |
97865538 | 944 | default: |
c2a04078 JM |
945 | wpa_printf(MSG_DEBUG, "nl80211: Ignored unknown event " |
946 | "(cmd=%d)", gnlh->cmd); | |
97865538 JM |
947 | break; |
948 | } | |
949 | ||
950 | return NL_SKIP; | |
951 | } | |
952 | ||
953 | ||
954 | static void wpa_driver_nl80211_event_receive(int sock, void *eloop_ctx, | |
955 | void *sock_ctx) | |
956 | { | |
957 | struct nl_cb *cb; | |
958 | struct wpa_driver_nl80211_data *drv = eloop_ctx; | |
959 | ||
960 | wpa_printf(MSG_DEBUG, "nl80211: Event message available"); | |
961 | ||
962 | cb = nl_cb_clone(drv->nl_cb); | |
963 | if (!cb) | |
964 | return; | |
965 | nl_cb_set(cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, no_seq_check, NULL); | |
966 | nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, process_event, drv); | |
335ce76b | 967 | nl_recvmsgs(drv->nl_handle_event, cb); |
97865538 JM |
968 | nl_cb_put(cb); |
969 | } | |
970 | ||
971 | ||
6d158490 LR |
972 | /** |
973 | * wpa_driver_nl80211_set_country - ask nl80211 to set the regulatory domain | |
974 | * @priv: driver_nl80211 private data | |
975 | * @alpha2_arg: country to which to switch to | |
976 | * Returns: 0 on success, -1 on failure | |
977 | * | |
978 | * This asks nl80211 to set the regulatory domain for given | |
979 | * country ISO / IEC alpha2. | |
980 | */ | |
981 | static int wpa_driver_nl80211_set_country(void *priv, const char *alpha2_arg) | |
982 | { | |
a2e40bb6 FF |
983 | struct i802_bss *bss = priv; |
984 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
6d158490 LR |
985 | char alpha2[3]; |
986 | struct nl_msg *msg; | |
987 | ||
988 | msg = nlmsg_alloc(); | |
989 | if (!msg) | |
e785c2ba | 990 | return -ENOMEM; |
6d158490 LR |
991 | |
992 | alpha2[0] = alpha2_arg[0]; | |
993 | alpha2[1] = alpha2_arg[1]; | |
994 | alpha2[2] = '\0'; | |
995 | ||
996 | genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0, | |
997 | 0, NL80211_CMD_REQ_SET_REG, 0); | |
998 | ||
999 | NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2, alpha2); | |
1000 | if (send_and_recv_msgs(drv, msg, NULL, NULL)) | |
1001 | return -EINVAL; | |
1002 | return 0; | |
1003 | nla_put_failure: | |
1004 | return -EINVAL; | |
1005 | } | |
1006 | ||
1007 | ||
bbaf0837 | 1008 | #ifndef HOSTAPD |
80bc75f1 JM |
1009 | struct wiphy_info_data { |
1010 | int max_scan_ssids; | |
1581b38b | 1011 | int ap_supported; |
93d11400 ZY |
1012 | int auth_supported; |
1013 | int connect_supported; | |
80bc75f1 JM |
1014 | }; |
1015 | ||
1016 | ||
1017 | static int wiphy_info_handler(struct nl_msg *msg, void *arg) | |
1018 | { | |
1019 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
1020 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
1021 | struct wiphy_info_data *info = arg; | |
1022 | ||
1023 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
1024 | genlmsg_attrlen(gnlh, 0), NULL); | |
1025 | ||
1026 | if (tb[NL80211_ATTR_MAX_NUM_SCAN_SSIDS]) | |
1027 | info->max_scan_ssids = | |
1028 | nla_get_u8(tb[NL80211_ATTR_MAX_NUM_SCAN_SSIDS]); | |
1029 | ||
1581b38b JM |
1030 | if (tb[NL80211_ATTR_SUPPORTED_IFTYPES]) { |
1031 | struct nlattr *nl_mode; | |
1032 | int i; | |
1033 | nla_for_each_nested(nl_mode, | |
1034 | tb[NL80211_ATTR_SUPPORTED_IFTYPES], i) { | |
1035 | if (nl_mode->nla_type == NL80211_IFTYPE_AP) { | |
1036 | info->ap_supported = 1; | |
1037 | break; | |
1038 | } | |
1039 | } | |
1040 | } | |
1041 | ||
93d11400 ZY |
1042 | if (tb[NL80211_ATTR_SUPPORTED_COMMANDS]) { |
1043 | struct nlattr *nl_cmd; | |
1044 | int i; | |
1045 | ||
1046 | nla_for_each_nested(nl_cmd, | |
1047 | tb[NL80211_ATTR_SUPPORTED_COMMANDS], i) { | |
1048 | u32 cmd = nla_get_u32(nl_cmd); | |
1049 | if (cmd == NL80211_CMD_AUTHENTICATE) | |
1050 | info->auth_supported = 1; | |
1051 | else if (cmd == NL80211_CMD_CONNECT) | |
1052 | info->connect_supported = 1; | |
1053 | } | |
1054 | } | |
1055 | ||
80bc75f1 JM |
1056 | return NL_SKIP; |
1057 | } | |
1058 | ||
1059 | ||
1060 | static int wpa_driver_nl80211_get_info(struct wpa_driver_nl80211_data *drv, | |
1061 | struct wiphy_info_data *info) | |
1062 | { | |
1063 | struct nl_msg *msg; | |
1064 | ||
1065 | os_memset(info, 0, sizeof(*info)); | |
1066 | msg = nlmsg_alloc(); | |
1067 | if (!msg) | |
1068 | return -1; | |
1069 | ||
1070 | genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0, | |
1071 | 0, NL80211_CMD_GET_WIPHY, 0); | |
1072 | ||
a2e40bb6 | 1073 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->first_bss.ifindex); |
80bc75f1 JM |
1074 | |
1075 | if (send_and_recv_msgs(drv, msg, wiphy_info_handler, info) == 0) | |
1076 | return 0; | |
1077 | msg = NULL; | |
1078 | nla_put_failure: | |
1079 | nlmsg_free(msg); | |
1080 | return -1; | |
1081 | } | |
1082 | ||
1083 | ||
93d11400 | 1084 | static int wpa_driver_nl80211_capa(struct wpa_driver_nl80211_data *drv) |
80bc75f1 JM |
1085 | { |
1086 | struct wiphy_info_data info; | |
1087 | if (wpa_driver_nl80211_get_info(drv, &info)) | |
93d11400 | 1088 | return -1; |
80bc75f1 | 1089 | drv->has_capability = 1; |
1b2a72e8 JM |
1090 | /* For now, assume TKIP, CCMP, WPA, WPA2 are supported */ |
1091 | drv->capa.key_mgmt = WPA_DRIVER_CAPA_KEY_MGMT_WPA | | |
1092 | WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK | | |
1093 | WPA_DRIVER_CAPA_KEY_MGMT_WPA2 | | |
1094 | WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK; | |
1095 | drv->capa.enc = WPA_DRIVER_CAPA_ENC_WEP40 | | |
1096 | WPA_DRIVER_CAPA_ENC_WEP104 | | |
1097 | WPA_DRIVER_CAPA_ENC_TKIP | | |
1098 | WPA_DRIVER_CAPA_ENC_CCMP; | |
291b6068 JM |
1099 | drv->capa.auth = WPA_DRIVER_AUTH_OPEN | |
1100 | WPA_DRIVER_AUTH_SHARED | | |
1101 | WPA_DRIVER_AUTH_LEAP; | |
1b2a72e8 | 1102 | |
80bc75f1 | 1103 | drv->capa.max_scan_ssids = info.max_scan_ssids; |
1581b38b JM |
1104 | if (info.ap_supported) |
1105 | drv->capa.flags |= WPA_DRIVER_FLAGS_AP; | |
93d11400 ZY |
1106 | |
1107 | if (info.auth_supported) | |
1108 | drv->capa.flags |= WPA_DRIVER_FLAGS_SME; | |
1109 | else if (!info.connect_supported) { | |
1110 | wpa_printf(MSG_INFO, "nl80211: Driver does not support " | |
1111 | "authentication/association or connect commands"); | |
1112 | return -1; | |
1113 | } | |
1114 | ||
0194fedb JB |
1115 | drv->capa.flags |= WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE; |
1116 | ||
93d11400 | 1117 | return 0; |
80bc75f1 | 1118 | } |
bbaf0837 | 1119 | #endif /* HOSTAPD */ |
80bc75f1 JM |
1120 | |
1121 | ||
9fff9fdc JM |
1122 | static int wpa_driver_nl80211_init_nl(struct wpa_driver_nl80211_data *drv, |
1123 | void *ctx) | |
3f5285e8 | 1124 | { |
9fff9fdc | 1125 | int ret; |
3f5285e8 | 1126 | |
9fff9fdc | 1127 | /* Initialize generic netlink and nl80211 */ |
3f5285e8 JM |
1128 | |
1129 | drv->nl_cb = nl_cb_alloc(NL_CB_DEFAULT); | |
1130 | if (drv->nl_cb == NULL) { | |
1131 | wpa_printf(MSG_ERROR, "nl80211: Failed to allocate netlink " | |
1132 | "callbacks"); | |
1133 | goto err1; | |
1134 | } | |
1135 | ||
1136 | drv->nl_handle = nl_handle_alloc_cb(drv->nl_cb); | |
1137 | if (drv->nl_handle == NULL) { | |
1138 | wpa_printf(MSG_ERROR, "nl80211: Failed to allocate netlink " | |
1139 | "callbacks"); | |
1140 | goto err2; | |
1141 | } | |
1142 | ||
335ce76b JM |
1143 | drv->nl_handle_event = nl_handle_alloc_cb(drv->nl_cb); |
1144 | if (drv->nl_handle_event == NULL) { | |
1145 | wpa_printf(MSG_ERROR, "nl80211: Failed to allocate netlink " | |
1146 | "callbacks (event)"); | |
1147 | goto err2b; | |
1148 | } | |
1149 | ||
3f5285e8 JM |
1150 | if (genl_connect(drv->nl_handle)) { |
1151 | wpa_printf(MSG_ERROR, "nl80211: Failed to connect to generic " | |
1152 | "netlink"); | |
1153 | goto err3; | |
1154 | } | |
1155 | ||
335ce76b JM |
1156 | if (genl_connect(drv->nl_handle_event)) { |
1157 | wpa_printf(MSG_ERROR, "nl80211: Failed to connect to generic " | |
1158 | "netlink (event)"); | |
1159 | goto err3; | |
1160 | } | |
1161 | ||
9fff9fdc JM |
1162 | #ifdef CONFIG_LIBNL20 |
1163 | if (genl_ctrl_alloc_cache(drv->nl_handle, &drv->nl_cache) < 0) { | |
1164 | wpa_printf(MSG_ERROR, "nl80211: Failed to allocate generic " | |
1165 | "netlink cache"); | |
1166 | goto err3; | |
1167 | } | |
335ce76b JM |
1168 | if (genl_ctrl_alloc_cache(drv->nl_handle_event, &drv->nl_cache_event) < |
1169 | 0) { | |
1170 | wpa_printf(MSG_ERROR, "nl80211: Failed to allocate generic " | |
1171 | "netlink cache (event)"); | |
1172 | goto err3b; | |
1173 | } | |
9fff9fdc | 1174 | #else /* CONFIG_LIBNL20 */ |
3f5285e8 JM |
1175 | drv->nl_cache = genl_ctrl_alloc_cache(drv->nl_handle); |
1176 | if (drv->nl_cache == NULL) { | |
1177 | wpa_printf(MSG_ERROR, "nl80211: Failed to allocate generic " | |
1178 | "netlink cache"); | |
1179 | goto err3; | |
1180 | } | |
335ce76b JM |
1181 | drv->nl_cache_event = genl_ctrl_alloc_cache(drv->nl_handle_event); |
1182 | if (drv->nl_cache_event == NULL) { | |
1183 | wpa_printf(MSG_ERROR, "nl80211: Failed to allocate generic " | |
1184 | "netlink cache (event)"); | |
1185 | goto err3b; | |
1186 | } | |
9fff9fdc JM |
1187 | #endif /* CONFIG_LIBNL20 */ |
1188 | ||
3f5285e8 JM |
1189 | drv->nl80211 = genl_ctrl_search_by_name(drv->nl_cache, "nl80211"); |
1190 | if (drv->nl80211 == NULL) { | |
1191 | wpa_printf(MSG_ERROR, "nl80211: 'nl80211' generic netlink not " | |
1192 | "found"); | |
1193 | goto err4; | |
1194 | } | |
1195 | ||
97865538 JM |
1196 | ret = nl_get_multicast_id(drv, "nl80211", "scan"); |
1197 | if (ret >= 0) | |
335ce76b | 1198 | ret = nl_socket_add_membership(drv->nl_handle_event, ret); |
97865538 JM |
1199 | if (ret < 0) { |
1200 | wpa_printf(MSG_ERROR, "nl80211: Could not add multicast " | |
1201 | "membership for scan events: %d (%s)", | |
1202 | ret, strerror(-ret)); | |
1203 | goto err4; | |
1204 | } | |
c2a04078 JM |
1205 | |
1206 | ret = nl_get_multicast_id(drv, "nl80211", "mlme"); | |
1207 | if (ret >= 0) | |
335ce76b | 1208 | ret = nl_socket_add_membership(drv->nl_handle_event, ret); |
c2a04078 JM |
1209 | if (ret < 0) { |
1210 | wpa_printf(MSG_ERROR, "nl80211: Could not add multicast " | |
1211 | "membership for mlme events: %d (%s)", | |
1212 | ret, strerror(-ret)); | |
1213 | goto err4; | |
1214 | } | |
c2a04078 | 1215 | |
335ce76b | 1216 | eloop_register_read_sock(nl_socket_get_fd(drv->nl_handle_event), |
97865538 JM |
1217 | wpa_driver_nl80211_event_receive, drv, ctx); |
1218 | ||
9fff9fdc JM |
1219 | return 0; |
1220 | ||
1221 | err4: | |
335ce76b JM |
1222 | nl_cache_free(drv->nl_cache_event); |
1223 | err3b: | |
9fff9fdc JM |
1224 | nl_cache_free(drv->nl_cache); |
1225 | err3: | |
335ce76b JM |
1226 | nl_handle_destroy(drv->nl_handle_event); |
1227 | err2b: | |
9fff9fdc JM |
1228 | nl_handle_destroy(drv->nl_handle); |
1229 | err2: | |
1230 | nl_cb_put(drv->nl_cb); | |
1231 | err1: | |
1232 | return -1; | |
1233 | } | |
1234 | ||
1235 | ||
1236 | /** | |
1237 | * wpa_driver_nl80211_init - Initialize nl80211 driver interface | |
1238 | * @ctx: context to be used when calling wpa_supplicant functions, | |
1239 | * e.g., wpa_supplicant_event() | |
1240 | * @ifname: interface name, e.g., wlan0 | |
1241 | * Returns: Pointer to private data, %NULL on failure | |
1242 | */ | |
1243 | static void * wpa_driver_nl80211_init(void *ctx, const char *ifname) | |
1244 | { | |
9fff9fdc | 1245 | struct wpa_driver_nl80211_data *drv; |
08063178 | 1246 | struct netlink_config *cfg; |
a2e40bb6 | 1247 | struct i802_bss *bss; |
9fff9fdc JM |
1248 | |
1249 | drv = os_zalloc(sizeof(*drv)); | |
1250 | if (drv == NULL) | |
1251 | return NULL; | |
1252 | drv->ctx = ctx; | |
a2e40bb6 FF |
1253 | bss = &drv->first_bss; |
1254 | bss->drv = drv; | |
1255 | os_strlcpy(bss->ifname, ifname, sizeof(bss->ifname)); | |
9fff9fdc JM |
1256 | drv->monitor_ifidx = -1; |
1257 | drv->monitor_sock = -1; | |
bbaf0837 | 1258 | drv->ioctl_sock = -1; |
9fff9fdc | 1259 | |
bbaf0837 JM |
1260 | if (wpa_driver_nl80211_init_nl(drv, ctx)) { |
1261 | os_free(drv); | |
1262 | return NULL; | |
1263 | } | |
9fff9fdc | 1264 | |
3f5285e8 JM |
1265 | drv->ioctl_sock = socket(PF_INET, SOCK_DGRAM, 0); |
1266 | if (drv->ioctl_sock < 0) { | |
1267 | perror("socket(PF_INET,SOCK_DGRAM)"); | |
bbaf0837 | 1268 | goto failed; |
3f5285e8 JM |
1269 | } |
1270 | ||
08063178 JM |
1271 | cfg = os_zalloc(sizeof(*cfg)); |
1272 | if (cfg == NULL) | |
1273 | goto failed; | |
1274 | cfg->ctx = drv; | |
1275 | cfg->newlink_cb = wpa_driver_nl80211_event_rtm_newlink; | |
1276 | cfg->dellink_cb = wpa_driver_nl80211_event_rtm_dellink; | |
1277 | drv->netlink = netlink_init(cfg); | |
1278 | if (drv->netlink == NULL) { | |
1279 | os_free(cfg); | |
1280 | goto failed; | |
1281 | } | |
1282 | if (wpa_driver_nl80211_finish_drv_init(drv)) | |
bbaf0837 | 1283 | goto failed; |
7524cfb1 | 1284 | |
a2e40bb6 | 1285 | return bss; |
7524cfb1 | 1286 | |
bbaf0837 | 1287 | failed: |
08063178 | 1288 | netlink_deinit(drv->netlink); |
bbaf0837 JM |
1289 | if (drv->ioctl_sock >= 0) |
1290 | close(drv->ioctl_sock); | |
1291 | ||
7524cfb1 | 1292 | genl_family_put(drv->nl80211); |
7524cfb1 | 1293 | nl_cache_free(drv->nl_cache); |
7524cfb1 | 1294 | nl_handle_destroy(drv->nl_handle); |
7524cfb1 | 1295 | nl_cb_put(drv->nl_cb); |
05ba8690 | 1296 | eloop_unregister_read_sock(nl_socket_get_fd(drv->nl_handle_event)); |
bbaf0837 | 1297 | |
7524cfb1 JM |
1298 | os_free(drv); |
1299 | return NULL; | |
1300 | } | |
1301 | ||
1302 | ||
58f6fbe0 JM |
1303 | static int nl80211_register_action_frame(struct wpa_driver_nl80211_data *drv, |
1304 | const u8 *match, size_t match_len) | |
1305 | { | |
1306 | struct nl_msg *msg; | |
1307 | int ret = -1; | |
1308 | ||
1309 | msg = nlmsg_alloc(); | |
1310 | if (!msg) | |
1311 | return -1; | |
1312 | ||
1313 | genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0, 0, | |
1314 | NL80211_CMD_REGISTER_ACTION, 0); | |
1315 | ||
1316 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); | |
1317 | NLA_PUT(msg, NL80211_ATTR_FRAME_MATCH, match_len, match); | |
1318 | ||
1319 | ret = send_and_recv(drv, drv->nl_handle_event, msg, NULL, NULL); | |
1320 | msg = NULL; | |
1321 | if (ret) { | |
1322 | wpa_printf(MSG_DEBUG, "nl80211: Register Action command " | |
1323 | "failed: ret=%d (%s)", ret, strerror(-ret)); | |
1324 | wpa_hexdump(MSG_DEBUG, "nl80211: Register Action match", | |
1325 | match, match_len); | |
1326 | goto nla_put_failure; | |
1327 | } | |
1328 | ret = 0; | |
1329 | nla_put_failure: | |
1330 | nlmsg_free(msg); | |
1331 | return ret; | |
1332 | } | |
1333 | ||
1334 | ||
1335 | static int nl80211_register_action_frames(struct wpa_driver_nl80211_data *drv) | |
1336 | { | |
1337 | if (0) { | |
1338 | /* Public Action frames */ | |
1339 | return nl80211_register_action_frame(drv, (u8 *) "\x04", 1); | |
1340 | } | |
1341 | return 0; | |
1342 | } | |
1343 | ||
1344 | ||
362f781e | 1345 | static int |
7524cfb1 JM |
1346 | wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data *drv) |
1347 | { | |
a2e40bb6 FF |
1348 | struct i802_bss *bss = &drv->first_bss; |
1349 | ||
1350 | drv->ifindex = if_nametoindex(bss->ifname); | |
1351 | drv->first_bss.ifindex = drv->ifindex; | |
a87c9d96 | 1352 | |
bbaf0837 | 1353 | #ifndef HOSTAPD |
a2e40bb6 | 1354 | if (wpa_driver_nl80211_set_mode(bss, IEEE80211_MODE_INFRA) < 0) { |
a87c9d96 JM |
1355 | wpa_printf(MSG_DEBUG, "nl80211: Could not configure driver to " |
1356 | "use managed mode"); | |
1357 | } | |
1358 | ||
a2e40bb6 | 1359 | if (linux_set_iface_flags(drv->ioctl_sock, bss->ifname, 1)) { |
34f2f814 | 1360 | wpa_printf(MSG_ERROR, "Could not set interface '%s' UP", |
a2e40bb6 | 1361 | bss->ifname); |
362f781e JM |
1362 | return -1; |
1363 | } | |
3f5285e8 | 1364 | |
93d11400 ZY |
1365 | if (wpa_driver_nl80211_capa(drv)) |
1366 | return -1; | |
80bc75f1 | 1367 | |
08063178 | 1368 | netlink_send_oper_ifla(drv->netlink, drv->ifindex, |
e2d02c29 | 1369 | 1, IF_OPER_DORMANT); |
bbaf0837 | 1370 | #endif /* HOSTAPD */ |
362f781e | 1371 | |
58f6fbe0 JM |
1372 | if (nl80211_register_action_frames(drv) < 0) |
1373 | return -1; | |
1374 | ||
362f781e | 1375 | return 0; |
3f5285e8 JM |
1376 | } |
1377 | ||
1378 | ||
8a27af5c JM |
1379 | static int wpa_driver_nl80211_del_beacon(struct wpa_driver_nl80211_data *drv) |
1380 | { | |
1381 | struct nl_msg *msg; | |
1382 | ||
1383 | msg = nlmsg_alloc(); | |
1384 | if (!msg) | |
1385 | return -ENOMEM; | |
1386 | ||
1387 | genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0, | |
1388 | 0, NL80211_CMD_DEL_BEACON, 0); | |
1389 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); | |
1390 | ||
1391 | return send_and_recv_msgs(drv, msg, NULL, NULL); | |
1392 | nla_put_failure: | |
1393 | return -ENOBUFS; | |
1394 | } | |
8a27af5c JM |
1395 | |
1396 | ||
3f5285e8 | 1397 | /** |
7e5ba1b9 JM |
1398 | * wpa_driver_nl80211_deinit - Deinitialize nl80211 driver interface |
1399 | * @priv: Pointer to private nl80211 data from wpa_driver_nl80211_init() | |
3f5285e8 JM |
1400 | * |
1401 | * Shut down driver interface and processing of driver events. Free | |
1402 | * private data buffer if one was allocated in wpa_driver_nl80211_init(). | |
1403 | */ | |
7e5ba1b9 | 1404 | static void wpa_driver_nl80211_deinit(void *priv) |
3f5285e8 | 1405 | { |
a2e40bb6 FF |
1406 | struct i802_bss *bss = priv; |
1407 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
3f5285e8 | 1408 | |
94627f6c | 1409 | if (drv->added_if_into_bridge) { |
a2e40bb6 | 1410 | if (linux_br_del_if(drv->ioctl_sock, drv->brname, bss->ifname) |
94627f6c JM |
1411 | < 0) |
1412 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " | |
1413 | "interface %s from bridge %s: %s", | |
a2e40bb6 | 1414 | bss->ifname, drv->brname, strerror(errno)); |
94627f6c JM |
1415 | } |
1416 | if (drv->added_bridge) { | |
1417 | if (linux_br_del(drv->ioctl_sock, drv->brname) < 0) | |
1418 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " | |
1419 | "bridge %s: %s", | |
1420 | drv->brname, strerror(errno)); | |
1421 | } | |
1422 | ||
460456f8 | 1423 | nl80211_remove_monitor_interface(drv); |
8a27af5c JM |
1424 | |
1425 | if (drv->nlmode == NL80211_IFTYPE_AP) | |
1426 | wpa_driver_nl80211_del_beacon(drv); | |
0915d02c | 1427 | |
bbaf0837 JM |
1428 | #ifdef HOSTAPD |
1429 | if (drv->last_freq_ht) { | |
1430 | /* Clear HT flags from the driver */ | |
1431 | struct hostapd_freq_params freq; | |
1432 | os_memset(&freq, 0, sizeof(freq)); | |
1433 | freq.freq = drv->last_freq; | |
1434 | i802_set_freq(priv, &freq); | |
1435 | } | |
1436 | ||
bbaf0837 JM |
1437 | if (drv->eapol_sock >= 0) { |
1438 | eloop_unregister_read_sock(drv->eapol_sock); | |
1439 | close(drv->eapol_sock); | |
1440 | } | |
1441 | ||
1442 | if (drv->if_indices != drv->default_if_indices) | |
1443 | os_free(drv->if_indices); | |
1b648c7e | 1444 | #endif /* HOSTAPD */ |
3f5285e8 | 1445 | |
4e5cb1a3 JM |
1446 | if (drv->disable_11b_rates) |
1447 | nl80211_disable_11b_rates(drv, drv->ifindex, 0); | |
1448 | ||
08063178 JM |
1449 | netlink_send_oper_ifla(drv->netlink, drv->ifindex, 0, IF_OPER_UP); |
1450 | netlink_deinit(drv->netlink); | |
3f5285e8 | 1451 | |
bbaf0837 JM |
1452 | eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout, drv, drv->ctx); |
1453 | ||
a2e40bb6 FF |
1454 | (void) linux_set_iface_flags(drv->ioctl_sock, bss->ifname, 0); |
1455 | wpa_driver_nl80211_set_mode(bss, IEEE80211_MODE_INFRA); | |
3f5285e8 | 1456 | |
bbaf0837 JM |
1457 | if (drv->ioctl_sock >= 0) |
1458 | close(drv->ioctl_sock); | |
3f5285e8 | 1459 | |
335ce76b | 1460 | eloop_unregister_read_sock(nl_socket_get_fd(drv->nl_handle_event)); |
3f5285e8 JM |
1461 | genl_family_put(drv->nl80211); |
1462 | nl_cache_free(drv->nl_cache); | |
335ce76b | 1463 | nl_cache_free(drv->nl_cache_event); |
3f5285e8 | 1464 | nl_handle_destroy(drv->nl_handle); |
335ce76b | 1465 | nl_handle_destroy(drv->nl_handle_event); |
3f5285e8 JM |
1466 | nl_cb_put(drv->nl_cb); |
1467 | ||
504e905c JM |
1468 | eloop_cancel_timeout(wpa_driver_nl80211_probe_req_report_timeout, |
1469 | drv, NULL); | |
1470 | ||
3812464c JM |
1471 | os_free(drv->filter_ssids); |
1472 | ||
3f5285e8 JM |
1473 | os_free(drv); |
1474 | } | |
1475 | ||
1476 | ||
1477 | /** | |
1478 | * wpa_driver_nl80211_scan_timeout - Scan timeout to report scan completion | |
ad1e68e6 | 1479 | * @eloop_ctx: Driver private data |
3f5285e8 JM |
1480 | * @timeout_ctx: ctx argument given to wpa_driver_nl80211_init() |
1481 | * | |
1482 | * This function can be used as registered timeout when starting a scan to | |
1483 | * generate a scan completed event if the driver does not report this. | |
1484 | */ | |
1485 | static void wpa_driver_nl80211_scan_timeout(void *eloop_ctx, void *timeout_ctx) | |
1486 | { | |
ad1e68e6 JM |
1487 | struct wpa_driver_nl80211_data *drv = eloop_ctx; |
1488 | if (drv->ap_scan_as_station) { | |
a2e40bb6 FF |
1489 | wpa_driver_nl80211_set_mode(&drv->first_bss, |
1490 | IEEE80211_MODE_AP); | |
ad1e68e6 JM |
1491 | drv->ap_scan_as_station = 0; |
1492 | } | |
3f5285e8 JM |
1493 | wpa_printf(MSG_DEBUG, "Scan timeout - try to get results"); |
1494 | wpa_supplicant_event(timeout_ctx, EVENT_SCAN_RESULTS, NULL); | |
1495 | } | |
1496 | ||
1497 | ||
1498 | /** | |
1499 | * wpa_driver_nl80211_scan - Request the driver to initiate scan | |
ad1e68e6 | 1500 | * @priv: Pointer to private driver data from wpa_driver_nl80211_init() |
6a1063e0 | 1501 | * @params: Scan parameters |
3f5285e8 JM |
1502 | * Returns: 0 on success, -1 on failure |
1503 | */ | |
6a1063e0 JM |
1504 | static int wpa_driver_nl80211_scan(void *priv, |
1505 | struct wpa_driver_scan_params *params) | |
3f5285e8 | 1506 | { |
a2e40bb6 FF |
1507 | struct i802_bss *bss = priv; |
1508 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
3f5285e8 | 1509 | int ret = 0, timeout; |
d3a98225 | 1510 | struct nl_msg *msg, *ssids, *freqs; |
6a1063e0 | 1511 | size_t i; |
3f5285e8 | 1512 | |
0e75527f JM |
1513 | msg = nlmsg_alloc(); |
1514 | ssids = nlmsg_alloc(); | |
d3a98225 JM |
1515 | freqs = nlmsg_alloc(); |
1516 | if (!msg || !ssids || !freqs) { | |
0e75527f JM |
1517 | nlmsg_free(msg); |
1518 | nlmsg_free(ssids); | |
d3a98225 | 1519 | nlmsg_free(freqs); |
3f5285e8 JM |
1520 | return -1; |
1521 | } | |
1522 | ||
3812464c JM |
1523 | os_free(drv->filter_ssids); |
1524 | drv->filter_ssids = params->filter_ssids; | |
1525 | params->filter_ssids = NULL; | |
1526 | drv->num_filter_ssids = params->num_filter_ssids; | |
1527 | ||
0e75527f JM |
1528 | genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0, 0, |
1529 | NL80211_CMD_TRIGGER_SCAN, 0); | |
1530 | ||
1531 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); | |
3f5285e8 | 1532 | |
6a1063e0 JM |
1533 | for (i = 0; i < params->num_ssids; i++) { |
1534 | NLA_PUT(ssids, i + 1, params->ssids[i].ssid_len, | |
1535 | params->ssids[i].ssid); | |
3f5285e8 | 1536 | } |
6a1063e0 JM |
1537 | if (params->num_ssids) |
1538 | nla_put_nested(msg, NL80211_ATTR_SCAN_SSIDS, ssids); | |
3f5285e8 | 1539 | |
d173df52 JM |
1540 | if (params->extra_ies) { |
1541 | NLA_PUT(msg, NL80211_ATTR_IE, params->extra_ies_len, | |
1542 | params->extra_ies); | |
1543 | } | |
1544 | ||
d3a98225 JM |
1545 | if (params->freqs) { |
1546 | for (i = 0; params->freqs[i]; i++) | |
1547 | NLA_PUT_U32(freqs, i + 1, params->freqs[i]); | |
1548 | nla_put_nested(msg, NL80211_ATTR_SCAN_FREQUENCIES, freqs); | |
1549 | } | |
1550 | ||
0e75527f JM |
1551 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
1552 | msg = NULL; | |
1553 | if (ret) { | |
1554 | wpa_printf(MSG_DEBUG, "nl80211: Scan trigger failed: ret=%d " | |
1555 | "(%s)", ret, strerror(-ret)); | |
ad1e68e6 JM |
1556 | #ifdef HOSTAPD |
1557 | if (drv->nlmode == NL80211_IFTYPE_AP) { | |
1558 | /* | |
1559 | * mac80211 does not allow scan requests in AP mode, so | |
1560 | * try to do this in station mode. | |
1561 | */ | |
a2e40bb6 | 1562 | if (wpa_driver_nl80211_set_mode(bss, |
ad1e68e6 JM |
1563 | IEEE80211_MODE_INFRA)) |
1564 | goto nla_put_failure; | |
1565 | ||
1566 | if (wpa_driver_nl80211_scan(drv, params)) { | |
a2e40bb6 | 1567 | wpa_driver_nl80211_set_mode(bss, |
ad1e68e6 JM |
1568 | IEEE80211_MODE_AP); |
1569 | goto nla_put_failure; | |
1570 | } | |
1571 | ||
1572 | /* Restore AP mode when processing scan results */ | |
1573 | drv->ap_scan_as_station = 1; | |
1574 | ret = 0; | |
1575 | } else | |
1576 | goto nla_put_failure; | |
1577 | #else /* HOSTAPD */ | |
0e75527f | 1578 | goto nla_put_failure; |
ad1e68e6 | 1579 | #endif /* HOSTAPD */ |
3f5285e8 JM |
1580 | } |
1581 | ||
1582 | /* Not all drivers generate "scan completed" wireless event, so try to | |
1583 | * read results after a timeout. */ | |
0e75527f | 1584 | timeout = 10; |
3f5285e8 JM |
1585 | if (drv->scan_complete_events) { |
1586 | /* | |
d173df52 JM |
1587 | * The driver seems to deliver events to notify when scan is |
1588 | * complete, so use longer timeout to avoid race conditions | |
1589 | * with scanning and following association request. | |
3f5285e8 JM |
1590 | */ |
1591 | timeout = 30; | |
1592 | } | |
1593 | wpa_printf(MSG_DEBUG, "Scan requested (ret=%d) - scan timeout %d " | |
1594 | "seconds", ret, timeout); | |
1595 | eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout, drv, drv->ctx); | |
0e75527f JM |
1596 | eloop_register_timeout(timeout, 0, wpa_driver_nl80211_scan_timeout, |
1597 | drv, drv->ctx); | |
3f5285e8 | 1598 | |
0e75527f JM |
1599 | nla_put_failure: |
1600 | nlmsg_free(ssids); | |
1601 | nlmsg_free(msg); | |
d3a98225 | 1602 | nlmsg_free(freqs); |
3f5285e8 JM |
1603 | return ret; |
1604 | } | |
1605 | ||
1606 | ||
3812464c JM |
1607 | static const u8 * nl80211_get_ie(const u8 *ies, size_t ies_len, u8 ie) |
1608 | { | |
1609 | const u8 *end, *pos; | |
1610 | ||
1611 | if (ies == NULL) | |
1612 | return NULL; | |
1613 | ||
1614 | pos = ies; | |
1615 | end = ies + ies_len; | |
1616 | ||
1617 | while (pos + 1 < end) { | |
1618 | if (pos + 2 + pos[1] > end) | |
1619 | break; | |
1620 | if (pos[0] == ie) | |
1621 | return pos; | |
1622 | pos += 2 + pos[1]; | |
1623 | } | |
1624 | ||
1625 | return NULL; | |
1626 | } | |
1627 | ||
1628 | ||
1629 | static int nl80211_scan_filtered(struct wpa_driver_nl80211_data *drv, | |
1630 | const u8 *ie, size_t ie_len) | |
1631 | { | |
1632 | const u8 *ssid; | |
1633 | size_t i; | |
1634 | ||
1635 | if (drv->filter_ssids == NULL) | |
1636 | return 0; | |
1637 | ||
1638 | ssid = nl80211_get_ie(ie, ie_len, WLAN_EID_SSID); | |
1639 | if (ssid == NULL) | |
1640 | return 1; | |
1641 | ||
1642 | for (i = 0; i < drv->num_filter_ssids; i++) { | |
1643 | if (ssid[1] == drv->filter_ssids[i].ssid_len && | |
1644 | os_memcmp(ssid + 2, drv->filter_ssids[i].ssid, ssid[1]) == | |
1645 | 0) | |
1646 | return 0; | |
1647 | } | |
1648 | ||
1649 | return 1; | |
1650 | } | |
1651 | ||
1652 | ||
1653 | struct nl80211_bss_info_arg { | |
1654 | struct wpa_driver_nl80211_data *drv; | |
1655 | struct wpa_scan_results *res; | |
1656 | }; | |
1657 | ||
b3db1e1c | 1658 | static int bss_info_handler(struct nl_msg *msg, void *arg) |
3f5285e8 | 1659 | { |
b3db1e1c JM |
1660 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
1661 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
1662 | struct nlattr *bss[NL80211_BSS_MAX + 1]; | |
1663 | static struct nla_policy bss_policy[NL80211_BSS_MAX + 1] = { | |
1664 | [NL80211_BSS_BSSID] = { .type = NLA_UNSPEC }, | |
1665 | [NL80211_BSS_FREQUENCY] = { .type = NLA_U32 }, | |
1666 | [NL80211_BSS_TSF] = { .type = NLA_U64 }, | |
1667 | [NL80211_BSS_BEACON_INTERVAL] = { .type = NLA_U16 }, | |
1668 | [NL80211_BSS_CAPABILITY] = { .type = NLA_U16 }, | |
1669 | [NL80211_BSS_INFORMATION_ELEMENTS] = { .type = NLA_UNSPEC }, | |
1670 | [NL80211_BSS_SIGNAL_MBM] = { .type = NLA_U32 }, | |
1671 | [NL80211_BSS_SIGNAL_UNSPEC] = { .type = NLA_U8 }, | |
e6b8efeb | 1672 | [NL80211_BSS_STATUS] = { .type = NLA_U32 }, |
b3ad11bb | 1673 | [NL80211_BSS_SEEN_MS_AGO] = { .type = NLA_U32 }, |
8c090654 | 1674 | [NL80211_BSS_BEACON_IES] = { .type = NLA_UNSPEC }, |
b3db1e1c | 1675 | }; |
3812464c JM |
1676 | struct nl80211_bss_info_arg *_arg = arg; |
1677 | struct wpa_scan_results *res = _arg->res; | |
3f5285e8 JM |
1678 | struct wpa_scan_res **tmp; |
1679 | struct wpa_scan_res *r; | |
8c090654 JM |
1680 | const u8 *ie, *beacon_ie; |
1681 | size_t ie_len, beacon_ie_len; | |
1682 | u8 *pos; | |
3f5285e8 | 1683 | |
b3db1e1c JM |
1684 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
1685 | genlmsg_attrlen(gnlh, 0), NULL); | |
1686 | if (!tb[NL80211_ATTR_BSS]) | |
1687 | return NL_SKIP; | |
1688 | if (nla_parse_nested(bss, NL80211_BSS_MAX, tb[NL80211_ATTR_BSS], | |
1689 | bss_policy)) | |
1690 | return NL_SKIP; | |
1691 | if (bss[NL80211_BSS_INFORMATION_ELEMENTS]) { | |
1692 | ie = nla_data(bss[NL80211_BSS_INFORMATION_ELEMENTS]); | |
1693 | ie_len = nla_len(bss[NL80211_BSS_INFORMATION_ELEMENTS]); | |
1694 | } else { | |
1695 | ie = NULL; | |
1696 | ie_len = 0; | |
1697 | } | |
8c090654 JM |
1698 | if (bss[NL80211_BSS_BEACON_IES]) { |
1699 | beacon_ie = nla_data(bss[NL80211_BSS_BEACON_IES]); | |
1700 | beacon_ie_len = nla_len(bss[NL80211_BSS_BEACON_IES]); | |
1701 | } else { | |
1702 | beacon_ie = NULL; | |
1703 | beacon_ie_len = 0; | |
1704 | } | |
3f5285e8 | 1705 | |
3812464c JM |
1706 | if (nl80211_scan_filtered(_arg->drv, ie ? ie : beacon_ie, |
1707 | ie ? ie_len : beacon_ie_len)) | |
1708 | return NL_SKIP; | |
1709 | ||
8c090654 | 1710 | r = os_zalloc(sizeof(*r) + ie_len + beacon_ie_len); |
3f5285e8 | 1711 | if (r == NULL) |
b3db1e1c JM |
1712 | return NL_SKIP; |
1713 | if (bss[NL80211_BSS_BSSID]) | |
1714 | os_memcpy(r->bssid, nla_data(bss[NL80211_BSS_BSSID]), | |
1715 | ETH_ALEN); | |
1716 | if (bss[NL80211_BSS_FREQUENCY]) | |
1717 | r->freq = nla_get_u32(bss[NL80211_BSS_FREQUENCY]); | |
1718 | if (bss[NL80211_BSS_BEACON_INTERVAL]) | |
1719 | r->beacon_int = nla_get_u16(bss[NL80211_BSS_BEACON_INTERVAL]); | |
1720 | if (bss[NL80211_BSS_CAPABILITY]) | |
1721 | r->caps = nla_get_u16(bss[NL80211_BSS_CAPABILITY]); | |
7c2849d2 JM |
1722 | r->flags |= WPA_SCAN_NOISE_INVALID; |
1723 | if (bss[NL80211_BSS_SIGNAL_MBM]) { | |
b3db1e1c | 1724 | r->level = nla_get_u32(bss[NL80211_BSS_SIGNAL_MBM]); |
7c2849d2 JM |
1725 | r->level /= 100; /* mBm to dBm */ |
1726 | r->flags |= WPA_SCAN_LEVEL_DBM | WPA_SCAN_QUAL_INVALID; | |
1727 | } else if (bss[NL80211_BSS_SIGNAL_UNSPEC]) { | |
1728 | r->level = nla_get_u8(bss[NL80211_BSS_SIGNAL_UNSPEC]); | |
1729 | r->flags |= WPA_SCAN_LEVEL_INVALID; | |
1730 | } else | |
1731 | r->flags |= WPA_SCAN_LEVEL_INVALID | WPA_SCAN_QUAL_INVALID; | |
b3db1e1c JM |
1732 | if (bss[NL80211_BSS_TSF]) |
1733 | r->tsf = nla_get_u64(bss[NL80211_BSS_TSF]); | |
b3ad11bb JM |
1734 | if (bss[NL80211_BSS_SEEN_MS_AGO]) |
1735 | r->age = nla_get_u32(bss[NL80211_BSS_SEEN_MS_AGO]); | |
b3db1e1c | 1736 | r->ie_len = ie_len; |
8c090654 JM |
1737 | pos = (u8 *) (r + 1); |
1738 | if (ie) { | |
1739 | os_memcpy(pos, ie, ie_len); | |
1740 | pos += ie_len; | |
1741 | } | |
1742 | r->beacon_ie_len = beacon_ie_len; | |
1743 | if (beacon_ie) | |
1744 | os_memcpy(pos, beacon_ie, beacon_ie_len); | |
3f5285e8 | 1745 | |
e6b8efeb JM |
1746 | if (bss[NL80211_BSS_STATUS]) { |
1747 | enum nl80211_bss_status status; | |
1748 | status = nla_get_u32(bss[NL80211_BSS_STATUS]); | |
1749 | switch (status) { | |
1750 | case NL80211_BSS_STATUS_AUTHENTICATED: | |
1751 | r->flags |= WPA_SCAN_AUTHENTICATED; | |
1752 | break; | |
1753 | case NL80211_BSS_STATUS_ASSOCIATED: | |
1754 | r->flags |= WPA_SCAN_ASSOCIATED; | |
1755 | break; | |
1756 | default: | |
1757 | break; | |
1758 | } | |
1759 | } | |
1760 | ||
3f5285e8 JM |
1761 | tmp = os_realloc(res->res, |
1762 | (res->num + 1) * sizeof(struct wpa_scan_res *)); | |
1763 | if (tmp == NULL) { | |
1764 | os_free(r); | |
b3db1e1c | 1765 | return NL_SKIP; |
3f5285e8 JM |
1766 | } |
1767 | tmp[res->num++] = r; | |
1768 | res->res = tmp; | |
b3db1e1c JM |
1769 | |
1770 | return NL_SKIP; | |
3f5285e8 | 1771 | } |
b3db1e1c | 1772 | |
3f5285e8 | 1773 | |
d72aad94 JM |
1774 | static void clear_state_mismatch(struct wpa_driver_nl80211_data *drv, |
1775 | const u8 *addr) | |
1776 | { | |
1777 | if (drv->capa.flags & WPA_DRIVER_FLAGS_SME) { | |
1778 | wpa_printf(MSG_DEBUG, "nl80211: Clear possible state " | |
582507be | 1779 | "mismatch (" MACSTR ")", MAC2STR(addr)); |
d72aad94 JM |
1780 | wpa_driver_nl80211_mlme(drv, addr, |
1781 | NL80211_CMD_DEAUTHENTICATE, | |
1782 | WLAN_REASON_PREV_AUTH_NOT_VALID); | |
1783 | } | |
1784 | } | |
1785 | ||
1786 | ||
e6b8efeb JM |
1787 | static void wpa_driver_nl80211_check_bss_status( |
1788 | struct wpa_driver_nl80211_data *drv, struct wpa_scan_results *res) | |
1789 | { | |
1790 | size_t i; | |
1791 | ||
1792 | for (i = 0; i < res->num; i++) { | |
1793 | struct wpa_scan_res *r = res->res[i]; | |
1794 | if (r->flags & WPA_SCAN_AUTHENTICATED) { | |
1795 | wpa_printf(MSG_DEBUG, "nl80211: Scan results " | |
1796 | "indicates BSS status with " MACSTR | |
1797 | " as authenticated", | |
1798 | MAC2STR(r->bssid)); | |
1799 | if (drv->nlmode == NL80211_IFTYPE_STATION && | |
1800 | os_memcmp(r->bssid, drv->bssid, ETH_ALEN) != 0 && | |
1801 | os_memcmp(r->bssid, drv->auth_bssid, ETH_ALEN) != | |
1802 | 0) { | |
1803 | wpa_printf(MSG_DEBUG, "nl80211: Unknown BSSID" | |
1804 | " in local state (auth=" MACSTR | |
1805 | " assoc=" MACSTR ")", | |
1806 | MAC2STR(drv->auth_bssid), | |
1807 | MAC2STR(drv->bssid)); | |
582507be | 1808 | clear_state_mismatch(drv, r->bssid); |
e6b8efeb JM |
1809 | } |
1810 | } | |
1811 | ||
1812 | if (r->flags & WPA_SCAN_ASSOCIATED) { | |
1813 | wpa_printf(MSG_DEBUG, "nl80211: Scan results " | |
1814 | "indicate BSS status with " MACSTR | |
1815 | " as associated", | |
1816 | MAC2STR(r->bssid)); | |
1817 | if (drv->nlmode == NL80211_IFTYPE_STATION && | |
1818 | !drv->associated) { | |
1819 | wpa_printf(MSG_DEBUG, "nl80211: Local state " | |
1820 | "(not associated) does not match " | |
1821 | "with BSS state"); | |
d72aad94 | 1822 | clear_state_mismatch(drv, r->bssid); |
e6b8efeb JM |
1823 | } else if (drv->nlmode == NL80211_IFTYPE_STATION && |
1824 | os_memcmp(drv->bssid, r->bssid, ETH_ALEN) != | |
1825 | 0) { | |
1826 | wpa_printf(MSG_DEBUG, "nl80211: Local state " | |
1827 | "(associated with " MACSTR ") does " | |
1828 | "not match with BSS state", | |
d72aad94 JM |
1829 | MAC2STR(drv->bssid)); |
1830 | clear_state_mismatch(drv, r->bssid); | |
1831 | clear_state_mismatch(drv, drv->bssid); | |
e6b8efeb JM |
1832 | } |
1833 | } | |
1834 | } | |
1835 | } | |
1836 | ||
1837 | ||
d1f9c410 JM |
1838 | static void wpa_scan_results_free(struct wpa_scan_results *res) |
1839 | { | |
1840 | size_t i; | |
1841 | ||
1842 | if (res == NULL) | |
1843 | return; | |
1844 | ||
1845 | for (i = 0; i < res->num; i++) | |
1846 | os_free(res->res[i]); | |
1847 | os_free(res->res); | |
1848 | os_free(res); | |
1849 | } | |
1850 | ||
1851 | ||
7e5ba1b9 | 1852 | static struct wpa_scan_results * |
8856462d | 1853 | nl80211_get_scan_results(struct wpa_driver_nl80211_data *drv) |
3f5285e8 | 1854 | { |
b3db1e1c | 1855 | struct nl_msg *msg; |
3f5285e8 | 1856 | struct wpa_scan_results *res; |
b3db1e1c | 1857 | int ret; |
3812464c | 1858 | struct nl80211_bss_info_arg arg; |
3f5285e8 JM |
1859 | |
1860 | res = os_zalloc(sizeof(*res)); | |
b3db1e1c | 1861 | if (res == NULL) |
8e2c104f | 1862 | return NULL; |
b3db1e1c JM |
1863 | msg = nlmsg_alloc(); |
1864 | if (!msg) | |
1865 | goto nla_put_failure; | |
3f5285e8 | 1866 | |
b3db1e1c JM |
1867 | genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0, NLM_F_DUMP, |
1868 | NL80211_CMD_GET_SCAN, 0); | |
1869 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); | |
3f5285e8 | 1870 | |
3812464c JM |
1871 | arg.drv = drv; |
1872 | arg.res = res; | |
1873 | ret = send_and_recv_msgs(drv, msg, bss_info_handler, &arg); | |
b3db1e1c JM |
1874 | msg = NULL; |
1875 | if (ret == 0) { | |
1876 | wpa_printf(MSG_DEBUG, "Received scan results (%lu BSSes)", | |
1877 | (unsigned long) res->num); | |
1878 | return res; | |
3f5285e8 | 1879 | } |
b3db1e1c JM |
1880 | wpa_printf(MSG_DEBUG, "nl80211: Scan result fetch failed: ret=%d " |
1881 | "(%s)", ret, strerror(-ret)); | |
1882 | nla_put_failure: | |
1883 | nlmsg_free(msg); | |
1884 | wpa_scan_results_free(res); | |
1885 | return NULL; | |
3f5285e8 JM |
1886 | } |
1887 | ||
1888 | ||
8856462d JM |
1889 | /** |
1890 | * wpa_driver_nl80211_get_scan_results - Fetch the latest scan results | |
1891 | * @priv: Pointer to private wext data from wpa_driver_nl80211_init() | |
1892 | * Returns: Scan results on success, -1 on failure | |
1893 | */ | |
1894 | static struct wpa_scan_results * | |
1895 | wpa_driver_nl80211_get_scan_results(void *priv) | |
1896 | { | |
a2e40bb6 FF |
1897 | struct i802_bss *bss = priv; |
1898 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8856462d JM |
1899 | struct wpa_scan_results *res; |
1900 | ||
1901 | res = nl80211_get_scan_results(drv); | |
1902 | if (res) | |
1903 | wpa_driver_nl80211_check_bss_status(drv, res); | |
1904 | return res; | |
1905 | } | |
1906 | ||
1907 | ||
1908 | static void nl80211_dump_scan(struct wpa_driver_nl80211_data *drv) | |
1909 | { | |
1910 | struct wpa_scan_results *res; | |
1911 | size_t i; | |
1912 | ||
1913 | res = nl80211_get_scan_results(drv); | |
1914 | if (res == NULL) { | |
1915 | wpa_printf(MSG_DEBUG, "nl80211: Failed to get scan results"); | |
1916 | return; | |
1917 | } | |
1918 | ||
1919 | wpa_printf(MSG_DEBUG, "nl80211: Scan result dump"); | |
1920 | for (i = 0; i < res->num; i++) { | |
1921 | struct wpa_scan_res *r = res->res[i]; | |
1922 | wpa_printf(MSG_DEBUG, "nl80211: %d/%d " MACSTR "%s%s", | |
1923 | (int) i, (int) res->num, MAC2STR(r->bssid), | |
1924 | r->flags & WPA_SCAN_AUTHENTICATED ? " [auth]" : "", | |
1925 | r->flags & WPA_SCAN_ASSOCIATED ? " [assoc]" : ""); | |
1926 | } | |
1927 | ||
1928 | wpa_scan_results_free(res); | |
1929 | } | |
1930 | ||
1931 | ||
642187d6 | 1932 | static int wpa_driver_nl80211_set_key(const char *ifname, void *priv, |
71934751 JM |
1933 | enum wpa_alg alg, const u8 *addr, |
1934 | int key_idx, int set_tx, | |
642187d6 JM |
1935 | const u8 *seq, size_t seq_len, |
1936 | const u8 *key, size_t key_len) | |
3f5285e8 | 1937 | { |
a2e40bb6 FF |
1938 | struct i802_bss *bss = priv; |
1939 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
642187d6 | 1940 | int ifindex = if_nametoindex(ifname); |
3f5285e8 | 1941 | struct nl_msg *msg; |
1ad1cdc2 | 1942 | int ret; |
3f5285e8 | 1943 | |
1ad1cdc2 JM |
1944 | wpa_printf(MSG_DEBUG, "%s: ifindex=%d alg=%d addr=%p key_idx=%d " |
1945 | "set_tx=%d seq_len=%lu key_len=%lu", | |
1946 | __func__, ifindex, alg, addr, key_idx, set_tx, | |
3f5285e8 JM |
1947 | (unsigned long) seq_len, (unsigned long) key_len); |
1948 | ||
1949 | msg = nlmsg_alloc(); | |
1ad1cdc2 JM |
1950 | if (!msg) |
1951 | return -ENOMEM; | |
3f5285e8 JM |
1952 | |
1953 | if (alg == WPA_ALG_NONE) { | |
1ad1cdc2 JM |
1954 | genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0, |
1955 | 0, NL80211_CMD_DEL_KEY, 0); | |
3f5285e8 | 1956 | } else { |
1ad1cdc2 JM |
1957 | genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0, |
1958 | 0, NL80211_CMD_NEW_KEY, 0); | |
3f5285e8 | 1959 | NLA_PUT(msg, NL80211_ATTR_KEY_DATA, key_len, key); |
d723bab4 JM |
1960 | switch (alg) { |
1961 | case WPA_ALG_WEP: | |
1962 | if (key_len == 5) | |
1963 | NLA_PUT_U32(msg, NL80211_ATTR_KEY_CIPHER, | |
1964 | WLAN_CIPHER_SUITE_WEP40); | |
1965 | else | |
1966 | NLA_PUT_U32(msg, NL80211_ATTR_KEY_CIPHER, | |
1967 | WLAN_CIPHER_SUITE_WEP104); | |
1968 | break; | |
1969 | case WPA_ALG_TKIP: | |
1970 | NLA_PUT_U32(msg, NL80211_ATTR_KEY_CIPHER, | |
1971 | WLAN_CIPHER_SUITE_TKIP); | |
1972 | break; | |
1973 | case WPA_ALG_CCMP: | |
1974 | NLA_PUT_U32(msg, NL80211_ATTR_KEY_CIPHER, | |
1975 | WLAN_CIPHER_SUITE_CCMP); | |
1976 | break; | |
1977 | case WPA_ALG_IGTK: | |
1978 | NLA_PUT_U32(msg, NL80211_ATTR_KEY_CIPHER, | |
1979 | WLAN_CIPHER_SUITE_AES_CMAC); | |
1980 | break; | |
1981 | default: | |
1982 | wpa_printf(MSG_ERROR, "%s: Unsupported encryption " | |
1983 | "algorithm %d", __func__, alg); | |
3f5285e8 JM |
1984 | nlmsg_free(msg); |
1985 | return -1; | |
1986 | } | |
1987 | } | |
1988 | ||
849ef835 | 1989 | if (seq && seq_len) |
1ad1cdc2 JM |
1990 | NLA_PUT(msg, NL80211_ATTR_KEY_SEQ, seq_len, seq); |
1991 | ||
3f5285e8 JM |
1992 | if (addr && os_memcmp(addr, "\xff\xff\xff\xff\xff\xff", ETH_ALEN) != 0) |
1993 | { | |
1994 | wpa_printf(MSG_DEBUG, " addr=" MACSTR, MAC2STR(addr)); | |
1995 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); | |
1996 | } | |
1997 | NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_idx); | |
1ad1cdc2 | 1998 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, ifindex); |
3f5285e8 | 1999 | |
1ad1cdc2 JM |
2000 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
2001 | if (ret == -ENOENT && alg == WPA_ALG_NONE) | |
2002 | ret = 0; | |
2003 | if (ret) | |
2004 | wpa_printf(MSG_DEBUG, "nl80211: set_key failed; err=%d %s)", | |
2005 | ret, strerror(-ret)); | |
3f5285e8 | 2006 | |
1ad1cdc2 JM |
2007 | /* |
2008 | * If we failed or don't need to set the default TX key (below), | |
2009 | * we're done here. | |
2010 | */ | |
2011 | if (ret || !set_tx || alg == WPA_ALG_NONE) | |
2012 | return ret; | |
2013 | #ifdef HOSTAPD /* FIX: is this needed? */ | |
2014 | if (addr) | |
2015 | return ret; | |
2016 | #endif /* HOSTAPD */ | |
3f5285e8 | 2017 | |
1ad1cdc2 JM |
2018 | msg = nlmsg_alloc(); |
2019 | if (!msg) | |
2020 | return -ENOMEM; | |
3f5285e8 | 2021 | |
1ad1cdc2 JM |
2022 | genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0, |
2023 | 0, NL80211_CMD_SET_KEY, 0); | |
2024 | NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_idx); | |
2025 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, ifindex); | |
2026 | if (alg == WPA_ALG_IGTK) | |
2027 | NLA_PUT_FLAG(msg, NL80211_ATTR_KEY_DEFAULT_MGMT); | |
2028 | else | |
2029 | NLA_PUT_FLAG(msg, NL80211_ATTR_KEY_DEFAULT); | |
3f5285e8 | 2030 | |
1ad1cdc2 JM |
2031 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
2032 | if (ret == -ENOENT) | |
2033 | ret = 0; | |
2034 | if (ret) | |
2035 | wpa_printf(MSG_DEBUG, "nl80211: set_key default failed; " | |
2036 | "err=%d %s)", ret, strerror(-ret)); | |
2037 | return ret; | |
3f5285e8 JM |
2038 | |
2039 | nla_put_failure: | |
6241fcb1 | 2040 | return -ENOBUFS; |
3f5285e8 JM |
2041 | } |
2042 | ||
2043 | ||
71934751 | 2044 | static int nl_add_key(struct nl_msg *msg, enum wpa_alg alg, |
0194fedb JB |
2045 | int key_idx, int defkey, |
2046 | const u8 *seq, size_t seq_len, | |
2047 | const u8 *key, size_t key_len) | |
2048 | { | |
2049 | struct nlattr *key_attr = nla_nest_start(msg, NL80211_ATTR_KEY); | |
2050 | if (!key_attr) | |
2051 | return -1; | |
2052 | ||
2053 | if (defkey && alg == WPA_ALG_IGTK) | |
2054 | NLA_PUT_FLAG(msg, NL80211_KEY_DEFAULT_MGMT); | |
2055 | else if (defkey) | |
2056 | NLA_PUT_FLAG(msg, NL80211_KEY_DEFAULT); | |
2057 | ||
2058 | NLA_PUT_U8(msg, NL80211_KEY_IDX, key_idx); | |
2059 | ||
d723bab4 JM |
2060 | switch (alg) { |
2061 | case WPA_ALG_WEP: | |
2062 | if (key_len == 5) | |
2aa5f847 JM |
2063 | NLA_PUT_U32(msg, NL80211_KEY_CIPHER, |
2064 | WLAN_CIPHER_SUITE_WEP40); | |
d723bab4 | 2065 | else |
2aa5f847 JM |
2066 | NLA_PUT_U32(msg, NL80211_KEY_CIPHER, |
2067 | WLAN_CIPHER_SUITE_WEP104); | |
d723bab4 JM |
2068 | break; |
2069 | case WPA_ALG_TKIP: | |
2aa5f847 | 2070 | NLA_PUT_U32(msg, NL80211_KEY_CIPHER, WLAN_CIPHER_SUITE_TKIP); |
d723bab4 JM |
2071 | break; |
2072 | case WPA_ALG_CCMP: | |
2aa5f847 | 2073 | NLA_PUT_U32(msg, NL80211_KEY_CIPHER, WLAN_CIPHER_SUITE_CCMP); |
d723bab4 JM |
2074 | break; |
2075 | case WPA_ALG_IGTK: | |
2aa5f847 JM |
2076 | NLA_PUT_U32(msg, NL80211_KEY_CIPHER, |
2077 | WLAN_CIPHER_SUITE_AES_CMAC); | |
d723bab4 JM |
2078 | break; |
2079 | default: | |
2080 | wpa_printf(MSG_ERROR, "%s: Unsupported encryption " | |
2081 | "algorithm %d", __func__, alg); | |
0194fedb | 2082 | return -1; |
d723bab4 | 2083 | } |
0194fedb JB |
2084 | |
2085 | if (seq && seq_len) | |
2086 | NLA_PUT(msg, NL80211_KEY_SEQ, seq_len, seq); | |
2087 | ||
2088 | NLA_PUT(msg, NL80211_KEY_DATA, key_len, key); | |
2089 | ||
2090 | nla_nest_end(msg, key_attr); | |
2091 | ||
2092 | return 0; | |
2093 | nla_put_failure: | |
2094 | return -1; | |
2095 | } | |
2096 | ||
c811d5bc | 2097 | |
cfaab580 ZY |
2098 | static int nl80211_set_conn_keys(struct wpa_driver_associate_params *params, |
2099 | struct nl_msg *msg) | |
2100 | { | |
2101 | int i, privacy = 0; | |
2102 | struct nlattr *nl_keys, *nl_key; | |
2103 | ||
2104 | for (i = 0; i < 4; i++) { | |
2105 | if (!params->wep_key[i]) | |
2106 | continue; | |
2107 | privacy = 1; | |
2108 | break; | |
2109 | } | |
2110 | if (!privacy) | |
2111 | return 0; | |
2112 | ||
2113 | NLA_PUT_FLAG(msg, NL80211_ATTR_PRIVACY); | |
2114 | ||
2115 | nl_keys = nla_nest_start(msg, NL80211_ATTR_KEYS); | |
2116 | if (!nl_keys) | |
2117 | goto nla_put_failure; | |
2118 | ||
2119 | for (i = 0; i < 4; i++) { | |
2120 | if (!params->wep_key[i]) | |
2121 | continue; | |
2122 | ||
2123 | nl_key = nla_nest_start(msg, i); | |
2124 | if (!nl_key) | |
2125 | goto nla_put_failure; | |
2126 | ||
2127 | NLA_PUT(msg, NL80211_KEY_DATA, params->wep_key_len[i], | |
2128 | params->wep_key[i]); | |
2129 | if (params->wep_key_len[i] == 5) | |
2130 | NLA_PUT_U32(msg, NL80211_KEY_CIPHER, | |
2131 | WLAN_CIPHER_SUITE_WEP40); | |
2132 | else | |
2133 | NLA_PUT_U32(msg, NL80211_KEY_CIPHER, | |
2134 | WLAN_CIPHER_SUITE_WEP104); | |
2135 | ||
2136 | NLA_PUT_U8(msg, NL80211_KEY_IDX, i); | |
2137 | ||
2138 | if (i == params->wep_tx_keyidx) | |
2139 | NLA_PUT_FLAG(msg, NL80211_KEY_DEFAULT); | |
2140 | ||
2141 | nla_nest_end(msg, nl_key); | |
2142 | } | |
2143 | nla_nest_end(msg, nl_keys); | |
2144 | ||
2145 | return 0; | |
2146 | ||
2147 | nla_put_failure: | |
2148 | return -ENOBUFS; | |
2149 | } | |
2150 | ||
2151 | ||
c2a04078 JM |
2152 | static int wpa_driver_nl80211_mlme(struct wpa_driver_nl80211_data *drv, |
2153 | const u8 *addr, int cmd, u16 reason_code) | |
2154 | { | |
2155 | int ret = -1; | |
2156 | struct nl_msg *msg; | |
2157 | ||
2158 | msg = nlmsg_alloc(); | |
2159 | if (!msg) | |
2160 | return -1; | |
2161 | ||
2162 | genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0, 0, cmd, 0); | |
2163 | ||
2164 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); | |
2165 | NLA_PUT_U16(msg, NL80211_ATTR_REASON_CODE, reason_code); | |
2166 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); | |
2167 | ||
2168 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
2169 | msg = NULL; | |
2170 | if (ret) { | |
2171 | wpa_printf(MSG_DEBUG, "nl80211: MLME command failed: ret=%d " | |
2172 | "(%s)", ret, strerror(-ret)); | |
2173 | goto nla_put_failure; | |
2174 | } | |
2175 | ret = 0; | |
2176 | ||
2177 | nla_put_failure: | |
2178 | nlmsg_free(msg); | |
2179 | return ret; | |
2180 | } | |
3f5285e8 JM |
2181 | |
2182 | ||
cfaab580 ZY |
2183 | static int wpa_driver_nl80211_disconnect(struct wpa_driver_nl80211_data *drv, |
2184 | const u8 *addr, int reason_code) | |
2185 | { | |
2186 | wpa_printf(MSG_DEBUG, "%s", __func__); | |
2187 | drv->associated = 0; | |
2188 | return wpa_driver_nl80211_mlme(drv, addr, NL80211_CMD_DISCONNECT, | |
2189 | reason_code); | |
2190 | } | |
2191 | ||
2192 | ||
3f5285e8 | 2193 | static int wpa_driver_nl80211_deauthenticate(void *priv, const u8 *addr, |
c2a04078 | 2194 | int reason_code) |
3f5285e8 | 2195 | { |
a2e40bb6 FF |
2196 | struct i802_bss *bss = priv; |
2197 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
cfaab580 ZY |
2198 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) |
2199 | return wpa_driver_nl80211_disconnect(drv, addr, reason_code); | |
c2a04078 | 2200 | wpa_printf(MSG_DEBUG, "%s", __func__); |
13405f35 | 2201 | drv->associated = 0; |
c2a04078 JM |
2202 | return wpa_driver_nl80211_mlme(drv, addr, NL80211_CMD_DEAUTHENTICATE, |
2203 | reason_code); | |
3f5285e8 JM |
2204 | } |
2205 | ||
2206 | ||
2207 | static int wpa_driver_nl80211_disassociate(void *priv, const u8 *addr, | |
c2a04078 | 2208 | int reason_code) |
3f5285e8 | 2209 | { |
a2e40bb6 FF |
2210 | struct i802_bss *bss = priv; |
2211 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
cfaab580 ZY |
2212 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) |
2213 | return wpa_driver_nl80211_disconnect(drv, addr, reason_code); | |
c2a04078 | 2214 | wpa_printf(MSG_DEBUG, "%s", __func__); |
13405f35 | 2215 | drv->associated = 0; |
c2a04078 JM |
2216 | return wpa_driver_nl80211_mlme(drv, addr, NL80211_CMD_DISASSOCIATE, |
2217 | reason_code); | |
3f5285e8 JM |
2218 | } |
2219 | ||
2220 | ||
c2a04078 JM |
2221 | static int wpa_driver_nl80211_authenticate( |
2222 | void *priv, struct wpa_driver_auth_params *params) | |
2223 | { | |
a2e40bb6 FF |
2224 | struct i802_bss *bss = priv; |
2225 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
a0b2f99b | 2226 | int ret = -1, i; |
c2a04078 JM |
2227 | struct nl_msg *msg; |
2228 | enum nl80211_auth_type type; | |
6d6f4bb8 | 2229 | int count = 0; |
c2a04078 JM |
2230 | |
2231 | drv->associated = 0; | |
e6b8efeb | 2232 | os_memset(drv->auth_bssid, 0, ETH_ALEN); |
af473088 JM |
2233 | /* FIX: IBSS mode */ |
2234 | if (drv->nlmode != NL80211_IFTYPE_STATION) | |
2235 | wpa_driver_nl80211_set_mode(priv, IEEE80211_MODE_INFRA); | |
c2a04078 | 2236 | |
a2e40bb6 | 2237 | if (wpa_driver_nl80211_set_mode(priv, IEEE80211_MODE_INFRA) < 0) |
4a867032 JM |
2238 | return -1; |
2239 | ||
6d6f4bb8 | 2240 | retry: |
c2a04078 JM |
2241 | msg = nlmsg_alloc(); |
2242 | if (!msg) | |
2243 | return -1; | |
2244 | ||
2245 | wpa_printf(MSG_DEBUG, "nl80211: Authenticate (ifindex=%d)", | |
2246 | drv->ifindex); | |
a0b2f99b | 2247 | |
0194fedb JB |
2248 | genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0, 0, |
2249 | NL80211_CMD_AUTHENTICATE, 0); | |
2250 | ||
a0b2f99b JM |
2251 | for (i = 0; i < 4; i++) { |
2252 | if (!params->wep_key[i]) | |
2253 | continue; | |
a2e40bb6 | 2254 | wpa_driver_nl80211_set_key(bss->ifname, drv, WPA_ALG_WEP, NULL, |
642187d6 | 2255 | i, |
a0b2f99b JM |
2256 | i == params->wep_tx_keyidx, NULL, 0, |
2257 | params->wep_key[i], | |
2258 | params->wep_key_len[i]); | |
0194fedb JB |
2259 | if (params->wep_tx_keyidx != i) |
2260 | continue; | |
2261 | if (nl_add_key(msg, WPA_ALG_WEP, i, 1, NULL, 0, | |
2262 | params->wep_key[i], params->wep_key_len[i])) { | |
2263 | nlmsg_free(msg); | |
2264 | return -1; | |
2265 | } | |
a0b2f99b JM |
2266 | } |
2267 | ||
c2a04078 JM |
2268 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); |
2269 | if (params->bssid) { | |
2270 | wpa_printf(MSG_DEBUG, " * bssid=" MACSTR, | |
2271 | MAC2STR(params->bssid)); | |
2272 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid); | |
2273 | } | |
2274 | if (params->freq) { | |
2275 | wpa_printf(MSG_DEBUG, " * freq=%d", params->freq); | |
2276 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, params->freq); | |
2277 | } | |
2278 | if (params->ssid) { | |
2279 | wpa_hexdump_ascii(MSG_DEBUG, " * SSID", | |
2280 | params->ssid, params->ssid_len); | |
2281 | NLA_PUT(msg, NL80211_ATTR_SSID, params->ssid_len, | |
2282 | params->ssid); | |
2283 | } | |
2284 | wpa_hexdump(MSG_DEBUG, " * IEs", params->ie, params->ie_len); | |
2285 | if (params->ie) | |
2286 | NLA_PUT(msg, NL80211_ATTR_IE, params->ie_len, params->ie); | |
2287 | /* | |
2288 | * TODO: if multiple auth_alg options enabled, try them one by one if | |
2289 | * the AP rejects authentication due to unknown auth alg | |
2290 | */ | |
abd9fafa | 2291 | if (params->auth_alg & WPA_AUTH_ALG_OPEN) |
c2a04078 | 2292 | type = NL80211_AUTHTYPE_OPEN_SYSTEM; |
abd9fafa | 2293 | else if (params->auth_alg & WPA_AUTH_ALG_SHARED) |
c2a04078 | 2294 | type = NL80211_AUTHTYPE_SHARED_KEY; |
abd9fafa | 2295 | else if (params->auth_alg & WPA_AUTH_ALG_LEAP) |
c2a04078 | 2296 | type = NL80211_AUTHTYPE_NETWORK_EAP; |
abd9fafa | 2297 | else if (params->auth_alg & WPA_AUTH_ALG_FT) |
c2a04078 JM |
2298 | type = NL80211_AUTHTYPE_FT; |
2299 | else | |
2300 | goto nla_put_failure; | |
2301 | wpa_printf(MSG_DEBUG, " * Auth Type %d", type); | |
2302 | NLA_PUT_U32(msg, NL80211_ATTR_AUTH_TYPE, type); | |
2303 | ||
2304 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
2305 | msg = NULL; | |
2306 | if (ret) { | |
2307 | wpa_printf(MSG_DEBUG, "nl80211: MLME command failed: ret=%d " | |
2308 | "(%s)", ret, strerror(-ret)); | |
6d6f4bb8 JM |
2309 | count++; |
2310 | if (ret == -EALREADY && count == 1 && params->bssid) { | |
2311 | /* | |
2312 | * mac80211 does not currently accept new | |
2313 | * authentication if we are already authenticated. As a | |
2314 | * workaround, force deauthentication and try again. | |
2315 | */ | |
2316 | wpa_printf(MSG_DEBUG, "nl80211: Retry authentication " | |
2317 | "after forced deauthentication"); | |
2318 | wpa_driver_nl80211_deauthenticate( | |
2319 | drv, params->bssid, | |
2320 | WLAN_REASON_PREV_AUTH_NOT_VALID); | |
2321 | nlmsg_free(msg); | |
2322 | goto retry; | |
2323 | } | |
c2a04078 JM |
2324 | goto nla_put_failure; |
2325 | } | |
2326 | ret = 0; | |
2327 | wpa_printf(MSG_DEBUG, "nl80211: Authentication request send " | |
2328 | "successfully"); | |
2329 | ||
2330 | nla_put_failure: | |
2331 | nlmsg_free(msg); | |
2332 | return ret; | |
2333 | } | |
2334 | ||
2335 | ||
282d5590 JM |
2336 | struct phy_info_arg { |
2337 | u16 *num_modes; | |
2338 | struct hostapd_hw_modes *modes; | |
2339 | }; | |
2340 | ||
2341 | static int phy_info_handler(struct nl_msg *msg, void *arg) | |
2342 | { | |
2343 | struct nlattr *tb_msg[NL80211_ATTR_MAX + 1]; | |
2344 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
2345 | struct phy_info_arg *phy_info = arg; | |
2346 | ||
2347 | struct nlattr *tb_band[NL80211_BAND_ATTR_MAX + 1]; | |
2348 | ||
2349 | struct nlattr *tb_freq[NL80211_FREQUENCY_ATTR_MAX + 1]; | |
2350 | static struct nla_policy freq_policy[NL80211_FREQUENCY_ATTR_MAX + 1] = { | |
2351 | [NL80211_FREQUENCY_ATTR_FREQ] = { .type = NLA_U32 }, | |
2352 | [NL80211_FREQUENCY_ATTR_DISABLED] = { .type = NLA_FLAG }, | |
2353 | [NL80211_FREQUENCY_ATTR_PASSIVE_SCAN] = { .type = NLA_FLAG }, | |
2354 | [NL80211_FREQUENCY_ATTR_NO_IBSS] = { .type = NLA_FLAG }, | |
2355 | [NL80211_FREQUENCY_ATTR_RADAR] = { .type = NLA_FLAG }, | |
2356 | [NL80211_FREQUENCY_ATTR_MAX_TX_POWER] = { .type = NLA_U32 }, | |
2357 | }; | |
2358 | ||
2359 | struct nlattr *tb_rate[NL80211_BITRATE_ATTR_MAX + 1]; | |
2360 | static struct nla_policy rate_policy[NL80211_BITRATE_ATTR_MAX + 1] = { | |
2361 | [NL80211_BITRATE_ATTR_RATE] = { .type = NLA_U32 }, | |
2362 | [NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE] = { .type = NLA_FLAG }, | |
2363 | }; | |
2364 | ||
2365 | struct nlattr *nl_band; | |
2366 | struct nlattr *nl_freq; | |
2367 | struct nlattr *nl_rate; | |
2368 | int rem_band, rem_freq, rem_rate; | |
2369 | struct hostapd_hw_modes *mode; | |
2370 | int idx, mode_is_set; | |
2371 | ||
2372 | nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
2373 | genlmsg_attrlen(gnlh, 0), NULL); | |
2374 | ||
2375 | if (!tb_msg[NL80211_ATTR_WIPHY_BANDS]) | |
2376 | return NL_SKIP; | |
2377 | ||
2378 | nla_for_each_nested(nl_band, tb_msg[NL80211_ATTR_WIPHY_BANDS], rem_band) { | |
e62fb0a0 | 2379 | mode = os_realloc(phy_info->modes, (*phy_info->num_modes + 1) * sizeof(*mode)); |
282d5590 JM |
2380 | if (!mode) |
2381 | return NL_SKIP; | |
2382 | phy_info->modes = mode; | |
2383 | ||
2384 | mode_is_set = 0; | |
2385 | ||
2386 | mode = &phy_info->modes[*(phy_info->num_modes)]; | |
2387 | memset(mode, 0, sizeof(*mode)); | |
2388 | *(phy_info->num_modes) += 1; | |
2389 | ||
2390 | nla_parse(tb_band, NL80211_BAND_ATTR_MAX, nla_data(nl_band), | |
2391 | nla_len(nl_band), NULL); | |
2392 | ||
2393 | if (tb_band[NL80211_BAND_ATTR_HT_CAPA]) { | |
2394 | mode->ht_capab = nla_get_u16( | |
2395 | tb_band[NL80211_BAND_ATTR_HT_CAPA]); | |
2396 | } | |
2397 | ||
be8eb8ab JM |
2398 | if (tb_band[NL80211_BAND_ATTR_HT_AMPDU_FACTOR]) { |
2399 | mode->a_mpdu_params |= nla_get_u8( | |
2400 | tb_band[NL80211_BAND_ATTR_HT_AMPDU_FACTOR]) & | |
2401 | 0x03; | |
2402 | } | |
2403 | ||
2404 | if (tb_band[NL80211_BAND_ATTR_HT_AMPDU_DENSITY]) { | |
2405 | mode->a_mpdu_params |= nla_get_u8( | |
2406 | tb_band[NL80211_BAND_ATTR_HT_AMPDU_DENSITY]) << | |
2407 | 2; | |
2408 | } | |
2409 | ||
08eb154d JM |
2410 | if (tb_band[NL80211_BAND_ATTR_HT_MCS_SET] && |
2411 | nla_len(tb_band[NL80211_BAND_ATTR_HT_MCS_SET])) { | |
2412 | u8 *mcs; | |
2413 | mcs = nla_data(tb_band[NL80211_BAND_ATTR_HT_MCS_SET]); | |
2414 | os_memcpy(mode->mcs_set, mcs, 16); | |
2415 | } | |
2416 | ||
282d5590 JM |
2417 | nla_for_each_nested(nl_freq, tb_band[NL80211_BAND_ATTR_FREQS], rem_freq) { |
2418 | nla_parse(tb_freq, NL80211_FREQUENCY_ATTR_MAX, nla_data(nl_freq), | |
2419 | nla_len(nl_freq), freq_policy); | |
2420 | if (!tb_freq[NL80211_FREQUENCY_ATTR_FREQ]) | |
2421 | continue; | |
2422 | mode->num_channels++; | |
2423 | } | |
2424 | ||
e62fb0a0 | 2425 | mode->channels = os_zalloc(mode->num_channels * sizeof(struct hostapd_channel_data)); |
282d5590 JM |
2426 | if (!mode->channels) |
2427 | return NL_SKIP; | |
2428 | ||
2429 | idx = 0; | |
2430 | ||
2431 | nla_for_each_nested(nl_freq, tb_band[NL80211_BAND_ATTR_FREQS], rem_freq) { | |
2432 | nla_parse(tb_freq, NL80211_FREQUENCY_ATTR_MAX, nla_data(nl_freq), | |
2433 | nla_len(nl_freq), freq_policy); | |
2434 | if (!tb_freq[NL80211_FREQUENCY_ATTR_FREQ]) | |
2435 | continue; | |
2436 | ||
2437 | mode->channels[idx].freq = nla_get_u32(tb_freq[NL80211_FREQUENCY_ATTR_FREQ]); | |
2438 | mode->channels[idx].flag = 0; | |
2439 | ||
2440 | if (!mode_is_set) { | |
2441 | /* crude heuristic */ | |
2442 | if (mode->channels[idx].freq < 4000) | |
2443 | mode->mode = HOSTAPD_MODE_IEEE80211B; | |
2444 | else | |
2445 | mode->mode = HOSTAPD_MODE_IEEE80211A; | |
2446 | mode_is_set = 1; | |
2447 | } | |
2448 | ||
2449 | /* crude heuristic */ | |
2450 | if (mode->channels[idx].freq < 4000) | |
5a0ffb5f | 2451 | if (mode->channels[idx].freq == 2484) |
282d5590 JM |
2452 | mode->channels[idx].chan = 14; |
2453 | else | |
2454 | mode->channels[idx].chan = (mode->channels[idx].freq - 2407) / 5; | |
2455 | else | |
2456 | mode->channels[idx].chan = mode->channels[idx].freq/5 - 1000; | |
2457 | ||
2458 | if (tb_freq[NL80211_FREQUENCY_ATTR_DISABLED]) | |
2459 | mode->channels[idx].flag |= | |
2460 | HOSTAPD_CHAN_DISABLED; | |
2461 | if (tb_freq[NL80211_FREQUENCY_ATTR_PASSIVE_SCAN]) | |
2462 | mode->channels[idx].flag |= | |
2463 | HOSTAPD_CHAN_PASSIVE_SCAN; | |
2464 | if (tb_freq[NL80211_FREQUENCY_ATTR_NO_IBSS]) | |
2465 | mode->channels[idx].flag |= | |
2466 | HOSTAPD_CHAN_NO_IBSS; | |
2467 | if (tb_freq[NL80211_FREQUENCY_ATTR_RADAR]) | |
2468 | mode->channels[idx].flag |= | |
2469 | HOSTAPD_CHAN_RADAR; | |
2470 | ||
2471 | if (tb_freq[NL80211_FREQUENCY_ATTR_MAX_TX_POWER] && | |
2472 | !tb_freq[NL80211_FREQUENCY_ATTR_DISABLED]) | |
2473 | mode->channels[idx].max_tx_power = | |
2474 | nla_get_u32(tb_freq[NL80211_FREQUENCY_ATTR_MAX_TX_POWER]) / 100; | |
2475 | ||
2476 | idx++; | |
2477 | } | |
2478 | ||
2479 | nla_for_each_nested(nl_rate, tb_band[NL80211_BAND_ATTR_RATES], rem_rate) { | |
2480 | nla_parse(tb_rate, NL80211_BITRATE_ATTR_MAX, nla_data(nl_rate), | |
2481 | nla_len(nl_rate), rate_policy); | |
2482 | if (!tb_rate[NL80211_BITRATE_ATTR_RATE]) | |
2483 | continue; | |
2484 | mode->num_rates++; | |
2485 | } | |
2486 | ||
e62fb0a0 | 2487 | mode->rates = os_zalloc(mode->num_rates * sizeof(int)); |
282d5590 JM |
2488 | if (!mode->rates) |
2489 | return NL_SKIP; | |
2490 | ||
2491 | idx = 0; | |
2492 | ||
2493 | nla_for_each_nested(nl_rate, tb_band[NL80211_BAND_ATTR_RATES], rem_rate) { | |
2494 | nla_parse(tb_rate, NL80211_BITRATE_ATTR_MAX, nla_data(nl_rate), | |
2495 | nla_len(nl_rate), rate_policy); | |
2496 | if (!tb_rate[NL80211_BITRATE_ATTR_RATE]) | |
2497 | continue; | |
fb7842aa | 2498 | mode->rates[idx] = nla_get_u32(tb_rate[NL80211_BITRATE_ATTR_RATE]); |
282d5590 JM |
2499 | |
2500 | /* crude heuristic */ | |
2501 | if (mode->mode == HOSTAPD_MODE_IEEE80211B && | |
fb7842aa | 2502 | mode->rates[idx] > 200) |
282d5590 JM |
2503 | mode->mode = HOSTAPD_MODE_IEEE80211G; |
2504 | ||
282d5590 JM |
2505 | idx++; |
2506 | } | |
2507 | } | |
2508 | ||
2509 | return NL_SKIP; | |
2510 | } | |
2511 | ||
2512 | static struct hostapd_hw_modes * | |
2513 | wpa_driver_nl80211_add_11b(struct hostapd_hw_modes *modes, u16 *num_modes) | |
2514 | { | |
2515 | u16 m; | |
2516 | struct hostapd_hw_modes *mode11g = NULL, *nmodes, *mode; | |
2517 | int i, mode11g_idx = -1; | |
2518 | ||
2519 | /* If only 802.11g mode is included, use it to construct matching | |
2520 | * 802.11b mode data. */ | |
2521 | ||
2522 | for (m = 0; m < *num_modes; m++) { | |
2523 | if (modes[m].mode == HOSTAPD_MODE_IEEE80211B) | |
2524 | return modes; /* 802.11b already included */ | |
2525 | if (modes[m].mode == HOSTAPD_MODE_IEEE80211G) | |
2526 | mode11g_idx = m; | |
2527 | } | |
2528 | ||
2529 | if (mode11g_idx < 0) | |
2530 | return modes; /* 2.4 GHz band not supported at all */ | |
2531 | ||
2532 | nmodes = os_realloc(modes, (*num_modes + 1) * sizeof(*nmodes)); | |
2533 | if (nmodes == NULL) | |
2534 | return modes; /* Could not add 802.11b mode */ | |
2535 | ||
2536 | mode = &nmodes[*num_modes]; | |
2537 | os_memset(mode, 0, sizeof(*mode)); | |
2538 | (*num_modes)++; | |
2539 | modes = nmodes; | |
2540 | ||
2541 | mode->mode = HOSTAPD_MODE_IEEE80211B; | |
2542 | ||
2543 | mode11g = &modes[mode11g_idx]; | |
2544 | mode->num_channels = mode11g->num_channels; | |
2545 | mode->channels = os_malloc(mode11g->num_channels * | |
2546 | sizeof(struct hostapd_channel_data)); | |
2547 | if (mode->channels == NULL) { | |
2548 | (*num_modes)--; | |
2549 | return modes; /* Could not add 802.11b mode */ | |
2550 | } | |
2551 | os_memcpy(mode->channels, mode11g->channels, | |
2552 | mode11g->num_channels * sizeof(struct hostapd_channel_data)); | |
2553 | ||
2554 | mode->num_rates = 0; | |
fb7842aa | 2555 | mode->rates = os_malloc(4 * sizeof(int)); |
282d5590 JM |
2556 | if (mode->rates == NULL) { |
2557 | os_free(mode->channels); | |
2558 | (*num_modes)--; | |
2559 | return modes; /* Could not add 802.11b mode */ | |
2560 | } | |
2561 | ||
2562 | for (i = 0; i < mode11g->num_rates; i++) { | |
fb7842aa JM |
2563 | if (mode11g->rates[i] != 10 && mode11g->rates[i] != 20 && |
2564 | mode11g->rates[i] != 55 && mode11g->rates[i] != 110) | |
282d5590 JM |
2565 | continue; |
2566 | mode->rates[mode->num_rates] = mode11g->rates[i]; | |
2567 | mode->num_rates++; | |
2568 | if (mode->num_rates == 4) | |
2569 | break; | |
2570 | } | |
2571 | ||
2572 | if (mode->num_rates == 0) { | |
2573 | os_free(mode->channels); | |
2574 | os_free(mode->rates); | |
2575 | (*num_modes)--; | |
2576 | return modes; /* No 802.11b rates */ | |
2577 | } | |
2578 | ||
2579 | wpa_printf(MSG_DEBUG, "nl80211: Added 802.11b mode based on 802.11g " | |
2580 | "information"); | |
2581 | ||
2582 | return modes; | |
2583 | } | |
2584 | ||
2585 | ||
2586 | static struct hostapd_hw_modes * | |
2587 | wpa_driver_nl80211_get_hw_feature_data(void *priv, u16 *num_modes, u16 *flags) | |
2588 | { | |
a2e40bb6 FF |
2589 | struct i802_bss *bss = priv; |
2590 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
282d5590 JM |
2591 | struct nl_msg *msg; |
2592 | struct phy_info_arg result = { | |
2593 | .num_modes = num_modes, | |
2594 | .modes = NULL, | |
2595 | }; | |
2596 | ||
2597 | *num_modes = 0; | |
2598 | *flags = 0; | |
2599 | ||
2600 | msg = nlmsg_alloc(); | |
2601 | if (!msg) | |
2602 | return NULL; | |
2603 | ||
2604 | genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0, | |
2605 | 0, NL80211_CMD_GET_WIPHY, 0); | |
2606 | ||
2607 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); | |
2608 | ||
2609 | if (send_and_recv_msgs(drv, msg, phy_info_handler, &result) == 0) | |
2610 | return wpa_driver_nl80211_add_11b(result.modes, num_modes); | |
2611 | nla_put_failure: | |
2612 | return NULL; | |
2613 | } | |
2614 | ||
2615 | ||
2c2010ac JM |
2616 | static int wpa_driver_nl80211_send_frame(struct wpa_driver_nl80211_data *drv, |
2617 | const void *data, size_t len, | |
2618 | int encrypt) | |
2619 | { | |
2620 | __u8 rtap_hdr[] = { | |
2621 | 0x00, 0x00, /* radiotap version */ | |
2622 | 0x0e, 0x00, /* radiotap length */ | |
2623 | 0x02, 0xc0, 0x00, 0x00, /* bmap: flags, tx and rx flags */ | |
2624 | IEEE80211_RADIOTAP_F_FRAG, /* F_FRAG (fragment if required) */ | |
2625 | 0x00, /* padding */ | |
2626 | 0x00, 0x00, /* RX and TX flags to indicate that */ | |
2627 | 0x00, 0x00, /* this is the injected frame directly */ | |
2628 | }; | |
2629 | struct iovec iov[2] = { | |
2630 | { | |
2631 | .iov_base = &rtap_hdr, | |
2632 | .iov_len = sizeof(rtap_hdr), | |
2633 | }, | |
2634 | { | |
2635 | .iov_base = (void *) data, | |
2636 | .iov_len = len, | |
2637 | } | |
2638 | }; | |
2639 | struct msghdr msg = { | |
2640 | .msg_name = NULL, | |
2641 | .msg_namelen = 0, | |
2642 | .msg_iov = iov, | |
2643 | .msg_iovlen = 2, | |
2644 | .msg_control = NULL, | |
2645 | .msg_controllen = 0, | |
2646 | .msg_flags = 0, | |
2647 | }; | |
2648 | ||
2649 | if (encrypt) | |
2650 | rtap_hdr[8] |= IEEE80211_RADIOTAP_F_WEP; | |
2651 | ||
2652 | return sendmsg(drv->monitor_sock, &msg, 0); | |
2653 | } | |
2654 | ||
2655 | ||
2656 | static int wpa_driver_nl80211_send_mlme(void *priv, const u8 *data, | |
2657 | size_t data_len) | |
2658 | { | |
a2e40bb6 FF |
2659 | struct i802_bss *bss = priv; |
2660 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
2c2010ac | 2661 | struct ieee80211_mgmt *mgmt; |
7a47d567 | 2662 | int encrypt = 1; |
2c2010ac JM |
2663 | u16 fc; |
2664 | ||
2665 | mgmt = (struct ieee80211_mgmt *) data; | |
2666 | fc = le_to_host16(mgmt->frame_control); | |
2667 | ||
2668 | if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && | |
2669 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_AUTH) { | |
2670 | /* | |
2671 | * Only one of the authentication frame types is encrypted. | |
2672 | * In order for static WEP encryption to work properly (i.e., | |
2673 | * to not encrypt the frame), we need to tell mac80211 about | |
2674 | * the frames that must not be encrypted. | |
2675 | */ | |
2676 | u16 auth_alg = le_to_host16(mgmt->u.auth.auth_alg); | |
2677 | u16 auth_trans = le_to_host16(mgmt->u.auth.auth_transaction); | |
7a47d567 JB |
2678 | if (auth_alg != WLAN_AUTH_SHARED_KEY || auth_trans != 3) |
2679 | encrypt = 0; | |
2c2010ac JM |
2680 | } |
2681 | ||
7a47d567 | 2682 | return wpa_driver_nl80211_send_frame(drv, data, data_len, encrypt); |
2c2010ac JM |
2683 | } |
2684 | ||
2685 | ||
8b897f5a | 2686 | static int wpa_driver_nl80211_set_beacon(void *priv, |
5d674872 JM |
2687 | const u8 *head, size_t head_len, |
2688 | const u8 *tail, size_t tail_len, | |
2689 | int dtim_period, int beacon_int) | |
d2440ba0 | 2690 | { |
a2e40bb6 FF |
2691 | struct i802_bss *bss = priv; |
2692 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
d2440ba0 JM |
2693 | struct nl_msg *msg; |
2694 | u8 cmd = NL80211_CMD_NEW_BEACON; | |
2695 | int ret; | |
b4fd6fab | 2696 | int beacon_set; |
8b897f5a | 2697 | int ifindex = if_nametoindex(bss->ifname); |
b4fd6fab | 2698 | |
b4fd6fab | 2699 | beacon_set = bss->beacon_set; |
d2440ba0 JM |
2700 | |
2701 | msg = nlmsg_alloc(); | |
2702 | if (!msg) | |
2703 | return -ENOMEM; | |
2704 | ||
2705 | wpa_printf(MSG_DEBUG, "nl80211: Set beacon (beacon_set=%d)", | |
b4fd6fab JM |
2706 | beacon_set); |
2707 | if (beacon_set) | |
d2440ba0 JM |
2708 | cmd = NL80211_CMD_SET_BEACON; |
2709 | ||
2710 | genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0, | |
2711 | 0, cmd, 0); | |
2712 | NLA_PUT(msg, NL80211_ATTR_BEACON_HEAD, head_len, head); | |
2713 | NLA_PUT(msg, NL80211_ATTR_BEACON_TAIL, tail_len, tail); | |
b4fd6fab | 2714 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, ifindex); |
5d674872 | 2715 | NLA_PUT_U32(msg, NL80211_ATTR_BEACON_INTERVAL, beacon_int); |
d2440ba0 JM |
2716 | NLA_PUT_U32(msg, NL80211_ATTR_DTIM_PERIOD, dtim_period); |
2717 | ||
2718 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
2719 | if (ret) { | |
2720 | wpa_printf(MSG_DEBUG, "nl80211: Beacon set failed: %d (%s)", | |
2721 | ret, strerror(-ret)); | |
b4fd6fab | 2722 | } else { |
b4fd6fab | 2723 | bss->beacon_set = 1; |
b4fd6fab | 2724 | } |
d2440ba0 JM |
2725 | return ret; |
2726 | nla_put_failure: | |
2727 | return -ENOBUFS; | |
2728 | } | |
2729 | ||
2730 | ||
f019981a JM |
2731 | static int wpa_driver_nl80211_set_freq(struct wpa_driver_nl80211_data *drv, |
2732 | int freq, int ht_enabled, | |
2733 | int sec_channel_offset) | |
1581b38b JM |
2734 | { |
2735 | struct nl_msg *msg; | |
d2440ba0 | 2736 | int ret; |
1581b38b JM |
2737 | |
2738 | msg = nlmsg_alloc(); | |
2739 | if (!msg) | |
2740 | return -1; | |
2741 | ||
2742 | genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0, 0, | |
2743 | NL80211_CMD_SET_WIPHY, 0); | |
2744 | ||
2745 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); | |
f019981a JM |
2746 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, freq); |
2747 | if (ht_enabled) { | |
2748 | switch (sec_channel_offset) { | |
2749 | case -1: | |
2750 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, | |
2751 | NL80211_CHAN_HT40MINUS); | |
2752 | break; | |
2753 | case 1: | |
2754 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, | |
2755 | NL80211_CHAN_HT40PLUS); | |
2756 | break; | |
2757 | default: | |
2758 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, | |
2759 | NL80211_CHAN_HT20); | |
2760 | break; | |
2761 | } | |
2762 | } | |
1581b38b | 2763 | |
d2440ba0 JM |
2764 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
2765 | if (ret == 0) | |
1581b38b | 2766 | return 0; |
f019981a JM |
2767 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set channel (freq=%d): " |
2768 | "%d (%s)", freq, ret, strerror(-ret)); | |
1581b38b JM |
2769 | nla_put_failure: |
2770 | return -1; | |
2771 | } | |
2772 | ||
0f4e8b4f | 2773 | |
62847751 | 2774 | static int wpa_driver_nl80211_sta_add(void *priv, |
0f4e8b4f JM |
2775 | struct hostapd_sta_add_params *params) |
2776 | { | |
a2e40bb6 FF |
2777 | struct i802_bss *bss = priv; |
2778 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
0f4e8b4f JM |
2779 | struct nl_msg *msg; |
2780 | int ret = -ENOBUFS; | |
2781 | ||
2782 | msg = nlmsg_alloc(); | |
2783 | if (!msg) | |
2784 | return -ENOMEM; | |
2785 | ||
2786 | genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0, | |
2787 | 0, NL80211_CMD_NEW_STATION, 0); | |
2788 | ||
62847751 | 2789 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(bss->ifname)); |
0f4e8b4f JM |
2790 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, params->addr); |
2791 | NLA_PUT_U16(msg, NL80211_ATTR_STA_AID, params->aid); | |
2792 | NLA_PUT(msg, NL80211_ATTR_STA_SUPPORTED_RATES, params->supp_rates_len, | |
2793 | params->supp_rates); | |
2794 | NLA_PUT_U16(msg, NL80211_ATTR_STA_LISTEN_INTERVAL, | |
2795 | params->listen_interval); | |
0f4e8b4f JM |
2796 | if (params->ht_capabilities) { |
2797 | NLA_PUT(msg, NL80211_ATTR_HT_CAPABILITY, | |
fc4e2d95 JM |
2798 | sizeof(*params->ht_capabilities), |
2799 | params->ht_capabilities); | |
0f4e8b4f | 2800 | } |
0f4e8b4f JM |
2801 | |
2802 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
2803 | if (ret) | |
2804 | wpa_printf(MSG_DEBUG, "nl80211: NL80211_CMD_NEW_STATION " | |
2805 | "result: %d (%s)", ret, strerror(-ret)); | |
2806 | if (ret == -EEXIST) | |
2807 | ret = 0; | |
2808 | nla_put_failure: | |
2809 | return ret; | |
2810 | } | |
2811 | ||
2812 | ||
2813 | static int wpa_driver_nl80211_sta_remove(void *priv, const u8 *addr) | |
2814 | { | |
a2e40bb6 FF |
2815 | struct i802_bss *bss = priv; |
2816 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
0f4e8b4f JM |
2817 | struct nl_msg *msg; |
2818 | int ret; | |
2819 | ||
2820 | msg = nlmsg_alloc(); | |
2821 | if (!msg) | |
2822 | return -ENOMEM; | |
2823 | ||
2824 | genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0, | |
2825 | 0, NL80211_CMD_DEL_STATION, 0); | |
2826 | ||
2827 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, | |
a2e40bb6 | 2828 | if_nametoindex(bss->ifname)); |
0f4e8b4f JM |
2829 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); |
2830 | ||
2831 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
2832 | if (ret == -ENOENT) | |
2833 | return 0; | |
2834 | return ret; | |
2835 | nla_put_failure: | |
2836 | return -ENOBUFS; | |
2837 | } | |
2838 | ||
1581b38b | 2839 | |
0915d02c JM |
2840 | static void nl80211_remove_iface(struct wpa_driver_nl80211_data *drv, |
2841 | int ifidx) | |
2842 | { | |
2843 | struct nl_msg *msg; | |
2844 | ||
c6e8e8e4 JM |
2845 | wpa_printf(MSG_DEBUG, "nl80211: Remove interface ifindex=%d", ifidx); |
2846 | ||
2135f224 JM |
2847 | #ifdef HOSTAPD |
2848 | /* stop listening for EAPOL on this interface */ | |
2849 | del_ifidx(drv, ifidx); | |
2850 | #endif /* HOSTAPD */ | |
2851 | ||
0915d02c JM |
2852 | msg = nlmsg_alloc(); |
2853 | if (!msg) | |
2854 | goto nla_put_failure; | |
2855 | ||
2856 | genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0, | |
2857 | 0, NL80211_CMD_DEL_INTERFACE, 0); | |
2858 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, ifidx); | |
2859 | ||
2860 | if (send_and_recv_msgs(drv, msg, NULL, NULL) == 0) | |
2861 | return; | |
2862 | nla_put_failure: | |
e748062b | 2863 | wpa_printf(MSG_ERROR, "Failed to remove interface (ifidx=%d)", ifidx); |
0915d02c JM |
2864 | } |
2865 | ||
2866 | ||
a35187e7 KH |
2867 | static int nl80211_create_iface_once(struct wpa_driver_nl80211_data *drv, |
2868 | const char *ifname, | |
2869 | enum nl80211_iftype iftype, | |
fbbfcbac | 2870 | const u8 *addr, int wds) |
0915d02c JM |
2871 | { |
2872 | struct nl_msg *msg, *flags = NULL; | |
2873 | int ifidx; | |
2874 | int ret = -ENOBUFS; | |
2875 | ||
2876 | msg = nlmsg_alloc(); | |
2877 | if (!msg) | |
2878 | return -1; | |
2879 | ||
2880 | genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0, | |
2881 | 0, NL80211_CMD_NEW_INTERFACE, 0); | |
2882 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); | |
2883 | NLA_PUT_STRING(msg, NL80211_ATTR_IFNAME, ifname); | |
2884 | NLA_PUT_U32(msg, NL80211_ATTR_IFTYPE, iftype); | |
2885 | ||
2886 | if (iftype == NL80211_IFTYPE_MONITOR) { | |
2887 | int err; | |
2888 | ||
2889 | flags = nlmsg_alloc(); | |
2890 | if (!flags) | |
2891 | goto nla_put_failure; | |
2892 | ||
2893 | NLA_PUT_FLAG(flags, NL80211_MNTR_FLAG_COOK_FRAMES); | |
2894 | ||
2895 | err = nla_put_nested(msg, NL80211_ATTR_MNTR_FLAGS, flags); | |
2896 | ||
2897 | nlmsg_free(flags); | |
2898 | ||
2899 | if (err) | |
2900 | goto nla_put_failure; | |
fbbfcbac FF |
2901 | } else if (wds) { |
2902 | NLA_PUT_U8(msg, NL80211_ATTR_4ADDR, wds); | |
0915d02c JM |
2903 | } |
2904 | ||
2905 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
2906 | if (ret) { | |
2907 | nla_put_failure: | |
a35187e7 KH |
2908 | wpa_printf(MSG_ERROR, "Failed to create interface %s: %d (%s)", |
2909 | ifname, ret, strerror(-ret)); | |
0915d02c JM |
2910 | return ret; |
2911 | } | |
2912 | ||
2913 | ifidx = if_nametoindex(ifname); | |
c6e8e8e4 JM |
2914 | wpa_printf(MSG_DEBUG, "nl80211: New interface %s created: ifindex=%d", |
2915 | ifname, ifidx); | |
0915d02c JM |
2916 | |
2917 | if (ifidx <= 0) | |
2918 | return -1; | |
2919 | ||
2135f224 JM |
2920 | #ifdef HOSTAPD |
2921 | /* start listening for EAPOL on this interface */ | |
2922 | add_ifidx(drv, ifidx); | |
7bfc47c3 | 2923 | #endif /* HOSTAPD */ |
2135f224 | 2924 | |
7bfc47c3 | 2925 | if (addr && iftype != NL80211_IFTYPE_MONITOR && |
2ac9688e | 2926 | linux_set_ifhwaddr(drv->ioctl_sock, ifname, addr)) { |
41d931ee JM |
2927 | nl80211_remove_iface(drv, ifidx); |
2928 | return -1; | |
2135f224 | 2929 | } |
2135f224 | 2930 | |
0915d02c JM |
2931 | return ifidx; |
2932 | } | |
22a7c9d7 JM |
2933 | |
2934 | ||
a35187e7 KH |
2935 | static int nl80211_create_iface(struct wpa_driver_nl80211_data *drv, |
2936 | const char *ifname, enum nl80211_iftype iftype, | |
fbbfcbac | 2937 | const u8 *addr, int wds) |
a35187e7 KH |
2938 | { |
2939 | int ret; | |
2940 | ||
fbbfcbac | 2941 | ret = nl80211_create_iface_once(drv, ifname, iftype, addr, wds); |
a35187e7 KH |
2942 | |
2943 | /* if error occured and interface exists already */ | |
2944 | if (ret == -ENFILE && if_nametoindex(ifname)) { | |
2945 | wpa_printf(MSG_INFO, "Try to remove and re-create %s", ifname); | |
2946 | ||
2947 | /* Try to remove the interface that was already there. */ | |
2948 | nl80211_remove_iface(drv, if_nametoindex(ifname)); | |
2949 | ||
2950 | /* Try to create the interface again */ | |
fbbfcbac FF |
2951 | ret = nl80211_create_iface_once(drv, ifname, iftype, addr, |
2952 | wds); | |
a35187e7 KH |
2953 | } |
2954 | ||
4e5cb1a3 JM |
2955 | if (ret >= 0 && drv->disable_11b_rates) |
2956 | nl80211_disable_11b_rates(drv, ret, 1); | |
2957 | ||
a35187e7 KH |
2958 | return ret; |
2959 | } | |
0915d02c | 2960 | |
2135f224 | 2961 | |
0915d02c JM |
2962 | static void handle_tx_callback(void *ctx, u8 *buf, size_t len, int ok) |
2963 | { | |
2964 | struct ieee80211_hdr *hdr; | |
f8b1f695 JM |
2965 | u16 fc; |
2966 | union wpa_event_data event; | |
0915d02c JM |
2967 | |
2968 | hdr = (struct ieee80211_hdr *) buf; | |
2969 | fc = le_to_host16(hdr->frame_control); | |
2970 | ||
f8b1f695 JM |
2971 | os_memset(&event, 0, sizeof(event)); |
2972 | event.tx_status.type = WLAN_FC_GET_TYPE(fc); | |
2973 | event.tx_status.stype = WLAN_FC_GET_STYPE(fc); | |
2974 | event.tx_status.dst = hdr->addr1; | |
2975 | event.tx_status.data = buf; | |
2976 | event.tx_status.data_len = len; | |
2977 | event.tx_status.ack = ok; | |
2978 | wpa_supplicant_event(ctx, EVENT_TX_STATUS, &event); | |
0915d02c JM |
2979 | } |
2980 | ||
2981 | ||
4b9841d3 | 2982 | static void from_unknown_sta(struct wpa_driver_nl80211_data *drv, |
0d9fc3d8 | 2983 | u8 *buf, size_t len) |
0915d02c | 2984 | { |
f8b1f695 JM |
2985 | union wpa_event_data event; |
2986 | os_memset(&event, 0, sizeof(event)); | |
0d9fc3d8 | 2987 | event.rx_from_unknown.frame = buf; |
f8b1f695 JM |
2988 | event.rx_from_unknown.len = len; |
2989 | wpa_supplicant_event(drv->ctx, EVENT_RX_FROM_UNKNOWN, &event); | |
4b9841d3 | 2990 | } |
0915d02c | 2991 | |
4b9841d3 JM |
2992 | |
2993 | static void handle_frame(struct wpa_driver_nl80211_data *drv, | |
2a8b7416 | 2994 | u8 *buf, size_t len, int datarate, int ssi_signal) |
4b9841d3 JM |
2995 | { |
2996 | struct ieee80211_hdr *hdr; | |
f8b1f695 JM |
2997 | u16 fc; |
2998 | union wpa_event_data event; | |
0915d02c JM |
2999 | |
3000 | hdr = (struct ieee80211_hdr *) buf; | |
3001 | fc = le_to_host16(hdr->frame_control); | |
0915d02c | 3002 | |
4b9841d3 | 3003 | switch (WLAN_FC_GET_TYPE(fc)) { |
0915d02c | 3004 | case WLAN_FC_TYPE_MGMT: |
f8b1f695 JM |
3005 | os_memset(&event, 0, sizeof(event)); |
3006 | event.rx_mgmt.frame = buf; | |
3007 | event.rx_mgmt.frame_len = len; | |
2a8b7416 JM |
3008 | event.rx_mgmt.datarate = datarate; |
3009 | event.rx_mgmt.ssi_signal = ssi_signal; | |
f8b1f695 | 3010 | wpa_supplicant_event(drv->ctx, EVENT_RX_MGMT, &event); |
0915d02c JM |
3011 | break; |
3012 | case WLAN_FC_TYPE_CTRL: | |
3013 | /* can only get here with PS-Poll frames */ | |
3014 | wpa_printf(MSG_DEBUG, "CTRL"); | |
0d9fc3d8 | 3015 | from_unknown_sta(drv, buf, len); |
0915d02c JM |
3016 | break; |
3017 | case WLAN_FC_TYPE_DATA: | |
0d9fc3d8 | 3018 | from_unknown_sta(drv, buf, len); |
0915d02c JM |
3019 | break; |
3020 | } | |
3021 | } | |
3022 | ||
3023 | ||
3024 | static void handle_monitor_read(int sock, void *eloop_ctx, void *sock_ctx) | |
3025 | { | |
3026 | struct wpa_driver_nl80211_data *drv = eloop_ctx; | |
3027 | int len; | |
3028 | unsigned char buf[3000]; | |
3029 | struct ieee80211_radiotap_iterator iter; | |
3030 | int ret; | |
2a8b7416 | 3031 | int datarate = 0, ssi_signal = 0; |
4b9841d3 | 3032 | int injected = 0, failed = 0, rxflags = 0; |
0915d02c JM |
3033 | |
3034 | len = recv(sock, buf, sizeof(buf), 0); | |
3035 | if (len < 0) { | |
3036 | perror("recv"); | |
3037 | return; | |
3038 | } | |
3039 | ||
504e905c JM |
3040 | if (drv->nlmode == NL80211_IFTYPE_STATION && !drv->probe_req_report) { |
3041 | wpa_printf(MSG_DEBUG, "nl80211: Ignore monitor interface " | |
3042 | "frame since Probe Request reporting is disabled"); | |
3043 | return; | |
3044 | } | |
3045 | ||
0915d02c JM |
3046 | if (ieee80211_radiotap_iterator_init(&iter, (void*)buf, len)) { |
3047 | printf("received invalid radiotap frame\n"); | |
3048 | return; | |
3049 | } | |
3050 | ||
0915d02c JM |
3051 | while (1) { |
3052 | ret = ieee80211_radiotap_iterator_next(&iter); | |
3053 | if (ret == -ENOENT) | |
3054 | break; | |
3055 | if (ret) { | |
3056 | printf("received invalid radiotap frame (%d)\n", ret); | |
3057 | return; | |
3058 | } | |
3059 | switch (iter.this_arg_index) { | |
3060 | case IEEE80211_RADIOTAP_FLAGS: | |
3061 | if (*iter.this_arg & IEEE80211_RADIOTAP_F_FCS) | |
3062 | len -= 4; | |
3063 | break; | |
3064 | case IEEE80211_RADIOTAP_RX_FLAGS: | |
3065 | rxflags = 1; | |
3066 | break; | |
3067 | case IEEE80211_RADIOTAP_TX_FLAGS: | |
3068 | injected = 1; | |
3069 | failed = le_to_host16((*(uint16_t *) iter.this_arg)) & | |
3070 | IEEE80211_RADIOTAP_F_TX_FAIL; | |
3071 | break; | |
3072 | case IEEE80211_RADIOTAP_DATA_RETRIES: | |
3073 | break; | |
3074 | case IEEE80211_RADIOTAP_CHANNEL: | |
2a8b7416 | 3075 | /* TODO: convert from freq/flags to channel number */ |
0915d02c JM |
3076 | break; |
3077 | case IEEE80211_RADIOTAP_RATE: | |
2a8b7416 | 3078 | datarate = *iter.this_arg * 5; |
0915d02c JM |
3079 | break; |
3080 | case IEEE80211_RADIOTAP_DB_ANTSIGNAL: | |
2a8b7416 | 3081 | ssi_signal = *iter.this_arg; |
0915d02c JM |
3082 | break; |
3083 | } | |
3084 | } | |
3085 | ||
3086 | if (rxflags && injected) | |
3087 | return; | |
3088 | ||
3089 | if (!injected) | |
4b9841d3 | 3090 | handle_frame(drv, buf + iter.max_length, |
2a8b7416 | 3091 | len - iter.max_length, datarate, ssi_signal); |
0915d02c | 3092 | else |
4b9841d3 JM |
3093 | handle_tx_callback(drv->ctx, buf + iter.max_length, |
3094 | len - iter.max_length, !failed); | |
0915d02c JM |
3095 | } |
3096 | ||
3097 | ||
3098 | /* | |
3099 | * we post-process the filter code later and rewrite | |
3100 | * this to the offset to the last instruction | |
3101 | */ | |
3102 | #define PASS 0xFF | |
3103 | #define FAIL 0xFE | |
3104 | ||
3105 | static struct sock_filter msock_filter_insns[] = { | |
3106 | /* | |
3107 | * do a little-endian load of the radiotap length field | |
3108 | */ | |
3109 | /* load lower byte into A */ | |
3110 | BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2), | |
3111 | /* put it into X (== index register) */ | |
3112 | BPF_STMT(BPF_MISC| BPF_TAX, 0), | |
3113 | /* load upper byte into A */ | |
3114 | BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 3), | |
3115 | /* left-shift it by 8 */ | |
3116 | BPF_STMT(BPF_ALU | BPF_LSH | BPF_K, 8), | |
3117 | /* or with X */ | |
3118 | BPF_STMT(BPF_ALU | BPF_OR | BPF_X, 0), | |
3119 | /* put result into X */ | |
3120 | BPF_STMT(BPF_MISC| BPF_TAX, 0), | |
3121 | ||
3122 | /* | |
3123 | * Allow management frames through, this also gives us those | |
3124 | * management frames that we sent ourselves with status | |
3125 | */ | |
3126 | /* load the lower byte of the IEEE 802.11 frame control field */ | |
3127 | BPF_STMT(BPF_LD | BPF_B | BPF_IND, 0), | |
3128 | /* mask off frame type and version */ | |
3129 | BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0xF), | |
3130 | /* accept frame if it's both 0, fall through otherwise */ | |
3131 | BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0, PASS, 0), | |
3132 | ||
3133 | /* | |
3134 | * TODO: add a bit to radiotap RX flags that indicates | |
3135 | * that the sending station is not associated, then | |
3136 | * add a filter here that filters on our DA and that flag | |
3137 | * to allow us to deauth frames to that bad station. | |
3138 | * | |
3139 | * Not a regression -- we didn't do it before either. | |
3140 | */ | |
3141 | ||
3142 | #if 0 | |
3143 | /* | |
fbbfcbac | 3144 | * drop non-data frames |
0915d02c JM |
3145 | */ |
3146 | /* load the lower byte of the frame control field */ | |
3147 | BPF_STMT(BPF_LD | BPF_B | BPF_IND, 0), | |
3148 | /* mask off QoS bit */ | |
3149 | BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0x0c), | |
3150 | /* drop non-data frames */ | |
3151 | BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 8, 0, FAIL), | |
fbbfcbac | 3152 | #endif |
0915d02c | 3153 | /* load the upper byte of the frame control field */ |
fbbfcbac | 3154 | BPF_STMT(BPF_LD | BPF_B | BPF_IND, 1), |
0915d02c JM |
3155 | /* mask off toDS/fromDS */ |
3156 | BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0x03), | |
fbbfcbac FF |
3157 | /* accept WDS frames */ |
3158 | BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 3, PASS, 0), | |
0915d02c JM |
3159 | |
3160 | /* | |
3161 | * add header length to index | |
3162 | */ | |
3163 | /* load the lower byte of the frame control field */ | |
3164 | BPF_STMT(BPF_LD | BPF_B | BPF_IND, 0), | |
3165 | /* mask off QoS bit */ | |
3166 | BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0x80), | |
3167 | /* right shift it by 6 to give 0 or 2 */ | |
3168 | BPF_STMT(BPF_ALU | BPF_RSH | BPF_K, 6), | |
3169 | /* add data frame header length */ | |
3170 | BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 24), | |
3171 | /* add index, was start of 802.11 header */ | |
3172 | BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0), | |
3173 | /* move to index, now start of LL header */ | |
3174 | BPF_STMT(BPF_MISC | BPF_TAX, 0), | |
3175 | ||
3176 | /* | |
3177 | * Accept empty data frames, we use those for | |
3178 | * polling activity. | |
3179 | */ | |
3180 | BPF_STMT(BPF_LD | BPF_W | BPF_LEN, 0), | |
3181 | BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_X, 0, PASS, 0), | |
3182 | ||
3183 | /* | |
3184 | * Accept EAPOL frames | |
3185 | */ | |
3186 | BPF_STMT(BPF_LD | BPF_W | BPF_IND, 0), | |
3187 | BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0xAAAA0300, 0, FAIL), | |
3188 | BPF_STMT(BPF_LD | BPF_W | BPF_IND, 4), | |
3189 | BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x0000888E, PASS, FAIL), | |
3190 | ||
3191 | /* keep these last two statements or change the code below */ | |
3192 | /* return 0 == "DROP" */ | |
3193 | BPF_STMT(BPF_RET | BPF_K, 0), | |
3194 | /* return ~0 == "keep all" */ | |
3195 | BPF_STMT(BPF_RET | BPF_K, ~0), | |
3196 | }; | |
3197 | ||
3198 | static struct sock_fprog msock_filter = { | |
3199 | .len = sizeof(msock_filter_insns)/sizeof(msock_filter_insns[0]), | |
3200 | .filter = msock_filter_insns, | |
3201 | }; | |
3202 | ||
3203 | ||
3204 | static int add_monitor_filter(int s) | |
3205 | { | |
3206 | int idx; | |
3207 | ||
3208 | /* rewrite all PASS/FAIL jump offsets */ | |
3209 | for (idx = 0; idx < msock_filter.len; idx++) { | |
3210 | struct sock_filter *insn = &msock_filter_insns[idx]; | |
3211 | ||
3212 | if (BPF_CLASS(insn->code) == BPF_JMP) { | |
3213 | if (insn->code == (BPF_JMP|BPF_JA)) { | |
3214 | if (insn->k == PASS) | |
3215 | insn->k = msock_filter.len - idx - 2; | |
3216 | else if (insn->k == FAIL) | |
3217 | insn->k = msock_filter.len - idx - 3; | |
3218 | } | |
3219 | ||
3220 | if (insn->jt == PASS) | |
3221 | insn->jt = msock_filter.len - idx - 2; | |
3222 | else if (insn->jt == FAIL) | |
3223 | insn->jt = msock_filter.len - idx - 3; | |
3224 | ||
3225 | if (insn->jf == PASS) | |
3226 | insn->jf = msock_filter.len - idx - 2; | |
3227 | else if (insn->jf == FAIL) | |
3228 | insn->jf = msock_filter.len - idx - 3; | |
3229 | } | |
3230 | } | |
3231 | ||
3232 | if (setsockopt(s, SOL_SOCKET, SO_ATTACH_FILTER, | |
3233 | &msock_filter, sizeof(msock_filter))) { | |
3234 | perror("SO_ATTACH_FILTER"); | |
3235 | return -1; | |
3236 | } | |
3237 | ||
3238 | return 0; | |
3239 | } | |
3240 | ||
3241 | ||
460456f8 JM |
3242 | static void nl80211_remove_monitor_interface( |
3243 | struct wpa_driver_nl80211_data *drv) | |
3244 | { | |
3245 | if (drv->monitor_ifidx >= 0) { | |
3246 | nl80211_remove_iface(drv, drv->monitor_ifidx); | |
3247 | drv->monitor_ifidx = -1; | |
3248 | } | |
504e905c JM |
3249 | if (drv->monitor_sock >= 0) { |
3250 | eloop_unregister_read_sock(drv->monitor_sock); | |
3251 | close(drv->monitor_sock); | |
3252 | drv->monitor_sock = -1; | |
3253 | } | |
460456f8 JM |
3254 | } |
3255 | ||
3256 | ||
0915d02c JM |
3257 | static int |
3258 | nl80211_create_monitor_interface(struct wpa_driver_nl80211_data *drv) | |
3259 | { | |
3260 | char buf[IFNAMSIZ]; | |
3261 | struct sockaddr_ll ll; | |
3262 | int optval; | |
3263 | socklen_t optlen; | |
0915d02c | 3264 | |
a2e40bb6 | 3265 | snprintf(buf, IFNAMSIZ, "mon.%s", drv->first_bss.ifname); |
0915d02c JM |
3266 | buf[IFNAMSIZ - 1] = '\0'; |
3267 | ||
3268 | drv->monitor_ifidx = | |
fbbfcbac FF |
3269 | nl80211_create_iface(drv, buf, NL80211_IFTYPE_MONITOR, NULL, |
3270 | 0); | |
0915d02c JM |
3271 | |
3272 | if (drv->monitor_ifidx < 0) | |
3273 | return -1; | |
3274 | ||
34f2f814 | 3275 | if (linux_set_iface_flags(drv->ioctl_sock, buf, 1)) |
0915d02c | 3276 | goto error; |
0915d02c JM |
3277 | |
3278 | memset(&ll, 0, sizeof(ll)); | |
3279 | ll.sll_family = AF_PACKET; | |
3280 | ll.sll_ifindex = drv->monitor_ifidx; | |
3281 | drv->monitor_sock = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL)); | |
3282 | if (drv->monitor_sock < 0) { | |
3283 | perror("socket[PF_PACKET,SOCK_RAW]"); | |
3284 | goto error; | |
3285 | } | |
3286 | ||
3287 | if (add_monitor_filter(drv->monitor_sock)) { | |
3288 | wpa_printf(MSG_INFO, "Failed to set socket filter for monitor " | |
3289 | "interface; do filtering in user space"); | |
3290 | /* This works, but will cost in performance. */ | |
3291 | } | |
3292 | ||
2135f224 | 3293 | if (bind(drv->monitor_sock, (struct sockaddr *) &ll, sizeof(ll)) < 0) { |
0915d02c JM |
3294 | perror("monitor socket bind"); |
3295 | goto error; | |
3296 | } | |
3297 | ||
3298 | optlen = sizeof(optval); | |
3299 | optval = 20; | |
3300 | if (setsockopt | |
3301 | (drv->monitor_sock, SOL_SOCKET, SO_PRIORITY, &optval, optlen)) { | |
3302 | perror("Failed to set socket priority"); | |
3303 | goto error; | |
3304 | } | |
3305 | ||
3306 | if (eloop_register_read_sock(drv->monitor_sock, handle_monitor_read, | |
3307 | drv, NULL)) { | |
3308 | printf("Could not register monitor read socket\n"); | |
3309 | goto error; | |
3310 | } | |
3311 | ||
3312 | return 0; | |
3313 | error: | |
460456f8 | 3314 | nl80211_remove_monitor_interface(drv); |
0915d02c JM |
3315 | return -1; |
3316 | } | |
3317 | ||
db149ac9 JM |
3318 | |
3319 | static const u8 rfc1042_header[6] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 }; | |
3320 | ||
3321 | static int wpa_driver_nl80211_hapd_send_eapol( | |
3322 | void *priv, const u8 *addr, const u8 *data, | |
3323 | size_t data_len, int encrypt, const u8 *own_addr) | |
3324 | { | |
a2e40bb6 FF |
3325 | struct i802_bss *bss = priv; |
3326 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
db149ac9 JM |
3327 | struct ieee80211_hdr *hdr; |
3328 | size_t len; | |
3329 | u8 *pos; | |
3330 | int res; | |
3331 | #if 0 /* FIX */ | |
0de39516 | 3332 | int qos = sta->flags & WPA_STA_WMM; |
db149ac9 JM |
3333 | #else |
3334 | int qos = 0; | |
3335 | #endif | |
3336 | ||
3337 | len = sizeof(*hdr) + (qos ? 2 : 0) + sizeof(rfc1042_header) + 2 + | |
3338 | data_len; | |
3339 | hdr = os_zalloc(len); | |
3340 | if (hdr == NULL) { | |
3341 | printf("malloc() failed for i802_send_data(len=%lu)\n", | |
3342 | (unsigned long) len); | |
3343 | return -1; | |
3344 | } | |
3345 | ||
3346 | hdr->frame_control = | |
3347 | IEEE80211_FC(WLAN_FC_TYPE_DATA, WLAN_FC_STYPE_DATA); | |
3348 | hdr->frame_control |= host_to_le16(WLAN_FC_FROMDS); | |
3349 | if (encrypt) | |
3350 | hdr->frame_control |= host_to_le16(WLAN_FC_ISWEP); | |
3351 | #if 0 /* To be enabled if qos determination is added above */ | |
3352 | if (qos) { | |
3353 | hdr->frame_control |= | |
3354 | host_to_le16(WLAN_FC_STYPE_QOS_DATA << 4); | |
3355 | } | |
3356 | #endif | |
3357 | ||
3358 | memcpy(hdr->IEEE80211_DA_FROMDS, addr, ETH_ALEN); | |
3359 | memcpy(hdr->IEEE80211_BSSID_FROMDS, own_addr, ETH_ALEN); | |
3360 | memcpy(hdr->IEEE80211_SA_FROMDS, own_addr, ETH_ALEN); | |
3361 | pos = (u8 *) (hdr + 1); | |
3362 | ||
3363 | #if 0 /* To be enabled if qos determination is added above */ | |
3364 | if (qos) { | |
3365 | /* add an empty QoS header if needed */ | |
3366 | pos[0] = 0; | |
3367 | pos[1] = 0; | |
3368 | pos += 2; | |
3369 | } | |
3370 | #endif | |
3371 | ||
3372 | memcpy(pos, rfc1042_header, sizeof(rfc1042_header)); | |
3373 | pos += sizeof(rfc1042_header); | |
3374 | WPA_PUT_BE16(pos, ETH_P_PAE); | |
3375 | pos += 2; | |
3376 | memcpy(pos, data, data_len); | |
3377 | ||
3378 | res = wpa_driver_nl80211_send_frame(drv, (u8 *) hdr, len, encrypt); | |
3379 | if (res < 0) { | |
3380 | wpa_printf(MSG_ERROR, "i802_send_eapol - packet len: %lu - " | |
3381 | "failed: %d (%s)", | |
3382 | (unsigned long) len, errno, strerror(errno)); | |
3383 | } | |
7bf12757 | 3384 | os_free(hdr); |
db149ac9 JM |
3385 | |
3386 | return res; | |
3387 | } | |
3388 | ||
a8d6ffa4 | 3389 | |
7e76ee9c JM |
3390 | static u32 sta_flags_nl80211(int flags) |
3391 | { | |
3392 | u32 f = 0; | |
3393 | ||
0de39516 | 3394 | if (flags & WPA_STA_AUTHORIZED) |
7e76ee9c | 3395 | f |= BIT(NL80211_STA_FLAG_AUTHORIZED); |
0de39516 | 3396 | if (flags & WPA_STA_WMM) |
7e76ee9c | 3397 | f |= BIT(NL80211_STA_FLAG_WME); |
0de39516 | 3398 | if (flags & WPA_STA_SHORT_PREAMBLE) |
7e76ee9c | 3399 | f |= BIT(NL80211_STA_FLAG_SHORT_PREAMBLE); |
0de39516 | 3400 | if (flags & WPA_STA_MFP) |
7e76ee9c JM |
3401 | f |= BIT(NL80211_STA_FLAG_MFP); |
3402 | ||
3403 | return f; | |
3404 | } | |
3405 | ||
3406 | ||
3234cba4 JM |
3407 | static int wpa_driver_nl80211_sta_set_flags(void *priv, const u8 *addr, |
3408 | int total_flags, | |
4c32757d | 3409 | int flags_or, int flags_and) |
a8d6ffa4 | 3410 | { |
a2e40bb6 FF |
3411 | struct i802_bss *bss = priv; |
3412 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
a8d6ffa4 | 3413 | struct nl_msg *msg, *flags = NULL; |
7e76ee9c | 3414 | struct nl80211_sta_flag_update upd; |
a8d6ffa4 JM |
3415 | |
3416 | msg = nlmsg_alloc(); | |
3417 | if (!msg) | |
3418 | return -ENOMEM; | |
3419 | ||
3420 | flags = nlmsg_alloc(); | |
3421 | if (!flags) { | |
3422 | nlmsg_free(msg); | |
3423 | return -ENOMEM; | |
3424 | } | |
3425 | ||
3426 | genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0, | |
3427 | 0, NL80211_CMD_SET_STATION, 0); | |
3428 | ||
3429 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, | |
3234cba4 | 3430 | if_nametoindex(bss->ifname)); |
a8d6ffa4 JM |
3431 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); |
3432 | ||
7e76ee9c JM |
3433 | /* |
3434 | * Backwards compatibility version using NL80211_ATTR_STA_FLAGS. This | |
3435 | * can be removed eventually. | |
3436 | */ | |
0de39516 | 3437 | if (total_flags & WPA_STA_AUTHORIZED) |
a8d6ffa4 JM |
3438 | NLA_PUT_FLAG(flags, NL80211_STA_FLAG_AUTHORIZED); |
3439 | ||
0de39516 | 3440 | if (total_flags & WPA_STA_WMM) |
a8d6ffa4 JM |
3441 | NLA_PUT_FLAG(flags, NL80211_STA_FLAG_WME); |
3442 | ||
0de39516 | 3443 | if (total_flags & WPA_STA_SHORT_PREAMBLE) |
a8d6ffa4 JM |
3444 | NLA_PUT_FLAG(flags, NL80211_STA_FLAG_SHORT_PREAMBLE); |
3445 | ||
0de39516 | 3446 | if (total_flags & WPA_STA_MFP) |
a8d6ffa4 JM |
3447 | NLA_PUT_FLAG(flags, NL80211_STA_FLAG_MFP); |
3448 | ||
3449 | if (nla_put_nested(msg, NL80211_ATTR_STA_FLAGS, flags)) | |
3450 | goto nla_put_failure; | |
3451 | ||
7e76ee9c JM |
3452 | os_memset(&upd, 0, sizeof(upd)); |
3453 | upd.mask = sta_flags_nl80211(flags_or | ~flags_and); | |
3454 | upd.set = sta_flags_nl80211(flags_or); | |
3455 | NLA_PUT(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd); | |
3456 | ||
a8d6ffa4 JM |
3457 | nlmsg_free(flags); |
3458 | ||
3459 | return send_and_recv_msgs(drv, msg, NULL, NULL); | |
3460 | nla_put_failure: | |
3461 | nlmsg_free(flags); | |
3462 | return -ENOBUFS; | |
3463 | } | |
3464 | ||
0915d02c | 3465 | |
1581b38b JM |
3466 | static int wpa_driver_nl80211_ap(struct wpa_driver_nl80211_data *drv, |
3467 | struct wpa_driver_associate_params *params) | |
3468 | { | |
a2e40bb6 | 3469 | if (wpa_driver_nl80211_set_mode(&drv->first_bss, params->mode) || |
f019981a | 3470 | wpa_driver_nl80211_set_freq(drv, params->freq, 0, 0)) { |
460456f8 | 3471 | nl80211_remove_monitor_interface(drv); |
1581b38b | 3472 | return -1; |
0915d02c | 3473 | } |
1581b38b JM |
3474 | |
3475 | /* TODO: setup monitor interface (and add code somewhere to remove this | |
3476 | * when AP mode is stopped; associate with mode != 2 or drv_deinit) */ | |
1581b38b JM |
3477 | |
3478 | return 0; | |
3479 | } | |
1581b38b JM |
3480 | |
3481 | ||
5cc4d64b JM |
3482 | static int nl80211_leave_ibss(struct wpa_driver_nl80211_data *drv) |
3483 | { | |
3484 | struct nl_msg *msg; | |
3485 | int ret = -1; | |
3486 | ||
3487 | msg = nlmsg_alloc(); | |
3488 | if (!msg) | |
3489 | return -1; | |
3490 | ||
3491 | genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0, 0, | |
3492 | NL80211_CMD_LEAVE_IBSS, 0); | |
3493 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); | |
3494 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
3495 | msg = NULL; | |
3496 | if (ret) { | |
3497 | wpa_printf(MSG_DEBUG, "nl80211: Leave IBSS failed: ret=%d " | |
3498 | "(%s)", ret, strerror(-ret)); | |
3499 | goto nla_put_failure; | |
3500 | } | |
3501 | ||
3502 | ret = 0; | |
3503 | wpa_printf(MSG_DEBUG, "nl80211: Leave IBSS request sent successfully"); | |
3504 | ||
3505 | nla_put_failure: | |
3506 | nlmsg_free(msg); | |
3507 | return ret; | |
3508 | } | |
3509 | ||
3510 | ||
3511 | static int wpa_driver_nl80211_ibss(struct wpa_driver_nl80211_data *drv, | |
3512 | struct wpa_driver_associate_params *params) | |
3513 | { | |
3514 | struct nl_msg *msg; | |
3515 | int ret = -1; | |
3516 | int count = 0; | |
3517 | ||
3518 | wpa_printf(MSG_DEBUG, "nl80211: Join IBSS (ifindex=%d)", drv->ifindex); | |
3519 | ||
a2e40bb6 | 3520 | if (wpa_driver_nl80211_set_mode(&drv->first_bss, params->mode)) { |
5cc4d64b JM |
3521 | wpa_printf(MSG_INFO, "nl80211: Failed to set interface into " |
3522 | "IBSS mode"); | |
3523 | return -1; | |
3524 | } | |
3525 | ||
3526 | retry: | |
3527 | msg = nlmsg_alloc(); | |
3528 | if (!msg) | |
3529 | return -1; | |
3530 | ||
3531 | genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0, 0, | |
3532 | NL80211_CMD_JOIN_IBSS, 0); | |
3533 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); | |
3534 | ||
3535 | if (params->ssid == NULL || params->ssid_len > sizeof(drv->ssid)) | |
3536 | goto nla_put_failure; | |
3537 | ||
3538 | wpa_hexdump_ascii(MSG_DEBUG, " * SSID", | |
3539 | params->ssid, params->ssid_len); | |
3540 | NLA_PUT(msg, NL80211_ATTR_SSID, params->ssid_len, | |
3541 | params->ssid); | |
3542 | os_memcpy(drv->ssid, params->ssid, params->ssid_len); | |
3543 | drv->ssid_len = params->ssid_len; | |
3544 | ||
3545 | wpa_printf(MSG_DEBUG, " * freq=%d", params->freq); | |
3546 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, params->freq); | |
3547 | ||
3548 | ret = nl80211_set_conn_keys(params, msg); | |
3549 | if (ret) | |
3550 | goto nla_put_failure; | |
3551 | ||
a95795ad JM |
3552 | if (params->wpa_ie) { |
3553 | wpa_hexdump(MSG_DEBUG, | |
3554 | " * Extra IEs for Beacon/Probe Response frames", | |
3555 | params->wpa_ie, params->wpa_ie_len); | |
3556 | NLA_PUT(msg, NL80211_ATTR_IE, params->wpa_ie_len, | |
3557 | params->wpa_ie); | |
3558 | } | |
3559 | ||
5cc4d64b JM |
3560 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
3561 | msg = NULL; | |
3562 | if (ret) { | |
3563 | wpa_printf(MSG_DEBUG, "nl80211: Join IBSS failed: ret=%d (%s)", | |
3564 | ret, strerror(-ret)); | |
3565 | count++; | |
3566 | if (ret == -EALREADY && count == 1) { | |
3567 | wpa_printf(MSG_DEBUG, "nl80211: Retry IBSS join after " | |
3568 | "forced leave"); | |
3569 | nl80211_leave_ibss(drv); | |
3570 | nlmsg_free(msg); | |
3571 | goto retry; | |
3572 | } | |
3573 | ||
3574 | goto nla_put_failure; | |
3575 | } | |
3576 | ret = 0; | |
3577 | wpa_printf(MSG_DEBUG, "nl80211: Join IBSS request sent successfully"); | |
3578 | ||
3579 | nla_put_failure: | |
3580 | nlmsg_free(msg); | |
3581 | return ret; | |
3582 | } | |
3583 | ||
3584 | ||
cfaab580 ZY |
3585 | static int wpa_driver_nl80211_connect( |
3586 | struct wpa_driver_nl80211_data *drv, | |
3587 | struct wpa_driver_associate_params *params) | |
3588 | { | |
3589 | struct nl_msg *msg; | |
3590 | enum nl80211_auth_type type; | |
3591 | int ret = 0; | |
3592 | ||
3593 | msg = nlmsg_alloc(); | |
3594 | if (!msg) | |
3595 | return -1; | |
3596 | ||
3597 | wpa_printf(MSG_DEBUG, "nl80211: Connect (ifindex=%d)", drv->ifindex); | |
3598 | genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0, 0, | |
3599 | NL80211_CMD_CONNECT, 0); | |
3600 | ||
3601 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); | |
3602 | if (params->bssid) { | |
3603 | wpa_printf(MSG_DEBUG, " * bssid=" MACSTR, | |
3604 | MAC2STR(params->bssid)); | |
3605 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid); | |
3606 | } | |
3607 | if (params->freq) { | |
3608 | wpa_printf(MSG_DEBUG, " * freq=%d", params->freq); | |
3609 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, params->freq); | |
3610 | } | |
3611 | if (params->ssid) { | |
3612 | wpa_hexdump_ascii(MSG_DEBUG, " * SSID", | |
3613 | params->ssid, params->ssid_len); | |
3614 | NLA_PUT(msg, NL80211_ATTR_SSID, params->ssid_len, | |
3615 | params->ssid); | |
3616 | if (params->ssid_len > sizeof(drv->ssid)) | |
3617 | goto nla_put_failure; | |
3618 | os_memcpy(drv->ssid, params->ssid, params->ssid_len); | |
3619 | drv->ssid_len = params->ssid_len; | |
3620 | } | |
3621 | wpa_hexdump(MSG_DEBUG, " * IEs", params->wpa_ie, params->wpa_ie_len); | |
3622 | if (params->wpa_ie) | |
3623 | NLA_PUT(msg, NL80211_ATTR_IE, params->wpa_ie_len, | |
3624 | params->wpa_ie); | |
3625 | ||
abd9fafa | 3626 | if (params->auth_alg & WPA_AUTH_ALG_OPEN) |
cfaab580 | 3627 | type = NL80211_AUTHTYPE_OPEN_SYSTEM; |
abd9fafa | 3628 | else if (params->auth_alg & WPA_AUTH_ALG_SHARED) |
cfaab580 | 3629 | type = NL80211_AUTHTYPE_SHARED_KEY; |
abd9fafa | 3630 | else if (params->auth_alg & WPA_AUTH_ALG_LEAP) |
cfaab580 | 3631 | type = NL80211_AUTHTYPE_NETWORK_EAP; |
abd9fafa | 3632 | else if (params->auth_alg & WPA_AUTH_ALG_FT) |
cfaab580 ZY |
3633 | type = NL80211_AUTHTYPE_FT; |
3634 | else | |
3635 | goto nla_put_failure; | |
3636 | ||
3637 | wpa_printf(MSG_DEBUG, " * Auth Type %d", type); | |
3638 | NLA_PUT_U32(msg, NL80211_ATTR_AUTH_TYPE, type); | |
3639 | ||
3640 | if (params->wpa_ie && params->wpa_ie_len) { | |
3641 | enum nl80211_wpa_versions ver; | |
3642 | ||
3643 | if (params->wpa_ie[0] == WLAN_EID_RSN) | |
3644 | ver = NL80211_WPA_VERSION_2; | |
3645 | else | |
3646 | ver = NL80211_WPA_VERSION_1; | |
3647 | ||
3648 | wpa_printf(MSG_DEBUG, " * WPA Version %d", ver); | |
3649 | NLA_PUT_U32(msg, NL80211_ATTR_WPA_VERSIONS, ver); | |
3650 | } | |
3651 | ||
3652 | if (params->pairwise_suite != CIPHER_NONE) { | |
c1bb3e0a | 3653 | int cipher; |
cfaab580 ZY |
3654 | |
3655 | switch (params->pairwise_suite) { | |
3656 | case CIPHER_WEP40: | |
3657 | cipher = WLAN_CIPHER_SUITE_WEP40; | |
3658 | break; | |
3659 | case CIPHER_WEP104: | |
3660 | cipher = WLAN_CIPHER_SUITE_WEP104; | |
3661 | break; | |
3662 | case CIPHER_CCMP: | |
3663 | cipher = WLAN_CIPHER_SUITE_CCMP; | |
3664 | break; | |
3665 | case CIPHER_TKIP: | |
3666 | default: | |
3667 | cipher = WLAN_CIPHER_SUITE_TKIP; | |
3668 | break; | |
3669 | } | |
3670 | NLA_PUT_U32(msg, NL80211_ATTR_CIPHER_SUITES_PAIRWISE, cipher); | |
3671 | } | |
3672 | ||
3673 | if (params->group_suite != CIPHER_NONE) { | |
c1bb3e0a | 3674 | int cipher; |
cfaab580 ZY |
3675 | |
3676 | switch (params->group_suite) { | |
3677 | case CIPHER_WEP40: | |
3678 | cipher = WLAN_CIPHER_SUITE_WEP40; | |
3679 | break; | |
3680 | case CIPHER_WEP104: | |
3681 | cipher = WLAN_CIPHER_SUITE_WEP104; | |
3682 | break; | |
3683 | case CIPHER_CCMP: | |
3684 | cipher = WLAN_CIPHER_SUITE_CCMP; | |
3685 | break; | |
3686 | case CIPHER_TKIP: | |
3687 | default: | |
3688 | cipher = WLAN_CIPHER_SUITE_TKIP; | |
3689 | break; | |
3690 | } | |
3691 | NLA_PUT_U32(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, cipher); | |
3692 | } | |
3693 | ||
3694 | if (params->key_mgmt_suite == KEY_MGMT_802_1X || | |
3695 | params->key_mgmt_suite == KEY_MGMT_PSK) { | |
3696 | int mgmt = WLAN_AKM_SUITE_PSK; | |
3697 | ||
3698 | switch (params->key_mgmt_suite) { | |
3699 | case KEY_MGMT_802_1X: | |
3700 | mgmt = WLAN_AKM_SUITE_8021X; | |
3701 | break; | |
3702 | case KEY_MGMT_PSK: | |
3703 | default: | |
3704 | mgmt = WLAN_AKM_SUITE_PSK; | |
3705 | break; | |
3706 | } | |
3707 | NLA_PUT_U32(msg, NL80211_ATTR_AKM_SUITES, mgmt); | |
3708 | } | |
3709 | ||
3710 | ret = nl80211_set_conn_keys(params, msg); | |
3711 | if (ret) | |
3712 | goto nla_put_failure; | |
3713 | ||
3714 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
3715 | msg = NULL; | |
3716 | if (ret) { | |
3717 | wpa_printf(MSG_DEBUG, "nl80211: MLME connect failed: ret=%d " | |
3718 | "(%s)", ret, strerror(-ret)); | |
3719 | goto nla_put_failure; | |
3720 | } | |
3721 | ret = 0; | |
3722 | wpa_printf(MSG_DEBUG, "nl80211: Connect request send successfully"); | |
3723 | ||
3724 | nla_put_failure: | |
3725 | nlmsg_free(msg); | |
3726 | return ret; | |
3727 | ||
3728 | } | |
3729 | ||
3730 | ||
c2a04078 JM |
3731 | static int wpa_driver_nl80211_associate( |
3732 | void *priv, struct wpa_driver_associate_params *params) | |
3733 | { | |
a2e40bb6 FF |
3734 | struct i802_bss *bss = priv; |
3735 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
c2a04078 JM |
3736 | int ret = -1; |
3737 | struct nl_msg *msg; | |
3738 | ||
5cc4d64b | 3739 | if (params->mode == IEEE80211_MODE_AP) |
1581b38b | 3740 | return wpa_driver_nl80211_ap(drv, params); |
1581b38b | 3741 | |
5cc4d64b JM |
3742 | if (params->mode == IEEE80211_MODE_IBSS) |
3743 | return wpa_driver_nl80211_ibss(drv, params); | |
3744 | ||
4a867032 | 3745 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) { |
a2e40bb6 | 3746 | if (wpa_driver_nl80211_set_mode(priv, params->mode) < 0) |
4a867032 | 3747 | return -1; |
cfaab580 | 3748 | return wpa_driver_nl80211_connect(drv, params); |
4a867032 | 3749 | } |
cfaab580 | 3750 | |
c2a04078 JM |
3751 | drv->associated = 0; |
3752 | ||
3753 | msg = nlmsg_alloc(); | |
3754 | if (!msg) | |
3755 | return -1; | |
3756 | ||
3757 | wpa_printf(MSG_DEBUG, "nl80211: Associate (ifindex=%d)", | |
3758 | drv->ifindex); | |
3759 | genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0, 0, | |
3760 | NL80211_CMD_ASSOCIATE, 0); | |
3761 | ||
3762 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); | |
3763 | if (params->bssid) { | |
3764 | wpa_printf(MSG_DEBUG, " * bssid=" MACSTR, | |
3765 | MAC2STR(params->bssid)); | |
3766 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid); | |
3767 | } | |
3768 | if (params->freq) { | |
3769 | wpa_printf(MSG_DEBUG, " * freq=%d", params->freq); | |
3770 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, params->freq); | |
4832ecd7 JM |
3771 | drv->assoc_freq = params->freq; |
3772 | } else | |
3773 | drv->assoc_freq = 0; | |
c2a04078 JM |
3774 | if (params->ssid) { |
3775 | wpa_hexdump_ascii(MSG_DEBUG, " * SSID", | |
3776 | params->ssid, params->ssid_len); | |
3777 | NLA_PUT(msg, NL80211_ATTR_SSID, params->ssid_len, | |
3778 | params->ssid); | |
fd05d64e JM |
3779 | if (params->ssid_len > sizeof(drv->ssid)) |
3780 | goto nla_put_failure; | |
3781 | os_memcpy(drv->ssid, params->ssid, params->ssid_len); | |
3782 | drv->ssid_len = params->ssid_len; | |
c2a04078 JM |
3783 | } |
3784 | wpa_hexdump(MSG_DEBUG, " * IEs", params->wpa_ie, params->wpa_ie_len); | |
3785 | if (params->wpa_ie) | |
3786 | NLA_PUT(msg, NL80211_ATTR_IE, params->wpa_ie_len, | |
3787 | params->wpa_ie); | |
3788 | ||
e572fa33 JM |
3789 | #ifdef CONFIG_IEEE80211W |
3790 | if (params->mgmt_frame_protection == MGMT_FRAME_PROTECTION_REQUIRED) | |
3791 | NLA_PUT_U32(msg, NL80211_ATTR_USE_MFP, NL80211_MFP_REQUIRED); | |
3792 | #endif /* CONFIG_IEEE80211W */ | |
3793 | ||
01652550 JM |
3794 | NLA_PUT_FLAG(msg, NL80211_ATTR_CONTROL_PORT); |
3795 | ||
62fa124c JM |
3796 | if (params->prev_bssid) { |
3797 | wpa_printf(MSG_DEBUG, " * prev_bssid=" MACSTR, | |
3798 | MAC2STR(params->prev_bssid)); | |
3799 | NLA_PUT(msg, NL80211_ATTR_PREV_BSSID, ETH_ALEN, | |
3800 | params->prev_bssid); | |
3801 | } | |
3802 | ||
c2a04078 JM |
3803 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
3804 | msg = NULL; | |
3805 | if (ret) { | |
3806 | wpa_printf(MSG_DEBUG, "nl80211: MLME command failed: ret=%d " | |
3807 | "(%s)", ret, strerror(-ret)); | |
8856462d | 3808 | nl80211_dump_scan(drv); |
c2a04078 JM |
3809 | goto nla_put_failure; |
3810 | } | |
3811 | ret = 0; | |
3812 | wpa_printf(MSG_DEBUG, "nl80211: Association request send " | |
3813 | "successfully"); | |
3814 | ||
3815 | nla_put_failure: | |
3816 | nlmsg_free(msg); | |
3817 | return ret; | |
3818 | } | |
3f5285e8 JM |
3819 | |
3820 | ||
ad1e68e6 JM |
3821 | static int nl80211_set_mode(struct wpa_driver_nl80211_data *drv, |
3822 | int ifindex, int mode) | |
3f5285e8 | 3823 | { |
3f5285e8 | 3824 | struct nl_msg *msg; |
ad1e68e6 JM |
3825 | int ret = -ENOBUFS; |
3826 | ||
3827 | msg = nlmsg_alloc(); | |
3828 | if (!msg) | |
3829 | return -ENOMEM; | |
3830 | ||
3831 | genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0, | |
3832 | 0, NL80211_CMD_SET_INTERFACE, 0); | |
3833 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, ifindex); | |
3834 | NLA_PUT_U32(msg, NL80211_ATTR_IFTYPE, mode); | |
3835 | ||
3836 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
3837 | if (!ret) | |
3838 | return 0; | |
3839 | nla_put_failure: | |
3840 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set interface %d to mode %d:" | |
3841 | " %d (%s)", ifindex, mode, ret, strerror(-ret)); | |
3842 | return ret; | |
3843 | } | |
3844 | ||
3845 | ||
3846 | static int wpa_driver_nl80211_set_mode(void *priv, int mode) | |
3847 | { | |
a2e40bb6 FF |
3848 | struct i802_bss *bss = priv; |
3849 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
ad1e68e6 | 3850 | int ret = -1; |
1581b38b JM |
3851 | int nlmode; |
3852 | ||
3853 | switch (mode) { | |
3854 | case 0: | |
3855 | nlmode = NL80211_IFTYPE_STATION; | |
3856 | break; | |
3857 | case 1: | |
3858 | nlmode = NL80211_IFTYPE_ADHOC; | |
3859 | break; | |
3860 | case 2: | |
3861 | nlmode = NL80211_IFTYPE_AP; | |
3862 | break; | |
3863 | default: | |
3864 | return -1; | |
3865 | } | |
3f5285e8 | 3866 | |
ad1e68e6 JM |
3867 | if (nl80211_set_mode(drv, drv->ifindex, nlmode) == 0) { |
3868 | drv->nlmode = nlmode; | |
460456f8 JM |
3869 | ret = 0; |
3870 | goto done; | |
ad1e68e6 | 3871 | } |
3f5285e8 | 3872 | |
460456f8 | 3873 | if (nlmode == drv->nlmode) { |
c6e8e8e4 JM |
3874 | wpa_printf(MSG_DEBUG, "nl80211: Interface already in " |
3875 | "requested mode - ignore error"); | |
460456f8 JM |
3876 | ret = 0; |
3877 | goto done; /* Already in the requested mode */ | |
3878 | } | |
3f5285e8 | 3879 | |
3f5285e8 JM |
3880 | /* mac80211 doesn't allow mode changes while the device is up, so |
3881 | * take the device down, try to set the mode again, and bring the | |
3882 | * device back up. | |
3883 | */ | |
a2e40bb6 | 3884 | if (linux_set_iface_flags(drv->ioctl_sock, bss->ifname, 0) == 0) { |
3f5285e8 | 3885 | /* Try to set the mode again while the interface is down */ |
ad1e68e6 | 3886 | ret = nl80211_set_mode(drv, drv->ifindex, nlmode); |
a2e40bb6 | 3887 | if (linux_set_iface_flags(drv->ioctl_sock, bss->ifname, 1)) |
2135f224 | 3888 | ret = -1; |
3f5285e8 JM |
3889 | } |
3890 | ||
c6e8e8e4 JM |
3891 | if (!ret) { |
3892 | wpa_printf(MSG_DEBUG, "nl80211: Mode change succeeded while " | |
3893 | "interface is down"); | |
ad1e68e6 | 3894 | drv->nlmode = nlmode; |
c6e8e8e4 | 3895 | } |
ad1e68e6 | 3896 | |
460456f8 | 3897 | done: |
460456f8 JM |
3898 | if (!ret && nlmode == NL80211_IFTYPE_AP) { |
3899 | /* Setup additional AP mode functionality if needed */ | |
3900 | if (drv->monitor_ifidx < 0 && | |
3901 | nl80211_create_monitor_interface(drv)) | |
3902 | return -1; | |
3903 | } else if (!ret && nlmode != NL80211_IFTYPE_AP) { | |
3904 | /* Remove additional AP mode functionality */ | |
3905 | nl80211_remove_monitor_interface(drv); | |
a2e40bb6 | 3906 | bss->beacon_set = 0; |
460456f8 | 3907 | } |
460456f8 | 3908 | |
c6e8e8e4 JM |
3909 | if (ret) |
3910 | wpa_printf(MSG_DEBUG, "nl80211: Interface mode change to %d " | |
3911 | "from %d failed", nlmode, drv->nlmode); | |
3912 | ||
3f5285e8 JM |
3913 | return ret; |
3914 | } | |
3915 | ||
3916 | ||
3f5285e8 JM |
3917 | static int wpa_driver_nl80211_get_capa(void *priv, |
3918 | struct wpa_driver_capa *capa) | |
3919 | { | |
a2e40bb6 FF |
3920 | struct i802_bss *bss = priv; |
3921 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
3f5285e8 JM |
3922 | if (!drv->has_capability) |
3923 | return -1; | |
3924 | os_memcpy(capa, &drv->capa, sizeof(*capa)); | |
3925 | return 0; | |
3926 | } | |
3927 | ||
3928 | ||
3929 | static int wpa_driver_nl80211_set_operstate(void *priv, int state) | |
3930 | { | |
a2e40bb6 FF |
3931 | struct i802_bss *bss = priv; |
3932 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
3f5285e8 JM |
3933 | |
3934 | wpa_printf(MSG_DEBUG, "%s: operstate %d->%d (%s)", | |
3935 | __func__, drv->operstate, state, state ? "UP" : "DORMANT"); | |
3936 | drv->operstate = state; | |
08063178 | 3937 | return netlink_send_oper_ifla(drv->netlink, drv->ifindex, -1, |
e2d02c29 | 3938 | state ? IF_OPER_UP : IF_OPER_DORMANT); |
3f5285e8 JM |
3939 | } |
3940 | ||
01652550 JM |
3941 | |
3942 | static int wpa_driver_nl80211_set_supp_port(void *priv, int authorized) | |
3943 | { | |
a2e40bb6 FF |
3944 | struct i802_bss *bss = priv; |
3945 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
01652550 JM |
3946 | struct nl_msg *msg; |
3947 | struct nl80211_sta_flag_update upd; | |
3948 | ||
3949 | msg = nlmsg_alloc(); | |
3950 | if (!msg) | |
3951 | return -ENOMEM; | |
3952 | ||
3953 | genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0, | |
3954 | 0, NL80211_CMD_SET_STATION, 0); | |
3955 | ||
3956 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, | |
a2e40bb6 | 3957 | if_nametoindex(bss->ifname)); |
01652550 JM |
3958 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, drv->bssid); |
3959 | ||
3960 | os_memset(&upd, 0, sizeof(upd)); | |
3961 | upd.mask = BIT(NL80211_STA_FLAG_AUTHORIZED); | |
3962 | if (authorized) | |
3963 | upd.set = BIT(NL80211_STA_FLAG_AUTHORIZED); | |
3964 | NLA_PUT(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd); | |
3965 | ||
3966 | return send_and_recv_msgs(drv, msg, NULL, NULL); | |
3967 | nla_put_failure: | |
3968 | return -ENOBUFS; | |
3969 | } | |
3970 | ||
3f5285e8 | 3971 | |
c5121837 JM |
3972 | #ifdef HOSTAPD |
3973 | ||
c5121837 JM |
3974 | static void add_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx) |
3975 | { | |
3976 | int i; | |
3977 | int *old; | |
3978 | ||
3979 | wpa_printf(MSG_DEBUG, "nl80211: Add own interface ifindex %d", | |
3980 | ifidx); | |
3981 | for (i = 0; i < drv->num_if_indices; i++) { | |
3982 | if (drv->if_indices[i] == 0) { | |
3983 | drv->if_indices[i] = ifidx; | |
3984 | return; | |
3985 | } | |
3986 | } | |
3987 | ||
3988 | if (drv->if_indices != drv->default_if_indices) | |
3989 | old = drv->if_indices; | |
3990 | else | |
3991 | old = NULL; | |
3992 | ||
7bf12757 JM |
3993 | drv->if_indices = os_realloc(old, |
3994 | sizeof(int) * (drv->num_if_indices + 1)); | |
c5121837 JM |
3995 | if (!drv->if_indices) { |
3996 | if (!old) | |
3997 | drv->if_indices = drv->default_if_indices; | |
3998 | else | |
3999 | drv->if_indices = old; | |
4000 | wpa_printf(MSG_ERROR, "Failed to reallocate memory for " | |
4001 | "interfaces"); | |
4002 | wpa_printf(MSG_ERROR, "Ignoring EAPOL on interface %d", ifidx); | |
4003 | return; | |
4004 | } | |
4005 | drv->if_indices[drv->num_if_indices] = ifidx; | |
4006 | drv->num_if_indices++; | |
4007 | } | |
4008 | ||
4009 | ||
4010 | static void del_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx) | |
4011 | { | |
4012 | int i; | |
4013 | ||
4014 | for (i = 0; i < drv->num_if_indices; i++) { | |
4015 | if (drv->if_indices[i] == ifidx) { | |
4016 | drv->if_indices[i] = 0; | |
4017 | break; | |
4018 | } | |
4019 | } | |
4020 | } | |
4021 | ||
4022 | ||
4023 | static int have_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx) | |
4024 | { | |
4025 | int i; | |
4026 | ||
4027 | for (i = 0; i < drv->num_if_indices; i++) | |
4028 | if (drv->if_indices[i] == ifidx) | |
4029 | return 1; | |
4030 | ||
4031 | return 0; | |
4032 | } | |
4033 | ||
4034 | ||
c5121837 JM |
4035 | static inline int min_int(int a, int b) |
4036 | { | |
4037 | if (a < b) | |
4038 | return a; | |
4039 | return b; | |
4040 | } | |
4041 | ||
4042 | ||
4043 | static int get_key_handler(struct nl_msg *msg, void *arg) | |
4044 | { | |
4045 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
4046 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
4047 | ||
4048 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
4049 | genlmsg_attrlen(gnlh, 0), NULL); | |
4050 | ||
4051 | /* | |
4052 | * TODO: validate the key index and mac address! | |
4053 | * Otherwise, there's a race condition as soon as | |
4054 | * the kernel starts sending key notifications. | |
4055 | */ | |
4056 | ||
4057 | if (tb[NL80211_ATTR_KEY_SEQ]) | |
4058 | memcpy(arg, nla_data(tb[NL80211_ATTR_KEY_SEQ]), | |
4059 | min_int(nla_len(tb[NL80211_ATTR_KEY_SEQ]), 6)); | |
4060 | return NL_SKIP; | |
4061 | } | |
4062 | ||
4063 | ||
4064 | static int i802_get_seqnum(const char *iface, void *priv, const u8 *addr, | |
4065 | int idx, u8 *seq) | |
4066 | { | |
a2e40bb6 FF |
4067 | struct i802_bss *bss = priv; |
4068 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
c5121837 JM |
4069 | struct nl_msg *msg; |
4070 | ||
4071 | msg = nlmsg_alloc(); | |
4072 | if (!msg) | |
4073 | return -ENOMEM; | |
4074 | ||
4075 | genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0, | |
4076 | 0, NL80211_CMD_GET_KEY, 0); | |
4077 | ||
4078 | if (addr) | |
4079 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); | |
4080 | NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, idx); | |
4081 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(iface)); | |
4082 | ||
4083 | memset(seq, 0, 6); | |
4084 | ||
4085 | return send_and_recv_msgs(drv, msg, get_key_handler, seq); | |
4086 | nla_put_failure: | |
4087 | return -ENOBUFS; | |
4088 | } | |
4089 | ||
4090 | ||
4091 | static int i802_set_rate_sets(void *priv, int *supp_rates, int *basic_rates, | |
4092 | int mode) | |
4093 | { | |
a2e40bb6 FF |
4094 | struct i802_bss *bss = priv; |
4095 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
c5121837 JM |
4096 | struct nl_msg *msg; |
4097 | u8 rates[NL80211_MAX_SUPP_RATES]; | |
4098 | u8 rates_len = 0; | |
4099 | int i; | |
4100 | ||
4101 | msg = nlmsg_alloc(); | |
4102 | if (!msg) | |
4103 | return -ENOMEM; | |
4104 | ||
4105 | genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0, 0, | |
4106 | NL80211_CMD_SET_BSS, 0); | |
4107 | ||
4108 | for (i = 0; i < NL80211_MAX_SUPP_RATES && basic_rates[i] >= 0; i++) | |
4109 | rates[rates_len++] = basic_rates[i] / 5; | |
4110 | ||
4111 | NLA_PUT(msg, NL80211_ATTR_BSS_BASIC_RATES, rates_len, rates); | |
4112 | ||
a2e40bb6 | 4113 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(bss->ifname)); |
c5121837 JM |
4114 | |
4115 | return send_and_recv_msgs(drv, msg, NULL, NULL); | |
4116 | nla_put_failure: | |
4117 | return -ENOBUFS; | |
4118 | } | |
4119 | ||
4120 | ||
c5121837 JM |
4121 | /* Set kernel driver on given frequency (MHz) */ |
4122 | static int i802_set_freq(void *priv, struct hostapd_freq_params *freq) | |
4123 | { | |
a2e40bb6 FF |
4124 | struct i802_bss *bss = priv; |
4125 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
f019981a JM |
4126 | return wpa_driver_nl80211_set_freq(drv, freq->freq, freq->ht_enabled, |
4127 | freq->sec_channel_offset); | |
c5121837 JM |
4128 | } |
4129 | ||
4130 | ||
4131 | static int i802_set_rts(void *priv, int rts) | |
4132 | { | |
a2e40bb6 FF |
4133 | struct i802_bss *bss = priv; |
4134 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
ad649451 JM |
4135 | struct nl_msg *msg; |
4136 | int ret = -ENOBUFS; | |
4137 | u32 val; | |
c5121837 | 4138 | |
ad649451 JM |
4139 | msg = nlmsg_alloc(); |
4140 | if (!msg) | |
4141 | return -ENOMEM; | |
c5121837 | 4142 | |
ad649451 JM |
4143 | if (rts >= 2347) |
4144 | val = (u32) -1; | |
4145 | else | |
4146 | val = rts; | |
c5121837 | 4147 | |
ad649451 JM |
4148 | genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0, |
4149 | 0, NL80211_CMD_SET_WIPHY, 0); | |
4150 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); | |
4151 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, val); | |
4152 | ||
4153 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
4154 | if (!ret) | |
4155 | return 0; | |
4156 | nla_put_failure: | |
4157 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set RTS threshold %d: " | |
4158 | "%d (%s)", rts, ret, strerror(-ret)); | |
4159 | return ret; | |
c5121837 JM |
4160 | } |
4161 | ||
4162 | ||
4163 | static int i802_set_frag(void *priv, int frag) | |
4164 | { | |
a2e40bb6 FF |
4165 | struct i802_bss *bss = priv; |
4166 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
ad649451 JM |
4167 | struct nl_msg *msg; |
4168 | int ret = -ENOBUFS; | |
4169 | u32 val; | |
c5121837 | 4170 | |
ad649451 JM |
4171 | msg = nlmsg_alloc(); |
4172 | if (!msg) | |
4173 | return -ENOMEM; | |
c5121837 | 4174 | |
ad649451 JM |
4175 | if (frag >= 2346) |
4176 | val = (u32) -1; | |
4177 | else | |
4178 | val = frag; | |
c5121837 | 4179 | |
ad649451 JM |
4180 | genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0, |
4181 | 0, NL80211_CMD_SET_WIPHY, 0); | |
4182 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); | |
4183 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, val); | |
4184 | ||
4185 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
4186 | if (!ret) | |
4187 | return 0; | |
4188 | nla_put_failure: | |
4189 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set fragmentation threshold " | |
4190 | "%d: %d (%s)", frag, ret, strerror(-ret)); | |
4191 | return ret; | |
c5121837 JM |
4192 | } |
4193 | ||
4194 | ||
c5121837 JM |
4195 | static int i802_flush(void *priv) |
4196 | { | |
a2e40bb6 FF |
4197 | struct i802_bss *bss = priv; |
4198 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
c5121837 JM |
4199 | struct nl_msg *msg; |
4200 | ||
4201 | msg = nlmsg_alloc(); | |
4202 | if (!msg) | |
4203 | return -1; | |
4204 | ||
4205 | genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0, | |
4206 | 0, NL80211_CMD_DEL_STATION, 0); | |
4207 | ||
4208 | /* | |
4209 | * XXX: FIX! this needs to flush all VLANs too | |
4210 | */ | |
4211 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, | |
a2e40bb6 | 4212 | if_nametoindex(bss->ifname)); |
c5121837 JM |
4213 | |
4214 | return send_and_recv_msgs(drv, msg, NULL, NULL); | |
4215 | nla_put_failure: | |
4216 | return -ENOBUFS; | |
4217 | } | |
4218 | ||
4219 | ||
4220 | static int get_sta_handler(struct nl_msg *msg, void *arg) | |
4221 | { | |
4222 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
4223 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
4224 | struct hostap_sta_driver_data *data = arg; | |
4225 | struct nlattr *stats[NL80211_STA_INFO_MAX + 1]; | |
4226 | static struct nla_policy stats_policy[NL80211_STA_INFO_MAX + 1] = { | |
4227 | [NL80211_STA_INFO_INACTIVE_TIME] = { .type = NLA_U32 }, | |
4228 | [NL80211_STA_INFO_RX_BYTES] = { .type = NLA_U32 }, | |
4229 | [NL80211_STA_INFO_TX_BYTES] = { .type = NLA_U32 }, | |
4230 | [NL80211_STA_INFO_RX_PACKETS] = { .type = NLA_U32 }, | |
4231 | [NL80211_STA_INFO_TX_PACKETS] = { .type = NLA_U32 }, | |
4232 | }; | |
4233 | ||
4234 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
4235 | genlmsg_attrlen(gnlh, 0), NULL); | |
4236 | ||
4237 | /* | |
4238 | * TODO: validate the interface and mac address! | |
4239 | * Otherwise, there's a race condition as soon as | |
4240 | * the kernel starts sending station notifications. | |
4241 | */ | |
4242 | ||
4243 | if (!tb[NL80211_ATTR_STA_INFO]) { | |
4244 | wpa_printf(MSG_DEBUG, "sta stats missing!"); | |
4245 | return NL_SKIP; | |
4246 | } | |
4247 | if (nla_parse_nested(stats, NL80211_STA_INFO_MAX, | |
4248 | tb[NL80211_ATTR_STA_INFO], | |
4249 | stats_policy)) { | |
4250 | wpa_printf(MSG_DEBUG, "failed to parse nested attributes!"); | |
4251 | return NL_SKIP; | |
4252 | } | |
4253 | ||
4254 | if (stats[NL80211_STA_INFO_INACTIVE_TIME]) | |
4255 | data->inactive_msec = | |
4256 | nla_get_u32(stats[NL80211_STA_INFO_INACTIVE_TIME]); | |
4257 | if (stats[NL80211_STA_INFO_RX_BYTES]) | |
4258 | data->rx_bytes = nla_get_u32(stats[NL80211_STA_INFO_RX_BYTES]); | |
4259 | if (stats[NL80211_STA_INFO_TX_BYTES]) | |
4260 | data->tx_bytes = nla_get_u32(stats[NL80211_STA_INFO_TX_BYTES]); | |
4261 | if (stats[NL80211_STA_INFO_RX_PACKETS]) | |
4262 | data->rx_packets = | |
4263 | nla_get_u32(stats[NL80211_STA_INFO_RX_PACKETS]); | |
4264 | if (stats[NL80211_STA_INFO_TX_PACKETS]) | |
4265 | data->tx_packets = | |
4266 | nla_get_u32(stats[NL80211_STA_INFO_TX_PACKETS]); | |
4267 | ||
4268 | return NL_SKIP; | |
4269 | } | |
4270 | ||
4271 | static int i802_read_sta_data(void *priv, struct hostap_sta_driver_data *data, | |
4272 | const u8 *addr) | |
4273 | { | |
a2e40bb6 FF |
4274 | struct i802_bss *bss = priv; |
4275 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
c5121837 JM |
4276 | struct nl_msg *msg; |
4277 | ||
4278 | os_memset(data, 0, sizeof(*data)); | |
4279 | msg = nlmsg_alloc(); | |
4280 | if (!msg) | |
4281 | return -ENOMEM; | |
4282 | ||
4283 | genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0, | |
4284 | 0, NL80211_CMD_GET_STATION, 0); | |
4285 | ||
4286 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); | |
a2e40bb6 | 4287 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(bss->ifname)); |
c5121837 JM |
4288 | |
4289 | return send_and_recv_msgs(drv, msg, get_sta_handler, data); | |
4290 | nla_put_failure: | |
4291 | return -ENOBUFS; | |
4292 | } | |
4293 | ||
4294 | ||
c5121837 JM |
4295 | static int i802_set_tx_queue_params(void *priv, int queue, int aifs, |
4296 | int cw_min, int cw_max, int burst_time) | |
4297 | { | |
a2e40bb6 FF |
4298 | struct i802_bss *bss = priv; |
4299 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
c5121837 JM |
4300 | struct nl_msg *msg; |
4301 | struct nlattr *txq, *params; | |
4302 | ||
4303 | msg = nlmsg_alloc(); | |
4304 | if (!msg) | |
4305 | return -1; | |
4306 | ||
4307 | genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0, | |
4308 | 0, NL80211_CMD_SET_WIPHY, 0); | |
4309 | ||
a2e40bb6 | 4310 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(bss->ifname)); |
c5121837 JM |
4311 | |
4312 | txq = nla_nest_start(msg, NL80211_ATTR_WIPHY_TXQ_PARAMS); | |
4313 | if (!txq) | |
4314 | goto nla_put_failure; | |
4315 | ||
4316 | /* We are only sending parameters for a single TXQ at a time */ | |
4317 | params = nla_nest_start(msg, 1); | |
4318 | if (!params) | |
4319 | goto nla_put_failure; | |
4320 | ||
4321 | NLA_PUT_U8(msg, NL80211_TXQ_ATTR_QUEUE, queue); | |
4322 | /* Burst time is configured in units of 0.1 msec and TXOP parameter in | |
4323 | * 32 usec, so need to convert the value here. */ | |
4324 | NLA_PUT_U16(msg, NL80211_TXQ_ATTR_TXOP, (burst_time * 100 + 16) / 32); | |
4325 | NLA_PUT_U16(msg, NL80211_TXQ_ATTR_CWMIN, cw_min); | |
4326 | NLA_PUT_U16(msg, NL80211_TXQ_ATTR_CWMAX, cw_max); | |
4327 | NLA_PUT_U8(msg, NL80211_TXQ_ATTR_AIFS, aifs); | |
4328 | ||
4329 | nla_nest_end(msg, params); | |
4330 | ||
4331 | nla_nest_end(msg, txq); | |
4332 | ||
4333 | if (send_and_recv_msgs(drv, msg, NULL, NULL) == 0) | |
4334 | return 0; | |
4335 | nla_put_failure: | |
4336 | return -1; | |
4337 | } | |
4338 | ||
4339 | ||
c5121837 JM |
4340 | static int i802_set_bss(void *priv, int cts, int preamble, int slot) |
4341 | { | |
a2e40bb6 FF |
4342 | struct i802_bss *bss = priv; |
4343 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
c5121837 JM |
4344 | struct nl_msg *msg; |
4345 | ||
4346 | msg = nlmsg_alloc(); | |
4347 | if (!msg) | |
4348 | return -ENOMEM; | |
4349 | ||
4350 | genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0, 0, | |
4351 | NL80211_CMD_SET_BSS, 0); | |
4352 | ||
4353 | if (cts >= 0) | |
4354 | NLA_PUT_U8(msg, NL80211_ATTR_BSS_CTS_PROT, cts); | |
4355 | if (preamble >= 0) | |
4356 | NLA_PUT_U8(msg, NL80211_ATTR_BSS_SHORT_PREAMBLE, preamble); | |
4357 | if (slot >= 0) | |
4358 | NLA_PUT_U8(msg, NL80211_ATTR_BSS_SHORT_SLOT_TIME, slot); | |
4359 | ||
a2e40bb6 | 4360 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(bss->ifname)); |
c5121837 JM |
4361 | |
4362 | return send_and_recv_msgs(drv, msg, NULL, NULL); | |
4363 | nla_put_failure: | |
4364 | return -ENOBUFS; | |
4365 | } | |
4366 | ||
4367 | ||
4368 | static int i802_set_cts_protect(void *priv, int value) | |
4369 | { | |
4370 | return i802_set_bss(priv, value, -1, -1); | |
4371 | } | |
4372 | ||
4373 | ||
4374 | static int i802_set_preamble(void *priv, int value) | |
4375 | { | |
4376 | return i802_set_bss(priv, -1, value, -1); | |
4377 | } | |
4378 | ||
4379 | ||
4380 | static int i802_set_short_slot_time(void *priv, int value) | |
4381 | { | |
4382 | return i802_set_bss(priv, -1, -1, value); | |
4383 | } | |
4384 | ||
4385 | ||
c5121837 JM |
4386 | static int i802_set_sta_vlan(void *priv, const u8 *addr, |
4387 | const char *ifname, int vlan_id) | |
4388 | { | |
a2e40bb6 FF |
4389 | struct i802_bss *bss = priv; |
4390 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
c5121837 JM |
4391 | struct nl_msg *msg; |
4392 | ||
4393 | msg = nlmsg_alloc(); | |
4394 | if (!msg) | |
4395 | return -ENOMEM; | |
4396 | ||
4397 | genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0, | |
4398 | 0, NL80211_CMD_SET_STATION, 0); | |
4399 | ||
4400 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, | |
a2e40bb6 | 4401 | if_nametoindex(bss->ifname)); |
c5121837 | 4402 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); |
1c766b09 | 4403 | NLA_PUT_U32(msg, NL80211_ATTR_STA_VLAN, |
c5121837 JM |
4404 | if_nametoindex(ifname)); |
4405 | ||
4406 | return send_and_recv_msgs(drv, msg, NULL, NULL); | |
4407 | nla_put_failure: | |
4408 | return -ENOBUFS; | |
4409 | } | |
4410 | ||
4411 | ||
fbbfcbac FF |
4412 | static int i802_set_wds_sta(void *priv, const u8 *addr, int aid, int val) |
4413 | { | |
a2e40bb6 FF |
4414 | struct i802_bss *bss = priv; |
4415 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
e748062b | 4416 | char name[IFNAMSIZ + 1]; |
fbbfcbac | 4417 | |
a2e40bb6 | 4418 | os_snprintf(name, sizeof(name), "%s.sta%d", bss->ifname, aid); |
e748062b JM |
4419 | wpa_printf(MSG_DEBUG, "nl80211: Set WDS STA addr=" MACSTR |
4420 | " aid=%d val=%d name=%s", MAC2STR(addr), aid, val, name); | |
fbbfcbac | 4421 | if (val) { |
a2e40bb6 | 4422 | if (nl80211_create_iface(drv, name, NL80211_IFTYPE_AP_VLAN, |
fbbfcbac FF |
4423 | NULL, 1) < 0) |
4424 | return -1; | |
34f2f814 | 4425 | linux_set_iface_flags(drv->ioctl_sock, name, 1); |
fbbfcbac FF |
4426 | return i802_set_sta_vlan(priv, addr, name, 0); |
4427 | } else { | |
a2e40bb6 | 4428 | i802_set_sta_vlan(priv, addr, bss->ifname, 0); |
fbbfcbac FF |
4429 | return wpa_driver_nl80211_if_remove(priv, WPA_IF_AP_VLAN, |
4430 | name); | |
4431 | } | |
4432 | } | |
4433 | ||
4434 | ||
c5121837 JM |
4435 | static void handle_eapol(int sock, void *eloop_ctx, void *sock_ctx) |
4436 | { | |
4437 | struct wpa_driver_nl80211_data *drv = eloop_ctx; | |
4438 | struct sockaddr_ll lladdr; | |
4439 | unsigned char buf[3000]; | |
4440 | int len; | |
4441 | socklen_t fromlen = sizeof(lladdr); | |
4442 | ||
4443 | len = recvfrom(sock, buf, sizeof(buf), 0, | |
4444 | (struct sockaddr *)&lladdr, &fromlen); | |
4445 | if (len < 0) { | |
4446 | perror("recv"); | |
4447 | return; | |
4448 | } | |
4449 | ||
baac6490 JM |
4450 | if (have_ifidx(drv, lladdr.sll_ifindex)) |
4451 | drv_event_eapol_rx(drv->ctx, lladdr.sll_addr, buf, len); | |
c5121837 JM |
4452 | } |
4453 | ||
4454 | ||
c5121837 JM |
4455 | static int i802_get_inact_sec(void *priv, const u8 *addr) |
4456 | { | |
4457 | struct hostap_sta_driver_data data; | |
4458 | int ret; | |
4459 | ||
4460 | data.inactive_msec = (unsigned long) -1; | |
4461 | ret = i802_read_sta_data(priv, &data, addr); | |
4462 | if (ret || data.inactive_msec == (unsigned long) -1) | |
4463 | return -1; | |
4464 | return data.inactive_msec / 1000; | |
4465 | } | |
4466 | ||
4467 | ||
4468 | static int i802_sta_clear_stats(void *priv, const u8 *addr) | |
4469 | { | |
4470 | #if 0 | |
4471 | /* TODO */ | |
4472 | #endif | |
4473 | return 0; | |
4474 | } | |
4475 | ||
4476 | ||
731723a5 JM |
4477 | static int i802_sta_deauth(void *priv, const u8 *own_addr, const u8 *addr, |
4478 | int reason) | |
c5121837 | 4479 | { |
a2e40bb6 | 4480 | struct i802_bss *bss = priv; |
c5121837 JM |
4481 | struct ieee80211_mgmt mgmt; |
4482 | ||
4483 | memset(&mgmt, 0, sizeof(mgmt)); | |
4484 | mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, | |
4485 | WLAN_FC_STYPE_DEAUTH); | |
4486 | memcpy(mgmt.da, addr, ETH_ALEN); | |
731723a5 JM |
4487 | memcpy(mgmt.sa, own_addr, ETH_ALEN); |
4488 | memcpy(mgmt.bssid, own_addr, ETH_ALEN); | |
c5121837 | 4489 | mgmt.u.deauth.reason_code = host_to_le16(reason); |
a2e40bb6 | 4490 | return wpa_driver_nl80211_send_mlme(bss, (u8 *) &mgmt, |
9f324b61 JM |
4491 | IEEE80211_HDRLEN + |
4492 | sizeof(mgmt.u.deauth)); | |
c5121837 JM |
4493 | } |
4494 | ||
4495 | ||
731723a5 JM |
4496 | static int i802_sta_disassoc(void *priv, const u8 *own_addr, const u8 *addr, |
4497 | int reason) | |
c5121837 | 4498 | { |
a2e40bb6 | 4499 | struct i802_bss *bss = priv; |
c5121837 JM |
4500 | struct ieee80211_mgmt mgmt; |
4501 | ||
4502 | memset(&mgmt, 0, sizeof(mgmt)); | |
4503 | mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, | |
4504 | WLAN_FC_STYPE_DISASSOC); | |
4505 | memcpy(mgmt.da, addr, ETH_ALEN); | |
731723a5 JM |
4506 | memcpy(mgmt.sa, own_addr, ETH_ALEN); |
4507 | memcpy(mgmt.bssid, own_addr, ETH_ALEN); | |
c5121837 | 4508 | mgmt.u.disassoc.reason_code = host_to_le16(reason); |
a2e40bb6 | 4509 | return wpa_driver_nl80211_send_mlme(bss, (u8 *) &mgmt, |
9f324b61 JM |
4510 | IEEE80211_HDRLEN + |
4511 | sizeof(mgmt.u.disassoc)); | |
c5121837 JM |
4512 | } |
4513 | ||
4514 | ||
94627f6c JM |
4515 | static int i802_check_bridge(struct wpa_driver_nl80211_data *drv, |
4516 | const char *brname, const char *ifname) | |
4517 | { | |
4518 | int ifindex; | |
4519 | char in_br[IFNAMSIZ]; | |
4520 | ||
4521 | os_strlcpy(drv->brname, brname, IFNAMSIZ); | |
4522 | ifindex = if_nametoindex(brname); | |
4523 | if (ifindex == 0) { | |
4524 | /* | |
4525 | * Bridge was configured, but the bridge device does | |
4526 | * not exist. Try to add it now. | |
4527 | */ | |
4528 | if (linux_br_add(drv->ioctl_sock, brname) < 0) { | |
4529 | wpa_printf(MSG_ERROR, "nl80211: Failed to add the " | |
4530 | "bridge interface %s: %s", | |
4531 | brname, strerror(errno)); | |
4532 | return -1; | |
4533 | } | |
4534 | drv->added_bridge = 1; | |
4535 | add_ifidx(drv, if_nametoindex(brname)); | |
4536 | } | |
4537 | ||
4538 | if (linux_br_get(in_br, ifname) == 0) { | |
4539 | if (os_strcmp(in_br, brname) == 0) | |
4540 | return 0; /* already in the bridge */ | |
4541 | ||
4542 | wpa_printf(MSG_DEBUG, "nl80211: Removing interface %s from " | |
4543 | "bridge %s", ifname, in_br); | |
4544 | if (linux_br_del_if(drv->ioctl_sock, in_br, ifname) < 0) { | |
4545 | wpa_printf(MSG_ERROR, "nl80211: Failed to " | |
4546 | "remove interface %s from bridge " | |
4547 | "%s: %s", | |
4548 | ifname, brname, strerror(errno)); | |
4549 | return -1; | |
4550 | } | |
4551 | } | |
4552 | ||
4553 | wpa_printf(MSG_DEBUG, "nl80211: Adding interface %s into bridge %s", | |
4554 | ifname, brname); | |
4555 | if (linux_br_add_if(drv->ioctl_sock, brname, ifname) < 0) { | |
4556 | wpa_printf(MSG_ERROR, "nl80211: Failed to add interface %s " | |
4557 | "into bridge %s: %s", | |
4558 | ifname, brname, strerror(errno)); | |
4559 | return -1; | |
4560 | } | |
4561 | drv->added_if_into_bridge = 1; | |
4562 | ||
4563 | return 0; | |
4564 | } | |
4565 | ||
4566 | ||
92f475b4 JM |
4567 | static void *i802_init(struct hostapd_data *hapd, |
4568 | struct wpa_init_params *params) | |
c5121837 JM |
4569 | { |
4570 | struct wpa_driver_nl80211_data *drv; | |
a2e40bb6 | 4571 | struct i802_bss *bss; |
c5121837 | 4572 | size_t i; |
94627f6c JM |
4573 | char brname[IFNAMSIZ]; |
4574 | int ifindex, br_ifindex; | |
4575 | int br_added = 0; | |
c5121837 | 4576 | |
a2e40bb6 FF |
4577 | bss = wpa_driver_nl80211_init(hapd, params->ifname); |
4578 | if (bss == NULL) | |
c5121837 | 4579 | return NULL; |
c5121837 | 4580 | |
a2e40bb6 | 4581 | drv = bss->drv; |
94627f6c JM |
4582 | if (linux_br_get(brname, params->ifname) == 0) { |
4583 | wpa_printf(MSG_DEBUG, "nl80211: Interface %s is in bridge %s", | |
4584 | params->ifname, brname); | |
4585 | br_ifindex = if_nametoindex(brname); | |
4586 | } else { | |
4587 | brname[0] = '\0'; | |
4588 | br_ifindex = 0; | |
4589 | } | |
4590 | ||
c5121837 JM |
4591 | drv->num_if_indices = sizeof(drv->default_if_indices) / sizeof(int); |
4592 | drv->if_indices = drv->default_if_indices; | |
92f475b4 | 4593 | for (i = 0; i < params->num_bridge; i++) { |
94627f6c JM |
4594 | if (params->bridge[i]) { |
4595 | ifindex = if_nametoindex(params->bridge[i]); | |
4596 | if (ifindex) | |
4597 | add_ifidx(drv, ifindex); | |
4598 | if (ifindex == br_ifindex) | |
4599 | br_added = 1; | |
4600 | } | |
c5121837 | 4601 | } |
94627f6c JM |
4602 | if (!br_added && br_ifindex && |
4603 | (params->num_bridge == 0 || !params->bridge[0])) | |
4604 | add_ifidx(drv, br_ifindex); | |
c5121837 | 4605 | |
ad1e68e6 JM |
4606 | /* start listening for EAPOL on the default AP interface */ |
4607 | add_ifidx(drv, drv->ifindex); | |
4608 | ||
a2e40bb6 | 4609 | if (linux_set_iface_flags(drv->ioctl_sock, bss->ifname, 0)) |
6980c191 | 4610 | goto failed; |
ad1e68e6 | 4611 | |
6980c191 | 4612 | if (params->bssid) { |
a2e40bb6 | 4613 | if (linux_set_ifhwaddr(drv->ioctl_sock, bss->ifname, |
2ac9688e | 4614 | params->bssid)) |
460456f8 JM |
4615 | goto failed; |
4616 | } | |
ad1e68e6 | 4617 | |
a2e40bb6 | 4618 | if (wpa_driver_nl80211_set_mode(bss, IEEE80211_MODE_AP)) { |
ad1e68e6 | 4619 | wpa_printf(MSG_ERROR, "nl80211: Failed to set interface %s " |
a2e40bb6 | 4620 | "into AP mode", bss->ifname); |
bbaf0837 | 4621 | goto failed; |
ad1e68e6 JM |
4622 | } |
4623 | ||
94627f6c JM |
4624 | if (params->num_bridge && params->bridge[0] && |
4625 | i802_check_bridge(drv, params->bridge[0], params->ifname) < 0) | |
4626 | goto failed; | |
4627 | ||
a2e40bb6 | 4628 | if (linux_set_iface_flags(drv->ioctl_sock, bss->ifname, 1)) |
bbaf0837 | 4629 | goto failed; |
ad1e68e6 JM |
4630 | |
4631 | drv->eapol_sock = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_PAE)); | |
4632 | if (drv->eapol_sock < 0) { | |
4633 | perror("socket(PF_PACKET, SOCK_DGRAM, ETH_P_PAE)"); | |
bbaf0837 | 4634 | goto failed; |
ad1e68e6 JM |
4635 | } |
4636 | ||
4637 | if (eloop_register_read_sock(drv->eapol_sock, handle_eapol, drv, NULL)) | |
4638 | { | |
4639 | printf("Could not register read socket for eapol\n"); | |
c5121837 | 4640 | goto failed; |
ad1e68e6 JM |
4641 | } |
4642 | ||
a2e40bb6 | 4643 | if (linux_get_ifhwaddr(drv->ioctl_sock, bss->ifname, params->own_addr)) |
bbaf0837 | 4644 | goto failed; |
c5121837 | 4645 | |
a2e40bb6 | 4646 | return bss; |
c5121837 JM |
4647 | |
4648 | failed: | |
460456f8 | 4649 | nl80211_remove_monitor_interface(drv); |
c5121837 JM |
4650 | if (drv->ioctl_sock >= 0) |
4651 | close(drv->ioctl_sock); | |
c5121837 JM |
4652 | |
4653 | genl_family_put(drv->nl80211); | |
4654 | nl_cache_free(drv->nl_cache); | |
4655 | nl_handle_destroy(drv->nl_handle); | |
4656 | nl_cb_put(drv->nl_cb); | |
4657 | ||
bbaf0837 JM |
4658 | os_free(drv); |
4659 | return NULL; | |
4660 | } | |
c5121837 | 4661 | |
c5121837 | 4662 | |
bbaf0837 JM |
4663 | static void i802_deinit(void *priv) |
4664 | { | |
4665 | wpa_driver_nl80211_deinit(priv); | |
c5121837 JM |
4666 | } |
4667 | ||
4668 | #endif /* HOSTAPD */ | |
4669 | ||
4670 | ||
22a7c9d7 JM |
4671 | static enum nl80211_iftype wpa_driver_nl80211_if_type( |
4672 | enum wpa_driver_if_type type) | |
4673 | { | |
4674 | switch (type) { | |
4675 | case WPA_IF_STATION: | |
4676 | return NL80211_IFTYPE_STATION; | |
4677 | case WPA_IF_AP_VLAN: | |
4678 | return NL80211_IFTYPE_AP_VLAN; | |
4679 | case WPA_IF_AP_BSS: | |
4680 | return NL80211_IFTYPE_AP; | |
4681 | } | |
4682 | return -1; | |
4683 | } | |
4684 | ||
4685 | ||
7ab68865 | 4686 | static int wpa_driver_nl80211_if_add(void *priv, enum wpa_driver_if_type type, |
8043e725 | 4687 | const char *ifname, const u8 *addr, |
a2e40bb6 | 4688 | void *bss_ctx, void **drv_priv) |
22a7c9d7 | 4689 | { |
a2e40bb6 FF |
4690 | struct i802_bss *bss = priv; |
4691 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
22a7c9d7 JM |
4692 | int ifidx; |
4693 | #ifdef HOSTAPD | |
a2e40bb6 | 4694 | struct i802_bss *new_bss = NULL; |
22a7c9d7 JM |
4695 | |
4696 | if (type == WPA_IF_AP_BSS) { | |
a2e40bb6 FF |
4697 | new_bss = os_zalloc(sizeof(*new_bss)); |
4698 | if (new_bss == NULL) | |
22a7c9d7 JM |
4699 | return -1; |
4700 | } | |
4701 | #endif /* HOSTAPD */ | |
4702 | ||
4703 | ifidx = nl80211_create_iface(drv, ifname, | |
fbbfcbac FF |
4704 | wpa_driver_nl80211_if_type(type), addr, |
4705 | 0); | |
22a7c9d7 JM |
4706 | if (ifidx < 0) { |
4707 | #ifdef HOSTAPD | |
a2e40bb6 | 4708 | os_free(new_bss); |
22a7c9d7 JM |
4709 | #endif /* HOSTAPD */ |
4710 | return -1; | |
4711 | } | |
4712 | ||
4713 | #ifdef HOSTAPD | |
4714 | if (type == WPA_IF_AP_BSS) { | |
34f2f814 JM |
4715 | if (linux_set_iface_flags(drv->ioctl_sock, ifname, 1)) { |
4716 | nl80211_remove_iface(drv, ifidx); | |
07179987 | 4717 | os_free(new_bss); |
22a7c9d7 JM |
4718 | return -1; |
4719 | } | |
a2e40bb6 FF |
4720 | os_strlcpy(new_bss->ifname, ifname, IFNAMSIZ); |
4721 | new_bss->ifindex = ifidx; | |
4722 | new_bss->drv = drv; | |
4723 | new_bss->next = drv->first_bss.next; | |
4724 | drv->first_bss.next = new_bss; | |
4725 | if (drv_priv) | |
4726 | *drv_priv = new_bss; | |
22a7c9d7 JM |
4727 | } |
4728 | #endif /* HOSTAPD */ | |
4729 | ||
4730 | return 0; | |
4731 | } | |
4732 | ||
4733 | ||
4734 | static int wpa_driver_nl80211_if_remove(void *priv, | |
4735 | enum wpa_driver_if_type type, | |
4736 | const char *ifname) | |
4737 | { | |
a2e40bb6 FF |
4738 | struct i802_bss *bss = priv; |
4739 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
22a7c9d7 JM |
4740 | int ifindex = if_nametoindex(ifname); |
4741 | ||
e748062b JM |
4742 | wpa_printf(MSG_DEBUG, "nl80211: %s(type=%d ifname=%s) ifindex=%d", |
4743 | __func__, type, ifname, ifindex); | |
4744 | if (ifindex <= 0) | |
4745 | return -1; | |
22a7c9d7 JM |
4746 | nl80211_remove_iface(drv, ifindex); |
4747 | ||
4748 | #ifdef HOSTAPD | |
a2e40bb6 FF |
4749 | if (type != WPA_IF_AP_BSS) |
4750 | return 0; | |
4751 | ||
4752 | if (bss != &drv->first_bss) { | |
4753 | struct i802_bss *tbss = &drv->first_bss; | |
4754 | ||
4755 | while (tbss) { | |
4756 | if (tbss->next != bss) | |
4757 | continue; | |
4758 | ||
4759 | tbss->next = bss->next; | |
4760 | os_free(bss); | |
4761 | break; | |
22a7c9d7 JM |
4762 | } |
4763 | } | |
4764 | #endif /* HOSTAPD */ | |
4765 | ||
4766 | return 0; | |
4767 | } | |
4768 | ||
4769 | ||
55777702 JM |
4770 | static int cookie_handler(struct nl_msg *msg, void *arg) |
4771 | { | |
4772 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
4773 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
4774 | u64 *cookie = arg; | |
4775 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
4776 | genlmsg_attrlen(gnlh, 0), NULL); | |
4777 | if (tb[NL80211_ATTR_COOKIE]) | |
4778 | *cookie = nla_get_u64(tb[NL80211_ATTR_COOKIE]); | |
4779 | return NL_SKIP; | |
4780 | } | |
4781 | ||
4782 | ||
58f6fbe0 JM |
4783 | static int wpa_driver_nl80211_send_action(void *priv, unsigned int freq, |
4784 | const u8 *dst, const u8 *src, | |
4785 | const u8 *bssid, | |
4786 | const u8 *data, size_t data_len) | |
4787 | { | |
a2e40bb6 FF |
4788 | struct i802_bss *bss = priv; |
4789 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
58f6fbe0 JM |
4790 | int ret = -1; |
4791 | struct nl_msg *msg; | |
4792 | u8 *buf; | |
4793 | struct ieee80211_hdr *hdr; | |
4794 | u64 cookie; | |
4795 | ||
4796 | wpa_printf(MSG_DEBUG, "nl80211: Send Action frame (ifindex=%d)", | |
4797 | drv->ifindex); | |
4798 | ||
4799 | buf = os_zalloc(24 + data_len); | |
4800 | if (buf == NULL) | |
4801 | return ret; | |
4802 | os_memcpy(buf + 24, data, data_len); | |
4803 | hdr = (struct ieee80211_hdr *) buf; | |
4804 | hdr->frame_control = | |
4805 | IEEE80211_FC(WLAN_FC_TYPE_MGMT, WLAN_FC_STYPE_ACTION); | |
4806 | os_memcpy(hdr->addr1, dst, ETH_ALEN); | |
4807 | os_memcpy(hdr->addr2, src, ETH_ALEN); | |
4808 | os_memcpy(hdr->addr3, bssid, ETH_ALEN); | |
4809 | ||
4810 | if (drv->nlmode == NL80211_IFTYPE_AP) { | |
4811 | ret = wpa_driver_nl80211_send_mlme(priv, buf, 24 + data_len); | |
4812 | os_free(buf); | |
4813 | return ret; | |
4814 | } | |
4815 | ||
4816 | msg = nlmsg_alloc(); | |
4817 | if (!msg) | |
4818 | return -1; | |
4819 | ||
4820 | genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0, 0, | |
4821 | NL80211_CMD_ACTION, 0); | |
4822 | ||
4823 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); | |
4824 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, freq); | |
4825 | NLA_PUT(msg, NL80211_ATTR_FRAME, 24 + data_len, buf); | |
4826 | os_free(buf); | |
4827 | ||
4828 | cookie = 0; | |
4829 | ret = send_and_recv_msgs(drv, msg, cookie_handler, &cookie); | |
4830 | msg = NULL; | |
4831 | if (ret) { | |
4832 | wpa_printf(MSG_DEBUG, "nl80211: Action command failed: ret=%d " | |
4833 | "(%s)", ret, strerror(-ret)); | |
4834 | goto nla_put_failure; | |
4835 | } | |
4836 | wpa_printf(MSG_DEBUG, "nl80211: Action TX command accepted; " | |
4837 | "cookie 0x%llx", (long long unsigned int) cookie); | |
4838 | drv->send_action_cookie = cookie; | |
4839 | drv->pending_send_action = 1; | |
4840 | ret = 0; | |
4841 | ||
4842 | nla_put_failure: | |
4843 | nlmsg_free(msg); | |
4844 | return ret; | |
4845 | } | |
4846 | ||
4847 | ||
55777702 JM |
4848 | static int wpa_driver_nl80211_remain_on_channel(void *priv, unsigned int freq, |
4849 | unsigned int duration) | |
4850 | { | |
a2e40bb6 FF |
4851 | struct i802_bss *bss = priv; |
4852 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
55777702 JM |
4853 | struct nl_msg *msg; |
4854 | int ret; | |
4855 | u64 cookie; | |
4856 | ||
4857 | msg = nlmsg_alloc(); | |
4858 | if (!msg) | |
4859 | return -1; | |
4860 | ||
4861 | genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0, 0, | |
4862 | NL80211_CMD_REMAIN_ON_CHANNEL, 0); | |
4863 | ||
4864 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); | |
4865 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, freq); | |
4866 | NLA_PUT_U32(msg, NL80211_ATTR_DURATION, duration); | |
4867 | ||
4868 | cookie = 0; | |
4869 | ret = send_and_recv_msgs(drv, msg, cookie_handler, &cookie); | |
4870 | if (ret == 0) { | |
4871 | wpa_printf(MSG_DEBUG, "nl80211: Remain-on-channel cookie " | |
4872 | "0x%llx for freq=%u MHz duration=%u", | |
4873 | (long long unsigned int) cookie, freq, duration); | |
4874 | drv->remain_on_chan_cookie = cookie; | |
4875 | return 0; | |
4876 | } | |
4877 | wpa_printf(MSG_DEBUG, "nl80211: Failed to request remain-on-channel " | |
4878 | "(freq=%d): %d (%s)", freq, ret, strerror(-ret)); | |
4879 | nla_put_failure: | |
4880 | return -1; | |
4881 | } | |
4882 | ||
4883 | ||
4884 | static int wpa_driver_nl80211_cancel_remain_on_channel(void *priv) | |
4885 | { | |
a2e40bb6 FF |
4886 | struct i802_bss *bss = priv; |
4887 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
55777702 JM |
4888 | struct nl_msg *msg; |
4889 | int ret; | |
4890 | ||
4891 | if (!drv->pending_remain_on_chan) { | |
4892 | wpa_printf(MSG_DEBUG, "nl80211: No pending remain-on-channel " | |
4893 | "to cancel"); | |
4894 | return -1; | |
4895 | } | |
4896 | ||
4897 | wpa_printf(MSG_DEBUG, "nl80211: Cancel remain-on-channel with cookie " | |
4898 | "0x%llx", | |
4899 | (long long unsigned int) drv->remain_on_chan_cookie); | |
4900 | ||
4901 | msg = nlmsg_alloc(); | |
4902 | if (!msg) | |
4903 | return -1; | |
4904 | ||
4905 | genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0, 0, | |
4906 | NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, 0); | |
4907 | ||
4908 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); | |
4909 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, drv->remain_on_chan_cookie); | |
4910 | ||
4911 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
4912 | if (ret == 0) | |
4913 | return 0; | |
4914 | wpa_printf(MSG_DEBUG, "nl80211: Failed to cancel remain-on-channel: " | |
4915 | "%d (%s)", ret, strerror(-ret)); | |
4916 | nla_put_failure: | |
4917 | return -1; | |
4918 | } | |
4919 | ||
4920 | ||
504e905c JM |
4921 | static void wpa_driver_nl80211_probe_req_report_timeout(void *eloop_ctx, |
4922 | void *timeout_ctx) | |
4923 | { | |
4924 | struct wpa_driver_nl80211_data *drv = eloop_ctx; | |
4925 | if (drv->monitor_ifidx < 0) | |
4926 | return; /* monitor interface already removed */ | |
4927 | ||
4928 | if (drv->nlmode != NL80211_IFTYPE_STATION) | |
4929 | return; /* not in station mode anymore */ | |
4930 | ||
4931 | if (drv->probe_req_report) | |
4932 | return; /* reporting enabled */ | |
4933 | ||
4934 | wpa_printf(MSG_DEBUG, "nl80211: Remove monitor interface due to no " | |
4935 | "Probe Request reporting needed anymore"); | |
4936 | nl80211_remove_monitor_interface(drv); | |
4937 | } | |
4938 | ||
4939 | ||
4940 | static int wpa_driver_nl80211_probe_req_report(void *priv, int report) | |
4941 | { | |
a2e40bb6 FF |
4942 | struct i802_bss *bss = priv; |
4943 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
504e905c JM |
4944 | |
4945 | if (drv->nlmode != NL80211_IFTYPE_STATION) { | |
4946 | wpa_printf(MSG_DEBUG, "nl80211: probe_req_report control only " | |
4947 | "allowed in station mode (iftype=%d)", | |
4948 | drv->nlmode); | |
4949 | return -1; | |
4950 | } | |
4951 | drv->probe_req_report = report; | |
4952 | ||
4953 | if (report) { | |
4954 | eloop_cancel_timeout( | |
4955 | wpa_driver_nl80211_probe_req_report_timeout, | |
4956 | drv, NULL); | |
4957 | if (drv->monitor_ifidx < 0 && | |
4958 | nl80211_create_monitor_interface(drv)) | |
4959 | return -1; | |
4960 | } else { | |
4961 | /* | |
4962 | * It takes a while to remove the monitor interface, so try to | |
4963 | * avoid doing this if it is needed again shortly. Instead, | |
4964 | * schedule the interface to be removed later if no need for it | |
4965 | * is seen. | |
4966 | */ | |
4967 | wpa_printf(MSG_DEBUG, "nl80211: Scheduling monitor interface " | |
4968 | "to be removed after 10 seconds of no use"); | |
4969 | eloop_register_timeout( | |
4970 | 10, 0, wpa_driver_nl80211_probe_req_report_timeout, | |
4971 | drv, NULL); | |
4972 | } | |
4973 | ||
4974 | return 0; | |
4975 | } | |
4976 | ||
4977 | ||
b7a2b0b6 JM |
4978 | static int wpa_driver_nl80211_alloc_interface_addr(void *priv, u8 *addr, |
4979 | char *ifname) | |
7bfc47c3 | 4980 | { |
a2e40bb6 FF |
4981 | struct i802_bss *bss = priv; |
4982 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
7bfc47c3 | 4983 | |
b7a2b0b6 JM |
4984 | if (ifname) |
4985 | ifname[0] = '\0'; | |
4986 | ||
a2e40bb6 | 4987 | if (linux_get_ifhwaddr(drv->ioctl_sock, bss->ifname, addr) < 0) |
7bfc47c3 JM |
4988 | return -1; |
4989 | ||
4990 | if (addr[0] & 0x02) { | |
4991 | /* TODO: add support for generating multiple addresses */ | |
4992 | addr[0] ^= 0x80; | |
4993 | } else | |
4994 | addr[0] = 0x02; /* locally administered */ | |
4995 | ||
4996 | return 0; | |
4997 | } | |
4998 | ||
4999 | ||
5000 | static void wpa_driver_nl80211_release_interface_addr(void *priv, | |
5001 | const u8 *addr) | |
5002 | { | |
5003 | /* TODO: keep list of allocated address and release them here */ | |
5004 | } | |
5005 | ||
5006 | ||
4e5cb1a3 JM |
5007 | static int nl80211_disable_11b_rates(struct wpa_driver_nl80211_data *drv, |
5008 | int ifindex, int disabled) | |
5009 | { | |
5010 | struct nl_msg *msg; | |
5011 | struct nlattr *bands, *band; | |
5012 | int ret; | |
5013 | ||
5014 | msg = nlmsg_alloc(); | |
5015 | if (!msg) | |
5016 | return -1; | |
5017 | ||
5018 | genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0, 0, | |
5019 | NL80211_CMD_SET_TX_BITRATE_MASK, 0); | |
5020 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, ifindex); | |
5021 | ||
5022 | bands = nla_nest_start(msg, NL80211_ATTR_TX_RATES); | |
5023 | if (!bands) | |
5024 | goto nla_put_failure; | |
5025 | ||
5026 | /* | |
5027 | * Disable 2 GHz rates 1, 2, 5.5, 11 Mbps by masking out everything | |
5028 | * else apart from 6, 9, 12, 18, 24, 36, 48, 54 Mbps from non-MCS | |
5029 | * rates. All 5 GHz rates are left enabled. | |
5030 | */ | |
5031 | band = nla_nest_start(msg, NL80211_BAND_2GHZ); | |
5032 | if (!band) | |
5033 | goto nla_put_failure; | |
5034 | NLA_PUT(msg, NL80211_TXRATE_LEGACY, 8, | |
5035 | "\x0c\x12\x18\x24\x30\x48\x60\x6c"); | |
5036 | nla_nest_end(msg, band); | |
5037 | ||
5038 | nla_nest_end(msg, bands); | |
5039 | ||
5040 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
5041 | msg = NULL; | |
5042 | if (ret) { | |
5043 | wpa_printf(MSG_DEBUG, "nl80211: Set TX rates failed: ret=%d " | |
5044 | "(%s)", ret, strerror(-ret)); | |
5045 | } | |
5046 | ||
5047 | return ret; | |
5048 | ||
5049 | nla_put_failure: | |
5050 | nlmsg_free(msg); | |
5051 | return -1; | |
5052 | } | |
5053 | ||
5054 | ||
5055 | static int wpa_driver_nl80211_disable_11b_rates(void *priv, int disabled) | |
5056 | { | |
a2e40bb6 FF |
5057 | struct i802_bss *bss = priv; |
5058 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
4e5cb1a3 JM |
5059 | drv->disable_11b_rates = disabled; |
5060 | return nl80211_disable_11b_rates(drv, drv->ifindex, disabled); | |
5061 | } | |
5062 | ||
5063 | ||
af473088 JM |
5064 | static int wpa_driver_nl80211_deinit_ap(void *priv) |
5065 | { | |
a2e40bb6 FF |
5066 | struct i802_bss *bss = priv; |
5067 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
af473088 JM |
5068 | if (drv->nlmode != NL80211_IFTYPE_AP) |
5069 | return -1; | |
5070 | wpa_driver_nl80211_del_beacon(drv); | |
a2e40bb6 | 5071 | return wpa_driver_nl80211_set_mode(priv, IEEE80211_MODE_INFRA); |
af473088 JM |
5072 | } |
5073 | ||
5074 | ||
207ef3fb JM |
5075 | static void wpa_driver_nl80211_resume(void *priv) |
5076 | { | |
a2e40bb6 FF |
5077 | struct i802_bss *bss = priv; |
5078 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
5079 | if (linux_set_iface_flags(drv->ioctl_sock, bss->ifname, 1)) { | |
207ef3fb JM |
5080 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set interface up on " |
5081 | "resume event"); | |
5082 | } | |
5083 | } | |
5084 | ||
5085 | ||
3f5285e8 JM |
5086 | const struct wpa_driver_ops wpa_driver_nl80211_ops = { |
5087 | .name = "nl80211", | |
5088 | .desc = "Linux nl80211/cfg80211", | |
5089 | .get_bssid = wpa_driver_nl80211_get_bssid, | |
5090 | .get_ssid = wpa_driver_nl80211_get_ssid, | |
3f5285e8 | 5091 | .set_key = wpa_driver_nl80211_set_key, |
6a1063e0 | 5092 | .scan2 = wpa_driver_nl80211_scan, |
3f5285e8 JM |
5093 | .get_scan_results2 = wpa_driver_nl80211_get_scan_results, |
5094 | .deauthenticate = wpa_driver_nl80211_deauthenticate, | |
5095 | .disassociate = wpa_driver_nl80211_disassociate, | |
c2a04078 | 5096 | .authenticate = wpa_driver_nl80211_authenticate, |
3f5285e8 | 5097 | .associate = wpa_driver_nl80211_associate, |
3f5285e8 JM |
5098 | .init = wpa_driver_nl80211_init, |
5099 | .deinit = wpa_driver_nl80211_deinit, | |
3f5285e8 JM |
5100 | .get_capa = wpa_driver_nl80211_get_capa, |
5101 | .set_operstate = wpa_driver_nl80211_set_operstate, | |
01652550 | 5102 | .set_supp_port = wpa_driver_nl80211_set_supp_port, |
6d158490 | 5103 | .set_country = wpa_driver_nl80211_set_country, |
d2440ba0 | 5104 | .set_beacon = wpa_driver_nl80211_set_beacon, |
22a7c9d7 JM |
5105 | .if_add = wpa_driver_nl80211_if_add, |
5106 | .if_remove = wpa_driver_nl80211_if_remove, | |
071f8ac4 | 5107 | .send_mlme = wpa_driver_nl80211_send_mlme, |
c3965310 | 5108 | .get_hw_feature_data = wpa_driver_nl80211_get_hw_feature_data, |
0f4e8b4f JM |
5109 | .sta_add = wpa_driver_nl80211_sta_add, |
5110 | .sta_remove = wpa_driver_nl80211_sta_remove, | |
db149ac9 | 5111 | .hapd_send_eapol = wpa_driver_nl80211_hapd_send_eapol, |
a8d6ffa4 | 5112 | .sta_set_flags = wpa_driver_nl80211_sta_set_flags, |
c5121837 JM |
5113 | #ifdef HOSTAPD |
5114 | .hapd_init = i802_init, | |
c5121837 | 5115 | .hapd_deinit = i802_deinit, |
c5121837 JM |
5116 | .get_seqnum = i802_get_seqnum, |
5117 | .flush = i802_flush, | |
5118 | .read_sta_data = i802_read_sta_data, | |
c5121837 JM |
5119 | .sta_deauth = i802_sta_deauth, |
5120 | .sta_disassoc = i802_sta_disassoc, | |
c5121837 JM |
5121 | .get_inact_sec = i802_get_inact_sec, |
5122 | .sta_clear_stats = i802_sta_clear_stats, | |
5123 | .set_freq = i802_set_freq, | |
5124 | .set_rts = i802_set_rts, | |
5125 | .set_frag = i802_set_frag, | |
c5121837 | 5126 | .set_rate_sets = i802_set_rate_sets, |
c5121837 JM |
5127 | .set_cts_protect = i802_set_cts_protect, |
5128 | .set_preamble = i802_set_preamble, | |
5129 | .set_short_slot_time = i802_set_short_slot_time, | |
5130 | .set_tx_queue_params = i802_set_tx_queue_params, | |
c5121837 | 5131 | .set_sta_vlan = i802_set_sta_vlan, |
fbbfcbac | 5132 | .set_wds_sta = i802_set_wds_sta, |
c5121837 | 5133 | #endif /* HOSTAPD */ |
58f6fbe0 | 5134 | .send_action = wpa_driver_nl80211_send_action, |
55777702 JM |
5135 | .remain_on_channel = wpa_driver_nl80211_remain_on_channel, |
5136 | .cancel_remain_on_channel = | |
5137 | wpa_driver_nl80211_cancel_remain_on_channel, | |
504e905c | 5138 | .probe_req_report = wpa_driver_nl80211_probe_req_report, |
7bfc47c3 JM |
5139 | .alloc_interface_addr = wpa_driver_nl80211_alloc_interface_addr, |
5140 | .release_interface_addr = wpa_driver_nl80211_release_interface_addr, | |
4e5cb1a3 | 5141 | .disable_11b_rates = wpa_driver_nl80211_disable_11b_rates, |
af473088 | 5142 | .deinit_ap = wpa_driver_nl80211_deinit_ap, |
207ef3fb | 5143 | .resume = wpa_driver_nl80211_resume, |
3f5285e8 | 5144 | }; |