orinoco.c 156 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032
  1. /* orinoco.c - (formerly known as dldwd_cs.c and orinoco_cs.c)
  2. *
  3. * A driver for Hermes or Prism 2 chipset based PCMCIA wireless
  4. * adaptors, with Lucent/Agere, Intersil or Symbol firmware.
  5. *
  6. * Current maintainers (as of 29 September 2003) are:
  7. * Pavel Roskin <proski AT gnu.org>
  8. * and David Gibson <hermes AT gibson.dropbear.id.au>
  9. *
  10. * (C) Copyright David Gibson, IBM Corporation 2001-2003.
  11. * Copyright (C) 2000 David Gibson, Linuxcare Australia.
  12. * With some help from :
  13. * Copyright (C) 2001 Jean Tourrilhes, HP Labs
  14. * Copyright (C) 2001 Benjamin Herrenschmidt
  15. *
  16. * Based on dummy_cs.c 1.27 2000/06/12 21:27:25
  17. *
  18. * Portions based on wvlan_cs.c 1.0.6, Copyright Andreas Neuhaus <andy
  19. * AT fasta.fh-dortmund.de>
  20. * http://www.stud.fh-dortmund.de/~andy/wvlan/
  21. *
  22. * The contents of this file are subject to the Mozilla Public License
  23. * Version 1.1 (the "License"); you may not use this file except in
  24. * compliance with the License. You may obtain a copy of the License
  25. * at http://www.mozilla.org/MPL/
  26. *
  27. * Software distributed under the License is distributed on an "AS IS"
  28. * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
  29. * the License for the specific language governing rights and
  30. * limitations under the License.
  31. *
  32. * The initial developer of the original code is David A. Hinds
  33. * <dahinds AT users.sourceforge.net>. Portions created by David
  34. * A. Hinds are Copyright (C) 1999 David A. Hinds. All Rights
  35. * Reserved.
  36. *
  37. * Alternatively, the contents of this file may be used under the
  38. * terms of the GNU General Public License version 2 (the "GPL"), in
  39. * which case the provisions of the GPL are applicable instead of the
  40. * above. If you wish to allow the use of your version of this file
  41. * only under the terms of the GPL and not to allow others to use your
  42. * version of this file under the MPL, indicate your decision by
  43. * deleting the provisions above and replace them with the notice and
  44. * other provisions required by the GPL. If you do not delete the
  45. * provisions above, a recipient may use your version of this file
  46. * under either the MPL or the GPL. */
  47. /*
  48. * TODO
  49. * o Handle de-encapsulation within network layer, provide 802.11
  50. * headers (patch from Thomas 'Dent' Mirlacher)
  51. * o Fix possible races in SPY handling.
  52. * o Disconnect wireless extensions from fundamental configuration.
  53. * o (maybe) Software WEP support (patch from Stano Meduna).
  54. * o (maybe) Use multiple Tx buffers - driver handling queue
  55. * rather than firmware.
  56. */
  57. /* Locking and synchronization:
  58. *
  59. * The basic principle is that everything is serialized through a
  60. * single spinlock, priv->lock. The lock is used in user, bh and irq
  61. * context, so when taken outside hardirq context it should always be
  62. * taken with interrupts disabled. The lock protects both the
  63. * hardware and the struct orinoco_private.
  64. *
  65. * Another flag, priv->hw_unavailable indicates that the hardware is
  66. * unavailable for an extended period of time (e.g. suspended, or in
  67. * the middle of a hard reset). This flag is protected by the
  68. * spinlock. All code which touches the hardware should check the
  69. * flag after taking the lock, and if it is set, give up on whatever
  70. * they are doing and drop the lock again. The orinoco_lock()
  71. * function handles this (it unlocks and returns -EBUSY if
  72. * hw_unavailable is non-zero).
  73. */
  74. #define DRIVER_NAME "orinoco"
  75. #include <linux/module.h>
  76. #include <linux/kernel.h>
  77. #include <linux/init.h>
  78. #include <linux/delay.h>
  79. #include <linux/netdevice.h>
  80. #include <linux/etherdevice.h>
  81. #include <linux/ethtool.h>
  82. #include <linux/firmware.h>
  83. #include <linux/if_arp.h>
  84. #include <linux/wireless.h>
  85. #include <linux/ieee80211.h>
  86. #include <net/iw_handler.h>
  87. #include <linux/scatterlist.h>
  88. #include <linux/crypto.h>
  89. #include "hermes_rid.h"
  90. #include "hermes_dld.h"
  91. #include "orinoco.h"
  92. /********************************************************************/
  93. /* Module information */
  94. /********************************************************************/
  95. MODULE_AUTHOR("Pavel Roskin <proski@gnu.org> & David Gibson <hermes@gibson.dropbear.id.au>");
  96. MODULE_DESCRIPTION("Driver for Lucent Orinoco, Prism II based and similar wireless cards");
  97. MODULE_LICENSE("Dual MPL/GPL");
  98. /* Level of debugging. Used in the macros in orinoco.h */
  99. #ifdef ORINOCO_DEBUG
  100. int orinoco_debug = ORINOCO_DEBUG;
  101. module_param(orinoco_debug, int, 0644);
  102. MODULE_PARM_DESC(orinoco_debug, "Debug level");
  103. EXPORT_SYMBOL(orinoco_debug);
  104. #endif
  105. static int suppress_linkstatus; /* = 0 */
  106. module_param(suppress_linkstatus, bool, 0644);
  107. MODULE_PARM_DESC(suppress_linkstatus, "Don't log link status changes");
  108. static int ignore_disconnect; /* = 0 */
  109. module_param(ignore_disconnect, int, 0644);
  110. MODULE_PARM_DESC(ignore_disconnect, "Don't report lost link to the network layer");
  111. static int force_monitor; /* = 0 */
  112. module_param(force_monitor, int, 0644);
  113. MODULE_PARM_DESC(force_monitor, "Allow monitor mode for all firmware versions");
  114. /********************************************************************/
  115. /* Compile time configuration and compatibility stuff */
  116. /********************************************************************/
  117. /* We do this this way to avoid ifdefs in the actual code */
  118. #ifdef WIRELESS_SPY
  119. #define SPY_NUMBER(priv) (priv->spy_data.spy_number)
  120. #else
  121. #define SPY_NUMBER(priv) 0
  122. #endif /* WIRELESS_SPY */
  123. /********************************************************************/
  124. /* Internal constants */
  125. /********************************************************************/
  126. /* 802.2 LLC/SNAP header used for Ethernet encapsulation over 802.11 */
  127. static const u8 encaps_hdr[] = {0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00};
  128. #define ENCAPS_OVERHEAD (sizeof(encaps_hdr) + 2)
  129. #define ORINOCO_MIN_MTU 256
  130. #define ORINOCO_MAX_MTU (IEEE80211_MAX_DATA_LEN - ENCAPS_OVERHEAD)
  131. #define SYMBOL_MAX_VER_LEN (14)
  132. #define USER_BAP 0
  133. #define IRQ_BAP 1
  134. #define MAX_IRQLOOPS_PER_IRQ 10
  135. #define MAX_IRQLOOPS_PER_JIFFY (20000/HZ) /* Based on a guestimate of
  136. * how many events the
  137. * device could
  138. * legitimately generate */
  139. #define SMALL_KEY_SIZE 5
  140. #define LARGE_KEY_SIZE 13
  141. #define TX_NICBUF_SIZE_BUG 1585 /* Bug in Symbol firmware */
  142. #define DUMMY_FID 0xFFFF
  143. /*#define MAX_MULTICAST(priv) (priv->firmware_type == FIRMWARE_TYPE_AGERE ? \
  144. HERMES_MAX_MULTICAST : 0)*/
  145. #define MAX_MULTICAST(priv) (HERMES_MAX_MULTICAST)
  146. #define ORINOCO_INTEN (HERMES_EV_RX | HERMES_EV_ALLOC \
  147. | HERMES_EV_TX | HERMES_EV_TXEXC \
  148. | HERMES_EV_WTERR | HERMES_EV_INFO \
  149. | HERMES_EV_INFDROP )
  150. #define MAX_RID_LEN 1024
  151. static const struct iw_handler_def orinoco_handler_def;
  152. static const struct ethtool_ops orinoco_ethtool_ops;
  153. /********************************************************************/
  154. /* Data tables */
  155. /********************************************************************/
  156. /* The frequency of each channel in MHz */
  157. static const long channel_frequency[] = {
  158. 2412, 2417, 2422, 2427, 2432, 2437, 2442,
  159. 2447, 2452, 2457, 2462, 2467, 2472, 2484
  160. };
  161. #define NUM_CHANNELS ARRAY_SIZE(channel_frequency)
  162. /* This tables gives the actual meanings of the bitrate IDs returned
  163. * by the firmware. */
  164. static struct {
  165. int bitrate; /* in 100s of kilobits */
  166. int automatic;
  167. u16 agere_txratectrl;
  168. u16 intersil_txratectrl;
  169. } bitrate_table[] = {
  170. {110, 1, 3, 15}, /* Entry 0 is the default */
  171. {10, 0, 1, 1},
  172. {10, 1, 1, 1},
  173. {20, 0, 2, 2},
  174. {20, 1, 6, 3},
  175. {55, 0, 4, 4},
  176. {55, 1, 7, 7},
  177. {110, 0, 5, 8},
  178. };
  179. #define BITRATE_TABLE_SIZE ARRAY_SIZE(bitrate_table)
  180. /********************************************************************/
  181. /* Data types */
  182. /********************************************************************/
  183. /* Beginning of the Tx descriptor, used in TxExc handling */
  184. struct hermes_txexc_data {
  185. struct hermes_tx_descriptor desc;
  186. __le16 frame_ctl;
  187. __le16 duration_id;
  188. u8 addr1[ETH_ALEN];
  189. } __attribute__ ((packed));
  190. /* Rx frame header except compatibility 802.3 header */
  191. struct hermes_rx_descriptor {
  192. /* Control */
  193. __le16 status;
  194. __le32 time;
  195. u8 silence;
  196. u8 signal;
  197. u8 rate;
  198. u8 rxflow;
  199. __le32 reserved;
  200. /* 802.11 header */
  201. __le16 frame_ctl;
  202. __le16 duration_id;
  203. u8 addr1[ETH_ALEN];
  204. u8 addr2[ETH_ALEN];
  205. u8 addr3[ETH_ALEN];
  206. __le16 seq_ctl;
  207. u8 addr4[ETH_ALEN];
  208. /* Data length */
  209. __le16 data_len;
  210. } __attribute__ ((packed));
  211. /********************************************************************/
  212. /* Function prototypes */
  213. /********************************************************************/
  214. static int __orinoco_program_rids(struct net_device *dev);
  215. static void __orinoco_set_multicast_list(struct net_device *dev);
  216. /********************************************************************/
  217. /* Michael MIC crypto setup */
  218. /********************************************************************/
  219. #define MICHAEL_MIC_LEN 8
  220. static int orinoco_mic_init(struct orinoco_private *priv)
  221. {
  222. priv->tx_tfm_mic = crypto_alloc_hash("michael_mic", 0, 0);
  223. if (IS_ERR(priv->tx_tfm_mic)) {
  224. printk(KERN_DEBUG "orinoco_mic_init: could not allocate "
  225. "crypto API michael_mic\n");
  226. priv->tx_tfm_mic = NULL;
  227. return -ENOMEM;
  228. }
  229. priv->rx_tfm_mic = crypto_alloc_hash("michael_mic", 0, 0);
  230. if (IS_ERR(priv->rx_tfm_mic)) {
  231. printk(KERN_DEBUG "orinoco_mic_init: could not allocate "
  232. "crypto API michael_mic\n");
  233. priv->rx_tfm_mic = NULL;
  234. return -ENOMEM;
  235. }
  236. return 0;
  237. }
  238. static void orinoco_mic_free(struct orinoco_private *priv)
  239. {
  240. if (priv->tx_tfm_mic)
  241. crypto_free_hash(priv->tx_tfm_mic);
  242. if (priv->rx_tfm_mic)
  243. crypto_free_hash(priv->rx_tfm_mic);
  244. }
  245. static int michael_mic(struct crypto_hash *tfm_michael, u8 *key,
  246. u8 *da, u8 *sa, u8 priority,
  247. u8 *data, size_t data_len, u8 *mic)
  248. {
  249. struct hash_desc desc;
  250. struct scatterlist sg[2];
  251. u8 hdr[ETH_HLEN + 2]; /* size of header + padding */
  252. if (tfm_michael == NULL) {
  253. printk(KERN_WARNING "michael_mic: tfm_michael == NULL\n");
  254. return -1;
  255. }
  256. /* Copy header into buffer. We need the padding on the end zeroed */
  257. memcpy(&hdr[0], da, ETH_ALEN);
  258. memcpy(&hdr[ETH_ALEN], sa, ETH_ALEN);
  259. hdr[ETH_ALEN*2] = priority;
  260. hdr[ETH_ALEN*2+1] = 0;
  261. hdr[ETH_ALEN*2+2] = 0;
  262. hdr[ETH_ALEN*2+3] = 0;
  263. /* Use scatter gather to MIC header and data in one go */
  264. sg_init_table(sg, 2);
  265. sg_set_buf(&sg[0], hdr, sizeof(hdr));
  266. sg_set_buf(&sg[1], data, data_len);
  267. if (crypto_hash_setkey(tfm_michael, key, MIC_KEYLEN))
  268. return -1;
  269. desc.tfm = tfm_michael;
  270. desc.flags = 0;
  271. return crypto_hash_digest(&desc, sg, data_len + sizeof(hdr),
  272. mic);
  273. }
  274. /********************************************************************/
  275. /* Internal helper functions */
  276. /********************************************************************/
  277. static inline void set_port_type(struct orinoco_private *priv)
  278. {
  279. switch (priv->iw_mode) {
  280. case IW_MODE_INFRA:
  281. priv->port_type = 1;
  282. priv->createibss = 0;
  283. break;
  284. case IW_MODE_ADHOC:
  285. if (priv->prefer_port3) {
  286. priv->port_type = 3;
  287. priv->createibss = 0;
  288. } else {
  289. priv->port_type = priv->ibss_port;
  290. priv->createibss = 1;
  291. }
  292. break;
  293. case IW_MODE_MONITOR:
  294. priv->port_type = 3;
  295. priv->createibss = 0;
  296. break;
  297. default:
  298. printk(KERN_ERR "%s: Invalid priv->iw_mode in set_port_type()\n",
  299. priv->ndev->name);
  300. }
  301. }
  302. #define ORINOCO_MAX_BSS_COUNT 64
  303. static int orinoco_bss_data_allocate(struct orinoco_private *priv)
  304. {
  305. if (priv->bss_xbss_data)
  306. return 0;
  307. if (priv->has_ext_scan)
  308. priv->bss_xbss_data = kzalloc(ORINOCO_MAX_BSS_COUNT *
  309. sizeof(struct xbss_element),
  310. GFP_KERNEL);
  311. else
  312. priv->bss_xbss_data = kzalloc(ORINOCO_MAX_BSS_COUNT *
  313. sizeof(struct bss_element),
  314. GFP_KERNEL);
  315. if (!priv->bss_xbss_data) {
  316. printk(KERN_WARNING "Out of memory allocating beacons");
  317. return -ENOMEM;
  318. }
  319. return 0;
  320. }
  321. static void orinoco_bss_data_free(struct orinoco_private *priv)
  322. {
  323. kfree(priv->bss_xbss_data);
  324. priv->bss_xbss_data = NULL;
  325. }
  326. #define PRIV_BSS ((struct bss_element *)priv->bss_xbss_data)
  327. #define PRIV_XBSS ((struct xbss_element *)priv->bss_xbss_data)
  328. static void orinoco_bss_data_init(struct orinoco_private *priv)
  329. {
  330. int i;
  331. INIT_LIST_HEAD(&priv->bss_free_list);
  332. INIT_LIST_HEAD(&priv->bss_list);
  333. if (priv->has_ext_scan)
  334. for (i = 0; i < ORINOCO_MAX_BSS_COUNT; i++)
  335. list_add_tail(&(PRIV_XBSS[i].list),
  336. &priv->bss_free_list);
  337. else
  338. for (i = 0; i < ORINOCO_MAX_BSS_COUNT; i++)
  339. list_add_tail(&(PRIV_BSS[i].list),
  340. &priv->bss_free_list);
  341. }
  342. static inline u8 *orinoco_get_ie(u8 *data, size_t len,
  343. enum ieee80211_eid eid)
  344. {
  345. u8 *p = data;
  346. while ((p + 2) < (data + len)) {
  347. if (p[0] == eid)
  348. return p;
  349. p += p[1] + 2;
  350. }
  351. return NULL;
  352. }
  353. #define WPA_OUI_TYPE "\x00\x50\xF2\x01"
  354. #define WPA_SELECTOR_LEN 4
  355. static inline u8 *orinoco_get_wpa_ie(u8 *data, size_t len)
  356. {
  357. u8 *p = data;
  358. while ((p + 2 + WPA_SELECTOR_LEN) < (data + len)) {
  359. if ((p[0] == WLAN_EID_GENERIC) &&
  360. (memcmp(&p[2], WPA_OUI_TYPE, WPA_SELECTOR_LEN) == 0))
  361. return p;
  362. p += p[1] + 2;
  363. }
  364. return NULL;
  365. }
  366. /********************************************************************/
  367. /* Download functionality */
  368. /********************************************************************/
  369. struct fw_info {
  370. char *pri_fw;
  371. char *sta_fw;
  372. char *ap_fw;
  373. u32 pda_addr;
  374. u16 pda_size;
  375. };
  376. const static struct fw_info orinoco_fw[] = {
  377. { "", "agere_sta_fw.bin", "agere_ap_fw.bin", 0x00390000, 1000 },
  378. { "", "prism_sta_fw.bin", "prism_ap_fw.bin", 0, 1024 },
  379. { "symbol_sp24t_prim_fw", "symbol_sp24t_sec_fw", "", 0x00003100, 512 }
  380. };
  381. /* Structure used to access fields in FW
  382. * Make sure LE decoding macros are used
  383. */
  384. struct orinoco_fw_header {
  385. char hdr_vers[6]; /* ASCII string for header version */
  386. __le16 headersize; /* Total length of header */
  387. __le32 entry_point; /* NIC entry point */
  388. __le32 blocks; /* Number of blocks to program */
  389. __le32 block_offset; /* Offset of block data from eof header */
  390. __le32 pdr_offset; /* Offset to PDR data from eof header */
  391. __le32 pri_offset; /* Offset to primary plug data */
  392. __le32 compat_offset; /* Offset to compatibility data*/
  393. char signature[0]; /* FW signature length headersize-20 */
  394. } __attribute__ ((packed));
  395. /* Download either STA or AP firmware into the card. */
  396. static int
  397. orinoco_dl_firmware(struct orinoco_private *priv,
  398. const struct fw_info *fw,
  399. int ap)
  400. {
  401. /* Plug Data Area (PDA) */
  402. __le16 *pda;
  403. hermes_t *hw = &priv->hw;
  404. const struct firmware *fw_entry;
  405. const struct orinoco_fw_header *hdr;
  406. const unsigned char *first_block;
  407. const unsigned char *end;
  408. const char *firmware;
  409. struct net_device *dev = priv->ndev;
  410. int err = 0;
  411. pda = kzalloc(fw->pda_size, GFP_KERNEL);
  412. if (!pda)
  413. return -ENOMEM;
  414. if (ap)
  415. firmware = fw->ap_fw;
  416. else
  417. firmware = fw->sta_fw;
  418. printk(KERN_DEBUG "%s: Attempting to download firmware %s\n",
  419. dev->name, firmware);
  420. /* Read current plug data */
  421. err = hermes_read_pda(hw, pda, fw->pda_addr, fw->pda_size, 0);
  422. printk(KERN_DEBUG "%s: Read PDA returned %d\n", dev->name, err);
  423. if (err)
  424. goto free;
  425. if (priv->cached_fw)
  426. fw_entry = priv->cached_fw;
  427. else {
  428. err = request_firmware(&fw_entry, firmware, priv->dev);
  429. if (err) {
  430. printk(KERN_ERR "%s: Cannot find firmware %s\n",
  431. dev->name, firmware);
  432. err = -ENOENT;
  433. goto free;
  434. }
  435. priv->cached_fw = fw_entry;
  436. }
  437. hdr = (const struct orinoco_fw_header *) fw_entry->data;
  438. /* Enable aux port to allow programming */
  439. err = hermesi_program_init(hw, le32_to_cpu(hdr->entry_point));
  440. printk(KERN_DEBUG "%s: Program init returned %d\n", dev->name, err);
  441. if (err != 0)
  442. goto abort;
  443. /* Program data */
  444. first_block = (fw_entry->data +
  445. le16_to_cpu(hdr->headersize) +
  446. le32_to_cpu(hdr->block_offset));
  447. end = fw_entry->data + fw_entry->size;
  448. err = hermes_program(hw, first_block, end);
  449. printk(KERN_DEBUG "%s: Program returned %d\n", dev->name, err);
  450. if (err != 0)
  451. goto abort;
  452. /* Update production data */
  453. first_block = (fw_entry->data +
  454. le16_to_cpu(hdr->headersize) +
  455. le32_to_cpu(hdr->pdr_offset));
  456. err = hermes_apply_pda_with_defaults(hw, first_block, pda);
  457. printk(KERN_DEBUG "%s: Apply PDA returned %d\n", dev->name, err);
  458. if (err)
  459. goto abort;
  460. /* Tell card we've finished */
  461. err = hermesi_program_end(hw);
  462. printk(KERN_DEBUG "%s: Program end returned %d\n", dev->name, err);
  463. if (err != 0)
  464. goto abort;
  465. /* Check if we're running */
  466. printk(KERN_DEBUG "%s: hermes_present returned %d\n",
  467. dev->name, hermes_present(hw));
  468. abort:
  469. /* In case of error, assume firmware was bogus and release it */
  470. if (err) {
  471. priv->cached_fw = NULL;
  472. release_firmware(fw_entry);
  473. }
  474. free:
  475. kfree(pda);
  476. return err;
  477. }
  478. /* End markers */
  479. #define TEXT_END 0x1A /* End of text header */
  480. /*
  481. * Process a firmware image - stop the card, load the firmware, reset
  482. * the card and make sure it responds. For the secondary firmware take
  483. * care of the PDA - read it and then write it on top of the firmware.
  484. */
  485. static int
  486. symbol_dl_image(struct orinoco_private *priv, const struct fw_info *fw,
  487. const unsigned char *image, const unsigned char *end,
  488. int secondary)
  489. {
  490. hermes_t *hw = &priv->hw;
  491. int ret = 0;
  492. const unsigned char *ptr;
  493. const unsigned char *first_block;
  494. /* Plug Data Area (PDA) */
  495. __le16 *pda = NULL;
  496. /* Binary block begins after the 0x1A marker */
  497. ptr = image;
  498. while (*ptr++ != TEXT_END);
  499. first_block = ptr;
  500. /* Read the PDA from EEPROM */
  501. if (secondary) {
  502. pda = kzalloc(fw->pda_size, GFP_KERNEL);
  503. if (!pda)
  504. return -ENOMEM;
  505. ret = hermes_read_pda(hw, pda, fw->pda_addr, fw->pda_size, 1);
  506. if (ret)
  507. goto free;
  508. }
  509. /* Stop the firmware, so that it can be safely rewritten */
  510. if (priv->stop_fw) {
  511. ret = priv->stop_fw(priv, 1);
  512. if (ret)
  513. goto free;
  514. }
  515. /* Program the adapter with new firmware */
  516. ret = hermes_program(hw, first_block, end);
  517. if (ret)
  518. goto free;
  519. /* Write the PDA to the adapter */
  520. if (secondary) {
  521. size_t len = hermes_blocks_length(first_block);
  522. ptr = first_block + len;
  523. ret = hermes_apply_pda(hw, ptr, pda);
  524. kfree(pda);
  525. if (ret)
  526. return ret;
  527. }
  528. /* Run the firmware */
  529. if (priv->stop_fw) {
  530. ret = priv->stop_fw(priv, 0);
  531. if (ret)
  532. return ret;
  533. }
  534. /* Reset hermes chip and make sure it responds */
  535. ret = hermes_init(hw);
  536. /* hermes_reset() should return 0 with the secondary firmware */
  537. if (secondary && ret != 0)
  538. return -ENODEV;
  539. /* And this should work with any firmware */
  540. if (!hermes_present(hw))
  541. return -ENODEV;
  542. return 0;
  543. free:
  544. kfree(pda);
  545. return ret;
  546. }
  547. /*
  548. * Download the firmware into the card, this also does a PCMCIA soft
  549. * reset on the card, to make sure it's in a sane state.
  550. */
  551. static int
  552. symbol_dl_firmware(struct orinoco_private *priv,
  553. const struct fw_info *fw)
  554. {
  555. struct net_device *dev = priv->ndev;
  556. int ret;
  557. const struct firmware *fw_entry;
  558. if (request_firmware(&fw_entry, fw->pri_fw,
  559. priv->dev) != 0) {
  560. printk(KERN_ERR "%s: Cannot find firmware: %s\n",
  561. dev->name, fw->pri_fw);
  562. return -ENOENT;
  563. }
  564. /* Load primary firmware */
  565. ret = symbol_dl_image(priv, fw, fw_entry->data,
  566. fw_entry->data + fw_entry->size, 0);
  567. release_firmware(fw_entry);
  568. if (ret) {
  569. printk(KERN_ERR "%s: Primary firmware download failed\n",
  570. dev->name);
  571. return ret;
  572. }
  573. if (request_firmware(&fw_entry, fw->sta_fw,
  574. priv->dev) != 0) {
  575. printk(KERN_ERR "%s: Cannot find firmware: %s\n",
  576. dev->name, fw->sta_fw);
  577. return -ENOENT;
  578. }
  579. /* Load secondary firmware */
  580. ret = symbol_dl_image(priv, fw, fw_entry->data,
  581. fw_entry->data + fw_entry->size, 1);
  582. release_firmware(fw_entry);
  583. if (ret) {
  584. printk(KERN_ERR "%s: Secondary firmware download failed\n",
  585. dev->name);
  586. }
  587. return ret;
  588. }
  589. static int orinoco_download(struct orinoco_private *priv)
  590. {
  591. int err = 0;
  592. /* Reload firmware */
  593. switch (priv->firmware_type) {
  594. case FIRMWARE_TYPE_AGERE:
  595. /* case FIRMWARE_TYPE_INTERSIL: */
  596. err = orinoco_dl_firmware(priv,
  597. &orinoco_fw[priv->firmware_type], 0);
  598. break;
  599. case FIRMWARE_TYPE_SYMBOL:
  600. err = symbol_dl_firmware(priv,
  601. &orinoco_fw[priv->firmware_type]);
  602. break;
  603. case FIRMWARE_TYPE_INTERSIL:
  604. break;
  605. }
  606. /* TODO: if we fail we probably need to reinitialise
  607. * the driver */
  608. return err;
  609. }
  610. /********************************************************************/
  611. /* Device methods */
  612. /********************************************************************/
  613. static int orinoco_open(struct net_device *dev)
  614. {
  615. struct orinoco_private *priv = netdev_priv(dev);
  616. unsigned long flags;
  617. int err;
  618. if (orinoco_lock(priv, &flags) != 0)
  619. return -EBUSY;
  620. err = __orinoco_up(dev);
  621. if (! err)
  622. priv->open = 1;
  623. orinoco_unlock(priv, &flags);
  624. return err;
  625. }
  626. static int orinoco_stop(struct net_device *dev)
  627. {
  628. struct orinoco_private *priv = netdev_priv(dev);
  629. int err = 0;
  630. /* We mustn't use orinoco_lock() here, because we need to be
  631. able to close the interface even if hw_unavailable is set
  632. (e.g. as we're released after a PC Card removal) */
  633. spin_lock_irq(&priv->lock);
  634. priv->open = 0;
  635. err = __orinoco_down(dev);
  636. spin_unlock_irq(&priv->lock);
  637. return err;
  638. }
  639. static struct net_device_stats *orinoco_get_stats(struct net_device *dev)
  640. {
  641. struct orinoco_private *priv = netdev_priv(dev);
  642. return &priv->stats;
  643. }
  644. static struct iw_statistics *orinoco_get_wireless_stats(struct net_device *dev)
  645. {
  646. struct orinoco_private *priv = netdev_priv(dev);
  647. hermes_t *hw = &priv->hw;
  648. struct iw_statistics *wstats = &priv->wstats;
  649. int err;
  650. unsigned long flags;
  651. if (! netif_device_present(dev)) {
  652. printk(KERN_WARNING "%s: get_wireless_stats() called while device not present\n",
  653. dev->name);
  654. return NULL; /* FIXME: Can we do better than this? */
  655. }
  656. /* If busy, return the old stats. Returning NULL may cause
  657. * the interface to disappear from /proc/net/wireless */
  658. if (orinoco_lock(priv, &flags) != 0)
  659. return wstats;
  660. /* We can't really wait for the tallies inquiry command to
  661. * complete, so we just use the previous results and trigger
  662. * a new tallies inquiry command for next time - Jean II */
  663. /* FIXME: Really we should wait for the inquiry to come back -
  664. * as it is the stats we give don't make a whole lot of sense.
  665. * Unfortunately, it's not clear how to do that within the
  666. * wireless extensions framework: I think we're in user
  667. * context, but a lock seems to be held by the time we get in
  668. * here so we're not safe to sleep here. */
  669. hermes_inquire(hw, HERMES_INQ_TALLIES);
  670. if (priv->iw_mode == IW_MODE_ADHOC) {
  671. memset(&wstats->qual, 0, sizeof(wstats->qual));
  672. /* If a spy address is defined, we report stats of the
  673. * first spy address - Jean II */
  674. if (SPY_NUMBER(priv)) {
  675. wstats->qual.qual = priv->spy_data.spy_stat[0].qual;
  676. wstats->qual.level = priv->spy_data.spy_stat[0].level;
  677. wstats->qual.noise = priv->spy_data.spy_stat[0].noise;
  678. wstats->qual.updated = priv->spy_data.spy_stat[0].updated;
  679. }
  680. } else {
  681. struct {
  682. __le16 qual, signal, noise, unused;
  683. } __attribute__ ((packed)) cq;
  684. err = HERMES_READ_RECORD(hw, USER_BAP,
  685. HERMES_RID_COMMSQUALITY, &cq);
  686. if (!err) {
  687. wstats->qual.qual = (int)le16_to_cpu(cq.qual);
  688. wstats->qual.level = (int)le16_to_cpu(cq.signal) - 0x95;
  689. wstats->qual.noise = (int)le16_to_cpu(cq.noise) - 0x95;
  690. wstats->qual.updated = 7;
  691. }
  692. }
  693. orinoco_unlock(priv, &flags);
  694. return wstats;
  695. }
  696. static void orinoco_set_multicast_list(struct net_device *dev)
  697. {
  698. struct orinoco_private *priv = netdev_priv(dev);
  699. unsigned long flags;
  700. if (orinoco_lock(priv, &flags) != 0) {
  701. printk(KERN_DEBUG "%s: orinoco_set_multicast_list() "
  702. "called when hw_unavailable\n", dev->name);
  703. return;
  704. }
  705. __orinoco_set_multicast_list(dev);
  706. orinoco_unlock(priv, &flags);
  707. }
  708. static int orinoco_change_mtu(struct net_device *dev, int new_mtu)
  709. {
  710. struct orinoco_private *priv = netdev_priv(dev);
  711. if ( (new_mtu < ORINOCO_MIN_MTU) || (new_mtu > ORINOCO_MAX_MTU) )
  712. return -EINVAL;
  713. /* MTU + encapsulation + header length */
  714. if ( (new_mtu + ENCAPS_OVERHEAD + sizeof(struct ieee80211_hdr)) >
  715. (priv->nicbuf_size - ETH_HLEN) )
  716. return -EINVAL;
  717. dev->mtu = new_mtu;
  718. return 0;
  719. }
  720. /********************************************************************/
  721. /* Tx path */
  722. /********************************************************************/
  723. static int orinoco_xmit(struct sk_buff *skb, struct net_device *dev)
  724. {
  725. struct orinoco_private *priv = netdev_priv(dev);
  726. struct net_device_stats *stats = &priv->stats;
  727. hermes_t *hw = &priv->hw;
  728. int err = 0;
  729. u16 txfid = priv->txfid;
  730. struct ethhdr *eh;
  731. int tx_control;
  732. unsigned long flags;
  733. if (! netif_running(dev)) {
  734. printk(KERN_ERR "%s: Tx on stopped device!\n",
  735. dev->name);
  736. return NETDEV_TX_BUSY;
  737. }
  738. if (netif_queue_stopped(dev)) {
  739. printk(KERN_DEBUG "%s: Tx while transmitter busy!\n",
  740. dev->name);
  741. return NETDEV_TX_BUSY;
  742. }
  743. if (orinoco_lock(priv, &flags) != 0) {
  744. printk(KERN_ERR "%s: orinoco_xmit() called while hw_unavailable\n",
  745. dev->name);
  746. return NETDEV_TX_BUSY;
  747. }
  748. if (! netif_carrier_ok(dev) || (priv->iw_mode == IW_MODE_MONITOR)) {
  749. /* Oops, the firmware hasn't established a connection,
  750. silently drop the packet (this seems to be the
  751. safest approach). */
  752. goto drop;
  753. }
  754. /* Check packet length */
  755. if (skb->len < ETH_HLEN)
  756. goto drop;
  757. tx_control = HERMES_TXCTRL_TX_OK | HERMES_TXCTRL_TX_EX;
  758. if (priv->encode_alg == IW_ENCODE_ALG_TKIP)
  759. tx_control |= (priv->tx_key << HERMES_MIC_KEY_ID_SHIFT) |
  760. HERMES_TXCTRL_MIC;
  761. if (priv->has_alt_txcntl) {
  762. /* WPA enabled firmwares have tx_cntl at the end of
  763. * the 802.11 header. So write zeroed descriptor and
  764. * 802.11 header at the same time
  765. */
  766. char desc[HERMES_802_3_OFFSET];
  767. __le16 *txcntl = (__le16 *) &desc[HERMES_TXCNTL2_OFFSET];
  768. memset(&desc, 0, sizeof(desc));
  769. *txcntl = cpu_to_le16(tx_control);
  770. err = hermes_bap_pwrite(hw, USER_BAP, &desc, sizeof(desc),
  771. txfid, 0);
  772. if (err) {
  773. if (net_ratelimit())
  774. printk(KERN_ERR "%s: Error %d writing Tx "
  775. "descriptor to BAP\n", dev->name, err);
  776. goto busy;
  777. }
  778. } else {
  779. struct hermes_tx_descriptor desc;
  780. memset(&desc, 0, sizeof(desc));
  781. desc.tx_control = cpu_to_le16(tx_control);
  782. err = hermes_bap_pwrite(hw, USER_BAP, &desc, sizeof(desc),
  783. txfid, 0);
  784. if (err) {
  785. if (net_ratelimit())
  786. printk(KERN_ERR "%s: Error %d writing Tx "
  787. "descriptor to BAP\n", dev->name, err);
  788. goto busy;
  789. }
  790. /* Clear the 802.11 header and data length fields - some
  791. * firmwares (e.g. Lucent/Agere 8.xx) appear to get confused
  792. * if this isn't done. */
  793. hermes_clear_words(hw, HERMES_DATA0,
  794. HERMES_802_3_OFFSET - HERMES_802_11_OFFSET);
  795. }
  796. eh = (struct ethhdr *)skb->data;
  797. /* Encapsulate Ethernet-II frames */
  798. if (ntohs(eh->h_proto) > ETH_DATA_LEN) { /* Ethernet-II frame */
  799. struct header_struct {
  800. struct ethhdr eth; /* 802.3 header */
  801. u8 encap[6]; /* 802.2 header */
  802. } __attribute__ ((packed)) hdr;
  803. /* Strip destination and source from the data */
  804. skb_pull(skb, 2 * ETH_ALEN);
  805. /* And move them to a separate header */
  806. memcpy(&hdr.eth, eh, 2 * ETH_ALEN);
  807. hdr.eth.h_proto = htons(sizeof(encaps_hdr) + skb->len);
  808. memcpy(hdr.encap, encaps_hdr, sizeof(encaps_hdr));
  809. /* Insert the SNAP header */
  810. if (skb_headroom(skb) < sizeof(hdr)) {
  811. printk(KERN_ERR
  812. "%s: Not enough headroom for 802.2 headers %d\n",
  813. dev->name, skb_headroom(skb));
  814. goto drop;
  815. }
  816. eh = (struct ethhdr *) skb_push(skb, sizeof(hdr));
  817. memcpy(eh, &hdr, sizeof(hdr));
  818. }
  819. err = hermes_bap_pwrite(hw, USER_BAP, skb->data, skb->len,
  820. txfid, HERMES_802_3_OFFSET);
  821. if (err) {
  822. printk(KERN_ERR "%s: Error %d writing packet to BAP\n",
  823. dev->name, err);
  824. goto busy;
  825. }
  826. /* Calculate Michael MIC */
  827. if (priv->encode_alg == IW_ENCODE_ALG_TKIP) {
  828. u8 mic_buf[MICHAEL_MIC_LEN + 1];
  829. u8 *mic;
  830. size_t offset;
  831. size_t len;
  832. if (skb->len % 2) {
  833. /* MIC start is on an odd boundary */
  834. mic_buf[0] = skb->data[skb->len - 1];
  835. mic = &mic_buf[1];
  836. offset = skb->len - 1;
  837. len = MICHAEL_MIC_LEN + 1;
  838. } else {
  839. mic = &mic_buf[0];
  840. offset = skb->len;
  841. len = MICHAEL_MIC_LEN;
  842. }
  843. michael_mic(priv->tx_tfm_mic,
  844. priv->tkip_key[priv->tx_key].tx_mic,
  845. eh->h_dest, eh->h_source, 0 /* priority */,
  846. skb->data + ETH_HLEN, skb->len - ETH_HLEN, mic);
  847. /* Write the MIC */
  848. err = hermes_bap_pwrite(hw, USER_BAP, &mic_buf[0], len,
  849. txfid, HERMES_802_3_OFFSET + offset);
  850. if (err) {
  851. printk(KERN_ERR "%s: Error %d writing MIC to BAP\n",
  852. dev->name, err);
  853. goto busy;
  854. }
  855. }
  856. /* Finally, we actually initiate the send */
  857. netif_stop_queue(dev);
  858. err = hermes_docmd_wait(hw, HERMES_CMD_TX | HERMES_CMD_RECL,
  859. txfid, NULL);
  860. if (err) {
  861. netif_start_queue(dev);
  862. if (net_ratelimit())
  863. printk(KERN_ERR "%s: Error %d transmitting packet\n",
  864. dev->name, err);
  865. goto busy;
  866. }
  867. dev->trans_start = jiffies;
  868. stats->tx_bytes += HERMES_802_3_OFFSET + skb->len;
  869. goto ok;
  870. drop:
  871. stats->tx_errors++;
  872. stats->tx_dropped++;
  873. ok:
  874. orinoco_unlock(priv, &flags);
  875. dev_kfree_skb(skb);
  876. return NETDEV_TX_OK;
  877. busy:
  878. if (err == -EIO)
  879. schedule_work(&priv->reset_work);
  880. orinoco_unlock(priv, &flags);
  881. return NETDEV_TX_BUSY;
  882. }
  883. static void __orinoco_ev_alloc(struct net_device *dev, hermes_t *hw)
  884. {
  885. struct orinoco_private *priv = netdev_priv(dev);
  886. u16 fid = hermes_read_regn(hw, ALLOCFID);
  887. if (fid != priv->txfid) {
  888. if (fid != DUMMY_FID)
  889. printk(KERN_WARNING "%s: Allocate event on unexpected fid (%04X)\n",
  890. dev->name, fid);
  891. return;
  892. }
  893. hermes_write_regn(hw, ALLOCFID, DUMMY_FID);
  894. }
  895. static void __orinoco_ev_tx(struct net_device *dev, hermes_t *hw)
  896. {
  897. struct orinoco_private *priv = netdev_priv(dev);
  898. struct net_device_stats *stats = &priv->stats;
  899. stats->tx_packets++;
  900. netif_wake_queue(dev);
  901. hermes_write_regn(hw, TXCOMPLFID, DUMMY_FID);
  902. }
  903. static void __orinoco_ev_txexc(struct net_device *dev, hermes_t *hw)
  904. {
  905. struct orinoco_private *priv = netdev_priv(dev);
  906. struct net_device_stats *stats = &priv->stats;
  907. u16 fid = hermes_read_regn(hw, TXCOMPLFID);
  908. u16 status;
  909. struct hermes_txexc_data hdr;
  910. int err = 0;
  911. if (fid == DUMMY_FID)
  912. return; /* Nothing's really happened */
  913. /* Read part of the frame header - we need status and addr1 */
  914. err = hermes_bap_pread(hw, IRQ_BAP, &hdr,
  915. sizeof(struct hermes_txexc_data),
  916. fid, 0);
  917. hermes_write_regn(hw, TXCOMPLFID, DUMMY_FID);
  918. stats->tx_errors++;
  919. if (err) {
  920. printk(KERN_WARNING "%s: Unable to read descriptor on Tx error "
  921. "(FID=%04X error %d)\n",
  922. dev->name, fid, err);
  923. return;
  924. }
  925. DEBUG(1, "%s: Tx error, err %d (FID=%04X)\n", dev->name,
  926. err, fid);
  927. /* We produce a TXDROP event only for retry or lifetime
  928. * exceeded, because that's the only status that really mean
  929. * that this particular node went away.
  930. * Other errors means that *we* screwed up. - Jean II */
  931. status = le16_to_cpu(hdr.desc.status);
  932. if (status & (HERMES_TXSTAT_RETRYERR | HERMES_TXSTAT_AGEDERR)) {
  933. union iwreq_data wrqu;
  934. /* Copy 802.11 dest address.
  935. * We use the 802.11 header because the frame may
  936. * not be 802.3 or may be mangled...
  937. * In Ad-Hoc mode, it will be the node address.
  938. * In managed mode, it will be most likely the AP addr
  939. * User space will figure out how to convert it to
  940. * whatever it needs (IP address or else).
  941. * - Jean II */
  942. memcpy(wrqu.addr.sa_data, hdr.addr1, ETH_ALEN);
  943. wrqu.addr.sa_family = ARPHRD_ETHER;
  944. /* Send event to user space */
  945. wireless_send_event(dev, IWEVTXDROP, &wrqu, NULL);
  946. }
  947. netif_wake_queue(dev);
  948. }
  949. static void orinoco_tx_timeout(struct net_device *dev)
  950. {
  951. struct orinoco_private *priv = netdev_priv(dev);
  952. struct net_device_stats *stats = &priv->stats;
  953. struct hermes *hw = &priv->hw;
  954. printk(KERN_WARNING "%s: Tx timeout! "
  955. "ALLOCFID=%04x, TXCOMPLFID=%04x, EVSTAT=%04x\n",
  956. dev->name, hermes_read_regn(hw, ALLOCFID),
  957. hermes_read_regn(hw, TXCOMPLFID), hermes_read_regn(hw, EVSTAT));
  958. stats->tx_errors++;
  959. schedule_work(&priv->reset_work);
  960. }
  961. /********************************************************************/
  962. /* Rx path (data frames) */
  963. /********************************************************************/
  964. /* Does the frame have a SNAP header indicating it should be
  965. * de-encapsulated to Ethernet-II? */
  966. static inline int is_ethersnap(void *_hdr)
  967. {
  968. u8 *hdr = _hdr;
  969. /* We de-encapsulate all packets which, a) have SNAP headers
  970. * (i.e. SSAP=DSAP=0xaa and CTRL=0x3 in the 802.2 LLC header
  971. * and where b) the OUI of the SNAP header is 00:00:00 or
  972. * 00:00:f8 - we need both because different APs appear to use
  973. * different OUIs for some reason */
  974. return (memcmp(hdr, &encaps_hdr, 5) == 0)
  975. && ( (hdr[5] == 0x00) || (hdr[5] == 0xf8) );
  976. }
  977. static inline void orinoco_spy_gather(struct net_device *dev, u_char *mac,
  978. int level, int noise)
  979. {
  980. struct iw_quality wstats;
  981. wstats.level = level - 0x95;
  982. wstats.noise = noise - 0x95;
  983. wstats.qual = (level > noise) ? (level - noise) : 0;
  984. wstats.updated = 7;
  985. /* Update spy records */
  986. wireless_spy_update(dev, mac, &wstats);
  987. }
  988. static void orinoco_stat_gather(struct net_device *dev,
  989. struct sk_buff *skb,
  990. struct hermes_rx_descriptor *desc)
  991. {
  992. struct orinoco_private *priv = netdev_priv(dev);
  993. /* Using spy support with lots of Rx packets, like in an
  994. * infrastructure (AP), will really slow down everything, because
  995. * the MAC address must be compared to each entry of the spy list.
  996. * If the user really asks for it (set some address in the
  997. * spy list), we do it, but he will pay the price.
  998. * Note that to get here, you need both WIRELESS_SPY
  999. * compiled in AND some addresses in the list !!!
  1000. */
  1001. /* Note : gcc will optimise the whole section away if
  1002. * WIRELESS_SPY is not defined... - Jean II */
  1003. if (SPY_NUMBER(priv)) {
  1004. orinoco_spy_gather(dev, skb_mac_header(skb) + ETH_ALEN,
  1005. desc->signal, desc->silence);
  1006. }
  1007. }
  1008. /*
  1009. * orinoco_rx_monitor - handle received monitor frames.
  1010. *
  1011. * Arguments:
  1012. * dev network device
  1013. * rxfid received FID
  1014. * desc rx descriptor of the frame
  1015. *
  1016. * Call context: interrupt
  1017. */
  1018. static void orinoco_rx_monitor(struct net_device *dev, u16 rxfid,
  1019. struct hermes_rx_descriptor *desc)
  1020. {
  1021. u32 hdrlen = 30; /* return full header by default */
  1022. u32 datalen = 0;
  1023. u16 fc;
  1024. int err;
  1025. int len;
  1026. struct sk_buff *skb;
  1027. struct orinoco_private *priv = netdev_priv(dev);
  1028. struct net_device_stats *stats = &priv->stats;
  1029. hermes_t *hw = &priv->hw;
  1030. len = le16_to_cpu(desc->data_len);
  1031. /* Determine the size of the header and the data */
  1032. fc = le16_to_cpu(desc->frame_ctl);
  1033. switch (fc & IEEE80211_FCTL_FTYPE) {
  1034. case IEEE80211_FTYPE_DATA:
  1035. if ((fc & IEEE80211_FCTL_TODS)
  1036. && (fc & IEEE80211_FCTL_FROMDS))
  1037. hdrlen = 30;
  1038. else
  1039. hdrlen = 24;
  1040. datalen = len;
  1041. break;
  1042. case IEEE80211_FTYPE_MGMT:
  1043. hdrlen = 24;
  1044. datalen = len;
  1045. break;
  1046. case IEEE80211_FTYPE_CTL:
  1047. switch (fc & IEEE80211_FCTL_STYPE) {
  1048. case IEEE80211_STYPE_PSPOLL:
  1049. case IEEE80211_STYPE_RTS:
  1050. case IEEE80211_STYPE_CFEND:
  1051. case IEEE80211_STYPE_CFENDACK:
  1052. hdrlen = 16;
  1053. break;
  1054. case IEEE80211_STYPE_CTS:
  1055. case IEEE80211_STYPE_ACK:
  1056. hdrlen = 10;
  1057. break;
  1058. }
  1059. break;
  1060. default:
  1061. /* Unknown frame type */
  1062. break;
  1063. }
  1064. /* sanity check the length */
  1065. if (datalen > IEEE80211_MAX_DATA_LEN + 12) {
  1066. printk(KERN_DEBUG "%s: oversized monitor frame, "
  1067. "data length = %d\n", dev->name, datalen);
  1068. stats->rx_length_errors++;
  1069. goto update_stats;
  1070. }
  1071. skb = dev_alloc_skb(hdrlen + datalen);
  1072. if (!skb) {
  1073. printk(KERN_WARNING "%s: Cannot allocate skb for monitor frame\n",
  1074. dev->name);
  1075. goto update_stats;
  1076. }
  1077. /* Copy the 802.11 header to the skb */
  1078. memcpy(skb_put(skb, hdrlen), &(desc->frame_ctl), hdrlen);
  1079. skb_reset_mac_header(skb);
  1080. /* If any, copy the data from the card to the skb */
  1081. if (datalen > 0) {
  1082. err = hermes_bap_pread(hw, IRQ_BAP, skb_put(skb, datalen),
  1083. ALIGN(datalen, 2), rxfid,
  1084. HERMES_802_2_OFFSET);
  1085. if (err) {
  1086. printk(KERN_ERR "%s: error %d reading monitor frame\n",
  1087. dev->name, err);
  1088. goto drop;
  1089. }
  1090. }
  1091. skb->dev = dev;
  1092. skb->ip_summed = CHECKSUM_NONE;
  1093. skb->pkt_type = PACKET_OTHERHOST;
  1094. skb->protocol = __constant_htons(ETH_P_802_2);
  1095. stats->rx_packets++;
  1096. stats->rx_bytes += skb->len;
  1097. netif_rx(skb);
  1098. return;
  1099. drop:
  1100. dev_kfree_skb_irq(skb);
  1101. update_stats:
  1102. stats->rx_errors++;
  1103. stats->rx_dropped++;
  1104. }
  1105. /* Get tsc from the firmware */
  1106. static int orinoco_hw_get_tkip_iv(struct orinoco_private *priv, int key,
  1107. u8 *tsc)
  1108. {
  1109. hermes_t *hw = &priv->hw;
  1110. int err = 0;
  1111. u8 tsc_arr[4][IW_ENCODE_SEQ_MAX_SIZE];
  1112. if ((key < 0) || (key > 4))
  1113. return -EINVAL;
  1114. err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENT_TKIP_IV,
  1115. sizeof(tsc_arr), NULL, &tsc_arr);
  1116. if (!err)
  1117. memcpy(tsc, &tsc_arr[key][0], sizeof(tsc_arr[0]));
  1118. return err;
  1119. }
  1120. static void __orinoco_ev_rx(struct net_device *dev, hermes_t *hw)
  1121. {
  1122. struct orinoco_private *priv = netdev_priv(dev);
  1123. struct net_device_stats *stats = &priv->stats;
  1124. struct iw_statistics *wstats = &priv->wstats;
  1125. struct sk_buff *skb = NULL;
  1126. u16 rxfid, status;
  1127. int length;
  1128. struct hermes_rx_descriptor *desc;
  1129. struct orinoco_rx_data *rx_data;
  1130. int err;
  1131. desc = kmalloc(sizeof(*desc), GFP_ATOMIC);
  1132. if (!desc) {
  1133. printk(KERN_WARNING
  1134. "%s: Can't allocate space for RX descriptor\n",
  1135. dev->name);
  1136. goto update_stats;
  1137. }
  1138. rxfid = hermes_read_regn(hw, RXFID);
  1139. err = hermes_bap_pread(hw, IRQ_BAP, desc, sizeof(*desc),
  1140. rxfid, 0);
  1141. if (err) {
  1142. printk(KERN_ERR "%s: error %d reading Rx descriptor. "
  1143. "Frame dropped.\n", dev->name, err);
  1144. goto update_stats;
  1145. }
  1146. status = le16_to_cpu(desc->status);
  1147. if (status & HERMES_RXSTAT_BADCRC) {
  1148. DEBUG(1, "%s: Bad CRC on Rx. Frame dropped.\n",
  1149. dev->name);
  1150. stats->rx_crc_errors++;
  1151. goto update_stats;
  1152. }
  1153. /* Handle frames in monitor mode */
  1154. if (priv->iw_mode == IW_MODE_MONITOR) {
  1155. orinoco_rx_monitor(dev, rxfid, desc);
  1156. goto out;
  1157. }
  1158. if (status & HERMES_RXSTAT_UNDECRYPTABLE) {
  1159. DEBUG(1, "%s: Undecryptable frame on Rx. Frame dropped.\n",
  1160. dev->name);
  1161. wstats->discard.code++;
  1162. goto update_stats;
  1163. }
  1164. length = le16_to_cpu(desc->data_len);
  1165. /* Sanity checks */
  1166. if (length < 3) { /* No for even an 802.2 LLC header */
  1167. /* At least on Symbol firmware with PCF we get quite a
  1168. lot of these legitimately - Poll frames with no
  1169. data. */
  1170. goto out;
  1171. }
  1172. if (length > IEEE80211_MAX_DATA_LEN) {
  1173. printk(KERN_WARNING "%s: Oversized frame received (%d bytes)\n",
  1174. dev->name, length);
  1175. stats->rx_length_errors++;
  1176. goto update_stats;
  1177. }
  1178. /* Payload size does not include Michael MIC. Increase payload
  1179. * size to read it together with the data. */
  1180. if (status & HERMES_RXSTAT_MIC)
  1181. length += MICHAEL_MIC_LEN;
  1182. /* We need space for the packet data itself, plus an ethernet
  1183. header, plus 2 bytes so we can align the IP header on a
  1184. 32bit boundary, plus 1 byte so we can read in odd length
  1185. packets from the card, which has an IO granularity of 16
  1186. bits */
  1187. skb = dev_alloc_skb(length+ETH_HLEN+2+1);
  1188. if (!skb) {
  1189. printk(KERN_WARNING "%s: Can't allocate skb for Rx\n",
  1190. dev->name);
  1191. goto update_stats;
  1192. }
  1193. /* We'll prepend the header, so reserve space for it. The worst
  1194. case is no decapsulation, when 802.3 header is prepended and
  1195. nothing is removed. 2 is for aligning the IP header. */
  1196. skb_reserve(skb, ETH_HLEN + 2);
  1197. err = hermes_bap_pread(hw, IRQ_BAP, skb_put(skb, length),
  1198. ALIGN(length, 2), rxfid,
  1199. HERMES_802_2_OFFSET);
  1200. if (err) {
  1201. printk(KERN_ERR "%s: error %d reading frame. "
  1202. "Frame dropped.\n", dev->name, err);
  1203. goto drop;
  1204. }
  1205. /* Add desc and skb to rx queue */
  1206. rx_data = kzalloc(sizeof(*rx_data), GFP_ATOMIC);
  1207. if (!rx_data) {
  1208. printk(KERN_WARNING "%s: Can't allocate RX packet\n",
  1209. dev->name);
  1210. goto drop;
  1211. }
  1212. rx_data->desc = desc;
  1213. rx_data->skb = skb;
  1214. list_add_tail(&rx_data->list, &priv->rx_list);
  1215. tasklet_schedule(&priv->rx_tasklet);
  1216. return;
  1217. drop:
  1218. dev_kfree_skb_irq(skb);
  1219. update_stats:
  1220. stats->rx_errors++;
  1221. stats->rx_dropped++;
  1222. out:
  1223. kfree(desc);
  1224. }
  1225. static void orinoco_rx(struct net_device *dev,
  1226. struct hermes_rx_descriptor *desc,
  1227. struct sk_buff *skb)
  1228. {
  1229. struct orinoco_private *priv = netdev_priv(dev);
  1230. struct net_device_stats *stats = &priv->stats;
  1231. u16 status, fc;
  1232. int length;
  1233. struct ethhdr *hdr;
  1234. status = le16_to_cpu(desc->status);
  1235. length = le16_to_cpu(desc->data_len);
  1236. fc = le16_to_cpu(desc->frame_ctl);
  1237. /* Calculate and check MIC */
  1238. if (status & HERMES_RXSTAT_MIC) {
  1239. int key_id = ((status & HERMES_RXSTAT_MIC_KEY_ID) >>
  1240. HERMES_MIC_KEY_ID_SHIFT);
  1241. u8 mic[MICHAEL_MIC_LEN];
  1242. u8 *rxmic;
  1243. u8 *src = (fc & IEEE80211_FCTL_FROMDS) ?
  1244. desc->addr3 : desc->addr2;
  1245. /* Extract Michael MIC from payload */
  1246. rxmic = skb->data + skb->len - MICHAEL_MIC_LEN;
  1247. skb_trim(skb, skb->len - MICHAEL_MIC_LEN);
  1248. length -= MICHAEL_MIC_LEN;
  1249. michael_mic(priv->rx_tfm_mic,
  1250. priv->tkip_key[key_id].rx_mic,
  1251. desc->addr1,
  1252. src,
  1253. 0, /* priority or QoS? */
  1254. skb->data,
  1255. skb->len,
  1256. &mic[0]);
  1257. if (memcmp(mic, rxmic,
  1258. MICHAEL_MIC_LEN)) {
  1259. union iwreq_data wrqu;
  1260. struct iw_michaelmicfailure wxmic;
  1261. printk(KERN_WARNING "%s: "
  1262. "Invalid Michael MIC in data frame from %pM, "
  1263. "using key %i\n",
  1264. dev->name, src, key_id);
  1265. /* TODO: update stats */
  1266. /* Notify userspace */
  1267. memset(&wxmic, 0, sizeof(wxmic));
  1268. wxmic.flags = key_id & IW_MICFAILURE_KEY_ID;
  1269. wxmic.flags |= (desc->addr1[0] & 1) ?
  1270. IW_MICFAILURE_GROUP : IW_MICFAILURE_PAIRWISE;
  1271. wxmic.src_addr.sa_family = ARPHRD_ETHER;
  1272. memcpy(wxmic.src_addr.sa_data, src, ETH_ALEN);
  1273. (void) orinoco_hw_get_tkip_iv(priv, key_id,
  1274. &wxmic.tsc[0]);
  1275. memset(&wrqu, 0, sizeof(wrqu));
  1276. wrqu.data.length = sizeof(wxmic);
  1277. wireless_send_event(dev, IWEVMICHAELMICFAILURE, &wrqu,
  1278. (char *) &wxmic);
  1279. goto drop;
  1280. }
  1281. }
  1282. /* Handle decapsulation
  1283. * In most cases, the firmware tell us about SNAP frames.
  1284. * For some reason, the SNAP frames sent by LinkSys APs
  1285. * are not properly recognised by most firmwares.
  1286. * So, check ourselves */
  1287. if (length >= ENCAPS_OVERHEAD &&
  1288. (((status & HERMES_RXSTAT_MSGTYPE) == HERMES_RXSTAT_1042) ||
  1289. ((status & HERMES_RXSTAT_MSGTYPE) == HERMES_RXSTAT_TUNNEL) ||
  1290. is_ethersnap(skb->data))) {
  1291. /* These indicate a SNAP within 802.2 LLC within
  1292. 802.11 frame which we'll need to de-encapsulate to
  1293. the original EthernetII frame. */
  1294. hdr = (struct ethhdr *)skb_push(skb, ETH_HLEN - ENCAPS_OVERHEAD);
  1295. } else {
  1296. /* 802.3 frame - prepend 802.3 header as is */
  1297. hdr = (struct ethhdr *)skb_push(skb, ETH_HLEN);
  1298. hdr->h_proto = htons(length);
  1299. }
  1300. memcpy(hdr->h_dest, desc->addr1, ETH_ALEN);
  1301. if (fc & IEEE80211_FCTL_FROMDS)
  1302. memcpy(hdr->h_source, desc->addr3, ETH_ALEN);
  1303. else
  1304. memcpy(hdr->h_source, desc->addr2, ETH_ALEN);
  1305. skb->protocol = eth_type_trans(skb, dev);
  1306. skb->ip_summed = CHECKSUM_NONE;
  1307. if (fc & IEEE80211_FCTL_TODS)
  1308. skb->pkt_type = PACKET_OTHERHOST;
  1309. /* Process the wireless stats if needed */
  1310. orinoco_stat_gather(dev, skb, desc);
  1311. /* Pass the packet to the networking stack */
  1312. netif_rx(skb);
  1313. stats->rx_packets++;
  1314. stats->rx_bytes += length;
  1315. return;
  1316. drop:
  1317. dev_kfree_skb(skb);
  1318. stats->rx_errors++;
  1319. stats->rx_dropped++;
  1320. }
  1321. static void orinoco_rx_isr_tasklet(unsigned long data)
  1322. {
  1323. struct net_device *dev = (struct net_device *) data;
  1324. struct orinoco_private *priv = netdev_priv(dev);
  1325. struct orinoco_rx_data *rx_data, *temp;
  1326. struct hermes_rx_descriptor *desc;
  1327. struct sk_buff *skb;
  1328. /* extract desc and skb from queue */
  1329. list_for_each_entry_safe(rx_data, temp, &priv->rx_list, list) {
  1330. desc = rx_data->desc;
  1331. skb = rx_data->skb;
  1332. list_del(&rx_data->list);
  1333. kfree(rx_data);
  1334. orinoco_rx(dev, desc, skb);
  1335. kfree(desc);
  1336. }
  1337. }
  1338. /********************************************************************/
  1339. /* Rx path (info frames) */
  1340. /********************************************************************/
  1341. static void print_linkstatus(struct net_device *dev, u16 status)
  1342. {
  1343. char * s;
  1344. if (suppress_linkstatus)
  1345. return;
  1346. switch (status) {
  1347. case HERMES_LINKSTATUS_NOT_CONNECTED:
  1348. s = "Not Connected";
  1349. break;
  1350. case HERMES_LINKSTATUS_CONNECTED:
  1351. s = "Connected";
  1352. break;
  1353. case HERMES_LINKSTATUS_DISCONNECTED:
  1354. s = "Disconnected";
  1355. break;
  1356. case HERMES_LINKSTATUS_AP_CHANGE:
  1357. s = "AP Changed";
  1358. break;
  1359. case HERMES_LINKSTATUS_AP_OUT_OF_RANGE:
  1360. s = "AP Out of Range";
  1361. break;
  1362. case HERMES_LINKSTATUS_AP_IN_RANGE:
  1363. s = "AP In Range";
  1364. break;
  1365. case HERMES_LINKSTATUS_ASSOC_FAILED:
  1366. s = "Association Failed";
  1367. break;
  1368. default:
  1369. s = "UNKNOWN";
  1370. }
  1371. printk(KERN_INFO "%s: New link status: %s (%04x)\n",
  1372. dev->name, s, status);
  1373. }
  1374. /* Search scan results for requested BSSID, join it if found */
  1375. static void orinoco_join_ap(struct work_struct *work)
  1376. {
  1377. struct orinoco_private *priv =
  1378. container_of(work, struct orinoco_private, join_work);
  1379. struct net_device *dev = priv->ndev;
  1380. struct hermes *hw = &priv->hw;
  1381. int err;
  1382. unsigned long flags;
  1383. struct join_req {
  1384. u8 bssid[ETH_ALEN];
  1385. __le16 channel;
  1386. } __attribute__ ((packed)) req;
  1387. const int atom_len = offsetof(struct prism2_scan_apinfo, atim);
  1388. struct prism2_scan_apinfo *atom = NULL;
  1389. int offset = 4;
  1390. int found = 0;
  1391. u8 *buf;
  1392. u16 len;
  1393. /* Allocate buffer for scan results */
  1394. buf = kmalloc(MAX_SCAN_LEN, GFP_KERNEL);
  1395. if (! buf)
  1396. return;
  1397. if (orinoco_lock(priv, &flags) != 0)
  1398. goto fail_lock;
  1399. /* Sanity checks in case user changed something in the meantime */
  1400. if (! priv->bssid_fixed)
  1401. goto out;
  1402. if (strlen(priv->desired_essid) == 0)
  1403. goto out;
  1404. /* Read scan results from the firmware */
  1405. err = hermes_read_ltv(hw, USER_BAP,
  1406. HERMES_RID_SCANRESULTSTABLE,
  1407. MAX_SCAN_LEN, &len, buf);
  1408. if (err) {
  1409. printk(KERN_ERR "%s: Cannot read scan results\n",
  1410. dev->name);
  1411. goto out;
  1412. }
  1413. len = HERMES_RECLEN_TO_BYTES(len);
  1414. /* Go through the scan results looking for the channel of the AP
  1415. * we were requested to join */
  1416. for (; offset + atom_len <= len; offset += atom_len) {
  1417. atom = (struct prism2_scan_apinfo *) (buf + offset);
  1418. if (memcmp(&atom->bssid, priv->desired_bssid, ETH_ALEN) == 0) {
  1419. found = 1;
  1420. break;
  1421. }
  1422. }
  1423. if (! found) {
  1424. DEBUG(1, "%s: Requested AP not found in scan results\n",
  1425. dev->name);
  1426. goto out;
  1427. }
  1428. memcpy(req.bssid, priv->desired_bssid, ETH_ALEN);
  1429. req.channel = atom->channel; /* both are little-endian */
  1430. err = HERMES_WRITE_RECORD(hw, USER_BAP, HERMES_RID_CNFJOINREQUEST,
  1431. &req);
  1432. if (err)
  1433. printk(KERN_ERR "%s: Error issuing join request\n", dev->name);
  1434. out:
  1435. orinoco_unlock(priv, &flags);
  1436. fail_lock:
  1437. kfree(buf);
  1438. }
  1439. /* Send new BSSID to userspace */
  1440. static void orinoco_send_bssid_wevent(struct orinoco_private *priv)
  1441. {
  1442. struct net_device *dev = priv->ndev;
  1443. struct hermes *hw = &priv->hw;
  1444. union iwreq_data wrqu;
  1445. int err;
  1446. err = hermes_read_ltv(hw, IRQ_BAP, HERMES_RID_CURRENTBSSID,
  1447. ETH_ALEN, NULL, wrqu.ap_addr.sa_data);
  1448. if (err != 0)
  1449. return;
  1450. wrqu.ap_addr.sa_family = ARPHRD_ETHER;
  1451. /* Send event to user space */
  1452. wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL);
  1453. }
  1454. static void orinoco_send_assocreqie_wevent(struct orinoco_private *priv)
  1455. {
  1456. struct net_device *dev = priv->ndev;
  1457. struct hermes *hw = &priv->hw;
  1458. union iwreq_data wrqu;
  1459. int err;
  1460. u8 buf[88];
  1461. u8 *ie;
  1462. if (!priv->has_wpa)
  1463. return;
  1464. err = hermes_read_ltv(hw, IRQ_BAP, HERMES_RID_CURRENT_ASSOC_REQ_INFO,
  1465. sizeof(buf), NULL, &buf);
  1466. if (err != 0)
  1467. return;
  1468. ie = orinoco_get_wpa_ie(buf, sizeof(buf));
  1469. if (ie) {
  1470. int rem = sizeof(buf) - (ie - &buf[0]);
  1471. wrqu.data.length = ie[1] + 2;
  1472. if (wrqu.data.length > rem)
  1473. wrqu.data.length = rem;
  1474. if (wrqu.data.length)
  1475. /* Send event to user space */
  1476. wireless_send_event(dev, IWEVASSOCREQIE, &wrqu, ie);
  1477. }
  1478. }
  1479. static void orinoco_send_assocrespie_wevent(struct orinoco_private *priv)
  1480. {
  1481. struct net_device *dev = priv->ndev;
  1482. struct hermes *hw = &priv->hw;
  1483. union iwreq_data wrqu;
  1484. int err;
  1485. u8 buf[88]; /* TODO: verify max size or IW_GENERIC_IE_MAX */
  1486. u8 *ie;
  1487. if (!priv->has_wpa)
  1488. return;
  1489. err = hermes_read_ltv(hw, IRQ_BAP, HERMES_RID_CURRENT_ASSOC_RESP_INFO,
  1490. sizeof(buf), NULL, &buf);
  1491. if (err != 0)
  1492. return;
  1493. ie = orinoco_get_wpa_ie(buf, sizeof(buf));
  1494. if (ie) {
  1495. int rem = sizeof(buf) - (ie - &buf[0]);
  1496. wrqu.data.length = ie[1] + 2;
  1497. if (wrqu.data.length > rem)
  1498. wrqu.data.length = rem;
  1499. if (wrqu.data.length)
  1500. /* Send event to user space */
  1501. wireless_send_event(dev, IWEVASSOCRESPIE, &wrqu, ie);
  1502. }
  1503. }
  1504. static void orinoco_send_wevents(struct work_struct *work)
  1505. {
  1506. struct orinoco_private *priv =
  1507. container_of(work, struct orinoco_private, wevent_work);
  1508. unsigned long flags;
  1509. if (orinoco_lock(priv, &flags) != 0)
  1510. return;
  1511. orinoco_send_assocreqie_wevent(priv);
  1512. orinoco_send_assocrespie_wevent(priv);
  1513. orinoco_send_bssid_wevent(priv);
  1514. orinoco_unlock(priv, &flags);
  1515. }
  1516. static inline void orinoco_clear_scan_results(struct orinoco_private *priv,
  1517. unsigned long scan_age)
  1518. {
  1519. if (priv->has_ext_scan) {
  1520. struct xbss_element *bss;
  1521. struct xbss_element *tmp_bss;
  1522. /* Blow away current list of scan results */
  1523. list_for_each_entry_safe(bss, tmp_bss, &priv->bss_list, list) {
  1524. if (!scan_age ||
  1525. time_after(jiffies, bss->last_scanned + scan_age)) {
  1526. list_move_tail(&bss->list,
  1527. &priv->bss_free_list);
  1528. /* Don't blow away ->list, just BSS data */
  1529. memset(&bss->bss, 0, sizeof(bss->bss));
  1530. bss->last_scanned = 0;
  1531. }
  1532. }
  1533. } else {
  1534. struct bss_element *bss;
  1535. struct bss_element *tmp_bss;
  1536. /* Blow away current list of scan results */
  1537. list_for_each_entry_safe(bss, tmp_bss, &priv->bss_list, list) {
  1538. if (!scan_age ||
  1539. time_after(jiffies, bss->last_scanned + scan_age)) {
  1540. list_move_tail(&bss->list,
  1541. &priv->bss_free_list);
  1542. /* Don't blow away ->list, just BSS data */
  1543. memset(&bss->bss, 0, sizeof(bss->bss));
  1544. bss->last_scanned = 0;
  1545. }
  1546. }
  1547. }
  1548. }
  1549. static void orinoco_add_ext_scan_result(struct orinoco_private *priv,
  1550. struct agere_ext_scan_info *atom)
  1551. {
  1552. struct xbss_element *bss = NULL;
  1553. int found = 0;
  1554. /* Try to update an existing bss first */
  1555. list_for_each_entry(bss, &priv->bss_list, list) {
  1556. if (compare_ether_addr(bss->bss.bssid, atom->bssid))
  1557. continue;
  1558. /* ESSID lengths */
  1559. if (bss->bss.data[1] != atom->data[1])
  1560. continue;
  1561. if (memcmp(&bss->bss.data[2], &atom->data[2],
  1562. atom->data[1]))
  1563. continue;
  1564. found = 1;
  1565. break;
  1566. }
  1567. /* Grab a bss off the free list */
  1568. if (!found && !list_empty(&priv->bss_free_list)) {
  1569. bss = list_entry(priv->bss_free_list.next,
  1570. struct xbss_element, list);
  1571. list_del(priv->bss_free_list.next);
  1572. list_add_tail(&bss->list, &priv->bss_list);
  1573. }
  1574. if (bss) {
  1575. /* Always update the BSS to get latest beacon info */
  1576. memcpy(&bss->bss, atom, sizeof(bss->bss));
  1577. bss->last_scanned = jiffies;
  1578. }
  1579. }
  1580. static int orinoco_process_scan_results(struct net_device *dev,
  1581. unsigned char *buf,
  1582. int len)
  1583. {
  1584. struct orinoco_private *priv = netdev_priv(dev);
  1585. int offset; /* In the scan data */
  1586. union hermes_scan_info *atom;
  1587. int atom_len;
  1588. switch (priv->firmware_type) {
  1589. case FIRMWARE_TYPE_AGERE:
  1590. atom_len = sizeof(struct agere_scan_apinfo);
  1591. offset = 0;
  1592. break;
  1593. case FIRMWARE_TYPE_SYMBOL:
  1594. /* Lack of documentation necessitates this hack.
  1595. * Different firmwares have 68 or 76 byte long atoms.
  1596. * We try modulo first. If the length divides by both,
  1597. * we check what would be the channel in the second
  1598. * frame for a 68-byte atom. 76-byte atoms have 0 there.
  1599. * Valid channel cannot be 0. */
  1600. if (len % 76)
  1601. atom_len = 68;
  1602. else if (len % 68)
  1603. atom_len = 76;
  1604. else if (len >= 1292 && buf[68] == 0)
  1605. atom_len = 76;
  1606. else
  1607. atom_len = 68;
  1608. offset = 0;
  1609. break;
  1610. case FIRMWARE_TYPE_INTERSIL:
  1611. offset = 4;
  1612. if (priv->has_hostscan) {
  1613. atom_len = le16_to_cpup((__le16 *)buf);
  1614. /* Sanity check for atom_len */
  1615. if (atom_len < sizeof(struct prism2_scan_apinfo)) {
  1616. printk(KERN_ERR "%s: Invalid atom_len in scan "
  1617. "data: %d\n", dev->name, atom_len);
  1618. return -EIO;
  1619. }
  1620. } else
  1621. atom_len = offsetof(struct prism2_scan_apinfo, atim);
  1622. break;
  1623. default:
  1624. return -EOPNOTSUPP;
  1625. }
  1626. /* Check that we got an whole number of atoms */
  1627. if ((len - offset) % atom_len) {
  1628. printk(KERN_ERR "%s: Unexpected scan data length %d, "
  1629. "atom_len %d, offset %d\n", dev->name, len,
  1630. atom_len, offset);
  1631. return -EIO;
  1632. }
  1633. orinoco_clear_scan_results(priv, msecs_to_jiffies(15000));
  1634. /* Read the entries one by one */
  1635. for (; offset + atom_len <= len; offset += atom_len) {
  1636. int found = 0;
  1637. struct bss_element *bss = NULL;
  1638. /* Get next atom */
  1639. atom = (union hermes_scan_info *) (buf + offset);
  1640. /* Try to update an existing bss first */
  1641. list_for_each_entry(bss, &priv->bss_list, list) {
  1642. if (compare_ether_addr(bss->bss.a.bssid, atom->a.bssid))
  1643. continue;
  1644. if (le16_to_cpu(bss->bss.a.essid_len) !=
  1645. le16_to_cpu(atom->a.essid_len))
  1646. continue;
  1647. if (memcmp(bss->bss.a.essid, atom->a.essid,
  1648. le16_to_cpu(atom->a.essid_len)))
  1649. continue;
  1650. found = 1;
  1651. break;
  1652. }
  1653. /* Grab a bss off the free list */
  1654. if (!found && !list_empty(&priv->bss_free_list)) {
  1655. bss = list_entry(priv->bss_free_list.next,
  1656. struct bss_element, list);
  1657. list_del(priv->bss_free_list.next);
  1658. list_add_tail(&bss->list, &priv->bss_list);
  1659. }
  1660. if (bss) {
  1661. /* Always update the BSS to get latest beacon info */
  1662. memcpy(&bss->bss, atom, sizeof(bss->bss));
  1663. bss->last_scanned = jiffies;
  1664. }
  1665. }
  1666. return 0;
  1667. }
  1668. static void __orinoco_ev_info(struct net_device *dev, hermes_t *hw)
  1669. {
  1670. struct orinoco_private *priv = netdev_priv(dev);
  1671. u16 infofid;
  1672. struct {
  1673. __le16 len;
  1674. __le16 type;
  1675. } __attribute__ ((packed)) info;
  1676. int len, type;
  1677. int err;
  1678. /* This is an answer to an INQUIRE command that we did earlier,
  1679. * or an information "event" generated by the card
  1680. * The controller return to us a pseudo frame containing
  1681. * the information in question - Jean II */
  1682. infofid = hermes_read_regn(hw, INFOFID);
  1683. /* Read the info frame header - don't try too hard */
  1684. err = hermes_bap_pread(hw, IRQ_BAP, &info, sizeof(info),
  1685. infofid, 0);
  1686. if (err) {
  1687. printk(KERN_ERR "%s: error %d reading info frame. "
  1688. "Frame dropped.\n", dev->name, err);
  1689. return;
  1690. }
  1691. len = HERMES_RECLEN_TO_BYTES(le16_to_cpu(info.len));
  1692. type = le16_to_cpu(info.type);
  1693. switch (type) {
  1694. case HERMES_INQ_TALLIES: {
  1695. struct hermes_tallies_frame tallies;
  1696. struct iw_statistics *wstats = &priv->wstats;
  1697. if (len > sizeof(tallies)) {
  1698. printk(KERN_WARNING "%s: Tallies frame too long (%d bytes)\n",
  1699. dev->name, len);
  1700. len = sizeof(tallies);
  1701. }
  1702. err = hermes_bap_pread(hw, IRQ_BAP, &tallies, len,
  1703. infofid, sizeof(info));
  1704. if (err)
  1705. break;
  1706. /* Increment our various counters */
  1707. /* wstats->discard.nwid - no wrong BSSID stuff */
  1708. wstats->discard.code +=
  1709. le16_to_cpu(tallies.RxWEPUndecryptable);
  1710. if (len == sizeof(tallies))
  1711. wstats->discard.code +=
  1712. le16_to_cpu(tallies.RxDiscards_WEPICVError) +
  1713. le16_to_cpu(tallies.RxDiscards_WEPExcluded);
  1714. wstats->discard.misc +=
  1715. le16_to_cpu(tallies.TxDiscardsWrongSA);
  1716. wstats->discard.fragment +=
  1717. le16_to_cpu(tallies.RxMsgInBadMsgFragments);
  1718. wstats->discard.retries +=
  1719. le16_to_cpu(tallies.TxRetryLimitExceeded);
  1720. /* wstats->miss.beacon - no match */
  1721. }
  1722. break;
  1723. case HERMES_INQ_LINKSTATUS: {
  1724. struct hermes_linkstatus linkstatus;
  1725. u16 newstatus;
  1726. int connected;
  1727. if (priv->iw_mode == IW_MODE_MONITOR)
  1728. break;
  1729. if (len != sizeof(linkstatus)) {
  1730. printk(KERN_WARNING "%s: Unexpected size for linkstatus frame (%d bytes)\n",
  1731. dev->name, len);
  1732. break;
  1733. }
  1734. err = hermes_bap_pread(hw, IRQ_BAP, &linkstatus, len,
  1735. infofid, sizeof(info));
  1736. if (err)
  1737. break;
  1738. newstatus = le16_to_cpu(linkstatus.linkstatus);
  1739. /* Symbol firmware uses "out of range" to signal that
  1740. * the hostscan frame can be requested. */
  1741. if (newstatus == HERMES_LINKSTATUS_AP_OUT_OF_RANGE &&
  1742. priv->firmware_type == FIRMWARE_TYPE_SYMBOL &&
  1743. priv->has_hostscan && priv->scan_inprogress) {
  1744. hermes_inquire(hw, HERMES_INQ_HOSTSCAN_SYMBOL);
  1745. break;
  1746. }
  1747. connected = (newstatus == HERMES_LINKSTATUS_CONNECTED)
  1748. || (newstatus == HERMES_LINKSTATUS_AP_CHANGE)
  1749. || (newstatus == HERMES_LINKSTATUS_AP_IN_RANGE);
  1750. if (connected)
  1751. netif_carrier_on(dev);
  1752. else if (!ignore_disconnect)
  1753. netif_carrier_off(dev);
  1754. if (newstatus != priv->last_linkstatus) {
  1755. priv->last_linkstatus = newstatus;
  1756. print_linkstatus(dev, newstatus);
  1757. /* The info frame contains only one word which is the
  1758. * status (see hermes.h). The status is pretty boring
  1759. * in itself, that's why we export the new BSSID...
  1760. * Jean II */
  1761. schedule_work(&priv->wevent_work);
  1762. }
  1763. }
  1764. break;
  1765. case HERMES_INQ_SCAN:
  1766. if (!priv->scan_inprogress && priv->bssid_fixed &&
  1767. priv->firmware_type == FIRMWARE_TYPE_INTERSIL) {
  1768. schedule_work(&priv->join_work);
  1769. break;
  1770. }
  1771. /* fall through */
  1772. case HERMES_INQ_HOSTSCAN:
  1773. case HERMES_INQ_HOSTSCAN_SYMBOL: {
  1774. /* Result of a scanning. Contains information about
  1775. * cells in the vicinity - Jean II */
  1776. union iwreq_data wrqu;
  1777. unsigned char *buf;
  1778. /* Scan is no longer in progress */
  1779. priv->scan_inprogress = 0;
  1780. /* Sanity check */
  1781. if (len > 4096) {
  1782. printk(KERN_WARNING "%s: Scan results too large (%d bytes)\n",
  1783. dev->name, len);
  1784. break;
  1785. }
  1786. /* Allocate buffer for results */
  1787. buf = kmalloc(len, GFP_ATOMIC);
  1788. if (buf == NULL)
  1789. /* No memory, so can't printk()... */
  1790. break;
  1791. /* Read scan data */
  1792. err = hermes_bap_pread(hw, IRQ_BAP, (void *) buf, len,
  1793. infofid, sizeof(info));
  1794. if (err) {
  1795. kfree(buf);
  1796. break;
  1797. }
  1798. #ifdef ORINOCO_DEBUG
  1799. {
  1800. int i;
  1801. printk(KERN_DEBUG "Scan result [%02X", buf[0]);
  1802. for(i = 1; i < (len * 2); i++)
  1803. printk(":%02X", buf[i]);
  1804. printk("]\n");
  1805. }
  1806. #endif /* ORINOCO_DEBUG */
  1807. if (orinoco_process_scan_results(dev, buf, len) == 0) {
  1808. /* Send an empty event to user space.
  1809. * We don't send the received data on the event because
  1810. * it would require us to do complex transcoding, and
  1811. * we want to minimise the work done in the irq handler
  1812. * Use a request to extract the data - Jean II */
  1813. wrqu.data.length = 0;
  1814. wrqu.data.flags = 0;
  1815. wireless_send_event(dev, SIOCGIWSCAN, &wrqu, NULL);
  1816. }
  1817. kfree(buf);
  1818. }
  1819. break;
  1820. case HERMES_INQ_CHANNELINFO:
  1821. {
  1822. struct agere_ext_scan_info *bss;
  1823. if (!priv->scan_inprogress) {
  1824. printk(KERN_DEBUG "%s: Got chaninfo without scan, "
  1825. "len=%d\n", dev->name, len);
  1826. break;
  1827. }
  1828. /* An empty result indicates that the scan is complete */
  1829. if (len == 0) {
  1830. union iwreq_data wrqu;
  1831. /* Scan is no longer in progress */
  1832. priv->scan_inprogress = 0;
  1833. wrqu.data.length = 0;
  1834. wrqu.data.flags = 0;
  1835. wireless_send_event(dev, SIOCGIWSCAN, &wrqu, NULL);
  1836. break;
  1837. }
  1838. /* Sanity check */
  1839. else if (len > sizeof(*bss)) {
  1840. printk(KERN_WARNING
  1841. "%s: Ext scan results too large (%d bytes). "
  1842. "Truncating results to %zd bytes.\n",
  1843. dev->name, len, sizeof(*bss));
  1844. len = sizeof(*bss);
  1845. } else if (len < (offsetof(struct agere_ext_scan_info,
  1846. data) + 2)) {
  1847. /* Drop this result now so we don't have to
  1848. * keep checking later */
  1849. printk(KERN_WARNING
  1850. "%s: Ext scan results too short (%d bytes)\n",
  1851. dev->name, len);
  1852. break;
  1853. }
  1854. bss = kmalloc(sizeof(*bss), GFP_ATOMIC);
  1855. if (bss == NULL)
  1856. break;
  1857. /* Read scan data */
  1858. err = hermes_bap_pread(hw, IRQ_BAP, (void *) bss, len,
  1859. infofid, sizeof(info));
  1860. if (err) {
  1861. kfree(bss);
  1862. break;
  1863. }
  1864. orinoco_add_ext_scan_result(priv, bss);
  1865. kfree(bss);
  1866. break;
  1867. }
  1868. case HERMES_INQ_SEC_STAT_AGERE:
  1869. /* Security status (Agere specific) */
  1870. /* Ignore this frame for now */
  1871. if (priv->firmware_type == FIRMWARE_TYPE_AGERE)
  1872. break;
  1873. /* fall through */
  1874. default:
  1875. printk(KERN_DEBUG "%s: Unknown information frame received: "
  1876. "type 0x%04x, length %d\n", dev->name, type, len);
  1877. /* We don't actually do anything about it */
  1878. break;
  1879. }
  1880. }
  1881. static void __orinoco_ev_infdrop(struct net_device *dev, hermes_t *hw)
  1882. {
  1883. if (net_ratelimit())
  1884. printk(KERN_DEBUG "%s: Information frame lost.\n", dev->name);
  1885. }
  1886. /********************************************************************/
  1887. /* Internal hardware control routines */
  1888. /********************************************************************/
  1889. int __orinoco_up(struct net_device *dev)
  1890. {
  1891. struct orinoco_private *priv = netdev_priv(dev);
  1892. struct hermes *hw = &priv->hw;
  1893. int err;
  1894. netif_carrier_off(dev); /* just to make sure */
  1895. err = __orinoco_program_rids(dev);
  1896. if (err) {
  1897. printk(KERN_ERR "%s: Error %d configuring card\n",
  1898. dev->name, err);
  1899. return err;
  1900. }
  1901. /* Fire things up again */
  1902. hermes_set_irqmask(hw, ORINOCO_INTEN);
  1903. err = hermes_enable_port(hw, 0);
  1904. if (err) {
  1905. printk(KERN_ERR "%s: Error %d enabling MAC port\n",
  1906. dev->name, err);
  1907. return err;
  1908. }
  1909. netif_start_queue(dev);
  1910. return 0;
  1911. }
  1912. int __orinoco_down(struct net_device *dev)
  1913. {
  1914. struct orinoco_private *priv = netdev_priv(dev);
  1915. struct hermes *hw = &priv->hw;
  1916. int err;
  1917. netif_stop_queue(dev);
  1918. if (! priv->hw_unavailable) {
  1919. if (! priv->broken_disableport) {
  1920. err = hermes_disable_port(hw, 0);
  1921. if (err) {
  1922. /* Some firmwares (e.g. Intersil 1.3.x) seem
  1923. * to have problems disabling the port, oh
  1924. * well, too bad. */
  1925. printk(KERN_WARNING "%s: Error %d disabling MAC port\n",
  1926. dev->name, err);
  1927. priv->broken_disableport = 1;
  1928. }
  1929. }
  1930. hermes_set_irqmask(hw, 0);
  1931. hermes_write_regn(hw, EVACK, 0xffff);
  1932. }
  1933. /* firmware will have to reassociate */
  1934. netif_carrier_off(dev);
  1935. priv->last_linkstatus = 0xffff;
  1936. return 0;
  1937. }
  1938. static int orinoco_allocate_fid(struct net_device *dev)
  1939. {
  1940. struct orinoco_private *priv = netdev_priv(dev);
  1941. struct hermes *hw = &priv->hw;
  1942. int err;
  1943. err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid);
  1944. if (err == -EIO && priv->nicbuf_size > TX_NICBUF_SIZE_BUG) {
  1945. /* Try workaround for old Symbol firmware bug */
  1946. printk(KERN_WARNING "%s: firmware ALLOC bug detected "
  1947. "(old Symbol firmware?). Trying to work around... ",
  1948. dev->name);
  1949. priv->nicbuf_size = TX_NICBUF_SIZE_BUG;
  1950. err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid);
  1951. if (err)
  1952. printk("failed!\n");
  1953. else
  1954. printk("ok.\n");
  1955. }
  1956. return err;
  1957. }
  1958. int orinoco_reinit_firmware(struct net_device *dev)
  1959. {
  1960. struct orinoco_private *priv = netdev_priv(dev);
  1961. struct hermes *hw = &priv->hw;
  1962. int err;
  1963. err = hermes_init(hw);
  1964. if (priv->do_fw_download && !err) {
  1965. err = orinoco_download(priv);
  1966. if (err)
  1967. priv->do_fw_download = 0;
  1968. }
  1969. if (!err)
  1970. err = orinoco_allocate_fid(dev);
  1971. return err;
  1972. }
  1973. static int __orinoco_hw_set_bitrate(struct orinoco_private *priv)
  1974. {
  1975. hermes_t *hw = &priv->hw;
  1976. int err = 0;
  1977. if (priv->bitratemode >= BITRATE_TABLE_SIZE) {
  1978. printk(KERN_ERR "%s: BUG: Invalid bitrate mode %d\n",
  1979. priv->ndev->name, priv->bitratemode);
  1980. return -EINVAL;
  1981. }
  1982. switch (priv->firmware_type) {
  1983. case FIRMWARE_TYPE_AGERE:
  1984. err = hermes_write_wordrec(hw, USER_BAP,
  1985. HERMES_RID_CNFTXRATECONTROL,
  1986. bitrate_table[priv->bitratemode].agere_txratectrl);
  1987. break;
  1988. case FIRMWARE_TYPE_INTERSIL:
  1989. case FIRMWARE_TYPE_SYMBOL:
  1990. err = hermes_write_wordrec(hw, USER_BAP,
  1991. HERMES_RID_CNFTXRATECONTROL,
  1992. bitrate_table[priv->bitratemode].intersil_txratectrl);
  1993. break;
  1994. default:
  1995. BUG();
  1996. }
  1997. return err;
  1998. }
  1999. /* Set fixed AP address */
  2000. static int __orinoco_hw_set_wap(struct orinoco_private *priv)
  2001. {
  2002. int roaming_flag;
  2003. int err = 0;
  2004. hermes_t *hw = &priv->hw;
  2005. switch (priv->firmware_type) {
  2006. case FIRMWARE_TYPE_AGERE:
  2007. /* not supported */
  2008. break;
  2009. case FIRMWARE_TYPE_INTERSIL:
  2010. if (priv->bssid_fixed)
  2011. roaming_flag = 2;
  2012. else
  2013. roaming_flag = 1;
  2014. err = hermes_write_wordrec(hw, USER_BAP,
  2015. HERMES_RID_CNFROAMINGMODE,
  2016. roaming_flag);
  2017. break;
  2018. case FIRMWARE_TYPE_SYMBOL:
  2019. err = HERMES_WRITE_RECORD(hw, USER_BAP,
  2020. HERMES_RID_CNFMANDATORYBSSID_SYMBOL,
  2021. &priv->desired_bssid);
  2022. break;
  2023. }
  2024. return err;
  2025. }
  2026. /* Change the WEP keys and/or the current keys. Can be called
  2027. * either from __orinoco_hw_setup_enc() or directly from
  2028. * orinoco_ioctl_setiwencode(). In the later case the association
  2029. * with the AP is not broken (if the firmware can handle it),
  2030. * which is needed for 802.1x implementations. */
  2031. static int __orinoco_hw_setup_wepkeys(struct orinoco_private *priv)
  2032. {
  2033. hermes_t *hw = &priv->hw;
  2034. int err = 0;
  2035. switch (priv->firmware_type) {
  2036. case FIRMWARE_TYPE_AGERE:
  2037. err = HERMES_WRITE_RECORD(hw, USER_BAP,
  2038. HERMES_RID_CNFWEPKEYS_AGERE,
  2039. &priv->keys);
  2040. if (err)
  2041. return err;
  2042. err = hermes_write_wordrec(hw, USER_BAP,
  2043. HERMES_RID_CNFTXKEY_AGERE,
  2044. priv->tx_key);
  2045. if (err)
  2046. return err;
  2047. break;
  2048. case FIRMWARE_TYPE_INTERSIL:
  2049. case FIRMWARE_TYPE_SYMBOL:
  2050. {
  2051. int keylen;
  2052. int i;
  2053. /* Force uniform key length to work around firmware bugs */
  2054. keylen = le16_to_cpu(priv->keys[priv->tx_key].len);
  2055. if (keylen > LARGE_KEY_SIZE) {
  2056. printk(KERN_ERR "%s: BUG: Key %d has oversize length %d.\n",
  2057. priv->ndev->name, priv->tx_key, keylen);
  2058. return -E2BIG;
  2059. }
  2060. /* Write all 4 keys */
  2061. for(i = 0; i < ORINOCO_MAX_KEYS; i++) {
  2062. err = hermes_write_ltv(hw, USER_BAP,
  2063. HERMES_RID_CNFDEFAULTKEY0 + i,
  2064. HERMES_BYTES_TO_RECLEN(keylen),
  2065. priv->keys[i].data);
  2066. if (err)
  2067. return err;
  2068. }
  2069. /* Write the index of the key used in transmission */
  2070. err = hermes_write_wordrec(hw, USER_BAP,
  2071. HERMES_RID_CNFWEPDEFAULTKEYID,
  2072. priv->tx_key);
  2073. if (err)
  2074. return err;
  2075. }
  2076. break;
  2077. }
  2078. return 0;
  2079. }
  2080. static int __orinoco_hw_setup_enc(struct orinoco_private *priv)
  2081. {
  2082. hermes_t *hw = &priv->hw;
  2083. int err = 0;
  2084. int master_wep_flag;
  2085. int auth_flag;
  2086. int enc_flag;
  2087. /* Setup WEP keys for WEP and WPA */
  2088. if (priv->encode_alg)
  2089. __orinoco_hw_setup_wepkeys(priv);
  2090. if (priv->wep_restrict)
  2091. auth_flag = HERMES_AUTH_SHARED_KEY;
  2092. else
  2093. auth_flag = HERMES_AUTH_OPEN;
  2094. if (priv->wpa_enabled)
  2095. enc_flag = 2;
  2096. else if (priv->encode_alg == IW_ENCODE_ALG_WEP)
  2097. enc_flag = 1;
  2098. else
  2099. enc_flag = 0;
  2100. switch (priv->firmware_type) {
  2101. case FIRMWARE_TYPE_AGERE: /* Agere style WEP */
  2102. if (priv->encode_alg == IW_ENCODE_ALG_WEP) {
  2103. /* Enable the shared-key authentication. */
  2104. err = hermes_write_wordrec(hw, USER_BAP,
  2105. HERMES_RID_CNFAUTHENTICATION_AGERE,
  2106. auth_flag);
  2107. }
  2108. err = hermes_write_wordrec(hw, USER_BAP,
  2109. HERMES_RID_CNFWEPENABLED_AGERE,
  2110. enc_flag);
  2111. if (err)
  2112. return err;
  2113. if (priv->has_wpa) {
  2114. /* Set WPA key management */
  2115. err = hermes_write_wordrec(hw, USER_BAP,
  2116. HERMES_RID_CNFSETWPAAUTHMGMTSUITE_AGERE,
  2117. priv->key_mgmt);
  2118. if (err)
  2119. return err;
  2120. }
  2121. break;
  2122. case FIRMWARE_TYPE_INTERSIL: /* Intersil style WEP */
  2123. case FIRMWARE_TYPE_SYMBOL: /* Symbol style WEP */
  2124. if (priv->encode_alg == IW_ENCODE_ALG_WEP) {
  2125. if (priv->wep_restrict ||
  2126. (priv->firmware_type == FIRMWARE_TYPE_SYMBOL))
  2127. master_wep_flag = HERMES_WEP_PRIVACY_INVOKED |
  2128. HERMES_WEP_EXCL_UNENCRYPTED;
  2129. else
  2130. master_wep_flag = HERMES_WEP_PRIVACY_INVOKED;
  2131. err = hermes_write_wordrec(hw, USER_BAP,
  2132. HERMES_RID_CNFAUTHENTICATION,
  2133. auth_flag);
  2134. if (err)
  2135. return err;
  2136. } else
  2137. master_wep_flag = 0;
  2138. if (priv->iw_mode == IW_MODE_MONITOR)
  2139. master_wep_flag |= HERMES_WEP_HOST_DECRYPT;
  2140. /* Master WEP setting : on/off */
  2141. err = hermes_write_wordrec(hw, USER_BAP,
  2142. HERMES_RID_CNFWEPFLAGS_INTERSIL,
  2143. master_wep_flag);
  2144. if (err)
  2145. return err;
  2146. break;
  2147. }
  2148. return 0;
  2149. }
  2150. /* key must be 32 bytes, including the tx and rx MIC keys.
  2151. * rsc must be 8 bytes
  2152. * tsc must be 8 bytes or NULL
  2153. */
  2154. static int __orinoco_hw_set_tkip_key(hermes_t *hw, int key_idx, int set_tx,
  2155. u8 *key, u8 *rsc, u8 *tsc)
  2156. {
  2157. struct {
  2158. __le16 idx;
  2159. u8 rsc[IW_ENCODE_SEQ_MAX_SIZE];
  2160. u8 key[TKIP_KEYLEN];
  2161. u8 tx_mic[MIC_KEYLEN];
  2162. u8 rx_mic[MIC_KEYLEN];
  2163. u8 tsc[IW_ENCODE_SEQ_MAX_SIZE];
  2164. } __attribute__ ((packed)) buf;
  2165. int ret;
  2166. int err;
  2167. int k;
  2168. u16 xmitting;
  2169. key_idx &= 0x3;
  2170. if (set_tx)
  2171. key_idx |= 0x8000;
  2172. buf.idx = cpu_to_le16(key_idx);
  2173. memcpy(buf.key, key,
  2174. sizeof(buf.key) + sizeof(buf.tx_mic) + sizeof(buf.rx_mic));
  2175. if (rsc == NULL)
  2176. memset(buf.rsc, 0, sizeof(buf.rsc));
  2177. else
  2178. memcpy(buf.rsc, rsc, sizeof(buf.rsc));
  2179. if (tsc == NULL) {
  2180. memset(buf.tsc, 0, sizeof(buf.tsc));
  2181. buf.tsc[4] = 0x10;
  2182. } else {
  2183. memcpy(buf.tsc, tsc, sizeof(buf.tsc));
  2184. }
  2185. /* Wait upto 100ms for tx queue to empty */
  2186. k = 100;
  2187. do {
  2188. k--;
  2189. udelay(1000);
  2190. ret = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_TXQUEUEEMPTY,
  2191. &xmitting);
  2192. if (ret)
  2193. break;
  2194. } while ((k > 0) && xmitting);
  2195. if (k == 0)
  2196. ret = -ETIMEDOUT;
  2197. err = HERMES_WRITE_RECORD(hw, USER_BAP,
  2198. HERMES_RID_CNFADDDEFAULTTKIPKEY_AGERE,
  2199. &buf);
  2200. return ret ? ret : err;
  2201. }
  2202. static int orinoco_clear_tkip_key(struct orinoco_private *priv,
  2203. int key_idx)
  2204. {
  2205. hermes_t *hw = &priv->hw;
  2206. int err;
  2207. memset(&priv->tkip_key[key_idx], 0, sizeof(priv->tkip_key[key_idx]));
  2208. err = hermes_write_wordrec(hw, USER_BAP,
  2209. HERMES_RID_CNFREMDEFAULTTKIPKEY_AGERE,
  2210. key_idx);
  2211. if (err)
  2212. printk(KERN_WARNING "%s: Error %d clearing TKIP key %d\n",
  2213. priv->ndev->name, err, key_idx);
  2214. return err;
  2215. }
  2216. static int __orinoco_program_rids(struct net_device *dev)
  2217. {
  2218. struct orinoco_private *priv = netdev_priv(dev);
  2219. hermes_t *hw = &priv->hw;
  2220. int err;
  2221. struct hermes_idstring idbuf;
  2222. /* Set the MAC address */
  2223. err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNMACADDR,
  2224. HERMES_BYTES_TO_RECLEN(ETH_ALEN), dev->dev_addr);
  2225. if (err) {
  2226. printk(KERN_ERR "%s: Error %d setting MAC address\n",
  2227. dev->name, err);
  2228. return err;
  2229. }
  2230. /* Set up the link mode */
  2231. err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFPORTTYPE,
  2232. priv->port_type);
  2233. if (err) {
  2234. printk(KERN_ERR "%s: Error %d setting port type\n",
  2235. dev->name, err);
  2236. return err;
  2237. }
  2238. /* Set the channel/frequency */
  2239. if (priv->channel != 0 && priv->iw_mode != IW_MODE_INFRA) {
  2240. err = hermes_write_wordrec(hw, USER_BAP,
  2241. HERMES_RID_CNFOWNCHANNEL,
  2242. priv->channel);
  2243. if (err) {
  2244. printk(KERN_ERR "%s: Error %d setting channel %d\n",
  2245. dev->name, err, priv->channel);
  2246. return err;
  2247. }
  2248. }
  2249. if (priv->has_ibss) {
  2250. u16 createibss;
  2251. if ((strlen(priv->desired_essid) == 0) && (priv->createibss)) {
  2252. printk(KERN_WARNING "%s: This firmware requires an "
  2253. "ESSID in IBSS-Ad-Hoc mode.\n", dev->name);
  2254. /* With wvlan_cs, in this case, we would crash.
  2255. * hopefully, this driver will behave better...
  2256. * Jean II */
  2257. createibss = 0;
  2258. } else {
  2259. createibss = priv->createibss;
  2260. }
  2261. err = hermes_write_wordrec(hw, USER_BAP,
  2262. HERMES_RID_CNFCREATEIBSS,
  2263. createibss);
  2264. if (err) {
  2265. printk(KERN_ERR "%s: Error %d setting CREATEIBSS\n",
  2266. dev->name, err);
  2267. return err;
  2268. }
  2269. }
  2270. /* Set the desired BSSID */
  2271. err = __orinoco_hw_set_wap(priv);
  2272. if (err) {
  2273. printk(KERN_ERR "%s: Error %d setting AP address\n",
  2274. dev->name, err);
  2275. return err;
  2276. }
  2277. /* Set the desired ESSID */
  2278. idbuf.len = cpu_to_le16(strlen(priv->desired_essid));
  2279. memcpy(&idbuf.val, priv->desired_essid, sizeof(idbuf.val));
  2280. /* WinXP wants partner to configure OWNSSID even in IBSS mode. (jimc) */
  2281. err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNSSID,
  2282. HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid)+2),
  2283. &idbuf);
  2284. if (err) {
  2285. printk(KERN_ERR "%s: Error %d setting OWNSSID\n",
  2286. dev->name, err);
  2287. return err;
  2288. }
  2289. err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFDESIREDSSID,
  2290. HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid)+2),
  2291. &idbuf);
  2292. if (err) {
  2293. printk(KERN_ERR "%s: Error %d setting DESIREDSSID\n",
  2294. dev->name, err);
  2295. return err;
  2296. }
  2297. /* Set the station name */
  2298. idbuf.len = cpu_to_le16(strlen(priv->nick));
  2299. memcpy(&idbuf.val, priv->nick, sizeof(idbuf.val));
  2300. err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNNAME,
  2301. HERMES_BYTES_TO_RECLEN(strlen(priv->nick)+2),
  2302. &idbuf);
  2303. if (err) {
  2304. printk(KERN_ERR "%s: Error %d setting nickname\n",
  2305. dev->name, err);
  2306. return err;
  2307. }
  2308. /* Set AP density */
  2309. if (priv->has_sensitivity) {
  2310. err = hermes_write_wordrec(hw, USER_BAP,
  2311. HERMES_RID_CNFSYSTEMSCALE,
  2312. priv->ap_density);
  2313. if (err) {
  2314. printk(KERN_WARNING "%s: Error %d setting SYSTEMSCALE. "
  2315. "Disabling sensitivity control\n",
  2316. dev->name, err);
  2317. priv->has_sensitivity = 0;
  2318. }
  2319. }
  2320. /* Set RTS threshold */
  2321. err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFRTSTHRESHOLD,
  2322. priv->rts_thresh);
  2323. if (err) {
  2324. printk(KERN_ERR "%s: Error %d setting RTS threshold\n",
  2325. dev->name, err);
  2326. return err;
  2327. }
  2328. /* Set fragmentation threshold or MWO robustness */
  2329. if (priv->has_mwo)
  2330. err = hermes_write_wordrec(hw, USER_BAP,
  2331. HERMES_RID_CNFMWOROBUST_AGERE,
  2332. priv->mwo_robust);
  2333. else
  2334. err = hermes_write_wordrec(hw, USER_BAP,
  2335. HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
  2336. priv->frag_thresh);
  2337. if (err) {
  2338. printk(KERN_ERR "%s: Error %d setting fragmentation\n",
  2339. dev->name, err);
  2340. return err;
  2341. }
  2342. /* Set bitrate */
  2343. err = __orinoco_hw_set_bitrate(priv);
  2344. if (err) {
  2345. printk(KERN_ERR "%s: Error %d setting bitrate\n",
  2346. dev->name, err);
  2347. return err;
  2348. }
  2349. /* Set power management */
  2350. if (priv->has_pm) {
  2351. err = hermes_write_wordrec(hw, USER_BAP,
  2352. HERMES_RID_CNFPMENABLED,
  2353. priv->pm_on);
  2354. if (err) {
  2355. printk(KERN_ERR "%s: Error %d setting up PM\n",
  2356. dev->name, err);
  2357. return err;
  2358. }
  2359. err = hermes_write_wordrec(hw, USER_BAP,
  2360. HERMES_RID_CNFMULTICASTRECEIVE,
  2361. priv->pm_mcast);
  2362. if (err) {
  2363. printk(KERN_ERR "%s: Error %d setting up PM\n",
  2364. dev->name, err);
  2365. return err;
  2366. }
  2367. err = hermes_write_wordrec(hw, USER_BAP,
  2368. HERMES_RID_CNFMAXSLEEPDURATION,
  2369. priv->pm_period);
  2370. if (err) {
  2371. printk(KERN_ERR "%s: Error %d setting up PM\n",
  2372. dev->name, err);
  2373. return err;
  2374. }
  2375. err = hermes_write_wordrec(hw, USER_BAP,
  2376. HERMES_RID_CNFPMHOLDOVERDURATION,
  2377. priv->pm_timeout);
  2378. if (err) {
  2379. printk(KERN_ERR "%s: Error %d setting up PM\n",
  2380. dev->name, err);
  2381. return err;
  2382. }
  2383. }
  2384. /* Set preamble - only for Symbol so far... */
  2385. if (priv->has_preamble) {
  2386. err = hermes_write_wordrec(hw, USER_BAP,
  2387. HERMES_RID_CNFPREAMBLE_SYMBOL,
  2388. priv->preamble);
  2389. if (err) {
  2390. printk(KERN_ERR "%s: Error %d setting preamble\n",
  2391. dev->name, err);
  2392. return err;
  2393. }
  2394. }
  2395. /* Set up encryption */
  2396. if (priv->has_wep || priv->has_wpa) {
  2397. err = __orinoco_hw_setup_enc(priv);
  2398. if (err) {
  2399. printk(KERN_ERR "%s: Error %d activating encryption\n",
  2400. dev->name, err);
  2401. return err;
  2402. }
  2403. }
  2404. if (priv->iw_mode == IW_MODE_MONITOR) {
  2405. /* Enable monitor mode */
  2406. dev->type = ARPHRD_IEEE80211;
  2407. err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
  2408. HERMES_TEST_MONITOR, 0, NULL);
  2409. } else {
  2410. /* Disable monitor mode */
  2411. dev->type = ARPHRD_ETHER;
  2412. err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
  2413. HERMES_TEST_STOP, 0, NULL);
  2414. }
  2415. if (err)
  2416. return err;
  2417. /* Set promiscuity / multicast*/
  2418. priv->promiscuous = 0;
  2419. priv->mc_count = 0;
  2420. /* FIXME: what about netif_tx_lock */
  2421. __orinoco_set_multicast_list(dev);
  2422. return 0;
  2423. }
  2424. /* FIXME: return int? */
  2425. static void
  2426. __orinoco_set_multicast_list(struct net_device *dev)
  2427. {
  2428. struct orinoco_private *priv = netdev_priv(dev);
  2429. hermes_t *hw = &priv->hw;
  2430. int err = 0;
  2431. int promisc, mc_count;
  2432. /* The Hermes doesn't seem to have an allmulti mode, so we go
  2433. * into promiscuous mode and let the upper levels deal. */
  2434. if ( (dev->flags & IFF_PROMISC) || (dev->flags & IFF_ALLMULTI) ||
  2435. (dev->mc_count > MAX_MULTICAST(priv)) ) {
  2436. promisc = 1;
  2437. mc_count = 0;
  2438. } else {
  2439. promisc = 0;
  2440. mc_count = dev->mc_count;
  2441. }
  2442. if (promisc != priv->promiscuous) {
  2443. err = hermes_write_wordrec(hw, USER_BAP,
  2444. HERMES_RID_CNFPROMISCUOUSMODE,
  2445. promisc);
  2446. if (err) {
  2447. printk(KERN_ERR "%s: Error %d setting PROMISCUOUSMODE to 1.\n",
  2448. dev->name, err);
  2449. } else
  2450. priv->promiscuous = promisc;
  2451. }
  2452. /* If we're not in promiscuous mode, then we need to set the
  2453. * group address if either we want to multicast, or if we were
  2454. * multicasting and want to stop */
  2455. if (! promisc && (mc_count || priv->mc_count) ) {
  2456. struct dev_mc_list *p = dev->mc_list;
  2457. struct hermes_multicast mclist;
  2458. int i;
  2459. for (i = 0; i < mc_count; i++) {
  2460. /* paranoia: is list shorter than mc_count? */
  2461. BUG_ON(! p);
  2462. /* paranoia: bad address size in list? */
  2463. BUG_ON(p->dmi_addrlen != ETH_ALEN);
  2464. memcpy(mclist.addr[i], p->dmi_addr, ETH_ALEN);
  2465. p = p->next;
  2466. }
  2467. if (p)
  2468. printk(KERN_WARNING "%s: Multicast list is "
  2469. "longer than mc_count\n", dev->name);
  2470. err = hermes_write_ltv(hw, USER_BAP,
  2471. HERMES_RID_CNFGROUPADDRESSES,
  2472. HERMES_BYTES_TO_RECLEN(mc_count * ETH_ALEN),
  2473. &mclist);
  2474. if (err)
  2475. printk(KERN_ERR "%s: Error %d setting multicast list.\n",
  2476. dev->name, err);
  2477. else
  2478. priv->mc_count = mc_count;
  2479. }
  2480. }
  2481. /* This must be called from user context, without locks held - use
  2482. * schedule_work() */
  2483. static void orinoco_reset(struct work_struct *work)
  2484. {
  2485. struct orinoco_private *priv =
  2486. container_of(work, struct orinoco_private, reset_work);
  2487. struct net_device *dev = priv->ndev;
  2488. struct hermes *hw = &priv->hw;
  2489. int err;
  2490. unsigned long flags;
  2491. if (orinoco_lock(priv, &flags) != 0)
  2492. /* When the hardware becomes available again, whatever
  2493. * detects that is responsible for re-initializing
  2494. * it. So no need for anything further */
  2495. return;
  2496. netif_stop_queue(dev);
  2497. /* Shut off interrupts. Depending on what state the hardware
  2498. * is in, this might not work, but we'll try anyway */
  2499. hermes_set_irqmask(hw, 0);
  2500. hermes_write_regn(hw, EVACK, 0xffff);
  2501. priv->hw_unavailable++;
  2502. priv->last_linkstatus = 0xffff; /* firmware will have to reassociate */
  2503. netif_carrier_off(dev);
  2504. orinoco_unlock(priv, &flags);
  2505. /* Scanning support: Cleanup of driver struct */
  2506. orinoco_clear_scan_results(priv, 0);
  2507. priv->scan_inprogress = 0;
  2508. if (priv->hard_reset) {
  2509. err = (*priv->hard_reset)(priv);
  2510. if (err) {
  2511. printk(KERN_ERR "%s: orinoco_reset: Error %d "
  2512. "performing hard reset\n", dev->name, err);
  2513. goto disable;
  2514. }
  2515. }
  2516. err = orinoco_reinit_firmware(dev);
  2517. if (err) {
  2518. printk(KERN_ERR "%s: orinoco_reset: Error %d re-initializing firmware\n",
  2519. dev->name, err);
  2520. goto disable;
  2521. }
  2522. spin_lock_irq(&priv->lock); /* This has to be called from user context */
  2523. priv->hw_unavailable--;
  2524. /* priv->open or priv->hw_unavailable might have changed while
  2525. * we dropped the lock */
  2526. if (priv->open && (! priv->hw_unavailable)) {
  2527. err = __orinoco_up(dev);
  2528. if (err) {
  2529. printk(KERN_ERR "%s: orinoco_reset: Error %d reenabling card\n",
  2530. dev->name, err);
  2531. } else
  2532. dev->trans_start = jiffies;
  2533. }
  2534. spin_unlock_irq(&priv->lock);
  2535. return;
  2536. disable:
  2537. hermes_set_irqmask(hw, 0);
  2538. netif_device_detach(dev);
  2539. printk(KERN_ERR "%s: Device has been disabled!\n", dev->name);
  2540. }
  2541. /********************************************************************/
  2542. /* Interrupt handler */
  2543. /********************************************************************/
  2544. static void __orinoco_ev_tick(struct net_device *dev, hermes_t *hw)
  2545. {
  2546. printk(KERN_DEBUG "%s: TICK\n", dev->name);
  2547. }
  2548. static void __orinoco_ev_wterr(struct net_device *dev, hermes_t *hw)
  2549. {
  2550. /* This seems to happen a fair bit under load, but ignoring it
  2551. seems to work fine...*/
  2552. printk(KERN_DEBUG "%s: MAC controller error (WTERR). Ignoring.\n",
  2553. dev->name);
  2554. }
  2555. irqreturn_t orinoco_interrupt(int irq, void *dev_id)
  2556. {
  2557. struct net_device *dev = dev_id;
  2558. struct orinoco_private *priv = netdev_priv(dev);
  2559. hermes_t *hw = &priv->hw;
  2560. int count = MAX_IRQLOOPS_PER_IRQ;
  2561. u16 evstat, events;
  2562. /* These are used to detect a runaway interrupt situation */
  2563. /* If we get more than MAX_IRQLOOPS_PER_JIFFY iterations in a jiffy,
  2564. * we panic and shut down the hardware */
  2565. static int last_irq_jiffy = 0; /* jiffies value the last time
  2566. * we were called */
  2567. static int loops_this_jiffy = 0;
  2568. unsigned long flags;
  2569. if (orinoco_lock(priv, &flags) != 0) {
  2570. /* If hw is unavailable - we don't know if the irq was
  2571. * for us or not */
  2572. return IRQ_HANDLED;
  2573. }
  2574. evstat = hermes_read_regn(hw, EVSTAT);
  2575. events = evstat & hw->inten;
  2576. if (! events) {
  2577. orinoco_unlock(priv, &flags);
  2578. return IRQ_NONE;
  2579. }
  2580. if (jiffies != last_irq_jiffy)
  2581. loops_this_jiffy = 0;
  2582. last_irq_jiffy = jiffies;
  2583. while (events && count--) {
  2584. if (++loops_this_jiffy > MAX_IRQLOOPS_PER_JIFFY) {
  2585. printk(KERN_WARNING "%s: IRQ handler is looping too "
  2586. "much! Resetting.\n", dev->name);
  2587. /* Disable interrupts for now */
  2588. hermes_set_irqmask(hw, 0);
  2589. schedule_work(&priv->reset_work);
  2590. break;
  2591. }
  2592. /* Check the card hasn't been removed */
  2593. if (! hermes_present(hw)) {
  2594. DEBUG(0, "orinoco_interrupt(): card removed\n");
  2595. break;
  2596. }
  2597. if (events & HERMES_EV_TICK)
  2598. __orinoco_ev_tick(dev, hw);
  2599. if (events & HERMES_EV_WTERR)
  2600. __orinoco_ev_wterr(dev, hw);
  2601. if (events & HERMES_EV_INFDROP)
  2602. __orinoco_ev_infdrop(dev, hw);
  2603. if (events & HERMES_EV_INFO)
  2604. __orinoco_ev_info(dev, hw);
  2605. if (events & HERMES_EV_RX)
  2606. __orinoco_ev_rx(dev, hw);
  2607. if (events & HERMES_EV_TXEXC)
  2608. __orinoco_ev_txexc(dev, hw);
  2609. if (events & HERMES_EV_TX)
  2610. __orinoco_ev_tx(dev, hw);
  2611. if (events & HERMES_EV_ALLOC)
  2612. __orinoco_ev_alloc(dev, hw);
  2613. hermes_write_regn(hw, EVACK, evstat);
  2614. evstat = hermes_read_regn(hw, EVSTAT);
  2615. events = evstat & hw->inten;
  2616. };
  2617. orinoco_unlock(priv, &flags);
  2618. return IRQ_HANDLED;
  2619. }
  2620. /********************************************************************/
  2621. /* Initialization */
  2622. /********************************************************************/
  2623. struct comp_id {
  2624. u16 id, variant, major, minor;
  2625. } __attribute__ ((packed));
  2626. static inline fwtype_t determine_firmware_type(struct comp_id *nic_id)
  2627. {
  2628. if (nic_id->id < 0x8000)
  2629. return FIRMWARE_TYPE_AGERE;
  2630. else if (nic_id->id == 0x8000 && nic_id->major == 0)
  2631. return FIRMWARE_TYPE_SYMBOL;
  2632. else
  2633. return FIRMWARE_TYPE_INTERSIL;
  2634. }
  2635. /* Set priv->firmware type, determine firmware properties */
  2636. static int determine_firmware(struct net_device *dev)
  2637. {
  2638. struct orinoco_private *priv = netdev_priv(dev);
  2639. hermes_t *hw = &priv->hw;
  2640. int err;
  2641. struct comp_id nic_id, sta_id;
  2642. unsigned int firmver;
  2643. char tmp[SYMBOL_MAX_VER_LEN+1] __attribute__((aligned(2)));
  2644. /* Get the hardware version */
  2645. err = HERMES_READ_RECORD(hw, USER_BAP, HERMES_RID_NICID, &nic_id);
  2646. if (err) {
  2647. printk(KERN_ERR "%s: Cannot read hardware identity: error %d\n",
  2648. dev->name, err);
  2649. return err;
  2650. }
  2651. le16_to_cpus(&nic_id.id);
  2652. le16_to_cpus(&nic_id.variant);
  2653. le16_to_cpus(&nic_id.major);
  2654. le16_to_cpus(&nic_id.minor);
  2655. printk(KERN_DEBUG "%s: Hardware identity %04x:%04x:%04x:%04x\n",
  2656. dev->name, nic_id.id, nic_id.variant,
  2657. nic_id.major, nic_id.minor);
  2658. priv->firmware_type = determine_firmware_type(&nic_id);
  2659. /* Get the firmware version */
  2660. err = HERMES_READ_RECORD(hw, USER_BAP, HERMES_RID_STAID, &sta_id);
  2661. if (err) {
  2662. printk(KERN_ERR "%s: Cannot read station identity: error %d\n",
  2663. dev->name, err);
  2664. return err;
  2665. }
  2666. le16_to_cpus(&sta_id.id);
  2667. le16_to_cpus(&sta_id.variant);
  2668. le16_to_cpus(&sta_id.major);
  2669. le16_to_cpus(&sta_id.minor);
  2670. printk(KERN_DEBUG "%s: Station identity %04x:%04x:%04x:%04x\n",
  2671. dev->name, sta_id.id, sta_id.variant,
  2672. sta_id.major, sta_id.minor);
  2673. switch (sta_id.id) {
  2674. case 0x15:
  2675. printk(KERN_ERR "%s: Primary firmware is active\n",
  2676. dev->name);
  2677. return -ENODEV;
  2678. case 0x14b:
  2679. printk(KERN_ERR "%s: Tertiary firmware is active\n",
  2680. dev->name);
  2681. return -ENODEV;
  2682. case 0x1f: /* Intersil, Agere, Symbol Spectrum24 */
  2683. case 0x21: /* Symbol Spectrum24 Trilogy */
  2684. break;
  2685. default:
  2686. printk(KERN_NOTICE "%s: Unknown station ID, please report\n",
  2687. dev->name);
  2688. break;
  2689. }
  2690. /* Default capabilities */
  2691. priv->has_sensitivity = 1;
  2692. priv->has_mwo = 0;
  2693. priv->has_preamble = 0;
  2694. priv->has_port3 = 1;
  2695. priv->has_ibss = 1;
  2696. priv->has_wep = 0;
  2697. priv->has_big_wep = 0;
  2698. priv->has_alt_txcntl = 0;
  2699. priv->has_ext_scan = 0;
  2700. priv->has_wpa = 0;
  2701. priv->do_fw_download = 0;
  2702. /* Determine capabilities from the firmware version */
  2703. switch (priv->firmware_type) {
  2704. case FIRMWARE_TYPE_AGERE:
  2705. /* Lucent Wavelan IEEE, Lucent Orinoco, Cabletron RoamAbout,
  2706. ELSA, Melco, HP, IBM, Dell 1150, Compaq 110/210 */
  2707. snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
  2708. "Lucent/Agere %d.%02d", sta_id.major, sta_id.minor);
  2709. firmver = ((unsigned long)sta_id.major << 16) | sta_id.minor;
  2710. priv->has_ibss = (firmver >= 0x60006);
  2711. priv->has_wep = (firmver >= 0x40020);
  2712. priv->has_big_wep = 1; /* FIXME: this is wrong - how do we tell
  2713. Gold cards from the others? */
  2714. priv->has_mwo = (firmver >= 0x60000);
  2715. priv->has_pm = (firmver >= 0x40020); /* Don't work in 7.52 ? */
  2716. priv->ibss_port = 1;
  2717. priv->has_hostscan = (firmver >= 0x8000a);
  2718. priv->do_fw_download = 1;
  2719. priv->broken_monitor = (firmver >= 0x80000);
  2720. priv->has_alt_txcntl = (firmver >= 0x90000); /* All 9.x ? */
  2721. priv->has_ext_scan = (firmver >= 0x90000); /* All 9.x ? */
  2722. priv->has_wpa = (firmver >= 0x9002a);
  2723. /* Tested with Agere firmware :
  2724. * 1.16 ; 4.08 ; 4.52 ; 6.04 ; 6.16 ; 7.28 => Jean II
  2725. * Tested CableTron firmware : 4.32 => Anton */
  2726. break;
  2727. case FIRMWARE_TYPE_SYMBOL:
  2728. /* Symbol , 3Com AirConnect, Intel, Ericsson WLAN */
  2729. /* Intel MAC : 00:02:B3:* */
  2730. /* 3Com MAC : 00:50:DA:* */
  2731. memset(tmp, 0, sizeof(tmp));
  2732. /* Get the Symbol firmware version */
  2733. err = hermes_read_ltv(hw, USER_BAP,
  2734. HERMES_RID_SECONDARYVERSION_SYMBOL,
  2735. SYMBOL_MAX_VER_LEN, NULL, &tmp);
  2736. if (err) {
  2737. printk(KERN_WARNING
  2738. "%s: Error %d reading Symbol firmware info. Wildly guessing capabilities...\n",
  2739. dev->name, err);
  2740. firmver = 0;
  2741. tmp[0] = '\0';
  2742. } else {
  2743. /* The firmware revision is a string, the format is
  2744. * something like : "V2.20-01".
  2745. * Quick and dirty parsing... - Jean II
  2746. */
  2747. firmver = ((tmp[1] - '0') << 16) | ((tmp[3] - '0') << 12)
  2748. | ((tmp[4] - '0') << 8) | ((tmp[6] - '0') << 4)
  2749. | (tmp[7] - '0');
  2750. tmp[SYMBOL_MAX_VER_LEN] = '\0';
  2751. }
  2752. snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
  2753. "Symbol %s", tmp);
  2754. priv->has_ibss = (firmver >= 0x20000);
  2755. priv->has_wep = (firmver >= 0x15012);
  2756. priv->has_big_wep = (firmver >= 0x20000);
  2757. priv->has_pm = (firmver >= 0x20000 && firmver < 0x22000) ||
  2758. (firmver >= 0x29000 && firmver < 0x30000) ||
  2759. firmver >= 0x31000;
  2760. priv->has_preamble = (firmver >= 0x20000);
  2761. priv->ibss_port = 4;
  2762. /* Symbol firmware is found on various cards, but
  2763. * there has been no attempt to check firmware
  2764. * download on non-spectrum_cs based cards.
  2765. *
  2766. * Given that the Agere firmware download works
  2767. * differently, we should avoid doing a firmware
  2768. * download with the Symbol algorithm on non-spectrum
  2769. * cards.
  2770. *
  2771. * For now we can identify a spectrum_cs based card
  2772. * because it has a firmware reset function.
  2773. */
  2774. priv->do_fw_download = (priv->stop_fw != NULL);
  2775. priv->broken_disableport = (firmver == 0x25013) ||
  2776. (firmver >= 0x30000 && firmver <= 0x31000);
  2777. priv->has_hostscan = (firmver >= 0x31001) ||
  2778. (firmver >= 0x29057 && firmver < 0x30000);
  2779. /* Tested with Intel firmware : 0x20015 => Jean II */
  2780. /* Tested with 3Com firmware : 0x15012 & 0x22001 => Jean II */
  2781. break;
  2782. case FIRMWARE_TYPE_INTERSIL:
  2783. /* D-Link, Linksys, Adtron, ZoomAir, and many others...
  2784. * Samsung, Compaq 100/200 and Proxim are slightly
  2785. * different and less well tested */
  2786. /* D-Link MAC : 00:40:05:* */
  2787. /* Addtron MAC : 00:90:D1:* */
  2788. snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
  2789. "Intersil %d.%d.%d", sta_id.major, sta_id.minor,
  2790. sta_id.variant);
  2791. firmver = ((unsigned long)sta_id.major << 16) |
  2792. ((unsigned long)sta_id.minor << 8) | sta_id.variant;
  2793. priv->has_ibss = (firmver >= 0x000700); /* FIXME */
  2794. priv->has_big_wep = priv->has_wep = (firmver >= 0x000800);
  2795. priv->has_pm = (firmver >= 0x000700);
  2796. priv->has_hostscan = (firmver >= 0x010301);
  2797. if (firmver >= 0x000800)
  2798. priv->ibss_port = 0;
  2799. else {
  2800. printk(KERN_NOTICE "%s: Intersil firmware earlier "
  2801. "than v0.8.x - several features not supported\n",
  2802. dev->name);
  2803. priv->ibss_port = 1;
  2804. }
  2805. break;
  2806. }
  2807. printk(KERN_DEBUG "%s: Firmware determined as %s\n", dev->name,
  2808. priv->fw_name);
  2809. return 0;
  2810. }
  2811. static int orinoco_init(struct net_device *dev)
  2812. {
  2813. struct orinoco_private *priv = netdev_priv(dev);
  2814. hermes_t *hw = &priv->hw;
  2815. int err = 0;
  2816. struct hermes_idstring nickbuf;
  2817. u16 reclen;
  2818. int len;
  2819. /* No need to lock, the hw_unavailable flag is already set in
  2820. * alloc_orinocodev() */
  2821. priv->nicbuf_size = IEEE80211_MAX_FRAME_LEN + ETH_HLEN;
  2822. /* Initialize the firmware */
  2823. err = hermes_init(hw);
  2824. if (err != 0) {
  2825. printk(KERN_ERR "%s: failed to initialize firmware (err = %d)\n",
  2826. dev->name, err);
  2827. goto out;
  2828. }
  2829. err = determine_firmware(dev);
  2830. if (err != 0) {
  2831. printk(KERN_ERR "%s: Incompatible firmware, aborting\n",
  2832. dev->name);
  2833. goto out;
  2834. }
  2835. if (priv->do_fw_download) {
  2836. err = orinoco_download(priv);
  2837. if (err)
  2838. priv->do_fw_download = 0;
  2839. /* Check firmware version again */
  2840. err = determine_firmware(dev);
  2841. if (err != 0) {
  2842. printk(KERN_ERR "%s: Incompatible firmware, aborting\n",
  2843. dev->name);
  2844. goto out;
  2845. }
  2846. }
  2847. if (priv->has_port3)
  2848. printk(KERN_DEBUG "%s: Ad-hoc demo mode supported\n", dev->name);
  2849. if (priv->has_ibss)
  2850. printk(KERN_DEBUG "%s: IEEE standard IBSS ad-hoc mode supported\n",
  2851. dev->name);
  2852. if (priv->has_wep) {
  2853. printk(KERN_DEBUG "%s: WEP supported, ", dev->name);
  2854. if (priv->has_big_wep)
  2855. printk("104-bit key\n");
  2856. else
  2857. printk("40-bit key\n");
  2858. }
  2859. if (priv->has_wpa) {
  2860. printk(KERN_DEBUG "%s: WPA-PSK supported\n", dev->name);
  2861. if (orinoco_mic_init(priv)) {
  2862. printk(KERN_ERR "%s: Failed to setup MIC crypto "
  2863. "algorithm. Disabling WPA support\n", dev->name);
  2864. priv->has_wpa = 0;
  2865. }
  2866. }
  2867. /* Now we have the firmware capabilities, allocate appropiate
  2868. * sized scan buffers */
  2869. if (orinoco_bss_data_allocate(priv))
  2870. goto out;
  2871. orinoco_bss_data_init(priv);
  2872. /* Get the MAC address */
  2873. err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CNFOWNMACADDR,
  2874. ETH_ALEN, NULL, dev->dev_addr);
  2875. if (err) {
  2876. printk(KERN_WARNING "%s: failed to read MAC address!\n",
  2877. dev->name);
  2878. goto out;
  2879. }
  2880. printk(KERN_DEBUG "%s: MAC address %pM\n",
  2881. dev->name, dev->dev_addr);
  2882. /* Get the station name */
  2883. err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CNFOWNNAME,
  2884. sizeof(nickbuf), &reclen, &nickbuf);
  2885. if (err) {
  2886. printk(KERN_ERR "%s: failed to read station name\n",
  2887. dev->name);
  2888. goto out;
  2889. }
  2890. if (nickbuf.len)
  2891. len = min(IW_ESSID_MAX_SIZE, (int)le16_to_cpu(nickbuf.len));
  2892. else
  2893. len = min(IW_ESSID_MAX_SIZE, 2 * reclen);
  2894. memcpy(priv->nick, &nickbuf.val, len);
  2895. priv->nick[len] = '\0';
  2896. printk(KERN_DEBUG "%s: Station name \"%s\"\n", dev->name, priv->nick);
  2897. err = orinoco_allocate_fid(dev);
  2898. if (err) {
  2899. printk(KERN_ERR "%s: failed to allocate NIC buffer!\n",
  2900. dev->name);
  2901. goto out;
  2902. }
  2903. /* Get allowed channels */
  2904. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CHANNELLIST,
  2905. &priv->channel_mask);
  2906. if (err) {
  2907. printk(KERN_ERR "%s: failed to read channel list!\n",
  2908. dev->name);
  2909. goto out;
  2910. }
  2911. /* Get initial AP density */
  2912. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFSYSTEMSCALE,
  2913. &priv->ap_density);
  2914. if (err || priv->ap_density < 1 || priv->ap_density > 3) {
  2915. priv->has_sensitivity = 0;
  2916. }
  2917. /* Get initial RTS threshold */
  2918. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFRTSTHRESHOLD,
  2919. &priv->rts_thresh);
  2920. if (err) {
  2921. printk(KERN_ERR "%s: failed to read RTS threshold!\n",
  2922. dev->name);
  2923. goto out;
  2924. }
  2925. /* Get initial fragmentation settings */
  2926. if (priv->has_mwo)
  2927. err = hermes_read_wordrec(hw, USER_BAP,
  2928. HERMES_RID_CNFMWOROBUST_AGERE,
  2929. &priv->mwo_robust);
  2930. else
  2931. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
  2932. &priv->frag_thresh);
  2933. if (err) {
  2934. printk(KERN_ERR "%s: failed to read fragmentation settings!\n",
  2935. dev->name);
  2936. goto out;
  2937. }
  2938. /* Power management setup */
  2939. if (priv->has_pm) {
  2940. priv->pm_on = 0;
  2941. priv->pm_mcast = 1;
  2942. err = hermes_read_wordrec(hw, USER_BAP,
  2943. HERMES_RID_CNFMAXSLEEPDURATION,
  2944. &priv->pm_period);
  2945. if (err) {
  2946. printk(KERN_ERR "%s: failed to read power management period!\n",
  2947. dev->name);
  2948. goto out;
  2949. }
  2950. err = hermes_read_wordrec(hw, USER_BAP,
  2951. HERMES_RID_CNFPMHOLDOVERDURATION,
  2952. &priv->pm_timeout);
  2953. if (err) {
  2954. printk(KERN_ERR "%s: failed to read power management timeout!\n",
  2955. dev->name);
  2956. goto out;
  2957. }
  2958. }
  2959. /* Preamble setup */
  2960. if (priv->has_preamble) {
  2961. err = hermes_read_wordrec(hw, USER_BAP,
  2962. HERMES_RID_CNFPREAMBLE_SYMBOL,
  2963. &priv->preamble);
  2964. if (err)
  2965. goto out;
  2966. }
  2967. /* Set up the default configuration */
  2968. priv->iw_mode = IW_MODE_INFRA;
  2969. /* By default use IEEE/IBSS ad-hoc mode if we have it */
  2970. priv->prefer_port3 = priv->has_port3 && (! priv->has_ibss);
  2971. set_port_type(priv);
  2972. priv->channel = 0; /* use firmware default */
  2973. priv->promiscuous = 0;
  2974. priv->encode_alg = IW_ENCODE_ALG_NONE;
  2975. priv->tx_key = 0;
  2976. priv->wpa_enabled = 0;
  2977. priv->tkip_cm_active = 0;
  2978. priv->key_mgmt = 0;
  2979. priv->wpa_ie_len = 0;
  2980. priv->wpa_ie = NULL;
  2981. /* Make the hardware available, as long as it hasn't been
  2982. * removed elsewhere (e.g. by PCMCIA hot unplug) */
  2983. spin_lock_irq(&priv->lock);
  2984. priv->hw_unavailable--;
  2985. spin_unlock_irq(&priv->lock);
  2986. printk(KERN_DEBUG "%s: ready\n", dev->name);
  2987. out:
  2988. return err;
  2989. }
  2990. struct net_device
  2991. *alloc_orinocodev(int sizeof_card,
  2992. struct device *device,
  2993. int (*hard_reset)(struct orinoco_private *),
  2994. int (*stop_fw)(struct orinoco_private *, int))
  2995. {
  2996. struct net_device *dev;
  2997. struct orinoco_private *priv;
  2998. dev = alloc_etherdev(sizeof(struct orinoco_private) + sizeof_card);
  2999. if (! dev)
  3000. return NULL;
  3001. priv = netdev_priv(dev);
  3002. priv->ndev = dev;
  3003. if (sizeof_card)
  3004. priv->card = (void *)((unsigned long)priv
  3005. + sizeof(struct orinoco_private));
  3006. else
  3007. priv->card = NULL;
  3008. priv->dev = device;
  3009. /* Setup / override net_device fields */
  3010. dev->init = orinoco_init;
  3011. dev->hard_start_xmit = orinoco_xmit;
  3012. dev->tx_timeout = orinoco_tx_timeout;
  3013. dev->watchdog_timeo = HZ; /* 1 second timeout */
  3014. dev->get_stats = orinoco_get_stats;
  3015. dev->ethtool_ops = &orinoco_ethtool_ops;
  3016. dev->wireless_handlers = (struct iw_handler_def *)&orinoco_handler_def;
  3017. #ifdef WIRELESS_SPY
  3018. priv->wireless_data.spy_data = &priv->spy_data;
  3019. dev->wireless_data = &priv->wireless_data;
  3020. #endif
  3021. dev->change_mtu = orinoco_change_mtu;
  3022. dev->set_multicast_list = orinoco_set_multicast_list;
  3023. /* we use the default eth_mac_addr for setting the MAC addr */
  3024. /* Reserve space in skb for the SNAP header */
  3025. dev->hard_header_len += ENCAPS_OVERHEAD;
  3026. /* Set up default callbacks */
  3027. dev->open = orinoco_open;
  3028. dev->stop = orinoco_stop;
  3029. priv->hard_reset = hard_reset;
  3030. priv->stop_fw = stop_fw;
  3031. spin_lock_init(&priv->lock);
  3032. priv->open = 0;
  3033. priv->hw_unavailable = 1; /* orinoco_init() must clear this
  3034. * before anything else touches the
  3035. * hardware */
  3036. INIT_WORK(&priv->reset_work, orinoco_reset);
  3037. INIT_WORK(&priv->join_work, orinoco_join_ap);
  3038. INIT_WORK(&priv->wevent_work, orinoco_send_wevents);
  3039. INIT_LIST_HEAD(&priv->rx_list);
  3040. tasklet_init(&priv->rx_tasklet, orinoco_rx_isr_tasklet,
  3041. (unsigned long) dev);
  3042. netif_carrier_off(dev);
  3043. priv->last_linkstatus = 0xffff;
  3044. priv->cached_fw = NULL;
  3045. return dev;
  3046. }
  3047. void free_orinocodev(struct net_device *dev)
  3048. {
  3049. struct orinoco_private *priv = netdev_priv(dev);
  3050. /* No need to empty priv->rx_list: if the tasklet is scheduled
  3051. * when we call tasklet_kill it will run one final time,
  3052. * emptying the list */
  3053. tasklet_kill(&priv->rx_tasklet);
  3054. if (priv->cached_fw)
  3055. release_firmware(priv->cached_fw);
  3056. priv->cached_fw = NULL;
  3057. priv->wpa_ie_len = 0;
  3058. kfree(priv->wpa_ie);
  3059. orinoco_mic_free(priv);
  3060. orinoco_bss_data_free(priv);
  3061. free_netdev(dev);
  3062. }
  3063. /********************************************************************/
  3064. /* Wireless extensions */
  3065. /********************************************************************/
  3066. /* Return : < 0 -> error code ; >= 0 -> length */
  3067. static int orinoco_hw_get_essid(struct orinoco_private *priv, int *active,
  3068. char buf[IW_ESSID_MAX_SIZE+1])
  3069. {
  3070. hermes_t *hw = &priv->hw;
  3071. int err = 0;
  3072. struct hermes_idstring essidbuf;
  3073. char *p = (char *)(&essidbuf.val);
  3074. int len;
  3075. unsigned long flags;
  3076. if (orinoco_lock(priv, &flags) != 0)
  3077. return -EBUSY;
  3078. if (strlen(priv->desired_essid) > 0) {
  3079. /* We read the desired SSID from the hardware rather
  3080. than from priv->desired_essid, just in case the
  3081. firmware is allowed to change it on us. I'm not
  3082. sure about this */
  3083. /* My guess is that the OWNSSID should always be whatever
  3084. * we set to the card, whereas CURRENT_SSID is the one that
  3085. * may change... - Jean II */
  3086. u16 rid;
  3087. *active = 1;
  3088. rid = (priv->port_type == 3) ? HERMES_RID_CNFOWNSSID :
  3089. HERMES_RID_CNFDESIREDSSID;
  3090. err = hermes_read_ltv(hw, USER_BAP, rid, sizeof(essidbuf),
  3091. NULL, &essidbuf);
  3092. if (err)
  3093. goto fail_unlock;
  3094. } else {
  3095. *active = 0;
  3096. err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTSSID,
  3097. sizeof(essidbuf), NULL, &essidbuf);
  3098. if (err)
  3099. goto fail_unlock;
  3100. }
  3101. len = le16_to_cpu(essidbuf.len);
  3102. BUG_ON(len > IW_ESSID_MAX_SIZE);
  3103. memset(buf, 0, IW_ESSID_MAX_SIZE);
  3104. memcpy(buf, p, len);
  3105. err = len;
  3106. fail_unlock:
  3107. orinoco_unlock(priv, &flags);
  3108. return err;
  3109. }
  3110. static long orinoco_hw_get_freq(struct orinoco_private *priv)
  3111. {
  3112. hermes_t *hw = &priv->hw;
  3113. int err = 0;
  3114. u16 channel;
  3115. long freq = 0;
  3116. unsigned long flags;
  3117. if (orinoco_lock(priv, &flags) != 0)
  3118. return -EBUSY;
  3119. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CURRENTCHANNEL, &channel);
  3120. if (err)
  3121. goto out;
  3122. /* Intersil firmware 1.3.5 returns 0 when the interface is down */
  3123. if (channel == 0) {
  3124. err = -EBUSY;
  3125. goto out;
  3126. }
  3127. if ( (channel < 1) || (channel > NUM_CHANNELS) ) {
  3128. printk(KERN_WARNING "%s: Channel out of range (%d)!\n",
  3129. priv->ndev->name, channel);
  3130. err = -EBUSY;
  3131. goto out;
  3132. }
  3133. freq = channel_frequency[channel-1] * 100000;
  3134. out:
  3135. orinoco_unlock(priv, &flags);
  3136. if (err > 0)
  3137. err = -EBUSY;
  3138. return err ? err : freq;
  3139. }
  3140. static int orinoco_hw_get_bitratelist(struct orinoco_private *priv,
  3141. int *numrates, s32 *rates, int max)
  3142. {
  3143. hermes_t *hw = &priv->hw;
  3144. struct hermes_idstring list;
  3145. unsigned char *p = (unsigned char *)&list.val;
  3146. int err = 0;
  3147. int num;
  3148. int i;
  3149. unsigned long flags;
  3150. if (orinoco_lock(priv, &flags) != 0)
  3151. return -EBUSY;
  3152. err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_SUPPORTEDDATARATES,
  3153. sizeof(list), NULL, &list);
  3154. orinoco_unlock(priv, &flags);
  3155. if (err)
  3156. return err;
  3157. num = le16_to_cpu(list.len);
  3158. *numrates = num;
  3159. num = min(num, max);
  3160. for (i = 0; i < num; i++) {
  3161. rates[i] = (p[i] & 0x7f) * 500000; /* convert to bps */
  3162. }
  3163. return 0;
  3164. }
  3165. static int orinoco_ioctl_getname(struct net_device *dev,
  3166. struct iw_request_info *info,
  3167. char *name,
  3168. char *extra)
  3169. {
  3170. struct orinoco_private *priv = netdev_priv(dev);
  3171. int numrates;
  3172. int err;
  3173. err = orinoco_hw_get_bitratelist(priv, &numrates, NULL, 0);
  3174. if (!err && (numrates > 2))
  3175. strcpy(name, "IEEE 802.11b");
  3176. else
  3177. strcpy(name, "IEEE 802.11-DS");
  3178. return 0;
  3179. }
  3180. static int orinoco_ioctl_setwap(struct net_device *dev,
  3181. struct iw_request_info *info,
  3182. struct sockaddr *ap_addr,
  3183. char *extra)
  3184. {
  3185. struct orinoco_private *priv = netdev_priv(dev);
  3186. int err = -EINPROGRESS; /* Call commit handler */
  3187. unsigned long flags;
  3188. static const u8 off_addr[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  3189. static const u8 any_addr[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
  3190. if (orinoco_lock(priv, &flags) != 0)
  3191. return -EBUSY;
  3192. /* Enable automatic roaming - no sanity checks are needed */
  3193. if (memcmp(&ap_addr->sa_data, off_addr, ETH_ALEN) == 0 ||
  3194. memcmp(&ap_addr->sa_data, any_addr, ETH_ALEN) == 0) {
  3195. priv->bssid_fixed = 0;
  3196. memset(priv->desired_bssid, 0, ETH_ALEN);
  3197. /* "off" means keep existing connection */
  3198. if (ap_addr->sa_data[0] == 0) {
  3199. __orinoco_hw_set_wap(priv);
  3200. err = 0;
  3201. }
  3202. goto out;
  3203. }
  3204. if (priv->firmware_type == FIRMWARE_TYPE_AGERE) {
  3205. printk(KERN_WARNING "%s: Lucent/Agere firmware doesn't "
  3206. "support manual roaming\n",
  3207. dev->name);
  3208. err = -EOPNOTSUPP;
  3209. goto out;
  3210. }
  3211. if (priv->iw_mode != IW_MODE_INFRA) {
  3212. printk(KERN_WARNING "%s: Manual roaming supported only in "
  3213. "managed mode\n", dev->name);
  3214. err = -EOPNOTSUPP;
  3215. goto out;
  3216. }
  3217. /* Intersil firmware hangs without Desired ESSID */
  3218. if (priv->firmware_type == FIRMWARE_TYPE_INTERSIL &&
  3219. strlen(priv->desired_essid) == 0) {
  3220. printk(KERN_WARNING "%s: Desired ESSID must be set for "
  3221. "manual roaming\n", dev->name);
  3222. err = -EOPNOTSUPP;
  3223. goto out;
  3224. }
  3225. /* Finally, enable manual roaming */
  3226. priv->bssid_fixed = 1;
  3227. memcpy(priv->desired_bssid, &ap_addr->sa_data, ETH_ALEN);
  3228. out:
  3229. orinoco_unlock(priv, &flags);
  3230. return err;
  3231. }
  3232. static int orinoco_ioctl_getwap(struct net_device *dev,
  3233. struct iw_request_info *info,
  3234. struct sockaddr *ap_addr,
  3235. char *extra)
  3236. {
  3237. struct orinoco_private *priv = netdev_priv(dev);
  3238. hermes_t *hw = &priv->hw;
  3239. int err = 0;
  3240. unsigned long flags;
  3241. if (orinoco_lock(priv, &flags) != 0)
  3242. return -EBUSY;
  3243. ap_addr->sa_family = ARPHRD_ETHER;
  3244. err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTBSSID,
  3245. ETH_ALEN, NULL, ap_addr->sa_data);
  3246. orinoco_unlock(priv, &flags);
  3247. return err;
  3248. }
  3249. static int orinoco_ioctl_setmode(struct net_device *dev,
  3250. struct iw_request_info *info,
  3251. u32 *mode,
  3252. char *extra)
  3253. {
  3254. struct orinoco_private *priv = netdev_priv(dev);
  3255. int err = -EINPROGRESS; /* Call commit handler */
  3256. unsigned long flags;
  3257. if (priv->iw_mode == *mode)
  3258. return 0;
  3259. if (orinoco_lock(priv, &flags) != 0)
  3260. return -EBUSY;
  3261. switch (*mode) {
  3262. case IW_MODE_ADHOC:
  3263. if (!priv->has_ibss && !priv->has_port3)
  3264. err = -EOPNOTSUPP;
  3265. break;
  3266. case IW_MODE_INFRA:
  3267. break;
  3268. case IW_MODE_MONITOR:
  3269. if (priv->broken_monitor && !force_monitor) {
  3270. printk(KERN_WARNING "%s: Monitor mode support is "
  3271. "buggy in this firmware, not enabling\n",
  3272. dev->name);
  3273. err = -EOPNOTSUPP;
  3274. }
  3275. break;
  3276. default:
  3277. err = -EOPNOTSUPP;
  3278. break;
  3279. }
  3280. if (err == -EINPROGRESS) {
  3281. priv->iw_mode = *mode;
  3282. set_port_type(priv);
  3283. }
  3284. orinoco_unlock(priv, &flags);
  3285. return err;
  3286. }
  3287. static int orinoco_ioctl_getmode(struct net_device *dev,
  3288. struct iw_request_info *info,
  3289. u32 *mode,
  3290. char *extra)
  3291. {
  3292. struct orinoco_private *priv = netdev_priv(dev);
  3293. *mode = priv->iw_mode;
  3294. return 0;
  3295. }
  3296. static int orinoco_ioctl_getiwrange(struct net_device *dev,
  3297. struct iw_request_info *info,
  3298. struct iw_point *rrq,
  3299. char *extra)
  3300. {
  3301. struct orinoco_private *priv = netdev_priv(dev);
  3302. int err = 0;
  3303. struct iw_range *range = (struct iw_range *) extra;
  3304. int numrates;
  3305. int i, k;
  3306. rrq->length = sizeof(struct iw_range);
  3307. memset(range, 0, sizeof(struct iw_range));
  3308. range->we_version_compiled = WIRELESS_EXT;
  3309. range->we_version_source = 22;
  3310. /* Set available channels/frequencies */
  3311. range->num_channels = NUM_CHANNELS;
  3312. k = 0;
  3313. for (i = 0; i < NUM_CHANNELS; i++) {
  3314. if (priv->channel_mask & (1 << i)) {
  3315. range->freq[k].i = i + 1;
  3316. range->freq[k].m = channel_frequency[i] * 100000;
  3317. range->freq[k].e = 1;
  3318. k++;
  3319. }
  3320. if (k >= IW_MAX_FREQUENCIES)
  3321. break;
  3322. }
  3323. range->num_frequency = k;
  3324. range->sensitivity = 3;
  3325. if (priv->has_wep) {
  3326. range->max_encoding_tokens = ORINOCO_MAX_KEYS;
  3327. range->encoding_size[0] = SMALL_KEY_SIZE;
  3328. range->num_encoding_sizes = 1;
  3329. if (priv->has_big_wep) {
  3330. range->encoding_size[1] = LARGE_KEY_SIZE;
  3331. range->num_encoding_sizes = 2;
  3332. }
  3333. }
  3334. if (priv->has_wpa)
  3335. range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_CIPHER_TKIP;
  3336. if ((priv->iw_mode == IW_MODE_ADHOC) && (!SPY_NUMBER(priv))){
  3337. /* Quality stats meaningless in ad-hoc mode */
  3338. } else {
  3339. range->max_qual.qual = 0x8b - 0x2f;
  3340. range->max_qual.level = 0x2f - 0x95 - 1;
  3341. range->max_qual.noise = 0x2f - 0x95 - 1;
  3342. /* Need to get better values */
  3343. range->avg_qual.qual = 0x24;
  3344. range->avg_qual.level = 0xC2;
  3345. range->avg_qual.noise = 0x9E;
  3346. }
  3347. err = orinoco_hw_get_bitratelist(priv, &numrates,
  3348. range->bitrate, IW_MAX_BITRATES);
  3349. if (err)
  3350. return err;
  3351. range->num_bitrates = numrates;
  3352. /* Set an indication of the max TCP throughput in bit/s that we can
  3353. * expect using this interface. May be use for QoS stuff...
  3354. * Jean II */
  3355. if (numrates > 2)
  3356. range->throughput = 5 * 1000 * 1000; /* ~5 Mb/s */
  3357. else
  3358. range->throughput = 1.5 * 1000 * 1000; /* ~1.5 Mb/s */
  3359. range->min_rts = 0;
  3360. range->max_rts = 2347;
  3361. range->min_frag = 256;
  3362. range->max_frag = 2346;
  3363. range->min_pmp = 0;
  3364. range->max_pmp = 65535000;
  3365. range->min_pmt = 0;
  3366. range->max_pmt = 65535 * 1000; /* ??? */
  3367. range->pmp_flags = IW_POWER_PERIOD;
  3368. range->pmt_flags = IW_POWER_TIMEOUT;
  3369. range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT | IW_POWER_UNICAST_R;
  3370. range->retry_capa = IW_RETRY_LIMIT | IW_RETRY_LIFETIME;
  3371. range->retry_flags = IW_RETRY_LIMIT;
  3372. range->r_time_flags = IW_RETRY_LIFETIME;
  3373. range->min_retry = 0;
  3374. range->max_retry = 65535; /* ??? */
  3375. range->min_r_time = 0;
  3376. range->max_r_time = 65535 * 1000; /* ??? */
  3377. if (priv->firmware_type == FIRMWARE_TYPE_AGERE)
  3378. range->scan_capa = IW_SCAN_CAPA_ESSID;
  3379. else
  3380. range->scan_capa = IW_SCAN_CAPA_NONE;
  3381. /* Event capability (kernel) */
  3382. IW_EVENT_CAPA_SET_KERNEL(range->event_capa);
  3383. /* Event capability (driver) */
  3384. IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWTHRSPY);
  3385. IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWAP);
  3386. IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWSCAN);
  3387. IW_EVENT_CAPA_SET(range->event_capa, IWEVTXDROP);
  3388. return 0;
  3389. }
  3390. static int orinoco_ioctl_setiwencode(struct net_device *dev,
  3391. struct iw_request_info *info,
  3392. struct iw_point *erq,
  3393. char *keybuf)
  3394. {
  3395. struct orinoco_private *priv = netdev_priv(dev);
  3396. int index = (erq->flags & IW_ENCODE_INDEX) - 1;
  3397. int setindex = priv->tx_key;
  3398. int encode_alg = priv->encode_alg;
  3399. int restricted = priv->wep_restrict;
  3400. u16 xlen = 0;
  3401. int err = -EINPROGRESS; /* Call commit handler */
  3402. unsigned long flags;
  3403. if (! priv->has_wep)
  3404. return -EOPNOTSUPP;
  3405. if (erq->pointer) {
  3406. /* We actually have a key to set - check its length */
  3407. if (erq->length > LARGE_KEY_SIZE)
  3408. return -E2BIG;
  3409. if ( (erq->length > SMALL_KEY_SIZE) && !priv->has_big_wep )
  3410. return -E2BIG;
  3411. }
  3412. if (orinoco_lock(priv, &flags) != 0)
  3413. return -EBUSY;
  3414. /* Clear any TKIP key we have */
  3415. if ((priv->has_wpa) && (priv->encode_alg == IW_ENCODE_ALG_TKIP))
  3416. (void) orinoco_clear_tkip_key(priv, setindex);
  3417. if (erq->length > 0) {
  3418. if ((index < 0) || (index >= ORINOCO_MAX_KEYS))
  3419. index = priv->tx_key;
  3420. /* Adjust key length to a supported value */
  3421. if (erq->length > SMALL_KEY_SIZE) {
  3422. xlen = LARGE_KEY_SIZE;
  3423. } else if (erq->length > 0) {
  3424. xlen = SMALL_KEY_SIZE;
  3425. } else
  3426. xlen = 0;
  3427. /* Switch on WEP if off */
  3428. if ((encode_alg != IW_ENCODE_ALG_WEP) && (xlen > 0)) {
  3429. setindex = index;
  3430. encode_alg = IW_ENCODE_ALG_WEP;
  3431. }
  3432. } else {
  3433. /* Important note : if the user do "iwconfig eth0 enc off",
  3434. * we will arrive there with an index of -1. This is valid
  3435. * but need to be taken care off... Jean II */
  3436. if ((index < 0) || (index >= ORINOCO_MAX_KEYS)) {
  3437. if((index != -1) || (erq->flags == 0)) {
  3438. err = -EINVAL;
  3439. goto out;
  3440. }
  3441. } else {
  3442. /* Set the index : Check that the key is valid */
  3443. if(priv->keys[index].len == 0) {
  3444. err = -EINVAL;
  3445. goto out;
  3446. }
  3447. setindex = index;
  3448. }
  3449. }
  3450. if (erq->flags & IW_ENCODE_DISABLED)
  3451. encode_alg = IW_ENCODE_ALG_NONE;
  3452. if (erq->flags & IW_ENCODE_OPEN)
  3453. restricted = 0;
  3454. if (erq->flags & IW_ENCODE_RESTRICTED)
  3455. restricted = 1;
  3456. if (erq->pointer && erq->length > 0) {
  3457. priv->keys[index].len = cpu_to_le16(xlen);
  3458. memset(priv->keys[index].data, 0,
  3459. sizeof(priv->keys[index].data));
  3460. memcpy(priv->keys[index].data, keybuf, erq->length);
  3461. }
  3462. priv->tx_key = setindex;
  3463. /* Try fast key change if connected and only keys are changed */
  3464. if ((priv->encode_alg == encode_alg) &&
  3465. (priv->wep_restrict == restricted) &&
  3466. netif_carrier_ok(dev)) {
  3467. err = __orinoco_hw_setup_wepkeys(priv);
  3468. /* No need to commit if successful */
  3469. goto out;
  3470. }
  3471. priv->encode_alg = encode_alg;
  3472. priv->wep_restrict = restricted;
  3473. out:
  3474. orinoco_unlock(priv, &flags);
  3475. return err;
  3476. }
  3477. static int orinoco_ioctl_getiwencode(struct net_device *dev,
  3478. struct iw_request_info *info,
  3479. struct iw_point *erq,
  3480. char *keybuf)
  3481. {
  3482. struct orinoco_private *priv = netdev_priv(dev);
  3483. int index = (erq->flags & IW_ENCODE_INDEX) - 1;
  3484. u16 xlen = 0;
  3485. unsigned long flags;
  3486. if (! priv->has_wep)
  3487. return -EOPNOTSUPP;
  3488. if (orinoco_lock(priv, &flags) != 0)
  3489. return -EBUSY;
  3490. if ((index < 0) || (index >= ORINOCO_MAX_KEYS))
  3491. index = priv->tx_key;
  3492. erq->flags = 0;
  3493. if (!priv->encode_alg)
  3494. erq->flags |= IW_ENCODE_DISABLED;
  3495. erq->flags |= index + 1;
  3496. if (priv->wep_restrict)
  3497. erq->flags |= IW_ENCODE_RESTRICTED;
  3498. else
  3499. erq->flags |= IW_ENCODE_OPEN;
  3500. xlen = le16_to_cpu(priv->keys[index].len);
  3501. erq->length = xlen;
  3502. memcpy(keybuf, priv->keys[index].data, ORINOCO_MAX_KEY_SIZE);
  3503. orinoco_unlock(priv, &flags);
  3504. return 0;
  3505. }
  3506. static int orinoco_ioctl_setessid(struct net_device *dev,
  3507. struct iw_request_info *info,
  3508. struct iw_point *erq,
  3509. char *essidbuf)
  3510. {
  3511. struct orinoco_private *priv = netdev_priv(dev);
  3512. unsigned long flags;
  3513. /* Note : ESSID is ignored in Ad-Hoc demo mode, but we can set it
  3514. * anyway... - Jean II */
  3515. /* Hum... Should not use Wireless Extension constant (may change),
  3516. * should use our own... - Jean II */
  3517. if (erq->length > IW_ESSID_MAX_SIZE)
  3518. return -E2BIG;
  3519. if (orinoco_lock(priv, &flags) != 0)
  3520. return -EBUSY;
  3521. /* NULL the string (for NULL termination & ESSID = ANY) - Jean II */
  3522. memset(priv->desired_essid, 0, sizeof(priv->desired_essid));
  3523. /* If not ANY, get the new ESSID */
  3524. if (erq->flags) {
  3525. memcpy(priv->desired_essid, essidbuf, erq->length);
  3526. }
  3527. orinoco_unlock(priv, &flags);
  3528. return -EINPROGRESS; /* Call commit handler */
  3529. }
  3530. static int orinoco_ioctl_getessid(struct net_device *dev,
  3531. struct iw_request_info *info,
  3532. struct iw_point *erq,
  3533. char *essidbuf)
  3534. {
  3535. struct orinoco_private *priv = netdev_priv(dev);
  3536. int active;
  3537. int err = 0;
  3538. unsigned long flags;
  3539. if (netif_running(dev)) {
  3540. err = orinoco_hw_get_essid(priv, &active, essidbuf);
  3541. if (err < 0)
  3542. return err;
  3543. erq->length = err;
  3544. } else {
  3545. if (orinoco_lock(priv, &flags) != 0)
  3546. return -EBUSY;
  3547. memcpy(essidbuf, priv->desired_essid, IW_ESSID_MAX_SIZE);
  3548. erq->length = strlen(priv->desired_essid);
  3549. orinoco_unlock(priv, &flags);
  3550. }
  3551. erq->flags = 1;
  3552. return 0;
  3553. }
  3554. static int orinoco_ioctl_setnick(struct net_device *dev,
  3555. struct iw_request_info *info,
  3556. struct iw_point *nrq,
  3557. char *nickbuf)
  3558. {
  3559. struct orinoco_private *priv = netdev_priv(dev);
  3560. unsigned long flags;
  3561. if (nrq->length > IW_ESSID_MAX_SIZE)
  3562. return -E2BIG;
  3563. if (orinoco_lock(priv, &flags) != 0)
  3564. return -EBUSY;
  3565. memset(priv->nick, 0, sizeof(priv->nick));
  3566. memcpy(priv->nick, nickbuf, nrq->length);
  3567. orinoco_unlock(priv, &flags);
  3568. return -EINPROGRESS; /* Call commit handler */
  3569. }
  3570. static int orinoco_ioctl_getnick(struct net_device *dev,
  3571. struct iw_request_info *info,
  3572. struct iw_point *nrq,
  3573. char *nickbuf)
  3574. {
  3575. struct orinoco_private *priv = netdev_priv(dev);
  3576. unsigned long flags;
  3577. if (orinoco_lock(priv, &flags) != 0)
  3578. return -EBUSY;
  3579. memcpy(nickbuf, priv->nick, IW_ESSID_MAX_SIZE);
  3580. orinoco_unlock(priv, &flags);
  3581. nrq->length = strlen(priv->nick);
  3582. return 0;
  3583. }
  3584. static int orinoco_ioctl_setfreq(struct net_device *dev,
  3585. struct iw_request_info *info,
  3586. struct iw_freq *frq,
  3587. char *extra)
  3588. {
  3589. struct orinoco_private *priv = netdev_priv(dev);
  3590. int chan = -1;
  3591. unsigned long flags;
  3592. int err = -EINPROGRESS; /* Call commit handler */
  3593. /* In infrastructure mode the AP sets the channel */
  3594. if (priv->iw_mode == IW_MODE_INFRA)
  3595. return -EBUSY;
  3596. if ( (frq->e == 0) && (frq->m <= 1000) ) {
  3597. /* Setting by channel number */
  3598. chan = frq->m;
  3599. } else {
  3600. /* Setting by frequency - search the table */
  3601. int mult = 1;
  3602. int i;
  3603. for (i = 0; i < (6 - frq->e); i++)
  3604. mult *= 10;
  3605. for (i = 0; i < NUM_CHANNELS; i++)
  3606. if (frq->m == (channel_frequency[i] * mult))
  3607. chan = i+1;
  3608. }
  3609. if ( (chan < 1) || (chan > NUM_CHANNELS) ||
  3610. ! (priv->channel_mask & (1 << (chan-1)) ) )
  3611. return -EINVAL;
  3612. if (orinoco_lock(priv, &flags) != 0)
  3613. return -EBUSY;
  3614. priv->channel = chan;
  3615. if (priv->iw_mode == IW_MODE_MONITOR) {
  3616. /* Fast channel change - no commit if successful */
  3617. hermes_t *hw = &priv->hw;
  3618. err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
  3619. HERMES_TEST_SET_CHANNEL,
  3620. chan, NULL);
  3621. }
  3622. orinoco_unlock(priv, &flags);
  3623. return err;
  3624. }
  3625. static int orinoco_ioctl_getfreq(struct net_device *dev,
  3626. struct iw_request_info *info,
  3627. struct iw_freq *frq,
  3628. char *extra)
  3629. {
  3630. struct orinoco_private *priv = netdev_priv(dev);
  3631. int tmp;
  3632. /* Locking done in there */
  3633. tmp = orinoco_hw_get_freq(priv);
  3634. if (tmp < 0) {
  3635. return tmp;
  3636. }
  3637. frq->m = tmp;
  3638. frq->e = 1;
  3639. return 0;
  3640. }
  3641. static int orinoco_ioctl_getsens(struct net_device *dev,
  3642. struct iw_request_info *info,
  3643. struct iw_param *srq,
  3644. char *extra)
  3645. {
  3646. struct orinoco_private *priv = netdev_priv(dev);
  3647. hermes_t *hw = &priv->hw;
  3648. u16 val;
  3649. int err;
  3650. unsigned long flags;
  3651. if (!priv->has_sensitivity)
  3652. return -EOPNOTSUPP;
  3653. if (orinoco_lock(priv, &flags) != 0)
  3654. return -EBUSY;
  3655. err = hermes_read_wordrec(hw, USER_BAP,
  3656. HERMES_RID_CNFSYSTEMSCALE, &val);
  3657. orinoco_unlock(priv, &flags);
  3658. if (err)
  3659. return err;
  3660. srq->value = val;
  3661. srq->fixed = 0; /* auto */
  3662. return 0;
  3663. }
  3664. static int orinoco_ioctl_setsens(struct net_device *dev,
  3665. struct iw_request_info *info,
  3666. struct iw_param *srq,
  3667. char *extra)
  3668. {
  3669. struct orinoco_private *priv = netdev_priv(dev);
  3670. int val = srq->value;
  3671. unsigned long flags;
  3672. if (!priv->has_sensitivity)
  3673. return -EOPNOTSUPP;
  3674. if ((val < 1) || (val > 3))
  3675. return -EINVAL;
  3676. if (orinoco_lock(priv, &flags) != 0)
  3677. return -EBUSY;
  3678. priv->ap_density = val;
  3679. orinoco_unlock(priv, &flags);
  3680. return -EINPROGRESS; /* Call commit handler */
  3681. }
  3682. static int orinoco_ioctl_setrts(struct net_device *dev,
  3683. struct iw_request_info *info,
  3684. struct iw_param *rrq,
  3685. char *extra)
  3686. {
  3687. struct orinoco_private *priv = netdev_priv(dev);
  3688. int val = rrq->value;
  3689. unsigned long flags;
  3690. if (rrq->disabled)
  3691. val = 2347;
  3692. if ( (val < 0) || (val > 2347) )
  3693. return -EINVAL;
  3694. if (orinoco_lock(priv, &flags) != 0)
  3695. return -EBUSY;
  3696. priv->rts_thresh = val;
  3697. orinoco_unlock(priv, &flags);
  3698. return -EINPROGRESS; /* Call commit handler */
  3699. }
  3700. static int orinoco_ioctl_getrts(struct net_device *dev,
  3701. struct iw_request_info *info,
  3702. struct iw_param *rrq,
  3703. char *extra)
  3704. {
  3705. struct orinoco_private *priv = netdev_priv(dev);
  3706. rrq->value = priv->rts_thresh;
  3707. rrq->disabled = (rrq->value == 2347);
  3708. rrq->fixed = 1;
  3709. return 0;
  3710. }
  3711. static int orinoco_ioctl_setfrag(struct net_device *dev,
  3712. struct iw_request_info *info,
  3713. struct iw_param *frq,
  3714. char *extra)
  3715. {
  3716. struct orinoco_private *priv = netdev_priv(dev);
  3717. int err = -EINPROGRESS; /* Call commit handler */
  3718. unsigned long flags;
  3719. if (orinoco_lock(priv, &flags) != 0)
  3720. return -EBUSY;
  3721. if (priv->has_mwo) {
  3722. if (frq->disabled)
  3723. priv->mwo_robust = 0;
  3724. else {
  3725. if (frq->fixed)
  3726. printk(KERN_WARNING "%s: Fixed fragmentation is "
  3727. "not supported on this firmware. "
  3728. "Using MWO robust instead.\n", dev->name);
  3729. priv->mwo_robust = 1;
  3730. }
  3731. } else {
  3732. if (frq->disabled)
  3733. priv->frag_thresh = 2346;
  3734. else {
  3735. if ( (frq->value < 256) || (frq->value > 2346) )
  3736. err = -EINVAL;
  3737. else
  3738. priv->frag_thresh = frq->value & ~0x1; /* must be even */
  3739. }
  3740. }
  3741. orinoco_unlock(priv, &flags);
  3742. return err;
  3743. }
  3744. static int orinoco_ioctl_getfrag(struct net_device *dev,
  3745. struct iw_request_info *info,
  3746. struct iw_param *frq,
  3747. char *extra)
  3748. {
  3749. struct orinoco_private *priv = netdev_priv(dev);
  3750. hermes_t *hw = &priv->hw;
  3751. int err;
  3752. u16 val;
  3753. unsigned long flags;
  3754. if (orinoco_lock(priv, &flags) != 0)
  3755. return -EBUSY;
  3756. if (priv->has_mwo) {
  3757. err = hermes_read_wordrec(hw, USER_BAP,
  3758. HERMES_RID_CNFMWOROBUST_AGERE,
  3759. &val);
  3760. if (err)
  3761. val = 0;
  3762. frq->value = val ? 2347 : 0;
  3763. frq->disabled = ! val;
  3764. frq->fixed = 0;
  3765. } else {
  3766. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
  3767. &val);
  3768. if (err)
  3769. val = 0;
  3770. frq->value = val;
  3771. frq->disabled = (val >= 2346);
  3772. frq->fixed = 1;
  3773. }
  3774. orinoco_unlock(priv, &flags);
  3775. return err;
  3776. }
  3777. static int orinoco_ioctl_setrate(struct net_device *dev,
  3778. struct iw_request_info *info,
  3779. struct iw_param *rrq,
  3780. char *extra)
  3781. {
  3782. struct orinoco_private *priv = netdev_priv(dev);
  3783. int ratemode = -1;
  3784. int bitrate; /* 100s of kilobits */
  3785. int i;
  3786. unsigned long flags;
  3787. /* As the user space doesn't know our highest rate, it uses -1
  3788. * to ask us to set the highest rate. Test it using "iwconfig
  3789. * ethX rate auto" - Jean II */
  3790. if (rrq->value == -1)
  3791. bitrate = 110;
  3792. else {
  3793. if (rrq->value % 100000)
  3794. return -EINVAL;
  3795. bitrate = rrq->value / 100000;
  3796. }
  3797. if ( (bitrate != 10) && (bitrate != 20) &&
  3798. (bitrate != 55) && (bitrate != 110) )
  3799. return -EINVAL;
  3800. for (i = 0; i < BITRATE_TABLE_SIZE; i++)
  3801. if ( (bitrate_table[i].bitrate == bitrate) &&
  3802. (bitrate_table[i].automatic == ! rrq->fixed) ) {
  3803. ratemode = i;
  3804. break;
  3805. }
  3806. if (ratemode == -1)
  3807. return -EINVAL;
  3808. if (orinoco_lock(priv, &flags) != 0)
  3809. return -EBUSY;
  3810. priv->bitratemode = ratemode;
  3811. orinoco_unlock(priv, &flags);
  3812. return -EINPROGRESS;
  3813. }
  3814. static int orinoco_ioctl_getrate(struct net_device *dev,
  3815. struct iw_request_info *info,
  3816. struct iw_param *rrq,
  3817. char *extra)
  3818. {
  3819. struct orinoco_private *priv = netdev_priv(dev);
  3820. hermes_t *hw = &priv->hw;
  3821. int err = 0;
  3822. int ratemode;
  3823. int i;
  3824. u16 val;
  3825. unsigned long flags;
  3826. if (orinoco_lock(priv, &flags) != 0)
  3827. return -EBUSY;
  3828. ratemode = priv->bitratemode;
  3829. BUG_ON((ratemode < 0) || (ratemode >= BITRATE_TABLE_SIZE));
  3830. rrq->value = bitrate_table[ratemode].bitrate * 100000;
  3831. rrq->fixed = ! bitrate_table[ratemode].automatic;
  3832. rrq->disabled = 0;
  3833. /* If the interface is running we try to find more about the
  3834. current mode */
  3835. if (netif_running(dev)) {
  3836. err = hermes_read_wordrec(hw, USER_BAP,
  3837. HERMES_RID_CURRENTTXRATE, &val);
  3838. if (err)
  3839. goto out;
  3840. switch (priv->firmware_type) {
  3841. case FIRMWARE_TYPE_AGERE: /* Lucent style rate */
  3842. /* Note : in Lucent firmware, the return value of
  3843. * HERMES_RID_CURRENTTXRATE is the bitrate in Mb/s,
  3844. * and therefore is totally different from the
  3845. * encoding of HERMES_RID_CNFTXRATECONTROL.
  3846. * Don't forget that 6Mb/s is really 5.5Mb/s */
  3847. if (val == 6)
  3848. rrq->value = 5500000;
  3849. else
  3850. rrq->value = val * 1000000;
  3851. break;
  3852. case FIRMWARE_TYPE_INTERSIL: /* Intersil style rate */
  3853. case FIRMWARE_TYPE_SYMBOL: /* Symbol style rate */
  3854. for (i = 0; i < BITRATE_TABLE_SIZE; i++)
  3855. if (bitrate_table[i].intersil_txratectrl == val) {
  3856. ratemode = i;
  3857. break;
  3858. }
  3859. if (i >= BITRATE_TABLE_SIZE)
  3860. printk(KERN_INFO "%s: Unable to determine current bitrate (0x%04hx)\n",
  3861. dev->name, val);
  3862. rrq->value = bitrate_table[ratemode].bitrate * 100000;
  3863. break;
  3864. default:
  3865. BUG();
  3866. }
  3867. }
  3868. out:
  3869. orinoco_unlock(priv, &flags);
  3870. return err;
  3871. }
  3872. static int orinoco_ioctl_setpower(struct net_device *dev,
  3873. struct iw_request_info *info,
  3874. struct iw_param *prq,
  3875. char *extra)
  3876. {
  3877. struct orinoco_private *priv = netdev_priv(dev);
  3878. int err = -EINPROGRESS; /* Call commit handler */
  3879. unsigned long flags;
  3880. if (orinoco_lock(priv, &flags) != 0)
  3881. return -EBUSY;
  3882. if (prq->disabled) {
  3883. priv->pm_on = 0;
  3884. } else {
  3885. switch (prq->flags & IW_POWER_MODE) {
  3886. case IW_POWER_UNICAST_R:
  3887. priv->pm_mcast = 0;
  3888. priv->pm_on = 1;
  3889. break;
  3890. case IW_POWER_ALL_R:
  3891. priv->pm_mcast = 1;
  3892. priv->pm_on = 1;
  3893. break;
  3894. case IW_POWER_ON:
  3895. /* No flags : but we may have a value - Jean II */
  3896. break;
  3897. default:
  3898. err = -EINVAL;
  3899. goto out;
  3900. }
  3901. if (prq->flags & IW_POWER_TIMEOUT) {
  3902. priv->pm_on = 1;
  3903. priv->pm_timeout = prq->value / 1000;
  3904. }
  3905. if (prq->flags & IW_POWER_PERIOD) {
  3906. priv->pm_on = 1;
  3907. priv->pm_period = prq->value / 1000;
  3908. }
  3909. /* It's valid to not have a value if we are just toggling
  3910. * the flags... Jean II */
  3911. if(!priv->pm_on) {
  3912. err = -EINVAL;
  3913. goto out;
  3914. }
  3915. }
  3916. out:
  3917. orinoco_unlock(priv, &flags);
  3918. return err;
  3919. }
  3920. static int orinoco_ioctl_getpower(struct net_device *dev,
  3921. struct iw_request_info *info,
  3922. struct iw_param *prq,
  3923. char *extra)
  3924. {
  3925. struct orinoco_private *priv = netdev_priv(dev);
  3926. hermes_t *hw = &priv->hw;
  3927. int err = 0;
  3928. u16 enable, period, timeout, mcast;
  3929. unsigned long flags;
  3930. if (orinoco_lock(priv, &flags) != 0)
  3931. return -EBUSY;
  3932. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFPMENABLED, &enable);
  3933. if (err)
  3934. goto out;
  3935. err = hermes_read_wordrec(hw, USER_BAP,
  3936. HERMES_RID_CNFMAXSLEEPDURATION, &period);
  3937. if (err)
  3938. goto out;
  3939. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFPMHOLDOVERDURATION, &timeout);
  3940. if (err)
  3941. goto out;
  3942. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFMULTICASTRECEIVE, &mcast);
  3943. if (err)
  3944. goto out;
  3945. prq->disabled = !enable;
  3946. /* Note : by default, display the period */
  3947. if ((prq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
  3948. prq->flags = IW_POWER_TIMEOUT;
  3949. prq->value = timeout * 1000;
  3950. } else {
  3951. prq->flags = IW_POWER_PERIOD;
  3952. prq->value = period * 1000;
  3953. }
  3954. if (mcast)
  3955. prq->flags |= IW_POWER_ALL_R;
  3956. else
  3957. prq->flags |= IW_POWER_UNICAST_R;
  3958. out:
  3959. orinoco_unlock(priv, &flags);
  3960. return err;
  3961. }
  3962. static int orinoco_ioctl_set_encodeext(struct net_device *dev,
  3963. struct iw_request_info *info,
  3964. union iwreq_data *wrqu,
  3965. char *extra)
  3966. {
  3967. struct orinoco_private *priv = netdev_priv(dev);
  3968. struct iw_point *encoding = &wrqu->encoding;
  3969. struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
  3970. int idx, alg = ext->alg, set_key = 1;
  3971. unsigned long flags;
  3972. int err = -EINVAL;
  3973. u16 key_len;
  3974. if (orinoco_lock(priv, &flags) != 0)
  3975. return -EBUSY;
  3976. /* Determine and validate the key index */
  3977. idx = encoding->flags & IW_ENCODE_INDEX;
  3978. if (idx) {
  3979. if ((idx < 1) || (idx > 4))
  3980. goto out;
  3981. idx--;
  3982. } else
  3983. idx = priv->tx_key;
  3984. if (encoding->flags & IW_ENCODE_DISABLED)
  3985. alg = IW_ENCODE_ALG_NONE;
  3986. if (priv->has_wpa && (alg != IW_ENCODE_ALG_TKIP)) {
  3987. /* Clear any TKIP TX key we had */
  3988. (void) orinoco_clear_tkip_key(priv, priv->tx_key);
  3989. }
  3990. if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) {
  3991. priv->tx_key = idx;
  3992. set_key = ((alg == IW_ENCODE_ALG_TKIP) ||
  3993. (ext->key_len > 0)) ? 1 : 0;
  3994. }
  3995. if (set_key) {
  3996. /* Set the requested key first */
  3997. switch (alg) {
  3998. case IW_ENCODE_ALG_NONE:
  3999. priv->encode_alg = alg;
  4000. priv->keys[idx].len = 0;
  4001. break;
  4002. case IW_ENCODE_ALG_WEP:
  4003. if (ext->key_len > SMALL_KEY_SIZE)
  4004. key_len = LARGE_KEY_SIZE;
  4005. else if (ext->key_len > 0)
  4006. key_len = SMALL_KEY_SIZE;
  4007. else
  4008. goto out;
  4009. priv->encode_alg = alg;
  4010. priv->keys[idx].len = cpu_to_le16(key_len);
  4011. key_len = min(ext->key_len, key_len);
  4012. memset(priv->keys[idx].data, 0, ORINOCO_MAX_KEY_SIZE);
  4013. memcpy(priv->keys[idx].data, ext->key, key_len);
  4014. break;
  4015. case IW_ENCODE_ALG_TKIP:
  4016. {
  4017. hermes_t *hw = &priv->hw;
  4018. u8 *tkip_iv = NULL;
  4019. if (!priv->has_wpa ||
  4020. (ext->key_len > sizeof(priv->tkip_key[0])))
  4021. goto out;
  4022. priv->encode_alg = alg;
  4023. memset(&priv->tkip_key[idx], 0,
  4024. sizeof(priv->tkip_key[idx]));
  4025. memcpy(&priv->tkip_key[idx], ext->key, ext->key_len);
  4026. if (ext->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID)
  4027. tkip_iv = &ext->rx_seq[0];
  4028. err = __orinoco_hw_set_tkip_key(hw, idx,
  4029. ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY,
  4030. (u8 *) &priv->tkip_key[idx],
  4031. tkip_iv, NULL);
  4032. if (err)
  4033. printk(KERN_ERR "%s: Error %d setting TKIP key"
  4034. "\n", dev->name, err);
  4035. goto out;
  4036. }
  4037. default:
  4038. goto out;
  4039. }
  4040. }
  4041. err = -EINPROGRESS;
  4042. out:
  4043. orinoco_unlock(priv, &flags);
  4044. return err;
  4045. }
  4046. static int orinoco_ioctl_get_encodeext(struct net_device *dev,
  4047. struct iw_request_info *info,
  4048. union iwreq_data *wrqu,
  4049. char *extra)
  4050. {
  4051. struct orinoco_private *priv = netdev_priv(dev);
  4052. struct iw_point *encoding = &wrqu->encoding;
  4053. struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
  4054. int idx, max_key_len;
  4055. unsigned long flags;
  4056. int err;
  4057. if (orinoco_lock(priv, &flags) != 0)
  4058. return -EBUSY;
  4059. err = -EINVAL;
  4060. max_key_len = encoding->length - sizeof(*ext);
  4061. if (max_key_len < 0)
  4062. goto out;
  4063. idx = encoding->flags & IW_ENCODE_INDEX;
  4064. if (idx) {
  4065. if ((idx < 1) || (idx > 4))
  4066. goto out;
  4067. idx--;
  4068. } else
  4069. idx = priv->tx_key;
  4070. encoding->flags = idx + 1;
  4071. memset(ext, 0, sizeof(*ext));
  4072. ext->alg = priv->encode_alg;
  4073. switch (priv->encode_alg) {
  4074. case IW_ENCODE_ALG_NONE:
  4075. ext->key_len = 0;
  4076. encoding->flags |= IW_ENCODE_DISABLED;
  4077. break;
  4078. case IW_ENCODE_ALG_WEP:
  4079. ext->key_len = min_t(u16, le16_to_cpu(priv->keys[idx].len),
  4080. max_key_len);
  4081. memcpy(ext->key, priv->keys[idx].data, ext->key_len);
  4082. encoding->flags |= IW_ENCODE_ENABLED;
  4083. break;
  4084. case IW_ENCODE_ALG_TKIP:
  4085. ext->key_len = min_t(u16, sizeof(struct orinoco_tkip_key),
  4086. max_key_len);
  4087. memcpy(ext->key, &priv->tkip_key[idx], ext->key_len);
  4088. encoding->flags |= IW_ENCODE_ENABLED;
  4089. break;
  4090. }
  4091. err = 0;
  4092. out:
  4093. orinoco_unlock(priv, &flags);
  4094. return err;
  4095. }
  4096. static int orinoco_ioctl_set_auth(struct net_device *dev,
  4097. struct iw_request_info *info,
  4098. union iwreq_data *wrqu, char *extra)
  4099. {
  4100. struct orinoco_private *priv = netdev_priv(dev);
  4101. hermes_t *hw = &priv->hw;
  4102. struct iw_param *param = &wrqu->param;
  4103. unsigned long flags;
  4104. int ret = -EINPROGRESS;
  4105. if (orinoco_lock(priv, &flags) != 0)
  4106. return -EBUSY;
  4107. switch (param->flags & IW_AUTH_INDEX) {
  4108. case IW_AUTH_WPA_VERSION:
  4109. case IW_AUTH_CIPHER_PAIRWISE:
  4110. case IW_AUTH_CIPHER_GROUP:
  4111. case IW_AUTH_RX_UNENCRYPTED_EAPOL:
  4112. case IW_AUTH_PRIVACY_INVOKED:
  4113. case IW_AUTH_DROP_UNENCRYPTED:
  4114. /*
  4115. * orinoco does not use these parameters
  4116. */
  4117. break;
  4118. case IW_AUTH_KEY_MGMT:
  4119. /* wl_lkm implies value 2 == PSK for Hermes I
  4120. * which ties in with WEXT
  4121. * no other hints tho :(
  4122. */
  4123. priv->key_mgmt = param->value;
  4124. break;
  4125. case IW_AUTH_TKIP_COUNTERMEASURES:
  4126. /* When countermeasures are enabled, shut down the
  4127. * card; when disabled, re-enable the card. This must
  4128. * take effect immediately.
  4129. *
  4130. * TODO: Make sure that the EAPOL message is getting
  4131. * out before card disabled
  4132. */
  4133. if (param->value) {
  4134. priv->tkip_cm_active = 1;
  4135. ret = hermes_enable_port(hw, 0);
  4136. } else {
  4137. priv->tkip_cm_active = 0;
  4138. ret = hermes_disable_port(hw, 0);
  4139. }
  4140. break;
  4141. case IW_AUTH_80211_AUTH_ALG:
  4142. if (param->value & IW_AUTH_ALG_SHARED_KEY)
  4143. priv->wep_restrict = 1;
  4144. else if (param->value & IW_AUTH_ALG_OPEN_SYSTEM)
  4145. priv->wep_restrict = 0;
  4146. else
  4147. ret = -EINVAL;
  4148. break;
  4149. case IW_AUTH_WPA_ENABLED:
  4150. if (priv->has_wpa) {
  4151. priv->wpa_enabled = param->value ? 1 : 0;
  4152. } else {
  4153. if (param->value)
  4154. ret = -EOPNOTSUPP;
  4155. /* else silently accept disable of WPA */
  4156. priv->wpa_enabled = 0;
  4157. }
  4158. break;
  4159. default:
  4160. ret = -EOPNOTSUPP;
  4161. }
  4162. orinoco_unlock(priv, &flags);
  4163. return ret;
  4164. }
  4165. static int orinoco_ioctl_get_auth(struct net_device *dev,
  4166. struct iw_request_info *info,
  4167. union iwreq_data *wrqu, char *extra)
  4168. {
  4169. struct orinoco_private *priv = netdev_priv(dev);
  4170. struct iw_param *param = &wrqu->param;
  4171. unsigned long flags;
  4172. int ret = 0;
  4173. if (orinoco_lock(priv, &flags) != 0)
  4174. return -EBUSY;
  4175. switch (param->flags & IW_AUTH_INDEX) {
  4176. case IW_AUTH_KEY_MGMT:
  4177. param->value = priv->key_mgmt;
  4178. break;
  4179. case IW_AUTH_TKIP_COUNTERMEASURES:
  4180. param->value = priv->tkip_cm_active;
  4181. break;
  4182. case IW_AUTH_80211_AUTH_ALG:
  4183. if (priv->wep_restrict)
  4184. param->value = IW_AUTH_ALG_SHARED_KEY;
  4185. else
  4186. param->value = IW_AUTH_ALG_OPEN_SYSTEM;
  4187. break;
  4188. case IW_AUTH_WPA_ENABLED:
  4189. param->value = priv->wpa_enabled;
  4190. break;
  4191. default:
  4192. ret = -EOPNOTSUPP;
  4193. }
  4194. orinoco_unlock(priv, &flags);
  4195. return ret;
  4196. }
  4197. static int orinoco_ioctl_set_genie(struct net_device *dev,
  4198. struct iw_request_info *info,
  4199. union iwreq_data *wrqu, char *extra)
  4200. {
  4201. struct orinoco_private *priv = netdev_priv(dev);
  4202. u8 *buf;
  4203. unsigned long flags;
  4204. int err = 0;
  4205. /* cut off at IEEE80211_MAX_DATA_LEN */
  4206. if ((wrqu->data.length > IEEE80211_MAX_DATA_LEN) ||
  4207. (wrqu->data.length && (extra == NULL)))
  4208. return -EINVAL;
  4209. if (orinoco_lock(priv, &flags) != 0)
  4210. return -EBUSY;
  4211. if (wrqu->data.length) {
  4212. buf = kmalloc(wrqu->data.length, GFP_KERNEL);
  4213. if (buf == NULL) {
  4214. err = -ENOMEM;
  4215. goto out;
  4216. }
  4217. memcpy(buf, extra, wrqu->data.length);
  4218. kfree(priv->wpa_ie);
  4219. priv->wpa_ie = buf;
  4220. priv->wpa_ie_len = wrqu->data.length;
  4221. } else {
  4222. kfree(priv->wpa_ie);
  4223. priv->wpa_ie = NULL;
  4224. priv->wpa_ie_len = 0;
  4225. }
  4226. if (priv->wpa_ie) {
  4227. /* Looks like wl_lkm wants to check the auth alg, and
  4228. * somehow pass it to the firmware.
  4229. * Instead it just calls the key mgmt rid
  4230. * - we do this in set auth.
  4231. */
  4232. }
  4233. out:
  4234. orinoco_unlock(priv, &flags);
  4235. return err;
  4236. }
  4237. static int orinoco_ioctl_get_genie(struct net_device *dev,
  4238. struct iw_request_info *info,
  4239. union iwreq_data *wrqu, char *extra)
  4240. {
  4241. struct orinoco_private *priv = netdev_priv(dev);
  4242. unsigned long flags;
  4243. int err = 0;
  4244. if (orinoco_lock(priv, &flags) != 0)
  4245. return -EBUSY;
  4246. if ((priv->wpa_ie_len == 0) || (priv->wpa_ie == NULL)) {
  4247. wrqu->data.length = 0;
  4248. goto out;
  4249. }
  4250. if (wrqu->data.length < priv->wpa_ie_len) {
  4251. err = -E2BIG;
  4252. goto out;
  4253. }
  4254. wrqu->data.length = priv->wpa_ie_len;
  4255. memcpy(extra, priv->wpa_ie, priv->wpa_ie_len);
  4256. out:
  4257. orinoco_unlock(priv, &flags);
  4258. return err;
  4259. }
  4260. static int orinoco_ioctl_set_mlme(struct net_device *dev,
  4261. struct iw_request_info *info,
  4262. union iwreq_data *wrqu, char *extra)
  4263. {
  4264. struct orinoco_private *priv = netdev_priv(dev);
  4265. hermes_t *hw = &priv->hw;
  4266. struct iw_mlme *mlme = (struct iw_mlme *)extra;
  4267. unsigned long flags;
  4268. int ret = 0;
  4269. if (orinoco_lock(priv, &flags) != 0)
  4270. return -EBUSY;
  4271. switch (mlme->cmd) {
  4272. case IW_MLME_DEAUTH:
  4273. /* silently ignore */
  4274. break;
  4275. case IW_MLME_DISASSOC:
  4276. {
  4277. struct {
  4278. u8 addr[ETH_ALEN];
  4279. __le16 reason_code;
  4280. } __attribute__ ((packed)) buf;
  4281. memcpy(buf.addr, mlme->addr.sa_data, ETH_ALEN);
  4282. buf.reason_code = cpu_to_le16(mlme->reason_code);
  4283. ret = HERMES_WRITE_RECORD(hw, USER_BAP,
  4284. HERMES_RID_CNFDISASSOCIATE,
  4285. &buf);
  4286. break;
  4287. }
  4288. default:
  4289. ret = -EOPNOTSUPP;
  4290. }
  4291. orinoco_unlock(priv, &flags);
  4292. return ret;
  4293. }
  4294. static int orinoco_ioctl_getretry(struct net_device *dev,
  4295. struct iw_request_info *info,
  4296. struct iw_param *rrq,
  4297. char *extra)
  4298. {
  4299. struct orinoco_private *priv = netdev_priv(dev);
  4300. hermes_t *hw = &priv->hw;
  4301. int err = 0;
  4302. u16 short_limit, long_limit, lifetime;
  4303. unsigned long flags;
  4304. if (orinoco_lock(priv, &flags) != 0)
  4305. return -EBUSY;
  4306. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_SHORTRETRYLIMIT,
  4307. &short_limit);
  4308. if (err)
  4309. goto out;
  4310. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_LONGRETRYLIMIT,
  4311. &long_limit);
  4312. if (err)
  4313. goto out;
  4314. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_MAXTRANSMITLIFETIME,
  4315. &lifetime);
  4316. if (err)
  4317. goto out;
  4318. rrq->disabled = 0; /* Can't be disabled */
  4319. /* Note : by default, display the retry number */
  4320. if ((rrq->flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
  4321. rrq->flags = IW_RETRY_LIFETIME;
  4322. rrq->value = lifetime * 1000; /* ??? */
  4323. } else {
  4324. /* By default, display the min number */
  4325. if ((rrq->flags & IW_RETRY_LONG)) {
  4326. rrq->flags = IW_RETRY_LIMIT | IW_RETRY_LONG;
  4327. rrq->value = long_limit;
  4328. } else {
  4329. rrq->flags = IW_RETRY_LIMIT;
  4330. rrq->value = short_limit;
  4331. if(short_limit != long_limit)
  4332. rrq->flags |= IW_RETRY_SHORT;
  4333. }
  4334. }
  4335. out:
  4336. orinoco_unlock(priv, &flags);
  4337. return err;
  4338. }
  4339. static int orinoco_ioctl_reset(struct net_device *dev,
  4340. struct iw_request_info *info,
  4341. void *wrqu,
  4342. char *extra)
  4343. {
  4344. struct orinoco_private *priv = netdev_priv(dev);
  4345. if (! capable(CAP_NET_ADMIN))
  4346. return -EPERM;
  4347. if (info->cmd == (SIOCIWFIRSTPRIV + 0x1)) {
  4348. printk(KERN_DEBUG "%s: Forcing reset!\n", dev->name);
  4349. /* Firmware reset */
  4350. orinoco_reset(&priv->reset_work);
  4351. } else {
  4352. printk(KERN_DEBUG "%s: Force scheduling reset!\n", dev->name);
  4353. schedule_work(&priv->reset_work);
  4354. }
  4355. return 0;
  4356. }
  4357. static int orinoco_ioctl_setibssport(struct net_device *dev,
  4358. struct iw_request_info *info,
  4359. void *wrqu,
  4360. char *extra)
  4361. {
  4362. struct orinoco_private *priv = netdev_priv(dev);
  4363. int val = *( (int *) extra );
  4364. unsigned long flags;
  4365. if (orinoco_lock(priv, &flags) != 0)
  4366. return -EBUSY;
  4367. priv->ibss_port = val ;
  4368. /* Actually update the mode we are using */
  4369. set_port_type(priv);
  4370. orinoco_unlock(priv, &flags);
  4371. return -EINPROGRESS; /* Call commit handler */
  4372. }
  4373. static int orinoco_ioctl_getibssport(struct net_device *dev,
  4374. struct iw_request_info *info,
  4375. void *wrqu,
  4376. char *extra)
  4377. {
  4378. struct orinoco_private *priv = netdev_priv(dev);
  4379. int *val = (int *) extra;
  4380. *val = priv->ibss_port;
  4381. return 0;
  4382. }
  4383. static int orinoco_ioctl_setport3(struct net_device *dev,
  4384. struct iw_request_info *info,
  4385. void *wrqu,
  4386. char *extra)
  4387. {
  4388. struct orinoco_private *priv = netdev_priv(dev);
  4389. int val = *( (int *) extra );
  4390. int err = 0;
  4391. unsigned long flags;
  4392. if (orinoco_lock(priv, &flags) != 0)
  4393. return -EBUSY;
  4394. switch (val) {
  4395. case 0: /* Try to do IEEE ad-hoc mode */
  4396. if (! priv->has_ibss) {
  4397. err = -EINVAL;
  4398. break;
  4399. }
  4400. priv->prefer_port3 = 0;
  4401. break;
  4402. case 1: /* Try to do Lucent proprietary ad-hoc mode */
  4403. if (! priv->has_port3) {
  4404. err = -EINVAL;
  4405. break;
  4406. }
  4407. priv->prefer_port3 = 1;
  4408. break;
  4409. default:
  4410. err = -EINVAL;
  4411. }
  4412. if (! err) {
  4413. /* Actually update the mode we are using */
  4414. set_port_type(priv);
  4415. err = -EINPROGRESS;
  4416. }
  4417. orinoco_unlock(priv, &flags);
  4418. return err;
  4419. }
  4420. static int orinoco_ioctl_getport3(struct net_device *dev,
  4421. struct iw_request_info *info,
  4422. void *wrqu,
  4423. char *extra)
  4424. {
  4425. struct orinoco_private *priv = netdev_priv(dev);
  4426. int *val = (int *) extra;
  4427. *val = priv->prefer_port3;
  4428. return 0;
  4429. }
  4430. static int orinoco_ioctl_setpreamble(struct net_device *dev,
  4431. struct iw_request_info *info,
  4432. void *wrqu,
  4433. char *extra)
  4434. {
  4435. struct orinoco_private *priv = netdev_priv(dev);
  4436. unsigned long flags;
  4437. int val;
  4438. if (! priv->has_preamble)
  4439. return -EOPNOTSUPP;
  4440. /* 802.11b has recently defined some short preamble.
  4441. * Basically, the Phy header has been reduced in size.
  4442. * This increase performance, especially at high rates
  4443. * (the preamble is transmitted at 1Mb/s), unfortunately
  4444. * this give compatibility troubles... - Jean II */
  4445. val = *( (int *) extra );
  4446. if (orinoco_lock(priv, &flags) != 0)
  4447. return -EBUSY;
  4448. if (val)
  4449. priv->preamble = 1;
  4450. else
  4451. priv->preamble = 0;
  4452. orinoco_unlock(priv, &flags);
  4453. return -EINPROGRESS; /* Call commit handler */
  4454. }
  4455. static int orinoco_ioctl_getpreamble(struct net_device *dev,
  4456. struct iw_request_info *info,
  4457. void *wrqu,
  4458. char *extra)
  4459. {
  4460. struct orinoco_private *priv = netdev_priv(dev);
  4461. int *val = (int *) extra;
  4462. if (! priv->has_preamble)
  4463. return -EOPNOTSUPP;
  4464. *val = priv->preamble;
  4465. return 0;
  4466. }
  4467. /* ioctl interface to hermes_read_ltv()
  4468. * To use with iwpriv, pass the RID as the token argument, e.g.
  4469. * iwpriv get_rid [0xfc00]
  4470. * At least Wireless Tools 25 is required to use iwpriv.
  4471. * For Wireless Tools 25 and 26 append "dummy" are the end. */
  4472. static int orinoco_ioctl_getrid(struct net_device *dev,
  4473. struct iw_request_info *info,
  4474. struct iw_point *data,
  4475. char *extra)
  4476. {
  4477. struct orinoco_private *priv = netdev_priv(dev);
  4478. hermes_t *hw = &priv->hw;
  4479. int rid = data->flags;
  4480. u16 length;
  4481. int err;
  4482. unsigned long flags;
  4483. /* It's a "get" function, but we don't want users to access the
  4484. * WEP key and other raw firmware data */
  4485. if (! capable(CAP_NET_ADMIN))
  4486. return -EPERM;
  4487. if (rid < 0xfc00 || rid > 0xffff)
  4488. return -EINVAL;
  4489. if (orinoco_lock(priv, &flags) != 0)
  4490. return -EBUSY;
  4491. err = hermes_read_ltv(hw, USER_BAP, rid, MAX_RID_LEN, &length,
  4492. extra);
  4493. if (err)
  4494. goto out;
  4495. data->length = min_t(u16, HERMES_RECLEN_TO_BYTES(length),
  4496. MAX_RID_LEN);
  4497. out:
  4498. orinoco_unlock(priv, &flags);
  4499. return err;
  4500. }
  4501. /* Trigger a scan (look for other cells in the vicinity) */
  4502. static int orinoco_ioctl_setscan(struct net_device *dev,
  4503. struct iw_request_info *info,
  4504. struct iw_point *srq,
  4505. char *extra)
  4506. {
  4507. struct orinoco_private *priv = netdev_priv(dev);
  4508. hermes_t *hw = &priv->hw;
  4509. struct iw_scan_req *si = (struct iw_scan_req *) extra;
  4510. int err = 0;
  4511. unsigned long flags;
  4512. /* Note : you may have realised that, as this is a SET operation,
  4513. * this is privileged and therefore a normal user can't
  4514. * perform scanning.
  4515. * This is not an error, while the device perform scanning,
  4516. * traffic doesn't flow, so it's a perfect DoS...
  4517. * Jean II */
  4518. if (orinoco_lock(priv, &flags) != 0)
  4519. return -EBUSY;
  4520. /* Scanning with port 0 disabled would fail */
  4521. if (!netif_running(dev)) {
  4522. err = -ENETDOWN;
  4523. goto out;
  4524. }
  4525. /* In monitor mode, the scan results are always empty.
  4526. * Probe responses are passed to the driver as received
  4527. * frames and could be processed in software. */
  4528. if (priv->iw_mode == IW_MODE_MONITOR) {
  4529. err = -EOPNOTSUPP;
  4530. goto out;
  4531. }
  4532. /* Note : because we don't lock out the irq handler, the way
  4533. * we access scan variables in priv is critical.
  4534. * o scan_inprogress : not touched by irq handler
  4535. * o scan_mode : not touched by irq handler
  4536. * Before modifying anything on those variables, please think hard !
  4537. * Jean II */
  4538. /* Save flags */
  4539. priv->scan_mode = srq->flags;
  4540. /* Always trigger scanning, even if it's in progress.
  4541. * This way, if the info frame get lost, we will recover somewhat
  4542. * gracefully - Jean II */
  4543. if (priv->has_hostscan) {
  4544. switch (priv->firmware_type) {
  4545. case FIRMWARE_TYPE_SYMBOL:
  4546. err = hermes_write_wordrec(hw, USER_BAP,
  4547. HERMES_RID_CNFHOSTSCAN_SYMBOL,
  4548. HERMES_HOSTSCAN_SYMBOL_ONCE |
  4549. HERMES_HOSTSCAN_SYMBOL_BCAST);
  4550. break;
  4551. case FIRMWARE_TYPE_INTERSIL: {
  4552. __le16 req[3];
  4553. req[0] = cpu_to_le16(0x3fff); /* All channels */
  4554. req[1] = cpu_to_le16(0x0001); /* rate 1 Mbps */
  4555. req[2] = 0; /* Any ESSID */
  4556. err = HERMES_WRITE_RECORD(hw, USER_BAP,
  4557. HERMES_RID_CNFHOSTSCAN, &req);
  4558. }
  4559. break;
  4560. case FIRMWARE_TYPE_AGERE:
  4561. if (priv->scan_mode & IW_SCAN_THIS_ESSID) {
  4562. struct hermes_idstring idbuf;
  4563. size_t len = min(sizeof(idbuf.val),
  4564. (size_t) si->essid_len);
  4565. idbuf.len = cpu_to_le16(len);
  4566. memcpy(idbuf.val, si->essid, len);
  4567. err = hermes_write_ltv(hw, USER_BAP,
  4568. HERMES_RID_CNFSCANSSID_AGERE,
  4569. HERMES_BYTES_TO_RECLEN(len + 2),
  4570. &idbuf);
  4571. } else
  4572. err = hermes_write_wordrec(hw, USER_BAP,
  4573. HERMES_RID_CNFSCANSSID_AGERE,
  4574. 0); /* Any ESSID */
  4575. if (err)
  4576. break;
  4577. if (priv->has_ext_scan) {
  4578. /* Clear scan results at the start of
  4579. * an extended scan */
  4580. orinoco_clear_scan_results(priv,
  4581. msecs_to_jiffies(15000));
  4582. /* TODO: Is this available on older firmware?
  4583. * Can we use it to scan specific channels
  4584. * for IW_SCAN_THIS_FREQ? */
  4585. err = hermes_write_wordrec(hw, USER_BAP,
  4586. HERMES_RID_CNFSCANCHANNELS2GHZ,
  4587. 0x7FFF);
  4588. if (err)
  4589. goto out;
  4590. err = hermes_inquire(hw,
  4591. HERMES_INQ_CHANNELINFO);
  4592. } else
  4593. err = hermes_inquire(hw, HERMES_INQ_SCAN);
  4594. break;
  4595. }
  4596. } else
  4597. err = hermes_inquire(hw, HERMES_INQ_SCAN);
  4598. /* One more client */
  4599. if (! err)
  4600. priv->scan_inprogress = 1;
  4601. out:
  4602. orinoco_unlock(priv, &flags);
  4603. return err;
  4604. }
  4605. #define MAX_CUSTOM_LEN 64
  4606. /* Translate scan data returned from the card to a card independant
  4607. * format that the Wireless Tools will understand - Jean II */
  4608. static inline char *orinoco_translate_scan(struct net_device *dev,
  4609. struct iw_request_info *info,
  4610. char *current_ev,
  4611. char *end_buf,
  4612. union hermes_scan_info *bss,
  4613. unsigned int last_scanned)
  4614. {
  4615. struct orinoco_private *priv = netdev_priv(dev);
  4616. u16 capabilities;
  4617. u16 channel;
  4618. struct iw_event iwe; /* Temporary buffer */
  4619. char custom[MAX_CUSTOM_LEN];
  4620. memset(&iwe, 0, sizeof(iwe));
  4621. /* First entry *MUST* be the AP MAC address */
  4622. iwe.cmd = SIOCGIWAP;
  4623. iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
  4624. memcpy(iwe.u.ap_addr.sa_data, bss->a.bssid, ETH_ALEN);
  4625. current_ev = iwe_stream_add_event(info, current_ev, end_buf,
  4626. &iwe, IW_EV_ADDR_LEN);
  4627. /* Other entries will be displayed in the order we give them */
  4628. /* Add the ESSID */
  4629. iwe.u.data.length = le16_to_cpu(bss->a.essid_len);
  4630. if (iwe.u.data.length > 32)
  4631. iwe.u.data.length = 32;
  4632. iwe.cmd = SIOCGIWESSID;
  4633. iwe.u.data.flags = 1;
  4634. current_ev = iwe_stream_add_point(info, current_ev, end_buf,
  4635. &iwe, bss->a.essid);
  4636. /* Add mode */
  4637. iwe.cmd = SIOCGIWMODE;
  4638. capabilities = le16_to_cpu(bss->a.capabilities);
  4639. if (capabilities & (WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_IBSS)) {
  4640. if (capabilities & WLAN_CAPABILITY_ESS)
  4641. iwe.u.mode = IW_MODE_MASTER;
  4642. else
  4643. iwe.u.mode = IW_MODE_ADHOC;
  4644. current_ev = iwe_stream_add_event(info, current_ev, end_buf,
  4645. &iwe, IW_EV_UINT_LEN);
  4646. }
  4647. channel = bss->s.channel;
  4648. if ((channel >= 1) && (channel <= NUM_CHANNELS)) {
  4649. /* Add channel and frequency */
  4650. iwe.cmd = SIOCGIWFREQ;
  4651. iwe.u.freq.m = channel;
  4652. iwe.u.freq.e = 0;
  4653. current_ev = iwe_stream_add_event(info, current_ev, end_buf,
  4654. &iwe, IW_EV_FREQ_LEN);
  4655. iwe.u.freq.m = channel_frequency[channel-1] * 100000;
  4656. iwe.u.freq.e = 1;
  4657. current_ev = iwe_stream_add_event(info, current_ev, end_buf,
  4658. &iwe, IW_EV_FREQ_LEN);
  4659. }
  4660. /* Add quality statistics. level and noise in dB. No link quality */
  4661. iwe.cmd = IWEVQUAL;
  4662. iwe.u.qual.updated = IW_QUAL_DBM | IW_QUAL_QUAL_INVALID;
  4663. iwe.u.qual.level = (__u8) le16_to_cpu(bss->a.level) - 0x95;
  4664. iwe.u.qual.noise = (__u8) le16_to_cpu(bss->a.noise) - 0x95;
  4665. /* Wireless tools prior to 27.pre22 will show link quality
  4666. * anyway, so we provide a reasonable value. */
  4667. if (iwe.u.qual.level > iwe.u.qual.noise)
  4668. iwe.u.qual.qual = iwe.u.qual.level - iwe.u.qual.noise;
  4669. else
  4670. iwe.u.qual.qual = 0;
  4671. current_ev = iwe_stream_add_event(info, current_ev, end_buf,
  4672. &iwe, IW_EV_QUAL_LEN);
  4673. /* Add encryption capability */
  4674. iwe.cmd = SIOCGIWENCODE;
  4675. if (capabilities & WLAN_CAPABILITY_PRIVACY)
  4676. iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
  4677. else
  4678. iwe.u.data.flags = IW_ENCODE_DISABLED;
  4679. iwe.u.data.length = 0;
  4680. current_ev = iwe_stream_add_point(info, current_ev, end_buf,
  4681. &iwe, NULL);
  4682. /* Bit rate is not available in Lucent/Agere firmwares */
  4683. if (priv->firmware_type != FIRMWARE_TYPE_AGERE) {
  4684. char *current_val = current_ev + iwe_stream_lcp_len(info);
  4685. int i;
  4686. int step;
  4687. if (priv->firmware_type == FIRMWARE_TYPE_SYMBOL)
  4688. step = 2;
  4689. else
  4690. step = 1;
  4691. iwe.cmd = SIOCGIWRATE;
  4692. /* Those two flags are ignored... */
  4693. iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
  4694. /* Max 10 values */
  4695. for (i = 0; i < 10; i += step) {
  4696. /* NULL terminated */
  4697. if (bss->p.rates[i] == 0x0)
  4698. break;
  4699. /* Bit rate given in 500 kb/s units (+ 0x80) */
  4700. iwe.u.bitrate.value =
  4701. ((bss->p.rates[i] & 0x7f) * 500000);
  4702. current_val = iwe_stream_add_value(info, current_ev,
  4703. current_val,
  4704. end_buf, &iwe,
  4705. IW_EV_PARAM_LEN);
  4706. }
  4707. /* Check if we added any event */
  4708. if ((current_val - current_ev) > iwe_stream_lcp_len(info))
  4709. current_ev = current_val;
  4710. }
  4711. /* Beacon interval */
  4712. iwe.cmd = IWEVCUSTOM;
  4713. iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN,
  4714. "bcn_int=%d",
  4715. le16_to_cpu(bss->a.beacon_interv));
  4716. if (iwe.u.data.length)
  4717. current_ev = iwe_stream_add_point(info, current_ev, end_buf,
  4718. &iwe, custom);
  4719. /* Capabilites */
  4720. iwe.cmd = IWEVCUSTOM;
  4721. iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN,
  4722. "capab=0x%04x",
  4723. capabilities);
  4724. if (iwe.u.data.length)
  4725. current_ev = iwe_stream_add_point(info, current_ev, end_buf,
  4726. &iwe, custom);
  4727. /* Add EXTRA: Age to display seconds since last beacon/probe response
  4728. * for given network. */
  4729. iwe.cmd = IWEVCUSTOM;
  4730. iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN,
  4731. " Last beacon: %dms ago",
  4732. jiffies_to_msecs(jiffies - last_scanned));
  4733. if (iwe.u.data.length)
  4734. current_ev = iwe_stream_add_point(info, current_ev, end_buf,
  4735. &iwe, custom);
  4736. return current_ev;
  4737. }
  4738. static inline char *orinoco_translate_ext_scan(struct net_device *dev,
  4739. struct iw_request_info *info,
  4740. char *current_ev,
  4741. char *end_buf,
  4742. struct agere_ext_scan_info *bss,
  4743. unsigned int last_scanned)
  4744. {
  4745. u16 capabilities;
  4746. u16 channel;
  4747. struct iw_event iwe; /* Temporary buffer */
  4748. char custom[MAX_CUSTOM_LEN];
  4749. u8 *ie;
  4750. memset(&iwe, 0, sizeof(iwe));
  4751. /* First entry *MUST* be the AP MAC address */
  4752. iwe.cmd = SIOCGIWAP;
  4753. iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
  4754. memcpy(iwe.u.ap_addr.sa_data, bss->bssid, ETH_ALEN);
  4755. current_ev = iwe_stream_add_event(info, current_ev, end_buf,
  4756. &iwe, IW_EV_ADDR_LEN);
  4757. /* Other entries will be displayed in the order we give them */
  4758. /* Add the ESSID */
  4759. ie = bss->data;
  4760. iwe.u.data.length = ie[1];
  4761. if (iwe.u.data.length) {
  4762. if (iwe.u.data.length > 32)
  4763. iwe.u.data.length = 32;
  4764. iwe.cmd = SIOCGIWESSID;
  4765. iwe.u.data.flags = 1;
  4766. current_ev = iwe_stream_add_point(info, current_ev, end_buf,
  4767. &iwe, &ie[2]);
  4768. }
  4769. /* Add mode */
  4770. capabilities = le16_to_cpu(bss->capabilities);
  4771. if (capabilities & (WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_IBSS)) {
  4772. iwe.cmd = SIOCGIWMODE;
  4773. if (capabilities & WLAN_CAPABILITY_ESS)
  4774. iwe.u.mode = IW_MODE_MASTER;
  4775. else
  4776. iwe.u.mode = IW_MODE_ADHOC;
  4777. current_ev = iwe_stream_add_event(info, current_ev, end_buf,
  4778. &iwe, IW_EV_UINT_LEN);
  4779. }
  4780. ie = orinoco_get_ie(bss->data, sizeof(bss->data), WLAN_EID_DS_PARAMS);
  4781. channel = ie ? ie[2] : 0;
  4782. if ((channel >= 1) && (channel <= NUM_CHANNELS)) {
  4783. /* Add channel and frequency */
  4784. iwe.cmd = SIOCGIWFREQ;
  4785. iwe.u.freq.m = channel;
  4786. iwe.u.freq.e = 0;
  4787. current_ev = iwe_stream_add_event(info, current_ev, end_buf,
  4788. &iwe, IW_EV_FREQ_LEN);
  4789. iwe.u.freq.m = channel_frequency[channel-1] * 100000;
  4790. iwe.u.freq.e = 1;
  4791. current_ev = iwe_stream_add_event(info, current_ev, end_buf,
  4792. &iwe, IW_EV_FREQ_LEN);
  4793. }
  4794. /* Add quality statistics. level and noise in dB. No link quality */
  4795. iwe.cmd = IWEVQUAL;
  4796. iwe.u.qual.updated = IW_QUAL_DBM | IW_QUAL_QUAL_INVALID;
  4797. iwe.u.qual.level = bss->level - 0x95;
  4798. iwe.u.qual.noise = bss->noise - 0x95;
  4799. /* Wireless tools prior to 27.pre22 will show link quality
  4800. * anyway, so we provide a reasonable value. */
  4801. if (iwe.u.qual.level > iwe.u.qual.noise)
  4802. iwe.u.qual.qual = iwe.u.qual.level - iwe.u.qual.noise;
  4803. else
  4804. iwe.u.qual.qual = 0;
  4805. current_ev = iwe_stream_add_event(info, current_ev, end_buf,
  4806. &iwe, IW_EV_QUAL_LEN);
  4807. /* Add encryption capability */
  4808. iwe.cmd = SIOCGIWENCODE;
  4809. if (capabilities & WLAN_CAPABILITY_PRIVACY)
  4810. iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
  4811. else
  4812. iwe.u.data.flags = IW_ENCODE_DISABLED;
  4813. iwe.u.data.length = 0;
  4814. current_ev = iwe_stream_add_point(info, current_ev, end_buf,
  4815. &iwe, NULL);
  4816. /* WPA IE */
  4817. ie = orinoco_get_wpa_ie(bss->data, sizeof(bss->data));
  4818. if (ie) {
  4819. iwe.cmd = IWEVGENIE;
  4820. iwe.u.data.length = ie[1] + 2;
  4821. current_ev = iwe_stream_add_point(info, current_ev, end_buf,
  4822. &iwe, ie);
  4823. }
  4824. /* RSN IE */
  4825. ie = orinoco_get_ie(bss->data, sizeof(bss->data), WLAN_EID_RSN);
  4826. if (ie) {
  4827. iwe.cmd = IWEVGENIE;
  4828. iwe.u.data.length = ie[1] + 2;
  4829. current_ev = iwe_stream_add_point(info, current_ev, end_buf,
  4830. &iwe, ie);
  4831. }
  4832. ie = orinoco_get_ie(bss->data, sizeof(bss->data), WLAN_EID_SUPP_RATES);
  4833. if (ie) {
  4834. char *p = current_ev + iwe_stream_lcp_len(info);
  4835. int i;
  4836. iwe.cmd = SIOCGIWRATE;
  4837. /* Those two flags are ignored... */
  4838. iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
  4839. for (i = 2; i < (ie[1] + 2); i++) {
  4840. iwe.u.bitrate.value = ((ie[i] & 0x7F) * 500000);
  4841. p = iwe_stream_add_value(info, current_ev, p, end_buf,
  4842. &iwe, IW_EV_PARAM_LEN);
  4843. }
  4844. /* Check if we added any event */
  4845. if (p > (current_ev + iwe_stream_lcp_len(info)))
  4846. current_ev = p;
  4847. }
  4848. /* Timestamp */
  4849. iwe.cmd = IWEVCUSTOM;
  4850. iwe.u.data.length =
  4851. snprintf(custom, MAX_CUSTOM_LEN, "tsf=%016llx",
  4852. (unsigned long long) le64_to_cpu(bss->timestamp));
  4853. if (iwe.u.data.length)
  4854. current_ev = iwe_stream_add_point(info, current_ev, end_buf,
  4855. &iwe, custom);
  4856. /* Beacon interval */
  4857. iwe.cmd = IWEVCUSTOM;
  4858. iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN,
  4859. "bcn_int=%d",
  4860. le16_to_cpu(bss->beacon_interval));
  4861. if (iwe.u.data.length)
  4862. current_ev = iwe_stream_add_point(info, current_ev, end_buf,
  4863. &iwe, custom);
  4864. /* Capabilites */
  4865. iwe.cmd = IWEVCUSTOM;
  4866. iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN,
  4867. "capab=0x%04x",
  4868. capabilities);
  4869. if (iwe.u.data.length)
  4870. current_ev = iwe_stream_add_point(info, current_ev, end_buf,
  4871. &iwe, custom);
  4872. /* Add EXTRA: Age to display seconds since last beacon/probe response
  4873. * for given network. */
  4874. iwe.cmd = IWEVCUSTOM;
  4875. iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN,
  4876. " Last beacon: %dms ago",
  4877. jiffies_to_msecs(jiffies - last_scanned));
  4878. if (iwe.u.data.length)
  4879. current_ev = iwe_stream_add_point(info, current_ev, end_buf,
  4880. &iwe, custom);
  4881. return current_ev;
  4882. }
  4883. /* Return results of a scan */
  4884. static int orinoco_ioctl_getscan(struct net_device *dev,
  4885. struct iw_request_info *info,
  4886. struct iw_point *srq,
  4887. char *extra)
  4888. {
  4889. struct orinoco_private *priv = netdev_priv(dev);
  4890. int err = 0;
  4891. unsigned long flags;
  4892. char *current_ev = extra;
  4893. if (orinoco_lock(priv, &flags) != 0)
  4894. return -EBUSY;
  4895. if (priv->scan_inprogress) {
  4896. /* Important note : we don't want to block the caller
  4897. * until results are ready for various reasons.
  4898. * First, managing wait queues is complex and racy.
  4899. * Second, we grab some rtnetlink lock before comming
  4900. * here (in dev_ioctl()).
  4901. * Third, we generate an Wireless Event, so the
  4902. * caller can wait itself on that - Jean II */
  4903. err = -EAGAIN;
  4904. goto out;
  4905. }
  4906. if (priv->has_ext_scan) {
  4907. struct xbss_element *bss;
  4908. list_for_each_entry(bss, &priv->bss_list, list) {
  4909. /* Translate this entry to WE format */
  4910. current_ev =
  4911. orinoco_translate_ext_scan(dev, info,
  4912. current_ev,
  4913. extra + srq->length,
  4914. &bss->bss,
  4915. bss->last_scanned);
  4916. /* Check if there is space for one more entry */
  4917. if ((extra + srq->length - current_ev)
  4918. <= IW_EV_ADDR_LEN) {
  4919. /* Ask user space to try again with a
  4920. * bigger buffer */
  4921. err = -E2BIG;
  4922. goto out;
  4923. }
  4924. }
  4925. } else {
  4926. struct bss_element *bss;
  4927. list_for_each_entry(bss, &priv->bss_list, list) {
  4928. /* Translate this entry to WE format */
  4929. current_ev = orinoco_translate_scan(dev, info,
  4930. current_ev,
  4931. extra + srq->length,
  4932. &bss->bss,
  4933. bss->last_scanned);
  4934. /* Check if there is space for one more entry */
  4935. if ((extra + srq->length - current_ev)
  4936. <= IW_EV_ADDR_LEN) {
  4937. /* Ask user space to try again with a
  4938. * bigger buffer */
  4939. err = -E2BIG;
  4940. goto out;
  4941. }
  4942. }
  4943. }
  4944. srq->length = (current_ev - extra);
  4945. srq->flags = (__u16) priv->scan_mode;
  4946. out:
  4947. orinoco_unlock(priv, &flags);
  4948. return err;
  4949. }
  4950. /* Commit handler, called after set operations */
  4951. static int orinoco_ioctl_commit(struct net_device *dev,
  4952. struct iw_request_info *info,
  4953. void *wrqu,
  4954. char *extra)
  4955. {
  4956. struct orinoco_private *priv = netdev_priv(dev);
  4957. struct hermes *hw = &priv->hw;
  4958. unsigned long flags;
  4959. int err = 0;
  4960. if (!priv->open)
  4961. return 0;
  4962. if (priv->broken_disableport) {
  4963. orinoco_reset(&priv->reset_work);
  4964. return 0;
  4965. }
  4966. if (orinoco_lock(priv, &flags) != 0)
  4967. return err;
  4968. err = hermes_disable_port(hw, 0);
  4969. if (err) {
  4970. printk(KERN_WARNING "%s: Unable to disable port "
  4971. "while reconfiguring card\n", dev->name);
  4972. priv->broken_disableport = 1;
  4973. goto out;
  4974. }
  4975. err = __orinoco_program_rids(dev);
  4976. if (err) {
  4977. printk(KERN_WARNING "%s: Unable to reconfigure card\n",
  4978. dev->name);
  4979. goto out;
  4980. }
  4981. err = hermes_enable_port(hw, 0);
  4982. if (err) {
  4983. printk(KERN_WARNING "%s: Unable to enable port while reconfiguring card\n",
  4984. dev->name);
  4985. goto out;
  4986. }
  4987. out:
  4988. if (err) {
  4989. printk(KERN_WARNING "%s: Resetting instead...\n", dev->name);
  4990. schedule_work(&priv->reset_work);
  4991. err = 0;
  4992. }
  4993. orinoco_unlock(priv, &flags);
  4994. return err;
  4995. }
  4996. static const struct iw_priv_args orinoco_privtab[] = {
  4997. { SIOCIWFIRSTPRIV + 0x0, 0, 0, "force_reset" },
  4998. { SIOCIWFIRSTPRIV + 0x1, 0, 0, "card_reset" },
  4999. { SIOCIWFIRSTPRIV + 0x2, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  5000. 0, "set_port3" },
  5001. { SIOCIWFIRSTPRIV + 0x3, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  5002. "get_port3" },
  5003. { SIOCIWFIRSTPRIV + 0x4, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  5004. 0, "set_preamble" },
  5005. { SIOCIWFIRSTPRIV + 0x5, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  5006. "get_preamble" },
  5007. { SIOCIWFIRSTPRIV + 0x6, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  5008. 0, "set_ibssport" },
  5009. { SIOCIWFIRSTPRIV + 0x7, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  5010. "get_ibssport" },
  5011. { SIOCIWFIRSTPRIV + 0x9, 0, IW_PRIV_TYPE_BYTE | MAX_RID_LEN,
  5012. "get_rid" },
  5013. };
  5014. /*
  5015. * Structures to export the Wireless Handlers
  5016. */
  5017. #define STD_IW_HANDLER(id, func) \
  5018. [IW_IOCTL_IDX(id)] = (iw_handler) func
  5019. static const iw_handler orinoco_handler[] = {
  5020. STD_IW_HANDLER(SIOCSIWCOMMIT, orinoco_ioctl_commit),
  5021. STD_IW_HANDLER(SIOCGIWNAME, orinoco_ioctl_getname),
  5022. STD_IW_HANDLER(SIOCSIWFREQ, orinoco_ioctl_setfreq),
  5023. STD_IW_HANDLER(SIOCGIWFREQ, orinoco_ioctl_getfreq),
  5024. STD_IW_HANDLER(SIOCSIWMODE, orinoco_ioctl_setmode),
  5025. STD_IW_HANDLER(SIOCGIWMODE, orinoco_ioctl_getmode),
  5026. STD_IW_HANDLER(SIOCSIWSENS, orinoco_ioctl_setsens),
  5027. STD_IW_HANDLER(SIOCGIWSENS, orinoco_ioctl_getsens),
  5028. STD_IW_HANDLER(SIOCGIWRANGE, orinoco_ioctl_getiwrange),
  5029. STD_IW_HANDLER(SIOCSIWSPY, iw_handler_set_spy),
  5030. STD_IW_HANDLER(SIOCGIWSPY, iw_handler_get_spy),
  5031. STD_IW_HANDLER(SIOCSIWTHRSPY, iw_handler_set_thrspy),
  5032. STD_IW_HANDLER(SIOCGIWTHRSPY, iw_handler_get_thrspy),
  5033. STD_IW_HANDLER(SIOCSIWAP, orinoco_ioctl_setwap),
  5034. STD_IW_HANDLER(SIOCGIWAP, orinoco_ioctl_getwap),
  5035. STD_IW_HANDLER(SIOCSIWSCAN, orinoco_ioctl_setscan),
  5036. STD_IW_HANDLER(SIOCGIWSCAN, orinoco_ioctl_getscan),
  5037. STD_IW_HANDLER(SIOCSIWESSID, orinoco_ioctl_setessid),
  5038. STD_IW_HANDLER(SIOCGIWESSID, orinoco_ioctl_getessid),
  5039. STD_IW_HANDLER(SIOCSIWNICKN, orinoco_ioctl_setnick),
  5040. STD_IW_HANDLER(SIOCGIWNICKN, orinoco_ioctl_getnick),
  5041. STD_IW_HANDLER(SIOCSIWRATE, orinoco_ioctl_setrate),
  5042. STD_IW_HANDLER(SIOCGIWRATE, orinoco_ioctl_getrate),
  5043. STD_IW_HANDLER(SIOCSIWRTS, orinoco_ioctl_setrts),
  5044. STD_IW_HANDLER(SIOCGIWRTS, orinoco_ioctl_getrts),
  5045. STD_IW_HANDLER(SIOCSIWFRAG, orinoco_ioctl_setfrag),
  5046. STD_IW_HANDLER(SIOCGIWFRAG, orinoco_ioctl_getfrag),
  5047. STD_IW_HANDLER(SIOCGIWRETRY, orinoco_ioctl_getretry),
  5048. STD_IW_HANDLER(SIOCSIWENCODE, orinoco_ioctl_setiwencode),
  5049. STD_IW_HANDLER(SIOCGIWENCODE, orinoco_ioctl_getiwencode),
  5050. STD_IW_HANDLER(SIOCSIWPOWER, orinoco_ioctl_setpower),
  5051. STD_IW_HANDLER(SIOCGIWPOWER, orinoco_ioctl_getpower),
  5052. STD_IW_HANDLER(SIOCSIWGENIE, orinoco_ioctl_set_genie),
  5053. STD_IW_HANDLER(SIOCGIWGENIE, orinoco_ioctl_get_genie),
  5054. STD_IW_HANDLER(SIOCSIWMLME, orinoco_ioctl_set_mlme),
  5055. STD_IW_HANDLER(SIOCSIWAUTH, orinoco_ioctl_set_auth),
  5056. STD_IW_HANDLER(SIOCGIWAUTH, orinoco_ioctl_get_auth),
  5057. STD_IW_HANDLER(SIOCSIWENCODEEXT, orinoco_ioctl_set_encodeext),
  5058. STD_IW_HANDLER(SIOCGIWENCODEEXT, orinoco_ioctl_get_encodeext),
  5059. };
  5060. /*
  5061. Added typecasting since we no longer use iwreq_data -- Moustafa
  5062. */
  5063. static const iw_handler orinoco_private_handler[] = {
  5064. [0] = (iw_handler) orinoco_ioctl_reset,
  5065. [1] = (iw_handler) orinoco_ioctl_reset,
  5066. [2] = (iw_handler) orinoco_ioctl_setport3,
  5067. [3] = (iw_handler) orinoco_ioctl_getport3,
  5068. [4] = (iw_handler) orinoco_ioctl_setpreamble,
  5069. [5] = (iw_handler) orinoco_ioctl_getpreamble,
  5070. [6] = (iw_handler) orinoco_ioctl_setibssport,
  5071. [7] = (iw_handler) orinoco_ioctl_getibssport,
  5072. [9] = (iw_handler) orinoco_ioctl_getrid,
  5073. };
  5074. static const struct iw_handler_def orinoco_handler_def = {
  5075. .num_standard = ARRAY_SIZE(orinoco_handler),
  5076. .num_private = ARRAY_SIZE(orinoco_private_handler),
  5077. .num_private_args = ARRAY_SIZE(orinoco_privtab),
  5078. .standard = orinoco_handler,
  5079. .private = orinoco_private_handler,
  5080. .private_args = orinoco_privtab,
  5081. .get_wireless_stats = orinoco_get_wireless_stats,
  5082. };
  5083. static void orinoco_get_drvinfo(struct net_device *dev,
  5084. struct ethtool_drvinfo *info)
  5085. {
  5086. struct orinoco_private *priv = netdev_priv(dev);
  5087. strncpy(info->driver, DRIVER_NAME, sizeof(info->driver) - 1);
  5088. strncpy(info->version, DRIVER_VERSION, sizeof(info->version) - 1);
  5089. strncpy(info->fw_version, priv->fw_name, sizeof(info->fw_version) - 1);
  5090. if (dev->dev.parent)
  5091. strncpy(info->bus_info, dev_name(dev->dev.parent),
  5092. sizeof(info->bus_info) - 1);
  5093. else
  5094. snprintf(info->bus_info, sizeof(info->bus_info) - 1,
  5095. "PCMCIA %p", priv->hw.iobase);
  5096. }
  5097. static const struct ethtool_ops orinoco_ethtool_ops = {
  5098. .get_drvinfo = orinoco_get_drvinfo,
  5099. .get_link = ethtool_op_get_link,
  5100. };
  5101. /********************************************************************/
  5102. /* Module initialization */
  5103. /********************************************************************/
  5104. EXPORT_SYMBOL(alloc_orinocodev);
  5105. EXPORT_SYMBOL(free_orinocodev);
  5106. EXPORT_SYMBOL(__orinoco_up);
  5107. EXPORT_SYMBOL(__orinoco_down);
  5108. EXPORT_SYMBOL(orinoco_reinit_firmware);
  5109. EXPORT_SYMBOL(orinoco_interrupt);
  5110. /* Can't be declared "const" or the whole __initdata section will
  5111. * become const */
  5112. static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION
  5113. " (David Gibson <hermes@gibson.dropbear.id.au>, "
  5114. "Pavel Roskin <proski@gnu.org>, et al)";
  5115. static int __init init_orinoco(void)
  5116. {
  5117. printk(KERN_DEBUG "%s\n", version);
  5118. return 0;
  5119. }
  5120. static void __exit exit_orinoco(void)
  5121. {
  5122. }
  5123. module_init(init_orinoco);
  5124. module_exit(exit_orinoco);