orinoco.c 155 KB

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