orinoco.c 118 KB

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