orinoco.c 120 KB

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