]>
Commit | Line | Data |
---|---|---|
6fc6879b JM |
1 | /* |
2 | * WPA Supplicant - driver interaction with BSD net80211 layer | |
3 | * Copyright (c) 2004, Sam Leffler <sam@errno.com> | |
c5121837 | 4 | * Copyright (c) 2004, 2Wire, Inc |
6fc6879b JM |
5 | * |
6 | * This program is free software; you can redistribute it and/or modify | |
7 | * it under the terms of the GNU General Public License version 2 as | |
8 | * published by the Free Software Foundation. | |
9 | * | |
10 | * Alternatively, this software may be distributed under the terms of BSD | |
11 | * license. | |
12 | * | |
13 | * See README and COPYING for more details. | |
14 | */ | |
15 | ||
16 | #include "includes.h" | |
17 | #include <sys/ioctl.h> | |
18 | ||
19 | #include "common.h" | |
20 | #include "driver.h" | |
21 | #include "eloop.h" | |
22 | #include "ieee802_11_defs.h" | |
23 | ||
24 | #include <net/if.h> | |
898d6921 JR |
25 | |
26 | #ifdef __NetBSD__ | |
27 | #include <net/if_ether.h> | |
898d6921 | 28 | #else |
6fc6879b | 29 | #include <net/ethernet.h> |
898d6921 | 30 | #endif |
131289d8 | 31 | #include <net/route.h> |
6fc6879b JM |
32 | |
33 | #include <net80211/ieee80211.h> | |
34 | #include <net80211/ieee80211_crypto.h> | |
35 | #include <net80211/ieee80211_ioctl.h> | |
131289d8 MH |
36 | #if __FreeBSD__ |
37 | #include <net80211/ieee80211_freebsd.h> | |
38 | #endif | |
39 | #if __NetBSD__ | |
40 | #include <net80211/ieee80211_netbsd.h> | |
41 | #endif | |
42 | ||
66d4085f RM |
43 | /* Generic functions for hostapd and wpa_supplicant */ |
44 | ||
45 | static int | |
46 | bsd_set80211var(int s, const char *ifname, int op, const void *arg, int arg_len) | |
47 | { | |
48 | struct ieee80211req ireq; | |
49 | ||
50 | os_memset(&ireq, 0, sizeof(ireq)); | |
51 | os_strlcpy(ireq.i_name, ifname, sizeof(ireq.i_name)); | |
52 | ireq.i_type = op; | |
53 | ireq.i_len = arg_len; | |
54 | ireq.i_data = (void *) arg; | |
55 | ||
56 | if (ioctl(s, SIOCS80211, &ireq) < 0) { | |
57 | fprintf(stderr, "ioctl[SIOCS80211, op %u, len %u]: %s\n", | |
58 | op, arg_len, strerror(errno)); | |
59 | return -1; | |
60 | } | |
61 | return 0; | |
62 | } | |
63 | ||
64 | static int | |
65 | bsd_get80211var(int s, const char *ifname, int op, void *arg, int arg_len) | |
66 | { | |
67 | struct ieee80211req ireq; | |
68 | ||
69 | os_memset(&ireq, 0, sizeof(ireq)); | |
70 | os_strlcpy(ireq.i_name, ifname, sizeof(ireq.i_name)); | |
71 | ireq.i_type = op; | |
72 | ireq.i_len = arg_len; | |
73 | ireq.i_data = arg; | |
74 | ||
75 | if (ioctl(s, SIOCG80211, &ireq) < 0) { | |
76 | fprintf(stderr, "ioctl[SIOCG80211, op %u, len %u]: %s\n", | |
77 | op, arg_len, strerror(errno)); | |
78 | return -1; | |
79 | } | |
80 | return ireq.i_len; | |
81 | } | |
82 | ||
83 | static int | |
84 | bsd_set80211param(int s, const char *ifname, int op, int arg) | |
85 | { | |
86 | struct ieee80211req ireq; | |
87 | ||
88 | os_memset(&ireq, 0, sizeof(ireq)); | |
89 | os_strlcpy(ireq.i_name, ifname, sizeof(ireq.i_name)); | |
90 | ireq.i_type = op; | |
91 | ireq.i_val = arg; | |
92 | ||
93 | if (ioctl(s, SIOCS80211, &ireq) < 0) { | |
94 | fprintf(stderr, "ioctl[SIOCS80211, op %u, arg 0x%x]: %s\n", | |
95 | op, arg, strerror(errno)); | |
96 | return -1; | |
97 | } | |
98 | return 0; | |
99 | } | |
100 | ||
101 | static int | |
102 | bsd_get_ssid(int s, const char *ifname, u8 *ssid) | |
103 | { | |
104 | #ifdef SIOCG80211NWID | |
105 | struct ieee80211_nwid nwid; | |
106 | struct ifreq ifr; | |
107 | ||
108 | os_memset(&ifr, 0, sizeof(ifr)); | |
109 | os_strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name)); | |
110 | ifr.ifr_data = (void *)&nwid; | |
111 | if (ioctl(s, SIOCG80211NWID, &ifr) < 0 || | |
112 | nwid.i_len > IEEE80211_NWID_LEN) | |
113 | return -1; | |
114 | os_memcpy(ssid, nwid.i_nwid, nwid.i_len); | |
115 | return nwid.i_len; | |
116 | #else | |
117 | return bsd_get80211var(s, ifname, IEEE80211_IOC_SSID, | |
118 | ssid, IEEE80211_NWID_LEN); | |
119 | #endif | |
120 | } | |
121 | ||
122 | static int | |
123 | bsd_set_ssid(int s, const char *ifname, const u8 *ssid, size_t ssid_len) | |
124 | { | |
125 | #ifdef SIOCS80211NWID | |
126 | struct ieee80211_nwid nwid; | |
127 | struct ifreq ifr; | |
128 | ||
129 | os_memcpy(nwid.i_nwid, ssid, ssid_len); | |
130 | nwid.i_len = ssid_len; | |
131 | os_memset(&ifr, 0, sizeof(ifr)); | |
132 | os_strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name)); | |
133 | ifr.ifr_data = (void *)&nwid; | |
134 | return ioctl(s, SIOCS80211NWID, &ifr); | |
135 | #else | |
136 | return bsd_set80211var(s, ifname, IEEE80211_IOC_SSID, ssid, ssid_len); | |
137 | #endif | |
138 | } | |
139 | ||
140 | ||
131289d8 | 141 | #ifdef HOSTAPD |
6fc6879b | 142 | |
c5121837 JM |
143 | /* |
144 | * Avoid conflicts with hostapd definitions by undefining couple of defines | |
145 | * from net80211 header files. | |
146 | */ | |
147 | #undef RSN_VERSION | |
148 | #undef WPA_VERSION | |
149 | #undef WPA_OUI_TYPE | |
150 | ||
c5121837 JM |
151 | #include "l2_packet/l2_packet.h" |
152 | #include "../../hostapd/hostapd.h" | |
153 | #include "../../hostapd/config.h" | |
154 | #include "../../hostapd/eapol_sm.h" | |
131289d8 | 155 | #include "../../hostapd/sta_flags.h" |
c5121837 JM |
156 | |
157 | struct bsd_driver_data { | |
158 | struct hostapd_data *hapd; /* back pointer */ | |
159 | ||
160 | char iface[IFNAMSIZ + 1]; | |
161 | struct l2_packet_data *sock_xmit; /* raw packet xmit socket */ | |
162 | int ioctl_sock; /* socket for ioctl() use */ | |
163 | int wext_sock; /* socket for wireless events */ | |
164 | }; | |
165 | ||
731723a5 JM |
166 | static int bsd_sta_deauth(void *priv, const u8 *own_addr, const u8 *addr, |
167 | int reason_code); | |
c5121837 JM |
168 | |
169 | static int | |
170 | set80211var(struct bsd_driver_data *drv, int op, const void *arg, int arg_len) | |
171 | { | |
66d4085f | 172 | return bsd_set80211var(drv->ioctl_sock, drv->iface, op, arg, arg_len); |
c5121837 JM |
173 | } |
174 | ||
175 | static int | |
176 | get80211var(struct bsd_driver_data *drv, int op, void *arg, int arg_len) | |
177 | { | |
66d4085f | 178 | return bsd_get80211var(drv->ioctl_sock, drv->iface, op, arg, arg_len); |
c5121837 JM |
179 | } |
180 | ||
181 | static int | |
182 | set80211param(struct bsd_driver_data *drv, int op, int arg) | |
183 | { | |
66d4085f | 184 | return bsd_set80211param(drv->ioctl_sock, drv->iface, op, arg); |
c5121837 JM |
185 | } |
186 | ||
187 | static const char * | |
188 | ether_sprintf(const u8 *addr) | |
189 | { | |
190 | static char buf[sizeof(MACSTR)]; | |
191 | ||
192 | if (addr != NULL) | |
193 | snprintf(buf, sizeof(buf), MACSTR, MAC2STR(addr)); | |
194 | else | |
195 | snprintf(buf, sizeof(buf), MACSTR, 0,0,0,0,0,0); | |
196 | return buf; | |
197 | } | |
198 | ||
199 | /* | |
200 | * Configure WPA parameters. | |
201 | */ | |
202 | static int | |
203 | bsd_configure_wpa(struct bsd_driver_data *drv) | |
204 | { | |
205 | static const char *ciphernames[] = | |
206 | { "WEP", "TKIP", "AES-OCB", "AES-CCM", "CKIP", "NONE" }; | |
207 | struct hostapd_data *hapd = drv->hapd; | |
208 | struct hostapd_bss_config *conf = hapd->conf; | |
209 | int v; | |
210 | ||
211 | switch (conf->wpa_group) { | |
212 | case WPA_CIPHER_CCMP: | |
213 | v = IEEE80211_CIPHER_AES_CCM; | |
214 | break; | |
215 | case WPA_CIPHER_TKIP: | |
216 | v = IEEE80211_CIPHER_TKIP; | |
217 | break; | |
218 | case WPA_CIPHER_WEP104: | |
219 | v = IEEE80211_CIPHER_WEP; | |
220 | break; | |
221 | case WPA_CIPHER_WEP40: | |
222 | v = IEEE80211_CIPHER_WEP; | |
223 | break; | |
224 | case WPA_CIPHER_NONE: | |
225 | v = IEEE80211_CIPHER_NONE; | |
226 | break; | |
227 | default: | |
228 | printf("Unknown group key cipher %u\n", | |
229 | conf->wpa_group); | |
230 | return -1; | |
231 | } | |
232 | wpa_printf(MSG_DEBUG, "%s: group key cipher=%s (%u)", | |
233 | __func__, ciphernames[v], v); | |
234 | if (set80211param(drv, IEEE80211_IOC_MCASTCIPHER, v)) { | |
235 | printf("Unable to set group key cipher to %u (%s)\n", | |
236 | v, ciphernames[v]); | |
237 | return -1; | |
238 | } | |
239 | if (v == IEEE80211_CIPHER_WEP) { | |
240 | /* key length is done only for specific ciphers */ | |
241 | v = (conf->wpa_group == WPA_CIPHER_WEP104 ? 13 : 5); | |
242 | if (set80211param(drv, IEEE80211_IOC_MCASTKEYLEN, v)) { | |
243 | printf("Unable to set group key length to %u\n", v); | |
244 | return -1; | |
245 | } | |
246 | } | |
247 | ||
248 | v = 0; | |
249 | if (conf->wpa_pairwise & WPA_CIPHER_CCMP) | |
250 | v |= 1<<IEEE80211_CIPHER_AES_CCM; | |
251 | if (conf->wpa_pairwise & WPA_CIPHER_TKIP) | |
252 | v |= 1<<IEEE80211_CIPHER_TKIP; | |
253 | if (conf->wpa_pairwise & WPA_CIPHER_NONE) | |
254 | v |= 1<<IEEE80211_CIPHER_NONE; | |
255 | wpa_printf(MSG_DEBUG, "%s: pairwise key ciphers=0x%x", __func__, v); | |
256 | if (set80211param(drv, IEEE80211_IOC_UCASTCIPHERS, v)) { | |
257 | printf("Unable to set pairwise key ciphers to 0x%x\n", v); | |
258 | return -1; | |
259 | } | |
260 | ||
261 | wpa_printf(MSG_DEBUG, "%s: key management algorithms=0x%x", | |
262 | __func__, conf->wpa_key_mgmt); | |
263 | if (set80211param(drv, IEEE80211_IOC_KEYMGTALGS, conf->wpa_key_mgmt)) { | |
264 | printf("Unable to set key management algorithms to 0x%x\n", | |
265 | conf->wpa_key_mgmt); | |
266 | return -1; | |
267 | } | |
268 | ||
269 | v = 0; | |
270 | if (conf->rsn_preauth) | |
271 | v |= BIT(0); | |
272 | wpa_printf(MSG_DEBUG, "%s: rsn capabilities=0x%x", | |
273 | __func__, conf->rsn_preauth); | |
274 | if (set80211param(drv, IEEE80211_IOC_RSNCAPS, v)) { | |
275 | printf("Unable to set RSN capabilities to 0x%x\n", v); | |
276 | return -1; | |
277 | } | |
278 | ||
279 | wpa_printf(MSG_DEBUG, "%s: enable WPA= 0x%x", __func__, conf->wpa); | |
280 | if (set80211param(drv, IEEE80211_IOC_WPA, conf->wpa)) { | |
281 | printf("Unable to set WPA to %u\n", conf->wpa); | |
282 | return -1; | |
283 | } | |
284 | return 0; | |
285 | } | |
286 | ||
287 | ||
288 | static int | |
289 | bsd_set_iface_flags(void *priv, int dev_up) | |
290 | { | |
291 | struct bsd_driver_data *drv = priv; | |
292 | struct ifreq ifr; | |
293 | ||
294 | wpa_printf(MSG_DEBUG, "%s: dev_up=%d", __func__, dev_up); | |
295 | ||
296 | if (drv->ioctl_sock < 0) | |
297 | return -1; | |
298 | ||
299 | memset(&ifr, 0, sizeof(ifr)); | |
66d4085f | 300 | os_strlcpy(ifr.ifr_name, drv->iface, sizeof(ifr.ifr_name)); |
c5121837 JM |
301 | |
302 | if (ioctl(drv->ioctl_sock, SIOCGIFFLAGS, &ifr) != 0) { | |
303 | perror("ioctl[SIOCGIFFLAGS]"); | |
304 | return -1; | |
305 | } | |
306 | ||
307 | if (dev_up) | |
308 | ifr.ifr_flags |= IFF_UP; | |
309 | else | |
310 | ifr.ifr_flags &= ~IFF_UP; | |
311 | ||
312 | if (ioctl(drv->ioctl_sock, SIOCSIFFLAGS, &ifr) != 0) { | |
313 | perror("ioctl[SIOCSIFFLAGS]"); | |
314 | return -1; | |
315 | } | |
316 | ||
317 | if (dev_up) { | |
318 | memset(&ifr, 0, sizeof(ifr)); | |
66d4085f | 319 | os_strlcpy(ifr.ifr_name, drv->iface, sizeof(ifr.ifr_name)); |
c5121837 JM |
320 | ifr.ifr_mtu = HOSTAPD_MTU; |
321 | if (ioctl(drv->ioctl_sock, SIOCSIFMTU, &ifr) != 0) { | |
322 | perror("ioctl[SIOCSIFMTU]"); | |
323 | printf("Setting MTU failed - trying to survive with " | |
324 | "current value\n"); | |
325 | } | |
326 | } | |
327 | ||
328 | return 0; | |
329 | } | |
330 | ||
331 | static int | |
332 | bsd_set_ieee8021x(const char *ifname, void *priv, int enabled) | |
333 | { | |
334 | struct bsd_driver_data *drv = priv; | |
335 | struct hostapd_data *hapd = drv->hapd; | |
336 | struct hostapd_bss_config *conf = hapd->conf; | |
337 | ||
338 | wpa_printf(MSG_DEBUG, "%s: enabled=%d", __func__, enabled); | |
339 | ||
340 | if (!enabled) { | |
341 | /* XXX restore state */ | |
342 | return set80211param(priv, IEEE80211_IOC_AUTHMODE, | |
343 | IEEE80211_AUTH_AUTO); | |
344 | } | |
345 | if (!conf->wpa && !conf->ieee802_1x) { | |
346 | hostapd_logger(hapd, NULL, HOSTAPD_MODULE_DRIVER, | |
347 | HOSTAPD_LEVEL_WARNING, "No 802.1X or WPA enabled!"); | |
348 | return -1; | |
349 | } | |
350 | if (conf->wpa && bsd_configure_wpa(drv) != 0) { | |
351 | hostapd_logger(hapd, NULL, HOSTAPD_MODULE_DRIVER, | |
352 | HOSTAPD_LEVEL_WARNING, "Error configuring WPA state!"); | |
353 | return -1; | |
354 | } | |
355 | if (set80211param(priv, IEEE80211_IOC_AUTHMODE, | |
356 | (conf->wpa ? IEEE80211_AUTH_WPA : IEEE80211_AUTH_8021X))) { | |
357 | hostapd_logger(hapd, NULL, HOSTAPD_MODULE_DRIVER, | |
358 | HOSTAPD_LEVEL_WARNING, "Error enabling WPA/802.1X!"); | |
359 | return -1; | |
360 | } | |
361 | return bsd_set_iface_flags(priv, 1); | |
362 | } | |
363 | ||
364 | static int | |
365 | bsd_set_privacy(const char *ifname, void *priv, int enabled) | |
366 | { | |
367 | struct bsd_driver_data *drv = priv; | |
368 | ||
369 | wpa_printf(MSG_DEBUG, "%s: enabled=%d", __func__, enabled); | |
370 | ||
371 | return set80211param(drv, IEEE80211_IOC_PRIVACY, enabled); | |
372 | } | |
373 | ||
374 | static int | |
375 | bsd_set_sta_authorized(void *priv, const u8 *addr, int authorized) | |
376 | { | |
377 | struct bsd_driver_data *drv = priv; | |
378 | struct ieee80211req_mlme mlme; | |
379 | ||
380 | wpa_printf(MSG_DEBUG, "%s: addr=%s authorized=%d", | |
381 | __func__, ether_sprintf(addr), authorized); | |
382 | ||
383 | if (authorized) | |
384 | mlme.im_op = IEEE80211_MLME_AUTHORIZE; | |
385 | else | |
386 | mlme.im_op = IEEE80211_MLME_UNAUTHORIZE; | |
387 | mlme.im_reason = 0; | |
388 | memcpy(mlme.im_macaddr, addr, IEEE80211_ADDR_LEN); | |
389 | return set80211var(drv, IEEE80211_IOC_MLME, &mlme, sizeof(mlme)); | |
390 | } | |
391 | ||
392 | static int | |
393 | bsd_sta_set_flags(void *priv, const u8 *addr, int total_flags, int flags_or, | |
394 | int flags_and) | |
395 | { | |
396 | /* For now, only support setting Authorized flag */ | |
397 | if (flags_or & WLAN_STA_AUTHORIZED) | |
398 | return bsd_set_sta_authorized(priv, addr, 1); | |
399 | if (!(flags_and & WLAN_STA_AUTHORIZED)) | |
400 | return bsd_set_sta_authorized(priv, addr, 0); | |
401 | return 0; | |
402 | } | |
403 | ||
404 | static int | |
405 | bsd_del_key(void *priv, const u8 *addr, int key_idx) | |
406 | { | |
407 | struct bsd_driver_data *drv = priv; | |
408 | struct ieee80211req_del_key wk; | |
409 | ||
410 | wpa_printf(MSG_DEBUG, "%s: addr=%s key_idx=%d", | |
411 | __func__, ether_sprintf(addr), key_idx); | |
412 | ||
413 | memset(&wk, 0, sizeof(wk)); | |
414 | if (addr != NULL) { | |
415 | memcpy(wk.idk_macaddr, addr, IEEE80211_ADDR_LEN); | |
416 | wk.idk_keyix = (u_int8_t) IEEE80211_KEYIX_NONE; /* XXX */ | |
417 | } else { | |
418 | wk.idk_keyix = key_idx; | |
419 | } | |
420 | ||
421 | return set80211var(drv, IEEE80211_IOC_DELKEY, &wk, sizeof(wk)); | |
422 | } | |
423 | ||
424 | static int | |
425 | bsd_set_key(const char *ifname, void *priv, wpa_alg alg, | |
426 | const u8 *addr, int key_idx, int set_tx, const u8 *seq, | |
427 | size_t seq_len, const u8 *key, size_t key_len) | |
428 | { | |
429 | struct bsd_driver_data *drv = priv; | |
430 | struct ieee80211req_key wk; | |
431 | u_int8_t cipher; | |
432 | ||
433 | if (alg == WPA_ALG_NONE) | |
434 | return bsd_del_key(drv, addr, key_idx); | |
435 | ||
436 | wpa_printf(MSG_DEBUG, "%s: alg=%d addr=%s key_idx=%d", | |
437 | __func__, alg, ether_sprintf(addr), key_idx); | |
438 | ||
439 | if (alg == WPA_ALG_WEP) | |
440 | cipher = IEEE80211_CIPHER_WEP; | |
441 | else if (alg == WPA_ALG_TKIP) | |
442 | cipher = IEEE80211_CIPHER_TKIP; | |
443 | else if (alg == WPA_ALG_CCMP) | |
444 | cipher = IEEE80211_CIPHER_AES_CCM; | |
445 | else { | |
446 | printf("%s: unknown/unsupported algorithm %d\n", | |
447 | __func__, alg); | |
448 | return -1; | |
449 | } | |
450 | ||
451 | if (key_len > sizeof(wk.ik_keydata)) { | |
92e63aaf | 452 | printf("%s: key length %d too big\n", __func__, (int) key_len); |
c5121837 JM |
453 | return -3; |
454 | } | |
455 | ||
456 | memset(&wk, 0, sizeof(wk)); | |
457 | wk.ik_type = cipher; | |
458 | wk.ik_flags = IEEE80211_KEY_RECV | IEEE80211_KEY_XMIT; | |
459 | if (addr == NULL) { | |
460 | memset(wk.ik_macaddr, 0xff, IEEE80211_ADDR_LEN); | |
461 | wk.ik_keyix = key_idx; | |
462 | wk.ik_flags |= IEEE80211_KEY_DEFAULT; | |
463 | } else { | |
464 | memcpy(wk.ik_macaddr, addr, IEEE80211_ADDR_LEN); | |
465 | wk.ik_keyix = IEEE80211_KEYIX_NONE; | |
466 | } | |
467 | wk.ik_keylen = key_len; | |
468 | memcpy(wk.ik_keydata, key, key_len); | |
469 | ||
470 | return set80211var(drv, IEEE80211_IOC_WPAKEY, &wk, sizeof(wk)); | |
471 | } | |
472 | ||
473 | ||
474 | static int | |
475 | bsd_get_seqnum(const char *ifname, void *priv, const u8 *addr, int idx, | |
476 | u8 *seq) | |
477 | { | |
478 | struct bsd_driver_data *drv = priv; | |
479 | struct ieee80211req_key wk; | |
480 | ||
481 | wpa_printf(MSG_DEBUG, "%s: addr=%s idx=%d", | |
482 | __func__, ether_sprintf(addr), idx); | |
483 | ||
484 | memset(&wk, 0, sizeof(wk)); | |
485 | if (addr == NULL) | |
486 | memset(wk.ik_macaddr, 0xff, IEEE80211_ADDR_LEN); | |
487 | else | |
488 | memcpy(wk.ik_macaddr, addr, IEEE80211_ADDR_LEN); | |
489 | wk.ik_keyix = idx; | |
490 | ||
491 | if (get80211var(drv, IEEE80211_IOC_WPAKEY, &wk, sizeof(wk)) < 0) { | |
492 | printf("Failed to get encryption.\n"); | |
493 | return -1; | |
494 | } | |
495 | ||
496 | #ifdef WORDS_BIGENDIAN | |
497 | { | |
498 | /* | |
499 | * wk.ik_keytsc is in host byte order (big endian), need to | |
500 | * swap it to match with the byte order used in WPA. | |
501 | */ | |
502 | int i; | |
503 | u8 tmp[WPA_KEY_RSC_LEN]; | |
504 | memcpy(tmp, &wk.ik_keytsc, sizeof(wk.ik_keytsc)); | |
505 | for (i = 0; i < WPA_KEY_RSC_LEN; i++) { | |
506 | seq[i] = tmp[WPA_KEY_RSC_LEN - i - 1]; | |
507 | } | |
508 | } | |
509 | #else /* WORDS_BIGENDIAN */ | |
510 | memcpy(seq, &wk.ik_keytsc, sizeof(wk.ik_keytsc)); | |
511 | #endif /* WORDS_BIGENDIAN */ | |
512 | return 0; | |
513 | } | |
514 | ||
515 | ||
516 | static int | |
517 | bsd_flush(void *priv) | |
518 | { | |
519 | u8 allsta[IEEE80211_ADDR_LEN]; | |
520 | ||
521 | memset(allsta, 0xff, IEEE80211_ADDR_LEN); | |
731723a5 | 522 | return bsd_sta_deauth(priv, NULL, allsta, IEEE80211_REASON_AUTH_LEAVE); |
c5121837 JM |
523 | } |
524 | ||
525 | ||
526 | static int | |
527 | bsd_read_sta_driver_data(void *priv, struct hostap_sta_driver_data *data, | |
528 | const u8 *addr) | |
529 | { | |
530 | struct bsd_driver_data *drv = priv; | |
531 | struct ieee80211req_sta_stats stats; | |
532 | ||
533 | memcpy(stats.is_u.macaddr, addr, IEEE80211_ADDR_LEN); | |
534 | if (get80211var(drv, IEEE80211_IOC_STA_STATS, &stats, sizeof(stats)) > 0) { | |
535 | /* XXX? do packets counts include non-data frames? */ | |
536 | data->rx_packets = stats.is_stats.ns_rx_data; | |
537 | data->rx_bytes = stats.is_stats.ns_rx_bytes; | |
538 | data->tx_packets = stats.is_stats.ns_tx_data; | |
539 | data->tx_bytes = stats.is_stats.ns_tx_bytes; | |
540 | } | |
541 | return 0; | |
542 | } | |
543 | ||
544 | static int | |
545 | bsd_set_opt_ie(const char *ifname, void *priv, const u8 *ie, size_t ie_len) | |
546 | { | |
547 | /* | |
548 | * Do nothing; we setup parameters at startup that define the | |
549 | * contents of the beacon information element. | |
550 | */ | |
551 | return 0; | |
552 | } | |
553 | ||
554 | static int | |
731723a5 | 555 | bsd_sta_deauth(void *priv, const u8 *own_addr, const u8 *addr, int reason_code) |
c5121837 JM |
556 | { |
557 | struct bsd_driver_data *drv = priv; | |
558 | struct ieee80211req_mlme mlme; | |
559 | ||
560 | wpa_printf(MSG_DEBUG, "%s: addr=%s reason_code=%d", | |
561 | __func__, ether_sprintf(addr), reason_code); | |
562 | ||
563 | mlme.im_op = IEEE80211_MLME_DEAUTH; | |
564 | mlme.im_reason = reason_code; | |
565 | memcpy(mlme.im_macaddr, addr, IEEE80211_ADDR_LEN); | |
566 | return set80211var(drv, IEEE80211_IOC_MLME, &mlme, sizeof(mlme)); | |
567 | } | |
568 | ||
569 | static int | |
731723a5 JM |
570 | bsd_sta_disassoc(void *priv, const u8 *own_addr, const u8 *addr, |
571 | int reason_code) | |
c5121837 JM |
572 | { |
573 | struct bsd_driver_data *drv = priv; | |
574 | struct ieee80211req_mlme mlme; | |
575 | ||
576 | wpa_printf(MSG_DEBUG, "%s: addr=%s reason_code=%d", | |
577 | __func__, ether_sprintf(addr), reason_code); | |
578 | ||
579 | mlme.im_op = IEEE80211_MLME_DISASSOC; | |
580 | mlme.im_reason = reason_code; | |
581 | memcpy(mlme.im_macaddr, addr, IEEE80211_ADDR_LEN); | |
582 | return set80211var(drv, IEEE80211_IOC_MLME, &mlme, sizeof(mlme)); | |
583 | } | |
584 | ||
585 | static int | |
586 | bsd_new_sta(struct bsd_driver_data *drv, u8 addr[IEEE80211_ADDR_LEN]) | |
587 | { | |
588 | struct hostapd_data *hapd = drv->hapd; | |
589 | struct ieee80211req_wpaie ie; | |
590 | int ielen = 0; | |
591 | u8 *iebuf = NULL; | |
592 | ||
593 | /* | |
594 | * Fetch and validate any negotiated WPA/RSN parameters. | |
595 | */ | |
596 | memset(&ie, 0, sizeof(ie)); | |
597 | memcpy(ie.wpa_macaddr, addr, IEEE80211_ADDR_LEN); | |
598 | if (get80211var(drv, IEEE80211_IOC_WPAIE, &ie, sizeof(ie)) < 0) { | |
599 | printf("Failed to get WPA/RSN information element.\n"); | |
600 | goto no_ie; | |
601 | } | |
602 | iebuf = ie.wpa_ie; | |
603 | ielen = ie.wpa_ie[1]; | |
604 | if (ielen == 0) | |
605 | iebuf = NULL; | |
606 | else | |
607 | ielen += 2; | |
608 | ||
609 | no_ie: | |
610 | return hostapd_notif_assoc(hapd, addr, iebuf, ielen); | |
611 | } | |
612 | ||
c5121837 JM |
613 | static void |
614 | bsd_wireless_event_receive(int sock, void *ctx, void *sock_ctx) | |
615 | { | |
616 | struct bsd_driver_data *drv = ctx; | |
617 | struct hostapd_data *hapd = drv->hapd; | |
618 | char buf[2048]; | |
619 | struct if_announcemsghdr *ifan; | |
620 | struct rt_msghdr *rtm; | |
621 | struct ieee80211_michael_event *mic; | |
622 | struct ieee80211_join_event *join; | |
623 | struct ieee80211_leave_event *leave; | |
624 | int n; | |
625 | ||
626 | n = read(sock, buf, sizeof(buf)); | |
627 | if (n < 0) { | |
628 | if (errno != EINTR && errno != EAGAIN) | |
629 | perror("read(PF_ROUTE)"); | |
630 | return; | |
631 | } | |
632 | ||
633 | rtm = (struct rt_msghdr *) buf; | |
634 | if (rtm->rtm_version != RTM_VERSION) { | |
635 | wpa_printf(MSG_DEBUG, "Routing message version %d not " | |
636 | "understood\n", rtm->rtm_version); | |
637 | return; | |
638 | } | |
639 | ifan = (struct if_announcemsghdr *) rtm; | |
640 | switch (rtm->rtm_type) { | |
641 | case RTM_IEEE80211: | |
642 | switch (ifan->ifan_what) { | |
643 | case RTM_IEEE80211_ASSOC: | |
644 | case RTM_IEEE80211_REASSOC: | |
645 | case RTM_IEEE80211_DISASSOC: | |
646 | case RTM_IEEE80211_SCAN: | |
647 | break; | |
648 | case RTM_IEEE80211_LEAVE: | |
649 | leave = (struct ieee80211_leave_event *) &ifan[1]; | |
650 | hostapd_notif_disassoc(drv->hapd, leave->iev_addr); | |
651 | break; | |
652 | case RTM_IEEE80211_JOIN: | |
653 | #ifdef RTM_IEEE80211_REJOIN | |
654 | case RTM_IEEE80211_REJOIN: | |
655 | #endif | |
656 | join = (struct ieee80211_join_event *) &ifan[1]; | |
657 | bsd_new_sta(drv, join->iev_addr); | |
658 | break; | |
659 | case RTM_IEEE80211_REPLAY: | |
660 | /* ignore */ | |
661 | break; | |
662 | case RTM_IEEE80211_MICHAEL: | |
663 | mic = (struct ieee80211_michael_event *) &ifan[1]; | |
664 | wpa_printf(MSG_DEBUG, | |
665 | "Michael MIC failure wireless event: " | |
666 | "keyix=%u src_addr=" MACSTR, mic->iev_keyix, | |
667 | MAC2STR(mic->iev_src)); | |
668 | hostapd_michael_mic_failure(hapd, mic->iev_src); | |
669 | break; | |
670 | } | |
671 | break; | |
672 | } | |
673 | } | |
674 | ||
675 | static int | |
676 | bsd_wireless_event_init(struct bsd_driver_data *drv) | |
677 | { | |
678 | int s; | |
679 | ||
680 | drv->wext_sock = -1; | |
681 | ||
682 | s = socket(PF_ROUTE, SOCK_RAW, 0); | |
683 | if (s < 0) { | |
684 | perror("socket(PF_ROUTE,SOCK_RAW)"); | |
685 | return -1; | |
686 | } | |
687 | eloop_register_read_sock(s, bsd_wireless_event_receive, drv, NULL); | |
688 | drv->wext_sock = s; | |
689 | ||
690 | return 0; | |
691 | } | |
692 | ||
693 | static void | |
694 | bsd_wireless_event_deinit(struct bsd_driver_data *drv) | |
695 | { | |
696 | if (drv->wext_sock < 0) | |
697 | return; | |
698 | eloop_unregister_read_sock(drv->wext_sock); | |
699 | close(drv->wext_sock); | |
700 | } | |
701 | ||
702 | ||
703 | static int | |
704 | bsd_send_eapol(void *priv, const u8 *addr, const u8 *data, size_t data_len, | |
705 | int encrypt, const u8 *own_addr) | |
706 | { | |
707 | struct bsd_driver_data *drv = priv; | |
708 | unsigned char buf[3000]; | |
709 | unsigned char *bp = buf; | |
710 | struct l2_ethhdr *eth; | |
711 | size_t len; | |
712 | int status; | |
713 | ||
714 | /* | |
715 | * Prepend the Etherent header. If the caller left us | |
716 | * space at the front we could just insert it but since | |
717 | * we don't know we copy to a local buffer. Given the frequency | |
718 | * and size of frames this probably doesn't matter. | |
719 | */ | |
720 | len = data_len + sizeof(struct l2_ethhdr); | |
721 | if (len > sizeof(buf)) { | |
722 | bp = malloc(len); | |
723 | if (bp == NULL) { | |
724 | printf("EAPOL frame discarded, cannot malloc temp " | |
92e63aaf | 725 | "buffer of size %u!\n", (unsigned int) len); |
c5121837 JM |
726 | return -1; |
727 | } | |
728 | } | |
729 | eth = (struct l2_ethhdr *) bp; | |
730 | memcpy(eth->h_dest, addr, ETH_ALEN); | |
731 | memcpy(eth->h_source, own_addr, ETH_ALEN); | |
732 | eth->h_proto = htons(ETH_P_EAPOL); | |
733 | memcpy(eth+1, data, data_len); | |
734 | ||
735 | wpa_hexdump(MSG_MSGDUMP, "TX EAPOL", bp, len); | |
736 | ||
737 | status = l2_packet_send(drv->sock_xmit, addr, ETH_P_EAPOL, bp, len); | |
738 | ||
739 | if (bp != buf) | |
740 | free(bp); | |
741 | return status; | |
742 | } | |
743 | ||
744 | static void | |
745 | handle_read(void *ctx, const u8 *src_addr, const u8 *buf, size_t len) | |
746 | { | |
747 | struct bsd_driver_data *drv = ctx; | |
748 | hostapd_eapol_receive(drv->hapd, src_addr, | |
749 | buf + sizeof(struct l2_ethhdr), | |
750 | len - sizeof(struct l2_ethhdr)); | |
751 | } | |
752 | ||
753 | static int | |
66d4085f | 754 | hostapd_bsd_get_ssid(const char *ifname, void *priv, u8 *buf, int len) |
c5121837 JM |
755 | { |
756 | struct bsd_driver_data *drv = priv; | |
66d4085f | 757 | int ssid_len; |
c5121837 | 758 | |
66d4085f | 759 | ssid_len = bsd_get_ssid(drv->ioctl_sock, drv->iface, buf); |
c5121837 JM |
760 | wpa_printf(MSG_DEBUG, "%s: ssid=\"%.*s\"", __func__, ssid_len, buf); |
761 | ||
762 | return ssid_len; | |
763 | } | |
764 | ||
765 | static int | |
66d4085f | 766 | hostapd_bsd_set_ssid(const char *ifname, void *priv, const u8 *buf, int len) |
c5121837 JM |
767 | { |
768 | struct bsd_driver_data *drv = priv; | |
769 | ||
770 | wpa_printf(MSG_DEBUG, "%s: ssid=\"%.*s\"", __func__, len, buf); | |
771 | ||
66d4085f | 772 | return bsd_set_ssid(drv->ioctl_sock, drv->iface, buf, len); |
c5121837 JM |
773 | } |
774 | ||
775 | static void * | |
92f475b4 | 776 | bsd_init(struct hostapd_data *hapd, struct wpa_init_params *params) |
c5121837 JM |
777 | { |
778 | struct bsd_driver_data *drv; | |
779 | ||
780 | drv = os_zalloc(sizeof(struct bsd_driver_data)); | |
781 | if (drv == NULL) { | |
782 | printf("Could not allocate memory for bsd driver data\n"); | |
783 | goto bad; | |
784 | } | |
785 | ||
786 | drv->hapd = hapd; | |
787 | drv->ioctl_sock = socket(PF_INET, SOCK_DGRAM, 0); | |
788 | if (drv->ioctl_sock < 0) { | |
789 | perror("socket[PF_INET,SOCK_DGRAM]"); | |
790 | goto bad; | |
791 | } | |
412036f5 | 792 | memcpy(drv->iface, params->ifname, sizeof(drv->iface)); |
c5121837 JM |
793 | |
794 | drv->sock_xmit = l2_packet_init(drv->iface, NULL, ETH_P_EAPOL, | |
795 | handle_read, drv, 1); | |
796 | if (drv->sock_xmit == NULL) | |
797 | goto bad; | |
412036f5 | 798 | if (l2_packet_get_own_addr(drv->sock_xmit, params->own_addr)) |
c5121837 JM |
799 | goto bad; |
800 | ||
801 | bsd_set_iface_flags(drv, 0); /* mark down during setup */ | |
802 | if (bsd_wireless_event_init(drv)) | |
803 | goto bad; | |
804 | ||
805 | return drv; | |
806 | bad: | |
807 | if (drv->sock_xmit != NULL) | |
808 | l2_packet_deinit(drv->sock_xmit); | |
809 | if (drv->ioctl_sock >= 0) | |
810 | close(drv->ioctl_sock); | |
811 | if (drv != NULL) | |
812 | free(drv); | |
813 | return NULL; | |
814 | } | |
815 | ||
816 | ||
817 | static void | |
818 | bsd_deinit(void *priv) | |
819 | { | |
820 | struct bsd_driver_data *drv = priv; | |
821 | ||
822 | bsd_wireless_event_deinit(drv); | |
823 | (void) bsd_set_iface_flags(drv, 0); | |
824 | if (drv->ioctl_sock >= 0) | |
825 | close(drv->ioctl_sock); | |
826 | if (drv->sock_xmit != NULL) | |
827 | l2_packet_deinit(drv->sock_xmit); | |
828 | free(drv); | |
829 | } | |
830 | ||
831 | const struct wpa_driver_ops wpa_driver_bsd_ops = { | |
832 | .name = "bsd", | |
833 | .hapd_init = bsd_init, | |
834 | .hapd_deinit = bsd_deinit, | |
835 | .set_ieee8021x = bsd_set_ieee8021x, | |
836 | .set_privacy = bsd_set_privacy, | |
837 | .hapd_set_key = bsd_set_key, | |
838 | .get_seqnum = bsd_get_seqnum, | |
839 | .flush = bsd_flush, | |
840 | .set_generic_elem = bsd_set_opt_ie, | |
841 | .sta_set_flags = bsd_sta_set_flags, | |
842 | .read_sta_data = bsd_read_sta_driver_data, | |
843 | .hapd_send_eapol = bsd_send_eapol, | |
844 | .sta_disassoc = bsd_sta_disassoc, | |
845 | .sta_deauth = bsd_sta_deauth, | |
66d4085f RM |
846 | .hapd_set_ssid = hostapd_bsd_set_ssid, |
847 | .hapd_get_ssid = hostapd_bsd_get_ssid, | |
c5121837 JM |
848 | }; |
849 | ||
850 | #else /* HOSTAPD */ | |
851 | ||
6fc6879b JM |
852 | struct wpa_driver_bsd_data { |
853 | int sock; /* open socket for 802.11 ioctls */ | |
854 | int route; /* routing socket for events */ | |
855 | char ifname[IFNAMSIZ+1]; /* interface name */ | |
856 | unsigned int ifindex; /* interface index */ | |
857 | void *ctx; | |
858 | int prev_roaming; /* roaming state to restore on deinit */ | |
859 | int prev_privacy; /* privacy state to restore on deinit */ | |
860 | int prev_wpa; /* wpa state to restore on deinit */ | |
861 | }; | |
862 | ||
863 | static int | |
864 | set80211var(struct wpa_driver_bsd_data *drv, int op, const void *arg, int arg_len) | |
865 | { | |
66d4085f | 866 | return bsd_set80211var(drv->sock, drv->ifname, op, arg, arg_len); |
6fc6879b JM |
867 | } |
868 | ||
869 | static int | |
870 | get80211var(struct wpa_driver_bsd_data *drv, int op, void *arg, int arg_len) | |
871 | { | |
66d4085f | 872 | return bsd_get80211var(drv->sock, drv->ifname, op, arg, arg_len); |
6fc6879b JM |
873 | } |
874 | ||
875 | static int | |
876 | set80211param(struct wpa_driver_bsd_data *drv, int op, int arg) | |
877 | { | |
66d4085f | 878 | return bsd_set80211param(drv->sock, drv->ifname, op, arg); |
6fc6879b JM |
879 | } |
880 | ||
881 | static int | |
882 | get80211param(struct wpa_driver_bsd_data *drv, int op) | |
883 | { | |
884 | struct ieee80211req ireq; | |
885 | ||
886 | os_memset(&ireq, 0, sizeof(ireq)); | |
66d4085f | 887 | os_strlcpy(ireq.i_name, drv->ifname, sizeof(ireq.i_name)); |
6fc6879b JM |
888 | ireq.i_type = op; |
889 | ||
890 | if (ioctl(drv->sock, SIOCG80211, &ireq) < 0) { | |
891 | fprintf(stderr, "ioctl[SIOCG80211, op %u]: %s\n", | |
892 | op, strerror(errno)); | |
893 | return -1; | |
894 | } | |
895 | return ireq.i_val; | |
896 | } | |
897 | ||
898 | static int | |
899 | getifflags(struct wpa_driver_bsd_data *drv, int *flags) | |
900 | { | |
901 | struct ifreq ifr; | |
902 | ||
903 | os_memset(&ifr, 0, sizeof(ifr)); | |
904 | os_strlcpy(ifr.ifr_name, drv->ifname, sizeof(ifr.ifr_name)); | |
905 | if (ioctl(drv->sock, SIOCGIFFLAGS, (caddr_t)&ifr) < 0) { | |
906 | perror("SIOCGIFFLAGS"); | |
907 | return errno; | |
908 | } | |
909 | *flags = ifr.ifr_flags & 0xffff; | |
910 | return 0; | |
911 | } | |
912 | ||
913 | static int | |
914 | setifflags(struct wpa_driver_bsd_data *drv, int flags) | |
915 | { | |
916 | struct ifreq ifr; | |
917 | ||
918 | os_memset(&ifr, 0, sizeof(ifr)); | |
919 | os_strlcpy(ifr.ifr_name, drv->ifname, sizeof(ifr.ifr_name)); | |
920 | ifr.ifr_flags = flags & 0xffff; | |
921 | if (ioctl(drv->sock, SIOCSIFFLAGS, (caddr_t)&ifr) < 0) { | |
922 | perror("SIOCSIFFLAGS"); | |
923 | return errno; | |
924 | } | |
925 | return 0; | |
926 | } | |
927 | ||
928 | static int | |
929 | wpa_driver_bsd_get_bssid(void *priv, u8 *bssid) | |
930 | { | |
931 | struct wpa_driver_bsd_data *drv = priv; | |
66d4085f | 932 | #ifdef SIOCG80211BSSID |
a65f4a57 | 933 | struct ieee80211_bssid bs; |
6fc6879b | 934 | |
a65f4a57 MH |
935 | os_strncpy(bs.i_name, drv->ifname, sizeof(bs.i_name)); |
936 | if (ioctl(drv->sock, SIOCG80211BSSID, &bs) < 0) | |
937 | return -1; | |
938 | os_memcpy(bssid, bs.i_bssid, sizeof(bs.i_bssid)); | |
939 | return 0; | |
940 | #else | |
6fc6879b JM |
941 | return get80211var(drv, IEEE80211_IOC_BSSID, |
942 | bssid, IEEE80211_ADDR_LEN) < 0 ? -1 : 0; | |
a65f4a57 | 943 | #endif |
6fc6879b JM |
944 | } |
945 | ||
946 | #if 0 | |
947 | static int | |
948 | wpa_driver_bsd_set_bssid(void *priv, const char *bssid) | |
949 | { | |
950 | struct wpa_driver_bsd_data *drv = priv; | |
951 | ||
952 | return set80211var(drv, IEEE80211_IOC_BSSID, | |
953 | bssid, IEEE80211_ADDR_LEN); | |
954 | } | |
955 | #endif | |
956 | ||
957 | static int | |
958 | wpa_driver_bsd_get_ssid(void *priv, u8 *ssid) | |
959 | { | |
960 | struct wpa_driver_bsd_data *drv = priv; | |
961 | ||
66d4085f | 962 | return bsd_get_ssid(drv->sock, drv->ifname, ssid); |
6fc6879b JM |
963 | } |
964 | ||
965 | static int | |
4df91b3f | 966 | wpa_driver_bsd_set_ssid(void *priv, const u8 *ssid, |
6fc6879b JM |
967 | size_t ssid_len) |
968 | { | |
969 | struct wpa_driver_bsd_data *drv = priv; | |
970 | ||
66d4085f | 971 | return bsd_set_ssid(drv->sock, drv->ifname, ssid, ssid_len); |
6fc6879b JM |
972 | } |
973 | ||
974 | static int | |
975 | wpa_driver_bsd_set_wpa_ie(struct wpa_driver_bsd_data *drv, | |
4df91b3f | 976 | const u8 *wpa_ie, size_t wpa_ie_len) |
6fc6879b JM |
977 | { |
978 | return set80211var(drv, IEEE80211_IOC_OPTIE, wpa_ie, wpa_ie_len); | |
979 | } | |
980 | ||
981 | static int | |
982 | wpa_driver_bsd_set_wpa_internal(void *priv, int wpa, int privacy) | |
983 | { | |
984 | struct wpa_driver_bsd_data *drv = priv; | |
985 | int ret = 0; | |
986 | ||
987 | wpa_printf(MSG_DEBUG, "%s: wpa=%d privacy=%d", | |
988 | __FUNCTION__, wpa, privacy); | |
989 | ||
990 | if (!wpa && wpa_driver_bsd_set_wpa_ie(drv, NULL, 0) < 0) | |
991 | ret = -1; | |
992 | if (set80211param(drv, IEEE80211_IOC_PRIVACY, privacy) < 0) | |
993 | ret = -1; | |
994 | if (set80211param(drv, IEEE80211_IOC_WPA, wpa) < 0) | |
995 | ret = -1; | |
996 | ||
997 | return ret; | |
998 | } | |
999 | ||
1000 | static int | |
1001 | wpa_driver_bsd_set_wpa(void *priv, int enabled) | |
1002 | { | |
1003 | wpa_printf(MSG_DEBUG, "%s: enabled=%d", __FUNCTION__, enabled); | |
1004 | ||
1005 | return wpa_driver_bsd_set_wpa_internal(priv, enabled ? 3 : 0, enabled); | |
1006 | } | |
1007 | ||
1008 | static int | |
1009 | wpa_driver_bsd_del_key(struct wpa_driver_bsd_data *drv, int key_idx, | |
1010 | const unsigned char *addr) | |
1011 | { | |
1012 | struct ieee80211req_del_key wk; | |
1013 | ||
1014 | os_memset(&wk, 0, sizeof(wk)); | |
1015 | if (addr != NULL && | |
1016 | bcmp(addr, "\xff\xff\xff\xff\xff\xff", IEEE80211_ADDR_LEN) != 0) { | |
1017 | struct ether_addr ea; | |
1018 | ||
1019 | os_memcpy(&ea, addr, IEEE80211_ADDR_LEN); | |
1020 | wpa_printf(MSG_DEBUG, "%s: addr=%s keyidx=%d", | |
1021 | __func__, ether_ntoa(&ea), key_idx); | |
1022 | os_memcpy(wk.idk_macaddr, addr, IEEE80211_ADDR_LEN); | |
1023 | wk.idk_keyix = (uint8_t) IEEE80211_KEYIX_NONE; | |
1024 | } else { | |
1025 | wpa_printf(MSG_DEBUG, "%s: keyidx=%d", __func__, key_idx); | |
1026 | wk.idk_keyix = key_idx; | |
1027 | } | |
1028 | return set80211var(drv, IEEE80211_IOC_DELKEY, &wk, sizeof(wk)); | |
1029 | } | |
1030 | ||
1031 | static int | |
1032 | wpa_driver_bsd_set_key(void *priv, wpa_alg alg, | |
1033 | const unsigned char *addr, int key_idx, int set_tx, | |
1034 | const u8 *seq, size_t seq_len, | |
1035 | const u8 *key, size_t key_len) | |
1036 | { | |
1037 | struct wpa_driver_bsd_data *drv = priv; | |
1038 | struct ieee80211req_key wk; | |
1039 | struct ether_addr ea; | |
1040 | char *alg_name; | |
1041 | u_int8_t cipher; | |
1042 | ||
1043 | if (alg == WPA_ALG_NONE) | |
1044 | return wpa_driver_bsd_del_key(drv, key_idx, addr); | |
1045 | ||
1046 | switch (alg) { | |
1047 | case WPA_ALG_WEP: | |
1048 | alg_name = "WEP"; | |
1049 | cipher = IEEE80211_CIPHER_WEP; | |
1050 | break; | |
1051 | case WPA_ALG_TKIP: | |
1052 | alg_name = "TKIP"; | |
1053 | cipher = IEEE80211_CIPHER_TKIP; | |
1054 | break; | |
1055 | case WPA_ALG_CCMP: | |
1056 | alg_name = "CCMP"; | |
1057 | cipher = IEEE80211_CIPHER_AES_CCM; | |
1058 | break; | |
1059 | default: | |
1060 | wpa_printf(MSG_DEBUG, "%s: unknown/unsupported algorithm %d", | |
1061 | __func__, alg); | |
1062 | return -1; | |
1063 | } | |
1064 | ||
1065 | os_memcpy(&ea, addr, IEEE80211_ADDR_LEN); | |
1066 | wpa_printf(MSG_DEBUG, | |
1067 | "%s: alg=%s addr=%s key_idx=%d set_tx=%d seq_len=%zu key_len=%zu", | |
1068 | __func__, alg_name, ether_ntoa(&ea), key_idx, set_tx, | |
1069 | seq_len, key_len); | |
1070 | ||
1071 | if (seq_len > sizeof(u_int64_t)) { | |
1072 | wpa_printf(MSG_DEBUG, "%s: seq_len %zu too big", | |
1073 | __func__, seq_len); | |
1074 | return -2; | |
1075 | } | |
1076 | if (key_len > sizeof(wk.ik_keydata)) { | |
1077 | wpa_printf(MSG_DEBUG, "%s: key length %zu too big", | |
1078 | __func__, key_len); | |
1079 | return -3; | |
1080 | } | |
1081 | ||
1082 | os_memset(&wk, 0, sizeof(wk)); | |
1083 | wk.ik_type = cipher; | |
1084 | wk.ik_flags = IEEE80211_KEY_RECV; | |
1085 | if (set_tx) | |
1086 | wk.ik_flags |= IEEE80211_KEY_XMIT; | |
1087 | os_memcpy(wk.ik_macaddr, addr, IEEE80211_ADDR_LEN); | |
1088 | /* | |
1089 | * Deduce whether group/global or unicast key by checking | |
1090 | * the address (yech). Note also that we can only mark global | |
1091 | * keys default; doing this for a unicast key is an error. | |
1092 | */ | |
1093 | if (bcmp(addr, "\xff\xff\xff\xff\xff\xff", IEEE80211_ADDR_LEN) == 0) { | |
1094 | wk.ik_flags |= IEEE80211_KEY_GROUP; | |
1095 | wk.ik_keyix = key_idx; | |
1096 | } else { | |
1097 | wk.ik_keyix = (key_idx == 0 ? IEEE80211_KEYIX_NONE : key_idx); | |
1098 | } | |
1099 | if (wk.ik_keyix != IEEE80211_KEYIX_NONE && set_tx) | |
1100 | wk.ik_flags |= IEEE80211_KEY_DEFAULT; | |
1101 | wk.ik_keylen = key_len; | |
1102 | os_memcpy(&wk.ik_keyrsc, seq, seq_len); | |
1103 | os_memcpy(wk.ik_keydata, key, key_len); | |
1104 | ||
1105 | return set80211var(drv, IEEE80211_IOC_WPAKEY, &wk, sizeof(wk)); | |
1106 | } | |
1107 | ||
1108 | static int | |
1109 | wpa_driver_bsd_set_countermeasures(void *priv, int enabled) | |
1110 | { | |
1111 | struct wpa_driver_bsd_data *drv = priv; | |
1112 | ||
1113 | wpa_printf(MSG_DEBUG, "%s: enabled=%d", __func__, enabled); | |
1114 | return set80211param(drv, IEEE80211_IOC_COUNTERMEASURES, enabled); | |
1115 | } | |
1116 | ||
1117 | ||
1118 | static int | |
1119 | wpa_driver_bsd_set_drop_unencrypted(void *priv, int enabled) | |
1120 | { | |
1121 | struct wpa_driver_bsd_data *drv = priv; | |
1122 | ||
1123 | wpa_printf(MSG_DEBUG, "%s: enabled=%d", __func__, enabled); | |
1124 | return set80211param(drv, IEEE80211_IOC_DROPUNENCRYPTED, enabled); | |
1125 | } | |
1126 | ||
1127 | static int | |
1128 | wpa_driver_bsd_deauthenticate(void *priv, const u8 *addr, int reason_code) | |
1129 | { | |
1130 | struct wpa_driver_bsd_data *drv = priv; | |
1131 | struct ieee80211req_mlme mlme; | |
1132 | ||
1133 | wpa_printf(MSG_DEBUG, "%s", __func__); | |
1134 | os_memset(&mlme, 0, sizeof(mlme)); | |
1135 | mlme.im_op = IEEE80211_MLME_DEAUTH; | |
1136 | mlme.im_reason = reason_code; | |
1137 | os_memcpy(mlme.im_macaddr, addr, IEEE80211_ADDR_LEN); | |
1138 | return set80211var(drv, IEEE80211_IOC_MLME, &mlme, sizeof(mlme)); | |
1139 | } | |
1140 | ||
1141 | static int | |
1142 | wpa_driver_bsd_disassociate(void *priv, const u8 *addr, int reason_code) | |
1143 | { | |
1144 | struct wpa_driver_bsd_data *drv = priv; | |
1145 | struct ieee80211req_mlme mlme; | |
1146 | ||
1147 | wpa_printf(MSG_DEBUG, "%s", __func__); | |
1148 | os_memset(&mlme, 0, sizeof(mlme)); | |
1149 | mlme.im_op = IEEE80211_MLME_DISASSOC; | |
1150 | mlme.im_reason = reason_code; | |
1151 | os_memcpy(mlme.im_macaddr, addr, IEEE80211_ADDR_LEN); | |
1152 | return set80211var(drv, IEEE80211_IOC_MLME, &mlme, sizeof(mlme)); | |
1153 | } | |
1154 | ||
1155 | static int | |
1156 | wpa_driver_bsd_associate(void *priv, struct wpa_driver_associate_params *params) | |
1157 | { | |
1158 | struct wpa_driver_bsd_data *drv = priv; | |
1159 | struct ieee80211req_mlme mlme; | |
1160 | int privacy; | |
1161 | ||
1162 | wpa_printf(MSG_DEBUG, | |
1163 | "%s: ssid '%.*s' wpa ie len %u pairwise %u group %u key mgmt %u" | |
1164 | , __func__ | |
92e63aaf JM |
1165 | , (unsigned int) params->ssid_len, params->ssid |
1166 | , (unsigned int) params->wpa_ie_len | |
6fc6879b JM |
1167 | , params->pairwise_suite |
1168 | , params->group_suite | |
1169 | , params->key_mgmt_suite | |
1170 | ); | |
1171 | ||
1172 | /* XXX error handling is wrong but unclear what to do... */ | |
1173 | if (wpa_driver_bsd_set_wpa_ie(drv, params->wpa_ie, params->wpa_ie_len) < 0) | |
1174 | return -1; | |
6fc6879b JM |
1175 | |
1176 | privacy = !(params->pairwise_suite == CIPHER_NONE && | |
1177 | params->group_suite == CIPHER_NONE && | |
1178 | params->key_mgmt_suite == KEY_MGMT_NONE && | |
1179 | params->wpa_ie_len == 0); | |
1180 | wpa_printf(MSG_DEBUG, "%s: set PRIVACY %u", __func__, privacy); | |
1181 | ||
1182 | if (set80211param(drv, IEEE80211_IOC_PRIVACY, privacy) < 0) | |
1183 | return -1; | |
1184 | ||
1185 | if (params->wpa_ie_len && | |
1186 | set80211param(drv, IEEE80211_IOC_WPA, | |
1187 | params->wpa_ie[0] == WLAN_EID_RSN ? 2 : 1) < 0) | |
1188 | return -1; | |
1189 | ||
1190 | os_memset(&mlme, 0, sizeof(mlme)); | |
1191 | mlme.im_op = IEEE80211_MLME_ASSOC; | |
6fc6879b JM |
1192 | if (params->ssid != NULL) |
1193 | os_memcpy(mlme.im_ssid, params->ssid, params->ssid_len); | |
1194 | mlme.im_ssid_len = params->ssid_len; | |
6fc6879b JM |
1195 | if (params->bssid != NULL) |
1196 | os_memcpy(mlme.im_macaddr, params->bssid, IEEE80211_ADDR_LEN); | |
1197 | if (set80211var(drv, IEEE80211_IOC_MLME, &mlme, sizeof(mlme)) < 0) | |
1198 | return -1; | |
1199 | return 0; | |
1200 | } | |
1201 | ||
1202 | static int | |
1203 | wpa_driver_bsd_set_auth_alg(void *priv, int auth_alg) | |
1204 | { | |
1205 | struct wpa_driver_bsd_data *drv = priv; | |
1206 | int authmode; | |
1207 | ||
1208 | if ((auth_alg & AUTH_ALG_OPEN_SYSTEM) && | |
1209 | (auth_alg & AUTH_ALG_SHARED_KEY)) | |
1210 | authmode = IEEE80211_AUTH_AUTO; | |
1211 | else if (auth_alg & AUTH_ALG_SHARED_KEY) | |
1212 | authmode = IEEE80211_AUTH_SHARED; | |
1213 | else | |
1214 | authmode = IEEE80211_AUTH_OPEN; | |
1215 | ||
1216 | return set80211param(drv, IEEE80211_IOC_AUTHMODE, authmode); | |
1217 | } | |
1218 | ||
1219 | static int | |
1220 | wpa_driver_bsd_scan(void *priv, const u8 *ssid, size_t ssid_len) | |
1221 | { | |
1222 | struct wpa_driver_bsd_data *drv = priv; | |
1223 | int flags; | |
1224 | ||
1225 | /* NB: interface must be marked UP to do a scan */ | |
1226 | if (getifflags(drv, &flags) != 0 || setifflags(drv, flags | IFF_UP) != 0) | |
1227 | return -1; | |
1228 | ||
1229 | /* set desired ssid before scan */ | |
1230 | if (wpa_driver_bsd_set_ssid(drv, ssid, ssid_len) < 0) | |
1231 | return -1; | |
1232 | ||
1233 | /* NB: net80211 delivers a scan complete event so no need to poll */ | |
1234 | return set80211param(drv, IEEE80211_IOC_SCAN_REQ, 0); | |
1235 | } | |
1236 | ||
6fc6879b JM |
1237 | static void |
1238 | wpa_driver_bsd_event_receive(int sock, void *ctx, void *sock_ctx) | |
1239 | { | |
1240 | struct wpa_driver_bsd_data *drv = sock_ctx; | |
1241 | char buf[2048]; | |
1242 | struct if_announcemsghdr *ifan; | |
1243 | struct if_msghdr *ifm; | |
1244 | struct rt_msghdr *rtm; | |
1245 | union wpa_event_data event; | |
1246 | struct ieee80211_michael_event *mic; | |
1247 | int n; | |
1248 | ||
1249 | n = read(sock, buf, sizeof(buf)); | |
1250 | if (n < 0) { | |
1251 | if (errno != EINTR && errno != EAGAIN) | |
1252 | perror("read(PF_ROUTE)"); | |
1253 | return; | |
1254 | } | |
1255 | ||
1256 | rtm = (struct rt_msghdr *) buf; | |
1257 | if (rtm->rtm_version != RTM_VERSION) { | |
1258 | wpa_printf(MSG_DEBUG, "Routing message version %d not " | |
1259 | "understood\n", rtm->rtm_version); | |
1260 | return; | |
1261 | } | |
1262 | os_memset(&event, 0, sizeof(event)); | |
1263 | switch (rtm->rtm_type) { | |
1264 | case RTM_IFANNOUNCE: | |
1265 | ifan = (struct if_announcemsghdr *) rtm; | |
1266 | if (ifan->ifan_index != drv->ifindex) | |
1267 | break; | |
1268 | strlcpy(event.interface_status.ifname, drv->ifname, | |
1269 | sizeof(event.interface_status.ifname)); | |
1270 | switch (ifan->ifan_what) { | |
1271 | case IFAN_DEPARTURE: | |
1272 | event.interface_status.ievent = EVENT_INTERFACE_REMOVED; | |
1273 | default: | |
1274 | return; | |
1275 | } | |
1276 | wpa_printf(MSG_DEBUG, "RTM_IFANNOUNCE: Interface '%s' %s", | |
1277 | event.interface_status.ifname, | |
1278 | ifan->ifan_what == IFAN_DEPARTURE ? | |
1279 | "removed" : "added"); | |
1280 | wpa_supplicant_event(ctx, EVENT_INTERFACE_STATUS, &event); | |
1281 | break; | |
1282 | case RTM_IEEE80211: | |
1283 | ifan = (struct if_announcemsghdr *) rtm; | |
1284 | if (ifan->ifan_index != drv->ifindex) | |
1285 | break; | |
1286 | switch (ifan->ifan_what) { | |
1287 | case RTM_IEEE80211_ASSOC: | |
1288 | case RTM_IEEE80211_REASSOC: | |
1289 | wpa_supplicant_event(ctx, EVENT_ASSOC, NULL); | |
1290 | break; | |
1291 | case RTM_IEEE80211_DISASSOC: | |
1292 | wpa_supplicant_event(ctx, EVENT_DISASSOC, NULL); | |
1293 | break; | |
1294 | case RTM_IEEE80211_SCAN: | |
1295 | wpa_supplicant_event(ctx, EVENT_SCAN_RESULTS, NULL); | |
1296 | break; | |
1297 | case RTM_IEEE80211_REPLAY: | |
1298 | /* ignore */ | |
1299 | break; | |
1300 | case RTM_IEEE80211_MICHAEL: | |
1301 | mic = (struct ieee80211_michael_event *) &ifan[1]; | |
1302 | wpa_printf(MSG_DEBUG, | |
1303 | "Michael MIC failure wireless event: " | |
1304 | "keyix=%u src_addr=" MACSTR, mic->iev_keyix, | |
1305 | MAC2STR(mic->iev_src)); | |
1306 | ||
1307 | os_memset(&event, 0, sizeof(event)); | |
1308 | event.michael_mic_failure.unicast = | |
1309 | !IEEE80211_IS_MULTICAST(mic->iev_dst); | |
1310 | wpa_supplicant_event(ctx, EVENT_MICHAEL_MIC_FAILURE, | |
1311 | &event); | |
1312 | break; | |
1313 | } | |
1314 | break; | |
1315 | case RTM_IFINFO: | |
1316 | ifm = (struct if_msghdr *) rtm; | |
1317 | if (ifm->ifm_index != drv->ifindex) | |
1318 | break; | |
1319 | if ((rtm->rtm_flags & RTF_UP) == 0) { | |
1320 | strlcpy(event.interface_status.ifname, drv->ifname, | |
1321 | sizeof(event.interface_status.ifname)); | |
1322 | event.interface_status.ievent = EVENT_INTERFACE_REMOVED; | |
1323 | wpa_printf(MSG_DEBUG, "RTM_IFINFO: Interface '%s' DOWN", | |
1324 | event.interface_status.ifname); | |
1325 | wpa_supplicant_event(ctx, EVENT_INTERFACE_STATUS, &event); | |
1326 | } | |
1327 | break; | |
1328 | } | |
1329 | } | |
1330 | ||
a65f4a57 MH |
1331 | static void |
1332 | wpa_driver_bsd_add_scan_entry(struct wpa_scan_results *res, | |
1333 | struct ieee80211req_scan_result *sr) | |
6fc6879b | 1334 | { |
a65f4a57 MH |
1335 | struct wpa_scan_res *result, **tmp; |
1336 | size_t extra_len; | |
1337 | u8 *pos; | |
6fc6879b | 1338 | |
a65f4a57 MH |
1339 | extra_len = 2 + sr->isr_ssid_len; |
1340 | extra_len += 2 + sr->isr_nrates; | |
1341 | extra_len += 3; /* ERP IE */ | |
1342 | extra_len += sr->isr_ie_len; | |
6fc6879b | 1343 | |
a65f4a57 MH |
1344 | result = os_zalloc(sizeof(*result) + extra_len); |
1345 | if (result == NULL) | |
1346 | return; | |
1347 | os_memcpy(result->bssid, sr->isr_bssid, ETH_ALEN); | |
1348 | result->freq = sr->isr_freq; | |
1349 | result->beacon_int = sr->isr_intval; | |
1350 | result->caps = sr->isr_capinfo; | |
1351 | result->qual = sr->isr_rssi; | |
1352 | result->noise = sr->isr_noise; | |
6fc6879b | 1353 | |
a65f4a57 | 1354 | pos = (u8 *)(result + 1); |
6fc6879b | 1355 | |
a65f4a57 MH |
1356 | *pos++ = WLAN_EID_SSID; |
1357 | *pos++ = sr->isr_ssid_len; | |
1358 | os_memcpy(pos, sr + 1, sr->isr_ssid_len); | |
1359 | pos += sr->isr_ssid_len; | |
6fc6879b | 1360 | |
a65f4a57 MH |
1361 | /* |
1362 | * Deal all rates as supported rate. | |
1363 | * Because net80211 doesn't report extended supported rate or not. | |
1364 | */ | |
1365 | *pos++ = WLAN_EID_SUPP_RATES; | |
1366 | *pos++ = sr->isr_nrates; | |
1367 | os_memcpy(pos, sr->isr_rates, sr->isr_nrates); | |
1368 | pos += sr->isr_nrates; | |
6fc6879b | 1369 | |
a65f4a57 MH |
1370 | *pos++ = WLAN_EID_ERP_INFO; |
1371 | *pos++ = 1; | |
1372 | *pos++ = sr->isr_erp; | |
6fc6879b | 1373 | |
a65f4a57 MH |
1374 | os_memcpy(pos, (u8 *)(sr + 1) + sr->isr_ssid_len, sr->isr_ie_len); |
1375 | pos += sr->isr_ie_len; | |
6fc6879b | 1376 | |
a65f4a57 MH |
1377 | result->ie_len = pos - (u8 *)(result + 1); |
1378 | ||
1379 | tmp = os_realloc(res->res, | |
1380 | (res->num + 1) * sizeof(struct wpa_scan_res *)); | |
1381 | if (tmp == NULL) { | |
1382 | os_free(result); | |
1383 | return; | |
1384 | } | |
1385 | tmp[res->num++] = result; | |
1386 | res->res = tmp; | |
6fc6879b JM |
1387 | } |
1388 | ||
a65f4a57 MH |
1389 | struct wpa_scan_results * |
1390 | wpa_driver_bsd_get_scan_results2(void *priv) | |
6fc6879b | 1391 | { |
6fc6879b | 1392 | struct wpa_driver_bsd_data *drv = priv; |
6fc6879b | 1393 | struct ieee80211req_scan_result *sr; |
a65f4a57 MH |
1394 | struct wpa_scan_results *res; |
1395 | int len, rest; | |
1396 | uint8_t buf[24*1024], *pos; | |
6fc6879b | 1397 | |
a65f4a57 | 1398 | len = get80211var(drv, IEEE80211_IOC_SCAN_RESULTS, buf, 24*1024); |
6fc6879b | 1399 | if (len < 0) |
a65f4a57 MH |
1400 | return NULL; |
1401 | ||
1402 | res = os_zalloc(sizeof(*res)); | |
1403 | if (res == NULL) | |
1404 | return NULL; | |
6fc6879b | 1405 | |
a65f4a57 MH |
1406 | pos = buf; |
1407 | rest = len; | |
1408 | while (rest >= sizeof(struct ieee80211req_scan_result)) { | |
1409 | sr = (struct ieee80211req_scan_result *)pos; | |
1410 | wpa_driver_bsd_add_scan_entry(res, sr); | |
1411 | pos += sr->isr_len; | |
1412 | rest -= sr->isr_len; | |
6fc6879b | 1413 | } |
6fc6879b | 1414 | |
a65f4a57 MH |
1415 | wpa_printf(MSG_DEBUG, "Received %d bytes of scan results (%lu BSSes)", |
1416 | len, (unsigned long)res->num); | |
6fc6879b | 1417 | |
a65f4a57 | 1418 | return res; |
6fc6879b JM |
1419 | } |
1420 | ||
1421 | static void * | |
1422 | wpa_driver_bsd_init(void *ctx, const char *ifname) | |
1423 | { | |
1424 | #define GETPARAM(drv, param, v) \ | |
1425 | (((v) = get80211param(drv, param)) != -1) | |
1426 | struct wpa_driver_bsd_data *drv; | |
1427 | ||
1428 | drv = os_zalloc(sizeof(*drv)); | |
1429 | if (drv == NULL) | |
1430 | return NULL; | |
1431 | /* | |
1432 | * NB: We require the interface name be mappable to an index. | |
1433 | * This implies we do not support having wpa_supplicant | |
1434 | * wait for an interface to appear. This seems ok; that | |
1435 | * doesn't belong here; it's really the job of devd. | |
1436 | */ | |
1437 | drv->ifindex = if_nametoindex(ifname); | |
1438 | if (drv->ifindex == 0) { | |
1439 | wpa_printf(MSG_DEBUG, "%s: interface %s does not exist", | |
1440 | __func__, ifname); | |
1441 | goto fail1; | |
1442 | } | |
1443 | drv->sock = socket(PF_INET, SOCK_DGRAM, 0); | |
1444 | if (drv->sock < 0) | |
1445 | goto fail1; | |
1446 | drv->route = socket(PF_ROUTE, SOCK_RAW, 0); | |
1447 | if (drv->route < 0) | |
1448 | goto fail; | |
1449 | eloop_register_read_sock(drv->route, | |
1450 | wpa_driver_bsd_event_receive, ctx, drv); | |
1451 | ||
1452 | drv->ctx = ctx; | |
1453 | os_strlcpy(drv->ifname, ifname, sizeof(drv->ifname)); | |
1454 | ||
1455 | if (!GETPARAM(drv, IEEE80211_IOC_ROAMING, drv->prev_roaming)) { | |
1456 | wpa_printf(MSG_DEBUG, "%s: failed to get roaming state: %s", | |
1457 | __func__, strerror(errno)); | |
1458 | goto fail; | |
1459 | } | |
1460 | if (!GETPARAM(drv, IEEE80211_IOC_PRIVACY, drv->prev_privacy)) { | |
1461 | wpa_printf(MSG_DEBUG, "%s: failed to get privacy state: %s", | |
1462 | __func__, strerror(errno)); | |
1463 | goto fail; | |
1464 | } | |
1465 | if (!GETPARAM(drv, IEEE80211_IOC_WPA, drv->prev_wpa)) { | |
1466 | wpa_printf(MSG_DEBUG, "%s: failed to get wpa state: %s", | |
1467 | __func__, strerror(errno)); | |
1468 | goto fail; | |
1469 | } | |
1470 | if (set80211param(drv, IEEE80211_IOC_ROAMING, IEEE80211_ROAMING_MANUAL) < 0) { | |
1471 | wpa_printf(MSG_DEBUG, "%s: failed to set wpa_supplicant-based " | |
1472 | "roaming: %s", __func__, strerror(errno)); | |
1473 | goto fail; | |
1474 | } | |
1475 | ||
1476 | if (set80211param(drv, IEEE80211_IOC_WPA, 1+2) < 0) { | |
1477 | wpa_printf(MSG_DEBUG, "%s: failed to enable WPA support %s", | |
1478 | __func__, strerror(errno)); | |
1479 | goto fail; | |
1480 | } | |
1481 | ||
1482 | return drv; | |
1483 | fail: | |
1484 | close(drv->sock); | |
1485 | fail1: | |
1486 | os_free(drv); | |
1487 | return NULL; | |
1488 | #undef GETPARAM | |
1489 | } | |
1490 | ||
1491 | static void | |
1492 | wpa_driver_bsd_deinit(void *priv) | |
1493 | { | |
1494 | struct wpa_driver_bsd_data *drv = priv; | |
1495 | int flags; | |
1496 | ||
1497 | eloop_unregister_read_sock(drv->route); | |
1498 | ||
1499 | /* NB: mark interface down */ | |
1500 | if (getifflags(drv, &flags) == 0) | |
1501 | (void) setifflags(drv, flags &~ IFF_UP); | |
1502 | ||
1503 | wpa_driver_bsd_set_wpa_internal(drv, drv->prev_wpa, drv->prev_privacy); | |
1504 | if (set80211param(drv, IEEE80211_IOC_ROAMING, drv->prev_roaming) < 0) | |
1505 | wpa_printf(MSG_DEBUG, "%s: failed to restore roaming state", | |
1506 | __func__); | |
1507 | ||
1508 | (void) close(drv->route); /* ioctl socket */ | |
1509 | (void) close(drv->sock); /* event socket */ | |
1510 | os_free(drv); | |
1511 | } | |
1512 | ||
1513 | ||
1514 | const struct wpa_driver_ops wpa_driver_bsd_ops = { | |
1515 | .name = "bsd", | |
66d4085f | 1516 | .desc = "BSD 802.11 support", |
6fc6879b JM |
1517 | .init = wpa_driver_bsd_init, |
1518 | .deinit = wpa_driver_bsd_deinit, | |
1519 | .get_bssid = wpa_driver_bsd_get_bssid, | |
1520 | .get_ssid = wpa_driver_bsd_get_ssid, | |
1521 | .set_wpa = wpa_driver_bsd_set_wpa, | |
1522 | .set_key = wpa_driver_bsd_set_key, | |
1523 | .set_countermeasures = wpa_driver_bsd_set_countermeasures, | |
1524 | .set_drop_unencrypted = wpa_driver_bsd_set_drop_unencrypted, | |
1525 | .scan = wpa_driver_bsd_scan, | |
a65f4a57 | 1526 | .get_scan_results2 = wpa_driver_bsd_get_scan_results2, |
6fc6879b JM |
1527 | .deauthenticate = wpa_driver_bsd_deauthenticate, |
1528 | .disassociate = wpa_driver_bsd_disassociate, | |
1529 | .associate = wpa_driver_bsd_associate, | |
1530 | .set_auth_alg = wpa_driver_bsd_set_auth_alg, | |
1531 | }; | |
c5121837 JM |
1532 | |
1533 | #endif /* HOSTAPD */ |