orinoco.c 148 KB

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