]>
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); |
bbaf0837 | 1296 | |
7524cfb1 JM |
1297 | os_free(drv); |
1298 | return NULL; | |
1299 | } | |
1300 | ||
1301 | ||
58f6fbe0 JM |
1302 | static int nl80211_register_action_frame(struct wpa_driver_nl80211_data *drv, |
1303 | const u8 *match, size_t match_len) | |
1304 | { | |
1305 | struct nl_msg *msg; | |
1306 | int ret = -1; | |
1307 | ||
1308 | msg = nlmsg_alloc(); | |
1309 | if (!msg) | |
1310 | return -1; | |
1311 | ||
1312 | genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0, 0, | |
1313 | NL80211_CMD_REGISTER_ACTION, 0); | |
1314 | ||
1315 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); | |
1316 | NLA_PUT(msg, NL80211_ATTR_FRAME_MATCH, match_len, match); | |
1317 | ||
1318 | ret = send_and_recv(drv, drv->nl_handle_event, msg, NULL, NULL); | |
1319 | msg = NULL; | |
1320 | if (ret) { | |
1321 | wpa_printf(MSG_DEBUG, "nl80211: Register Action command " | |
1322 | "failed: ret=%d (%s)", ret, strerror(-ret)); | |
1323 | wpa_hexdump(MSG_DEBUG, "nl80211: Register Action match", | |
1324 | match, match_len); | |
1325 | goto nla_put_failure; | |
1326 | } | |
1327 | ret = 0; | |
1328 | nla_put_failure: | |
1329 | nlmsg_free(msg); | |
1330 | return ret; | |
1331 | } | |
1332 | ||
1333 | ||
1334 | static int nl80211_register_action_frames(struct wpa_driver_nl80211_data *drv) | |
1335 | { | |
1336 | if (0) { | |
1337 | /* Public Action frames */ | |
1338 | return nl80211_register_action_frame(drv, (u8 *) "\x04", 1); | |
1339 | } | |
1340 | return 0; | |
1341 | } | |
1342 | ||
1343 | ||
362f781e | 1344 | static int |
7524cfb1 JM |
1345 | wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data *drv) |
1346 | { | |
a2e40bb6 FF |
1347 | struct i802_bss *bss = &drv->first_bss; |
1348 | ||
1349 | drv->ifindex = if_nametoindex(bss->ifname); | |
1350 | drv->first_bss.ifindex = drv->ifindex; | |
a87c9d96 | 1351 | |
bbaf0837 | 1352 | #ifndef HOSTAPD |
a2e40bb6 | 1353 | if (wpa_driver_nl80211_set_mode(bss, IEEE80211_MODE_INFRA) < 0) { |
a87c9d96 JM |
1354 | wpa_printf(MSG_DEBUG, "nl80211: Could not configure driver to " |
1355 | "use managed mode"); | |
1356 | } | |
1357 | ||
a2e40bb6 | 1358 | if (linux_set_iface_flags(drv->ioctl_sock, bss->ifname, 1)) { |
34f2f814 | 1359 | wpa_printf(MSG_ERROR, "Could not set interface '%s' UP", |
a2e40bb6 | 1360 | bss->ifname); |
362f781e JM |
1361 | return -1; |
1362 | } | |
3f5285e8 | 1363 | |
93d11400 ZY |
1364 | if (wpa_driver_nl80211_capa(drv)) |
1365 | return -1; | |
80bc75f1 | 1366 | |
08063178 | 1367 | netlink_send_oper_ifla(drv->netlink, drv->ifindex, |
e2d02c29 | 1368 | 1, IF_OPER_DORMANT); |
bbaf0837 | 1369 | #endif /* HOSTAPD */ |
362f781e | 1370 | |
58f6fbe0 JM |
1371 | if (nl80211_register_action_frames(drv) < 0) |
1372 | return -1; | |
1373 | ||
362f781e | 1374 | return 0; |
3f5285e8 JM |
1375 | } |
1376 | ||
1377 | ||
8a27af5c JM |
1378 | static int wpa_driver_nl80211_del_beacon(struct wpa_driver_nl80211_data *drv) |
1379 | { | |
1380 | struct nl_msg *msg; | |
1381 | ||
1382 | msg = nlmsg_alloc(); | |
1383 | if (!msg) | |
1384 | return -ENOMEM; | |
1385 | ||
1386 | genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0, | |
1387 | 0, NL80211_CMD_DEL_BEACON, 0); | |
1388 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); | |
1389 | ||
1390 | return send_and_recv_msgs(drv, msg, NULL, NULL); | |
1391 | nla_put_failure: | |
1392 | return -ENOBUFS; | |
1393 | } | |
8a27af5c JM |
1394 | |
1395 | ||
3f5285e8 | 1396 | /** |
7e5ba1b9 JM |
1397 | * wpa_driver_nl80211_deinit - Deinitialize nl80211 driver interface |
1398 | * @priv: Pointer to private nl80211 data from wpa_driver_nl80211_init() | |
3f5285e8 JM |
1399 | * |
1400 | * Shut down driver interface and processing of driver events. Free | |
1401 | * private data buffer if one was allocated in wpa_driver_nl80211_init(). | |
1402 | */ | |
7e5ba1b9 | 1403 | static void wpa_driver_nl80211_deinit(void *priv) |
3f5285e8 | 1404 | { |
a2e40bb6 FF |
1405 | struct i802_bss *bss = priv; |
1406 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
3f5285e8 | 1407 | |
94627f6c | 1408 | if (drv->added_if_into_bridge) { |
a2e40bb6 | 1409 | if (linux_br_del_if(drv->ioctl_sock, drv->brname, bss->ifname) |
94627f6c JM |
1410 | < 0) |
1411 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " | |
1412 | "interface %s from bridge %s: %s", | |
a2e40bb6 | 1413 | bss->ifname, drv->brname, strerror(errno)); |
94627f6c JM |
1414 | } |
1415 | if (drv->added_bridge) { | |
1416 | if (linux_br_del(drv->ioctl_sock, drv->brname) < 0) | |
1417 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " | |
1418 | "bridge %s: %s", | |
1419 | drv->brname, strerror(errno)); | |
1420 | } | |
1421 | ||
460456f8 | 1422 | nl80211_remove_monitor_interface(drv); |
8a27af5c JM |
1423 | |
1424 | if (drv->nlmode == NL80211_IFTYPE_AP) | |
1425 | wpa_driver_nl80211_del_beacon(drv); | |
0915d02c | 1426 | |
bbaf0837 JM |
1427 | #ifdef HOSTAPD |
1428 | if (drv->last_freq_ht) { | |
1429 | /* Clear HT flags from the driver */ | |
1430 | struct hostapd_freq_params freq; | |
1431 | os_memset(&freq, 0, sizeof(freq)); | |
1432 | freq.freq = drv->last_freq; | |
1433 | i802_set_freq(priv, &freq); | |
1434 | } | |
1435 | ||
bbaf0837 JM |
1436 | if (drv->eapol_sock >= 0) { |
1437 | eloop_unregister_read_sock(drv->eapol_sock); | |
1438 | close(drv->eapol_sock); | |
1439 | } | |
1440 | ||
1441 | if (drv->if_indices != drv->default_if_indices) | |
1442 | os_free(drv->if_indices); | |
1b648c7e | 1443 | #endif /* HOSTAPD */ |
3f5285e8 | 1444 | |
4e5cb1a3 JM |
1445 | if (drv->disable_11b_rates) |
1446 | nl80211_disable_11b_rates(drv, drv->ifindex, 0); | |
1447 | ||
08063178 JM |
1448 | netlink_send_oper_ifla(drv->netlink, drv->ifindex, 0, IF_OPER_UP); |
1449 | netlink_deinit(drv->netlink); | |
3f5285e8 | 1450 | |
bbaf0837 JM |
1451 | eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout, drv, drv->ctx); |
1452 | ||
a2e40bb6 FF |
1453 | (void) linux_set_iface_flags(drv->ioctl_sock, bss->ifname, 0); |
1454 | wpa_driver_nl80211_set_mode(bss, IEEE80211_MODE_INFRA); | |
3f5285e8 | 1455 | |
bbaf0837 JM |
1456 | if (drv->ioctl_sock >= 0) |
1457 | close(drv->ioctl_sock); | |
3f5285e8 | 1458 | |
335ce76b | 1459 | eloop_unregister_read_sock(nl_socket_get_fd(drv->nl_handle_event)); |
3f5285e8 JM |
1460 | genl_family_put(drv->nl80211); |
1461 | nl_cache_free(drv->nl_cache); | |
335ce76b | 1462 | nl_cache_free(drv->nl_cache_event); |
3f5285e8 | 1463 | nl_handle_destroy(drv->nl_handle); |
335ce76b | 1464 | nl_handle_destroy(drv->nl_handle_event); |
3f5285e8 JM |
1465 | nl_cb_put(drv->nl_cb); |
1466 | ||
504e905c JM |
1467 | eloop_cancel_timeout(wpa_driver_nl80211_probe_req_report_timeout, |
1468 | drv, NULL); | |
1469 | ||
3812464c JM |
1470 | os_free(drv->filter_ssids); |
1471 | ||
3f5285e8 JM |
1472 | os_free(drv); |
1473 | } | |
1474 | ||
1475 | ||
1476 | /** | |
1477 | * wpa_driver_nl80211_scan_timeout - Scan timeout to report scan completion | |
ad1e68e6 | 1478 | * @eloop_ctx: Driver private data |
3f5285e8 JM |
1479 | * @timeout_ctx: ctx argument given to wpa_driver_nl80211_init() |
1480 | * | |
1481 | * This function can be used as registered timeout when starting a scan to | |
1482 | * generate a scan completed event if the driver does not report this. | |
1483 | */ | |
1484 | static void wpa_driver_nl80211_scan_timeout(void *eloop_ctx, void *timeout_ctx) | |
1485 | { | |
ad1e68e6 JM |
1486 | struct wpa_driver_nl80211_data *drv = eloop_ctx; |
1487 | if (drv->ap_scan_as_station) { | |
a2e40bb6 FF |
1488 | wpa_driver_nl80211_set_mode(&drv->first_bss, |
1489 | IEEE80211_MODE_AP); | |
ad1e68e6 JM |
1490 | drv->ap_scan_as_station = 0; |
1491 | } | |
3f5285e8 JM |
1492 | wpa_printf(MSG_DEBUG, "Scan timeout - try to get results"); |
1493 | wpa_supplicant_event(timeout_ctx, EVENT_SCAN_RESULTS, NULL); | |
1494 | } | |
1495 | ||
1496 | ||
1497 | /** | |
1498 | * wpa_driver_nl80211_scan - Request the driver to initiate scan | |
ad1e68e6 | 1499 | * @priv: Pointer to private driver data from wpa_driver_nl80211_init() |
6a1063e0 | 1500 | * @params: Scan parameters |
3f5285e8 JM |
1501 | * Returns: 0 on success, -1 on failure |
1502 | */ | |
6a1063e0 JM |
1503 | static int wpa_driver_nl80211_scan(void *priv, |
1504 | struct wpa_driver_scan_params *params) | |
3f5285e8 | 1505 | { |
a2e40bb6 FF |
1506 | struct i802_bss *bss = priv; |
1507 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
3f5285e8 | 1508 | int ret = 0, timeout; |
d3a98225 | 1509 | struct nl_msg *msg, *ssids, *freqs; |
6a1063e0 | 1510 | size_t i; |
3f5285e8 | 1511 | |
0e75527f JM |
1512 | msg = nlmsg_alloc(); |
1513 | ssids = nlmsg_alloc(); | |
d3a98225 JM |
1514 | freqs = nlmsg_alloc(); |
1515 | if (!msg || !ssids || !freqs) { | |
0e75527f JM |
1516 | nlmsg_free(msg); |
1517 | nlmsg_free(ssids); | |
d3a98225 | 1518 | nlmsg_free(freqs); |
3f5285e8 JM |
1519 | return -1; |
1520 | } | |
1521 | ||
3812464c JM |
1522 | os_free(drv->filter_ssids); |
1523 | drv->filter_ssids = params->filter_ssids; | |
1524 | params->filter_ssids = NULL; | |
1525 | drv->num_filter_ssids = params->num_filter_ssids; | |
1526 | ||
0e75527f JM |
1527 | genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0, 0, |
1528 | NL80211_CMD_TRIGGER_SCAN, 0); | |
1529 | ||
1530 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); | |
3f5285e8 | 1531 | |
6a1063e0 JM |
1532 | for (i = 0; i < params->num_ssids; i++) { |
1533 | NLA_PUT(ssids, i + 1, params->ssids[i].ssid_len, | |
1534 | params->ssids[i].ssid); | |
3f5285e8 | 1535 | } |
6a1063e0 JM |
1536 | if (params->num_ssids) |
1537 | nla_put_nested(msg, NL80211_ATTR_SCAN_SSIDS, ssids); | |
3f5285e8 | 1538 | |
d173df52 JM |
1539 | if (params->extra_ies) { |
1540 | NLA_PUT(msg, NL80211_ATTR_IE, params->extra_ies_len, | |
1541 | params->extra_ies); | |
1542 | } | |
1543 | ||
d3a98225 JM |
1544 | if (params->freqs) { |
1545 | for (i = 0; params->freqs[i]; i++) | |
1546 | NLA_PUT_U32(freqs, i + 1, params->freqs[i]); | |
1547 | nla_put_nested(msg, NL80211_ATTR_SCAN_FREQUENCIES, freqs); | |
1548 | } | |
1549 | ||
0e75527f JM |
1550 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
1551 | msg = NULL; | |
1552 | if (ret) { | |
1553 | wpa_printf(MSG_DEBUG, "nl80211: Scan trigger failed: ret=%d " | |
1554 | "(%s)", ret, strerror(-ret)); | |
ad1e68e6 JM |
1555 | #ifdef HOSTAPD |
1556 | if (drv->nlmode == NL80211_IFTYPE_AP) { | |
1557 | /* | |
1558 | * mac80211 does not allow scan requests in AP mode, so | |
1559 | * try to do this in station mode. | |
1560 | */ | |
a2e40bb6 | 1561 | if (wpa_driver_nl80211_set_mode(bss, |
ad1e68e6 JM |
1562 | IEEE80211_MODE_INFRA)) |
1563 | goto nla_put_failure; | |
1564 | ||
1565 | if (wpa_driver_nl80211_scan(drv, params)) { | |
a2e40bb6 | 1566 | wpa_driver_nl80211_set_mode(bss, |
ad1e68e6 JM |
1567 | IEEE80211_MODE_AP); |
1568 | goto nla_put_failure; | |
1569 | } | |
1570 | ||
1571 | /* Restore AP mode when processing scan results */ | |
1572 | drv->ap_scan_as_station = 1; | |
1573 | ret = 0; | |
1574 | } else | |
1575 | goto nla_put_failure; | |
1576 | #else /* HOSTAPD */ | |
0e75527f | 1577 | goto nla_put_failure; |
ad1e68e6 | 1578 | #endif /* HOSTAPD */ |
3f5285e8 JM |
1579 | } |
1580 | ||
1581 | /* Not all drivers generate "scan completed" wireless event, so try to | |
1582 | * read results after a timeout. */ | |
0e75527f | 1583 | timeout = 10; |
3f5285e8 JM |
1584 | if (drv->scan_complete_events) { |
1585 | /* | |
d173df52 JM |
1586 | * The driver seems to deliver events to notify when scan is |
1587 | * complete, so use longer timeout to avoid race conditions | |
1588 | * with scanning and following association request. | |
3f5285e8 JM |
1589 | */ |
1590 | timeout = 30; | |
1591 | } | |
1592 | wpa_printf(MSG_DEBUG, "Scan requested (ret=%d) - scan timeout %d " | |
1593 | "seconds", ret, timeout); | |
1594 | eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout, drv, drv->ctx); | |
0e75527f JM |
1595 | eloop_register_timeout(timeout, 0, wpa_driver_nl80211_scan_timeout, |
1596 | drv, drv->ctx); | |
3f5285e8 | 1597 | |
0e75527f JM |
1598 | nla_put_failure: |
1599 | nlmsg_free(ssids); | |
1600 | nlmsg_free(msg); | |
d3a98225 | 1601 | nlmsg_free(freqs); |
3f5285e8 JM |
1602 | return ret; |
1603 | } | |
1604 | ||
1605 | ||
3812464c JM |
1606 | static const u8 * nl80211_get_ie(const u8 *ies, size_t ies_len, u8 ie) |
1607 | { | |
1608 | const u8 *end, *pos; | |
1609 | ||
1610 | if (ies == NULL) | |
1611 | return NULL; | |
1612 | ||
1613 | pos = ies; | |
1614 | end = ies + ies_len; | |
1615 | ||
1616 | while (pos + 1 < end) { | |
1617 | if (pos + 2 + pos[1] > end) | |
1618 | break; | |
1619 | if (pos[0] == ie) | |
1620 | return pos; | |
1621 | pos += 2 + pos[1]; | |
1622 | } | |
1623 | ||
1624 | return NULL; | |
1625 | } | |
1626 | ||
1627 | ||
1628 | static int nl80211_scan_filtered(struct wpa_driver_nl80211_data *drv, | |
1629 | const u8 *ie, size_t ie_len) | |
1630 | { | |
1631 | const u8 *ssid; | |
1632 | size_t i; | |
1633 | ||
1634 | if (drv->filter_ssids == NULL) | |
1635 | return 0; | |
1636 | ||
1637 | ssid = nl80211_get_ie(ie, ie_len, WLAN_EID_SSID); | |
1638 | if (ssid == NULL) | |
1639 | return 1; | |
1640 | ||
1641 | for (i = 0; i < drv->num_filter_ssids; i++) { | |
1642 | if (ssid[1] == drv->filter_ssids[i].ssid_len && | |
1643 | os_memcmp(ssid + 2, drv->filter_ssids[i].ssid, ssid[1]) == | |
1644 | 0) | |
1645 | return 0; | |
1646 | } | |
1647 | ||
1648 | return 1; | |
1649 | } | |
1650 | ||
1651 | ||
1652 | struct nl80211_bss_info_arg { | |
1653 | struct wpa_driver_nl80211_data *drv; | |
1654 | struct wpa_scan_results *res; | |
1655 | }; | |
1656 | ||
b3db1e1c | 1657 | static int bss_info_handler(struct nl_msg *msg, void *arg) |
3f5285e8 | 1658 | { |
b3db1e1c JM |
1659 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
1660 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
1661 | struct nlattr *bss[NL80211_BSS_MAX + 1]; | |
1662 | static struct nla_policy bss_policy[NL80211_BSS_MAX + 1] = { | |
1663 | [NL80211_BSS_BSSID] = { .type = NLA_UNSPEC }, | |
1664 | [NL80211_BSS_FREQUENCY] = { .type = NLA_U32 }, | |
1665 | [NL80211_BSS_TSF] = { .type = NLA_U64 }, | |
1666 | [NL80211_BSS_BEACON_INTERVAL] = { .type = NLA_U16 }, | |
1667 | [NL80211_BSS_CAPABILITY] = { .type = NLA_U16 }, | |
1668 | [NL80211_BSS_INFORMATION_ELEMENTS] = { .type = NLA_UNSPEC }, | |
1669 | [NL80211_BSS_SIGNAL_MBM] = { .type = NLA_U32 }, | |
1670 | [NL80211_BSS_SIGNAL_UNSPEC] = { .type = NLA_U8 }, | |
e6b8efeb | 1671 | [NL80211_BSS_STATUS] = { .type = NLA_U32 }, |
b3ad11bb | 1672 | [NL80211_BSS_SEEN_MS_AGO] = { .type = NLA_U32 }, |
8c090654 | 1673 | [NL80211_BSS_BEACON_IES] = { .type = NLA_UNSPEC }, |
b3db1e1c | 1674 | }; |
3812464c JM |
1675 | struct nl80211_bss_info_arg *_arg = arg; |
1676 | struct wpa_scan_results *res = _arg->res; | |
3f5285e8 JM |
1677 | struct wpa_scan_res **tmp; |
1678 | struct wpa_scan_res *r; | |
8c090654 JM |
1679 | const u8 *ie, *beacon_ie; |
1680 | size_t ie_len, beacon_ie_len; | |
1681 | u8 *pos; | |
3f5285e8 | 1682 | |
b3db1e1c JM |
1683 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
1684 | genlmsg_attrlen(gnlh, 0), NULL); | |
1685 | if (!tb[NL80211_ATTR_BSS]) | |
1686 | return NL_SKIP; | |
1687 | if (nla_parse_nested(bss, NL80211_BSS_MAX, tb[NL80211_ATTR_BSS], | |
1688 | bss_policy)) | |
1689 | return NL_SKIP; | |
1690 | if (bss[NL80211_BSS_INFORMATION_ELEMENTS]) { | |
1691 | ie = nla_data(bss[NL80211_BSS_INFORMATION_ELEMENTS]); | |
1692 | ie_len = nla_len(bss[NL80211_BSS_INFORMATION_ELEMENTS]); | |
1693 | } else { | |
1694 | ie = NULL; | |
1695 | ie_len = 0; | |
1696 | } | |
8c090654 JM |
1697 | if (bss[NL80211_BSS_BEACON_IES]) { |
1698 | beacon_ie = nla_data(bss[NL80211_BSS_BEACON_IES]); | |
1699 | beacon_ie_len = nla_len(bss[NL80211_BSS_BEACON_IES]); | |
1700 | } else { | |
1701 | beacon_ie = NULL; | |
1702 | beacon_ie_len = 0; | |
1703 | } | |
3f5285e8 | 1704 | |
3812464c JM |
1705 | if (nl80211_scan_filtered(_arg->drv, ie ? ie : beacon_ie, |
1706 | ie ? ie_len : beacon_ie_len)) | |
1707 | return NL_SKIP; | |
1708 | ||
8c090654 | 1709 | r = os_zalloc(sizeof(*r) + ie_len + beacon_ie_len); |
3f5285e8 | 1710 | if (r == NULL) |
b3db1e1c JM |
1711 | return NL_SKIP; |
1712 | if (bss[NL80211_BSS_BSSID]) | |
1713 | os_memcpy(r->bssid, nla_data(bss[NL80211_BSS_BSSID]), | |
1714 | ETH_ALEN); | |
1715 | if (bss[NL80211_BSS_FREQUENCY]) | |
1716 | r->freq = nla_get_u32(bss[NL80211_BSS_FREQUENCY]); | |
1717 | if (bss[NL80211_BSS_BEACON_INTERVAL]) | |
1718 | r->beacon_int = nla_get_u16(bss[NL80211_BSS_BEACON_INTERVAL]); | |
1719 | if (bss[NL80211_BSS_CAPABILITY]) | |
1720 | r->caps = nla_get_u16(bss[NL80211_BSS_CAPABILITY]); | |
7c2849d2 JM |
1721 | r->flags |= WPA_SCAN_NOISE_INVALID; |
1722 | if (bss[NL80211_BSS_SIGNAL_MBM]) { | |
b3db1e1c | 1723 | r->level = nla_get_u32(bss[NL80211_BSS_SIGNAL_MBM]); |
7c2849d2 JM |
1724 | r->level /= 100; /* mBm to dBm */ |
1725 | r->flags |= WPA_SCAN_LEVEL_DBM | WPA_SCAN_QUAL_INVALID; | |
1726 | } else if (bss[NL80211_BSS_SIGNAL_UNSPEC]) { | |
1727 | r->level = nla_get_u8(bss[NL80211_BSS_SIGNAL_UNSPEC]); | |
1728 | r->flags |= WPA_SCAN_LEVEL_INVALID; | |
1729 | } else | |
1730 | r->flags |= WPA_SCAN_LEVEL_INVALID | WPA_SCAN_QUAL_INVALID; | |
b3db1e1c JM |
1731 | if (bss[NL80211_BSS_TSF]) |
1732 | r->tsf = nla_get_u64(bss[NL80211_BSS_TSF]); | |
b3ad11bb JM |
1733 | if (bss[NL80211_BSS_SEEN_MS_AGO]) |
1734 | r->age = nla_get_u32(bss[NL80211_BSS_SEEN_MS_AGO]); | |
b3db1e1c | 1735 | r->ie_len = ie_len; |
8c090654 JM |
1736 | pos = (u8 *) (r + 1); |
1737 | if (ie) { | |
1738 | os_memcpy(pos, ie, ie_len); | |
1739 | pos += ie_len; | |
1740 | } | |
1741 | r->beacon_ie_len = beacon_ie_len; | |
1742 | if (beacon_ie) | |
1743 | os_memcpy(pos, beacon_ie, beacon_ie_len); | |
3f5285e8 | 1744 | |
e6b8efeb JM |
1745 | if (bss[NL80211_BSS_STATUS]) { |
1746 | enum nl80211_bss_status status; | |
1747 | status = nla_get_u32(bss[NL80211_BSS_STATUS]); | |
1748 | switch (status) { | |
1749 | case NL80211_BSS_STATUS_AUTHENTICATED: | |
1750 | r->flags |= WPA_SCAN_AUTHENTICATED; | |
1751 | break; | |
1752 | case NL80211_BSS_STATUS_ASSOCIATED: | |
1753 | r->flags |= WPA_SCAN_ASSOCIATED; | |
1754 | break; | |
1755 | default: | |
1756 | break; | |
1757 | } | |
1758 | } | |
1759 | ||
3f5285e8 JM |
1760 | tmp = os_realloc(res->res, |
1761 | (res->num + 1) * sizeof(struct wpa_scan_res *)); | |
1762 | if (tmp == NULL) { | |
1763 | os_free(r); | |
b3db1e1c | 1764 | return NL_SKIP; |
3f5285e8 JM |
1765 | } |
1766 | tmp[res->num++] = r; | |
1767 | res->res = tmp; | |
b3db1e1c JM |
1768 | |
1769 | return NL_SKIP; | |
3f5285e8 | 1770 | } |
b3db1e1c | 1771 | |
3f5285e8 | 1772 | |
d72aad94 JM |
1773 | static void clear_state_mismatch(struct wpa_driver_nl80211_data *drv, |
1774 | const u8 *addr) | |
1775 | { | |
1776 | if (drv->capa.flags & WPA_DRIVER_FLAGS_SME) { | |
1777 | wpa_printf(MSG_DEBUG, "nl80211: Clear possible state " | |
582507be | 1778 | "mismatch (" MACSTR ")", MAC2STR(addr)); |
d72aad94 JM |
1779 | wpa_driver_nl80211_mlme(drv, addr, |
1780 | NL80211_CMD_DEAUTHENTICATE, | |
1781 | WLAN_REASON_PREV_AUTH_NOT_VALID); | |
1782 | } | |
1783 | } | |
1784 | ||
1785 | ||
e6b8efeb JM |
1786 | static void wpa_driver_nl80211_check_bss_status( |
1787 | struct wpa_driver_nl80211_data *drv, struct wpa_scan_results *res) | |
1788 | { | |
1789 | size_t i; | |
1790 | ||
1791 | for (i = 0; i < res->num; i++) { | |
1792 | struct wpa_scan_res *r = res->res[i]; | |
1793 | if (r->flags & WPA_SCAN_AUTHENTICATED) { | |
1794 | wpa_printf(MSG_DEBUG, "nl80211: Scan results " | |
1795 | "indicates BSS status with " MACSTR | |
1796 | " as authenticated", | |
1797 | MAC2STR(r->bssid)); | |
1798 | if (drv->nlmode == NL80211_IFTYPE_STATION && | |
1799 | os_memcmp(r->bssid, drv->bssid, ETH_ALEN) != 0 && | |
1800 | os_memcmp(r->bssid, drv->auth_bssid, ETH_ALEN) != | |
1801 | 0) { | |
1802 | wpa_printf(MSG_DEBUG, "nl80211: Unknown BSSID" | |
1803 | " in local state (auth=" MACSTR | |
1804 | " assoc=" MACSTR ")", | |
1805 | MAC2STR(drv->auth_bssid), | |
1806 | MAC2STR(drv->bssid)); | |
582507be | 1807 | clear_state_mismatch(drv, r->bssid); |
e6b8efeb JM |
1808 | } |
1809 | } | |
1810 | ||
1811 | if (r->flags & WPA_SCAN_ASSOCIATED) { | |
1812 | wpa_printf(MSG_DEBUG, "nl80211: Scan results " | |
1813 | "indicate BSS status with " MACSTR | |
1814 | " as associated", | |
1815 | MAC2STR(r->bssid)); | |
1816 | if (drv->nlmode == NL80211_IFTYPE_STATION && | |
1817 | !drv->associated) { | |
1818 | wpa_printf(MSG_DEBUG, "nl80211: Local state " | |
1819 | "(not associated) does not match " | |
1820 | "with BSS state"); | |
d72aad94 | 1821 | clear_state_mismatch(drv, r->bssid); |
e6b8efeb JM |
1822 | } else if (drv->nlmode == NL80211_IFTYPE_STATION && |
1823 | os_memcmp(drv->bssid, r->bssid, ETH_ALEN) != | |
1824 | 0) { | |
1825 | wpa_printf(MSG_DEBUG, "nl80211: Local state " | |
1826 | "(associated with " MACSTR ") does " | |
1827 | "not match with BSS state", | |
d72aad94 JM |
1828 | MAC2STR(drv->bssid)); |
1829 | clear_state_mismatch(drv, r->bssid); | |
1830 | clear_state_mismatch(drv, drv->bssid); | |
e6b8efeb JM |
1831 | } |
1832 | } | |
1833 | } | |
1834 | } | |
1835 | ||
1836 | ||
d1f9c410 JM |
1837 | static void wpa_scan_results_free(struct wpa_scan_results *res) |
1838 | { | |
1839 | size_t i; | |
1840 | ||
1841 | if (res == NULL) | |
1842 | return; | |
1843 | ||
1844 | for (i = 0; i < res->num; i++) | |
1845 | os_free(res->res[i]); | |
1846 | os_free(res->res); | |
1847 | os_free(res); | |
1848 | } | |
1849 | ||
1850 | ||
7e5ba1b9 | 1851 | static struct wpa_scan_results * |
8856462d | 1852 | nl80211_get_scan_results(struct wpa_driver_nl80211_data *drv) |
3f5285e8 | 1853 | { |
b3db1e1c | 1854 | struct nl_msg *msg; |
3f5285e8 | 1855 | struct wpa_scan_results *res; |
b3db1e1c | 1856 | int ret; |
3812464c | 1857 | struct nl80211_bss_info_arg arg; |
3f5285e8 JM |
1858 | |
1859 | res = os_zalloc(sizeof(*res)); | |
b3db1e1c | 1860 | if (res == NULL) |
8e2c104f | 1861 | return NULL; |
b3db1e1c JM |
1862 | msg = nlmsg_alloc(); |
1863 | if (!msg) | |
1864 | goto nla_put_failure; | |
3f5285e8 | 1865 | |
b3db1e1c JM |
1866 | genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0, NLM_F_DUMP, |
1867 | NL80211_CMD_GET_SCAN, 0); | |
1868 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); | |
3f5285e8 | 1869 | |
3812464c JM |
1870 | arg.drv = drv; |
1871 | arg.res = res; | |
1872 | ret = send_and_recv_msgs(drv, msg, bss_info_handler, &arg); | |
b3db1e1c JM |
1873 | msg = NULL; |
1874 | if (ret == 0) { | |
1875 | wpa_printf(MSG_DEBUG, "Received scan results (%lu BSSes)", | |
1876 | (unsigned long) res->num); | |
1877 | return res; | |
3f5285e8 | 1878 | } |
b3db1e1c JM |
1879 | wpa_printf(MSG_DEBUG, "nl80211: Scan result fetch failed: ret=%d " |
1880 | "(%s)", ret, strerror(-ret)); | |
1881 | nla_put_failure: | |
1882 | nlmsg_free(msg); | |
1883 | wpa_scan_results_free(res); | |
1884 | return NULL; | |
3f5285e8 JM |
1885 | } |
1886 | ||
1887 | ||
8856462d JM |
1888 | /** |
1889 | * wpa_driver_nl80211_get_scan_results - Fetch the latest scan results | |
1890 | * @priv: Pointer to private wext data from wpa_driver_nl80211_init() | |
1891 | * Returns: Scan results on success, -1 on failure | |
1892 | */ | |
1893 | static struct wpa_scan_results * | |
1894 | wpa_driver_nl80211_get_scan_results(void *priv) | |
1895 | { | |
a2e40bb6 FF |
1896 | struct i802_bss *bss = priv; |
1897 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8856462d JM |
1898 | struct wpa_scan_results *res; |
1899 | ||
1900 | res = nl80211_get_scan_results(drv); | |
1901 | if (res) | |
1902 | wpa_driver_nl80211_check_bss_status(drv, res); | |
1903 | return res; | |
1904 | } | |
1905 | ||
1906 | ||
1907 | static void nl80211_dump_scan(struct wpa_driver_nl80211_data *drv) | |
1908 | { | |
1909 | struct wpa_scan_results *res; | |
1910 | size_t i; | |
1911 | ||
1912 | res = nl80211_get_scan_results(drv); | |
1913 | if (res == NULL) { | |
1914 | wpa_printf(MSG_DEBUG, "nl80211: Failed to get scan results"); | |
1915 | return; | |
1916 | } | |
1917 | ||
1918 | wpa_printf(MSG_DEBUG, "nl80211: Scan result dump"); | |
1919 | for (i = 0; i < res->num; i++) { | |
1920 | struct wpa_scan_res *r = res->res[i]; | |
1921 | wpa_printf(MSG_DEBUG, "nl80211: %d/%d " MACSTR "%s%s", | |
1922 | (int) i, (int) res->num, MAC2STR(r->bssid), | |
1923 | r->flags & WPA_SCAN_AUTHENTICATED ? " [auth]" : "", | |
1924 | r->flags & WPA_SCAN_ASSOCIATED ? " [assoc]" : ""); | |
1925 | } | |
1926 | ||
1927 | wpa_scan_results_free(res); | |
1928 | } | |
1929 | ||
1930 | ||
642187d6 | 1931 | static int wpa_driver_nl80211_set_key(const char *ifname, void *priv, |
71934751 JM |
1932 | enum wpa_alg alg, const u8 *addr, |
1933 | int key_idx, int set_tx, | |
642187d6 JM |
1934 | const u8 *seq, size_t seq_len, |
1935 | const u8 *key, size_t key_len) | |
3f5285e8 | 1936 | { |
a2e40bb6 FF |
1937 | struct i802_bss *bss = priv; |
1938 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
642187d6 | 1939 | int ifindex = if_nametoindex(ifname); |
3f5285e8 | 1940 | struct nl_msg *msg; |
1ad1cdc2 | 1941 | int ret; |
3f5285e8 | 1942 | |
1ad1cdc2 JM |
1943 | wpa_printf(MSG_DEBUG, "%s: ifindex=%d alg=%d addr=%p key_idx=%d " |
1944 | "set_tx=%d seq_len=%lu key_len=%lu", | |
1945 | __func__, ifindex, alg, addr, key_idx, set_tx, | |
3f5285e8 JM |
1946 | (unsigned long) seq_len, (unsigned long) key_len); |
1947 | ||
1948 | msg = nlmsg_alloc(); | |
1ad1cdc2 JM |
1949 | if (!msg) |
1950 | return -ENOMEM; | |
3f5285e8 JM |
1951 | |
1952 | if (alg == WPA_ALG_NONE) { | |
1ad1cdc2 JM |
1953 | genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0, |
1954 | 0, NL80211_CMD_DEL_KEY, 0); | |
3f5285e8 | 1955 | } else { |
1ad1cdc2 JM |
1956 | genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0, |
1957 | 0, NL80211_CMD_NEW_KEY, 0); | |
3f5285e8 | 1958 | NLA_PUT(msg, NL80211_ATTR_KEY_DATA, key_len, key); |
d723bab4 JM |
1959 | switch (alg) { |
1960 | case WPA_ALG_WEP: | |
1961 | if (key_len == 5) | |
1962 | NLA_PUT_U32(msg, NL80211_ATTR_KEY_CIPHER, | |
1963 | WLAN_CIPHER_SUITE_WEP40); | |
1964 | else | |
1965 | NLA_PUT_U32(msg, NL80211_ATTR_KEY_CIPHER, | |
1966 | WLAN_CIPHER_SUITE_WEP104); | |
1967 | break; | |
1968 | case WPA_ALG_TKIP: | |
1969 | NLA_PUT_U32(msg, NL80211_ATTR_KEY_CIPHER, | |
1970 | WLAN_CIPHER_SUITE_TKIP); | |
1971 | break; | |
1972 | case WPA_ALG_CCMP: | |
1973 | NLA_PUT_U32(msg, NL80211_ATTR_KEY_CIPHER, | |
1974 | WLAN_CIPHER_SUITE_CCMP); | |
1975 | break; | |
1976 | case WPA_ALG_IGTK: | |
1977 | NLA_PUT_U32(msg, NL80211_ATTR_KEY_CIPHER, | |
1978 | WLAN_CIPHER_SUITE_AES_CMAC); | |
1979 | break; | |
1980 | default: | |
1981 | wpa_printf(MSG_ERROR, "%s: Unsupported encryption " | |
1982 | "algorithm %d", __func__, alg); | |
3f5285e8 JM |
1983 | nlmsg_free(msg); |
1984 | return -1; | |
1985 | } | |
1986 | } | |
1987 | ||
849ef835 | 1988 | if (seq && seq_len) |
1ad1cdc2 JM |
1989 | NLA_PUT(msg, NL80211_ATTR_KEY_SEQ, seq_len, seq); |
1990 | ||
3f5285e8 JM |
1991 | if (addr && os_memcmp(addr, "\xff\xff\xff\xff\xff\xff", ETH_ALEN) != 0) |
1992 | { | |
1993 | wpa_printf(MSG_DEBUG, " addr=" MACSTR, MAC2STR(addr)); | |
1994 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); | |
1995 | } | |
1996 | NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_idx); | |
1ad1cdc2 | 1997 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, ifindex); |
3f5285e8 | 1998 | |
1ad1cdc2 JM |
1999 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
2000 | if (ret == -ENOENT && alg == WPA_ALG_NONE) | |
2001 | ret = 0; | |
2002 | if (ret) | |
2003 | wpa_printf(MSG_DEBUG, "nl80211: set_key failed; err=%d %s)", | |
2004 | ret, strerror(-ret)); | |
3f5285e8 | 2005 | |
1ad1cdc2 JM |
2006 | /* |
2007 | * If we failed or don't need to set the default TX key (below), | |
2008 | * we're done here. | |
2009 | */ | |
2010 | if (ret || !set_tx || alg == WPA_ALG_NONE) | |
2011 | return ret; | |
2012 | #ifdef HOSTAPD /* FIX: is this needed? */ | |
2013 | if (addr) | |
2014 | return ret; | |
2015 | #endif /* HOSTAPD */ | |
3f5285e8 | 2016 | |
1ad1cdc2 JM |
2017 | msg = nlmsg_alloc(); |
2018 | if (!msg) | |
2019 | return -ENOMEM; | |
3f5285e8 | 2020 | |
1ad1cdc2 JM |
2021 | genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0, |
2022 | 0, NL80211_CMD_SET_KEY, 0); | |
2023 | NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_idx); | |
2024 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, ifindex); | |
2025 | if (alg == WPA_ALG_IGTK) | |
2026 | NLA_PUT_FLAG(msg, NL80211_ATTR_KEY_DEFAULT_MGMT); | |
2027 | else | |
2028 | NLA_PUT_FLAG(msg, NL80211_ATTR_KEY_DEFAULT); | |
3f5285e8 | 2029 | |
1ad1cdc2 JM |
2030 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
2031 | if (ret == -ENOENT) | |
2032 | ret = 0; | |
2033 | if (ret) | |
2034 | wpa_printf(MSG_DEBUG, "nl80211: set_key default failed; " | |
2035 | "err=%d %s)", ret, strerror(-ret)); | |
2036 | return ret; | |
3f5285e8 JM |
2037 | |
2038 | nla_put_failure: | |
6241fcb1 | 2039 | return -ENOBUFS; |
3f5285e8 JM |
2040 | } |
2041 | ||
2042 | ||
71934751 | 2043 | static int nl_add_key(struct nl_msg *msg, enum wpa_alg alg, |
0194fedb JB |
2044 | int key_idx, int defkey, |
2045 | const u8 *seq, size_t seq_len, | |
2046 | const u8 *key, size_t key_len) | |
2047 | { | |
2048 | struct nlattr *key_attr = nla_nest_start(msg, NL80211_ATTR_KEY); | |
2049 | if (!key_attr) | |
2050 | return -1; | |
2051 | ||
2052 | if (defkey && alg == WPA_ALG_IGTK) | |
2053 | NLA_PUT_FLAG(msg, NL80211_KEY_DEFAULT_MGMT); | |
2054 | else if (defkey) | |
2055 | NLA_PUT_FLAG(msg, NL80211_KEY_DEFAULT); | |
2056 | ||
2057 | NLA_PUT_U8(msg, NL80211_KEY_IDX, key_idx); | |
2058 | ||
d723bab4 JM |
2059 | switch (alg) { |
2060 | case WPA_ALG_WEP: | |
2061 | if (key_len == 5) | |
2aa5f847 JM |
2062 | NLA_PUT_U32(msg, NL80211_KEY_CIPHER, |
2063 | WLAN_CIPHER_SUITE_WEP40); | |
d723bab4 | 2064 | else |
2aa5f847 JM |
2065 | NLA_PUT_U32(msg, NL80211_KEY_CIPHER, |
2066 | WLAN_CIPHER_SUITE_WEP104); | |
d723bab4 JM |
2067 | break; |
2068 | case WPA_ALG_TKIP: | |
2aa5f847 | 2069 | NLA_PUT_U32(msg, NL80211_KEY_CIPHER, WLAN_CIPHER_SUITE_TKIP); |
d723bab4 JM |
2070 | break; |
2071 | case WPA_ALG_CCMP: | |
2aa5f847 | 2072 | NLA_PUT_U32(msg, NL80211_KEY_CIPHER, WLAN_CIPHER_SUITE_CCMP); |
d723bab4 JM |
2073 | break; |
2074 | case WPA_ALG_IGTK: | |
2aa5f847 JM |
2075 | NLA_PUT_U32(msg, NL80211_KEY_CIPHER, |
2076 | WLAN_CIPHER_SUITE_AES_CMAC); | |
d723bab4 JM |
2077 | break; |
2078 | default: | |
2079 | wpa_printf(MSG_ERROR, "%s: Unsupported encryption " | |
2080 | "algorithm %d", __func__, alg); | |
0194fedb | 2081 | return -1; |
d723bab4 | 2082 | } |
0194fedb JB |
2083 | |
2084 | if (seq && seq_len) | |
2085 | NLA_PUT(msg, NL80211_KEY_SEQ, seq_len, seq); | |
2086 | ||
2087 | NLA_PUT(msg, NL80211_KEY_DATA, key_len, key); | |
2088 | ||
2089 | nla_nest_end(msg, key_attr); | |
2090 | ||
2091 | return 0; | |
2092 | nla_put_failure: | |
2093 | return -1; | |
2094 | } | |
2095 | ||
c811d5bc | 2096 | |
cfaab580 ZY |
2097 | static int nl80211_set_conn_keys(struct wpa_driver_associate_params *params, |
2098 | struct nl_msg *msg) | |
2099 | { | |
2100 | int i, privacy = 0; | |
2101 | struct nlattr *nl_keys, *nl_key; | |
2102 | ||
2103 | for (i = 0; i < 4; i++) { | |
2104 | if (!params->wep_key[i]) | |
2105 | continue; | |
2106 | privacy = 1; | |
2107 | break; | |
2108 | } | |
2109 | if (!privacy) | |
2110 | return 0; | |
2111 | ||
2112 | NLA_PUT_FLAG(msg, NL80211_ATTR_PRIVACY); | |
2113 | ||
2114 | nl_keys = nla_nest_start(msg, NL80211_ATTR_KEYS); | |
2115 | if (!nl_keys) | |
2116 | goto nla_put_failure; | |
2117 | ||
2118 | for (i = 0; i < 4; i++) { | |
2119 | if (!params->wep_key[i]) | |
2120 | continue; | |
2121 | ||
2122 | nl_key = nla_nest_start(msg, i); | |
2123 | if (!nl_key) | |
2124 | goto nla_put_failure; | |
2125 | ||
2126 | NLA_PUT(msg, NL80211_KEY_DATA, params->wep_key_len[i], | |
2127 | params->wep_key[i]); | |
2128 | if (params->wep_key_len[i] == 5) | |
2129 | NLA_PUT_U32(msg, NL80211_KEY_CIPHER, | |
2130 | WLAN_CIPHER_SUITE_WEP40); | |
2131 | else | |
2132 | NLA_PUT_U32(msg, NL80211_KEY_CIPHER, | |
2133 | WLAN_CIPHER_SUITE_WEP104); | |
2134 | ||
2135 | NLA_PUT_U8(msg, NL80211_KEY_IDX, i); | |
2136 | ||
2137 | if (i == params->wep_tx_keyidx) | |
2138 | NLA_PUT_FLAG(msg, NL80211_KEY_DEFAULT); | |
2139 | ||
2140 | nla_nest_end(msg, nl_key); | |
2141 | } | |
2142 | nla_nest_end(msg, nl_keys); | |
2143 | ||
2144 | return 0; | |
2145 | ||
2146 | nla_put_failure: | |
2147 | return -ENOBUFS; | |
2148 | } | |
2149 | ||
2150 | ||
c2a04078 JM |
2151 | static int wpa_driver_nl80211_mlme(struct wpa_driver_nl80211_data *drv, |
2152 | const u8 *addr, int cmd, u16 reason_code) | |
2153 | { | |
2154 | int ret = -1; | |
2155 | struct nl_msg *msg; | |
2156 | ||
2157 | msg = nlmsg_alloc(); | |
2158 | if (!msg) | |
2159 | return -1; | |
2160 | ||
2161 | genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0, 0, cmd, 0); | |
2162 | ||
2163 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); | |
2164 | NLA_PUT_U16(msg, NL80211_ATTR_REASON_CODE, reason_code); | |
2165 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); | |
2166 | ||
2167 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
2168 | msg = NULL; | |
2169 | if (ret) { | |
2170 | wpa_printf(MSG_DEBUG, "nl80211: MLME command failed: ret=%d " | |
2171 | "(%s)", ret, strerror(-ret)); | |
2172 | goto nla_put_failure; | |
2173 | } | |
2174 | ret = 0; | |
2175 | ||
2176 | nla_put_failure: | |
2177 | nlmsg_free(msg); | |
2178 | return ret; | |
2179 | } | |
3f5285e8 JM |
2180 | |
2181 | ||
cfaab580 ZY |
2182 | static int wpa_driver_nl80211_disconnect(struct wpa_driver_nl80211_data *drv, |
2183 | const u8 *addr, int reason_code) | |
2184 | { | |
2185 | wpa_printf(MSG_DEBUG, "%s", __func__); | |
2186 | drv->associated = 0; | |
2187 | return wpa_driver_nl80211_mlme(drv, addr, NL80211_CMD_DISCONNECT, | |
2188 | reason_code); | |
2189 | } | |
2190 | ||
2191 | ||
3f5285e8 | 2192 | static int wpa_driver_nl80211_deauthenticate(void *priv, const u8 *addr, |
c2a04078 | 2193 | int reason_code) |
3f5285e8 | 2194 | { |
a2e40bb6 FF |
2195 | struct i802_bss *bss = priv; |
2196 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
cfaab580 ZY |
2197 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) |
2198 | return wpa_driver_nl80211_disconnect(drv, addr, reason_code); | |
c2a04078 | 2199 | wpa_printf(MSG_DEBUG, "%s", __func__); |
13405f35 | 2200 | drv->associated = 0; |
c2a04078 JM |
2201 | return wpa_driver_nl80211_mlme(drv, addr, NL80211_CMD_DEAUTHENTICATE, |
2202 | reason_code); | |
3f5285e8 JM |
2203 | } |
2204 | ||
2205 | ||
2206 | static int wpa_driver_nl80211_disassociate(void *priv, const u8 *addr, | |
c2a04078 | 2207 | int reason_code) |
3f5285e8 | 2208 | { |
a2e40bb6 FF |
2209 | struct i802_bss *bss = priv; |
2210 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
cfaab580 ZY |
2211 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) |
2212 | return wpa_driver_nl80211_disconnect(drv, addr, reason_code); | |
c2a04078 | 2213 | wpa_printf(MSG_DEBUG, "%s", __func__); |
13405f35 | 2214 | drv->associated = 0; |
c2a04078 JM |
2215 | return wpa_driver_nl80211_mlme(drv, addr, NL80211_CMD_DISASSOCIATE, |
2216 | reason_code); | |
3f5285e8 JM |
2217 | } |
2218 | ||
2219 | ||
c2a04078 JM |
2220 | static int wpa_driver_nl80211_authenticate( |
2221 | void *priv, struct wpa_driver_auth_params *params) | |
2222 | { | |
a2e40bb6 FF |
2223 | struct i802_bss *bss = priv; |
2224 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
a0b2f99b | 2225 | int ret = -1, i; |
c2a04078 JM |
2226 | struct nl_msg *msg; |
2227 | enum nl80211_auth_type type; | |
6d6f4bb8 | 2228 | int count = 0; |
c2a04078 JM |
2229 | |
2230 | drv->associated = 0; | |
e6b8efeb | 2231 | os_memset(drv->auth_bssid, 0, ETH_ALEN); |
af473088 JM |
2232 | /* FIX: IBSS mode */ |
2233 | if (drv->nlmode != NL80211_IFTYPE_STATION) | |
2234 | wpa_driver_nl80211_set_mode(priv, IEEE80211_MODE_INFRA); | |
c2a04078 | 2235 | |
a2e40bb6 | 2236 | if (wpa_driver_nl80211_set_mode(priv, IEEE80211_MODE_INFRA) < 0) |
4a867032 JM |
2237 | return -1; |
2238 | ||
6d6f4bb8 | 2239 | retry: |
c2a04078 JM |
2240 | msg = nlmsg_alloc(); |
2241 | if (!msg) | |
2242 | return -1; | |
2243 | ||
2244 | wpa_printf(MSG_DEBUG, "nl80211: Authenticate (ifindex=%d)", | |
2245 | drv->ifindex); | |
a0b2f99b | 2246 | |
0194fedb JB |
2247 | genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0, 0, |
2248 | NL80211_CMD_AUTHENTICATE, 0); | |
2249 | ||
a0b2f99b JM |
2250 | for (i = 0; i < 4; i++) { |
2251 | if (!params->wep_key[i]) | |
2252 | continue; | |
a2e40bb6 | 2253 | wpa_driver_nl80211_set_key(bss->ifname, drv, WPA_ALG_WEP, NULL, |
642187d6 | 2254 | i, |
a0b2f99b JM |
2255 | i == params->wep_tx_keyidx, NULL, 0, |
2256 | params->wep_key[i], | |
2257 | params->wep_key_len[i]); | |
0194fedb JB |
2258 | if (params->wep_tx_keyidx != i) |
2259 | continue; | |
2260 | if (nl_add_key(msg, WPA_ALG_WEP, i, 1, NULL, 0, | |
2261 | params->wep_key[i], params->wep_key_len[i])) { | |
2262 | nlmsg_free(msg); | |
2263 | return -1; | |
2264 | } | |
a0b2f99b JM |
2265 | } |
2266 | ||
c2a04078 JM |
2267 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); |
2268 | if (params->bssid) { | |
2269 | wpa_printf(MSG_DEBUG, " * bssid=" MACSTR, | |
2270 | MAC2STR(params->bssid)); | |
2271 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid); | |
2272 | } | |
2273 | if (params->freq) { | |
2274 | wpa_printf(MSG_DEBUG, " * freq=%d", params->freq); | |
2275 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, params->freq); | |
2276 | } | |
2277 | if (params->ssid) { | |
2278 | wpa_hexdump_ascii(MSG_DEBUG, " * SSID", | |
2279 | params->ssid, params->ssid_len); | |
2280 | NLA_PUT(msg, NL80211_ATTR_SSID, params->ssid_len, | |
2281 | params->ssid); | |
2282 | } | |
2283 | wpa_hexdump(MSG_DEBUG, " * IEs", params->ie, params->ie_len); | |
2284 | if (params->ie) | |
2285 | NLA_PUT(msg, NL80211_ATTR_IE, params->ie_len, params->ie); | |
2286 | /* | |
2287 | * TODO: if multiple auth_alg options enabled, try them one by one if | |
2288 | * the AP rejects authentication due to unknown auth alg | |
2289 | */ | |
abd9fafa | 2290 | if (params->auth_alg & WPA_AUTH_ALG_OPEN) |
c2a04078 | 2291 | type = NL80211_AUTHTYPE_OPEN_SYSTEM; |
abd9fafa | 2292 | else if (params->auth_alg & WPA_AUTH_ALG_SHARED) |
c2a04078 | 2293 | type = NL80211_AUTHTYPE_SHARED_KEY; |
abd9fafa | 2294 | else if (params->auth_alg & WPA_AUTH_ALG_LEAP) |
c2a04078 | 2295 | type = NL80211_AUTHTYPE_NETWORK_EAP; |
abd9fafa | 2296 | else if (params->auth_alg & WPA_AUTH_ALG_FT) |
c2a04078 JM |
2297 | type = NL80211_AUTHTYPE_FT; |
2298 | else | |
2299 | goto nla_put_failure; | |
2300 | wpa_printf(MSG_DEBUG, " * Auth Type %d", type); | |
2301 | NLA_PUT_U32(msg, NL80211_ATTR_AUTH_TYPE, type); | |
2302 | ||
2303 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
2304 | msg = NULL; | |
2305 | if (ret) { | |
2306 | wpa_printf(MSG_DEBUG, "nl80211: MLME command failed: ret=%d " | |
2307 | "(%s)", ret, strerror(-ret)); | |
6d6f4bb8 JM |
2308 | count++; |
2309 | if (ret == -EALREADY && count == 1 && params->bssid) { | |
2310 | /* | |
2311 | * mac80211 does not currently accept new | |
2312 | * authentication if we are already authenticated. As a | |
2313 | * workaround, force deauthentication and try again. | |
2314 | */ | |
2315 | wpa_printf(MSG_DEBUG, "nl80211: Retry authentication " | |
2316 | "after forced deauthentication"); | |
2317 | wpa_driver_nl80211_deauthenticate( | |
2318 | drv, params->bssid, | |
2319 | WLAN_REASON_PREV_AUTH_NOT_VALID); | |
2320 | nlmsg_free(msg); | |
2321 | goto retry; | |
2322 | } | |
c2a04078 JM |
2323 | goto nla_put_failure; |
2324 | } | |
2325 | ret = 0; | |
2326 | wpa_printf(MSG_DEBUG, "nl80211: Authentication request send " | |
2327 | "successfully"); | |
2328 | ||
2329 | nla_put_failure: | |
2330 | nlmsg_free(msg); | |
2331 | return ret; | |
2332 | } | |
2333 | ||
2334 | ||
282d5590 JM |
2335 | struct phy_info_arg { |
2336 | u16 *num_modes; | |
2337 | struct hostapd_hw_modes *modes; | |
2338 | }; | |
2339 | ||
2340 | static int phy_info_handler(struct nl_msg *msg, void *arg) | |
2341 | { | |
2342 | struct nlattr *tb_msg[NL80211_ATTR_MAX + 1]; | |
2343 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
2344 | struct phy_info_arg *phy_info = arg; | |
2345 | ||
2346 | struct nlattr *tb_band[NL80211_BAND_ATTR_MAX + 1]; | |
2347 | ||
2348 | struct nlattr *tb_freq[NL80211_FREQUENCY_ATTR_MAX + 1]; | |
2349 | static struct nla_policy freq_policy[NL80211_FREQUENCY_ATTR_MAX + 1] = { | |
2350 | [NL80211_FREQUENCY_ATTR_FREQ] = { .type = NLA_U32 }, | |
2351 | [NL80211_FREQUENCY_ATTR_DISABLED] = { .type = NLA_FLAG }, | |
2352 | [NL80211_FREQUENCY_ATTR_PASSIVE_SCAN] = { .type = NLA_FLAG }, | |
2353 | [NL80211_FREQUENCY_ATTR_NO_IBSS] = { .type = NLA_FLAG }, | |
2354 | [NL80211_FREQUENCY_ATTR_RADAR] = { .type = NLA_FLAG }, | |
2355 | [NL80211_FREQUENCY_ATTR_MAX_TX_POWER] = { .type = NLA_U32 }, | |
2356 | }; | |
2357 | ||
2358 | struct nlattr *tb_rate[NL80211_BITRATE_ATTR_MAX + 1]; | |
2359 | static struct nla_policy rate_policy[NL80211_BITRATE_ATTR_MAX + 1] = { | |
2360 | [NL80211_BITRATE_ATTR_RATE] = { .type = NLA_U32 }, | |
2361 | [NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE] = { .type = NLA_FLAG }, | |
2362 | }; | |
2363 | ||
2364 | struct nlattr *nl_band; | |
2365 | struct nlattr *nl_freq; | |
2366 | struct nlattr *nl_rate; | |
2367 | int rem_band, rem_freq, rem_rate; | |
2368 | struct hostapd_hw_modes *mode; | |
2369 | int idx, mode_is_set; | |
2370 | ||
2371 | nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
2372 | genlmsg_attrlen(gnlh, 0), NULL); | |
2373 | ||
2374 | if (!tb_msg[NL80211_ATTR_WIPHY_BANDS]) | |
2375 | return NL_SKIP; | |
2376 | ||
2377 | nla_for_each_nested(nl_band, tb_msg[NL80211_ATTR_WIPHY_BANDS], rem_band) { | |
e62fb0a0 | 2378 | mode = os_realloc(phy_info->modes, (*phy_info->num_modes + 1) * sizeof(*mode)); |
282d5590 JM |
2379 | if (!mode) |
2380 | return NL_SKIP; | |
2381 | phy_info->modes = mode; | |
2382 | ||
2383 | mode_is_set = 0; | |
2384 | ||
2385 | mode = &phy_info->modes[*(phy_info->num_modes)]; | |
2386 | memset(mode, 0, sizeof(*mode)); | |
2387 | *(phy_info->num_modes) += 1; | |
2388 | ||
2389 | nla_parse(tb_band, NL80211_BAND_ATTR_MAX, nla_data(nl_band), | |
2390 | nla_len(nl_band), NULL); | |
2391 | ||
2392 | if (tb_band[NL80211_BAND_ATTR_HT_CAPA]) { | |
2393 | mode->ht_capab = nla_get_u16( | |
2394 | tb_band[NL80211_BAND_ATTR_HT_CAPA]); | |
2395 | } | |
2396 | ||
be8eb8ab JM |
2397 | if (tb_band[NL80211_BAND_ATTR_HT_AMPDU_FACTOR]) { |
2398 | mode->a_mpdu_params |= nla_get_u8( | |
2399 | tb_band[NL80211_BAND_ATTR_HT_AMPDU_FACTOR]) & | |
2400 | 0x03; | |
2401 | } | |
2402 | ||
2403 | if (tb_band[NL80211_BAND_ATTR_HT_AMPDU_DENSITY]) { | |
2404 | mode->a_mpdu_params |= nla_get_u8( | |
2405 | tb_band[NL80211_BAND_ATTR_HT_AMPDU_DENSITY]) << | |
2406 | 2; | |
2407 | } | |
2408 | ||
08eb154d JM |
2409 | if (tb_band[NL80211_BAND_ATTR_HT_MCS_SET] && |
2410 | nla_len(tb_band[NL80211_BAND_ATTR_HT_MCS_SET])) { | |
2411 | u8 *mcs; | |
2412 | mcs = nla_data(tb_band[NL80211_BAND_ATTR_HT_MCS_SET]); | |
2413 | os_memcpy(mode->mcs_set, mcs, 16); | |
2414 | } | |
2415 | ||
282d5590 JM |
2416 | nla_for_each_nested(nl_freq, tb_band[NL80211_BAND_ATTR_FREQS], rem_freq) { |
2417 | nla_parse(tb_freq, NL80211_FREQUENCY_ATTR_MAX, nla_data(nl_freq), | |
2418 | nla_len(nl_freq), freq_policy); | |
2419 | if (!tb_freq[NL80211_FREQUENCY_ATTR_FREQ]) | |
2420 | continue; | |
2421 | mode->num_channels++; | |
2422 | } | |
2423 | ||
e62fb0a0 | 2424 | mode->channels = os_zalloc(mode->num_channels * sizeof(struct hostapd_channel_data)); |
282d5590 JM |
2425 | if (!mode->channels) |
2426 | return NL_SKIP; | |
2427 | ||
2428 | idx = 0; | |
2429 | ||
2430 | nla_for_each_nested(nl_freq, tb_band[NL80211_BAND_ATTR_FREQS], rem_freq) { | |
2431 | nla_parse(tb_freq, NL80211_FREQUENCY_ATTR_MAX, nla_data(nl_freq), | |
2432 | nla_len(nl_freq), freq_policy); | |
2433 | if (!tb_freq[NL80211_FREQUENCY_ATTR_FREQ]) | |
2434 | continue; | |
2435 | ||
2436 | mode->channels[idx].freq = nla_get_u32(tb_freq[NL80211_FREQUENCY_ATTR_FREQ]); | |
2437 | mode->channels[idx].flag = 0; | |
2438 | ||
2439 | if (!mode_is_set) { | |
2440 | /* crude heuristic */ | |
2441 | if (mode->channels[idx].freq < 4000) | |
2442 | mode->mode = HOSTAPD_MODE_IEEE80211B; | |
2443 | else | |
2444 | mode->mode = HOSTAPD_MODE_IEEE80211A; | |
2445 | mode_is_set = 1; | |
2446 | } | |
2447 | ||
2448 | /* crude heuristic */ | |
2449 | if (mode->channels[idx].freq < 4000) | |
5a0ffb5f | 2450 | if (mode->channels[idx].freq == 2484) |
282d5590 JM |
2451 | mode->channels[idx].chan = 14; |
2452 | else | |
2453 | mode->channels[idx].chan = (mode->channels[idx].freq - 2407) / 5; | |
2454 | else | |
2455 | mode->channels[idx].chan = mode->channels[idx].freq/5 - 1000; | |
2456 | ||
2457 | if (tb_freq[NL80211_FREQUENCY_ATTR_DISABLED]) | |
2458 | mode->channels[idx].flag |= | |
2459 | HOSTAPD_CHAN_DISABLED; | |
2460 | if (tb_freq[NL80211_FREQUENCY_ATTR_PASSIVE_SCAN]) | |
2461 | mode->channels[idx].flag |= | |
2462 | HOSTAPD_CHAN_PASSIVE_SCAN; | |
2463 | if (tb_freq[NL80211_FREQUENCY_ATTR_NO_IBSS]) | |
2464 | mode->channels[idx].flag |= | |
2465 | HOSTAPD_CHAN_NO_IBSS; | |
2466 | if (tb_freq[NL80211_FREQUENCY_ATTR_RADAR]) | |
2467 | mode->channels[idx].flag |= | |
2468 | HOSTAPD_CHAN_RADAR; | |
2469 | ||
2470 | if (tb_freq[NL80211_FREQUENCY_ATTR_MAX_TX_POWER] && | |
2471 | !tb_freq[NL80211_FREQUENCY_ATTR_DISABLED]) | |
2472 | mode->channels[idx].max_tx_power = | |
2473 | nla_get_u32(tb_freq[NL80211_FREQUENCY_ATTR_MAX_TX_POWER]) / 100; | |
2474 | ||
2475 | idx++; | |
2476 | } | |
2477 | ||
2478 | nla_for_each_nested(nl_rate, tb_band[NL80211_BAND_ATTR_RATES], rem_rate) { | |
2479 | nla_parse(tb_rate, NL80211_BITRATE_ATTR_MAX, nla_data(nl_rate), | |
2480 | nla_len(nl_rate), rate_policy); | |
2481 | if (!tb_rate[NL80211_BITRATE_ATTR_RATE]) | |
2482 | continue; | |
2483 | mode->num_rates++; | |
2484 | } | |
2485 | ||
e62fb0a0 | 2486 | mode->rates = os_zalloc(mode->num_rates * sizeof(int)); |
282d5590 JM |
2487 | if (!mode->rates) |
2488 | return NL_SKIP; | |
2489 | ||
2490 | idx = 0; | |
2491 | ||
2492 | nla_for_each_nested(nl_rate, tb_band[NL80211_BAND_ATTR_RATES], rem_rate) { | |
2493 | nla_parse(tb_rate, NL80211_BITRATE_ATTR_MAX, nla_data(nl_rate), | |
2494 | nla_len(nl_rate), rate_policy); | |
2495 | if (!tb_rate[NL80211_BITRATE_ATTR_RATE]) | |
2496 | continue; | |
fb7842aa | 2497 | mode->rates[idx] = nla_get_u32(tb_rate[NL80211_BITRATE_ATTR_RATE]); |
282d5590 JM |
2498 | |
2499 | /* crude heuristic */ | |
2500 | if (mode->mode == HOSTAPD_MODE_IEEE80211B && | |
fb7842aa | 2501 | mode->rates[idx] > 200) |
282d5590 JM |
2502 | mode->mode = HOSTAPD_MODE_IEEE80211G; |
2503 | ||
282d5590 JM |
2504 | idx++; |
2505 | } | |
2506 | } | |
2507 | ||
2508 | return NL_SKIP; | |
2509 | } | |
2510 | ||
2511 | static struct hostapd_hw_modes * | |
2512 | wpa_driver_nl80211_add_11b(struct hostapd_hw_modes *modes, u16 *num_modes) | |
2513 | { | |
2514 | u16 m; | |
2515 | struct hostapd_hw_modes *mode11g = NULL, *nmodes, *mode; | |
2516 | int i, mode11g_idx = -1; | |
2517 | ||
2518 | /* If only 802.11g mode is included, use it to construct matching | |
2519 | * 802.11b mode data. */ | |
2520 | ||
2521 | for (m = 0; m < *num_modes; m++) { | |
2522 | if (modes[m].mode == HOSTAPD_MODE_IEEE80211B) | |
2523 | return modes; /* 802.11b already included */ | |
2524 | if (modes[m].mode == HOSTAPD_MODE_IEEE80211G) | |
2525 | mode11g_idx = m; | |
2526 | } | |
2527 | ||
2528 | if (mode11g_idx < 0) | |
2529 | return modes; /* 2.4 GHz band not supported at all */ | |
2530 | ||
2531 | nmodes = os_realloc(modes, (*num_modes + 1) * sizeof(*nmodes)); | |
2532 | if (nmodes == NULL) | |
2533 | return modes; /* Could not add 802.11b mode */ | |
2534 | ||
2535 | mode = &nmodes[*num_modes]; | |
2536 | os_memset(mode, 0, sizeof(*mode)); | |
2537 | (*num_modes)++; | |
2538 | modes = nmodes; | |
2539 | ||
2540 | mode->mode = HOSTAPD_MODE_IEEE80211B; | |
2541 | ||
2542 | mode11g = &modes[mode11g_idx]; | |
2543 | mode->num_channels = mode11g->num_channels; | |
2544 | mode->channels = os_malloc(mode11g->num_channels * | |
2545 | sizeof(struct hostapd_channel_data)); | |
2546 | if (mode->channels == NULL) { | |
2547 | (*num_modes)--; | |
2548 | return modes; /* Could not add 802.11b mode */ | |
2549 | } | |
2550 | os_memcpy(mode->channels, mode11g->channels, | |
2551 | mode11g->num_channels * sizeof(struct hostapd_channel_data)); | |
2552 | ||
2553 | mode->num_rates = 0; | |
fb7842aa | 2554 | mode->rates = os_malloc(4 * sizeof(int)); |
282d5590 JM |
2555 | if (mode->rates == NULL) { |
2556 | os_free(mode->channels); | |
2557 | (*num_modes)--; | |
2558 | return modes; /* Could not add 802.11b mode */ | |
2559 | } | |
2560 | ||
2561 | for (i = 0; i < mode11g->num_rates; i++) { | |
fb7842aa JM |
2562 | if (mode11g->rates[i] != 10 && mode11g->rates[i] != 20 && |
2563 | mode11g->rates[i] != 55 && mode11g->rates[i] != 110) | |
282d5590 JM |
2564 | continue; |
2565 | mode->rates[mode->num_rates] = mode11g->rates[i]; | |
2566 | mode->num_rates++; | |
2567 | if (mode->num_rates == 4) | |
2568 | break; | |
2569 | } | |
2570 | ||
2571 | if (mode->num_rates == 0) { | |
2572 | os_free(mode->channels); | |
2573 | os_free(mode->rates); | |
2574 | (*num_modes)--; | |
2575 | return modes; /* No 802.11b rates */ | |
2576 | } | |
2577 | ||
2578 | wpa_printf(MSG_DEBUG, "nl80211: Added 802.11b mode based on 802.11g " | |
2579 | "information"); | |
2580 | ||
2581 | return modes; | |
2582 | } | |
2583 | ||
2584 | ||
2585 | static struct hostapd_hw_modes * | |
2586 | wpa_driver_nl80211_get_hw_feature_data(void *priv, u16 *num_modes, u16 *flags) | |
2587 | { | |
a2e40bb6 FF |
2588 | struct i802_bss *bss = priv; |
2589 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
282d5590 JM |
2590 | struct nl_msg *msg; |
2591 | struct phy_info_arg result = { | |
2592 | .num_modes = num_modes, | |
2593 | .modes = NULL, | |
2594 | }; | |
2595 | ||
2596 | *num_modes = 0; | |
2597 | *flags = 0; | |
2598 | ||
2599 | msg = nlmsg_alloc(); | |
2600 | if (!msg) | |
2601 | return NULL; | |
2602 | ||
2603 | genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0, | |
2604 | 0, NL80211_CMD_GET_WIPHY, 0); | |
2605 | ||
2606 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); | |
2607 | ||
2608 | if (send_and_recv_msgs(drv, msg, phy_info_handler, &result) == 0) | |
2609 | return wpa_driver_nl80211_add_11b(result.modes, num_modes); | |
2610 | nla_put_failure: | |
2611 | return NULL; | |
2612 | } | |
2613 | ||
2614 | ||
2c2010ac JM |
2615 | static int wpa_driver_nl80211_send_frame(struct wpa_driver_nl80211_data *drv, |
2616 | const void *data, size_t len, | |
2617 | int encrypt) | |
2618 | { | |
2619 | __u8 rtap_hdr[] = { | |
2620 | 0x00, 0x00, /* radiotap version */ | |
2621 | 0x0e, 0x00, /* radiotap length */ | |
2622 | 0x02, 0xc0, 0x00, 0x00, /* bmap: flags, tx and rx flags */ | |
2623 | IEEE80211_RADIOTAP_F_FRAG, /* F_FRAG (fragment if required) */ | |
2624 | 0x00, /* padding */ | |
2625 | 0x00, 0x00, /* RX and TX flags to indicate that */ | |
2626 | 0x00, 0x00, /* this is the injected frame directly */ | |
2627 | }; | |
2628 | struct iovec iov[2] = { | |
2629 | { | |
2630 | .iov_base = &rtap_hdr, | |
2631 | .iov_len = sizeof(rtap_hdr), | |
2632 | }, | |
2633 | { | |
2634 | .iov_base = (void *) data, | |
2635 | .iov_len = len, | |
2636 | } | |
2637 | }; | |
2638 | struct msghdr msg = { | |
2639 | .msg_name = NULL, | |
2640 | .msg_namelen = 0, | |
2641 | .msg_iov = iov, | |
2642 | .msg_iovlen = 2, | |
2643 | .msg_control = NULL, | |
2644 | .msg_controllen = 0, | |
2645 | .msg_flags = 0, | |
2646 | }; | |
2647 | ||
2648 | if (encrypt) | |
2649 | rtap_hdr[8] |= IEEE80211_RADIOTAP_F_WEP; | |
2650 | ||
2651 | return sendmsg(drv->monitor_sock, &msg, 0); | |
2652 | } | |
2653 | ||
2654 | ||
2655 | static int wpa_driver_nl80211_send_mlme(void *priv, const u8 *data, | |
2656 | size_t data_len) | |
2657 | { | |
a2e40bb6 FF |
2658 | struct i802_bss *bss = priv; |
2659 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
2c2010ac | 2660 | struct ieee80211_mgmt *mgmt; |
7a47d567 | 2661 | int encrypt = 1; |
2c2010ac JM |
2662 | u16 fc; |
2663 | ||
2664 | mgmt = (struct ieee80211_mgmt *) data; | |
2665 | fc = le_to_host16(mgmt->frame_control); | |
2666 | ||
2667 | if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && | |
2668 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_AUTH) { | |
2669 | /* | |
2670 | * Only one of the authentication frame types is encrypted. | |
2671 | * In order for static WEP encryption to work properly (i.e., | |
2672 | * to not encrypt the frame), we need to tell mac80211 about | |
2673 | * the frames that must not be encrypted. | |
2674 | */ | |
2675 | u16 auth_alg = le_to_host16(mgmt->u.auth.auth_alg); | |
2676 | u16 auth_trans = le_to_host16(mgmt->u.auth.auth_transaction); | |
7a47d567 JB |
2677 | if (auth_alg != WLAN_AUTH_SHARED_KEY || auth_trans != 3) |
2678 | encrypt = 0; | |
2c2010ac JM |
2679 | } |
2680 | ||
7a47d567 | 2681 | return wpa_driver_nl80211_send_frame(drv, data, data_len, encrypt); |
2c2010ac JM |
2682 | } |
2683 | ||
2684 | ||
5d674872 JM |
2685 | static int wpa_driver_nl80211_set_beacon(const char *ifname, void *priv, |
2686 | const u8 *head, size_t head_len, | |
2687 | const u8 *tail, size_t tail_len, | |
2688 | int dtim_period, int beacon_int) | |
d2440ba0 | 2689 | { |
a2e40bb6 FF |
2690 | struct i802_bss *bss = priv; |
2691 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
d2440ba0 JM |
2692 | struct nl_msg *msg; |
2693 | u8 cmd = NL80211_CMD_NEW_BEACON; | |
2694 | int ret; | |
b4fd6fab | 2695 | int beacon_set; |
5d674872 | 2696 | int ifindex = if_nametoindex(ifname); |
b4fd6fab | 2697 | |
b4fd6fab | 2698 | beacon_set = bss->beacon_set; |
d2440ba0 JM |
2699 | |
2700 | msg = nlmsg_alloc(); | |
2701 | if (!msg) | |
2702 | return -ENOMEM; | |
2703 | ||
2704 | wpa_printf(MSG_DEBUG, "nl80211: Set beacon (beacon_set=%d)", | |
b4fd6fab JM |
2705 | beacon_set); |
2706 | if (beacon_set) | |
d2440ba0 JM |
2707 | cmd = NL80211_CMD_SET_BEACON; |
2708 | ||
2709 | genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0, | |
2710 | 0, cmd, 0); | |
2711 | NLA_PUT(msg, NL80211_ATTR_BEACON_HEAD, head_len, head); | |
2712 | NLA_PUT(msg, NL80211_ATTR_BEACON_TAIL, tail_len, tail); | |
b4fd6fab | 2713 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, ifindex); |
5d674872 | 2714 | NLA_PUT_U32(msg, NL80211_ATTR_BEACON_INTERVAL, beacon_int); |
d2440ba0 JM |
2715 | NLA_PUT_U32(msg, NL80211_ATTR_DTIM_PERIOD, dtim_period); |
2716 | ||
2717 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
2718 | if (ret) { | |
2719 | wpa_printf(MSG_DEBUG, "nl80211: Beacon set failed: %d (%s)", | |
2720 | ret, strerror(-ret)); | |
b4fd6fab | 2721 | } else { |
b4fd6fab | 2722 | bss->beacon_set = 1; |
b4fd6fab | 2723 | } |
d2440ba0 JM |
2724 | return ret; |
2725 | nla_put_failure: | |
2726 | return -ENOBUFS; | |
2727 | } | |
2728 | ||
2729 | ||
f019981a JM |
2730 | static int wpa_driver_nl80211_set_freq(struct wpa_driver_nl80211_data *drv, |
2731 | int freq, int ht_enabled, | |
2732 | int sec_channel_offset) | |
1581b38b JM |
2733 | { |
2734 | struct nl_msg *msg; | |
d2440ba0 | 2735 | int ret; |
1581b38b JM |
2736 | |
2737 | msg = nlmsg_alloc(); | |
2738 | if (!msg) | |
2739 | return -1; | |
2740 | ||
2741 | genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0, 0, | |
2742 | NL80211_CMD_SET_WIPHY, 0); | |
2743 | ||
2744 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); | |
f019981a JM |
2745 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, freq); |
2746 | if (ht_enabled) { | |
2747 | switch (sec_channel_offset) { | |
2748 | case -1: | |
2749 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, | |
2750 | NL80211_CHAN_HT40MINUS); | |
2751 | break; | |
2752 | case 1: | |
2753 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, | |
2754 | NL80211_CHAN_HT40PLUS); | |
2755 | break; | |
2756 | default: | |
2757 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, | |
2758 | NL80211_CHAN_HT20); | |
2759 | break; | |
2760 | } | |
2761 | } | |
1581b38b | 2762 | |
d2440ba0 JM |
2763 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
2764 | if (ret == 0) | |
1581b38b | 2765 | return 0; |
f019981a JM |
2766 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set channel (freq=%d): " |
2767 | "%d (%s)", freq, ret, strerror(-ret)); | |
1581b38b JM |
2768 | nla_put_failure: |
2769 | return -1; | |
2770 | } | |
2771 | ||
0f4e8b4f JM |
2772 | |
2773 | static int wpa_driver_nl80211_sta_add(const char *ifname, void *priv, | |
2774 | struct hostapd_sta_add_params *params) | |
2775 | { | |
a2e40bb6 FF |
2776 | struct i802_bss *bss = priv; |
2777 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
0f4e8b4f JM |
2778 | struct nl_msg *msg; |
2779 | int ret = -ENOBUFS; | |
2780 | ||
2781 | msg = nlmsg_alloc(); | |
2782 | if (!msg) | |
2783 | return -ENOMEM; | |
2784 | ||
2785 | genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0, | |
2786 | 0, NL80211_CMD_NEW_STATION, 0); | |
2787 | ||
2788 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(ifname)); | |
2789 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, params->addr); | |
2790 | NLA_PUT_U16(msg, NL80211_ATTR_STA_AID, params->aid); | |
2791 | NLA_PUT(msg, NL80211_ATTR_STA_SUPPORTED_RATES, params->supp_rates_len, | |
2792 | params->supp_rates); | |
2793 | NLA_PUT_U16(msg, NL80211_ATTR_STA_LISTEN_INTERVAL, | |
2794 | params->listen_interval); | |
0f4e8b4f JM |
2795 | if (params->ht_capabilities) { |
2796 | NLA_PUT(msg, NL80211_ATTR_HT_CAPABILITY, | |
fc4e2d95 JM |
2797 | sizeof(*params->ht_capabilities), |
2798 | params->ht_capabilities); | |
0f4e8b4f | 2799 | } |
0f4e8b4f JM |
2800 | |
2801 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
2802 | if (ret) | |
2803 | wpa_printf(MSG_DEBUG, "nl80211: NL80211_CMD_NEW_STATION " | |
2804 | "result: %d (%s)", ret, strerror(-ret)); | |
2805 | if (ret == -EEXIST) | |
2806 | ret = 0; | |
2807 | nla_put_failure: | |
2808 | return ret; | |
2809 | } | |
2810 | ||
2811 | ||
2812 | static int wpa_driver_nl80211_sta_remove(void *priv, const u8 *addr) | |
2813 | { | |
a2e40bb6 FF |
2814 | struct i802_bss *bss = priv; |
2815 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
0f4e8b4f JM |
2816 | struct nl_msg *msg; |
2817 | int ret; | |
2818 | ||
2819 | msg = nlmsg_alloc(); | |
2820 | if (!msg) | |
2821 | return -ENOMEM; | |
2822 | ||
2823 | genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0, | |
2824 | 0, NL80211_CMD_DEL_STATION, 0); | |
2825 | ||
2826 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, | |
a2e40bb6 | 2827 | if_nametoindex(bss->ifname)); |
0f4e8b4f JM |
2828 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); |
2829 | ||
2830 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
2831 | if (ret == -ENOENT) | |
2832 | return 0; | |
2833 | return ret; | |
2834 | nla_put_failure: | |
2835 | return -ENOBUFS; | |
2836 | } | |
2837 | ||
1581b38b | 2838 | |
0915d02c JM |
2839 | static void nl80211_remove_iface(struct wpa_driver_nl80211_data *drv, |
2840 | int ifidx) | |
2841 | { | |
2842 | struct nl_msg *msg; | |
2843 | ||
c6e8e8e4 JM |
2844 | wpa_printf(MSG_DEBUG, "nl80211: Remove interface ifindex=%d", ifidx); |
2845 | ||
2135f224 JM |
2846 | #ifdef HOSTAPD |
2847 | /* stop listening for EAPOL on this interface */ | |
2848 | del_ifidx(drv, ifidx); | |
2849 | #endif /* HOSTAPD */ | |
2850 | ||
0915d02c JM |
2851 | msg = nlmsg_alloc(); |
2852 | if (!msg) | |
2853 | goto nla_put_failure; | |
2854 | ||
2855 | genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0, | |
2856 | 0, NL80211_CMD_DEL_INTERFACE, 0); | |
2857 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, ifidx); | |
2858 | ||
2859 | if (send_and_recv_msgs(drv, msg, NULL, NULL) == 0) | |
2860 | return; | |
2861 | nla_put_failure: | |
e748062b | 2862 | wpa_printf(MSG_ERROR, "Failed to remove interface (ifidx=%d)", ifidx); |
0915d02c JM |
2863 | } |
2864 | ||
2865 | ||
a35187e7 KH |
2866 | static int nl80211_create_iface_once(struct wpa_driver_nl80211_data *drv, |
2867 | const char *ifname, | |
2868 | enum nl80211_iftype iftype, | |
fbbfcbac | 2869 | const u8 *addr, int wds) |
0915d02c JM |
2870 | { |
2871 | struct nl_msg *msg, *flags = NULL; | |
2872 | int ifidx; | |
2873 | int ret = -ENOBUFS; | |
2874 | ||
2875 | msg = nlmsg_alloc(); | |
2876 | if (!msg) | |
2877 | return -1; | |
2878 | ||
2879 | genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0, | |
2880 | 0, NL80211_CMD_NEW_INTERFACE, 0); | |
2881 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); | |
2882 | NLA_PUT_STRING(msg, NL80211_ATTR_IFNAME, ifname); | |
2883 | NLA_PUT_U32(msg, NL80211_ATTR_IFTYPE, iftype); | |
2884 | ||
2885 | if (iftype == NL80211_IFTYPE_MONITOR) { | |
2886 | int err; | |
2887 | ||
2888 | flags = nlmsg_alloc(); | |
2889 | if (!flags) | |
2890 | goto nla_put_failure; | |
2891 | ||
2892 | NLA_PUT_FLAG(flags, NL80211_MNTR_FLAG_COOK_FRAMES); | |
2893 | ||
2894 | err = nla_put_nested(msg, NL80211_ATTR_MNTR_FLAGS, flags); | |
2895 | ||
2896 | nlmsg_free(flags); | |
2897 | ||
2898 | if (err) | |
2899 | goto nla_put_failure; | |
fbbfcbac FF |
2900 | } else if (wds) { |
2901 | NLA_PUT_U8(msg, NL80211_ATTR_4ADDR, wds); | |
0915d02c JM |
2902 | } |
2903 | ||
2904 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
2905 | if (ret) { | |
2906 | nla_put_failure: | |
a35187e7 KH |
2907 | wpa_printf(MSG_ERROR, "Failed to create interface %s: %d (%s)", |
2908 | ifname, ret, strerror(-ret)); | |
0915d02c JM |
2909 | return ret; |
2910 | } | |
2911 | ||
2912 | ifidx = if_nametoindex(ifname); | |
c6e8e8e4 JM |
2913 | wpa_printf(MSG_DEBUG, "nl80211: New interface %s created: ifindex=%d", |
2914 | ifname, ifidx); | |
0915d02c JM |
2915 | |
2916 | if (ifidx <= 0) | |
2917 | return -1; | |
2918 | ||
2135f224 JM |
2919 | #ifdef HOSTAPD |
2920 | /* start listening for EAPOL on this interface */ | |
2921 | add_ifidx(drv, ifidx); | |
7bfc47c3 | 2922 | #endif /* HOSTAPD */ |
2135f224 | 2923 | |
7bfc47c3 | 2924 | if (addr && iftype != NL80211_IFTYPE_MONITOR && |
2ac9688e | 2925 | linux_set_ifhwaddr(drv->ioctl_sock, ifname, addr)) { |
41d931ee JM |
2926 | nl80211_remove_iface(drv, ifidx); |
2927 | return -1; | |
2135f224 | 2928 | } |
2135f224 | 2929 | |
0915d02c JM |
2930 | return ifidx; |
2931 | } | |
22a7c9d7 JM |
2932 | |
2933 | ||
a35187e7 KH |
2934 | static int nl80211_create_iface(struct wpa_driver_nl80211_data *drv, |
2935 | const char *ifname, enum nl80211_iftype iftype, | |
fbbfcbac | 2936 | const u8 *addr, int wds) |
a35187e7 KH |
2937 | { |
2938 | int ret; | |
2939 | ||
fbbfcbac | 2940 | ret = nl80211_create_iface_once(drv, ifname, iftype, addr, wds); |
a35187e7 KH |
2941 | |
2942 | /* if error occured and interface exists already */ | |
2943 | if (ret == -ENFILE && if_nametoindex(ifname)) { | |
2944 | wpa_printf(MSG_INFO, "Try to remove and re-create %s", ifname); | |
2945 | ||
2946 | /* Try to remove the interface that was already there. */ | |
2947 | nl80211_remove_iface(drv, if_nametoindex(ifname)); | |
2948 | ||
2949 | /* Try to create the interface again */ | |
fbbfcbac FF |
2950 | ret = nl80211_create_iface_once(drv, ifname, iftype, addr, |
2951 | wds); | |
a35187e7 KH |
2952 | } |
2953 | ||
4e5cb1a3 JM |
2954 | if (ret >= 0 && drv->disable_11b_rates) |
2955 | nl80211_disable_11b_rates(drv, ret, 1); | |
2956 | ||
a35187e7 KH |
2957 | return ret; |
2958 | } | |
0915d02c | 2959 | |
2135f224 | 2960 | |
0915d02c JM |
2961 | static void handle_tx_callback(void *ctx, u8 *buf, size_t len, int ok) |
2962 | { | |
2963 | struct ieee80211_hdr *hdr; | |
f8b1f695 JM |
2964 | u16 fc; |
2965 | union wpa_event_data event; | |
0915d02c JM |
2966 | |
2967 | hdr = (struct ieee80211_hdr *) buf; | |
2968 | fc = le_to_host16(hdr->frame_control); | |
2969 | ||
f8b1f695 JM |
2970 | os_memset(&event, 0, sizeof(event)); |
2971 | event.tx_status.type = WLAN_FC_GET_TYPE(fc); | |
2972 | event.tx_status.stype = WLAN_FC_GET_STYPE(fc); | |
2973 | event.tx_status.dst = hdr->addr1; | |
2974 | event.tx_status.data = buf; | |
2975 | event.tx_status.data_len = len; | |
2976 | event.tx_status.ack = ok; | |
2977 | wpa_supplicant_event(ctx, EVENT_TX_STATUS, &event); | |
0915d02c JM |
2978 | } |
2979 | ||
2980 | ||
4b9841d3 | 2981 | static void from_unknown_sta(struct wpa_driver_nl80211_data *drv, |
0d9fc3d8 | 2982 | u8 *buf, size_t len) |
0915d02c | 2983 | { |
f8b1f695 JM |
2984 | union wpa_event_data event; |
2985 | os_memset(&event, 0, sizeof(event)); | |
0d9fc3d8 | 2986 | event.rx_from_unknown.frame = buf; |
f8b1f695 JM |
2987 | event.rx_from_unknown.len = len; |
2988 | wpa_supplicant_event(drv->ctx, EVENT_RX_FROM_UNKNOWN, &event); | |
4b9841d3 | 2989 | } |
0915d02c | 2990 | |
4b9841d3 JM |
2991 | |
2992 | static void handle_frame(struct wpa_driver_nl80211_data *drv, | |
2a8b7416 | 2993 | u8 *buf, size_t len, int datarate, int ssi_signal) |
4b9841d3 JM |
2994 | { |
2995 | struct ieee80211_hdr *hdr; | |
f8b1f695 JM |
2996 | u16 fc; |
2997 | union wpa_event_data event; | |
0915d02c JM |
2998 | |
2999 | hdr = (struct ieee80211_hdr *) buf; | |
3000 | fc = le_to_host16(hdr->frame_control); | |
0915d02c | 3001 | |
4b9841d3 | 3002 | switch (WLAN_FC_GET_TYPE(fc)) { |
0915d02c | 3003 | case WLAN_FC_TYPE_MGMT: |
f8b1f695 JM |
3004 | os_memset(&event, 0, sizeof(event)); |
3005 | event.rx_mgmt.frame = buf; | |
3006 | event.rx_mgmt.frame_len = len; | |
2a8b7416 JM |
3007 | event.rx_mgmt.datarate = datarate; |
3008 | event.rx_mgmt.ssi_signal = ssi_signal; | |
f8b1f695 | 3009 | wpa_supplicant_event(drv->ctx, EVENT_RX_MGMT, &event); |
0915d02c JM |
3010 | break; |
3011 | case WLAN_FC_TYPE_CTRL: | |
3012 | /* can only get here with PS-Poll frames */ | |
3013 | wpa_printf(MSG_DEBUG, "CTRL"); | |
0d9fc3d8 | 3014 | from_unknown_sta(drv, buf, len); |
0915d02c JM |
3015 | break; |
3016 | case WLAN_FC_TYPE_DATA: | |
0d9fc3d8 | 3017 | from_unknown_sta(drv, buf, len); |
0915d02c JM |
3018 | break; |
3019 | } | |
3020 | } | |
3021 | ||
3022 | ||
3023 | static void handle_monitor_read(int sock, void *eloop_ctx, void *sock_ctx) | |
3024 | { | |
3025 | struct wpa_driver_nl80211_data *drv = eloop_ctx; | |
3026 | int len; | |
3027 | unsigned char buf[3000]; | |
3028 | struct ieee80211_radiotap_iterator iter; | |
3029 | int ret; | |
2a8b7416 | 3030 | int datarate = 0, ssi_signal = 0; |
4b9841d3 | 3031 | int injected = 0, failed = 0, rxflags = 0; |
0915d02c JM |
3032 | |
3033 | len = recv(sock, buf, sizeof(buf), 0); | |
3034 | if (len < 0) { | |
3035 | perror("recv"); | |
3036 | return; | |
3037 | } | |
3038 | ||
504e905c JM |
3039 | if (drv->nlmode == NL80211_IFTYPE_STATION && !drv->probe_req_report) { |
3040 | wpa_printf(MSG_DEBUG, "nl80211: Ignore monitor interface " | |
3041 | "frame since Probe Request reporting is disabled"); | |
3042 | return; | |
3043 | } | |
3044 | ||
0915d02c JM |
3045 | if (ieee80211_radiotap_iterator_init(&iter, (void*)buf, len)) { |
3046 | printf("received invalid radiotap frame\n"); | |
3047 | return; | |
3048 | } | |
3049 | ||
0915d02c JM |
3050 | while (1) { |
3051 | ret = ieee80211_radiotap_iterator_next(&iter); | |
3052 | if (ret == -ENOENT) | |
3053 | break; | |
3054 | if (ret) { | |
3055 | printf("received invalid radiotap frame (%d)\n", ret); | |
3056 | return; | |
3057 | } | |
3058 | switch (iter.this_arg_index) { | |
3059 | case IEEE80211_RADIOTAP_FLAGS: | |
3060 | if (*iter.this_arg & IEEE80211_RADIOTAP_F_FCS) | |
3061 | len -= 4; | |
3062 | break; | |
3063 | case IEEE80211_RADIOTAP_RX_FLAGS: | |
3064 | rxflags = 1; | |
3065 | break; | |
3066 | case IEEE80211_RADIOTAP_TX_FLAGS: | |
3067 | injected = 1; | |
3068 | failed = le_to_host16((*(uint16_t *) iter.this_arg)) & | |
3069 | IEEE80211_RADIOTAP_F_TX_FAIL; | |
3070 | break; | |
3071 | case IEEE80211_RADIOTAP_DATA_RETRIES: | |
3072 | break; | |
3073 | case IEEE80211_RADIOTAP_CHANNEL: | |
2a8b7416 | 3074 | /* TODO: convert from freq/flags to channel number */ |
0915d02c JM |
3075 | break; |
3076 | case IEEE80211_RADIOTAP_RATE: | |
2a8b7416 | 3077 | datarate = *iter.this_arg * 5; |
0915d02c JM |
3078 | break; |
3079 | case IEEE80211_RADIOTAP_DB_ANTSIGNAL: | |
2a8b7416 | 3080 | ssi_signal = *iter.this_arg; |
0915d02c JM |
3081 | break; |
3082 | } | |
3083 | } | |
3084 | ||
3085 | if (rxflags && injected) | |
3086 | return; | |
3087 | ||
3088 | if (!injected) | |
4b9841d3 | 3089 | handle_frame(drv, buf + iter.max_length, |
2a8b7416 | 3090 | len - iter.max_length, datarate, ssi_signal); |
0915d02c | 3091 | else |
4b9841d3 JM |
3092 | handle_tx_callback(drv->ctx, buf + iter.max_length, |
3093 | len - iter.max_length, !failed); | |
0915d02c JM |
3094 | } |
3095 | ||
3096 | ||
3097 | /* | |
3098 | * we post-process the filter code later and rewrite | |
3099 | * this to the offset to the last instruction | |
3100 | */ | |
3101 | #define PASS 0xFF | |
3102 | #define FAIL 0xFE | |
3103 | ||
3104 | static struct sock_filter msock_filter_insns[] = { | |
3105 | /* | |
3106 | * do a little-endian load of the radiotap length field | |
3107 | */ | |
3108 | /* load lower byte into A */ | |
3109 | BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2), | |
3110 | /* put it into X (== index register) */ | |
3111 | BPF_STMT(BPF_MISC| BPF_TAX, 0), | |
3112 | /* load upper byte into A */ | |
3113 | BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 3), | |
3114 | /* left-shift it by 8 */ | |
3115 | BPF_STMT(BPF_ALU | BPF_LSH | BPF_K, 8), | |
3116 | /* or with X */ | |
3117 | BPF_STMT(BPF_ALU | BPF_OR | BPF_X, 0), | |
3118 | /* put result into X */ | |
3119 | BPF_STMT(BPF_MISC| BPF_TAX, 0), | |
3120 | ||
3121 | /* | |
3122 | * Allow management frames through, this also gives us those | |
3123 | * management frames that we sent ourselves with status | |
3124 | */ | |
3125 | /* load the lower byte of the IEEE 802.11 frame control field */ | |
3126 | BPF_STMT(BPF_LD | BPF_B | BPF_IND, 0), | |
3127 | /* mask off frame type and version */ | |
3128 | BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0xF), | |
3129 | /* accept frame if it's both 0, fall through otherwise */ | |
3130 | BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0, PASS, 0), | |
3131 | ||
3132 | /* | |
3133 | * TODO: add a bit to radiotap RX flags that indicates | |
3134 | * that the sending station is not associated, then | |
3135 | * add a filter here that filters on our DA and that flag | |
3136 | * to allow us to deauth frames to that bad station. | |
3137 | * | |
3138 | * Not a regression -- we didn't do it before either. | |
3139 | */ | |
3140 | ||
3141 | #if 0 | |
3142 | /* | |
fbbfcbac | 3143 | * drop non-data frames |
0915d02c JM |
3144 | */ |
3145 | /* load the lower byte of the frame control field */ | |
3146 | BPF_STMT(BPF_LD | BPF_B | BPF_IND, 0), | |
3147 | /* mask off QoS bit */ | |
3148 | BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0x0c), | |
3149 | /* drop non-data frames */ | |
3150 | BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 8, 0, FAIL), | |
fbbfcbac | 3151 | #endif |
0915d02c | 3152 | /* load the upper byte of the frame control field */ |
fbbfcbac | 3153 | BPF_STMT(BPF_LD | BPF_B | BPF_IND, 1), |
0915d02c JM |
3154 | /* mask off toDS/fromDS */ |
3155 | BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0x03), | |
fbbfcbac FF |
3156 | /* accept WDS frames */ |
3157 | BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 3, PASS, 0), | |
0915d02c JM |
3158 | |
3159 | /* | |
3160 | * add header length to index | |
3161 | */ | |
3162 | /* load the lower byte of the frame control field */ | |
3163 | BPF_STMT(BPF_LD | BPF_B | BPF_IND, 0), | |
3164 | /* mask off QoS bit */ | |
3165 | BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0x80), | |
3166 | /* right shift it by 6 to give 0 or 2 */ | |
3167 | BPF_STMT(BPF_ALU | BPF_RSH | BPF_K, 6), | |
3168 | /* add data frame header length */ | |
3169 | BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 24), | |
3170 | /* add index, was start of 802.11 header */ | |
3171 | BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0), | |
3172 | /* move to index, now start of LL header */ | |
3173 | BPF_STMT(BPF_MISC | BPF_TAX, 0), | |
3174 | ||
3175 | /* | |
3176 | * Accept empty data frames, we use those for | |
3177 | * polling activity. | |
3178 | */ | |
3179 | BPF_STMT(BPF_LD | BPF_W | BPF_LEN, 0), | |
3180 | BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_X, 0, PASS, 0), | |
3181 | ||
3182 | /* | |
3183 | * Accept EAPOL frames | |
3184 | */ | |
3185 | BPF_STMT(BPF_LD | BPF_W | BPF_IND, 0), | |
3186 | BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0xAAAA0300, 0, FAIL), | |
3187 | BPF_STMT(BPF_LD | BPF_W | BPF_IND, 4), | |
3188 | BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x0000888E, PASS, FAIL), | |
3189 | ||
3190 | /* keep these last two statements or change the code below */ | |
3191 | /* return 0 == "DROP" */ | |
3192 | BPF_STMT(BPF_RET | BPF_K, 0), | |
3193 | /* return ~0 == "keep all" */ | |
3194 | BPF_STMT(BPF_RET | BPF_K, ~0), | |
3195 | }; | |
3196 | ||
3197 | static struct sock_fprog msock_filter = { | |
3198 | .len = sizeof(msock_filter_insns)/sizeof(msock_filter_insns[0]), | |
3199 | .filter = msock_filter_insns, | |
3200 | }; | |
3201 | ||
3202 | ||
3203 | static int add_monitor_filter(int s) | |
3204 | { | |
3205 | int idx; | |
3206 | ||
3207 | /* rewrite all PASS/FAIL jump offsets */ | |
3208 | for (idx = 0; idx < msock_filter.len; idx++) { | |
3209 | struct sock_filter *insn = &msock_filter_insns[idx]; | |
3210 | ||
3211 | if (BPF_CLASS(insn->code) == BPF_JMP) { | |
3212 | if (insn->code == (BPF_JMP|BPF_JA)) { | |
3213 | if (insn->k == PASS) | |
3214 | insn->k = msock_filter.len - idx - 2; | |
3215 | else if (insn->k == FAIL) | |
3216 | insn->k = msock_filter.len - idx - 3; | |
3217 | } | |
3218 | ||
3219 | if (insn->jt == PASS) | |
3220 | insn->jt = msock_filter.len - idx - 2; | |
3221 | else if (insn->jt == FAIL) | |
3222 | insn->jt = msock_filter.len - idx - 3; | |
3223 | ||
3224 | if (insn->jf == PASS) | |
3225 | insn->jf = msock_filter.len - idx - 2; | |
3226 | else if (insn->jf == FAIL) | |
3227 | insn->jf = msock_filter.len - idx - 3; | |
3228 | } | |
3229 | } | |
3230 | ||
3231 | if (setsockopt(s, SOL_SOCKET, SO_ATTACH_FILTER, | |
3232 | &msock_filter, sizeof(msock_filter))) { | |
3233 | perror("SO_ATTACH_FILTER"); | |
3234 | return -1; | |
3235 | } | |
3236 | ||
3237 | return 0; | |
3238 | } | |
3239 | ||
3240 | ||
460456f8 JM |
3241 | static void nl80211_remove_monitor_interface( |
3242 | struct wpa_driver_nl80211_data *drv) | |
3243 | { | |
3244 | if (drv->monitor_ifidx >= 0) { | |
3245 | nl80211_remove_iface(drv, drv->monitor_ifidx); | |
3246 | drv->monitor_ifidx = -1; | |
3247 | } | |
504e905c JM |
3248 | if (drv->monitor_sock >= 0) { |
3249 | eloop_unregister_read_sock(drv->monitor_sock); | |
3250 | close(drv->monitor_sock); | |
3251 | drv->monitor_sock = -1; | |
3252 | } | |
460456f8 JM |
3253 | } |
3254 | ||
3255 | ||
0915d02c JM |
3256 | static int |
3257 | nl80211_create_monitor_interface(struct wpa_driver_nl80211_data *drv) | |
3258 | { | |
3259 | char buf[IFNAMSIZ]; | |
3260 | struct sockaddr_ll ll; | |
3261 | int optval; | |
3262 | socklen_t optlen; | |
0915d02c | 3263 | |
a2e40bb6 | 3264 | snprintf(buf, IFNAMSIZ, "mon.%s", drv->first_bss.ifname); |
0915d02c JM |
3265 | buf[IFNAMSIZ - 1] = '\0'; |
3266 | ||
3267 | drv->monitor_ifidx = | |
fbbfcbac FF |
3268 | nl80211_create_iface(drv, buf, NL80211_IFTYPE_MONITOR, NULL, |
3269 | 0); | |
0915d02c JM |
3270 | |
3271 | if (drv->monitor_ifidx < 0) | |
3272 | return -1; | |
3273 | ||
34f2f814 | 3274 | if (linux_set_iface_flags(drv->ioctl_sock, buf, 1)) |
0915d02c | 3275 | goto error; |
0915d02c JM |
3276 | |
3277 | memset(&ll, 0, sizeof(ll)); | |
3278 | ll.sll_family = AF_PACKET; | |
3279 | ll.sll_ifindex = drv->monitor_ifidx; | |
3280 | drv->monitor_sock = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL)); | |
3281 | if (drv->monitor_sock < 0) { | |
3282 | perror("socket[PF_PACKET,SOCK_RAW]"); | |
3283 | goto error; | |
3284 | } | |
3285 | ||
3286 | if (add_monitor_filter(drv->monitor_sock)) { | |
3287 | wpa_printf(MSG_INFO, "Failed to set socket filter for monitor " | |
3288 | "interface; do filtering in user space"); | |
3289 | /* This works, but will cost in performance. */ | |
3290 | } | |
3291 | ||
2135f224 | 3292 | if (bind(drv->monitor_sock, (struct sockaddr *) &ll, sizeof(ll)) < 0) { |
0915d02c JM |
3293 | perror("monitor socket bind"); |
3294 | goto error; | |
3295 | } | |
3296 | ||
3297 | optlen = sizeof(optval); | |
3298 | optval = 20; | |
3299 | if (setsockopt | |
3300 | (drv->monitor_sock, SOL_SOCKET, SO_PRIORITY, &optval, optlen)) { | |
3301 | perror("Failed to set socket priority"); | |
3302 | goto error; | |
3303 | } | |
3304 | ||
3305 | if (eloop_register_read_sock(drv->monitor_sock, handle_monitor_read, | |
3306 | drv, NULL)) { | |
3307 | printf("Could not register monitor read socket\n"); | |
3308 | goto error; | |
3309 | } | |
3310 | ||
3311 | return 0; | |
3312 | error: | |
460456f8 | 3313 | nl80211_remove_monitor_interface(drv); |
0915d02c JM |
3314 | return -1; |
3315 | } | |
3316 | ||
db149ac9 JM |
3317 | |
3318 | static const u8 rfc1042_header[6] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 }; | |
3319 | ||
3320 | static int wpa_driver_nl80211_hapd_send_eapol( | |
3321 | void *priv, const u8 *addr, const u8 *data, | |
3322 | size_t data_len, int encrypt, const u8 *own_addr) | |
3323 | { | |
a2e40bb6 FF |
3324 | struct i802_bss *bss = priv; |
3325 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
db149ac9 JM |
3326 | struct ieee80211_hdr *hdr; |
3327 | size_t len; | |
3328 | u8 *pos; | |
3329 | int res; | |
3330 | #if 0 /* FIX */ | |
0de39516 | 3331 | int qos = sta->flags & WPA_STA_WMM; |
db149ac9 JM |
3332 | #else |
3333 | int qos = 0; | |
3334 | #endif | |
3335 | ||
3336 | len = sizeof(*hdr) + (qos ? 2 : 0) + sizeof(rfc1042_header) + 2 + | |
3337 | data_len; | |
3338 | hdr = os_zalloc(len); | |
3339 | if (hdr == NULL) { | |
3340 | printf("malloc() failed for i802_send_data(len=%lu)\n", | |
3341 | (unsigned long) len); | |
3342 | return -1; | |
3343 | } | |
3344 | ||
3345 | hdr->frame_control = | |
3346 | IEEE80211_FC(WLAN_FC_TYPE_DATA, WLAN_FC_STYPE_DATA); | |
3347 | hdr->frame_control |= host_to_le16(WLAN_FC_FROMDS); | |
3348 | if (encrypt) | |
3349 | hdr->frame_control |= host_to_le16(WLAN_FC_ISWEP); | |
3350 | #if 0 /* To be enabled if qos determination is added above */ | |
3351 | if (qos) { | |
3352 | hdr->frame_control |= | |
3353 | host_to_le16(WLAN_FC_STYPE_QOS_DATA << 4); | |
3354 | } | |
3355 | #endif | |
3356 | ||
3357 | memcpy(hdr->IEEE80211_DA_FROMDS, addr, ETH_ALEN); | |
3358 | memcpy(hdr->IEEE80211_BSSID_FROMDS, own_addr, ETH_ALEN); | |
3359 | memcpy(hdr->IEEE80211_SA_FROMDS, own_addr, ETH_ALEN); | |
3360 | pos = (u8 *) (hdr + 1); | |
3361 | ||
3362 | #if 0 /* To be enabled if qos determination is added above */ | |
3363 | if (qos) { | |
3364 | /* add an empty QoS header if needed */ | |
3365 | pos[0] = 0; | |
3366 | pos[1] = 0; | |
3367 | pos += 2; | |
3368 | } | |
3369 | #endif | |
3370 | ||
3371 | memcpy(pos, rfc1042_header, sizeof(rfc1042_header)); | |
3372 | pos += sizeof(rfc1042_header); | |
3373 | WPA_PUT_BE16(pos, ETH_P_PAE); | |
3374 | pos += 2; | |
3375 | memcpy(pos, data, data_len); | |
3376 | ||
3377 | res = wpa_driver_nl80211_send_frame(drv, (u8 *) hdr, len, encrypt); | |
3378 | if (res < 0) { | |
3379 | wpa_printf(MSG_ERROR, "i802_send_eapol - packet len: %lu - " | |
3380 | "failed: %d (%s)", | |
3381 | (unsigned long) len, errno, strerror(errno)); | |
3382 | } | |
7bf12757 | 3383 | os_free(hdr); |
db149ac9 JM |
3384 | |
3385 | return res; | |
3386 | } | |
3387 | ||
a8d6ffa4 | 3388 | |
7e76ee9c JM |
3389 | static u32 sta_flags_nl80211(int flags) |
3390 | { | |
3391 | u32 f = 0; | |
3392 | ||
0de39516 | 3393 | if (flags & WPA_STA_AUTHORIZED) |
7e76ee9c | 3394 | f |= BIT(NL80211_STA_FLAG_AUTHORIZED); |
0de39516 | 3395 | if (flags & WPA_STA_WMM) |
7e76ee9c | 3396 | f |= BIT(NL80211_STA_FLAG_WME); |
0de39516 | 3397 | if (flags & WPA_STA_SHORT_PREAMBLE) |
7e76ee9c | 3398 | f |= BIT(NL80211_STA_FLAG_SHORT_PREAMBLE); |
0de39516 | 3399 | if (flags & WPA_STA_MFP) |
7e76ee9c JM |
3400 | f |= BIT(NL80211_STA_FLAG_MFP); |
3401 | ||
3402 | return f; | |
3403 | } | |
3404 | ||
3405 | ||
4c32757d FF |
3406 | static int wpa_driver_nl80211_sta_set_flags(const char *ifname, void *priv, |
3407 | const u8 *addr, int total_flags, | |
3408 | int flags_or, int flags_and) | |
a8d6ffa4 | 3409 | { |
a2e40bb6 FF |
3410 | struct i802_bss *bss = priv; |
3411 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
a8d6ffa4 | 3412 | struct nl_msg *msg, *flags = NULL; |
7e76ee9c | 3413 | struct nl80211_sta_flag_update upd; |
a8d6ffa4 JM |
3414 | |
3415 | msg = nlmsg_alloc(); | |
3416 | if (!msg) | |
3417 | return -ENOMEM; | |
3418 | ||
3419 | flags = nlmsg_alloc(); | |
3420 | if (!flags) { | |
3421 | nlmsg_free(msg); | |
3422 | return -ENOMEM; | |
3423 | } | |
3424 | ||
3425 | genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0, | |
3426 | 0, NL80211_CMD_SET_STATION, 0); | |
3427 | ||
3428 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, | |
4c32757d | 3429 | if_nametoindex(ifname)); |
a8d6ffa4 JM |
3430 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); |
3431 | ||
7e76ee9c JM |
3432 | /* |
3433 | * Backwards compatibility version using NL80211_ATTR_STA_FLAGS. This | |
3434 | * can be removed eventually. | |
3435 | */ | |
0de39516 | 3436 | if (total_flags & WPA_STA_AUTHORIZED) |
a8d6ffa4 JM |
3437 | NLA_PUT_FLAG(flags, NL80211_STA_FLAG_AUTHORIZED); |
3438 | ||
0de39516 | 3439 | if (total_flags & WPA_STA_WMM) |
a8d6ffa4 JM |
3440 | NLA_PUT_FLAG(flags, NL80211_STA_FLAG_WME); |
3441 | ||
0de39516 | 3442 | if (total_flags & WPA_STA_SHORT_PREAMBLE) |
a8d6ffa4 JM |
3443 | NLA_PUT_FLAG(flags, NL80211_STA_FLAG_SHORT_PREAMBLE); |
3444 | ||
0de39516 | 3445 | if (total_flags & WPA_STA_MFP) |
a8d6ffa4 JM |
3446 | NLA_PUT_FLAG(flags, NL80211_STA_FLAG_MFP); |
3447 | ||
3448 | if (nla_put_nested(msg, NL80211_ATTR_STA_FLAGS, flags)) | |
3449 | goto nla_put_failure; | |
3450 | ||
7e76ee9c JM |
3451 | os_memset(&upd, 0, sizeof(upd)); |
3452 | upd.mask = sta_flags_nl80211(flags_or | ~flags_and); | |
3453 | upd.set = sta_flags_nl80211(flags_or); | |
3454 | NLA_PUT(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd); | |
3455 | ||
a8d6ffa4 JM |
3456 | nlmsg_free(flags); |
3457 | ||
3458 | return send_and_recv_msgs(drv, msg, NULL, NULL); | |
3459 | nla_put_failure: | |
3460 | nlmsg_free(flags); | |
3461 | return -ENOBUFS; | |
3462 | } | |
3463 | ||
0915d02c | 3464 | |
1581b38b JM |
3465 | static int wpa_driver_nl80211_ap(struct wpa_driver_nl80211_data *drv, |
3466 | struct wpa_driver_associate_params *params) | |
3467 | { | |
a2e40bb6 | 3468 | if (wpa_driver_nl80211_set_mode(&drv->first_bss, params->mode) || |
f019981a | 3469 | wpa_driver_nl80211_set_freq(drv, params->freq, 0, 0)) { |
460456f8 | 3470 | nl80211_remove_monitor_interface(drv); |
1581b38b | 3471 | return -1; |
0915d02c | 3472 | } |
1581b38b JM |
3473 | |
3474 | /* TODO: setup monitor interface (and add code somewhere to remove this | |
3475 | * when AP mode is stopped; associate with mode != 2 or drv_deinit) */ | |
1581b38b JM |
3476 | |
3477 | return 0; | |
3478 | } | |
1581b38b JM |
3479 | |
3480 | ||
5cc4d64b JM |
3481 | static int nl80211_leave_ibss(struct wpa_driver_nl80211_data *drv) |
3482 | { | |
3483 | struct nl_msg *msg; | |
3484 | int ret = -1; | |
3485 | ||
3486 | msg = nlmsg_alloc(); | |
3487 | if (!msg) | |
3488 | return -1; | |
3489 | ||
3490 | genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0, 0, | |
3491 | NL80211_CMD_LEAVE_IBSS, 0); | |
3492 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); | |
3493 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
3494 | msg = NULL; | |
3495 | if (ret) { | |
3496 | wpa_printf(MSG_DEBUG, "nl80211: Leave IBSS failed: ret=%d " | |
3497 | "(%s)", ret, strerror(-ret)); | |
3498 | goto nla_put_failure; | |
3499 | } | |
3500 | ||
3501 | ret = 0; | |
3502 | wpa_printf(MSG_DEBUG, "nl80211: Leave IBSS request sent successfully"); | |
3503 | ||
3504 | nla_put_failure: | |
3505 | nlmsg_free(msg); | |
3506 | return ret; | |
3507 | } | |
3508 | ||
3509 | ||
3510 | static int wpa_driver_nl80211_ibss(struct wpa_driver_nl80211_data *drv, | |
3511 | struct wpa_driver_associate_params *params) | |
3512 | { | |
3513 | struct nl_msg *msg; | |
3514 | int ret = -1; | |
3515 | int count = 0; | |
3516 | ||
3517 | wpa_printf(MSG_DEBUG, "nl80211: Join IBSS (ifindex=%d)", drv->ifindex); | |
3518 | ||
a2e40bb6 | 3519 | if (wpa_driver_nl80211_set_mode(&drv->first_bss, params->mode)) { |
5cc4d64b JM |
3520 | wpa_printf(MSG_INFO, "nl80211: Failed to set interface into " |
3521 | "IBSS mode"); | |
3522 | return -1; | |
3523 | } | |
3524 | ||
3525 | retry: | |
3526 | msg = nlmsg_alloc(); | |
3527 | if (!msg) | |
3528 | return -1; | |
3529 | ||
3530 | genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0, 0, | |
3531 | NL80211_CMD_JOIN_IBSS, 0); | |
3532 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); | |
3533 | ||
3534 | if (params->ssid == NULL || params->ssid_len > sizeof(drv->ssid)) | |
3535 | goto nla_put_failure; | |
3536 | ||
3537 | wpa_hexdump_ascii(MSG_DEBUG, " * SSID", | |
3538 | params->ssid, params->ssid_len); | |
3539 | NLA_PUT(msg, NL80211_ATTR_SSID, params->ssid_len, | |
3540 | params->ssid); | |
3541 | os_memcpy(drv->ssid, params->ssid, params->ssid_len); | |
3542 | drv->ssid_len = params->ssid_len; | |
3543 | ||
3544 | wpa_printf(MSG_DEBUG, " * freq=%d", params->freq); | |
3545 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, params->freq); | |
3546 | ||
3547 | ret = nl80211_set_conn_keys(params, msg); | |
3548 | if (ret) | |
3549 | goto nla_put_failure; | |
3550 | ||
a95795ad JM |
3551 | if (params->wpa_ie) { |
3552 | wpa_hexdump(MSG_DEBUG, | |
3553 | " * Extra IEs for Beacon/Probe Response frames", | |
3554 | params->wpa_ie, params->wpa_ie_len); | |
3555 | NLA_PUT(msg, NL80211_ATTR_IE, params->wpa_ie_len, | |
3556 | params->wpa_ie); | |
3557 | } | |
3558 | ||
5cc4d64b JM |
3559 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
3560 | msg = NULL; | |
3561 | if (ret) { | |
3562 | wpa_printf(MSG_DEBUG, "nl80211: Join IBSS failed: ret=%d (%s)", | |
3563 | ret, strerror(-ret)); | |
3564 | count++; | |
3565 | if (ret == -EALREADY && count == 1) { | |
3566 | wpa_printf(MSG_DEBUG, "nl80211: Retry IBSS join after " | |
3567 | "forced leave"); | |
3568 | nl80211_leave_ibss(drv); | |
3569 | nlmsg_free(msg); | |
3570 | goto retry; | |
3571 | } | |
3572 | ||
3573 | goto nla_put_failure; | |
3574 | } | |
3575 | ret = 0; | |
3576 | wpa_printf(MSG_DEBUG, "nl80211: Join IBSS request sent successfully"); | |
3577 | ||
3578 | nla_put_failure: | |
3579 | nlmsg_free(msg); | |
3580 | return ret; | |
3581 | } | |
3582 | ||
3583 | ||
cfaab580 ZY |
3584 | static int wpa_driver_nl80211_connect( |
3585 | struct wpa_driver_nl80211_data *drv, | |
3586 | struct wpa_driver_associate_params *params) | |
3587 | { | |
3588 | struct nl_msg *msg; | |
3589 | enum nl80211_auth_type type; | |
3590 | int ret = 0; | |
3591 | ||
3592 | msg = nlmsg_alloc(); | |
3593 | if (!msg) | |
3594 | return -1; | |
3595 | ||
3596 | wpa_printf(MSG_DEBUG, "nl80211: Connect (ifindex=%d)", drv->ifindex); | |
3597 | genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0, 0, | |
3598 | NL80211_CMD_CONNECT, 0); | |
3599 | ||
3600 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); | |
3601 | if (params->bssid) { | |
3602 | wpa_printf(MSG_DEBUG, " * bssid=" MACSTR, | |
3603 | MAC2STR(params->bssid)); | |
3604 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid); | |
3605 | } | |
3606 | if (params->freq) { | |
3607 | wpa_printf(MSG_DEBUG, " * freq=%d", params->freq); | |
3608 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, params->freq); | |
3609 | } | |
3610 | if (params->ssid) { | |
3611 | wpa_hexdump_ascii(MSG_DEBUG, " * SSID", | |
3612 | params->ssid, params->ssid_len); | |
3613 | NLA_PUT(msg, NL80211_ATTR_SSID, params->ssid_len, | |
3614 | params->ssid); | |
3615 | if (params->ssid_len > sizeof(drv->ssid)) | |
3616 | goto nla_put_failure; | |
3617 | os_memcpy(drv->ssid, params->ssid, params->ssid_len); | |
3618 | drv->ssid_len = params->ssid_len; | |
3619 | } | |
3620 | wpa_hexdump(MSG_DEBUG, " * IEs", params->wpa_ie, params->wpa_ie_len); | |
3621 | if (params->wpa_ie) | |
3622 | NLA_PUT(msg, NL80211_ATTR_IE, params->wpa_ie_len, | |
3623 | params->wpa_ie); | |
3624 | ||
abd9fafa | 3625 | if (params->auth_alg & WPA_AUTH_ALG_OPEN) |
cfaab580 | 3626 | type = NL80211_AUTHTYPE_OPEN_SYSTEM; |
abd9fafa | 3627 | else if (params->auth_alg & WPA_AUTH_ALG_SHARED) |
cfaab580 | 3628 | type = NL80211_AUTHTYPE_SHARED_KEY; |
abd9fafa | 3629 | else if (params->auth_alg & WPA_AUTH_ALG_LEAP) |
cfaab580 | 3630 | type = NL80211_AUTHTYPE_NETWORK_EAP; |
abd9fafa | 3631 | else if (params->auth_alg & WPA_AUTH_ALG_FT) |
cfaab580 ZY |
3632 | type = NL80211_AUTHTYPE_FT; |
3633 | else | |
3634 | goto nla_put_failure; | |
3635 | ||
3636 | wpa_printf(MSG_DEBUG, " * Auth Type %d", type); | |
3637 | NLA_PUT_U32(msg, NL80211_ATTR_AUTH_TYPE, type); | |
3638 | ||
3639 | if (params->wpa_ie && params->wpa_ie_len) { | |
3640 | enum nl80211_wpa_versions ver; | |
3641 | ||
3642 | if (params->wpa_ie[0] == WLAN_EID_RSN) | |
3643 | ver = NL80211_WPA_VERSION_2; | |
3644 | else | |
3645 | ver = NL80211_WPA_VERSION_1; | |
3646 | ||
3647 | wpa_printf(MSG_DEBUG, " * WPA Version %d", ver); | |
3648 | NLA_PUT_U32(msg, NL80211_ATTR_WPA_VERSIONS, ver); | |
3649 | } | |
3650 | ||
3651 | if (params->pairwise_suite != CIPHER_NONE) { | |
c1bb3e0a | 3652 | int cipher; |
cfaab580 ZY |
3653 | |
3654 | switch (params->pairwise_suite) { | |
3655 | case CIPHER_WEP40: | |
3656 | cipher = WLAN_CIPHER_SUITE_WEP40; | |
3657 | break; | |
3658 | case CIPHER_WEP104: | |
3659 | cipher = WLAN_CIPHER_SUITE_WEP104; | |
3660 | break; | |
3661 | case CIPHER_CCMP: | |
3662 | cipher = WLAN_CIPHER_SUITE_CCMP; | |
3663 | break; | |
3664 | case CIPHER_TKIP: | |
3665 | default: | |
3666 | cipher = WLAN_CIPHER_SUITE_TKIP; | |
3667 | break; | |
3668 | } | |
3669 | NLA_PUT_U32(msg, NL80211_ATTR_CIPHER_SUITES_PAIRWISE, cipher); | |
3670 | } | |
3671 | ||
3672 | if (params->group_suite != CIPHER_NONE) { | |
c1bb3e0a | 3673 | int cipher; |
cfaab580 ZY |
3674 | |
3675 | switch (params->group_suite) { | |
3676 | case CIPHER_WEP40: | |
3677 | cipher = WLAN_CIPHER_SUITE_WEP40; | |
3678 | break; | |
3679 | case CIPHER_WEP104: | |
3680 | cipher = WLAN_CIPHER_SUITE_WEP104; | |
3681 | break; | |
3682 | case CIPHER_CCMP: | |
3683 | cipher = WLAN_CIPHER_SUITE_CCMP; | |
3684 | break; | |
3685 | case CIPHER_TKIP: | |
3686 | default: | |
3687 | cipher = WLAN_CIPHER_SUITE_TKIP; | |
3688 | break; | |
3689 | } | |
3690 | NLA_PUT_U32(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, cipher); | |
3691 | } | |
3692 | ||
3693 | if (params->key_mgmt_suite == KEY_MGMT_802_1X || | |
3694 | params->key_mgmt_suite == KEY_MGMT_PSK) { | |
3695 | int mgmt = WLAN_AKM_SUITE_PSK; | |
3696 | ||
3697 | switch (params->key_mgmt_suite) { | |
3698 | case KEY_MGMT_802_1X: | |
3699 | mgmt = WLAN_AKM_SUITE_8021X; | |
3700 | break; | |
3701 | case KEY_MGMT_PSK: | |
3702 | default: | |
3703 | mgmt = WLAN_AKM_SUITE_PSK; | |
3704 | break; | |
3705 | } | |
3706 | NLA_PUT_U32(msg, NL80211_ATTR_AKM_SUITES, mgmt); | |
3707 | } | |
3708 | ||
3709 | ret = nl80211_set_conn_keys(params, msg); | |
3710 | if (ret) | |
3711 | goto nla_put_failure; | |
3712 | ||
3713 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
3714 | msg = NULL; | |
3715 | if (ret) { | |
3716 | wpa_printf(MSG_DEBUG, "nl80211: MLME connect failed: ret=%d " | |
3717 | "(%s)", ret, strerror(-ret)); | |
3718 | goto nla_put_failure; | |
3719 | } | |
3720 | ret = 0; | |
3721 | wpa_printf(MSG_DEBUG, "nl80211: Connect request send successfully"); | |
3722 | ||
3723 | nla_put_failure: | |
3724 | nlmsg_free(msg); | |
3725 | return ret; | |
3726 | ||
3727 | } | |
3728 | ||
3729 | ||
c2a04078 JM |
3730 | static int wpa_driver_nl80211_associate( |
3731 | void *priv, struct wpa_driver_associate_params *params) | |
3732 | { | |
a2e40bb6 FF |
3733 | struct i802_bss *bss = priv; |
3734 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
c2a04078 JM |
3735 | int ret = -1; |
3736 | struct nl_msg *msg; | |
3737 | ||
5cc4d64b | 3738 | if (params->mode == IEEE80211_MODE_AP) |
1581b38b | 3739 | return wpa_driver_nl80211_ap(drv, params); |
1581b38b | 3740 | |
5cc4d64b JM |
3741 | if (params->mode == IEEE80211_MODE_IBSS) |
3742 | return wpa_driver_nl80211_ibss(drv, params); | |
3743 | ||
4a867032 | 3744 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) { |
a2e40bb6 | 3745 | if (wpa_driver_nl80211_set_mode(priv, params->mode) < 0) |
4a867032 | 3746 | return -1; |
cfaab580 | 3747 | return wpa_driver_nl80211_connect(drv, params); |
4a867032 | 3748 | } |
cfaab580 | 3749 | |
c2a04078 JM |
3750 | drv->associated = 0; |
3751 | ||
3752 | msg = nlmsg_alloc(); | |
3753 | if (!msg) | |
3754 | return -1; | |
3755 | ||
3756 | wpa_printf(MSG_DEBUG, "nl80211: Associate (ifindex=%d)", | |
3757 | drv->ifindex); | |
3758 | genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0, 0, | |
3759 | NL80211_CMD_ASSOCIATE, 0); | |
3760 | ||
3761 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); | |
3762 | if (params->bssid) { | |
3763 | wpa_printf(MSG_DEBUG, " * bssid=" MACSTR, | |
3764 | MAC2STR(params->bssid)); | |
3765 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid); | |
3766 | } | |
3767 | if (params->freq) { | |
3768 | wpa_printf(MSG_DEBUG, " * freq=%d", params->freq); | |
3769 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, params->freq); | |
4832ecd7 JM |
3770 | drv->assoc_freq = params->freq; |
3771 | } else | |
3772 | drv->assoc_freq = 0; | |
c2a04078 JM |
3773 | if (params->ssid) { |
3774 | wpa_hexdump_ascii(MSG_DEBUG, " * SSID", | |
3775 | params->ssid, params->ssid_len); | |
3776 | NLA_PUT(msg, NL80211_ATTR_SSID, params->ssid_len, | |
3777 | params->ssid); | |
fd05d64e JM |
3778 | if (params->ssid_len > sizeof(drv->ssid)) |
3779 | goto nla_put_failure; | |
3780 | os_memcpy(drv->ssid, params->ssid, params->ssid_len); | |
3781 | drv->ssid_len = params->ssid_len; | |
c2a04078 JM |
3782 | } |
3783 | wpa_hexdump(MSG_DEBUG, " * IEs", params->wpa_ie, params->wpa_ie_len); | |
3784 | if (params->wpa_ie) | |
3785 | NLA_PUT(msg, NL80211_ATTR_IE, params->wpa_ie_len, | |
3786 | params->wpa_ie); | |
3787 | ||
e572fa33 JM |
3788 | #ifdef CONFIG_IEEE80211W |
3789 | if (params->mgmt_frame_protection == MGMT_FRAME_PROTECTION_REQUIRED) | |
3790 | NLA_PUT_U32(msg, NL80211_ATTR_USE_MFP, NL80211_MFP_REQUIRED); | |
3791 | #endif /* CONFIG_IEEE80211W */ | |
3792 | ||
01652550 JM |
3793 | NLA_PUT_FLAG(msg, NL80211_ATTR_CONTROL_PORT); |
3794 | ||
62fa124c JM |
3795 | if (params->prev_bssid) { |
3796 | wpa_printf(MSG_DEBUG, " * prev_bssid=" MACSTR, | |
3797 | MAC2STR(params->prev_bssid)); | |
3798 | NLA_PUT(msg, NL80211_ATTR_PREV_BSSID, ETH_ALEN, | |
3799 | params->prev_bssid); | |
3800 | } | |
3801 | ||
c2a04078 JM |
3802 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
3803 | msg = NULL; | |
3804 | if (ret) { | |
3805 | wpa_printf(MSG_DEBUG, "nl80211: MLME command failed: ret=%d " | |
3806 | "(%s)", ret, strerror(-ret)); | |
8856462d | 3807 | nl80211_dump_scan(drv); |
c2a04078 JM |
3808 | goto nla_put_failure; |
3809 | } | |
3810 | ret = 0; | |
3811 | wpa_printf(MSG_DEBUG, "nl80211: Association request send " | |
3812 | "successfully"); | |
3813 | ||
3814 | nla_put_failure: | |
3815 | nlmsg_free(msg); | |
3816 | return ret; | |
3817 | } | |
3f5285e8 JM |
3818 | |
3819 | ||
ad1e68e6 JM |
3820 | static int nl80211_set_mode(struct wpa_driver_nl80211_data *drv, |
3821 | int ifindex, int mode) | |
3f5285e8 | 3822 | { |
3f5285e8 | 3823 | struct nl_msg *msg; |
ad1e68e6 JM |
3824 | int ret = -ENOBUFS; |
3825 | ||
3826 | msg = nlmsg_alloc(); | |
3827 | if (!msg) | |
3828 | return -ENOMEM; | |
3829 | ||
3830 | genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0, | |
3831 | 0, NL80211_CMD_SET_INTERFACE, 0); | |
3832 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, ifindex); | |
3833 | NLA_PUT_U32(msg, NL80211_ATTR_IFTYPE, mode); | |
3834 | ||
3835 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
3836 | if (!ret) | |
3837 | return 0; | |
3838 | nla_put_failure: | |
3839 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set interface %d to mode %d:" | |
3840 | " %d (%s)", ifindex, mode, ret, strerror(-ret)); | |
3841 | return ret; | |
3842 | } | |
3843 | ||
3844 | ||
3845 | static int wpa_driver_nl80211_set_mode(void *priv, int mode) | |
3846 | { | |
a2e40bb6 FF |
3847 | struct i802_bss *bss = priv; |
3848 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
ad1e68e6 | 3849 | int ret = -1; |
1581b38b JM |
3850 | int nlmode; |
3851 | ||
3852 | switch (mode) { | |
3853 | case 0: | |
3854 | nlmode = NL80211_IFTYPE_STATION; | |
3855 | break; | |
3856 | case 1: | |
3857 | nlmode = NL80211_IFTYPE_ADHOC; | |
3858 | break; | |
3859 | case 2: | |
3860 | nlmode = NL80211_IFTYPE_AP; | |
3861 | break; | |
3862 | default: | |
3863 | return -1; | |
3864 | } | |
3f5285e8 | 3865 | |
ad1e68e6 JM |
3866 | if (nl80211_set_mode(drv, drv->ifindex, nlmode) == 0) { |
3867 | drv->nlmode = nlmode; | |
460456f8 JM |
3868 | ret = 0; |
3869 | goto done; | |
ad1e68e6 | 3870 | } |
3f5285e8 | 3871 | |
460456f8 | 3872 | if (nlmode == drv->nlmode) { |
c6e8e8e4 JM |
3873 | wpa_printf(MSG_DEBUG, "nl80211: Interface already in " |
3874 | "requested mode - ignore error"); | |
460456f8 JM |
3875 | ret = 0; |
3876 | goto done; /* Already in the requested mode */ | |
3877 | } | |
3f5285e8 | 3878 | |
3f5285e8 JM |
3879 | /* mac80211 doesn't allow mode changes while the device is up, so |
3880 | * take the device down, try to set the mode again, and bring the | |
3881 | * device back up. | |
3882 | */ | |
a2e40bb6 | 3883 | if (linux_set_iface_flags(drv->ioctl_sock, bss->ifname, 0) == 0) { |
3f5285e8 | 3884 | /* Try to set the mode again while the interface is down */ |
ad1e68e6 | 3885 | ret = nl80211_set_mode(drv, drv->ifindex, nlmode); |
a2e40bb6 | 3886 | if (linux_set_iface_flags(drv->ioctl_sock, bss->ifname, 1)) |
2135f224 | 3887 | ret = -1; |
3f5285e8 JM |
3888 | } |
3889 | ||
c6e8e8e4 JM |
3890 | if (!ret) { |
3891 | wpa_printf(MSG_DEBUG, "nl80211: Mode change succeeded while " | |
3892 | "interface is down"); | |
ad1e68e6 | 3893 | drv->nlmode = nlmode; |
c6e8e8e4 | 3894 | } |
ad1e68e6 | 3895 | |
460456f8 | 3896 | done: |
460456f8 JM |
3897 | if (!ret && nlmode == NL80211_IFTYPE_AP) { |
3898 | /* Setup additional AP mode functionality if needed */ | |
3899 | if (drv->monitor_ifidx < 0 && | |
3900 | nl80211_create_monitor_interface(drv)) | |
3901 | return -1; | |
3902 | } else if (!ret && nlmode != NL80211_IFTYPE_AP) { | |
3903 | /* Remove additional AP mode functionality */ | |
3904 | nl80211_remove_monitor_interface(drv); | |
a2e40bb6 | 3905 | bss->beacon_set = 0; |
460456f8 | 3906 | } |
460456f8 | 3907 | |
c6e8e8e4 JM |
3908 | if (ret) |
3909 | wpa_printf(MSG_DEBUG, "nl80211: Interface mode change to %d " | |
3910 | "from %d failed", nlmode, drv->nlmode); | |
3911 | ||
3f5285e8 JM |
3912 | return ret; |
3913 | } | |
3914 | ||
3915 | ||
3f5285e8 JM |
3916 | static int wpa_driver_nl80211_get_capa(void *priv, |
3917 | struct wpa_driver_capa *capa) | |
3918 | { | |
a2e40bb6 FF |
3919 | struct i802_bss *bss = priv; |
3920 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
3f5285e8 JM |
3921 | if (!drv->has_capability) |
3922 | return -1; | |
3923 | os_memcpy(capa, &drv->capa, sizeof(*capa)); | |
3924 | return 0; | |
3925 | } | |
3926 | ||
3927 | ||
3928 | static int wpa_driver_nl80211_set_operstate(void *priv, int state) | |
3929 | { | |
a2e40bb6 FF |
3930 | struct i802_bss *bss = priv; |
3931 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
3f5285e8 JM |
3932 | |
3933 | wpa_printf(MSG_DEBUG, "%s: operstate %d->%d (%s)", | |
3934 | __func__, drv->operstate, state, state ? "UP" : "DORMANT"); | |
3935 | drv->operstate = state; | |
08063178 | 3936 | return netlink_send_oper_ifla(drv->netlink, drv->ifindex, -1, |
e2d02c29 | 3937 | state ? IF_OPER_UP : IF_OPER_DORMANT); |
3f5285e8 JM |
3938 | } |
3939 | ||
01652550 JM |
3940 | |
3941 | static int wpa_driver_nl80211_set_supp_port(void *priv, int authorized) | |
3942 | { | |
a2e40bb6 FF |
3943 | struct i802_bss *bss = priv; |
3944 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
01652550 JM |
3945 | struct nl_msg *msg; |
3946 | struct nl80211_sta_flag_update upd; | |
3947 | ||
3948 | msg = nlmsg_alloc(); | |
3949 | if (!msg) | |
3950 | return -ENOMEM; | |
3951 | ||
3952 | genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0, | |
3953 | 0, NL80211_CMD_SET_STATION, 0); | |
3954 | ||
3955 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, | |
a2e40bb6 | 3956 | if_nametoindex(bss->ifname)); |
01652550 JM |
3957 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, drv->bssid); |
3958 | ||
3959 | os_memset(&upd, 0, sizeof(upd)); | |
3960 | upd.mask = BIT(NL80211_STA_FLAG_AUTHORIZED); | |
3961 | if (authorized) | |
3962 | upd.set = BIT(NL80211_STA_FLAG_AUTHORIZED); | |
3963 | NLA_PUT(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd); | |
3964 | ||
3965 | return send_and_recv_msgs(drv, msg, NULL, NULL); | |
3966 | nla_put_failure: | |
3967 | return -ENOBUFS; | |
3968 | } | |
3969 | ||
3f5285e8 | 3970 | |
c5121837 JM |
3971 | #ifdef HOSTAPD |
3972 | ||
c5121837 JM |
3973 | static void add_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx) |
3974 | { | |
3975 | int i; | |
3976 | int *old; | |
3977 | ||
3978 | wpa_printf(MSG_DEBUG, "nl80211: Add own interface ifindex %d", | |
3979 | ifidx); | |
3980 | for (i = 0; i < drv->num_if_indices; i++) { | |
3981 | if (drv->if_indices[i] == 0) { | |
3982 | drv->if_indices[i] = ifidx; | |
3983 | return; | |
3984 | } | |
3985 | } | |
3986 | ||
3987 | if (drv->if_indices != drv->default_if_indices) | |
3988 | old = drv->if_indices; | |
3989 | else | |
3990 | old = NULL; | |
3991 | ||
7bf12757 JM |
3992 | drv->if_indices = os_realloc(old, |
3993 | sizeof(int) * (drv->num_if_indices + 1)); | |
c5121837 JM |
3994 | if (!drv->if_indices) { |
3995 | if (!old) | |
3996 | drv->if_indices = drv->default_if_indices; | |
3997 | else | |
3998 | drv->if_indices = old; | |
3999 | wpa_printf(MSG_ERROR, "Failed to reallocate memory for " | |
4000 | "interfaces"); | |
4001 | wpa_printf(MSG_ERROR, "Ignoring EAPOL on interface %d", ifidx); | |
4002 | return; | |
4003 | } | |
4004 | drv->if_indices[drv->num_if_indices] = ifidx; | |
4005 | drv->num_if_indices++; | |
4006 | } | |
4007 | ||
4008 | ||
4009 | static void del_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx) | |
4010 | { | |
4011 | int i; | |
4012 | ||
4013 | for (i = 0; i < drv->num_if_indices; i++) { | |
4014 | if (drv->if_indices[i] == ifidx) { | |
4015 | drv->if_indices[i] = 0; | |
4016 | break; | |
4017 | } | |
4018 | } | |
4019 | } | |
4020 | ||
4021 | ||
4022 | static int have_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx) | |
4023 | { | |
4024 | int i; | |
4025 | ||
4026 | for (i = 0; i < drv->num_if_indices; i++) | |
4027 | if (drv->if_indices[i] == ifidx) | |
4028 | return 1; | |
4029 | ||
4030 | return 0; | |
4031 | } | |
4032 | ||
4033 | ||
c5121837 JM |
4034 | static inline int min_int(int a, int b) |
4035 | { | |
4036 | if (a < b) | |
4037 | return a; | |
4038 | return b; | |
4039 | } | |
4040 | ||
4041 | ||
4042 | static int get_key_handler(struct nl_msg *msg, void *arg) | |
4043 | { | |
4044 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
4045 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
4046 | ||
4047 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
4048 | genlmsg_attrlen(gnlh, 0), NULL); | |
4049 | ||
4050 | /* | |
4051 | * TODO: validate the key index and mac address! | |
4052 | * Otherwise, there's a race condition as soon as | |
4053 | * the kernel starts sending key notifications. | |
4054 | */ | |
4055 | ||
4056 | if (tb[NL80211_ATTR_KEY_SEQ]) | |
4057 | memcpy(arg, nla_data(tb[NL80211_ATTR_KEY_SEQ]), | |
4058 | min_int(nla_len(tb[NL80211_ATTR_KEY_SEQ]), 6)); | |
4059 | return NL_SKIP; | |
4060 | } | |
4061 | ||
4062 | ||
4063 | static int i802_get_seqnum(const char *iface, void *priv, const u8 *addr, | |
4064 | int idx, u8 *seq) | |
4065 | { | |
a2e40bb6 FF |
4066 | struct i802_bss *bss = priv; |
4067 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
c5121837 JM |
4068 | struct nl_msg *msg; |
4069 | ||
4070 | msg = nlmsg_alloc(); | |
4071 | if (!msg) | |
4072 | return -ENOMEM; | |
4073 | ||
4074 | genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0, | |
4075 | 0, NL80211_CMD_GET_KEY, 0); | |
4076 | ||
4077 | if (addr) | |
4078 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); | |
4079 | NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, idx); | |
4080 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(iface)); | |
4081 | ||
4082 | memset(seq, 0, 6); | |
4083 | ||
4084 | return send_and_recv_msgs(drv, msg, get_key_handler, seq); | |
4085 | nla_put_failure: | |
4086 | return -ENOBUFS; | |
4087 | } | |
4088 | ||
4089 | ||
4090 | static int i802_set_rate_sets(void *priv, int *supp_rates, int *basic_rates, | |
4091 | int mode) | |
4092 | { | |
a2e40bb6 FF |
4093 | struct i802_bss *bss = priv; |
4094 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
c5121837 JM |
4095 | struct nl_msg *msg; |
4096 | u8 rates[NL80211_MAX_SUPP_RATES]; | |
4097 | u8 rates_len = 0; | |
4098 | int i; | |
4099 | ||
4100 | msg = nlmsg_alloc(); | |
4101 | if (!msg) | |
4102 | return -ENOMEM; | |
4103 | ||
4104 | genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0, 0, | |
4105 | NL80211_CMD_SET_BSS, 0); | |
4106 | ||
4107 | for (i = 0; i < NL80211_MAX_SUPP_RATES && basic_rates[i] >= 0; i++) | |
4108 | rates[rates_len++] = basic_rates[i] / 5; | |
4109 | ||
4110 | NLA_PUT(msg, NL80211_ATTR_BSS_BASIC_RATES, rates_len, rates); | |
4111 | ||
a2e40bb6 | 4112 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(bss->ifname)); |
c5121837 JM |
4113 | |
4114 | return send_and_recv_msgs(drv, msg, NULL, NULL); | |
4115 | nla_put_failure: | |
4116 | return -ENOBUFS; | |
4117 | } | |
4118 | ||
4119 | ||
c5121837 JM |
4120 | /* Set kernel driver on given frequency (MHz) */ |
4121 | static int i802_set_freq(void *priv, struct hostapd_freq_params *freq) | |
4122 | { | |
a2e40bb6 FF |
4123 | struct i802_bss *bss = priv; |
4124 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
f019981a JM |
4125 | return wpa_driver_nl80211_set_freq(drv, freq->freq, freq->ht_enabled, |
4126 | freq->sec_channel_offset); | |
c5121837 JM |
4127 | } |
4128 | ||
4129 | ||
4130 | static int i802_set_rts(void *priv, int rts) | |
4131 | { | |
a2e40bb6 FF |
4132 | struct i802_bss *bss = priv; |
4133 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
ad649451 JM |
4134 | struct nl_msg *msg; |
4135 | int ret = -ENOBUFS; | |
4136 | u32 val; | |
c5121837 | 4137 | |
ad649451 JM |
4138 | msg = nlmsg_alloc(); |
4139 | if (!msg) | |
4140 | return -ENOMEM; | |
c5121837 | 4141 | |
ad649451 JM |
4142 | if (rts >= 2347) |
4143 | val = (u32) -1; | |
4144 | else | |
4145 | val = rts; | |
c5121837 | 4146 | |
ad649451 JM |
4147 | genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0, |
4148 | 0, NL80211_CMD_SET_WIPHY, 0); | |
4149 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); | |
4150 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, val); | |
4151 | ||
4152 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
4153 | if (!ret) | |
4154 | return 0; | |
4155 | nla_put_failure: | |
4156 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set RTS threshold %d: " | |
4157 | "%d (%s)", rts, ret, strerror(-ret)); | |
4158 | return ret; | |
c5121837 JM |
4159 | } |
4160 | ||
4161 | ||
4162 | static int i802_set_frag(void *priv, int frag) | |
4163 | { | |
a2e40bb6 FF |
4164 | struct i802_bss *bss = priv; |
4165 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
ad649451 JM |
4166 | struct nl_msg *msg; |
4167 | int ret = -ENOBUFS; | |
4168 | u32 val; | |
c5121837 | 4169 | |
ad649451 JM |
4170 | msg = nlmsg_alloc(); |
4171 | if (!msg) | |
4172 | return -ENOMEM; | |
c5121837 | 4173 | |
ad649451 JM |
4174 | if (frag >= 2346) |
4175 | val = (u32) -1; | |
4176 | else | |
4177 | val = frag; | |
c5121837 | 4178 | |
ad649451 JM |
4179 | genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0, |
4180 | 0, NL80211_CMD_SET_WIPHY, 0); | |
4181 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); | |
4182 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, val); | |
4183 | ||
4184 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
4185 | if (!ret) | |
4186 | return 0; | |
4187 | nla_put_failure: | |
4188 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set fragmentation threshold " | |
4189 | "%d: %d (%s)", frag, ret, strerror(-ret)); | |
4190 | return ret; | |
c5121837 JM |
4191 | } |
4192 | ||
4193 | ||
c5121837 JM |
4194 | static int i802_flush(void *priv) |
4195 | { | |
a2e40bb6 FF |
4196 | struct i802_bss *bss = priv; |
4197 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
c5121837 JM |
4198 | struct nl_msg *msg; |
4199 | ||
4200 | msg = nlmsg_alloc(); | |
4201 | if (!msg) | |
4202 | return -1; | |
4203 | ||
4204 | genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0, | |
4205 | 0, NL80211_CMD_DEL_STATION, 0); | |
4206 | ||
4207 | /* | |
4208 | * XXX: FIX! this needs to flush all VLANs too | |
4209 | */ | |
4210 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, | |
a2e40bb6 | 4211 | if_nametoindex(bss->ifname)); |
c5121837 JM |
4212 | |
4213 | return send_and_recv_msgs(drv, msg, NULL, NULL); | |
4214 | nla_put_failure: | |
4215 | return -ENOBUFS; | |
4216 | } | |
4217 | ||
4218 | ||
4219 | static int get_sta_handler(struct nl_msg *msg, void *arg) | |
4220 | { | |
4221 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
4222 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
4223 | struct hostap_sta_driver_data *data = arg; | |
4224 | struct nlattr *stats[NL80211_STA_INFO_MAX + 1]; | |
4225 | static struct nla_policy stats_policy[NL80211_STA_INFO_MAX + 1] = { | |
4226 | [NL80211_STA_INFO_INACTIVE_TIME] = { .type = NLA_U32 }, | |
4227 | [NL80211_STA_INFO_RX_BYTES] = { .type = NLA_U32 }, | |
4228 | [NL80211_STA_INFO_TX_BYTES] = { .type = NLA_U32 }, | |
4229 | [NL80211_STA_INFO_RX_PACKETS] = { .type = NLA_U32 }, | |
4230 | [NL80211_STA_INFO_TX_PACKETS] = { .type = NLA_U32 }, | |
4231 | }; | |
4232 | ||
4233 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
4234 | genlmsg_attrlen(gnlh, 0), NULL); | |
4235 | ||
4236 | /* | |
4237 | * TODO: validate the interface and mac address! | |
4238 | * Otherwise, there's a race condition as soon as | |
4239 | * the kernel starts sending station notifications. | |
4240 | */ | |
4241 | ||
4242 | if (!tb[NL80211_ATTR_STA_INFO]) { | |
4243 | wpa_printf(MSG_DEBUG, "sta stats missing!"); | |
4244 | return NL_SKIP; | |
4245 | } | |
4246 | if (nla_parse_nested(stats, NL80211_STA_INFO_MAX, | |
4247 | tb[NL80211_ATTR_STA_INFO], | |
4248 | stats_policy)) { | |
4249 | wpa_printf(MSG_DEBUG, "failed to parse nested attributes!"); | |
4250 | return NL_SKIP; | |
4251 | } | |
4252 | ||
4253 | if (stats[NL80211_STA_INFO_INACTIVE_TIME]) | |
4254 | data->inactive_msec = | |
4255 | nla_get_u32(stats[NL80211_STA_INFO_INACTIVE_TIME]); | |
4256 | if (stats[NL80211_STA_INFO_RX_BYTES]) | |
4257 | data->rx_bytes = nla_get_u32(stats[NL80211_STA_INFO_RX_BYTES]); | |
4258 | if (stats[NL80211_STA_INFO_TX_BYTES]) | |
4259 | data->tx_bytes = nla_get_u32(stats[NL80211_STA_INFO_TX_BYTES]); | |
4260 | if (stats[NL80211_STA_INFO_RX_PACKETS]) | |
4261 | data->rx_packets = | |
4262 | nla_get_u32(stats[NL80211_STA_INFO_RX_PACKETS]); | |
4263 | if (stats[NL80211_STA_INFO_TX_PACKETS]) | |
4264 | data->tx_packets = | |
4265 | nla_get_u32(stats[NL80211_STA_INFO_TX_PACKETS]); | |
4266 | ||
4267 | return NL_SKIP; | |
4268 | } | |
4269 | ||
4270 | static int i802_read_sta_data(void *priv, struct hostap_sta_driver_data *data, | |
4271 | const u8 *addr) | |
4272 | { | |
a2e40bb6 FF |
4273 | struct i802_bss *bss = priv; |
4274 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
c5121837 JM |
4275 | struct nl_msg *msg; |
4276 | ||
4277 | os_memset(data, 0, sizeof(*data)); | |
4278 | msg = nlmsg_alloc(); | |
4279 | if (!msg) | |
4280 | return -ENOMEM; | |
4281 | ||
4282 | genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0, | |
4283 | 0, NL80211_CMD_GET_STATION, 0); | |
4284 | ||
4285 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); | |
a2e40bb6 | 4286 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(bss->ifname)); |
c5121837 JM |
4287 | |
4288 | return send_and_recv_msgs(drv, msg, get_sta_handler, data); | |
4289 | nla_put_failure: | |
4290 | return -ENOBUFS; | |
4291 | } | |
4292 | ||
4293 | ||
c5121837 JM |
4294 | static int i802_set_tx_queue_params(void *priv, int queue, int aifs, |
4295 | int cw_min, int cw_max, int burst_time) | |
4296 | { | |
a2e40bb6 FF |
4297 | struct i802_bss *bss = priv; |
4298 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
c5121837 JM |
4299 | struct nl_msg *msg; |
4300 | struct nlattr *txq, *params; | |
4301 | ||
4302 | msg = nlmsg_alloc(); | |
4303 | if (!msg) | |
4304 | return -1; | |
4305 | ||
4306 | genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0, | |
4307 | 0, NL80211_CMD_SET_WIPHY, 0); | |
4308 | ||
a2e40bb6 | 4309 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(bss->ifname)); |
c5121837 JM |
4310 | |
4311 | txq = nla_nest_start(msg, NL80211_ATTR_WIPHY_TXQ_PARAMS); | |
4312 | if (!txq) | |
4313 | goto nla_put_failure; | |
4314 | ||
4315 | /* We are only sending parameters for a single TXQ at a time */ | |
4316 | params = nla_nest_start(msg, 1); | |
4317 | if (!params) | |
4318 | goto nla_put_failure; | |
4319 | ||
4320 | NLA_PUT_U8(msg, NL80211_TXQ_ATTR_QUEUE, queue); | |
4321 | /* Burst time is configured in units of 0.1 msec and TXOP parameter in | |
4322 | * 32 usec, so need to convert the value here. */ | |
4323 | NLA_PUT_U16(msg, NL80211_TXQ_ATTR_TXOP, (burst_time * 100 + 16) / 32); | |
4324 | NLA_PUT_U16(msg, NL80211_TXQ_ATTR_CWMIN, cw_min); | |
4325 | NLA_PUT_U16(msg, NL80211_TXQ_ATTR_CWMAX, cw_max); | |
4326 | NLA_PUT_U8(msg, NL80211_TXQ_ATTR_AIFS, aifs); | |
4327 | ||
4328 | nla_nest_end(msg, params); | |
4329 | ||
4330 | nla_nest_end(msg, txq); | |
4331 | ||
4332 | if (send_and_recv_msgs(drv, msg, NULL, NULL) == 0) | |
4333 | return 0; | |
4334 | nla_put_failure: | |
4335 | return -1; | |
4336 | } | |
4337 | ||
4338 | ||
c5121837 JM |
4339 | static int i802_set_bss(void *priv, int cts, int preamble, int slot) |
4340 | { | |
a2e40bb6 FF |
4341 | struct i802_bss *bss = priv; |
4342 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
c5121837 JM |
4343 | struct nl_msg *msg; |
4344 | ||
4345 | msg = nlmsg_alloc(); | |
4346 | if (!msg) | |
4347 | return -ENOMEM; | |
4348 | ||
4349 | genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0, 0, | |
4350 | NL80211_CMD_SET_BSS, 0); | |
4351 | ||
4352 | if (cts >= 0) | |
4353 | NLA_PUT_U8(msg, NL80211_ATTR_BSS_CTS_PROT, cts); | |
4354 | if (preamble >= 0) | |
4355 | NLA_PUT_U8(msg, NL80211_ATTR_BSS_SHORT_PREAMBLE, preamble); | |
4356 | if (slot >= 0) | |
4357 | NLA_PUT_U8(msg, NL80211_ATTR_BSS_SHORT_SLOT_TIME, slot); | |
4358 | ||
a2e40bb6 | 4359 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(bss->ifname)); |
c5121837 JM |
4360 | |
4361 | return send_and_recv_msgs(drv, msg, NULL, NULL); | |
4362 | nla_put_failure: | |
4363 | return -ENOBUFS; | |
4364 | } | |
4365 | ||
4366 | ||
4367 | static int i802_set_cts_protect(void *priv, int value) | |
4368 | { | |
4369 | return i802_set_bss(priv, value, -1, -1); | |
4370 | } | |
4371 | ||
4372 | ||
4373 | static int i802_set_preamble(void *priv, int value) | |
4374 | { | |
4375 | return i802_set_bss(priv, -1, value, -1); | |
4376 | } | |
4377 | ||
4378 | ||
4379 | static int i802_set_short_slot_time(void *priv, int value) | |
4380 | { | |
4381 | return i802_set_bss(priv, -1, -1, value); | |
4382 | } | |
4383 | ||
4384 | ||
c5121837 JM |
4385 | static int i802_set_sta_vlan(void *priv, const u8 *addr, |
4386 | const char *ifname, int vlan_id) | |
4387 | { | |
a2e40bb6 FF |
4388 | struct i802_bss *bss = priv; |
4389 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
c5121837 JM |
4390 | struct nl_msg *msg; |
4391 | ||
4392 | msg = nlmsg_alloc(); | |
4393 | if (!msg) | |
4394 | return -ENOMEM; | |
4395 | ||
4396 | genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0, | |
4397 | 0, NL80211_CMD_SET_STATION, 0); | |
4398 | ||
4399 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, | |
a2e40bb6 | 4400 | if_nametoindex(bss->ifname)); |
c5121837 | 4401 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); |
1c766b09 | 4402 | NLA_PUT_U32(msg, NL80211_ATTR_STA_VLAN, |
c5121837 JM |
4403 | if_nametoindex(ifname)); |
4404 | ||
4405 | return send_and_recv_msgs(drv, msg, NULL, NULL); | |
4406 | nla_put_failure: | |
4407 | return -ENOBUFS; | |
4408 | } | |
4409 | ||
4410 | ||
fbbfcbac FF |
4411 | static int i802_set_wds_sta(void *priv, const u8 *addr, int aid, int val) |
4412 | { | |
a2e40bb6 FF |
4413 | struct i802_bss *bss = priv; |
4414 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
e748062b | 4415 | char name[IFNAMSIZ + 1]; |
fbbfcbac | 4416 | |
a2e40bb6 | 4417 | os_snprintf(name, sizeof(name), "%s.sta%d", bss->ifname, aid); |
e748062b JM |
4418 | wpa_printf(MSG_DEBUG, "nl80211: Set WDS STA addr=" MACSTR |
4419 | " aid=%d val=%d name=%s", MAC2STR(addr), aid, val, name); | |
fbbfcbac | 4420 | if (val) { |
a2e40bb6 | 4421 | if (nl80211_create_iface(drv, name, NL80211_IFTYPE_AP_VLAN, |
fbbfcbac FF |
4422 | NULL, 1) < 0) |
4423 | return -1; | |
34f2f814 | 4424 | linux_set_iface_flags(drv->ioctl_sock, name, 1); |
fbbfcbac FF |
4425 | return i802_set_sta_vlan(priv, addr, name, 0); |
4426 | } else { | |
a2e40bb6 | 4427 | i802_set_sta_vlan(priv, addr, bss->ifname, 0); |
fbbfcbac FF |
4428 | return wpa_driver_nl80211_if_remove(priv, WPA_IF_AP_VLAN, |
4429 | name); | |
4430 | } | |
4431 | } | |
4432 | ||
4433 | ||
c5121837 JM |
4434 | static void handle_eapol(int sock, void *eloop_ctx, void *sock_ctx) |
4435 | { | |
4436 | struct wpa_driver_nl80211_data *drv = eloop_ctx; | |
4437 | struct sockaddr_ll lladdr; | |
4438 | unsigned char buf[3000]; | |
4439 | int len; | |
4440 | socklen_t fromlen = sizeof(lladdr); | |
4441 | ||
4442 | len = recvfrom(sock, buf, sizeof(buf), 0, | |
4443 | (struct sockaddr *)&lladdr, &fromlen); | |
4444 | if (len < 0) { | |
4445 | perror("recv"); | |
4446 | return; | |
4447 | } | |
4448 | ||
baac6490 JM |
4449 | if (have_ifidx(drv, lladdr.sll_ifindex)) |
4450 | drv_event_eapol_rx(drv->ctx, lladdr.sll_addr, buf, len); | |
c5121837 JM |
4451 | } |
4452 | ||
4453 | ||
c5121837 JM |
4454 | static int i802_get_inact_sec(void *priv, const u8 *addr) |
4455 | { | |
4456 | struct hostap_sta_driver_data data; | |
4457 | int ret; | |
4458 | ||
4459 | data.inactive_msec = (unsigned long) -1; | |
4460 | ret = i802_read_sta_data(priv, &data, addr); | |
4461 | if (ret || data.inactive_msec == (unsigned long) -1) | |
4462 | return -1; | |
4463 | return data.inactive_msec / 1000; | |
4464 | } | |
4465 | ||
4466 | ||
4467 | static int i802_sta_clear_stats(void *priv, const u8 *addr) | |
4468 | { | |
4469 | #if 0 | |
4470 | /* TODO */ | |
4471 | #endif | |
4472 | return 0; | |
4473 | } | |
4474 | ||
4475 | ||
731723a5 JM |
4476 | static int i802_sta_deauth(void *priv, const u8 *own_addr, const u8 *addr, |
4477 | int reason) | |
c5121837 | 4478 | { |
a2e40bb6 | 4479 | struct i802_bss *bss = priv; |
c5121837 JM |
4480 | struct ieee80211_mgmt mgmt; |
4481 | ||
4482 | memset(&mgmt, 0, sizeof(mgmt)); | |
4483 | mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, | |
4484 | WLAN_FC_STYPE_DEAUTH); | |
4485 | memcpy(mgmt.da, addr, ETH_ALEN); | |
731723a5 JM |
4486 | memcpy(mgmt.sa, own_addr, ETH_ALEN); |
4487 | memcpy(mgmt.bssid, own_addr, ETH_ALEN); | |
c5121837 | 4488 | mgmt.u.deauth.reason_code = host_to_le16(reason); |
a2e40bb6 | 4489 | return wpa_driver_nl80211_send_mlme(bss, (u8 *) &mgmt, |
9f324b61 JM |
4490 | IEEE80211_HDRLEN + |
4491 | sizeof(mgmt.u.deauth)); | |
c5121837 JM |
4492 | } |
4493 | ||
4494 | ||
731723a5 JM |
4495 | static int i802_sta_disassoc(void *priv, const u8 *own_addr, const u8 *addr, |
4496 | int reason) | |
c5121837 | 4497 | { |
a2e40bb6 | 4498 | struct i802_bss *bss = priv; |
c5121837 JM |
4499 | struct ieee80211_mgmt mgmt; |
4500 | ||
4501 | memset(&mgmt, 0, sizeof(mgmt)); | |
4502 | mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, | |
4503 | WLAN_FC_STYPE_DISASSOC); | |
4504 | memcpy(mgmt.da, addr, ETH_ALEN); | |
731723a5 JM |
4505 | memcpy(mgmt.sa, own_addr, ETH_ALEN); |
4506 | memcpy(mgmt.bssid, own_addr, ETH_ALEN); | |
c5121837 | 4507 | mgmt.u.disassoc.reason_code = host_to_le16(reason); |
a2e40bb6 | 4508 | return wpa_driver_nl80211_send_mlme(bss, (u8 *) &mgmt, |
9f324b61 JM |
4509 | IEEE80211_HDRLEN + |
4510 | sizeof(mgmt.u.disassoc)); | |
c5121837 JM |
4511 | } |
4512 | ||
4513 | ||
94627f6c JM |
4514 | static int i802_check_bridge(struct wpa_driver_nl80211_data *drv, |
4515 | const char *brname, const char *ifname) | |
4516 | { | |
4517 | int ifindex; | |
4518 | char in_br[IFNAMSIZ]; | |
4519 | ||
4520 | os_strlcpy(drv->brname, brname, IFNAMSIZ); | |
4521 | ifindex = if_nametoindex(brname); | |
4522 | if (ifindex == 0) { | |
4523 | /* | |
4524 | * Bridge was configured, but the bridge device does | |
4525 | * not exist. Try to add it now. | |
4526 | */ | |
4527 | if (linux_br_add(drv->ioctl_sock, brname) < 0) { | |
4528 | wpa_printf(MSG_ERROR, "nl80211: Failed to add the " | |
4529 | "bridge interface %s: %s", | |
4530 | brname, strerror(errno)); | |
4531 | return -1; | |
4532 | } | |
4533 | drv->added_bridge = 1; | |
4534 | add_ifidx(drv, if_nametoindex(brname)); | |
4535 | } | |
4536 | ||
4537 | if (linux_br_get(in_br, ifname) == 0) { | |
4538 | if (os_strcmp(in_br, brname) == 0) | |
4539 | return 0; /* already in the bridge */ | |
4540 | ||
4541 | wpa_printf(MSG_DEBUG, "nl80211: Removing interface %s from " | |
4542 | "bridge %s", ifname, in_br); | |
4543 | if (linux_br_del_if(drv->ioctl_sock, in_br, ifname) < 0) { | |
4544 | wpa_printf(MSG_ERROR, "nl80211: Failed to " | |
4545 | "remove interface %s from bridge " | |
4546 | "%s: %s", | |
4547 | ifname, brname, strerror(errno)); | |
4548 | return -1; | |
4549 | } | |
4550 | } | |
4551 | ||
4552 | wpa_printf(MSG_DEBUG, "nl80211: Adding interface %s into bridge %s", | |
4553 | ifname, brname); | |
4554 | if (linux_br_add_if(drv->ioctl_sock, brname, ifname) < 0) { | |
4555 | wpa_printf(MSG_ERROR, "nl80211: Failed to add interface %s " | |
4556 | "into bridge %s: %s", | |
4557 | ifname, brname, strerror(errno)); | |
4558 | return -1; | |
4559 | } | |
4560 | drv->added_if_into_bridge = 1; | |
4561 | ||
4562 | return 0; | |
4563 | } | |
4564 | ||
4565 | ||
92f475b4 JM |
4566 | static void *i802_init(struct hostapd_data *hapd, |
4567 | struct wpa_init_params *params) | |
c5121837 JM |
4568 | { |
4569 | struct wpa_driver_nl80211_data *drv; | |
a2e40bb6 | 4570 | struct i802_bss *bss; |
c5121837 | 4571 | size_t i; |
94627f6c JM |
4572 | char brname[IFNAMSIZ]; |
4573 | int ifindex, br_ifindex; | |
4574 | int br_added = 0; | |
c5121837 | 4575 | |
a2e40bb6 FF |
4576 | bss = wpa_driver_nl80211_init(hapd, params->ifname); |
4577 | if (bss == NULL) | |
c5121837 | 4578 | return NULL; |
c5121837 | 4579 | |
a2e40bb6 | 4580 | drv = bss->drv; |
94627f6c JM |
4581 | if (linux_br_get(brname, params->ifname) == 0) { |
4582 | wpa_printf(MSG_DEBUG, "nl80211: Interface %s is in bridge %s", | |
4583 | params->ifname, brname); | |
4584 | br_ifindex = if_nametoindex(brname); | |
4585 | } else { | |
4586 | brname[0] = '\0'; | |
4587 | br_ifindex = 0; | |
4588 | } | |
4589 | ||
c5121837 JM |
4590 | drv->num_if_indices = sizeof(drv->default_if_indices) / sizeof(int); |
4591 | drv->if_indices = drv->default_if_indices; | |
92f475b4 | 4592 | for (i = 0; i < params->num_bridge; i++) { |
94627f6c JM |
4593 | if (params->bridge[i]) { |
4594 | ifindex = if_nametoindex(params->bridge[i]); | |
4595 | if (ifindex) | |
4596 | add_ifidx(drv, ifindex); | |
4597 | if (ifindex == br_ifindex) | |
4598 | br_added = 1; | |
4599 | } | |
c5121837 | 4600 | } |
94627f6c JM |
4601 | if (!br_added && br_ifindex && |
4602 | (params->num_bridge == 0 || !params->bridge[0])) | |
4603 | add_ifidx(drv, br_ifindex); | |
c5121837 | 4604 | |
ad1e68e6 JM |
4605 | /* start listening for EAPOL on the default AP interface */ |
4606 | add_ifidx(drv, drv->ifindex); | |
4607 | ||
a2e40bb6 | 4608 | if (linux_set_iface_flags(drv->ioctl_sock, bss->ifname, 0)) |
6980c191 | 4609 | goto failed; |
ad1e68e6 | 4610 | |
6980c191 | 4611 | if (params->bssid) { |
a2e40bb6 | 4612 | if (linux_set_ifhwaddr(drv->ioctl_sock, bss->ifname, |
2ac9688e | 4613 | params->bssid)) |
460456f8 JM |
4614 | goto failed; |
4615 | } | |
ad1e68e6 | 4616 | |
a2e40bb6 | 4617 | if (wpa_driver_nl80211_set_mode(bss, IEEE80211_MODE_AP)) { |
ad1e68e6 | 4618 | wpa_printf(MSG_ERROR, "nl80211: Failed to set interface %s " |
a2e40bb6 | 4619 | "into AP mode", bss->ifname); |
bbaf0837 | 4620 | goto failed; |
ad1e68e6 JM |
4621 | } |
4622 | ||
94627f6c JM |
4623 | if (params->num_bridge && params->bridge[0] && |
4624 | i802_check_bridge(drv, params->bridge[0], params->ifname) < 0) | |
4625 | goto failed; | |
4626 | ||
a2e40bb6 | 4627 | if (linux_set_iface_flags(drv->ioctl_sock, bss->ifname, 1)) |
bbaf0837 | 4628 | goto failed; |
ad1e68e6 JM |
4629 | |
4630 | drv->eapol_sock = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_PAE)); | |
4631 | if (drv->eapol_sock < 0) { | |
4632 | perror("socket(PF_PACKET, SOCK_DGRAM, ETH_P_PAE)"); | |
bbaf0837 | 4633 | goto failed; |
ad1e68e6 JM |
4634 | } |
4635 | ||
4636 | if (eloop_register_read_sock(drv->eapol_sock, handle_eapol, drv, NULL)) | |
4637 | { | |
4638 | printf("Could not register read socket for eapol\n"); | |
c5121837 | 4639 | goto failed; |
ad1e68e6 JM |
4640 | } |
4641 | ||
a2e40bb6 | 4642 | if (linux_get_ifhwaddr(drv->ioctl_sock, bss->ifname, params->own_addr)) |
bbaf0837 | 4643 | goto failed; |
c5121837 | 4644 | |
a2e40bb6 | 4645 | return bss; |
c5121837 JM |
4646 | |
4647 | failed: | |
460456f8 | 4648 | nl80211_remove_monitor_interface(drv); |
c5121837 JM |
4649 | if (drv->ioctl_sock >= 0) |
4650 | close(drv->ioctl_sock); | |
c5121837 JM |
4651 | |
4652 | genl_family_put(drv->nl80211); | |
4653 | nl_cache_free(drv->nl_cache); | |
4654 | nl_handle_destroy(drv->nl_handle); | |
4655 | nl_cb_put(drv->nl_cb); | |
4656 | ||
bbaf0837 JM |
4657 | os_free(drv); |
4658 | return NULL; | |
4659 | } | |
c5121837 | 4660 | |
c5121837 | 4661 | |
bbaf0837 JM |
4662 | static void i802_deinit(void *priv) |
4663 | { | |
4664 | wpa_driver_nl80211_deinit(priv); | |
c5121837 JM |
4665 | } |
4666 | ||
4667 | #endif /* HOSTAPD */ | |
4668 | ||
4669 | ||
22a7c9d7 JM |
4670 | static enum nl80211_iftype wpa_driver_nl80211_if_type( |
4671 | enum wpa_driver_if_type type) | |
4672 | { | |
4673 | switch (type) { | |
4674 | case WPA_IF_STATION: | |
4675 | return NL80211_IFTYPE_STATION; | |
4676 | case WPA_IF_AP_VLAN: | |
4677 | return NL80211_IFTYPE_AP_VLAN; | |
4678 | case WPA_IF_AP_BSS: | |
4679 | return NL80211_IFTYPE_AP; | |
4680 | } | |
4681 | return -1; | |
4682 | } | |
4683 | ||
4684 | ||
4685 | static int wpa_driver_nl80211_if_add(const char *iface, void *priv, | |
4686 | 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); | |
22a7c9d7 JM |
4717 | os_free(bss); |
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 | }; |