orinoco.c 159 KB

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