orinoco.c 155 KB

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