2 * WPA Supplicant - driver interaction with generic Linux Wireless Extensions
3 * Copyright (c) 2003-2007, 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.
14 * This file implements a driver interface for the Linux Wireless Extensions.
15 * When used with WE-18 or newer, this interface can be used as-is with number
16 * of drivers. In addition to this, some of the common functions in this file
17 * can be used by other driver interface implementations that use generic WE
18 * ioctls, but require private ioctls for some of the functionality.
22 #include <sys/ioctl.h>
23 #include <net/if_arp.h>
25 #include "wireless_copy.h"
29 #include "priv_netlink.h"
30 #include "driver_wext.h"
31 #include "ieee802_11_defs.h"
32 #include "wpa_common.h"
35 static int wpa_driver_wext_flush_pmkid(void *priv);
36 static int wpa_driver_wext_get_range(void *priv);
37 static int wpa_driver_wext_finish_drv_init(struct wpa_driver_wext_data *drv);
38 static void wpa_driver_wext_disconnect(struct wpa_driver_wext_data *drv);
41 static int wpa_driver_wext_send_oper_ifla(struct wpa_driver_wext_data *drv,
42 int linkmode, int operstate)
46 struct ifinfomsg ifinfo;
53 os_memset(&req, 0, sizeof(req));
55 req.hdr.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg));
56 req.hdr.nlmsg_type = RTM_SETLINK;
57 req.hdr.nlmsg_flags = NLM_F_REQUEST;
58 req.hdr.nlmsg_seq = ++nl_seq;
59 req.hdr.nlmsg_pid = 0;
61 req.ifinfo.ifi_family = AF_UNSPEC;
62 req.ifinfo.ifi_type = 0;
63 req.ifinfo.ifi_index = drv->ifindex;
64 req.ifinfo.ifi_flags = 0;
65 req.ifinfo.ifi_change = 0;
68 rta = aliasing_hide_typecast(
69 ((char *) &req + NLMSG_ALIGN(req.hdr.nlmsg_len)),
71 rta->rta_type = IFLA_LINKMODE;
72 rta->rta_len = RTA_LENGTH(sizeof(char));
73 *((char *) RTA_DATA(rta)) = linkmode;
74 req.hdr.nlmsg_len = NLMSG_ALIGN(req.hdr.nlmsg_len) +
75 RTA_LENGTH(sizeof(char));
77 if (operstate != -1) {
78 rta = (struct rtattr *)
79 ((char *) &req + NLMSG_ALIGN(req.hdr.nlmsg_len));
80 rta->rta_type = IFLA_OPERSTATE;
81 rta->rta_len = RTA_LENGTH(sizeof(char));
82 *((char *) RTA_DATA(rta)) = operstate;
83 req.hdr.nlmsg_len = NLMSG_ALIGN(req.hdr.nlmsg_len) +
84 RTA_LENGTH(sizeof(char));
87 wpa_printf(MSG_DEBUG, "WEXT: Operstate: linkmode=%d, operstate=%d",
90 ret = send(drv->event_sock, &req, req.hdr.nlmsg_len, 0);
92 wpa_printf(MSG_DEBUG, "WEXT: Sending operstate IFLA failed: "
93 "%s (assume operstate is not supported)",
97 return ret < 0 ? -1 : 0;
101 int wpa_driver_wext_set_auth_param(struct wpa_driver_wext_data *drv,
107 os_memset(&iwr, 0, sizeof(iwr));
108 os_strlcpy(iwr.ifr_name, drv->ifname, IFNAMSIZ);
109 iwr.u.param.flags = idx & IW_AUTH_INDEX;
110 iwr.u.param.value = value;
112 if (ioctl(drv->ioctl_sock, SIOCSIWAUTH, &iwr) < 0) {
113 if (errno != EOPNOTSUPP) {
114 wpa_printf(MSG_DEBUG, "WEXT: SIOCSIWAUTH(param %d "
115 "value 0x%x) failed: %s)",
116 idx, value, strerror(errno));
118 ret = errno == EOPNOTSUPP ? -2 : -1;
126 * wpa_driver_wext_get_bssid - Get BSSID, SIOCGIWAP
127 * @priv: Pointer to private wext data from wpa_driver_wext_init()
128 * @bssid: Buffer for BSSID
129 * Returns: 0 on success, -1 on failure
131 int wpa_driver_wext_get_bssid(void *priv, u8 *bssid)
133 struct wpa_driver_wext_data *drv = priv;
137 os_memset(&iwr, 0, sizeof(iwr));
138 os_strlcpy(iwr.ifr_name, drv->ifname, IFNAMSIZ);
140 if (ioctl(drv->ioctl_sock, SIOCGIWAP, &iwr) < 0) {
141 perror("ioctl[SIOCGIWAP]");
144 os_memcpy(bssid, iwr.u.ap_addr.sa_data, ETH_ALEN);
151 * wpa_driver_wext_set_bssid - Set BSSID, SIOCSIWAP
152 * @priv: Pointer to private wext data from wpa_driver_wext_init()
154 * Returns: 0 on success, -1 on failure
156 int wpa_driver_wext_set_bssid(void *priv, const u8 *bssid)
158 struct wpa_driver_wext_data *drv = priv;
162 os_memset(&iwr, 0, sizeof(iwr));
163 os_strlcpy(iwr.ifr_name, drv->ifname, IFNAMSIZ);
164 iwr.u.ap_addr.sa_family = ARPHRD_ETHER;
166 os_memcpy(iwr.u.ap_addr.sa_data, bssid, ETH_ALEN);
168 os_memset(iwr.u.ap_addr.sa_data, 0, ETH_ALEN);
170 if (ioctl(drv->ioctl_sock, SIOCSIWAP, &iwr) < 0) {
171 perror("ioctl[SIOCSIWAP]");
180 * wpa_driver_wext_get_ssid - Get SSID, SIOCGIWESSID
181 * @priv: Pointer to private wext data from wpa_driver_wext_init()
182 * @ssid: Buffer for the SSID; must be at least 32 bytes long
183 * Returns: SSID length on success, -1 on failure
185 int wpa_driver_wext_get_ssid(void *priv, u8 *ssid)
187 struct wpa_driver_wext_data *drv = priv;
191 os_memset(&iwr, 0, sizeof(iwr));
192 os_strlcpy(iwr.ifr_name, drv->ifname, IFNAMSIZ);
193 iwr.u.essid.pointer = (caddr_t) ssid;
194 iwr.u.essid.length = 32;
196 if (ioctl(drv->ioctl_sock, SIOCGIWESSID, &iwr) < 0) {
197 perror("ioctl[SIOCGIWESSID]");
200 ret = iwr.u.essid.length;
203 /* Some drivers include nul termination in the SSID, so let's
204 * remove it here before further processing. WE-21 changes this
205 * to explicitly require the length _not_ to include nul
207 if (ret > 0 && ssid[ret - 1] == '\0' &&
208 drv->we_version_compiled < 21)
217 * wpa_driver_wext_set_ssid - Set SSID, SIOCSIWESSID
218 * @priv: Pointer to private wext data from wpa_driver_wext_init()
220 * @ssid_len: Length of SSID (0..32)
221 * Returns: 0 on success, -1 on failure
223 int wpa_driver_wext_set_ssid(void *priv, const u8 *ssid, size_t ssid_len)
225 struct wpa_driver_wext_data *drv = priv;
233 os_memset(&iwr, 0, sizeof(iwr));
234 os_strlcpy(iwr.ifr_name, drv->ifname, IFNAMSIZ);
235 /* flags: 1 = ESSID is active, 0 = not (promiscuous) */
236 iwr.u.essid.flags = (ssid_len != 0);
237 os_memset(buf, 0, sizeof(buf));
238 os_memcpy(buf, ssid, ssid_len);
239 iwr.u.essid.pointer = (caddr_t) buf;
240 if (drv->we_version_compiled < 21) {
241 /* For historic reasons, set SSID length to include one extra
242 * character, C string nul termination, even though SSID is
243 * really an octet string that should not be presented as a C
244 * string. Some Linux drivers decrement the length by one and
245 * can thus end up missing the last octet of the SSID if the
246 * length is not incremented here. WE-21 changes this to
247 * explicitly require the length _not_ to include nul
252 iwr.u.essid.length = ssid_len;
254 if (ioctl(drv->ioctl_sock, SIOCSIWESSID, &iwr) < 0) {
255 perror("ioctl[SIOCSIWESSID]");
264 * wpa_driver_wext_set_freq - Set frequency/channel, SIOCSIWFREQ
265 * @priv: Pointer to private wext data from wpa_driver_wext_init()
266 * @freq: Frequency in MHz
267 * Returns: 0 on success, -1 on failure
269 int wpa_driver_wext_set_freq(void *priv, int freq)
271 struct wpa_driver_wext_data *drv = priv;
275 os_memset(&iwr, 0, sizeof(iwr));
276 os_strlcpy(iwr.ifr_name, drv->ifname, IFNAMSIZ);
277 iwr.u.freq.m = freq * 100000;
280 if (ioctl(drv->ioctl_sock, SIOCSIWFREQ, &iwr) < 0) {
281 perror("ioctl[SIOCSIWFREQ]");
290 wpa_driver_wext_event_wireless_custom(void *ctx, char *custom)
292 union wpa_event_data data;
294 wpa_printf(MSG_MSGDUMP, "WEXT: Custom wireless event: '%s'",
297 os_memset(&data, 0, sizeof(data));
299 if (os_strncmp(custom, "MLME-MICHAELMICFAILURE.indication", 33) == 0) {
300 data.michael_mic_failure.unicast =
301 os_strstr(custom, " unicast ") != NULL;
302 /* TODO: parse parameters(?) */
303 wpa_supplicant_event(ctx, EVENT_MICHAEL_MIC_FAILURE, &data);
304 } else if (os_strncmp(custom, "ASSOCINFO(ReqIEs=", 17) == 0) {
310 bytes = strspn(spos, "0123456789abcdefABCDEF");
311 if (!bytes || (bytes & 1))
315 data.assoc_info.req_ies = os_malloc(bytes);
316 if (data.assoc_info.req_ies == NULL)
319 data.assoc_info.req_ies_len = bytes;
320 hexstr2bin(spos, data.assoc_info.req_ies, bytes);
324 data.assoc_info.resp_ies = NULL;
325 data.assoc_info.resp_ies_len = 0;
327 if (os_strncmp(spos, " RespIEs=", 9) == 0) {
330 bytes = strspn(spos, "0123456789abcdefABCDEF");
331 if (!bytes || (bytes & 1))
335 data.assoc_info.resp_ies = os_malloc(bytes);
336 if (data.assoc_info.resp_ies == NULL)
339 data.assoc_info.resp_ies_len = bytes;
340 hexstr2bin(spos, data.assoc_info.resp_ies, bytes);
343 wpa_supplicant_event(ctx, EVENT_ASSOCINFO, &data);
346 os_free(data.assoc_info.resp_ies);
347 os_free(data.assoc_info.req_ies);
348 #ifdef CONFIG_PEERKEY
349 } else if (os_strncmp(custom, "STKSTART.request=", 17) == 0) {
350 if (hwaddr_aton(custom + 17, data.stkstart.peer)) {
351 wpa_printf(MSG_DEBUG, "WEXT: unrecognized "
352 "STKSTART.request '%s'", custom + 17);
355 wpa_supplicant_event(ctx, EVENT_STKSTART, &data);
356 #endif /* CONFIG_PEERKEY */
361 static int wpa_driver_wext_event_wireless_michaelmicfailure(
362 void *ctx, const char *ev, size_t len)
364 const struct iw_michaelmicfailure *mic;
365 union wpa_event_data data;
367 if (len < sizeof(*mic))
370 mic = (const struct iw_michaelmicfailure *) ev;
372 wpa_printf(MSG_DEBUG, "Michael MIC failure wireless event: "
373 "flags=0x%x src_addr=" MACSTR, mic->flags,
374 MAC2STR(mic->src_addr.sa_data));
376 os_memset(&data, 0, sizeof(data));
377 data.michael_mic_failure.unicast = !(mic->flags & IW_MICFAILURE_GROUP);
378 wpa_supplicant_event(ctx, EVENT_MICHAEL_MIC_FAILURE, &data);
384 static int wpa_driver_wext_event_wireless_pmkidcand(
385 struct wpa_driver_wext_data *drv, const char *ev, size_t len)
387 const struct iw_pmkid_cand *cand;
388 union wpa_event_data data;
391 if (len < sizeof(*cand))
394 cand = (const struct iw_pmkid_cand *) ev;
395 addr = (const u8 *) cand->bssid.sa_data;
397 wpa_printf(MSG_DEBUG, "PMKID candidate wireless event: "
398 "flags=0x%x index=%d bssid=" MACSTR, cand->flags,
399 cand->index, MAC2STR(addr));
401 os_memset(&data, 0, sizeof(data));
402 os_memcpy(data.pmkid_candidate.bssid, addr, ETH_ALEN);
403 data.pmkid_candidate.index = cand->index;
404 data.pmkid_candidate.preauth = cand->flags & IW_PMKID_CAND_PREAUTH;
405 wpa_supplicant_event(drv->ctx, EVENT_PMKID_CANDIDATE, &data);
411 static int wpa_driver_wext_event_wireless_assocreqie(
412 struct wpa_driver_wext_data *drv, const char *ev, int len)
417 wpa_hexdump(MSG_DEBUG, "AssocReq IE wireless event", (const u8 *) ev,
419 os_free(drv->assoc_req_ies);
420 drv->assoc_req_ies = os_malloc(len);
421 if (drv->assoc_req_ies == NULL) {
422 drv->assoc_req_ies_len = 0;
425 os_memcpy(drv->assoc_req_ies, ev, len);
426 drv->assoc_req_ies_len = len;
432 static int wpa_driver_wext_event_wireless_assocrespie(
433 struct wpa_driver_wext_data *drv, const char *ev, int len)
438 wpa_hexdump(MSG_DEBUG, "AssocResp IE wireless event", (const u8 *) ev,
440 os_free(drv->assoc_resp_ies);
441 drv->assoc_resp_ies = os_malloc(len);
442 if (drv->assoc_resp_ies == NULL) {
443 drv->assoc_resp_ies_len = 0;
446 os_memcpy(drv->assoc_resp_ies, ev, len);
447 drv->assoc_resp_ies_len = len;
453 static void wpa_driver_wext_event_assoc_ies(struct wpa_driver_wext_data *drv)
455 union wpa_event_data data;
457 if (drv->assoc_req_ies == NULL && drv->assoc_resp_ies == NULL)
460 os_memset(&data, 0, sizeof(data));
461 if (drv->assoc_req_ies) {
462 data.assoc_info.req_ies = drv->assoc_req_ies;
463 drv->assoc_req_ies = NULL;
464 data.assoc_info.req_ies_len = drv->assoc_req_ies_len;
466 if (drv->assoc_resp_ies) {
467 data.assoc_info.resp_ies = drv->assoc_resp_ies;
468 drv->assoc_resp_ies = NULL;
469 data.assoc_info.resp_ies_len = drv->assoc_resp_ies_len;
472 wpa_supplicant_event(drv->ctx, EVENT_ASSOCINFO, &data);
474 os_free(data.assoc_info.req_ies);
475 os_free(data.assoc_info.resp_ies);
479 static void wpa_driver_wext_event_wireless(struct wpa_driver_wext_data *drv,
480 void *ctx, char *data, int len)
482 struct iw_event iwe_buf, *iwe = &iwe_buf;
483 char *pos, *end, *custom, *buf;
488 while (pos + IW_EV_LCP_LEN <= end) {
489 /* Event data may be unaligned, so make a local, aligned copy
490 * before processing. */
491 os_memcpy(&iwe_buf, pos, IW_EV_LCP_LEN);
492 wpa_printf(MSG_DEBUG, "Wireless event: cmd=0x%x len=%d",
494 if (iwe->len <= IW_EV_LCP_LEN)
497 custom = pos + IW_EV_POINT_LEN;
498 if (drv->we_version_compiled > 18 &&
499 (iwe->cmd == IWEVMICHAELMICFAILURE ||
500 iwe->cmd == IWEVCUSTOM ||
501 iwe->cmd == IWEVASSOCREQIE ||
502 iwe->cmd == IWEVASSOCRESPIE ||
503 iwe->cmd == IWEVPMKIDCAND)) {
504 /* WE-19 removed the pointer from struct iw_point */
505 char *dpos = (char *) &iwe_buf.u.data.length;
506 int dlen = dpos - (char *) &iwe_buf;
507 os_memcpy(dpos, pos + IW_EV_LCP_LEN,
508 sizeof(struct iw_event) - dlen);
510 os_memcpy(&iwe_buf, pos, sizeof(struct iw_event));
511 custom += IW_EV_POINT_OFF;
516 wpa_printf(MSG_DEBUG, "Wireless event: new AP: "
518 MAC2STR((u8 *) iwe->u.ap_addr.sa_data));
519 if (is_zero_ether_addr(
520 (const u8 *) iwe->u.ap_addr.sa_data) ||
521 os_memcmp(iwe->u.ap_addr.sa_data,
522 "\x44\x44\x44\x44\x44\x44", ETH_ALEN) ==
524 os_free(drv->assoc_req_ies);
525 drv->assoc_req_ies = NULL;
526 os_free(drv->assoc_resp_ies);
527 drv->assoc_resp_ies = NULL;
528 wpa_supplicant_event(ctx, EVENT_DISASSOC,
532 wpa_driver_wext_event_assoc_ies(drv);
533 wpa_supplicant_event(ctx, EVENT_ASSOC, NULL);
536 case IWEVMICHAELMICFAILURE:
537 if (custom + iwe->u.data.length > end) {
538 wpa_printf(MSG_DEBUG, "WEXT: Invalid "
539 "IWEVMICHAELMICFAILURE length");
542 wpa_driver_wext_event_wireless_michaelmicfailure(
543 ctx, custom, iwe->u.data.length);
546 if (custom + iwe->u.data.length > end) {
547 wpa_printf(MSG_DEBUG, "WEXT: Invalid "
548 "IWEVCUSTOM length");
551 buf = os_malloc(iwe->u.data.length + 1);
554 os_memcpy(buf, custom, iwe->u.data.length);
555 buf[iwe->u.data.length] = '\0';
556 wpa_driver_wext_event_wireless_custom(ctx, buf);
560 drv->scan_complete_events = 1;
561 eloop_cancel_timeout(wpa_driver_wext_scan_timeout,
563 wpa_supplicant_event(ctx, EVENT_SCAN_RESULTS, NULL);
566 if (custom + iwe->u.data.length > end) {
567 wpa_printf(MSG_DEBUG, "WEXT: Invalid "
568 "IWEVASSOCREQIE length");
571 wpa_driver_wext_event_wireless_assocreqie(
572 drv, custom, iwe->u.data.length);
574 case IWEVASSOCRESPIE:
575 if (custom + iwe->u.data.length > end) {
576 wpa_printf(MSG_DEBUG, "WEXT: Invalid "
577 "IWEVASSOCRESPIE length");
580 wpa_driver_wext_event_wireless_assocrespie(
581 drv, custom, iwe->u.data.length);
584 if (custom + iwe->u.data.length > end) {
585 wpa_printf(MSG_DEBUG, "WEXT: Invalid "
586 "IWEVPMKIDCAND length");
589 wpa_driver_wext_event_wireless_pmkidcand(
590 drv, custom, iwe->u.data.length);
599 static void wpa_driver_wext_event_link(struct wpa_driver_wext_data *drv,
600 void *ctx, char *buf, size_t len,
603 union wpa_event_data event;
605 os_memset(&event, 0, sizeof(event));
606 if (len > sizeof(event.interface_status.ifname))
607 len = sizeof(event.interface_status.ifname) - 1;
608 os_memcpy(event.interface_status.ifname, buf, len);
609 event.interface_status.ievent = del ? EVENT_INTERFACE_REMOVED :
610 EVENT_INTERFACE_ADDED;
612 wpa_printf(MSG_DEBUG, "RTM_%sLINK, IFLA_IFNAME: Interface '%s' %s",
614 event.interface_status.ifname,
615 del ? "removed" : "added");
617 if (os_strcmp(drv->ifname, event.interface_status.ifname) == 0) {
624 wpa_supplicant_event(ctx, EVENT_INTERFACE_STATUS, &event);
628 static int wpa_driver_wext_own_ifname(struct wpa_driver_wext_data *drv,
631 struct ifinfomsg *ifi;
632 int attrlen, nlmsg_len, rta_len;
637 nlmsg_len = NLMSG_ALIGN(sizeof(struct ifinfomsg));
639 attrlen = h->nlmsg_len - nlmsg_len;
643 attr = (struct rtattr *) (((char *) ifi) + nlmsg_len);
645 rta_len = RTA_ALIGN(sizeof(struct rtattr));
646 while (RTA_OK(attr, attrlen)) {
647 if (attr->rta_type == IFLA_IFNAME) {
648 if (os_strcmp(((char *) attr) + rta_len, drv->ifname)
654 attr = RTA_NEXT(attr, attrlen);
661 static int wpa_driver_wext_own_ifindex(struct wpa_driver_wext_data *drv,
662 int ifindex, struct nlmsghdr *h)
664 if (drv->ifindex == ifindex || drv->ifindex2 == ifindex)
667 if (drv->if_removed && wpa_driver_wext_own_ifname(drv, h)) {
668 drv->ifindex = if_nametoindex(drv->ifname);
669 wpa_printf(MSG_DEBUG, "WEXT: Update ifindex for a removed "
671 wpa_driver_wext_finish_drv_init(drv);
679 static void wpa_driver_wext_event_rtm_newlink(struct wpa_driver_wext_data *drv,
680 void *ctx, struct nlmsghdr *h,
683 struct ifinfomsg *ifi;
684 int attrlen, nlmsg_len, rta_len;
685 struct rtattr * attr;
687 if (len < sizeof(*ifi))
692 if (!wpa_driver_wext_own_ifindex(drv, ifi->ifi_index, h)) {
693 wpa_printf(MSG_DEBUG, "Ignore event for foreign ifindex %d",
698 wpa_printf(MSG_DEBUG, "RTM_NEWLINK: operstate=%d ifi_flags=0x%x "
700 drv->operstate, ifi->ifi_flags,
701 (ifi->ifi_flags & IFF_UP) ? "[UP]" : "",
702 (ifi->ifi_flags & IFF_RUNNING) ? "[RUNNING]" : "",
703 (ifi->ifi_flags & IFF_LOWER_UP) ? "[LOWER_UP]" : "",
704 (ifi->ifi_flags & IFF_DORMANT) ? "[DORMANT]" : "");
706 * Some drivers send the association event before the operup event--in
707 * this case, lifting operstate in wpa_driver_wext_set_operstate()
708 * fails. This will hit us when wpa_supplicant does not need to do
709 * IEEE 802.1X authentication
711 if (drv->operstate == 1 &&
712 (ifi->ifi_flags & (IFF_LOWER_UP | IFF_DORMANT)) == IFF_LOWER_UP &&
713 !(ifi->ifi_flags & IFF_RUNNING))
714 wpa_driver_wext_send_oper_ifla(drv, -1, IF_OPER_UP);
716 nlmsg_len = NLMSG_ALIGN(sizeof(struct ifinfomsg));
718 attrlen = h->nlmsg_len - nlmsg_len;
722 attr = (struct rtattr *) (((char *) ifi) + nlmsg_len);
724 rta_len = RTA_ALIGN(sizeof(struct rtattr));
725 while (RTA_OK(attr, attrlen)) {
726 if (attr->rta_type == IFLA_WIRELESS) {
727 wpa_driver_wext_event_wireless(
728 drv, ctx, ((char *) attr) + rta_len,
729 attr->rta_len - rta_len);
730 } else if (attr->rta_type == IFLA_IFNAME) {
731 wpa_driver_wext_event_link(drv, ctx,
732 ((char *) attr) + rta_len,
733 attr->rta_len - rta_len, 0);
735 attr = RTA_NEXT(attr, attrlen);
740 static void wpa_driver_wext_event_rtm_dellink(struct wpa_driver_wext_data *drv,
741 void *ctx, struct nlmsghdr *h,
744 struct ifinfomsg *ifi;
745 int attrlen, nlmsg_len, rta_len;
746 struct rtattr * attr;
748 if (len < sizeof(*ifi))
753 nlmsg_len = NLMSG_ALIGN(sizeof(struct ifinfomsg));
755 attrlen = h->nlmsg_len - nlmsg_len;
759 attr = (struct rtattr *) (((char *) ifi) + nlmsg_len);
761 rta_len = RTA_ALIGN(sizeof(struct rtattr));
762 while (RTA_OK(attr, attrlen)) {
763 if (attr->rta_type == IFLA_IFNAME) {
764 wpa_driver_wext_event_link(drv, ctx,
765 ((char *) attr) + rta_len,
766 attr->rta_len - rta_len, 1);
768 attr = RTA_NEXT(attr, attrlen);
773 static void wpa_driver_wext_event_receive(int sock, void *eloop_ctx,
778 struct sockaddr_nl from;
784 fromlen = sizeof(from);
785 left = recvfrom(sock, buf, sizeof(buf), MSG_DONTWAIT,
786 (struct sockaddr *) &from, &fromlen);
788 if (errno != EINTR && errno != EAGAIN)
789 perror("recvfrom(netlink)");
793 h = (struct nlmsghdr *) buf;
794 while (left >= (int) sizeof(*h)) {
798 plen = len - sizeof(*h);
799 if (len > left || plen < 0) {
800 wpa_printf(MSG_DEBUG, "Malformed netlink message: "
801 "len=%d left=%d plen=%d",
806 switch (h->nlmsg_type) {
808 wpa_driver_wext_event_rtm_newlink(eloop_ctx, sock_ctx,
812 wpa_driver_wext_event_rtm_dellink(eloop_ctx, sock_ctx,
817 len = NLMSG_ALIGN(len);
819 h = (struct nlmsghdr *) ((char *) h + len);
823 wpa_printf(MSG_DEBUG, "%d extra bytes in the end of netlink "
827 if (--max_events > 0) {
829 * Try to receive all events in one eloop call in order to
830 * limit race condition on cases where AssocInfo event, Assoc
831 * event, and EAPOL frames are received more or less at the
832 * same time. We want to process the event messages first
833 * before starting EAPOL processing.
840 static int wpa_driver_wext_get_ifflags_ifname(struct wpa_driver_wext_data *drv,
841 const char *ifname, int *flags)
845 os_memset(&ifr, 0, sizeof(ifr));
846 os_strlcpy(ifr.ifr_name, ifname, IFNAMSIZ);
847 if (ioctl(drv->ioctl_sock, SIOCGIFFLAGS, (caddr_t) &ifr) < 0) {
848 perror("ioctl[SIOCGIFFLAGS]");
851 *flags = ifr.ifr_flags & 0xffff;
857 * wpa_driver_wext_get_ifflags - Get interface flags (SIOCGIFFLAGS)
858 * @drv: driver_wext private data
859 * @flags: Pointer to returned flags value
860 * Returns: 0 on success, -1 on failure
862 int wpa_driver_wext_get_ifflags(struct wpa_driver_wext_data *drv, int *flags)
864 return wpa_driver_wext_get_ifflags_ifname(drv, drv->ifname, flags);
868 static int wpa_driver_wext_set_ifflags_ifname(struct wpa_driver_wext_data *drv,
869 const char *ifname, int flags)
873 os_memset(&ifr, 0, sizeof(ifr));
874 os_strlcpy(ifr.ifr_name, ifname, IFNAMSIZ);
875 ifr.ifr_flags = flags & 0xffff;
876 if (ioctl(drv->ioctl_sock, SIOCSIFFLAGS, (caddr_t) &ifr) < 0) {
877 perror("SIOCSIFFLAGS");
885 * wpa_driver_wext_set_ifflags - Set interface flags (SIOCSIFFLAGS)
886 * @drv: driver_wext private data
887 * @flags: New value for flags
888 * Returns: 0 on success, -1 on failure
890 int wpa_driver_wext_set_ifflags(struct wpa_driver_wext_data *drv, int flags)
892 return wpa_driver_wext_set_ifflags_ifname(drv, drv->ifname, flags);
897 * wpa_driver_wext_init - Initialize WE driver interface
898 * @ctx: context to be used when calling wpa_supplicant functions,
899 * e.g., wpa_supplicant_event()
900 * @ifname: interface name, e.g., wlan0
901 * Returns: Pointer to private data, %NULL on failure
903 void * wpa_driver_wext_init(void *ctx, const char *ifname)
906 struct sockaddr_nl local;
907 struct wpa_driver_wext_data *drv;
909 drv = os_zalloc(sizeof(*drv));
913 os_strlcpy(drv->ifname, ifname, sizeof(drv->ifname));
915 drv->ioctl_sock = socket(PF_INET, SOCK_DGRAM, 0);
916 if (drv->ioctl_sock < 0) {
917 perror("socket(PF_INET,SOCK_DGRAM)");
921 s = socket(PF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
923 perror("socket(PF_NETLINK,SOCK_RAW,NETLINK_ROUTE)");
928 os_memset(&local, 0, sizeof(local));
929 local.nl_family = AF_NETLINK;
930 local.nl_groups = RTMGRP_LINK;
931 if (bind(s, (struct sockaddr *) &local, sizeof(local)) < 0) {
932 perror("bind(netlink)");
936 eloop_register_read_sock(s, wpa_driver_wext_event_receive, drv, ctx);
940 if (wpa_driver_wext_finish_drv_init(drv) < 0)
946 eloop_unregister_read_sock(drv->event_sock);
948 close(drv->event_sock);
950 close(drv->ioctl_sock);
957 static int wpa_driver_wext_finish_drv_init(struct wpa_driver_wext_data *drv)
961 if (wpa_driver_wext_get_ifflags(drv, &flags) != 0) {
962 wpa_printf(MSG_ERROR, "Could not get interface '%s' flags",
967 if (!(flags & IFF_UP)) {
968 if (wpa_driver_wext_set_ifflags(drv, flags | IFF_UP) != 0) {
969 wpa_printf(MSG_ERROR, "Could not set interface '%s' "
974 * Wait some time to allow driver to initialize before
975 * starting configuring the driver. This seems to be
976 * needed at least some drivers that load firmware etc.
977 * when the interface is set up.
979 wpa_printf(MSG_DEBUG, "Interface %s set UP - waiting "
980 "a second for the driver to complete "
981 "initialization", drv->ifname);
987 * Make sure that the driver does not have any obsolete PMKID entries.
989 wpa_driver_wext_flush_pmkid(drv);
991 if (wpa_driver_wext_set_mode(drv, 0) < 0) {
992 wpa_printf(MSG_DEBUG, "Could not configure driver to use "
994 /* Try to use it anyway */
997 wpa_driver_wext_get_range(drv);
1000 * Unlock the driver's BSSID and force to a random SSID to clear any
1001 * previous association the driver might have when the supplicant
1004 wpa_driver_wext_disconnect(drv);
1006 drv->ifindex = if_nametoindex(drv->ifname);
1008 if (os_strncmp(drv->ifname, "wlan", 4) == 0) {
1010 * Host AP driver may use both wlan# and wifi# interface in
1011 * wireless events. Since some of the versions included WE-18
1012 * support, let's add the alternative ifindex also from
1013 * driver_wext.c for the time being. This may be removed at
1014 * some point once it is believed that old versions of the
1015 * driver are not in use anymore.
1017 char ifname2[IFNAMSIZ + 1];
1018 os_strlcpy(ifname2, drv->ifname, sizeof(ifname2));
1019 os_memcpy(ifname2, "wifi", 4);
1020 wpa_driver_wext_alternative_ifindex(drv, ifname2);
1023 wpa_driver_wext_send_oper_ifla(drv, 1, IF_OPER_DORMANT);
1030 * wpa_driver_wext_deinit - Deinitialize WE driver interface
1031 * @priv: Pointer to private wext data from wpa_driver_wext_init()
1033 * Shut down driver interface and processing of driver events. Free
1034 * private data buffer if one was allocated in wpa_driver_wext_init().
1036 void wpa_driver_wext_deinit(void *priv)
1038 struct wpa_driver_wext_data *drv = priv;
1041 eloop_cancel_timeout(wpa_driver_wext_scan_timeout, drv, drv->ctx);
1044 * Clear possibly configured driver parameters in order to make it
1045 * easier to use the driver after wpa_supplicant has been terminated.
1047 wpa_driver_wext_disconnect(drv);
1049 wpa_driver_wext_send_oper_ifla(priv, 0, IF_OPER_UP);
1051 eloop_unregister_read_sock(drv->event_sock);
1052 if (drv->mlme_sock >= 0)
1053 eloop_unregister_read_sock(drv->mlme_sock);
1055 if (wpa_driver_wext_get_ifflags(drv, &flags) == 0)
1056 (void) wpa_driver_wext_set_ifflags(drv, flags & ~IFF_UP);
1058 close(drv->event_sock);
1059 close(drv->ioctl_sock);
1060 if (drv->mlme_sock >= 0)
1061 close(drv->mlme_sock);
1062 os_free(drv->assoc_req_ies);
1063 os_free(drv->assoc_resp_ies);
1069 * wpa_driver_wext_scan_timeout - Scan timeout to report scan completion
1070 * @eloop_ctx: Unused
1071 * @timeout_ctx: ctx argument given to wpa_driver_wext_init()
1073 * This function can be used as registered timeout when starting a scan to
1074 * generate a scan completed event if the driver does not report this.
1076 void wpa_driver_wext_scan_timeout(void *eloop_ctx, void *timeout_ctx)
1078 wpa_printf(MSG_DEBUG, "Scan timeout - try to get results");
1079 wpa_supplicant_event(timeout_ctx, EVENT_SCAN_RESULTS, NULL);
1084 * wpa_driver_wext_scan - Request the driver to initiate scan
1085 * @priv: Pointer to private wext data from wpa_driver_wext_init()
1086 * @ssid: Specific SSID to scan for (ProbeReq) or %NULL to scan for
1087 * all SSIDs (either active scan with wildcard SSID or passive
1089 * @ssid_len: Length of the SSID
1090 * Returns: 0 on success, -1 on failure
1092 int wpa_driver_wext_scan(void *priv, const u8 *ssid, size_t ssid_len)
1094 struct wpa_driver_wext_data *drv = priv;
1096 int ret = 0, timeout;
1097 struct iw_scan_req req;
1099 if (ssid_len > IW_ESSID_MAX_SIZE) {
1100 wpa_printf(MSG_DEBUG, "%s: too long SSID (%lu)",
1101 __FUNCTION__, (unsigned long) ssid_len);
1105 os_memset(&iwr, 0, sizeof(iwr));
1106 os_strlcpy(iwr.ifr_name, drv->ifname, IFNAMSIZ);
1108 if (ssid && ssid_len) {
1109 os_memset(&req, 0, sizeof(req));
1110 req.essid_len = ssid_len;
1111 req.bssid.sa_family = ARPHRD_ETHER;
1112 os_memset(req.bssid.sa_data, 0xff, ETH_ALEN);
1113 os_memcpy(req.essid, ssid, ssid_len);
1114 iwr.u.data.pointer = (caddr_t) &req;
1115 iwr.u.data.length = sizeof(req);
1116 iwr.u.data.flags = IW_SCAN_THIS_ESSID;
1119 if (ioctl(drv->ioctl_sock, SIOCSIWSCAN, &iwr) < 0) {
1120 perror("ioctl[SIOCSIWSCAN]");
1124 /* Not all drivers generate "scan completed" wireless event, so try to
1125 * read results after a timeout. */
1127 if (drv->scan_complete_events) {
1129 * The driver seems to deliver SIOCGIWSCAN events to notify
1130 * when scan is complete, so use longer timeout to avoid race
1131 * conditions with scanning and following association request.
1135 wpa_printf(MSG_DEBUG, "Scan requested (ret=%d) - scan timeout %d "
1136 "seconds", ret, timeout);
1137 eloop_cancel_timeout(wpa_driver_wext_scan_timeout, drv, drv->ctx);
1138 eloop_register_timeout(timeout, 0, wpa_driver_wext_scan_timeout, drv,
1145 static u8 * wpa_driver_wext_giwscan(struct wpa_driver_wext_data *drv,
1152 res_buf_len = IW_SCAN_MAX_DATA;
1154 res_buf = os_malloc(res_buf_len);
1155 if (res_buf == NULL)
1157 os_memset(&iwr, 0, sizeof(iwr));
1158 os_strlcpy(iwr.ifr_name, drv->ifname, IFNAMSIZ);
1159 iwr.u.data.pointer = res_buf;
1160 iwr.u.data.length = res_buf_len;
1162 if (ioctl(drv->ioctl_sock, SIOCGIWSCAN, &iwr) == 0)
1165 if (errno == E2BIG && res_buf_len < 65535) {
1169 if (res_buf_len > 65535)
1170 res_buf_len = 65535; /* 16-bit length field */
1171 wpa_printf(MSG_DEBUG, "Scan results did not fit - "
1172 "trying larger buffer (%lu bytes)",
1173 (unsigned long) res_buf_len);
1175 perror("ioctl[SIOCGIWSCAN]");
1181 if (iwr.u.data.length > res_buf_len) {
1185 *len = iwr.u.data.length;
1192 * Data structure for collecting WEXT scan results. This is needed to allow
1193 * the various methods of reporting IEs to be combined into a single IE buffer.
1195 struct wext_scan_data {
1196 struct wpa_scan_res res;
1205 static void wext_get_scan_mode(struct iw_event *iwe,
1206 struct wext_scan_data *res)
1208 if (iwe->u.mode == IW_MODE_ADHOC)
1209 res->res.caps |= IEEE80211_CAP_IBSS;
1210 else if (iwe->u.mode == IW_MODE_MASTER || iwe->u.mode == IW_MODE_INFRA)
1211 res->res.caps |= IEEE80211_CAP_ESS;
1215 static void wext_get_scan_ssid(struct iw_event *iwe,
1216 struct wext_scan_data *res, char *custom,
1219 int ssid_len = iwe->u.essid.length;
1220 if (custom + ssid_len > end)
1222 if (iwe->u.essid.flags &&
1224 ssid_len <= IW_ESSID_MAX_SIZE) {
1225 os_memcpy(res->ssid, custom, ssid_len);
1226 res->ssid_len = ssid_len;
1231 static void wext_get_scan_freq(struct iw_event *iwe,
1232 struct wext_scan_data *res)
1234 int divi = 1000000, i;
1236 if (iwe->u.freq.e == 0) {
1238 * Some drivers do not report frequency, but a channel.
1239 * Try to map this to frequency by assuming they are using
1240 * IEEE 802.11b/g. But don't overwrite a previously parsed
1241 * frequency if the driver sends both frequency and channel,
1242 * since the driver may be sending an A-band channel that we
1243 * don't handle here.
1249 if (iwe->u.freq.m >= 1 && iwe->u.freq.m <= 13) {
1250 res->res.freq = 2407 + 5 * iwe->u.freq.m;
1252 } else if (iwe->u.freq.m == 14) {
1253 res->res.freq = 2484;
1258 if (iwe->u.freq.e > 6) {
1259 wpa_printf(MSG_DEBUG, "Invalid freq in scan results (BSSID="
1260 MACSTR " m=%d e=%d)",
1261 MAC2STR(res->res.bssid), iwe->u.freq.m,
1266 for (i = 0; i < iwe->u.freq.e; i++)
1268 res->res.freq = iwe->u.freq.m / divi;
1272 static void wext_get_scan_qual(struct iw_event *iwe,
1273 struct wext_scan_data *res)
1275 res->res.qual = iwe->u.qual.qual;
1276 res->res.noise = iwe->u.qual.noise;
1277 res->res.level = iwe->u.qual.level;
1278 if (iwe->u.qual.updated & IW_QUAL_QUAL_INVALID)
1279 res->res.flags |= WPA_SCAN_QUAL_INVALID;
1280 if (iwe->u.qual.updated & IW_QUAL_LEVEL_INVALID)
1281 res->res.flags |= WPA_SCAN_LEVEL_INVALID;
1282 if (iwe->u.qual.updated & IW_QUAL_NOISE_INVALID)
1283 res->res.flags |= WPA_SCAN_NOISE_INVALID;
1284 if (iwe->u.qual.updated & IW_QUAL_DBM)
1285 res->res.flags |= WPA_SCAN_LEVEL_DBM;
1289 static void wext_get_scan_encode(struct iw_event *iwe,
1290 struct wext_scan_data *res)
1292 if (!(iwe->u.data.flags & IW_ENCODE_DISABLED))
1293 res->res.caps |= IEEE80211_CAP_PRIVACY;
1297 static void wext_get_scan_rate(struct iw_event *iwe,
1298 struct wext_scan_data *res, char *pos,
1302 char *custom = pos + IW_EV_LCP_LEN;
1307 if (custom + clen > end)
1310 while (((ssize_t) clen) >= (ssize_t) sizeof(struct iw_param)) {
1311 /* Note: may be misaligned, make a local, aligned copy */
1312 os_memcpy(&p, custom, sizeof(struct iw_param));
1313 if (p.value > maxrate)
1315 clen -= sizeof(struct iw_param);
1316 custom += sizeof(struct iw_param);
1319 /* Convert the maxrate from WE-style (b/s units) to
1320 * 802.11 rates (500000 b/s units).
1322 res->maxrate = maxrate / 500000;
1326 static void wext_get_scan_iwevgenie(struct iw_event *iwe,
1327 struct wext_scan_data *res, char *custom,
1330 char *genie, *gpos, *gend;
1333 if (iwe->u.data.length == 0)
1336 gpos = genie = custom;
1337 gend = genie + iwe->u.data.length;
1339 wpa_printf(MSG_INFO, "IWEVGENIE overflow");
1343 tmp = os_realloc(res->ie, res->ie_len + gend - gpos);
1346 os_memcpy(tmp + res->ie_len, gpos, gend - gpos);
1348 res->ie_len += gend - gpos;
1352 static void wext_get_scan_custom(struct iw_event *iwe,
1353 struct wext_scan_data *res, char *custom,
1359 clen = iwe->u.data.length;
1360 if (custom + clen > end)
1363 if (clen > 7 && os_strncmp(custom, "wpa_ie=", 7) == 0) {
1367 bytes = custom + clen - spos;
1368 if (bytes & 1 || bytes == 0)
1371 tmp = os_realloc(res->ie, res->ie_len + bytes);
1374 hexstr2bin(spos, tmp + res->ie_len, bytes);
1376 res->ie_len += bytes;
1377 } else if (clen > 7 && os_strncmp(custom, "rsn_ie=", 7) == 0) {
1381 bytes = custom + clen - spos;
1382 if (bytes & 1 || bytes == 0)
1385 tmp = os_realloc(res->ie, res->ie_len + bytes);
1388 hexstr2bin(spos, tmp + res->ie_len, bytes);
1390 res->ie_len += bytes;
1391 } else if (clen > 4 && os_strncmp(custom, "tsf=", 4) == 0) {
1396 bytes = custom + clen - spos;
1398 wpa_printf(MSG_INFO, "Invalid TSF length (%d)", bytes);
1402 hexstr2bin(spos, bin, bytes);
1403 res->res.tsf += WPA_GET_BE64(bin);
1408 static int wext_19_iw_point(struct wpa_driver_wext_data *drv, u16 cmd)
1410 return drv->we_version_compiled > 18 &&
1411 (cmd == SIOCGIWESSID || cmd == SIOCGIWENCODE ||
1412 cmd == IWEVGENIE || cmd == IWEVCUSTOM);
1416 static void wpa_driver_wext_add_scan_entry(struct wpa_scan_results *res,
1417 struct wext_scan_data *data)
1419 struct wpa_scan_res **tmp;
1420 struct wpa_scan_res *r;
1422 u8 *pos, *end, *ssid_ie = NULL, *rate_ie = NULL;
1424 /* Figure out whether we need to fake any IEs */
1426 end = pos + data->ie_len;
1427 while (pos && pos + 1 < end) {
1428 if (pos + 2 + pos[1] > end)
1430 if (pos[0] == WLAN_EID_SSID)
1432 else if (pos[0] == WLAN_EID_SUPP_RATES)
1434 else if (pos[0] == WLAN_EID_EXT_SUPP_RATES)
1440 if (ssid_ie == NULL)
1441 extra_len += 2 + data->ssid_len;
1442 if (rate_ie == NULL && data->maxrate)
1445 r = os_zalloc(sizeof(*r) + extra_len + data->ie_len);
1448 os_memcpy(r, &data->res, sizeof(*r));
1449 r->ie_len = extra_len + data->ie_len;
1450 pos = (u8 *) (r + 1);
1451 if (ssid_ie == NULL) {
1453 * Generate a fake SSID IE since the driver did not report
1456 *pos++ = WLAN_EID_SSID;
1457 *pos++ = data->ssid_len;
1458 os_memcpy(pos, data->ssid, data->ssid_len);
1459 pos += data->ssid_len;
1461 if (rate_ie == NULL && data->maxrate) {
1463 * Generate a fake Supported Rates IE since the driver did not
1464 * report a full IE list.
1466 *pos++ = WLAN_EID_SUPP_RATES;
1468 *pos++ = data->maxrate;
1471 os_memcpy(pos, data->ie, data->ie_len);
1473 tmp = os_realloc(res->res,
1474 (res->num + 1) * sizeof(struct wpa_scan_res *));
1479 tmp[res->num++] = r;
1485 * wpa_driver_wext_get_scan_results - Fetch the latest scan results
1486 * @priv: Pointer to private wext data from wpa_driver_wext_init()
1487 * Returns: Scan results on success, -1 on failure
1489 struct wpa_scan_results * wpa_driver_wext_get_scan_results(void *priv)
1491 struct wpa_driver_wext_data *drv = priv;
1492 size_t ap_num = 0, len;
1495 struct iw_event iwe_buf, *iwe = &iwe_buf;
1496 char *pos, *end, *custom;
1497 struct wpa_scan_results *res;
1498 struct wext_scan_data data;
1500 res_buf = wpa_driver_wext_giwscan(drv, &len);
1501 if (res_buf == NULL)
1507 res = os_zalloc(sizeof(*res));
1513 pos = (char *) res_buf;
1514 end = (char *) res_buf + len;
1515 os_memset(&data, 0, sizeof(data));
1517 while (pos + IW_EV_LCP_LEN <= end) {
1518 /* Event data may be unaligned, so make a local, aligned copy
1519 * before processing. */
1520 os_memcpy(&iwe_buf, pos, IW_EV_LCP_LEN);
1521 if (iwe->len <= IW_EV_LCP_LEN)
1524 custom = pos + IW_EV_POINT_LEN;
1525 if (wext_19_iw_point(drv, iwe->cmd)) {
1526 /* WE-19 removed the pointer from struct iw_point */
1527 char *dpos = (char *) &iwe_buf.u.data.length;
1528 int dlen = dpos - (char *) &iwe_buf;
1529 os_memcpy(dpos, pos + IW_EV_LCP_LEN,
1530 sizeof(struct iw_event) - dlen);
1532 os_memcpy(&iwe_buf, pos, sizeof(struct iw_event));
1533 custom += IW_EV_POINT_OFF;
1539 wpa_driver_wext_add_scan_entry(res, &data);
1542 os_memset(&data, 0, sizeof(data));
1543 os_memcpy(data.res.bssid,
1544 iwe->u.ap_addr.sa_data, ETH_ALEN);
1547 wext_get_scan_mode(iwe, &data);
1550 wext_get_scan_ssid(iwe, &data, custom, end);
1553 wext_get_scan_freq(iwe, &data);
1556 wext_get_scan_qual(iwe, &data);
1559 wext_get_scan_encode(iwe, &data);
1562 wext_get_scan_rate(iwe, &data, pos, end);
1565 wext_get_scan_iwevgenie(iwe, &data, custom, end);
1568 wext_get_scan_custom(iwe, &data, custom, end);
1577 wpa_driver_wext_add_scan_entry(res, &data);
1580 wpa_printf(MSG_DEBUG, "Received %lu bytes of scan results (%lu BSSes)",
1581 (unsigned long) len, (unsigned long) res->num);
1587 static int wpa_driver_wext_get_range(void *priv)
1589 struct wpa_driver_wext_data *drv = priv;
1590 struct iw_range *range;
1596 * Use larger buffer than struct iw_range in order to allow the
1597 * structure to grow in the future.
1599 buflen = sizeof(struct iw_range) + 500;
1600 range = os_zalloc(buflen);
1604 os_memset(&iwr, 0, sizeof(iwr));
1605 os_strlcpy(iwr.ifr_name, drv->ifname, IFNAMSIZ);
1606 iwr.u.data.pointer = (caddr_t) range;
1607 iwr.u.data.length = buflen;
1609 minlen = ((char *) &range->enc_capa) - (char *) range +
1610 sizeof(range->enc_capa);
1612 if (ioctl(drv->ioctl_sock, SIOCGIWRANGE, &iwr) < 0) {
1613 perror("ioctl[SIOCGIWRANGE]");
1616 } else if (iwr.u.data.length >= minlen &&
1617 range->we_version_compiled >= 18) {
1618 wpa_printf(MSG_DEBUG, "SIOCGIWRANGE: WE(compiled)=%d "
1619 "WE(source)=%d enc_capa=0x%x",
1620 range->we_version_compiled,
1621 range->we_version_source,
1623 drv->has_capability = 1;
1624 drv->we_version_compiled = range->we_version_compiled;
1625 if (range->enc_capa & IW_ENC_CAPA_WPA) {
1626 drv->capa.key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_WPA |
1627 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK;
1629 if (range->enc_capa & IW_ENC_CAPA_WPA2) {
1630 drv->capa.key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_WPA2 |
1631 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK;
1633 drv->capa.enc |= WPA_DRIVER_CAPA_ENC_WEP40 |
1634 WPA_DRIVER_CAPA_ENC_WEP104;
1635 if (range->enc_capa & IW_ENC_CAPA_CIPHER_TKIP)
1636 drv->capa.enc |= WPA_DRIVER_CAPA_ENC_TKIP;
1637 if (range->enc_capa & IW_ENC_CAPA_CIPHER_CCMP)
1638 drv->capa.enc |= WPA_DRIVER_CAPA_ENC_CCMP;
1639 if (range->enc_capa & IW_ENC_CAPA_4WAY_HANDSHAKE)
1640 drv->capa.flags |= WPA_DRIVER_FLAGS_4WAY_HANDSHAKE;
1641 drv->capa.max_scan_ssids = 1;
1643 wpa_printf(MSG_DEBUG, " capabilities: key_mgmt 0x%x enc 0x%x "
1645 drv->capa.key_mgmt, drv->capa.enc, drv->capa.flags);
1647 wpa_printf(MSG_DEBUG, "SIOCGIWRANGE: too old (short) data - "
1648 "assuming WPA is not supported");
1656 static int wpa_driver_wext_set_wpa(void *priv, int enabled)
1658 struct wpa_driver_wext_data *drv = priv;
1659 wpa_printf(MSG_DEBUG, "%s", __FUNCTION__);
1661 return wpa_driver_wext_set_auth_param(drv, IW_AUTH_WPA_ENABLED,
1666 static int wpa_driver_wext_set_psk(struct wpa_driver_wext_data *drv,
1669 struct iw_encode_ext *ext;
1673 wpa_printf(MSG_DEBUG, "%s", __FUNCTION__);
1675 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE))
1681 os_memset(&iwr, 0, sizeof(iwr));
1682 os_strlcpy(iwr.ifr_name, drv->ifname, IFNAMSIZ);
1684 ext = os_zalloc(sizeof(*ext) + PMK_LEN);
1688 iwr.u.encoding.pointer = (caddr_t) ext;
1689 iwr.u.encoding.length = sizeof(*ext) + PMK_LEN;
1690 ext->key_len = PMK_LEN;
1691 os_memcpy(&ext->key, psk, ext->key_len);
1692 ext->alg = IW_ENCODE_ALG_PMK;
1694 ret = ioctl(drv->ioctl_sock, SIOCSIWENCODEEXT, &iwr);
1696 perror("ioctl[SIOCSIWENCODEEXT] PMK");
1703 static int wpa_driver_wext_set_key_ext(void *priv, wpa_alg alg,
1704 const u8 *addr, int key_idx,
1705 int set_tx, const u8 *seq,
1707 const u8 *key, size_t key_len)
1709 struct wpa_driver_wext_data *drv = priv;
1712 struct iw_encode_ext *ext;
1714 if (seq_len > IW_ENCODE_SEQ_MAX_SIZE) {
1715 wpa_printf(MSG_DEBUG, "%s: Invalid seq_len %lu",
1716 __FUNCTION__, (unsigned long) seq_len);
1720 ext = os_zalloc(sizeof(*ext) + key_len);
1723 os_memset(&iwr, 0, sizeof(iwr));
1724 os_strlcpy(iwr.ifr_name, drv->ifname, IFNAMSIZ);
1725 iwr.u.encoding.flags = key_idx + 1;
1726 iwr.u.encoding.flags |= IW_ENCODE_TEMP;
1727 if (alg == WPA_ALG_NONE)
1728 iwr.u.encoding.flags |= IW_ENCODE_DISABLED;
1729 iwr.u.encoding.pointer = (caddr_t) ext;
1730 iwr.u.encoding.length = sizeof(*ext) + key_len;
1733 os_memcmp(addr, "\xff\xff\xff\xff\xff\xff", ETH_ALEN) == 0)
1734 ext->ext_flags |= IW_ENCODE_EXT_GROUP_KEY;
1736 ext->ext_flags |= IW_ENCODE_EXT_SET_TX_KEY;
1738 ext->addr.sa_family = ARPHRD_ETHER;
1740 os_memcpy(ext->addr.sa_data, addr, ETH_ALEN);
1742 os_memset(ext->addr.sa_data, 0xff, ETH_ALEN);
1743 if (key && key_len) {
1744 os_memcpy(ext + 1, key, key_len);
1745 ext->key_len = key_len;
1749 ext->alg = IW_ENCODE_ALG_NONE;
1752 ext->alg = IW_ENCODE_ALG_WEP;
1755 ext->alg = IW_ENCODE_ALG_TKIP;
1758 ext->alg = IW_ENCODE_ALG_CCMP;
1761 ext->alg = IW_ENCODE_ALG_PMK;
1763 #ifdef CONFIG_IEEE80211W
1765 ext->alg = IW_ENCODE_ALG_AES_CMAC;
1767 #endif /* CONFIG_IEEE80211W */
1769 wpa_printf(MSG_DEBUG, "%s: Unknown algorithm %d",
1775 if (seq && seq_len) {
1776 ext->ext_flags |= IW_ENCODE_EXT_RX_SEQ_VALID;
1777 os_memcpy(ext->rx_seq, seq, seq_len);
1780 if (ioctl(drv->ioctl_sock, SIOCSIWENCODEEXT, &iwr) < 0) {
1781 ret = errno == EOPNOTSUPP ? -2 : -1;
1782 if (errno == ENODEV) {
1784 * ndiswrapper seems to be returning incorrect error
1789 perror("ioctl[SIOCSIWENCODEEXT]");
1798 * wpa_driver_wext_set_key - Configure encryption key
1799 * @priv: Pointer to private wext data from wpa_driver_wext_init()
1800 * @priv: Private driver interface data
1801 * @alg: Encryption algorithm (%WPA_ALG_NONE, %WPA_ALG_WEP,
1802 * %WPA_ALG_TKIP, %WPA_ALG_CCMP); %WPA_ALG_NONE clears the key.
1803 * @addr: Address of the peer STA or ff:ff:ff:ff:ff:ff for
1804 * broadcast/default keys
1805 * @key_idx: key index (0..3), usually 0 for unicast keys
1806 * @set_tx: Configure this key as the default Tx key (only used when
1807 * driver does not support separate unicast/individual key
1808 * @seq: Sequence number/packet number, seq_len octets, the next
1809 * packet number to be used for in replay protection; configured
1810 * for Rx keys (in most cases, this is only used with broadcast
1811 * keys and set to zero for unicast keys)
1812 * @seq_len: Length of the seq, depends on the algorithm:
1813 * TKIP: 6 octets, CCMP: 6 octets
1814 * @key: Key buffer; TKIP: 16-byte temporal key, 8-byte Tx Mic key,
1816 * @key_len: Length of the key buffer in octets (WEP: 5 or 13,
1817 * TKIP: 32, CCMP: 16)
1818 * Returns: 0 on success, -1 on failure
1820 * This function uses SIOCSIWENCODEEXT by default, but tries to use
1821 * SIOCSIWENCODE if the extended ioctl fails when configuring a WEP key.
1823 int wpa_driver_wext_set_key(void *priv, wpa_alg alg,
1824 const u8 *addr, int key_idx,
1825 int set_tx, const u8 *seq, size_t seq_len,
1826 const u8 *key, size_t key_len)
1828 struct wpa_driver_wext_data *drv = priv;
1832 wpa_printf(MSG_DEBUG, "%s: alg=%d key_idx=%d set_tx=%d seq_len=%lu "
1834 __FUNCTION__, alg, key_idx, set_tx,
1835 (unsigned long) seq_len, (unsigned long) key_len);
1837 ret = wpa_driver_wext_set_key_ext(drv, alg, addr, key_idx, set_tx,
1838 seq, seq_len, key, key_len);
1843 (alg == WPA_ALG_NONE || alg == WPA_ALG_WEP)) {
1844 wpa_printf(MSG_DEBUG, "Driver did not support "
1845 "SIOCSIWENCODEEXT, trying SIOCSIWENCODE");
1848 wpa_printf(MSG_DEBUG, "Driver did not support "
1849 "SIOCSIWENCODEEXT");
1853 os_memset(&iwr, 0, sizeof(iwr));
1854 os_strlcpy(iwr.ifr_name, drv->ifname, IFNAMSIZ);
1855 iwr.u.encoding.flags = key_idx + 1;
1856 iwr.u.encoding.flags |= IW_ENCODE_TEMP;
1857 if (alg == WPA_ALG_NONE)
1858 iwr.u.encoding.flags |= IW_ENCODE_DISABLED;
1859 iwr.u.encoding.pointer = (caddr_t) key;
1860 iwr.u.encoding.length = key_len;
1862 if (ioctl(drv->ioctl_sock, SIOCSIWENCODE, &iwr) < 0) {
1863 perror("ioctl[SIOCSIWENCODE]");
1867 if (set_tx && alg != WPA_ALG_NONE) {
1868 os_memset(&iwr, 0, sizeof(iwr));
1869 os_strlcpy(iwr.ifr_name, drv->ifname, IFNAMSIZ);
1870 iwr.u.encoding.flags = key_idx + 1;
1871 iwr.u.encoding.flags |= IW_ENCODE_TEMP;
1872 iwr.u.encoding.pointer = (caddr_t) NULL;
1873 iwr.u.encoding.length = 0;
1874 if (ioctl(drv->ioctl_sock, SIOCSIWENCODE, &iwr) < 0) {
1875 perror("ioctl[SIOCSIWENCODE] (set_tx)");
1884 static int wpa_driver_wext_set_countermeasures(void *priv,
1887 struct wpa_driver_wext_data *drv = priv;
1888 wpa_printf(MSG_DEBUG, "%s", __FUNCTION__);
1889 return wpa_driver_wext_set_auth_param(drv,
1890 IW_AUTH_TKIP_COUNTERMEASURES,
1895 static int wpa_driver_wext_set_drop_unencrypted(void *priv,
1898 struct wpa_driver_wext_data *drv = priv;
1899 wpa_printf(MSG_DEBUG, "%s", __FUNCTION__);
1900 drv->use_crypt = enabled;
1901 return wpa_driver_wext_set_auth_param(drv, IW_AUTH_DROP_UNENCRYPTED,
1906 static int wpa_driver_wext_mlme(struct wpa_driver_wext_data *drv,
1907 const u8 *addr, int cmd, int reason_code)
1910 struct iw_mlme mlme;
1913 os_memset(&iwr, 0, sizeof(iwr));
1914 os_strlcpy(iwr.ifr_name, drv->ifname, IFNAMSIZ);
1915 os_memset(&mlme, 0, sizeof(mlme));
1917 mlme.reason_code = reason_code;
1918 mlme.addr.sa_family = ARPHRD_ETHER;
1919 os_memcpy(mlme.addr.sa_data, addr, ETH_ALEN);
1920 iwr.u.data.pointer = (caddr_t) &mlme;
1921 iwr.u.data.length = sizeof(mlme);
1923 if (ioctl(drv->ioctl_sock, SIOCSIWMLME, &iwr) < 0) {
1924 perror("ioctl[SIOCSIWMLME]");
1932 static void wpa_driver_wext_disconnect(struct wpa_driver_wext_data *drv)
1935 const u8 null_bssid[ETH_ALEN] = { 0, 0, 0, 0, 0, 0 };
1940 * Only force-disconnect when the card is in infrastructure mode,
1941 * otherwise the driver might interpret the cleared BSSID and random
1942 * SSID as an attempt to create a new ad-hoc network.
1944 os_memset(&iwr, 0, sizeof(iwr));
1945 os_strlcpy(iwr.ifr_name, drv->ifname, IFNAMSIZ);
1946 if (ioctl(drv->ioctl_sock, SIOCGIWMODE, &iwr) < 0) {
1947 perror("ioctl[SIOCGIWMODE]");
1948 iwr.u.mode = IW_MODE_INFRA;
1951 if (iwr.u.mode == IW_MODE_INFRA) {
1953 * Clear the BSSID selection and set a random SSID to make sure
1954 * the driver will not be trying to associate with something
1955 * even if it does not understand SIOCSIWMLME commands (or
1956 * tries to associate automatically after deauth/disassoc).
1958 wpa_driver_wext_set_bssid(drv, null_bssid);
1960 for (i = 0; i < 32; i++)
1961 ssid[i] = rand() & 0xFF;
1962 wpa_driver_wext_set_ssid(drv, ssid, 32);
1967 static int wpa_driver_wext_deauthenticate(void *priv, const u8 *addr,
1970 struct wpa_driver_wext_data *drv = priv;
1972 wpa_printf(MSG_DEBUG, "%s", __FUNCTION__);
1973 ret = wpa_driver_wext_mlme(drv, addr, IW_MLME_DEAUTH, reason_code);
1974 wpa_driver_wext_disconnect(drv);
1979 static int wpa_driver_wext_disassociate(void *priv, const u8 *addr,
1982 struct wpa_driver_wext_data *drv = priv;
1984 wpa_printf(MSG_DEBUG, "%s", __FUNCTION__);
1985 ret = wpa_driver_wext_mlme(drv, addr, IW_MLME_DISASSOC, reason_code);
1986 wpa_driver_wext_disconnect(drv);
1991 static int wpa_driver_wext_set_gen_ie(void *priv, const u8 *ie,
1994 struct wpa_driver_wext_data *drv = priv;
1998 os_memset(&iwr, 0, sizeof(iwr));
1999 os_strlcpy(iwr.ifr_name, drv->ifname, IFNAMSIZ);
2000 iwr.u.data.pointer = (caddr_t) ie;
2001 iwr.u.data.length = ie_len;
2003 if (ioctl(drv->ioctl_sock, SIOCSIWGENIE, &iwr) < 0) {
2004 perror("ioctl[SIOCSIWGENIE]");
2012 int wpa_driver_wext_cipher2wext(int cipher)
2016 return IW_AUTH_CIPHER_NONE;
2018 return IW_AUTH_CIPHER_WEP40;
2020 return IW_AUTH_CIPHER_TKIP;
2022 return IW_AUTH_CIPHER_CCMP;
2024 return IW_AUTH_CIPHER_WEP104;
2031 int wpa_driver_wext_keymgmt2wext(int keymgmt)
2034 case KEY_MGMT_802_1X:
2035 case KEY_MGMT_802_1X_NO_WPA:
2036 return IW_AUTH_KEY_MGMT_802_1X;
2038 return IW_AUTH_KEY_MGMT_PSK;
2046 wpa_driver_wext_auth_alg_fallback(struct wpa_driver_wext_data *drv,
2047 struct wpa_driver_associate_params *params)
2052 wpa_printf(MSG_DEBUG, "WEXT: Driver did not support "
2053 "SIOCSIWAUTH for AUTH_ALG, trying SIOCSIWENCODE");
2055 os_memset(&iwr, 0, sizeof(iwr));
2056 os_strlcpy(iwr.ifr_name, drv->ifname, IFNAMSIZ);
2057 /* Just changing mode, not actual keys */
2058 iwr.u.encoding.flags = 0;
2059 iwr.u.encoding.pointer = (caddr_t) NULL;
2060 iwr.u.encoding.length = 0;
2063 * Note: IW_ENCODE_{OPEN,RESTRICTED} can be interpreted to mean two
2064 * different things. Here they are used to indicate Open System vs.
2065 * Shared Key authentication algorithm. However, some drivers may use
2066 * them to select between open/restricted WEP encrypted (open = allow
2067 * both unencrypted and encrypted frames; restricted = only allow
2068 * encrypted frames).
2071 if (!drv->use_crypt) {
2072 iwr.u.encoding.flags |= IW_ENCODE_DISABLED;
2074 if (params->auth_alg & AUTH_ALG_OPEN_SYSTEM)
2075 iwr.u.encoding.flags |= IW_ENCODE_OPEN;
2076 if (params->auth_alg & AUTH_ALG_SHARED_KEY)
2077 iwr.u.encoding.flags |= IW_ENCODE_RESTRICTED;
2080 if (ioctl(drv->ioctl_sock, SIOCSIWENCODE, &iwr) < 0) {
2081 perror("ioctl[SIOCSIWENCODE]");
2089 int wpa_driver_wext_associate(void *priv,
2090 struct wpa_driver_associate_params *params)
2092 struct wpa_driver_wext_data *drv = priv;
2094 int allow_unencrypted_eapol;
2097 wpa_printf(MSG_DEBUG, "%s", __FUNCTION__);
2100 * If the driver did not support SIOCSIWAUTH, fallback to
2101 * SIOCSIWENCODE here.
2103 if (drv->auth_alg_fallback &&
2104 wpa_driver_wext_auth_alg_fallback(drv, params) < 0)
2107 if (!params->bssid &&
2108 wpa_driver_wext_set_bssid(drv, NULL) < 0)
2111 /* TODO: should consider getting wpa version and cipher/key_mgmt suites
2112 * from configuration, not from here, where only the selected suite is
2114 if (wpa_driver_wext_set_gen_ie(drv, params->wpa_ie, params->wpa_ie_len)
2117 if (params->wpa_ie == NULL || params->wpa_ie_len == 0)
2118 value = IW_AUTH_WPA_VERSION_DISABLED;
2119 else if (params->wpa_ie[0] == WLAN_EID_RSN)
2120 value = IW_AUTH_WPA_VERSION_WPA2;
2122 value = IW_AUTH_WPA_VERSION_WPA;
2123 if (wpa_driver_wext_set_auth_param(drv,
2124 IW_AUTH_WPA_VERSION, value) < 0)
2126 value = wpa_driver_wext_cipher2wext(params->pairwise_suite);
2127 if (wpa_driver_wext_set_auth_param(drv,
2128 IW_AUTH_CIPHER_PAIRWISE, value) < 0)
2130 value = wpa_driver_wext_cipher2wext(params->group_suite);
2131 if (wpa_driver_wext_set_auth_param(drv,
2132 IW_AUTH_CIPHER_GROUP, value) < 0)
2134 value = wpa_driver_wext_keymgmt2wext(params->key_mgmt_suite);
2135 if (wpa_driver_wext_set_auth_param(drv,
2136 IW_AUTH_KEY_MGMT, value) < 0)
2138 value = params->key_mgmt_suite != KEY_MGMT_NONE ||
2139 params->pairwise_suite != CIPHER_NONE ||
2140 params->group_suite != CIPHER_NONE ||
2142 if (wpa_driver_wext_set_auth_param(drv,
2143 IW_AUTH_PRIVACY_INVOKED, value) < 0)
2146 /* Allow unencrypted EAPOL messages even if pairwise keys are set when
2147 * not using WPA. IEEE 802.1X specifies that these frames are not
2148 * encrypted, but WPA encrypts them when pairwise keys are in use. */
2149 if (params->key_mgmt_suite == KEY_MGMT_802_1X ||
2150 params->key_mgmt_suite == KEY_MGMT_PSK)
2151 allow_unencrypted_eapol = 0;
2153 allow_unencrypted_eapol = 1;
2155 if (wpa_driver_wext_set_psk(drv, params->psk) < 0)
2157 if (wpa_driver_wext_set_auth_param(drv,
2158 IW_AUTH_RX_UNENCRYPTED_EAPOL,
2159 allow_unencrypted_eapol) < 0)
2161 #ifdef CONFIG_IEEE80211W
2162 switch (params->mgmt_frame_protection) {
2163 case NO_MGMT_FRAME_PROTECTION:
2164 value = IW_AUTH_MFP_DISABLED;
2166 case MGMT_FRAME_PROTECTION_OPTIONAL:
2167 value = IW_AUTH_MFP_OPTIONAL;
2169 case MGMT_FRAME_PROTECTION_REQUIRED:
2170 value = IW_AUTH_MFP_REQUIRED;
2173 if (wpa_driver_wext_set_auth_param(drv, IW_AUTH_MFP, value) < 0)
2175 #endif /* CONFIG_IEEE80211W */
2176 if (params->freq && wpa_driver_wext_set_freq(drv, params->freq) < 0)
2178 if (wpa_driver_wext_set_ssid(drv, params->ssid, params->ssid_len) < 0)
2180 if (params->bssid &&
2181 wpa_driver_wext_set_bssid(drv, params->bssid) < 0)
2188 static int wpa_driver_wext_set_auth_alg(void *priv, int auth_alg)
2190 struct wpa_driver_wext_data *drv = priv;
2193 if (auth_alg & AUTH_ALG_OPEN_SYSTEM)
2194 algs |= IW_AUTH_ALG_OPEN_SYSTEM;
2195 if (auth_alg & AUTH_ALG_SHARED_KEY)
2196 algs |= IW_AUTH_ALG_SHARED_KEY;
2197 if (auth_alg & AUTH_ALG_LEAP)
2198 algs |= IW_AUTH_ALG_LEAP;
2200 /* at least one algorithm should be set */
2201 algs = IW_AUTH_ALG_OPEN_SYSTEM;
2204 res = wpa_driver_wext_set_auth_param(drv, IW_AUTH_80211_AUTH_ALG,
2206 drv->auth_alg_fallback = res == -2;
2212 * wpa_driver_wext_set_mode - Set wireless mode (infra/adhoc), SIOCSIWMODE
2213 * @priv: Pointer to private wext data from wpa_driver_wext_init()
2214 * @mode: 0 = infra/BSS (associate with an AP), 1 = adhoc/IBSS
2215 * Returns: 0 on success, -1 on failure
2217 int wpa_driver_wext_set_mode(void *priv, int mode)
2219 struct wpa_driver_wext_data *drv = priv;
2221 int ret = -1, flags;
2222 unsigned int new_mode = mode ? IW_MODE_ADHOC : IW_MODE_INFRA;
2224 os_memset(&iwr, 0, sizeof(iwr));
2225 os_strlcpy(iwr.ifr_name, drv->ifname, IFNAMSIZ);
2226 iwr.u.mode = new_mode;
2227 if (ioctl(drv->ioctl_sock, SIOCSIWMODE, &iwr) == 0) {
2232 if (errno != EBUSY) {
2233 perror("ioctl[SIOCSIWMODE]");
2237 /* mac80211 doesn't allow mode changes while the device is up, so if
2238 * the device isn't in the mode we're about to change to, take device
2239 * down, try to set the mode again, and bring it back up.
2241 if (ioctl(drv->ioctl_sock, SIOCGIWMODE, &iwr) < 0) {
2242 perror("ioctl[SIOCGIWMODE]");
2246 if (iwr.u.mode == new_mode) {
2251 if (wpa_driver_wext_get_ifflags(drv, &flags) == 0) {
2252 (void) wpa_driver_wext_set_ifflags(drv, flags & ~IFF_UP);
2254 /* Try to set the mode again while the interface is down */
2255 iwr.u.mode = new_mode;
2256 if (ioctl(drv->ioctl_sock, SIOCSIWMODE, &iwr) < 0)
2257 perror("ioctl[SIOCSIWMODE]");
2261 /* Ignore return value of get_ifflags to ensure that the device
2262 * is always up like it was before this function was called.
2264 (void) wpa_driver_wext_get_ifflags(drv, &flags);
2265 (void) wpa_driver_wext_set_ifflags(drv, flags | IFF_UP);
2273 static int wpa_driver_wext_pmksa(struct wpa_driver_wext_data *drv,
2274 u32 cmd, const u8 *bssid, const u8 *pmkid)
2277 struct iw_pmksa pmksa;
2280 os_memset(&iwr, 0, sizeof(iwr));
2281 os_strlcpy(iwr.ifr_name, drv->ifname, IFNAMSIZ);
2282 os_memset(&pmksa, 0, sizeof(pmksa));
2284 pmksa.bssid.sa_family = ARPHRD_ETHER;
2286 os_memcpy(pmksa.bssid.sa_data, bssid, ETH_ALEN);
2288 os_memcpy(pmksa.pmkid, pmkid, IW_PMKID_LEN);
2289 iwr.u.data.pointer = (caddr_t) &pmksa;
2290 iwr.u.data.length = sizeof(pmksa);
2292 if (ioctl(drv->ioctl_sock, SIOCSIWPMKSA, &iwr) < 0) {
2293 if (errno != EOPNOTSUPP)
2294 perror("ioctl[SIOCSIWPMKSA]");
2302 static int wpa_driver_wext_add_pmkid(void *priv, const u8 *bssid,
2305 struct wpa_driver_wext_data *drv = priv;
2306 return wpa_driver_wext_pmksa(drv, IW_PMKSA_ADD, bssid, pmkid);
2310 static int wpa_driver_wext_remove_pmkid(void *priv, const u8 *bssid,
2313 struct wpa_driver_wext_data *drv = priv;
2314 return wpa_driver_wext_pmksa(drv, IW_PMKSA_REMOVE, bssid, pmkid);
2318 static int wpa_driver_wext_flush_pmkid(void *priv)
2320 struct wpa_driver_wext_data *drv = priv;
2321 return wpa_driver_wext_pmksa(drv, IW_PMKSA_FLUSH, NULL, NULL);
2325 int wpa_driver_wext_get_capa(void *priv, struct wpa_driver_capa *capa)
2327 struct wpa_driver_wext_data *drv = priv;
2328 if (!drv->has_capability)
2330 os_memcpy(capa, &drv->capa, sizeof(*capa));
2335 int wpa_driver_wext_alternative_ifindex(struct wpa_driver_wext_data *drv,
2338 if (ifname == NULL) {
2343 drv->ifindex2 = if_nametoindex(ifname);
2344 if (drv->ifindex2 <= 0)
2347 wpa_printf(MSG_DEBUG, "Added alternative ifindex %d (%s) for "
2348 "wireless events", drv->ifindex2, ifname);
2354 int wpa_driver_wext_set_operstate(void *priv, int state)
2356 struct wpa_driver_wext_data *drv = priv;
2358 wpa_printf(MSG_DEBUG, "%s: operstate %d->%d (%s)",
2359 __func__, drv->operstate, state, state ? "UP" : "DORMANT");
2360 drv->operstate = state;
2361 return wpa_driver_wext_send_oper_ifla(
2362 drv, -1, state ? IF_OPER_UP : IF_OPER_DORMANT);
2366 int wpa_driver_wext_get_version(struct wpa_driver_wext_data *drv)
2368 return drv->we_version_compiled;
2372 const struct wpa_driver_ops wpa_driver_wext_ops = {
2374 .desc = "Linux wireless extensions (generic)",
2375 .get_bssid = wpa_driver_wext_get_bssid,
2376 .get_ssid = wpa_driver_wext_get_ssid,
2377 .set_wpa = wpa_driver_wext_set_wpa,
2378 .set_key = wpa_driver_wext_set_key,
2379 .set_countermeasures = wpa_driver_wext_set_countermeasures,
2380 .set_drop_unencrypted = wpa_driver_wext_set_drop_unencrypted,
2381 .scan = wpa_driver_wext_scan,
2382 .get_scan_results2 = wpa_driver_wext_get_scan_results,
2383 .deauthenticate = wpa_driver_wext_deauthenticate,
2384 .disassociate = wpa_driver_wext_disassociate,
2385 .set_mode = wpa_driver_wext_set_mode,
2386 .associate = wpa_driver_wext_associate,
2387 .set_auth_alg = wpa_driver_wext_set_auth_alg,
2388 .init = wpa_driver_wext_init,
2389 .deinit = wpa_driver_wext_deinit,
2390 .add_pmkid = wpa_driver_wext_add_pmkid,
2391 .remove_pmkid = wpa_driver_wext_remove_pmkid,
2392 .flush_pmkid = wpa_driver_wext_flush_pmkid,
2393 .get_capa = wpa_driver_wext_get_capa,
2394 .set_operstate = wpa_driver_wext_set_operstate,