orinoco.c 118 KB

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