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)
298 struct hostap_driver_data *drv = priv;
299 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) msg;
302 /* Request TX callback */
303 hdr->frame_control |= host_to_le16(BIT(1));
304 res = send(drv->sock, msg, len, 0);
305 hdr->frame_control &= ~host_to_le16(BIT(1));
311 static int hostap_send_eapol(void *priv, const u8 *addr, const u8 *data,
312 size_t data_len, int encrypt, const u8 *own_addr)
314 struct hostap_driver_data *drv = priv;
315 struct ieee80211_hdr *hdr;
320 len = sizeof(*hdr) + sizeof(rfc1042_header) + 2 + data_len;
321 hdr = os_zalloc(len);
323 printf("malloc() failed for hostapd_send_data(len=%lu)\n",
324 (unsigned long) len);
329 IEEE80211_FC(WLAN_FC_TYPE_DATA, WLAN_FC_STYPE_DATA);
330 hdr->frame_control |= host_to_le16(WLAN_FC_FROMDS);
332 hdr->frame_control |= host_to_le16(WLAN_FC_ISWEP);
333 memcpy(hdr->IEEE80211_DA_FROMDS, addr, ETH_ALEN);
334 memcpy(hdr->IEEE80211_BSSID_FROMDS, own_addr, ETH_ALEN);
335 memcpy(hdr->IEEE80211_SA_FROMDS, own_addr, ETH_ALEN);
337 pos = (u8 *) (hdr + 1);
338 memcpy(pos, rfc1042_header, sizeof(rfc1042_header));
339 pos += sizeof(rfc1042_header);
340 *((u16 *) pos) = htons(ETH_P_PAE);
342 memcpy(pos, data, data_len);
344 res = hostap_send_mgmt_frame(drv, (u8 *) hdr, len);
348 perror("hostapd_send_eapol: send");
349 printf("hostapd_send_eapol - packet len: %lu - failed\n",
350 (unsigned long) len);
357 static int hostap_sta_set_flags(void *priv, const u8 *addr,
358 int total_flags, int flags_or, int flags_and)
360 struct hostap_driver_data *drv = priv;
361 struct prism2_hostapd_param param;
363 memset(¶m, 0, sizeof(param));
364 param.cmd = PRISM2_HOSTAPD_SET_FLAGS_STA;
365 memcpy(param.sta_addr, addr, ETH_ALEN);
366 param.u.set_flags_sta.flags_or = flags_or;
367 param.u.set_flags_sta.flags_and = flags_and;
368 return hostapd_ioctl(drv, ¶m, sizeof(param));
372 static int hostap_set_iface_flags(void *priv, int dev_up)
374 struct hostap_driver_data *drv = priv;
377 if (drv->ioctl_sock < 0)
380 memset(&ifr, 0, sizeof(ifr));
381 snprintf(ifr.ifr_name, IFNAMSIZ, "%sap", drv->iface);
383 if (ioctl(drv->ioctl_sock, SIOCGIFFLAGS, &ifr) != 0) {
384 perror("ioctl[SIOCGIFFLAGS]");
389 ifr.ifr_flags |= IFF_UP;
391 ifr.ifr_flags &= ~IFF_UP;
393 if (ioctl(drv->ioctl_sock, SIOCSIFFLAGS, &ifr) != 0) {
394 perror("ioctl[SIOCSIFFLAGS]");
399 memset(&ifr, 0, sizeof(ifr));
400 snprintf(ifr.ifr_name, IFNAMSIZ, "%sap", drv->iface);
401 ifr.ifr_mtu = HOSTAPD_MTU;
402 if (ioctl(drv->ioctl_sock, SIOCSIFMTU, &ifr) != 0) {
403 perror("ioctl[SIOCSIFMTU]");
404 printf("Setting MTU failed - trying to survive with "
413 static int hostapd_ioctl(void *priv, struct prism2_hostapd_param *param,
416 struct hostap_driver_data *drv = priv;
419 memset(&iwr, 0, sizeof(iwr));
420 os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
421 iwr.u.data.pointer = (caddr_t) param;
422 iwr.u.data.length = len;
424 if (ioctl(drv->ioctl_sock, PRISM2_IOCTL_HOSTAPD, &iwr) < 0) {
425 perror("ioctl[PRISM2_IOCTL_HOSTAPD]");
433 static int hostap_set_key(const char *ifname, void *priv, wpa_alg alg,
434 const u8 *addr, int key_idx, int set_tx,
435 const u8 *seq, size_t seq_len, const u8 *key,
438 struct hostap_driver_data *drv = priv;
439 struct prism2_hostapd_param *param;
444 blen = sizeof(*param) + key_len;
445 buf = os_zalloc(blen);
449 param = (struct prism2_hostapd_param *) buf;
450 param->cmd = PRISM2_SET_ENCRYPTION;
452 memset(param->sta_addr, 0xff, ETH_ALEN);
454 memcpy(param->sta_addr, addr, ETH_ALEN);
457 os_strlcpy((char *) param->u.crypt.alg, "NONE",
458 HOSTAP_CRYPT_ALG_NAME_LEN);
461 os_strlcpy((char *) param->u.crypt.alg, "WEP",
462 HOSTAP_CRYPT_ALG_NAME_LEN);
465 os_strlcpy((char *) param->u.crypt.alg, "TKIP",
466 HOSTAP_CRYPT_ALG_NAME_LEN);
469 os_strlcpy((char *) param->u.crypt.alg, "CCMP",
470 HOSTAP_CRYPT_ALG_NAME_LEN);
476 param->u.crypt.flags = set_tx ? HOSTAP_CRYPT_FLAG_SET_TX_KEY : 0;
477 param->u.crypt.idx = key_idx;
478 param->u.crypt.key_len = key_len;
479 memcpy((u8 *) (param + 1), key, key_len);
481 if (hostapd_ioctl(drv, param, blen)) {
482 printf("Failed to set encryption.\n");
491 static int hostap_get_seqnum(const char *ifname, void *priv, const u8 *addr,
494 struct hostap_driver_data *drv = priv;
495 struct prism2_hostapd_param *param;
500 blen = sizeof(*param) + 32;
501 buf = os_zalloc(blen);
505 param = (struct prism2_hostapd_param *) buf;
506 param->cmd = PRISM2_GET_ENCRYPTION;
508 memset(param->sta_addr, 0xff, ETH_ALEN);
510 memcpy(param->sta_addr, addr, ETH_ALEN);
511 param->u.crypt.idx = idx;
513 if (hostapd_ioctl(drv, param, blen)) {
514 printf("Failed to get encryption.\n");
517 memcpy(seq, param->u.crypt.seq, 8);
525 static int hostap_ioctl_prism2param(void *priv, int param, int value)
527 struct hostap_driver_data *drv = priv;
531 memset(&iwr, 0, sizeof(iwr));
532 os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
533 i = (int *) iwr.u.name;
537 if (ioctl(drv->ioctl_sock, PRISM2_IOCTL_PRISM2_PARAM, &iwr) < 0) {
538 perror("ioctl[PRISM2_IOCTL_PRISM2_PARAM]");
546 static int hostap_set_ieee8021x(const char *ifname, void *priv, int enabled)
548 struct hostap_driver_data *drv = priv;
550 /* enable kernel driver support for IEEE 802.1X */
551 if (hostap_ioctl_prism2param(drv, PRISM2_PARAM_IEEE_802_1X, enabled)) {
552 printf("Could not setup IEEE 802.1X support in kernel driver."
560 /* use host driver implementation of encryption to allow
561 * individual keys and passing plaintext EAPOL frames */
562 if (hostap_ioctl_prism2param(drv, PRISM2_PARAM_HOST_DECRYPT, 1) ||
563 hostap_ioctl_prism2param(drv, PRISM2_PARAM_HOST_ENCRYPT, 1)) {
564 printf("Could not setup host-based encryption in kernel "
573 static int hostap_set_privacy(const char *ifname, void *priv, int enabled)
575 struct hostap_drvier_data *drv = priv;
577 return hostap_ioctl_prism2param(drv, PRISM2_PARAM_PRIVACY_INVOKED,
582 static int hostap_set_ssid(const char *ifname, void *priv, const u8 *buf,
585 struct hostap_driver_data *drv = priv;
588 memset(&iwr, 0, sizeof(iwr));
589 os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
590 iwr.u.essid.flags = 1; /* SSID active */
591 iwr.u.essid.pointer = (caddr_t) buf;
592 iwr.u.essid.length = len + 1;
594 if (ioctl(drv->ioctl_sock, SIOCSIWESSID, &iwr) < 0) {
595 perror("ioctl[SIOCSIWESSID]");
596 printf("len=%d\n", len);
604 static int hostap_flush(void *priv)
606 struct hostap_driver_data *drv = priv;
607 struct prism2_hostapd_param param;
609 memset(¶m, 0, sizeof(param));
610 param.cmd = PRISM2_HOSTAPD_FLUSH;
611 return hostapd_ioctl(drv, ¶m, sizeof(param));
615 static int hostap_read_sta_data(void *priv,
616 struct hostap_sta_driver_data *data,
619 struct hostap_driver_data *drv = priv;
620 char buf[1024], line[128], *pos;
624 memset(data, 0, sizeof(*data));
625 snprintf(buf, sizeof(buf), "/proc/net/hostap/%s/" MACSTR,
626 drv->iface, MAC2STR(addr));
631 /* Need to read proc file with in one piece, so use large enough
633 setbuffer(f, buf, sizeof(buf));
635 while (fgets(line, sizeof(line), f)) {
636 pos = strchr(line, '=');
640 val = strtoul(pos, NULL, 10);
641 if (strcmp(line, "rx_packets") == 0)
642 data->rx_packets = val;
643 else if (strcmp(line, "tx_packets") == 0)
644 data->tx_packets = val;
645 else if (strcmp(line, "rx_bytes") == 0)
646 data->rx_bytes = val;
647 else if (strcmp(line, "tx_bytes") == 0)
648 data->tx_bytes = val;
657 static int hostap_sta_add(const char *ifname, void *priv,
658 struct hostapd_sta_add_params *params)
660 struct hostap_driver_data *drv = priv;
661 struct prism2_hostapd_param param;
662 int tx_supp_rates = 0;
665 #define WLAN_RATE_1M BIT(0)
666 #define WLAN_RATE_2M BIT(1)
667 #define WLAN_RATE_5M5 BIT(2)
668 #define WLAN_RATE_11M BIT(3)
670 for (i = 0; i < params->supp_rates_len; i++) {
671 if ((params->supp_rates[i] & 0x7f) == 2)
672 tx_supp_rates |= WLAN_RATE_1M;
673 if ((params->supp_rates[i] & 0x7f) == 4)
674 tx_supp_rates |= WLAN_RATE_2M;
675 if ((params->supp_rates[i] & 0x7f) == 11)
676 tx_supp_rates |= WLAN_RATE_5M5;
677 if ((params->supp_rates[i] & 0x7f) == 22)
678 tx_supp_rates |= WLAN_RATE_11M;
681 memset(¶m, 0, sizeof(param));
682 param.cmd = PRISM2_HOSTAPD_ADD_STA;
683 memcpy(param.sta_addr, params->addr, ETH_ALEN);
684 param.u.add_sta.aid = params->aid;
685 param.u.add_sta.capability = params->capability;
686 param.u.add_sta.tx_supp_rates = tx_supp_rates;
687 return hostapd_ioctl(drv, ¶m, sizeof(param));
691 static int hostap_sta_remove(void *priv, const u8 *addr)
693 struct hostap_driver_data *drv = priv;
694 struct prism2_hostapd_param param;
696 hostap_sta_set_flags(drv, addr, 0, 0, ~WLAN_STA_AUTHORIZED);
698 memset(¶m, 0, sizeof(param));
699 param.cmd = PRISM2_HOSTAPD_REMOVE_STA;
700 memcpy(param.sta_addr, addr, ETH_ALEN);
701 if (hostapd_ioctl(drv, ¶m, sizeof(param))) {
702 printf("Could not remove station from kernel driver.\n");
709 static int hostap_get_inact_sec(void *priv, const u8 *addr)
711 struct hostap_driver_data *drv = priv;
712 struct prism2_hostapd_param param;
714 memset(¶m, 0, sizeof(param));
715 param.cmd = PRISM2_HOSTAPD_GET_INFO_STA;
716 memcpy(param.sta_addr, addr, ETH_ALEN);
717 if (hostapd_ioctl(drv, ¶m, sizeof(param))) {
721 return param.u.get_info_sta.inactive_sec;
725 static int hostap_sta_clear_stats(void *priv, const u8 *addr)
727 struct hostap_driver_data *drv = priv;
728 struct prism2_hostapd_param param;
730 memset(¶m, 0, sizeof(param));
731 param.cmd = PRISM2_HOSTAPD_STA_CLEAR_STATS;
732 memcpy(param.sta_addr, addr, ETH_ALEN);
733 if (hostapd_ioctl(drv, ¶m, sizeof(param))) {
741 static int hostapd_ioctl_set_generic_elem(struct hostap_driver_data *drv)
743 struct prism2_hostapd_param *param;
745 size_t blen, elem_len;
747 elem_len = drv->generic_ie_len + drv->wps_ie_len;
748 blen = PRISM2_HOSTAPD_GENERIC_ELEMENT_HDR_LEN + elem_len;
749 if (blen < sizeof(*param))
750 blen = sizeof(*param);
752 param = os_zalloc(blen);
756 param->cmd = PRISM2_HOSTAPD_SET_GENERIC_ELEMENT;
757 param->u.generic_elem.len = elem_len;
758 if (drv->generic_ie) {
759 os_memcpy(param->u.generic_elem.data, drv->generic_ie,
760 drv->generic_ie_len);
763 os_memcpy(¶m->u.generic_elem.data[drv->generic_ie_len],
764 drv->wps_ie, drv->wps_ie_len);
766 wpa_hexdump(MSG_DEBUG, "hostap: Set generic IE",
767 param->u.generic_elem.data, elem_len);
768 res = hostapd_ioctl(drv, param, blen);
776 static int hostap_set_generic_elem(const char *ifname, void *priv,
777 const u8 *elem, size_t elem_len)
779 struct hostap_driver_data *drv = priv;
781 os_free(drv->generic_ie);
782 drv->generic_ie = NULL;
783 drv->generic_ie_len = 0;
785 drv->generic_ie = os_malloc(elem_len);
786 if (drv->generic_ie == NULL)
788 os_memcpy(drv->generic_ie, elem, elem_len);
789 drv->generic_ie_len = elem_len;
792 return hostapd_ioctl_set_generic_elem(drv);
796 static int hostap_set_wps_beacon_ie(const char *ifname, void *priv,
797 const u8 *ie, size_t len)
799 /* Host AP driver supports only one set of extra IEs, so we need to
800 * use the ProbeResp IEs also for Beacon frames since they include more
806 static int hostap_set_wps_probe_resp_ie(const char *ifname, void *priv,
807 const u8 *ie, size_t len)
809 struct hostap_driver_data *drv = priv;
811 os_free(drv->wps_ie);
815 drv->wps_ie = os_malloc(len);
816 if (drv->wps_ie == NULL)
818 os_memcpy(drv->wps_ie, ie, len);
819 drv->wps_ie_len = len;
822 return hostapd_ioctl_set_generic_elem(drv);
827 hostapd_wireless_event_wireless_custom(struct hostap_driver_data *drv,
830 wpa_printf(MSG_DEBUG, "Custom wireless event: '%s'", custom);
832 if (strncmp(custom, "MLME-MICHAELMICFAILURE.indication", 33) == 0) {
835 pos = strstr(custom, "addr=");
837 wpa_printf(MSG_DEBUG,
838 "MLME-MICHAELMICFAILURE.indication "
839 "without sender address ignored");
843 if (hwaddr_aton(pos, addr) == 0) {
844 hostapd_michael_mic_failure(drv->hapd, addr);
846 wpa_printf(MSG_DEBUG,
847 "MLME-MICHAELMICFAILURE.indication "
848 "with invalid MAC address");
854 static void hostapd_wireless_event_wireless(struct hostap_driver_data *drv,
857 struct iw_event iwe_buf, *iwe = &iwe_buf;
858 char *pos, *end, *custom, *buf;
863 while (pos + IW_EV_LCP_LEN <= end) {
864 /* Event data may be unaligned, so make a local, aligned copy
865 * before processing. */
866 memcpy(&iwe_buf, pos, IW_EV_LCP_LEN);
867 wpa_printf(MSG_DEBUG, "Wireless event: cmd=0x%x len=%d",
869 if (iwe->len <= IW_EV_LCP_LEN)
872 custom = pos + IW_EV_POINT_LEN;
873 if (drv->we_version > 18 &&
874 (iwe->cmd == IWEVMICHAELMICFAILURE ||
875 iwe->cmd == IWEVCUSTOM)) {
876 /* WE-19 removed the pointer from struct iw_point */
877 char *dpos = (char *) &iwe_buf.u.data.length;
878 int dlen = dpos - (char *) &iwe_buf;
879 memcpy(dpos, pos + IW_EV_LCP_LEN,
880 sizeof(struct iw_event) - dlen);
882 memcpy(&iwe_buf, pos, sizeof(struct iw_event));
883 custom += IW_EV_POINT_OFF;
888 if (custom + iwe->u.data.length > end)
890 buf = malloc(iwe->u.data.length + 1);
893 memcpy(buf, custom, iwe->u.data.length);
894 buf[iwe->u.data.length] = '\0';
895 hostapd_wireless_event_wireless_custom(drv, buf);
905 static void hostapd_wireless_event_rtm_newlink(struct hostap_driver_data *drv,
906 struct nlmsghdr *h, int len)
908 struct ifinfomsg *ifi;
909 int attrlen, nlmsg_len, rta_len;
910 struct rtattr * attr;
912 if (len < (int) sizeof(*ifi))
917 /* TODO: use ifi->ifi_index to filter out wireless events from other
920 nlmsg_len = NLMSG_ALIGN(sizeof(struct ifinfomsg));
922 attrlen = h->nlmsg_len - nlmsg_len;
926 attr = (struct rtattr *) (((char *) ifi) + nlmsg_len);
928 rta_len = RTA_ALIGN(sizeof(struct rtattr));
929 while (RTA_OK(attr, attrlen)) {
930 if (attr->rta_type == IFLA_WIRELESS) {
931 hostapd_wireless_event_wireless(
932 drv, ((char *) attr) + rta_len,
933 attr->rta_len - rta_len);
935 attr = RTA_NEXT(attr, attrlen);
940 static void hostapd_wireless_event_receive(int sock, void *eloop_ctx,
945 struct sockaddr_nl from;
948 struct hostap_driver_data *drv = eloop_ctx;
950 fromlen = sizeof(from);
951 left = recvfrom(sock, buf, sizeof(buf), MSG_DONTWAIT,
952 (struct sockaddr *) &from, &fromlen);
954 if (errno != EINTR && errno != EAGAIN)
955 perror("recvfrom(netlink)");
959 h = (struct nlmsghdr *) buf;
960 while (left >= (int) sizeof(*h)) {
964 plen = len - sizeof(*h);
965 if (len > left || plen < 0) {
966 printf("Malformed netlink message: "
967 "len=%d left=%d plen=%d\n",
972 switch (h->nlmsg_type) {
974 hostapd_wireless_event_rtm_newlink(drv, h, plen);
978 len = NLMSG_ALIGN(len);
980 h = (struct nlmsghdr *) ((char *) h + len);
984 printf("%d extra bytes in the end of netlink message\n", left);
989 static int hostap_get_we_version(struct hostap_driver_data *drv)
991 struct iw_range *range;
999 * Use larger buffer than struct iw_range in order to allow the
1000 * structure to grow in the future.
1002 buflen = sizeof(struct iw_range) + 500;
1003 range = os_zalloc(buflen);
1007 memset(&iwr, 0, sizeof(iwr));
1008 os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
1009 iwr.u.data.pointer = (caddr_t) range;
1010 iwr.u.data.length = buflen;
1012 minlen = ((char *) &range->enc_capa) - (char *) range +
1013 sizeof(range->enc_capa);
1015 if (ioctl(drv->ioctl_sock, SIOCGIWRANGE, &iwr) < 0) {
1016 perror("ioctl[SIOCGIWRANGE]");
1019 } else if (iwr.u.data.length >= minlen &&
1020 range->we_version_compiled >= 18) {
1021 wpa_printf(MSG_DEBUG, "SIOCGIWRANGE: WE(compiled)=%d "
1022 "WE(source)=%d enc_capa=0x%x",
1023 range->we_version_compiled,
1024 range->we_version_source,
1026 drv->we_version = range->we_version_compiled;
1034 static int hostap_wireless_event_init(struct hostap_driver_data *drv)
1037 struct sockaddr_nl local;
1039 hostap_get_we_version(drv);
1041 drv->wext_sock = -1;
1043 s = socket(PF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
1045 perror("socket(PF_NETLINK,SOCK_RAW,NETLINK_ROUTE)");
1049 memset(&local, 0, sizeof(local));
1050 local.nl_family = AF_NETLINK;
1051 local.nl_groups = RTMGRP_LINK;
1052 if (bind(s, (struct sockaddr *) &local, sizeof(local)) < 0) {
1053 perror("bind(netlink)");
1058 eloop_register_read_sock(s, hostapd_wireless_event_receive, drv,
1066 static void hostap_wireless_event_deinit(struct hostap_driver_data *drv)
1068 if (drv->wext_sock < 0)
1070 eloop_unregister_read_sock(drv->wext_sock);
1071 close(drv->wext_sock);
1075 static void * hostap_init(struct hostapd_data *hapd)
1077 struct hostap_driver_data *drv;
1079 drv = os_zalloc(sizeof(struct hostap_driver_data));
1081 printf("Could not allocate memory for hostapd driver data\n");
1086 drv->ioctl_sock = drv->sock = -1;
1087 memcpy(drv->iface, hapd->conf->iface, sizeof(drv->iface));
1089 drv->ioctl_sock = socket(PF_INET, SOCK_DGRAM, 0);
1090 if (drv->ioctl_sock < 0) {
1091 perror("socket[PF_INET,SOCK_DGRAM]");
1096 if (hostap_ioctl_prism2param(drv, PRISM2_PARAM_HOSTAPD, 1)) {
1097 printf("Could not enable hostapd mode for interface %s\n",
1099 close(drv->ioctl_sock);
1104 if (hostap_init_sockets(drv) || hostap_wireless_event_init(drv)) {
1105 close(drv->ioctl_sock);
1114 static void hostap_driver_deinit(void *priv)
1116 struct hostap_driver_data *drv = priv;
1118 hostap_wireless_event_deinit(drv);
1119 (void) hostap_set_iface_flags(drv, 0);
1120 (void) hostap_ioctl_prism2param(drv, PRISM2_PARAM_HOSTAPD, 0);
1121 (void) hostap_ioctl_prism2param(drv, PRISM2_PARAM_HOSTAPD_STA, 0);
1123 if (drv->ioctl_sock >= 0)
1124 close(drv->ioctl_sock);
1129 os_free(drv->generic_ie);
1130 os_free(drv->wps_ie);
1136 static int hostap_sta_deauth(void *priv, const u8 *addr, int reason)
1138 struct hostap_driver_data *drv = priv;
1139 struct ieee80211_mgmt mgmt;
1141 memset(&mgmt, 0, sizeof(mgmt));
1142 mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
1143 WLAN_FC_STYPE_DEAUTH);
1144 memcpy(mgmt.da, addr, ETH_ALEN);
1145 memcpy(mgmt.sa, drv->hapd->own_addr, ETH_ALEN);
1146 memcpy(mgmt.bssid, drv->hapd->own_addr, ETH_ALEN);
1147 mgmt.u.deauth.reason_code = host_to_le16(reason);
1148 return hostap_send_mgmt_frame(drv, &mgmt, IEEE80211_HDRLEN +
1149 sizeof(mgmt.u.deauth));
1153 static int hostap_sta_disassoc(void *priv, const u8 *addr, int reason)
1155 struct hostap_driver_data *drv = priv;
1156 struct ieee80211_mgmt mgmt;
1158 memset(&mgmt, 0, sizeof(mgmt));
1159 mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
1160 WLAN_FC_STYPE_DISASSOC);
1161 memcpy(mgmt.da, addr, ETH_ALEN);
1162 memcpy(mgmt.sa, drv->hapd->own_addr, ETH_ALEN);
1163 memcpy(mgmt.bssid, drv->hapd->own_addr, ETH_ALEN);
1164 mgmt.u.disassoc.reason_code = host_to_le16(reason);
1165 return hostap_send_mgmt_frame(drv, &mgmt, IEEE80211_HDRLEN +
1166 sizeof(mgmt.u.disassoc));
1170 static struct hostapd_hw_modes * hostap_get_hw_feature_data(void *priv,
1174 struct hostapd_hw_modes *mode;
1176 const short chan2freq[14] = {
1177 2412, 2417, 2422, 2427, 2432, 2437, 2442,
1178 2447, 2452, 2457, 2462, 2467, 2472, 2484
1181 mode = os_zalloc(sizeof(struct hostapd_hw_modes));
1188 mode->mode = HOSTAPD_MODE_IEEE80211B;
1189 mode->num_channels = 14;
1190 mode->num_rates = 4;
1192 clen = mode->num_channels * sizeof(struct hostapd_channel_data);
1193 rlen = mode->num_rates * sizeof(struct hostapd_rate_data);
1195 mode->channels = os_zalloc(clen);
1196 mode->rates = os_zalloc(rlen);
1197 if (mode->channels == NULL || mode->rates == NULL) {
1198 hostapd_free_hw_features(mode, *num_modes);
1202 for (i = 0; i < 14; i++) {
1203 mode->channels[i].chan = i + 1;
1204 mode->channels[i].freq = chan2freq[i];
1205 /* TODO: Get allowed channel list from the driver */
1207 mode->channels[i].flag = HOSTAPD_CHAN_DISABLED;
1210 mode->rates[0].rate = 10;
1211 mode->rates[0].flags = HOSTAPD_RATE_CCK;
1212 mode->rates[1].rate = 20;
1213 mode->rates[1].flags = HOSTAPD_RATE_CCK;
1214 mode->rates[2].rate = 55;
1215 mode->rates[2].flags = HOSTAPD_RATE_CCK;
1216 mode->rates[3].rate = 110;
1217 mode->rates[3].flags = HOSTAPD_RATE_CCK;
1224 struct wpa_driver_hostap_data {
1225 void *wext; /* private data for driver_wext */
1227 char ifname[IFNAMSIZ + 1];
1229 int current_mode; /* infra/adhoc */
1233 static int hostapd_ioctl(struct wpa_driver_hostap_data *drv,
1234 struct prism2_hostapd_param *param,
1235 int len, int show_err)
1239 os_memset(&iwr, 0, sizeof(iwr));
1240 os_strlcpy(iwr.ifr_name, drv->ifname, IFNAMSIZ);
1241 iwr.u.data.pointer = (caddr_t) param;
1242 iwr.u.data.length = len;
1244 if (ioctl(drv->sock, PRISM2_IOCTL_HOSTAPD, &iwr) < 0) {
1247 perror("ioctl[PRISM2_IOCTL_HOSTAPD]");
1255 static int wpa_driver_hostap_set_wpa_ie(struct wpa_driver_hostap_data *drv,
1256 const u8 *wpa_ie, size_t wpa_ie_len)
1258 struct prism2_hostapd_param *param;
1260 size_t blen = PRISM2_HOSTAPD_GENERIC_ELEMENT_HDR_LEN + wpa_ie_len;
1261 if (blen < sizeof(*param))
1262 blen = sizeof(*param);
1264 param = os_zalloc(blen);
1268 param->cmd = PRISM2_HOSTAPD_SET_GENERIC_ELEMENT;
1269 param->u.generic_elem.len = wpa_ie_len;
1270 os_memcpy(param->u.generic_elem.data, wpa_ie, wpa_ie_len);
1271 res = hostapd_ioctl(drv, param, blen, 1);
1279 static int prism2param(struct wpa_driver_hostap_data *drv, int param,
1285 os_memset(&iwr, 0, sizeof(iwr));
1286 os_strlcpy(iwr.ifr_name, drv->ifname, IFNAMSIZ);
1287 i = (int *) iwr.u.name;
1291 if (ioctl(drv->sock, PRISM2_IOCTL_PRISM2_PARAM, &iwr) < 0) {
1292 perror("ioctl[PRISM2_IOCTL_PRISM2_PARAM]");
1299 static int wpa_driver_hostap_set_wpa(void *priv, int enabled)
1301 struct wpa_driver_hostap_data *drv = priv;
1304 wpa_printf(MSG_DEBUG, "%s: enabled=%d", __FUNCTION__, enabled);
1306 if (!enabled && wpa_driver_hostap_set_wpa_ie(drv, NULL, 0) < 0)
1308 if (prism2param(drv, PRISM2_PARAM_HOST_ROAMING, enabled ? 2 : 0) < 0)
1310 if (prism2param(drv, PRISM2_PARAM_WPA, enabled) < 0)
1317 static void show_set_key_error(struct prism2_hostapd_param *param)
1319 switch (param->u.crypt.err) {
1320 case HOSTAP_CRYPT_ERR_UNKNOWN_ALG:
1321 wpa_printf(MSG_INFO, "Unknown algorithm '%s'.",
1322 param->u.crypt.alg);
1323 wpa_printf(MSG_INFO, "You may need to load kernel module to "
1324 "register that algorithm.");
1325 wpa_printf(MSG_INFO, "E.g., 'modprobe hostap_crypt_wep' for "
1328 case HOSTAP_CRYPT_ERR_UNKNOWN_ADDR:
1329 wpa_printf(MSG_INFO, "Unknown address " MACSTR ".",
1330 MAC2STR(param->sta_addr));
1332 case HOSTAP_CRYPT_ERR_CRYPT_INIT_FAILED:
1333 wpa_printf(MSG_INFO, "Crypt algorithm initialization failed.");
1335 case HOSTAP_CRYPT_ERR_KEY_SET_FAILED:
1336 wpa_printf(MSG_INFO, "Key setting failed.");
1338 case HOSTAP_CRYPT_ERR_TX_KEY_SET_FAILED:
1339 wpa_printf(MSG_INFO, "TX key index setting failed.");
1341 case HOSTAP_CRYPT_ERR_CARD_CONF_FAILED:
1342 wpa_printf(MSG_INFO, "Card configuration failed.");
1348 static int wpa_driver_hostap_set_key(void *priv, wpa_alg alg,
1349 const u8 *addr, int key_idx,
1350 int set_tx, const u8 *seq, size_t seq_len,
1351 const u8 *key, size_t key_len)
1353 struct wpa_driver_hostap_data *drv = priv;
1354 struct prism2_hostapd_param *param;
1377 wpa_printf(MSG_DEBUG, "%s: alg=%s key_idx=%d set_tx=%d seq_len=%lu "
1378 "key_len=%lu", __FUNCTION__, alg_name, key_idx, set_tx,
1379 (unsigned long) seq_len, (unsigned long) key_len);
1384 blen = sizeof(*param) + key_len;
1385 buf = os_zalloc(blen);
1389 param = (struct prism2_hostapd_param *) buf;
1390 param->cmd = PRISM2_SET_ENCRYPTION;
1391 /* TODO: In theory, STA in client mode can use five keys; four default
1392 * keys for receiving (with keyidx 0..3) and one individual key for
1393 * both transmitting and receiving (keyidx 0) _unicast_ packets. Now,
1394 * keyidx 0 is reserved for this unicast use and default keys can only
1395 * use keyidx 1..3 (i.e., default key with keyidx 0 is not supported).
1396 * This should be fine for more or less all cases, but for completeness
1397 * sake, the driver could be enhanced to support the missing key. */
1400 os_memset(param->sta_addr, 0xff, ETH_ALEN);
1402 os_memcpy(param->sta_addr, addr, ETH_ALEN);
1404 os_memset(param->sta_addr, 0xff, ETH_ALEN);
1406 os_strlcpy((char *) param->u.crypt.alg, alg_name,
1407 HOSTAP_CRYPT_ALG_NAME_LEN);
1408 param->u.crypt.flags = set_tx ? HOSTAP_CRYPT_FLAG_SET_TX_KEY : 0;
1409 param->u.crypt.idx = key_idx;
1410 os_memcpy(param->u.crypt.seq, seq, seq_len);
1411 param->u.crypt.key_len = key_len;
1412 os_memcpy((u8 *) (param + 1), key, key_len);
1414 if (hostapd_ioctl(drv, param, blen, 1)) {
1415 wpa_printf(MSG_WARNING, "Failed to set encryption.");
1416 show_set_key_error(param);
1425 static int wpa_driver_hostap_set_countermeasures(void *priv, int enabled)
1427 struct wpa_driver_hostap_data *drv = priv;
1428 wpa_printf(MSG_DEBUG, "%s: enabled=%d", __FUNCTION__, enabled);
1429 return prism2param(drv, PRISM2_PARAM_TKIP_COUNTERMEASURES, enabled);
1433 static int wpa_driver_hostap_set_drop_unencrypted(void *priv, int enabled)
1435 struct wpa_driver_hostap_data *drv = priv;
1436 wpa_printf(MSG_DEBUG, "%s: enabled=%d", __FUNCTION__, enabled);
1437 return prism2param(drv, PRISM2_PARAM_DROP_UNENCRYPTED, enabled);
1441 static int wpa_driver_hostap_reset(struct wpa_driver_hostap_data *drv,
1447 wpa_printf(MSG_DEBUG, "%s: type=%d", __FUNCTION__, type);
1449 os_memset(&iwr, 0, sizeof(iwr));
1450 os_strlcpy(iwr.ifr_name, drv->ifname, IFNAMSIZ);
1451 i = (int *) iwr.u.name;
1454 if (ioctl(drv->sock, PRISM2_IOCTL_RESET, &iwr) < 0) {
1455 perror("ioctl[PRISM2_IOCTL_RESET]");
1462 static int wpa_driver_hostap_mlme(struct wpa_driver_hostap_data *drv,
1463 const u8 *addr, int cmd, int reason_code)
1465 struct prism2_hostapd_param param;
1468 /* There does not seem to be a better way of deauthenticating or
1469 * disassociating with Prism2/2.5/3 than sending the management frame
1470 * and then resetting the Port0 to make sure both the AP and the STA
1471 * end up in disconnected state. */
1472 os_memset(¶m, 0, sizeof(param));
1473 param.cmd = PRISM2_HOSTAPD_MLME;
1474 os_memcpy(param.sta_addr, addr, ETH_ALEN);
1475 param.u.mlme.cmd = cmd;
1476 param.u.mlme.reason_code = reason_code;
1477 ret = hostapd_ioctl(drv, ¶m, sizeof(param), 1);
1479 os_sleep(0, 100000);
1480 ret = wpa_driver_hostap_reset(drv, 2);
1486 static int wpa_driver_hostap_deauthenticate(void *priv, const u8 *addr,
1489 struct wpa_driver_hostap_data *drv = priv;
1490 wpa_printf(MSG_DEBUG, "%s", __FUNCTION__);
1491 return wpa_driver_hostap_mlme(drv, addr, MLME_STA_DEAUTH,
1496 static int wpa_driver_hostap_disassociate(void *priv, const u8 *addr,
1499 struct wpa_driver_hostap_data *drv = priv;
1500 wpa_printf(MSG_DEBUG, "%s", __FUNCTION__);
1501 return wpa_driver_hostap_mlme(drv, addr, MLME_STA_DISASSOC,
1507 wpa_driver_hostap_associate(void *priv,
1508 struct wpa_driver_associate_params *params)
1510 struct wpa_driver_hostap_data *drv = priv;
1512 int allow_unencrypted_eapol;
1514 wpa_printf(MSG_DEBUG, "%s", __FUNCTION__);
1516 if (params->mode != drv->current_mode) {
1517 /* At the moment, Host AP driver requires host_roaming=2 for
1518 * infrastructure mode and host_roaming=0 for adhoc. */
1519 if (prism2param(drv, PRISM2_PARAM_HOST_ROAMING,
1520 params->mode == IEEE80211_MODE_IBSS ? 0 : 2) <
1522 wpa_printf(MSG_DEBUG, "%s: failed to set host_roaming",
1525 drv->current_mode = params->mode;
1528 if (prism2param(drv, PRISM2_PARAM_PRIVACY_INVOKED,
1529 params->key_mgmt_suite != KEY_MGMT_NONE) < 0)
1531 if (wpa_driver_hostap_set_wpa_ie(drv, params->wpa_ie,
1532 params->wpa_ie_len) < 0)
1534 if (wpa_driver_wext_set_mode(drv->wext, params->mode) < 0)
1537 wpa_driver_wext_set_freq(drv->wext, params->freq) < 0)
1539 if (wpa_driver_wext_set_ssid(drv->wext, params->ssid, params->ssid_len)
1542 if (wpa_driver_wext_set_bssid(drv->wext, params->bssid) < 0)
1545 /* Allow unencrypted EAPOL messages even if pairwise keys are set when
1546 * not using WPA. IEEE 802.1X specifies that these frames are not
1547 * encrypted, but WPA encrypts them when pairwise keys are in use. */
1548 if (params->key_mgmt_suite == KEY_MGMT_802_1X ||
1549 params->key_mgmt_suite == KEY_MGMT_PSK)
1550 allow_unencrypted_eapol = 0;
1552 allow_unencrypted_eapol = 1;
1554 if (prism2param(drv, PRISM2_PARAM_IEEE_802_1X,
1555 allow_unencrypted_eapol) < 0) {
1556 wpa_printf(MSG_DEBUG, "hostap: Failed to configure "
1557 "ieee_802_1x param");
1558 /* Ignore this error.. driver_hostap.c can also be used with
1559 * other drivers that do not support this prism2_param. */
1566 static int wpa_driver_hostap_scan(void *priv, const u8 *ssid, size_t ssid_len)
1568 struct wpa_driver_hostap_data *drv = priv;
1569 struct prism2_hostapd_param param;
1573 /* Use standard Linux Wireless Extensions ioctl if possible
1574 * because some drivers using hostap code in wpa_supplicant
1575 * might not support Host AP specific scan request (with SSID
1577 return wpa_driver_wext_scan(drv->wext, ssid, ssid_len);
1583 os_memset(¶m, 0, sizeof(param));
1584 param.cmd = PRISM2_HOSTAPD_SCAN_REQ;
1585 param.u.scan_req.ssid_len = ssid_len;
1586 os_memcpy(param.u.scan_req.ssid, ssid, ssid_len);
1587 ret = hostapd_ioctl(drv, ¶m, sizeof(param), 1);
1589 /* Not all drivers generate "scan completed" wireless event, so try to
1590 * read results after a timeout. */
1591 eloop_cancel_timeout(wpa_driver_wext_scan_timeout, drv->wext,
1593 eloop_register_timeout(3, 0, wpa_driver_wext_scan_timeout, drv->wext,
1600 static int wpa_driver_hostap_set_auth_alg(void *priv, int auth_alg)
1602 struct wpa_driver_hostap_data *drv = priv;
1605 if (auth_alg & AUTH_ALG_OPEN_SYSTEM)
1607 if (auth_alg & AUTH_ALG_SHARED_KEY)
1609 if (auth_alg & AUTH_ALG_LEAP)
1612 algs = 1; /* at least one algorithm should be set */
1614 return prism2param(drv, PRISM2_PARAM_AP_AUTH_ALGS, algs);
1618 static int wpa_driver_hostap_get_bssid(void *priv, u8 *bssid)
1620 struct wpa_driver_hostap_data *drv = priv;
1621 return wpa_driver_wext_get_bssid(drv->wext, bssid);
1625 static int wpa_driver_hostap_get_ssid(void *priv, u8 *ssid)
1627 struct wpa_driver_hostap_data *drv = priv;
1628 return wpa_driver_wext_get_ssid(drv->wext, ssid);
1632 static struct wpa_scan_results * wpa_driver_hostap_get_scan_results(void *priv)
1634 struct wpa_driver_hostap_data *drv = priv;
1635 return wpa_driver_wext_get_scan_results(drv->wext);
1639 static int wpa_driver_hostap_set_operstate(void *priv, int state)
1641 struct wpa_driver_hostap_data *drv = priv;
1642 return wpa_driver_wext_set_operstate(drv->wext, state);
1646 static void * wpa_driver_hostap_init(void *ctx, const char *ifname)
1648 struct wpa_driver_hostap_data *drv;
1650 drv = os_zalloc(sizeof(*drv));
1653 drv->wext = wpa_driver_wext_init(ctx, ifname);
1654 if (drv->wext == NULL) {
1660 os_strlcpy(drv->ifname, ifname, sizeof(drv->ifname));
1661 drv->sock = socket(PF_INET, SOCK_DGRAM, 0);
1662 if (drv->sock < 0) {
1664 wpa_driver_wext_deinit(drv->wext);
1669 if (os_strncmp(ifname, "wlan", 4) == 0) {
1671 * Host AP driver may use both wlan# and wifi# interface in
1674 char ifname2[IFNAMSIZ + 1];
1675 os_strlcpy(ifname2, ifname, sizeof(ifname2));
1676 os_memcpy(ifname2, "wifi", 4);
1677 wpa_driver_wext_alternative_ifindex(drv->wext, ifname2);
1684 static void wpa_driver_hostap_deinit(void *priv)
1686 struct wpa_driver_hostap_data *drv = priv;
1687 wpa_driver_wext_deinit(drv->wext);
1692 #endif /* HOSTAPD */
1695 const struct wpa_driver_ops wpa_driver_hostap_ops = {
1697 .desc = "Host AP driver (Intersil Prism2/2.5/3)",
1699 .hapd_init = hostap_init,
1700 .hapd_deinit = hostap_driver_deinit,
1701 .set_ieee8021x = hostap_set_ieee8021x,
1702 .set_privacy = hostap_set_privacy,
1703 .hapd_set_key = hostap_set_key,
1704 .get_seqnum = hostap_get_seqnum,
1705 .flush = hostap_flush,
1706 .set_generic_elem = hostap_set_generic_elem,
1707 .read_sta_data = hostap_read_sta_data,
1708 .hapd_send_eapol = hostap_send_eapol,
1709 .sta_set_flags = hostap_sta_set_flags,
1710 .sta_deauth = hostap_sta_deauth,
1711 .sta_disassoc = hostap_sta_disassoc,
1712 .sta_remove = hostap_sta_remove,
1713 .hapd_set_ssid = hostap_set_ssid,
1714 .send_mgmt_frame = hostap_send_mgmt_frame,
1715 .sta_add = hostap_sta_add,
1716 .get_inact_sec = hostap_get_inact_sec,
1717 .sta_clear_stats = hostap_sta_clear_stats,
1718 .get_hw_feature_data = hostap_get_hw_feature_data,
1719 .set_wps_beacon_ie = hostap_set_wps_beacon_ie,
1720 .set_wps_probe_resp_ie = hostap_set_wps_probe_resp_ie,
1722 .get_bssid = wpa_driver_hostap_get_bssid,
1723 .get_ssid = wpa_driver_hostap_get_ssid,
1724 .set_wpa = wpa_driver_hostap_set_wpa,
1725 .set_key = wpa_driver_hostap_set_key,
1726 .set_countermeasures = wpa_driver_hostap_set_countermeasures,
1727 .set_drop_unencrypted = wpa_driver_hostap_set_drop_unencrypted,
1728 .scan = wpa_driver_hostap_scan,
1729 .get_scan_results2 = wpa_driver_hostap_get_scan_results,
1730 .deauthenticate = wpa_driver_hostap_deauthenticate,
1731 .disassociate = wpa_driver_hostap_disassociate,
1732 .associate = wpa_driver_hostap_associate,
1733 .set_auth_alg = wpa_driver_hostap_set_auth_alg,
1734 .init = wpa_driver_hostap_init,
1735 .deinit = wpa_driver_hostap_deinit,
1736 .set_operstate = wpa_driver_hostap_set_operstate,
1737 #endif /* HOSTAPD */