2 * WPA Supplicant - Windows/NDIS driver interface
3 * Copyright (c) 2004-2007, Jouni Malinen <j@w1.fi>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
9 * Alternatively, this software may be distributed under the terms of BSD
12 * See README and COPYING for more details.
16 /* Avoid some header file conflicts by not including standard headers for
17 * cygwin builds when Packet32.h is included. */
18 #include "build_config.h"
20 #else /* __CYGWIN__ */
22 #endif /* __CYGWIN__ */
23 #ifdef CONFIG_USE_NDISUIO
25 #else /* CONFIG_USE_NDISUIO */
27 #endif /* CONFIG_USE_NDISUIO */
34 #endif /* _WIN32_WCE */
39 #include "ieee802_11_defs.h"
40 #include "driver_ndis.h"
42 int wpa_driver_register_event_cb(struct wpa_driver_ndis_data
*drv
);
43 #ifdef CONFIG_NDIS_EVENTS_INTEGRATED
44 void wpa_driver_ndis_event_pipe_cb(void *eloop_data
, void *user_data
);
45 #endif /* CONFIG_NDIS_EVENTS_INTEGRATED */
47 static void wpa_driver_ndis_deinit(void *priv
);
48 static void wpa_driver_ndis_poll(void *drv
);
49 static void wpa_driver_ndis_poll_timeout(void *eloop_ctx
, void *timeout_ctx
);
50 static int wpa_driver_ndis_adapter_init(struct wpa_driver_ndis_data
*drv
);
51 static int wpa_driver_ndis_adapter_open(struct wpa_driver_ndis_data
*drv
);
52 static void wpa_driver_ndis_adapter_close(struct wpa_driver_ndis_data
*drv
);
55 /* FIX: to be removed once this can be compiled with the complete NDIS
57 #ifndef OID_802_11_BSSID
58 #define OID_802_11_BSSID 0x0d010101
59 #define OID_802_11_SSID 0x0d010102
60 #define OID_802_11_INFRASTRUCTURE_MODE 0x0d010108
61 #define OID_802_11_ADD_WEP 0x0D010113
62 #define OID_802_11_REMOVE_WEP 0x0D010114
63 #define OID_802_11_DISASSOCIATE 0x0D010115
64 #define OID_802_11_BSSID_LIST 0x0d010217
65 #define OID_802_11_AUTHENTICATION_MODE 0x0d010118
66 #define OID_802_11_PRIVACY_FILTER 0x0d010119
67 #define OID_802_11_BSSID_LIST_SCAN 0x0d01011A
68 #define OID_802_11_WEP_STATUS 0x0d01011B
69 #define OID_802_11_ENCRYPTION_STATUS OID_802_11_WEP_STATUS
70 #define OID_802_11_ADD_KEY 0x0d01011D
71 #define OID_802_11_REMOVE_KEY 0x0d01011E
72 #define OID_802_11_ASSOCIATION_INFORMATION 0x0d01011F
73 #define OID_802_11_TEST 0x0d010120
74 #define OID_802_11_CAPABILITY 0x0d010122
75 #define OID_802_11_PMKID 0x0d010123
77 #define NDIS_802_11_LENGTH_SSID 32
78 #define NDIS_802_11_LENGTH_RATES 8
79 #define NDIS_802_11_LENGTH_RATES_EX 16
81 typedef UCHAR NDIS_802_11_MAC_ADDRESS
[6];
83 typedef struct NDIS_802_11_SSID
{
85 UCHAR Ssid
[NDIS_802_11_LENGTH_SSID
];
88 typedef LONG NDIS_802_11_RSSI
;
90 typedef enum NDIS_802_11_NETWORK_TYPE
{
95 Ndis802_11NetworkTypeMax
96 } NDIS_802_11_NETWORK_TYPE
;
98 typedef struct NDIS_802_11_CONFIGURATION_FH
{
103 } NDIS_802_11_CONFIGURATION_FH
;
105 typedef struct NDIS_802_11_CONFIGURATION
{
110 NDIS_802_11_CONFIGURATION_FH FHConfig
;
111 } NDIS_802_11_CONFIGURATION
;
113 typedef enum NDIS_802_11_NETWORK_INFRASTRUCTURE
{
115 Ndis802_11Infrastructure
,
116 Ndis802_11AutoUnknown
,
117 Ndis802_11InfrastructureMax
118 } NDIS_802_11_NETWORK_INFRASTRUCTURE
;
120 typedef enum NDIS_802_11_AUTHENTICATION_MODE
{
121 Ndis802_11AuthModeOpen
,
122 Ndis802_11AuthModeShared
,
123 Ndis802_11AuthModeAutoSwitch
,
124 Ndis802_11AuthModeWPA
,
125 Ndis802_11AuthModeWPAPSK
,
126 Ndis802_11AuthModeWPANone
,
127 Ndis802_11AuthModeWPA2
,
128 Ndis802_11AuthModeWPA2PSK
,
129 Ndis802_11AuthModeMax
130 } NDIS_802_11_AUTHENTICATION_MODE
;
132 typedef enum NDIS_802_11_WEP_STATUS
{
133 Ndis802_11WEPEnabled
,
134 Ndis802_11Encryption1Enabled
= Ndis802_11WEPEnabled
,
135 Ndis802_11WEPDisabled
,
136 Ndis802_11EncryptionDisabled
= Ndis802_11WEPDisabled
,
137 Ndis802_11WEPKeyAbsent
,
138 Ndis802_11Encryption1KeyAbsent
= Ndis802_11WEPKeyAbsent
,
139 Ndis802_11WEPNotSupported
,
140 Ndis802_11EncryptionNotSupported
= Ndis802_11WEPNotSupported
,
141 Ndis802_11Encryption2Enabled
,
142 Ndis802_11Encryption2KeyAbsent
,
143 Ndis802_11Encryption3Enabled
,
144 Ndis802_11Encryption3KeyAbsent
145 } NDIS_802_11_WEP_STATUS
, NDIS_802_11_ENCRYPTION_STATUS
;
147 typedef enum NDIS_802_11_PRIVACY_FILTER
{
148 Ndis802_11PrivFilterAcceptAll
,
149 Ndis802_11PrivFilter8021xWEP
150 } NDIS_802_11_PRIVACY_FILTER
;
152 typedef UCHAR NDIS_802_11_RATES
[NDIS_802_11_LENGTH_RATES
];
153 typedef UCHAR NDIS_802_11_RATES_EX
[NDIS_802_11_LENGTH_RATES_EX
];
155 typedef struct NDIS_WLAN_BSSID_EX
{
157 NDIS_802_11_MAC_ADDRESS MacAddress
; /* BSSID */
159 NDIS_802_11_SSID Ssid
;
161 NDIS_802_11_RSSI Rssi
;
162 NDIS_802_11_NETWORK_TYPE NetworkTypeInUse
;
163 NDIS_802_11_CONFIGURATION Configuration
;
164 NDIS_802_11_NETWORK_INFRASTRUCTURE InfrastructureMode
;
165 NDIS_802_11_RATES_EX SupportedRates
;
168 } NDIS_WLAN_BSSID_EX
;
170 typedef struct NDIS_802_11_BSSID_LIST_EX
{
172 NDIS_WLAN_BSSID_EX Bssid
[1];
173 } NDIS_802_11_BSSID_LIST_EX
;
175 typedef struct NDIS_802_11_FIXED_IEs
{
177 USHORT BeaconInterval
;
179 } NDIS_802_11_FIXED_IEs
;
181 typedef struct NDIS_802_11_WEP
{
185 UCHAR KeyMaterial
[1];
188 typedef ULONG NDIS_802_11_KEY_INDEX
;
189 typedef ULONGLONG NDIS_802_11_KEY_RSC
;
191 typedef struct NDIS_802_11_KEY
{
195 NDIS_802_11_MAC_ADDRESS BSSID
;
196 NDIS_802_11_KEY_RSC KeyRSC
;
197 UCHAR KeyMaterial
[1];
200 typedef struct NDIS_802_11_REMOVE_KEY
{
203 NDIS_802_11_MAC_ADDRESS BSSID
;
204 } NDIS_802_11_REMOVE_KEY
;
206 typedef struct NDIS_802_11_AI_REQFI
{
208 USHORT ListenInterval
;
209 NDIS_802_11_MAC_ADDRESS CurrentAPAddress
;
210 } NDIS_802_11_AI_REQFI
;
212 typedef struct NDIS_802_11_AI_RESFI
{
215 USHORT AssociationId
;
216 } NDIS_802_11_AI_RESFI
;
218 typedef struct NDIS_802_11_ASSOCIATION_INFORMATION
{
220 USHORT AvailableRequestFixedIEs
;
221 NDIS_802_11_AI_REQFI RequestFixedIEs
;
222 ULONG RequestIELength
;
223 ULONG OffsetRequestIEs
;
224 USHORT AvailableResponseFixedIEs
;
225 NDIS_802_11_AI_RESFI ResponseFixedIEs
;
226 ULONG ResponseIELength
;
227 ULONG OffsetResponseIEs
;
228 } NDIS_802_11_ASSOCIATION_INFORMATION
;
230 typedef struct NDIS_802_11_AUTHENTICATION_ENCRYPTION
{
231 NDIS_802_11_AUTHENTICATION_MODE AuthModeSupported
;
232 NDIS_802_11_ENCRYPTION_STATUS EncryptStatusSupported
;
233 } NDIS_802_11_AUTHENTICATION_ENCRYPTION
;
235 typedef struct NDIS_802_11_CAPABILITY
{
239 ULONG NoOfAuthEncryptPairsSupported
;
240 NDIS_802_11_AUTHENTICATION_ENCRYPTION
241 AuthenticationEncryptionSupported
[1];
242 } NDIS_802_11_CAPABILITY
;
244 typedef UCHAR NDIS_802_11_PMKID_VALUE
[16];
246 typedef struct BSSID_INFO
{
247 NDIS_802_11_MAC_ADDRESS BSSID
;
248 NDIS_802_11_PMKID_VALUE PMKID
;
251 typedef struct NDIS_802_11_PMKID
{
253 ULONG BSSIDInfoCount
;
254 BSSID_INFO BSSIDInfo
[1];
257 typedef enum NDIS_802_11_STATUS_TYPE
{
258 Ndis802_11StatusType_Authentication
,
259 Ndis802_11StatusType_PMKID_CandidateList
= 2,
260 Ndis802_11StatusTypeMax
261 } NDIS_802_11_STATUS_TYPE
;
263 typedef struct NDIS_802_11_STATUS_INDICATION
{
264 NDIS_802_11_STATUS_TYPE StatusType
;
265 } NDIS_802_11_STATUS_INDICATION
;
267 typedef struct PMKID_CANDIDATE
{
268 NDIS_802_11_MAC_ADDRESS BSSID
;
272 #define NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED 0x01
274 typedef struct NDIS_802_11_PMKID_CANDIDATE_LIST
{
277 PMKID_CANDIDATE CandidateList
[1];
278 } NDIS_802_11_PMKID_CANDIDATE_LIST
;
280 typedef struct NDIS_802_11_AUTHENTICATION_REQUEST
{
282 NDIS_802_11_MAC_ADDRESS Bssid
;
284 } NDIS_802_11_AUTHENTICATION_REQUEST
;
286 #define NDIS_802_11_AUTH_REQUEST_REAUTH 0x01
287 #define NDIS_802_11_AUTH_REQUEST_KEYUPDATE 0x02
288 #define NDIS_802_11_AUTH_REQUEST_PAIRWISE_ERROR 0x06
289 #define NDIS_802_11_AUTH_REQUEST_GROUP_ERROR 0x0E
291 #endif /* OID_802_11_BSSID */
294 #ifndef OID_802_11_PMKID
295 /* Platform SDK for XP did not include WPA2, so add needed definitions */
297 #define OID_802_11_CAPABILITY 0x0d010122
298 #define OID_802_11_PMKID 0x0d010123
300 #define Ndis802_11AuthModeWPA2 6
301 #define Ndis802_11AuthModeWPA2PSK 7
303 #define Ndis802_11StatusType_PMKID_CandidateList 2
305 typedef struct NDIS_802_11_AUTHENTICATION_ENCRYPTION
{
306 NDIS_802_11_AUTHENTICATION_MODE AuthModeSupported
;
307 NDIS_802_11_ENCRYPTION_STATUS EncryptStatusSupported
;
308 } NDIS_802_11_AUTHENTICATION_ENCRYPTION
;
310 typedef struct NDIS_802_11_CAPABILITY
{
314 ULONG NoOfAuthEncryptPairsSupported
;
315 NDIS_802_11_AUTHENTICATION_ENCRYPTION
316 AuthenticationEncryptionSupported
[1];
317 } NDIS_802_11_CAPABILITY
;
319 typedef UCHAR NDIS_802_11_PMKID_VALUE
[16];
321 typedef struct BSSID_INFO
{
322 NDIS_802_11_MAC_ADDRESS BSSID
;
323 NDIS_802_11_PMKID_VALUE PMKID
;
326 typedef struct NDIS_802_11_PMKID
{
328 ULONG BSSIDInfoCount
;
329 BSSID_INFO BSSIDInfo
[1];
332 typedef struct PMKID_CANDIDATE
{
333 NDIS_802_11_MAC_ADDRESS BSSID
;
337 #define NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED 0x01
339 typedef struct NDIS_802_11_PMKID_CANDIDATE_LIST
{
342 PMKID_CANDIDATE CandidateList
[1];
343 } NDIS_802_11_PMKID_CANDIDATE_LIST
;
345 #endif /* OID_802_11_CAPABILITY */
348 #ifdef CONFIG_USE_NDISUIO
350 #ifdef __MINGW32_VERSION
351 typedef ULONG NDIS_OID
;
352 #endif /* __MINGW32_VERSION */
353 /* from nuiouser.h */
354 #define FSCTL_NDISUIO_BASE FILE_DEVICE_NETWORK
356 #define _NDISUIO_CTL_CODE(_Function, _Method, _Access) \
357 CTL_CODE(FSCTL_NDISUIO_BASE, _Function, _Method, _Access)
359 #define IOCTL_NDISUIO_OPEN_DEVICE \
360 _NDISUIO_CTL_CODE(0x200, METHOD_BUFFERED, \
361 FILE_READ_ACCESS | FILE_WRITE_ACCESS)
363 #define IOCTL_NDISUIO_QUERY_OID_VALUE \
364 _NDISUIO_CTL_CODE(0x201, METHOD_BUFFERED, \
365 FILE_READ_ACCESS | FILE_WRITE_ACCESS)
367 #define IOCTL_NDISUIO_SET_OID_VALUE \
368 _NDISUIO_CTL_CODE(0x205, METHOD_BUFFERED, \
369 FILE_READ_ACCESS | FILE_WRITE_ACCESS)
371 #define IOCTL_NDISUIO_SET_ETHER_TYPE \
372 _NDISUIO_CTL_CODE(0x202, METHOD_BUFFERED, \
373 FILE_READ_ACCESS | FILE_WRITE_ACCESS)
375 #define IOCTL_NDISUIO_QUERY_BINDING \
376 _NDISUIO_CTL_CODE(0x203, METHOD_BUFFERED, \
377 FILE_READ_ACCESS | FILE_WRITE_ACCESS)
379 #define IOCTL_NDISUIO_BIND_WAIT \
380 _NDISUIO_CTL_CODE(0x204, METHOD_BUFFERED, \
381 FILE_READ_ACCESS | FILE_WRITE_ACCESS)
383 typedef struct _NDISUIO_QUERY_OID
386 UCHAR Data
[sizeof(ULONG
)];
387 } NDISUIO_QUERY_OID
, *PNDISUIO_QUERY_OID
;
389 typedef struct _NDISUIO_SET_OID
392 UCHAR Data
[sizeof(ULONG
)];
393 } NDISUIO_SET_OID
, *PNDISUIO_SET_OID
;
395 typedef struct _NDISUIO_QUERY_BINDING
398 ULONG DeviceNameOffset
;
399 ULONG DeviceNameLength
;
400 ULONG DeviceDescrOffset
;
401 ULONG DeviceDescrLength
;
402 } NDISUIO_QUERY_BINDING
, *PNDISUIO_QUERY_BINDING
;
403 #endif /* _WIN32_WCE */
404 #endif /* CONFIG_USE_NDISUIO */
407 static int ndis_get_oid(struct wpa_driver_ndis_data
*drv
, unsigned int oid
,
408 char *data
, size_t len
)
410 #ifdef CONFIG_USE_NDISUIO
411 NDISUIO_QUERY_OID
*o
;
412 size_t buflen
= sizeof(*o
) + len
;
417 o
= os_zalloc(buflen
);
422 o
->ptcDeviceName
= drv
->adapter_name
;
423 #endif /* _WIN32_WCE */
424 if (!DeviceIoControl(drv
->ndisuio
, IOCTL_NDISUIO_QUERY_OID_VALUE
,
425 o
, sizeof(NDISUIO_QUERY_OID
), o
, buflen
, &written
,
427 wpa_printf(MSG_DEBUG
, "NDIS: IOCTL_NDISUIO_QUERY_OID_VALUE "
428 "failed (oid=%08x): %d", oid
, (int) GetLastError());
432 hdrlen
= sizeof(NDISUIO_QUERY_OID
) - sizeof(o
->Data
);
433 if (written
< hdrlen
) {
434 wpa_printf(MSG_DEBUG
, "NDIS: query oid=%08x written (%d); "
435 "too short", oid
, (unsigned int) written
);
441 wpa_printf(MSG_DEBUG
, "NDIS: query oid=%08x written (%d) > "
442 "len (%d)",oid
, (unsigned int) written
, len
);
446 os_memcpy(data
, o
->Data
, written
);
450 #else /* CONFIG_USE_NDISUIO */
455 buf
= os_zalloc(sizeof(*o
) + len
);
458 o
= (PACKET_OID_DATA
*) buf
;
462 if (!PacketRequest(drv
->adapter
, FALSE
, o
)) {
463 wpa_printf(MSG_DEBUG
, "%s: oid=0x%x len (%d) failed",
468 if (o
->Length
> len
) {
469 wpa_printf(MSG_DEBUG
, "%s: oid=0x%x Length (%d) > len (%d)",
470 __func__
, oid
, (unsigned int) o
->Length
, len
);
474 os_memcpy(data
, o
->Data
, o
->Length
);
478 #endif /* CONFIG_USE_NDISUIO */
482 static int ndis_set_oid(struct wpa_driver_ndis_data
*drv
, unsigned int oid
,
483 const char *data
, size_t len
)
485 #ifdef CONFIG_USE_NDISUIO
487 size_t buflen
, reallen
;
491 os_snprintf(txt
, sizeof(txt
), "NDIS: Set OID %08x", oid
);
492 wpa_hexdump_key(MSG_MSGDUMP
, txt
, data
, len
);
494 buflen
= sizeof(*o
) + len
;
495 reallen
= buflen
- sizeof(o
->Data
);
496 o
= os_zalloc(buflen
);
501 o
->ptcDeviceName
= drv
->adapter_name
;
502 #endif /* _WIN32_WCE */
504 os_memcpy(o
->Data
, data
, len
);
505 if (!DeviceIoControl(drv
->ndisuio
, IOCTL_NDISUIO_SET_OID_VALUE
,
506 o
, reallen
, NULL
, 0, &written
, NULL
)) {
507 wpa_printf(MSG_DEBUG
, "NDIS: IOCTL_NDISUIO_SET_OID_VALUE "
508 "(oid=%08x) failed: %d", oid
, (int) GetLastError());
514 #else /* CONFIG_USE_NDISUIO */
519 os_snprintf(txt
, sizeof(txt
), "NDIS: Set OID %08x", oid
);
520 wpa_hexdump_key(MSG_MSGDUMP
, txt
, data
, len
);
522 buf
= os_zalloc(sizeof(*o
) + len
);
525 o
= (PACKET_OID_DATA
*) buf
;
529 os_memcpy(o
->Data
, data
, len
);
531 if (!PacketRequest(drv
->adapter
, TRUE
, o
)) {
532 wpa_printf(MSG_DEBUG
, "%s: oid=0x%x len (%d) failed",
539 #endif /* CONFIG_USE_NDISUIO */
543 static int ndis_set_auth_mode(struct wpa_driver_ndis_data
*drv
, int mode
)
545 u32 auth_mode
= mode
;
546 if (ndis_set_oid(drv
, OID_802_11_AUTHENTICATION_MODE
,
547 (char *) &auth_mode
, sizeof(auth_mode
)) < 0) {
548 wpa_printf(MSG_DEBUG
, "NDIS: Failed to set "
549 "OID_802_11_AUTHENTICATION_MODE (%d)",
557 static int ndis_get_auth_mode(struct wpa_driver_ndis_data
*drv
)
561 res
= ndis_get_oid(drv
, OID_802_11_AUTHENTICATION_MODE
,
562 (char *) &auth_mode
, sizeof(auth_mode
));
563 if (res
!= sizeof(auth_mode
)) {
564 wpa_printf(MSG_DEBUG
, "NDIS: Failed to get "
565 "OID_802_11_AUTHENTICATION_MODE");
572 static int ndis_set_encr_status(struct wpa_driver_ndis_data
*drv
, int encr
)
574 u32 encr_status
= encr
;
575 if (ndis_set_oid(drv
, OID_802_11_ENCRYPTION_STATUS
,
576 (char *) &encr_status
, sizeof(encr_status
)) < 0) {
577 wpa_printf(MSG_DEBUG
, "NDIS: Failed to set "
578 "OID_802_11_ENCRYPTION_STATUS (%d)", encr
);
585 static int ndis_get_encr_status(struct wpa_driver_ndis_data
*drv
)
589 res
= ndis_get_oid(drv
, OID_802_11_ENCRYPTION_STATUS
,
590 (char *) &encr
, sizeof(encr
));
591 if (res
!= sizeof(encr
)) {
592 wpa_printf(MSG_DEBUG
, "NDIS: Failed to get "
593 "OID_802_11_ENCRYPTION_STATUS");
600 static int wpa_driver_ndis_get_bssid(void *priv
, u8
*bssid
)
602 struct wpa_driver_ndis_data
*drv
= priv
;
606 * Report PAE group address as the "BSSID" for wired
618 return ndis_get_oid(drv
, OID_802_11_BSSID
, bssid
, ETH_ALEN
) < 0 ?
623 static int wpa_driver_ndis_get_ssid(void *priv
, u8
*ssid
)
625 struct wpa_driver_ndis_data
*drv
= priv
;
626 NDIS_802_11_SSID buf
;
629 res
= ndis_get_oid(drv
, OID_802_11_SSID
, (char *) &buf
, sizeof(buf
));
631 wpa_printf(MSG_DEBUG
, "NDIS: Failed to get SSID");
633 wpa_printf(MSG_DEBUG
, "NDIS: Allow get_ssid failure "
634 "with a wired interface");
639 os_memcpy(ssid
, buf
.Ssid
, buf
.SsidLength
);
640 return buf
.SsidLength
;
644 static int wpa_driver_ndis_set_ssid(struct wpa_driver_ndis_data
*drv
,
645 const u8
*ssid
, size_t ssid_len
)
647 NDIS_802_11_SSID buf
;
649 os_memset(&buf
, 0, sizeof(buf
));
650 buf
.SsidLength
= ssid_len
;
651 os_memcpy(buf
.Ssid
, ssid
, ssid_len
);
653 * Make sure radio is marked enabled here so that scan request will not
654 * force SSID to be changed to a random one in order to enable radio at
657 drv
->radio_enabled
= 1;
658 return ndis_set_oid(drv
, OID_802_11_SSID
, (char *) &buf
, sizeof(buf
));
662 /* Disconnect using OID_802_11_DISASSOCIATE. This will also turn the radio off.
664 static int wpa_driver_ndis_radio_off(struct wpa_driver_ndis_data
*drv
)
666 drv
->radio_enabled
= 0;
667 return ndis_set_oid(drv
, OID_802_11_DISASSOCIATE
, " ", 4);
671 /* Disconnect by setting SSID to random (i.e., likely not used). */
672 static int wpa_driver_ndis_disconnect(struct wpa_driver_ndis_data
*drv
)
676 for (i
= 0; i
< 32; i
++)
677 ssid
[i
] = rand() & 0xff;
678 return wpa_driver_ndis_set_ssid(drv
, ssid
, 32);
682 static int wpa_driver_ndis_deauthenticate(void *priv
, const u8
*addr
,
685 struct wpa_driver_ndis_data
*drv
= priv
;
686 return wpa_driver_ndis_disconnect(drv
);
690 static int wpa_driver_ndis_disassociate(void *priv
, const u8
*addr
,
693 struct wpa_driver_ndis_data
*drv
= priv
;
694 return wpa_driver_ndis_disconnect(drv
);
698 static int wpa_driver_ndis_set_wpa(void *priv
, int enabled
)
700 wpa_printf(MSG_DEBUG
, "%s: enabled=%d", __func__
, enabled
);
705 static void wpa_driver_ndis_scan_timeout(void *eloop_ctx
, void *timeout_ctx
)
707 wpa_printf(MSG_DEBUG
, "Scan timeout - try to get results");
708 wpa_supplicant_event(timeout_ctx
, EVENT_SCAN_RESULTS
, NULL
);
712 static int wpa_driver_ndis_scan(void *priv
, const u8
*ssid
, size_t ssid_len
)
714 struct wpa_driver_ndis_data
*drv
= priv
;
717 if (!drv
->radio_enabled
) {
718 wpa_printf(MSG_DEBUG
, "NDIS: turning radio on before the first"
720 if (wpa_driver_ndis_disconnect(drv
) < 0) {
721 wpa_printf(MSG_DEBUG
, "NDIS: failed to enable radio");
723 drv
->radio_enabled
= 1;
726 res
= ndis_set_oid(drv
, OID_802_11_BSSID_LIST_SCAN
, " ", 4);
727 eloop_cancel_timeout(wpa_driver_ndis_scan_timeout
, drv
, drv
->ctx
);
728 eloop_register_timeout(7, 0, wpa_driver_ndis_scan_timeout
, drv
,
734 static struct wpa_scan_results
* wpa_driver_ndis_get_scan_results(void *priv
)
736 struct wpa_driver_ndis_data
*drv
= priv
;
737 NDIS_802_11_BSSID_LIST_EX
*b
;
738 size_t blen
, count
, i
;
741 struct wpa_scan_results
*results
;
742 struct wpa_scan_res
*r
;
748 len
= ndis_get_oid(drv
, OID_802_11_BSSID_LIST
, (char *) b
, blen
);
750 wpa_printf(MSG_DEBUG
, "NDIS: failed to get scan results");
754 count
= b
->NumberOfItems
;
756 results
= os_zalloc(sizeof(*results
));
757 if (results
== NULL
) {
761 results
->res
= os_zalloc(count
* sizeof(struct wpa_scan_res
*));
762 if (results
->res
== NULL
) {
768 pos
= (char *) &b
->Bssid
[0];
769 for (i
= 0; i
< count
; i
++) {
770 NDIS_WLAN_BSSID_EX
*bss
= (NDIS_WLAN_BSSID_EX
*) pos
;
771 NDIS_802_11_FIXED_IEs
*fixed
;
773 if (bss
->IELength
< sizeof(NDIS_802_11_FIXED_IEs
)) {
774 wpa_printf(MSG_DEBUG
, "NDIS: too small IELength=%d",
775 (int) bss
->IELength
);
778 if (((char *) bss
->IEs
) + bss
->IELength
> (char *) b
+ blen
) {
780 * Some NDIS drivers have been reported to include an
781 * entry with an invalid IELength in scan results and
782 * this has crashed wpa_supplicant, so validate the
783 * returned value before using it.
785 wpa_printf(MSG_DEBUG
, "NDIS: skipped invalid scan "
786 "result IE (BSSID=" MACSTR
") IELength=%d",
787 MAC2STR(bss
->MacAddress
),
788 (int) bss
->IELength
);
792 r
= os_zalloc(sizeof(*r
) + bss
->IELength
-
793 sizeof(NDIS_802_11_FIXED_IEs
));
797 os_memcpy(r
->bssid
, bss
->MacAddress
, ETH_ALEN
);
798 r
->level
= (int) bss
->Rssi
;
799 r
->freq
= bss
->Configuration
.DSConfig
/ 1000;
800 fixed
= (NDIS_802_11_FIXED_IEs
*) bss
->IEs
;
801 r
->beacon_int
= WPA_GET_LE16((u8
*) &fixed
->BeaconInterval
);
802 r
->caps
= WPA_GET_LE16((u8
*) &fixed
->Capabilities
);
803 r
->tsf
= WPA_GET_LE64(fixed
->Timestamp
);
804 os_memcpy(r
+ 1, bss
->IEs
+ sizeof(NDIS_802_11_FIXED_IEs
),
805 bss
->IELength
- sizeof(NDIS_802_11_FIXED_IEs
));
806 r
->ie_len
= bss
->IELength
- sizeof(NDIS_802_11_FIXED_IEs
);
808 results
->res
[results
->num
++] = r
;
811 if (pos
> (char *) b
+ blen
)
821 static int wpa_driver_ndis_remove_key(struct wpa_driver_ndis_data
*drv
,
822 int key_idx
, const u8
*addr
,
823 const u8
*bssid
, int pairwise
)
825 NDIS_802_11_REMOVE_KEY rkey
;
826 NDIS_802_11_KEY_INDEX index
;
829 os_memset(&rkey
, 0, sizeof(rkey
));
831 rkey
.Length
= sizeof(rkey
);
832 rkey
.KeyIndex
= key_idx
;
834 rkey
.KeyIndex
|= 1 << 30;
835 os_memcpy(rkey
.BSSID
, bssid
, ETH_ALEN
);
837 res
= ndis_set_oid(drv
, OID_802_11_REMOVE_KEY
, (char *) &rkey
,
841 res2
= ndis_set_oid(drv
, OID_802_11_REMOVE_WEP
,
842 (char *) &index
, sizeof(index
));
846 if (res
< 0 && res2
< 0)
852 static int wpa_driver_ndis_add_wep(struct wpa_driver_ndis_data
*drv
,
853 int pairwise
, int key_idx
, int set_tx
,
854 const u8
*key
, size_t key_len
)
856 NDIS_802_11_WEP
*wep
;
861 wep
= os_zalloc(len
);
865 wep
->KeyIndex
= key_idx
;
867 wep
->KeyIndex
|= 1 << 31;
868 #if 0 /* Setting bit30 does not seem to work with some NDIS drivers */
870 wep
->KeyIndex
|= 1 << 30;
872 wep
->KeyLength
= key_len
;
873 os_memcpy(wep
->KeyMaterial
, key
, key_len
);
875 wpa_hexdump_key(MSG_MSGDUMP
, "NDIS: OID_802_11_ADD_WEP",
877 res
= ndis_set_oid(drv
, OID_802_11_ADD_WEP
, (char *) wep
, len
);
885 static int wpa_driver_ndis_set_key(void *priv
, wpa_alg alg
, const u8
*addr
,
886 int key_idx
, int set_tx
,
887 const u8
*seq
, size_t seq_len
,
888 const u8
*key
, size_t key_len
)
890 struct wpa_driver_ndis_data
*drv
= priv
;
892 NDIS_802_11_KEY
*nkey
;
896 if (addr
== NULL
|| os_memcmp(addr
, "\xff\xff\xff\xff\xff\xff",
900 if (wpa_driver_ndis_get_bssid(drv
, bssid
) < 0)
901 os_memset(bssid
, 0xff, ETH_ALEN
);
905 os_memcpy(bssid
, addr
, ETH_ALEN
);
908 if (alg
== WPA_ALG_NONE
|| key_len
== 0) {
909 return wpa_driver_ndis_remove_key(drv
, key_idx
, addr
, bssid
,
913 if (alg
== WPA_ALG_WEP
) {
914 return wpa_driver_ndis_add_wep(drv
, pairwise
, key_idx
, set_tx
,
918 len
= 12 + 6 + 6 + 8 + key_len
;
920 nkey
= os_zalloc(len
);
925 nkey
->KeyIndex
= key_idx
;
927 nkey
->KeyIndex
|= 1 << 31;
929 nkey
->KeyIndex
|= 1 << 30;
931 nkey
->KeyIndex
|= 1 << 29;
932 nkey
->KeyLength
= key_len
;
933 os_memcpy(nkey
->BSSID
, bssid
, ETH_ALEN
);
934 if (seq
&& seq_len
) {
935 for (i
= 0; i
< seq_len
; i
++)
936 nkey
->KeyRSC
|= (ULONGLONG
) seq
[i
] << (i
* 8);
938 if (alg
== WPA_ALG_TKIP
&& key_len
== 32) {
939 os_memcpy(nkey
->KeyMaterial
, key
, 16);
940 os_memcpy(nkey
->KeyMaterial
+ 16, key
+ 24, 8);
941 os_memcpy(nkey
->KeyMaterial
+ 24, key
+ 16, 8);
943 os_memcpy(nkey
->KeyMaterial
, key
, key_len
);
946 wpa_hexdump_key(MSG_MSGDUMP
, "NDIS: OID_802_11_ADD_KEY",
948 res
= ndis_set_oid(drv
, OID_802_11_ADD_KEY
, (char *) nkey
, len
);
956 wpa_driver_ndis_associate(void *priv
,
957 struct wpa_driver_associate_params
*params
)
959 struct wpa_driver_ndis_data
*drv
= priv
;
960 u32 auth_mode
, encr
, priv_mode
, mode
;
962 drv
->mode
= params
->mode
;
964 /* Note: Setting OID_802_11_INFRASTRUCTURE_MODE clears current keys,
965 * so static WEP keys needs to be set again after this. */
966 if (params
->mode
== IEEE80211_MODE_IBSS
) {
967 mode
= Ndis802_11IBSS
;
968 /* Need to make sure that BSSID polling is enabled for
970 eloop_cancel_timeout(wpa_driver_ndis_poll_timeout
, drv
, NULL
);
971 eloop_register_timeout(1, 0, wpa_driver_ndis_poll_timeout
,
974 mode
= Ndis802_11Infrastructure
;
975 if (ndis_set_oid(drv
, OID_802_11_INFRASTRUCTURE_MODE
,
976 (char *) &mode
, sizeof(mode
)) < 0) {
977 wpa_printf(MSG_DEBUG
, "NDIS: Failed to set "
978 "OID_802_11_INFRASTRUCTURE_MODE (%d)",
980 /* Try to continue anyway */
983 if (params
->key_mgmt_suite
== KEY_MGMT_NONE
||
984 params
->key_mgmt_suite
== KEY_MGMT_802_1X_NO_WPA
) {
985 /* Re-set WEP keys if static WEP configuration is used. */
986 u8 bcast
[ETH_ALEN
] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
988 for (i
= 0; i
< 4; i
++) {
989 if (!params
->wep_key
[i
])
991 wpa_printf(MSG_DEBUG
, "NDIS: Re-setting static WEP "
993 wpa_driver_ndis_set_key(drv
, WPA_ALG_WEP
, bcast
, i
,
994 i
== params
->wep_tx_keyidx
,
995 NULL
, 0, params
->wep_key
[i
],
996 params
->wep_key_len
[i
]);
1000 if (params
->wpa_ie
== NULL
|| params
->wpa_ie_len
== 0) {
1001 if (params
->auth_alg
& AUTH_ALG_SHARED_KEY
) {
1002 if (params
->auth_alg
& AUTH_ALG_OPEN_SYSTEM
)
1003 auth_mode
= Ndis802_11AuthModeAutoSwitch
;
1005 auth_mode
= Ndis802_11AuthModeShared
;
1007 auth_mode
= Ndis802_11AuthModeOpen
;
1008 priv_mode
= Ndis802_11PrivFilterAcceptAll
;
1009 } else if (params
->wpa_ie
[0] == WLAN_EID_RSN
) {
1010 priv_mode
= Ndis802_11PrivFilter8021xWEP
;
1011 if (params
->key_mgmt_suite
== KEY_MGMT_PSK
)
1012 auth_mode
= Ndis802_11AuthModeWPA2PSK
;
1014 auth_mode
= Ndis802_11AuthModeWPA2
;
1016 priv_mode
= Ndis802_11PrivFilter8021xWEP
;
1017 if (params
->key_mgmt_suite
== KEY_MGMT_WPA_NONE
)
1018 auth_mode
= Ndis802_11AuthModeWPANone
;
1019 else if (params
->key_mgmt_suite
== KEY_MGMT_PSK
)
1020 auth_mode
= Ndis802_11AuthModeWPAPSK
;
1022 auth_mode
= Ndis802_11AuthModeWPA
;
1025 switch (params
->pairwise_suite
) {
1027 encr
= Ndis802_11Encryption3Enabled
;
1030 encr
= Ndis802_11Encryption2Enabled
;
1034 encr
= Ndis802_11Encryption1Enabled
;
1037 if (params
->group_suite
== CIPHER_CCMP
)
1038 encr
= Ndis802_11Encryption3Enabled
;
1039 else if (params
->group_suite
== CIPHER_TKIP
)
1040 encr
= Ndis802_11Encryption2Enabled
;
1042 encr
= Ndis802_11EncryptionDisabled
;
1045 encr
= Ndis802_11EncryptionDisabled
;
1048 if (ndis_set_oid(drv
, OID_802_11_PRIVACY_FILTER
,
1049 (char *) &priv_mode
, sizeof(priv_mode
)) < 0) {
1050 wpa_printf(MSG_DEBUG
, "NDIS: Failed to set "
1051 "OID_802_11_PRIVACY_FILTER (%d)",
1053 /* Try to continue anyway */
1056 ndis_set_auth_mode(drv
, auth_mode
);
1057 ndis_set_encr_status(drv
, encr
);
1059 if (params
->bssid
) {
1060 ndis_set_oid(drv
, OID_802_11_BSSID
, params
->bssid
, ETH_ALEN
);
1061 drv
->oid_bssid_set
= 1;
1062 } else if (drv
->oid_bssid_set
) {
1063 ndis_set_oid(drv
, OID_802_11_BSSID
, "\xff\xff\xff\xff\xff\xff",
1065 drv
->oid_bssid_set
= 0;
1068 return wpa_driver_ndis_set_ssid(drv
, params
->ssid
, params
->ssid_len
);
1072 static int wpa_driver_ndis_set_pmkid(struct wpa_driver_ndis_data
*drv
)
1074 int len
, count
, i
, ret
;
1075 struct ndis_pmkid_entry
*entry
;
1076 NDIS_802_11_PMKID
*p
;
1082 if (count
>= drv
->no_of_pmkid
)
1084 entry
= entry
->next
;
1086 len
= 8 + count
* sizeof(BSSID_INFO
);
1092 p
->BSSIDInfoCount
= count
;
1094 for (i
= 0; i
< count
; i
++) {
1095 os_memcpy(&p
->BSSIDInfo
[i
].BSSID
, entry
->bssid
, ETH_ALEN
);
1096 os_memcpy(&p
->BSSIDInfo
[i
].PMKID
, entry
->pmkid
, 16);
1097 entry
= entry
->next
;
1099 wpa_hexdump(MSG_MSGDUMP
, "NDIS: OID_802_11_PMKID", (char *) p
, len
);
1100 ret
= ndis_set_oid(drv
, OID_802_11_PMKID
, (char *) p
, len
);
1106 static int wpa_driver_ndis_add_pmkid(void *priv
, const u8
*bssid
,
1109 struct wpa_driver_ndis_data
*drv
= priv
;
1110 struct ndis_pmkid_entry
*entry
, *prev
;
1112 if (drv
->no_of_pmkid
== 0)
1118 if (os_memcmp(entry
->bssid
, bssid
, ETH_ALEN
) == 0)
1121 entry
= entry
->next
;
1125 /* Replace existing entry for this BSSID and move it into the
1126 * beginning of the list. */
1127 os_memcpy(entry
->pmkid
, pmkid
, 16);
1129 prev
->next
= entry
->next
;
1130 entry
->next
= drv
->pmkid
;
1134 entry
= os_malloc(sizeof(*entry
));
1136 os_memcpy(entry
->bssid
, bssid
, ETH_ALEN
);
1137 os_memcpy(entry
->pmkid
, pmkid
, 16);
1138 entry
->next
= drv
->pmkid
;
1143 return wpa_driver_ndis_set_pmkid(drv
);
1147 static int wpa_driver_ndis_remove_pmkid(void *priv
, const u8
*bssid
,
1150 struct wpa_driver_ndis_data
*drv
= priv
;
1151 struct ndis_pmkid_entry
*entry
, *prev
;
1153 if (drv
->no_of_pmkid
== 0)
1159 if (os_memcmp(entry
->bssid
, bssid
, ETH_ALEN
) == 0 &&
1160 os_memcmp(entry
->pmkid
, pmkid
, 16) == 0) {
1162 prev
->next
= entry
->next
;
1164 drv
->pmkid
= entry
->next
;
1169 entry
= entry
->next
;
1171 return wpa_driver_ndis_set_pmkid(drv
);
1175 static int wpa_driver_ndis_flush_pmkid(void *priv
)
1177 struct wpa_driver_ndis_data
*drv
= priv
;
1178 NDIS_802_11_PMKID p
;
1179 struct ndis_pmkid_entry
*pmkid
, *prev
;
1181 if (drv
->no_of_pmkid
== 0)
1188 pmkid
= pmkid
->next
;
1192 os_memset(&p
, 0, sizeof(p
));
1194 p
.BSSIDInfoCount
= 0;
1195 wpa_hexdump(MSG_MSGDUMP
, "NDIS: OID_802_11_PMKID (flush)",
1197 return ndis_set_oid(drv
, OID_802_11_PMKID
, (char *) &p
, 8);
1201 static int wpa_driver_ndis_get_associnfo(struct wpa_driver_ndis_data
*drv
)
1203 char buf
[512], *pos
;
1204 NDIS_802_11_ASSOCIATION_INFORMATION
*ai
;
1206 union wpa_event_data data
;
1207 NDIS_802_11_BSSID_LIST_EX
*b
;
1210 len
= ndis_get_oid(drv
, OID_802_11_ASSOCIATION_INFORMATION
, buf
,
1213 wpa_printf(MSG_DEBUG
, "NDIS: failed to get association "
1217 if (len
> sizeof(buf
)) {
1218 /* Some drivers seem to be producing incorrect length for this
1219 * data. Limit the length to the current buffer size to avoid
1220 * crashing in hexdump. The data seems to be otherwise valid,
1221 * so better try to use it. */
1222 wpa_printf(MSG_DEBUG
, "NDIS: ignored bogus association "
1223 "information length %d", len
);
1224 len
= ndis_get_oid(drv
, OID_802_11_ASSOCIATION_INFORMATION
,
1227 wpa_printf(MSG_DEBUG
, "NDIS: re-reading association "
1228 "information failed");
1231 if (len
> sizeof(buf
)) {
1232 wpa_printf(MSG_DEBUG
, "NDIS: ignored bogus association"
1233 " information length %d (re-read)", len
);
1237 wpa_hexdump(MSG_MSGDUMP
, "NDIS: association information", buf
, len
);
1238 if (len
< sizeof(*ai
)) {
1239 wpa_printf(MSG_DEBUG
, "NDIS: too short association "
1243 ai
= (NDIS_802_11_ASSOCIATION_INFORMATION
*) buf
;
1244 wpa_printf(MSG_DEBUG
, "NDIS: ReqFixed=0x%x RespFixed=0x%x off_req=%d "
1245 "off_resp=%d len_req=%d len_resp=%d",
1246 ai
->AvailableRequestFixedIEs
, ai
->AvailableResponseFixedIEs
,
1247 (int) ai
->OffsetRequestIEs
, (int) ai
->OffsetResponseIEs
,
1248 (int) ai
->RequestIELength
, (int) ai
->ResponseIELength
);
1250 if (ai
->OffsetRequestIEs
+ ai
->RequestIELength
> (unsigned) len
||
1251 ai
->OffsetResponseIEs
+ ai
->ResponseIELength
> (unsigned) len
) {
1252 wpa_printf(MSG_DEBUG
, "NDIS: association information - "
1257 wpa_hexdump(MSG_MSGDUMP
, "NDIS: Request IEs",
1258 buf
+ ai
->OffsetRequestIEs
, ai
->RequestIELength
);
1259 wpa_hexdump(MSG_MSGDUMP
, "NDIS: Response IEs",
1260 buf
+ ai
->OffsetResponseIEs
, ai
->ResponseIELength
);
1262 os_memset(&data
, 0, sizeof(data
));
1263 data
.assoc_info
.req_ies
= buf
+ ai
->OffsetRequestIEs
;
1264 data
.assoc_info
.req_ies_len
= ai
->RequestIELength
;
1265 data
.assoc_info
.resp_ies
= buf
+ ai
->OffsetResponseIEs
;
1266 data
.assoc_info
.resp_ies_len
= ai
->ResponseIELength
;
1269 b
= os_zalloc(blen
);
1271 goto skip_scan_results
;
1272 len
= ndis_get_oid(drv
, OID_802_11_BSSID_LIST
, (char *) b
, blen
);
1274 wpa_printf(MSG_DEBUG
, "NDIS: failed to get scan results");
1277 goto skip_scan_results
;
1279 wpa_printf(MSG_DEBUG
, "NDIS: %d BSSID items to process for AssocInfo",
1280 (unsigned int) b
->NumberOfItems
);
1282 pos
= (char *) &b
->Bssid
[0];
1283 for (i
= 0; i
< b
->NumberOfItems
; i
++) {
1284 NDIS_WLAN_BSSID_EX
*bss
= (NDIS_WLAN_BSSID_EX
*) pos
;
1285 if (os_memcmp(drv
->bssid
, bss
->MacAddress
, ETH_ALEN
) == 0 &&
1286 bss
->IELength
> sizeof(NDIS_802_11_FIXED_IEs
)) {
1287 data
.assoc_info
.beacon_ies
=
1289 sizeof(NDIS_802_11_FIXED_IEs
);
1290 data
.assoc_info
.beacon_ies_len
=
1291 bss
->IELength
- sizeof(NDIS_802_11_FIXED_IEs
);
1292 wpa_hexdump(MSG_MSGDUMP
, "NDIS: Beacon IEs",
1293 data
.assoc_info
.beacon_ies
,
1294 data
.assoc_info
.beacon_ies_len
);
1298 if (pos
> (char *) b
+ blen
)
1303 wpa_supplicant_event(drv
->ctx
, EVENT_ASSOCINFO
, &data
);
1311 static void wpa_driver_ndis_poll_timeout(void *eloop_ctx
, void *timeout_ctx
)
1313 struct wpa_driver_ndis_data
*drv
= eloop_ctx
;
1320 if (wpa_driver_ndis_get_bssid(drv
, bssid
)) {
1322 if (!is_zero_ether_addr(drv
->bssid
)) {
1323 os_memset(drv
->bssid
, 0, ETH_ALEN
);
1324 wpa_supplicant_event(drv
->ctx
, EVENT_DISASSOC
, NULL
);
1328 if (os_memcmp(drv
->bssid
, bssid
, ETH_ALEN
) != 0) {
1329 os_memcpy(drv
->bssid
, bssid
, ETH_ALEN
);
1330 wpa_driver_ndis_get_associnfo(drv
);
1331 wpa_supplicant_event(drv
->ctx
, EVENT_ASSOC
, NULL
);
1335 /* When using integrated NDIS event receiver, we can skip BSSID
1336 * polling when using infrastructure network. However, when using
1337 * IBSS mode, many driver do not seem to generate connection event,
1338 * so we need to enable BSSID polling to figure out when IBSS network
1341 poll
= drv
->mode
== IEEE80211_MODE_IBSS
;
1342 #ifndef CONFIG_NDIS_EVENTS_INTEGRATED
1345 #endif /* _WIN32_WCE */
1346 #endif /* CONFIG_NDIS_EVENTS_INTEGRATED */
1349 eloop_register_timeout(1, 0, wpa_driver_ndis_poll_timeout
,
1355 static void wpa_driver_ndis_poll(void *priv
)
1357 struct wpa_driver_ndis_data
*drv
= priv
;
1358 eloop_cancel_timeout(wpa_driver_ndis_poll_timeout
, drv
, NULL
);
1359 wpa_driver_ndis_poll_timeout(drv
, NULL
);
1363 /* Called when driver generates Media Connect Event by calling
1364 * NdisMIndicateStatus() with NDIS_STATUS_MEDIA_CONNECT */
1365 void wpa_driver_ndis_event_connect(struct wpa_driver_ndis_data
*drv
)
1367 wpa_printf(MSG_DEBUG
, "NDIS: Media Connect Event");
1368 if (wpa_driver_ndis_get_bssid(drv
, drv
->bssid
) == 0) {
1369 wpa_driver_ndis_get_associnfo(drv
);
1370 wpa_supplicant_event(drv
->ctx
, EVENT_ASSOC
, NULL
);
1375 /* Called when driver generates Media Disconnect Event by calling
1376 * NdisMIndicateStatus() with NDIS_STATUS_MEDIA_DISCONNECT */
1377 void wpa_driver_ndis_event_disconnect(struct wpa_driver_ndis_data
*drv
)
1379 wpa_printf(MSG_DEBUG
, "NDIS: Media Disconnect Event");
1380 os_memset(drv
->bssid
, 0, ETH_ALEN
);
1381 wpa_supplicant_event(drv
->ctx
, EVENT_DISASSOC
, NULL
);
1385 static void wpa_driver_ndis_event_auth(struct wpa_driver_ndis_data
*drv
,
1386 const u8
*data
, size_t data_len
)
1388 NDIS_802_11_AUTHENTICATION_REQUEST
*req
;
1389 int pairwise
= 0, group
= 0;
1390 union wpa_event_data event
;
1392 if (data_len
< sizeof(*req
)) {
1393 wpa_printf(MSG_DEBUG
, "NDIS: Too short Authentication Request "
1394 "Event (len=%d)", data_len
);
1397 req
= (NDIS_802_11_AUTHENTICATION_REQUEST
*) data
;
1399 wpa_printf(MSG_DEBUG
, "NDIS: Authentication Request Event: "
1400 "Bssid " MACSTR
" Flags 0x%x",
1401 MAC2STR(req
->Bssid
), (int) req
->Flags
);
1403 if ((req
->Flags
& NDIS_802_11_AUTH_REQUEST_PAIRWISE_ERROR
) ==
1404 NDIS_802_11_AUTH_REQUEST_PAIRWISE_ERROR
)
1406 else if ((req
->Flags
& NDIS_802_11_AUTH_REQUEST_GROUP_ERROR
) ==
1407 NDIS_802_11_AUTH_REQUEST_GROUP_ERROR
)
1410 if (pairwise
|| group
) {
1411 os_memset(&event
, 0, sizeof(event
));
1412 event
.michael_mic_failure
.unicast
= pairwise
;
1413 wpa_supplicant_event(drv
->ctx
, EVENT_MICHAEL_MIC_FAILURE
,
1419 static void wpa_driver_ndis_event_pmkid(struct wpa_driver_ndis_data
*drv
,
1420 const u8
*data
, size_t data_len
)
1422 NDIS_802_11_PMKID_CANDIDATE_LIST
*pmkid
;
1424 union wpa_event_data event
;
1427 wpa_printf(MSG_DEBUG
, "NDIS: Too short PMKID Candidate List "
1428 "Event (len=%d)", data_len
);
1431 pmkid
= (NDIS_802_11_PMKID_CANDIDATE_LIST
*) data
;
1432 wpa_printf(MSG_DEBUG
, "NDIS: PMKID Candidate List Event - Version %d "
1434 (int) pmkid
->Version
, (int) pmkid
->NumCandidates
);
1436 if (pmkid
->Version
!= 1) {
1437 wpa_printf(MSG_DEBUG
, "NDIS: Unsupported PMKID Candidate List "
1438 "Version %d", (int) pmkid
->Version
);
1442 if (data_len
< 8 + pmkid
->NumCandidates
* sizeof(PMKID_CANDIDATE
)) {
1443 wpa_printf(MSG_DEBUG
, "NDIS: PMKID Candidate List underflow");
1447 os_memset(&event
, 0, sizeof(event
));
1448 for (i
= 0; i
< pmkid
->NumCandidates
; i
++) {
1449 PMKID_CANDIDATE
*p
= &pmkid
->CandidateList
[i
];
1450 wpa_printf(MSG_DEBUG
, "NDIS: %d: " MACSTR
" Flags 0x%x",
1451 i
, MAC2STR(p
->BSSID
), (int) p
->Flags
);
1452 os_memcpy(event
.pmkid_candidate
.bssid
, p
->BSSID
, ETH_ALEN
);
1453 event
.pmkid_candidate
.index
= i
;
1454 event
.pmkid_candidate
.preauth
=
1455 p
->Flags
& NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED
;
1456 wpa_supplicant_event(drv
->ctx
, EVENT_PMKID_CANDIDATE
,
1462 /* Called when driver calls NdisMIndicateStatus() with
1463 * NDIS_STATUS_MEDIA_SPECIFIC_INDICATION */
1464 void wpa_driver_ndis_event_media_specific(struct wpa_driver_ndis_data
*drv
,
1465 const u8
*data
, size_t data_len
)
1467 NDIS_802_11_STATUS_INDICATION
*status
;
1469 if (data
== NULL
|| data_len
< sizeof(*status
))
1472 wpa_hexdump(MSG_DEBUG
, "NDIS: Media Specific Indication",
1475 status
= (NDIS_802_11_STATUS_INDICATION
*) data
;
1476 data
+= sizeof(status
);
1477 data_len
-= sizeof(status
);
1479 switch (status
->StatusType
) {
1480 case Ndis802_11StatusType_Authentication
:
1481 wpa_driver_ndis_event_auth(drv
, data
, data_len
);
1483 case Ndis802_11StatusType_PMKID_CandidateList
:
1484 wpa_driver_ndis_event_pmkid(drv
, data
, data_len
);
1487 wpa_printf(MSG_DEBUG
, "NDIS: Unknown StatusType %d",
1488 (int) status
->StatusType
);
1494 /* Called when an adapter is added */
1495 void wpa_driver_ndis_event_adapter_arrival(struct wpa_driver_ndis_data
*drv
)
1497 union wpa_event_data event
;
1500 wpa_printf(MSG_DEBUG
, "NDIS: Notify Adapter Arrival");
1502 for (i
= 0; i
< 30; i
++) {
1503 /* Re-open Packet32/NDISUIO connection */
1504 wpa_driver_ndis_adapter_close(drv
);
1505 if (wpa_driver_ndis_adapter_init(drv
) < 0 ||
1506 wpa_driver_ndis_adapter_open(drv
) < 0) {
1507 wpa_printf(MSG_DEBUG
, "NDIS: Driver re-initialization "
1511 wpa_printf(MSG_DEBUG
, "NDIS: Driver re-initialized");
1516 os_memset(&event
, 0, sizeof(event
));
1517 os_strlcpy(event
.interface_status
.ifname
, drv
->ifname
,
1518 sizeof(event
.interface_status
.ifname
));
1519 event
.interface_status
.ievent
= EVENT_INTERFACE_ADDED
;
1520 wpa_supplicant_event(drv
->ctx
, EVENT_INTERFACE_STATUS
, &event
);
1524 /* Called when an adapter is removed */
1525 void wpa_driver_ndis_event_adapter_removal(struct wpa_driver_ndis_data
*drv
)
1527 union wpa_event_data event
;
1529 wpa_printf(MSG_DEBUG
, "NDIS: Notify Adapter Removal");
1530 os_memset(&event
, 0, sizeof(event
));
1531 os_strlcpy(event
.interface_status
.ifname
, drv
->ifname
,
1532 sizeof(event
.interface_status
.ifname
));
1533 event
.interface_status
.ievent
= EVENT_INTERFACE_REMOVED
;
1534 wpa_supplicant_event(drv
->ctx
, EVENT_INTERFACE_STATUS
, &event
);
1539 wpa_driver_ndis_get_wpa_capability(struct wpa_driver_ndis_data
*drv
)
1541 wpa_printf(MSG_DEBUG
, "NDIS: verifying driver WPA capability");
1543 if (ndis_set_auth_mode(drv
, Ndis802_11AuthModeWPA
) == 0 &&
1544 ndis_get_auth_mode(drv
) == Ndis802_11AuthModeWPA
) {
1545 wpa_printf(MSG_DEBUG
, "NDIS: WPA key management supported");
1546 drv
->capa
.key_mgmt
|= WPA_DRIVER_CAPA_KEY_MGMT_WPA
;
1549 if (ndis_set_auth_mode(drv
, Ndis802_11AuthModeWPAPSK
) == 0 &&
1550 ndis_get_auth_mode(drv
) == Ndis802_11AuthModeWPAPSK
) {
1551 wpa_printf(MSG_DEBUG
, "NDIS: WPA-PSK key management "
1553 drv
->capa
.key_mgmt
|= WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK
;
1556 if (ndis_set_encr_status(drv
, Ndis802_11Encryption3Enabled
) == 0 &&
1557 ndis_get_encr_status(drv
) == Ndis802_11Encryption3KeyAbsent
) {
1558 wpa_printf(MSG_DEBUG
, "NDIS: CCMP encryption supported");
1559 drv
->capa
.enc
|= WPA_DRIVER_CAPA_ENC_CCMP
;
1562 if (ndis_set_encr_status(drv
, Ndis802_11Encryption2Enabled
) == 0 &&
1563 ndis_get_encr_status(drv
) == Ndis802_11Encryption2KeyAbsent
) {
1564 wpa_printf(MSG_DEBUG
, "NDIS: TKIP encryption supported");
1565 drv
->capa
.enc
|= WPA_DRIVER_CAPA_ENC_TKIP
;
1568 if (ndis_set_encr_status(drv
, Ndis802_11Encryption1Enabled
) == 0 &&
1569 ndis_get_encr_status(drv
) == Ndis802_11Encryption1KeyAbsent
) {
1570 wpa_printf(MSG_DEBUG
, "NDIS: WEP encryption supported");
1571 drv
->capa
.enc
|= WPA_DRIVER_CAPA_ENC_WEP40
|
1572 WPA_DRIVER_CAPA_ENC_WEP104
;
1575 if (ndis_set_auth_mode(drv
, Ndis802_11AuthModeShared
) == 0 &&
1576 ndis_get_auth_mode(drv
) == Ndis802_11AuthModeShared
) {
1577 drv
->capa
.auth
|= WPA_DRIVER_AUTH_SHARED
;
1580 if (ndis_set_auth_mode(drv
, Ndis802_11AuthModeOpen
) == 0 &&
1581 ndis_get_auth_mode(drv
) == Ndis802_11AuthModeOpen
) {
1582 drv
->capa
.auth
|= WPA_DRIVER_AUTH_OPEN
;
1585 ndis_set_encr_status(drv
, Ndis802_11EncryptionDisabled
);
1587 /* Could also verify OID_802_11_ADD_KEY error reporting and
1588 * support for OID_802_11_ASSOCIATION_INFORMATION. */
1590 if (drv
->capa
.key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_WPA
&&
1591 drv
->capa
.enc
& (WPA_DRIVER_CAPA_ENC_TKIP
|
1592 WPA_DRIVER_CAPA_ENC_CCMP
)) {
1593 wpa_printf(MSG_DEBUG
, "NDIS: driver supports WPA");
1594 drv
->has_capability
= 1;
1596 wpa_printf(MSG_DEBUG
, "NDIS: no WPA support found");
1599 wpa_printf(MSG_DEBUG
, "NDIS: driver capabilities: key_mgmt 0x%x "
1600 "enc 0x%x auth 0x%x",
1601 drv
->capa
.key_mgmt
, drv
->capa
.enc
, drv
->capa
.auth
);
1605 static void wpa_driver_ndis_get_capability(struct wpa_driver_ndis_data
*drv
)
1610 NDIS_802_11_CAPABILITY
*c
;
1612 drv
->capa
.flags
= WPA_DRIVER_FLAGS_DRIVER_IE
;
1614 len
= ndis_get_oid(drv
, OID_802_11_CAPABILITY
, buf
, sizeof(buf
));
1616 wpa_driver_ndis_get_wpa_capability(drv
);
1620 wpa_hexdump(MSG_MSGDUMP
, "OID_802_11_CAPABILITY", buf
, len
);
1621 c
= (NDIS_802_11_CAPABILITY
*) buf
;
1622 if (len
< sizeof(*c
) || c
->Version
!= 2) {
1623 wpa_printf(MSG_DEBUG
, "NDIS: unsupported "
1624 "OID_802_11_CAPABILITY data");
1627 wpa_printf(MSG_DEBUG
, "NDIS: Driver supports OID_802_11_CAPABILITY - "
1628 "NoOfPMKIDs %d NoOfAuthEncrPairs %d",
1629 (int) c
->NoOfPMKIDs
,
1630 (int) c
->NoOfAuthEncryptPairsSupported
);
1631 drv
->has_capability
= 1;
1632 drv
->no_of_pmkid
= c
->NoOfPMKIDs
;
1633 for (i
= 0; i
< c
->NoOfAuthEncryptPairsSupported
; i
++) {
1634 NDIS_802_11_AUTHENTICATION_ENCRYPTION
*ae
;
1635 ae
= &c
->AuthenticationEncryptionSupported
[i
];
1636 if ((char *) (ae
+ 1) > buf
+ len
) {
1637 wpa_printf(MSG_DEBUG
, "NDIS: auth/encr pair list "
1641 wpa_printf(MSG_MSGDUMP
, "NDIS: %d - auth %d encr %d",
1642 i
, (int) ae
->AuthModeSupported
,
1643 (int) ae
->EncryptStatusSupported
);
1644 switch (ae
->AuthModeSupported
) {
1645 case Ndis802_11AuthModeOpen
:
1646 drv
->capa
.auth
|= WPA_DRIVER_AUTH_OPEN
;
1648 case Ndis802_11AuthModeShared
:
1649 drv
->capa
.auth
|= WPA_DRIVER_AUTH_SHARED
;
1651 case Ndis802_11AuthModeWPA
:
1652 drv
->capa
.key_mgmt
|= WPA_DRIVER_CAPA_KEY_MGMT_WPA
;
1654 case Ndis802_11AuthModeWPAPSK
:
1655 drv
->capa
.key_mgmt
|= WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK
;
1657 case Ndis802_11AuthModeWPA2
:
1658 drv
->capa
.key_mgmt
|= WPA_DRIVER_CAPA_KEY_MGMT_WPA2
;
1660 case Ndis802_11AuthModeWPA2PSK
:
1661 drv
->capa
.key_mgmt
|=
1662 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK
;
1664 case Ndis802_11AuthModeWPANone
:
1665 drv
->capa
.key_mgmt
|=
1666 WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE
;
1671 switch (ae
->EncryptStatusSupported
) {
1672 case Ndis802_11Encryption1Enabled
:
1673 drv
->capa
.enc
|= WPA_DRIVER_CAPA_ENC_WEP40
;
1674 drv
->capa
.enc
|= WPA_DRIVER_CAPA_ENC_WEP104
;
1676 case Ndis802_11Encryption2Enabled
:
1677 drv
->capa
.enc
|= WPA_DRIVER_CAPA_ENC_TKIP
;
1679 case Ndis802_11Encryption3Enabled
:
1680 drv
->capa
.enc
|= WPA_DRIVER_CAPA_ENC_CCMP
;
1687 wpa_printf(MSG_DEBUG
, "NDIS: driver capabilities: key_mgmt 0x%x "
1688 "enc 0x%x auth 0x%x",
1689 drv
->capa
.key_mgmt
, drv
->capa
.enc
, drv
->capa
.auth
);
1693 static int wpa_driver_ndis_get_capa(void *priv
, struct wpa_driver_capa
*capa
)
1695 struct wpa_driver_ndis_data
*drv
= priv
;
1696 if (!drv
->has_capability
)
1698 os_memcpy(capa
, &drv
->capa
, sizeof(*capa
));
1703 static const char * wpa_driver_ndis_get_ifname(void *priv
)
1705 struct wpa_driver_ndis_data
*drv
= priv
;
1710 static const u8
* wpa_driver_ndis_get_mac_addr(void *priv
)
1712 struct wpa_driver_ndis_data
*drv
= priv
;
1713 return drv
->own_addr
;
1719 #define NDISUIO_MSG_SIZE (sizeof(NDISUIO_DEVICE_NOTIFICATION) + 512)
1721 static void ndisuio_notification_receive(void *eloop_data
, void *user_ctx
)
1723 struct wpa_driver_ndis_data
*drv
= eloop_data
;
1724 NDISUIO_DEVICE_NOTIFICATION
*hdr
;
1725 u8 buf
[NDISUIO_MSG_SIZE
];
1728 if (!ReadMsgQueue(drv
->event_queue
, buf
, NDISUIO_MSG_SIZE
, &len
, 0,
1730 wpa_printf(MSG_DEBUG
, "ndisuio_notification_receive: "
1731 "ReadMsgQueue failed: %d", (int) GetLastError());
1735 if (len
< sizeof(NDISUIO_DEVICE_NOTIFICATION
)) {
1736 wpa_printf(MSG_DEBUG
, "ndisuio_notification_receive: "
1737 "Too short message (len=%d)", (int) len
);
1741 hdr
= (NDISUIO_DEVICE_NOTIFICATION
*) buf
;
1742 wpa_printf(MSG_DEBUG
, "NDIS: Notification received: len=%d type=0x%x",
1743 (int) len
, hdr
->dwNotificationType
);
1745 switch (hdr
->dwNotificationType
) {
1746 #ifdef NDISUIO_NOTIFICATION_ADAPTER_ARRIVAL
1747 case NDISUIO_NOTIFICATION_ADAPTER_ARRIVAL
:
1748 wpa_printf(MSG_DEBUG
, "NDIS: ADAPTER_ARRIVAL");
1749 wpa_driver_ndis_event_adapter_arrival(drv
);
1752 #ifdef NDISUIO_NOTIFICATION_ADAPTER_REMOVAL
1753 case NDISUIO_NOTIFICATION_ADAPTER_REMOVAL
:
1754 wpa_printf(MSG_DEBUG
, "NDIS: ADAPTER_REMOVAL");
1755 wpa_driver_ndis_event_adapter_removal(drv
);
1758 case NDISUIO_NOTIFICATION_MEDIA_CONNECT
:
1759 wpa_printf(MSG_DEBUG
, "NDIS: MEDIA_CONNECT");
1760 SetEvent(drv
->connected_event
);
1761 wpa_driver_ndis_event_connect(drv
);
1763 case NDISUIO_NOTIFICATION_MEDIA_DISCONNECT
:
1764 ResetEvent(drv
->connected_event
);
1765 wpa_printf(MSG_DEBUG
, "NDIS: MEDIA_DISCONNECT");
1766 wpa_driver_ndis_event_disconnect(drv
);
1768 case NDISUIO_NOTIFICATION_MEDIA_SPECIFIC_NOTIFICATION
:
1769 wpa_printf(MSG_DEBUG
, "NDIS: MEDIA_SPECIFIC_NOTIFICATION");
1770 #if _WIN32_WCE == 420 || _WIN32_WCE == 0x420
1771 wpa_driver_ndis_event_media_specific(
1772 drv
, hdr
->pvStatusBuffer
, hdr
->uiStatusBufferSize
);
1774 wpa_driver_ndis_event_media_specific(
1775 drv
, ((const u8
*) hdr
) + hdr
->uiOffsetToStatusBuffer
,
1776 (size_t) hdr
->uiStatusBufferSize
);
1780 wpa_printf(MSG_DEBUG
, "NDIS: Unknown notification type 0x%x",
1781 hdr
->dwNotificationType
);
1787 static void ndisuio_notification_deinit(struct wpa_driver_ndis_data
*drv
)
1789 NDISUIO_REQUEST_NOTIFICATION req
;
1791 memset(&req
, 0, sizeof(req
));
1792 req
.hMsgQueue
= drv
->event_queue
;
1793 req
.dwNotificationTypes
= 0;
1795 if (!DeviceIoControl(drv
->ndisuio
, IOCTL_NDISUIO_REQUEST_NOTIFICATION
,
1796 &req
, sizeof(req
), NULL
, 0, NULL
, NULL
)) {
1797 wpa_printf(MSG_INFO
, "ndisuio_notification_deinit: "
1798 "IOCTL_NDISUIO_REQUEST_NOTIFICATION failed: %d",
1799 (int) GetLastError());
1802 if (!DeviceIoControl(drv
->ndisuio
, IOCTL_NDISUIO_CANCEL_NOTIFICATION
,
1803 NULL
, 0, NULL
, 0, NULL
, NULL
)) {
1804 wpa_printf(MSG_INFO
, "ndisuio_notification_deinit: "
1805 "IOCTL_NDISUIO_CANCEL_NOTIFICATION failed: %d",
1806 (int) GetLastError());
1809 if (drv
->event_queue
) {
1810 eloop_unregister_event(drv
->event_queue
,
1811 sizeof(drv
->event_queue
));
1812 CloseHandle(drv
->event_queue
);
1813 drv
->event_queue
= NULL
;
1816 if (drv
->connected_event
) {
1817 CloseHandle(drv
->connected_event
);
1818 drv
->connected_event
= NULL
;
1823 static int ndisuio_notification_init(struct wpa_driver_ndis_data
*drv
)
1825 MSGQUEUEOPTIONS opt
;
1826 NDISUIO_REQUEST_NOTIFICATION req
;
1828 drv
->connected_event
=
1829 CreateEvent(NULL
, TRUE
, FALSE
, TEXT("WpaSupplicantConnected"));
1830 if (drv
->connected_event
== NULL
) {
1831 wpa_printf(MSG_INFO
, "ndisuio_notification_init: "
1832 "CreateEvent failed: %d",
1833 (int) GetLastError());
1837 memset(&opt
, 0, sizeof(opt
));
1838 opt
.dwSize
= sizeof(opt
);
1839 opt
.dwMaxMessages
= 5;
1840 opt
.cbMaxMessage
= NDISUIO_MSG_SIZE
;
1841 opt
.bReadAccess
= TRUE
;
1843 drv
->event_queue
= CreateMsgQueue(NULL
, &opt
);
1844 if (drv
->event_queue
== NULL
) {
1845 wpa_printf(MSG_INFO
, "ndisuio_notification_init: "
1846 "CreateMsgQueue failed: %d",
1847 (int) GetLastError());
1848 ndisuio_notification_deinit(drv
);
1852 memset(&req
, 0, sizeof(req
));
1853 req
.hMsgQueue
= drv
->event_queue
;
1854 req
.dwNotificationTypes
=
1855 #ifdef NDISUIO_NOTIFICATION_ADAPTER_ARRIVAL
1856 NDISUIO_NOTIFICATION_ADAPTER_ARRIVAL
|
1858 #ifdef NDISUIO_NOTIFICATION_ADAPTER_REMOVAL
1859 NDISUIO_NOTIFICATION_ADAPTER_REMOVAL
|
1861 NDISUIO_NOTIFICATION_MEDIA_CONNECT
|
1862 NDISUIO_NOTIFICATION_MEDIA_DISCONNECT
|
1863 NDISUIO_NOTIFICATION_MEDIA_SPECIFIC_NOTIFICATION
;
1865 if (!DeviceIoControl(drv
->ndisuio
, IOCTL_NDISUIO_REQUEST_NOTIFICATION
,
1866 &req
, sizeof(req
), NULL
, 0, NULL
, NULL
)) {
1867 wpa_printf(MSG_INFO
, "ndisuio_notification_init: "
1868 "IOCTL_NDISUIO_REQUEST_NOTIFICATION failed: %d",
1869 (int) GetLastError());
1870 ndisuio_notification_deinit(drv
);
1874 eloop_register_event(drv
->event_queue
, sizeof(drv
->event_queue
),
1875 ndisuio_notification_receive
, drv
, NULL
);
1879 #endif /* _WIN32_WCE */
1882 static int wpa_driver_ndis_get_names(struct wpa_driver_ndis_data
*drv
)
1884 #ifdef CONFIG_USE_NDISUIO
1885 NDISUIO_QUERY_BINDING
*b
;
1886 size_t blen
= sizeof(*b
) + 1024;
1887 int i
, error
, found
= 0;
1889 char name
[256], desc
[256], *dpos
;
1891 size_t j
, len
, dlen
;
1893 b
= os_malloc(blen
);
1897 for (i
= 0; ; i
++) {
1898 os_memset(b
, 0, blen
);
1899 b
->BindingIndex
= i
;
1900 if (!DeviceIoControl(drv
->ndisuio
, IOCTL_NDISUIO_QUERY_BINDING
,
1901 b
, sizeof(NDISUIO_QUERY_BINDING
), b
, blen
,
1903 error
= (int) GetLastError();
1904 if (error
== ERROR_NO_MORE_ITEMS
)
1906 wpa_printf(MSG_DEBUG
, "IOCTL_NDISUIO_QUERY_BINDING "
1907 "failed: %d", error
);
1911 pos
= (WCHAR
*) ((char *) b
+ b
->DeviceNameOffset
);
1912 len
= b
->DeviceNameLength
;
1913 if (len
>= sizeof(name
))
1914 len
= sizeof(name
) - 1;
1915 for (j
= 0; j
< len
; j
++)
1916 name
[j
] = (char) pos
[j
];
1919 pos
= (WCHAR
*) ((char *) b
+ b
->DeviceDescrOffset
);
1920 len
= b
->DeviceDescrLength
;
1921 if (len
>= sizeof(desc
))
1922 len
= sizeof(desc
) - 1;
1923 for (j
= 0; j
< len
; j
++)
1924 desc
[j
] = (char) pos
[j
];
1927 wpa_printf(MSG_DEBUG
, "NDIS: %d - %s - %s", i
, name
, desc
);
1929 if (os_strstr(name
, drv
->ifname
)) {
1930 wpa_printf(MSG_DEBUG
, "NDIS: Interface name match");
1935 if (os_strncmp(desc
, drv
->ifname
, os_strlen(drv
->ifname
)) == 0)
1937 wpa_printf(MSG_DEBUG
, "NDIS: Interface description "
1945 wpa_printf(MSG_DEBUG
, "NDIS: Could not find interface '%s'",
1951 os_strlcpy(drv
->ifname
,
1952 os_strncmp(name
, "\\DEVICE\\", 8) == 0 ? name
+ 8 : name
,
1953 sizeof(drv
->ifname
));
1955 drv
->adapter_name
= wpa_strdup_tchar(drv
->ifname
);
1956 if (drv
->adapter_name
== NULL
) {
1957 wpa_printf(MSG_ERROR
, "NDIS: Failed to allocate memory for "
1962 #endif /* _WIN32_WCE */
1964 dpos
= os_strstr(desc
, " - ");
1968 dlen
= os_strlen(desc
);
1969 drv
->adapter_desc
= os_malloc(dlen
+ 1);
1970 if (drv
->adapter_desc
) {
1971 os_memcpy(drv
->adapter_desc
, desc
, dlen
);
1972 drv
->adapter_desc
[dlen
] = '\0';
1977 if (drv
->adapter_desc
== NULL
)
1980 wpa_printf(MSG_DEBUG
, "NDIS: Adapter description prefix '%s'",
1984 #else /* CONFIG_USE_NDISUIO */
1986 char *names
, *pos
, *pos2
;
1989 #define MAX_ADAPTERS 32
1990 char *name
[MAX_ADAPTERS
];
1991 char *desc
[MAX_ADAPTERS
];
1992 int num_name
, num_desc
, i
, found_name
, found_desc
;
1995 wpa_printf(MSG_DEBUG
, "NDIS: Packet.dll version: %s",
1996 PacketGetVersion());
1999 _names
= os_zalloc(len
);
2003 res
= PacketGetAdapterNames(_names
, &len
);
2004 if (!res
&& len
> 8192) {
2006 _names
= os_zalloc(len
);
2009 res
= PacketGetAdapterNames(_names
, &len
);
2013 wpa_printf(MSG_ERROR
, "NDIS: Failed to get adapter list "
2014 "(PacketGetAdapterNames)");
2019 names
= (char *) _names
;
2020 if (names
[0] && names
[1] == '\0' && names
[2] && names
[3] == '\0') {
2021 wpa_printf(MSG_DEBUG
, "NDIS: Looks like adapter names are in "
2023 /* Convert to ASCII */
2025 while (pos2
< names
+ len
) {
2026 if (pos2
[0] == '\0' && pos2
[1] == '\0' &&
2027 pos2
[2] == '\0' && pos2
[3] == '\0') {
2034 os_memcpy(pos
+ 2, names
, pos
- names
);
2040 while (pos
< names
+ len
) {
2041 name
[num_name
] = pos
;
2042 while (*pos
&& pos
< names
+ len
)
2044 if (pos
+ 1 >= names
+ len
) {
2050 if (num_name
>= MAX_ADAPTERS
) {
2051 wpa_printf(MSG_DEBUG
, "NDIS: Too many adapters");
2056 wpa_printf(MSG_DEBUG
, "NDIS: %d adapter names found",
2064 while (pos
< names
+ len
) {
2065 desc
[num_desc
] = pos
;
2066 while (*pos
&& pos
< names
+ len
)
2068 if (pos
+ 1 >= names
+ len
) {
2074 if (num_desc
>= MAX_ADAPTERS
) {
2075 wpa_printf(MSG_DEBUG
, "NDIS: Too many adapter "
2081 wpa_printf(MSG_DEBUG
, "NDIS: %d adapter descriptions "
2089 * Windows 98 with Packet.dll 3.0 alpha3 does not include adapter
2090 * descriptions. Fill in dummy descriptors to work around this.
2092 while (num_desc
< num_name
)
2093 desc
[num_desc
++] = "dummy description";
2095 if (num_name
!= num_desc
) {
2096 wpa_printf(MSG_DEBUG
, "NDIS: mismatch in adapter name and "
2097 "description counts (%d != %d)",
2098 num_name
, num_desc
);
2103 found_name
= found_desc
= -1;
2104 for (i
= 0; i
< num_name
; i
++) {
2105 wpa_printf(MSG_DEBUG
, "NDIS: %d - %s - %s",
2106 i
, name
[i
], desc
[i
]);
2107 if (found_name
== -1 && os_strstr(name
[i
], drv
->ifname
))
2109 if (found_desc
== -1 &&
2110 os_strncmp(desc
[i
], drv
->ifname
, os_strlen(drv
->ifname
)) ==
2115 if (found_name
< 0 && found_desc
>= 0) {
2116 wpa_printf(MSG_DEBUG
, "NDIS: Matched interface '%s' based on "
2118 name
[found_desc
], desc
[found_desc
]);
2119 found_name
= found_desc
;
2120 os_strlcpy(drv
->ifname
,
2121 os_strncmp(name
[found_desc
], "\\Device\\NPF_", 12)
2122 == 0 ? name
[found_desc
] + 12 : name
[found_desc
],
2123 sizeof(drv
->ifname
));
2126 if (found_name
< 0) {
2127 wpa_printf(MSG_DEBUG
, "NDIS: Could not find interface '%s'",
2134 pos
= os_strrchr(desc
[i
], '(');
2136 dlen
= pos
- desc
[i
];
2138 if (pos
> desc
[i
] && *pos
== ' ')
2141 dlen
= os_strlen(desc
[i
]);
2143 drv
->adapter_desc
= os_malloc(dlen
+ 1);
2144 if (drv
->adapter_desc
) {
2145 os_memcpy(drv
->adapter_desc
, desc
[i
], dlen
);
2146 drv
->adapter_desc
[dlen
] = '\0';
2151 if (drv
->adapter_desc
== NULL
)
2154 wpa_printf(MSG_DEBUG
, "NDIS: Adapter description prefix '%s'",
2158 #endif /* CONFIG_USE_NDISUIO */
2162 #if defined(CONFIG_NATIVE_WINDOWS) || defined(__CYGWIN__)
2165 * These structures are undocumented for WinXP; only WinCE version is
2166 * documented. These would be included wzcsapi.h if it were available. Some
2167 * changes here have been needed to make the structures match with WinXP SP2.
2168 * It is unclear whether these work with any other version.
2173 } INTF_KEY_ENTRY
, *PINTF_KEY_ENTRY
;
2177 PINTF_KEY_ENTRY pIntfs
;
2178 } INTFS_KEY_TABLE
, *PINTFS_KEY_TABLE
;
2183 } RAW_DATA
, *PRAW_DATA
;
2190 ULONG ulPhysicalMediaType
;
2195 u8 pad
[2]; /* why is this needed? */
2196 #endif /* _WIN32_WCE */
2198 DWORD dwCapabilities
; /* something added for WinXP SP2(?) */
2201 RAW_DATA rdBSSIDList
;
2202 RAW_DATA rdStSSIDList
;
2203 RAW_DATA rdCtrlData
;
2207 DWORD nWPAMCastCipher
;
2208 /* add some extra buffer for later additions since this interface is
2209 * far from stable */
2210 u8 later_additions
[100];
2211 } INTF_ENTRY
, *PINTF_ENTRY
;
2213 #define INTF_ALL 0xffffffff
2214 #define INTF_ALL_FLAGS 0x0000ffff
2215 #define INTF_CTLFLAGS 0x00000010
2216 #define INTFCTL_ENABLED 0x8000
2217 #endif /* _WIN32_WCE */
2221 static int wpa_driver_ndis_rebind_adapter(struct wpa_driver_ndis_data
*drv
)
2227 len
= _tcslen(drv
->adapter_name
);
2231 ndis
= CreateFile(DD_NDIS_DEVICE_NAME
, GENERIC_READ
| GENERIC_WRITE
,
2232 0, NULL
, OPEN_EXISTING
, 0, NULL
);
2233 if (ndis
== INVALID_HANDLE_VALUE
) {
2234 wpa_printf(MSG_DEBUG
, "NDIS: Failed to open file to NDIS "
2235 "device: %d", (int) GetLastError());
2240 memcpy(multi
, drv
->adapter_name
, len
* sizeof(TCHAR
));
2241 memcpy(&multi
[len
], TEXT("NDISUIO\0"), 9 * sizeof(TCHAR
));
2244 if (!DeviceIoControl(ndis
, IOCTL_NDIS_REBIND_ADAPTER
,
2245 multi
, len
* sizeof(TCHAR
), NULL
, 0, NULL
, NULL
))
2247 wpa_printf(MSG_DEBUG
, "NDIS: IOCTL_NDIS_REBIND_ADAPTER "
2248 "failed: 0x%x", (int) GetLastError());
2249 wpa_hexdump_ascii(MSG_DEBUG
, "NDIS: rebind multi_sz",
2250 (u8
*) multi
, len
* sizeof(TCHAR
));
2257 wpa_printf(MSG_DEBUG
, "NDIS: Requested NDIS rebind of NDISUIO "
2262 #endif /* _WIN32_WCE */
2265 static int wpa_driver_ndis_set_wzc(struct wpa_driver_ndis_data
*drv
,
2272 TCHAR keyname
[256], devname
[256];
2274 #define WZC_DRIVER TEXT("Drivers\\BuiltIn\\ZeroConfig")
2278 h
= ActivateDeviceEx(WZC_DRIVER
, NULL
, 0, NULL
);
2279 if (h
== INVALID_HANDLE_VALUE
|| h
== 0) {
2280 wpa_printf(MSG_DEBUG
, "NDIS: Failed to re-enable WZC "
2281 "- ActivateDeviceEx failed: %d",
2282 (int) GetLastError());
2286 wpa_printf(MSG_DEBUG
, "NDIS: WZC re-enabled");
2287 return wpa_driver_ndis_rebind_adapter(drv
);
2291 * Unfortunately, just disabling the WZC for an interface is not enough
2292 * to free NDISUIO for us, so need to disable and unload WZC completely
2293 * for now when using WinCE with NDISUIO. In addition, must request
2294 * NDISUIO protocol to be rebound to the adapter in order to free the
2295 * NDISUIO binding that WZC hold before us.
2298 /* Enumerate HKLM\Drivers\Active\* to find a handle to WZC. */
2299 ret
= RegOpenKeyEx(HKEY_LOCAL_MACHINE
, DEVLOAD_ACTIVE_KEY
, 0, 0, &hk
);
2300 if (ret
!= ERROR_SUCCESS
) {
2301 wpa_printf(MSG_DEBUG
, "NDIS: RegOpenKeyEx(DEVLOAD_ACTIVE_KEY) "
2302 "failed: %d %d", (int) ret
, (int) GetLastError());
2306 for (i
= 0; ; i
++) {
2307 len
= sizeof(keyname
);
2308 ret
= RegEnumKeyEx(hk
, i
, keyname
, &len
, NULL
, NULL
, NULL
,
2310 if (ret
!= ERROR_SUCCESS
) {
2311 wpa_printf(MSG_DEBUG
, "NDIS: Could not find active "
2312 "WZC - assuming it is not running.");
2317 ret
= RegOpenKeyEx(hk
, keyname
, 0, 0, &hk2
);
2318 if (ret
!= ERROR_SUCCESS
) {
2319 wpa_printf(MSG_DEBUG
, "NDIS: RegOpenKeyEx(active dev) "
2321 (int) ret
, (int) GetLastError());
2325 len
= sizeof(devname
);
2326 ret
= RegQueryValueEx(hk2
, DEVLOAD_DEVKEY_VALNAME
, NULL
, NULL
,
2327 (LPBYTE
) devname
, &len
);
2328 if (ret
!= ERROR_SUCCESS
) {
2329 wpa_printf(MSG_DEBUG
, "NDIS: RegQueryValueEx("
2330 "DEVKEY_VALNAME) failed: %d %d",
2331 (int) ret
, (int) GetLastError());
2336 if (_tcscmp(devname
, WZC_DRIVER
) == 0)
2344 /* Found WZC - get handle to it. */
2346 ret
= RegQueryValueEx(hk2
, DEVLOAD_HANDLE_VALNAME
, NULL
, NULL
,
2347 (PUCHAR
) &hnd
, &len
);
2348 if (ret
!= ERROR_SUCCESS
) {
2349 wpa_printf(MSG_DEBUG
, "NDIS: RegQueryValueEx(HANDLE_VALNAME) "
2350 "failed: %d %d", (int) ret
, (int) GetLastError());
2357 /* Deactivate WZC */
2358 if (!DeactivateDevice((HANDLE
) hnd
)) {
2359 wpa_printf(MSG_DEBUG
, "NDIS: DeactivateDevice failed: %d",
2360 (int) GetLastError());
2364 wpa_printf(MSG_DEBUG
, "NDIS: Disabled WZC temporarily");
2365 drv
->wzc_disabled
= 1;
2366 return wpa_driver_ndis_rebind_adapter(drv
);
2368 #else /* _WIN32_WCE */
2371 DWORD (WINAPI
*wzc_enum_interf
)(LPWSTR pSrvAddr
,
2372 PINTFS_KEY_TABLE pIntfs
);
2373 DWORD (WINAPI
*wzc_query_interf
)(LPWSTR pSrvAddr
, DWORD dwInFlags
,
2375 LPDWORD pdwOutFlags
);
2376 DWORD (WINAPI
*wzc_set_interf
)(LPWSTR pSrvAddr
, DWORD dwInFlags
,
2377 PINTF_ENTRY pIntf
, LPDWORD pdwOutFlags
);
2380 INTFS_KEY_TABLE guids
;
2386 hm
= LoadLibrary(TEXT("wzcsapi.dll"));
2388 wpa_printf(MSG_DEBUG
, "NDIS: Failed to load wzcsapi.dll (%u) "
2389 "- WZC probably not running",
2390 (unsigned int) GetLastError());
2395 wzc_enum_interf
= (void *) GetProcAddressA(hm
, "WZCEnumInterfaces");
2396 wzc_query_interf
= (void *) GetProcAddressA(hm
, "WZCQueryInterface");
2397 wzc_set_interf
= (void *) GetProcAddressA(hm
, "WZCSetInterface");
2398 #else /* _WIN32_WCE */
2399 wzc_enum_interf
= (void *) GetProcAddress(hm
, "WZCEnumInterfaces");
2400 wzc_query_interf
= (void *) GetProcAddress(hm
, "WZCQueryInterface");
2401 wzc_set_interf
= (void *) GetProcAddress(hm
, "WZCSetInterface");
2402 #endif /* _WIN32_WCE */
2404 if (wzc_enum_interf
== NULL
|| wzc_query_interf
== NULL
||
2405 wzc_set_interf
== NULL
) {
2406 wpa_printf(MSG_DEBUG
, "NDIS: WZCEnumInterfaces, "
2407 "WZCQueryInterface, or WZCSetInterface not found "
2412 os_memset(&guids
, 0, sizeof(guids
));
2413 res
= wzc_enum_interf(NULL
, &guids
);
2415 wpa_printf(MSG_DEBUG
, "NDIS: WZCEnumInterfaces failed: %d; "
2416 "WZC service is apparently not running",
2421 wpa_printf(MSG_DEBUG
, "NDIS: WZCEnumInterfaces: %d interfaces",
2422 (int) guids
.dwNumIntfs
);
2424 for (i
= 0; i
< guids
.dwNumIntfs
; i
++) {
2425 pos
= guids
.pIntfs
[i
].wszGuid
;
2426 for (j
= 0; j
< sizeof(guid
); j
++) {
2427 guid
[j
] = (char) *pos
;
2432 guid
[sizeof(guid
) - 1] = '\0';
2433 wpa_printf(MSG_DEBUG
, "NDIS: intfs %d GUID '%s'",
2435 if (os_strstr(drv
->ifname
, guid
) == NULL
)
2438 wpa_printf(MSG_DEBUG
, "NDIS: Current interface found from "
2443 if (i
>= guids
.dwNumIntfs
) {
2444 wpa_printf(MSG_DEBUG
, "NDIS: Current interface not found from "
2449 os_memset(&intf
, 0, sizeof(intf
));
2450 intf
.wszGuid
= guids
.pIntfs
[i
].wszGuid
;
2451 /* Set flags to verify that the structure has not changed. */
2452 intf
.dwCtlFlags
= -1;
2454 res
= wzc_query_interf(NULL
, INTFCTL_ENABLED
, &intf
, &flags
);
2456 wpa_printf(MSG_DEBUG
, "NDIS: Could not query flags for the "
2457 "WZC interface: %d (0x%x)",
2458 (int) res
, (int) res
);
2459 wpa_printf(MSG_DEBUG
, "NDIS: GetLastError: %u",
2460 (unsigned int) GetLastError());
2464 wpa_printf(MSG_DEBUG
, "NDIS: WZC interface flags 0x%x dwCtlFlags 0x%x",
2465 (int) flags
, (int) intf
.dwCtlFlags
);
2467 if (intf
.dwCtlFlags
== -1) {
2468 wpa_printf(MSG_DEBUG
, "NDIS: Looks like wzcsapi has changed "
2469 "again - could not disable WZC");
2470 wpa_hexdump(MSG_MSGDUMP
, "NDIS: intf",
2471 (u8
*) &intf
, sizeof(intf
));
2476 if (!(intf
.dwCtlFlags
& INTFCTL_ENABLED
)) {
2477 wpa_printf(MSG_DEBUG
, "NDIS: Enabling WZC for this "
2479 intf
.dwCtlFlags
|= INTFCTL_ENABLED
;
2480 res
= wzc_set_interf(NULL
, INTFCTL_ENABLED
, &intf
,
2483 wpa_printf(MSG_DEBUG
, "NDIS: Failed to enable "
2485 (int) res
, (int) res
);
2486 wpa_printf(MSG_DEBUG
, "NDIS: GetLastError: %u",
2487 (unsigned int) GetLastError());
2490 wpa_printf(MSG_DEBUG
, "NDIS: Re-enabled WZC for this "
2492 drv
->wzc_disabled
= 0;
2495 if (intf
.dwCtlFlags
& INTFCTL_ENABLED
) {
2496 wpa_printf(MSG_DEBUG
, "NDIS: Disabling WZC for this "
2498 intf
.dwCtlFlags
&= ~INTFCTL_ENABLED
;
2499 res
= wzc_set_interf(NULL
, INTFCTL_ENABLED
, &intf
,
2502 wpa_printf(MSG_DEBUG
, "NDIS: Failed to "
2503 "disable WZC: %d (0x%x)",
2504 (int) res
, (int) res
);
2505 wpa_printf(MSG_DEBUG
, "NDIS: GetLastError: %u",
2506 (unsigned int) GetLastError());
2509 wpa_printf(MSG_DEBUG
, "NDIS: Disabled WZC temporarily "
2510 "for this interface");
2511 drv
->wzc_disabled
= 1;
2513 wpa_printf(MSG_DEBUG
, "NDIS: WZC was not enabled for "
2524 #endif /* _WIN32_WCE */
2527 #else /* CONFIG_NATIVE_WINDOWS || __CYGWIN__ */
2529 static int wpa_driver_ndis_set_wzc(struct wpa_driver_ndis_data
*drv
,
2535 #endif /* CONFIG_NATIVE_WINDOWS || __CYGWIN__ */
2538 #ifdef CONFIG_USE_NDISUIO
2540 * l2_packet_ndis.c is sharing the same handle to NDISUIO, so we must be able
2541 * to export this handle. This is somewhat ugly, but there is no better
2542 * mechanism available to pass data from driver interface to l2_packet wrapper.
2544 static HANDLE driver_ndis_ndisuio_handle
= INVALID_HANDLE_VALUE
;
2546 HANDLE
driver_ndis_get_ndisuio_handle(void)
2548 return driver_ndis_ndisuio_handle
;
2550 #endif /* CONFIG_USE_NDISUIO */
2553 static int wpa_driver_ndis_adapter_init(struct wpa_driver_ndis_data
*drv
)
2555 #ifdef CONFIG_USE_NDISUIO
2557 #define NDISUIO_DEVICE_NAME TEXT("\\\\.\\\\Ndisuio")
2559 #endif /* _WIN32_WCE */
2560 drv
->ndisuio
= CreateFile(NDISUIO_DEVICE_NAME
,
2561 GENERIC_READ
| GENERIC_WRITE
, 0, NULL
,
2563 FILE_ATTRIBUTE_NORMAL
| FILE_FLAG_OVERLAPPED
,
2564 INVALID_HANDLE_VALUE
);
2565 if (drv
->ndisuio
== INVALID_HANDLE_VALUE
) {
2566 wpa_printf(MSG_ERROR
, "NDIS: Failed to open connection to "
2567 "NDISUIO: %d", (int) GetLastError());
2570 driver_ndis_ndisuio_handle
= drv
->ndisuio
;
2573 if (!DeviceIoControl(drv
->ndisuio
, IOCTL_NDISUIO_BIND_WAIT
, NULL
, 0,
2574 NULL
, 0, &written
, NULL
)) {
2575 wpa_printf(MSG_ERROR
, "NDIS: IOCTL_NDISUIO_BIND_WAIT failed: "
2576 "%d", (int) GetLastError());
2577 CloseHandle(drv
->ndisuio
);
2578 drv
->ndisuio
= INVALID_HANDLE_VALUE
;
2581 #endif /* _WIN32_WCE */
2584 #else /* CONFIG_USE_NDISUIO */
2586 #endif /* CONFIG_USE_NDISUIO */
2590 static int wpa_driver_ndis_adapter_open(struct wpa_driver_ndis_data
*drv
)
2592 #ifdef CONFIG_USE_NDISUIO
2594 #define MAX_NDIS_DEVICE_NAME_LEN 256
2595 WCHAR ifname
[MAX_NDIS_DEVICE_NAME_LEN
];
2597 const char *prefix
= "\\DEVICE\\";
2601 #else /* _WIN32_WCE */
2603 #endif /* _WIN32_WCE */
2604 len
= pos
+ os_strlen(drv
->ifname
);
2605 if (len
>= MAX_NDIS_DEVICE_NAME_LEN
)
2607 for (i
= 0; i
< pos
; i
++)
2608 ifname
[i
] = (WCHAR
) prefix
[i
];
2609 for (i
= pos
; i
< len
; i
++)
2610 ifname
[i
] = (WCHAR
) drv
->ifname
[i
- pos
];
2613 if (!DeviceIoControl(drv
->ndisuio
, IOCTL_NDISUIO_OPEN_DEVICE
,
2614 ifname
, len
* sizeof(WCHAR
), NULL
, 0, &written
,
2616 wpa_printf(MSG_ERROR
, "NDIS: IOCTL_NDISUIO_OPEN_DEVICE "
2617 "failed: %d", (int) GetLastError());
2618 wpa_hexdump_ascii(MSG_DEBUG
, "NDIS: ifname",
2619 (const u8
*) ifname
, len
* sizeof(WCHAR
));
2620 CloseHandle(drv
->ndisuio
);
2621 drv
->ndisuio
= INVALID_HANDLE_VALUE
;
2625 wpa_printf(MSG_DEBUG
, "NDIS: Opened NDISUIO device successfully");
2628 #else /* CONFIG_USE_NDISUIO */
2630 os_snprintf(ifname
, sizeof(ifname
), "\\Device\\NPF_%s", drv
->ifname
);
2631 drv
->adapter
= PacketOpenAdapter(ifname
);
2632 if (drv
->adapter
== NULL
) {
2633 wpa_printf(MSG_DEBUG
, "NDIS: PacketOpenAdapter failed for "
2638 #endif /* CONFIG_USE_NDISUIO */
2642 static void wpa_driver_ndis_adapter_close(struct wpa_driver_ndis_data
*drv
)
2644 #ifdef CONFIG_USE_NDISUIO
2645 driver_ndis_ndisuio_handle
= INVALID_HANDLE_VALUE
;
2646 if (drv
->ndisuio
!= INVALID_HANDLE_VALUE
)
2647 CloseHandle(drv
->ndisuio
);
2648 #else /* CONFIG_USE_NDISUIO */
2650 PacketCloseAdapter(drv
->adapter
);
2651 #endif /* CONFIG_USE_NDISUIO */
2655 static void * wpa_driver_ndis_init(void *ctx
, const char *ifname
)
2657 struct wpa_driver_ndis_data
*drv
;
2660 drv
= os_zalloc(sizeof(*drv
));
2665 * Compatibility code to strip possible prefix from the GUID. Previous
2666 * versions include \Device\NPF_ prefix for all names, but the internal
2667 * interface name is now only the GUI. Both Packet32 and NDISUIO
2668 * prefixes are supported.
2670 if (os_strncmp(ifname
, "\\Device\\NPF_", 12) == 0)
2672 else if (os_strncmp(ifname
, "\\DEVICE\\", 8) == 0)
2674 os_strlcpy(drv
->ifname
, ifname
, sizeof(drv
->ifname
));
2676 if (wpa_driver_ndis_adapter_init(drv
) < 0) {
2681 if (wpa_driver_ndis_get_names(drv
) < 0) {
2682 wpa_driver_ndis_adapter_close(drv
);
2687 wpa_driver_ndis_set_wzc(drv
, 0);
2689 if (wpa_driver_ndis_adapter_open(drv
) < 0) {
2690 wpa_driver_ndis_adapter_close(drv
);
2695 if (ndis_get_oid(drv
, OID_802_3_CURRENT_ADDRESS
,
2696 drv
->own_addr
, ETH_ALEN
) < 0) {
2697 wpa_printf(MSG_DEBUG
, "NDIS: Get OID_802_3_CURRENT_ADDRESS "
2699 wpa_driver_ndis_adapter_close(drv
);
2703 wpa_driver_ndis_get_capability(drv
);
2705 /* Make sure that the driver does not have any obsolete PMKID entries.
2707 wpa_driver_ndis_flush_pmkid(drv
);
2710 * Disconnect to make sure that driver re-associates if it was
2713 wpa_driver_ndis_disconnect(drv
);
2715 eloop_register_timeout(1, 0, wpa_driver_ndis_poll_timeout
, drv
, NULL
);
2717 #ifdef CONFIG_NDIS_EVENTS_INTEGRATED
2718 drv
->events
= ndis_events_init(&drv
->events_pipe
, &drv
->event_avail
,
2719 drv
->ifname
, drv
->adapter_desc
);
2720 if (drv
->events
== NULL
) {
2721 wpa_driver_ndis_deinit(drv
);
2724 eloop_register_event(drv
->event_avail
, sizeof(drv
->event_avail
),
2725 wpa_driver_ndis_event_pipe_cb
, drv
, NULL
);
2726 #endif /* CONFIG_NDIS_EVENTS_INTEGRATED */
2729 if (ndisuio_notification_init(drv
) < 0) {
2730 wpa_driver_ndis_deinit(drv
);
2733 #endif /* _WIN32_WCE */
2735 /* Set mode here in case card was configured for ad-hoc mode
2737 mode
= Ndis802_11Infrastructure
;
2738 if (ndis_set_oid(drv
, OID_802_11_INFRASTRUCTURE_MODE
,
2739 (char *) &mode
, sizeof(mode
)) < 0) {
2740 wpa_printf(MSG_DEBUG
, "NDIS: Failed to set "
2741 "OID_802_11_INFRASTRUCTURE_MODE (%d)",
2743 /* Try to continue anyway */
2745 if (!drv
->has_capability
&& drv
->capa
.enc
== 0) {
2746 wpa_printf(MSG_DEBUG
, "NDIS: Driver did not provide "
2747 "any wireless capabilities - assume it is "
2748 "a wired interface");
2757 static void wpa_driver_ndis_deinit(void *priv
)
2759 struct wpa_driver_ndis_data
*drv
= priv
;
2761 #ifdef CONFIG_NDIS_EVENTS_INTEGRATED
2763 eloop_unregister_event(drv
->event_avail
,
2764 sizeof(drv
->event_avail
));
2765 ndis_events_deinit(drv
->events
);
2767 #endif /* CONFIG_NDIS_EVENTS_INTEGRATED */
2770 ndisuio_notification_deinit(drv
);
2771 #endif /* _WIN32_WCE */
2773 eloop_cancel_timeout(wpa_driver_ndis_scan_timeout
, drv
, drv
->ctx
);
2774 eloop_cancel_timeout(wpa_driver_ndis_poll_timeout
, drv
, NULL
);
2775 wpa_driver_ndis_flush_pmkid(drv
);
2776 wpa_driver_ndis_disconnect(drv
);
2777 if (wpa_driver_ndis_radio_off(drv
) < 0) {
2778 wpa_printf(MSG_DEBUG
, "NDIS: failed to disassociate and turn "
2782 wpa_driver_ndis_adapter_close(drv
);
2784 if (drv
->wzc_disabled
)
2785 wpa_driver_ndis_set_wzc(drv
, 1);
2788 os_free(drv
->adapter_name
);
2789 #endif /* _WIN32_WCE */
2790 os_free(drv
->adapter_desc
);
2795 const struct wpa_driver_ops wpa_driver_ndis_ops
= {
2797 "Windows NDIS driver",
2798 wpa_driver_ndis_get_bssid
,
2799 wpa_driver_ndis_get_ssid
,
2800 wpa_driver_ndis_set_wpa
,
2801 wpa_driver_ndis_set_key
,
2802 wpa_driver_ndis_init
,
2803 wpa_driver_ndis_deinit
,
2804 NULL
/* set_param */,
2805 NULL
/* set_countermeasures */,
2806 NULL
/* set_drop_unencrypted */,
2807 wpa_driver_ndis_scan
,
2808 NULL
/* get_scan_results */,
2809 wpa_driver_ndis_deauthenticate
,
2810 wpa_driver_ndis_disassociate
,
2811 wpa_driver_ndis_associate
,
2812 NULL
/* set_auth_alg */,
2813 wpa_driver_ndis_add_pmkid
,
2814 wpa_driver_ndis_remove_pmkid
,
2815 wpa_driver_ndis_flush_pmkid
,
2816 wpa_driver_ndis_get_capa
,
2817 wpa_driver_ndis_poll
,
2818 wpa_driver_ndis_get_ifname
,
2819 wpa_driver_ndis_get_mac_addr
,
2820 NULL
/* send_eapol */,
2821 NULL
/* set_operstate */,
2822 NULL
/* mlme_setprotection */,
2823 NULL
/* get_hw_feature_data */,
2824 NULL
/* set_channel */,
2825 NULL
/* set_ssid */,
2826 NULL
/* set_bssid */,
2827 NULL
/* send_mlme */,
2828 NULL
/* mlme_add_sta */,
2829 NULL
/* mlme_remove_sta */,
2830 NULL
/* update_ft_ies */,
2831 NULL
/* send_ft_action */,
2832 wpa_driver_ndis_get_scan_results