orinoco.c 159 KB

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