orinoco.c 115 KB

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