2
* hostapd / Driver interaction with BSD net80211 layer
3
* Copyright (c) 2004, Sam Leffler <sam@errno.com>
4
* Copyright (c) 2004, 2Wire, Inc
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.
10
* Alternatively, this software may be distributed under the terms of BSD
13
* See README and COPYING for more details.
17
#include <sys/ioctl.h>
21
#include <net80211/ieee80211.h>
22
#include <net80211/ieee80211_crypto.h>
23
#include <net80211/ieee80211_ioctl.h>
27
#include "ieee802_1x.h"
30
#include "l2_packet.h"
35
#include "ieee802_11.h"
38
struct bsd_driver_data {
39
struct driver_ops ops; /* base class */
40
struct hostapd_data *hapd; /* back pointer */
42
char iface[IFNAMSIZ + 1];
43
struct l2_packet_data *sock_xmit; /* raw packet xmit socket */
44
int ioctl_sock; /* socket for ioctl() use */
45
int wext_sock; /* socket for wireless events */
48
static const struct driver_ops bsd_driver_ops;
50
static int bsd_sta_deauth(void *priv, const u8 *addr, int reason_code);
53
set80211var(struct bsd_driver_data *drv, int op, const void *arg, int arg_len)
55
struct ieee80211req ireq;
57
memset(&ireq, 0, sizeof(ireq));
58
strncpy(ireq.i_name, drv->iface, IFNAMSIZ);
61
ireq.i_data = (void *) arg;
63
if (ioctl(drv->ioctl_sock, SIOCS80211, &ireq) < 0) {
64
perror("ioctl[SIOCS80211]");
71
get80211var(struct bsd_driver_data *drv, int op, void *arg, int arg_len)
73
struct ieee80211req ireq;
75
memset(&ireq, 0, sizeof(ireq));
76
strncpy(ireq.i_name, drv->iface, IFNAMSIZ);
81
if (ioctl(drv->ioctl_sock, SIOCG80211, &ireq) < 0) {
82
perror("ioctl[SIOCG80211]");
89
set80211param(struct bsd_driver_data *drv, int op, int arg)
91
struct ieee80211req ireq;
93
memset(&ireq, 0, sizeof(ireq));
94
strncpy(ireq.i_name, drv->iface, IFNAMSIZ);
98
if (ioctl(drv->ioctl_sock, SIOCS80211, &ireq) < 0) {
99
perror("ioctl[SIOCS80211]");
106
ether_sprintf(const u8 *addr)
108
static char buf[sizeof(MACSTR)];
111
snprintf(buf, sizeof(buf), MACSTR, MAC2STR(addr));
113
snprintf(buf, sizeof(buf), MACSTR, 0,0,0,0,0,0);
118
* Configure WPA parameters.
121
bsd_configure_wpa(struct bsd_driver_data *drv)
123
static const char *ciphernames[] =
124
{ "WEP", "TKIP", "AES-OCB", "AES-CCM", "CKIP", "NONE" };
125
struct hostapd_data *hapd = drv->hapd;
126
struct hostapd_bss_config *conf = hapd->conf;
129
switch (conf->wpa_group) {
130
case WPA_CIPHER_CCMP:
131
v = IEEE80211_CIPHER_AES_CCM;
133
case WPA_CIPHER_TKIP:
134
v = IEEE80211_CIPHER_TKIP;
136
case WPA_CIPHER_WEP104:
137
v = IEEE80211_CIPHER_WEP;
139
case WPA_CIPHER_WEP40:
140
v = IEEE80211_CIPHER_WEP;
142
case WPA_CIPHER_NONE:
143
v = IEEE80211_CIPHER_NONE;
146
printf("Unknown group key cipher %u\n",
150
HOSTAPD_DEBUG(HOSTAPD_DEBUG_MINIMAL,
151
"%s: group key cipher=%s (%u)\n", __func__, ciphernames[v], v);
152
if (set80211param(drv, IEEE80211_IOC_MCASTCIPHER, v)) {
153
printf("Unable to set group key cipher to %u (%s)\n",
157
if (v == IEEE80211_CIPHER_WEP) {
158
/* key length is done only for specific ciphers */
159
v = (conf->wpa_group == WPA_CIPHER_WEP104 ? 13 : 5);
160
if (set80211param(drv, IEEE80211_IOC_MCASTKEYLEN, v)) {
161
printf("Unable to set group key length to %u\n", v);
167
if (conf->wpa_pairwise & WPA_CIPHER_CCMP)
168
v |= 1<<IEEE80211_CIPHER_AES_CCM;
169
if (conf->wpa_pairwise & WPA_CIPHER_TKIP)
170
v |= 1<<IEEE80211_CIPHER_TKIP;
171
if (conf->wpa_pairwise & WPA_CIPHER_NONE)
172
v |= 1<<IEEE80211_CIPHER_NONE;
173
HOSTAPD_DEBUG(HOSTAPD_DEBUG_MINIMAL,
174
"%s: pairwise key ciphers=0x%x\n", __func__, v);
175
if (set80211param(drv, IEEE80211_IOC_UCASTCIPHERS, v)) {
176
printf("Unable to set pairwise key ciphers to 0x%x\n", v);
180
HOSTAPD_DEBUG(HOSTAPD_DEBUG_MINIMAL,
181
"%s: key management algorithms=0x%x\n",
182
__func__, conf->wpa_key_mgmt);
183
if (set80211param(drv, IEEE80211_IOC_KEYMGTALGS, conf->wpa_key_mgmt)) {
184
printf("Unable to set key management algorithms to 0x%x\n",
190
if (conf->rsn_preauth)
192
HOSTAPD_DEBUG(HOSTAPD_DEBUG_MINIMAL,
193
"%s: rsn capabilities=0x%x\n", __func__, conf->rsn_preauth);
194
if (set80211param(drv, IEEE80211_IOC_RSNCAPS, v)) {
195
printf("Unable to set RSN capabilities to 0x%x\n", v);
199
HOSTAPD_DEBUG(HOSTAPD_DEBUG_MINIMAL,
200
"%s: enable WPA= 0x%x\n", __func__, conf->wpa);
201
if (set80211param(drv, IEEE80211_IOC_WPA, conf->wpa)) {
202
printf("Unable to set WPA to %u\n", conf->wpa);
210
bsd_set_iface_flags(void *priv, int dev_up)
212
struct bsd_driver_data *drv = priv;
213
struct hostapd_data *hapd = drv->hapd;
216
HOSTAPD_DEBUG(HOSTAPD_DEBUG_VERBOSE,
217
"%s: dev_up=%d\n", __func__, dev_up);
219
if (drv->ioctl_sock < 0)
222
memset(&ifr, 0, sizeof(ifr));
223
snprintf(ifr.ifr_name, IFNAMSIZ, "%s", drv->iface);
225
if (ioctl(drv->ioctl_sock, SIOCGIFFLAGS, &ifr) != 0) {
226
perror("ioctl[SIOCGIFFLAGS]");
231
ifr.ifr_flags |= IFF_UP;
233
ifr.ifr_flags &= ~IFF_UP;
235
if (ioctl(drv->ioctl_sock, SIOCSIFFLAGS, &ifr) != 0) {
236
perror("ioctl[SIOCSIFFLAGS]");
241
memset(&ifr, 0, sizeof(ifr));
242
snprintf(ifr.ifr_name, IFNAMSIZ, "%s", drv->iface);
243
ifr.ifr_mtu = HOSTAPD_MTU;
244
if (ioctl(drv->ioctl_sock, SIOCSIFMTU, &ifr) != 0) {
245
perror("ioctl[SIOCSIFMTU]");
246
printf("Setting MTU failed - trying to survive with "
255
bsd_set_ieee8021x(const char *ifname, void *priv, int enabled)
257
struct bsd_driver_data *drv = priv;
258
struct hostapd_data *hapd = drv->hapd;
259
struct hostapd_bss_config *conf = hapd->conf;
261
HOSTAPD_DEBUG(HOSTAPD_DEBUG_VERBOSE,
262
"%s: enabled=%d\n", __func__, enabled);
265
/* XXX restore state */
266
return set80211param(priv, IEEE80211_IOC_AUTHMODE,
267
IEEE80211_AUTH_AUTO);
269
if (!conf->wpa && !conf->ieee802_1x) {
270
hostapd_logger(hapd, NULL, HOSTAPD_MODULE_DRIVER,
271
HOSTAPD_LEVEL_WARNING, "No 802.1X or WPA enabled!");
274
if (conf->wpa && bsd_configure_wpa(drv) != 0) {
275
hostapd_logger(hapd, NULL, HOSTAPD_MODULE_DRIVER,
276
HOSTAPD_LEVEL_WARNING, "Error configuring WPA state!");
279
if (set80211param(priv, IEEE80211_IOC_AUTHMODE,
280
(conf->wpa ? IEEE80211_AUTH_WPA : IEEE80211_AUTH_8021X))) {
281
hostapd_logger(hapd, NULL, HOSTAPD_MODULE_DRIVER,
282
HOSTAPD_LEVEL_WARNING, "Error enabling WPA/802.1X!");
285
return bsd_set_iface_flags(priv, 1);
289
bsd_set_privacy(const char *ifname, void *priv, int enabled)
291
struct bsd_driver_data *drv = priv;
292
struct hostapd_data *hapd = drv->hapd;
294
HOSTAPD_DEBUG(HOSTAPD_DEBUG_MINIMAL,
295
"%s: enabled=%d\n", __func__, enabled);
297
return set80211param(priv, IEEE80211_IOC_PRIVACY, enabled);
301
bsd_set_sta_authorized(void *priv, const u8 *addr, int authorized)
303
struct bsd_driver_data *drv = priv;
304
struct hostapd_data *hapd = drv->hapd;
305
struct ieee80211req_mlme mlme;
307
HOSTAPD_DEBUG(HOSTAPD_DEBUG_VERBOSE,
308
"%s: addr=%s authorized=%d\n",
309
__func__, ether_sprintf(addr), authorized);
312
mlme.im_op = IEEE80211_MLME_AUTHORIZE;
314
mlme.im_op = IEEE80211_MLME_UNAUTHORIZE;
316
memcpy(mlme.im_macaddr, addr, IEEE80211_ADDR_LEN);
317
return set80211var(priv, IEEE80211_IOC_MLME, &mlme, sizeof(mlme));
321
bsd_sta_set_flags(void *priv, const u8 *addr, int flags_or, int flags_and)
323
/* For now, only support setting Authorized flag */
324
if (flags_or & WLAN_STA_AUTHORIZED)
325
return bsd_set_sta_authorized(priv, addr, 1);
326
if (!(flags_and & WLAN_STA_AUTHORIZED))
327
return bsd_set_sta_authorized(priv, addr, 0);
332
bsd_del_key(void *priv, const u8 *addr, int key_idx)
334
struct bsd_driver_data *drv = priv;
335
struct hostapd_data *hapd = drv->hapd;
336
struct ieee80211req_del_key wk;
338
HOSTAPD_DEBUG(HOSTAPD_DEBUG_MINIMAL,
339
"%s: addr=%s key_idx=%d\n",
340
__func__, ether_sprintf(addr), key_idx);
342
memset(&wk, 0, sizeof(wk));
344
memcpy(wk.idk_macaddr, addr, IEEE80211_ADDR_LEN);
345
wk.idk_keyix = (u_int8_t) IEEE80211_KEYIX_NONE; /* XXX */
347
wk.idk_keyix = key_idx;
350
return set80211var(priv, IEEE80211_IOC_DELKEY, &wk, sizeof(wk));
354
bsd_set_key(const char *ifname, void *priv, const char *alg,
355
const u8 *addr, int key_idx,
356
const u8 *key, size_t key_len, int txkey)
358
struct bsd_driver_data *drv = priv;
359
struct hostapd_data *hapd = drv->hapd;
360
struct ieee80211req_key wk;
363
if (strcmp(alg, "none") == 0)
364
return bsd_del_key(priv, addr, key_idx);
366
HOSTAPD_DEBUG(HOSTAPD_DEBUG_MINIMAL,
367
"%s: alg=%s addr=%s key_idx=%d\n",
368
__func__, alg, ether_sprintf(addr), key_idx);
370
if (strcmp(alg, "WEP") == 0)
371
cipher = IEEE80211_CIPHER_WEP;
372
else if (strcmp(alg, "TKIP") == 0)
373
cipher = IEEE80211_CIPHER_TKIP;
374
else if (strcmp(alg, "CCMP") == 0)
375
cipher = IEEE80211_CIPHER_AES_CCM;
377
printf("%s: unknown/unsupported algorithm %s\n",
382
if (key_len > sizeof(wk.ik_keydata)) {
383
printf("%s: key length %d too big\n", __func__, key_len);
387
memset(&wk, 0, sizeof(wk));
389
wk.ik_flags = IEEE80211_KEY_RECV | IEEE80211_KEY_XMIT;
391
memset(wk.ik_macaddr, 0xff, IEEE80211_ADDR_LEN);
392
wk.ik_keyix = key_idx;
393
wk.ik_flags |= IEEE80211_KEY_DEFAULT;
395
memcpy(wk.ik_macaddr, addr, IEEE80211_ADDR_LEN);
396
wk.ik_keyix = IEEE80211_KEYIX_NONE;
398
wk.ik_keylen = key_len;
399
memcpy(wk.ik_keydata, key, key_len);
401
return set80211var(priv, IEEE80211_IOC_WPAKEY, &wk, sizeof(wk));
406
bsd_get_seqnum(const char *ifname, void *priv, const u8 *addr, int idx,
409
struct bsd_driver_data *drv = priv;
410
struct hostapd_data *hapd = drv->hapd;
411
struct ieee80211req_key wk;
413
HOSTAPD_DEBUG(HOSTAPD_DEBUG_MINIMAL,
414
"%s: addr=%s idx=%d\n", __func__, ether_sprintf(addr), idx);
416
memset(&wk, 0, sizeof(wk));
418
memset(wk.ik_macaddr, 0xff, IEEE80211_ADDR_LEN);
420
memcpy(wk.ik_macaddr, addr, IEEE80211_ADDR_LEN);
423
if (get80211var(drv, IEEE80211_IOC_WPAKEY, &wk, sizeof(wk)) < 0) {
424
printf("Failed to get encryption.\n");
428
#ifdef WORDS_BIGENDIAN
431
* wk.ik_keytsc is in host byte order (big endian), need to
432
* swap it to match with the byte order used in WPA.
435
u8 tmp[WPA_KEY_RSC_LEN];
436
memcpy(tmp, &wk.ik_keytsc, sizeof(wk.ik_keytsc));
437
for (i = 0; i < WPA_KEY_RSC_LEN; i++) {
438
seq[i] = tmp[WPA_KEY_RSC_LEN - i - 1];
441
#else /* WORDS_BIGENDIAN */
442
memcpy(seq, &wk.ik_keytsc, sizeof(wk.ik_keytsc));
443
#endif /* WORDS_BIGENDIAN */
449
bsd_flush(void *priv)
451
u8 allsta[IEEE80211_ADDR_LEN];
453
memset(allsta, 0xff, IEEE80211_ADDR_LEN);
454
return bsd_sta_deauth(priv, allsta, IEEE80211_REASON_AUTH_LEAVE);
459
bsd_read_sta_driver_data(void *priv, struct hostap_sta_driver_data *data,
462
struct bsd_driver_data *drv = priv;
463
struct ieee80211req_sta_stats stats;
465
memcpy(stats.is_u.macaddr, addr, IEEE80211_ADDR_LEN);
466
if (get80211var(drv, IEEE80211_IOC_STA_STATS, &stats, sizeof(stats)) > 0) {
467
/* XXX? do packets counts include non-data frames? */
468
data->rx_packets = stats.is_stats.ns_rx_data;
469
data->rx_bytes = stats.is_stats.ns_rx_bytes;
470
data->tx_packets = stats.is_stats.ns_tx_data;
471
data->tx_bytes = stats.is_stats.ns_tx_bytes;
477
bsd_set_opt_ie(const char *ifname, void *priv, const u8 *ie, size_t ie_len)
480
* Do nothing; we setup parameters at startup that define the
481
* contents of the beacon information element.
487
bsd_sta_deauth(void *priv, const u8 *addr, int reason_code)
489
struct bsd_driver_data *drv = priv;
490
struct hostapd_data *hapd = drv->hapd;
491
struct ieee80211req_mlme mlme;
493
HOSTAPD_DEBUG(HOSTAPD_DEBUG_MINIMAL,
494
"%s: addr=%s reason_code=%d\n",
495
__func__, ether_sprintf(addr), reason_code);
497
mlme.im_op = IEEE80211_MLME_DEAUTH;
498
mlme.im_reason = reason_code;
499
memcpy(mlme.im_macaddr, addr, IEEE80211_ADDR_LEN);
500
return set80211var(priv, IEEE80211_IOC_MLME, &mlme, sizeof(mlme));
504
bsd_sta_disassoc(void *priv, const u8 *addr, int reason_code)
506
struct bsd_driver_data *drv = priv;
507
struct hostapd_data *hapd = drv->hapd;
508
struct ieee80211req_mlme mlme;
510
HOSTAPD_DEBUG(HOSTAPD_DEBUG_MINIMAL,
511
"%s: addr=%s reason_code=%d\n",
512
__func__, ether_sprintf(addr), reason_code);
514
mlme.im_op = IEEE80211_MLME_DISASSOC;
515
mlme.im_reason = reason_code;
516
memcpy(mlme.im_macaddr, addr, IEEE80211_ADDR_LEN);
517
return set80211var(priv, IEEE80211_IOC_MLME, &mlme, sizeof(mlme));
521
bsd_del_sta(struct bsd_driver_data *drv, u8 addr[IEEE80211_ADDR_LEN])
523
struct hostapd_data *hapd = drv->hapd;
524
struct hostapd_bss_config *conf = hapd->conf;
525
struct sta_info *sta;
527
hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211,
528
HOSTAPD_LEVEL_INFO, "deassociated");
530
sta = ap_get_sta(hapd, addr);
532
sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);
534
wpa_auth_sm_event(sta->wpa_sm, WPA_DISASSOC);
535
sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
536
ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
537
ap_free_sta(hapd, sta);
543
bsd_new_sta(struct bsd_driver_data *drv, u8 addr[IEEE80211_ADDR_LEN])
545
struct hostapd_data *hapd = drv->hapd;
546
struct hostapd_bss_config *conf = hapd->conf;
547
struct sta_info *sta;
548
struct ieee80211req_wpaie ie;
549
int new_assoc, ielen, res;
551
hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211,
552
HOSTAPD_LEVEL_INFO, "associated");
554
sta = ap_sta_add(hapd, addr);
558
* Fetch and validate any negotiated WPA/RSN parameters.
561
memset(&ie, 0, sizeof(ie));
562
memcpy(ie.wpa_macaddr, addr, IEEE80211_ADDR_LEN);
563
if (get80211var(drv, IEEE80211_IOC_WPAIE, &ie, sizeof(ie)) < 0) {
564
printf("Failed to get WPA/RSN information element.\n");
565
return -1; /* XXX not right */
567
ielen = ie.wpa_ie[1];
569
printf("No WPA/RSN information element for station!\n");
570
return -1; /* XXX not right */
573
if (sta->wpa_sm == NULL)
574
sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
576
if (sta->wpa_sm == NULL) {
577
printf("Failed to initialize WPA state machine\n");
580
res = wpa_validate_wpa_ie(hapd->wpa_auth, sta->wpa_sm,
582
if (res != WPA_IE_OK) {
583
printf("WPA/RSN information element rejected? "
590
* Now that the internal station state is setup
591
* kick the authenticator into action.
593
new_assoc = (sta->flags & WLAN_STA_ASSOC) == 0;
594
sta->flags |= WLAN_STA_AUTH | WLAN_STA_ASSOC;
595
wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC);
596
hostapd_new_assoc_sta(hapd, sta, !new_assoc);
597
ieee802_1x_notify_port_enabled(sta->eapol_sm, 1);
601
#include <net/route.h>
602
#include <net80211/ieee80211_freebsd.h>
605
bsd_wireless_event_receive(int sock, void *ctx, void *sock_ctx)
607
struct bsd_driver_data *drv = ctx;
608
struct hostapd_data *hapd = drv->hapd;
610
struct if_announcemsghdr *ifan;
611
struct rt_msghdr *rtm;
612
struct ieee80211_michael_event *mic;
613
struct ieee80211_join_event *join;
614
struct ieee80211_leave_event *leave;
617
n = read(sock, buf, sizeof(buf));
619
if (errno != EINTR && errno != EAGAIN)
620
perror("read(PF_ROUTE)");
624
rtm = (struct rt_msghdr *) buf;
625
if (rtm->rtm_version != RTM_VERSION) {
626
wpa_printf(MSG_DEBUG, "Routing message version %d not "
627
"understood\n", rtm->rtm_version);
630
ifan = (struct if_announcemsghdr *) rtm;
631
switch (rtm->rtm_type) {
633
switch (ifan->ifan_what) {
634
case RTM_IEEE80211_ASSOC:
635
case RTM_IEEE80211_REASSOC:
636
case RTM_IEEE80211_DISASSOC:
637
case RTM_IEEE80211_SCAN:
639
case RTM_IEEE80211_LEAVE:
640
leave = (struct ieee80211_leave_event *) &ifan[1];
641
bsd_del_sta(drv, leave->iev_addr);
643
case RTM_IEEE80211_JOIN:
644
#ifdef RTM_IEEE80211_REJOIN
645
case RTM_IEEE80211_REJOIN:
647
join = (struct ieee80211_join_event *) &ifan[1];
648
bsd_new_sta(drv, join->iev_addr);
650
case RTM_IEEE80211_REPLAY:
653
case RTM_IEEE80211_MICHAEL:
654
mic = (struct ieee80211_michael_event *) &ifan[1];
655
wpa_printf(MSG_DEBUG,
656
"Michael MIC failure wireless event: "
657
"keyix=%u src_addr=" MACSTR, mic->iev_keyix,
658
MAC2STR(mic->iev_src));
659
ieee80211_michael_mic_failure(hapd, mic->iev_src, 1);
667
bsd_wireless_event_init(void *priv)
669
struct bsd_driver_data *drv = priv;
674
s = socket(PF_ROUTE, SOCK_RAW, 0);
676
perror("socket(PF_ROUTE,SOCK_RAW)");
679
eloop_register_read_sock(s, bsd_wireless_event_receive, drv, NULL);
686
bsd_wireless_event_deinit(void *priv)
688
struct bsd_driver_data *drv = priv;
691
if (drv->wext_sock < 0)
693
eloop_unregister_read_sock(drv->wext_sock);
694
close(drv->wext_sock);
700
bsd_send_eapol(void *priv, const u8 *addr, const u8 *data, size_t data_len,
701
int encrypt, const u8 *own_addr)
703
struct bsd_driver_data *drv = priv;
704
unsigned char buf[3000];
705
unsigned char *bp = buf;
706
struct l2_ethhdr *eth;
711
* Prepend the Etherent header. If the caller left us
712
* space at the front we could just insert it but since
713
* we don't know we copy to a local buffer. Given the frequency
714
* and size of frames this probably doesn't matter.
716
len = data_len + sizeof(struct l2_ethhdr);
717
if (len > sizeof(buf)) {
720
printf("EAPOL frame discarded, cannot malloc temp "
721
"buffer of size %u!\n", len);
725
eth = (struct l2_ethhdr *) bp;
726
memcpy(eth->h_dest, addr, ETH_ALEN);
727
memcpy(eth->h_source, own_addr, ETH_ALEN);
728
eth->h_proto = htons(ETH_P_EAPOL);
729
memcpy(eth+1, data, data_len);
731
wpa_hexdump(MSG_MSGDUMP, "TX EAPOL", bp, len);
733
status = l2_packet_send(drv->sock_xmit, addr, ETH_P_EAPOL, bp, len);
741
handle_read(void *ctx, const u8 *src_addr, const u8 *buf, size_t len)
743
struct bsd_driver_data *drv = ctx;
744
struct hostapd_data *hapd = drv->hapd;
745
struct sta_info *sta;
747
sta = ap_get_sta(hapd, src_addr);
748
if (!sta || !(sta->flags & WLAN_STA_ASSOC)) {
749
printf("Data frame from not associated STA %s\n",
750
ether_sprintf(src_addr));
751
/* XXX cannot happen */
754
ieee802_1x_receive(hapd, src_addr, buf + sizeof(struct l2_ethhdr),
755
len - sizeof(struct l2_ethhdr));
759
bsd_get_ssid(const char *ifname, void *priv, u8 *buf, int len)
761
struct bsd_driver_data *drv = priv;
762
struct hostapd_data *hapd = drv->hapd;
763
int ssid_len = get80211var(priv, IEEE80211_IOC_SSID, buf, len);
765
HOSTAPD_DEBUG(HOSTAPD_DEBUG_MINIMAL, "%s: ssid=\"%.*s\"\n",
766
__func__, ssid_len, buf);
772
bsd_set_ssid(const char *ifname, void *priv, const u8 *buf, int len)
774
struct bsd_driver_data *drv = priv;
775
struct hostapd_data *hapd = drv->hapd;
777
HOSTAPD_DEBUG(HOSTAPD_DEBUG_MINIMAL, "%s: ssid=\"%.*s\"\n",
780
return set80211var(priv, IEEE80211_IOC_SSID, buf, len);
784
bsd_init(struct hostapd_data *hapd)
786
struct bsd_driver_data *drv;
788
drv = wpa_zalloc(sizeof(struct bsd_driver_data));
790
printf("Could not allocate memory for bsd driver data\n");
794
drv->ops = bsd_driver_ops;
796
drv->ioctl_sock = socket(PF_INET, SOCK_DGRAM, 0);
797
if (drv->ioctl_sock < 0) {
798
perror("socket[PF_INET,SOCK_DGRAM]");
801
memcpy(drv->iface, hapd->conf->iface, sizeof(drv->iface));
803
drv->sock_xmit = l2_packet_init(drv->iface, NULL, ETH_P_EAPOL,
804
handle_read, drv, 1);
805
if (drv->sock_xmit == NULL)
807
if (l2_packet_get_own_addr(drv->sock_xmit, hapd->own_addr))
810
bsd_set_iface_flags(drv, 0); /* mark down during setup */
812
hapd->driver = &drv->ops;
815
if (drv->sock_xmit != NULL)
816
l2_packet_deinit(drv->sock_xmit);
817
if (drv->ioctl_sock >= 0)
818
close(drv->ioctl_sock);
826
bsd_deinit(void *priv)
828
struct bsd_driver_data *drv = priv;
830
drv->hapd->driver = NULL;
832
(void) bsd_set_iface_flags(drv, 0);
833
if (drv->ioctl_sock >= 0)
834
close(drv->ioctl_sock);
835
if (drv->sock_xmit != NULL)
836
l2_packet_deinit(drv->sock_xmit);
840
static const struct driver_ops bsd_driver_ops = {
843
.deinit = bsd_deinit,
844
.set_ieee8021x = bsd_set_ieee8021x,
845
.set_privacy = bsd_set_privacy,
846
.set_encryption = bsd_set_key,
847
.get_seqnum = bsd_get_seqnum,
849
.set_generic_elem = bsd_set_opt_ie,
850
.wireless_event_init = bsd_wireless_event_init,
851
.wireless_event_deinit = bsd_wireless_event_deinit,
852
.sta_set_flags = bsd_sta_set_flags,
853
.read_sta_data = bsd_read_sta_driver_data,
854
.send_eapol = bsd_send_eapol,
855
.sta_disassoc = bsd_sta_disassoc,
856
.sta_deauth = bsd_sta_deauth,
857
.set_ssid = bsd_set_ssid,
858
.get_ssid = bsd_get_ssid,
861
void bsd_driver_register(void)
863
driver_register(bsd_driver_ops.name, &bsd_driver_ops);