orinoco.c 115 KB

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