orinoco.c 118 KB

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