orinoco.c 137 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869
  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. * v0.01 -> v0.02 - 21/3/2001 - Jean II
  49. * o Allow to use regular ethX device name instead of dldwdX
  50. * o Warning on IBSS with ESSID=any for firmware 6.06
  51. * o Put proper range.throughput values (optimistic)
  52. * o IWSPY support (IOCTL and stat gather in Rx path)
  53. * o Allow setting frequency in Ad-Hoc mode
  54. * o Disable WEP setting if !has_wep to work on old firmware
  55. * o Fix txpower range
  56. * o Start adding support for Samsung/Compaq firmware
  57. *
  58. * v0.02 -> v0.03 - 23/3/2001 - Jean II
  59. * o Start adding Symbol support - need to check all that
  60. * o Fix Prism2/Symbol WEP to accept 128 bits keys
  61. * o Add Symbol WEP (add authentication type)
  62. * o Add Prism2/Symbol rate
  63. * o Add PM timeout (holdover duration)
  64. * o Enable "iwconfig eth0 key off" and friends (toggle flags)
  65. * o Enable "iwconfig eth0 power unicast/all" (toggle flags)
  66. * o Try with an Intel card. It report firmware 1.01, behave like
  67. * an antiquated firmware, however on windows it says 2.00. Yuck !
  68. * o Workaround firmware bug in allocate buffer (Intel 1.01)
  69. * o Finish external renaming to orinoco...
  70. * o Testing with various Wavelan firmwares
  71. *
  72. * v0.03 -> v0.04 - 30/3/2001 - Jean II
  73. * o Update to Wireless 11 -> add retry limit/lifetime support
  74. * o Tested with a D-Link DWL 650 card, fill in firmware support
  75. * o Warning on Vcc mismatch (D-Link 3.3v card in Lucent 5v only slot)
  76. * o Fixed the Prism2 WEP bugs that I introduced in v0.03 :-(
  77. * It works on D-Link *only* after a tcpdump. Weird...
  78. * And still doesn't work on Intel card. Grrrr...
  79. * o Update the mode after a setport3
  80. * o Add preamble setting for Symbol cards (not yet enabled)
  81. * o Don't complain as much about Symbol cards...
  82. *
  83. * v0.04 -> v0.04b - 22/4/2001 - David Gibson
  84. * o Removed the 'eth' parameter - always use ethXX as the
  85. * interface name instead of dldwdXX. The other was racy
  86. * anyway.
  87. * o Clean up RID definitions in hermes.h, other cleanups
  88. *
  89. * v0.04b -> v0.04c - 24/4/2001 - Jean II
  90. * o Tim Hurley <timster AT seiki.bliztech.com> reported a D-Link card
  91. * with vendor 02 and firmware 0.08. Added in the capabilities...
  92. * o Tested Lucent firmware 7.28, everything works...
  93. *
  94. * v0.04c -> v0.05 - 3/5/2001 - Benjamin Herrenschmidt
  95. * o Spin-off Pcmcia code. This file is renamed orinoco.c,
  96. * and orinoco_cs.c now contains only the Pcmcia specific stuff
  97. * o Add Airport driver support on top of orinoco.c (see airport.c)
  98. *
  99. * v0.05 -> v0.05a - 4/5/2001 - Jean II
  100. * o Revert to old Pcmcia code to fix breakage of Ben's changes...
  101. *
  102. * v0.05a -> v0.05b - 4/5/2001 - Jean II
  103. * o add module parameter 'ignore_cis_vcc' for D-Link @ 5V
  104. * o D-Link firmware doesn't support multicast. We just print a few
  105. * error messages, but otherwise everything works...
  106. * o For David : set/getport3 works fine, just upgrade iwpriv...
  107. *
  108. * v0.05b -> v0.05c - 5/5/2001 - Benjamin Herrenschmidt
  109. * o Adapt airport.c to latest changes in orinoco.c
  110. * o Remove deferred power enabling code
  111. *
  112. * v0.05c -> v0.05d - 5/5/2001 - Jean II
  113. * o Workaround to SNAP decapsulate frame from Linksys AP
  114. * original patch from : Dong Liu <dliu AT research.bell-labs.com>
  115. * (note : the memcmp bug was mine - fixed)
  116. * o Remove set_retry stuff, no firmware support it (bloat--).
  117. *
  118. * v0.05d -> v0.06 - 25/5/2001 - Jean II
  119. * Original patch from "Hong Lin" <alin AT redhat.com>,
  120. * "Ian Kinner" <ikinner AT redhat.com>
  121. * and "David Smith" <dsmith AT redhat.com>
  122. * o Init of priv->tx_rate_ctrl in firmware specific section.
  123. * o Prism2/Symbol rate, upto should be 0xF and not 0x15. Doh !
  124. * o Spectrum card always need cor_reset (for every reset)
  125. * o Fix cor_reset to not lose bit 7 in the register
  126. * o flush_stale_links to remove zombie Pcmcia instances
  127. * o Ack previous hermes event before reset
  128. * Me (with my little hands)
  129. * o Allow orinoco.c to call cor_reset via priv->card_reset_handler
  130. * o Add priv->need_card_reset to toggle this feature
  131. * o Fix various buglets when setting WEP in Symbol firmware
  132. * Now, encryption is fully functional on Symbol cards. Youpi !
  133. *
  134. * v0.06 -> v0.06b - 25/5/2001 - Jean II
  135. * o IBSS on Symbol use port_mode = 4. Please don't ask...
  136. *
  137. * v0.06b -> v0.06c - 29/5/2001 - Jean II
  138. * o Show first spy address in /proc/net/wireless for IBSS mode as well
  139. *
  140. * v0.06c -> v0.06d - 6/7/2001 - David Gibson
  141. * o Change a bunch of KERN_INFO messages to KERN_DEBUG, as per Linus'
  142. * wishes to reduce the number of unnecessary messages.
  143. * o Removed bogus message on CRC error.
  144. * o Merged fixes for v0.08 Prism 2 firmware from William Waghorn
  145. * <willwaghorn AT yahoo.co.uk>
  146. * o Slight cleanup/re-arrangement of firmware detection code.
  147. *
  148. * v0.06d -> v0.06e - 1/8/2001 - David Gibson
  149. * o Removed some redundant global initializers (orinoco_cs.c).
  150. * o Added some module metadata
  151. *
  152. * v0.06e -> v0.06f - 14/8/2001 - David Gibson
  153. * o Wording fix to license
  154. * o Added a 'use_alternate_encaps' module parameter for APs which need an
  155. * oui of 00:00:00. We really need a better way of handling this, but
  156. * the module flag is better than nothing for now.
  157. *
  158. * v0.06f -> v0.07 - 20/8/2001 - David Gibson
  159. * o Removed BAP error retries from hermes_bap_seek(). For Tx we now
  160. * let the upper layers handle the retry, we retry explicitly in the
  161. * Rx path, but don't make as much noise about it.
  162. * o Firmware detection cleanups.
  163. *
  164. * v0.07 -> v0.07a - 1/10/3001 - Jean II
  165. * o Add code to read Symbol firmware revision, inspired by latest code
  166. * in Spectrum24 by Lee John Keyser-Allen - Thanks Lee !
  167. * o Thanks to Jared Valentine <hidden AT xmission.com> for "providing" me
  168. * a 3Com card with a recent firmware, fill out Symbol firmware
  169. * capabilities of latest rev (2.20), as well as older Symbol cards.
  170. * o Disable Power Management in newer Symbol firmware, the API
  171. * has changed (documentation needed).
  172. *
  173. * v0.07a -> v0.08 - 3/10/2001 - David Gibson
  174. * o Fixed a possible buffer overrun found by the Stanford checker (in
  175. * dldwd_ioctl_setiwencode()). Can only be called by root anyway, so not
  176. * a big problem.
  177. * o Turned has_big_wep on for Intersil cards. That's not true for all of
  178. * them but we should at least let the capable ones try.
  179. * o Wait for BUSY to clear at the beginning of hermes_bap_seek(). I
  180. * realized that my assumption that the driver's serialization
  181. * would prevent the BAP being busy on entry was possibly false, because
  182. * things other than seeks may make the BAP busy.
  183. * o Use "alternate" (oui 00:00:00) encapsulation by default.
  184. * Setting use_old_encaps will mimic the old behaviour, but I think we
  185. * will be able to eliminate this.
  186. * o Don't try to make __initdata const (the version string). This can't
  187. * work because of the way the __initdata sectioning works.
  188. * o Added MODULE_LICENSE tags.
  189. * o Support for PLX (transparent PCMCIA->PCI bridge) cards.
  190. * o Changed to using the new type-fascist min/max.
  191. *
  192. * v0.08 -> v0.08a - 9/10/2001 - David Gibson
  193. * o Inserted some missing acknowledgements/info into the Changelog.
  194. * o Fixed some bugs in the normalization of signal level reporting.
  195. * o Fixed bad bug in WEP key handling on Intersil and Symbol firmware,
  196. * which led to an instant crash on big-endian machines.
  197. *
  198. * v0.08a -> v0.08b - 20/11/2001 - David Gibson
  199. * o Lots of cleanup and bugfixes in orinoco_plx.c
  200. * o Cleanup to handling of Tx rate setting.
  201. * o Removed support for old encapsulation method.
  202. * o Removed old "dldwd" names.
  203. * o Split RID constants into a new file hermes_rid.h
  204. * o Renamed RID constants to match linux-wlan-ng and prism2.o
  205. * o Bugfixes in hermes.c
  206. * o Poke the PLX's INTCSR register, so it actually starts
  207. * generating interrupts. These cards might actually work now.
  208. * o Update to wireless extensions v12 (Jean II)
  209. * o Support for tallies and inquire command (Jean II)
  210. * o Airport updates for newer PPC kernels (BenH)
  211. *
  212. * v0.08b -> v0.09 - 21/12/2001 - David Gibson
  213. * o Some new PCI IDs for PLX cards.
  214. * o Removed broken attempt to do ALLMULTI reception. Just use
  215. * promiscuous mode instead
  216. * o Preliminary work for list-AP (Jean II)
  217. * o Airport updates from (BenH)
  218. * o Eliminated racy hw_ready stuff
  219. * o Fixed generation of fake events in irq handler. This should
  220. * finally kill the EIO problems (Jean II & dgibson)
  221. * o Fixed breakage of bitrate set/get on Agere firmware (Jean II)
  222. *
  223. * v0.09 -> v0.09a - 2/1/2002 - David Gibson
  224. * o Fixed stupid mistake in multicast list handling, triggering
  225. * a BUG()
  226. *
  227. * v0.09a -> v0.09b - 16/1/2002 - David Gibson
  228. * o Fixed even stupider mistake in new interrupt handling, which
  229. * seriously broke things on big-endian machines.
  230. * o Removed a bunch of redundant includes and exports.
  231. * o Removed a redundant MOD_{INC,DEC}_USE_COUNT pair in airport.c
  232. * o Don't attempt to do hardware level multicast reception on
  233. * Intersil firmware, just go promisc instead.
  234. * o Typo fixed in hermes_issue_cmd()
  235. * o Eliminated WIRELESS_SPY #ifdefs
  236. * o Status code reported on Tx exceptions
  237. * o Moved netif_wake_queue() from ALLOC interrupts to TX and TXEXC
  238. * interrupts, which should fix the timeouts we're seeing.
  239. *
  240. * v0.09b -> v0.10 - 25 Feb 2002 - David Gibson
  241. * o Removed nested structures used for header parsing, so the
  242. * driver should now work without hackery on ARM
  243. * o Fix for WEP handling on Intersil (Hawk Newton)
  244. * o Eliminated the /proc/hermes/ethXX/regs debugging file. It
  245. * was never very useful.
  246. * o Make Rx errors less noisy.
  247. *
  248. * v0.10 -> v0.11 - 5 Apr 2002 - David Gibson
  249. * o Laid the groundwork in hermes.[ch] for devices which map
  250. * into PCI memory space rather than IO space.
  251. * o Fixed bug in multicast handling (cleared multicast list when
  252. * leaving promiscuous mode).
  253. * o Relegated Tx error messages to debug.
  254. * o Cleaned up / corrected handling of allocation lengths.
  255. * o Set OWNSSID in IBSS mode for WinXP interoperability (jimc).
  256. * o Change to using alloc_etherdev() for structure allocations.
  257. * o Check for and drop undersized packets.
  258. * o Fixed a race in stopping/waking the queue. This should fix
  259. * the timeout problems (Pavel Roskin)
  260. * o Reverted to netif_wake_queue() on the ALLOC event.
  261. * o Fixes for recent Symbol firmwares which lack AP density
  262. * (Pavel Roskin).
  263. *
  264. * v0.11 -> v0.11a - 29 Apr 2002 - David Gibson
  265. * o Handle different register spacing, necessary for Prism 2.5
  266. * PCI adaptors (Steve Hill).
  267. * o Cleaned up initialization of card structures in orinoco_cs
  268. * and airport. Removed card->priv field.
  269. * o Make response structure optional for hermes_docmd_wait()
  270. * Pavel Roskin)
  271. * o Added PCI id for Nortel emobility to orinoco_plx.c.
  272. * o Cleanup to handling of Symbol's allocation bug. (Pavel Roskin)
  273. * o Cleanups to firmware capability detection.
  274. * o Arrange for orinoco_pci.c to override firmware detection.
  275. * We should be able to support the PCI Intersil cards now.
  276. * o Cleanup handling of reset_cor and hard_reset (Pavel Roskin).
  277. * o Remove erroneous use of USER_BAP in the TxExc handler (Jouni
  278. * Malinen).
  279. * o Makefile changes for better integration into David Hinds
  280. * pcmcia-cs package.
  281. *
  282. * v0.11a -> v0.11b - 1 May 2002 - David Gibson
  283. * o Better error reporting in orinoco_plx_init_one()
  284. * o Fixed multiple bad kfree() bugs introduced by the
  285. * alloc_orinocodev() changes.
  286. *
  287. * v0.11b -> v0.12 - 19 Jun 2002 - David Gibson
  288. * o Support changing the MAC address.
  289. * o Correct display of Intersil firmware revision numbers.
  290. * o Entirely revised locking scheme. Should be both simpler and
  291. * better.
  292. * o Merged some common code in orinoco_plx, orinoco_pci and
  293. * airport by creating orinoco_default_{open,stop,reset}()
  294. * which are used as the dev->open, dev->stop, priv->reset
  295. * callbacks if none are specified when alloc_orinocodev() is
  296. * called.
  297. * o Removed orinoco_plx_interrupt() and orinoco_pci_interrupt().
  298. * They didn't do anything.
  299. *
  300. * v0.12 -> v0.12a - 4 Jul 2002 - David Gibson
  301. * o Some rearrangement of code.
  302. * o Numerous fixups to locking and rest handling, particularly
  303. * for PCMCIA.
  304. * o This allows open and stop net_device methods to be in
  305. * orinoco.c now, rather than in the init modules.
  306. * o In orinoco_cs.c link->priv now points to the struct
  307. * net_device not to the struct orinoco_private.
  308. * o Added a check for undersized SNAP frames, which could cause
  309. * crashes.
  310. *
  311. * v0.12a -> v0.12b - 11 Jul 2002 - David Gibson
  312. * o Fix hw->num_init testing code, so num_init is actually
  313. * incremented.
  314. * o Fix very stupid bug in orinoco_cs which broke compile with
  315. * CONFIG_SMP.
  316. * o Squashed a warning.
  317. *
  318. * v0.12b -> v0.12c - 26 Jul 2002 - David Gibson
  319. * o Change to C9X style designated initializers.
  320. * o Add support for 3Com AirConnect PCI.
  321. * o No longer ignore the hard_reset argument to
  322. * alloc_orinocodev(). Oops.
  323. *
  324. * v0.12c -> v0.13beta1 - 13 Sep 2002 - David Gibson
  325. * o Revert the broken 0.12* locking scheme and go to a new yet
  326. * simpler scheme.
  327. * o Do firmware resets only in orinoco_init() and when waking
  328. * the card from hard sleep.
  329. *
  330. * v0.13beta1 -> v0.13 - 27 Sep 2002 - David Gibson
  331. * o Re-introduced full resets (via schedule_task()) on Tx
  332. * timeout.
  333. *
  334. * v0.13 -> v0.13a - 30 Sep 2002 - David Gibson
  335. * o Minor cleanups to info frame handling. Add basic support
  336. * for linkstatus info frames.
  337. * o Include required kernel headers in orinoco.h, to avoid
  338. * compile problems.
  339. *
  340. * v0.13a -> v0.13b - 10 Feb 2003 - David Gibson
  341. * o Implemented hard reset for Airport cards
  342. * o Experimental suspend/resume implementation for orinoco_pci
  343. * o Abolished /proc debugging support, replaced with a debugging
  344. * iwpriv. Now it's ugly and simple instead of ugly and complex.
  345. * o Bugfix in hermes.c if the firmware returned a record length
  346. * of 0, we could go clobbering memory.
  347. * o Bugfix in orinoco_stop() - it used to fail if hw_unavailable
  348. * was set, which was usually true on PCMCIA hot removes.
  349. * o Track LINKSTATUS messages, silently drop Tx packets before
  350. * we are connected (avoids confusing the firmware), and only
  351. * give LINKSTATUS printk()s if the status has changed.
  352. *
  353. * v0.13b -> v0.13c - 11 Mar 2003 - David Gibson
  354. * o Cleanup: use dev instead of priv in various places.
  355. * o Bug fix: Don't ReleaseConfiguration on RESET_PHYSICAL event
  356. * if we're in the middle of a (driver initiated) hard reset.
  357. * o Bug fix: ETH_ZLEN is supposed to include the header
  358. * (Dionysus Blazakis & Manish Karir)
  359. * o Convert to using workqueues instead of taskqueues (and
  360. * backwards compatibility macros for pre 2.5.41 kernels).
  361. * o Drop redundant (I think...) MOD_{INC,DEC}_USE_COUNT in
  362. * airport.c
  363. * o New orinoco_tmd.c init module from Joerg Dorchain for
  364. * TMD7160 based PCI to PCMCIA bridges (similar to
  365. * orinoco_plx.c).
  366. *
  367. * v0.13c -> v0.13d - 22 Apr 2003 - David Gibson
  368. * o Make hw_unavailable a counter, rather than just a flag, this
  369. * is necessary to avoid some races (such as a card being
  370. * removed in the middle of orinoco_reset().
  371. * o Restore Release/RequestConfiguration in the PCMCIA event handler
  372. * when dealing with a driver initiated hard reset. This is
  373. * necessary to prevent hangs due to a spurious interrupt while
  374. * the reset is in progress.
  375. * o Clear the 802.11 header when transmitting, even though we
  376. * don't use it. This fixes a long standing bug on some
  377. * firmwares, which seem to get confused if that isn't done.
  378. * o Be less eager to de-encapsulate SNAP frames, only do so if
  379. * the OUI is 00:00:00 or 00:00:f8, leave others alone. The old
  380. * behaviour broke CDP (Cisco Discovery Protocol).
  381. * o Use dev instead of priv for free_irq() as well as
  382. * request_irq() (oops).
  383. * o Attempt to reset rather than giving up if we get too many
  384. * IRQs.
  385. * o Changed semantics of __orinoco_down() so it can be called
  386. * safely with hw_unavailable set. It also now clears the
  387. * linkstatus (since we're going to have to reassociate).
  388. *
  389. * v0.13d -> v0.13e - 12 May 2003 - David Gibson
  390. * o Support for post-2.5.68 return values from irq handler.
  391. * o Fixed bug where underlength packets would be double counted
  392. * in the rx_dropped statistics.
  393. * o Provided a module parameter to suppress linkstatus messages.
  394. *
  395. * v0.13e -> v0.14alpha1 - 30 Sep 2003 - David Gibson
  396. * o Replaced priv->connected logic with netif_carrier_on/off()
  397. * calls.
  398. * o Remove has_ibss_any and never set the CREATEIBSS RID when
  399. * the ESSID is empty. Too many firmwares break if we do.
  400. * o 2.6 merges: Replace pdev->slot_name with pci_name(), remove
  401. * __devinitdata from PCI ID tables, use free_netdev().
  402. * o Enabled shared-key authentication for Agere firmware (from
  403. * Robert J. Moore <Robert.J.Moore AT allanbank.com>
  404. * o Move netif_wake_queue() (back) to the Tx completion from the
  405. * ALLOC event. This seems to prevent/mitigate the rolling
  406. * error -110 problems at least on some Intersil firmwares.
  407. * Theoretically reduces performance, but I can't measure it.
  408. * Patch from Andrew Tridgell <tridge AT samba.org>
  409. *
  410. * v0.14alpha1 -> v0.14alpha2 - 20 Oct 2003 - David Gibson
  411. * o Correctly turn off shared-key authentication when requested
  412. * (bugfix from Robert J. Moore).
  413. * o Correct airport sleep interfaces for current 2.6 kernels.
  414. * o Add code for key change without disabling/enabling the MAC
  415. * port. This is supposed to allow 802.1x to work sanely, but
  416. * doesn't seem to yet.
  417. *
  418. * TODO
  419. * o New wireless extensions API (patch from Moustafa
  420. * Youssef, updated by Jim Carter and Pavel Roskin).
  421. * o Handle de-encapsulation within network layer, provide 802.11
  422. * headers (patch from Thomas 'Dent' Mirlacher)
  423. * o RF monitor mode support
  424. * o Fix possible races in SPY handling.
  425. * o Disconnect wireless extensions from fundamental configuration.
  426. * o (maybe) Software WEP support (patch from Stano Meduna).
  427. * o (maybe) Use multiple Tx buffers - driver handling queue
  428. * rather than firmware.
  429. */
  430. /* Locking and synchronization:
  431. *
  432. * The basic principle is that everything is serialized through a
  433. * single spinlock, priv->lock. The lock is used in user, bh and irq
  434. * context, so when taken outside hardirq context it should always be
  435. * taken with interrupts disabled. The lock protects both the
  436. * hardware and the struct orinoco_private.
  437. *
  438. * Another flag, priv->hw_unavailable indicates that the hardware is
  439. * unavailable for an extended period of time (e.g. suspended, or in
  440. * the middle of a hard reset). This flag is protected by the
  441. * spinlock. All code which touches the hardware should check the
  442. * flag after taking the lock, and if it is set, give up on whatever
  443. * they are doing and drop the lock again. The orinoco_lock()
  444. * function handles this (it unlocks and returns -EBUSY if
  445. * hw_unavailable is non-zero).
  446. */
  447. #define DRIVER_NAME "orinoco"
  448. #include <linux/config.h>
  449. #include <linux/module.h>
  450. #include <linux/kernel.h>
  451. #include <linux/init.h>
  452. #include <linux/ptrace.h>
  453. #include <linux/slab.h>
  454. #include <linux/string.h>
  455. #include <linux/timer.h>
  456. #include <linux/ioport.h>
  457. #include <linux/netdevice.h>
  458. #include <linux/if_arp.h>
  459. #include <linux/etherdevice.h>
  460. #include <linux/ethtool.h>
  461. #include <linux/wireless.h>
  462. #include <net/iw_handler.h>
  463. #include <net/ieee80211.h>
  464. #include <asm/uaccess.h>
  465. #include <asm/io.h>
  466. #include <asm/system.h>
  467. #include "hermes.h"
  468. #include "hermes_rid.h"
  469. #include "orinoco.h"
  470. #include "ieee802_11.h"
  471. /********************************************************************/
  472. /* Module information */
  473. /********************************************************************/
  474. MODULE_AUTHOR("Pavel Roskin <proski@gnu.org> & David Gibson <hermes@gibson.dropbear.id.au>");
  475. MODULE_DESCRIPTION("Driver for Lucent Orinoco, Prism II based and similar wireless cards");
  476. MODULE_LICENSE("Dual MPL/GPL");
  477. /* Level of debugging. Used in the macros in orinoco.h */
  478. #ifdef ORINOCO_DEBUG
  479. int orinoco_debug = ORINOCO_DEBUG;
  480. module_param(orinoco_debug, int, 0644);
  481. MODULE_PARM_DESC(orinoco_debug, "Debug level");
  482. EXPORT_SYMBOL(orinoco_debug);
  483. #endif
  484. static int suppress_linkstatus; /* = 0 */
  485. module_param(suppress_linkstatus, bool, 0644);
  486. MODULE_PARM_DESC(suppress_linkstatus, "Don't log link status changes");
  487. static int ignore_disconnect; /* = 0 */
  488. module_param(ignore_disconnect, int, 0644);
  489. MODULE_PARM_DESC(ignore_disconnect, "Don't report lost link to the network layer");
  490. static int force_monitor; /* = 0 */
  491. module_param(force_monitor, int, 0644);
  492. MODULE_PARM_DESC(force_monitor, "Allow monitor mode for all firmware versions");
  493. /********************************************************************/
  494. /* Compile time configuration and compatibility stuff */
  495. /********************************************************************/
  496. /* We do this this way to avoid ifdefs in the actual code */
  497. #ifdef WIRELESS_SPY
  498. #define SPY_NUMBER(priv) (priv->spy_number)
  499. #else
  500. #define SPY_NUMBER(priv) 0
  501. #endif /* WIRELESS_SPY */
  502. /********************************************************************/
  503. /* Internal constants */
  504. /********************************************************************/
  505. /* 802.2 LLC/SNAP header used for Ethernet encapsulation over 802.11 */
  506. static const u8 encaps_hdr[] = {0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00};
  507. #define ENCAPS_OVERHEAD (sizeof(encaps_hdr) + 2)
  508. #define ORINOCO_MIN_MTU 256
  509. #define ORINOCO_MAX_MTU (IEEE802_11_DATA_LEN - ENCAPS_OVERHEAD)
  510. #define SYMBOL_MAX_VER_LEN (14)
  511. #define USER_BAP 0
  512. #define IRQ_BAP 1
  513. #define MAX_IRQLOOPS_PER_IRQ 10
  514. #define MAX_IRQLOOPS_PER_JIFFY (20000/HZ) /* Based on a guestimate of
  515. * how many events the
  516. * device could
  517. * legitimately generate */
  518. #define SMALL_KEY_SIZE 5
  519. #define LARGE_KEY_SIZE 13
  520. #define TX_NICBUF_SIZE_BUG 1585 /* Bug in Symbol firmware */
  521. #define DUMMY_FID 0xFFFF
  522. /*#define MAX_MULTICAST(priv) (priv->firmware_type == FIRMWARE_TYPE_AGERE ? \
  523. HERMES_MAX_MULTICAST : 0)*/
  524. #define MAX_MULTICAST(priv) (HERMES_MAX_MULTICAST)
  525. #define ORINOCO_INTEN (HERMES_EV_RX | HERMES_EV_ALLOC \
  526. | HERMES_EV_TX | HERMES_EV_TXEXC \
  527. | HERMES_EV_WTERR | HERMES_EV_INFO \
  528. | HERMES_EV_INFDROP )
  529. #define MAX_RID_LEN 1024
  530. static const struct iw_handler_def orinoco_handler_def;
  531. static struct ethtool_ops orinoco_ethtool_ops;
  532. /********************************************************************/
  533. /* Data tables */
  534. /********************************************************************/
  535. /* The frequency of each channel in MHz */
  536. static const long channel_frequency[] = {
  537. 2412, 2417, 2422, 2427, 2432, 2437, 2442,
  538. 2447, 2452, 2457, 2462, 2467, 2472, 2484
  539. };
  540. #define NUM_CHANNELS ARRAY_SIZE(channel_frequency)
  541. /* This tables gives the actual meanings of the bitrate IDs returned
  542. * by the firmware. */
  543. static struct {
  544. int bitrate; /* in 100s of kilobits */
  545. int automatic;
  546. u16 agere_txratectrl;
  547. u16 intersil_txratectrl;
  548. } bitrate_table[] = {
  549. {110, 1, 3, 15}, /* Entry 0 is the default */
  550. {10, 0, 1, 1},
  551. {10, 1, 1, 1},
  552. {20, 0, 2, 2},
  553. {20, 1, 6, 3},
  554. {55, 0, 4, 4},
  555. {55, 1, 7, 7},
  556. {110, 0, 5, 8},
  557. };
  558. #define BITRATE_TABLE_SIZE ARRAY_SIZE(bitrate_table)
  559. /********************************************************************/
  560. /* Data types */
  561. /********************************************************************/
  562. /* Used in Event handling.
  563. * We avoid nested structres as they break on ARM -- Moustafa */
  564. struct hermes_tx_descriptor_802_11 {
  565. /* hermes_tx_descriptor */
  566. u16 status;
  567. u16 reserved1;
  568. u16 reserved2;
  569. u32 sw_support;
  570. u8 retry_count;
  571. u8 tx_rate;
  572. u16 tx_control;
  573. /* ieee802_11_hdr */
  574. u16 frame_ctl;
  575. u16 duration_id;
  576. u8 addr1[ETH_ALEN];
  577. u8 addr2[ETH_ALEN];
  578. u8 addr3[ETH_ALEN];
  579. u16 seq_ctl;
  580. u8 addr4[ETH_ALEN];
  581. u16 data_len;
  582. /* ethhdr */
  583. unsigned char h_dest[ETH_ALEN]; /* destination eth addr */
  584. unsigned char h_source[ETH_ALEN]; /* source ether addr */
  585. unsigned short h_proto; /* packet type ID field */
  586. /* p8022_hdr */
  587. u8 dsap;
  588. u8 ssap;
  589. u8 ctrl;
  590. u8 oui[3];
  591. u16 ethertype;
  592. } __attribute__ ((packed));
  593. /* Rx frame header except compatibility 802.3 header */
  594. struct hermes_rx_descriptor {
  595. /* Control */
  596. u16 status;
  597. u32 time;
  598. u8 silence;
  599. u8 signal;
  600. u8 rate;
  601. u8 rxflow;
  602. u32 reserved;
  603. /* 802.11 header */
  604. u16 frame_ctl;
  605. u16 duration_id;
  606. u8 addr1[ETH_ALEN];
  607. u8 addr2[ETH_ALEN];
  608. u8 addr3[ETH_ALEN];
  609. u16 seq_ctl;
  610. u8 addr4[ETH_ALEN];
  611. /* Data length */
  612. u16 data_len;
  613. } __attribute__ ((packed));
  614. /********************************************************************/
  615. /* Function prototypes */
  616. /********************************************************************/
  617. static int __orinoco_program_rids(struct net_device *dev);
  618. static void __orinoco_set_multicast_list(struct net_device *dev);
  619. /********************************************************************/
  620. /* Internal helper functions */
  621. /********************************************************************/
  622. static inline void set_port_type(struct orinoco_private *priv)
  623. {
  624. switch (priv->iw_mode) {
  625. case IW_MODE_INFRA:
  626. priv->port_type = 1;
  627. priv->createibss = 0;
  628. break;
  629. case IW_MODE_ADHOC:
  630. if (priv->prefer_port3) {
  631. priv->port_type = 3;
  632. priv->createibss = 0;
  633. } else {
  634. priv->port_type = priv->ibss_port;
  635. priv->createibss = 1;
  636. }
  637. break;
  638. case IW_MODE_MONITOR:
  639. priv->port_type = 3;
  640. priv->createibss = 0;
  641. break;
  642. default:
  643. printk(KERN_ERR "%s: Invalid priv->iw_mode in set_port_type()\n",
  644. priv->ndev->name);
  645. }
  646. }
  647. /********************************************************************/
  648. /* Device methods */
  649. /********************************************************************/
  650. static int orinoco_open(struct net_device *dev)
  651. {
  652. struct orinoco_private *priv = netdev_priv(dev);
  653. unsigned long flags;
  654. int err;
  655. if (orinoco_lock(priv, &flags) != 0)
  656. return -EBUSY;
  657. err = __orinoco_up(dev);
  658. if (! err)
  659. priv->open = 1;
  660. orinoco_unlock(priv, &flags);
  661. return err;
  662. }
  663. static int orinoco_stop(struct net_device *dev)
  664. {
  665. struct orinoco_private *priv = netdev_priv(dev);
  666. int err = 0;
  667. /* We mustn't use orinoco_lock() here, because we need to be
  668. able to close the interface even if hw_unavailable is set
  669. (e.g. as we're released after a PC Card removal) */
  670. spin_lock_irq(&priv->lock);
  671. priv->open = 0;
  672. err = __orinoco_down(dev);
  673. spin_unlock_irq(&priv->lock);
  674. return err;
  675. }
  676. static struct net_device_stats *orinoco_get_stats(struct net_device *dev)
  677. {
  678. struct orinoco_private *priv = netdev_priv(dev);
  679. return &priv->stats;
  680. }
  681. static struct iw_statistics *orinoco_get_wireless_stats(struct net_device *dev)
  682. {
  683. struct orinoco_private *priv = netdev_priv(dev);
  684. hermes_t *hw = &priv->hw;
  685. struct iw_statistics *wstats = &priv->wstats;
  686. int err;
  687. unsigned long flags;
  688. if (! netif_device_present(dev)) {
  689. printk(KERN_WARNING "%s: get_wireless_stats() called while device not present\n",
  690. dev->name);
  691. return NULL; /* FIXME: Can we do better than this? */
  692. }
  693. /* If busy, return the old stats. Returning NULL may cause
  694. * the interface to disappear from /proc/net/wireless */
  695. if (orinoco_lock(priv, &flags) != 0)
  696. return wstats;
  697. /* We can't really wait for the tallies inquiry command to
  698. * complete, so we just use the previous results and trigger
  699. * a new tallies inquiry command for next time - Jean II */
  700. /* FIXME: Really we should wait for the inquiry to come back -
  701. * as it is the stats we give don't make a whole lot of sense.
  702. * Unfortunately, it's not clear how to do that within the
  703. * wireless extensions framework: I think we're in user
  704. * context, but a lock seems to be held by the time we get in
  705. * here so we're not safe to sleep here. */
  706. hermes_inquire(hw, HERMES_INQ_TALLIES);
  707. if (priv->iw_mode == IW_MODE_ADHOC) {
  708. memset(&wstats->qual, 0, sizeof(wstats->qual));
  709. /* If a spy address is defined, we report stats of the
  710. * first spy address - Jean II */
  711. if (SPY_NUMBER(priv)) {
  712. wstats->qual.qual = priv->spy_stat[0].qual;
  713. wstats->qual.level = priv->spy_stat[0].level;
  714. wstats->qual.noise = priv->spy_stat[0].noise;
  715. wstats->qual.updated = priv->spy_stat[0].updated;
  716. }
  717. } else {
  718. struct {
  719. u16 qual, signal, noise;
  720. } __attribute__ ((packed)) cq;
  721. err = HERMES_READ_RECORD(hw, USER_BAP,
  722. HERMES_RID_COMMSQUALITY, &cq);
  723. if (!err) {
  724. wstats->qual.qual = (int)le16_to_cpu(cq.qual);
  725. wstats->qual.level = (int)le16_to_cpu(cq.signal) - 0x95;
  726. wstats->qual.noise = (int)le16_to_cpu(cq.noise) - 0x95;
  727. wstats->qual.updated = 7;
  728. }
  729. }
  730. orinoco_unlock(priv, &flags);
  731. return wstats;
  732. }
  733. static void orinoco_set_multicast_list(struct net_device *dev)
  734. {
  735. struct orinoco_private *priv = netdev_priv(dev);
  736. unsigned long flags;
  737. if (orinoco_lock(priv, &flags) != 0) {
  738. printk(KERN_DEBUG "%s: orinoco_set_multicast_list() "
  739. "called when hw_unavailable\n", dev->name);
  740. return;
  741. }
  742. __orinoco_set_multicast_list(dev);
  743. orinoco_unlock(priv, &flags);
  744. }
  745. static int orinoco_change_mtu(struct net_device *dev, int new_mtu)
  746. {
  747. struct orinoco_private *priv = netdev_priv(dev);
  748. if ( (new_mtu < ORINOCO_MIN_MTU) || (new_mtu > ORINOCO_MAX_MTU) )
  749. return -EINVAL;
  750. if ( (new_mtu + ENCAPS_OVERHEAD + IEEE802_11_HLEN) >
  751. (priv->nicbuf_size - ETH_HLEN) )
  752. return -EINVAL;
  753. dev->mtu = new_mtu;
  754. return 0;
  755. }
  756. /********************************************************************/
  757. /* Tx path */
  758. /********************************************************************/
  759. static int orinoco_xmit(struct sk_buff *skb, struct net_device *dev)
  760. {
  761. struct orinoco_private *priv = netdev_priv(dev);
  762. struct net_device_stats *stats = &priv->stats;
  763. hermes_t *hw = &priv->hw;
  764. int err = 0;
  765. u16 txfid = priv->txfid;
  766. char *p;
  767. struct ethhdr *eh;
  768. int len, data_len, data_off;
  769. struct hermes_tx_descriptor desc;
  770. unsigned long flags;
  771. TRACE_ENTER(dev->name);
  772. if (! netif_running(dev)) {
  773. printk(KERN_ERR "%s: Tx on stopped device!\n",
  774. dev->name);
  775. TRACE_EXIT(dev->name);
  776. return 1;
  777. }
  778. if (netif_queue_stopped(dev)) {
  779. printk(KERN_DEBUG "%s: Tx while transmitter busy!\n",
  780. dev->name);
  781. TRACE_EXIT(dev->name);
  782. return 1;
  783. }
  784. if (orinoco_lock(priv, &flags) != 0) {
  785. printk(KERN_ERR "%s: orinoco_xmit() called while hw_unavailable\n",
  786. dev->name);
  787. TRACE_EXIT(dev->name);
  788. return 1;
  789. }
  790. if (! netif_carrier_ok(dev) || (priv->iw_mode == IW_MODE_MONITOR)) {
  791. /* Oops, the firmware hasn't established a connection,
  792. silently drop the packet (this seems to be the
  793. safest approach). */
  794. stats->tx_errors++;
  795. orinoco_unlock(priv, &flags);
  796. dev_kfree_skb(skb);
  797. TRACE_EXIT(dev->name);
  798. return 0;
  799. }
  800. /* Length of the packet body */
  801. /* FIXME: what if the skb is smaller than this? */
  802. len = max_t(int,skb->len - ETH_HLEN, ETH_ZLEN - ETH_HLEN);
  803. eh = (struct ethhdr *)skb->data;
  804. memset(&desc, 0, sizeof(desc));
  805. desc.tx_control = cpu_to_le16(HERMES_TXCTRL_TX_OK | HERMES_TXCTRL_TX_EX);
  806. err = hermes_bap_pwrite(hw, USER_BAP, &desc, sizeof(desc), txfid, 0);
  807. if (err) {
  808. if (net_ratelimit())
  809. printk(KERN_ERR "%s: Error %d writing Tx descriptor "
  810. "to BAP\n", dev->name, err);
  811. stats->tx_errors++;
  812. goto fail;
  813. }
  814. /* Clear the 802.11 header and data length fields - some
  815. * firmwares (e.g. Lucent/Agere 8.xx) appear to get confused
  816. * if this isn't done. */
  817. hermes_clear_words(hw, HERMES_DATA0,
  818. HERMES_802_3_OFFSET - HERMES_802_11_OFFSET);
  819. /* Encapsulate Ethernet-II frames */
  820. if (ntohs(eh->h_proto) > ETH_DATA_LEN) { /* Ethernet-II frame */
  821. struct header_struct hdr;
  822. data_len = len;
  823. data_off = HERMES_802_3_OFFSET + sizeof(hdr);
  824. p = skb->data + ETH_HLEN;
  825. /* 802.3 header */
  826. memcpy(hdr.dest, eh->h_dest, ETH_ALEN);
  827. memcpy(hdr.src, eh->h_source, ETH_ALEN);
  828. hdr.len = htons(data_len + ENCAPS_OVERHEAD);
  829. /* 802.2 header */
  830. memcpy(&hdr.dsap, &encaps_hdr, sizeof(encaps_hdr));
  831. hdr.ethertype = eh->h_proto;
  832. err = hermes_bap_pwrite(hw, USER_BAP, &hdr, sizeof(hdr),
  833. txfid, HERMES_802_3_OFFSET);
  834. if (err) {
  835. if (net_ratelimit())
  836. printk(KERN_ERR "%s: Error %d writing packet "
  837. "header to BAP\n", dev->name, err);
  838. stats->tx_errors++;
  839. goto fail;
  840. }
  841. } else { /* IEEE 802.3 frame */
  842. data_len = len + ETH_HLEN;
  843. data_off = HERMES_802_3_OFFSET;
  844. p = skb->data;
  845. }
  846. /* Round up for odd length packets */
  847. err = hermes_bap_pwrite(hw, USER_BAP, p, ALIGN(data_len, 2),
  848. txfid, data_off);
  849. if (err) {
  850. printk(KERN_ERR "%s: Error %d writing packet to BAP\n",
  851. dev->name, err);
  852. stats->tx_errors++;
  853. goto fail;
  854. }
  855. /* Finally, we actually initiate the send */
  856. netif_stop_queue(dev);
  857. err = hermes_docmd_wait(hw, HERMES_CMD_TX | HERMES_CMD_RECL,
  858. txfid, NULL);
  859. if (err) {
  860. netif_start_queue(dev);
  861. printk(KERN_ERR "%s: Error %d transmitting packet\n",
  862. dev->name, err);
  863. stats->tx_errors++;
  864. goto fail;
  865. }
  866. dev->trans_start = jiffies;
  867. stats->tx_bytes += data_off + data_len;
  868. orinoco_unlock(priv, &flags);
  869. dev_kfree_skb(skb);
  870. TRACE_EXIT(dev->name);
  871. return 0;
  872. fail:
  873. TRACE_EXIT(dev->name);
  874. orinoco_unlock(priv, &flags);
  875. return err;
  876. }
  877. static void __orinoco_ev_alloc(struct net_device *dev, hermes_t *hw)
  878. {
  879. struct orinoco_private *priv = netdev_priv(dev);
  880. u16 fid = hermes_read_regn(hw, ALLOCFID);
  881. if (fid != priv->txfid) {
  882. if (fid != DUMMY_FID)
  883. printk(KERN_WARNING "%s: Allocate event on unexpected fid (%04X)\n",
  884. dev->name, fid);
  885. return;
  886. }
  887. hermes_write_regn(hw, ALLOCFID, DUMMY_FID);
  888. }
  889. static void __orinoco_ev_tx(struct net_device *dev, hermes_t *hw)
  890. {
  891. struct orinoco_private *priv = netdev_priv(dev);
  892. struct net_device_stats *stats = &priv->stats;
  893. stats->tx_packets++;
  894. netif_wake_queue(dev);
  895. hermes_write_regn(hw, TXCOMPLFID, DUMMY_FID);
  896. }
  897. static void __orinoco_ev_txexc(struct net_device *dev, hermes_t *hw)
  898. {
  899. struct orinoco_private *priv = netdev_priv(dev);
  900. struct net_device_stats *stats = &priv->stats;
  901. u16 fid = hermes_read_regn(hw, TXCOMPLFID);
  902. struct hermes_tx_descriptor_802_11 hdr;
  903. int err = 0;
  904. if (fid == DUMMY_FID)
  905. return; /* Nothing's really happened */
  906. /* Read the frame header */
  907. err = hermes_bap_pread(hw, IRQ_BAP, &hdr,
  908. sizeof(struct hermes_tx_descriptor) +
  909. sizeof(struct ieee80211_hdr),
  910. fid, 0);
  911. hermes_write_regn(hw, TXCOMPLFID, DUMMY_FID);
  912. stats->tx_errors++;
  913. if (err) {
  914. printk(KERN_WARNING "%s: Unable to read descriptor on Tx error "
  915. "(FID=%04X error %d)\n",
  916. dev->name, fid, err);
  917. return;
  918. }
  919. DEBUG(1, "%s: Tx error, err %d (FID=%04X)\n", dev->name,
  920. err, fid);
  921. /* We produce a TXDROP event only for retry or lifetime
  922. * exceeded, because that's the only status that really mean
  923. * that this particular node went away.
  924. * Other errors means that *we* screwed up. - Jean II */
  925. hdr.status = le16_to_cpu(hdr.status);
  926. if (hdr.status & (HERMES_TXSTAT_RETRYERR | HERMES_TXSTAT_AGEDERR)) {
  927. union iwreq_data wrqu;
  928. /* Copy 802.11 dest address.
  929. * We use the 802.11 header because the frame may
  930. * not be 802.3 or may be mangled...
  931. * In Ad-Hoc mode, it will be the node address.
  932. * In managed mode, it will be most likely the AP addr
  933. * User space will figure out how to convert it to
  934. * whatever it needs (IP address or else).
  935. * - Jean II */
  936. memcpy(wrqu.addr.sa_data, hdr.addr1, ETH_ALEN);
  937. wrqu.addr.sa_family = ARPHRD_ETHER;
  938. /* Send event to user space */
  939. wireless_send_event(dev, IWEVTXDROP, &wrqu, NULL);
  940. }
  941. netif_wake_queue(dev);
  942. }
  943. static void orinoco_tx_timeout(struct net_device *dev)
  944. {
  945. struct orinoco_private *priv = netdev_priv(dev);
  946. struct net_device_stats *stats = &priv->stats;
  947. struct hermes *hw = &priv->hw;
  948. printk(KERN_WARNING "%s: Tx timeout! "
  949. "ALLOCFID=%04x, TXCOMPLFID=%04x, EVSTAT=%04x\n",
  950. dev->name, hermes_read_regn(hw, ALLOCFID),
  951. hermes_read_regn(hw, TXCOMPLFID), hermes_read_regn(hw, EVSTAT));
  952. stats->tx_errors++;
  953. schedule_work(&priv->reset_work);
  954. }
  955. /********************************************************************/
  956. /* Rx path (data frames) */
  957. /********************************************************************/
  958. /* Does the frame have a SNAP header indicating it should be
  959. * de-encapsulated to Ethernet-II? */
  960. static inline int is_ethersnap(void *_hdr)
  961. {
  962. u8 *hdr = _hdr;
  963. /* We de-encapsulate all packets which, a) have SNAP headers
  964. * (i.e. SSAP=DSAP=0xaa and CTRL=0x3 in the 802.2 LLC header
  965. * and where b) the OUI of the SNAP header is 00:00:00 or
  966. * 00:00:f8 - we need both because different APs appear to use
  967. * different OUIs for some reason */
  968. return (memcmp(hdr, &encaps_hdr, 5) == 0)
  969. && ( (hdr[5] == 0x00) || (hdr[5] == 0xf8) );
  970. }
  971. static inline void orinoco_spy_gather(struct net_device *dev, u_char *mac,
  972. int level, int noise)
  973. {
  974. struct orinoco_private *priv = netdev_priv(dev);
  975. int i;
  976. /* Gather wireless spy statistics: for each packet, compare the
  977. * source address with out list, and if match, get the stats... */
  978. for (i = 0; i < priv->spy_number; i++)
  979. if (!memcmp(mac, priv->spy_address[i], ETH_ALEN)) {
  980. priv->spy_stat[i].level = level - 0x95;
  981. priv->spy_stat[i].noise = noise - 0x95;
  982. priv->spy_stat[i].qual = (level > noise) ? (level - noise) : 0;
  983. priv->spy_stat[i].updated = 7;
  984. }
  985. }
  986. static void orinoco_stat_gather(struct net_device *dev,
  987. struct sk_buff *skb,
  988. struct hermes_rx_descriptor *desc)
  989. {
  990. struct orinoco_private *priv = netdev_priv(dev);
  991. /* Using spy support with lots of Rx packets, like in an
  992. * infrastructure (AP), will really slow down everything, because
  993. * the MAC address must be compared to each entry of the spy list.
  994. * If the user really asks for it (set some address in the
  995. * spy list), we do it, but he will pay the price.
  996. * Note that to get here, you need both WIRELESS_SPY
  997. * compiled in AND some addresses in the list !!!
  998. */
  999. /* Note : gcc will optimise the whole section away if
  1000. * WIRELESS_SPY is not defined... - Jean II */
  1001. if (SPY_NUMBER(priv)) {
  1002. orinoco_spy_gather(dev, skb->mac.raw + ETH_ALEN,
  1003. desc->signal, desc->silence);
  1004. }
  1005. }
  1006. /*
  1007. * orinoco_rx_monitor - handle received monitor frames.
  1008. *
  1009. * Arguments:
  1010. * dev network device
  1011. * rxfid received FID
  1012. * desc rx descriptor of the frame
  1013. *
  1014. * Call context: interrupt
  1015. */
  1016. static void orinoco_rx_monitor(struct net_device *dev, u16 rxfid,
  1017. struct hermes_rx_descriptor *desc)
  1018. {
  1019. u32 hdrlen = 30; /* return full header by default */
  1020. u32 datalen = 0;
  1021. u16 fc;
  1022. int err;
  1023. int len;
  1024. struct sk_buff *skb;
  1025. struct orinoco_private *priv = netdev_priv(dev);
  1026. struct net_device_stats *stats = &priv->stats;
  1027. hermes_t *hw = &priv->hw;
  1028. len = le16_to_cpu(desc->data_len);
  1029. /* Determine the size of the header and the data */
  1030. fc = le16_to_cpu(desc->frame_ctl);
  1031. switch (fc & IEEE80211_FCTL_FTYPE) {
  1032. case IEEE80211_FTYPE_DATA:
  1033. if ((fc & IEEE80211_FCTL_TODS)
  1034. && (fc & IEEE80211_FCTL_FROMDS))
  1035. hdrlen = 30;
  1036. else
  1037. hdrlen = 24;
  1038. datalen = len;
  1039. break;
  1040. case IEEE80211_FTYPE_MGMT:
  1041. hdrlen = 24;
  1042. datalen = len;
  1043. break;
  1044. case IEEE80211_FTYPE_CTL:
  1045. switch (fc & IEEE80211_FCTL_STYPE) {
  1046. case IEEE80211_STYPE_PSPOLL:
  1047. case IEEE80211_STYPE_RTS:
  1048. case IEEE80211_STYPE_CFEND:
  1049. case IEEE80211_STYPE_CFENDACK:
  1050. hdrlen = 16;
  1051. break;
  1052. case IEEE80211_STYPE_CTS:
  1053. case IEEE80211_STYPE_ACK:
  1054. hdrlen = 10;
  1055. break;
  1056. }
  1057. break;
  1058. default:
  1059. /* Unknown frame type */
  1060. break;
  1061. }
  1062. /* sanity check the length */
  1063. if (datalen > IEEE80211_DATA_LEN + 12) {
  1064. printk(KERN_DEBUG "%s: oversized monitor frame, "
  1065. "data length = %d\n", dev->name, datalen);
  1066. err = -EIO;
  1067. stats->rx_length_errors++;
  1068. goto update_stats;
  1069. }
  1070. skb = dev_alloc_skb(hdrlen + datalen);
  1071. if (!skb) {
  1072. printk(KERN_WARNING "%s: Cannot allocate skb for monitor frame\n",
  1073. dev->name);
  1074. err = -ENOMEM;
  1075. goto drop;
  1076. }
  1077. /* Copy the 802.11 header to the skb */
  1078. memcpy(skb_put(skb, hdrlen), &(desc->frame_ctl), hdrlen);
  1079. skb->mac.raw = skb->data;
  1080. /* If any, copy the data from the card to the skb */
  1081. if (datalen > 0) {
  1082. err = hermes_bap_pread(hw, IRQ_BAP, skb_put(skb, datalen),
  1083. ALIGN(datalen, 2), rxfid,
  1084. HERMES_802_2_OFFSET);
  1085. if (err) {
  1086. printk(KERN_ERR "%s: error %d reading monitor frame\n",
  1087. dev->name, err);
  1088. goto drop;
  1089. }
  1090. }
  1091. skb->dev = dev;
  1092. skb->ip_summed = CHECKSUM_NONE;
  1093. skb->pkt_type = PACKET_OTHERHOST;
  1094. skb->protocol = __constant_htons(ETH_P_802_2);
  1095. dev->last_rx = jiffies;
  1096. stats->rx_packets++;
  1097. stats->rx_bytes += skb->len;
  1098. netif_rx(skb);
  1099. return;
  1100. drop:
  1101. dev_kfree_skb_irq(skb);
  1102. update_stats:
  1103. stats->rx_errors++;
  1104. stats->rx_dropped++;
  1105. }
  1106. static void __orinoco_ev_rx(struct net_device *dev, hermes_t *hw)
  1107. {
  1108. struct orinoco_private *priv = netdev_priv(dev);
  1109. struct net_device_stats *stats = &priv->stats;
  1110. struct iw_statistics *wstats = &priv->wstats;
  1111. struct sk_buff *skb = NULL;
  1112. u16 rxfid, status, fc;
  1113. int length;
  1114. struct hermes_rx_descriptor desc;
  1115. struct ethhdr *hdr;
  1116. int err;
  1117. rxfid = hermes_read_regn(hw, RXFID);
  1118. err = hermes_bap_pread(hw, IRQ_BAP, &desc, sizeof(desc),
  1119. rxfid, 0);
  1120. if (err) {
  1121. printk(KERN_ERR "%s: error %d reading Rx descriptor. "
  1122. "Frame dropped.\n", dev->name, err);
  1123. goto update_stats;
  1124. }
  1125. status = le16_to_cpu(desc.status);
  1126. if (status & HERMES_RXSTAT_BADCRC) {
  1127. DEBUG(1, "%s: Bad CRC on Rx. Frame dropped.\n",
  1128. dev->name);
  1129. stats->rx_crc_errors++;
  1130. goto update_stats;
  1131. }
  1132. /* Handle frames in monitor mode */
  1133. if (priv->iw_mode == IW_MODE_MONITOR) {
  1134. orinoco_rx_monitor(dev, rxfid, &desc);
  1135. return;
  1136. }
  1137. if (status & HERMES_RXSTAT_UNDECRYPTABLE) {
  1138. DEBUG(1, "%s: Undecryptable frame on Rx. Frame dropped.\n",
  1139. dev->name);
  1140. wstats->discard.code++;
  1141. goto update_stats;
  1142. }
  1143. length = le16_to_cpu(desc.data_len);
  1144. fc = le16_to_cpu(desc.frame_ctl);
  1145. /* Sanity checks */
  1146. if (length < 3) { /* No for even an 802.2 LLC header */
  1147. /* At least on Symbol firmware with PCF we get quite a
  1148. lot of these legitimately - Poll frames with no
  1149. data. */
  1150. return;
  1151. }
  1152. if (length > IEEE802_11_DATA_LEN) {
  1153. printk(KERN_WARNING "%s: Oversized frame received (%d bytes)\n",
  1154. dev->name, length);
  1155. stats->rx_length_errors++;
  1156. goto update_stats;
  1157. }
  1158. /* We need space for the packet data itself, plus an ethernet
  1159. header, plus 2 bytes so we can align the IP header on a
  1160. 32bit boundary, plus 1 byte so we can read in odd length
  1161. packets from the card, which has an IO granularity of 16
  1162. bits */
  1163. skb = dev_alloc_skb(length+ETH_HLEN+2+1);
  1164. if (!skb) {
  1165. printk(KERN_WARNING "%s: Can't allocate skb for Rx\n",
  1166. dev->name);
  1167. goto update_stats;
  1168. }
  1169. /* We'll prepend the header, so reserve space for it. The worst
  1170. case is no decapsulation, when 802.3 header is prepended and
  1171. nothing is removed. 2 is for aligning the IP header. */
  1172. skb_reserve(skb, ETH_HLEN + 2);
  1173. err = hermes_bap_pread(hw, IRQ_BAP, skb_put(skb, length),
  1174. ALIGN(length, 2), rxfid,
  1175. HERMES_802_2_OFFSET);
  1176. if (err) {
  1177. printk(KERN_ERR "%s: error %d reading frame. "
  1178. "Frame dropped.\n", dev->name, err);
  1179. goto drop;
  1180. }
  1181. /* Handle decapsulation
  1182. * In most cases, the firmware tell us about SNAP frames.
  1183. * For some reason, the SNAP frames sent by LinkSys APs
  1184. * are not properly recognised by most firmwares.
  1185. * So, check ourselves */
  1186. if (length >= ENCAPS_OVERHEAD &&
  1187. (((status & HERMES_RXSTAT_MSGTYPE) == HERMES_RXSTAT_1042) ||
  1188. ((status & HERMES_RXSTAT_MSGTYPE) == HERMES_RXSTAT_TUNNEL) ||
  1189. is_ethersnap(skb->data))) {
  1190. /* These indicate a SNAP within 802.2 LLC within
  1191. 802.11 frame which we'll need to de-encapsulate to
  1192. the original EthernetII frame. */
  1193. hdr = (struct ethhdr *)skb_push(skb, ETH_HLEN - ENCAPS_OVERHEAD);
  1194. } else {
  1195. /* 802.3 frame - prepend 802.3 header as is */
  1196. hdr = (struct ethhdr *)skb_push(skb, ETH_HLEN);
  1197. hdr->h_proto = htons(length);
  1198. }
  1199. memcpy(hdr->h_dest, desc.addr1, ETH_ALEN);
  1200. if (fc & IEEE80211_FCTL_FROMDS)
  1201. memcpy(hdr->h_source, desc.addr3, ETH_ALEN);
  1202. else
  1203. memcpy(hdr->h_source, desc.addr2, ETH_ALEN);
  1204. dev->last_rx = jiffies;
  1205. skb->dev = dev;
  1206. skb->protocol = eth_type_trans(skb, dev);
  1207. skb->ip_summed = CHECKSUM_NONE;
  1208. if (fc & IEEE80211_FCTL_TODS)
  1209. skb->pkt_type = PACKET_OTHERHOST;
  1210. /* Process the wireless stats if needed */
  1211. orinoco_stat_gather(dev, skb, &desc);
  1212. /* Pass the packet to the networking stack */
  1213. netif_rx(skb);
  1214. stats->rx_packets++;
  1215. stats->rx_bytes += length;
  1216. return;
  1217. drop:
  1218. dev_kfree_skb_irq(skb);
  1219. update_stats:
  1220. stats->rx_errors++;
  1221. stats->rx_dropped++;
  1222. }
  1223. /********************************************************************/
  1224. /* Rx path (info frames) */
  1225. /********************************************************************/
  1226. static void print_linkstatus(struct net_device *dev, u16 status)
  1227. {
  1228. char * s;
  1229. if (suppress_linkstatus)
  1230. return;
  1231. switch (status) {
  1232. case HERMES_LINKSTATUS_NOT_CONNECTED:
  1233. s = "Not Connected";
  1234. break;
  1235. case HERMES_LINKSTATUS_CONNECTED:
  1236. s = "Connected";
  1237. break;
  1238. case HERMES_LINKSTATUS_DISCONNECTED:
  1239. s = "Disconnected";
  1240. break;
  1241. case HERMES_LINKSTATUS_AP_CHANGE:
  1242. s = "AP Changed";
  1243. break;
  1244. case HERMES_LINKSTATUS_AP_OUT_OF_RANGE:
  1245. s = "AP Out of Range";
  1246. break;
  1247. case HERMES_LINKSTATUS_AP_IN_RANGE:
  1248. s = "AP In Range";
  1249. break;
  1250. case HERMES_LINKSTATUS_ASSOC_FAILED:
  1251. s = "Association Failed";
  1252. break;
  1253. default:
  1254. s = "UNKNOWN";
  1255. }
  1256. printk(KERN_INFO "%s: New link status: %s (%04x)\n",
  1257. dev->name, s, status);
  1258. }
  1259. /* Search scan results for requested BSSID, join it if found */
  1260. static void orinoco_join_ap(struct net_device *dev)
  1261. {
  1262. struct orinoco_private *priv = netdev_priv(dev);
  1263. struct hermes *hw = &priv->hw;
  1264. int err;
  1265. unsigned long flags;
  1266. struct join_req {
  1267. u8 bssid[ETH_ALEN];
  1268. u16 channel;
  1269. } __attribute__ ((packed)) req;
  1270. const int atom_len = offsetof(struct prism2_scan_apinfo, atim);
  1271. struct prism2_scan_apinfo *atom;
  1272. int offset = 4;
  1273. u8 *buf;
  1274. u16 len;
  1275. /* Allocate buffer for scan results */
  1276. buf = kmalloc(MAX_SCAN_LEN, GFP_KERNEL);
  1277. if (! buf)
  1278. return;
  1279. if (orinoco_lock(priv, &flags) != 0)
  1280. goto out;
  1281. /* Sanity checks in case user changed something in the meantime */
  1282. if (! priv->bssid_fixed)
  1283. goto out;
  1284. if (strlen(priv->desired_essid) == 0)
  1285. goto out;
  1286. /* Read scan results from the firmware */
  1287. err = hermes_read_ltv(hw, USER_BAP,
  1288. HERMES_RID_SCANRESULTSTABLE,
  1289. MAX_SCAN_LEN, &len, buf);
  1290. if (err) {
  1291. printk(KERN_ERR "%s: Cannot read scan results\n",
  1292. dev->name);
  1293. goto out;
  1294. }
  1295. len = HERMES_RECLEN_TO_BYTES(len);
  1296. /* Go through the scan results looking for the channel of the AP
  1297. * we were requested to join */
  1298. for (; offset + atom_len <= len; offset += atom_len) {
  1299. atom = (struct prism2_scan_apinfo *) (buf + offset);
  1300. if (memcmp(&atom->bssid, priv->desired_bssid, ETH_ALEN) == 0)
  1301. goto found;
  1302. }
  1303. DEBUG(1, "%s: Requested AP not found in scan results\n",
  1304. dev->name);
  1305. goto out;
  1306. found:
  1307. memcpy(req.bssid, priv->desired_bssid, ETH_ALEN);
  1308. req.channel = atom->channel; /* both are little-endian */
  1309. err = HERMES_WRITE_RECORD(hw, USER_BAP, HERMES_RID_CNFJOINREQUEST,
  1310. &req);
  1311. if (err)
  1312. printk(KERN_ERR "%s: Error issuing join request\n", dev->name);
  1313. out:
  1314. kfree(buf);
  1315. orinoco_unlock(priv, &flags);
  1316. }
  1317. /* Send new BSSID to userspace */
  1318. static void orinoco_send_wevents(struct net_device *dev)
  1319. {
  1320. struct orinoco_private *priv = netdev_priv(dev);
  1321. struct hermes *hw = &priv->hw;
  1322. union iwreq_data wrqu;
  1323. int err;
  1324. unsigned long flags;
  1325. if (orinoco_lock(priv, &flags) != 0)
  1326. return;
  1327. err = hermes_read_ltv(hw, IRQ_BAP, HERMES_RID_CURRENTBSSID,
  1328. ETH_ALEN, NULL, wrqu.ap_addr.sa_data);
  1329. if (err != 0)
  1330. return;
  1331. wrqu.ap_addr.sa_family = ARPHRD_ETHER;
  1332. /* Send event to user space */
  1333. wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL);
  1334. orinoco_unlock(priv, &flags);
  1335. }
  1336. static void __orinoco_ev_info(struct net_device *dev, hermes_t *hw)
  1337. {
  1338. struct orinoco_private *priv = netdev_priv(dev);
  1339. u16 infofid;
  1340. struct {
  1341. u16 len;
  1342. u16 type;
  1343. } __attribute__ ((packed)) info;
  1344. int len, type;
  1345. int err;
  1346. /* This is an answer to an INQUIRE command that we did earlier,
  1347. * or an information "event" generated by the card
  1348. * The controller return to us a pseudo frame containing
  1349. * the information in question - Jean II */
  1350. infofid = hermes_read_regn(hw, INFOFID);
  1351. /* Read the info frame header - don't try too hard */
  1352. err = hermes_bap_pread(hw, IRQ_BAP, &info, sizeof(info),
  1353. infofid, 0);
  1354. if (err) {
  1355. printk(KERN_ERR "%s: error %d reading info frame. "
  1356. "Frame dropped.\n", dev->name, err);
  1357. return;
  1358. }
  1359. len = HERMES_RECLEN_TO_BYTES(le16_to_cpu(info.len));
  1360. type = le16_to_cpu(info.type);
  1361. switch (type) {
  1362. case HERMES_INQ_TALLIES: {
  1363. struct hermes_tallies_frame tallies;
  1364. struct iw_statistics *wstats = &priv->wstats;
  1365. if (len > sizeof(tallies)) {
  1366. printk(KERN_WARNING "%s: Tallies frame too long (%d bytes)\n",
  1367. dev->name, len);
  1368. len = sizeof(tallies);
  1369. }
  1370. err = hermes_bap_pread(hw, IRQ_BAP, &tallies, len,
  1371. infofid, sizeof(info));
  1372. if (err)
  1373. break;
  1374. /* Increment our various counters */
  1375. /* wstats->discard.nwid - no wrong BSSID stuff */
  1376. wstats->discard.code +=
  1377. le16_to_cpu(tallies.RxWEPUndecryptable);
  1378. if (len == sizeof(tallies))
  1379. wstats->discard.code +=
  1380. le16_to_cpu(tallies.RxDiscards_WEPICVError) +
  1381. le16_to_cpu(tallies.RxDiscards_WEPExcluded);
  1382. wstats->discard.misc +=
  1383. le16_to_cpu(tallies.TxDiscardsWrongSA);
  1384. wstats->discard.fragment +=
  1385. le16_to_cpu(tallies.RxMsgInBadMsgFragments);
  1386. wstats->discard.retries +=
  1387. le16_to_cpu(tallies.TxRetryLimitExceeded);
  1388. /* wstats->miss.beacon - no match */
  1389. }
  1390. break;
  1391. case HERMES_INQ_LINKSTATUS: {
  1392. struct hermes_linkstatus linkstatus;
  1393. u16 newstatus;
  1394. int connected;
  1395. if (priv->iw_mode == IW_MODE_MONITOR)
  1396. break;
  1397. if (len != sizeof(linkstatus)) {
  1398. printk(KERN_WARNING "%s: Unexpected size for linkstatus frame (%d bytes)\n",
  1399. dev->name, len);
  1400. break;
  1401. }
  1402. err = hermes_bap_pread(hw, IRQ_BAP, &linkstatus, len,
  1403. infofid, sizeof(info));
  1404. if (err)
  1405. break;
  1406. newstatus = le16_to_cpu(linkstatus.linkstatus);
  1407. /* Symbol firmware uses "out of range" to signal that
  1408. * the hostscan frame can be requested. */
  1409. if (newstatus == HERMES_LINKSTATUS_AP_OUT_OF_RANGE &&
  1410. priv->firmware_type == FIRMWARE_TYPE_SYMBOL &&
  1411. priv->has_hostscan && priv->scan_inprogress) {
  1412. hermes_inquire(hw, HERMES_INQ_HOSTSCAN_SYMBOL);
  1413. break;
  1414. }
  1415. connected = (newstatus == HERMES_LINKSTATUS_CONNECTED)
  1416. || (newstatus == HERMES_LINKSTATUS_AP_CHANGE)
  1417. || (newstatus == HERMES_LINKSTATUS_AP_IN_RANGE);
  1418. if (connected)
  1419. netif_carrier_on(dev);
  1420. else if (!ignore_disconnect)
  1421. netif_carrier_off(dev);
  1422. if (newstatus != priv->last_linkstatus) {
  1423. priv->last_linkstatus = newstatus;
  1424. print_linkstatus(dev, newstatus);
  1425. /* The info frame contains only one word which is the
  1426. * status (see hermes.h). The status is pretty boring
  1427. * in itself, that's why we export the new BSSID...
  1428. * Jean II */
  1429. schedule_work(&priv->wevent_work);
  1430. }
  1431. }
  1432. break;
  1433. case HERMES_INQ_SCAN:
  1434. if (!priv->scan_inprogress && priv->bssid_fixed &&
  1435. priv->firmware_type == FIRMWARE_TYPE_INTERSIL) {
  1436. schedule_work(&priv->join_work);
  1437. break;
  1438. }
  1439. /* fall through */
  1440. case HERMES_INQ_HOSTSCAN:
  1441. case HERMES_INQ_HOSTSCAN_SYMBOL: {
  1442. /* Result of a scanning. Contains information about
  1443. * cells in the vicinity - Jean II */
  1444. union iwreq_data wrqu;
  1445. unsigned char *buf;
  1446. /* Sanity check */
  1447. if (len > 4096) {
  1448. printk(KERN_WARNING "%s: Scan results too large (%d bytes)\n",
  1449. dev->name, len);
  1450. break;
  1451. }
  1452. /* We are a strict producer. If the previous scan results
  1453. * have not been consumed, we just have to drop this
  1454. * frame. We can't remove the previous results ourselves,
  1455. * that would be *very* racy... Jean II */
  1456. if (priv->scan_result != NULL) {
  1457. printk(KERN_WARNING "%s: Previous scan results not consumed, dropping info frame.\n", dev->name);
  1458. break;
  1459. }
  1460. /* Allocate buffer for results */
  1461. buf = kmalloc(len, GFP_ATOMIC);
  1462. if (buf == NULL)
  1463. /* No memory, so can't printk()... */
  1464. break;
  1465. /* Read scan data */
  1466. err = hermes_bap_pread(hw, IRQ_BAP, (void *) buf, len,
  1467. infofid, sizeof(info));
  1468. if (err)
  1469. break;
  1470. #ifdef ORINOCO_DEBUG
  1471. {
  1472. int i;
  1473. printk(KERN_DEBUG "Scan result [%02X", buf[0]);
  1474. for(i = 1; i < (len * 2); i++)
  1475. printk(":%02X", buf[i]);
  1476. printk("]\n");
  1477. }
  1478. #endif /* ORINOCO_DEBUG */
  1479. /* Allow the clients to access the results */
  1480. priv->scan_len = len;
  1481. priv->scan_result = buf;
  1482. /* Send an empty event to user space.
  1483. * We don't send the received data on the event because
  1484. * it would require us to do complex transcoding, and
  1485. * we want to minimise the work done in the irq handler
  1486. * Use a request to extract the data - Jean II */
  1487. wrqu.data.length = 0;
  1488. wrqu.data.flags = 0;
  1489. wireless_send_event(dev, SIOCGIWSCAN, &wrqu, NULL);
  1490. }
  1491. break;
  1492. case HERMES_INQ_SEC_STAT_AGERE:
  1493. /* Security status (Agere specific) */
  1494. /* Ignore this frame for now */
  1495. if (priv->firmware_type == FIRMWARE_TYPE_AGERE)
  1496. break;
  1497. /* fall through */
  1498. default:
  1499. printk(KERN_DEBUG "%s: Unknown information frame received: "
  1500. "type 0x%04x, length %d\n", dev->name, type, len);
  1501. /* We don't actually do anything about it */
  1502. break;
  1503. }
  1504. }
  1505. static void __orinoco_ev_infdrop(struct net_device *dev, hermes_t *hw)
  1506. {
  1507. if (net_ratelimit())
  1508. printk(KERN_DEBUG "%s: Information frame lost.\n", dev->name);
  1509. }
  1510. /********************************************************************/
  1511. /* Internal hardware control routines */
  1512. /********************************************************************/
  1513. int __orinoco_up(struct net_device *dev)
  1514. {
  1515. struct orinoco_private *priv = netdev_priv(dev);
  1516. struct hermes *hw = &priv->hw;
  1517. int err;
  1518. netif_carrier_off(dev); /* just to make sure */
  1519. err = __orinoco_program_rids(dev);
  1520. if (err) {
  1521. printk(KERN_ERR "%s: Error %d configuring card\n",
  1522. dev->name, err);
  1523. return err;
  1524. }
  1525. /* Fire things up again */
  1526. hermes_set_irqmask(hw, ORINOCO_INTEN);
  1527. err = hermes_enable_port(hw, 0);
  1528. if (err) {
  1529. printk(KERN_ERR "%s: Error %d enabling MAC port\n",
  1530. dev->name, err);
  1531. return err;
  1532. }
  1533. netif_start_queue(dev);
  1534. return 0;
  1535. }
  1536. int __orinoco_down(struct net_device *dev)
  1537. {
  1538. struct orinoco_private *priv = netdev_priv(dev);
  1539. struct hermes *hw = &priv->hw;
  1540. int err;
  1541. netif_stop_queue(dev);
  1542. if (! priv->hw_unavailable) {
  1543. if (! priv->broken_disableport) {
  1544. err = hermes_disable_port(hw, 0);
  1545. if (err) {
  1546. /* Some firmwares (e.g. Intersil 1.3.x) seem
  1547. * to have problems disabling the port, oh
  1548. * well, too bad. */
  1549. printk(KERN_WARNING "%s: Error %d disabling MAC port\n",
  1550. dev->name, err);
  1551. priv->broken_disableport = 1;
  1552. }
  1553. }
  1554. hermes_set_irqmask(hw, 0);
  1555. hermes_write_regn(hw, EVACK, 0xffff);
  1556. }
  1557. /* firmware will have to reassociate */
  1558. netif_carrier_off(dev);
  1559. priv->last_linkstatus = 0xffff;
  1560. return 0;
  1561. }
  1562. int orinoco_reinit_firmware(struct net_device *dev)
  1563. {
  1564. struct orinoco_private *priv = netdev_priv(dev);
  1565. struct hermes *hw = &priv->hw;
  1566. int err;
  1567. err = hermes_init(hw);
  1568. if (err)
  1569. return err;
  1570. err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid);
  1571. if (err == -EIO && priv->nicbuf_size > TX_NICBUF_SIZE_BUG) {
  1572. /* Try workaround for old Symbol firmware bug */
  1573. printk(KERN_WARNING "%s: firmware ALLOC bug detected "
  1574. "(old Symbol firmware?). Trying to work around... ",
  1575. dev->name);
  1576. priv->nicbuf_size = TX_NICBUF_SIZE_BUG;
  1577. err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid);
  1578. if (err)
  1579. printk("failed!\n");
  1580. else
  1581. printk("ok.\n");
  1582. }
  1583. return err;
  1584. }
  1585. static int __orinoco_hw_set_bitrate(struct orinoco_private *priv)
  1586. {
  1587. hermes_t *hw = &priv->hw;
  1588. int err = 0;
  1589. if (priv->bitratemode >= BITRATE_TABLE_SIZE) {
  1590. printk(KERN_ERR "%s: BUG: Invalid bitrate mode %d\n",
  1591. priv->ndev->name, priv->bitratemode);
  1592. return -EINVAL;
  1593. }
  1594. switch (priv->firmware_type) {
  1595. case FIRMWARE_TYPE_AGERE:
  1596. err = hermes_write_wordrec(hw, USER_BAP,
  1597. HERMES_RID_CNFTXRATECONTROL,
  1598. bitrate_table[priv->bitratemode].agere_txratectrl);
  1599. break;
  1600. case FIRMWARE_TYPE_INTERSIL:
  1601. case FIRMWARE_TYPE_SYMBOL:
  1602. err = hermes_write_wordrec(hw, USER_BAP,
  1603. HERMES_RID_CNFTXRATECONTROL,
  1604. bitrate_table[priv->bitratemode].intersil_txratectrl);
  1605. break;
  1606. default:
  1607. BUG();
  1608. }
  1609. return err;
  1610. }
  1611. /* Set fixed AP address */
  1612. static int __orinoco_hw_set_wap(struct orinoco_private *priv)
  1613. {
  1614. int roaming_flag;
  1615. int err = 0;
  1616. hermes_t *hw = &priv->hw;
  1617. switch (priv->firmware_type) {
  1618. case FIRMWARE_TYPE_AGERE:
  1619. /* not supported */
  1620. break;
  1621. case FIRMWARE_TYPE_INTERSIL:
  1622. if (priv->bssid_fixed)
  1623. roaming_flag = 2;
  1624. else
  1625. roaming_flag = 1;
  1626. err = hermes_write_wordrec(hw, USER_BAP,
  1627. HERMES_RID_CNFROAMINGMODE,
  1628. roaming_flag);
  1629. break;
  1630. case FIRMWARE_TYPE_SYMBOL:
  1631. err = HERMES_WRITE_RECORD(hw, USER_BAP,
  1632. HERMES_RID_CNFMANDATORYBSSID_SYMBOL,
  1633. &priv->desired_bssid);
  1634. break;
  1635. }
  1636. return err;
  1637. }
  1638. /* Change the WEP keys and/or the current keys. Can be called
  1639. * either from __orinoco_hw_setup_wep() or directly from
  1640. * orinoco_ioctl_setiwencode(). In the later case the association
  1641. * with the AP is not broken (if the firmware can handle it),
  1642. * which is needed for 802.1x implementations. */
  1643. static int __orinoco_hw_setup_wepkeys(struct orinoco_private *priv)
  1644. {
  1645. hermes_t *hw = &priv->hw;
  1646. int err = 0;
  1647. switch (priv->firmware_type) {
  1648. case FIRMWARE_TYPE_AGERE:
  1649. err = HERMES_WRITE_RECORD(hw, USER_BAP,
  1650. HERMES_RID_CNFWEPKEYS_AGERE,
  1651. &priv->keys);
  1652. if (err)
  1653. return err;
  1654. err = hermes_write_wordrec(hw, USER_BAP,
  1655. HERMES_RID_CNFTXKEY_AGERE,
  1656. priv->tx_key);
  1657. if (err)
  1658. return err;
  1659. break;
  1660. case FIRMWARE_TYPE_INTERSIL:
  1661. case FIRMWARE_TYPE_SYMBOL:
  1662. {
  1663. int keylen;
  1664. int i;
  1665. /* Force uniform key length to work around firmware bugs */
  1666. keylen = le16_to_cpu(priv->keys[priv->tx_key].len);
  1667. if (keylen > LARGE_KEY_SIZE) {
  1668. printk(KERN_ERR "%s: BUG: Key %d has oversize length %d.\n",
  1669. priv->ndev->name, priv->tx_key, keylen);
  1670. return -E2BIG;
  1671. }
  1672. /* Write all 4 keys */
  1673. for(i = 0; i < ORINOCO_MAX_KEYS; i++) {
  1674. err = hermes_write_ltv(hw, USER_BAP,
  1675. HERMES_RID_CNFDEFAULTKEY0 + i,
  1676. HERMES_BYTES_TO_RECLEN(keylen),
  1677. priv->keys[i].data);
  1678. if (err)
  1679. return err;
  1680. }
  1681. /* Write the index of the key used in transmission */
  1682. err = hermes_write_wordrec(hw, USER_BAP,
  1683. HERMES_RID_CNFWEPDEFAULTKEYID,
  1684. priv->tx_key);
  1685. if (err)
  1686. return err;
  1687. }
  1688. break;
  1689. }
  1690. return 0;
  1691. }
  1692. static int __orinoco_hw_setup_wep(struct orinoco_private *priv)
  1693. {
  1694. hermes_t *hw = &priv->hw;
  1695. int err = 0;
  1696. int master_wep_flag;
  1697. int auth_flag;
  1698. if (priv->wep_on)
  1699. __orinoco_hw_setup_wepkeys(priv);
  1700. if (priv->wep_restrict)
  1701. auth_flag = HERMES_AUTH_SHARED_KEY;
  1702. else
  1703. auth_flag = HERMES_AUTH_OPEN;
  1704. switch (priv->firmware_type) {
  1705. case FIRMWARE_TYPE_AGERE: /* Agere style WEP */
  1706. if (priv->wep_on) {
  1707. /* Enable the shared-key authentication. */
  1708. err = hermes_write_wordrec(hw, USER_BAP,
  1709. HERMES_RID_CNFAUTHENTICATION_AGERE,
  1710. auth_flag);
  1711. }
  1712. err = hermes_write_wordrec(hw, USER_BAP,
  1713. HERMES_RID_CNFWEPENABLED_AGERE,
  1714. priv->wep_on);
  1715. if (err)
  1716. return err;
  1717. break;
  1718. case FIRMWARE_TYPE_INTERSIL: /* Intersil style WEP */
  1719. case FIRMWARE_TYPE_SYMBOL: /* Symbol style WEP */
  1720. if (priv->wep_on) {
  1721. if (priv->wep_restrict ||
  1722. (priv->firmware_type == FIRMWARE_TYPE_SYMBOL))
  1723. master_wep_flag = HERMES_WEP_PRIVACY_INVOKED |
  1724. HERMES_WEP_EXCL_UNENCRYPTED;
  1725. else
  1726. master_wep_flag = HERMES_WEP_PRIVACY_INVOKED;
  1727. err = hermes_write_wordrec(hw, USER_BAP,
  1728. HERMES_RID_CNFAUTHENTICATION,
  1729. auth_flag);
  1730. if (err)
  1731. return err;
  1732. } else
  1733. master_wep_flag = 0;
  1734. if (priv->iw_mode == IW_MODE_MONITOR)
  1735. master_wep_flag |= HERMES_WEP_HOST_DECRYPT;
  1736. /* Master WEP setting : on/off */
  1737. err = hermes_write_wordrec(hw, USER_BAP,
  1738. HERMES_RID_CNFWEPFLAGS_INTERSIL,
  1739. master_wep_flag);
  1740. if (err)
  1741. return err;
  1742. break;
  1743. }
  1744. return 0;
  1745. }
  1746. static int __orinoco_program_rids(struct net_device *dev)
  1747. {
  1748. struct orinoco_private *priv = netdev_priv(dev);
  1749. hermes_t *hw = &priv->hw;
  1750. int err;
  1751. struct hermes_idstring idbuf;
  1752. /* Set the MAC address */
  1753. err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNMACADDR,
  1754. HERMES_BYTES_TO_RECLEN(ETH_ALEN), dev->dev_addr);
  1755. if (err) {
  1756. printk(KERN_ERR "%s: Error %d setting MAC address\n",
  1757. dev->name, err);
  1758. return err;
  1759. }
  1760. /* Set up the link mode */
  1761. err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFPORTTYPE,
  1762. priv->port_type);
  1763. if (err) {
  1764. printk(KERN_ERR "%s: Error %d setting port type\n",
  1765. dev->name, err);
  1766. return err;
  1767. }
  1768. /* Set the channel/frequency */
  1769. if (priv->channel != 0 && priv->iw_mode != IW_MODE_INFRA) {
  1770. err = hermes_write_wordrec(hw, USER_BAP,
  1771. HERMES_RID_CNFOWNCHANNEL,
  1772. priv->channel);
  1773. if (err) {
  1774. printk(KERN_ERR "%s: Error %d setting channel %d\n",
  1775. dev->name, err, priv->channel);
  1776. return err;
  1777. }
  1778. }
  1779. if (priv->has_ibss) {
  1780. u16 createibss;
  1781. if ((strlen(priv->desired_essid) == 0) && (priv->createibss)) {
  1782. printk(KERN_WARNING "%s: This firmware requires an "
  1783. "ESSID in IBSS-Ad-Hoc mode.\n", dev->name);
  1784. /* With wvlan_cs, in this case, we would crash.
  1785. * hopefully, this driver will behave better...
  1786. * Jean II */
  1787. createibss = 0;
  1788. } else {
  1789. createibss = priv->createibss;
  1790. }
  1791. err = hermes_write_wordrec(hw, USER_BAP,
  1792. HERMES_RID_CNFCREATEIBSS,
  1793. createibss);
  1794. if (err) {
  1795. printk(KERN_ERR "%s: Error %d setting CREATEIBSS\n",
  1796. dev->name, err);
  1797. return err;
  1798. }
  1799. }
  1800. /* Set the desired BSSID */
  1801. err = __orinoco_hw_set_wap(priv);
  1802. if (err) {
  1803. printk(KERN_ERR "%s: Error %d setting AP address\n",
  1804. dev->name, err);
  1805. return err;
  1806. }
  1807. /* Set the desired ESSID */
  1808. idbuf.len = cpu_to_le16(strlen(priv->desired_essid));
  1809. memcpy(&idbuf.val, priv->desired_essid, sizeof(idbuf.val));
  1810. /* WinXP wants partner to configure OWNSSID even in IBSS mode. (jimc) */
  1811. err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNSSID,
  1812. HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid)+2),
  1813. &idbuf);
  1814. if (err) {
  1815. printk(KERN_ERR "%s: Error %d setting OWNSSID\n",
  1816. dev->name, err);
  1817. return err;
  1818. }
  1819. err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFDESIREDSSID,
  1820. HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid)+2),
  1821. &idbuf);
  1822. if (err) {
  1823. printk(KERN_ERR "%s: Error %d setting DESIREDSSID\n",
  1824. dev->name, err);
  1825. return err;
  1826. }
  1827. /* Set the station name */
  1828. idbuf.len = cpu_to_le16(strlen(priv->nick));
  1829. memcpy(&idbuf.val, priv->nick, sizeof(idbuf.val));
  1830. err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNNAME,
  1831. HERMES_BYTES_TO_RECLEN(strlen(priv->nick)+2),
  1832. &idbuf);
  1833. if (err) {
  1834. printk(KERN_ERR "%s: Error %d setting nickname\n",
  1835. dev->name, err);
  1836. return err;
  1837. }
  1838. /* Set AP density */
  1839. if (priv->has_sensitivity) {
  1840. err = hermes_write_wordrec(hw, USER_BAP,
  1841. HERMES_RID_CNFSYSTEMSCALE,
  1842. priv->ap_density);
  1843. if (err) {
  1844. printk(KERN_WARNING "%s: Error %d setting SYSTEMSCALE. "
  1845. "Disabling sensitivity control\n",
  1846. dev->name, err);
  1847. priv->has_sensitivity = 0;
  1848. }
  1849. }
  1850. /* Set RTS threshold */
  1851. err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFRTSTHRESHOLD,
  1852. priv->rts_thresh);
  1853. if (err) {
  1854. printk(KERN_ERR "%s: Error %d setting RTS threshold\n",
  1855. dev->name, err);
  1856. return err;
  1857. }
  1858. /* Set fragmentation threshold or MWO robustness */
  1859. if (priv->has_mwo)
  1860. err = hermes_write_wordrec(hw, USER_BAP,
  1861. HERMES_RID_CNFMWOROBUST_AGERE,
  1862. priv->mwo_robust);
  1863. else
  1864. err = hermes_write_wordrec(hw, USER_BAP,
  1865. HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
  1866. priv->frag_thresh);
  1867. if (err) {
  1868. printk(KERN_ERR "%s: Error %d setting fragmentation\n",
  1869. dev->name, err);
  1870. return err;
  1871. }
  1872. /* Set bitrate */
  1873. err = __orinoco_hw_set_bitrate(priv);
  1874. if (err) {
  1875. printk(KERN_ERR "%s: Error %d setting bitrate\n",
  1876. dev->name, err);
  1877. return err;
  1878. }
  1879. /* Set power management */
  1880. if (priv->has_pm) {
  1881. err = hermes_write_wordrec(hw, USER_BAP,
  1882. HERMES_RID_CNFPMENABLED,
  1883. priv->pm_on);
  1884. if (err) {
  1885. printk(KERN_ERR "%s: Error %d setting up PM\n",
  1886. dev->name, err);
  1887. return err;
  1888. }
  1889. err = hermes_write_wordrec(hw, USER_BAP,
  1890. HERMES_RID_CNFMULTICASTRECEIVE,
  1891. priv->pm_mcast);
  1892. if (err) {
  1893. printk(KERN_ERR "%s: Error %d setting up PM\n",
  1894. dev->name, err);
  1895. return err;
  1896. }
  1897. err = hermes_write_wordrec(hw, USER_BAP,
  1898. HERMES_RID_CNFMAXSLEEPDURATION,
  1899. priv->pm_period);
  1900. if (err) {
  1901. printk(KERN_ERR "%s: Error %d setting up PM\n",
  1902. dev->name, err);
  1903. return err;
  1904. }
  1905. err = hermes_write_wordrec(hw, USER_BAP,
  1906. HERMES_RID_CNFPMHOLDOVERDURATION,
  1907. priv->pm_timeout);
  1908. if (err) {
  1909. printk(KERN_ERR "%s: Error %d setting up PM\n",
  1910. dev->name, err);
  1911. return err;
  1912. }
  1913. }
  1914. /* Set preamble - only for Symbol so far... */
  1915. if (priv->has_preamble) {
  1916. err = hermes_write_wordrec(hw, USER_BAP,
  1917. HERMES_RID_CNFPREAMBLE_SYMBOL,
  1918. priv->preamble);
  1919. if (err) {
  1920. printk(KERN_ERR "%s: Error %d setting preamble\n",
  1921. dev->name, err);
  1922. return err;
  1923. }
  1924. }
  1925. /* Set up encryption */
  1926. if (priv->has_wep) {
  1927. err = __orinoco_hw_setup_wep(priv);
  1928. if (err) {
  1929. printk(KERN_ERR "%s: Error %d activating WEP\n",
  1930. dev->name, err);
  1931. return err;
  1932. }
  1933. }
  1934. if (priv->iw_mode == IW_MODE_MONITOR) {
  1935. /* Enable monitor mode */
  1936. dev->type = ARPHRD_IEEE80211;
  1937. err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
  1938. HERMES_TEST_MONITOR, 0, NULL);
  1939. } else {
  1940. /* Disable monitor mode */
  1941. dev->type = ARPHRD_ETHER;
  1942. err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
  1943. HERMES_TEST_STOP, 0, NULL);
  1944. }
  1945. if (err)
  1946. return err;
  1947. /* Set promiscuity / multicast*/
  1948. priv->promiscuous = 0;
  1949. priv->mc_count = 0;
  1950. __orinoco_set_multicast_list(dev); /* FIXME: what about the xmit_lock */
  1951. return 0;
  1952. }
  1953. /* FIXME: return int? */
  1954. static void
  1955. __orinoco_set_multicast_list(struct net_device *dev)
  1956. {
  1957. struct orinoco_private *priv = netdev_priv(dev);
  1958. hermes_t *hw = &priv->hw;
  1959. int err = 0;
  1960. int promisc, mc_count;
  1961. /* The Hermes doesn't seem to have an allmulti mode, so we go
  1962. * into promiscuous mode and let the upper levels deal. */
  1963. if ( (dev->flags & IFF_PROMISC) || (dev->flags & IFF_ALLMULTI) ||
  1964. (dev->mc_count > MAX_MULTICAST(priv)) ) {
  1965. promisc = 1;
  1966. mc_count = 0;
  1967. } else {
  1968. promisc = 0;
  1969. mc_count = dev->mc_count;
  1970. }
  1971. if (promisc != priv->promiscuous) {
  1972. err = hermes_write_wordrec(hw, USER_BAP,
  1973. HERMES_RID_CNFPROMISCUOUSMODE,
  1974. promisc);
  1975. if (err) {
  1976. printk(KERN_ERR "%s: Error %d setting PROMISCUOUSMODE to 1.\n",
  1977. dev->name, err);
  1978. } else
  1979. priv->promiscuous = promisc;
  1980. }
  1981. if (! promisc && (mc_count || priv->mc_count) ) {
  1982. struct dev_mc_list *p = dev->mc_list;
  1983. struct hermes_multicast mclist;
  1984. int i;
  1985. for (i = 0; i < mc_count; i++) {
  1986. /* paranoia: is list shorter than mc_count? */
  1987. BUG_ON(! p);
  1988. /* paranoia: bad address size in list? */
  1989. BUG_ON(p->dmi_addrlen != ETH_ALEN);
  1990. memcpy(mclist.addr[i], p->dmi_addr, ETH_ALEN);
  1991. p = p->next;
  1992. }
  1993. if (p)
  1994. printk(KERN_WARNING "%s: Multicast list is "
  1995. "longer than mc_count\n", dev->name);
  1996. err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFGROUPADDRESSES,
  1997. HERMES_BYTES_TO_RECLEN(priv->mc_count * ETH_ALEN),
  1998. &mclist);
  1999. if (err)
  2000. printk(KERN_ERR "%s: Error %d setting multicast list.\n",
  2001. dev->name, err);
  2002. else
  2003. priv->mc_count = mc_count;
  2004. }
  2005. /* Since we can set the promiscuous flag when it wasn't asked
  2006. for, make sure the net_device knows about it. */
  2007. if (priv->promiscuous)
  2008. dev->flags |= IFF_PROMISC;
  2009. else
  2010. dev->flags &= ~IFF_PROMISC;
  2011. }
  2012. /* This must be called from user context, without locks held - use
  2013. * schedule_work() */
  2014. static void orinoco_reset(struct net_device *dev)
  2015. {
  2016. struct orinoco_private *priv = netdev_priv(dev);
  2017. struct hermes *hw = &priv->hw;
  2018. int err;
  2019. unsigned long flags;
  2020. if (orinoco_lock(priv, &flags) != 0)
  2021. /* When the hardware becomes available again, whatever
  2022. * detects that is responsible for re-initializing
  2023. * it. So no need for anything further */
  2024. return;
  2025. netif_stop_queue(dev);
  2026. /* Shut off interrupts. Depending on what state the hardware
  2027. * is in, this might not work, but we'll try anyway */
  2028. hermes_set_irqmask(hw, 0);
  2029. hermes_write_regn(hw, EVACK, 0xffff);
  2030. priv->hw_unavailable++;
  2031. priv->last_linkstatus = 0xffff; /* firmware will have to reassociate */
  2032. netif_carrier_off(dev);
  2033. orinoco_unlock(priv, &flags);
  2034. /* Scanning support: Cleanup of driver struct */
  2035. kfree(priv->scan_result);
  2036. priv->scan_result = NULL;
  2037. priv->scan_inprogress = 0;
  2038. if (priv->hard_reset) {
  2039. err = (*priv->hard_reset)(priv);
  2040. if (err) {
  2041. printk(KERN_ERR "%s: orinoco_reset: Error %d "
  2042. "performing hard reset\n", dev->name, err);
  2043. goto disable;
  2044. }
  2045. }
  2046. err = orinoco_reinit_firmware(dev);
  2047. if (err) {
  2048. printk(KERN_ERR "%s: orinoco_reset: Error %d re-initializing firmware\n",
  2049. dev->name, err);
  2050. goto disable;
  2051. }
  2052. spin_lock_irq(&priv->lock); /* This has to be called from user context */
  2053. priv->hw_unavailable--;
  2054. /* priv->open or priv->hw_unavailable might have changed while
  2055. * we dropped the lock */
  2056. if (priv->open && (! priv->hw_unavailable)) {
  2057. err = __orinoco_up(dev);
  2058. if (err) {
  2059. printk(KERN_ERR "%s: orinoco_reset: Error %d reenabling card\n",
  2060. dev->name, err);
  2061. } else
  2062. dev->trans_start = jiffies;
  2063. }
  2064. spin_unlock_irq(&priv->lock);
  2065. return;
  2066. disable:
  2067. hermes_set_irqmask(hw, 0);
  2068. netif_device_detach(dev);
  2069. printk(KERN_ERR "%s: Device has been disabled!\n", dev->name);
  2070. }
  2071. /********************************************************************/
  2072. /* Interrupt handler */
  2073. /********************************************************************/
  2074. static void __orinoco_ev_tick(struct net_device *dev, hermes_t *hw)
  2075. {
  2076. printk(KERN_DEBUG "%s: TICK\n", dev->name);
  2077. }
  2078. static void __orinoco_ev_wterr(struct net_device *dev, hermes_t *hw)
  2079. {
  2080. /* This seems to happen a fair bit under load, but ignoring it
  2081. seems to work fine...*/
  2082. printk(KERN_DEBUG "%s: MAC controller error (WTERR). Ignoring.\n",
  2083. dev->name);
  2084. }
  2085. irqreturn_t orinoco_interrupt(int irq, void *dev_id, struct pt_regs *regs)
  2086. {
  2087. struct net_device *dev = (struct net_device *)dev_id;
  2088. struct orinoco_private *priv = netdev_priv(dev);
  2089. hermes_t *hw = &priv->hw;
  2090. int count = MAX_IRQLOOPS_PER_IRQ;
  2091. u16 evstat, events;
  2092. /* These are used to detect a runaway interrupt situation */
  2093. /* If we get more than MAX_IRQLOOPS_PER_JIFFY iterations in a jiffy,
  2094. * we panic and shut down the hardware */
  2095. static int last_irq_jiffy = 0; /* jiffies value the last time
  2096. * we were called */
  2097. static int loops_this_jiffy = 0;
  2098. unsigned long flags;
  2099. if (orinoco_lock(priv, &flags) != 0) {
  2100. /* If hw is unavailable - we don't know if the irq was
  2101. * for us or not */
  2102. return IRQ_HANDLED;
  2103. }
  2104. evstat = hermes_read_regn(hw, EVSTAT);
  2105. events = evstat & hw->inten;
  2106. if (! events) {
  2107. orinoco_unlock(priv, &flags);
  2108. return IRQ_NONE;
  2109. }
  2110. if (jiffies != last_irq_jiffy)
  2111. loops_this_jiffy = 0;
  2112. last_irq_jiffy = jiffies;
  2113. while (events && count--) {
  2114. if (++loops_this_jiffy > MAX_IRQLOOPS_PER_JIFFY) {
  2115. printk(KERN_WARNING "%s: IRQ handler is looping too "
  2116. "much! Resetting.\n", dev->name);
  2117. /* Disable interrupts for now */
  2118. hermes_set_irqmask(hw, 0);
  2119. schedule_work(&priv->reset_work);
  2120. break;
  2121. }
  2122. /* Check the card hasn't been removed */
  2123. if (! hermes_present(hw)) {
  2124. DEBUG(0, "orinoco_interrupt(): card removed\n");
  2125. break;
  2126. }
  2127. if (events & HERMES_EV_TICK)
  2128. __orinoco_ev_tick(dev, hw);
  2129. if (events & HERMES_EV_WTERR)
  2130. __orinoco_ev_wterr(dev, hw);
  2131. if (events & HERMES_EV_INFDROP)
  2132. __orinoco_ev_infdrop(dev, hw);
  2133. if (events & HERMES_EV_INFO)
  2134. __orinoco_ev_info(dev, hw);
  2135. if (events & HERMES_EV_RX)
  2136. __orinoco_ev_rx(dev, hw);
  2137. if (events & HERMES_EV_TXEXC)
  2138. __orinoco_ev_txexc(dev, hw);
  2139. if (events & HERMES_EV_TX)
  2140. __orinoco_ev_tx(dev, hw);
  2141. if (events & HERMES_EV_ALLOC)
  2142. __orinoco_ev_alloc(dev, hw);
  2143. hermes_write_regn(hw, EVACK, evstat);
  2144. evstat = hermes_read_regn(hw, EVSTAT);
  2145. events = evstat & hw->inten;
  2146. };
  2147. orinoco_unlock(priv, &flags);
  2148. return IRQ_HANDLED;
  2149. }
  2150. /********************************************************************/
  2151. /* Initialization */
  2152. /********************************************************************/
  2153. struct comp_id {
  2154. u16 id, variant, major, minor;
  2155. } __attribute__ ((packed));
  2156. static inline fwtype_t determine_firmware_type(struct comp_id *nic_id)
  2157. {
  2158. if (nic_id->id < 0x8000)
  2159. return FIRMWARE_TYPE_AGERE;
  2160. else if (nic_id->id == 0x8000 && nic_id->major == 0)
  2161. return FIRMWARE_TYPE_SYMBOL;
  2162. else
  2163. return FIRMWARE_TYPE_INTERSIL;
  2164. }
  2165. /* Set priv->firmware type, determine firmware properties */
  2166. static int determine_firmware(struct net_device *dev)
  2167. {
  2168. struct orinoco_private *priv = netdev_priv(dev);
  2169. hermes_t *hw = &priv->hw;
  2170. int err;
  2171. struct comp_id nic_id, sta_id;
  2172. unsigned int firmver;
  2173. char tmp[SYMBOL_MAX_VER_LEN+1];
  2174. /* Get the hardware version */
  2175. err = HERMES_READ_RECORD(hw, USER_BAP, HERMES_RID_NICID, &nic_id);
  2176. if (err) {
  2177. printk(KERN_ERR "%s: Cannot read hardware identity: error %d\n",
  2178. dev->name, err);
  2179. return err;
  2180. }
  2181. le16_to_cpus(&nic_id.id);
  2182. le16_to_cpus(&nic_id.variant);
  2183. le16_to_cpus(&nic_id.major);
  2184. le16_to_cpus(&nic_id.minor);
  2185. printk(KERN_DEBUG "%s: Hardware identity %04x:%04x:%04x:%04x\n",
  2186. dev->name, nic_id.id, nic_id.variant,
  2187. nic_id.major, nic_id.minor);
  2188. priv->firmware_type = determine_firmware_type(&nic_id);
  2189. /* Get the firmware version */
  2190. err = HERMES_READ_RECORD(hw, USER_BAP, HERMES_RID_STAID, &sta_id);
  2191. if (err) {
  2192. printk(KERN_ERR "%s: Cannot read station identity: error %d\n",
  2193. dev->name, err);
  2194. return err;
  2195. }
  2196. le16_to_cpus(&sta_id.id);
  2197. le16_to_cpus(&sta_id.variant);
  2198. le16_to_cpus(&sta_id.major);
  2199. le16_to_cpus(&sta_id.minor);
  2200. printk(KERN_DEBUG "%s: Station identity %04x:%04x:%04x:%04x\n",
  2201. dev->name, sta_id.id, sta_id.variant,
  2202. sta_id.major, sta_id.minor);
  2203. switch (sta_id.id) {
  2204. case 0x15:
  2205. printk(KERN_ERR "%s: Primary firmware is active\n",
  2206. dev->name);
  2207. return -ENODEV;
  2208. case 0x14b:
  2209. printk(KERN_ERR "%s: Tertiary firmware is active\n",
  2210. dev->name);
  2211. return -ENODEV;
  2212. case 0x1f: /* Intersil, Agere, Symbol Spectrum24 */
  2213. case 0x21: /* Symbol Spectrum24 Trilogy */
  2214. break;
  2215. default:
  2216. printk(KERN_NOTICE "%s: Unknown station ID, please report\n",
  2217. dev->name);
  2218. break;
  2219. }
  2220. /* Default capabilities */
  2221. priv->has_sensitivity = 1;
  2222. priv->has_mwo = 0;
  2223. priv->has_preamble = 0;
  2224. priv->has_port3 = 1;
  2225. priv->has_ibss = 1;
  2226. priv->has_wep = 0;
  2227. priv->has_big_wep = 0;
  2228. /* Determine capabilities from the firmware version */
  2229. switch (priv->firmware_type) {
  2230. case FIRMWARE_TYPE_AGERE:
  2231. /* Lucent Wavelan IEEE, Lucent Orinoco, Cabletron RoamAbout,
  2232. ELSA, Melco, HP, IBM, Dell 1150, Compaq 110/210 */
  2233. snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
  2234. "Lucent/Agere %d.%02d", sta_id.major, sta_id.minor);
  2235. firmver = ((unsigned long)sta_id.major << 16) | sta_id.minor;
  2236. priv->has_ibss = (firmver >= 0x60006);
  2237. priv->has_wep = (firmver >= 0x40020);
  2238. priv->has_big_wep = 1; /* FIXME: this is wrong - how do we tell
  2239. Gold cards from the others? */
  2240. priv->has_mwo = (firmver >= 0x60000);
  2241. priv->has_pm = (firmver >= 0x40020); /* Don't work in 7.52 ? */
  2242. priv->ibss_port = 1;
  2243. priv->has_hostscan = (firmver >= 0x8000a);
  2244. priv->broken_monitor = (firmver >= 0x80000);
  2245. /* Tested with Agere firmware :
  2246. * 1.16 ; 4.08 ; 4.52 ; 6.04 ; 6.16 ; 7.28 => Jean II
  2247. * Tested CableTron firmware : 4.32 => Anton */
  2248. break;
  2249. case FIRMWARE_TYPE_SYMBOL:
  2250. /* Symbol , 3Com AirConnect, Intel, Ericsson WLAN */
  2251. /* Intel MAC : 00:02:B3:* */
  2252. /* 3Com MAC : 00:50:DA:* */
  2253. memset(tmp, 0, sizeof(tmp));
  2254. /* Get the Symbol firmware version */
  2255. err = hermes_read_ltv(hw, USER_BAP,
  2256. HERMES_RID_SECONDARYVERSION_SYMBOL,
  2257. SYMBOL_MAX_VER_LEN, NULL, &tmp);
  2258. if (err) {
  2259. printk(KERN_WARNING
  2260. "%s: Error %d reading Symbol firmware info. Wildly guessing capabilities...\n",
  2261. dev->name, err);
  2262. firmver = 0;
  2263. tmp[0] = '\0';
  2264. } else {
  2265. /* The firmware revision is a string, the format is
  2266. * something like : "V2.20-01".
  2267. * Quick and dirty parsing... - Jean II
  2268. */
  2269. firmver = ((tmp[1] - '0') << 16) | ((tmp[3] - '0') << 12)
  2270. | ((tmp[4] - '0') << 8) | ((tmp[6] - '0') << 4)
  2271. | (tmp[7] - '0');
  2272. tmp[SYMBOL_MAX_VER_LEN] = '\0';
  2273. }
  2274. snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
  2275. "Symbol %s", tmp);
  2276. priv->has_ibss = (firmver >= 0x20000);
  2277. priv->has_wep = (firmver >= 0x15012);
  2278. priv->has_big_wep = (firmver >= 0x20000);
  2279. priv->has_pm = (firmver >= 0x20000 && firmver < 0x22000) ||
  2280. (firmver >= 0x29000 && firmver < 0x30000) ||
  2281. firmver >= 0x31000;
  2282. priv->has_preamble = (firmver >= 0x20000);
  2283. priv->ibss_port = 4;
  2284. priv->broken_disableport = (firmver == 0x25013) ||
  2285. (firmver >= 0x30000 && firmver <= 0x31000);
  2286. priv->has_hostscan = (firmver >= 0x31001) ||
  2287. (firmver >= 0x29057 && firmver < 0x30000);
  2288. /* Tested with Intel firmware : 0x20015 => Jean II */
  2289. /* Tested with 3Com firmware : 0x15012 & 0x22001 => Jean II */
  2290. break;
  2291. case FIRMWARE_TYPE_INTERSIL:
  2292. /* D-Link, Linksys, Adtron, ZoomAir, and many others...
  2293. * Samsung, Compaq 100/200 and Proxim are slightly
  2294. * different and less well tested */
  2295. /* D-Link MAC : 00:40:05:* */
  2296. /* Addtron MAC : 00:90:D1:* */
  2297. snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
  2298. "Intersil %d.%d.%d", sta_id.major, sta_id.minor,
  2299. sta_id.variant);
  2300. firmver = ((unsigned long)sta_id.major << 16) |
  2301. ((unsigned long)sta_id.minor << 8) | sta_id.variant;
  2302. priv->has_ibss = (firmver >= 0x000700); /* FIXME */
  2303. priv->has_big_wep = priv->has_wep = (firmver >= 0x000800);
  2304. priv->has_pm = (firmver >= 0x000700);
  2305. priv->has_hostscan = (firmver >= 0x010301);
  2306. if (firmver >= 0x000800)
  2307. priv->ibss_port = 0;
  2308. else {
  2309. printk(KERN_NOTICE "%s: Intersil firmware earlier "
  2310. "than v0.8.x - several features not supported\n",
  2311. dev->name);
  2312. priv->ibss_port = 1;
  2313. }
  2314. break;
  2315. }
  2316. printk(KERN_DEBUG "%s: Firmware determined as %s\n", dev->name,
  2317. priv->fw_name);
  2318. return 0;
  2319. }
  2320. static int orinoco_init(struct net_device *dev)
  2321. {
  2322. struct orinoco_private *priv = netdev_priv(dev);
  2323. hermes_t *hw = &priv->hw;
  2324. int err = 0;
  2325. struct hermes_idstring nickbuf;
  2326. u16 reclen;
  2327. int len;
  2328. TRACE_ENTER(dev->name);
  2329. /* No need to lock, the hw_unavailable flag is already set in
  2330. * alloc_orinocodev() */
  2331. priv->nicbuf_size = IEEE802_11_FRAME_LEN + ETH_HLEN;
  2332. /* Initialize the firmware */
  2333. err = orinoco_reinit_firmware(dev);
  2334. if (err != 0) {
  2335. printk(KERN_ERR "%s: failed to initialize firmware (err = %d)\n",
  2336. dev->name, err);
  2337. goto out;
  2338. }
  2339. err = determine_firmware(dev);
  2340. if (err != 0) {
  2341. printk(KERN_ERR "%s: Incompatible firmware, aborting\n",
  2342. dev->name);
  2343. goto out;
  2344. }
  2345. if (priv->has_port3)
  2346. printk(KERN_DEBUG "%s: Ad-hoc demo mode supported\n", dev->name);
  2347. if (priv->has_ibss)
  2348. printk(KERN_DEBUG "%s: IEEE standard IBSS ad-hoc mode supported\n",
  2349. dev->name);
  2350. if (priv->has_wep) {
  2351. printk(KERN_DEBUG "%s: WEP supported, ", dev->name);
  2352. if (priv->has_big_wep)
  2353. printk("104-bit key\n");
  2354. else
  2355. printk("40-bit key\n");
  2356. }
  2357. /* Get the MAC address */
  2358. err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CNFOWNMACADDR,
  2359. ETH_ALEN, NULL, dev->dev_addr);
  2360. if (err) {
  2361. printk(KERN_WARNING "%s: failed to read MAC address!\n",
  2362. dev->name);
  2363. goto out;
  2364. }
  2365. printk(KERN_DEBUG "%s: MAC address %02X:%02X:%02X:%02X:%02X:%02X\n",
  2366. dev->name, dev->dev_addr[0], dev->dev_addr[1],
  2367. dev->dev_addr[2], dev->dev_addr[3], dev->dev_addr[4],
  2368. dev->dev_addr[5]);
  2369. /* Get the station name */
  2370. err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CNFOWNNAME,
  2371. sizeof(nickbuf), &reclen, &nickbuf);
  2372. if (err) {
  2373. printk(KERN_ERR "%s: failed to read station name\n",
  2374. dev->name);
  2375. goto out;
  2376. }
  2377. if (nickbuf.len)
  2378. len = min(IW_ESSID_MAX_SIZE, (int)le16_to_cpu(nickbuf.len));
  2379. else
  2380. len = min(IW_ESSID_MAX_SIZE, 2 * reclen);
  2381. memcpy(priv->nick, &nickbuf.val, len);
  2382. priv->nick[len] = '\0';
  2383. printk(KERN_DEBUG "%s: Station name \"%s\"\n", dev->name, priv->nick);
  2384. /* Get allowed channels */
  2385. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CHANNELLIST,
  2386. &priv->channel_mask);
  2387. if (err) {
  2388. printk(KERN_ERR "%s: failed to read channel list!\n",
  2389. dev->name);
  2390. goto out;
  2391. }
  2392. /* Get initial AP density */
  2393. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFSYSTEMSCALE,
  2394. &priv->ap_density);
  2395. if (err || priv->ap_density < 1 || priv->ap_density > 3) {
  2396. priv->has_sensitivity = 0;
  2397. }
  2398. /* Get initial RTS threshold */
  2399. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFRTSTHRESHOLD,
  2400. &priv->rts_thresh);
  2401. if (err) {
  2402. printk(KERN_ERR "%s: failed to read RTS threshold!\n",
  2403. dev->name);
  2404. goto out;
  2405. }
  2406. /* Get initial fragmentation settings */
  2407. if (priv->has_mwo)
  2408. err = hermes_read_wordrec(hw, USER_BAP,
  2409. HERMES_RID_CNFMWOROBUST_AGERE,
  2410. &priv->mwo_robust);
  2411. else
  2412. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
  2413. &priv->frag_thresh);
  2414. if (err) {
  2415. printk(KERN_ERR "%s: failed to read fragmentation settings!\n",
  2416. dev->name);
  2417. goto out;
  2418. }
  2419. /* Power management setup */
  2420. if (priv->has_pm) {
  2421. priv->pm_on = 0;
  2422. priv->pm_mcast = 1;
  2423. err = hermes_read_wordrec(hw, USER_BAP,
  2424. HERMES_RID_CNFMAXSLEEPDURATION,
  2425. &priv->pm_period);
  2426. if (err) {
  2427. printk(KERN_ERR "%s: failed to read power management period!\n",
  2428. dev->name);
  2429. goto out;
  2430. }
  2431. err = hermes_read_wordrec(hw, USER_BAP,
  2432. HERMES_RID_CNFPMHOLDOVERDURATION,
  2433. &priv->pm_timeout);
  2434. if (err) {
  2435. printk(KERN_ERR "%s: failed to read power management timeout!\n",
  2436. dev->name);
  2437. goto out;
  2438. }
  2439. }
  2440. /* Preamble setup */
  2441. if (priv->has_preamble) {
  2442. err = hermes_read_wordrec(hw, USER_BAP,
  2443. HERMES_RID_CNFPREAMBLE_SYMBOL,
  2444. &priv->preamble);
  2445. if (err)
  2446. goto out;
  2447. }
  2448. /* Set up the default configuration */
  2449. priv->iw_mode = IW_MODE_INFRA;
  2450. /* By default use IEEE/IBSS ad-hoc mode if we have it */
  2451. priv->prefer_port3 = priv->has_port3 && (! priv->has_ibss);
  2452. set_port_type(priv);
  2453. priv->channel = 0; /* use firmware default */
  2454. priv->promiscuous = 0;
  2455. priv->wep_on = 0;
  2456. priv->tx_key = 0;
  2457. /* Make the hardware available, as long as it hasn't been
  2458. * removed elsewhere (e.g. by PCMCIA hot unplug) */
  2459. spin_lock_irq(&priv->lock);
  2460. priv->hw_unavailable--;
  2461. spin_unlock_irq(&priv->lock);
  2462. printk(KERN_DEBUG "%s: ready\n", dev->name);
  2463. out:
  2464. TRACE_EXIT(dev->name);
  2465. return err;
  2466. }
  2467. struct net_device *alloc_orinocodev(int sizeof_card,
  2468. int (*hard_reset)(struct orinoco_private *))
  2469. {
  2470. struct net_device *dev;
  2471. struct orinoco_private *priv;
  2472. dev = alloc_etherdev(sizeof(struct orinoco_private) + sizeof_card);
  2473. if (! dev)
  2474. return NULL;
  2475. priv = netdev_priv(dev);
  2476. priv->ndev = dev;
  2477. if (sizeof_card)
  2478. priv->card = (void *)((unsigned long)priv
  2479. + sizeof(struct orinoco_private));
  2480. else
  2481. priv->card = NULL;
  2482. /* Setup / override net_device fields */
  2483. dev->init = orinoco_init;
  2484. dev->hard_start_xmit = orinoco_xmit;
  2485. dev->tx_timeout = orinoco_tx_timeout;
  2486. dev->watchdog_timeo = HZ; /* 1 second timeout */
  2487. dev->get_stats = orinoco_get_stats;
  2488. dev->ethtool_ops = &orinoco_ethtool_ops;
  2489. dev->get_wireless_stats = orinoco_get_wireless_stats;
  2490. dev->wireless_handlers = (struct iw_handler_def *)&orinoco_handler_def;
  2491. dev->change_mtu = orinoco_change_mtu;
  2492. dev->set_multicast_list = orinoco_set_multicast_list;
  2493. /* we use the default eth_mac_addr for setting the MAC addr */
  2494. /* Set up default callbacks */
  2495. dev->open = orinoco_open;
  2496. dev->stop = orinoco_stop;
  2497. priv->hard_reset = hard_reset;
  2498. spin_lock_init(&priv->lock);
  2499. priv->open = 0;
  2500. priv->hw_unavailable = 1; /* orinoco_init() must clear this
  2501. * before anything else touches the
  2502. * hardware */
  2503. INIT_WORK(&priv->reset_work, (void (*)(void *))orinoco_reset, dev);
  2504. INIT_WORK(&priv->join_work, (void (*)(void *))orinoco_join_ap, dev);
  2505. INIT_WORK(&priv->wevent_work, (void (*)(void *))orinoco_send_wevents, dev);
  2506. netif_carrier_off(dev);
  2507. priv->last_linkstatus = 0xffff;
  2508. return dev;
  2509. }
  2510. void free_orinocodev(struct net_device *dev)
  2511. {
  2512. struct orinoco_private *priv = netdev_priv(dev);
  2513. kfree(priv->scan_result);
  2514. free_netdev(dev);
  2515. }
  2516. /********************************************************************/
  2517. /* Wireless extensions */
  2518. /********************************************************************/
  2519. static int orinoco_hw_get_essid(struct orinoco_private *priv, int *active,
  2520. char buf[IW_ESSID_MAX_SIZE+1])
  2521. {
  2522. hermes_t *hw = &priv->hw;
  2523. int err = 0;
  2524. struct hermes_idstring essidbuf;
  2525. char *p = (char *)(&essidbuf.val);
  2526. int len;
  2527. unsigned long flags;
  2528. if (orinoco_lock(priv, &flags) != 0)
  2529. return -EBUSY;
  2530. if (strlen(priv->desired_essid) > 0) {
  2531. /* We read the desired SSID from the hardware rather
  2532. than from priv->desired_essid, just in case the
  2533. firmware is allowed to change it on us. I'm not
  2534. sure about this */
  2535. /* My guess is that the OWNSSID should always be whatever
  2536. * we set to the card, whereas CURRENT_SSID is the one that
  2537. * may change... - Jean II */
  2538. u16 rid;
  2539. *active = 1;
  2540. rid = (priv->port_type == 3) ? HERMES_RID_CNFOWNSSID :
  2541. HERMES_RID_CNFDESIREDSSID;
  2542. err = hermes_read_ltv(hw, USER_BAP, rid, sizeof(essidbuf),
  2543. NULL, &essidbuf);
  2544. if (err)
  2545. goto fail_unlock;
  2546. } else {
  2547. *active = 0;
  2548. err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTSSID,
  2549. sizeof(essidbuf), NULL, &essidbuf);
  2550. if (err)
  2551. goto fail_unlock;
  2552. }
  2553. len = le16_to_cpu(essidbuf.len);
  2554. BUG_ON(len > IW_ESSID_MAX_SIZE);
  2555. memset(buf, 0, IW_ESSID_MAX_SIZE+1);
  2556. memcpy(buf, p, len);
  2557. buf[len] = '\0';
  2558. fail_unlock:
  2559. orinoco_unlock(priv, &flags);
  2560. return err;
  2561. }
  2562. static long orinoco_hw_get_freq(struct orinoco_private *priv)
  2563. {
  2564. hermes_t *hw = &priv->hw;
  2565. int err = 0;
  2566. u16 channel;
  2567. long freq = 0;
  2568. unsigned long flags;
  2569. if (orinoco_lock(priv, &flags) != 0)
  2570. return -EBUSY;
  2571. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CURRENTCHANNEL, &channel);
  2572. if (err)
  2573. goto out;
  2574. /* Intersil firmware 1.3.5 returns 0 when the interface is down */
  2575. if (channel == 0) {
  2576. err = -EBUSY;
  2577. goto out;
  2578. }
  2579. if ( (channel < 1) || (channel > NUM_CHANNELS) ) {
  2580. printk(KERN_WARNING "%s: Channel out of range (%d)!\n",
  2581. priv->ndev->name, channel);
  2582. err = -EBUSY;
  2583. goto out;
  2584. }
  2585. freq = channel_frequency[channel-1] * 100000;
  2586. out:
  2587. orinoco_unlock(priv, &flags);
  2588. if (err > 0)
  2589. err = -EBUSY;
  2590. return err ? err : freq;
  2591. }
  2592. static int orinoco_hw_get_bitratelist(struct orinoco_private *priv,
  2593. int *numrates, s32 *rates, int max)
  2594. {
  2595. hermes_t *hw = &priv->hw;
  2596. struct hermes_idstring list;
  2597. unsigned char *p = (unsigned char *)&list.val;
  2598. int err = 0;
  2599. int num;
  2600. int i;
  2601. unsigned long flags;
  2602. if (orinoco_lock(priv, &flags) != 0)
  2603. return -EBUSY;
  2604. err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_SUPPORTEDDATARATES,
  2605. sizeof(list), NULL, &list);
  2606. orinoco_unlock(priv, &flags);
  2607. if (err)
  2608. return err;
  2609. num = le16_to_cpu(list.len);
  2610. *numrates = num;
  2611. num = min(num, max);
  2612. for (i = 0; i < num; i++) {
  2613. rates[i] = (p[i] & 0x7f) * 500000; /* convert to bps */
  2614. }
  2615. return 0;
  2616. }
  2617. static int orinoco_ioctl_getname(struct net_device *dev,
  2618. struct iw_request_info *info,
  2619. char *name,
  2620. char *extra)
  2621. {
  2622. struct orinoco_private *priv = netdev_priv(dev);
  2623. int numrates;
  2624. int err;
  2625. err = orinoco_hw_get_bitratelist(priv, &numrates, NULL, 0);
  2626. if (!err && (numrates > 2))
  2627. strcpy(name, "IEEE 802.11b");
  2628. else
  2629. strcpy(name, "IEEE 802.11-DS");
  2630. return 0;
  2631. }
  2632. static int orinoco_ioctl_setwap(struct net_device *dev,
  2633. struct iw_request_info *info,
  2634. struct sockaddr *ap_addr,
  2635. char *extra)
  2636. {
  2637. struct orinoco_private *priv = netdev_priv(dev);
  2638. int err = -EINPROGRESS; /* Call commit handler */
  2639. unsigned long flags;
  2640. static const u8 off_addr[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  2641. static const u8 any_addr[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
  2642. if (orinoco_lock(priv, &flags) != 0)
  2643. return -EBUSY;
  2644. /* Enable automatic roaming - no sanity checks are needed */
  2645. if (memcmp(&ap_addr->sa_data, off_addr, ETH_ALEN) == 0 ||
  2646. memcmp(&ap_addr->sa_data, any_addr, ETH_ALEN) == 0) {
  2647. priv->bssid_fixed = 0;
  2648. memset(priv->desired_bssid, 0, ETH_ALEN);
  2649. /* "off" means keep existing connection */
  2650. if (ap_addr->sa_data[0] == 0) {
  2651. __orinoco_hw_set_wap(priv);
  2652. err = 0;
  2653. }
  2654. goto out;
  2655. }
  2656. if (priv->firmware_type == FIRMWARE_TYPE_AGERE) {
  2657. printk(KERN_WARNING "%s: Lucent/Agere firmware doesn't "
  2658. "support manual roaming\n",
  2659. dev->name);
  2660. err = -EOPNOTSUPP;
  2661. goto out;
  2662. }
  2663. if (priv->iw_mode != IW_MODE_INFRA) {
  2664. printk(KERN_WARNING "%s: Manual roaming supported only in "
  2665. "managed mode\n", dev->name);
  2666. err = -EOPNOTSUPP;
  2667. goto out;
  2668. }
  2669. /* Intersil firmware hangs without Desired ESSID */
  2670. if (priv->firmware_type == FIRMWARE_TYPE_INTERSIL &&
  2671. strlen(priv->desired_essid) == 0) {
  2672. printk(KERN_WARNING "%s: Desired ESSID must be set for "
  2673. "manual roaming\n", dev->name);
  2674. err = -EOPNOTSUPP;
  2675. goto out;
  2676. }
  2677. /* Finally, enable manual roaming */
  2678. priv->bssid_fixed = 1;
  2679. memcpy(priv->desired_bssid, &ap_addr->sa_data, ETH_ALEN);
  2680. out:
  2681. orinoco_unlock(priv, &flags);
  2682. return err;
  2683. }
  2684. static int orinoco_ioctl_getwap(struct net_device *dev,
  2685. struct iw_request_info *info,
  2686. struct sockaddr *ap_addr,
  2687. char *extra)
  2688. {
  2689. struct orinoco_private *priv = netdev_priv(dev);
  2690. hermes_t *hw = &priv->hw;
  2691. int err = 0;
  2692. unsigned long flags;
  2693. if (orinoco_lock(priv, &flags) != 0)
  2694. return -EBUSY;
  2695. ap_addr->sa_family = ARPHRD_ETHER;
  2696. err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTBSSID,
  2697. ETH_ALEN, NULL, ap_addr->sa_data);
  2698. orinoco_unlock(priv, &flags);
  2699. return err;
  2700. }
  2701. static int orinoco_ioctl_setmode(struct net_device *dev,
  2702. struct iw_request_info *info,
  2703. u32 *mode,
  2704. char *extra)
  2705. {
  2706. struct orinoco_private *priv = netdev_priv(dev);
  2707. int err = -EINPROGRESS; /* Call commit handler */
  2708. unsigned long flags;
  2709. if (priv->iw_mode == *mode)
  2710. return 0;
  2711. if (orinoco_lock(priv, &flags) != 0)
  2712. return -EBUSY;
  2713. switch (*mode) {
  2714. case IW_MODE_ADHOC:
  2715. if (!priv->has_ibss && !priv->has_port3)
  2716. err = -EOPNOTSUPP;
  2717. break;
  2718. case IW_MODE_INFRA:
  2719. break;
  2720. case IW_MODE_MONITOR:
  2721. if (priv->broken_monitor && !force_monitor) {
  2722. printk(KERN_WARNING "%s: Monitor mode support is "
  2723. "buggy in this firmware, not enabling\n",
  2724. dev->name);
  2725. err = -EOPNOTSUPP;
  2726. }
  2727. break;
  2728. default:
  2729. err = -EOPNOTSUPP;
  2730. break;
  2731. }
  2732. if (err == -EINPROGRESS) {
  2733. priv->iw_mode = *mode;
  2734. set_port_type(priv);
  2735. }
  2736. orinoco_unlock(priv, &flags);
  2737. return err;
  2738. }
  2739. static int orinoco_ioctl_getmode(struct net_device *dev,
  2740. struct iw_request_info *info,
  2741. u32 *mode,
  2742. char *extra)
  2743. {
  2744. struct orinoco_private *priv = netdev_priv(dev);
  2745. *mode = priv->iw_mode;
  2746. return 0;
  2747. }
  2748. static int orinoco_ioctl_getiwrange(struct net_device *dev,
  2749. struct iw_request_info *info,
  2750. struct iw_point *rrq,
  2751. char *extra)
  2752. {
  2753. struct orinoco_private *priv = netdev_priv(dev);
  2754. int err = 0;
  2755. struct iw_range *range = (struct iw_range *) extra;
  2756. int numrates;
  2757. int i, k;
  2758. TRACE_ENTER(dev->name);
  2759. rrq->length = sizeof(struct iw_range);
  2760. memset(range, 0, sizeof(struct iw_range));
  2761. range->we_version_compiled = WIRELESS_EXT;
  2762. range->we_version_source = 14;
  2763. /* Set available channels/frequencies */
  2764. range->num_channels = NUM_CHANNELS;
  2765. k = 0;
  2766. for (i = 0; i < NUM_CHANNELS; i++) {
  2767. if (priv->channel_mask & (1 << i)) {
  2768. range->freq[k].i = i + 1;
  2769. range->freq[k].m = channel_frequency[i] * 100000;
  2770. range->freq[k].e = 1;
  2771. k++;
  2772. }
  2773. if (k >= IW_MAX_FREQUENCIES)
  2774. break;
  2775. }
  2776. range->num_frequency = k;
  2777. range->sensitivity = 3;
  2778. if (priv->has_wep) {
  2779. range->max_encoding_tokens = ORINOCO_MAX_KEYS;
  2780. range->encoding_size[0] = SMALL_KEY_SIZE;
  2781. range->num_encoding_sizes = 1;
  2782. if (priv->has_big_wep) {
  2783. range->encoding_size[1] = LARGE_KEY_SIZE;
  2784. range->num_encoding_sizes = 2;
  2785. }
  2786. }
  2787. if ((priv->iw_mode == IW_MODE_ADHOC) && (priv->spy_number == 0)){
  2788. /* Quality stats meaningless in ad-hoc mode */
  2789. } else {
  2790. range->max_qual.qual = 0x8b - 0x2f;
  2791. range->max_qual.level = 0x2f - 0x95 - 1;
  2792. range->max_qual.noise = 0x2f - 0x95 - 1;
  2793. /* Need to get better values */
  2794. range->avg_qual.qual = 0x24;
  2795. range->avg_qual.level = 0xC2;
  2796. range->avg_qual.noise = 0x9E;
  2797. }
  2798. err = orinoco_hw_get_bitratelist(priv, &numrates,
  2799. range->bitrate, IW_MAX_BITRATES);
  2800. if (err)
  2801. return err;
  2802. range->num_bitrates = numrates;
  2803. /* Set an indication of the max TCP throughput in bit/s that we can
  2804. * expect using this interface. May be use for QoS stuff...
  2805. * Jean II */
  2806. if (numrates > 2)
  2807. range->throughput = 5 * 1000 * 1000; /* ~5 Mb/s */
  2808. else
  2809. range->throughput = 1.5 * 1000 * 1000; /* ~1.5 Mb/s */
  2810. range->min_rts = 0;
  2811. range->max_rts = 2347;
  2812. range->min_frag = 256;
  2813. range->max_frag = 2346;
  2814. range->min_pmp = 0;
  2815. range->max_pmp = 65535000;
  2816. range->min_pmt = 0;
  2817. range->max_pmt = 65535 * 1000; /* ??? */
  2818. range->pmp_flags = IW_POWER_PERIOD;
  2819. range->pmt_flags = IW_POWER_TIMEOUT;
  2820. range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT | IW_POWER_UNICAST_R;
  2821. range->retry_capa = IW_RETRY_LIMIT | IW_RETRY_LIFETIME;
  2822. range->retry_flags = IW_RETRY_LIMIT;
  2823. range->r_time_flags = IW_RETRY_LIFETIME;
  2824. range->min_retry = 0;
  2825. range->max_retry = 65535; /* ??? */
  2826. range->min_r_time = 0;
  2827. range->max_r_time = 65535 * 1000; /* ??? */
  2828. TRACE_EXIT(dev->name);
  2829. return 0;
  2830. }
  2831. static int orinoco_ioctl_setiwencode(struct net_device *dev,
  2832. struct iw_request_info *info,
  2833. struct iw_point *erq,
  2834. char *keybuf)
  2835. {
  2836. struct orinoco_private *priv = netdev_priv(dev);
  2837. int index = (erq->flags & IW_ENCODE_INDEX) - 1;
  2838. int setindex = priv->tx_key;
  2839. int enable = priv->wep_on;
  2840. int restricted = priv->wep_restrict;
  2841. u16 xlen = 0;
  2842. int err = -EINPROGRESS; /* Call commit handler */
  2843. unsigned long flags;
  2844. if (! priv->has_wep)
  2845. return -EOPNOTSUPP;
  2846. if (erq->pointer) {
  2847. /* We actually have a key to set - check its length */
  2848. if (erq->length > LARGE_KEY_SIZE)
  2849. return -E2BIG;
  2850. if ( (erq->length > SMALL_KEY_SIZE) && !priv->has_big_wep )
  2851. return -E2BIG;
  2852. }
  2853. if (orinoco_lock(priv, &flags) != 0)
  2854. return -EBUSY;
  2855. if (erq->pointer) {
  2856. if ((index < 0) || (index >= ORINOCO_MAX_KEYS))
  2857. index = priv->tx_key;
  2858. /* Adjust key length to a supported value */
  2859. if (erq->length > SMALL_KEY_SIZE) {
  2860. xlen = LARGE_KEY_SIZE;
  2861. } else if (erq->length > 0) {
  2862. xlen = SMALL_KEY_SIZE;
  2863. } else
  2864. xlen = 0;
  2865. /* Switch on WEP if off */
  2866. if ((!enable) && (xlen > 0)) {
  2867. setindex = index;
  2868. enable = 1;
  2869. }
  2870. } else {
  2871. /* Important note : if the user do "iwconfig eth0 enc off",
  2872. * we will arrive there with an index of -1. This is valid
  2873. * but need to be taken care off... Jean II */
  2874. if ((index < 0) || (index >= ORINOCO_MAX_KEYS)) {
  2875. if((index != -1) || (erq->flags == 0)) {
  2876. err = -EINVAL;
  2877. goto out;
  2878. }
  2879. } else {
  2880. /* Set the index : Check that the key is valid */
  2881. if(priv->keys[index].len == 0) {
  2882. err = -EINVAL;
  2883. goto out;
  2884. }
  2885. setindex = index;
  2886. }
  2887. }
  2888. if (erq->flags & IW_ENCODE_DISABLED)
  2889. enable = 0;
  2890. if (erq->flags & IW_ENCODE_OPEN)
  2891. restricted = 0;
  2892. if (erq->flags & IW_ENCODE_RESTRICTED)
  2893. restricted = 1;
  2894. if (erq->pointer) {
  2895. priv->keys[index].len = cpu_to_le16(xlen);
  2896. memset(priv->keys[index].data, 0,
  2897. sizeof(priv->keys[index].data));
  2898. memcpy(priv->keys[index].data, keybuf, erq->length);
  2899. }
  2900. priv->tx_key = setindex;
  2901. /* Try fast key change if connected and only keys are changed */
  2902. if (priv->wep_on && enable && (priv->wep_restrict == restricted) &&
  2903. netif_carrier_ok(dev)) {
  2904. err = __orinoco_hw_setup_wepkeys(priv);
  2905. /* No need to commit if successful */
  2906. goto out;
  2907. }
  2908. priv->wep_on = enable;
  2909. priv->wep_restrict = restricted;
  2910. out:
  2911. orinoco_unlock(priv, &flags);
  2912. return err;
  2913. }
  2914. static int orinoco_ioctl_getiwencode(struct net_device *dev,
  2915. struct iw_request_info *info,
  2916. struct iw_point *erq,
  2917. char *keybuf)
  2918. {
  2919. struct orinoco_private *priv = netdev_priv(dev);
  2920. int index = (erq->flags & IW_ENCODE_INDEX) - 1;
  2921. u16 xlen = 0;
  2922. unsigned long flags;
  2923. if (! priv->has_wep)
  2924. return -EOPNOTSUPP;
  2925. if (orinoco_lock(priv, &flags) != 0)
  2926. return -EBUSY;
  2927. if ((index < 0) || (index >= ORINOCO_MAX_KEYS))
  2928. index = priv->tx_key;
  2929. erq->flags = 0;
  2930. if (! priv->wep_on)
  2931. erq->flags |= IW_ENCODE_DISABLED;
  2932. erq->flags |= index + 1;
  2933. if (priv->wep_restrict)
  2934. erq->flags |= IW_ENCODE_RESTRICTED;
  2935. else
  2936. erq->flags |= IW_ENCODE_OPEN;
  2937. xlen = le16_to_cpu(priv->keys[index].len);
  2938. erq->length = xlen;
  2939. memcpy(keybuf, priv->keys[index].data, ORINOCO_MAX_KEY_SIZE);
  2940. orinoco_unlock(priv, &flags);
  2941. return 0;
  2942. }
  2943. static int orinoco_ioctl_setessid(struct net_device *dev,
  2944. struct iw_request_info *info,
  2945. struct iw_point *erq,
  2946. char *essidbuf)
  2947. {
  2948. struct orinoco_private *priv = netdev_priv(dev);
  2949. unsigned long flags;
  2950. /* Note : ESSID is ignored in Ad-Hoc demo mode, but we can set it
  2951. * anyway... - Jean II */
  2952. /* Hum... Should not use Wireless Extension constant (may change),
  2953. * should use our own... - Jean II */
  2954. if (erq->length > IW_ESSID_MAX_SIZE)
  2955. return -E2BIG;
  2956. if (orinoco_lock(priv, &flags) != 0)
  2957. return -EBUSY;
  2958. /* NULL the string (for NULL termination & ESSID = ANY) - Jean II */
  2959. memset(priv->desired_essid, 0, sizeof(priv->desired_essid));
  2960. /* If not ANY, get the new ESSID */
  2961. if (erq->flags) {
  2962. memcpy(priv->desired_essid, essidbuf, erq->length);
  2963. }
  2964. orinoco_unlock(priv, &flags);
  2965. return -EINPROGRESS; /* Call commit handler */
  2966. }
  2967. static int orinoco_ioctl_getessid(struct net_device *dev,
  2968. struct iw_request_info *info,
  2969. struct iw_point *erq,
  2970. char *essidbuf)
  2971. {
  2972. struct orinoco_private *priv = netdev_priv(dev);
  2973. int active;
  2974. int err = 0;
  2975. unsigned long flags;
  2976. TRACE_ENTER(dev->name);
  2977. if (netif_running(dev)) {
  2978. err = orinoco_hw_get_essid(priv, &active, essidbuf);
  2979. if (err)
  2980. return err;
  2981. } else {
  2982. if (orinoco_lock(priv, &flags) != 0)
  2983. return -EBUSY;
  2984. memcpy(essidbuf, priv->desired_essid, IW_ESSID_MAX_SIZE + 1);
  2985. orinoco_unlock(priv, &flags);
  2986. }
  2987. erq->flags = 1;
  2988. erq->length = strlen(essidbuf) + 1;
  2989. TRACE_EXIT(dev->name);
  2990. return 0;
  2991. }
  2992. static int orinoco_ioctl_setnick(struct net_device *dev,
  2993. struct iw_request_info *info,
  2994. struct iw_point *nrq,
  2995. char *nickbuf)
  2996. {
  2997. struct orinoco_private *priv = netdev_priv(dev);
  2998. unsigned long flags;
  2999. if (nrq->length > IW_ESSID_MAX_SIZE)
  3000. return -E2BIG;
  3001. if (orinoco_lock(priv, &flags) != 0)
  3002. return -EBUSY;
  3003. memset(priv->nick, 0, sizeof(priv->nick));
  3004. memcpy(priv->nick, nickbuf, nrq->length);
  3005. orinoco_unlock(priv, &flags);
  3006. return -EINPROGRESS; /* Call commit handler */
  3007. }
  3008. static int orinoco_ioctl_getnick(struct net_device *dev,
  3009. struct iw_request_info *info,
  3010. struct iw_point *nrq,
  3011. char *nickbuf)
  3012. {
  3013. struct orinoco_private *priv = netdev_priv(dev);
  3014. unsigned long flags;
  3015. if (orinoco_lock(priv, &flags) != 0)
  3016. return -EBUSY;
  3017. memcpy(nickbuf, priv->nick, IW_ESSID_MAX_SIZE+1);
  3018. orinoco_unlock(priv, &flags);
  3019. nrq->length = strlen(nickbuf)+1;
  3020. return 0;
  3021. }
  3022. static int orinoco_ioctl_setfreq(struct net_device *dev,
  3023. struct iw_request_info *info,
  3024. struct iw_freq *frq,
  3025. char *extra)
  3026. {
  3027. struct orinoco_private *priv = netdev_priv(dev);
  3028. int chan = -1;
  3029. unsigned long flags;
  3030. int err = -EINPROGRESS; /* Call commit handler */
  3031. /* In infrastructure mode the AP sets the channel */
  3032. if (priv->iw_mode == IW_MODE_INFRA)
  3033. return -EBUSY;
  3034. if ( (frq->e == 0) && (frq->m <= 1000) ) {
  3035. /* Setting by channel number */
  3036. chan = frq->m;
  3037. } else {
  3038. /* Setting by frequency - search the table */
  3039. int mult = 1;
  3040. int i;
  3041. for (i = 0; i < (6 - frq->e); i++)
  3042. mult *= 10;
  3043. for (i = 0; i < NUM_CHANNELS; i++)
  3044. if (frq->m == (channel_frequency[i] * mult))
  3045. chan = i+1;
  3046. }
  3047. if ( (chan < 1) || (chan > NUM_CHANNELS) ||
  3048. ! (priv->channel_mask & (1 << (chan-1)) ) )
  3049. return -EINVAL;
  3050. if (orinoco_lock(priv, &flags) != 0)
  3051. return -EBUSY;
  3052. priv->channel = chan;
  3053. if (priv->iw_mode == IW_MODE_MONITOR) {
  3054. /* Fast channel change - no commit if successful */
  3055. hermes_t *hw = &priv->hw;
  3056. err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
  3057. HERMES_TEST_SET_CHANNEL,
  3058. chan, NULL);
  3059. }
  3060. orinoco_unlock(priv, &flags);
  3061. return err;
  3062. }
  3063. static int orinoco_ioctl_getfreq(struct net_device *dev,
  3064. struct iw_request_info *info,
  3065. struct iw_freq *frq,
  3066. char *extra)
  3067. {
  3068. struct orinoco_private *priv = netdev_priv(dev);
  3069. int tmp;
  3070. /* Locking done in there */
  3071. tmp = orinoco_hw_get_freq(priv);
  3072. if (tmp < 0) {
  3073. return tmp;
  3074. }
  3075. frq->m = tmp;
  3076. frq->e = 1;
  3077. return 0;
  3078. }
  3079. static int orinoco_ioctl_getsens(struct net_device *dev,
  3080. struct iw_request_info *info,
  3081. struct iw_param *srq,
  3082. char *extra)
  3083. {
  3084. struct orinoco_private *priv = netdev_priv(dev);
  3085. hermes_t *hw = &priv->hw;
  3086. u16 val;
  3087. int err;
  3088. unsigned long flags;
  3089. if (!priv->has_sensitivity)
  3090. return -EOPNOTSUPP;
  3091. if (orinoco_lock(priv, &flags) != 0)
  3092. return -EBUSY;
  3093. err = hermes_read_wordrec(hw, USER_BAP,
  3094. HERMES_RID_CNFSYSTEMSCALE, &val);
  3095. orinoco_unlock(priv, &flags);
  3096. if (err)
  3097. return err;
  3098. srq->value = val;
  3099. srq->fixed = 0; /* auto */
  3100. return 0;
  3101. }
  3102. static int orinoco_ioctl_setsens(struct net_device *dev,
  3103. struct iw_request_info *info,
  3104. struct iw_param *srq,
  3105. char *extra)
  3106. {
  3107. struct orinoco_private *priv = netdev_priv(dev);
  3108. int val = srq->value;
  3109. unsigned long flags;
  3110. if (!priv->has_sensitivity)
  3111. return -EOPNOTSUPP;
  3112. if ((val < 1) || (val > 3))
  3113. return -EINVAL;
  3114. if (orinoco_lock(priv, &flags) != 0)
  3115. return -EBUSY;
  3116. priv->ap_density = val;
  3117. orinoco_unlock(priv, &flags);
  3118. return -EINPROGRESS; /* Call commit handler */
  3119. }
  3120. static int orinoco_ioctl_setrts(struct net_device *dev,
  3121. struct iw_request_info *info,
  3122. struct iw_param *rrq,
  3123. char *extra)
  3124. {
  3125. struct orinoco_private *priv = netdev_priv(dev);
  3126. int val = rrq->value;
  3127. unsigned long flags;
  3128. if (rrq->disabled)
  3129. val = 2347;
  3130. if ( (val < 0) || (val > 2347) )
  3131. return -EINVAL;
  3132. if (orinoco_lock(priv, &flags) != 0)
  3133. return -EBUSY;
  3134. priv->rts_thresh = val;
  3135. orinoco_unlock(priv, &flags);
  3136. return -EINPROGRESS; /* Call commit handler */
  3137. }
  3138. static int orinoco_ioctl_getrts(struct net_device *dev,
  3139. struct iw_request_info *info,
  3140. struct iw_param *rrq,
  3141. char *extra)
  3142. {
  3143. struct orinoco_private *priv = netdev_priv(dev);
  3144. rrq->value = priv->rts_thresh;
  3145. rrq->disabled = (rrq->value == 2347);
  3146. rrq->fixed = 1;
  3147. return 0;
  3148. }
  3149. static int orinoco_ioctl_setfrag(struct net_device *dev,
  3150. struct iw_request_info *info,
  3151. struct iw_param *frq,
  3152. char *extra)
  3153. {
  3154. struct orinoco_private *priv = netdev_priv(dev);
  3155. int err = -EINPROGRESS; /* Call commit handler */
  3156. unsigned long flags;
  3157. if (orinoco_lock(priv, &flags) != 0)
  3158. return -EBUSY;
  3159. if (priv->has_mwo) {
  3160. if (frq->disabled)
  3161. priv->mwo_robust = 0;
  3162. else {
  3163. if (frq->fixed)
  3164. printk(KERN_WARNING "%s: Fixed fragmentation is "
  3165. "not supported on this firmware. "
  3166. "Using MWO robust instead.\n", dev->name);
  3167. priv->mwo_robust = 1;
  3168. }
  3169. } else {
  3170. if (frq->disabled)
  3171. priv->frag_thresh = 2346;
  3172. else {
  3173. if ( (frq->value < 256) || (frq->value > 2346) )
  3174. err = -EINVAL;
  3175. else
  3176. priv->frag_thresh = frq->value & ~0x1; /* must be even */
  3177. }
  3178. }
  3179. orinoco_unlock(priv, &flags);
  3180. return err;
  3181. }
  3182. static int orinoco_ioctl_getfrag(struct net_device *dev,
  3183. struct iw_request_info *info,
  3184. struct iw_param *frq,
  3185. char *extra)
  3186. {
  3187. struct orinoco_private *priv = netdev_priv(dev);
  3188. hermes_t *hw = &priv->hw;
  3189. int err;
  3190. u16 val;
  3191. unsigned long flags;
  3192. if (orinoco_lock(priv, &flags) != 0)
  3193. return -EBUSY;
  3194. if (priv->has_mwo) {
  3195. err = hermes_read_wordrec(hw, USER_BAP,
  3196. HERMES_RID_CNFMWOROBUST_AGERE,
  3197. &val);
  3198. if (err)
  3199. val = 0;
  3200. frq->value = val ? 2347 : 0;
  3201. frq->disabled = ! val;
  3202. frq->fixed = 0;
  3203. } else {
  3204. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
  3205. &val);
  3206. if (err)
  3207. val = 0;
  3208. frq->value = val;
  3209. frq->disabled = (val >= 2346);
  3210. frq->fixed = 1;
  3211. }
  3212. orinoco_unlock(priv, &flags);
  3213. return err;
  3214. }
  3215. static int orinoco_ioctl_setrate(struct net_device *dev,
  3216. struct iw_request_info *info,
  3217. struct iw_param *rrq,
  3218. char *extra)
  3219. {
  3220. struct orinoco_private *priv = netdev_priv(dev);
  3221. int ratemode = -1;
  3222. int bitrate; /* 100s of kilobits */
  3223. int i;
  3224. unsigned long flags;
  3225. /* As the user space doesn't know our highest rate, it uses -1
  3226. * to ask us to set the highest rate. Test it using "iwconfig
  3227. * ethX rate auto" - Jean II */
  3228. if (rrq->value == -1)
  3229. bitrate = 110;
  3230. else {
  3231. if (rrq->value % 100000)
  3232. return -EINVAL;
  3233. bitrate = rrq->value / 100000;
  3234. }
  3235. if ( (bitrate != 10) && (bitrate != 20) &&
  3236. (bitrate != 55) && (bitrate != 110) )
  3237. return -EINVAL;
  3238. for (i = 0; i < BITRATE_TABLE_SIZE; i++)
  3239. if ( (bitrate_table[i].bitrate == bitrate) &&
  3240. (bitrate_table[i].automatic == ! rrq->fixed) ) {
  3241. ratemode = i;
  3242. break;
  3243. }
  3244. if (ratemode == -1)
  3245. return -EINVAL;
  3246. if (orinoco_lock(priv, &flags) != 0)
  3247. return -EBUSY;
  3248. priv->bitratemode = ratemode;
  3249. orinoco_unlock(priv, &flags);
  3250. return -EINPROGRESS;
  3251. }
  3252. static int orinoco_ioctl_getrate(struct net_device *dev,
  3253. struct iw_request_info *info,
  3254. struct iw_param *rrq,
  3255. char *extra)
  3256. {
  3257. struct orinoco_private *priv = netdev_priv(dev);
  3258. hermes_t *hw = &priv->hw;
  3259. int err = 0;
  3260. int ratemode;
  3261. int i;
  3262. u16 val;
  3263. unsigned long flags;
  3264. if (orinoco_lock(priv, &flags) != 0)
  3265. return -EBUSY;
  3266. ratemode = priv->bitratemode;
  3267. BUG_ON((ratemode < 0) || (ratemode >= BITRATE_TABLE_SIZE));
  3268. rrq->value = bitrate_table[ratemode].bitrate * 100000;
  3269. rrq->fixed = ! bitrate_table[ratemode].automatic;
  3270. rrq->disabled = 0;
  3271. /* If the interface is running we try to find more about the
  3272. current mode */
  3273. if (netif_running(dev)) {
  3274. err = hermes_read_wordrec(hw, USER_BAP,
  3275. HERMES_RID_CURRENTTXRATE, &val);
  3276. if (err)
  3277. goto out;
  3278. switch (priv->firmware_type) {
  3279. case FIRMWARE_TYPE_AGERE: /* Lucent style rate */
  3280. /* Note : in Lucent firmware, the return value of
  3281. * HERMES_RID_CURRENTTXRATE is the bitrate in Mb/s,
  3282. * and therefore is totally different from the
  3283. * encoding of HERMES_RID_CNFTXRATECONTROL.
  3284. * Don't forget that 6Mb/s is really 5.5Mb/s */
  3285. if (val == 6)
  3286. rrq->value = 5500000;
  3287. else
  3288. rrq->value = val * 1000000;
  3289. break;
  3290. case FIRMWARE_TYPE_INTERSIL: /* Intersil style rate */
  3291. case FIRMWARE_TYPE_SYMBOL: /* Symbol style rate */
  3292. for (i = 0; i < BITRATE_TABLE_SIZE; i++)
  3293. if (bitrate_table[i].intersil_txratectrl == val) {
  3294. ratemode = i;
  3295. break;
  3296. }
  3297. if (i >= BITRATE_TABLE_SIZE)
  3298. printk(KERN_INFO "%s: Unable to determine current bitrate (0x%04hx)\n",
  3299. dev->name, val);
  3300. rrq->value = bitrate_table[ratemode].bitrate * 100000;
  3301. break;
  3302. default:
  3303. BUG();
  3304. }
  3305. }
  3306. out:
  3307. orinoco_unlock(priv, &flags);
  3308. return err;
  3309. }
  3310. static int orinoco_ioctl_setpower(struct net_device *dev,
  3311. struct iw_request_info *info,
  3312. struct iw_param *prq,
  3313. char *extra)
  3314. {
  3315. struct orinoco_private *priv = netdev_priv(dev);
  3316. int err = -EINPROGRESS; /* Call commit handler */
  3317. unsigned long flags;
  3318. if (orinoco_lock(priv, &flags) != 0)
  3319. return -EBUSY;
  3320. if (prq->disabled) {
  3321. priv->pm_on = 0;
  3322. } else {
  3323. switch (prq->flags & IW_POWER_MODE) {
  3324. case IW_POWER_UNICAST_R:
  3325. priv->pm_mcast = 0;
  3326. priv->pm_on = 1;
  3327. break;
  3328. case IW_POWER_ALL_R:
  3329. priv->pm_mcast = 1;
  3330. priv->pm_on = 1;
  3331. break;
  3332. case IW_POWER_ON:
  3333. /* No flags : but we may have a value - Jean II */
  3334. break;
  3335. default:
  3336. err = -EINVAL;
  3337. }
  3338. if (err)
  3339. goto out;
  3340. if (prq->flags & IW_POWER_TIMEOUT) {
  3341. priv->pm_on = 1;
  3342. priv->pm_timeout = prq->value / 1000;
  3343. }
  3344. if (prq->flags & IW_POWER_PERIOD) {
  3345. priv->pm_on = 1;
  3346. priv->pm_period = prq->value / 1000;
  3347. }
  3348. /* It's valid to not have a value if we are just toggling
  3349. * the flags... Jean II */
  3350. if(!priv->pm_on) {
  3351. err = -EINVAL;
  3352. goto out;
  3353. }
  3354. }
  3355. out:
  3356. orinoco_unlock(priv, &flags);
  3357. return err;
  3358. }
  3359. static int orinoco_ioctl_getpower(struct net_device *dev,
  3360. struct iw_request_info *info,
  3361. struct iw_param *prq,
  3362. char *extra)
  3363. {
  3364. struct orinoco_private *priv = netdev_priv(dev);
  3365. hermes_t *hw = &priv->hw;
  3366. int err = 0;
  3367. u16 enable, period, timeout, mcast;
  3368. unsigned long flags;
  3369. if (orinoco_lock(priv, &flags) != 0)
  3370. return -EBUSY;
  3371. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFPMENABLED, &enable);
  3372. if (err)
  3373. goto out;
  3374. err = hermes_read_wordrec(hw, USER_BAP,
  3375. HERMES_RID_CNFMAXSLEEPDURATION, &period);
  3376. if (err)
  3377. goto out;
  3378. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFPMHOLDOVERDURATION, &timeout);
  3379. if (err)
  3380. goto out;
  3381. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFMULTICASTRECEIVE, &mcast);
  3382. if (err)
  3383. goto out;
  3384. prq->disabled = !enable;
  3385. /* Note : by default, display the period */
  3386. if ((prq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
  3387. prq->flags = IW_POWER_TIMEOUT;
  3388. prq->value = timeout * 1000;
  3389. } else {
  3390. prq->flags = IW_POWER_PERIOD;
  3391. prq->value = period * 1000;
  3392. }
  3393. if (mcast)
  3394. prq->flags |= IW_POWER_ALL_R;
  3395. else
  3396. prq->flags |= IW_POWER_UNICAST_R;
  3397. out:
  3398. orinoco_unlock(priv, &flags);
  3399. return err;
  3400. }
  3401. static int orinoco_ioctl_getretry(struct net_device *dev,
  3402. struct iw_request_info *info,
  3403. struct iw_param *rrq,
  3404. char *extra)
  3405. {
  3406. struct orinoco_private *priv = netdev_priv(dev);
  3407. hermes_t *hw = &priv->hw;
  3408. int err = 0;
  3409. u16 short_limit, long_limit, lifetime;
  3410. unsigned long flags;
  3411. if (orinoco_lock(priv, &flags) != 0)
  3412. return -EBUSY;
  3413. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_SHORTRETRYLIMIT,
  3414. &short_limit);
  3415. if (err)
  3416. goto out;
  3417. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_LONGRETRYLIMIT,
  3418. &long_limit);
  3419. if (err)
  3420. goto out;
  3421. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_MAXTRANSMITLIFETIME,
  3422. &lifetime);
  3423. if (err)
  3424. goto out;
  3425. rrq->disabled = 0; /* Can't be disabled */
  3426. /* Note : by default, display the retry number */
  3427. if ((rrq->flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
  3428. rrq->flags = IW_RETRY_LIFETIME;
  3429. rrq->value = lifetime * 1000; /* ??? */
  3430. } else {
  3431. /* By default, display the min number */
  3432. if ((rrq->flags & IW_RETRY_MAX)) {
  3433. rrq->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
  3434. rrq->value = long_limit;
  3435. } else {
  3436. rrq->flags = IW_RETRY_LIMIT;
  3437. rrq->value = short_limit;
  3438. if(short_limit != long_limit)
  3439. rrq->flags |= IW_RETRY_MIN;
  3440. }
  3441. }
  3442. out:
  3443. orinoco_unlock(priv, &flags);
  3444. return err;
  3445. }
  3446. static int orinoco_ioctl_reset(struct net_device *dev,
  3447. struct iw_request_info *info,
  3448. void *wrqu,
  3449. char *extra)
  3450. {
  3451. struct orinoco_private *priv = netdev_priv(dev);
  3452. if (! capable(CAP_NET_ADMIN))
  3453. return -EPERM;
  3454. if (info->cmd == (SIOCIWFIRSTPRIV + 0x1)) {
  3455. printk(KERN_DEBUG "%s: Forcing reset!\n", dev->name);
  3456. /* Firmware reset */
  3457. orinoco_reset(dev);
  3458. } else {
  3459. printk(KERN_DEBUG "%s: Force scheduling reset!\n", dev->name);
  3460. schedule_work(&priv->reset_work);
  3461. }
  3462. return 0;
  3463. }
  3464. static int orinoco_ioctl_setibssport(struct net_device *dev,
  3465. struct iw_request_info *info,
  3466. void *wrqu,
  3467. char *extra)
  3468. {
  3469. struct orinoco_private *priv = netdev_priv(dev);
  3470. int val = *( (int *) extra );
  3471. unsigned long flags;
  3472. if (orinoco_lock(priv, &flags) != 0)
  3473. return -EBUSY;
  3474. priv->ibss_port = val ;
  3475. /* Actually update the mode we are using */
  3476. set_port_type(priv);
  3477. orinoco_unlock(priv, &flags);
  3478. return -EINPROGRESS; /* Call commit handler */
  3479. }
  3480. static int orinoco_ioctl_getibssport(struct net_device *dev,
  3481. struct iw_request_info *info,
  3482. void *wrqu,
  3483. char *extra)
  3484. {
  3485. struct orinoco_private *priv = netdev_priv(dev);
  3486. int *val = (int *) extra;
  3487. *val = priv->ibss_port;
  3488. return 0;
  3489. }
  3490. static int orinoco_ioctl_setport3(struct net_device *dev,
  3491. struct iw_request_info *info,
  3492. void *wrqu,
  3493. char *extra)
  3494. {
  3495. struct orinoco_private *priv = netdev_priv(dev);
  3496. int val = *( (int *) extra );
  3497. int err = 0;
  3498. unsigned long flags;
  3499. if (orinoco_lock(priv, &flags) != 0)
  3500. return -EBUSY;
  3501. switch (val) {
  3502. case 0: /* Try to do IEEE ad-hoc mode */
  3503. if (! priv->has_ibss) {
  3504. err = -EINVAL;
  3505. break;
  3506. }
  3507. priv->prefer_port3 = 0;
  3508. break;
  3509. case 1: /* Try to do Lucent proprietary ad-hoc mode */
  3510. if (! priv->has_port3) {
  3511. err = -EINVAL;
  3512. break;
  3513. }
  3514. priv->prefer_port3 = 1;
  3515. break;
  3516. default:
  3517. err = -EINVAL;
  3518. }
  3519. if (! err) {
  3520. /* Actually update the mode we are using */
  3521. set_port_type(priv);
  3522. err = -EINPROGRESS;
  3523. }
  3524. orinoco_unlock(priv, &flags);
  3525. return err;
  3526. }
  3527. static int orinoco_ioctl_getport3(struct net_device *dev,
  3528. struct iw_request_info *info,
  3529. void *wrqu,
  3530. char *extra)
  3531. {
  3532. struct orinoco_private *priv = netdev_priv(dev);
  3533. int *val = (int *) extra;
  3534. *val = priv->prefer_port3;
  3535. return 0;
  3536. }
  3537. static int orinoco_ioctl_setpreamble(struct net_device *dev,
  3538. struct iw_request_info *info,
  3539. void *wrqu,
  3540. char *extra)
  3541. {
  3542. struct orinoco_private *priv = netdev_priv(dev);
  3543. unsigned long flags;
  3544. int val;
  3545. if (! priv->has_preamble)
  3546. return -EOPNOTSUPP;
  3547. /* 802.11b has recently defined some short preamble.
  3548. * Basically, the Phy header has been reduced in size.
  3549. * This increase performance, especially at high rates
  3550. * (the preamble is transmitted at 1Mb/s), unfortunately
  3551. * this give compatibility troubles... - Jean II */
  3552. val = *( (int *) extra );
  3553. if (orinoco_lock(priv, &flags) != 0)
  3554. return -EBUSY;
  3555. if (val)
  3556. priv->preamble = 1;
  3557. else
  3558. priv->preamble = 0;
  3559. orinoco_unlock(priv, &flags);
  3560. return -EINPROGRESS; /* Call commit handler */
  3561. }
  3562. static int orinoco_ioctl_getpreamble(struct net_device *dev,
  3563. struct iw_request_info *info,
  3564. void *wrqu,
  3565. char *extra)
  3566. {
  3567. struct orinoco_private *priv = netdev_priv(dev);
  3568. int *val = (int *) extra;
  3569. if (! priv->has_preamble)
  3570. return -EOPNOTSUPP;
  3571. *val = priv->preamble;
  3572. return 0;
  3573. }
  3574. /* ioctl interface to hermes_read_ltv()
  3575. * To use with iwpriv, pass the RID as the token argument, e.g.
  3576. * iwpriv get_rid [0xfc00]
  3577. * At least Wireless Tools 25 is required to use iwpriv.
  3578. * For Wireless Tools 25 and 26 append "dummy" are the end. */
  3579. static int orinoco_ioctl_getrid(struct net_device *dev,
  3580. struct iw_request_info *info,
  3581. struct iw_point *data,
  3582. char *extra)
  3583. {
  3584. struct orinoco_private *priv = netdev_priv(dev);
  3585. hermes_t *hw = &priv->hw;
  3586. int rid = data->flags;
  3587. u16 length;
  3588. int err;
  3589. unsigned long flags;
  3590. /* It's a "get" function, but we don't want users to access the
  3591. * WEP key and other raw firmware data */
  3592. if (! capable(CAP_NET_ADMIN))
  3593. return -EPERM;
  3594. if (rid < 0xfc00 || rid > 0xffff)
  3595. return -EINVAL;
  3596. if (orinoco_lock(priv, &flags) != 0)
  3597. return -EBUSY;
  3598. err = hermes_read_ltv(hw, USER_BAP, rid, MAX_RID_LEN, &length,
  3599. extra);
  3600. if (err)
  3601. goto out;
  3602. data->length = min_t(u16, HERMES_RECLEN_TO_BYTES(length),
  3603. MAX_RID_LEN);
  3604. out:
  3605. orinoco_unlock(priv, &flags);
  3606. return err;
  3607. }
  3608. /* Spy is used for link quality/strength measurements in Ad-Hoc mode
  3609. * Jean II */
  3610. static int orinoco_ioctl_setspy(struct net_device *dev,
  3611. struct iw_request_info *info,
  3612. struct iw_point *srq,
  3613. char *extra)
  3614. {
  3615. struct orinoco_private *priv = netdev_priv(dev);
  3616. struct sockaddr *address = (struct sockaddr *) extra;
  3617. int number = srq->length;
  3618. int i;
  3619. unsigned long flags;
  3620. /* Make sure nobody mess with the structure while we do */
  3621. if (orinoco_lock(priv, &flags) != 0)
  3622. return -EBUSY;
  3623. /* orinoco_lock() doesn't disable interrupts, so make sure the
  3624. * interrupt rx path don't get confused while we copy */
  3625. priv->spy_number = 0;
  3626. if (number > 0) {
  3627. /* Extract the addresses */
  3628. for (i = 0; i < number; i++)
  3629. memcpy(priv->spy_address[i], address[i].sa_data,
  3630. ETH_ALEN);
  3631. /* Reset stats */
  3632. memset(priv->spy_stat, 0,
  3633. sizeof(struct iw_quality) * IW_MAX_SPY);
  3634. /* Set number of addresses */
  3635. priv->spy_number = number;
  3636. }
  3637. /* Now, let the others play */
  3638. orinoco_unlock(priv, &flags);
  3639. /* Do NOT call commit handler */
  3640. return 0;
  3641. }
  3642. static int orinoco_ioctl_getspy(struct net_device *dev,
  3643. struct iw_request_info *info,
  3644. struct iw_point *srq,
  3645. char *extra)
  3646. {
  3647. struct orinoco_private *priv = netdev_priv(dev);
  3648. struct sockaddr *address = (struct sockaddr *) extra;
  3649. int number;
  3650. int i;
  3651. unsigned long flags;
  3652. if (orinoco_lock(priv, &flags) != 0)
  3653. return -EBUSY;
  3654. number = priv->spy_number;
  3655. /* Create address struct */
  3656. for (i = 0; i < number; i++) {
  3657. memcpy(address[i].sa_data, priv->spy_address[i], ETH_ALEN);
  3658. address[i].sa_family = AF_UNIX;
  3659. }
  3660. if (number > 0) {
  3661. /* Create address struct */
  3662. for (i = 0; i < number; i++) {
  3663. memcpy(address[i].sa_data, priv->spy_address[i],
  3664. ETH_ALEN);
  3665. address[i].sa_family = AF_UNIX;
  3666. }
  3667. /* Copy stats */
  3668. /* In theory, we should disable irqs while copying the stats
  3669. * because the rx path might update it in the middle...
  3670. * Bah, who care ? - Jean II */
  3671. memcpy(extra + (sizeof(struct sockaddr) * number),
  3672. priv->spy_stat, sizeof(struct iw_quality) * number);
  3673. }
  3674. /* Reset updated flags. */
  3675. for (i = 0; i < number; i++)
  3676. priv->spy_stat[i].updated = 0;
  3677. orinoco_unlock(priv, &flags);
  3678. srq->length = number;
  3679. return 0;
  3680. }
  3681. /* Trigger a scan (look for other cells in the vicinity */
  3682. static int orinoco_ioctl_setscan(struct net_device *dev,
  3683. struct iw_request_info *info,
  3684. struct iw_param *srq,
  3685. char *extra)
  3686. {
  3687. struct orinoco_private *priv = netdev_priv(dev);
  3688. hermes_t *hw = &priv->hw;
  3689. int err = 0;
  3690. unsigned long flags;
  3691. /* Note : you may have realised that, as this is a SET operation,
  3692. * this is priviledged and therefore a normal user can't
  3693. * perform scanning.
  3694. * This is not an error, while the device perform scanning,
  3695. * traffic doesn't flow, so it's a perfect DoS...
  3696. * Jean II */
  3697. if (orinoco_lock(priv, &flags) != 0)
  3698. return -EBUSY;
  3699. /* Scanning with port 0 disabled would fail */
  3700. if (!netif_running(dev)) {
  3701. err = -ENETDOWN;
  3702. goto out;
  3703. }
  3704. /* In monitor mode, the scan results are always empty.
  3705. * Probe responses are passed to the driver as received
  3706. * frames and could be processed in software. */
  3707. if (priv->iw_mode == IW_MODE_MONITOR) {
  3708. err = -EOPNOTSUPP;
  3709. goto out;
  3710. }
  3711. /* Note : because we don't lock out the irq handler, the way
  3712. * we access scan variables in priv is critical.
  3713. * o scan_inprogress : not touched by irq handler
  3714. * o scan_mode : not touched by irq handler
  3715. * o scan_result : irq is strict producer, non-irq is strict
  3716. * consumer.
  3717. * o scan_len : synchronised with scan_result
  3718. * Before modifying anything on those variables, please think hard !
  3719. * Jean II */
  3720. /* If there is still some left-over scan results, get rid of it */
  3721. if (priv->scan_result != NULL) {
  3722. /* What's likely is that a client did crash or was killed
  3723. * between triggering the scan request and reading the
  3724. * results, so we need to reset everything.
  3725. * Some clients that are too slow may suffer from that...
  3726. * Jean II */
  3727. kfree(priv->scan_result);
  3728. priv->scan_result = NULL;
  3729. }
  3730. /* Save flags */
  3731. priv->scan_mode = srq->flags;
  3732. /* Always trigger scanning, even if it's in progress.
  3733. * This way, if the info frame get lost, we will recover somewhat
  3734. * gracefully - Jean II */
  3735. if (priv->has_hostscan) {
  3736. switch (priv->firmware_type) {
  3737. case FIRMWARE_TYPE_SYMBOL:
  3738. err = hermes_write_wordrec(hw, USER_BAP,
  3739. HERMES_RID_CNFHOSTSCAN_SYMBOL,
  3740. HERMES_HOSTSCAN_SYMBOL_ONCE |
  3741. HERMES_HOSTSCAN_SYMBOL_BCAST);
  3742. break;
  3743. case FIRMWARE_TYPE_INTERSIL: {
  3744. u16 req[3];
  3745. req[0] = cpu_to_le16(0x3fff); /* All channels */
  3746. req[1] = cpu_to_le16(0x0001); /* rate 1 Mbps */
  3747. req[2] = 0; /* Any ESSID */
  3748. err = HERMES_WRITE_RECORD(hw, USER_BAP,
  3749. HERMES_RID_CNFHOSTSCAN, &req);
  3750. }
  3751. break;
  3752. case FIRMWARE_TYPE_AGERE:
  3753. err = hermes_write_wordrec(hw, USER_BAP,
  3754. HERMES_RID_CNFSCANSSID_AGERE,
  3755. 0); /* Any ESSID */
  3756. if (err)
  3757. break;
  3758. err = hermes_inquire(hw, HERMES_INQ_SCAN);
  3759. break;
  3760. }
  3761. } else
  3762. err = hermes_inquire(hw, HERMES_INQ_SCAN);
  3763. /* One more client */
  3764. if (! err)
  3765. priv->scan_inprogress = 1;
  3766. out:
  3767. orinoco_unlock(priv, &flags);
  3768. return err;
  3769. }
  3770. /* Translate scan data returned from the card to a card independant
  3771. * format that the Wireless Tools will understand - Jean II */
  3772. static inline int orinoco_translate_scan(struct net_device *dev,
  3773. char *buffer,
  3774. char *scan,
  3775. int scan_len)
  3776. {
  3777. struct orinoco_private *priv = netdev_priv(dev);
  3778. int offset; /* In the scan data */
  3779. union hermes_scan_info *atom;
  3780. int atom_len;
  3781. u16 capabilities;
  3782. u16 channel;
  3783. struct iw_event iwe; /* Temporary buffer */
  3784. char * current_ev = buffer;
  3785. char * end_buf = buffer + IW_SCAN_MAX_DATA;
  3786. switch (priv->firmware_type) {
  3787. case FIRMWARE_TYPE_AGERE:
  3788. atom_len = sizeof(struct agere_scan_apinfo);
  3789. offset = 0;
  3790. break;
  3791. case FIRMWARE_TYPE_SYMBOL:
  3792. /* Lack of documentation necessitates this hack.
  3793. * Different firmwares have 68 or 76 byte long atoms.
  3794. * We try modulo first. If the length divides by both,
  3795. * we check what would be the channel in the second
  3796. * frame for a 68-byte atom. 76-byte atoms have 0 there.
  3797. * Valid channel cannot be 0. */
  3798. if (scan_len % 76)
  3799. atom_len = 68;
  3800. else if (scan_len % 68)
  3801. atom_len = 76;
  3802. else if (scan_len >= 1292 && scan[68] == 0)
  3803. atom_len = 76;
  3804. else
  3805. atom_len = 68;
  3806. offset = 0;
  3807. break;
  3808. case FIRMWARE_TYPE_INTERSIL:
  3809. offset = 4;
  3810. if (priv->has_hostscan)
  3811. atom_len = scan[0] + (scan[1] << 8);
  3812. else
  3813. atom_len = offsetof(struct prism2_scan_apinfo, atim);
  3814. break;
  3815. default:
  3816. return 0;
  3817. }
  3818. /* Check that we got an whole number of atoms */
  3819. if ((scan_len - offset) % atom_len) {
  3820. printk(KERN_ERR "%s: Unexpected scan data length %d, "
  3821. "atom_len %d, offset %d\n", dev->name, scan_len,
  3822. atom_len, offset);
  3823. return 0;
  3824. }
  3825. /* Read the entries one by one */
  3826. for (; offset + atom_len <= scan_len; offset += atom_len) {
  3827. /* Get next atom */
  3828. atom = (union hermes_scan_info *) (scan + offset);
  3829. /* First entry *MUST* be the AP MAC address */
  3830. iwe.cmd = SIOCGIWAP;
  3831. iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
  3832. memcpy(iwe.u.ap_addr.sa_data, atom->a.bssid, ETH_ALEN);
  3833. current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_ADDR_LEN);
  3834. /* Other entries will be displayed in the order we give them */
  3835. /* Add the ESSID */
  3836. iwe.u.data.length = le16_to_cpu(atom->a.essid_len);
  3837. if (iwe.u.data.length > 32)
  3838. iwe.u.data.length = 32;
  3839. iwe.cmd = SIOCGIWESSID;
  3840. iwe.u.data.flags = 1;
  3841. current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, atom->a.essid);
  3842. /* Add mode */
  3843. iwe.cmd = SIOCGIWMODE;
  3844. capabilities = le16_to_cpu(atom->a.capabilities);
  3845. if (capabilities & 0x3) {
  3846. if (capabilities & 0x1)
  3847. iwe.u.mode = IW_MODE_MASTER;
  3848. else
  3849. iwe.u.mode = IW_MODE_ADHOC;
  3850. current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_UINT_LEN);
  3851. }
  3852. channel = atom->s.channel;
  3853. if ( (channel >= 1) && (channel <= NUM_CHANNELS) ) {
  3854. /* Add frequency */
  3855. iwe.cmd = SIOCGIWFREQ;
  3856. iwe.u.freq.m = channel_frequency[channel-1] * 100000;
  3857. iwe.u.freq.e = 1;
  3858. current_ev = iwe_stream_add_event(current_ev, end_buf,
  3859. &iwe, IW_EV_FREQ_LEN);
  3860. }
  3861. /* Add quality statistics */
  3862. iwe.cmd = IWEVQUAL;
  3863. iwe.u.qual.updated = 0x10; /* no link quality */
  3864. iwe.u.qual.level = (__u8) le16_to_cpu(atom->a.level) - 0x95;
  3865. iwe.u.qual.noise = (__u8) le16_to_cpu(atom->a.noise) - 0x95;
  3866. /* Wireless tools prior to 27.pre22 will show link quality
  3867. * anyway, so we provide a reasonable value. */
  3868. if (iwe.u.qual.level > iwe.u.qual.noise)
  3869. iwe.u.qual.qual = iwe.u.qual.level - iwe.u.qual.noise;
  3870. else
  3871. iwe.u.qual.qual = 0;
  3872. current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_QUAL_LEN);
  3873. /* Add encryption capability */
  3874. iwe.cmd = SIOCGIWENCODE;
  3875. if (capabilities & 0x10)
  3876. iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
  3877. else
  3878. iwe.u.data.flags = IW_ENCODE_DISABLED;
  3879. iwe.u.data.length = 0;
  3880. current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, atom->a.essid);
  3881. /* Bit rate is not available in Lucent/Agere firmwares */
  3882. if (priv->firmware_type != FIRMWARE_TYPE_AGERE) {
  3883. char * current_val = current_ev + IW_EV_LCP_LEN;
  3884. int i;
  3885. int step;
  3886. if (priv->firmware_type == FIRMWARE_TYPE_SYMBOL)
  3887. step = 2;
  3888. else
  3889. step = 1;
  3890. iwe.cmd = SIOCGIWRATE;
  3891. /* Those two flags are ignored... */
  3892. iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
  3893. /* Max 10 values */
  3894. for (i = 0; i < 10; i += step) {
  3895. /* NULL terminated */
  3896. if (atom->p.rates[i] == 0x0)
  3897. break;
  3898. /* Bit rate given in 500 kb/s units (+ 0x80) */
  3899. iwe.u.bitrate.value = ((atom->p.rates[i] & 0x7f) * 500000);
  3900. current_val = iwe_stream_add_value(current_ev, current_val,
  3901. end_buf, &iwe,
  3902. IW_EV_PARAM_LEN);
  3903. }
  3904. /* Check if we added any event */
  3905. if ((current_val - current_ev) > IW_EV_LCP_LEN)
  3906. current_ev = current_val;
  3907. }
  3908. /* The other data in the scan result are not really
  3909. * interesting, so for now drop it - Jean II */
  3910. }
  3911. return current_ev - buffer;
  3912. }
  3913. /* Return results of a scan */
  3914. static int orinoco_ioctl_getscan(struct net_device *dev,
  3915. struct iw_request_info *info,
  3916. struct iw_point *srq,
  3917. char *extra)
  3918. {
  3919. struct orinoco_private *priv = netdev_priv(dev);
  3920. int err = 0;
  3921. unsigned long flags;
  3922. if (orinoco_lock(priv, &flags) != 0)
  3923. return -EBUSY;
  3924. /* If no results yet, ask to try again later */
  3925. if (priv->scan_result == NULL) {
  3926. if (priv->scan_inprogress)
  3927. /* Important note : we don't want to block the caller
  3928. * until results are ready for various reasons.
  3929. * First, managing wait queues is complex and racy.
  3930. * Second, we grab some rtnetlink lock before comming
  3931. * here (in dev_ioctl()).
  3932. * Third, we generate an Wireless Event, so the
  3933. * caller can wait itself on that - Jean II */
  3934. err = -EAGAIN;
  3935. else
  3936. /* Client error, no scan results...
  3937. * The caller need to restart the scan. */
  3938. err = -ENODATA;
  3939. } else {
  3940. /* We have some results to push back to user space */
  3941. /* Translate to WE format */
  3942. srq->length = orinoco_translate_scan(dev, extra,
  3943. priv->scan_result,
  3944. priv->scan_len);
  3945. /* Return flags */
  3946. srq->flags = (__u16) priv->scan_mode;
  3947. /* Results are here, so scan no longer in progress */
  3948. priv->scan_inprogress = 0;
  3949. /* In any case, Scan results will be cleaned up in the
  3950. * reset function and when exiting the driver.
  3951. * The person triggering the scanning may never come to
  3952. * pick the results, so we need to do it in those places.
  3953. * Jean II */
  3954. #ifdef SCAN_SINGLE_READ
  3955. /* If you enable this option, only one client (the first
  3956. * one) will be able to read the result (and only one
  3957. * time). If there is multiple concurent clients that
  3958. * want to read scan results, this behavior is not
  3959. * advisable - Jean II */
  3960. kfree(priv->scan_result);
  3961. priv->scan_result = NULL;
  3962. #endif /* SCAN_SINGLE_READ */
  3963. /* Here, if too much time has elapsed since last scan,
  3964. * we may want to clean up scan results... - Jean II */
  3965. }
  3966. orinoco_unlock(priv, &flags);
  3967. return err;
  3968. }
  3969. /* Commit handler, called after set operations */
  3970. static int orinoco_ioctl_commit(struct net_device *dev,
  3971. struct iw_request_info *info,
  3972. void *wrqu,
  3973. char *extra)
  3974. {
  3975. struct orinoco_private *priv = netdev_priv(dev);
  3976. struct hermes *hw = &priv->hw;
  3977. unsigned long flags;
  3978. int err = 0;
  3979. if (!priv->open)
  3980. return 0;
  3981. if (priv->broken_disableport) {
  3982. orinoco_reset(dev);
  3983. return 0;
  3984. }
  3985. if (orinoco_lock(priv, &flags) != 0)
  3986. return err;
  3987. err = hermes_disable_port(hw, 0);
  3988. if (err) {
  3989. printk(KERN_WARNING "%s: Unable to disable port "
  3990. "while reconfiguring card\n", dev->name);
  3991. priv->broken_disableport = 1;
  3992. goto out;
  3993. }
  3994. err = __orinoco_program_rids(dev);
  3995. if (err) {
  3996. printk(KERN_WARNING "%s: Unable to reconfigure card\n",
  3997. dev->name);
  3998. goto out;
  3999. }
  4000. err = hermes_enable_port(hw, 0);
  4001. if (err) {
  4002. printk(KERN_WARNING "%s: Unable to enable port while reconfiguring card\n",
  4003. dev->name);
  4004. goto out;
  4005. }
  4006. out:
  4007. if (err) {
  4008. printk(KERN_WARNING "%s: Resetting instead...\n", dev->name);
  4009. schedule_work(&priv->reset_work);
  4010. err = 0;
  4011. }
  4012. orinoco_unlock(priv, &flags);
  4013. return err;
  4014. }
  4015. static const struct iw_priv_args orinoco_privtab[] = {
  4016. { SIOCIWFIRSTPRIV + 0x0, 0, 0, "force_reset" },
  4017. { SIOCIWFIRSTPRIV + 0x1, 0, 0, "card_reset" },
  4018. { SIOCIWFIRSTPRIV + 0x2, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  4019. 0, "set_port3" },
  4020. { SIOCIWFIRSTPRIV + 0x3, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  4021. "get_port3" },
  4022. { SIOCIWFIRSTPRIV + 0x4, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  4023. 0, "set_preamble" },
  4024. { SIOCIWFIRSTPRIV + 0x5, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  4025. "get_preamble" },
  4026. { SIOCIWFIRSTPRIV + 0x6, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  4027. 0, "set_ibssport" },
  4028. { SIOCIWFIRSTPRIV + 0x7, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  4029. "get_ibssport" },
  4030. { SIOCIWFIRSTPRIV + 0x9, 0, IW_PRIV_TYPE_BYTE | MAX_RID_LEN,
  4031. "get_rid" },
  4032. };
  4033. /*
  4034. * Structures to export the Wireless Handlers
  4035. */
  4036. static const iw_handler orinoco_handler[] = {
  4037. [SIOCSIWCOMMIT-SIOCIWFIRST] (iw_handler) orinoco_ioctl_commit,
  4038. [SIOCGIWNAME -SIOCIWFIRST] (iw_handler) orinoco_ioctl_getname,
  4039. [SIOCSIWFREQ -SIOCIWFIRST] (iw_handler) orinoco_ioctl_setfreq,
  4040. [SIOCGIWFREQ -SIOCIWFIRST] (iw_handler) orinoco_ioctl_getfreq,
  4041. [SIOCSIWMODE -SIOCIWFIRST] (iw_handler) orinoco_ioctl_setmode,
  4042. [SIOCGIWMODE -SIOCIWFIRST] (iw_handler) orinoco_ioctl_getmode,
  4043. [SIOCSIWSENS -SIOCIWFIRST] (iw_handler) orinoco_ioctl_setsens,
  4044. [SIOCGIWSENS -SIOCIWFIRST] (iw_handler) orinoco_ioctl_getsens,
  4045. [SIOCGIWRANGE -SIOCIWFIRST] (iw_handler) orinoco_ioctl_getiwrange,
  4046. [SIOCSIWSPY -SIOCIWFIRST] (iw_handler) orinoco_ioctl_setspy,
  4047. [SIOCGIWSPY -SIOCIWFIRST] (iw_handler) orinoco_ioctl_getspy,
  4048. [SIOCSIWAP -SIOCIWFIRST] (iw_handler) orinoco_ioctl_setwap,
  4049. [SIOCGIWAP -SIOCIWFIRST] (iw_handler) orinoco_ioctl_getwap,
  4050. [SIOCSIWSCAN -SIOCIWFIRST] (iw_handler) orinoco_ioctl_setscan,
  4051. [SIOCGIWSCAN -SIOCIWFIRST] (iw_handler) orinoco_ioctl_getscan,
  4052. [SIOCSIWESSID -SIOCIWFIRST] (iw_handler) orinoco_ioctl_setessid,
  4053. [SIOCGIWESSID -SIOCIWFIRST] (iw_handler) orinoco_ioctl_getessid,
  4054. [SIOCSIWNICKN -SIOCIWFIRST] (iw_handler) orinoco_ioctl_setnick,
  4055. [SIOCGIWNICKN -SIOCIWFIRST] (iw_handler) orinoco_ioctl_getnick,
  4056. [SIOCSIWRATE -SIOCIWFIRST] (iw_handler) orinoco_ioctl_setrate,
  4057. [SIOCGIWRATE -SIOCIWFIRST] (iw_handler) orinoco_ioctl_getrate,
  4058. [SIOCSIWRTS -SIOCIWFIRST] (iw_handler) orinoco_ioctl_setrts,
  4059. [SIOCGIWRTS -SIOCIWFIRST] (iw_handler) orinoco_ioctl_getrts,
  4060. [SIOCSIWFRAG -SIOCIWFIRST] (iw_handler) orinoco_ioctl_setfrag,
  4061. [SIOCGIWFRAG -SIOCIWFIRST] (iw_handler) orinoco_ioctl_getfrag,
  4062. [SIOCGIWRETRY -SIOCIWFIRST] (iw_handler) orinoco_ioctl_getretry,
  4063. [SIOCSIWENCODE-SIOCIWFIRST] (iw_handler) orinoco_ioctl_setiwencode,
  4064. [SIOCGIWENCODE-SIOCIWFIRST] (iw_handler) orinoco_ioctl_getiwencode,
  4065. [SIOCSIWPOWER -SIOCIWFIRST] (iw_handler) orinoco_ioctl_setpower,
  4066. [SIOCGIWPOWER -SIOCIWFIRST] (iw_handler) orinoco_ioctl_getpower,
  4067. };
  4068. /*
  4069. Added typecasting since we no longer use iwreq_data -- Moustafa
  4070. */
  4071. static const iw_handler orinoco_private_handler[] = {
  4072. [0] (iw_handler) orinoco_ioctl_reset,
  4073. [1] (iw_handler) orinoco_ioctl_reset,
  4074. [2] (iw_handler) orinoco_ioctl_setport3,
  4075. [3] (iw_handler) orinoco_ioctl_getport3,
  4076. [4] (iw_handler) orinoco_ioctl_setpreamble,
  4077. [5] (iw_handler) orinoco_ioctl_getpreamble,
  4078. [6] (iw_handler) orinoco_ioctl_setibssport,
  4079. [7] (iw_handler) orinoco_ioctl_getibssport,
  4080. [9] (iw_handler) orinoco_ioctl_getrid,
  4081. };
  4082. static const struct iw_handler_def orinoco_handler_def = {
  4083. .num_standard = ARRAY_SIZE(orinoco_handler),
  4084. .num_private = ARRAY_SIZE(orinoco_private_handler),
  4085. .num_private_args = ARRAY_SIZE(orinoco_privtab),
  4086. .standard = orinoco_handler,
  4087. .private = orinoco_private_handler,
  4088. .private_args = orinoco_privtab,
  4089. };
  4090. static void orinoco_get_drvinfo(struct net_device *dev,
  4091. struct ethtool_drvinfo *info)
  4092. {
  4093. struct orinoco_private *priv = netdev_priv(dev);
  4094. strncpy(info->driver, DRIVER_NAME, sizeof(info->driver) - 1);
  4095. strncpy(info->version, DRIVER_VERSION, sizeof(info->version) - 1);
  4096. strncpy(info->fw_version, priv->fw_name, sizeof(info->fw_version) - 1);
  4097. if (dev->class_dev.dev)
  4098. strncpy(info->bus_info, dev->class_dev.dev->bus_id,
  4099. sizeof(info->bus_info) - 1);
  4100. else
  4101. snprintf(info->bus_info, sizeof(info->bus_info) - 1,
  4102. "PCMCIA %p", priv->hw.iobase);
  4103. }
  4104. static struct ethtool_ops orinoco_ethtool_ops = {
  4105. .get_drvinfo = orinoco_get_drvinfo,
  4106. .get_link = ethtool_op_get_link,
  4107. };
  4108. /********************************************************************/
  4109. /* Debugging */
  4110. /********************************************************************/
  4111. #if 0
  4112. static void show_rx_frame(struct orinoco_rxframe_hdr *frame)
  4113. {
  4114. printk(KERN_DEBUG "RX descriptor:\n");
  4115. printk(KERN_DEBUG " status = 0x%04x\n", frame->desc.status);
  4116. printk(KERN_DEBUG " time = 0x%08x\n", frame->desc.time);
  4117. printk(KERN_DEBUG " silence = 0x%02x\n", frame->desc.silence);
  4118. printk(KERN_DEBUG " signal = 0x%02x\n", frame->desc.signal);
  4119. printk(KERN_DEBUG " rate = 0x%02x\n", frame->desc.rate);
  4120. printk(KERN_DEBUG " rxflow = 0x%02x\n", frame->desc.rxflow);
  4121. printk(KERN_DEBUG " reserved = 0x%08x\n", frame->desc.reserved);
  4122. printk(KERN_DEBUG "IEEE 802.11 header:\n");
  4123. printk(KERN_DEBUG " frame_ctl = 0x%04x\n",
  4124. frame->p80211.frame_ctl);
  4125. printk(KERN_DEBUG " duration_id = 0x%04x\n",
  4126. frame->p80211.duration_id);
  4127. printk(KERN_DEBUG " addr1 = %02x:%02x:%02x:%02x:%02x:%02x\n",
  4128. frame->p80211.addr1[0], frame->p80211.addr1[1],
  4129. frame->p80211.addr1[2], frame->p80211.addr1[3],
  4130. frame->p80211.addr1[4], frame->p80211.addr1[5]);
  4131. printk(KERN_DEBUG " addr2 = %02x:%02x:%02x:%02x:%02x:%02x\n",
  4132. frame->p80211.addr2[0], frame->p80211.addr2[1],
  4133. frame->p80211.addr2[2], frame->p80211.addr2[3],
  4134. frame->p80211.addr2[4], frame->p80211.addr2[5]);
  4135. printk(KERN_DEBUG " addr3 = %02x:%02x:%02x:%02x:%02x:%02x\n",
  4136. frame->p80211.addr3[0], frame->p80211.addr3[1],
  4137. frame->p80211.addr3[2], frame->p80211.addr3[3],
  4138. frame->p80211.addr3[4], frame->p80211.addr3[5]);
  4139. printk(KERN_DEBUG " seq_ctl = 0x%04x\n",
  4140. frame->p80211.seq_ctl);
  4141. printk(KERN_DEBUG " addr4 = %02x:%02x:%02x:%02x:%02x:%02x\n",
  4142. frame->p80211.addr4[0], frame->p80211.addr4[1],
  4143. frame->p80211.addr4[2], frame->p80211.addr4[3],
  4144. frame->p80211.addr4[4], frame->p80211.addr4[5]);
  4145. printk(KERN_DEBUG " data_len = 0x%04x\n",
  4146. frame->p80211.data_len);
  4147. printk(KERN_DEBUG "IEEE 802.3 header:\n");
  4148. printk(KERN_DEBUG " dest = %02x:%02x:%02x:%02x:%02x:%02x\n",
  4149. frame->p8023.h_dest[0], frame->p8023.h_dest[1],
  4150. frame->p8023.h_dest[2], frame->p8023.h_dest[3],
  4151. frame->p8023.h_dest[4], frame->p8023.h_dest[5]);
  4152. printk(KERN_DEBUG " src = %02x:%02x:%02x:%02x:%02x:%02x\n",
  4153. frame->p8023.h_source[0], frame->p8023.h_source[1],
  4154. frame->p8023.h_source[2], frame->p8023.h_source[3],
  4155. frame->p8023.h_source[4], frame->p8023.h_source[5]);
  4156. printk(KERN_DEBUG " len = 0x%04x\n", frame->p8023.h_proto);
  4157. printk(KERN_DEBUG "IEEE 802.2 LLC/SNAP header:\n");
  4158. printk(KERN_DEBUG " DSAP = 0x%02x\n", frame->p8022.dsap);
  4159. printk(KERN_DEBUG " SSAP = 0x%02x\n", frame->p8022.ssap);
  4160. printk(KERN_DEBUG " ctrl = 0x%02x\n", frame->p8022.ctrl);
  4161. printk(KERN_DEBUG " OUI = %02x:%02x:%02x\n",
  4162. frame->p8022.oui[0], frame->p8022.oui[1], frame->p8022.oui[2]);
  4163. printk(KERN_DEBUG " ethertype = 0x%04x\n", frame->ethertype);
  4164. }
  4165. #endif /* 0 */
  4166. /********************************************************************/
  4167. /* Module initialization */
  4168. /********************************************************************/
  4169. EXPORT_SYMBOL(alloc_orinocodev);
  4170. EXPORT_SYMBOL(free_orinocodev);
  4171. EXPORT_SYMBOL(__orinoco_up);
  4172. EXPORT_SYMBOL(__orinoco_down);
  4173. EXPORT_SYMBOL(orinoco_reinit_firmware);
  4174. EXPORT_SYMBOL(orinoco_interrupt);
  4175. /* Can't be declared "const" or the whole __initdata section will
  4176. * become const */
  4177. static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION
  4178. " (David Gibson <hermes@gibson.dropbear.id.au>, "
  4179. "Pavel Roskin <proski@gnu.org>, et al)";
  4180. static int __init init_orinoco(void)
  4181. {
  4182. printk(KERN_DEBUG "%s\n", version);
  4183. return 0;
  4184. }
  4185. static void __exit exit_orinoco(void)
  4186. {
  4187. }
  4188. module_init(init_orinoco);
  4189. module_exit(exit_orinoco);