orinoco.c 158 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130
  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. /* extract desc and skb from queue */
  1365. list_for_each_entry_safe(rx_data, temp, &priv->rx_list, list) {
  1366. desc = rx_data->desc;
  1367. skb = rx_data->skb;
  1368. list_del(&rx_data->list);
  1369. kfree(rx_data);
  1370. orinoco_rx(dev, desc, skb);
  1371. kfree(desc);
  1372. }
  1373. }
  1374. /********************************************************************/
  1375. /* Rx path (info frames) */
  1376. /********************************************************************/
  1377. static void print_linkstatus(struct net_device *dev, u16 status)
  1378. {
  1379. char * s;
  1380. if (suppress_linkstatus)
  1381. return;
  1382. switch (status) {
  1383. case HERMES_LINKSTATUS_NOT_CONNECTED:
  1384. s = "Not Connected";
  1385. break;
  1386. case HERMES_LINKSTATUS_CONNECTED:
  1387. s = "Connected";
  1388. break;
  1389. case HERMES_LINKSTATUS_DISCONNECTED:
  1390. s = "Disconnected";
  1391. break;
  1392. case HERMES_LINKSTATUS_AP_CHANGE:
  1393. s = "AP Changed";
  1394. break;
  1395. case HERMES_LINKSTATUS_AP_OUT_OF_RANGE:
  1396. s = "AP Out of Range";
  1397. break;
  1398. case HERMES_LINKSTATUS_AP_IN_RANGE:
  1399. s = "AP In Range";
  1400. break;
  1401. case HERMES_LINKSTATUS_ASSOC_FAILED:
  1402. s = "Association Failed";
  1403. break;
  1404. default:
  1405. s = "UNKNOWN";
  1406. }
  1407. printk(KERN_INFO "%s: New link status: %s (%04x)\n",
  1408. dev->name, s, status);
  1409. }
  1410. /* Search scan results for requested BSSID, join it if found */
  1411. static void orinoco_join_ap(struct work_struct *work)
  1412. {
  1413. struct orinoco_private *priv =
  1414. container_of(work, struct orinoco_private, join_work);
  1415. struct net_device *dev = priv->ndev;
  1416. struct hermes *hw = &priv->hw;
  1417. int err;
  1418. unsigned long flags;
  1419. struct join_req {
  1420. u8 bssid[ETH_ALEN];
  1421. __le16 channel;
  1422. } __attribute__ ((packed)) req;
  1423. const int atom_len = offsetof(struct prism2_scan_apinfo, atim);
  1424. struct prism2_scan_apinfo *atom = NULL;
  1425. int offset = 4;
  1426. int found = 0;
  1427. u8 *buf;
  1428. u16 len;
  1429. /* Allocate buffer for scan results */
  1430. buf = kmalloc(MAX_SCAN_LEN, GFP_KERNEL);
  1431. if (! buf)
  1432. return;
  1433. if (orinoco_lock(priv, &flags) != 0)
  1434. goto fail_lock;
  1435. /* Sanity checks in case user changed something in the meantime */
  1436. if (! priv->bssid_fixed)
  1437. goto out;
  1438. if (strlen(priv->desired_essid) == 0)
  1439. goto out;
  1440. /* Read scan results from the firmware */
  1441. err = hermes_read_ltv(hw, USER_BAP,
  1442. HERMES_RID_SCANRESULTSTABLE,
  1443. MAX_SCAN_LEN, &len, buf);
  1444. if (err) {
  1445. printk(KERN_ERR "%s: Cannot read scan results\n",
  1446. dev->name);
  1447. goto out;
  1448. }
  1449. len = HERMES_RECLEN_TO_BYTES(len);
  1450. /* Go through the scan results looking for the channel of the AP
  1451. * we were requested to join */
  1452. for (; offset + atom_len <= len; offset += atom_len) {
  1453. atom = (struct prism2_scan_apinfo *) (buf + offset);
  1454. if (memcmp(&atom->bssid, priv->desired_bssid, ETH_ALEN) == 0) {
  1455. found = 1;
  1456. break;
  1457. }
  1458. }
  1459. if (! found) {
  1460. DEBUG(1, "%s: Requested AP not found in scan results\n",
  1461. dev->name);
  1462. goto out;
  1463. }
  1464. memcpy(req.bssid, priv->desired_bssid, ETH_ALEN);
  1465. req.channel = atom->channel; /* both are little-endian */
  1466. err = HERMES_WRITE_RECORD(hw, USER_BAP, HERMES_RID_CNFJOINREQUEST,
  1467. &req);
  1468. if (err)
  1469. printk(KERN_ERR "%s: Error issuing join request\n", dev->name);
  1470. out:
  1471. orinoco_unlock(priv, &flags);
  1472. fail_lock:
  1473. kfree(buf);
  1474. }
  1475. /* Send new BSSID to userspace */
  1476. static void orinoco_send_bssid_wevent(struct orinoco_private *priv)
  1477. {
  1478. struct net_device *dev = priv->ndev;
  1479. struct hermes *hw = &priv->hw;
  1480. union iwreq_data wrqu;
  1481. int err;
  1482. err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTBSSID,
  1483. ETH_ALEN, NULL, wrqu.ap_addr.sa_data);
  1484. if (err != 0)
  1485. return;
  1486. wrqu.ap_addr.sa_family = ARPHRD_ETHER;
  1487. /* Send event to user space */
  1488. wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL);
  1489. }
  1490. static void orinoco_send_assocreqie_wevent(struct orinoco_private *priv)
  1491. {
  1492. struct net_device *dev = priv->ndev;
  1493. struct hermes *hw = &priv->hw;
  1494. union iwreq_data wrqu;
  1495. int err;
  1496. u8 buf[88];
  1497. u8 *ie;
  1498. if (!priv->has_wpa)
  1499. return;
  1500. err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENT_ASSOC_REQ_INFO,
  1501. sizeof(buf), NULL, &buf);
  1502. if (err != 0)
  1503. return;
  1504. ie = orinoco_get_wpa_ie(buf, sizeof(buf));
  1505. if (ie) {
  1506. int rem = sizeof(buf) - (ie - &buf[0]);
  1507. wrqu.data.length = ie[1] + 2;
  1508. if (wrqu.data.length > rem)
  1509. wrqu.data.length = rem;
  1510. if (wrqu.data.length)
  1511. /* Send event to user space */
  1512. wireless_send_event(dev, IWEVASSOCREQIE, &wrqu, ie);
  1513. }
  1514. }
  1515. static void orinoco_send_assocrespie_wevent(struct orinoco_private *priv)
  1516. {
  1517. struct net_device *dev = priv->ndev;
  1518. struct hermes *hw = &priv->hw;
  1519. union iwreq_data wrqu;
  1520. int err;
  1521. u8 buf[88]; /* TODO: verify max size or IW_GENERIC_IE_MAX */
  1522. u8 *ie;
  1523. if (!priv->has_wpa)
  1524. return;
  1525. err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENT_ASSOC_RESP_INFO,
  1526. sizeof(buf), NULL, &buf);
  1527. if (err != 0)
  1528. return;
  1529. ie = orinoco_get_wpa_ie(buf, sizeof(buf));
  1530. if (ie) {
  1531. int rem = sizeof(buf) - (ie - &buf[0]);
  1532. wrqu.data.length = ie[1] + 2;
  1533. if (wrqu.data.length > rem)
  1534. wrqu.data.length = rem;
  1535. if (wrqu.data.length)
  1536. /* Send event to user space */
  1537. wireless_send_event(dev, IWEVASSOCRESPIE, &wrqu, ie);
  1538. }
  1539. }
  1540. static void orinoco_send_wevents(struct work_struct *work)
  1541. {
  1542. struct orinoco_private *priv =
  1543. container_of(work, struct orinoco_private, wevent_work);
  1544. unsigned long flags;
  1545. if (orinoco_lock(priv, &flags) != 0)
  1546. return;
  1547. orinoco_send_assocreqie_wevent(priv);
  1548. orinoco_send_assocrespie_wevent(priv);
  1549. orinoco_send_bssid_wevent(priv);
  1550. orinoco_unlock(priv, &flags);
  1551. }
  1552. static inline void orinoco_clear_scan_results(struct orinoco_private *priv,
  1553. unsigned long scan_age)
  1554. {
  1555. if (priv->has_ext_scan) {
  1556. struct xbss_element *bss;
  1557. struct xbss_element *tmp_bss;
  1558. /* Blow away current list of scan results */
  1559. list_for_each_entry_safe(bss, tmp_bss, &priv->bss_list, list) {
  1560. if (!scan_age ||
  1561. time_after(jiffies, bss->last_scanned + scan_age)) {
  1562. list_move_tail(&bss->list,
  1563. &priv->bss_free_list);
  1564. /* Don't blow away ->list, just BSS data */
  1565. memset(&bss->bss, 0, sizeof(bss->bss));
  1566. bss->last_scanned = 0;
  1567. }
  1568. }
  1569. } else {
  1570. struct bss_element *bss;
  1571. struct bss_element *tmp_bss;
  1572. /* Blow away current list of scan results */
  1573. list_for_each_entry_safe(bss, tmp_bss, &priv->bss_list, list) {
  1574. if (!scan_age ||
  1575. time_after(jiffies, bss->last_scanned + scan_age)) {
  1576. list_move_tail(&bss->list,
  1577. &priv->bss_free_list);
  1578. /* Don't blow away ->list, just BSS data */
  1579. memset(&bss->bss, 0, sizeof(bss->bss));
  1580. bss->last_scanned = 0;
  1581. }
  1582. }
  1583. }
  1584. }
  1585. static void orinoco_add_ext_scan_result(struct orinoco_private *priv,
  1586. struct agere_ext_scan_info *atom)
  1587. {
  1588. struct xbss_element *bss = NULL;
  1589. int found = 0;
  1590. /* Try to update an existing bss first */
  1591. list_for_each_entry(bss, &priv->bss_list, list) {
  1592. if (compare_ether_addr(bss->bss.bssid, atom->bssid))
  1593. continue;
  1594. /* ESSID lengths */
  1595. if (bss->bss.data[1] != atom->data[1])
  1596. continue;
  1597. if (memcmp(&bss->bss.data[2], &atom->data[2],
  1598. atom->data[1]))
  1599. continue;
  1600. found = 1;
  1601. break;
  1602. }
  1603. /* Grab a bss off the free list */
  1604. if (!found && !list_empty(&priv->bss_free_list)) {
  1605. bss = list_entry(priv->bss_free_list.next,
  1606. struct xbss_element, list);
  1607. list_del(priv->bss_free_list.next);
  1608. list_add_tail(&bss->list, &priv->bss_list);
  1609. }
  1610. if (bss) {
  1611. /* Always update the BSS to get latest beacon info */
  1612. memcpy(&bss->bss, atom, sizeof(bss->bss));
  1613. bss->last_scanned = jiffies;
  1614. }
  1615. }
  1616. static int orinoco_process_scan_results(struct net_device *dev,
  1617. unsigned char *buf,
  1618. int len)
  1619. {
  1620. struct orinoco_private *priv = netdev_priv(dev);
  1621. int offset; /* In the scan data */
  1622. union hermes_scan_info *atom;
  1623. int atom_len;
  1624. switch (priv->firmware_type) {
  1625. case FIRMWARE_TYPE_AGERE:
  1626. atom_len = sizeof(struct agere_scan_apinfo);
  1627. offset = 0;
  1628. break;
  1629. case FIRMWARE_TYPE_SYMBOL:
  1630. /* Lack of documentation necessitates this hack.
  1631. * Different firmwares have 68 or 76 byte long atoms.
  1632. * We try modulo first. If the length divides by both,
  1633. * we check what would be the channel in the second
  1634. * frame for a 68-byte atom. 76-byte atoms have 0 there.
  1635. * Valid channel cannot be 0. */
  1636. if (len % 76)
  1637. atom_len = 68;
  1638. else if (len % 68)
  1639. atom_len = 76;
  1640. else if (len >= 1292 && buf[68] == 0)
  1641. atom_len = 76;
  1642. else
  1643. atom_len = 68;
  1644. offset = 0;
  1645. break;
  1646. case FIRMWARE_TYPE_INTERSIL:
  1647. offset = 4;
  1648. if (priv->has_hostscan) {
  1649. atom_len = le16_to_cpup((__le16 *)buf);
  1650. /* Sanity check for atom_len */
  1651. if (atom_len < sizeof(struct prism2_scan_apinfo)) {
  1652. printk(KERN_ERR "%s: Invalid atom_len in scan "
  1653. "data: %d\n", dev->name, atom_len);
  1654. return -EIO;
  1655. }
  1656. } else
  1657. atom_len = offsetof(struct prism2_scan_apinfo, atim);
  1658. break;
  1659. default:
  1660. return -EOPNOTSUPP;
  1661. }
  1662. /* Check that we got an whole number of atoms */
  1663. if ((len - offset) % atom_len) {
  1664. printk(KERN_ERR "%s: Unexpected scan data length %d, "
  1665. "atom_len %d, offset %d\n", dev->name, len,
  1666. atom_len, offset);
  1667. return -EIO;
  1668. }
  1669. orinoco_clear_scan_results(priv, msecs_to_jiffies(15000));
  1670. /* Read the entries one by one */
  1671. for (; offset + atom_len <= len; offset += atom_len) {
  1672. int found = 0;
  1673. struct bss_element *bss = NULL;
  1674. /* Get next atom */
  1675. atom = (union hermes_scan_info *) (buf + offset);
  1676. /* Try to update an existing bss first */
  1677. list_for_each_entry(bss, &priv->bss_list, list) {
  1678. if (compare_ether_addr(bss->bss.a.bssid, atom->a.bssid))
  1679. continue;
  1680. if (le16_to_cpu(bss->bss.a.essid_len) !=
  1681. le16_to_cpu(atom->a.essid_len))
  1682. continue;
  1683. if (memcmp(bss->bss.a.essid, atom->a.essid,
  1684. le16_to_cpu(atom->a.essid_len)))
  1685. continue;
  1686. found = 1;
  1687. break;
  1688. }
  1689. /* Grab a bss off the free list */
  1690. if (!found && !list_empty(&priv->bss_free_list)) {
  1691. bss = list_entry(priv->bss_free_list.next,
  1692. struct bss_element, list);
  1693. list_del(priv->bss_free_list.next);
  1694. list_add_tail(&bss->list, &priv->bss_list);
  1695. }
  1696. if (bss) {
  1697. /* Always update the BSS to get latest beacon info */
  1698. memcpy(&bss->bss, atom, sizeof(bss->bss));
  1699. bss->last_scanned = jiffies;
  1700. }
  1701. }
  1702. return 0;
  1703. }
  1704. static void __orinoco_ev_info(struct net_device *dev, hermes_t *hw)
  1705. {
  1706. struct orinoco_private *priv = netdev_priv(dev);
  1707. u16 infofid;
  1708. struct {
  1709. __le16 len;
  1710. __le16 type;
  1711. } __attribute__ ((packed)) info;
  1712. int len, type;
  1713. int err;
  1714. /* This is an answer to an INQUIRE command that we did earlier,
  1715. * or an information "event" generated by the card
  1716. * The controller return to us a pseudo frame containing
  1717. * the information in question - Jean II */
  1718. infofid = hermes_read_regn(hw, INFOFID);
  1719. /* Read the info frame header - don't try too hard */
  1720. err = hermes_bap_pread(hw, IRQ_BAP, &info, sizeof(info),
  1721. infofid, 0);
  1722. if (err) {
  1723. printk(KERN_ERR "%s: error %d reading info frame. "
  1724. "Frame dropped.\n", dev->name, err);
  1725. return;
  1726. }
  1727. len = HERMES_RECLEN_TO_BYTES(le16_to_cpu(info.len));
  1728. type = le16_to_cpu(info.type);
  1729. switch (type) {
  1730. case HERMES_INQ_TALLIES: {
  1731. struct hermes_tallies_frame tallies;
  1732. struct iw_statistics *wstats = &priv->wstats;
  1733. if (len > sizeof(tallies)) {
  1734. printk(KERN_WARNING "%s: Tallies frame too long (%d bytes)\n",
  1735. dev->name, len);
  1736. len = sizeof(tallies);
  1737. }
  1738. err = hermes_bap_pread(hw, IRQ_BAP, &tallies, len,
  1739. infofid, sizeof(info));
  1740. if (err)
  1741. break;
  1742. /* Increment our various counters */
  1743. /* wstats->discard.nwid - no wrong BSSID stuff */
  1744. wstats->discard.code +=
  1745. le16_to_cpu(tallies.RxWEPUndecryptable);
  1746. if (len == sizeof(tallies))
  1747. wstats->discard.code +=
  1748. le16_to_cpu(tallies.RxDiscards_WEPICVError) +
  1749. le16_to_cpu(tallies.RxDiscards_WEPExcluded);
  1750. wstats->discard.misc +=
  1751. le16_to_cpu(tallies.TxDiscardsWrongSA);
  1752. wstats->discard.fragment +=
  1753. le16_to_cpu(tallies.RxMsgInBadMsgFragments);
  1754. wstats->discard.retries +=
  1755. le16_to_cpu(tallies.TxRetryLimitExceeded);
  1756. /* wstats->miss.beacon - no match */
  1757. }
  1758. break;
  1759. case HERMES_INQ_LINKSTATUS: {
  1760. struct hermes_linkstatus linkstatus;
  1761. u16 newstatus;
  1762. int connected;
  1763. if (priv->iw_mode == IW_MODE_MONITOR)
  1764. break;
  1765. if (len != sizeof(linkstatus)) {
  1766. printk(KERN_WARNING "%s: Unexpected size for linkstatus frame (%d bytes)\n",
  1767. dev->name, len);
  1768. break;
  1769. }
  1770. err = hermes_bap_pread(hw, IRQ_BAP, &linkstatus, len,
  1771. infofid, sizeof(info));
  1772. if (err)
  1773. break;
  1774. newstatus = le16_to_cpu(linkstatus.linkstatus);
  1775. /* Symbol firmware uses "out of range" to signal that
  1776. * the hostscan frame can be requested. */
  1777. if (newstatus == HERMES_LINKSTATUS_AP_OUT_OF_RANGE &&
  1778. priv->firmware_type == FIRMWARE_TYPE_SYMBOL &&
  1779. priv->has_hostscan && priv->scan_inprogress) {
  1780. hermes_inquire(hw, HERMES_INQ_HOSTSCAN_SYMBOL);
  1781. break;
  1782. }
  1783. connected = (newstatus == HERMES_LINKSTATUS_CONNECTED)
  1784. || (newstatus == HERMES_LINKSTATUS_AP_CHANGE)
  1785. || (newstatus == HERMES_LINKSTATUS_AP_IN_RANGE);
  1786. if (connected)
  1787. netif_carrier_on(dev);
  1788. else if (!ignore_disconnect)
  1789. netif_carrier_off(dev);
  1790. if (newstatus != priv->last_linkstatus) {
  1791. priv->last_linkstatus = newstatus;
  1792. print_linkstatus(dev, newstatus);
  1793. /* The info frame contains only one word which is the
  1794. * status (see hermes.h). The status is pretty boring
  1795. * in itself, that's why we export the new BSSID...
  1796. * Jean II */
  1797. schedule_work(&priv->wevent_work);
  1798. }
  1799. }
  1800. break;
  1801. case HERMES_INQ_SCAN:
  1802. if (!priv->scan_inprogress && priv->bssid_fixed &&
  1803. priv->firmware_type == FIRMWARE_TYPE_INTERSIL) {
  1804. schedule_work(&priv->join_work);
  1805. break;
  1806. }
  1807. /* fall through */
  1808. case HERMES_INQ_HOSTSCAN:
  1809. case HERMES_INQ_HOSTSCAN_SYMBOL: {
  1810. /* Result of a scanning. Contains information about
  1811. * cells in the vicinity - Jean II */
  1812. union iwreq_data wrqu;
  1813. unsigned char *buf;
  1814. /* Scan is no longer in progress */
  1815. priv->scan_inprogress = 0;
  1816. /* Sanity check */
  1817. if (len > 4096) {
  1818. printk(KERN_WARNING "%s: Scan results too large (%d bytes)\n",
  1819. dev->name, len);
  1820. break;
  1821. }
  1822. /* Allocate buffer for results */
  1823. buf = kmalloc(len, GFP_ATOMIC);
  1824. if (buf == NULL)
  1825. /* No memory, so can't printk()... */
  1826. break;
  1827. /* Read scan data */
  1828. err = hermes_bap_pread(hw, IRQ_BAP, (void *) buf, len,
  1829. infofid, sizeof(info));
  1830. if (err) {
  1831. kfree(buf);
  1832. break;
  1833. }
  1834. #ifdef ORINOCO_DEBUG
  1835. {
  1836. int i;
  1837. printk(KERN_DEBUG "Scan result [%02X", buf[0]);
  1838. for(i = 1; i < (len * 2); i++)
  1839. printk(":%02X", buf[i]);
  1840. printk("]\n");
  1841. }
  1842. #endif /* ORINOCO_DEBUG */
  1843. if (orinoco_process_scan_results(dev, buf, len) == 0) {
  1844. /* Send an empty event to user space.
  1845. * We don't send the received data on the event because
  1846. * it would require us to do complex transcoding, and
  1847. * we want to minimise the work done in the irq handler
  1848. * Use a request to extract the data - Jean II */
  1849. wrqu.data.length = 0;
  1850. wrqu.data.flags = 0;
  1851. wireless_send_event(dev, SIOCGIWSCAN, &wrqu, NULL);
  1852. }
  1853. kfree(buf);
  1854. }
  1855. break;
  1856. case HERMES_INQ_CHANNELINFO:
  1857. {
  1858. struct agere_ext_scan_info *bss;
  1859. if (!priv->scan_inprogress) {
  1860. printk(KERN_DEBUG "%s: Got chaninfo without scan, "
  1861. "len=%d\n", dev->name, len);
  1862. break;
  1863. }
  1864. /* An empty result indicates that the scan is complete */
  1865. if (len == 0) {
  1866. union iwreq_data wrqu;
  1867. /* Scan is no longer in progress */
  1868. priv->scan_inprogress = 0;
  1869. wrqu.data.length = 0;
  1870. wrqu.data.flags = 0;
  1871. wireless_send_event(dev, SIOCGIWSCAN, &wrqu, NULL);
  1872. break;
  1873. }
  1874. /* Sanity check */
  1875. else if (len > sizeof(*bss)) {
  1876. printk(KERN_WARNING
  1877. "%s: Ext scan results too large (%d bytes). "
  1878. "Truncating results to %zd bytes.\n",
  1879. dev->name, len, sizeof(*bss));
  1880. len = sizeof(*bss);
  1881. } else if (len < (offsetof(struct agere_ext_scan_info,
  1882. data) + 2)) {
  1883. /* Drop this result now so we don't have to
  1884. * keep checking later */
  1885. printk(KERN_WARNING
  1886. "%s: Ext scan results too short (%d bytes)\n",
  1887. dev->name, len);
  1888. break;
  1889. }
  1890. bss = kmalloc(sizeof(*bss), GFP_ATOMIC);
  1891. if (bss == NULL)
  1892. break;
  1893. /* Read scan data */
  1894. err = hermes_bap_pread(hw, IRQ_BAP, (void *) bss, len,
  1895. infofid, sizeof(info));
  1896. if (err) {
  1897. kfree(bss);
  1898. break;
  1899. }
  1900. orinoco_add_ext_scan_result(priv, bss);
  1901. kfree(bss);
  1902. break;
  1903. }
  1904. case HERMES_INQ_SEC_STAT_AGERE:
  1905. /* Security status (Agere specific) */
  1906. /* Ignore this frame for now */
  1907. if (priv->firmware_type == FIRMWARE_TYPE_AGERE)
  1908. break;
  1909. /* fall through */
  1910. default:
  1911. printk(KERN_DEBUG "%s: Unknown information frame received: "
  1912. "type 0x%04x, length %d\n", dev->name, type, len);
  1913. /* We don't actually do anything about it */
  1914. break;
  1915. }
  1916. }
  1917. static void __orinoco_ev_infdrop(struct net_device *dev, hermes_t *hw)
  1918. {
  1919. if (net_ratelimit())
  1920. printk(KERN_DEBUG "%s: Information frame lost.\n", dev->name);
  1921. }
  1922. /********************************************************************/
  1923. /* Internal hardware control routines */
  1924. /********************************************************************/
  1925. int __orinoco_up(struct net_device *dev)
  1926. {
  1927. struct orinoco_private *priv = netdev_priv(dev);
  1928. struct hermes *hw = &priv->hw;
  1929. int err;
  1930. netif_carrier_off(dev); /* just to make sure */
  1931. err = __orinoco_program_rids(dev);
  1932. if (err) {
  1933. printk(KERN_ERR "%s: Error %d configuring card\n",
  1934. dev->name, err);
  1935. return err;
  1936. }
  1937. /* Fire things up again */
  1938. hermes_set_irqmask(hw, ORINOCO_INTEN);
  1939. err = hermes_enable_port(hw, 0);
  1940. if (err) {
  1941. printk(KERN_ERR "%s: Error %d enabling MAC port\n",
  1942. dev->name, err);
  1943. return err;
  1944. }
  1945. netif_start_queue(dev);
  1946. return 0;
  1947. }
  1948. int __orinoco_down(struct net_device *dev)
  1949. {
  1950. struct orinoco_private *priv = netdev_priv(dev);
  1951. struct hermes *hw = &priv->hw;
  1952. int err;
  1953. netif_stop_queue(dev);
  1954. if (! priv->hw_unavailable) {
  1955. if (! priv->broken_disableport) {
  1956. err = hermes_disable_port(hw, 0);
  1957. if (err) {
  1958. /* Some firmwares (e.g. Intersil 1.3.x) seem
  1959. * to have problems disabling the port, oh
  1960. * well, too bad. */
  1961. printk(KERN_WARNING "%s: Error %d disabling MAC port\n",
  1962. dev->name, err);
  1963. priv->broken_disableport = 1;
  1964. }
  1965. }
  1966. hermes_set_irqmask(hw, 0);
  1967. hermes_write_regn(hw, EVACK, 0xffff);
  1968. }
  1969. /* firmware will have to reassociate */
  1970. netif_carrier_off(dev);
  1971. priv->last_linkstatus = 0xffff;
  1972. return 0;
  1973. }
  1974. static int orinoco_allocate_fid(struct net_device *dev)
  1975. {
  1976. struct orinoco_private *priv = netdev_priv(dev);
  1977. struct hermes *hw = &priv->hw;
  1978. int err;
  1979. err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid);
  1980. if (err == -EIO && priv->nicbuf_size > TX_NICBUF_SIZE_BUG) {
  1981. /* Try workaround for old Symbol firmware bug */
  1982. printk(KERN_WARNING "%s: firmware ALLOC bug detected "
  1983. "(old Symbol firmware?). Trying to work around... ",
  1984. dev->name);
  1985. priv->nicbuf_size = TX_NICBUF_SIZE_BUG;
  1986. err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid);
  1987. if (err)
  1988. printk("failed!\n");
  1989. else
  1990. printk("ok.\n");
  1991. }
  1992. return err;
  1993. }
  1994. int orinoco_reinit_firmware(struct net_device *dev)
  1995. {
  1996. struct orinoco_private *priv = netdev_priv(dev);
  1997. struct hermes *hw = &priv->hw;
  1998. int err;
  1999. err = hermes_init(hw);
  2000. if (priv->do_fw_download && !err) {
  2001. err = orinoco_download(priv);
  2002. if (err)
  2003. priv->do_fw_download = 0;
  2004. }
  2005. if (!err)
  2006. err = orinoco_allocate_fid(dev);
  2007. return err;
  2008. }
  2009. static int __orinoco_hw_set_bitrate(struct orinoco_private *priv)
  2010. {
  2011. hermes_t *hw = &priv->hw;
  2012. int err = 0;
  2013. if (priv->bitratemode >= BITRATE_TABLE_SIZE) {
  2014. printk(KERN_ERR "%s: BUG: Invalid bitrate mode %d\n",
  2015. priv->ndev->name, priv->bitratemode);
  2016. return -EINVAL;
  2017. }
  2018. switch (priv->firmware_type) {
  2019. case FIRMWARE_TYPE_AGERE:
  2020. err = hermes_write_wordrec(hw, USER_BAP,
  2021. HERMES_RID_CNFTXRATECONTROL,
  2022. bitrate_table[priv->bitratemode].agere_txratectrl);
  2023. break;
  2024. case FIRMWARE_TYPE_INTERSIL:
  2025. case FIRMWARE_TYPE_SYMBOL:
  2026. err = hermes_write_wordrec(hw, USER_BAP,
  2027. HERMES_RID_CNFTXRATECONTROL,
  2028. bitrate_table[priv->bitratemode].intersil_txratectrl);
  2029. break;
  2030. default:
  2031. BUG();
  2032. }
  2033. return err;
  2034. }
  2035. /* Set fixed AP address */
  2036. static int __orinoco_hw_set_wap(struct orinoco_private *priv)
  2037. {
  2038. int roaming_flag;
  2039. int err = 0;
  2040. hermes_t *hw = &priv->hw;
  2041. switch (priv->firmware_type) {
  2042. case FIRMWARE_TYPE_AGERE:
  2043. /* not supported */
  2044. break;
  2045. case FIRMWARE_TYPE_INTERSIL:
  2046. if (priv->bssid_fixed)
  2047. roaming_flag = 2;
  2048. else
  2049. roaming_flag = 1;
  2050. err = hermes_write_wordrec(hw, USER_BAP,
  2051. HERMES_RID_CNFROAMINGMODE,
  2052. roaming_flag);
  2053. break;
  2054. case FIRMWARE_TYPE_SYMBOL:
  2055. err = HERMES_WRITE_RECORD(hw, USER_BAP,
  2056. HERMES_RID_CNFMANDATORYBSSID_SYMBOL,
  2057. &priv->desired_bssid);
  2058. break;
  2059. }
  2060. return err;
  2061. }
  2062. /* Change the WEP keys and/or the current keys. Can be called
  2063. * either from __orinoco_hw_setup_enc() or directly from
  2064. * orinoco_ioctl_setiwencode(). In the later case the association
  2065. * with the AP is not broken (if the firmware can handle it),
  2066. * which is needed for 802.1x implementations. */
  2067. static int __orinoco_hw_setup_wepkeys(struct orinoco_private *priv)
  2068. {
  2069. hermes_t *hw = &priv->hw;
  2070. int err = 0;
  2071. switch (priv->firmware_type) {
  2072. case FIRMWARE_TYPE_AGERE:
  2073. err = HERMES_WRITE_RECORD(hw, USER_BAP,
  2074. HERMES_RID_CNFWEPKEYS_AGERE,
  2075. &priv->keys);
  2076. if (err)
  2077. return err;
  2078. err = hermes_write_wordrec(hw, USER_BAP,
  2079. HERMES_RID_CNFTXKEY_AGERE,
  2080. priv->tx_key);
  2081. if (err)
  2082. return err;
  2083. break;
  2084. case FIRMWARE_TYPE_INTERSIL:
  2085. case FIRMWARE_TYPE_SYMBOL:
  2086. {
  2087. int keylen;
  2088. int i;
  2089. /* Force uniform key length to work around firmware bugs */
  2090. keylen = le16_to_cpu(priv->keys[priv->tx_key].len);
  2091. if (keylen > LARGE_KEY_SIZE) {
  2092. printk(KERN_ERR "%s: BUG: Key %d has oversize length %d.\n",
  2093. priv->ndev->name, priv->tx_key, keylen);
  2094. return -E2BIG;
  2095. }
  2096. /* Write all 4 keys */
  2097. for(i = 0; i < ORINOCO_MAX_KEYS; i++) {
  2098. err = hermes_write_ltv(hw, USER_BAP,
  2099. HERMES_RID_CNFDEFAULTKEY0 + i,
  2100. HERMES_BYTES_TO_RECLEN(keylen),
  2101. priv->keys[i].data);
  2102. if (err)
  2103. return err;
  2104. }
  2105. /* Write the index of the key used in transmission */
  2106. err = hermes_write_wordrec(hw, USER_BAP,
  2107. HERMES_RID_CNFWEPDEFAULTKEYID,
  2108. priv->tx_key);
  2109. if (err)
  2110. return err;
  2111. }
  2112. break;
  2113. }
  2114. return 0;
  2115. }
  2116. static int __orinoco_hw_setup_enc(struct orinoco_private *priv)
  2117. {
  2118. hermes_t *hw = &priv->hw;
  2119. int err = 0;
  2120. int master_wep_flag;
  2121. int auth_flag;
  2122. int enc_flag;
  2123. /* Setup WEP keys for WEP and WPA */
  2124. if (priv->encode_alg)
  2125. __orinoco_hw_setup_wepkeys(priv);
  2126. if (priv->wep_restrict)
  2127. auth_flag = HERMES_AUTH_SHARED_KEY;
  2128. else
  2129. auth_flag = HERMES_AUTH_OPEN;
  2130. if (priv->wpa_enabled)
  2131. enc_flag = 2;
  2132. else if (priv->encode_alg == IW_ENCODE_ALG_WEP)
  2133. enc_flag = 1;
  2134. else
  2135. enc_flag = 0;
  2136. switch (priv->firmware_type) {
  2137. case FIRMWARE_TYPE_AGERE: /* Agere style WEP */
  2138. if (priv->encode_alg == IW_ENCODE_ALG_WEP) {
  2139. /* Enable the shared-key authentication. */
  2140. err = hermes_write_wordrec(hw, USER_BAP,
  2141. HERMES_RID_CNFAUTHENTICATION_AGERE,
  2142. auth_flag);
  2143. }
  2144. err = hermes_write_wordrec(hw, USER_BAP,
  2145. HERMES_RID_CNFWEPENABLED_AGERE,
  2146. enc_flag);
  2147. if (err)
  2148. return err;
  2149. if (priv->has_wpa) {
  2150. /* Set WPA key management */
  2151. err = hermes_write_wordrec(hw, USER_BAP,
  2152. HERMES_RID_CNFSETWPAAUTHMGMTSUITE_AGERE,
  2153. priv->key_mgmt);
  2154. if (err)
  2155. return err;
  2156. }
  2157. break;
  2158. case FIRMWARE_TYPE_INTERSIL: /* Intersil style WEP */
  2159. case FIRMWARE_TYPE_SYMBOL: /* Symbol style WEP */
  2160. if (priv->encode_alg == IW_ENCODE_ALG_WEP) {
  2161. if (priv->wep_restrict ||
  2162. (priv->firmware_type == FIRMWARE_TYPE_SYMBOL))
  2163. master_wep_flag = HERMES_WEP_PRIVACY_INVOKED |
  2164. HERMES_WEP_EXCL_UNENCRYPTED;
  2165. else
  2166. master_wep_flag = HERMES_WEP_PRIVACY_INVOKED;
  2167. err = hermes_write_wordrec(hw, USER_BAP,
  2168. HERMES_RID_CNFAUTHENTICATION,
  2169. auth_flag);
  2170. if (err)
  2171. return err;
  2172. } else
  2173. master_wep_flag = 0;
  2174. if (priv->iw_mode == IW_MODE_MONITOR)
  2175. master_wep_flag |= HERMES_WEP_HOST_DECRYPT;
  2176. /* Master WEP setting : on/off */
  2177. err = hermes_write_wordrec(hw, USER_BAP,
  2178. HERMES_RID_CNFWEPFLAGS_INTERSIL,
  2179. master_wep_flag);
  2180. if (err)
  2181. return err;
  2182. break;
  2183. }
  2184. return 0;
  2185. }
  2186. /* key must be 32 bytes, including the tx and rx MIC keys.
  2187. * rsc must be 8 bytes
  2188. * tsc must be 8 bytes or NULL
  2189. */
  2190. static int __orinoco_hw_set_tkip_key(hermes_t *hw, int key_idx, int set_tx,
  2191. u8 *key, u8 *rsc, u8 *tsc)
  2192. {
  2193. struct {
  2194. __le16 idx;
  2195. u8 rsc[IW_ENCODE_SEQ_MAX_SIZE];
  2196. u8 key[TKIP_KEYLEN];
  2197. u8 tx_mic[MIC_KEYLEN];
  2198. u8 rx_mic[MIC_KEYLEN];
  2199. u8 tsc[IW_ENCODE_SEQ_MAX_SIZE];
  2200. } __attribute__ ((packed)) buf;
  2201. int ret;
  2202. int err;
  2203. int k;
  2204. u16 xmitting;
  2205. key_idx &= 0x3;
  2206. if (set_tx)
  2207. key_idx |= 0x8000;
  2208. buf.idx = cpu_to_le16(key_idx);
  2209. memcpy(buf.key, key,
  2210. sizeof(buf.key) + sizeof(buf.tx_mic) + sizeof(buf.rx_mic));
  2211. if (rsc == NULL)
  2212. memset(buf.rsc, 0, sizeof(buf.rsc));
  2213. else
  2214. memcpy(buf.rsc, rsc, sizeof(buf.rsc));
  2215. if (tsc == NULL) {
  2216. memset(buf.tsc, 0, sizeof(buf.tsc));
  2217. buf.tsc[4] = 0x10;
  2218. } else {
  2219. memcpy(buf.tsc, tsc, sizeof(buf.tsc));
  2220. }
  2221. /* Wait upto 100ms for tx queue to empty */
  2222. k = 100;
  2223. do {
  2224. k--;
  2225. udelay(1000);
  2226. ret = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_TXQUEUEEMPTY,
  2227. &xmitting);
  2228. if (ret)
  2229. break;
  2230. } while ((k > 0) && xmitting);
  2231. if (k == 0)
  2232. ret = -ETIMEDOUT;
  2233. err = HERMES_WRITE_RECORD(hw, USER_BAP,
  2234. HERMES_RID_CNFADDDEFAULTTKIPKEY_AGERE,
  2235. &buf);
  2236. return ret ? ret : err;
  2237. }
  2238. static int orinoco_clear_tkip_key(struct orinoco_private *priv,
  2239. int key_idx)
  2240. {
  2241. hermes_t *hw = &priv->hw;
  2242. int err;
  2243. memset(&priv->tkip_key[key_idx], 0, sizeof(priv->tkip_key[key_idx]));
  2244. err = hermes_write_wordrec(hw, USER_BAP,
  2245. HERMES_RID_CNFREMDEFAULTTKIPKEY_AGERE,
  2246. key_idx);
  2247. if (err)
  2248. printk(KERN_WARNING "%s: Error %d clearing TKIP key %d\n",
  2249. priv->ndev->name, err, key_idx);
  2250. return err;
  2251. }
  2252. static int __orinoco_program_rids(struct net_device *dev)
  2253. {
  2254. struct orinoco_private *priv = netdev_priv(dev);
  2255. hermes_t *hw = &priv->hw;
  2256. int err;
  2257. struct hermes_idstring idbuf;
  2258. /* Set the MAC address */
  2259. err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNMACADDR,
  2260. HERMES_BYTES_TO_RECLEN(ETH_ALEN), dev->dev_addr);
  2261. if (err) {
  2262. printk(KERN_ERR "%s: Error %d setting MAC address\n",
  2263. dev->name, err);
  2264. return err;
  2265. }
  2266. /* Set up the link mode */
  2267. err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFPORTTYPE,
  2268. priv->port_type);
  2269. if (err) {
  2270. printk(KERN_ERR "%s: Error %d setting port type\n",
  2271. dev->name, err);
  2272. return err;
  2273. }
  2274. /* Set the channel/frequency */
  2275. if (priv->channel != 0 && priv->iw_mode != IW_MODE_INFRA) {
  2276. err = hermes_write_wordrec(hw, USER_BAP,
  2277. HERMES_RID_CNFOWNCHANNEL,
  2278. priv->channel);
  2279. if (err) {
  2280. printk(KERN_ERR "%s: Error %d setting channel %d\n",
  2281. dev->name, err, priv->channel);
  2282. return err;
  2283. }
  2284. }
  2285. if (priv->has_ibss) {
  2286. u16 createibss;
  2287. if ((strlen(priv->desired_essid) == 0) && (priv->createibss)) {
  2288. printk(KERN_WARNING "%s: This firmware requires an "
  2289. "ESSID in IBSS-Ad-Hoc mode.\n", dev->name);
  2290. /* With wvlan_cs, in this case, we would crash.
  2291. * hopefully, this driver will behave better...
  2292. * Jean II */
  2293. createibss = 0;
  2294. } else {
  2295. createibss = priv->createibss;
  2296. }
  2297. err = hermes_write_wordrec(hw, USER_BAP,
  2298. HERMES_RID_CNFCREATEIBSS,
  2299. createibss);
  2300. if (err) {
  2301. printk(KERN_ERR "%s: Error %d setting CREATEIBSS\n",
  2302. dev->name, err);
  2303. return err;
  2304. }
  2305. }
  2306. /* Set the desired BSSID */
  2307. err = __orinoco_hw_set_wap(priv);
  2308. if (err) {
  2309. printk(KERN_ERR "%s: Error %d setting AP address\n",
  2310. dev->name, err);
  2311. return err;
  2312. }
  2313. /* Set the desired ESSID */
  2314. idbuf.len = cpu_to_le16(strlen(priv->desired_essid));
  2315. memcpy(&idbuf.val, priv->desired_essid, sizeof(idbuf.val));
  2316. /* WinXP wants partner to configure OWNSSID even in IBSS mode. (jimc) */
  2317. err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNSSID,
  2318. HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid)+2),
  2319. &idbuf);
  2320. if (err) {
  2321. printk(KERN_ERR "%s: Error %d setting OWNSSID\n",
  2322. dev->name, err);
  2323. return err;
  2324. }
  2325. err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFDESIREDSSID,
  2326. HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid)+2),
  2327. &idbuf);
  2328. if (err) {
  2329. printk(KERN_ERR "%s: Error %d setting DESIREDSSID\n",
  2330. dev->name, err);
  2331. return err;
  2332. }
  2333. /* Set the station name */
  2334. idbuf.len = cpu_to_le16(strlen(priv->nick));
  2335. memcpy(&idbuf.val, priv->nick, sizeof(idbuf.val));
  2336. err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNNAME,
  2337. HERMES_BYTES_TO_RECLEN(strlen(priv->nick)+2),
  2338. &idbuf);
  2339. if (err) {
  2340. printk(KERN_ERR "%s: Error %d setting nickname\n",
  2341. dev->name, err);
  2342. return err;
  2343. }
  2344. /* Set AP density */
  2345. if (priv->has_sensitivity) {
  2346. err = hermes_write_wordrec(hw, USER_BAP,
  2347. HERMES_RID_CNFSYSTEMSCALE,
  2348. priv->ap_density);
  2349. if (err) {
  2350. printk(KERN_WARNING "%s: Error %d setting SYSTEMSCALE. "
  2351. "Disabling sensitivity control\n",
  2352. dev->name, err);
  2353. priv->has_sensitivity = 0;
  2354. }
  2355. }
  2356. /* Set RTS threshold */
  2357. err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFRTSTHRESHOLD,
  2358. priv->rts_thresh);
  2359. if (err) {
  2360. printk(KERN_ERR "%s: Error %d setting RTS threshold\n",
  2361. dev->name, err);
  2362. return err;
  2363. }
  2364. /* Set fragmentation threshold or MWO robustness */
  2365. if (priv->has_mwo)
  2366. err = hermes_write_wordrec(hw, USER_BAP,
  2367. HERMES_RID_CNFMWOROBUST_AGERE,
  2368. priv->mwo_robust);
  2369. else
  2370. err = hermes_write_wordrec(hw, USER_BAP,
  2371. HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
  2372. priv->frag_thresh);
  2373. if (err) {
  2374. printk(KERN_ERR "%s: Error %d setting fragmentation\n",
  2375. dev->name, err);
  2376. return err;
  2377. }
  2378. /* Set bitrate */
  2379. err = __orinoco_hw_set_bitrate(priv);
  2380. if (err) {
  2381. printk(KERN_ERR "%s: Error %d setting bitrate\n",
  2382. dev->name, err);
  2383. return err;
  2384. }
  2385. /* Set power management */
  2386. if (priv->has_pm) {
  2387. err = hermes_write_wordrec(hw, USER_BAP,
  2388. HERMES_RID_CNFPMENABLED,
  2389. priv->pm_on);
  2390. if (err) {
  2391. printk(KERN_ERR "%s: Error %d setting up PM\n",
  2392. dev->name, err);
  2393. return err;
  2394. }
  2395. err = hermes_write_wordrec(hw, USER_BAP,
  2396. HERMES_RID_CNFMULTICASTRECEIVE,
  2397. priv->pm_mcast);
  2398. if (err) {
  2399. printk(KERN_ERR "%s: Error %d setting up PM\n",
  2400. dev->name, err);
  2401. return err;
  2402. }
  2403. err = hermes_write_wordrec(hw, USER_BAP,
  2404. HERMES_RID_CNFMAXSLEEPDURATION,
  2405. priv->pm_period);
  2406. if (err) {
  2407. printk(KERN_ERR "%s: Error %d setting up PM\n",
  2408. dev->name, err);
  2409. return err;
  2410. }
  2411. err = hermes_write_wordrec(hw, USER_BAP,
  2412. HERMES_RID_CNFPMHOLDOVERDURATION,
  2413. priv->pm_timeout);
  2414. if (err) {
  2415. printk(KERN_ERR "%s: Error %d setting up PM\n",
  2416. dev->name, err);
  2417. return err;
  2418. }
  2419. }
  2420. /* Set preamble - only for Symbol so far... */
  2421. if (priv->has_preamble) {
  2422. err = hermes_write_wordrec(hw, USER_BAP,
  2423. HERMES_RID_CNFPREAMBLE_SYMBOL,
  2424. priv->preamble);
  2425. if (err) {
  2426. printk(KERN_ERR "%s: Error %d setting preamble\n",
  2427. dev->name, err);
  2428. return err;
  2429. }
  2430. }
  2431. /* Set up encryption */
  2432. if (priv->has_wep || priv->has_wpa) {
  2433. err = __orinoco_hw_setup_enc(priv);
  2434. if (err) {
  2435. printk(KERN_ERR "%s: Error %d activating encryption\n",
  2436. dev->name, err);
  2437. return err;
  2438. }
  2439. }
  2440. if (priv->iw_mode == IW_MODE_MONITOR) {
  2441. /* Enable monitor mode */
  2442. dev->type = ARPHRD_IEEE80211;
  2443. err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
  2444. HERMES_TEST_MONITOR, 0, NULL);
  2445. } else {
  2446. /* Disable monitor mode */
  2447. dev->type = ARPHRD_ETHER;
  2448. err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
  2449. HERMES_TEST_STOP, 0, NULL);
  2450. }
  2451. if (err)
  2452. return err;
  2453. /* Set promiscuity / multicast*/
  2454. priv->promiscuous = 0;
  2455. priv->mc_count = 0;
  2456. /* FIXME: what about netif_tx_lock */
  2457. __orinoco_set_multicast_list(dev);
  2458. return 0;
  2459. }
  2460. /* FIXME: return int? */
  2461. static void
  2462. __orinoco_set_multicast_list(struct net_device *dev)
  2463. {
  2464. struct orinoco_private *priv = netdev_priv(dev);
  2465. hermes_t *hw = &priv->hw;
  2466. int err = 0;
  2467. int promisc, mc_count;
  2468. /* The Hermes doesn't seem to have an allmulti mode, so we go
  2469. * into promiscuous mode and let the upper levels deal. */
  2470. if ( (dev->flags & IFF_PROMISC) || (dev->flags & IFF_ALLMULTI) ||
  2471. (dev->mc_count > MAX_MULTICAST(priv)) ) {
  2472. promisc = 1;
  2473. mc_count = 0;
  2474. } else {
  2475. promisc = 0;
  2476. mc_count = dev->mc_count;
  2477. }
  2478. if (promisc != priv->promiscuous) {
  2479. err = hermes_write_wordrec(hw, USER_BAP,
  2480. HERMES_RID_CNFPROMISCUOUSMODE,
  2481. promisc);
  2482. if (err) {
  2483. printk(KERN_ERR "%s: Error %d setting PROMISCUOUSMODE to 1.\n",
  2484. dev->name, err);
  2485. } else
  2486. priv->promiscuous = promisc;
  2487. }
  2488. /* If we're not in promiscuous mode, then we need to set the
  2489. * group address if either we want to multicast, or if we were
  2490. * multicasting and want to stop */
  2491. if (! promisc && (mc_count || priv->mc_count) ) {
  2492. struct dev_mc_list *p = dev->mc_list;
  2493. struct hermes_multicast mclist;
  2494. int i;
  2495. for (i = 0; i < mc_count; i++) {
  2496. /* paranoia: is list shorter than mc_count? */
  2497. BUG_ON(! p);
  2498. /* paranoia: bad address size in list? */
  2499. BUG_ON(p->dmi_addrlen != ETH_ALEN);
  2500. memcpy(mclist.addr[i], p->dmi_addr, ETH_ALEN);
  2501. p = p->next;
  2502. }
  2503. if (p)
  2504. printk(KERN_WARNING "%s: Multicast list is "
  2505. "longer than mc_count\n", dev->name);
  2506. err = hermes_write_ltv(hw, USER_BAP,
  2507. HERMES_RID_CNFGROUPADDRESSES,
  2508. HERMES_BYTES_TO_RECLEN(mc_count * ETH_ALEN),
  2509. &mclist);
  2510. if (err)
  2511. printk(KERN_ERR "%s: Error %d setting multicast list.\n",
  2512. dev->name, err);
  2513. else
  2514. priv->mc_count = mc_count;
  2515. }
  2516. }
  2517. /* This must be called from user context, without locks held - use
  2518. * schedule_work() */
  2519. static void orinoco_reset(struct work_struct *work)
  2520. {
  2521. struct orinoco_private *priv =
  2522. container_of(work, struct orinoco_private, reset_work);
  2523. struct net_device *dev = priv->ndev;
  2524. struct hermes *hw = &priv->hw;
  2525. int err;
  2526. unsigned long flags;
  2527. if (orinoco_lock(priv, &flags) != 0)
  2528. /* When the hardware becomes available again, whatever
  2529. * detects that is responsible for re-initializing
  2530. * it. So no need for anything further */
  2531. return;
  2532. netif_stop_queue(dev);
  2533. /* Shut off interrupts. Depending on what state the hardware
  2534. * is in, this might not work, but we'll try anyway */
  2535. hermes_set_irqmask(hw, 0);
  2536. hermes_write_regn(hw, EVACK, 0xffff);
  2537. priv->hw_unavailable++;
  2538. priv->last_linkstatus = 0xffff; /* firmware will have to reassociate */
  2539. netif_carrier_off(dev);
  2540. orinoco_unlock(priv, &flags);
  2541. /* Scanning support: Cleanup of driver struct */
  2542. orinoco_clear_scan_results(priv, 0);
  2543. priv->scan_inprogress = 0;
  2544. if (priv->hard_reset) {
  2545. err = (*priv->hard_reset)(priv);
  2546. if (err) {
  2547. printk(KERN_ERR "%s: orinoco_reset: Error %d "
  2548. "performing hard reset\n", dev->name, err);
  2549. goto disable;
  2550. }
  2551. }
  2552. err = orinoco_reinit_firmware(dev);
  2553. if (err) {
  2554. printk(KERN_ERR "%s: orinoco_reset: Error %d re-initializing firmware\n",
  2555. dev->name, err);
  2556. goto disable;
  2557. }
  2558. spin_lock_irq(&priv->lock); /* This has to be called from user context */
  2559. priv->hw_unavailable--;
  2560. /* priv->open or priv->hw_unavailable might have changed while
  2561. * we dropped the lock */
  2562. if (priv->open && (! priv->hw_unavailable)) {
  2563. err = __orinoco_up(dev);
  2564. if (err) {
  2565. printk(KERN_ERR "%s: orinoco_reset: Error %d reenabling card\n",
  2566. dev->name, err);
  2567. } else
  2568. dev->trans_start = jiffies;
  2569. }
  2570. spin_unlock_irq(&priv->lock);
  2571. return;
  2572. disable:
  2573. hermes_set_irqmask(hw, 0);
  2574. netif_device_detach(dev);
  2575. printk(KERN_ERR "%s: Device has been disabled!\n", dev->name);
  2576. }
  2577. /********************************************************************/
  2578. /* Interrupt handler */
  2579. /********************************************************************/
  2580. static void __orinoco_ev_tick(struct net_device *dev, hermes_t *hw)
  2581. {
  2582. printk(KERN_DEBUG "%s: TICK\n", dev->name);
  2583. }
  2584. static void __orinoco_ev_wterr(struct net_device *dev, hermes_t *hw)
  2585. {
  2586. /* This seems to happen a fair bit under load, but ignoring it
  2587. seems to work fine...*/
  2588. printk(KERN_DEBUG "%s: MAC controller error (WTERR). Ignoring.\n",
  2589. dev->name);
  2590. }
  2591. irqreturn_t orinoco_interrupt(int irq, void *dev_id)
  2592. {
  2593. struct net_device *dev = dev_id;
  2594. struct orinoco_private *priv = netdev_priv(dev);
  2595. hermes_t *hw = &priv->hw;
  2596. int count = MAX_IRQLOOPS_PER_IRQ;
  2597. u16 evstat, events;
  2598. /* These are used to detect a runaway interrupt situation */
  2599. /* If we get more than MAX_IRQLOOPS_PER_JIFFY iterations in a jiffy,
  2600. * we panic and shut down the hardware */
  2601. static int last_irq_jiffy = 0; /* jiffies value the last time
  2602. * we were called */
  2603. static int loops_this_jiffy = 0;
  2604. unsigned long flags;
  2605. if (orinoco_lock(priv, &flags) != 0) {
  2606. /* If hw is unavailable - we don't know if the irq was
  2607. * for us or not */
  2608. return IRQ_HANDLED;
  2609. }
  2610. evstat = hermes_read_regn(hw, EVSTAT);
  2611. events = evstat & hw->inten;
  2612. if (! events) {
  2613. orinoco_unlock(priv, &flags);
  2614. return IRQ_NONE;
  2615. }
  2616. if (jiffies != last_irq_jiffy)
  2617. loops_this_jiffy = 0;
  2618. last_irq_jiffy = jiffies;
  2619. while (events && count--) {
  2620. if (++loops_this_jiffy > MAX_IRQLOOPS_PER_JIFFY) {
  2621. printk(KERN_WARNING "%s: IRQ handler is looping too "
  2622. "much! Resetting.\n", dev->name);
  2623. /* Disable interrupts for now */
  2624. hermes_set_irqmask(hw, 0);
  2625. schedule_work(&priv->reset_work);
  2626. break;
  2627. }
  2628. /* Check the card hasn't been removed */
  2629. if (! hermes_present(hw)) {
  2630. DEBUG(0, "orinoco_interrupt(): card removed\n");
  2631. break;
  2632. }
  2633. if (events & HERMES_EV_TICK)
  2634. __orinoco_ev_tick(dev, hw);
  2635. if (events & HERMES_EV_WTERR)
  2636. __orinoco_ev_wterr(dev, hw);
  2637. if (events & HERMES_EV_INFDROP)
  2638. __orinoco_ev_infdrop(dev, hw);
  2639. if (events & HERMES_EV_INFO)
  2640. __orinoco_ev_info(dev, hw);
  2641. if (events & HERMES_EV_RX)
  2642. __orinoco_ev_rx(dev, hw);
  2643. if (events & HERMES_EV_TXEXC)
  2644. __orinoco_ev_txexc(dev, hw);
  2645. if (events & HERMES_EV_TX)
  2646. __orinoco_ev_tx(dev, hw);
  2647. if (events & HERMES_EV_ALLOC)
  2648. __orinoco_ev_alloc(dev, hw);
  2649. hermes_write_regn(hw, EVACK, evstat);
  2650. evstat = hermes_read_regn(hw, EVSTAT);
  2651. events = evstat & hw->inten;
  2652. };
  2653. orinoco_unlock(priv, &flags);
  2654. return IRQ_HANDLED;
  2655. }
  2656. /********************************************************************/
  2657. /* Power management */
  2658. /********************************************************************/
  2659. #if defined(CONFIG_PM_SLEEP) && !defined(CONFIG_HERMES_CACHE_FW_ON_INIT)
  2660. static int orinoco_pm_notifier(struct notifier_block *notifier,
  2661. unsigned long pm_event,
  2662. void *unused)
  2663. {
  2664. struct orinoco_private *priv = container_of(notifier,
  2665. struct orinoco_private,
  2666. pm_notifier);
  2667. /* All we need to do is cache the firmware before suspend, and
  2668. * release it when we come out.
  2669. *
  2670. * Only need to do this if we're downloading firmware. */
  2671. if (!priv->do_fw_download)
  2672. return NOTIFY_DONE;
  2673. switch (pm_event) {
  2674. case PM_HIBERNATION_PREPARE:
  2675. case PM_SUSPEND_PREPARE:
  2676. orinoco_cache_fw(priv, 0);
  2677. break;
  2678. case PM_POST_RESTORE:
  2679. /* Restore from hibernation failed. We need to clean
  2680. * up in exactly the same way, so fall through. */
  2681. case PM_POST_HIBERNATION:
  2682. case PM_POST_SUSPEND:
  2683. orinoco_uncache_fw(priv);
  2684. break;
  2685. case PM_RESTORE_PREPARE:
  2686. default:
  2687. break;
  2688. }
  2689. return NOTIFY_DONE;
  2690. }
  2691. #else /* !PM_SLEEP || HERMES_CACHE_FW_ON_INIT */
  2692. #define orinoco_pm_notifier NULL
  2693. #endif
  2694. /********************************************************************/
  2695. /* Initialization */
  2696. /********************************************************************/
  2697. struct comp_id {
  2698. u16 id, variant, major, minor;
  2699. } __attribute__ ((packed));
  2700. static inline fwtype_t determine_firmware_type(struct comp_id *nic_id)
  2701. {
  2702. if (nic_id->id < 0x8000)
  2703. return FIRMWARE_TYPE_AGERE;
  2704. else if (nic_id->id == 0x8000 && nic_id->major == 0)
  2705. return FIRMWARE_TYPE_SYMBOL;
  2706. else
  2707. return FIRMWARE_TYPE_INTERSIL;
  2708. }
  2709. /* Set priv->firmware type, determine firmware properties */
  2710. static int determine_firmware(struct net_device *dev)
  2711. {
  2712. struct orinoco_private *priv = netdev_priv(dev);
  2713. hermes_t *hw = &priv->hw;
  2714. int err;
  2715. struct comp_id nic_id, sta_id;
  2716. unsigned int firmver;
  2717. char tmp[SYMBOL_MAX_VER_LEN+1] __attribute__((aligned(2)));
  2718. /* Get the hardware version */
  2719. err = HERMES_READ_RECORD(hw, USER_BAP, HERMES_RID_NICID, &nic_id);
  2720. if (err) {
  2721. printk(KERN_ERR "%s: Cannot read hardware identity: error %d\n",
  2722. dev->name, err);
  2723. return err;
  2724. }
  2725. le16_to_cpus(&nic_id.id);
  2726. le16_to_cpus(&nic_id.variant);
  2727. le16_to_cpus(&nic_id.major);
  2728. le16_to_cpus(&nic_id.minor);
  2729. printk(KERN_DEBUG "%s: Hardware identity %04x:%04x:%04x:%04x\n",
  2730. dev->name, nic_id.id, nic_id.variant,
  2731. nic_id.major, nic_id.minor);
  2732. priv->firmware_type = determine_firmware_type(&nic_id);
  2733. /* Get the firmware version */
  2734. err = HERMES_READ_RECORD(hw, USER_BAP, HERMES_RID_STAID, &sta_id);
  2735. if (err) {
  2736. printk(KERN_ERR "%s: Cannot read station identity: error %d\n",
  2737. dev->name, err);
  2738. return err;
  2739. }
  2740. le16_to_cpus(&sta_id.id);
  2741. le16_to_cpus(&sta_id.variant);
  2742. le16_to_cpus(&sta_id.major);
  2743. le16_to_cpus(&sta_id.minor);
  2744. printk(KERN_DEBUG "%s: Station identity %04x:%04x:%04x:%04x\n",
  2745. dev->name, sta_id.id, sta_id.variant,
  2746. sta_id.major, sta_id.minor);
  2747. switch (sta_id.id) {
  2748. case 0x15:
  2749. printk(KERN_ERR "%s: Primary firmware is active\n",
  2750. dev->name);
  2751. return -ENODEV;
  2752. case 0x14b:
  2753. printk(KERN_ERR "%s: Tertiary firmware is active\n",
  2754. dev->name);
  2755. return -ENODEV;
  2756. case 0x1f: /* Intersil, Agere, Symbol Spectrum24 */
  2757. case 0x21: /* Symbol Spectrum24 Trilogy */
  2758. break;
  2759. default:
  2760. printk(KERN_NOTICE "%s: Unknown station ID, please report\n",
  2761. dev->name);
  2762. break;
  2763. }
  2764. /* Default capabilities */
  2765. priv->has_sensitivity = 1;
  2766. priv->has_mwo = 0;
  2767. priv->has_preamble = 0;
  2768. priv->has_port3 = 1;
  2769. priv->has_ibss = 1;
  2770. priv->has_wep = 0;
  2771. priv->has_big_wep = 0;
  2772. priv->has_alt_txcntl = 0;
  2773. priv->has_ext_scan = 0;
  2774. priv->has_wpa = 0;
  2775. priv->do_fw_download = 0;
  2776. /* Determine capabilities from the firmware version */
  2777. switch (priv->firmware_type) {
  2778. case FIRMWARE_TYPE_AGERE:
  2779. /* Lucent Wavelan IEEE, Lucent Orinoco, Cabletron RoamAbout,
  2780. ELSA, Melco, HP, IBM, Dell 1150, Compaq 110/210 */
  2781. snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
  2782. "Lucent/Agere %d.%02d", sta_id.major, sta_id.minor);
  2783. firmver = ((unsigned long)sta_id.major << 16) | sta_id.minor;
  2784. priv->has_ibss = (firmver >= 0x60006);
  2785. priv->has_wep = (firmver >= 0x40020);
  2786. priv->has_big_wep = 1; /* FIXME: this is wrong - how do we tell
  2787. Gold cards from the others? */
  2788. priv->has_mwo = (firmver >= 0x60000);
  2789. priv->has_pm = (firmver >= 0x40020); /* Don't work in 7.52 ? */
  2790. priv->ibss_port = 1;
  2791. priv->has_hostscan = (firmver >= 0x8000a);
  2792. priv->do_fw_download = 1;
  2793. priv->broken_monitor = (firmver >= 0x80000);
  2794. priv->has_alt_txcntl = (firmver >= 0x90000); /* All 9.x ? */
  2795. priv->has_ext_scan = (firmver >= 0x90000); /* All 9.x ? */
  2796. priv->has_wpa = (firmver >= 0x9002a);
  2797. /* Tested with Agere firmware :
  2798. * 1.16 ; 4.08 ; 4.52 ; 6.04 ; 6.16 ; 7.28 => Jean II
  2799. * Tested CableTron firmware : 4.32 => Anton */
  2800. break;
  2801. case FIRMWARE_TYPE_SYMBOL:
  2802. /* Symbol , 3Com AirConnect, Intel, Ericsson WLAN */
  2803. /* Intel MAC : 00:02:B3:* */
  2804. /* 3Com MAC : 00:50:DA:* */
  2805. memset(tmp, 0, sizeof(tmp));
  2806. /* Get the Symbol firmware version */
  2807. err = hermes_read_ltv(hw, USER_BAP,
  2808. HERMES_RID_SECONDARYVERSION_SYMBOL,
  2809. SYMBOL_MAX_VER_LEN, NULL, &tmp);
  2810. if (err) {
  2811. printk(KERN_WARNING
  2812. "%s: Error %d reading Symbol firmware info. Wildly guessing capabilities...\n",
  2813. dev->name, err);
  2814. firmver = 0;
  2815. tmp[0] = '\0';
  2816. } else {
  2817. /* The firmware revision is a string, the format is
  2818. * something like : "V2.20-01".
  2819. * Quick and dirty parsing... - Jean II
  2820. */
  2821. firmver = ((tmp[1] - '0') << 16) | ((tmp[3] - '0') << 12)
  2822. | ((tmp[4] - '0') << 8) | ((tmp[6] - '0') << 4)
  2823. | (tmp[7] - '0');
  2824. tmp[SYMBOL_MAX_VER_LEN] = '\0';
  2825. }
  2826. snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
  2827. "Symbol %s", tmp);
  2828. priv->has_ibss = (firmver >= 0x20000);
  2829. priv->has_wep = (firmver >= 0x15012);
  2830. priv->has_big_wep = (firmver >= 0x20000);
  2831. priv->has_pm = (firmver >= 0x20000 && firmver < 0x22000) ||
  2832. (firmver >= 0x29000 && firmver < 0x30000) ||
  2833. firmver >= 0x31000;
  2834. priv->has_preamble = (firmver >= 0x20000);
  2835. priv->ibss_port = 4;
  2836. /* Symbol firmware is found on various cards, but
  2837. * there has been no attempt to check firmware
  2838. * download on non-spectrum_cs based cards.
  2839. *
  2840. * Given that the Agere firmware download works
  2841. * differently, we should avoid doing a firmware
  2842. * download with the Symbol algorithm on non-spectrum
  2843. * cards.
  2844. *
  2845. * For now we can identify a spectrum_cs based card
  2846. * because it has a firmware reset function.
  2847. */
  2848. priv->do_fw_download = (priv->stop_fw != NULL);
  2849. priv->broken_disableport = (firmver == 0x25013) ||
  2850. (firmver >= 0x30000 && firmver <= 0x31000);
  2851. priv->has_hostscan = (firmver >= 0x31001) ||
  2852. (firmver >= 0x29057 && firmver < 0x30000);
  2853. /* Tested with Intel firmware : 0x20015 => Jean II */
  2854. /* Tested with 3Com firmware : 0x15012 & 0x22001 => Jean II */
  2855. break;
  2856. case FIRMWARE_TYPE_INTERSIL:
  2857. /* D-Link, Linksys, Adtron, ZoomAir, and many others...
  2858. * Samsung, Compaq 100/200 and Proxim are slightly
  2859. * different and less well tested */
  2860. /* D-Link MAC : 00:40:05:* */
  2861. /* Addtron MAC : 00:90:D1:* */
  2862. snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
  2863. "Intersil %d.%d.%d", sta_id.major, sta_id.minor,
  2864. sta_id.variant);
  2865. firmver = ((unsigned long)sta_id.major << 16) |
  2866. ((unsigned long)sta_id.minor << 8) | sta_id.variant;
  2867. priv->has_ibss = (firmver >= 0x000700); /* FIXME */
  2868. priv->has_big_wep = priv->has_wep = (firmver >= 0x000800);
  2869. priv->has_pm = (firmver >= 0x000700);
  2870. priv->has_hostscan = (firmver >= 0x010301);
  2871. if (firmver >= 0x000800)
  2872. priv->ibss_port = 0;
  2873. else {
  2874. printk(KERN_NOTICE "%s: Intersil firmware earlier "
  2875. "than v0.8.x - several features not supported\n",
  2876. dev->name);
  2877. priv->ibss_port = 1;
  2878. }
  2879. break;
  2880. }
  2881. printk(KERN_DEBUG "%s: Firmware determined as %s\n", dev->name,
  2882. priv->fw_name);
  2883. return 0;
  2884. }
  2885. static int orinoco_init(struct net_device *dev)
  2886. {
  2887. struct orinoco_private *priv = netdev_priv(dev);
  2888. hermes_t *hw = &priv->hw;
  2889. int err = 0;
  2890. struct hermes_idstring nickbuf;
  2891. u16 reclen;
  2892. int len;
  2893. /* No need to lock, the hw_unavailable flag is already set in
  2894. * alloc_orinocodev() */
  2895. priv->nicbuf_size = IEEE80211_MAX_FRAME_LEN + ETH_HLEN;
  2896. /* Initialize the firmware */
  2897. err = hermes_init(hw);
  2898. if (err != 0) {
  2899. printk(KERN_ERR "%s: failed to initialize firmware (err = %d)\n",
  2900. dev->name, err);
  2901. goto out;
  2902. }
  2903. err = determine_firmware(dev);
  2904. if (err != 0) {
  2905. printk(KERN_ERR "%s: Incompatible firmware, aborting\n",
  2906. dev->name);
  2907. goto out;
  2908. }
  2909. if (priv->do_fw_download) {
  2910. #ifdef CONFIG_HERMES_CACHE_FW_ON_INIT
  2911. orinoco_cache_fw(priv, 0);
  2912. #endif
  2913. err = orinoco_download(priv);
  2914. if (err)
  2915. priv->do_fw_download = 0;
  2916. /* Check firmware version again */
  2917. err = determine_firmware(dev);
  2918. if (err != 0) {
  2919. printk(KERN_ERR "%s: Incompatible firmware, aborting\n",
  2920. dev->name);
  2921. goto out;
  2922. }
  2923. }
  2924. if (priv->has_port3)
  2925. printk(KERN_DEBUG "%s: Ad-hoc demo mode supported\n", dev->name);
  2926. if (priv->has_ibss)
  2927. printk(KERN_DEBUG "%s: IEEE standard IBSS ad-hoc mode supported\n",
  2928. dev->name);
  2929. if (priv->has_wep) {
  2930. printk(KERN_DEBUG "%s: WEP supported, ", dev->name);
  2931. if (priv->has_big_wep)
  2932. printk("104-bit key\n");
  2933. else
  2934. printk("40-bit key\n");
  2935. }
  2936. if (priv->has_wpa) {
  2937. printk(KERN_DEBUG "%s: WPA-PSK supported\n", dev->name);
  2938. if (orinoco_mic_init(priv)) {
  2939. printk(KERN_ERR "%s: Failed to setup MIC crypto "
  2940. "algorithm. Disabling WPA support\n", dev->name);
  2941. priv->has_wpa = 0;
  2942. }
  2943. }
  2944. /* Now we have the firmware capabilities, allocate appropiate
  2945. * sized scan buffers */
  2946. if (orinoco_bss_data_allocate(priv))
  2947. goto out;
  2948. orinoco_bss_data_init(priv);
  2949. /* Get the MAC address */
  2950. err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CNFOWNMACADDR,
  2951. ETH_ALEN, NULL, dev->dev_addr);
  2952. if (err) {
  2953. printk(KERN_WARNING "%s: failed to read MAC address!\n",
  2954. dev->name);
  2955. goto out;
  2956. }
  2957. printk(KERN_DEBUG "%s: MAC address %pM\n",
  2958. dev->name, dev->dev_addr);
  2959. /* Get the station name */
  2960. err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CNFOWNNAME,
  2961. sizeof(nickbuf), &reclen, &nickbuf);
  2962. if (err) {
  2963. printk(KERN_ERR "%s: failed to read station name\n",
  2964. dev->name);
  2965. goto out;
  2966. }
  2967. if (nickbuf.len)
  2968. len = min(IW_ESSID_MAX_SIZE, (int)le16_to_cpu(nickbuf.len));
  2969. else
  2970. len = min(IW_ESSID_MAX_SIZE, 2 * reclen);
  2971. memcpy(priv->nick, &nickbuf.val, len);
  2972. priv->nick[len] = '\0';
  2973. printk(KERN_DEBUG "%s: Station name \"%s\"\n", dev->name, priv->nick);
  2974. err = orinoco_allocate_fid(dev);
  2975. if (err) {
  2976. printk(KERN_ERR "%s: failed to allocate NIC buffer!\n",
  2977. dev->name);
  2978. goto out;
  2979. }
  2980. /* Get allowed channels */
  2981. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CHANNELLIST,
  2982. &priv->channel_mask);
  2983. if (err) {
  2984. printk(KERN_ERR "%s: failed to read channel list!\n",
  2985. dev->name);
  2986. goto out;
  2987. }
  2988. /* Get initial AP density */
  2989. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFSYSTEMSCALE,
  2990. &priv->ap_density);
  2991. if (err || priv->ap_density < 1 || priv->ap_density > 3) {
  2992. priv->has_sensitivity = 0;
  2993. }
  2994. /* Get initial RTS threshold */
  2995. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFRTSTHRESHOLD,
  2996. &priv->rts_thresh);
  2997. if (err) {
  2998. printk(KERN_ERR "%s: failed to read RTS threshold!\n",
  2999. dev->name);
  3000. goto out;
  3001. }
  3002. /* Get initial fragmentation settings */
  3003. if (priv->has_mwo)
  3004. err = hermes_read_wordrec(hw, USER_BAP,
  3005. HERMES_RID_CNFMWOROBUST_AGERE,
  3006. &priv->mwo_robust);
  3007. else
  3008. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
  3009. &priv->frag_thresh);
  3010. if (err) {
  3011. printk(KERN_ERR "%s: failed to read fragmentation settings!\n",
  3012. dev->name);
  3013. goto out;
  3014. }
  3015. /* Power management setup */
  3016. if (priv->has_pm) {
  3017. priv->pm_on = 0;
  3018. priv->pm_mcast = 1;
  3019. err = hermes_read_wordrec(hw, USER_BAP,
  3020. HERMES_RID_CNFMAXSLEEPDURATION,
  3021. &priv->pm_period);
  3022. if (err) {
  3023. printk(KERN_ERR "%s: failed to read power management period!\n",
  3024. dev->name);
  3025. goto out;
  3026. }
  3027. err = hermes_read_wordrec(hw, USER_BAP,
  3028. HERMES_RID_CNFPMHOLDOVERDURATION,
  3029. &priv->pm_timeout);
  3030. if (err) {
  3031. printk(KERN_ERR "%s: failed to read power management timeout!\n",
  3032. dev->name);
  3033. goto out;
  3034. }
  3035. }
  3036. /* Preamble setup */
  3037. if (priv->has_preamble) {
  3038. err = hermes_read_wordrec(hw, USER_BAP,
  3039. HERMES_RID_CNFPREAMBLE_SYMBOL,
  3040. &priv->preamble);
  3041. if (err)
  3042. goto out;
  3043. }
  3044. /* Set up the default configuration */
  3045. priv->iw_mode = IW_MODE_INFRA;
  3046. /* By default use IEEE/IBSS ad-hoc mode if we have it */
  3047. priv->prefer_port3 = priv->has_port3 && (! priv->has_ibss);
  3048. set_port_type(priv);
  3049. priv->channel = 0; /* use firmware default */
  3050. priv->promiscuous = 0;
  3051. priv->encode_alg = IW_ENCODE_ALG_NONE;
  3052. priv->tx_key = 0;
  3053. priv->wpa_enabled = 0;
  3054. priv->tkip_cm_active = 0;
  3055. priv->key_mgmt = 0;
  3056. priv->wpa_ie_len = 0;
  3057. priv->wpa_ie = NULL;
  3058. /* Make the hardware available, as long as it hasn't been
  3059. * removed elsewhere (e.g. by PCMCIA hot unplug) */
  3060. spin_lock_irq(&priv->lock);
  3061. priv->hw_unavailable--;
  3062. spin_unlock_irq(&priv->lock);
  3063. printk(KERN_DEBUG "%s: ready\n", dev->name);
  3064. out:
  3065. return err;
  3066. }
  3067. struct net_device
  3068. *alloc_orinocodev(int sizeof_card,
  3069. struct device *device,
  3070. int (*hard_reset)(struct orinoco_private *),
  3071. int (*stop_fw)(struct orinoco_private *, int))
  3072. {
  3073. struct net_device *dev;
  3074. struct orinoco_private *priv;
  3075. dev = alloc_etherdev(sizeof(struct orinoco_private) + sizeof_card);
  3076. if (! dev)
  3077. return NULL;
  3078. priv = netdev_priv(dev);
  3079. priv->ndev = dev;
  3080. if (sizeof_card)
  3081. priv->card = (void *)((unsigned long)priv
  3082. + sizeof(struct orinoco_private));
  3083. else
  3084. priv->card = NULL;
  3085. priv->dev = device;
  3086. /* Setup / override net_device fields */
  3087. dev->init = orinoco_init;
  3088. dev->hard_start_xmit = orinoco_xmit;
  3089. dev->tx_timeout = orinoco_tx_timeout;
  3090. dev->watchdog_timeo = HZ; /* 1 second timeout */
  3091. dev->get_stats = orinoco_get_stats;
  3092. dev->ethtool_ops = &orinoco_ethtool_ops;
  3093. dev->wireless_handlers = (struct iw_handler_def *)&orinoco_handler_def;
  3094. #ifdef WIRELESS_SPY
  3095. priv->wireless_data.spy_data = &priv->spy_data;
  3096. dev->wireless_data = &priv->wireless_data;
  3097. #endif
  3098. dev->change_mtu = orinoco_change_mtu;
  3099. dev->set_multicast_list = orinoco_set_multicast_list;
  3100. /* we use the default eth_mac_addr for setting the MAC addr */
  3101. /* Reserve space in skb for the SNAP header */
  3102. dev->hard_header_len += ENCAPS_OVERHEAD;
  3103. /* Set up default callbacks */
  3104. dev->open = orinoco_open;
  3105. dev->stop = orinoco_stop;
  3106. priv->hard_reset = hard_reset;
  3107. priv->stop_fw = stop_fw;
  3108. spin_lock_init(&priv->lock);
  3109. priv->open = 0;
  3110. priv->hw_unavailable = 1; /* orinoco_init() must clear this
  3111. * before anything else touches the
  3112. * hardware */
  3113. INIT_WORK(&priv->reset_work, orinoco_reset);
  3114. INIT_WORK(&priv->join_work, orinoco_join_ap);
  3115. INIT_WORK(&priv->wevent_work, orinoco_send_wevents);
  3116. INIT_LIST_HEAD(&priv->rx_list);
  3117. tasklet_init(&priv->rx_tasklet, orinoco_rx_isr_tasklet,
  3118. (unsigned long) dev);
  3119. netif_carrier_off(dev);
  3120. priv->last_linkstatus = 0xffff;
  3121. priv->cached_pri_fw = NULL;
  3122. priv->cached_fw = NULL;
  3123. /* Register PM notifiers */
  3124. priv->pm_notifier.notifier_call = orinoco_pm_notifier;
  3125. register_pm_notifier(&priv->pm_notifier);
  3126. return dev;
  3127. }
  3128. void free_orinocodev(struct net_device *dev)
  3129. {
  3130. struct orinoco_private *priv = netdev_priv(dev);
  3131. /* No need to empty priv->rx_list: if the tasklet is scheduled
  3132. * when we call tasklet_kill it will run one final time,
  3133. * emptying the list */
  3134. tasklet_kill(&priv->rx_tasklet);
  3135. unregister_pm_notifier(&priv->pm_notifier);
  3136. orinoco_uncache_fw(priv);
  3137. priv->wpa_ie_len = 0;
  3138. kfree(priv->wpa_ie);
  3139. orinoco_mic_free(priv);
  3140. orinoco_bss_data_free(priv);
  3141. free_netdev(dev);
  3142. }
  3143. /********************************************************************/
  3144. /* Wireless extensions */
  3145. /********************************************************************/
  3146. /* Return : < 0 -> error code ; >= 0 -> length */
  3147. static int orinoco_hw_get_essid(struct orinoco_private *priv, int *active,
  3148. char buf[IW_ESSID_MAX_SIZE+1])
  3149. {
  3150. hermes_t *hw = &priv->hw;
  3151. int err = 0;
  3152. struct hermes_idstring essidbuf;
  3153. char *p = (char *)(&essidbuf.val);
  3154. int len;
  3155. unsigned long flags;
  3156. if (orinoco_lock(priv, &flags) != 0)
  3157. return -EBUSY;
  3158. if (strlen(priv->desired_essid) > 0) {
  3159. /* We read the desired SSID from the hardware rather
  3160. than from priv->desired_essid, just in case the
  3161. firmware is allowed to change it on us. I'm not
  3162. sure about this */
  3163. /* My guess is that the OWNSSID should always be whatever
  3164. * we set to the card, whereas CURRENT_SSID is the one that
  3165. * may change... - Jean II */
  3166. u16 rid;
  3167. *active = 1;
  3168. rid = (priv->port_type == 3) ? HERMES_RID_CNFOWNSSID :
  3169. HERMES_RID_CNFDESIREDSSID;
  3170. err = hermes_read_ltv(hw, USER_BAP, rid, sizeof(essidbuf),
  3171. NULL, &essidbuf);
  3172. if (err)
  3173. goto fail_unlock;
  3174. } else {
  3175. *active = 0;
  3176. err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTSSID,
  3177. sizeof(essidbuf), NULL, &essidbuf);
  3178. if (err)
  3179. goto fail_unlock;
  3180. }
  3181. len = le16_to_cpu(essidbuf.len);
  3182. BUG_ON(len > IW_ESSID_MAX_SIZE);
  3183. memset(buf, 0, IW_ESSID_MAX_SIZE);
  3184. memcpy(buf, p, len);
  3185. err = len;
  3186. fail_unlock:
  3187. orinoco_unlock(priv, &flags);
  3188. return err;
  3189. }
  3190. static long orinoco_hw_get_freq(struct orinoco_private *priv)
  3191. {
  3192. hermes_t *hw = &priv->hw;
  3193. int err = 0;
  3194. u16 channel;
  3195. long freq = 0;
  3196. unsigned long flags;
  3197. if (orinoco_lock(priv, &flags) != 0)
  3198. return -EBUSY;
  3199. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CURRENTCHANNEL, &channel);
  3200. if (err)
  3201. goto out;
  3202. /* Intersil firmware 1.3.5 returns 0 when the interface is down */
  3203. if (channel == 0) {
  3204. err = -EBUSY;
  3205. goto out;
  3206. }
  3207. if ( (channel < 1) || (channel > NUM_CHANNELS) ) {
  3208. printk(KERN_WARNING "%s: Channel out of range (%d)!\n",
  3209. priv->ndev->name, channel);
  3210. err = -EBUSY;
  3211. goto out;
  3212. }
  3213. freq = channel_frequency[channel-1] * 100000;
  3214. out:
  3215. orinoco_unlock(priv, &flags);
  3216. if (err > 0)
  3217. err = -EBUSY;
  3218. return err ? err : freq;
  3219. }
  3220. static int orinoco_hw_get_bitratelist(struct orinoco_private *priv,
  3221. int *numrates, s32 *rates, int max)
  3222. {
  3223. hermes_t *hw = &priv->hw;
  3224. struct hermes_idstring list;
  3225. unsigned char *p = (unsigned char *)&list.val;
  3226. int err = 0;
  3227. int num;
  3228. int i;
  3229. unsigned long flags;
  3230. if (orinoco_lock(priv, &flags) != 0)
  3231. return -EBUSY;
  3232. err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_SUPPORTEDDATARATES,
  3233. sizeof(list), NULL, &list);
  3234. orinoco_unlock(priv, &flags);
  3235. if (err)
  3236. return err;
  3237. num = le16_to_cpu(list.len);
  3238. *numrates = num;
  3239. num = min(num, max);
  3240. for (i = 0; i < num; i++) {
  3241. rates[i] = (p[i] & 0x7f) * 500000; /* convert to bps */
  3242. }
  3243. return 0;
  3244. }
  3245. static int orinoco_ioctl_getname(struct net_device *dev,
  3246. struct iw_request_info *info,
  3247. char *name,
  3248. char *extra)
  3249. {
  3250. struct orinoco_private *priv = netdev_priv(dev);
  3251. int numrates;
  3252. int err;
  3253. err = orinoco_hw_get_bitratelist(priv, &numrates, NULL, 0);
  3254. if (!err && (numrates > 2))
  3255. strcpy(name, "IEEE 802.11b");
  3256. else
  3257. strcpy(name, "IEEE 802.11-DS");
  3258. return 0;
  3259. }
  3260. static int orinoco_ioctl_setwap(struct net_device *dev,
  3261. struct iw_request_info *info,
  3262. struct sockaddr *ap_addr,
  3263. char *extra)
  3264. {
  3265. struct orinoco_private *priv = netdev_priv(dev);
  3266. int err = -EINPROGRESS; /* Call commit handler */
  3267. unsigned long flags;
  3268. static const u8 off_addr[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  3269. static const u8 any_addr[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
  3270. if (orinoco_lock(priv, &flags) != 0)
  3271. return -EBUSY;
  3272. /* Enable automatic roaming - no sanity checks are needed */
  3273. if (memcmp(&ap_addr->sa_data, off_addr, ETH_ALEN) == 0 ||
  3274. memcmp(&ap_addr->sa_data, any_addr, ETH_ALEN) == 0) {
  3275. priv->bssid_fixed = 0;
  3276. memset(priv->desired_bssid, 0, ETH_ALEN);
  3277. /* "off" means keep existing connection */
  3278. if (ap_addr->sa_data[0] == 0) {
  3279. __orinoco_hw_set_wap(priv);
  3280. err = 0;
  3281. }
  3282. goto out;
  3283. }
  3284. if (priv->firmware_type == FIRMWARE_TYPE_AGERE) {
  3285. printk(KERN_WARNING "%s: Lucent/Agere firmware doesn't "
  3286. "support manual roaming\n",
  3287. dev->name);
  3288. err = -EOPNOTSUPP;
  3289. goto out;
  3290. }
  3291. if (priv->iw_mode != IW_MODE_INFRA) {
  3292. printk(KERN_WARNING "%s: Manual roaming supported only in "
  3293. "managed mode\n", dev->name);
  3294. err = -EOPNOTSUPP;
  3295. goto out;
  3296. }
  3297. /* Intersil firmware hangs without Desired ESSID */
  3298. if (priv->firmware_type == FIRMWARE_TYPE_INTERSIL &&
  3299. strlen(priv->desired_essid) == 0) {
  3300. printk(KERN_WARNING "%s: Desired ESSID must be set for "
  3301. "manual roaming\n", dev->name);
  3302. err = -EOPNOTSUPP;
  3303. goto out;
  3304. }
  3305. /* Finally, enable manual roaming */
  3306. priv->bssid_fixed = 1;
  3307. memcpy(priv->desired_bssid, &ap_addr->sa_data, ETH_ALEN);
  3308. out:
  3309. orinoco_unlock(priv, &flags);
  3310. return err;
  3311. }
  3312. static int orinoco_ioctl_getwap(struct net_device *dev,
  3313. struct iw_request_info *info,
  3314. struct sockaddr *ap_addr,
  3315. char *extra)
  3316. {
  3317. struct orinoco_private *priv = netdev_priv(dev);
  3318. hermes_t *hw = &priv->hw;
  3319. int err = 0;
  3320. unsigned long flags;
  3321. if (orinoco_lock(priv, &flags) != 0)
  3322. return -EBUSY;
  3323. ap_addr->sa_family = ARPHRD_ETHER;
  3324. err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTBSSID,
  3325. ETH_ALEN, NULL, ap_addr->sa_data);
  3326. orinoco_unlock(priv, &flags);
  3327. return err;
  3328. }
  3329. static int orinoco_ioctl_setmode(struct net_device *dev,
  3330. struct iw_request_info *info,
  3331. u32 *mode,
  3332. char *extra)
  3333. {
  3334. struct orinoco_private *priv = netdev_priv(dev);
  3335. int err = -EINPROGRESS; /* Call commit handler */
  3336. unsigned long flags;
  3337. if (priv->iw_mode == *mode)
  3338. return 0;
  3339. if (orinoco_lock(priv, &flags) != 0)
  3340. return -EBUSY;
  3341. switch (*mode) {
  3342. case IW_MODE_ADHOC:
  3343. if (!priv->has_ibss && !priv->has_port3)
  3344. err = -EOPNOTSUPP;
  3345. break;
  3346. case IW_MODE_INFRA:
  3347. break;
  3348. case IW_MODE_MONITOR:
  3349. if (priv->broken_monitor && !force_monitor) {
  3350. printk(KERN_WARNING "%s: Monitor mode support is "
  3351. "buggy in this firmware, not enabling\n",
  3352. dev->name);
  3353. err = -EOPNOTSUPP;
  3354. }
  3355. break;
  3356. default:
  3357. err = -EOPNOTSUPP;
  3358. break;
  3359. }
  3360. if (err == -EINPROGRESS) {
  3361. priv->iw_mode = *mode;
  3362. set_port_type(priv);
  3363. }
  3364. orinoco_unlock(priv, &flags);
  3365. return err;
  3366. }
  3367. static int orinoco_ioctl_getmode(struct net_device *dev,
  3368. struct iw_request_info *info,
  3369. u32 *mode,
  3370. char *extra)
  3371. {
  3372. struct orinoco_private *priv = netdev_priv(dev);
  3373. *mode = priv->iw_mode;
  3374. return 0;
  3375. }
  3376. static int orinoco_ioctl_getiwrange(struct net_device *dev,
  3377. struct iw_request_info *info,
  3378. struct iw_point *rrq,
  3379. char *extra)
  3380. {
  3381. struct orinoco_private *priv = netdev_priv(dev);
  3382. int err = 0;
  3383. struct iw_range *range = (struct iw_range *) extra;
  3384. int numrates;
  3385. int i, k;
  3386. rrq->length = sizeof(struct iw_range);
  3387. memset(range, 0, sizeof(struct iw_range));
  3388. range->we_version_compiled = WIRELESS_EXT;
  3389. range->we_version_source = 22;
  3390. /* Set available channels/frequencies */
  3391. range->num_channels = NUM_CHANNELS;
  3392. k = 0;
  3393. for (i = 0; i < NUM_CHANNELS; i++) {
  3394. if (priv->channel_mask & (1 << i)) {
  3395. range->freq[k].i = i + 1;
  3396. range->freq[k].m = channel_frequency[i] * 100000;
  3397. range->freq[k].e = 1;
  3398. k++;
  3399. }
  3400. if (k >= IW_MAX_FREQUENCIES)
  3401. break;
  3402. }
  3403. range->num_frequency = k;
  3404. range->sensitivity = 3;
  3405. if (priv->has_wep) {
  3406. range->max_encoding_tokens = ORINOCO_MAX_KEYS;
  3407. range->encoding_size[0] = SMALL_KEY_SIZE;
  3408. range->num_encoding_sizes = 1;
  3409. if (priv->has_big_wep) {
  3410. range->encoding_size[1] = LARGE_KEY_SIZE;
  3411. range->num_encoding_sizes = 2;
  3412. }
  3413. }
  3414. if (priv->has_wpa)
  3415. range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_CIPHER_TKIP;
  3416. if ((priv->iw_mode == IW_MODE_ADHOC) && (!SPY_NUMBER(priv))){
  3417. /* Quality stats meaningless in ad-hoc mode */
  3418. } else {
  3419. range->max_qual.qual = 0x8b - 0x2f;
  3420. range->max_qual.level = 0x2f - 0x95 - 1;
  3421. range->max_qual.noise = 0x2f - 0x95 - 1;
  3422. /* Need to get better values */
  3423. range->avg_qual.qual = 0x24;
  3424. range->avg_qual.level = 0xC2;
  3425. range->avg_qual.noise = 0x9E;
  3426. }
  3427. err = orinoco_hw_get_bitratelist(priv, &numrates,
  3428. range->bitrate, IW_MAX_BITRATES);
  3429. if (err)
  3430. return err;
  3431. range->num_bitrates = numrates;
  3432. /* Set an indication of the max TCP throughput in bit/s that we can
  3433. * expect using this interface. May be use for QoS stuff...
  3434. * Jean II */
  3435. if (numrates > 2)
  3436. range->throughput = 5 * 1000 * 1000; /* ~5 Mb/s */
  3437. else
  3438. range->throughput = 1.5 * 1000 * 1000; /* ~1.5 Mb/s */
  3439. range->min_rts = 0;
  3440. range->max_rts = 2347;
  3441. range->min_frag = 256;
  3442. range->max_frag = 2346;
  3443. range->min_pmp = 0;
  3444. range->max_pmp = 65535000;
  3445. range->min_pmt = 0;
  3446. range->max_pmt = 65535 * 1000; /* ??? */
  3447. range->pmp_flags = IW_POWER_PERIOD;
  3448. range->pmt_flags = IW_POWER_TIMEOUT;
  3449. range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT | IW_POWER_UNICAST_R;
  3450. range->retry_capa = IW_RETRY_LIMIT | IW_RETRY_LIFETIME;
  3451. range->retry_flags = IW_RETRY_LIMIT;
  3452. range->r_time_flags = IW_RETRY_LIFETIME;
  3453. range->min_retry = 0;
  3454. range->max_retry = 65535; /* ??? */
  3455. range->min_r_time = 0;
  3456. range->max_r_time = 65535 * 1000; /* ??? */
  3457. if (priv->firmware_type == FIRMWARE_TYPE_AGERE)
  3458. range->scan_capa = IW_SCAN_CAPA_ESSID;
  3459. else
  3460. range->scan_capa = IW_SCAN_CAPA_NONE;
  3461. /* Event capability (kernel) */
  3462. IW_EVENT_CAPA_SET_KERNEL(range->event_capa);
  3463. /* Event capability (driver) */
  3464. IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWTHRSPY);
  3465. IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWAP);
  3466. IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWSCAN);
  3467. IW_EVENT_CAPA_SET(range->event_capa, IWEVTXDROP);
  3468. return 0;
  3469. }
  3470. static int orinoco_ioctl_setiwencode(struct net_device *dev,
  3471. struct iw_request_info *info,
  3472. struct iw_point *erq,
  3473. char *keybuf)
  3474. {
  3475. struct orinoco_private *priv = netdev_priv(dev);
  3476. int index = (erq->flags & IW_ENCODE_INDEX) - 1;
  3477. int setindex = priv->tx_key;
  3478. int encode_alg = priv->encode_alg;
  3479. int restricted = priv->wep_restrict;
  3480. u16 xlen = 0;
  3481. int err = -EINPROGRESS; /* Call commit handler */
  3482. unsigned long flags;
  3483. if (! priv->has_wep)
  3484. return -EOPNOTSUPP;
  3485. if (erq->pointer) {
  3486. /* We actually have a key to set - check its length */
  3487. if (erq->length > LARGE_KEY_SIZE)
  3488. return -E2BIG;
  3489. if ( (erq->length > SMALL_KEY_SIZE) && !priv->has_big_wep )
  3490. return -E2BIG;
  3491. }
  3492. if (orinoco_lock(priv, &flags) != 0)
  3493. return -EBUSY;
  3494. /* Clear any TKIP key we have */
  3495. if ((priv->has_wpa) && (priv->encode_alg == IW_ENCODE_ALG_TKIP))
  3496. (void) orinoco_clear_tkip_key(priv, setindex);
  3497. if (erq->length > 0) {
  3498. if ((index < 0) || (index >= ORINOCO_MAX_KEYS))
  3499. index = priv->tx_key;
  3500. /* Adjust key length to a supported value */
  3501. if (erq->length > SMALL_KEY_SIZE) {
  3502. xlen = LARGE_KEY_SIZE;
  3503. } else if (erq->length > 0) {
  3504. xlen = SMALL_KEY_SIZE;
  3505. } else
  3506. xlen = 0;
  3507. /* Switch on WEP if off */
  3508. if ((encode_alg != IW_ENCODE_ALG_WEP) && (xlen > 0)) {
  3509. setindex = index;
  3510. encode_alg = IW_ENCODE_ALG_WEP;
  3511. }
  3512. } else {
  3513. /* Important note : if the user do "iwconfig eth0 enc off",
  3514. * we will arrive there with an index of -1. This is valid
  3515. * but need to be taken care off... Jean II */
  3516. if ((index < 0) || (index >= ORINOCO_MAX_KEYS)) {
  3517. if((index != -1) || (erq->flags == 0)) {
  3518. err = -EINVAL;
  3519. goto out;
  3520. }
  3521. } else {
  3522. /* Set the index : Check that the key is valid */
  3523. if(priv->keys[index].len == 0) {
  3524. err = -EINVAL;
  3525. goto out;
  3526. }
  3527. setindex = index;
  3528. }
  3529. }
  3530. if (erq->flags & IW_ENCODE_DISABLED)
  3531. encode_alg = IW_ENCODE_ALG_NONE;
  3532. if (erq->flags & IW_ENCODE_OPEN)
  3533. restricted = 0;
  3534. if (erq->flags & IW_ENCODE_RESTRICTED)
  3535. restricted = 1;
  3536. if (erq->pointer && erq->length > 0) {
  3537. priv->keys[index].len = cpu_to_le16(xlen);
  3538. memset(priv->keys[index].data, 0,
  3539. sizeof(priv->keys[index].data));
  3540. memcpy(priv->keys[index].data, keybuf, erq->length);
  3541. }
  3542. priv->tx_key = setindex;
  3543. /* Try fast key change if connected and only keys are changed */
  3544. if ((priv->encode_alg == encode_alg) &&
  3545. (priv->wep_restrict == restricted) &&
  3546. netif_carrier_ok(dev)) {
  3547. err = __orinoco_hw_setup_wepkeys(priv);
  3548. /* No need to commit if successful */
  3549. goto out;
  3550. }
  3551. priv->encode_alg = encode_alg;
  3552. priv->wep_restrict = restricted;
  3553. out:
  3554. orinoco_unlock(priv, &flags);
  3555. return err;
  3556. }
  3557. static int orinoco_ioctl_getiwencode(struct net_device *dev,
  3558. struct iw_request_info *info,
  3559. struct iw_point *erq,
  3560. char *keybuf)
  3561. {
  3562. struct orinoco_private *priv = netdev_priv(dev);
  3563. int index = (erq->flags & IW_ENCODE_INDEX) - 1;
  3564. u16 xlen = 0;
  3565. unsigned long flags;
  3566. if (! priv->has_wep)
  3567. return -EOPNOTSUPP;
  3568. if (orinoco_lock(priv, &flags) != 0)
  3569. return -EBUSY;
  3570. if ((index < 0) || (index >= ORINOCO_MAX_KEYS))
  3571. index = priv->tx_key;
  3572. erq->flags = 0;
  3573. if (!priv->encode_alg)
  3574. erq->flags |= IW_ENCODE_DISABLED;
  3575. erq->flags |= index + 1;
  3576. if (priv->wep_restrict)
  3577. erq->flags |= IW_ENCODE_RESTRICTED;
  3578. else
  3579. erq->flags |= IW_ENCODE_OPEN;
  3580. xlen = le16_to_cpu(priv->keys[index].len);
  3581. erq->length = xlen;
  3582. memcpy(keybuf, priv->keys[index].data, ORINOCO_MAX_KEY_SIZE);
  3583. orinoco_unlock(priv, &flags);
  3584. return 0;
  3585. }
  3586. static int orinoco_ioctl_setessid(struct net_device *dev,
  3587. struct iw_request_info *info,
  3588. struct iw_point *erq,
  3589. char *essidbuf)
  3590. {
  3591. struct orinoco_private *priv = netdev_priv(dev);
  3592. unsigned long flags;
  3593. /* Note : ESSID is ignored in Ad-Hoc demo mode, but we can set it
  3594. * anyway... - Jean II */
  3595. /* Hum... Should not use Wireless Extension constant (may change),
  3596. * should use our own... - Jean II */
  3597. if (erq->length > IW_ESSID_MAX_SIZE)
  3598. return -E2BIG;
  3599. if (orinoco_lock(priv, &flags) != 0)
  3600. return -EBUSY;
  3601. /* NULL the string (for NULL termination & ESSID = ANY) - Jean II */
  3602. memset(priv->desired_essid, 0, sizeof(priv->desired_essid));
  3603. /* If not ANY, get the new ESSID */
  3604. if (erq->flags) {
  3605. memcpy(priv->desired_essid, essidbuf, erq->length);
  3606. }
  3607. orinoco_unlock(priv, &flags);
  3608. return -EINPROGRESS; /* Call commit handler */
  3609. }
  3610. static int orinoco_ioctl_getessid(struct net_device *dev,
  3611. struct iw_request_info *info,
  3612. struct iw_point *erq,
  3613. char *essidbuf)
  3614. {
  3615. struct orinoco_private *priv = netdev_priv(dev);
  3616. int active;
  3617. int err = 0;
  3618. unsigned long flags;
  3619. if (netif_running(dev)) {
  3620. err = orinoco_hw_get_essid(priv, &active, essidbuf);
  3621. if (err < 0)
  3622. return err;
  3623. erq->length = err;
  3624. } else {
  3625. if (orinoco_lock(priv, &flags) != 0)
  3626. return -EBUSY;
  3627. memcpy(essidbuf, priv->desired_essid, IW_ESSID_MAX_SIZE);
  3628. erq->length = strlen(priv->desired_essid);
  3629. orinoco_unlock(priv, &flags);
  3630. }
  3631. erq->flags = 1;
  3632. return 0;
  3633. }
  3634. static int orinoco_ioctl_setnick(struct net_device *dev,
  3635. struct iw_request_info *info,
  3636. struct iw_point *nrq,
  3637. char *nickbuf)
  3638. {
  3639. struct orinoco_private *priv = netdev_priv(dev);
  3640. unsigned long flags;
  3641. if (nrq->length > IW_ESSID_MAX_SIZE)
  3642. return -E2BIG;
  3643. if (orinoco_lock(priv, &flags) != 0)
  3644. return -EBUSY;
  3645. memset(priv->nick, 0, sizeof(priv->nick));
  3646. memcpy(priv->nick, nickbuf, nrq->length);
  3647. orinoco_unlock(priv, &flags);
  3648. return -EINPROGRESS; /* Call commit handler */
  3649. }
  3650. static int orinoco_ioctl_getnick(struct net_device *dev,
  3651. struct iw_request_info *info,
  3652. struct iw_point *nrq,
  3653. char *nickbuf)
  3654. {
  3655. struct orinoco_private *priv = netdev_priv(dev);
  3656. unsigned long flags;
  3657. if (orinoco_lock(priv, &flags) != 0)
  3658. return -EBUSY;
  3659. memcpy(nickbuf, priv->nick, IW_ESSID_MAX_SIZE);
  3660. orinoco_unlock(priv, &flags);
  3661. nrq->length = strlen(priv->nick);
  3662. return 0;
  3663. }
  3664. static int orinoco_ioctl_setfreq(struct net_device *dev,
  3665. struct iw_request_info *info,
  3666. struct iw_freq *frq,
  3667. char *extra)
  3668. {
  3669. struct orinoco_private *priv = netdev_priv(dev);
  3670. int chan = -1;
  3671. unsigned long flags;
  3672. int err = -EINPROGRESS; /* Call commit handler */
  3673. /* In infrastructure mode the AP sets the channel */
  3674. if (priv->iw_mode == IW_MODE_INFRA)
  3675. return -EBUSY;
  3676. if ( (frq->e == 0) && (frq->m <= 1000) ) {
  3677. /* Setting by channel number */
  3678. chan = frq->m;
  3679. } else {
  3680. /* Setting by frequency - search the table */
  3681. int mult = 1;
  3682. int i;
  3683. for (i = 0; i < (6 - frq->e); i++)
  3684. mult *= 10;
  3685. for (i = 0; i < NUM_CHANNELS; i++)
  3686. if (frq->m == (channel_frequency[i] * mult))
  3687. chan = i+1;
  3688. }
  3689. if ( (chan < 1) || (chan > NUM_CHANNELS) ||
  3690. ! (priv->channel_mask & (1 << (chan-1)) ) )
  3691. return -EINVAL;
  3692. if (orinoco_lock(priv, &flags) != 0)
  3693. return -EBUSY;
  3694. priv->channel = chan;
  3695. if (priv->iw_mode == IW_MODE_MONITOR) {
  3696. /* Fast channel change - no commit if successful */
  3697. hermes_t *hw = &priv->hw;
  3698. err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
  3699. HERMES_TEST_SET_CHANNEL,
  3700. chan, NULL);
  3701. }
  3702. orinoco_unlock(priv, &flags);
  3703. return err;
  3704. }
  3705. static int orinoco_ioctl_getfreq(struct net_device *dev,
  3706. struct iw_request_info *info,
  3707. struct iw_freq *frq,
  3708. char *extra)
  3709. {
  3710. struct orinoco_private *priv = netdev_priv(dev);
  3711. int tmp;
  3712. /* Locking done in there */
  3713. tmp = orinoco_hw_get_freq(priv);
  3714. if (tmp < 0) {
  3715. return tmp;
  3716. }
  3717. frq->m = tmp;
  3718. frq->e = 1;
  3719. return 0;
  3720. }
  3721. static int orinoco_ioctl_getsens(struct net_device *dev,
  3722. struct iw_request_info *info,
  3723. struct iw_param *srq,
  3724. char *extra)
  3725. {
  3726. struct orinoco_private *priv = netdev_priv(dev);
  3727. hermes_t *hw = &priv->hw;
  3728. u16 val;
  3729. int err;
  3730. unsigned long flags;
  3731. if (!priv->has_sensitivity)
  3732. return -EOPNOTSUPP;
  3733. if (orinoco_lock(priv, &flags) != 0)
  3734. return -EBUSY;
  3735. err = hermes_read_wordrec(hw, USER_BAP,
  3736. HERMES_RID_CNFSYSTEMSCALE, &val);
  3737. orinoco_unlock(priv, &flags);
  3738. if (err)
  3739. return err;
  3740. srq->value = val;
  3741. srq->fixed = 0; /* auto */
  3742. return 0;
  3743. }
  3744. static int orinoco_ioctl_setsens(struct net_device *dev,
  3745. struct iw_request_info *info,
  3746. struct iw_param *srq,
  3747. char *extra)
  3748. {
  3749. struct orinoco_private *priv = netdev_priv(dev);
  3750. int val = srq->value;
  3751. unsigned long flags;
  3752. if (!priv->has_sensitivity)
  3753. return -EOPNOTSUPP;
  3754. if ((val < 1) || (val > 3))
  3755. return -EINVAL;
  3756. if (orinoco_lock(priv, &flags) != 0)
  3757. return -EBUSY;
  3758. priv->ap_density = val;
  3759. orinoco_unlock(priv, &flags);
  3760. return -EINPROGRESS; /* Call commit handler */
  3761. }
  3762. static int orinoco_ioctl_setrts(struct net_device *dev,
  3763. struct iw_request_info *info,
  3764. struct iw_param *rrq,
  3765. char *extra)
  3766. {
  3767. struct orinoco_private *priv = netdev_priv(dev);
  3768. int val = rrq->value;
  3769. unsigned long flags;
  3770. if (rrq->disabled)
  3771. val = 2347;
  3772. if ( (val < 0) || (val > 2347) )
  3773. return -EINVAL;
  3774. if (orinoco_lock(priv, &flags) != 0)
  3775. return -EBUSY;
  3776. priv->rts_thresh = val;
  3777. orinoco_unlock(priv, &flags);
  3778. return -EINPROGRESS; /* Call commit handler */
  3779. }
  3780. static int orinoco_ioctl_getrts(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. rrq->value = priv->rts_thresh;
  3787. rrq->disabled = (rrq->value == 2347);
  3788. rrq->fixed = 1;
  3789. return 0;
  3790. }
  3791. static int orinoco_ioctl_setfrag(struct net_device *dev,
  3792. struct iw_request_info *info,
  3793. struct iw_param *frq,
  3794. char *extra)
  3795. {
  3796. struct orinoco_private *priv = netdev_priv(dev);
  3797. int err = -EINPROGRESS; /* Call commit handler */
  3798. unsigned long flags;
  3799. if (orinoco_lock(priv, &flags) != 0)
  3800. return -EBUSY;
  3801. if (priv->has_mwo) {
  3802. if (frq->disabled)
  3803. priv->mwo_robust = 0;
  3804. else {
  3805. if (frq->fixed)
  3806. printk(KERN_WARNING "%s: Fixed fragmentation is "
  3807. "not supported on this firmware. "
  3808. "Using MWO robust instead.\n", dev->name);
  3809. priv->mwo_robust = 1;
  3810. }
  3811. } else {
  3812. if (frq->disabled)
  3813. priv->frag_thresh = 2346;
  3814. else {
  3815. if ( (frq->value < 256) || (frq->value > 2346) )
  3816. err = -EINVAL;
  3817. else
  3818. priv->frag_thresh = frq->value & ~0x1; /* must be even */
  3819. }
  3820. }
  3821. orinoco_unlock(priv, &flags);
  3822. return err;
  3823. }
  3824. static int orinoco_ioctl_getfrag(struct net_device *dev,
  3825. struct iw_request_info *info,
  3826. struct iw_param *frq,
  3827. char *extra)
  3828. {
  3829. struct orinoco_private *priv = netdev_priv(dev);
  3830. hermes_t *hw = &priv->hw;
  3831. int err;
  3832. u16 val;
  3833. unsigned long flags;
  3834. if (orinoco_lock(priv, &flags) != 0)
  3835. return -EBUSY;
  3836. if (priv->has_mwo) {
  3837. err = hermes_read_wordrec(hw, USER_BAP,
  3838. HERMES_RID_CNFMWOROBUST_AGERE,
  3839. &val);
  3840. if (err)
  3841. val = 0;
  3842. frq->value = val ? 2347 : 0;
  3843. frq->disabled = ! val;
  3844. frq->fixed = 0;
  3845. } else {
  3846. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
  3847. &val);
  3848. if (err)
  3849. val = 0;
  3850. frq->value = val;
  3851. frq->disabled = (val >= 2346);
  3852. frq->fixed = 1;
  3853. }
  3854. orinoco_unlock(priv, &flags);
  3855. return err;
  3856. }
  3857. static int orinoco_ioctl_setrate(struct net_device *dev,
  3858. struct iw_request_info *info,
  3859. struct iw_param *rrq,
  3860. char *extra)
  3861. {
  3862. struct orinoco_private *priv = netdev_priv(dev);
  3863. int ratemode = -1;
  3864. int bitrate; /* 100s of kilobits */
  3865. int i;
  3866. unsigned long flags;
  3867. /* As the user space doesn't know our highest rate, it uses -1
  3868. * to ask us to set the highest rate. Test it using "iwconfig
  3869. * ethX rate auto" - Jean II */
  3870. if (rrq->value == -1)
  3871. bitrate = 110;
  3872. else {
  3873. if (rrq->value % 100000)
  3874. return -EINVAL;
  3875. bitrate = rrq->value / 100000;
  3876. }
  3877. if ( (bitrate != 10) && (bitrate != 20) &&
  3878. (bitrate != 55) && (bitrate != 110) )
  3879. return -EINVAL;
  3880. for (i = 0; i < BITRATE_TABLE_SIZE; i++)
  3881. if ( (bitrate_table[i].bitrate == bitrate) &&
  3882. (bitrate_table[i].automatic == ! rrq->fixed) ) {
  3883. ratemode = i;
  3884. break;
  3885. }
  3886. if (ratemode == -1)
  3887. return -EINVAL;
  3888. if (orinoco_lock(priv, &flags) != 0)
  3889. return -EBUSY;
  3890. priv->bitratemode = ratemode;
  3891. orinoco_unlock(priv, &flags);
  3892. return -EINPROGRESS;
  3893. }
  3894. static int orinoco_ioctl_getrate(struct net_device *dev,
  3895. struct iw_request_info *info,
  3896. struct iw_param *rrq,
  3897. char *extra)
  3898. {
  3899. struct orinoco_private *priv = netdev_priv(dev);
  3900. hermes_t *hw = &priv->hw;
  3901. int err = 0;
  3902. int ratemode;
  3903. int i;
  3904. u16 val;
  3905. unsigned long flags;
  3906. if (orinoco_lock(priv, &flags) != 0)
  3907. return -EBUSY;
  3908. ratemode = priv->bitratemode;
  3909. BUG_ON((ratemode < 0) || (ratemode >= BITRATE_TABLE_SIZE));
  3910. rrq->value = bitrate_table[ratemode].bitrate * 100000;
  3911. rrq->fixed = ! bitrate_table[ratemode].automatic;
  3912. rrq->disabled = 0;
  3913. /* If the interface is running we try to find more about the
  3914. current mode */
  3915. if (netif_running(dev)) {
  3916. err = hermes_read_wordrec(hw, USER_BAP,
  3917. HERMES_RID_CURRENTTXRATE, &val);
  3918. if (err)
  3919. goto out;
  3920. switch (priv->firmware_type) {
  3921. case FIRMWARE_TYPE_AGERE: /* Lucent style rate */
  3922. /* Note : in Lucent firmware, the return value of
  3923. * HERMES_RID_CURRENTTXRATE is the bitrate in Mb/s,
  3924. * and therefore is totally different from the
  3925. * encoding of HERMES_RID_CNFTXRATECONTROL.
  3926. * Don't forget that 6Mb/s is really 5.5Mb/s */
  3927. if (val == 6)
  3928. rrq->value = 5500000;
  3929. else
  3930. rrq->value = val * 1000000;
  3931. break;
  3932. case FIRMWARE_TYPE_INTERSIL: /* Intersil style rate */
  3933. case FIRMWARE_TYPE_SYMBOL: /* Symbol style rate */
  3934. for (i = 0; i < BITRATE_TABLE_SIZE; i++)
  3935. if (bitrate_table[i].intersil_txratectrl == val) {
  3936. ratemode = i;
  3937. break;
  3938. }
  3939. if (i >= BITRATE_TABLE_SIZE)
  3940. printk(KERN_INFO "%s: Unable to determine current bitrate (0x%04hx)\n",
  3941. dev->name, val);
  3942. rrq->value = bitrate_table[ratemode].bitrate * 100000;
  3943. break;
  3944. default:
  3945. BUG();
  3946. }
  3947. }
  3948. out:
  3949. orinoco_unlock(priv, &flags);
  3950. return err;
  3951. }
  3952. static int orinoco_ioctl_setpower(struct net_device *dev,
  3953. struct iw_request_info *info,
  3954. struct iw_param *prq,
  3955. char *extra)
  3956. {
  3957. struct orinoco_private *priv = netdev_priv(dev);
  3958. int err = -EINPROGRESS; /* Call commit handler */
  3959. unsigned long flags;
  3960. if (orinoco_lock(priv, &flags) != 0)
  3961. return -EBUSY;
  3962. if (prq->disabled) {
  3963. priv->pm_on = 0;
  3964. } else {
  3965. switch (prq->flags & IW_POWER_MODE) {
  3966. case IW_POWER_UNICAST_R:
  3967. priv->pm_mcast = 0;
  3968. priv->pm_on = 1;
  3969. break;
  3970. case IW_POWER_ALL_R:
  3971. priv->pm_mcast = 1;
  3972. priv->pm_on = 1;
  3973. break;
  3974. case IW_POWER_ON:
  3975. /* No flags : but we may have a value - Jean II */
  3976. break;
  3977. default:
  3978. err = -EINVAL;
  3979. goto out;
  3980. }
  3981. if (prq->flags & IW_POWER_TIMEOUT) {
  3982. priv->pm_on = 1;
  3983. priv->pm_timeout = prq->value / 1000;
  3984. }
  3985. if (prq->flags & IW_POWER_PERIOD) {
  3986. priv->pm_on = 1;
  3987. priv->pm_period = prq->value / 1000;
  3988. }
  3989. /* It's valid to not have a value if we are just toggling
  3990. * the flags... Jean II */
  3991. if(!priv->pm_on) {
  3992. err = -EINVAL;
  3993. goto out;
  3994. }
  3995. }
  3996. out:
  3997. orinoco_unlock(priv, &flags);
  3998. return err;
  3999. }
  4000. static int orinoco_ioctl_getpower(struct net_device *dev,
  4001. struct iw_request_info *info,
  4002. struct iw_param *prq,
  4003. char *extra)
  4004. {
  4005. struct orinoco_private *priv = netdev_priv(dev);
  4006. hermes_t *hw = &priv->hw;
  4007. int err = 0;
  4008. u16 enable, period, timeout, mcast;
  4009. unsigned long flags;
  4010. if (orinoco_lock(priv, &flags) != 0)
  4011. return -EBUSY;
  4012. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFPMENABLED, &enable);
  4013. if (err)
  4014. goto out;
  4015. err = hermes_read_wordrec(hw, USER_BAP,
  4016. HERMES_RID_CNFMAXSLEEPDURATION, &period);
  4017. if (err)
  4018. goto out;
  4019. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFPMHOLDOVERDURATION, &timeout);
  4020. if (err)
  4021. goto out;
  4022. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFMULTICASTRECEIVE, &mcast);
  4023. if (err)
  4024. goto out;
  4025. prq->disabled = !enable;
  4026. /* Note : by default, display the period */
  4027. if ((prq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
  4028. prq->flags = IW_POWER_TIMEOUT;
  4029. prq->value = timeout * 1000;
  4030. } else {
  4031. prq->flags = IW_POWER_PERIOD;
  4032. prq->value = period * 1000;
  4033. }
  4034. if (mcast)
  4035. prq->flags |= IW_POWER_ALL_R;
  4036. else
  4037. prq->flags |= IW_POWER_UNICAST_R;
  4038. out:
  4039. orinoco_unlock(priv, &flags);
  4040. return err;
  4041. }
  4042. static int orinoco_ioctl_set_encodeext(struct net_device *dev,
  4043. struct iw_request_info *info,
  4044. union iwreq_data *wrqu,
  4045. char *extra)
  4046. {
  4047. struct orinoco_private *priv = netdev_priv(dev);
  4048. struct iw_point *encoding = &wrqu->encoding;
  4049. struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
  4050. int idx, alg = ext->alg, set_key = 1;
  4051. unsigned long flags;
  4052. int err = -EINVAL;
  4053. u16 key_len;
  4054. if (orinoco_lock(priv, &flags) != 0)
  4055. return -EBUSY;
  4056. /* Determine and validate the key index */
  4057. idx = encoding->flags & IW_ENCODE_INDEX;
  4058. if (idx) {
  4059. if ((idx < 1) || (idx > 4))
  4060. goto out;
  4061. idx--;
  4062. } else
  4063. idx = priv->tx_key;
  4064. if (encoding->flags & IW_ENCODE_DISABLED)
  4065. alg = IW_ENCODE_ALG_NONE;
  4066. if (priv->has_wpa && (alg != IW_ENCODE_ALG_TKIP)) {
  4067. /* Clear any TKIP TX key we had */
  4068. (void) orinoco_clear_tkip_key(priv, priv->tx_key);
  4069. }
  4070. if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) {
  4071. priv->tx_key = idx;
  4072. set_key = ((alg == IW_ENCODE_ALG_TKIP) ||
  4073. (ext->key_len > 0)) ? 1 : 0;
  4074. }
  4075. if (set_key) {
  4076. /* Set the requested key first */
  4077. switch (alg) {
  4078. case IW_ENCODE_ALG_NONE:
  4079. priv->encode_alg = alg;
  4080. priv->keys[idx].len = 0;
  4081. break;
  4082. case IW_ENCODE_ALG_WEP:
  4083. if (ext->key_len > SMALL_KEY_SIZE)
  4084. key_len = LARGE_KEY_SIZE;
  4085. else if (ext->key_len > 0)
  4086. key_len = SMALL_KEY_SIZE;
  4087. else
  4088. goto out;
  4089. priv->encode_alg = alg;
  4090. priv->keys[idx].len = cpu_to_le16(key_len);
  4091. key_len = min(ext->key_len, key_len);
  4092. memset(priv->keys[idx].data, 0, ORINOCO_MAX_KEY_SIZE);
  4093. memcpy(priv->keys[idx].data, ext->key, key_len);
  4094. break;
  4095. case IW_ENCODE_ALG_TKIP:
  4096. {
  4097. hermes_t *hw = &priv->hw;
  4098. u8 *tkip_iv = NULL;
  4099. if (!priv->has_wpa ||
  4100. (ext->key_len > sizeof(priv->tkip_key[0])))
  4101. goto out;
  4102. priv->encode_alg = alg;
  4103. memset(&priv->tkip_key[idx], 0,
  4104. sizeof(priv->tkip_key[idx]));
  4105. memcpy(&priv->tkip_key[idx], ext->key, ext->key_len);
  4106. if (ext->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID)
  4107. tkip_iv = &ext->rx_seq[0];
  4108. err = __orinoco_hw_set_tkip_key(hw, idx,
  4109. ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY,
  4110. (u8 *) &priv->tkip_key[idx],
  4111. tkip_iv, NULL);
  4112. if (err)
  4113. printk(KERN_ERR "%s: Error %d setting TKIP key"
  4114. "\n", dev->name, err);
  4115. goto out;
  4116. }
  4117. default:
  4118. goto out;
  4119. }
  4120. }
  4121. err = -EINPROGRESS;
  4122. out:
  4123. orinoco_unlock(priv, &flags);
  4124. return err;
  4125. }
  4126. static int orinoco_ioctl_get_encodeext(struct net_device *dev,
  4127. struct iw_request_info *info,
  4128. union iwreq_data *wrqu,
  4129. char *extra)
  4130. {
  4131. struct orinoco_private *priv = netdev_priv(dev);
  4132. struct iw_point *encoding = &wrqu->encoding;
  4133. struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
  4134. int idx, max_key_len;
  4135. unsigned long flags;
  4136. int err;
  4137. if (orinoco_lock(priv, &flags) != 0)
  4138. return -EBUSY;
  4139. err = -EINVAL;
  4140. max_key_len = encoding->length - sizeof(*ext);
  4141. if (max_key_len < 0)
  4142. goto out;
  4143. idx = encoding->flags & IW_ENCODE_INDEX;
  4144. if (idx) {
  4145. if ((idx < 1) || (idx > 4))
  4146. goto out;
  4147. idx--;
  4148. } else
  4149. idx = priv->tx_key;
  4150. encoding->flags = idx + 1;
  4151. memset(ext, 0, sizeof(*ext));
  4152. ext->alg = priv->encode_alg;
  4153. switch (priv->encode_alg) {
  4154. case IW_ENCODE_ALG_NONE:
  4155. ext->key_len = 0;
  4156. encoding->flags |= IW_ENCODE_DISABLED;
  4157. break;
  4158. case IW_ENCODE_ALG_WEP:
  4159. ext->key_len = min_t(u16, le16_to_cpu(priv->keys[idx].len),
  4160. max_key_len);
  4161. memcpy(ext->key, priv->keys[idx].data, ext->key_len);
  4162. encoding->flags |= IW_ENCODE_ENABLED;
  4163. break;
  4164. case IW_ENCODE_ALG_TKIP:
  4165. ext->key_len = min_t(u16, sizeof(struct orinoco_tkip_key),
  4166. max_key_len);
  4167. memcpy(ext->key, &priv->tkip_key[idx], ext->key_len);
  4168. encoding->flags |= IW_ENCODE_ENABLED;
  4169. break;
  4170. }
  4171. err = 0;
  4172. out:
  4173. orinoco_unlock(priv, &flags);
  4174. return err;
  4175. }
  4176. static int orinoco_ioctl_set_auth(struct net_device *dev,
  4177. struct iw_request_info *info,
  4178. union iwreq_data *wrqu, char *extra)
  4179. {
  4180. struct orinoco_private *priv = netdev_priv(dev);
  4181. hermes_t *hw = &priv->hw;
  4182. struct iw_param *param = &wrqu->param;
  4183. unsigned long flags;
  4184. int ret = -EINPROGRESS;
  4185. if (orinoco_lock(priv, &flags) != 0)
  4186. return -EBUSY;
  4187. switch (param->flags & IW_AUTH_INDEX) {
  4188. case IW_AUTH_WPA_VERSION:
  4189. case IW_AUTH_CIPHER_PAIRWISE:
  4190. case IW_AUTH_CIPHER_GROUP:
  4191. case IW_AUTH_RX_UNENCRYPTED_EAPOL:
  4192. case IW_AUTH_PRIVACY_INVOKED:
  4193. case IW_AUTH_DROP_UNENCRYPTED:
  4194. /*
  4195. * orinoco does not use these parameters
  4196. */
  4197. break;
  4198. case IW_AUTH_KEY_MGMT:
  4199. /* wl_lkm implies value 2 == PSK for Hermes I
  4200. * which ties in with WEXT
  4201. * no other hints tho :(
  4202. */
  4203. priv->key_mgmt = param->value;
  4204. break;
  4205. case IW_AUTH_TKIP_COUNTERMEASURES:
  4206. /* When countermeasures are enabled, shut down the
  4207. * card; when disabled, re-enable the card. This must
  4208. * take effect immediately.
  4209. *
  4210. * TODO: Make sure that the EAPOL message is getting
  4211. * out before card disabled
  4212. */
  4213. if (param->value) {
  4214. priv->tkip_cm_active = 1;
  4215. ret = hermes_enable_port(hw, 0);
  4216. } else {
  4217. priv->tkip_cm_active = 0;
  4218. ret = hermes_disable_port(hw, 0);
  4219. }
  4220. break;
  4221. case IW_AUTH_80211_AUTH_ALG:
  4222. if (param->value & IW_AUTH_ALG_SHARED_KEY)
  4223. priv->wep_restrict = 1;
  4224. else if (param->value & IW_AUTH_ALG_OPEN_SYSTEM)
  4225. priv->wep_restrict = 0;
  4226. else
  4227. ret = -EINVAL;
  4228. break;
  4229. case IW_AUTH_WPA_ENABLED:
  4230. if (priv->has_wpa) {
  4231. priv->wpa_enabled = param->value ? 1 : 0;
  4232. } else {
  4233. if (param->value)
  4234. ret = -EOPNOTSUPP;
  4235. /* else silently accept disable of WPA */
  4236. priv->wpa_enabled = 0;
  4237. }
  4238. break;
  4239. default:
  4240. ret = -EOPNOTSUPP;
  4241. }
  4242. orinoco_unlock(priv, &flags);
  4243. return ret;
  4244. }
  4245. static int orinoco_ioctl_get_auth(struct net_device *dev,
  4246. struct iw_request_info *info,
  4247. union iwreq_data *wrqu, char *extra)
  4248. {
  4249. struct orinoco_private *priv = netdev_priv(dev);
  4250. struct iw_param *param = &wrqu->param;
  4251. unsigned long flags;
  4252. int ret = 0;
  4253. if (orinoco_lock(priv, &flags) != 0)
  4254. return -EBUSY;
  4255. switch (param->flags & IW_AUTH_INDEX) {
  4256. case IW_AUTH_KEY_MGMT:
  4257. param->value = priv->key_mgmt;
  4258. break;
  4259. case IW_AUTH_TKIP_COUNTERMEASURES:
  4260. param->value = priv->tkip_cm_active;
  4261. break;
  4262. case IW_AUTH_80211_AUTH_ALG:
  4263. if (priv->wep_restrict)
  4264. param->value = IW_AUTH_ALG_SHARED_KEY;
  4265. else
  4266. param->value = IW_AUTH_ALG_OPEN_SYSTEM;
  4267. break;
  4268. case IW_AUTH_WPA_ENABLED:
  4269. param->value = priv->wpa_enabled;
  4270. break;
  4271. default:
  4272. ret = -EOPNOTSUPP;
  4273. }
  4274. orinoco_unlock(priv, &flags);
  4275. return ret;
  4276. }
  4277. static int orinoco_ioctl_set_genie(struct net_device *dev,
  4278. struct iw_request_info *info,
  4279. union iwreq_data *wrqu, char *extra)
  4280. {
  4281. struct orinoco_private *priv = netdev_priv(dev);
  4282. u8 *buf;
  4283. unsigned long flags;
  4284. int err = 0;
  4285. /* cut off at IEEE80211_MAX_DATA_LEN */
  4286. if ((wrqu->data.length > IEEE80211_MAX_DATA_LEN) ||
  4287. (wrqu->data.length && (extra == NULL)))
  4288. return -EINVAL;
  4289. if (orinoco_lock(priv, &flags) != 0)
  4290. return -EBUSY;
  4291. if (wrqu->data.length) {
  4292. buf = kmalloc(wrqu->data.length, GFP_KERNEL);
  4293. if (buf == NULL) {
  4294. err = -ENOMEM;
  4295. goto out;
  4296. }
  4297. memcpy(buf, extra, wrqu->data.length);
  4298. kfree(priv->wpa_ie);
  4299. priv->wpa_ie = buf;
  4300. priv->wpa_ie_len = wrqu->data.length;
  4301. } else {
  4302. kfree(priv->wpa_ie);
  4303. priv->wpa_ie = NULL;
  4304. priv->wpa_ie_len = 0;
  4305. }
  4306. if (priv->wpa_ie) {
  4307. /* Looks like wl_lkm wants to check the auth alg, and
  4308. * somehow pass it to the firmware.
  4309. * Instead it just calls the key mgmt rid
  4310. * - we do this in set auth.
  4311. */
  4312. }
  4313. out:
  4314. orinoco_unlock(priv, &flags);
  4315. return err;
  4316. }
  4317. static int orinoco_ioctl_get_genie(struct net_device *dev,
  4318. struct iw_request_info *info,
  4319. union iwreq_data *wrqu, char *extra)
  4320. {
  4321. struct orinoco_private *priv = netdev_priv(dev);
  4322. unsigned long flags;
  4323. int err = 0;
  4324. if (orinoco_lock(priv, &flags) != 0)
  4325. return -EBUSY;
  4326. if ((priv->wpa_ie_len == 0) || (priv->wpa_ie == NULL)) {
  4327. wrqu->data.length = 0;
  4328. goto out;
  4329. }
  4330. if (wrqu->data.length < priv->wpa_ie_len) {
  4331. err = -E2BIG;
  4332. goto out;
  4333. }
  4334. wrqu->data.length = priv->wpa_ie_len;
  4335. memcpy(extra, priv->wpa_ie, priv->wpa_ie_len);
  4336. out:
  4337. orinoco_unlock(priv, &flags);
  4338. return err;
  4339. }
  4340. static int orinoco_ioctl_set_mlme(struct net_device *dev,
  4341. struct iw_request_info *info,
  4342. union iwreq_data *wrqu, char *extra)
  4343. {
  4344. struct orinoco_private *priv = netdev_priv(dev);
  4345. hermes_t *hw = &priv->hw;
  4346. struct iw_mlme *mlme = (struct iw_mlme *)extra;
  4347. unsigned long flags;
  4348. int ret = 0;
  4349. if (orinoco_lock(priv, &flags) != 0)
  4350. return -EBUSY;
  4351. switch (mlme->cmd) {
  4352. case IW_MLME_DEAUTH:
  4353. /* silently ignore */
  4354. break;
  4355. case IW_MLME_DISASSOC:
  4356. {
  4357. struct {
  4358. u8 addr[ETH_ALEN];
  4359. __le16 reason_code;
  4360. } __attribute__ ((packed)) buf;
  4361. memcpy(buf.addr, mlme->addr.sa_data, ETH_ALEN);
  4362. buf.reason_code = cpu_to_le16(mlme->reason_code);
  4363. ret = HERMES_WRITE_RECORD(hw, USER_BAP,
  4364. HERMES_RID_CNFDISASSOCIATE,
  4365. &buf);
  4366. break;
  4367. }
  4368. default:
  4369. ret = -EOPNOTSUPP;
  4370. }
  4371. orinoco_unlock(priv, &flags);
  4372. return ret;
  4373. }
  4374. static int orinoco_ioctl_getretry(struct net_device *dev,
  4375. struct iw_request_info *info,
  4376. struct iw_param *rrq,
  4377. char *extra)
  4378. {
  4379. struct orinoco_private *priv = netdev_priv(dev);
  4380. hermes_t *hw = &priv->hw;
  4381. int err = 0;
  4382. u16 short_limit, long_limit, lifetime;
  4383. unsigned long flags;
  4384. if (orinoco_lock(priv, &flags) != 0)
  4385. return -EBUSY;
  4386. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_SHORTRETRYLIMIT,
  4387. &short_limit);
  4388. if (err)
  4389. goto out;
  4390. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_LONGRETRYLIMIT,
  4391. &long_limit);
  4392. if (err)
  4393. goto out;
  4394. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_MAXTRANSMITLIFETIME,
  4395. &lifetime);
  4396. if (err)
  4397. goto out;
  4398. rrq->disabled = 0; /* Can't be disabled */
  4399. /* Note : by default, display the retry number */
  4400. if ((rrq->flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
  4401. rrq->flags = IW_RETRY_LIFETIME;
  4402. rrq->value = lifetime * 1000; /* ??? */
  4403. } else {
  4404. /* By default, display the min number */
  4405. if ((rrq->flags & IW_RETRY_LONG)) {
  4406. rrq->flags = IW_RETRY_LIMIT | IW_RETRY_LONG;
  4407. rrq->value = long_limit;
  4408. } else {
  4409. rrq->flags = IW_RETRY_LIMIT;
  4410. rrq->value = short_limit;
  4411. if(short_limit != long_limit)
  4412. rrq->flags |= IW_RETRY_SHORT;
  4413. }
  4414. }
  4415. out:
  4416. orinoco_unlock(priv, &flags);
  4417. return err;
  4418. }
  4419. static int orinoco_ioctl_reset(struct net_device *dev,
  4420. struct iw_request_info *info,
  4421. void *wrqu,
  4422. char *extra)
  4423. {
  4424. struct orinoco_private *priv = netdev_priv(dev);
  4425. if (! capable(CAP_NET_ADMIN))
  4426. return -EPERM;
  4427. if (info->cmd == (SIOCIWFIRSTPRIV + 0x1)) {
  4428. printk(KERN_DEBUG "%s: Forcing reset!\n", dev->name);
  4429. /* Firmware reset */
  4430. orinoco_reset(&priv->reset_work);
  4431. } else {
  4432. printk(KERN_DEBUG "%s: Force scheduling reset!\n", dev->name);
  4433. schedule_work(&priv->reset_work);
  4434. }
  4435. return 0;
  4436. }
  4437. static int orinoco_ioctl_setibssport(struct net_device *dev,
  4438. struct iw_request_info *info,
  4439. void *wrqu,
  4440. char *extra)
  4441. {
  4442. struct orinoco_private *priv = netdev_priv(dev);
  4443. int val = *( (int *) extra );
  4444. unsigned long flags;
  4445. if (orinoco_lock(priv, &flags) != 0)
  4446. return -EBUSY;
  4447. priv->ibss_port = val ;
  4448. /* Actually update the mode we are using */
  4449. set_port_type(priv);
  4450. orinoco_unlock(priv, &flags);
  4451. return -EINPROGRESS; /* Call commit handler */
  4452. }
  4453. static int orinoco_ioctl_getibssport(struct net_device *dev,
  4454. struct iw_request_info *info,
  4455. void *wrqu,
  4456. char *extra)
  4457. {
  4458. struct orinoco_private *priv = netdev_priv(dev);
  4459. int *val = (int *) extra;
  4460. *val = priv->ibss_port;
  4461. return 0;
  4462. }
  4463. static int orinoco_ioctl_setport3(struct net_device *dev,
  4464. struct iw_request_info *info,
  4465. void *wrqu,
  4466. char *extra)
  4467. {
  4468. struct orinoco_private *priv = netdev_priv(dev);
  4469. int val = *( (int *) extra );
  4470. int err = 0;
  4471. unsigned long flags;
  4472. if (orinoco_lock(priv, &flags) != 0)
  4473. return -EBUSY;
  4474. switch (val) {
  4475. case 0: /* Try to do IEEE ad-hoc mode */
  4476. if (! priv->has_ibss) {
  4477. err = -EINVAL;
  4478. break;
  4479. }
  4480. priv->prefer_port3 = 0;
  4481. break;
  4482. case 1: /* Try to do Lucent proprietary ad-hoc mode */
  4483. if (! priv->has_port3) {
  4484. err = -EINVAL;
  4485. break;
  4486. }
  4487. priv->prefer_port3 = 1;
  4488. break;
  4489. default:
  4490. err = -EINVAL;
  4491. }
  4492. if (! err) {
  4493. /* Actually update the mode we are using */
  4494. set_port_type(priv);
  4495. err = -EINPROGRESS;
  4496. }
  4497. orinoco_unlock(priv, &flags);
  4498. return err;
  4499. }
  4500. static int orinoco_ioctl_getport3(struct net_device *dev,
  4501. struct iw_request_info *info,
  4502. void *wrqu,
  4503. char *extra)
  4504. {
  4505. struct orinoco_private *priv = netdev_priv(dev);
  4506. int *val = (int *) extra;
  4507. *val = priv->prefer_port3;
  4508. return 0;
  4509. }
  4510. static int orinoco_ioctl_setpreamble(struct net_device *dev,
  4511. struct iw_request_info *info,
  4512. void *wrqu,
  4513. char *extra)
  4514. {
  4515. struct orinoco_private *priv = netdev_priv(dev);
  4516. unsigned long flags;
  4517. int val;
  4518. if (! priv->has_preamble)
  4519. return -EOPNOTSUPP;
  4520. /* 802.11b has recently defined some short preamble.
  4521. * Basically, the Phy header has been reduced in size.
  4522. * This increase performance, especially at high rates
  4523. * (the preamble is transmitted at 1Mb/s), unfortunately
  4524. * this give compatibility troubles... - Jean II */
  4525. val = *( (int *) extra );
  4526. if (orinoco_lock(priv, &flags) != 0)
  4527. return -EBUSY;
  4528. if (val)
  4529. priv->preamble = 1;
  4530. else
  4531. priv->preamble = 0;
  4532. orinoco_unlock(priv, &flags);
  4533. return -EINPROGRESS; /* Call commit handler */
  4534. }
  4535. static int orinoco_ioctl_getpreamble(struct net_device *dev,
  4536. struct iw_request_info *info,
  4537. void *wrqu,
  4538. char *extra)
  4539. {
  4540. struct orinoco_private *priv = netdev_priv(dev);
  4541. int *val = (int *) extra;
  4542. if (! priv->has_preamble)
  4543. return -EOPNOTSUPP;
  4544. *val = priv->preamble;
  4545. return 0;
  4546. }
  4547. /* ioctl interface to hermes_read_ltv()
  4548. * To use with iwpriv, pass the RID as the token argument, e.g.
  4549. * iwpriv get_rid [0xfc00]
  4550. * At least Wireless Tools 25 is required to use iwpriv.
  4551. * For Wireless Tools 25 and 26 append "dummy" are the end. */
  4552. static int orinoco_ioctl_getrid(struct net_device *dev,
  4553. struct iw_request_info *info,
  4554. struct iw_point *data,
  4555. char *extra)
  4556. {
  4557. struct orinoco_private *priv = netdev_priv(dev);
  4558. hermes_t *hw = &priv->hw;
  4559. int rid = data->flags;
  4560. u16 length;
  4561. int err;
  4562. unsigned long flags;
  4563. /* It's a "get" function, but we don't want users to access the
  4564. * WEP key and other raw firmware data */
  4565. if (! capable(CAP_NET_ADMIN))
  4566. return -EPERM;
  4567. if (rid < 0xfc00 || rid > 0xffff)
  4568. return -EINVAL;
  4569. if (orinoco_lock(priv, &flags) != 0)
  4570. return -EBUSY;
  4571. err = hermes_read_ltv(hw, USER_BAP, rid, MAX_RID_LEN, &length,
  4572. extra);
  4573. if (err)
  4574. goto out;
  4575. data->length = min_t(u16, HERMES_RECLEN_TO_BYTES(length),
  4576. MAX_RID_LEN);
  4577. out:
  4578. orinoco_unlock(priv, &flags);
  4579. return err;
  4580. }
  4581. /* Trigger a scan (look for other cells in the vicinity) */
  4582. static int orinoco_ioctl_setscan(struct net_device *dev,
  4583. struct iw_request_info *info,
  4584. struct iw_point *srq,
  4585. char *extra)
  4586. {
  4587. struct orinoco_private *priv = netdev_priv(dev);
  4588. hermes_t *hw = &priv->hw;
  4589. struct iw_scan_req *si = (struct iw_scan_req *) extra;
  4590. int err = 0;
  4591. unsigned long flags;
  4592. /* Note : you may have realised that, as this is a SET operation,
  4593. * this is privileged and therefore a normal user can't
  4594. * perform scanning.
  4595. * This is not an error, while the device perform scanning,
  4596. * traffic doesn't flow, so it's a perfect DoS...
  4597. * Jean II */
  4598. if (orinoco_lock(priv, &flags) != 0)
  4599. return -EBUSY;
  4600. /* Scanning with port 0 disabled would fail */
  4601. if (!netif_running(dev)) {
  4602. err = -ENETDOWN;
  4603. goto out;
  4604. }
  4605. /* In monitor mode, the scan results are always empty.
  4606. * Probe responses are passed to the driver as received
  4607. * frames and could be processed in software. */
  4608. if (priv->iw_mode == IW_MODE_MONITOR) {
  4609. err = -EOPNOTSUPP;
  4610. goto out;
  4611. }
  4612. /* Note : because we don't lock out the irq handler, the way
  4613. * we access scan variables in priv is critical.
  4614. * o scan_inprogress : not touched by irq handler
  4615. * o scan_mode : not touched by irq handler
  4616. * Before modifying anything on those variables, please think hard !
  4617. * Jean II */
  4618. /* Save flags */
  4619. priv->scan_mode = srq->flags;
  4620. /* Always trigger scanning, even if it's in progress.
  4621. * This way, if the info frame get lost, we will recover somewhat
  4622. * gracefully - Jean II */
  4623. if (priv->has_hostscan) {
  4624. switch (priv->firmware_type) {
  4625. case FIRMWARE_TYPE_SYMBOL:
  4626. err = hermes_write_wordrec(hw, USER_BAP,
  4627. HERMES_RID_CNFHOSTSCAN_SYMBOL,
  4628. HERMES_HOSTSCAN_SYMBOL_ONCE |
  4629. HERMES_HOSTSCAN_SYMBOL_BCAST);
  4630. break;
  4631. case FIRMWARE_TYPE_INTERSIL: {
  4632. __le16 req[3];
  4633. req[0] = cpu_to_le16(0x3fff); /* All channels */
  4634. req[1] = cpu_to_le16(0x0001); /* rate 1 Mbps */
  4635. req[2] = 0; /* Any ESSID */
  4636. err = HERMES_WRITE_RECORD(hw, USER_BAP,
  4637. HERMES_RID_CNFHOSTSCAN, &req);
  4638. }
  4639. break;
  4640. case FIRMWARE_TYPE_AGERE:
  4641. if (priv->scan_mode & IW_SCAN_THIS_ESSID) {
  4642. struct hermes_idstring idbuf;
  4643. size_t len = min(sizeof(idbuf.val),
  4644. (size_t) si->essid_len);
  4645. idbuf.len = cpu_to_le16(len);
  4646. memcpy(idbuf.val, si->essid, len);
  4647. err = hermes_write_ltv(hw, USER_BAP,
  4648. HERMES_RID_CNFSCANSSID_AGERE,
  4649. HERMES_BYTES_TO_RECLEN(len + 2),
  4650. &idbuf);
  4651. } else
  4652. err = hermes_write_wordrec(hw, USER_BAP,
  4653. HERMES_RID_CNFSCANSSID_AGERE,
  4654. 0); /* Any ESSID */
  4655. if (err)
  4656. break;
  4657. if (priv->has_ext_scan) {
  4658. /* Clear scan results at the start of
  4659. * an extended scan */
  4660. orinoco_clear_scan_results(priv,
  4661. msecs_to_jiffies(15000));
  4662. /* TODO: Is this available on older firmware?
  4663. * Can we use it to scan specific channels
  4664. * for IW_SCAN_THIS_FREQ? */
  4665. err = hermes_write_wordrec(hw, USER_BAP,
  4666. HERMES_RID_CNFSCANCHANNELS2GHZ,
  4667. 0x7FFF);
  4668. if (err)
  4669. goto out;
  4670. err = hermes_inquire(hw,
  4671. HERMES_INQ_CHANNELINFO);
  4672. } else
  4673. err = hermes_inquire(hw, HERMES_INQ_SCAN);
  4674. break;
  4675. }
  4676. } else
  4677. err = hermes_inquire(hw, HERMES_INQ_SCAN);
  4678. /* One more client */
  4679. if (! err)
  4680. priv->scan_inprogress = 1;
  4681. out:
  4682. orinoco_unlock(priv, &flags);
  4683. return err;
  4684. }
  4685. #define MAX_CUSTOM_LEN 64
  4686. /* Translate scan data returned from the card to a card independant
  4687. * format that the Wireless Tools will understand - Jean II */
  4688. static inline char *orinoco_translate_scan(struct net_device *dev,
  4689. struct iw_request_info *info,
  4690. char *current_ev,
  4691. char *end_buf,
  4692. union hermes_scan_info *bss,
  4693. unsigned long last_scanned)
  4694. {
  4695. struct orinoco_private *priv = netdev_priv(dev);
  4696. u16 capabilities;
  4697. u16 channel;
  4698. struct iw_event iwe; /* Temporary buffer */
  4699. char custom[MAX_CUSTOM_LEN];
  4700. memset(&iwe, 0, sizeof(iwe));
  4701. /* First entry *MUST* be the AP MAC address */
  4702. iwe.cmd = SIOCGIWAP;
  4703. iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
  4704. memcpy(iwe.u.ap_addr.sa_data, bss->a.bssid, ETH_ALEN);
  4705. current_ev = iwe_stream_add_event(info, current_ev, end_buf,
  4706. &iwe, IW_EV_ADDR_LEN);
  4707. /* Other entries will be displayed in the order we give them */
  4708. /* Add the ESSID */
  4709. iwe.u.data.length = le16_to_cpu(bss->a.essid_len);
  4710. if (iwe.u.data.length > 32)
  4711. iwe.u.data.length = 32;
  4712. iwe.cmd = SIOCGIWESSID;
  4713. iwe.u.data.flags = 1;
  4714. current_ev = iwe_stream_add_point(info, current_ev, end_buf,
  4715. &iwe, bss->a.essid);
  4716. /* Add mode */
  4717. iwe.cmd = SIOCGIWMODE;
  4718. capabilities = le16_to_cpu(bss->a.capabilities);
  4719. if (capabilities & (WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_IBSS)) {
  4720. if (capabilities & WLAN_CAPABILITY_ESS)
  4721. iwe.u.mode = IW_MODE_MASTER;
  4722. else
  4723. iwe.u.mode = IW_MODE_ADHOC;
  4724. current_ev = iwe_stream_add_event(info, current_ev, end_buf,
  4725. &iwe, IW_EV_UINT_LEN);
  4726. }
  4727. channel = bss->s.channel;
  4728. if ((channel >= 1) && (channel <= NUM_CHANNELS)) {
  4729. /* Add channel and frequency */
  4730. iwe.cmd = SIOCGIWFREQ;
  4731. iwe.u.freq.m = channel;
  4732. iwe.u.freq.e = 0;
  4733. current_ev = iwe_stream_add_event(info, current_ev, end_buf,
  4734. &iwe, IW_EV_FREQ_LEN);
  4735. iwe.u.freq.m = channel_frequency[channel-1] * 100000;
  4736. iwe.u.freq.e = 1;
  4737. current_ev = iwe_stream_add_event(info, current_ev, end_buf,
  4738. &iwe, IW_EV_FREQ_LEN);
  4739. }
  4740. /* Add quality statistics. level and noise in dB. No link quality */
  4741. iwe.cmd = IWEVQUAL;
  4742. iwe.u.qual.updated = IW_QUAL_DBM | IW_QUAL_QUAL_INVALID;
  4743. iwe.u.qual.level = (__u8) le16_to_cpu(bss->a.level) - 0x95;
  4744. iwe.u.qual.noise = (__u8) le16_to_cpu(bss->a.noise) - 0x95;
  4745. /* Wireless tools prior to 27.pre22 will show link quality
  4746. * anyway, so we provide a reasonable value. */
  4747. if (iwe.u.qual.level > iwe.u.qual.noise)
  4748. iwe.u.qual.qual = iwe.u.qual.level - iwe.u.qual.noise;
  4749. else
  4750. iwe.u.qual.qual = 0;
  4751. current_ev = iwe_stream_add_event(info, current_ev, end_buf,
  4752. &iwe, IW_EV_QUAL_LEN);
  4753. /* Add encryption capability */
  4754. iwe.cmd = SIOCGIWENCODE;
  4755. if (capabilities & WLAN_CAPABILITY_PRIVACY)
  4756. iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
  4757. else
  4758. iwe.u.data.flags = IW_ENCODE_DISABLED;
  4759. iwe.u.data.length = 0;
  4760. current_ev = iwe_stream_add_point(info, current_ev, end_buf,
  4761. &iwe, NULL);
  4762. /* Bit rate is not available in Lucent/Agere firmwares */
  4763. if (priv->firmware_type != FIRMWARE_TYPE_AGERE) {
  4764. char *current_val = current_ev + iwe_stream_lcp_len(info);
  4765. int i;
  4766. int step;
  4767. if (priv->firmware_type == FIRMWARE_TYPE_SYMBOL)
  4768. step = 2;
  4769. else
  4770. step = 1;
  4771. iwe.cmd = SIOCGIWRATE;
  4772. /* Those two flags are ignored... */
  4773. iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
  4774. /* Max 10 values */
  4775. for (i = 0; i < 10; i += step) {
  4776. /* NULL terminated */
  4777. if (bss->p.rates[i] == 0x0)
  4778. break;
  4779. /* Bit rate given in 500 kb/s units (+ 0x80) */
  4780. iwe.u.bitrate.value =
  4781. ((bss->p.rates[i] & 0x7f) * 500000);
  4782. current_val = iwe_stream_add_value(info, current_ev,
  4783. current_val,
  4784. end_buf, &iwe,
  4785. IW_EV_PARAM_LEN);
  4786. }
  4787. /* Check if we added any event */
  4788. if ((current_val - current_ev) > iwe_stream_lcp_len(info))
  4789. current_ev = current_val;
  4790. }
  4791. /* Beacon interval */
  4792. iwe.cmd = IWEVCUSTOM;
  4793. iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN,
  4794. "bcn_int=%d",
  4795. le16_to_cpu(bss->a.beacon_interv));
  4796. if (iwe.u.data.length)
  4797. current_ev = iwe_stream_add_point(info, current_ev, end_buf,
  4798. &iwe, custom);
  4799. /* Capabilites */
  4800. iwe.cmd = IWEVCUSTOM;
  4801. iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN,
  4802. "capab=0x%04x",
  4803. capabilities);
  4804. if (iwe.u.data.length)
  4805. current_ev = iwe_stream_add_point(info, current_ev, end_buf,
  4806. &iwe, custom);
  4807. /* Add EXTRA: Age to display seconds since last beacon/probe response
  4808. * for given network. */
  4809. iwe.cmd = IWEVCUSTOM;
  4810. iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN,
  4811. " Last beacon: %dms ago",
  4812. jiffies_to_msecs(jiffies - last_scanned));
  4813. if (iwe.u.data.length)
  4814. current_ev = iwe_stream_add_point(info, current_ev, end_buf,
  4815. &iwe, custom);
  4816. return current_ev;
  4817. }
  4818. static inline char *orinoco_translate_ext_scan(struct net_device *dev,
  4819. struct iw_request_info *info,
  4820. char *current_ev,
  4821. char *end_buf,
  4822. struct agere_ext_scan_info *bss,
  4823. unsigned long last_scanned)
  4824. {
  4825. u16 capabilities;
  4826. u16 channel;
  4827. struct iw_event iwe; /* Temporary buffer */
  4828. char custom[MAX_CUSTOM_LEN];
  4829. u8 *ie;
  4830. memset(&iwe, 0, sizeof(iwe));
  4831. /* First entry *MUST* be the AP MAC address */
  4832. iwe.cmd = SIOCGIWAP;
  4833. iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
  4834. memcpy(iwe.u.ap_addr.sa_data, bss->bssid, ETH_ALEN);
  4835. current_ev = iwe_stream_add_event(info, current_ev, end_buf,
  4836. &iwe, IW_EV_ADDR_LEN);
  4837. /* Other entries will be displayed in the order we give them */
  4838. /* Add the ESSID */
  4839. ie = bss->data;
  4840. iwe.u.data.length = ie[1];
  4841. if (iwe.u.data.length) {
  4842. if (iwe.u.data.length > 32)
  4843. iwe.u.data.length = 32;
  4844. iwe.cmd = SIOCGIWESSID;
  4845. iwe.u.data.flags = 1;
  4846. current_ev = iwe_stream_add_point(info, current_ev, end_buf,
  4847. &iwe, &ie[2]);
  4848. }
  4849. /* Add mode */
  4850. capabilities = le16_to_cpu(bss->capabilities);
  4851. if (capabilities & (WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_IBSS)) {
  4852. iwe.cmd = SIOCGIWMODE;
  4853. if (capabilities & WLAN_CAPABILITY_ESS)
  4854. iwe.u.mode = IW_MODE_MASTER;
  4855. else
  4856. iwe.u.mode = IW_MODE_ADHOC;
  4857. current_ev = iwe_stream_add_event(info, current_ev, end_buf,
  4858. &iwe, IW_EV_UINT_LEN);
  4859. }
  4860. ie = orinoco_get_ie(bss->data, sizeof(bss->data), WLAN_EID_DS_PARAMS);
  4861. channel = ie ? ie[2] : 0;
  4862. if ((channel >= 1) && (channel <= NUM_CHANNELS)) {
  4863. /* Add channel and frequency */
  4864. iwe.cmd = SIOCGIWFREQ;
  4865. iwe.u.freq.m = channel;
  4866. iwe.u.freq.e = 0;
  4867. current_ev = iwe_stream_add_event(info, current_ev, end_buf,
  4868. &iwe, IW_EV_FREQ_LEN);
  4869. iwe.u.freq.m = channel_frequency[channel-1] * 100000;
  4870. iwe.u.freq.e = 1;
  4871. current_ev = iwe_stream_add_event(info, current_ev, end_buf,
  4872. &iwe, IW_EV_FREQ_LEN);
  4873. }
  4874. /* Add quality statistics. level and noise in dB. No link quality */
  4875. iwe.cmd = IWEVQUAL;
  4876. iwe.u.qual.updated = IW_QUAL_DBM | IW_QUAL_QUAL_INVALID;
  4877. iwe.u.qual.level = bss->level - 0x95;
  4878. iwe.u.qual.noise = bss->noise - 0x95;
  4879. /* Wireless tools prior to 27.pre22 will show link quality
  4880. * anyway, so we provide a reasonable value. */
  4881. if (iwe.u.qual.level > iwe.u.qual.noise)
  4882. iwe.u.qual.qual = iwe.u.qual.level - iwe.u.qual.noise;
  4883. else
  4884. iwe.u.qual.qual = 0;
  4885. current_ev = iwe_stream_add_event(info, current_ev, end_buf,
  4886. &iwe, IW_EV_QUAL_LEN);
  4887. /* Add encryption capability */
  4888. iwe.cmd = SIOCGIWENCODE;
  4889. if (capabilities & WLAN_CAPABILITY_PRIVACY)
  4890. iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
  4891. else
  4892. iwe.u.data.flags = IW_ENCODE_DISABLED;
  4893. iwe.u.data.length = 0;
  4894. current_ev = iwe_stream_add_point(info, current_ev, end_buf,
  4895. &iwe, NULL);
  4896. /* WPA IE */
  4897. ie = orinoco_get_wpa_ie(bss->data, sizeof(bss->data));
  4898. if (ie) {
  4899. iwe.cmd = IWEVGENIE;
  4900. iwe.u.data.length = ie[1] + 2;
  4901. current_ev = iwe_stream_add_point(info, current_ev, end_buf,
  4902. &iwe, ie);
  4903. }
  4904. /* RSN IE */
  4905. ie = orinoco_get_ie(bss->data, sizeof(bss->data), WLAN_EID_RSN);
  4906. if (ie) {
  4907. iwe.cmd = IWEVGENIE;
  4908. iwe.u.data.length = ie[1] + 2;
  4909. current_ev = iwe_stream_add_point(info, current_ev, end_buf,
  4910. &iwe, ie);
  4911. }
  4912. ie = orinoco_get_ie(bss->data, sizeof(bss->data), WLAN_EID_SUPP_RATES);
  4913. if (ie) {
  4914. char *p = current_ev + iwe_stream_lcp_len(info);
  4915. int i;
  4916. iwe.cmd = SIOCGIWRATE;
  4917. /* Those two flags are ignored... */
  4918. iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
  4919. for (i = 2; i < (ie[1] + 2); i++) {
  4920. iwe.u.bitrate.value = ((ie[i] & 0x7F) * 500000);
  4921. p = iwe_stream_add_value(info, current_ev, p, end_buf,
  4922. &iwe, IW_EV_PARAM_LEN);
  4923. }
  4924. /* Check if we added any event */
  4925. if (p > (current_ev + iwe_stream_lcp_len(info)))
  4926. current_ev = p;
  4927. }
  4928. /* Timestamp */
  4929. iwe.cmd = IWEVCUSTOM;
  4930. iwe.u.data.length =
  4931. snprintf(custom, MAX_CUSTOM_LEN, "tsf=%016llx",
  4932. (unsigned long long) le64_to_cpu(bss->timestamp));
  4933. if (iwe.u.data.length)
  4934. current_ev = iwe_stream_add_point(info, current_ev, end_buf,
  4935. &iwe, custom);
  4936. /* Beacon interval */
  4937. iwe.cmd = IWEVCUSTOM;
  4938. iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN,
  4939. "bcn_int=%d",
  4940. le16_to_cpu(bss->beacon_interval));
  4941. if (iwe.u.data.length)
  4942. current_ev = iwe_stream_add_point(info, current_ev, end_buf,
  4943. &iwe, custom);
  4944. /* Capabilites */
  4945. iwe.cmd = IWEVCUSTOM;
  4946. iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN,
  4947. "capab=0x%04x",
  4948. capabilities);
  4949. if (iwe.u.data.length)
  4950. current_ev = iwe_stream_add_point(info, current_ev, end_buf,
  4951. &iwe, custom);
  4952. /* Add EXTRA: Age to display seconds since last beacon/probe response
  4953. * for given network. */
  4954. iwe.cmd = IWEVCUSTOM;
  4955. iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN,
  4956. " Last beacon: %dms ago",
  4957. jiffies_to_msecs(jiffies - last_scanned));
  4958. if (iwe.u.data.length)
  4959. current_ev = iwe_stream_add_point(info, current_ev, end_buf,
  4960. &iwe, custom);
  4961. return current_ev;
  4962. }
  4963. /* Return results of a scan */
  4964. static int orinoco_ioctl_getscan(struct net_device *dev,
  4965. struct iw_request_info *info,
  4966. struct iw_point *srq,
  4967. char *extra)
  4968. {
  4969. struct orinoco_private *priv = netdev_priv(dev);
  4970. int err = 0;
  4971. unsigned long flags;
  4972. char *current_ev = extra;
  4973. if (orinoco_lock(priv, &flags) != 0)
  4974. return -EBUSY;
  4975. if (priv->scan_inprogress) {
  4976. /* Important note : we don't want to block the caller
  4977. * until results are ready for various reasons.
  4978. * First, managing wait queues is complex and racy.
  4979. * Second, we grab some rtnetlink lock before comming
  4980. * here (in dev_ioctl()).
  4981. * Third, we generate an Wireless Event, so the
  4982. * caller can wait itself on that - Jean II */
  4983. err = -EAGAIN;
  4984. goto out;
  4985. }
  4986. if (priv->has_ext_scan) {
  4987. struct xbss_element *bss;
  4988. list_for_each_entry(bss, &priv->bss_list, list) {
  4989. /* Translate this entry to WE format */
  4990. current_ev =
  4991. orinoco_translate_ext_scan(dev, info,
  4992. current_ev,
  4993. extra + srq->length,
  4994. &bss->bss,
  4995. bss->last_scanned);
  4996. /* Check if there is space for one more entry */
  4997. if ((extra + srq->length - current_ev)
  4998. <= IW_EV_ADDR_LEN) {
  4999. /* Ask user space to try again with a
  5000. * bigger buffer */
  5001. err = -E2BIG;
  5002. goto out;
  5003. }
  5004. }
  5005. } else {
  5006. struct bss_element *bss;
  5007. list_for_each_entry(bss, &priv->bss_list, list) {
  5008. /* Translate this entry to WE format */
  5009. current_ev = orinoco_translate_scan(dev, info,
  5010. current_ev,
  5011. extra + srq->length,
  5012. &bss->bss,
  5013. bss->last_scanned);
  5014. /* Check if there is space for one more entry */
  5015. if ((extra + srq->length - current_ev)
  5016. <= IW_EV_ADDR_LEN) {
  5017. /* Ask user space to try again with a
  5018. * bigger buffer */
  5019. err = -E2BIG;
  5020. goto out;
  5021. }
  5022. }
  5023. }
  5024. srq->length = (current_ev - extra);
  5025. srq->flags = (__u16) priv->scan_mode;
  5026. out:
  5027. orinoco_unlock(priv, &flags);
  5028. return err;
  5029. }
  5030. /* Commit handler, called after set operations */
  5031. static int orinoco_ioctl_commit(struct net_device *dev,
  5032. struct iw_request_info *info,
  5033. void *wrqu,
  5034. char *extra)
  5035. {
  5036. struct orinoco_private *priv = netdev_priv(dev);
  5037. struct hermes *hw = &priv->hw;
  5038. unsigned long flags;
  5039. int err = 0;
  5040. if (!priv->open)
  5041. return 0;
  5042. if (priv->broken_disableport) {
  5043. orinoco_reset(&priv->reset_work);
  5044. return 0;
  5045. }
  5046. if (orinoco_lock(priv, &flags) != 0)
  5047. return err;
  5048. err = hermes_disable_port(hw, 0);
  5049. if (err) {
  5050. printk(KERN_WARNING "%s: Unable to disable port "
  5051. "while reconfiguring card\n", dev->name);
  5052. priv->broken_disableport = 1;
  5053. goto out;
  5054. }
  5055. err = __orinoco_program_rids(dev);
  5056. if (err) {
  5057. printk(KERN_WARNING "%s: Unable to reconfigure card\n",
  5058. dev->name);
  5059. goto out;
  5060. }
  5061. err = hermes_enable_port(hw, 0);
  5062. if (err) {
  5063. printk(KERN_WARNING "%s: Unable to enable port while reconfiguring card\n",
  5064. dev->name);
  5065. goto out;
  5066. }
  5067. out:
  5068. if (err) {
  5069. printk(KERN_WARNING "%s: Resetting instead...\n", dev->name);
  5070. schedule_work(&priv->reset_work);
  5071. err = 0;
  5072. }
  5073. orinoco_unlock(priv, &flags);
  5074. return err;
  5075. }
  5076. static const struct iw_priv_args orinoco_privtab[] = {
  5077. { SIOCIWFIRSTPRIV + 0x0, 0, 0, "force_reset" },
  5078. { SIOCIWFIRSTPRIV + 0x1, 0, 0, "card_reset" },
  5079. { SIOCIWFIRSTPRIV + 0x2, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  5080. 0, "set_port3" },
  5081. { SIOCIWFIRSTPRIV + 0x3, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  5082. "get_port3" },
  5083. { SIOCIWFIRSTPRIV + 0x4, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  5084. 0, "set_preamble" },
  5085. { SIOCIWFIRSTPRIV + 0x5, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  5086. "get_preamble" },
  5087. { SIOCIWFIRSTPRIV + 0x6, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  5088. 0, "set_ibssport" },
  5089. { SIOCIWFIRSTPRIV + 0x7, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  5090. "get_ibssport" },
  5091. { SIOCIWFIRSTPRIV + 0x9, 0, IW_PRIV_TYPE_BYTE | MAX_RID_LEN,
  5092. "get_rid" },
  5093. };
  5094. /*
  5095. * Structures to export the Wireless Handlers
  5096. */
  5097. #define STD_IW_HANDLER(id, func) \
  5098. [IW_IOCTL_IDX(id)] = (iw_handler) func
  5099. static const iw_handler orinoco_handler[] = {
  5100. STD_IW_HANDLER(SIOCSIWCOMMIT, orinoco_ioctl_commit),
  5101. STD_IW_HANDLER(SIOCGIWNAME, orinoco_ioctl_getname),
  5102. STD_IW_HANDLER(SIOCSIWFREQ, orinoco_ioctl_setfreq),
  5103. STD_IW_HANDLER(SIOCGIWFREQ, orinoco_ioctl_getfreq),
  5104. STD_IW_HANDLER(SIOCSIWMODE, orinoco_ioctl_setmode),
  5105. STD_IW_HANDLER(SIOCGIWMODE, orinoco_ioctl_getmode),
  5106. STD_IW_HANDLER(SIOCSIWSENS, orinoco_ioctl_setsens),
  5107. STD_IW_HANDLER(SIOCGIWSENS, orinoco_ioctl_getsens),
  5108. STD_IW_HANDLER(SIOCGIWRANGE, orinoco_ioctl_getiwrange),
  5109. STD_IW_HANDLER(SIOCSIWSPY, iw_handler_set_spy),
  5110. STD_IW_HANDLER(SIOCGIWSPY, iw_handler_get_spy),
  5111. STD_IW_HANDLER(SIOCSIWTHRSPY, iw_handler_set_thrspy),
  5112. STD_IW_HANDLER(SIOCGIWTHRSPY, iw_handler_get_thrspy),
  5113. STD_IW_HANDLER(SIOCSIWAP, orinoco_ioctl_setwap),
  5114. STD_IW_HANDLER(SIOCGIWAP, orinoco_ioctl_getwap),
  5115. STD_IW_HANDLER(SIOCSIWSCAN, orinoco_ioctl_setscan),
  5116. STD_IW_HANDLER(SIOCGIWSCAN, orinoco_ioctl_getscan),
  5117. STD_IW_HANDLER(SIOCSIWESSID, orinoco_ioctl_setessid),
  5118. STD_IW_HANDLER(SIOCGIWESSID, orinoco_ioctl_getessid),
  5119. STD_IW_HANDLER(SIOCSIWNICKN, orinoco_ioctl_setnick),
  5120. STD_IW_HANDLER(SIOCGIWNICKN, orinoco_ioctl_getnick),
  5121. STD_IW_HANDLER(SIOCSIWRATE, orinoco_ioctl_setrate),
  5122. STD_IW_HANDLER(SIOCGIWRATE, orinoco_ioctl_getrate),
  5123. STD_IW_HANDLER(SIOCSIWRTS, orinoco_ioctl_setrts),
  5124. STD_IW_HANDLER(SIOCGIWRTS, orinoco_ioctl_getrts),
  5125. STD_IW_HANDLER(SIOCSIWFRAG, orinoco_ioctl_setfrag),
  5126. STD_IW_HANDLER(SIOCGIWFRAG, orinoco_ioctl_getfrag),
  5127. STD_IW_HANDLER(SIOCGIWRETRY, orinoco_ioctl_getretry),
  5128. STD_IW_HANDLER(SIOCSIWENCODE, orinoco_ioctl_setiwencode),
  5129. STD_IW_HANDLER(SIOCGIWENCODE, orinoco_ioctl_getiwencode),
  5130. STD_IW_HANDLER(SIOCSIWPOWER, orinoco_ioctl_setpower),
  5131. STD_IW_HANDLER(SIOCGIWPOWER, orinoco_ioctl_getpower),
  5132. STD_IW_HANDLER(SIOCSIWGENIE, orinoco_ioctl_set_genie),
  5133. STD_IW_HANDLER(SIOCGIWGENIE, orinoco_ioctl_get_genie),
  5134. STD_IW_HANDLER(SIOCSIWMLME, orinoco_ioctl_set_mlme),
  5135. STD_IW_HANDLER(SIOCSIWAUTH, orinoco_ioctl_set_auth),
  5136. STD_IW_HANDLER(SIOCGIWAUTH, orinoco_ioctl_get_auth),
  5137. STD_IW_HANDLER(SIOCSIWENCODEEXT, orinoco_ioctl_set_encodeext),
  5138. STD_IW_HANDLER(SIOCGIWENCODEEXT, orinoco_ioctl_get_encodeext),
  5139. };
  5140. /*
  5141. Added typecasting since we no longer use iwreq_data -- Moustafa
  5142. */
  5143. static const iw_handler orinoco_private_handler[] = {
  5144. [0] = (iw_handler) orinoco_ioctl_reset,
  5145. [1] = (iw_handler) orinoco_ioctl_reset,
  5146. [2] = (iw_handler) orinoco_ioctl_setport3,
  5147. [3] = (iw_handler) orinoco_ioctl_getport3,
  5148. [4] = (iw_handler) orinoco_ioctl_setpreamble,
  5149. [5] = (iw_handler) orinoco_ioctl_getpreamble,
  5150. [6] = (iw_handler) orinoco_ioctl_setibssport,
  5151. [7] = (iw_handler) orinoco_ioctl_getibssport,
  5152. [9] = (iw_handler) orinoco_ioctl_getrid,
  5153. };
  5154. static const struct iw_handler_def orinoco_handler_def = {
  5155. .num_standard = ARRAY_SIZE(orinoco_handler),
  5156. .num_private = ARRAY_SIZE(orinoco_private_handler),
  5157. .num_private_args = ARRAY_SIZE(orinoco_privtab),
  5158. .standard = orinoco_handler,
  5159. .private = orinoco_private_handler,
  5160. .private_args = orinoco_privtab,
  5161. .get_wireless_stats = orinoco_get_wireless_stats,
  5162. };
  5163. static void orinoco_get_drvinfo(struct net_device *dev,
  5164. struct ethtool_drvinfo *info)
  5165. {
  5166. struct orinoco_private *priv = netdev_priv(dev);
  5167. strncpy(info->driver, DRIVER_NAME, sizeof(info->driver) - 1);
  5168. strncpy(info->version, DRIVER_VERSION, sizeof(info->version) - 1);
  5169. strncpy(info->fw_version, priv->fw_name, sizeof(info->fw_version) - 1);
  5170. if (dev->dev.parent)
  5171. strncpy(info->bus_info, dev_name(dev->dev.parent),
  5172. sizeof(info->bus_info) - 1);
  5173. else
  5174. snprintf(info->bus_info, sizeof(info->bus_info) - 1,
  5175. "PCMCIA %p", priv->hw.iobase);
  5176. }
  5177. static const struct ethtool_ops orinoco_ethtool_ops = {
  5178. .get_drvinfo = orinoco_get_drvinfo,
  5179. .get_link = ethtool_op_get_link,
  5180. };
  5181. /********************************************************************/
  5182. /* Module initialization */
  5183. /********************************************************************/
  5184. EXPORT_SYMBOL(alloc_orinocodev);
  5185. EXPORT_SYMBOL(free_orinocodev);
  5186. EXPORT_SYMBOL(__orinoco_up);
  5187. EXPORT_SYMBOL(__orinoco_down);
  5188. EXPORT_SYMBOL(orinoco_reinit_firmware);
  5189. EXPORT_SYMBOL(orinoco_interrupt);
  5190. /* Can't be declared "const" or the whole __initdata section will
  5191. * become const */
  5192. static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION
  5193. " (David Gibson <hermes@gibson.dropbear.id.au>, "
  5194. "Pavel Roskin <proski@gnu.org>, et al)";
  5195. static int __init init_orinoco(void)
  5196. {
  5197. printk(KERN_DEBUG "%s\n", version);
  5198. return 0;
  5199. }
  5200. static void __exit exit_orinoco(void)
  5201. {
  5202. }
  5203. module_init(init_orinoco);
  5204. module_exit(exit_orinoco);