main.c 151 KB

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