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