airo.c 219 KB

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