orinoco.c 114 KB

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