2 * WPA Supplicant - driver interaction with Ralink Wireless Client
3 * Copyright (c) 2003-2006, Jouni Malinen <j@w1.fi>
4 * Copyright (c) 2007, Snowpin Lee <snowpin_lee@ralinktech.com.tw>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
10 * Alternatively, this software may be distributed under the terms of BSD
13 * See README and COPYING for more details.
18 #include <sys/ioctl.h>
20 #include "wireless_copy.h"
23 #include "l2_packet/l2_packet.h"
25 #include "common/ieee802_11_defs.h"
26 #include "priv_netlink.h"
28 #include "driver_ralink.h"
30 static void wpa_driver_ralink_scan_timeout(void *eloop_ctx
, void *timeout_ctx
);
32 #define MAX_SSID_LEN 32
34 struct wpa_driver_ralink_data
{
37 struct netlink_data
*netlink
;
38 char ifname
[IFNAMSIZ
+ 1];
40 size_t assoc_req_ies_len
;
42 size_t assoc_resp_ies_len
;
44 struct ndis_pmkid_entry
*pmkid
;
45 int we_version_compiled
;
52 static int ralink_set_oid(struct wpa_driver_ralink_data
*drv
,
53 unsigned short oid
, char *data
, int len
)
61 os_memset(&iwr
, 0, sizeof(iwr
));
62 os_strlcpy(iwr
.ifr_name
, drv
->ifname
, IFNAMSIZ
);
63 iwr
.u
.data
.flags
= oid
;
64 iwr
.u
.data
.flags
|= OID_GET_SET_TOGGLE
;
67 os_memcpy(buf
, data
, len
);
69 iwr
.u
.data
.pointer
= (caddr_t
) buf
;
70 iwr
.u
.data
.length
= len
;
72 if (ioctl(drv
->ioctl_sock
, RT_PRIV_IOCTL
, &iwr
) < 0) {
73 wpa_printf(MSG_DEBUG
, "%s: oid=0x%x len (%d) failed",
83 ralink_get_new_driver_flag(struct wpa_driver_ralink_data
*drv
)
88 os_memset(&iwr
, 0, sizeof(iwr
));
89 os_strlcpy(iwr
.ifr_name
, drv
->ifname
, IFNAMSIZ
);
90 iwr
.u
.data
.pointer
= (UCHAR
*) &enabled
;
91 iwr
.u
.data
.flags
= RT_OID_NEW_DRIVER
;
93 if (ioctl(drv
->ioctl_sock
, RT_PRIV_IOCTL
, &iwr
) < 0) {
94 wpa_printf(MSG_DEBUG
, "%s: failed", __func__
);
98 return (enabled
== 1) ? 1 : 0;
101 static int wpa_driver_ralink_get_bssid(void *priv
, u8
*bssid
)
103 struct wpa_driver_ralink_data
*drv
= priv
;
107 if (drv
->g_driver_down
== 1)
110 wpa_printf(MSG_DEBUG
, "%s", __FUNCTION__
);
112 os_memset(&iwr
, 0, sizeof(iwr
));
113 os_strlcpy(iwr
.ifr_name
, drv
->ifname
, IFNAMSIZ
);
115 if (ioctl(drv
->ioctl_sock
, SIOCGIWAP
, &iwr
) < 0) {
116 perror("ioctl[SIOCGIWAP]");
119 os_memcpy(bssid
, iwr
.u
.ap_addr
.sa_data
, ETH_ALEN
);
124 static int wpa_driver_ralink_get_ssid(void *priv
, u8
*ssid
)
126 struct wpa_driver_ralink_data
*drv
= priv
;
128 struct wpa_supplicant
*wpa_s
= drv
->ctx
;
129 struct wpa_ssid
*entry
;
133 u8 ssid_str
[MAX_SSID_LEN
];
140 BOOLEAN ieee8021x_mode
= FALSE
;
141 BOOLEAN ieee8021x_required_key
= FALSE
;
144 if (drv
->g_driver_down
== 1)
147 wpa_printf(MSG_DEBUG
, "%s", __FUNCTION__
);
149 os_memset(&iwr
, 0, sizeof(iwr
));
150 os_strlcpy(iwr
.ifr_name
, drv
->ifname
, IFNAMSIZ
);
151 iwr
.u
.essid
.pointer
= (caddr_t
) ssid
;
152 iwr
.u
.essid
.length
= 32;
154 if (ioctl(drv
->ioctl_sock
, SIOCGIWESSID
, &iwr
) < 0) {
155 perror("ioctl[SIOCGIWESSID]");
158 ret
= iwr
.u
.essid
.length
;
164 os_memset(ssid_str
, 0, MAX_SSID_LEN
);
165 os_memcpy(ssid_str
, ssid
, ssid_len
);
167 if (drv
->ap_scan
== 0) {
168 /* Read BSSID form driver */
169 if (wpa_driver_ralink_get_bssid(priv
, bssid
) < 0) {
170 wpa_printf(MSG_WARNING
, "Could not read BSSID from "
176 entry
= wpa_s
->conf
->ssid
;
178 if (!entry
->disabled
&& ssid_len
== entry
->ssid_len
&&
179 os_memcmp(ssid_str
, entry
->ssid
, ssid_len
) == 0 &&
180 (!entry
->bssid_set
||
181 os_memcmp(bssid
, entry
->bssid
, ETH_ALEN
) == 0)) {
182 /* match the config of driver */
190 wpa_printf(MSG_DEBUG
, "Ready to set 802.1x mode and "
191 "ieee_required_keys parameters to driver");
193 /* set 802.1x mode and ieee_required_keys parameter */
194 if (entry
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
) {
195 if ((entry
->eapol_flags
& (EAPOL_FLAG_REQUIRE_KEY_UNICAST
| EAPOL_FLAG_REQUIRE_KEY_BROADCAST
)))
196 ieee8021x_required_key
= TRUE
;
197 ieee8021x_mode
= TRUE
;
200 if (ralink_set_oid(drv
, OID_802_11_SET_IEEE8021X
, (char *) &ieee8021x_mode
, sizeof(BOOLEAN
)) < 0)
202 wpa_printf(MSG_DEBUG
, "RALINK: Failed to set OID_802_11_SET_IEEE8021X(%d)", (int) ieee8021x_mode
);
206 wpa_printf(MSG_DEBUG
, "ieee8021x_mode is %s", ieee8021x_mode
? "TRUE" : "FALSE");
209 if (ralink_set_oid(drv
, OID_802_11_SET_IEEE8021X_REQUIRE_KEY
, (char *) &ieee8021x_required_key
, sizeof(BOOLEAN
)) < 0)
211 wpa_printf(MSG_DEBUG
, "ERROR: Failed to set OID_802_11_SET_IEEE8021X_REQUIRE_KEY(%d)", (int) ieee8021x_required_key
);
215 wpa_printf(MSG_DEBUG
, "ieee8021x_required_key is %s and eapol_flag(%d)", ieee8021x_required_key
? "TRUE" : "FALSE",
225 static int wpa_driver_ralink_set_ssid(struct wpa_driver_ralink_data
*drv
,
226 const u8
*ssid
, size_t ssid_len
)
228 NDIS_802_11_SSID
*buf
;
232 wpa_printf(MSG_DEBUG
, "%s", __FUNCTION__
);
234 buf
= os_zalloc(sizeof(NDIS_802_11_SSID
));
237 os_memset(buf
, 0, sizeof(buf
));
238 buf
->SsidLength
= ssid_len
;
239 os_memcpy(buf
->Ssid
, ssid
, ssid_len
);
240 os_memset(&iwr
, 0, sizeof(iwr
));
241 os_strlcpy(iwr
.ifr_name
, drv
->ifname
, IFNAMSIZ
);
243 iwr
.u
.data
.flags
= OID_802_11_SSID
;
244 iwr
.u
.data
.flags
|= OID_GET_SET_TOGGLE
;
245 iwr
.u
.data
.pointer
= (caddr_t
) buf
;
246 iwr
.u
.data
.length
= sizeof(NDIS_802_11_SSID
);
248 if (ioctl(drv
->ioctl_sock
, RT_PRIV_IOCTL
, &iwr
) < 0) {
249 perror("ioctl[RT_PRIV_IOCTL] -- OID_802_11_SSID");
256 static void wpa_driver_ralink_event_pmkid(struct wpa_driver_ralink_data
*drv
,
257 const u8
*data
, size_t data_len
)
259 NDIS_802_11_PMKID_CANDIDATE_LIST
*pmkid
;
261 union wpa_event_data event
;
263 wpa_printf(MSG_DEBUG
, "%s", __FUNCTION__
);
266 wpa_printf(MSG_DEBUG
, "RALINK: Too short PMKID Candidate List "
267 "Event (len=%lu)", (unsigned long) data_len
);
270 pmkid
= (NDIS_802_11_PMKID_CANDIDATE_LIST
*) data
;
271 wpa_printf(MSG_DEBUG
, "RALINK: PMKID Candidate List Event - Version %d"
273 (int) pmkid
->Version
, (int) pmkid
->NumCandidates
);
275 if (pmkid
->Version
!= 1) {
276 wpa_printf(MSG_DEBUG
, "RALINK: Unsupported PMKID Candidate "
277 "List Version %d", (int) pmkid
->Version
);
281 if (data_len
< 8 + pmkid
->NumCandidates
* sizeof(PMKID_CANDIDATE
)) {
282 wpa_printf(MSG_DEBUG
, "RALINK: PMKID Candidate List "
290 os_memset(&event
, 0, sizeof(event
));
291 for (i
= 0; i
< pmkid
->NumCandidates
; i
++) {
292 PMKID_CANDIDATE
*p
= &pmkid
->CandidateList
[i
];
293 wpa_printf(MSG_DEBUG
, "RALINK: %lu: " MACSTR
" Flags 0x%x",
294 (unsigned long) i
, MAC2STR(p
->BSSID
),
296 os_memcpy(event
.pmkid_candidate
.bssid
, p
->BSSID
, ETH_ALEN
);
297 event
.pmkid_candidate
.index
= i
;
298 event
.pmkid_candidate
.preauth
=
299 p
->Flags
& NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED
;
300 wpa_supplicant_event(drv
->ctx
, EVENT_PMKID_CANDIDATE
,
305 static int wpa_driver_ralink_set_pmkid(struct wpa_driver_ralink_data
*drv
)
307 int len
, count
, i
, ret
;
308 struct ndis_pmkid_entry
*entry
;
309 NDIS_802_11_PMKID
*p
;
311 wpa_printf(MSG_DEBUG
, "%s", __FUNCTION__
);
317 if (count
>= drv
->no_of_pmkid
)
321 len
= 8 + count
* sizeof(BSSID_INFO
);
326 p
->BSSIDInfoCount
= count
;
328 for (i
= 0; i
< count
; i
++) {
329 os_memcpy(&p
->BSSIDInfo
[i
].BSSID
, entry
->bssid
, ETH_ALEN
);
330 os_memcpy(&p
->BSSIDInfo
[i
].PMKID
, entry
->pmkid
, 16);
333 wpa_hexdump(MSG_MSGDUMP
, "NDIS: OID_802_11_PMKID",
334 (const u8
*) p
, len
);
335 ret
= ralink_set_oid(drv
, OID_802_11_PMKID
, (char *) p
, len
);
340 static int wpa_driver_ralink_add_pmkid(void *priv
, const u8
*bssid
,
343 struct wpa_driver_ralink_data
*drv
= priv
;
344 struct ndis_pmkid_entry
*entry
, *prev
;
346 if (drv
->g_driver_down
== 1)
349 wpa_printf(MSG_DEBUG
, "%s", __FUNCTION__
);
351 if (drv
->no_of_pmkid
== 0)
357 if (os_memcmp(entry
->bssid
, bssid
, ETH_ALEN
) == 0)
364 /* Replace existing entry for this BSSID and move it into the
365 * beginning of the list. */
366 os_memcpy(entry
->pmkid
, pmkid
, 16);
368 prev
->next
= entry
->next
;
369 entry
->next
= drv
->pmkid
;
373 entry
= os_malloc(sizeof(*entry
));
375 os_memcpy(entry
->bssid
, bssid
, ETH_ALEN
);
376 os_memcpy(entry
->pmkid
, pmkid
, 16);
377 entry
->next
= drv
->pmkid
;
382 return wpa_driver_ralink_set_pmkid(drv
);
386 static int wpa_driver_ralink_remove_pmkid(void *priv
, const u8
*bssid
,
389 struct wpa_driver_ralink_data
*drv
= priv
;
390 struct ndis_pmkid_entry
*entry
, *prev
;
392 if (drv
->g_driver_down
== 1)
395 wpa_printf(MSG_DEBUG
, "%s", __FUNCTION__
);
397 if (drv
->no_of_pmkid
== 0)
404 if (os_memcmp(entry
->bssid
, bssid
, ETH_ALEN
) == 0 &&
405 os_memcmp(entry
->pmkid
, pmkid
, 16) == 0) {
407 prev
->next
= entry
->next
;
409 drv
->pmkid
= entry
->next
;
416 return wpa_driver_ralink_set_pmkid(drv
);
420 static int wpa_driver_ralink_flush_pmkid(void *priv
)
422 struct wpa_driver_ralink_data
*drv
= priv
;
424 struct ndis_pmkid_entry
*pmkid
, *prev
;
426 if (drv
->g_driver_down
== 1)
429 wpa_printf(MSG_DEBUG
, "%s", __FUNCTION__
);
431 if (drv
->no_of_pmkid
== 0)
442 os_memset(&p
, 0, sizeof(p
));
444 p
.BSSIDInfoCount
= 0;
445 wpa_hexdump(MSG_MSGDUMP
, "NDIS: OID_802_11_PMKID (flush)",
447 return ralink_set_oid(drv
, OID_802_11_PMKID
, (char *) &p
, 8);
451 wpa_driver_ralink_event_wireless_custom(struct wpa_driver_ralink_data
*drv
,
452 void *ctx
, char *custom
)
454 union wpa_event_data data
;
456 wpa_printf(MSG_DEBUG
, "%s", __FUNCTION__
);
458 wpa_printf(MSG_DEBUG
, "Custom wireless event: '%s'", custom
);
460 os_memset(&data
, 0, sizeof(data
));
462 if (os_strncmp(custom
, "MLME-MICHAELMICFAILURE.indication", 33) == 0) {
463 /* receive a MICFAILURE report */
464 data
.michael_mic_failure
.unicast
=
465 os_strstr(custom
, " unicast") != NULL
;
466 /* TODO: parse parameters(?) */
467 wpa_supplicant_event(ctx
, EVENT_MICHAEL_MIC_FAILURE
, &data
);
468 } else if (os_strncmp(custom
, "ASSOCINFO_ReqIEs=", 17) == 0) {
469 /* receive assoc. req. IEs */
476 * bytes = strlen(spos); ==> bug, bytes may less than original
477 * size by using this way to get size. snowpin 20070312
481 bytes
= drv
->assoc_req_ies_len
;
483 data
.assoc_info
.req_ies
= os_malloc(bytes
);
484 if (data
.assoc_info
.req_ies
== NULL
)
487 data
.assoc_info
.req_ies_len
= bytes
;
488 os_memcpy(data
.assoc_info
.req_ies
, spos
, bytes
);
490 /* skip the '\0' byte */
493 data
.assoc_info
.resp_ies
= NULL
;
494 data
.assoc_info
.resp_ies_len
= 0;
496 if (os_strncmp(spos
, " RespIEs=", 9) == 0) {
497 /* receive assoc. resp. IEs */
499 /* get IE's length */
500 bytes
= os_strlen(spos
);
505 data
.assoc_info
.resp_ies
= os_malloc(bytes
);
506 if (data
.assoc_info
.resp_ies
== NULL
)
509 data
.assoc_info
.resp_ies_len
= bytes
;
510 os_memcpy(data
.assoc_info
.resp_ies
, spos
, bytes
);
513 wpa_supplicant_event(ctx
, EVENT_ASSOCINFO
, &data
);
515 /* free allocated memory */
517 os_free(data
.assoc_info
.resp_ies
);
518 os_free(data
.assoc_info
.req_ies
);
522 static void ralink_interface_up(struct wpa_driver_ralink_data
*drv
)
524 union wpa_event_data event
;
525 int enable_wpa_supplicant
= 0;
526 drv
->g_driver_down
= 0;
527 os_memset(&event
, 0, sizeof(event
));
528 os_snprintf(event
.interface_status
.ifname
,
529 sizeof(event
.interface_status
.ifname
), "%s", drv
->ifname
);
531 event
.interface_status
.ievent
= EVENT_INTERFACE_ADDED
;
532 wpa_supplicant_event(drv
->ctx
, EVENT_INTERFACE_STATUS
, &event
);
534 if (drv
->ap_scan
== 1)
535 enable_wpa_supplicant
= 1;
537 enable_wpa_supplicant
= 2;
538 /* trigger driver support wpa_supplicant */
539 if (ralink_set_oid(drv
, RT_OID_WPA_SUPPLICANT_SUPPORT
,
540 (PCHAR
) &enable_wpa_supplicant
, sizeof(UCHAR
)) < 0)
542 wpa_printf(MSG_INFO
, "RALINK: Failed to set "
543 "RT_OID_WPA_SUPPLICANT_SUPPORT(%d)",
544 (int) enable_wpa_supplicant
);
545 wpa_printf(MSG_ERROR
, "ralink. Driver does not support "
551 wpa_driver_ralink_event_wireless(struct wpa_driver_ralink_data
*drv
,
552 void *ctx
, char *data
, int len
)
554 struct iw_event iwe_buf
, *iwe
= &iwe_buf
;
555 char *pos
, *end
, *custom
, *buf
, *assoc_info_buf
, *info_pos
;
557 BOOLEAN ieee8021x_required_key
= FALSE
;
560 wpa_printf(MSG_DEBUG
, "%s", __FUNCTION__
);
562 assoc_info_buf
= info_pos
= NULL
;
566 while (pos
+ IW_EV_LCP_LEN
<= end
) {
567 /* Event data may be unaligned, so make a local, aligned copy
568 * before processing. */
569 os_memcpy(&iwe_buf
, pos
, IW_EV_LCP_LEN
);
570 wpa_printf(MSG_DEBUG
, "Wireless event: cmd=0x%x len=%d",
572 if (iwe
->len
<= IW_EV_LCP_LEN
)
575 custom
= pos
+ IW_EV_POINT_LEN
;
577 if (drv
->we_version_compiled
> 18 && iwe
->cmd
== IWEVCUSTOM
) {
578 /* WE-19 removed the pointer from struct iw_point */
579 char *dpos
= (char *) &iwe_buf
.u
.data
.length
;
580 int dlen
= dpos
- (char *) &iwe_buf
;
581 os_memcpy(dpos
, pos
+ IW_EV_LCP_LEN
,
582 sizeof(struct iw_event
) - dlen
);
584 os_memcpy(&iwe_buf
, pos
, sizeof(struct iw_event
));
585 custom
+= IW_EV_POINT_OFF
;
590 if (custom
+ iwe
->u
.data
.length
> end
)
592 buf
= os_malloc(iwe
->u
.data
.length
+ 1);
595 os_memcpy(buf
, custom
, iwe
->u
.data
.length
);
596 buf
[iwe
->u
.data
.length
] = '\0';
598 if (drv
->ap_scan
== 1) {
599 if ((iwe
->u
.data
.flags
== RT_ASSOC_EVENT_FLAG
)
600 || (iwe
->u
.data
.flags
==
601 RT_REQIE_EVENT_FLAG
) ||
602 (iwe
->u
.data
.flags
== RT_RESPIE_EVENT_FLAG
)
603 || (iwe
->u
.data
.flags
==
604 RT_ASSOCINFO_EVENT_FLAG
)) {
605 if (drv
->scanning_done
== 0) {
612 if (iwe
->u
.data
.flags
== RT_ASSOC_EVENT_FLAG
) {
613 wpa_supplicant_event(ctx
, EVENT_ASSOC
, NULL
);
614 wpa_printf(MSG_DEBUG
, "Custom wireless event: "
615 "receive ASSOCIATED_EVENT !!!");
616 } else if (iwe
->u
.data
.flags
== RT_REQIE_EVENT_FLAG
) {
617 wpa_printf(MSG_DEBUG
, "Custom wireless event: "
618 "receive ReqIEs !!!");
620 os_malloc(iwe
->u
.data
.length
);
621 if (drv
->assoc_req_ies
== NULL
) {
626 drv
->assoc_req_ies_len
= iwe
->u
.data
.length
;
627 os_memcpy(drv
->assoc_req_ies
, custom
,
629 } else if (iwe
->u
.data
.flags
== RT_RESPIE_EVENT_FLAG
) {
630 wpa_printf(MSG_DEBUG
, "Custom wireless event: "
631 "receive RespIEs !!!");
632 drv
->assoc_resp_ies
=
633 os_malloc(iwe
->u
.data
.length
);
634 if (drv
->assoc_resp_ies
== NULL
) {
635 os_free(drv
->assoc_req_ies
);
636 drv
->assoc_req_ies
= NULL
;
641 drv
->assoc_resp_ies_len
= iwe
->u
.data
.length
;
642 os_memcpy(drv
->assoc_resp_ies
, custom
,
644 } else if (iwe
->u
.data
.flags
==
645 RT_ASSOCINFO_EVENT_FLAG
) {
646 wpa_printf(MSG_DEBUG
, "Custom wireless event: "
647 "receive ASSOCINFO_EVENT !!!");
650 os_zalloc(drv
->assoc_req_ies_len
+
651 drv
->assoc_resp_ies_len
+ 1);
653 if (assoc_info_buf
== NULL
) {
654 os_free(drv
->assoc_req_ies
);
655 drv
->assoc_req_ies
= NULL
;
656 os_free(drv
->assoc_resp_ies
);
657 drv
->assoc_resp_ies
= NULL
;
662 if (drv
->assoc_req_ies
) {
663 os_memcpy(assoc_info_buf
,
665 drv
->assoc_req_ies_len
);
667 info_pos
= assoc_info_buf
+
668 drv
->assoc_req_ies_len
;
669 if (drv
->assoc_resp_ies
) {
672 drv
->assoc_resp_ies_len
);
674 assoc_info_buf
[drv
->assoc_req_ies_len
+
675 drv
->assoc_resp_ies_len
] = '\0';
676 wpa_driver_ralink_event_wireless_custom(
677 drv
, ctx
, assoc_info_buf
);
678 os_free(drv
->assoc_req_ies
);
679 drv
->assoc_req_ies
= NULL
;
680 os_free(drv
->assoc_resp_ies
);
681 drv
->assoc_resp_ies
= NULL
;
682 os_free(assoc_info_buf
);
683 } else if (iwe
->u
.data
.flags
== RT_DISASSOC_EVENT_FLAG
)
685 wpa_printf(MSG_DEBUG
, "Custom wireless event: "
686 "receive DISASSOCIATED_EVENT !!!");
687 wpa_supplicant_event(ctx
, EVENT_DISASSOC
,
689 } else if (iwe
->u
.data
.flags
== RT_PMKIDCAND_FLAG
) {
690 wpa_printf(MSG_DEBUG
, "Custom wireless event: "
691 "receive PMKIDCAND_EVENT !!!");
692 wpa_driver_ralink_event_pmkid(
693 drv
, (const u8
*) custom
,
695 } else if (iwe
->u
.data
.flags
== RT_INTERFACE_DOWN
) {
696 drv
->g_driver_down
= 1;
698 } else if (iwe
->u
.data
.flags
== RT_INTERFACE_UP
) {
699 ralink_interface_up(drv
);
701 wpa_driver_ralink_event_wireless_custom(
713 wpa_driver_ralink_event_rtm_newlink(void *ctx
, struct ifinfomsg
*ifi
,
716 struct wpa_driver_ralink_data
*drv
= ctx
;
717 int attrlen
, rta_len
;
720 wpa_printf(MSG_DEBUG
, "%s", __FUNCTION__
);
722 wpa_hexdump(MSG_DEBUG
, "ifi: ", (u8
*) ifi
, sizeof(struct ifinfomsg
));
725 wpa_printf(MSG_DEBUG
, "attrlen=%d", attrlen
);
726 attr
= (struct rtattr
*) buf
;
727 wpa_hexdump(MSG_DEBUG
, "attr1: ", (u8
*) attr
, sizeof(struct rtattr
));
728 rta_len
= RTA_ALIGN(sizeof(struct rtattr
));
729 wpa_hexdump(MSG_DEBUG
, "attr2: ", (u8
*)attr
,rta_len
);
730 while (RTA_OK(attr
, attrlen
)) {
731 wpa_printf(MSG_DEBUG
, "rta_type=%02x\n", attr
->rta_type
);
732 if (attr
->rta_type
== IFLA_WIRELESS
) {
733 wpa_driver_ralink_event_wireless(
735 ((char *) attr
) + rta_len
,
736 attr
->rta_len
- rta_len
);
738 attr
= RTA_NEXT(attr
, attrlen
);
739 wpa_hexdump(MSG_DEBUG
, "attr3: ",
740 (u8
*) attr
, sizeof(struct rtattr
));
745 ralink_get_we_version_compiled(struct wpa_driver_ralink_data
*drv
)
748 UINT we_version_compiled
= 0;
750 os_memset(&iwr
, 0, sizeof(iwr
));
751 os_strlcpy(iwr
.ifr_name
, drv
->ifname
, IFNAMSIZ
);
752 iwr
.u
.data
.pointer
= (caddr_t
) &we_version_compiled
;
753 iwr
.u
.data
.flags
= RT_OID_WE_VERSION_COMPILED
;
755 if (ioctl(drv
->ioctl_sock
, RT_PRIV_IOCTL
, &iwr
) < 0) {
756 wpa_printf(MSG_DEBUG
, "%s: failed", __func__
);
760 drv
->we_version_compiled
= we_version_compiled
;
766 ralink_set_iface_flags(void *priv
, int dev_up
)
768 struct wpa_driver_ralink_data
*drv
= priv
;
771 wpa_printf(MSG_DEBUG
, "%s", __FUNCTION__
);
773 if (drv
->ioctl_sock
< 0)
776 os_memset(&ifr
, 0, sizeof(ifr
));
777 os_snprintf(ifr
.ifr_name
, IFNAMSIZ
, "%s", drv
->ifname
);
779 if (ioctl(drv
->ioctl_sock
, SIOCGIFFLAGS
, &ifr
) != 0) {
780 perror("ioctl[SIOCGIFFLAGS]");
785 ifr
.ifr_flags
|= IFF_UP
;
787 ifr
.ifr_flags
&= ~IFF_UP
;
789 if (ioctl(drv
->ioctl_sock
, SIOCSIFFLAGS
, &ifr
) != 0) {
790 perror("ioctl[SIOCSIFFLAGS]");
797 static void * wpa_driver_ralink_init(void *ctx
, const char *ifname
)
800 struct wpa_driver_ralink_data
*drv
;
802 UCHAR enable_wpa_supplicant
= 0;
803 struct netlink_config
*cfg
;
805 wpa_printf(MSG_DEBUG
, "%s", __FUNCTION__
);
807 /* open socket to kernel */
808 if ((s
= socket(AF_INET
, SOCK_DGRAM
, 0)) < 0) {
813 os_strlcpy(ifr
.ifr_name
, ifname
, IFNAMSIZ
);
815 if (ioctl(s
, SIOCGIFINDEX
, &ifr
) < 0) {
816 perror(ifr
.ifr_name
);
820 drv
= os_zalloc(sizeof(*drv
));
824 drv
->scanning_done
= 1;
825 drv
->ap_scan
= 1; /* for now - let's assume ap_scan=1 is used */
827 os_strlcpy(drv
->ifname
, ifname
, sizeof(drv
->ifname
));
829 drv
->g_driver_down
= 0;
831 cfg
= os_zalloc(sizeof(*cfg
));
833 close(drv
->ioctl_sock
);
838 cfg
->newlink_cb
= wpa_driver_ralink_event_rtm_newlink
;
839 drv
->netlink
= netlink_init(cfg
);
840 if (drv
->netlink
== NULL
) {
842 close(drv
->ioctl_sock
);
847 drv
->no_of_pmkid
= 4; /* Number of PMKID saved supported */
849 ralink_set_iface_flags(drv
, 1); /* mark up during setup */
850 ralink_get_we_version_compiled(drv
);
851 wpa_driver_ralink_flush_pmkid(drv
);
853 if (drv
->ap_scan
== 1)
854 enable_wpa_supplicant
= 1;
856 enable_wpa_supplicant
= 2;
857 /* trigger driver support wpa_supplicant */
858 if (ralink_set_oid(drv
, RT_OID_WPA_SUPPLICANT_SUPPORT
,
859 (PCHAR
) &enable_wpa_supplicant
, sizeof(UCHAR
)) < 0)
861 wpa_printf(MSG_DEBUG
, "RALINK: Failed to set "
862 "RT_OID_WPA_SUPPLICANT_SUPPORT(%d)",
863 (int) enable_wpa_supplicant
);
864 wpa_printf(MSG_ERROR
, "RALINK: Driver does not support "
867 close(drv
->ioctl_sock
);
872 if (drv
->ap_scan
== 1)
873 drv
->scanning_done
= 0;
878 static void wpa_driver_ralink_deinit(void *priv
)
880 struct wpa_driver_ralink_data
*drv
= priv
;
881 UCHAR enable_wpa_supplicant
;
883 wpa_printf(MSG_DEBUG
, "%s", __FUNCTION__
);
885 enable_wpa_supplicant
= 0;
887 if (drv
->g_driver_down
== 0) {
888 /* trigger driver disable wpa_supplicant support */
889 if (ralink_set_oid(drv
, RT_OID_WPA_SUPPLICANT_SUPPORT
,
890 (char *) &enable_wpa_supplicant
,
891 sizeof(BOOLEAN
)) < 0) {
892 wpa_printf(MSG_DEBUG
, "RALINK: Failed to set "
893 "RT_OID_WPA_SUPPLICANT_SUPPORT(%d)",
894 (int) enable_wpa_supplicant
);
897 wpa_driver_ralink_flush_pmkid(drv
);
900 /* ralink_set_iface_flags(drv, 0); */
903 eloop_cancel_timeout(wpa_driver_ralink_scan_timeout
, drv
, drv
->ctx
);
904 netlink_deinit(drv
->netlink
);
905 close(drv
->ioctl_sock
);
909 static void wpa_driver_ralink_scan_timeout(void *eloop_ctx
, void *timeout_ctx
)
911 struct wpa_driver_ralink_data
*drv
= eloop_ctx
;
913 wpa_printf(MSG_DEBUG
, "%s", __FUNCTION__
);
915 wpa_printf(MSG_DEBUG
, "Scan timeout - try to get results");
916 wpa_supplicant_event(timeout_ctx
, EVENT_SCAN_RESULTS
, NULL
);
918 drv
->scanning_done
= 1;
922 static int wpa_driver_ralink_scan(void *priv
,
923 struct wpa_driver_scan_params
*params
)
925 struct wpa_driver_ralink_data
*drv
= priv
;
929 if (drv
->g_driver_down
== 1)
932 wpa_printf(MSG_DEBUG
, "%s", __FUNCTION__
);
935 if (ssid_len
> IW_ESSID_MAX_SIZE
) {
936 wpa_printf(MSG_DEBUG
, "%s: too long SSID (%lu)",
937 __FUNCTION__
, (unsigned long) ssid_len
);
941 /* wpa_driver_ralink_set_ssid(drv, ssid, ssid_len); */
944 if (ralink_set_oid(drv
, RT_OID_WPS_PROBE_REQ_IE
,
945 (char *) params
->extra_ies
, params
->extra_ies_len
) <
947 wpa_printf(MSG_DEBUG
, "RALINK: Failed to set "
948 "RT_OID_WPS_PROBE_REQ_IE");
951 os_memset(&iwr
, 0, sizeof(iwr
));
952 os_strlcpy(iwr
.ifr_name
, drv
->ifname
, IFNAMSIZ
);
954 if (ioctl(drv
->ioctl_sock
, SIOCSIWSCAN
, &iwr
) < 0) {
955 perror("ioctl[SIOCSIWSCAN]");
959 /* Not all drivers generate "scan completed" wireless event, so try to
960 * read results after a timeout. */
961 eloop_cancel_timeout(wpa_driver_ralink_scan_timeout
, drv
, drv
->ctx
);
962 eloop_register_timeout(4, 0, wpa_driver_ralink_scan_timeout
, drv
,
965 drv
->scanning_done
= 0;
970 static struct wpa_scan_results
*
971 wpa_driver_ralink_get_scan_results(void *priv
)
973 struct wpa_driver_ralink_data
*drv
= priv
;
976 NDIS_802_11_BSSID_LIST_EX
*wsr
;
977 NDIS_WLAN_BSSID_EX
*wbi
;
981 struct wpa_scan_results
*res
;
983 if (drv
->g_driver_down
== 1)
985 wpa_printf(MSG_DEBUG
, "%s", __FUNCTION__
);
987 if (drv
->we_version_compiled
>= 17)
993 buf
= os_zalloc(buf_len
);
994 iwr
.u
.data
.length
= buf_len
;
998 wsr
= (NDIS_802_11_BSSID_LIST_EX
*) buf
;
1000 wsr
->NumberOfItems
= 0;
1001 os_strlcpy(iwr
.ifr_name
, drv
->ifname
, IFNAMSIZ
);
1002 iwr
.u
.data
.pointer
= (void *) buf
;
1003 iwr
.u
.data
.flags
= OID_802_11_BSSID_LIST
;
1005 if (ioctl(drv
->ioctl_sock
, RT_PRIV_IOCTL
, &iwr
) == 0)
1008 if (errno
== E2BIG
&& buf_len
< 65535) {
1012 if (buf_len
> 65535)
1013 buf_len
= 65535; /* 16-bit length field */
1014 wpa_printf(MSG_DEBUG
, "Scan results did not fit - "
1015 "trying larger buffer (%lu bytes)",
1016 (unsigned long) buf_len
);
1018 perror("ioctl[RT_PRIV_IOCTL]");
1024 res
= os_zalloc(sizeof(*res
));
1030 res
->res
= os_zalloc(wsr
->NumberOfItems
*
1031 sizeof(struct wpa_scan_res
*));
1032 if (res
->res
== NULL
) {
1038 for (ap_num
= 0, wbi
= wsr
->Bssid
; ap_num
< wsr
->NumberOfItems
;
1040 struct wpa_scan_res
*r
= NULL
;
1041 size_t extra_len
= 0, var_ie_len
= 0;
1044 /* SSID data element */
1045 extra_len
+= 2 + wbi
->Ssid
.SsidLength
;
1046 var_ie_len
= wbi
->IELength
- sizeof(NDIS_802_11_FIXED_IEs
);
1047 r
= os_zalloc(sizeof(*r
) + extra_len
+ var_ie_len
);
1050 res
->res
[res
->num
++] = r
;
1052 wpa_printf(MSG_DEBUG
, "SSID - %s", wbi
->Ssid
.Ssid
);
1054 wpa_hexdump(MSG_DEBUG
, "RALINK: AP IEs",
1055 (u8
*) &wbi
->IEs
[0], wbi
->IELength
);
1057 os_memcpy(r
->bssid
, wbi
->MacAddress
, ETH_ALEN
);
1059 extra_len
+= (2 + wbi
->Ssid
.SsidLength
);
1060 r
->ie_len
= extra_len
+ var_ie_len
;
1061 pos2
= (u8
*) (r
+ 1);
1064 * Generate a fake SSID IE since the driver did not report
1067 *pos2
++ = WLAN_EID_SSID
;
1068 *pos2
++ = wbi
->Ssid
.SsidLength
;
1069 os_memcpy(pos2
, wbi
->Ssid
.Ssid
, wbi
->Ssid
.SsidLength
);
1070 pos2
+= wbi
->Ssid
.SsidLength
;
1072 r
->freq
= (wbi
->Configuration
.DSConfig
/ 1000);
1074 pos
= (u8
*) wbi
+ sizeof(*wbi
) - 1;
1076 pos
+= sizeof(NDIS_802_11_FIXED_IEs
) - 2;
1077 os_memcpy(&(r
->caps
), pos
, 2);
1080 if (wbi
->IELength
> sizeof(NDIS_802_11_FIXED_IEs
))
1081 os_memcpy(pos2
, pos
, var_ie_len
);
1083 wbi
= (NDIS_WLAN_BSSID_EX
*) ((u8
*) wbi
+ wbi
->Length
);
1090 static int ralink_set_auth_mode(struct wpa_driver_ralink_data
*drv
,
1091 NDIS_802_11_AUTHENTICATION_MODE mode
)
1093 NDIS_802_11_AUTHENTICATION_MODE auth_mode
= mode
;
1095 wpa_printf(MSG_DEBUG
, "%s", __FUNCTION__
);
1097 if (ralink_set_oid(drv
, OID_802_11_AUTHENTICATION_MODE
,
1098 (char *) &auth_mode
, sizeof(auth_mode
)) < 0) {
1099 wpa_printf(MSG_DEBUG
, "RALINK: Failed to set "
1100 "OID_802_11_AUTHENTICATION_MODE (%d)",
1107 static int ralink_set_encr_type(struct wpa_driver_ralink_data
*drv
,
1108 NDIS_802_11_WEP_STATUS encr_type
)
1110 NDIS_802_11_WEP_STATUS wep_status
= encr_type
;
1112 wpa_printf(MSG_DEBUG
, "%s", __FUNCTION__
);
1114 if (ralink_set_oid(drv
, OID_802_11_WEP_STATUS
,
1115 (char *) &wep_status
, sizeof(wep_status
)) < 0) {
1116 wpa_printf(MSG_DEBUG
, "RALINK: Failed to set "
1117 "OID_802_11_WEP_STATUS (%d)",
1125 static int wpa_driver_ralink_remove_key(struct wpa_driver_ralink_data
*drv
,
1126 int key_idx
, const u8
*addr
,
1127 const u8
*bssid
, int pairwise
)
1129 NDIS_802_11_REMOVE_KEY rkey
;
1130 NDIS_802_11_KEY_INDEX _index
;
1133 wpa_printf(MSG_DEBUG
, "%s", __FUNCTION__
);
1135 os_memset(&rkey
, 0, sizeof(rkey
));
1137 rkey
.Length
= sizeof(rkey
);
1138 rkey
.KeyIndex
= key_idx
;
1141 rkey
.KeyIndex
|= 1 << 30;
1143 os_memcpy(rkey
.BSSID
, bssid
, ETH_ALEN
);
1145 res
= ralink_set_oid(drv
, OID_802_11_REMOVE_KEY
, (char *) &rkey
,
1148 /* AlbertY@20060210 removed it */
1149 if (0 /* !pairwise */) {
1150 res2
= ralink_set_oid(drv
, OID_802_11_REMOVE_WEP
,
1151 (char *) &_index
, sizeof(_index
));
1155 if (res
< 0 && res2
< 0)
1160 static int wpa_driver_ralink_add_wep(struct wpa_driver_ralink_data
*drv
,
1161 int pairwise
, int key_idx
, int set_tx
,
1162 const u8
*key
, size_t key_len
)
1164 NDIS_802_11_WEP
*wep
;
1168 wpa_printf(MSG_DEBUG
, "%s", __FUNCTION__
);
1171 wep
= os_zalloc(len
);
1176 wep
->KeyIndex
= key_idx
;
1179 wep
->KeyIndex
|= 0x80000000;
1181 wep
->KeyLength
= key_len
;
1182 os_memcpy(wep
->KeyMaterial
, key
, key_len
);
1184 wpa_hexdump_key(MSG_MSGDUMP
, "RALINK: OID_802_11_ADD_WEP",
1185 (const u8
*) wep
, len
);
1186 res
= ralink_set_oid(drv
, OID_802_11_ADD_WEP
, (char *) wep
, len
);
1193 static int wpa_driver_ralink_set_key(const char *ifname
, void *priv
,
1194 enum wpa_alg alg
, const u8
*addr
,
1195 int key_idx
, int set_tx
,
1196 const u8
*seq
, size_t seq_len
,
1197 const u8
*key
, size_t key_len
)
1199 struct wpa_driver_ralink_data
*drv
= priv
;
1201 NDIS_802_11_KEY
*nkey
;
1205 if (drv
->g_driver_down
== 1)
1208 wpa_printf(MSG_DEBUG
, "%s", __FUNCTION__
);
1210 drv
->bAddWepKey
= FALSE
;
1212 if (addr
== NULL
|| os_memcmp(addr
, "\xff\xff\xff\xff\xff\xff",
1216 wpa_driver_ralink_get_bssid(drv
, bssid
);
1220 os_memcpy(bssid
, addr
, ETH_ALEN
);
1223 if (alg
== WPA_ALG_NONE
|| key_len
== 0) {
1224 return wpa_driver_ralink_remove_key(drv
, key_idx
, addr
, bssid
,
1228 if (alg
== WPA_ALG_WEP
) {
1229 drv
->bAddWepKey
= TRUE
;
1230 return wpa_driver_ralink_add_wep(drv
, pairwise
, key_idx
,
1231 set_tx
, key
, key_len
);
1234 len
= 12 + 6 + 6 + 8 + key_len
;
1236 nkey
= os_zalloc(len
);
1241 nkey
->KeyIndex
= key_idx
;
1244 nkey
->KeyIndex
|= 1 << 31;
1247 nkey
->KeyIndex
|= 1 << 30;
1250 nkey
->KeyIndex
|= 1 << 29;
1252 nkey
->KeyLength
= key_len
;
1253 os_memcpy(nkey
->BSSID
, bssid
, ETH_ALEN
);
1255 if (seq
&& seq_len
) {
1256 for (i
= 0; i
< seq_len
; i
++)
1257 nkey
->KeyRSC
|= seq
[i
] << (i
* 8);
1259 if (alg
== WPA_ALG_TKIP
&& key_len
== 32) {
1260 os_memcpy(nkey
->KeyMaterial
, key
, 16);
1261 os_memcpy(nkey
->KeyMaterial
+ 16, key
+ 24, 8);
1262 os_memcpy(nkey
->KeyMaterial
+ 24, key
+ 16, 8);
1264 os_memcpy(nkey
->KeyMaterial
, key
, key_len
);
1267 wpa_printf(MSG_DEBUG
, "%s: alg=%d key_idx=%d set_tx=%d seq_len=%lu "
1268 "key_len=%lu", __FUNCTION__
, alg
, key_idx
, set_tx
,
1269 (unsigned long) seq_len
, (unsigned long) key_len
);
1271 wpa_hexdump_key(MSG_MSGDUMP
, "RALINK: OID_802_11_ADD_KEY",
1272 (const u8
*) nkey
, len
);
1273 res
= ralink_set_oid(drv
, OID_802_11_ADD_KEY
, (char *) nkey
, len
);
1279 static int wpa_driver_ralink_disassociate(void *priv
, const u8
*addr
,
1282 struct wpa_driver_ralink_data
*drv
= priv
;
1284 if (drv
->g_driver_down
== 1)
1286 wpa_printf(MSG_DEBUG
, "%s", __FUNCTION__
);
1287 if (ralink_set_oid(drv
, OID_802_11_DISASSOCIATE
, " ", 4) < 0) {
1288 wpa_printf(MSG_DEBUG
, "RALINK: Failed to set "
1289 "OID_802_11_DISASSOCIATE");
1295 static int wpa_driver_ralink_deauthenticate(void *priv
, const u8
*addr
,
1298 struct wpa_driver_ralink_data
*drv
= priv
;
1300 wpa_printf(MSG_DEBUG
, "g_driver_down = %d", drv
->g_driver_down
);
1302 if (drv
->g_driver_down
== 1)
1305 wpa_printf(MSG_DEBUG
, "%s", __FUNCTION__
);
1306 if (ralink_get_new_driver_flag(drv
) == 0) {
1307 return wpa_driver_ralink_disassociate(priv
, addr
, reason_code
);
1309 MLME_DEAUTH_REQ_STRUCT mlme
;
1310 os_memset(&mlme
, 0, sizeof(MLME_DEAUTH_REQ_STRUCT
));
1311 mlme
.Reason
= reason_code
;
1312 os_memcpy(mlme
.Addr
, addr
, MAC_ADDR_LEN
);
1313 return ralink_set_oid(drv
, OID_802_11_DEAUTHENTICATION
,
1315 sizeof(MLME_DEAUTH_REQ_STRUCT
));
1319 static int wpa_driver_ralink_set_gen_ie(void *priv
, const u8
*ie
,
1322 struct wpa_driver_ralink_data
*drv
= priv
;
1326 os_memset(&iwr
, 0, sizeof(iwr
));
1327 os_strlcpy(iwr
.ifr_name
, drv
->ifname
, IFNAMSIZ
);
1328 iwr
.u
.data
.pointer
= (caddr_t
) ie
;
1329 iwr
.u
.data
.length
= ie_len
;
1331 wpa_hexdump(MSG_DEBUG
, "wpa_driver_ralink_set_gen_ie: ",
1334 if (ioctl(drv
->ioctl_sock
, SIOCSIWGENIE
, &iwr
) < 0) {
1335 perror("ioctl[SIOCSIWGENIE]");
1343 wpa_driver_ralink_associate(void *priv
,
1344 struct wpa_driver_associate_params
*params
)
1346 struct wpa_driver_ralink_data
*drv
= priv
;
1348 NDIS_802_11_NETWORK_INFRASTRUCTURE mode
;
1349 NDIS_802_11_AUTHENTICATION_MODE auth_mode
;
1350 NDIS_802_11_WEP_STATUS encr
;
1351 BOOLEAN ieee8021xMode
;
1352 BOOLEAN ieee8021x_required_key
= TRUE
;
1354 if (drv
->g_driver_down
== 1)
1356 wpa_printf(MSG_DEBUG
, "%s", __FUNCTION__
);
1358 if (params
->mode
== IEEE80211_MODE_IBSS
)
1359 mode
= Ndis802_11IBSS
;
1361 mode
= Ndis802_11Infrastructure
;
1363 if (ralink_set_oid(drv
, OID_802_11_INFRASTRUCTURE_MODE
,
1364 (char *) &mode
, sizeof(mode
)) < 0) {
1365 wpa_printf(MSG_DEBUG
, "RALINK: Failed to set "
1366 "OID_802_11_INFRASTRUCTURE_MODE (%d)",
1368 /* Try to continue anyway */
1371 if (params
->key_mgmt_suite
== KEY_MGMT_WPS
) {
1372 UCHAR enable_wps
= 0x80;
1373 /* trigger driver support wpa_supplicant */
1374 if (ralink_set_oid(drv
, RT_OID_WPA_SUPPLICANT_SUPPORT
,
1375 (PCHAR
) &enable_wps
, sizeof(UCHAR
)) < 0) {
1376 wpa_printf(MSG_INFO
, "RALINK: Failed to set "
1377 "RT_OID_WPA_SUPPLICANT_SUPPORT (%d)",
1381 wpa_driver_ralink_set_gen_ie(priv
, params
->wpa_ie
,
1382 params
->wpa_ie_len
);
1384 ralink_set_auth_mode(drv
, Ndis802_11AuthModeOpen
);
1386 ralink_set_encr_type(drv
, Ndis802_11EncryptionDisabled
);
1389 UCHAR enable_wpa_supplicant
;
1391 if (drv
->ap_scan
== 1)
1392 enable_wpa_supplicant
= 0x01;
1394 enable_wpa_supplicant
= 0x02;
1396 /* trigger driver support wpa_supplicant */
1397 if (ralink_set_oid(drv
, RT_OID_WPA_SUPPLICANT_SUPPORT
,
1398 (PCHAR
) &enable_wpa_supplicant
,
1399 sizeof(UCHAR
)) < 0) {
1400 wpa_printf(MSG_DEBUG
, "RALINK: Failed to set "
1401 "RT_OID_WPA_SUPPLICANT_SUPPORT (%d)",
1402 (int) enable_wpa_supplicant
);
1405 wpa_driver_ralink_set_gen_ie(priv
, (u8
*) "", 0);
1406 #endif /* CONFIG_WPS */
1408 if (params
->wpa_ie
== NULL
|| params
->wpa_ie_len
== 0) {
1409 if (params
->auth_alg
& AUTH_ALG_SHARED_KEY
) {
1410 if (params
->auth_alg
& AUTH_ALG_OPEN_SYSTEM
)
1411 auth_mode
= Ndis802_11AuthModeAutoSwitch
;
1413 auth_mode
= Ndis802_11AuthModeShared
;
1415 auth_mode
= Ndis802_11AuthModeOpen
;
1416 } else if (params
->wpa_ie
[0] == WLAN_EID_RSN
) {
1417 if (params
->key_mgmt_suite
== KEY_MGMT_PSK
)
1418 auth_mode
= Ndis802_11AuthModeWPA2PSK
;
1420 auth_mode
= Ndis802_11AuthModeWPA2
;
1422 if (params
->key_mgmt_suite
== KEY_MGMT_WPA_NONE
)
1423 auth_mode
= Ndis802_11AuthModeWPANone
;
1424 else if (params
->key_mgmt_suite
== KEY_MGMT_PSK
)
1425 auth_mode
= Ndis802_11AuthModeWPAPSK
;
1427 auth_mode
= Ndis802_11AuthModeWPA
;
1430 switch (params
->pairwise_suite
) {
1432 encr
= Ndis802_11Encryption3Enabled
;
1435 encr
= Ndis802_11Encryption2Enabled
;
1439 encr
= Ndis802_11Encryption1Enabled
;
1442 if (params
->group_suite
== CIPHER_CCMP
)
1443 encr
= Ndis802_11Encryption3Enabled
;
1444 else if (params
->group_suite
== CIPHER_TKIP
)
1445 encr
= Ndis802_11Encryption2Enabled
;
1447 encr
= Ndis802_11EncryptionDisabled
;
1450 encr
= Ndis802_11EncryptionDisabled
;
1454 ralink_set_auth_mode(drv
, auth_mode
);
1456 /* notify driver that IEEE8021x mode is enabled */
1457 if (params
->key_mgmt_suite
== KEY_MGMT_802_1X_NO_WPA
) {
1458 ieee8021xMode
= TRUE
;
1459 if (drv
->bAddWepKey
)
1460 ieee8021x_required_key
= FALSE
;
1462 ieee8021xMode
= FALSE
;
1464 if (ralink_set_oid(drv
, OID_802_11_SET_IEEE8021X_REQUIRE_KEY
,
1465 (char *) &ieee8021x_required_key
,
1466 sizeof(BOOLEAN
)) < 0) {
1467 wpa_printf(MSG_DEBUG
, "ERROR: Failed to set "
1468 "OID_802_11_SET_IEEE8021X_REQUIRE_KEY(%d)",
1469 (int) ieee8021x_required_key
);
1471 wpa_printf(MSG_DEBUG
, "ieee8021x_required_key is %s",
1472 ieee8021x_required_key
? "TRUE" : "FALSE");
1475 if (ralink_set_oid(drv
, OID_802_11_SET_IEEE8021X
,
1476 (char *) &ieee8021xMode
, sizeof(BOOLEAN
)) <
1478 wpa_printf(MSG_DEBUG
, "RALINK: Failed to set "
1479 "OID_802_11_SET_IEEE8021X(%d)",
1480 (int) ieee8021xMode
);
1483 ralink_set_encr_type(drv
, encr
);
1485 if ((ieee8021xMode
== FALSE
) &&
1486 (encr
== Ndis802_11Encryption1Enabled
)) {
1489 if (ralink_set_oid(drv
, OID_802_11_DROP_UNENCRYPTED
,
1490 (char *) &enabled
, sizeof(enabled
))
1492 wpa_printf(MSG_DEBUG
, "RALINK: Failed to set "
1493 "OID_802_11_DROP_UNENCRYPTED(%d)",
1499 return wpa_driver_ralink_set_ssid(drv
, params
->ssid
, params
->ssid_len
);
1503 wpa_driver_ralink_set_countermeasures(void *priv
, int enabled
)
1505 struct wpa_driver_ralink_data
*drv
= priv
;
1506 if (drv
->g_driver_down
== 1)
1508 wpa_printf(MSG_DEBUG
, "%s: enabled=%d", __FUNCTION__
, enabled
);
1509 return ralink_set_oid(drv
, OID_SET_COUNTERMEASURES
, (char *) &enabled
,
1513 const struct wpa_driver_ops wpa_driver_ralink_ops
= {
1515 .desc
= "Ralink Wireless Client driver",
1516 .get_bssid
= wpa_driver_ralink_get_bssid
,
1517 .get_ssid
= wpa_driver_ralink_get_ssid
,
1518 .set_key
= wpa_driver_ralink_set_key
,
1519 .init
= wpa_driver_ralink_init
,
1520 .deinit
= wpa_driver_ralink_deinit
,
1521 .set_countermeasures
= wpa_driver_ralink_set_countermeasures
,
1522 .scan2
= wpa_driver_ralink_scan
,
1523 .get_scan_results2
= wpa_driver_ralink_get_scan_results
,
1524 .deauthenticate
= wpa_driver_ralink_deauthenticate
,
1525 .disassociate
= wpa_driver_ralink_disassociate
,
1526 .associate
= wpa_driver_ralink_associate
,
1527 .add_pmkid
= wpa_driver_ralink_add_pmkid
,
1528 .remove_pmkid
= wpa_driver_ralink_remove_pmkid
,
1529 .flush_pmkid
= wpa_driver_ralink_flush_pmkid
,