orinoco.c 135 KB

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