orinoco.c 155 KB

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