orinoco.c 118 KB

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