driver_ndis.c 84 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218
  1. /*
  2. * WPA Supplicant - Windows/NDIS driver interface
  3. * Copyright (c) 2004-2007, Jouni Malinen <j@w1.fi>
  4. *
  5. * This software may be distributed under the terms of the BSD license.
  6. * See README for more details.
  7. */
  8. #ifdef __CYGWIN__
  9. /* Avoid some header file conflicts by not including standard headers for
  10. * cygwin builds when Packet32.h is included. */
  11. #include "build_config.h"
  12. int close(int fd);
  13. #else /* __CYGWIN__ */
  14. #include "includes.h"
  15. #endif /* __CYGWIN__ */
  16. #ifdef CONFIG_USE_NDISUIO
  17. #include <winsock2.h>
  18. #else /* CONFIG_USE_NDISUIO */
  19. #include <Packet32.h>
  20. #endif /* CONFIG_USE_NDISUIO */
  21. #ifdef __MINGW32_VERSION
  22. #include <ddk/ntddndis.h>
  23. #else /* __MINGW32_VERSION */
  24. #include <ntddndis.h>
  25. #endif /* __MINGW32_VERSION */
  26. #ifdef _WIN32_WCE
  27. #include <winioctl.h>
  28. #include <nuiouser.h>
  29. #include <devload.h>
  30. #endif /* _WIN32_WCE */
  31. #include "common.h"
  32. #include "driver.h"
  33. #include "eloop.h"
  34. #include "common/ieee802_11_defs.h"
  35. #include "driver_ndis.h"
  36. int wpa_driver_register_event_cb(struct wpa_driver_ndis_data *drv);
  37. #ifdef CONFIG_NDIS_EVENTS_INTEGRATED
  38. void wpa_driver_ndis_event_pipe_cb(void *eloop_data, void *user_data);
  39. #endif /* CONFIG_NDIS_EVENTS_INTEGRATED */
  40. static void wpa_driver_ndis_deinit(void *priv);
  41. static void wpa_driver_ndis_poll(void *drv);
  42. static void wpa_driver_ndis_poll_timeout(void *eloop_ctx, void *timeout_ctx);
  43. static int wpa_driver_ndis_adapter_init(struct wpa_driver_ndis_data *drv);
  44. static int wpa_driver_ndis_adapter_open(struct wpa_driver_ndis_data *drv);
  45. static void wpa_driver_ndis_adapter_close(struct wpa_driver_ndis_data *drv);
  46. static const u8 pae_group_addr[ETH_ALEN] =
  47. { 0x01, 0x80, 0xc2, 0x00, 0x00, 0x03 };
  48. /* FIX: to be removed once this can be compiled with the complete NDIS
  49. * header files */
  50. #ifndef OID_802_11_BSSID
  51. #define OID_802_11_BSSID 0x0d010101
  52. #define OID_802_11_SSID 0x0d010102
  53. #define OID_802_11_INFRASTRUCTURE_MODE 0x0d010108
  54. #define OID_802_11_ADD_WEP 0x0D010113
  55. #define OID_802_11_REMOVE_WEP 0x0D010114
  56. #define OID_802_11_DISASSOCIATE 0x0D010115
  57. #define OID_802_11_BSSID_LIST 0x0d010217
  58. #define OID_802_11_AUTHENTICATION_MODE 0x0d010118
  59. #define OID_802_11_PRIVACY_FILTER 0x0d010119
  60. #define OID_802_11_BSSID_LIST_SCAN 0x0d01011A
  61. #define OID_802_11_WEP_STATUS 0x0d01011B
  62. #define OID_802_11_ENCRYPTION_STATUS OID_802_11_WEP_STATUS
  63. #define OID_802_11_ADD_KEY 0x0d01011D
  64. #define OID_802_11_REMOVE_KEY 0x0d01011E
  65. #define OID_802_11_ASSOCIATION_INFORMATION 0x0d01011F
  66. #define OID_802_11_TEST 0x0d010120
  67. #define OID_802_11_CAPABILITY 0x0d010122
  68. #define OID_802_11_PMKID 0x0d010123
  69. #define NDIS_802_11_LENGTH_SSID 32
  70. #define NDIS_802_11_LENGTH_RATES 8
  71. #define NDIS_802_11_LENGTH_RATES_EX 16
  72. typedef UCHAR NDIS_802_11_MAC_ADDRESS[6];
  73. typedef struct NDIS_802_11_SSID {
  74. ULONG SsidLength;
  75. UCHAR Ssid[NDIS_802_11_LENGTH_SSID];
  76. } NDIS_802_11_SSID;
  77. typedef LONG NDIS_802_11_RSSI;
  78. typedef enum NDIS_802_11_NETWORK_TYPE {
  79. Ndis802_11FH,
  80. Ndis802_11DS,
  81. Ndis802_11OFDM5,
  82. Ndis802_11OFDM24,
  83. Ndis802_11NetworkTypeMax
  84. } NDIS_802_11_NETWORK_TYPE;
  85. typedef struct NDIS_802_11_CONFIGURATION_FH {
  86. ULONG Length;
  87. ULONG HopPattern;
  88. ULONG HopSet;
  89. ULONG DwellTime;
  90. } NDIS_802_11_CONFIGURATION_FH;
  91. typedef struct NDIS_802_11_CONFIGURATION {
  92. ULONG Length;
  93. ULONG BeaconPeriod;
  94. ULONG ATIMWindow;
  95. ULONG DSConfig;
  96. NDIS_802_11_CONFIGURATION_FH FHConfig;
  97. } NDIS_802_11_CONFIGURATION;
  98. typedef enum NDIS_802_11_NETWORK_INFRASTRUCTURE {
  99. Ndis802_11IBSS,
  100. Ndis802_11Infrastructure,
  101. Ndis802_11AutoUnknown,
  102. Ndis802_11InfrastructureMax
  103. } NDIS_802_11_NETWORK_INFRASTRUCTURE;
  104. typedef enum NDIS_802_11_AUTHENTICATION_MODE {
  105. Ndis802_11AuthModeOpen,
  106. Ndis802_11AuthModeShared,
  107. Ndis802_11AuthModeAutoSwitch,
  108. Ndis802_11AuthModeWPA,
  109. Ndis802_11AuthModeWPAPSK,
  110. Ndis802_11AuthModeWPANone,
  111. Ndis802_11AuthModeWPA2,
  112. Ndis802_11AuthModeWPA2PSK,
  113. Ndis802_11AuthModeMax
  114. } NDIS_802_11_AUTHENTICATION_MODE;
  115. typedef enum NDIS_802_11_WEP_STATUS {
  116. Ndis802_11WEPEnabled,
  117. Ndis802_11Encryption1Enabled = Ndis802_11WEPEnabled,
  118. Ndis802_11WEPDisabled,
  119. Ndis802_11EncryptionDisabled = Ndis802_11WEPDisabled,
  120. Ndis802_11WEPKeyAbsent,
  121. Ndis802_11Encryption1KeyAbsent = Ndis802_11WEPKeyAbsent,
  122. Ndis802_11WEPNotSupported,
  123. Ndis802_11EncryptionNotSupported = Ndis802_11WEPNotSupported,
  124. Ndis802_11Encryption2Enabled,
  125. Ndis802_11Encryption2KeyAbsent,
  126. Ndis802_11Encryption3Enabled,
  127. Ndis802_11Encryption3KeyAbsent
  128. } NDIS_802_11_WEP_STATUS, NDIS_802_11_ENCRYPTION_STATUS;
  129. typedef enum NDIS_802_11_PRIVACY_FILTER {
  130. Ndis802_11PrivFilterAcceptAll,
  131. Ndis802_11PrivFilter8021xWEP
  132. } NDIS_802_11_PRIVACY_FILTER;
  133. typedef UCHAR NDIS_802_11_RATES[NDIS_802_11_LENGTH_RATES];
  134. typedef UCHAR NDIS_802_11_RATES_EX[NDIS_802_11_LENGTH_RATES_EX];
  135. typedef struct NDIS_WLAN_BSSID_EX {
  136. ULONG Length;
  137. NDIS_802_11_MAC_ADDRESS MacAddress; /* BSSID */
  138. UCHAR Reserved[2];
  139. NDIS_802_11_SSID Ssid;
  140. ULONG Privacy;
  141. NDIS_802_11_RSSI Rssi;
  142. NDIS_802_11_NETWORK_TYPE NetworkTypeInUse;
  143. NDIS_802_11_CONFIGURATION Configuration;
  144. NDIS_802_11_NETWORK_INFRASTRUCTURE InfrastructureMode;
  145. NDIS_802_11_RATES_EX SupportedRates;
  146. ULONG IELength;
  147. UCHAR IEs[1];
  148. } NDIS_WLAN_BSSID_EX;
  149. typedef struct NDIS_802_11_BSSID_LIST_EX {
  150. ULONG NumberOfItems;
  151. NDIS_WLAN_BSSID_EX Bssid[1];
  152. } NDIS_802_11_BSSID_LIST_EX;
  153. typedef struct NDIS_802_11_FIXED_IEs {
  154. UCHAR Timestamp[8];
  155. USHORT BeaconInterval;
  156. USHORT Capabilities;
  157. } NDIS_802_11_FIXED_IEs;
  158. typedef struct NDIS_802_11_WEP {
  159. ULONG Length;
  160. ULONG KeyIndex;
  161. ULONG KeyLength;
  162. UCHAR KeyMaterial[1];
  163. } NDIS_802_11_WEP;
  164. typedef ULONG NDIS_802_11_KEY_INDEX;
  165. typedef ULONGLONG NDIS_802_11_KEY_RSC;
  166. typedef struct NDIS_802_11_KEY {
  167. ULONG Length;
  168. ULONG KeyIndex;
  169. ULONG KeyLength;
  170. NDIS_802_11_MAC_ADDRESS BSSID;
  171. NDIS_802_11_KEY_RSC KeyRSC;
  172. UCHAR KeyMaterial[1];
  173. } NDIS_802_11_KEY;
  174. typedef struct NDIS_802_11_REMOVE_KEY {
  175. ULONG Length;
  176. ULONG KeyIndex;
  177. NDIS_802_11_MAC_ADDRESS BSSID;
  178. } NDIS_802_11_REMOVE_KEY;
  179. typedef struct NDIS_802_11_AI_REQFI {
  180. USHORT Capabilities;
  181. USHORT ListenInterval;
  182. NDIS_802_11_MAC_ADDRESS CurrentAPAddress;
  183. } NDIS_802_11_AI_REQFI;
  184. typedef struct NDIS_802_11_AI_RESFI {
  185. USHORT Capabilities;
  186. USHORT StatusCode;
  187. USHORT AssociationId;
  188. } NDIS_802_11_AI_RESFI;
  189. typedef struct NDIS_802_11_ASSOCIATION_INFORMATION {
  190. ULONG Length;
  191. USHORT AvailableRequestFixedIEs;
  192. NDIS_802_11_AI_REQFI RequestFixedIEs;
  193. ULONG RequestIELength;
  194. ULONG OffsetRequestIEs;
  195. USHORT AvailableResponseFixedIEs;
  196. NDIS_802_11_AI_RESFI ResponseFixedIEs;
  197. ULONG ResponseIELength;
  198. ULONG OffsetResponseIEs;
  199. } NDIS_802_11_ASSOCIATION_INFORMATION;
  200. typedef struct NDIS_802_11_AUTHENTICATION_ENCRYPTION {
  201. NDIS_802_11_AUTHENTICATION_MODE AuthModeSupported;
  202. NDIS_802_11_ENCRYPTION_STATUS EncryptStatusSupported;
  203. } NDIS_802_11_AUTHENTICATION_ENCRYPTION;
  204. typedef struct NDIS_802_11_CAPABILITY {
  205. ULONG Length;
  206. ULONG Version;
  207. ULONG NoOfPMKIDs;
  208. ULONG NoOfAuthEncryptPairsSupported;
  209. NDIS_802_11_AUTHENTICATION_ENCRYPTION
  210. AuthenticationEncryptionSupported[1];
  211. } NDIS_802_11_CAPABILITY;
  212. typedef UCHAR NDIS_802_11_PMKID_VALUE[16];
  213. typedef struct BSSID_INFO {
  214. NDIS_802_11_MAC_ADDRESS BSSID;
  215. NDIS_802_11_PMKID_VALUE PMKID;
  216. } BSSID_INFO;
  217. typedef struct NDIS_802_11_PMKID {
  218. ULONG Length;
  219. ULONG BSSIDInfoCount;
  220. BSSID_INFO BSSIDInfo[1];
  221. } NDIS_802_11_PMKID;
  222. typedef enum NDIS_802_11_STATUS_TYPE {
  223. Ndis802_11StatusType_Authentication,
  224. Ndis802_11StatusType_PMKID_CandidateList = 2,
  225. Ndis802_11StatusTypeMax
  226. } NDIS_802_11_STATUS_TYPE;
  227. typedef struct NDIS_802_11_STATUS_INDICATION {
  228. NDIS_802_11_STATUS_TYPE StatusType;
  229. } NDIS_802_11_STATUS_INDICATION;
  230. typedef struct PMKID_CANDIDATE {
  231. NDIS_802_11_MAC_ADDRESS BSSID;
  232. ULONG Flags;
  233. } PMKID_CANDIDATE;
  234. #define NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED 0x01
  235. typedef struct NDIS_802_11_PMKID_CANDIDATE_LIST {
  236. ULONG Version;
  237. ULONG NumCandidates;
  238. PMKID_CANDIDATE CandidateList[1];
  239. } NDIS_802_11_PMKID_CANDIDATE_LIST;
  240. typedef struct NDIS_802_11_AUTHENTICATION_REQUEST {
  241. ULONG Length;
  242. NDIS_802_11_MAC_ADDRESS Bssid;
  243. ULONG Flags;
  244. } NDIS_802_11_AUTHENTICATION_REQUEST;
  245. #define NDIS_802_11_AUTH_REQUEST_REAUTH 0x01
  246. #define NDIS_802_11_AUTH_REQUEST_KEYUPDATE 0x02
  247. #define NDIS_802_11_AUTH_REQUEST_PAIRWISE_ERROR 0x06
  248. #define NDIS_802_11_AUTH_REQUEST_GROUP_ERROR 0x0E
  249. #endif /* OID_802_11_BSSID */
  250. #ifndef OID_802_11_PMKID
  251. /* Platform SDK for XP did not include WPA2, so add needed definitions */
  252. #define OID_802_11_CAPABILITY 0x0d010122
  253. #define OID_802_11_PMKID 0x0d010123
  254. #define Ndis802_11AuthModeWPA2 6
  255. #define Ndis802_11AuthModeWPA2PSK 7
  256. #define Ndis802_11StatusType_PMKID_CandidateList 2
  257. typedef struct NDIS_802_11_AUTHENTICATION_ENCRYPTION {
  258. NDIS_802_11_AUTHENTICATION_MODE AuthModeSupported;
  259. NDIS_802_11_ENCRYPTION_STATUS EncryptStatusSupported;
  260. } NDIS_802_11_AUTHENTICATION_ENCRYPTION;
  261. typedef struct NDIS_802_11_CAPABILITY {
  262. ULONG Length;
  263. ULONG Version;
  264. ULONG NoOfPMKIDs;
  265. ULONG NoOfAuthEncryptPairsSupported;
  266. NDIS_802_11_AUTHENTICATION_ENCRYPTION
  267. AuthenticationEncryptionSupported[1];
  268. } NDIS_802_11_CAPABILITY;
  269. typedef UCHAR NDIS_802_11_PMKID_VALUE[16];
  270. typedef struct BSSID_INFO {
  271. NDIS_802_11_MAC_ADDRESS BSSID;
  272. NDIS_802_11_PMKID_VALUE PMKID;
  273. } BSSID_INFO;
  274. typedef struct NDIS_802_11_PMKID {
  275. ULONG Length;
  276. ULONG BSSIDInfoCount;
  277. BSSID_INFO BSSIDInfo[1];
  278. } NDIS_802_11_PMKID;
  279. typedef struct PMKID_CANDIDATE {
  280. NDIS_802_11_MAC_ADDRESS BSSID;
  281. ULONG Flags;
  282. } PMKID_CANDIDATE;
  283. #define NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED 0x01
  284. typedef struct NDIS_802_11_PMKID_CANDIDATE_LIST {
  285. ULONG Version;
  286. ULONG NumCandidates;
  287. PMKID_CANDIDATE CandidateList[1];
  288. } NDIS_802_11_PMKID_CANDIDATE_LIST;
  289. #endif /* OID_802_11_CAPABILITY */
  290. #ifndef OID_DOT11_CURRENT_OPERATION_MODE
  291. /* Native 802.11 OIDs */
  292. #define OID_DOT11_NDIS_START 0x0D010300
  293. #define OID_DOT11_CURRENT_OPERATION_MODE (OID_DOT11_NDIS_START + 8)
  294. #define OID_DOT11_SCAN_REQUEST (OID_DOT11_NDIS_START + 11)
  295. typedef enum _DOT11_BSS_TYPE {
  296. dot11_BSS_type_infrastructure = 1,
  297. dot11_BSS_type_independent = 2,
  298. dot11_BSS_type_any = 3
  299. } DOT11_BSS_TYPE, * PDOT11_BSS_TYPE;
  300. typedef UCHAR DOT11_MAC_ADDRESS[6];
  301. typedef DOT11_MAC_ADDRESS * PDOT11_MAC_ADDRESS;
  302. typedef enum _DOT11_SCAN_TYPE {
  303. dot11_scan_type_active = 1,
  304. dot11_scan_type_passive = 2,
  305. dot11_scan_type_auto = 3,
  306. dot11_scan_type_forced = 0x80000000
  307. } DOT11_SCAN_TYPE, * PDOT11_SCAN_TYPE;
  308. typedef struct _DOT11_SCAN_REQUEST_V2 {
  309. DOT11_BSS_TYPE dot11BSSType;
  310. DOT11_MAC_ADDRESS dot11BSSID;
  311. DOT11_SCAN_TYPE dot11ScanType;
  312. BOOLEAN bRestrictedScan;
  313. ULONG udot11SSIDsOffset;
  314. ULONG uNumOfdot11SSIDs;
  315. BOOLEAN bUseRequestIE;
  316. ULONG uRequestIDsOffset;
  317. ULONG uNumOfRequestIDs;
  318. ULONG uPhyTypeInfosOffset;
  319. ULONG uNumOfPhyTypeInfos;
  320. ULONG uIEsOffset;
  321. ULONG uIEsLength;
  322. UCHAR ucBuffer[1];
  323. } DOT11_SCAN_REQUEST_V2, * PDOT11_SCAN_REQUEST_V2;
  324. #endif /* OID_DOT11_CURRENT_OPERATION_MODE */
  325. #ifdef CONFIG_USE_NDISUIO
  326. #ifndef _WIN32_WCE
  327. #ifdef __MINGW32_VERSION
  328. typedef ULONG NDIS_OID;
  329. #endif /* __MINGW32_VERSION */
  330. /* from nuiouser.h */
  331. #define FSCTL_NDISUIO_BASE FILE_DEVICE_NETWORK
  332. #define _NDISUIO_CTL_CODE(_Function, _Method, _Access) \
  333. CTL_CODE(FSCTL_NDISUIO_BASE, _Function, _Method, _Access)
  334. #define IOCTL_NDISUIO_OPEN_DEVICE \
  335. _NDISUIO_CTL_CODE(0x200, METHOD_BUFFERED, \
  336. FILE_READ_ACCESS | FILE_WRITE_ACCESS)
  337. #define IOCTL_NDISUIO_QUERY_OID_VALUE \
  338. _NDISUIO_CTL_CODE(0x201, METHOD_BUFFERED, \
  339. FILE_READ_ACCESS | FILE_WRITE_ACCESS)
  340. #define IOCTL_NDISUIO_SET_OID_VALUE \
  341. _NDISUIO_CTL_CODE(0x205, METHOD_BUFFERED, \
  342. FILE_READ_ACCESS | FILE_WRITE_ACCESS)
  343. #define IOCTL_NDISUIO_SET_ETHER_TYPE \
  344. _NDISUIO_CTL_CODE(0x202, METHOD_BUFFERED, \
  345. FILE_READ_ACCESS | FILE_WRITE_ACCESS)
  346. #define IOCTL_NDISUIO_QUERY_BINDING \
  347. _NDISUIO_CTL_CODE(0x203, METHOD_BUFFERED, \
  348. FILE_READ_ACCESS | FILE_WRITE_ACCESS)
  349. #define IOCTL_NDISUIO_BIND_WAIT \
  350. _NDISUIO_CTL_CODE(0x204, METHOD_BUFFERED, \
  351. FILE_READ_ACCESS | FILE_WRITE_ACCESS)
  352. typedef struct _NDISUIO_QUERY_OID
  353. {
  354. NDIS_OID Oid;
  355. UCHAR Data[sizeof(ULONG)];
  356. } NDISUIO_QUERY_OID, *PNDISUIO_QUERY_OID;
  357. typedef struct _NDISUIO_SET_OID
  358. {
  359. NDIS_OID Oid;
  360. UCHAR Data[sizeof(ULONG)];
  361. } NDISUIO_SET_OID, *PNDISUIO_SET_OID;
  362. typedef struct _NDISUIO_QUERY_BINDING
  363. {
  364. ULONG BindingIndex;
  365. ULONG DeviceNameOffset;
  366. ULONG DeviceNameLength;
  367. ULONG DeviceDescrOffset;
  368. ULONG DeviceDescrLength;
  369. } NDISUIO_QUERY_BINDING, *PNDISUIO_QUERY_BINDING;
  370. #endif /* _WIN32_WCE */
  371. #endif /* CONFIG_USE_NDISUIO */
  372. static int ndis_get_oid(struct wpa_driver_ndis_data *drv, unsigned int oid,
  373. char *data, size_t len)
  374. {
  375. #ifdef CONFIG_USE_NDISUIO
  376. NDISUIO_QUERY_OID *o;
  377. size_t buflen = sizeof(*o) + len;
  378. DWORD written;
  379. int ret;
  380. size_t hdrlen;
  381. o = os_zalloc(buflen);
  382. if (o == NULL)
  383. return -1;
  384. o->Oid = oid;
  385. #ifdef _WIN32_WCE
  386. o->ptcDeviceName = drv->adapter_name;
  387. #endif /* _WIN32_WCE */
  388. if (!DeviceIoControl(drv->ndisuio, IOCTL_NDISUIO_QUERY_OID_VALUE,
  389. o, sizeof(NDISUIO_QUERY_OID), o, buflen, &written,
  390. NULL)) {
  391. wpa_printf(MSG_DEBUG, "NDIS: IOCTL_NDISUIO_QUERY_OID_VALUE "
  392. "failed (oid=%08x): %d", oid, (int) GetLastError());
  393. os_free(o);
  394. return -1;
  395. }
  396. hdrlen = sizeof(NDISUIO_QUERY_OID) - sizeof(o->Data);
  397. if (written < hdrlen) {
  398. wpa_printf(MSG_DEBUG, "NDIS: query oid=%08x written (%d); "
  399. "too short", oid, (unsigned int) written);
  400. os_free(o);
  401. return -1;
  402. }
  403. written -= hdrlen;
  404. if (written > len) {
  405. wpa_printf(MSG_DEBUG, "NDIS: query oid=%08x written (%d) > "
  406. "len (%d)",oid, (unsigned int) written, len);
  407. os_free(o);
  408. return -1;
  409. }
  410. os_memcpy(data, o->Data, written);
  411. ret = written;
  412. os_free(o);
  413. return ret;
  414. #else /* CONFIG_USE_NDISUIO */
  415. char *buf;
  416. PACKET_OID_DATA *o;
  417. int ret;
  418. buf = os_zalloc(sizeof(*o) + len);
  419. if (buf == NULL)
  420. return -1;
  421. o = (PACKET_OID_DATA *) buf;
  422. o->Oid = oid;
  423. o->Length = len;
  424. if (!PacketRequest(drv->adapter, FALSE, o)) {
  425. wpa_printf(MSG_DEBUG, "%s: oid=0x%x len (%d) failed",
  426. __func__, oid, len);
  427. os_free(buf);
  428. return -1;
  429. }
  430. if (o->Length > len) {
  431. wpa_printf(MSG_DEBUG, "%s: oid=0x%x Length (%d) > len (%d)",
  432. __func__, oid, (unsigned int) o->Length, len);
  433. os_free(buf);
  434. return -1;
  435. }
  436. os_memcpy(data, o->Data, o->Length);
  437. ret = o->Length;
  438. os_free(buf);
  439. return ret;
  440. #endif /* CONFIG_USE_NDISUIO */
  441. }
  442. static int ndis_set_oid(struct wpa_driver_ndis_data *drv, unsigned int oid,
  443. const char *data, size_t len)
  444. {
  445. #ifdef CONFIG_USE_NDISUIO
  446. NDISUIO_SET_OID *o;
  447. size_t buflen, reallen;
  448. DWORD written;
  449. char txt[50];
  450. os_snprintf(txt, sizeof(txt), "NDIS: Set OID %08x", oid);
  451. wpa_hexdump_key(MSG_MSGDUMP, txt, (const u8 *) data, len);
  452. buflen = sizeof(*o) + len;
  453. reallen = buflen - sizeof(o->Data);
  454. o = os_zalloc(buflen);
  455. if (o == NULL)
  456. return -1;
  457. o->Oid = oid;
  458. #ifdef _WIN32_WCE
  459. o->ptcDeviceName = drv->adapter_name;
  460. #endif /* _WIN32_WCE */
  461. if (data)
  462. os_memcpy(o->Data, data, len);
  463. if (!DeviceIoControl(drv->ndisuio, IOCTL_NDISUIO_SET_OID_VALUE,
  464. o, reallen, NULL, 0, &written, NULL)) {
  465. wpa_printf(MSG_DEBUG, "NDIS: IOCTL_NDISUIO_SET_OID_VALUE "
  466. "(oid=%08x) failed: %d", oid, (int) GetLastError());
  467. os_free(o);
  468. return -1;
  469. }
  470. os_free(o);
  471. return 0;
  472. #else /* CONFIG_USE_NDISUIO */
  473. char *buf;
  474. PACKET_OID_DATA *o;
  475. char txt[50];
  476. os_snprintf(txt, sizeof(txt), "NDIS: Set OID %08x", oid);
  477. wpa_hexdump_key(MSG_MSGDUMP, txt, (const u8 *) data, len);
  478. buf = os_zalloc(sizeof(*o) + len);
  479. if (buf == NULL)
  480. return -1;
  481. o = (PACKET_OID_DATA *) buf;
  482. o->Oid = oid;
  483. o->Length = len;
  484. if (data)
  485. os_memcpy(o->Data, data, len);
  486. if (!PacketRequest(drv->adapter, TRUE, o)) {
  487. wpa_printf(MSG_DEBUG, "%s: oid=0x%x len (%d) failed",
  488. __func__, oid, len);
  489. os_free(buf);
  490. return -1;
  491. }
  492. os_free(buf);
  493. return 0;
  494. #endif /* CONFIG_USE_NDISUIO */
  495. }
  496. static int ndis_set_auth_mode(struct wpa_driver_ndis_data *drv, int mode)
  497. {
  498. u32 auth_mode = mode;
  499. if (ndis_set_oid(drv, OID_802_11_AUTHENTICATION_MODE,
  500. (char *) &auth_mode, sizeof(auth_mode)) < 0) {
  501. wpa_printf(MSG_DEBUG, "NDIS: Failed to set "
  502. "OID_802_11_AUTHENTICATION_MODE (%d)",
  503. (int) auth_mode);
  504. return -1;
  505. }
  506. return 0;
  507. }
  508. static int ndis_get_auth_mode(struct wpa_driver_ndis_data *drv)
  509. {
  510. u32 auth_mode;
  511. int res;
  512. res = ndis_get_oid(drv, OID_802_11_AUTHENTICATION_MODE,
  513. (char *) &auth_mode, sizeof(auth_mode));
  514. if (res != sizeof(auth_mode)) {
  515. wpa_printf(MSG_DEBUG, "NDIS: Failed to get "
  516. "OID_802_11_AUTHENTICATION_MODE");
  517. return -1;
  518. }
  519. return auth_mode;
  520. }
  521. static int ndis_set_encr_status(struct wpa_driver_ndis_data *drv, int encr)
  522. {
  523. u32 encr_status = encr;
  524. if (ndis_set_oid(drv, OID_802_11_ENCRYPTION_STATUS,
  525. (char *) &encr_status, sizeof(encr_status)) < 0) {
  526. wpa_printf(MSG_DEBUG, "NDIS: Failed to set "
  527. "OID_802_11_ENCRYPTION_STATUS (%d)", encr);
  528. return -1;
  529. }
  530. return 0;
  531. }
  532. static int ndis_get_encr_status(struct wpa_driver_ndis_data *drv)
  533. {
  534. u32 encr;
  535. int res;
  536. res = ndis_get_oid(drv, OID_802_11_ENCRYPTION_STATUS,
  537. (char *) &encr, sizeof(encr));
  538. if (res != sizeof(encr)) {
  539. wpa_printf(MSG_DEBUG, "NDIS: Failed to get "
  540. "OID_802_11_ENCRYPTION_STATUS");
  541. return -1;
  542. }
  543. return encr;
  544. }
  545. static int wpa_driver_ndis_get_bssid(void *priv, u8 *bssid)
  546. {
  547. struct wpa_driver_ndis_data *drv = priv;
  548. if (drv->wired) {
  549. /*
  550. * Report PAE group address as the "BSSID" for wired
  551. * connection.
  552. */
  553. os_memcpy(bssid, pae_group_addr, ETH_ALEN);
  554. return 0;
  555. }
  556. return ndis_get_oid(drv, OID_802_11_BSSID, (char *) bssid, ETH_ALEN) <
  557. 0 ? -1 : 0;
  558. }
  559. static int wpa_driver_ndis_get_ssid(void *priv, u8 *ssid)
  560. {
  561. struct wpa_driver_ndis_data *drv = priv;
  562. NDIS_802_11_SSID buf;
  563. int res;
  564. res = ndis_get_oid(drv, OID_802_11_SSID, (char *) &buf, sizeof(buf));
  565. if (res < 4) {
  566. wpa_printf(MSG_DEBUG, "NDIS: Failed to get SSID");
  567. if (drv->wired) {
  568. wpa_printf(MSG_DEBUG, "NDIS: Allow get_ssid failure "
  569. "with a wired interface");
  570. return 0;
  571. }
  572. return -1;
  573. }
  574. os_memcpy(ssid, buf.Ssid, buf.SsidLength);
  575. return buf.SsidLength;
  576. }
  577. static int wpa_driver_ndis_set_ssid(struct wpa_driver_ndis_data *drv,
  578. const u8 *ssid, size_t ssid_len)
  579. {
  580. NDIS_802_11_SSID buf;
  581. os_memset(&buf, 0, sizeof(buf));
  582. buf.SsidLength = ssid_len;
  583. os_memcpy(buf.Ssid, ssid, ssid_len);
  584. /*
  585. * Make sure radio is marked enabled here so that scan request will not
  586. * force SSID to be changed to a random one in order to enable radio at
  587. * that point.
  588. */
  589. drv->radio_enabled = 1;
  590. return ndis_set_oid(drv, OID_802_11_SSID, (char *) &buf, sizeof(buf));
  591. }
  592. /* Disconnect using OID_802_11_DISASSOCIATE. This will also turn the radio off.
  593. */
  594. static int wpa_driver_ndis_radio_off(struct wpa_driver_ndis_data *drv)
  595. {
  596. drv->radio_enabled = 0;
  597. return ndis_set_oid(drv, OID_802_11_DISASSOCIATE, " ", 4);
  598. }
  599. /* Disconnect by setting SSID to random (i.e., likely not used). */
  600. static int wpa_driver_ndis_disconnect(struct wpa_driver_ndis_data *drv)
  601. {
  602. char ssid[32];
  603. int i;
  604. for (i = 0; i < 32; i++)
  605. ssid[i] = rand() & 0xff;
  606. return wpa_driver_ndis_set_ssid(drv, (u8 *) ssid, 32);
  607. }
  608. static int wpa_driver_ndis_deauthenticate(void *priv, const u8 *addr,
  609. int reason_code)
  610. {
  611. struct wpa_driver_ndis_data *drv = priv;
  612. return wpa_driver_ndis_disconnect(drv);
  613. }
  614. static void wpa_driver_ndis_scan_timeout(void *eloop_ctx, void *timeout_ctx)
  615. {
  616. wpa_printf(MSG_DEBUG, "Scan timeout - try to get results");
  617. wpa_supplicant_event(timeout_ctx, EVENT_SCAN_RESULTS, NULL);
  618. }
  619. static int wpa_driver_ndis_scan_native80211(
  620. struct wpa_driver_ndis_data *drv,
  621. struct wpa_driver_scan_params *params)
  622. {
  623. DOT11_SCAN_REQUEST_V2 req;
  624. int res;
  625. os_memset(&req, 0, sizeof(req));
  626. req.dot11BSSType = dot11_BSS_type_any;
  627. os_memset(req.dot11BSSID, 0xff, ETH_ALEN);
  628. req.dot11ScanType = dot11_scan_type_auto;
  629. res = ndis_set_oid(drv, OID_DOT11_SCAN_REQUEST, (char *) &req,
  630. sizeof(req));
  631. eloop_cancel_timeout(wpa_driver_ndis_scan_timeout, drv, drv->ctx);
  632. eloop_register_timeout(7, 0, wpa_driver_ndis_scan_timeout, drv,
  633. drv->ctx);
  634. return res;
  635. }
  636. static int wpa_driver_ndis_scan(void *priv,
  637. struct wpa_driver_scan_params *params)
  638. {
  639. struct wpa_driver_ndis_data *drv = priv;
  640. int res;
  641. if (drv->native80211)
  642. return wpa_driver_ndis_scan_native80211(drv, params);
  643. if (!drv->radio_enabled) {
  644. wpa_printf(MSG_DEBUG, "NDIS: turning radio on before the first"
  645. " scan");
  646. if (wpa_driver_ndis_disconnect(drv) < 0) {
  647. wpa_printf(MSG_DEBUG, "NDIS: failed to enable radio");
  648. }
  649. drv->radio_enabled = 1;
  650. }
  651. res = ndis_set_oid(drv, OID_802_11_BSSID_LIST_SCAN, " ", 4);
  652. eloop_cancel_timeout(wpa_driver_ndis_scan_timeout, drv, drv->ctx);
  653. eloop_register_timeout(7, 0, wpa_driver_ndis_scan_timeout, drv,
  654. drv->ctx);
  655. return res;
  656. }
  657. static const u8 * wpa_scan_get_ie(const struct wpa_scan_res *res, u8 ie)
  658. {
  659. const u8 *end, *pos;
  660. pos = (const u8 *) (res + 1);
  661. end = pos + res->ie_len;
  662. while (pos + 1 < end) {
  663. if (pos + 2 + pos[1] > end)
  664. break;
  665. if (pos[0] == ie)
  666. return pos;
  667. pos += 2 + pos[1];
  668. }
  669. return NULL;
  670. }
  671. static struct wpa_scan_res * wpa_driver_ndis_add_scan_ssid(
  672. struct wpa_scan_res *r, NDIS_802_11_SSID *ssid)
  673. {
  674. struct wpa_scan_res *nr;
  675. u8 *pos;
  676. if (wpa_scan_get_ie(r, WLAN_EID_SSID))
  677. return r; /* SSID IE already present */
  678. if (ssid->SsidLength == 0 || ssid->SsidLength > 32)
  679. return r; /* No valid SSID inside scan data */
  680. nr = os_realloc(r, sizeof(*r) + r->ie_len + 2 + ssid->SsidLength);
  681. if (nr == NULL)
  682. return r;
  683. pos = ((u8 *) (nr + 1)) + nr->ie_len;
  684. *pos++ = WLAN_EID_SSID;
  685. *pos++ = ssid->SsidLength;
  686. os_memcpy(pos, ssid->Ssid, ssid->SsidLength);
  687. nr->ie_len += 2 + ssid->SsidLength;
  688. return nr;
  689. }
  690. static struct wpa_scan_results * wpa_driver_ndis_get_scan_results(void *priv)
  691. {
  692. struct wpa_driver_ndis_data *drv = priv;
  693. NDIS_802_11_BSSID_LIST_EX *b;
  694. size_t blen, count, i;
  695. int len;
  696. char *pos;
  697. struct wpa_scan_results *results;
  698. struct wpa_scan_res *r;
  699. blen = 65535;
  700. b = os_zalloc(blen);
  701. if (b == NULL)
  702. return NULL;
  703. len = ndis_get_oid(drv, OID_802_11_BSSID_LIST, (char *) b, blen);
  704. if (len < 0) {
  705. wpa_printf(MSG_DEBUG, "NDIS: failed to get scan results");
  706. os_free(b);
  707. return NULL;
  708. }
  709. count = b->NumberOfItems;
  710. results = os_zalloc(sizeof(*results));
  711. if (results == NULL) {
  712. os_free(b);
  713. return NULL;
  714. }
  715. results->res = os_calloc(count, sizeof(struct wpa_scan_res *));
  716. if (results->res == NULL) {
  717. os_free(results);
  718. os_free(b);
  719. return NULL;
  720. }
  721. pos = (char *) &b->Bssid[0];
  722. for (i = 0; i < count; i++) {
  723. NDIS_WLAN_BSSID_EX *bss = (NDIS_WLAN_BSSID_EX *) pos;
  724. NDIS_802_11_FIXED_IEs *fixed;
  725. if (bss->IELength < sizeof(NDIS_802_11_FIXED_IEs)) {
  726. wpa_printf(MSG_DEBUG, "NDIS: too small IELength=%d",
  727. (int) bss->IELength);
  728. break;
  729. }
  730. if (((char *) bss->IEs) + bss->IELength > (char *) b + blen) {
  731. /*
  732. * Some NDIS drivers have been reported to include an
  733. * entry with an invalid IELength in scan results and
  734. * this has crashed wpa_supplicant, so validate the
  735. * returned value before using it.
  736. */
  737. wpa_printf(MSG_DEBUG, "NDIS: skipped invalid scan "
  738. "result IE (BSSID=" MACSTR ") IELength=%d",
  739. MAC2STR(bss->MacAddress),
  740. (int) bss->IELength);
  741. break;
  742. }
  743. r = os_zalloc(sizeof(*r) + bss->IELength -
  744. sizeof(NDIS_802_11_FIXED_IEs));
  745. if (r == NULL)
  746. break;
  747. os_memcpy(r->bssid, bss->MacAddress, ETH_ALEN);
  748. r->level = (int) bss->Rssi;
  749. r->freq = bss->Configuration.DSConfig / 1000;
  750. fixed = (NDIS_802_11_FIXED_IEs *) bss->IEs;
  751. r->beacon_int = WPA_GET_LE16((u8 *) &fixed->BeaconInterval);
  752. r->caps = WPA_GET_LE16((u8 *) &fixed->Capabilities);
  753. r->tsf = WPA_GET_LE64(fixed->Timestamp);
  754. os_memcpy(r + 1, bss->IEs + sizeof(NDIS_802_11_FIXED_IEs),
  755. bss->IELength - sizeof(NDIS_802_11_FIXED_IEs));
  756. r->ie_len = bss->IELength - sizeof(NDIS_802_11_FIXED_IEs);
  757. r = wpa_driver_ndis_add_scan_ssid(r, &bss->Ssid);
  758. results->res[results->num++] = r;
  759. pos += bss->Length;
  760. if (pos > (char *) b + blen)
  761. break;
  762. }
  763. os_free(b);
  764. return results;
  765. }
  766. static int wpa_driver_ndis_remove_key(struct wpa_driver_ndis_data *drv,
  767. int key_idx, const u8 *addr,
  768. const u8 *bssid, int pairwise)
  769. {
  770. NDIS_802_11_REMOVE_KEY rkey;
  771. NDIS_802_11_KEY_INDEX index;
  772. int res, res2;
  773. os_memset(&rkey, 0, sizeof(rkey));
  774. rkey.Length = sizeof(rkey);
  775. rkey.KeyIndex = key_idx;
  776. if (pairwise)
  777. rkey.KeyIndex |= 1 << 30;
  778. os_memcpy(rkey.BSSID, bssid, ETH_ALEN);
  779. res = ndis_set_oid(drv, OID_802_11_REMOVE_KEY, (char *) &rkey,
  780. sizeof(rkey));
  781. if (!pairwise) {
  782. index = key_idx;
  783. res2 = ndis_set_oid(drv, OID_802_11_REMOVE_WEP,
  784. (char *) &index, sizeof(index));
  785. } else
  786. res2 = 0;
  787. if (res < 0 && res2 < 0)
  788. return -1;
  789. return 0;
  790. }
  791. static int wpa_driver_ndis_add_wep(struct wpa_driver_ndis_data *drv,
  792. int pairwise, int key_idx, int set_tx,
  793. const u8 *key, size_t key_len)
  794. {
  795. NDIS_802_11_WEP *wep;
  796. size_t len;
  797. int res;
  798. len = 12 + key_len;
  799. wep = os_zalloc(len);
  800. if (wep == NULL)
  801. return -1;
  802. wep->Length = len;
  803. wep->KeyIndex = key_idx;
  804. if (set_tx)
  805. wep->KeyIndex |= 1 << 31;
  806. #if 0 /* Setting bit30 does not seem to work with some NDIS drivers */
  807. if (pairwise)
  808. wep->KeyIndex |= 1 << 30;
  809. #endif
  810. wep->KeyLength = key_len;
  811. os_memcpy(wep->KeyMaterial, key, key_len);
  812. wpa_hexdump_key(MSG_MSGDUMP, "NDIS: OID_802_11_ADD_WEP",
  813. (u8 *) wep, len);
  814. res = ndis_set_oid(drv, OID_802_11_ADD_WEP, (char *) wep, len);
  815. os_free(wep);
  816. return res;
  817. }
  818. static int wpa_driver_ndis_set_key(const char *ifname, void *priv,
  819. enum wpa_alg alg, const u8 *addr,
  820. int key_idx, int set_tx,
  821. const u8 *seq, size_t seq_len,
  822. const u8 *key, size_t key_len)
  823. {
  824. struct wpa_driver_ndis_data *drv = priv;
  825. size_t len, i;
  826. NDIS_802_11_KEY *nkey;
  827. int res, pairwise;
  828. u8 bssid[ETH_ALEN];
  829. if (addr == NULL || is_broadcast_ether_addr(addr)) {
  830. /* Group Key */
  831. pairwise = 0;
  832. if (wpa_driver_ndis_get_bssid(drv, bssid) < 0)
  833. os_memset(bssid, 0xff, ETH_ALEN);
  834. } else {
  835. /* Pairwise Key */
  836. pairwise = 1;
  837. os_memcpy(bssid, addr, ETH_ALEN);
  838. }
  839. if (alg == WPA_ALG_NONE || key_len == 0) {
  840. return wpa_driver_ndis_remove_key(drv, key_idx, addr, bssid,
  841. pairwise);
  842. }
  843. if (alg == WPA_ALG_WEP) {
  844. return wpa_driver_ndis_add_wep(drv, pairwise, key_idx, set_tx,
  845. key, key_len);
  846. }
  847. len = 12 + 6 + 6 + 8 + key_len;
  848. nkey = os_zalloc(len);
  849. if (nkey == NULL)
  850. return -1;
  851. nkey->Length = len;
  852. nkey->KeyIndex = key_idx;
  853. if (set_tx)
  854. nkey->KeyIndex |= 1 << 31;
  855. if (pairwise)
  856. nkey->KeyIndex |= 1 << 30;
  857. if (seq && seq_len)
  858. nkey->KeyIndex |= 1 << 29;
  859. nkey->KeyLength = key_len;
  860. os_memcpy(nkey->BSSID, bssid, ETH_ALEN);
  861. if (seq && seq_len) {
  862. for (i = 0; i < seq_len; i++)
  863. nkey->KeyRSC |= (ULONGLONG) seq[i] << (i * 8);
  864. }
  865. if (alg == WPA_ALG_TKIP && key_len == 32) {
  866. os_memcpy(nkey->KeyMaterial, key, 16);
  867. os_memcpy(nkey->KeyMaterial + 16, key + 24, 8);
  868. os_memcpy(nkey->KeyMaterial + 24, key + 16, 8);
  869. } else {
  870. os_memcpy(nkey->KeyMaterial, key, key_len);
  871. }
  872. wpa_hexdump_key(MSG_MSGDUMP, "NDIS: OID_802_11_ADD_KEY",
  873. (u8 *) nkey, len);
  874. res = ndis_set_oid(drv, OID_802_11_ADD_KEY, (char *) nkey, len);
  875. os_free(nkey);
  876. return res;
  877. }
  878. static int
  879. wpa_driver_ndis_associate(void *priv,
  880. struct wpa_driver_associate_params *params)
  881. {
  882. struct wpa_driver_ndis_data *drv = priv;
  883. u32 auth_mode, encr, priv_mode, mode;
  884. u8 bcast[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
  885. drv->mode = params->mode;
  886. /* Note: Setting OID_802_11_INFRASTRUCTURE_MODE clears current keys,
  887. * so static WEP keys needs to be set again after this. */
  888. if (params->mode == IEEE80211_MODE_IBSS) {
  889. mode = Ndis802_11IBSS;
  890. /* Need to make sure that BSSID polling is enabled for
  891. * IBSS mode. */
  892. eloop_cancel_timeout(wpa_driver_ndis_poll_timeout, drv, NULL);
  893. eloop_register_timeout(1, 0, wpa_driver_ndis_poll_timeout,
  894. drv, NULL);
  895. } else
  896. mode = Ndis802_11Infrastructure;
  897. if (ndis_set_oid(drv, OID_802_11_INFRASTRUCTURE_MODE,
  898. (char *) &mode, sizeof(mode)) < 0) {
  899. wpa_printf(MSG_DEBUG, "NDIS: Failed to set "
  900. "OID_802_11_INFRASTRUCTURE_MODE (%d)",
  901. (int) mode);
  902. /* Try to continue anyway */
  903. }
  904. if (params->key_mgmt_suite == KEY_MGMT_NONE ||
  905. params->key_mgmt_suite == KEY_MGMT_802_1X_NO_WPA) {
  906. /* Re-set WEP keys if static WEP configuration is used. */
  907. int i;
  908. for (i = 0; i < 4; i++) {
  909. if (!params->wep_key[i])
  910. continue;
  911. wpa_printf(MSG_DEBUG, "NDIS: Re-setting static WEP "
  912. "key %d", i);
  913. wpa_driver_ndis_set_key(drv->ifname, drv, WPA_ALG_WEP,
  914. bcast, i,
  915. i == params->wep_tx_keyidx,
  916. NULL, 0, params->wep_key[i],
  917. params->wep_key_len[i]);
  918. }
  919. }
  920. if (params->wpa_ie == NULL || params->wpa_ie_len == 0) {
  921. if (params->auth_alg & WPA_AUTH_ALG_SHARED) {
  922. if (params->auth_alg & WPA_AUTH_ALG_OPEN)
  923. auth_mode = Ndis802_11AuthModeAutoSwitch;
  924. else
  925. auth_mode = Ndis802_11AuthModeShared;
  926. } else
  927. auth_mode = Ndis802_11AuthModeOpen;
  928. priv_mode = Ndis802_11PrivFilterAcceptAll;
  929. } else if (params->wpa_ie[0] == WLAN_EID_RSN) {
  930. priv_mode = Ndis802_11PrivFilter8021xWEP;
  931. if (params->key_mgmt_suite == KEY_MGMT_PSK)
  932. auth_mode = Ndis802_11AuthModeWPA2PSK;
  933. else
  934. auth_mode = Ndis802_11AuthModeWPA2;
  935. #ifdef CONFIG_WPS
  936. } else if (params->key_mgmt_suite == KEY_MGMT_WPS) {
  937. auth_mode = Ndis802_11AuthModeOpen;
  938. priv_mode = Ndis802_11PrivFilterAcceptAll;
  939. if (params->wps == WPS_MODE_PRIVACY) {
  940. u8 dummy_key[5] = { 0x11, 0x22, 0x33, 0x44, 0x55 };
  941. /*
  942. * Some NDIS drivers refuse to associate in open mode
  943. * configuration due to Privacy field mismatch, so use
  944. * a workaround to make the configuration look like
  945. * matching one for WPS provisioning.
  946. */
  947. wpa_printf(MSG_DEBUG, "NDIS: Set dummy WEP key as a "
  948. "workaround to allow driver to associate "
  949. "for WPS");
  950. wpa_driver_ndis_set_key(drv->ifname, drv, WPA_ALG_WEP,
  951. bcast, 0, 1,
  952. NULL, 0, dummy_key,
  953. sizeof(dummy_key));
  954. }
  955. #endif /* CONFIG_WPS */
  956. } else {
  957. priv_mode = Ndis802_11PrivFilter8021xWEP;
  958. if (params->key_mgmt_suite == KEY_MGMT_WPA_NONE)
  959. auth_mode = Ndis802_11AuthModeWPANone;
  960. else if (params->key_mgmt_suite == KEY_MGMT_PSK)
  961. auth_mode = Ndis802_11AuthModeWPAPSK;
  962. else
  963. auth_mode = Ndis802_11AuthModeWPA;
  964. }
  965. switch (params->pairwise_suite) {
  966. case CIPHER_CCMP:
  967. encr = Ndis802_11Encryption3Enabled;
  968. break;
  969. case CIPHER_TKIP:
  970. encr = Ndis802_11Encryption2Enabled;
  971. break;
  972. case CIPHER_WEP40:
  973. case CIPHER_WEP104:
  974. encr = Ndis802_11Encryption1Enabled;
  975. break;
  976. case CIPHER_NONE:
  977. #ifdef CONFIG_WPS
  978. if (params->wps == WPS_MODE_PRIVACY) {
  979. encr = Ndis802_11Encryption1Enabled;
  980. break;
  981. }
  982. #endif /* CONFIG_WPS */
  983. if (params->group_suite == CIPHER_CCMP)
  984. encr = Ndis802_11Encryption3Enabled;
  985. else if (params->group_suite == CIPHER_TKIP)
  986. encr = Ndis802_11Encryption2Enabled;
  987. else
  988. encr = Ndis802_11EncryptionDisabled;
  989. break;
  990. default:
  991. #ifdef CONFIG_WPS
  992. if (params->wps == WPS_MODE_PRIVACY) {
  993. encr = Ndis802_11Encryption1Enabled;
  994. break;
  995. }
  996. #endif /* CONFIG_WPS */
  997. encr = Ndis802_11EncryptionDisabled;
  998. break;
  999. };
  1000. if (ndis_set_oid(drv, OID_802_11_PRIVACY_FILTER,
  1001. (char *) &priv_mode, sizeof(priv_mode)) < 0) {
  1002. wpa_printf(MSG_DEBUG, "NDIS: Failed to set "
  1003. "OID_802_11_PRIVACY_FILTER (%d)",
  1004. (int) priv_mode);
  1005. /* Try to continue anyway */
  1006. }
  1007. ndis_set_auth_mode(drv, auth_mode);
  1008. ndis_set_encr_status(drv, encr);
  1009. if (params->bssid) {
  1010. ndis_set_oid(drv, OID_802_11_BSSID, (char *) params->bssid,
  1011. ETH_ALEN);
  1012. drv->oid_bssid_set = 1;
  1013. } else if (drv->oid_bssid_set) {
  1014. ndis_set_oid(drv, OID_802_11_BSSID, "\xff\xff\xff\xff\xff\xff",
  1015. ETH_ALEN);
  1016. drv->oid_bssid_set = 0;
  1017. }
  1018. return wpa_driver_ndis_set_ssid(drv, params->ssid, params->ssid_len);
  1019. }
  1020. static int wpa_driver_ndis_set_pmkid(struct wpa_driver_ndis_data *drv)
  1021. {
  1022. int len, count, i, ret;
  1023. struct ndis_pmkid_entry *entry;
  1024. NDIS_802_11_PMKID *p;
  1025. count = 0;
  1026. entry = drv->pmkid;
  1027. while (entry) {
  1028. count++;
  1029. if (count >= drv->no_of_pmkid)
  1030. break;
  1031. entry = entry->next;
  1032. }
  1033. len = 8 + count * sizeof(BSSID_INFO);
  1034. p = os_zalloc(len);
  1035. if (p == NULL)
  1036. return -1;
  1037. p->Length = len;
  1038. p->BSSIDInfoCount = count;
  1039. entry = drv->pmkid;
  1040. for (i = 0; i < count; i++) {
  1041. os_memcpy(&p->BSSIDInfo[i].BSSID, entry->bssid, ETH_ALEN);
  1042. os_memcpy(&p->BSSIDInfo[i].PMKID, entry->pmkid, 16);
  1043. entry = entry->next;
  1044. }
  1045. wpa_hexdump(MSG_MSGDUMP, "NDIS: OID_802_11_PMKID", (u8 *) p, len);
  1046. ret = ndis_set_oid(drv, OID_802_11_PMKID, (char *) p, len);
  1047. os_free(p);
  1048. return ret;
  1049. }
  1050. static int wpa_driver_ndis_add_pmkid(void *priv, const u8 *bssid,
  1051. const u8 *pmkid)
  1052. {
  1053. struct wpa_driver_ndis_data *drv = priv;
  1054. struct ndis_pmkid_entry *entry, *prev;
  1055. if (drv->no_of_pmkid == 0)
  1056. return 0;
  1057. prev = NULL;
  1058. entry = drv->pmkid;
  1059. while (entry) {
  1060. if (os_memcmp(entry->bssid, bssid, ETH_ALEN) == 0)
  1061. break;
  1062. prev = entry;
  1063. entry = entry->next;
  1064. }
  1065. if (entry) {
  1066. /* Replace existing entry for this BSSID and move it into the
  1067. * beginning of the list. */
  1068. os_memcpy(entry->pmkid, pmkid, 16);
  1069. if (prev) {
  1070. prev->next = entry->next;
  1071. entry->next = drv->pmkid;
  1072. drv->pmkid = entry;
  1073. }
  1074. } else {
  1075. entry = os_malloc(sizeof(*entry));
  1076. if (entry) {
  1077. os_memcpy(entry->bssid, bssid, ETH_ALEN);
  1078. os_memcpy(entry->pmkid, pmkid, 16);
  1079. entry->next = drv->pmkid;
  1080. drv->pmkid = entry;
  1081. }
  1082. }
  1083. return wpa_driver_ndis_set_pmkid(drv);
  1084. }
  1085. static int wpa_driver_ndis_remove_pmkid(void *priv, const u8 *bssid,
  1086. const u8 *pmkid)
  1087. {
  1088. struct wpa_driver_ndis_data *drv = priv;
  1089. struct ndis_pmkid_entry *entry, *prev;
  1090. if (drv->no_of_pmkid == 0)
  1091. return 0;
  1092. entry = drv->pmkid;
  1093. prev = NULL;
  1094. while (entry) {
  1095. if (os_memcmp(entry->bssid, bssid, ETH_ALEN) == 0 &&
  1096. os_memcmp(entry->pmkid, pmkid, 16) == 0) {
  1097. if (prev)
  1098. prev->next = entry->next;
  1099. else
  1100. drv->pmkid = entry->next;
  1101. os_free(entry);
  1102. break;
  1103. }
  1104. prev = entry;
  1105. entry = entry->next;
  1106. }
  1107. return wpa_driver_ndis_set_pmkid(drv);
  1108. }
  1109. static int wpa_driver_ndis_flush_pmkid(void *priv)
  1110. {
  1111. struct wpa_driver_ndis_data *drv = priv;
  1112. NDIS_802_11_PMKID p;
  1113. struct ndis_pmkid_entry *pmkid, *prev;
  1114. int prev_authmode, ret;
  1115. if (drv->no_of_pmkid == 0)
  1116. return 0;
  1117. pmkid = drv->pmkid;
  1118. drv->pmkid = NULL;
  1119. while (pmkid) {
  1120. prev = pmkid;
  1121. pmkid = pmkid->next;
  1122. os_free(prev);
  1123. }
  1124. /*
  1125. * Some drivers may refuse OID_802_11_PMKID if authMode is not set to
  1126. * WPA2, so change authMode temporarily, if needed.
  1127. */
  1128. prev_authmode = ndis_get_auth_mode(drv);
  1129. if (prev_authmode != Ndis802_11AuthModeWPA2)
  1130. ndis_set_auth_mode(drv, Ndis802_11AuthModeWPA2);
  1131. os_memset(&p, 0, sizeof(p));
  1132. p.Length = 8;
  1133. p.BSSIDInfoCount = 0;
  1134. wpa_hexdump(MSG_MSGDUMP, "NDIS: OID_802_11_PMKID (flush)",
  1135. (u8 *) &p, 8);
  1136. ret = ndis_set_oid(drv, OID_802_11_PMKID, (char *) &p, 8);
  1137. if (prev_authmode != Ndis802_11AuthModeWPA2)
  1138. ndis_set_auth_mode(drv, prev_authmode);
  1139. return ret;
  1140. }
  1141. static int wpa_driver_ndis_get_associnfo(struct wpa_driver_ndis_data *drv)
  1142. {
  1143. char buf[512], *pos;
  1144. NDIS_802_11_ASSOCIATION_INFORMATION *ai;
  1145. int len;
  1146. union wpa_event_data data;
  1147. NDIS_802_11_BSSID_LIST_EX *b;
  1148. size_t blen, i;
  1149. len = ndis_get_oid(drv, OID_802_11_ASSOCIATION_INFORMATION, buf,
  1150. sizeof(buf));
  1151. if (len < 0) {
  1152. wpa_printf(MSG_DEBUG, "NDIS: failed to get association "
  1153. "information");
  1154. return -1;
  1155. }
  1156. if (len > sizeof(buf)) {
  1157. /* Some drivers seem to be producing incorrect length for this
  1158. * data. Limit the length to the current buffer size to avoid
  1159. * crashing in hexdump. The data seems to be otherwise valid,
  1160. * so better try to use it. */
  1161. wpa_printf(MSG_DEBUG, "NDIS: ignored bogus association "
  1162. "information length %d", len);
  1163. len = ndis_get_oid(drv, OID_802_11_ASSOCIATION_INFORMATION,
  1164. buf, sizeof(buf));
  1165. if (len < -1) {
  1166. wpa_printf(MSG_DEBUG, "NDIS: re-reading association "
  1167. "information failed");
  1168. return -1;
  1169. }
  1170. if (len > sizeof(buf)) {
  1171. wpa_printf(MSG_DEBUG, "NDIS: ignored bogus association"
  1172. " information length %d (re-read)", len);
  1173. len = sizeof(buf);
  1174. }
  1175. }
  1176. wpa_hexdump(MSG_MSGDUMP, "NDIS: association information",
  1177. (u8 *) buf, len);
  1178. if (len < sizeof(*ai)) {
  1179. wpa_printf(MSG_DEBUG, "NDIS: too short association "
  1180. "information");
  1181. return -1;
  1182. }
  1183. ai = (NDIS_802_11_ASSOCIATION_INFORMATION *) buf;
  1184. wpa_printf(MSG_DEBUG, "NDIS: ReqFixed=0x%x RespFixed=0x%x off_req=%d "
  1185. "off_resp=%d len_req=%d len_resp=%d",
  1186. ai->AvailableRequestFixedIEs, ai->AvailableResponseFixedIEs,
  1187. (int) ai->OffsetRequestIEs, (int) ai->OffsetResponseIEs,
  1188. (int) ai->RequestIELength, (int) ai->ResponseIELength);
  1189. if (ai->OffsetRequestIEs + ai->RequestIELength > (unsigned) len ||
  1190. ai->OffsetResponseIEs + ai->ResponseIELength > (unsigned) len) {
  1191. wpa_printf(MSG_DEBUG, "NDIS: association information - "
  1192. "IE overflow");
  1193. return -1;
  1194. }
  1195. wpa_hexdump(MSG_MSGDUMP, "NDIS: Request IEs",
  1196. (u8 *) buf + ai->OffsetRequestIEs, ai->RequestIELength);
  1197. wpa_hexdump(MSG_MSGDUMP, "NDIS: Response IEs",
  1198. (u8 *) buf + ai->OffsetResponseIEs, ai->ResponseIELength);
  1199. os_memset(&data, 0, sizeof(data));
  1200. data.assoc_info.req_ies = (u8 *) buf + ai->OffsetRequestIEs;
  1201. data.assoc_info.req_ies_len = ai->RequestIELength;
  1202. data.assoc_info.resp_ies = (u8 *) buf + ai->OffsetResponseIEs;
  1203. data.assoc_info.resp_ies_len = ai->ResponseIELength;
  1204. blen = 65535;
  1205. b = os_zalloc(blen);
  1206. if (b == NULL)
  1207. goto skip_scan_results;
  1208. len = ndis_get_oid(drv, OID_802_11_BSSID_LIST, (char *) b, blen);
  1209. if (len < 0) {
  1210. wpa_printf(MSG_DEBUG, "NDIS: failed to get scan results");
  1211. os_free(b);
  1212. b = NULL;
  1213. goto skip_scan_results;
  1214. }
  1215. wpa_printf(MSG_DEBUG, "NDIS: %d BSSID items to process for AssocInfo",
  1216. (unsigned int) b->NumberOfItems);
  1217. pos = (char *) &b->Bssid[0];
  1218. for (i = 0; i < b->NumberOfItems; i++) {
  1219. NDIS_WLAN_BSSID_EX *bss = (NDIS_WLAN_BSSID_EX *) pos;
  1220. if (os_memcmp(drv->bssid, bss->MacAddress, ETH_ALEN) == 0 &&
  1221. bss->IELength > sizeof(NDIS_802_11_FIXED_IEs)) {
  1222. data.assoc_info.beacon_ies =
  1223. ((u8 *) bss->IEs) +
  1224. sizeof(NDIS_802_11_FIXED_IEs);
  1225. data.assoc_info.beacon_ies_len =
  1226. bss->IELength - sizeof(NDIS_802_11_FIXED_IEs);
  1227. wpa_hexdump(MSG_MSGDUMP, "NDIS: Beacon IEs",
  1228. data.assoc_info.beacon_ies,
  1229. data.assoc_info.beacon_ies_len);
  1230. break;
  1231. }
  1232. pos += bss->Length;
  1233. if (pos > (char *) b + blen)
  1234. break;
  1235. }
  1236. skip_scan_results:
  1237. wpa_supplicant_event(drv->ctx, EVENT_ASSOCINFO, &data);
  1238. os_free(b);
  1239. return 0;
  1240. }
  1241. static void wpa_driver_ndis_poll_timeout(void *eloop_ctx, void *timeout_ctx)
  1242. {
  1243. struct wpa_driver_ndis_data *drv = eloop_ctx;
  1244. u8 bssid[ETH_ALEN];
  1245. int poll;
  1246. if (drv->wired)
  1247. return;
  1248. if (wpa_driver_ndis_get_bssid(drv, bssid)) {
  1249. /* Disconnected */
  1250. if (!is_zero_ether_addr(drv->bssid)) {
  1251. os_memset(drv->bssid, 0, ETH_ALEN);
  1252. wpa_supplicant_event(drv->ctx, EVENT_DISASSOC, NULL);
  1253. }
  1254. } else {
  1255. /* Connected */
  1256. if (os_memcmp(drv->bssid, bssid, ETH_ALEN) != 0) {
  1257. os_memcpy(drv->bssid, bssid, ETH_ALEN);
  1258. wpa_driver_ndis_get_associnfo(drv);
  1259. wpa_supplicant_event(drv->ctx, EVENT_ASSOC, NULL);
  1260. }
  1261. }
  1262. /* When using integrated NDIS event receiver, we can skip BSSID
  1263. * polling when using infrastructure network. However, when using
  1264. * IBSS mode, many driver do not seem to generate connection event,
  1265. * so we need to enable BSSID polling to figure out when IBSS network
  1266. * has been formed.
  1267. */
  1268. poll = drv->mode == IEEE80211_MODE_IBSS;
  1269. #ifndef CONFIG_NDIS_EVENTS_INTEGRATED
  1270. #ifndef _WIN32_WCE
  1271. poll = 1;
  1272. #endif /* _WIN32_WCE */
  1273. #endif /* CONFIG_NDIS_EVENTS_INTEGRATED */
  1274. if (poll) {
  1275. eloop_register_timeout(1, 0, wpa_driver_ndis_poll_timeout,
  1276. drv, NULL);
  1277. }
  1278. }
  1279. static void wpa_driver_ndis_poll(void *priv)
  1280. {
  1281. struct wpa_driver_ndis_data *drv = priv;
  1282. eloop_cancel_timeout(wpa_driver_ndis_poll_timeout, drv, NULL);
  1283. wpa_driver_ndis_poll_timeout(drv, NULL);
  1284. }
  1285. /* Called when driver generates Media Connect Event by calling
  1286. * NdisMIndicateStatus() with NDIS_STATUS_MEDIA_CONNECT */
  1287. void wpa_driver_ndis_event_connect(struct wpa_driver_ndis_data *drv)
  1288. {
  1289. wpa_printf(MSG_DEBUG, "NDIS: Media Connect Event");
  1290. if (wpa_driver_ndis_get_bssid(drv, drv->bssid) == 0) {
  1291. wpa_driver_ndis_get_associnfo(drv);
  1292. wpa_supplicant_event(drv->ctx, EVENT_ASSOC, NULL);
  1293. }
  1294. }
  1295. /* Called when driver generates Media Disconnect Event by calling
  1296. * NdisMIndicateStatus() with NDIS_STATUS_MEDIA_DISCONNECT */
  1297. void wpa_driver_ndis_event_disconnect(struct wpa_driver_ndis_data *drv)
  1298. {
  1299. wpa_printf(MSG_DEBUG, "NDIS: Media Disconnect Event");
  1300. os_memset(drv->bssid, 0, ETH_ALEN);
  1301. wpa_supplicant_event(drv->ctx, EVENT_DISASSOC, NULL);
  1302. }
  1303. static void wpa_driver_ndis_event_auth(struct wpa_driver_ndis_data *drv,
  1304. const u8 *data, size_t data_len)
  1305. {
  1306. NDIS_802_11_AUTHENTICATION_REQUEST *req;
  1307. int pairwise = 0, group = 0;
  1308. union wpa_event_data event;
  1309. if (data_len < sizeof(*req)) {
  1310. wpa_printf(MSG_DEBUG, "NDIS: Too short Authentication Request "
  1311. "Event (len=%d)", data_len);
  1312. return;
  1313. }
  1314. req = (NDIS_802_11_AUTHENTICATION_REQUEST *) data;
  1315. wpa_printf(MSG_DEBUG, "NDIS: Authentication Request Event: "
  1316. "Bssid " MACSTR " Flags 0x%x",
  1317. MAC2STR(req->Bssid), (int) req->Flags);
  1318. if ((req->Flags & NDIS_802_11_AUTH_REQUEST_PAIRWISE_ERROR) ==
  1319. NDIS_802_11_AUTH_REQUEST_PAIRWISE_ERROR)
  1320. pairwise = 1;
  1321. else if ((req->Flags & NDIS_802_11_AUTH_REQUEST_GROUP_ERROR) ==
  1322. NDIS_802_11_AUTH_REQUEST_GROUP_ERROR)
  1323. group = 1;
  1324. if (pairwise || group) {
  1325. os_memset(&event, 0, sizeof(event));
  1326. event.michael_mic_failure.unicast = pairwise;
  1327. wpa_supplicant_event(drv->ctx, EVENT_MICHAEL_MIC_FAILURE,
  1328. &event);
  1329. }
  1330. }
  1331. static void wpa_driver_ndis_event_pmkid(struct wpa_driver_ndis_data *drv,
  1332. const u8 *data, size_t data_len)
  1333. {
  1334. NDIS_802_11_PMKID_CANDIDATE_LIST *pmkid;
  1335. size_t i;
  1336. union wpa_event_data event;
  1337. if (data_len < 8) {
  1338. wpa_printf(MSG_DEBUG, "NDIS: Too short PMKID Candidate List "
  1339. "Event (len=%d)", data_len);
  1340. return;
  1341. }
  1342. pmkid = (NDIS_802_11_PMKID_CANDIDATE_LIST *) data;
  1343. wpa_printf(MSG_DEBUG, "NDIS: PMKID Candidate List Event - Version %d "
  1344. "NumCandidates %d",
  1345. (int) pmkid->Version, (int) pmkid->NumCandidates);
  1346. if (pmkid->Version != 1) {
  1347. wpa_printf(MSG_DEBUG, "NDIS: Unsupported PMKID Candidate List "
  1348. "Version %d", (int) pmkid->Version);
  1349. return;
  1350. }
  1351. if (data_len < 8 + pmkid->NumCandidates * sizeof(PMKID_CANDIDATE)) {
  1352. wpa_printf(MSG_DEBUG, "NDIS: PMKID Candidate List underflow");
  1353. return;
  1354. }
  1355. os_memset(&event, 0, sizeof(event));
  1356. for (i = 0; i < pmkid->NumCandidates; i++) {
  1357. PMKID_CANDIDATE *p = &pmkid->CandidateList[i];
  1358. wpa_printf(MSG_DEBUG, "NDIS: %d: " MACSTR " Flags 0x%x",
  1359. i, MAC2STR(p->BSSID), (int) p->Flags);
  1360. os_memcpy(event.pmkid_candidate.bssid, p->BSSID, ETH_ALEN);
  1361. event.pmkid_candidate.index = i;
  1362. event.pmkid_candidate.preauth =
  1363. p->Flags & NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED;
  1364. wpa_supplicant_event(drv->ctx, EVENT_PMKID_CANDIDATE,
  1365. &event);
  1366. }
  1367. }
  1368. /* Called when driver calls NdisMIndicateStatus() with
  1369. * NDIS_STATUS_MEDIA_SPECIFIC_INDICATION */
  1370. void wpa_driver_ndis_event_media_specific(struct wpa_driver_ndis_data *drv,
  1371. const u8 *data, size_t data_len)
  1372. {
  1373. NDIS_802_11_STATUS_INDICATION *status;
  1374. if (data == NULL || data_len < sizeof(*status))
  1375. return;
  1376. wpa_hexdump(MSG_DEBUG, "NDIS: Media Specific Indication",
  1377. data, data_len);
  1378. status = (NDIS_802_11_STATUS_INDICATION *) data;
  1379. data += sizeof(status);
  1380. data_len -= sizeof(status);
  1381. switch (status->StatusType) {
  1382. case Ndis802_11StatusType_Authentication:
  1383. wpa_driver_ndis_event_auth(drv, data, data_len);
  1384. break;
  1385. case Ndis802_11StatusType_PMKID_CandidateList:
  1386. wpa_driver_ndis_event_pmkid(drv, data, data_len);
  1387. break;
  1388. default:
  1389. wpa_printf(MSG_DEBUG, "NDIS: Unknown StatusType %d",
  1390. (int) status->StatusType);
  1391. break;
  1392. }
  1393. }
  1394. /* Called when an adapter is added */
  1395. void wpa_driver_ndis_event_adapter_arrival(struct wpa_driver_ndis_data *drv)
  1396. {
  1397. union wpa_event_data event;
  1398. int i;
  1399. wpa_printf(MSG_DEBUG, "NDIS: Notify Adapter Arrival");
  1400. for (i = 0; i < 30; i++) {
  1401. /* Re-open Packet32/NDISUIO connection */
  1402. wpa_driver_ndis_adapter_close(drv);
  1403. if (wpa_driver_ndis_adapter_init(drv) < 0 ||
  1404. wpa_driver_ndis_adapter_open(drv) < 0) {
  1405. wpa_printf(MSG_DEBUG, "NDIS: Driver re-initialization "
  1406. "(%d) failed", i);
  1407. os_sleep(1, 0);
  1408. } else {
  1409. wpa_printf(MSG_DEBUG, "NDIS: Driver re-initialized");
  1410. break;
  1411. }
  1412. }
  1413. os_memset(&event, 0, sizeof(event));
  1414. os_strlcpy(event.interface_status.ifname, drv->ifname,
  1415. sizeof(event.interface_status.ifname));
  1416. event.interface_status.ievent = EVENT_INTERFACE_ADDED;
  1417. wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_STATUS, &event);
  1418. }
  1419. /* Called when an adapter is removed */
  1420. void wpa_driver_ndis_event_adapter_removal(struct wpa_driver_ndis_data *drv)
  1421. {
  1422. union wpa_event_data event;
  1423. wpa_printf(MSG_DEBUG, "NDIS: Notify Adapter Removal");
  1424. os_memset(&event, 0, sizeof(event));
  1425. os_strlcpy(event.interface_status.ifname, drv->ifname,
  1426. sizeof(event.interface_status.ifname));
  1427. event.interface_status.ievent = EVENT_INTERFACE_REMOVED;
  1428. wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_STATUS, &event);
  1429. }
  1430. static void
  1431. wpa_driver_ndis_get_wpa_capability(struct wpa_driver_ndis_data *drv)
  1432. {
  1433. wpa_printf(MSG_DEBUG, "NDIS: verifying driver WPA capability");
  1434. if (ndis_set_auth_mode(drv, Ndis802_11AuthModeWPA) == 0 &&
  1435. ndis_get_auth_mode(drv) == Ndis802_11AuthModeWPA) {
  1436. wpa_printf(MSG_DEBUG, "NDIS: WPA key management supported");
  1437. drv->capa.key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_WPA;
  1438. }
  1439. if (ndis_set_auth_mode(drv, Ndis802_11AuthModeWPAPSK) == 0 &&
  1440. ndis_get_auth_mode(drv) == Ndis802_11AuthModeWPAPSK) {
  1441. wpa_printf(MSG_DEBUG, "NDIS: WPA-PSK key management "
  1442. "supported");
  1443. drv->capa.key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK;
  1444. }
  1445. if (ndis_set_encr_status(drv, Ndis802_11Encryption3Enabled) == 0 &&
  1446. ndis_get_encr_status(drv) == Ndis802_11Encryption3KeyAbsent) {
  1447. wpa_printf(MSG_DEBUG, "NDIS: CCMP encryption supported");
  1448. drv->capa.enc |= WPA_DRIVER_CAPA_ENC_CCMP;
  1449. }
  1450. if (ndis_set_encr_status(drv, Ndis802_11Encryption2Enabled) == 0 &&
  1451. ndis_get_encr_status(drv) == Ndis802_11Encryption2KeyAbsent) {
  1452. wpa_printf(MSG_DEBUG, "NDIS: TKIP encryption supported");
  1453. drv->capa.enc |= WPA_DRIVER_CAPA_ENC_TKIP;
  1454. }
  1455. if (ndis_set_encr_status(drv, Ndis802_11Encryption1Enabled) == 0 &&
  1456. ndis_get_encr_status(drv) == Ndis802_11Encryption1KeyAbsent) {
  1457. wpa_printf(MSG_DEBUG, "NDIS: WEP encryption supported");
  1458. drv->capa.enc |= WPA_DRIVER_CAPA_ENC_WEP40 |
  1459. WPA_DRIVER_CAPA_ENC_WEP104;
  1460. }
  1461. if (ndis_set_auth_mode(drv, Ndis802_11AuthModeShared) == 0 &&
  1462. ndis_get_auth_mode(drv) == Ndis802_11AuthModeShared) {
  1463. drv->capa.auth |= WPA_DRIVER_AUTH_SHARED;
  1464. }
  1465. if (ndis_set_auth_mode(drv, Ndis802_11AuthModeOpen) == 0 &&
  1466. ndis_get_auth_mode(drv) == Ndis802_11AuthModeOpen) {
  1467. drv->capa.auth |= WPA_DRIVER_AUTH_OPEN;
  1468. }
  1469. ndis_set_encr_status(drv, Ndis802_11EncryptionDisabled);
  1470. /* Could also verify OID_802_11_ADD_KEY error reporting and
  1471. * support for OID_802_11_ASSOCIATION_INFORMATION. */
  1472. if (drv->capa.key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA &&
  1473. drv->capa.enc & (WPA_DRIVER_CAPA_ENC_TKIP |
  1474. WPA_DRIVER_CAPA_ENC_CCMP)) {
  1475. wpa_printf(MSG_DEBUG, "NDIS: driver supports WPA");
  1476. drv->has_capability = 1;
  1477. } else {
  1478. wpa_printf(MSG_DEBUG, "NDIS: no WPA support found");
  1479. }
  1480. wpa_printf(MSG_DEBUG, "NDIS: driver capabilities: key_mgmt 0x%x "
  1481. "enc 0x%x auth 0x%x",
  1482. drv->capa.key_mgmt, drv->capa.enc, drv->capa.auth);
  1483. }
  1484. static void wpa_driver_ndis_get_capability(struct wpa_driver_ndis_data *drv)
  1485. {
  1486. char buf[512];
  1487. int len;
  1488. size_t i;
  1489. NDIS_802_11_CAPABILITY *c;
  1490. drv->capa.flags = WPA_DRIVER_FLAGS_DRIVER_IE;
  1491. len = ndis_get_oid(drv, OID_802_11_CAPABILITY, buf, sizeof(buf));
  1492. if (len < 0) {
  1493. wpa_driver_ndis_get_wpa_capability(drv);
  1494. return;
  1495. }
  1496. wpa_hexdump(MSG_MSGDUMP, "OID_802_11_CAPABILITY", (u8 *) buf, len);
  1497. c = (NDIS_802_11_CAPABILITY *) buf;
  1498. if (len < sizeof(*c) || c->Version != 2) {
  1499. wpa_printf(MSG_DEBUG, "NDIS: unsupported "
  1500. "OID_802_11_CAPABILITY data");
  1501. return;
  1502. }
  1503. wpa_printf(MSG_DEBUG, "NDIS: Driver supports OID_802_11_CAPABILITY - "
  1504. "NoOfPMKIDs %d NoOfAuthEncrPairs %d",
  1505. (int) c->NoOfPMKIDs,
  1506. (int) c->NoOfAuthEncryptPairsSupported);
  1507. drv->has_capability = 1;
  1508. drv->no_of_pmkid = c->NoOfPMKIDs;
  1509. for (i = 0; i < c->NoOfAuthEncryptPairsSupported; i++) {
  1510. NDIS_802_11_AUTHENTICATION_ENCRYPTION *ae;
  1511. ae = &c->AuthenticationEncryptionSupported[i];
  1512. if ((char *) (ae + 1) > buf + len) {
  1513. wpa_printf(MSG_DEBUG, "NDIS: auth/encr pair list "
  1514. "overflow");
  1515. break;
  1516. }
  1517. wpa_printf(MSG_MSGDUMP, "NDIS: %d - auth %d encr %d",
  1518. i, (int) ae->AuthModeSupported,
  1519. (int) ae->EncryptStatusSupported);
  1520. switch (ae->AuthModeSupported) {
  1521. case Ndis802_11AuthModeOpen:
  1522. drv->capa.auth |= WPA_DRIVER_AUTH_OPEN;
  1523. break;
  1524. case Ndis802_11AuthModeShared:
  1525. drv->capa.auth |= WPA_DRIVER_AUTH_SHARED;
  1526. break;
  1527. case Ndis802_11AuthModeWPA:
  1528. drv->capa.key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_WPA;
  1529. break;
  1530. case Ndis802_11AuthModeWPAPSK:
  1531. drv->capa.key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK;
  1532. break;
  1533. case Ndis802_11AuthModeWPA2:
  1534. drv->capa.key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_WPA2;
  1535. break;
  1536. case Ndis802_11AuthModeWPA2PSK:
  1537. drv->capa.key_mgmt |=
  1538. WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK;
  1539. break;
  1540. case Ndis802_11AuthModeWPANone:
  1541. drv->capa.key_mgmt |=
  1542. WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE;
  1543. break;
  1544. default:
  1545. break;
  1546. }
  1547. switch (ae->EncryptStatusSupported) {
  1548. case Ndis802_11Encryption1Enabled:
  1549. drv->capa.enc |= WPA_DRIVER_CAPA_ENC_WEP40;
  1550. drv->capa.enc |= WPA_DRIVER_CAPA_ENC_WEP104;
  1551. break;
  1552. case Ndis802_11Encryption2Enabled:
  1553. drv->capa.enc |= WPA_DRIVER_CAPA_ENC_TKIP;
  1554. break;
  1555. case Ndis802_11Encryption3Enabled:
  1556. drv->capa.enc |= WPA_DRIVER_CAPA_ENC_CCMP;
  1557. break;
  1558. default:
  1559. break;
  1560. }
  1561. }
  1562. wpa_printf(MSG_DEBUG, "NDIS: driver capabilities: key_mgmt 0x%x "
  1563. "enc 0x%x auth 0x%x",
  1564. drv->capa.key_mgmt, drv->capa.enc, drv->capa.auth);
  1565. }
  1566. static int wpa_driver_ndis_get_capa(void *priv, struct wpa_driver_capa *capa)
  1567. {
  1568. struct wpa_driver_ndis_data *drv = priv;
  1569. if (!drv->has_capability)
  1570. return -1;
  1571. os_memcpy(capa, &drv->capa, sizeof(*capa));
  1572. return 0;
  1573. }
  1574. static const char * wpa_driver_ndis_get_ifname(void *priv)
  1575. {
  1576. struct wpa_driver_ndis_data *drv = priv;
  1577. return drv->ifname;
  1578. }
  1579. static const u8 * wpa_driver_ndis_get_mac_addr(void *priv)
  1580. {
  1581. struct wpa_driver_ndis_data *drv = priv;
  1582. return drv->own_addr;
  1583. }
  1584. #ifdef _WIN32_WCE
  1585. #define NDISUIO_MSG_SIZE (sizeof(NDISUIO_DEVICE_NOTIFICATION) + 512)
  1586. static void ndisuio_notification_receive(void *eloop_data, void *user_ctx)
  1587. {
  1588. struct wpa_driver_ndis_data *drv = eloop_data;
  1589. NDISUIO_DEVICE_NOTIFICATION *hdr;
  1590. u8 buf[NDISUIO_MSG_SIZE];
  1591. DWORD len, flags;
  1592. if (!ReadMsgQueue(drv->event_queue, buf, NDISUIO_MSG_SIZE, &len, 0,
  1593. &flags)) {
  1594. wpa_printf(MSG_DEBUG, "ndisuio_notification_receive: "
  1595. "ReadMsgQueue failed: %d", (int) GetLastError());
  1596. return;
  1597. }
  1598. if (len < sizeof(NDISUIO_DEVICE_NOTIFICATION)) {
  1599. wpa_printf(MSG_DEBUG, "ndisuio_notification_receive: "
  1600. "Too short message (len=%d)", (int) len);
  1601. return;
  1602. }
  1603. hdr = (NDISUIO_DEVICE_NOTIFICATION *) buf;
  1604. wpa_printf(MSG_DEBUG, "NDIS: Notification received: len=%d type=0x%x",
  1605. (int) len, hdr->dwNotificationType);
  1606. switch (hdr->dwNotificationType) {
  1607. #ifdef NDISUIO_NOTIFICATION_ADAPTER_ARRIVAL
  1608. case NDISUIO_NOTIFICATION_ADAPTER_ARRIVAL:
  1609. wpa_printf(MSG_DEBUG, "NDIS: ADAPTER_ARRIVAL");
  1610. wpa_driver_ndis_event_adapter_arrival(drv);
  1611. break;
  1612. #endif
  1613. #ifdef NDISUIO_NOTIFICATION_ADAPTER_REMOVAL
  1614. case NDISUIO_NOTIFICATION_ADAPTER_REMOVAL:
  1615. wpa_printf(MSG_DEBUG, "NDIS: ADAPTER_REMOVAL");
  1616. wpa_driver_ndis_event_adapter_removal(drv);
  1617. break;
  1618. #endif
  1619. case NDISUIO_NOTIFICATION_MEDIA_CONNECT:
  1620. wpa_printf(MSG_DEBUG, "NDIS: MEDIA_CONNECT");
  1621. SetEvent(drv->connected_event);
  1622. wpa_driver_ndis_event_connect(drv);
  1623. break;
  1624. case NDISUIO_NOTIFICATION_MEDIA_DISCONNECT:
  1625. ResetEvent(drv->connected_event);
  1626. wpa_printf(MSG_DEBUG, "NDIS: MEDIA_DISCONNECT");
  1627. wpa_driver_ndis_event_disconnect(drv);
  1628. break;
  1629. case NDISUIO_NOTIFICATION_MEDIA_SPECIFIC_NOTIFICATION:
  1630. wpa_printf(MSG_DEBUG, "NDIS: MEDIA_SPECIFIC_NOTIFICATION");
  1631. #if _WIN32_WCE == 420 || _WIN32_WCE == 0x420
  1632. wpa_driver_ndis_event_media_specific(
  1633. drv, hdr->pvStatusBuffer, hdr->uiStatusBufferSize);
  1634. #else
  1635. wpa_driver_ndis_event_media_specific(
  1636. drv, ((const u8 *) hdr) + hdr->uiOffsetToStatusBuffer,
  1637. (size_t) hdr->uiStatusBufferSize);
  1638. #endif
  1639. break;
  1640. default:
  1641. wpa_printf(MSG_DEBUG, "NDIS: Unknown notification type 0x%x",
  1642. hdr->dwNotificationType);
  1643. break;
  1644. }
  1645. }
  1646. static void ndisuio_notification_deinit(struct wpa_driver_ndis_data *drv)
  1647. {
  1648. NDISUIO_REQUEST_NOTIFICATION req;
  1649. memset(&req, 0, sizeof(req));
  1650. req.hMsgQueue = drv->event_queue;
  1651. req.dwNotificationTypes = 0;
  1652. if (!DeviceIoControl(drv->ndisuio, IOCTL_NDISUIO_REQUEST_NOTIFICATION,
  1653. &req, sizeof(req), NULL, 0, NULL, NULL)) {
  1654. wpa_printf(MSG_INFO, "ndisuio_notification_deinit: "
  1655. "IOCTL_NDISUIO_REQUEST_NOTIFICATION failed: %d",
  1656. (int) GetLastError());
  1657. }
  1658. if (!DeviceIoControl(drv->ndisuio, IOCTL_NDISUIO_CANCEL_NOTIFICATION,
  1659. NULL, 0, NULL, 0, NULL, NULL)) {
  1660. wpa_printf(MSG_INFO, "ndisuio_notification_deinit: "
  1661. "IOCTL_NDISUIO_CANCEL_NOTIFICATION failed: %d",
  1662. (int) GetLastError());
  1663. }
  1664. if (drv->event_queue) {
  1665. eloop_unregister_event(drv->event_queue,
  1666. sizeof(drv->event_queue));
  1667. CloseHandle(drv->event_queue);
  1668. drv->event_queue = NULL;
  1669. }
  1670. if (drv->connected_event) {
  1671. CloseHandle(drv->connected_event);
  1672. drv->connected_event = NULL;
  1673. }
  1674. }
  1675. static int ndisuio_notification_init(struct wpa_driver_ndis_data *drv)
  1676. {
  1677. MSGQUEUEOPTIONS opt;
  1678. NDISUIO_REQUEST_NOTIFICATION req;
  1679. drv->connected_event =
  1680. CreateEvent(NULL, TRUE, FALSE, TEXT("WpaSupplicantConnected"));
  1681. if (drv->connected_event == NULL) {
  1682. wpa_printf(MSG_INFO, "ndisuio_notification_init: "
  1683. "CreateEvent failed: %d",
  1684. (int) GetLastError());
  1685. return -1;
  1686. }
  1687. memset(&opt, 0, sizeof(opt));
  1688. opt.dwSize = sizeof(opt);
  1689. opt.dwMaxMessages = 5;
  1690. opt.cbMaxMessage = NDISUIO_MSG_SIZE;
  1691. opt.bReadAccess = TRUE;
  1692. drv->event_queue = CreateMsgQueue(NULL, &opt);
  1693. if (drv->event_queue == NULL) {
  1694. wpa_printf(MSG_INFO, "ndisuio_notification_init: "
  1695. "CreateMsgQueue failed: %d",
  1696. (int) GetLastError());
  1697. ndisuio_notification_deinit(drv);
  1698. return -1;
  1699. }
  1700. memset(&req, 0, sizeof(req));
  1701. req.hMsgQueue = drv->event_queue;
  1702. req.dwNotificationTypes =
  1703. #ifdef NDISUIO_NOTIFICATION_ADAPTER_ARRIVAL
  1704. NDISUIO_NOTIFICATION_ADAPTER_ARRIVAL |
  1705. #endif
  1706. #ifdef NDISUIO_NOTIFICATION_ADAPTER_REMOVAL
  1707. NDISUIO_NOTIFICATION_ADAPTER_REMOVAL |
  1708. #endif
  1709. NDISUIO_NOTIFICATION_MEDIA_CONNECT |
  1710. NDISUIO_NOTIFICATION_MEDIA_DISCONNECT |
  1711. NDISUIO_NOTIFICATION_MEDIA_SPECIFIC_NOTIFICATION;
  1712. if (!DeviceIoControl(drv->ndisuio, IOCTL_NDISUIO_REQUEST_NOTIFICATION,
  1713. &req, sizeof(req), NULL, 0, NULL, NULL)) {
  1714. wpa_printf(MSG_INFO, "ndisuio_notification_init: "
  1715. "IOCTL_NDISUIO_REQUEST_NOTIFICATION failed: %d",
  1716. (int) GetLastError());
  1717. ndisuio_notification_deinit(drv);
  1718. return -1;
  1719. }
  1720. eloop_register_event(drv->event_queue, sizeof(drv->event_queue),
  1721. ndisuio_notification_receive, drv, NULL);
  1722. return 0;
  1723. }
  1724. #endif /* _WIN32_WCE */
  1725. static int wpa_driver_ndis_get_names(struct wpa_driver_ndis_data *drv)
  1726. {
  1727. #ifdef CONFIG_USE_NDISUIO
  1728. NDISUIO_QUERY_BINDING *b;
  1729. size_t blen = sizeof(*b) + 1024;
  1730. int i, error, found = 0;
  1731. DWORD written;
  1732. char name[256], desc[256], *dpos;
  1733. WCHAR *pos;
  1734. size_t j, len, dlen;
  1735. b = os_malloc(blen);
  1736. if (b == NULL)
  1737. return -1;
  1738. for (i = 0; ; i++) {
  1739. os_memset(b, 0, blen);
  1740. b->BindingIndex = i;
  1741. if (!DeviceIoControl(drv->ndisuio, IOCTL_NDISUIO_QUERY_BINDING,
  1742. b, sizeof(NDISUIO_QUERY_BINDING), b, blen,
  1743. &written, NULL)) {
  1744. error = (int) GetLastError();
  1745. if (error == ERROR_NO_MORE_ITEMS)
  1746. break;
  1747. wpa_printf(MSG_DEBUG, "IOCTL_NDISUIO_QUERY_BINDING "
  1748. "failed: %d", error);
  1749. break;
  1750. }
  1751. pos = (WCHAR *) ((char *) b + b->DeviceNameOffset);
  1752. len = b->DeviceNameLength;
  1753. if (len >= sizeof(name))
  1754. len = sizeof(name) - 1;
  1755. for (j = 0; j < len; j++)
  1756. name[j] = (char) pos[j];
  1757. name[len] = '\0';
  1758. pos = (WCHAR *) ((char *) b + b->DeviceDescrOffset);
  1759. len = b->DeviceDescrLength;
  1760. if (len >= sizeof(desc))
  1761. len = sizeof(desc) - 1;
  1762. for (j = 0; j < len; j++)
  1763. desc[j] = (char) pos[j];
  1764. desc[len] = '\0';
  1765. wpa_printf(MSG_DEBUG, "NDIS: %d - %s - %s", i, name, desc);
  1766. if (os_strstr(name, drv->ifname)) {
  1767. wpa_printf(MSG_DEBUG, "NDIS: Interface name match");
  1768. found = 1;
  1769. break;
  1770. }
  1771. if (os_strncmp(desc, drv->ifname, os_strlen(drv->ifname)) == 0)
  1772. {
  1773. wpa_printf(MSG_DEBUG, "NDIS: Interface description "
  1774. "match");
  1775. found = 1;
  1776. break;
  1777. }
  1778. }
  1779. if (!found) {
  1780. wpa_printf(MSG_DEBUG, "NDIS: Could not find interface '%s'",
  1781. drv->ifname);
  1782. os_free(b);
  1783. return -1;
  1784. }
  1785. os_strlcpy(drv->ifname,
  1786. os_strncmp(name, "\\DEVICE\\", 8) == 0 ? name + 8 : name,
  1787. sizeof(drv->ifname));
  1788. #ifdef _WIN32_WCE
  1789. drv->adapter_name = wpa_strdup_tchar(drv->ifname);
  1790. if (drv->adapter_name == NULL) {
  1791. wpa_printf(MSG_ERROR, "NDIS: Failed to allocate memory for "
  1792. "adapter name");
  1793. os_free(b);
  1794. return -1;
  1795. }
  1796. #endif /* _WIN32_WCE */
  1797. dpos = os_strstr(desc, " - ");
  1798. if (dpos)
  1799. dlen = dpos - desc;
  1800. else
  1801. dlen = os_strlen(desc);
  1802. drv->adapter_desc = dup_binstr(desc, dlen);
  1803. os_free(b);
  1804. if (drv->adapter_desc == NULL)
  1805. return -1;
  1806. wpa_printf(MSG_DEBUG, "NDIS: Adapter description prefix '%s'",
  1807. drv->adapter_desc);
  1808. return 0;
  1809. #else /* CONFIG_USE_NDISUIO */
  1810. PTSTR _names;
  1811. char *names, *pos, *pos2;
  1812. ULONG len;
  1813. BOOLEAN res;
  1814. #define MAX_ADAPTERS 32
  1815. char *name[MAX_ADAPTERS];
  1816. char *desc[MAX_ADAPTERS];
  1817. int num_name, num_desc, i, found_name, found_desc;
  1818. size_t dlen;
  1819. wpa_printf(MSG_DEBUG, "NDIS: Packet.dll version: %s",
  1820. PacketGetVersion());
  1821. len = 8192;
  1822. _names = os_zalloc(len);
  1823. if (_names == NULL)
  1824. return -1;
  1825. res = PacketGetAdapterNames(_names, &len);
  1826. if (!res && len > 8192) {
  1827. os_free(_names);
  1828. _names = os_zalloc(len);
  1829. if (_names == NULL)
  1830. return -1;
  1831. res = PacketGetAdapterNames(_names, &len);
  1832. }
  1833. if (!res) {
  1834. wpa_printf(MSG_ERROR, "NDIS: Failed to get adapter list "
  1835. "(PacketGetAdapterNames)");
  1836. os_free(_names);
  1837. return -1;
  1838. }
  1839. names = (char *) _names;
  1840. if (names[0] && names[1] == '\0' && names[2] && names[3] == '\0') {
  1841. wpa_printf(MSG_DEBUG, "NDIS: Looks like adapter names are in "
  1842. "UNICODE");
  1843. /* Convert to ASCII */
  1844. pos2 = pos = names;
  1845. while (pos2 < names + len) {
  1846. if (pos2[0] == '\0' && pos2[1] == '\0' &&
  1847. pos2[2] == '\0' && pos2[3] == '\0') {
  1848. pos2 += 4;
  1849. break;
  1850. }
  1851. *pos++ = pos2[0];
  1852. pos2 += 2;
  1853. }
  1854. os_memcpy(pos + 2, names, pos - names);
  1855. pos += 2;
  1856. } else
  1857. pos = names;
  1858. num_name = 0;
  1859. while (pos < names + len) {
  1860. name[num_name] = pos;
  1861. while (*pos && pos < names + len)
  1862. pos++;
  1863. if (pos + 1 >= names + len) {
  1864. os_free(names);
  1865. return -1;
  1866. }
  1867. pos++;
  1868. num_name++;
  1869. if (num_name >= MAX_ADAPTERS) {
  1870. wpa_printf(MSG_DEBUG, "NDIS: Too many adapters");
  1871. os_free(names);
  1872. return -1;
  1873. }
  1874. if (*pos == '\0') {
  1875. wpa_printf(MSG_DEBUG, "NDIS: %d adapter names found",
  1876. num_name);
  1877. pos++;
  1878. break;
  1879. }
  1880. }
  1881. num_desc = 0;
  1882. while (pos < names + len) {
  1883. desc[num_desc] = pos;
  1884. while (*pos && pos < names + len)
  1885. pos++;
  1886. if (pos + 1 >= names + len) {
  1887. os_free(names);
  1888. return -1;
  1889. }
  1890. pos++;
  1891. num_desc++;
  1892. if (num_desc >= MAX_ADAPTERS) {
  1893. wpa_printf(MSG_DEBUG, "NDIS: Too many adapter "
  1894. "descriptions");
  1895. os_free(names);
  1896. return -1;
  1897. }
  1898. if (*pos == '\0') {
  1899. wpa_printf(MSG_DEBUG, "NDIS: %d adapter descriptions "
  1900. "found", num_name);
  1901. pos++;
  1902. break;
  1903. }
  1904. }
  1905. /*
  1906. * Windows 98 with Packet.dll 3.0 alpha3 does not include adapter
  1907. * descriptions. Fill in dummy descriptors to work around this.
  1908. */
  1909. while (num_desc < num_name)
  1910. desc[num_desc++] = "dummy description";
  1911. if (num_name != num_desc) {
  1912. wpa_printf(MSG_DEBUG, "NDIS: mismatch in adapter name and "
  1913. "description counts (%d != %d)",
  1914. num_name, num_desc);
  1915. os_free(names);
  1916. return -1;
  1917. }
  1918. found_name = found_desc = -1;
  1919. for (i = 0; i < num_name; i++) {
  1920. wpa_printf(MSG_DEBUG, "NDIS: %d - %s - %s",
  1921. i, name[i], desc[i]);
  1922. if (found_name == -1 && os_strstr(name[i], drv->ifname))
  1923. found_name = i;
  1924. if (found_desc == -1 &&
  1925. os_strncmp(desc[i], drv->ifname, os_strlen(drv->ifname)) ==
  1926. 0)
  1927. found_desc = i;
  1928. }
  1929. if (found_name < 0 && found_desc >= 0) {
  1930. wpa_printf(MSG_DEBUG, "NDIS: Matched interface '%s' based on "
  1931. "description '%s'",
  1932. name[found_desc], desc[found_desc]);
  1933. found_name = found_desc;
  1934. os_strlcpy(drv->ifname,
  1935. os_strncmp(name[found_desc], "\\Device\\NPF_", 12)
  1936. == 0 ? name[found_desc] + 12 : name[found_desc],
  1937. sizeof(drv->ifname));
  1938. }
  1939. if (found_name < 0) {
  1940. wpa_printf(MSG_DEBUG, "NDIS: Could not find interface '%s'",
  1941. drv->ifname);
  1942. os_free(names);
  1943. return -1;
  1944. }
  1945. i = found_name;
  1946. pos = os_strrchr(desc[i], '(');
  1947. if (pos) {
  1948. dlen = pos - desc[i];
  1949. pos--;
  1950. if (pos > desc[i] && *pos == ' ')
  1951. dlen--;
  1952. } else {
  1953. dlen = os_strlen(desc[i]);
  1954. }
  1955. drv->adapter_desc = dup_binstr(desc[i], dlen);
  1956. os_free(names);
  1957. if (drv->adapter_desc == NULL)
  1958. return -1;
  1959. wpa_printf(MSG_DEBUG, "NDIS: Adapter description prefix '%s'",
  1960. drv->adapter_desc);
  1961. return 0;
  1962. #endif /* CONFIG_USE_NDISUIO */
  1963. }
  1964. #if defined(CONFIG_NATIVE_WINDOWS) || defined(__CYGWIN__)
  1965. #ifndef _WIN32_WCE
  1966. /*
  1967. * These structures are undocumented for WinXP; only WinCE version is
  1968. * documented. These would be included wzcsapi.h if it were available. Some
  1969. * changes here have been needed to make the structures match with WinXP SP2.
  1970. * It is unclear whether these work with any other version.
  1971. */
  1972. typedef struct {
  1973. LPWSTR wszGuid;
  1974. } INTF_KEY_ENTRY, *PINTF_KEY_ENTRY;
  1975. typedef struct {
  1976. DWORD dwNumIntfs;
  1977. PINTF_KEY_ENTRY pIntfs;
  1978. } INTFS_KEY_TABLE, *PINTFS_KEY_TABLE;
  1979. typedef struct {
  1980. DWORD dwDataLen;
  1981. LPBYTE pData;
  1982. } RAW_DATA, *PRAW_DATA;
  1983. typedef struct {
  1984. LPWSTR wszGuid;
  1985. LPWSTR wszDescr;
  1986. ULONG ulMediaState;
  1987. ULONG ulMediaType;
  1988. ULONG ulPhysicalMediaType;
  1989. INT nInfraMode;
  1990. INT nAuthMode;
  1991. INT nWepStatus;
  1992. #ifndef _WIN32_WCE
  1993. u8 pad[2]; /* why is this needed? */
  1994. #endif /* _WIN32_WCE */
  1995. DWORD dwCtlFlags;
  1996. DWORD dwCapabilities; /* something added for WinXP SP2(?) */
  1997. RAW_DATA rdSSID;
  1998. RAW_DATA rdBSSID;
  1999. RAW_DATA rdBSSIDList;
  2000. RAW_DATA rdStSSIDList;
  2001. RAW_DATA rdCtrlData;
  2002. #ifdef UNDER_CE
  2003. BOOL bInitialized;
  2004. #endif
  2005. DWORD nWPAMCastCipher;
  2006. /* add some extra buffer for later additions since this interface is
  2007. * far from stable */
  2008. u8 later_additions[100];
  2009. } INTF_ENTRY, *PINTF_ENTRY;
  2010. #define INTF_ALL 0xffffffff
  2011. #define INTF_ALL_FLAGS 0x0000ffff
  2012. #define INTF_CTLFLAGS 0x00000010
  2013. #define INTFCTL_ENABLED 0x8000
  2014. #endif /* _WIN32_WCE */
  2015. #ifdef _WIN32_WCE
  2016. static int wpa_driver_ndis_rebind_adapter(struct wpa_driver_ndis_data *drv)
  2017. {
  2018. HANDLE ndis;
  2019. TCHAR multi[100];
  2020. int len;
  2021. len = _tcslen(drv->adapter_name);
  2022. if (len > 80)
  2023. return -1;
  2024. ndis = CreateFile(DD_NDIS_DEVICE_NAME, GENERIC_READ | GENERIC_WRITE,
  2025. 0, NULL, OPEN_EXISTING, 0, NULL);
  2026. if (ndis == INVALID_HANDLE_VALUE) {
  2027. wpa_printf(MSG_DEBUG, "NDIS: Failed to open file to NDIS "
  2028. "device: %d", (int) GetLastError());
  2029. return -1;
  2030. }
  2031. len++;
  2032. memcpy(multi, drv->adapter_name, len * sizeof(TCHAR));
  2033. memcpy(&multi[len], TEXT("NDISUIO\0"), 9 * sizeof(TCHAR));
  2034. len += 9;
  2035. if (!DeviceIoControl(ndis, IOCTL_NDIS_REBIND_ADAPTER,
  2036. multi, len * sizeof(TCHAR), NULL, 0, NULL, NULL))
  2037. {
  2038. wpa_printf(MSG_DEBUG, "NDIS: IOCTL_NDIS_REBIND_ADAPTER "
  2039. "failed: 0x%x", (int) GetLastError());
  2040. wpa_hexdump_ascii(MSG_DEBUG, "NDIS: rebind multi_sz",
  2041. (u8 *) multi, len * sizeof(TCHAR));
  2042. CloseHandle(ndis);
  2043. return -1;
  2044. }
  2045. CloseHandle(ndis);
  2046. wpa_printf(MSG_DEBUG, "NDIS: Requested NDIS rebind of NDISUIO "
  2047. "protocol");
  2048. return 0;
  2049. }
  2050. #endif /* _WIN32_WCE */
  2051. static int wpa_driver_ndis_set_wzc(struct wpa_driver_ndis_data *drv,
  2052. int enable)
  2053. {
  2054. #ifdef _WIN32_WCE
  2055. HKEY hk, hk2;
  2056. LONG ret;
  2057. DWORD i, hnd, len;
  2058. TCHAR keyname[256], devname[256];
  2059. #define WZC_DRIVER TEXT("Drivers\\BuiltIn\\ZeroConfig")
  2060. if (enable) {
  2061. HANDLE h;
  2062. h = ActivateDeviceEx(WZC_DRIVER, NULL, 0, NULL);
  2063. if (h == INVALID_HANDLE_VALUE || h == 0) {
  2064. wpa_printf(MSG_DEBUG, "NDIS: Failed to re-enable WZC "
  2065. "- ActivateDeviceEx failed: %d",
  2066. (int) GetLastError());
  2067. return -1;
  2068. }
  2069. wpa_printf(MSG_DEBUG, "NDIS: WZC re-enabled");
  2070. return wpa_driver_ndis_rebind_adapter(drv);
  2071. }
  2072. /*
  2073. * Unfortunately, just disabling the WZC for an interface is not enough
  2074. * to free NDISUIO for us, so need to disable and unload WZC completely
  2075. * for now when using WinCE with NDISUIO. In addition, must request
  2076. * NDISUIO protocol to be rebound to the adapter in order to free the
  2077. * NDISUIO binding that WZC hold before us.
  2078. */
  2079. /* Enumerate HKLM\Drivers\Active\* to find a handle to WZC. */
  2080. ret = RegOpenKeyEx(HKEY_LOCAL_MACHINE, DEVLOAD_ACTIVE_KEY, 0, 0, &hk);
  2081. if (ret != ERROR_SUCCESS) {
  2082. wpa_printf(MSG_DEBUG, "NDIS: RegOpenKeyEx(DEVLOAD_ACTIVE_KEY) "
  2083. "failed: %d %d", (int) ret, (int) GetLastError());
  2084. return -1;
  2085. }
  2086. for (i = 0; ; i++) {
  2087. len = sizeof(keyname);
  2088. ret = RegEnumKeyEx(hk, i, keyname, &len, NULL, NULL, NULL,
  2089. NULL);
  2090. if (ret != ERROR_SUCCESS) {
  2091. wpa_printf(MSG_DEBUG, "NDIS: Could not find active "
  2092. "WZC - assuming it is not running.");
  2093. RegCloseKey(hk);
  2094. return -1;
  2095. }
  2096. ret = RegOpenKeyEx(hk, keyname, 0, 0, &hk2);
  2097. if (ret != ERROR_SUCCESS) {
  2098. wpa_printf(MSG_DEBUG, "NDIS: RegOpenKeyEx(active dev) "
  2099. "failed: %d %d",
  2100. (int) ret, (int) GetLastError());
  2101. continue;
  2102. }
  2103. len = sizeof(devname);
  2104. ret = RegQueryValueEx(hk2, DEVLOAD_DEVKEY_VALNAME, NULL, NULL,
  2105. (LPBYTE) devname, &len);
  2106. if (ret != ERROR_SUCCESS) {
  2107. wpa_printf(MSG_DEBUG, "NDIS: RegQueryValueEx("
  2108. "DEVKEY_VALNAME) failed: %d %d",
  2109. (int) ret, (int) GetLastError());
  2110. RegCloseKey(hk2);
  2111. continue;
  2112. }
  2113. if (_tcscmp(devname, WZC_DRIVER) == 0)
  2114. break;
  2115. RegCloseKey(hk2);
  2116. }
  2117. RegCloseKey(hk);
  2118. /* Found WZC - get handle to it. */
  2119. len = sizeof(hnd);
  2120. ret = RegQueryValueEx(hk2, DEVLOAD_HANDLE_VALNAME, NULL, NULL,
  2121. (PUCHAR) &hnd, &len);
  2122. if (ret != ERROR_SUCCESS) {
  2123. wpa_printf(MSG_DEBUG, "NDIS: RegQueryValueEx(HANDLE_VALNAME) "
  2124. "failed: %d %d", (int) ret, (int) GetLastError());
  2125. RegCloseKey(hk2);
  2126. return -1;
  2127. }
  2128. RegCloseKey(hk2);
  2129. /* Deactivate WZC */
  2130. if (!DeactivateDevice((HANDLE) hnd)) {
  2131. wpa_printf(MSG_DEBUG, "NDIS: DeactivateDevice failed: %d",
  2132. (int) GetLastError());
  2133. return -1;
  2134. }
  2135. wpa_printf(MSG_DEBUG, "NDIS: Disabled WZC temporarily");
  2136. drv->wzc_disabled = 1;
  2137. return wpa_driver_ndis_rebind_adapter(drv);
  2138. #else /* _WIN32_WCE */
  2139. HMODULE hm;
  2140. DWORD (WINAPI *wzc_enum_interf)(LPWSTR pSrvAddr,
  2141. PINTFS_KEY_TABLE pIntfs);
  2142. DWORD (WINAPI *wzc_query_interf)(LPWSTR pSrvAddr, DWORD dwInFlags,
  2143. PINTF_ENTRY pIntf,
  2144. LPDWORD pdwOutFlags);
  2145. DWORD (WINAPI *wzc_set_interf)(LPWSTR pSrvAddr, DWORD dwInFlags,
  2146. PINTF_ENTRY pIntf, LPDWORD pdwOutFlags);
  2147. int ret = -1, j;
  2148. DWORD res;
  2149. INTFS_KEY_TABLE guids;
  2150. INTF_ENTRY intf;
  2151. char guid[128];
  2152. WCHAR *pos;
  2153. DWORD flags, i;
  2154. hm = LoadLibrary(TEXT("wzcsapi.dll"));
  2155. if (hm == NULL) {
  2156. wpa_printf(MSG_DEBUG, "NDIS: Failed to load wzcsapi.dll (%u) "
  2157. "- WZC probably not running",
  2158. (unsigned int) GetLastError());
  2159. return -1;
  2160. }
  2161. #ifdef _WIN32_WCE
  2162. wzc_enum_interf = (void *) GetProcAddressA(hm, "WZCEnumInterfaces");
  2163. wzc_query_interf = (void *) GetProcAddressA(hm, "WZCQueryInterface");
  2164. wzc_set_interf = (void *) GetProcAddressA(hm, "WZCSetInterface");
  2165. #else /* _WIN32_WCE */
  2166. wzc_enum_interf = (void *) GetProcAddress(hm, "WZCEnumInterfaces");
  2167. wzc_query_interf = (void *) GetProcAddress(hm, "WZCQueryInterface");
  2168. wzc_set_interf = (void *) GetProcAddress(hm, "WZCSetInterface");
  2169. #endif /* _WIN32_WCE */
  2170. if (wzc_enum_interf == NULL || wzc_query_interf == NULL ||
  2171. wzc_set_interf == NULL) {
  2172. wpa_printf(MSG_DEBUG, "NDIS: WZCEnumInterfaces, "
  2173. "WZCQueryInterface, or WZCSetInterface not found "
  2174. "in wzcsapi.dll");
  2175. goto fail;
  2176. }
  2177. os_memset(&guids, 0, sizeof(guids));
  2178. res = wzc_enum_interf(NULL, &guids);
  2179. if (res != 0) {
  2180. wpa_printf(MSG_DEBUG, "NDIS: WZCEnumInterfaces failed: %d; "
  2181. "WZC service is apparently not running",
  2182. (int) res);
  2183. goto fail;
  2184. }
  2185. wpa_printf(MSG_DEBUG, "NDIS: WZCEnumInterfaces: %d interfaces",
  2186. (int) guids.dwNumIntfs);
  2187. for (i = 0; i < guids.dwNumIntfs; i++) {
  2188. pos = guids.pIntfs[i].wszGuid;
  2189. for (j = 0; j < sizeof(guid); j++) {
  2190. guid[j] = (char) *pos;
  2191. if (*pos == 0)
  2192. break;
  2193. pos++;
  2194. }
  2195. guid[sizeof(guid) - 1] = '\0';
  2196. wpa_printf(MSG_DEBUG, "NDIS: intfs %d GUID '%s'",
  2197. (int) i, guid);
  2198. if (os_strstr(drv->ifname, guid) == NULL)
  2199. continue;
  2200. wpa_printf(MSG_DEBUG, "NDIS: Current interface found from "
  2201. "WZC");
  2202. break;
  2203. }
  2204. if (i >= guids.dwNumIntfs) {
  2205. wpa_printf(MSG_DEBUG, "NDIS: Current interface not found from "
  2206. "WZC");
  2207. goto fail;
  2208. }
  2209. os_memset(&intf, 0, sizeof(intf));
  2210. intf.wszGuid = guids.pIntfs[i].wszGuid;
  2211. /* Set flags to verify that the structure has not changed. */
  2212. intf.dwCtlFlags = -1;
  2213. flags = 0;
  2214. res = wzc_query_interf(NULL, INTFCTL_ENABLED, &intf, &flags);
  2215. if (res != 0) {
  2216. wpa_printf(MSG_DEBUG, "NDIS: Could not query flags for the "
  2217. "WZC interface: %d (0x%x)",
  2218. (int) res, (int) res);
  2219. wpa_printf(MSG_DEBUG, "NDIS: GetLastError: %u",
  2220. (unsigned int) GetLastError());
  2221. goto fail;
  2222. }
  2223. wpa_printf(MSG_DEBUG, "NDIS: WZC interface flags 0x%x dwCtlFlags 0x%x",
  2224. (int) flags, (int) intf.dwCtlFlags);
  2225. if (intf.dwCtlFlags == -1) {
  2226. wpa_printf(MSG_DEBUG, "NDIS: Looks like wzcsapi has changed "
  2227. "again - could not disable WZC");
  2228. wpa_hexdump(MSG_MSGDUMP, "NDIS: intf",
  2229. (u8 *) &intf, sizeof(intf));
  2230. goto fail;
  2231. }
  2232. if (enable) {
  2233. if (!(intf.dwCtlFlags & INTFCTL_ENABLED)) {
  2234. wpa_printf(MSG_DEBUG, "NDIS: Enabling WZC for this "
  2235. "interface");
  2236. intf.dwCtlFlags |= INTFCTL_ENABLED;
  2237. res = wzc_set_interf(NULL, INTFCTL_ENABLED, &intf,
  2238. &flags);
  2239. if (res != 0) {
  2240. wpa_printf(MSG_DEBUG, "NDIS: Failed to enable "
  2241. "WZC: %d (0x%x)",
  2242. (int) res, (int) res);
  2243. wpa_printf(MSG_DEBUG, "NDIS: GetLastError: %u",
  2244. (unsigned int) GetLastError());
  2245. goto fail;
  2246. }
  2247. wpa_printf(MSG_DEBUG, "NDIS: Re-enabled WZC for this "
  2248. "interface");
  2249. drv->wzc_disabled = 0;
  2250. }
  2251. } else {
  2252. if (intf.dwCtlFlags & INTFCTL_ENABLED) {
  2253. wpa_printf(MSG_DEBUG, "NDIS: Disabling WZC for this "
  2254. "interface");
  2255. intf.dwCtlFlags &= ~INTFCTL_ENABLED;
  2256. res = wzc_set_interf(NULL, INTFCTL_ENABLED, &intf,
  2257. &flags);
  2258. if (res != 0) {
  2259. wpa_printf(MSG_DEBUG, "NDIS: Failed to "
  2260. "disable WZC: %d (0x%x)",
  2261. (int) res, (int) res);
  2262. wpa_printf(MSG_DEBUG, "NDIS: GetLastError: %u",
  2263. (unsigned int) GetLastError());
  2264. goto fail;
  2265. }
  2266. wpa_printf(MSG_DEBUG, "NDIS: Disabled WZC temporarily "
  2267. "for this interface");
  2268. drv->wzc_disabled = 1;
  2269. } else {
  2270. wpa_printf(MSG_DEBUG, "NDIS: WZC was not enabled for "
  2271. "this interface");
  2272. }
  2273. }
  2274. ret = 0;
  2275. fail:
  2276. FreeLibrary(hm);
  2277. return ret;
  2278. #endif /* _WIN32_WCE */
  2279. }
  2280. #else /* CONFIG_NATIVE_WINDOWS || __CYGWIN__ */
  2281. static int wpa_driver_ndis_set_wzc(struct wpa_driver_ndis_data *drv,
  2282. int enable)
  2283. {
  2284. return 0;
  2285. }
  2286. #endif /* CONFIG_NATIVE_WINDOWS || __CYGWIN__ */
  2287. #ifdef CONFIG_USE_NDISUIO
  2288. /*
  2289. * l2_packet_ndis.c is sharing the same handle to NDISUIO, so we must be able
  2290. * to export this handle. This is somewhat ugly, but there is no better
  2291. * mechanism available to pass data from driver interface to l2_packet wrapper.
  2292. */
  2293. static HANDLE driver_ndis_ndisuio_handle = INVALID_HANDLE_VALUE;
  2294. HANDLE driver_ndis_get_ndisuio_handle(void)
  2295. {
  2296. return driver_ndis_ndisuio_handle;
  2297. }
  2298. #endif /* CONFIG_USE_NDISUIO */
  2299. static int wpa_driver_ndis_adapter_init(struct wpa_driver_ndis_data *drv)
  2300. {
  2301. #ifdef CONFIG_USE_NDISUIO
  2302. #ifndef _WIN32_WCE
  2303. #define NDISUIO_DEVICE_NAME TEXT("\\\\.\\\\Ndisuio")
  2304. DWORD written;
  2305. #endif /* _WIN32_WCE */
  2306. drv->ndisuio = CreateFile(NDISUIO_DEVICE_NAME,
  2307. GENERIC_READ | GENERIC_WRITE, 0, NULL,
  2308. OPEN_EXISTING,
  2309. FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED,
  2310. INVALID_HANDLE_VALUE);
  2311. if (drv->ndisuio == INVALID_HANDLE_VALUE) {
  2312. wpa_printf(MSG_ERROR, "NDIS: Failed to open connection to "
  2313. "NDISUIO: %d", (int) GetLastError());
  2314. return -1;
  2315. }
  2316. driver_ndis_ndisuio_handle = drv->ndisuio;
  2317. #ifndef _WIN32_WCE
  2318. if (!DeviceIoControl(drv->ndisuio, IOCTL_NDISUIO_BIND_WAIT, NULL, 0,
  2319. NULL, 0, &written, NULL)) {
  2320. wpa_printf(MSG_ERROR, "NDIS: IOCTL_NDISUIO_BIND_WAIT failed: "
  2321. "%d", (int) GetLastError());
  2322. CloseHandle(drv->ndisuio);
  2323. drv->ndisuio = INVALID_HANDLE_VALUE;
  2324. return -1;
  2325. }
  2326. #endif /* _WIN32_WCE */
  2327. return 0;
  2328. #else /* CONFIG_USE_NDISUIO */
  2329. return 0;
  2330. #endif /* CONFIG_USE_NDISUIO */
  2331. }
  2332. static int wpa_driver_ndis_adapter_open(struct wpa_driver_ndis_data *drv)
  2333. {
  2334. #ifdef CONFIG_USE_NDISUIO
  2335. DWORD written;
  2336. #define MAX_NDIS_DEVICE_NAME_LEN 256
  2337. WCHAR ifname[MAX_NDIS_DEVICE_NAME_LEN];
  2338. size_t len, i, pos;
  2339. const char *prefix = "\\DEVICE\\";
  2340. #ifdef _WIN32_WCE
  2341. pos = 0;
  2342. #else /* _WIN32_WCE */
  2343. pos = 8;
  2344. #endif /* _WIN32_WCE */
  2345. len = pos + os_strlen(drv->ifname);
  2346. if (len >= MAX_NDIS_DEVICE_NAME_LEN)
  2347. return -1;
  2348. for (i = 0; i < pos; i++)
  2349. ifname[i] = (WCHAR) prefix[i];
  2350. for (i = pos; i < len; i++)
  2351. ifname[i] = (WCHAR) drv->ifname[i - pos];
  2352. ifname[i] = L'\0';
  2353. if (!DeviceIoControl(drv->ndisuio, IOCTL_NDISUIO_OPEN_DEVICE,
  2354. ifname, len * sizeof(WCHAR), NULL, 0, &written,
  2355. NULL)) {
  2356. wpa_printf(MSG_ERROR, "NDIS: IOCTL_NDISUIO_OPEN_DEVICE "
  2357. "failed: %d", (int) GetLastError());
  2358. wpa_hexdump_ascii(MSG_DEBUG, "NDIS: ifname",
  2359. (const u8 *) ifname, len * sizeof(WCHAR));
  2360. CloseHandle(drv->ndisuio);
  2361. drv->ndisuio = INVALID_HANDLE_VALUE;
  2362. return -1;
  2363. }
  2364. wpa_printf(MSG_DEBUG, "NDIS: Opened NDISUIO device successfully");
  2365. return 0;
  2366. #else /* CONFIG_USE_NDISUIO */
  2367. char ifname[128];
  2368. os_snprintf(ifname, sizeof(ifname), "\\Device\\NPF_%s", drv->ifname);
  2369. drv->adapter = PacketOpenAdapter(ifname);
  2370. if (drv->adapter == NULL) {
  2371. wpa_printf(MSG_DEBUG, "NDIS: PacketOpenAdapter failed for "
  2372. "'%s'", ifname);
  2373. return -1;
  2374. }
  2375. return 0;
  2376. #endif /* CONFIG_USE_NDISUIO */
  2377. }
  2378. static void wpa_driver_ndis_adapter_close(struct wpa_driver_ndis_data *drv)
  2379. {
  2380. #ifdef CONFIG_USE_NDISUIO
  2381. driver_ndis_ndisuio_handle = INVALID_HANDLE_VALUE;
  2382. if (drv->ndisuio != INVALID_HANDLE_VALUE)
  2383. CloseHandle(drv->ndisuio);
  2384. #else /* CONFIG_USE_NDISUIO */
  2385. if (drv->adapter)
  2386. PacketCloseAdapter(drv->adapter);
  2387. #endif /* CONFIG_USE_NDISUIO */
  2388. }
  2389. static int ndis_add_multicast(struct wpa_driver_ndis_data *drv)
  2390. {
  2391. if (ndis_set_oid(drv, OID_802_3_MULTICAST_LIST,
  2392. (const char *) pae_group_addr, ETH_ALEN) < 0) {
  2393. wpa_printf(MSG_DEBUG, "NDIS: Failed to add PAE group address "
  2394. "to the multicast list");
  2395. return -1;
  2396. }
  2397. return 0;
  2398. }
  2399. static void * wpa_driver_ndis_init(void *ctx, const char *ifname)
  2400. {
  2401. struct wpa_driver_ndis_data *drv;
  2402. u32 mode;
  2403. drv = os_zalloc(sizeof(*drv));
  2404. if (drv == NULL)
  2405. return NULL;
  2406. drv->ctx = ctx;
  2407. /*
  2408. * Compatibility code to strip possible prefix from the GUID. Previous
  2409. * versions include \Device\NPF_ prefix for all names, but the internal
  2410. * interface name is now only the GUI. Both Packet32 and NDISUIO
  2411. * prefixes are supported.
  2412. */
  2413. if (os_strncmp(ifname, "\\Device\\NPF_", 12) == 0)
  2414. ifname += 12;
  2415. else if (os_strncmp(ifname, "\\DEVICE\\", 8) == 0)
  2416. ifname += 8;
  2417. os_strlcpy(drv->ifname, ifname, sizeof(drv->ifname));
  2418. if (wpa_driver_ndis_adapter_init(drv) < 0) {
  2419. os_free(drv);
  2420. return NULL;
  2421. }
  2422. if (wpa_driver_ndis_get_names(drv) < 0) {
  2423. wpa_driver_ndis_adapter_close(drv);
  2424. os_free(drv);
  2425. return NULL;
  2426. }
  2427. wpa_driver_ndis_set_wzc(drv, 0);
  2428. if (wpa_driver_ndis_adapter_open(drv) < 0) {
  2429. wpa_driver_ndis_adapter_close(drv);
  2430. os_free(drv);
  2431. return NULL;
  2432. }
  2433. if (ndis_get_oid(drv, OID_802_3_CURRENT_ADDRESS,
  2434. (char *) drv->own_addr, ETH_ALEN) < 0) {
  2435. wpa_printf(MSG_DEBUG, "NDIS: Get OID_802_3_CURRENT_ADDRESS "
  2436. "failed");
  2437. wpa_driver_ndis_adapter_close(drv);
  2438. os_free(drv);
  2439. return NULL;
  2440. }
  2441. wpa_driver_ndis_get_capability(drv);
  2442. /* Make sure that the driver does not have any obsolete PMKID entries.
  2443. */
  2444. wpa_driver_ndis_flush_pmkid(drv);
  2445. /*
  2446. * Disconnect to make sure that driver re-associates if it was
  2447. * connected.
  2448. */
  2449. wpa_driver_ndis_disconnect(drv);
  2450. eloop_register_timeout(1, 0, wpa_driver_ndis_poll_timeout, drv, NULL);
  2451. #ifdef CONFIG_NDIS_EVENTS_INTEGRATED
  2452. drv->events = ndis_events_init(&drv->events_pipe, &drv->event_avail,
  2453. drv->ifname, drv->adapter_desc);
  2454. if (drv->events == NULL) {
  2455. wpa_driver_ndis_deinit(drv);
  2456. return NULL;
  2457. }
  2458. eloop_register_event(drv->event_avail, sizeof(drv->event_avail),
  2459. wpa_driver_ndis_event_pipe_cb, drv, NULL);
  2460. #endif /* CONFIG_NDIS_EVENTS_INTEGRATED */
  2461. #ifdef _WIN32_WCE
  2462. if (ndisuio_notification_init(drv) < 0) {
  2463. wpa_driver_ndis_deinit(drv);
  2464. return NULL;
  2465. }
  2466. #endif /* _WIN32_WCE */
  2467. /* Set mode here in case card was configured for ad-hoc mode
  2468. * previously. */
  2469. mode = Ndis802_11Infrastructure;
  2470. if (ndis_set_oid(drv, OID_802_11_INFRASTRUCTURE_MODE,
  2471. (char *) &mode, sizeof(mode)) < 0) {
  2472. char buf[8];
  2473. int res;
  2474. wpa_printf(MSG_DEBUG, "NDIS: Failed to set "
  2475. "OID_802_11_INFRASTRUCTURE_MODE (%d)",
  2476. (int) mode);
  2477. /* Try to continue anyway */
  2478. res = ndis_get_oid(drv, OID_DOT11_CURRENT_OPERATION_MODE, buf,
  2479. sizeof(buf));
  2480. if (res > 0) {
  2481. wpa_printf(MSG_INFO, "NDIS: The driver seems to use "
  2482. "Native 802.11 OIDs. These are not yet "
  2483. "fully supported.");
  2484. drv->native80211 = 1;
  2485. } else if (!drv->has_capability || drv->capa.enc == 0) {
  2486. /*
  2487. * Note: This will also happen with NDIS 6 drivers with
  2488. * Vista.
  2489. */
  2490. wpa_printf(MSG_DEBUG, "NDIS: Driver did not provide "
  2491. "any wireless capabilities - assume it is "
  2492. "a wired interface");
  2493. drv->wired = 1;
  2494. drv->capa.flags |= WPA_DRIVER_FLAGS_WIRED;
  2495. drv->has_capability = 1;
  2496. ndis_add_multicast(drv);
  2497. }
  2498. }
  2499. return drv;
  2500. }
  2501. static void wpa_driver_ndis_deinit(void *priv)
  2502. {
  2503. struct wpa_driver_ndis_data *drv = priv;
  2504. #ifdef CONFIG_NDIS_EVENTS_INTEGRATED
  2505. if (drv->events) {
  2506. eloop_unregister_event(drv->event_avail,
  2507. sizeof(drv->event_avail));
  2508. ndis_events_deinit(drv->events);
  2509. }
  2510. #endif /* CONFIG_NDIS_EVENTS_INTEGRATED */
  2511. #ifdef _WIN32_WCE
  2512. ndisuio_notification_deinit(drv);
  2513. #endif /* _WIN32_WCE */
  2514. eloop_cancel_timeout(wpa_driver_ndis_scan_timeout, drv, drv->ctx);
  2515. eloop_cancel_timeout(wpa_driver_ndis_poll_timeout, drv, NULL);
  2516. wpa_driver_ndis_flush_pmkid(drv);
  2517. wpa_driver_ndis_disconnect(drv);
  2518. if (wpa_driver_ndis_radio_off(drv) < 0) {
  2519. wpa_printf(MSG_DEBUG, "NDIS: failed to disassociate and turn "
  2520. "radio off");
  2521. }
  2522. wpa_driver_ndis_adapter_close(drv);
  2523. if (drv->wzc_disabled)
  2524. wpa_driver_ndis_set_wzc(drv, 1);
  2525. #ifdef _WIN32_WCE
  2526. os_free(drv->adapter_name);
  2527. #endif /* _WIN32_WCE */
  2528. os_free(drv->adapter_desc);
  2529. os_free(drv);
  2530. }
  2531. static struct wpa_interface_info *
  2532. wpa_driver_ndis_get_interfaces(void *global_priv)
  2533. {
  2534. struct wpa_interface_info *iface = NULL, *niface;
  2535. #ifdef CONFIG_USE_NDISUIO
  2536. NDISUIO_QUERY_BINDING *b;
  2537. size_t blen = sizeof(*b) + 1024;
  2538. int i, error;
  2539. DWORD written;
  2540. char name[256], desc[256];
  2541. WCHAR *pos;
  2542. size_t j, len;
  2543. HANDLE ndisuio;
  2544. ndisuio = CreateFile(NDISUIO_DEVICE_NAME,
  2545. GENERIC_READ | GENERIC_WRITE, 0, NULL,
  2546. OPEN_EXISTING,
  2547. FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED,
  2548. INVALID_HANDLE_VALUE);
  2549. if (ndisuio == INVALID_HANDLE_VALUE) {
  2550. wpa_printf(MSG_ERROR, "NDIS: Failed to open connection to "
  2551. "NDISUIO: %d", (int) GetLastError());
  2552. return NULL;
  2553. }
  2554. #ifndef _WIN32_WCE
  2555. if (!DeviceIoControl(ndisuio, IOCTL_NDISUIO_BIND_WAIT, NULL, 0,
  2556. NULL, 0, &written, NULL)) {
  2557. wpa_printf(MSG_ERROR, "NDIS: IOCTL_NDISUIO_BIND_WAIT failed: "
  2558. "%d", (int) GetLastError());
  2559. CloseHandle(ndisuio);
  2560. return NULL;
  2561. }
  2562. #endif /* _WIN32_WCE */
  2563. b = os_malloc(blen);
  2564. if (b == NULL) {
  2565. CloseHandle(ndisuio);
  2566. return NULL;
  2567. }
  2568. for (i = 0; ; i++) {
  2569. os_memset(b, 0, blen);
  2570. b->BindingIndex = i;
  2571. if (!DeviceIoControl(ndisuio, IOCTL_NDISUIO_QUERY_BINDING,
  2572. b, sizeof(NDISUIO_QUERY_BINDING), b, blen,
  2573. &written, NULL)) {
  2574. error = (int) GetLastError();
  2575. if (error == ERROR_NO_MORE_ITEMS)
  2576. break;
  2577. wpa_printf(MSG_DEBUG, "IOCTL_NDISUIO_QUERY_BINDING "
  2578. "failed: %d", error);
  2579. break;
  2580. }
  2581. pos = (WCHAR *) ((char *) b + b->DeviceNameOffset);
  2582. len = b->DeviceNameLength;
  2583. if (len >= sizeof(name))
  2584. len = sizeof(name) - 1;
  2585. for (j = 0; j < len; j++)
  2586. name[j] = (char) pos[j];
  2587. name[len] = '\0';
  2588. pos = (WCHAR *) ((char *) b + b->DeviceDescrOffset);
  2589. len = b->DeviceDescrLength;
  2590. if (len >= sizeof(desc))
  2591. len = sizeof(desc) - 1;
  2592. for (j = 0; j < len; j++)
  2593. desc[j] = (char) pos[j];
  2594. desc[len] = '\0';
  2595. wpa_printf(MSG_DEBUG, "NDIS: %d - %s - %s", i, name, desc);
  2596. niface = os_zalloc(sizeof(*niface));
  2597. if (niface == NULL)
  2598. break;
  2599. niface->drv_name = "ndis";
  2600. if (os_strncmp(name, "\\DEVICE\\", 8) == 0)
  2601. niface->ifname = os_strdup(name + 8);
  2602. else
  2603. niface->ifname = os_strdup(name);
  2604. if (niface->ifname == NULL) {
  2605. os_free(niface);
  2606. break;
  2607. }
  2608. niface->desc = os_strdup(desc);
  2609. niface->next = iface;
  2610. iface = niface;
  2611. }
  2612. os_free(b);
  2613. CloseHandle(ndisuio);
  2614. #else /* CONFIG_USE_NDISUIO */
  2615. PTSTR _names;
  2616. char *names, *pos, *pos2;
  2617. ULONG len;
  2618. BOOLEAN res;
  2619. char *name[MAX_ADAPTERS];
  2620. char *desc[MAX_ADAPTERS];
  2621. int num_name, num_desc, i;
  2622. wpa_printf(MSG_DEBUG, "NDIS: Packet.dll version: %s",
  2623. PacketGetVersion());
  2624. len = 8192;
  2625. _names = os_zalloc(len);
  2626. if (_names == NULL)
  2627. return NULL;
  2628. res = PacketGetAdapterNames(_names, &len);
  2629. if (!res && len > 8192) {
  2630. os_free(_names);
  2631. _names = os_zalloc(len);
  2632. if (_names == NULL)
  2633. return NULL;
  2634. res = PacketGetAdapterNames(_names, &len);
  2635. }
  2636. if (!res) {
  2637. wpa_printf(MSG_ERROR, "NDIS: Failed to get adapter list "
  2638. "(PacketGetAdapterNames)");
  2639. os_free(_names);
  2640. return NULL;
  2641. }
  2642. names = (char *) _names;
  2643. if (names[0] && names[1] == '\0' && names[2] && names[3] == '\0') {
  2644. wpa_printf(MSG_DEBUG, "NDIS: Looks like adapter names are in "
  2645. "UNICODE");
  2646. /* Convert to ASCII */
  2647. pos2 = pos = names;
  2648. while (pos2 < names + len) {
  2649. if (pos2[0] == '\0' && pos2[1] == '\0' &&
  2650. pos2[2] == '\0' && pos2[3] == '\0') {
  2651. pos2 += 4;
  2652. break;
  2653. }
  2654. *pos++ = pos2[0];
  2655. pos2 += 2;
  2656. }
  2657. os_memcpy(pos + 2, names, pos - names);
  2658. pos += 2;
  2659. } else
  2660. pos = names;
  2661. num_name = 0;
  2662. while (pos < names + len) {
  2663. name[num_name] = pos;
  2664. while (*pos && pos < names + len)
  2665. pos++;
  2666. if (pos + 1 >= names + len) {
  2667. os_free(names);
  2668. return NULL;
  2669. }
  2670. pos++;
  2671. num_name++;
  2672. if (num_name >= MAX_ADAPTERS) {
  2673. wpa_printf(MSG_DEBUG, "NDIS: Too many adapters");
  2674. os_free(names);
  2675. return NULL;
  2676. }
  2677. if (*pos == '\0') {
  2678. wpa_printf(MSG_DEBUG, "NDIS: %d adapter names found",
  2679. num_name);
  2680. pos++;
  2681. break;
  2682. }
  2683. }
  2684. num_desc = 0;
  2685. while (pos < names + len) {
  2686. desc[num_desc] = pos;
  2687. while (*pos && pos < names + len)
  2688. pos++;
  2689. if (pos + 1 >= names + len) {
  2690. os_free(names);
  2691. return NULL;
  2692. }
  2693. pos++;
  2694. num_desc++;
  2695. if (num_desc >= MAX_ADAPTERS) {
  2696. wpa_printf(MSG_DEBUG, "NDIS: Too many adapter "
  2697. "descriptions");
  2698. os_free(names);
  2699. return NULL;
  2700. }
  2701. if (*pos == '\0') {
  2702. wpa_printf(MSG_DEBUG, "NDIS: %d adapter descriptions "
  2703. "found", num_name);
  2704. pos++;
  2705. break;
  2706. }
  2707. }
  2708. /*
  2709. * Windows 98 with Packet.dll 3.0 alpha3 does not include adapter
  2710. * descriptions. Fill in dummy descriptors to work around this.
  2711. */
  2712. while (num_desc < num_name)
  2713. desc[num_desc++] = "dummy description";
  2714. if (num_name != num_desc) {
  2715. wpa_printf(MSG_DEBUG, "NDIS: mismatch in adapter name and "
  2716. "description counts (%d != %d)",
  2717. num_name, num_desc);
  2718. os_free(names);
  2719. return NULL;
  2720. }
  2721. for (i = 0; i < num_name; i++) {
  2722. niface = os_zalloc(sizeof(*niface));
  2723. if (niface == NULL)
  2724. break;
  2725. niface->drv_name = "ndis";
  2726. if (os_strncmp(name[i], "\\Device\\NPF_", 12) == 0)
  2727. niface->ifname = os_strdup(name[i] + 12);
  2728. else
  2729. niface->ifname = os_strdup(name[i]);
  2730. if (niface->ifname == NULL) {
  2731. os_free(niface);
  2732. break;
  2733. }
  2734. niface->desc = os_strdup(desc[i]);
  2735. niface->next = iface;
  2736. iface = niface;
  2737. }
  2738. #endif /* CONFIG_USE_NDISUIO */
  2739. return iface;
  2740. }
  2741. static const char *ndis_drv_name = "ndis";
  2742. static const char *ndis_drv_desc = "Windows NDIS driver";
  2743. struct wpa_driver_ops wpa_driver_ndis_ops;
  2744. void driver_ndis_init_ops(void)
  2745. {
  2746. os_memset(&wpa_driver_ndis_ops, 0, sizeof(wpa_driver_ndis_ops));
  2747. wpa_driver_ndis_ops.name = ndis_drv_name;
  2748. wpa_driver_ndis_ops.desc = ndis_drv_desc;
  2749. wpa_driver_ndis_ops.get_bssid = wpa_driver_ndis_get_bssid;
  2750. wpa_driver_ndis_ops.get_ssid = wpa_driver_ndis_get_ssid;
  2751. wpa_driver_ndis_ops.set_key = wpa_driver_ndis_set_key;
  2752. wpa_driver_ndis_ops.init = wpa_driver_ndis_init;
  2753. wpa_driver_ndis_ops.deinit = wpa_driver_ndis_deinit;
  2754. wpa_driver_ndis_ops.deauthenticate = wpa_driver_ndis_deauthenticate;
  2755. wpa_driver_ndis_ops.associate = wpa_driver_ndis_associate;
  2756. wpa_driver_ndis_ops.add_pmkid = wpa_driver_ndis_add_pmkid;
  2757. wpa_driver_ndis_ops.remove_pmkid = wpa_driver_ndis_remove_pmkid;
  2758. wpa_driver_ndis_ops.flush_pmkid = wpa_driver_ndis_flush_pmkid;
  2759. wpa_driver_ndis_ops.get_capa = wpa_driver_ndis_get_capa;
  2760. wpa_driver_ndis_ops.poll = wpa_driver_ndis_poll;
  2761. wpa_driver_ndis_ops.get_ifname = wpa_driver_ndis_get_ifname;
  2762. wpa_driver_ndis_ops.get_mac_addr = wpa_driver_ndis_get_mac_addr;
  2763. wpa_driver_ndis_ops.get_scan_results2 =
  2764. wpa_driver_ndis_get_scan_results;
  2765. wpa_driver_ndis_ops.get_interfaces = wpa_driver_ndis_get_interfaces;
  2766. wpa_driver_ndis_ops.scan2 = wpa_driver_ndis_scan;
  2767. }