2 * Driver interaction with Linux Host AP driver
3 * Copyright (c) 2003-2005, Jouni Malinen <j@w1.fi>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
9 * Alternatively, this software may be distributed under the terms of BSD
12 * See README and COPYING for more details.
16 #include <sys/ioctl.h>
18 #include "wireless_copy.h"
21 #include "driver_wext.h"
23 #include "driver_hostap.h"
28 #include <net/if_arp.h>
29 #include <netpacket/packet.h>
31 #include "priv_netlink.h"
32 #include "ieee802_11_defs.h"
33 #include "../../hostapd/hostapd.h"
34 #include "../../hostapd/config.h"
35 #include "../../hostapd/hw_features.h"
36 #include "../../hostapd/sta_flags.h"
39 static const u8 rfc1042_header[6] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
41 struct hostap_driver_data {
42 struct hostapd_data *hapd;
44 char iface[IFNAMSIZ + 1];
45 int sock; /* raw packet socket for driver access */
46 int ioctl_sock; /* socket for ioctl() use */
47 int wext_sock; /* socket for wireless events */
52 size_t generic_ie_len;
58 static int hostapd_ioctl(void *priv, struct prism2_hostapd_param *param,
60 static int hostap_set_iface_flags(void *priv, int dev_up);
61 static int hostap_sta_disassoc(void *priv, const u8 *addr, int reason);
62 static int hostap_sta_deauth(void *priv, const u8 *addr, int reason);
64 static void handle_data(struct hostap_driver_data *drv, u8 *buf, size_t len,
67 struct ieee80211_hdr *hdr;
72 if (len < sizeof(struct ieee80211_hdr))
75 hdr = (struct ieee80211_hdr *) buf;
76 fc = le_to_host16(hdr->frame_control);
78 if ((fc & (WLAN_FC_FROMDS | WLAN_FC_TODS)) != WLAN_FC_TODS) {
79 printf("Not ToDS data frame (fc=0x%04x)\n", fc);
84 hostapd_rx_from_unknown_sta(drv->hapd, sa);
86 pos = (u8 *) (hdr + 1);
87 left = len - sizeof(*hdr);
89 if (left < sizeof(rfc1042_header)) {
90 printf("Too short data frame\n");
94 if (memcmp(pos, rfc1042_header, sizeof(rfc1042_header)) != 0) {
95 printf("Data frame with no RFC1042 header\n");
98 pos += sizeof(rfc1042_header);
99 left -= sizeof(rfc1042_header);
102 printf("No ethertype in data frame\n");
106 ethertype = WPA_GET_BE16(pos);
111 hostapd_eapol_receive(drv->hapd, sa, pos, left);
115 printf("Unknown ethertype 0x%04x in data frame\n", ethertype);
121 static void handle_tx_callback(struct hostap_driver_data *drv, u8 *buf,
124 struct ieee80211_hdr *hdr;
127 hdr = (struct ieee80211_hdr *) buf;
128 fc = le_to_host16(hdr->frame_control);
130 type = WLAN_FC_GET_TYPE(fc);
131 stype = WLAN_FC_GET_STYPE(fc);
134 case WLAN_FC_TYPE_MGMT:
135 wpa_printf(MSG_DEBUG, "MGMT (TX callback) %s",
136 ok ? "ACK" : "fail");
137 hostapd_mgmt_tx_cb(drv->hapd, buf, len, stype, ok);
139 case WLAN_FC_TYPE_CTRL:
140 wpa_printf(MSG_DEBUG, "CTRL (TX callback) %s",
141 ok ? "ACK" : "fail");
143 case WLAN_FC_TYPE_DATA:
144 wpa_printf(MSG_DEBUG, "DATA (TX callback) %s",
145 ok ? "ACK" : "fail");
146 hostapd_tx_status(drv->hapd, hdr->addr1, buf, len, ok);
149 printf("unknown TX callback frame type %d\n", type);
155 static void handle_frame(struct hostap_driver_data *drv, u8 *buf, size_t len)
157 struct ieee80211_hdr *hdr;
158 u16 fc, extra_len, type, stype;
159 unsigned char *extra = NULL;
160 size_t data_len = len;
163 /* PSPOLL is only 16 bytes, but driver does not (at least yet) pass
164 * these to user space */
166 wpa_printf(MSG_MSGDUMP, "handle_frame: too short (%lu)",
167 (unsigned long) len);
171 hdr = (struct ieee80211_hdr *) buf;
172 fc = le_to_host16(hdr->frame_control);
173 type = WLAN_FC_GET_TYPE(fc);
174 stype = WLAN_FC_GET_STYPE(fc);
176 if (type != WLAN_FC_TYPE_MGMT || stype != WLAN_FC_STYPE_BEACON) {
177 wpa_hexdump(MSG_MSGDUMP, "Received management frame",
181 ver = fc & WLAN_FC_PVER;
183 /* protocol version 3 is reserved for indicating extra data after the
184 * payload, version 2 for indicating ACKed frame (TX callbacks), and
185 * version 1 for indicating failed frame (no ACK, TX callbacks) */
187 u8 *pos = buf + len - 2;
188 extra_len = WPA_GET_LE16(pos);
189 printf("extra data in frame (elen=%d)\n", extra_len);
190 if ((size_t) extra_len + 2 > len) {
191 printf(" extra data overflow\n");
194 len -= extra_len + 2;
196 } else if (ver == 1 || ver == 2) {
197 handle_tx_callback(drv, buf, data_len, ver == 2 ? 1 : 0);
199 } else if (ver != 0) {
200 printf("unknown protocol version %d\n", ver);
205 case WLAN_FC_TYPE_MGMT:
206 if (stype != WLAN_FC_STYPE_BEACON)
207 wpa_printf(MSG_MSGDUMP, "MGMT");
208 hostapd_mgmt_rx(drv->hapd, buf, data_len, stype, NULL);
210 case WLAN_FC_TYPE_CTRL:
211 wpa_printf(MSG_DEBUG, "CTRL");
213 case WLAN_FC_TYPE_DATA:
214 wpa_printf(MSG_DEBUG, "DATA");
215 handle_data(drv, buf, data_len, stype);
218 wpa_printf(MSG_DEBUG, "unknown frame type %d", type);
224 static void handle_read(int sock, void *eloop_ctx, void *sock_ctx)
226 struct hostap_driver_data *drv = eloop_ctx;
228 unsigned char buf[3000];
230 len = recv(sock, buf, sizeof(buf), 0);
236 handle_frame(drv, buf, len);
240 static int hostap_init_sockets(struct hostap_driver_data *drv)
243 struct sockaddr_ll addr;
245 drv->sock = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
247 perror("socket[PF_PACKET,SOCK_RAW]");
251 if (eloop_register_read_sock(drv->sock, handle_read, drv, NULL)) {
252 printf("Could not register read socket\n");
256 memset(&ifr, 0, sizeof(ifr));
257 snprintf(ifr.ifr_name, sizeof(ifr.ifr_name), "%sap", drv->iface);
258 if (ioctl(drv->sock, SIOCGIFINDEX, &ifr) != 0) {
259 perror("ioctl(SIOCGIFINDEX)");
263 if (hostap_set_iface_flags(drv, 1)) {
267 memset(&addr, 0, sizeof(addr));
268 addr.sll_family = AF_PACKET;
269 addr.sll_ifindex = ifr.ifr_ifindex;
270 wpa_printf(MSG_DEBUG, "Opening raw packet socket for ifindex %d",
273 if (bind(drv->sock, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
278 memset(&ifr, 0, sizeof(ifr));
279 os_strlcpy(ifr.ifr_name, drv->iface, sizeof(ifr.ifr_name));
280 if (ioctl(drv->sock, SIOCGIFHWADDR, &ifr) != 0) {
281 perror("ioctl(SIOCGIFHWADDR)");
285 if (ifr.ifr_hwaddr.sa_family != ARPHRD_ETHER) {
286 printf("Invalid HW-addr family 0x%04x\n",
287 ifr.ifr_hwaddr.sa_family);
290 memcpy(drv->hapd->own_addr, ifr.ifr_hwaddr.sa_data, ETH_ALEN);
296 static int hostap_send_mgmt_frame(void *priv, const void *msg, size_t len,
299 struct hostap_driver_data *drv = priv;
300 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) msg;
303 /* Request TX callback */
304 hdr->frame_control |= host_to_le16(BIT(1));
305 res = send(drv->sock, msg, len, flags);
306 hdr->frame_control &= ~host_to_le16(BIT(1));
312 static int hostap_send_eapol(void *priv, const u8 *addr, const u8 *data,
313 size_t data_len, int encrypt, const u8 *own_addr)
315 struct hostap_driver_data *drv = priv;
316 struct ieee80211_hdr *hdr;
321 len = sizeof(*hdr) + sizeof(rfc1042_header) + 2 + data_len;
322 hdr = os_zalloc(len);
324 printf("malloc() failed for hostapd_send_data(len=%lu)\n",
325 (unsigned long) len);
330 IEEE80211_FC(WLAN_FC_TYPE_DATA, WLAN_FC_STYPE_DATA);
331 hdr->frame_control |= host_to_le16(WLAN_FC_FROMDS);
333 hdr->frame_control |= host_to_le16(WLAN_FC_ISWEP);
334 memcpy(hdr->IEEE80211_DA_FROMDS, addr, ETH_ALEN);
335 memcpy(hdr->IEEE80211_BSSID_FROMDS, own_addr, ETH_ALEN);
336 memcpy(hdr->IEEE80211_SA_FROMDS, own_addr, ETH_ALEN);
338 pos = (u8 *) (hdr + 1);
339 memcpy(pos, rfc1042_header, sizeof(rfc1042_header));
340 pos += sizeof(rfc1042_header);
341 *((u16 *) pos) = htons(ETH_P_PAE);
343 memcpy(pos, data, data_len);
345 res = hostap_send_mgmt_frame(drv, (u8 *) hdr, len, 0);
349 perror("hostapd_send_eapol: send");
350 printf("hostapd_send_eapol - packet len: %lu - failed\n",
351 (unsigned long) len);
358 static int hostap_sta_set_flags(void *priv, const u8 *addr,
359 int total_flags, int flags_or, int flags_and)
361 struct hostap_driver_data *drv = priv;
362 struct prism2_hostapd_param param;
364 memset(¶m, 0, sizeof(param));
365 param.cmd = PRISM2_HOSTAPD_SET_FLAGS_STA;
366 memcpy(param.sta_addr, addr, ETH_ALEN);
367 param.u.set_flags_sta.flags_or = flags_or;
368 param.u.set_flags_sta.flags_and = flags_and;
369 return hostapd_ioctl(drv, ¶m, sizeof(param));
373 static int hostap_set_iface_flags(void *priv, int dev_up)
375 struct hostap_driver_data *drv = priv;
378 if (drv->ioctl_sock < 0)
381 memset(&ifr, 0, sizeof(ifr));
382 snprintf(ifr.ifr_name, IFNAMSIZ, "%sap", drv->iface);
384 if (ioctl(drv->ioctl_sock, SIOCGIFFLAGS, &ifr) != 0) {
385 perror("ioctl[SIOCGIFFLAGS]");
390 ifr.ifr_flags |= IFF_UP;
392 ifr.ifr_flags &= ~IFF_UP;
394 if (ioctl(drv->ioctl_sock, SIOCSIFFLAGS, &ifr) != 0) {
395 perror("ioctl[SIOCSIFFLAGS]");
400 memset(&ifr, 0, sizeof(ifr));
401 snprintf(ifr.ifr_name, IFNAMSIZ, "%sap", drv->iface);
402 ifr.ifr_mtu = HOSTAPD_MTU;
403 if (ioctl(drv->ioctl_sock, SIOCSIFMTU, &ifr) != 0) {
404 perror("ioctl[SIOCSIFMTU]");
405 printf("Setting MTU failed - trying to survive with "
414 static int hostapd_ioctl(void *priv, struct prism2_hostapd_param *param,
417 struct hostap_driver_data *drv = priv;
420 memset(&iwr, 0, sizeof(iwr));
421 os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
422 iwr.u.data.pointer = (caddr_t) param;
423 iwr.u.data.length = len;
425 if (ioctl(drv->ioctl_sock, PRISM2_IOCTL_HOSTAPD, &iwr) < 0) {
426 perror("ioctl[PRISM2_IOCTL_HOSTAPD]");
434 static int hostap_set_key(const char *ifname, void *priv, wpa_alg alg,
435 const u8 *addr, int key_idx, int set_tx,
436 const u8 *seq, size_t seq_len, const u8 *key,
439 struct hostap_driver_data *drv = priv;
440 struct prism2_hostapd_param *param;
445 blen = sizeof(*param) + key_len;
446 buf = os_zalloc(blen);
450 param = (struct prism2_hostapd_param *) buf;
451 param->cmd = PRISM2_SET_ENCRYPTION;
453 memset(param->sta_addr, 0xff, ETH_ALEN);
455 memcpy(param->sta_addr, addr, ETH_ALEN);
458 os_strlcpy((char *) param->u.crypt.alg, "NONE",
459 HOSTAP_CRYPT_ALG_NAME_LEN);
462 os_strlcpy((char *) param->u.crypt.alg, "WEP",
463 HOSTAP_CRYPT_ALG_NAME_LEN);
466 os_strlcpy((char *) param->u.crypt.alg, "TKIP",
467 HOSTAP_CRYPT_ALG_NAME_LEN);
470 os_strlcpy((char *) param->u.crypt.alg, "CCMP",
471 HOSTAP_CRYPT_ALG_NAME_LEN);
477 param->u.crypt.flags = set_tx ? HOSTAP_CRYPT_FLAG_SET_TX_KEY : 0;
478 param->u.crypt.idx = key_idx;
479 param->u.crypt.key_len = key_len;
480 memcpy((u8 *) (param + 1), key, key_len);
482 if (hostapd_ioctl(drv, param, blen)) {
483 printf("Failed to set encryption.\n");
492 static int hostap_get_seqnum(const char *ifname, void *priv, const u8 *addr,
495 struct hostap_driver_data *drv = priv;
496 struct prism2_hostapd_param *param;
501 blen = sizeof(*param) + 32;
502 buf = os_zalloc(blen);
506 param = (struct prism2_hostapd_param *) buf;
507 param->cmd = PRISM2_GET_ENCRYPTION;
509 memset(param->sta_addr, 0xff, ETH_ALEN);
511 memcpy(param->sta_addr, addr, ETH_ALEN);
512 param->u.crypt.idx = idx;
514 if (hostapd_ioctl(drv, param, blen)) {
515 printf("Failed to get encryption.\n");
518 memcpy(seq, param->u.crypt.seq, 8);
526 static int hostap_ioctl_prism2param(void *priv, int param, int value)
528 struct hostap_driver_data *drv = priv;
532 memset(&iwr, 0, sizeof(iwr));
533 os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
534 i = (int *) iwr.u.name;
538 if (ioctl(drv->ioctl_sock, PRISM2_IOCTL_PRISM2_PARAM, &iwr) < 0) {
539 perror("ioctl[PRISM2_IOCTL_PRISM2_PARAM]");
547 static int hostap_set_ieee8021x(const char *ifname, void *priv, int enabled)
549 struct hostap_driver_data *drv = priv;
551 /* enable kernel driver support for IEEE 802.1X */
552 if (hostap_ioctl_prism2param(drv, PRISM2_PARAM_IEEE_802_1X, enabled)) {
553 printf("Could not setup IEEE 802.1X support in kernel driver."
561 /* use host driver implementation of encryption to allow
562 * individual keys and passing plaintext EAPOL frames */
563 if (hostap_ioctl_prism2param(drv, PRISM2_PARAM_HOST_DECRYPT, 1) ||
564 hostap_ioctl_prism2param(drv, PRISM2_PARAM_HOST_ENCRYPT, 1)) {
565 printf("Could not setup host-based encryption in kernel "
574 static int hostap_set_privacy(const char *ifname, void *priv, int enabled)
576 struct hostap_drvier_data *drv = priv;
578 return hostap_ioctl_prism2param(drv, PRISM2_PARAM_PRIVACY_INVOKED,
583 static int hostap_set_ssid(const char *ifname, void *priv, const u8 *buf,
586 struct hostap_driver_data *drv = priv;
589 memset(&iwr, 0, sizeof(iwr));
590 os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
591 iwr.u.essid.flags = 1; /* SSID active */
592 iwr.u.essid.pointer = (caddr_t) buf;
593 iwr.u.essid.length = len + 1;
595 if (ioctl(drv->ioctl_sock, SIOCSIWESSID, &iwr) < 0) {
596 perror("ioctl[SIOCSIWESSID]");
597 printf("len=%d\n", len);
605 static int hostap_flush(void *priv)
607 struct hostap_driver_data *drv = priv;
608 struct prism2_hostapd_param param;
610 memset(¶m, 0, sizeof(param));
611 param.cmd = PRISM2_HOSTAPD_FLUSH;
612 return hostapd_ioctl(drv, ¶m, sizeof(param));
616 static int hostap_read_sta_data(void *priv,
617 struct hostap_sta_driver_data *data,
620 struct hostap_driver_data *drv = priv;
621 char buf[1024], line[128], *pos;
625 memset(data, 0, sizeof(*data));
626 snprintf(buf, sizeof(buf), "/proc/net/hostap/%s/" MACSTR,
627 drv->iface, MAC2STR(addr));
632 /* Need to read proc file with in one piece, so use large enough
634 setbuffer(f, buf, sizeof(buf));
636 while (fgets(line, sizeof(line), f)) {
637 pos = strchr(line, '=');
641 val = strtoul(pos, NULL, 10);
642 if (strcmp(line, "rx_packets") == 0)
643 data->rx_packets = val;
644 else if (strcmp(line, "tx_packets") == 0)
645 data->tx_packets = val;
646 else if (strcmp(line, "rx_bytes") == 0)
647 data->rx_bytes = val;
648 else if (strcmp(line, "tx_bytes") == 0)
649 data->tx_bytes = val;
658 static int hostap_sta_add(const char *ifname, void *priv,
659 struct hostapd_sta_add_params *params)
661 struct hostap_driver_data *drv = priv;
662 struct prism2_hostapd_param param;
663 int tx_supp_rates = 0;
666 #define WLAN_RATE_1M BIT(0)
667 #define WLAN_RATE_2M BIT(1)
668 #define WLAN_RATE_5M5 BIT(2)
669 #define WLAN_RATE_11M BIT(3)
671 for (i = 0; i < params->supp_rates_len; i++) {
672 if ((params->supp_rates[i] & 0x7f) == 2)
673 tx_supp_rates |= WLAN_RATE_1M;
674 if ((params->supp_rates[i] & 0x7f) == 4)
675 tx_supp_rates |= WLAN_RATE_2M;
676 if ((params->supp_rates[i] & 0x7f) == 11)
677 tx_supp_rates |= WLAN_RATE_5M5;
678 if ((params->supp_rates[i] & 0x7f) == 22)
679 tx_supp_rates |= WLAN_RATE_11M;
682 memset(¶m, 0, sizeof(param));
683 param.cmd = PRISM2_HOSTAPD_ADD_STA;
684 memcpy(param.sta_addr, params->addr, ETH_ALEN);
685 param.u.add_sta.aid = params->aid;
686 param.u.add_sta.capability = params->capability;
687 param.u.add_sta.tx_supp_rates = tx_supp_rates;
688 return hostapd_ioctl(drv, ¶m, sizeof(param));
692 static int hostap_sta_remove(void *priv, const u8 *addr)
694 struct hostap_driver_data *drv = priv;
695 struct prism2_hostapd_param param;
697 hostap_sta_set_flags(drv, addr, 0, 0, ~WLAN_STA_AUTHORIZED);
699 memset(¶m, 0, sizeof(param));
700 param.cmd = PRISM2_HOSTAPD_REMOVE_STA;
701 memcpy(param.sta_addr, addr, ETH_ALEN);
702 if (hostapd_ioctl(drv, ¶m, sizeof(param))) {
703 printf("Could not remove station from kernel driver.\n");
710 static int hostap_get_inact_sec(void *priv, const u8 *addr)
712 struct hostap_driver_data *drv = priv;
713 struct prism2_hostapd_param param;
715 memset(¶m, 0, sizeof(param));
716 param.cmd = PRISM2_HOSTAPD_GET_INFO_STA;
717 memcpy(param.sta_addr, addr, ETH_ALEN);
718 if (hostapd_ioctl(drv, ¶m, sizeof(param))) {
722 return param.u.get_info_sta.inactive_sec;
726 static int hostap_sta_clear_stats(void *priv, const u8 *addr)
728 struct hostap_driver_data *drv = priv;
729 struct prism2_hostapd_param param;
731 memset(¶m, 0, sizeof(param));
732 param.cmd = PRISM2_HOSTAPD_STA_CLEAR_STATS;
733 memcpy(param.sta_addr, addr, ETH_ALEN);
734 if (hostapd_ioctl(drv, ¶m, sizeof(param))) {
742 static int hostapd_ioctl_set_generic_elem(struct hostap_driver_data *drv)
744 struct prism2_hostapd_param *param;
746 size_t blen, elem_len;
748 elem_len = drv->generic_ie_len + drv->wps_ie_len;
749 blen = PRISM2_HOSTAPD_GENERIC_ELEMENT_HDR_LEN + elem_len;
750 if (blen < sizeof(*param))
751 blen = sizeof(*param);
753 param = os_zalloc(blen);
757 param->cmd = PRISM2_HOSTAPD_SET_GENERIC_ELEMENT;
758 param->u.generic_elem.len = elem_len;
759 if (drv->generic_ie) {
760 os_memcpy(param->u.generic_elem.data, drv->generic_ie,
761 drv->generic_ie_len);
764 os_memcpy(¶m->u.generic_elem.data[drv->generic_ie_len],
765 drv->wps_ie, drv->wps_ie_len);
767 wpa_hexdump(MSG_DEBUG, "hostap: Set generic IE",
768 param->u.generic_elem.data, elem_len);
769 res = hostapd_ioctl(drv, param, blen);
777 static int hostap_set_generic_elem(const char *ifname, void *priv,
778 const u8 *elem, size_t elem_len)
780 struct hostap_driver_data *drv = priv;
782 os_free(drv->generic_ie);
783 drv->generic_ie = NULL;
784 drv->generic_ie_len = 0;
786 drv->generic_ie = os_malloc(elem_len);
787 if (drv->generic_ie == NULL)
789 os_memcpy(drv->generic_ie, elem, elem_len);
790 drv->generic_ie_len = elem_len;
793 return hostapd_ioctl_set_generic_elem(drv);
797 static int hostap_set_wps_beacon_ie(const char *ifname, void *priv,
798 const u8 *ie, size_t len)
800 /* Host AP driver supports only one set of extra IEs, so we need to
801 * use the ProbeResp IEs also for Beacon frames since they include more
807 static int hostap_set_wps_probe_resp_ie(const char *ifname, void *priv,
808 const u8 *ie, size_t len)
810 struct hostap_driver_data *drv = priv;
812 os_free(drv->wps_ie);
816 drv->wps_ie = os_malloc(len);
817 if (drv->wps_ie == NULL)
819 os_memcpy(drv->wps_ie, ie, len);
820 drv->wps_ie_len = len;
823 return hostapd_ioctl_set_generic_elem(drv);
828 hostapd_wireless_event_wireless_custom(struct hostap_driver_data *drv,
831 wpa_printf(MSG_DEBUG, "Custom wireless event: '%s'", custom);
833 if (strncmp(custom, "MLME-MICHAELMICFAILURE.indication", 33) == 0) {
836 pos = strstr(custom, "addr=");
838 wpa_printf(MSG_DEBUG,
839 "MLME-MICHAELMICFAILURE.indication "
840 "without sender address ignored");
844 if (hwaddr_aton(pos, addr) == 0) {
845 hostapd_michael_mic_failure(drv->hapd, addr);
847 wpa_printf(MSG_DEBUG,
848 "MLME-MICHAELMICFAILURE.indication "
849 "with invalid MAC address");
855 static void hostapd_wireless_event_wireless(struct hostap_driver_data *drv,
858 struct iw_event iwe_buf, *iwe = &iwe_buf;
859 char *pos, *end, *custom, *buf;
864 while (pos + IW_EV_LCP_LEN <= end) {
865 /* Event data may be unaligned, so make a local, aligned copy
866 * before processing. */
867 memcpy(&iwe_buf, pos, IW_EV_LCP_LEN);
868 wpa_printf(MSG_DEBUG, "Wireless event: cmd=0x%x len=%d",
870 if (iwe->len <= IW_EV_LCP_LEN)
873 custom = pos + IW_EV_POINT_LEN;
874 if (drv->we_version > 18 &&
875 (iwe->cmd == IWEVMICHAELMICFAILURE ||
876 iwe->cmd == IWEVCUSTOM)) {
877 /* WE-19 removed the pointer from struct iw_point */
878 char *dpos = (char *) &iwe_buf.u.data.length;
879 int dlen = dpos - (char *) &iwe_buf;
880 memcpy(dpos, pos + IW_EV_LCP_LEN,
881 sizeof(struct iw_event) - dlen);
883 memcpy(&iwe_buf, pos, sizeof(struct iw_event));
884 custom += IW_EV_POINT_OFF;
889 if (custom + iwe->u.data.length > end)
891 buf = malloc(iwe->u.data.length + 1);
894 memcpy(buf, custom, iwe->u.data.length);
895 buf[iwe->u.data.length] = '\0';
896 hostapd_wireless_event_wireless_custom(drv, buf);
906 static void hostapd_wireless_event_rtm_newlink(struct hostap_driver_data *drv,
907 struct nlmsghdr *h, int len)
909 struct ifinfomsg *ifi;
910 int attrlen, nlmsg_len, rta_len;
911 struct rtattr * attr;
913 if (len < (int) sizeof(*ifi))
918 /* TODO: use ifi->ifi_index to filter out wireless events from other
921 nlmsg_len = NLMSG_ALIGN(sizeof(struct ifinfomsg));
923 attrlen = h->nlmsg_len - nlmsg_len;
927 attr = (struct rtattr *) (((char *) ifi) + nlmsg_len);
929 rta_len = RTA_ALIGN(sizeof(struct rtattr));
930 while (RTA_OK(attr, attrlen)) {
931 if (attr->rta_type == IFLA_WIRELESS) {
932 hostapd_wireless_event_wireless(
933 drv, ((char *) attr) + rta_len,
934 attr->rta_len - rta_len);
936 attr = RTA_NEXT(attr, attrlen);
941 static void hostapd_wireless_event_receive(int sock, void *eloop_ctx,
946 struct sockaddr_nl from;
949 struct hostap_driver_data *drv = eloop_ctx;
951 fromlen = sizeof(from);
952 left = recvfrom(sock, buf, sizeof(buf), MSG_DONTWAIT,
953 (struct sockaddr *) &from, &fromlen);
955 if (errno != EINTR && errno != EAGAIN)
956 perror("recvfrom(netlink)");
960 h = (struct nlmsghdr *) buf;
961 while (left >= (int) sizeof(*h)) {
965 plen = len - sizeof(*h);
966 if (len > left || plen < 0) {
967 printf("Malformed netlink message: "
968 "len=%d left=%d plen=%d\n",
973 switch (h->nlmsg_type) {
975 hostapd_wireless_event_rtm_newlink(drv, h, plen);
979 len = NLMSG_ALIGN(len);
981 h = (struct nlmsghdr *) ((char *) h + len);
985 printf("%d extra bytes in the end of netlink message\n", left);
990 static int hostap_get_we_version(struct hostap_driver_data *drv)
992 struct iw_range *range;
1000 * Use larger buffer than struct iw_range in order to allow the
1001 * structure to grow in the future.
1003 buflen = sizeof(struct iw_range) + 500;
1004 range = os_zalloc(buflen);
1008 memset(&iwr, 0, sizeof(iwr));
1009 os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
1010 iwr.u.data.pointer = (caddr_t) range;
1011 iwr.u.data.length = buflen;
1013 minlen = ((char *) &range->enc_capa) - (char *) range +
1014 sizeof(range->enc_capa);
1016 if (ioctl(drv->ioctl_sock, SIOCGIWRANGE, &iwr) < 0) {
1017 perror("ioctl[SIOCGIWRANGE]");
1020 } else if (iwr.u.data.length >= minlen &&
1021 range->we_version_compiled >= 18) {
1022 wpa_printf(MSG_DEBUG, "SIOCGIWRANGE: WE(compiled)=%d "
1023 "WE(source)=%d enc_capa=0x%x",
1024 range->we_version_compiled,
1025 range->we_version_source,
1027 drv->we_version = range->we_version_compiled;
1035 static int hostap_wireless_event_init(struct hostap_driver_data *drv)
1038 struct sockaddr_nl local;
1040 hostap_get_we_version(drv);
1042 drv->wext_sock = -1;
1044 s = socket(PF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
1046 perror("socket(PF_NETLINK,SOCK_RAW,NETLINK_ROUTE)");
1050 memset(&local, 0, sizeof(local));
1051 local.nl_family = AF_NETLINK;
1052 local.nl_groups = RTMGRP_LINK;
1053 if (bind(s, (struct sockaddr *) &local, sizeof(local)) < 0) {
1054 perror("bind(netlink)");
1059 eloop_register_read_sock(s, hostapd_wireless_event_receive, drv,
1067 static void hostap_wireless_event_deinit(struct hostap_driver_data *drv)
1069 if (drv->wext_sock < 0)
1071 eloop_unregister_read_sock(drv->wext_sock);
1072 close(drv->wext_sock);
1076 static void * hostap_init(struct hostapd_data *hapd)
1078 struct hostap_driver_data *drv;
1080 drv = os_zalloc(sizeof(struct hostap_driver_data));
1082 printf("Could not allocate memory for hostapd driver data\n");
1087 drv->ioctl_sock = drv->sock = -1;
1088 memcpy(drv->iface, hapd->conf->iface, sizeof(drv->iface));
1090 drv->ioctl_sock = socket(PF_INET, SOCK_DGRAM, 0);
1091 if (drv->ioctl_sock < 0) {
1092 perror("socket[PF_INET,SOCK_DGRAM]");
1097 if (hostap_ioctl_prism2param(drv, PRISM2_PARAM_HOSTAPD, 1)) {
1098 printf("Could not enable hostapd mode for interface %s\n",
1100 close(drv->ioctl_sock);
1105 if (hostap_init_sockets(drv) || hostap_wireless_event_init(drv)) {
1106 close(drv->ioctl_sock);
1115 static void hostap_driver_deinit(void *priv)
1117 struct hostap_driver_data *drv = priv;
1119 hostap_wireless_event_deinit(drv);
1120 (void) hostap_set_iface_flags(drv, 0);
1121 (void) hostap_ioctl_prism2param(drv, PRISM2_PARAM_HOSTAPD, 0);
1122 (void) hostap_ioctl_prism2param(drv, PRISM2_PARAM_HOSTAPD_STA, 0);
1124 if (drv->ioctl_sock >= 0)
1125 close(drv->ioctl_sock);
1130 os_free(drv->generic_ie);
1131 os_free(drv->wps_ie);
1137 static int hostap_sta_deauth(void *priv, const u8 *addr, int reason)
1139 struct hostap_driver_data *drv = priv;
1140 struct ieee80211_mgmt mgmt;
1142 memset(&mgmt, 0, sizeof(mgmt));
1143 mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
1144 WLAN_FC_STYPE_DEAUTH);
1145 memcpy(mgmt.da, addr, ETH_ALEN);
1146 memcpy(mgmt.sa, drv->hapd->own_addr, ETH_ALEN);
1147 memcpy(mgmt.bssid, drv->hapd->own_addr, ETH_ALEN);
1148 mgmt.u.deauth.reason_code = host_to_le16(reason);
1149 return hostap_send_mgmt_frame(drv, &mgmt, IEEE80211_HDRLEN +
1150 sizeof(mgmt.u.deauth), 0);
1154 static int hostap_sta_disassoc(void *priv, const u8 *addr, int reason)
1156 struct hostap_driver_data *drv = priv;
1157 struct ieee80211_mgmt mgmt;
1159 memset(&mgmt, 0, sizeof(mgmt));
1160 mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
1161 WLAN_FC_STYPE_DISASSOC);
1162 memcpy(mgmt.da, addr, ETH_ALEN);
1163 memcpy(mgmt.sa, drv->hapd->own_addr, ETH_ALEN);
1164 memcpy(mgmt.bssid, drv->hapd->own_addr, ETH_ALEN);
1165 mgmt.u.disassoc.reason_code = host_to_le16(reason);
1166 return hostap_send_mgmt_frame(drv, &mgmt, IEEE80211_HDRLEN +
1167 sizeof(mgmt.u.disassoc), 0);
1171 static struct hostapd_hw_modes * hostap_get_hw_feature_data(void *priv,
1175 struct hostapd_hw_modes *mode;
1177 const short chan2freq[14] = {
1178 2412, 2417, 2422, 2427, 2432, 2437, 2442,
1179 2447, 2452, 2457, 2462, 2467, 2472, 2484
1182 mode = os_zalloc(sizeof(struct hostapd_hw_modes));
1189 mode->mode = HOSTAPD_MODE_IEEE80211B;
1190 mode->num_channels = 14;
1191 mode->num_rates = 4;
1193 clen = mode->num_channels * sizeof(struct hostapd_channel_data);
1194 rlen = mode->num_rates * sizeof(struct hostapd_rate_data);
1196 mode->channels = os_zalloc(clen);
1197 mode->rates = os_zalloc(rlen);
1198 if (mode->channels == NULL || mode->rates == NULL) {
1199 hostapd_free_hw_features(mode, *num_modes);
1203 for (i = 0; i < 14; i++) {
1204 mode->channels[i].chan = i + 1;
1205 mode->channels[i].freq = chan2freq[i];
1206 /* TODO: Get allowed channel list from the driver */
1208 mode->channels[i].flag = HOSTAPD_CHAN_DISABLED;
1211 mode->rates[0].rate = 10;
1212 mode->rates[0].flags = HOSTAPD_RATE_CCK;
1213 mode->rates[1].rate = 20;
1214 mode->rates[1].flags = HOSTAPD_RATE_CCK;
1215 mode->rates[2].rate = 55;
1216 mode->rates[2].flags = HOSTAPD_RATE_CCK;
1217 mode->rates[3].rate = 110;
1218 mode->rates[3].flags = HOSTAPD_RATE_CCK;
1225 struct wpa_driver_hostap_data {
1226 void *wext; /* private data for driver_wext */
1228 char ifname[IFNAMSIZ + 1];
1230 int current_mode; /* infra/adhoc */
1234 static int hostapd_ioctl(struct wpa_driver_hostap_data *drv,
1235 struct prism2_hostapd_param *param,
1236 int len, int show_err)
1240 os_memset(&iwr, 0, sizeof(iwr));
1241 os_strlcpy(iwr.ifr_name, drv->ifname, IFNAMSIZ);
1242 iwr.u.data.pointer = (caddr_t) param;
1243 iwr.u.data.length = len;
1245 if (ioctl(drv->sock, PRISM2_IOCTL_HOSTAPD, &iwr) < 0) {
1248 perror("ioctl[PRISM2_IOCTL_HOSTAPD]");
1256 static int wpa_driver_hostap_set_wpa_ie(struct wpa_driver_hostap_data *drv,
1257 const u8 *wpa_ie, size_t wpa_ie_len)
1259 struct prism2_hostapd_param *param;
1261 size_t blen = PRISM2_HOSTAPD_GENERIC_ELEMENT_HDR_LEN + wpa_ie_len;
1262 if (blen < sizeof(*param))
1263 blen = sizeof(*param);
1265 param = os_zalloc(blen);
1269 param->cmd = PRISM2_HOSTAPD_SET_GENERIC_ELEMENT;
1270 param->u.generic_elem.len = wpa_ie_len;
1271 os_memcpy(param->u.generic_elem.data, wpa_ie, wpa_ie_len);
1272 res = hostapd_ioctl(drv, param, blen, 1);
1280 static int prism2param(struct wpa_driver_hostap_data *drv, int param,
1286 os_memset(&iwr, 0, sizeof(iwr));
1287 os_strlcpy(iwr.ifr_name, drv->ifname, IFNAMSIZ);
1288 i = (int *) iwr.u.name;
1292 if (ioctl(drv->sock, PRISM2_IOCTL_PRISM2_PARAM, &iwr) < 0) {
1293 perror("ioctl[PRISM2_IOCTL_PRISM2_PARAM]");
1300 static int wpa_driver_hostap_set_wpa(void *priv, int enabled)
1302 struct wpa_driver_hostap_data *drv = priv;
1305 wpa_printf(MSG_DEBUG, "%s: enabled=%d", __FUNCTION__, enabled);
1307 if (!enabled && wpa_driver_hostap_set_wpa_ie(drv, NULL, 0) < 0)
1309 if (prism2param(drv, PRISM2_PARAM_HOST_ROAMING, enabled ? 2 : 0) < 0)
1311 if (prism2param(drv, PRISM2_PARAM_WPA, enabled) < 0)
1318 static void show_set_key_error(struct prism2_hostapd_param *param)
1320 switch (param->u.crypt.err) {
1321 case HOSTAP_CRYPT_ERR_UNKNOWN_ALG:
1322 wpa_printf(MSG_INFO, "Unknown algorithm '%s'.",
1323 param->u.crypt.alg);
1324 wpa_printf(MSG_INFO, "You may need to load kernel module to "
1325 "register that algorithm.");
1326 wpa_printf(MSG_INFO, "E.g., 'modprobe hostap_crypt_wep' for "
1329 case HOSTAP_CRYPT_ERR_UNKNOWN_ADDR:
1330 wpa_printf(MSG_INFO, "Unknown address " MACSTR ".",
1331 MAC2STR(param->sta_addr));
1333 case HOSTAP_CRYPT_ERR_CRYPT_INIT_FAILED:
1334 wpa_printf(MSG_INFO, "Crypt algorithm initialization failed.");
1336 case HOSTAP_CRYPT_ERR_KEY_SET_FAILED:
1337 wpa_printf(MSG_INFO, "Key setting failed.");
1339 case HOSTAP_CRYPT_ERR_TX_KEY_SET_FAILED:
1340 wpa_printf(MSG_INFO, "TX key index setting failed.");
1342 case HOSTAP_CRYPT_ERR_CARD_CONF_FAILED:
1343 wpa_printf(MSG_INFO, "Card configuration failed.");
1349 static int wpa_driver_hostap_set_key(void *priv, wpa_alg alg,
1350 const u8 *addr, int key_idx,
1351 int set_tx, const u8 *seq, size_t seq_len,
1352 const u8 *key, size_t key_len)
1354 struct wpa_driver_hostap_data *drv = priv;
1355 struct prism2_hostapd_param *param;
1378 wpa_printf(MSG_DEBUG, "%s: alg=%s key_idx=%d set_tx=%d seq_len=%lu "
1379 "key_len=%lu", __FUNCTION__, alg_name, key_idx, set_tx,
1380 (unsigned long) seq_len, (unsigned long) key_len);
1385 blen = sizeof(*param) + key_len;
1386 buf = os_zalloc(blen);
1390 param = (struct prism2_hostapd_param *) buf;
1391 param->cmd = PRISM2_SET_ENCRYPTION;
1392 /* TODO: In theory, STA in client mode can use five keys; four default
1393 * keys for receiving (with keyidx 0..3) and one individual key for
1394 * both transmitting and receiving (keyidx 0) _unicast_ packets. Now,
1395 * keyidx 0 is reserved for this unicast use and default keys can only
1396 * use keyidx 1..3 (i.e., default key with keyidx 0 is not supported).
1397 * This should be fine for more or less all cases, but for completeness
1398 * sake, the driver could be enhanced to support the missing key. */
1401 os_memset(param->sta_addr, 0xff, ETH_ALEN);
1403 os_memcpy(param->sta_addr, addr, ETH_ALEN);
1405 os_memset(param->sta_addr, 0xff, ETH_ALEN);
1407 os_strlcpy((char *) param->u.crypt.alg, alg_name,
1408 HOSTAP_CRYPT_ALG_NAME_LEN);
1409 param->u.crypt.flags = set_tx ? HOSTAP_CRYPT_FLAG_SET_TX_KEY : 0;
1410 param->u.crypt.idx = key_idx;
1411 os_memcpy(param->u.crypt.seq, seq, seq_len);
1412 param->u.crypt.key_len = key_len;
1413 os_memcpy((u8 *) (param + 1), key, key_len);
1415 if (hostapd_ioctl(drv, param, blen, 1)) {
1416 wpa_printf(MSG_WARNING, "Failed to set encryption.");
1417 show_set_key_error(param);
1426 static int wpa_driver_hostap_set_countermeasures(void *priv, int enabled)
1428 struct wpa_driver_hostap_data *drv = priv;
1429 wpa_printf(MSG_DEBUG, "%s: enabled=%d", __FUNCTION__, enabled);
1430 return prism2param(drv, PRISM2_PARAM_TKIP_COUNTERMEASURES, enabled);
1434 static int wpa_driver_hostap_set_drop_unencrypted(void *priv, int enabled)
1436 struct wpa_driver_hostap_data *drv = priv;
1437 wpa_printf(MSG_DEBUG, "%s: enabled=%d", __FUNCTION__, enabled);
1438 return prism2param(drv, PRISM2_PARAM_DROP_UNENCRYPTED, enabled);
1442 static int wpa_driver_hostap_reset(struct wpa_driver_hostap_data *drv,
1448 wpa_printf(MSG_DEBUG, "%s: type=%d", __FUNCTION__, type);
1450 os_memset(&iwr, 0, sizeof(iwr));
1451 os_strlcpy(iwr.ifr_name, drv->ifname, IFNAMSIZ);
1452 i = (int *) iwr.u.name;
1455 if (ioctl(drv->sock, PRISM2_IOCTL_RESET, &iwr) < 0) {
1456 perror("ioctl[PRISM2_IOCTL_RESET]");
1463 static int wpa_driver_hostap_mlme(struct wpa_driver_hostap_data *drv,
1464 const u8 *addr, int cmd, int reason_code)
1466 struct prism2_hostapd_param param;
1469 /* There does not seem to be a better way of deauthenticating or
1470 * disassociating with Prism2/2.5/3 than sending the management frame
1471 * and then resetting the Port0 to make sure both the AP and the STA
1472 * end up in disconnected state. */
1473 os_memset(¶m, 0, sizeof(param));
1474 param.cmd = PRISM2_HOSTAPD_MLME;
1475 os_memcpy(param.sta_addr, addr, ETH_ALEN);
1476 param.u.mlme.cmd = cmd;
1477 param.u.mlme.reason_code = reason_code;
1478 ret = hostapd_ioctl(drv, ¶m, sizeof(param), 1);
1480 os_sleep(0, 100000);
1481 ret = wpa_driver_hostap_reset(drv, 2);
1487 static int wpa_driver_hostap_deauthenticate(void *priv, const u8 *addr,
1490 struct wpa_driver_hostap_data *drv = priv;
1491 wpa_printf(MSG_DEBUG, "%s", __FUNCTION__);
1492 return wpa_driver_hostap_mlme(drv, addr, MLME_STA_DEAUTH,
1497 static int wpa_driver_hostap_disassociate(void *priv, const u8 *addr,
1500 struct wpa_driver_hostap_data *drv = priv;
1501 wpa_printf(MSG_DEBUG, "%s", __FUNCTION__);
1502 return wpa_driver_hostap_mlme(drv, addr, MLME_STA_DISASSOC,
1508 wpa_driver_hostap_associate(void *priv,
1509 struct wpa_driver_associate_params *params)
1511 struct wpa_driver_hostap_data *drv = priv;
1513 int allow_unencrypted_eapol;
1515 wpa_printf(MSG_DEBUG, "%s", __FUNCTION__);
1517 if (params->mode != drv->current_mode) {
1518 /* At the moment, Host AP driver requires host_roaming=2 for
1519 * infrastructure mode and host_roaming=0 for adhoc. */
1520 if (prism2param(drv, PRISM2_PARAM_HOST_ROAMING,
1521 params->mode == IEEE80211_MODE_IBSS ? 0 : 2) <
1523 wpa_printf(MSG_DEBUG, "%s: failed to set host_roaming",
1526 drv->current_mode = params->mode;
1529 if (prism2param(drv, PRISM2_PARAM_PRIVACY_INVOKED,
1530 params->key_mgmt_suite != KEY_MGMT_NONE) < 0)
1532 if (wpa_driver_hostap_set_wpa_ie(drv, params->wpa_ie,
1533 params->wpa_ie_len) < 0)
1535 if (wpa_driver_wext_set_mode(drv->wext, params->mode) < 0)
1538 wpa_driver_wext_set_freq(drv->wext, params->freq) < 0)
1540 if (wpa_driver_wext_set_ssid(drv->wext, params->ssid, params->ssid_len)
1543 if (wpa_driver_wext_set_bssid(drv->wext, params->bssid) < 0)
1546 /* Allow unencrypted EAPOL messages even if pairwise keys are set when
1547 * not using WPA. IEEE 802.1X specifies that these frames are not
1548 * encrypted, but WPA encrypts them when pairwise keys are in use. */
1549 if (params->key_mgmt_suite == KEY_MGMT_802_1X ||
1550 params->key_mgmt_suite == KEY_MGMT_PSK)
1551 allow_unencrypted_eapol = 0;
1553 allow_unencrypted_eapol = 1;
1555 if (prism2param(drv, PRISM2_PARAM_IEEE_802_1X,
1556 allow_unencrypted_eapol) < 0) {
1557 wpa_printf(MSG_DEBUG, "hostap: Failed to configure "
1558 "ieee_802_1x param");
1559 /* Ignore this error.. driver_hostap.c can also be used with
1560 * other drivers that do not support this prism2_param. */
1567 static int wpa_driver_hostap_scan(void *priv, const u8 *ssid, size_t ssid_len)
1569 struct wpa_driver_hostap_data *drv = priv;
1570 struct prism2_hostapd_param param;
1574 /* Use standard Linux Wireless Extensions ioctl if possible
1575 * because some drivers using hostap code in wpa_supplicant
1576 * might not support Host AP specific scan request (with SSID
1578 return wpa_driver_wext_scan(drv->wext, ssid, ssid_len);
1584 os_memset(¶m, 0, sizeof(param));
1585 param.cmd = PRISM2_HOSTAPD_SCAN_REQ;
1586 param.u.scan_req.ssid_len = ssid_len;
1587 os_memcpy(param.u.scan_req.ssid, ssid, ssid_len);
1588 ret = hostapd_ioctl(drv, ¶m, sizeof(param), 1);
1590 /* Not all drivers generate "scan completed" wireless event, so try to
1591 * read results after a timeout. */
1592 eloop_cancel_timeout(wpa_driver_wext_scan_timeout, drv->wext,
1594 eloop_register_timeout(3, 0, wpa_driver_wext_scan_timeout, drv->wext,
1601 static int wpa_driver_hostap_set_auth_alg(void *priv, int auth_alg)
1603 struct wpa_driver_hostap_data *drv = priv;
1606 if (auth_alg & AUTH_ALG_OPEN_SYSTEM)
1608 if (auth_alg & AUTH_ALG_SHARED_KEY)
1610 if (auth_alg & AUTH_ALG_LEAP)
1613 algs = 1; /* at least one algorithm should be set */
1615 return prism2param(drv, PRISM2_PARAM_AP_AUTH_ALGS, algs);
1619 static int wpa_driver_hostap_get_bssid(void *priv, u8 *bssid)
1621 struct wpa_driver_hostap_data *drv = priv;
1622 return wpa_driver_wext_get_bssid(drv->wext, bssid);
1626 static int wpa_driver_hostap_get_ssid(void *priv, u8 *ssid)
1628 struct wpa_driver_hostap_data *drv = priv;
1629 return wpa_driver_wext_get_ssid(drv->wext, ssid);
1633 static struct wpa_scan_results * wpa_driver_hostap_get_scan_results(void *priv)
1635 struct wpa_driver_hostap_data *drv = priv;
1636 return wpa_driver_wext_get_scan_results(drv->wext);
1640 static int wpa_driver_hostap_set_operstate(void *priv, int state)
1642 struct wpa_driver_hostap_data *drv = priv;
1643 return wpa_driver_wext_set_operstate(drv->wext, state);
1647 static void * wpa_driver_hostap_init(void *ctx, const char *ifname)
1649 struct wpa_driver_hostap_data *drv;
1651 drv = os_zalloc(sizeof(*drv));
1654 drv->wext = wpa_driver_wext_init(ctx, ifname);
1655 if (drv->wext == NULL) {
1661 os_strlcpy(drv->ifname, ifname, sizeof(drv->ifname));
1662 drv->sock = socket(PF_INET, SOCK_DGRAM, 0);
1663 if (drv->sock < 0) {
1665 wpa_driver_wext_deinit(drv->wext);
1670 if (os_strncmp(ifname, "wlan", 4) == 0) {
1672 * Host AP driver may use both wlan# and wifi# interface in
1675 char ifname2[IFNAMSIZ + 1];
1676 os_strlcpy(ifname2, ifname, sizeof(ifname2));
1677 os_memcpy(ifname2, "wifi", 4);
1678 wpa_driver_wext_alternative_ifindex(drv->wext, ifname2);
1685 static void wpa_driver_hostap_deinit(void *priv)
1687 struct wpa_driver_hostap_data *drv = priv;
1688 wpa_driver_wext_deinit(drv->wext);
1693 #endif /* HOSTAPD */
1696 const struct wpa_driver_ops wpa_driver_hostap_ops = {
1698 .desc = "Host AP driver (Intersil Prism2/2.5/3)",
1700 .hapd_init = hostap_init,
1701 .hapd_deinit = hostap_driver_deinit,
1702 .set_ieee8021x = hostap_set_ieee8021x,
1703 .set_privacy = hostap_set_privacy,
1704 .hapd_set_key = hostap_set_key,
1705 .get_seqnum = hostap_get_seqnum,
1706 .flush = hostap_flush,
1707 .set_generic_elem = hostap_set_generic_elem,
1708 .read_sta_data = hostap_read_sta_data,
1709 .hapd_send_eapol = hostap_send_eapol,
1710 .sta_set_flags = hostap_sta_set_flags,
1711 .sta_deauth = hostap_sta_deauth,
1712 .sta_disassoc = hostap_sta_disassoc,
1713 .sta_remove = hostap_sta_remove,
1714 .hapd_set_ssid = hostap_set_ssid,
1715 .send_mgmt_frame = hostap_send_mgmt_frame,
1716 .sta_add = hostap_sta_add,
1717 .get_inact_sec = hostap_get_inact_sec,
1718 .sta_clear_stats = hostap_sta_clear_stats,
1719 .get_hw_feature_data = hostap_get_hw_feature_data,
1720 .set_wps_beacon_ie = hostap_set_wps_beacon_ie,
1721 .set_wps_probe_resp_ie = hostap_set_wps_probe_resp_ie,
1723 .get_bssid = wpa_driver_hostap_get_bssid,
1724 .get_ssid = wpa_driver_hostap_get_ssid,
1725 .set_wpa = wpa_driver_hostap_set_wpa,
1726 .set_key = wpa_driver_hostap_set_key,
1727 .set_countermeasures = wpa_driver_hostap_set_countermeasures,
1728 .set_drop_unencrypted = wpa_driver_hostap_set_drop_unencrypted,
1729 .scan = wpa_driver_hostap_scan,
1730 .get_scan_results2 = wpa_driver_hostap_get_scan_results,
1731 .deauthenticate = wpa_driver_hostap_deauthenticate,
1732 .disassociate = wpa_driver_hostap_disassociate,
1733 .associate = wpa_driver_hostap_associate,
1734 .set_auth_alg = wpa_driver_hostap_set_auth_alg,
1735 .init = wpa_driver_hostap_init,
1736 .deinit = wpa_driver_hostap_deinit,
1737 .set_operstate = wpa_driver_hostap_set_operstate,
1738 #endif /* HOSTAPD */