orinoco.c 159 KB

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