orinoco.c 120 KB

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