orinoco.c 116 KB

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