orinoco.c 155 KB

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