orinoco.c 112 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058
  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. * v0.01 -> v0.02 - 21/3/2001 - Jean II
  49. * o Allow to use regular ethX device name instead of dldwdX
  50. * o Warning on IBSS with ESSID=any for firmware 6.06
  51. * o Put proper range.throughput values (optimistic)
  52. * o IWSPY support (IOCTL and stat gather in Rx path)
  53. * o Allow setting frequency in Ad-Hoc mode
  54. * o Disable WEP setting if !has_wep to work on old firmware
  55. * o Fix txpower range
  56. * o Start adding support for Samsung/Compaq firmware
  57. *
  58. * v0.02 -> v0.03 - 23/3/2001 - Jean II
  59. * o Start adding Symbol support - need to check all that
  60. * o Fix Prism2/Symbol WEP to accept 128 bits keys
  61. * o Add Symbol WEP (add authentication type)
  62. * o Add Prism2/Symbol rate
  63. * o Add PM timeout (holdover duration)
  64. * o Enable "iwconfig eth0 key off" and friends (toggle flags)
  65. * o Enable "iwconfig eth0 power unicast/all" (toggle flags)
  66. * o Try with an Intel card. It report firmware 1.01, behave like
  67. * an antiquated firmware, however on windows it says 2.00. Yuck !
  68. * o Workaround firmware bug in allocate buffer (Intel 1.01)
  69. * o Finish external renaming to orinoco...
  70. * o Testing with various Wavelan firmwares
  71. *
  72. * v0.03 -> v0.04 - 30/3/2001 - Jean II
  73. * o Update to Wireless 11 -> add retry limit/lifetime support
  74. * o Tested with a D-Link DWL 650 card, fill in firmware support
  75. * o Warning on Vcc mismatch (D-Link 3.3v card in Lucent 5v only slot)
  76. * o Fixed the Prism2 WEP bugs that I introduced in v0.03 :-(
  77. * It works on D-Link *only* after a tcpdump. Weird...
  78. * And still doesn't work on Intel card. Grrrr...
  79. * o Update the mode after a setport3
  80. * o Add preamble setting for Symbol cards (not yet enabled)
  81. * o Don't complain as much about Symbol cards...
  82. *
  83. * v0.04 -> v0.04b - 22/4/2001 - David Gibson
  84. * o Removed the 'eth' parameter - always use ethXX as the
  85. * interface name instead of dldwdXX. The other was racy
  86. * anyway.
  87. * o Clean up RID definitions in hermes.h, other cleanups
  88. *
  89. * v0.04b -> v0.04c - 24/4/2001 - Jean II
  90. * o Tim Hurley <timster AT seiki.bliztech.com> reported a D-Link card
  91. * with vendor 02 and firmware 0.08. Added in the capabilities...
  92. * o Tested Lucent firmware 7.28, everything works...
  93. *
  94. * v0.04c -> v0.05 - 3/5/2001 - Benjamin Herrenschmidt
  95. * o Spin-off Pcmcia code. This file is renamed orinoco.c,
  96. * and orinoco_cs.c now contains only the Pcmcia specific stuff
  97. * o Add Airport driver support on top of orinoco.c (see airport.c)
  98. *
  99. * v0.05 -> v0.05a - 4/5/2001 - Jean II
  100. * o Revert to old Pcmcia code to fix breakage of Ben's changes...
  101. *
  102. * v0.05a -> v0.05b - 4/5/2001 - Jean II
  103. * o add module parameter 'ignore_cis_vcc' for D-Link @ 5V
  104. * o D-Link firmware doesn't support multicast. We just print a few
  105. * error messages, but otherwise everything works...
  106. * o For David : set/getport3 works fine, just upgrade iwpriv...
  107. *
  108. * v0.05b -> v0.05c - 5/5/2001 - Benjamin Herrenschmidt
  109. * o Adapt airport.c to latest changes in orinoco.c
  110. * o Remove deferred power enabling code
  111. *
  112. * v0.05c -> v0.05d - 5/5/2001 - Jean II
  113. * o Workaround to SNAP decapsulate frame from Linksys AP
  114. * original patch from : Dong Liu <dliu AT research.bell-labs.com>
  115. * (note : the memcmp bug was mine - fixed)
  116. * o Remove set_retry stuff, no firmware support it (bloat--).
  117. *
  118. * v0.05d -> v0.06 - 25/5/2001 - Jean II
  119. * Original patch from "Hong Lin" <alin AT redhat.com>,
  120. * "Ian Kinner" <ikinner AT redhat.com>
  121. * and "David Smith" <dsmith AT redhat.com>
  122. * o Init of priv->tx_rate_ctrl in firmware specific section.
  123. * o Prism2/Symbol rate, upto should be 0xF and not 0x15. Doh !
  124. * o Spectrum card always need cor_reset (for every reset)
  125. * o Fix cor_reset to not lose bit 7 in the register
  126. * o flush_stale_links to remove zombie Pcmcia instances
  127. * o Ack previous hermes event before reset
  128. * Me (with my little hands)
  129. * o Allow orinoco.c to call cor_reset via priv->card_reset_handler
  130. * o Add priv->need_card_reset to toggle this feature
  131. * o Fix various buglets when setting WEP in Symbol firmware
  132. * Now, encryption is fully functional on Symbol cards. Youpi !
  133. *
  134. * v0.06 -> v0.06b - 25/5/2001 - Jean II
  135. * o IBSS on Symbol use port_mode = 4. Please don't ask...
  136. *
  137. * v0.06b -> v0.06c - 29/5/2001 - Jean II
  138. * o Show first spy address in /proc/net/wireless for IBSS mode as well
  139. *
  140. * v0.06c -> v0.06d - 6/7/2001 - David Gibson
  141. * o Change a bunch of KERN_INFO messages to KERN_DEBUG, as per Linus'
  142. * wishes to reduce the number of unnecessary messages.
  143. * o Removed bogus message on CRC error.
  144. * o Merged fixes for v0.08 Prism 2 firmware from William Waghorn
  145. * <willwaghorn AT yahoo.co.uk>
  146. * o Slight cleanup/re-arrangement of firmware detection code.
  147. *
  148. * v0.06d -> v0.06e - 1/8/2001 - David Gibson
  149. * o Removed some redundant global initializers (orinoco_cs.c).
  150. * o Added some module metadata
  151. *
  152. * v0.06e -> v0.06f - 14/8/2001 - David Gibson
  153. * o Wording fix to license
  154. * o Added a 'use_alternate_encaps' module parameter for APs which need an
  155. * oui of 00:00:00. We really need a better way of handling this, but
  156. * the module flag is better than nothing for now.
  157. *
  158. * v0.06f -> v0.07 - 20/8/2001 - David Gibson
  159. * o Removed BAP error retries from hermes_bap_seek(). For Tx we now
  160. * let the upper layers handle the retry, we retry explicitly in the
  161. * Rx path, but don't make as much noise about it.
  162. * o Firmware detection cleanups.
  163. *
  164. * v0.07 -> v0.07a - 1/10/3001 - Jean II
  165. * o Add code to read Symbol firmware revision, inspired by latest code
  166. * in Spectrum24 by Lee John Keyser-Allen - Thanks Lee !
  167. * o Thanks to Jared Valentine <hidden AT xmission.com> for "providing" me
  168. * a 3Com card with a recent firmware, fill out Symbol firmware
  169. * capabilities of latest rev (2.20), as well as older Symbol cards.
  170. * o Disable Power Management in newer Symbol firmware, the API
  171. * has changed (documentation needed).
  172. *
  173. * v0.07a -> v0.08 - 3/10/2001 - David Gibson
  174. * o Fixed a possible buffer overrun found by the Stanford checker (in
  175. * dldwd_ioctl_setiwencode()). Can only be called by root anyway, so not
  176. * a big problem.
  177. * o Turned has_big_wep on for Intersil cards. That's not true for all of
  178. * them but we should at least let the capable ones try.
  179. * o Wait for BUSY to clear at the beginning of hermes_bap_seek(). I
  180. * realized that my assumption that the driver's serialization
  181. * would prevent the BAP being busy on entry was possibly false, because
  182. * things other than seeks may make the BAP busy.
  183. * o Use "alternate" (oui 00:00:00) encapsulation by default.
  184. * Setting use_old_encaps will mimic the old behaviour, but I think we
  185. * will be able to eliminate this.
  186. * o Don't try to make __initdata const (the version string). This can't
  187. * work because of the way the __initdata sectioning works.
  188. * o Added MODULE_LICENSE tags.
  189. * o Support for PLX (transparent PCMCIA->PCI bridge) cards.
  190. * o Changed to using the new type-fascist min/max.
  191. *
  192. * v0.08 -> v0.08a - 9/10/2001 - David Gibson
  193. * o Inserted some missing acknowledgements/info into the Changelog.
  194. * o Fixed some bugs in the normalization of signal level reporting.
  195. * o Fixed bad bug in WEP key handling on Intersil and Symbol firmware,
  196. * which led to an instant crash on big-endian machines.
  197. *
  198. * v0.08a -> v0.08b - 20/11/2001 - David Gibson
  199. * o Lots of cleanup and bugfixes in orinoco_plx.c
  200. * o Cleanup to handling of Tx rate setting.
  201. * o Removed support for old encapsulation method.
  202. * o Removed old "dldwd" names.
  203. * o Split RID constants into a new file hermes_rid.h
  204. * o Renamed RID constants to match linux-wlan-ng and prism2.o
  205. * o Bugfixes in hermes.c
  206. * o Poke the PLX's INTCSR register, so it actually starts
  207. * generating interrupts. These cards might actually work now.
  208. * o Update to wireless extensions v12 (Jean II)
  209. * o Support for tallies and inquire command (Jean II)
  210. * o Airport updates for newer PPC kernels (BenH)
  211. *
  212. * v0.08b -> v0.09 - 21/12/2001 - David Gibson
  213. * o Some new PCI IDs for PLX cards.
  214. * o Removed broken attempt to do ALLMULTI reception. Just use
  215. * promiscuous mode instead
  216. * o Preliminary work for list-AP (Jean II)
  217. * o Airport updates from (BenH)
  218. * o Eliminated racy hw_ready stuff
  219. * o Fixed generation of fake events in irq handler. This should
  220. * finally kill the EIO problems (Jean II & dgibson)
  221. * o Fixed breakage of bitrate set/get on Agere firmware (Jean II)
  222. *
  223. * v0.09 -> v0.09a - 2/1/2002 - David Gibson
  224. * o Fixed stupid mistake in multicast list handling, triggering
  225. * a BUG()
  226. *
  227. * v0.09a -> v0.09b - 16/1/2002 - David Gibson
  228. * o Fixed even stupider mistake in new interrupt handling, which
  229. * seriously broke things on big-endian machines.
  230. * o Removed a bunch of redundant includes and exports.
  231. * o Removed a redundant MOD_{INC,DEC}_USE_COUNT pair in airport.c
  232. * o Don't attempt to do hardware level multicast reception on
  233. * Intersil firmware, just go promisc instead.
  234. * o Typo fixed in hermes_issue_cmd()
  235. * o Eliminated WIRELESS_SPY #ifdefs
  236. * o Status code reported on Tx exceptions
  237. * o Moved netif_wake_queue() from ALLOC interrupts to TX and TXEXC
  238. * interrupts, which should fix the timeouts we're seeing.
  239. *
  240. * v0.09b -> v0.10 - 25 Feb 2002 - David Gibson
  241. * o Removed nested structures used for header parsing, so the
  242. * driver should now work without hackery on ARM
  243. * o Fix for WEP handling on Intersil (Hawk Newton)
  244. * o Eliminated the /proc/hermes/ethXX/regs debugging file. It
  245. * was never very useful.
  246. * o Make Rx errors less noisy.
  247. *
  248. * v0.10 -> v0.11 - 5 Apr 2002 - David Gibson
  249. * o Laid the groundwork in hermes.[ch] for devices which map
  250. * into PCI memory space rather than IO space.
  251. * o Fixed bug in multicast handling (cleared multicast list when
  252. * leaving promiscuous mode).
  253. * o Relegated Tx error messages to debug.
  254. * o Cleaned up / corrected handling of allocation lengths.
  255. * o Set OWNSSID in IBSS mode for WinXP interoperability (jimc).
  256. * o Change to using alloc_etherdev() for structure allocations.
  257. * o Check for and drop undersized packets.
  258. * o Fixed a race in stopping/waking the queue. This should fix
  259. * the timeout problems (Pavel Roskin)
  260. * o Reverted to netif_wake_queue() on the ALLOC event.
  261. * o Fixes for recent Symbol firmwares which lack AP density
  262. * (Pavel Roskin).
  263. *
  264. * v0.11 -> v0.11a - 29 Apr 2002 - David Gibson
  265. * o Handle different register spacing, necessary for Prism 2.5
  266. * PCI adaptors (Steve Hill).
  267. * o Cleaned up initialization of card structures in orinoco_cs
  268. * and airport. Removed card->priv field.
  269. * o Make response structure optional for hermes_docmd_wait()
  270. * Pavel Roskin)
  271. * o Added PCI id for Nortel emobility to orinoco_plx.c.
  272. * o Cleanup to handling of Symbol's allocation bug. (Pavel Roskin)
  273. * o Cleanups to firmware capability detection.
  274. * o Arrange for orinoco_pci.c to override firmware detection.
  275. * We should be able to support the PCI Intersil cards now.
  276. * o Cleanup handling of reset_cor and hard_reset (Pavel Roskin).
  277. * o Remove erroneous use of USER_BAP in the TxExc handler (Jouni
  278. * Malinen).
  279. * o Makefile changes for better integration into David Hinds
  280. * pcmcia-cs package.
  281. *
  282. * v0.11a -> v0.11b - 1 May 2002 - David Gibson
  283. * o Better error reporting in orinoco_plx_init_one()
  284. * o Fixed multiple bad kfree() bugs introduced by the
  285. * alloc_orinocodev() changes.
  286. *
  287. * v0.11b -> v0.12 - 19 Jun 2002 - David Gibson
  288. * o Support changing the MAC address.
  289. * o Correct display of Intersil firmware revision numbers.
  290. * o Entirely revised locking scheme. Should be both simpler and
  291. * better.
  292. * o Merged some common code in orinoco_plx, orinoco_pci and
  293. * airport by creating orinoco_default_{open,stop,reset}()
  294. * which are used as the dev->open, dev->stop, priv->reset
  295. * callbacks if none are specified when alloc_orinocodev() is
  296. * called.
  297. * o Removed orinoco_plx_interrupt() and orinoco_pci_interrupt().
  298. * They didn't do anything.
  299. *
  300. * v0.12 -> v0.12a - 4 Jul 2002 - David Gibson
  301. * o Some rearrangement of code.
  302. * o Numerous fixups to locking and rest handling, particularly
  303. * for PCMCIA.
  304. * o This allows open and stop net_device methods to be in
  305. * orinoco.c now, rather than in the init modules.
  306. * o In orinoco_cs.c link->priv now points to the struct
  307. * net_device not to the struct orinoco_private.
  308. * o Added a check for undersized SNAP frames, which could cause
  309. * crashes.
  310. *
  311. * v0.12a -> v0.12b - 11 Jul 2002 - David Gibson
  312. * o Fix hw->num_init testing code, so num_init is actually
  313. * incremented.
  314. * o Fix very stupid bug in orinoco_cs which broke compile with
  315. * CONFIG_SMP.
  316. * o Squashed a warning.
  317. *
  318. * v0.12b -> v0.12c - 26 Jul 2002 - David Gibson
  319. * o Change to C9X style designated initializers.
  320. * o Add support for 3Com AirConnect PCI.
  321. * o No longer ignore the hard_reset argument to
  322. * alloc_orinocodev(). Oops.
  323. *
  324. * v0.12c -> v0.13beta1 - 13 Sep 2002 - David Gibson
  325. * o Revert the broken 0.12* locking scheme and go to a new yet
  326. * simpler scheme.
  327. * o Do firmware resets only in orinoco_init() and when waking
  328. * the card from hard sleep.
  329. *
  330. * v0.13beta1 -> v0.13 - 27 Sep 2002 - David Gibson
  331. * o Re-introduced full resets (via schedule_task()) on Tx
  332. * timeout.
  333. *
  334. * v0.13 -> v0.13a - 30 Sep 2002 - David Gibson
  335. * o Minor cleanups to info frame handling. Add basic support
  336. * for linkstatus info frames.
  337. * o Include required kernel headers in orinoco.h, to avoid
  338. * compile problems.
  339. *
  340. * v0.13a -> v0.13b - 10 Feb 2003 - David Gibson
  341. * o Implemented hard reset for Airport cards
  342. * o Experimental suspend/resume implementation for orinoco_pci
  343. * o Abolished /proc debugging support, replaced with a debugging
  344. * iwpriv. Now it's ugly and simple instead of ugly and complex.
  345. * o Bugfix in hermes.c if the firmware returned a record length
  346. * of 0, we could go clobbering memory.
  347. * o Bugfix in orinoco_stop() - it used to fail if hw_unavailable
  348. * was set, which was usually true on PCMCIA hot removes.
  349. * o Track LINKSTATUS messages, silently drop Tx packets before
  350. * we are connected (avoids confusing the firmware), and only
  351. * give LINKSTATUS printk()s if the status has changed.
  352. *
  353. * v0.13b -> v0.13c - 11 Mar 2003 - David Gibson
  354. * o Cleanup: use dev instead of priv in various places.
  355. * o Bug fix: Don't ReleaseConfiguration on RESET_PHYSICAL event
  356. * if we're in the middle of a (driver initiated) hard reset.
  357. * o Bug fix: ETH_ZLEN is supposed to include the header
  358. * (Dionysus Blazakis & Manish Karir)
  359. * o Convert to using workqueues instead of taskqueues (and
  360. * backwards compatibility macros for pre 2.5.41 kernels).
  361. * o Drop redundant (I think...) MOD_{INC,DEC}_USE_COUNT in
  362. * airport.c
  363. * o New orinoco_tmd.c init module from Joerg Dorchain for
  364. * TMD7160 based PCI to PCMCIA bridges (similar to
  365. * orinoco_plx.c).
  366. *
  367. * v0.13c -> v0.13d - 22 Apr 2003 - David Gibson
  368. * o Make hw_unavailable a counter, rather than just a flag, this
  369. * is necessary to avoid some races (such as a card being
  370. * removed in the middle of orinoco_reset().
  371. * o Restore Release/RequestConfiguration in the PCMCIA event handler
  372. * when dealing with a driver initiated hard reset. This is
  373. * necessary to prevent hangs due to a spurious interrupt while
  374. * the reset is in progress.
  375. * o Clear the 802.11 header when transmitting, even though we
  376. * don't use it. This fixes a long standing bug on some
  377. * firmwares, which seem to get confused if that isn't done.
  378. * o Be less eager to de-encapsulate SNAP frames, only do so if
  379. * the OUI is 00:00:00 or 00:00:f8, leave others alone. The old
  380. * behaviour broke CDP (Cisco Discovery Protocol).
  381. * o Use dev instead of priv for free_irq() as well as
  382. * request_irq() (oops).
  383. * o Attempt to reset rather than giving up if we get too many
  384. * IRQs.
  385. * o Changed semantics of __orinoco_down() so it can be called
  386. * safely with hw_unavailable set. It also now clears the
  387. * linkstatus (since we're going to have to reassociate).
  388. *
  389. * v0.13d -> v0.13e - 12 May 2003 - David Gibson
  390. * o Support for post-2.5.68 return values from irq handler.
  391. * o Fixed bug where underlength packets would be double counted
  392. * in the rx_dropped statistics.
  393. * o Provided a module parameter to suppress linkstatus messages.
  394. *
  395. * v0.13e -> v0.14alpha1 - 30 Sep 2003 - David Gibson
  396. * o Replaced priv->connected logic with netif_carrier_on/off()
  397. * calls.
  398. * o Remove has_ibss_any and never set the CREATEIBSS RID when
  399. * the ESSID is empty. Too many firmwares break if we do.
  400. * o 2.6 merges: Replace pdev->slot_name with pci_name(), remove
  401. * __devinitdata from PCI ID tables, use free_netdev().
  402. * o Enabled shared-key authentication for Agere firmware (from
  403. * Robert J. Moore <Robert.J.Moore AT allanbank.com>
  404. * o Move netif_wake_queue() (back) to the Tx completion from the
  405. * ALLOC event. This seems to prevent/mitigate the rolling
  406. * error -110 problems at least on some Intersil firmwares.
  407. * Theoretically reduces performance, but I can't measure it.
  408. * Patch from Andrew Tridgell <tridge AT samba.org>
  409. *
  410. * v0.14alpha1 -> v0.14alpha2 - 20 Oct 2003 - David Gibson
  411. * o Correctly turn off shared-key authentication when requested
  412. * (bugfix from Robert J. Moore).
  413. * o Correct airport sleep interfaces for current 2.6 kernels.
  414. * o Add code for key change without disabling/enabling the MAC
  415. * port. This is supposed to allow 802.1x to work sanely, but
  416. * doesn't seem to yet.
  417. *
  418. * TODO
  419. * o New wireless extensions API (patch from Moustafa
  420. * Youssef, updated by Jim Carter and Pavel Roskin).
  421. * o Handle de-encapsulation within network layer, provide 802.11
  422. * headers (patch from Thomas 'Dent' Mirlacher)
  423. * o RF monitor mode support
  424. * o Fix possible races in SPY handling.
  425. * o Disconnect wireless extensions from fundamental configuration.
  426. * o (maybe) Software WEP support (patch from Stano Meduna).
  427. * o (maybe) Use multiple Tx buffers - driver handling queue
  428. * rather than firmware.
  429. */
  430. /* Locking and synchronization:
  431. *
  432. * The basic principle is that everything is serialized through a
  433. * single spinlock, priv->lock. The lock is used in user, bh and irq
  434. * context, so when taken outside hardirq context it should always be
  435. * taken with interrupts disabled. The lock protects both the
  436. * hardware and the struct orinoco_private.
  437. *
  438. * Another flag, priv->hw_unavailable indicates that the hardware is
  439. * unavailable for an extended period of time (e.g. suspended, or in
  440. * the middle of a hard reset). This flag is protected by the
  441. * spinlock. All code which touches the hardware should check the
  442. * flag after taking the lock, and if it is set, give up on whatever
  443. * they are doing and drop the lock again. The orinoco_lock()
  444. * function handles this (it unlocks and returns -EBUSY if
  445. * hw_unavailable is non-zero).
  446. */
  447. #define DRIVER_NAME "orinoco"
  448. #include <linux/config.h>
  449. #include <linux/module.h>
  450. #include <linux/kernel.h>
  451. #include <linux/init.h>
  452. #include <linux/ptrace.h>
  453. #include <linux/slab.h>
  454. #include <linux/string.h>
  455. #include <linux/timer.h>
  456. #include <linux/ioport.h>
  457. #include <linux/netdevice.h>
  458. #include <linux/if_arp.h>
  459. #include <linux/etherdevice.h>
  460. #include <linux/wireless.h>
  461. #include <asm/uaccess.h>
  462. #include <asm/io.h>
  463. #include <asm/system.h>
  464. #include "hermes.h"
  465. #include "hermes_rid.h"
  466. #include "orinoco.h"
  467. #include "ieee802_11.h"
  468. /********************************************************************/
  469. /* Module information */
  470. /********************************************************************/
  471. MODULE_AUTHOR("Pavel Roskin <proski@gnu.org> & David Gibson <hermes@gibson.dropbear.id.au>");
  472. MODULE_DESCRIPTION("Driver for Lucent Orinoco, Prism II based and similar wireless cards");
  473. MODULE_LICENSE("Dual MPL/GPL");
  474. /* Level of debugging. Used in the macros in orinoco.h */
  475. #ifdef ORINOCO_DEBUG
  476. int orinoco_debug = ORINOCO_DEBUG;
  477. module_param(orinoco_debug, int, 0644);
  478. MODULE_PARM_DESC(orinoco_debug, "Debug level");
  479. EXPORT_SYMBOL(orinoco_debug);
  480. #endif
  481. static int suppress_linkstatus; /* = 0 */
  482. module_param(suppress_linkstatus, bool, 0644);
  483. MODULE_PARM_DESC(suppress_linkstatus, "Don't log link status changes");
  484. static int ignore_disconnect; /* = 0 */
  485. module_param(ignore_disconnect, int, 0644);
  486. MODULE_PARM_DESC(ignore_disconnect, "Don't report lost link to the network layer");
  487. /********************************************************************/
  488. /* Compile time configuration and compatibility stuff */
  489. /********************************************************************/
  490. /* We do this this way to avoid ifdefs in the actual code */
  491. #ifdef WIRELESS_SPY
  492. #define SPY_NUMBER(priv) (priv->spy_number)
  493. #else
  494. #define SPY_NUMBER(priv) 0
  495. #endif /* WIRELESS_SPY */
  496. /********************************************************************/
  497. /* Internal constants */
  498. /********************************************************************/
  499. #define ORINOCO_MIN_MTU 256
  500. #define ORINOCO_MAX_MTU (IEEE802_11_DATA_LEN - ENCAPS_OVERHEAD)
  501. #define SYMBOL_MAX_VER_LEN (14)
  502. #define USER_BAP 0
  503. #define IRQ_BAP 1
  504. #define MAX_IRQLOOPS_PER_IRQ 10
  505. #define MAX_IRQLOOPS_PER_JIFFY (20000/HZ) /* Based on a guestimate of
  506. * how many events the
  507. * device could
  508. * legitimately generate */
  509. #define SMALL_KEY_SIZE 5
  510. #define LARGE_KEY_SIZE 13
  511. #define TX_NICBUF_SIZE_BUG 1585 /* Bug in Symbol firmware */
  512. #define DUMMY_FID 0xFFFF
  513. /*#define MAX_MULTICAST(priv) (priv->firmware_type == FIRMWARE_TYPE_AGERE ? \
  514. HERMES_MAX_MULTICAST : 0)*/
  515. #define MAX_MULTICAST(priv) (HERMES_MAX_MULTICAST)
  516. #define ORINOCO_INTEN (HERMES_EV_RX | HERMES_EV_ALLOC \
  517. | HERMES_EV_TX | HERMES_EV_TXEXC \
  518. | HERMES_EV_WTERR | HERMES_EV_INFO \
  519. | HERMES_EV_INFDROP )
  520. /********************************************************************/
  521. /* Data tables */
  522. /********************************************************************/
  523. /* The frequency of each channel in MHz */
  524. static const long channel_frequency[] = {
  525. 2412, 2417, 2422, 2427, 2432, 2437, 2442,
  526. 2447, 2452, 2457, 2462, 2467, 2472, 2484
  527. };
  528. #define NUM_CHANNELS ARRAY_SIZE(channel_frequency)
  529. /* This tables gives the actual meanings of the bitrate IDs returned
  530. * by the firmware. */
  531. static struct {
  532. int bitrate; /* in 100s of kilobits */
  533. int automatic;
  534. u16 agere_txratectrl;
  535. u16 intersil_txratectrl;
  536. } bitrate_table[] = {
  537. {110, 1, 3, 15}, /* Entry 0 is the default */
  538. {10, 0, 1, 1},
  539. {10, 1, 1, 1},
  540. {20, 0, 2, 2},
  541. {20, 1, 6, 3},
  542. {55, 0, 4, 4},
  543. {55, 1, 7, 7},
  544. {110, 0, 5, 8},
  545. };
  546. #define BITRATE_TABLE_SIZE ARRAY_SIZE(bitrate_table)
  547. /********************************************************************/
  548. /* Data types */
  549. /********************************************************************/
  550. struct header_struct {
  551. /* 802.3 */
  552. u8 dest[ETH_ALEN];
  553. u8 src[ETH_ALEN];
  554. u16 len;
  555. /* 802.2 */
  556. u8 dsap;
  557. u8 ssap;
  558. u8 ctrl;
  559. /* SNAP */
  560. u8 oui[3];
  561. u16 ethertype;
  562. } __attribute__ ((packed));
  563. /* 802.2 LLC/SNAP header used for Ethernet encapsulation over 802.11 */
  564. u8 encaps_hdr[] = {0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00};
  565. #define ENCAPS_OVERHEAD (sizeof(encaps_hdr) + 2)
  566. struct hermes_rx_descriptor {
  567. u16 status;
  568. u32 time;
  569. u8 silence;
  570. u8 signal;
  571. u8 rate;
  572. u8 rxflow;
  573. u32 reserved;
  574. } __attribute__ ((packed));
  575. /********************************************************************/
  576. /* Function prototypes */
  577. /********************************************************************/
  578. static int orinoco_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
  579. static int __orinoco_program_rids(struct net_device *dev);
  580. static void __orinoco_set_multicast_list(struct net_device *dev);
  581. /********************************************************************/
  582. /* Internal helper functions */
  583. /********************************************************************/
  584. static inline void set_port_type(struct orinoco_private *priv)
  585. {
  586. switch (priv->iw_mode) {
  587. case IW_MODE_INFRA:
  588. priv->port_type = 1;
  589. priv->createibss = 0;
  590. break;
  591. case IW_MODE_ADHOC:
  592. if (priv->prefer_port3) {
  593. priv->port_type = 3;
  594. priv->createibss = 0;
  595. } else {
  596. priv->port_type = priv->ibss_port;
  597. priv->createibss = 1;
  598. }
  599. break;
  600. default:
  601. printk(KERN_ERR "%s: Invalid priv->iw_mode in set_port_type()\n",
  602. priv->ndev->name);
  603. }
  604. }
  605. /********************************************************************/
  606. /* Device methods */
  607. /********************************************************************/
  608. static int orinoco_open(struct net_device *dev)
  609. {
  610. struct orinoco_private *priv = netdev_priv(dev);
  611. unsigned long flags;
  612. int err;
  613. if (orinoco_lock(priv, &flags) != 0)
  614. return -EBUSY;
  615. err = __orinoco_up(dev);
  616. if (! err)
  617. priv->open = 1;
  618. orinoco_unlock(priv, &flags);
  619. return err;
  620. }
  621. int orinoco_stop(struct net_device *dev)
  622. {
  623. struct orinoco_private *priv = netdev_priv(dev);
  624. int err = 0;
  625. /* We mustn't use orinoco_lock() here, because we need to be
  626. able to close the interface even if hw_unavailable is set
  627. (e.g. as we're released after a PC Card removal) */
  628. spin_lock_irq(&priv->lock);
  629. priv->open = 0;
  630. err = __orinoco_down(dev);
  631. spin_unlock_irq(&priv->lock);
  632. return err;
  633. }
  634. static struct net_device_stats *orinoco_get_stats(struct net_device *dev)
  635. {
  636. struct orinoco_private *priv = netdev_priv(dev);
  637. return &priv->stats;
  638. }
  639. static struct iw_statistics *orinoco_get_wireless_stats(struct net_device *dev)
  640. {
  641. struct orinoco_private *priv = netdev_priv(dev);
  642. hermes_t *hw = &priv->hw;
  643. struct iw_statistics *wstats = &priv->wstats;
  644. int err;
  645. unsigned long flags;
  646. if (! netif_device_present(dev)) {
  647. printk(KERN_WARNING "%s: get_wireless_stats() called while device not present\n",
  648. dev->name);
  649. return NULL; /* FIXME: Can we do better than this? */
  650. }
  651. /* If busy, return the old stats. Returning NULL may cause
  652. * the interface to disappear from /proc/net/wireless */
  653. if (orinoco_lock(priv, &flags) != 0)
  654. return wstats;
  655. /* We can't really wait for the tallies inquiry command to
  656. * complete, so we just use the previous results and trigger
  657. * a new tallies inquiry command for next time - Jean II */
  658. /* FIXME: Really we should wait for the inquiry to come back -
  659. * as it is the stats we give don't make a whole lot of sense.
  660. * Unfortunately, it's not clear how to do that within the
  661. * wireless extensions framework: I think we're in user
  662. * context, but a lock seems to be held by the time we get in
  663. * here so we're not safe to sleep here. */
  664. hermes_inquire(hw, HERMES_INQ_TALLIES);
  665. if (priv->iw_mode == IW_MODE_ADHOC) {
  666. memset(&wstats->qual, 0, sizeof(wstats->qual));
  667. /* If a spy address is defined, we report stats of the
  668. * first spy address - Jean II */
  669. if (SPY_NUMBER(priv)) {
  670. wstats->qual.qual = priv->spy_stat[0].qual;
  671. wstats->qual.level = priv->spy_stat[0].level;
  672. wstats->qual.noise = priv->spy_stat[0].noise;
  673. wstats->qual.updated = priv->spy_stat[0].updated;
  674. }
  675. } else {
  676. struct {
  677. u16 qual, signal, noise;
  678. } __attribute__ ((packed)) cq;
  679. err = HERMES_READ_RECORD(hw, USER_BAP,
  680. HERMES_RID_COMMSQUALITY, &cq);
  681. if (!err) {
  682. wstats->qual.qual = (int)le16_to_cpu(cq.qual);
  683. wstats->qual.level = (int)le16_to_cpu(cq.signal) - 0x95;
  684. wstats->qual.noise = (int)le16_to_cpu(cq.noise) - 0x95;
  685. wstats->qual.updated = 7;
  686. }
  687. }
  688. orinoco_unlock(priv, &flags);
  689. return wstats;
  690. }
  691. static void orinoco_set_multicast_list(struct net_device *dev)
  692. {
  693. struct orinoco_private *priv = netdev_priv(dev);
  694. unsigned long flags;
  695. if (orinoco_lock(priv, &flags) != 0) {
  696. printk(KERN_DEBUG "%s: orinoco_set_multicast_list() "
  697. "called when hw_unavailable\n", dev->name);
  698. return;
  699. }
  700. __orinoco_set_multicast_list(dev);
  701. orinoco_unlock(priv, &flags);
  702. }
  703. static int orinoco_change_mtu(struct net_device *dev, int new_mtu)
  704. {
  705. struct orinoco_private *priv = netdev_priv(dev);
  706. if ( (new_mtu < ORINOCO_MIN_MTU) || (new_mtu > ORINOCO_MAX_MTU) )
  707. return -EINVAL;
  708. if ( (new_mtu + ENCAPS_OVERHEAD + IEEE802_11_HLEN) >
  709. (priv->nicbuf_size - ETH_HLEN) )
  710. return -EINVAL;
  711. dev->mtu = new_mtu;
  712. return 0;
  713. }
  714. /********************************************************************/
  715. /* Tx path */
  716. /********************************************************************/
  717. static int orinoco_xmit(struct sk_buff *skb, struct net_device *dev)
  718. {
  719. struct orinoco_private *priv = netdev_priv(dev);
  720. struct net_device_stats *stats = &priv->stats;
  721. hermes_t *hw = &priv->hw;
  722. int err = 0;
  723. u16 txfid = priv->txfid;
  724. char *p;
  725. struct ethhdr *eh;
  726. int len, data_len, data_off;
  727. struct hermes_tx_descriptor desc;
  728. unsigned long flags;
  729. TRACE_ENTER(dev->name);
  730. if (! netif_running(dev)) {
  731. printk(KERN_ERR "%s: Tx on stopped device!\n",
  732. dev->name);
  733. TRACE_EXIT(dev->name);
  734. return 1;
  735. }
  736. if (netif_queue_stopped(dev)) {
  737. printk(KERN_DEBUG "%s: Tx while transmitter busy!\n",
  738. dev->name);
  739. TRACE_EXIT(dev->name);
  740. return 1;
  741. }
  742. if (orinoco_lock(priv, &flags) != 0) {
  743. printk(KERN_ERR "%s: orinoco_xmit() called while hw_unavailable\n",
  744. dev->name);
  745. TRACE_EXIT(dev->name);
  746. return 1;
  747. }
  748. if (! netif_carrier_ok(dev)) {
  749. /* Oops, the firmware hasn't established a connection,
  750. silently drop the packet (this seems to be the
  751. safest approach). */
  752. stats->tx_errors++;
  753. orinoco_unlock(priv, &flags);
  754. dev_kfree_skb(skb);
  755. TRACE_EXIT(dev->name);
  756. return 0;
  757. }
  758. /* Length of the packet body */
  759. /* FIXME: what if the skb is smaller than this? */
  760. len = max_t(int,skb->len - ETH_HLEN, ETH_ZLEN - ETH_HLEN);
  761. eh = (struct ethhdr *)skb->data;
  762. memset(&desc, 0, sizeof(desc));
  763. desc.tx_control = cpu_to_le16(HERMES_TXCTRL_TX_OK | HERMES_TXCTRL_TX_EX);
  764. err = hermes_bap_pwrite(hw, USER_BAP, &desc, sizeof(desc), txfid, 0);
  765. if (err) {
  766. if (net_ratelimit())
  767. printk(KERN_ERR "%s: Error %d writing Tx descriptor "
  768. "to BAP\n", dev->name, err);
  769. stats->tx_errors++;
  770. goto fail;
  771. }
  772. /* Clear the 802.11 header and data length fields - some
  773. * firmwares (e.g. Lucent/Agere 8.xx) appear to get confused
  774. * if this isn't done. */
  775. hermes_clear_words(hw, HERMES_DATA0,
  776. HERMES_802_3_OFFSET - HERMES_802_11_OFFSET);
  777. /* Encapsulate Ethernet-II frames */
  778. if (ntohs(eh->h_proto) > ETH_DATA_LEN) { /* Ethernet-II frame */
  779. struct header_struct hdr;
  780. data_len = len;
  781. data_off = HERMES_802_3_OFFSET + sizeof(hdr);
  782. p = skb->data + ETH_HLEN;
  783. /* 802.3 header */
  784. memcpy(hdr.dest, eh->h_dest, ETH_ALEN);
  785. memcpy(hdr.src, eh->h_source, ETH_ALEN);
  786. hdr.len = htons(data_len + ENCAPS_OVERHEAD);
  787. /* 802.2 header */
  788. memcpy(&hdr.dsap, &encaps_hdr, sizeof(encaps_hdr));
  789. hdr.ethertype = eh->h_proto;
  790. err = hermes_bap_pwrite(hw, USER_BAP, &hdr, sizeof(hdr),
  791. txfid, HERMES_802_3_OFFSET);
  792. if (err) {
  793. if (net_ratelimit())
  794. printk(KERN_ERR "%s: Error %d writing packet "
  795. "header to BAP\n", dev->name, err);
  796. stats->tx_errors++;
  797. goto fail;
  798. }
  799. } else { /* IEEE 802.3 frame */
  800. data_len = len + ETH_HLEN;
  801. data_off = HERMES_802_3_OFFSET;
  802. p = skb->data;
  803. }
  804. /* Round up for odd length packets */
  805. err = hermes_bap_pwrite(hw, USER_BAP, p, ALIGN(data_len, 2),
  806. txfid, data_off);
  807. if (err) {
  808. printk(KERN_ERR "%s: Error %d writing packet to BAP\n",
  809. dev->name, err);
  810. stats->tx_errors++;
  811. goto fail;
  812. }
  813. /* Finally, we actually initiate the send */
  814. netif_stop_queue(dev);
  815. err = hermes_docmd_wait(hw, HERMES_CMD_TX | HERMES_CMD_RECL,
  816. txfid, NULL);
  817. if (err) {
  818. netif_start_queue(dev);
  819. printk(KERN_ERR "%s: Error %d transmitting packet\n",
  820. dev->name, err);
  821. stats->tx_errors++;
  822. goto fail;
  823. }
  824. dev->trans_start = jiffies;
  825. stats->tx_bytes += data_off + data_len;
  826. orinoco_unlock(priv, &flags);
  827. dev_kfree_skb(skb);
  828. TRACE_EXIT(dev->name);
  829. return 0;
  830. fail:
  831. TRACE_EXIT(dev->name);
  832. orinoco_unlock(priv, &flags);
  833. return err;
  834. }
  835. static void __orinoco_ev_alloc(struct net_device *dev, hermes_t *hw)
  836. {
  837. struct orinoco_private *priv = netdev_priv(dev);
  838. u16 fid = hermes_read_regn(hw, ALLOCFID);
  839. if (fid != priv->txfid) {
  840. if (fid != DUMMY_FID)
  841. printk(KERN_WARNING "%s: Allocate event on unexpected fid (%04X)\n",
  842. dev->name, fid);
  843. return;
  844. }
  845. hermes_write_regn(hw, ALLOCFID, DUMMY_FID);
  846. }
  847. static void __orinoco_ev_tx(struct net_device *dev, hermes_t *hw)
  848. {
  849. struct orinoco_private *priv = netdev_priv(dev);
  850. struct net_device_stats *stats = &priv->stats;
  851. stats->tx_packets++;
  852. netif_wake_queue(dev);
  853. hermes_write_regn(hw, TXCOMPLFID, DUMMY_FID);
  854. }
  855. static void __orinoco_ev_txexc(struct net_device *dev, hermes_t *hw)
  856. {
  857. struct orinoco_private *priv = netdev_priv(dev);
  858. struct net_device_stats *stats = &priv->stats;
  859. u16 fid = hermes_read_regn(hw, TXCOMPLFID);
  860. struct hermes_tx_descriptor desc;
  861. int err = 0;
  862. if (fid == DUMMY_FID)
  863. return; /* Nothing's really happened */
  864. err = hermes_bap_pread(hw, IRQ_BAP, &desc, sizeof(desc), fid, 0);
  865. if (err) {
  866. printk(KERN_WARNING "%s: Unable to read descriptor on Tx error "
  867. "(FID=%04X error %d)\n",
  868. dev->name, fid, err);
  869. } else {
  870. DEBUG(1, "%s: Tx error, status %d\n",
  871. dev->name, le16_to_cpu(desc.status));
  872. }
  873. stats->tx_errors++;
  874. netif_wake_queue(dev);
  875. hermes_write_regn(hw, TXCOMPLFID, DUMMY_FID);
  876. }
  877. static void orinoco_tx_timeout(struct net_device *dev)
  878. {
  879. struct orinoco_private *priv = netdev_priv(dev);
  880. struct net_device_stats *stats = &priv->stats;
  881. struct hermes *hw = &priv->hw;
  882. printk(KERN_WARNING "%s: Tx timeout! "
  883. "ALLOCFID=%04x, TXCOMPLFID=%04x, EVSTAT=%04x\n",
  884. dev->name, hermes_read_regn(hw, ALLOCFID),
  885. hermes_read_regn(hw, TXCOMPLFID), hermes_read_regn(hw, EVSTAT));
  886. stats->tx_errors++;
  887. schedule_work(&priv->reset_work);
  888. }
  889. /********************************************************************/
  890. /* Rx path (data frames) */
  891. /********************************************************************/
  892. /* Does the frame have a SNAP header indicating it should be
  893. * de-encapsulated to Ethernet-II? */
  894. static inline int is_ethersnap(void *_hdr)
  895. {
  896. u8 *hdr = _hdr;
  897. /* We de-encapsulate all packets which, a) have SNAP headers
  898. * (i.e. SSAP=DSAP=0xaa and CTRL=0x3 in the 802.2 LLC header
  899. * and where b) the OUI of the SNAP header is 00:00:00 or
  900. * 00:00:f8 - we need both because different APs appear to use
  901. * different OUIs for some reason */
  902. return (memcmp(hdr, &encaps_hdr, 5) == 0)
  903. && ( (hdr[5] == 0x00) || (hdr[5] == 0xf8) );
  904. }
  905. static inline void orinoco_spy_gather(struct net_device *dev, u_char *mac,
  906. int level, int noise)
  907. {
  908. struct orinoco_private *priv = netdev_priv(dev);
  909. int i;
  910. /* Gather wireless spy statistics: for each packet, compare the
  911. * source address with out list, and if match, get the stats... */
  912. for (i = 0; i < priv->spy_number; i++)
  913. if (!memcmp(mac, priv->spy_address[i], ETH_ALEN)) {
  914. priv->spy_stat[i].level = level - 0x95;
  915. priv->spy_stat[i].noise = noise - 0x95;
  916. priv->spy_stat[i].qual = (level > noise) ? (level - noise) : 0;
  917. priv->spy_stat[i].updated = 7;
  918. }
  919. }
  920. static void orinoco_stat_gather(struct net_device *dev,
  921. struct sk_buff *skb,
  922. struct hermes_rx_descriptor *desc)
  923. {
  924. struct orinoco_private *priv = netdev_priv(dev);
  925. /* Using spy support with lots of Rx packets, like in an
  926. * infrastructure (AP), will really slow down everything, because
  927. * the MAC address must be compared to each entry of the spy list.
  928. * If the user really asks for it (set some address in the
  929. * spy list), we do it, but he will pay the price.
  930. * Note that to get here, you need both WIRELESS_SPY
  931. * compiled in AND some addresses in the list !!!
  932. */
  933. /* Note : gcc will optimise the whole section away if
  934. * WIRELESS_SPY is not defined... - Jean II */
  935. if (SPY_NUMBER(priv)) {
  936. orinoco_spy_gather(dev, skb->mac.raw + ETH_ALEN,
  937. desc->signal, desc->silence);
  938. }
  939. }
  940. static void __orinoco_ev_rx(struct net_device *dev, hermes_t *hw)
  941. {
  942. struct orinoco_private *priv = netdev_priv(dev);
  943. struct net_device_stats *stats = &priv->stats;
  944. struct iw_statistics *wstats = &priv->wstats;
  945. struct sk_buff *skb = NULL;
  946. u16 rxfid, status;
  947. int length, data_len, data_off;
  948. char *p;
  949. struct hermes_rx_descriptor desc;
  950. struct header_struct hdr;
  951. struct ethhdr *eh;
  952. int err;
  953. rxfid = hermes_read_regn(hw, RXFID);
  954. err = hermes_bap_pread(hw, IRQ_BAP, &desc, sizeof(desc),
  955. rxfid, 0);
  956. if (err) {
  957. printk(KERN_ERR "%s: error %d reading Rx descriptor. "
  958. "Frame dropped.\n", dev->name, err);
  959. stats->rx_errors++;
  960. goto drop;
  961. }
  962. status = le16_to_cpu(desc.status);
  963. if (status & HERMES_RXSTAT_ERR) {
  964. if (status & HERMES_RXSTAT_UNDECRYPTABLE) {
  965. wstats->discard.code++;
  966. DEBUG(1, "%s: Undecryptable frame on Rx. Frame dropped.\n",
  967. dev->name);
  968. } else {
  969. stats->rx_crc_errors++;
  970. DEBUG(1, "%s: Bad CRC on Rx. Frame dropped.\n", dev->name);
  971. }
  972. stats->rx_errors++;
  973. goto drop;
  974. }
  975. /* For now we ignore the 802.11 header completely, assuming
  976. that the card's firmware has handled anything vital */
  977. err = hermes_bap_pread(hw, IRQ_BAP, &hdr, sizeof(hdr),
  978. rxfid, HERMES_802_3_OFFSET);
  979. if (err) {
  980. printk(KERN_ERR "%s: error %d reading frame header. "
  981. "Frame dropped.\n", dev->name, err);
  982. stats->rx_errors++;
  983. goto drop;
  984. }
  985. length = ntohs(hdr.len);
  986. /* Sanity checks */
  987. if (length < 3) { /* No for even an 802.2 LLC header */
  988. /* At least on Symbol firmware with PCF we get quite a
  989. lot of these legitimately - Poll frames with no
  990. data. */
  991. stats->rx_dropped++;
  992. goto drop;
  993. }
  994. if (length > IEEE802_11_DATA_LEN) {
  995. printk(KERN_WARNING "%s: Oversized frame received (%d bytes)\n",
  996. dev->name, length);
  997. stats->rx_length_errors++;
  998. stats->rx_errors++;
  999. goto drop;
  1000. }
  1001. /* We need space for the packet data itself, plus an ethernet
  1002. header, plus 2 bytes so we can align the IP header on a
  1003. 32bit boundary, plus 1 byte so we can read in odd length
  1004. packets from the card, which has an IO granularity of 16
  1005. bits */
  1006. skb = dev_alloc_skb(length+ETH_HLEN+2+1);
  1007. if (!skb) {
  1008. printk(KERN_WARNING "%s: Can't allocate skb for Rx\n",
  1009. dev->name);
  1010. goto drop;
  1011. }
  1012. skb_reserve(skb, 2); /* This way the IP header is aligned */
  1013. /* Handle decapsulation
  1014. * In most cases, the firmware tell us about SNAP frames.
  1015. * For some reason, the SNAP frames sent by LinkSys APs
  1016. * are not properly recognised by most firmwares.
  1017. * So, check ourselves */
  1018. if (((status & HERMES_RXSTAT_MSGTYPE) == HERMES_RXSTAT_1042) ||
  1019. ((status & HERMES_RXSTAT_MSGTYPE) == HERMES_RXSTAT_TUNNEL) ||
  1020. is_ethersnap(&hdr)) {
  1021. /* These indicate a SNAP within 802.2 LLC within
  1022. 802.11 frame which we'll need to de-encapsulate to
  1023. the original EthernetII frame. */
  1024. if (length < ENCAPS_OVERHEAD) { /* No room for full LLC+SNAP */
  1025. stats->rx_length_errors++;
  1026. goto drop;
  1027. }
  1028. /* Remove SNAP header, reconstruct EthernetII frame */
  1029. data_len = length - ENCAPS_OVERHEAD;
  1030. data_off = HERMES_802_3_OFFSET + sizeof(hdr);
  1031. eh = (struct ethhdr *)skb_put(skb, ETH_HLEN);
  1032. memcpy(eh, &hdr, 2 * ETH_ALEN);
  1033. eh->h_proto = hdr.ethertype;
  1034. } else {
  1035. /* All other cases indicate a genuine 802.3 frame. No
  1036. decapsulation needed. We just throw the whole
  1037. thing in, and hope the protocol layer can deal with
  1038. it as 802.3 */
  1039. data_len = length;
  1040. data_off = HERMES_802_3_OFFSET;
  1041. /* FIXME: we re-read from the card data we already read here */
  1042. }
  1043. p = skb_put(skb, data_len);
  1044. err = hermes_bap_pread(hw, IRQ_BAP, p, ALIGN(data_len, 2),
  1045. rxfid, data_off);
  1046. if (err) {
  1047. printk(KERN_ERR "%s: error %d reading frame. "
  1048. "Frame dropped.\n", dev->name, err);
  1049. stats->rx_errors++;
  1050. goto drop;
  1051. }
  1052. dev->last_rx = jiffies;
  1053. skb->dev = dev;
  1054. skb->protocol = eth_type_trans(skb, dev);
  1055. skb->ip_summed = CHECKSUM_NONE;
  1056. /* Process the wireless stats if needed */
  1057. orinoco_stat_gather(dev, skb, &desc);
  1058. /* Pass the packet to the networking stack */
  1059. netif_rx(skb);
  1060. stats->rx_packets++;
  1061. stats->rx_bytes += length;
  1062. return;
  1063. drop:
  1064. stats->rx_dropped++;
  1065. if (skb)
  1066. dev_kfree_skb_irq(skb);
  1067. return;
  1068. }
  1069. /********************************************************************/
  1070. /* Rx path (info frames) */
  1071. /********************************************************************/
  1072. static void print_linkstatus(struct net_device *dev, u16 status)
  1073. {
  1074. char * s;
  1075. if (suppress_linkstatus)
  1076. return;
  1077. switch (status) {
  1078. case HERMES_LINKSTATUS_NOT_CONNECTED:
  1079. s = "Not Connected";
  1080. break;
  1081. case HERMES_LINKSTATUS_CONNECTED:
  1082. s = "Connected";
  1083. break;
  1084. case HERMES_LINKSTATUS_DISCONNECTED:
  1085. s = "Disconnected";
  1086. break;
  1087. case HERMES_LINKSTATUS_AP_CHANGE:
  1088. s = "AP Changed";
  1089. break;
  1090. case HERMES_LINKSTATUS_AP_OUT_OF_RANGE:
  1091. s = "AP Out of Range";
  1092. break;
  1093. case HERMES_LINKSTATUS_AP_IN_RANGE:
  1094. s = "AP In Range";
  1095. break;
  1096. case HERMES_LINKSTATUS_ASSOC_FAILED:
  1097. s = "Association Failed";
  1098. break;
  1099. default:
  1100. s = "UNKNOWN";
  1101. }
  1102. printk(KERN_INFO "%s: New link status: %s (%04x)\n",
  1103. dev->name, s, status);
  1104. }
  1105. static void __orinoco_ev_info(struct net_device *dev, hermes_t *hw)
  1106. {
  1107. struct orinoco_private *priv = netdev_priv(dev);
  1108. u16 infofid;
  1109. struct {
  1110. u16 len;
  1111. u16 type;
  1112. } __attribute__ ((packed)) info;
  1113. int len, type;
  1114. int err;
  1115. /* This is an answer to an INQUIRE command that we did earlier,
  1116. * or an information "event" generated by the card
  1117. * The controller return to us a pseudo frame containing
  1118. * the information in question - Jean II */
  1119. infofid = hermes_read_regn(hw, INFOFID);
  1120. /* Read the info frame header - don't try too hard */
  1121. err = hermes_bap_pread(hw, IRQ_BAP, &info, sizeof(info),
  1122. infofid, 0);
  1123. if (err) {
  1124. printk(KERN_ERR "%s: error %d reading info frame. "
  1125. "Frame dropped.\n", dev->name, err);
  1126. return;
  1127. }
  1128. len = HERMES_RECLEN_TO_BYTES(le16_to_cpu(info.len));
  1129. type = le16_to_cpu(info.type);
  1130. switch (type) {
  1131. case HERMES_INQ_TALLIES: {
  1132. struct hermes_tallies_frame tallies;
  1133. struct iw_statistics *wstats = &priv->wstats;
  1134. if (len > sizeof(tallies)) {
  1135. printk(KERN_WARNING "%s: Tallies frame too long (%d bytes)\n",
  1136. dev->name, len);
  1137. len = sizeof(tallies);
  1138. }
  1139. /* Read directly the data (no seek) */
  1140. hermes_read_words(hw, HERMES_DATA1, (void *) &tallies,
  1141. len / 2); /* FIXME: blech! */
  1142. /* Increment our various counters */
  1143. /* wstats->discard.nwid - no wrong BSSID stuff */
  1144. wstats->discard.code +=
  1145. le16_to_cpu(tallies.RxWEPUndecryptable);
  1146. if (len == sizeof(tallies))
  1147. wstats->discard.code +=
  1148. le16_to_cpu(tallies.RxDiscards_WEPICVError) +
  1149. le16_to_cpu(tallies.RxDiscards_WEPExcluded);
  1150. wstats->discard.misc +=
  1151. le16_to_cpu(tallies.TxDiscardsWrongSA);
  1152. wstats->discard.fragment +=
  1153. le16_to_cpu(tallies.RxMsgInBadMsgFragments);
  1154. wstats->discard.retries +=
  1155. le16_to_cpu(tallies.TxRetryLimitExceeded);
  1156. /* wstats->miss.beacon - no match */
  1157. }
  1158. break;
  1159. case HERMES_INQ_LINKSTATUS: {
  1160. struct hermes_linkstatus linkstatus;
  1161. u16 newstatus;
  1162. int connected;
  1163. if (len != sizeof(linkstatus)) {
  1164. printk(KERN_WARNING "%s: Unexpected size for linkstatus frame (%d bytes)\n",
  1165. dev->name, len);
  1166. break;
  1167. }
  1168. hermes_read_words(hw, HERMES_DATA1, (void *) &linkstatus,
  1169. len / 2);
  1170. newstatus = le16_to_cpu(linkstatus.linkstatus);
  1171. connected = (newstatus == HERMES_LINKSTATUS_CONNECTED)
  1172. || (newstatus == HERMES_LINKSTATUS_AP_CHANGE)
  1173. || (newstatus == HERMES_LINKSTATUS_AP_IN_RANGE);
  1174. if (connected)
  1175. netif_carrier_on(dev);
  1176. else if (!ignore_disconnect)
  1177. netif_carrier_off(dev);
  1178. if (newstatus != priv->last_linkstatus)
  1179. print_linkstatus(dev, newstatus);
  1180. priv->last_linkstatus = newstatus;
  1181. }
  1182. break;
  1183. default:
  1184. printk(KERN_DEBUG "%s: Unknown information frame received: "
  1185. "type 0x%04x, length %d\n", dev->name, type, len);
  1186. /* We don't actually do anything about it */
  1187. break;
  1188. }
  1189. }
  1190. static void __orinoco_ev_infdrop(struct net_device *dev, hermes_t *hw)
  1191. {
  1192. if (net_ratelimit())
  1193. printk(KERN_DEBUG "%s: Information frame lost.\n", dev->name);
  1194. }
  1195. /********************************************************************/
  1196. /* Internal hardware control routines */
  1197. /********************************************************************/
  1198. int __orinoco_up(struct net_device *dev)
  1199. {
  1200. struct orinoco_private *priv = netdev_priv(dev);
  1201. struct hermes *hw = &priv->hw;
  1202. int err;
  1203. err = __orinoco_program_rids(dev);
  1204. if (err) {
  1205. printk(KERN_ERR "%s: Error %d configuring card\n",
  1206. dev->name, err);
  1207. return err;
  1208. }
  1209. /* Fire things up again */
  1210. hermes_set_irqmask(hw, ORINOCO_INTEN);
  1211. err = hermes_enable_port(hw, 0);
  1212. if (err) {
  1213. printk(KERN_ERR "%s: Error %d enabling MAC port\n",
  1214. dev->name, err);
  1215. return err;
  1216. }
  1217. netif_start_queue(dev);
  1218. return 0;
  1219. }
  1220. int __orinoco_down(struct net_device *dev)
  1221. {
  1222. struct orinoco_private *priv = netdev_priv(dev);
  1223. struct hermes *hw = &priv->hw;
  1224. int err;
  1225. netif_stop_queue(dev);
  1226. if (! priv->hw_unavailable) {
  1227. if (! priv->broken_disableport) {
  1228. err = hermes_disable_port(hw, 0);
  1229. if (err) {
  1230. /* Some firmwares (e.g. Intersil 1.3.x) seem
  1231. * to have problems disabling the port, oh
  1232. * well, too bad. */
  1233. printk(KERN_WARNING "%s: Error %d disabling MAC port\n",
  1234. dev->name, err);
  1235. priv->broken_disableport = 1;
  1236. }
  1237. }
  1238. hermes_set_irqmask(hw, 0);
  1239. hermes_write_regn(hw, EVACK, 0xffff);
  1240. }
  1241. /* firmware will have to reassociate */
  1242. netif_carrier_off(dev);
  1243. priv->last_linkstatus = 0xffff;
  1244. return 0;
  1245. }
  1246. int orinoco_reinit_firmware(struct net_device *dev)
  1247. {
  1248. struct orinoco_private *priv = netdev_priv(dev);
  1249. struct hermes *hw = &priv->hw;
  1250. int err;
  1251. err = hermes_init(hw);
  1252. if (err)
  1253. return err;
  1254. err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid);
  1255. if (err == -EIO) {
  1256. /* Try workaround for old Symbol firmware bug */
  1257. printk(KERN_WARNING "%s: firmware ALLOC bug detected "
  1258. "(old Symbol firmware?). Trying to work around... ",
  1259. dev->name);
  1260. priv->nicbuf_size = TX_NICBUF_SIZE_BUG;
  1261. err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid);
  1262. if (err)
  1263. printk("failed!\n");
  1264. else
  1265. printk("ok.\n");
  1266. }
  1267. return err;
  1268. }
  1269. static int __orinoco_hw_set_bitrate(struct orinoco_private *priv)
  1270. {
  1271. hermes_t *hw = &priv->hw;
  1272. int err = 0;
  1273. if (priv->bitratemode >= BITRATE_TABLE_SIZE) {
  1274. printk(KERN_ERR "%s: BUG: Invalid bitrate mode %d\n",
  1275. priv->ndev->name, priv->bitratemode);
  1276. return -EINVAL;
  1277. }
  1278. switch (priv->firmware_type) {
  1279. case FIRMWARE_TYPE_AGERE:
  1280. err = hermes_write_wordrec(hw, USER_BAP,
  1281. HERMES_RID_CNFTXRATECONTROL,
  1282. bitrate_table[priv->bitratemode].agere_txratectrl);
  1283. break;
  1284. case FIRMWARE_TYPE_INTERSIL:
  1285. case FIRMWARE_TYPE_SYMBOL:
  1286. err = hermes_write_wordrec(hw, USER_BAP,
  1287. HERMES_RID_CNFTXRATECONTROL,
  1288. bitrate_table[priv->bitratemode].intersil_txratectrl);
  1289. break;
  1290. default:
  1291. BUG();
  1292. }
  1293. return err;
  1294. }
  1295. /* Change the WEP keys and/or the current keys. Can be called
  1296. * either from __orinoco_hw_setup_wep() or directly from
  1297. * orinoco_ioctl_setiwencode(). In the later case the association
  1298. * with the AP is not broken (if the firmware can handle it),
  1299. * which is needed for 802.1x implementations. */
  1300. static int __orinoco_hw_setup_wepkeys(struct orinoco_private *priv)
  1301. {
  1302. hermes_t *hw = &priv->hw;
  1303. int err = 0;
  1304. switch (priv->firmware_type) {
  1305. case FIRMWARE_TYPE_AGERE:
  1306. err = HERMES_WRITE_RECORD(hw, USER_BAP,
  1307. HERMES_RID_CNFWEPKEYS_AGERE,
  1308. &priv->keys);
  1309. if (err)
  1310. return err;
  1311. err = hermes_write_wordrec(hw, USER_BAP,
  1312. HERMES_RID_CNFTXKEY_AGERE,
  1313. priv->tx_key);
  1314. if (err)
  1315. return err;
  1316. break;
  1317. case FIRMWARE_TYPE_INTERSIL:
  1318. case FIRMWARE_TYPE_SYMBOL:
  1319. {
  1320. int keylen;
  1321. int i;
  1322. /* Force uniform key length to work around firmware bugs */
  1323. keylen = le16_to_cpu(priv->keys[priv->tx_key].len);
  1324. if (keylen > LARGE_KEY_SIZE) {
  1325. printk(KERN_ERR "%s: BUG: Key %d has oversize length %d.\n",
  1326. priv->ndev->name, priv->tx_key, keylen);
  1327. return -E2BIG;
  1328. }
  1329. /* Write all 4 keys */
  1330. for(i = 0; i < ORINOCO_MAX_KEYS; i++) {
  1331. err = hermes_write_ltv(hw, USER_BAP,
  1332. HERMES_RID_CNFDEFAULTKEY0 + i,
  1333. HERMES_BYTES_TO_RECLEN(keylen),
  1334. priv->keys[i].data);
  1335. if (err)
  1336. return err;
  1337. }
  1338. /* Write the index of the key used in transmission */
  1339. err = hermes_write_wordrec(hw, USER_BAP,
  1340. HERMES_RID_CNFWEPDEFAULTKEYID,
  1341. priv->tx_key);
  1342. if (err)
  1343. return err;
  1344. }
  1345. break;
  1346. }
  1347. return 0;
  1348. }
  1349. static int __orinoco_hw_setup_wep(struct orinoco_private *priv)
  1350. {
  1351. hermes_t *hw = &priv->hw;
  1352. int err = 0;
  1353. int master_wep_flag;
  1354. int auth_flag;
  1355. if (priv->wep_on)
  1356. __orinoco_hw_setup_wepkeys(priv);
  1357. if (priv->wep_restrict)
  1358. auth_flag = HERMES_AUTH_SHARED_KEY;
  1359. else
  1360. auth_flag = HERMES_AUTH_OPEN;
  1361. switch (priv->firmware_type) {
  1362. case FIRMWARE_TYPE_AGERE: /* Agere style WEP */
  1363. if (priv->wep_on) {
  1364. /* Enable the shared-key authentication. */
  1365. err = hermes_write_wordrec(hw, USER_BAP,
  1366. HERMES_RID_CNFAUTHENTICATION_AGERE,
  1367. auth_flag);
  1368. }
  1369. err = hermes_write_wordrec(hw, USER_BAP,
  1370. HERMES_RID_CNFWEPENABLED_AGERE,
  1371. priv->wep_on);
  1372. if (err)
  1373. return err;
  1374. break;
  1375. case FIRMWARE_TYPE_INTERSIL: /* Intersil style WEP */
  1376. case FIRMWARE_TYPE_SYMBOL: /* Symbol style WEP */
  1377. if (priv->wep_on) {
  1378. if (priv->wep_restrict ||
  1379. (priv->firmware_type == FIRMWARE_TYPE_SYMBOL))
  1380. master_wep_flag = HERMES_WEP_PRIVACY_INVOKED |
  1381. HERMES_WEP_EXCL_UNENCRYPTED;
  1382. else
  1383. master_wep_flag = HERMES_WEP_PRIVACY_INVOKED;
  1384. err = hermes_write_wordrec(hw, USER_BAP,
  1385. HERMES_RID_CNFAUTHENTICATION,
  1386. auth_flag);
  1387. if (err)
  1388. return err;
  1389. } else
  1390. master_wep_flag = 0;
  1391. if (priv->iw_mode == IW_MODE_MONITOR)
  1392. master_wep_flag |= HERMES_WEP_HOST_DECRYPT;
  1393. /* Master WEP setting : on/off */
  1394. err = hermes_write_wordrec(hw, USER_BAP,
  1395. HERMES_RID_CNFWEPFLAGS_INTERSIL,
  1396. master_wep_flag);
  1397. if (err)
  1398. return err;
  1399. break;
  1400. }
  1401. return 0;
  1402. }
  1403. static int __orinoco_program_rids(struct net_device *dev)
  1404. {
  1405. struct orinoco_private *priv = netdev_priv(dev);
  1406. hermes_t *hw = &priv->hw;
  1407. int err;
  1408. struct hermes_idstring idbuf;
  1409. /* Set the MAC address */
  1410. err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNMACADDR,
  1411. HERMES_BYTES_TO_RECLEN(ETH_ALEN), dev->dev_addr);
  1412. if (err) {
  1413. printk(KERN_ERR "%s: Error %d setting MAC address\n",
  1414. dev->name, err);
  1415. return err;
  1416. }
  1417. /* Set up the link mode */
  1418. err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFPORTTYPE,
  1419. priv->port_type);
  1420. if (err) {
  1421. printk(KERN_ERR "%s: Error %d setting port type\n",
  1422. dev->name, err);
  1423. return err;
  1424. }
  1425. /* Set the channel/frequency */
  1426. if (priv->channel == 0) {
  1427. printk(KERN_DEBUG "%s: Channel is 0 in __orinoco_program_rids()\n", dev->name);
  1428. if (priv->createibss)
  1429. priv->channel = 10;
  1430. }
  1431. err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFOWNCHANNEL,
  1432. priv->channel);
  1433. if (err) {
  1434. printk(KERN_ERR "%s: Error %d setting channel\n",
  1435. dev->name, err);
  1436. return err;
  1437. }
  1438. if (priv->has_ibss) {
  1439. u16 createibss;
  1440. if ((strlen(priv->desired_essid) == 0) && (priv->createibss)) {
  1441. printk(KERN_WARNING "%s: This firmware requires an "
  1442. "ESSID in IBSS-Ad-Hoc mode.\n", dev->name);
  1443. /* With wvlan_cs, in this case, we would crash.
  1444. * hopefully, this driver will behave better...
  1445. * Jean II */
  1446. createibss = 0;
  1447. } else {
  1448. createibss = priv->createibss;
  1449. }
  1450. err = hermes_write_wordrec(hw, USER_BAP,
  1451. HERMES_RID_CNFCREATEIBSS,
  1452. createibss);
  1453. if (err) {
  1454. printk(KERN_ERR "%s: Error %d setting CREATEIBSS\n",
  1455. dev->name, err);
  1456. return err;
  1457. }
  1458. }
  1459. /* Set the desired ESSID */
  1460. idbuf.len = cpu_to_le16(strlen(priv->desired_essid));
  1461. memcpy(&idbuf.val, priv->desired_essid, sizeof(idbuf.val));
  1462. /* WinXP wants partner to configure OWNSSID even in IBSS mode. (jimc) */
  1463. err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNSSID,
  1464. HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid)+2),
  1465. &idbuf);
  1466. if (err) {
  1467. printk(KERN_ERR "%s: Error %d setting OWNSSID\n",
  1468. dev->name, err);
  1469. return err;
  1470. }
  1471. err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFDESIREDSSID,
  1472. HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid)+2),
  1473. &idbuf);
  1474. if (err) {
  1475. printk(KERN_ERR "%s: Error %d setting DESIREDSSID\n",
  1476. dev->name, err);
  1477. return err;
  1478. }
  1479. /* Set the station name */
  1480. idbuf.len = cpu_to_le16(strlen(priv->nick));
  1481. memcpy(&idbuf.val, priv->nick, sizeof(idbuf.val));
  1482. err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNNAME,
  1483. HERMES_BYTES_TO_RECLEN(strlen(priv->nick)+2),
  1484. &idbuf);
  1485. if (err) {
  1486. printk(KERN_ERR "%s: Error %d setting nickname\n",
  1487. dev->name, err);
  1488. return err;
  1489. }
  1490. /* Set AP density */
  1491. if (priv->has_sensitivity) {
  1492. err = hermes_write_wordrec(hw, USER_BAP,
  1493. HERMES_RID_CNFSYSTEMSCALE,
  1494. priv->ap_density);
  1495. if (err) {
  1496. printk(KERN_WARNING "%s: Error %d setting SYSTEMSCALE. "
  1497. "Disabling sensitivity control\n",
  1498. dev->name, err);
  1499. priv->has_sensitivity = 0;
  1500. }
  1501. }
  1502. /* Set RTS threshold */
  1503. err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFRTSTHRESHOLD,
  1504. priv->rts_thresh);
  1505. if (err) {
  1506. printk(KERN_ERR "%s: Error %d setting RTS threshold\n",
  1507. dev->name, err);
  1508. return err;
  1509. }
  1510. /* Set fragmentation threshold or MWO robustness */
  1511. if (priv->has_mwo)
  1512. err = hermes_write_wordrec(hw, USER_BAP,
  1513. HERMES_RID_CNFMWOROBUST_AGERE,
  1514. priv->mwo_robust);
  1515. else
  1516. err = hermes_write_wordrec(hw, USER_BAP,
  1517. HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
  1518. priv->frag_thresh);
  1519. if (err) {
  1520. printk(KERN_ERR "%s: Error %d setting fragmentation\n",
  1521. dev->name, err);
  1522. return err;
  1523. }
  1524. /* Set bitrate */
  1525. err = __orinoco_hw_set_bitrate(priv);
  1526. if (err) {
  1527. printk(KERN_ERR "%s: Error %d setting bitrate\n",
  1528. dev->name, err);
  1529. return err;
  1530. }
  1531. /* Set power management */
  1532. if (priv->has_pm) {
  1533. err = hermes_write_wordrec(hw, USER_BAP,
  1534. HERMES_RID_CNFPMENABLED,
  1535. priv->pm_on);
  1536. if (err) {
  1537. printk(KERN_ERR "%s: Error %d setting up PM\n",
  1538. dev->name, err);
  1539. return err;
  1540. }
  1541. err = hermes_write_wordrec(hw, USER_BAP,
  1542. HERMES_RID_CNFMULTICASTRECEIVE,
  1543. priv->pm_mcast);
  1544. if (err) {
  1545. printk(KERN_ERR "%s: Error %d setting up PM\n",
  1546. dev->name, err);
  1547. return err;
  1548. }
  1549. err = hermes_write_wordrec(hw, USER_BAP,
  1550. HERMES_RID_CNFMAXSLEEPDURATION,
  1551. priv->pm_period);
  1552. if (err) {
  1553. printk(KERN_ERR "%s: Error %d setting up PM\n",
  1554. dev->name, err);
  1555. return err;
  1556. }
  1557. err = hermes_write_wordrec(hw, USER_BAP,
  1558. HERMES_RID_CNFPMHOLDOVERDURATION,
  1559. priv->pm_timeout);
  1560. if (err) {
  1561. printk(KERN_ERR "%s: Error %d setting up PM\n",
  1562. dev->name, err);
  1563. return err;
  1564. }
  1565. }
  1566. /* Set preamble - only for Symbol so far... */
  1567. if (priv->has_preamble) {
  1568. err = hermes_write_wordrec(hw, USER_BAP,
  1569. HERMES_RID_CNFPREAMBLE_SYMBOL,
  1570. priv->preamble);
  1571. if (err) {
  1572. printk(KERN_ERR "%s: Error %d setting preamble\n",
  1573. dev->name, err);
  1574. return err;
  1575. }
  1576. }
  1577. /* Set up encryption */
  1578. if (priv->has_wep) {
  1579. err = __orinoco_hw_setup_wep(priv);
  1580. if (err) {
  1581. printk(KERN_ERR "%s: Error %d activating WEP\n",
  1582. dev->name, err);
  1583. return err;
  1584. }
  1585. }
  1586. /* Set promiscuity / multicast*/
  1587. priv->promiscuous = 0;
  1588. priv->mc_count = 0;
  1589. __orinoco_set_multicast_list(dev); /* FIXME: what about the xmit_lock */
  1590. return 0;
  1591. }
  1592. /* FIXME: return int? */
  1593. static void
  1594. __orinoco_set_multicast_list(struct net_device *dev)
  1595. {
  1596. struct orinoco_private *priv = netdev_priv(dev);
  1597. hermes_t *hw = &priv->hw;
  1598. int err = 0;
  1599. int promisc, mc_count;
  1600. /* The Hermes doesn't seem to have an allmulti mode, so we go
  1601. * into promiscuous mode and let the upper levels deal. */
  1602. if ( (dev->flags & IFF_PROMISC) || (dev->flags & IFF_ALLMULTI) ||
  1603. (dev->mc_count > MAX_MULTICAST(priv)) ) {
  1604. promisc = 1;
  1605. mc_count = 0;
  1606. } else {
  1607. promisc = 0;
  1608. mc_count = dev->mc_count;
  1609. }
  1610. if (promisc != priv->promiscuous) {
  1611. err = hermes_write_wordrec(hw, USER_BAP,
  1612. HERMES_RID_CNFPROMISCUOUSMODE,
  1613. promisc);
  1614. if (err) {
  1615. printk(KERN_ERR "%s: Error %d setting PROMISCUOUSMODE to 1.\n",
  1616. dev->name, err);
  1617. } else
  1618. priv->promiscuous = promisc;
  1619. }
  1620. if (! promisc && (mc_count || priv->mc_count) ) {
  1621. struct dev_mc_list *p = dev->mc_list;
  1622. struct hermes_multicast mclist;
  1623. int i;
  1624. for (i = 0; i < mc_count; i++) {
  1625. /* paranoia: is list shorter than mc_count? */
  1626. BUG_ON(! p);
  1627. /* paranoia: bad address size in list? */
  1628. BUG_ON(p->dmi_addrlen != ETH_ALEN);
  1629. memcpy(mclist.addr[i], p->dmi_addr, ETH_ALEN);
  1630. p = p->next;
  1631. }
  1632. if (p)
  1633. printk(KERN_WARNING "%s: Multicast list is "
  1634. "longer than mc_count\n", dev->name);
  1635. err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFGROUPADDRESSES,
  1636. HERMES_BYTES_TO_RECLEN(priv->mc_count * ETH_ALEN),
  1637. &mclist);
  1638. if (err)
  1639. printk(KERN_ERR "%s: Error %d setting multicast list.\n",
  1640. dev->name, err);
  1641. else
  1642. priv->mc_count = mc_count;
  1643. }
  1644. /* Since we can set the promiscuous flag when it wasn't asked
  1645. for, make sure the net_device knows about it. */
  1646. if (priv->promiscuous)
  1647. dev->flags |= IFF_PROMISC;
  1648. else
  1649. dev->flags &= ~IFF_PROMISC;
  1650. }
  1651. static int orinoco_reconfigure(struct net_device *dev)
  1652. {
  1653. struct orinoco_private *priv = netdev_priv(dev);
  1654. struct hermes *hw = &priv->hw;
  1655. unsigned long flags;
  1656. int err = 0;
  1657. if (priv->broken_disableport) {
  1658. schedule_work(&priv->reset_work);
  1659. return 0;
  1660. }
  1661. if (orinoco_lock(priv, &flags) != 0)
  1662. return -EBUSY;
  1663. err = hermes_disable_port(hw, 0);
  1664. if (err) {
  1665. printk(KERN_WARNING "%s: Unable to disable port while reconfiguring card\n",
  1666. dev->name);
  1667. priv->broken_disableport = 1;
  1668. goto out;
  1669. }
  1670. err = __orinoco_program_rids(dev);
  1671. if (err) {
  1672. printk(KERN_WARNING "%s: Unable to reconfigure card\n",
  1673. dev->name);
  1674. goto out;
  1675. }
  1676. err = hermes_enable_port(hw, 0);
  1677. if (err) {
  1678. printk(KERN_WARNING "%s: Unable to enable port while reconfiguring card\n",
  1679. dev->name);
  1680. goto out;
  1681. }
  1682. out:
  1683. if (err) {
  1684. printk(KERN_WARNING "%s: Resetting instead...\n", dev->name);
  1685. schedule_work(&priv->reset_work);
  1686. err = 0;
  1687. }
  1688. orinoco_unlock(priv, &flags);
  1689. return err;
  1690. }
  1691. /* This must be called from user context, without locks held - use
  1692. * schedule_work() */
  1693. static void orinoco_reset(struct net_device *dev)
  1694. {
  1695. struct orinoco_private *priv = netdev_priv(dev);
  1696. struct hermes *hw = &priv->hw;
  1697. int err = 0;
  1698. unsigned long flags;
  1699. if (orinoco_lock(priv, &flags) != 0)
  1700. /* When the hardware becomes available again, whatever
  1701. * detects that is responsible for re-initializing
  1702. * it. So no need for anything further */
  1703. return;
  1704. netif_stop_queue(dev);
  1705. /* Shut off interrupts. Depending on what state the hardware
  1706. * is in, this might not work, but we'll try anyway */
  1707. hermes_set_irqmask(hw, 0);
  1708. hermes_write_regn(hw, EVACK, 0xffff);
  1709. priv->hw_unavailable++;
  1710. priv->last_linkstatus = 0xffff; /* firmware will have to reassociate */
  1711. netif_carrier_off(dev);
  1712. orinoco_unlock(priv, &flags);
  1713. if (priv->hard_reset)
  1714. err = (*priv->hard_reset)(priv);
  1715. if (err) {
  1716. printk(KERN_ERR "%s: orinoco_reset: Error %d "
  1717. "performing hard reset\n", dev->name, err);
  1718. /* FIXME: shutdown of some sort */
  1719. return;
  1720. }
  1721. err = orinoco_reinit_firmware(dev);
  1722. if (err) {
  1723. printk(KERN_ERR "%s: orinoco_reset: Error %d re-initializing firmware\n",
  1724. dev->name, err);
  1725. return;
  1726. }
  1727. spin_lock_irq(&priv->lock); /* This has to be called from user context */
  1728. priv->hw_unavailable--;
  1729. /* priv->open or priv->hw_unavailable might have changed while
  1730. * we dropped the lock */
  1731. if (priv->open && (! priv->hw_unavailable)) {
  1732. err = __orinoco_up(dev);
  1733. if (err) {
  1734. printk(KERN_ERR "%s: orinoco_reset: Error %d reenabling card\n",
  1735. dev->name, err);
  1736. } else
  1737. dev->trans_start = jiffies;
  1738. }
  1739. spin_unlock_irq(&priv->lock);
  1740. return;
  1741. }
  1742. /********************************************************************/
  1743. /* Interrupt handler */
  1744. /********************************************************************/
  1745. static void __orinoco_ev_tick(struct net_device *dev, hermes_t *hw)
  1746. {
  1747. printk(KERN_DEBUG "%s: TICK\n", dev->name);
  1748. }
  1749. static void __orinoco_ev_wterr(struct net_device *dev, hermes_t *hw)
  1750. {
  1751. /* This seems to happen a fair bit under load, but ignoring it
  1752. seems to work fine...*/
  1753. printk(KERN_DEBUG "%s: MAC controller error (WTERR). Ignoring.\n",
  1754. dev->name);
  1755. }
  1756. irqreturn_t orinoco_interrupt(int irq, void *dev_id, struct pt_regs *regs)
  1757. {
  1758. struct net_device *dev = (struct net_device *)dev_id;
  1759. struct orinoco_private *priv = netdev_priv(dev);
  1760. hermes_t *hw = &priv->hw;
  1761. int count = MAX_IRQLOOPS_PER_IRQ;
  1762. u16 evstat, events;
  1763. /* These are used to detect a runaway interrupt situation */
  1764. /* If we get more than MAX_IRQLOOPS_PER_JIFFY iterations in a jiffy,
  1765. * we panic and shut down the hardware */
  1766. static int last_irq_jiffy = 0; /* jiffies value the last time
  1767. * we were called */
  1768. static int loops_this_jiffy = 0;
  1769. unsigned long flags;
  1770. if (orinoco_lock(priv, &flags) != 0) {
  1771. /* If hw is unavailable - we don't know if the irq was
  1772. * for us or not */
  1773. return IRQ_HANDLED;
  1774. }
  1775. evstat = hermes_read_regn(hw, EVSTAT);
  1776. events = evstat & hw->inten;
  1777. if (! events) {
  1778. orinoco_unlock(priv, &flags);
  1779. return IRQ_NONE;
  1780. }
  1781. if (jiffies != last_irq_jiffy)
  1782. loops_this_jiffy = 0;
  1783. last_irq_jiffy = jiffies;
  1784. while (events && count--) {
  1785. if (++loops_this_jiffy > MAX_IRQLOOPS_PER_JIFFY) {
  1786. printk(KERN_WARNING "%s: IRQ handler is looping too "
  1787. "much! Resetting.\n", dev->name);
  1788. /* Disable interrupts for now */
  1789. hermes_set_irqmask(hw, 0);
  1790. schedule_work(&priv->reset_work);
  1791. break;
  1792. }
  1793. /* Check the card hasn't been removed */
  1794. if (! hermes_present(hw)) {
  1795. DEBUG(0, "orinoco_interrupt(): card removed\n");
  1796. break;
  1797. }
  1798. if (events & HERMES_EV_TICK)
  1799. __orinoco_ev_tick(dev, hw);
  1800. if (events & HERMES_EV_WTERR)
  1801. __orinoco_ev_wterr(dev, hw);
  1802. if (events & HERMES_EV_INFDROP)
  1803. __orinoco_ev_infdrop(dev, hw);
  1804. if (events & HERMES_EV_INFO)
  1805. __orinoco_ev_info(dev, hw);
  1806. if (events & HERMES_EV_RX)
  1807. __orinoco_ev_rx(dev, hw);
  1808. if (events & HERMES_EV_TXEXC)
  1809. __orinoco_ev_txexc(dev, hw);
  1810. if (events & HERMES_EV_TX)
  1811. __orinoco_ev_tx(dev, hw);
  1812. if (events & HERMES_EV_ALLOC)
  1813. __orinoco_ev_alloc(dev, hw);
  1814. hermes_write_regn(hw, EVACK, events);
  1815. evstat = hermes_read_regn(hw, EVSTAT);
  1816. events = evstat & hw->inten;
  1817. };
  1818. orinoco_unlock(priv, &flags);
  1819. return IRQ_HANDLED;
  1820. }
  1821. /********************************************************************/
  1822. /* Initialization */
  1823. /********************************************************************/
  1824. struct comp_id {
  1825. u16 id, variant, major, minor;
  1826. } __attribute__ ((packed));
  1827. static inline fwtype_t determine_firmware_type(struct comp_id *nic_id)
  1828. {
  1829. if (nic_id->id < 0x8000)
  1830. return FIRMWARE_TYPE_AGERE;
  1831. else if (nic_id->id == 0x8000 && nic_id->major == 0)
  1832. return FIRMWARE_TYPE_SYMBOL;
  1833. else
  1834. return FIRMWARE_TYPE_INTERSIL;
  1835. }
  1836. /* Set priv->firmware type, determine firmware properties */
  1837. static int determine_firmware(struct net_device *dev)
  1838. {
  1839. struct orinoco_private *priv = netdev_priv(dev);
  1840. hermes_t *hw = &priv->hw;
  1841. int err;
  1842. struct comp_id nic_id, sta_id;
  1843. unsigned int firmver;
  1844. char tmp[SYMBOL_MAX_VER_LEN+1];
  1845. /* Get the hardware version */
  1846. err = HERMES_READ_RECORD(hw, USER_BAP, HERMES_RID_NICID, &nic_id);
  1847. if (err) {
  1848. printk(KERN_ERR "%s: Cannot read hardware identity: error %d\n",
  1849. dev->name, err);
  1850. return err;
  1851. }
  1852. le16_to_cpus(&nic_id.id);
  1853. le16_to_cpus(&nic_id.variant);
  1854. le16_to_cpus(&nic_id.major);
  1855. le16_to_cpus(&nic_id.minor);
  1856. printk(KERN_DEBUG "%s: Hardware identity %04x:%04x:%04x:%04x\n",
  1857. dev->name, nic_id.id, nic_id.variant,
  1858. nic_id.major, nic_id.minor);
  1859. priv->firmware_type = determine_firmware_type(&nic_id);
  1860. /* Get the firmware version */
  1861. err = HERMES_READ_RECORD(hw, USER_BAP, HERMES_RID_STAID, &sta_id);
  1862. if (err) {
  1863. printk(KERN_ERR "%s: Cannot read station identity: error %d\n",
  1864. dev->name, err);
  1865. return err;
  1866. }
  1867. le16_to_cpus(&sta_id.id);
  1868. le16_to_cpus(&sta_id.variant);
  1869. le16_to_cpus(&sta_id.major);
  1870. le16_to_cpus(&sta_id.minor);
  1871. printk(KERN_DEBUG "%s: Station identity %04x:%04x:%04x:%04x\n",
  1872. dev->name, sta_id.id, sta_id.variant,
  1873. sta_id.major, sta_id.minor);
  1874. switch (sta_id.id) {
  1875. case 0x15:
  1876. printk(KERN_ERR "%s: Primary firmware is active\n",
  1877. dev->name);
  1878. return -ENODEV;
  1879. case 0x14b:
  1880. printk(KERN_ERR "%s: Tertiary firmware is active\n",
  1881. dev->name);
  1882. return -ENODEV;
  1883. case 0x1f: /* Intersil, Agere, Symbol Spectrum24 */
  1884. case 0x21: /* Symbol Spectrum24 Trilogy */
  1885. break;
  1886. default:
  1887. printk(KERN_NOTICE "%s: Unknown station ID, please report\n",
  1888. dev->name);
  1889. break;
  1890. }
  1891. /* Default capabilities */
  1892. priv->has_sensitivity = 1;
  1893. priv->has_mwo = 0;
  1894. priv->has_preamble = 0;
  1895. priv->has_port3 = 1;
  1896. priv->has_ibss = 1;
  1897. priv->has_wep = 0;
  1898. priv->has_big_wep = 0;
  1899. /* Determine capabilities from the firmware version */
  1900. switch (priv->firmware_type) {
  1901. case FIRMWARE_TYPE_AGERE:
  1902. /* Lucent Wavelan IEEE, Lucent Orinoco, Cabletron RoamAbout,
  1903. ELSA, Melco, HP, IBM, Dell 1150, Compaq 110/210 */
  1904. snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
  1905. "Lucent/Agere %d.%02d", sta_id.major, sta_id.minor);
  1906. firmver = ((unsigned long)sta_id.major << 16) | sta_id.minor;
  1907. priv->has_ibss = (firmver >= 0x60006);
  1908. priv->has_wep = (firmver >= 0x40020);
  1909. priv->has_big_wep = 1; /* FIXME: this is wrong - how do we tell
  1910. Gold cards from the others? */
  1911. priv->has_mwo = (firmver >= 0x60000);
  1912. priv->has_pm = (firmver >= 0x40020); /* Don't work in 7.52 ? */
  1913. priv->ibss_port = 1;
  1914. /* Tested with Agere firmware :
  1915. * 1.16 ; 4.08 ; 4.52 ; 6.04 ; 6.16 ; 7.28 => Jean II
  1916. * Tested CableTron firmware : 4.32 => Anton */
  1917. break;
  1918. case FIRMWARE_TYPE_SYMBOL:
  1919. /* Symbol , 3Com AirConnect, Intel, Ericsson WLAN */
  1920. /* Intel MAC : 00:02:B3:* */
  1921. /* 3Com MAC : 00:50:DA:* */
  1922. memset(tmp, 0, sizeof(tmp));
  1923. /* Get the Symbol firmware version */
  1924. err = hermes_read_ltv(hw, USER_BAP,
  1925. HERMES_RID_SECONDARYVERSION_SYMBOL,
  1926. SYMBOL_MAX_VER_LEN, NULL, &tmp);
  1927. if (err) {
  1928. printk(KERN_WARNING
  1929. "%s: Error %d reading Symbol firmware info. Wildly guessing capabilities...\n",
  1930. dev->name, err);
  1931. firmver = 0;
  1932. tmp[0] = '\0';
  1933. } else {
  1934. /* The firmware revision is a string, the format is
  1935. * something like : "V2.20-01".
  1936. * Quick and dirty parsing... - Jean II
  1937. */
  1938. firmver = ((tmp[1] - '0') << 16) | ((tmp[3] - '0') << 12)
  1939. | ((tmp[4] - '0') << 8) | ((tmp[6] - '0') << 4)
  1940. | (tmp[7] - '0');
  1941. tmp[SYMBOL_MAX_VER_LEN] = '\0';
  1942. }
  1943. snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
  1944. "Symbol %s", tmp);
  1945. priv->has_ibss = (firmver >= 0x20000);
  1946. priv->has_wep = (firmver >= 0x15012);
  1947. priv->has_big_wep = (firmver >= 0x20000);
  1948. priv->has_pm = (firmver >= 0x20000 && firmver < 0x22000) ||
  1949. (firmver >= 0x29000 && firmver < 0x30000) ||
  1950. firmver >= 0x31000;
  1951. priv->has_preamble = (firmver >= 0x20000);
  1952. priv->ibss_port = 4;
  1953. /* Tested with Intel firmware : 0x20015 => Jean II */
  1954. /* Tested with 3Com firmware : 0x15012 & 0x22001 => Jean II */
  1955. break;
  1956. case FIRMWARE_TYPE_INTERSIL:
  1957. /* D-Link, Linksys, Adtron, ZoomAir, and many others...
  1958. * Samsung, Compaq 100/200 and Proxim are slightly
  1959. * different and less well tested */
  1960. /* D-Link MAC : 00:40:05:* */
  1961. /* Addtron MAC : 00:90:D1:* */
  1962. snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
  1963. "Intersil %d.%d.%d", sta_id.major, sta_id.minor,
  1964. sta_id.variant);
  1965. firmver = ((unsigned long)sta_id.major << 16) |
  1966. ((unsigned long)sta_id.minor << 8) | sta_id.variant;
  1967. priv->has_ibss = (firmver >= 0x000700); /* FIXME */
  1968. priv->has_big_wep = priv->has_wep = (firmver >= 0x000800);
  1969. priv->has_pm = (firmver >= 0x000700);
  1970. if (firmver >= 0x000800)
  1971. priv->ibss_port = 0;
  1972. else {
  1973. printk(KERN_NOTICE "%s: Intersil firmware earlier "
  1974. "than v0.8.x - several features not supported\n",
  1975. dev->name);
  1976. priv->ibss_port = 1;
  1977. }
  1978. break;
  1979. }
  1980. printk(KERN_DEBUG "%s: Firmware determined as %s\n", dev->name,
  1981. priv->fw_name);
  1982. return 0;
  1983. }
  1984. static int orinoco_init(struct net_device *dev)
  1985. {
  1986. struct orinoco_private *priv = netdev_priv(dev);
  1987. hermes_t *hw = &priv->hw;
  1988. int err = 0;
  1989. struct hermes_idstring nickbuf;
  1990. u16 reclen;
  1991. int len;
  1992. TRACE_ENTER(dev->name);
  1993. /* No need to lock, the hw_unavailable flag is already set in
  1994. * alloc_orinocodev() */
  1995. priv->nicbuf_size = IEEE802_11_FRAME_LEN + ETH_HLEN;
  1996. /* Initialize the firmware */
  1997. err = hermes_init(hw);
  1998. if (err != 0) {
  1999. printk(KERN_ERR "%s: failed to initialize firmware (err = %d)\n",
  2000. dev->name, err);
  2001. goto out;
  2002. }
  2003. err = determine_firmware(dev);
  2004. if (err != 0) {
  2005. printk(KERN_ERR "%s: Incompatible firmware, aborting\n",
  2006. dev->name);
  2007. goto out;
  2008. }
  2009. if (priv->has_port3)
  2010. printk(KERN_DEBUG "%s: Ad-hoc demo mode supported\n", dev->name);
  2011. if (priv->has_ibss)
  2012. printk(KERN_DEBUG "%s: IEEE standard IBSS ad-hoc mode supported\n",
  2013. dev->name);
  2014. if (priv->has_wep) {
  2015. printk(KERN_DEBUG "%s: WEP supported, ", dev->name);
  2016. if (priv->has_big_wep)
  2017. printk("104-bit key\n");
  2018. else
  2019. printk("40-bit key\n");
  2020. }
  2021. /* Get the MAC address */
  2022. err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CNFOWNMACADDR,
  2023. ETH_ALEN, NULL, dev->dev_addr);
  2024. if (err) {
  2025. printk(KERN_WARNING "%s: failed to read MAC address!\n",
  2026. dev->name);
  2027. goto out;
  2028. }
  2029. printk(KERN_DEBUG "%s: MAC address %02X:%02X:%02X:%02X:%02X:%02X\n",
  2030. dev->name, dev->dev_addr[0], dev->dev_addr[1],
  2031. dev->dev_addr[2], dev->dev_addr[3], dev->dev_addr[4],
  2032. dev->dev_addr[5]);
  2033. /* Get the station name */
  2034. err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CNFOWNNAME,
  2035. sizeof(nickbuf), &reclen, &nickbuf);
  2036. if (err) {
  2037. printk(KERN_ERR "%s: failed to read station name\n",
  2038. dev->name);
  2039. goto out;
  2040. }
  2041. if (nickbuf.len)
  2042. len = min(IW_ESSID_MAX_SIZE, (int)le16_to_cpu(nickbuf.len));
  2043. else
  2044. len = min(IW_ESSID_MAX_SIZE, 2 * reclen);
  2045. memcpy(priv->nick, &nickbuf.val, len);
  2046. priv->nick[len] = '\0';
  2047. printk(KERN_DEBUG "%s: Station name \"%s\"\n", dev->name, priv->nick);
  2048. /* Get allowed channels */
  2049. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CHANNELLIST,
  2050. &priv->channel_mask);
  2051. if (err) {
  2052. printk(KERN_ERR "%s: failed to read channel list!\n",
  2053. dev->name);
  2054. goto out;
  2055. }
  2056. /* Get initial AP density */
  2057. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFSYSTEMSCALE,
  2058. &priv->ap_density);
  2059. if (err || priv->ap_density < 1 || priv->ap_density > 3) {
  2060. priv->has_sensitivity = 0;
  2061. }
  2062. /* Get initial RTS threshold */
  2063. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFRTSTHRESHOLD,
  2064. &priv->rts_thresh);
  2065. if (err) {
  2066. printk(KERN_ERR "%s: failed to read RTS threshold!\n",
  2067. dev->name);
  2068. goto out;
  2069. }
  2070. /* Get initial fragmentation settings */
  2071. if (priv->has_mwo)
  2072. err = hermes_read_wordrec(hw, USER_BAP,
  2073. HERMES_RID_CNFMWOROBUST_AGERE,
  2074. &priv->mwo_robust);
  2075. else
  2076. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
  2077. &priv->frag_thresh);
  2078. if (err) {
  2079. printk(KERN_ERR "%s: failed to read fragmentation settings!\n",
  2080. dev->name);
  2081. goto out;
  2082. }
  2083. /* Power management setup */
  2084. if (priv->has_pm) {
  2085. priv->pm_on = 0;
  2086. priv->pm_mcast = 1;
  2087. err = hermes_read_wordrec(hw, USER_BAP,
  2088. HERMES_RID_CNFMAXSLEEPDURATION,
  2089. &priv->pm_period);
  2090. if (err) {
  2091. printk(KERN_ERR "%s: failed to read power management period!\n",
  2092. dev->name);
  2093. goto out;
  2094. }
  2095. err = hermes_read_wordrec(hw, USER_BAP,
  2096. HERMES_RID_CNFPMHOLDOVERDURATION,
  2097. &priv->pm_timeout);
  2098. if (err) {
  2099. printk(KERN_ERR "%s: failed to read power management timeout!\n",
  2100. dev->name);
  2101. goto out;
  2102. }
  2103. }
  2104. /* Preamble setup */
  2105. if (priv->has_preamble) {
  2106. err = hermes_read_wordrec(hw, USER_BAP,
  2107. HERMES_RID_CNFPREAMBLE_SYMBOL,
  2108. &priv->preamble);
  2109. if (err)
  2110. goto out;
  2111. }
  2112. /* Set up the default configuration */
  2113. priv->iw_mode = IW_MODE_INFRA;
  2114. /* By default use IEEE/IBSS ad-hoc mode if we have it */
  2115. priv->prefer_port3 = priv->has_port3 && (! priv->has_ibss);
  2116. set_port_type(priv);
  2117. priv->channel = 10; /* default channel, more-or-less arbitrary */
  2118. priv->promiscuous = 0;
  2119. priv->wep_on = 0;
  2120. priv->tx_key = 0;
  2121. err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid);
  2122. if (err == -EIO) {
  2123. /* Try workaround for old Symbol firmware bug */
  2124. printk(KERN_WARNING "%s: firmware ALLOC bug detected "
  2125. "(old Symbol firmware?). Trying to work around... ",
  2126. dev->name);
  2127. priv->nicbuf_size = TX_NICBUF_SIZE_BUG;
  2128. err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid);
  2129. if (err)
  2130. printk("failed!\n");
  2131. else
  2132. printk("ok.\n");
  2133. }
  2134. if (err) {
  2135. printk("%s: Error %d allocating Tx buffer\n", dev->name, err);
  2136. goto out;
  2137. }
  2138. /* Make the hardware available, as long as it hasn't been
  2139. * removed elsewhere (e.g. by PCMCIA hot unplug) */
  2140. spin_lock_irq(&priv->lock);
  2141. priv->hw_unavailable--;
  2142. spin_unlock_irq(&priv->lock);
  2143. printk(KERN_DEBUG "%s: ready\n", dev->name);
  2144. out:
  2145. TRACE_EXIT(dev->name);
  2146. return err;
  2147. }
  2148. struct net_device *alloc_orinocodev(int sizeof_card,
  2149. int (*hard_reset)(struct orinoco_private *))
  2150. {
  2151. struct net_device *dev;
  2152. struct orinoco_private *priv;
  2153. dev = alloc_etherdev(sizeof(struct orinoco_private) + sizeof_card);
  2154. if (! dev)
  2155. return NULL;
  2156. priv = netdev_priv(dev);
  2157. priv->ndev = dev;
  2158. if (sizeof_card)
  2159. priv->card = (void *)((unsigned long)netdev_priv(dev)
  2160. + sizeof(struct orinoco_private));
  2161. else
  2162. priv->card = NULL;
  2163. /* Setup / override net_device fields */
  2164. dev->init = orinoco_init;
  2165. dev->hard_start_xmit = orinoco_xmit;
  2166. dev->tx_timeout = orinoco_tx_timeout;
  2167. dev->watchdog_timeo = HZ; /* 1 second timeout */
  2168. dev->get_stats = orinoco_get_stats;
  2169. dev->get_wireless_stats = orinoco_get_wireless_stats;
  2170. dev->do_ioctl = orinoco_ioctl;
  2171. dev->change_mtu = orinoco_change_mtu;
  2172. dev->set_multicast_list = orinoco_set_multicast_list;
  2173. /* we use the default eth_mac_addr for setting the MAC addr */
  2174. /* Set up default callbacks */
  2175. dev->open = orinoco_open;
  2176. dev->stop = orinoco_stop;
  2177. priv->hard_reset = hard_reset;
  2178. spin_lock_init(&priv->lock);
  2179. priv->open = 0;
  2180. priv->hw_unavailable = 1; /* orinoco_init() must clear this
  2181. * before anything else touches the
  2182. * hardware */
  2183. INIT_WORK(&priv->reset_work, (void (*)(void *))orinoco_reset, dev);
  2184. netif_carrier_off(dev);
  2185. priv->last_linkstatus = 0xffff;
  2186. return dev;
  2187. }
  2188. void free_orinocodev(struct net_device *dev)
  2189. {
  2190. free_netdev(dev);
  2191. }
  2192. /********************************************************************/
  2193. /* Wireless extensions */
  2194. /********************************************************************/
  2195. static int orinoco_hw_get_bssid(struct orinoco_private *priv,
  2196. char buf[ETH_ALEN])
  2197. {
  2198. hermes_t *hw = &priv->hw;
  2199. int err = 0;
  2200. unsigned long flags;
  2201. if (orinoco_lock(priv, &flags) != 0)
  2202. return -EBUSY;
  2203. err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTBSSID,
  2204. ETH_ALEN, NULL, buf);
  2205. orinoco_unlock(priv, &flags);
  2206. return err;
  2207. }
  2208. static int orinoco_hw_get_essid(struct orinoco_private *priv, int *active,
  2209. char buf[IW_ESSID_MAX_SIZE+1])
  2210. {
  2211. hermes_t *hw = &priv->hw;
  2212. int err = 0;
  2213. struct hermes_idstring essidbuf;
  2214. char *p = (char *)(&essidbuf.val);
  2215. int len;
  2216. unsigned long flags;
  2217. if (orinoco_lock(priv, &flags) != 0)
  2218. return -EBUSY;
  2219. if (strlen(priv->desired_essid) > 0) {
  2220. /* We read the desired SSID from the hardware rather
  2221. than from priv->desired_essid, just in case the
  2222. firmware is allowed to change it on us. I'm not
  2223. sure about this */
  2224. /* My guess is that the OWNSSID should always be whatever
  2225. * we set to the card, whereas CURRENT_SSID is the one that
  2226. * may change... - Jean II */
  2227. u16 rid;
  2228. *active = 1;
  2229. rid = (priv->port_type == 3) ? HERMES_RID_CNFOWNSSID :
  2230. HERMES_RID_CNFDESIREDSSID;
  2231. err = hermes_read_ltv(hw, USER_BAP, rid, sizeof(essidbuf),
  2232. NULL, &essidbuf);
  2233. if (err)
  2234. goto fail_unlock;
  2235. } else {
  2236. *active = 0;
  2237. err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTSSID,
  2238. sizeof(essidbuf), NULL, &essidbuf);
  2239. if (err)
  2240. goto fail_unlock;
  2241. }
  2242. len = le16_to_cpu(essidbuf.len);
  2243. memset(buf, 0, IW_ESSID_MAX_SIZE+1);
  2244. memcpy(buf, p, len);
  2245. buf[len] = '\0';
  2246. fail_unlock:
  2247. orinoco_unlock(priv, &flags);
  2248. return err;
  2249. }
  2250. static long orinoco_hw_get_freq(struct orinoco_private *priv)
  2251. {
  2252. hermes_t *hw = &priv->hw;
  2253. int err = 0;
  2254. u16 channel;
  2255. long freq = 0;
  2256. unsigned long flags;
  2257. if (orinoco_lock(priv, &flags) != 0)
  2258. return -EBUSY;
  2259. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CURRENTCHANNEL, &channel);
  2260. if (err)
  2261. goto out;
  2262. /* Intersil firmware 1.3.5 returns 0 when the interface is down */
  2263. if (channel == 0) {
  2264. err = -EBUSY;
  2265. goto out;
  2266. }
  2267. if ( (channel < 1) || (channel > NUM_CHANNELS) ) {
  2268. printk(KERN_WARNING "%s: Channel out of range (%d)!\n",
  2269. priv->ndev->name, channel);
  2270. err = -EBUSY;
  2271. goto out;
  2272. }
  2273. freq = channel_frequency[channel-1] * 100000;
  2274. out:
  2275. orinoco_unlock(priv, &flags);
  2276. if (err > 0)
  2277. err = -EBUSY;
  2278. return err ? err : freq;
  2279. }
  2280. static int orinoco_hw_get_bitratelist(struct orinoco_private *priv,
  2281. int *numrates, s32 *rates, int max)
  2282. {
  2283. hermes_t *hw = &priv->hw;
  2284. struct hermes_idstring list;
  2285. unsigned char *p = (unsigned char *)&list.val;
  2286. int err = 0;
  2287. int num;
  2288. int i;
  2289. unsigned long flags;
  2290. if (orinoco_lock(priv, &flags) != 0)
  2291. return -EBUSY;
  2292. err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_SUPPORTEDDATARATES,
  2293. sizeof(list), NULL, &list);
  2294. orinoco_unlock(priv, &flags);
  2295. if (err)
  2296. return err;
  2297. num = le16_to_cpu(list.len);
  2298. *numrates = num;
  2299. num = min(num, max);
  2300. for (i = 0; i < num; i++) {
  2301. rates[i] = (p[i] & 0x7f) * 500000; /* convert to bps */
  2302. }
  2303. return 0;
  2304. }
  2305. static int orinoco_ioctl_getiwrange(struct net_device *dev, struct iw_point *rrq)
  2306. {
  2307. struct orinoco_private *priv = netdev_priv(dev);
  2308. int err = 0;
  2309. int mode;
  2310. struct iw_range range;
  2311. int numrates;
  2312. int i, k;
  2313. unsigned long flags;
  2314. TRACE_ENTER(dev->name);
  2315. if (!access_ok(VERIFY_WRITE, rrq->pointer, sizeof(range)))
  2316. return -EFAULT;
  2317. rrq->length = sizeof(range);
  2318. if (orinoco_lock(priv, &flags) != 0)
  2319. return -EBUSY;
  2320. mode = priv->iw_mode;
  2321. orinoco_unlock(priv, &flags);
  2322. memset(&range, 0, sizeof(range));
  2323. /* Much of this shamelessly taken from wvlan_cs.c. No idea
  2324. * what it all means -dgibson */
  2325. range.we_version_compiled = WIRELESS_EXT;
  2326. range.we_version_source = 11;
  2327. range.min_nwid = range.max_nwid = 0; /* We don't use nwids */
  2328. /* Set available channels/frequencies */
  2329. range.num_channels = NUM_CHANNELS;
  2330. k = 0;
  2331. for (i = 0; i < NUM_CHANNELS; i++) {
  2332. if (priv->channel_mask & (1 << i)) {
  2333. range.freq[k].i = i + 1;
  2334. range.freq[k].m = channel_frequency[i] * 100000;
  2335. range.freq[k].e = 1;
  2336. k++;
  2337. }
  2338. if (k >= IW_MAX_FREQUENCIES)
  2339. break;
  2340. }
  2341. range.num_frequency = k;
  2342. range.sensitivity = 3;
  2343. if ((mode == IW_MODE_ADHOC) && (priv->spy_number == 0)){
  2344. /* Quality stats meaningless in ad-hoc mode */
  2345. range.max_qual.qual = 0;
  2346. range.max_qual.level = 0;
  2347. range.max_qual.noise = 0;
  2348. range.avg_qual.qual = 0;
  2349. range.avg_qual.level = 0;
  2350. range.avg_qual.noise = 0;
  2351. } else {
  2352. range.max_qual.qual = 0x8b - 0x2f;
  2353. range.max_qual.level = 0x2f - 0x95 - 1;
  2354. range.max_qual.noise = 0x2f - 0x95 - 1;
  2355. /* Need to get better values */
  2356. range.avg_qual.qual = 0x24;
  2357. range.avg_qual.level = 0xC2;
  2358. range.avg_qual.noise = 0x9E;
  2359. }
  2360. err = orinoco_hw_get_bitratelist(priv, &numrates,
  2361. range.bitrate, IW_MAX_BITRATES);
  2362. if (err)
  2363. return err;
  2364. range.num_bitrates = numrates;
  2365. /* Set an indication of the max TCP throughput in bit/s that we can
  2366. * expect using this interface. May be use for QoS stuff...
  2367. * Jean II */
  2368. if(numrates > 2)
  2369. range.throughput = 5 * 1000 * 1000; /* ~5 Mb/s */
  2370. else
  2371. range.throughput = 1.5 * 1000 * 1000; /* ~1.5 Mb/s */
  2372. range.min_rts = 0;
  2373. range.max_rts = 2347;
  2374. range.min_frag = 256;
  2375. range.max_frag = 2346;
  2376. if (orinoco_lock(priv, &flags) != 0)
  2377. return -EBUSY;
  2378. if (priv->has_wep) {
  2379. range.max_encoding_tokens = ORINOCO_MAX_KEYS;
  2380. range.encoding_size[0] = SMALL_KEY_SIZE;
  2381. range.num_encoding_sizes = 1;
  2382. if (priv->has_big_wep) {
  2383. range.encoding_size[1] = LARGE_KEY_SIZE;
  2384. range.num_encoding_sizes = 2;
  2385. }
  2386. } else {
  2387. range.num_encoding_sizes = 0;
  2388. range.max_encoding_tokens = 0;
  2389. }
  2390. orinoco_unlock(priv, &flags);
  2391. range.min_pmp = 0;
  2392. range.max_pmp = 65535000;
  2393. range.min_pmt = 0;
  2394. range.max_pmt = 65535 * 1000; /* ??? */
  2395. range.pmp_flags = IW_POWER_PERIOD;
  2396. range.pmt_flags = IW_POWER_TIMEOUT;
  2397. range.pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT | IW_POWER_UNICAST_R;
  2398. range.num_txpower = 1;
  2399. range.txpower[0] = 15; /* 15dBm */
  2400. range.txpower_capa = IW_TXPOW_DBM;
  2401. range.retry_capa = IW_RETRY_LIMIT | IW_RETRY_LIFETIME;
  2402. range.retry_flags = IW_RETRY_LIMIT;
  2403. range.r_time_flags = IW_RETRY_LIFETIME;
  2404. range.min_retry = 0;
  2405. range.max_retry = 65535; /* ??? */
  2406. range.min_r_time = 0;
  2407. range.max_r_time = 65535 * 1000; /* ??? */
  2408. if (copy_to_user(rrq->pointer, &range, sizeof(range)))
  2409. return -EFAULT;
  2410. TRACE_EXIT(dev->name);
  2411. return 0;
  2412. }
  2413. static int orinoco_ioctl_setiwencode(struct net_device *dev, struct iw_point *erq)
  2414. {
  2415. struct orinoco_private *priv = netdev_priv(dev);
  2416. int index = (erq->flags & IW_ENCODE_INDEX) - 1;
  2417. int setindex = priv->tx_key;
  2418. int enable = priv->wep_on;
  2419. int restricted = priv->wep_restrict;
  2420. u16 xlen = 0;
  2421. int err = 0;
  2422. char keybuf[ORINOCO_MAX_KEY_SIZE];
  2423. unsigned long flags;
  2424. if (! priv->has_wep)
  2425. return -EOPNOTSUPP;
  2426. if (erq->pointer) {
  2427. /* We actually have a key to set - check its length */
  2428. if (erq->length > LARGE_KEY_SIZE)
  2429. return -E2BIG;
  2430. if ( (erq->length > SMALL_KEY_SIZE) && !priv->has_big_wep )
  2431. return -E2BIG;
  2432. if (copy_from_user(keybuf, erq->pointer, erq->length))
  2433. return -EFAULT;
  2434. }
  2435. if (orinoco_lock(priv, &flags) != 0)
  2436. return -EBUSY;
  2437. if (erq->pointer) {
  2438. if ((index < 0) || (index >= ORINOCO_MAX_KEYS))
  2439. index = priv->tx_key;
  2440. /* Adjust key length to a supported value */
  2441. if (erq->length > SMALL_KEY_SIZE) {
  2442. xlen = LARGE_KEY_SIZE;
  2443. } else if (erq->length > 0) {
  2444. xlen = SMALL_KEY_SIZE;
  2445. } else
  2446. xlen = 0;
  2447. /* Switch on WEP if off */
  2448. if ((!enable) && (xlen > 0)) {
  2449. setindex = index;
  2450. enable = 1;
  2451. }
  2452. } else {
  2453. /* Important note : if the user do "iwconfig eth0 enc off",
  2454. * we will arrive there with an index of -1. This is valid
  2455. * but need to be taken care off... Jean II */
  2456. if ((index < 0) || (index >= ORINOCO_MAX_KEYS)) {
  2457. if((index != -1) || (erq->flags == 0)) {
  2458. err = -EINVAL;
  2459. goto out;
  2460. }
  2461. } else {
  2462. /* Set the index : Check that the key is valid */
  2463. if(priv->keys[index].len == 0) {
  2464. err = -EINVAL;
  2465. goto out;
  2466. }
  2467. setindex = index;
  2468. }
  2469. }
  2470. if (erq->flags & IW_ENCODE_DISABLED)
  2471. enable = 0;
  2472. if (erq->flags & IW_ENCODE_OPEN)
  2473. restricted = 0;
  2474. if (erq->flags & IW_ENCODE_RESTRICTED)
  2475. restricted = 1;
  2476. if (erq->pointer) {
  2477. priv->keys[index].len = cpu_to_le16(xlen);
  2478. memset(priv->keys[index].data, 0,
  2479. sizeof(priv->keys[index].data));
  2480. memcpy(priv->keys[index].data, keybuf, erq->length);
  2481. }
  2482. priv->tx_key = setindex;
  2483. /* Try fast key change if connected and only keys are changed */
  2484. if (priv->wep_on && enable && (priv->wep_restrict == restricted) &&
  2485. netif_carrier_ok(dev)) {
  2486. err = __orinoco_hw_setup_wepkeys(priv);
  2487. /* No need to commit if successful */
  2488. goto out;
  2489. }
  2490. priv->wep_on = enable;
  2491. priv->wep_restrict = restricted;
  2492. out:
  2493. orinoco_unlock(priv, &flags);
  2494. return err;
  2495. }
  2496. static int orinoco_ioctl_getiwencode(struct net_device *dev, struct iw_point *erq)
  2497. {
  2498. struct orinoco_private *priv = netdev_priv(dev);
  2499. int index = (erq->flags & IW_ENCODE_INDEX) - 1;
  2500. u16 xlen = 0;
  2501. char keybuf[ORINOCO_MAX_KEY_SIZE];
  2502. unsigned long flags;
  2503. if (! priv->has_wep)
  2504. return -EOPNOTSUPP;
  2505. if (orinoco_lock(priv, &flags) != 0)
  2506. return -EBUSY;
  2507. if ((index < 0) || (index >= ORINOCO_MAX_KEYS))
  2508. index = priv->tx_key;
  2509. erq->flags = 0;
  2510. if (! priv->wep_on)
  2511. erq->flags |= IW_ENCODE_DISABLED;
  2512. erq->flags |= index + 1;
  2513. if (priv->wep_restrict)
  2514. erq->flags |= IW_ENCODE_RESTRICTED;
  2515. else
  2516. erq->flags |= IW_ENCODE_OPEN;
  2517. xlen = le16_to_cpu(priv->keys[index].len);
  2518. erq->length = xlen;
  2519. memcpy(keybuf, priv->keys[index].data, ORINOCO_MAX_KEY_SIZE);
  2520. orinoco_unlock(priv, &flags);
  2521. if (erq->pointer) {
  2522. if (copy_to_user(erq->pointer, keybuf, xlen))
  2523. return -EFAULT;
  2524. }
  2525. return 0;
  2526. }
  2527. static int orinoco_ioctl_setessid(struct net_device *dev, struct iw_point *erq)
  2528. {
  2529. struct orinoco_private *priv = netdev_priv(dev);
  2530. char essidbuf[IW_ESSID_MAX_SIZE+1];
  2531. unsigned long flags;
  2532. /* Note : ESSID is ignored in Ad-Hoc demo mode, but we can set it
  2533. * anyway... - Jean II */
  2534. memset(&essidbuf, 0, sizeof(essidbuf));
  2535. if (erq->flags) {
  2536. if (erq->length > IW_ESSID_MAX_SIZE)
  2537. return -E2BIG;
  2538. if (copy_from_user(&essidbuf, erq->pointer, erq->length))
  2539. return -EFAULT;
  2540. essidbuf[erq->length] = '\0';
  2541. }
  2542. if (orinoco_lock(priv, &flags) != 0)
  2543. return -EBUSY;
  2544. memcpy(priv->desired_essid, essidbuf, sizeof(priv->desired_essid));
  2545. orinoco_unlock(priv, &flags);
  2546. return 0;
  2547. }
  2548. static int orinoco_ioctl_getessid(struct net_device *dev, struct iw_point *erq)
  2549. {
  2550. struct orinoco_private *priv = netdev_priv(dev);
  2551. char essidbuf[IW_ESSID_MAX_SIZE+1];
  2552. int active;
  2553. int err = 0;
  2554. unsigned long flags;
  2555. TRACE_ENTER(dev->name);
  2556. if (netif_running(dev)) {
  2557. err = orinoco_hw_get_essid(priv, &active, essidbuf);
  2558. if (err)
  2559. return err;
  2560. } else {
  2561. if (orinoco_lock(priv, &flags) != 0)
  2562. return -EBUSY;
  2563. memcpy(essidbuf, priv->desired_essid, sizeof(essidbuf));
  2564. orinoco_unlock(priv, &flags);
  2565. }
  2566. erq->flags = 1;
  2567. erq->length = strlen(essidbuf) + 1;
  2568. if (erq->pointer)
  2569. if (copy_to_user(erq->pointer, essidbuf, erq->length))
  2570. return -EFAULT;
  2571. TRACE_EXIT(dev->name);
  2572. return 0;
  2573. }
  2574. static int orinoco_ioctl_setnick(struct net_device *dev, struct iw_point *nrq)
  2575. {
  2576. struct orinoco_private *priv = netdev_priv(dev);
  2577. char nickbuf[IW_ESSID_MAX_SIZE+1];
  2578. unsigned long flags;
  2579. if (nrq->length > IW_ESSID_MAX_SIZE)
  2580. return -E2BIG;
  2581. memset(nickbuf, 0, sizeof(nickbuf));
  2582. if (copy_from_user(nickbuf, nrq->pointer, nrq->length))
  2583. return -EFAULT;
  2584. nickbuf[nrq->length] = '\0';
  2585. if (orinoco_lock(priv, &flags) != 0)
  2586. return -EBUSY;
  2587. memcpy(priv->nick, nickbuf, sizeof(priv->nick));
  2588. orinoco_unlock(priv, &flags);
  2589. return 0;
  2590. }
  2591. static int orinoco_ioctl_getnick(struct net_device *dev, struct iw_point *nrq)
  2592. {
  2593. struct orinoco_private *priv = netdev_priv(dev);
  2594. char nickbuf[IW_ESSID_MAX_SIZE+1];
  2595. unsigned long flags;
  2596. if (orinoco_lock(priv, &flags) != 0)
  2597. return -EBUSY;
  2598. memcpy(nickbuf, priv->nick, IW_ESSID_MAX_SIZE+1);
  2599. orinoco_unlock(priv, &flags);
  2600. nrq->length = strlen(nickbuf)+1;
  2601. if (copy_to_user(nrq->pointer, nickbuf, sizeof(nickbuf)))
  2602. return -EFAULT;
  2603. return 0;
  2604. }
  2605. static int orinoco_ioctl_setfreq(struct net_device *dev, struct iw_freq *frq)
  2606. {
  2607. struct orinoco_private *priv = netdev_priv(dev);
  2608. int chan = -1;
  2609. unsigned long flags;
  2610. /* We can only use this in Ad-Hoc demo mode to set the operating
  2611. * frequency, or in IBSS mode to set the frequency where the IBSS
  2612. * will be created - Jean II */
  2613. if (priv->iw_mode != IW_MODE_ADHOC)
  2614. return -EOPNOTSUPP;
  2615. if ( (frq->e == 0) && (frq->m <= 1000) ) {
  2616. /* Setting by channel number */
  2617. chan = frq->m;
  2618. } else {
  2619. /* Setting by frequency - search the table */
  2620. int mult = 1;
  2621. int i;
  2622. for (i = 0; i < (6 - frq->e); i++)
  2623. mult *= 10;
  2624. for (i = 0; i < NUM_CHANNELS; i++)
  2625. if (frq->m == (channel_frequency[i] * mult))
  2626. chan = i+1;
  2627. }
  2628. if ( (chan < 1) || (chan > NUM_CHANNELS) ||
  2629. ! (priv->channel_mask & (1 << (chan-1)) ) )
  2630. return -EINVAL;
  2631. if (orinoco_lock(priv, &flags) != 0)
  2632. return -EBUSY;
  2633. priv->channel = chan;
  2634. orinoco_unlock(priv, &flags);
  2635. return 0;
  2636. }
  2637. static int orinoco_ioctl_getsens(struct net_device *dev, struct iw_param *srq)
  2638. {
  2639. struct orinoco_private *priv = netdev_priv(dev);
  2640. hermes_t *hw = &priv->hw;
  2641. u16 val;
  2642. int err;
  2643. unsigned long flags;
  2644. if (!priv->has_sensitivity)
  2645. return -EOPNOTSUPP;
  2646. if (orinoco_lock(priv, &flags) != 0)
  2647. return -EBUSY;
  2648. err = hermes_read_wordrec(hw, USER_BAP,
  2649. HERMES_RID_CNFSYSTEMSCALE, &val);
  2650. orinoco_unlock(priv, &flags);
  2651. if (err)
  2652. return err;
  2653. srq->value = val;
  2654. srq->fixed = 0; /* auto */
  2655. return 0;
  2656. }
  2657. static int orinoco_ioctl_setsens(struct net_device *dev, struct iw_param *srq)
  2658. {
  2659. struct orinoco_private *priv = netdev_priv(dev);
  2660. int val = srq->value;
  2661. unsigned long flags;
  2662. if (!priv->has_sensitivity)
  2663. return -EOPNOTSUPP;
  2664. if ((val < 1) || (val > 3))
  2665. return -EINVAL;
  2666. if (orinoco_lock(priv, &flags) != 0)
  2667. return -EBUSY;
  2668. priv->ap_density = val;
  2669. orinoco_unlock(priv, &flags);
  2670. return 0;
  2671. }
  2672. static int orinoco_ioctl_setrts(struct net_device *dev, struct iw_param *rrq)
  2673. {
  2674. struct orinoco_private *priv = netdev_priv(dev);
  2675. int val = rrq->value;
  2676. unsigned long flags;
  2677. if (rrq->disabled)
  2678. val = 2347;
  2679. if ( (val < 0) || (val > 2347) )
  2680. return -EINVAL;
  2681. if (orinoco_lock(priv, &flags) != 0)
  2682. return -EBUSY;
  2683. priv->rts_thresh = val;
  2684. orinoco_unlock(priv, &flags);
  2685. return 0;
  2686. }
  2687. static int orinoco_ioctl_setfrag(struct net_device *dev, struct iw_param *frq)
  2688. {
  2689. struct orinoco_private *priv = netdev_priv(dev);
  2690. int err = 0;
  2691. unsigned long flags;
  2692. if (orinoco_lock(priv, &flags) != 0)
  2693. return -EBUSY;
  2694. if (priv->has_mwo) {
  2695. if (frq->disabled)
  2696. priv->mwo_robust = 0;
  2697. else {
  2698. if (frq->fixed)
  2699. printk(KERN_WARNING "%s: Fixed fragmentation is "
  2700. "not supported on this firmware. "
  2701. "Using MWO robust instead.\n", dev->name);
  2702. priv->mwo_robust = 1;
  2703. }
  2704. } else {
  2705. if (frq->disabled)
  2706. priv->frag_thresh = 2346;
  2707. else {
  2708. if ( (frq->value < 256) || (frq->value > 2346) )
  2709. err = -EINVAL;
  2710. else
  2711. priv->frag_thresh = frq->value & ~0x1; /* must be even */
  2712. }
  2713. }
  2714. orinoco_unlock(priv, &flags);
  2715. return err;
  2716. }
  2717. static int orinoco_ioctl_getfrag(struct net_device *dev, struct iw_param *frq)
  2718. {
  2719. struct orinoco_private *priv = netdev_priv(dev);
  2720. hermes_t *hw = &priv->hw;
  2721. int err = 0;
  2722. u16 val;
  2723. unsigned long flags;
  2724. if (orinoco_lock(priv, &flags) != 0)
  2725. return -EBUSY;
  2726. if (priv->has_mwo) {
  2727. err = hermes_read_wordrec(hw, USER_BAP,
  2728. HERMES_RID_CNFMWOROBUST_AGERE,
  2729. &val);
  2730. if (err)
  2731. val = 0;
  2732. frq->value = val ? 2347 : 0;
  2733. frq->disabled = ! val;
  2734. frq->fixed = 0;
  2735. } else {
  2736. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
  2737. &val);
  2738. if (err)
  2739. val = 0;
  2740. frq->value = val;
  2741. frq->disabled = (val >= 2346);
  2742. frq->fixed = 1;
  2743. }
  2744. orinoco_unlock(priv, &flags);
  2745. return err;
  2746. }
  2747. static int orinoco_ioctl_setrate(struct net_device *dev, struct iw_param *rrq)
  2748. {
  2749. struct orinoco_private *priv = netdev_priv(dev);
  2750. int err = 0;
  2751. int ratemode = -1;
  2752. int bitrate; /* 100s of kilobits */
  2753. int i;
  2754. unsigned long flags;
  2755. /* As the user space doesn't know our highest rate, it uses -1
  2756. * to ask us to set the highest rate. Test it using "iwconfig
  2757. * ethX rate auto" - Jean II */
  2758. if (rrq->value == -1)
  2759. bitrate = 110;
  2760. else {
  2761. if (rrq->value % 100000)
  2762. return -EINVAL;
  2763. bitrate = rrq->value / 100000;
  2764. }
  2765. if ( (bitrate != 10) && (bitrate != 20) &&
  2766. (bitrate != 55) && (bitrate != 110) )
  2767. return -EINVAL;
  2768. for (i = 0; i < BITRATE_TABLE_SIZE; i++)
  2769. if ( (bitrate_table[i].bitrate == bitrate) &&
  2770. (bitrate_table[i].automatic == ! rrq->fixed) ) {
  2771. ratemode = i;
  2772. break;
  2773. }
  2774. if (ratemode == -1)
  2775. return -EINVAL;
  2776. if (orinoco_lock(priv, &flags) != 0)
  2777. return -EBUSY;
  2778. priv->bitratemode = ratemode;
  2779. orinoco_unlock(priv, &flags);
  2780. return err;
  2781. }
  2782. static int orinoco_ioctl_getrate(struct net_device *dev, struct iw_param *rrq)
  2783. {
  2784. struct orinoco_private *priv = netdev_priv(dev);
  2785. hermes_t *hw = &priv->hw;
  2786. int err = 0;
  2787. int ratemode;
  2788. int i;
  2789. u16 val;
  2790. unsigned long flags;
  2791. if (orinoco_lock(priv, &flags) != 0)
  2792. return -EBUSY;
  2793. ratemode = priv->bitratemode;
  2794. BUG_ON((ratemode < 0) || (ratemode >= BITRATE_TABLE_SIZE));
  2795. rrq->value = bitrate_table[ratemode].bitrate * 100000;
  2796. rrq->fixed = ! bitrate_table[ratemode].automatic;
  2797. rrq->disabled = 0;
  2798. /* If the interface is running we try to find more about the
  2799. current mode */
  2800. if (netif_running(dev)) {
  2801. err = hermes_read_wordrec(hw, USER_BAP,
  2802. HERMES_RID_CURRENTTXRATE, &val);
  2803. if (err)
  2804. goto out;
  2805. switch (priv->firmware_type) {
  2806. case FIRMWARE_TYPE_AGERE: /* Lucent style rate */
  2807. /* Note : in Lucent firmware, the return value of
  2808. * HERMES_RID_CURRENTTXRATE is the bitrate in Mb/s,
  2809. * and therefore is totally different from the
  2810. * encoding of HERMES_RID_CNFTXRATECONTROL.
  2811. * Don't forget that 6Mb/s is really 5.5Mb/s */
  2812. if (val == 6)
  2813. rrq->value = 5500000;
  2814. else
  2815. rrq->value = val * 1000000;
  2816. break;
  2817. case FIRMWARE_TYPE_INTERSIL: /* Intersil style rate */
  2818. case FIRMWARE_TYPE_SYMBOL: /* Symbol style rate */
  2819. for (i = 0; i < BITRATE_TABLE_SIZE; i++)
  2820. if (bitrate_table[i].intersil_txratectrl == val) {
  2821. ratemode = i;
  2822. break;
  2823. }
  2824. if (i >= BITRATE_TABLE_SIZE)
  2825. printk(KERN_INFO "%s: Unable to determine current bitrate (0x%04hx)\n",
  2826. dev->name, val);
  2827. rrq->value = bitrate_table[ratemode].bitrate * 100000;
  2828. break;
  2829. default:
  2830. BUG();
  2831. }
  2832. }
  2833. out:
  2834. orinoco_unlock(priv, &flags);
  2835. return err;
  2836. }
  2837. static int orinoco_ioctl_setpower(struct net_device *dev, struct iw_param *prq)
  2838. {
  2839. struct orinoco_private *priv = netdev_priv(dev);
  2840. int err = 0;
  2841. unsigned long flags;
  2842. if (orinoco_lock(priv, &flags) != 0)
  2843. return -EBUSY;
  2844. if (prq->disabled) {
  2845. priv->pm_on = 0;
  2846. } else {
  2847. switch (prq->flags & IW_POWER_MODE) {
  2848. case IW_POWER_UNICAST_R:
  2849. priv->pm_mcast = 0;
  2850. priv->pm_on = 1;
  2851. break;
  2852. case IW_POWER_ALL_R:
  2853. priv->pm_mcast = 1;
  2854. priv->pm_on = 1;
  2855. break;
  2856. case IW_POWER_ON:
  2857. /* No flags : but we may have a value - Jean II */
  2858. break;
  2859. default:
  2860. err = -EINVAL;
  2861. }
  2862. if (err)
  2863. goto out;
  2864. if (prq->flags & IW_POWER_TIMEOUT) {
  2865. priv->pm_on = 1;
  2866. priv->pm_timeout = prq->value / 1000;
  2867. }
  2868. if (prq->flags & IW_POWER_PERIOD) {
  2869. priv->pm_on = 1;
  2870. priv->pm_period = prq->value / 1000;
  2871. }
  2872. /* It's valid to not have a value if we are just toggling
  2873. * the flags... Jean II */
  2874. if(!priv->pm_on) {
  2875. err = -EINVAL;
  2876. goto out;
  2877. }
  2878. }
  2879. out:
  2880. orinoco_unlock(priv, &flags);
  2881. return err;
  2882. }
  2883. static int orinoco_ioctl_getpower(struct net_device *dev, struct iw_param *prq)
  2884. {
  2885. struct orinoco_private *priv = netdev_priv(dev);
  2886. hermes_t *hw = &priv->hw;
  2887. int err = 0;
  2888. u16 enable, period, timeout, mcast;
  2889. unsigned long flags;
  2890. if (orinoco_lock(priv, &flags) != 0)
  2891. return -EBUSY;
  2892. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFPMENABLED, &enable);
  2893. if (err)
  2894. goto out;
  2895. err = hermes_read_wordrec(hw, USER_BAP,
  2896. HERMES_RID_CNFMAXSLEEPDURATION, &period);
  2897. if (err)
  2898. goto out;
  2899. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFPMHOLDOVERDURATION, &timeout);
  2900. if (err)
  2901. goto out;
  2902. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFMULTICASTRECEIVE, &mcast);
  2903. if (err)
  2904. goto out;
  2905. prq->disabled = !enable;
  2906. /* Note : by default, display the period */
  2907. if ((prq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
  2908. prq->flags = IW_POWER_TIMEOUT;
  2909. prq->value = timeout * 1000;
  2910. } else {
  2911. prq->flags = IW_POWER_PERIOD;
  2912. prq->value = period * 1000;
  2913. }
  2914. if (mcast)
  2915. prq->flags |= IW_POWER_ALL_R;
  2916. else
  2917. prq->flags |= IW_POWER_UNICAST_R;
  2918. out:
  2919. orinoco_unlock(priv, &flags);
  2920. return err;
  2921. }
  2922. static int orinoco_ioctl_getretry(struct net_device *dev, struct iw_param *rrq)
  2923. {
  2924. struct orinoco_private *priv = netdev_priv(dev);
  2925. hermes_t *hw = &priv->hw;
  2926. int err = 0;
  2927. u16 short_limit, long_limit, lifetime;
  2928. unsigned long flags;
  2929. if (orinoco_lock(priv, &flags) != 0)
  2930. return -EBUSY;
  2931. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_SHORTRETRYLIMIT,
  2932. &short_limit);
  2933. if (err)
  2934. goto out;
  2935. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_LONGRETRYLIMIT,
  2936. &long_limit);
  2937. if (err)
  2938. goto out;
  2939. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_MAXTRANSMITLIFETIME,
  2940. &lifetime);
  2941. if (err)
  2942. goto out;
  2943. rrq->disabled = 0; /* Can't be disabled */
  2944. /* Note : by default, display the retry number */
  2945. if ((rrq->flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
  2946. rrq->flags = IW_RETRY_LIFETIME;
  2947. rrq->value = lifetime * 1000; /* ??? */
  2948. } else {
  2949. /* By default, display the min number */
  2950. if ((rrq->flags & IW_RETRY_MAX)) {
  2951. rrq->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
  2952. rrq->value = long_limit;
  2953. } else {
  2954. rrq->flags = IW_RETRY_LIMIT;
  2955. rrq->value = short_limit;
  2956. if(short_limit != long_limit)
  2957. rrq->flags |= IW_RETRY_MIN;
  2958. }
  2959. }
  2960. out:
  2961. orinoco_unlock(priv, &flags);
  2962. return err;
  2963. }
  2964. static int orinoco_ioctl_setibssport(struct net_device *dev, struct iwreq *wrq)
  2965. {
  2966. struct orinoco_private *priv = netdev_priv(dev);
  2967. int val = *( (int *) wrq->u.name );
  2968. unsigned long flags;
  2969. if (orinoco_lock(priv, &flags) != 0)
  2970. return -EBUSY;
  2971. priv->ibss_port = val ;
  2972. /* Actually update the mode we are using */
  2973. set_port_type(priv);
  2974. orinoco_unlock(priv, &flags);
  2975. return 0;
  2976. }
  2977. static int orinoco_ioctl_getibssport(struct net_device *dev, struct iwreq *wrq)
  2978. {
  2979. struct orinoco_private *priv = netdev_priv(dev);
  2980. int *val = (int *)wrq->u.name;
  2981. unsigned long flags;
  2982. if (orinoco_lock(priv, &flags) != 0)
  2983. return -EBUSY;
  2984. *val = priv->ibss_port;
  2985. orinoco_unlock(priv, &flags);
  2986. return 0;
  2987. }
  2988. static int orinoco_ioctl_setport3(struct net_device *dev, struct iwreq *wrq)
  2989. {
  2990. struct orinoco_private *priv = netdev_priv(dev);
  2991. int val = *( (int *) wrq->u.name );
  2992. int err = 0;
  2993. unsigned long flags;
  2994. if (orinoco_lock(priv, &flags) != 0)
  2995. return -EBUSY;
  2996. switch (val) {
  2997. case 0: /* Try to do IEEE ad-hoc mode */
  2998. if (! priv->has_ibss) {
  2999. err = -EINVAL;
  3000. break;
  3001. }
  3002. priv->prefer_port3 = 0;
  3003. break;
  3004. case 1: /* Try to do Lucent proprietary ad-hoc mode */
  3005. if (! priv->has_port3) {
  3006. err = -EINVAL;
  3007. break;
  3008. }
  3009. priv->prefer_port3 = 1;
  3010. break;
  3011. default:
  3012. err = -EINVAL;
  3013. }
  3014. if (! err)
  3015. /* Actually update the mode we are using */
  3016. set_port_type(priv);
  3017. orinoco_unlock(priv, &flags);
  3018. return err;
  3019. }
  3020. static int orinoco_ioctl_getport3(struct net_device *dev, struct iwreq *wrq)
  3021. {
  3022. struct orinoco_private *priv = netdev_priv(dev);
  3023. int *val = (int *)wrq->u.name;
  3024. unsigned long flags;
  3025. if (orinoco_lock(priv, &flags) != 0)
  3026. return -EBUSY;
  3027. *val = priv->prefer_port3;
  3028. orinoco_unlock(priv, &flags);
  3029. return 0;
  3030. }
  3031. /* Spy is used for link quality/strength measurements in Ad-Hoc mode
  3032. * Jean II */
  3033. static int orinoco_ioctl_setspy(struct net_device *dev, struct iw_point *srq)
  3034. {
  3035. struct orinoco_private *priv = netdev_priv(dev);
  3036. struct sockaddr address[IW_MAX_SPY];
  3037. int number = srq->length;
  3038. int i;
  3039. int err = 0;
  3040. unsigned long flags;
  3041. /* Check the number of addresses */
  3042. if (number > IW_MAX_SPY)
  3043. return -E2BIG;
  3044. /* Get the data in the driver */
  3045. if (srq->pointer) {
  3046. if (copy_from_user(address, srq->pointer,
  3047. sizeof(struct sockaddr) * number))
  3048. return -EFAULT;
  3049. }
  3050. /* Make sure nobody mess with the structure while we do */
  3051. if (orinoco_lock(priv, &flags) != 0)
  3052. return -EBUSY;
  3053. /* orinoco_lock() doesn't disable interrupts, so make sure the
  3054. * interrupt rx path don't get confused while we copy */
  3055. priv->spy_number = 0;
  3056. if (number > 0) {
  3057. /* Extract the addresses */
  3058. for (i = 0; i < number; i++)
  3059. memcpy(priv->spy_address[i], address[i].sa_data,
  3060. ETH_ALEN);
  3061. /* Reset stats */
  3062. memset(priv->spy_stat, 0,
  3063. sizeof(struct iw_quality) * IW_MAX_SPY);
  3064. /* Set number of addresses */
  3065. priv->spy_number = number;
  3066. }
  3067. /* Now, let the others play */
  3068. orinoco_unlock(priv, &flags);
  3069. return err;
  3070. }
  3071. static int orinoco_ioctl_getspy(struct net_device *dev, struct iw_point *srq)
  3072. {
  3073. struct orinoco_private *priv = netdev_priv(dev);
  3074. struct sockaddr address[IW_MAX_SPY];
  3075. struct iw_quality spy_stat[IW_MAX_SPY];
  3076. int number;
  3077. int i;
  3078. unsigned long flags;
  3079. if (orinoco_lock(priv, &flags) != 0)
  3080. return -EBUSY;
  3081. number = priv->spy_number;
  3082. if ((number > 0) && (srq->pointer)) {
  3083. /* Create address struct */
  3084. for (i = 0; i < number; i++) {
  3085. memcpy(address[i].sa_data, priv->spy_address[i],
  3086. ETH_ALEN);
  3087. address[i].sa_family = AF_UNIX;
  3088. }
  3089. /* Copy stats */
  3090. /* In theory, we should disable irqs while copying the stats
  3091. * because the rx path might update it in the middle...
  3092. * Bah, who care ? - Jean II */
  3093. memcpy(&spy_stat, priv->spy_stat,
  3094. sizeof(struct iw_quality) * IW_MAX_SPY);
  3095. for (i=0; i < number; i++)
  3096. priv->spy_stat[i].updated = 0;
  3097. }
  3098. orinoco_unlock(priv, &flags);
  3099. /* Push stuff to user space */
  3100. srq->length = number;
  3101. if(copy_to_user(srq->pointer, address,
  3102. sizeof(struct sockaddr) * number))
  3103. return -EFAULT;
  3104. if(copy_to_user(srq->pointer + (sizeof(struct sockaddr)*number),
  3105. &spy_stat, sizeof(struct iw_quality) * number))
  3106. return -EFAULT;
  3107. return 0;
  3108. }
  3109. static int
  3110. orinoco_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
  3111. {
  3112. struct orinoco_private *priv = netdev_priv(dev);
  3113. struct iwreq *wrq = (struct iwreq *)rq;
  3114. int err = 0;
  3115. int tmp;
  3116. int changed = 0;
  3117. unsigned long flags;
  3118. TRACE_ENTER(dev->name);
  3119. /* In theory, we could allow most of the the SET stuff to be
  3120. * done. In practice, the lapse of time at startup when the
  3121. * card is not ready is very short, so why bother... Note
  3122. * that netif_device_present is different from up/down
  3123. * (ifconfig), when the device is not yet up, it is usually
  3124. * already ready... Jean II */
  3125. if (! netif_device_present(dev))
  3126. return -ENODEV;
  3127. switch (cmd) {
  3128. case SIOCGIWNAME:
  3129. strcpy(wrq->u.name, "IEEE 802.11-DS");
  3130. break;
  3131. case SIOCGIWAP:
  3132. wrq->u.ap_addr.sa_family = ARPHRD_ETHER;
  3133. err = orinoco_hw_get_bssid(priv, wrq->u.ap_addr.sa_data);
  3134. break;
  3135. case SIOCGIWRANGE:
  3136. err = orinoco_ioctl_getiwrange(dev, &wrq->u.data);
  3137. break;
  3138. case SIOCSIWMODE:
  3139. if (orinoco_lock(priv, &flags) != 0)
  3140. return -EBUSY;
  3141. switch (wrq->u.mode) {
  3142. case IW_MODE_ADHOC:
  3143. if (! (priv->has_ibss || priv->has_port3) )
  3144. err = -EINVAL;
  3145. else {
  3146. priv->iw_mode = IW_MODE_ADHOC;
  3147. changed = 1;
  3148. }
  3149. break;
  3150. case IW_MODE_INFRA:
  3151. priv->iw_mode = IW_MODE_INFRA;
  3152. changed = 1;
  3153. break;
  3154. default:
  3155. err = -EINVAL;
  3156. break;
  3157. }
  3158. set_port_type(priv);
  3159. orinoco_unlock(priv, &flags);
  3160. break;
  3161. case SIOCGIWMODE:
  3162. if (orinoco_lock(priv, &flags) != 0)
  3163. return -EBUSY;
  3164. wrq->u.mode = priv->iw_mode;
  3165. orinoco_unlock(priv, &flags);
  3166. break;
  3167. case SIOCSIWENCODE:
  3168. err = orinoco_ioctl_setiwencode(dev, &wrq->u.encoding);
  3169. if (! err)
  3170. changed = 1;
  3171. break;
  3172. case SIOCGIWENCODE:
  3173. if (! capable(CAP_NET_ADMIN)) {
  3174. err = -EPERM;
  3175. break;
  3176. }
  3177. err = orinoco_ioctl_getiwencode(dev, &wrq->u.encoding);
  3178. break;
  3179. case SIOCSIWESSID:
  3180. err = orinoco_ioctl_setessid(dev, &wrq->u.essid);
  3181. if (! err)
  3182. changed = 1;
  3183. break;
  3184. case SIOCGIWESSID:
  3185. err = orinoco_ioctl_getessid(dev, &wrq->u.essid);
  3186. break;
  3187. case SIOCSIWNICKN:
  3188. err = orinoco_ioctl_setnick(dev, &wrq->u.data);
  3189. if (! err)
  3190. changed = 1;
  3191. break;
  3192. case SIOCGIWNICKN:
  3193. err = orinoco_ioctl_getnick(dev, &wrq->u.data);
  3194. break;
  3195. case SIOCGIWFREQ:
  3196. tmp = orinoco_hw_get_freq(priv);
  3197. if (tmp < 0) {
  3198. err = tmp;
  3199. } else {
  3200. wrq->u.freq.m = tmp;
  3201. wrq->u.freq.e = 1;
  3202. }
  3203. break;
  3204. case SIOCSIWFREQ:
  3205. err = orinoco_ioctl_setfreq(dev, &wrq->u.freq);
  3206. if (! err)
  3207. changed = 1;
  3208. break;
  3209. case SIOCGIWSENS:
  3210. err = orinoco_ioctl_getsens(dev, &wrq->u.sens);
  3211. break;
  3212. case SIOCSIWSENS:
  3213. err = orinoco_ioctl_setsens(dev, &wrq->u.sens);
  3214. if (! err)
  3215. changed = 1;
  3216. break;
  3217. case SIOCGIWRTS:
  3218. wrq->u.rts.value = priv->rts_thresh;
  3219. wrq->u.rts.disabled = (wrq->u.rts.value == 2347);
  3220. wrq->u.rts.fixed = 1;
  3221. break;
  3222. case SIOCSIWRTS:
  3223. err = orinoco_ioctl_setrts(dev, &wrq->u.rts);
  3224. if (! err)
  3225. changed = 1;
  3226. break;
  3227. case SIOCSIWFRAG:
  3228. err = orinoco_ioctl_setfrag(dev, &wrq->u.frag);
  3229. if (! err)
  3230. changed = 1;
  3231. break;
  3232. case SIOCGIWFRAG:
  3233. err = orinoco_ioctl_getfrag(dev, &wrq->u.frag);
  3234. break;
  3235. case SIOCSIWRATE:
  3236. err = orinoco_ioctl_setrate(dev, &wrq->u.bitrate);
  3237. if (! err)
  3238. changed = 1;
  3239. break;
  3240. case SIOCGIWRATE:
  3241. err = orinoco_ioctl_getrate(dev, &wrq->u.bitrate);
  3242. break;
  3243. case SIOCSIWPOWER:
  3244. err = orinoco_ioctl_setpower(dev, &wrq->u.power);
  3245. if (! err)
  3246. changed = 1;
  3247. break;
  3248. case SIOCGIWPOWER:
  3249. err = orinoco_ioctl_getpower(dev, &wrq->u.power);
  3250. break;
  3251. case SIOCGIWTXPOW:
  3252. /* The card only supports one tx power, so this is easy */
  3253. wrq->u.txpower.value = 15; /* dBm */
  3254. wrq->u.txpower.fixed = 1;
  3255. wrq->u.txpower.disabled = 0;
  3256. wrq->u.txpower.flags = IW_TXPOW_DBM;
  3257. break;
  3258. case SIOCSIWRETRY:
  3259. err = -EOPNOTSUPP;
  3260. break;
  3261. case SIOCGIWRETRY:
  3262. err = orinoco_ioctl_getretry(dev, &wrq->u.retry);
  3263. break;
  3264. case SIOCSIWSPY:
  3265. err = orinoco_ioctl_setspy(dev, &wrq->u.data);
  3266. break;
  3267. case SIOCGIWSPY:
  3268. err = orinoco_ioctl_getspy(dev, &wrq->u.data);
  3269. break;
  3270. case SIOCGIWPRIV:
  3271. if (wrq->u.data.pointer) {
  3272. struct iw_priv_args privtab[] = {
  3273. { SIOCIWFIRSTPRIV + 0x0, 0, 0, "force_reset" },
  3274. { SIOCIWFIRSTPRIV + 0x1, 0, 0, "card_reset" },
  3275. { SIOCIWFIRSTPRIV + 0x2,
  3276. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  3277. 0, "set_port3" },
  3278. { SIOCIWFIRSTPRIV + 0x3, 0,
  3279. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  3280. "get_port3" },
  3281. { SIOCIWFIRSTPRIV + 0x4,
  3282. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  3283. 0, "set_preamble" },
  3284. { SIOCIWFIRSTPRIV + 0x5, 0,
  3285. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  3286. "get_preamble" },
  3287. { SIOCIWFIRSTPRIV + 0x6,
  3288. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  3289. 0, "set_ibssport" },
  3290. { SIOCIWFIRSTPRIV + 0x7, 0,
  3291. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  3292. "get_ibssport" },
  3293. };
  3294. wrq->u.data.length = sizeof(privtab) / sizeof(privtab[0]);
  3295. if (copy_to_user(wrq->u.data.pointer, privtab, sizeof(privtab)))
  3296. err = -EFAULT;
  3297. }
  3298. break;
  3299. case SIOCIWFIRSTPRIV + 0x0: /* force_reset */
  3300. case SIOCIWFIRSTPRIV + 0x1: /* card_reset */
  3301. if (! capable(CAP_NET_ADMIN)) {
  3302. err = -EPERM;
  3303. break;
  3304. }
  3305. printk(KERN_DEBUG "%s: Force scheduling reset!\n", dev->name);
  3306. schedule_work(&priv->reset_work);
  3307. break;
  3308. case SIOCIWFIRSTPRIV + 0x2: /* set_port3 */
  3309. if (! capable(CAP_NET_ADMIN)) {
  3310. err = -EPERM;
  3311. break;
  3312. }
  3313. err = orinoco_ioctl_setport3(dev, wrq);
  3314. if (! err)
  3315. changed = 1;
  3316. break;
  3317. case SIOCIWFIRSTPRIV + 0x3: /* get_port3 */
  3318. err = orinoco_ioctl_getport3(dev, wrq);
  3319. break;
  3320. case SIOCIWFIRSTPRIV + 0x4: /* set_preamble */
  3321. if (! capable(CAP_NET_ADMIN)) {
  3322. err = -EPERM;
  3323. break;
  3324. }
  3325. /* 802.11b has recently defined some short preamble.
  3326. * Basically, the Phy header has been reduced in size.
  3327. * This increase performance, especially at high rates
  3328. * (the preamble is transmitted at 1Mb/s), unfortunately
  3329. * this give compatibility troubles... - Jean II */
  3330. if(priv->has_preamble) {
  3331. int val = *( (int *) wrq->u.name );
  3332. if (orinoco_lock(priv, &flags) != 0)
  3333. return -EBUSY;
  3334. if (val)
  3335. priv->preamble = 1;
  3336. else
  3337. priv->preamble = 0;
  3338. orinoco_unlock(priv, &flags);
  3339. changed = 1;
  3340. } else
  3341. err = -EOPNOTSUPP;
  3342. break;
  3343. case SIOCIWFIRSTPRIV + 0x5: /* get_preamble */
  3344. if(priv->has_preamble) {
  3345. int *val = (int *)wrq->u.name;
  3346. if (orinoco_lock(priv, &flags) != 0)
  3347. return -EBUSY;
  3348. *val = priv->preamble;
  3349. orinoco_unlock(priv, &flags);
  3350. } else
  3351. err = -EOPNOTSUPP;
  3352. break;
  3353. case SIOCIWFIRSTPRIV + 0x6: /* set_ibssport */
  3354. if (! capable(CAP_NET_ADMIN)) {
  3355. err = -EPERM;
  3356. break;
  3357. }
  3358. err = orinoco_ioctl_setibssport(dev, wrq);
  3359. if (! err)
  3360. changed = 1;
  3361. break;
  3362. case SIOCIWFIRSTPRIV + 0x7: /* get_ibssport */
  3363. err = orinoco_ioctl_getibssport(dev, wrq);
  3364. break;
  3365. default:
  3366. err = -EOPNOTSUPP;
  3367. }
  3368. if (! err && changed && netif_running(dev)) {
  3369. err = orinoco_reconfigure(dev);
  3370. }
  3371. TRACE_EXIT(dev->name);
  3372. return err;
  3373. }
  3374. /********************************************************************/
  3375. /* Debugging */
  3376. /********************************************************************/
  3377. #if 0
  3378. static void show_rx_frame(struct orinoco_rxframe_hdr *frame)
  3379. {
  3380. printk(KERN_DEBUG "RX descriptor:\n");
  3381. printk(KERN_DEBUG " status = 0x%04x\n", frame->desc.status);
  3382. printk(KERN_DEBUG " time = 0x%08x\n", frame->desc.time);
  3383. printk(KERN_DEBUG " silence = 0x%02x\n", frame->desc.silence);
  3384. printk(KERN_DEBUG " signal = 0x%02x\n", frame->desc.signal);
  3385. printk(KERN_DEBUG " rate = 0x%02x\n", frame->desc.rate);
  3386. printk(KERN_DEBUG " rxflow = 0x%02x\n", frame->desc.rxflow);
  3387. printk(KERN_DEBUG " reserved = 0x%08x\n", frame->desc.reserved);
  3388. printk(KERN_DEBUG "IEEE 802.11 header:\n");
  3389. printk(KERN_DEBUG " frame_ctl = 0x%04x\n",
  3390. frame->p80211.frame_ctl);
  3391. printk(KERN_DEBUG " duration_id = 0x%04x\n",
  3392. frame->p80211.duration_id);
  3393. printk(KERN_DEBUG " addr1 = %02x:%02x:%02x:%02x:%02x:%02x\n",
  3394. frame->p80211.addr1[0], frame->p80211.addr1[1],
  3395. frame->p80211.addr1[2], frame->p80211.addr1[3],
  3396. frame->p80211.addr1[4], frame->p80211.addr1[5]);
  3397. printk(KERN_DEBUG " addr2 = %02x:%02x:%02x:%02x:%02x:%02x\n",
  3398. frame->p80211.addr2[0], frame->p80211.addr2[1],
  3399. frame->p80211.addr2[2], frame->p80211.addr2[3],
  3400. frame->p80211.addr2[4], frame->p80211.addr2[5]);
  3401. printk(KERN_DEBUG " addr3 = %02x:%02x:%02x:%02x:%02x:%02x\n",
  3402. frame->p80211.addr3[0], frame->p80211.addr3[1],
  3403. frame->p80211.addr3[2], frame->p80211.addr3[3],
  3404. frame->p80211.addr3[4], frame->p80211.addr3[5]);
  3405. printk(KERN_DEBUG " seq_ctl = 0x%04x\n",
  3406. frame->p80211.seq_ctl);
  3407. printk(KERN_DEBUG " addr4 = %02x:%02x:%02x:%02x:%02x:%02x\n",
  3408. frame->p80211.addr4[0], frame->p80211.addr4[1],
  3409. frame->p80211.addr4[2], frame->p80211.addr4[3],
  3410. frame->p80211.addr4[4], frame->p80211.addr4[5]);
  3411. printk(KERN_DEBUG " data_len = 0x%04x\n",
  3412. frame->p80211.data_len);
  3413. printk(KERN_DEBUG "IEEE 802.3 header:\n");
  3414. printk(KERN_DEBUG " dest = %02x:%02x:%02x:%02x:%02x:%02x\n",
  3415. frame->p8023.h_dest[0], frame->p8023.h_dest[1],
  3416. frame->p8023.h_dest[2], frame->p8023.h_dest[3],
  3417. frame->p8023.h_dest[4], frame->p8023.h_dest[5]);
  3418. printk(KERN_DEBUG " src = %02x:%02x:%02x:%02x:%02x:%02x\n",
  3419. frame->p8023.h_source[0], frame->p8023.h_source[1],
  3420. frame->p8023.h_source[2], frame->p8023.h_source[3],
  3421. frame->p8023.h_source[4], frame->p8023.h_source[5]);
  3422. printk(KERN_DEBUG " len = 0x%04x\n", frame->p8023.h_proto);
  3423. printk(KERN_DEBUG "IEEE 802.2 LLC/SNAP header:\n");
  3424. printk(KERN_DEBUG " DSAP = 0x%02x\n", frame->p8022.dsap);
  3425. printk(KERN_DEBUG " SSAP = 0x%02x\n", frame->p8022.ssap);
  3426. printk(KERN_DEBUG " ctrl = 0x%02x\n", frame->p8022.ctrl);
  3427. printk(KERN_DEBUG " OUI = %02x:%02x:%02x\n",
  3428. frame->p8022.oui[0], frame->p8022.oui[1], frame->p8022.oui[2]);
  3429. printk(KERN_DEBUG " ethertype = 0x%04x\n", frame->ethertype);
  3430. }
  3431. #endif /* 0 */
  3432. /********************************************************************/
  3433. /* Module initialization */
  3434. /********************************************************************/
  3435. EXPORT_SYMBOL(alloc_orinocodev);
  3436. EXPORT_SYMBOL(free_orinocodev);
  3437. EXPORT_SYMBOL(__orinoco_up);
  3438. EXPORT_SYMBOL(__orinoco_down);
  3439. EXPORT_SYMBOL(orinoco_stop);
  3440. EXPORT_SYMBOL(orinoco_reinit_firmware);
  3441. EXPORT_SYMBOL(orinoco_interrupt);
  3442. /* Can't be declared "const" or the whole __initdata section will
  3443. * become const */
  3444. static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION
  3445. " (David Gibson <hermes@gibson.dropbear.id.au>, "
  3446. "Pavel Roskin <proski@gnu.org>, et al)";
  3447. static int __init init_orinoco(void)
  3448. {
  3449. printk(KERN_DEBUG "%s\n", version);
  3450. return 0;
  3451. }
  3452. static void __exit exit_orinoco(void)
  3453. {
  3454. }
  3455. module_init(init_orinoco);
  3456. module_exit(exit_orinoco);