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 "ieee802_11_defs.h"
26 #include "priv_netlink.h"
27 #include "driver_ralink.h"
29 static void wpa_driver_ralink_scan_timeout(void *eloop_ctx
, void *timeout_ctx
);
31 #define MAX_SSID_LEN 32
33 struct wpa_driver_ralink_data
{
37 char ifname
[IFNAMSIZ
+ 1];
39 size_t assoc_req_ies_len
;
41 size_t assoc_resp_ies_len
;
43 struct ndis_pmkid_entry
*pmkid
;
44 int we_version_compiled
;
50 static int ralink_set_oid(struct wpa_driver_ralink_data
*drv
,
51 unsigned short oid
, char *data
, int len
)
59 os_memset(&iwr
, 0, sizeof(iwr
));
60 os_strlcpy(iwr
.ifr_name
, drv
->ifname
, IFNAMSIZ
);
61 iwr
.u
.data
.flags
= oid
;
62 iwr
.u
.data
.flags
|= OID_GET_SET_TOGGLE
;
65 os_memcpy(buf
, data
, len
);
67 iwr
.u
.data
.pointer
= (caddr_t
) buf
;
68 iwr
.u
.data
.length
= len
;
70 if (ioctl(drv
->ioctl_sock
, RT_PRIV_IOCTL
, &iwr
) < 0) {
71 wpa_printf(MSG_DEBUG
, "%s: oid=0x%x len (%d) failed",
81 ralink_get_new_driver_flag(struct wpa_driver_ralink_data
*drv
)
86 os_memset(&iwr
, 0, sizeof(iwr
));
87 os_strlcpy(iwr
.ifr_name
, drv
->ifname
, IFNAMSIZ
);
88 iwr
.u
.data
.pointer
= (UCHAR
*) &enabled
;
89 iwr
.u
.data
.flags
= RT_OID_NEW_DRIVER
;
91 if (ioctl(drv
->ioctl_sock
, RT_PRIV_IOCTL
, &iwr
) < 0) {
92 wpa_printf(MSG_DEBUG
, "%s: failed", __func__
);
96 return (enabled
== 1) ? 1 : 0;
99 static int wpa_driver_ralink_get_bssid(void *priv
, u8
*bssid
)
101 struct wpa_driver_ralink_data
*drv
= priv
;
105 if (drv
->g_driver_down
== 1)
108 wpa_printf(MSG_DEBUG
, "%s", __FUNCTION__
);
110 os_memset(&iwr
, 0, sizeof(iwr
));
111 os_strlcpy(iwr
.ifr_name
, drv
->ifname
, IFNAMSIZ
);
113 if (ioctl(drv
->ioctl_sock
, SIOCGIWAP
, &iwr
) < 0) {
114 perror("ioctl[SIOCGIWAP]");
117 os_memcpy(bssid
, iwr
.u
.ap_addr
.sa_data
, ETH_ALEN
);
122 static int wpa_driver_ralink_get_ssid(void *priv
, u8
*ssid
)
124 struct wpa_driver_ralink_data
*drv
= priv
;
126 struct wpa_supplicant
*wpa_s
= drv
->ctx
;
127 struct wpa_ssid
*entry
;
131 u8 ssid_str
[MAX_SSID_LEN
];
138 BOOLEAN ieee8021x_mode
= FALSE
;
139 BOOLEAN ieee8021x_required_key
= FALSE
;
142 if (drv
->g_driver_down
== 1)
145 wpa_printf(MSG_DEBUG
, "%s", __FUNCTION__
);
147 os_memset(&iwr
, 0, sizeof(iwr
));
148 os_strlcpy(iwr
.ifr_name
, drv
->ifname
, IFNAMSIZ
);
149 iwr
.u
.essid
.pointer
= (caddr_t
) ssid
;
150 iwr
.u
.essid
.length
= 32;
152 if (ioctl(drv
->ioctl_sock
, SIOCGIWESSID
, &iwr
) < 0) {
153 perror("ioctl[SIOCGIWESSID]");
156 ret
= iwr
.u
.essid
.length
;
162 os_memset(ssid_str
, 0, MAX_SSID_LEN
);
163 os_memcpy(ssid_str
, ssid
, ssid_len
);
165 if (drv
->ap_scan
== 0) {
166 /* Read BSSID form driver */
167 if (wpa_driver_ralink_get_bssid(priv
, bssid
) < 0) {
168 wpa_printf(MSG_WARNING
, "Could not read BSSID from "
174 entry
= wpa_s
->conf
->ssid
;
176 if (!entry
->disabled
&& ssid_len
== entry
->ssid_len
&&
177 os_memcmp(ssid_str
, entry
->ssid
, ssid_len
) == 0 &&
178 (!entry
->bssid_set
||
179 os_memcmp(bssid
, entry
->bssid
, ETH_ALEN
) == 0)) {
180 /* match the config of driver */
188 wpa_printf(MSG_DEBUG
, "Ready to set 802.1x mode and "
189 "ieee_required_keys parameters to driver");
191 /* set 802.1x mode and ieee_required_keys parameter */
192 if (entry
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
) {
193 if ((entry
->eapol_flags
& (EAPOL_FLAG_REQUIRE_KEY_UNICAST
| EAPOL_FLAG_REQUIRE_KEY_BROADCAST
)))
194 ieee8021x_required_key
= TRUE
;
195 ieee8021x_mode
= TRUE
;
198 if (ralink_set_oid(drv
, OID_802_11_SET_IEEE8021X
, (char *) &ieee8021x_mode
, sizeof(BOOLEAN
)) < 0)
200 wpa_printf(MSG_DEBUG
, "RALINK: Failed to set OID_802_11_SET_IEEE8021X(%d)", (int) ieee8021x_mode
);
204 wpa_printf(MSG_DEBUG
, "ieee8021x_mode is %s", ieee8021x_mode
? "TRUE" : "FALSE");
207 if (ralink_set_oid(drv
, OID_802_11_SET_IEEE8021X_REQUIRE_KEY
, (char *) &ieee8021x_required_key
, sizeof(BOOLEAN
)) < 0)
209 wpa_printf(MSG_DEBUG
, "ERROR: Failed to set OID_802_11_SET_IEEE8021X_REQUIRE_KEY(%d)", (int) ieee8021x_required_key
);
213 wpa_printf(MSG_DEBUG
, "ieee8021x_required_key is %s and eapol_flag(%d)", ieee8021x_required_key
? "TRUE" : "FALSE",
223 static int wpa_driver_ralink_set_ssid(struct wpa_driver_ralink_data
*drv
,
224 const u8
*ssid
, size_t ssid_len
)
226 NDIS_802_11_SSID
*buf
;
230 wpa_printf(MSG_DEBUG
, "%s", __FUNCTION__
);
232 buf
= os_zalloc(sizeof(NDIS_802_11_SSID
));
235 os_memset(buf
, 0, sizeof(buf
));
236 buf
->SsidLength
= ssid_len
;
237 os_memcpy(buf
->Ssid
, ssid
, ssid_len
);
238 os_memset(&iwr
, 0, sizeof(iwr
));
239 os_strlcpy(iwr
.ifr_name
, drv
->ifname
, IFNAMSIZ
);
241 iwr
.u
.data
.flags
= OID_802_11_SSID
;
242 iwr
.u
.data
.flags
|= OID_GET_SET_TOGGLE
;
243 iwr
.u
.data
.pointer
= (caddr_t
) buf
;
244 iwr
.u
.data
.length
= sizeof(NDIS_802_11_SSID
);
246 if (ioctl(drv
->ioctl_sock
, RT_PRIV_IOCTL
, &iwr
) < 0) {
247 perror("ioctl[RT_PRIV_IOCTL] -- OID_802_11_SSID");
254 static void wpa_driver_ralink_event_pmkid(struct wpa_driver_ralink_data
*drv
,
255 const u8
*data
, size_t data_len
)
257 NDIS_802_11_PMKID_CANDIDATE_LIST
*pmkid
;
259 union wpa_event_data event
;
261 wpa_printf(MSG_DEBUG
, "%s", __FUNCTION__
);
264 wpa_printf(MSG_DEBUG
, "RALINK: Too short PMKID Candidate List "
265 "Event (len=%lu)", (unsigned long) data_len
);
268 pmkid
= (NDIS_802_11_PMKID_CANDIDATE_LIST
*) data
;
269 wpa_printf(MSG_DEBUG
, "RALINK: PMKID Candidate List Event - Version %d"
271 (int) pmkid
->Version
, (int) pmkid
->NumCandidates
);
273 if (pmkid
->Version
!= 1) {
274 wpa_printf(MSG_DEBUG
, "RALINK: Unsupported PMKID Candidate "
275 "List Version %d", (int) pmkid
->Version
);
279 if (data_len
< 8 + pmkid
->NumCandidates
* sizeof(PMKID_CANDIDATE
)) {
280 wpa_printf(MSG_DEBUG
, "RALINK: PMKID Candidate List "
288 os_memset(&event
, 0, sizeof(event
));
289 for (i
= 0; i
< pmkid
->NumCandidates
; i
++) {
290 PMKID_CANDIDATE
*p
= &pmkid
->CandidateList
[i
];
291 wpa_printf(MSG_DEBUG
, "RALINK: %d: " MACSTR
" Flags 0x%x",
292 i
, MAC2STR(p
->BSSID
), (int) p
->Flags
);
293 os_memcpy(event
.pmkid_candidate
.bssid
, p
->BSSID
, ETH_ALEN
);
294 event
.pmkid_candidate
.index
= i
;
295 event
.pmkid_candidate
.preauth
=
296 p
->Flags
& NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED
;
297 wpa_supplicant_event(drv
->ctx
, EVENT_PMKID_CANDIDATE
,
302 static int wpa_driver_ralink_set_pmkid(struct wpa_driver_ralink_data
*drv
)
304 int len
, count
, i
, ret
;
305 struct ndis_pmkid_entry
*entry
;
306 NDIS_802_11_PMKID
*p
;
308 wpa_printf(MSG_DEBUG
, "%s", __FUNCTION__
);
314 if (count
>= drv
->no_of_pmkid
)
318 len
= 8 + count
* sizeof(BSSID_INFO
);
323 p
->BSSIDInfoCount
= count
;
325 for (i
= 0; i
< count
; i
++) {
326 os_memcpy(&p
->BSSIDInfo
[i
].BSSID
, entry
->bssid
, ETH_ALEN
);
327 os_memcpy(&p
->BSSIDInfo
[i
].PMKID
, entry
->pmkid
, 16);
330 wpa_hexdump(MSG_MSGDUMP
, "NDIS: OID_802_11_PMKID",
331 (const u8
*) p
, len
);
332 ret
= ralink_set_oid(drv
, OID_802_11_PMKID
, (char *) p
, len
);
337 static int wpa_driver_ralink_add_pmkid(void *priv
, const u8
*bssid
,
340 struct wpa_driver_ralink_data
*drv
= priv
;
341 struct ndis_pmkid_entry
*entry
, *prev
;
343 if (drv
->g_driver_down
== 1)
346 wpa_printf(MSG_DEBUG
, "%s", __FUNCTION__
);
348 if (drv
->no_of_pmkid
== 0)
354 if (os_memcmp(entry
->bssid
, bssid
, ETH_ALEN
) == 0)
361 /* Replace existing entry for this BSSID and move it into the
362 * beginning of the list. */
363 os_memcpy(entry
->pmkid
, pmkid
, 16);
365 prev
->next
= entry
->next
;
366 entry
->next
= drv
->pmkid
;
370 entry
= os_malloc(sizeof(*entry
));
372 os_memcpy(entry
->bssid
, bssid
, ETH_ALEN
);
373 os_memcpy(entry
->pmkid
, pmkid
, 16);
374 entry
->next
= drv
->pmkid
;
379 return wpa_driver_ralink_set_pmkid(drv
);
383 static int wpa_driver_ralink_remove_pmkid(void *priv
, const u8
*bssid
,
386 struct wpa_driver_ralink_data
*drv
= priv
;
387 struct ndis_pmkid_entry
*entry
, *prev
;
389 if (drv
->g_driver_down
== 1)
392 wpa_printf(MSG_DEBUG
, "%s", __FUNCTION__
);
394 if (drv
->no_of_pmkid
== 0)
401 if (os_memcmp(entry
->bssid
, bssid
, ETH_ALEN
) == 0 &&
402 os_memcmp(entry
->pmkid
, pmkid
, 16) == 0) {
404 prev
->next
= entry
->next
;
406 drv
->pmkid
= entry
->next
;
413 return wpa_driver_ralink_set_pmkid(drv
);
417 static int wpa_driver_ralink_flush_pmkid(void *priv
)
419 struct wpa_driver_ralink_data
*drv
= priv
;
421 struct ndis_pmkid_entry
*pmkid
, *prev
;
423 if (drv
->g_driver_down
== 1)
426 wpa_printf(MSG_DEBUG
, "%s", __FUNCTION__
);
428 if (drv
->no_of_pmkid
== 0)
439 os_memset(&p
, 0, sizeof(p
));
441 p
.BSSIDInfoCount
= 0;
442 wpa_hexdump(MSG_MSGDUMP
, "NDIS: OID_802_11_PMKID (flush)",
444 return ralink_set_oid(drv
, OID_802_11_PMKID
, (char *) &p
, 8);
448 wpa_driver_ralink_event_wireless_custom(struct wpa_driver_ralink_data
*drv
,
449 void *ctx
, char *custom
)
451 union wpa_event_data data
;
453 wpa_printf(MSG_DEBUG
, "%s", __FUNCTION__
);
455 wpa_printf(MSG_DEBUG
, "Custom wireless event: '%s'", custom
);
457 os_memset(&data
, 0, sizeof(data
));
459 if (os_strncmp(custom
, "MLME-MICHAELMICFAILURE.indication", 33) == 0) {
460 /* receive a MICFAILURE report */
461 data
.michael_mic_failure
.unicast
=
462 os_strstr(custom
, " unicast") != NULL
;
463 /* TODO: parse parameters(?) */
464 wpa_supplicant_event(ctx
, EVENT_MICHAEL_MIC_FAILURE
, &data
);
465 } else if (os_strncmp(custom
, "ASSOCINFO_ReqIEs=", 17) == 0) {
466 /* receive assoc. req. IEs */
473 * bytes = strlen(spos); ==> bug, bytes may less than original
474 * size by using this way to get size. snowpin 20070312
478 bytes
= drv
->assoc_req_ies_len
;
480 data
.assoc_info
.req_ies
= os_malloc(bytes
);
481 if (data
.assoc_info
.req_ies
== NULL
)
484 data
.assoc_info
.req_ies_len
= bytes
;
485 os_memcpy(data
.assoc_info
.req_ies
, spos
, bytes
);
487 /* skip the '\0' byte */
490 data
.assoc_info
.resp_ies
= NULL
;
491 data
.assoc_info
.resp_ies_len
= 0;
493 if (os_strncmp(spos
, " RespIEs=", 9) == 0) {
494 /* receive assoc. resp. IEs */
496 /* get IE's length */
497 bytes
= os_strlen(spos
);
502 data
.assoc_info
.resp_ies
= os_malloc(bytes
);
503 if (data
.assoc_info
.resp_ies
== NULL
)
506 data
.assoc_info
.resp_ies_len
= bytes
;
507 os_memcpy(data
.assoc_info
.resp_ies
, spos
, bytes
);
510 wpa_supplicant_event(ctx
, EVENT_ASSOCINFO
, &data
);
512 /* free allocated memory */
514 os_free(data
.assoc_info
.resp_ies
);
515 os_free(data
.assoc_info
.req_ies
);
520 wpa_driver_ralink_event_wireless(struct wpa_driver_ralink_data
*drv
,
521 void *ctx
, char *data
, int len
)
523 struct iw_event iwe_buf
, *iwe
= &iwe_buf
;
524 char *pos
, *end
, *custom
, *buf
, *assoc_info_buf
, *info_pos
;
526 BOOLEAN ieee8021x_required_key
= FALSE
;
529 wpa_printf(MSG_DEBUG
, "%s", __FUNCTION__
);
531 assoc_info_buf
= info_pos
= NULL
;
535 while (pos
+ IW_EV_LCP_LEN
<= end
) {
536 /* Event data may be unaligned, so make a local, aligned copy
537 * before processing. */
538 os_memcpy(&iwe_buf
, pos
, IW_EV_LCP_LEN
);
539 wpa_printf(MSG_DEBUG
, "Wireless event: cmd=0x%x len=%d",
541 if (iwe
->len
<= IW_EV_LCP_LEN
)
544 custom
= pos
+ IW_EV_POINT_LEN
;
546 if (drv
->we_version_compiled
> 18 && iwe
->cmd
== IWEVCUSTOM
) {
547 /* WE-19 removed the pointer from struct iw_point */
548 char *dpos
= (char *) &iwe_buf
.u
.data
.length
;
549 int dlen
= dpos
- (char *) &iwe_buf
;
550 os_memcpy(dpos
, pos
+ IW_EV_LCP_LEN
,
551 sizeof(struct iw_event
) - dlen
);
553 os_memcpy(&iwe_buf
, pos
, sizeof(struct iw_event
));
554 custom
+= IW_EV_POINT_OFF
;
559 if (custom
+ iwe
->u
.data
.length
> end
)
561 buf
= os_malloc(iwe
->u
.data
.length
+ 1);
564 os_memcpy(buf
, custom
, iwe
->u
.data
.length
);
565 buf
[iwe
->u
.data
.length
] = '\0';
567 if (drv
->ap_scan
== 1) {
568 if ((iwe
->u
.data
.flags
== RT_ASSOC_EVENT_FLAG
)
569 || (iwe
->u
.data
.flags
==
570 RT_REQIE_EVENT_FLAG
) ||
571 (iwe
->u
.data
.flags
== RT_RESPIE_EVENT_FLAG
)
572 || (iwe
->u
.data
.flags
==
573 RT_ASSOCINFO_EVENT_FLAG
)) {
574 if (drv
->scanning_done
== 0) {
581 if (iwe
->u
.data
.flags
== RT_ASSOC_EVENT_FLAG
) {
582 wpa_printf(MSG_DEBUG
, "Custom wireless event: "
583 "receive ASSOCIATED_EVENT !!!");
584 /* determine whether the dynamic-WEP is used or
587 if (wpa_s
&& wpa_s
->current_ssid
&&
588 wpa_s
->current_ssid
->key_mgmt
==
589 WPA_KEY_MGMT_IEEE8021X_NO_WPA
) {
590 if ((wpa_s
->current_ssid
->eapol_flags
&
591 (EAPOL_FLAG_REQUIRE_KEY_UNICAST
| EAPOL_FLAG_REQUIRE_KEY_BROADCAST
))) {
592 //wpa_printf(MSG_DEBUG, "The current ssid - (%s), eapol_flag = %d.\n",
593 // wpa_ssid_txt(wpa_s->current_ssid->ssid, wpa_s->current_ssid->ssid_len),wpa_s->current_ssid->eapol_flags);
594 ieee8021x_required_key
= TRUE
;
597 if (ralink_set_oid(drv
, OID_802_11_SET_IEEE8021X_REQUIRE_KEY
, (char *) &ieee8021x_required_key
, sizeof(BOOLEAN
)) < 0)
599 wpa_printf(MSG_DEBUG
, "ERROR: Failed to set OID_802_11_SET_IEEE8021X_REQUIRE_KEY(%d)",
600 (int) ieee8021x_required_key
);
603 wpa_printf(MSG_DEBUG
, "ieee8021x_required_key is %s and eapol_flag(%d).\n", ieee8021x_required_key
? "TRUE" : "FALSE",
604 wpa_s
->current_ssid
->eapol_flags
);
608 wpa_supplicant_event(ctx
, EVENT_ASSOC
, NULL
);
609 } else if (iwe
->u
.data
.flags
== RT_REQIE_EVENT_FLAG
) {
610 wpa_printf(MSG_DEBUG
, "Custom wireless event: "
611 "receive ReqIEs !!!");
613 os_malloc(iwe
->u
.data
.length
);
614 if (drv
->assoc_req_ies
== NULL
) {
619 drv
->assoc_req_ies_len
= iwe
->u
.data
.length
;
620 os_memcpy(drv
->assoc_req_ies
, custom
,
622 } else if (iwe
->u
.data
.flags
== RT_RESPIE_EVENT_FLAG
) {
623 wpa_printf(MSG_DEBUG
, "Custom wireless event: "
624 "receive RespIEs !!!");
625 drv
->assoc_resp_ies
=
626 os_malloc(iwe
->u
.data
.length
);
627 if (drv
->assoc_resp_ies
== NULL
) {
628 os_free(drv
->assoc_req_ies
);
629 drv
->assoc_req_ies
= NULL
;
634 drv
->assoc_resp_ies_len
= iwe
->u
.data
.length
;
635 os_memcpy(drv
->assoc_resp_ies
, custom
,
637 } else if (iwe
->u
.data
.flags
==
638 RT_ASSOCINFO_EVENT_FLAG
) {
639 wpa_printf(MSG_DEBUG
, "Custom wireless event: "
640 "receive ASSOCINFO_EVENT !!!");
643 os_zalloc(drv
->assoc_req_ies_len
+
644 drv
->assoc_resp_ies_len
+ 1);
646 if (assoc_info_buf
== NULL
) {
647 os_free(drv
->assoc_req_ies
);
648 drv
->assoc_req_ies
= NULL
;
649 os_free(drv
->assoc_resp_ies
);
650 drv
->assoc_resp_ies
= NULL
;
655 if (drv
->assoc_req_ies
) {
656 os_memcpy(assoc_info_buf
,
658 drv
->assoc_req_ies_len
);
660 info_pos
= assoc_info_buf
+
661 drv
->assoc_req_ies_len
;
662 if (drv
->assoc_resp_ies
) {
665 drv
->assoc_resp_ies_len
);
667 assoc_info_buf
[drv
->assoc_req_ies_len
+
668 drv
->assoc_resp_ies_len
] = '\0';
669 wpa_driver_ralink_event_wireless_custom(
670 drv
, ctx
, assoc_info_buf
);
671 os_free(drv
->assoc_req_ies
);
672 drv
->assoc_req_ies
= NULL
;
673 os_free(drv
->assoc_resp_ies
);
674 drv
->assoc_resp_ies
= NULL
;
675 os_free(assoc_info_buf
);
676 } else if (iwe
->u
.data
.flags
== RT_DISASSOC_EVENT_FLAG
)
678 wpa_printf(MSG_DEBUG
, "Custom wireless event: "
679 "receive DISASSOCIATED_EVENT !!!");
680 wpa_supplicant_event(ctx
, EVENT_DISASSOC
,
682 } else if (iwe
->u
.data
.flags
== RT_PMKIDCAND_FLAG
) {
683 wpa_printf(MSG_DEBUG
, "Custom wireless event: "
684 "receive PMKIDCAND_EVENT !!!");
685 wpa_driver_ralink_event_pmkid(
686 drv
, (const u8
*) custom
,
688 } else if (iwe
->u
.data
.flags
== RT_INTERFACE_DOWN
) {
689 drv
->g_driver_down
= 1;
691 } else if (iwe
->u
.data
.flags
== RT_REPORT_AP_INFO
) {
692 if (drv
->ap_scan
!= 1) {
693 typedef struct PACKED
{
694 UCHAR bssid
[MAC_ADDR_LEN
];
695 UCHAR ssid
[MAX_LEN_OF_SSID
];
705 wpa_printf(MSG_DEBUG
, "Custom wireless"
707 "RT_REPORT_AP_INFO !!!");
708 //printf("iwe->u.data.length = %d\n", iwe->u.data.length);
709 //wpa_hexdump(MSG_DEBUG, "AP_Info: ", buf, iwe->u.data.length);
711 wpa_s
->num_scan_results
= 1;
712 if (wpa_s
->scan_results
)
713 os_free(wpa_s
->scan_results
);
714 wpa_s
->scan_results
= os_malloc(sizeof(struct wpa_scan_result
) + 1);
715 if (wpa_s
->scan_results
) {
716 PAPINFO pApInfo
= (PAPINFO
)buf
;
717 os_memcpy(wpa_s
->scan_results
[0].bssid
, pApInfo
->bssid
, ETH_ALEN
);
718 os_memcpy(wpa_s
->scan_results
[0].ssid
, pApInfo
->ssid
, pApInfo
->ssid_len
);
719 wpa_s
->scan_results
[0].ssid_len
= pApInfo
->ssid_len
;
720 if (pApInfo
->wpa_ie_len
> 0) {
721 os_memcpy(wpa_s
->scan_results
[0].wpa_ie
, pApInfo
->wpa_ie
, pApInfo
->wpa_ie_len
);
722 wpa_s
->scan_results
[0].wpa_ie_len
= pApInfo
->wpa_ie_len
;
723 } else if (pApInfo
->rsn_ie_len
> 0) {
724 os_memcpy(wpa_s
->scan_results
[0].rsn_ie
, pApInfo
->rsn_ie
, pApInfo
->rsn_ie_len
);
725 wpa_s
->scan_results
[0].rsn_ie_len
= pApInfo
->rsn_ie_len
;
727 wpa_s
->scan_results
[0].caps
= pApInfo
->caps
;
728 wpa_s
->scan_results
[0].freq
= pApInfo
->freq
;
730 wpa_printf("wpa_s->scan_"
737 wpa_driver_ralink_event_wireless_custom(
749 wpa_driver_ralink_event_rtm_newlink(struct wpa_driver_ralink_data
*drv
,
750 void *ctx
, struct nlmsghdr
*h
, int len
)
752 struct ifinfomsg
*ifi
;
753 int attrlen
, nlmsg_len
, rta_len
;
754 struct rtattr
* attr
;
756 wpa_printf(MSG_DEBUG
, "%s", __FUNCTION__
);
758 if (len
< (int) sizeof(*ifi
))
762 wpa_hexdump(MSG_DEBUG
, "ifi: ", (u8
*) ifi
, sizeof(struct ifinfomsg
));
764 nlmsg_len
= NLMSG_ALIGN(sizeof(struct ifinfomsg
));
766 attrlen
= h
->nlmsg_len
- nlmsg_len
;
767 wpa_printf(MSG_DEBUG
, "attrlen=%d", attrlen
);
771 attr
= (struct rtattr
*) (((char *) ifi
) + nlmsg_len
);
772 wpa_hexdump(MSG_DEBUG
, "attr1: ", (u8
*) attr
, sizeof(struct rtattr
));
773 rta_len
= RTA_ALIGN(sizeof(struct rtattr
));
774 wpa_hexdump(MSG_DEBUG
, "attr2: ", (u8
*)attr
,rta_len
);
775 while (RTA_OK(attr
, attrlen
)) {
776 wpa_printf(MSG_DEBUG
, "rta_type=%02x\n", attr
->rta_type
);
777 if (attr
->rta_type
== IFLA_WIRELESS
) {
778 wpa_driver_ralink_event_wireless(
780 ((char *) attr
) + rta_len
,
781 attr
->rta_len
- rta_len
);
783 attr
= RTA_NEXT(attr
, attrlen
);
784 wpa_hexdump(MSG_DEBUG
, "attr3: ",
785 (u8
*) attr
, sizeof(struct rtattr
));
789 static void wpa_driver_ralink_event_receive(int sock
, void *ctx
,
794 struct sockaddr_nl from
;
798 wpa_printf(MSG_DEBUG
, "%s", __FUNCTION__
);
800 fromlen
= sizeof(from
);
801 left
= recvfrom(sock
, buf
, sizeof(buf
), MSG_DONTWAIT
,
802 (struct sockaddr
*) &from
, &fromlen
);
805 if (errno
!= EINTR
&& errno
!= EAGAIN
)
806 perror("recvfrom(netlink)");
810 h
= (struct nlmsghdr
*) buf
;
811 wpa_hexdump(MSG_DEBUG
, "h: ", (u8
*)h
, h
->nlmsg_len
);
813 while (left
>= (int) sizeof(*h
)) {
817 plen
= len
- sizeof(*h
);
818 if (len
> left
|| plen
< 0) {
819 wpa_printf(MSG_DEBUG
, "Malformed netlink message: "
820 "len=%d left=%d plen=%d", len
, left
, plen
);
824 switch (h
->nlmsg_type
) {
826 wpa_driver_ralink_event_rtm_newlink(ctx
, sock_ctx
, h
,
831 len
= NLMSG_ALIGN(len
);
833 h
= (struct nlmsghdr
*) ((char *) h
+ len
);
837 wpa_printf(MSG_DEBUG
, "%d extra bytes in the end of netlink "
844 ralink_get_we_version_compiled(struct wpa_driver_ralink_data
*drv
)
847 UINT we_version_compiled
= 0;
849 os_memset(&iwr
, 0, sizeof(iwr
));
850 os_strlcpy(iwr
.ifr_name
, drv
->ifname
, IFNAMSIZ
);
851 iwr
.u
.data
.pointer
= (caddr_t
) &we_version_compiled
;
852 iwr
.u
.data
.flags
= RT_OID_WE_VERSION_COMPILED
;
854 if (ioctl(drv
->ioctl_sock
, RT_PRIV_IOCTL
, &iwr
) < 0) {
855 wpa_printf(MSG_DEBUG
, "%s: failed", __func__
);
859 drv
->we_version_compiled
= we_version_compiled
;
865 ralink_set_iface_flags(void *priv
, int dev_up
)
867 struct wpa_driver_ralink_data
*drv
= priv
;
870 wpa_printf(MSG_DEBUG
, "%s", __FUNCTION__
);
872 if (drv
->ioctl_sock
< 0)
875 os_memset(&ifr
, 0, sizeof(ifr
));
876 os_snprintf(ifr
.ifr_name
, IFNAMSIZ
, "%s", drv
->ifname
);
878 if (ioctl(drv
->ioctl_sock
, SIOCGIFFLAGS
, &ifr
) != 0) {
879 perror("ioctl[SIOCGIFFLAGS]");
884 ifr
.ifr_flags
|= IFF_UP
;
886 ifr
.ifr_flags
&= ~IFF_UP
;
888 if (ioctl(drv
->ioctl_sock
, SIOCSIFFLAGS
, &ifr
) != 0) {
889 perror("ioctl[SIOCSIFFLAGS]");
896 static void * wpa_driver_ralink_init(void *ctx
, const char *ifname
)
899 struct wpa_driver_ralink_data
*drv
;
901 struct sockaddr_nl local
;
902 UCHAR enable_wpa_supplicant
= 0;
904 wpa_printf(MSG_DEBUG
, "%s", __FUNCTION__
);
906 /* open socket to kernel */
907 if ((s
= socket(AF_INET
, SOCK_DGRAM
, 0)) < 0) {
912 os_strlcpy(ifr
.ifr_name
, ifname
, IFNAMSIZ
);
914 if (ioctl(s
, SIOCGIFINDEX
, &ifr
) < 0) {
915 perror(ifr
.ifr_name
);
919 drv
= os_zalloc(sizeof(*drv
));
923 drv
->scanning_done
= 1;
924 drv
->ap_scan
= 1; /* for now - let's assume ap_scan=1 is used */
926 os_strlcpy(drv
->ifname
, ifname
, sizeof(drv
->ifname
));
928 drv
->g_driver_down
= 0;
930 s
= socket(PF_NETLINK
, SOCK_RAW
, NETLINK_ROUTE
);
932 perror("socket(PF_NETLINK,SOCK_RAW,NETLINK_ROUTE)");
933 close(drv
->ioctl_sock
);
938 os_memset(&local
, 0, sizeof(local
));
939 local
.nl_family
= AF_NETLINK
;
940 local
.nl_groups
= RTMGRP_LINK
;
942 if (bind(s
, (struct sockaddr
*) &local
, sizeof(local
)) < 0) {
943 perror("bind(netlink)");
945 close(drv
->ioctl_sock
);
950 eloop_register_read_sock(s
, wpa_driver_ralink_event_receive
, drv
, ctx
);
952 drv
->no_of_pmkid
= 4; /* Number of PMKID saved supported */
954 ralink_set_iface_flags(drv
, 1); /* mark up during setup */
955 ralink_get_we_version_compiled(drv
);
956 wpa_driver_ralink_flush_pmkid(drv
);
958 if (drv
->ap_scan
== 1)
959 enable_wpa_supplicant
= 1;
961 enable_wpa_supplicant
= 2;
962 /* trigger driver support wpa_supplicant */
963 if (ralink_set_oid(drv
, RT_OID_WPA_SUPPLICANT_SUPPORT
,
964 (PCHAR
) &enable_wpa_supplicant
, sizeof(UCHAR
)) < 0)
966 wpa_printf(MSG_DEBUG
, "RALINK: Failed to set "
967 "RT_OID_WPA_SUPPLICANT_SUPPORT(%d)",
968 (int) enable_wpa_supplicant
);
969 wpa_printf(MSG_ERROR
, "RALINK: Driver does not support "
972 close(drv
->ioctl_sock
);
977 if (drv
->ap_scan
== 1)
978 drv
->scanning_done
= 0;
983 static void wpa_driver_ralink_deinit(void *priv
)
985 struct wpa_driver_ralink_data
*drv
= priv
;
986 UCHAR enable_wpa_supplicant
;
988 wpa_printf(MSG_DEBUG
, "%s", __FUNCTION__
);
990 enable_wpa_supplicant
= 0;
992 if (drv
->g_driver_down
== 0) {
993 /* trigger driver disable wpa_supplicant support */
994 if (ralink_set_oid(drv
, RT_OID_WPA_SUPPLICANT_SUPPORT
,
995 (char *) &enable_wpa_supplicant
,
996 sizeof(BOOLEAN
)) < 0) {
997 wpa_printf(MSG_DEBUG
, "RALINK: Failed to set "
998 "RT_OID_WPA_SUPPLICANT_SUPPORT(%d)",
999 (int) enable_wpa_supplicant
);
1002 wpa_driver_ralink_flush_pmkid(drv
);
1005 ralink_set_iface_flags(drv
, 0);
1008 eloop_cancel_timeout(wpa_driver_ralink_scan_timeout
, drv
, drv
->ctx
);
1009 eloop_unregister_read_sock(drv
->event_sock
);
1010 close(drv
->event_sock
);
1011 close(drv
->ioctl_sock
);
1015 static void wpa_driver_ralink_scan_timeout(void *eloop_ctx
, void *timeout_ctx
)
1017 struct wpa_driver_ralink_data
*drv
= eloop_ctx
;
1019 wpa_printf(MSG_DEBUG
, "%s", __FUNCTION__
);
1021 wpa_printf(MSG_DEBUG
, "Scan timeout - try to get results");
1022 wpa_supplicant_event(timeout_ctx
, EVENT_SCAN_RESULTS
, NULL
);
1024 drv
->scanning_done
= 1;
1028 static int wpa_driver_ralink_scan(void *priv
, const u8
*ssid
, size_t ssid_len
)
1030 struct wpa_driver_ralink_data
*drv
= priv
;
1034 if (drv
->g_driver_down
== 1)
1037 wpa_printf(MSG_DEBUG
, "%s", __FUNCTION__
);
1039 if (ssid_len
> IW_ESSID_MAX_SIZE
) {
1040 wpa_printf(MSG_DEBUG
, "%s: too long SSID (%lu)",
1041 __FUNCTION__
, (unsigned long) ssid_len
);
1045 /* wpa_driver_ralink_set_ssid(drv, ssid, ssid_len); */
1047 os_memset(&iwr
, 0, sizeof(iwr
));
1048 os_strlcpy(iwr
.ifr_name
, drv
->ifname
, IFNAMSIZ
);
1050 if (ioctl(drv
->ioctl_sock
, SIOCSIWSCAN
, &iwr
) < 0) {
1051 perror("ioctl[SIOCSIWSCAN]");
1055 /* Not all drivers generate "scan completed" wireless event, so try to
1056 * read results after a timeout. */
1057 eloop_cancel_timeout(wpa_driver_ralink_scan_timeout
, drv
, drv
->ctx
);
1058 eloop_register_timeout(4, 0, wpa_driver_ralink_scan_timeout
, drv
,
1061 drv
->scanning_done
= 0;
1067 wpa_driver_ralink_get_scan_results(void *priv
,
1068 struct wpa_scan_result
*results
,
1071 struct wpa_driver_ralink_data
*drv
= priv
;
1073 NDIS_802_11_BSSID_LIST_EX
*wsr
;
1074 NDIS_WLAN_BSSID_EX
*wbi
;
1080 if (drv
->g_driver_down
== 1)
1082 wpa_printf(MSG_DEBUG
, "%s", __FUNCTION__
);
1084 if (drv
->we_version_compiled
>= 17) {
1085 buf
= os_zalloc(8192);
1086 iwr
.u
.data
.length
= 8192;
1088 buf
= os_zalloc(4096);
1089 iwr
.u
.data
.length
= 4096;
1094 wsr
= (NDIS_802_11_BSSID_LIST_EX
*) buf
;
1096 wsr
->NumberOfItems
= 0;
1097 os_strlcpy(iwr
.ifr_name
, drv
->ifname
, IFNAMSIZ
);
1098 iwr
.u
.data
.pointer
= (void *) buf
;
1099 iwr
.u
.data
.flags
= OID_802_11_BSSID_LIST
;
1101 if ((rv
= ioctl(drv
->ioctl_sock
, RT_PRIV_IOCTL
, &iwr
)) < 0) {
1102 wpa_printf(MSG_DEBUG
, "ioctl fail: rv = %d", rv
);
1107 os_memset(results
, 0, max_size
* sizeof(struct wpa_scan_result
));
1109 for (ap_num
= 0, wbi
= wsr
->Bssid
; ap_num
< wsr
->NumberOfItems
;
1111 os_memcpy(results
[ap_num
].bssid
, &wbi
->MacAddress
, ETH_ALEN
);
1112 os_memcpy(results
[ap_num
].ssid
, wbi
->Ssid
.Ssid
,
1113 wbi
->Ssid
.SsidLength
);
1114 results
[ap_num
].ssid_len
= wbi
->Ssid
.SsidLength
;
1115 results
[ap_num
].freq
= (wbi
->Configuration
.DSConfig
/ 1000);
1118 wpa_hexdump(MSG_DEBUG
, "RALINK: AP IEs",
1119 (u8
*) wbi
+ sizeof(*wbi
) - 1, wbi
->IELength
);
1121 pos
= (u8
*) wbi
+ sizeof(*wbi
) - 1;
1122 end
= (u8
*) wbi
+ sizeof(*wbi
) + wbi
->IELength
;
1124 if (wbi
->IELength
< sizeof(NDIS_802_11_FIXED_IEs
))
1127 pos
+= sizeof(NDIS_802_11_FIXED_IEs
) - 2;
1128 os_memcpy(&results
[ap_num
].caps
, pos
, 2);
1131 while (pos
+ 1 < end
&& pos
+ 2 + pos
[1] <= end
) {
1132 u8 ielen
= 2 + pos
[1];
1134 if (ielen
> SSID_MAX_WPA_IE_LEN
) {
1139 if (pos
[0] == WLAN_EID_VENDOR_SPECIFIC
&&
1141 os_memcmp(pos
+ 2, "\x00\x50\xf2\x01", 4) == 0) {
1142 os_memcpy(results
[ap_num
].wpa_ie
, pos
, ielen
);
1143 results
[ap_num
].wpa_ie_len
= ielen
;
1144 } else if (pos
[0] == WLAN_EID_RSN
) {
1145 os_memcpy(results
[ap_num
].rsn_ie
, pos
, ielen
);
1146 results
[ap_num
].rsn_ie_len
= ielen
;
1151 wbi
= (NDIS_WLAN_BSSID_EX
*) ((u8
*) wbi
+ wbi
->Length
);
1158 static int ralink_set_auth_mode(struct wpa_driver_ralink_data
*drv
,
1159 NDIS_802_11_AUTHENTICATION_MODE mode
)
1161 NDIS_802_11_AUTHENTICATION_MODE auth_mode
= mode
;
1163 wpa_printf(MSG_DEBUG
, "%s", __FUNCTION__
);
1165 if (ralink_set_oid(drv
, OID_802_11_AUTHENTICATION_MODE
,
1166 (char *) &auth_mode
, sizeof(auth_mode
)) < 0) {
1167 wpa_printf(MSG_DEBUG
, "RALINK: Failed to set "
1168 "OID_802_11_AUTHENTICATION_MODE (%d)",
1175 static int wpa_driver_ralink_remove_key(struct wpa_driver_ralink_data
*drv
,
1176 int key_idx
, const u8
*addr
,
1177 const u8
*bssid
, int pairwise
)
1179 NDIS_802_11_REMOVE_KEY rkey
;
1180 NDIS_802_11_KEY_INDEX _index
;
1183 wpa_printf(MSG_DEBUG
, "%s", __FUNCTION__
);
1185 os_memset(&rkey
, 0, sizeof(rkey
));
1187 rkey
.Length
= sizeof(rkey
);
1188 rkey
.KeyIndex
= key_idx
;
1191 rkey
.KeyIndex
|= 1 << 30;
1193 os_memcpy(rkey
.BSSID
, bssid
, ETH_ALEN
);
1195 res
= ralink_set_oid(drv
, OID_802_11_REMOVE_KEY
, (char *) &rkey
,
1198 /* AlbertY@20060210 removed it */
1199 if (0 /* !pairwise */) {
1200 res2
= ralink_set_oid(drv
, OID_802_11_REMOVE_WEP
,
1201 (char *) &_index
, sizeof(_index
));
1205 if (res
< 0 && res2
< 0)
1210 static int wpa_driver_ralink_add_wep(struct wpa_driver_ralink_data
*drv
,
1211 int pairwise
, int key_idx
, int set_tx
,
1212 const u8
*key
, size_t key_len
)
1214 NDIS_802_11_WEP
*wep
;
1218 wpa_printf(MSG_DEBUG
, "%s", __FUNCTION__
);
1221 wep
= os_zalloc(len
);
1226 wep
->KeyIndex
= key_idx
;
1229 wep
->KeyIndex
|= 0x80000000;
1231 wep
->KeyLength
= key_len
;
1232 os_memcpy(wep
->KeyMaterial
, key
, key_len
);
1234 wpa_hexdump_key(MSG_MSGDUMP
, "RALINK: OID_802_11_ADD_WEP",
1235 (const u8
*) wep
, len
);
1236 res
= ralink_set_oid(drv
, OID_802_11_ADD_WEP
, (char *) wep
, len
);
1243 static int wpa_driver_ralink_set_key(void *priv
, wpa_alg alg
, const u8
*addr
,
1244 int key_idx
, int set_tx
,
1245 const u8
*seq
, size_t seq_len
,
1246 const u8
*key
, size_t key_len
)
1248 struct wpa_driver_ralink_data
*drv
= priv
;
1250 NDIS_802_11_KEY
*nkey
;
1254 if (drv
->g_driver_down
== 1)
1257 wpa_printf(MSG_DEBUG
, "%s", __FUNCTION__
);
1259 if (addr
== NULL
|| os_memcmp(addr
, "\xff\xff\xff\xff\xff\xff",
1263 wpa_driver_ralink_get_bssid(drv
, bssid
);
1267 os_memcpy(bssid
, addr
, ETH_ALEN
);
1270 if (alg
== WPA_ALG_NONE
|| key_len
== 0) {
1271 return wpa_driver_ralink_remove_key(drv
, key_idx
, addr
, bssid
,
1275 if (alg
== WPA_ALG_WEP
) {
1276 return wpa_driver_ralink_add_wep(drv
, pairwise
, key_idx
,
1277 set_tx
, key
, key_len
);
1280 len
= 12 + 6 + 6 + 8 + key_len
;
1282 nkey
= os_zalloc(len
);
1287 nkey
->KeyIndex
= key_idx
;
1290 nkey
->KeyIndex
|= 1 << 31;
1293 nkey
->KeyIndex
|= 1 << 30;
1296 nkey
->KeyIndex
|= 1 << 29;
1298 nkey
->KeyLength
= key_len
;
1299 os_memcpy(nkey
->BSSID
, bssid
, ETH_ALEN
);
1301 if (seq
&& seq_len
) {
1302 for (i
= 0; i
< seq_len
; i
++)
1303 nkey
->KeyRSC
|= seq
[i
] << (i
* 8);
1305 if (alg
== WPA_ALG_TKIP
&& key_len
== 32) {
1306 os_memcpy(nkey
->KeyMaterial
, key
, 16);
1307 os_memcpy(nkey
->KeyMaterial
+ 16, key
+ 24, 8);
1308 os_memcpy(nkey
->KeyMaterial
+ 24, key
+ 16, 8);
1310 os_memcpy(nkey
->KeyMaterial
, key
, key_len
);
1313 wpa_printf(MSG_DEBUG
, "%s: alg=%d key_idx=%d set_tx=%d seq_len=%lu "
1314 "key_len=%lu", __FUNCTION__
, alg
, key_idx
, set_tx
,
1315 (unsigned long) seq_len
, (unsigned long) key_len
);
1317 wpa_hexdump_key(MSG_MSGDUMP
, "RALINK: OID_802_11_ADD_KEY",
1318 (const u8
*) nkey
, len
);
1319 res
= ralink_set_oid(drv
, OID_802_11_ADD_KEY
, (char *) nkey
, len
);
1325 static int wpa_driver_ralink_disassociate(void *priv
, const u8
*addr
,
1328 struct wpa_driver_ralink_data
*drv
= priv
;
1330 if (drv
->g_driver_down
== 1)
1332 wpa_printf(MSG_DEBUG
, "%s", __FUNCTION__
);
1333 if (ralink_set_oid(drv
, OID_802_11_DISASSOCIATE
, " ", 4) < 0) {
1334 wpa_printf(MSG_DEBUG
, "RALINK: Failed to set "
1335 "OID_802_11_DISASSOCIATE");
1341 static int wpa_driver_ralink_deauthenticate(void *priv
, const u8
*addr
,
1344 struct wpa_driver_ralink_data
*drv
= priv
;
1346 wpa_printf(MSG_DEBUG
, "g_driver_down = %d", drv
->g_driver_down
);
1348 if (drv
->g_driver_down
== 1)
1351 wpa_printf(MSG_DEBUG
, "%s", __FUNCTION__
);
1352 if (ralink_get_new_driver_flag(drv
) == 0) {
1353 return wpa_driver_ralink_disassociate(priv
, addr
, reason_code
);
1355 MLME_DEAUTH_REQ_STRUCT mlme
;
1356 os_memset(&mlme
, 0, sizeof(MLME_DEAUTH_REQ_STRUCT
));
1357 mlme
.Reason
= reason_code
;
1358 os_memcpy(mlme
.Addr
, addr
, MAC_ADDR_LEN
);
1359 return ralink_set_oid(drv
, OID_802_11_DEAUTHENTICATION
,
1361 sizeof(MLME_DEAUTH_REQ_STRUCT
));
1366 wpa_driver_ralink_associate(void *priv
,
1367 struct wpa_driver_associate_params
*params
)
1369 struct wpa_driver_ralink_data
*drv
= priv
;
1371 NDIS_802_11_NETWORK_INFRASTRUCTURE mode
;
1372 NDIS_802_11_AUTHENTICATION_MODE auth_mode
;
1373 NDIS_802_11_WEP_STATUS encr
;
1374 BOOLEAN ieee8021xMode
;
1376 if (drv
->g_driver_down
== 1)
1378 wpa_printf(MSG_DEBUG
, "%s", __FUNCTION__
);
1380 if (params
->mode
== IEEE80211_MODE_IBSS
)
1381 mode
= Ndis802_11IBSS
;
1383 mode
= Ndis802_11Infrastructure
;
1385 if (ralink_set_oid(drv
, OID_802_11_INFRASTRUCTURE_MODE
,
1386 (char *) &mode
, sizeof(mode
)) < 0) {
1387 wpa_printf(MSG_DEBUG
, "RALINK: Failed to set "
1388 "OID_802_11_INFRASTRUCTURE_MODE (%d)",
1390 /* Try to continue anyway */
1393 if (params
->wpa_ie
== NULL
|| params
->wpa_ie_len
== 0) {
1394 if (params
->auth_alg
& AUTH_ALG_SHARED_KEY
) {
1395 if (params
->auth_alg
& AUTH_ALG_OPEN_SYSTEM
)
1396 auth_mode
= Ndis802_11AuthModeAutoSwitch
;
1398 auth_mode
= Ndis802_11AuthModeShared
;
1400 auth_mode
= Ndis802_11AuthModeOpen
;
1401 } else if (params
->wpa_ie
[0] == WLAN_EID_RSN
) {
1402 if (params
->key_mgmt_suite
== KEY_MGMT_PSK
)
1403 auth_mode
= Ndis802_11AuthModeWPA2PSK
;
1405 auth_mode
= Ndis802_11AuthModeWPA2
;
1407 if (params
->key_mgmt_suite
== KEY_MGMT_WPA_NONE
)
1408 auth_mode
= Ndis802_11AuthModeWPANone
;
1409 else if (params
->key_mgmt_suite
== KEY_MGMT_PSK
)
1410 auth_mode
= Ndis802_11AuthModeWPAPSK
;
1412 auth_mode
= Ndis802_11AuthModeWPA
;
1415 switch (params
->pairwise_suite
) {
1417 encr
= Ndis802_11Encryption3Enabled
;
1420 encr
= Ndis802_11Encryption2Enabled
;
1424 encr
= Ndis802_11Encryption1Enabled
;
1427 if (params
->group_suite
== CIPHER_CCMP
)
1428 encr
= Ndis802_11Encryption3Enabled
;
1429 else if (params
->group_suite
== CIPHER_TKIP
)
1430 encr
= Ndis802_11Encryption2Enabled
;
1432 encr
= Ndis802_11EncryptionDisabled
;
1435 encr
= Ndis802_11EncryptionDisabled
;
1439 ralink_set_auth_mode(drv
, auth_mode
);
1441 /* notify driver that IEEE8021x mode is enabled */
1442 if (params
->key_mgmt_suite
== KEY_MGMT_802_1X_NO_WPA
)
1443 ieee8021xMode
= TRUE
;
1445 ieee8021xMode
= FALSE
;
1447 if (ralink_set_oid(drv
, OID_802_11_SET_IEEE8021X
,
1448 (char *) &ieee8021xMode
, sizeof(BOOLEAN
)) < 0) {
1449 wpa_printf(MSG_DEBUG
, "RALINK: Failed to set "
1450 "OID_802_11_SET_IEEE8021X(%d)",
1451 (int) ieee8021xMode
);
1454 if (ralink_set_oid(drv
, OID_802_11_WEP_STATUS
,
1455 (char *) &encr
, sizeof(encr
)) < 0) {
1456 wpa_printf(MSG_DEBUG
, "RALINK: Failed to set "
1457 "OID_802_11_WEP_STATUS(%d)",
1461 if ((ieee8021xMode
== FALSE
) &&
1462 (encr
== Ndis802_11Encryption1Enabled
)) {
1465 if (ralink_set_oid(drv
, OID_802_11_DROP_UNENCRYPTED
,
1466 (char *) &enabled
, sizeof(enabled
)) < 0) {
1467 wpa_printf(MSG_DEBUG
, "RALINK: Failed to set "
1468 "OID_802_11_DROP_UNENCRYPTED(%d)",
1473 return wpa_driver_ralink_set_ssid(drv
, params
->ssid
, params
->ssid_len
);
1477 wpa_driver_ralink_set_countermeasures(void *priv
, int enabled
)
1479 struct wpa_driver_ralink_data
*drv
= priv
;
1480 if (drv
->g_driver_down
== 1)
1482 wpa_printf(MSG_DEBUG
, "%s: enabled=%d", __FUNCTION__
, enabled
);
1483 return ralink_set_oid(drv
, OID_SET_COUNTERMEASURES
, (char *) &enabled
,
1487 const struct wpa_driver_ops wpa_driver_ralink_ops
= {
1489 .desc
= "Ralink Wireless Client driver",
1490 .get_bssid
= wpa_driver_ralink_get_bssid
,
1491 .get_ssid
= wpa_driver_ralink_get_ssid
,
1492 .set_key
= wpa_driver_ralink_set_key
,
1493 .init
= wpa_driver_ralink_init
,
1494 .deinit
= wpa_driver_ralink_deinit
,
1495 .set_countermeasures
= wpa_driver_ralink_set_countermeasures
,
1496 .scan
= wpa_driver_ralink_scan
,
1497 .get_scan_results
= wpa_driver_ralink_get_scan_results
,
1498 .deauthenticate
= wpa_driver_ralink_deauthenticate
,
1499 .disassociate
= wpa_driver_ralink_disassociate
,
1500 .associate
= wpa_driver_ralink_associate
,
1501 .add_pmkid
= wpa_driver_ralink_add_pmkid
,
1502 .remove_pmkid
= wpa_driver_ralink_remove_pmkid
,
1503 .flush_pmkid
= wpa_driver_ralink_flush_pmkid
,