orinoco.c 118 KB

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