orinoco.c 159 KB

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