gl_wext.c 127 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181
  1. /*
  2. ** Id: //Department/DaVinci/BRANCHES/MT6620_WIFI_DRIVER_V2_3/os/linux/gl_wext.c#3
  3. */
  4. /*! \file gl_wext.c
  5. \brief ioctl() (mostly Linux Wireless Extensions) routines for STA driver.
  6. */
  7. /*
  8. ** Log: gl_wext.c
  9. *
  10. * 06 13 2012 yuche.tsai
  11. * NULL
  12. * Update maintrunk driver.
  13. * Add support for driver compose assoc request frame.
  14. *
  15. * 01 16 2012 wh.su
  16. * [WCXRP00001170] [MT6620 Wi-Fi][Driver] Adding the related code for set/get band ioctl
  17. * Adding the template code for set / get band IOCTL (with ICS supplicant_6)..
  18. *
  19. * 01 05 2012 wh.su
  20. * [WCXRP00001153] [MT6620 Wi-Fi][Driver] Adding the get_ch_list and set_tx_power proto type function
  21. * Adding the related ioctl / wlan oid function to set the Tx power cfg.
  22. *
  23. * 01 02 2012 wh.su
  24. * [WCXRP00001153] [MT6620 Wi-Fi][Driver] Adding the get_ch_list and set_tx_power proto type function
  25. * Adding the proto type function for set_int set_tx_power and get int get_ch_list.
  26. *
  27. * 11 10 2011 cp.wu
  28. * [WCXRP00001098] [MT6620 Wi-Fi][Driver] Replace printk by DBG LOG macros in linux porting layer
  29. * 1. eliminaite direct calls to printk in porting layer.
  30. * 2. replaced by DBGLOG, which would be XLOG on ALPS platforms.
  31. *
  32. * 10 12 2011 wh.su
  33. * [WCXRP00001036] [MT6620 Wi-Fi][Driver][FW] Adding the 802.11w code for MFP
  34. * adding the 802.11w related function and define .
  35. *
  36. * 09 23 2011 tsaiyuan.hsu
  37. * [WCXRP00000979] [MT6620 Wi-Fi][DRV]] stop attempting to connect to config AP after D3 state
  38. * avoid entering D3 state after deep sleep.
  39. *
  40. * 07 28 2011 chinghwa.yu
  41. * [WCXRP00000063] Update BCM CoEx design and settings
  42. * Add BWCS cmd and event.
  43. *
  44. * 07 27 2011 wh.su
  45. * [WCXRP00000877] [MT6620 Wi-Fi][Driver] Remove the netif_carry_ok check for avoid the wpa_supplicant fail to query
  46. * the ap address
  47. * Remove the netif check while query bssid and ssid
  48. *
  49. * 07 26 2011 chinglan.wang
  50. * NULL
  51. * [MT6620][WiFi Driver] Do not include the WSC IE in the association info packet when not do the wps connection..
  52. *
  53. * 07 18 2011 chinghwa.yu
  54. * [WCXRP00000063] Update BCM CoEx design and settings[WCXRP00000612] [MT6620 Wi-Fi] [FW] CSD update SWRDD algorithm
  55. * Add CMD/Event for RDD and BWCS.
  56. *
  57. * 05 17 2011 eddie.chen
  58. * [WCXRP00000603] [MT6620 Wi-Fi][DRV] Fix Klocwork warning
  59. * Initialize the vairlabes.
  60. *
  61. * 05 11 2011 jeffrey.chang
  62. * [WCXRP00000718] [MT6620 Wi-Fi] modify the behavior of setting tx power
  63. * modify set_tx_pow ioctl
  64. *
  65. * 03 29 2011 terry.wu
  66. * [WCXRP00000610] [MT 6620 Wi-Fi][Driver] Fix klocwork waring
  67. * [MT6620 Wi-Fi][Driver] Fix klocwork warning. Add Null pointer check on wext_get_essid. Limit the upper bound of
  68. * essid storage array.
  69. *
  70. * 03 21 2011 cp.wu
  71. * [WCXRP00000540] [MT5931][Driver] Add eHPI8/eHPI16 support to Linux Glue Layer
  72. * improve portability for awareness of early version of linux kernel and wireless extension.
  73. *
  74. * 03 17 2011 chinglan.wang
  75. * [WCXRP00000570] [MT6620 Wi-Fi][Driver] Add Wi-Fi Protected Setup v2.0 feature
  76. * .
  77. *
  78. * 03 07 2011 terry.wu
  79. * [WCXRP00000521] [MT6620 Wi-Fi][Driver] Remove non-standard debug message
  80. * Toggle non-standard debug messages to comments.
  81. *
  82. * 02 21 2011 wh.su
  83. * [WCXRP00000483] [MT6620 Wi-Fi][Driver] Check the kalIoctl return value before doing the memory copy at linux get
  84. * essid
  85. * fixed the potential error to do a larget memory copy while wlanoid get essid not actually running.
  86. *
  87. * 02 08 2011 george.huang
  88. * [WCXRP00000422] [MT6620 Wi-Fi][Driver] support query power mode OID handler
  89. * Support querying power mode OID.
  90. *
  91. * 01 29 2011 wh.su
  92. * [WCXRP00000408] [MT6620 Wi-Fi][Driver] Not doing memory alloc while ioctl set ie with length 0
  93. * not doing mem alloc. while set ie length already 0
  94. *
  95. * 01 20 2011 eddie.chen
  96. * [WCXRP00000374] [MT6620 Wi-Fi][DRV] SW debug control
  97. * Remove debug text.
  98. *
  99. * 01 20 2011 eddie.chen
  100. * [WCXRP00000374] [MT6620 Wi-Fi][DRV] SW debug control
  101. * Adjust OID order.
  102. *
  103. * 01 20 2011 eddie.chen
  104. * [WCXRP00000374] [MT6620 Wi-Fi][DRV] SW debug control
  105. * Add Oid for sw control debug command
  106. *
  107. * 01 11 2011 chinglan.wang
  108. * NULL
  109. * Modify to reslove the CR :[ALPS00028994] Use WEP security to connect Marvell 11N AP. Connection establish
  110. * successfully.
  111. * Use the WPS function to connect AP, the privacy bit always is set to 1. .
  112. *
  113. * 01 07 2011 cm.chang
  114. * [WCXRP00000336] [MT6620 Wi-Fi][Driver] Add test mode commands in normal phone operation
  115. * Add a new compiling option to control if MCR read/write is permitted
  116. *
  117. * 01 04 2011 cp.wu
  118. * [WCXRP00000338] [MT6620 Wi-Fi][Driver] Separate kalMemAlloc into kmalloc and vmalloc implementations to ease
  119. * physically continuous memory demands
  120. * separate kalMemAlloc() into virtually-continuous and physically-continuous types
  121. * to ease slab system pressure
  122. *
  123. * 01 04 2011 cp.wu
  124. * [WCXRP00000338] [MT6620 Wi-Fi][Driver] Separate kalMemAlloc into kmalloc and vmalloc implementations to ease
  125. * physically continuous memory demands
  126. * separate kalMemAlloc() into virtually-continuous and physically-continuous type to ease slab system pressure
  127. *
  128. * 12 31 2010 cm.chang
  129. * [WCXRP00000336] [MT6620 Wi-Fi][Driver] Add test mode commands in normal phone operation
  130. * Add some iwpriv commands to support test mode operation
  131. *
  132. * 12 15 2010 george.huang
  133. * [WCXRP00000152] [MT6620 Wi-Fi] AP mode power saving function
  134. * Support set PS profile and set WMM-PS related iwpriv.
  135. *
  136. * 12 15 2010 george.huang
  137. * [WCXRP00000152] [MT6620 Wi-Fi] AP mode power saving function
  138. * Allow change PS profile function (through wext_set_power()).
  139. *
  140. * 12 14 2010 jeffrey.chang
  141. * [WCXRP00000262] [MT6620 Wi-Fi][Driver] modify the scan request ioctl to handle hidden SSID
  142. * handle hidden SSID
  143. *
  144. * 12 13 2010 chinglan.wang
  145. * NULL
  146. * Add WPS 1.0 feature flag to enable the WPS 1.0 function.
  147. *
  148. * 12 07 2010 cm.chang
  149. * [WCXRP00000238] MT6620 Wi-Fi][Driver][FW] Support regulation domain setting from NVRAM and supplicant
  150. * Fix compiling error
  151. *
  152. * 12 07 2010 cm.chang
  153. * [WCXRP00000238] MT6620 Wi-Fi][Driver][FW] Support regulation domain setting from NVRAM and supplicant
  154. * 1. Country code is from NVRAM or supplicant
  155. * 2. Change band definition in CMD/EVENT.
  156. *
  157. * 11 30 2010 cp.wu
  158. * [WCXRP00000213] [MT6620 Wi-Fi][Driver] Implement scanning with specified SSID for wpa_supplicant with ap_scan=1
  159. * .
  160. *
  161. * 11 08 2010 wh.su
  162. * [WCXRP00000171] [MT6620 Wi-Fi][Driver] Add message check code same behavior as mt5921
  163. * add the message check code from mt5921.
  164. *
  165. * 10 19 2010 jeffrey.chang
  166. * [WCXRP00000121] [MT6620 Wi-Fi][Driver] Temporarily disable set power mode ioctl which may cause 6620 to enter power
  167. * saving
  168. * Temporarily disable set power mode ioctl which may cause MT6620 to enter power saving
  169. *
  170. * 10 18 2010 jeffrey.chang
  171. * [WCXRP00000116] [MT6620 Wi-Fi][Driver] Refine the set_scan ioctl to resolve the Android UI hanging issue
  172. * refine the scan ioctl to prevent hanging of Android UI
  173. *
  174. * 10 01 2010 wh.su
  175. * [WCXRP00000067] [MT6620 Wi-Fi][Driver] Support the android+ WAPI function
  176. * add the scan result with wapi ie.
  177. *
  178. * 09 30 2010 wh.su
  179. * [WCXRP00000072] [MT6620 Wi-Fi][Driver] Fix TKIP Counter Measure EAPoL callback register issue
  180. * fixed the wapi ie assigned issue.
  181. *
  182. * 09 27 2010 wh.su
  183. * NULL
  184. * [WCXRP00000067][MT6620 Wi-Fi][Driver] Support the android+ WAPI function.
  185. *
  186. * 09 21 2010 kevin.huang
  187. * [WCXRP00000052] [MT6620 Wi-Fi][Driver] Eliminate Linux Compile Warning
  188. * Eliminate Linux Compile Warning
  189. *
  190. * 09 09 2010 cp.wu
  191. * NULL
  192. * add WPS/WPA/RSN IE for Wi-Fi Direct scanning result.
  193. *
  194. * 09 06 2010 cp.wu
  195. * NULL
  196. * Androi/Linux: return current operating channel information
  197. *
  198. * 09 01 2010 wh.su
  199. * NULL
  200. * adding the wapi support for integration test.
  201. *
  202. * 08 02 2010 jeffrey.chang
  203. * NULL
  204. * enable remove key ioctl
  205. *
  206. * 08 02 2010 jeffrey.chang
  207. * NULL
  208. * 1) modify tx service thread to avoid busy looping
  209. * 2) add spin lock declartion for linux build
  210. *
  211. * 07 28 2010 jeffrey.chang
  212. * NULL
  213. * 1) enable encyption ioctls
  214. * 2) temporarily disable remove keys ioctl to prevent TX1 busy
  215. *
  216. * 07 28 2010 jeffrey.chang
  217. * NULL
  218. * 1) remove unused spinlocks
  219. * 2) enable encyption ioctls
  220. * 3) fix scan ioctl which may cause supplicant to hang
  221. *
  222. * 07 19 2010 jeffrey.chang
  223. *
  224. * add kal api for scanning done
  225. *
  226. * 07 19 2010 jeffrey.chang
  227. *
  228. * for linux driver migration
  229. *
  230. * 07 19 2010 jeffrey.chang
  231. *
  232. * Linux port modification
  233. *
  234. * 07 08 2010 cp.wu
  235. *
  236. * [WPD00003833] [MT6620 and MT5931] Driver migration - move to new repository.
  237. *
  238. * 06 06 2010 kevin.huang
  239. * [WPD00003832][MT6620 5931] Create driver base
  240. * [MT6620 5931] Create driver base
  241. *
  242. * 05 28 2010 jeffrey.chang
  243. * [WPD00003826]Initial import for Linux port
  244. * remove unused macro and debug messages
  245. *
  246. * 05 14 2010 jeffrey.chang
  247. * [WPD00003826]Initial import for Linux port
  248. * Add dissassoication support for wpa supplicant
  249. *
  250. * 04 22 2010 jeffrey.chang
  251. * [WPD00003826]Initial import for Linux port
  252. *
  253. * 1) modify rx path code for supporting Wi-Fi direct
  254. * 2) modify config.h since Linux dont need to consider retaining packet
  255. *
  256. * 04 21 2010 jeffrey.chang
  257. * [WPD00003826]Initial import for Linux port
  258. * add for private ioctl support
  259. *
  260. * 04 19 2010 jeffrey.chang
  261. * [WPD00003826]Initial import for Linux port
  262. * Add ioctl of power management
  263. *
  264. * 04 19 2010 jeffrey.chang
  265. * [WPD00003826]Initial import for Linux port
  266. * remove debug message
  267. *
  268. * 04 14 2010 jeffrey.chang
  269. * [WPD00003826]Initial import for Linux port
  270. * 1) prGlueInfo->pvInformationBuffer and prGlueInfo->u4InformationBufferLength are no longer used
  271. * * 2) fix ioctl
  272. *
  273. * 04 12 2010 jeffrey.chang
  274. * [WPD00003826]Initial import for Linux port
  275. * remove debug messages for pre-release
  276. *
  277. * 04 07 2010 cp.wu
  278. * [WPD00001943]Create WiFi test driver framework on WinXP
  279. * rWlanInfo should be placed at adapter rather than glue due to most operations
  280. * * * * * * * * are done in adapter layer.
  281. *
  282. * 04 02 2010 jeffrey.chang
  283. * [WPD00003826]Initial import for Linux port
  284. * fix ioctl type
  285. *
  286. * 04 01 2010 jeffrey.chang
  287. * [WPD00003826]Initial import for Linux port
  288. * enable pmksa cache operation
  289. *
  290. * 03 31 2010 jeffrey.chang
  291. * [WPD00003826]Initial import for Linux port
  292. * fix ioctl which may cause cmdinfo memory leak
  293. *
  294. * 03 31 2010 wh.su
  295. * [WPD00003816][MT6620 Wi-Fi] Adding the security support
  296. * modify the wapi related code for new driver's design.
  297. *
  298. * 03 30 2010 jeffrey.chang
  299. * [WPD00003826]Initial import for Linux port
  300. * emulate NDIS Pending OID facility
  301. *
  302. * 03 24 2010 jeffrey.chang
  303. * [WPD00003826]Initial import for Linux port
  304. * initial import for Linux port
  305. ** \main\maintrunk.MT5921\38 2009-10-08 10:33:22 GMT mtk01090
  306. ** Avoid accessing private data of net_device directly. Replace with netdev_priv().
  307. ** Add more checking for input parameters and pointers.
  308. ** \main\maintrunk.MT5921\37 2009-09-29 16:49:48 GMT mtk01090
  309. ** Remove unused variables
  310. ** \main\maintrunk.MT5921\36 2009-09-28 20:19:11 GMT mtk01090
  311. ** Add private ioctl to carry OID structures. Restructure public/private ioctl interfaces to Linux kernel.
  312. ** \main\maintrunk.MT5921\35 2009-09-03 11:42:30 GMT mtk01088
  313. ** adding the wapi ioctl support
  314. ** \main\maintrunk.MT5921\34 2009-08-18 22:56:50 GMT mtk01090
  315. ** Add Linux SDIO (with mmc core) support.
  316. ** Add Linux 2.6.21, 2.6.25, 2.6.26.
  317. ** Fix compile warning in Linux.
  318. ** \main\maintrunk.MT5921\33 2009-05-14 22:43:47 GMT mtk01089
  319. ** fix compiling warning
  320. ** \main\maintrunk.MT5921\32 2009-05-07 22:26:18 GMT mtk01089
  321. ** Add mandatory and private IO control for Linux BWCS
  322. ** \main\maintrunk.MT5921\31 2009-02-07 15:11:14 GMT mtk01088
  323. ** fixed the compiling error
  324. ** \main\maintrunk.MT5921\30 2009-02-07 14:46:51 GMT mtk01088
  325. ** add the privacy setting from linux supplicant ap selection
  326. ** \main\maintrunk.MT5921\29 2008-11-19 15:18:50 GMT mtk01088
  327. ** fixed the compling error
  328. ** \main\maintrunk.MT5921\28 2008-11-19 11:56:18 GMT mtk01088
  329. ** rename some variable with pre-fix to avoid the misunderstanding
  330. ** \main\maintrunk.MT5921\27 2008-08-29 16:59:43 GMT mtk01088
  331. ** fixed compiling error
  332. ** \main\maintrunk.MT5921\26 2008-08-29 14:55:53 GMT mtk01088
  333. ** adjust the code for meet the coding style, and add assert check
  334. ** \main\maintrunk.MT5921\25 2008-06-02 11:15:19 GMT mtk01461
  335. ** Update after wlanoidSetPowerMode changed
  336. ** \main\maintrunk.MT5921\24 2008-05-30 15:13:12 GMT mtk01084
  337. ** rename wlanoid
  338. ** \main\maintrunk.MT5921\23 2008-03-28 10:40:28 GMT mtk01461
  339. ** Add set desired rate in Linux STD IOCTL
  340. ** \main\maintrunk.MT5921\22 2008-03-18 10:31:24 GMT mtk01088
  341. ** add pmkid ioctl and indicate
  342. ** \main\maintrunk.MT5921\21 2008-03-11 15:21:24 GMT mtk01461
  343. ** \main\maintrunk.MT5921\20 2008-03-11 14:50:55 GMT mtk01461
  344. ** Refine WPS related priv ioctl for unified interface
  345. **
  346. ** \main\maintrunk.MT5921\19 2008-03-06 16:30:41 GMT mtk01088
  347. ** move the configuration code from set essid function,
  348. ** remove the non-used code
  349. ** \main\maintrunk.MT5921\18 2008-02-21 15:47:09 GMT mtk01461
  350. ** Fix CR[489]
  351. ** \main\maintrunk.MT5921\17 2008-02-12 23:38:31 GMT mtk01461
  352. ** Add Set Frequency & Channel oid support for Linux
  353. ** \main\maintrunk.MT5921\16 2008-01-24 12:07:34 GMT mtk01461
  354. ** \main\maintrunk.MT5921\15 2008-01-24 12:00:10 GMT mtk01461
  355. ** Modify the wext_essid for set up correct information for IBSS, and fix the wrong input ptr for prAdapter
  356. ** \main\maintrunk.MT5921\14 2007-12-06 09:30:12 GMT mtk01425
  357. ** 1. Branch Test
  358. ** \main\maintrunk.MT5921\13 2007-12-04 18:07:59 GMT mtk01461
  359. ** fix typo
  360. ** \main\maintrunk.MT5921\12 2007-11-30 17:10:21 GMT mtk01425
  361. ** 1. Fix compiling erros
  362. **
  363. ** \main\maintrunk.MT5921\11 2007-11-27 10:43:22 GMT mtk01425
  364. ** 1. Add WMM-PS setting
  365. ** \main\maintrunk.MT5921\10 2007-11-06 20:33:32 GMT mtk01088
  366. ** fixed the compiler error
  367. ** \main\maintrunk.MT5921\9 2007-11-06 19:33:15 GMT mtk01088
  368. ** add WPS code
  369. ** \main\maintrunk.MT5921\8 2007-10-30 12:00:44 GMT MTK01425
  370. ** 1. Update wlanQueryInformation
  371. */
  372. /*******************************************************************************
  373. * C O M P I L E R F L A G S
  374. ********************************************************************************
  375. */
  376. /*******************************************************************************
  377. * E X T E R N A L R E F E R E N C E S
  378. ********************************************************************************
  379. */
  380. #include "gl_os.h"
  381. #include "config.h"
  382. #include "wlan_oid.h"
  383. #include "gl_wext.h"
  384. #include "gl_wext_priv.h"
  385. #include "precomp.h"
  386. #if CFG_SUPPORT_WAPI
  387. #include "gl_sec.h"
  388. #endif
  389. /* compatibility to wireless extensions */
  390. #ifdef WIRELESS_EXT
  391. /*******************************************************************************
  392. * C O N S T A N T S
  393. ********************************************************************************
  394. */
  395. const long channel_freq[] = {
  396. 2412, 2417, 2422, 2427, 2432, 2437, 2442,
  397. 2447, 2452, 2457, 2462, 2467, 2472, 2484
  398. };
  399. #define NUM_CHANNELS (sizeof(channel_freq) / sizeof(channel_freq[0]))
  400. #define MAX_SSID_LEN 32
  401. #define COUNTRY_CODE_LEN 10 /* country code length */
  402. /*******************************************************************************
  403. * D A T A T Y P E S
  404. ********************************************************************************
  405. */
  406. /*******************************************************************************
  407. * P U B L I C D A T A
  408. ********************************************************************************
  409. */
  410. /* NOTE: name in iwpriv_args only have 16 bytes */
  411. static const struct iw_priv_args rIwPrivTable[] = {
  412. {IOCTL_SET_INT, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, ""},
  413. {IOCTL_GET_INT, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, ""},
  414. {IOCTL_SET_INT, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 3, 0, ""},
  415. {IOCTL_GET_INT, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 3, ""},
  416. {IOCTL_SET_INT, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, ""},
  417. {IOCTL_GET_INT, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, ""},
  418. {IOCTL_GET_INT, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, ""},
  419. {IOCTL_SET_INTS, IW_PRIV_TYPE_INT | 4, 0, ""},
  420. {IOCTL_GET_INT, 0, IW_PRIV_TYPE_INT | 50, ""},
  421. {IOCTL_GET_INT, 0, IW_PRIV_TYPE_CHAR | 16, ""},
  422. {IOCTL_SET_STRING, IW_PRIV_TYPE_CHAR | 256, 0, ""},
  423. /* added for set_oid and get_oid */
  424. {IOCTL_SET_STRUCT, 256, 0, ""},
  425. {IOCTL_GET_STRUCT, 0, 256, ""},
  426. /* sub-ioctl definitions */
  427. #if 0
  428. {PRIV_CMD_REG_DOMAIN, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "set_reg_domain"},
  429. {PRIV_CMD_REG_DOMAIN, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "get_reg_domain"},
  430. #endif
  431. #if CFG_TCP_IP_CHKSUM_OFFLOAD
  432. {PRIV_CMD_CSUM_OFFLOAD, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "set_tcp_csum"},
  433. #endif /* CFG_TCP_IP_CHKSUM_OFFLOAD */
  434. {PRIV_CMD_POWER_MODE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "set_power_mode"},
  435. {PRIV_CMD_POWER_MODE, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "get_power_mode"},
  436. {PRIV_CMD_WMM_PS, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 3, 0, "set_wmm_ps"},
  437. {PRIV_CMD_TEST_MODE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "set_test_mode"},
  438. {PRIV_CMD_TEST_CMD, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "set_test_cmd"},
  439. {PRIV_CMD_TEST_CMD, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  440. "get_test_result"},
  441. #if CFG_SUPPORT_PRIV_MCR_RW
  442. {PRIV_CMD_ACCESS_MCR, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "set_mcr"},
  443. {PRIV_CMD_ACCESS_MCR, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  444. "get_mcr"},
  445. #endif
  446. {PRIV_CMD_SW_CTRL, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "set_sw_ctrl"},
  447. {PRIV_CMD_SW_CTRL, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  448. "get_sw_ctrl"},
  449. #if CFG_SUPPORT_BCM && CFG_SUPPORT_BCM_BWCS
  450. {PRIV_CUSTOM_BWCS_CMD, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "set_bwcs"},
  451. /* GET STRUCT sub-ioctls commands */
  452. {PRIV_CUSTOM_BWCS_CMD, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  453. "get_bwcs"},
  454. #endif
  455. /* SET STRUCT sub-ioctls commands */
  456. {PRIV_CMD_OID, 256, 0, "set_oid"},
  457. /* GET STRUCT sub-ioctls commands */
  458. {PRIV_CMD_OID, 0, 256, "get_oid"},
  459. {PRIV_CMD_BAND_CONFIG, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "set_band"},
  460. {PRIV_CMD_BAND_CONFIG, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "get_band"},
  461. {PRIV_CMD_SET_TX_POWER, IW_PRIV_TYPE_INT | 4, 0, "set_txpower"},
  462. {PRIV_CMD_GET_CH_LIST, 0, IW_PRIV_TYPE_INT | 50, "get_ch_list"},
  463. {PRIV_CMD_DUMP_MEM, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  464. "get_mem"},
  465. #if CFG_ENABLE_WIFI_DIRECT
  466. {PRIV_CMD_P2P_MODE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "set_p2p_mode"},
  467. #endif
  468. {PRIV_CMD_GET_BUILD_DATE_CODE, 0, IW_PRIV_TYPE_CHAR | 16, "get_date_code"},
  469. {PRIV_CMD_GET_DEBUG_CODE, 0, IW_PRIV_TYPE_CHAR | 16, "get_dbg_code"},
  470. /* handle any command with many input parameters */
  471. {PRIV_CMD_OTHER, IW_PRIV_TYPE_CHAR | 256, 0, "set_str_cmd"},
  472. {PRIV_CMD_WFD_DEBUG_CODE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "set_wfd_dbg_code"},
  473. };
  474. static const iw_handler rIwPrivHandler[] = {
  475. [IOCTL_SET_INT - SIOCIWFIRSTPRIV] = priv_set_int,
  476. [IOCTL_GET_INT - SIOCIWFIRSTPRIV] = priv_get_int,
  477. [IOCTL_SET_ADDRESS - SIOCIWFIRSTPRIV] = NULL,
  478. [IOCTL_GET_ADDRESS - SIOCIWFIRSTPRIV] = NULL,
  479. [IOCTL_SET_STR - SIOCIWFIRSTPRIV] = NULL,
  480. [IOCTL_GET_STR - SIOCIWFIRSTPRIV] = NULL,
  481. [IOCTL_SET_KEY - SIOCIWFIRSTPRIV] = NULL,
  482. [IOCTL_GET_KEY - SIOCIWFIRSTPRIV] = NULL,
  483. [IOCTL_SET_STRUCT - SIOCIWFIRSTPRIV] = priv_set_struct,
  484. [IOCTL_GET_STRUCT - SIOCIWFIRSTPRIV] = priv_get_struct,
  485. [IOCTL_SET_STRUCT_FOR_EM - SIOCIWFIRSTPRIV] = priv_set_struct,
  486. [IOCTL_SET_INTS - SIOCIWFIRSTPRIV] = priv_set_ints,
  487. [IOCTL_GET_INTS - SIOCIWFIRSTPRIV] = priv_get_ints,
  488. [IOCTL_SET_STRING - SIOCIWFIRSTPRIV] = priv_set_string,
  489. };
  490. const struct iw_handler_def wext_handler_def = {
  491. .num_standard = 0,
  492. .num_private = (__u16) sizeof(rIwPrivHandler) / sizeof(iw_handler),
  493. .num_private_args = (__u16) sizeof(rIwPrivTable) / sizeof(struct iw_priv_args),
  494. .standard = (iw_handler *) NULL,
  495. .private = rIwPrivHandler,
  496. .private_args = rIwPrivTable,
  497. .get_wireless_stats = wext_get_wireless_stats,
  498. };
  499. /*******************************************************************************
  500. * P R I V A T E D A T A
  501. ********************************************************************************
  502. */
  503. /*******************************************************************************
  504. * M A C R O S
  505. ********************************************************************************
  506. */
  507. /*******************************************************************************
  508. * F U N C T I O N D E C L A R A T I O N S
  509. ********************************************************************************
  510. */
  511. /*******************************************************************************
  512. * F U N C T I O N S
  513. ********************************************************************************
  514. */
  515. /*----------------------------------------------------------------------------*/
  516. /*!
  517. * \brief Find the desired WPA/RSN Information Element according to desiredElemID.
  518. *
  519. * \param[in] pucIEStart IE starting address.
  520. * \param[in] i4TotalIeLen Total length of all the IE.
  521. * \param[in] ucDesiredElemId Desired element ID.
  522. * \param[out] ppucDesiredIE Pointer to the desired IE.
  523. *
  524. * \retval TRUE Find the desired IE.
  525. * \retval FALSE Desired IE not found.
  526. *
  527. * \note
  528. */
  529. /*----------------------------------------------------------------------------*/
  530. BOOLEAN
  531. wextSrchDesiredWPAIE(IN PUINT_8 pucIEStart,
  532. IN INT_32 i4TotalIeLen, IN UINT_8 ucDesiredElemId, OUT PUINT_8 *ppucDesiredIE)
  533. {
  534. INT_32 i4InfoElemLen;
  535. ASSERT(pucIEStart);
  536. ASSERT(ppucDesiredIE);
  537. while (i4TotalIeLen >= 2) {
  538. i4InfoElemLen = (INT_32) pucIEStart[1] + 2;
  539. if (pucIEStart[0] == ucDesiredElemId && i4InfoElemLen <= i4TotalIeLen) {
  540. if (ucDesiredElemId != 0xDD) {
  541. /* Non 0xDD, OK! */
  542. *ppucDesiredIE = &pucIEStart[0];
  543. return TRUE;
  544. }
  545. /* EID == 0xDD, check WPA IE */
  546. if (pucIEStart[1] >= 4) {
  547. if (memcmp(&pucIEStart[2], "\x00\x50\xf2\x01", 4) == 0) {
  548. *ppucDesiredIE = &pucIEStart[0];
  549. return TRUE;
  550. }
  551. } /* check WPA IE length */
  552. /* check EID == 0xDD */
  553. }
  554. /* check desired EID */
  555. /* Select next information element. */
  556. i4TotalIeLen -= i4InfoElemLen;
  557. pucIEStart += i4InfoElemLen;
  558. }
  559. return FALSE;
  560. } /* parseSearchDesiredWPAIE */
  561. #if CFG_SUPPORT_WAPI
  562. /*----------------------------------------------------------------------------*/
  563. /*!
  564. * \brief Find the desired WAPI Information Element .
  565. *
  566. * \param[in] pucIEStart IE starting address.
  567. * \param[in] i4TotalIeLen Total length of all the IE.
  568. * \param[out] ppucDesiredIE Pointer to the desired IE.
  569. *
  570. * \retval TRUE Find the desired IE.
  571. * \retval FALSE Desired IE not found.
  572. *
  573. * \note
  574. */
  575. /*----------------------------------------------------------------------------*/
  576. BOOLEAN wextSrchDesiredWAPIIE(IN PUINT_8 pucIEStart, IN INT_32 i4TotalIeLen, OUT PUINT_8 *ppucDesiredIE)
  577. {
  578. INT_32 i4InfoElemLen;
  579. ASSERT(pucIEStart);
  580. ASSERT(ppucDesiredIE);
  581. while (i4TotalIeLen >= 2) {
  582. i4InfoElemLen = (INT_32) pucIEStart[1] + 2;
  583. if (pucIEStart[0] == ELEM_ID_WAPI && i4InfoElemLen <= i4TotalIeLen) {
  584. *ppucDesiredIE = &pucIEStart[0];
  585. return TRUE;
  586. }
  587. /* check desired EID */
  588. /* Select next information element. */
  589. i4TotalIeLen -= i4InfoElemLen;
  590. pucIEStart += i4InfoElemLen;
  591. }
  592. return FALSE;
  593. } /* wextSrchDesiredWAPIIE */
  594. #endif
  595. #if CFG_SUPPORT_HOTSPOT_2_0
  596. /*----------------------------------------------------------------------------*/
  597. /*!
  598. * \brief Check if exist the desired HS2.0 Information Element according to desiredElemID.
  599. *
  600. * \param[in] pucIEStart IE starting address.
  601. * \param[in] i4TotalIeLen Total length of all the IE.
  602. * \param[in] ucDesiredElemId Desired element ID.
  603. * \param[out] ppucDesiredIE Pointer to the desired IE.
  604. *
  605. * \retval TRUE Find the desired IE.
  606. * \retval FALSE Desired IE not found.
  607. *
  608. * \note
  609. */
  610. /*----------------------------------------------------------------------------*/
  611. BOOLEAN wextIsDesiredHS20IE(IN PUINT_8 pucCurIE, IN INT_32 i4TotalIeLen)
  612. {
  613. INT_32 i4InfoElemLen;
  614. ASSERT(pucCurIE);
  615. i4InfoElemLen = (INT_32) pucCurIE[1] + 2;
  616. if (pucCurIE[0] == ELEM_ID_VENDOR && i4InfoElemLen <= i4TotalIeLen) {
  617. if (pucCurIE[1] >= ELEM_MIN_LEN_HS20_INDICATION) {
  618. if (memcmp(&pucCurIE[2], "\x50\x6f\x9a\x10", 4) == 0)
  619. return TRUE;
  620. }
  621. }
  622. /* check desired EID */
  623. return FALSE;
  624. } /* wextIsDesiredHS20IE */
  625. /*----------------------------------------------------------------------------*/
  626. /*!
  627. * \brief Check if exist the desired interworking Information Element according to desiredElemID.
  628. *
  629. * \param[in] pucIEStart IE starting address.
  630. * \param[in] i4TotalIeLen Total length of all the IE.
  631. * \param[in] ucDesiredElemId Desired element ID.
  632. * \param[out] ppucDesiredIE Pointer to the desired IE.
  633. *
  634. * \retval TRUE Find the desired IE.
  635. * \retval FALSE Desired IE not found.
  636. *
  637. * \note
  638. */
  639. /*----------------------------------------------------------------------------*/
  640. BOOLEAN wextIsDesiredInterworkingIE(IN PUINT_8 pucCurIE, IN INT_32 i4TotalIeLen)
  641. {
  642. INT_32 i4InfoElemLen;
  643. ASSERT(pucCurIE);
  644. i4InfoElemLen = (INT_32) pucCurIE[1] + 2;
  645. if (pucCurIE[0] == ELEM_ID_INTERWORKING && i4InfoElemLen <= i4TotalIeLen) {
  646. switch (pucCurIE[1]) {
  647. case IW_IE_LENGTH_ANO:
  648. case IW_IE_LENGTH_ANO_HESSID:
  649. case IW_IE_LENGTH_ANO_VENUE:
  650. case IW_IE_LENGTH_ANO_VENUE_HESSID:
  651. return TRUE;
  652. default:
  653. break;
  654. }
  655. }
  656. /* check desired EID */
  657. return FALSE;
  658. } /* wextIsDesiredInterworkingIE */
  659. /*----------------------------------------------------------------------------*/
  660. /*!
  661. * \brief Check if exist the desired Adv Protocol Information Element according to desiredElemID.
  662. *
  663. * \param[in] pucIEStart IE starting address.
  664. * \param[in] i4TotalIeLen Total length of all the IE.
  665. * \param[in] ucDesiredElemId Desired element ID.
  666. * \param[out] ppucDesiredIE Pointer to the desired IE.
  667. *
  668. * \retval TRUE Find the desired IE.
  669. * \retval FALSE Desired IE not found.
  670. *
  671. * \note
  672. */
  673. /*----------------------------------------------------------------------------*/
  674. BOOLEAN wextIsDesiredAdvProtocolIE(IN PUINT_8 pucCurIE, IN INT_32 i4TotalIeLen)
  675. {
  676. INT_32 i4InfoElemLen;
  677. ASSERT(pucCurIE);
  678. i4InfoElemLen = (INT_32) pucCurIE[1] + 2;
  679. if (pucCurIE[0] == ELEM_ID_ADVERTISEMENT_PROTOCOL && i4InfoElemLen <= i4TotalIeLen)
  680. return TRUE;
  681. /* check desired EID */
  682. return FALSE;
  683. } /* wextIsDesiredAdvProtocolIE */
  684. /*----------------------------------------------------------------------------*/
  685. /*!
  686. * \brief Check if exist the desired Roaming Consortium Information Element according to desiredElemID.
  687. *
  688. * \param[in] pucIEStart IE starting address.
  689. * \param[in] i4TotalIeLen Total length of all the IE.
  690. * \param[in] ucDesiredElemId Desired element ID.
  691. * \param[out] ppucDesiredIE Pointer to the desired IE.
  692. *
  693. * \retval TRUE Find the desired IE.
  694. * \retval FALSE Desired IE not found.
  695. *
  696. * \note
  697. */
  698. /*----------------------------------------------------------------------------*/
  699. BOOLEAN wextIsDesiredRoamingConsortiumIE(IN PUINT_8 pucCurIE, IN INT_32 i4TotalIeLen)
  700. {
  701. INT_32 i4InfoElemLen;
  702. ASSERT(pucCurIE);
  703. i4InfoElemLen = (INT_32) pucCurIE[1] + 2;
  704. if (pucCurIE[0] == ELEM_ID_ROAMING_CONSORTIUM && i4InfoElemLen <= i4TotalIeLen)
  705. return TRUE;
  706. /* check desired EID */
  707. return FALSE;
  708. } /* wextIsDesiredRoamingConsortiumIE */
  709. /*----------------------------------------------------------------------------*/
  710. /*!
  711. * \brief Find the desired HS2.0 Information Element according to desiredElemID.
  712. *
  713. * \param[in] pucIEStart IE starting address.
  714. * \param[in] i4TotalIeLen Total length of all the IE.
  715. * \param[in] ucDesiredElemId Desired element ID.
  716. * \param[out] ppucDesiredIE Pointer to the desired IE.
  717. *
  718. * \retval TRUE Find the desired IE.
  719. * \retval FALSE Desired IE not found.
  720. *
  721. * \note
  722. */
  723. /*----------------------------------------------------------------------------*/
  724. BOOLEAN wextSrchDesiredHS20IE(IN PUINT_8 pucIEStart, IN INT_32 i4TotalIeLen, OUT PUINT_8 *ppucDesiredIE)
  725. {
  726. INT_32 i4InfoElemLen;
  727. ASSERT(pucIEStart);
  728. ASSERT(ppucDesiredIE);
  729. while (i4TotalIeLen >= 2) {
  730. i4InfoElemLen = (INT_32) pucIEStart[1] + 2;
  731. if (pucIEStart[0] == ELEM_ID_VENDOR && i4InfoElemLen <= i4TotalIeLen) {
  732. if (pucIEStart[1] >= ELEM_MIN_LEN_HS20_INDICATION) {
  733. if (memcmp(&pucIEStart[2], "\x50\x6f\x9a\x10", 4) == 0) {
  734. *ppucDesiredIE = &pucIEStart[0];
  735. return TRUE;
  736. }
  737. }
  738. }
  739. /* check desired EID */
  740. /* Select next information element. */
  741. i4TotalIeLen -= i4InfoElemLen;
  742. pucIEStart += i4InfoElemLen;
  743. }
  744. return FALSE;
  745. } /* wextSrchDesiredHS20IE */
  746. /*----------------------------------------------------------------------------*/
  747. /*!
  748. * \brief Find the desired interworking Information Element according to desiredElemID.
  749. *
  750. * \param[in] pucIEStart IE starting address.
  751. * \param[in] i4TotalIeLen Total length of all the IE.
  752. * \param[in] ucDesiredElemId Desired element ID.
  753. * \param[out] ppucDesiredIE Pointer to the desired IE.
  754. *
  755. * \retval TRUE Find the desired IE.
  756. * \retval FALSE Desired IE not found.
  757. *
  758. * \note
  759. */
  760. /*----------------------------------------------------------------------------*/
  761. BOOLEAN wextSrchDesiredInterworkingIE(IN PUINT_8 pucIEStart, IN INT_32 i4TotalIeLen, OUT PUINT_8 *ppucDesiredIE)
  762. {
  763. INT_32 i4InfoElemLen;
  764. ASSERT(pucIEStart);
  765. ASSERT(ppucDesiredIE);
  766. while (i4TotalIeLen >= 2) {
  767. i4InfoElemLen = (INT_32) pucIEStart[1] + 2;
  768. if (pucIEStart[0] == ELEM_ID_INTERWORKING && i4InfoElemLen <= i4TotalIeLen) {
  769. *ppucDesiredIE = &pucIEStart[0];
  770. return TRUE;
  771. }
  772. /* check desired EID */
  773. /* Select next information element. */
  774. i4TotalIeLen -= i4InfoElemLen;
  775. pucIEStart += i4InfoElemLen;
  776. }
  777. return FALSE;
  778. } /* wextSrchDesiredInterworkingIE */
  779. /*----------------------------------------------------------------------------*/
  780. /*!
  781. * \brief Find the desired Adv Protocol Information Element according to desiredElemID.
  782. *
  783. * \param[in] pucIEStart IE starting address.
  784. * \param[in] i4TotalIeLen Total length of all the IE.
  785. * \param[in] ucDesiredElemId Desired element ID.
  786. * \param[out] ppucDesiredIE Pointer to the desired IE.
  787. *
  788. * \retval TRUE Find the desired IE.
  789. * \retval FALSE Desired IE not found.
  790. *
  791. * \note
  792. */
  793. /*----------------------------------------------------------------------------*/
  794. BOOLEAN wextSrchDesiredAdvProtocolIE(IN PUINT_8 pucIEStart, IN INT_32 i4TotalIeLen, OUT PUINT_8 *ppucDesiredIE)
  795. {
  796. INT_32 i4InfoElemLen;
  797. ASSERT(pucIEStart);
  798. ASSERT(ppucDesiredIE);
  799. while (i4TotalIeLen >= 2) {
  800. i4InfoElemLen = (INT_32) pucIEStart[1] + 2;
  801. if (pucIEStart[0] == ELEM_ID_ADVERTISEMENT_PROTOCOL && i4InfoElemLen <= i4TotalIeLen) {
  802. *ppucDesiredIE = &pucIEStart[0];
  803. return TRUE;
  804. }
  805. /* check desired EID */
  806. /* Select next information element. */
  807. i4TotalIeLen -= i4InfoElemLen;
  808. pucIEStart += i4InfoElemLen;
  809. }
  810. return FALSE;
  811. } /* wextSrchDesiredAdvProtocolIE */
  812. /*----------------------------------------------------------------------------*/
  813. /*!
  814. * \brief Find the desired Roaming Consortium Information Element according to desiredElemID.
  815. *
  816. * \param[in] pucIEStart IE starting address.
  817. * \param[in] i4TotalIeLen Total length of all the IE.
  818. * \param[in] ucDesiredElemId Desired element ID.
  819. * \param[out] ppucDesiredIE Pointer to the desired IE.
  820. *
  821. * \retval TRUE Find the desired IE.
  822. * \retval FALSE Desired IE not found.
  823. *
  824. * \note
  825. */
  826. /*----------------------------------------------------------------------------*/
  827. BOOLEAN wextSrchDesiredRoamingConsortiumIE(IN PUINT_8 pucIEStart, IN INT_32 i4TotalIeLen, OUT PUINT_8 *ppucDesiredIE)
  828. {
  829. INT_32 i4InfoElemLen;
  830. ASSERT(pucIEStart);
  831. ASSERT(ppucDesiredIE);
  832. while (i4TotalIeLen >= 2) {
  833. i4InfoElemLen = (INT_32) pucIEStart[1] + 2;
  834. if (pucIEStart[0] == ELEM_ID_ROAMING_CONSORTIUM && i4InfoElemLen <= i4TotalIeLen) {
  835. *ppucDesiredIE = &pucIEStart[0];
  836. return TRUE;
  837. }
  838. /* check desired EID */
  839. /* Select next information element. */
  840. i4TotalIeLen -= i4InfoElemLen;
  841. pucIEStart += i4InfoElemLen;
  842. }
  843. return FALSE;
  844. } /* wextSrchDesiredRoamingConsortiumIE */
  845. #endif
  846. #if CFG_SUPPORT_WPS
  847. /*----------------------------------------------------------------------------*/
  848. /*!
  849. * \brief Find the desired WPS Information Element according to desiredElemID.
  850. *
  851. * \param[in] pucIEStart IE starting address.
  852. * \param[in] i4TotalIeLen Total length of all the IE.
  853. * \param[in] ucDesiredElemId Desired element ID.
  854. * \param[out] ppucDesiredIE Pointer to the desired IE.
  855. *
  856. * \retval TRUE Find the desired IE.
  857. * \retval FALSE Desired IE not found.
  858. *
  859. * \note
  860. */
  861. /*----------------------------------------------------------------------------*/
  862. BOOLEAN
  863. wextSrchDesiredWPSIE(IN PUINT_8 pucIEStart,
  864. IN INT_32 i4TotalIeLen, IN UINT_8 ucDesiredElemId, OUT PUINT_8 *ppucDesiredIE)
  865. {
  866. INT_32 i4InfoElemLen;
  867. ASSERT(pucIEStart);
  868. ASSERT(ppucDesiredIE);
  869. while (i4TotalIeLen >= 2) {
  870. i4InfoElemLen = (INT_32) pucIEStart[1] + 2;
  871. if (pucIEStart[0] == ucDesiredElemId && i4InfoElemLen <= i4TotalIeLen) {
  872. if (ucDesiredElemId != 0xDD) {
  873. /* Non 0xDD, OK! */
  874. *ppucDesiredIE = &pucIEStart[0];
  875. return TRUE;
  876. }
  877. /* EID == 0xDD, check WPS IE */
  878. if (pucIEStart[1] >= 4) {
  879. if (memcmp(&pucIEStart[2], "\x00\x50\xf2\x04", 4) == 0) {
  880. *ppucDesiredIE = &pucIEStart[0];
  881. return TRUE;
  882. }
  883. } /* check WPS IE length */
  884. /* check EID == 0xDD */
  885. }
  886. /* check desired EID */
  887. /* Select next information element. */
  888. i4TotalIeLen -= i4InfoElemLen;
  889. pucIEStart += i4InfoElemLen;
  890. }
  891. return FALSE;
  892. } /* parseSearchDesiredWPSIE */
  893. #endif
  894. /*----------------------------------------------------------------------------*/
  895. /*!
  896. * \brief Get the name of the protocol used on the air.
  897. *
  898. * \param[in] prDev Net device requested.
  899. * \param[in] prIwrInfo NULL.
  900. * \param[out] pcName Buffer to store protocol name string
  901. * \param[in] pcExtra NULL.
  902. *
  903. * \retval 0 For success.
  904. *
  905. * \note If netif_carrier_ok, protocol name is returned;
  906. * otherwise, "disconnected" is returned.
  907. */
  908. /*----------------------------------------------------------------------------*/
  909. static int
  910. wext_get_name(IN struct net_device *prNetDev, IN struct iw_request_info *prIwrInfo, OUT char *pcName, IN char *pcExtra)
  911. {
  912. ENUM_PARAM_NETWORK_TYPE_T eNetWorkType = PARAM_NETWORK_TYPE_NUM;
  913. P_GLUE_INFO_T prGlueInfo = NULL;
  914. WLAN_STATUS rStatus = WLAN_STATUS_SUCCESS;
  915. UINT_32 u4BufLen = 0;
  916. ASSERT(prNetDev);
  917. ASSERT(pcName);
  918. if (FALSE == GLUE_CHK_PR2(prNetDev, pcName))
  919. return -EINVAL;
  920. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prNetDev));
  921. if (netif_carrier_ok(prNetDev)) {
  922. rStatus = kalIoctl(prGlueInfo,
  923. wlanoidQueryNetworkTypeInUse,
  924. &eNetWorkType, sizeof(eNetWorkType), TRUE, FALSE, FALSE, FALSE, &u4BufLen);
  925. switch (eNetWorkType) {
  926. case PARAM_NETWORK_TYPE_DS:
  927. strcpy(pcName, "IEEE 802.11b");
  928. break;
  929. case PARAM_NETWORK_TYPE_OFDM24:
  930. strcpy(pcName, "IEEE 802.11bgn");
  931. break;
  932. case PARAM_NETWORK_TYPE_AUTOMODE:
  933. case PARAM_NETWORK_TYPE_OFDM5:
  934. strcpy(pcName, "IEEE 802.11abgn");
  935. break;
  936. case PARAM_NETWORK_TYPE_FH:
  937. default:
  938. strcpy(pcName, "IEEE 802.11");
  939. break;
  940. }
  941. } else {
  942. strcpy(pcName, "Disconnected");
  943. }
  944. return 0;
  945. } /* wext_get_name */
  946. /*----------------------------------------------------------------------------*/
  947. /*!
  948. * \brief To set the operating channel in the wireless device.
  949. *
  950. * \param[in] prDev Net device requested.
  951. * \param[in] prIwrInfo NULL
  952. * \param[in] prFreq Buffer to store frequency information
  953. * \param[in] pcExtra NULL
  954. *
  955. * \retval 0 For success.
  956. * \retval -EOPNOTSUPP If infrastructure mode is not NET NET_TYPE_IBSS.
  957. * \retval -EINVAL Invalid channel frequency.
  958. *
  959. * \note If infrastructure mode is IBSS, new channel frequency is set to device.
  960. * The range of channel number depends on different regulatory domain.
  961. */
  962. /*----------------------------------------------------------------------------*/
  963. static int
  964. wext_set_freq(IN struct net_device *prNetDev,
  965. IN struct iw_request_info *prIwReqInfo, IN struct iw_freq *prIwFreq, IN char *pcExtra)
  966. {
  967. #if 0
  968. UINT_32 u4ChnlFreq; /* Store channel or frequency information */
  969. P_GLUE_INFO_T prGlueInfo = NULL;
  970. WLAN_STATUS rStatus = WLAN_STATUS_SUCCESS;
  971. UINT_32 u4BufLen = 0;
  972. ASSERT(prNetDev);
  973. ASSERT(prIwFreq);
  974. if (FALSE == GLUE_CHK_PR2(prNetDev, prIwFreq))
  975. return -EINVAL;
  976. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prNetDev));
  977. /*
  978. printk("set m:%d, e:%d, i:%d, flags:%d\n",
  979. prIwFreq->m, prIwFreq->e, prIwFreq->i, prIwFreq->flags);
  980. */
  981. /* If setting by frequency, convert to a channel */
  982. if ((prIwFreq->e == 1) && (prIwFreq->m >= (int)2.412e8) && (prIwFreq->m <= (int)2.484e8)) {
  983. /* Change to KHz format */
  984. u4ChnlFreq = (UINT_32) (prIwFreq->m / (KILO / 10));
  985. rStatus = kalIoctl(prGlueInfo,
  986. wlanoidSetFrequency,
  987. &u4ChnlFreq, sizeof(u4ChnlFreq), FALSE, FALSE, FALSE, &u4BufLen);
  988. if (WLAN_STATUS_SUCCESS != rStatus)
  989. return -EINVAL;
  990. }
  991. /* Setting by channel number */
  992. else if ((prIwFreq->m > KILO) || (prIwFreq->e > 0))
  993. return -EOPNOTSUPP;
  994. /* Change to channel number format */
  995. u4ChnlFreq = (UINT_32) prIwFreq->m;
  996. rStatus = kalIoctl(prGlueInfo,
  997. wlanoidSetChannel, &u4ChnlFreq, sizeof(u4ChnlFreq), FALSE, FALSE, FALSE, &u4BufLen);
  998. if (WLAN_STATUS_SUCCESS != rStatus)
  999. return -EINVAL;
  1000. #endif
  1001. return 0;
  1002. } /* wext_set_freq */
  1003. /*----------------------------------------------------------------------------*/
  1004. /*!
  1005. * \brief To get the operating channel in the wireless device.
  1006. *
  1007. * \param[in] prDev Net device requested.
  1008. * \param[in] prIwrInfo NULL.
  1009. * \param[out] prFreq Buffer to store frequency information.
  1010. * \param[in] pcExtra NULL.
  1011. *
  1012. * \retval 0 If netif_carrier_ok.
  1013. * \retval -ENOTCONN Otherwise
  1014. *
  1015. * \note If netif_carrier_ok, channel frequency information is stored in pFreq.
  1016. */
  1017. /*----------------------------------------------------------------------------*/
  1018. static int
  1019. wext_get_freq(IN struct net_device *prNetDev,
  1020. IN struct iw_request_info *prIwrInfo, OUT struct iw_freq *prIwFreq, IN char *pcExtra)
  1021. {
  1022. UINT_32 u4Channel = 0;
  1023. P_GLUE_INFO_T prGlueInfo = NULL;
  1024. WLAN_STATUS rStatus = WLAN_STATUS_SUCCESS;
  1025. UINT_32 u4BufLen = 0;
  1026. ASSERT(prNetDev);
  1027. ASSERT(prIwFreq);
  1028. if (FALSE == GLUE_CHK_PR2(prNetDev, prIwFreq))
  1029. return -EINVAL;
  1030. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prNetDev));
  1031. /* GeorgeKuo: TODO skip checking in IBSS mode */
  1032. if (!netif_carrier_ok(prNetDev))
  1033. return -ENOTCONN;
  1034. rStatus = kalIoctl(prGlueInfo,
  1035. wlanoidQueryFrequency, &u4Channel, sizeof(u4Channel), TRUE, FALSE, FALSE, FALSE, &u4BufLen);
  1036. prIwFreq->m = (int)u4Channel; /* freq in KHz */
  1037. prIwFreq->e = 3;
  1038. return 0;
  1039. } /* wext_get_freq */
  1040. /*----------------------------------------------------------------------------*/
  1041. /*!
  1042. * \brief To set operating mode.
  1043. *
  1044. * \param[in] prDev Net device requested.
  1045. * \param[in] prIwrInfo NULL.
  1046. * \param[in] pu4Mode Pointer to new operation mode.
  1047. * \param[in] pcExtra NULL.
  1048. *
  1049. * \retval 0 For success.
  1050. * \retval -EOPNOTSUPP If new mode is not supported.
  1051. *
  1052. * \note Device will run in new operation mode if it is valid.
  1053. */
  1054. /*----------------------------------------------------------------------------*/
  1055. static int
  1056. wext_set_mode(IN struct net_device *prNetDev,
  1057. IN struct iw_request_info *prIwReqInfo, IN unsigned int *pu4Mode, IN char *pcExtra)
  1058. {
  1059. ENUM_PARAM_OP_MODE_T eOpMode;
  1060. P_GLUE_INFO_T prGlueInfo = NULL;
  1061. WLAN_STATUS rStatus = WLAN_STATUS_SUCCESS;
  1062. UINT_32 u4BufLen = 0;
  1063. ASSERT(prNetDev);
  1064. ASSERT(pu4Mode);
  1065. if (FALSE == GLUE_CHK_PR2(prNetDev, pu4Mode))
  1066. return -EINVAL;
  1067. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prNetDev));
  1068. switch (*pu4Mode) {
  1069. case IW_MODE_AUTO:
  1070. eOpMode = NET_TYPE_AUTO_SWITCH;
  1071. break;
  1072. case IW_MODE_ADHOC:
  1073. eOpMode = NET_TYPE_IBSS;
  1074. break;
  1075. case IW_MODE_INFRA:
  1076. eOpMode = NET_TYPE_INFRA;
  1077. break;
  1078. default:
  1079. DBGLOG(REQ, ERROR, "%s(): Set UNSUPPORTED Mode = %d.\n", __func__, *pu4Mode);
  1080. return -EOPNOTSUPP;
  1081. }
  1082. /* printk("%s(): Set Mode = %d\n", __FUNCTION__, *pu4Mode); */
  1083. rStatus = kalIoctl(prGlueInfo,
  1084. wlanoidSetInfrastructureMode,
  1085. &eOpMode, sizeof(eOpMode), FALSE, FALSE, TRUE, FALSE, &u4BufLen);
  1086. /* after set operation mode, key table are cleared */
  1087. /* reset wpa info */
  1088. prGlueInfo->rWpaInfo.u4WpaVersion = IW_AUTH_WPA_VERSION_DISABLED;
  1089. prGlueInfo->rWpaInfo.u4KeyMgmt = 0;
  1090. prGlueInfo->rWpaInfo.u4CipherGroup = IW_AUTH_CIPHER_NONE;
  1091. prGlueInfo->rWpaInfo.u4CipherPairwise = IW_AUTH_CIPHER_NONE;
  1092. prGlueInfo->rWpaInfo.u4AuthAlg = IW_AUTH_ALG_OPEN_SYSTEM;
  1093. #if CFG_SUPPORT_802_11W
  1094. prGlueInfo->rWpaInfo.u4Mfp = IW_AUTH_MFP_DISABLED;
  1095. #endif
  1096. return 0;
  1097. } /* wext_set_mode */
  1098. /*----------------------------------------------------------------------------*/
  1099. /*!
  1100. * \brief To get operating mode.
  1101. *
  1102. * \param[in] prNetDev Net device requested.
  1103. * \param[in] prIwReqInfo NULL.
  1104. * \param[out] pu4Mode Buffer to store operating mode information.
  1105. * \param[in] pcExtra NULL.
  1106. *
  1107. * \retval 0 If data is valid.
  1108. * \retval -EINVAL Otherwise.
  1109. *
  1110. * \note If netif_carrier_ok, operating mode information is stored in pu4Mode.
  1111. */
  1112. /*----------------------------------------------------------------------------*/
  1113. static int
  1114. wext_get_mode(IN struct net_device *prNetDev,
  1115. IN struct iw_request_info *prIwReqInfo, OUT unsigned int *pu4Mode, IN char *pcExtra)
  1116. {
  1117. ENUM_PARAM_OP_MODE_T eOpMode = NET_TYPE_NUM;
  1118. P_GLUE_INFO_T prGlueInfo = NULL;
  1119. WLAN_STATUS rStatus = WLAN_STATUS_SUCCESS;
  1120. UINT_32 u4BufLen = 0;
  1121. ASSERT(prNetDev);
  1122. ASSERT(pu4Mode);
  1123. if (FALSE == GLUE_CHK_PR2(prNetDev, pu4Mode))
  1124. return -EINVAL;
  1125. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prNetDev));
  1126. rStatus = kalIoctl(prGlueInfo,
  1127. wlanoidQueryInfrastructureMode,
  1128. &eOpMode, sizeof(eOpMode), TRUE, FALSE, FALSE, FALSE, &u4BufLen);
  1129. switch (eOpMode) {
  1130. case NET_TYPE_IBSS:
  1131. *pu4Mode = IW_MODE_ADHOC;
  1132. break;
  1133. case NET_TYPE_INFRA:
  1134. *pu4Mode = IW_MODE_INFRA;
  1135. break;
  1136. case NET_TYPE_AUTO_SWITCH:
  1137. *pu4Mode = IW_MODE_AUTO;
  1138. break;
  1139. default:
  1140. DBGLOG(REQ, ERROR, "%s(): Get UNKNOWN Mode.\n", __func__);
  1141. return -EINVAL;
  1142. }
  1143. return 0;
  1144. } /* wext_get_mode */
  1145. /*----------------------------------------------------------------------------*/
  1146. /*!
  1147. * \brief To get the valid range for each configurable STA setting value.
  1148. *
  1149. * \param[in] prDev Net device requested.
  1150. * \param[in] prIwrInfo NULL.
  1151. * \param[in] prData Pointer to iw_point structure, not used.
  1152. * \param[out] pcExtra Pointer to buffer which is allocated by caller of this
  1153. * function, wext_support_ioctl() or ioctl_standard_call() in
  1154. * wireless.c.
  1155. *
  1156. * \retval 0 If data is valid.
  1157. *
  1158. * \note The extra buffer (pcExtra) is filled with information from driver.
  1159. */
  1160. /*----------------------------------------------------------------------------*/
  1161. static int
  1162. wext_get_range(IN struct net_device *prNetDev,
  1163. IN struct iw_request_info *prIwrInfo, IN struct iw_point *prData, OUT char *pcExtra)
  1164. {
  1165. struct iw_range *prRange = NULL;
  1166. PARAM_RATES_EX aucSuppRate = { 0 }; /* data buffers */
  1167. int i = 0;
  1168. P_GLUE_INFO_T prGlueInfo = NULL;
  1169. WLAN_STATUS rStatus = WLAN_STATUS_SUCCESS;
  1170. UINT_32 u4BufLen = 0;
  1171. ASSERT(prNetDev);
  1172. ASSERT(pcExtra);
  1173. if (FALSE == GLUE_CHK_PR2(prNetDev, pcExtra))
  1174. return -EINVAL;
  1175. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prNetDev));
  1176. prRange = (struct iw_range *)pcExtra;
  1177. memset(prRange, 0, sizeof(*prRange));
  1178. prRange->throughput = 20000000; /* 20Mbps */
  1179. prRange->min_nwid = 0; /* not used */
  1180. prRange->max_nwid = 0; /* not used */
  1181. /* scan_capa not implemented */
  1182. /* event_capa[6]: kernel + driver capabilities */
  1183. prRange->event_capa[0] = (IW_EVENT_CAPA_K_0 | IW_EVENT_CAPA_MASK(SIOCGIWAP)
  1184. | IW_EVENT_CAPA_MASK(SIOCGIWSCAN)
  1185. /* can't display meaningful string in iwlist
  1186. | IW_EVENT_CAPA_MASK(SIOCGIWTXPOW)
  1187. | IW_EVENT_CAPA_MASK(IWEVMICHAELMICFAILURE)
  1188. | IW_EVENT_CAPA_MASK(IWEVASSOCREQIE)
  1189. | IW_EVENT_CAPA_MASK(IWEVPMKIDCAND)
  1190. */
  1191. );
  1192. prRange->event_capa[1] = IW_EVENT_CAPA_K_1;
  1193. /* report 2.4G channel and frequency only */
  1194. prRange->num_channels = (__u16) NUM_CHANNELS;
  1195. prRange->num_frequency = (__u8) NUM_CHANNELS;
  1196. for (i = 0; i < NUM_CHANNELS; i++) {
  1197. /* iwlib takes this number as channel number */
  1198. prRange->freq[i].i = i + 1;
  1199. prRange->freq[i].m = channel_freq[i];
  1200. prRange->freq[i].e = 6; /* Values in table in MHz */
  1201. }
  1202. rStatus = kalIoctl(prGlueInfo,
  1203. wlanoidQuerySupportedRates,
  1204. &aucSuppRate, sizeof(aucSuppRate), TRUE, FALSE, FALSE, FALSE, &u4BufLen);
  1205. for (i = 0; i < IW_MAX_BITRATES && i < PARAM_MAX_LEN_RATES_EX; i++) {
  1206. if (aucSuppRate[i] == 0)
  1207. break;
  1208. prRange->bitrate[i] = (aucSuppRate[i] & 0x7F) * 500000; /* 0.5Mbps */
  1209. }
  1210. prRange->num_bitrates = i;
  1211. prRange->min_rts = 0;
  1212. prRange->max_rts = 2347;
  1213. prRange->min_frag = 256;
  1214. prRange->max_frag = 2346;
  1215. prRange->min_pmp = 0; /* power management by driver */
  1216. prRange->max_pmp = 0; /* power management by driver */
  1217. prRange->min_pmt = 0; /* power management by driver */
  1218. prRange->max_pmt = 0; /* power management by driver */
  1219. prRange->pmp_flags = IW_POWER_RELATIVE; /* pm default flag */
  1220. prRange->pmt_flags = IW_POWER_ON; /* pm timeout flag */
  1221. prRange->pm_capa = IW_POWER_ON; /* power management by driver */
  1222. prRange->encoding_size[0] = 5; /* wep40 */
  1223. prRange->encoding_size[1] = 16; /* tkip */
  1224. prRange->encoding_size[2] = 16; /* ckip */
  1225. prRange->encoding_size[3] = 16; /* ccmp */
  1226. prRange->encoding_size[4] = 13; /* wep104 */
  1227. prRange->encoding_size[5] = 16; /* wep128 */
  1228. prRange->num_encoding_sizes = 6;
  1229. prRange->max_encoding_tokens = 6; /* token? */
  1230. #if WIRELESS_EXT < 17
  1231. prRange->txpower_capa = 0x0002; /* IW_TXPOW_RELATIVE */
  1232. #else
  1233. prRange->txpower_capa = IW_TXPOW_RELATIVE;
  1234. #endif
  1235. prRange->num_txpower = 5;
  1236. prRange->txpower[0] = 0; /* minimum */
  1237. prRange->txpower[1] = 25; /* 25% */
  1238. prRange->txpower[2] = 50; /* 50% */
  1239. prRange->txpower[3] = 100; /* 100% */
  1240. prRange->we_version_compiled = WIRELESS_EXT;
  1241. prRange->we_version_source = WIRELESS_EXT;
  1242. prRange->retry_capa = IW_RETRY_LIMIT;
  1243. prRange->retry_flags = IW_RETRY_LIMIT;
  1244. prRange->min_retry = 7;
  1245. prRange->max_retry = 7;
  1246. prRange->r_time_flags = IW_RETRY_ON;
  1247. prRange->min_r_time = 0;
  1248. prRange->max_r_time = 0;
  1249. /* signal strength and link quality */
  1250. /* Just define range here, reporting value moved to wext_get_stats() */
  1251. prRange->sensitivity = -83; /* fixed value */
  1252. prRange->max_qual.qual = 100; /* max 100% */
  1253. prRange->max_qual.level = (__u8) (0x100 - 0); /* max 0 dbm */
  1254. prRange->max_qual.noise = (__u8) (0x100 - 0); /* max 0 dbm */
  1255. /* enc_capa */
  1256. #if WIRELESS_EXT > 17
  1257. prRange->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 | IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
  1258. #endif
  1259. /* min_pms; Minimal PM saving */
  1260. /* max_pms; Maximal PM saving */
  1261. /* pms_flags; How to decode max/min PM saving */
  1262. /* modul_capa; IW_MODUL_* bit field */
  1263. /* bitrate_capa; Types of bitrates supported */
  1264. return 0;
  1265. } /* wext_get_range */
  1266. /*----------------------------------------------------------------------------*/
  1267. /*!
  1268. * \brief To set BSSID of AP to connect.
  1269. *
  1270. * \param[in] prDev Net device requested.
  1271. * \param[in] prIwrInfo NULL.
  1272. * \param[in] prAddr Pointer to struct sockaddr structure containing AP's BSSID.
  1273. * \param[in] pcExtra NULL.
  1274. *
  1275. * \retval 0 For success.
  1276. *
  1277. * \note Desired AP's BSSID is set to driver.
  1278. */
  1279. /*----------------------------------------------------------------------------*/
  1280. static int
  1281. wext_set_ap(IN struct net_device *prDev,
  1282. IN struct iw_request_info *prIwrInfo, IN struct sockaddr *prAddr, IN char *pcExtra)
  1283. {
  1284. return 0;
  1285. } /* wext_set_ap */
  1286. /*----------------------------------------------------------------------------*/
  1287. /*!
  1288. * \brief To get AP MAC address.
  1289. *
  1290. * \param[in] prDev Net device requested.
  1291. * \param[in] prIwrInfo NULL.
  1292. * \param[out] prAddr Pointer to struct sockaddr structure storing AP's BSSID.
  1293. * \param[in] pcExtra NULL.
  1294. *
  1295. * \retval 0 If netif_carrier_ok.
  1296. * \retval -ENOTCONN Otherwise.
  1297. *
  1298. * \note If netif_carrier_ok, AP's mac address is stored in pAddr->sa_data.
  1299. */
  1300. /*----------------------------------------------------------------------------*/
  1301. static int
  1302. wext_get_ap(IN struct net_device *prNetDev,
  1303. IN struct iw_request_info *prIwrInfo, OUT struct sockaddr *prAddr, IN char *pcExtra)
  1304. {
  1305. P_GLUE_INFO_T prGlueInfo = NULL;
  1306. WLAN_STATUS rStatus = WLAN_STATUS_SUCCESS;
  1307. UINT_32 u4BufLen = 0;
  1308. ASSERT(prNetDev);
  1309. ASSERT(prAddr);
  1310. if (FALSE == GLUE_CHK_PR2(prNetDev, prAddr))
  1311. return -EINVAL;
  1312. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prNetDev));
  1313. /* if (!netif_carrier_ok(prNetDev)) { */
  1314. /* return -ENOTCONN; */
  1315. /* } */
  1316. if (prGlueInfo->eParamMediaStateIndicated == PARAM_MEDIA_STATE_DISCONNECTED) {
  1317. /*memset(prAddr, 0, 6);*/
  1318. memset(prAddr, 0, sizeof(struct sockaddr));
  1319. return 0;
  1320. }
  1321. rStatus = kalIoctl(prGlueInfo,
  1322. wlanoidQueryBssid, prAddr->sa_data, ETH_ALEN, TRUE, FALSE, FALSE, FALSE, &u4BufLen);
  1323. return 0;
  1324. } /* wext_get_ap */
  1325. /*----------------------------------------------------------------------------*/
  1326. /*!
  1327. * \brief To set mlme operation request.
  1328. *
  1329. * \param[in] prDev Net device requested.
  1330. * \param[in] prIwrInfo NULL.
  1331. * \param[in] prData Pointer of iw_point header.
  1332. * \param[in] pcExtra Pointer to iw_mlme structure mlme request information.
  1333. *
  1334. * \retval 0 For success.
  1335. * \retval -EOPNOTSUPP unsupported IW_MLME_ command.
  1336. * \retval -EINVAL Set MLME Fail, different bssid.
  1337. *
  1338. * \note Driver will start mlme operation if valid.
  1339. */
  1340. /*----------------------------------------------------------------------------*/
  1341. static int
  1342. wext_set_mlme(IN struct net_device *prNetDev,
  1343. IN struct iw_request_info *prIwrInfo, IN struct iw_point *prData, IN char *pcExtra)
  1344. {
  1345. struct iw_mlme *prMlme = NULL;
  1346. P_GLUE_INFO_T prGlueInfo = NULL;
  1347. WLAN_STATUS rStatus = WLAN_STATUS_SUCCESS;
  1348. UINT_32 u4BufLen = 0;
  1349. ASSERT(prNetDev);
  1350. ASSERT(pcExtra);
  1351. if (FALSE == GLUE_CHK_PR2(prNetDev, pcExtra))
  1352. return -EINVAL;
  1353. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prNetDev));
  1354. prMlme = (struct iw_mlme *)pcExtra;
  1355. if (prMlme->cmd == IW_MLME_DEAUTH || prMlme->cmd == IW_MLME_DISASSOC) {
  1356. if (!netif_carrier_ok(prNetDev)) {
  1357. DBGLOG(REQ, WARN, "[wifi] Set MLME Deauth/Disassoc, but netif_carrier_off\n");
  1358. return 0;
  1359. }
  1360. rStatus = kalIoctl(prGlueInfo, wlanoidSetDisassociate, NULL, 0, FALSE, FALSE, TRUE, FALSE, &u4BufLen);
  1361. return 0;
  1362. }
  1363. DBGLOG(REQ, WARN, "[wifi] unsupported IW_MLME_ command :%d\n", prMlme->cmd);
  1364. return -EOPNOTSUPP;
  1365. } /* wext_set_mlme */
  1366. /*----------------------------------------------------------------------------*/
  1367. /*!
  1368. * \brief To issue scan request.
  1369. *
  1370. * \param[in] prDev Net device requested.
  1371. * \param[in] prIwrInfo NULL.
  1372. * \param[in] prData NULL.
  1373. * \param[in] pcExtra NULL.
  1374. *
  1375. * \retval 0 For success.
  1376. * \retval -EFAULT Tx power is off.
  1377. *
  1378. * \note Device will start scanning.
  1379. */
  1380. /*----------------------------------------------------------------------------*/
  1381. static int
  1382. wext_set_scan(IN struct net_device *prNetDev,
  1383. IN struct iw_request_info *prIwrInfo, IN struct iw_scan_req *prIwScanReq, IN char *pcExtra)
  1384. {
  1385. P_GLUE_INFO_T prGlueInfo = NULL;
  1386. WLAN_STATUS rStatus = WLAN_STATUS_SUCCESS;
  1387. UINT_32 u4BufLen = 0;
  1388. int essid_len = 0;
  1389. ASSERT(prNetDev);
  1390. if (FALSE == GLUE_CHK_DEV(prNetDev))
  1391. return -EINVAL;
  1392. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prNetDev));
  1393. #if WIRELESS_EXT > 17
  1394. /* retrieve SSID */
  1395. if (prIwScanReq)
  1396. essid_len = prIwScanReq->essid_len;
  1397. #endif
  1398. init_completion(&prGlueInfo->rScanComp);
  1399. /* TODO: parse flags and issue different scan requests? */
  1400. rStatus = kalIoctl(prGlueInfo,
  1401. wlanoidSetBssidListScan, pcExtra, essid_len, FALSE, FALSE, FALSE, FALSE, &u4BufLen);
  1402. /* wait_for_completion_interruptible_timeout(&prGlueInfo->rScanComp, 2 * KAL_HZ); */
  1403. /* kalIndicateStatusAndComplete(prGlueInfo, WLAN_STATUS_SCAN_COMPLETE, NULL, 0); */
  1404. return 0;
  1405. } /* wext_set_scan */
  1406. /*----------------------------------------------------------------------------*/
  1407. /*!
  1408. * \brief To write the ie to buffer
  1409. *
  1410. */
  1411. /*----------------------------------------------------------------------------*/
  1412. static inline int snprintf_hex(char *buf, size_t buf_size, const u8 *data, size_t len)
  1413. {
  1414. size_t i;
  1415. char *pos = buf, *end = buf + buf_size;
  1416. int ret;
  1417. if (buf_size == 0)
  1418. return 0;
  1419. for (i = 0; i < len; i++) {
  1420. ret = snprintf(pos, end - pos, "%02x", data[i]);
  1421. if (ret < 0 || ret >= end - pos) {
  1422. end[-1] = '\0';
  1423. return pos - buf;
  1424. }
  1425. pos += ret;
  1426. }
  1427. end[-1] = '\0';
  1428. return pos - buf;
  1429. }
  1430. /*----------------------------------------------------------------------------*/
  1431. /*!
  1432. * \brief To get scan results, transform results from driver's format to WE's.
  1433. *
  1434. * \param[in] prDev Net device requested.
  1435. * \param[in] prIwrInfo NULL.
  1436. * \param[out] prData Pointer to iw_point structure, pData->length is the size of
  1437. * pcExtra buffer before used, and is updated after filling scan
  1438. * results.
  1439. * \param[out] pcExtra Pointer to buffer which is allocated by caller of this
  1440. * function, wext_support_ioctl() or ioctl_standard_call() in
  1441. * wireless.c.
  1442. *
  1443. * \retval 0 For success.
  1444. * \retval -ENOMEM If dynamic memory allocation fail.
  1445. * \retval -E2BIG Invalid length.
  1446. *
  1447. * \note Scan results is filled into pcExtra buffer, data size is updated in
  1448. * pData->length.
  1449. */
  1450. /*----------------------------------------------------------------------------*/
  1451. static int
  1452. wext_get_scan(IN struct net_device *prNetDev,
  1453. IN struct iw_request_info *prIwrInfo, IN OUT struct iw_point *prData, IN char *pcExtra)
  1454. {
  1455. UINT_32 i = 0;
  1456. UINT_32 j = 0;
  1457. P_PARAM_BSSID_LIST_EX_T prList = NULL;
  1458. P_PARAM_BSSID_EX_T prBss = NULL;
  1459. P_PARAM_VARIABLE_IE_T prDesiredIE = NULL;
  1460. struct iw_event iwEvent; /* local iw_event buffer */
  1461. /* write pointer of extra buffer */
  1462. char *pcCur = NULL;
  1463. /* pointer to the end of last full entry in extra buffer */
  1464. char *pcValidEntryEnd = NULL;
  1465. char *pcEnd = NULL; /* end of extra buffer */
  1466. UINT_32 u4AllocBufLen = 0;
  1467. /* arrange rate information */
  1468. UINT_32 u4HighestRate = 0;
  1469. char aucRatesBuf[64];
  1470. UINT_32 u4BufIndex;
  1471. /* return value */
  1472. int ret = 0;
  1473. P_GLUE_INFO_T prGlueInfo = NULL;
  1474. WLAN_STATUS rStatus = WLAN_STATUS_SUCCESS;
  1475. UINT_32 u4BufLen = 0;
  1476. ASSERT(prNetDev);
  1477. ASSERT(prData);
  1478. ASSERT(pcExtra);
  1479. if (FALSE == GLUE_CHK_PR3(prNetDev, prData, pcExtra))
  1480. return -EINVAL;
  1481. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prNetDev));
  1482. /* Initialize local variables */
  1483. pcCur = pcExtra;
  1484. pcValidEntryEnd = pcExtra;
  1485. pcEnd = pcExtra + prData->length; /* end of extra buffer */
  1486. /* Allocate another query buffer with the same size of extra buffer */
  1487. u4AllocBufLen = prData->length;
  1488. prList = kalMemAlloc(u4AllocBufLen, VIR_MEM_TYPE);
  1489. if (prList == NULL) {
  1490. DBGLOG(REQ, ERROR, "[wifi] no memory for scan list:%d\n", prData->length);
  1491. ret = -ENOMEM;
  1492. goto error;
  1493. }
  1494. prList->u4NumberOfItems = 0;
  1495. /* wait scan done */
  1496. /* printk ("wait for scan results\n"); */
  1497. /* wait_for_completion_interruptible_timeout(&prGlueInfo->rScanComp, 4 * KAL_HZ); */
  1498. rStatus = kalIoctl(prGlueInfo,
  1499. wlanoidQueryBssidList, prList, u4AllocBufLen, TRUE, FALSE, FALSE, FALSE, &u4BufLen);
  1500. if (rStatus == WLAN_STATUS_INVALID_LENGTH) {
  1501. /* Buffer length is not large enough. */
  1502. /* printk(KERN_INFO "[wifi] buf:%d result:%ld\n", pData->length, u4BufLen); */
  1503. #if WIRELESS_EXT >= 17
  1504. /* This feature is supported in WE-17 or above, limited by iwlist.
  1505. ** Return -E2BIG and iwlist will request again with a larger buffer.
  1506. */
  1507. ret = -E2BIG;
  1508. /* Update length to give application a hint on result length */
  1509. prData->length = (__u16) u4BufLen;
  1510. goto error;
  1511. #else
  1512. /* Realloc a larger query buffer here, but don't write too much to extra
  1513. ** buffer when filling it later.
  1514. */
  1515. kalMemFree(prList, VIR_MEM_TYPE, u4AllocBufLen);
  1516. u4AllocBufLen = u4BufLen;
  1517. prList = kalMemAlloc(u4AllocBufLen, VIR_MEM_TYPE);
  1518. if (prList == NULL) {
  1519. DBGLOG(REQ, ERROR, "[wifi] no memory for larger scan list :%u\n", u4BufLen);
  1520. ret = -ENOMEM;
  1521. goto error;
  1522. }
  1523. prList->NumberOfItems = 0;
  1524. rStatus = kalIoctl(prGlueInfo,
  1525. wlanoidQueryBssidList, prList, u4AllocBufLen, TRUE, FALSE, FALSE, FALSE, &u4BufLen);
  1526. if (rStatus == WLAN_STATUS_INVALID_LENGTH) {
  1527. DBGLOG(REQ, ERROR, "[wifi] larger buf:%u result:%u\n", u4AllocBufLen, u4BufLen);
  1528. ret = -E2BIG;
  1529. prData->length = (__u16) u4BufLen;
  1530. goto error;
  1531. }
  1532. #endif /* WIRELESS_EXT >= 17 */
  1533. }
  1534. if (prList->u4NumberOfItems > CFG_MAX_NUM_BSS_LIST) {
  1535. DBGLOG(REQ, WARN, "[wifi] strange scan result count:%u\n", prList->u4NumberOfItems);
  1536. goto error;
  1537. }
  1538. /* Copy required data from pList to pcExtra */
  1539. prBss = &prList->arBssid[0]; /* set to the first entry */
  1540. for (i = 0; i < prList->u4NumberOfItems; ++i) {
  1541. /* BSSID */
  1542. iwEvent.cmd = SIOCGIWAP;
  1543. iwEvent.len = IW_EV_ADDR_LEN;
  1544. if ((pcCur + iwEvent.len) > pcEnd)
  1545. break;
  1546. iwEvent.u.ap_addr.sa_family = ARPHRD_ETHER;
  1547. ether_addr_copy(iwEvent.u.ap_addr.sa_data, prBss->arMacAddress);
  1548. memcpy(pcCur, &iwEvent, IW_EV_ADDR_LEN);
  1549. pcCur += IW_EV_ADDR_LEN;
  1550. /* SSID */
  1551. iwEvent.cmd = SIOCGIWESSID;
  1552. /* Modification to user space pointer(essid.pointer) is not needed. */
  1553. iwEvent.u.essid.length = (__u16) prBss->rSsid.u4SsidLen;
  1554. iwEvent.len = IW_EV_POINT_LEN + iwEvent.u.essid.length;
  1555. if ((pcCur + iwEvent.len) > pcEnd)
  1556. break;
  1557. iwEvent.u.essid.flags = 1;
  1558. iwEvent.u.essid.pointer = NULL;
  1559. #if WIRELESS_EXT <= 18
  1560. memcpy(pcCur, &iwEvent, iwEvent.len);
  1561. #else
  1562. memcpy(pcCur, &iwEvent, IW_EV_LCP_LEN);
  1563. memcpy(pcCur + IW_EV_LCP_LEN, &iwEvent.u.data.length, sizeof(struct iw_point) - IW_EV_POINT_OFF);
  1564. #endif
  1565. memcpy(pcCur + IW_EV_POINT_LEN, prBss->rSsid.aucSsid, iwEvent.u.essid.length);
  1566. pcCur += iwEvent.len;
  1567. /* Frequency */
  1568. iwEvent.cmd = SIOCGIWFREQ;
  1569. iwEvent.len = IW_EV_FREQ_LEN;
  1570. if ((pcCur + iwEvent.len) > pcEnd)
  1571. break;
  1572. iwEvent.u.freq.m = prBss->rConfiguration.u4DSConfig;
  1573. iwEvent.u.freq.e = 3; /* (in KHz) */
  1574. iwEvent.u.freq.i = 0;
  1575. memcpy(pcCur, &iwEvent, IW_EV_FREQ_LEN);
  1576. pcCur += IW_EV_FREQ_LEN;
  1577. /* Operation Mode */
  1578. iwEvent.cmd = SIOCGIWMODE;
  1579. iwEvent.len = IW_EV_UINT_LEN;
  1580. if ((pcCur + iwEvent.len) > pcEnd)
  1581. break;
  1582. if (prBss->eOpMode == NET_TYPE_IBSS)
  1583. iwEvent.u.mode = IW_MODE_ADHOC;
  1584. else if (prBss->eOpMode == NET_TYPE_INFRA)
  1585. iwEvent.u.mode = IW_MODE_INFRA;
  1586. else
  1587. iwEvent.u.mode = IW_MODE_AUTO;
  1588. memcpy(pcCur, &iwEvent, IW_EV_UINT_LEN);
  1589. pcCur += IW_EV_UINT_LEN;
  1590. /* Quality */
  1591. iwEvent.cmd = IWEVQUAL;
  1592. iwEvent.len = IW_EV_QUAL_LEN;
  1593. if ((pcCur + iwEvent.len) > pcEnd)
  1594. break;
  1595. iwEvent.u.qual.qual = 0; /* Quality not available now */
  1596. /* -100 < Rssi < -10, normalized by adding 0x100 */
  1597. iwEvent.u.qual.level = 0x100 + prBss->rRssi;
  1598. iwEvent.u.qual.noise = 0; /* Noise not available now */
  1599. iwEvent.u.qual.updated = IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_UPDATED | IW_QUAL_NOISE_INVALID;
  1600. memcpy(pcCur, &iwEvent, IW_EV_QUAL_LEN);
  1601. pcCur += IW_EV_QUAL_LEN;
  1602. /* Security Mode */
  1603. iwEvent.cmd = SIOCGIWENCODE;
  1604. iwEvent.len = IW_EV_POINT_LEN;
  1605. if ((pcCur + iwEvent.len) > pcEnd)
  1606. break;
  1607. iwEvent.u.data.pointer = NULL;
  1608. iwEvent.u.data.flags = 0;
  1609. iwEvent.u.data.length = 0;
  1610. if (!prBss->u4Privacy)
  1611. iwEvent.u.data.flags |= IW_ENCODE_DISABLED;
  1612. #if WIRELESS_EXT <= 18
  1613. memcpy(pcCur, &iwEvent, IW_EV_POINT_LEN);
  1614. #else
  1615. memcpy(pcCur, &iwEvent, IW_EV_LCP_LEN);
  1616. memcpy(pcCur + IW_EV_LCP_LEN, &iwEvent.u.data.length, sizeof(struct iw_point) - IW_EV_POINT_OFF);
  1617. #endif
  1618. pcCur += IW_EV_POINT_LEN;
  1619. /* rearrange rate information */
  1620. u4BufIndex = sprintf(aucRatesBuf, "Rates (Mb/s):");
  1621. u4HighestRate = 0;
  1622. for (j = 0; j < PARAM_MAX_LEN_RATES_EX; ++j) {
  1623. UINT_8 curRate = prBss->rSupportedRates[j] & 0x7F;
  1624. if (curRate == 0)
  1625. break;
  1626. if (curRate > u4HighestRate)
  1627. u4HighestRate = curRate;
  1628. if (curRate == RATE_5_5M)
  1629. u4BufIndex += sprintf(aucRatesBuf + u4BufIndex, " 5.5");
  1630. else
  1631. u4BufIndex += sprintf(aucRatesBuf + u4BufIndex, " %d", curRate / 2);
  1632. #if DBG
  1633. if (u4BufIndex > sizeof(aucRatesBuf)) {
  1634. /* printk("rate info too long\n"); */
  1635. break;
  1636. }
  1637. #endif
  1638. }
  1639. /* Report Highest Rates */
  1640. iwEvent.cmd = SIOCGIWRATE;
  1641. iwEvent.len = IW_EV_PARAM_LEN;
  1642. if ((pcCur + iwEvent.len) > pcEnd)
  1643. break;
  1644. iwEvent.u.bitrate.value = u4HighestRate * 500000;
  1645. iwEvent.u.bitrate.fixed = 0;
  1646. iwEvent.u.bitrate.disabled = 0;
  1647. iwEvent.u.bitrate.flags = 0;
  1648. memcpy(pcCur, &iwEvent, iwEvent.len);
  1649. pcCur += iwEvent.len;
  1650. #if WIRELESS_EXT >= 15 /* IWEVCUSTOM is available in WE-15 or above */
  1651. /* Report Residual Rates */
  1652. iwEvent.cmd = IWEVCUSTOM;
  1653. iwEvent.u.data.length = u4BufIndex;
  1654. iwEvent.len = IW_EV_POINT_LEN + iwEvent.u.data.length;
  1655. if ((pcCur + iwEvent.len) > pcEnd)
  1656. break;
  1657. iwEvent.u.data.flags = 0;
  1658. #if WIRELESS_EXT <= 18
  1659. memcpy(pcCur, &iwEvent, IW_EV_POINT_LEN);
  1660. #else
  1661. memcpy(pcCur, &iwEvent, IW_EV_LCP_LEN);
  1662. memcpy(pcCur + IW_EV_LCP_LEN, &iwEvent.u.data.length, sizeof(struct iw_point) - IW_EV_POINT_OFF);
  1663. #endif
  1664. memcpy(pcCur + IW_EV_POINT_LEN, aucRatesBuf, u4BufIndex);
  1665. pcCur += iwEvent.len;
  1666. #endif /* WIRELESS_EXT >= 15 */
  1667. if (wextSrchDesiredWPAIE(&prBss->aucIEs[sizeof(PARAM_FIXED_IEs)],
  1668. prBss->u4IELength - sizeof(PARAM_FIXED_IEs),
  1669. 0xDD, (PUINT_8 *) &prDesiredIE)) {
  1670. iwEvent.cmd = IWEVGENIE;
  1671. iwEvent.u.data.flags = 1;
  1672. iwEvent.u.data.length = 2 + (__u16) prDesiredIE->ucLength;
  1673. iwEvent.len = IW_EV_POINT_LEN + iwEvent.u.data.length;
  1674. if ((pcCur + iwEvent.len) > pcEnd)
  1675. break;
  1676. #if WIRELESS_EXT <= 18
  1677. memcpy(pcCur, &iwEvent, IW_EV_POINT_LEN);
  1678. #else
  1679. memcpy(pcCur, &iwEvent, IW_EV_LCP_LEN);
  1680. memcpy(pcCur + IW_EV_LCP_LEN,
  1681. &iwEvent.u.data.length, sizeof(struct iw_point) - IW_EV_POINT_OFF);
  1682. #endif
  1683. memcpy(pcCur + IW_EV_POINT_LEN, prDesiredIE, 2 + prDesiredIE->ucLength);
  1684. pcCur += iwEvent.len;
  1685. }
  1686. #if CFG_SUPPORT_WPS /* search WPS IE (0xDD, 221, OUI: 0x0050f204 ) */
  1687. if (wextSrchDesiredWPSIE(&prBss->aucIEs[sizeof(PARAM_FIXED_IEs)],
  1688. prBss->u4IELength - sizeof(PARAM_FIXED_IEs),
  1689. 0xDD, (PUINT_8 *) &prDesiredIE)) {
  1690. iwEvent.cmd = IWEVGENIE;
  1691. iwEvent.u.data.flags = 1;
  1692. iwEvent.u.data.length = 2 + (__u16) prDesiredIE->ucLength;
  1693. iwEvent.len = IW_EV_POINT_LEN + iwEvent.u.data.length;
  1694. if ((pcCur + iwEvent.len) > pcEnd)
  1695. break;
  1696. #if WIRELESS_EXT <= 18
  1697. memcpy(pcCur, &iwEvent, IW_EV_POINT_LEN);
  1698. #else
  1699. memcpy(pcCur, &iwEvent, IW_EV_LCP_LEN);
  1700. memcpy(pcCur + IW_EV_LCP_LEN,
  1701. &iwEvent.u.data.length, sizeof(struct iw_point) - IW_EV_POINT_OFF);
  1702. #endif
  1703. memcpy(pcCur + IW_EV_POINT_LEN, prDesiredIE, 2 + prDesiredIE->ucLength);
  1704. pcCur += iwEvent.len;
  1705. }
  1706. #endif
  1707. /* Search RSN IE (0x30, 48). pBss->IEs starts from timestamp. */
  1708. /* pBss->IEs starts from timestamp */
  1709. if (wextSrchDesiredWPAIE(&prBss->aucIEs[sizeof(PARAM_FIXED_IEs)],
  1710. prBss->u4IELength - sizeof(PARAM_FIXED_IEs),
  1711. 0x30, (PUINT_8 *) &prDesiredIE)) {
  1712. iwEvent.cmd = IWEVGENIE;
  1713. iwEvent.u.data.flags = 1;
  1714. iwEvent.u.data.length = 2 + (__u16) prDesiredIE->ucLength;
  1715. iwEvent.len = IW_EV_POINT_LEN + iwEvent.u.data.length;
  1716. if ((pcCur + iwEvent.len) > pcEnd)
  1717. break;
  1718. #if WIRELESS_EXT <= 18
  1719. memcpy(pcCur, &iwEvent, IW_EV_POINT_LEN);
  1720. #else
  1721. memcpy(pcCur, &iwEvent, IW_EV_LCP_LEN);
  1722. memcpy(pcCur + IW_EV_LCP_LEN,
  1723. &iwEvent.u.data.length, sizeof(struct iw_point) - IW_EV_POINT_OFF);
  1724. #endif
  1725. memcpy(pcCur + IW_EV_POINT_LEN, prDesiredIE, 2 + prDesiredIE->ucLength);
  1726. pcCur += iwEvent.len;
  1727. }
  1728. #if CFG_SUPPORT_WAPI /* Android+ */
  1729. if (wextSrchDesiredWAPIIE(&prBss->aucIEs[sizeof(PARAM_FIXED_IEs)],
  1730. prBss->u4IELength - sizeof(PARAM_FIXED_IEs), (PUINT_8 *) &prDesiredIE)) {
  1731. #if 0
  1732. iwEvent.cmd = IWEVGENIE;
  1733. iwEvent.u.data.flags = 1;
  1734. iwEvent.u.data.length = 2 + (__u16) prDesiredIE->ucLength;
  1735. iwEvent.len = IW_EV_POINT_LEN + iwEvent.u.data.length;
  1736. if ((pcCur + iwEvent.len) > pcEnd)
  1737. break;
  1738. #if WIRELESS_EXT <= 18
  1739. memcpy(pcCur, &iwEvent, IW_EV_POINT_LEN);
  1740. #else
  1741. memcpy(pcCur, &iwEvent, IW_EV_LCP_LEN);
  1742. memcpy(pcCur + IW_EV_LCP_LEN,
  1743. &iwEvent.u.data.length, sizeof(struct iw_point) - IW_EV_POINT_OFF);
  1744. #endif
  1745. memcpy(pcCur + IW_EV_POINT_LEN, prDesiredIE, 2 + prDesiredIE->ucLength);
  1746. pcCur += iwEvent.len;
  1747. #else
  1748. iwEvent.cmd = IWEVCUSTOM;
  1749. iwEvent.u.data.length = (2 + prDesiredIE->ucLength) * 2 + 8 /* wapi_ie= */;
  1750. iwEvent.len = IW_EV_POINT_LEN + iwEvent.u.data.length;
  1751. if ((pcCur + iwEvent.len) > pcEnd)
  1752. break;
  1753. iwEvent.u.data.flags = 1;
  1754. memcpy(pcCur, &iwEvent, IW_EV_LCP_LEN);
  1755. memcpy(pcCur + IW_EV_LCP_LEN,
  1756. &iwEvent.u.data.length, sizeof(struct iw_point) - IW_EV_POINT_OFF);
  1757. pcCur += (IW_EV_POINT_LEN);
  1758. pcCur += sprintf(pcCur, "wapi_ie=");
  1759. snprintf_hex(pcCur, pcEnd - pcCur, (UINT_8 *) prDesiredIE, prDesiredIE->ucLength + 2);
  1760. pcCur += (2 + prDesiredIE->ucLength) * 2 /* iwEvent.len */;
  1761. #endif
  1762. }
  1763. #endif
  1764. /* Complete an entry. Update end of valid entry */
  1765. pcValidEntryEnd = pcCur;
  1766. /* Extract next bss */
  1767. prBss = (P_PARAM_BSSID_EX_T) ((char *)prBss + prBss->u4Length);
  1768. }
  1769. /* Update valid data length for caller function and upper layer
  1770. * applications.
  1771. */
  1772. prData->length = (pcValidEntryEnd - pcExtra);
  1773. /* printk(KERN_INFO "[wifi] buf:%d result:%ld\n", pData->length, u4BufLen); */
  1774. /* kalIndicateStatusAndComplete(prGlueInfo, WLAN_STATUS_SCAN_COMPLETE, NULL, 0); */
  1775. error:
  1776. /* free local query buffer */
  1777. if (prList)
  1778. kalMemFree(prList, VIR_MEM_TYPE, u4AllocBufLen);
  1779. return ret;
  1780. } /* wext_get_scan */
  1781. /*----------------------------------------------------------------------------*/
  1782. /*!
  1783. * \brief To set desired network name ESSID.
  1784. *
  1785. * \param[in] prDev Net device requested.
  1786. * \param[in] prIwrInfo NULL.
  1787. * \param[in] prEssid Pointer of iw_point header.
  1788. * \param[in] pcExtra Pointer to buffer srtoring essid string.
  1789. *
  1790. * \retval 0 If netif_carrier_ok.
  1791. * \retval -E2BIG Essid string length is too big.
  1792. * \retval -EINVAL pcExtra is null pointer.
  1793. * \retval -EFAULT Driver fail to set new essid.
  1794. *
  1795. * \note If string length is ok, device will try connecting to the new network.
  1796. */
  1797. /*----------------------------------------------------------------------------*/
  1798. static int
  1799. wext_set_essid(IN struct net_device *prNetDev,
  1800. IN struct iw_request_info *prIwrInfo, IN struct iw_point *prEssid, IN char *pcExtra)
  1801. {
  1802. PARAM_SSID_T rNewSsid;
  1803. UINT_32 cipher;
  1804. ENUM_PARAM_ENCRYPTION_STATUS_T eEncStatus;
  1805. ENUM_PARAM_AUTH_MODE_T eAuthMode;
  1806. P_GLUE_INFO_T prGlueInfo = NULL;
  1807. WLAN_STATUS rStatus = WLAN_STATUS_SUCCESS;
  1808. UINT_32 u4BufLen = 0;
  1809. ASSERT(prNetDev);
  1810. ASSERT(prEssid);
  1811. ASSERT(pcExtra);
  1812. if (FALSE == GLUE_CHK_PR3(prNetDev, prEssid, pcExtra))
  1813. return -EINVAL;
  1814. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prNetDev));
  1815. if (prEssid->length > IW_ESSID_MAX_SIZE)
  1816. return -E2BIG;
  1817. /* set auth mode */
  1818. if (prGlueInfo->rWpaInfo.u4WpaVersion == IW_AUTH_WPA_VERSION_DISABLED) {
  1819. eAuthMode = (prGlueInfo->rWpaInfo.u4AuthAlg == IW_AUTH_ALG_OPEN_SYSTEM) ?
  1820. AUTH_MODE_OPEN : AUTH_MODE_AUTO_SWITCH;
  1821. /* printk(KERN_INFO "IW_AUTH_WPA_VERSION_DISABLED->Param_AuthMode%s\n", */
  1822. /* (eAuthMode == AUTH_MODE_OPEN) ? "Open" : "Shared"); */
  1823. } else {
  1824. /* set auth mode */
  1825. switch (prGlueInfo->rWpaInfo.u4KeyMgmt) {
  1826. case IW_AUTH_KEY_MGMT_802_1X:
  1827. eAuthMode =
  1828. (prGlueInfo->rWpaInfo.u4WpaVersion == IW_AUTH_WPA_VERSION_WPA) ?
  1829. AUTH_MODE_WPA : AUTH_MODE_WPA2;
  1830. /* printk("IW_AUTH_KEY_MGMT_802_1X->AUTH_MODE_WPA%s\n", */
  1831. /* (eAuthMode == AUTH_MODE_WPA) ? "" : "2"); */
  1832. break;
  1833. case IW_AUTH_KEY_MGMT_PSK:
  1834. eAuthMode =
  1835. (prGlueInfo->rWpaInfo.u4WpaVersion == IW_AUTH_WPA_VERSION_WPA) ?
  1836. AUTH_MODE_WPA_PSK : AUTH_MODE_WPA2_PSK;
  1837. /* printk("IW_AUTH_KEY_MGMT_PSK->AUTH_MODE_WPA%sPSK\n", */
  1838. /* (eAuthMode == AUTH_MODE_WPA_PSK) ? "" : "2"); */
  1839. break;
  1840. #if CFG_SUPPORT_WAPI /* Android+ */
  1841. case IW_AUTH_KEY_MGMT_WAPI_PSK:
  1842. break;
  1843. case IW_AUTH_KEY_MGMT_WAPI_CERT:
  1844. break;
  1845. #endif
  1846. /* #if defined (IW_AUTH_KEY_MGMT_WPA_NONE) */
  1847. /* case IW_AUTH_KEY_MGMT_WPA_NONE: */
  1848. /* eAuthMode = AUTH_MODE_WPA_NONE; */
  1849. /* //printk("IW_AUTH_KEY_MGMT_WPA_NONE->AUTH_MODE_WPA_NONE\n"); */
  1850. /* break; */
  1851. /* #endif */
  1852. #if CFG_SUPPORT_802_11W
  1853. case IW_AUTH_KEY_MGMT_802_1X_SHA256:
  1854. eAuthMode = AUTH_MODE_WPA2;
  1855. break;
  1856. case IW_AUTH_KEY_MGMT_PSK_SHA256:
  1857. eAuthMode = AUTH_MODE_WPA2_PSK;
  1858. break;
  1859. #endif
  1860. default:
  1861. /* printk(KERN_INFO DRV_NAME"strange IW_AUTH_KEY_MGMT : %ld set auto switch\n", */
  1862. /* prGlueInfo->rWpaInfo.u4KeyMgmt); */
  1863. eAuthMode = AUTH_MODE_AUTO_SWITCH;
  1864. break;
  1865. }
  1866. }
  1867. rStatus = kalIoctl(prGlueInfo,
  1868. wlanoidSetAuthMode, &eAuthMode, sizeof(eAuthMode), FALSE, FALSE, FALSE, FALSE, &u4BufLen);
  1869. /* set encryption status */
  1870. cipher = prGlueInfo->rWpaInfo.u4CipherGroup | prGlueInfo->rWpaInfo.u4CipherPairwise;
  1871. if (cipher & IW_AUTH_CIPHER_CCMP) {
  1872. /* printk("IW_AUTH_CIPHER_CCMP->ENUM_ENCRYPTION3_ENABLED\n"); */
  1873. eEncStatus = ENUM_ENCRYPTION3_ENABLED;
  1874. } else if (cipher & IW_AUTH_CIPHER_TKIP) {
  1875. /* printk("IW_AUTH_CIPHER_TKIP->ENUM_ENCRYPTION2_ENABLED\n"); */
  1876. eEncStatus = ENUM_ENCRYPTION2_ENABLED;
  1877. } else if (cipher & (IW_AUTH_CIPHER_WEP104 | IW_AUTH_CIPHER_WEP40)) {
  1878. /* printk("IW_AUTH_CIPHER_WEPx->ENUM_ENCRYPTION1_ENABLED\n"); */
  1879. eEncStatus = ENUM_ENCRYPTION1_ENABLED;
  1880. } else if (cipher & IW_AUTH_CIPHER_NONE) {
  1881. /* printk("IW_AUTH_CIPHER_NONE->ENUM_ENCRYPTION_DISABLED\n"); */
  1882. if (prGlueInfo->rWpaInfo.fgPrivacyInvoke)
  1883. eEncStatus = ENUM_ENCRYPTION1_ENABLED;
  1884. else
  1885. eEncStatus = ENUM_ENCRYPTION_DISABLED;
  1886. } else {
  1887. /* printk("unknown IW_AUTH_CIPHER->Param_EncryptionDisabled\n"); */
  1888. eEncStatus = ENUM_ENCRYPTION_DISABLED;
  1889. }
  1890. rStatus = kalIoctl(prGlueInfo,
  1891. wlanoidSetEncryptionStatus,
  1892. &eEncStatus, sizeof(eEncStatus), FALSE, FALSE, FALSE, FALSE, &u4BufLen);
  1893. #if WIRELESS_EXT < 21
  1894. /* GeorgeKuo: a length error bug exists in (WE < 21) cases, kernel before
  1895. ** 2.6.19. Cut the trailing '\0'.
  1896. */
  1897. rNewSsid.u4SsidLen = (prEssid->length) ? prEssid->length - 1 : 0;
  1898. #else
  1899. rNewSsid.u4SsidLen = prEssid->length;
  1900. #endif
  1901. kalMemCopy(rNewSsid.aucSsid, pcExtra, rNewSsid.u4SsidLen);
  1902. /*
  1903. rNewSsid.aucSsid[rNewSsid.u4SsidLen] = '\0';
  1904. printk("set ssid(%lu): %s\n", rNewSsid.u4SsidLen, rNewSsid.aucSsid);
  1905. */
  1906. if (kalIoctl(prGlueInfo,
  1907. wlanoidSetSsid,
  1908. (PVOID)&rNewSsid,
  1909. sizeof(PARAM_SSID_T), FALSE, FALSE, TRUE, FALSE, &u4BufLen) != WLAN_STATUS_SUCCESS) {
  1910. /* printk(KERN_WARNING "Fail to set ssid\n"); */
  1911. return -EFAULT;
  1912. }
  1913. return 0;
  1914. } /* wext_set_essid */
  1915. /*----------------------------------------------------------------------------*/
  1916. /*!
  1917. * \brief To get current network name ESSID.
  1918. *
  1919. * \param[in] prDev Net device requested.
  1920. * \param[in] prIwrInfo NULL.
  1921. * \param[in] prEssid Pointer to iw_point structure containing essid information.
  1922. * \param[out] pcExtra Pointer to buffer srtoring essid string.
  1923. *
  1924. * \retval 0 If netif_carrier_ok.
  1925. * \retval -ENOTCONN Otherwise.
  1926. *
  1927. * \note If netif_carrier_ok, network essid is stored in pcExtra.
  1928. */
  1929. /*----------------------------------------------------------------------------*/
  1930. /* static PARAM_SSID_T ssid; */
  1931. static int
  1932. wext_get_essid(IN struct net_device *prNetDev,
  1933. IN struct iw_request_info *prIwrInfo, IN struct iw_point *prEssid, OUT char *pcExtra)
  1934. {
  1935. /* PARAM_SSID_T ssid; */
  1936. P_PARAM_SSID_T prSsid;
  1937. P_GLUE_INFO_T prGlueInfo = NULL;
  1938. WLAN_STATUS rStatus = WLAN_STATUS_SUCCESS;
  1939. UINT_32 u4BufLen = 0;
  1940. ASSERT(prNetDev);
  1941. ASSERT(prEssid);
  1942. ASSERT(pcExtra);
  1943. if (FALSE == GLUE_CHK_PR3(prNetDev, prEssid, pcExtra))
  1944. return -EINVAL;
  1945. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prNetDev));
  1946. /* if (!netif_carrier_ok(prNetDev)) { */
  1947. /* return -ENOTCONN; */
  1948. /* } */
  1949. prSsid = kalMemAlloc(sizeof(PARAM_SSID_T), VIR_MEM_TYPE);
  1950. if (!prSsid)
  1951. return -ENOMEM;
  1952. rStatus = kalIoctl(prGlueInfo,
  1953. wlanoidQuerySsid, prSsid, sizeof(PARAM_SSID_T), TRUE, FALSE, FALSE, FALSE, &u4BufLen);
  1954. if ((rStatus == WLAN_STATUS_SUCCESS) && (prSsid->u4SsidLen <= MAX_SSID_LEN)) {
  1955. kalMemCopy(pcExtra, prSsid->aucSsid, prSsid->u4SsidLen);
  1956. prEssid->length = prSsid->u4SsidLen;
  1957. prEssid->flags = 1;
  1958. }
  1959. kalMemFree(prSsid, VIR_MEM_TYPE, sizeof(PARAM_SSID_T));
  1960. return rStatus;
  1961. } /* wext_get_essid */
  1962. #if 0
  1963. /*----------------------------------------------------------------------------*/
  1964. /*!
  1965. * \brief To set tx desired bit rate. Three cases here
  1966. * iwconfig wlan0 auto -> Set to origianl supported rate set.
  1967. * iwconfig wlan0 18M -> Imply "fixed" case, set to 18Mbps as desired rate.
  1968. * iwconfig wlan0 18M auto -> Set to auto rate lower and equal to 18Mbps
  1969. *
  1970. * \param[in] prNetDev Pointer to the net_device handler.
  1971. * \param[in] prIwReqInfo Pointer to the Request Info.
  1972. * \param[in] prRate Pointer to the Rate Parameter.
  1973. * \param[in] pcExtra Pointer to the extra buffer.
  1974. *
  1975. * \retval 0 Update desired rate.
  1976. * \retval -EINVAL Wrong parameter
  1977. */
  1978. /*----------------------------------------------------------------------------*/
  1979. int
  1980. wext_set_rate(IN struct net_device *prNetDev,
  1981. IN struct iw_request_info *prIwReqInfo, IN struct iw_param *prRate, IN char *pcExtra)
  1982. {
  1983. PARAM_RATES_EX aucSuppRate = { 0 };
  1984. PARAM_RATES_EX aucNewRate = { 0 };
  1985. UINT_32 u4NewRateLen = 0;
  1986. UINT_32 i;
  1987. P_GLUE_INFO_T prGlueInfo = NULL;
  1988. WLAN_STATUS rStatus = WLAN_STATUS_SUCCESS;
  1989. UINT_32 u4BufLen = 0;
  1990. ASSERT(prNetDev);
  1991. ASSERT(prRate);
  1992. if (FALSE == GLUE_CHK_PR2(prNetDev, prRate))
  1993. return -EINVAL;
  1994. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prNetDev));
  1995. /*
  1996. printk("value = %d, fixed = %d, disable = %d, flags = %d\n",
  1997. prRate->value, prRate->fixed, prRate->disabled, prRate->flags);
  1998. */
  1999. rStatus = wlanQueryInformation(prGlueInfo->prAdapter,
  2000. wlanoidQuerySupportedRates, &aucSuppRate, sizeof(aucSuppRate), &u4BufLen);
  2001. /* Case: AUTO */
  2002. if (prRate->value < 0) {
  2003. if (prRate->fixed == 0) {
  2004. /* iwconfig wlan0 rate auto */
  2005. /* set full supported rate to device */
  2006. /* printk("wlanoidQuerySupportedRates():u4BufLen = %ld\n", u4BufLen); */
  2007. rStatus = wlanSetInformation(prGlueInfo->prAdapter,
  2008. wlanoidSetDesiredRates,
  2009. &aucSuppRate, sizeof(aucSuppRate), &u4BufLen);
  2010. return 0;
  2011. }
  2012. /* iwconfig wlan0 rate fixed */
  2013. /* fix rate to what? DO NOTHING */
  2014. return -EINVAL;
  2015. }
  2016. aucNewRate[0] = prRate->value / 500000; /* In unit of 500k */
  2017. for (i = 0; i < PARAM_MAX_LEN_RATES_EX; i++) {
  2018. /* check the given value is supported */
  2019. if (aucSuppRate[i] == 0)
  2020. break;
  2021. if (aucNewRate[0] == aucSuppRate[i]) {
  2022. u4NewRateLen = 1;
  2023. break;
  2024. }
  2025. }
  2026. if (u4NewRateLen == 0) {
  2027. /* the given value is not supported */
  2028. /* return error or use given rate as upper bound? */
  2029. return -EINVAL;
  2030. }
  2031. if (prRate->fixed == 0) {
  2032. /* add all rates lower than desired rate */
  2033. for (i = 0; i < PARAM_MAX_LEN_RATES_EX; ++i) {
  2034. if (aucSuppRate[i] == 0)
  2035. break;
  2036. if (aucSuppRate[i] < aucNewRate[0])
  2037. aucNewRate[u4NewRateLen++] = aucSuppRate[i];
  2038. }
  2039. }
  2040. rStatus = wlanSetInformation(prGlueInfo->prAdapter,
  2041. wlanoidSetDesiredRates, &aucNewRate, sizeof(aucNewRate), &u4BufLen);
  2042. return 0;
  2043. } /* wext_set_rate */
  2044. #endif
  2045. /*----------------------------------------------------------------------------*/
  2046. /*!
  2047. * \brief To get current tx bit rate.
  2048. *
  2049. * \param[in] prDev Net device requested.
  2050. * \param[in] prIwrInfo NULL.
  2051. * \param[out] prRate Pointer to iw_param structure to store current tx rate.
  2052. * \param[in] pcExtra NULL.
  2053. *
  2054. * \retval 0 If netif_carrier_ok.
  2055. * \retval -ENOTCONN Otherwise.
  2056. *
  2057. * \note If netif_carrier_ok, current tx rate is stored in pRate.
  2058. */
  2059. /*----------------------------------------------------------------------------*/
  2060. static int
  2061. wext_get_rate(IN struct net_device *prNetDev,
  2062. IN struct iw_request_info *prIwrInfo, OUT struct iw_param *prRate, IN char *pcExtra)
  2063. {
  2064. P_GLUE_INFO_T prGlueInfo = NULL;
  2065. WLAN_STATUS rStatus = WLAN_STATUS_SUCCESS;
  2066. UINT_32 u4BufLen = 0;
  2067. UINT_32 u4Rate = 0;
  2068. ASSERT(prNetDev);
  2069. ASSERT(prRate);
  2070. if (FALSE == GLUE_CHK_PR2(prNetDev, prRate))
  2071. return -EINVAL;
  2072. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prNetDev));
  2073. if (!netif_carrier_ok(prNetDev))
  2074. return -ENOTCONN;
  2075. rStatus = kalIoctl(prGlueInfo,
  2076. wlanoidQueryLinkSpeed, &u4Rate, sizeof(u4Rate), TRUE, FALSE, FALSE, FALSE, &u4BufLen);
  2077. if (rStatus != WLAN_STATUS_SUCCESS)
  2078. return -EFAULT;
  2079. prRate->value = u4Rate * 100; /* u4Rate is in unit of 100bps */
  2080. prRate->fixed = 0;
  2081. return 0;
  2082. } /* wext_get_rate */
  2083. /*----------------------------------------------------------------------------*/
  2084. /*!
  2085. * \brief To set RTS/CTS theshold.
  2086. *
  2087. * \param[in] prDev Net device requested.
  2088. * \param[in] prIwrInfo NULL.
  2089. * \param[in] prRts Pointer to iw_param structure containing rts threshold.
  2090. * \param[in] pcExtra NULL.
  2091. *
  2092. * \retval 0 For success.
  2093. * \retval -EINVAL Given value is out of range.
  2094. *
  2095. * \note If given value is valid, device will follow the new setting.
  2096. */
  2097. /*----------------------------------------------------------------------------*/
  2098. static int
  2099. wext_set_rts(IN struct net_device *prNetDev,
  2100. IN struct iw_request_info *prIwrInfo, IN struct iw_param *prRts, IN char *pcExtra)
  2101. {
  2102. PARAM_RTS_THRESHOLD u4RtsThresh;
  2103. P_GLUE_INFO_T prGlueInfo = NULL;
  2104. WLAN_STATUS rStatus = WLAN_STATUS_SUCCESS;
  2105. UINT_32 u4BufLen = 0;
  2106. ASSERT(prNetDev);
  2107. ASSERT(prRts);
  2108. if (FALSE == GLUE_CHK_PR2(prNetDev, prRts))
  2109. return -EINVAL;
  2110. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prNetDev));
  2111. if (prRts->disabled == 1)
  2112. u4RtsThresh = 2347;
  2113. else if (prRts->value < 0 || prRts->value > 2347)
  2114. return -EINVAL;
  2115. u4RtsThresh = (PARAM_RTS_THRESHOLD) prRts->value;
  2116. rStatus = kalIoctl(prGlueInfo,
  2117. wlanoidSetRtsThreshold,
  2118. &u4RtsThresh, sizeof(u4RtsThresh), FALSE, FALSE, FALSE, FALSE, &u4BufLen);
  2119. prRts->value = (typeof(prRts->value)) u4RtsThresh;
  2120. prRts->disabled = (prRts->value > 2347) ? 1 : 0;
  2121. prRts->fixed = 1;
  2122. return 0;
  2123. } /* wext_set_rts */
  2124. /*----------------------------------------------------------------------------*/
  2125. /*!
  2126. * \brief To get RTS/CTS theshold.
  2127. *
  2128. * \param[in] prDev Net device requested.
  2129. * \param[in] prIwrInfo NULL.
  2130. * \param[out] prRts Pointer to iw_param structure containing rts threshold.
  2131. * \param[in] pcExtra NULL.
  2132. *
  2133. * \retval 0 Success.
  2134. *
  2135. * \note RTS threshold is stored in pRts.
  2136. */
  2137. /*----------------------------------------------------------------------------*/
  2138. static int
  2139. wext_get_rts(IN struct net_device *prNetDev,
  2140. IN struct iw_request_info *prIwrInfo, OUT struct iw_param *prRts, IN char *pcExtra)
  2141. {
  2142. PARAM_RTS_THRESHOLD u4RtsThresh = 0;
  2143. P_GLUE_INFO_T prGlueInfo = NULL;
  2144. WLAN_STATUS rStatus = WLAN_STATUS_SUCCESS;
  2145. UINT_32 u4BufLen = 0;
  2146. ASSERT(prNetDev);
  2147. ASSERT(prRts);
  2148. if (FALSE == GLUE_CHK_PR2(prNetDev, prRts))
  2149. return -EINVAL;
  2150. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prNetDev));
  2151. rStatus = kalIoctl(prGlueInfo,
  2152. wlanoidQueryRtsThreshold,
  2153. &u4RtsThresh, sizeof(u4RtsThresh), TRUE, FALSE, FALSE, FALSE, &u4BufLen);
  2154. prRts->value = (typeof(prRts->value)) u4RtsThresh;
  2155. prRts->disabled = (prRts->value > 2347 || prRts->value < 0) ? 1 : 0;
  2156. prRts->fixed = 1;
  2157. return 0;
  2158. } /* wext_get_rts */
  2159. /*----------------------------------------------------------------------------*/
  2160. /*!
  2161. * \brief To get fragmentation threshold.
  2162. *
  2163. * \param[in] prDev Net device requested.
  2164. * \param[in] prIwrInfo NULL.
  2165. * \param[out] prFrag Pointer to iw_param structure containing frag threshold.
  2166. * \param[in] pcExtra NULL.
  2167. *
  2168. * \retval 0 Success.
  2169. *
  2170. * \note RTS threshold is stored in pFrag. Fragmentation is disabled.
  2171. */
  2172. /*----------------------------------------------------------------------------*/
  2173. static int
  2174. wext_get_frag(IN struct net_device *prNetDev,
  2175. IN struct iw_request_info *prIwrInfo, OUT struct iw_param *prFrag, IN char *pcExtra)
  2176. {
  2177. ASSERT(prFrag);
  2178. prFrag->value = 2346;
  2179. prFrag->fixed = 1;
  2180. prFrag->disabled = 1;
  2181. return 0;
  2182. } /* wext_get_frag */
  2183. #if 1
  2184. /*----------------------------------------------------------------------------*/
  2185. /*!
  2186. * \brief To set TX power, or enable/disable the radio.
  2187. *
  2188. * \param[in] prDev Net device requested.
  2189. * \param[in] prIwrInfo NULL.
  2190. * \param[in] prTxPow Pointer to iw_param structure containing tx power setting.
  2191. * \param[in] pcExtra NULL.
  2192. *
  2193. * \retval 0 Success.
  2194. *
  2195. * \note Tx power is stored in pTxPow. iwconfig wlan0 txpow on/off are used
  2196. * to enable/disable the radio.
  2197. */
  2198. /*----------------------------------------------------------------------------*/
  2199. static int
  2200. wext_set_txpow(IN struct net_device *prNetDev,
  2201. IN struct iw_request_info *prIwrInfo, IN struct iw_param *prTxPow, IN char *pcExtra)
  2202. {
  2203. int ret = 0;
  2204. /* PARAM_DEVICE_POWER_STATE ePowerState; */
  2205. ENUM_ACPI_STATE_T ePowerState;
  2206. P_GLUE_INFO_T prGlueInfo = NULL;
  2207. WLAN_STATUS rStatus = WLAN_STATUS_SUCCESS;
  2208. UINT_32 u4BufLen = 0;
  2209. ASSERT(prNetDev);
  2210. ASSERT(prTxPow);
  2211. if (FALSE == GLUE_CHK_PR2(prNetDev, prTxPow))
  2212. return -EINVAL;
  2213. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prNetDev));
  2214. if (prTxPow->disabled) {
  2215. /* <1> disconnect */
  2216. rStatus = kalIoctl(prGlueInfo, wlanoidSetDisassociate, NULL, 0, FALSE, FALSE, TRUE, FALSE, &u4BufLen);
  2217. if (rStatus != WLAN_STATUS_SUCCESS)
  2218. DBGLOG(REQ, ERROR, "######set disassoc failed\n");
  2219. else
  2220. DBGLOG(REQ, TRACE, "######set assoc ok\n");
  2221. /* <2> mark to power state flag */
  2222. ePowerState = ACPI_STATE_D0;
  2223. DBGLOG(REQ, INFO, "set to acpi d3(0)\n");
  2224. wlanSetAcpiState(prGlueInfo->prAdapter, ePowerState);
  2225. } else {
  2226. ePowerState = ACPI_STATE_D0;
  2227. DBGLOG(REQ, INFO, "set to acpi d0\n");
  2228. wlanSetAcpiState(prGlueInfo->prAdapter, ePowerState);
  2229. }
  2230. prGlueInfo->ePowerState = ePowerState;
  2231. return ret;
  2232. } /* wext_set_txpow */
  2233. #endif
  2234. /*----------------------------------------------------------------------------*/
  2235. /*!
  2236. * \brief To get TX power.
  2237. *
  2238. * \param[in] prDev Net device requested.
  2239. * \param[in] prIwrInfo NULL.
  2240. * \param[out] prTxPow Pointer to iw_param structure containing tx power setting.
  2241. * \param[in] pcExtra NULL.
  2242. *
  2243. * \retval 0 Success.
  2244. *
  2245. * \note Tx power is stored in pTxPow.
  2246. */
  2247. /*----------------------------------------------------------------------------*/
  2248. static int
  2249. wext_get_txpow(IN struct net_device *prNetDev,
  2250. IN struct iw_request_info *prIwrInfo, OUT struct iw_param *prTxPow, IN char *pcExtra)
  2251. {
  2252. /* PARAM_DEVICE_POWER_STATE ePowerState; */
  2253. P_GLUE_INFO_T prGlueInfo = NULL;
  2254. ASSERT(prNetDev);
  2255. ASSERT(prTxPow);
  2256. if (FALSE == GLUE_CHK_PR2(prNetDev, prTxPow))
  2257. return -EINVAL;
  2258. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prNetDev));
  2259. /* GeorgeKuo: wlanoidQueryAcpiDevicePowerState() reports capability, not
  2260. * current state. Use GLUE_INFO_T to store state.
  2261. */
  2262. /* ePowerState = prGlueInfo->ePowerState; */
  2263. /* TxPow parameters: Fixed at relative 100% */
  2264. #if WIRELESS_EXT < 17
  2265. prTxPow->flags = 0x0002; /* IW_TXPOW_RELATIVE */
  2266. #else
  2267. prTxPow->flags = IW_TXPOW_RELATIVE;
  2268. #endif
  2269. prTxPow->value = 100;
  2270. prTxPow->fixed = 1;
  2271. /* prTxPow->disabled = (ePowerState != ParamDeviceStateD3) ? FALSE : TRUE; */
  2272. prTxPow->disabled = TRUE;
  2273. return 0;
  2274. } /* wext_get_txpow */
  2275. /*----------------------------------------------------------------------------*/
  2276. /*!
  2277. * \brief To get encryption cipher and key.
  2278. *
  2279. * \param[in] prDev Net device requested.
  2280. * \param[in] prIwrInfo NULL.
  2281. * \param[out] prEnc Pointer to iw_point structure containing securiry information.
  2282. * \param[in] pcExtra Buffer to store key content.
  2283. *
  2284. * \retval 0 Success.
  2285. *
  2286. * \note Securiry information is stored in pEnc except key content.
  2287. */
  2288. /*----------------------------------------------------------------------------*/
  2289. static int
  2290. wext_get_encode(IN struct net_device *prNetDev,
  2291. IN struct iw_request_info *prIwrInfo, OUT struct iw_point *prEnc, IN char *pcExtra)
  2292. {
  2293. #if 1
  2294. /* ENUM_ENCRYPTION_STATUS_T eEncMode; */
  2295. ENUM_PARAM_ENCRYPTION_STATUS_T eEncMode = ENUM_WEP_ENABLED;
  2296. P_GLUE_INFO_T prGlueInfo = NULL;
  2297. WLAN_STATUS rStatus = WLAN_STATUS_SUCCESS;
  2298. UINT_32 u4BufLen = 0;
  2299. ASSERT(prNetDev);
  2300. ASSERT(prEnc);
  2301. if (FALSE == GLUE_CHK_PR2(prNetDev, prEnc))
  2302. return -EINVAL;
  2303. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prNetDev));
  2304. rStatus = kalIoctl(prGlueInfo,
  2305. wlanoidQueryEncryptionStatus,
  2306. &eEncMode, sizeof(eEncMode), TRUE, FALSE, FALSE, FALSE, &u4BufLen);
  2307. switch (eEncMode) {
  2308. case ENUM_WEP_DISABLED:
  2309. prEnc->flags = IW_ENCODE_DISABLED;
  2310. break;
  2311. case ENUM_WEP_ENABLED:
  2312. prEnc->flags = IW_ENCODE_ENABLED;
  2313. break;
  2314. case ENUM_WEP_KEY_ABSENT:
  2315. prEnc->flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
  2316. break;
  2317. default:
  2318. prEnc->flags = IW_ENCODE_ENABLED;
  2319. break;
  2320. }
  2321. /* Cipher, Key Content, Key ID can't be queried */
  2322. prEnc->flags |= IW_ENCODE_NOKEY;
  2323. #endif
  2324. return 0;
  2325. } /* wext_get_encode */
  2326. /*----------------------------------------------------------------------------*/
  2327. /*!
  2328. * \brief To set encryption cipher and key.
  2329. *
  2330. * \param[in] prDev Net device requested.
  2331. * \param[in] prIwrInfo NULL.
  2332. * \param[in] prEnc Pointer to iw_point structure containing securiry information.
  2333. * \param[in] pcExtra Pointer to key string buffer.
  2334. *
  2335. * \retval 0 Success.
  2336. * \retval -EINVAL Key ID error for WEP.
  2337. * \retval -EFAULT Setting parameters to driver fail.
  2338. * \retval -EOPNOTSUPP Key size not supported.
  2339. *
  2340. * \note Securiry information is stored in pEnc.
  2341. */
  2342. /*----------------------------------------------------------------------------*/
  2343. static UINT_8 wepBuf[48];
  2344. static int
  2345. wext_set_encode(IN struct net_device *prNetDev,
  2346. IN struct iw_request_info *prIwrInfo, IN struct iw_point *prEnc, IN char *pcExtra)
  2347. {
  2348. #if 1
  2349. ENUM_PARAM_ENCRYPTION_STATUS_T eEncStatus;
  2350. ENUM_PARAM_AUTH_MODE_T eAuthMode;
  2351. /* UINT_8 wepBuf[48]; */
  2352. P_PARAM_WEP_T prWepKey = (P_PARAM_WEP_T) wepBuf;
  2353. P_GLUE_INFO_T prGlueInfo = NULL;
  2354. WLAN_STATUS rStatus = WLAN_STATUS_SUCCESS;
  2355. UINT_32 u4BufLen = 0;
  2356. ASSERT(prNetDev);
  2357. ASSERT(prEnc);
  2358. ASSERT(pcExtra);
  2359. if (FALSE == GLUE_CHK_PR3(prNetDev, prEnc, pcExtra))
  2360. return -EINVAL;
  2361. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prNetDev));
  2362. /* reset to default mode */
  2363. prGlueInfo->rWpaInfo.u4WpaVersion = IW_AUTH_WPA_VERSION_DISABLED;
  2364. prGlueInfo->rWpaInfo.u4KeyMgmt = 0;
  2365. prGlueInfo->rWpaInfo.u4CipherPairwise = IW_AUTH_CIPHER_NONE;
  2366. prGlueInfo->rWpaInfo.u4CipherGroup = IW_AUTH_CIPHER_NONE;
  2367. prGlueInfo->rWpaInfo.u4AuthAlg = IW_AUTH_ALG_OPEN_SYSTEM;
  2368. #if CFG_SUPPORT_802_11W
  2369. prGlueInfo->rWpaInfo.u4Mfp = IW_AUTH_MFP_DISABLED;
  2370. #endif
  2371. /* iwconfig wlan0 key off */
  2372. if ((prEnc->flags & IW_ENCODE_MODE) == IW_ENCODE_DISABLED) {
  2373. eAuthMode = AUTH_MODE_OPEN;
  2374. rStatus = kalIoctl(prGlueInfo,
  2375. wlanoidSetAuthMode,
  2376. &eAuthMode, sizeof(eAuthMode), FALSE, FALSE, FALSE, FALSE, &u4BufLen);
  2377. eEncStatus = ENUM_ENCRYPTION_DISABLED;
  2378. rStatus = kalIoctl(prGlueInfo,
  2379. wlanoidSetEncryptionStatus,
  2380. &eEncStatus, sizeof(eEncStatus), FALSE, FALSE, FALSE, FALSE, &u4BufLen);
  2381. return 0;
  2382. }
  2383. /* iwconfig wlan0 key 0123456789 */
  2384. /* iwconfig wlan0 key s:abcde */
  2385. /* iwconfig wlan0 key 0123456789 [1] */
  2386. /* iwconfig wlan0 key 01234567890123456789012345 [1] */
  2387. /* check key size for WEP */
  2388. if (prEnc->length == 5 || prEnc->length == 13 || prEnc->length == 16) {
  2389. /* prepare PARAM_WEP key structure */
  2390. prWepKey->u4KeyIndex = (prEnc->flags & IW_ENCODE_INDEX) ? (prEnc->flags & IW_ENCODE_INDEX) - 1 : 0;
  2391. if (prWepKey->u4KeyIndex > 3) {
  2392. /* key id is out of range */
  2393. return -EINVAL;
  2394. }
  2395. prWepKey->u4KeyIndex |= 0x80000000;
  2396. prWepKey->u4Length = 12 + prEnc->length;
  2397. prWepKey->u4KeyLength = prEnc->length;
  2398. kalMemCopy(prWepKey->aucKeyMaterial, pcExtra, prEnc->length);
  2399. rStatus = kalIoctl(prGlueInfo,
  2400. wlanoidSetAddWep,
  2401. prWepKey, prWepKey->u4Length, FALSE, FALSE, TRUE, FALSE, &u4BufLen);
  2402. if (rStatus != WLAN_STATUS_SUCCESS) {
  2403. DBGLOG(REQ, ERROR, "wlanoidSetAddWep fail 0x%x\n", rStatus);
  2404. return -EFAULT;
  2405. }
  2406. /* change to auto switch */
  2407. prGlueInfo->rWpaInfo.u4AuthAlg = IW_AUTH_ALG_SHARED_KEY | IW_AUTH_ALG_OPEN_SYSTEM;
  2408. eAuthMode = AUTH_MODE_AUTO_SWITCH;
  2409. rStatus = kalIoctl(prGlueInfo,
  2410. wlanoidSetAuthMode,
  2411. &eAuthMode, sizeof(eAuthMode), FALSE, FALSE, FALSE, FALSE, &u4BufLen);
  2412. if (rStatus != WLAN_STATUS_SUCCESS) {
  2413. /* printk(KERN_INFO DRV_NAME"wlanoidSetAuthMode fail 0x%lx\n", rStatus); */
  2414. return -EFAULT;
  2415. }
  2416. prGlueInfo->rWpaInfo.u4CipherPairwise = IW_AUTH_CIPHER_WEP104 | IW_AUTH_CIPHER_WEP40;
  2417. prGlueInfo->rWpaInfo.u4CipherGroup = IW_AUTH_CIPHER_WEP104 | IW_AUTH_CIPHER_WEP40;
  2418. eEncStatus = ENUM_WEP_ENABLED;
  2419. rStatus = kalIoctl(prGlueInfo,
  2420. wlanoidSetEncryptionStatus,
  2421. &eEncStatus,
  2422. sizeof(ENUM_PARAM_ENCRYPTION_STATUS_T), FALSE, FALSE, FALSE, FALSE, &u4BufLen);
  2423. if (rStatus != WLAN_STATUS_SUCCESS) {
  2424. /* printk(KERN_INFO DRV_NAME"wlanoidSetEncryptionStatus fail 0x%lx\n", rStatus); */
  2425. return -EFAULT;
  2426. }
  2427. return 0;
  2428. }
  2429. #endif
  2430. return -EOPNOTSUPP;
  2431. } /* wext_set_encode */
  2432. /*----------------------------------------------------------------------------*/
  2433. /*!
  2434. * \brief To set power management.
  2435. *
  2436. * \param[in] prDev Net device requested.
  2437. * \param[in] prIwrInfo NULL.
  2438. * \param[in] prPower Pointer to iw_param structure containing tx power setting.
  2439. * \param[in] pcExtra NULL.
  2440. *
  2441. * \retval 0 Success.
  2442. *
  2443. * \note New Power Management Mode is set to driver.
  2444. */
  2445. /*----------------------------------------------------------------------------*/
  2446. static int
  2447. wext_set_power(IN struct net_device *prNetDev,
  2448. IN struct iw_request_info *prIwrInfo, IN struct iw_param *prPower, IN char *pcExtra)
  2449. {
  2450. #if 1
  2451. PARAM_POWER_MODE ePowerMode;
  2452. INT_32 i4PowerValue;
  2453. P_GLUE_INFO_T prGlueInfo = NULL;
  2454. WLAN_STATUS rStatus = WLAN_STATUS_SUCCESS;
  2455. UINT_32 u4BufLen = 0;
  2456. ASSERT(prNetDev);
  2457. ASSERT(prPower);
  2458. if (FALSE == GLUE_CHK_PR2(prNetDev, prPower))
  2459. return -EINVAL;
  2460. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prNetDev));
  2461. /* printk(KERN_INFO "wext_set_power value(%d) disabled(%d) flag(0x%x)\n", */
  2462. /* prPower->value, prPower->disabled, prPower->flags); */
  2463. if (prPower->disabled) {
  2464. ePowerMode = Param_PowerModeCAM;
  2465. } else {
  2466. i4PowerValue = prPower->value;
  2467. #if WIRELESS_EXT < 21
  2468. i4PowerValue /= 1000000;
  2469. #endif
  2470. if (i4PowerValue == 0) {
  2471. ePowerMode = Param_PowerModeCAM;
  2472. } else if (i4PowerValue == 1) {
  2473. ePowerMode = Param_PowerModeMAX_PSP;
  2474. } else if (i4PowerValue == 2) {
  2475. ePowerMode = Param_PowerModeFast_PSP;
  2476. } else {
  2477. DBGLOG(REQ, ERROR, "%s(): unsupported power management mode value = %d.\n",
  2478. __func__, prPower->value);
  2479. return -EINVAL;
  2480. }
  2481. }
  2482. rStatus = kalIoctl(prGlueInfo,
  2483. wlanoidSet802dot11PowerSaveProfile,
  2484. &ePowerMode, sizeof(ePowerMode), FALSE, FALSE, TRUE, FALSE, &u4BufLen);
  2485. if (rStatus != WLAN_STATUS_SUCCESS) {
  2486. /* printk(KERN_INFO DRV_NAME"wlanoidSet802dot11PowerSaveProfile fail 0x%lx\n", rStatus); */
  2487. return -EFAULT;
  2488. }
  2489. #endif
  2490. return 0;
  2491. } /* wext_set_power */
  2492. /*----------------------------------------------------------------------------*/
  2493. /*!
  2494. * \brief To get power management.
  2495. *
  2496. * \param[in] prDev Net device requested.
  2497. * \param[in] prIwrInfo NULL.
  2498. * \param[out] prPower Pointer to iw_param structure containing tx power setting.
  2499. * \param[in] pcExtra NULL.
  2500. *
  2501. * \retval 0 Success.
  2502. *
  2503. * \note Power management mode is stored in pTxPow->value.
  2504. */
  2505. /*----------------------------------------------------------------------------*/
  2506. static int
  2507. wext_get_power(IN struct net_device *prNetDev,
  2508. IN struct iw_request_info *prIwrInfo, OUT struct iw_param *prPower, IN char *pcExtra)
  2509. {
  2510. P_GLUE_INFO_T prGlueInfo = NULL;
  2511. WLAN_STATUS rStatus = WLAN_STATUS_SUCCESS;
  2512. UINT_32 u4BufLen = 0;
  2513. PARAM_POWER_MODE ePowerMode = Param_PowerModeCAM;
  2514. ASSERT(prNetDev);
  2515. ASSERT(prPower);
  2516. if (FALSE == GLUE_CHK_PR2(prNetDev, prPower))
  2517. return -EINVAL;
  2518. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prNetDev));
  2519. #if 0
  2520. #if defined(_HIF_SDIO)
  2521. rStatus = sdio_io_ctrl(prGlueInfo,
  2522. wlanoidQuery802dot11PowerSaveProfile,
  2523. &ePowerMode, sizeof(ePowerMode), TRUE, TRUE, &u4BufLen);
  2524. #else
  2525. rStatus = wlanQueryInformation(prGlueInfo->prAdapter,
  2526. wlanoidQuery802dot11PowerSaveProfile,
  2527. &ePowerMode, sizeof(ePowerMode), &u4BufLen);
  2528. #endif
  2529. #else
  2530. rStatus = wlanQueryInformation(prGlueInfo->prAdapter,
  2531. wlanoidQuery802dot11PowerSaveProfile,
  2532. &ePowerMode, sizeof(ePowerMode), &u4BufLen);
  2533. #endif
  2534. if (rStatus != WLAN_STATUS_SUCCESS)
  2535. return -EFAULT;
  2536. prPower->value = 0;
  2537. prPower->disabled = 1;
  2538. if (Param_PowerModeCAM == ePowerMode) {
  2539. prPower->value = 0;
  2540. prPower->disabled = 1;
  2541. } else if (Param_PowerModeMAX_PSP == ePowerMode) {
  2542. prPower->value = 1;
  2543. prPower->disabled = 0;
  2544. } else if (Param_PowerModeFast_PSP == ePowerMode) {
  2545. prPower->value = 2;
  2546. prPower->disabled = 0;
  2547. }
  2548. prPower->flags = IW_POWER_PERIOD | IW_POWER_RELATIVE;
  2549. #if WIRELESS_EXT < 21
  2550. prPower->value *= 1000000;
  2551. #endif
  2552. /* printk(KERN_INFO "wext_get_power value(%d) disabled(%d) flag(0x%x)\n", */
  2553. /* prPower->value, prPower->disabled, prPower->flags); */
  2554. return 0;
  2555. } /* wext_get_power */
  2556. /*----------------------------------------------------------------------------*/
  2557. /*!
  2558. * \brief To set authentication parameters.
  2559. *
  2560. * \param[in] prDev Net device requested.
  2561. * \param[in] prIwrInfo NULL.
  2562. * \param[in] rpAuth Pointer to iw_param structure containing authentication information.
  2563. * \param[in] pcExtra Pointer to key string buffer.
  2564. *
  2565. * \retval 0 Success.
  2566. * \retval -EINVAL Key ID error for WEP.
  2567. * \retval -EFAULT Setting parameters to driver fail.
  2568. * \retval -EOPNOTSUPP Key size not supported.
  2569. *
  2570. * \note Securiry information is stored in pEnc.
  2571. */
  2572. /*----------------------------------------------------------------------------*/
  2573. static int
  2574. wext_set_auth(IN struct net_device *prNetDev,
  2575. IN struct iw_request_info *prIwrInfo, IN struct iw_param *prAuth, IN char *pcExtra)
  2576. {
  2577. P_GLUE_INFO_T prGlueInfo = NULL;
  2578. ASSERT(prNetDev);
  2579. ASSERT(prAuth);
  2580. if (FALSE == GLUE_CHK_PR2(prNetDev, prAuth))
  2581. return -EINVAL;
  2582. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prNetDev));
  2583. /* Save information to glue info and process later when ssid is set. */
  2584. switch (prAuth->flags & IW_AUTH_INDEX) {
  2585. case IW_AUTH_WPA_VERSION:
  2586. #if CFG_SUPPORT_WAPI
  2587. if (wlanQueryWapiMode(prGlueInfo->prAdapter)) {
  2588. prGlueInfo->rWpaInfo.u4WpaVersion = IW_AUTH_WPA_VERSION_DISABLED;
  2589. prGlueInfo->rWpaInfo.u4AuthAlg = IW_AUTH_ALG_OPEN_SYSTEM;
  2590. } else {
  2591. prGlueInfo->rWpaInfo.u4WpaVersion = prAuth->value;
  2592. }
  2593. #else
  2594. prGlueInfo->rWpaInfo.u4WpaVersion = prAuth->value;
  2595. #endif
  2596. break;
  2597. case IW_AUTH_CIPHER_PAIRWISE:
  2598. prGlueInfo->rWpaInfo.u4CipherPairwise = prAuth->value;
  2599. break;
  2600. case IW_AUTH_CIPHER_GROUP:
  2601. prGlueInfo->rWpaInfo.u4CipherGroup = prAuth->value;
  2602. break;
  2603. case IW_AUTH_KEY_MGMT:
  2604. prGlueInfo->rWpaInfo.u4KeyMgmt = prAuth->value;
  2605. #if CFG_SUPPORT_WAPI
  2606. if (prGlueInfo->rWpaInfo.u4KeyMgmt == IW_AUTH_KEY_MGMT_WAPI_PSK ||
  2607. prGlueInfo->rWpaInfo.u4KeyMgmt == IW_AUTH_KEY_MGMT_WAPI_CERT) {
  2608. UINT_32 u4BufLen;
  2609. WLAN_STATUS rStatus;
  2610. rStatus = kalIoctl(prGlueInfo,
  2611. wlanoidSetWapiMode,
  2612. &prAuth->value, sizeof(UINT_32), FALSE, FALSE, TRUE, FALSE, &u4BufLen);
  2613. DBGLOG(REQ, INFO, "IW_AUTH_WAPI_ENABLED :%d\n", prAuth->value);
  2614. }
  2615. #endif
  2616. if (prGlueInfo->rWpaInfo.u4KeyMgmt == IW_AUTH_KEY_MGMT_WPS)
  2617. prGlueInfo->fgWpsActive = TRUE;
  2618. else
  2619. prGlueInfo->fgWpsActive = FALSE;
  2620. break;
  2621. case IW_AUTH_80211_AUTH_ALG:
  2622. prGlueInfo->rWpaInfo.u4AuthAlg = prAuth->value;
  2623. break;
  2624. case IW_AUTH_PRIVACY_INVOKED:
  2625. prGlueInfo->rWpaInfo.fgPrivacyInvoke = prAuth->value;
  2626. break;
  2627. #if CFG_SUPPORT_802_11W
  2628. case IW_AUTH_MFP:
  2629. /* printk("wext_set_auth IW_AUTH_MFP=%d\n", prAuth->value); */
  2630. prGlueInfo->rWpaInfo.u4Mfp = prAuth->value;
  2631. break;
  2632. #endif
  2633. #if CFG_SUPPORT_WAPI
  2634. case IW_AUTH_WAPI_ENABLED:
  2635. {
  2636. UINT_32 u4BufLen;
  2637. WLAN_STATUS rStatus;
  2638. rStatus = kalIoctl(prGlueInfo,
  2639. wlanoidSetWapiMode,
  2640. &prAuth->value, sizeof(UINT_32), FALSE, FALSE, TRUE, FALSE, &u4BufLen);
  2641. }
  2642. DBGLOG(REQ, INFO, "IW_AUTH_WAPI_ENABLED :%d\n", prAuth->value);
  2643. break;
  2644. #endif
  2645. default:
  2646. /*
  2647. printk(KERN_INFO "[wifi] unsupported IW_AUTH_INDEX :%d\n", prAuth->flags);
  2648. */
  2649. break;
  2650. }
  2651. return 0;
  2652. } /* wext_set_auth */
  2653. /*----------------------------------------------------------------------------*/
  2654. /*!
  2655. * \brief To set encryption cipher and key.
  2656. *
  2657. * \param[in] prDev Net device requested.
  2658. * \param[in] prIwrInfo NULL.
  2659. * \param[in] prEnc Pointer to iw_point structure containing securiry information.
  2660. * \param[in] pcExtra Pointer to key string buffer.
  2661. *
  2662. * \retval 0 Success.
  2663. * \retval -EINVAL Key ID error for WEP.
  2664. * \retval -EFAULT Setting parameters to driver fail.
  2665. * \retval -EOPNOTSUPP Key size not supported.
  2666. *
  2667. * \note Securiry information is stored in pEnc.
  2668. */
  2669. /*----------------------------------------------------------------------------*/
  2670. #if CFG_SUPPORT_WAPI
  2671. UINT_8 keyStructBuf[320]; /* add/remove key shared buffer */
  2672. #else
  2673. UINT_8 keyStructBuf[100]; /* add/remove key shared buffer */
  2674. #endif
  2675. static int
  2676. wext_set_encode_ext(IN struct net_device *prNetDev,
  2677. IN struct iw_request_info *prIwrInfo, IN struct iw_point *prEnc, IN char *pcExtra)
  2678. {
  2679. P_PARAM_REMOVE_KEY_T prRemoveKey = (P_PARAM_REMOVE_KEY_T) keyStructBuf;
  2680. P_PARAM_KEY_T prKey = (P_PARAM_KEY_T) keyStructBuf;
  2681. P_PARAM_WEP_T prWepKey = (P_PARAM_WEP_T) wepBuf;
  2682. struct iw_encode_ext *prIWEncExt = (struct iw_encode_ext *)pcExtra;
  2683. ENUM_PARAM_ENCRYPTION_STATUS_T eEncStatus;
  2684. ENUM_PARAM_AUTH_MODE_T eAuthMode;
  2685. /* ENUM_PARAM_OP_MODE_T eOpMode = NET_TYPE_AUTO_SWITCH; */
  2686. #if CFG_SUPPORT_WAPI
  2687. P_PARAM_WPI_KEY_T prWpiKey = (P_PARAM_WPI_KEY_T) keyStructBuf;
  2688. #endif
  2689. P_GLUE_INFO_T prGlueInfo = NULL;
  2690. WLAN_STATUS rStatus = WLAN_STATUS_SUCCESS;
  2691. UINT_32 u4BufLen = 0;
  2692. ASSERT(prNetDev);
  2693. ASSERT(prEnc);
  2694. if (FALSE == GLUE_CHK_PR3(prNetDev, prEnc, pcExtra))
  2695. return -EINVAL;
  2696. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prNetDev));
  2697. memset(keyStructBuf, 0, sizeof(keyStructBuf));
  2698. #if CFG_SUPPORT_WAPI
  2699. if (prIWEncExt->alg == IW_ENCODE_ALG_SMS4) {
  2700. if (prEnc->flags & IW_ENCODE_DISABLED) {
  2701. /* printk(KERN_INFO "[wapi] IW_ENCODE_DISABLED\n"); */
  2702. return 0;
  2703. }
  2704. /* KeyID */
  2705. prWpiKey->ucKeyID = (prEnc->flags & IW_ENCODE_INDEX);
  2706. prWpiKey->ucKeyID--;
  2707. if (prWpiKey->ucKeyID > 1) {
  2708. /* key id is out of range */
  2709. /* printk(KERN_INFO "[wapi] add key error: key_id invalid %d\n", prWpiKey->ucKeyID); */
  2710. return -EINVAL;
  2711. }
  2712. if (prIWEncExt->key_len != 32) {
  2713. /* key length not valid */
  2714. /* printk(KERN_INFO "[wapi] add key error: key_len invalid %d\n", prIWEncExt->key_len); */
  2715. return -EINVAL;
  2716. }
  2717. /* printk(KERN_INFO "[wapi] %d ext_flags %d\n", prEnc->flags, prIWEncExt->ext_flags); */
  2718. if (prIWEncExt->ext_flags & IW_ENCODE_EXT_GROUP_KEY) {
  2719. prWpiKey->eKeyType = ENUM_WPI_GROUP_KEY;
  2720. prWpiKey->eDirection = ENUM_WPI_RX;
  2721. } else if (prIWEncExt->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) {
  2722. prWpiKey->eKeyType = ENUM_WPI_PAIRWISE_KEY;
  2723. prWpiKey->eDirection = ENUM_WPI_RX_TX;
  2724. }
  2725. /* PN */
  2726. {
  2727. UINT_32 i;
  2728. for (i = 0; i < IW_ENCODE_SEQ_MAX_SIZE; i++)
  2729. prWpiKey->aucPN[i] = prIWEncExt->tx_seq[i];
  2730. for (i = 0; i < IW_ENCODE_SEQ_MAX_SIZE; i++)
  2731. prWpiKey->aucPN[IW_ENCODE_SEQ_MAX_SIZE + i] = prIWEncExt->rx_seq[i];
  2732. }
  2733. /* BSSID */
  2734. memcpy(prWpiKey->aucAddrIndex, prIWEncExt->addr.sa_data, 6);
  2735. memcpy(prWpiKey->aucWPIEK, prIWEncExt->key, 16);
  2736. prWpiKey->u4LenWPIEK = 16;
  2737. memcpy(prWpiKey->aucWPICK, &prIWEncExt->key[16], 16);
  2738. prWpiKey->u4LenWPICK = 16;
  2739. rStatus = kalIoctl(prGlueInfo,
  2740. wlanoidSetWapiKey,
  2741. prWpiKey, sizeof(PARAM_WPI_KEY_T), FALSE, FALSE, TRUE, FALSE, &u4BufLen);
  2742. if (rStatus != WLAN_STATUS_SUCCESS) {
  2743. /* Do nothing */
  2744. /* printk(KERN_INFO "[wapi] add key error:%lx\n", rStatus); */
  2745. }
  2746. } else
  2747. #endif
  2748. {
  2749. if ((prEnc->flags & IW_ENCODE_MODE) == IW_ENCODE_DISABLED) {
  2750. prRemoveKey->u4Length = sizeof(*prRemoveKey);
  2751. memcpy(prRemoveKey->arBSSID, prIWEncExt->addr.sa_data, 6);
  2752. /*
  2753. printk("IW_ENCODE_DISABLED: ID:%d, Addr:[ %pM ]\n",
  2754. prRemoveKey->KeyIndex, prRemoveKey->BSSID);
  2755. */
  2756. rStatus = kalIoctl(prGlueInfo,
  2757. wlanoidSetRemoveKey,
  2758. prRemoveKey, prRemoveKey->u4Length, FALSE, FALSE, TRUE, FALSE, &u4BufLen);
  2759. if (rStatus != WLAN_STATUS_SUCCESS)
  2760. DBGLOG(REQ, INFO, "remove key error:%x\n", rStatus);
  2761. return 0;
  2762. }
  2763. /* return 0; */
  2764. /* printk ("alg %x\n", prIWEncExt->alg); */
  2765. switch (prIWEncExt->alg) {
  2766. case IW_ENCODE_ALG_NONE:
  2767. break;
  2768. case IW_ENCODE_ALG_WEP:
  2769. /* iwconfig wlan0 key 0123456789 */
  2770. /* iwconfig wlan0 key s:abcde */
  2771. /* iwconfig wlan0 key 0123456789 [1] */
  2772. /* iwconfig wlan0 key 01234567890123456789012345 [1] */
  2773. /* check key size for WEP */
  2774. if (prIWEncExt->key_len == 5 || prIWEncExt->key_len == 13 || prIWEncExt->key_len == 16) {
  2775. /* prepare PARAM_WEP key structure */
  2776. prWepKey->u4KeyIndex = (prEnc->flags & IW_ENCODE_INDEX) ?
  2777. (prEnc->flags & IW_ENCODE_INDEX) - 1 : 0;
  2778. if (prWepKey->u4KeyIndex > 3) {
  2779. /* key id is out of range */
  2780. return -EINVAL;
  2781. }
  2782. prWepKey->u4KeyIndex |= 0x80000000;
  2783. prWepKey->u4Length = 12 + prIWEncExt->key_len;
  2784. prWepKey->u4KeyLength = prIWEncExt->key_len;
  2785. /* kalMemCopy(prWepKey->aucKeyMaterial, pcExtra, prIWEncExt->key_len); */
  2786. kalMemCopy(prWepKey->aucKeyMaterial, prIWEncExt->key, prIWEncExt->key_len);
  2787. rStatus = kalIoctl(prGlueInfo,
  2788. wlanoidSetAddWep,
  2789. prWepKey, prWepKey->u4Length, FALSE, FALSE, TRUE, FALSE, &u4BufLen);
  2790. if (rStatus != WLAN_STATUS_SUCCESS) {
  2791. DBGLOG(REQ, ERROR, "wlanoidSetAddWep fail 0x%x\n", rStatus);
  2792. return -EFAULT;
  2793. }
  2794. /* change to auto switch */
  2795. prGlueInfo->rWpaInfo.u4AuthAlg = IW_AUTH_ALG_SHARED_KEY | IW_AUTH_ALG_OPEN_SYSTEM;
  2796. eAuthMode = AUTH_MODE_AUTO_SWITCH;
  2797. rStatus = kalIoctl(prGlueInfo,
  2798. wlanoidSetAuthMode,
  2799. &eAuthMode,
  2800. sizeof(eAuthMode), FALSE, FALSE, FALSE, FALSE, &u4BufLen);
  2801. if (rStatus != WLAN_STATUS_SUCCESS) {
  2802. DBGLOG(REQ, ERROR, "wlanoidSetAuthMode fail 0x%x\n", rStatus);
  2803. return -EFAULT;
  2804. }
  2805. prGlueInfo->rWpaInfo.u4CipherPairwise = IW_AUTH_CIPHER_WEP104 | IW_AUTH_CIPHER_WEP40;
  2806. prGlueInfo->rWpaInfo.u4CipherGroup = IW_AUTH_CIPHER_WEP104 | IW_AUTH_CIPHER_WEP40;
  2807. eEncStatus = ENUM_WEP_ENABLED;
  2808. rStatus = kalIoctl(prGlueInfo,
  2809. wlanoidSetEncryptionStatus,
  2810. &eEncStatus,
  2811. sizeof(ENUM_PARAM_ENCRYPTION_STATUS_T),
  2812. FALSE, FALSE, FALSE, FALSE, &u4BufLen);
  2813. if (rStatus != WLAN_STATUS_SUCCESS) {
  2814. DBGLOG(REQ, ERROR, "wlanoidSetEncryptionStatus fail 0x%x\n", rStatus);
  2815. return -EFAULT;
  2816. }
  2817. } else {
  2818. DBGLOG(REQ, INFO, "key length %x\n", prIWEncExt->key_len);
  2819. DBGLOG(REQ, INFO, "key error\n");
  2820. }
  2821. break;
  2822. case IW_ENCODE_ALG_TKIP:
  2823. case IW_ENCODE_ALG_CCMP:
  2824. #if CFG_SUPPORT_802_11W
  2825. case IW_ENCODE_ALG_AES_CMAC:
  2826. #endif
  2827. {
  2828. /* KeyID */
  2829. prKey->u4KeyIndex = (prEnc->flags & IW_ENCODE_INDEX) ?
  2830. (prEnc->flags & IW_ENCODE_INDEX) - 1 : 0;
  2831. #if CFG_SUPPORT_802_11W
  2832. if (prKey->u4KeyIndex > 5) {
  2833. #else
  2834. if (prKey->u4KeyIndex > 3) {
  2835. #endif
  2836. DBGLOG(REQ, ERROR, "key index error:0x%x\n", prKey->u4KeyIndex);
  2837. /* key id is out of range */
  2838. return -EINVAL;
  2839. }
  2840. /* bit(31) and bit(30) are shared by pKey and pRemoveKey */
  2841. /* Tx Key Bit(31) */
  2842. if (prIWEncExt->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) {
  2843. prKey->u4KeyIndex |= 0x1UL << 31;
  2844. /* Code style */
  2845. }
  2846. /* Pairwise Key Bit(30) */
  2847. if (prIWEncExt->ext_flags & IW_ENCODE_EXT_GROUP_KEY) {
  2848. /* Do nothing */
  2849. /* group key */
  2850. } else {
  2851. /* pairwise key */
  2852. prKey->u4KeyIndex |= 0x1UL << 30;
  2853. }
  2854. }
  2855. /* Rx SC Bit(29) */
  2856. if (prIWEncExt->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID) {
  2857. prKey->u4KeyIndex |= 0x1UL << 29;
  2858. memcpy(&prKey->rKeyRSC, prIWEncExt->rx_seq, IW_ENCODE_SEQ_MAX_SIZE);
  2859. }
  2860. /* BSSID */
  2861. memcpy(prKey->arBSSID, prIWEncExt->addr.sa_data, 6);
  2862. /* switch tx/rx MIC key for sta */
  2863. if (prIWEncExt->alg == IW_ENCODE_ALG_TKIP && prIWEncExt->key_len == 32) {
  2864. memcpy(prKey->aucKeyMaterial, prIWEncExt->key, 16);
  2865. memcpy(((PUINT_8) prKey->aucKeyMaterial) + 16, prIWEncExt->key + 24, 8);
  2866. memcpy((prKey->aucKeyMaterial) + 24, prIWEncExt->key + 16, 8);
  2867. } else {
  2868. memcpy(prKey->aucKeyMaterial, prIWEncExt->key, prIWEncExt->key_len);
  2869. }
  2870. prKey->u4KeyLength = prIWEncExt->key_len;
  2871. prKey->u4Length = ((ULONG)&(((P_PARAM_KEY_T) 0)->aucKeyMaterial)) + prKey->u4KeyLength;
  2872. rStatus = kalIoctl(prGlueInfo,
  2873. wlanoidSetAddKey,
  2874. prKey, prKey->u4Length, FALSE, FALSE, TRUE, FALSE, &u4BufLen);
  2875. if (rStatus != WLAN_STATUS_SUCCESS) {
  2876. DBGLOG(REQ, ERROR, "add key error:%x\n", rStatus);
  2877. return -EFAULT;
  2878. }
  2879. break;
  2880. }
  2881. }
  2882. return 0;
  2883. } /* wext_set_encode_ext */
  2884. /*----------------------------------------------------------------------------*/
  2885. /*!
  2886. * \brief Set country code
  2887. *
  2888. * \param[in] prDev Net device requested.
  2889. * \param[in] prIwrInfo NULL.
  2890. * \param[in] pu4Mode Pointer to new operation mode.
  2891. * \param[in] pcExtra NULL.
  2892. *
  2893. * \retval 0 For success.
  2894. * \retval -EOPNOTSUPP If new mode is not supported.
  2895. *
  2896. * \note Device will run in new operation mode if it is valid.
  2897. */
  2898. /*----------------------------------------------------------------------------*/
  2899. static int wext_set_country(IN struct net_device *prNetDev, IN struct iwreq *iwr)
  2900. {
  2901. P_GLUE_INFO_T prGlueInfo;
  2902. WLAN_STATUS rStatus;
  2903. UINT_32 u4BufLen;
  2904. UINT_8 aucCountry[COUNTRY_CODE_LEN];
  2905. ASSERT(prNetDev);
  2906. /* iwr->u.data.pointer should be like "COUNTRY US", "COUNTRY EU"
  2907. * and "COUNTRY JP"
  2908. */
  2909. if (FALSE == GLUE_CHK_PR2(prNetDev, iwr) || !iwr->u.data.pointer || iwr->u.data.length < COUNTRY_CODE_LEN)
  2910. return -EINVAL;
  2911. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prNetDev));
  2912. if (copy_from_user(aucCountry, iwr->u.data.pointer, COUNTRY_CODE_LEN))
  2913. return -EFAULT;
  2914. rStatus = kalIoctl(prGlueInfo,
  2915. wlanoidSetCountryCode,
  2916. &aucCountry[COUNTRY_CODE_LEN-2], 2, FALSE, FALSE, TRUE, FALSE, &u4BufLen);
  2917. wlanUpdateChannelTable(prGlueInfo);
  2918. p2pUpdateChannelTableByDomain(prGlueInfo);
  2919. if (rStatus != WLAN_STATUS_SUCCESS) {
  2920. DBGLOG(REQ, ERROR, "Set country code error: %x\n", rStatus);
  2921. return -EFAULT;
  2922. }
  2923. return 0;
  2924. }
  2925. /*----------------------------------------------------------------------------*/
  2926. /*!
  2927. * \brief ioctl() (Linux Wireless Extensions) routines
  2928. *
  2929. * \param[in] prDev Net device requested.
  2930. * \param[in] ifr The ifreq structure for seeting the wireless extension.
  2931. * \param[in] i4Cmd The wireless extension ioctl command.
  2932. *
  2933. * \retval zero On success.
  2934. * \retval -EOPNOTSUPP If the cmd is not supported.
  2935. * \retval -EFAULT If copy_to_user goes wrong.
  2936. * \retval -EINVAL If any value's out of range.
  2937. *
  2938. * \note
  2939. */
  2940. /*----------------------------------------------------------------------------*/
  2941. int wext_support_ioctl(IN struct net_device *prDev, IN struct ifreq *prIfReq, IN int i4Cmd)
  2942. {
  2943. /* prIfReq is verified in the caller function wlanDoIOCTL() */
  2944. struct iwreq *iwr = (struct iwreq *)prIfReq;
  2945. struct iw_request_info rIwReqInfo;
  2946. int ret = 0;
  2947. char *prExtraBuf = NULL;
  2948. UINT_32 u4ExtraSize = 0;
  2949. P_GLUE_INFO_T prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prDev));
  2950. WLAN_STATUS rStatus;
  2951. UINT_32 u4BufLen;
  2952. P_PARAM_PMKID_T prPmkid;
  2953. struct iw_scan_req *prIwScanReq = NULL;
  2954. /* prDev is verified in the caller function wlanDoIOCTL() */
  2955. /* printk("%d CMD:0x%x\n", jiffies_to_msecs(jiffies), i4Cmd); */
  2956. /* Prepare the call */
  2957. rIwReqInfo.cmd = (__u16) i4Cmd;
  2958. rIwReqInfo.flags = 0;
  2959. switch (i4Cmd) {
  2960. case SIOCGIWNAME: /* 0x8B01, get wireless protocol name */
  2961. ret = wext_get_name(prDev, &rIwReqInfo, (char *)&iwr->u.name, NULL);
  2962. break;
  2963. /* case SIOCSIWNWID: 0x8B02, deprecated */
  2964. /* case SIOCGIWNWID: 0x8B03, deprecated */
  2965. case SIOCSIWFREQ: /* 0x8B04, set channel */
  2966. ret = wext_set_freq(prDev, NULL, &iwr->u.freq, NULL);
  2967. break;
  2968. case SIOCGIWFREQ: /* 0x8B05, get channel */
  2969. ret = wext_get_freq(prDev, NULL, &iwr->u.freq, NULL);
  2970. break;
  2971. case SIOCSIWMODE: /* 0x8B06, set operation mode */
  2972. ret = wext_set_mode(prDev, NULL, &iwr->u.mode, NULL);
  2973. /* ret = 0; */
  2974. break;
  2975. case SIOCGIWMODE: /* 0x8B07, get operation mode */
  2976. ret = wext_get_mode(prDev, NULL, &iwr->u.mode, NULL);
  2977. break;
  2978. /* case SIOCSIWSENS: 0x8B08, unsupported */
  2979. /* case SIOCGIWSENS: 0x8B09, unsupported */
  2980. /* case SIOCSIWRANGE: 0x8B0A, unused */
  2981. case SIOCGIWRANGE: /* 0x8B0B, get range of parameters */
  2982. if (iwr->u.data.pointer != NULL) {
  2983. /* Buffer size should be large enough */
  2984. if (iwr->u.data.length < sizeof(struct iw_range)) {
  2985. ret = -E2BIG;
  2986. break;
  2987. }
  2988. prExtraBuf = kalMemAlloc(sizeof(struct iw_range), VIR_MEM_TYPE);
  2989. if (!prExtraBuf) {
  2990. ret = -ENOMEM;
  2991. break;
  2992. }
  2993. /* reset all fields */
  2994. memset(prExtraBuf, 0, sizeof(struct iw_range));
  2995. iwr->u.data.length = sizeof(struct iw_range);
  2996. ret = wext_get_range(prDev, NULL, &iwr->u.data, prExtraBuf);
  2997. /* Push up to the caller */
  2998. if (copy_to_user(iwr->u.data.pointer, prExtraBuf, iwr->u.data.length))
  2999. ret = -EFAULT;
  3000. kalMemFree(prExtraBuf, VIR_MEM_TYPE, sizeof(struct iw_range));
  3001. prExtraBuf = NULL;
  3002. } else {
  3003. ret = -EINVAL;
  3004. }
  3005. break;
  3006. case SIOCSIWPRIV: /* 0x8B0C, Country */
  3007. ret = wext_set_country(prDev, iwr);
  3008. break;
  3009. /* case SIOCGIWPRIV: 0x8B0D, handled in wlan_do_ioctl() */
  3010. /* caes SIOCSIWSTATS: 0x8B0E, unused */
  3011. /* case SIOCGIWSTATS:
  3012. get statistics, intercepted by wireless_process_ioctl() in wireless.c,
  3013. redirected to dev_iwstats(), dev->get_wireless_stats().
  3014. */
  3015. /* case SIOCSIWSPY: 0x8B10, unsupported */
  3016. /* case SIOCGIWSPY: 0x8B11, unsupported */
  3017. /* case SIOCSIWTHRSPY: 0x8B12, unsupported */
  3018. /* case SIOCGIWTHRSPY: 0x8B13, unsupported */
  3019. case SIOCSIWAP: /* 0x8B14, set access point MAC addresses (BSSID) */
  3020. if (iwr->u.ap_addr.sa_data[0] == 0 &&
  3021. iwr->u.ap_addr.sa_data[1] == 0 &&
  3022. iwr->u.ap_addr.sa_data[2] == 0 &&
  3023. iwr->u.ap_addr.sa_data[3] == 0 &&
  3024. iwr->u.ap_addr.sa_data[4] == 0 && iwr->u.ap_addr.sa_data[5] == 0) {
  3025. /* WPA Supplicant will set 000000000000 in
  3026. ** wpa_driver_wext_deinit(), do nothing here or disassoc again?
  3027. */
  3028. ret = 0;
  3029. break;
  3030. }
  3031. ret = wext_set_ap(prDev, NULL, &iwr->u.ap_addr, NULL);
  3032. break;
  3033. case SIOCGIWAP: /* 0x8B15, get access point MAC addresses (BSSID) */
  3034. ret = wext_get_ap(prDev, NULL, &iwr->u.ap_addr, NULL);
  3035. break;
  3036. case SIOCSIWMLME: /* 0x8B16, request MLME operation */
  3037. /* Fixed length structure */
  3038. if (iwr->u.data.length != sizeof(struct iw_mlme)) {
  3039. DBGLOG(REQ, ERROR, "MLME buffer strange:%d\n", iwr->u.data.length);
  3040. ret = -EINVAL;
  3041. break;
  3042. }
  3043. if (!iwr->u.data.pointer) {
  3044. ret = -EINVAL;
  3045. break;
  3046. }
  3047. prExtraBuf = kalMemAlloc(sizeof(struct iw_mlme), VIR_MEM_TYPE);
  3048. if (!prExtraBuf) {
  3049. ret = -ENOMEM;
  3050. break;
  3051. }
  3052. if (copy_from_user(prExtraBuf, iwr->u.data.pointer, sizeof(struct iw_mlme)))
  3053. ret = -EFAULT;
  3054. else
  3055. ret = wext_set_mlme(prDev, NULL, &(iwr->u.data), prExtraBuf);
  3056. kalMemFree(prExtraBuf, VIR_MEM_TYPE, sizeof(struct iw_mlme));
  3057. prExtraBuf = NULL;
  3058. break;
  3059. /* case SIOCGIWAPLIST: 0x8B17, deprecated */
  3060. case SIOCSIWSCAN: /* 0x8B18, scan request */
  3061. if (iwr->u.data.pointer == NULL)
  3062. ret = wext_set_scan(prDev, NULL, NULL, NULL);
  3063. #if WIRELESS_EXT > 17
  3064. else if (iwr->u.data.length == sizeof(struct iw_scan_req)) {
  3065. prIwScanReq = kalMemAlloc(sizeof(struct iw_scan_req), VIR_MEM_TYPE);
  3066. if (!prIwScanReq) {
  3067. ret = -ENOMEM;
  3068. break;
  3069. }
  3070. if (copy_from_user(prIwScanReq, iwr->u.data.pointer, sizeof(struct iw_scan_req)))
  3071. ret = -EFAULT;
  3072. else {
  3073. if (prIwScanReq->essid_len > IW_ESSID_MAX_SIZE)
  3074. prIwScanReq->essid_len = IW_ESSID_MAX_SIZE;
  3075. ret = wext_set_scan(prDev, NULL, prIwScanReq, &(prIwScanReq->essid[0]));
  3076. }
  3077. kalMemFree(prIwScanReq, VIR_MEM_TYPE, sizeof(struct iw_scan_req));
  3078. prIwScanReq = NULL;
  3079. }
  3080. #endif
  3081. else
  3082. ret = -EINVAL;
  3083. break;
  3084. #if 1
  3085. case SIOCGIWSCAN: /* 0x8B19, get scan results */
  3086. if (!iwr->u.data.pointer || !iwr->u.essid.pointer) {
  3087. ret = -EINVAL;
  3088. break;
  3089. }
  3090. u4ExtraSize = iwr->u.data.length;
  3091. /* allocate the same size of kernel buffer to store scan results. */
  3092. prExtraBuf = kalMemAlloc(u4ExtraSize, VIR_MEM_TYPE);
  3093. if (!prExtraBuf) {
  3094. ret = -ENOMEM;
  3095. break;
  3096. }
  3097. /* iwr->u.data.length may be updated by wext_get_scan() */
  3098. ret = wext_get_scan(prDev, NULL, &iwr->u.data, prExtraBuf);
  3099. if (ret != 0) {
  3100. if (ret == -E2BIG)
  3101. DBGLOG(REQ, WARN, "[wifi] wext_get_scan -E2BIG\n");
  3102. } else {
  3103. /* check updated length is valid */
  3104. ASSERT(iwr->u.data.length <= u4ExtraSize);
  3105. if (iwr->u.data.length > u4ExtraSize) {
  3106. DBGLOG(REQ, INFO, "Updated result length is larger than allocated (%d > %u)\n",
  3107. iwr->u.data.length, u4ExtraSize);
  3108. iwr->u.data.length = u4ExtraSize;
  3109. }
  3110. if (copy_to_user(iwr->u.data.pointer, prExtraBuf, iwr->u.data.length))
  3111. ret = -EFAULT;
  3112. }
  3113. kalMemFree(prExtraBuf, VIR_MEM_TYPE, u4ExtraSize);
  3114. prExtraBuf = NULL;
  3115. break;
  3116. #endif
  3117. #if 1
  3118. case SIOCSIWESSID: /* 0x8B1A, set SSID (network name) */
  3119. u4ExtraSize = iwr->u.essid.length;
  3120. if (u4ExtraSize > IW_ESSID_MAX_SIZE) {
  3121. ret = -E2BIG;
  3122. break;
  3123. }
  3124. if (!iwr->u.essid.pointer) {
  3125. ret = -EINVAL;
  3126. break;
  3127. }
  3128. prExtraBuf = kalMemAlloc(IW_ESSID_MAX_SIZE + 4, VIR_MEM_TYPE);
  3129. if (!prExtraBuf) {
  3130. ret = -ENOMEM;
  3131. break;
  3132. }
  3133. if (copy_from_user(prExtraBuf, iwr->u.essid.pointer, u4ExtraSize)) {
  3134. ret = -EFAULT;
  3135. } else {
  3136. /* Add trailing '\0' for printk */
  3137. /* prExtraBuf[iwr->u.essid.length] = 0; */
  3138. /* printk(KERN_INFO "wext_set_essid: %s (%d)\n", prExtraBuf, iwr->u.essid.length); */
  3139. ret = wext_set_essid(prDev, NULL, &iwr->u.essid, prExtraBuf);
  3140. /* printk ("set essid %d\n", ret); */
  3141. }
  3142. kalMemFree(prExtraBuf, VIR_MEM_TYPE, IW_ESSID_MAX_SIZE + 4);
  3143. prExtraBuf = NULL;
  3144. break;
  3145. #endif
  3146. case SIOCGIWESSID: /* 0x8B1B, get SSID */
  3147. u4ExtraSize = iwr->u.essid.length;
  3148. if (!iwr->u.essid.pointer) {
  3149. ret = -EINVAL;
  3150. break;
  3151. }
  3152. if (u4ExtraSize != IW_ESSID_MAX_SIZE && u4ExtraSize != IW_ESSID_MAX_SIZE + 1) {
  3153. DBGLOG(REQ, ERROR, "[wifi] iwr->u.essid.length:%d too small\n", u4ExtraSize);
  3154. ret = -E2BIG; /* let caller try larger buffer */
  3155. break;
  3156. }
  3157. prExtraBuf = kalMemAlloc(IW_ESSID_MAX_SIZE + 1, VIR_MEM_TYPE);
  3158. if (!prExtraBuf) {
  3159. ret = -ENOMEM;
  3160. break;
  3161. }
  3162. /* iwr->u.essid.length is updated by wext_get_essid() */
  3163. ret = wext_get_essid(prDev, NULL, &iwr->u.essid, prExtraBuf);
  3164. if (ret == 0) {
  3165. if (copy_to_user(iwr->u.essid.pointer, prExtraBuf, iwr->u.essid.length))
  3166. ret = -EFAULT;
  3167. }
  3168. kalMemFree(prExtraBuf, VIR_MEM_TYPE, IW_ESSID_MAX_SIZE + 1);
  3169. prExtraBuf = NULL;
  3170. break;
  3171. /* case SIOCSIWNICKN: 0x8B1C, not supported */
  3172. /* case SIOCGIWNICKN: 0x8B1D, not supported */
  3173. case SIOCSIWRATE: /* 0x8B20, set default bit rate (bps) */
  3174. /* ret = wext_set_rate(prDev, &rIwReqInfo, &iwr->u.bitrate, NULL); */
  3175. break;
  3176. case SIOCGIWRATE: /* 0x8B21, get current bit rate (bps) */
  3177. ret = wext_get_rate(prDev, NULL, &iwr->u.bitrate, NULL);
  3178. break;
  3179. case SIOCSIWRTS: /* 0x8B22, set rts/cts threshold */
  3180. ret = wext_set_rts(prDev, NULL, &iwr->u.rts, NULL);
  3181. break;
  3182. case SIOCGIWRTS: /* 0x8B23, get rts/cts threshold */
  3183. ret = wext_get_rts(prDev, NULL, &iwr->u.rts, NULL);
  3184. break;
  3185. /* case SIOCSIWFRAG: 0x8B24, unsupported */
  3186. case SIOCGIWFRAG: /* 0x8B25, get frag threshold */
  3187. ret = wext_get_frag(prDev, NULL, &iwr->u.frag, NULL);
  3188. break;
  3189. case SIOCSIWTXPOW: /* 0x8B26, set relative tx power (in %) */
  3190. ret = wext_set_txpow(prDev, NULL, &iwr->u.txpower, NULL);
  3191. break;
  3192. case SIOCGIWTXPOW: /* 0x8B27, get relative tx power (in %) */
  3193. ret = wext_get_txpow(prDev, NULL, &iwr->u.txpower, NULL);
  3194. break;
  3195. /* case SIOCSIWRETRY: 0x8B28, unsupported */
  3196. /* case SIOCGIWRETRY: 0x8B29, unsupported */
  3197. #if 1
  3198. case SIOCSIWENCODE: /* 0x8B2A, set encoding token & mode */
  3199. /* Only DISABLED case has NULL pointer and length == 0 */
  3200. u4ExtraSize = iwr->u.encoding.length;
  3201. if (iwr->u.encoding.pointer) {
  3202. if (u4ExtraSize > 16) {
  3203. ret = -E2BIG;
  3204. break;
  3205. }
  3206. prExtraBuf = kalMemAlloc(u4ExtraSize, VIR_MEM_TYPE);
  3207. if (!prExtraBuf) {
  3208. ret = -ENOMEM;
  3209. break;
  3210. }
  3211. if (copy_from_user(prExtraBuf, iwr->u.encoding.pointer, u4ExtraSize))
  3212. ret = -EFAULT;
  3213. } else if (u4ExtraSize != 0) {
  3214. ret = -EINVAL;
  3215. break;
  3216. }
  3217. if (ret == 0)
  3218. ret = wext_set_encode(prDev, NULL, &iwr->u.encoding, prExtraBuf);
  3219. if (prExtraBuf) {
  3220. kalMemFree(prExtraBuf, VIR_MEM_TYPE, u4ExtraSize);
  3221. prExtraBuf = NULL;
  3222. }
  3223. break;
  3224. case SIOCGIWENCODE: /* 0x8B2B, get encoding token & mode */
  3225. /* check pointer */
  3226. ret = wext_get_encode(prDev, NULL, &iwr->u.encoding, NULL);
  3227. break;
  3228. case SIOCSIWPOWER: /* 0x8B2C, set power management */
  3229. ret = wext_set_power(prDev, NULL, &iwr->u.power, NULL);
  3230. break;
  3231. case SIOCGIWPOWER: /* 0x8B2D, get power management */
  3232. ret = wext_get_power(prDev, NULL, &iwr->u.power, NULL);
  3233. break;
  3234. #if WIRELESS_EXT > 17
  3235. case SIOCSIWGENIE: /* 0x8B30, set gen ie */
  3236. if (iwr->u.data.pointer == NULL)
  3237. break;
  3238. if (0 /* wlanQueryWapiMode(prGlueInfo->prAdapter) */)
  3239. break;
  3240. /* Fixed length structure */
  3241. u4ExtraSize = iwr->u.data.length;
  3242. #if CFG_SUPPORT_WAPI
  3243. if (u4ExtraSize > 42 /* The max wapi ie buffer */) {
  3244. ret = -EINVAL;
  3245. break;
  3246. }
  3247. #endif
  3248. if (u4ExtraSize == 0)
  3249. break;
  3250. prExtraBuf = kalMemAlloc(u4ExtraSize, VIR_MEM_TYPE);
  3251. if (!prExtraBuf) {
  3252. ret = -ENOMEM;
  3253. break;
  3254. }
  3255. if (copy_from_user(prExtraBuf, iwr->u.data.pointer, u4ExtraSize)) {
  3256. ret = -EFAULT;
  3257. } else {
  3258. #if CFG_SUPPORT_WAPI
  3259. rStatus = kalIoctl(prGlueInfo,
  3260. wlanoidSetWapiAssocInfo,
  3261. prExtraBuf,
  3262. u4ExtraSize, FALSE, FALSE, TRUE, FALSE, &u4BufLen);
  3263. if (rStatus != WLAN_STATUS_SUCCESS) {
  3264. /* printk(KERN_INFO "[wapi] set wapi assoc info error:%lx\n",
  3265. rStatus); */
  3266. #endif
  3267. #if CFG_SUPPORT_WPS2
  3268. PUINT_8 prDesiredIE = NULL;
  3269. if (wextSrchDesiredWPSIE(prExtraBuf,
  3270. u4ExtraSize,
  3271. 0xDD, (PUINT_8 *) &prDesiredIE)) {
  3272. rStatus = kalIoctl(prGlueInfo,
  3273. wlanoidSetWSCAssocInfo,
  3274. prDesiredIE,
  3275. IE_SIZE(prDesiredIE),
  3276. FALSE,
  3277. FALSE, TRUE, FALSE, &u4BufLen);
  3278. if (rStatus != WLAN_STATUS_SUCCESS) {
  3279. /* printk(KERN_INFO "[WSC] set WSC assoc info
  3280. error:%lx\n", rStatus); */
  3281. }
  3282. }
  3283. #endif
  3284. #if CFG_SUPPORT_WAPI
  3285. }
  3286. #endif
  3287. }
  3288. kalMemFree(prExtraBuf, VIR_MEM_TYPE, u4ExtraSize);
  3289. prExtraBuf = NULL;
  3290. break;
  3291. case SIOCGIWGENIE: /* 0x8B31, get gen ie, unused */
  3292. break;
  3293. #endif
  3294. case SIOCSIWAUTH: /* 0x8B32, set auth mode params */
  3295. ret = wext_set_auth(prDev, NULL, &iwr->u.param, NULL);
  3296. break;
  3297. /* case SIOCGIWAUTH: 0x8B33, unused? */
  3298. case SIOCSIWENCODEEXT: /* 0x8B34, set extended encoding token & mode */
  3299. if (iwr->u.encoding.pointer) {
  3300. u4ExtraSize = iwr->u.encoding.length;
  3301. if (u4ExtraSize > sizeof(struct iw_encode_ext)) {
  3302. ret = -EINVAL;
  3303. break;
  3304. }
  3305. prExtraBuf = kalMemAlloc(u4ExtraSize, VIR_MEM_TYPE);
  3306. if (!prExtraBuf) {
  3307. ret = -ENOMEM;
  3308. break;
  3309. }
  3310. if (copy_from_user(prExtraBuf, iwr->u.encoding.pointer, u4ExtraSize))
  3311. ret = -EFAULT;
  3312. } else if (iwr->u.encoding.length != 0) {
  3313. ret = -EINVAL;
  3314. break;
  3315. }
  3316. if (ret == 0)
  3317. ret = wext_set_encode_ext(prDev, NULL, &iwr->u.encoding, prExtraBuf);
  3318. if (prExtraBuf) {
  3319. kalMemFree(prExtraBuf, VIR_MEM_TYPE, u4ExtraSize);
  3320. prExtraBuf = NULL;
  3321. }
  3322. break;
  3323. /* case SIOCGIWENCODEEXT: 0x8B35, unused? */
  3324. case SIOCSIWPMKSA: /* 0x8B36, pmksa cache operation */
  3325. #if 1
  3326. if (iwr->u.data.pointer) {
  3327. /* Fixed length structure */
  3328. if (iwr->u.data.length != sizeof(struct iw_pmksa)) {
  3329. ret = -EINVAL;
  3330. break;
  3331. }
  3332. u4ExtraSize = sizeof(struct iw_pmksa);
  3333. prExtraBuf = kalMemAlloc(u4ExtraSize, VIR_MEM_TYPE);
  3334. if (!prExtraBuf) {
  3335. ret = -ENOMEM;
  3336. break;
  3337. }
  3338. if (copy_from_user(prExtraBuf, iwr->u.data.pointer, sizeof(struct iw_pmksa))) {
  3339. ret = -EFAULT;
  3340. } else {
  3341. switch (((struct iw_pmksa *)prExtraBuf)->cmd) {
  3342. case IW_PMKSA_ADD:
  3343. /*
  3344. printk(KERN_INFO "IW_PMKSA_ADD [ %pM ]\n",
  3345. (((struct iw_pmksa *)pExtraBuf)->bssid.sa_data));
  3346. */
  3347. prPmkid =
  3348. (P_PARAM_PMKID_T) kalMemAlloc(8 + sizeof(PARAM_BSSID_INFO_T),
  3349. VIR_MEM_TYPE);
  3350. if (!prPmkid) {
  3351. DBGLOG(REQ, ERROR, "Can not alloc memory for IW_PMKSA_ADD\n");
  3352. ret = -ENOMEM;
  3353. break;
  3354. }
  3355. prPmkid->u4Length = 8 + sizeof(PARAM_BSSID_INFO_T);
  3356. prPmkid->u4BSSIDInfoCount = 1;
  3357. kalMemCopy(prPmkid->arBSSIDInfo->arBSSID,
  3358. ((struct iw_pmksa *)prExtraBuf)->bssid.sa_data, 6);
  3359. kalMemCopy(prPmkid->arBSSIDInfo->arPMKID,
  3360. ((struct iw_pmksa *)prExtraBuf)->pmkid, IW_PMKID_LEN);
  3361. rStatus = kalIoctl(prGlueInfo,
  3362. wlanoidSetPmkid,
  3363. prPmkid,
  3364. sizeof(PARAM_PMKID_T),
  3365. FALSE, FALSE, TRUE, FALSE, &u4BufLen);
  3366. if (rStatus != WLAN_STATUS_SUCCESS)
  3367. DBGLOG(REQ, ERROR, "add pmkid error:%x\n", rStatus);
  3368. kalMemFree(prPmkid, VIR_MEM_TYPE, 8 + sizeof(PARAM_BSSID_INFO_T));
  3369. break;
  3370. case IW_PMKSA_REMOVE:
  3371. /*
  3372. printk(KERN_INFO "IW_PMKSA_REMOVE [ %pM ]\n",
  3373. (((struct iw_pmksa *)buf)->bssid.sa_data));
  3374. */
  3375. break;
  3376. case IW_PMKSA_FLUSH:
  3377. /*
  3378. printk(KERN_INFO "IW_PMKSA_FLUSH\n");
  3379. */
  3380. prPmkid = (P_PARAM_PMKID_T) kalMemAlloc(8, VIR_MEM_TYPE);
  3381. if (!prPmkid) {
  3382. DBGLOG(REQ, ERROR,
  3383. "Can not alloc memory for IW_PMKSA_FLUSH\n");
  3384. ret = -ENOMEM;
  3385. break;
  3386. }
  3387. prPmkid->u4Length = 8;
  3388. prPmkid->u4BSSIDInfoCount = 0;
  3389. rStatus = kalIoctl(prGlueInfo,
  3390. wlanoidSetPmkid,
  3391. prPmkid,
  3392. sizeof(PARAM_PMKID_T),
  3393. FALSE, FALSE, TRUE, FALSE, &u4BufLen);
  3394. if (rStatus != WLAN_STATUS_SUCCESS)
  3395. DBGLOG(REQ, ERROR, "flush pmkid error:%x\n", rStatus);
  3396. kalMemFree(prPmkid, VIR_MEM_TYPE, 8);
  3397. break;
  3398. default:
  3399. DBGLOG(REQ, WARN, "UNKNOWN iw_pmksa command:%d\n",
  3400. ((struct iw_pmksa *)prExtraBuf)->cmd);
  3401. ret = -EFAULT;
  3402. break;
  3403. }
  3404. }
  3405. if (prExtraBuf) {
  3406. kalMemFree(prExtraBuf, VIR_MEM_TYPE, u4ExtraSize);
  3407. prExtraBuf = NULL;
  3408. }
  3409. } else if (iwr->u.data.length != 0) {
  3410. ret = -EINVAL;
  3411. break;
  3412. }
  3413. #endif
  3414. break;
  3415. #endif
  3416. default:
  3417. /* printk(KERN_NOTICE "unsupported IOCTL: 0x%x\n", i4Cmd); */
  3418. ret = -EOPNOTSUPP;
  3419. break;
  3420. }
  3421. /* printk("%ld CMD:0x%x ret:%d\n", jiffies_to_msecs(jiffies), i4Cmd, ret); */
  3422. return ret;
  3423. } /* wext_support_ioctl */
  3424. /*----------------------------------------------------------------------------*/
  3425. /*!
  3426. * \brief To send an event (RAW socket pacekt) to user process actively.
  3427. *
  3428. * \param[in] prGlueInfo Glue layer info.
  3429. * \param[in] u4cmd Whcih event command we want to indicate to user process.
  3430. * \param[in] pData Data buffer to be indicated.
  3431. * \param[in] dataLen Available data size in pData.
  3432. *
  3433. * \return (none)
  3434. *
  3435. * \note Event is indicated to upper layer if cmd is supported and data is valid.
  3436. * Using of kernel symbol wireless_send_event(), which is defined in
  3437. * <net/iw_handler.h> after WE-14 (2.4.20).
  3438. */
  3439. /*----------------------------------------------------------------------------*/
  3440. void
  3441. wext_indicate_wext_event(IN P_GLUE_INFO_T prGlueInfo,
  3442. IN unsigned int u4Cmd, IN unsigned char *pucData, IN unsigned int u4dataLen)
  3443. {
  3444. union iwreq_data wrqu;
  3445. unsigned char *pucExtraInfo = NULL;
  3446. #if WIRELESS_EXT >= 15
  3447. unsigned char *pucDesiredIE = NULL;
  3448. unsigned char aucExtraInfoBuf[200];
  3449. #endif
  3450. #if WIRELESS_EXT < 18
  3451. int i;
  3452. #endif
  3453. memset(&wrqu, 0, sizeof(wrqu));
  3454. switch (u4Cmd) {
  3455. case SIOCGIWTXPOW:
  3456. memcpy(&wrqu.power, pucData, u4dataLen);
  3457. break;
  3458. case SIOCGIWSCAN:
  3459. complete_all(&prGlueInfo->rScanComp);
  3460. break;
  3461. case SIOCGIWAP:
  3462. if (pucData)
  3463. ether_addr_copy((u8 *)&(wrqu.ap_addr.sa_data), pucData);
  3464. /*memcpy(&wrqu.ap_addr.sa_data, pucData, ETH_ALEN);*/
  3465. else
  3466. memset(&wrqu.ap_addr.sa_data, 0, ETH_ALEN);
  3467. break;
  3468. case IWEVASSOCREQIE:
  3469. #if WIRELESS_EXT < 15
  3470. /* under WE-15, no suitable Event can be used */
  3471. goto skip_indicate_event;
  3472. #else
  3473. /* do supplicant a favor, parse to the start of WPA/RSN IE */
  3474. if (wextSrchDesiredWPAIE(pucData, u4dataLen, 0x30, &pucDesiredIE)) {
  3475. /* RSN IE found */
  3476. /* Do nothing */
  3477. #if 0
  3478. } else if (wextSrchDesiredWPSIE(pucData, u4dataLen, 0xDD, &pucDesiredIE)) {
  3479. /* WPS IE found */
  3480. /* Do nothing */
  3481. #endif
  3482. } else if (wextSrchDesiredWPAIE(pucData, u4dataLen, 0xDD, &pucDesiredIE)) {
  3483. /* WPA IE found */
  3484. /* Do nothing*/
  3485. #if CFG_SUPPORT_WAPI /* Android+ */
  3486. } else if (wextSrchDesiredWAPIIE(pucData, u4dataLen, &pucDesiredIE)) {
  3487. /* WAPI IE found */
  3488. /* printk("wextSrchDesiredWAPIIE!!\n"); */
  3489. #endif
  3490. } else {
  3491. /* no WPA/RSN IE found, skip this event */
  3492. goto skip_indicate_event;
  3493. }
  3494. #if WIRELESS_EXT < 18
  3495. /* under WE-18, only IWEVCUSTOM can be used */
  3496. u4Cmd = IWEVCUSTOM;
  3497. pucExtraInfo = aucExtraInfoBuf;
  3498. pucExtraInfo += sprintf(pucExtraInfo, "ASSOCINFO(ReqIEs=");
  3499. /* printk(KERN_DEBUG "assoc info buffer size needed:%d\n", infoElemLen * 2 + 17); */
  3500. /* translate binary string to hex string, requirement of IWEVCUSTOM */
  3501. for (i = 0; i < pucDesiredIE[1] + 2; ++i)
  3502. pucExtraInfo += sprintf(pucExtraInfo, "%02x", pucDesiredIE[i]);
  3503. pucExtraInfo = aucExtraInfoBuf;
  3504. wrqu.data.length = 17 + (pucDesiredIE[1] + 2) * 2;
  3505. #else
  3506. /* IWEVASSOCREQIE, indicate binary string */
  3507. pucExtraInfo = pucDesiredIE;
  3508. wrqu.data.length = pucDesiredIE[1] + 2;
  3509. #endif
  3510. #endif /* WIRELESS_EXT < 15 */
  3511. break;
  3512. case IWEVMICHAELMICFAILURE:
  3513. #if WIRELESS_EXT < 15
  3514. /* under WE-15, no suitable Event can be used */
  3515. goto skip_indicate_event;
  3516. #else
  3517. if (pucData) {
  3518. P_PARAM_AUTH_REQUEST_T pAuthReq = (P_PARAM_AUTH_REQUEST_T) pucData;
  3519. /* under WE-18, only IWEVCUSTOM can be used */
  3520. u4Cmd = IWEVCUSTOM;
  3521. pucExtraInfo = aucExtraInfoBuf;
  3522. pucExtraInfo += sprintf(pucExtraInfo, "MLME-MICHAELMICFAILURE.indication ");
  3523. pucExtraInfo += sprintf(pucExtraInfo,
  3524. "%s",
  3525. (pAuthReq->u4Flags == PARAM_AUTH_REQUEST_GROUP_ERROR) ?
  3526. "groupcast " : "unicast ");
  3527. wrqu.data.length = pucExtraInfo - aucExtraInfoBuf;
  3528. pucExtraInfo = aucExtraInfoBuf;
  3529. }
  3530. #endif /* WIRELESS_EXT < 15 */
  3531. break;
  3532. case IWEVPMKIDCAND:
  3533. if (prGlueInfo->rWpaInfo.u4WpaVersion == IW_AUTH_WPA_VERSION_WPA2 &&
  3534. prGlueInfo->rWpaInfo.u4KeyMgmt == IW_AUTH_KEY_MGMT_802_1X) {
  3535. /* only used in WPA2 */
  3536. #if WIRELESS_EXT >= 18
  3537. P_PARAM_PMKID_CANDIDATE_T prPmkidCand = (P_PARAM_PMKID_CANDIDATE_T) pucData;
  3538. struct iw_pmkid_cand rPmkidCand;
  3539. pucExtraInfo = aucExtraInfoBuf;
  3540. rPmkidCand.flags = prPmkidCand->u4Flags;
  3541. rPmkidCand.index = 0;
  3542. rPmkidCand.bssid.sa_family = 0;
  3543. kalMemCopy(rPmkidCand.bssid.sa_data, prPmkidCand->arBSSID, 6);
  3544. kalMemCopy(pucExtraInfo, (PUINT_8) &rPmkidCand, sizeof(struct iw_pmkid_cand));
  3545. wrqu.data.length = sizeof(struct iw_pmkid_cand);
  3546. /* pmkid canadidate list is supported after WE-18 */
  3547. /* indicate struct iw_pmkid_cand */
  3548. #else
  3549. /* printk(KERN_INFO "IWEVPMKIDCAND event skipped, WE < 18\n"); */
  3550. goto skip_indicate_event;
  3551. #endif
  3552. } else {
  3553. /* printk(KERN_INFO "IWEVPMKIDCAND event skipped, NOT WPA2\n"); */
  3554. goto skip_indicate_event;
  3555. }
  3556. break;
  3557. case IWEVCUSTOM:
  3558. u4Cmd = IWEVCUSTOM;
  3559. pucExtraInfo = aucExtraInfoBuf;
  3560. kalMemCopy(pucExtraInfo, pucData, sizeof(PTA_IPC_T));
  3561. wrqu.data.length = sizeof(PTA_IPC_T);
  3562. break;
  3563. default:
  3564. /* printk(KERN_INFO "Unsupported wext event:%x\n", cmd); */
  3565. goto skip_indicate_event;
  3566. }
  3567. /* Send event to user space */
  3568. wireless_send_event(prGlueInfo->prDevHandler, u4Cmd, &wrqu, pucExtraInfo);
  3569. skip_indicate_event:
  3570. return;
  3571. } /* wext_indicate_wext_event */
  3572. /*----------------------------------------------------------------------------*/
  3573. /*!
  3574. * \brief A method of struct net_device, to get the network interface statistical
  3575. * information.
  3576. *
  3577. * Whenever an application needs to get statistics for the interface, this method
  3578. * is called. This happens, for example, when ifconfig or netstat -i is run.
  3579. *
  3580. * \param[in] pDev Pointer to struct net_device.
  3581. *
  3582. * \return net_device_stats buffer pointer.
  3583. *
  3584. */
  3585. /*----------------------------------------------------------------------------*/
  3586. struct iw_statistics *wext_get_wireless_stats(struct net_device *prDev)
  3587. {
  3588. WLAN_STATUS rStatus = WLAN_STATUS_FAILURE;
  3589. P_GLUE_INFO_T prGlueInfo = NULL;
  3590. struct iw_statistics *pStats = NULL;
  3591. INT_32 i4Rssi;
  3592. UINT_32 bufLen = 0;
  3593. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prDev));
  3594. ASSERT(prGlueInfo);
  3595. if (!prGlueInfo)
  3596. goto stat_out;
  3597. pStats = (struct iw_statistics *)(&(prGlueInfo->rIwStats));
  3598. if (!prDev || !netif_carrier_ok(prDev)) {
  3599. /* network not connected */
  3600. goto stat_out;
  3601. }
  3602. rStatus = kalIoctl(prGlueInfo, wlanoidQueryRssi, &i4Rssi, sizeof(i4Rssi), TRUE, TRUE, TRUE, FALSE, &bufLen);
  3603. stat_out:
  3604. return pStats;
  3605. } /* wlan_get_wireless_stats */
  3606. /*----------------------------------------------------------------------------*/
  3607. /*!
  3608. * \brief To report the private supported IOCTLs table to user space.
  3609. *
  3610. * \param[in] prNetDev Net device requested.
  3611. * \param[out] prIfReq Pointer to ifreq structure, content is copied back to
  3612. * user space buffer in gl_iwpriv_table.
  3613. *
  3614. * \retval 0 For success.
  3615. * \retval -E2BIG For user's buffer size is too small.
  3616. * \retval -EFAULT For fail.
  3617. *
  3618. */
  3619. /*----------------------------------------------------------------------------*/
  3620. int wext_get_priv(IN struct net_device *prNetDev, IN struct ifreq *prIfReq)
  3621. {
  3622. /* prIfReq is verified in the caller function wlanDoIOCTL() */
  3623. struct iwreq *prIwReq = (struct iwreq *)prIfReq;
  3624. struct iw_point *prData = (struct iw_point *)&prIwReq->u.data;
  3625. UINT_16 u2BufferSize = 0;
  3626. u2BufferSize = prData->length;
  3627. /* update our private table size */
  3628. prData->length = (__u16) sizeof(rIwPrivTable) / sizeof(struct iw_priv_args);
  3629. if (u2BufferSize < prData->length)
  3630. return -E2BIG;
  3631. if (prData->length) {
  3632. if (copy_to_user(prData->pointer, rIwPrivTable, sizeof(rIwPrivTable)))
  3633. return -EFAULT;
  3634. }
  3635. return 0;
  3636. } /* wext_get_priv */
  3637. #endif /* WIRELESS_EXT */