airo.c 207 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691
  1. /*======================================================================
  2. Aironet driver for 4500 and 4800 series cards
  3. This code is released under both the GPL version 2 and BSD licenses.
  4. Either license may be used. The respective licenses are found at
  5. the end of this file.
  6. This code was developed by Benjamin Reed <breed@users.sourceforge.net>
  7. including portions of which come from the Aironet PC4500
  8. Developer's Reference Manual and used with permission. Copyright
  9. (C) 1999 Benjamin Reed. All Rights Reserved. Permission to use
  10. code in the Developer's manual was granted for this driver by
  11. Aironet. Major code contributions were received from Javier Achirica
  12. <achirica@users.sourceforge.net> and Jean Tourrilhes <jt@hpl.hp.com>.
  13. Code was also integrated from the Cisco Aironet driver for Linux.
  14. Support for MPI350 cards was added by Fabrice Bellet
  15. <fabrice@bellet.info>.
  16. ======================================================================*/
  17. #include <linux/config.h>
  18. #include <linux/init.h>
  19. #include <linux/kernel.h>
  20. #include <linux/module.h>
  21. #include <linux/proc_fs.h>
  22. #include <linux/smp_lock.h>
  23. #include <linux/sched.h>
  24. #include <linux/ptrace.h>
  25. #include <linux/slab.h>
  26. #include <linux/string.h>
  27. #include <linux/timer.h>
  28. #include <linux/interrupt.h>
  29. #include <linux/in.h>
  30. #include <linux/bitops.h>
  31. #include <linux/scatterlist.h>
  32. #include <asm/io.h>
  33. #include <asm/system.h>
  34. #include <linux/netdevice.h>
  35. #include <linux/etherdevice.h>
  36. #include <linux/skbuff.h>
  37. #include <linux/if_arp.h>
  38. #include <linux/ioport.h>
  39. #include <linux/pci.h>
  40. #include <asm/uaccess.h>
  41. #ifdef CONFIG_PCI
  42. static struct pci_device_id card_ids[] = {
  43. { 0x14b9, 1, PCI_ANY_ID, PCI_ANY_ID, },
  44. { 0x14b9, 0x4500, PCI_ANY_ID, PCI_ANY_ID },
  45. { 0x14b9, 0x4800, PCI_ANY_ID, PCI_ANY_ID, },
  46. { 0x14b9, 0x0340, PCI_ANY_ID, PCI_ANY_ID, },
  47. { 0x14b9, 0x0350, PCI_ANY_ID, PCI_ANY_ID, },
  48. { 0x14b9, 0x5000, PCI_ANY_ID, PCI_ANY_ID, },
  49. { 0x14b9, 0xa504, PCI_ANY_ID, PCI_ANY_ID, },
  50. { 0, }
  51. };
  52. MODULE_DEVICE_TABLE(pci, card_ids);
  53. static int airo_pci_probe(struct pci_dev *, const struct pci_device_id *);
  54. static void airo_pci_remove(struct pci_dev *);
  55. static int airo_pci_suspend(struct pci_dev *pdev, pm_message_t state);
  56. static int airo_pci_resume(struct pci_dev *pdev);
  57. static struct pci_driver airo_driver = {
  58. .name = "airo",
  59. .id_table = card_ids,
  60. .probe = airo_pci_probe,
  61. .remove = __devexit_p(airo_pci_remove),
  62. .suspend = airo_pci_suspend,
  63. .resume = airo_pci_resume,
  64. };
  65. #endif /* CONFIG_PCI */
  66. /* Include Wireless Extension definition and check version - Jean II */
  67. #include <linux/wireless.h>
  68. #define WIRELESS_SPY // enable iwspy support
  69. #include <net/iw_handler.h> // New driver API
  70. #define CISCO_EXT // enable Cisco extensions
  71. #ifdef CISCO_EXT
  72. #include <linux/delay.h>
  73. #endif
  74. /* Support Cisco MIC feature */
  75. #define MICSUPPORT
  76. #if defined(MICSUPPORT) && !defined(CONFIG_CRYPTO)
  77. #warning MIC support requires Crypto API
  78. #undef MICSUPPORT
  79. #endif
  80. /* Hack to do some power saving */
  81. #define POWER_ON_DOWN
  82. /* As you can see this list is HUGH!
  83. I really don't know what a lot of these counts are about, but they
  84. are all here for completeness. If the IGNLABEL macro is put in
  85. infront of the label, that statistic will not be included in the list
  86. of statistics in the /proc filesystem */
  87. #define IGNLABEL(comment) NULL
  88. static char *statsLabels[] = {
  89. "RxOverrun",
  90. IGNLABEL("RxPlcpCrcErr"),
  91. IGNLABEL("RxPlcpFormatErr"),
  92. IGNLABEL("RxPlcpLengthErr"),
  93. "RxMacCrcErr",
  94. "RxMacCrcOk",
  95. "RxWepErr",
  96. "RxWepOk",
  97. "RetryLong",
  98. "RetryShort",
  99. "MaxRetries",
  100. "NoAck",
  101. "NoCts",
  102. "RxAck",
  103. "RxCts",
  104. "TxAck",
  105. "TxRts",
  106. "TxCts",
  107. "TxMc",
  108. "TxBc",
  109. "TxUcFrags",
  110. "TxUcPackets",
  111. "TxBeacon",
  112. "RxBeacon",
  113. "TxSinColl",
  114. "TxMulColl",
  115. "DefersNo",
  116. "DefersProt",
  117. "DefersEngy",
  118. "DupFram",
  119. "RxFragDisc",
  120. "TxAged",
  121. "RxAged",
  122. "LostSync-MaxRetry",
  123. "LostSync-MissedBeacons",
  124. "LostSync-ArlExceeded",
  125. "LostSync-Deauth",
  126. "LostSync-Disassoced",
  127. "LostSync-TsfTiming",
  128. "HostTxMc",
  129. "HostTxBc",
  130. "HostTxUc",
  131. "HostTxFail",
  132. "HostRxMc",
  133. "HostRxBc",
  134. "HostRxUc",
  135. "HostRxDiscard",
  136. IGNLABEL("HmacTxMc"),
  137. IGNLABEL("HmacTxBc"),
  138. IGNLABEL("HmacTxUc"),
  139. IGNLABEL("HmacTxFail"),
  140. IGNLABEL("HmacRxMc"),
  141. IGNLABEL("HmacRxBc"),
  142. IGNLABEL("HmacRxUc"),
  143. IGNLABEL("HmacRxDiscard"),
  144. IGNLABEL("HmacRxAccepted"),
  145. "SsidMismatch",
  146. "ApMismatch",
  147. "RatesMismatch",
  148. "AuthReject",
  149. "AuthTimeout",
  150. "AssocReject",
  151. "AssocTimeout",
  152. IGNLABEL("ReasonOutsideTable"),
  153. IGNLABEL("ReasonStatus1"),
  154. IGNLABEL("ReasonStatus2"),
  155. IGNLABEL("ReasonStatus3"),
  156. IGNLABEL("ReasonStatus4"),
  157. IGNLABEL("ReasonStatus5"),
  158. IGNLABEL("ReasonStatus6"),
  159. IGNLABEL("ReasonStatus7"),
  160. IGNLABEL("ReasonStatus8"),
  161. IGNLABEL("ReasonStatus9"),
  162. IGNLABEL("ReasonStatus10"),
  163. IGNLABEL("ReasonStatus11"),
  164. IGNLABEL("ReasonStatus12"),
  165. IGNLABEL("ReasonStatus13"),
  166. IGNLABEL("ReasonStatus14"),
  167. IGNLABEL("ReasonStatus15"),
  168. IGNLABEL("ReasonStatus16"),
  169. IGNLABEL("ReasonStatus17"),
  170. IGNLABEL("ReasonStatus18"),
  171. IGNLABEL("ReasonStatus19"),
  172. "RxMan",
  173. "TxMan",
  174. "RxRefresh",
  175. "TxRefresh",
  176. "RxPoll",
  177. "TxPoll",
  178. "HostRetries",
  179. "LostSync-HostReq",
  180. "HostTxBytes",
  181. "HostRxBytes",
  182. "ElapsedUsec",
  183. "ElapsedSec",
  184. "LostSyncBetterAP",
  185. "PrivacyMismatch",
  186. "Jammed",
  187. "DiscRxNotWepped",
  188. "PhyEleMismatch",
  189. (char*)-1 };
  190. #ifndef RUN_AT
  191. #define RUN_AT(x) (jiffies+(x))
  192. #endif
  193. /* These variables are for insmod, since it seems that the rates
  194. can only be set in setup_card. Rates should be a comma separated
  195. (no spaces) list of rates (up to 8). */
  196. static int rates[8];
  197. static int basic_rate;
  198. static char *ssids[3];
  199. static int io[4];
  200. static int irq[4];
  201. static
  202. int maxencrypt /* = 0 */; /* The highest rate that the card can encrypt at.
  203. 0 means no limit. For old cards this was 4 */
  204. static int auto_wep /* = 0 */; /* If set, it tries to figure out the wep mode */
  205. static int aux_bap /* = 0 */; /* Checks to see if the aux ports are needed to read
  206. the bap, needed on some older cards and buses. */
  207. static int adhoc;
  208. static int probe = 1;
  209. static int proc_uid /* = 0 */;
  210. static int proc_gid /* = 0 */;
  211. static int airo_perm = 0555;
  212. static int proc_perm = 0644;
  213. MODULE_AUTHOR("Benjamin Reed");
  214. MODULE_DESCRIPTION("Support for Cisco/Aironet 802.11 wireless ethernet \
  215. cards. Direct support for ISA/PCI/MPI cards and support \
  216. for PCMCIA when used with airo_cs.");
  217. MODULE_LICENSE("Dual BSD/GPL");
  218. MODULE_SUPPORTED_DEVICE("Aironet 4500, 4800 and Cisco 340/350");
  219. module_param_array(io, int, NULL, 0);
  220. module_param_array(irq, int, NULL, 0);
  221. module_param(basic_rate, int, 0);
  222. module_param_array(rates, int, NULL, 0);
  223. module_param_array(ssids, charp, NULL, 0);
  224. module_param(auto_wep, int, 0);
  225. MODULE_PARM_DESC(auto_wep, "If non-zero, the driver will keep looping through \
  226. the authentication options until an association is made. The value of \
  227. auto_wep is number of the wep keys to check. A value of 2 will try using \
  228. the key at index 0 and index 1.");
  229. module_param(aux_bap, int, 0);
  230. MODULE_PARM_DESC(aux_bap, "If non-zero, the driver will switch into a mode \
  231. than seems to work better for older cards with some older buses. Before \
  232. switching it checks that the switch is needed.");
  233. module_param(maxencrypt, int, 0);
  234. MODULE_PARM_DESC(maxencrypt, "The maximum speed that the card can do \
  235. encryption. Units are in 512kbs. Zero (default) means there is no limit. \
  236. Older cards used to be limited to 2mbs (4).");
  237. module_param(adhoc, int, 0);
  238. MODULE_PARM_DESC(adhoc, "If non-zero, the card will start in adhoc mode.");
  239. module_param(probe, int, 0);
  240. MODULE_PARM_DESC(probe, "If zero, the driver won't start the card.");
  241. module_param(proc_uid, int, 0);
  242. MODULE_PARM_DESC(proc_uid, "The uid that the /proc files will belong to.");
  243. module_param(proc_gid, int, 0);
  244. MODULE_PARM_DESC(proc_gid, "The gid that the /proc files will belong to.");
  245. module_param(airo_perm, int, 0);
  246. MODULE_PARM_DESC(airo_perm, "The permission bits of /proc/[driver/]aironet.");
  247. module_param(proc_perm, int, 0);
  248. MODULE_PARM_DESC(proc_perm, "The permission bits of the files in /proc");
  249. /* This is a kind of sloppy hack to get this information to OUT4500 and
  250. IN4500. I would be extremely interested in the situation where this
  251. doesn't work though!!! */
  252. static int do8bitIO = 0;
  253. /* Return codes */
  254. #define SUCCESS 0
  255. #define ERROR -1
  256. #define NO_PACKET -2
  257. /* Commands */
  258. #define NOP2 0x0000
  259. #define MAC_ENABLE 0x0001
  260. #define MAC_DISABLE 0x0002
  261. #define CMD_LOSE_SYNC 0x0003 /* Not sure what this does... */
  262. #define CMD_SOFTRESET 0x0004
  263. #define HOSTSLEEP 0x0005
  264. #define CMD_MAGIC_PKT 0x0006
  265. #define CMD_SETWAKEMASK 0x0007
  266. #define CMD_READCFG 0x0008
  267. #define CMD_SETMODE 0x0009
  268. #define CMD_ALLOCATETX 0x000a
  269. #define CMD_TRANSMIT 0x000b
  270. #define CMD_DEALLOCATETX 0x000c
  271. #define NOP 0x0010
  272. #define CMD_WORKAROUND 0x0011
  273. #define CMD_ALLOCATEAUX 0x0020
  274. #define CMD_ACCESS 0x0021
  275. #define CMD_PCIBAP 0x0022
  276. #define CMD_PCIAUX 0x0023
  277. #define CMD_ALLOCBUF 0x0028
  278. #define CMD_GETTLV 0x0029
  279. #define CMD_PUTTLV 0x002a
  280. #define CMD_DELTLV 0x002b
  281. #define CMD_FINDNEXTTLV 0x002c
  282. #define CMD_PSPNODES 0x0030
  283. #define CMD_SETCW 0x0031
  284. #define CMD_SETPCF 0x0032
  285. #define CMD_SETPHYREG 0x003e
  286. #define CMD_TXTEST 0x003f
  287. #define MAC_ENABLETX 0x0101
  288. #define CMD_LISTBSS 0x0103
  289. #define CMD_SAVECFG 0x0108
  290. #define CMD_ENABLEAUX 0x0111
  291. #define CMD_WRITERID 0x0121
  292. #define CMD_USEPSPNODES 0x0130
  293. #define MAC_ENABLERX 0x0201
  294. /* Command errors */
  295. #define ERROR_QUALIF 0x00
  296. #define ERROR_ILLCMD 0x01
  297. #define ERROR_ILLFMT 0x02
  298. #define ERROR_INVFID 0x03
  299. #define ERROR_INVRID 0x04
  300. #define ERROR_LARGE 0x05
  301. #define ERROR_NDISABL 0x06
  302. #define ERROR_ALLOCBSY 0x07
  303. #define ERROR_NORD 0x0B
  304. #define ERROR_NOWR 0x0C
  305. #define ERROR_INVFIDTX 0x0D
  306. #define ERROR_TESTACT 0x0E
  307. #define ERROR_TAGNFND 0x12
  308. #define ERROR_DECODE 0x20
  309. #define ERROR_DESCUNAV 0x21
  310. #define ERROR_BADLEN 0x22
  311. #define ERROR_MODE 0x80
  312. #define ERROR_HOP 0x81
  313. #define ERROR_BINTER 0x82
  314. #define ERROR_RXMODE 0x83
  315. #define ERROR_MACADDR 0x84
  316. #define ERROR_RATES 0x85
  317. #define ERROR_ORDER 0x86
  318. #define ERROR_SCAN 0x87
  319. #define ERROR_AUTH 0x88
  320. #define ERROR_PSMODE 0x89
  321. #define ERROR_RTYPE 0x8A
  322. #define ERROR_DIVER 0x8B
  323. #define ERROR_SSID 0x8C
  324. #define ERROR_APLIST 0x8D
  325. #define ERROR_AUTOWAKE 0x8E
  326. #define ERROR_LEAP 0x8F
  327. /* Registers */
  328. #define COMMAND 0x00
  329. #define PARAM0 0x02
  330. #define PARAM1 0x04
  331. #define PARAM2 0x06
  332. #define STATUS 0x08
  333. #define RESP0 0x0a
  334. #define RESP1 0x0c
  335. #define RESP2 0x0e
  336. #define LINKSTAT 0x10
  337. #define SELECT0 0x18
  338. #define OFFSET0 0x1c
  339. #define RXFID 0x20
  340. #define TXALLOCFID 0x22
  341. #define TXCOMPLFID 0x24
  342. #define DATA0 0x36
  343. #define EVSTAT 0x30
  344. #define EVINTEN 0x32
  345. #define EVACK 0x34
  346. #define SWS0 0x28
  347. #define SWS1 0x2a
  348. #define SWS2 0x2c
  349. #define SWS3 0x2e
  350. #define AUXPAGE 0x3A
  351. #define AUXOFF 0x3C
  352. #define AUXDATA 0x3E
  353. #define FID_TX 1
  354. #define FID_RX 2
  355. /* Offset into aux memory for descriptors */
  356. #define AUX_OFFSET 0x800
  357. /* Size of allocated packets */
  358. #define PKTSIZE 1840
  359. #define RIDSIZE 2048
  360. /* Size of the transmit queue */
  361. #define MAXTXQ 64
  362. /* BAP selectors */
  363. #define BAP0 0 // Used for receiving packets
  364. #define BAP1 2 // Used for xmiting packets and working with RIDS
  365. /* Flags */
  366. #define COMMAND_BUSY 0x8000
  367. #define BAP_BUSY 0x8000
  368. #define BAP_ERR 0x4000
  369. #define BAP_DONE 0x2000
  370. #define PROMISC 0xffff
  371. #define NOPROMISC 0x0000
  372. #define EV_CMD 0x10
  373. #define EV_CLEARCOMMANDBUSY 0x4000
  374. #define EV_RX 0x01
  375. #define EV_TX 0x02
  376. #define EV_TXEXC 0x04
  377. #define EV_ALLOC 0x08
  378. #define EV_LINK 0x80
  379. #define EV_AWAKE 0x100
  380. #define EV_TXCPY 0x400
  381. #define EV_UNKNOWN 0x800
  382. #define EV_MIC 0x1000 /* Message Integrity Check Interrupt */
  383. #define EV_AWAKEN 0x2000
  384. #define STATUS_INTS (EV_AWAKE|EV_LINK|EV_TXEXC|EV_TX|EV_TXCPY|EV_RX|EV_MIC)
  385. #ifdef CHECK_UNKNOWN_INTS
  386. #define IGNORE_INTS ( EV_CMD | EV_UNKNOWN)
  387. #else
  388. #define IGNORE_INTS (~STATUS_INTS)
  389. #endif
  390. /* RID TYPES */
  391. #define RID_RW 0x20
  392. /* The RIDs */
  393. #define RID_CAPABILITIES 0xFF00
  394. #define RID_APINFO 0xFF01
  395. #define RID_RADIOINFO 0xFF02
  396. #define RID_UNKNOWN3 0xFF03
  397. #define RID_RSSI 0xFF04
  398. #define RID_CONFIG 0xFF10
  399. #define RID_SSID 0xFF11
  400. #define RID_APLIST 0xFF12
  401. #define RID_DRVNAME 0xFF13
  402. #define RID_ETHERENCAP 0xFF14
  403. #define RID_WEP_TEMP 0xFF15
  404. #define RID_WEP_PERM 0xFF16
  405. #define RID_MODULATION 0xFF17
  406. #define RID_OPTIONS 0xFF18
  407. #define RID_ACTUALCONFIG 0xFF20 /*readonly*/
  408. #define RID_FACTORYCONFIG 0xFF21
  409. #define RID_UNKNOWN22 0xFF22
  410. #define RID_LEAPUSERNAME 0xFF23
  411. #define RID_LEAPPASSWORD 0xFF24
  412. #define RID_STATUS 0xFF50
  413. #define RID_BEACON_HST 0xFF51
  414. #define RID_BUSY_HST 0xFF52
  415. #define RID_RETRIES_HST 0xFF53
  416. #define RID_UNKNOWN54 0xFF54
  417. #define RID_UNKNOWN55 0xFF55
  418. #define RID_UNKNOWN56 0xFF56
  419. #define RID_MIC 0xFF57
  420. #define RID_STATS16 0xFF60
  421. #define RID_STATS16DELTA 0xFF61
  422. #define RID_STATS16DELTACLEAR 0xFF62
  423. #define RID_STATS 0xFF68
  424. #define RID_STATSDELTA 0xFF69
  425. #define RID_STATSDELTACLEAR 0xFF6A
  426. #define RID_ECHOTEST_RID 0xFF70
  427. #define RID_ECHOTEST_RESULTS 0xFF71
  428. #define RID_BSSLISTFIRST 0xFF72
  429. #define RID_BSSLISTNEXT 0xFF73
  430. typedef struct {
  431. u16 cmd;
  432. u16 parm0;
  433. u16 parm1;
  434. u16 parm2;
  435. } Cmd;
  436. typedef struct {
  437. u16 status;
  438. u16 rsp0;
  439. u16 rsp1;
  440. u16 rsp2;
  441. } Resp;
  442. /*
  443. * Rids and endian-ness: The Rids will always be in cpu endian, since
  444. * this all the patches from the big-endian guys end up doing that.
  445. * so all rid access should use the read/writeXXXRid routines.
  446. */
  447. /* This is redundant for x86 archs, but it seems necessary for ARM */
  448. #pragma pack(1)
  449. /* This structure came from an email sent to me from an engineer at
  450. aironet for inclusion into this driver */
  451. typedef struct {
  452. u16 len;
  453. u16 kindex;
  454. u8 mac[ETH_ALEN];
  455. u16 klen;
  456. u8 key[16];
  457. } WepKeyRid;
  458. /* These structures are from the Aironet's PC4500 Developers Manual */
  459. typedef struct {
  460. u16 len;
  461. u8 ssid[32];
  462. } Ssid;
  463. typedef struct {
  464. u16 len;
  465. Ssid ssids[3];
  466. } SsidRid;
  467. typedef struct {
  468. u16 len;
  469. u16 modulation;
  470. #define MOD_DEFAULT 0
  471. #define MOD_CCK 1
  472. #define MOD_MOK 2
  473. } ModulationRid;
  474. typedef struct {
  475. u16 len; /* sizeof(ConfigRid) */
  476. u16 opmode; /* operating mode */
  477. #define MODE_STA_IBSS 0
  478. #define MODE_STA_ESS 1
  479. #define MODE_AP 2
  480. #define MODE_AP_RPTR 3
  481. #define MODE_ETHERNET_HOST (0<<8) /* rx payloads converted */
  482. #define MODE_LLC_HOST (1<<8) /* rx payloads left as is */
  483. #define MODE_AIRONET_EXTEND (1<<9) /* enable Aironet extenstions */
  484. #define MODE_AP_INTERFACE (1<<10) /* enable ap interface extensions */
  485. #define MODE_ANTENNA_ALIGN (1<<11) /* enable antenna alignment */
  486. #define MODE_ETHER_LLC (1<<12) /* enable ethernet LLC */
  487. #define MODE_LEAF_NODE (1<<13) /* enable leaf node bridge */
  488. #define MODE_CF_POLLABLE (1<<14) /* enable CF pollable */
  489. #define MODE_MIC (1<<15) /* enable MIC */
  490. u16 rmode; /* receive mode */
  491. #define RXMODE_BC_MC_ADDR 0
  492. #define RXMODE_BC_ADDR 1 /* ignore multicasts */
  493. #define RXMODE_ADDR 2 /* ignore multicast and broadcast */
  494. #define RXMODE_RFMON 3 /* wireless monitor mode */
  495. #define RXMODE_RFMON_ANYBSS 4
  496. #define RXMODE_LANMON 5 /* lan style monitor -- data packets only */
  497. #define RXMODE_DISABLE_802_3_HEADER (1<<8) /* disables 802.3 header on rx */
  498. #define RXMODE_NORMALIZED_RSSI (1<<9) /* return normalized RSSI */
  499. u16 fragThresh;
  500. u16 rtsThres;
  501. u8 macAddr[ETH_ALEN];
  502. u8 rates[8];
  503. u16 shortRetryLimit;
  504. u16 longRetryLimit;
  505. u16 txLifetime; /* in kusec */
  506. u16 rxLifetime; /* in kusec */
  507. u16 stationary;
  508. u16 ordering;
  509. u16 u16deviceType; /* for overriding device type */
  510. u16 cfpRate;
  511. u16 cfpDuration;
  512. u16 _reserved1[3];
  513. /*---------- Scanning/Associating ----------*/
  514. u16 scanMode;
  515. #define SCANMODE_ACTIVE 0
  516. #define SCANMODE_PASSIVE 1
  517. #define SCANMODE_AIROSCAN 2
  518. u16 probeDelay; /* in kusec */
  519. u16 probeEnergyTimeout; /* in kusec */
  520. u16 probeResponseTimeout;
  521. u16 beaconListenTimeout;
  522. u16 joinNetTimeout;
  523. u16 authTimeout;
  524. u16 authType;
  525. #define AUTH_OPEN 0x1
  526. #define AUTH_ENCRYPT 0x101
  527. #define AUTH_SHAREDKEY 0x102
  528. #define AUTH_ALLOW_UNENCRYPTED 0x200
  529. u16 associationTimeout;
  530. u16 specifiedApTimeout;
  531. u16 offlineScanInterval;
  532. u16 offlineScanDuration;
  533. u16 linkLossDelay;
  534. u16 maxBeaconLostTime;
  535. u16 refreshInterval;
  536. #define DISABLE_REFRESH 0xFFFF
  537. u16 _reserved1a[1];
  538. /*---------- Power save operation ----------*/
  539. u16 powerSaveMode;
  540. #define POWERSAVE_CAM 0
  541. #define POWERSAVE_PSP 1
  542. #define POWERSAVE_PSPCAM 2
  543. u16 sleepForDtims;
  544. u16 listenInterval;
  545. u16 fastListenInterval;
  546. u16 listenDecay;
  547. u16 fastListenDelay;
  548. u16 _reserved2[2];
  549. /*---------- Ap/Ibss config items ----------*/
  550. u16 beaconPeriod;
  551. u16 atimDuration;
  552. u16 hopPeriod;
  553. u16 channelSet;
  554. u16 channel;
  555. u16 dtimPeriod;
  556. u16 bridgeDistance;
  557. u16 radioID;
  558. /*---------- Radio configuration ----------*/
  559. u16 radioType;
  560. #define RADIOTYPE_DEFAULT 0
  561. #define RADIOTYPE_802_11 1
  562. #define RADIOTYPE_LEGACY 2
  563. u8 rxDiversity;
  564. u8 txDiversity;
  565. u16 txPower;
  566. #define TXPOWER_DEFAULT 0
  567. u16 rssiThreshold;
  568. #define RSSI_DEFAULT 0
  569. u16 modulation;
  570. #define PREAMBLE_AUTO 0
  571. #define PREAMBLE_LONG 1
  572. #define PREAMBLE_SHORT 2
  573. u16 preamble;
  574. u16 homeProduct;
  575. u16 radioSpecific;
  576. /*---------- Aironet Extensions ----------*/
  577. u8 nodeName[16];
  578. u16 arlThreshold;
  579. u16 arlDecay;
  580. u16 arlDelay;
  581. u16 _reserved4[1];
  582. /*---------- Aironet Extensions ----------*/
  583. u8 magicAction;
  584. #define MAGIC_ACTION_STSCHG 1
  585. #define MAGIC_ACTION_RESUME 2
  586. #define MAGIC_IGNORE_MCAST (1<<8)
  587. #define MAGIC_IGNORE_BCAST (1<<9)
  588. #define MAGIC_SWITCH_TO_PSP (0<<10)
  589. #define MAGIC_STAY_IN_CAM (1<<10)
  590. u8 magicControl;
  591. u16 autoWake;
  592. } ConfigRid;
  593. typedef struct {
  594. u16 len;
  595. u8 mac[ETH_ALEN];
  596. u16 mode;
  597. u16 errorCode;
  598. u16 sigQuality;
  599. u16 SSIDlen;
  600. char SSID[32];
  601. char apName[16];
  602. u8 bssid[4][ETH_ALEN];
  603. u16 beaconPeriod;
  604. u16 dimPeriod;
  605. u16 atimDuration;
  606. u16 hopPeriod;
  607. u16 channelSet;
  608. u16 channel;
  609. u16 hopsToBackbone;
  610. u16 apTotalLoad;
  611. u16 generatedLoad;
  612. u16 accumulatedArl;
  613. u16 signalQuality;
  614. u16 currentXmitRate;
  615. u16 apDevExtensions;
  616. u16 normalizedSignalStrength;
  617. u16 shortPreamble;
  618. u8 apIP[4];
  619. u8 noisePercent; /* Noise percent in last second */
  620. u8 noisedBm; /* Noise dBm in last second */
  621. u8 noiseAvePercent; /* Noise percent in last minute */
  622. u8 noiseAvedBm; /* Noise dBm in last minute */
  623. u8 noiseMaxPercent; /* Highest noise percent in last minute */
  624. u8 noiseMaxdBm; /* Highest noise dbm in last minute */
  625. u16 load;
  626. u8 carrier[4];
  627. u16 assocStatus;
  628. #define STAT_NOPACKETS 0
  629. #define STAT_NOCARRIERSET 10
  630. #define STAT_GOTCARRIERSET 11
  631. #define STAT_WRONGSSID 20
  632. #define STAT_BADCHANNEL 25
  633. #define STAT_BADBITRATES 30
  634. #define STAT_BADPRIVACY 35
  635. #define STAT_APFOUND 40
  636. #define STAT_APREJECTED 50
  637. #define STAT_AUTHENTICATING 60
  638. #define STAT_DEAUTHENTICATED 61
  639. #define STAT_AUTHTIMEOUT 62
  640. #define STAT_ASSOCIATING 70
  641. #define STAT_DEASSOCIATED 71
  642. #define STAT_ASSOCTIMEOUT 72
  643. #define STAT_NOTAIROAP 73
  644. #define STAT_ASSOCIATED 80
  645. #define STAT_LEAPING 90
  646. #define STAT_LEAPFAILED 91
  647. #define STAT_LEAPTIMEDOUT 92
  648. #define STAT_LEAPCOMPLETE 93
  649. } StatusRid;
  650. typedef struct {
  651. u16 len;
  652. u16 spacer;
  653. u32 vals[100];
  654. } StatsRid;
  655. typedef struct {
  656. u16 len;
  657. u8 ap[4][ETH_ALEN];
  658. } APListRid;
  659. typedef struct {
  660. u16 len;
  661. char oui[3];
  662. char zero;
  663. u16 prodNum;
  664. char manName[32];
  665. char prodName[16];
  666. char prodVer[8];
  667. char factoryAddr[ETH_ALEN];
  668. char aironetAddr[ETH_ALEN];
  669. u16 radioType;
  670. u16 country;
  671. char callid[ETH_ALEN];
  672. char supportedRates[8];
  673. char rxDiversity;
  674. char txDiversity;
  675. u16 txPowerLevels[8];
  676. u16 hardVer;
  677. u16 hardCap;
  678. u16 tempRange;
  679. u16 softVer;
  680. u16 softSubVer;
  681. u16 interfaceVer;
  682. u16 softCap;
  683. u16 bootBlockVer;
  684. u16 requiredHard;
  685. u16 extSoftCap;
  686. } CapabilityRid;
  687. typedef struct {
  688. u16 len;
  689. u16 index; /* First is 0 and 0xffff means end of list */
  690. #define RADIO_FH 1 /* Frequency hopping radio type */
  691. #define RADIO_DS 2 /* Direct sequence radio type */
  692. #define RADIO_TMA 4 /* Proprietary radio used in old cards (2500) */
  693. u16 radioType;
  694. u8 bssid[ETH_ALEN]; /* Mac address of the BSS */
  695. u8 zero;
  696. u8 ssidLen;
  697. u8 ssid[32];
  698. u16 dBm;
  699. #define CAP_ESS (1<<0)
  700. #define CAP_IBSS (1<<1)
  701. #define CAP_PRIVACY (1<<4)
  702. #define CAP_SHORTHDR (1<<5)
  703. u16 cap;
  704. u16 beaconInterval;
  705. u8 rates[8]; /* Same as rates for config rid */
  706. struct { /* For frequency hopping only */
  707. u16 dwell;
  708. u8 hopSet;
  709. u8 hopPattern;
  710. u8 hopIndex;
  711. u8 fill;
  712. } fh;
  713. u16 dsChannel;
  714. u16 atimWindow;
  715. } BSSListRid;
  716. typedef struct {
  717. u8 rssipct;
  718. u8 rssidBm;
  719. } tdsRssiEntry;
  720. typedef struct {
  721. u16 len;
  722. tdsRssiEntry x[256];
  723. } tdsRssiRid;
  724. typedef struct {
  725. u16 len;
  726. u16 state;
  727. u16 multicastValid;
  728. u8 multicast[16];
  729. u16 unicastValid;
  730. u8 unicast[16];
  731. } MICRid;
  732. typedef struct {
  733. u16 typelen;
  734. union {
  735. u8 snap[8];
  736. struct {
  737. u8 dsap;
  738. u8 ssap;
  739. u8 control;
  740. u8 orgcode[3];
  741. u8 fieldtype[2];
  742. } llc;
  743. } u;
  744. u32 mic;
  745. u32 seq;
  746. } MICBuffer;
  747. typedef struct {
  748. u8 da[ETH_ALEN];
  749. u8 sa[ETH_ALEN];
  750. } etherHead;
  751. #pragma pack()
  752. #define TXCTL_TXOK (1<<1) /* report if tx is ok */
  753. #define TXCTL_TXEX (1<<2) /* report if tx fails */
  754. #define TXCTL_802_3 (0<<3) /* 802.3 packet */
  755. #define TXCTL_802_11 (1<<3) /* 802.11 mac packet */
  756. #define TXCTL_ETHERNET (0<<4) /* payload has ethertype */
  757. #define TXCTL_LLC (1<<4) /* payload is llc */
  758. #define TXCTL_RELEASE (0<<5) /* release after completion */
  759. #define TXCTL_NORELEASE (1<<5) /* on completion returns to host */
  760. #define BUSY_FID 0x10000
  761. #ifdef CISCO_EXT
  762. #define AIROMAGIC 0xa55a
  763. /* Warning : SIOCDEVPRIVATE may disapear during 2.5.X - Jean II */
  764. #ifdef SIOCIWFIRSTPRIV
  765. #ifdef SIOCDEVPRIVATE
  766. #define AIROOLDIOCTL SIOCDEVPRIVATE
  767. #define AIROOLDIDIFC AIROOLDIOCTL + 1
  768. #endif /* SIOCDEVPRIVATE */
  769. #else /* SIOCIWFIRSTPRIV */
  770. #define SIOCIWFIRSTPRIV SIOCDEVPRIVATE
  771. #endif /* SIOCIWFIRSTPRIV */
  772. /* This may be wrong. When using the new SIOCIWFIRSTPRIV range, we probably
  773. * should use only "GET" ioctls (last bit set to 1). "SET" ioctls are root
  774. * only and don't return the modified struct ifreq to the application which
  775. * is usually a problem. - Jean II */
  776. #define AIROIOCTL SIOCIWFIRSTPRIV
  777. #define AIROIDIFC AIROIOCTL + 1
  778. /* Ioctl constants to be used in airo_ioctl.command */
  779. #define AIROGCAP 0 // Capability rid
  780. #define AIROGCFG 1 // USED A LOT
  781. #define AIROGSLIST 2 // System ID list
  782. #define AIROGVLIST 3 // List of specified AP's
  783. #define AIROGDRVNAM 4 // NOTUSED
  784. #define AIROGEHTENC 5 // NOTUSED
  785. #define AIROGWEPKTMP 6
  786. #define AIROGWEPKNV 7
  787. #define AIROGSTAT 8
  788. #define AIROGSTATSC32 9
  789. #define AIROGSTATSD32 10
  790. #define AIROGMICRID 11
  791. #define AIROGMICSTATS 12
  792. #define AIROGFLAGS 13
  793. #define AIROGID 14
  794. #define AIRORRID 15
  795. #define AIRORSWVERSION 17
  796. /* Leave gap of 40 commands after AIROGSTATSD32 for future */
  797. #define AIROPCAP AIROGSTATSD32 + 40
  798. #define AIROPVLIST AIROPCAP + 1
  799. #define AIROPSLIST AIROPVLIST + 1
  800. #define AIROPCFG AIROPSLIST + 1
  801. #define AIROPSIDS AIROPCFG + 1
  802. #define AIROPAPLIST AIROPSIDS + 1
  803. #define AIROPMACON AIROPAPLIST + 1 /* Enable mac */
  804. #define AIROPMACOFF AIROPMACON + 1 /* Disable mac */
  805. #define AIROPSTCLR AIROPMACOFF + 1
  806. #define AIROPWEPKEY AIROPSTCLR + 1
  807. #define AIROPWEPKEYNV AIROPWEPKEY + 1
  808. #define AIROPLEAPPWD AIROPWEPKEYNV + 1
  809. #define AIROPLEAPUSR AIROPLEAPPWD + 1
  810. /* Flash codes */
  811. #define AIROFLSHRST AIROPWEPKEYNV + 40
  812. #define AIROFLSHGCHR AIROFLSHRST + 1
  813. #define AIROFLSHSTFL AIROFLSHGCHR + 1
  814. #define AIROFLSHPCHR AIROFLSHSTFL + 1
  815. #define AIROFLPUTBUF AIROFLSHPCHR + 1
  816. #define AIRORESTART AIROFLPUTBUF + 1
  817. #define FLASHSIZE 32768
  818. #define AUXMEMSIZE (256 * 1024)
  819. typedef struct aironet_ioctl {
  820. unsigned short command; // What to do
  821. unsigned short len; // Len of data
  822. unsigned short ridnum; // rid number
  823. unsigned char __user *data; // d-data
  824. } aironet_ioctl;
  825. static char swversion[] = "2.1";
  826. #endif /* CISCO_EXT */
  827. #define NUM_MODULES 2
  828. #define MIC_MSGLEN_MAX 2400
  829. #define EMMH32_MSGLEN_MAX MIC_MSGLEN_MAX
  830. typedef struct {
  831. u32 size; // size
  832. u8 enabled; // MIC enabled or not
  833. u32 rxSuccess; // successful packets received
  834. u32 rxIncorrectMIC; // pkts dropped due to incorrect MIC comparison
  835. u32 rxNotMICed; // pkts dropped due to not being MIC'd
  836. u32 rxMICPlummed; // pkts dropped due to not having a MIC plummed
  837. u32 rxWrongSequence; // pkts dropped due to sequence number violation
  838. u32 reserve[32];
  839. } mic_statistics;
  840. typedef struct {
  841. u32 coeff[((EMMH32_MSGLEN_MAX)+3)>>2];
  842. u64 accum; // accumulated mic, reduced to u32 in final()
  843. int position; // current position (byte offset) in message
  844. union {
  845. u8 d8[4];
  846. u32 d32;
  847. } part; // saves partial message word across update() calls
  848. } emmh32_context;
  849. typedef struct {
  850. emmh32_context seed; // Context - the seed
  851. u32 rx; // Received sequence number
  852. u32 tx; // Tx sequence number
  853. u32 window; // Start of window
  854. u8 valid; // Flag to say if context is valid or not
  855. u8 key[16];
  856. } miccntx;
  857. typedef struct {
  858. miccntx mCtx; // Multicast context
  859. miccntx uCtx; // Unicast context
  860. } mic_module;
  861. typedef struct {
  862. unsigned int rid: 16;
  863. unsigned int len: 15;
  864. unsigned int valid: 1;
  865. dma_addr_t host_addr;
  866. } Rid;
  867. typedef struct {
  868. unsigned int offset: 15;
  869. unsigned int eoc: 1;
  870. unsigned int len: 15;
  871. unsigned int valid: 1;
  872. dma_addr_t host_addr;
  873. } TxFid;
  874. typedef struct {
  875. unsigned int ctl: 15;
  876. unsigned int rdy: 1;
  877. unsigned int len: 15;
  878. unsigned int valid: 1;
  879. dma_addr_t host_addr;
  880. } RxFid;
  881. /*
  882. * Host receive descriptor
  883. */
  884. typedef struct {
  885. unsigned char __iomem *card_ram_off; /* offset into card memory of the
  886. desc */
  887. RxFid rx_desc; /* card receive descriptor */
  888. char *virtual_host_addr; /* virtual address of host receive
  889. buffer */
  890. int pending;
  891. } HostRxDesc;
  892. /*
  893. * Host transmit descriptor
  894. */
  895. typedef struct {
  896. unsigned char __iomem *card_ram_off; /* offset into card memory of the
  897. desc */
  898. TxFid tx_desc; /* card transmit descriptor */
  899. char *virtual_host_addr; /* virtual address of host receive
  900. buffer */
  901. int pending;
  902. } HostTxDesc;
  903. /*
  904. * Host RID descriptor
  905. */
  906. typedef struct {
  907. unsigned char __iomem *card_ram_off; /* offset into card memory of the
  908. descriptor */
  909. Rid rid_desc; /* card RID descriptor */
  910. char *virtual_host_addr; /* virtual address of host receive
  911. buffer */
  912. } HostRidDesc;
  913. typedef struct {
  914. u16 sw0;
  915. u16 sw1;
  916. u16 status;
  917. u16 len;
  918. #define HOST_SET (1 << 0)
  919. #define HOST_INT_TX (1 << 1) /* Interrupt on successful TX */
  920. #define HOST_INT_TXERR (1 << 2) /* Interrupt on unseccessful TX */
  921. #define HOST_LCC_PAYLOAD (1 << 4) /* LLC payload, 0 = Ethertype */
  922. #define HOST_DONT_RLSE (1 << 5) /* Don't release buffer when done */
  923. #define HOST_DONT_RETRY (1 << 6) /* Don't retry trasmit */
  924. #define HOST_CLR_AID (1 << 7) /* clear AID failure */
  925. #define HOST_RTS (1 << 9) /* Force RTS use */
  926. #define HOST_SHORT (1 << 10) /* Do short preamble */
  927. u16 ctl;
  928. u16 aid;
  929. u16 retries;
  930. u16 fill;
  931. } TxCtlHdr;
  932. typedef struct {
  933. u16 ctl;
  934. u16 duration;
  935. char addr1[6];
  936. char addr2[6];
  937. char addr3[6];
  938. u16 seq;
  939. char addr4[6];
  940. } WifiHdr;
  941. typedef struct {
  942. TxCtlHdr ctlhdr;
  943. u16 fill1;
  944. u16 fill2;
  945. WifiHdr wifihdr;
  946. u16 gaplen;
  947. u16 status;
  948. } WifiCtlHdr;
  949. static WifiCtlHdr wifictlhdr8023 = {
  950. .ctlhdr = {
  951. .ctl = HOST_DONT_RLSE,
  952. }
  953. };
  954. // Frequency list (map channels to frequencies)
  955. static const long frequency_list[] = { 2412, 2417, 2422, 2427, 2432, 2437, 2442,
  956. 2447, 2452, 2457, 2462, 2467, 2472, 2484 };
  957. // A few details needed for WEP (Wireless Equivalent Privacy)
  958. #define MAX_KEY_SIZE 13 // 128 (?) bits
  959. #define MIN_KEY_SIZE 5 // 40 bits RC4 - WEP
  960. typedef struct wep_key_t {
  961. u16 len;
  962. u8 key[16]; /* 40-bit and 104-bit keys */
  963. } wep_key_t;
  964. /* Backward compatibility */
  965. #ifndef IW_ENCODE_NOKEY
  966. #define IW_ENCODE_NOKEY 0x0800 /* Key is write only, so not present */
  967. #define IW_ENCODE_MODE (IW_ENCODE_DISABLED | IW_ENCODE_RESTRICTED | IW_ENCODE_OPEN)
  968. #endif /* IW_ENCODE_NOKEY */
  969. /* List of Wireless Handlers (new API) */
  970. static const struct iw_handler_def airo_handler_def;
  971. static const char version[] = "airo.c 0.6 (Ben Reed & Javier Achirica)";
  972. struct airo_info;
  973. static int get_dec_u16( char *buffer, int *start, int limit );
  974. static void OUT4500( struct airo_info *, u16 register, u16 value );
  975. static unsigned short IN4500( struct airo_info *, u16 register );
  976. static u16 setup_card(struct airo_info*, u8 *mac, int lock);
  977. static int enable_MAC( struct airo_info *ai, Resp *rsp, int lock );
  978. static void disable_MAC(struct airo_info *ai, int lock);
  979. static void enable_interrupts(struct airo_info*);
  980. static void disable_interrupts(struct airo_info*);
  981. static u16 issuecommand(struct airo_info*, Cmd *pCmd, Resp *pRsp);
  982. static int bap_setup(struct airo_info*, u16 rid, u16 offset, int whichbap);
  983. static int aux_bap_read(struct airo_info*, u16 *pu16Dst, int bytelen,
  984. int whichbap);
  985. static int fast_bap_read(struct airo_info*, u16 *pu16Dst, int bytelen,
  986. int whichbap);
  987. static int bap_write(struct airo_info*, const u16 *pu16Src, int bytelen,
  988. int whichbap);
  989. static int PC4500_accessrid(struct airo_info*, u16 rid, u16 accmd);
  990. static int PC4500_readrid(struct airo_info*, u16 rid, void *pBuf, int len, int lock);
  991. static int PC4500_writerid(struct airo_info*, u16 rid, const void
  992. *pBuf, int len, int lock);
  993. static int do_writerid( struct airo_info*, u16 rid, const void *rid_data,
  994. int len, int dummy );
  995. static u16 transmit_allocate(struct airo_info*, int lenPayload, int raw);
  996. static int transmit_802_3_packet(struct airo_info*, int len, char *pPacket);
  997. static int transmit_802_11_packet(struct airo_info*, int len, char *pPacket);
  998. static int mpi_send_packet (struct net_device *dev);
  999. static void mpi_unmap_card(struct pci_dev *pci);
  1000. static void mpi_receive_802_3(struct airo_info *ai);
  1001. static void mpi_receive_802_11(struct airo_info *ai);
  1002. static int waitbusy (struct airo_info *ai);
  1003. static irqreturn_t airo_interrupt( int irq, void* dev_id, struct pt_regs
  1004. *regs);
  1005. static int airo_thread(void *data);
  1006. static void timer_func( struct net_device *dev );
  1007. static int airo_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
  1008. static struct iw_statistics *airo_get_wireless_stats (struct net_device *dev);
  1009. static void airo_read_wireless_stats (struct airo_info *local);
  1010. #ifdef CISCO_EXT
  1011. static int readrids(struct net_device *dev, aironet_ioctl *comp);
  1012. static int writerids(struct net_device *dev, aironet_ioctl *comp);
  1013. static int flashcard(struct net_device *dev, aironet_ioctl *comp);
  1014. #endif /* CISCO_EXT */
  1015. #ifdef MICSUPPORT
  1016. static void micinit(struct airo_info *ai);
  1017. static int micsetup(struct airo_info *ai);
  1018. static int encapsulate(struct airo_info *ai, etherHead *pPacket, MICBuffer *buffer, int len);
  1019. static int decapsulate(struct airo_info *ai, MICBuffer *mic, etherHead *pPacket, u16 payLen);
  1020. static u8 airo_rssi_to_dbm (tdsRssiEntry *rssi_rid, u8 rssi);
  1021. static u8 airo_dbm_to_pct (tdsRssiEntry *rssi_rid, u8 dbm);
  1022. #include <linux/crypto.h>
  1023. #endif
  1024. struct airo_info {
  1025. struct net_device_stats stats;
  1026. struct net_device *dev;
  1027. /* Note, we can have MAX_FIDS outstanding. FIDs are 16-bits, so we
  1028. use the high bit to mark whether it is in use. */
  1029. #define MAX_FIDS 6
  1030. #define MPI_MAX_FIDS 1
  1031. int fids[MAX_FIDS];
  1032. ConfigRid config;
  1033. char keyindex; // Used with auto wep
  1034. char defindex; // Used with auto wep
  1035. struct proc_dir_entry *proc_entry;
  1036. spinlock_t aux_lock;
  1037. unsigned long flags;
  1038. #define FLAG_PROMISC 8 /* IFF_PROMISC 0x100 - include/linux/if.h */
  1039. #define FLAG_RADIO_OFF 0 /* User disabling of MAC */
  1040. #define FLAG_RADIO_DOWN 1 /* ifup/ifdown disabling of MAC */
  1041. #define FLAG_RADIO_MASK 0x03
  1042. #define FLAG_ENABLED 2
  1043. #define FLAG_ADHOC 3 /* Needed by MIC */
  1044. #define FLAG_MIC_CAPABLE 4
  1045. #define FLAG_UPDATE_MULTI 5
  1046. #define FLAG_UPDATE_UNI 6
  1047. #define FLAG_802_11 7
  1048. #define FLAG_PENDING_XMIT 9
  1049. #define FLAG_PENDING_XMIT11 10
  1050. #define FLAG_MPI 11
  1051. #define FLAG_REGISTERED 12
  1052. #define FLAG_COMMIT 13
  1053. #define FLAG_RESET 14
  1054. #define FLAG_FLASHING 15
  1055. #define JOB_MASK 0x1ff0000
  1056. #define JOB_DIE 16
  1057. #define JOB_XMIT 17
  1058. #define JOB_XMIT11 18
  1059. #define JOB_STATS 19
  1060. #define JOB_PROMISC 20
  1061. #define JOB_MIC 21
  1062. #define JOB_EVENT 22
  1063. #define JOB_AUTOWEP 23
  1064. #define JOB_WSTATS 24
  1065. int (*bap_read)(struct airo_info*, u16 *pu16Dst, int bytelen,
  1066. int whichbap);
  1067. unsigned short *flash;
  1068. tdsRssiEntry *rssi;
  1069. struct task_struct *task;
  1070. struct semaphore sem;
  1071. pid_t thr_pid;
  1072. wait_queue_head_t thr_wait;
  1073. struct completion thr_exited;
  1074. unsigned long expires;
  1075. struct {
  1076. struct sk_buff *skb;
  1077. int fid;
  1078. } xmit, xmit11;
  1079. struct net_device *wifidev;
  1080. struct iw_statistics wstats; // wireless stats
  1081. unsigned long scan_timestamp; /* Time started to scan */
  1082. struct iw_spy_data spy_data;
  1083. struct iw_public_data wireless_data;
  1084. #ifdef MICSUPPORT
  1085. /* MIC stuff */
  1086. struct crypto_tfm *tfm;
  1087. mic_module mod[2];
  1088. mic_statistics micstats;
  1089. #endif
  1090. HostRxDesc rxfids[MPI_MAX_FIDS]; // rx/tx/config MPI350 descriptors
  1091. HostTxDesc txfids[MPI_MAX_FIDS];
  1092. HostRidDesc config_desc;
  1093. unsigned long ridbus; // phys addr of config_desc
  1094. struct sk_buff_head txq;// tx queue used by mpi350 code
  1095. struct pci_dev *pci;
  1096. unsigned char __iomem *pcimem;
  1097. unsigned char __iomem *pciaux;
  1098. unsigned char *shared;
  1099. dma_addr_t shared_dma;
  1100. pm_message_t power;
  1101. SsidRid *SSID;
  1102. APListRid *APList;
  1103. #define PCI_SHARED_LEN 2*MPI_MAX_FIDS*PKTSIZE+RIDSIZE
  1104. char proc_name[IFNAMSIZ];
  1105. };
  1106. static inline int bap_read(struct airo_info *ai, u16 *pu16Dst, int bytelen,
  1107. int whichbap) {
  1108. return ai->bap_read(ai, pu16Dst, bytelen, whichbap);
  1109. }
  1110. static int setup_proc_entry( struct net_device *dev,
  1111. struct airo_info *apriv );
  1112. static int takedown_proc_entry( struct net_device *dev,
  1113. struct airo_info *apriv );
  1114. static int cmdreset(struct airo_info *ai);
  1115. static int setflashmode (struct airo_info *ai);
  1116. static int flashgchar(struct airo_info *ai,int matchbyte,int dwelltime);
  1117. static int flashputbuf(struct airo_info *ai);
  1118. static int flashrestart(struct airo_info *ai,struct net_device *dev);
  1119. #ifdef MICSUPPORT
  1120. /***********************************************************************
  1121. * MIC ROUTINES *
  1122. ***********************************************************************
  1123. */
  1124. static int RxSeqValid (struct airo_info *ai,miccntx *context,int mcast,u32 micSeq);
  1125. static void MoveWindow(miccntx *context, u32 micSeq);
  1126. static void emmh32_setseed(emmh32_context *context, u8 *pkey, int keylen, struct crypto_tfm *);
  1127. static void emmh32_init(emmh32_context *context);
  1128. static void emmh32_update(emmh32_context *context, u8 *pOctets, int len);
  1129. static void emmh32_final(emmh32_context *context, u8 digest[4]);
  1130. static int flashpchar(struct airo_info *ai,int byte,int dwelltime);
  1131. /* micinit - Initialize mic seed */
  1132. static void micinit(struct airo_info *ai)
  1133. {
  1134. MICRid mic_rid;
  1135. clear_bit(JOB_MIC, &ai->flags);
  1136. PC4500_readrid(ai, RID_MIC, &mic_rid, sizeof(mic_rid), 0);
  1137. up(&ai->sem);
  1138. ai->micstats.enabled = (mic_rid.state & 0x00FF) ? 1 : 0;
  1139. if (ai->micstats.enabled) {
  1140. /* Key must be valid and different */
  1141. if (mic_rid.multicastValid && (!ai->mod[0].mCtx.valid ||
  1142. (memcmp (ai->mod[0].mCtx.key, mic_rid.multicast,
  1143. sizeof(ai->mod[0].mCtx.key)) != 0))) {
  1144. /* Age current mic Context */
  1145. memcpy(&ai->mod[1].mCtx,&ai->mod[0].mCtx,sizeof(miccntx));
  1146. /* Initialize new context */
  1147. memcpy(&ai->mod[0].mCtx.key,mic_rid.multicast,sizeof(mic_rid.multicast));
  1148. ai->mod[0].mCtx.window = 33; //Window always points to the middle
  1149. ai->mod[0].mCtx.rx = 0; //Rx Sequence numbers
  1150. ai->mod[0].mCtx.tx = 0; //Tx sequence numbers
  1151. ai->mod[0].mCtx.valid = 1; //Key is now valid
  1152. /* Give key to mic seed */
  1153. emmh32_setseed(&ai->mod[0].mCtx.seed,mic_rid.multicast,sizeof(mic_rid.multicast), ai->tfm);
  1154. }
  1155. /* Key must be valid and different */
  1156. if (mic_rid.unicastValid && (!ai->mod[0].uCtx.valid ||
  1157. (memcmp(ai->mod[0].uCtx.key, mic_rid.unicast,
  1158. sizeof(ai->mod[0].uCtx.key)) != 0))) {
  1159. /* Age current mic Context */
  1160. memcpy(&ai->mod[1].uCtx,&ai->mod[0].uCtx,sizeof(miccntx));
  1161. /* Initialize new context */
  1162. memcpy(&ai->mod[0].uCtx.key,mic_rid.unicast,sizeof(mic_rid.unicast));
  1163. ai->mod[0].uCtx.window = 33; //Window always points to the middle
  1164. ai->mod[0].uCtx.rx = 0; //Rx Sequence numbers
  1165. ai->mod[0].uCtx.tx = 0; //Tx sequence numbers
  1166. ai->mod[0].uCtx.valid = 1; //Key is now valid
  1167. //Give key to mic seed
  1168. emmh32_setseed(&ai->mod[0].uCtx.seed, mic_rid.unicast, sizeof(mic_rid.unicast), ai->tfm);
  1169. }
  1170. } else {
  1171. /* So next time we have a valid key and mic is enabled, we will update
  1172. * the sequence number if the key is the same as before.
  1173. */
  1174. ai->mod[0].uCtx.valid = 0;
  1175. ai->mod[0].mCtx.valid = 0;
  1176. }
  1177. }
  1178. /* micsetup - Get ready for business */
  1179. static int micsetup(struct airo_info *ai) {
  1180. int i;
  1181. if (ai->tfm == NULL)
  1182. ai->tfm = crypto_alloc_tfm("aes", CRYPTO_TFM_REQ_MAY_SLEEP);
  1183. if (ai->tfm == NULL) {
  1184. printk(KERN_ERR "airo: failed to load transform for AES\n");
  1185. return ERROR;
  1186. }
  1187. for (i=0; i < NUM_MODULES; i++) {
  1188. memset(&ai->mod[i].mCtx,0,sizeof(miccntx));
  1189. memset(&ai->mod[i].uCtx,0,sizeof(miccntx));
  1190. }
  1191. return SUCCESS;
  1192. }
  1193. static char micsnap[] = {0xAA,0xAA,0x03,0x00,0x40,0x96,0x00,0x02};
  1194. /*===========================================================================
  1195. * Description: Mic a packet
  1196. *
  1197. * Inputs: etherHead * pointer to an 802.3 frame
  1198. *
  1199. * Returns: BOOLEAN if successful, otherwise false.
  1200. * PacketTxLen will be updated with the mic'd packets size.
  1201. *
  1202. * Caveats: It is assumed that the frame buffer will already
  1203. * be big enough to hold the largets mic message possible.
  1204. * (No memory allocation is done here).
  1205. *
  1206. * Author: sbraneky (10/15/01)
  1207. * Merciless hacks by rwilcher (1/14/02)
  1208. */
  1209. static int encapsulate(struct airo_info *ai ,etherHead *frame, MICBuffer *mic, int payLen)
  1210. {
  1211. miccntx *context;
  1212. // Determine correct context
  1213. // If not adhoc, always use unicast key
  1214. if (test_bit(FLAG_ADHOC, &ai->flags) && (frame->da[0] & 0x1))
  1215. context = &ai->mod[0].mCtx;
  1216. else
  1217. context = &ai->mod[0].uCtx;
  1218. if (!context->valid)
  1219. return ERROR;
  1220. mic->typelen = htons(payLen + 16); //Length of Mic'd packet
  1221. memcpy(&mic->u.snap, micsnap, sizeof(micsnap)); // Add Snap
  1222. // Add Tx sequence
  1223. mic->seq = htonl(context->tx);
  1224. context->tx += 2;
  1225. emmh32_init(&context->seed); // Mic the packet
  1226. emmh32_update(&context->seed,frame->da,ETH_ALEN * 2); // DA,SA
  1227. emmh32_update(&context->seed,(u8*)&mic->typelen,10); // Type/Length and Snap
  1228. emmh32_update(&context->seed,(u8*)&mic->seq,sizeof(mic->seq)); //SEQ
  1229. emmh32_update(&context->seed,frame->da + ETH_ALEN * 2,payLen); //payload
  1230. emmh32_final(&context->seed, (u8*)&mic->mic);
  1231. /* New Type/length ?????????? */
  1232. mic->typelen = 0; //Let NIC know it could be an oversized packet
  1233. return SUCCESS;
  1234. }
  1235. typedef enum {
  1236. NONE,
  1237. NOMIC,
  1238. NOMICPLUMMED,
  1239. SEQUENCE,
  1240. INCORRECTMIC,
  1241. } mic_error;
  1242. /*===========================================================================
  1243. * Description: Decapsulates a MIC'd packet and returns the 802.3 packet
  1244. * (removes the MIC stuff) if packet is a valid packet.
  1245. *
  1246. * Inputs: etherHead pointer to the 802.3 packet
  1247. *
  1248. * Returns: BOOLEAN - TRUE if packet should be dropped otherwise FALSE
  1249. *
  1250. * Author: sbraneky (10/15/01)
  1251. * Merciless hacks by rwilcher (1/14/02)
  1252. *---------------------------------------------------------------------------
  1253. */
  1254. static int decapsulate(struct airo_info *ai, MICBuffer *mic, etherHead *eth, u16 payLen)
  1255. {
  1256. int i;
  1257. u32 micSEQ;
  1258. miccntx *context;
  1259. u8 digest[4];
  1260. mic_error micError = NONE;
  1261. // Check if the packet is a Mic'd packet
  1262. if (!ai->micstats.enabled) {
  1263. //No Mic set or Mic OFF but we received a MIC'd packet.
  1264. if (memcmp ((u8*)eth + 14, micsnap, sizeof(micsnap)) == 0) {
  1265. ai->micstats.rxMICPlummed++;
  1266. return ERROR;
  1267. }
  1268. return SUCCESS;
  1269. }
  1270. if (ntohs(mic->typelen) == 0x888E)
  1271. return SUCCESS;
  1272. if (memcmp (mic->u.snap, micsnap, sizeof(micsnap)) != 0) {
  1273. // Mic enabled but packet isn't Mic'd
  1274. ai->micstats.rxMICPlummed++;
  1275. return ERROR;
  1276. }
  1277. micSEQ = ntohl(mic->seq); //store SEQ as CPU order
  1278. //At this point we a have a mic'd packet and mic is enabled
  1279. //Now do the mic error checking.
  1280. //Receive seq must be odd
  1281. if ( (micSEQ & 1) == 0 ) {
  1282. ai->micstats.rxWrongSequence++;
  1283. return ERROR;
  1284. }
  1285. for (i = 0; i < NUM_MODULES; i++) {
  1286. int mcast = eth->da[0] & 1;
  1287. //Determine proper context
  1288. context = mcast ? &ai->mod[i].mCtx : &ai->mod[i].uCtx;
  1289. //Make sure context is valid
  1290. if (!context->valid) {
  1291. if (i == 0)
  1292. micError = NOMICPLUMMED;
  1293. continue;
  1294. }
  1295. //DeMic it
  1296. if (!mic->typelen)
  1297. mic->typelen = htons(payLen + sizeof(MICBuffer) - 2);
  1298. emmh32_init(&context->seed);
  1299. emmh32_update(&context->seed, eth->da, ETH_ALEN*2);
  1300. emmh32_update(&context->seed, (u8 *)&mic->typelen, sizeof(mic->typelen)+sizeof(mic->u.snap));
  1301. emmh32_update(&context->seed, (u8 *)&mic->seq,sizeof(mic->seq));
  1302. emmh32_update(&context->seed, eth->da + ETH_ALEN*2,payLen);
  1303. //Calculate MIC
  1304. emmh32_final(&context->seed, digest);
  1305. if (memcmp(digest, &mic->mic, 4)) { //Make sure the mics match
  1306. //Invalid Mic
  1307. if (i == 0)
  1308. micError = INCORRECTMIC;
  1309. continue;
  1310. }
  1311. //Check Sequence number if mics pass
  1312. if (RxSeqValid(ai, context, mcast, micSEQ) == SUCCESS) {
  1313. ai->micstats.rxSuccess++;
  1314. return SUCCESS;
  1315. }
  1316. if (i == 0)
  1317. micError = SEQUENCE;
  1318. }
  1319. // Update statistics
  1320. switch (micError) {
  1321. case NOMICPLUMMED: ai->micstats.rxMICPlummed++; break;
  1322. case SEQUENCE: ai->micstats.rxWrongSequence++; break;
  1323. case INCORRECTMIC: ai->micstats.rxIncorrectMIC++; break;
  1324. case NONE: break;
  1325. case NOMIC: break;
  1326. }
  1327. return ERROR;
  1328. }
  1329. /*===========================================================================
  1330. * Description: Checks the Rx Seq number to make sure it is valid
  1331. * and hasn't already been received
  1332. *
  1333. * Inputs: miccntx - mic context to check seq against
  1334. * micSeq - the Mic seq number
  1335. *
  1336. * Returns: TRUE if valid otherwise FALSE.
  1337. *
  1338. * Author: sbraneky (10/15/01)
  1339. * Merciless hacks by rwilcher (1/14/02)
  1340. *---------------------------------------------------------------------------
  1341. */
  1342. static int RxSeqValid (struct airo_info *ai,miccntx *context,int mcast,u32 micSeq)
  1343. {
  1344. u32 seq,index;
  1345. //Allow for the ap being rebooted - if it is then use the next
  1346. //sequence number of the current sequence number - might go backwards
  1347. if (mcast) {
  1348. if (test_bit(FLAG_UPDATE_MULTI, &ai->flags)) {
  1349. clear_bit (FLAG_UPDATE_MULTI, &ai->flags);
  1350. context->window = (micSeq > 33) ? micSeq : 33;
  1351. context->rx = 0; // Reset rx
  1352. }
  1353. } else if (test_bit(FLAG_UPDATE_UNI, &ai->flags)) {
  1354. clear_bit (FLAG_UPDATE_UNI, &ai->flags);
  1355. context->window = (micSeq > 33) ? micSeq : 33; // Move window
  1356. context->rx = 0; // Reset rx
  1357. }
  1358. //Make sequence number relative to START of window
  1359. seq = micSeq - (context->window - 33);
  1360. //Too old of a SEQ number to check.
  1361. if ((s32)seq < 0)
  1362. return ERROR;
  1363. if ( seq > 64 ) {
  1364. //Window is infinite forward
  1365. MoveWindow(context,micSeq);
  1366. return SUCCESS;
  1367. }
  1368. // We are in the window. Now check the context rx bit to see if it was already sent
  1369. seq >>= 1; //divide by 2 because we only have odd numbers
  1370. index = 1 << seq; //Get an index number
  1371. if (!(context->rx & index)) {
  1372. //micSEQ falls inside the window.
  1373. //Add seqence number to the list of received numbers.
  1374. context->rx |= index;
  1375. MoveWindow(context,micSeq);
  1376. return SUCCESS;
  1377. }
  1378. return ERROR;
  1379. }
  1380. static void MoveWindow(miccntx *context, u32 micSeq)
  1381. {
  1382. u32 shift;
  1383. //Move window if seq greater than the middle of the window
  1384. if (micSeq > context->window) {
  1385. shift = (micSeq - context->window) >> 1;
  1386. //Shift out old
  1387. if (shift < 32)
  1388. context->rx >>= shift;
  1389. else
  1390. context->rx = 0;
  1391. context->window = micSeq; //Move window
  1392. }
  1393. }
  1394. /*==============================================*/
  1395. /*========== EMMH ROUTINES ====================*/
  1396. /*==============================================*/
  1397. /* mic accumulate */
  1398. #define MIC_ACCUM(val) \
  1399. context->accum += (u64)(val) * context->coeff[coeff_position++];
  1400. static unsigned char aes_counter[16];
  1401. /* expand the key to fill the MMH coefficient array */
  1402. static void emmh32_setseed(emmh32_context *context, u8 *pkey, int keylen, struct crypto_tfm *tfm)
  1403. {
  1404. /* take the keying material, expand if necessary, truncate at 16-bytes */
  1405. /* run through AES counter mode to generate context->coeff[] */
  1406. int i,j;
  1407. u32 counter;
  1408. u8 *cipher, plain[16];
  1409. struct scatterlist sg[1];
  1410. crypto_cipher_setkey(tfm, pkey, 16);
  1411. counter = 0;
  1412. for (i = 0; i < (sizeof(context->coeff)/sizeof(context->coeff[0])); ) {
  1413. aes_counter[15] = (u8)(counter >> 0);
  1414. aes_counter[14] = (u8)(counter >> 8);
  1415. aes_counter[13] = (u8)(counter >> 16);
  1416. aes_counter[12] = (u8)(counter >> 24);
  1417. counter++;
  1418. memcpy (plain, aes_counter, 16);
  1419. sg_set_buf(sg, plain, 16);
  1420. crypto_cipher_encrypt(tfm, sg, sg, 16);
  1421. cipher = kmap(sg->page) + sg->offset;
  1422. for (j=0; (j<16) && (i< (sizeof(context->coeff)/sizeof(context->coeff[0]))); ) {
  1423. context->coeff[i++] = ntohl(*(u32 *)&cipher[j]);
  1424. j += 4;
  1425. }
  1426. }
  1427. }
  1428. /* prepare for calculation of a new mic */
  1429. static void emmh32_init(emmh32_context *context)
  1430. {
  1431. /* prepare for new mic calculation */
  1432. context->accum = 0;
  1433. context->position = 0;
  1434. }
  1435. /* add some bytes to the mic calculation */
  1436. static void emmh32_update(emmh32_context *context, u8 *pOctets, int len)
  1437. {
  1438. int coeff_position, byte_position;
  1439. if (len == 0) return;
  1440. coeff_position = context->position >> 2;
  1441. /* deal with partial 32-bit word left over from last update */
  1442. byte_position = context->position & 3;
  1443. if (byte_position) {
  1444. /* have a partial word in part to deal with */
  1445. do {
  1446. if (len == 0) return;
  1447. context->part.d8[byte_position++] = *pOctets++;
  1448. context->position++;
  1449. len--;
  1450. } while (byte_position < 4);
  1451. MIC_ACCUM(htonl(context->part.d32));
  1452. }
  1453. /* deal with full 32-bit words */
  1454. while (len >= 4) {
  1455. MIC_ACCUM(htonl(*(u32 *)pOctets));
  1456. context->position += 4;
  1457. pOctets += 4;
  1458. len -= 4;
  1459. }
  1460. /* deal with partial 32-bit word that will be left over from this update */
  1461. byte_position = 0;
  1462. while (len > 0) {
  1463. context->part.d8[byte_position++] = *pOctets++;
  1464. context->position++;
  1465. len--;
  1466. }
  1467. }
  1468. /* mask used to zero empty bytes for final partial word */
  1469. static u32 mask32[4] = { 0x00000000L, 0xFF000000L, 0xFFFF0000L, 0xFFFFFF00L };
  1470. /* calculate the mic */
  1471. static void emmh32_final(emmh32_context *context, u8 digest[4])
  1472. {
  1473. int coeff_position, byte_position;
  1474. u32 val;
  1475. u64 sum, utmp;
  1476. s64 stmp;
  1477. coeff_position = context->position >> 2;
  1478. /* deal with partial 32-bit word left over from last update */
  1479. byte_position = context->position & 3;
  1480. if (byte_position) {
  1481. /* have a partial word in part to deal with */
  1482. val = htonl(context->part.d32);
  1483. MIC_ACCUM(val & mask32[byte_position]); /* zero empty bytes */
  1484. }
  1485. /* reduce the accumulated u64 to a 32-bit MIC */
  1486. sum = context->accum;
  1487. stmp = (sum & 0xffffffffLL) - ((sum >> 32) * 15);
  1488. utmp = (stmp & 0xffffffffLL) - ((stmp >> 32) * 15);
  1489. sum = utmp & 0xffffffffLL;
  1490. if (utmp > 0x10000000fLL)
  1491. sum -= 15;
  1492. val = (u32)sum;
  1493. digest[0] = (val>>24) & 0xFF;
  1494. digest[1] = (val>>16) & 0xFF;
  1495. digest[2] = (val>>8) & 0xFF;
  1496. digest[3] = val & 0xFF;
  1497. }
  1498. #endif
  1499. static int readBSSListRid(struct airo_info *ai, int first,
  1500. BSSListRid *list) {
  1501. int rc;
  1502. Cmd cmd;
  1503. Resp rsp;
  1504. if (first == 1) {
  1505. if (ai->flags & FLAG_RADIO_MASK) return -ENETDOWN;
  1506. memset(&cmd, 0, sizeof(cmd));
  1507. cmd.cmd=CMD_LISTBSS;
  1508. if (down_interruptible(&ai->sem))
  1509. return -ERESTARTSYS;
  1510. issuecommand(ai, &cmd, &rsp);
  1511. up(&ai->sem);
  1512. /* Let the command take effect */
  1513. ai->task = current;
  1514. ssleep(3);
  1515. ai->task = NULL;
  1516. }
  1517. rc = PC4500_readrid(ai, first ? RID_BSSLISTFIRST : RID_BSSLISTNEXT,
  1518. list, sizeof(*list), 1);
  1519. list->len = le16_to_cpu(list->len);
  1520. list->index = le16_to_cpu(list->index);
  1521. list->radioType = le16_to_cpu(list->radioType);
  1522. list->cap = le16_to_cpu(list->cap);
  1523. list->beaconInterval = le16_to_cpu(list->beaconInterval);
  1524. list->fh.dwell = le16_to_cpu(list->fh.dwell);
  1525. list->dsChannel = le16_to_cpu(list->dsChannel);
  1526. list->atimWindow = le16_to_cpu(list->atimWindow);
  1527. list->dBm = le16_to_cpu(list->dBm);
  1528. return rc;
  1529. }
  1530. static int readWepKeyRid(struct airo_info*ai, WepKeyRid *wkr, int temp, int lock) {
  1531. int rc = PC4500_readrid(ai, temp ? RID_WEP_TEMP : RID_WEP_PERM,
  1532. wkr, sizeof(*wkr), lock);
  1533. wkr->len = le16_to_cpu(wkr->len);
  1534. wkr->kindex = le16_to_cpu(wkr->kindex);
  1535. wkr->klen = le16_to_cpu(wkr->klen);
  1536. return rc;
  1537. }
  1538. /* In the writeXXXRid routines we copy the rids so that we don't screwup
  1539. * the originals when we endian them... */
  1540. static int writeWepKeyRid(struct airo_info*ai, WepKeyRid *pwkr, int perm, int lock) {
  1541. int rc;
  1542. WepKeyRid wkr = *pwkr;
  1543. wkr.len = cpu_to_le16(wkr.len);
  1544. wkr.kindex = cpu_to_le16(wkr.kindex);
  1545. wkr.klen = cpu_to_le16(wkr.klen);
  1546. rc = PC4500_writerid(ai, RID_WEP_TEMP, &wkr, sizeof(wkr), lock);
  1547. if (rc!=SUCCESS) printk(KERN_ERR "airo: WEP_TEMP set %x\n", rc);
  1548. if (perm) {
  1549. rc = PC4500_writerid(ai, RID_WEP_PERM, &wkr, sizeof(wkr), lock);
  1550. if (rc!=SUCCESS) {
  1551. printk(KERN_ERR "airo: WEP_PERM set %x\n", rc);
  1552. }
  1553. }
  1554. return rc;
  1555. }
  1556. static int readSsidRid(struct airo_info*ai, SsidRid *ssidr) {
  1557. int i;
  1558. int rc = PC4500_readrid(ai, RID_SSID, ssidr, sizeof(*ssidr), 1);
  1559. ssidr->len = le16_to_cpu(ssidr->len);
  1560. for(i = 0; i < 3; i++) {
  1561. ssidr->ssids[i].len = le16_to_cpu(ssidr->ssids[i].len);
  1562. }
  1563. return rc;
  1564. }
  1565. static int writeSsidRid(struct airo_info*ai, SsidRid *pssidr, int lock) {
  1566. int rc;
  1567. int i;
  1568. SsidRid ssidr = *pssidr;
  1569. ssidr.len = cpu_to_le16(ssidr.len);
  1570. for(i = 0; i < 3; i++) {
  1571. ssidr.ssids[i].len = cpu_to_le16(ssidr.ssids[i].len);
  1572. }
  1573. rc = PC4500_writerid(ai, RID_SSID, &ssidr, sizeof(ssidr), lock);
  1574. return rc;
  1575. }
  1576. static int readConfigRid(struct airo_info*ai, int lock) {
  1577. int rc;
  1578. u16 *s;
  1579. ConfigRid cfg;
  1580. if (ai->config.len)
  1581. return SUCCESS;
  1582. rc = PC4500_readrid(ai, RID_ACTUALCONFIG, &cfg, sizeof(cfg), lock);
  1583. if (rc != SUCCESS)
  1584. return rc;
  1585. for(s = &cfg.len; s <= &cfg.rtsThres; s++) *s = le16_to_cpu(*s);
  1586. for(s = &cfg.shortRetryLimit; s <= &cfg.radioType; s++)
  1587. *s = le16_to_cpu(*s);
  1588. for(s = &cfg.txPower; s <= &cfg.radioSpecific; s++)
  1589. *s = le16_to_cpu(*s);
  1590. for(s = &cfg.arlThreshold; s <= &cfg._reserved4[0]; s++)
  1591. *s = cpu_to_le16(*s);
  1592. for(s = &cfg.autoWake; s <= &cfg.autoWake; s++)
  1593. *s = cpu_to_le16(*s);
  1594. ai->config = cfg;
  1595. return SUCCESS;
  1596. }
  1597. static inline void checkThrottle(struct airo_info *ai) {
  1598. int i;
  1599. /* Old hardware had a limit on encryption speed */
  1600. if (ai->config.authType != AUTH_OPEN && maxencrypt) {
  1601. for(i=0; i<8; i++) {
  1602. if (ai->config.rates[i] > maxencrypt) {
  1603. ai->config.rates[i] = 0;
  1604. }
  1605. }
  1606. }
  1607. }
  1608. static int writeConfigRid(struct airo_info*ai, int lock) {
  1609. u16 *s;
  1610. ConfigRid cfgr;
  1611. if (!test_bit (FLAG_COMMIT, &ai->flags))
  1612. return SUCCESS;
  1613. clear_bit (FLAG_COMMIT, &ai->flags);
  1614. clear_bit (FLAG_RESET, &ai->flags);
  1615. checkThrottle(ai);
  1616. cfgr = ai->config;
  1617. if ((cfgr.opmode & 0xFF) == MODE_STA_IBSS)
  1618. set_bit(FLAG_ADHOC, &ai->flags);
  1619. else
  1620. clear_bit(FLAG_ADHOC, &ai->flags);
  1621. for(s = &cfgr.len; s <= &cfgr.rtsThres; s++) *s = cpu_to_le16(*s);
  1622. for(s = &cfgr.shortRetryLimit; s <= &cfgr.radioType; s++)
  1623. *s = cpu_to_le16(*s);
  1624. for(s = &cfgr.txPower; s <= &cfgr.radioSpecific; s++)
  1625. *s = cpu_to_le16(*s);
  1626. for(s = &cfgr.arlThreshold; s <= &cfgr._reserved4[0]; s++)
  1627. *s = cpu_to_le16(*s);
  1628. for(s = &cfgr.autoWake; s <= &cfgr.autoWake; s++)
  1629. *s = cpu_to_le16(*s);
  1630. return PC4500_writerid( ai, RID_CONFIG, &cfgr, sizeof(cfgr), lock);
  1631. }
  1632. static int readStatusRid(struct airo_info*ai, StatusRid *statr, int lock) {
  1633. int rc = PC4500_readrid(ai, RID_STATUS, statr, sizeof(*statr), lock);
  1634. u16 *s;
  1635. statr->len = le16_to_cpu(statr->len);
  1636. for(s = &statr->mode; s <= &statr->SSIDlen; s++) *s = le16_to_cpu(*s);
  1637. for(s = &statr->beaconPeriod; s <= &statr->shortPreamble; s++)
  1638. *s = le16_to_cpu(*s);
  1639. statr->load = le16_to_cpu(statr->load);
  1640. statr->assocStatus = le16_to_cpu(statr->assocStatus);
  1641. return rc;
  1642. }
  1643. static int readAPListRid(struct airo_info*ai, APListRid *aplr) {
  1644. int rc = PC4500_readrid(ai, RID_APLIST, aplr, sizeof(*aplr), 1);
  1645. aplr->len = le16_to_cpu(aplr->len);
  1646. return rc;
  1647. }
  1648. static int writeAPListRid(struct airo_info*ai, APListRid *aplr, int lock) {
  1649. int rc;
  1650. aplr->len = cpu_to_le16(aplr->len);
  1651. rc = PC4500_writerid(ai, RID_APLIST, aplr, sizeof(*aplr), lock);
  1652. return rc;
  1653. }
  1654. static int readCapabilityRid(struct airo_info*ai, CapabilityRid *capr, int lock) {
  1655. int rc = PC4500_readrid(ai, RID_CAPABILITIES, capr, sizeof(*capr), lock);
  1656. u16 *s;
  1657. capr->len = le16_to_cpu(capr->len);
  1658. capr->prodNum = le16_to_cpu(capr->prodNum);
  1659. capr->radioType = le16_to_cpu(capr->radioType);
  1660. capr->country = le16_to_cpu(capr->country);
  1661. for(s = &capr->txPowerLevels[0]; s <= &capr->requiredHard; s++)
  1662. *s = le16_to_cpu(*s);
  1663. return rc;
  1664. }
  1665. static int readStatsRid(struct airo_info*ai, StatsRid *sr, int rid, int lock) {
  1666. int rc = PC4500_readrid(ai, rid, sr, sizeof(*sr), lock);
  1667. u32 *i;
  1668. sr->len = le16_to_cpu(sr->len);
  1669. for(i = &sr->vals[0]; i <= &sr->vals[99]; i++) *i = le32_to_cpu(*i);
  1670. return rc;
  1671. }
  1672. static int airo_open(struct net_device *dev) {
  1673. struct airo_info *info = dev->priv;
  1674. Resp rsp;
  1675. if (test_bit(FLAG_FLASHING, &info->flags))
  1676. return -EIO;
  1677. /* Make sure the card is configured.
  1678. * Wireless Extensions may postpone config changes until the card
  1679. * is open (to pipeline changes and speed-up card setup). If
  1680. * those changes are not yet commited, do it now - Jean II */
  1681. if (test_bit (FLAG_COMMIT, &info->flags)) {
  1682. disable_MAC(info, 1);
  1683. writeConfigRid(info, 1);
  1684. }
  1685. if (info->wifidev != dev) {
  1686. /* Power on the MAC controller (which may have been disabled) */
  1687. clear_bit(FLAG_RADIO_DOWN, &info->flags);
  1688. enable_interrupts(info);
  1689. }
  1690. enable_MAC(info, &rsp, 1);
  1691. netif_start_queue(dev);
  1692. return 0;
  1693. }
  1694. static int mpi_start_xmit(struct sk_buff *skb, struct net_device *dev) {
  1695. int npacks, pending;
  1696. unsigned long flags;
  1697. struct airo_info *ai = dev->priv;
  1698. if (!skb) {
  1699. printk(KERN_ERR "airo: %s: skb==NULL\n",__FUNCTION__);
  1700. return 0;
  1701. }
  1702. npacks = skb_queue_len (&ai->txq);
  1703. if (npacks >= MAXTXQ - 1) {
  1704. netif_stop_queue (dev);
  1705. if (npacks > MAXTXQ) {
  1706. ai->stats.tx_fifo_errors++;
  1707. return 1;
  1708. }
  1709. skb_queue_tail (&ai->txq, skb);
  1710. return 0;
  1711. }
  1712. spin_lock_irqsave(&ai->aux_lock, flags);
  1713. skb_queue_tail (&ai->txq, skb);
  1714. pending = test_bit(FLAG_PENDING_XMIT, &ai->flags);
  1715. spin_unlock_irqrestore(&ai->aux_lock,flags);
  1716. netif_wake_queue (dev);
  1717. if (pending == 0) {
  1718. set_bit(FLAG_PENDING_XMIT, &ai->flags);
  1719. mpi_send_packet (dev);
  1720. }
  1721. return 0;
  1722. }
  1723. /*
  1724. * @mpi_send_packet
  1725. *
  1726. * Attempt to transmit a packet. Can be called from interrupt
  1727. * or transmit . return number of packets we tried to send
  1728. */
  1729. static int mpi_send_packet (struct net_device *dev)
  1730. {
  1731. struct sk_buff *skb;
  1732. unsigned char *buffer;
  1733. s16 len, *payloadLen;
  1734. struct airo_info *ai = dev->priv;
  1735. u8 *sendbuf;
  1736. /* get a packet to send */
  1737. if ((skb = skb_dequeue(&ai->txq)) == 0) {
  1738. printk (KERN_ERR
  1739. "airo: %s: Dequeue'd zero in send_packet()\n",
  1740. __FUNCTION__);
  1741. return 0;
  1742. }
  1743. /* check min length*/
  1744. len = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN;
  1745. buffer = skb->data;
  1746. ai->txfids[0].tx_desc.offset = 0;
  1747. ai->txfids[0].tx_desc.valid = 1;
  1748. ai->txfids[0].tx_desc.eoc = 1;
  1749. ai->txfids[0].tx_desc.len =len+sizeof(WifiHdr);
  1750. /*
  1751. * Magic, the cards firmware needs a length count (2 bytes) in the host buffer
  1752. * right after TXFID_HDR.The TXFID_HDR contains the status short so payloadlen
  1753. * is immediatly after it. ------------------------------------------------
  1754. * |TXFIDHDR+STATUS|PAYLOADLEN|802.3HDR|PACKETDATA|
  1755. * ------------------------------------------------
  1756. */
  1757. memcpy((char *)ai->txfids[0].virtual_host_addr,
  1758. (char *)&wifictlhdr8023, sizeof(wifictlhdr8023));
  1759. payloadLen = (s16 *)(ai->txfids[0].virtual_host_addr +
  1760. sizeof(wifictlhdr8023));
  1761. sendbuf = ai->txfids[0].virtual_host_addr +
  1762. sizeof(wifictlhdr8023) + 2 ;
  1763. /*
  1764. * Firmware automaticly puts 802 header on so
  1765. * we don't need to account for it in the length
  1766. */
  1767. #ifdef MICSUPPORT
  1768. if (test_bit(FLAG_MIC_CAPABLE, &ai->flags) && ai->micstats.enabled &&
  1769. (ntohs(((u16 *)buffer)[6]) != 0x888E)) {
  1770. MICBuffer pMic;
  1771. if (encapsulate(ai, (etherHead *)buffer, &pMic, len - sizeof(etherHead)) != SUCCESS)
  1772. return ERROR;
  1773. *payloadLen = cpu_to_le16(len-sizeof(etherHead)+sizeof(pMic));
  1774. ai->txfids[0].tx_desc.len += sizeof(pMic);
  1775. /* copy data into airo dma buffer */
  1776. memcpy (sendbuf, buffer, sizeof(etherHead));
  1777. buffer += sizeof(etherHead);
  1778. sendbuf += sizeof(etherHead);
  1779. memcpy (sendbuf, &pMic, sizeof(pMic));
  1780. sendbuf += sizeof(pMic);
  1781. memcpy (sendbuf, buffer, len - sizeof(etherHead));
  1782. } else
  1783. #endif
  1784. {
  1785. *payloadLen = cpu_to_le16(len - sizeof(etherHead));
  1786. dev->trans_start = jiffies;
  1787. /* copy data into airo dma buffer */
  1788. memcpy(sendbuf, buffer, len);
  1789. }
  1790. memcpy_toio(ai->txfids[0].card_ram_off,
  1791. &ai->txfids[0].tx_desc, sizeof(TxFid));
  1792. OUT4500(ai, EVACK, 8);
  1793. dev_kfree_skb_any(skb);
  1794. return 1;
  1795. }
  1796. static void get_tx_error(struct airo_info *ai, s32 fid)
  1797. {
  1798. u16 status;
  1799. if (fid < 0)
  1800. status = ((WifiCtlHdr *)ai->txfids[0].virtual_host_addr)->ctlhdr.status;
  1801. else {
  1802. if (bap_setup(ai, ai->fids[fid] & 0xffff, 4, BAP0) != SUCCESS)
  1803. return;
  1804. bap_read(ai, &status, 2, BAP0);
  1805. }
  1806. if (le16_to_cpu(status) & 2) /* Too many retries */
  1807. ai->stats.tx_aborted_errors++;
  1808. if (le16_to_cpu(status) & 4) /* Transmit lifetime exceeded */
  1809. ai->stats.tx_heartbeat_errors++;
  1810. if (le16_to_cpu(status) & 8) /* Aid fail */
  1811. { }
  1812. if (le16_to_cpu(status) & 0x10) /* MAC disabled */
  1813. ai->stats.tx_carrier_errors++;
  1814. if (le16_to_cpu(status) & 0x20) /* Association lost */
  1815. { }
  1816. /* We produce a TXDROP event only for retry or lifetime
  1817. * exceeded, because that's the only status that really mean
  1818. * that this particular node went away.
  1819. * Other errors means that *we* screwed up. - Jean II */
  1820. if ((le16_to_cpu(status) & 2) ||
  1821. (le16_to_cpu(status) & 4)) {
  1822. union iwreq_data wrqu;
  1823. char junk[0x18];
  1824. /* Faster to skip over useless data than to do
  1825. * another bap_setup(). We are at offset 0x6 and
  1826. * need to go to 0x18 and read 6 bytes - Jean II */
  1827. bap_read(ai, (u16 *) junk, 0x18, BAP0);
  1828. /* Copy 802.11 dest address.
  1829. * We use the 802.11 header because the frame may
  1830. * not be 802.3 or may be mangled...
  1831. * In Ad-Hoc mode, it will be the node address.
  1832. * In managed mode, it will be most likely the AP addr
  1833. * User space will figure out how to convert it to
  1834. * whatever it needs (IP address or else).
  1835. * - Jean II */
  1836. memcpy(wrqu.addr.sa_data, junk + 0x12, ETH_ALEN);
  1837. wrqu.addr.sa_family = ARPHRD_ETHER;
  1838. /* Send event to user space */
  1839. wireless_send_event(ai->dev, IWEVTXDROP, &wrqu, NULL);
  1840. }
  1841. }
  1842. static void airo_end_xmit(struct net_device *dev) {
  1843. u16 status;
  1844. int i;
  1845. struct airo_info *priv = dev->priv;
  1846. struct sk_buff *skb = priv->xmit.skb;
  1847. int fid = priv->xmit.fid;
  1848. u32 *fids = priv->fids;
  1849. clear_bit(JOB_XMIT, &priv->flags);
  1850. clear_bit(FLAG_PENDING_XMIT, &priv->flags);
  1851. status = transmit_802_3_packet (priv, fids[fid], skb->data);
  1852. up(&priv->sem);
  1853. i = 0;
  1854. if ( status == SUCCESS ) {
  1855. dev->trans_start = jiffies;
  1856. for (; i < MAX_FIDS / 2 && (priv->fids[i] & 0xffff0000); i++);
  1857. } else {
  1858. priv->fids[fid] &= 0xffff;
  1859. priv->stats.tx_window_errors++;
  1860. }
  1861. if (i < MAX_FIDS / 2)
  1862. netif_wake_queue(dev);
  1863. dev_kfree_skb(skb);
  1864. }
  1865. static int airo_start_xmit(struct sk_buff *skb, struct net_device *dev) {
  1866. s16 len;
  1867. int i, j;
  1868. struct airo_info *priv = dev->priv;
  1869. u32 *fids = priv->fids;
  1870. if ( skb == NULL ) {
  1871. printk( KERN_ERR "airo: skb == NULL!!!\n" );
  1872. return 0;
  1873. }
  1874. /* Find a vacant FID */
  1875. for( i = 0; i < MAX_FIDS / 2 && (fids[i] & 0xffff0000); i++ );
  1876. for( j = i + 1; j < MAX_FIDS / 2 && (fids[j] & 0xffff0000); j++ );
  1877. if ( j >= MAX_FIDS / 2 ) {
  1878. netif_stop_queue(dev);
  1879. if (i == MAX_FIDS / 2) {
  1880. priv->stats.tx_fifo_errors++;
  1881. return 1;
  1882. }
  1883. }
  1884. /* check min length*/
  1885. len = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN;
  1886. /* Mark fid as used & save length for later */
  1887. fids[i] |= (len << 16);
  1888. priv->xmit.skb = skb;
  1889. priv->xmit.fid = i;
  1890. if (down_trylock(&priv->sem) != 0) {
  1891. set_bit(FLAG_PENDING_XMIT, &priv->flags);
  1892. netif_stop_queue(dev);
  1893. set_bit(JOB_XMIT, &priv->flags);
  1894. wake_up_interruptible(&priv->thr_wait);
  1895. } else
  1896. airo_end_xmit(dev);
  1897. return 0;
  1898. }
  1899. static void airo_end_xmit11(struct net_device *dev) {
  1900. u16 status;
  1901. int i;
  1902. struct airo_info *priv = dev->priv;
  1903. struct sk_buff *skb = priv->xmit11.skb;
  1904. int fid = priv->xmit11.fid;
  1905. u32 *fids = priv->fids;
  1906. clear_bit(JOB_XMIT11, &priv->flags);
  1907. clear_bit(FLAG_PENDING_XMIT11, &priv->flags);
  1908. status = transmit_802_11_packet (priv, fids[fid], skb->data);
  1909. up(&priv->sem);
  1910. i = MAX_FIDS / 2;
  1911. if ( status == SUCCESS ) {
  1912. dev->trans_start = jiffies;
  1913. for (; i < MAX_FIDS && (priv->fids[i] & 0xffff0000); i++);
  1914. } else {
  1915. priv->fids[fid] &= 0xffff;
  1916. priv->stats.tx_window_errors++;
  1917. }
  1918. if (i < MAX_FIDS)
  1919. netif_wake_queue(dev);
  1920. dev_kfree_skb(skb);
  1921. }
  1922. static int airo_start_xmit11(struct sk_buff *skb, struct net_device *dev) {
  1923. s16 len;
  1924. int i, j;
  1925. struct airo_info *priv = dev->priv;
  1926. u32 *fids = priv->fids;
  1927. if (test_bit(FLAG_MPI, &priv->flags)) {
  1928. /* Not implemented yet for MPI350 */
  1929. netif_stop_queue(dev);
  1930. return -ENETDOWN;
  1931. }
  1932. if ( skb == NULL ) {
  1933. printk( KERN_ERR "airo: skb == NULL!!!\n" );
  1934. return 0;
  1935. }
  1936. /* Find a vacant FID */
  1937. for( i = MAX_FIDS / 2; i < MAX_FIDS && (fids[i] & 0xffff0000); i++ );
  1938. for( j = i + 1; j < MAX_FIDS && (fids[j] & 0xffff0000); j++ );
  1939. if ( j >= MAX_FIDS ) {
  1940. netif_stop_queue(dev);
  1941. if (i == MAX_FIDS) {
  1942. priv->stats.tx_fifo_errors++;
  1943. return 1;
  1944. }
  1945. }
  1946. /* check min length*/
  1947. len = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN;
  1948. /* Mark fid as used & save length for later */
  1949. fids[i] |= (len << 16);
  1950. priv->xmit11.skb = skb;
  1951. priv->xmit11.fid = i;
  1952. if (down_trylock(&priv->sem) != 0) {
  1953. set_bit(FLAG_PENDING_XMIT11, &priv->flags);
  1954. netif_stop_queue(dev);
  1955. set_bit(JOB_XMIT11, &priv->flags);
  1956. wake_up_interruptible(&priv->thr_wait);
  1957. } else
  1958. airo_end_xmit11(dev);
  1959. return 0;
  1960. }
  1961. static void airo_read_stats(struct airo_info *ai) {
  1962. StatsRid stats_rid;
  1963. u32 *vals = stats_rid.vals;
  1964. clear_bit(JOB_STATS, &ai->flags);
  1965. if (ai->power.event) {
  1966. up(&ai->sem);
  1967. return;
  1968. }
  1969. readStatsRid(ai, &stats_rid, RID_STATS, 0);
  1970. up(&ai->sem);
  1971. ai->stats.rx_packets = vals[43] + vals[44] + vals[45];
  1972. ai->stats.tx_packets = vals[39] + vals[40] + vals[41];
  1973. ai->stats.rx_bytes = vals[92];
  1974. ai->stats.tx_bytes = vals[91];
  1975. ai->stats.rx_errors = vals[0] + vals[2] + vals[3] + vals[4];
  1976. ai->stats.tx_errors = vals[42] + ai->stats.tx_fifo_errors;
  1977. ai->stats.multicast = vals[43];
  1978. ai->stats.collisions = vals[89];
  1979. /* detailed rx_errors: */
  1980. ai->stats.rx_length_errors = vals[3];
  1981. ai->stats.rx_crc_errors = vals[4];
  1982. ai->stats.rx_frame_errors = vals[2];
  1983. ai->stats.rx_fifo_errors = vals[0];
  1984. }
  1985. static struct net_device_stats *airo_get_stats(struct net_device *dev)
  1986. {
  1987. struct airo_info *local = dev->priv;
  1988. if (!test_bit(JOB_STATS, &local->flags)) {
  1989. /* Get stats out of the card if available */
  1990. if (down_trylock(&local->sem) != 0) {
  1991. set_bit(JOB_STATS, &local->flags);
  1992. wake_up_interruptible(&local->thr_wait);
  1993. } else
  1994. airo_read_stats(local);
  1995. }
  1996. return &local->stats;
  1997. }
  1998. static void airo_set_promisc(struct airo_info *ai) {
  1999. Cmd cmd;
  2000. Resp rsp;
  2001. memset(&cmd, 0, sizeof(cmd));
  2002. cmd.cmd=CMD_SETMODE;
  2003. clear_bit(JOB_PROMISC, &ai->flags);
  2004. cmd.parm0=(ai->flags&IFF_PROMISC) ? PROMISC : NOPROMISC;
  2005. issuecommand(ai, &cmd, &rsp);
  2006. up(&ai->sem);
  2007. }
  2008. static void airo_set_multicast_list(struct net_device *dev) {
  2009. struct airo_info *ai = dev->priv;
  2010. if ((dev->flags ^ ai->flags) & IFF_PROMISC) {
  2011. change_bit(FLAG_PROMISC, &ai->flags);
  2012. if (down_trylock(&ai->sem) != 0) {
  2013. set_bit(JOB_PROMISC, &ai->flags);
  2014. wake_up_interruptible(&ai->thr_wait);
  2015. } else
  2016. airo_set_promisc(ai);
  2017. }
  2018. if ((dev->flags&IFF_ALLMULTI)||dev->mc_count>0) {
  2019. /* Turn on multicast. (Should be already setup...) */
  2020. }
  2021. }
  2022. static int airo_set_mac_address(struct net_device *dev, void *p)
  2023. {
  2024. struct airo_info *ai = dev->priv;
  2025. struct sockaddr *addr = p;
  2026. Resp rsp;
  2027. readConfigRid(ai, 1);
  2028. memcpy (ai->config.macAddr, addr->sa_data, dev->addr_len);
  2029. set_bit (FLAG_COMMIT, &ai->flags);
  2030. disable_MAC(ai, 1);
  2031. writeConfigRid (ai, 1);
  2032. enable_MAC(ai, &rsp, 1);
  2033. memcpy (ai->dev->dev_addr, addr->sa_data, dev->addr_len);
  2034. if (ai->wifidev)
  2035. memcpy (ai->wifidev->dev_addr, addr->sa_data, dev->addr_len);
  2036. return 0;
  2037. }
  2038. static int airo_change_mtu(struct net_device *dev, int new_mtu)
  2039. {
  2040. if ((new_mtu < 68) || (new_mtu > 2400))
  2041. return -EINVAL;
  2042. dev->mtu = new_mtu;
  2043. return 0;
  2044. }
  2045. static int airo_close(struct net_device *dev) {
  2046. struct airo_info *ai = dev->priv;
  2047. netif_stop_queue(dev);
  2048. if (ai->wifidev != dev) {
  2049. #ifdef POWER_ON_DOWN
  2050. /* Shut power to the card. The idea is that the user can save
  2051. * power when he doesn't need the card with "ifconfig down".
  2052. * That's the method that is most friendly towards the network
  2053. * stack (i.e. the network stack won't try to broadcast
  2054. * anything on the interface and routes are gone. Jean II */
  2055. set_bit(FLAG_RADIO_DOWN, &ai->flags);
  2056. disable_MAC(ai, 1);
  2057. #endif
  2058. disable_interrupts( ai );
  2059. }
  2060. return 0;
  2061. }
  2062. static void del_airo_dev( struct net_device *dev );
  2063. void stop_airo_card( struct net_device *dev, int freeres )
  2064. {
  2065. struct airo_info *ai = dev->priv;
  2066. set_bit(FLAG_RADIO_DOWN, &ai->flags);
  2067. disable_MAC(ai, 1);
  2068. disable_interrupts(ai);
  2069. free_irq( dev->irq, dev );
  2070. takedown_proc_entry( dev, ai );
  2071. if (test_bit(FLAG_REGISTERED, &ai->flags)) {
  2072. unregister_netdev( dev );
  2073. if (ai->wifidev) {
  2074. unregister_netdev(ai->wifidev);
  2075. free_netdev(ai->wifidev);
  2076. ai->wifidev = NULL;
  2077. }
  2078. clear_bit(FLAG_REGISTERED, &ai->flags);
  2079. }
  2080. set_bit(JOB_DIE, &ai->flags);
  2081. kill_proc(ai->thr_pid, SIGTERM, 1);
  2082. wait_for_completion(&ai->thr_exited);
  2083. /*
  2084. * Clean out tx queue
  2085. */
  2086. if (test_bit(FLAG_MPI, &ai->flags) && !skb_queue_empty(&ai->txq)) {
  2087. struct sk_buff *skb = NULL;
  2088. for (;(skb = skb_dequeue(&ai->txq));)
  2089. dev_kfree_skb(skb);
  2090. }
  2091. kfree(ai->flash);
  2092. kfree(ai->rssi);
  2093. kfree(ai->APList);
  2094. kfree(ai->SSID);
  2095. if (freeres) {
  2096. /* PCMCIA frees this stuff, so only for PCI and ISA */
  2097. release_region( dev->base_addr, 64 );
  2098. if (test_bit(FLAG_MPI, &ai->flags)) {
  2099. if (ai->pci)
  2100. mpi_unmap_card(ai->pci);
  2101. if (ai->pcimem)
  2102. iounmap(ai->pcimem);
  2103. if (ai->pciaux)
  2104. iounmap(ai->pciaux);
  2105. pci_free_consistent(ai->pci, PCI_SHARED_LEN,
  2106. ai->shared, ai->shared_dma);
  2107. }
  2108. }
  2109. #ifdef MICSUPPORT
  2110. crypto_free_tfm(ai->tfm);
  2111. #endif
  2112. del_airo_dev( dev );
  2113. free_netdev( dev );
  2114. }
  2115. EXPORT_SYMBOL(stop_airo_card);
  2116. static int add_airo_dev( struct net_device *dev );
  2117. static int wll_header_parse(struct sk_buff *skb, unsigned char *haddr)
  2118. {
  2119. memcpy(haddr, skb->mac.raw + 10, ETH_ALEN);
  2120. return ETH_ALEN;
  2121. }
  2122. static void mpi_unmap_card(struct pci_dev *pci)
  2123. {
  2124. unsigned long mem_start = pci_resource_start(pci, 1);
  2125. unsigned long mem_len = pci_resource_len(pci, 1);
  2126. unsigned long aux_start = pci_resource_start(pci, 2);
  2127. unsigned long aux_len = AUXMEMSIZE;
  2128. release_mem_region(aux_start, aux_len);
  2129. release_mem_region(mem_start, mem_len);
  2130. }
  2131. /*************************************************************
  2132. * This routine assumes that descriptors have been setup .
  2133. * Run at insmod time or after reset when the decriptors
  2134. * have been initialized . Returns 0 if all is well nz
  2135. * otherwise . Does not allocate memory but sets up card
  2136. * using previously allocated descriptors.
  2137. */
  2138. static int mpi_init_descriptors (struct airo_info *ai)
  2139. {
  2140. Cmd cmd;
  2141. Resp rsp;
  2142. int i;
  2143. int rc = SUCCESS;
  2144. /* Alloc card RX descriptors */
  2145. netif_stop_queue(ai->dev);
  2146. memset(&rsp,0,sizeof(rsp));
  2147. memset(&cmd,0,sizeof(cmd));
  2148. cmd.cmd = CMD_ALLOCATEAUX;
  2149. cmd.parm0 = FID_RX;
  2150. cmd.parm1 = (ai->rxfids[0].card_ram_off - ai->pciaux);
  2151. cmd.parm2 = MPI_MAX_FIDS;
  2152. rc=issuecommand(ai, &cmd, &rsp);
  2153. if (rc != SUCCESS) {
  2154. printk(KERN_ERR "airo: Couldn't allocate RX FID\n");
  2155. return rc;
  2156. }
  2157. for (i=0; i<MPI_MAX_FIDS; i++) {
  2158. memcpy_toio(ai->rxfids[i].card_ram_off,
  2159. &ai->rxfids[i].rx_desc, sizeof(RxFid));
  2160. }
  2161. /* Alloc card TX descriptors */
  2162. memset(&rsp,0,sizeof(rsp));
  2163. memset(&cmd,0,sizeof(cmd));
  2164. cmd.cmd = CMD_ALLOCATEAUX;
  2165. cmd.parm0 = FID_TX;
  2166. cmd.parm1 = (ai->txfids[0].card_ram_off - ai->pciaux);
  2167. cmd.parm2 = MPI_MAX_FIDS;
  2168. for (i=0; i<MPI_MAX_FIDS; i++) {
  2169. ai->txfids[i].tx_desc.valid = 1;
  2170. memcpy_toio(ai->txfids[i].card_ram_off,
  2171. &ai->txfids[i].tx_desc, sizeof(TxFid));
  2172. }
  2173. ai->txfids[i-1].tx_desc.eoc = 1; /* Last descriptor has EOC set */
  2174. rc=issuecommand(ai, &cmd, &rsp);
  2175. if (rc != SUCCESS) {
  2176. printk(KERN_ERR "airo: Couldn't allocate TX FID\n");
  2177. return rc;
  2178. }
  2179. /* Alloc card Rid descriptor */
  2180. memset(&rsp,0,sizeof(rsp));
  2181. memset(&cmd,0,sizeof(cmd));
  2182. cmd.cmd = CMD_ALLOCATEAUX;
  2183. cmd.parm0 = RID_RW;
  2184. cmd.parm1 = (ai->config_desc.card_ram_off - ai->pciaux);
  2185. cmd.parm2 = 1; /* Magic number... */
  2186. rc=issuecommand(ai, &cmd, &rsp);
  2187. if (rc != SUCCESS) {
  2188. printk(KERN_ERR "airo: Couldn't allocate RID\n");
  2189. return rc;
  2190. }
  2191. memcpy_toio(ai->config_desc.card_ram_off,
  2192. &ai->config_desc.rid_desc, sizeof(Rid));
  2193. return rc;
  2194. }
  2195. /*
  2196. * We are setting up three things here:
  2197. * 1) Map AUX memory for descriptors: Rid, TxFid, or RxFid.
  2198. * 2) Map PCI memory for issueing commands.
  2199. * 3) Allocate memory (shared) to send and receive ethernet frames.
  2200. */
  2201. static int mpi_map_card(struct airo_info *ai, struct pci_dev *pci,
  2202. const char *name)
  2203. {
  2204. unsigned long mem_start, mem_len, aux_start, aux_len;
  2205. int rc = -1;
  2206. int i;
  2207. dma_addr_t busaddroff;
  2208. unsigned char *vpackoff;
  2209. unsigned char __iomem *pciaddroff;
  2210. mem_start = pci_resource_start(pci, 1);
  2211. mem_len = pci_resource_len(pci, 1);
  2212. aux_start = pci_resource_start(pci, 2);
  2213. aux_len = AUXMEMSIZE;
  2214. if (!request_mem_region(mem_start, mem_len, name)) {
  2215. printk(KERN_ERR "airo: Couldn't get region %x[%x] for %s\n",
  2216. (int)mem_start, (int)mem_len, name);
  2217. goto out;
  2218. }
  2219. if (!request_mem_region(aux_start, aux_len, name)) {
  2220. printk(KERN_ERR "airo: Couldn't get region %x[%x] for %s\n",
  2221. (int)aux_start, (int)aux_len, name);
  2222. goto free_region1;
  2223. }
  2224. ai->pcimem = ioremap(mem_start, mem_len);
  2225. if (!ai->pcimem) {
  2226. printk(KERN_ERR "airo: Couldn't map region %x[%x] for %s\n",
  2227. (int)mem_start, (int)mem_len, name);
  2228. goto free_region2;
  2229. }
  2230. ai->pciaux = ioremap(aux_start, aux_len);
  2231. if (!ai->pciaux) {
  2232. printk(KERN_ERR "airo: Couldn't map region %x[%x] for %s\n",
  2233. (int)aux_start, (int)aux_len, name);
  2234. goto free_memmap;
  2235. }
  2236. /* Reserve PKTSIZE for each fid and 2K for the Rids */
  2237. ai->shared = pci_alloc_consistent(pci, PCI_SHARED_LEN, &ai->shared_dma);
  2238. if (!ai->shared) {
  2239. printk(KERN_ERR "airo: Couldn't alloc_consistent %d\n",
  2240. PCI_SHARED_LEN);
  2241. goto free_auxmap;
  2242. }
  2243. /*
  2244. * Setup descriptor RX, TX, CONFIG
  2245. */
  2246. busaddroff = ai->shared_dma;
  2247. pciaddroff = ai->pciaux + AUX_OFFSET;
  2248. vpackoff = ai->shared;
  2249. /* RX descriptor setup */
  2250. for(i = 0; i < MPI_MAX_FIDS; i++) {
  2251. ai->rxfids[i].pending = 0;
  2252. ai->rxfids[i].card_ram_off = pciaddroff;
  2253. ai->rxfids[i].virtual_host_addr = vpackoff;
  2254. ai->rxfids[i].rx_desc.host_addr = busaddroff;
  2255. ai->rxfids[i].rx_desc.valid = 1;
  2256. ai->rxfids[i].rx_desc.len = PKTSIZE;
  2257. ai->rxfids[i].rx_desc.rdy = 0;
  2258. pciaddroff += sizeof(RxFid);
  2259. busaddroff += PKTSIZE;
  2260. vpackoff += PKTSIZE;
  2261. }
  2262. /* TX descriptor setup */
  2263. for(i = 0; i < MPI_MAX_FIDS; i++) {
  2264. ai->txfids[i].card_ram_off = pciaddroff;
  2265. ai->txfids[i].virtual_host_addr = vpackoff;
  2266. ai->txfids[i].tx_desc.valid = 1;
  2267. ai->txfids[i].tx_desc.host_addr = busaddroff;
  2268. memcpy(ai->txfids[i].virtual_host_addr,
  2269. &wifictlhdr8023, sizeof(wifictlhdr8023));
  2270. pciaddroff += sizeof(TxFid);
  2271. busaddroff += PKTSIZE;
  2272. vpackoff += PKTSIZE;
  2273. }
  2274. ai->txfids[i-1].tx_desc.eoc = 1; /* Last descriptor has EOC set */
  2275. /* Rid descriptor setup */
  2276. ai->config_desc.card_ram_off = pciaddroff;
  2277. ai->config_desc.virtual_host_addr = vpackoff;
  2278. ai->config_desc.rid_desc.host_addr = busaddroff;
  2279. ai->ridbus = busaddroff;
  2280. ai->config_desc.rid_desc.rid = 0;
  2281. ai->config_desc.rid_desc.len = RIDSIZE;
  2282. ai->config_desc.rid_desc.valid = 1;
  2283. pciaddroff += sizeof(Rid);
  2284. busaddroff += RIDSIZE;
  2285. vpackoff += RIDSIZE;
  2286. /* Tell card about descriptors */
  2287. if (mpi_init_descriptors (ai) != SUCCESS)
  2288. goto free_shared;
  2289. return 0;
  2290. free_shared:
  2291. pci_free_consistent(pci, PCI_SHARED_LEN, ai->shared, ai->shared_dma);
  2292. free_auxmap:
  2293. iounmap(ai->pciaux);
  2294. free_memmap:
  2295. iounmap(ai->pcimem);
  2296. free_region2:
  2297. release_mem_region(aux_start, aux_len);
  2298. free_region1:
  2299. release_mem_region(mem_start, mem_len);
  2300. out:
  2301. return rc;
  2302. }
  2303. static void wifi_setup(struct net_device *dev)
  2304. {
  2305. dev->hard_header = NULL;
  2306. dev->rebuild_header = NULL;
  2307. dev->hard_header_cache = NULL;
  2308. dev->header_cache_update= NULL;
  2309. dev->hard_header_parse = wll_header_parse;
  2310. dev->hard_start_xmit = &airo_start_xmit11;
  2311. dev->get_stats = &airo_get_stats;
  2312. dev->set_mac_address = &airo_set_mac_address;
  2313. dev->do_ioctl = &airo_ioctl;
  2314. dev->wireless_handlers = &airo_handler_def;
  2315. dev->change_mtu = &airo_change_mtu;
  2316. dev->open = &airo_open;
  2317. dev->stop = &airo_close;
  2318. dev->type = ARPHRD_IEEE80211;
  2319. dev->hard_header_len = ETH_HLEN;
  2320. dev->mtu = 2312;
  2321. dev->addr_len = ETH_ALEN;
  2322. dev->tx_queue_len = 100;
  2323. memset(dev->broadcast,0xFF, ETH_ALEN);
  2324. dev->flags = IFF_BROADCAST|IFF_MULTICAST;
  2325. }
  2326. static struct net_device *init_wifidev(struct airo_info *ai,
  2327. struct net_device *ethdev)
  2328. {
  2329. int err;
  2330. struct net_device *dev = alloc_netdev(0, "wifi%d", wifi_setup);
  2331. if (!dev)
  2332. return NULL;
  2333. dev->priv = ethdev->priv;
  2334. dev->irq = ethdev->irq;
  2335. dev->base_addr = ethdev->base_addr;
  2336. dev->wireless_data = ethdev->wireless_data;
  2337. memcpy(dev->dev_addr, ethdev->dev_addr, dev->addr_len);
  2338. err = register_netdev(dev);
  2339. if (err<0) {
  2340. free_netdev(dev);
  2341. return NULL;
  2342. }
  2343. return dev;
  2344. }
  2345. static int reset_card( struct net_device *dev , int lock) {
  2346. struct airo_info *ai = dev->priv;
  2347. if (lock && down_interruptible(&ai->sem))
  2348. return -1;
  2349. waitbusy (ai);
  2350. OUT4500(ai,COMMAND,CMD_SOFTRESET);
  2351. msleep(200);
  2352. waitbusy (ai);
  2353. msleep(200);
  2354. if (lock)
  2355. up(&ai->sem);
  2356. return 0;
  2357. }
  2358. static struct net_device *_init_airo_card( unsigned short irq, int port,
  2359. int is_pcmcia, struct pci_dev *pci,
  2360. struct device *dmdev )
  2361. {
  2362. struct net_device *dev;
  2363. struct airo_info *ai;
  2364. int i, rc;
  2365. /* Create the network device object. */
  2366. dev = alloc_etherdev(sizeof(*ai));
  2367. if (!dev) {
  2368. printk(KERN_ERR "airo: Couldn't alloc_etherdev\n");
  2369. return NULL;
  2370. }
  2371. if (dev_alloc_name(dev, dev->name) < 0) {
  2372. printk(KERN_ERR "airo: Couldn't get name!\n");
  2373. goto err_out_free;
  2374. }
  2375. ai = dev->priv;
  2376. ai->wifidev = NULL;
  2377. ai->flags = 0;
  2378. if (pci && (pci->device == 0x5000 || pci->device == 0xa504)) {
  2379. printk(KERN_DEBUG "airo: Found an MPI350 card\n");
  2380. set_bit(FLAG_MPI, &ai->flags);
  2381. }
  2382. ai->dev = dev;
  2383. spin_lock_init(&ai->aux_lock);
  2384. sema_init(&ai->sem, 1);
  2385. ai->config.len = 0;
  2386. ai->pci = pci;
  2387. init_waitqueue_head (&ai->thr_wait);
  2388. init_completion (&ai->thr_exited);
  2389. ai->thr_pid = kernel_thread(airo_thread, dev, CLONE_FS | CLONE_FILES);
  2390. if (ai->thr_pid < 0)
  2391. goto err_out_free;
  2392. #ifdef MICSUPPORT
  2393. ai->tfm = NULL;
  2394. #endif
  2395. rc = add_airo_dev( dev );
  2396. if (rc)
  2397. goto err_out_thr;
  2398. /* The Airo-specific entries in the device structure. */
  2399. if (test_bit(FLAG_MPI,&ai->flags)) {
  2400. skb_queue_head_init (&ai->txq);
  2401. dev->hard_start_xmit = &mpi_start_xmit;
  2402. } else
  2403. dev->hard_start_xmit = &airo_start_xmit;
  2404. dev->get_stats = &airo_get_stats;
  2405. dev->set_multicast_list = &airo_set_multicast_list;
  2406. dev->set_mac_address = &airo_set_mac_address;
  2407. dev->do_ioctl = &airo_ioctl;
  2408. dev->wireless_handlers = &airo_handler_def;
  2409. ai->wireless_data.spy_data = &ai->spy_data;
  2410. dev->wireless_data = &ai->wireless_data;
  2411. dev->change_mtu = &airo_change_mtu;
  2412. dev->open = &airo_open;
  2413. dev->stop = &airo_close;
  2414. dev->irq = irq;
  2415. dev->base_addr = port;
  2416. SET_NETDEV_DEV(dev, dmdev);
  2417. if (test_bit(FLAG_MPI,&ai->flags))
  2418. reset_card (dev, 1);
  2419. rc = request_irq( dev->irq, airo_interrupt, SA_SHIRQ, dev->name, dev );
  2420. if (rc) {
  2421. printk(KERN_ERR "airo: register interrupt %d failed, rc %d\n", irq, rc );
  2422. goto err_out_unlink;
  2423. }
  2424. if (!is_pcmcia) {
  2425. if (!request_region( dev->base_addr, 64, dev->name )) {
  2426. rc = -EBUSY;
  2427. printk(KERN_ERR "airo: Couldn't request region\n");
  2428. goto err_out_irq;
  2429. }
  2430. }
  2431. if (test_bit(FLAG_MPI,&ai->flags)) {
  2432. if (mpi_map_card(ai, pci, dev->name)) {
  2433. printk(KERN_ERR "airo: Could not map memory\n");
  2434. goto err_out_res;
  2435. }
  2436. }
  2437. if (probe) {
  2438. if ( setup_card( ai, dev->dev_addr, 1 ) != SUCCESS ) {
  2439. printk( KERN_ERR "airo: MAC could not be enabled\n" );
  2440. rc = -EIO;
  2441. goto err_out_map;
  2442. }
  2443. } else if (!test_bit(FLAG_MPI,&ai->flags)) {
  2444. ai->bap_read = fast_bap_read;
  2445. set_bit(FLAG_FLASHING, &ai->flags);
  2446. }
  2447. rc = register_netdev(dev);
  2448. if (rc) {
  2449. printk(KERN_ERR "airo: Couldn't register_netdev\n");
  2450. goto err_out_map;
  2451. }
  2452. ai->wifidev = init_wifidev(ai, dev);
  2453. set_bit(FLAG_REGISTERED,&ai->flags);
  2454. printk( KERN_INFO "airo: MAC enabled %s %x:%x:%x:%x:%x:%x\n",
  2455. dev->name,
  2456. dev->dev_addr[0], dev->dev_addr[1], dev->dev_addr[2],
  2457. dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5] );
  2458. /* Allocate the transmit buffers */
  2459. if (probe && !test_bit(FLAG_MPI,&ai->flags))
  2460. for( i = 0; i < MAX_FIDS; i++ )
  2461. ai->fids[i] = transmit_allocate(ai,2312,i>=MAX_FIDS/2);
  2462. setup_proc_entry( dev, dev->priv ); /* XXX check for failure */
  2463. netif_start_queue(dev);
  2464. SET_MODULE_OWNER(dev);
  2465. return dev;
  2466. err_out_map:
  2467. if (test_bit(FLAG_MPI,&ai->flags) && pci) {
  2468. pci_free_consistent(pci, PCI_SHARED_LEN, ai->shared, ai->shared_dma);
  2469. iounmap(ai->pciaux);
  2470. iounmap(ai->pcimem);
  2471. mpi_unmap_card(ai->pci);
  2472. }
  2473. err_out_res:
  2474. if (!is_pcmcia)
  2475. release_region( dev->base_addr, 64 );
  2476. err_out_irq:
  2477. free_irq(dev->irq, dev);
  2478. err_out_unlink:
  2479. del_airo_dev(dev);
  2480. err_out_thr:
  2481. set_bit(JOB_DIE, &ai->flags);
  2482. kill_proc(ai->thr_pid, SIGTERM, 1);
  2483. wait_for_completion(&ai->thr_exited);
  2484. err_out_free:
  2485. free_netdev(dev);
  2486. return NULL;
  2487. }
  2488. struct net_device *init_airo_card( unsigned short irq, int port, int is_pcmcia,
  2489. struct device *dmdev)
  2490. {
  2491. return _init_airo_card ( irq, port, is_pcmcia, NULL, dmdev);
  2492. }
  2493. EXPORT_SYMBOL(init_airo_card);
  2494. static int waitbusy (struct airo_info *ai) {
  2495. int delay = 0;
  2496. while ((IN4500 (ai, COMMAND) & COMMAND_BUSY) & (delay < 10000)) {
  2497. udelay (10);
  2498. if ((++delay % 20) == 0)
  2499. OUT4500(ai, EVACK, EV_CLEARCOMMANDBUSY);
  2500. }
  2501. return delay < 10000;
  2502. }
  2503. int reset_airo_card( struct net_device *dev )
  2504. {
  2505. int i;
  2506. struct airo_info *ai = dev->priv;
  2507. if (reset_card (dev, 1))
  2508. return -1;
  2509. if ( setup_card(ai, dev->dev_addr, 1 ) != SUCCESS ) {
  2510. printk( KERN_ERR "airo: MAC could not be enabled\n" );
  2511. return -1;
  2512. }
  2513. printk( KERN_INFO "airo: MAC enabled %s %x:%x:%x:%x:%x:%x\n", dev->name,
  2514. dev->dev_addr[0], dev->dev_addr[1], dev->dev_addr[2],
  2515. dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5]);
  2516. /* Allocate the transmit buffers if needed */
  2517. if (!test_bit(FLAG_MPI,&ai->flags))
  2518. for( i = 0; i < MAX_FIDS; i++ )
  2519. ai->fids[i] = transmit_allocate (ai,2312,i>=MAX_FIDS/2);
  2520. enable_interrupts( ai );
  2521. netif_wake_queue(dev);
  2522. return 0;
  2523. }
  2524. EXPORT_SYMBOL(reset_airo_card);
  2525. static void airo_send_event(struct net_device *dev) {
  2526. struct airo_info *ai = dev->priv;
  2527. union iwreq_data wrqu;
  2528. StatusRid status_rid;
  2529. clear_bit(JOB_EVENT, &ai->flags);
  2530. PC4500_readrid(ai, RID_STATUS, &status_rid, sizeof(status_rid), 0);
  2531. up(&ai->sem);
  2532. wrqu.data.length = 0;
  2533. wrqu.data.flags = 0;
  2534. memcpy(wrqu.ap_addr.sa_data, status_rid.bssid[0], ETH_ALEN);
  2535. wrqu.ap_addr.sa_family = ARPHRD_ETHER;
  2536. /* Send event to user space */
  2537. wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL);
  2538. }
  2539. static int airo_thread(void *data) {
  2540. struct net_device *dev = data;
  2541. struct airo_info *ai = dev->priv;
  2542. int locked;
  2543. daemonize("%s", dev->name);
  2544. allow_signal(SIGTERM);
  2545. while(1) {
  2546. if (signal_pending(current))
  2547. flush_signals(current);
  2548. /* make swsusp happy with our thread */
  2549. try_to_freeze();
  2550. if (test_bit(JOB_DIE, &ai->flags))
  2551. break;
  2552. if (ai->flags & JOB_MASK) {
  2553. locked = down_interruptible(&ai->sem);
  2554. } else {
  2555. wait_queue_t wait;
  2556. init_waitqueue_entry(&wait, current);
  2557. add_wait_queue(&ai->thr_wait, &wait);
  2558. for (;;) {
  2559. set_current_state(TASK_INTERRUPTIBLE);
  2560. if (ai->flags & JOB_MASK)
  2561. break;
  2562. if (ai->expires) {
  2563. if (time_after_eq(jiffies,ai->expires)){
  2564. set_bit(JOB_AUTOWEP,&ai->flags);
  2565. break;
  2566. }
  2567. if (!signal_pending(current)) {
  2568. schedule_timeout(ai->expires - jiffies);
  2569. continue;
  2570. }
  2571. } else if (!signal_pending(current)) {
  2572. schedule();
  2573. continue;
  2574. }
  2575. break;
  2576. }
  2577. current->state = TASK_RUNNING;
  2578. remove_wait_queue(&ai->thr_wait, &wait);
  2579. locked = 1;
  2580. }
  2581. if (locked)
  2582. continue;
  2583. if (test_bit(JOB_DIE, &ai->flags)) {
  2584. up(&ai->sem);
  2585. break;
  2586. }
  2587. if (ai->power.event || test_bit(FLAG_FLASHING, &ai->flags)) {
  2588. up(&ai->sem);
  2589. continue;
  2590. }
  2591. if (test_bit(JOB_XMIT, &ai->flags))
  2592. airo_end_xmit(dev);
  2593. else if (test_bit(JOB_XMIT11, &ai->flags))
  2594. airo_end_xmit11(dev);
  2595. else if (test_bit(JOB_STATS, &ai->flags))
  2596. airo_read_stats(ai);
  2597. else if (test_bit(JOB_WSTATS, &ai->flags))
  2598. airo_read_wireless_stats(ai);
  2599. else if (test_bit(JOB_PROMISC, &ai->flags))
  2600. airo_set_promisc(ai);
  2601. #ifdef MICSUPPORT
  2602. else if (test_bit(JOB_MIC, &ai->flags))
  2603. micinit(ai);
  2604. #endif
  2605. else if (test_bit(JOB_EVENT, &ai->flags))
  2606. airo_send_event(dev);
  2607. else if (test_bit(JOB_AUTOWEP, &ai->flags))
  2608. timer_func(dev);
  2609. }
  2610. complete_and_exit (&ai->thr_exited, 0);
  2611. }
  2612. static irqreturn_t airo_interrupt ( int irq, void* dev_id, struct pt_regs *regs) {
  2613. struct net_device *dev = (struct net_device *)dev_id;
  2614. u16 status;
  2615. u16 fid;
  2616. struct airo_info *apriv = dev->priv;
  2617. u16 savedInterrupts = 0;
  2618. int handled = 0;
  2619. if (!netif_device_present(dev))
  2620. return IRQ_NONE;
  2621. for (;;) {
  2622. status = IN4500( apriv, EVSTAT );
  2623. if ( !(status & STATUS_INTS) || status == 0xffff ) break;
  2624. handled = 1;
  2625. if ( status & EV_AWAKE ) {
  2626. OUT4500( apriv, EVACK, EV_AWAKE );
  2627. OUT4500( apriv, EVACK, EV_AWAKE );
  2628. }
  2629. if (!savedInterrupts) {
  2630. savedInterrupts = IN4500( apriv, EVINTEN );
  2631. OUT4500( apriv, EVINTEN, 0 );
  2632. }
  2633. if ( status & EV_MIC ) {
  2634. OUT4500( apriv, EVACK, EV_MIC );
  2635. #ifdef MICSUPPORT
  2636. if (test_bit(FLAG_MIC_CAPABLE, &apriv->flags)) {
  2637. set_bit(JOB_MIC, &apriv->flags);
  2638. wake_up_interruptible(&apriv->thr_wait);
  2639. }
  2640. #endif
  2641. }
  2642. if ( status & EV_LINK ) {
  2643. union iwreq_data wrqu;
  2644. /* The link status has changed, if you want to put a
  2645. monitor hook in, do it here. (Remember that
  2646. interrupts are still disabled!)
  2647. */
  2648. u16 newStatus = IN4500(apriv, LINKSTAT);
  2649. OUT4500( apriv, EVACK, EV_LINK);
  2650. /* Here is what newStatus means: */
  2651. #define NOBEACON 0x8000 /* Loss of sync - missed beacons */
  2652. #define MAXRETRIES 0x8001 /* Loss of sync - max retries */
  2653. #define MAXARL 0x8002 /* Loss of sync - average retry level exceeded*/
  2654. #define FORCELOSS 0x8003 /* Loss of sync - host request */
  2655. #define TSFSYNC 0x8004 /* Loss of sync - TSF synchronization */
  2656. #define DEAUTH 0x8100 /* Deauthentication (low byte is reason code) */
  2657. #define DISASS 0x8200 /* Disassociation (low byte is reason code) */
  2658. #define ASSFAIL 0x8400 /* Association failure (low byte is reason
  2659. code) */
  2660. #define AUTHFAIL 0x0300 /* Authentication failure (low byte is reason
  2661. code) */
  2662. #define ASSOCIATED 0x0400 /* Assocatied */
  2663. #define RC_RESERVED 0 /* Reserved return code */
  2664. #define RC_NOREASON 1 /* Unspecified reason */
  2665. #define RC_AUTHINV 2 /* Previous authentication invalid */
  2666. #define RC_DEAUTH 3 /* Deauthenticated because sending station is
  2667. leaving */
  2668. #define RC_NOACT 4 /* Disassociated due to inactivity */
  2669. #define RC_MAXLOAD 5 /* Disassociated because AP is unable to handle
  2670. all currently associated stations */
  2671. #define RC_BADCLASS2 6 /* Class 2 frame received from
  2672. non-Authenticated station */
  2673. #define RC_BADCLASS3 7 /* Class 3 frame received from
  2674. non-Associated station */
  2675. #define RC_STATLEAVE 8 /* Disassociated because sending station is
  2676. leaving BSS */
  2677. #define RC_NOAUTH 9 /* Station requesting (Re)Association is not
  2678. Authenticated with the responding station */
  2679. if (newStatus != ASSOCIATED) {
  2680. if (auto_wep && !apriv->expires) {
  2681. apriv->expires = RUN_AT(3*HZ);
  2682. wake_up_interruptible(&apriv->thr_wait);
  2683. }
  2684. } else {
  2685. struct task_struct *task = apriv->task;
  2686. if (auto_wep)
  2687. apriv->expires = 0;
  2688. if (task)
  2689. wake_up_process (task);
  2690. set_bit(FLAG_UPDATE_UNI, &apriv->flags);
  2691. set_bit(FLAG_UPDATE_MULTI, &apriv->flags);
  2692. }
  2693. /* Question : is ASSOCIATED the only status
  2694. * that is valid ? We want to catch handover
  2695. * and reassociations as valid status
  2696. * Jean II */
  2697. if(newStatus == ASSOCIATED) {
  2698. if (apriv->scan_timestamp) {
  2699. /* Send an empty event to user space.
  2700. * We don't send the received data on
  2701. * the event because it would require
  2702. * us to do complex transcoding, and
  2703. * we want to minimise the work done in
  2704. * the irq handler. Use a request to
  2705. * extract the data - Jean II */
  2706. wrqu.data.length = 0;
  2707. wrqu.data.flags = 0;
  2708. wireless_send_event(dev, SIOCGIWSCAN, &wrqu, NULL);
  2709. apriv->scan_timestamp = 0;
  2710. }
  2711. if (down_trylock(&apriv->sem) != 0) {
  2712. set_bit(JOB_EVENT, &apriv->flags);
  2713. wake_up_interruptible(&apriv->thr_wait);
  2714. } else
  2715. airo_send_event(dev);
  2716. } else {
  2717. memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
  2718. wrqu.ap_addr.sa_family = ARPHRD_ETHER;
  2719. /* Send event to user space */
  2720. wireless_send_event(dev, SIOCGIWAP, &wrqu,NULL);
  2721. }
  2722. }
  2723. /* Check to see if there is something to receive */
  2724. if ( status & EV_RX ) {
  2725. struct sk_buff *skb = NULL;
  2726. u16 fc, len, hdrlen = 0;
  2727. #pragma pack(1)
  2728. struct {
  2729. u16 status, len;
  2730. u8 rssi[2];
  2731. u8 rate;
  2732. u8 freq;
  2733. u16 tmp[4];
  2734. } hdr;
  2735. #pragma pack()
  2736. u16 gap;
  2737. u16 tmpbuf[4];
  2738. u16 *buffer;
  2739. if (test_bit(FLAG_MPI,&apriv->flags)) {
  2740. if (test_bit(FLAG_802_11, &apriv->flags))
  2741. mpi_receive_802_11(apriv);
  2742. else
  2743. mpi_receive_802_3(apriv);
  2744. OUT4500(apriv, EVACK, EV_RX);
  2745. goto exitrx;
  2746. }
  2747. fid = IN4500( apriv, RXFID );
  2748. /* Get the packet length */
  2749. if (test_bit(FLAG_802_11, &apriv->flags)) {
  2750. bap_setup (apriv, fid, 4, BAP0);
  2751. bap_read (apriv, (u16*)&hdr, sizeof(hdr), BAP0);
  2752. /* Bad CRC. Ignore packet */
  2753. if (le16_to_cpu(hdr.status) & 2)
  2754. hdr.len = 0;
  2755. if (apriv->wifidev == NULL)
  2756. hdr.len = 0;
  2757. } else {
  2758. bap_setup (apriv, fid, 0x36, BAP0);
  2759. bap_read (apriv, (u16*)&hdr.len, 2, BAP0);
  2760. }
  2761. len = le16_to_cpu(hdr.len);
  2762. if (len > 2312) {
  2763. printk( KERN_ERR "airo: Bad size %d\n", len );
  2764. goto badrx;
  2765. }
  2766. if (len == 0)
  2767. goto badrx;
  2768. if (test_bit(FLAG_802_11, &apriv->flags)) {
  2769. bap_read (apriv, (u16*)&fc, sizeof(fc), BAP0);
  2770. fc = le16_to_cpu(fc);
  2771. switch (fc & 0xc) {
  2772. case 4:
  2773. if ((fc & 0xe0) == 0xc0)
  2774. hdrlen = 10;
  2775. else
  2776. hdrlen = 16;
  2777. break;
  2778. case 8:
  2779. if ((fc&0x300)==0x300){
  2780. hdrlen = 30;
  2781. break;
  2782. }
  2783. default:
  2784. hdrlen = 24;
  2785. }
  2786. } else
  2787. hdrlen = ETH_ALEN * 2;
  2788. skb = dev_alloc_skb( len + hdrlen + 2 + 2 );
  2789. if ( !skb ) {
  2790. apriv->stats.rx_dropped++;
  2791. goto badrx;
  2792. }
  2793. skb_reserve(skb, 2); /* This way the IP header is aligned */
  2794. buffer = (u16*)skb_put (skb, len + hdrlen);
  2795. if (test_bit(FLAG_802_11, &apriv->flags)) {
  2796. buffer[0] = fc;
  2797. bap_read (apriv, buffer + 1, hdrlen - 2, BAP0);
  2798. if (hdrlen == 24)
  2799. bap_read (apriv, tmpbuf, 6, BAP0);
  2800. bap_read (apriv, &gap, sizeof(gap), BAP0);
  2801. gap = le16_to_cpu(gap);
  2802. if (gap) {
  2803. if (gap <= 8)
  2804. bap_read (apriv, tmpbuf, gap, BAP0);
  2805. else
  2806. printk(KERN_ERR "airo: gaplen too big. Problems will follow...\n");
  2807. }
  2808. bap_read (apriv, buffer + hdrlen/2, len, BAP0);
  2809. } else {
  2810. #ifdef MICSUPPORT
  2811. MICBuffer micbuf;
  2812. #endif
  2813. bap_read (apriv, buffer, ETH_ALEN*2, BAP0);
  2814. #ifdef MICSUPPORT
  2815. if (apriv->micstats.enabled) {
  2816. bap_read (apriv,(u16*)&micbuf,sizeof(micbuf),BAP0);
  2817. if (ntohs(micbuf.typelen) > 0x05DC)
  2818. bap_setup (apriv, fid, 0x44, BAP0);
  2819. else {
  2820. if (len <= sizeof(micbuf))
  2821. goto badmic;
  2822. len -= sizeof(micbuf);
  2823. skb_trim (skb, len + hdrlen);
  2824. }
  2825. }
  2826. #endif
  2827. bap_read(apriv,buffer+ETH_ALEN,len,BAP0);
  2828. #ifdef MICSUPPORT
  2829. if (decapsulate(apriv,&micbuf,(etherHead*)buffer,len)) {
  2830. badmic:
  2831. dev_kfree_skb_irq (skb);
  2832. #else
  2833. if (0) {
  2834. #endif
  2835. badrx:
  2836. OUT4500( apriv, EVACK, EV_RX);
  2837. goto exitrx;
  2838. }
  2839. }
  2840. #ifdef WIRELESS_SPY
  2841. if (apriv->spy_data.spy_number > 0) {
  2842. char *sa;
  2843. struct iw_quality wstats;
  2844. /* Prepare spy data : addr + qual */
  2845. if (!test_bit(FLAG_802_11, &apriv->flags)) {
  2846. sa = (char*)buffer + 6;
  2847. bap_setup (apriv, fid, 8, BAP0);
  2848. bap_read (apriv, (u16*)hdr.rssi, 2, BAP0);
  2849. } else
  2850. sa = (char*)buffer + 10;
  2851. wstats.qual = hdr.rssi[0];
  2852. if (apriv->rssi)
  2853. wstats.level = 0x100 - apriv->rssi[hdr.rssi[1]].rssidBm;
  2854. else
  2855. wstats.level = (hdr.rssi[1] + 321) / 2;
  2856. wstats.noise = apriv->wstats.qual.noise;
  2857. wstats.updated = IW_QUAL_LEVEL_UPDATED
  2858. | IW_QUAL_QUAL_UPDATED
  2859. | IW_QUAL_DBM;
  2860. /* Update spy records */
  2861. wireless_spy_update(dev, sa, &wstats);
  2862. }
  2863. #endif /* WIRELESS_SPY */
  2864. OUT4500( apriv, EVACK, EV_RX);
  2865. if (test_bit(FLAG_802_11, &apriv->flags)) {
  2866. skb->mac.raw = skb->data;
  2867. skb->pkt_type = PACKET_OTHERHOST;
  2868. skb->dev = apriv->wifidev;
  2869. skb->protocol = htons(ETH_P_802_2);
  2870. } else {
  2871. skb->dev = dev;
  2872. skb->protocol = eth_type_trans(skb,dev);
  2873. }
  2874. skb->dev->last_rx = jiffies;
  2875. skb->ip_summed = CHECKSUM_NONE;
  2876. netif_rx( skb );
  2877. }
  2878. exitrx:
  2879. /* Check to see if a packet has been transmitted */
  2880. if ( status & ( EV_TX|EV_TXCPY|EV_TXEXC ) ) {
  2881. int i;
  2882. int len = 0;
  2883. int index = -1;
  2884. if (test_bit(FLAG_MPI,&apriv->flags)) {
  2885. unsigned long flags;
  2886. if (status & EV_TXEXC)
  2887. get_tx_error(apriv, -1);
  2888. spin_lock_irqsave(&apriv->aux_lock, flags);
  2889. if (!skb_queue_empty(&apriv->txq)) {
  2890. spin_unlock_irqrestore(&apriv->aux_lock,flags);
  2891. mpi_send_packet (dev);
  2892. } else {
  2893. clear_bit(FLAG_PENDING_XMIT, &apriv->flags);
  2894. spin_unlock_irqrestore(&apriv->aux_lock,flags);
  2895. netif_wake_queue (dev);
  2896. }
  2897. OUT4500( apriv, EVACK,
  2898. status & (EV_TX|EV_TXCPY|EV_TXEXC));
  2899. goto exittx;
  2900. }
  2901. fid = IN4500(apriv, TXCOMPLFID);
  2902. for( i = 0; i < MAX_FIDS; i++ ) {
  2903. if ( ( apriv->fids[i] & 0xffff ) == fid ) {
  2904. len = apriv->fids[i] >> 16;
  2905. index = i;
  2906. }
  2907. }
  2908. if (index != -1) {
  2909. if (status & EV_TXEXC)
  2910. get_tx_error(apriv, index);
  2911. OUT4500( apriv, EVACK, status & (EV_TX | EV_TXEXC));
  2912. /* Set up to be used again */
  2913. apriv->fids[index] &= 0xffff;
  2914. if (index < MAX_FIDS / 2) {
  2915. if (!test_bit(FLAG_PENDING_XMIT, &apriv->flags))
  2916. netif_wake_queue(dev);
  2917. } else {
  2918. if (!test_bit(FLAG_PENDING_XMIT11, &apriv->flags))
  2919. netif_wake_queue(apriv->wifidev);
  2920. }
  2921. } else {
  2922. OUT4500( apriv, EVACK, status & (EV_TX | EV_TXCPY | EV_TXEXC));
  2923. printk( KERN_ERR "airo: Unallocated FID was used to xmit\n" );
  2924. }
  2925. }
  2926. exittx:
  2927. if ( status & ~STATUS_INTS & ~IGNORE_INTS )
  2928. printk( KERN_WARNING "airo: Got weird status %x\n",
  2929. status & ~STATUS_INTS & ~IGNORE_INTS );
  2930. }
  2931. if (savedInterrupts)
  2932. OUT4500( apriv, EVINTEN, savedInterrupts );
  2933. /* done.. */
  2934. return IRQ_RETVAL(handled);
  2935. }
  2936. /*
  2937. * Routines to talk to the card
  2938. */
  2939. /*
  2940. * This was originally written for the 4500, hence the name
  2941. * NOTE: If use with 8bit mode and SMP bad things will happen!
  2942. * Why would some one do 8 bit IO in an SMP machine?!?
  2943. */
  2944. static void OUT4500( struct airo_info *ai, u16 reg, u16 val ) {
  2945. if (test_bit(FLAG_MPI,&ai->flags))
  2946. reg <<= 1;
  2947. if ( !do8bitIO )
  2948. outw( val, ai->dev->base_addr + reg );
  2949. else {
  2950. outb( val & 0xff, ai->dev->base_addr + reg );
  2951. outb( val >> 8, ai->dev->base_addr + reg + 1 );
  2952. }
  2953. }
  2954. static u16 IN4500( struct airo_info *ai, u16 reg ) {
  2955. unsigned short rc;
  2956. if (test_bit(FLAG_MPI,&ai->flags))
  2957. reg <<= 1;
  2958. if ( !do8bitIO )
  2959. rc = inw( ai->dev->base_addr + reg );
  2960. else {
  2961. rc = inb( ai->dev->base_addr + reg );
  2962. rc += ((int)inb( ai->dev->base_addr + reg + 1 )) << 8;
  2963. }
  2964. return rc;
  2965. }
  2966. static int enable_MAC( struct airo_info *ai, Resp *rsp, int lock ) {
  2967. int rc;
  2968. Cmd cmd;
  2969. /* FLAG_RADIO_OFF : Radio disabled via /proc or Wireless Extensions
  2970. * FLAG_RADIO_DOWN : Radio disabled via "ifconfig ethX down"
  2971. * Note : we could try to use !netif_running(dev) in enable_MAC()
  2972. * instead of this flag, but I don't trust it *within* the
  2973. * open/close functions, and testing both flags together is
  2974. * "cheaper" - Jean II */
  2975. if (ai->flags & FLAG_RADIO_MASK) return SUCCESS;
  2976. if (lock && down_interruptible(&ai->sem))
  2977. return -ERESTARTSYS;
  2978. if (!test_bit(FLAG_ENABLED, &ai->flags)) {
  2979. memset(&cmd, 0, sizeof(cmd));
  2980. cmd.cmd = MAC_ENABLE;
  2981. rc = issuecommand(ai, &cmd, rsp);
  2982. if (rc == SUCCESS)
  2983. set_bit(FLAG_ENABLED, &ai->flags);
  2984. } else
  2985. rc = SUCCESS;
  2986. if (lock)
  2987. up(&ai->sem);
  2988. if (rc)
  2989. printk(KERN_ERR "%s: Cannot enable MAC, err=%d\n",
  2990. __FUNCTION__,rc);
  2991. return rc;
  2992. }
  2993. static void disable_MAC( struct airo_info *ai, int lock ) {
  2994. Cmd cmd;
  2995. Resp rsp;
  2996. if (lock && down_interruptible(&ai->sem))
  2997. return;
  2998. if (test_bit(FLAG_ENABLED, &ai->flags)) {
  2999. memset(&cmd, 0, sizeof(cmd));
  3000. cmd.cmd = MAC_DISABLE; // disable in case already enabled
  3001. issuecommand(ai, &cmd, &rsp);
  3002. clear_bit(FLAG_ENABLED, &ai->flags);
  3003. }
  3004. if (lock)
  3005. up(&ai->sem);
  3006. }
  3007. static void enable_interrupts( struct airo_info *ai ) {
  3008. /* Enable the interrupts */
  3009. OUT4500( ai, EVINTEN, STATUS_INTS );
  3010. }
  3011. static void disable_interrupts( struct airo_info *ai ) {
  3012. OUT4500( ai, EVINTEN, 0 );
  3013. }
  3014. static void mpi_receive_802_3(struct airo_info *ai)
  3015. {
  3016. RxFid rxd;
  3017. int len = 0;
  3018. struct sk_buff *skb;
  3019. char *buffer;
  3020. #ifdef MICSUPPORT
  3021. int off = 0;
  3022. MICBuffer micbuf;
  3023. #endif
  3024. memcpy_fromio(&rxd, ai->rxfids[0].card_ram_off, sizeof(rxd));
  3025. /* Make sure we got something */
  3026. if (rxd.rdy && rxd.valid == 0) {
  3027. len = rxd.len + 12;
  3028. if (len < 12 || len > 2048)
  3029. goto badrx;
  3030. skb = dev_alloc_skb(len);
  3031. if (!skb) {
  3032. ai->stats.rx_dropped++;
  3033. goto badrx;
  3034. }
  3035. buffer = skb_put(skb,len);
  3036. #ifdef MICSUPPORT
  3037. memcpy(buffer, ai->rxfids[0].virtual_host_addr, ETH_ALEN * 2);
  3038. if (ai->micstats.enabled) {
  3039. memcpy(&micbuf,
  3040. ai->rxfids[0].virtual_host_addr + ETH_ALEN * 2,
  3041. sizeof(micbuf));
  3042. if (ntohs(micbuf.typelen) <= 0x05DC) {
  3043. if (len <= sizeof(micbuf) + ETH_ALEN * 2)
  3044. goto badmic;
  3045. off = sizeof(micbuf);
  3046. skb_trim (skb, len - off);
  3047. }
  3048. }
  3049. memcpy(buffer + ETH_ALEN * 2,
  3050. ai->rxfids[0].virtual_host_addr + ETH_ALEN * 2 + off,
  3051. len - ETH_ALEN * 2 - off);
  3052. if (decapsulate (ai, &micbuf, (etherHead*)buffer, len - off - ETH_ALEN * 2)) {
  3053. badmic:
  3054. dev_kfree_skb_irq (skb);
  3055. goto badrx;
  3056. }
  3057. #else
  3058. memcpy(buffer, ai->rxfids[0].virtual_host_addr, len);
  3059. #endif
  3060. #ifdef WIRELESS_SPY
  3061. if (ai->spy_data.spy_number > 0) {
  3062. char *sa;
  3063. struct iw_quality wstats;
  3064. /* Prepare spy data : addr + qual */
  3065. sa = buffer + ETH_ALEN;
  3066. wstats.qual = 0; /* XXX Where do I get that info from ??? */
  3067. wstats.level = 0;
  3068. wstats.updated = 0;
  3069. /* Update spy records */
  3070. wireless_spy_update(ai->dev, sa, &wstats);
  3071. }
  3072. #endif /* WIRELESS_SPY */
  3073. skb->dev = ai->dev;
  3074. skb->ip_summed = CHECKSUM_NONE;
  3075. skb->protocol = eth_type_trans(skb, ai->dev);
  3076. skb->dev->last_rx = jiffies;
  3077. netif_rx(skb);
  3078. }
  3079. badrx:
  3080. if (rxd.valid == 0) {
  3081. rxd.valid = 1;
  3082. rxd.rdy = 0;
  3083. rxd.len = PKTSIZE;
  3084. memcpy_toio(ai->rxfids[0].card_ram_off, &rxd, sizeof(rxd));
  3085. }
  3086. }
  3087. void mpi_receive_802_11 (struct airo_info *ai)
  3088. {
  3089. RxFid rxd;
  3090. struct sk_buff *skb = NULL;
  3091. u16 fc, len, hdrlen = 0;
  3092. #pragma pack(1)
  3093. struct {
  3094. u16 status, len;
  3095. u8 rssi[2];
  3096. u8 rate;
  3097. u8 freq;
  3098. u16 tmp[4];
  3099. } hdr;
  3100. #pragma pack()
  3101. u16 gap;
  3102. u16 *buffer;
  3103. char *ptr = ai->rxfids[0].virtual_host_addr+4;
  3104. memcpy_fromio(&rxd, ai->rxfids[0].card_ram_off, sizeof(rxd));
  3105. memcpy ((char *)&hdr, ptr, sizeof(hdr));
  3106. ptr += sizeof(hdr);
  3107. /* Bad CRC. Ignore packet */
  3108. if (le16_to_cpu(hdr.status) & 2)
  3109. hdr.len = 0;
  3110. if (ai->wifidev == NULL)
  3111. hdr.len = 0;
  3112. len = le16_to_cpu(hdr.len);
  3113. if (len > 2312) {
  3114. printk( KERN_ERR "airo: Bad size %d\n", len );
  3115. goto badrx;
  3116. }
  3117. if (len == 0)
  3118. goto badrx;
  3119. memcpy ((char *)&fc, ptr, sizeof(fc));
  3120. fc = le16_to_cpu(fc);
  3121. switch (fc & 0xc) {
  3122. case 4:
  3123. if ((fc & 0xe0) == 0xc0)
  3124. hdrlen = 10;
  3125. else
  3126. hdrlen = 16;
  3127. break;
  3128. case 8:
  3129. if ((fc&0x300)==0x300){
  3130. hdrlen = 30;
  3131. break;
  3132. }
  3133. default:
  3134. hdrlen = 24;
  3135. }
  3136. skb = dev_alloc_skb( len + hdrlen + 2 );
  3137. if ( !skb ) {
  3138. ai->stats.rx_dropped++;
  3139. goto badrx;
  3140. }
  3141. buffer = (u16*)skb_put (skb, len + hdrlen);
  3142. memcpy ((char *)buffer, ptr, hdrlen);
  3143. ptr += hdrlen;
  3144. if (hdrlen == 24)
  3145. ptr += 6;
  3146. memcpy ((char *)&gap, ptr, sizeof(gap));
  3147. ptr += sizeof(gap);
  3148. gap = le16_to_cpu(gap);
  3149. if (gap) {
  3150. if (gap <= 8)
  3151. ptr += gap;
  3152. else
  3153. printk(KERN_ERR
  3154. "airo: gaplen too big. Problems will follow...\n");
  3155. }
  3156. memcpy ((char *)buffer + hdrlen, ptr, len);
  3157. ptr += len;
  3158. #ifdef IW_WIRELESS_SPY /* defined in iw_handler.h */
  3159. if (ai->spy_data.spy_number > 0) {
  3160. char *sa;
  3161. struct iw_quality wstats;
  3162. /* Prepare spy data : addr + qual */
  3163. sa = (char*)buffer + 10;
  3164. wstats.qual = hdr.rssi[0];
  3165. if (ai->rssi)
  3166. wstats.level = 0x100 - ai->rssi[hdr.rssi[1]].rssidBm;
  3167. else
  3168. wstats.level = (hdr.rssi[1] + 321) / 2;
  3169. wstats.noise = ai->wstats.qual.noise;
  3170. wstats.updated = IW_QUAL_QUAL_UPDATED
  3171. | IW_QUAL_LEVEL_UPDATED
  3172. | IW_QUAL_DBM;
  3173. /* Update spy records */
  3174. wireless_spy_update(ai->dev, sa, &wstats);
  3175. }
  3176. #endif /* IW_WIRELESS_SPY */
  3177. skb->mac.raw = skb->data;
  3178. skb->pkt_type = PACKET_OTHERHOST;
  3179. skb->dev = ai->wifidev;
  3180. skb->protocol = htons(ETH_P_802_2);
  3181. skb->dev->last_rx = jiffies;
  3182. skb->ip_summed = CHECKSUM_NONE;
  3183. netif_rx( skb );
  3184. badrx:
  3185. if (rxd.valid == 0) {
  3186. rxd.valid = 1;
  3187. rxd.rdy = 0;
  3188. rxd.len = PKTSIZE;
  3189. memcpy_toio(ai->rxfids[0].card_ram_off, &rxd, sizeof(rxd));
  3190. }
  3191. }
  3192. static u16 setup_card(struct airo_info *ai, u8 *mac, int lock)
  3193. {
  3194. Cmd cmd;
  3195. Resp rsp;
  3196. int status;
  3197. int i;
  3198. SsidRid mySsid;
  3199. u16 lastindex;
  3200. WepKeyRid wkr;
  3201. int rc;
  3202. memset( &mySsid, 0, sizeof( mySsid ) );
  3203. kfree (ai->flash);
  3204. ai->flash = NULL;
  3205. /* The NOP is the first step in getting the card going */
  3206. cmd.cmd = NOP;
  3207. cmd.parm0 = cmd.parm1 = cmd.parm2 = 0;
  3208. if (lock && down_interruptible(&ai->sem))
  3209. return ERROR;
  3210. if ( issuecommand( ai, &cmd, &rsp ) != SUCCESS ) {
  3211. if (lock)
  3212. up(&ai->sem);
  3213. return ERROR;
  3214. }
  3215. disable_MAC( ai, 0);
  3216. // Let's figure out if we need to use the AUX port
  3217. if (!test_bit(FLAG_MPI,&ai->flags)) {
  3218. cmd.cmd = CMD_ENABLEAUX;
  3219. if (issuecommand(ai, &cmd, &rsp) != SUCCESS) {
  3220. if (lock)
  3221. up(&ai->sem);
  3222. printk(KERN_ERR "airo: Error checking for AUX port\n");
  3223. return ERROR;
  3224. }
  3225. if (!aux_bap || rsp.status & 0xff00) {
  3226. ai->bap_read = fast_bap_read;
  3227. printk(KERN_DEBUG "airo: Doing fast bap_reads\n");
  3228. } else {
  3229. ai->bap_read = aux_bap_read;
  3230. printk(KERN_DEBUG "airo: Doing AUX bap_reads\n");
  3231. }
  3232. }
  3233. if (lock)
  3234. up(&ai->sem);
  3235. if (ai->config.len == 0) {
  3236. tdsRssiRid rssi_rid;
  3237. CapabilityRid cap_rid;
  3238. kfree(ai->APList);
  3239. ai->APList = NULL;
  3240. kfree(ai->SSID);
  3241. ai->SSID = NULL;
  3242. // general configuration (read/modify/write)
  3243. status = readConfigRid(ai, lock);
  3244. if ( status != SUCCESS ) return ERROR;
  3245. status = readCapabilityRid(ai, &cap_rid, lock);
  3246. if ( status != SUCCESS ) return ERROR;
  3247. status = PC4500_readrid(ai,RID_RSSI,&rssi_rid,sizeof(rssi_rid),lock);
  3248. if ( status == SUCCESS ) {
  3249. if (ai->rssi || (ai->rssi = kmalloc(512, GFP_KERNEL)) != NULL)
  3250. memcpy(ai->rssi, (u8*)&rssi_rid + 2, 512); /* Skip RID length member */
  3251. }
  3252. else {
  3253. kfree(ai->rssi);
  3254. ai->rssi = NULL;
  3255. if (cap_rid.softCap & 8)
  3256. ai->config.rmode |= RXMODE_NORMALIZED_RSSI;
  3257. else
  3258. printk(KERN_WARNING "airo: unknown received signal level scale\n");
  3259. }
  3260. ai->config.opmode = adhoc ? MODE_STA_IBSS : MODE_STA_ESS;
  3261. ai->config.authType = AUTH_OPEN;
  3262. ai->config.modulation = MOD_CCK;
  3263. #ifdef MICSUPPORT
  3264. if ((cap_rid.len>=sizeof(cap_rid)) && (cap_rid.extSoftCap&1) &&
  3265. (micsetup(ai) == SUCCESS)) {
  3266. ai->config.opmode |= MODE_MIC;
  3267. set_bit(FLAG_MIC_CAPABLE, &ai->flags);
  3268. }
  3269. #endif
  3270. /* Save off the MAC */
  3271. for( i = 0; i < ETH_ALEN; i++ ) {
  3272. mac[i] = ai->config.macAddr[i];
  3273. }
  3274. /* Check to see if there are any insmod configured
  3275. rates to add */
  3276. if ( rates[0] ) {
  3277. int i = 0;
  3278. memset(ai->config.rates,0,sizeof(ai->config.rates));
  3279. for( i = 0; i < 8 && rates[i]; i++ ) {
  3280. ai->config.rates[i] = rates[i];
  3281. }
  3282. }
  3283. if ( basic_rate > 0 ) {
  3284. int i;
  3285. for( i = 0; i < 8; i++ ) {
  3286. if ( ai->config.rates[i] == basic_rate ||
  3287. !ai->config.rates ) {
  3288. ai->config.rates[i] = basic_rate | 0x80;
  3289. break;
  3290. }
  3291. }
  3292. }
  3293. set_bit (FLAG_COMMIT, &ai->flags);
  3294. }
  3295. /* Setup the SSIDs if present */
  3296. if ( ssids[0] ) {
  3297. int i;
  3298. for( i = 0; i < 3 && ssids[i]; i++ ) {
  3299. mySsid.ssids[i].len = strlen(ssids[i]);
  3300. if ( mySsid.ssids[i].len > 32 )
  3301. mySsid.ssids[i].len = 32;
  3302. memcpy(mySsid.ssids[i].ssid, ssids[i],
  3303. mySsid.ssids[i].len);
  3304. }
  3305. mySsid.len = sizeof(mySsid);
  3306. }
  3307. status = writeConfigRid(ai, lock);
  3308. if ( status != SUCCESS ) return ERROR;
  3309. /* Set up the SSID list */
  3310. if ( ssids[0] ) {
  3311. status = writeSsidRid(ai, &mySsid, lock);
  3312. if ( status != SUCCESS ) return ERROR;
  3313. }
  3314. status = enable_MAC(ai, &rsp, lock);
  3315. if ( status != SUCCESS || (rsp.status & 0xFF00) != 0) {
  3316. printk( KERN_ERR "airo: Bad MAC enable reason = %x, rid = %x, offset = %d\n", rsp.rsp0, rsp.rsp1, rsp.rsp2 );
  3317. return ERROR;
  3318. }
  3319. /* Grab the initial wep key, we gotta save it for auto_wep */
  3320. rc = readWepKeyRid(ai, &wkr, 1, lock);
  3321. if (rc == SUCCESS) do {
  3322. lastindex = wkr.kindex;
  3323. if (wkr.kindex == 0xffff) {
  3324. ai->defindex = wkr.mac[0];
  3325. }
  3326. rc = readWepKeyRid(ai, &wkr, 0, lock);
  3327. } while(lastindex != wkr.kindex);
  3328. if (auto_wep) {
  3329. ai->expires = RUN_AT(3*HZ);
  3330. wake_up_interruptible(&ai->thr_wait);
  3331. }
  3332. return SUCCESS;
  3333. }
  3334. static u16 issuecommand(struct airo_info *ai, Cmd *pCmd, Resp *pRsp) {
  3335. // Im really paranoid about letting it run forever!
  3336. int max_tries = 600000;
  3337. if (IN4500(ai, EVSTAT) & EV_CMD)
  3338. OUT4500(ai, EVACK, EV_CMD);
  3339. OUT4500(ai, PARAM0, pCmd->parm0);
  3340. OUT4500(ai, PARAM1, pCmd->parm1);
  3341. OUT4500(ai, PARAM2, pCmd->parm2);
  3342. OUT4500(ai, COMMAND, pCmd->cmd);
  3343. while (max_tries-- && (IN4500(ai, EVSTAT) & EV_CMD) == 0) {
  3344. if ((IN4500(ai, COMMAND)) == pCmd->cmd)
  3345. // PC4500 didn't notice command, try again
  3346. OUT4500(ai, COMMAND, pCmd->cmd);
  3347. if (!in_atomic() && (max_tries & 255) == 0)
  3348. schedule();
  3349. }
  3350. if ( max_tries == -1 ) {
  3351. printk( KERN_ERR
  3352. "airo: Max tries exceeded when issueing command\n" );
  3353. if (IN4500(ai, COMMAND) & COMMAND_BUSY)
  3354. OUT4500(ai, EVACK, EV_CLEARCOMMANDBUSY);
  3355. return ERROR;
  3356. }
  3357. // command completed
  3358. pRsp->status = IN4500(ai, STATUS);
  3359. pRsp->rsp0 = IN4500(ai, RESP0);
  3360. pRsp->rsp1 = IN4500(ai, RESP1);
  3361. pRsp->rsp2 = IN4500(ai, RESP2);
  3362. if ((pRsp->status & 0xff00)!=0 && pCmd->cmd != CMD_SOFTRESET) {
  3363. printk (KERN_ERR "airo: cmd= %x\n", pCmd->cmd);
  3364. printk (KERN_ERR "airo: status= %x\n", pRsp->status);
  3365. printk (KERN_ERR "airo: Rsp0= %x\n", pRsp->rsp0);
  3366. printk (KERN_ERR "airo: Rsp1= %x\n", pRsp->rsp1);
  3367. printk (KERN_ERR "airo: Rsp2= %x\n", pRsp->rsp2);
  3368. }
  3369. // clear stuck command busy if necessary
  3370. if (IN4500(ai, COMMAND) & COMMAND_BUSY) {
  3371. OUT4500(ai, EVACK, EV_CLEARCOMMANDBUSY);
  3372. }
  3373. // acknowledge processing the status/response
  3374. OUT4500(ai, EVACK, EV_CMD);
  3375. return SUCCESS;
  3376. }
  3377. /* Sets up the bap to start exchange data. whichbap should
  3378. * be one of the BAP0 or BAP1 defines. Locks should be held before
  3379. * calling! */
  3380. static int bap_setup(struct airo_info *ai, u16 rid, u16 offset, int whichbap )
  3381. {
  3382. int timeout = 50;
  3383. int max_tries = 3;
  3384. OUT4500(ai, SELECT0+whichbap, rid);
  3385. OUT4500(ai, OFFSET0+whichbap, offset);
  3386. while (1) {
  3387. int status = IN4500(ai, OFFSET0+whichbap);
  3388. if (status & BAP_BUSY) {
  3389. /* This isn't really a timeout, but its kinda
  3390. close */
  3391. if (timeout--) {
  3392. continue;
  3393. }
  3394. } else if ( status & BAP_ERR ) {
  3395. /* invalid rid or offset */
  3396. printk( KERN_ERR "airo: BAP error %x %d\n",
  3397. status, whichbap );
  3398. return ERROR;
  3399. } else if (status & BAP_DONE) { // success
  3400. return SUCCESS;
  3401. }
  3402. if ( !(max_tries--) ) {
  3403. printk( KERN_ERR
  3404. "airo: BAP setup error too many retries\n" );
  3405. return ERROR;
  3406. }
  3407. // -- PC4500 missed it, try again
  3408. OUT4500(ai, SELECT0+whichbap, rid);
  3409. OUT4500(ai, OFFSET0+whichbap, offset);
  3410. timeout = 50;
  3411. }
  3412. }
  3413. /* should only be called by aux_bap_read. This aux function and the
  3414. following use concepts not documented in the developers guide. I
  3415. got them from a patch given to my by Aironet */
  3416. static u16 aux_setup(struct airo_info *ai, u16 page,
  3417. u16 offset, u16 *len)
  3418. {
  3419. u16 next;
  3420. OUT4500(ai, AUXPAGE, page);
  3421. OUT4500(ai, AUXOFF, 0);
  3422. next = IN4500(ai, AUXDATA);
  3423. *len = IN4500(ai, AUXDATA)&0xff;
  3424. if (offset != 4) OUT4500(ai, AUXOFF, offset);
  3425. return next;
  3426. }
  3427. /* requires call to bap_setup() first */
  3428. static int aux_bap_read(struct airo_info *ai, u16 *pu16Dst,
  3429. int bytelen, int whichbap)
  3430. {
  3431. u16 len;
  3432. u16 page;
  3433. u16 offset;
  3434. u16 next;
  3435. int words;
  3436. int i;
  3437. unsigned long flags;
  3438. spin_lock_irqsave(&ai->aux_lock, flags);
  3439. page = IN4500(ai, SWS0+whichbap);
  3440. offset = IN4500(ai, SWS2+whichbap);
  3441. next = aux_setup(ai, page, offset, &len);
  3442. words = (bytelen+1)>>1;
  3443. for (i=0; i<words;) {
  3444. int count;
  3445. count = (len>>1) < (words-i) ? (len>>1) : (words-i);
  3446. if ( !do8bitIO )
  3447. insw( ai->dev->base_addr+DATA0+whichbap,
  3448. pu16Dst+i,count );
  3449. else
  3450. insb( ai->dev->base_addr+DATA0+whichbap,
  3451. pu16Dst+i, count << 1 );
  3452. i += count;
  3453. if (i<words) {
  3454. next = aux_setup(ai, next, 4, &len);
  3455. }
  3456. }
  3457. spin_unlock_irqrestore(&ai->aux_lock, flags);
  3458. return SUCCESS;
  3459. }
  3460. /* requires call to bap_setup() first */
  3461. static int fast_bap_read(struct airo_info *ai, u16 *pu16Dst,
  3462. int bytelen, int whichbap)
  3463. {
  3464. bytelen = (bytelen + 1) & (~1); // round up to even value
  3465. if ( !do8bitIO )
  3466. insw( ai->dev->base_addr+DATA0+whichbap, pu16Dst, bytelen>>1 );
  3467. else
  3468. insb( ai->dev->base_addr+DATA0+whichbap, pu16Dst, bytelen );
  3469. return SUCCESS;
  3470. }
  3471. /* requires call to bap_setup() first */
  3472. static int bap_write(struct airo_info *ai, const u16 *pu16Src,
  3473. int bytelen, int whichbap)
  3474. {
  3475. bytelen = (bytelen + 1) & (~1); // round up to even value
  3476. if ( !do8bitIO )
  3477. outsw( ai->dev->base_addr+DATA0+whichbap,
  3478. pu16Src, bytelen>>1 );
  3479. else
  3480. outsb( ai->dev->base_addr+DATA0+whichbap, pu16Src, bytelen );
  3481. return SUCCESS;
  3482. }
  3483. static int PC4500_accessrid(struct airo_info *ai, u16 rid, u16 accmd)
  3484. {
  3485. Cmd cmd; /* for issuing commands */
  3486. Resp rsp; /* response from commands */
  3487. u16 status;
  3488. memset(&cmd, 0, sizeof(cmd));
  3489. cmd.cmd = accmd;
  3490. cmd.parm0 = rid;
  3491. status = issuecommand(ai, &cmd, &rsp);
  3492. if (status != 0) return status;
  3493. if ( (rsp.status & 0x7F00) != 0) {
  3494. return (accmd << 8) + (rsp.rsp0 & 0xFF);
  3495. }
  3496. return 0;
  3497. }
  3498. /* Note, that we are using BAP1 which is also used by transmit, so
  3499. * we must get a lock. */
  3500. static int PC4500_readrid(struct airo_info *ai, u16 rid, void *pBuf, int len, int lock)
  3501. {
  3502. u16 status;
  3503. int rc = SUCCESS;
  3504. if (lock) {
  3505. if (down_interruptible(&ai->sem))
  3506. return ERROR;
  3507. }
  3508. if (test_bit(FLAG_MPI,&ai->flags)) {
  3509. Cmd cmd;
  3510. Resp rsp;
  3511. memset(&cmd, 0, sizeof(cmd));
  3512. memset(&rsp, 0, sizeof(rsp));
  3513. ai->config_desc.rid_desc.valid = 1;
  3514. ai->config_desc.rid_desc.len = RIDSIZE;
  3515. ai->config_desc.rid_desc.rid = 0;
  3516. ai->config_desc.rid_desc.host_addr = ai->ridbus;
  3517. cmd.cmd = CMD_ACCESS;
  3518. cmd.parm0 = rid;
  3519. memcpy_toio(ai->config_desc.card_ram_off,
  3520. &ai->config_desc.rid_desc, sizeof(Rid));
  3521. rc = issuecommand(ai, &cmd, &rsp);
  3522. if (rsp.status & 0x7f00)
  3523. rc = rsp.rsp0;
  3524. if (!rc)
  3525. memcpy(pBuf, ai->config_desc.virtual_host_addr, len);
  3526. goto done;
  3527. } else {
  3528. if ((status = PC4500_accessrid(ai, rid, CMD_ACCESS))!=SUCCESS) {
  3529. rc = status;
  3530. goto done;
  3531. }
  3532. if (bap_setup(ai, rid, 0, BAP1) != SUCCESS) {
  3533. rc = ERROR;
  3534. goto done;
  3535. }
  3536. // read the rid length field
  3537. bap_read(ai, pBuf, 2, BAP1);
  3538. // length for remaining part of rid
  3539. len = min(len, (int)le16_to_cpu(*(u16*)pBuf)) - 2;
  3540. if ( len <= 2 ) {
  3541. printk( KERN_ERR
  3542. "airo: Rid %x has a length of %d which is too short\n",
  3543. (int)rid, (int)len );
  3544. rc = ERROR;
  3545. goto done;
  3546. }
  3547. // read remainder of the rid
  3548. rc = bap_read(ai, ((u16*)pBuf)+1, len, BAP1);
  3549. }
  3550. done:
  3551. if (lock)
  3552. up(&ai->sem);
  3553. return rc;
  3554. }
  3555. /* Note, that we are using BAP1 which is also used by transmit, so
  3556. * make sure this isnt called when a transmit is happening */
  3557. static int PC4500_writerid(struct airo_info *ai, u16 rid,
  3558. const void *pBuf, int len, int lock)
  3559. {
  3560. u16 status;
  3561. int rc = SUCCESS;
  3562. *(u16*)pBuf = cpu_to_le16((u16)len);
  3563. if (lock) {
  3564. if (down_interruptible(&ai->sem))
  3565. return ERROR;
  3566. }
  3567. if (test_bit(FLAG_MPI,&ai->flags)) {
  3568. Cmd cmd;
  3569. Resp rsp;
  3570. if (test_bit(FLAG_ENABLED, &ai->flags))
  3571. printk(KERN_ERR
  3572. "%s: MAC should be disabled (rid=%04x)\n",
  3573. __FUNCTION__, rid);
  3574. memset(&cmd, 0, sizeof(cmd));
  3575. memset(&rsp, 0, sizeof(rsp));
  3576. ai->config_desc.rid_desc.valid = 1;
  3577. ai->config_desc.rid_desc.len = *((u16 *)pBuf);
  3578. ai->config_desc.rid_desc.rid = 0;
  3579. cmd.cmd = CMD_WRITERID;
  3580. cmd.parm0 = rid;
  3581. memcpy_toio(ai->config_desc.card_ram_off,
  3582. &ai->config_desc.rid_desc, sizeof(Rid));
  3583. if (len < 4 || len > 2047) {
  3584. printk(KERN_ERR "%s: len=%d\n",__FUNCTION__,len);
  3585. rc = -1;
  3586. } else {
  3587. memcpy((char *)ai->config_desc.virtual_host_addr,
  3588. pBuf, len);
  3589. rc = issuecommand(ai, &cmd, &rsp);
  3590. if ((rc & 0xff00) != 0) {
  3591. printk(KERN_ERR "%s: Write rid Error %d\n",
  3592. __FUNCTION__,rc);
  3593. printk(KERN_ERR "%s: Cmd=%04x\n",
  3594. __FUNCTION__,cmd.cmd);
  3595. }
  3596. if ((rsp.status & 0x7f00))
  3597. rc = rsp.rsp0;
  3598. }
  3599. } else {
  3600. // --- first access so that we can write the rid data
  3601. if ( (status = PC4500_accessrid(ai, rid, CMD_ACCESS)) != 0) {
  3602. rc = status;
  3603. goto done;
  3604. }
  3605. // --- now write the rid data
  3606. if (bap_setup(ai, rid, 0, BAP1) != SUCCESS) {
  3607. rc = ERROR;
  3608. goto done;
  3609. }
  3610. bap_write(ai, pBuf, len, BAP1);
  3611. // ---now commit the rid data
  3612. rc = PC4500_accessrid(ai, rid, 0x100|CMD_ACCESS);
  3613. }
  3614. done:
  3615. if (lock)
  3616. up(&ai->sem);
  3617. return rc;
  3618. }
  3619. /* Allocates a FID to be used for transmitting packets. We only use
  3620. one for now. */
  3621. static u16 transmit_allocate(struct airo_info *ai, int lenPayload, int raw)
  3622. {
  3623. unsigned int loop = 3000;
  3624. Cmd cmd;
  3625. Resp rsp;
  3626. u16 txFid;
  3627. u16 txControl;
  3628. cmd.cmd = CMD_ALLOCATETX;
  3629. cmd.parm0 = lenPayload;
  3630. if (down_interruptible(&ai->sem))
  3631. return ERROR;
  3632. if (issuecommand(ai, &cmd, &rsp) != SUCCESS) {
  3633. txFid = ERROR;
  3634. goto done;
  3635. }
  3636. if ( (rsp.status & 0xFF00) != 0) {
  3637. txFid = ERROR;
  3638. goto done;
  3639. }
  3640. /* wait for the allocate event/indication
  3641. * It makes me kind of nervous that this can just sit here and spin,
  3642. * but in practice it only loops like four times. */
  3643. while (((IN4500(ai, EVSTAT) & EV_ALLOC) == 0) && --loop);
  3644. if (!loop) {
  3645. txFid = ERROR;
  3646. goto done;
  3647. }
  3648. // get the allocated fid and acknowledge
  3649. txFid = IN4500(ai, TXALLOCFID);
  3650. OUT4500(ai, EVACK, EV_ALLOC);
  3651. /* The CARD is pretty cool since it converts the ethernet packet
  3652. * into 802.11. Also note that we don't release the FID since we
  3653. * will be using the same one over and over again. */
  3654. /* We only have to setup the control once since we are not
  3655. * releasing the fid. */
  3656. if (raw)
  3657. txControl = cpu_to_le16(TXCTL_TXOK | TXCTL_TXEX | TXCTL_802_11
  3658. | TXCTL_ETHERNET | TXCTL_NORELEASE);
  3659. else
  3660. txControl = cpu_to_le16(TXCTL_TXOK | TXCTL_TXEX | TXCTL_802_3
  3661. | TXCTL_ETHERNET | TXCTL_NORELEASE);
  3662. if (bap_setup(ai, txFid, 0x0008, BAP1) != SUCCESS)
  3663. txFid = ERROR;
  3664. else
  3665. bap_write(ai, &txControl, sizeof(txControl), BAP1);
  3666. done:
  3667. up(&ai->sem);
  3668. return txFid;
  3669. }
  3670. /* In general BAP1 is dedicated to transmiting packets. However,
  3671. since we need a BAP when accessing RIDs, we also use BAP1 for that.
  3672. Make sure the BAP1 spinlock is held when this is called. */
  3673. static int transmit_802_3_packet(struct airo_info *ai, int len, char *pPacket)
  3674. {
  3675. u16 payloadLen;
  3676. Cmd cmd;
  3677. Resp rsp;
  3678. int miclen = 0;
  3679. u16 txFid = len;
  3680. MICBuffer pMic;
  3681. len >>= 16;
  3682. if (len <= ETH_ALEN * 2) {
  3683. printk( KERN_WARNING "Short packet %d\n", len );
  3684. return ERROR;
  3685. }
  3686. len -= ETH_ALEN * 2;
  3687. #ifdef MICSUPPORT
  3688. if (test_bit(FLAG_MIC_CAPABLE, &ai->flags) && ai->micstats.enabled &&
  3689. (ntohs(((u16 *)pPacket)[6]) != 0x888E)) {
  3690. if (encapsulate(ai,(etherHead *)pPacket,&pMic,len) != SUCCESS)
  3691. return ERROR;
  3692. miclen = sizeof(pMic);
  3693. }
  3694. #endif
  3695. // packet is destination[6], source[6], payload[len-12]
  3696. // write the payload length and dst/src/payload
  3697. if (bap_setup(ai, txFid, 0x0036, BAP1) != SUCCESS) return ERROR;
  3698. /* The hardware addresses aren't counted as part of the payload, so
  3699. * we have to subtract the 12 bytes for the addresses off */
  3700. payloadLen = cpu_to_le16(len + miclen);
  3701. bap_write(ai, &payloadLen, sizeof(payloadLen),BAP1);
  3702. bap_write(ai, (const u16*)pPacket, sizeof(etherHead), BAP1);
  3703. if (miclen)
  3704. bap_write(ai, (const u16*)&pMic, miclen, BAP1);
  3705. bap_write(ai, (const u16*)(pPacket + sizeof(etherHead)), len, BAP1);
  3706. // issue the transmit command
  3707. memset( &cmd, 0, sizeof( cmd ) );
  3708. cmd.cmd = CMD_TRANSMIT;
  3709. cmd.parm0 = txFid;
  3710. if (issuecommand(ai, &cmd, &rsp) != SUCCESS) return ERROR;
  3711. if ( (rsp.status & 0xFF00) != 0) return ERROR;
  3712. return SUCCESS;
  3713. }
  3714. static int transmit_802_11_packet(struct airo_info *ai, int len, char *pPacket)
  3715. {
  3716. u16 fc, payloadLen;
  3717. Cmd cmd;
  3718. Resp rsp;
  3719. int hdrlen;
  3720. struct {
  3721. u8 addr4[ETH_ALEN];
  3722. u16 gaplen;
  3723. u8 gap[6];
  3724. } gap;
  3725. u16 txFid = len;
  3726. len >>= 16;
  3727. gap.gaplen = 6;
  3728. fc = le16_to_cpu(*(const u16*)pPacket);
  3729. switch (fc & 0xc) {
  3730. case 4:
  3731. if ((fc & 0xe0) == 0xc0)
  3732. hdrlen = 10;
  3733. else
  3734. hdrlen = 16;
  3735. break;
  3736. case 8:
  3737. if ((fc&0x300)==0x300){
  3738. hdrlen = 30;
  3739. break;
  3740. }
  3741. default:
  3742. hdrlen = 24;
  3743. }
  3744. if (len < hdrlen) {
  3745. printk( KERN_WARNING "Short packet %d\n", len );
  3746. return ERROR;
  3747. }
  3748. /* packet is 802.11 header + payload
  3749. * write the payload length and dst/src/payload */
  3750. if (bap_setup(ai, txFid, 6, BAP1) != SUCCESS) return ERROR;
  3751. /* The 802.11 header aren't counted as part of the payload, so
  3752. * we have to subtract the header bytes off */
  3753. payloadLen = cpu_to_le16(len-hdrlen);
  3754. bap_write(ai, &payloadLen, sizeof(payloadLen),BAP1);
  3755. if (bap_setup(ai, txFid, 0x0014, BAP1) != SUCCESS) return ERROR;
  3756. bap_write(ai, (const u16*)pPacket, hdrlen, BAP1);
  3757. bap_write(ai, hdrlen == 30 ?
  3758. (const u16*)&gap.gaplen : (const u16*)&gap, 38 - hdrlen, BAP1);
  3759. bap_write(ai, (const u16*)(pPacket + hdrlen), len - hdrlen, BAP1);
  3760. // issue the transmit command
  3761. memset( &cmd, 0, sizeof( cmd ) );
  3762. cmd.cmd = CMD_TRANSMIT;
  3763. cmd.parm0 = txFid;
  3764. if (issuecommand(ai, &cmd, &rsp) != SUCCESS) return ERROR;
  3765. if ( (rsp.status & 0xFF00) != 0) return ERROR;
  3766. return SUCCESS;
  3767. }
  3768. /*
  3769. * This is the proc_fs routines. It is a bit messier than I would
  3770. * like! Feel free to clean it up!
  3771. */
  3772. static ssize_t proc_read( struct file *file,
  3773. char __user *buffer,
  3774. size_t len,
  3775. loff_t *offset);
  3776. static ssize_t proc_write( struct file *file,
  3777. const char __user *buffer,
  3778. size_t len,
  3779. loff_t *offset );
  3780. static int proc_close( struct inode *inode, struct file *file );
  3781. static int proc_stats_open( struct inode *inode, struct file *file );
  3782. static int proc_statsdelta_open( struct inode *inode, struct file *file );
  3783. static int proc_status_open( struct inode *inode, struct file *file );
  3784. static int proc_SSID_open( struct inode *inode, struct file *file );
  3785. static int proc_APList_open( struct inode *inode, struct file *file );
  3786. static int proc_BSSList_open( struct inode *inode, struct file *file );
  3787. static int proc_config_open( struct inode *inode, struct file *file );
  3788. static int proc_wepkey_open( struct inode *inode, struct file *file );
  3789. static struct file_operations proc_statsdelta_ops = {
  3790. .read = proc_read,
  3791. .open = proc_statsdelta_open,
  3792. .release = proc_close
  3793. };
  3794. static struct file_operations proc_stats_ops = {
  3795. .read = proc_read,
  3796. .open = proc_stats_open,
  3797. .release = proc_close
  3798. };
  3799. static struct file_operations proc_status_ops = {
  3800. .read = proc_read,
  3801. .open = proc_status_open,
  3802. .release = proc_close
  3803. };
  3804. static struct file_operations proc_SSID_ops = {
  3805. .read = proc_read,
  3806. .write = proc_write,
  3807. .open = proc_SSID_open,
  3808. .release = proc_close
  3809. };
  3810. static struct file_operations proc_BSSList_ops = {
  3811. .read = proc_read,
  3812. .write = proc_write,
  3813. .open = proc_BSSList_open,
  3814. .release = proc_close
  3815. };
  3816. static struct file_operations proc_APList_ops = {
  3817. .read = proc_read,
  3818. .write = proc_write,
  3819. .open = proc_APList_open,
  3820. .release = proc_close
  3821. };
  3822. static struct file_operations proc_config_ops = {
  3823. .read = proc_read,
  3824. .write = proc_write,
  3825. .open = proc_config_open,
  3826. .release = proc_close
  3827. };
  3828. static struct file_operations proc_wepkey_ops = {
  3829. .read = proc_read,
  3830. .write = proc_write,
  3831. .open = proc_wepkey_open,
  3832. .release = proc_close
  3833. };
  3834. static struct proc_dir_entry *airo_entry;
  3835. struct proc_data {
  3836. int release_buffer;
  3837. int readlen;
  3838. char *rbuffer;
  3839. int writelen;
  3840. int maxwritelen;
  3841. char *wbuffer;
  3842. void (*on_close) (struct inode *, struct file *);
  3843. };
  3844. #ifndef SETPROC_OPS
  3845. #define SETPROC_OPS(entry, ops) (entry)->proc_fops = &(ops)
  3846. #endif
  3847. static int setup_proc_entry( struct net_device *dev,
  3848. struct airo_info *apriv ) {
  3849. struct proc_dir_entry *entry;
  3850. /* First setup the device directory */
  3851. strcpy(apriv->proc_name,dev->name);
  3852. apriv->proc_entry = create_proc_entry(apriv->proc_name,
  3853. S_IFDIR|airo_perm,
  3854. airo_entry);
  3855. apriv->proc_entry->uid = proc_uid;
  3856. apriv->proc_entry->gid = proc_gid;
  3857. apriv->proc_entry->owner = THIS_MODULE;
  3858. /* Setup the StatsDelta */
  3859. entry = create_proc_entry("StatsDelta",
  3860. S_IFREG | (S_IRUGO&proc_perm),
  3861. apriv->proc_entry);
  3862. entry->uid = proc_uid;
  3863. entry->gid = proc_gid;
  3864. entry->data = dev;
  3865. entry->owner = THIS_MODULE;
  3866. SETPROC_OPS(entry, proc_statsdelta_ops);
  3867. /* Setup the Stats */
  3868. entry = create_proc_entry("Stats",
  3869. S_IFREG | (S_IRUGO&proc_perm),
  3870. apriv->proc_entry);
  3871. entry->uid = proc_uid;
  3872. entry->gid = proc_gid;
  3873. entry->data = dev;
  3874. entry->owner = THIS_MODULE;
  3875. SETPROC_OPS(entry, proc_stats_ops);
  3876. /* Setup the Status */
  3877. entry = create_proc_entry("Status",
  3878. S_IFREG | (S_IRUGO&proc_perm),
  3879. apriv->proc_entry);
  3880. entry->uid = proc_uid;
  3881. entry->gid = proc_gid;
  3882. entry->data = dev;
  3883. entry->owner = THIS_MODULE;
  3884. SETPROC_OPS(entry, proc_status_ops);
  3885. /* Setup the Config */
  3886. entry = create_proc_entry("Config",
  3887. S_IFREG | proc_perm,
  3888. apriv->proc_entry);
  3889. entry->uid = proc_uid;
  3890. entry->gid = proc_gid;
  3891. entry->data = dev;
  3892. entry->owner = THIS_MODULE;
  3893. SETPROC_OPS(entry, proc_config_ops);
  3894. /* Setup the SSID */
  3895. entry = create_proc_entry("SSID",
  3896. S_IFREG | proc_perm,
  3897. apriv->proc_entry);
  3898. entry->uid = proc_uid;
  3899. entry->gid = proc_gid;
  3900. entry->data = dev;
  3901. entry->owner = THIS_MODULE;
  3902. SETPROC_OPS(entry, proc_SSID_ops);
  3903. /* Setup the APList */
  3904. entry = create_proc_entry("APList",
  3905. S_IFREG | proc_perm,
  3906. apriv->proc_entry);
  3907. entry->uid = proc_uid;
  3908. entry->gid = proc_gid;
  3909. entry->data = dev;
  3910. entry->owner = THIS_MODULE;
  3911. SETPROC_OPS(entry, proc_APList_ops);
  3912. /* Setup the BSSList */
  3913. entry = create_proc_entry("BSSList",
  3914. S_IFREG | proc_perm,
  3915. apriv->proc_entry);
  3916. entry->uid = proc_uid;
  3917. entry->gid = proc_gid;
  3918. entry->data = dev;
  3919. entry->owner = THIS_MODULE;
  3920. SETPROC_OPS(entry, proc_BSSList_ops);
  3921. /* Setup the WepKey */
  3922. entry = create_proc_entry("WepKey",
  3923. S_IFREG | proc_perm,
  3924. apriv->proc_entry);
  3925. entry->uid = proc_uid;
  3926. entry->gid = proc_gid;
  3927. entry->data = dev;
  3928. entry->owner = THIS_MODULE;
  3929. SETPROC_OPS(entry, proc_wepkey_ops);
  3930. return 0;
  3931. }
  3932. static int takedown_proc_entry( struct net_device *dev,
  3933. struct airo_info *apriv ) {
  3934. if ( !apriv->proc_entry->namelen ) return 0;
  3935. remove_proc_entry("Stats",apriv->proc_entry);
  3936. remove_proc_entry("StatsDelta",apriv->proc_entry);
  3937. remove_proc_entry("Status",apriv->proc_entry);
  3938. remove_proc_entry("Config",apriv->proc_entry);
  3939. remove_proc_entry("SSID",apriv->proc_entry);
  3940. remove_proc_entry("APList",apriv->proc_entry);
  3941. remove_proc_entry("BSSList",apriv->proc_entry);
  3942. remove_proc_entry("WepKey",apriv->proc_entry);
  3943. remove_proc_entry(apriv->proc_name,airo_entry);
  3944. return 0;
  3945. }
  3946. /*
  3947. * What we want from the proc_fs is to be able to efficiently read
  3948. * and write the configuration. To do this, we want to read the
  3949. * configuration when the file is opened and write it when the file is
  3950. * closed. So basically we allocate a read buffer at open and fill it
  3951. * with data, and allocate a write buffer and read it at close.
  3952. */
  3953. /*
  3954. * The read routine is generic, it relies on the preallocated rbuffer
  3955. * to supply the data.
  3956. */
  3957. static ssize_t proc_read( struct file *file,
  3958. char __user *buffer,
  3959. size_t len,
  3960. loff_t *offset )
  3961. {
  3962. loff_t pos = *offset;
  3963. struct proc_data *priv = (struct proc_data*)file->private_data;
  3964. if (!priv->rbuffer)
  3965. return -EINVAL;
  3966. if (pos < 0)
  3967. return -EINVAL;
  3968. if (pos >= priv->readlen)
  3969. return 0;
  3970. if (len > priv->readlen - pos)
  3971. len = priv->readlen - pos;
  3972. if (copy_to_user(buffer, priv->rbuffer + pos, len))
  3973. return -EFAULT;
  3974. *offset = pos + len;
  3975. return len;
  3976. }
  3977. /*
  3978. * The write routine is generic, it fills in a preallocated rbuffer
  3979. * to supply the data.
  3980. */
  3981. static ssize_t proc_write( struct file *file,
  3982. const char __user *buffer,
  3983. size_t len,
  3984. loff_t *offset )
  3985. {
  3986. loff_t pos = *offset;
  3987. struct proc_data *priv = (struct proc_data*)file->private_data;
  3988. if (!priv->wbuffer)
  3989. return -EINVAL;
  3990. if (pos < 0)
  3991. return -EINVAL;
  3992. if (pos >= priv->maxwritelen)
  3993. return 0;
  3994. if (len > priv->maxwritelen - pos)
  3995. len = priv->maxwritelen - pos;
  3996. if (copy_from_user(priv->wbuffer + pos, buffer, len))
  3997. return -EFAULT;
  3998. if ( pos + len > priv->writelen )
  3999. priv->writelen = len + file->f_pos;
  4000. *offset = pos + len;
  4001. return len;
  4002. }
  4003. static int proc_status_open( struct inode *inode, struct file *file ) {
  4004. struct proc_data *data;
  4005. struct proc_dir_entry *dp = PDE(inode);
  4006. struct net_device *dev = dp->data;
  4007. struct airo_info *apriv = dev->priv;
  4008. CapabilityRid cap_rid;
  4009. StatusRid status_rid;
  4010. int i;
  4011. if ((file->private_data = kzalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
  4012. return -ENOMEM;
  4013. data = (struct proc_data *)file->private_data;
  4014. if ((data->rbuffer = kmalloc( 2048, GFP_KERNEL )) == NULL) {
  4015. kfree (file->private_data);
  4016. return -ENOMEM;
  4017. }
  4018. readStatusRid(apriv, &status_rid, 1);
  4019. readCapabilityRid(apriv, &cap_rid, 1);
  4020. i = sprintf(data->rbuffer, "Status: %s%s%s%s%s%s%s%s%s\n",
  4021. status_rid.mode & 1 ? "CFG ": "",
  4022. status_rid.mode & 2 ? "ACT ": "",
  4023. status_rid.mode & 0x10 ? "SYN ": "",
  4024. status_rid.mode & 0x20 ? "LNK ": "",
  4025. status_rid.mode & 0x40 ? "LEAP ": "",
  4026. status_rid.mode & 0x80 ? "PRIV ": "",
  4027. status_rid.mode & 0x100 ? "KEY ": "",
  4028. status_rid.mode & 0x200 ? "WEP ": "",
  4029. status_rid.mode & 0x8000 ? "ERR ": "");
  4030. sprintf( data->rbuffer+i, "Mode: %x\n"
  4031. "Signal Strength: %d\n"
  4032. "Signal Quality: %d\n"
  4033. "SSID: %-.*s\n"
  4034. "AP: %-.16s\n"
  4035. "Freq: %d\n"
  4036. "BitRate: %dmbs\n"
  4037. "Driver Version: %s\n"
  4038. "Device: %s\nManufacturer: %s\nFirmware Version: %s\n"
  4039. "Radio type: %x\nCountry: %x\nHardware Version: %x\n"
  4040. "Software Version: %x\nSoftware Subversion: %x\n"
  4041. "Boot block version: %x\n",
  4042. (int)status_rid.mode,
  4043. (int)status_rid.normalizedSignalStrength,
  4044. (int)status_rid.signalQuality,
  4045. (int)status_rid.SSIDlen,
  4046. status_rid.SSID,
  4047. status_rid.apName,
  4048. (int)status_rid.channel,
  4049. (int)status_rid.currentXmitRate/2,
  4050. version,
  4051. cap_rid.prodName,
  4052. cap_rid.manName,
  4053. cap_rid.prodVer,
  4054. cap_rid.radioType,
  4055. cap_rid.country,
  4056. cap_rid.hardVer,
  4057. (int)cap_rid.softVer,
  4058. (int)cap_rid.softSubVer,
  4059. (int)cap_rid.bootBlockVer );
  4060. data->readlen = strlen( data->rbuffer );
  4061. return 0;
  4062. }
  4063. static int proc_stats_rid_open(struct inode*, struct file*, u16);
  4064. static int proc_statsdelta_open( struct inode *inode,
  4065. struct file *file ) {
  4066. if (file->f_mode&FMODE_WRITE) {
  4067. return proc_stats_rid_open(inode, file, RID_STATSDELTACLEAR);
  4068. }
  4069. return proc_stats_rid_open(inode, file, RID_STATSDELTA);
  4070. }
  4071. static int proc_stats_open( struct inode *inode, struct file *file ) {
  4072. return proc_stats_rid_open(inode, file, RID_STATS);
  4073. }
  4074. static int proc_stats_rid_open( struct inode *inode,
  4075. struct file *file,
  4076. u16 rid ) {
  4077. struct proc_data *data;
  4078. struct proc_dir_entry *dp = PDE(inode);
  4079. struct net_device *dev = dp->data;
  4080. struct airo_info *apriv = dev->priv;
  4081. StatsRid stats;
  4082. int i, j;
  4083. u32 *vals = stats.vals;
  4084. if ((file->private_data = kzalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
  4085. return -ENOMEM;
  4086. data = (struct proc_data *)file->private_data;
  4087. if ((data->rbuffer = kmalloc( 4096, GFP_KERNEL )) == NULL) {
  4088. kfree (file->private_data);
  4089. return -ENOMEM;
  4090. }
  4091. readStatsRid(apriv, &stats, rid, 1);
  4092. j = 0;
  4093. for(i=0; statsLabels[i]!=(char *)-1 &&
  4094. i*4<stats.len; i++){
  4095. if (!statsLabels[i]) continue;
  4096. if (j+strlen(statsLabels[i])+16>4096) {
  4097. printk(KERN_WARNING
  4098. "airo: Potentially disasterous buffer overflow averted!\n");
  4099. break;
  4100. }
  4101. j+=sprintf(data->rbuffer+j, "%s: %u\n", statsLabels[i], vals[i]);
  4102. }
  4103. if (i*4>=stats.len){
  4104. printk(KERN_WARNING
  4105. "airo: Got a short rid\n");
  4106. }
  4107. data->readlen = j;
  4108. return 0;
  4109. }
  4110. static int get_dec_u16( char *buffer, int *start, int limit ) {
  4111. u16 value;
  4112. int valid = 0;
  4113. for( value = 0; buffer[*start] >= '0' &&
  4114. buffer[*start] <= '9' &&
  4115. *start < limit; (*start)++ ) {
  4116. valid = 1;
  4117. value *= 10;
  4118. value += buffer[*start] - '0';
  4119. }
  4120. if ( !valid ) return -1;
  4121. return value;
  4122. }
  4123. static int airo_config_commit(struct net_device *dev,
  4124. struct iw_request_info *info, void *zwrq,
  4125. char *extra);
  4126. static void proc_config_on_close( struct inode *inode, struct file *file ) {
  4127. struct proc_data *data = file->private_data;
  4128. struct proc_dir_entry *dp = PDE(inode);
  4129. struct net_device *dev = dp->data;
  4130. struct airo_info *ai = dev->priv;
  4131. char *line;
  4132. if ( !data->writelen ) return;
  4133. readConfigRid(ai, 1);
  4134. set_bit (FLAG_COMMIT, &ai->flags);
  4135. line = data->wbuffer;
  4136. while( line[0] ) {
  4137. /*** Mode processing */
  4138. if ( !strncmp( line, "Mode: ", 6 ) ) {
  4139. line += 6;
  4140. if ((ai->config.rmode & 0xff) >= RXMODE_RFMON)
  4141. set_bit (FLAG_RESET, &ai->flags);
  4142. ai->config.rmode &= 0xfe00;
  4143. clear_bit (FLAG_802_11, &ai->flags);
  4144. ai->config.opmode &= 0xFF00;
  4145. ai->config.scanMode = SCANMODE_ACTIVE;
  4146. if ( line[0] == 'a' ) {
  4147. ai->config.opmode |= 0;
  4148. } else {
  4149. ai->config.opmode |= 1;
  4150. if ( line[0] == 'r' ) {
  4151. ai->config.rmode |= RXMODE_RFMON | RXMODE_DISABLE_802_3_HEADER;
  4152. ai->config.scanMode = SCANMODE_PASSIVE;
  4153. set_bit (FLAG_802_11, &ai->flags);
  4154. } else if ( line[0] == 'y' ) {
  4155. ai->config.rmode |= RXMODE_RFMON_ANYBSS | RXMODE_DISABLE_802_3_HEADER;
  4156. ai->config.scanMode = SCANMODE_PASSIVE;
  4157. set_bit (FLAG_802_11, &ai->flags);
  4158. } else if ( line[0] == 'l' )
  4159. ai->config.rmode |= RXMODE_LANMON;
  4160. }
  4161. set_bit (FLAG_COMMIT, &ai->flags);
  4162. }
  4163. /*** Radio status */
  4164. else if (!strncmp(line,"Radio: ", 7)) {
  4165. line += 7;
  4166. if (!strncmp(line,"off",3)) {
  4167. set_bit (FLAG_RADIO_OFF, &ai->flags);
  4168. } else {
  4169. clear_bit (FLAG_RADIO_OFF, &ai->flags);
  4170. }
  4171. }
  4172. /*** NodeName processing */
  4173. else if ( !strncmp( line, "NodeName: ", 10 ) ) {
  4174. int j;
  4175. line += 10;
  4176. memset( ai->config.nodeName, 0, 16 );
  4177. /* Do the name, assume a space between the mode and node name */
  4178. for( j = 0; j < 16 && line[j] != '\n'; j++ ) {
  4179. ai->config.nodeName[j] = line[j];
  4180. }
  4181. set_bit (FLAG_COMMIT, &ai->flags);
  4182. }
  4183. /*** PowerMode processing */
  4184. else if ( !strncmp( line, "PowerMode: ", 11 ) ) {
  4185. line += 11;
  4186. if ( !strncmp( line, "PSPCAM", 6 ) ) {
  4187. ai->config.powerSaveMode = POWERSAVE_PSPCAM;
  4188. set_bit (FLAG_COMMIT, &ai->flags);
  4189. } else if ( !strncmp( line, "PSP", 3 ) ) {
  4190. ai->config.powerSaveMode = POWERSAVE_PSP;
  4191. set_bit (FLAG_COMMIT, &ai->flags);
  4192. } else {
  4193. ai->config.powerSaveMode = POWERSAVE_CAM;
  4194. set_bit (FLAG_COMMIT, &ai->flags);
  4195. }
  4196. } else if ( !strncmp( line, "DataRates: ", 11 ) ) {
  4197. int v, i = 0, k = 0; /* i is index into line,
  4198. k is index to rates */
  4199. line += 11;
  4200. while((v = get_dec_u16(line, &i, 3))!=-1) {
  4201. ai->config.rates[k++] = (u8)v;
  4202. line += i + 1;
  4203. i = 0;
  4204. }
  4205. set_bit (FLAG_COMMIT, &ai->flags);
  4206. } else if ( !strncmp( line, "Channel: ", 9 ) ) {
  4207. int v, i = 0;
  4208. line += 9;
  4209. v = get_dec_u16(line, &i, i+3);
  4210. if ( v != -1 ) {
  4211. ai->config.channelSet = (u16)v;
  4212. set_bit (FLAG_COMMIT, &ai->flags);
  4213. }
  4214. } else if ( !strncmp( line, "XmitPower: ", 11 ) ) {
  4215. int v, i = 0;
  4216. line += 11;
  4217. v = get_dec_u16(line, &i, i+3);
  4218. if ( v != -1 ) {
  4219. ai->config.txPower = (u16)v;
  4220. set_bit (FLAG_COMMIT, &ai->flags);
  4221. }
  4222. } else if ( !strncmp( line, "WEP: ", 5 ) ) {
  4223. line += 5;
  4224. switch( line[0] ) {
  4225. case 's':
  4226. ai->config.authType = (u16)AUTH_SHAREDKEY;
  4227. break;
  4228. case 'e':
  4229. ai->config.authType = (u16)AUTH_ENCRYPT;
  4230. break;
  4231. default:
  4232. ai->config.authType = (u16)AUTH_OPEN;
  4233. break;
  4234. }
  4235. set_bit (FLAG_COMMIT, &ai->flags);
  4236. } else if ( !strncmp( line, "LongRetryLimit: ", 16 ) ) {
  4237. int v, i = 0;
  4238. line += 16;
  4239. v = get_dec_u16(line, &i, 3);
  4240. v = (v<0) ? 0 : ((v>255) ? 255 : v);
  4241. ai->config.longRetryLimit = (u16)v;
  4242. set_bit (FLAG_COMMIT, &ai->flags);
  4243. } else if ( !strncmp( line, "ShortRetryLimit: ", 17 ) ) {
  4244. int v, i = 0;
  4245. line += 17;
  4246. v = get_dec_u16(line, &i, 3);
  4247. v = (v<0) ? 0 : ((v>255) ? 255 : v);
  4248. ai->config.shortRetryLimit = (u16)v;
  4249. set_bit (FLAG_COMMIT, &ai->flags);
  4250. } else if ( !strncmp( line, "RTSThreshold: ", 14 ) ) {
  4251. int v, i = 0;
  4252. line += 14;
  4253. v = get_dec_u16(line, &i, 4);
  4254. v = (v<0) ? 0 : ((v>2312) ? 2312 : v);
  4255. ai->config.rtsThres = (u16)v;
  4256. set_bit (FLAG_COMMIT, &ai->flags);
  4257. } else if ( !strncmp( line, "TXMSDULifetime: ", 16 ) ) {
  4258. int v, i = 0;
  4259. line += 16;
  4260. v = get_dec_u16(line, &i, 5);
  4261. v = (v<0) ? 0 : v;
  4262. ai->config.txLifetime = (u16)v;
  4263. set_bit (FLAG_COMMIT, &ai->flags);
  4264. } else if ( !strncmp( line, "RXMSDULifetime: ", 16 ) ) {
  4265. int v, i = 0;
  4266. line += 16;
  4267. v = get_dec_u16(line, &i, 5);
  4268. v = (v<0) ? 0 : v;
  4269. ai->config.rxLifetime = (u16)v;
  4270. set_bit (FLAG_COMMIT, &ai->flags);
  4271. } else if ( !strncmp( line, "TXDiversity: ", 13 ) ) {
  4272. ai->config.txDiversity =
  4273. (line[13]=='l') ? 1 :
  4274. ((line[13]=='r')? 2: 3);
  4275. set_bit (FLAG_COMMIT, &ai->flags);
  4276. } else if ( !strncmp( line, "RXDiversity: ", 13 ) ) {
  4277. ai->config.rxDiversity =
  4278. (line[13]=='l') ? 1 :
  4279. ((line[13]=='r')? 2: 3);
  4280. set_bit (FLAG_COMMIT, &ai->flags);
  4281. } else if ( !strncmp( line, "FragThreshold: ", 15 ) ) {
  4282. int v, i = 0;
  4283. line += 15;
  4284. v = get_dec_u16(line, &i, 4);
  4285. v = (v<256) ? 256 : ((v>2312) ? 2312 : v);
  4286. v = v & 0xfffe; /* Make sure its even */
  4287. ai->config.fragThresh = (u16)v;
  4288. set_bit (FLAG_COMMIT, &ai->flags);
  4289. } else if (!strncmp(line, "Modulation: ", 12)) {
  4290. line += 12;
  4291. switch(*line) {
  4292. case 'd': ai->config.modulation=MOD_DEFAULT; set_bit(FLAG_COMMIT, &ai->flags); break;
  4293. case 'c': ai->config.modulation=MOD_CCK; set_bit(FLAG_COMMIT, &ai->flags); break;
  4294. case 'm': ai->config.modulation=MOD_MOK; set_bit(FLAG_COMMIT, &ai->flags); break;
  4295. default:
  4296. printk( KERN_WARNING "airo: Unknown modulation\n" );
  4297. }
  4298. } else if (!strncmp(line, "Preamble: ", 10)) {
  4299. line += 10;
  4300. switch(*line) {
  4301. case 'a': ai->config.preamble=PREAMBLE_AUTO; set_bit(FLAG_COMMIT, &ai->flags); break;
  4302. case 'l': ai->config.preamble=PREAMBLE_LONG; set_bit(FLAG_COMMIT, &ai->flags); break;
  4303. case 's': ai->config.preamble=PREAMBLE_SHORT; set_bit(FLAG_COMMIT, &ai->flags); break;
  4304. default: printk(KERN_WARNING "airo: Unknown preamble\n");
  4305. }
  4306. } else {
  4307. printk( KERN_WARNING "Couldn't figure out %s\n", line );
  4308. }
  4309. while( line[0] && line[0] != '\n' ) line++;
  4310. if ( line[0] ) line++;
  4311. }
  4312. airo_config_commit(dev, NULL, NULL, NULL);
  4313. }
  4314. static char *get_rmode(u16 mode) {
  4315. switch(mode&0xff) {
  4316. case RXMODE_RFMON: return "rfmon";
  4317. case RXMODE_RFMON_ANYBSS: return "yna (any) bss rfmon";
  4318. case RXMODE_LANMON: return "lanmon";
  4319. }
  4320. return "ESS";
  4321. }
  4322. static int proc_config_open( struct inode *inode, struct file *file ) {
  4323. struct proc_data *data;
  4324. struct proc_dir_entry *dp = PDE(inode);
  4325. struct net_device *dev = dp->data;
  4326. struct airo_info *ai = dev->priv;
  4327. int i;
  4328. if ((file->private_data = kzalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
  4329. return -ENOMEM;
  4330. data = (struct proc_data *)file->private_data;
  4331. if ((data->rbuffer = kmalloc( 2048, GFP_KERNEL )) == NULL) {
  4332. kfree (file->private_data);
  4333. return -ENOMEM;
  4334. }
  4335. if ((data->wbuffer = kzalloc( 2048, GFP_KERNEL )) == NULL) {
  4336. kfree (data->rbuffer);
  4337. kfree (file->private_data);
  4338. return -ENOMEM;
  4339. }
  4340. data->maxwritelen = 2048;
  4341. data->on_close = proc_config_on_close;
  4342. readConfigRid(ai, 1);
  4343. i = sprintf( data->rbuffer,
  4344. "Mode: %s\n"
  4345. "Radio: %s\n"
  4346. "NodeName: %-16s\n"
  4347. "PowerMode: %s\n"
  4348. "DataRates: %d %d %d %d %d %d %d %d\n"
  4349. "Channel: %d\n"
  4350. "XmitPower: %d\n",
  4351. (ai->config.opmode & 0xFF) == 0 ? "adhoc" :
  4352. (ai->config.opmode & 0xFF) == 1 ? get_rmode(ai->config.rmode):
  4353. (ai->config.opmode & 0xFF) == 2 ? "AP" :
  4354. (ai->config.opmode & 0xFF) == 3 ? "AP RPTR" : "Error",
  4355. test_bit(FLAG_RADIO_OFF, &ai->flags) ? "off" : "on",
  4356. ai->config.nodeName,
  4357. ai->config.powerSaveMode == 0 ? "CAM" :
  4358. ai->config.powerSaveMode == 1 ? "PSP" :
  4359. ai->config.powerSaveMode == 2 ? "PSPCAM" : "Error",
  4360. (int)ai->config.rates[0],
  4361. (int)ai->config.rates[1],
  4362. (int)ai->config.rates[2],
  4363. (int)ai->config.rates[3],
  4364. (int)ai->config.rates[4],
  4365. (int)ai->config.rates[5],
  4366. (int)ai->config.rates[6],
  4367. (int)ai->config.rates[7],
  4368. (int)ai->config.channelSet,
  4369. (int)ai->config.txPower
  4370. );
  4371. sprintf( data->rbuffer + i,
  4372. "LongRetryLimit: %d\n"
  4373. "ShortRetryLimit: %d\n"
  4374. "RTSThreshold: %d\n"
  4375. "TXMSDULifetime: %d\n"
  4376. "RXMSDULifetime: %d\n"
  4377. "TXDiversity: %s\n"
  4378. "RXDiversity: %s\n"
  4379. "FragThreshold: %d\n"
  4380. "WEP: %s\n"
  4381. "Modulation: %s\n"
  4382. "Preamble: %s\n",
  4383. (int)ai->config.longRetryLimit,
  4384. (int)ai->config.shortRetryLimit,
  4385. (int)ai->config.rtsThres,
  4386. (int)ai->config.txLifetime,
  4387. (int)ai->config.rxLifetime,
  4388. ai->config.txDiversity == 1 ? "left" :
  4389. ai->config.txDiversity == 2 ? "right" : "both",
  4390. ai->config.rxDiversity == 1 ? "left" :
  4391. ai->config.rxDiversity == 2 ? "right" : "both",
  4392. (int)ai->config.fragThresh,
  4393. ai->config.authType == AUTH_ENCRYPT ? "encrypt" :
  4394. ai->config.authType == AUTH_SHAREDKEY ? "shared" : "open",
  4395. ai->config.modulation == 0 ? "default" :
  4396. ai->config.modulation == MOD_CCK ? "cck" :
  4397. ai->config.modulation == MOD_MOK ? "mok" : "error",
  4398. ai->config.preamble == PREAMBLE_AUTO ? "auto" :
  4399. ai->config.preamble == PREAMBLE_LONG ? "long" :
  4400. ai->config.preamble == PREAMBLE_SHORT ? "short" : "error"
  4401. );
  4402. data->readlen = strlen( data->rbuffer );
  4403. return 0;
  4404. }
  4405. static void proc_SSID_on_close( struct inode *inode, struct file *file ) {
  4406. struct proc_data *data = (struct proc_data *)file->private_data;
  4407. struct proc_dir_entry *dp = PDE(inode);
  4408. struct net_device *dev = dp->data;
  4409. struct airo_info *ai = dev->priv;
  4410. SsidRid SSID_rid;
  4411. Resp rsp;
  4412. int i;
  4413. int offset = 0;
  4414. if ( !data->writelen ) return;
  4415. memset( &SSID_rid, 0, sizeof( SSID_rid ) );
  4416. for( i = 0; i < 3; i++ ) {
  4417. int j;
  4418. for( j = 0; j+offset < data->writelen && j < 32 &&
  4419. data->wbuffer[offset+j] != '\n'; j++ ) {
  4420. SSID_rid.ssids[i].ssid[j] = data->wbuffer[offset+j];
  4421. }
  4422. if ( j == 0 ) break;
  4423. SSID_rid.ssids[i].len = j;
  4424. offset += j;
  4425. while( data->wbuffer[offset] != '\n' &&
  4426. offset < data->writelen ) offset++;
  4427. offset++;
  4428. }
  4429. if (i)
  4430. SSID_rid.len = sizeof(SSID_rid);
  4431. disable_MAC(ai, 1);
  4432. writeSsidRid(ai, &SSID_rid, 1);
  4433. enable_MAC(ai, &rsp, 1);
  4434. }
  4435. static inline u8 hexVal(char c) {
  4436. if (c>='0' && c<='9') return c -= '0';
  4437. if (c>='a' && c<='f') return c -= 'a'-10;
  4438. if (c>='A' && c<='F') return c -= 'A'-10;
  4439. return 0;
  4440. }
  4441. static void proc_APList_on_close( struct inode *inode, struct file *file ) {
  4442. struct proc_data *data = (struct proc_data *)file->private_data;
  4443. struct proc_dir_entry *dp = PDE(inode);
  4444. struct net_device *dev = dp->data;
  4445. struct airo_info *ai = dev->priv;
  4446. APListRid APList_rid;
  4447. Resp rsp;
  4448. int i;
  4449. if ( !data->writelen ) return;
  4450. memset( &APList_rid, 0, sizeof(APList_rid) );
  4451. APList_rid.len = sizeof(APList_rid);
  4452. for( i = 0; i < 4 && data->writelen >= (i+1)*6*3; i++ ) {
  4453. int j;
  4454. for( j = 0; j < 6*3 && data->wbuffer[j+i*6*3]; j++ ) {
  4455. switch(j%3) {
  4456. case 0:
  4457. APList_rid.ap[i][j/3]=
  4458. hexVal(data->wbuffer[j+i*6*3])<<4;
  4459. break;
  4460. case 1:
  4461. APList_rid.ap[i][j/3]|=
  4462. hexVal(data->wbuffer[j+i*6*3]);
  4463. break;
  4464. }
  4465. }
  4466. }
  4467. disable_MAC(ai, 1);
  4468. writeAPListRid(ai, &APList_rid, 1);
  4469. enable_MAC(ai, &rsp, 1);
  4470. }
  4471. /* This function wraps PC4500_writerid with a MAC disable */
  4472. static int do_writerid( struct airo_info *ai, u16 rid, const void *rid_data,
  4473. int len, int dummy ) {
  4474. int rc;
  4475. Resp rsp;
  4476. disable_MAC(ai, 1);
  4477. rc = PC4500_writerid(ai, rid, rid_data, len, 1);
  4478. enable_MAC(ai, &rsp, 1);
  4479. return rc;
  4480. }
  4481. /* Returns the length of the key at the index. If index == 0xffff
  4482. * the index of the transmit key is returned. If the key doesn't exist,
  4483. * -1 will be returned.
  4484. */
  4485. static int get_wep_key(struct airo_info *ai, u16 index) {
  4486. WepKeyRid wkr;
  4487. int rc;
  4488. u16 lastindex;
  4489. rc = readWepKeyRid(ai, &wkr, 1, 1);
  4490. if (rc == SUCCESS) do {
  4491. lastindex = wkr.kindex;
  4492. if (wkr.kindex == index) {
  4493. if (index == 0xffff) {
  4494. return wkr.mac[0];
  4495. }
  4496. return wkr.klen;
  4497. }
  4498. readWepKeyRid(ai, &wkr, 0, 1);
  4499. } while(lastindex != wkr.kindex);
  4500. return -1;
  4501. }
  4502. static int set_wep_key(struct airo_info *ai, u16 index,
  4503. const char *key, u16 keylen, int perm, int lock ) {
  4504. static const unsigned char macaddr[ETH_ALEN] = { 0x01, 0, 0, 0, 0, 0 };
  4505. WepKeyRid wkr;
  4506. Resp rsp;
  4507. memset(&wkr, 0, sizeof(wkr));
  4508. if (keylen == 0) {
  4509. // We are selecting which key to use
  4510. wkr.len = sizeof(wkr);
  4511. wkr.kindex = 0xffff;
  4512. wkr.mac[0] = (char)index;
  4513. if (perm) printk(KERN_INFO "Setting transmit key to %d\n", index);
  4514. if (perm) ai->defindex = (char)index;
  4515. } else {
  4516. // We are actually setting the key
  4517. wkr.len = sizeof(wkr);
  4518. wkr.kindex = index;
  4519. wkr.klen = keylen;
  4520. memcpy( wkr.key, key, keylen );
  4521. memcpy( wkr.mac, macaddr, ETH_ALEN );
  4522. printk(KERN_INFO "Setting key %d\n", index);
  4523. }
  4524. disable_MAC(ai, lock);
  4525. writeWepKeyRid(ai, &wkr, perm, lock);
  4526. enable_MAC(ai, &rsp, lock);
  4527. return 0;
  4528. }
  4529. static void proc_wepkey_on_close( struct inode *inode, struct file *file ) {
  4530. struct proc_data *data;
  4531. struct proc_dir_entry *dp = PDE(inode);
  4532. struct net_device *dev = dp->data;
  4533. struct airo_info *ai = dev->priv;
  4534. int i;
  4535. char key[16];
  4536. u16 index = 0;
  4537. int j = 0;
  4538. memset(key, 0, sizeof(key));
  4539. data = (struct proc_data *)file->private_data;
  4540. if ( !data->writelen ) return;
  4541. if (data->wbuffer[0] >= '0' && data->wbuffer[0] <= '3' &&
  4542. (data->wbuffer[1] == ' ' || data->wbuffer[1] == '\n')) {
  4543. index = data->wbuffer[0] - '0';
  4544. if (data->wbuffer[1] == '\n') {
  4545. set_wep_key(ai, index, NULL, 0, 1, 1);
  4546. return;
  4547. }
  4548. j = 2;
  4549. } else {
  4550. printk(KERN_ERR "airo: WepKey passed invalid key index\n");
  4551. return;
  4552. }
  4553. for( i = 0; i < 16*3 && data->wbuffer[i+j]; i++ ) {
  4554. switch(i%3) {
  4555. case 0:
  4556. key[i/3] = hexVal(data->wbuffer[i+j])<<4;
  4557. break;
  4558. case 1:
  4559. key[i/3] |= hexVal(data->wbuffer[i+j]);
  4560. break;
  4561. }
  4562. }
  4563. set_wep_key(ai, index, key, i/3, 1, 1);
  4564. }
  4565. static int proc_wepkey_open( struct inode *inode, struct file *file ) {
  4566. struct proc_data *data;
  4567. struct proc_dir_entry *dp = PDE(inode);
  4568. struct net_device *dev = dp->data;
  4569. struct airo_info *ai = dev->priv;
  4570. char *ptr;
  4571. WepKeyRid wkr;
  4572. u16 lastindex;
  4573. int j=0;
  4574. int rc;
  4575. if ((file->private_data = kzalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
  4576. return -ENOMEM;
  4577. memset(&wkr, 0, sizeof(wkr));
  4578. data = (struct proc_data *)file->private_data;
  4579. if ((data->rbuffer = kzalloc( 180, GFP_KERNEL )) == NULL) {
  4580. kfree (file->private_data);
  4581. return -ENOMEM;
  4582. }
  4583. data->writelen = 0;
  4584. data->maxwritelen = 80;
  4585. if ((data->wbuffer = kzalloc( 80, GFP_KERNEL )) == NULL) {
  4586. kfree (data->rbuffer);
  4587. kfree (file->private_data);
  4588. return -ENOMEM;
  4589. }
  4590. data->on_close = proc_wepkey_on_close;
  4591. ptr = data->rbuffer;
  4592. strcpy(ptr, "No wep keys\n");
  4593. rc = readWepKeyRid(ai, &wkr, 1, 1);
  4594. if (rc == SUCCESS) do {
  4595. lastindex = wkr.kindex;
  4596. if (wkr.kindex == 0xffff) {
  4597. j += sprintf(ptr+j, "Tx key = %d\n",
  4598. (int)wkr.mac[0]);
  4599. } else {
  4600. j += sprintf(ptr+j, "Key %d set with length = %d\n",
  4601. (int)wkr.kindex, (int)wkr.klen);
  4602. }
  4603. readWepKeyRid(ai, &wkr, 0, 1);
  4604. } while((lastindex != wkr.kindex) && (j < 180-30));
  4605. data->readlen = strlen( data->rbuffer );
  4606. return 0;
  4607. }
  4608. static int proc_SSID_open( struct inode *inode, struct file *file ) {
  4609. struct proc_data *data;
  4610. struct proc_dir_entry *dp = PDE(inode);
  4611. struct net_device *dev = dp->data;
  4612. struct airo_info *ai = dev->priv;
  4613. int i;
  4614. char *ptr;
  4615. SsidRid SSID_rid;
  4616. if ((file->private_data = kzalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
  4617. return -ENOMEM;
  4618. data = (struct proc_data *)file->private_data;
  4619. if ((data->rbuffer = kmalloc( 104, GFP_KERNEL )) == NULL) {
  4620. kfree (file->private_data);
  4621. return -ENOMEM;
  4622. }
  4623. data->writelen = 0;
  4624. data->maxwritelen = 33*3;
  4625. if ((data->wbuffer = kzalloc( 33*3, GFP_KERNEL )) == NULL) {
  4626. kfree (data->rbuffer);
  4627. kfree (file->private_data);
  4628. return -ENOMEM;
  4629. }
  4630. data->on_close = proc_SSID_on_close;
  4631. readSsidRid(ai, &SSID_rid);
  4632. ptr = data->rbuffer;
  4633. for( i = 0; i < 3; i++ ) {
  4634. int j;
  4635. if ( !SSID_rid.ssids[i].len ) break;
  4636. for( j = 0; j < 32 &&
  4637. j < SSID_rid.ssids[i].len &&
  4638. SSID_rid.ssids[i].ssid[j]; j++ ) {
  4639. *ptr++ = SSID_rid.ssids[i].ssid[j];
  4640. }
  4641. *ptr++ = '\n';
  4642. }
  4643. *ptr = '\0';
  4644. data->readlen = strlen( data->rbuffer );
  4645. return 0;
  4646. }
  4647. static int proc_APList_open( struct inode *inode, struct file *file ) {
  4648. struct proc_data *data;
  4649. struct proc_dir_entry *dp = PDE(inode);
  4650. struct net_device *dev = dp->data;
  4651. struct airo_info *ai = dev->priv;
  4652. int i;
  4653. char *ptr;
  4654. APListRid APList_rid;
  4655. if ((file->private_data = kzalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
  4656. return -ENOMEM;
  4657. data = (struct proc_data *)file->private_data;
  4658. if ((data->rbuffer = kmalloc( 104, GFP_KERNEL )) == NULL) {
  4659. kfree (file->private_data);
  4660. return -ENOMEM;
  4661. }
  4662. data->writelen = 0;
  4663. data->maxwritelen = 4*6*3;
  4664. if ((data->wbuffer = kzalloc( data->maxwritelen, GFP_KERNEL )) == NULL) {
  4665. kfree (data->rbuffer);
  4666. kfree (file->private_data);
  4667. return -ENOMEM;
  4668. }
  4669. data->on_close = proc_APList_on_close;
  4670. readAPListRid(ai, &APList_rid);
  4671. ptr = data->rbuffer;
  4672. for( i = 0; i < 4; i++ ) {
  4673. // We end when we find a zero MAC
  4674. if ( !*(int*)APList_rid.ap[i] &&
  4675. !*(int*)&APList_rid.ap[i][2]) break;
  4676. ptr += sprintf(ptr, "%02x:%02x:%02x:%02x:%02x:%02x\n",
  4677. (int)APList_rid.ap[i][0],
  4678. (int)APList_rid.ap[i][1],
  4679. (int)APList_rid.ap[i][2],
  4680. (int)APList_rid.ap[i][3],
  4681. (int)APList_rid.ap[i][4],
  4682. (int)APList_rid.ap[i][5]);
  4683. }
  4684. if (i==0) ptr += sprintf(ptr, "Not using specific APs\n");
  4685. *ptr = '\0';
  4686. data->readlen = strlen( data->rbuffer );
  4687. return 0;
  4688. }
  4689. static int proc_BSSList_open( struct inode *inode, struct file *file ) {
  4690. struct proc_data *data;
  4691. struct proc_dir_entry *dp = PDE(inode);
  4692. struct net_device *dev = dp->data;
  4693. struct airo_info *ai = dev->priv;
  4694. char *ptr;
  4695. BSSListRid BSSList_rid;
  4696. int rc;
  4697. /* If doLoseSync is not 1, we won't do a Lose Sync */
  4698. int doLoseSync = -1;
  4699. if ((file->private_data = kzalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
  4700. return -ENOMEM;
  4701. data = (struct proc_data *)file->private_data;
  4702. if ((data->rbuffer = kmalloc( 1024, GFP_KERNEL )) == NULL) {
  4703. kfree (file->private_data);
  4704. return -ENOMEM;
  4705. }
  4706. data->writelen = 0;
  4707. data->maxwritelen = 0;
  4708. data->wbuffer = NULL;
  4709. data->on_close = NULL;
  4710. if (file->f_mode & FMODE_WRITE) {
  4711. if (!(file->f_mode & FMODE_READ)) {
  4712. Cmd cmd;
  4713. Resp rsp;
  4714. if (ai->flags & FLAG_RADIO_MASK) return -ENETDOWN;
  4715. memset(&cmd, 0, sizeof(cmd));
  4716. cmd.cmd=CMD_LISTBSS;
  4717. if (down_interruptible(&ai->sem))
  4718. return -ERESTARTSYS;
  4719. issuecommand(ai, &cmd, &rsp);
  4720. up(&ai->sem);
  4721. data->readlen = 0;
  4722. return 0;
  4723. }
  4724. doLoseSync = 1;
  4725. }
  4726. ptr = data->rbuffer;
  4727. /* There is a race condition here if there are concurrent opens.
  4728. Since it is a rare condition, we'll just live with it, otherwise
  4729. we have to add a spin lock... */
  4730. rc = readBSSListRid(ai, doLoseSync, &BSSList_rid);
  4731. while(rc == 0 && BSSList_rid.index != 0xffff) {
  4732. ptr += sprintf(ptr, "%02x:%02x:%02x:%02x:%02x:%02x %*s rssi = %d",
  4733. (int)BSSList_rid.bssid[0],
  4734. (int)BSSList_rid.bssid[1],
  4735. (int)BSSList_rid.bssid[2],
  4736. (int)BSSList_rid.bssid[3],
  4737. (int)BSSList_rid.bssid[4],
  4738. (int)BSSList_rid.bssid[5],
  4739. (int)BSSList_rid.ssidLen,
  4740. BSSList_rid.ssid,
  4741. (int)BSSList_rid.dBm);
  4742. ptr += sprintf(ptr, " channel = %d %s %s %s %s\n",
  4743. (int)BSSList_rid.dsChannel,
  4744. BSSList_rid.cap & CAP_ESS ? "ESS" : "",
  4745. BSSList_rid.cap & CAP_IBSS ? "adhoc" : "",
  4746. BSSList_rid.cap & CAP_PRIVACY ? "wep" : "",
  4747. BSSList_rid.cap & CAP_SHORTHDR ? "shorthdr" : "");
  4748. rc = readBSSListRid(ai, 0, &BSSList_rid);
  4749. }
  4750. *ptr = '\0';
  4751. data->readlen = strlen( data->rbuffer );
  4752. return 0;
  4753. }
  4754. static int proc_close( struct inode *inode, struct file *file )
  4755. {
  4756. struct proc_data *data = file->private_data;
  4757. if (data->on_close != NULL)
  4758. data->on_close(inode, file);
  4759. kfree(data->rbuffer);
  4760. kfree(data->wbuffer);
  4761. kfree(data);
  4762. return 0;
  4763. }
  4764. static struct net_device_list {
  4765. struct net_device *dev;
  4766. struct net_device_list *next;
  4767. } *airo_devices;
  4768. /* Since the card doesn't automatically switch to the right WEP mode,
  4769. we will make it do it. If the card isn't associated, every secs we
  4770. will switch WEP modes to see if that will help. If the card is
  4771. associated we will check every minute to see if anything has
  4772. changed. */
  4773. static void timer_func( struct net_device *dev ) {
  4774. struct airo_info *apriv = dev->priv;
  4775. Resp rsp;
  4776. /* We don't have a link so try changing the authtype */
  4777. readConfigRid(apriv, 0);
  4778. disable_MAC(apriv, 0);
  4779. switch(apriv->config.authType) {
  4780. case AUTH_ENCRYPT:
  4781. /* So drop to OPEN */
  4782. apriv->config.authType = AUTH_OPEN;
  4783. break;
  4784. case AUTH_SHAREDKEY:
  4785. if (apriv->keyindex < auto_wep) {
  4786. set_wep_key(apriv, apriv->keyindex, NULL, 0, 0, 0);
  4787. apriv->config.authType = AUTH_SHAREDKEY;
  4788. apriv->keyindex++;
  4789. } else {
  4790. /* Drop to ENCRYPT */
  4791. apriv->keyindex = 0;
  4792. set_wep_key(apriv, apriv->defindex, NULL, 0, 0, 0);
  4793. apriv->config.authType = AUTH_ENCRYPT;
  4794. }
  4795. break;
  4796. default: /* We'll escalate to SHAREDKEY */
  4797. apriv->config.authType = AUTH_SHAREDKEY;
  4798. }
  4799. set_bit (FLAG_COMMIT, &apriv->flags);
  4800. writeConfigRid(apriv, 0);
  4801. enable_MAC(apriv, &rsp, 0);
  4802. up(&apriv->sem);
  4803. /* Schedule check to see if the change worked */
  4804. clear_bit(JOB_AUTOWEP, &apriv->flags);
  4805. apriv->expires = RUN_AT(HZ*3);
  4806. }
  4807. static int add_airo_dev( struct net_device *dev ) {
  4808. struct net_device_list *node = kmalloc( sizeof( *node ), GFP_KERNEL );
  4809. if ( !node )
  4810. return -ENOMEM;
  4811. node->dev = dev;
  4812. node->next = airo_devices;
  4813. airo_devices = node;
  4814. return 0;
  4815. }
  4816. static void del_airo_dev( struct net_device *dev ) {
  4817. struct net_device_list **p = &airo_devices;
  4818. while( *p && ( (*p)->dev != dev ) )
  4819. p = &(*p)->next;
  4820. if ( *p && (*p)->dev == dev )
  4821. *p = (*p)->next;
  4822. }
  4823. #ifdef CONFIG_PCI
  4824. static int __devinit airo_pci_probe(struct pci_dev *pdev,
  4825. const struct pci_device_id *pent)
  4826. {
  4827. struct net_device *dev;
  4828. if (pci_enable_device(pdev))
  4829. return -ENODEV;
  4830. pci_set_master(pdev);
  4831. if (pdev->device == 0x5000 || pdev->device == 0xa504)
  4832. dev = _init_airo_card(pdev->irq, pdev->resource[0].start, 0, pdev, &pdev->dev);
  4833. else
  4834. dev = _init_airo_card(pdev->irq, pdev->resource[2].start, 0, pdev, &pdev->dev);
  4835. if (!dev)
  4836. return -ENODEV;
  4837. pci_set_drvdata(pdev, dev);
  4838. return 0;
  4839. }
  4840. static void __devexit airo_pci_remove(struct pci_dev *pdev)
  4841. {
  4842. }
  4843. static int airo_pci_suspend(struct pci_dev *pdev, pm_message_t state)
  4844. {
  4845. struct net_device *dev = pci_get_drvdata(pdev);
  4846. struct airo_info *ai = dev->priv;
  4847. Cmd cmd;
  4848. Resp rsp;
  4849. if ((ai->APList == NULL) &&
  4850. (ai->APList = kmalloc(sizeof(APListRid), GFP_KERNEL)) == NULL)
  4851. return -ENOMEM;
  4852. if ((ai->SSID == NULL) &&
  4853. (ai->SSID = kmalloc(sizeof(SsidRid), GFP_KERNEL)) == NULL)
  4854. return -ENOMEM;
  4855. readAPListRid(ai, ai->APList);
  4856. readSsidRid(ai, ai->SSID);
  4857. memset(&cmd, 0, sizeof(cmd));
  4858. /* the lock will be released at the end of the resume callback */
  4859. if (down_interruptible(&ai->sem))
  4860. return -EAGAIN;
  4861. disable_MAC(ai, 0);
  4862. netif_device_detach(dev);
  4863. ai->power = state;
  4864. cmd.cmd=HOSTSLEEP;
  4865. issuecommand(ai, &cmd, &rsp);
  4866. pci_enable_wake(pdev, pci_choose_state(pdev, state), 1);
  4867. pci_save_state(pdev);
  4868. return pci_set_power_state(pdev, pci_choose_state(pdev, state));
  4869. }
  4870. static int airo_pci_resume(struct pci_dev *pdev)
  4871. {
  4872. struct net_device *dev = pci_get_drvdata(pdev);
  4873. struct airo_info *ai = dev->priv;
  4874. Resp rsp;
  4875. pci_power_t prev_state = pdev->current_state;
  4876. pci_set_power_state(pdev, PCI_D0);
  4877. pci_restore_state(pdev);
  4878. pci_enable_wake(pdev, PCI_D0, 0);
  4879. if (prev_state != PCI_D1) {
  4880. reset_card(dev, 0);
  4881. mpi_init_descriptors(ai);
  4882. setup_card(ai, dev->dev_addr, 0);
  4883. clear_bit(FLAG_RADIO_OFF, &ai->flags);
  4884. clear_bit(FLAG_PENDING_XMIT, &ai->flags);
  4885. } else {
  4886. OUT4500(ai, EVACK, EV_AWAKEN);
  4887. OUT4500(ai, EVACK, EV_AWAKEN);
  4888. msleep(100);
  4889. }
  4890. set_bit (FLAG_COMMIT, &ai->flags);
  4891. disable_MAC(ai, 0);
  4892. msleep(200);
  4893. if (ai->SSID) {
  4894. writeSsidRid(ai, ai->SSID, 0);
  4895. kfree(ai->SSID);
  4896. ai->SSID = NULL;
  4897. }
  4898. if (ai->APList) {
  4899. writeAPListRid(ai, ai->APList, 0);
  4900. kfree(ai->APList);
  4901. ai->APList = NULL;
  4902. }
  4903. writeConfigRid(ai, 0);
  4904. enable_MAC(ai, &rsp, 0);
  4905. ai->power = PMSG_ON;
  4906. netif_device_attach(dev);
  4907. netif_wake_queue(dev);
  4908. enable_interrupts(ai);
  4909. up(&ai->sem);
  4910. return 0;
  4911. }
  4912. #endif
  4913. static int __init airo_init_module( void )
  4914. {
  4915. int i, have_isa_dev = 0;
  4916. airo_entry = create_proc_entry("aironet",
  4917. S_IFDIR | airo_perm,
  4918. proc_root_driver);
  4919. airo_entry->uid = proc_uid;
  4920. airo_entry->gid = proc_gid;
  4921. for( i = 0; i < 4 && io[i] && irq[i]; i++ ) {
  4922. printk( KERN_INFO
  4923. "airo: Trying to configure ISA adapter at irq=%d io=0x%x\n",
  4924. irq[i], io[i] );
  4925. if (init_airo_card( irq[i], io[i], 0, NULL ))
  4926. have_isa_dev = 1;
  4927. }
  4928. #ifdef CONFIG_PCI
  4929. printk( KERN_INFO "airo: Probing for PCI adapters\n" );
  4930. pci_register_driver(&airo_driver);
  4931. printk( KERN_INFO "airo: Finished probing for PCI adapters\n" );
  4932. #endif
  4933. /* Always exit with success, as we are a library module
  4934. * as well as a driver module
  4935. */
  4936. return 0;
  4937. }
  4938. static void __exit airo_cleanup_module( void )
  4939. {
  4940. while( airo_devices ) {
  4941. printk( KERN_INFO "airo: Unregistering %s\n", airo_devices->dev->name );
  4942. stop_airo_card( airo_devices->dev, 1 );
  4943. }
  4944. #ifdef CONFIG_PCI
  4945. pci_unregister_driver(&airo_driver);
  4946. #endif
  4947. remove_proc_entry("aironet", proc_root_driver);
  4948. }
  4949. /*
  4950. * Initial Wireless Extension code for Aironet driver by :
  4951. * Jean Tourrilhes <jt@hpl.hp.com> - HPL - 17 November 00
  4952. * Conversion to new driver API by :
  4953. * Jean Tourrilhes <jt@hpl.hp.com> - HPL - 26 March 02
  4954. * Javier also did a good amount of work here, adding some new extensions
  4955. * and fixing my code. Let's just say that without him this code just
  4956. * would not work at all... - Jean II
  4957. */
  4958. static u8 airo_rssi_to_dbm (tdsRssiEntry *rssi_rid, u8 rssi)
  4959. {
  4960. if( !rssi_rid )
  4961. return 0;
  4962. return (0x100 - rssi_rid[rssi].rssidBm);
  4963. }
  4964. static u8 airo_dbm_to_pct (tdsRssiEntry *rssi_rid, u8 dbm)
  4965. {
  4966. int i;
  4967. if( !rssi_rid )
  4968. return 0;
  4969. for( i = 0; i < 256; i++ )
  4970. if (rssi_rid[i].rssidBm == dbm)
  4971. return rssi_rid[i].rssipct;
  4972. return 0;
  4973. }
  4974. static int airo_get_quality (StatusRid *status_rid, CapabilityRid *cap_rid)
  4975. {
  4976. int quality = 0;
  4977. if ((status_rid->mode & 0x3f) == 0x3f && (cap_rid->hardCap & 8)) {
  4978. if (memcmp(cap_rid->prodName, "350", 3))
  4979. if (status_rid->signalQuality > 0x20)
  4980. quality = 0;
  4981. else
  4982. quality = 0x20 - status_rid->signalQuality;
  4983. else
  4984. if (status_rid->signalQuality > 0xb0)
  4985. quality = 0;
  4986. else if (status_rid->signalQuality < 0x10)
  4987. quality = 0xa0;
  4988. else
  4989. quality = 0xb0 - status_rid->signalQuality;
  4990. }
  4991. return quality;
  4992. }
  4993. #define airo_get_max_quality(cap_rid) (memcmp((cap_rid)->prodName, "350", 3) ? 0x20 : 0xa0)
  4994. #define airo_get_avg_quality(cap_rid) (memcmp((cap_rid)->prodName, "350", 3) ? 0x10 : 0x50);
  4995. /*------------------------------------------------------------------*/
  4996. /*
  4997. * Wireless Handler : get protocol name
  4998. */
  4999. static int airo_get_name(struct net_device *dev,
  5000. struct iw_request_info *info,
  5001. char *cwrq,
  5002. char *extra)
  5003. {
  5004. strcpy(cwrq, "IEEE 802.11-DS");
  5005. return 0;
  5006. }
  5007. /*------------------------------------------------------------------*/
  5008. /*
  5009. * Wireless Handler : set frequency
  5010. */
  5011. static int airo_set_freq(struct net_device *dev,
  5012. struct iw_request_info *info,
  5013. struct iw_freq *fwrq,
  5014. char *extra)
  5015. {
  5016. struct airo_info *local = dev->priv;
  5017. int rc = -EINPROGRESS; /* Call commit handler */
  5018. /* If setting by frequency, convert to a channel */
  5019. if((fwrq->e == 1) &&
  5020. (fwrq->m >= (int) 2.412e8) &&
  5021. (fwrq->m <= (int) 2.487e8)) {
  5022. int f = fwrq->m / 100000;
  5023. int c = 0;
  5024. while((c < 14) && (f != frequency_list[c]))
  5025. c++;
  5026. /* Hack to fall through... */
  5027. fwrq->e = 0;
  5028. fwrq->m = c + 1;
  5029. }
  5030. /* Setting by channel number */
  5031. if((fwrq->m > 1000) || (fwrq->e > 0))
  5032. rc = -EOPNOTSUPP;
  5033. else {
  5034. int channel = fwrq->m;
  5035. /* We should do a better check than that,
  5036. * based on the card capability !!! */
  5037. if((channel < 1) || (channel > 16)) {
  5038. printk(KERN_DEBUG "%s: New channel value of %d is invalid!\n", dev->name, fwrq->m);
  5039. rc = -EINVAL;
  5040. } else {
  5041. readConfigRid(local, 1);
  5042. /* Yes ! We can set it !!! */
  5043. local->config.channelSet = (u16)(channel - 1);
  5044. set_bit (FLAG_COMMIT, &local->flags);
  5045. }
  5046. }
  5047. return rc;
  5048. }
  5049. /*------------------------------------------------------------------*/
  5050. /*
  5051. * Wireless Handler : get frequency
  5052. */
  5053. static int airo_get_freq(struct net_device *dev,
  5054. struct iw_request_info *info,
  5055. struct iw_freq *fwrq,
  5056. char *extra)
  5057. {
  5058. struct airo_info *local = dev->priv;
  5059. StatusRid status_rid; /* Card status info */
  5060. readConfigRid(local, 1);
  5061. if ((local->config.opmode & 0xFF) == MODE_STA_ESS)
  5062. status_rid.channel = local->config.channelSet;
  5063. else
  5064. readStatusRid(local, &status_rid, 1);
  5065. #ifdef WEXT_USECHANNELS
  5066. fwrq->m = ((int)status_rid.channel) + 1;
  5067. fwrq->e = 0;
  5068. #else
  5069. {
  5070. int f = (int)status_rid.channel;
  5071. fwrq->m = frequency_list[f] * 100000;
  5072. fwrq->e = 1;
  5073. }
  5074. #endif
  5075. return 0;
  5076. }
  5077. /*------------------------------------------------------------------*/
  5078. /*
  5079. * Wireless Handler : set ESSID
  5080. */
  5081. static int airo_set_essid(struct net_device *dev,
  5082. struct iw_request_info *info,
  5083. struct iw_point *dwrq,
  5084. char *extra)
  5085. {
  5086. struct airo_info *local = dev->priv;
  5087. Resp rsp;
  5088. SsidRid SSID_rid; /* SSIDs */
  5089. /* Reload the list of current SSID */
  5090. readSsidRid(local, &SSID_rid);
  5091. /* Check if we asked for `any' */
  5092. if(dwrq->flags == 0) {
  5093. /* Just send an empty SSID list */
  5094. memset(&SSID_rid, 0, sizeof(SSID_rid));
  5095. } else {
  5096. int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
  5097. /* Check the size of the string */
  5098. if(dwrq->length > IW_ESSID_MAX_SIZE+1) {
  5099. return -E2BIG ;
  5100. }
  5101. /* Check if index is valid */
  5102. if((index < 0) || (index >= 4)) {
  5103. return -EINVAL;
  5104. }
  5105. /* Set the SSID */
  5106. memset(SSID_rid.ssids[index].ssid, 0,
  5107. sizeof(SSID_rid.ssids[index].ssid));
  5108. memcpy(SSID_rid.ssids[index].ssid, extra, dwrq->length);
  5109. SSID_rid.ssids[index].len = dwrq->length - 1;
  5110. }
  5111. SSID_rid.len = sizeof(SSID_rid);
  5112. /* Write it to the card */
  5113. disable_MAC(local, 1);
  5114. writeSsidRid(local, &SSID_rid, 1);
  5115. enable_MAC(local, &rsp, 1);
  5116. return 0;
  5117. }
  5118. /*------------------------------------------------------------------*/
  5119. /*
  5120. * Wireless Handler : get ESSID
  5121. */
  5122. static int airo_get_essid(struct net_device *dev,
  5123. struct iw_request_info *info,
  5124. struct iw_point *dwrq,
  5125. char *extra)
  5126. {
  5127. struct airo_info *local = dev->priv;
  5128. StatusRid status_rid; /* Card status info */
  5129. readStatusRid(local, &status_rid, 1);
  5130. /* Note : if dwrq->flags != 0, we should
  5131. * get the relevant SSID from the SSID list... */
  5132. /* Get the current SSID */
  5133. memcpy(extra, status_rid.SSID, status_rid.SSIDlen);
  5134. extra[status_rid.SSIDlen] = '\0';
  5135. /* If none, we may want to get the one that was set */
  5136. /* Push it out ! */
  5137. dwrq->length = status_rid.SSIDlen + 1;
  5138. dwrq->flags = 1; /* active */
  5139. return 0;
  5140. }
  5141. /*------------------------------------------------------------------*/
  5142. /*
  5143. * Wireless Handler : set AP address
  5144. */
  5145. static int airo_set_wap(struct net_device *dev,
  5146. struct iw_request_info *info,
  5147. struct sockaddr *awrq,
  5148. char *extra)
  5149. {
  5150. struct airo_info *local = dev->priv;
  5151. Cmd cmd;
  5152. Resp rsp;
  5153. APListRid APList_rid;
  5154. static const unsigned char bcast[ETH_ALEN] = { 255, 255, 255, 255, 255, 255 };
  5155. if (awrq->sa_family != ARPHRD_ETHER)
  5156. return -EINVAL;
  5157. else if (!memcmp(bcast, awrq->sa_data, ETH_ALEN)) {
  5158. memset(&cmd, 0, sizeof(cmd));
  5159. cmd.cmd=CMD_LOSE_SYNC;
  5160. if (down_interruptible(&local->sem))
  5161. return -ERESTARTSYS;
  5162. issuecommand(local, &cmd, &rsp);
  5163. up(&local->sem);
  5164. } else {
  5165. memset(&APList_rid, 0, sizeof(APList_rid));
  5166. APList_rid.len = sizeof(APList_rid);
  5167. memcpy(APList_rid.ap[0], awrq->sa_data, ETH_ALEN);
  5168. disable_MAC(local, 1);
  5169. writeAPListRid(local, &APList_rid, 1);
  5170. enable_MAC(local, &rsp, 1);
  5171. }
  5172. return 0;
  5173. }
  5174. /*------------------------------------------------------------------*/
  5175. /*
  5176. * Wireless Handler : get AP address
  5177. */
  5178. static int airo_get_wap(struct net_device *dev,
  5179. struct iw_request_info *info,
  5180. struct sockaddr *awrq,
  5181. char *extra)
  5182. {
  5183. struct airo_info *local = dev->priv;
  5184. StatusRid status_rid; /* Card status info */
  5185. readStatusRid(local, &status_rid, 1);
  5186. /* Tentative. This seems to work, wow, I'm lucky !!! */
  5187. memcpy(awrq->sa_data, status_rid.bssid[0], ETH_ALEN);
  5188. awrq->sa_family = ARPHRD_ETHER;
  5189. return 0;
  5190. }
  5191. /*------------------------------------------------------------------*/
  5192. /*
  5193. * Wireless Handler : set Nickname
  5194. */
  5195. static int airo_set_nick(struct net_device *dev,
  5196. struct iw_request_info *info,
  5197. struct iw_point *dwrq,
  5198. char *extra)
  5199. {
  5200. struct airo_info *local = dev->priv;
  5201. /* Check the size of the string */
  5202. if(dwrq->length > 16 + 1) {
  5203. return -E2BIG;
  5204. }
  5205. readConfigRid(local, 1);
  5206. memset(local->config.nodeName, 0, sizeof(local->config.nodeName));
  5207. memcpy(local->config.nodeName, extra, dwrq->length);
  5208. set_bit (FLAG_COMMIT, &local->flags);
  5209. return -EINPROGRESS; /* Call commit handler */
  5210. }
  5211. /*------------------------------------------------------------------*/
  5212. /*
  5213. * Wireless Handler : get Nickname
  5214. */
  5215. static int airo_get_nick(struct net_device *dev,
  5216. struct iw_request_info *info,
  5217. struct iw_point *dwrq,
  5218. char *extra)
  5219. {
  5220. struct airo_info *local = dev->priv;
  5221. readConfigRid(local, 1);
  5222. strncpy(extra, local->config.nodeName, 16);
  5223. extra[16] = '\0';
  5224. dwrq->length = strlen(extra) + 1;
  5225. return 0;
  5226. }
  5227. /*------------------------------------------------------------------*/
  5228. /*
  5229. * Wireless Handler : set Bit-Rate
  5230. */
  5231. static int airo_set_rate(struct net_device *dev,
  5232. struct iw_request_info *info,
  5233. struct iw_param *vwrq,
  5234. char *extra)
  5235. {
  5236. struct airo_info *local = dev->priv;
  5237. CapabilityRid cap_rid; /* Card capability info */
  5238. u8 brate = 0;
  5239. int i;
  5240. /* First : get a valid bit rate value */
  5241. readCapabilityRid(local, &cap_rid, 1);
  5242. /* Which type of value ? */
  5243. if((vwrq->value < 8) && (vwrq->value >= 0)) {
  5244. /* Setting by rate index */
  5245. /* Find value in the magic rate table */
  5246. brate = cap_rid.supportedRates[vwrq->value];
  5247. } else {
  5248. /* Setting by frequency value */
  5249. u8 normvalue = (u8) (vwrq->value/500000);
  5250. /* Check if rate is valid */
  5251. for(i = 0 ; i < 8 ; i++) {
  5252. if(normvalue == cap_rid.supportedRates[i]) {
  5253. brate = normvalue;
  5254. break;
  5255. }
  5256. }
  5257. }
  5258. /* -1 designed the max rate (mostly auto mode) */
  5259. if(vwrq->value == -1) {
  5260. /* Get the highest available rate */
  5261. for(i = 0 ; i < 8 ; i++) {
  5262. if(cap_rid.supportedRates[i] == 0)
  5263. break;
  5264. }
  5265. if(i != 0)
  5266. brate = cap_rid.supportedRates[i - 1];
  5267. }
  5268. /* Check that it is valid */
  5269. if(brate == 0) {
  5270. return -EINVAL;
  5271. }
  5272. readConfigRid(local, 1);
  5273. /* Now, check if we want a fixed or auto value */
  5274. if(vwrq->fixed == 0) {
  5275. /* Fill all the rates up to this max rate */
  5276. memset(local->config.rates, 0, 8);
  5277. for(i = 0 ; i < 8 ; i++) {
  5278. local->config.rates[i] = cap_rid.supportedRates[i];
  5279. if(local->config.rates[i] == brate)
  5280. break;
  5281. }
  5282. } else {
  5283. /* Fixed mode */
  5284. /* One rate, fixed */
  5285. memset(local->config.rates, 0, 8);
  5286. local->config.rates[0] = brate;
  5287. }
  5288. set_bit (FLAG_COMMIT, &local->flags);
  5289. return -EINPROGRESS; /* Call commit handler */
  5290. }
  5291. /*------------------------------------------------------------------*/
  5292. /*
  5293. * Wireless Handler : get Bit-Rate
  5294. */
  5295. static int airo_get_rate(struct net_device *dev,
  5296. struct iw_request_info *info,
  5297. struct iw_param *vwrq,
  5298. char *extra)
  5299. {
  5300. struct airo_info *local = dev->priv;
  5301. StatusRid status_rid; /* Card status info */
  5302. readStatusRid(local, &status_rid, 1);
  5303. vwrq->value = status_rid.currentXmitRate * 500000;
  5304. /* If more than one rate, set auto */
  5305. readConfigRid(local, 1);
  5306. vwrq->fixed = (local->config.rates[1] == 0);
  5307. return 0;
  5308. }
  5309. /*------------------------------------------------------------------*/
  5310. /*
  5311. * Wireless Handler : set RTS threshold
  5312. */
  5313. static int airo_set_rts(struct net_device *dev,
  5314. struct iw_request_info *info,
  5315. struct iw_param *vwrq,
  5316. char *extra)
  5317. {
  5318. struct airo_info *local = dev->priv;
  5319. int rthr = vwrq->value;
  5320. if(vwrq->disabled)
  5321. rthr = 2312;
  5322. if((rthr < 0) || (rthr > 2312)) {
  5323. return -EINVAL;
  5324. }
  5325. readConfigRid(local, 1);
  5326. local->config.rtsThres = rthr;
  5327. set_bit (FLAG_COMMIT, &local->flags);
  5328. return -EINPROGRESS; /* Call commit handler */
  5329. }
  5330. /*------------------------------------------------------------------*/
  5331. /*
  5332. * Wireless Handler : get RTS threshold
  5333. */
  5334. static int airo_get_rts(struct net_device *dev,
  5335. struct iw_request_info *info,
  5336. struct iw_param *vwrq,
  5337. char *extra)
  5338. {
  5339. struct airo_info *local = dev->priv;
  5340. readConfigRid(local, 1);
  5341. vwrq->value = local->config.rtsThres;
  5342. vwrq->disabled = (vwrq->value >= 2312);
  5343. vwrq->fixed = 1;
  5344. return 0;
  5345. }
  5346. /*------------------------------------------------------------------*/
  5347. /*
  5348. * Wireless Handler : set Fragmentation threshold
  5349. */
  5350. static int airo_set_frag(struct net_device *dev,
  5351. struct iw_request_info *info,
  5352. struct iw_param *vwrq,
  5353. char *extra)
  5354. {
  5355. struct airo_info *local = dev->priv;
  5356. int fthr = vwrq->value;
  5357. if(vwrq->disabled)
  5358. fthr = 2312;
  5359. if((fthr < 256) || (fthr > 2312)) {
  5360. return -EINVAL;
  5361. }
  5362. fthr &= ~0x1; /* Get an even value - is it really needed ??? */
  5363. readConfigRid(local, 1);
  5364. local->config.fragThresh = (u16)fthr;
  5365. set_bit (FLAG_COMMIT, &local->flags);
  5366. return -EINPROGRESS; /* Call commit handler */
  5367. }
  5368. /*------------------------------------------------------------------*/
  5369. /*
  5370. * Wireless Handler : get Fragmentation threshold
  5371. */
  5372. static int airo_get_frag(struct net_device *dev,
  5373. struct iw_request_info *info,
  5374. struct iw_param *vwrq,
  5375. char *extra)
  5376. {
  5377. struct airo_info *local = dev->priv;
  5378. readConfigRid(local, 1);
  5379. vwrq->value = local->config.fragThresh;
  5380. vwrq->disabled = (vwrq->value >= 2312);
  5381. vwrq->fixed = 1;
  5382. return 0;
  5383. }
  5384. /*------------------------------------------------------------------*/
  5385. /*
  5386. * Wireless Handler : set Mode of Operation
  5387. */
  5388. static int airo_set_mode(struct net_device *dev,
  5389. struct iw_request_info *info,
  5390. __u32 *uwrq,
  5391. char *extra)
  5392. {
  5393. struct airo_info *local = dev->priv;
  5394. int reset = 0;
  5395. readConfigRid(local, 1);
  5396. if ((local->config.rmode & 0xff) >= RXMODE_RFMON)
  5397. reset = 1;
  5398. switch(*uwrq) {
  5399. case IW_MODE_ADHOC:
  5400. local->config.opmode &= 0xFF00;
  5401. local->config.opmode |= MODE_STA_IBSS;
  5402. local->config.rmode &= 0xfe00;
  5403. local->config.scanMode = SCANMODE_ACTIVE;
  5404. clear_bit (FLAG_802_11, &local->flags);
  5405. break;
  5406. case IW_MODE_INFRA:
  5407. local->config.opmode &= 0xFF00;
  5408. local->config.opmode |= MODE_STA_ESS;
  5409. local->config.rmode &= 0xfe00;
  5410. local->config.scanMode = SCANMODE_ACTIVE;
  5411. clear_bit (FLAG_802_11, &local->flags);
  5412. break;
  5413. case IW_MODE_MASTER:
  5414. local->config.opmode &= 0xFF00;
  5415. local->config.opmode |= MODE_AP;
  5416. local->config.rmode &= 0xfe00;
  5417. local->config.scanMode = SCANMODE_ACTIVE;
  5418. clear_bit (FLAG_802_11, &local->flags);
  5419. break;
  5420. case IW_MODE_REPEAT:
  5421. local->config.opmode &= 0xFF00;
  5422. local->config.opmode |= MODE_AP_RPTR;
  5423. local->config.rmode &= 0xfe00;
  5424. local->config.scanMode = SCANMODE_ACTIVE;
  5425. clear_bit (FLAG_802_11, &local->flags);
  5426. break;
  5427. case IW_MODE_MONITOR:
  5428. local->config.opmode &= 0xFF00;
  5429. local->config.opmode |= MODE_STA_ESS;
  5430. local->config.rmode &= 0xfe00;
  5431. local->config.rmode |= RXMODE_RFMON | RXMODE_DISABLE_802_3_HEADER;
  5432. local->config.scanMode = SCANMODE_PASSIVE;
  5433. set_bit (FLAG_802_11, &local->flags);
  5434. break;
  5435. default:
  5436. return -EINVAL;
  5437. }
  5438. if (reset)
  5439. set_bit (FLAG_RESET, &local->flags);
  5440. set_bit (FLAG_COMMIT, &local->flags);
  5441. return -EINPROGRESS; /* Call commit handler */
  5442. }
  5443. /*------------------------------------------------------------------*/
  5444. /*
  5445. * Wireless Handler : get Mode of Operation
  5446. */
  5447. static int airo_get_mode(struct net_device *dev,
  5448. struct iw_request_info *info,
  5449. __u32 *uwrq,
  5450. char *extra)
  5451. {
  5452. struct airo_info *local = dev->priv;
  5453. readConfigRid(local, 1);
  5454. /* If not managed, assume it's ad-hoc */
  5455. switch (local->config.opmode & 0xFF) {
  5456. case MODE_STA_ESS:
  5457. *uwrq = IW_MODE_INFRA;
  5458. break;
  5459. case MODE_AP:
  5460. *uwrq = IW_MODE_MASTER;
  5461. break;
  5462. case MODE_AP_RPTR:
  5463. *uwrq = IW_MODE_REPEAT;
  5464. break;
  5465. default:
  5466. *uwrq = IW_MODE_ADHOC;
  5467. }
  5468. return 0;
  5469. }
  5470. /*------------------------------------------------------------------*/
  5471. /*
  5472. * Wireless Handler : set Encryption Key
  5473. */
  5474. static int airo_set_encode(struct net_device *dev,
  5475. struct iw_request_info *info,
  5476. struct iw_point *dwrq,
  5477. char *extra)
  5478. {
  5479. struct airo_info *local = dev->priv;
  5480. CapabilityRid cap_rid; /* Card capability info */
  5481. /* Is WEP supported ? */
  5482. readCapabilityRid(local, &cap_rid, 1);
  5483. /* Older firmware doesn't support this...
  5484. if(!(cap_rid.softCap & 2)) {
  5485. return -EOPNOTSUPP;
  5486. } */
  5487. readConfigRid(local, 1);
  5488. /* Basic checking: do we have a key to set ?
  5489. * Note : with the new API, it's impossible to get a NULL pointer.
  5490. * Therefore, we need to check a key size == 0 instead.
  5491. * New version of iwconfig properly set the IW_ENCODE_NOKEY flag
  5492. * when no key is present (only change flags), but older versions
  5493. * don't do it. - Jean II */
  5494. if (dwrq->length > 0) {
  5495. wep_key_t key;
  5496. int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
  5497. int current_index = get_wep_key(local, 0xffff);
  5498. /* Check the size of the key */
  5499. if (dwrq->length > MAX_KEY_SIZE) {
  5500. return -EINVAL;
  5501. }
  5502. /* Check the index (none -> use current) */
  5503. if ((index < 0) || (index >= ((cap_rid.softCap & 0x80) ? 4:1)))
  5504. index = current_index;
  5505. /* Set the length */
  5506. if (dwrq->length > MIN_KEY_SIZE)
  5507. key.len = MAX_KEY_SIZE;
  5508. else
  5509. if (dwrq->length > 0)
  5510. key.len = MIN_KEY_SIZE;
  5511. else
  5512. /* Disable the key */
  5513. key.len = 0;
  5514. /* Check if the key is not marked as invalid */
  5515. if(!(dwrq->flags & IW_ENCODE_NOKEY)) {
  5516. /* Cleanup */
  5517. memset(key.key, 0, MAX_KEY_SIZE);
  5518. /* Copy the key in the driver */
  5519. memcpy(key.key, extra, dwrq->length);
  5520. /* Send the key to the card */
  5521. set_wep_key(local, index, key.key, key.len, 1, 1);
  5522. }
  5523. /* WE specify that if a valid key is set, encryption
  5524. * should be enabled (user may turn it off later)
  5525. * This is also how "iwconfig ethX key on" works */
  5526. if((index == current_index) && (key.len > 0) &&
  5527. (local->config.authType == AUTH_OPEN)) {
  5528. local->config.authType = AUTH_ENCRYPT;
  5529. set_bit (FLAG_COMMIT, &local->flags);
  5530. }
  5531. } else {
  5532. /* Do we want to just set the transmit key index ? */
  5533. int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
  5534. if ((index >= 0) && (index < ((cap_rid.softCap & 0x80)?4:1))) {
  5535. set_wep_key(local, index, NULL, 0, 1, 1);
  5536. } else
  5537. /* Don't complain if only change the mode */
  5538. if(!dwrq->flags & IW_ENCODE_MODE) {
  5539. return -EINVAL;
  5540. }
  5541. }
  5542. /* Read the flags */
  5543. if(dwrq->flags & IW_ENCODE_DISABLED)
  5544. local->config.authType = AUTH_OPEN; // disable encryption
  5545. if(dwrq->flags & IW_ENCODE_RESTRICTED)
  5546. local->config.authType = AUTH_SHAREDKEY; // Only Both
  5547. if(dwrq->flags & IW_ENCODE_OPEN)
  5548. local->config.authType = AUTH_ENCRYPT; // Only Wep
  5549. /* Commit the changes to flags if needed */
  5550. if(dwrq->flags & IW_ENCODE_MODE)
  5551. set_bit (FLAG_COMMIT, &local->flags);
  5552. return -EINPROGRESS; /* Call commit handler */
  5553. }
  5554. /*------------------------------------------------------------------*/
  5555. /*
  5556. * Wireless Handler : get Encryption Key
  5557. */
  5558. static int airo_get_encode(struct net_device *dev,
  5559. struct iw_request_info *info,
  5560. struct iw_point *dwrq,
  5561. char *extra)
  5562. {
  5563. struct airo_info *local = dev->priv;
  5564. int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
  5565. CapabilityRid cap_rid; /* Card capability info */
  5566. /* Is it supported ? */
  5567. readCapabilityRid(local, &cap_rid, 1);
  5568. if(!(cap_rid.softCap & 2)) {
  5569. return -EOPNOTSUPP;
  5570. }
  5571. readConfigRid(local, 1);
  5572. /* Check encryption mode */
  5573. switch(local->config.authType) {
  5574. case AUTH_ENCRYPT:
  5575. dwrq->flags = IW_ENCODE_OPEN;
  5576. break;
  5577. case AUTH_SHAREDKEY:
  5578. dwrq->flags = IW_ENCODE_RESTRICTED;
  5579. break;
  5580. default:
  5581. case AUTH_OPEN:
  5582. dwrq->flags = IW_ENCODE_DISABLED;
  5583. break;
  5584. }
  5585. /* We can't return the key, so set the proper flag and return zero */
  5586. dwrq->flags |= IW_ENCODE_NOKEY;
  5587. memset(extra, 0, 16);
  5588. /* Which key do we want ? -1 -> tx index */
  5589. if ((index < 0) || (index >= ((cap_rid.softCap & 0x80) ? 4 : 1)))
  5590. index = get_wep_key(local, 0xffff);
  5591. dwrq->flags |= index + 1;
  5592. /* Copy the key to the user buffer */
  5593. dwrq->length = get_wep_key(local, index);
  5594. if (dwrq->length > 16) {
  5595. dwrq->length=0;
  5596. }
  5597. return 0;
  5598. }
  5599. /*------------------------------------------------------------------*/
  5600. /*
  5601. * Wireless Handler : set Tx-Power
  5602. */
  5603. static int airo_set_txpow(struct net_device *dev,
  5604. struct iw_request_info *info,
  5605. struct iw_param *vwrq,
  5606. char *extra)
  5607. {
  5608. struct airo_info *local = dev->priv;
  5609. CapabilityRid cap_rid; /* Card capability info */
  5610. int i;
  5611. int rc = -EINVAL;
  5612. readCapabilityRid(local, &cap_rid, 1);
  5613. if (vwrq->disabled) {
  5614. set_bit (FLAG_RADIO_OFF, &local->flags);
  5615. set_bit (FLAG_COMMIT, &local->flags);
  5616. return -EINPROGRESS; /* Call commit handler */
  5617. }
  5618. if (vwrq->flags != IW_TXPOW_MWATT) {
  5619. return -EINVAL;
  5620. }
  5621. clear_bit (FLAG_RADIO_OFF, &local->flags);
  5622. for (i = 0; cap_rid.txPowerLevels[i] && (i < 8); i++)
  5623. if ((vwrq->value==cap_rid.txPowerLevels[i])) {
  5624. readConfigRid(local, 1);
  5625. local->config.txPower = vwrq->value;
  5626. set_bit (FLAG_COMMIT, &local->flags);
  5627. rc = -EINPROGRESS; /* Call commit handler */
  5628. break;
  5629. }
  5630. return rc;
  5631. }
  5632. /*------------------------------------------------------------------*/
  5633. /*
  5634. * Wireless Handler : get Tx-Power
  5635. */
  5636. static int airo_get_txpow(struct net_device *dev,
  5637. struct iw_request_info *info,
  5638. struct iw_param *vwrq,
  5639. char *extra)
  5640. {
  5641. struct airo_info *local = dev->priv;
  5642. readConfigRid(local, 1);
  5643. vwrq->value = local->config.txPower;
  5644. vwrq->fixed = 1; /* No power control */
  5645. vwrq->disabled = test_bit(FLAG_RADIO_OFF, &local->flags);
  5646. vwrq->flags = IW_TXPOW_MWATT;
  5647. return 0;
  5648. }
  5649. /*------------------------------------------------------------------*/
  5650. /*
  5651. * Wireless Handler : set Retry limits
  5652. */
  5653. static int airo_set_retry(struct net_device *dev,
  5654. struct iw_request_info *info,
  5655. struct iw_param *vwrq,
  5656. char *extra)
  5657. {
  5658. struct airo_info *local = dev->priv;
  5659. int rc = -EINVAL;
  5660. if(vwrq->disabled) {
  5661. return -EINVAL;
  5662. }
  5663. readConfigRid(local, 1);
  5664. if(vwrq->flags & IW_RETRY_LIMIT) {
  5665. if(vwrq->flags & IW_RETRY_MAX)
  5666. local->config.longRetryLimit = vwrq->value;
  5667. else if (vwrq->flags & IW_RETRY_MIN)
  5668. local->config.shortRetryLimit = vwrq->value;
  5669. else {
  5670. /* No modifier : set both */
  5671. local->config.longRetryLimit = vwrq->value;
  5672. local->config.shortRetryLimit = vwrq->value;
  5673. }
  5674. set_bit (FLAG_COMMIT, &local->flags);
  5675. rc = -EINPROGRESS; /* Call commit handler */
  5676. }
  5677. if(vwrq->flags & IW_RETRY_LIFETIME) {
  5678. local->config.txLifetime = vwrq->value / 1024;
  5679. set_bit (FLAG_COMMIT, &local->flags);
  5680. rc = -EINPROGRESS; /* Call commit handler */
  5681. }
  5682. return rc;
  5683. }
  5684. /*------------------------------------------------------------------*/
  5685. /*
  5686. * Wireless Handler : get Retry limits
  5687. */
  5688. static int airo_get_retry(struct net_device *dev,
  5689. struct iw_request_info *info,
  5690. struct iw_param *vwrq,
  5691. char *extra)
  5692. {
  5693. struct airo_info *local = dev->priv;
  5694. vwrq->disabled = 0; /* Can't be disabled */
  5695. readConfigRid(local, 1);
  5696. /* Note : by default, display the min retry number */
  5697. if((vwrq->flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
  5698. vwrq->flags = IW_RETRY_LIFETIME;
  5699. vwrq->value = (int)local->config.txLifetime * 1024;
  5700. } else if((vwrq->flags & IW_RETRY_MAX)) {
  5701. vwrq->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
  5702. vwrq->value = (int)local->config.longRetryLimit;
  5703. } else {
  5704. vwrq->flags = IW_RETRY_LIMIT;
  5705. vwrq->value = (int)local->config.shortRetryLimit;
  5706. if((int)local->config.shortRetryLimit != (int)local->config.longRetryLimit)
  5707. vwrq->flags |= IW_RETRY_MIN;
  5708. }
  5709. return 0;
  5710. }
  5711. /*------------------------------------------------------------------*/
  5712. /*
  5713. * Wireless Handler : get range info
  5714. */
  5715. static int airo_get_range(struct net_device *dev,
  5716. struct iw_request_info *info,
  5717. struct iw_point *dwrq,
  5718. char *extra)
  5719. {
  5720. struct airo_info *local = dev->priv;
  5721. struct iw_range *range = (struct iw_range *) extra;
  5722. CapabilityRid cap_rid; /* Card capability info */
  5723. int i;
  5724. int k;
  5725. readCapabilityRid(local, &cap_rid, 1);
  5726. dwrq->length = sizeof(struct iw_range);
  5727. memset(range, 0, sizeof(*range));
  5728. range->min_nwid = 0x0000;
  5729. range->max_nwid = 0x0000;
  5730. range->num_channels = 14;
  5731. /* Should be based on cap_rid.country to give only
  5732. * what the current card support */
  5733. k = 0;
  5734. for(i = 0; i < 14; i++) {
  5735. range->freq[k].i = i + 1; /* List index */
  5736. range->freq[k].m = frequency_list[i] * 100000;
  5737. range->freq[k++].e = 1; /* Values in table in MHz -> * 10^5 * 10 */
  5738. }
  5739. range->num_frequency = k;
  5740. range->sensitivity = 65535;
  5741. /* Hum... Should put the right values there */
  5742. if (local->rssi)
  5743. range->max_qual.qual = 100; /* % */
  5744. else
  5745. range->max_qual.qual = airo_get_max_quality(&cap_rid);
  5746. range->max_qual.level = 0x100 - 120; /* -120 dBm */
  5747. range->max_qual.noise = 0x100 - 120; /* -120 dBm */
  5748. /* Experimental measurements - boundary 11/5.5 Mb/s */
  5749. /* Note : with or without the (local->rssi), results
  5750. * are somewhat different. - Jean II */
  5751. if (local->rssi) {
  5752. range->avg_qual.qual = 50; /* % */
  5753. range->avg_qual.level = 0x100 - 70; /* -70 dBm */
  5754. } else {
  5755. range->avg_qual.qual = airo_get_avg_quality(&cap_rid);
  5756. range->avg_qual.level = 0x100 - 80; /* -80 dBm */
  5757. }
  5758. range->avg_qual.noise = 0x100 - 85; /* -85 dBm */
  5759. for(i = 0 ; i < 8 ; i++) {
  5760. range->bitrate[i] = cap_rid.supportedRates[i] * 500000;
  5761. if(range->bitrate[i] == 0)
  5762. break;
  5763. }
  5764. range->num_bitrates = i;
  5765. /* Set an indication of the max TCP throughput
  5766. * in bit/s that we can expect using this interface.
  5767. * May be use for QoS stuff... Jean II */
  5768. if(i > 2)
  5769. range->throughput = 5000 * 1000;
  5770. else
  5771. range->throughput = 1500 * 1000;
  5772. range->min_rts = 0;
  5773. range->max_rts = 2312;
  5774. range->min_frag = 256;
  5775. range->max_frag = 2312;
  5776. if(cap_rid.softCap & 2) {
  5777. // WEP: RC4 40 bits
  5778. range->encoding_size[0] = 5;
  5779. // RC4 ~128 bits
  5780. if (cap_rid.softCap & 0x100) {
  5781. range->encoding_size[1] = 13;
  5782. range->num_encoding_sizes = 2;
  5783. } else
  5784. range->num_encoding_sizes = 1;
  5785. range->max_encoding_tokens = (cap_rid.softCap & 0x80) ? 4 : 1;
  5786. } else {
  5787. range->num_encoding_sizes = 0;
  5788. range->max_encoding_tokens = 0;
  5789. }
  5790. range->min_pmp = 0;
  5791. range->max_pmp = 5000000; /* 5 secs */
  5792. range->min_pmt = 0;
  5793. range->max_pmt = 65535 * 1024; /* ??? */
  5794. range->pmp_flags = IW_POWER_PERIOD;
  5795. range->pmt_flags = IW_POWER_TIMEOUT;
  5796. range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT | IW_POWER_ALL_R;
  5797. /* Transmit Power - values are in mW */
  5798. for(i = 0 ; i < 8 ; i++) {
  5799. range->txpower[i] = cap_rid.txPowerLevels[i];
  5800. if(range->txpower[i] == 0)
  5801. break;
  5802. }
  5803. range->num_txpower = i;
  5804. range->txpower_capa = IW_TXPOW_MWATT;
  5805. range->we_version_source = 12;
  5806. range->we_version_compiled = WIRELESS_EXT;
  5807. range->retry_capa = IW_RETRY_LIMIT | IW_RETRY_LIFETIME;
  5808. range->retry_flags = IW_RETRY_LIMIT;
  5809. range->r_time_flags = IW_RETRY_LIFETIME;
  5810. range->min_retry = 1;
  5811. range->max_retry = 65535;
  5812. range->min_r_time = 1024;
  5813. range->max_r_time = 65535 * 1024;
  5814. /* Event capability (kernel + driver) */
  5815. range->event_capa[0] = (IW_EVENT_CAPA_K_0 |
  5816. IW_EVENT_CAPA_MASK(SIOCGIWTHRSPY) |
  5817. IW_EVENT_CAPA_MASK(SIOCGIWAP) |
  5818. IW_EVENT_CAPA_MASK(SIOCGIWSCAN));
  5819. range->event_capa[1] = IW_EVENT_CAPA_K_1;
  5820. range->event_capa[4] = IW_EVENT_CAPA_MASK(IWEVTXDROP);
  5821. return 0;
  5822. }
  5823. /*------------------------------------------------------------------*/
  5824. /*
  5825. * Wireless Handler : set Power Management
  5826. */
  5827. static int airo_set_power(struct net_device *dev,
  5828. struct iw_request_info *info,
  5829. struct iw_param *vwrq,
  5830. char *extra)
  5831. {
  5832. struct airo_info *local = dev->priv;
  5833. readConfigRid(local, 1);
  5834. if (vwrq->disabled) {
  5835. if ((local->config.rmode & 0xFF) >= RXMODE_RFMON) {
  5836. return -EINVAL;
  5837. }
  5838. local->config.powerSaveMode = POWERSAVE_CAM;
  5839. local->config.rmode &= 0xFF00;
  5840. local->config.rmode |= RXMODE_BC_MC_ADDR;
  5841. set_bit (FLAG_COMMIT, &local->flags);
  5842. return -EINPROGRESS; /* Call commit handler */
  5843. }
  5844. if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
  5845. local->config.fastListenDelay = (vwrq->value + 500) / 1024;
  5846. local->config.powerSaveMode = POWERSAVE_PSPCAM;
  5847. set_bit (FLAG_COMMIT, &local->flags);
  5848. } else if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_PERIOD) {
  5849. local->config.fastListenInterval = local->config.listenInterval = (vwrq->value + 500) / 1024;
  5850. local->config.powerSaveMode = POWERSAVE_PSPCAM;
  5851. set_bit (FLAG_COMMIT, &local->flags);
  5852. }
  5853. switch (vwrq->flags & IW_POWER_MODE) {
  5854. case IW_POWER_UNICAST_R:
  5855. if ((local->config.rmode & 0xFF) >= RXMODE_RFMON) {
  5856. return -EINVAL;
  5857. }
  5858. local->config.rmode &= 0xFF00;
  5859. local->config.rmode |= RXMODE_ADDR;
  5860. set_bit (FLAG_COMMIT, &local->flags);
  5861. break;
  5862. case IW_POWER_ALL_R:
  5863. if ((local->config.rmode & 0xFF) >= RXMODE_RFMON) {
  5864. return -EINVAL;
  5865. }
  5866. local->config.rmode &= 0xFF00;
  5867. local->config.rmode |= RXMODE_BC_MC_ADDR;
  5868. set_bit (FLAG_COMMIT, &local->flags);
  5869. case IW_POWER_ON:
  5870. break;
  5871. default:
  5872. return -EINVAL;
  5873. }
  5874. // Note : we may want to factor local->need_commit here
  5875. // Note2 : may also want to factor RXMODE_RFMON test
  5876. return -EINPROGRESS; /* Call commit handler */
  5877. }
  5878. /*------------------------------------------------------------------*/
  5879. /*
  5880. * Wireless Handler : get Power Management
  5881. */
  5882. static int airo_get_power(struct net_device *dev,
  5883. struct iw_request_info *info,
  5884. struct iw_param *vwrq,
  5885. char *extra)
  5886. {
  5887. struct airo_info *local = dev->priv;
  5888. int mode;
  5889. readConfigRid(local, 1);
  5890. mode = local->config.powerSaveMode;
  5891. if ((vwrq->disabled = (mode == POWERSAVE_CAM)))
  5892. return 0;
  5893. if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
  5894. vwrq->value = (int)local->config.fastListenDelay * 1024;
  5895. vwrq->flags = IW_POWER_TIMEOUT;
  5896. } else {
  5897. vwrq->value = (int)local->config.fastListenInterval * 1024;
  5898. vwrq->flags = IW_POWER_PERIOD;
  5899. }
  5900. if ((local->config.rmode & 0xFF) == RXMODE_ADDR)
  5901. vwrq->flags |= IW_POWER_UNICAST_R;
  5902. else
  5903. vwrq->flags |= IW_POWER_ALL_R;
  5904. return 0;
  5905. }
  5906. /*------------------------------------------------------------------*/
  5907. /*
  5908. * Wireless Handler : set Sensitivity
  5909. */
  5910. static int airo_set_sens(struct net_device *dev,
  5911. struct iw_request_info *info,
  5912. struct iw_param *vwrq,
  5913. char *extra)
  5914. {
  5915. struct airo_info *local = dev->priv;
  5916. readConfigRid(local, 1);
  5917. local->config.rssiThreshold = vwrq->disabled ? RSSI_DEFAULT : vwrq->value;
  5918. set_bit (FLAG_COMMIT, &local->flags);
  5919. return -EINPROGRESS; /* Call commit handler */
  5920. }
  5921. /*------------------------------------------------------------------*/
  5922. /*
  5923. * Wireless Handler : get Sensitivity
  5924. */
  5925. static int airo_get_sens(struct net_device *dev,
  5926. struct iw_request_info *info,
  5927. struct iw_param *vwrq,
  5928. char *extra)
  5929. {
  5930. struct airo_info *local = dev->priv;
  5931. readConfigRid(local, 1);
  5932. vwrq->value = local->config.rssiThreshold;
  5933. vwrq->disabled = (vwrq->value == 0);
  5934. vwrq->fixed = 1;
  5935. return 0;
  5936. }
  5937. /*------------------------------------------------------------------*/
  5938. /*
  5939. * Wireless Handler : get AP List
  5940. * Note : this is deprecated in favor of IWSCAN
  5941. */
  5942. static int airo_get_aplist(struct net_device *dev,
  5943. struct iw_request_info *info,
  5944. struct iw_point *dwrq,
  5945. char *extra)
  5946. {
  5947. struct airo_info *local = dev->priv;
  5948. struct sockaddr *address = (struct sockaddr *) extra;
  5949. struct iw_quality qual[IW_MAX_AP];
  5950. BSSListRid BSSList;
  5951. int i;
  5952. int loseSync = capable(CAP_NET_ADMIN) ? 1: -1;
  5953. for (i = 0; i < IW_MAX_AP; i++) {
  5954. if (readBSSListRid(local, loseSync, &BSSList))
  5955. break;
  5956. loseSync = 0;
  5957. memcpy(address[i].sa_data, BSSList.bssid, ETH_ALEN);
  5958. address[i].sa_family = ARPHRD_ETHER;
  5959. if (local->rssi) {
  5960. qual[i].level = 0x100 - BSSList.dBm;
  5961. qual[i].qual = airo_dbm_to_pct( local->rssi, BSSList.dBm );
  5962. qual[i].updated = IW_QUAL_QUAL_UPDATED
  5963. | IW_QUAL_LEVEL_UPDATED
  5964. | IW_QUAL_DBM;
  5965. } else {
  5966. qual[i].level = (BSSList.dBm + 321) / 2;
  5967. qual[i].qual = 0;
  5968. qual[i].updated = IW_QUAL_QUAL_INVALID
  5969. | IW_QUAL_LEVEL_UPDATED
  5970. | IW_QUAL_DBM;
  5971. }
  5972. qual[i].noise = local->wstats.qual.noise;
  5973. if (BSSList.index == 0xffff)
  5974. break;
  5975. }
  5976. if (!i) {
  5977. StatusRid status_rid; /* Card status info */
  5978. readStatusRid(local, &status_rid, 1);
  5979. for (i = 0;
  5980. i < min(IW_MAX_AP, 4) &&
  5981. (status_rid.bssid[i][0]
  5982. & status_rid.bssid[i][1]
  5983. & status_rid.bssid[i][2]
  5984. & status_rid.bssid[i][3]
  5985. & status_rid.bssid[i][4]
  5986. & status_rid.bssid[i][5])!=0xff &&
  5987. (status_rid.bssid[i][0]
  5988. | status_rid.bssid[i][1]
  5989. | status_rid.bssid[i][2]
  5990. | status_rid.bssid[i][3]
  5991. | status_rid.bssid[i][4]
  5992. | status_rid.bssid[i][5]);
  5993. i++) {
  5994. memcpy(address[i].sa_data,
  5995. status_rid.bssid[i], ETH_ALEN);
  5996. address[i].sa_family = ARPHRD_ETHER;
  5997. }
  5998. } else {
  5999. dwrq->flags = 1; /* Should be define'd */
  6000. memcpy(extra + sizeof(struct sockaddr)*i,
  6001. &qual, sizeof(struct iw_quality)*i);
  6002. }
  6003. dwrq->length = i;
  6004. return 0;
  6005. }
  6006. /*------------------------------------------------------------------*/
  6007. /*
  6008. * Wireless Handler : Initiate Scan
  6009. */
  6010. static int airo_set_scan(struct net_device *dev,
  6011. struct iw_request_info *info,
  6012. struct iw_param *vwrq,
  6013. char *extra)
  6014. {
  6015. struct airo_info *ai = dev->priv;
  6016. Cmd cmd;
  6017. Resp rsp;
  6018. /* Note : you may have realised that, as this is a SET operation,
  6019. * this is privileged and therefore a normal user can't
  6020. * perform scanning.
  6021. * This is not an error, while the device perform scanning,
  6022. * traffic doesn't flow, so it's a perfect DoS...
  6023. * Jean II */
  6024. if (ai->flags & FLAG_RADIO_MASK) return -ENETDOWN;
  6025. /* Initiate a scan command */
  6026. memset(&cmd, 0, sizeof(cmd));
  6027. cmd.cmd=CMD_LISTBSS;
  6028. if (down_interruptible(&ai->sem))
  6029. return -ERESTARTSYS;
  6030. issuecommand(ai, &cmd, &rsp);
  6031. ai->scan_timestamp = jiffies;
  6032. up(&ai->sem);
  6033. /* At this point, just return to the user. */
  6034. return 0;
  6035. }
  6036. /*------------------------------------------------------------------*/
  6037. /*
  6038. * Translate scan data returned from the card to a card independent
  6039. * format that the Wireless Tools will understand - Jean II
  6040. */
  6041. static inline char *airo_translate_scan(struct net_device *dev,
  6042. char *current_ev,
  6043. char *end_buf,
  6044. BSSListRid *bss)
  6045. {
  6046. struct airo_info *ai = dev->priv;
  6047. struct iw_event iwe; /* Temporary buffer */
  6048. u16 capabilities;
  6049. char * current_val; /* For rates */
  6050. int i;
  6051. /* First entry *MUST* be the AP MAC address */
  6052. iwe.cmd = SIOCGIWAP;
  6053. iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
  6054. memcpy(iwe.u.ap_addr.sa_data, bss->bssid, ETH_ALEN);
  6055. current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_ADDR_LEN);
  6056. /* Other entries will be displayed in the order we give them */
  6057. /* Add the ESSID */
  6058. iwe.u.data.length = bss->ssidLen;
  6059. if(iwe.u.data.length > 32)
  6060. iwe.u.data.length = 32;
  6061. iwe.cmd = SIOCGIWESSID;
  6062. iwe.u.data.flags = 1;
  6063. current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, bss->ssid);
  6064. /* Add mode */
  6065. iwe.cmd = SIOCGIWMODE;
  6066. capabilities = le16_to_cpu(bss->cap);
  6067. if(capabilities & (CAP_ESS | CAP_IBSS)) {
  6068. if(capabilities & CAP_ESS)
  6069. iwe.u.mode = IW_MODE_MASTER;
  6070. else
  6071. iwe.u.mode = IW_MODE_ADHOC;
  6072. current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_UINT_LEN);
  6073. }
  6074. /* Add frequency */
  6075. iwe.cmd = SIOCGIWFREQ;
  6076. iwe.u.freq.m = le16_to_cpu(bss->dsChannel);
  6077. /* iwe.u.freq.m containt the channel (starting 1), our
  6078. * frequency_list array start at index 0...
  6079. */
  6080. iwe.u.freq.m = frequency_list[iwe.u.freq.m - 1] * 100000;
  6081. iwe.u.freq.e = 1;
  6082. current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_FREQ_LEN);
  6083. /* Add quality statistics */
  6084. iwe.cmd = IWEVQUAL;
  6085. if (ai->rssi) {
  6086. iwe.u.qual.level = 0x100 - bss->dBm;
  6087. iwe.u.qual.qual = airo_dbm_to_pct( ai->rssi, bss->dBm );
  6088. iwe.u.qual.updated = IW_QUAL_QUAL_UPDATED
  6089. | IW_QUAL_LEVEL_UPDATED
  6090. | IW_QUAL_DBM;
  6091. } else {
  6092. iwe.u.qual.level = (bss->dBm + 321) / 2;
  6093. iwe.u.qual.qual = 0;
  6094. iwe.u.qual.updated = IW_QUAL_QUAL_INVALID
  6095. | IW_QUAL_LEVEL_UPDATED
  6096. | IW_QUAL_DBM;
  6097. }
  6098. iwe.u.qual.noise = ai->wstats.qual.noise;
  6099. current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_QUAL_LEN);
  6100. /* Add encryption capability */
  6101. iwe.cmd = SIOCGIWENCODE;
  6102. if(capabilities & CAP_PRIVACY)
  6103. iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
  6104. else
  6105. iwe.u.data.flags = IW_ENCODE_DISABLED;
  6106. iwe.u.data.length = 0;
  6107. current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, bss->ssid);
  6108. /* Rate : stuffing multiple values in a single event require a bit
  6109. * more of magic - Jean II */
  6110. current_val = current_ev + IW_EV_LCP_LEN;
  6111. iwe.cmd = SIOCGIWRATE;
  6112. /* Those two flags are ignored... */
  6113. iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
  6114. /* Max 8 values */
  6115. for(i = 0 ; i < 8 ; i++) {
  6116. /* NULL terminated */
  6117. if(bss->rates[i] == 0)
  6118. break;
  6119. /* Bit rate given in 500 kb/s units (+ 0x80) */
  6120. iwe.u.bitrate.value = ((bss->rates[i] & 0x7f) * 500000);
  6121. /* Add new value to event */
  6122. current_val = iwe_stream_add_value(current_ev, current_val, end_buf, &iwe, IW_EV_PARAM_LEN);
  6123. }
  6124. /* Check if we added any event */
  6125. if((current_val - current_ev) > IW_EV_LCP_LEN)
  6126. current_ev = current_val;
  6127. /* The other data in the scan result are not really
  6128. * interesting, so for now drop it - Jean II */
  6129. return current_ev;
  6130. }
  6131. /*------------------------------------------------------------------*/
  6132. /*
  6133. * Wireless Handler : Read Scan Results
  6134. */
  6135. static int airo_get_scan(struct net_device *dev,
  6136. struct iw_request_info *info,
  6137. struct iw_point *dwrq,
  6138. char *extra)
  6139. {
  6140. struct airo_info *ai = dev->priv;
  6141. BSSListRid BSSList;
  6142. int rc;
  6143. char *current_ev = extra;
  6144. /* When we are associated again, the scan has surely finished.
  6145. * Just in case, let's make sure enough time has elapsed since
  6146. * we started the scan. - Javier */
  6147. if(ai->scan_timestamp && time_before(jiffies,ai->scan_timestamp+3*HZ)) {
  6148. /* Important note : we don't want to block the caller
  6149. * until results are ready for various reasons.
  6150. * First, managing wait queues is complex and racy
  6151. * (there may be multiple simultaneous callers).
  6152. * Second, we grab some rtnetlink lock before comming
  6153. * here (in dev_ioctl()).
  6154. * Third, the caller can wait on the Wireless Event
  6155. * - Jean II */
  6156. return -EAGAIN;
  6157. }
  6158. ai->scan_timestamp = 0;
  6159. /* There's only a race with proc_BSSList_open(), but its
  6160. * consequences are begnign. So I don't bother fixing it - Javier */
  6161. /* Try to read the first entry of the scan result */
  6162. rc = PC4500_readrid(ai, RID_BSSLISTFIRST, &BSSList, sizeof(BSSList), 1);
  6163. if((rc) || (BSSList.index == 0xffff)) {
  6164. /* Client error, no scan results...
  6165. * The caller need to restart the scan. */
  6166. return -ENODATA;
  6167. }
  6168. /* Read and parse all entries */
  6169. while((!rc) && (BSSList.index != 0xffff)) {
  6170. /* Translate to WE format this entry */
  6171. current_ev = airo_translate_scan(dev, current_ev,
  6172. extra + dwrq->length,
  6173. &BSSList);
  6174. /* Check if there is space for one more entry */
  6175. if((extra + dwrq->length - current_ev) <= IW_EV_ADDR_LEN) {
  6176. /* Ask user space to try again with a bigger buffer */
  6177. return -E2BIG;
  6178. }
  6179. /* Read next entry */
  6180. rc = PC4500_readrid(ai, RID_BSSLISTNEXT,
  6181. &BSSList, sizeof(BSSList), 1);
  6182. }
  6183. /* Length of data */
  6184. dwrq->length = (current_ev - extra);
  6185. dwrq->flags = 0; /* todo */
  6186. return 0;
  6187. }
  6188. /*------------------------------------------------------------------*/
  6189. /*
  6190. * Commit handler : called after a bunch of SET operations
  6191. */
  6192. static int airo_config_commit(struct net_device *dev,
  6193. struct iw_request_info *info, /* NULL */
  6194. void *zwrq, /* NULL */
  6195. char *extra) /* NULL */
  6196. {
  6197. struct airo_info *local = dev->priv;
  6198. Resp rsp;
  6199. if (!test_bit (FLAG_COMMIT, &local->flags))
  6200. return 0;
  6201. /* Some of the "SET" function may have modified some of the
  6202. * parameters. It's now time to commit them in the card */
  6203. disable_MAC(local, 1);
  6204. if (test_bit (FLAG_RESET, &local->flags)) {
  6205. APListRid APList_rid;
  6206. SsidRid SSID_rid;
  6207. readAPListRid(local, &APList_rid);
  6208. readSsidRid(local, &SSID_rid);
  6209. if (test_bit(FLAG_MPI,&local->flags))
  6210. setup_card(local, dev->dev_addr, 1 );
  6211. else
  6212. reset_airo_card(dev);
  6213. disable_MAC(local, 1);
  6214. writeSsidRid(local, &SSID_rid, 1);
  6215. writeAPListRid(local, &APList_rid, 1);
  6216. }
  6217. if (down_interruptible(&local->sem))
  6218. return -ERESTARTSYS;
  6219. writeConfigRid(local, 0);
  6220. enable_MAC(local, &rsp, 0);
  6221. if (test_bit (FLAG_RESET, &local->flags))
  6222. airo_set_promisc(local);
  6223. else
  6224. up(&local->sem);
  6225. return 0;
  6226. }
  6227. /*------------------------------------------------------------------*/
  6228. /*
  6229. * Structures to export the Wireless Handlers
  6230. */
  6231. static const struct iw_priv_args airo_private_args[] = {
  6232. /*{ cmd, set_args, get_args, name } */
  6233. { AIROIOCTL, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | sizeof (aironet_ioctl),
  6234. IW_PRIV_TYPE_BYTE | 2047, "airoioctl" },
  6235. { AIROIDIFC, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | sizeof (aironet_ioctl),
  6236. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "airoidifc" },
  6237. };
  6238. static const iw_handler airo_handler[] =
  6239. {
  6240. (iw_handler) airo_config_commit, /* SIOCSIWCOMMIT */
  6241. (iw_handler) airo_get_name, /* SIOCGIWNAME */
  6242. (iw_handler) NULL, /* SIOCSIWNWID */
  6243. (iw_handler) NULL, /* SIOCGIWNWID */
  6244. (iw_handler) airo_set_freq, /* SIOCSIWFREQ */
  6245. (iw_handler) airo_get_freq, /* SIOCGIWFREQ */
  6246. (iw_handler) airo_set_mode, /* SIOCSIWMODE */
  6247. (iw_handler) airo_get_mode, /* SIOCGIWMODE */
  6248. (iw_handler) airo_set_sens, /* SIOCSIWSENS */
  6249. (iw_handler) airo_get_sens, /* SIOCGIWSENS */
  6250. (iw_handler) NULL, /* SIOCSIWRANGE */
  6251. (iw_handler) airo_get_range, /* SIOCGIWRANGE */
  6252. (iw_handler) NULL, /* SIOCSIWPRIV */
  6253. (iw_handler) NULL, /* SIOCGIWPRIV */
  6254. (iw_handler) NULL, /* SIOCSIWSTATS */
  6255. (iw_handler) NULL, /* SIOCGIWSTATS */
  6256. iw_handler_set_spy, /* SIOCSIWSPY */
  6257. iw_handler_get_spy, /* SIOCGIWSPY */
  6258. iw_handler_set_thrspy, /* SIOCSIWTHRSPY */
  6259. iw_handler_get_thrspy, /* SIOCGIWTHRSPY */
  6260. (iw_handler) airo_set_wap, /* SIOCSIWAP */
  6261. (iw_handler) airo_get_wap, /* SIOCGIWAP */
  6262. (iw_handler) NULL, /* -- hole -- */
  6263. (iw_handler) airo_get_aplist, /* SIOCGIWAPLIST */
  6264. (iw_handler) airo_set_scan, /* SIOCSIWSCAN */
  6265. (iw_handler) airo_get_scan, /* SIOCGIWSCAN */
  6266. (iw_handler) airo_set_essid, /* SIOCSIWESSID */
  6267. (iw_handler) airo_get_essid, /* SIOCGIWESSID */
  6268. (iw_handler) airo_set_nick, /* SIOCSIWNICKN */
  6269. (iw_handler) airo_get_nick, /* SIOCGIWNICKN */
  6270. (iw_handler) NULL, /* -- hole -- */
  6271. (iw_handler) NULL, /* -- hole -- */
  6272. (iw_handler) airo_set_rate, /* SIOCSIWRATE */
  6273. (iw_handler) airo_get_rate, /* SIOCGIWRATE */
  6274. (iw_handler) airo_set_rts, /* SIOCSIWRTS */
  6275. (iw_handler) airo_get_rts, /* SIOCGIWRTS */
  6276. (iw_handler) airo_set_frag, /* SIOCSIWFRAG */
  6277. (iw_handler) airo_get_frag, /* SIOCGIWFRAG */
  6278. (iw_handler) airo_set_txpow, /* SIOCSIWTXPOW */
  6279. (iw_handler) airo_get_txpow, /* SIOCGIWTXPOW */
  6280. (iw_handler) airo_set_retry, /* SIOCSIWRETRY */
  6281. (iw_handler) airo_get_retry, /* SIOCGIWRETRY */
  6282. (iw_handler) airo_set_encode, /* SIOCSIWENCODE */
  6283. (iw_handler) airo_get_encode, /* SIOCGIWENCODE */
  6284. (iw_handler) airo_set_power, /* SIOCSIWPOWER */
  6285. (iw_handler) airo_get_power, /* SIOCGIWPOWER */
  6286. };
  6287. /* Note : don't describe AIROIDIFC and AIROOLDIDIFC in here.
  6288. * We want to force the use of the ioctl code, because those can't be
  6289. * won't work the iw_handler code (because they simultaneously read
  6290. * and write data and iw_handler can't do that).
  6291. * Note that it's perfectly legal to read/write on a single ioctl command,
  6292. * you just can't use iwpriv and need to force it via the ioctl handler.
  6293. * Jean II */
  6294. static const iw_handler airo_private_handler[] =
  6295. {
  6296. NULL, /* SIOCIWFIRSTPRIV */
  6297. };
  6298. static const struct iw_handler_def airo_handler_def =
  6299. {
  6300. .num_standard = sizeof(airo_handler)/sizeof(iw_handler),
  6301. .num_private = sizeof(airo_private_handler)/sizeof(iw_handler),
  6302. .num_private_args = sizeof(airo_private_args)/sizeof(struct iw_priv_args),
  6303. .standard = airo_handler,
  6304. .private = airo_private_handler,
  6305. .private_args = airo_private_args,
  6306. .get_wireless_stats = airo_get_wireless_stats,
  6307. };
  6308. /*
  6309. * This defines the configuration part of the Wireless Extensions
  6310. * Note : irq and spinlock protection will occur in the subroutines
  6311. *
  6312. * TODO :
  6313. * o Check input value more carefully and fill correct values in range
  6314. * o Test and shakeout the bugs (if any)
  6315. *
  6316. * Jean II
  6317. *
  6318. * Javier Achirica did a great job of merging code from the unnamed CISCO
  6319. * developer that added support for flashing the card.
  6320. */
  6321. static int airo_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
  6322. {
  6323. int rc = 0;
  6324. struct airo_info *ai = (struct airo_info *)dev->priv;
  6325. if (ai->power.event)
  6326. return 0;
  6327. switch (cmd) {
  6328. #ifdef CISCO_EXT
  6329. case AIROIDIFC:
  6330. #ifdef AIROOLDIDIFC
  6331. case AIROOLDIDIFC:
  6332. #endif
  6333. {
  6334. int val = AIROMAGIC;
  6335. aironet_ioctl com;
  6336. if (copy_from_user(&com,rq->ifr_data,sizeof(com)))
  6337. rc = -EFAULT;
  6338. else if (copy_to_user(com.data,(char *)&val,sizeof(val)))
  6339. rc = -EFAULT;
  6340. }
  6341. break;
  6342. case AIROIOCTL:
  6343. #ifdef AIROOLDIOCTL
  6344. case AIROOLDIOCTL:
  6345. #endif
  6346. /* Get the command struct and hand it off for evaluation by
  6347. * the proper subfunction
  6348. */
  6349. {
  6350. aironet_ioctl com;
  6351. if (copy_from_user(&com,rq->ifr_data,sizeof(com))) {
  6352. rc = -EFAULT;
  6353. break;
  6354. }
  6355. /* Separate R/W functions bracket legality here
  6356. */
  6357. if ( com.command == AIRORSWVERSION ) {
  6358. if (copy_to_user(com.data, swversion, sizeof(swversion)))
  6359. rc = -EFAULT;
  6360. else
  6361. rc = 0;
  6362. }
  6363. else if ( com.command <= AIRORRID)
  6364. rc = readrids(dev,&com);
  6365. else if ( com.command >= AIROPCAP && com.command <= (AIROPLEAPUSR+2) )
  6366. rc = writerids(dev,&com);
  6367. else if ( com.command >= AIROFLSHRST && com.command <= AIRORESTART )
  6368. rc = flashcard(dev,&com);
  6369. else
  6370. rc = -EINVAL; /* Bad command in ioctl */
  6371. }
  6372. break;
  6373. #endif /* CISCO_EXT */
  6374. // All other calls are currently unsupported
  6375. default:
  6376. rc = -EOPNOTSUPP;
  6377. }
  6378. return rc;
  6379. }
  6380. /*
  6381. * Get the Wireless stats out of the driver
  6382. * Note : irq and spinlock protection will occur in the subroutines
  6383. *
  6384. * TODO :
  6385. * o Check if work in Ad-Hoc mode (otherwise, use SPY, as in wvlan_cs)
  6386. *
  6387. * Jean
  6388. */
  6389. static void airo_read_wireless_stats(struct airo_info *local)
  6390. {
  6391. StatusRid status_rid;
  6392. StatsRid stats_rid;
  6393. CapabilityRid cap_rid;
  6394. u32 *vals = stats_rid.vals;
  6395. /* Get stats out of the card */
  6396. clear_bit(JOB_WSTATS, &local->flags);
  6397. if (local->power.event) {
  6398. up(&local->sem);
  6399. return;
  6400. }
  6401. readCapabilityRid(local, &cap_rid, 0);
  6402. readStatusRid(local, &status_rid, 0);
  6403. readStatsRid(local, &stats_rid, RID_STATS, 0);
  6404. up(&local->sem);
  6405. /* The status */
  6406. local->wstats.status = status_rid.mode;
  6407. /* Signal quality and co */
  6408. if (local->rssi) {
  6409. local->wstats.qual.level = airo_rssi_to_dbm( local->rssi, status_rid.sigQuality );
  6410. /* normalizedSignalStrength appears to be a percentage */
  6411. local->wstats.qual.qual = status_rid.normalizedSignalStrength;
  6412. } else {
  6413. local->wstats.qual.level = (status_rid.normalizedSignalStrength + 321) / 2;
  6414. local->wstats.qual.qual = airo_get_quality(&status_rid, &cap_rid);
  6415. }
  6416. if (status_rid.len >= 124) {
  6417. local->wstats.qual.noise = 0x100 - status_rid.noisedBm;
  6418. local->wstats.qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
  6419. } else {
  6420. local->wstats.qual.noise = 0;
  6421. local->wstats.qual.updated = IW_QUAL_QUAL_UPDATED | IW_QUAL_LEVEL_UPDATED | IW_QUAL_NOISE_INVALID | IW_QUAL_DBM;
  6422. }
  6423. /* Packets discarded in the wireless adapter due to wireless
  6424. * specific problems */
  6425. local->wstats.discard.nwid = vals[56] + vals[57] + vals[58];/* SSID Mismatch */
  6426. local->wstats.discard.code = vals[6];/* RxWepErr */
  6427. local->wstats.discard.fragment = vals[30];
  6428. local->wstats.discard.retries = vals[10];
  6429. local->wstats.discard.misc = vals[1] + vals[32];
  6430. local->wstats.miss.beacon = vals[34];
  6431. }
  6432. static struct iw_statistics *airo_get_wireless_stats(struct net_device *dev)
  6433. {
  6434. struct airo_info *local = dev->priv;
  6435. if (!test_bit(JOB_WSTATS, &local->flags)) {
  6436. /* Get stats out of the card if available */
  6437. if (down_trylock(&local->sem) != 0) {
  6438. set_bit(JOB_WSTATS, &local->flags);
  6439. wake_up_interruptible(&local->thr_wait);
  6440. } else
  6441. airo_read_wireless_stats(local);
  6442. }
  6443. return &local->wstats;
  6444. }
  6445. #ifdef CISCO_EXT
  6446. /*
  6447. * This just translates from driver IOCTL codes to the command codes to
  6448. * feed to the radio's host interface. Things can be added/deleted
  6449. * as needed. This represents the READ side of control I/O to
  6450. * the card
  6451. */
  6452. static int readrids(struct net_device *dev, aironet_ioctl *comp) {
  6453. unsigned short ridcode;
  6454. unsigned char *iobuf;
  6455. int len;
  6456. struct airo_info *ai = dev->priv;
  6457. Resp rsp;
  6458. if (test_bit(FLAG_FLASHING, &ai->flags))
  6459. return -EIO;
  6460. switch(comp->command)
  6461. {
  6462. case AIROGCAP: ridcode = RID_CAPABILITIES; break;
  6463. case AIROGCFG: ridcode = RID_CONFIG;
  6464. if (test_bit(FLAG_COMMIT, &ai->flags)) {
  6465. disable_MAC (ai, 1);
  6466. writeConfigRid (ai, 1);
  6467. enable_MAC (ai, &rsp, 1);
  6468. }
  6469. break;
  6470. case AIROGSLIST: ridcode = RID_SSID; break;
  6471. case AIROGVLIST: ridcode = RID_APLIST; break;
  6472. case AIROGDRVNAM: ridcode = RID_DRVNAME; break;
  6473. case AIROGEHTENC: ridcode = RID_ETHERENCAP; break;
  6474. case AIROGWEPKTMP: ridcode = RID_WEP_TEMP;
  6475. /* Only super-user can read WEP keys */
  6476. if (!capable(CAP_NET_ADMIN))
  6477. return -EPERM;
  6478. break;
  6479. case AIROGWEPKNV: ridcode = RID_WEP_PERM;
  6480. /* Only super-user can read WEP keys */
  6481. if (!capable(CAP_NET_ADMIN))
  6482. return -EPERM;
  6483. break;
  6484. case AIROGSTAT: ridcode = RID_STATUS; break;
  6485. case AIROGSTATSD32: ridcode = RID_STATSDELTA; break;
  6486. case AIROGSTATSC32: ridcode = RID_STATS; break;
  6487. #ifdef MICSUPPORT
  6488. case AIROGMICSTATS:
  6489. if (copy_to_user(comp->data, &ai->micstats,
  6490. min((int)comp->len,(int)sizeof(ai->micstats))))
  6491. return -EFAULT;
  6492. return 0;
  6493. #endif
  6494. case AIRORRID: ridcode = comp->ridnum; break;
  6495. default:
  6496. return -EINVAL;
  6497. break;
  6498. }
  6499. if ((iobuf = kmalloc(RIDSIZE, GFP_KERNEL)) == NULL)
  6500. return -ENOMEM;
  6501. PC4500_readrid(ai,ridcode,iobuf,RIDSIZE, 1);
  6502. /* get the count of bytes in the rid docs say 1st 2 bytes is it.
  6503. * then return it to the user
  6504. * 9/22/2000 Honor user given length
  6505. */
  6506. len = comp->len;
  6507. if (copy_to_user(comp->data, iobuf, min(len, (int)RIDSIZE))) {
  6508. kfree (iobuf);
  6509. return -EFAULT;
  6510. }
  6511. kfree (iobuf);
  6512. return 0;
  6513. }
  6514. /*
  6515. * Danger Will Robinson write the rids here
  6516. */
  6517. static int writerids(struct net_device *dev, aironet_ioctl *comp) {
  6518. struct airo_info *ai = dev->priv;
  6519. int ridcode;
  6520. #ifdef MICSUPPORT
  6521. int enabled;
  6522. #endif
  6523. Resp rsp;
  6524. static int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
  6525. unsigned char *iobuf;
  6526. /* Only super-user can write RIDs */
  6527. if (!capable(CAP_NET_ADMIN))
  6528. return -EPERM;
  6529. if (test_bit(FLAG_FLASHING, &ai->flags))
  6530. return -EIO;
  6531. ridcode = 0;
  6532. writer = do_writerid;
  6533. switch(comp->command)
  6534. {
  6535. case AIROPSIDS: ridcode = RID_SSID; break;
  6536. case AIROPCAP: ridcode = RID_CAPABILITIES; break;
  6537. case AIROPAPLIST: ridcode = RID_APLIST; break;
  6538. case AIROPCFG: ai->config.len = 0;
  6539. clear_bit(FLAG_COMMIT, &ai->flags);
  6540. ridcode = RID_CONFIG; break;
  6541. case AIROPWEPKEYNV: ridcode = RID_WEP_PERM; break;
  6542. case AIROPLEAPUSR: ridcode = RID_LEAPUSERNAME; break;
  6543. case AIROPLEAPPWD: ridcode = RID_LEAPPASSWORD; break;
  6544. case AIROPWEPKEY: ridcode = RID_WEP_TEMP; writer = PC4500_writerid;
  6545. break;
  6546. case AIROPLEAPUSR+1: ridcode = 0xFF2A; break;
  6547. case AIROPLEAPUSR+2: ridcode = 0xFF2B; break;
  6548. /* this is not really a rid but a command given to the card
  6549. * same with MAC off
  6550. */
  6551. case AIROPMACON:
  6552. if (enable_MAC(ai, &rsp, 1) != 0)
  6553. return -EIO;
  6554. return 0;
  6555. /*
  6556. * Evidently this code in the airo driver does not get a symbol
  6557. * as disable_MAC. it's probably so short the compiler does not gen one.
  6558. */
  6559. case AIROPMACOFF:
  6560. disable_MAC(ai, 1);
  6561. return 0;
  6562. /* This command merely clears the counts does not actually store any data
  6563. * only reads rid. But as it changes the cards state, I put it in the
  6564. * writerid routines.
  6565. */
  6566. case AIROPSTCLR:
  6567. if ((iobuf = kmalloc(RIDSIZE, GFP_KERNEL)) == NULL)
  6568. return -ENOMEM;
  6569. PC4500_readrid(ai,RID_STATSDELTACLEAR,iobuf,RIDSIZE, 1);
  6570. #ifdef MICSUPPORT
  6571. enabled = ai->micstats.enabled;
  6572. memset(&ai->micstats,0,sizeof(ai->micstats));
  6573. ai->micstats.enabled = enabled;
  6574. #endif
  6575. if (copy_to_user(comp->data, iobuf,
  6576. min((int)comp->len, (int)RIDSIZE))) {
  6577. kfree (iobuf);
  6578. return -EFAULT;
  6579. }
  6580. kfree (iobuf);
  6581. return 0;
  6582. default:
  6583. return -EOPNOTSUPP; /* Blarg! */
  6584. }
  6585. if(comp->len > RIDSIZE)
  6586. return -EINVAL;
  6587. if ((iobuf = kmalloc(RIDSIZE, GFP_KERNEL)) == NULL)
  6588. return -ENOMEM;
  6589. if (copy_from_user(iobuf,comp->data,comp->len)) {
  6590. kfree (iobuf);
  6591. return -EFAULT;
  6592. }
  6593. if (comp->command == AIROPCFG) {
  6594. ConfigRid *cfg = (ConfigRid *)iobuf;
  6595. if (test_bit(FLAG_MIC_CAPABLE, &ai->flags))
  6596. cfg->opmode |= MODE_MIC;
  6597. if ((cfg->opmode & 0xFF) == MODE_STA_IBSS)
  6598. set_bit (FLAG_ADHOC, &ai->flags);
  6599. else
  6600. clear_bit (FLAG_ADHOC, &ai->flags);
  6601. }
  6602. if((*writer)(ai, ridcode, iobuf,comp->len,1)) {
  6603. kfree (iobuf);
  6604. return -EIO;
  6605. }
  6606. kfree (iobuf);
  6607. return 0;
  6608. }
  6609. /*****************************************************************************
  6610. * Ancillary flash / mod functions much black magic lurkes here *
  6611. *****************************************************************************
  6612. */
  6613. /*
  6614. * Flash command switch table
  6615. */
  6616. static int flashcard(struct net_device *dev, aironet_ioctl *comp) {
  6617. int z;
  6618. /* Only super-user can modify flash */
  6619. if (!capable(CAP_NET_ADMIN))
  6620. return -EPERM;
  6621. switch(comp->command)
  6622. {
  6623. case AIROFLSHRST:
  6624. return cmdreset((struct airo_info *)dev->priv);
  6625. case AIROFLSHSTFL:
  6626. if (!((struct airo_info *)dev->priv)->flash &&
  6627. (((struct airo_info *)dev->priv)->flash = kmalloc (FLASHSIZE, GFP_KERNEL)) == NULL)
  6628. return -ENOMEM;
  6629. return setflashmode((struct airo_info *)dev->priv);
  6630. case AIROFLSHGCHR: /* Get char from aux */
  6631. if(comp->len != sizeof(int))
  6632. return -EINVAL;
  6633. if (copy_from_user(&z,comp->data,comp->len))
  6634. return -EFAULT;
  6635. return flashgchar((struct airo_info *)dev->priv,z,8000);
  6636. case AIROFLSHPCHR: /* Send char to card. */
  6637. if(comp->len != sizeof(int))
  6638. return -EINVAL;
  6639. if (copy_from_user(&z,comp->data,comp->len))
  6640. return -EFAULT;
  6641. return flashpchar((struct airo_info *)dev->priv,z,8000);
  6642. case AIROFLPUTBUF: /* Send 32k to card */
  6643. if (!((struct airo_info *)dev->priv)->flash)
  6644. return -ENOMEM;
  6645. if(comp->len > FLASHSIZE)
  6646. return -EINVAL;
  6647. if(copy_from_user(((struct airo_info *)dev->priv)->flash,comp->data,comp->len))
  6648. return -EFAULT;
  6649. flashputbuf((struct airo_info *)dev->priv);
  6650. return 0;
  6651. case AIRORESTART:
  6652. if(flashrestart((struct airo_info *)dev->priv,dev))
  6653. return -EIO;
  6654. return 0;
  6655. }
  6656. return -EINVAL;
  6657. }
  6658. #define FLASH_COMMAND 0x7e7e
  6659. /*
  6660. * STEP 1)
  6661. * Disable MAC and do soft reset on
  6662. * card.
  6663. */
  6664. static int cmdreset(struct airo_info *ai) {
  6665. disable_MAC(ai, 1);
  6666. if(!waitbusy (ai)){
  6667. printk(KERN_INFO "Waitbusy hang before RESET\n");
  6668. return -EBUSY;
  6669. }
  6670. OUT4500(ai,COMMAND,CMD_SOFTRESET);
  6671. ssleep(1); /* WAS 600 12/7/00 */
  6672. if(!waitbusy (ai)){
  6673. printk(KERN_INFO "Waitbusy hang AFTER RESET\n");
  6674. return -EBUSY;
  6675. }
  6676. return 0;
  6677. }
  6678. /* STEP 2)
  6679. * Put the card in legendary flash
  6680. * mode
  6681. */
  6682. static int setflashmode (struct airo_info *ai) {
  6683. set_bit (FLAG_FLASHING, &ai->flags);
  6684. OUT4500(ai, SWS0, FLASH_COMMAND);
  6685. OUT4500(ai, SWS1, FLASH_COMMAND);
  6686. if (probe) {
  6687. OUT4500(ai, SWS0, FLASH_COMMAND);
  6688. OUT4500(ai, COMMAND,0x10);
  6689. } else {
  6690. OUT4500(ai, SWS2, FLASH_COMMAND);
  6691. OUT4500(ai, SWS3, FLASH_COMMAND);
  6692. OUT4500(ai, COMMAND,0);
  6693. }
  6694. msleep(500); /* 500ms delay */
  6695. if(!waitbusy(ai)) {
  6696. clear_bit (FLAG_FLASHING, &ai->flags);
  6697. printk(KERN_INFO "Waitbusy hang after setflash mode\n");
  6698. return -EIO;
  6699. }
  6700. return 0;
  6701. }
  6702. /* Put character to SWS0 wait for dwelltime
  6703. * x 50us for echo .
  6704. */
  6705. static int flashpchar(struct airo_info *ai,int byte,int dwelltime) {
  6706. int echo;
  6707. int waittime;
  6708. byte |= 0x8000;
  6709. if(dwelltime == 0 )
  6710. dwelltime = 200;
  6711. waittime=dwelltime;
  6712. /* Wait for busy bit d15 to go false indicating buffer empty */
  6713. while ((IN4500 (ai, SWS0) & 0x8000) && waittime > 0) {
  6714. udelay (50);
  6715. waittime -= 50;
  6716. }
  6717. /* timeout for busy clear wait */
  6718. if(waittime <= 0 ){
  6719. printk(KERN_INFO "flash putchar busywait timeout! \n");
  6720. return -EBUSY;
  6721. }
  6722. /* Port is clear now write byte and wait for it to echo back */
  6723. do {
  6724. OUT4500(ai,SWS0,byte);
  6725. udelay(50);
  6726. dwelltime -= 50;
  6727. echo = IN4500(ai,SWS1);
  6728. } while (dwelltime >= 0 && echo != byte);
  6729. OUT4500(ai,SWS1,0);
  6730. return (echo == byte) ? 0 : -EIO;
  6731. }
  6732. /*
  6733. * Get a character from the card matching matchbyte
  6734. * Step 3)
  6735. */
  6736. static int flashgchar(struct airo_info *ai,int matchbyte,int dwelltime){
  6737. int rchar;
  6738. unsigned char rbyte=0;
  6739. do {
  6740. rchar = IN4500(ai,SWS1);
  6741. if(dwelltime && !(0x8000 & rchar)){
  6742. dwelltime -= 10;
  6743. mdelay(10);
  6744. continue;
  6745. }
  6746. rbyte = 0xff & rchar;
  6747. if( (rbyte == matchbyte) && (0x8000 & rchar) ){
  6748. OUT4500(ai,SWS1,0);
  6749. return 0;
  6750. }
  6751. if( rbyte == 0x81 || rbyte == 0x82 || rbyte == 0x83 || rbyte == 0x1a || 0xffff == rchar)
  6752. break;
  6753. OUT4500(ai,SWS1,0);
  6754. }while(dwelltime > 0);
  6755. return -EIO;
  6756. }
  6757. /*
  6758. * Transfer 32k of firmware data from user buffer to our buffer and
  6759. * send to the card
  6760. */
  6761. static int flashputbuf(struct airo_info *ai){
  6762. int nwords;
  6763. /* Write stuff */
  6764. if (test_bit(FLAG_MPI,&ai->flags))
  6765. memcpy_toio(ai->pciaux + 0x8000, ai->flash, FLASHSIZE);
  6766. else {
  6767. OUT4500(ai,AUXPAGE,0x100);
  6768. OUT4500(ai,AUXOFF,0);
  6769. for(nwords=0;nwords != FLASHSIZE / 2;nwords++){
  6770. OUT4500(ai,AUXDATA,ai->flash[nwords] & 0xffff);
  6771. }
  6772. }
  6773. OUT4500(ai,SWS0,0x8000);
  6774. return 0;
  6775. }
  6776. /*
  6777. *
  6778. */
  6779. static int flashrestart(struct airo_info *ai,struct net_device *dev){
  6780. int i,status;
  6781. ssleep(1); /* Added 12/7/00 */
  6782. clear_bit (FLAG_FLASHING, &ai->flags);
  6783. if (test_bit(FLAG_MPI, &ai->flags)) {
  6784. status = mpi_init_descriptors(ai);
  6785. if (status != SUCCESS)
  6786. return status;
  6787. }
  6788. status = setup_card(ai, dev->dev_addr, 1);
  6789. if (!test_bit(FLAG_MPI,&ai->flags))
  6790. for( i = 0; i < MAX_FIDS; i++ ) {
  6791. ai->fids[i] = transmit_allocate
  6792. ( ai, 2312, i >= MAX_FIDS / 2 );
  6793. }
  6794. ssleep(1); /* Added 12/7/00 */
  6795. return status;
  6796. }
  6797. #endif /* CISCO_EXT */
  6798. /*
  6799. This program is free software; you can redistribute it and/or
  6800. modify it under the terms of the GNU General Public License
  6801. as published by the Free Software Foundation; either version 2
  6802. of the License, or (at your option) any later version.
  6803. This program is distributed in the hope that it will be useful,
  6804. but WITHOUT ANY WARRANTY; without even the implied warranty of
  6805. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  6806. GNU General Public License for more details.
  6807. In addition:
  6808. Redistribution and use in source and binary forms, with or without
  6809. modification, are permitted provided that the following conditions
  6810. are met:
  6811. 1. Redistributions of source code must retain the above copyright
  6812. notice, this list of conditions and the following disclaimer.
  6813. 2. Redistributions in binary form must reproduce the above copyright
  6814. notice, this list of conditions and the following disclaimer in the
  6815. documentation and/or other materials provided with the distribution.
  6816. 3. The name of the author may not be used to endorse or promote
  6817. products derived from this software without specific prior written
  6818. permission.
  6819. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  6820. IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  6821. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  6822. ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
  6823. INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  6824. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  6825. SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  6826. HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  6827. STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  6828. IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  6829. POSSIBILITY OF SUCH DAMAGE.
  6830. */
  6831. module_init(airo_init_module);
  6832. module_exit(airo_cleanup_module);