orinoco.c 114 KB

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