orinoco.c 120 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518
  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 = NULL;
  899. int offset = 4;
  900. int found = 0;
  901. u8 *buf;
  902. u16 len;
  903. /* Allocate buffer for scan results */
  904. buf = kmalloc(MAX_SCAN_LEN, GFP_KERNEL);
  905. if (! buf)
  906. return;
  907. if (orinoco_lock(priv, &flags) != 0)
  908. goto out;
  909. /* Sanity checks in case user changed something in the meantime */
  910. if (! priv->bssid_fixed)
  911. goto out;
  912. if (strlen(priv->desired_essid) == 0)
  913. goto out;
  914. /* Read scan results from the firmware */
  915. err = hermes_read_ltv(hw, USER_BAP,
  916. HERMES_RID_SCANRESULTSTABLE,
  917. MAX_SCAN_LEN, &len, buf);
  918. if (err) {
  919. printk(KERN_ERR "%s: Cannot read scan results\n",
  920. dev->name);
  921. goto out;
  922. }
  923. len = HERMES_RECLEN_TO_BYTES(len);
  924. /* Go through the scan results looking for the channel of the AP
  925. * we were requested to join */
  926. for (; offset + atom_len <= len; offset += atom_len) {
  927. atom = (struct prism2_scan_apinfo *) (buf + offset);
  928. if (memcmp(&atom->bssid, priv->desired_bssid, ETH_ALEN) == 0) {
  929. found = 1;
  930. break;
  931. }
  932. }
  933. if (! found) {
  934. DEBUG(1, "%s: Requested AP not found in scan results\n",
  935. dev->name);
  936. goto out;
  937. }
  938. memcpy(req.bssid, priv->desired_bssid, ETH_ALEN);
  939. req.channel = atom->channel; /* both are little-endian */
  940. err = HERMES_WRITE_RECORD(hw, USER_BAP, HERMES_RID_CNFJOINREQUEST,
  941. &req);
  942. if (err)
  943. printk(KERN_ERR "%s: Error issuing join request\n", dev->name);
  944. out:
  945. kfree(buf);
  946. orinoco_unlock(priv, &flags);
  947. }
  948. /* Send new BSSID to userspace */
  949. static void orinoco_send_wevents(struct net_device *dev)
  950. {
  951. struct orinoco_private *priv = netdev_priv(dev);
  952. struct hermes *hw = &priv->hw;
  953. union iwreq_data wrqu;
  954. int err;
  955. unsigned long flags;
  956. if (orinoco_lock(priv, &flags) != 0)
  957. return;
  958. err = hermes_read_ltv(hw, IRQ_BAP, HERMES_RID_CURRENTBSSID,
  959. ETH_ALEN, NULL, wrqu.ap_addr.sa_data);
  960. if (err != 0)
  961. return;
  962. wrqu.ap_addr.sa_family = ARPHRD_ETHER;
  963. /* Send event to user space */
  964. wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL);
  965. orinoco_unlock(priv, &flags);
  966. }
  967. static void __orinoco_ev_info(struct net_device *dev, hermes_t *hw)
  968. {
  969. struct orinoco_private *priv = netdev_priv(dev);
  970. u16 infofid;
  971. struct {
  972. u16 len;
  973. u16 type;
  974. } __attribute__ ((packed)) info;
  975. int len, type;
  976. int err;
  977. /* This is an answer to an INQUIRE command that we did earlier,
  978. * or an information "event" generated by the card
  979. * The controller return to us a pseudo frame containing
  980. * the information in question - Jean II */
  981. infofid = hermes_read_regn(hw, INFOFID);
  982. /* Read the info frame header - don't try too hard */
  983. err = hermes_bap_pread(hw, IRQ_BAP, &info, sizeof(info),
  984. infofid, 0);
  985. if (err) {
  986. printk(KERN_ERR "%s: error %d reading info frame. "
  987. "Frame dropped.\n", dev->name, err);
  988. return;
  989. }
  990. len = HERMES_RECLEN_TO_BYTES(le16_to_cpu(info.len));
  991. type = le16_to_cpu(info.type);
  992. switch (type) {
  993. case HERMES_INQ_TALLIES: {
  994. struct hermes_tallies_frame tallies;
  995. struct iw_statistics *wstats = &priv->wstats;
  996. if (len > sizeof(tallies)) {
  997. printk(KERN_WARNING "%s: Tallies frame too long (%d bytes)\n",
  998. dev->name, len);
  999. len = sizeof(tallies);
  1000. }
  1001. err = hermes_bap_pread(hw, IRQ_BAP, &tallies, len,
  1002. infofid, sizeof(info));
  1003. if (err)
  1004. break;
  1005. /* Increment our various counters */
  1006. /* wstats->discard.nwid - no wrong BSSID stuff */
  1007. wstats->discard.code +=
  1008. le16_to_cpu(tallies.RxWEPUndecryptable);
  1009. if (len == sizeof(tallies))
  1010. wstats->discard.code +=
  1011. le16_to_cpu(tallies.RxDiscards_WEPICVError) +
  1012. le16_to_cpu(tallies.RxDiscards_WEPExcluded);
  1013. wstats->discard.misc +=
  1014. le16_to_cpu(tallies.TxDiscardsWrongSA);
  1015. wstats->discard.fragment +=
  1016. le16_to_cpu(tallies.RxMsgInBadMsgFragments);
  1017. wstats->discard.retries +=
  1018. le16_to_cpu(tallies.TxRetryLimitExceeded);
  1019. /* wstats->miss.beacon - no match */
  1020. }
  1021. break;
  1022. case HERMES_INQ_LINKSTATUS: {
  1023. struct hermes_linkstatus linkstatus;
  1024. u16 newstatus;
  1025. int connected;
  1026. if (priv->iw_mode == IW_MODE_MONITOR)
  1027. break;
  1028. if (len != sizeof(linkstatus)) {
  1029. printk(KERN_WARNING "%s: Unexpected size for linkstatus frame (%d bytes)\n",
  1030. dev->name, len);
  1031. break;
  1032. }
  1033. err = hermes_bap_pread(hw, IRQ_BAP, &linkstatus, len,
  1034. infofid, sizeof(info));
  1035. if (err)
  1036. break;
  1037. newstatus = le16_to_cpu(linkstatus.linkstatus);
  1038. /* Symbol firmware uses "out of range" to signal that
  1039. * the hostscan frame can be requested. */
  1040. if (newstatus == HERMES_LINKSTATUS_AP_OUT_OF_RANGE &&
  1041. priv->firmware_type == FIRMWARE_TYPE_SYMBOL &&
  1042. priv->has_hostscan && priv->scan_inprogress) {
  1043. hermes_inquire(hw, HERMES_INQ_HOSTSCAN_SYMBOL);
  1044. break;
  1045. }
  1046. connected = (newstatus == HERMES_LINKSTATUS_CONNECTED)
  1047. || (newstatus == HERMES_LINKSTATUS_AP_CHANGE)
  1048. || (newstatus == HERMES_LINKSTATUS_AP_IN_RANGE);
  1049. if (connected)
  1050. netif_carrier_on(dev);
  1051. else if (!ignore_disconnect)
  1052. netif_carrier_off(dev);
  1053. if (newstatus != priv->last_linkstatus) {
  1054. priv->last_linkstatus = newstatus;
  1055. print_linkstatus(dev, newstatus);
  1056. /* The info frame contains only one word which is the
  1057. * status (see hermes.h). The status is pretty boring
  1058. * in itself, that's why we export the new BSSID...
  1059. * Jean II */
  1060. schedule_work(&priv->wevent_work);
  1061. }
  1062. }
  1063. break;
  1064. case HERMES_INQ_SCAN:
  1065. if (!priv->scan_inprogress && priv->bssid_fixed &&
  1066. priv->firmware_type == FIRMWARE_TYPE_INTERSIL) {
  1067. schedule_work(&priv->join_work);
  1068. break;
  1069. }
  1070. /* fall through */
  1071. case HERMES_INQ_HOSTSCAN:
  1072. case HERMES_INQ_HOSTSCAN_SYMBOL: {
  1073. /* Result of a scanning. Contains information about
  1074. * cells in the vicinity - Jean II */
  1075. union iwreq_data wrqu;
  1076. unsigned char *buf;
  1077. /* Sanity check */
  1078. if (len > 4096) {
  1079. printk(KERN_WARNING "%s: Scan results too large (%d bytes)\n",
  1080. dev->name, len);
  1081. break;
  1082. }
  1083. /* We are a strict producer. If the previous scan results
  1084. * have not been consumed, we just have to drop this
  1085. * frame. We can't remove the previous results ourselves,
  1086. * that would be *very* racy... Jean II */
  1087. if (priv->scan_result != NULL) {
  1088. printk(KERN_WARNING "%s: Previous scan results not consumed, dropping info frame.\n", dev->name);
  1089. break;
  1090. }
  1091. /* Allocate buffer for results */
  1092. buf = kmalloc(len, GFP_ATOMIC);
  1093. if (buf == NULL)
  1094. /* No memory, so can't printk()... */
  1095. break;
  1096. /* Read scan data */
  1097. err = hermes_bap_pread(hw, IRQ_BAP, (void *) buf, len,
  1098. infofid, sizeof(info));
  1099. if (err) {
  1100. kfree(buf);
  1101. break;
  1102. }
  1103. #ifdef ORINOCO_DEBUG
  1104. {
  1105. int i;
  1106. printk(KERN_DEBUG "Scan result [%02X", buf[0]);
  1107. for(i = 1; i < (len * 2); i++)
  1108. printk(":%02X", buf[i]);
  1109. printk("]\n");
  1110. }
  1111. #endif /* ORINOCO_DEBUG */
  1112. /* Allow the clients to access the results */
  1113. priv->scan_len = len;
  1114. priv->scan_result = buf;
  1115. /* Send an empty event to user space.
  1116. * We don't send the received data on the event because
  1117. * it would require us to do complex transcoding, and
  1118. * we want to minimise the work done in the irq handler
  1119. * Use a request to extract the data - Jean II */
  1120. wrqu.data.length = 0;
  1121. wrqu.data.flags = 0;
  1122. wireless_send_event(dev, SIOCGIWSCAN, &wrqu, NULL);
  1123. }
  1124. break;
  1125. case HERMES_INQ_SEC_STAT_AGERE:
  1126. /* Security status (Agere specific) */
  1127. /* Ignore this frame for now */
  1128. if (priv->firmware_type == FIRMWARE_TYPE_AGERE)
  1129. break;
  1130. /* fall through */
  1131. default:
  1132. printk(KERN_DEBUG "%s: Unknown information frame received: "
  1133. "type 0x%04x, length %d\n", dev->name, type, len);
  1134. /* We don't actually do anything about it */
  1135. break;
  1136. }
  1137. }
  1138. static void __orinoco_ev_infdrop(struct net_device *dev, hermes_t *hw)
  1139. {
  1140. if (net_ratelimit())
  1141. printk(KERN_DEBUG "%s: Information frame lost.\n", dev->name);
  1142. }
  1143. /********************************************************************/
  1144. /* Internal hardware control routines */
  1145. /********************************************************************/
  1146. int __orinoco_up(struct net_device *dev)
  1147. {
  1148. struct orinoco_private *priv = netdev_priv(dev);
  1149. struct hermes *hw = &priv->hw;
  1150. int err;
  1151. netif_carrier_off(dev); /* just to make sure */
  1152. err = __orinoco_program_rids(dev);
  1153. if (err) {
  1154. printk(KERN_ERR "%s: Error %d configuring card\n",
  1155. dev->name, err);
  1156. return err;
  1157. }
  1158. /* Fire things up again */
  1159. hermes_set_irqmask(hw, ORINOCO_INTEN);
  1160. err = hermes_enable_port(hw, 0);
  1161. if (err) {
  1162. printk(KERN_ERR "%s: Error %d enabling MAC port\n",
  1163. dev->name, err);
  1164. return err;
  1165. }
  1166. netif_start_queue(dev);
  1167. return 0;
  1168. }
  1169. int __orinoco_down(struct net_device *dev)
  1170. {
  1171. struct orinoco_private *priv = netdev_priv(dev);
  1172. struct hermes *hw = &priv->hw;
  1173. int err;
  1174. netif_stop_queue(dev);
  1175. if (! priv->hw_unavailable) {
  1176. if (! priv->broken_disableport) {
  1177. err = hermes_disable_port(hw, 0);
  1178. if (err) {
  1179. /* Some firmwares (e.g. Intersil 1.3.x) seem
  1180. * to have problems disabling the port, oh
  1181. * well, too bad. */
  1182. printk(KERN_WARNING "%s: Error %d disabling MAC port\n",
  1183. dev->name, err);
  1184. priv->broken_disableport = 1;
  1185. }
  1186. }
  1187. hermes_set_irqmask(hw, 0);
  1188. hermes_write_regn(hw, EVACK, 0xffff);
  1189. }
  1190. /* firmware will have to reassociate */
  1191. netif_carrier_off(dev);
  1192. priv->last_linkstatus = 0xffff;
  1193. return 0;
  1194. }
  1195. int orinoco_reinit_firmware(struct net_device *dev)
  1196. {
  1197. struct orinoco_private *priv = netdev_priv(dev);
  1198. struct hermes *hw = &priv->hw;
  1199. int err;
  1200. err = hermes_init(hw);
  1201. if (err)
  1202. return err;
  1203. err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid);
  1204. if (err == -EIO && priv->nicbuf_size > TX_NICBUF_SIZE_BUG) {
  1205. /* Try workaround for old Symbol firmware bug */
  1206. printk(KERN_WARNING "%s: firmware ALLOC bug detected "
  1207. "(old Symbol firmware?). Trying to work around... ",
  1208. dev->name);
  1209. priv->nicbuf_size = TX_NICBUF_SIZE_BUG;
  1210. err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid);
  1211. if (err)
  1212. printk("failed!\n");
  1213. else
  1214. printk("ok.\n");
  1215. }
  1216. return err;
  1217. }
  1218. static int __orinoco_hw_set_bitrate(struct orinoco_private *priv)
  1219. {
  1220. hermes_t *hw = &priv->hw;
  1221. int err = 0;
  1222. if (priv->bitratemode >= BITRATE_TABLE_SIZE) {
  1223. printk(KERN_ERR "%s: BUG: Invalid bitrate mode %d\n",
  1224. priv->ndev->name, priv->bitratemode);
  1225. return -EINVAL;
  1226. }
  1227. switch (priv->firmware_type) {
  1228. case FIRMWARE_TYPE_AGERE:
  1229. err = hermes_write_wordrec(hw, USER_BAP,
  1230. HERMES_RID_CNFTXRATECONTROL,
  1231. bitrate_table[priv->bitratemode].agere_txratectrl);
  1232. break;
  1233. case FIRMWARE_TYPE_INTERSIL:
  1234. case FIRMWARE_TYPE_SYMBOL:
  1235. err = hermes_write_wordrec(hw, USER_BAP,
  1236. HERMES_RID_CNFTXRATECONTROL,
  1237. bitrate_table[priv->bitratemode].intersil_txratectrl);
  1238. break;
  1239. default:
  1240. BUG();
  1241. }
  1242. return err;
  1243. }
  1244. /* Set fixed AP address */
  1245. static int __orinoco_hw_set_wap(struct orinoco_private *priv)
  1246. {
  1247. int roaming_flag;
  1248. int err = 0;
  1249. hermes_t *hw = &priv->hw;
  1250. switch (priv->firmware_type) {
  1251. case FIRMWARE_TYPE_AGERE:
  1252. /* not supported */
  1253. break;
  1254. case FIRMWARE_TYPE_INTERSIL:
  1255. if (priv->bssid_fixed)
  1256. roaming_flag = 2;
  1257. else
  1258. roaming_flag = 1;
  1259. err = hermes_write_wordrec(hw, USER_BAP,
  1260. HERMES_RID_CNFROAMINGMODE,
  1261. roaming_flag);
  1262. break;
  1263. case FIRMWARE_TYPE_SYMBOL:
  1264. err = HERMES_WRITE_RECORD(hw, USER_BAP,
  1265. HERMES_RID_CNFMANDATORYBSSID_SYMBOL,
  1266. &priv->desired_bssid);
  1267. break;
  1268. }
  1269. return err;
  1270. }
  1271. /* Change the WEP keys and/or the current keys. Can be called
  1272. * either from __orinoco_hw_setup_wep() or directly from
  1273. * orinoco_ioctl_setiwencode(). In the later case the association
  1274. * with the AP is not broken (if the firmware can handle it),
  1275. * which is needed for 802.1x implementations. */
  1276. static int __orinoco_hw_setup_wepkeys(struct orinoco_private *priv)
  1277. {
  1278. hermes_t *hw = &priv->hw;
  1279. int err = 0;
  1280. switch (priv->firmware_type) {
  1281. case FIRMWARE_TYPE_AGERE:
  1282. err = HERMES_WRITE_RECORD(hw, USER_BAP,
  1283. HERMES_RID_CNFWEPKEYS_AGERE,
  1284. &priv->keys);
  1285. if (err)
  1286. return err;
  1287. err = hermes_write_wordrec(hw, USER_BAP,
  1288. HERMES_RID_CNFTXKEY_AGERE,
  1289. priv->tx_key);
  1290. if (err)
  1291. return err;
  1292. break;
  1293. case FIRMWARE_TYPE_INTERSIL:
  1294. case FIRMWARE_TYPE_SYMBOL:
  1295. {
  1296. int keylen;
  1297. int i;
  1298. /* Force uniform key length to work around firmware bugs */
  1299. keylen = le16_to_cpu(priv->keys[priv->tx_key].len);
  1300. if (keylen > LARGE_KEY_SIZE) {
  1301. printk(KERN_ERR "%s: BUG: Key %d has oversize length %d.\n",
  1302. priv->ndev->name, priv->tx_key, keylen);
  1303. return -E2BIG;
  1304. }
  1305. /* Write all 4 keys */
  1306. for(i = 0; i < ORINOCO_MAX_KEYS; i++) {
  1307. err = hermes_write_ltv(hw, USER_BAP,
  1308. HERMES_RID_CNFDEFAULTKEY0 + i,
  1309. HERMES_BYTES_TO_RECLEN(keylen),
  1310. priv->keys[i].data);
  1311. if (err)
  1312. return err;
  1313. }
  1314. /* Write the index of the key used in transmission */
  1315. err = hermes_write_wordrec(hw, USER_BAP,
  1316. HERMES_RID_CNFWEPDEFAULTKEYID,
  1317. priv->tx_key);
  1318. if (err)
  1319. return err;
  1320. }
  1321. break;
  1322. }
  1323. return 0;
  1324. }
  1325. static int __orinoco_hw_setup_wep(struct orinoco_private *priv)
  1326. {
  1327. hermes_t *hw = &priv->hw;
  1328. int err = 0;
  1329. int master_wep_flag;
  1330. int auth_flag;
  1331. if (priv->wep_on)
  1332. __orinoco_hw_setup_wepkeys(priv);
  1333. if (priv->wep_restrict)
  1334. auth_flag = HERMES_AUTH_SHARED_KEY;
  1335. else
  1336. auth_flag = HERMES_AUTH_OPEN;
  1337. switch (priv->firmware_type) {
  1338. case FIRMWARE_TYPE_AGERE: /* Agere style WEP */
  1339. if (priv->wep_on) {
  1340. /* Enable the shared-key authentication. */
  1341. err = hermes_write_wordrec(hw, USER_BAP,
  1342. HERMES_RID_CNFAUTHENTICATION_AGERE,
  1343. auth_flag);
  1344. }
  1345. err = hermes_write_wordrec(hw, USER_BAP,
  1346. HERMES_RID_CNFWEPENABLED_AGERE,
  1347. priv->wep_on);
  1348. if (err)
  1349. return err;
  1350. break;
  1351. case FIRMWARE_TYPE_INTERSIL: /* Intersil style WEP */
  1352. case FIRMWARE_TYPE_SYMBOL: /* Symbol style WEP */
  1353. if (priv->wep_on) {
  1354. if (priv->wep_restrict ||
  1355. (priv->firmware_type == FIRMWARE_TYPE_SYMBOL))
  1356. master_wep_flag = HERMES_WEP_PRIVACY_INVOKED |
  1357. HERMES_WEP_EXCL_UNENCRYPTED;
  1358. else
  1359. master_wep_flag = HERMES_WEP_PRIVACY_INVOKED;
  1360. err = hermes_write_wordrec(hw, USER_BAP,
  1361. HERMES_RID_CNFAUTHENTICATION,
  1362. auth_flag);
  1363. if (err)
  1364. return err;
  1365. } else
  1366. master_wep_flag = 0;
  1367. if (priv->iw_mode == IW_MODE_MONITOR)
  1368. master_wep_flag |= HERMES_WEP_HOST_DECRYPT;
  1369. /* Master WEP setting : on/off */
  1370. err = hermes_write_wordrec(hw, USER_BAP,
  1371. HERMES_RID_CNFWEPFLAGS_INTERSIL,
  1372. master_wep_flag);
  1373. if (err)
  1374. return err;
  1375. break;
  1376. }
  1377. return 0;
  1378. }
  1379. static int __orinoco_program_rids(struct net_device *dev)
  1380. {
  1381. struct orinoco_private *priv = netdev_priv(dev);
  1382. hermes_t *hw = &priv->hw;
  1383. int err;
  1384. struct hermes_idstring idbuf;
  1385. /* Set the MAC address */
  1386. err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNMACADDR,
  1387. HERMES_BYTES_TO_RECLEN(ETH_ALEN), dev->dev_addr);
  1388. if (err) {
  1389. printk(KERN_ERR "%s: Error %d setting MAC address\n",
  1390. dev->name, err);
  1391. return err;
  1392. }
  1393. /* Set up the link mode */
  1394. err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFPORTTYPE,
  1395. priv->port_type);
  1396. if (err) {
  1397. printk(KERN_ERR "%s: Error %d setting port type\n",
  1398. dev->name, err);
  1399. return err;
  1400. }
  1401. /* Set the channel/frequency */
  1402. if (priv->channel != 0 && priv->iw_mode != IW_MODE_INFRA) {
  1403. err = hermes_write_wordrec(hw, USER_BAP,
  1404. HERMES_RID_CNFOWNCHANNEL,
  1405. priv->channel);
  1406. if (err) {
  1407. printk(KERN_ERR "%s: Error %d setting channel %d\n",
  1408. dev->name, err, priv->channel);
  1409. return err;
  1410. }
  1411. }
  1412. if (priv->has_ibss) {
  1413. u16 createibss;
  1414. if ((strlen(priv->desired_essid) == 0) && (priv->createibss)) {
  1415. printk(KERN_WARNING "%s: This firmware requires an "
  1416. "ESSID in IBSS-Ad-Hoc mode.\n", dev->name);
  1417. /* With wvlan_cs, in this case, we would crash.
  1418. * hopefully, this driver will behave better...
  1419. * Jean II */
  1420. createibss = 0;
  1421. } else {
  1422. createibss = priv->createibss;
  1423. }
  1424. err = hermes_write_wordrec(hw, USER_BAP,
  1425. HERMES_RID_CNFCREATEIBSS,
  1426. createibss);
  1427. if (err) {
  1428. printk(KERN_ERR "%s: Error %d setting CREATEIBSS\n",
  1429. dev->name, err);
  1430. return err;
  1431. }
  1432. }
  1433. /* Set the desired BSSID */
  1434. err = __orinoco_hw_set_wap(priv);
  1435. if (err) {
  1436. printk(KERN_ERR "%s: Error %d setting AP address\n",
  1437. dev->name, err);
  1438. return err;
  1439. }
  1440. /* Set the desired ESSID */
  1441. idbuf.len = cpu_to_le16(strlen(priv->desired_essid));
  1442. memcpy(&idbuf.val, priv->desired_essid, sizeof(idbuf.val));
  1443. /* WinXP wants partner to configure OWNSSID even in IBSS mode. (jimc) */
  1444. err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNSSID,
  1445. HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid)+2),
  1446. &idbuf);
  1447. if (err) {
  1448. printk(KERN_ERR "%s: Error %d setting OWNSSID\n",
  1449. dev->name, err);
  1450. return err;
  1451. }
  1452. err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFDESIREDSSID,
  1453. HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid)+2),
  1454. &idbuf);
  1455. if (err) {
  1456. printk(KERN_ERR "%s: Error %d setting DESIREDSSID\n",
  1457. dev->name, err);
  1458. return err;
  1459. }
  1460. /* Set the station name */
  1461. idbuf.len = cpu_to_le16(strlen(priv->nick));
  1462. memcpy(&idbuf.val, priv->nick, sizeof(idbuf.val));
  1463. err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNNAME,
  1464. HERMES_BYTES_TO_RECLEN(strlen(priv->nick)+2),
  1465. &idbuf);
  1466. if (err) {
  1467. printk(KERN_ERR "%s: Error %d setting nickname\n",
  1468. dev->name, err);
  1469. return err;
  1470. }
  1471. /* Set AP density */
  1472. if (priv->has_sensitivity) {
  1473. err = hermes_write_wordrec(hw, USER_BAP,
  1474. HERMES_RID_CNFSYSTEMSCALE,
  1475. priv->ap_density);
  1476. if (err) {
  1477. printk(KERN_WARNING "%s: Error %d setting SYSTEMSCALE. "
  1478. "Disabling sensitivity control\n",
  1479. dev->name, err);
  1480. priv->has_sensitivity = 0;
  1481. }
  1482. }
  1483. /* Set RTS threshold */
  1484. err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFRTSTHRESHOLD,
  1485. priv->rts_thresh);
  1486. if (err) {
  1487. printk(KERN_ERR "%s: Error %d setting RTS threshold\n",
  1488. dev->name, err);
  1489. return err;
  1490. }
  1491. /* Set fragmentation threshold or MWO robustness */
  1492. if (priv->has_mwo)
  1493. err = hermes_write_wordrec(hw, USER_BAP,
  1494. HERMES_RID_CNFMWOROBUST_AGERE,
  1495. priv->mwo_robust);
  1496. else
  1497. err = hermes_write_wordrec(hw, USER_BAP,
  1498. HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
  1499. priv->frag_thresh);
  1500. if (err) {
  1501. printk(KERN_ERR "%s: Error %d setting fragmentation\n",
  1502. dev->name, err);
  1503. return err;
  1504. }
  1505. /* Set bitrate */
  1506. err = __orinoco_hw_set_bitrate(priv);
  1507. if (err) {
  1508. printk(KERN_ERR "%s: Error %d setting bitrate\n",
  1509. dev->name, err);
  1510. return err;
  1511. }
  1512. /* Set power management */
  1513. if (priv->has_pm) {
  1514. err = hermes_write_wordrec(hw, USER_BAP,
  1515. HERMES_RID_CNFPMENABLED,
  1516. priv->pm_on);
  1517. if (err) {
  1518. printk(KERN_ERR "%s: Error %d setting up PM\n",
  1519. dev->name, err);
  1520. return err;
  1521. }
  1522. err = hermes_write_wordrec(hw, USER_BAP,
  1523. HERMES_RID_CNFMULTICASTRECEIVE,
  1524. priv->pm_mcast);
  1525. if (err) {
  1526. printk(KERN_ERR "%s: Error %d setting up PM\n",
  1527. dev->name, err);
  1528. return err;
  1529. }
  1530. err = hermes_write_wordrec(hw, USER_BAP,
  1531. HERMES_RID_CNFMAXSLEEPDURATION,
  1532. priv->pm_period);
  1533. if (err) {
  1534. printk(KERN_ERR "%s: Error %d setting up PM\n",
  1535. dev->name, err);
  1536. return err;
  1537. }
  1538. err = hermes_write_wordrec(hw, USER_BAP,
  1539. HERMES_RID_CNFPMHOLDOVERDURATION,
  1540. priv->pm_timeout);
  1541. if (err) {
  1542. printk(KERN_ERR "%s: Error %d setting up PM\n",
  1543. dev->name, err);
  1544. return err;
  1545. }
  1546. }
  1547. /* Set preamble - only for Symbol so far... */
  1548. if (priv->has_preamble) {
  1549. err = hermes_write_wordrec(hw, USER_BAP,
  1550. HERMES_RID_CNFPREAMBLE_SYMBOL,
  1551. priv->preamble);
  1552. if (err) {
  1553. printk(KERN_ERR "%s: Error %d setting preamble\n",
  1554. dev->name, err);
  1555. return err;
  1556. }
  1557. }
  1558. /* Set up encryption */
  1559. if (priv->has_wep) {
  1560. err = __orinoco_hw_setup_wep(priv);
  1561. if (err) {
  1562. printk(KERN_ERR "%s: Error %d activating WEP\n",
  1563. dev->name, err);
  1564. return err;
  1565. }
  1566. }
  1567. if (priv->iw_mode == IW_MODE_MONITOR) {
  1568. /* Enable monitor mode */
  1569. dev->type = ARPHRD_IEEE80211;
  1570. err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
  1571. HERMES_TEST_MONITOR, 0, NULL);
  1572. } else {
  1573. /* Disable monitor mode */
  1574. dev->type = ARPHRD_ETHER;
  1575. err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
  1576. HERMES_TEST_STOP, 0, NULL);
  1577. }
  1578. if (err)
  1579. return err;
  1580. /* Set promiscuity / multicast*/
  1581. priv->promiscuous = 0;
  1582. priv->mc_count = 0;
  1583. __orinoco_set_multicast_list(dev); /* FIXME: what about the xmit_lock */
  1584. return 0;
  1585. }
  1586. /* FIXME: return int? */
  1587. static void
  1588. __orinoco_set_multicast_list(struct net_device *dev)
  1589. {
  1590. struct orinoco_private *priv = netdev_priv(dev);
  1591. hermes_t *hw = &priv->hw;
  1592. int err = 0;
  1593. int promisc, mc_count;
  1594. /* The Hermes doesn't seem to have an allmulti mode, so we go
  1595. * into promiscuous mode and let the upper levels deal. */
  1596. if ( (dev->flags & IFF_PROMISC) || (dev->flags & IFF_ALLMULTI) ||
  1597. (dev->mc_count > MAX_MULTICAST(priv)) ) {
  1598. promisc = 1;
  1599. mc_count = 0;
  1600. } else {
  1601. promisc = 0;
  1602. mc_count = dev->mc_count;
  1603. }
  1604. if (promisc != priv->promiscuous) {
  1605. err = hermes_write_wordrec(hw, USER_BAP,
  1606. HERMES_RID_CNFPROMISCUOUSMODE,
  1607. promisc);
  1608. if (err) {
  1609. printk(KERN_ERR "%s: Error %d setting PROMISCUOUSMODE to 1.\n",
  1610. dev->name, err);
  1611. } else
  1612. priv->promiscuous = promisc;
  1613. }
  1614. if (! promisc && (mc_count || priv->mc_count) ) {
  1615. struct dev_mc_list *p = dev->mc_list;
  1616. struct hermes_multicast mclist;
  1617. int i;
  1618. for (i = 0; i < mc_count; i++) {
  1619. /* paranoia: is list shorter than mc_count? */
  1620. BUG_ON(! p);
  1621. /* paranoia: bad address size in list? */
  1622. BUG_ON(p->dmi_addrlen != ETH_ALEN);
  1623. memcpy(mclist.addr[i], p->dmi_addr, ETH_ALEN);
  1624. p = p->next;
  1625. }
  1626. if (p)
  1627. printk(KERN_WARNING "%s: Multicast list is "
  1628. "longer than mc_count\n", dev->name);
  1629. err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFGROUPADDRESSES,
  1630. HERMES_BYTES_TO_RECLEN(priv->mc_count * ETH_ALEN),
  1631. &mclist);
  1632. if (err)
  1633. printk(KERN_ERR "%s: Error %d setting multicast list.\n",
  1634. dev->name, err);
  1635. else
  1636. priv->mc_count = mc_count;
  1637. }
  1638. /* Since we can set the promiscuous flag when it wasn't asked
  1639. for, make sure the net_device knows about it. */
  1640. if (priv->promiscuous)
  1641. dev->flags |= IFF_PROMISC;
  1642. else
  1643. dev->flags &= ~IFF_PROMISC;
  1644. }
  1645. /* This must be called from user context, without locks held - use
  1646. * schedule_work() */
  1647. static void orinoco_reset(struct net_device *dev)
  1648. {
  1649. struct orinoco_private *priv = netdev_priv(dev);
  1650. struct hermes *hw = &priv->hw;
  1651. int err;
  1652. unsigned long flags;
  1653. if (orinoco_lock(priv, &flags) != 0)
  1654. /* When the hardware becomes available again, whatever
  1655. * detects that is responsible for re-initializing
  1656. * it. So no need for anything further */
  1657. return;
  1658. netif_stop_queue(dev);
  1659. /* Shut off interrupts. Depending on what state the hardware
  1660. * is in, this might not work, but we'll try anyway */
  1661. hermes_set_irqmask(hw, 0);
  1662. hermes_write_regn(hw, EVACK, 0xffff);
  1663. priv->hw_unavailable++;
  1664. priv->last_linkstatus = 0xffff; /* firmware will have to reassociate */
  1665. netif_carrier_off(dev);
  1666. orinoco_unlock(priv, &flags);
  1667. /* Scanning support: Cleanup of driver struct */
  1668. kfree(priv->scan_result);
  1669. priv->scan_result = NULL;
  1670. priv->scan_inprogress = 0;
  1671. if (priv->hard_reset) {
  1672. err = (*priv->hard_reset)(priv);
  1673. if (err) {
  1674. printk(KERN_ERR "%s: orinoco_reset: Error %d "
  1675. "performing hard reset\n", dev->name, err);
  1676. goto disable;
  1677. }
  1678. }
  1679. err = orinoco_reinit_firmware(dev);
  1680. if (err) {
  1681. printk(KERN_ERR "%s: orinoco_reset: Error %d re-initializing firmware\n",
  1682. dev->name, err);
  1683. goto disable;
  1684. }
  1685. spin_lock_irq(&priv->lock); /* This has to be called from user context */
  1686. priv->hw_unavailable--;
  1687. /* priv->open or priv->hw_unavailable might have changed while
  1688. * we dropped the lock */
  1689. if (priv->open && (! priv->hw_unavailable)) {
  1690. err = __orinoco_up(dev);
  1691. if (err) {
  1692. printk(KERN_ERR "%s: orinoco_reset: Error %d reenabling card\n",
  1693. dev->name, err);
  1694. } else
  1695. dev->trans_start = jiffies;
  1696. }
  1697. spin_unlock_irq(&priv->lock);
  1698. return;
  1699. disable:
  1700. hermes_set_irqmask(hw, 0);
  1701. netif_device_detach(dev);
  1702. printk(KERN_ERR "%s: Device has been disabled!\n", dev->name);
  1703. }
  1704. /********************************************************************/
  1705. /* Interrupt handler */
  1706. /********************************************************************/
  1707. static void __orinoco_ev_tick(struct net_device *dev, hermes_t *hw)
  1708. {
  1709. printk(KERN_DEBUG "%s: TICK\n", dev->name);
  1710. }
  1711. static void __orinoco_ev_wterr(struct net_device *dev, hermes_t *hw)
  1712. {
  1713. /* This seems to happen a fair bit under load, but ignoring it
  1714. seems to work fine...*/
  1715. printk(KERN_DEBUG "%s: MAC controller error (WTERR). Ignoring.\n",
  1716. dev->name);
  1717. }
  1718. irqreturn_t orinoco_interrupt(int irq, void *dev_id, struct pt_regs *regs)
  1719. {
  1720. struct net_device *dev = (struct net_device *)dev_id;
  1721. struct orinoco_private *priv = netdev_priv(dev);
  1722. hermes_t *hw = &priv->hw;
  1723. int count = MAX_IRQLOOPS_PER_IRQ;
  1724. u16 evstat, events;
  1725. /* These are used to detect a runaway interrupt situation */
  1726. /* If we get more than MAX_IRQLOOPS_PER_JIFFY iterations in a jiffy,
  1727. * we panic and shut down the hardware */
  1728. static int last_irq_jiffy = 0; /* jiffies value the last time
  1729. * we were called */
  1730. static int loops_this_jiffy = 0;
  1731. unsigned long flags;
  1732. if (orinoco_lock(priv, &flags) != 0) {
  1733. /* If hw is unavailable - we don't know if the irq was
  1734. * for us or not */
  1735. return IRQ_HANDLED;
  1736. }
  1737. evstat = hermes_read_regn(hw, EVSTAT);
  1738. events = evstat & hw->inten;
  1739. if (! events) {
  1740. orinoco_unlock(priv, &flags);
  1741. return IRQ_NONE;
  1742. }
  1743. if (jiffies != last_irq_jiffy)
  1744. loops_this_jiffy = 0;
  1745. last_irq_jiffy = jiffies;
  1746. while (events && count--) {
  1747. if (++loops_this_jiffy > MAX_IRQLOOPS_PER_JIFFY) {
  1748. printk(KERN_WARNING "%s: IRQ handler is looping too "
  1749. "much! Resetting.\n", dev->name);
  1750. /* Disable interrupts for now */
  1751. hermes_set_irqmask(hw, 0);
  1752. schedule_work(&priv->reset_work);
  1753. break;
  1754. }
  1755. /* Check the card hasn't been removed */
  1756. if (! hermes_present(hw)) {
  1757. DEBUG(0, "orinoco_interrupt(): card removed\n");
  1758. break;
  1759. }
  1760. if (events & HERMES_EV_TICK)
  1761. __orinoco_ev_tick(dev, hw);
  1762. if (events & HERMES_EV_WTERR)
  1763. __orinoco_ev_wterr(dev, hw);
  1764. if (events & HERMES_EV_INFDROP)
  1765. __orinoco_ev_infdrop(dev, hw);
  1766. if (events & HERMES_EV_INFO)
  1767. __orinoco_ev_info(dev, hw);
  1768. if (events & HERMES_EV_RX)
  1769. __orinoco_ev_rx(dev, hw);
  1770. if (events & HERMES_EV_TXEXC)
  1771. __orinoco_ev_txexc(dev, hw);
  1772. if (events & HERMES_EV_TX)
  1773. __orinoco_ev_tx(dev, hw);
  1774. if (events & HERMES_EV_ALLOC)
  1775. __orinoco_ev_alloc(dev, hw);
  1776. hermes_write_regn(hw, EVACK, evstat);
  1777. evstat = hermes_read_regn(hw, EVSTAT);
  1778. events = evstat & hw->inten;
  1779. };
  1780. orinoco_unlock(priv, &flags);
  1781. return IRQ_HANDLED;
  1782. }
  1783. /********************************************************************/
  1784. /* Initialization */
  1785. /********************************************************************/
  1786. struct comp_id {
  1787. u16 id, variant, major, minor;
  1788. } __attribute__ ((packed));
  1789. static inline fwtype_t determine_firmware_type(struct comp_id *nic_id)
  1790. {
  1791. if (nic_id->id < 0x8000)
  1792. return FIRMWARE_TYPE_AGERE;
  1793. else if (nic_id->id == 0x8000 && nic_id->major == 0)
  1794. return FIRMWARE_TYPE_SYMBOL;
  1795. else
  1796. return FIRMWARE_TYPE_INTERSIL;
  1797. }
  1798. /* Set priv->firmware type, determine firmware properties */
  1799. static int determine_firmware(struct net_device *dev)
  1800. {
  1801. struct orinoco_private *priv = netdev_priv(dev);
  1802. hermes_t *hw = &priv->hw;
  1803. int err;
  1804. struct comp_id nic_id, sta_id;
  1805. unsigned int firmver;
  1806. char tmp[SYMBOL_MAX_VER_LEN+1];
  1807. /* Get the hardware version */
  1808. err = HERMES_READ_RECORD(hw, USER_BAP, HERMES_RID_NICID, &nic_id);
  1809. if (err) {
  1810. printk(KERN_ERR "%s: Cannot read hardware identity: error %d\n",
  1811. dev->name, err);
  1812. return err;
  1813. }
  1814. le16_to_cpus(&nic_id.id);
  1815. le16_to_cpus(&nic_id.variant);
  1816. le16_to_cpus(&nic_id.major);
  1817. le16_to_cpus(&nic_id.minor);
  1818. printk(KERN_DEBUG "%s: Hardware identity %04x:%04x:%04x:%04x\n",
  1819. dev->name, nic_id.id, nic_id.variant,
  1820. nic_id.major, nic_id.minor);
  1821. priv->firmware_type = determine_firmware_type(&nic_id);
  1822. /* Get the firmware version */
  1823. err = HERMES_READ_RECORD(hw, USER_BAP, HERMES_RID_STAID, &sta_id);
  1824. if (err) {
  1825. printk(KERN_ERR "%s: Cannot read station identity: error %d\n",
  1826. dev->name, err);
  1827. return err;
  1828. }
  1829. le16_to_cpus(&sta_id.id);
  1830. le16_to_cpus(&sta_id.variant);
  1831. le16_to_cpus(&sta_id.major);
  1832. le16_to_cpus(&sta_id.minor);
  1833. printk(KERN_DEBUG "%s: Station identity %04x:%04x:%04x:%04x\n",
  1834. dev->name, sta_id.id, sta_id.variant,
  1835. sta_id.major, sta_id.minor);
  1836. switch (sta_id.id) {
  1837. case 0x15:
  1838. printk(KERN_ERR "%s: Primary firmware is active\n",
  1839. dev->name);
  1840. return -ENODEV;
  1841. case 0x14b:
  1842. printk(KERN_ERR "%s: Tertiary firmware is active\n",
  1843. dev->name);
  1844. return -ENODEV;
  1845. case 0x1f: /* Intersil, Agere, Symbol Spectrum24 */
  1846. case 0x21: /* Symbol Spectrum24 Trilogy */
  1847. break;
  1848. default:
  1849. printk(KERN_NOTICE "%s: Unknown station ID, please report\n",
  1850. dev->name);
  1851. break;
  1852. }
  1853. /* Default capabilities */
  1854. priv->has_sensitivity = 1;
  1855. priv->has_mwo = 0;
  1856. priv->has_preamble = 0;
  1857. priv->has_port3 = 1;
  1858. priv->has_ibss = 1;
  1859. priv->has_wep = 0;
  1860. priv->has_big_wep = 0;
  1861. /* Determine capabilities from the firmware version */
  1862. switch (priv->firmware_type) {
  1863. case FIRMWARE_TYPE_AGERE:
  1864. /* Lucent Wavelan IEEE, Lucent Orinoco, Cabletron RoamAbout,
  1865. ELSA, Melco, HP, IBM, Dell 1150, Compaq 110/210 */
  1866. snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
  1867. "Lucent/Agere %d.%02d", sta_id.major, sta_id.minor);
  1868. firmver = ((unsigned long)sta_id.major << 16) | sta_id.minor;
  1869. priv->has_ibss = (firmver >= 0x60006);
  1870. priv->has_wep = (firmver >= 0x40020);
  1871. priv->has_big_wep = 1; /* FIXME: this is wrong - how do we tell
  1872. Gold cards from the others? */
  1873. priv->has_mwo = (firmver >= 0x60000);
  1874. priv->has_pm = (firmver >= 0x40020); /* Don't work in 7.52 ? */
  1875. priv->ibss_port = 1;
  1876. priv->has_hostscan = (firmver >= 0x8000a);
  1877. priv->broken_monitor = (firmver >= 0x80000);
  1878. /* Tested with Agere firmware :
  1879. * 1.16 ; 4.08 ; 4.52 ; 6.04 ; 6.16 ; 7.28 => Jean II
  1880. * Tested CableTron firmware : 4.32 => Anton */
  1881. break;
  1882. case FIRMWARE_TYPE_SYMBOL:
  1883. /* Symbol , 3Com AirConnect, Intel, Ericsson WLAN */
  1884. /* Intel MAC : 00:02:B3:* */
  1885. /* 3Com MAC : 00:50:DA:* */
  1886. memset(tmp, 0, sizeof(tmp));
  1887. /* Get the Symbol firmware version */
  1888. err = hermes_read_ltv(hw, USER_BAP,
  1889. HERMES_RID_SECONDARYVERSION_SYMBOL,
  1890. SYMBOL_MAX_VER_LEN, NULL, &tmp);
  1891. if (err) {
  1892. printk(KERN_WARNING
  1893. "%s: Error %d reading Symbol firmware info. Wildly guessing capabilities...\n",
  1894. dev->name, err);
  1895. firmver = 0;
  1896. tmp[0] = '\0';
  1897. } else {
  1898. /* The firmware revision is a string, the format is
  1899. * something like : "V2.20-01".
  1900. * Quick and dirty parsing... - Jean II
  1901. */
  1902. firmver = ((tmp[1] - '0') << 16) | ((tmp[3] - '0') << 12)
  1903. | ((tmp[4] - '0') << 8) | ((tmp[6] - '0') << 4)
  1904. | (tmp[7] - '0');
  1905. tmp[SYMBOL_MAX_VER_LEN] = '\0';
  1906. }
  1907. snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
  1908. "Symbol %s", tmp);
  1909. priv->has_ibss = (firmver >= 0x20000);
  1910. priv->has_wep = (firmver >= 0x15012);
  1911. priv->has_big_wep = (firmver >= 0x20000);
  1912. priv->has_pm = (firmver >= 0x20000 && firmver < 0x22000) ||
  1913. (firmver >= 0x29000 && firmver < 0x30000) ||
  1914. firmver >= 0x31000;
  1915. priv->has_preamble = (firmver >= 0x20000);
  1916. priv->ibss_port = 4;
  1917. priv->broken_disableport = (firmver == 0x25013) ||
  1918. (firmver >= 0x30000 && firmver <= 0x31000);
  1919. priv->has_hostscan = (firmver >= 0x31001) ||
  1920. (firmver >= 0x29057 && firmver < 0x30000);
  1921. /* Tested with Intel firmware : 0x20015 => Jean II */
  1922. /* Tested with 3Com firmware : 0x15012 & 0x22001 => Jean II */
  1923. break;
  1924. case FIRMWARE_TYPE_INTERSIL:
  1925. /* D-Link, Linksys, Adtron, ZoomAir, and many others...
  1926. * Samsung, Compaq 100/200 and Proxim are slightly
  1927. * different and less well tested */
  1928. /* D-Link MAC : 00:40:05:* */
  1929. /* Addtron MAC : 00:90:D1:* */
  1930. snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
  1931. "Intersil %d.%d.%d", sta_id.major, sta_id.minor,
  1932. sta_id.variant);
  1933. firmver = ((unsigned long)sta_id.major << 16) |
  1934. ((unsigned long)sta_id.minor << 8) | sta_id.variant;
  1935. priv->has_ibss = (firmver >= 0x000700); /* FIXME */
  1936. priv->has_big_wep = priv->has_wep = (firmver >= 0x000800);
  1937. priv->has_pm = (firmver >= 0x000700);
  1938. priv->has_hostscan = (firmver >= 0x010301);
  1939. if (firmver >= 0x000800)
  1940. priv->ibss_port = 0;
  1941. else {
  1942. printk(KERN_NOTICE "%s: Intersil firmware earlier "
  1943. "than v0.8.x - several features not supported\n",
  1944. dev->name);
  1945. priv->ibss_port = 1;
  1946. }
  1947. break;
  1948. }
  1949. printk(KERN_DEBUG "%s: Firmware determined as %s\n", dev->name,
  1950. priv->fw_name);
  1951. return 0;
  1952. }
  1953. static int orinoco_init(struct net_device *dev)
  1954. {
  1955. struct orinoco_private *priv = netdev_priv(dev);
  1956. hermes_t *hw = &priv->hw;
  1957. int err = 0;
  1958. struct hermes_idstring nickbuf;
  1959. u16 reclen;
  1960. int len;
  1961. TRACE_ENTER(dev->name);
  1962. /* No need to lock, the hw_unavailable flag is already set in
  1963. * alloc_orinocodev() */
  1964. priv->nicbuf_size = IEEE80211_FRAME_LEN + ETH_HLEN;
  1965. /* Initialize the firmware */
  1966. err = orinoco_reinit_firmware(dev);
  1967. if (err != 0) {
  1968. printk(KERN_ERR "%s: failed to initialize firmware (err = %d)\n",
  1969. dev->name, err);
  1970. goto out;
  1971. }
  1972. err = determine_firmware(dev);
  1973. if (err != 0) {
  1974. printk(KERN_ERR "%s: Incompatible firmware, aborting\n",
  1975. dev->name);
  1976. goto out;
  1977. }
  1978. if (priv->has_port3)
  1979. printk(KERN_DEBUG "%s: Ad-hoc demo mode supported\n", dev->name);
  1980. if (priv->has_ibss)
  1981. printk(KERN_DEBUG "%s: IEEE standard IBSS ad-hoc mode supported\n",
  1982. dev->name);
  1983. if (priv->has_wep) {
  1984. printk(KERN_DEBUG "%s: WEP supported, ", dev->name);
  1985. if (priv->has_big_wep)
  1986. printk("104-bit key\n");
  1987. else
  1988. printk("40-bit key\n");
  1989. }
  1990. /* Get the MAC address */
  1991. err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CNFOWNMACADDR,
  1992. ETH_ALEN, NULL, dev->dev_addr);
  1993. if (err) {
  1994. printk(KERN_WARNING "%s: failed to read MAC address!\n",
  1995. dev->name);
  1996. goto out;
  1997. }
  1998. printk(KERN_DEBUG "%s: MAC address %02X:%02X:%02X:%02X:%02X:%02X\n",
  1999. dev->name, dev->dev_addr[0], dev->dev_addr[1],
  2000. dev->dev_addr[2], dev->dev_addr[3], dev->dev_addr[4],
  2001. dev->dev_addr[5]);
  2002. /* Get the station name */
  2003. err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CNFOWNNAME,
  2004. sizeof(nickbuf), &reclen, &nickbuf);
  2005. if (err) {
  2006. printk(KERN_ERR "%s: failed to read station name\n",
  2007. dev->name);
  2008. goto out;
  2009. }
  2010. if (nickbuf.len)
  2011. len = min(IW_ESSID_MAX_SIZE, (int)le16_to_cpu(nickbuf.len));
  2012. else
  2013. len = min(IW_ESSID_MAX_SIZE, 2 * reclen);
  2014. memcpy(priv->nick, &nickbuf.val, len);
  2015. priv->nick[len] = '\0';
  2016. printk(KERN_DEBUG "%s: Station name \"%s\"\n", dev->name, priv->nick);
  2017. /* Get allowed channels */
  2018. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CHANNELLIST,
  2019. &priv->channel_mask);
  2020. if (err) {
  2021. printk(KERN_ERR "%s: failed to read channel list!\n",
  2022. dev->name);
  2023. goto out;
  2024. }
  2025. /* Get initial AP density */
  2026. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFSYSTEMSCALE,
  2027. &priv->ap_density);
  2028. if (err || priv->ap_density < 1 || priv->ap_density > 3) {
  2029. priv->has_sensitivity = 0;
  2030. }
  2031. /* Get initial RTS threshold */
  2032. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFRTSTHRESHOLD,
  2033. &priv->rts_thresh);
  2034. if (err) {
  2035. printk(KERN_ERR "%s: failed to read RTS threshold!\n",
  2036. dev->name);
  2037. goto out;
  2038. }
  2039. /* Get initial fragmentation settings */
  2040. if (priv->has_mwo)
  2041. err = hermes_read_wordrec(hw, USER_BAP,
  2042. HERMES_RID_CNFMWOROBUST_AGERE,
  2043. &priv->mwo_robust);
  2044. else
  2045. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
  2046. &priv->frag_thresh);
  2047. if (err) {
  2048. printk(KERN_ERR "%s: failed to read fragmentation settings!\n",
  2049. dev->name);
  2050. goto out;
  2051. }
  2052. /* Power management setup */
  2053. if (priv->has_pm) {
  2054. priv->pm_on = 0;
  2055. priv->pm_mcast = 1;
  2056. err = hermes_read_wordrec(hw, USER_BAP,
  2057. HERMES_RID_CNFMAXSLEEPDURATION,
  2058. &priv->pm_period);
  2059. if (err) {
  2060. printk(KERN_ERR "%s: failed to read power management period!\n",
  2061. dev->name);
  2062. goto out;
  2063. }
  2064. err = hermes_read_wordrec(hw, USER_BAP,
  2065. HERMES_RID_CNFPMHOLDOVERDURATION,
  2066. &priv->pm_timeout);
  2067. if (err) {
  2068. printk(KERN_ERR "%s: failed to read power management timeout!\n",
  2069. dev->name);
  2070. goto out;
  2071. }
  2072. }
  2073. /* Preamble setup */
  2074. if (priv->has_preamble) {
  2075. err = hermes_read_wordrec(hw, USER_BAP,
  2076. HERMES_RID_CNFPREAMBLE_SYMBOL,
  2077. &priv->preamble);
  2078. if (err)
  2079. goto out;
  2080. }
  2081. /* Set up the default configuration */
  2082. priv->iw_mode = IW_MODE_INFRA;
  2083. /* By default use IEEE/IBSS ad-hoc mode if we have it */
  2084. priv->prefer_port3 = priv->has_port3 && (! priv->has_ibss);
  2085. set_port_type(priv);
  2086. priv->channel = 0; /* use firmware default */
  2087. priv->promiscuous = 0;
  2088. priv->wep_on = 0;
  2089. priv->tx_key = 0;
  2090. /* Make the hardware available, as long as it hasn't been
  2091. * removed elsewhere (e.g. by PCMCIA hot unplug) */
  2092. spin_lock_irq(&priv->lock);
  2093. priv->hw_unavailable--;
  2094. spin_unlock_irq(&priv->lock);
  2095. printk(KERN_DEBUG "%s: ready\n", dev->name);
  2096. out:
  2097. TRACE_EXIT(dev->name);
  2098. return err;
  2099. }
  2100. struct net_device *alloc_orinocodev(int sizeof_card,
  2101. int (*hard_reset)(struct orinoco_private *))
  2102. {
  2103. struct net_device *dev;
  2104. struct orinoco_private *priv;
  2105. dev = alloc_etherdev(sizeof(struct orinoco_private) + sizeof_card);
  2106. if (! dev)
  2107. return NULL;
  2108. priv = netdev_priv(dev);
  2109. priv->ndev = dev;
  2110. if (sizeof_card)
  2111. priv->card = (void *)((unsigned long)priv
  2112. + sizeof(struct orinoco_private));
  2113. else
  2114. priv->card = NULL;
  2115. /* Setup / override net_device fields */
  2116. dev->init = orinoco_init;
  2117. dev->hard_start_xmit = orinoco_xmit;
  2118. dev->tx_timeout = orinoco_tx_timeout;
  2119. dev->watchdog_timeo = HZ; /* 1 second timeout */
  2120. dev->get_stats = orinoco_get_stats;
  2121. dev->ethtool_ops = &orinoco_ethtool_ops;
  2122. dev->get_wireless_stats = orinoco_get_wireless_stats;
  2123. dev->wireless_handlers = (struct iw_handler_def *)&orinoco_handler_def;
  2124. dev->change_mtu = orinoco_change_mtu;
  2125. dev->set_multicast_list = orinoco_set_multicast_list;
  2126. /* we use the default eth_mac_addr for setting the MAC addr */
  2127. /* Set up default callbacks */
  2128. dev->open = orinoco_open;
  2129. dev->stop = orinoco_stop;
  2130. priv->hard_reset = hard_reset;
  2131. spin_lock_init(&priv->lock);
  2132. priv->open = 0;
  2133. priv->hw_unavailable = 1; /* orinoco_init() must clear this
  2134. * before anything else touches the
  2135. * hardware */
  2136. INIT_WORK(&priv->reset_work, (void (*)(void *))orinoco_reset, dev);
  2137. INIT_WORK(&priv->join_work, (void (*)(void *))orinoco_join_ap, dev);
  2138. INIT_WORK(&priv->wevent_work, (void (*)(void *))orinoco_send_wevents, dev);
  2139. netif_carrier_off(dev);
  2140. priv->last_linkstatus = 0xffff;
  2141. return dev;
  2142. }
  2143. void free_orinocodev(struct net_device *dev)
  2144. {
  2145. struct orinoco_private *priv = netdev_priv(dev);
  2146. kfree(priv->scan_result);
  2147. free_netdev(dev);
  2148. }
  2149. /********************************************************************/
  2150. /* Wireless extensions */
  2151. /********************************************************************/
  2152. static int orinoco_hw_get_essid(struct orinoco_private *priv, int *active,
  2153. char buf[IW_ESSID_MAX_SIZE+1])
  2154. {
  2155. hermes_t *hw = &priv->hw;
  2156. int err = 0;
  2157. struct hermes_idstring essidbuf;
  2158. char *p = (char *)(&essidbuf.val);
  2159. int len;
  2160. unsigned long flags;
  2161. if (orinoco_lock(priv, &flags) != 0)
  2162. return -EBUSY;
  2163. if (strlen(priv->desired_essid) > 0) {
  2164. /* We read the desired SSID from the hardware rather
  2165. than from priv->desired_essid, just in case the
  2166. firmware is allowed to change it on us. I'm not
  2167. sure about this */
  2168. /* My guess is that the OWNSSID should always be whatever
  2169. * we set to the card, whereas CURRENT_SSID is the one that
  2170. * may change... - Jean II */
  2171. u16 rid;
  2172. *active = 1;
  2173. rid = (priv->port_type == 3) ? HERMES_RID_CNFOWNSSID :
  2174. HERMES_RID_CNFDESIREDSSID;
  2175. err = hermes_read_ltv(hw, USER_BAP, rid, sizeof(essidbuf),
  2176. NULL, &essidbuf);
  2177. if (err)
  2178. goto fail_unlock;
  2179. } else {
  2180. *active = 0;
  2181. err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTSSID,
  2182. sizeof(essidbuf), NULL, &essidbuf);
  2183. if (err)
  2184. goto fail_unlock;
  2185. }
  2186. len = le16_to_cpu(essidbuf.len);
  2187. BUG_ON(len > IW_ESSID_MAX_SIZE);
  2188. memset(buf, 0, IW_ESSID_MAX_SIZE+1);
  2189. memcpy(buf, p, len);
  2190. buf[len] = '\0';
  2191. fail_unlock:
  2192. orinoco_unlock(priv, &flags);
  2193. return err;
  2194. }
  2195. static long orinoco_hw_get_freq(struct orinoco_private *priv)
  2196. {
  2197. hermes_t *hw = &priv->hw;
  2198. int err = 0;
  2199. u16 channel;
  2200. long freq = 0;
  2201. unsigned long flags;
  2202. if (orinoco_lock(priv, &flags) != 0)
  2203. return -EBUSY;
  2204. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CURRENTCHANNEL, &channel);
  2205. if (err)
  2206. goto out;
  2207. /* Intersil firmware 1.3.5 returns 0 when the interface is down */
  2208. if (channel == 0) {
  2209. err = -EBUSY;
  2210. goto out;
  2211. }
  2212. if ( (channel < 1) || (channel > NUM_CHANNELS) ) {
  2213. printk(KERN_WARNING "%s: Channel out of range (%d)!\n",
  2214. priv->ndev->name, channel);
  2215. err = -EBUSY;
  2216. goto out;
  2217. }
  2218. freq = channel_frequency[channel-1] * 100000;
  2219. out:
  2220. orinoco_unlock(priv, &flags);
  2221. if (err > 0)
  2222. err = -EBUSY;
  2223. return err ? err : freq;
  2224. }
  2225. static int orinoco_hw_get_bitratelist(struct orinoco_private *priv,
  2226. int *numrates, s32 *rates, int max)
  2227. {
  2228. hermes_t *hw = &priv->hw;
  2229. struct hermes_idstring list;
  2230. unsigned char *p = (unsigned char *)&list.val;
  2231. int err = 0;
  2232. int num;
  2233. int i;
  2234. unsigned long flags;
  2235. if (orinoco_lock(priv, &flags) != 0)
  2236. return -EBUSY;
  2237. err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_SUPPORTEDDATARATES,
  2238. sizeof(list), NULL, &list);
  2239. orinoco_unlock(priv, &flags);
  2240. if (err)
  2241. return err;
  2242. num = le16_to_cpu(list.len);
  2243. *numrates = num;
  2244. num = min(num, max);
  2245. for (i = 0; i < num; i++) {
  2246. rates[i] = (p[i] & 0x7f) * 500000; /* convert to bps */
  2247. }
  2248. return 0;
  2249. }
  2250. static int orinoco_ioctl_getname(struct net_device *dev,
  2251. struct iw_request_info *info,
  2252. char *name,
  2253. char *extra)
  2254. {
  2255. struct orinoco_private *priv = netdev_priv(dev);
  2256. int numrates;
  2257. int err;
  2258. err = orinoco_hw_get_bitratelist(priv, &numrates, NULL, 0);
  2259. if (!err && (numrates > 2))
  2260. strcpy(name, "IEEE 802.11b");
  2261. else
  2262. strcpy(name, "IEEE 802.11-DS");
  2263. return 0;
  2264. }
  2265. static int orinoco_ioctl_setwap(struct net_device *dev,
  2266. struct iw_request_info *info,
  2267. struct sockaddr *ap_addr,
  2268. char *extra)
  2269. {
  2270. struct orinoco_private *priv = netdev_priv(dev);
  2271. int err = -EINPROGRESS; /* Call commit handler */
  2272. unsigned long flags;
  2273. static const u8 off_addr[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  2274. static const u8 any_addr[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
  2275. if (orinoco_lock(priv, &flags) != 0)
  2276. return -EBUSY;
  2277. /* Enable automatic roaming - no sanity checks are needed */
  2278. if (memcmp(&ap_addr->sa_data, off_addr, ETH_ALEN) == 0 ||
  2279. memcmp(&ap_addr->sa_data, any_addr, ETH_ALEN) == 0) {
  2280. priv->bssid_fixed = 0;
  2281. memset(priv->desired_bssid, 0, ETH_ALEN);
  2282. /* "off" means keep existing connection */
  2283. if (ap_addr->sa_data[0] == 0) {
  2284. __orinoco_hw_set_wap(priv);
  2285. err = 0;
  2286. }
  2287. goto out;
  2288. }
  2289. if (priv->firmware_type == FIRMWARE_TYPE_AGERE) {
  2290. printk(KERN_WARNING "%s: Lucent/Agere firmware doesn't "
  2291. "support manual roaming\n",
  2292. dev->name);
  2293. err = -EOPNOTSUPP;
  2294. goto out;
  2295. }
  2296. if (priv->iw_mode != IW_MODE_INFRA) {
  2297. printk(KERN_WARNING "%s: Manual roaming supported only in "
  2298. "managed mode\n", dev->name);
  2299. err = -EOPNOTSUPP;
  2300. goto out;
  2301. }
  2302. /* Intersil firmware hangs without Desired ESSID */
  2303. if (priv->firmware_type == FIRMWARE_TYPE_INTERSIL &&
  2304. strlen(priv->desired_essid) == 0) {
  2305. printk(KERN_WARNING "%s: Desired ESSID must be set for "
  2306. "manual roaming\n", dev->name);
  2307. err = -EOPNOTSUPP;
  2308. goto out;
  2309. }
  2310. /* Finally, enable manual roaming */
  2311. priv->bssid_fixed = 1;
  2312. memcpy(priv->desired_bssid, &ap_addr->sa_data, ETH_ALEN);
  2313. out:
  2314. orinoco_unlock(priv, &flags);
  2315. return err;
  2316. }
  2317. static int orinoco_ioctl_getwap(struct net_device *dev,
  2318. struct iw_request_info *info,
  2319. struct sockaddr *ap_addr,
  2320. char *extra)
  2321. {
  2322. struct orinoco_private *priv = netdev_priv(dev);
  2323. hermes_t *hw = &priv->hw;
  2324. int err = 0;
  2325. unsigned long flags;
  2326. if (orinoco_lock(priv, &flags) != 0)
  2327. return -EBUSY;
  2328. ap_addr->sa_family = ARPHRD_ETHER;
  2329. err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTBSSID,
  2330. ETH_ALEN, NULL, ap_addr->sa_data);
  2331. orinoco_unlock(priv, &flags);
  2332. return err;
  2333. }
  2334. static int orinoco_ioctl_setmode(struct net_device *dev,
  2335. struct iw_request_info *info,
  2336. u32 *mode,
  2337. char *extra)
  2338. {
  2339. struct orinoco_private *priv = netdev_priv(dev);
  2340. int err = -EINPROGRESS; /* Call commit handler */
  2341. unsigned long flags;
  2342. if (priv->iw_mode == *mode)
  2343. return 0;
  2344. if (orinoco_lock(priv, &flags) != 0)
  2345. return -EBUSY;
  2346. switch (*mode) {
  2347. case IW_MODE_ADHOC:
  2348. if (!priv->has_ibss && !priv->has_port3)
  2349. err = -EOPNOTSUPP;
  2350. break;
  2351. case IW_MODE_INFRA:
  2352. break;
  2353. case IW_MODE_MONITOR:
  2354. if (priv->broken_monitor && !force_monitor) {
  2355. printk(KERN_WARNING "%s: Monitor mode support is "
  2356. "buggy in this firmware, not enabling\n",
  2357. dev->name);
  2358. err = -EOPNOTSUPP;
  2359. }
  2360. break;
  2361. default:
  2362. err = -EOPNOTSUPP;
  2363. break;
  2364. }
  2365. if (err == -EINPROGRESS) {
  2366. priv->iw_mode = *mode;
  2367. set_port_type(priv);
  2368. }
  2369. orinoco_unlock(priv, &flags);
  2370. return err;
  2371. }
  2372. static int orinoco_ioctl_getmode(struct net_device *dev,
  2373. struct iw_request_info *info,
  2374. u32 *mode,
  2375. char *extra)
  2376. {
  2377. struct orinoco_private *priv = netdev_priv(dev);
  2378. *mode = priv->iw_mode;
  2379. return 0;
  2380. }
  2381. static int orinoco_ioctl_getiwrange(struct net_device *dev,
  2382. struct iw_request_info *info,
  2383. struct iw_point *rrq,
  2384. char *extra)
  2385. {
  2386. struct orinoco_private *priv = netdev_priv(dev);
  2387. int err = 0;
  2388. struct iw_range *range = (struct iw_range *) extra;
  2389. int numrates;
  2390. int i, k;
  2391. TRACE_ENTER(dev->name);
  2392. rrq->length = sizeof(struct iw_range);
  2393. memset(range, 0, sizeof(struct iw_range));
  2394. range->we_version_compiled = WIRELESS_EXT;
  2395. range->we_version_source = 14;
  2396. /* Set available channels/frequencies */
  2397. range->num_channels = NUM_CHANNELS;
  2398. k = 0;
  2399. for (i = 0; i < NUM_CHANNELS; i++) {
  2400. if (priv->channel_mask & (1 << i)) {
  2401. range->freq[k].i = i + 1;
  2402. range->freq[k].m = channel_frequency[i] * 100000;
  2403. range->freq[k].e = 1;
  2404. k++;
  2405. }
  2406. if (k >= IW_MAX_FREQUENCIES)
  2407. break;
  2408. }
  2409. range->num_frequency = k;
  2410. range->sensitivity = 3;
  2411. if (priv->has_wep) {
  2412. range->max_encoding_tokens = ORINOCO_MAX_KEYS;
  2413. range->encoding_size[0] = SMALL_KEY_SIZE;
  2414. range->num_encoding_sizes = 1;
  2415. if (priv->has_big_wep) {
  2416. range->encoding_size[1] = LARGE_KEY_SIZE;
  2417. range->num_encoding_sizes = 2;
  2418. }
  2419. }
  2420. if ((priv->iw_mode == IW_MODE_ADHOC) && (priv->spy_number == 0)){
  2421. /* Quality stats meaningless in ad-hoc mode */
  2422. } else {
  2423. range->max_qual.qual = 0x8b - 0x2f;
  2424. range->max_qual.level = 0x2f - 0x95 - 1;
  2425. range->max_qual.noise = 0x2f - 0x95 - 1;
  2426. /* Need to get better values */
  2427. range->avg_qual.qual = 0x24;
  2428. range->avg_qual.level = 0xC2;
  2429. range->avg_qual.noise = 0x9E;
  2430. }
  2431. err = orinoco_hw_get_bitratelist(priv, &numrates,
  2432. range->bitrate, IW_MAX_BITRATES);
  2433. if (err)
  2434. return err;
  2435. range->num_bitrates = numrates;
  2436. /* Set an indication of the max TCP throughput in bit/s that we can
  2437. * expect using this interface. May be use for QoS stuff...
  2438. * Jean II */
  2439. if (numrates > 2)
  2440. range->throughput = 5 * 1000 * 1000; /* ~5 Mb/s */
  2441. else
  2442. range->throughput = 1.5 * 1000 * 1000; /* ~1.5 Mb/s */
  2443. range->min_rts = 0;
  2444. range->max_rts = 2347;
  2445. range->min_frag = 256;
  2446. range->max_frag = 2346;
  2447. range->min_pmp = 0;
  2448. range->max_pmp = 65535000;
  2449. range->min_pmt = 0;
  2450. range->max_pmt = 65535 * 1000; /* ??? */
  2451. range->pmp_flags = IW_POWER_PERIOD;
  2452. range->pmt_flags = IW_POWER_TIMEOUT;
  2453. range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT | IW_POWER_UNICAST_R;
  2454. range->retry_capa = IW_RETRY_LIMIT | IW_RETRY_LIFETIME;
  2455. range->retry_flags = IW_RETRY_LIMIT;
  2456. range->r_time_flags = IW_RETRY_LIFETIME;
  2457. range->min_retry = 0;
  2458. range->max_retry = 65535; /* ??? */
  2459. range->min_r_time = 0;
  2460. range->max_r_time = 65535 * 1000; /* ??? */
  2461. TRACE_EXIT(dev->name);
  2462. return 0;
  2463. }
  2464. static int orinoco_ioctl_setiwencode(struct net_device *dev,
  2465. struct iw_request_info *info,
  2466. struct iw_point *erq,
  2467. char *keybuf)
  2468. {
  2469. struct orinoco_private *priv = netdev_priv(dev);
  2470. int index = (erq->flags & IW_ENCODE_INDEX) - 1;
  2471. int setindex = priv->tx_key;
  2472. int enable = priv->wep_on;
  2473. int restricted = priv->wep_restrict;
  2474. u16 xlen = 0;
  2475. int err = -EINPROGRESS; /* Call commit handler */
  2476. unsigned long flags;
  2477. if (! priv->has_wep)
  2478. return -EOPNOTSUPP;
  2479. if (erq->pointer) {
  2480. /* We actually have a key to set - check its length */
  2481. if (erq->length > LARGE_KEY_SIZE)
  2482. return -E2BIG;
  2483. if ( (erq->length > SMALL_KEY_SIZE) && !priv->has_big_wep )
  2484. return -E2BIG;
  2485. }
  2486. if (orinoco_lock(priv, &flags) != 0)
  2487. return -EBUSY;
  2488. if (erq->pointer) {
  2489. if ((index < 0) || (index >= ORINOCO_MAX_KEYS))
  2490. index = priv->tx_key;
  2491. /* Adjust key length to a supported value */
  2492. if (erq->length > SMALL_KEY_SIZE) {
  2493. xlen = LARGE_KEY_SIZE;
  2494. } else if (erq->length > 0) {
  2495. xlen = SMALL_KEY_SIZE;
  2496. } else
  2497. xlen = 0;
  2498. /* Switch on WEP if off */
  2499. if ((!enable) && (xlen > 0)) {
  2500. setindex = index;
  2501. enable = 1;
  2502. }
  2503. } else {
  2504. /* Important note : if the user do "iwconfig eth0 enc off",
  2505. * we will arrive there with an index of -1. This is valid
  2506. * but need to be taken care off... Jean II */
  2507. if ((index < 0) || (index >= ORINOCO_MAX_KEYS)) {
  2508. if((index != -1) || (erq->flags == 0)) {
  2509. err = -EINVAL;
  2510. goto out;
  2511. }
  2512. } else {
  2513. /* Set the index : Check that the key is valid */
  2514. if(priv->keys[index].len == 0) {
  2515. err = -EINVAL;
  2516. goto out;
  2517. }
  2518. setindex = index;
  2519. }
  2520. }
  2521. if (erq->flags & IW_ENCODE_DISABLED)
  2522. enable = 0;
  2523. if (erq->flags & IW_ENCODE_OPEN)
  2524. restricted = 0;
  2525. if (erq->flags & IW_ENCODE_RESTRICTED)
  2526. restricted = 1;
  2527. if (erq->pointer) {
  2528. priv->keys[index].len = cpu_to_le16(xlen);
  2529. memset(priv->keys[index].data, 0,
  2530. sizeof(priv->keys[index].data));
  2531. memcpy(priv->keys[index].data, keybuf, erq->length);
  2532. }
  2533. priv->tx_key = setindex;
  2534. /* Try fast key change if connected and only keys are changed */
  2535. if (priv->wep_on && enable && (priv->wep_restrict == restricted) &&
  2536. netif_carrier_ok(dev)) {
  2537. err = __orinoco_hw_setup_wepkeys(priv);
  2538. /* No need to commit if successful */
  2539. goto out;
  2540. }
  2541. priv->wep_on = enable;
  2542. priv->wep_restrict = restricted;
  2543. out:
  2544. orinoco_unlock(priv, &flags);
  2545. return err;
  2546. }
  2547. static int orinoco_ioctl_getiwencode(struct net_device *dev,
  2548. struct iw_request_info *info,
  2549. struct iw_point *erq,
  2550. char *keybuf)
  2551. {
  2552. struct orinoco_private *priv = netdev_priv(dev);
  2553. int index = (erq->flags & IW_ENCODE_INDEX) - 1;
  2554. u16 xlen = 0;
  2555. unsigned long flags;
  2556. if (! priv->has_wep)
  2557. return -EOPNOTSUPP;
  2558. if (orinoco_lock(priv, &flags) != 0)
  2559. return -EBUSY;
  2560. if ((index < 0) || (index >= ORINOCO_MAX_KEYS))
  2561. index = priv->tx_key;
  2562. erq->flags = 0;
  2563. if (! priv->wep_on)
  2564. erq->flags |= IW_ENCODE_DISABLED;
  2565. erq->flags |= index + 1;
  2566. if (priv->wep_restrict)
  2567. erq->flags |= IW_ENCODE_RESTRICTED;
  2568. else
  2569. erq->flags |= IW_ENCODE_OPEN;
  2570. xlen = le16_to_cpu(priv->keys[index].len);
  2571. erq->length = xlen;
  2572. memcpy(keybuf, priv->keys[index].data, ORINOCO_MAX_KEY_SIZE);
  2573. orinoco_unlock(priv, &flags);
  2574. return 0;
  2575. }
  2576. static int orinoco_ioctl_setessid(struct net_device *dev,
  2577. struct iw_request_info *info,
  2578. struct iw_point *erq,
  2579. char *essidbuf)
  2580. {
  2581. struct orinoco_private *priv = netdev_priv(dev);
  2582. unsigned long flags;
  2583. /* Note : ESSID is ignored in Ad-Hoc demo mode, but we can set it
  2584. * anyway... - Jean II */
  2585. /* Hum... Should not use Wireless Extension constant (may change),
  2586. * should use our own... - Jean II */
  2587. if (erq->length > IW_ESSID_MAX_SIZE)
  2588. return -E2BIG;
  2589. if (orinoco_lock(priv, &flags) != 0)
  2590. return -EBUSY;
  2591. /* NULL the string (for NULL termination & ESSID = ANY) - Jean II */
  2592. memset(priv->desired_essid, 0, sizeof(priv->desired_essid));
  2593. /* If not ANY, get the new ESSID */
  2594. if (erq->flags) {
  2595. memcpy(priv->desired_essid, essidbuf, erq->length);
  2596. }
  2597. orinoco_unlock(priv, &flags);
  2598. return -EINPROGRESS; /* Call commit handler */
  2599. }
  2600. static int orinoco_ioctl_getessid(struct net_device *dev,
  2601. struct iw_request_info *info,
  2602. struct iw_point *erq,
  2603. char *essidbuf)
  2604. {
  2605. struct orinoco_private *priv = netdev_priv(dev);
  2606. int active;
  2607. int err = 0;
  2608. unsigned long flags;
  2609. TRACE_ENTER(dev->name);
  2610. if (netif_running(dev)) {
  2611. err = orinoco_hw_get_essid(priv, &active, essidbuf);
  2612. if (err)
  2613. return err;
  2614. } else {
  2615. if (orinoco_lock(priv, &flags) != 0)
  2616. return -EBUSY;
  2617. memcpy(essidbuf, priv->desired_essid, IW_ESSID_MAX_SIZE + 1);
  2618. orinoco_unlock(priv, &flags);
  2619. }
  2620. erq->flags = 1;
  2621. erq->length = strlen(essidbuf) + 1;
  2622. TRACE_EXIT(dev->name);
  2623. return 0;
  2624. }
  2625. static int orinoco_ioctl_setnick(struct net_device *dev,
  2626. struct iw_request_info *info,
  2627. struct iw_point *nrq,
  2628. char *nickbuf)
  2629. {
  2630. struct orinoco_private *priv = netdev_priv(dev);
  2631. unsigned long flags;
  2632. if (nrq->length > IW_ESSID_MAX_SIZE)
  2633. return -E2BIG;
  2634. if (orinoco_lock(priv, &flags) != 0)
  2635. return -EBUSY;
  2636. memset(priv->nick, 0, sizeof(priv->nick));
  2637. memcpy(priv->nick, nickbuf, nrq->length);
  2638. orinoco_unlock(priv, &flags);
  2639. return -EINPROGRESS; /* Call commit handler */
  2640. }
  2641. static int orinoco_ioctl_getnick(struct net_device *dev,
  2642. struct iw_request_info *info,
  2643. struct iw_point *nrq,
  2644. char *nickbuf)
  2645. {
  2646. struct orinoco_private *priv = netdev_priv(dev);
  2647. unsigned long flags;
  2648. if (orinoco_lock(priv, &flags) != 0)
  2649. return -EBUSY;
  2650. memcpy(nickbuf, priv->nick, IW_ESSID_MAX_SIZE+1);
  2651. orinoco_unlock(priv, &flags);
  2652. nrq->length = strlen(nickbuf)+1;
  2653. return 0;
  2654. }
  2655. static int orinoco_ioctl_setfreq(struct net_device *dev,
  2656. struct iw_request_info *info,
  2657. struct iw_freq *frq,
  2658. char *extra)
  2659. {
  2660. struct orinoco_private *priv = netdev_priv(dev);
  2661. int chan = -1;
  2662. unsigned long flags;
  2663. int err = -EINPROGRESS; /* Call commit handler */
  2664. /* In infrastructure mode the AP sets the channel */
  2665. if (priv->iw_mode == IW_MODE_INFRA)
  2666. return -EBUSY;
  2667. if ( (frq->e == 0) && (frq->m <= 1000) ) {
  2668. /* Setting by channel number */
  2669. chan = frq->m;
  2670. } else {
  2671. /* Setting by frequency - search the table */
  2672. int mult = 1;
  2673. int i;
  2674. for (i = 0; i < (6 - frq->e); i++)
  2675. mult *= 10;
  2676. for (i = 0; i < NUM_CHANNELS; i++)
  2677. if (frq->m == (channel_frequency[i] * mult))
  2678. chan = i+1;
  2679. }
  2680. if ( (chan < 1) || (chan > NUM_CHANNELS) ||
  2681. ! (priv->channel_mask & (1 << (chan-1)) ) )
  2682. return -EINVAL;
  2683. if (orinoco_lock(priv, &flags) != 0)
  2684. return -EBUSY;
  2685. priv->channel = chan;
  2686. if (priv->iw_mode == IW_MODE_MONITOR) {
  2687. /* Fast channel change - no commit if successful */
  2688. hermes_t *hw = &priv->hw;
  2689. err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
  2690. HERMES_TEST_SET_CHANNEL,
  2691. chan, NULL);
  2692. }
  2693. orinoco_unlock(priv, &flags);
  2694. return err;
  2695. }
  2696. static int orinoco_ioctl_getfreq(struct net_device *dev,
  2697. struct iw_request_info *info,
  2698. struct iw_freq *frq,
  2699. char *extra)
  2700. {
  2701. struct orinoco_private *priv = netdev_priv(dev);
  2702. int tmp;
  2703. /* Locking done in there */
  2704. tmp = orinoco_hw_get_freq(priv);
  2705. if (tmp < 0) {
  2706. return tmp;
  2707. }
  2708. frq->m = tmp;
  2709. frq->e = 1;
  2710. return 0;
  2711. }
  2712. static int orinoco_ioctl_getsens(struct net_device *dev,
  2713. struct iw_request_info *info,
  2714. struct iw_param *srq,
  2715. char *extra)
  2716. {
  2717. struct orinoco_private *priv = netdev_priv(dev);
  2718. hermes_t *hw = &priv->hw;
  2719. u16 val;
  2720. int err;
  2721. unsigned long flags;
  2722. if (!priv->has_sensitivity)
  2723. return -EOPNOTSUPP;
  2724. if (orinoco_lock(priv, &flags) != 0)
  2725. return -EBUSY;
  2726. err = hermes_read_wordrec(hw, USER_BAP,
  2727. HERMES_RID_CNFSYSTEMSCALE, &val);
  2728. orinoco_unlock(priv, &flags);
  2729. if (err)
  2730. return err;
  2731. srq->value = val;
  2732. srq->fixed = 0; /* auto */
  2733. return 0;
  2734. }
  2735. static int orinoco_ioctl_setsens(struct net_device *dev,
  2736. struct iw_request_info *info,
  2737. struct iw_param *srq,
  2738. char *extra)
  2739. {
  2740. struct orinoco_private *priv = netdev_priv(dev);
  2741. int val = srq->value;
  2742. unsigned long flags;
  2743. if (!priv->has_sensitivity)
  2744. return -EOPNOTSUPP;
  2745. if ((val < 1) || (val > 3))
  2746. return -EINVAL;
  2747. if (orinoco_lock(priv, &flags) != 0)
  2748. return -EBUSY;
  2749. priv->ap_density = val;
  2750. orinoco_unlock(priv, &flags);
  2751. return -EINPROGRESS; /* Call commit handler */
  2752. }
  2753. static int orinoco_ioctl_setrts(struct net_device *dev,
  2754. struct iw_request_info *info,
  2755. struct iw_param *rrq,
  2756. char *extra)
  2757. {
  2758. struct orinoco_private *priv = netdev_priv(dev);
  2759. int val = rrq->value;
  2760. unsigned long flags;
  2761. if (rrq->disabled)
  2762. val = 2347;
  2763. if ( (val < 0) || (val > 2347) )
  2764. return -EINVAL;
  2765. if (orinoco_lock(priv, &flags) != 0)
  2766. return -EBUSY;
  2767. priv->rts_thresh = val;
  2768. orinoco_unlock(priv, &flags);
  2769. return -EINPROGRESS; /* Call commit handler */
  2770. }
  2771. static int orinoco_ioctl_getrts(struct net_device *dev,
  2772. struct iw_request_info *info,
  2773. struct iw_param *rrq,
  2774. char *extra)
  2775. {
  2776. struct orinoco_private *priv = netdev_priv(dev);
  2777. rrq->value = priv->rts_thresh;
  2778. rrq->disabled = (rrq->value == 2347);
  2779. rrq->fixed = 1;
  2780. return 0;
  2781. }
  2782. static int orinoco_ioctl_setfrag(struct net_device *dev,
  2783. struct iw_request_info *info,
  2784. struct iw_param *frq,
  2785. char *extra)
  2786. {
  2787. struct orinoco_private *priv = netdev_priv(dev);
  2788. int err = -EINPROGRESS; /* Call commit handler */
  2789. unsigned long flags;
  2790. if (orinoco_lock(priv, &flags) != 0)
  2791. return -EBUSY;
  2792. if (priv->has_mwo) {
  2793. if (frq->disabled)
  2794. priv->mwo_robust = 0;
  2795. else {
  2796. if (frq->fixed)
  2797. printk(KERN_WARNING "%s: Fixed fragmentation is "
  2798. "not supported on this firmware. "
  2799. "Using MWO robust instead.\n", dev->name);
  2800. priv->mwo_robust = 1;
  2801. }
  2802. } else {
  2803. if (frq->disabled)
  2804. priv->frag_thresh = 2346;
  2805. else {
  2806. if ( (frq->value < 256) || (frq->value > 2346) )
  2807. err = -EINVAL;
  2808. else
  2809. priv->frag_thresh = frq->value & ~0x1; /* must be even */
  2810. }
  2811. }
  2812. orinoco_unlock(priv, &flags);
  2813. return err;
  2814. }
  2815. static int orinoco_ioctl_getfrag(struct net_device *dev,
  2816. struct iw_request_info *info,
  2817. struct iw_param *frq,
  2818. char *extra)
  2819. {
  2820. struct orinoco_private *priv = netdev_priv(dev);
  2821. hermes_t *hw = &priv->hw;
  2822. int err;
  2823. u16 val;
  2824. unsigned long flags;
  2825. if (orinoco_lock(priv, &flags) != 0)
  2826. return -EBUSY;
  2827. if (priv->has_mwo) {
  2828. err = hermes_read_wordrec(hw, USER_BAP,
  2829. HERMES_RID_CNFMWOROBUST_AGERE,
  2830. &val);
  2831. if (err)
  2832. val = 0;
  2833. frq->value = val ? 2347 : 0;
  2834. frq->disabled = ! val;
  2835. frq->fixed = 0;
  2836. } else {
  2837. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
  2838. &val);
  2839. if (err)
  2840. val = 0;
  2841. frq->value = val;
  2842. frq->disabled = (val >= 2346);
  2843. frq->fixed = 1;
  2844. }
  2845. orinoco_unlock(priv, &flags);
  2846. return err;
  2847. }
  2848. static int orinoco_ioctl_setrate(struct net_device *dev,
  2849. struct iw_request_info *info,
  2850. struct iw_param *rrq,
  2851. char *extra)
  2852. {
  2853. struct orinoco_private *priv = netdev_priv(dev);
  2854. int ratemode = -1;
  2855. int bitrate; /* 100s of kilobits */
  2856. int i;
  2857. unsigned long flags;
  2858. /* As the user space doesn't know our highest rate, it uses -1
  2859. * to ask us to set the highest rate. Test it using "iwconfig
  2860. * ethX rate auto" - Jean II */
  2861. if (rrq->value == -1)
  2862. bitrate = 110;
  2863. else {
  2864. if (rrq->value % 100000)
  2865. return -EINVAL;
  2866. bitrate = rrq->value / 100000;
  2867. }
  2868. if ( (bitrate != 10) && (bitrate != 20) &&
  2869. (bitrate != 55) && (bitrate != 110) )
  2870. return -EINVAL;
  2871. for (i = 0; i < BITRATE_TABLE_SIZE; i++)
  2872. if ( (bitrate_table[i].bitrate == bitrate) &&
  2873. (bitrate_table[i].automatic == ! rrq->fixed) ) {
  2874. ratemode = i;
  2875. break;
  2876. }
  2877. if (ratemode == -1)
  2878. return -EINVAL;
  2879. if (orinoco_lock(priv, &flags) != 0)
  2880. return -EBUSY;
  2881. priv->bitratemode = ratemode;
  2882. orinoco_unlock(priv, &flags);
  2883. return -EINPROGRESS;
  2884. }
  2885. static int orinoco_ioctl_getrate(struct net_device *dev,
  2886. struct iw_request_info *info,
  2887. struct iw_param *rrq,
  2888. char *extra)
  2889. {
  2890. struct orinoco_private *priv = netdev_priv(dev);
  2891. hermes_t *hw = &priv->hw;
  2892. int err = 0;
  2893. int ratemode;
  2894. int i;
  2895. u16 val;
  2896. unsigned long flags;
  2897. if (orinoco_lock(priv, &flags) != 0)
  2898. return -EBUSY;
  2899. ratemode = priv->bitratemode;
  2900. BUG_ON((ratemode < 0) || (ratemode >= BITRATE_TABLE_SIZE));
  2901. rrq->value = bitrate_table[ratemode].bitrate * 100000;
  2902. rrq->fixed = ! bitrate_table[ratemode].automatic;
  2903. rrq->disabled = 0;
  2904. /* If the interface is running we try to find more about the
  2905. current mode */
  2906. if (netif_running(dev)) {
  2907. err = hermes_read_wordrec(hw, USER_BAP,
  2908. HERMES_RID_CURRENTTXRATE, &val);
  2909. if (err)
  2910. goto out;
  2911. switch (priv->firmware_type) {
  2912. case FIRMWARE_TYPE_AGERE: /* Lucent style rate */
  2913. /* Note : in Lucent firmware, the return value of
  2914. * HERMES_RID_CURRENTTXRATE is the bitrate in Mb/s,
  2915. * and therefore is totally different from the
  2916. * encoding of HERMES_RID_CNFTXRATECONTROL.
  2917. * Don't forget that 6Mb/s is really 5.5Mb/s */
  2918. if (val == 6)
  2919. rrq->value = 5500000;
  2920. else
  2921. rrq->value = val * 1000000;
  2922. break;
  2923. case FIRMWARE_TYPE_INTERSIL: /* Intersil style rate */
  2924. case FIRMWARE_TYPE_SYMBOL: /* Symbol style rate */
  2925. for (i = 0; i < BITRATE_TABLE_SIZE; i++)
  2926. if (bitrate_table[i].intersil_txratectrl == val) {
  2927. ratemode = i;
  2928. break;
  2929. }
  2930. if (i >= BITRATE_TABLE_SIZE)
  2931. printk(KERN_INFO "%s: Unable to determine current bitrate (0x%04hx)\n",
  2932. dev->name, val);
  2933. rrq->value = bitrate_table[ratemode].bitrate * 100000;
  2934. break;
  2935. default:
  2936. BUG();
  2937. }
  2938. }
  2939. out:
  2940. orinoco_unlock(priv, &flags);
  2941. return err;
  2942. }
  2943. static int orinoco_ioctl_setpower(struct net_device *dev,
  2944. struct iw_request_info *info,
  2945. struct iw_param *prq,
  2946. char *extra)
  2947. {
  2948. struct orinoco_private *priv = netdev_priv(dev);
  2949. int err = -EINPROGRESS; /* Call commit handler */
  2950. unsigned long flags;
  2951. if (orinoco_lock(priv, &flags) != 0)
  2952. return -EBUSY;
  2953. if (prq->disabled) {
  2954. priv->pm_on = 0;
  2955. } else {
  2956. switch (prq->flags & IW_POWER_MODE) {
  2957. case IW_POWER_UNICAST_R:
  2958. priv->pm_mcast = 0;
  2959. priv->pm_on = 1;
  2960. break;
  2961. case IW_POWER_ALL_R:
  2962. priv->pm_mcast = 1;
  2963. priv->pm_on = 1;
  2964. break;
  2965. case IW_POWER_ON:
  2966. /* No flags : but we may have a value - Jean II */
  2967. break;
  2968. default:
  2969. err = -EINVAL;
  2970. }
  2971. if (err)
  2972. goto out;
  2973. if (prq->flags & IW_POWER_TIMEOUT) {
  2974. priv->pm_on = 1;
  2975. priv->pm_timeout = prq->value / 1000;
  2976. }
  2977. if (prq->flags & IW_POWER_PERIOD) {
  2978. priv->pm_on = 1;
  2979. priv->pm_period = prq->value / 1000;
  2980. }
  2981. /* It's valid to not have a value if we are just toggling
  2982. * the flags... Jean II */
  2983. if(!priv->pm_on) {
  2984. err = -EINVAL;
  2985. goto out;
  2986. }
  2987. }
  2988. out:
  2989. orinoco_unlock(priv, &flags);
  2990. return err;
  2991. }
  2992. static int orinoco_ioctl_getpower(struct net_device *dev,
  2993. struct iw_request_info *info,
  2994. struct iw_param *prq,
  2995. char *extra)
  2996. {
  2997. struct orinoco_private *priv = netdev_priv(dev);
  2998. hermes_t *hw = &priv->hw;
  2999. int err = 0;
  3000. u16 enable, period, timeout, mcast;
  3001. unsigned long flags;
  3002. if (orinoco_lock(priv, &flags) != 0)
  3003. return -EBUSY;
  3004. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFPMENABLED, &enable);
  3005. if (err)
  3006. goto out;
  3007. err = hermes_read_wordrec(hw, USER_BAP,
  3008. HERMES_RID_CNFMAXSLEEPDURATION, &period);
  3009. if (err)
  3010. goto out;
  3011. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFPMHOLDOVERDURATION, &timeout);
  3012. if (err)
  3013. goto out;
  3014. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFMULTICASTRECEIVE, &mcast);
  3015. if (err)
  3016. goto out;
  3017. prq->disabled = !enable;
  3018. /* Note : by default, display the period */
  3019. if ((prq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
  3020. prq->flags = IW_POWER_TIMEOUT;
  3021. prq->value = timeout * 1000;
  3022. } else {
  3023. prq->flags = IW_POWER_PERIOD;
  3024. prq->value = period * 1000;
  3025. }
  3026. if (mcast)
  3027. prq->flags |= IW_POWER_ALL_R;
  3028. else
  3029. prq->flags |= IW_POWER_UNICAST_R;
  3030. out:
  3031. orinoco_unlock(priv, &flags);
  3032. return err;
  3033. }
  3034. static int orinoco_ioctl_getretry(struct net_device *dev,
  3035. struct iw_request_info *info,
  3036. struct iw_param *rrq,
  3037. char *extra)
  3038. {
  3039. struct orinoco_private *priv = netdev_priv(dev);
  3040. hermes_t *hw = &priv->hw;
  3041. int err = 0;
  3042. u16 short_limit, long_limit, lifetime;
  3043. unsigned long flags;
  3044. if (orinoco_lock(priv, &flags) != 0)
  3045. return -EBUSY;
  3046. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_SHORTRETRYLIMIT,
  3047. &short_limit);
  3048. if (err)
  3049. goto out;
  3050. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_LONGRETRYLIMIT,
  3051. &long_limit);
  3052. if (err)
  3053. goto out;
  3054. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_MAXTRANSMITLIFETIME,
  3055. &lifetime);
  3056. if (err)
  3057. goto out;
  3058. rrq->disabled = 0; /* Can't be disabled */
  3059. /* Note : by default, display the retry number */
  3060. if ((rrq->flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
  3061. rrq->flags = IW_RETRY_LIFETIME;
  3062. rrq->value = lifetime * 1000; /* ??? */
  3063. } else {
  3064. /* By default, display the min number */
  3065. if ((rrq->flags & IW_RETRY_MAX)) {
  3066. rrq->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
  3067. rrq->value = long_limit;
  3068. } else {
  3069. rrq->flags = IW_RETRY_LIMIT;
  3070. rrq->value = short_limit;
  3071. if(short_limit != long_limit)
  3072. rrq->flags |= IW_RETRY_MIN;
  3073. }
  3074. }
  3075. out:
  3076. orinoco_unlock(priv, &flags);
  3077. return err;
  3078. }
  3079. static int orinoco_ioctl_reset(struct net_device *dev,
  3080. struct iw_request_info *info,
  3081. void *wrqu,
  3082. char *extra)
  3083. {
  3084. struct orinoco_private *priv = netdev_priv(dev);
  3085. if (! capable(CAP_NET_ADMIN))
  3086. return -EPERM;
  3087. if (info->cmd == (SIOCIWFIRSTPRIV + 0x1)) {
  3088. printk(KERN_DEBUG "%s: Forcing reset!\n", dev->name);
  3089. /* Firmware reset */
  3090. orinoco_reset(dev);
  3091. } else {
  3092. printk(KERN_DEBUG "%s: Force scheduling reset!\n", dev->name);
  3093. schedule_work(&priv->reset_work);
  3094. }
  3095. return 0;
  3096. }
  3097. static int orinoco_ioctl_setibssport(struct net_device *dev,
  3098. struct iw_request_info *info,
  3099. void *wrqu,
  3100. char *extra)
  3101. {
  3102. struct orinoco_private *priv = netdev_priv(dev);
  3103. int val = *( (int *) extra );
  3104. unsigned long flags;
  3105. if (orinoco_lock(priv, &flags) != 0)
  3106. return -EBUSY;
  3107. priv->ibss_port = val ;
  3108. /* Actually update the mode we are using */
  3109. set_port_type(priv);
  3110. orinoco_unlock(priv, &flags);
  3111. return -EINPROGRESS; /* Call commit handler */
  3112. }
  3113. static int orinoco_ioctl_getibssport(struct net_device *dev,
  3114. struct iw_request_info *info,
  3115. void *wrqu,
  3116. char *extra)
  3117. {
  3118. struct orinoco_private *priv = netdev_priv(dev);
  3119. int *val = (int *) extra;
  3120. *val = priv->ibss_port;
  3121. return 0;
  3122. }
  3123. static int orinoco_ioctl_setport3(struct net_device *dev,
  3124. struct iw_request_info *info,
  3125. void *wrqu,
  3126. char *extra)
  3127. {
  3128. struct orinoco_private *priv = netdev_priv(dev);
  3129. int val = *( (int *) extra );
  3130. int err = 0;
  3131. unsigned long flags;
  3132. if (orinoco_lock(priv, &flags) != 0)
  3133. return -EBUSY;
  3134. switch (val) {
  3135. case 0: /* Try to do IEEE ad-hoc mode */
  3136. if (! priv->has_ibss) {
  3137. err = -EINVAL;
  3138. break;
  3139. }
  3140. priv->prefer_port3 = 0;
  3141. break;
  3142. case 1: /* Try to do Lucent proprietary ad-hoc mode */
  3143. if (! priv->has_port3) {
  3144. err = -EINVAL;
  3145. break;
  3146. }
  3147. priv->prefer_port3 = 1;
  3148. break;
  3149. default:
  3150. err = -EINVAL;
  3151. }
  3152. if (! err) {
  3153. /* Actually update the mode we are using */
  3154. set_port_type(priv);
  3155. err = -EINPROGRESS;
  3156. }
  3157. orinoco_unlock(priv, &flags);
  3158. return err;
  3159. }
  3160. static int orinoco_ioctl_getport3(struct net_device *dev,
  3161. struct iw_request_info *info,
  3162. void *wrqu,
  3163. char *extra)
  3164. {
  3165. struct orinoco_private *priv = netdev_priv(dev);
  3166. int *val = (int *) extra;
  3167. *val = priv->prefer_port3;
  3168. return 0;
  3169. }
  3170. static int orinoco_ioctl_setpreamble(struct net_device *dev,
  3171. struct iw_request_info *info,
  3172. void *wrqu,
  3173. char *extra)
  3174. {
  3175. struct orinoco_private *priv = netdev_priv(dev);
  3176. unsigned long flags;
  3177. int val;
  3178. if (! priv->has_preamble)
  3179. return -EOPNOTSUPP;
  3180. /* 802.11b has recently defined some short preamble.
  3181. * Basically, the Phy header has been reduced in size.
  3182. * This increase performance, especially at high rates
  3183. * (the preamble is transmitted at 1Mb/s), unfortunately
  3184. * this give compatibility troubles... - Jean II */
  3185. val = *( (int *) extra );
  3186. if (orinoco_lock(priv, &flags) != 0)
  3187. return -EBUSY;
  3188. if (val)
  3189. priv->preamble = 1;
  3190. else
  3191. priv->preamble = 0;
  3192. orinoco_unlock(priv, &flags);
  3193. return -EINPROGRESS; /* Call commit handler */
  3194. }
  3195. static int orinoco_ioctl_getpreamble(struct net_device *dev,
  3196. struct iw_request_info *info,
  3197. void *wrqu,
  3198. char *extra)
  3199. {
  3200. struct orinoco_private *priv = netdev_priv(dev);
  3201. int *val = (int *) extra;
  3202. if (! priv->has_preamble)
  3203. return -EOPNOTSUPP;
  3204. *val = priv->preamble;
  3205. return 0;
  3206. }
  3207. /* ioctl interface to hermes_read_ltv()
  3208. * To use with iwpriv, pass the RID as the token argument, e.g.
  3209. * iwpriv get_rid [0xfc00]
  3210. * At least Wireless Tools 25 is required to use iwpriv.
  3211. * For Wireless Tools 25 and 26 append "dummy" are the end. */
  3212. static int orinoco_ioctl_getrid(struct net_device *dev,
  3213. struct iw_request_info *info,
  3214. struct iw_point *data,
  3215. char *extra)
  3216. {
  3217. struct orinoco_private *priv = netdev_priv(dev);
  3218. hermes_t *hw = &priv->hw;
  3219. int rid = data->flags;
  3220. u16 length;
  3221. int err;
  3222. unsigned long flags;
  3223. /* It's a "get" function, but we don't want users to access the
  3224. * WEP key and other raw firmware data */
  3225. if (! capable(CAP_NET_ADMIN))
  3226. return -EPERM;
  3227. if (rid < 0xfc00 || rid > 0xffff)
  3228. return -EINVAL;
  3229. if (orinoco_lock(priv, &flags) != 0)
  3230. return -EBUSY;
  3231. err = hermes_read_ltv(hw, USER_BAP, rid, MAX_RID_LEN, &length,
  3232. extra);
  3233. if (err)
  3234. goto out;
  3235. data->length = min_t(u16, HERMES_RECLEN_TO_BYTES(length),
  3236. MAX_RID_LEN);
  3237. out:
  3238. orinoco_unlock(priv, &flags);
  3239. return err;
  3240. }
  3241. /* Spy is used for link quality/strength measurements in Ad-Hoc mode
  3242. * Jean II */
  3243. static int orinoco_ioctl_setspy(struct net_device *dev,
  3244. struct iw_request_info *info,
  3245. struct iw_point *srq,
  3246. char *extra)
  3247. {
  3248. struct orinoco_private *priv = netdev_priv(dev);
  3249. struct sockaddr *address = (struct sockaddr *) extra;
  3250. int number = srq->length;
  3251. int i;
  3252. unsigned long flags;
  3253. /* Make sure nobody mess with the structure while we do */
  3254. if (orinoco_lock(priv, &flags) != 0)
  3255. return -EBUSY;
  3256. /* orinoco_lock() doesn't disable interrupts, so make sure the
  3257. * interrupt rx path don't get confused while we copy */
  3258. priv->spy_number = 0;
  3259. if (number > 0) {
  3260. /* Extract the addresses */
  3261. for (i = 0; i < number; i++)
  3262. memcpy(priv->spy_address[i], address[i].sa_data,
  3263. ETH_ALEN);
  3264. /* Reset stats */
  3265. memset(priv->spy_stat, 0,
  3266. sizeof(struct iw_quality) * IW_MAX_SPY);
  3267. /* Set number of addresses */
  3268. priv->spy_number = number;
  3269. }
  3270. /* Now, let the others play */
  3271. orinoco_unlock(priv, &flags);
  3272. /* Do NOT call commit handler */
  3273. return 0;
  3274. }
  3275. static int orinoco_ioctl_getspy(struct net_device *dev,
  3276. struct iw_request_info *info,
  3277. struct iw_point *srq,
  3278. char *extra)
  3279. {
  3280. struct orinoco_private *priv = netdev_priv(dev);
  3281. struct sockaddr *address = (struct sockaddr *) extra;
  3282. int number;
  3283. int i;
  3284. unsigned long flags;
  3285. if (orinoco_lock(priv, &flags) != 0)
  3286. return -EBUSY;
  3287. number = priv->spy_number;
  3288. /* Create address struct */
  3289. for (i = 0; i < number; i++) {
  3290. memcpy(address[i].sa_data, priv->spy_address[i], ETH_ALEN);
  3291. address[i].sa_family = AF_UNIX;
  3292. }
  3293. if (number > 0) {
  3294. /* Create address struct */
  3295. for (i = 0; i < number; i++) {
  3296. memcpy(address[i].sa_data, priv->spy_address[i],
  3297. ETH_ALEN);
  3298. address[i].sa_family = AF_UNIX;
  3299. }
  3300. /* Copy stats */
  3301. /* In theory, we should disable irqs while copying the stats
  3302. * because the rx path might update it in the middle...
  3303. * Bah, who care ? - Jean II */
  3304. memcpy(extra + (sizeof(struct sockaddr) * number),
  3305. priv->spy_stat, sizeof(struct iw_quality) * number);
  3306. }
  3307. /* Reset updated flags. */
  3308. for (i = 0; i < number; i++)
  3309. priv->spy_stat[i].updated = 0;
  3310. orinoco_unlock(priv, &flags);
  3311. srq->length = number;
  3312. return 0;
  3313. }
  3314. /* Trigger a scan (look for other cells in the vicinity */
  3315. static int orinoco_ioctl_setscan(struct net_device *dev,
  3316. struct iw_request_info *info,
  3317. struct iw_param *srq,
  3318. char *extra)
  3319. {
  3320. struct orinoco_private *priv = netdev_priv(dev);
  3321. hermes_t *hw = &priv->hw;
  3322. int err = 0;
  3323. unsigned long flags;
  3324. /* Note : you may have realised that, as this is a SET operation,
  3325. * this is priviledged and therefore a normal user can't
  3326. * perform scanning.
  3327. * This is not an error, while the device perform scanning,
  3328. * traffic doesn't flow, so it's a perfect DoS...
  3329. * Jean II */
  3330. if (orinoco_lock(priv, &flags) != 0)
  3331. return -EBUSY;
  3332. /* Scanning with port 0 disabled would fail */
  3333. if (!netif_running(dev)) {
  3334. err = -ENETDOWN;
  3335. goto out;
  3336. }
  3337. /* In monitor mode, the scan results are always empty.
  3338. * Probe responses are passed to the driver as received
  3339. * frames and could be processed in software. */
  3340. if (priv->iw_mode == IW_MODE_MONITOR) {
  3341. err = -EOPNOTSUPP;
  3342. goto out;
  3343. }
  3344. /* Note : because we don't lock out the irq handler, the way
  3345. * we access scan variables in priv is critical.
  3346. * o scan_inprogress : not touched by irq handler
  3347. * o scan_mode : not touched by irq handler
  3348. * o scan_result : irq is strict producer, non-irq is strict
  3349. * consumer.
  3350. * o scan_len : synchronised with scan_result
  3351. * Before modifying anything on those variables, please think hard !
  3352. * Jean II */
  3353. /* If there is still some left-over scan results, get rid of it */
  3354. if (priv->scan_result != NULL) {
  3355. /* What's likely is that a client did crash or was killed
  3356. * between triggering the scan request and reading the
  3357. * results, so we need to reset everything.
  3358. * Some clients that are too slow may suffer from that...
  3359. * Jean II */
  3360. kfree(priv->scan_result);
  3361. priv->scan_result = NULL;
  3362. }
  3363. /* Save flags */
  3364. priv->scan_mode = srq->flags;
  3365. /* Always trigger scanning, even if it's in progress.
  3366. * This way, if the info frame get lost, we will recover somewhat
  3367. * gracefully - Jean II */
  3368. if (priv->has_hostscan) {
  3369. switch (priv->firmware_type) {
  3370. case FIRMWARE_TYPE_SYMBOL:
  3371. err = hermes_write_wordrec(hw, USER_BAP,
  3372. HERMES_RID_CNFHOSTSCAN_SYMBOL,
  3373. HERMES_HOSTSCAN_SYMBOL_ONCE |
  3374. HERMES_HOSTSCAN_SYMBOL_BCAST);
  3375. break;
  3376. case FIRMWARE_TYPE_INTERSIL: {
  3377. u16 req[3];
  3378. req[0] = cpu_to_le16(0x3fff); /* All channels */
  3379. req[1] = cpu_to_le16(0x0001); /* rate 1 Mbps */
  3380. req[2] = 0; /* Any ESSID */
  3381. err = HERMES_WRITE_RECORD(hw, USER_BAP,
  3382. HERMES_RID_CNFHOSTSCAN, &req);
  3383. }
  3384. break;
  3385. case FIRMWARE_TYPE_AGERE:
  3386. err = hermes_write_wordrec(hw, USER_BAP,
  3387. HERMES_RID_CNFSCANSSID_AGERE,
  3388. 0); /* Any ESSID */
  3389. if (err)
  3390. break;
  3391. err = hermes_inquire(hw, HERMES_INQ_SCAN);
  3392. break;
  3393. }
  3394. } else
  3395. err = hermes_inquire(hw, HERMES_INQ_SCAN);
  3396. /* One more client */
  3397. if (! err)
  3398. priv->scan_inprogress = 1;
  3399. out:
  3400. orinoco_unlock(priv, &flags);
  3401. return err;
  3402. }
  3403. /* Translate scan data returned from the card to a card independant
  3404. * format that the Wireless Tools will understand - Jean II
  3405. * Return message length or -errno for fatal errors */
  3406. static inline int orinoco_translate_scan(struct net_device *dev,
  3407. char *buffer,
  3408. char *scan,
  3409. int scan_len)
  3410. {
  3411. struct orinoco_private *priv = netdev_priv(dev);
  3412. int offset; /* In the scan data */
  3413. union hermes_scan_info *atom;
  3414. int atom_len;
  3415. u16 capabilities;
  3416. u16 channel;
  3417. struct iw_event iwe; /* Temporary buffer */
  3418. char * current_ev = buffer;
  3419. char * end_buf = buffer + IW_SCAN_MAX_DATA;
  3420. switch (priv->firmware_type) {
  3421. case FIRMWARE_TYPE_AGERE:
  3422. atom_len = sizeof(struct agere_scan_apinfo);
  3423. offset = 0;
  3424. break;
  3425. case FIRMWARE_TYPE_SYMBOL:
  3426. /* Lack of documentation necessitates this hack.
  3427. * Different firmwares have 68 or 76 byte long atoms.
  3428. * We try modulo first. If the length divides by both,
  3429. * we check what would be the channel in the second
  3430. * frame for a 68-byte atom. 76-byte atoms have 0 there.
  3431. * Valid channel cannot be 0. */
  3432. if (scan_len % 76)
  3433. atom_len = 68;
  3434. else if (scan_len % 68)
  3435. atom_len = 76;
  3436. else if (scan_len >= 1292 && scan[68] == 0)
  3437. atom_len = 76;
  3438. else
  3439. atom_len = 68;
  3440. offset = 0;
  3441. break;
  3442. case FIRMWARE_TYPE_INTERSIL:
  3443. offset = 4;
  3444. if (priv->has_hostscan) {
  3445. atom_len = le16_to_cpup((u16 *)scan);
  3446. /* Sanity check for atom_len */
  3447. if (atom_len < sizeof(struct prism2_scan_apinfo)) {
  3448. printk(KERN_ERR "%s: Invalid atom_len in scan data: %d\n",
  3449. dev->name, atom_len);
  3450. return -EIO;
  3451. }
  3452. } else
  3453. atom_len = offsetof(struct prism2_scan_apinfo, atim);
  3454. break;
  3455. default:
  3456. return -EOPNOTSUPP;
  3457. }
  3458. /* Check that we got an whole number of atoms */
  3459. if ((scan_len - offset) % atom_len) {
  3460. printk(KERN_ERR "%s: Unexpected scan data length %d, "
  3461. "atom_len %d, offset %d\n", dev->name, scan_len,
  3462. atom_len, offset);
  3463. return -EIO;
  3464. }
  3465. /* Read the entries one by one */
  3466. for (; offset + atom_len <= scan_len; offset += atom_len) {
  3467. /* Get next atom */
  3468. atom = (union hermes_scan_info *) (scan + offset);
  3469. /* First entry *MUST* be the AP MAC address */
  3470. iwe.cmd = SIOCGIWAP;
  3471. iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
  3472. memcpy(iwe.u.ap_addr.sa_data, atom->a.bssid, ETH_ALEN);
  3473. current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_ADDR_LEN);
  3474. /* Other entries will be displayed in the order we give them */
  3475. /* Add the ESSID */
  3476. iwe.u.data.length = le16_to_cpu(atom->a.essid_len);
  3477. if (iwe.u.data.length > 32)
  3478. iwe.u.data.length = 32;
  3479. iwe.cmd = SIOCGIWESSID;
  3480. iwe.u.data.flags = 1;
  3481. current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, atom->a.essid);
  3482. /* Add mode */
  3483. iwe.cmd = SIOCGIWMODE;
  3484. capabilities = le16_to_cpu(atom->a.capabilities);
  3485. if (capabilities & 0x3) {
  3486. if (capabilities & 0x1)
  3487. iwe.u.mode = IW_MODE_MASTER;
  3488. else
  3489. iwe.u.mode = IW_MODE_ADHOC;
  3490. current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_UINT_LEN);
  3491. }
  3492. channel = atom->s.channel;
  3493. if ( (channel >= 1) && (channel <= NUM_CHANNELS) ) {
  3494. /* Add frequency */
  3495. iwe.cmd = SIOCGIWFREQ;
  3496. iwe.u.freq.m = channel_frequency[channel-1] * 100000;
  3497. iwe.u.freq.e = 1;
  3498. current_ev = iwe_stream_add_event(current_ev, end_buf,
  3499. &iwe, IW_EV_FREQ_LEN);
  3500. }
  3501. /* Add quality statistics */
  3502. iwe.cmd = IWEVQUAL;
  3503. iwe.u.qual.updated = 0x10; /* no link quality */
  3504. iwe.u.qual.level = (__u8) le16_to_cpu(atom->a.level) - 0x95;
  3505. iwe.u.qual.noise = (__u8) le16_to_cpu(atom->a.noise) - 0x95;
  3506. /* Wireless tools prior to 27.pre22 will show link quality
  3507. * anyway, so we provide a reasonable value. */
  3508. if (iwe.u.qual.level > iwe.u.qual.noise)
  3509. iwe.u.qual.qual = iwe.u.qual.level - iwe.u.qual.noise;
  3510. else
  3511. iwe.u.qual.qual = 0;
  3512. current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_QUAL_LEN);
  3513. /* Add encryption capability */
  3514. iwe.cmd = SIOCGIWENCODE;
  3515. if (capabilities & 0x10)
  3516. iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
  3517. else
  3518. iwe.u.data.flags = IW_ENCODE_DISABLED;
  3519. iwe.u.data.length = 0;
  3520. current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, atom->a.essid);
  3521. /* Bit rate is not available in Lucent/Agere firmwares */
  3522. if (priv->firmware_type != FIRMWARE_TYPE_AGERE) {
  3523. char * current_val = current_ev + IW_EV_LCP_LEN;
  3524. int i;
  3525. int step;
  3526. if (priv->firmware_type == FIRMWARE_TYPE_SYMBOL)
  3527. step = 2;
  3528. else
  3529. step = 1;
  3530. iwe.cmd = SIOCGIWRATE;
  3531. /* Those two flags are ignored... */
  3532. iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
  3533. /* Max 10 values */
  3534. for (i = 0; i < 10; i += step) {
  3535. /* NULL terminated */
  3536. if (atom->p.rates[i] == 0x0)
  3537. break;
  3538. /* Bit rate given in 500 kb/s units (+ 0x80) */
  3539. iwe.u.bitrate.value = ((atom->p.rates[i] & 0x7f) * 500000);
  3540. current_val = iwe_stream_add_value(current_ev, current_val,
  3541. end_buf, &iwe,
  3542. IW_EV_PARAM_LEN);
  3543. }
  3544. /* Check if we added any event */
  3545. if ((current_val - current_ev) > IW_EV_LCP_LEN)
  3546. current_ev = current_val;
  3547. }
  3548. /* The other data in the scan result are not really
  3549. * interesting, so for now drop it - Jean II */
  3550. }
  3551. return current_ev - buffer;
  3552. }
  3553. /* Return results of a scan */
  3554. static int orinoco_ioctl_getscan(struct net_device *dev,
  3555. struct iw_request_info *info,
  3556. struct iw_point *srq,
  3557. char *extra)
  3558. {
  3559. struct orinoco_private *priv = netdev_priv(dev);
  3560. int err = 0;
  3561. unsigned long flags;
  3562. if (orinoco_lock(priv, &flags) != 0)
  3563. return -EBUSY;
  3564. /* If no results yet, ask to try again later */
  3565. if (priv->scan_result == NULL) {
  3566. if (priv->scan_inprogress)
  3567. /* Important note : we don't want to block the caller
  3568. * until results are ready for various reasons.
  3569. * First, managing wait queues is complex and racy.
  3570. * Second, we grab some rtnetlink lock before comming
  3571. * here (in dev_ioctl()).
  3572. * Third, we generate an Wireless Event, so the
  3573. * caller can wait itself on that - Jean II */
  3574. err = -EAGAIN;
  3575. else
  3576. /* Client error, no scan results...
  3577. * The caller need to restart the scan. */
  3578. err = -ENODATA;
  3579. } else {
  3580. /* We have some results to push back to user space */
  3581. /* Translate to WE format */
  3582. int ret = orinoco_translate_scan(dev, extra,
  3583. priv->scan_result,
  3584. priv->scan_len);
  3585. if (ret < 0) {
  3586. err = ret;
  3587. kfree(priv->scan_result);
  3588. priv->scan_result = NULL;
  3589. } else {
  3590. srq->length = ret;
  3591. /* Return flags */
  3592. srq->flags = (__u16) priv->scan_mode;
  3593. /* In any case, Scan results will be cleaned up in the
  3594. * reset function and when exiting the driver.
  3595. * The person triggering the scanning may never come to
  3596. * pick the results, so we need to do it in those places.
  3597. * Jean II */
  3598. #ifdef SCAN_SINGLE_READ
  3599. /* If you enable this option, only one client (the first
  3600. * one) will be able to read the result (and only one
  3601. * time). If there is multiple concurent clients that
  3602. * want to read scan results, this behavior is not
  3603. * advisable - Jean II */
  3604. kfree(priv->scan_result);
  3605. priv->scan_result = NULL;
  3606. #endif /* SCAN_SINGLE_READ */
  3607. /* Here, if too much time has elapsed since last scan,
  3608. * we may want to clean up scan results... - Jean II */
  3609. }
  3610. /* Scan is no longer in progress */
  3611. priv->scan_inprogress = 0;
  3612. }
  3613. orinoco_unlock(priv, &flags);
  3614. return err;
  3615. }
  3616. /* Commit handler, called after set operations */
  3617. static int orinoco_ioctl_commit(struct net_device *dev,
  3618. struct iw_request_info *info,
  3619. void *wrqu,
  3620. char *extra)
  3621. {
  3622. struct orinoco_private *priv = netdev_priv(dev);
  3623. struct hermes *hw = &priv->hw;
  3624. unsigned long flags;
  3625. int err = 0;
  3626. if (!priv->open)
  3627. return 0;
  3628. if (priv->broken_disableport) {
  3629. orinoco_reset(dev);
  3630. return 0;
  3631. }
  3632. if (orinoco_lock(priv, &flags) != 0)
  3633. return err;
  3634. err = hermes_disable_port(hw, 0);
  3635. if (err) {
  3636. printk(KERN_WARNING "%s: Unable to disable port "
  3637. "while reconfiguring card\n", dev->name);
  3638. priv->broken_disableport = 1;
  3639. goto out;
  3640. }
  3641. err = __orinoco_program_rids(dev);
  3642. if (err) {
  3643. printk(KERN_WARNING "%s: Unable to reconfigure card\n",
  3644. dev->name);
  3645. goto out;
  3646. }
  3647. err = hermes_enable_port(hw, 0);
  3648. if (err) {
  3649. printk(KERN_WARNING "%s: Unable to enable port while reconfiguring card\n",
  3650. dev->name);
  3651. goto out;
  3652. }
  3653. out:
  3654. if (err) {
  3655. printk(KERN_WARNING "%s: Resetting instead...\n", dev->name);
  3656. schedule_work(&priv->reset_work);
  3657. err = 0;
  3658. }
  3659. orinoco_unlock(priv, &flags);
  3660. return err;
  3661. }
  3662. static const struct iw_priv_args orinoco_privtab[] = {
  3663. { SIOCIWFIRSTPRIV + 0x0, 0, 0, "force_reset" },
  3664. { SIOCIWFIRSTPRIV + 0x1, 0, 0, "card_reset" },
  3665. { SIOCIWFIRSTPRIV + 0x2, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  3666. 0, "set_port3" },
  3667. { SIOCIWFIRSTPRIV + 0x3, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  3668. "get_port3" },
  3669. { SIOCIWFIRSTPRIV + 0x4, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  3670. 0, "set_preamble" },
  3671. { SIOCIWFIRSTPRIV + 0x5, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  3672. "get_preamble" },
  3673. { SIOCIWFIRSTPRIV + 0x6, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  3674. 0, "set_ibssport" },
  3675. { SIOCIWFIRSTPRIV + 0x7, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  3676. "get_ibssport" },
  3677. { SIOCIWFIRSTPRIV + 0x9, 0, IW_PRIV_TYPE_BYTE | MAX_RID_LEN,
  3678. "get_rid" },
  3679. };
  3680. /*
  3681. * Structures to export the Wireless Handlers
  3682. */
  3683. static const iw_handler orinoco_handler[] = {
  3684. [SIOCSIWCOMMIT-SIOCIWFIRST] = (iw_handler) orinoco_ioctl_commit,
  3685. [SIOCGIWNAME -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getname,
  3686. [SIOCSIWFREQ -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setfreq,
  3687. [SIOCGIWFREQ -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getfreq,
  3688. [SIOCSIWMODE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setmode,
  3689. [SIOCGIWMODE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getmode,
  3690. [SIOCSIWSENS -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setsens,
  3691. [SIOCGIWSENS -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getsens,
  3692. [SIOCGIWRANGE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getiwrange,
  3693. [SIOCSIWSPY -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setspy,
  3694. [SIOCGIWSPY -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getspy,
  3695. [SIOCSIWAP -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setwap,
  3696. [SIOCGIWAP -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getwap,
  3697. [SIOCSIWSCAN -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setscan,
  3698. [SIOCGIWSCAN -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getscan,
  3699. [SIOCSIWESSID -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setessid,
  3700. [SIOCGIWESSID -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getessid,
  3701. [SIOCSIWNICKN -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setnick,
  3702. [SIOCGIWNICKN -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getnick,
  3703. [SIOCSIWRATE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setrate,
  3704. [SIOCGIWRATE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getrate,
  3705. [SIOCSIWRTS -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setrts,
  3706. [SIOCGIWRTS -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getrts,
  3707. [SIOCSIWFRAG -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setfrag,
  3708. [SIOCGIWFRAG -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getfrag,
  3709. [SIOCGIWRETRY -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getretry,
  3710. [SIOCSIWENCODE-SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setiwencode,
  3711. [SIOCGIWENCODE-SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getiwencode,
  3712. [SIOCSIWPOWER -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setpower,
  3713. [SIOCGIWPOWER -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getpower,
  3714. };
  3715. /*
  3716. Added typecasting since we no longer use iwreq_data -- Moustafa
  3717. */
  3718. static const iw_handler orinoco_private_handler[] = {
  3719. [0] = (iw_handler) orinoco_ioctl_reset,
  3720. [1] = (iw_handler) orinoco_ioctl_reset,
  3721. [2] = (iw_handler) orinoco_ioctl_setport3,
  3722. [3] = (iw_handler) orinoco_ioctl_getport3,
  3723. [4] = (iw_handler) orinoco_ioctl_setpreamble,
  3724. [5] = (iw_handler) orinoco_ioctl_getpreamble,
  3725. [6] = (iw_handler) orinoco_ioctl_setibssport,
  3726. [7] = (iw_handler) orinoco_ioctl_getibssport,
  3727. [9] = (iw_handler) orinoco_ioctl_getrid,
  3728. };
  3729. static const struct iw_handler_def orinoco_handler_def = {
  3730. .num_standard = ARRAY_SIZE(orinoco_handler),
  3731. .num_private = ARRAY_SIZE(orinoco_private_handler),
  3732. .num_private_args = ARRAY_SIZE(orinoco_privtab),
  3733. .standard = orinoco_handler,
  3734. .private = orinoco_private_handler,
  3735. .private_args = orinoco_privtab,
  3736. };
  3737. static void orinoco_get_drvinfo(struct net_device *dev,
  3738. struct ethtool_drvinfo *info)
  3739. {
  3740. struct orinoco_private *priv = netdev_priv(dev);
  3741. strncpy(info->driver, DRIVER_NAME, sizeof(info->driver) - 1);
  3742. strncpy(info->version, DRIVER_VERSION, sizeof(info->version) - 1);
  3743. strncpy(info->fw_version, priv->fw_name, sizeof(info->fw_version) - 1);
  3744. if (dev->class_dev.dev)
  3745. strncpy(info->bus_info, dev->class_dev.dev->bus_id,
  3746. sizeof(info->bus_info) - 1);
  3747. else
  3748. snprintf(info->bus_info, sizeof(info->bus_info) - 1,
  3749. "PCMCIA %p", priv->hw.iobase);
  3750. }
  3751. static struct ethtool_ops orinoco_ethtool_ops = {
  3752. .get_drvinfo = orinoco_get_drvinfo,
  3753. .get_link = ethtool_op_get_link,
  3754. };
  3755. /********************************************************************/
  3756. /* Debugging */
  3757. /********************************************************************/
  3758. #if 0
  3759. static void show_rx_frame(struct orinoco_rxframe_hdr *frame)
  3760. {
  3761. printk(KERN_DEBUG "RX descriptor:\n");
  3762. printk(KERN_DEBUG " status = 0x%04x\n", frame->desc.status);
  3763. printk(KERN_DEBUG " time = 0x%08x\n", frame->desc.time);
  3764. printk(KERN_DEBUG " silence = 0x%02x\n", frame->desc.silence);
  3765. printk(KERN_DEBUG " signal = 0x%02x\n", frame->desc.signal);
  3766. printk(KERN_DEBUG " rate = 0x%02x\n", frame->desc.rate);
  3767. printk(KERN_DEBUG " rxflow = 0x%02x\n", frame->desc.rxflow);
  3768. printk(KERN_DEBUG " reserved = 0x%08x\n", frame->desc.reserved);
  3769. printk(KERN_DEBUG "IEEE 802.11 header:\n");
  3770. printk(KERN_DEBUG " frame_ctl = 0x%04x\n",
  3771. frame->p80211.frame_ctl);
  3772. printk(KERN_DEBUG " duration_id = 0x%04x\n",
  3773. frame->p80211.duration_id);
  3774. printk(KERN_DEBUG " addr1 = %02x:%02x:%02x:%02x:%02x:%02x\n",
  3775. frame->p80211.addr1[0], frame->p80211.addr1[1],
  3776. frame->p80211.addr1[2], frame->p80211.addr1[3],
  3777. frame->p80211.addr1[4], frame->p80211.addr1[5]);
  3778. printk(KERN_DEBUG " addr2 = %02x:%02x:%02x:%02x:%02x:%02x\n",
  3779. frame->p80211.addr2[0], frame->p80211.addr2[1],
  3780. frame->p80211.addr2[2], frame->p80211.addr2[3],
  3781. frame->p80211.addr2[4], frame->p80211.addr2[5]);
  3782. printk(KERN_DEBUG " addr3 = %02x:%02x:%02x:%02x:%02x:%02x\n",
  3783. frame->p80211.addr3[0], frame->p80211.addr3[1],
  3784. frame->p80211.addr3[2], frame->p80211.addr3[3],
  3785. frame->p80211.addr3[4], frame->p80211.addr3[5]);
  3786. printk(KERN_DEBUG " seq_ctl = 0x%04x\n",
  3787. frame->p80211.seq_ctl);
  3788. printk(KERN_DEBUG " addr4 = %02x:%02x:%02x:%02x:%02x:%02x\n",
  3789. frame->p80211.addr4[0], frame->p80211.addr4[1],
  3790. frame->p80211.addr4[2], frame->p80211.addr4[3],
  3791. frame->p80211.addr4[4], frame->p80211.addr4[5]);
  3792. printk(KERN_DEBUG " data_len = 0x%04x\n",
  3793. frame->p80211.data_len);
  3794. printk(KERN_DEBUG "IEEE 802.3 header:\n");
  3795. printk(KERN_DEBUG " dest = %02x:%02x:%02x:%02x:%02x:%02x\n",
  3796. frame->p8023.h_dest[0], frame->p8023.h_dest[1],
  3797. frame->p8023.h_dest[2], frame->p8023.h_dest[3],
  3798. frame->p8023.h_dest[4], frame->p8023.h_dest[5]);
  3799. printk(KERN_DEBUG " src = %02x:%02x:%02x:%02x:%02x:%02x\n",
  3800. frame->p8023.h_source[0], frame->p8023.h_source[1],
  3801. frame->p8023.h_source[2], frame->p8023.h_source[3],
  3802. frame->p8023.h_source[4], frame->p8023.h_source[5]);
  3803. printk(KERN_DEBUG " len = 0x%04x\n", frame->p8023.h_proto);
  3804. printk(KERN_DEBUG "IEEE 802.2 LLC/SNAP header:\n");
  3805. printk(KERN_DEBUG " DSAP = 0x%02x\n", frame->p8022.dsap);
  3806. printk(KERN_DEBUG " SSAP = 0x%02x\n", frame->p8022.ssap);
  3807. printk(KERN_DEBUG " ctrl = 0x%02x\n", frame->p8022.ctrl);
  3808. printk(KERN_DEBUG " OUI = %02x:%02x:%02x\n",
  3809. frame->p8022.oui[0], frame->p8022.oui[1], frame->p8022.oui[2]);
  3810. printk(KERN_DEBUG " ethertype = 0x%04x\n", frame->ethertype);
  3811. }
  3812. #endif /* 0 */
  3813. /********************************************************************/
  3814. /* Module initialization */
  3815. /********************************************************************/
  3816. EXPORT_SYMBOL(alloc_orinocodev);
  3817. EXPORT_SYMBOL(free_orinocodev);
  3818. EXPORT_SYMBOL(__orinoco_up);
  3819. EXPORT_SYMBOL(__orinoco_down);
  3820. EXPORT_SYMBOL(orinoco_reinit_firmware);
  3821. EXPORT_SYMBOL(orinoco_interrupt);
  3822. /* Can't be declared "const" or the whole __initdata section will
  3823. * become const */
  3824. static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION
  3825. " (David Gibson <hermes@gibson.dropbear.id.au>, "
  3826. "Pavel Roskin <proski@gnu.org>, et al)";
  3827. static int __init init_orinoco(void)
  3828. {
  3829. printk(KERN_DEBUG "%s\n", version);
  3830. return 0;
  3831. }
  3832. static void __exit exit_orinoco(void)
  3833. {
  3834. }
  3835. module_init(init_orinoco);
  3836. module_exit(exit_orinoco);