orinoco.c 135 KB

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