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/hw_features.h"
35 #include "../../hostapd/sta_flags.h"
38 static const u8 rfc1042_header[6] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
40 struct hostap_driver_data {
41 struct hostapd_data *hapd;
43 char iface[IFNAMSIZ + 1];
44 int sock; /* raw packet socket for driver access */
45 int ioctl_sock; /* socket for ioctl() use */
46 int wext_sock; /* socket for wireless events */
51 size_t generic_ie_len;
57 static int hostapd_ioctl(void *priv, struct prism2_hostapd_param *param,
59 static int hostap_set_iface_flags(void *priv, int dev_up);
60 static int hostap_sta_disassoc(void *priv, const u8 *addr, int reason);
61 static int hostap_sta_deauth(void *priv, const u8 *addr, int reason);
63 static void handle_data(struct hostap_driver_data *drv, u8 *buf, size_t len,
66 struct ieee80211_hdr *hdr;
71 if (len < sizeof(struct ieee80211_hdr))
74 hdr = (struct ieee80211_hdr *) buf;
75 fc = le_to_host16(hdr->frame_control);
77 if ((fc & (WLAN_FC_FROMDS | WLAN_FC_TODS)) != WLAN_FC_TODS) {
78 printf("Not ToDS data frame (fc=0x%04x)\n", fc);
83 hostapd_rx_from_unknown_sta(drv->hapd, sa);
85 pos = (u8 *) (hdr + 1);
86 left = len - sizeof(*hdr);
88 if (left < sizeof(rfc1042_header)) {
89 printf("Too short data frame\n");
93 if (memcmp(pos, rfc1042_header, sizeof(rfc1042_header)) != 0) {
94 printf("Data frame with no RFC1042 header\n");
97 pos += sizeof(rfc1042_header);
98 left -= sizeof(rfc1042_header);
101 printf("No ethertype in data frame\n");
105 ethertype = WPA_GET_BE16(pos);
110 hostapd_eapol_receive(drv->hapd, sa, pos, left);
114 printf("Unknown ethertype 0x%04x in data frame\n", ethertype);
120 static void handle_tx_callback(struct hostap_driver_data *drv, u8 *buf,
123 struct ieee80211_hdr *hdr;
126 hdr = (struct ieee80211_hdr *) buf;
127 fc = le_to_host16(hdr->frame_control);
129 type = WLAN_FC_GET_TYPE(fc);
130 stype = WLAN_FC_GET_STYPE(fc);
133 case WLAN_FC_TYPE_MGMT:
134 wpa_printf(MSG_DEBUG, "MGMT (TX callback) %s",
135 ok ? "ACK" : "fail");
136 hostapd_mgmt_tx_cb(drv->hapd, buf, len, stype, ok);
138 case WLAN_FC_TYPE_CTRL:
139 wpa_printf(MSG_DEBUG, "CTRL (TX callback) %s",
140 ok ? "ACK" : "fail");
142 case WLAN_FC_TYPE_DATA:
143 wpa_printf(MSG_DEBUG, "DATA (TX callback) %s",
144 ok ? "ACK" : "fail");
145 hostapd_tx_status(drv->hapd, hdr->addr1, buf, len, ok);
148 printf("unknown TX callback frame type %d\n", type);
154 static void handle_frame(struct hostap_driver_data *drv, u8 *buf, size_t len)
156 struct ieee80211_hdr *hdr;
157 u16 fc, extra_len, type, stype;
158 unsigned char *extra = NULL;
159 size_t data_len = len;
162 /* PSPOLL is only 16 bytes, but driver does not (at least yet) pass
163 * these to user space */
165 wpa_printf(MSG_MSGDUMP, "handle_frame: too short (%lu)",
166 (unsigned long) len);
170 hdr = (struct ieee80211_hdr *) buf;
171 fc = le_to_host16(hdr->frame_control);
172 type = WLAN_FC_GET_TYPE(fc);
173 stype = WLAN_FC_GET_STYPE(fc);
175 if (type != WLAN_FC_TYPE_MGMT || stype != WLAN_FC_STYPE_BEACON) {
176 wpa_hexdump(MSG_MSGDUMP, "Received management frame",
180 ver = fc & WLAN_FC_PVER;
182 /* protocol version 3 is reserved for indicating extra data after the
183 * payload, version 2 for indicating ACKed frame (TX callbacks), and
184 * version 1 for indicating failed frame (no ACK, TX callbacks) */
186 u8 *pos = buf + len - 2;
187 extra_len = WPA_GET_LE16(pos);
188 printf("extra data in frame (elen=%d)\n", extra_len);
189 if ((size_t) extra_len + 2 > len) {
190 printf(" extra data overflow\n");
193 len -= extra_len + 2;
195 } else if (ver == 1 || ver == 2) {
196 handle_tx_callback(drv, buf, data_len, ver == 2 ? 1 : 0);
198 } else if (ver != 0) {
199 printf("unknown protocol version %d\n", ver);
204 case WLAN_FC_TYPE_MGMT:
205 if (stype != WLAN_FC_STYPE_BEACON)
206 wpa_printf(MSG_MSGDUMP, "MGMT");
207 hostapd_mgmt_rx(drv->hapd, buf, data_len, stype, NULL);
209 case WLAN_FC_TYPE_CTRL:
210 wpa_printf(MSG_DEBUG, "CTRL");
212 case WLAN_FC_TYPE_DATA:
213 wpa_printf(MSG_DEBUG, "DATA");
214 handle_data(drv, buf, data_len, stype);
217 wpa_printf(MSG_DEBUG, "unknown frame type %d", type);
223 static void handle_read(int sock, void *eloop_ctx, void *sock_ctx)
225 struct hostap_driver_data *drv = eloop_ctx;
227 unsigned char buf[3000];
229 len = recv(sock, buf, sizeof(buf), 0);
235 handle_frame(drv, buf, len);
239 static int hostap_init_sockets(struct hostap_driver_data *drv)
242 struct sockaddr_ll addr;
244 drv->sock = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
246 perror("socket[PF_PACKET,SOCK_RAW]");
250 if (eloop_register_read_sock(drv->sock, handle_read, drv, NULL)) {
251 printf("Could not register read socket\n");
255 memset(&ifr, 0, sizeof(ifr));
256 snprintf(ifr.ifr_name, sizeof(ifr.ifr_name), "%sap", drv->iface);
257 if (ioctl(drv->sock, SIOCGIFINDEX, &ifr) != 0) {
258 perror("ioctl(SIOCGIFINDEX)");
262 if (hostap_set_iface_flags(drv, 1)) {
266 memset(&addr, 0, sizeof(addr));
267 addr.sll_family = AF_PACKET;
268 addr.sll_ifindex = ifr.ifr_ifindex;
269 wpa_printf(MSG_DEBUG, "Opening raw packet socket for ifindex %d",
272 if (bind(drv->sock, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
277 memset(&ifr, 0, sizeof(ifr));
278 os_strlcpy(ifr.ifr_name, drv->iface, sizeof(ifr.ifr_name));
279 if (ioctl(drv->sock, SIOCGIFHWADDR, &ifr) != 0) {
280 perror("ioctl(SIOCGIFHWADDR)");
284 if (ifr.ifr_hwaddr.sa_family != ARPHRD_ETHER) {
285 printf("Invalid HW-addr family 0x%04x\n",
286 ifr.ifr_hwaddr.sa_family);
289 memcpy(drv->hapd->own_addr, ifr.ifr_hwaddr.sa_data, ETH_ALEN);
295 static int hostap_send_mlme(void *priv, const u8 *msg, size_t len)
297 struct hostap_driver_data *drv = priv;
298 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) msg;
301 /* Request TX callback */
302 hdr->frame_control |= host_to_le16(BIT(1));
303 res = send(drv->sock, msg, len, 0);
304 hdr->frame_control &= ~host_to_le16(BIT(1));
310 static int hostap_send_eapol(void *priv, const u8 *addr, const u8 *data,
311 size_t data_len, int encrypt, const u8 *own_addr)
313 struct hostap_driver_data *drv = priv;
314 struct ieee80211_hdr *hdr;
319 len = sizeof(*hdr) + sizeof(rfc1042_header) + 2 + data_len;
320 hdr = os_zalloc(len);
322 printf("malloc() failed for hostapd_send_data(len=%lu)\n",
323 (unsigned long) len);
328 IEEE80211_FC(WLAN_FC_TYPE_DATA, WLAN_FC_STYPE_DATA);
329 hdr->frame_control |= host_to_le16(WLAN_FC_FROMDS);
331 hdr->frame_control |= host_to_le16(WLAN_FC_ISWEP);
332 memcpy(hdr->IEEE80211_DA_FROMDS, addr, ETH_ALEN);
333 memcpy(hdr->IEEE80211_BSSID_FROMDS, own_addr, ETH_ALEN);
334 memcpy(hdr->IEEE80211_SA_FROMDS, own_addr, ETH_ALEN);
336 pos = (u8 *) (hdr + 1);
337 memcpy(pos, rfc1042_header, sizeof(rfc1042_header));
338 pos += sizeof(rfc1042_header);
339 *((u16 *) pos) = htons(ETH_P_PAE);
341 memcpy(pos, data, data_len);
343 res = hostap_send_mlme(drv, (u8 *) hdr, len);
345 wpa_printf(MSG_ERROR, "hostap_send_eapol - packet len: %lu - "
347 (unsigned long) len, errno, strerror(errno));
355 static int hostap_sta_set_flags(void *priv, const u8 *addr,
356 int total_flags, int flags_or, int flags_and)
358 struct hostap_driver_data *drv = priv;
359 struct prism2_hostapd_param param;
361 memset(¶m, 0, sizeof(param));
362 param.cmd = PRISM2_HOSTAPD_SET_FLAGS_STA;
363 memcpy(param.sta_addr, addr, ETH_ALEN);
364 param.u.set_flags_sta.flags_or = flags_or;
365 param.u.set_flags_sta.flags_and = flags_and;
366 return hostapd_ioctl(drv, ¶m, sizeof(param));
370 static int hostap_set_iface_flags(void *priv, int dev_up)
372 struct hostap_driver_data *drv = priv;
375 if (drv->ioctl_sock < 0)
378 memset(&ifr, 0, sizeof(ifr));
379 snprintf(ifr.ifr_name, IFNAMSIZ, "%sap", drv->iface);
381 if (ioctl(drv->ioctl_sock, SIOCGIFFLAGS, &ifr) != 0) {
382 perror("ioctl[SIOCGIFFLAGS]");
387 ifr.ifr_flags |= IFF_UP;
389 ifr.ifr_flags &= ~IFF_UP;
391 if (ioctl(drv->ioctl_sock, SIOCSIFFLAGS, &ifr) != 0) {
392 perror("ioctl[SIOCSIFFLAGS]");
397 memset(&ifr, 0, sizeof(ifr));
398 snprintf(ifr.ifr_name, IFNAMSIZ, "%sap", drv->iface);
399 ifr.ifr_mtu = HOSTAPD_MTU;
400 if (ioctl(drv->ioctl_sock, SIOCSIFMTU, &ifr) != 0) {
401 perror("ioctl[SIOCSIFMTU]");
402 printf("Setting MTU failed - trying to survive with "
411 static int hostapd_ioctl(void *priv, struct prism2_hostapd_param *param,
414 struct hostap_driver_data *drv = priv;
417 memset(&iwr, 0, sizeof(iwr));
418 os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
419 iwr.u.data.pointer = (caddr_t) param;
420 iwr.u.data.length = len;
422 if (ioctl(drv->ioctl_sock, PRISM2_IOCTL_HOSTAPD, &iwr) < 0) {
423 perror("ioctl[PRISM2_IOCTL_HOSTAPD]");
431 static int hostap_set_key(const char *ifname, void *priv, wpa_alg alg,
432 const u8 *addr, int key_idx, int set_tx,
433 const u8 *seq, size_t seq_len, const u8 *key,
436 struct hostap_driver_data *drv = priv;
437 struct prism2_hostapd_param *param;
442 blen = sizeof(*param) + key_len;
443 buf = os_zalloc(blen);
447 param = (struct prism2_hostapd_param *) buf;
448 param->cmd = PRISM2_SET_ENCRYPTION;
450 memset(param->sta_addr, 0xff, ETH_ALEN);
452 memcpy(param->sta_addr, addr, ETH_ALEN);
455 os_strlcpy((char *) param->u.crypt.alg, "NONE",
456 HOSTAP_CRYPT_ALG_NAME_LEN);
459 os_strlcpy((char *) param->u.crypt.alg, "WEP",
460 HOSTAP_CRYPT_ALG_NAME_LEN);
463 os_strlcpy((char *) param->u.crypt.alg, "TKIP",
464 HOSTAP_CRYPT_ALG_NAME_LEN);
467 os_strlcpy((char *) param->u.crypt.alg, "CCMP",
468 HOSTAP_CRYPT_ALG_NAME_LEN);
474 param->u.crypt.flags = set_tx ? HOSTAP_CRYPT_FLAG_SET_TX_KEY : 0;
475 param->u.crypt.idx = key_idx;
476 param->u.crypt.key_len = key_len;
477 memcpy((u8 *) (param + 1), key, key_len);
479 if (hostapd_ioctl(drv, param, blen)) {
480 printf("Failed to set encryption.\n");
489 static int hostap_get_seqnum(const char *ifname, void *priv, const u8 *addr,
492 struct hostap_driver_data *drv = priv;
493 struct prism2_hostapd_param *param;
498 blen = sizeof(*param) + 32;
499 buf = os_zalloc(blen);
503 param = (struct prism2_hostapd_param *) buf;
504 param->cmd = PRISM2_GET_ENCRYPTION;
506 memset(param->sta_addr, 0xff, ETH_ALEN);
508 memcpy(param->sta_addr, addr, ETH_ALEN);
509 param->u.crypt.idx = idx;
511 if (hostapd_ioctl(drv, param, blen)) {
512 printf("Failed to get encryption.\n");
515 memcpy(seq, param->u.crypt.seq, 8);
523 static int hostap_ioctl_prism2param(void *priv, int param, int value)
525 struct hostap_driver_data *drv = priv;
529 memset(&iwr, 0, sizeof(iwr));
530 os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
531 i = (int *) iwr.u.name;
535 if (ioctl(drv->ioctl_sock, PRISM2_IOCTL_PRISM2_PARAM, &iwr) < 0) {
536 perror("ioctl[PRISM2_IOCTL_PRISM2_PARAM]");
544 static int hostap_set_ieee8021x(const char *ifname, void *priv, int enabled)
546 struct hostap_driver_data *drv = priv;
548 /* enable kernel driver support for IEEE 802.1X */
549 if (hostap_ioctl_prism2param(drv, PRISM2_PARAM_IEEE_802_1X, enabled)) {
550 printf("Could not setup IEEE 802.1X support in kernel driver."
558 /* use host driver implementation of encryption to allow
559 * individual keys and passing plaintext EAPOL frames */
560 if (hostap_ioctl_prism2param(drv, PRISM2_PARAM_HOST_DECRYPT, 1) ||
561 hostap_ioctl_prism2param(drv, PRISM2_PARAM_HOST_ENCRYPT, 1)) {
562 printf("Could not setup host-based encryption in kernel "
571 static int hostap_set_privacy(const char *ifname, void *priv, int enabled)
573 struct hostap_drvier_data *drv = priv;
575 return hostap_ioctl_prism2param(drv, PRISM2_PARAM_PRIVACY_INVOKED,
580 static int hostap_set_ssid(const char *ifname, void *priv, const u8 *buf,
583 struct hostap_driver_data *drv = priv;
586 memset(&iwr, 0, sizeof(iwr));
587 os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
588 iwr.u.essid.flags = 1; /* SSID active */
589 iwr.u.essid.pointer = (caddr_t) buf;
590 iwr.u.essid.length = len + 1;
592 if (ioctl(drv->ioctl_sock, SIOCSIWESSID, &iwr) < 0) {
593 perror("ioctl[SIOCSIWESSID]");
594 printf("len=%d\n", len);
602 static int hostap_flush(void *priv)
604 struct hostap_driver_data *drv = priv;
605 struct prism2_hostapd_param param;
607 memset(¶m, 0, sizeof(param));
608 param.cmd = PRISM2_HOSTAPD_FLUSH;
609 return hostapd_ioctl(drv, ¶m, sizeof(param));
613 static int hostap_read_sta_data(void *priv,
614 struct hostap_sta_driver_data *data,
617 struct hostap_driver_data *drv = priv;
618 char buf[1024], line[128], *pos;
622 memset(data, 0, sizeof(*data));
623 snprintf(buf, sizeof(buf), "/proc/net/hostap/%s/" MACSTR,
624 drv->iface, MAC2STR(addr));
629 /* Need to read proc file with in one piece, so use large enough
631 setbuffer(f, buf, sizeof(buf));
633 while (fgets(line, sizeof(line), f)) {
634 pos = strchr(line, '=');
638 val = strtoul(pos, NULL, 10);
639 if (strcmp(line, "rx_packets") == 0)
640 data->rx_packets = val;
641 else if (strcmp(line, "tx_packets") == 0)
642 data->tx_packets = val;
643 else if (strcmp(line, "rx_bytes") == 0)
644 data->rx_bytes = val;
645 else if (strcmp(line, "tx_bytes") == 0)
646 data->tx_bytes = val;
655 static int hostap_sta_add(const char *ifname, void *priv,
656 struct hostapd_sta_add_params *params)
658 struct hostap_driver_data *drv = priv;
659 struct prism2_hostapd_param param;
660 int tx_supp_rates = 0;
663 #define WLAN_RATE_1M BIT(0)
664 #define WLAN_RATE_2M BIT(1)
665 #define WLAN_RATE_5M5 BIT(2)
666 #define WLAN_RATE_11M BIT(3)
668 for (i = 0; i < params->supp_rates_len; i++) {
669 if ((params->supp_rates[i] & 0x7f) == 2)
670 tx_supp_rates |= WLAN_RATE_1M;
671 if ((params->supp_rates[i] & 0x7f) == 4)
672 tx_supp_rates |= WLAN_RATE_2M;
673 if ((params->supp_rates[i] & 0x7f) == 11)
674 tx_supp_rates |= WLAN_RATE_5M5;
675 if ((params->supp_rates[i] & 0x7f) == 22)
676 tx_supp_rates |= WLAN_RATE_11M;
679 memset(¶m, 0, sizeof(param));
680 param.cmd = PRISM2_HOSTAPD_ADD_STA;
681 memcpy(param.sta_addr, params->addr, ETH_ALEN);
682 param.u.add_sta.aid = params->aid;
683 param.u.add_sta.capability = params->capability;
684 param.u.add_sta.tx_supp_rates = tx_supp_rates;
685 return hostapd_ioctl(drv, ¶m, sizeof(param));
689 static int hostap_sta_remove(void *priv, const u8 *addr)
691 struct hostap_driver_data *drv = priv;
692 struct prism2_hostapd_param param;
694 hostap_sta_set_flags(drv, addr, 0, 0, ~WLAN_STA_AUTHORIZED);
696 memset(¶m, 0, sizeof(param));
697 param.cmd = PRISM2_HOSTAPD_REMOVE_STA;
698 memcpy(param.sta_addr, addr, ETH_ALEN);
699 if (hostapd_ioctl(drv, ¶m, sizeof(param))) {
700 printf("Could not remove station from kernel driver.\n");
707 static int hostap_get_inact_sec(void *priv, const u8 *addr)
709 struct hostap_driver_data *drv = priv;
710 struct prism2_hostapd_param param;
712 memset(¶m, 0, sizeof(param));
713 param.cmd = PRISM2_HOSTAPD_GET_INFO_STA;
714 memcpy(param.sta_addr, addr, ETH_ALEN);
715 if (hostapd_ioctl(drv, ¶m, sizeof(param))) {
719 return param.u.get_info_sta.inactive_sec;
723 static int hostap_sta_clear_stats(void *priv, const u8 *addr)
725 struct hostap_driver_data *drv = priv;
726 struct prism2_hostapd_param param;
728 memset(¶m, 0, sizeof(param));
729 param.cmd = PRISM2_HOSTAPD_STA_CLEAR_STATS;
730 memcpy(param.sta_addr, addr, ETH_ALEN);
731 if (hostapd_ioctl(drv, ¶m, sizeof(param))) {
739 static int hostapd_ioctl_set_generic_elem(struct hostap_driver_data *drv)
741 struct prism2_hostapd_param *param;
743 size_t blen, elem_len;
745 elem_len = drv->generic_ie_len + drv->wps_ie_len;
746 blen = PRISM2_HOSTAPD_GENERIC_ELEMENT_HDR_LEN + elem_len;
747 if (blen < sizeof(*param))
748 blen = sizeof(*param);
750 param = os_zalloc(blen);
754 param->cmd = PRISM2_HOSTAPD_SET_GENERIC_ELEMENT;
755 param->u.generic_elem.len = elem_len;
756 if (drv->generic_ie) {
757 os_memcpy(param->u.generic_elem.data, drv->generic_ie,
758 drv->generic_ie_len);
761 os_memcpy(¶m->u.generic_elem.data[drv->generic_ie_len],
762 drv->wps_ie, drv->wps_ie_len);
764 wpa_hexdump(MSG_DEBUG, "hostap: Set generic IE",
765 param->u.generic_elem.data, elem_len);
766 res = hostapd_ioctl(drv, param, blen);
774 static int hostap_set_generic_elem(const char *ifname, void *priv,
775 const u8 *elem, size_t elem_len)
777 struct hostap_driver_data *drv = priv;
779 os_free(drv->generic_ie);
780 drv->generic_ie = NULL;
781 drv->generic_ie_len = 0;
783 drv->generic_ie = os_malloc(elem_len);
784 if (drv->generic_ie == NULL)
786 os_memcpy(drv->generic_ie, elem, elem_len);
787 drv->generic_ie_len = elem_len;
790 return hostapd_ioctl_set_generic_elem(drv);
794 static int hostap_set_wps_beacon_ie(const char *ifname, void *priv,
795 const u8 *ie, size_t len)
797 /* Host AP driver supports only one set of extra IEs, so we need to
798 * use the ProbeResp IEs also for Beacon frames since they include more
804 static int hostap_set_wps_probe_resp_ie(const char *ifname, void *priv,
805 const u8 *ie, size_t len)
807 struct hostap_driver_data *drv = priv;
809 os_free(drv->wps_ie);
813 drv->wps_ie = os_malloc(len);
814 if (drv->wps_ie == NULL)
816 os_memcpy(drv->wps_ie, ie, len);
817 drv->wps_ie_len = len;
820 return hostapd_ioctl_set_generic_elem(drv);
825 hostapd_wireless_event_wireless_custom(struct hostap_driver_data *drv,
828 wpa_printf(MSG_DEBUG, "Custom wireless event: '%s'", custom);
830 if (strncmp(custom, "MLME-MICHAELMICFAILURE.indication", 33) == 0) {
833 pos = strstr(custom, "addr=");
835 wpa_printf(MSG_DEBUG,
836 "MLME-MICHAELMICFAILURE.indication "
837 "without sender address ignored");
841 if (hwaddr_aton(pos, addr) == 0) {
842 hostapd_michael_mic_failure(drv->hapd, addr);
844 wpa_printf(MSG_DEBUG,
845 "MLME-MICHAELMICFAILURE.indication "
846 "with invalid MAC address");
852 static void hostapd_wireless_event_wireless(struct hostap_driver_data *drv,
855 struct iw_event iwe_buf, *iwe = &iwe_buf;
856 char *pos, *end, *custom, *buf;
861 while (pos + IW_EV_LCP_LEN <= end) {
862 /* Event data may be unaligned, so make a local, aligned copy
863 * before processing. */
864 memcpy(&iwe_buf, pos, IW_EV_LCP_LEN);
865 wpa_printf(MSG_DEBUG, "Wireless event: cmd=0x%x len=%d",
867 if (iwe->len <= IW_EV_LCP_LEN)
870 custom = pos + IW_EV_POINT_LEN;
871 if (drv->we_version > 18 &&
872 (iwe->cmd == IWEVMICHAELMICFAILURE ||
873 iwe->cmd == IWEVCUSTOM)) {
874 /* WE-19 removed the pointer from struct iw_point */
875 char *dpos = (char *) &iwe_buf.u.data.length;
876 int dlen = dpos - (char *) &iwe_buf;
877 memcpy(dpos, pos + IW_EV_LCP_LEN,
878 sizeof(struct iw_event) - dlen);
880 memcpy(&iwe_buf, pos, sizeof(struct iw_event));
881 custom += IW_EV_POINT_OFF;
886 if (custom + iwe->u.data.length > end)
888 buf = malloc(iwe->u.data.length + 1);
891 memcpy(buf, custom, iwe->u.data.length);
892 buf[iwe->u.data.length] = '\0';
893 hostapd_wireless_event_wireless_custom(drv, buf);
903 static void hostapd_wireless_event_rtm_newlink(struct hostap_driver_data *drv,
904 struct nlmsghdr *h, int len)
906 struct ifinfomsg *ifi;
907 int attrlen, nlmsg_len, rta_len;
908 struct rtattr * attr;
910 if (len < (int) sizeof(*ifi))
915 /* TODO: use ifi->ifi_index to filter out wireless events from other
918 nlmsg_len = NLMSG_ALIGN(sizeof(struct ifinfomsg));
920 attrlen = h->nlmsg_len - nlmsg_len;
924 attr = (struct rtattr *) (((char *) ifi) + nlmsg_len);
926 rta_len = RTA_ALIGN(sizeof(struct rtattr));
927 while (RTA_OK(attr, attrlen)) {
928 if (attr->rta_type == IFLA_WIRELESS) {
929 hostapd_wireless_event_wireless(
930 drv, ((char *) attr) + rta_len,
931 attr->rta_len - rta_len);
933 attr = RTA_NEXT(attr, attrlen);
938 static void hostapd_wireless_event_receive(int sock, void *eloop_ctx,
943 struct sockaddr_nl from;
946 struct hostap_driver_data *drv = eloop_ctx;
948 fromlen = sizeof(from);
949 left = recvfrom(sock, buf, sizeof(buf), MSG_DONTWAIT,
950 (struct sockaddr *) &from, &fromlen);
952 if (errno != EINTR && errno != EAGAIN)
953 perror("recvfrom(netlink)");
957 h = (struct nlmsghdr *) buf;
958 while (left >= (int) sizeof(*h)) {
962 plen = len - sizeof(*h);
963 if (len > left || plen < 0) {
964 printf("Malformed netlink message: "
965 "len=%d left=%d plen=%d\n",
970 switch (h->nlmsg_type) {
972 hostapd_wireless_event_rtm_newlink(drv, h, plen);
976 len = NLMSG_ALIGN(len);
978 h = (struct nlmsghdr *) ((char *) h + len);
982 printf("%d extra bytes in the end of netlink message\n", left);
987 static int hostap_get_we_version(struct hostap_driver_data *drv)
989 struct iw_range *range;
997 * Use larger buffer than struct iw_range in order to allow the
998 * structure to grow in the future.
1000 buflen = sizeof(struct iw_range) + 500;
1001 range = os_zalloc(buflen);
1005 memset(&iwr, 0, sizeof(iwr));
1006 os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
1007 iwr.u.data.pointer = (caddr_t) range;
1008 iwr.u.data.length = buflen;
1010 minlen = ((char *) &range->enc_capa) - (char *) range +
1011 sizeof(range->enc_capa);
1013 if (ioctl(drv->ioctl_sock, SIOCGIWRANGE, &iwr) < 0) {
1014 perror("ioctl[SIOCGIWRANGE]");
1017 } else if (iwr.u.data.length >= minlen &&
1018 range->we_version_compiled >= 18) {
1019 wpa_printf(MSG_DEBUG, "SIOCGIWRANGE: WE(compiled)=%d "
1020 "WE(source)=%d enc_capa=0x%x",
1021 range->we_version_compiled,
1022 range->we_version_source,
1024 drv->we_version = range->we_version_compiled;
1032 static int hostap_wireless_event_init(struct hostap_driver_data *drv)
1035 struct sockaddr_nl local;
1037 hostap_get_we_version(drv);
1039 drv->wext_sock = -1;
1041 s = socket(PF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
1043 perror("socket(PF_NETLINK,SOCK_RAW,NETLINK_ROUTE)");
1047 memset(&local, 0, sizeof(local));
1048 local.nl_family = AF_NETLINK;
1049 local.nl_groups = RTMGRP_LINK;
1050 if (bind(s, (struct sockaddr *) &local, sizeof(local)) < 0) {
1051 perror("bind(netlink)");
1056 eloop_register_read_sock(s, hostapd_wireless_event_receive, drv,
1064 static void hostap_wireless_event_deinit(struct hostap_driver_data *drv)
1066 if (drv->wext_sock < 0)
1068 eloop_unregister_read_sock(drv->wext_sock);
1069 close(drv->wext_sock);
1073 static void * hostap_init(struct hostapd_data *hapd,
1074 struct wpa_init_params *params)
1076 struct hostap_driver_data *drv;
1078 drv = os_zalloc(sizeof(struct hostap_driver_data));
1080 printf("Could not allocate memory for hostapd driver data\n");
1085 drv->ioctl_sock = drv->sock = -1;
1086 memcpy(drv->iface, params->ifname, sizeof(drv->iface));
1088 drv->ioctl_sock = socket(PF_INET, SOCK_DGRAM, 0);
1089 if (drv->ioctl_sock < 0) {
1090 perror("socket[PF_INET,SOCK_DGRAM]");
1095 if (hostap_ioctl_prism2param(drv, PRISM2_PARAM_HOSTAPD, 1)) {
1096 printf("Could not enable hostapd mode for interface %s\n",
1098 close(drv->ioctl_sock);
1103 if (hostap_init_sockets(drv) || hostap_wireless_event_init(drv)) {
1104 close(drv->ioctl_sock);
1113 static void hostap_driver_deinit(void *priv)
1115 struct hostap_driver_data *drv = priv;
1117 hostap_wireless_event_deinit(drv);
1118 (void) hostap_set_iface_flags(drv, 0);
1119 (void) hostap_ioctl_prism2param(drv, PRISM2_PARAM_HOSTAPD, 0);
1120 (void) hostap_ioctl_prism2param(drv, PRISM2_PARAM_HOSTAPD_STA, 0);
1122 if (drv->ioctl_sock >= 0)
1123 close(drv->ioctl_sock);
1128 os_free(drv->generic_ie);
1129 os_free(drv->wps_ie);
1135 static int hostap_sta_deauth(void *priv, const u8 *addr, int reason)
1137 struct hostap_driver_data *drv = priv;
1138 struct ieee80211_mgmt mgmt;
1140 memset(&mgmt, 0, sizeof(mgmt));
1141 mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
1142 WLAN_FC_STYPE_DEAUTH);
1143 memcpy(mgmt.da, addr, ETH_ALEN);
1144 memcpy(mgmt.sa, drv->hapd->own_addr, ETH_ALEN);
1145 memcpy(mgmt.bssid, drv->hapd->own_addr, ETH_ALEN);
1146 mgmt.u.deauth.reason_code = host_to_le16(reason);
1147 return hostap_send_mlme(drv, (u8 *) &mgmt, IEEE80211_HDRLEN +
1148 sizeof(mgmt.u.deauth));
1152 static int hostap_sta_disassoc(void *priv, const u8 *addr, int reason)
1154 struct hostap_driver_data *drv = priv;
1155 struct ieee80211_mgmt mgmt;
1157 memset(&mgmt, 0, sizeof(mgmt));
1158 mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
1159 WLAN_FC_STYPE_DISASSOC);
1160 memcpy(mgmt.da, addr, ETH_ALEN);
1161 memcpy(mgmt.sa, drv->hapd->own_addr, ETH_ALEN);
1162 memcpy(mgmt.bssid, drv->hapd->own_addr, ETH_ALEN);
1163 mgmt.u.disassoc.reason_code = host_to_le16(reason);
1164 return hostap_send_mlme(drv, (u8 *) &mgmt, IEEE80211_HDRLEN +
1165 sizeof(mgmt.u.disassoc));
1169 static struct hostapd_hw_modes * hostap_get_hw_feature_data(void *priv,
1173 struct hostapd_hw_modes *mode;
1175 const short chan2freq[14] = {
1176 2412, 2417, 2422, 2427, 2432, 2437, 2442,
1177 2447, 2452, 2457, 2462, 2467, 2472, 2484
1180 mode = os_zalloc(sizeof(struct hostapd_hw_modes));
1187 mode->mode = HOSTAPD_MODE_IEEE80211B;
1188 mode->num_channels = 14;
1189 mode->num_rates = 4;
1191 clen = mode->num_channels * sizeof(struct hostapd_channel_data);
1192 rlen = mode->num_rates * sizeof(struct hostapd_rate_data);
1194 mode->channels = os_zalloc(clen);
1195 mode->rates = os_zalloc(rlen);
1196 if (mode->channels == NULL || mode->rates == NULL) {
1197 hostapd_free_hw_features(mode, *num_modes);
1201 for (i = 0; i < 14; i++) {
1202 mode->channels[i].chan = i + 1;
1203 mode->channels[i].freq = chan2freq[i];
1204 /* TODO: Get allowed channel list from the driver */
1206 mode->channels[i].flag = HOSTAPD_CHAN_DISABLED;
1209 mode->rates[0].rate = 10;
1210 mode->rates[0].flags = HOSTAPD_RATE_CCK;
1211 mode->rates[1].rate = 20;
1212 mode->rates[1].flags = HOSTAPD_RATE_CCK;
1213 mode->rates[2].rate = 55;
1214 mode->rates[2].flags = HOSTAPD_RATE_CCK;
1215 mode->rates[3].rate = 110;
1216 mode->rates[3].flags = HOSTAPD_RATE_CCK;
1223 struct wpa_driver_hostap_data {
1224 void *wext; /* private data for driver_wext */
1226 char ifname[IFNAMSIZ + 1];
1228 int current_mode; /* infra/adhoc */
1232 static int hostapd_ioctl(struct wpa_driver_hostap_data *drv,
1233 struct prism2_hostapd_param *param,
1234 int len, int show_err)
1238 os_memset(&iwr, 0, sizeof(iwr));
1239 os_strlcpy(iwr.ifr_name, drv->ifname, IFNAMSIZ);
1240 iwr.u.data.pointer = (caddr_t) param;
1241 iwr.u.data.length = len;
1243 if (ioctl(drv->sock, PRISM2_IOCTL_HOSTAPD, &iwr) < 0) {
1246 perror("ioctl[PRISM2_IOCTL_HOSTAPD]");
1254 static int wpa_driver_hostap_set_wpa_ie(struct wpa_driver_hostap_data *drv,
1255 const u8 *wpa_ie, size_t wpa_ie_len)
1257 struct prism2_hostapd_param *param;
1259 size_t blen = PRISM2_HOSTAPD_GENERIC_ELEMENT_HDR_LEN + wpa_ie_len;
1260 if (blen < sizeof(*param))
1261 blen = sizeof(*param);
1263 param = os_zalloc(blen);
1267 param->cmd = PRISM2_HOSTAPD_SET_GENERIC_ELEMENT;
1268 param->u.generic_elem.len = wpa_ie_len;
1269 os_memcpy(param->u.generic_elem.data, wpa_ie, wpa_ie_len);
1270 res = hostapd_ioctl(drv, param, blen, 1);
1278 static int prism2param(struct wpa_driver_hostap_data *drv, int param,
1284 os_memset(&iwr, 0, sizeof(iwr));
1285 os_strlcpy(iwr.ifr_name, drv->ifname, IFNAMSIZ);
1286 i = (int *) iwr.u.name;
1290 if (ioctl(drv->sock, PRISM2_IOCTL_PRISM2_PARAM, &iwr) < 0) {
1291 perror("ioctl[PRISM2_IOCTL_PRISM2_PARAM]");
1298 static int wpa_driver_hostap_set_wpa(void *priv, int enabled)
1300 struct wpa_driver_hostap_data *drv = priv;
1303 wpa_printf(MSG_DEBUG, "%s: enabled=%d", __FUNCTION__, enabled);
1305 if (!enabled && wpa_driver_hostap_set_wpa_ie(drv, NULL, 0) < 0)
1307 if (prism2param(drv, PRISM2_PARAM_HOST_ROAMING, enabled ? 2 : 0) < 0)
1309 if (prism2param(drv, PRISM2_PARAM_WPA, enabled) < 0)
1316 static void show_set_key_error(struct prism2_hostapd_param *param)
1318 switch (param->u.crypt.err) {
1319 case HOSTAP_CRYPT_ERR_UNKNOWN_ALG:
1320 wpa_printf(MSG_INFO, "Unknown algorithm '%s'.",
1321 param->u.crypt.alg);
1322 wpa_printf(MSG_INFO, "You may need to load kernel module to "
1323 "register that algorithm.");
1324 wpa_printf(MSG_INFO, "E.g., 'modprobe hostap_crypt_wep' for "
1327 case HOSTAP_CRYPT_ERR_UNKNOWN_ADDR:
1328 wpa_printf(MSG_INFO, "Unknown address " MACSTR ".",
1329 MAC2STR(param->sta_addr));
1331 case HOSTAP_CRYPT_ERR_CRYPT_INIT_FAILED:
1332 wpa_printf(MSG_INFO, "Crypt algorithm initialization failed.");
1334 case HOSTAP_CRYPT_ERR_KEY_SET_FAILED:
1335 wpa_printf(MSG_INFO, "Key setting failed.");
1337 case HOSTAP_CRYPT_ERR_TX_KEY_SET_FAILED:
1338 wpa_printf(MSG_INFO, "TX key index setting failed.");
1340 case HOSTAP_CRYPT_ERR_CARD_CONF_FAILED:
1341 wpa_printf(MSG_INFO, "Card configuration failed.");
1347 static int wpa_driver_hostap_set_key(void *priv, wpa_alg alg,
1348 const u8 *addr, int key_idx,
1349 int set_tx, const u8 *seq, size_t seq_len,
1350 const u8 *key, size_t key_len)
1352 struct wpa_driver_hostap_data *drv = priv;
1353 struct prism2_hostapd_param *param;
1376 wpa_printf(MSG_DEBUG, "%s: alg=%s key_idx=%d set_tx=%d seq_len=%lu "
1377 "key_len=%lu", __FUNCTION__, alg_name, key_idx, set_tx,
1378 (unsigned long) seq_len, (unsigned long) key_len);
1383 blen = sizeof(*param) + key_len;
1384 buf = os_zalloc(blen);
1388 param = (struct prism2_hostapd_param *) buf;
1389 param->cmd = PRISM2_SET_ENCRYPTION;
1390 /* TODO: In theory, STA in client mode can use five keys; four default
1391 * keys for receiving (with keyidx 0..3) and one individual key for
1392 * both transmitting and receiving (keyidx 0) _unicast_ packets. Now,
1393 * keyidx 0 is reserved for this unicast use and default keys can only
1394 * use keyidx 1..3 (i.e., default key with keyidx 0 is not supported).
1395 * This should be fine for more or less all cases, but for completeness
1396 * sake, the driver could be enhanced to support the missing key. */
1399 os_memset(param->sta_addr, 0xff, ETH_ALEN);
1401 os_memcpy(param->sta_addr, addr, ETH_ALEN);
1403 os_memset(param->sta_addr, 0xff, ETH_ALEN);
1405 os_strlcpy((char *) param->u.crypt.alg, alg_name,
1406 HOSTAP_CRYPT_ALG_NAME_LEN);
1407 param->u.crypt.flags = set_tx ? HOSTAP_CRYPT_FLAG_SET_TX_KEY : 0;
1408 param->u.crypt.idx = key_idx;
1409 os_memcpy(param->u.crypt.seq, seq, seq_len);
1410 param->u.crypt.key_len = key_len;
1411 os_memcpy((u8 *) (param + 1), key, key_len);
1413 if (hostapd_ioctl(drv, param, blen, 1)) {
1414 wpa_printf(MSG_WARNING, "Failed to set encryption.");
1415 show_set_key_error(param);
1424 static int wpa_driver_hostap_set_countermeasures(void *priv, int enabled)
1426 struct wpa_driver_hostap_data *drv = priv;
1427 wpa_printf(MSG_DEBUG, "%s: enabled=%d", __FUNCTION__, enabled);
1428 return prism2param(drv, PRISM2_PARAM_TKIP_COUNTERMEASURES, enabled);
1432 static int wpa_driver_hostap_set_drop_unencrypted(void *priv, int enabled)
1434 struct wpa_driver_hostap_data *drv = priv;
1435 wpa_printf(MSG_DEBUG, "%s: enabled=%d", __FUNCTION__, enabled);
1436 return prism2param(drv, PRISM2_PARAM_DROP_UNENCRYPTED, enabled);
1440 static int wpa_driver_hostap_reset(struct wpa_driver_hostap_data *drv,
1446 wpa_printf(MSG_DEBUG, "%s: type=%d", __FUNCTION__, type);
1448 os_memset(&iwr, 0, sizeof(iwr));
1449 os_strlcpy(iwr.ifr_name, drv->ifname, IFNAMSIZ);
1450 i = (int *) iwr.u.name;
1453 if (ioctl(drv->sock, PRISM2_IOCTL_RESET, &iwr) < 0) {
1454 perror("ioctl[PRISM2_IOCTL_RESET]");
1461 static int wpa_driver_hostap_mlme(struct wpa_driver_hostap_data *drv,
1462 const u8 *addr, int cmd, int reason_code)
1464 struct prism2_hostapd_param param;
1467 /* There does not seem to be a better way of deauthenticating or
1468 * disassociating with Prism2/2.5/3 than sending the management frame
1469 * and then resetting the Port0 to make sure both the AP and the STA
1470 * end up in disconnected state. */
1471 os_memset(¶m, 0, sizeof(param));
1472 param.cmd = PRISM2_HOSTAPD_MLME;
1473 os_memcpy(param.sta_addr, addr, ETH_ALEN);
1474 param.u.mlme.cmd = cmd;
1475 param.u.mlme.reason_code = reason_code;
1476 ret = hostapd_ioctl(drv, ¶m, sizeof(param), 1);
1478 os_sleep(0, 100000);
1479 ret = wpa_driver_hostap_reset(drv, 2);
1485 static int wpa_driver_hostap_deauthenticate(void *priv, const u8 *addr,
1488 struct wpa_driver_hostap_data *drv = priv;
1489 wpa_printf(MSG_DEBUG, "%s", __FUNCTION__);
1490 return wpa_driver_hostap_mlme(drv, addr, MLME_STA_DEAUTH,
1495 static int wpa_driver_hostap_disassociate(void *priv, const u8 *addr,
1498 struct wpa_driver_hostap_data *drv = priv;
1499 wpa_printf(MSG_DEBUG, "%s", __FUNCTION__);
1500 return wpa_driver_hostap_mlme(drv, addr, MLME_STA_DISASSOC,
1506 wpa_driver_hostap_associate(void *priv,
1507 struct wpa_driver_associate_params *params)
1509 struct wpa_driver_hostap_data *drv = priv;
1511 int allow_unencrypted_eapol;
1513 wpa_printf(MSG_DEBUG, "%s", __FUNCTION__);
1515 if (params->mode != drv->current_mode) {
1516 /* At the moment, Host AP driver requires host_roaming=2 for
1517 * infrastructure mode and host_roaming=0 for adhoc. */
1518 if (prism2param(drv, PRISM2_PARAM_HOST_ROAMING,
1519 params->mode == IEEE80211_MODE_IBSS ? 0 : 2) <
1521 wpa_printf(MSG_DEBUG, "%s: failed to set host_roaming",
1524 drv->current_mode = params->mode;
1527 if (prism2param(drv, PRISM2_PARAM_PRIVACY_INVOKED,
1528 params->key_mgmt_suite != KEY_MGMT_NONE) < 0)
1530 if (wpa_driver_hostap_set_wpa_ie(drv, params->wpa_ie,
1531 params->wpa_ie_len) < 0)
1533 if (wpa_driver_wext_set_mode(drv->wext, params->mode) < 0)
1536 wpa_driver_wext_set_freq(drv->wext, params->freq) < 0)
1538 if (wpa_driver_wext_set_ssid(drv->wext, params->ssid, params->ssid_len)
1541 if (wpa_driver_wext_set_bssid(drv->wext, params->bssid) < 0)
1544 /* Allow unencrypted EAPOL messages even if pairwise keys are set when
1545 * not using WPA. IEEE 802.1X specifies that these frames are not
1546 * encrypted, but WPA encrypts them when pairwise keys are in use. */
1547 if (params->key_mgmt_suite == KEY_MGMT_802_1X ||
1548 params->key_mgmt_suite == KEY_MGMT_PSK)
1549 allow_unencrypted_eapol = 0;
1551 allow_unencrypted_eapol = 1;
1553 if (prism2param(drv, PRISM2_PARAM_IEEE_802_1X,
1554 allow_unencrypted_eapol) < 0) {
1555 wpa_printf(MSG_DEBUG, "hostap: Failed to configure "
1556 "ieee_802_1x param");
1557 /* Ignore this error.. driver_hostap.c can also be used with
1558 * other drivers that do not support this prism2_param. */
1565 static int wpa_driver_hostap_scan(void *priv, const u8 *ssid, size_t ssid_len)
1567 struct wpa_driver_hostap_data *drv = priv;
1568 struct prism2_hostapd_param param;
1572 /* Use standard Linux Wireless Extensions ioctl if possible
1573 * because some drivers using hostap code in wpa_supplicant
1574 * might not support Host AP specific scan request (with SSID
1576 return wpa_driver_wext_scan(drv->wext, ssid, ssid_len);
1582 os_memset(¶m, 0, sizeof(param));
1583 param.cmd = PRISM2_HOSTAPD_SCAN_REQ;
1584 param.u.scan_req.ssid_len = ssid_len;
1585 os_memcpy(param.u.scan_req.ssid, ssid, ssid_len);
1586 ret = hostapd_ioctl(drv, ¶m, sizeof(param), 1);
1588 /* Not all drivers generate "scan completed" wireless event, so try to
1589 * read results after a timeout. */
1590 eloop_cancel_timeout(wpa_driver_wext_scan_timeout, drv->wext,
1592 eloop_register_timeout(3, 0, wpa_driver_wext_scan_timeout, drv->wext,
1599 static int wpa_driver_hostap_set_auth_alg(void *priv, int auth_alg)
1601 struct wpa_driver_hostap_data *drv = priv;
1604 if (auth_alg & AUTH_ALG_OPEN_SYSTEM)
1606 if (auth_alg & AUTH_ALG_SHARED_KEY)
1608 if (auth_alg & AUTH_ALG_LEAP)
1611 algs = 1; /* at least one algorithm should be set */
1613 return prism2param(drv, PRISM2_PARAM_AP_AUTH_ALGS, algs);
1617 static int wpa_driver_hostap_get_bssid(void *priv, u8 *bssid)
1619 struct wpa_driver_hostap_data *drv = priv;
1620 return wpa_driver_wext_get_bssid(drv->wext, bssid);
1624 static int wpa_driver_hostap_get_ssid(void *priv, u8 *ssid)
1626 struct wpa_driver_hostap_data *drv = priv;
1627 return wpa_driver_wext_get_ssid(drv->wext, ssid);
1631 static struct wpa_scan_results * wpa_driver_hostap_get_scan_results(void *priv)
1633 struct wpa_driver_hostap_data *drv = priv;
1634 return wpa_driver_wext_get_scan_results(drv->wext);
1638 static int wpa_driver_hostap_set_operstate(void *priv, int state)
1640 struct wpa_driver_hostap_data *drv = priv;
1641 return wpa_driver_wext_set_operstate(drv->wext, state);
1645 static void * wpa_driver_hostap_init(void *ctx, const char *ifname)
1647 struct wpa_driver_hostap_data *drv;
1649 drv = os_zalloc(sizeof(*drv));
1652 drv->wext = wpa_driver_wext_init(ctx, ifname);
1653 if (drv->wext == NULL) {
1659 os_strlcpy(drv->ifname, ifname, sizeof(drv->ifname));
1660 drv->sock = socket(PF_INET, SOCK_DGRAM, 0);
1661 if (drv->sock < 0) {
1663 wpa_driver_wext_deinit(drv->wext);
1668 if (os_strncmp(ifname, "wlan", 4) == 0) {
1670 * Host AP driver may use both wlan# and wifi# interface in
1673 char ifname2[IFNAMSIZ + 1];
1674 os_strlcpy(ifname2, ifname, sizeof(ifname2));
1675 os_memcpy(ifname2, "wifi", 4);
1676 wpa_driver_wext_alternative_ifindex(drv->wext, ifname2);
1683 static void wpa_driver_hostap_deinit(void *priv)
1685 struct wpa_driver_hostap_data *drv = priv;
1686 wpa_driver_wext_deinit(drv->wext);
1691 #endif /* HOSTAPD */
1694 const struct wpa_driver_ops wpa_driver_hostap_ops = {
1696 .desc = "Host AP driver (Intersil Prism2/2.5/3)",
1698 .hapd_init = hostap_init,
1699 .hapd_deinit = hostap_driver_deinit,
1700 .set_ieee8021x = hostap_set_ieee8021x,
1701 .set_privacy = hostap_set_privacy,
1702 .hapd_set_key = hostap_set_key,
1703 .get_seqnum = hostap_get_seqnum,
1704 .flush = hostap_flush,
1705 .set_generic_elem = hostap_set_generic_elem,
1706 .read_sta_data = hostap_read_sta_data,
1707 .hapd_send_eapol = hostap_send_eapol,
1708 .sta_set_flags = hostap_sta_set_flags,
1709 .sta_deauth = hostap_sta_deauth,
1710 .sta_disassoc = hostap_sta_disassoc,
1711 .sta_remove = hostap_sta_remove,
1712 .hapd_set_ssid = hostap_set_ssid,
1713 .send_mlme = hostap_send_mlme,
1714 .sta_add = hostap_sta_add,
1715 .get_inact_sec = hostap_get_inact_sec,
1716 .sta_clear_stats = hostap_sta_clear_stats,
1717 .get_hw_feature_data = hostap_get_hw_feature_data,
1718 .set_wps_beacon_ie = hostap_set_wps_beacon_ie,
1719 .set_wps_probe_resp_ie = hostap_set_wps_probe_resp_ie,
1721 .get_bssid = wpa_driver_hostap_get_bssid,
1722 .get_ssid = wpa_driver_hostap_get_ssid,
1723 .set_wpa = wpa_driver_hostap_set_wpa,
1724 .set_key = wpa_driver_hostap_set_key,
1725 .set_countermeasures = wpa_driver_hostap_set_countermeasures,
1726 .set_drop_unencrypted = wpa_driver_hostap_set_drop_unencrypted,
1727 .scan = wpa_driver_hostap_scan,
1728 .get_scan_results2 = wpa_driver_hostap_get_scan_results,
1729 .deauthenticate = wpa_driver_hostap_deauthenticate,
1730 .disassociate = wpa_driver_hostap_disassociate,
1731 .associate = wpa_driver_hostap_associate,
1732 .set_auth_alg = wpa_driver_hostap_set_auth_alg,
1733 .init = wpa_driver_hostap_init,
1734 .deinit = wpa_driver_hostap_deinit,
1735 .set_operstate = wpa_driver_hostap_set_operstate,
1736 #endif /* HOSTAPD */