airo.c 218 KB

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