orinoco.c 156 KB

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