airo.c 218 KB

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