orinoco.c 114 KB

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