orinoco.c 118 KB

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