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