gl_wext.c 122 KB

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