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 */
28 #ifdef __MINGW32_VERSION
29 #include <ddk/ntddndis.h>
30 #else /* __MINGW32_VERSION */
32 #endif /* __MINGW32_VERSION */
38 #endif /* _WIN32_WCE */
43 #include "common/ieee802_11_defs.h"
44 #include "driver_ndis.h"
46 int wpa_driver_register_event_cb(struct wpa_driver_ndis_data
*drv
);
47 #ifdef CONFIG_NDIS_EVENTS_INTEGRATED
48 void wpa_driver_ndis_event_pipe_cb(void *eloop_data
, void *user_data
);
49 #endif /* CONFIG_NDIS_EVENTS_INTEGRATED */
51 static void wpa_driver_ndis_deinit(void *priv
);
52 static void wpa_driver_ndis_poll(void *drv
);
53 static void wpa_driver_ndis_poll_timeout(void *eloop_ctx
, void *timeout_ctx
);
54 static int wpa_driver_ndis_adapter_init(struct wpa_driver_ndis_data
*drv
);
55 static int wpa_driver_ndis_adapter_open(struct wpa_driver_ndis_data
*drv
);
56 static void wpa_driver_ndis_adapter_close(struct wpa_driver_ndis_data
*drv
);
59 static const u8 pae_group_addr
[ETH_ALEN
] =
60 { 0x01, 0x80, 0xc2, 0x00, 0x00, 0x03 };
63 /* FIX: to be removed once this can be compiled with the complete NDIS
65 #ifndef OID_802_11_BSSID
66 #define OID_802_11_BSSID 0x0d010101
67 #define OID_802_11_SSID 0x0d010102
68 #define OID_802_11_INFRASTRUCTURE_MODE 0x0d010108
69 #define OID_802_11_ADD_WEP 0x0D010113
70 #define OID_802_11_REMOVE_WEP 0x0D010114
71 #define OID_802_11_DISASSOCIATE 0x0D010115
72 #define OID_802_11_BSSID_LIST 0x0d010217
73 #define OID_802_11_AUTHENTICATION_MODE 0x0d010118
74 #define OID_802_11_PRIVACY_FILTER 0x0d010119
75 #define OID_802_11_BSSID_LIST_SCAN 0x0d01011A
76 #define OID_802_11_WEP_STATUS 0x0d01011B
77 #define OID_802_11_ENCRYPTION_STATUS OID_802_11_WEP_STATUS
78 #define OID_802_11_ADD_KEY 0x0d01011D
79 #define OID_802_11_REMOVE_KEY 0x0d01011E
80 #define OID_802_11_ASSOCIATION_INFORMATION 0x0d01011F
81 #define OID_802_11_TEST 0x0d010120
82 #define OID_802_11_CAPABILITY 0x0d010122
83 #define OID_802_11_PMKID 0x0d010123
85 #define NDIS_802_11_LENGTH_SSID 32
86 #define NDIS_802_11_LENGTH_RATES 8
87 #define NDIS_802_11_LENGTH_RATES_EX 16
89 typedef UCHAR NDIS_802_11_MAC_ADDRESS
[6];
91 typedef struct NDIS_802_11_SSID
{
93 UCHAR Ssid
[NDIS_802_11_LENGTH_SSID
];
96 typedef LONG NDIS_802_11_RSSI
;
98 typedef enum NDIS_802_11_NETWORK_TYPE
{
103 Ndis802_11NetworkTypeMax
104 } NDIS_802_11_NETWORK_TYPE
;
106 typedef struct NDIS_802_11_CONFIGURATION_FH
{
111 } NDIS_802_11_CONFIGURATION_FH
;
113 typedef struct NDIS_802_11_CONFIGURATION
{
118 NDIS_802_11_CONFIGURATION_FH FHConfig
;
119 } NDIS_802_11_CONFIGURATION
;
121 typedef enum NDIS_802_11_NETWORK_INFRASTRUCTURE
{
123 Ndis802_11Infrastructure
,
124 Ndis802_11AutoUnknown
,
125 Ndis802_11InfrastructureMax
126 } NDIS_802_11_NETWORK_INFRASTRUCTURE
;
128 typedef enum NDIS_802_11_AUTHENTICATION_MODE
{
129 Ndis802_11AuthModeOpen
,
130 Ndis802_11AuthModeShared
,
131 Ndis802_11AuthModeAutoSwitch
,
132 Ndis802_11AuthModeWPA
,
133 Ndis802_11AuthModeWPAPSK
,
134 Ndis802_11AuthModeWPANone
,
135 Ndis802_11AuthModeWPA2
,
136 Ndis802_11AuthModeWPA2PSK
,
137 Ndis802_11AuthModeMax
138 } NDIS_802_11_AUTHENTICATION_MODE
;
140 typedef enum NDIS_802_11_WEP_STATUS
{
141 Ndis802_11WEPEnabled
,
142 Ndis802_11Encryption1Enabled
= Ndis802_11WEPEnabled
,
143 Ndis802_11WEPDisabled
,
144 Ndis802_11EncryptionDisabled
= Ndis802_11WEPDisabled
,
145 Ndis802_11WEPKeyAbsent
,
146 Ndis802_11Encryption1KeyAbsent
= Ndis802_11WEPKeyAbsent
,
147 Ndis802_11WEPNotSupported
,
148 Ndis802_11EncryptionNotSupported
= Ndis802_11WEPNotSupported
,
149 Ndis802_11Encryption2Enabled
,
150 Ndis802_11Encryption2KeyAbsent
,
151 Ndis802_11Encryption3Enabled
,
152 Ndis802_11Encryption3KeyAbsent
153 } NDIS_802_11_WEP_STATUS
, NDIS_802_11_ENCRYPTION_STATUS
;
155 typedef enum NDIS_802_11_PRIVACY_FILTER
{
156 Ndis802_11PrivFilterAcceptAll
,
157 Ndis802_11PrivFilter8021xWEP
158 } NDIS_802_11_PRIVACY_FILTER
;
160 typedef UCHAR NDIS_802_11_RATES
[NDIS_802_11_LENGTH_RATES
];
161 typedef UCHAR NDIS_802_11_RATES_EX
[NDIS_802_11_LENGTH_RATES_EX
];
163 typedef struct NDIS_WLAN_BSSID_EX
{
165 NDIS_802_11_MAC_ADDRESS MacAddress
; /* BSSID */
167 NDIS_802_11_SSID Ssid
;
169 NDIS_802_11_RSSI Rssi
;
170 NDIS_802_11_NETWORK_TYPE NetworkTypeInUse
;
171 NDIS_802_11_CONFIGURATION Configuration
;
172 NDIS_802_11_NETWORK_INFRASTRUCTURE InfrastructureMode
;
173 NDIS_802_11_RATES_EX SupportedRates
;
176 } NDIS_WLAN_BSSID_EX
;
178 typedef struct NDIS_802_11_BSSID_LIST_EX
{
180 NDIS_WLAN_BSSID_EX Bssid
[1];
181 } NDIS_802_11_BSSID_LIST_EX
;
183 typedef struct NDIS_802_11_FIXED_IEs
{
185 USHORT BeaconInterval
;
187 } NDIS_802_11_FIXED_IEs
;
189 typedef struct NDIS_802_11_WEP
{
193 UCHAR KeyMaterial
[1];
196 typedef ULONG NDIS_802_11_KEY_INDEX
;
197 typedef ULONGLONG NDIS_802_11_KEY_RSC
;
199 typedef struct NDIS_802_11_KEY
{
203 NDIS_802_11_MAC_ADDRESS BSSID
;
204 NDIS_802_11_KEY_RSC KeyRSC
;
205 UCHAR KeyMaterial
[1];
208 typedef struct NDIS_802_11_REMOVE_KEY
{
211 NDIS_802_11_MAC_ADDRESS BSSID
;
212 } NDIS_802_11_REMOVE_KEY
;
214 typedef struct NDIS_802_11_AI_REQFI
{
216 USHORT ListenInterval
;
217 NDIS_802_11_MAC_ADDRESS CurrentAPAddress
;
218 } NDIS_802_11_AI_REQFI
;
220 typedef struct NDIS_802_11_AI_RESFI
{
223 USHORT AssociationId
;
224 } NDIS_802_11_AI_RESFI
;
226 typedef struct NDIS_802_11_ASSOCIATION_INFORMATION
{
228 USHORT AvailableRequestFixedIEs
;
229 NDIS_802_11_AI_REQFI RequestFixedIEs
;
230 ULONG RequestIELength
;
231 ULONG OffsetRequestIEs
;
232 USHORT AvailableResponseFixedIEs
;
233 NDIS_802_11_AI_RESFI ResponseFixedIEs
;
234 ULONG ResponseIELength
;
235 ULONG OffsetResponseIEs
;
236 } NDIS_802_11_ASSOCIATION_INFORMATION
;
238 typedef struct NDIS_802_11_AUTHENTICATION_ENCRYPTION
{
239 NDIS_802_11_AUTHENTICATION_MODE AuthModeSupported
;
240 NDIS_802_11_ENCRYPTION_STATUS EncryptStatusSupported
;
241 } NDIS_802_11_AUTHENTICATION_ENCRYPTION
;
243 typedef struct NDIS_802_11_CAPABILITY
{
247 ULONG NoOfAuthEncryptPairsSupported
;
248 NDIS_802_11_AUTHENTICATION_ENCRYPTION
249 AuthenticationEncryptionSupported
[1];
250 } NDIS_802_11_CAPABILITY
;
252 typedef UCHAR NDIS_802_11_PMKID_VALUE
[16];
254 typedef struct BSSID_INFO
{
255 NDIS_802_11_MAC_ADDRESS BSSID
;
256 NDIS_802_11_PMKID_VALUE PMKID
;
259 typedef struct NDIS_802_11_PMKID
{
261 ULONG BSSIDInfoCount
;
262 BSSID_INFO BSSIDInfo
[1];
265 typedef enum NDIS_802_11_STATUS_TYPE
{
266 Ndis802_11StatusType_Authentication
,
267 Ndis802_11StatusType_PMKID_CandidateList
= 2,
268 Ndis802_11StatusTypeMax
269 } NDIS_802_11_STATUS_TYPE
;
271 typedef struct NDIS_802_11_STATUS_INDICATION
{
272 NDIS_802_11_STATUS_TYPE StatusType
;
273 } NDIS_802_11_STATUS_INDICATION
;
275 typedef struct PMKID_CANDIDATE
{
276 NDIS_802_11_MAC_ADDRESS BSSID
;
280 #define NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED 0x01
282 typedef struct NDIS_802_11_PMKID_CANDIDATE_LIST
{
285 PMKID_CANDIDATE CandidateList
[1];
286 } NDIS_802_11_PMKID_CANDIDATE_LIST
;
288 typedef struct NDIS_802_11_AUTHENTICATION_REQUEST
{
290 NDIS_802_11_MAC_ADDRESS Bssid
;
292 } NDIS_802_11_AUTHENTICATION_REQUEST
;
294 #define NDIS_802_11_AUTH_REQUEST_REAUTH 0x01
295 #define NDIS_802_11_AUTH_REQUEST_KEYUPDATE 0x02
296 #define NDIS_802_11_AUTH_REQUEST_PAIRWISE_ERROR 0x06
297 #define NDIS_802_11_AUTH_REQUEST_GROUP_ERROR 0x0E
299 #endif /* OID_802_11_BSSID */
302 #ifndef OID_802_11_PMKID
303 /* Platform SDK for XP did not include WPA2, so add needed definitions */
305 #define OID_802_11_CAPABILITY 0x0d010122
306 #define OID_802_11_PMKID 0x0d010123
308 #define Ndis802_11AuthModeWPA2 6
309 #define Ndis802_11AuthModeWPA2PSK 7
311 #define Ndis802_11StatusType_PMKID_CandidateList 2
313 typedef struct NDIS_802_11_AUTHENTICATION_ENCRYPTION
{
314 NDIS_802_11_AUTHENTICATION_MODE AuthModeSupported
;
315 NDIS_802_11_ENCRYPTION_STATUS EncryptStatusSupported
;
316 } NDIS_802_11_AUTHENTICATION_ENCRYPTION
;
318 typedef struct NDIS_802_11_CAPABILITY
{
322 ULONG NoOfAuthEncryptPairsSupported
;
323 NDIS_802_11_AUTHENTICATION_ENCRYPTION
324 AuthenticationEncryptionSupported
[1];
325 } NDIS_802_11_CAPABILITY
;
327 typedef UCHAR NDIS_802_11_PMKID_VALUE
[16];
329 typedef struct BSSID_INFO
{
330 NDIS_802_11_MAC_ADDRESS BSSID
;
331 NDIS_802_11_PMKID_VALUE PMKID
;
334 typedef struct NDIS_802_11_PMKID
{
336 ULONG BSSIDInfoCount
;
337 BSSID_INFO BSSIDInfo
[1];
340 typedef struct PMKID_CANDIDATE
{
341 NDIS_802_11_MAC_ADDRESS BSSID
;
345 #define NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED 0x01
347 typedef struct NDIS_802_11_PMKID_CANDIDATE_LIST
{
350 PMKID_CANDIDATE CandidateList
[1];
351 } NDIS_802_11_PMKID_CANDIDATE_LIST
;
353 #endif /* OID_802_11_CAPABILITY */
356 #ifndef OID_DOT11_CURRENT_OPERATION_MODE
357 /* Native 802.11 OIDs */
358 #define OID_DOT11_NDIS_START 0x0D010300
359 #define OID_DOT11_CURRENT_OPERATION_MODE (OID_DOT11_NDIS_START + 8)
360 #define OID_DOT11_SCAN_REQUEST (OID_DOT11_NDIS_START + 11)
362 typedef enum _DOT11_BSS_TYPE
{
363 dot11_BSS_type_infrastructure
= 1,
364 dot11_BSS_type_independent
= 2,
365 dot11_BSS_type_any
= 3
366 } DOT11_BSS_TYPE
, * PDOT11_BSS_TYPE
;
368 typedef UCHAR DOT11_MAC_ADDRESS
[6];
369 typedef DOT11_MAC_ADDRESS
* PDOT11_MAC_ADDRESS
;
371 typedef enum _DOT11_SCAN_TYPE
{
372 dot11_scan_type_active
= 1,
373 dot11_scan_type_passive
= 2,
374 dot11_scan_type_auto
= 3,
375 dot11_scan_type_forced
= 0x80000000
376 } DOT11_SCAN_TYPE
, * PDOT11_SCAN_TYPE
;
378 typedef struct _DOT11_SCAN_REQUEST_V2
{
379 DOT11_BSS_TYPE dot11BSSType
;
380 DOT11_MAC_ADDRESS dot11BSSID
;
381 DOT11_SCAN_TYPE dot11ScanType
;
382 BOOLEAN bRestrictedScan
;
383 ULONG udot11SSIDsOffset
;
384 ULONG uNumOfdot11SSIDs
;
385 BOOLEAN bUseRequestIE
;
386 ULONG uRequestIDsOffset
;
387 ULONG uNumOfRequestIDs
;
388 ULONG uPhyTypeInfosOffset
;
389 ULONG uNumOfPhyTypeInfos
;
393 } DOT11_SCAN_REQUEST_V2
, * PDOT11_SCAN_REQUEST_V2
;
395 #endif /* OID_DOT11_CURRENT_OPERATION_MODE */
397 #ifdef CONFIG_USE_NDISUIO
399 #ifdef __MINGW32_VERSION
400 typedef ULONG NDIS_OID
;
401 #endif /* __MINGW32_VERSION */
402 /* from nuiouser.h */
403 #define FSCTL_NDISUIO_BASE FILE_DEVICE_NETWORK
405 #define _NDISUIO_CTL_CODE(_Function, _Method, _Access) \
406 CTL_CODE(FSCTL_NDISUIO_BASE, _Function, _Method, _Access)
408 #define IOCTL_NDISUIO_OPEN_DEVICE \
409 _NDISUIO_CTL_CODE(0x200, METHOD_BUFFERED, \
410 FILE_READ_ACCESS | FILE_WRITE_ACCESS)
412 #define IOCTL_NDISUIO_QUERY_OID_VALUE \
413 _NDISUIO_CTL_CODE(0x201, METHOD_BUFFERED, \
414 FILE_READ_ACCESS | FILE_WRITE_ACCESS)
416 #define IOCTL_NDISUIO_SET_OID_VALUE \
417 _NDISUIO_CTL_CODE(0x205, METHOD_BUFFERED, \
418 FILE_READ_ACCESS | FILE_WRITE_ACCESS)
420 #define IOCTL_NDISUIO_SET_ETHER_TYPE \
421 _NDISUIO_CTL_CODE(0x202, METHOD_BUFFERED, \
422 FILE_READ_ACCESS | FILE_WRITE_ACCESS)
424 #define IOCTL_NDISUIO_QUERY_BINDING \
425 _NDISUIO_CTL_CODE(0x203, METHOD_BUFFERED, \
426 FILE_READ_ACCESS | FILE_WRITE_ACCESS)
428 #define IOCTL_NDISUIO_BIND_WAIT \
429 _NDISUIO_CTL_CODE(0x204, METHOD_BUFFERED, \
430 FILE_READ_ACCESS | FILE_WRITE_ACCESS)
432 typedef struct _NDISUIO_QUERY_OID
435 UCHAR Data
[sizeof(ULONG
)];
436 } NDISUIO_QUERY_OID
, *PNDISUIO_QUERY_OID
;
438 typedef struct _NDISUIO_SET_OID
441 UCHAR Data
[sizeof(ULONG
)];
442 } NDISUIO_SET_OID
, *PNDISUIO_SET_OID
;
444 typedef struct _NDISUIO_QUERY_BINDING
447 ULONG DeviceNameOffset
;
448 ULONG DeviceNameLength
;
449 ULONG DeviceDescrOffset
;
450 ULONG DeviceDescrLength
;
451 } NDISUIO_QUERY_BINDING
, *PNDISUIO_QUERY_BINDING
;
452 #endif /* _WIN32_WCE */
453 #endif /* CONFIG_USE_NDISUIO */
456 static int ndis_get_oid(struct wpa_driver_ndis_data
*drv
, unsigned int oid
,
457 char *data
, size_t len
)
459 #ifdef CONFIG_USE_NDISUIO
460 NDISUIO_QUERY_OID
*o
;
461 size_t buflen
= sizeof(*o
) + len
;
466 o
= os_zalloc(buflen
);
471 o
->ptcDeviceName
= drv
->adapter_name
;
472 #endif /* _WIN32_WCE */
473 if (!DeviceIoControl(drv
->ndisuio
, IOCTL_NDISUIO_QUERY_OID_VALUE
,
474 o
, sizeof(NDISUIO_QUERY_OID
), o
, buflen
, &written
,
476 wpa_printf(MSG_DEBUG
, "NDIS: IOCTL_NDISUIO_QUERY_OID_VALUE "
477 "failed (oid=%08x): %d", oid
, (int) GetLastError());
481 hdrlen
= sizeof(NDISUIO_QUERY_OID
) - sizeof(o
->Data
);
482 if (written
< hdrlen
) {
483 wpa_printf(MSG_DEBUG
, "NDIS: query oid=%08x written (%d); "
484 "too short", oid
, (unsigned int) written
);
490 wpa_printf(MSG_DEBUG
, "NDIS: query oid=%08x written (%d) > "
491 "len (%d)",oid
, (unsigned int) written
, len
);
495 os_memcpy(data
, o
->Data
, written
);
499 #else /* CONFIG_USE_NDISUIO */
504 buf
= os_zalloc(sizeof(*o
) + len
);
507 o
= (PACKET_OID_DATA
*) buf
;
511 if (!PacketRequest(drv
->adapter
, FALSE
, o
)) {
512 wpa_printf(MSG_DEBUG
, "%s: oid=0x%x len (%d) failed",
517 if (o
->Length
> len
) {
518 wpa_printf(MSG_DEBUG
, "%s: oid=0x%x Length (%d) > len (%d)",
519 __func__
, oid
, (unsigned int) o
->Length
, len
);
523 os_memcpy(data
, o
->Data
, o
->Length
);
527 #endif /* CONFIG_USE_NDISUIO */
531 static int ndis_set_oid(struct wpa_driver_ndis_data
*drv
, unsigned int oid
,
532 const char *data
, size_t len
)
534 #ifdef CONFIG_USE_NDISUIO
536 size_t buflen
, reallen
;
540 os_snprintf(txt
, sizeof(txt
), "NDIS: Set OID %08x", oid
);
541 wpa_hexdump_key(MSG_MSGDUMP
, txt
, (const u8
*) data
, len
);
543 buflen
= sizeof(*o
) + len
;
544 reallen
= buflen
- sizeof(o
->Data
);
545 o
= os_zalloc(buflen
);
550 o
->ptcDeviceName
= drv
->adapter_name
;
551 #endif /* _WIN32_WCE */
553 os_memcpy(o
->Data
, data
, len
);
554 if (!DeviceIoControl(drv
->ndisuio
, IOCTL_NDISUIO_SET_OID_VALUE
,
555 o
, reallen
, NULL
, 0, &written
, NULL
)) {
556 wpa_printf(MSG_DEBUG
, "NDIS: IOCTL_NDISUIO_SET_OID_VALUE "
557 "(oid=%08x) failed: %d", oid
, (int) GetLastError());
563 #else /* CONFIG_USE_NDISUIO */
568 os_snprintf(txt
, sizeof(txt
), "NDIS: Set OID %08x", oid
);
569 wpa_hexdump_key(MSG_MSGDUMP
, txt
, (const u8
*) data
, len
);
571 buf
= os_zalloc(sizeof(*o
) + len
);
574 o
= (PACKET_OID_DATA
*) buf
;
578 os_memcpy(o
->Data
, data
, len
);
580 if (!PacketRequest(drv
->adapter
, TRUE
, o
)) {
581 wpa_printf(MSG_DEBUG
, "%s: oid=0x%x len (%d) failed",
588 #endif /* CONFIG_USE_NDISUIO */
592 static int ndis_set_auth_mode(struct wpa_driver_ndis_data
*drv
, int mode
)
594 u32 auth_mode
= mode
;
595 if (ndis_set_oid(drv
, OID_802_11_AUTHENTICATION_MODE
,
596 (char *) &auth_mode
, sizeof(auth_mode
)) < 0) {
597 wpa_printf(MSG_DEBUG
, "NDIS: Failed to set "
598 "OID_802_11_AUTHENTICATION_MODE (%d)",
606 static int ndis_get_auth_mode(struct wpa_driver_ndis_data
*drv
)
610 res
= ndis_get_oid(drv
, OID_802_11_AUTHENTICATION_MODE
,
611 (char *) &auth_mode
, sizeof(auth_mode
));
612 if (res
!= sizeof(auth_mode
)) {
613 wpa_printf(MSG_DEBUG
, "NDIS: Failed to get "
614 "OID_802_11_AUTHENTICATION_MODE");
621 static int ndis_set_encr_status(struct wpa_driver_ndis_data
*drv
, int encr
)
623 u32 encr_status
= encr
;
624 if (ndis_set_oid(drv
, OID_802_11_ENCRYPTION_STATUS
,
625 (char *) &encr_status
, sizeof(encr_status
)) < 0) {
626 wpa_printf(MSG_DEBUG
, "NDIS: Failed to set "
627 "OID_802_11_ENCRYPTION_STATUS (%d)", encr
);
634 static int ndis_get_encr_status(struct wpa_driver_ndis_data
*drv
)
638 res
= ndis_get_oid(drv
, OID_802_11_ENCRYPTION_STATUS
,
639 (char *) &encr
, sizeof(encr
));
640 if (res
!= sizeof(encr
)) {
641 wpa_printf(MSG_DEBUG
, "NDIS: Failed to get "
642 "OID_802_11_ENCRYPTION_STATUS");
649 static int wpa_driver_ndis_get_bssid(void *priv
, u8
*bssid
)
651 struct wpa_driver_ndis_data
*drv
= priv
;
655 * Report PAE group address as the "BSSID" for wired
658 os_memcpy(bssid
, pae_group_addr
, ETH_ALEN
);
662 return ndis_get_oid(drv
, OID_802_11_BSSID
, (char *) bssid
, ETH_ALEN
) <
667 static int wpa_driver_ndis_get_ssid(void *priv
, u8
*ssid
)
669 struct wpa_driver_ndis_data
*drv
= priv
;
670 NDIS_802_11_SSID buf
;
673 res
= ndis_get_oid(drv
, OID_802_11_SSID
, (char *) &buf
, sizeof(buf
));
675 wpa_printf(MSG_DEBUG
, "NDIS: Failed to get SSID");
677 wpa_printf(MSG_DEBUG
, "NDIS: Allow get_ssid failure "
678 "with a wired interface");
683 os_memcpy(ssid
, buf
.Ssid
, buf
.SsidLength
);
684 return buf
.SsidLength
;
688 static int wpa_driver_ndis_set_ssid(struct wpa_driver_ndis_data
*drv
,
689 const u8
*ssid
, size_t ssid_len
)
691 NDIS_802_11_SSID buf
;
693 os_memset(&buf
, 0, sizeof(buf
));
694 buf
.SsidLength
= ssid_len
;
695 os_memcpy(buf
.Ssid
, ssid
, ssid_len
);
697 * Make sure radio is marked enabled here so that scan request will not
698 * force SSID to be changed to a random one in order to enable radio at
701 drv
->radio_enabled
= 1;
702 return ndis_set_oid(drv
, OID_802_11_SSID
, (char *) &buf
, sizeof(buf
));
706 /* Disconnect using OID_802_11_DISASSOCIATE. This will also turn the radio off.
708 static int wpa_driver_ndis_radio_off(struct wpa_driver_ndis_data
*drv
)
710 drv
->radio_enabled
= 0;
711 return ndis_set_oid(drv
, OID_802_11_DISASSOCIATE
, " ", 4);
715 /* Disconnect by setting SSID to random (i.e., likely not used). */
716 static int wpa_driver_ndis_disconnect(struct wpa_driver_ndis_data
*drv
)
720 for (i
= 0; i
< 32; i
++)
721 ssid
[i
] = rand() & 0xff;
722 return wpa_driver_ndis_set_ssid(drv
, (u8
*) ssid
, 32);
726 static int wpa_driver_ndis_deauthenticate(void *priv
, const u8
*addr
,
729 struct wpa_driver_ndis_data
*drv
= priv
;
730 return wpa_driver_ndis_disconnect(drv
);
734 static int wpa_driver_ndis_disassociate(void *priv
, const u8
*addr
,
737 struct wpa_driver_ndis_data
*drv
= priv
;
738 return wpa_driver_ndis_disconnect(drv
);
742 static void wpa_driver_ndis_scan_timeout(void *eloop_ctx
, void *timeout_ctx
)
744 wpa_printf(MSG_DEBUG
, "Scan timeout - try to get results");
745 wpa_supplicant_event(timeout_ctx
, EVENT_SCAN_RESULTS
, NULL
);
749 static int wpa_driver_ndis_scan_native80211(
750 struct wpa_driver_ndis_data
*drv
,
751 struct wpa_driver_scan_params
*params
)
753 DOT11_SCAN_REQUEST_V2 req
;
756 os_memset(&req
, 0, sizeof(req
));
757 req
.dot11BSSType
= dot11_BSS_type_any
;
758 os_memset(req
.dot11BSSID
, 0xff, ETH_ALEN
);
759 req
.dot11ScanType
= dot11_scan_type_auto
;
760 res
= ndis_set_oid(drv
, OID_DOT11_SCAN_REQUEST
, (char *) &req
,
762 eloop_cancel_timeout(wpa_driver_ndis_scan_timeout
, drv
, drv
->ctx
);
763 eloop_register_timeout(7, 0, wpa_driver_ndis_scan_timeout
, drv
,
769 static int wpa_driver_ndis_scan(void *priv
,
770 struct wpa_driver_scan_params
*params
)
772 struct wpa_driver_ndis_data
*drv
= priv
;
775 if (drv
->native80211
)
776 return wpa_driver_ndis_scan_native80211(drv
, params
);
778 if (!drv
->radio_enabled
) {
779 wpa_printf(MSG_DEBUG
, "NDIS: turning radio on before the first"
781 if (wpa_driver_ndis_disconnect(drv
) < 0) {
782 wpa_printf(MSG_DEBUG
, "NDIS: failed to enable radio");
784 drv
->radio_enabled
= 1;
787 res
= ndis_set_oid(drv
, OID_802_11_BSSID_LIST_SCAN
, " ", 4);
788 eloop_cancel_timeout(wpa_driver_ndis_scan_timeout
, drv
, drv
->ctx
);
789 eloop_register_timeout(7, 0, wpa_driver_ndis_scan_timeout
, drv
,
795 static const u8
* wpa_scan_get_ie(const struct wpa_scan_res
*res
, u8 ie
)
799 pos
= (const u8
*) (res
+ 1);
800 end
= pos
+ res
->ie_len
;
802 while (pos
+ 1 < end
) {
803 if (pos
+ 2 + pos
[1] > end
)
814 static struct wpa_scan_res
* wpa_driver_ndis_add_scan_ssid(
815 struct wpa_scan_res
*r
, NDIS_802_11_SSID
*ssid
)
817 struct wpa_scan_res
*nr
;
820 if (wpa_scan_get_ie(r
, WLAN_EID_SSID
))
821 return r
; /* SSID IE already present */
823 if (ssid
->SsidLength
== 0 || ssid
->SsidLength
> 32)
824 return r
; /* No valid SSID inside scan data */
826 nr
= os_realloc(r
, sizeof(*r
) + r
->ie_len
+ 2 + ssid
->SsidLength
);
830 pos
= ((u8
*) (nr
+ 1)) + nr
->ie_len
;
831 *pos
++ = WLAN_EID_SSID
;
832 *pos
++ = ssid
->SsidLength
;
833 os_memcpy(pos
, ssid
->Ssid
, ssid
->SsidLength
);
834 nr
->ie_len
+= 2 + ssid
->SsidLength
;
840 static struct wpa_scan_results
* wpa_driver_ndis_get_scan_results(void *priv
)
842 struct wpa_driver_ndis_data
*drv
= priv
;
843 NDIS_802_11_BSSID_LIST_EX
*b
;
844 size_t blen
, count
, i
;
847 struct wpa_scan_results
*results
;
848 struct wpa_scan_res
*r
;
854 len
= ndis_get_oid(drv
, OID_802_11_BSSID_LIST
, (char *) b
, blen
);
856 wpa_printf(MSG_DEBUG
, "NDIS: failed to get scan results");
860 count
= b
->NumberOfItems
;
862 results
= os_zalloc(sizeof(*results
));
863 if (results
== NULL
) {
867 results
->res
= os_zalloc(count
* sizeof(struct wpa_scan_res
*));
868 if (results
->res
== NULL
) {
874 pos
= (char *) &b
->Bssid
[0];
875 for (i
= 0; i
< count
; i
++) {
876 NDIS_WLAN_BSSID_EX
*bss
= (NDIS_WLAN_BSSID_EX
*) pos
;
877 NDIS_802_11_FIXED_IEs
*fixed
;
879 if (bss
->IELength
< sizeof(NDIS_802_11_FIXED_IEs
)) {
880 wpa_printf(MSG_DEBUG
, "NDIS: too small IELength=%d",
881 (int) bss
->IELength
);
884 if (((char *) bss
->IEs
) + bss
->IELength
> (char *) b
+ blen
) {
886 * Some NDIS drivers have been reported to include an
887 * entry with an invalid IELength in scan results and
888 * this has crashed wpa_supplicant, so validate the
889 * returned value before using it.
891 wpa_printf(MSG_DEBUG
, "NDIS: skipped invalid scan "
892 "result IE (BSSID=" MACSTR
") IELength=%d",
893 MAC2STR(bss
->MacAddress
),
894 (int) bss
->IELength
);
898 r
= os_zalloc(sizeof(*r
) + bss
->IELength
-
899 sizeof(NDIS_802_11_FIXED_IEs
));
903 os_memcpy(r
->bssid
, bss
->MacAddress
, ETH_ALEN
);
904 r
->level
= (int) bss
->Rssi
;
905 r
->freq
= bss
->Configuration
.DSConfig
/ 1000;
906 fixed
= (NDIS_802_11_FIXED_IEs
*) bss
->IEs
;
907 r
->beacon_int
= WPA_GET_LE16((u8
*) &fixed
->BeaconInterval
);
908 r
->caps
= WPA_GET_LE16((u8
*) &fixed
->Capabilities
);
909 r
->tsf
= WPA_GET_LE64(fixed
->Timestamp
);
910 os_memcpy(r
+ 1, bss
->IEs
+ sizeof(NDIS_802_11_FIXED_IEs
),
911 bss
->IELength
- sizeof(NDIS_802_11_FIXED_IEs
));
912 r
->ie_len
= bss
->IELength
- sizeof(NDIS_802_11_FIXED_IEs
);
913 r
= wpa_driver_ndis_add_scan_ssid(r
, &bss
->Ssid
);
915 results
->res
[results
->num
++] = r
;
918 if (pos
> (char *) b
+ blen
)
928 static int wpa_driver_ndis_remove_key(struct wpa_driver_ndis_data
*drv
,
929 int key_idx
, const u8
*addr
,
930 const u8
*bssid
, int pairwise
)
932 NDIS_802_11_REMOVE_KEY rkey
;
933 NDIS_802_11_KEY_INDEX index
;
936 os_memset(&rkey
, 0, sizeof(rkey
));
938 rkey
.Length
= sizeof(rkey
);
939 rkey
.KeyIndex
= key_idx
;
941 rkey
.KeyIndex
|= 1 << 30;
942 os_memcpy(rkey
.BSSID
, bssid
, ETH_ALEN
);
944 res
= ndis_set_oid(drv
, OID_802_11_REMOVE_KEY
, (char *) &rkey
,
948 res2
= ndis_set_oid(drv
, OID_802_11_REMOVE_WEP
,
949 (char *) &index
, sizeof(index
));
953 if (res
< 0 && res2
< 0)
959 static int wpa_driver_ndis_add_wep(struct wpa_driver_ndis_data
*drv
,
960 int pairwise
, int key_idx
, int set_tx
,
961 const u8
*key
, size_t key_len
)
963 NDIS_802_11_WEP
*wep
;
968 wep
= os_zalloc(len
);
972 wep
->KeyIndex
= key_idx
;
974 wep
->KeyIndex
|= 1 << 31;
975 #if 0 /* Setting bit30 does not seem to work with some NDIS drivers */
977 wep
->KeyIndex
|= 1 << 30;
979 wep
->KeyLength
= key_len
;
980 os_memcpy(wep
->KeyMaterial
, key
, key_len
);
982 wpa_hexdump_key(MSG_MSGDUMP
, "NDIS: OID_802_11_ADD_WEP",
984 res
= ndis_set_oid(drv
, OID_802_11_ADD_WEP
, (char *) wep
, len
);
992 static int wpa_driver_ndis_set_key(const char *ifname
, void *priv
,
993 enum wpa_alg alg
, const u8
*addr
,
994 int key_idx
, int set_tx
,
995 const u8
*seq
, size_t seq_len
,
996 const u8
*key
, size_t key_len
)
998 struct wpa_driver_ndis_data
*drv
= priv
;
1000 NDIS_802_11_KEY
*nkey
;
1004 if (addr
== NULL
|| os_memcmp(addr
, "\xff\xff\xff\xff\xff\xff",
1008 if (wpa_driver_ndis_get_bssid(drv
, bssid
) < 0)
1009 os_memset(bssid
, 0xff, ETH_ALEN
);
1013 os_memcpy(bssid
, addr
, ETH_ALEN
);
1016 if (alg
== WPA_ALG_NONE
|| key_len
== 0) {
1017 return wpa_driver_ndis_remove_key(drv
, key_idx
, addr
, bssid
,
1021 if (alg
== WPA_ALG_WEP
) {
1022 return wpa_driver_ndis_add_wep(drv
, pairwise
, key_idx
, set_tx
,
1026 len
= 12 + 6 + 6 + 8 + key_len
;
1028 nkey
= os_zalloc(len
);
1033 nkey
->KeyIndex
= key_idx
;
1035 nkey
->KeyIndex
|= 1 << 31;
1037 nkey
->KeyIndex
|= 1 << 30;
1039 nkey
->KeyIndex
|= 1 << 29;
1040 nkey
->KeyLength
= key_len
;
1041 os_memcpy(nkey
->BSSID
, bssid
, ETH_ALEN
);
1042 if (seq
&& seq_len
) {
1043 for (i
= 0; i
< seq_len
; i
++)
1044 nkey
->KeyRSC
|= (ULONGLONG
) seq
[i
] << (i
* 8);
1046 if (alg
== WPA_ALG_TKIP
&& key_len
== 32) {
1047 os_memcpy(nkey
->KeyMaterial
, key
, 16);
1048 os_memcpy(nkey
->KeyMaterial
+ 16, key
+ 24, 8);
1049 os_memcpy(nkey
->KeyMaterial
+ 24, key
+ 16, 8);
1051 os_memcpy(nkey
->KeyMaterial
, key
, key_len
);
1054 wpa_hexdump_key(MSG_MSGDUMP
, "NDIS: OID_802_11_ADD_KEY",
1056 res
= ndis_set_oid(drv
, OID_802_11_ADD_KEY
, (char *) nkey
, len
);
1064 wpa_driver_ndis_associate(void *priv
,
1065 struct wpa_driver_associate_params
*params
)
1067 struct wpa_driver_ndis_data
*drv
= priv
;
1068 u32 auth_mode
, encr
, priv_mode
, mode
;
1070 drv
->mode
= params
->mode
;
1072 /* Note: Setting OID_802_11_INFRASTRUCTURE_MODE clears current keys,
1073 * so static WEP keys needs to be set again after this. */
1074 if (params
->mode
== IEEE80211_MODE_IBSS
) {
1075 mode
= Ndis802_11IBSS
;
1076 /* Need to make sure that BSSID polling is enabled for
1078 eloop_cancel_timeout(wpa_driver_ndis_poll_timeout
, drv
, NULL
);
1079 eloop_register_timeout(1, 0, wpa_driver_ndis_poll_timeout
,
1082 mode
= Ndis802_11Infrastructure
;
1083 if (ndis_set_oid(drv
, OID_802_11_INFRASTRUCTURE_MODE
,
1084 (char *) &mode
, sizeof(mode
)) < 0) {
1085 wpa_printf(MSG_DEBUG
, "NDIS: Failed to set "
1086 "OID_802_11_INFRASTRUCTURE_MODE (%d)",
1088 /* Try to continue anyway */
1091 if (params
->key_mgmt_suite
== KEY_MGMT_NONE
||
1092 params
->key_mgmt_suite
== KEY_MGMT_802_1X_NO_WPA
) {
1093 /* Re-set WEP keys if static WEP configuration is used. */
1094 u8 bcast
[ETH_ALEN
] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
1096 for (i
= 0; i
< 4; i
++) {
1097 if (!params
->wep_key
[i
])
1099 wpa_printf(MSG_DEBUG
, "NDIS: Re-setting static WEP "
1101 wpa_driver_ndis_set_key(drv
->ifname
, drv
, WPA_ALG_WEP
,
1103 i
== params
->wep_tx_keyidx
,
1104 NULL
, 0, params
->wep_key
[i
],
1105 params
->wep_key_len
[i
]);
1109 if (params
->wpa_ie
== NULL
|| params
->wpa_ie_len
== 0) {
1110 if (params
->auth_alg
& WPA_AUTH_ALG_SHARED
) {
1111 if (params
->auth_alg
& WPA_AUTH_ALG_OPEN
)
1112 auth_mode
= Ndis802_11AuthModeAutoSwitch
;
1114 auth_mode
= Ndis802_11AuthModeShared
;
1116 auth_mode
= Ndis802_11AuthModeOpen
;
1117 priv_mode
= Ndis802_11PrivFilterAcceptAll
;
1118 } else if (params
->wpa_ie
[0] == WLAN_EID_RSN
) {
1119 priv_mode
= Ndis802_11PrivFilter8021xWEP
;
1120 if (params
->key_mgmt_suite
== KEY_MGMT_PSK
)
1121 auth_mode
= Ndis802_11AuthModeWPA2PSK
;
1123 auth_mode
= Ndis802_11AuthModeWPA2
;
1125 } else if (params
->key_mgmt_suite
== KEY_MGMT_WPS
) {
1126 auth_mode
= Ndis802_11AuthModeOpen
;
1127 priv_mode
= Ndis802_11PrivFilterAcceptAll
;
1128 #endif /* CONFIG_WPS */
1130 priv_mode
= Ndis802_11PrivFilter8021xWEP
;
1131 if (params
->key_mgmt_suite
== KEY_MGMT_WPA_NONE
)
1132 auth_mode
= Ndis802_11AuthModeWPANone
;
1133 else if (params
->key_mgmt_suite
== KEY_MGMT_PSK
)
1134 auth_mode
= Ndis802_11AuthModeWPAPSK
;
1136 auth_mode
= Ndis802_11AuthModeWPA
;
1139 switch (params
->pairwise_suite
) {
1141 encr
= Ndis802_11Encryption3Enabled
;
1144 encr
= Ndis802_11Encryption2Enabled
;
1148 encr
= Ndis802_11Encryption1Enabled
;
1151 if (params
->group_suite
== CIPHER_CCMP
)
1152 encr
= Ndis802_11Encryption3Enabled
;
1153 else if (params
->group_suite
== CIPHER_TKIP
)
1154 encr
= Ndis802_11Encryption2Enabled
;
1156 encr
= Ndis802_11EncryptionDisabled
;
1159 encr
= Ndis802_11EncryptionDisabled
;
1162 if (ndis_set_oid(drv
, OID_802_11_PRIVACY_FILTER
,
1163 (char *) &priv_mode
, sizeof(priv_mode
)) < 0) {
1164 wpa_printf(MSG_DEBUG
, "NDIS: Failed to set "
1165 "OID_802_11_PRIVACY_FILTER (%d)",
1167 /* Try to continue anyway */
1170 ndis_set_auth_mode(drv
, auth_mode
);
1171 ndis_set_encr_status(drv
, encr
);
1173 if (params
->bssid
) {
1174 ndis_set_oid(drv
, OID_802_11_BSSID
, (char *) params
->bssid
,
1176 drv
->oid_bssid_set
= 1;
1177 } else if (drv
->oid_bssid_set
) {
1178 ndis_set_oid(drv
, OID_802_11_BSSID
, "\xff\xff\xff\xff\xff\xff",
1180 drv
->oid_bssid_set
= 0;
1183 return wpa_driver_ndis_set_ssid(drv
, params
->ssid
, params
->ssid_len
);
1187 static int wpa_driver_ndis_set_pmkid(struct wpa_driver_ndis_data
*drv
)
1189 int len
, count
, i
, ret
;
1190 struct ndis_pmkid_entry
*entry
;
1191 NDIS_802_11_PMKID
*p
;
1197 if (count
>= drv
->no_of_pmkid
)
1199 entry
= entry
->next
;
1201 len
= 8 + count
* sizeof(BSSID_INFO
);
1207 p
->BSSIDInfoCount
= count
;
1209 for (i
= 0; i
< count
; i
++) {
1210 os_memcpy(&p
->BSSIDInfo
[i
].BSSID
, entry
->bssid
, ETH_ALEN
);
1211 os_memcpy(&p
->BSSIDInfo
[i
].PMKID
, entry
->pmkid
, 16);
1212 entry
= entry
->next
;
1214 wpa_hexdump(MSG_MSGDUMP
, "NDIS: OID_802_11_PMKID", (u8
*) p
, len
);
1215 ret
= ndis_set_oid(drv
, OID_802_11_PMKID
, (char *) p
, len
);
1221 static int wpa_driver_ndis_add_pmkid(void *priv
, const u8
*bssid
,
1224 struct wpa_driver_ndis_data
*drv
= priv
;
1225 struct ndis_pmkid_entry
*entry
, *prev
;
1227 if (drv
->no_of_pmkid
== 0)
1233 if (os_memcmp(entry
->bssid
, bssid
, ETH_ALEN
) == 0)
1236 entry
= entry
->next
;
1240 /* Replace existing entry for this BSSID and move it into the
1241 * beginning of the list. */
1242 os_memcpy(entry
->pmkid
, pmkid
, 16);
1244 prev
->next
= entry
->next
;
1245 entry
->next
= drv
->pmkid
;
1249 entry
= os_malloc(sizeof(*entry
));
1251 os_memcpy(entry
->bssid
, bssid
, ETH_ALEN
);
1252 os_memcpy(entry
->pmkid
, pmkid
, 16);
1253 entry
->next
= drv
->pmkid
;
1258 return wpa_driver_ndis_set_pmkid(drv
);
1262 static int wpa_driver_ndis_remove_pmkid(void *priv
, const u8
*bssid
,
1265 struct wpa_driver_ndis_data
*drv
= priv
;
1266 struct ndis_pmkid_entry
*entry
, *prev
;
1268 if (drv
->no_of_pmkid
== 0)
1274 if (os_memcmp(entry
->bssid
, bssid
, ETH_ALEN
) == 0 &&
1275 os_memcmp(entry
->pmkid
, pmkid
, 16) == 0) {
1277 prev
->next
= entry
->next
;
1279 drv
->pmkid
= entry
->next
;
1284 entry
= entry
->next
;
1286 return wpa_driver_ndis_set_pmkid(drv
);
1290 static int wpa_driver_ndis_flush_pmkid(void *priv
)
1292 struct wpa_driver_ndis_data
*drv
= priv
;
1293 NDIS_802_11_PMKID p
;
1294 struct ndis_pmkid_entry
*pmkid
, *prev
;
1295 int prev_authmode
, ret
;
1297 if (drv
->no_of_pmkid
== 0)
1304 pmkid
= pmkid
->next
;
1309 * Some drivers may refuse OID_802_11_PMKID if authMode is not set to
1310 * WPA2, so change authMode temporarily, if needed.
1312 prev_authmode
= ndis_get_auth_mode(drv
);
1313 if (prev_authmode
!= Ndis802_11AuthModeWPA2
)
1314 ndis_set_auth_mode(drv
, Ndis802_11AuthModeWPA2
);
1316 os_memset(&p
, 0, sizeof(p
));
1318 p
.BSSIDInfoCount
= 0;
1319 wpa_hexdump(MSG_MSGDUMP
, "NDIS: OID_802_11_PMKID (flush)",
1321 ret
= ndis_set_oid(drv
, OID_802_11_PMKID
, (char *) &p
, 8);
1323 if (prev_authmode
!= Ndis802_11AuthModeWPA2
)
1324 ndis_set_auth_mode(drv
, prev_authmode
);
1330 static int wpa_driver_ndis_get_associnfo(struct wpa_driver_ndis_data
*drv
)
1332 char buf
[512], *pos
;
1333 NDIS_802_11_ASSOCIATION_INFORMATION
*ai
;
1335 union wpa_event_data data
;
1336 NDIS_802_11_BSSID_LIST_EX
*b
;
1339 len
= ndis_get_oid(drv
, OID_802_11_ASSOCIATION_INFORMATION
, buf
,
1342 wpa_printf(MSG_DEBUG
, "NDIS: failed to get association "
1346 if (len
> sizeof(buf
)) {
1347 /* Some drivers seem to be producing incorrect length for this
1348 * data. Limit the length to the current buffer size to avoid
1349 * crashing in hexdump. The data seems to be otherwise valid,
1350 * so better try to use it. */
1351 wpa_printf(MSG_DEBUG
, "NDIS: ignored bogus association "
1352 "information length %d", len
);
1353 len
= ndis_get_oid(drv
, OID_802_11_ASSOCIATION_INFORMATION
,
1356 wpa_printf(MSG_DEBUG
, "NDIS: re-reading association "
1357 "information failed");
1360 if (len
> sizeof(buf
)) {
1361 wpa_printf(MSG_DEBUG
, "NDIS: ignored bogus association"
1362 " information length %d (re-read)", len
);
1366 wpa_hexdump(MSG_MSGDUMP
, "NDIS: association information",
1368 if (len
< sizeof(*ai
)) {
1369 wpa_printf(MSG_DEBUG
, "NDIS: too short association "
1373 ai
= (NDIS_802_11_ASSOCIATION_INFORMATION
*) buf
;
1374 wpa_printf(MSG_DEBUG
, "NDIS: ReqFixed=0x%x RespFixed=0x%x off_req=%d "
1375 "off_resp=%d len_req=%d len_resp=%d",
1376 ai
->AvailableRequestFixedIEs
, ai
->AvailableResponseFixedIEs
,
1377 (int) ai
->OffsetRequestIEs
, (int) ai
->OffsetResponseIEs
,
1378 (int) ai
->RequestIELength
, (int) ai
->ResponseIELength
);
1380 if (ai
->OffsetRequestIEs
+ ai
->RequestIELength
> (unsigned) len
||
1381 ai
->OffsetResponseIEs
+ ai
->ResponseIELength
> (unsigned) len
) {
1382 wpa_printf(MSG_DEBUG
, "NDIS: association information - "
1387 wpa_hexdump(MSG_MSGDUMP
, "NDIS: Request IEs",
1388 (u8
*) buf
+ ai
->OffsetRequestIEs
, ai
->RequestIELength
);
1389 wpa_hexdump(MSG_MSGDUMP
, "NDIS: Response IEs",
1390 (u8
*) buf
+ ai
->OffsetResponseIEs
, ai
->ResponseIELength
);
1392 os_memset(&data
, 0, sizeof(data
));
1393 data
.assoc_info
.req_ies
= (u8
*) buf
+ ai
->OffsetRequestIEs
;
1394 data
.assoc_info
.req_ies_len
= ai
->RequestIELength
;
1395 data
.assoc_info
.resp_ies
= (u8
*) buf
+ ai
->OffsetResponseIEs
;
1396 data
.assoc_info
.resp_ies_len
= ai
->ResponseIELength
;
1399 b
= os_zalloc(blen
);
1401 goto skip_scan_results
;
1402 len
= ndis_get_oid(drv
, OID_802_11_BSSID_LIST
, (char *) b
, blen
);
1404 wpa_printf(MSG_DEBUG
, "NDIS: failed to get scan results");
1407 goto skip_scan_results
;
1409 wpa_printf(MSG_DEBUG
, "NDIS: %d BSSID items to process for AssocInfo",
1410 (unsigned int) b
->NumberOfItems
);
1412 pos
= (char *) &b
->Bssid
[0];
1413 for (i
= 0; i
< b
->NumberOfItems
; i
++) {
1414 NDIS_WLAN_BSSID_EX
*bss
= (NDIS_WLAN_BSSID_EX
*) pos
;
1415 if (os_memcmp(drv
->bssid
, bss
->MacAddress
, ETH_ALEN
) == 0 &&
1416 bss
->IELength
> sizeof(NDIS_802_11_FIXED_IEs
)) {
1417 data
.assoc_info
.beacon_ies
=
1419 sizeof(NDIS_802_11_FIXED_IEs
);
1420 data
.assoc_info
.beacon_ies_len
=
1421 bss
->IELength
- sizeof(NDIS_802_11_FIXED_IEs
);
1422 wpa_hexdump(MSG_MSGDUMP
, "NDIS: Beacon IEs",
1423 data
.assoc_info
.beacon_ies
,
1424 data
.assoc_info
.beacon_ies_len
);
1428 if (pos
> (char *) b
+ blen
)
1433 wpa_supplicant_event(drv
->ctx
, EVENT_ASSOCINFO
, &data
);
1441 static void wpa_driver_ndis_poll_timeout(void *eloop_ctx
, void *timeout_ctx
)
1443 struct wpa_driver_ndis_data
*drv
= eloop_ctx
;
1450 if (wpa_driver_ndis_get_bssid(drv
, bssid
)) {
1452 if (!is_zero_ether_addr(drv
->bssid
)) {
1453 os_memset(drv
->bssid
, 0, ETH_ALEN
);
1454 wpa_supplicant_event(drv
->ctx
, EVENT_DISASSOC
, NULL
);
1458 if (os_memcmp(drv
->bssid
, bssid
, ETH_ALEN
) != 0) {
1459 os_memcpy(drv
->bssid
, bssid
, ETH_ALEN
);
1460 wpa_driver_ndis_get_associnfo(drv
);
1461 wpa_supplicant_event(drv
->ctx
, EVENT_ASSOC
, NULL
);
1465 /* When using integrated NDIS event receiver, we can skip BSSID
1466 * polling when using infrastructure network. However, when using
1467 * IBSS mode, many driver do not seem to generate connection event,
1468 * so we need to enable BSSID polling to figure out when IBSS network
1471 poll
= drv
->mode
== IEEE80211_MODE_IBSS
;
1472 #ifndef CONFIG_NDIS_EVENTS_INTEGRATED
1475 #endif /* _WIN32_WCE */
1476 #endif /* CONFIG_NDIS_EVENTS_INTEGRATED */
1479 eloop_register_timeout(1, 0, wpa_driver_ndis_poll_timeout
,
1485 static void wpa_driver_ndis_poll(void *priv
)
1487 struct wpa_driver_ndis_data
*drv
= priv
;
1488 eloop_cancel_timeout(wpa_driver_ndis_poll_timeout
, drv
, NULL
);
1489 wpa_driver_ndis_poll_timeout(drv
, NULL
);
1493 /* Called when driver generates Media Connect Event by calling
1494 * NdisMIndicateStatus() with NDIS_STATUS_MEDIA_CONNECT */
1495 void wpa_driver_ndis_event_connect(struct wpa_driver_ndis_data
*drv
)
1497 wpa_printf(MSG_DEBUG
, "NDIS: Media Connect Event");
1498 if (wpa_driver_ndis_get_bssid(drv
, drv
->bssid
) == 0) {
1499 wpa_driver_ndis_get_associnfo(drv
);
1500 wpa_supplicant_event(drv
->ctx
, EVENT_ASSOC
, NULL
);
1505 /* Called when driver generates Media Disconnect Event by calling
1506 * NdisMIndicateStatus() with NDIS_STATUS_MEDIA_DISCONNECT */
1507 void wpa_driver_ndis_event_disconnect(struct wpa_driver_ndis_data
*drv
)
1509 wpa_printf(MSG_DEBUG
, "NDIS: Media Disconnect Event");
1510 os_memset(drv
->bssid
, 0, ETH_ALEN
);
1511 wpa_supplicant_event(drv
->ctx
, EVENT_DISASSOC
, NULL
);
1515 static void wpa_driver_ndis_event_auth(struct wpa_driver_ndis_data
*drv
,
1516 const u8
*data
, size_t data_len
)
1518 NDIS_802_11_AUTHENTICATION_REQUEST
*req
;
1519 int pairwise
= 0, group
= 0;
1520 union wpa_event_data event
;
1522 if (data_len
< sizeof(*req
)) {
1523 wpa_printf(MSG_DEBUG
, "NDIS: Too short Authentication Request "
1524 "Event (len=%d)", data_len
);
1527 req
= (NDIS_802_11_AUTHENTICATION_REQUEST
*) data
;
1529 wpa_printf(MSG_DEBUG
, "NDIS: Authentication Request Event: "
1530 "Bssid " MACSTR
" Flags 0x%x",
1531 MAC2STR(req
->Bssid
), (int) req
->Flags
);
1533 if ((req
->Flags
& NDIS_802_11_AUTH_REQUEST_PAIRWISE_ERROR
) ==
1534 NDIS_802_11_AUTH_REQUEST_PAIRWISE_ERROR
)
1536 else if ((req
->Flags
& NDIS_802_11_AUTH_REQUEST_GROUP_ERROR
) ==
1537 NDIS_802_11_AUTH_REQUEST_GROUP_ERROR
)
1540 if (pairwise
|| group
) {
1541 os_memset(&event
, 0, sizeof(event
));
1542 event
.michael_mic_failure
.unicast
= pairwise
;
1543 wpa_supplicant_event(drv
->ctx
, EVENT_MICHAEL_MIC_FAILURE
,
1549 static void wpa_driver_ndis_event_pmkid(struct wpa_driver_ndis_data
*drv
,
1550 const u8
*data
, size_t data_len
)
1552 NDIS_802_11_PMKID_CANDIDATE_LIST
*pmkid
;
1554 union wpa_event_data event
;
1557 wpa_printf(MSG_DEBUG
, "NDIS: Too short PMKID Candidate List "
1558 "Event (len=%d)", data_len
);
1561 pmkid
= (NDIS_802_11_PMKID_CANDIDATE_LIST
*) data
;
1562 wpa_printf(MSG_DEBUG
, "NDIS: PMKID Candidate List Event - Version %d "
1564 (int) pmkid
->Version
, (int) pmkid
->NumCandidates
);
1566 if (pmkid
->Version
!= 1) {
1567 wpa_printf(MSG_DEBUG
, "NDIS: Unsupported PMKID Candidate List "
1568 "Version %d", (int) pmkid
->Version
);
1572 if (data_len
< 8 + pmkid
->NumCandidates
* sizeof(PMKID_CANDIDATE
)) {
1573 wpa_printf(MSG_DEBUG
, "NDIS: PMKID Candidate List underflow");
1577 os_memset(&event
, 0, sizeof(event
));
1578 for (i
= 0; i
< pmkid
->NumCandidates
; i
++) {
1579 PMKID_CANDIDATE
*p
= &pmkid
->CandidateList
[i
];
1580 wpa_printf(MSG_DEBUG
, "NDIS: %d: " MACSTR
" Flags 0x%x",
1581 i
, MAC2STR(p
->BSSID
), (int) p
->Flags
);
1582 os_memcpy(event
.pmkid_candidate
.bssid
, p
->BSSID
, ETH_ALEN
);
1583 event
.pmkid_candidate
.index
= i
;
1584 event
.pmkid_candidate
.preauth
=
1585 p
->Flags
& NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED
;
1586 wpa_supplicant_event(drv
->ctx
, EVENT_PMKID_CANDIDATE
,
1592 /* Called when driver calls NdisMIndicateStatus() with
1593 * NDIS_STATUS_MEDIA_SPECIFIC_INDICATION */
1594 void wpa_driver_ndis_event_media_specific(struct wpa_driver_ndis_data
*drv
,
1595 const u8
*data
, size_t data_len
)
1597 NDIS_802_11_STATUS_INDICATION
*status
;
1599 if (data
== NULL
|| data_len
< sizeof(*status
))
1602 wpa_hexdump(MSG_DEBUG
, "NDIS: Media Specific Indication",
1605 status
= (NDIS_802_11_STATUS_INDICATION
*) data
;
1606 data
+= sizeof(status
);
1607 data_len
-= sizeof(status
);
1609 switch (status
->StatusType
) {
1610 case Ndis802_11StatusType_Authentication
:
1611 wpa_driver_ndis_event_auth(drv
, data
, data_len
);
1613 case Ndis802_11StatusType_PMKID_CandidateList
:
1614 wpa_driver_ndis_event_pmkid(drv
, data
, data_len
);
1617 wpa_printf(MSG_DEBUG
, "NDIS: Unknown StatusType %d",
1618 (int) status
->StatusType
);
1624 /* Called when an adapter is added */
1625 void wpa_driver_ndis_event_adapter_arrival(struct wpa_driver_ndis_data
*drv
)
1627 union wpa_event_data event
;
1630 wpa_printf(MSG_DEBUG
, "NDIS: Notify Adapter Arrival");
1632 for (i
= 0; i
< 30; i
++) {
1633 /* Re-open Packet32/NDISUIO connection */
1634 wpa_driver_ndis_adapter_close(drv
);
1635 if (wpa_driver_ndis_adapter_init(drv
) < 0 ||
1636 wpa_driver_ndis_adapter_open(drv
) < 0) {
1637 wpa_printf(MSG_DEBUG
, "NDIS: Driver re-initialization "
1641 wpa_printf(MSG_DEBUG
, "NDIS: Driver re-initialized");
1646 os_memset(&event
, 0, sizeof(event
));
1647 os_strlcpy(event
.interface_status
.ifname
, drv
->ifname
,
1648 sizeof(event
.interface_status
.ifname
));
1649 event
.interface_status
.ievent
= EVENT_INTERFACE_ADDED
;
1650 wpa_supplicant_event(drv
->ctx
, EVENT_INTERFACE_STATUS
, &event
);
1654 /* Called when an adapter is removed */
1655 void wpa_driver_ndis_event_adapter_removal(struct wpa_driver_ndis_data
*drv
)
1657 union wpa_event_data event
;
1659 wpa_printf(MSG_DEBUG
, "NDIS: Notify Adapter Removal");
1660 os_memset(&event
, 0, sizeof(event
));
1661 os_strlcpy(event
.interface_status
.ifname
, drv
->ifname
,
1662 sizeof(event
.interface_status
.ifname
));
1663 event
.interface_status
.ievent
= EVENT_INTERFACE_REMOVED
;
1664 wpa_supplicant_event(drv
->ctx
, EVENT_INTERFACE_STATUS
, &event
);
1669 wpa_driver_ndis_get_wpa_capability(struct wpa_driver_ndis_data
*drv
)
1671 wpa_printf(MSG_DEBUG
, "NDIS: verifying driver WPA capability");
1673 if (ndis_set_auth_mode(drv
, Ndis802_11AuthModeWPA
) == 0 &&
1674 ndis_get_auth_mode(drv
) == Ndis802_11AuthModeWPA
) {
1675 wpa_printf(MSG_DEBUG
, "NDIS: WPA key management supported");
1676 drv
->capa
.key_mgmt
|= WPA_DRIVER_CAPA_KEY_MGMT_WPA
;
1679 if (ndis_set_auth_mode(drv
, Ndis802_11AuthModeWPAPSK
) == 0 &&
1680 ndis_get_auth_mode(drv
) == Ndis802_11AuthModeWPAPSK
) {
1681 wpa_printf(MSG_DEBUG
, "NDIS: WPA-PSK key management "
1683 drv
->capa
.key_mgmt
|= WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK
;
1686 if (ndis_set_encr_status(drv
, Ndis802_11Encryption3Enabled
) == 0 &&
1687 ndis_get_encr_status(drv
) == Ndis802_11Encryption3KeyAbsent
) {
1688 wpa_printf(MSG_DEBUG
, "NDIS: CCMP encryption supported");
1689 drv
->capa
.enc
|= WPA_DRIVER_CAPA_ENC_CCMP
;
1692 if (ndis_set_encr_status(drv
, Ndis802_11Encryption2Enabled
) == 0 &&
1693 ndis_get_encr_status(drv
) == Ndis802_11Encryption2KeyAbsent
) {
1694 wpa_printf(MSG_DEBUG
, "NDIS: TKIP encryption supported");
1695 drv
->capa
.enc
|= WPA_DRIVER_CAPA_ENC_TKIP
;
1698 if (ndis_set_encr_status(drv
, Ndis802_11Encryption1Enabled
) == 0 &&
1699 ndis_get_encr_status(drv
) == Ndis802_11Encryption1KeyAbsent
) {
1700 wpa_printf(MSG_DEBUG
, "NDIS: WEP encryption supported");
1701 drv
->capa
.enc
|= WPA_DRIVER_CAPA_ENC_WEP40
|
1702 WPA_DRIVER_CAPA_ENC_WEP104
;
1705 if (ndis_set_auth_mode(drv
, Ndis802_11AuthModeShared
) == 0 &&
1706 ndis_get_auth_mode(drv
) == Ndis802_11AuthModeShared
) {
1707 drv
->capa
.auth
|= WPA_DRIVER_AUTH_SHARED
;
1710 if (ndis_set_auth_mode(drv
, Ndis802_11AuthModeOpen
) == 0 &&
1711 ndis_get_auth_mode(drv
) == Ndis802_11AuthModeOpen
) {
1712 drv
->capa
.auth
|= WPA_DRIVER_AUTH_OPEN
;
1715 ndis_set_encr_status(drv
, Ndis802_11EncryptionDisabled
);
1717 /* Could also verify OID_802_11_ADD_KEY error reporting and
1718 * support for OID_802_11_ASSOCIATION_INFORMATION. */
1720 if (drv
->capa
.key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_WPA
&&
1721 drv
->capa
.enc
& (WPA_DRIVER_CAPA_ENC_TKIP
|
1722 WPA_DRIVER_CAPA_ENC_CCMP
)) {
1723 wpa_printf(MSG_DEBUG
, "NDIS: driver supports WPA");
1724 drv
->has_capability
= 1;
1726 wpa_printf(MSG_DEBUG
, "NDIS: no WPA support found");
1729 wpa_printf(MSG_DEBUG
, "NDIS: driver capabilities: key_mgmt 0x%x "
1730 "enc 0x%x auth 0x%x",
1731 drv
->capa
.key_mgmt
, drv
->capa
.enc
, drv
->capa
.auth
);
1735 static void wpa_driver_ndis_get_capability(struct wpa_driver_ndis_data
*drv
)
1740 NDIS_802_11_CAPABILITY
*c
;
1742 drv
->capa
.flags
= WPA_DRIVER_FLAGS_DRIVER_IE
;
1744 len
= ndis_get_oid(drv
, OID_802_11_CAPABILITY
, buf
, sizeof(buf
));
1746 wpa_driver_ndis_get_wpa_capability(drv
);
1750 wpa_hexdump(MSG_MSGDUMP
, "OID_802_11_CAPABILITY", (u8
*) buf
, len
);
1751 c
= (NDIS_802_11_CAPABILITY
*) buf
;
1752 if (len
< sizeof(*c
) || c
->Version
!= 2) {
1753 wpa_printf(MSG_DEBUG
, "NDIS: unsupported "
1754 "OID_802_11_CAPABILITY data");
1757 wpa_printf(MSG_DEBUG
, "NDIS: Driver supports OID_802_11_CAPABILITY - "
1758 "NoOfPMKIDs %d NoOfAuthEncrPairs %d",
1759 (int) c
->NoOfPMKIDs
,
1760 (int) c
->NoOfAuthEncryptPairsSupported
);
1761 drv
->has_capability
= 1;
1762 drv
->no_of_pmkid
= c
->NoOfPMKIDs
;
1763 for (i
= 0; i
< c
->NoOfAuthEncryptPairsSupported
; i
++) {
1764 NDIS_802_11_AUTHENTICATION_ENCRYPTION
*ae
;
1765 ae
= &c
->AuthenticationEncryptionSupported
[i
];
1766 if ((char *) (ae
+ 1) > buf
+ len
) {
1767 wpa_printf(MSG_DEBUG
, "NDIS: auth/encr pair list "
1771 wpa_printf(MSG_MSGDUMP
, "NDIS: %d - auth %d encr %d",
1772 i
, (int) ae
->AuthModeSupported
,
1773 (int) ae
->EncryptStatusSupported
);
1774 switch (ae
->AuthModeSupported
) {
1775 case Ndis802_11AuthModeOpen
:
1776 drv
->capa
.auth
|= WPA_DRIVER_AUTH_OPEN
;
1778 case Ndis802_11AuthModeShared
:
1779 drv
->capa
.auth
|= WPA_DRIVER_AUTH_SHARED
;
1781 case Ndis802_11AuthModeWPA
:
1782 drv
->capa
.key_mgmt
|= WPA_DRIVER_CAPA_KEY_MGMT_WPA
;
1784 case Ndis802_11AuthModeWPAPSK
:
1785 drv
->capa
.key_mgmt
|= WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK
;
1787 case Ndis802_11AuthModeWPA2
:
1788 drv
->capa
.key_mgmt
|= WPA_DRIVER_CAPA_KEY_MGMT_WPA2
;
1790 case Ndis802_11AuthModeWPA2PSK
:
1791 drv
->capa
.key_mgmt
|=
1792 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK
;
1794 case Ndis802_11AuthModeWPANone
:
1795 drv
->capa
.key_mgmt
|=
1796 WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE
;
1801 switch (ae
->EncryptStatusSupported
) {
1802 case Ndis802_11Encryption1Enabled
:
1803 drv
->capa
.enc
|= WPA_DRIVER_CAPA_ENC_WEP40
;
1804 drv
->capa
.enc
|= WPA_DRIVER_CAPA_ENC_WEP104
;
1806 case Ndis802_11Encryption2Enabled
:
1807 drv
->capa
.enc
|= WPA_DRIVER_CAPA_ENC_TKIP
;
1809 case Ndis802_11Encryption3Enabled
:
1810 drv
->capa
.enc
|= WPA_DRIVER_CAPA_ENC_CCMP
;
1817 wpa_printf(MSG_DEBUG
, "NDIS: driver capabilities: key_mgmt 0x%x "
1818 "enc 0x%x auth 0x%x",
1819 drv
->capa
.key_mgmt
, drv
->capa
.enc
, drv
->capa
.auth
);
1823 static int wpa_driver_ndis_get_capa(void *priv
, struct wpa_driver_capa
*capa
)
1825 struct wpa_driver_ndis_data
*drv
= priv
;
1826 if (!drv
->has_capability
)
1828 os_memcpy(capa
, &drv
->capa
, sizeof(*capa
));
1833 static const char * wpa_driver_ndis_get_ifname(void *priv
)
1835 struct wpa_driver_ndis_data
*drv
= priv
;
1840 static const u8
* wpa_driver_ndis_get_mac_addr(void *priv
)
1842 struct wpa_driver_ndis_data
*drv
= priv
;
1843 return drv
->own_addr
;
1849 #define NDISUIO_MSG_SIZE (sizeof(NDISUIO_DEVICE_NOTIFICATION) + 512)
1851 static void ndisuio_notification_receive(void *eloop_data
, void *user_ctx
)
1853 struct wpa_driver_ndis_data
*drv
= eloop_data
;
1854 NDISUIO_DEVICE_NOTIFICATION
*hdr
;
1855 u8 buf
[NDISUIO_MSG_SIZE
];
1858 if (!ReadMsgQueue(drv
->event_queue
, buf
, NDISUIO_MSG_SIZE
, &len
, 0,
1860 wpa_printf(MSG_DEBUG
, "ndisuio_notification_receive: "
1861 "ReadMsgQueue failed: %d", (int) GetLastError());
1865 if (len
< sizeof(NDISUIO_DEVICE_NOTIFICATION
)) {
1866 wpa_printf(MSG_DEBUG
, "ndisuio_notification_receive: "
1867 "Too short message (len=%d)", (int) len
);
1871 hdr
= (NDISUIO_DEVICE_NOTIFICATION
*) buf
;
1872 wpa_printf(MSG_DEBUG
, "NDIS: Notification received: len=%d type=0x%x",
1873 (int) len
, hdr
->dwNotificationType
);
1875 switch (hdr
->dwNotificationType
) {
1876 #ifdef NDISUIO_NOTIFICATION_ADAPTER_ARRIVAL
1877 case NDISUIO_NOTIFICATION_ADAPTER_ARRIVAL
:
1878 wpa_printf(MSG_DEBUG
, "NDIS: ADAPTER_ARRIVAL");
1879 wpa_driver_ndis_event_adapter_arrival(drv
);
1882 #ifdef NDISUIO_NOTIFICATION_ADAPTER_REMOVAL
1883 case NDISUIO_NOTIFICATION_ADAPTER_REMOVAL
:
1884 wpa_printf(MSG_DEBUG
, "NDIS: ADAPTER_REMOVAL");
1885 wpa_driver_ndis_event_adapter_removal(drv
);
1888 case NDISUIO_NOTIFICATION_MEDIA_CONNECT
:
1889 wpa_printf(MSG_DEBUG
, "NDIS: MEDIA_CONNECT");
1890 SetEvent(drv
->connected_event
);
1891 wpa_driver_ndis_event_connect(drv
);
1893 case NDISUIO_NOTIFICATION_MEDIA_DISCONNECT
:
1894 ResetEvent(drv
->connected_event
);
1895 wpa_printf(MSG_DEBUG
, "NDIS: MEDIA_DISCONNECT");
1896 wpa_driver_ndis_event_disconnect(drv
);
1898 case NDISUIO_NOTIFICATION_MEDIA_SPECIFIC_NOTIFICATION
:
1899 wpa_printf(MSG_DEBUG
, "NDIS: MEDIA_SPECIFIC_NOTIFICATION");
1900 #if _WIN32_WCE == 420 || _WIN32_WCE == 0x420
1901 wpa_driver_ndis_event_media_specific(
1902 drv
, hdr
->pvStatusBuffer
, hdr
->uiStatusBufferSize
);
1904 wpa_driver_ndis_event_media_specific(
1905 drv
, ((const u8
*) hdr
) + hdr
->uiOffsetToStatusBuffer
,
1906 (size_t) hdr
->uiStatusBufferSize
);
1910 wpa_printf(MSG_DEBUG
, "NDIS: Unknown notification type 0x%x",
1911 hdr
->dwNotificationType
);
1917 static void ndisuio_notification_deinit(struct wpa_driver_ndis_data
*drv
)
1919 NDISUIO_REQUEST_NOTIFICATION req
;
1921 memset(&req
, 0, sizeof(req
));
1922 req
.hMsgQueue
= drv
->event_queue
;
1923 req
.dwNotificationTypes
= 0;
1925 if (!DeviceIoControl(drv
->ndisuio
, IOCTL_NDISUIO_REQUEST_NOTIFICATION
,
1926 &req
, sizeof(req
), NULL
, 0, NULL
, NULL
)) {
1927 wpa_printf(MSG_INFO
, "ndisuio_notification_deinit: "
1928 "IOCTL_NDISUIO_REQUEST_NOTIFICATION failed: %d",
1929 (int) GetLastError());
1932 if (!DeviceIoControl(drv
->ndisuio
, IOCTL_NDISUIO_CANCEL_NOTIFICATION
,
1933 NULL
, 0, NULL
, 0, NULL
, NULL
)) {
1934 wpa_printf(MSG_INFO
, "ndisuio_notification_deinit: "
1935 "IOCTL_NDISUIO_CANCEL_NOTIFICATION failed: %d",
1936 (int) GetLastError());
1939 if (drv
->event_queue
) {
1940 eloop_unregister_event(drv
->event_queue
,
1941 sizeof(drv
->event_queue
));
1942 CloseHandle(drv
->event_queue
);
1943 drv
->event_queue
= NULL
;
1946 if (drv
->connected_event
) {
1947 CloseHandle(drv
->connected_event
);
1948 drv
->connected_event
= NULL
;
1953 static int ndisuio_notification_init(struct wpa_driver_ndis_data
*drv
)
1955 MSGQUEUEOPTIONS opt
;
1956 NDISUIO_REQUEST_NOTIFICATION req
;
1958 drv
->connected_event
=
1959 CreateEvent(NULL
, TRUE
, FALSE
, TEXT("WpaSupplicantConnected"));
1960 if (drv
->connected_event
== NULL
) {
1961 wpa_printf(MSG_INFO
, "ndisuio_notification_init: "
1962 "CreateEvent failed: %d",
1963 (int) GetLastError());
1967 memset(&opt
, 0, sizeof(opt
));
1968 opt
.dwSize
= sizeof(opt
);
1969 opt
.dwMaxMessages
= 5;
1970 opt
.cbMaxMessage
= NDISUIO_MSG_SIZE
;
1971 opt
.bReadAccess
= TRUE
;
1973 drv
->event_queue
= CreateMsgQueue(NULL
, &opt
);
1974 if (drv
->event_queue
== NULL
) {
1975 wpa_printf(MSG_INFO
, "ndisuio_notification_init: "
1976 "CreateMsgQueue failed: %d",
1977 (int) GetLastError());
1978 ndisuio_notification_deinit(drv
);
1982 memset(&req
, 0, sizeof(req
));
1983 req
.hMsgQueue
= drv
->event_queue
;
1984 req
.dwNotificationTypes
=
1985 #ifdef NDISUIO_NOTIFICATION_ADAPTER_ARRIVAL
1986 NDISUIO_NOTIFICATION_ADAPTER_ARRIVAL
|
1988 #ifdef NDISUIO_NOTIFICATION_ADAPTER_REMOVAL
1989 NDISUIO_NOTIFICATION_ADAPTER_REMOVAL
|
1991 NDISUIO_NOTIFICATION_MEDIA_CONNECT
|
1992 NDISUIO_NOTIFICATION_MEDIA_DISCONNECT
|
1993 NDISUIO_NOTIFICATION_MEDIA_SPECIFIC_NOTIFICATION
;
1995 if (!DeviceIoControl(drv
->ndisuio
, IOCTL_NDISUIO_REQUEST_NOTIFICATION
,
1996 &req
, sizeof(req
), NULL
, 0, NULL
, NULL
)) {
1997 wpa_printf(MSG_INFO
, "ndisuio_notification_init: "
1998 "IOCTL_NDISUIO_REQUEST_NOTIFICATION failed: %d",
1999 (int) GetLastError());
2000 ndisuio_notification_deinit(drv
);
2004 eloop_register_event(drv
->event_queue
, sizeof(drv
->event_queue
),
2005 ndisuio_notification_receive
, drv
, NULL
);
2009 #endif /* _WIN32_WCE */
2012 static int wpa_driver_ndis_get_names(struct wpa_driver_ndis_data
*drv
)
2014 #ifdef CONFIG_USE_NDISUIO
2015 NDISUIO_QUERY_BINDING
*b
;
2016 size_t blen
= sizeof(*b
) + 1024;
2017 int i
, error
, found
= 0;
2019 char name
[256], desc
[256], *dpos
;
2021 size_t j
, len
, dlen
;
2023 b
= os_malloc(blen
);
2027 for (i
= 0; ; i
++) {
2028 os_memset(b
, 0, blen
);
2029 b
->BindingIndex
= i
;
2030 if (!DeviceIoControl(drv
->ndisuio
, IOCTL_NDISUIO_QUERY_BINDING
,
2031 b
, sizeof(NDISUIO_QUERY_BINDING
), b
, blen
,
2033 error
= (int) GetLastError();
2034 if (error
== ERROR_NO_MORE_ITEMS
)
2036 wpa_printf(MSG_DEBUG
, "IOCTL_NDISUIO_QUERY_BINDING "
2037 "failed: %d", error
);
2041 pos
= (WCHAR
*) ((char *) b
+ b
->DeviceNameOffset
);
2042 len
= b
->DeviceNameLength
;
2043 if (len
>= sizeof(name
))
2044 len
= sizeof(name
) - 1;
2045 for (j
= 0; j
< len
; j
++)
2046 name
[j
] = (char) pos
[j
];
2049 pos
= (WCHAR
*) ((char *) b
+ b
->DeviceDescrOffset
);
2050 len
= b
->DeviceDescrLength
;
2051 if (len
>= sizeof(desc
))
2052 len
= sizeof(desc
) - 1;
2053 for (j
= 0; j
< len
; j
++)
2054 desc
[j
] = (char) pos
[j
];
2057 wpa_printf(MSG_DEBUG
, "NDIS: %d - %s - %s", i
, name
, desc
);
2059 if (os_strstr(name
, drv
->ifname
)) {
2060 wpa_printf(MSG_DEBUG
, "NDIS: Interface name match");
2065 if (os_strncmp(desc
, drv
->ifname
, os_strlen(drv
->ifname
)) == 0)
2067 wpa_printf(MSG_DEBUG
, "NDIS: Interface description "
2075 wpa_printf(MSG_DEBUG
, "NDIS: Could not find interface '%s'",
2081 os_strlcpy(drv
->ifname
,
2082 os_strncmp(name
, "\\DEVICE\\", 8) == 0 ? name
+ 8 : name
,
2083 sizeof(drv
->ifname
));
2085 drv
->adapter_name
= wpa_strdup_tchar(drv
->ifname
);
2086 if (drv
->adapter_name
== NULL
) {
2087 wpa_printf(MSG_ERROR
, "NDIS: Failed to allocate memory for "
2092 #endif /* _WIN32_WCE */
2094 dpos
= os_strstr(desc
, " - ");
2098 dlen
= os_strlen(desc
);
2099 drv
->adapter_desc
= os_malloc(dlen
+ 1);
2100 if (drv
->adapter_desc
) {
2101 os_memcpy(drv
->adapter_desc
, desc
, dlen
);
2102 drv
->adapter_desc
[dlen
] = '\0';
2107 if (drv
->adapter_desc
== NULL
)
2110 wpa_printf(MSG_DEBUG
, "NDIS: Adapter description prefix '%s'",
2114 #else /* CONFIG_USE_NDISUIO */
2116 char *names
, *pos
, *pos2
;
2119 #define MAX_ADAPTERS 32
2120 char *name
[MAX_ADAPTERS
];
2121 char *desc
[MAX_ADAPTERS
];
2122 int num_name
, num_desc
, i
, found_name
, found_desc
;
2125 wpa_printf(MSG_DEBUG
, "NDIS: Packet.dll version: %s",
2126 PacketGetVersion());
2129 _names
= os_zalloc(len
);
2133 res
= PacketGetAdapterNames(_names
, &len
);
2134 if (!res
&& len
> 8192) {
2136 _names
= os_zalloc(len
);
2139 res
= PacketGetAdapterNames(_names
, &len
);
2143 wpa_printf(MSG_ERROR
, "NDIS: Failed to get adapter list "
2144 "(PacketGetAdapterNames)");
2149 names
= (char *) _names
;
2150 if (names
[0] && names
[1] == '\0' && names
[2] && names
[3] == '\0') {
2151 wpa_printf(MSG_DEBUG
, "NDIS: Looks like adapter names are in "
2153 /* Convert to ASCII */
2155 while (pos2
< names
+ len
) {
2156 if (pos2
[0] == '\0' && pos2
[1] == '\0' &&
2157 pos2
[2] == '\0' && pos2
[3] == '\0') {
2164 os_memcpy(pos
+ 2, names
, pos
- names
);
2170 while (pos
< names
+ len
) {
2171 name
[num_name
] = pos
;
2172 while (*pos
&& pos
< names
+ len
)
2174 if (pos
+ 1 >= names
+ len
) {
2180 if (num_name
>= MAX_ADAPTERS
) {
2181 wpa_printf(MSG_DEBUG
, "NDIS: Too many adapters");
2186 wpa_printf(MSG_DEBUG
, "NDIS: %d adapter names found",
2194 while (pos
< names
+ len
) {
2195 desc
[num_desc
] = pos
;
2196 while (*pos
&& pos
< names
+ len
)
2198 if (pos
+ 1 >= names
+ len
) {
2204 if (num_desc
>= MAX_ADAPTERS
) {
2205 wpa_printf(MSG_DEBUG
, "NDIS: Too many adapter "
2211 wpa_printf(MSG_DEBUG
, "NDIS: %d adapter descriptions "
2219 * Windows 98 with Packet.dll 3.0 alpha3 does not include adapter
2220 * descriptions. Fill in dummy descriptors to work around this.
2222 while (num_desc
< num_name
)
2223 desc
[num_desc
++] = "dummy description";
2225 if (num_name
!= num_desc
) {
2226 wpa_printf(MSG_DEBUG
, "NDIS: mismatch in adapter name and "
2227 "description counts (%d != %d)",
2228 num_name
, num_desc
);
2233 found_name
= found_desc
= -1;
2234 for (i
= 0; i
< num_name
; i
++) {
2235 wpa_printf(MSG_DEBUG
, "NDIS: %d - %s - %s",
2236 i
, name
[i
], desc
[i
]);
2237 if (found_name
== -1 && os_strstr(name
[i
], drv
->ifname
))
2239 if (found_desc
== -1 &&
2240 os_strncmp(desc
[i
], drv
->ifname
, os_strlen(drv
->ifname
)) ==
2245 if (found_name
< 0 && found_desc
>= 0) {
2246 wpa_printf(MSG_DEBUG
, "NDIS: Matched interface '%s' based on "
2248 name
[found_desc
], desc
[found_desc
]);
2249 found_name
= found_desc
;
2250 os_strlcpy(drv
->ifname
,
2251 os_strncmp(name
[found_desc
], "\\Device\\NPF_", 12)
2252 == 0 ? name
[found_desc
] + 12 : name
[found_desc
],
2253 sizeof(drv
->ifname
));
2256 if (found_name
< 0) {
2257 wpa_printf(MSG_DEBUG
, "NDIS: Could not find interface '%s'",
2264 pos
= os_strrchr(desc
[i
], '(');
2266 dlen
= pos
- desc
[i
];
2268 if (pos
> desc
[i
] && *pos
== ' ')
2271 dlen
= os_strlen(desc
[i
]);
2273 drv
->adapter_desc
= os_malloc(dlen
+ 1);
2274 if (drv
->adapter_desc
) {
2275 os_memcpy(drv
->adapter_desc
, desc
[i
], dlen
);
2276 drv
->adapter_desc
[dlen
] = '\0';
2281 if (drv
->adapter_desc
== NULL
)
2284 wpa_printf(MSG_DEBUG
, "NDIS: Adapter description prefix '%s'",
2288 #endif /* CONFIG_USE_NDISUIO */
2292 #if defined(CONFIG_NATIVE_WINDOWS) || defined(__CYGWIN__)
2295 * These structures are undocumented for WinXP; only WinCE version is
2296 * documented. These would be included wzcsapi.h if it were available. Some
2297 * changes here have been needed to make the structures match with WinXP SP2.
2298 * It is unclear whether these work with any other version.
2303 } INTF_KEY_ENTRY
, *PINTF_KEY_ENTRY
;
2307 PINTF_KEY_ENTRY pIntfs
;
2308 } INTFS_KEY_TABLE
, *PINTFS_KEY_TABLE
;
2313 } RAW_DATA
, *PRAW_DATA
;
2320 ULONG ulPhysicalMediaType
;
2325 u8 pad
[2]; /* why is this needed? */
2326 #endif /* _WIN32_WCE */
2328 DWORD dwCapabilities
; /* something added for WinXP SP2(?) */
2331 RAW_DATA rdBSSIDList
;
2332 RAW_DATA rdStSSIDList
;
2333 RAW_DATA rdCtrlData
;
2337 DWORD nWPAMCastCipher
;
2338 /* add some extra buffer for later additions since this interface is
2339 * far from stable */
2340 u8 later_additions
[100];
2341 } INTF_ENTRY
, *PINTF_ENTRY
;
2343 #define INTF_ALL 0xffffffff
2344 #define INTF_ALL_FLAGS 0x0000ffff
2345 #define INTF_CTLFLAGS 0x00000010
2346 #define INTFCTL_ENABLED 0x8000
2347 #endif /* _WIN32_WCE */
2351 static int wpa_driver_ndis_rebind_adapter(struct wpa_driver_ndis_data
*drv
)
2357 len
= _tcslen(drv
->adapter_name
);
2361 ndis
= CreateFile(DD_NDIS_DEVICE_NAME
, GENERIC_READ
| GENERIC_WRITE
,
2362 0, NULL
, OPEN_EXISTING
, 0, NULL
);
2363 if (ndis
== INVALID_HANDLE_VALUE
) {
2364 wpa_printf(MSG_DEBUG
, "NDIS: Failed to open file to NDIS "
2365 "device: %d", (int) GetLastError());
2370 memcpy(multi
, drv
->adapter_name
, len
* sizeof(TCHAR
));
2371 memcpy(&multi
[len
], TEXT("NDISUIO\0"), 9 * sizeof(TCHAR
));
2374 if (!DeviceIoControl(ndis
, IOCTL_NDIS_REBIND_ADAPTER
,
2375 multi
, len
* sizeof(TCHAR
), NULL
, 0, NULL
, NULL
))
2377 wpa_printf(MSG_DEBUG
, "NDIS: IOCTL_NDIS_REBIND_ADAPTER "
2378 "failed: 0x%x", (int) GetLastError());
2379 wpa_hexdump_ascii(MSG_DEBUG
, "NDIS: rebind multi_sz",
2380 (u8
*) multi
, len
* sizeof(TCHAR
));
2387 wpa_printf(MSG_DEBUG
, "NDIS: Requested NDIS rebind of NDISUIO "
2392 #endif /* _WIN32_WCE */
2395 static int wpa_driver_ndis_set_wzc(struct wpa_driver_ndis_data
*drv
,
2402 TCHAR keyname
[256], devname
[256];
2404 #define WZC_DRIVER TEXT("Drivers\\BuiltIn\\ZeroConfig")
2408 h
= ActivateDeviceEx(WZC_DRIVER
, NULL
, 0, NULL
);
2409 if (h
== INVALID_HANDLE_VALUE
|| h
== 0) {
2410 wpa_printf(MSG_DEBUG
, "NDIS: Failed to re-enable WZC "
2411 "- ActivateDeviceEx failed: %d",
2412 (int) GetLastError());
2416 wpa_printf(MSG_DEBUG
, "NDIS: WZC re-enabled");
2417 return wpa_driver_ndis_rebind_adapter(drv
);
2421 * Unfortunately, just disabling the WZC for an interface is not enough
2422 * to free NDISUIO for us, so need to disable and unload WZC completely
2423 * for now when using WinCE with NDISUIO. In addition, must request
2424 * NDISUIO protocol to be rebound to the adapter in order to free the
2425 * NDISUIO binding that WZC hold before us.
2428 /* Enumerate HKLM\Drivers\Active\* to find a handle to WZC. */
2429 ret
= RegOpenKeyEx(HKEY_LOCAL_MACHINE
, DEVLOAD_ACTIVE_KEY
, 0, 0, &hk
);
2430 if (ret
!= ERROR_SUCCESS
) {
2431 wpa_printf(MSG_DEBUG
, "NDIS: RegOpenKeyEx(DEVLOAD_ACTIVE_KEY) "
2432 "failed: %d %d", (int) ret
, (int) GetLastError());
2436 for (i
= 0; ; i
++) {
2437 len
= sizeof(keyname
);
2438 ret
= RegEnumKeyEx(hk
, i
, keyname
, &len
, NULL
, NULL
, NULL
,
2440 if (ret
!= ERROR_SUCCESS
) {
2441 wpa_printf(MSG_DEBUG
, "NDIS: Could not find active "
2442 "WZC - assuming it is not running.");
2447 ret
= RegOpenKeyEx(hk
, keyname
, 0, 0, &hk2
);
2448 if (ret
!= ERROR_SUCCESS
) {
2449 wpa_printf(MSG_DEBUG
, "NDIS: RegOpenKeyEx(active dev) "
2451 (int) ret
, (int) GetLastError());
2455 len
= sizeof(devname
);
2456 ret
= RegQueryValueEx(hk2
, DEVLOAD_DEVKEY_VALNAME
, NULL
, NULL
,
2457 (LPBYTE
) devname
, &len
);
2458 if (ret
!= ERROR_SUCCESS
) {
2459 wpa_printf(MSG_DEBUG
, "NDIS: RegQueryValueEx("
2460 "DEVKEY_VALNAME) failed: %d %d",
2461 (int) ret
, (int) GetLastError());
2466 if (_tcscmp(devname
, WZC_DRIVER
) == 0)
2474 /* Found WZC - get handle to it. */
2476 ret
= RegQueryValueEx(hk2
, DEVLOAD_HANDLE_VALNAME
, NULL
, NULL
,
2477 (PUCHAR
) &hnd
, &len
);
2478 if (ret
!= ERROR_SUCCESS
) {
2479 wpa_printf(MSG_DEBUG
, "NDIS: RegQueryValueEx(HANDLE_VALNAME) "
2480 "failed: %d %d", (int) ret
, (int) GetLastError());
2487 /* Deactivate WZC */
2488 if (!DeactivateDevice((HANDLE
) hnd
)) {
2489 wpa_printf(MSG_DEBUG
, "NDIS: DeactivateDevice failed: %d",
2490 (int) GetLastError());
2494 wpa_printf(MSG_DEBUG
, "NDIS: Disabled WZC temporarily");
2495 drv
->wzc_disabled
= 1;
2496 return wpa_driver_ndis_rebind_adapter(drv
);
2498 #else /* _WIN32_WCE */
2501 DWORD (WINAPI
*wzc_enum_interf
)(LPWSTR pSrvAddr
,
2502 PINTFS_KEY_TABLE pIntfs
);
2503 DWORD (WINAPI
*wzc_query_interf
)(LPWSTR pSrvAddr
, DWORD dwInFlags
,
2505 LPDWORD pdwOutFlags
);
2506 DWORD (WINAPI
*wzc_set_interf
)(LPWSTR pSrvAddr
, DWORD dwInFlags
,
2507 PINTF_ENTRY pIntf
, LPDWORD pdwOutFlags
);
2510 INTFS_KEY_TABLE guids
;
2516 hm
= LoadLibrary(TEXT("wzcsapi.dll"));
2518 wpa_printf(MSG_DEBUG
, "NDIS: Failed to load wzcsapi.dll (%u) "
2519 "- WZC probably not running",
2520 (unsigned int) GetLastError());
2525 wzc_enum_interf
= (void *) GetProcAddressA(hm
, "WZCEnumInterfaces");
2526 wzc_query_interf
= (void *) GetProcAddressA(hm
, "WZCQueryInterface");
2527 wzc_set_interf
= (void *) GetProcAddressA(hm
, "WZCSetInterface");
2528 #else /* _WIN32_WCE */
2529 wzc_enum_interf
= (void *) GetProcAddress(hm
, "WZCEnumInterfaces");
2530 wzc_query_interf
= (void *) GetProcAddress(hm
, "WZCQueryInterface");
2531 wzc_set_interf
= (void *) GetProcAddress(hm
, "WZCSetInterface");
2532 #endif /* _WIN32_WCE */
2534 if (wzc_enum_interf
== NULL
|| wzc_query_interf
== NULL
||
2535 wzc_set_interf
== NULL
) {
2536 wpa_printf(MSG_DEBUG
, "NDIS: WZCEnumInterfaces, "
2537 "WZCQueryInterface, or WZCSetInterface not found "
2542 os_memset(&guids
, 0, sizeof(guids
));
2543 res
= wzc_enum_interf(NULL
, &guids
);
2545 wpa_printf(MSG_DEBUG
, "NDIS: WZCEnumInterfaces failed: %d; "
2546 "WZC service is apparently not running",
2551 wpa_printf(MSG_DEBUG
, "NDIS: WZCEnumInterfaces: %d interfaces",
2552 (int) guids
.dwNumIntfs
);
2554 for (i
= 0; i
< guids
.dwNumIntfs
; i
++) {
2555 pos
= guids
.pIntfs
[i
].wszGuid
;
2556 for (j
= 0; j
< sizeof(guid
); j
++) {
2557 guid
[j
] = (char) *pos
;
2562 guid
[sizeof(guid
) - 1] = '\0';
2563 wpa_printf(MSG_DEBUG
, "NDIS: intfs %d GUID '%s'",
2565 if (os_strstr(drv
->ifname
, guid
) == NULL
)
2568 wpa_printf(MSG_DEBUG
, "NDIS: Current interface found from "
2573 if (i
>= guids
.dwNumIntfs
) {
2574 wpa_printf(MSG_DEBUG
, "NDIS: Current interface not found from "
2579 os_memset(&intf
, 0, sizeof(intf
));
2580 intf
.wszGuid
= guids
.pIntfs
[i
].wszGuid
;
2581 /* Set flags to verify that the structure has not changed. */
2582 intf
.dwCtlFlags
= -1;
2584 res
= wzc_query_interf(NULL
, INTFCTL_ENABLED
, &intf
, &flags
);
2586 wpa_printf(MSG_DEBUG
, "NDIS: Could not query flags for the "
2587 "WZC interface: %d (0x%x)",
2588 (int) res
, (int) res
);
2589 wpa_printf(MSG_DEBUG
, "NDIS: GetLastError: %u",
2590 (unsigned int) GetLastError());
2594 wpa_printf(MSG_DEBUG
, "NDIS: WZC interface flags 0x%x dwCtlFlags 0x%x",
2595 (int) flags
, (int) intf
.dwCtlFlags
);
2597 if (intf
.dwCtlFlags
== -1) {
2598 wpa_printf(MSG_DEBUG
, "NDIS: Looks like wzcsapi has changed "
2599 "again - could not disable WZC");
2600 wpa_hexdump(MSG_MSGDUMP
, "NDIS: intf",
2601 (u8
*) &intf
, sizeof(intf
));
2606 if (!(intf
.dwCtlFlags
& INTFCTL_ENABLED
)) {
2607 wpa_printf(MSG_DEBUG
, "NDIS: Enabling WZC for this "
2609 intf
.dwCtlFlags
|= INTFCTL_ENABLED
;
2610 res
= wzc_set_interf(NULL
, INTFCTL_ENABLED
, &intf
,
2613 wpa_printf(MSG_DEBUG
, "NDIS: Failed to enable "
2615 (int) res
, (int) res
);
2616 wpa_printf(MSG_DEBUG
, "NDIS: GetLastError: %u",
2617 (unsigned int) GetLastError());
2620 wpa_printf(MSG_DEBUG
, "NDIS: Re-enabled WZC for this "
2622 drv
->wzc_disabled
= 0;
2625 if (intf
.dwCtlFlags
& INTFCTL_ENABLED
) {
2626 wpa_printf(MSG_DEBUG
, "NDIS: Disabling WZC for this "
2628 intf
.dwCtlFlags
&= ~INTFCTL_ENABLED
;
2629 res
= wzc_set_interf(NULL
, INTFCTL_ENABLED
, &intf
,
2632 wpa_printf(MSG_DEBUG
, "NDIS: Failed to "
2633 "disable WZC: %d (0x%x)",
2634 (int) res
, (int) res
);
2635 wpa_printf(MSG_DEBUG
, "NDIS: GetLastError: %u",
2636 (unsigned int) GetLastError());
2639 wpa_printf(MSG_DEBUG
, "NDIS: Disabled WZC temporarily "
2640 "for this interface");
2641 drv
->wzc_disabled
= 1;
2643 wpa_printf(MSG_DEBUG
, "NDIS: WZC was not enabled for "
2654 #endif /* _WIN32_WCE */
2657 #else /* CONFIG_NATIVE_WINDOWS || __CYGWIN__ */
2659 static int wpa_driver_ndis_set_wzc(struct wpa_driver_ndis_data
*drv
,
2665 #endif /* CONFIG_NATIVE_WINDOWS || __CYGWIN__ */
2668 #ifdef CONFIG_USE_NDISUIO
2670 * l2_packet_ndis.c is sharing the same handle to NDISUIO, so we must be able
2671 * to export this handle. This is somewhat ugly, but there is no better
2672 * mechanism available to pass data from driver interface to l2_packet wrapper.
2674 static HANDLE driver_ndis_ndisuio_handle
= INVALID_HANDLE_VALUE
;
2676 HANDLE
driver_ndis_get_ndisuio_handle(void)
2678 return driver_ndis_ndisuio_handle
;
2680 #endif /* CONFIG_USE_NDISUIO */
2683 static int wpa_driver_ndis_adapter_init(struct wpa_driver_ndis_data
*drv
)
2685 #ifdef CONFIG_USE_NDISUIO
2687 #define NDISUIO_DEVICE_NAME TEXT("\\\\.\\\\Ndisuio")
2689 #endif /* _WIN32_WCE */
2690 drv
->ndisuio
= CreateFile(NDISUIO_DEVICE_NAME
,
2691 GENERIC_READ
| GENERIC_WRITE
, 0, NULL
,
2693 FILE_ATTRIBUTE_NORMAL
| FILE_FLAG_OVERLAPPED
,
2694 INVALID_HANDLE_VALUE
);
2695 if (drv
->ndisuio
== INVALID_HANDLE_VALUE
) {
2696 wpa_printf(MSG_ERROR
, "NDIS: Failed to open connection to "
2697 "NDISUIO: %d", (int) GetLastError());
2700 driver_ndis_ndisuio_handle
= drv
->ndisuio
;
2703 if (!DeviceIoControl(drv
->ndisuio
, IOCTL_NDISUIO_BIND_WAIT
, NULL
, 0,
2704 NULL
, 0, &written
, NULL
)) {
2705 wpa_printf(MSG_ERROR
, "NDIS: IOCTL_NDISUIO_BIND_WAIT failed: "
2706 "%d", (int) GetLastError());
2707 CloseHandle(drv
->ndisuio
);
2708 drv
->ndisuio
= INVALID_HANDLE_VALUE
;
2711 #endif /* _WIN32_WCE */
2714 #else /* CONFIG_USE_NDISUIO */
2716 #endif /* CONFIG_USE_NDISUIO */
2720 static int wpa_driver_ndis_adapter_open(struct wpa_driver_ndis_data
*drv
)
2722 #ifdef CONFIG_USE_NDISUIO
2724 #define MAX_NDIS_DEVICE_NAME_LEN 256
2725 WCHAR ifname
[MAX_NDIS_DEVICE_NAME_LEN
];
2727 const char *prefix
= "\\DEVICE\\";
2731 #else /* _WIN32_WCE */
2733 #endif /* _WIN32_WCE */
2734 len
= pos
+ os_strlen(drv
->ifname
);
2735 if (len
>= MAX_NDIS_DEVICE_NAME_LEN
)
2737 for (i
= 0; i
< pos
; i
++)
2738 ifname
[i
] = (WCHAR
) prefix
[i
];
2739 for (i
= pos
; i
< len
; i
++)
2740 ifname
[i
] = (WCHAR
) drv
->ifname
[i
- pos
];
2743 if (!DeviceIoControl(drv
->ndisuio
, IOCTL_NDISUIO_OPEN_DEVICE
,
2744 ifname
, len
* sizeof(WCHAR
), NULL
, 0, &written
,
2746 wpa_printf(MSG_ERROR
, "NDIS: IOCTL_NDISUIO_OPEN_DEVICE "
2747 "failed: %d", (int) GetLastError());
2748 wpa_hexdump_ascii(MSG_DEBUG
, "NDIS: ifname",
2749 (const u8
*) ifname
, len
* sizeof(WCHAR
));
2750 CloseHandle(drv
->ndisuio
);
2751 drv
->ndisuio
= INVALID_HANDLE_VALUE
;
2755 wpa_printf(MSG_DEBUG
, "NDIS: Opened NDISUIO device successfully");
2758 #else /* CONFIG_USE_NDISUIO */
2760 os_snprintf(ifname
, sizeof(ifname
), "\\Device\\NPF_%s", drv
->ifname
);
2761 drv
->adapter
= PacketOpenAdapter(ifname
);
2762 if (drv
->adapter
== NULL
) {
2763 wpa_printf(MSG_DEBUG
, "NDIS: PacketOpenAdapter failed for "
2768 #endif /* CONFIG_USE_NDISUIO */
2772 static void wpa_driver_ndis_adapter_close(struct wpa_driver_ndis_data
*drv
)
2774 #ifdef CONFIG_USE_NDISUIO
2775 driver_ndis_ndisuio_handle
= INVALID_HANDLE_VALUE
;
2776 if (drv
->ndisuio
!= INVALID_HANDLE_VALUE
)
2777 CloseHandle(drv
->ndisuio
);
2778 #else /* CONFIG_USE_NDISUIO */
2780 PacketCloseAdapter(drv
->adapter
);
2781 #endif /* CONFIG_USE_NDISUIO */
2785 static int ndis_add_multicast(struct wpa_driver_ndis_data
*drv
)
2787 if (ndis_set_oid(drv
, OID_802_3_MULTICAST_LIST
,
2788 (const char *) pae_group_addr
, ETH_ALEN
) < 0) {
2789 wpa_printf(MSG_DEBUG
, "NDIS: Failed to add PAE group address "
2790 "to the multicast list");
2798 static void * wpa_driver_ndis_init(void *ctx
, const char *ifname
)
2800 struct wpa_driver_ndis_data
*drv
;
2803 drv
= os_zalloc(sizeof(*drv
));
2808 * Compatibility code to strip possible prefix from the GUID. Previous
2809 * versions include \Device\NPF_ prefix for all names, but the internal
2810 * interface name is now only the GUI. Both Packet32 and NDISUIO
2811 * prefixes are supported.
2813 if (os_strncmp(ifname
, "\\Device\\NPF_", 12) == 0)
2815 else if (os_strncmp(ifname
, "\\DEVICE\\", 8) == 0)
2817 os_strlcpy(drv
->ifname
, ifname
, sizeof(drv
->ifname
));
2819 if (wpa_driver_ndis_adapter_init(drv
) < 0) {
2824 if (wpa_driver_ndis_get_names(drv
) < 0) {
2825 wpa_driver_ndis_adapter_close(drv
);
2830 wpa_driver_ndis_set_wzc(drv
, 0);
2832 if (wpa_driver_ndis_adapter_open(drv
) < 0) {
2833 wpa_driver_ndis_adapter_close(drv
);
2838 if (ndis_get_oid(drv
, OID_802_3_CURRENT_ADDRESS
,
2839 (char *) drv
->own_addr
, ETH_ALEN
) < 0) {
2840 wpa_printf(MSG_DEBUG
, "NDIS: Get OID_802_3_CURRENT_ADDRESS "
2842 wpa_driver_ndis_adapter_close(drv
);
2846 wpa_driver_ndis_get_capability(drv
);
2848 /* Make sure that the driver does not have any obsolete PMKID entries.
2850 wpa_driver_ndis_flush_pmkid(drv
);
2853 * Disconnect to make sure that driver re-associates if it was
2856 wpa_driver_ndis_disconnect(drv
);
2858 eloop_register_timeout(1, 0, wpa_driver_ndis_poll_timeout
, drv
, NULL
);
2860 #ifdef CONFIG_NDIS_EVENTS_INTEGRATED
2861 drv
->events
= ndis_events_init(&drv
->events_pipe
, &drv
->event_avail
,
2862 drv
->ifname
, drv
->adapter_desc
);
2863 if (drv
->events
== NULL
) {
2864 wpa_driver_ndis_deinit(drv
);
2867 eloop_register_event(drv
->event_avail
, sizeof(drv
->event_avail
),
2868 wpa_driver_ndis_event_pipe_cb
, drv
, NULL
);
2869 #endif /* CONFIG_NDIS_EVENTS_INTEGRATED */
2872 if (ndisuio_notification_init(drv
) < 0) {
2873 wpa_driver_ndis_deinit(drv
);
2876 #endif /* _WIN32_WCE */
2878 /* Set mode here in case card was configured for ad-hoc mode
2880 mode
= Ndis802_11Infrastructure
;
2881 if (ndis_set_oid(drv
, OID_802_11_INFRASTRUCTURE_MODE
,
2882 (char *) &mode
, sizeof(mode
)) < 0) {
2885 wpa_printf(MSG_DEBUG
, "NDIS: Failed to set "
2886 "OID_802_11_INFRASTRUCTURE_MODE (%d)",
2888 /* Try to continue anyway */
2890 res
= ndis_get_oid(drv
, OID_DOT11_CURRENT_OPERATION_MODE
, buf
,
2893 wpa_printf(MSG_INFO
, "NDIS: The driver seems to use "
2894 "Native 802.11 OIDs. These are not yet "
2895 "fully supported.");
2896 drv
->native80211
= 1;
2897 } else if (!drv
->has_capability
|| drv
->capa
.enc
== 0) {
2899 * Note: This will also happen with NDIS 6 drivers with
2902 wpa_printf(MSG_DEBUG
, "NDIS: Driver did not provide "
2903 "any wireless capabilities - assume it is "
2904 "a wired interface");
2906 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_WIRED
;
2907 drv
->has_capability
= 1;
2908 ndis_add_multicast(drv
);
2916 static void wpa_driver_ndis_deinit(void *priv
)
2918 struct wpa_driver_ndis_data
*drv
= priv
;
2920 #ifdef CONFIG_NDIS_EVENTS_INTEGRATED
2922 eloop_unregister_event(drv
->event_avail
,
2923 sizeof(drv
->event_avail
));
2924 ndis_events_deinit(drv
->events
);
2926 #endif /* CONFIG_NDIS_EVENTS_INTEGRATED */
2929 ndisuio_notification_deinit(drv
);
2930 #endif /* _WIN32_WCE */
2932 eloop_cancel_timeout(wpa_driver_ndis_scan_timeout
, drv
, drv
->ctx
);
2933 eloop_cancel_timeout(wpa_driver_ndis_poll_timeout
, drv
, NULL
);
2934 wpa_driver_ndis_flush_pmkid(drv
);
2935 wpa_driver_ndis_disconnect(drv
);
2936 if (wpa_driver_ndis_radio_off(drv
) < 0) {
2937 wpa_printf(MSG_DEBUG
, "NDIS: failed to disassociate and turn "
2941 wpa_driver_ndis_adapter_close(drv
);
2943 if (drv
->wzc_disabled
)
2944 wpa_driver_ndis_set_wzc(drv
, 1);
2947 os_free(drv
->adapter_name
);
2948 #endif /* _WIN32_WCE */
2949 os_free(drv
->adapter_desc
);
2954 static struct wpa_interface_info
*
2955 wpa_driver_ndis_get_interfaces(void *global_priv
)
2957 struct wpa_interface_info
*iface
= NULL
, *niface
;
2959 #ifdef CONFIG_USE_NDISUIO
2960 NDISUIO_QUERY_BINDING
*b
;
2961 size_t blen
= sizeof(*b
) + 1024;
2964 char name
[256], desc
[256];
2969 ndisuio
= CreateFile(NDISUIO_DEVICE_NAME
,
2970 GENERIC_READ
| GENERIC_WRITE
, 0, NULL
,
2972 FILE_ATTRIBUTE_NORMAL
| FILE_FLAG_OVERLAPPED
,
2973 INVALID_HANDLE_VALUE
);
2974 if (ndisuio
== INVALID_HANDLE_VALUE
) {
2975 wpa_printf(MSG_ERROR
, "NDIS: Failed to open connection to "
2976 "NDISUIO: %d", (int) GetLastError());
2981 if (!DeviceIoControl(ndisuio
, IOCTL_NDISUIO_BIND_WAIT
, NULL
, 0,
2982 NULL
, 0, &written
, NULL
)) {
2983 wpa_printf(MSG_ERROR
, "NDIS: IOCTL_NDISUIO_BIND_WAIT failed: "
2984 "%d", (int) GetLastError());
2985 CloseHandle(ndisuio
);
2988 #endif /* _WIN32_WCE */
2990 b
= os_malloc(blen
);
2992 CloseHandle(ndisuio
);
2996 for (i
= 0; ; i
++) {
2997 os_memset(b
, 0, blen
);
2998 b
->BindingIndex
= i
;
2999 if (!DeviceIoControl(ndisuio
, IOCTL_NDISUIO_QUERY_BINDING
,
3000 b
, sizeof(NDISUIO_QUERY_BINDING
), b
, blen
,
3002 error
= (int) GetLastError();
3003 if (error
== ERROR_NO_MORE_ITEMS
)
3005 wpa_printf(MSG_DEBUG
, "IOCTL_NDISUIO_QUERY_BINDING "
3006 "failed: %d", error
);
3010 pos
= (WCHAR
*) ((char *) b
+ b
->DeviceNameOffset
);
3011 len
= b
->DeviceNameLength
;
3012 if (len
>= sizeof(name
))
3013 len
= sizeof(name
) - 1;
3014 for (j
= 0; j
< len
; j
++)
3015 name
[j
] = (char) pos
[j
];
3018 pos
= (WCHAR
*) ((char *) b
+ b
->DeviceDescrOffset
);
3019 len
= b
->DeviceDescrLength
;
3020 if (len
>= sizeof(desc
))
3021 len
= sizeof(desc
) - 1;
3022 for (j
= 0; j
< len
; j
++)
3023 desc
[j
] = (char) pos
[j
];
3026 wpa_printf(MSG_DEBUG
, "NDIS: %d - %s - %s", i
, name
, desc
);
3028 niface
= os_zalloc(sizeof(*niface
));
3031 niface
->drv_name
= "ndis";
3032 if (os_strncmp(name
, "\\DEVICE\\", 8) == 0)
3033 niface
->ifname
= os_strdup(name
+ 8);
3035 niface
->ifname
= os_strdup(name
);
3036 if (niface
->ifname
== NULL
) {
3040 niface
->desc
= os_strdup(desc
);
3041 niface
->next
= iface
;
3046 CloseHandle(ndisuio
);
3047 #else /* CONFIG_USE_NDISUIO */
3049 char *names
, *pos
, *pos2
;
3052 char *name
[MAX_ADAPTERS
];
3053 char *desc
[MAX_ADAPTERS
];
3054 int num_name
, num_desc
, i
;
3056 wpa_printf(MSG_DEBUG
, "NDIS: Packet.dll version: %s",
3057 PacketGetVersion());
3060 _names
= os_zalloc(len
);
3064 res
= PacketGetAdapterNames(_names
, &len
);
3065 if (!res
&& len
> 8192) {
3067 _names
= os_zalloc(len
);
3070 res
= PacketGetAdapterNames(_names
, &len
);
3074 wpa_printf(MSG_ERROR
, "NDIS: Failed to get adapter list "
3075 "(PacketGetAdapterNames)");
3080 names
= (char *) _names
;
3081 if (names
[0] && names
[1] == '\0' && names
[2] && names
[3] == '\0') {
3082 wpa_printf(MSG_DEBUG
, "NDIS: Looks like adapter names are in "
3084 /* Convert to ASCII */
3086 while (pos2
< names
+ len
) {
3087 if (pos2
[0] == '\0' && pos2
[1] == '\0' &&
3088 pos2
[2] == '\0' && pos2
[3] == '\0') {
3095 os_memcpy(pos
+ 2, names
, pos
- names
);
3101 while (pos
< names
+ len
) {
3102 name
[num_name
] = pos
;
3103 while (*pos
&& pos
< names
+ len
)
3105 if (pos
+ 1 >= names
+ len
) {
3111 if (num_name
>= MAX_ADAPTERS
) {
3112 wpa_printf(MSG_DEBUG
, "NDIS: Too many adapters");
3117 wpa_printf(MSG_DEBUG
, "NDIS: %d adapter names found",
3125 while (pos
< names
+ len
) {
3126 desc
[num_desc
] = pos
;
3127 while (*pos
&& pos
< names
+ len
)
3129 if (pos
+ 1 >= names
+ len
) {
3135 if (num_desc
>= MAX_ADAPTERS
) {
3136 wpa_printf(MSG_DEBUG
, "NDIS: Too many adapter "
3142 wpa_printf(MSG_DEBUG
, "NDIS: %d adapter descriptions "
3150 * Windows 98 with Packet.dll 3.0 alpha3 does not include adapter
3151 * descriptions. Fill in dummy descriptors to work around this.
3153 while (num_desc
< num_name
)
3154 desc
[num_desc
++] = "dummy description";
3156 if (num_name
!= num_desc
) {
3157 wpa_printf(MSG_DEBUG
, "NDIS: mismatch in adapter name and "
3158 "description counts (%d != %d)",
3159 num_name
, num_desc
);
3164 for (i
= 0; i
< num_name
; i
++) {
3165 niface
= os_zalloc(sizeof(*niface
));
3168 niface
->drv_name
= "ndis";
3169 if (os_strncmp(name
[i
], "\\Device\\NPF_", 12) == 0)
3170 niface
->ifname
= os_strdup(name
[i
] + 12);
3172 niface
->ifname
= os_strdup(name
[i
]);
3173 if (niface
->ifname
== NULL
) {
3177 niface
->desc
= os_strdup(desc
[i
]);
3178 niface
->next
= iface
;
3182 #endif /* CONFIG_USE_NDISUIO */
3188 const struct wpa_driver_ops wpa_driver_ndis_ops
= {
3190 "Windows NDIS driver",
3191 wpa_driver_ndis_get_bssid
,
3192 wpa_driver_ndis_get_ssid
,
3193 wpa_driver_ndis_set_key
,
3194 wpa_driver_ndis_init
,
3195 wpa_driver_ndis_deinit
,
3196 NULL
/* set_param */,
3197 NULL
/* set_countermeasures */,
3198 wpa_driver_ndis_deauthenticate
,
3199 wpa_driver_ndis_disassociate
,
3200 wpa_driver_ndis_associate
,
3201 wpa_driver_ndis_add_pmkid
,
3202 wpa_driver_ndis_remove_pmkid
,
3203 wpa_driver_ndis_flush_pmkid
,
3204 wpa_driver_ndis_get_capa
,
3205 wpa_driver_ndis_poll
,
3206 wpa_driver_ndis_get_ifname
,
3207 wpa_driver_ndis_get_mac_addr
,
3208 NULL
/* send_eapol */,
3209 NULL
/* set_operstate */,
3210 NULL
/* mlme_setprotection */,
3211 NULL
/* get_hw_feature_data */,
3212 NULL
/* set_channel */,
3213 NULL
/* set_ssid */,
3214 NULL
/* set_bssid */,
3215 NULL
/* send_mlme */,
3216 NULL
/* mlme_add_sta */,
3217 NULL
/* mlme_remove_sta */,
3218 NULL
/* update_ft_ies */,
3219 NULL
/* send_ft_action */,
3220 wpa_driver_ndis_get_scan_results
,
3221 NULL
/* set_country */,
3222 NULL
/* global_init */,
3223 NULL
/* global_deinit */,
3225 wpa_driver_ndis_get_interfaces
,
3226 wpa_driver_ndis_scan
,
3227 NULL
/* authenticate */,
3228 NULL
/* set_beacon */,
3229 NULL
/* hapd_init */,
3230 NULL
/* hapd_deinit */,
3231 NULL
/* set_ieee8021x */,
3232 NULL
/* set_privacy */,
3233 NULL
/* get_seqnum */,
3235 NULL
/* set_generic_elem */,
3236 NULL
/* read_sta_data */,
3237 NULL
/* hapd_send_eapol */,
3238 NULL
/* sta_deauth */,
3239 NULL
/* sta_disassoc */,
3240 NULL
/* sta_remove */,
3241 NULL
/* hapd_get_ssid */,
3242 NULL
/* hapd_set_ssid */,
3243 NULL
/* hapd_set_countermeasures */,
3245 NULL
/* get_inact_sec */,
3246 NULL
/* sta_clear_stats */,
3247 NULL
/* set_freq */,
3249 NULL
/* set_frag */,
3250 NULL
/* sta_set_flags */,
3251 NULL
/* set_rate_sets */,
3252 NULL
/* set_cts_protect */,
3253 NULL
/* set_preamble */,
3254 NULL
/* set_short_slot_time */,
3255 NULL
/* set_tx_queue_params */,
3256 NULL
/* valid_bss_mask */,
3258 NULL
/* if_remove */,
3259 NULL
/* set_sta_vlan */,
3261 NULL
/* send_ether */,
3262 NULL
/* set_radius_acl_auth */,
3263 NULL
/* set_radius_acl_expire */,
3264 NULL
/* set_ht_params */,
3265 NULL
/* set_ap_wps_ie */,
3266 NULL
/* set_supp_port */,
3267 NULL
/* set_wds_sta */,
3268 NULL
/* send_action */,
3269 NULL
/* remain_on_channel */,
3270 NULL
/* cancel_remain_on_channel */,
3271 NULL
/* probe_req_report */,
3272 NULL
/* disable_11b_rates */,
3273 NULL
/* deinit_ap */,
3276 NULL
/* signal_monitor */,
3277 NULL
/* send_frame */