2 * Driver interaction with generic Linux Wireless Extensions
3 * Copyright (c) 2003-2010, 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>
24 #include <net/if_arp.h>
26 #include "wireless_copy.h"
29 #include "common/ieee802_11_defs.h"
30 #include "common/wpa_common.h"
31 #include "priv_netlink.h"
33 #include "linux_ioctl.h"
35 #include "driver_wext.h"
38 static int wpa_driver_wext_flush_pmkid(void *priv
);
39 static int wpa_driver_wext_get_range(void *priv
);
40 static int wpa_driver_wext_finish_drv_init(struct wpa_driver_wext_data
*drv
);
41 static void wpa_driver_wext_disconnect(struct wpa_driver_wext_data
*drv
);
42 static int wpa_driver_wext_set_auth_alg(void *priv
, int auth_alg
);
45 int wpa_driver_wext_set_auth_param(struct wpa_driver_wext_data
*drv
,
51 os_memset(&iwr
, 0, sizeof(iwr
));
52 os_strlcpy(iwr
.ifr_name
, drv
->ifname
, IFNAMSIZ
);
53 iwr
.u
.param
.flags
= idx
& IW_AUTH_INDEX
;
54 iwr
.u
.param
.value
= value
;
56 if (ioctl(drv
->ioctl_sock
, SIOCSIWAUTH
, &iwr
) < 0) {
57 if (errno
!= EOPNOTSUPP
) {
58 wpa_printf(MSG_DEBUG
, "WEXT: SIOCSIWAUTH(param %d "
59 "value 0x%x) failed: %s)",
60 idx
, value
, strerror(errno
));
62 ret
= errno
== EOPNOTSUPP
? -2 : -1;
70 * wpa_driver_wext_get_bssid - Get BSSID, SIOCGIWAP
71 * @priv: Pointer to private wext data from wpa_driver_wext_init()
72 * @bssid: Buffer for BSSID
73 * Returns: 0 on success, -1 on failure
75 int wpa_driver_wext_get_bssid(void *priv
, u8
*bssid
)
77 struct wpa_driver_wext_data
*drv
= priv
;
81 os_memset(&iwr
, 0, sizeof(iwr
));
82 os_strlcpy(iwr
.ifr_name
, drv
->ifname
, IFNAMSIZ
);
84 if (ioctl(drv
->ioctl_sock
, SIOCGIWAP
, &iwr
) < 0) {
85 perror("ioctl[SIOCGIWAP]");
88 os_memcpy(bssid
, iwr
.u
.ap_addr
.sa_data
, ETH_ALEN
);
95 * wpa_driver_wext_set_bssid - Set BSSID, SIOCSIWAP
96 * @priv: Pointer to private wext data from wpa_driver_wext_init()
98 * Returns: 0 on success, -1 on failure
100 int wpa_driver_wext_set_bssid(void *priv
, const u8
*bssid
)
102 struct wpa_driver_wext_data
*drv
= priv
;
106 os_memset(&iwr
, 0, sizeof(iwr
));
107 os_strlcpy(iwr
.ifr_name
, drv
->ifname
, IFNAMSIZ
);
108 iwr
.u
.ap_addr
.sa_family
= ARPHRD_ETHER
;
110 os_memcpy(iwr
.u
.ap_addr
.sa_data
, bssid
, ETH_ALEN
);
112 os_memset(iwr
.u
.ap_addr
.sa_data
, 0, ETH_ALEN
);
114 if (ioctl(drv
->ioctl_sock
, SIOCSIWAP
, &iwr
) < 0) {
115 perror("ioctl[SIOCSIWAP]");
124 * wpa_driver_wext_get_ssid - Get SSID, SIOCGIWESSID
125 * @priv: Pointer to private wext data from wpa_driver_wext_init()
126 * @ssid: Buffer for the SSID; must be at least 32 bytes long
127 * Returns: SSID length on success, -1 on failure
129 int wpa_driver_wext_get_ssid(void *priv
, u8
*ssid
)
131 struct wpa_driver_wext_data
*drv
= priv
;
135 os_memset(&iwr
, 0, sizeof(iwr
));
136 os_strlcpy(iwr
.ifr_name
, drv
->ifname
, IFNAMSIZ
);
137 iwr
.u
.essid
.pointer
= (caddr_t
) ssid
;
138 iwr
.u
.essid
.length
= 32;
140 if (ioctl(drv
->ioctl_sock
, SIOCGIWESSID
, &iwr
) < 0) {
141 perror("ioctl[SIOCGIWESSID]");
144 ret
= iwr
.u
.essid
.length
;
147 /* Some drivers include nul termination in the SSID, so let's
148 * remove it here before further processing. WE-21 changes this
149 * to explicitly require the length _not_ to include nul
151 if (ret
> 0 && ssid
[ret
- 1] == '\0' &&
152 drv
->we_version_compiled
< 21)
161 * wpa_driver_wext_set_ssid - Set SSID, SIOCSIWESSID
162 * @priv: Pointer to private wext data from wpa_driver_wext_init()
164 * @ssid_len: Length of SSID (0..32)
165 * Returns: 0 on success, -1 on failure
167 int wpa_driver_wext_set_ssid(void *priv
, const u8
*ssid
, size_t ssid_len
)
169 struct wpa_driver_wext_data
*drv
= priv
;
177 os_memset(&iwr
, 0, sizeof(iwr
));
178 os_strlcpy(iwr
.ifr_name
, drv
->ifname
, IFNAMSIZ
);
179 /* flags: 1 = ESSID is active, 0 = not (promiscuous) */
180 iwr
.u
.essid
.flags
= (ssid_len
!= 0);
181 os_memset(buf
, 0, sizeof(buf
));
182 os_memcpy(buf
, ssid
, ssid_len
);
183 iwr
.u
.essid
.pointer
= (caddr_t
) buf
;
184 if (drv
->we_version_compiled
< 21) {
185 /* For historic reasons, set SSID length to include one extra
186 * character, C string nul termination, even though SSID is
187 * really an octet string that should not be presented as a C
188 * string. Some Linux drivers decrement the length by one and
189 * can thus end up missing the last octet of the SSID if the
190 * length is not incremented here. WE-21 changes this to
191 * explicitly require the length _not_ to include nul
196 iwr
.u
.essid
.length
= ssid_len
;
198 if (ioctl(drv
->ioctl_sock
, SIOCSIWESSID
, &iwr
) < 0) {
199 perror("ioctl[SIOCSIWESSID]");
208 * wpa_driver_wext_set_freq - Set frequency/channel, SIOCSIWFREQ
209 * @priv: Pointer to private wext data from wpa_driver_wext_init()
210 * @freq: Frequency in MHz
211 * Returns: 0 on success, -1 on failure
213 int wpa_driver_wext_set_freq(void *priv
, int freq
)
215 struct wpa_driver_wext_data
*drv
= priv
;
219 os_memset(&iwr
, 0, sizeof(iwr
));
220 os_strlcpy(iwr
.ifr_name
, drv
->ifname
, IFNAMSIZ
);
221 iwr
.u
.freq
.m
= freq
* 100000;
224 if (ioctl(drv
->ioctl_sock
, SIOCSIWFREQ
, &iwr
) < 0) {
225 perror("ioctl[SIOCSIWFREQ]");
234 wpa_driver_wext_event_wireless_custom(void *ctx
, char *custom
)
236 union wpa_event_data data
;
238 wpa_printf(MSG_MSGDUMP
, "WEXT: Custom wireless event: '%s'",
241 os_memset(&data
, 0, sizeof(data
));
243 if (os_strncmp(custom
, "MLME-MICHAELMICFAILURE.indication", 33) == 0) {
244 data
.michael_mic_failure
.unicast
=
245 os_strstr(custom
, " unicast ") != NULL
;
246 /* TODO: parse parameters(?) */
247 wpa_supplicant_event(ctx
, EVENT_MICHAEL_MIC_FAILURE
, &data
);
248 } else if (os_strncmp(custom
, "ASSOCINFO(ReqIEs=", 17) == 0) {
251 u8
*req_ies
= NULL
, *resp_ies
= NULL
;
255 bytes
= strspn(spos
, "0123456789abcdefABCDEF");
256 if (!bytes
|| (bytes
& 1))
260 req_ies
= os_malloc(bytes
);
261 if (req_ies
== NULL
||
262 hexstr2bin(spos
, req_ies
, bytes
) < 0)
264 data
.assoc_info
.req_ies
= req_ies
;
265 data
.assoc_info
.req_ies_len
= bytes
;
269 data
.assoc_info
.resp_ies
= NULL
;
270 data
.assoc_info
.resp_ies_len
= 0;
272 if (os_strncmp(spos
, " RespIEs=", 9) == 0) {
275 bytes
= strspn(spos
, "0123456789abcdefABCDEF");
276 if (!bytes
|| (bytes
& 1))
280 resp_ies
= os_malloc(bytes
);
281 if (resp_ies
== NULL
||
282 hexstr2bin(spos
, resp_ies
, bytes
) < 0)
284 data
.assoc_info
.resp_ies
= resp_ies
;
285 data
.assoc_info
.resp_ies_len
= bytes
;
288 wpa_supplicant_event(ctx
, EVENT_ASSOCINFO
, &data
);
293 #ifdef CONFIG_PEERKEY
294 } else if (os_strncmp(custom
, "STKSTART.request=", 17) == 0) {
295 if (hwaddr_aton(custom
+ 17, data
.stkstart
.peer
)) {
296 wpa_printf(MSG_DEBUG
, "WEXT: unrecognized "
297 "STKSTART.request '%s'", custom
+ 17);
300 wpa_supplicant_event(ctx
, EVENT_STKSTART
, &data
);
301 #endif /* CONFIG_PEERKEY */
306 static int wpa_driver_wext_event_wireless_michaelmicfailure(
307 void *ctx
, const char *ev
, size_t len
)
309 const struct iw_michaelmicfailure
*mic
;
310 union wpa_event_data data
;
312 if (len
< sizeof(*mic
))
315 mic
= (const struct iw_michaelmicfailure
*) ev
;
317 wpa_printf(MSG_DEBUG
, "Michael MIC failure wireless event: "
318 "flags=0x%x src_addr=" MACSTR
, mic
->flags
,
319 MAC2STR(mic
->src_addr
.sa_data
));
321 os_memset(&data
, 0, sizeof(data
));
322 data
.michael_mic_failure
.unicast
= !(mic
->flags
& IW_MICFAILURE_GROUP
);
323 wpa_supplicant_event(ctx
, EVENT_MICHAEL_MIC_FAILURE
, &data
);
329 static int wpa_driver_wext_event_wireless_pmkidcand(
330 struct wpa_driver_wext_data
*drv
, const char *ev
, size_t len
)
332 const struct iw_pmkid_cand
*cand
;
333 union wpa_event_data data
;
336 if (len
< sizeof(*cand
))
339 cand
= (const struct iw_pmkid_cand
*) ev
;
340 addr
= (const u8
*) cand
->bssid
.sa_data
;
342 wpa_printf(MSG_DEBUG
, "PMKID candidate wireless event: "
343 "flags=0x%x index=%d bssid=" MACSTR
, cand
->flags
,
344 cand
->index
, MAC2STR(addr
));
346 os_memset(&data
, 0, sizeof(data
));
347 os_memcpy(data
.pmkid_candidate
.bssid
, addr
, ETH_ALEN
);
348 data
.pmkid_candidate
.index
= cand
->index
;
349 data
.pmkid_candidate
.preauth
= cand
->flags
& IW_PMKID_CAND_PREAUTH
;
350 wpa_supplicant_event(drv
->ctx
, EVENT_PMKID_CANDIDATE
, &data
);
356 static int wpa_driver_wext_event_wireless_assocreqie(
357 struct wpa_driver_wext_data
*drv
, const char *ev
, int len
)
362 wpa_hexdump(MSG_DEBUG
, "AssocReq IE wireless event", (const u8
*) ev
,
364 os_free(drv
->assoc_req_ies
);
365 drv
->assoc_req_ies
= os_malloc(len
);
366 if (drv
->assoc_req_ies
== NULL
) {
367 drv
->assoc_req_ies_len
= 0;
370 os_memcpy(drv
->assoc_req_ies
, ev
, len
);
371 drv
->assoc_req_ies_len
= len
;
377 static int wpa_driver_wext_event_wireless_assocrespie(
378 struct wpa_driver_wext_data
*drv
, const char *ev
, int len
)
383 wpa_hexdump(MSG_DEBUG
, "AssocResp IE wireless event", (const u8
*) ev
,
385 os_free(drv
->assoc_resp_ies
);
386 drv
->assoc_resp_ies
= os_malloc(len
);
387 if (drv
->assoc_resp_ies
== NULL
) {
388 drv
->assoc_resp_ies_len
= 0;
391 os_memcpy(drv
->assoc_resp_ies
, ev
, len
);
392 drv
->assoc_resp_ies_len
= len
;
398 static void wpa_driver_wext_event_assoc_ies(struct wpa_driver_wext_data
*drv
)
400 union wpa_event_data data
;
402 if (drv
->assoc_req_ies
== NULL
&& drv
->assoc_resp_ies
== NULL
)
405 os_memset(&data
, 0, sizeof(data
));
406 if (drv
->assoc_req_ies
) {
407 data
.assoc_info
.req_ies
= drv
->assoc_req_ies
;
408 data
.assoc_info
.req_ies_len
= drv
->assoc_req_ies_len
;
410 if (drv
->assoc_resp_ies
) {
411 data
.assoc_info
.resp_ies
= drv
->assoc_resp_ies
;
412 data
.assoc_info
.resp_ies_len
= drv
->assoc_resp_ies_len
;
415 wpa_supplicant_event(drv
->ctx
, EVENT_ASSOCINFO
, &data
);
417 os_free(drv
->assoc_req_ies
);
418 drv
->assoc_req_ies
= NULL
;
419 os_free(drv
->assoc_resp_ies
);
420 drv
->assoc_resp_ies
= NULL
;
424 static void wpa_driver_wext_event_wireless(struct wpa_driver_wext_data
*drv
,
427 struct iw_event iwe_buf
, *iwe
= &iwe_buf
;
428 char *pos
, *end
, *custom
, *buf
;
433 while (pos
+ IW_EV_LCP_LEN
<= end
) {
434 /* Event data may be unaligned, so make a local, aligned copy
435 * before processing. */
436 os_memcpy(&iwe_buf
, pos
, IW_EV_LCP_LEN
);
437 wpa_printf(MSG_DEBUG
, "Wireless event: cmd=0x%x len=%d",
439 if (iwe
->len
<= IW_EV_LCP_LEN
)
442 custom
= pos
+ IW_EV_POINT_LEN
;
443 if (drv
->we_version_compiled
> 18 &&
444 (iwe
->cmd
== IWEVMICHAELMICFAILURE
||
445 iwe
->cmd
== IWEVCUSTOM
||
446 iwe
->cmd
== IWEVASSOCREQIE
||
447 iwe
->cmd
== IWEVASSOCRESPIE
||
448 iwe
->cmd
== IWEVPMKIDCAND
)) {
449 /* WE-19 removed the pointer from struct iw_point */
450 char *dpos
= (char *) &iwe_buf
.u
.data
.length
;
451 int dlen
= dpos
- (char *) &iwe_buf
;
452 os_memcpy(dpos
, pos
+ IW_EV_LCP_LEN
,
453 sizeof(struct iw_event
) - dlen
);
455 os_memcpy(&iwe_buf
, pos
, sizeof(struct iw_event
));
456 custom
+= IW_EV_POINT_OFF
;
461 wpa_printf(MSG_DEBUG
, "Wireless event: new AP: "
463 MAC2STR((u8
*) iwe
->u
.ap_addr
.sa_data
));
464 if (is_zero_ether_addr(
465 (const u8
*) iwe
->u
.ap_addr
.sa_data
) ||
466 os_memcmp(iwe
->u
.ap_addr
.sa_data
,
467 "\x44\x44\x44\x44\x44\x44", ETH_ALEN
) ==
469 os_free(drv
->assoc_req_ies
);
470 drv
->assoc_req_ies
= NULL
;
471 os_free(drv
->assoc_resp_ies
);
472 drv
->assoc_resp_ies
= NULL
;
473 wpa_supplicant_event(drv
->ctx
, EVENT_DISASSOC
,
477 wpa_driver_wext_event_assoc_ies(drv
);
478 wpa_supplicant_event(drv
->ctx
, EVENT_ASSOC
,
482 case IWEVMICHAELMICFAILURE
:
483 if (custom
+ iwe
->u
.data
.length
> end
) {
484 wpa_printf(MSG_DEBUG
, "WEXT: Invalid "
485 "IWEVMICHAELMICFAILURE length");
488 wpa_driver_wext_event_wireless_michaelmicfailure(
489 drv
->ctx
, custom
, iwe
->u
.data
.length
);
492 if (custom
+ iwe
->u
.data
.length
> end
) {
493 wpa_printf(MSG_DEBUG
, "WEXT: Invalid "
494 "IWEVCUSTOM length");
497 buf
= os_malloc(iwe
->u
.data
.length
+ 1);
500 os_memcpy(buf
, custom
, iwe
->u
.data
.length
);
501 buf
[iwe
->u
.data
.length
] = '\0';
502 wpa_driver_wext_event_wireless_custom(drv
->ctx
, buf
);
506 drv
->scan_complete_events
= 1;
507 eloop_cancel_timeout(wpa_driver_wext_scan_timeout
,
509 wpa_supplicant_event(drv
->ctx
, EVENT_SCAN_RESULTS
,
513 if (custom
+ iwe
->u
.data
.length
> end
) {
514 wpa_printf(MSG_DEBUG
, "WEXT: Invalid "
515 "IWEVASSOCREQIE length");
518 wpa_driver_wext_event_wireless_assocreqie(
519 drv
, custom
, iwe
->u
.data
.length
);
521 case IWEVASSOCRESPIE
:
522 if (custom
+ iwe
->u
.data
.length
> end
) {
523 wpa_printf(MSG_DEBUG
, "WEXT: Invalid "
524 "IWEVASSOCRESPIE length");
527 wpa_driver_wext_event_wireless_assocrespie(
528 drv
, custom
, iwe
->u
.data
.length
);
531 if (custom
+ iwe
->u
.data
.length
> end
) {
532 wpa_printf(MSG_DEBUG
, "WEXT: Invalid "
533 "IWEVPMKIDCAND length");
536 wpa_driver_wext_event_wireless_pmkidcand(
537 drv
, custom
, iwe
->u
.data
.length
);
546 static void wpa_driver_wext_event_link(struct wpa_driver_wext_data
*drv
,
547 char *buf
, size_t len
, int del
)
549 union wpa_event_data event
;
551 os_memset(&event
, 0, sizeof(event
));
552 if (len
> sizeof(event
.interface_status
.ifname
))
553 len
= sizeof(event
.interface_status
.ifname
) - 1;
554 os_memcpy(event
.interface_status
.ifname
, buf
, len
);
555 event
.interface_status
.ievent
= del
? EVENT_INTERFACE_REMOVED
:
556 EVENT_INTERFACE_ADDED
;
558 wpa_printf(MSG_DEBUG
, "RTM_%sLINK, IFLA_IFNAME: Interface '%s' %s",
560 event
.interface_status
.ifname
,
561 del
? "removed" : "added");
563 if (os_strcmp(drv
->ifname
, event
.interface_status
.ifname
) == 0) {
570 wpa_supplicant_event(drv
->ctx
, EVENT_INTERFACE_STATUS
, &event
);
574 static int wpa_driver_wext_own_ifname(struct wpa_driver_wext_data
*drv
,
577 int attrlen
, rta_len
;
581 attr
= (struct rtattr
*) buf
;
583 rta_len
= RTA_ALIGN(sizeof(struct rtattr
));
584 while (RTA_OK(attr
, attrlen
)) {
585 if (attr
->rta_type
== IFLA_IFNAME
) {
586 if (os_strcmp(((char *) attr
) + rta_len
, drv
->ifname
)
592 attr
= RTA_NEXT(attr
, attrlen
);
599 static int wpa_driver_wext_own_ifindex(struct wpa_driver_wext_data
*drv
,
600 int ifindex
, u8
*buf
, size_t len
)
602 if (drv
->ifindex
== ifindex
|| drv
->ifindex2
== ifindex
)
605 if (drv
->if_removed
&& wpa_driver_wext_own_ifname(drv
, buf
, len
)) {
606 drv
->ifindex
= if_nametoindex(drv
->ifname
);
607 wpa_printf(MSG_DEBUG
, "WEXT: Update ifindex for a removed "
609 wpa_driver_wext_finish_drv_init(drv
);
617 static void wpa_driver_wext_event_rtm_newlink(void *ctx
, struct ifinfomsg
*ifi
,
620 struct wpa_driver_wext_data
*drv
= ctx
;
621 int attrlen
, rta_len
;
624 if (!wpa_driver_wext_own_ifindex(drv
, ifi
->ifi_index
, buf
, len
)) {
625 wpa_printf(MSG_DEBUG
, "Ignore event for foreign ifindex %d",
630 wpa_printf(MSG_DEBUG
, "RTM_NEWLINK: operstate=%d ifi_flags=0x%x "
632 drv
->operstate
, ifi
->ifi_flags
,
633 (ifi
->ifi_flags
& IFF_UP
) ? "[UP]" : "",
634 (ifi
->ifi_flags
& IFF_RUNNING
) ? "[RUNNING]" : "",
635 (ifi
->ifi_flags
& IFF_LOWER_UP
) ? "[LOWER_UP]" : "",
636 (ifi
->ifi_flags
& IFF_DORMANT
) ? "[DORMANT]" : "");
638 * Some drivers send the association event before the operup event--in
639 * this case, lifting operstate in wpa_driver_wext_set_operstate()
640 * fails. This will hit us when wpa_supplicant does not need to do
641 * IEEE 802.1X authentication
643 if (drv
->operstate
== 1 &&
644 (ifi
->ifi_flags
& (IFF_LOWER_UP
| IFF_DORMANT
)) == IFF_LOWER_UP
&&
645 !(ifi
->ifi_flags
& IFF_RUNNING
))
646 netlink_send_oper_ifla(drv
->netlink
, drv
->ifindex
,
650 attr
= (struct rtattr
*) buf
;
652 rta_len
= RTA_ALIGN(sizeof(struct rtattr
));
653 while (RTA_OK(attr
, attrlen
)) {
654 if (attr
->rta_type
== IFLA_WIRELESS
) {
655 wpa_driver_wext_event_wireless(
656 drv
, ((char *) attr
) + rta_len
,
657 attr
->rta_len
- rta_len
);
658 } else if (attr
->rta_type
== IFLA_IFNAME
) {
659 wpa_driver_wext_event_link(drv
,
660 ((char *) attr
) + rta_len
,
661 attr
->rta_len
- rta_len
, 0);
663 attr
= RTA_NEXT(attr
, attrlen
);
668 static void wpa_driver_wext_event_rtm_dellink(void *ctx
, struct ifinfomsg
*ifi
,
671 struct wpa_driver_wext_data
*drv
= ctx
;
672 int attrlen
, rta_len
;
676 attr
= (struct rtattr
*) buf
;
678 rta_len
= RTA_ALIGN(sizeof(struct rtattr
));
679 while (RTA_OK(attr
, attrlen
)) {
680 if (attr
->rta_type
== IFLA_IFNAME
) {
681 wpa_driver_wext_event_link(drv
,
682 ((char *) attr
) + rta_len
,
683 attr
->rta_len
- rta_len
, 1);
685 attr
= RTA_NEXT(attr
, attrlen
);
691 * wpa_driver_wext_init - Initialize WE driver interface
692 * @ctx: context to be used when calling wpa_supplicant functions,
693 * e.g., wpa_supplicant_event()
694 * @ifname: interface name, e.g., wlan0
695 * Returns: Pointer to private data, %NULL on failure
697 void * wpa_driver_wext_init(void *ctx
, const char *ifname
)
699 struct wpa_driver_wext_data
*drv
;
700 struct netlink_config
*cfg
;
704 drv
= os_zalloc(sizeof(*drv
));
708 os_strlcpy(drv
->ifname
, ifname
, sizeof(drv
->ifname
));
710 os_snprintf(path
, sizeof(path
), "/sys/class/net/%s/phy80211", ifname
);
711 if (stat(path
, &buf
) == 0) {
712 wpa_printf(MSG_DEBUG
, "WEXT: cfg80211-based driver detected");
716 drv
->ioctl_sock
= socket(PF_INET
, SOCK_DGRAM
, 0);
717 if (drv
->ioctl_sock
< 0) {
718 perror("socket(PF_INET,SOCK_DGRAM)");
722 cfg
= os_zalloc(sizeof(*cfg
));
726 cfg
->newlink_cb
= wpa_driver_wext_event_rtm_newlink
;
727 cfg
->dellink_cb
= wpa_driver_wext_event_rtm_dellink
;
728 drv
->netlink
= netlink_init(cfg
);
729 if (drv
->netlink
== NULL
) {
736 if (wpa_driver_wext_finish_drv_init(drv
) < 0)
739 wpa_driver_wext_set_auth_param(drv
, IW_AUTH_WPA_ENABLED
, 1);
744 netlink_deinit(drv
->netlink
);
746 close(drv
->ioctl_sock
);
753 static int wpa_driver_wext_finish_drv_init(struct wpa_driver_wext_data
*drv
)
755 if (linux_set_iface_flags(drv
->ioctl_sock
, drv
->ifname
, 1) < 0)
759 * Make sure that the driver does not have any obsolete PMKID entries.
761 wpa_driver_wext_flush_pmkid(drv
);
763 if (wpa_driver_wext_set_mode(drv
, 0) < 0) {
764 wpa_printf(MSG_DEBUG
, "Could not configure driver to use "
766 /* Try to use it anyway */
769 wpa_driver_wext_get_range(drv
);
772 * Unlock the driver's BSSID and force to a random SSID to clear any
773 * previous association the driver might have when the supplicant
776 wpa_driver_wext_disconnect(drv
);
778 drv
->ifindex
= if_nametoindex(drv
->ifname
);
780 if (os_strncmp(drv
->ifname
, "wlan", 4) == 0) {
782 * Host AP driver may use both wlan# and wifi# interface in
783 * wireless events. Since some of the versions included WE-18
784 * support, let's add the alternative ifindex also from
785 * driver_wext.c for the time being. This may be removed at
786 * some point once it is believed that old versions of the
787 * driver are not in use anymore.
789 char ifname2
[IFNAMSIZ
+ 1];
790 os_strlcpy(ifname2
, drv
->ifname
, sizeof(ifname2
));
791 os_memcpy(ifname2
, "wifi", 4);
792 wpa_driver_wext_alternative_ifindex(drv
, ifname2
);
795 netlink_send_oper_ifla(drv
->netlink
, drv
->ifindex
,
803 * wpa_driver_wext_deinit - Deinitialize WE driver interface
804 * @priv: Pointer to private wext data from wpa_driver_wext_init()
806 * Shut down driver interface and processing of driver events. Free
807 * private data buffer if one was allocated in wpa_driver_wext_init().
809 void wpa_driver_wext_deinit(void *priv
)
811 struct wpa_driver_wext_data
*drv
= priv
;
813 wpa_driver_wext_set_auth_param(drv
, IW_AUTH_WPA_ENABLED
, 0);
815 eloop_cancel_timeout(wpa_driver_wext_scan_timeout
, drv
, drv
->ctx
);
818 * Clear possibly configured driver parameters in order to make it
819 * easier to use the driver after wpa_supplicant has been terminated.
821 wpa_driver_wext_disconnect(drv
);
823 netlink_send_oper_ifla(drv
->netlink
, drv
->ifindex
, 0, IF_OPER_UP
);
824 netlink_deinit(drv
->netlink
);
826 if (drv
->mlme_sock
>= 0)
827 eloop_unregister_read_sock(drv
->mlme_sock
);
829 (void) linux_set_iface_flags(drv
->ioctl_sock
, drv
->ifname
, 0);
831 close(drv
->ioctl_sock
);
832 if (drv
->mlme_sock
>= 0)
833 close(drv
->mlme_sock
);
834 os_free(drv
->assoc_req_ies
);
835 os_free(drv
->assoc_resp_ies
);
841 * wpa_driver_wext_scan_timeout - Scan timeout to report scan completion
843 * @timeout_ctx: ctx argument given to wpa_driver_wext_init()
845 * This function can be used as registered timeout when starting a scan to
846 * generate a scan completed event if the driver does not report this.
848 void wpa_driver_wext_scan_timeout(void *eloop_ctx
, void *timeout_ctx
)
850 wpa_printf(MSG_DEBUG
, "Scan timeout - try to get results");
851 wpa_supplicant_event(timeout_ctx
, EVENT_SCAN_RESULTS
, NULL
);
856 * wpa_driver_wext_scan - Request the driver to initiate scan
857 * @priv: Pointer to private wext data from wpa_driver_wext_init()
858 * @param: Scan parameters (specific SSID to scan for (ProbeReq), etc.)
859 * Returns: 0 on success, -1 on failure
861 int wpa_driver_wext_scan(void *priv
, struct wpa_driver_scan_params
*params
)
863 struct wpa_driver_wext_data
*drv
= priv
;
865 int ret
= 0, timeout
;
866 struct iw_scan_req req
;
867 const u8
*ssid
= params
->ssids
[0].ssid
;
868 size_t ssid_len
= params
->ssids
[0].ssid_len
;
870 if (ssid_len
> IW_ESSID_MAX_SIZE
) {
871 wpa_printf(MSG_DEBUG
, "%s: too long SSID (%lu)",
872 __FUNCTION__
, (unsigned long) ssid_len
);
876 os_memset(&iwr
, 0, sizeof(iwr
));
877 os_strlcpy(iwr
.ifr_name
, drv
->ifname
, IFNAMSIZ
);
879 if (ssid
&& ssid_len
) {
880 os_memset(&req
, 0, sizeof(req
));
881 req
.essid_len
= ssid_len
;
882 req
.bssid
.sa_family
= ARPHRD_ETHER
;
883 os_memset(req
.bssid
.sa_data
, 0xff, ETH_ALEN
);
884 os_memcpy(req
.essid
, ssid
, ssid_len
);
885 iwr
.u
.data
.pointer
= (caddr_t
) &req
;
886 iwr
.u
.data
.length
= sizeof(req
);
887 iwr
.u
.data
.flags
= IW_SCAN_THIS_ESSID
;
890 if (ioctl(drv
->ioctl_sock
, SIOCSIWSCAN
, &iwr
) < 0) {
891 perror("ioctl[SIOCSIWSCAN]");
895 /* Not all drivers generate "scan completed" wireless event, so try to
896 * read results after a timeout. */
898 if (drv
->scan_complete_events
) {
900 * The driver seems to deliver SIOCGIWSCAN events to notify
901 * when scan is complete, so use longer timeout to avoid race
902 * conditions with scanning and following association request.
906 wpa_printf(MSG_DEBUG
, "Scan requested (ret=%d) - scan timeout %d "
907 "seconds", ret
, timeout
);
908 eloop_cancel_timeout(wpa_driver_wext_scan_timeout
, drv
, drv
->ctx
);
909 eloop_register_timeout(timeout
, 0, wpa_driver_wext_scan_timeout
, drv
,
916 static u8
* wpa_driver_wext_giwscan(struct wpa_driver_wext_data
*drv
,
923 res_buf_len
= IW_SCAN_MAX_DATA
;
925 res_buf
= os_malloc(res_buf_len
);
928 os_memset(&iwr
, 0, sizeof(iwr
));
929 os_strlcpy(iwr
.ifr_name
, drv
->ifname
, IFNAMSIZ
);
930 iwr
.u
.data
.pointer
= res_buf
;
931 iwr
.u
.data
.length
= res_buf_len
;
933 if (ioctl(drv
->ioctl_sock
, SIOCGIWSCAN
, &iwr
) == 0)
936 if (errno
== E2BIG
&& res_buf_len
< 65535) {
940 if (res_buf_len
> 65535)
941 res_buf_len
= 65535; /* 16-bit length field */
942 wpa_printf(MSG_DEBUG
, "Scan results did not fit - "
943 "trying larger buffer (%lu bytes)",
944 (unsigned long) res_buf_len
);
946 perror("ioctl[SIOCGIWSCAN]");
952 if (iwr
.u
.data
.length
> res_buf_len
) {
956 *len
= iwr
.u
.data
.length
;
963 * Data structure for collecting WEXT scan results. This is needed to allow
964 * the various methods of reporting IEs to be combined into a single IE buffer.
966 struct wext_scan_data
{
967 struct wpa_scan_res res
;
976 static void wext_get_scan_mode(struct iw_event
*iwe
,
977 struct wext_scan_data
*res
)
979 if (iwe
->u
.mode
== IW_MODE_ADHOC
)
980 res
->res
.caps
|= IEEE80211_CAP_IBSS
;
981 else if (iwe
->u
.mode
== IW_MODE_MASTER
|| iwe
->u
.mode
== IW_MODE_INFRA
)
982 res
->res
.caps
|= IEEE80211_CAP_ESS
;
986 static void wext_get_scan_ssid(struct iw_event
*iwe
,
987 struct wext_scan_data
*res
, char *custom
,
990 int ssid_len
= iwe
->u
.essid
.length
;
991 if (custom
+ ssid_len
> end
)
993 if (iwe
->u
.essid
.flags
&&
995 ssid_len
<= IW_ESSID_MAX_SIZE
) {
996 os_memcpy(res
->ssid
, custom
, ssid_len
);
997 res
->ssid_len
= ssid_len
;
1002 static void wext_get_scan_freq(struct iw_event
*iwe
,
1003 struct wext_scan_data
*res
)
1005 int divi
= 1000000, i
;
1007 if (iwe
->u
.freq
.e
== 0) {
1009 * Some drivers do not report frequency, but a channel.
1010 * Try to map this to frequency by assuming they are using
1011 * IEEE 802.11b/g. But don't overwrite a previously parsed
1012 * frequency if the driver sends both frequency and channel,
1013 * since the driver may be sending an A-band channel that we
1014 * don't handle here.
1020 if (iwe
->u
.freq
.m
>= 1 && iwe
->u
.freq
.m
<= 13) {
1021 res
->res
.freq
= 2407 + 5 * iwe
->u
.freq
.m
;
1023 } else if (iwe
->u
.freq
.m
== 14) {
1024 res
->res
.freq
= 2484;
1029 if (iwe
->u
.freq
.e
> 6) {
1030 wpa_printf(MSG_DEBUG
, "Invalid freq in scan results (BSSID="
1031 MACSTR
" m=%d e=%d)",
1032 MAC2STR(res
->res
.bssid
), iwe
->u
.freq
.m
,
1037 for (i
= 0; i
< iwe
->u
.freq
.e
; i
++)
1039 res
->res
.freq
= iwe
->u
.freq
.m
/ divi
;
1043 static void wext_get_scan_qual(struct iw_event
*iwe
,
1044 struct wext_scan_data
*res
)
1046 res
->res
.qual
= iwe
->u
.qual
.qual
;
1047 res
->res
.noise
= iwe
->u
.qual
.noise
;
1048 res
->res
.level
= iwe
->u
.qual
.level
;
1049 if (iwe
->u
.qual
.updated
& IW_QUAL_QUAL_INVALID
)
1050 res
->res
.flags
|= WPA_SCAN_QUAL_INVALID
;
1051 if (iwe
->u
.qual
.updated
& IW_QUAL_LEVEL_INVALID
)
1052 res
->res
.flags
|= WPA_SCAN_LEVEL_INVALID
;
1053 if (iwe
->u
.qual
.updated
& IW_QUAL_NOISE_INVALID
)
1054 res
->res
.flags
|= WPA_SCAN_NOISE_INVALID
;
1055 if (iwe
->u
.qual
.updated
& IW_QUAL_DBM
)
1056 res
->res
.flags
|= WPA_SCAN_LEVEL_DBM
;
1060 static void wext_get_scan_encode(struct iw_event
*iwe
,
1061 struct wext_scan_data
*res
)
1063 if (!(iwe
->u
.data
.flags
& IW_ENCODE_DISABLED
))
1064 res
->res
.caps
|= IEEE80211_CAP_PRIVACY
;
1068 static void wext_get_scan_rate(struct iw_event
*iwe
,
1069 struct wext_scan_data
*res
, char *pos
,
1073 char *custom
= pos
+ IW_EV_LCP_LEN
;
1078 if (custom
+ clen
> end
)
1081 while (((ssize_t
) clen
) >= (ssize_t
) sizeof(struct iw_param
)) {
1082 /* Note: may be misaligned, make a local, aligned copy */
1083 os_memcpy(&p
, custom
, sizeof(struct iw_param
));
1084 if (p
.value
> maxrate
)
1086 clen
-= sizeof(struct iw_param
);
1087 custom
+= sizeof(struct iw_param
);
1090 /* Convert the maxrate from WE-style (b/s units) to
1091 * 802.11 rates (500000 b/s units).
1093 res
->maxrate
= maxrate
/ 500000;
1097 static void wext_get_scan_iwevgenie(struct iw_event
*iwe
,
1098 struct wext_scan_data
*res
, char *custom
,
1101 char *genie
, *gpos
, *gend
;
1104 if (iwe
->u
.data
.length
== 0)
1107 gpos
= genie
= custom
;
1108 gend
= genie
+ iwe
->u
.data
.length
;
1110 wpa_printf(MSG_INFO
, "IWEVGENIE overflow");
1114 tmp
= os_realloc(res
->ie
, res
->ie_len
+ gend
- gpos
);
1117 os_memcpy(tmp
+ res
->ie_len
, gpos
, gend
- gpos
);
1119 res
->ie_len
+= gend
- gpos
;
1123 static void wext_get_scan_custom(struct iw_event
*iwe
,
1124 struct wext_scan_data
*res
, char *custom
,
1130 clen
= iwe
->u
.data
.length
;
1131 if (custom
+ clen
> end
)
1134 if (clen
> 7 && os_strncmp(custom
, "wpa_ie=", 7) == 0) {
1138 bytes
= custom
+ clen
- spos
;
1139 if (bytes
& 1 || bytes
== 0)
1142 tmp
= os_realloc(res
->ie
, res
->ie_len
+ bytes
);
1146 if (hexstr2bin(spos
, tmp
+ res
->ie_len
, bytes
) < 0)
1148 res
->ie_len
+= bytes
;
1149 } else if (clen
> 7 && os_strncmp(custom
, "rsn_ie=", 7) == 0) {
1153 bytes
= custom
+ clen
- spos
;
1154 if (bytes
& 1 || bytes
== 0)
1157 tmp
= os_realloc(res
->ie
, res
->ie_len
+ bytes
);
1161 if (hexstr2bin(spos
, tmp
+ res
->ie_len
, bytes
) < 0)
1163 res
->ie_len
+= bytes
;
1164 } else if (clen
> 4 && os_strncmp(custom
, "tsf=", 4) == 0) {
1169 bytes
= custom
+ clen
- spos
;
1171 wpa_printf(MSG_INFO
, "Invalid TSF length (%d)", bytes
);
1175 if (hexstr2bin(spos
, bin
, bytes
) < 0) {
1176 wpa_printf(MSG_DEBUG
, "WEXT: Invalid TSF value");
1179 res
->res
.tsf
+= WPA_GET_BE64(bin
);
1184 static int wext_19_iw_point(struct wpa_driver_wext_data
*drv
, u16 cmd
)
1186 return drv
->we_version_compiled
> 18 &&
1187 (cmd
== SIOCGIWESSID
|| cmd
== SIOCGIWENCODE
||
1188 cmd
== IWEVGENIE
|| cmd
== IWEVCUSTOM
);
1192 static void wpa_driver_wext_add_scan_entry(struct wpa_scan_results
*res
,
1193 struct wext_scan_data
*data
)
1195 struct wpa_scan_res
**tmp
;
1196 struct wpa_scan_res
*r
;
1198 u8
*pos
, *end
, *ssid_ie
= NULL
, *rate_ie
= NULL
;
1200 /* Figure out whether we need to fake any IEs */
1202 end
= pos
+ data
->ie_len
;
1203 while (pos
&& pos
+ 1 < end
) {
1204 if (pos
+ 2 + pos
[1] > end
)
1206 if (pos
[0] == WLAN_EID_SSID
)
1208 else if (pos
[0] == WLAN_EID_SUPP_RATES
)
1210 else if (pos
[0] == WLAN_EID_EXT_SUPP_RATES
)
1216 if (ssid_ie
== NULL
)
1217 extra_len
+= 2 + data
->ssid_len
;
1218 if (rate_ie
== NULL
&& data
->maxrate
)
1221 r
= os_zalloc(sizeof(*r
) + extra_len
+ data
->ie_len
);
1224 os_memcpy(r
, &data
->res
, sizeof(*r
));
1225 r
->ie_len
= extra_len
+ data
->ie_len
;
1226 pos
= (u8
*) (r
+ 1);
1227 if (ssid_ie
== NULL
) {
1229 * Generate a fake SSID IE since the driver did not report
1232 *pos
++ = WLAN_EID_SSID
;
1233 *pos
++ = data
->ssid_len
;
1234 os_memcpy(pos
, data
->ssid
, data
->ssid_len
);
1235 pos
+= data
->ssid_len
;
1237 if (rate_ie
== NULL
&& data
->maxrate
) {
1239 * Generate a fake Supported Rates IE since the driver did not
1240 * report a full IE list.
1242 *pos
++ = WLAN_EID_SUPP_RATES
;
1244 *pos
++ = data
->maxrate
;
1247 os_memcpy(pos
, data
->ie
, data
->ie_len
);
1249 tmp
= os_realloc(res
->res
,
1250 (res
->num
+ 1) * sizeof(struct wpa_scan_res
*));
1255 tmp
[res
->num
++] = r
;
1261 * wpa_driver_wext_get_scan_results - Fetch the latest scan results
1262 * @priv: Pointer to private wext data from wpa_driver_wext_init()
1263 * Returns: Scan results on success, -1 on failure
1265 struct wpa_scan_results
* wpa_driver_wext_get_scan_results(void *priv
)
1267 struct wpa_driver_wext_data
*drv
= priv
;
1268 size_t ap_num
= 0, len
;
1271 struct iw_event iwe_buf
, *iwe
= &iwe_buf
;
1272 char *pos
, *end
, *custom
;
1273 struct wpa_scan_results
*res
;
1274 struct wext_scan_data data
;
1276 res_buf
= wpa_driver_wext_giwscan(drv
, &len
);
1277 if (res_buf
== NULL
)
1283 res
= os_zalloc(sizeof(*res
));
1289 pos
= (char *) res_buf
;
1290 end
= (char *) res_buf
+ len
;
1291 os_memset(&data
, 0, sizeof(data
));
1293 while (pos
+ IW_EV_LCP_LEN
<= end
) {
1294 /* Event data may be unaligned, so make a local, aligned copy
1295 * before processing. */
1296 os_memcpy(&iwe_buf
, pos
, IW_EV_LCP_LEN
);
1297 if (iwe
->len
<= IW_EV_LCP_LEN
)
1300 custom
= pos
+ IW_EV_POINT_LEN
;
1301 if (wext_19_iw_point(drv
, iwe
->cmd
)) {
1302 /* WE-19 removed the pointer from struct iw_point */
1303 char *dpos
= (char *) &iwe_buf
.u
.data
.length
;
1304 int dlen
= dpos
- (char *) &iwe_buf
;
1305 os_memcpy(dpos
, pos
+ IW_EV_LCP_LEN
,
1306 sizeof(struct iw_event
) - dlen
);
1308 os_memcpy(&iwe_buf
, pos
, sizeof(struct iw_event
));
1309 custom
+= IW_EV_POINT_OFF
;
1315 wpa_driver_wext_add_scan_entry(res
, &data
);
1318 os_memset(&data
, 0, sizeof(data
));
1319 os_memcpy(data
.res
.bssid
,
1320 iwe
->u
.ap_addr
.sa_data
, ETH_ALEN
);
1323 wext_get_scan_mode(iwe
, &data
);
1326 wext_get_scan_ssid(iwe
, &data
, custom
, end
);
1329 wext_get_scan_freq(iwe
, &data
);
1332 wext_get_scan_qual(iwe
, &data
);
1335 wext_get_scan_encode(iwe
, &data
);
1338 wext_get_scan_rate(iwe
, &data
, pos
, end
);
1341 wext_get_scan_iwevgenie(iwe
, &data
, custom
, end
);
1344 wext_get_scan_custom(iwe
, &data
, custom
, end
);
1353 wpa_driver_wext_add_scan_entry(res
, &data
);
1356 wpa_printf(MSG_DEBUG
, "Received %lu bytes of scan results (%lu BSSes)",
1357 (unsigned long) len
, (unsigned long) res
->num
);
1363 static int wpa_driver_wext_get_range(void *priv
)
1365 struct wpa_driver_wext_data
*drv
= priv
;
1366 struct iw_range
*range
;
1372 * Use larger buffer than struct iw_range in order to allow the
1373 * structure to grow in the future.
1375 buflen
= sizeof(struct iw_range
) + 500;
1376 range
= os_zalloc(buflen
);
1380 os_memset(&iwr
, 0, sizeof(iwr
));
1381 os_strlcpy(iwr
.ifr_name
, drv
->ifname
, IFNAMSIZ
);
1382 iwr
.u
.data
.pointer
= (caddr_t
) range
;
1383 iwr
.u
.data
.length
= buflen
;
1385 minlen
= ((char *) &range
->enc_capa
) - (char *) range
+
1386 sizeof(range
->enc_capa
);
1388 if (ioctl(drv
->ioctl_sock
, SIOCGIWRANGE
, &iwr
) < 0) {
1389 perror("ioctl[SIOCGIWRANGE]");
1392 } else if (iwr
.u
.data
.length
>= minlen
&&
1393 range
->we_version_compiled
>= 18) {
1394 wpa_printf(MSG_DEBUG
, "SIOCGIWRANGE: WE(compiled)=%d "
1395 "WE(source)=%d enc_capa=0x%x",
1396 range
->we_version_compiled
,
1397 range
->we_version_source
,
1399 drv
->has_capability
= 1;
1400 drv
->we_version_compiled
= range
->we_version_compiled
;
1401 if (range
->enc_capa
& IW_ENC_CAPA_WPA
) {
1402 drv
->capa
.key_mgmt
|= WPA_DRIVER_CAPA_KEY_MGMT_WPA
|
1403 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK
;
1405 if (range
->enc_capa
& IW_ENC_CAPA_WPA2
) {
1406 drv
->capa
.key_mgmt
|= WPA_DRIVER_CAPA_KEY_MGMT_WPA2
|
1407 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK
;
1409 drv
->capa
.enc
|= WPA_DRIVER_CAPA_ENC_WEP40
|
1410 WPA_DRIVER_CAPA_ENC_WEP104
;
1411 if (range
->enc_capa
& IW_ENC_CAPA_CIPHER_TKIP
)
1412 drv
->capa
.enc
|= WPA_DRIVER_CAPA_ENC_TKIP
;
1413 if (range
->enc_capa
& IW_ENC_CAPA_CIPHER_CCMP
)
1414 drv
->capa
.enc
|= WPA_DRIVER_CAPA_ENC_CCMP
;
1415 if (range
->enc_capa
& IW_ENC_CAPA_4WAY_HANDSHAKE
)
1416 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_4WAY_HANDSHAKE
;
1417 drv
->capa
.auth
= WPA_DRIVER_AUTH_OPEN
|
1418 WPA_DRIVER_AUTH_SHARED
|
1419 WPA_DRIVER_AUTH_LEAP
;
1420 drv
->capa
.max_scan_ssids
= 1;
1422 wpa_printf(MSG_DEBUG
, " capabilities: key_mgmt 0x%x enc 0x%x "
1424 drv
->capa
.key_mgmt
, drv
->capa
.enc
, drv
->capa
.flags
);
1426 wpa_printf(MSG_DEBUG
, "SIOCGIWRANGE: too old (short) data - "
1427 "assuming WPA is not supported");
1435 static int wpa_driver_wext_set_psk(struct wpa_driver_wext_data
*drv
,
1438 struct iw_encode_ext
*ext
;
1442 wpa_printf(MSG_DEBUG
, "%s", __FUNCTION__
);
1444 if (!(drv
->capa
.flags
& WPA_DRIVER_FLAGS_4WAY_HANDSHAKE
))
1450 os_memset(&iwr
, 0, sizeof(iwr
));
1451 os_strlcpy(iwr
.ifr_name
, drv
->ifname
, IFNAMSIZ
);
1453 ext
= os_zalloc(sizeof(*ext
) + PMK_LEN
);
1457 iwr
.u
.encoding
.pointer
= (caddr_t
) ext
;
1458 iwr
.u
.encoding
.length
= sizeof(*ext
) + PMK_LEN
;
1459 ext
->key_len
= PMK_LEN
;
1460 os_memcpy(&ext
->key
, psk
, ext
->key_len
);
1461 ext
->alg
= IW_ENCODE_ALG_PMK
;
1463 ret
= ioctl(drv
->ioctl_sock
, SIOCSIWENCODEEXT
, &iwr
);
1465 perror("ioctl[SIOCSIWENCODEEXT] PMK");
1472 static int wpa_driver_wext_set_key_ext(void *priv
, enum wpa_alg alg
,
1473 const u8
*addr
, int key_idx
,
1474 int set_tx
, const u8
*seq
,
1476 const u8
*key
, size_t key_len
)
1478 struct wpa_driver_wext_data
*drv
= priv
;
1481 struct iw_encode_ext
*ext
;
1483 if (seq_len
> IW_ENCODE_SEQ_MAX_SIZE
) {
1484 wpa_printf(MSG_DEBUG
, "%s: Invalid seq_len %lu",
1485 __FUNCTION__
, (unsigned long) seq_len
);
1489 ext
= os_zalloc(sizeof(*ext
) + key_len
);
1492 os_memset(&iwr
, 0, sizeof(iwr
));
1493 os_strlcpy(iwr
.ifr_name
, drv
->ifname
, IFNAMSIZ
);
1494 iwr
.u
.encoding
.flags
= key_idx
+ 1;
1495 iwr
.u
.encoding
.flags
|= IW_ENCODE_TEMP
;
1496 if (alg
== WPA_ALG_NONE
)
1497 iwr
.u
.encoding
.flags
|= IW_ENCODE_DISABLED
;
1498 iwr
.u
.encoding
.pointer
= (caddr_t
) ext
;
1499 iwr
.u
.encoding
.length
= sizeof(*ext
) + key_len
;
1502 os_memcmp(addr
, "\xff\xff\xff\xff\xff\xff", ETH_ALEN
) == 0)
1503 ext
->ext_flags
|= IW_ENCODE_EXT_GROUP_KEY
;
1505 ext
->ext_flags
|= IW_ENCODE_EXT_SET_TX_KEY
;
1507 ext
->addr
.sa_family
= ARPHRD_ETHER
;
1509 os_memcpy(ext
->addr
.sa_data
, addr
, ETH_ALEN
);
1511 os_memset(ext
->addr
.sa_data
, 0xff, ETH_ALEN
);
1512 if (key
&& key_len
) {
1513 os_memcpy(ext
+ 1, key
, key_len
);
1514 ext
->key_len
= key_len
;
1518 ext
->alg
= IW_ENCODE_ALG_NONE
;
1521 ext
->alg
= IW_ENCODE_ALG_WEP
;
1524 ext
->alg
= IW_ENCODE_ALG_TKIP
;
1527 ext
->alg
= IW_ENCODE_ALG_CCMP
;
1530 ext
->alg
= IW_ENCODE_ALG_PMK
;
1532 #ifdef CONFIG_IEEE80211W
1534 ext
->alg
= IW_ENCODE_ALG_AES_CMAC
;
1536 #endif /* CONFIG_IEEE80211W */
1538 wpa_printf(MSG_DEBUG
, "%s: Unknown algorithm %d",
1544 if (seq
&& seq_len
) {
1545 ext
->ext_flags
|= IW_ENCODE_EXT_RX_SEQ_VALID
;
1546 os_memcpy(ext
->rx_seq
, seq
, seq_len
);
1549 if (ioctl(drv
->ioctl_sock
, SIOCSIWENCODEEXT
, &iwr
) < 0) {
1550 ret
= errno
== EOPNOTSUPP
? -2 : -1;
1551 if (errno
== ENODEV
) {
1553 * ndiswrapper seems to be returning incorrect error
1558 perror("ioctl[SIOCSIWENCODEEXT]");
1567 * wpa_driver_wext_set_key - Configure encryption key
1568 * @priv: Pointer to private wext data from wpa_driver_wext_init()
1569 * @priv: Private driver interface data
1570 * @alg: Encryption algorithm (%WPA_ALG_NONE, %WPA_ALG_WEP,
1571 * %WPA_ALG_TKIP, %WPA_ALG_CCMP); %WPA_ALG_NONE clears the key.
1572 * @addr: Address of the peer STA or ff:ff:ff:ff:ff:ff for
1573 * broadcast/default keys
1574 * @key_idx: key index (0..3), usually 0 for unicast keys
1575 * @set_tx: Configure this key as the default Tx key (only used when
1576 * driver does not support separate unicast/individual key
1577 * @seq: Sequence number/packet number, seq_len octets, the next
1578 * packet number to be used for in replay protection; configured
1579 * for Rx keys (in most cases, this is only used with broadcast
1580 * keys and set to zero for unicast keys)
1581 * @seq_len: Length of the seq, depends on the algorithm:
1582 * TKIP: 6 octets, CCMP: 6 octets
1583 * @key: Key buffer; TKIP: 16-byte temporal key, 8-byte Tx Mic key,
1585 * @key_len: Length of the key buffer in octets (WEP: 5 or 13,
1586 * TKIP: 32, CCMP: 16)
1587 * Returns: 0 on success, -1 on failure
1589 * This function uses SIOCSIWENCODEEXT by default, but tries to use
1590 * SIOCSIWENCODE if the extended ioctl fails when configuring a WEP key.
1592 int wpa_driver_wext_set_key(const char *ifname
, void *priv
, enum wpa_alg alg
,
1593 const u8
*addr
, int key_idx
,
1594 int set_tx
, const u8
*seq
, size_t seq_len
,
1595 const u8
*key
, size_t key_len
)
1597 struct wpa_driver_wext_data
*drv
= priv
;
1601 wpa_printf(MSG_DEBUG
, "%s: alg=%d key_idx=%d set_tx=%d seq_len=%lu "
1603 __FUNCTION__
, alg
, key_idx
, set_tx
,
1604 (unsigned long) seq_len
, (unsigned long) key_len
);
1606 ret
= wpa_driver_wext_set_key_ext(drv
, alg
, addr
, key_idx
, set_tx
,
1607 seq
, seq_len
, key
, key_len
);
1612 (alg
== WPA_ALG_NONE
|| alg
== WPA_ALG_WEP
)) {
1613 wpa_printf(MSG_DEBUG
, "Driver did not support "
1614 "SIOCSIWENCODEEXT, trying SIOCSIWENCODE");
1617 wpa_printf(MSG_DEBUG
, "Driver did not support "
1618 "SIOCSIWENCODEEXT");
1622 os_memset(&iwr
, 0, sizeof(iwr
));
1623 os_strlcpy(iwr
.ifr_name
, drv
->ifname
, IFNAMSIZ
);
1624 iwr
.u
.encoding
.flags
= key_idx
+ 1;
1625 iwr
.u
.encoding
.flags
|= IW_ENCODE_TEMP
;
1626 if (alg
== WPA_ALG_NONE
)
1627 iwr
.u
.encoding
.flags
|= IW_ENCODE_DISABLED
;
1628 iwr
.u
.encoding
.pointer
= (caddr_t
) key
;
1629 iwr
.u
.encoding
.length
= key_len
;
1631 if (ioctl(drv
->ioctl_sock
, SIOCSIWENCODE
, &iwr
) < 0) {
1632 perror("ioctl[SIOCSIWENCODE]");
1636 if (set_tx
&& alg
!= WPA_ALG_NONE
) {
1637 os_memset(&iwr
, 0, sizeof(iwr
));
1638 os_strlcpy(iwr
.ifr_name
, drv
->ifname
, IFNAMSIZ
);
1639 iwr
.u
.encoding
.flags
= key_idx
+ 1;
1640 iwr
.u
.encoding
.flags
|= IW_ENCODE_TEMP
;
1641 iwr
.u
.encoding
.pointer
= (caddr_t
) NULL
;
1642 iwr
.u
.encoding
.length
= 0;
1643 if (ioctl(drv
->ioctl_sock
, SIOCSIWENCODE
, &iwr
) < 0) {
1644 perror("ioctl[SIOCSIWENCODE] (set_tx)");
1653 static int wpa_driver_wext_set_countermeasures(void *priv
,
1656 struct wpa_driver_wext_data
*drv
= priv
;
1657 wpa_printf(MSG_DEBUG
, "%s", __FUNCTION__
);
1658 return wpa_driver_wext_set_auth_param(drv
,
1659 IW_AUTH_TKIP_COUNTERMEASURES
,
1664 static int wpa_driver_wext_set_drop_unencrypted(void *priv
,
1667 struct wpa_driver_wext_data
*drv
= priv
;
1668 wpa_printf(MSG_DEBUG
, "%s", __FUNCTION__
);
1669 drv
->use_crypt
= enabled
;
1670 return wpa_driver_wext_set_auth_param(drv
, IW_AUTH_DROP_UNENCRYPTED
,
1675 static int wpa_driver_wext_mlme(struct wpa_driver_wext_data
*drv
,
1676 const u8
*addr
, int cmd
, int reason_code
)
1679 struct iw_mlme mlme
;
1682 os_memset(&iwr
, 0, sizeof(iwr
));
1683 os_strlcpy(iwr
.ifr_name
, drv
->ifname
, IFNAMSIZ
);
1684 os_memset(&mlme
, 0, sizeof(mlme
));
1686 mlme
.reason_code
= reason_code
;
1687 mlme
.addr
.sa_family
= ARPHRD_ETHER
;
1688 os_memcpy(mlme
.addr
.sa_data
, addr
, ETH_ALEN
);
1689 iwr
.u
.data
.pointer
= (caddr_t
) &mlme
;
1690 iwr
.u
.data
.length
= sizeof(mlme
);
1692 if (ioctl(drv
->ioctl_sock
, SIOCSIWMLME
, &iwr
) < 0) {
1693 perror("ioctl[SIOCSIWMLME]");
1701 static void wpa_driver_wext_disconnect(struct wpa_driver_wext_data
*drv
)
1704 const u8 null_bssid
[ETH_ALEN
] = { 0, 0, 0, 0, 0, 0 };
1709 * Only force-disconnect when the card is in infrastructure mode,
1710 * otherwise the driver might interpret the cleared BSSID and random
1711 * SSID as an attempt to create a new ad-hoc network.
1713 os_memset(&iwr
, 0, sizeof(iwr
));
1714 os_strlcpy(iwr
.ifr_name
, drv
->ifname
, IFNAMSIZ
);
1715 if (ioctl(drv
->ioctl_sock
, SIOCGIWMODE
, &iwr
) < 0) {
1716 perror("ioctl[SIOCGIWMODE]");
1717 iwr
.u
.mode
= IW_MODE_INFRA
;
1720 if (iwr
.u
.mode
== IW_MODE_INFRA
) {
1721 if (drv
->cfg80211
) {
1723 * cfg80211 supports SIOCSIWMLME commands, so there is
1724 * no need for the random SSID hack, but clear the
1727 if (wpa_driver_wext_set_bssid(drv
, null_bssid
) < 0 ||
1728 wpa_driver_wext_set_ssid(drv
, (u8
*) "", 0) < 0) {
1729 wpa_printf(MSG_DEBUG
, "WEXT: Failed to clear "
1735 * Clear the BSSID selection and set a random SSID to make sure
1736 * the driver will not be trying to associate with something
1737 * even if it does not understand SIOCSIWMLME commands (or
1738 * tries to associate automatically after deauth/disassoc).
1740 for (i
= 0; i
< 32; i
++)
1741 ssid
[i
] = rand() & 0xFF;
1742 if (wpa_driver_wext_set_bssid(drv
, null_bssid
) < 0 ||
1743 wpa_driver_wext_set_ssid(drv
, ssid
, 32) < 0) {
1744 wpa_printf(MSG_DEBUG
, "WEXT: Failed to set bogus "
1745 "BSSID/SSID to disconnect");
1751 static int wpa_driver_wext_deauthenticate(void *priv
, const u8
*addr
,
1754 struct wpa_driver_wext_data
*drv
= priv
;
1756 wpa_printf(MSG_DEBUG
, "%s", __FUNCTION__
);
1757 ret
= wpa_driver_wext_mlme(drv
, addr
, IW_MLME_DEAUTH
, reason_code
);
1758 wpa_driver_wext_disconnect(drv
);
1763 static int wpa_driver_wext_disassociate(void *priv
, const u8
*addr
,
1766 struct wpa_driver_wext_data
*drv
= priv
;
1768 wpa_printf(MSG_DEBUG
, "%s", __FUNCTION__
);
1769 ret
= wpa_driver_wext_mlme(drv
, addr
, IW_MLME_DISASSOC
, reason_code
);
1770 wpa_driver_wext_disconnect(drv
);
1775 static int wpa_driver_wext_set_gen_ie(void *priv
, const u8
*ie
,
1778 struct wpa_driver_wext_data
*drv
= priv
;
1782 os_memset(&iwr
, 0, sizeof(iwr
));
1783 os_strlcpy(iwr
.ifr_name
, drv
->ifname
, IFNAMSIZ
);
1784 iwr
.u
.data
.pointer
= (caddr_t
) ie
;
1785 iwr
.u
.data
.length
= ie_len
;
1787 if (ioctl(drv
->ioctl_sock
, SIOCSIWGENIE
, &iwr
) < 0) {
1788 perror("ioctl[SIOCSIWGENIE]");
1796 int wpa_driver_wext_cipher2wext(int cipher
)
1800 return IW_AUTH_CIPHER_NONE
;
1802 return IW_AUTH_CIPHER_WEP40
;
1804 return IW_AUTH_CIPHER_TKIP
;
1806 return IW_AUTH_CIPHER_CCMP
;
1808 return IW_AUTH_CIPHER_WEP104
;
1815 int wpa_driver_wext_keymgmt2wext(int keymgmt
)
1818 case KEY_MGMT_802_1X
:
1819 case KEY_MGMT_802_1X_NO_WPA
:
1820 return IW_AUTH_KEY_MGMT_802_1X
;
1822 return IW_AUTH_KEY_MGMT_PSK
;
1830 wpa_driver_wext_auth_alg_fallback(struct wpa_driver_wext_data
*drv
,
1831 struct wpa_driver_associate_params
*params
)
1836 wpa_printf(MSG_DEBUG
, "WEXT: Driver did not support "
1837 "SIOCSIWAUTH for AUTH_ALG, trying SIOCSIWENCODE");
1839 os_memset(&iwr
, 0, sizeof(iwr
));
1840 os_strlcpy(iwr
.ifr_name
, drv
->ifname
, IFNAMSIZ
);
1841 /* Just changing mode, not actual keys */
1842 iwr
.u
.encoding
.flags
= 0;
1843 iwr
.u
.encoding
.pointer
= (caddr_t
) NULL
;
1844 iwr
.u
.encoding
.length
= 0;
1847 * Note: IW_ENCODE_{OPEN,RESTRICTED} can be interpreted to mean two
1848 * different things. Here they are used to indicate Open System vs.
1849 * Shared Key authentication algorithm. However, some drivers may use
1850 * them to select between open/restricted WEP encrypted (open = allow
1851 * both unencrypted and encrypted frames; restricted = only allow
1852 * encrypted frames).
1855 if (!drv
->use_crypt
) {
1856 iwr
.u
.encoding
.flags
|= IW_ENCODE_DISABLED
;
1858 if (params
->auth_alg
& WPA_AUTH_ALG_OPEN
)
1859 iwr
.u
.encoding
.flags
|= IW_ENCODE_OPEN
;
1860 if (params
->auth_alg
& WPA_AUTH_ALG_SHARED
)
1861 iwr
.u
.encoding
.flags
|= IW_ENCODE_RESTRICTED
;
1864 if (ioctl(drv
->ioctl_sock
, SIOCSIWENCODE
, &iwr
) < 0) {
1865 perror("ioctl[SIOCSIWENCODE]");
1873 int wpa_driver_wext_associate(void *priv
,
1874 struct wpa_driver_associate_params
*params
)
1876 struct wpa_driver_wext_data
*drv
= priv
;
1878 int allow_unencrypted_eapol
;
1881 wpa_printf(MSG_DEBUG
, "%s", __FUNCTION__
);
1883 if (drv
->cfg80211
) {
1885 * Stop cfg80211 from trying to associate before we are done
1886 * with all parameters.
1888 wpa_driver_wext_set_ssid(drv
, (u8
*) "", 0);
1891 if (wpa_driver_wext_set_drop_unencrypted(drv
, params
->drop_unencrypted
)
1894 if (wpa_driver_wext_set_auth_alg(drv
, params
->auth_alg
) < 0)
1896 if (wpa_driver_wext_set_mode(drv
, params
->mode
) < 0)
1900 * If the driver did not support SIOCSIWAUTH, fallback to
1901 * SIOCSIWENCODE here.
1903 if (drv
->auth_alg_fallback
&&
1904 wpa_driver_wext_auth_alg_fallback(drv
, params
) < 0)
1907 if (!params
->bssid
&&
1908 wpa_driver_wext_set_bssid(drv
, NULL
) < 0)
1911 /* TODO: should consider getting wpa version and cipher/key_mgmt suites
1912 * from configuration, not from here, where only the selected suite is
1914 if (wpa_driver_wext_set_gen_ie(drv
, params
->wpa_ie
, params
->wpa_ie_len
)
1917 if (params
->wpa_ie
== NULL
|| params
->wpa_ie_len
== 0)
1918 value
= IW_AUTH_WPA_VERSION_DISABLED
;
1919 else if (params
->wpa_ie
[0] == WLAN_EID_RSN
)
1920 value
= IW_AUTH_WPA_VERSION_WPA2
;
1922 value
= IW_AUTH_WPA_VERSION_WPA
;
1923 if (wpa_driver_wext_set_auth_param(drv
,
1924 IW_AUTH_WPA_VERSION
, value
) < 0)
1926 value
= wpa_driver_wext_cipher2wext(params
->pairwise_suite
);
1927 if (wpa_driver_wext_set_auth_param(drv
,
1928 IW_AUTH_CIPHER_PAIRWISE
, value
) < 0)
1930 value
= wpa_driver_wext_cipher2wext(params
->group_suite
);
1931 if (wpa_driver_wext_set_auth_param(drv
,
1932 IW_AUTH_CIPHER_GROUP
, value
) < 0)
1934 value
= wpa_driver_wext_keymgmt2wext(params
->key_mgmt_suite
);
1935 if (wpa_driver_wext_set_auth_param(drv
,
1936 IW_AUTH_KEY_MGMT
, value
) < 0)
1938 value
= params
->key_mgmt_suite
!= KEY_MGMT_NONE
||
1939 params
->pairwise_suite
!= CIPHER_NONE
||
1940 params
->group_suite
!= CIPHER_NONE
||
1942 if (wpa_driver_wext_set_auth_param(drv
,
1943 IW_AUTH_PRIVACY_INVOKED
, value
) < 0)
1946 /* Allow unencrypted EAPOL messages even if pairwise keys are set when
1947 * not using WPA. IEEE 802.1X specifies that these frames are not
1948 * encrypted, but WPA encrypts them when pairwise keys are in use. */
1949 if (params
->key_mgmt_suite
== KEY_MGMT_802_1X
||
1950 params
->key_mgmt_suite
== KEY_MGMT_PSK
)
1951 allow_unencrypted_eapol
= 0;
1953 allow_unencrypted_eapol
= 1;
1955 if (wpa_driver_wext_set_psk(drv
, params
->psk
) < 0)
1957 if (wpa_driver_wext_set_auth_param(drv
,
1958 IW_AUTH_RX_UNENCRYPTED_EAPOL
,
1959 allow_unencrypted_eapol
) < 0)
1961 #ifdef CONFIG_IEEE80211W
1962 switch (params
->mgmt_frame_protection
) {
1963 case NO_MGMT_FRAME_PROTECTION
:
1964 value
= IW_AUTH_MFP_DISABLED
;
1966 case MGMT_FRAME_PROTECTION_OPTIONAL
:
1967 value
= IW_AUTH_MFP_OPTIONAL
;
1969 case MGMT_FRAME_PROTECTION_REQUIRED
:
1970 value
= IW_AUTH_MFP_REQUIRED
;
1973 if (wpa_driver_wext_set_auth_param(drv
, IW_AUTH_MFP
, value
) < 0)
1975 #endif /* CONFIG_IEEE80211W */
1976 if (params
->freq
&& wpa_driver_wext_set_freq(drv
, params
->freq
) < 0)
1978 if (!drv
->cfg80211
&&
1979 wpa_driver_wext_set_ssid(drv
, params
->ssid
, params
->ssid_len
) < 0)
1981 if (params
->bssid
&&
1982 wpa_driver_wext_set_bssid(drv
, params
->bssid
) < 0)
1984 if (drv
->cfg80211
&&
1985 wpa_driver_wext_set_ssid(drv
, params
->ssid
, params
->ssid_len
) < 0)
1992 static int wpa_driver_wext_set_auth_alg(void *priv
, int auth_alg
)
1994 struct wpa_driver_wext_data
*drv
= priv
;
1997 if (auth_alg
& WPA_AUTH_ALG_OPEN
)
1998 algs
|= IW_AUTH_ALG_OPEN_SYSTEM
;
1999 if (auth_alg
& WPA_AUTH_ALG_SHARED
)
2000 algs
|= IW_AUTH_ALG_SHARED_KEY
;
2001 if (auth_alg
& WPA_AUTH_ALG_LEAP
)
2002 algs
|= IW_AUTH_ALG_LEAP
;
2004 /* at least one algorithm should be set */
2005 algs
= IW_AUTH_ALG_OPEN_SYSTEM
;
2008 res
= wpa_driver_wext_set_auth_param(drv
, IW_AUTH_80211_AUTH_ALG
,
2010 drv
->auth_alg_fallback
= res
== -2;
2016 * wpa_driver_wext_set_mode - Set wireless mode (infra/adhoc), SIOCSIWMODE
2017 * @priv: Pointer to private wext data from wpa_driver_wext_init()
2018 * @mode: 0 = infra/BSS (associate with an AP), 1 = adhoc/IBSS
2019 * Returns: 0 on success, -1 on failure
2021 int wpa_driver_wext_set_mode(void *priv
, int mode
)
2023 struct wpa_driver_wext_data
*drv
= priv
;
2026 unsigned int new_mode
= mode
? IW_MODE_ADHOC
: IW_MODE_INFRA
;
2028 os_memset(&iwr
, 0, sizeof(iwr
));
2029 os_strlcpy(iwr
.ifr_name
, drv
->ifname
, IFNAMSIZ
);
2030 iwr
.u
.mode
= new_mode
;
2031 if (ioctl(drv
->ioctl_sock
, SIOCSIWMODE
, &iwr
) == 0) {
2036 if (errno
!= EBUSY
) {
2037 perror("ioctl[SIOCSIWMODE]");
2041 /* mac80211 doesn't allow mode changes while the device is up, so if
2042 * the device isn't in the mode we're about to change to, take device
2043 * down, try to set the mode again, and bring it back up.
2045 if (ioctl(drv
->ioctl_sock
, SIOCGIWMODE
, &iwr
) < 0) {
2046 perror("ioctl[SIOCGIWMODE]");
2050 if (iwr
.u
.mode
== new_mode
) {
2055 if (linux_set_iface_flags(drv
->ioctl_sock
, drv
->ifname
, 0) == 0) {
2056 /* Try to set the mode again while the interface is down */
2057 iwr
.u
.mode
= new_mode
;
2058 if (ioctl(drv
->ioctl_sock
, SIOCSIWMODE
, &iwr
) < 0)
2059 perror("ioctl[SIOCSIWMODE]");
2063 (void) linux_set_iface_flags(drv
->ioctl_sock
, drv
->ifname
, 1);
2071 static int wpa_driver_wext_pmksa(struct wpa_driver_wext_data
*drv
,
2072 u32 cmd
, const u8
*bssid
, const u8
*pmkid
)
2075 struct iw_pmksa pmksa
;
2078 os_memset(&iwr
, 0, sizeof(iwr
));
2079 os_strlcpy(iwr
.ifr_name
, drv
->ifname
, IFNAMSIZ
);
2080 os_memset(&pmksa
, 0, sizeof(pmksa
));
2082 pmksa
.bssid
.sa_family
= ARPHRD_ETHER
;
2084 os_memcpy(pmksa
.bssid
.sa_data
, bssid
, ETH_ALEN
);
2086 os_memcpy(pmksa
.pmkid
, pmkid
, IW_PMKID_LEN
);
2087 iwr
.u
.data
.pointer
= (caddr_t
) &pmksa
;
2088 iwr
.u
.data
.length
= sizeof(pmksa
);
2090 if (ioctl(drv
->ioctl_sock
, SIOCSIWPMKSA
, &iwr
) < 0) {
2091 if (errno
!= EOPNOTSUPP
)
2092 perror("ioctl[SIOCSIWPMKSA]");
2100 static int wpa_driver_wext_add_pmkid(void *priv
, const u8
*bssid
,
2103 struct wpa_driver_wext_data
*drv
= priv
;
2104 return wpa_driver_wext_pmksa(drv
, IW_PMKSA_ADD
, bssid
, pmkid
);
2108 static int wpa_driver_wext_remove_pmkid(void *priv
, const u8
*bssid
,
2111 struct wpa_driver_wext_data
*drv
= priv
;
2112 return wpa_driver_wext_pmksa(drv
, IW_PMKSA_REMOVE
, bssid
, pmkid
);
2116 static int wpa_driver_wext_flush_pmkid(void *priv
)
2118 struct wpa_driver_wext_data
*drv
= priv
;
2119 return wpa_driver_wext_pmksa(drv
, IW_PMKSA_FLUSH
, NULL
, NULL
);
2123 int wpa_driver_wext_get_capa(void *priv
, struct wpa_driver_capa
*capa
)
2125 struct wpa_driver_wext_data
*drv
= priv
;
2126 if (!drv
->has_capability
)
2128 os_memcpy(capa
, &drv
->capa
, sizeof(*capa
));
2133 int wpa_driver_wext_alternative_ifindex(struct wpa_driver_wext_data
*drv
,
2136 if (ifname
== NULL
) {
2141 drv
->ifindex2
= if_nametoindex(ifname
);
2142 if (drv
->ifindex2
<= 0)
2145 wpa_printf(MSG_DEBUG
, "Added alternative ifindex %d (%s) for "
2146 "wireless events", drv
->ifindex2
, ifname
);
2152 int wpa_driver_wext_set_operstate(void *priv
, int state
)
2154 struct wpa_driver_wext_data
*drv
= priv
;
2156 wpa_printf(MSG_DEBUG
, "%s: operstate %d->%d (%s)",
2157 __func__
, drv
->operstate
, state
, state
? "UP" : "DORMANT");
2158 drv
->operstate
= state
;
2159 return netlink_send_oper_ifla(drv
->netlink
, drv
->ifindex
, -1,
2160 state
? IF_OPER_UP
: IF_OPER_DORMANT
);
2164 int wpa_driver_wext_get_version(struct wpa_driver_wext_data
*drv
)
2166 return drv
->we_version_compiled
;
2170 const struct wpa_driver_ops wpa_driver_wext_ops
= {
2172 .desc
= "Linux wireless extensions (generic)",
2173 .get_bssid
= wpa_driver_wext_get_bssid
,
2174 .get_ssid
= wpa_driver_wext_get_ssid
,
2175 .set_key
= wpa_driver_wext_set_key
,
2176 .set_countermeasures
= wpa_driver_wext_set_countermeasures
,
2177 .scan2
= wpa_driver_wext_scan
,
2178 .get_scan_results2
= wpa_driver_wext_get_scan_results
,
2179 .deauthenticate
= wpa_driver_wext_deauthenticate
,
2180 .disassociate
= wpa_driver_wext_disassociate
,
2181 .associate
= wpa_driver_wext_associate
,
2182 .init
= wpa_driver_wext_init
,
2183 .deinit
= wpa_driver_wext_deinit
,
2184 .add_pmkid
= wpa_driver_wext_add_pmkid
,
2185 .remove_pmkid
= wpa_driver_wext_remove_pmkid
,
2186 .flush_pmkid
= wpa_driver_wext_flush_pmkid
,
2187 .get_capa
= wpa_driver_wext_get_capa
,
2188 .set_operstate
= wpa_driver_wext_set_operstate
,