orinoco.c 125 KB

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