orinoco.c 159 KB

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