orinoco.c 125 KB

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