orinoco.c 120 KB

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