main.c 143 KB

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