orinoco.c 133 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720
  1. /* orinoco.c - (formerly known as dldwd_cs.c and orinoco_cs.c)
  2. *
  3. * A driver for Hermes or Prism 2 chipset based PCMCIA wireless
  4. * adaptors, with Lucent/Agere, Intersil or Symbol firmware.
  5. *
  6. * Current maintainers (as of 29 September 2003) are:
  7. * Pavel Roskin <proski AT gnu.org>
  8. * and David Gibson <hermes AT gibson.dropbear.id.au>
  9. *
  10. * (C) Copyright David Gibson, IBM Corporation 2001-2003.
  11. * Copyright (C) 2000 David Gibson, Linuxcare Australia.
  12. * With some help from :
  13. * Copyright (C) 2001 Jean Tourrilhes, HP Labs
  14. * Copyright (C) 2001 Benjamin Herrenschmidt
  15. *
  16. * Based on dummy_cs.c 1.27 2000/06/12 21:27:25
  17. *
  18. * Portions based on wvlan_cs.c 1.0.6, Copyright Andreas Neuhaus <andy
  19. * AT fasta.fh-dortmund.de>
  20. * http://www.stud.fh-dortmund.de/~andy/wvlan/
  21. *
  22. * The contents of this file are subject to the Mozilla Public License
  23. * Version 1.1 (the "License"); you may not use this file except in
  24. * compliance with the License. You may obtain a copy of the License
  25. * at http://www.mozilla.org/MPL/
  26. *
  27. * Software distributed under the License is distributed on an "AS IS"
  28. * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
  29. * the License for the specific language governing rights and
  30. * limitations under the License.
  31. *
  32. * The initial developer of the original code is David A. Hinds
  33. * <dahinds AT users.sourceforge.net>. Portions created by David
  34. * A. Hinds are Copyright (C) 1999 David A. Hinds. All Rights
  35. * Reserved.
  36. *
  37. * Alternatively, the contents of this file may be used under the
  38. * terms of the GNU General Public License version 2 (the "GPL"), in
  39. * which case the provisions of the GPL are applicable instead of the
  40. * above. If you wish to allow the use of your version of this file
  41. * only under the terms of the GPL and not to allow others to use your
  42. * version of this file under the MPL, indicate your decision by
  43. * deleting the provisions above and replace them with the notice and
  44. * other provisions required by the GPL. If you do not delete the
  45. * provisions above, a recipient may use your version of this file
  46. * under either the MPL or the GPL. */
  47. /*
  48. * v0.01 -> v0.02 - 21/3/2001 - Jean II
  49. * o Allow to use regular ethX device name instead of dldwdX
  50. * o Warning on IBSS with ESSID=any for firmware 6.06
  51. * o Put proper range.throughput values (optimistic)
  52. * o IWSPY support (IOCTL and stat gather in Rx path)
  53. * o Allow setting frequency in Ad-Hoc mode
  54. * o Disable WEP setting if !has_wep to work on old firmware
  55. * o Fix txpower range
  56. * o Start adding support for Samsung/Compaq firmware
  57. *
  58. * v0.02 -> v0.03 - 23/3/2001 - Jean II
  59. * o Start adding Symbol support - need to check all that
  60. * o Fix Prism2/Symbol WEP to accept 128 bits keys
  61. * o Add Symbol WEP (add authentication type)
  62. * o Add Prism2/Symbol rate
  63. * o Add PM timeout (holdover duration)
  64. * o Enable "iwconfig eth0 key off" and friends (toggle flags)
  65. * o Enable "iwconfig eth0 power unicast/all" (toggle flags)
  66. * o Try with an Intel card. It report firmware 1.01, behave like
  67. * an antiquated firmware, however on windows it says 2.00. Yuck !
  68. * o Workaround firmware bug in allocate buffer (Intel 1.01)
  69. * o Finish external renaming to orinoco...
  70. * o Testing with various Wavelan firmwares
  71. *
  72. * v0.03 -> v0.04 - 30/3/2001 - Jean II
  73. * o Update to Wireless 11 -> add retry limit/lifetime support
  74. * o Tested with a D-Link DWL 650 card, fill in firmware support
  75. * o Warning on Vcc mismatch (D-Link 3.3v card in Lucent 5v only slot)
  76. * o Fixed the Prism2 WEP bugs that I introduced in v0.03 :-(
  77. * It works on D-Link *only* after a tcpdump. Weird...
  78. * And still doesn't work on Intel card. Grrrr...
  79. * o Update the mode after a setport3
  80. * o Add preamble setting for Symbol cards (not yet enabled)
  81. * o Don't complain as much about Symbol cards...
  82. *
  83. * v0.04 -> v0.04b - 22/4/2001 - David Gibson
  84. * o Removed the 'eth' parameter - always use ethXX as the
  85. * interface name instead of dldwdXX. The other was racy
  86. * anyway.
  87. * o Clean up RID definitions in hermes.h, other cleanups
  88. *
  89. * v0.04b -> v0.04c - 24/4/2001 - Jean II
  90. * o Tim Hurley <timster AT seiki.bliztech.com> reported a D-Link card
  91. * with vendor 02 and firmware 0.08. Added in the capabilities...
  92. * o Tested Lucent firmware 7.28, everything works...
  93. *
  94. * v0.04c -> v0.05 - 3/5/2001 - Benjamin Herrenschmidt
  95. * o Spin-off Pcmcia code. This file is renamed orinoco.c,
  96. * and orinoco_cs.c now contains only the Pcmcia specific stuff
  97. * o Add Airport driver support on top of orinoco.c (see airport.c)
  98. *
  99. * v0.05 -> v0.05a - 4/5/2001 - Jean II
  100. * o Revert to old Pcmcia code to fix breakage of Ben's changes...
  101. *
  102. * v0.05a -> v0.05b - 4/5/2001 - Jean II
  103. * o add module parameter 'ignore_cis_vcc' for D-Link @ 5V
  104. * o D-Link firmware doesn't support multicast. We just print a few
  105. * error messages, but otherwise everything works...
  106. * o For David : set/getport3 works fine, just upgrade iwpriv...
  107. *
  108. * v0.05b -> v0.05c - 5/5/2001 - Benjamin Herrenschmidt
  109. * o Adapt airport.c to latest changes in orinoco.c
  110. * o Remove deferred power enabling code
  111. *
  112. * v0.05c -> v0.05d - 5/5/2001 - Jean II
  113. * o Workaround to SNAP decapsulate frame from Linksys AP
  114. * original patch from : Dong Liu <dliu AT research.bell-labs.com>
  115. * (note : the memcmp bug was mine - fixed)
  116. * o Remove set_retry stuff, no firmware support it (bloat--).
  117. *
  118. * v0.05d -> v0.06 - 25/5/2001 - Jean II
  119. * Original patch from "Hong Lin" <alin AT redhat.com>,
  120. * "Ian Kinner" <ikinner AT redhat.com>
  121. * and "David Smith" <dsmith AT redhat.com>
  122. * o Init of priv->tx_rate_ctrl in firmware specific section.
  123. * o Prism2/Symbol rate, upto should be 0xF and not 0x15. Doh !
  124. * o Spectrum card always need cor_reset (for every reset)
  125. * o Fix cor_reset to not lose bit 7 in the register
  126. * o flush_stale_links to remove zombie Pcmcia instances
  127. * o Ack previous hermes event before reset
  128. * Me (with my little hands)
  129. * o Allow orinoco.c to call cor_reset via priv->card_reset_handler
  130. * o Add priv->need_card_reset to toggle this feature
  131. * o Fix various buglets when setting WEP in Symbol firmware
  132. * Now, encryption is fully functional on Symbol cards. Youpi !
  133. *
  134. * v0.06 -> v0.06b - 25/5/2001 - Jean II
  135. * o IBSS on Symbol use port_mode = 4. Please don't ask...
  136. *
  137. * v0.06b -> v0.06c - 29/5/2001 - Jean II
  138. * o Show first spy address in /proc/net/wireless for IBSS mode as well
  139. *
  140. * v0.06c -> v0.06d - 6/7/2001 - David Gibson
  141. * o Change a bunch of KERN_INFO messages to KERN_DEBUG, as per Linus'
  142. * wishes to reduce the number of unnecessary messages.
  143. * o Removed bogus message on CRC error.
  144. * o Merged fixes for v0.08 Prism 2 firmware from William Waghorn
  145. * <willwaghorn AT yahoo.co.uk>
  146. * o Slight cleanup/re-arrangement of firmware detection code.
  147. *
  148. * v0.06d -> v0.06e - 1/8/2001 - David Gibson
  149. * o Removed some redundant global initializers (orinoco_cs.c).
  150. * o Added some module metadata
  151. *
  152. * v0.06e -> v0.06f - 14/8/2001 - David Gibson
  153. * o Wording fix to license
  154. * o Added a 'use_alternate_encaps' module parameter for APs which need an
  155. * oui of 00:00:00. We really need a better way of handling this, but
  156. * the module flag is better than nothing for now.
  157. *
  158. * v0.06f -> v0.07 - 20/8/2001 - David Gibson
  159. * o Removed BAP error retries from hermes_bap_seek(). For Tx we now
  160. * let the upper layers handle the retry, we retry explicitly in the
  161. * Rx path, but don't make as much noise about it.
  162. * o Firmware detection cleanups.
  163. *
  164. * v0.07 -> v0.07a - 1/10/3001 - Jean II
  165. * o Add code to read Symbol firmware revision, inspired by latest code
  166. * in Spectrum24 by Lee John Keyser-Allen - Thanks Lee !
  167. * o Thanks to Jared Valentine <hidden AT xmission.com> for "providing" me
  168. * a 3Com card with a recent firmware, fill out Symbol firmware
  169. * capabilities of latest rev (2.20), as well as older Symbol cards.
  170. * o Disable Power Management in newer Symbol firmware, the API
  171. * has changed (documentation needed).
  172. *
  173. * v0.07a -> v0.08 - 3/10/2001 - David Gibson
  174. * o Fixed a possible buffer overrun found by the Stanford checker (in
  175. * dldwd_ioctl_setiwencode()). Can only be called by root anyway, so not
  176. * a big problem.
  177. * o Turned has_big_wep on for Intersil cards. That's not true for all of
  178. * them but we should at least let the capable ones try.
  179. * o Wait for BUSY to clear at the beginning of hermes_bap_seek(). I
  180. * realized that my assumption that the driver's serialization
  181. * would prevent the BAP being busy on entry was possibly false, because
  182. * things other than seeks may make the BAP busy.
  183. * o Use "alternate" (oui 00:00:00) encapsulation by default.
  184. * Setting use_old_encaps will mimic the old behaviour, but I think we
  185. * will be able to eliminate this.
  186. * o Don't try to make __initdata const (the version string). This can't
  187. * work because of the way the __initdata sectioning works.
  188. * o Added MODULE_LICENSE tags.
  189. * o Support for PLX (transparent PCMCIA->PCI bridge) cards.
  190. * o Changed to using the new type-fascist min/max.
  191. *
  192. * v0.08 -> v0.08a - 9/10/2001 - David Gibson
  193. * o Inserted some missing acknowledgements/info into the Changelog.
  194. * o Fixed some bugs in the normalization of signal level reporting.
  195. * o Fixed bad bug in WEP key handling on Intersil and Symbol firmware,
  196. * which led to an instant crash on big-endian machines.
  197. *
  198. * v0.08a -> v0.08b - 20/11/2001 - David Gibson
  199. * o Lots of cleanup and bugfixes in orinoco_plx.c
  200. * o Cleanup to handling of Tx rate setting.
  201. * o Removed support for old encapsulation method.
  202. * o Removed old "dldwd" names.
  203. * o Split RID constants into a new file hermes_rid.h
  204. * o Renamed RID constants to match linux-wlan-ng and prism2.o
  205. * o Bugfixes in hermes.c
  206. * o Poke the PLX's INTCSR register, so it actually starts
  207. * generating interrupts. These cards might actually work now.
  208. * o Update to wireless extensions v12 (Jean II)
  209. * o Support for tallies and inquire command (Jean II)
  210. * o Airport updates for newer PPC kernels (BenH)
  211. *
  212. * v0.08b -> v0.09 - 21/12/2001 - David Gibson
  213. * o Some new PCI IDs for PLX cards.
  214. * o Removed broken attempt to do ALLMULTI reception. Just use
  215. * promiscuous mode instead
  216. * o Preliminary work for list-AP (Jean II)
  217. * o Airport updates from (BenH)
  218. * o Eliminated racy hw_ready stuff
  219. * o Fixed generation of fake events in irq handler. This should
  220. * finally kill the EIO problems (Jean II & dgibson)
  221. * o Fixed breakage of bitrate set/get on Agere firmware (Jean II)
  222. *
  223. * v0.09 -> v0.09a - 2/1/2002 - David Gibson
  224. * o Fixed stupid mistake in multicast list handling, triggering
  225. * a BUG()
  226. *
  227. * v0.09a -> v0.09b - 16/1/2002 - David Gibson
  228. * o Fixed even stupider mistake in new interrupt handling, which
  229. * seriously broke things on big-endian machines.
  230. * o Removed a bunch of redundant includes and exports.
  231. * o Removed a redundant MOD_{INC,DEC}_USE_COUNT pair in airport.c
  232. * o Don't attempt to do hardware level multicast reception on
  233. * Intersil firmware, just go promisc instead.
  234. * o Typo fixed in hermes_issue_cmd()
  235. * o Eliminated WIRELESS_SPY #ifdefs
  236. * o Status code reported on Tx exceptions
  237. * o Moved netif_wake_queue() from ALLOC interrupts to TX and TXEXC
  238. * interrupts, which should fix the timeouts we're seeing.
  239. *
  240. * v0.09b -> v0.10 - 25 Feb 2002 - David Gibson
  241. * o Removed nested structures used for header parsing, so the
  242. * driver should now work without hackery on ARM
  243. * o Fix for WEP handling on Intersil (Hawk Newton)
  244. * o Eliminated the /proc/hermes/ethXX/regs debugging file. It
  245. * was never very useful.
  246. * o Make Rx errors less noisy.
  247. *
  248. * v0.10 -> v0.11 - 5 Apr 2002 - David Gibson
  249. * o Laid the groundwork in hermes.[ch] for devices which map
  250. * into PCI memory space rather than IO space.
  251. * o Fixed bug in multicast handling (cleared multicast list when
  252. * leaving promiscuous mode).
  253. * o Relegated Tx error messages to debug.
  254. * o Cleaned up / corrected handling of allocation lengths.
  255. * o Set OWNSSID in IBSS mode for WinXP interoperability (jimc).
  256. * o Change to using alloc_etherdev() for structure allocations.
  257. * o Check for and drop undersized packets.
  258. * o Fixed a race in stopping/waking the queue. This should fix
  259. * the timeout problems (Pavel Roskin)
  260. * o Reverted to netif_wake_queue() on the ALLOC event.
  261. * o Fixes for recent Symbol firmwares which lack AP density
  262. * (Pavel Roskin).
  263. *
  264. * v0.11 -> v0.11a - 29 Apr 2002 - David Gibson
  265. * o Handle different register spacing, necessary for Prism 2.5
  266. * PCI adaptors (Steve Hill).
  267. * o Cleaned up initialization of card structures in orinoco_cs
  268. * and airport. Removed card->priv field.
  269. * o Make response structure optional for hermes_docmd_wait()
  270. * Pavel Roskin)
  271. * o Added PCI id for Nortel emobility to orinoco_plx.c.
  272. * o Cleanup to handling of Symbol's allocation bug. (Pavel Roskin)
  273. * o Cleanups to firmware capability detection.
  274. * o Arrange for orinoco_pci.c to override firmware detection.
  275. * We should be able to support the PCI Intersil cards now.
  276. * o Cleanup handling of reset_cor and hard_reset (Pavel Roskin).
  277. * o Remove erroneous use of USER_BAP in the TxExc handler (Jouni
  278. * Malinen).
  279. * o Makefile changes for better integration into David Hinds
  280. * pcmcia-cs package.
  281. *
  282. * v0.11a -> v0.11b - 1 May 2002 - David Gibson
  283. * o Better error reporting in orinoco_plx_init_one()
  284. * o Fixed multiple bad kfree() bugs introduced by the
  285. * alloc_orinocodev() changes.
  286. *
  287. * v0.11b -> v0.12 - 19 Jun 2002 - David Gibson
  288. * o Support changing the MAC address.
  289. * o Correct display of Intersil firmware revision numbers.
  290. * o Entirely revised locking scheme. Should be both simpler and
  291. * better.
  292. * o Merged some common code in orinoco_plx, orinoco_pci and
  293. * airport by creating orinoco_default_{open,stop,reset}()
  294. * which are used as the dev->open, dev->stop, priv->reset
  295. * callbacks if none are specified when alloc_orinocodev() is
  296. * called.
  297. * o Removed orinoco_plx_interrupt() and orinoco_pci_interrupt().
  298. * They didn't do anything.
  299. *
  300. * v0.12 -> v0.12a - 4 Jul 2002 - David Gibson
  301. * o Some rearrangement of code.
  302. * o Numerous fixups to locking and rest handling, particularly
  303. * for PCMCIA.
  304. * o This allows open and stop net_device methods to be in
  305. * orinoco.c now, rather than in the init modules.
  306. * o In orinoco_cs.c link->priv now points to the struct
  307. * net_device not to the struct orinoco_private.
  308. * o Added a check for undersized SNAP frames, which could cause
  309. * crashes.
  310. *
  311. * v0.12a -> v0.12b - 11 Jul 2002 - David Gibson
  312. * o Fix hw->num_init testing code, so num_init is actually
  313. * incremented.
  314. * o Fix very stupid bug in orinoco_cs which broke compile with
  315. * CONFIG_SMP.
  316. * o Squashed a warning.
  317. *
  318. * v0.12b -> v0.12c - 26 Jul 2002 - David Gibson
  319. * o Change to C9X style designated initializers.
  320. * o Add support for 3Com AirConnect PCI.
  321. * o No longer ignore the hard_reset argument to
  322. * alloc_orinocodev(). Oops.
  323. *
  324. * v0.12c -> v0.13beta1 - 13 Sep 2002 - David Gibson
  325. * o Revert the broken 0.12* locking scheme and go to a new yet
  326. * simpler scheme.
  327. * o Do firmware resets only in orinoco_init() and when waking
  328. * the card from hard sleep.
  329. *
  330. * v0.13beta1 -> v0.13 - 27 Sep 2002 - David Gibson
  331. * o Re-introduced full resets (via schedule_task()) on Tx
  332. * timeout.
  333. *
  334. * v0.13 -> v0.13a - 30 Sep 2002 - David Gibson
  335. * o Minor cleanups to info frame handling. Add basic support
  336. * for linkstatus info frames.
  337. * o Include required kernel headers in orinoco.h, to avoid
  338. * compile problems.
  339. *
  340. * v0.13a -> v0.13b - 10 Feb 2003 - David Gibson
  341. * o Implemented hard reset for Airport cards
  342. * o Experimental suspend/resume implementation for orinoco_pci
  343. * o Abolished /proc debugging support, replaced with a debugging
  344. * iwpriv. Now it's ugly and simple instead of ugly and complex.
  345. * o Bugfix in hermes.c if the firmware returned a record length
  346. * of 0, we could go clobbering memory.
  347. * o Bugfix in orinoco_stop() - it used to fail if hw_unavailable
  348. * was set, which was usually true on PCMCIA hot removes.
  349. * o Track LINKSTATUS messages, silently drop Tx packets before
  350. * we are connected (avoids confusing the firmware), and only
  351. * give LINKSTATUS printk()s if the status has changed.
  352. *
  353. * v0.13b -> v0.13c - 11 Mar 2003 - David Gibson
  354. * o Cleanup: use dev instead of priv in various places.
  355. * o Bug fix: Don't ReleaseConfiguration on RESET_PHYSICAL event
  356. * if we're in the middle of a (driver initiated) hard reset.
  357. * o Bug fix: ETH_ZLEN is supposed to include the header
  358. * (Dionysus Blazakis & Manish Karir)
  359. * o Convert to using workqueues instead of taskqueues (and
  360. * backwards compatibility macros for pre 2.5.41 kernels).
  361. * o Drop redundant (I think...) MOD_{INC,DEC}_USE_COUNT in
  362. * airport.c
  363. * o New orinoco_tmd.c init module from Joerg Dorchain for
  364. * TMD7160 based PCI to PCMCIA bridges (similar to
  365. * orinoco_plx.c).
  366. *
  367. * v0.13c -> v0.13d - 22 Apr 2003 - David Gibson
  368. * o Make hw_unavailable a counter, rather than just a flag, this
  369. * is necessary to avoid some races (such as a card being
  370. * removed in the middle of orinoco_reset().
  371. * o Restore Release/RequestConfiguration in the PCMCIA event handler
  372. * when dealing with a driver initiated hard reset. This is
  373. * necessary to prevent hangs due to a spurious interrupt while
  374. * the reset is in progress.
  375. * o Clear the 802.11 header when transmitting, even though we
  376. * don't use it. This fixes a long standing bug on some
  377. * firmwares, which seem to get confused if that isn't done.
  378. * o Be less eager to de-encapsulate SNAP frames, only do so if
  379. * the OUI is 00:00:00 or 00:00:f8, leave others alone. The old
  380. * behaviour broke CDP (Cisco Discovery Protocol).
  381. * o Use dev instead of priv for free_irq() as well as
  382. * request_irq() (oops).
  383. * o Attempt to reset rather than giving up if we get too many
  384. * IRQs.
  385. * o Changed semantics of __orinoco_down() so it can be called
  386. * safely with hw_unavailable set. It also now clears the
  387. * linkstatus (since we're going to have to reassociate).
  388. *
  389. * v0.13d -> v0.13e - 12 May 2003 - David Gibson
  390. * o Support for post-2.5.68 return values from irq handler.
  391. * o Fixed bug where underlength packets would be double counted
  392. * in the rx_dropped statistics.
  393. * o Provided a module parameter to suppress linkstatus messages.
  394. *
  395. * v0.13e -> v0.14alpha1 - 30 Sep 2003 - David Gibson
  396. * o Replaced priv->connected logic with netif_carrier_on/off()
  397. * calls.
  398. * o Remove has_ibss_any and never set the CREATEIBSS RID when
  399. * the ESSID is empty. Too many firmwares break if we do.
  400. * o 2.6 merges: Replace pdev->slot_name with pci_name(), remove
  401. * __devinitdata from PCI ID tables, use free_netdev().
  402. * o Enabled shared-key authentication for Agere firmware (from
  403. * Robert J. Moore <Robert.J.Moore AT allanbank.com>
  404. * o Move netif_wake_queue() (back) to the Tx completion from the
  405. * ALLOC event. This seems to prevent/mitigate the rolling
  406. * error -110 problems at least on some Intersil firmwares.
  407. * Theoretically reduces performance, but I can't measure it.
  408. * Patch from Andrew Tridgell <tridge AT samba.org>
  409. *
  410. * v0.14alpha1 -> v0.14alpha2 - 20 Oct 2003 - David Gibson
  411. * o Correctly turn off shared-key authentication when requested
  412. * (bugfix from Robert J. Moore).
  413. * o Correct airport sleep interfaces for current 2.6 kernels.
  414. * o Add code for key change without disabling/enabling the MAC
  415. * port. This is supposed to allow 802.1x to work sanely, but
  416. * doesn't seem to yet.
  417. *
  418. * TODO
  419. * o New wireless extensions API (patch from Moustafa
  420. * Youssef, updated by Jim Carter and Pavel Roskin).
  421. * o Handle de-encapsulation within network layer, provide 802.11
  422. * headers (patch from Thomas 'Dent' Mirlacher)
  423. * o RF monitor mode support
  424. * o Fix possible races in SPY handling.
  425. * o Disconnect wireless extensions from fundamental configuration.
  426. * o (maybe) Software WEP support (patch from Stano Meduna).
  427. * o (maybe) Use multiple Tx buffers - driver handling queue
  428. * rather than firmware.
  429. */
  430. /* Locking and synchronization:
  431. *
  432. * The basic principle is that everything is serialized through a
  433. * single spinlock, priv->lock. The lock is used in user, bh and irq
  434. * context, so when taken outside hardirq context it should always be
  435. * taken with interrupts disabled. The lock protects both the
  436. * hardware and the struct orinoco_private.
  437. *
  438. * Another flag, priv->hw_unavailable indicates that the hardware is
  439. * unavailable for an extended period of time (e.g. suspended, or in
  440. * the middle of a hard reset). This flag is protected by the
  441. * spinlock. All code which touches the hardware should check the
  442. * flag after taking the lock, and if it is set, give up on whatever
  443. * they are doing and drop the lock again. The orinoco_lock()
  444. * function handles this (it unlocks and returns -EBUSY if
  445. * hw_unavailable is non-zero).
  446. */
  447. #define DRIVER_NAME "orinoco"
  448. #include <linux/config.h>
  449. #include <linux/module.h>
  450. #include <linux/kernel.h>
  451. #include <linux/init.h>
  452. #include <linux/ptrace.h>
  453. #include <linux/slab.h>
  454. #include <linux/string.h>
  455. #include <linux/timer.h>
  456. #include <linux/ioport.h>
  457. #include <linux/netdevice.h>
  458. #include <linux/if_arp.h>
  459. #include <linux/etherdevice.h>
  460. #include <linux/ethtool.h>
  461. #include <linux/wireless.h>
  462. #include <net/iw_handler.h>
  463. #include <net/ieee80211.h>
  464. #include <asm/uaccess.h>
  465. #include <asm/io.h>
  466. #include <asm/system.h>
  467. #include "hermes.h"
  468. #include "hermes_rid.h"
  469. #include "orinoco.h"
  470. #include "ieee802_11.h"
  471. /********************************************************************/
  472. /* Module information */
  473. /********************************************************************/
  474. MODULE_AUTHOR("Pavel Roskin <proski@gnu.org> & David Gibson <hermes@gibson.dropbear.id.au>");
  475. MODULE_DESCRIPTION("Driver for Lucent Orinoco, Prism II based and similar wireless cards");
  476. MODULE_LICENSE("Dual MPL/GPL");
  477. /* Level of debugging. Used in the macros in orinoco.h */
  478. #ifdef ORINOCO_DEBUG
  479. int orinoco_debug = ORINOCO_DEBUG;
  480. module_param(orinoco_debug, int, 0644);
  481. MODULE_PARM_DESC(orinoco_debug, "Debug level");
  482. EXPORT_SYMBOL(orinoco_debug);
  483. #endif
  484. static int suppress_linkstatus; /* = 0 */
  485. module_param(suppress_linkstatus, bool, 0644);
  486. MODULE_PARM_DESC(suppress_linkstatus, "Don't log link status changes");
  487. static int ignore_disconnect; /* = 0 */
  488. module_param(ignore_disconnect, int, 0644);
  489. MODULE_PARM_DESC(ignore_disconnect, "Don't report lost link to the network layer");
  490. /********************************************************************/
  491. /* Compile time configuration and compatibility stuff */
  492. /********************************************************************/
  493. /* We do this this way to avoid ifdefs in the actual code */
  494. #ifdef WIRELESS_SPY
  495. #define SPY_NUMBER(priv) (priv->spy_number)
  496. #else
  497. #define SPY_NUMBER(priv) 0
  498. #endif /* WIRELESS_SPY */
  499. /********************************************************************/
  500. /* Internal constants */
  501. /********************************************************************/
  502. /* 802.2 LLC/SNAP header used for Ethernet encapsulation over 802.11 */
  503. static const u8 encaps_hdr[] = {0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00};
  504. #define ENCAPS_OVERHEAD (sizeof(encaps_hdr) + 2)
  505. #define ORINOCO_MIN_MTU 256
  506. #define ORINOCO_MAX_MTU (IEEE802_11_DATA_LEN - ENCAPS_OVERHEAD)
  507. #define SYMBOL_MAX_VER_LEN (14)
  508. #define USER_BAP 0
  509. #define IRQ_BAP 1
  510. #define MAX_IRQLOOPS_PER_IRQ 10
  511. #define MAX_IRQLOOPS_PER_JIFFY (20000/HZ) /* Based on a guestimate of
  512. * how many events the
  513. * device could
  514. * legitimately generate */
  515. #define SMALL_KEY_SIZE 5
  516. #define LARGE_KEY_SIZE 13
  517. #define TX_NICBUF_SIZE_BUG 1585 /* Bug in Symbol firmware */
  518. #define DUMMY_FID 0xFFFF
  519. /*#define MAX_MULTICAST(priv) (priv->firmware_type == FIRMWARE_TYPE_AGERE ? \
  520. HERMES_MAX_MULTICAST : 0)*/
  521. #define MAX_MULTICAST(priv) (HERMES_MAX_MULTICAST)
  522. #define ORINOCO_INTEN (HERMES_EV_RX | HERMES_EV_ALLOC \
  523. | HERMES_EV_TX | HERMES_EV_TXEXC \
  524. | HERMES_EV_WTERR | HERMES_EV_INFO \
  525. | HERMES_EV_INFDROP )
  526. #define MAX_RID_LEN 1024
  527. static const struct iw_handler_def orinoco_handler_def;
  528. static struct ethtool_ops orinoco_ethtool_ops;
  529. /********************************************************************/
  530. /* Data tables */
  531. /********************************************************************/
  532. /* The frequency of each channel in MHz */
  533. static const long channel_frequency[] = {
  534. 2412, 2417, 2422, 2427, 2432, 2437, 2442,
  535. 2447, 2452, 2457, 2462, 2467, 2472, 2484
  536. };
  537. #define NUM_CHANNELS ARRAY_SIZE(channel_frequency)
  538. /* This tables gives the actual meanings of the bitrate IDs returned
  539. * by the firmware. */
  540. static struct {
  541. int bitrate; /* in 100s of kilobits */
  542. int automatic;
  543. u16 agere_txratectrl;
  544. u16 intersil_txratectrl;
  545. } bitrate_table[] = {
  546. {110, 1, 3, 15}, /* Entry 0 is the default */
  547. {10, 0, 1, 1},
  548. {10, 1, 1, 1},
  549. {20, 0, 2, 2},
  550. {20, 1, 6, 3},
  551. {55, 0, 4, 4},
  552. {55, 1, 7, 7},
  553. {110, 0, 5, 8},
  554. };
  555. #define BITRATE_TABLE_SIZE ARRAY_SIZE(bitrate_table)
  556. /********************************************************************/
  557. /* Data types */
  558. /********************************************************************/
  559. /* Used in Event handling.
  560. * We avoid nested structres as they break on ARM -- Moustafa */
  561. struct hermes_tx_descriptor_802_11 {
  562. /* hermes_tx_descriptor */
  563. u16 status;
  564. u16 reserved1;
  565. u16 reserved2;
  566. u32 sw_support;
  567. u8 retry_count;
  568. u8 tx_rate;
  569. u16 tx_control;
  570. /* ieee802_11_hdr */
  571. u16 frame_ctl;
  572. u16 duration_id;
  573. u8 addr1[ETH_ALEN];
  574. u8 addr2[ETH_ALEN];
  575. u8 addr3[ETH_ALEN];
  576. u16 seq_ctl;
  577. u8 addr4[ETH_ALEN];
  578. u16 data_len;
  579. /* ethhdr */
  580. unsigned char h_dest[ETH_ALEN]; /* destination eth addr */
  581. unsigned char h_source[ETH_ALEN]; /* source ether addr */
  582. unsigned short h_proto; /* packet type ID field */
  583. /* p8022_hdr */
  584. u8 dsap;
  585. u8 ssap;
  586. u8 ctrl;
  587. u8 oui[3];
  588. u16 ethertype;
  589. } __attribute__ ((packed));
  590. struct hermes_rx_descriptor {
  591. u16 status;
  592. u32 time;
  593. u8 silence;
  594. u8 signal;
  595. u8 rate;
  596. u8 rxflow;
  597. u32 reserved;
  598. } __attribute__ ((packed));
  599. /********************************************************************/
  600. /* Function prototypes */
  601. /********************************************************************/
  602. static int __orinoco_program_rids(struct net_device *dev);
  603. static void __orinoco_set_multicast_list(struct net_device *dev);
  604. /********************************************************************/
  605. /* Internal helper functions */
  606. /********************************************************************/
  607. static inline void set_port_type(struct orinoco_private *priv)
  608. {
  609. switch (priv->iw_mode) {
  610. case IW_MODE_INFRA:
  611. priv->port_type = 1;
  612. priv->createibss = 0;
  613. break;
  614. case IW_MODE_ADHOC:
  615. if (priv->prefer_port3) {
  616. priv->port_type = 3;
  617. priv->createibss = 0;
  618. } else {
  619. priv->port_type = priv->ibss_port;
  620. priv->createibss = 1;
  621. }
  622. break;
  623. default:
  624. printk(KERN_ERR "%s: Invalid priv->iw_mode in set_port_type()\n",
  625. priv->ndev->name);
  626. }
  627. }
  628. /********************************************************************/
  629. /* Device methods */
  630. /********************************************************************/
  631. static int orinoco_open(struct net_device *dev)
  632. {
  633. struct orinoco_private *priv = netdev_priv(dev);
  634. unsigned long flags;
  635. int err;
  636. if (orinoco_lock(priv, &flags) != 0)
  637. return -EBUSY;
  638. err = __orinoco_up(dev);
  639. if (! err)
  640. priv->open = 1;
  641. orinoco_unlock(priv, &flags);
  642. return err;
  643. }
  644. static int orinoco_stop(struct net_device *dev)
  645. {
  646. struct orinoco_private *priv = netdev_priv(dev);
  647. int err = 0;
  648. /* We mustn't use orinoco_lock() here, because we need to be
  649. able to close the interface even if hw_unavailable is set
  650. (e.g. as we're released after a PC Card removal) */
  651. spin_lock_irq(&priv->lock);
  652. priv->open = 0;
  653. err = __orinoco_down(dev);
  654. spin_unlock_irq(&priv->lock);
  655. return err;
  656. }
  657. static struct net_device_stats *orinoco_get_stats(struct net_device *dev)
  658. {
  659. struct orinoco_private *priv = netdev_priv(dev);
  660. return &priv->stats;
  661. }
  662. static struct iw_statistics *orinoco_get_wireless_stats(struct net_device *dev)
  663. {
  664. struct orinoco_private *priv = netdev_priv(dev);
  665. hermes_t *hw = &priv->hw;
  666. struct iw_statistics *wstats = &priv->wstats;
  667. int err;
  668. unsigned long flags;
  669. if (! netif_device_present(dev)) {
  670. printk(KERN_WARNING "%s: get_wireless_stats() called while device not present\n",
  671. dev->name);
  672. return NULL; /* FIXME: Can we do better than this? */
  673. }
  674. /* If busy, return the old stats. Returning NULL may cause
  675. * the interface to disappear from /proc/net/wireless */
  676. if (orinoco_lock(priv, &flags) != 0)
  677. return wstats;
  678. /* We can't really wait for the tallies inquiry command to
  679. * complete, so we just use the previous results and trigger
  680. * a new tallies inquiry command for next time - Jean II */
  681. /* FIXME: Really we should wait for the inquiry to come back -
  682. * as it is the stats we give don't make a whole lot of sense.
  683. * Unfortunately, it's not clear how to do that within the
  684. * wireless extensions framework: I think we're in user
  685. * context, but a lock seems to be held by the time we get in
  686. * here so we're not safe to sleep here. */
  687. hermes_inquire(hw, HERMES_INQ_TALLIES);
  688. if (priv->iw_mode == IW_MODE_ADHOC) {
  689. memset(&wstats->qual, 0, sizeof(wstats->qual));
  690. /* If a spy address is defined, we report stats of the
  691. * first spy address - Jean II */
  692. if (SPY_NUMBER(priv)) {
  693. wstats->qual.qual = priv->spy_stat[0].qual;
  694. wstats->qual.level = priv->spy_stat[0].level;
  695. wstats->qual.noise = priv->spy_stat[0].noise;
  696. wstats->qual.updated = priv->spy_stat[0].updated;
  697. }
  698. } else {
  699. struct {
  700. u16 qual, signal, noise;
  701. } __attribute__ ((packed)) cq;
  702. err = HERMES_READ_RECORD(hw, USER_BAP,
  703. HERMES_RID_COMMSQUALITY, &cq);
  704. if (!err) {
  705. wstats->qual.qual = (int)le16_to_cpu(cq.qual);
  706. wstats->qual.level = (int)le16_to_cpu(cq.signal) - 0x95;
  707. wstats->qual.noise = (int)le16_to_cpu(cq.noise) - 0x95;
  708. wstats->qual.updated = 7;
  709. }
  710. }
  711. orinoco_unlock(priv, &flags);
  712. return wstats;
  713. }
  714. static void orinoco_set_multicast_list(struct net_device *dev)
  715. {
  716. struct orinoco_private *priv = netdev_priv(dev);
  717. unsigned long flags;
  718. if (orinoco_lock(priv, &flags) != 0) {
  719. printk(KERN_DEBUG "%s: orinoco_set_multicast_list() "
  720. "called when hw_unavailable\n", dev->name);
  721. return;
  722. }
  723. __orinoco_set_multicast_list(dev);
  724. orinoco_unlock(priv, &flags);
  725. }
  726. static int orinoco_change_mtu(struct net_device *dev, int new_mtu)
  727. {
  728. struct orinoco_private *priv = netdev_priv(dev);
  729. if ( (new_mtu < ORINOCO_MIN_MTU) || (new_mtu > ORINOCO_MAX_MTU) )
  730. return -EINVAL;
  731. if ( (new_mtu + ENCAPS_OVERHEAD + IEEE802_11_HLEN) >
  732. (priv->nicbuf_size - ETH_HLEN) )
  733. return -EINVAL;
  734. dev->mtu = new_mtu;
  735. return 0;
  736. }
  737. /********************************************************************/
  738. /* Tx path */
  739. /********************************************************************/
  740. static int orinoco_xmit(struct sk_buff *skb, struct net_device *dev)
  741. {
  742. struct orinoco_private *priv = netdev_priv(dev);
  743. struct net_device_stats *stats = &priv->stats;
  744. hermes_t *hw = &priv->hw;
  745. int err = 0;
  746. u16 txfid = priv->txfid;
  747. char *p;
  748. struct ethhdr *eh;
  749. int len, data_len, data_off;
  750. struct hermes_tx_descriptor desc;
  751. unsigned long flags;
  752. TRACE_ENTER(dev->name);
  753. if (! netif_running(dev)) {
  754. printk(KERN_ERR "%s: Tx on stopped device!\n",
  755. dev->name);
  756. TRACE_EXIT(dev->name);
  757. return 1;
  758. }
  759. if (netif_queue_stopped(dev)) {
  760. printk(KERN_DEBUG "%s: Tx while transmitter busy!\n",
  761. dev->name);
  762. TRACE_EXIT(dev->name);
  763. return 1;
  764. }
  765. if (orinoco_lock(priv, &flags) != 0) {
  766. printk(KERN_ERR "%s: orinoco_xmit() called while hw_unavailable\n",
  767. dev->name);
  768. TRACE_EXIT(dev->name);
  769. return 1;
  770. }
  771. if (! netif_carrier_ok(dev)) {
  772. /* Oops, the firmware hasn't established a connection,
  773. silently drop the packet (this seems to be the
  774. safest approach). */
  775. stats->tx_errors++;
  776. orinoco_unlock(priv, &flags);
  777. dev_kfree_skb(skb);
  778. TRACE_EXIT(dev->name);
  779. return 0;
  780. }
  781. /* Length of the packet body */
  782. /* FIXME: what if the skb is smaller than this? */
  783. len = max_t(int,skb->len - ETH_HLEN, ETH_ZLEN - ETH_HLEN);
  784. eh = (struct ethhdr *)skb->data;
  785. memset(&desc, 0, sizeof(desc));
  786. desc.tx_control = cpu_to_le16(HERMES_TXCTRL_TX_OK | HERMES_TXCTRL_TX_EX);
  787. err = hermes_bap_pwrite(hw, USER_BAP, &desc, sizeof(desc), txfid, 0);
  788. if (err) {
  789. if (net_ratelimit())
  790. printk(KERN_ERR "%s: Error %d writing Tx descriptor "
  791. "to BAP\n", dev->name, err);
  792. stats->tx_errors++;
  793. goto fail;
  794. }
  795. /* Clear the 802.11 header and data length fields - some
  796. * firmwares (e.g. Lucent/Agere 8.xx) appear to get confused
  797. * if this isn't done. */
  798. hermes_clear_words(hw, HERMES_DATA0,
  799. HERMES_802_3_OFFSET - HERMES_802_11_OFFSET);
  800. /* Encapsulate Ethernet-II frames */
  801. if (ntohs(eh->h_proto) > ETH_DATA_LEN) { /* Ethernet-II frame */
  802. struct header_struct hdr;
  803. data_len = len;
  804. data_off = HERMES_802_3_OFFSET + sizeof(hdr);
  805. p = skb->data + ETH_HLEN;
  806. /* 802.3 header */
  807. memcpy(hdr.dest, eh->h_dest, ETH_ALEN);
  808. memcpy(hdr.src, eh->h_source, ETH_ALEN);
  809. hdr.len = htons(data_len + ENCAPS_OVERHEAD);
  810. /* 802.2 header */
  811. memcpy(&hdr.dsap, &encaps_hdr, sizeof(encaps_hdr));
  812. hdr.ethertype = eh->h_proto;
  813. err = hermes_bap_pwrite(hw, USER_BAP, &hdr, sizeof(hdr),
  814. txfid, HERMES_802_3_OFFSET);
  815. if (err) {
  816. if (net_ratelimit())
  817. printk(KERN_ERR "%s: Error %d writing packet "
  818. "header to BAP\n", dev->name, err);
  819. stats->tx_errors++;
  820. goto fail;
  821. }
  822. } else { /* IEEE 802.3 frame */
  823. data_len = len + ETH_HLEN;
  824. data_off = HERMES_802_3_OFFSET;
  825. p = skb->data;
  826. }
  827. /* Round up for odd length packets */
  828. err = hermes_bap_pwrite(hw, USER_BAP, p, ALIGN(data_len, 2),
  829. txfid, data_off);
  830. if (err) {
  831. printk(KERN_ERR "%s: Error %d writing packet to BAP\n",
  832. dev->name, err);
  833. stats->tx_errors++;
  834. goto fail;
  835. }
  836. /* Finally, we actually initiate the send */
  837. netif_stop_queue(dev);
  838. err = hermes_docmd_wait(hw, HERMES_CMD_TX | HERMES_CMD_RECL,
  839. txfid, NULL);
  840. if (err) {
  841. netif_start_queue(dev);
  842. printk(KERN_ERR "%s: Error %d transmitting packet\n",
  843. dev->name, err);
  844. stats->tx_errors++;
  845. goto fail;
  846. }
  847. dev->trans_start = jiffies;
  848. stats->tx_bytes += data_off + data_len;
  849. orinoco_unlock(priv, &flags);
  850. dev_kfree_skb(skb);
  851. TRACE_EXIT(dev->name);
  852. return 0;
  853. fail:
  854. TRACE_EXIT(dev->name);
  855. orinoco_unlock(priv, &flags);
  856. return err;
  857. }
  858. static void __orinoco_ev_alloc(struct net_device *dev, hermes_t *hw)
  859. {
  860. struct orinoco_private *priv = netdev_priv(dev);
  861. u16 fid = hermes_read_regn(hw, ALLOCFID);
  862. if (fid != priv->txfid) {
  863. if (fid != DUMMY_FID)
  864. printk(KERN_WARNING "%s: Allocate event on unexpected fid (%04X)\n",
  865. dev->name, fid);
  866. return;
  867. }
  868. hermes_write_regn(hw, ALLOCFID, DUMMY_FID);
  869. }
  870. static void __orinoco_ev_tx(struct net_device *dev, hermes_t *hw)
  871. {
  872. struct orinoco_private *priv = netdev_priv(dev);
  873. struct net_device_stats *stats = &priv->stats;
  874. stats->tx_packets++;
  875. netif_wake_queue(dev);
  876. hermes_write_regn(hw, TXCOMPLFID, DUMMY_FID);
  877. }
  878. static void __orinoco_ev_txexc(struct net_device *dev, hermes_t *hw)
  879. {
  880. struct orinoco_private *priv = netdev_priv(dev);
  881. struct net_device_stats *stats = &priv->stats;
  882. u16 fid = hermes_read_regn(hw, TXCOMPLFID);
  883. struct hermes_tx_descriptor_802_11 hdr;
  884. int err = 0;
  885. if (fid == DUMMY_FID)
  886. return; /* Nothing's really happened */
  887. /* Read the frame header */
  888. err = hermes_bap_pread(hw, IRQ_BAP, &hdr,
  889. sizeof(struct hermes_tx_descriptor) +
  890. sizeof(struct ieee80211_hdr),
  891. fid, 0);
  892. hermes_write_regn(hw, TXCOMPLFID, DUMMY_FID);
  893. stats->tx_errors++;
  894. if (err) {
  895. printk(KERN_WARNING "%s: Unable to read descriptor on Tx error "
  896. "(FID=%04X error %d)\n",
  897. dev->name, fid, err);
  898. return;
  899. }
  900. DEBUG(1, "%s: Tx error, err %d (FID=%04X)\n", dev->name,
  901. err, fid);
  902. /* We produce a TXDROP event only for retry or lifetime
  903. * exceeded, because that's the only status that really mean
  904. * that this particular node went away.
  905. * Other errors means that *we* screwed up. - Jean II */
  906. hdr.status = le16_to_cpu(hdr.status);
  907. if (hdr.status & (HERMES_TXSTAT_RETRYERR | HERMES_TXSTAT_AGEDERR)) {
  908. union iwreq_data wrqu;
  909. /* Copy 802.11 dest address.
  910. * We use the 802.11 header because the frame may
  911. * not be 802.3 or may be mangled...
  912. * In Ad-Hoc mode, it will be the node address.
  913. * In managed mode, it will be most likely the AP addr
  914. * User space will figure out how to convert it to
  915. * whatever it needs (IP address or else).
  916. * - Jean II */
  917. memcpy(wrqu.addr.sa_data, hdr.addr1, ETH_ALEN);
  918. wrqu.addr.sa_family = ARPHRD_ETHER;
  919. /* Send event to user space */
  920. wireless_send_event(dev, IWEVTXDROP, &wrqu, NULL);
  921. }
  922. netif_wake_queue(dev);
  923. }
  924. static void orinoco_tx_timeout(struct net_device *dev)
  925. {
  926. struct orinoco_private *priv = netdev_priv(dev);
  927. struct net_device_stats *stats = &priv->stats;
  928. struct hermes *hw = &priv->hw;
  929. printk(KERN_WARNING "%s: Tx timeout! "
  930. "ALLOCFID=%04x, TXCOMPLFID=%04x, EVSTAT=%04x\n",
  931. dev->name, hermes_read_regn(hw, ALLOCFID),
  932. hermes_read_regn(hw, TXCOMPLFID), hermes_read_regn(hw, EVSTAT));
  933. stats->tx_errors++;
  934. schedule_work(&priv->reset_work);
  935. }
  936. /********************************************************************/
  937. /* Rx path (data frames) */
  938. /********************************************************************/
  939. /* Does the frame have a SNAP header indicating it should be
  940. * de-encapsulated to Ethernet-II? */
  941. static inline int is_ethersnap(void *_hdr)
  942. {
  943. u8 *hdr = _hdr;
  944. /* We de-encapsulate all packets which, a) have SNAP headers
  945. * (i.e. SSAP=DSAP=0xaa and CTRL=0x3 in the 802.2 LLC header
  946. * and where b) the OUI of the SNAP header is 00:00:00 or
  947. * 00:00:f8 - we need both because different APs appear to use
  948. * different OUIs for some reason */
  949. return (memcmp(hdr, &encaps_hdr, 5) == 0)
  950. && ( (hdr[5] == 0x00) || (hdr[5] == 0xf8) );
  951. }
  952. static inline void orinoco_spy_gather(struct net_device *dev, u_char *mac,
  953. int level, int noise)
  954. {
  955. struct orinoco_private *priv = netdev_priv(dev);
  956. int i;
  957. /* Gather wireless spy statistics: for each packet, compare the
  958. * source address with out list, and if match, get the stats... */
  959. for (i = 0; i < priv->spy_number; i++)
  960. if (!memcmp(mac, priv->spy_address[i], ETH_ALEN)) {
  961. priv->spy_stat[i].level = level - 0x95;
  962. priv->spy_stat[i].noise = noise - 0x95;
  963. priv->spy_stat[i].qual = (level > noise) ? (level - noise) : 0;
  964. priv->spy_stat[i].updated = 7;
  965. }
  966. }
  967. static void orinoco_stat_gather(struct net_device *dev,
  968. struct sk_buff *skb,
  969. struct hermes_rx_descriptor *desc)
  970. {
  971. struct orinoco_private *priv = netdev_priv(dev);
  972. /* Using spy support with lots of Rx packets, like in an
  973. * infrastructure (AP), will really slow down everything, because
  974. * the MAC address must be compared to each entry of the spy list.
  975. * If the user really asks for it (set some address in the
  976. * spy list), we do it, but he will pay the price.
  977. * Note that to get here, you need both WIRELESS_SPY
  978. * compiled in AND some addresses in the list !!!
  979. */
  980. /* Note : gcc will optimise the whole section away if
  981. * WIRELESS_SPY is not defined... - Jean II */
  982. if (SPY_NUMBER(priv)) {
  983. orinoco_spy_gather(dev, skb->mac.raw + ETH_ALEN,
  984. desc->signal, desc->silence);
  985. }
  986. }
  987. static void __orinoco_ev_rx(struct net_device *dev, hermes_t *hw)
  988. {
  989. struct orinoco_private *priv = netdev_priv(dev);
  990. struct net_device_stats *stats = &priv->stats;
  991. struct iw_statistics *wstats = &priv->wstats;
  992. struct sk_buff *skb = NULL;
  993. u16 rxfid, status;
  994. int length, data_len, data_off;
  995. char *p;
  996. struct hermes_rx_descriptor desc;
  997. struct header_struct hdr;
  998. struct ethhdr *eh;
  999. int err;
  1000. rxfid = hermes_read_regn(hw, RXFID);
  1001. err = hermes_bap_pread(hw, IRQ_BAP, &desc, sizeof(desc),
  1002. rxfid, 0);
  1003. if (err) {
  1004. printk(KERN_ERR "%s: error %d reading Rx descriptor. "
  1005. "Frame dropped.\n", dev->name, err);
  1006. stats->rx_errors++;
  1007. goto drop;
  1008. }
  1009. status = le16_to_cpu(desc.status);
  1010. if (status & HERMES_RXSTAT_ERR) {
  1011. if (status & HERMES_RXSTAT_UNDECRYPTABLE) {
  1012. wstats->discard.code++;
  1013. DEBUG(1, "%s: Undecryptable frame on Rx. Frame dropped.\n",
  1014. dev->name);
  1015. } else {
  1016. stats->rx_crc_errors++;
  1017. DEBUG(1, "%s: Bad CRC on Rx. Frame dropped.\n", dev->name);
  1018. }
  1019. stats->rx_errors++;
  1020. goto drop;
  1021. }
  1022. /* For now we ignore the 802.11 header completely, assuming
  1023. that the card's firmware has handled anything vital */
  1024. err = hermes_bap_pread(hw, IRQ_BAP, &hdr, sizeof(hdr),
  1025. rxfid, HERMES_802_3_OFFSET);
  1026. if (err) {
  1027. printk(KERN_ERR "%s: error %d reading frame header. "
  1028. "Frame dropped.\n", dev->name, err);
  1029. stats->rx_errors++;
  1030. goto drop;
  1031. }
  1032. length = ntohs(hdr.len);
  1033. /* Sanity checks */
  1034. if (length < 3) { /* No for even an 802.2 LLC header */
  1035. /* At least on Symbol firmware with PCF we get quite a
  1036. lot of these legitimately - Poll frames with no
  1037. data. */
  1038. stats->rx_dropped++;
  1039. goto drop;
  1040. }
  1041. if (length > IEEE802_11_DATA_LEN) {
  1042. printk(KERN_WARNING "%s: Oversized frame received (%d bytes)\n",
  1043. dev->name, length);
  1044. stats->rx_length_errors++;
  1045. stats->rx_errors++;
  1046. goto drop;
  1047. }
  1048. /* We need space for the packet data itself, plus an ethernet
  1049. header, plus 2 bytes so we can align the IP header on a
  1050. 32bit boundary, plus 1 byte so we can read in odd length
  1051. packets from the card, which has an IO granularity of 16
  1052. bits */
  1053. skb = dev_alloc_skb(length+ETH_HLEN+2+1);
  1054. if (!skb) {
  1055. printk(KERN_WARNING "%s: Can't allocate skb for Rx\n",
  1056. dev->name);
  1057. goto drop;
  1058. }
  1059. skb_reserve(skb, 2); /* This way the IP header is aligned */
  1060. /* Handle decapsulation
  1061. * In most cases, the firmware tell us about SNAP frames.
  1062. * For some reason, the SNAP frames sent by LinkSys APs
  1063. * are not properly recognised by most firmwares.
  1064. * So, check ourselves */
  1065. if (((status & HERMES_RXSTAT_MSGTYPE) == HERMES_RXSTAT_1042) ||
  1066. ((status & HERMES_RXSTAT_MSGTYPE) == HERMES_RXSTAT_TUNNEL) ||
  1067. is_ethersnap(&hdr)) {
  1068. /* These indicate a SNAP within 802.2 LLC within
  1069. 802.11 frame which we'll need to de-encapsulate to
  1070. the original EthernetII frame. */
  1071. if (length < ENCAPS_OVERHEAD) { /* No room for full LLC+SNAP */
  1072. stats->rx_length_errors++;
  1073. goto drop;
  1074. }
  1075. /* Remove SNAP header, reconstruct EthernetII frame */
  1076. data_len = length - ENCAPS_OVERHEAD;
  1077. data_off = HERMES_802_3_OFFSET + sizeof(hdr);
  1078. eh = (struct ethhdr *)skb_put(skb, ETH_HLEN);
  1079. memcpy(eh, &hdr, 2 * ETH_ALEN);
  1080. eh->h_proto = hdr.ethertype;
  1081. } else {
  1082. /* All other cases indicate a genuine 802.3 frame. No
  1083. decapsulation needed. We just throw the whole
  1084. thing in, and hope the protocol layer can deal with
  1085. it as 802.3 */
  1086. data_len = length;
  1087. data_off = HERMES_802_3_OFFSET;
  1088. /* FIXME: we re-read from the card data we already read here */
  1089. }
  1090. p = skb_put(skb, data_len);
  1091. err = hermes_bap_pread(hw, IRQ_BAP, p, ALIGN(data_len, 2),
  1092. rxfid, data_off);
  1093. if (err) {
  1094. printk(KERN_ERR "%s: error %d reading frame. "
  1095. "Frame dropped.\n", dev->name, err);
  1096. stats->rx_errors++;
  1097. goto drop;
  1098. }
  1099. dev->last_rx = jiffies;
  1100. skb->dev = dev;
  1101. skb->protocol = eth_type_trans(skb, dev);
  1102. skb->ip_summed = CHECKSUM_NONE;
  1103. /* Process the wireless stats if needed */
  1104. orinoco_stat_gather(dev, skb, &desc);
  1105. /* Pass the packet to the networking stack */
  1106. netif_rx(skb);
  1107. stats->rx_packets++;
  1108. stats->rx_bytes += length;
  1109. return;
  1110. drop:
  1111. stats->rx_dropped++;
  1112. if (skb)
  1113. dev_kfree_skb_irq(skb);
  1114. return;
  1115. }
  1116. /********************************************************************/
  1117. /* Rx path (info frames) */
  1118. /********************************************************************/
  1119. static void print_linkstatus(struct net_device *dev, u16 status)
  1120. {
  1121. char * s;
  1122. if (suppress_linkstatus)
  1123. return;
  1124. switch (status) {
  1125. case HERMES_LINKSTATUS_NOT_CONNECTED:
  1126. s = "Not Connected";
  1127. break;
  1128. case HERMES_LINKSTATUS_CONNECTED:
  1129. s = "Connected";
  1130. break;
  1131. case HERMES_LINKSTATUS_DISCONNECTED:
  1132. s = "Disconnected";
  1133. break;
  1134. case HERMES_LINKSTATUS_AP_CHANGE:
  1135. s = "AP Changed";
  1136. break;
  1137. case HERMES_LINKSTATUS_AP_OUT_OF_RANGE:
  1138. s = "AP Out of Range";
  1139. break;
  1140. case HERMES_LINKSTATUS_AP_IN_RANGE:
  1141. s = "AP In Range";
  1142. break;
  1143. case HERMES_LINKSTATUS_ASSOC_FAILED:
  1144. s = "Association Failed";
  1145. break;
  1146. default:
  1147. s = "UNKNOWN";
  1148. }
  1149. printk(KERN_INFO "%s: New link status: %s (%04x)\n",
  1150. dev->name, s, status);
  1151. }
  1152. /* Search scan results for requested BSSID, join it if found */
  1153. static void orinoco_join_ap(struct net_device *dev)
  1154. {
  1155. struct orinoco_private *priv = netdev_priv(dev);
  1156. struct hermes *hw = &priv->hw;
  1157. int err;
  1158. unsigned long flags;
  1159. struct join_req {
  1160. u8 bssid[ETH_ALEN];
  1161. u16 channel;
  1162. } __attribute__ ((packed)) req;
  1163. const int atom_len = offsetof(struct prism2_scan_apinfo, atim);
  1164. struct prism2_scan_apinfo *atom;
  1165. int offset = 4;
  1166. u8 *buf;
  1167. u16 len;
  1168. /* Allocate buffer for scan results */
  1169. buf = kmalloc(MAX_SCAN_LEN, GFP_KERNEL);
  1170. if (! buf)
  1171. return;
  1172. if (orinoco_lock(priv, &flags) != 0)
  1173. goto out;
  1174. /* Sanity checks in case user changed something in the meantime */
  1175. if (! priv->bssid_fixed)
  1176. goto out;
  1177. if (strlen(priv->desired_essid) == 0)
  1178. goto out;
  1179. /* Read scan results from the firmware */
  1180. err = hermes_read_ltv(hw, USER_BAP,
  1181. HERMES_RID_SCANRESULTSTABLE,
  1182. MAX_SCAN_LEN, &len, buf);
  1183. if (err) {
  1184. printk(KERN_ERR "%s: Cannot read scan results\n",
  1185. dev->name);
  1186. goto out;
  1187. }
  1188. len = HERMES_RECLEN_TO_BYTES(len);
  1189. /* Go through the scan results looking for the channel of the AP
  1190. * we were requested to join */
  1191. for (; offset + atom_len <= len; offset += atom_len) {
  1192. atom = (struct prism2_scan_apinfo *) (buf + offset);
  1193. if (memcmp(&atom->bssid, priv->desired_bssid, ETH_ALEN) == 0)
  1194. goto found;
  1195. }
  1196. DEBUG(1, "%s: Requested AP not found in scan results\n",
  1197. dev->name);
  1198. goto out;
  1199. found:
  1200. memcpy(req.bssid, priv->desired_bssid, ETH_ALEN);
  1201. req.channel = atom->channel; /* both are little-endian */
  1202. err = HERMES_WRITE_RECORD(hw, USER_BAP, HERMES_RID_CNFJOINREQUEST,
  1203. &req);
  1204. if (err)
  1205. printk(KERN_ERR "%s: Error issuing join request\n", dev->name);
  1206. out:
  1207. kfree(buf);
  1208. orinoco_unlock(priv, &flags);
  1209. }
  1210. /* Send new BSSID to userspace */
  1211. static void orinoco_send_wevents(struct net_device *dev)
  1212. {
  1213. struct orinoco_private *priv = netdev_priv(dev);
  1214. struct hermes *hw = &priv->hw;
  1215. union iwreq_data wrqu;
  1216. int err;
  1217. unsigned long flags;
  1218. if (orinoco_lock(priv, &flags) != 0)
  1219. return;
  1220. err = hermes_read_ltv(hw, IRQ_BAP, HERMES_RID_CURRENTBSSID,
  1221. ETH_ALEN, NULL, wrqu.ap_addr.sa_data);
  1222. if (err != 0)
  1223. return;
  1224. wrqu.ap_addr.sa_family = ARPHRD_ETHER;
  1225. /* Send event to user space */
  1226. wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL);
  1227. orinoco_unlock(priv, &flags);
  1228. }
  1229. static void __orinoco_ev_info(struct net_device *dev, hermes_t *hw)
  1230. {
  1231. struct orinoco_private *priv = netdev_priv(dev);
  1232. u16 infofid;
  1233. struct {
  1234. u16 len;
  1235. u16 type;
  1236. } __attribute__ ((packed)) info;
  1237. int len, type;
  1238. int err;
  1239. /* This is an answer to an INQUIRE command that we did earlier,
  1240. * or an information "event" generated by the card
  1241. * The controller return to us a pseudo frame containing
  1242. * the information in question - Jean II */
  1243. infofid = hermes_read_regn(hw, INFOFID);
  1244. /* Read the info frame header - don't try too hard */
  1245. err = hermes_bap_pread(hw, IRQ_BAP, &info, sizeof(info),
  1246. infofid, 0);
  1247. if (err) {
  1248. printk(KERN_ERR "%s: error %d reading info frame. "
  1249. "Frame dropped.\n", dev->name, err);
  1250. return;
  1251. }
  1252. len = HERMES_RECLEN_TO_BYTES(le16_to_cpu(info.len));
  1253. type = le16_to_cpu(info.type);
  1254. switch (type) {
  1255. case HERMES_INQ_TALLIES: {
  1256. struct hermes_tallies_frame tallies;
  1257. struct iw_statistics *wstats = &priv->wstats;
  1258. if (len > sizeof(tallies)) {
  1259. printk(KERN_WARNING "%s: Tallies frame too long (%d bytes)\n",
  1260. dev->name, len);
  1261. len = sizeof(tallies);
  1262. }
  1263. err = hermes_bap_pread(hw, IRQ_BAP, &tallies, len,
  1264. infofid, sizeof(info));
  1265. if (err)
  1266. break;
  1267. /* Increment our various counters */
  1268. /* wstats->discard.nwid - no wrong BSSID stuff */
  1269. wstats->discard.code +=
  1270. le16_to_cpu(tallies.RxWEPUndecryptable);
  1271. if (len == sizeof(tallies))
  1272. wstats->discard.code +=
  1273. le16_to_cpu(tallies.RxDiscards_WEPICVError) +
  1274. le16_to_cpu(tallies.RxDiscards_WEPExcluded);
  1275. wstats->discard.misc +=
  1276. le16_to_cpu(tallies.TxDiscardsWrongSA);
  1277. wstats->discard.fragment +=
  1278. le16_to_cpu(tallies.RxMsgInBadMsgFragments);
  1279. wstats->discard.retries +=
  1280. le16_to_cpu(tallies.TxRetryLimitExceeded);
  1281. /* wstats->miss.beacon - no match */
  1282. }
  1283. break;
  1284. case HERMES_INQ_LINKSTATUS: {
  1285. struct hermes_linkstatus linkstatus;
  1286. u16 newstatus;
  1287. int connected;
  1288. if (len != sizeof(linkstatus)) {
  1289. printk(KERN_WARNING "%s: Unexpected size for linkstatus frame (%d bytes)\n",
  1290. dev->name, len);
  1291. break;
  1292. }
  1293. err = hermes_bap_pread(hw, IRQ_BAP, &linkstatus, len,
  1294. infofid, sizeof(info));
  1295. if (err)
  1296. break;
  1297. newstatus = le16_to_cpu(linkstatus.linkstatus);
  1298. /* Symbol firmware uses "out of range" to signal that
  1299. * the hostscan frame can be requested. */
  1300. if (newstatus == HERMES_LINKSTATUS_AP_OUT_OF_RANGE &&
  1301. priv->firmware_type == FIRMWARE_TYPE_SYMBOL &&
  1302. priv->has_hostscan && priv->scan_inprogress) {
  1303. hermes_inquire(hw, HERMES_INQ_HOSTSCAN_SYMBOL);
  1304. break;
  1305. }
  1306. connected = (newstatus == HERMES_LINKSTATUS_CONNECTED)
  1307. || (newstatus == HERMES_LINKSTATUS_AP_CHANGE)
  1308. || (newstatus == HERMES_LINKSTATUS_AP_IN_RANGE);
  1309. if (connected)
  1310. netif_carrier_on(dev);
  1311. else if (!ignore_disconnect)
  1312. netif_carrier_off(dev);
  1313. if (newstatus != priv->last_linkstatus) {
  1314. priv->last_linkstatus = newstatus;
  1315. print_linkstatus(dev, newstatus);
  1316. /* The info frame contains only one word which is the
  1317. * status (see hermes.h). The status is pretty boring
  1318. * in itself, that's why we export the new BSSID...
  1319. * Jean II */
  1320. schedule_work(&priv->wevent_work);
  1321. }
  1322. }
  1323. break;
  1324. case HERMES_INQ_SCAN:
  1325. if (!priv->scan_inprogress && priv->bssid_fixed &&
  1326. priv->firmware_type == FIRMWARE_TYPE_INTERSIL) {
  1327. schedule_work(&priv->join_work);
  1328. break;
  1329. }
  1330. /* fall through */
  1331. case HERMES_INQ_HOSTSCAN:
  1332. case HERMES_INQ_HOSTSCAN_SYMBOL: {
  1333. /* Result of a scanning. Contains information about
  1334. * cells in the vicinity - Jean II */
  1335. union iwreq_data wrqu;
  1336. unsigned char *buf;
  1337. /* Sanity check */
  1338. if (len > 4096) {
  1339. printk(KERN_WARNING "%s: Scan results too large (%d bytes)\n",
  1340. dev->name, len);
  1341. break;
  1342. }
  1343. /* We are a strict producer. If the previous scan results
  1344. * have not been consumed, we just have to drop this
  1345. * frame. We can't remove the previous results ourselves,
  1346. * that would be *very* racy... Jean II */
  1347. if (priv->scan_result != NULL) {
  1348. printk(KERN_WARNING "%s: Previous scan results not consumed, dropping info frame.\n", dev->name);
  1349. break;
  1350. }
  1351. /* Allocate buffer for results */
  1352. buf = kmalloc(len, GFP_ATOMIC);
  1353. if (buf == NULL)
  1354. /* No memory, so can't printk()... */
  1355. break;
  1356. /* Read scan data */
  1357. err = hermes_bap_pread(hw, IRQ_BAP, (void *) buf, len,
  1358. infofid, sizeof(info));
  1359. if (err)
  1360. break;
  1361. #ifdef ORINOCO_DEBUG
  1362. {
  1363. int i;
  1364. printk(KERN_DEBUG "Scan result [%02X", buf[0]);
  1365. for(i = 1; i < (len * 2); i++)
  1366. printk(":%02X", buf[i]);
  1367. printk("]\n");
  1368. }
  1369. #endif /* ORINOCO_DEBUG */
  1370. /* Allow the clients to access the results */
  1371. priv->scan_len = len;
  1372. priv->scan_result = buf;
  1373. /* Send an empty event to user space.
  1374. * We don't send the received data on the event because
  1375. * it would require us to do complex transcoding, and
  1376. * we want to minimise the work done in the irq handler
  1377. * Use a request to extract the data - Jean II */
  1378. wrqu.data.length = 0;
  1379. wrqu.data.flags = 0;
  1380. wireless_send_event(dev, SIOCGIWSCAN, &wrqu, NULL);
  1381. }
  1382. break;
  1383. case HERMES_INQ_SEC_STAT_AGERE:
  1384. /* Security status (Agere specific) */
  1385. /* Ignore this frame for now */
  1386. if (priv->firmware_type == FIRMWARE_TYPE_AGERE)
  1387. break;
  1388. /* fall through */
  1389. default:
  1390. printk(KERN_DEBUG "%s: Unknown information frame received: "
  1391. "type 0x%04x, length %d\n", dev->name, type, len);
  1392. /* We don't actually do anything about it */
  1393. break;
  1394. }
  1395. }
  1396. static void __orinoco_ev_infdrop(struct net_device *dev, hermes_t *hw)
  1397. {
  1398. if (net_ratelimit())
  1399. printk(KERN_DEBUG "%s: Information frame lost.\n", dev->name);
  1400. }
  1401. /********************************************************************/
  1402. /* Internal hardware control routines */
  1403. /********************************************************************/
  1404. int __orinoco_up(struct net_device *dev)
  1405. {
  1406. struct orinoco_private *priv = netdev_priv(dev);
  1407. struct hermes *hw = &priv->hw;
  1408. int err;
  1409. netif_carrier_off(dev); /* just to make sure */
  1410. err = __orinoco_program_rids(dev);
  1411. if (err) {
  1412. printk(KERN_ERR "%s: Error %d configuring card\n",
  1413. dev->name, err);
  1414. return err;
  1415. }
  1416. /* Fire things up again */
  1417. hermes_set_irqmask(hw, ORINOCO_INTEN);
  1418. err = hermes_enable_port(hw, 0);
  1419. if (err) {
  1420. printk(KERN_ERR "%s: Error %d enabling MAC port\n",
  1421. dev->name, err);
  1422. return err;
  1423. }
  1424. netif_start_queue(dev);
  1425. return 0;
  1426. }
  1427. int __orinoco_down(struct net_device *dev)
  1428. {
  1429. struct orinoco_private *priv = netdev_priv(dev);
  1430. struct hermes *hw = &priv->hw;
  1431. int err;
  1432. netif_stop_queue(dev);
  1433. if (! priv->hw_unavailable) {
  1434. if (! priv->broken_disableport) {
  1435. err = hermes_disable_port(hw, 0);
  1436. if (err) {
  1437. /* Some firmwares (e.g. Intersil 1.3.x) seem
  1438. * to have problems disabling the port, oh
  1439. * well, too bad. */
  1440. printk(KERN_WARNING "%s: Error %d disabling MAC port\n",
  1441. dev->name, err);
  1442. priv->broken_disableport = 1;
  1443. }
  1444. }
  1445. hermes_set_irqmask(hw, 0);
  1446. hermes_write_regn(hw, EVACK, 0xffff);
  1447. }
  1448. /* firmware will have to reassociate */
  1449. netif_carrier_off(dev);
  1450. priv->last_linkstatus = 0xffff;
  1451. return 0;
  1452. }
  1453. int orinoco_reinit_firmware(struct net_device *dev)
  1454. {
  1455. struct orinoco_private *priv = netdev_priv(dev);
  1456. struct hermes *hw = &priv->hw;
  1457. int err;
  1458. err = hermes_init(hw);
  1459. if (err)
  1460. return err;
  1461. err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid);
  1462. if (err == -EIO && priv->nicbuf_size > TX_NICBUF_SIZE_BUG) {
  1463. /* Try workaround for old Symbol firmware bug */
  1464. printk(KERN_WARNING "%s: firmware ALLOC bug detected "
  1465. "(old Symbol firmware?). Trying to work around... ",
  1466. dev->name);
  1467. priv->nicbuf_size = TX_NICBUF_SIZE_BUG;
  1468. err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid);
  1469. if (err)
  1470. printk("failed!\n");
  1471. else
  1472. printk("ok.\n");
  1473. }
  1474. return err;
  1475. }
  1476. static int __orinoco_hw_set_bitrate(struct orinoco_private *priv)
  1477. {
  1478. hermes_t *hw = &priv->hw;
  1479. int err = 0;
  1480. if (priv->bitratemode >= BITRATE_TABLE_SIZE) {
  1481. printk(KERN_ERR "%s: BUG: Invalid bitrate mode %d\n",
  1482. priv->ndev->name, priv->bitratemode);
  1483. return -EINVAL;
  1484. }
  1485. switch (priv->firmware_type) {
  1486. case FIRMWARE_TYPE_AGERE:
  1487. err = hermes_write_wordrec(hw, USER_BAP,
  1488. HERMES_RID_CNFTXRATECONTROL,
  1489. bitrate_table[priv->bitratemode].agere_txratectrl);
  1490. break;
  1491. case FIRMWARE_TYPE_INTERSIL:
  1492. case FIRMWARE_TYPE_SYMBOL:
  1493. err = hermes_write_wordrec(hw, USER_BAP,
  1494. HERMES_RID_CNFTXRATECONTROL,
  1495. bitrate_table[priv->bitratemode].intersil_txratectrl);
  1496. break;
  1497. default:
  1498. BUG();
  1499. }
  1500. return err;
  1501. }
  1502. /* Set fixed AP address */
  1503. static int __orinoco_hw_set_wap(struct orinoco_private *priv)
  1504. {
  1505. int roaming_flag;
  1506. int err = 0;
  1507. hermes_t *hw = &priv->hw;
  1508. switch (priv->firmware_type) {
  1509. case FIRMWARE_TYPE_AGERE:
  1510. /* not supported */
  1511. break;
  1512. case FIRMWARE_TYPE_INTERSIL:
  1513. if (priv->bssid_fixed)
  1514. roaming_flag = 2;
  1515. else
  1516. roaming_flag = 1;
  1517. err = hermes_write_wordrec(hw, USER_BAP,
  1518. HERMES_RID_CNFROAMINGMODE,
  1519. roaming_flag);
  1520. break;
  1521. case FIRMWARE_TYPE_SYMBOL:
  1522. err = HERMES_WRITE_RECORD(hw, USER_BAP,
  1523. HERMES_RID_CNFMANDATORYBSSID_SYMBOL,
  1524. &priv->desired_bssid);
  1525. break;
  1526. }
  1527. return err;
  1528. }
  1529. /* Change the WEP keys and/or the current keys. Can be called
  1530. * either from __orinoco_hw_setup_wep() or directly from
  1531. * orinoco_ioctl_setiwencode(). In the later case the association
  1532. * with the AP is not broken (if the firmware can handle it),
  1533. * which is needed for 802.1x implementations. */
  1534. static int __orinoco_hw_setup_wepkeys(struct orinoco_private *priv)
  1535. {
  1536. hermes_t *hw = &priv->hw;
  1537. int err = 0;
  1538. switch (priv->firmware_type) {
  1539. case FIRMWARE_TYPE_AGERE:
  1540. err = HERMES_WRITE_RECORD(hw, USER_BAP,
  1541. HERMES_RID_CNFWEPKEYS_AGERE,
  1542. &priv->keys);
  1543. if (err)
  1544. return err;
  1545. err = hermes_write_wordrec(hw, USER_BAP,
  1546. HERMES_RID_CNFTXKEY_AGERE,
  1547. priv->tx_key);
  1548. if (err)
  1549. return err;
  1550. break;
  1551. case FIRMWARE_TYPE_INTERSIL:
  1552. case FIRMWARE_TYPE_SYMBOL:
  1553. {
  1554. int keylen;
  1555. int i;
  1556. /* Force uniform key length to work around firmware bugs */
  1557. keylen = le16_to_cpu(priv->keys[priv->tx_key].len);
  1558. if (keylen > LARGE_KEY_SIZE) {
  1559. printk(KERN_ERR "%s: BUG: Key %d has oversize length %d.\n",
  1560. priv->ndev->name, priv->tx_key, keylen);
  1561. return -E2BIG;
  1562. }
  1563. /* Write all 4 keys */
  1564. for(i = 0; i < ORINOCO_MAX_KEYS; i++) {
  1565. err = hermes_write_ltv(hw, USER_BAP,
  1566. HERMES_RID_CNFDEFAULTKEY0 + i,
  1567. HERMES_BYTES_TO_RECLEN(keylen),
  1568. priv->keys[i].data);
  1569. if (err)
  1570. return err;
  1571. }
  1572. /* Write the index of the key used in transmission */
  1573. err = hermes_write_wordrec(hw, USER_BAP,
  1574. HERMES_RID_CNFWEPDEFAULTKEYID,
  1575. priv->tx_key);
  1576. if (err)
  1577. return err;
  1578. }
  1579. break;
  1580. }
  1581. return 0;
  1582. }
  1583. static int __orinoco_hw_setup_wep(struct orinoco_private *priv)
  1584. {
  1585. hermes_t *hw = &priv->hw;
  1586. int err = 0;
  1587. int master_wep_flag;
  1588. int auth_flag;
  1589. if (priv->wep_on)
  1590. __orinoco_hw_setup_wepkeys(priv);
  1591. if (priv->wep_restrict)
  1592. auth_flag = HERMES_AUTH_SHARED_KEY;
  1593. else
  1594. auth_flag = HERMES_AUTH_OPEN;
  1595. switch (priv->firmware_type) {
  1596. case FIRMWARE_TYPE_AGERE: /* Agere style WEP */
  1597. if (priv->wep_on) {
  1598. /* Enable the shared-key authentication. */
  1599. err = hermes_write_wordrec(hw, USER_BAP,
  1600. HERMES_RID_CNFAUTHENTICATION_AGERE,
  1601. auth_flag);
  1602. }
  1603. err = hermes_write_wordrec(hw, USER_BAP,
  1604. HERMES_RID_CNFWEPENABLED_AGERE,
  1605. priv->wep_on);
  1606. if (err)
  1607. return err;
  1608. break;
  1609. case FIRMWARE_TYPE_INTERSIL: /* Intersil style WEP */
  1610. case FIRMWARE_TYPE_SYMBOL: /* Symbol style WEP */
  1611. if (priv->wep_on) {
  1612. if (priv->wep_restrict ||
  1613. (priv->firmware_type == FIRMWARE_TYPE_SYMBOL))
  1614. master_wep_flag = HERMES_WEP_PRIVACY_INVOKED |
  1615. HERMES_WEP_EXCL_UNENCRYPTED;
  1616. else
  1617. master_wep_flag = HERMES_WEP_PRIVACY_INVOKED;
  1618. err = hermes_write_wordrec(hw, USER_BAP,
  1619. HERMES_RID_CNFAUTHENTICATION,
  1620. auth_flag);
  1621. if (err)
  1622. return err;
  1623. } else
  1624. master_wep_flag = 0;
  1625. if (priv->iw_mode == IW_MODE_MONITOR)
  1626. master_wep_flag |= HERMES_WEP_HOST_DECRYPT;
  1627. /* Master WEP setting : on/off */
  1628. err = hermes_write_wordrec(hw, USER_BAP,
  1629. HERMES_RID_CNFWEPFLAGS_INTERSIL,
  1630. master_wep_flag);
  1631. if (err)
  1632. return err;
  1633. break;
  1634. }
  1635. return 0;
  1636. }
  1637. static int __orinoco_program_rids(struct net_device *dev)
  1638. {
  1639. struct orinoco_private *priv = netdev_priv(dev);
  1640. hermes_t *hw = &priv->hw;
  1641. int err;
  1642. struct hermes_idstring idbuf;
  1643. /* Set the MAC address */
  1644. err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNMACADDR,
  1645. HERMES_BYTES_TO_RECLEN(ETH_ALEN), dev->dev_addr);
  1646. if (err) {
  1647. printk(KERN_ERR "%s: Error %d setting MAC address\n",
  1648. dev->name, err);
  1649. return err;
  1650. }
  1651. /* Set up the link mode */
  1652. err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFPORTTYPE,
  1653. priv->port_type);
  1654. if (err) {
  1655. printk(KERN_ERR "%s: Error %d setting port type\n",
  1656. dev->name, err);
  1657. return err;
  1658. }
  1659. /* Set the channel/frequency */
  1660. if (priv->channel != 0 && priv->iw_mode != IW_MODE_INFRA) {
  1661. err = hermes_write_wordrec(hw, USER_BAP,
  1662. HERMES_RID_CNFOWNCHANNEL,
  1663. priv->channel);
  1664. if (err) {
  1665. printk(KERN_ERR "%s: Error %d setting channel %d\n",
  1666. dev->name, err, priv->channel);
  1667. return err;
  1668. }
  1669. }
  1670. if (priv->has_ibss) {
  1671. u16 createibss;
  1672. if ((strlen(priv->desired_essid) == 0) && (priv->createibss)) {
  1673. printk(KERN_WARNING "%s: This firmware requires an "
  1674. "ESSID in IBSS-Ad-Hoc mode.\n", dev->name);
  1675. /* With wvlan_cs, in this case, we would crash.
  1676. * hopefully, this driver will behave better...
  1677. * Jean II */
  1678. createibss = 0;
  1679. } else {
  1680. createibss = priv->createibss;
  1681. }
  1682. err = hermes_write_wordrec(hw, USER_BAP,
  1683. HERMES_RID_CNFCREATEIBSS,
  1684. createibss);
  1685. if (err) {
  1686. printk(KERN_ERR "%s: Error %d setting CREATEIBSS\n",
  1687. dev->name, err);
  1688. return err;
  1689. }
  1690. }
  1691. /* Set the desired BSSID */
  1692. err = __orinoco_hw_set_wap(priv);
  1693. if (err) {
  1694. printk(KERN_ERR "%s: Error %d setting AP address\n",
  1695. dev->name, err);
  1696. return err;
  1697. }
  1698. /* Set the desired ESSID */
  1699. idbuf.len = cpu_to_le16(strlen(priv->desired_essid));
  1700. memcpy(&idbuf.val, priv->desired_essid, sizeof(idbuf.val));
  1701. /* WinXP wants partner to configure OWNSSID even in IBSS mode. (jimc) */
  1702. err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNSSID,
  1703. HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid)+2),
  1704. &idbuf);
  1705. if (err) {
  1706. printk(KERN_ERR "%s: Error %d setting OWNSSID\n",
  1707. dev->name, err);
  1708. return err;
  1709. }
  1710. err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFDESIREDSSID,
  1711. HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid)+2),
  1712. &idbuf);
  1713. if (err) {
  1714. printk(KERN_ERR "%s: Error %d setting DESIREDSSID\n",
  1715. dev->name, err);
  1716. return err;
  1717. }
  1718. /* Set the station name */
  1719. idbuf.len = cpu_to_le16(strlen(priv->nick));
  1720. memcpy(&idbuf.val, priv->nick, sizeof(idbuf.val));
  1721. err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNNAME,
  1722. HERMES_BYTES_TO_RECLEN(strlen(priv->nick)+2),
  1723. &idbuf);
  1724. if (err) {
  1725. printk(KERN_ERR "%s: Error %d setting nickname\n",
  1726. dev->name, err);
  1727. return err;
  1728. }
  1729. /* Set AP density */
  1730. if (priv->has_sensitivity) {
  1731. err = hermes_write_wordrec(hw, USER_BAP,
  1732. HERMES_RID_CNFSYSTEMSCALE,
  1733. priv->ap_density);
  1734. if (err) {
  1735. printk(KERN_WARNING "%s: Error %d setting SYSTEMSCALE. "
  1736. "Disabling sensitivity control\n",
  1737. dev->name, err);
  1738. priv->has_sensitivity = 0;
  1739. }
  1740. }
  1741. /* Set RTS threshold */
  1742. err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFRTSTHRESHOLD,
  1743. priv->rts_thresh);
  1744. if (err) {
  1745. printk(KERN_ERR "%s: Error %d setting RTS threshold\n",
  1746. dev->name, err);
  1747. return err;
  1748. }
  1749. /* Set fragmentation threshold or MWO robustness */
  1750. if (priv->has_mwo)
  1751. err = hermes_write_wordrec(hw, USER_BAP,
  1752. HERMES_RID_CNFMWOROBUST_AGERE,
  1753. priv->mwo_robust);
  1754. else
  1755. err = hermes_write_wordrec(hw, USER_BAP,
  1756. HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
  1757. priv->frag_thresh);
  1758. if (err) {
  1759. printk(KERN_ERR "%s: Error %d setting fragmentation\n",
  1760. dev->name, err);
  1761. return err;
  1762. }
  1763. /* Set bitrate */
  1764. err = __orinoco_hw_set_bitrate(priv);
  1765. if (err) {
  1766. printk(KERN_ERR "%s: Error %d setting bitrate\n",
  1767. dev->name, err);
  1768. return err;
  1769. }
  1770. /* Set power management */
  1771. if (priv->has_pm) {
  1772. err = hermes_write_wordrec(hw, USER_BAP,
  1773. HERMES_RID_CNFPMENABLED,
  1774. priv->pm_on);
  1775. if (err) {
  1776. printk(KERN_ERR "%s: Error %d setting up PM\n",
  1777. dev->name, err);
  1778. return err;
  1779. }
  1780. err = hermes_write_wordrec(hw, USER_BAP,
  1781. HERMES_RID_CNFMULTICASTRECEIVE,
  1782. priv->pm_mcast);
  1783. if (err) {
  1784. printk(KERN_ERR "%s: Error %d setting up PM\n",
  1785. dev->name, err);
  1786. return err;
  1787. }
  1788. err = hermes_write_wordrec(hw, USER_BAP,
  1789. HERMES_RID_CNFMAXSLEEPDURATION,
  1790. priv->pm_period);
  1791. if (err) {
  1792. printk(KERN_ERR "%s: Error %d setting up PM\n",
  1793. dev->name, err);
  1794. return err;
  1795. }
  1796. err = hermes_write_wordrec(hw, USER_BAP,
  1797. HERMES_RID_CNFPMHOLDOVERDURATION,
  1798. priv->pm_timeout);
  1799. if (err) {
  1800. printk(KERN_ERR "%s: Error %d setting up PM\n",
  1801. dev->name, err);
  1802. return err;
  1803. }
  1804. }
  1805. /* Set preamble - only for Symbol so far... */
  1806. if (priv->has_preamble) {
  1807. err = hermes_write_wordrec(hw, USER_BAP,
  1808. HERMES_RID_CNFPREAMBLE_SYMBOL,
  1809. priv->preamble);
  1810. if (err) {
  1811. printk(KERN_ERR "%s: Error %d setting preamble\n",
  1812. dev->name, err);
  1813. return err;
  1814. }
  1815. }
  1816. /* Set up encryption */
  1817. if (priv->has_wep) {
  1818. err = __orinoco_hw_setup_wep(priv);
  1819. if (err) {
  1820. printk(KERN_ERR "%s: Error %d activating WEP\n",
  1821. dev->name, err);
  1822. return err;
  1823. }
  1824. }
  1825. /* Set promiscuity / multicast*/
  1826. priv->promiscuous = 0;
  1827. priv->mc_count = 0;
  1828. __orinoco_set_multicast_list(dev); /* FIXME: what about the xmit_lock */
  1829. return 0;
  1830. }
  1831. /* FIXME: return int? */
  1832. static void
  1833. __orinoco_set_multicast_list(struct net_device *dev)
  1834. {
  1835. struct orinoco_private *priv = netdev_priv(dev);
  1836. hermes_t *hw = &priv->hw;
  1837. int err = 0;
  1838. int promisc, mc_count;
  1839. /* The Hermes doesn't seem to have an allmulti mode, so we go
  1840. * into promiscuous mode and let the upper levels deal. */
  1841. if ( (dev->flags & IFF_PROMISC) || (dev->flags & IFF_ALLMULTI) ||
  1842. (dev->mc_count > MAX_MULTICAST(priv)) ) {
  1843. promisc = 1;
  1844. mc_count = 0;
  1845. } else {
  1846. promisc = 0;
  1847. mc_count = dev->mc_count;
  1848. }
  1849. if (promisc != priv->promiscuous) {
  1850. err = hermes_write_wordrec(hw, USER_BAP,
  1851. HERMES_RID_CNFPROMISCUOUSMODE,
  1852. promisc);
  1853. if (err) {
  1854. printk(KERN_ERR "%s: Error %d setting PROMISCUOUSMODE to 1.\n",
  1855. dev->name, err);
  1856. } else
  1857. priv->promiscuous = promisc;
  1858. }
  1859. if (! promisc && (mc_count || priv->mc_count) ) {
  1860. struct dev_mc_list *p = dev->mc_list;
  1861. struct hermes_multicast mclist;
  1862. int i;
  1863. for (i = 0; i < mc_count; i++) {
  1864. /* paranoia: is list shorter than mc_count? */
  1865. BUG_ON(! p);
  1866. /* paranoia: bad address size in list? */
  1867. BUG_ON(p->dmi_addrlen != ETH_ALEN);
  1868. memcpy(mclist.addr[i], p->dmi_addr, ETH_ALEN);
  1869. p = p->next;
  1870. }
  1871. if (p)
  1872. printk(KERN_WARNING "%s: Multicast list is "
  1873. "longer than mc_count\n", dev->name);
  1874. err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFGROUPADDRESSES,
  1875. HERMES_BYTES_TO_RECLEN(priv->mc_count * ETH_ALEN),
  1876. &mclist);
  1877. if (err)
  1878. printk(KERN_ERR "%s: Error %d setting multicast list.\n",
  1879. dev->name, err);
  1880. else
  1881. priv->mc_count = mc_count;
  1882. }
  1883. /* Since we can set the promiscuous flag when it wasn't asked
  1884. for, make sure the net_device knows about it. */
  1885. if (priv->promiscuous)
  1886. dev->flags |= IFF_PROMISC;
  1887. else
  1888. dev->flags &= ~IFF_PROMISC;
  1889. }
  1890. /* This must be called from user context, without locks held - use
  1891. * schedule_work() */
  1892. static void orinoco_reset(struct net_device *dev)
  1893. {
  1894. struct orinoco_private *priv = netdev_priv(dev);
  1895. struct hermes *hw = &priv->hw;
  1896. int err;
  1897. unsigned long flags;
  1898. if (orinoco_lock(priv, &flags) != 0)
  1899. /* When the hardware becomes available again, whatever
  1900. * detects that is responsible for re-initializing
  1901. * it. So no need for anything further */
  1902. return;
  1903. netif_stop_queue(dev);
  1904. /* Shut off interrupts. Depending on what state the hardware
  1905. * is in, this might not work, but we'll try anyway */
  1906. hermes_set_irqmask(hw, 0);
  1907. hermes_write_regn(hw, EVACK, 0xffff);
  1908. priv->hw_unavailable++;
  1909. priv->last_linkstatus = 0xffff; /* firmware will have to reassociate */
  1910. netif_carrier_off(dev);
  1911. orinoco_unlock(priv, &flags);
  1912. /* Scanning support: Cleanup of driver struct */
  1913. kfree(priv->scan_result);
  1914. priv->scan_result = NULL;
  1915. priv->scan_inprogress = 0;
  1916. if (priv->hard_reset) {
  1917. err = (*priv->hard_reset)(priv);
  1918. if (err) {
  1919. printk(KERN_ERR "%s: orinoco_reset: Error %d "
  1920. "performing hard reset\n", dev->name, err);
  1921. goto disable;
  1922. }
  1923. }
  1924. err = orinoco_reinit_firmware(dev);
  1925. if (err) {
  1926. printk(KERN_ERR "%s: orinoco_reset: Error %d re-initializing firmware\n",
  1927. dev->name, err);
  1928. goto disable;
  1929. }
  1930. spin_lock_irq(&priv->lock); /* This has to be called from user context */
  1931. priv->hw_unavailable--;
  1932. /* priv->open or priv->hw_unavailable might have changed while
  1933. * we dropped the lock */
  1934. if (priv->open && (! priv->hw_unavailable)) {
  1935. err = __orinoco_up(dev);
  1936. if (err) {
  1937. printk(KERN_ERR "%s: orinoco_reset: Error %d reenabling card\n",
  1938. dev->name, err);
  1939. } else
  1940. dev->trans_start = jiffies;
  1941. }
  1942. spin_unlock_irq(&priv->lock);
  1943. return;
  1944. disable:
  1945. hermes_set_irqmask(hw, 0);
  1946. netif_device_detach(dev);
  1947. printk(KERN_ERR "%s: Device has been disabled!\n", dev->name);
  1948. }
  1949. /********************************************************************/
  1950. /* Interrupt handler */
  1951. /********************************************************************/
  1952. static void __orinoco_ev_tick(struct net_device *dev, hermes_t *hw)
  1953. {
  1954. printk(KERN_DEBUG "%s: TICK\n", dev->name);
  1955. }
  1956. static void __orinoco_ev_wterr(struct net_device *dev, hermes_t *hw)
  1957. {
  1958. /* This seems to happen a fair bit under load, but ignoring it
  1959. seems to work fine...*/
  1960. printk(KERN_DEBUG "%s: MAC controller error (WTERR). Ignoring.\n",
  1961. dev->name);
  1962. }
  1963. irqreturn_t orinoco_interrupt(int irq, void *dev_id, struct pt_regs *regs)
  1964. {
  1965. struct net_device *dev = (struct net_device *)dev_id;
  1966. struct orinoco_private *priv = netdev_priv(dev);
  1967. hermes_t *hw = &priv->hw;
  1968. int count = MAX_IRQLOOPS_PER_IRQ;
  1969. u16 evstat, events;
  1970. /* These are used to detect a runaway interrupt situation */
  1971. /* If we get more than MAX_IRQLOOPS_PER_JIFFY iterations in a jiffy,
  1972. * we panic and shut down the hardware */
  1973. static int last_irq_jiffy = 0; /* jiffies value the last time
  1974. * we were called */
  1975. static int loops_this_jiffy = 0;
  1976. unsigned long flags;
  1977. if (orinoco_lock(priv, &flags) != 0) {
  1978. /* If hw is unavailable - we don't know if the irq was
  1979. * for us or not */
  1980. return IRQ_HANDLED;
  1981. }
  1982. evstat = hermes_read_regn(hw, EVSTAT);
  1983. events = evstat & hw->inten;
  1984. if (! events) {
  1985. orinoco_unlock(priv, &flags);
  1986. return IRQ_NONE;
  1987. }
  1988. if (jiffies != last_irq_jiffy)
  1989. loops_this_jiffy = 0;
  1990. last_irq_jiffy = jiffies;
  1991. while (events && count--) {
  1992. if (++loops_this_jiffy > MAX_IRQLOOPS_PER_JIFFY) {
  1993. printk(KERN_WARNING "%s: IRQ handler is looping too "
  1994. "much! Resetting.\n", dev->name);
  1995. /* Disable interrupts for now */
  1996. hermes_set_irqmask(hw, 0);
  1997. schedule_work(&priv->reset_work);
  1998. break;
  1999. }
  2000. /* Check the card hasn't been removed */
  2001. if (! hermes_present(hw)) {
  2002. DEBUG(0, "orinoco_interrupt(): card removed\n");
  2003. break;
  2004. }
  2005. if (events & HERMES_EV_TICK)
  2006. __orinoco_ev_tick(dev, hw);
  2007. if (events & HERMES_EV_WTERR)
  2008. __orinoco_ev_wterr(dev, hw);
  2009. if (events & HERMES_EV_INFDROP)
  2010. __orinoco_ev_infdrop(dev, hw);
  2011. if (events & HERMES_EV_INFO)
  2012. __orinoco_ev_info(dev, hw);
  2013. if (events & HERMES_EV_RX)
  2014. __orinoco_ev_rx(dev, hw);
  2015. if (events & HERMES_EV_TXEXC)
  2016. __orinoco_ev_txexc(dev, hw);
  2017. if (events & HERMES_EV_TX)
  2018. __orinoco_ev_tx(dev, hw);
  2019. if (events & HERMES_EV_ALLOC)
  2020. __orinoco_ev_alloc(dev, hw);
  2021. hermes_write_regn(hw, EVACK, evstat);
  2022. evstat = hermes_read_regn(hw, EVSTAT);
  2023. events = evstat & hw->inten;
  2024. };
  2025. orinoco_unlock(priv, &flags);
  2026. return IRQ_HANDLED;
  2027. }
  2028. /********************************************************************/
  2029. /* Initialization */
  2030. /********************************************************************/
  2031. struct comp_id {
  2032. u16 id, variant, major, minor;
  2033. } __attribute__ ((packed));
  2034. static inline fwtype_t determine_firmware_type(struct comp_id *nic_id)
  2035. {
  2036. if (nic_id->id < 0x8000)
  2037. return FIRMWARE_TYPE_AGERE;
  2038. else if (nic_id->id == 0x8000 && nic_id->major == 0)
  2039. return FIRMWARE_TYPE_SYMBOL;
  2040. else
  2041. return FIRMWARE_TYPE_INTERSIL;
  2042. }
  2043. /* Set priv->firmware type, determine firmware properties */
  2044. static int determine_firmware(struct net_device *dev)
  2045. {
  2046. struct orinoco_private *priv = netdev_priv(dev);
  2047. hermes_t *hw = &priv->hw;
  2048. int err;
  2049. struct comp_id nic_id, sta_id;
  2050. unsigned int firmver;
  2051. char tmp[SYMBOL_MAX_VER_LEN+1];
  2052. /* Get the hardware version */
  2053. err = HERMES_READ_RECORD(hw, USER_BAP, HERMES_RID_NICID, &nic_id);
  2054. if (err) {
  2055. printk(KERN_ERR "%s: Cannot read hardware identity: error %d\n",
  2056. dev->name, err);
  2057. return err;
  2058. }
  2059. le16_to_cpus(&nic_id.id);
  2060. le16_to_cpus(&nic_id.variant);
  2061. le16_to_cpus(&nic_id.major);
  2062. le16_to_cpus(&nic_id.minor);
  2063. printk(KERN_DEBUG "%s: Hardware identity %04x:%04x:%04x:%04x\n",
  2064. dev->name, nic_id.id, nic_id.variant,
  2065. nic_id.major, nic_id.minor);
  2066. priv->firmware_type = determine_firmware_type(&nic_id);
  2067. /* Get the firmware version */
  2068. err = HERMES_READ_RECORD(hw, USER_BAP, HERMES_RID_STAID, &sta_id);
  2069. if (err) {
  2070. printk(KERN_ERR "%s: Cannot read station identity: error %d\n",
  2071. dev->name, err);
  2072. return err;
  2073. }
  2074. le16_to_cpus(&sta_id.id);
  2075. le16_to_cpus(&sta_id.variant);
  2076. le16_to_cpus(&sta_id.major);
  2077. le16_to_cpus(&sta_id.minor);
  2078. printk(KERN_DEBUG "%s: Station identity %04x:%04x:%04x:%04x\n",
  2079. dev->name, sta_id.id, sta_id.variant,
  2080. sta_id.major, sta_id.minor);
  2081. switch (sta_id.id) {
  2082. case 0x15:
  2083. printk(KERN_ERR "%s: Primary firmware is active\n",
  2084. dev->name);
  2085. return -ENODEV;
  2086. case 0x14b:
  2087. printk(KERN_ERR "%s: Tertiary firmware is active\n",
  2088. dev->name);
  2089. return -ENODEV;
  2090. case 0x1f: /* Intersil, Agere, Symbol Spectrum24 */
  2091. case 0x21: /* Symbol Spectrum24 Trilogy */
  2092. break;
  2093. default:
  2094. printk(KERN_NOTICE "%s: Unknown station ID, please report\n",
  2095. dev->name);
  2096. break;
  2097. }
  2098. /* Default capabilities */
  2099. priv->has_sensitivity = 1;
  2100. priv->has_mwo = 0;
  2101. priv->has_preamble = 0;
  2102. priv->has_port3 = 1;
  2103. priv->has_ibss = 1;
  2104. priv->has_wep = 0;
  2105. priv->has_big_wep = 0;
  2106. /* Determine capabilities from the firmware version */
  2107. switch (priv->firmware_type) {
  2108. case FIRMWARE_TYPE_AGERE:
  2109. /* Lucent Wavelan IEEE, Lucent Orinoco, Cabletron RoamAbout,
  2110. ELSA, Melco, HP, IBM, Dell 1150, Compaq 110/210 */
  2111. snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
  2112. "Lucent/Agere %d.%02d", sta_id.major, sta_id.minor);
  2113. firmver = ((unsigned long)sta_id.major << 16) | sta_id.minor;
  2114. priv->has_ibss = (firmver >= 0x60006);
  2115. priv->has_wep = (firmver >= 0x40020);
  2116. priv->has_big_wep = 1; /* FIXME: this is wrong - how do we tell
  2117. Gold cards from the others? */
  2118. priv->has_mwo = (firmver >= 0x60000);
  2119. priv->has_pm = (firmver >= 0x40020); /* Don't work in 7.52 ? */
  2120. priv->ibss_port = 1;
  2121. priv->has_hostscan = (firmver >= 0x8000a);
  2122. /* Tested with Agere firmware :
  2123. * 1.16 ; 4.08 ; 4.52 ; 6.04 ; 6.16 ; 7.28 => Jean II
  2124. * Tested CableTron firmware : 4.32 => Anton */
  2125. break;
  2126. case FIRMWARE_TYPE_SYMBOL:
  2127. /* Symbol , 3Com AirConnect, Intel, Ericsson WLAN */
  2128. /* Intel MAC : 00:02:B3:* */
  2129. /* 3Com MAC : 00:50:DA:* */
  2130. memset(tmp, 0, sizeof(tmp));
  2131. /* Get the Symbol firmware version */
  2132. err = hermes_read_ltv(hw, USER_BAP,
  2133. HERMES_RID_SECONDARYVERSION_SYMBOL,
  2134. SYMBOL_MAX_VER_LEN, NULL, &tmp);
  2135. if (err) {
  2136. printk(KERN_WARNING
  2137. "%s: Error %d reading Symbol firmware info. Wildly guessing capabilities...\n",
  2138. dev->name, err);
  2139. firmver = 0;
  2140. tmp[0] = '\0';
  2141. } else {
  2142. /* The firmware revision is a string, the format is
  2143. * something like : "V2.20-01".
  2144. * Quick and dirty parsing... - Jean II
  2145. */
  2146. firmver = ((tmp[1] - '0') << 16) | ((tmp[3] - '0') << 12)
  2147. | ((tmp[4] - '0') << 8) | ((tmp[6] - '0') << 4)
  2148. | (tmp[7] - '0');
  2149. tmp[SYMBOL_MAX_VER_LEN] = '\0';
  2150. }
  2151. snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
  2152. "Symbol %s", tmp);
  2153. priv->has_ibss = (firmver >= 0x20000);
  2154. priv->has_wep = (firmver >= 0x15012);
  2155. priv->has_big_wep = (firmver >= 0x20000);
  2156. priv->has_pm = (firmver >= 0x20000 && firmver < 0x22000) ||
  2157. (firmver >= 0x29000 && firmver < 0x30000) ||
  2158. firmver >= 0x31000;
  2159. priv->has_preamble = (firmver >= 0x20000);
  2160. priv->ibss_port = 4;
  2161. priv->broken_disableport = (firmver == 0x25013) ||
  2162. (firmver >= 0x30000 && firmver <= 0x31000);
  2163. priv->has_hostscan = (firmver >= 0x31001) ||
  2164. (firmver >= 0x29057 && firmver < 0x30000);
  2165. /* Tested with Intel firmware : 0x20015 => Jean II */
  2166. /* Tested with 3Com firmware : 0x15012 & 0x22001 => Jean II */
  2167. break;
  2168. case FIRMWARE_TYPE_INTERSIL:
  2169. /* D-Link, Linksys, Adtron, ZoomAir, and many others...
  2170. * Samsung, Compaq 100/200 and Proxim are slightly
  2171. * different and less well tested */
  2172. /* D-Link MAC : 00:40:05:* */
  2173. /* Addtron MAC : 00:90:D1:* */
  2174. snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
  2175. "Intersil %d.%d.%d", sta_id.major, sta_id.minor,
  2176. sta_id.variant);
  2177. firmver = ((unsigned long)sta_id.major << 16) |
  2178. ((unsigned long)sta_id.minor << 8) | sta_id.variant;
  2179. priv->has_ibss = (firmver >= 0x000700); /* FIXME */
  2180. priv->has_big_wep = priv->has_wep = (firmver >= 0x000800);
  2181. priv->has_pm = (firmver >= 0x000700);
  2182. priv->has_hostscan = (firmver >= 0x010301);
  2183. if (firmver >= 0x000800)
  2184. priv->ibss_port = 0;
  2185. else {
  2186. printk(KERN_NOTICE "%s: Intersil firmware earlier "
  2187. "than v0.8.x - several features not supported\n",
  2188. dev->name);
  2189. priv->ibss_port = 1;
  2190. }
  2191. break;
  2192. }
  2193. printk(KERN_DEBUG "%s: Firmware determined as %s\n", dev->name,
  2194. priv->fw_name);
  2195. return 0;
  2196. }
  2197. static int orinoco_init(struct net_device *dev)
  2198. {
  2199. struct orinoco_private *priv = netdev_priv(dev);
  2200. hermes_t *hw = &priv->hw;
  2201. int err = 0;
  2202. struct hermes_idstring nickbuf;
  2203. u16 reclen;
  2204. int len;
  2205. TRACE_ENTER(dev->name);
  2206. /* No need to lock, the hw_unavailable flag is already set in
  2207. * alloc_orinocodev() */
  2208. priv->nicbuf_size = IEEE802_11_FRAME_LEN + ETH_HLEN;
  2209. /* Initialize the firmware */
  2210. err = orinoco_reinit_firmware(dev);
  2211. if (err != 0) {
  2212. printk(KERN_ERR "%s: failed to initialize firmware (err = %d)\n",
  2213. dev->name, err);
  2214. goto out;
  2215. }
  2216. err = determine_firmware(dev);
  2217. if (err != 0) {
  2218. printk(KERN_ERR "%s: Incompatible firmware, aborting\n",
  2219. dev->name);
  2220. goto out;
  2221. }
  2222. if (priv->has_port3)
  2223. printk(KERN_DEBUG "%s: Ad-hoc demo mode supported\n", dev->name);
  2224. if (priv->has_ibss)
  2225. printk(KERN_DEBUG "%s: IEEE standard IBSS ad-hoc mode supported\n",
  2226. dev->name);
  2227. if (priv->has_wep) {
  2228. printk(KERN_DEBUG "%s: WEP supported, ", dev->name);
  2229. if (priv->has_big_wep)
  2230. printk("104-bit key\n");
  2231. else
  2232. printk("40-bit key\n");
  2233. }
  2234. /* Get the MAC address */
  2235. err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CNFOWNMACADDR,
  2236. ETH_ALEN, NULL, dev->dev_addr);
  2237. if (err) {
  2238. printk(KERN_WARNING "%s: failed to read MAC address!\n",
  2239. dev->name);
  2240. goto out;
  2241. }
  2242. printk(KERN_DEBUG "%s: MAC address %02X:%02X:%02X:%02X:%02X:%02X\n",
  2243. dev->name, dev->dev_addr[0], dev->dev_addr[1],
  2244. dev->dev_addr[2], dev->dev_addr[3], dev->dev_addr[4],
  2245. dev->dev_addr[5]);
  2246. /* Get the station name */
  2247. err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CNFOWNNAME,
  2248. sizeof(nickbuf), &reclen, &nickbuf);
  2249. if (err) {
  2250. printk(KERN_ERR "%s: failed to read station name\n",
  2251. dev->name);
  2252. goto out;
  2253. }
  2254. if (nickbuf.len)
  2255. len = min(IW_ESSID_MAX_SIZE, (int)le16_to_cpu(nickbuf.len));
  2256. else
  2257. len = min(IW_ESSID_MAX_SIZE, 2 * reclen);
  2258. memcpy(priv->nick, &nickbuf.val, len);
  2259. priv->nick[len] = '\0';
  2260. printk(KERN_DEBUG "%s: Station name \"%s\"\n", dev->name, priv->nick);
  2261. /* Get allowed channels */
  2262. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CHANNELLIST,
  2263. &priv->channel_mask);
  2264. if (err) {
  2265. printk(KERN_ERR "%s: failed to read channel list!\n",
  2266. dev->name);
  2267. goto out;
  2268. }
  2269. /* Get initial AP density */
  2270. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFSYSTEMSCALE,
  2271. &priv->ap_density);
  2272. if (err || priv->ap_density < 1 || priv->ap_density > 3) {
  2273. priv->has_sensitivity = 0;
  2274. }
  2275. /* Get initial RTS threshold */
  2276. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFRTSTHRESHOLD,
  2277. &priv->rts_thresh);
  2278. if (err) {
  2279. printk(KERN_ERR "%s: failed to read RTS threshold!\n",
  2280. dev->name);
  2281. goto out;
  2282. }
  2283. /* Get initial fragmentation settings */
  2284. if (priv->has_mwo)
  2285. err = hermes_read_wordrec(hw, USER_BAP,
  2286. HERMES_RID_CNFMWOROBUST_AGERE,
  2287. &priv->mwo_robust);
  2288. else
  2289. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
  2290. &priv->frag_thresh);
  2291. if (err) {
  2292. printk(KERN_ERR "%s: failed to read fragmentation settings!\n",
  2293. dev->name);
  2294. goto out;
  2295. }
  2296. /* Power management setup */
  2297. if (priv->has_pm) {
  2298. priv->pm_on = 0;
  2299. priv->pm_mcast = 1;
  2300. err = hermes_read_wordrec(hw, USER_BAP,
  2301. HERMES_RID_CNFMAXSLEEPDURATION,
  2302. &priv->pm_period);
  2303. if (err) {
  2304. printk(KERN_ERR "%s: failed to read power management period!\n",
  2305. dev->name);
  2306. goto out;
  2307. }
  2308. err = hermes_read_wordrec(hw, USER_BAP,
  2309. HERMES_RID_CNFPMHOLDOVERDURATION,
  2310. &priv->pm_timeout);
  2311. if (err) {
  2312. printk(KERN_ERR "%s: failed to read power management timeout!\n",
  2313. dev->name);
  2314. goto out;
  2315. }
  2316. }
  2317. /* Preamble setup */
  2318. if (priv->has_preamble) {
  2319. err = hermes_read_wordrec(hw, USER_BAP,
  2320. HERMES_RID_CNFPREAMBLE_SYMBOL,
  2321. &priv->preamble);
  2322. if (err)
  2323. goto out;
  2324. }
  2325. /* Set up the default configuration */
  2326. priv->iw_mode = IW_MODE_INFRA;
  2327. /* By default use IEEE/IBSS ad-hoc mode if we have it */
  2328. priv->prefer_port3 = priv->has_port3 && (! priv->has_ibss);
  2329. set_port_type(priv);
  2330. priv->channel = 0; /* use firmware default */
  2331. priv->promiscuous = 0;
  2332. priv->wep_on = 0;
  2333. priv->tx_key = 0;
  2334. /* Make the hardware available, as long as it hasn't been
  2335. * removed elsewhere (e.g. by PCMCIA hot unplug) */
  2336. spin_lock_irq(&priv->lock);
  2337. priv->hw_unavailable--;
  2338. spin_unlock_irq(&priv->lock);
  2339. printk(KERN_DEBUG "%s: ready\n", dev->name);
  2340. out:
  2341. TRACE_EXIT(dev->name);
  2342. return err;
  2343. }
  2344. struct net_device *alloc_orinocodev(int sizeof_card,
  2345. int (*hard_reset)(struct orinoco_private *))
  2346. {
  2347. struct net_device *dev;
  2348. struct orinoco_private *priv;
  2349. dev = alloc_etherdev(sizeof(struct orinoco_private) + sizeof_card);
  2350. if (! dev)
  2351. return NULL;
  2352. priv = netdev_priv(dev);
  2353. priv->ndev = dev;
  2354. if (sizeof_card)
  2355. priv->card = (void *)((unsigned long)priv
  2356. + sizeof(struct orinoco_private));
  2357. else
  2358. priv->card = NULL;
  2359. /* Setup / override net_device fields */
  2360. dev->init = orinoco_init;
  2361. dev->hard_start_xmit = orinoco_xmit;
  2362. dev->tx_timeout = orinoco_tx_timeout;
  2363. dev->watchdog_timeo = HZ; /* 1 second timeout */
  2364. dev->get_stats = orinoco_get_stats;
  2365. dev->ethtool_ops = &orinoco_ethtool_ops;
  2366. dev->get_wireless_stats = orinoco_get_wireless_stats;
  2367. dev->wireless_handlers = (struct iw_handler_def *)&orinoco_handler_def;
  2368. dev->change_mtu = orinoco_change_mtu;
  2369. dev->set_multicast_list = orinoco_set_multicast_list;
  2370. /* we use the default eth_mac_addr for setting the MAC addr */
  2371. /* Set up default callbacks */
  2372. dev->open = orinoco_open;
  2373. dev->stop = orinoco_stop;
  2374. priv->hard_reset = hard_reset;
  2375. spin_lock_init(&priv->lock);
  2376. priv->open = 0;
  2377. priv->hw_unavailable = 1; /* orinoco_init() must clear this
  2378. * before anything else touches the
  2379. * hardware */
  2380. INIT_WORK(&priv->reset_work, (void (*)(void *))orinoco_reset, dev);
  2381. INIT_WORK(&priv->join_work, (void (*)(void *))orinoco_join_ap, dev);
  2382. INIT_WORK(&priv->wevent_work, (void (*)(void *))orinoco_send_wevents, dev);
  2383. netif_carrier_off(dev);
  2384. priv->last_linkstatus = 0xffff;
  2385. return dev;
  2386. }
  2387. void free_orinocodev(struct net_device *dev)
  2388. {
  2389. struct orinoco_private *priv = netdev_priv(dev);
  2390. kfree(priv->scan_result);
  2391. free_netdev(dev);
  2392. }
  2393. /********************************************************************/
  2394. /* Wireless extensions */
  2395. /********************************************************************/
  2396. static int orinoco_hw_get_essid(struct orinoco_private *priv, int *active,
  2397. char buf[IW_ESSID_MAX_SIZE+1])
  2398. {
  2399. hermes_t *hw = &priv->hw;
  2400. int err = 0;
  2401. struct hermes_idstring essidbuf;
  2402. char *p = (char *)(&essidbuf.val);
  2403. int len;
  2404. unsigned long flags;
  2405. if (orinoco_lock(priv, &flags) != 0)
  2406. return -EBUSY;
  2407. if (strlen(priv->desired_essid) > 0) {
  2408. /* We read the desired SSID from the hardware rather
  2409. than from priv->desired_essid, just in case the
  2410. firmware is allowed to change it on us. I'm not
  2411. sure about this */
  2412. /* My guess is that the OWNSSID should always be whatever
  2413. * we set to the card, whereas CURRENT_SSID is the one that
  2414. * may change... - Jean II */
  2415. u16 rid;
  2416. *active = 1;
  2417. rid = (priv->port_type == 3) ? HERMES_RID_CNFOWNSSID :
  2418. HERMES_RID_CNFDESIREDSSID;
  2419. err = hermes_read_ltv(hw, USER_BAP, rid, sizeof(essidbuf),
  2420. NULL, &essidbuf);
  2421. if (err)
  2422. goto fail_unlock;
  2423. } else {
  2424. *active = 0;
  2425. err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTSSID,
  2426. sizeof(essidbuf), NULL, &essidbuf);
  2427. if (err)
  2428. goto fail_unlock;
  2429. }
  2430. len = le16_to_cpu(essidbuf.len);
  2431. BUG_ON(len > IW_ESSID_MAX_SIZE);
  2432. memset(buf, 0, IW_ESSID_MAX_SIZE+1);
  2433. memcpy(buf, p, len);
  2434. buf[len] = '\0';
  2435. fail_unlock:
  2436. orinoco_unlock(priv, &flags);
  2437. return err;
  2438. }
  2439. static long orinoco_hw_get_freq(struct orinoco_private *priv)
  2440. {
  2441. hermes_t *hw = &priv->hw;
  2442. int err = 0;
  2443. u16 channel;
  2444. long freq = 0;
  2445. unsigned long flags;
  2446. if (orinoco_lock(priv, &flags) != 0)
  2447. return -EBUSY;
  2448. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CURRENTCHANNEL, &channel);
  2449. if (err)
  2450. goto out;
  2451. /* Intersil firmware 1.3.5 returns 0 when the interface is down */
  2452. if (channel == 0) {
  2453. err = -EBUSY;
  2454. goto out;
  2455. }
  2456. if ( (channel < 1) || (channel > NUM_CHANNELS) ) {
  2457. printk(KERN_WARNING "%s: Channel out of range (%d)!\n",
  2458. priv->ndev->name, channel);
  2459. err = -EBUSY;
  2460. goto out;
  2461. }
  2462. freq = channel_frequency[channel-1] * 100000;
  2463. out:
  2464. orinoco_unlock(priv, &flags);
  2465. if (err > 0)
  2466. err = -EBUSY;
  2467. return err ? err : freq;
  2468. }
  2469. static int orinoco_hw_get_bitratelist(struct orinoco_private *priv,
  2470. int *numrates, s32 *rates, int max)
  2471. {
  2472. hermes_t *hw = &priv->hw;
  2473. struct hermes_idstring list;
  2474. unsigned char *p = (unsigned char *)&list.val;
  2475. int err = 0;
  2476. int num;
  2477. int i;
  2478. unsigned long flags;
  2479. if (orinoco_lock(priv, &flags) != 0)
  2480. return -EBUSY;
  2481. err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_SUPPORTEDDATARATES,
  2482. sizeof(list), NULL, &list);
  2483. orinoco_unlock(priv, &flags);
  2484. if (err)
  2485. return err;
  2486. num = le16_to_cpu(list.len);
  2487. *numrates = num;
  2488. num = min(num, max);
  2489. for (i = 0; i < num; i++) {
  2490. rates[i] = (p[i] & 0x7f) * 500000; /* convert to bps */
  2491. }
  2492. return 0;
  2493. }
  2494. static int orinoco_ioctl_getname(struct net_device *dev,
  2495. struct iw_request_info *info,
  2496. char *name,
  2497. char *extra)
  2498. {
  2499. struct orinoco_private *priv = netdev_priv(dev);
  2500. int numrates;
  2501. int err;
  2502. err = orinoco_hw_get_bitratelist(priv, &numrates, NULL, 0);
  2503. if (!err && (numrates > 2))
  2504. strcpy(name, "IEEE 802.11b");
  2505. else
  2506. strcpy(name, "IEEE 802.11-DS");
  2507. return 0;
  2508. }
  2509. static int orinoco_ioctl_setwap(struct net_device *dev,
  2510. struct iw_request_info *info,
  2511. struct sockaddr *ap_addr,
  2512. char *extra)
  2513. {
  2514. struct orinoco_private *priv = netdev_priv(dev);
  2515. int err = -EINPROGRESS; /* Call commit handler */
  2516. unsigned long flags;
  2517. static const u8 off_addr[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  2518. static const u8 any_addr[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
  2519. if (orinoco_lock(priv, &flags) != 0)
  2520. return -EBUSY;
  2521. /* Enable automatic roaming - no sanity checks are needed */
  2522. if (memcmp(&ap_addr->sa_data, off_addr, ETH_ALEN) == 0 ||
  2523. memcmp(&ap_addr->sa_data, any_addr, ETH_ALEN) == 0) {
  2524. priv->bssid_fixed = 0;
  2525. memset(priv->desired_bssid, 0, ETH_ALEN);
  2526. /* "off" means keep existing connection */
  2527. if (ap_addr->sa_data[0] == 0) {
  2528. __orinoco_hw_set_wap(priv);
  2529. err = 0;
  2530. }
  2531. goto out;
  2532. }
  2533. if (priv->firmware_type == FIRMWARE_TYPE_AGERE) {
  2534. printk(KERN_WARNING "%s: Lucent/Agere firmware doesn't "
  2535. "support manual roaming\n",
  2536. dev->name);
  2537. err = -EOPNOTSUPP;
  2538. goto out;
  2539. }
  2540. if (priv->iw_mode != IW_MODE_INFRA) {
  2541. printk(KERN_WARNING "%s: Manual roaming supported only in "
  2542. "managed mode\n", dev->name);
  2543. err = -EOPNOTSUPP;
  2544. goto out;
  2545. }
  2546. /* Intersil firmware hangs without Desired ESSID */
  2547. if (priv->firmware_type == FIRMWARE_TYPE_INTERSIL &&
  2548. strlen(priv->desired_essid) == 0) {
  2549. printk(KERN_WARNING "%s: Desired ESSID must be set for "
  2550. "manual roaming\n", dev->name);
  2551. err = -EOPNOTSUPP;
  2552. goto out;
  2553. }
  2554. /* Finally, enable manual roaming */
  2555. priv->bssid_fixed = 1;
  2556. memcpy(priv->desired_bssid, &ap_addr->sa_data, ETH_ALEN);
  2557. out:
  2558. orinoco_unlock(priv, &flags);
  2559. return err;
  2560. }
  2561. static int orinoco_ioctl_getwap(struct net_device *dev,
  2562. struct iw_request_info *info,
  2563. struct sockaddr *ap_addr,
  2564. char *extra)
  2565. {
  2566. struct orinoco_private *priv = netdev_priv(dev);
  2567. hermes_t *hw = &priv->hw;
  2568. int err = 0;
  2569. unsigned long flags;
  2570. if (orinoco_lock(priv, &flags) != 0)
  2571. return -EBUSY;
  2572. ap_addr->sa_family = ARPHRD_ETHER;
  2573. err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTBSSID,
  2574. ETH_ALEN, NULL, ap_addr->sa_data);
  2575. orinoco_unlock(priv, &flags);
  2576. return err;
  2577. }
  2578. static int orinoco_ioctl_setmode(struct net_device *dev,
  2579. struct iw_request_info *info,
  2580. u32 *mode,
  2581. char *extra)
  2582. {
  2583. struct orinoco_private *priv = netdev_priv(dev);
  2584. int err = -EINPROGRESS; /* Call commit handler */
  2585. unsigned long flags;
  2586. if (priv->iw_mode == *mode)
  2587. return 0;
  2588. if (orinoco_lock(priv, &flags) != 0)
  2589. return -EBUSY;
  2590. switch (*mode) {
  2591. case IW_MODE_ADHOC:
  2592. if (!priv->has_ibss && !priv->has_port3)
  2593. err = -EOPNOTSUPP;
  2594. break;
  2595. case IW_MODE_INFRA:
  2596. break;
  2597. default:
  2598. err = -EOPNOTSUPP;
  2599. break;
  2600. }
  2601. if (err == -EINPROGRESS) {
  2602. priv->iw_mode = *mode;
  2603. set_port_type(priv);
  2604. }
  2605. orinoco_unlock(priv, &flags);
  2606. return err;
  2607. }
  2608. static int orinoco_ioctl_getmode(struct net_device *dev,
  2609. struct iw_request_info *info,
  2610. u32 *mode,
  2611. char *extra)
  2612. {
  2613. struct orinoco_private *priv = netdev_priv(dev);
  2614. *mode = priv->iw_mode;
  2615. return 0;
  2616. }
  2617. static int orinoco_ioctl_getiwrange(struct net_device *dev,
  2618. struct iw_request_info *info,
  2619. struct iw_point *rrq,
  2620. char *extra)
  2621. {
  2622. struct orinoco_private *priv = netdev_priv(dev);
  2623. int err = 0;
  2624. struct iw_range *range = (struct iw_range *) extra;
  2625. int numrates;
  2626. int i, k;
  2627. TRACE_ENTER(dev->name);
  2628. rrq->length = sizeof(struct iw_range);
  2629. memset(range, 0, sizeof(struct iw_range));
  2630. range->we_version_compiled = WIRELESS_EXT;
  2631. range->we_version_source = 14;
  2632. /* Set available channels/frequencies */
  2633. range->num_channels = NUM_CHANNELS;
  2634. k = 0;
  2635. for (i = 0; i < NUM_CHANNELS; i++) {
  2636. if (priv->channel_mask & (1 << i)) {
  2637. range->freq[k].i = i + 1;
  2638. range->freq[k].m = channel_frequency[i] * 100000;
  2639. range->freq[k].e = 1;
  2640. k++;
  2641. }
  2642. if (k >= IW_MAX_FREQUENCIES)
  2643. break;
  2644. }
  2645. range->num_frequency = k;
  2646. range->sensitivity = 3;
  2647. if (priv->has_wep) {
  2648. range->max_encoding_tokens = ORINOCO_MAX_KEYS;
  2649. range->encoding_size[0] = SMALL_KEY_SIZE;
  2650. range->num_encoding_sizes = 1;
  2651. if (priv->has_big_wep) {
  2652. range->encoding_size[1] = LARGE_KEY_SIZE;
  2653. range->num_encoding_sizes = 2;
  2654. }
  2655. }
  2656. if ((priv->iw_mode == IW_MODE_ADHOC) && (priv->spy_number == 0)){
  2657. /* Quality stats meaningless in ad-hoc mode */
  2658. } else {
  2659. range->max_qual.qual = 0x8b - 0x2f;
  2660. range->max_qual.level = 0x2f - 0x95 - 1;
  2661. range->max_qual.noise = 0x2f - 0x95 - 1;
  2662. /* Need to get better values */
  2663. range->avg_qual.qual = 0x24;
  2664. range->avg_qual.level = 0xC2;
  2665. range->avg_qual.noise = 0x9E;
  2666. }
  2667. err = orinoco_hw_get_bitratelist(priv, &numrates,
  2668. range->bitrate, IW_MAX_BITRATES);
  2669. if (err)
  2670. return err;
  2671. range->num_bitrates = numrates;
  2672. /* Set an indication of the max TCP throughput in bit/s that we can
  2673. * expect using this interface. May be use for QoS stuff...
  2674. * Jean II */
  2675. if (numrates > 2)
  2676. range->throughput = 5 * 1000 * 1000; /* ~5 Mb/s */
  2677. else
  2678. range->throughput = 1.5 * 1000 * 1000; /* ~1.5 Mb/s */
  2679. range->min_rts = 0;
  2680. range->max_rts = 2347;
  2681. range->min_frag = 256;
  2682. range->max_frag = 2346;
  2683. range->min_pmp = 0;
  2684. range->max_pmp = 65535000;
  2685. range->min_pmt = 0;
  2686. range->max_pmt = 65535 * 1000; /* ??? */
  2687. range->pmp_flags = IW_POWER_PERIOD;
  2688. range->pmt_flags = IW_POWER_TIMEOUT;
  2689. range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT | IW_POWER_UNICAST_R;
  2690. range->retry_capa = IW_RETRY_LIMIT | IW_RETRY_LIFETIME;
  2691. range->retry_flags = IW_RETRY_LIMIT;
  2692. range->r_time_flags = IW_RETRY_LIFETIME;
  2693. range->min_retry = 0;
  2694. range->max_retry = 65535; /* ??? */
  2695. range->min_r_time = 0;
  2696. range->max_r_time = 65535 * 1000; /* ??? */
  2697. TRACE_EXIT(dev->name);
  2698. return 0;
  2699. }
  2700. static int orinoco_ioctl_setiwencode(struct net_device *dev,
  2701. struct iw_request_info *info,
  2702. struct iw_point *erq,
  2703. char *keybuf)
  2704. {
  2705. struct orinoco_private *priv = netdev_priv(dev);
  2706. int index = (erq->flags & IW_ENCODE_INDEX) - 1;
  2707. int setindex = priv->tx_key;
  2708. int enable = priv->wep_on;
  2709. int restricted = priv->wep_restrict;
  2710. u16 xlen = 0;
  2711. int err = -EINPROGRESS; /* Call commit handler */
  2712. unsigned long flags;
  2713. if (! priv->has_wep)
  2714. return -EOPNOTSUPP;
  2715. if (erq->pointer) {
  2716. /* We actually have a key to set - check its length */
  2717. if (erq->length > LARGE_KEY_SIZE)
  2718. return -E2BIG;
  2719. if ( (erq->length > SMALL_KEY_SIZE) && !priv->has_big_wep )
  2720. return -E2BIG;
  2721. }
  2722. if (orinoco_lock(priv, &flags) != 0)
  2723. return -EBUSY;
  2724. if (erq->pointer) {
  2725. if ((index < 0) || (index >= ORINOCO_MAX_KEYS))
  2726. index = priv->tx_key;
  2727. /* Adjust key length to a supported value */
  2728. if (erq->length > SMALL_KEY_SIZE) {
  2729. xlen = LARGE_KEY_SIZE;
  2730. } else if (erq->length > 0) {
  2731. xlen = SMALL_KEY_SIZE;
  2732. } else
  2733. xlen = 0;
  2734. /* Switch on WEP if off */
  2735. if ((!enable) && (xlen > 0)) {
  2736. setindex = index;
  2737. enable = 1;
  2738. }
  2739. } else {
  2740. /* Important note : if the user do "iwconfig eth0 enc off",
  2741. * we will arrive there with an index of -1. This is valid
  2742. * but need to be taken care off... Jean II */
  2743. if ((index < 0) || (index >= ORINOCO_MAX_KEYS)) {
  2744. if((index != -1) || (erq->flags == 0)) {
  2745. err = -EINVAL;
  2746. goto out;
  2747. }
  2748. } else {
  2749. /* Set the index : Check that the key is valid */
  2750. if(priv->keys[index].len == 0) {
  2751. err = -EINVAL;
  2752. goto out;
  2753. }
  2754. setindex = index;
  2755. }
  2756. }
  2757. if (erq->flags & IW_ENCODE_DISABLED)
  2758. enable = 0;
  2759. if (erq->flags & IW_ENCODE_OPEN)
  2760. restricted = 0;
  2761. if (erq->flags & IW_ENCODE_RESTRICTED)
  2762. restricted = 1;
  2763. if (erq->pointer) {
  2764. priv->keys[index].len = cpu_to_le16(xlen);
  2765. memset(priv->keys[index].data, 0,
  2766. sizeof(priv->keys[index].data));
  2767. memcpy(priv->keys[index].data, keybuf, erq->length);
  2768. }
  2769. priv->tx_key = setindex;
  2770. /* Try fast key change if connected and only keys are changed */
  2771. if (priv->wep_on && enable && (priv->wep_restrict == restricted) &&
  2772. netif_carrier_ok(dev)) {
  2773. err = __orinoco_hw_setup_wepkeys(priv);
  2774. /* No need to commit if successful */
  2775. goto out;
  2776. }
  2777. priv->wep_on = enable;
  2778. priv->wep_restrict = restricted;
  2779. out:
  2780. orinoco_unlock(priv, &flags);
  2781. return err;
  2782. }
  2783. static int orinoco_ioctl_getiwencode(struct net_device *dev,
  2784. struct iw_request_info *info,
  2785. struct iw_point *erq,
  2786. char *keybuf)
  2787. {
  2788. struct orinoco_private *priv = netdev_priv(dev);
  2789. int index = (erq->flags & IW_ENCODE_INDEX) - 1;
  2790. u16 xlen = 0;
  2791. unsigned long flags;
  2792. if (! priv->has_wep)
  2793. return -EOPNOTSUPP;
  2794. if (orinoco_lock(priv, &flags) != 0)
  2795. return -EBUSY;
  2796. if ((index < 0) || (index >= ORINOCO_MAX_KEYS))
  2797. index = priv->tx_key;
  2798. erq->flags = 0;
  2799. if (! priv->wep_on)
  2800. erq->flags |= IW_ENCODE_DISABLED;
  2801. erq->flags |= index + 1;
  2802. if (priv->wep_restrict)
  2803. erq->flags |= IW_ENCODE_RESTRICTED;
  2804. else
  2805. erq->flags |= IW_ENCODE_OPEN;
  2806. xlen = le16_to_cpu(priv->keys[index].len);
  2807. erq->length = xlen;
  2808. memcpy(keybuf, priv->keys[index].data, ORINOCO_MAX_KEY_SIZE);
  2809. orinoco_unlock(priv, &flags);
  2810. return 0;
  2811. }
  2812. static int orinoco_ioctl_setessid(struct net_device *dev,
  2813. struct iw_request_info *info,
  2814. struct iw_point *erq,
  2815. char *essidbuf)
  2816. {
  2817. struct orinoco_private *priv = netdev_priv(dev);
  2818. unsigned long flags;
  2819. /* Note : ESSID is ignored in Ad-Hoc demo mode, but we can set it
  2820. * anyway... - Jean II */
  2821. /* Hum... Should not use Wireless Extension constant (may change),
  2822. * should use our own... - Jean II */
  2823. if (erq->length > IW_ESSID_MAX_SIZE)
  2824. return -E2BIG;
  2825. if (orinoco_lock(priv, &flags) != 0)
  2826. return -EBUSY;
  2827. /* NULL the string (for NULL termination & ESSID = ANY) - Jean II */
  2828. memset(priv->desired_essid, 0, sizeof(priv->desired_essid));
  2829. /* If not ANY, get the new ESSID */
  2830. if (erq->flags) {
  2831. memcpy(priv->desired_essid, essidbuf, erq->length);
  2832. }
  2833. orinoco_unlock(priv, &flags);
  2834. return -EINPROGRESS; /* Call commit handler */
  2835. }
  2836. static int orinoco_ioctl_getessid(struct net_device *dev,
  2837. struct iw_request_info *info,
  2838. struct iw_point *erq,
  2839. char *essidbuf)
  2840. {
  2841. struct orinoco_private *priv = netdev_priv(dev);
  2842. int active;
  2843. int err = 0;
  2844. unsigned long flags;
  2845. TRACE_ENTER(dev->name);
  2846. if (netif_running(dev)) {
  2847. err = orinoco_hw_get_essid(priv, &active, essidbuf);
  2848. if (err)
  2849. return err;
  2850. } else {
  2851. if (orinoco_lock(priv, &flags) != 0)
  2852. return -EBUSY;
  2853. memcpy(essidbuf, priv->desired_essid, IW_ESSID_MAX_SIZE + 1);
  2854. orinoco_unlock(priv, &flags);
  2855. }
  2856. erq->flags = 1;
  2857. erq->length = strlen(essidbuf) + 1;
  2858. TRACE_EXIT(dev->name);
  2859. return 0;
  2860. }
  2861. static int orinoco_ioctl_setnick(struct net_device *dev,
  2862. struct iw_request_info *info,
  2863. struct iw_point *nrq,
  2864. char *nickbuf)
  2865. {
  2866. struct orinoco_private *priv = netdev_priv(dev);
  2867. unsigned long flags;
  2868. if (nrq->length > IW_ESSID_MAX_SIZE)
  2869. return -E2BIG;
  2870. if (orinoco_lock(priv, &flags) != 0)
  2871. return -EBUSY;
  2872. memset(priv->nick, 0, sizeof(priv->nick));
  2873. memcpy(priv->nick, nickbuf, nrq->length);
  2874. orinoco_unlock(priv, &flags);
  2875. return -EINPROGRESS; /* Call commit handler */
  2876. }
  2877. static int orinoco_ioctl_getnick(struct net_device *dev,
  2878. struct iw_request_info *info,
  2879. struct iw_point *nrq,
  2880. char *nickbuf)
  2881. {
  2882. struct orinoco_private *priv = netdev_priv(dev);
  2883. unsigned long flags;
  2884. if (orinoco_lock(priv, &flags) != 0)
  2885. return -EBUSY;
  2886. memcpy(nickbuf, priv->nick, IW_ESSID_MAX_SIZE+1);
  2887. orinoco_unlock(priv, &flags);
  2888. nrq->length = strlen(nickbuf)+1;
  2889. return 0;
  2890. }
  2891. static int orinoco_ioctl_setfreq(struct net_device *dev,
  2892. struct iw_request_info *info,
  2893. struct iw_freq *frq,
  2894. char *extra)
  2895. {
  2896. struct orinoco_private *priv = netdev_priv(dev);
  2897. int chan = -1;
  2898. unsigned long flags;
  2899. int err = -EINPROGRESS; /* Call commit handler */
  2900. /* We can only use this in Ad-Hoc demo mode to set the operating
  2901. * frequency, or in IBSS mode to set the frequency where the IBSS
  2902. * will be created - Jean II */
  2903. if (priv->iw_mode != IW_MODE_ADHOC)
  2904. return -EOPNOTSUPP;
  2905. if ( (frq->e == 0) && (frq->m <= 1000) ) {
  2906. /* Setting by channel number */
  2907. chan = frq->m;
  2908. } else {
  2909. /* Setting by frequency - search the table */
  2910. int mult = 1;
  2911. int i;
  2912. for (i = 0; i < (6 - frq->e); i++)
  2913. mult *= 10;
  2914. for (i = 0; i < NUM_CHANNELS; i++)
  2915. if (frq->m == (channel_frequency[i] * mult))
  2916. chan = i+1;
  2917. }
  2918. if ( (chan < 1) || (chan > NUM_CHANNELS) ||
  2919. ! (priv->channel_mask & (1 << (chan-1)) ) )
  2920. return -EINVAL;
  2921. if (orinoco_lock(priv, &flags) != 0)
  2922. return -EBUSY;
  2923. priv->channel = chan;
  2924. orinoco_unlock(priv, &flags);
  2925. return err;
  2926. }
  2927. static int orinoco_ioctl_getfreq(struct net_device *dev,
  2928. struct iw_request_info *info,
  2929. struct iw_freq *frq,
  2930. char *extra)
  2931. {
  2932. struct orinoco_private *priv = netdev_priv(dev);
  2933. int tmp;
  2934. /* Locking done in there */
  2935. tmp = orinoco_hw_get_freq(priv);
  2936. if (tmp < 0) {
  2937. return tmp;
  2938. }
  2939. frq->m = tmp;
  2940. frq->e = 1;
  2941. return 0;
  2942. }
  2943. static int orinoco_ioctl_getsens(struct net_device *dev,
  2944. struct iw_request_info *info,
  2945. struct iw_param *srq,
  2946. char *extra)
  2947. {
  2948. struct orinoco_private *priv = netdev_priv(dev);
  2949. hermes_t *hw = &priv->hw;
  2950. u16 val;
  2951. int err;
  2952. unsigned long flags;
  2953. if (!priv->has_sensitivity)
  2954. return -EOPNOTSUPP;
  2955. if (orinoco_lock(priv, &flags) != 0)
  2956. return -EBUSY;
  2957. err = hermes_read_wordrec(hw, USER_BAP,
  2958. HERMES_RID_CNFSYSTEMSCALE, &val);
  2959. orinoco_unlock(priv, &flags);
  2960. if (err)
  2961. return err;
  2962. srq->value = val;
  2963. srq->fixed = 0; /* auto */
  2964. return 0;
  2965. }
  2966. static int orinoco_ioctl_setsens(struct net_device *dev,
  2967. struct iw_request_info *info,
  2968. struct iw_param *srq,
  2969. char *extra)
  2970. {
  2971. struct orinoco_private *priv = netdev_priv(dev);
  2972. int val = srq->value;
  2973. unsigned long flags;
  2974. if (!priv->has_sensitivity)
  2975. return -EOPNOTSUPP;
  2976. if ((val < 1) || (val > 3))
  2977. return -EINVAL;
  2978. if (orinoco_lock(priv, &flags) != 0)
  2979. return -EBUSY;
  2980. priv->ap_density = val;
  2981. orinoco_unlock(priv, &flags);
  2982. return -EINPROGRESS; /* Call commit handler */
  2983. }
  2984. static int orinoco_ioctl_setrts(struct net_device *dev,
  2985. struct iw_request_info *info,
  2986. struct iw_param *rrq,
  2987. char *extra)
  2988. {
  2989. struct orinoco_private *priv = netdev_priv(dev);
  2990. int val = rrq->value;
  2991. unsigned long flags;
  2992. if (rrq->disabled)
  2993. val = 2347;
  2994. if ( (val < 0) || (val > 2347) )
  2995. return -EINVAL;
  2996. if (orinoco_lock(priv, &flags) != 0)
  2997. return -EBUSY;
  2998. priv->rts_thresh = val;
  2999. orinoco_unlock(priv, &flags);
  3000. return -EINPROGRESS; /* Call commit handler */
  3001. }
  3002. static int orinoco_ioctl_getrts(struct net_device *dev,
  3003. struct iw_request_info *info,
  3004. struct iw_param *rrq,
  3005. char *extra)
  3006. {
  3007. struct orinoco_private *priv = netdev_priv(dev);
  3008. rrq->value = priv->rts_thresh;
  3009. rrq->disabled = (rrq->value == 2347);
  3010. rrq->fixed = 1;
  3011. return 0;
  3012. }
  3013. static int orinoco_ioctl_setfrag(struct net_device *dev,
  3014. struct iw_request_info *info,
  3015. struct iw_param *frq,
  3016. char *extra)
  3017. {
  3018. struct orinoco_private *priv = netdev_priv(dev);
  3019. int err = -EINPROGRESS; /* Call commit handler */
  3020. unsigned long flags;
  3021. if (orinoco_lock(priv, &flags) != 0)
  3022. return -EBUSY;
  3023. if (priv->has_mwo) {
  3024. if (frq->disabled)
  3025. priv->mwo_robust = 0;
  3026. else {
  3027. if (frq->fixed)
  3028. printk(KERN_WARNING "%s: Fixed fragmentation is "
  3029. "not supported on this firmware. "
  3030. "Using MWO robust instead.\n", dev->name);
  3031. priv->mwo_robust = 1;
  3032. }
  3033. } else {
  3034. if (frq->disabled)
  3035. priv->frag_thresh = 2346;
  3036. else {
  3037. if ( (frq->value < 256) || (frq->value > 2346) )
  3038. err = -EINVAL;
  3039. else
  3040. priv->frag_thresh = frq->value & ~0x1; /* must be even */
  3041. }
  3042. }
  3043. orinoco_unlock(priv, &flags);
  3044. return err;
  3045. }
  3046. static int orinoco_ioctl_getfrag(struct net_device *dev,
  3047. struct iw_request_info *info,
  3048. struct iw_param *frq,
  3049. char *extra)
  3050. {
  3051. struct orinoco_private *priv = netdev_priv(dev);
  3052. hermes_t *hw = &priv->hw;
  3053. int err;
  3054. u16 val;
  3055. unsigned long flags;
  3056. if (orinoco_lock(priv, &flags) != 0)
  3057. return -EBUSY;
  3058. if (priv->has_mwo) {
  3059. err = hermes_read_wordrec(hw, USER_BAP,
  3060. HERMES_RID_CNFMWOROBUST_AGERE,
  3061. &val);
  3062. if (err)
  3063. val = 0;
  3064. frq->value = val ? 2347 : 0;
  3065. frq->disabled = ! val;
  3066. frq->fixed = 0;
  3067. } else {
  3068. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
  3069. &val);
  3070. if (err)
  3071. val = 0;
  3072. frq->value = val;
  3073. frq->disabled = (val >= 2346);
  3074. frq->fixed = 1;
  3075. }
  3076. orinoco_unlock(priv, &flags);
  3077. return err;
  3078. }
  3079. static int orinoco_ioctl_setrate(struct net_device *dev,
  3080. struct iw_request_info *info,
  3081. struct iw_param *rrq,
  3082. char *extra)
  3083. {
  3084. struct orinoco_private *priv = netdev_priv(dev);
  3085. int ratemode = -1;
  3086. int bitrate; /* 100s of kilobits */
  3087. int i;
  3088. unsigned long flags;
  3089. /* As the user space doesn't know our highest rate, it uses -1
  3090. * to ask us to set the highest rate. Test it using "iwconfig
  3091. * ethX rate auto" - Jean II */
  3092. if (rrq->value == -1)
  3093. bitrate = 110;
  3094. else {
  3095. if (rrq->value % 100000)
  3096. return -EINVAL;
  3097. bitrate = rrq->value / 100000;
  3098. }
  3099. if ( (bitrate != 10) && (bitrate != 20) &&
  3100. (bitrate != 55) && (bitrate != 110) )
  3101. return -EINVAL;
  3102. for (i = 0; i < BITRATE_TABLE_SIZE; i++)
  3103. if ( (bitrate_table[i].bitrate == bitrate) &&
  3104. (bitrate_table[i].automatic == ! rrq->fixed) ) {
  3105. ratemode = i;
  3106. break;
  3107. }
  3108. if (ratemode == -1)
  3109. return -EINVAL;
  3110. if (orinoco_lock(priv, &flags) != 0)
  3111. return -EBUSY;
  3112. priv->bitratemode = ratemode;
  3113. orinoco_unlock(priv, &flags);
  3114. return -EINPROGRESS;
  3115. }
  3116. static int orinoco_ioctl_getrate(struct net_device *dev,
  3117. struct iw_request_info *info,
  3118. struct iw_param *rrq,
  3119. char *extra)
  3120. {
  3121. struct orinoco_private *priv = netdev_priv(dev);
  3122. hermes_t *hw = &priv->hw;
  3123. int err = 0;
  3124. int ratemode;
  3125. int i;
  3126. u16 val;
  3127. unsigned long flags;
  3128. if (orinoco_lock(priv, &flags) != 0)
  3129. return -EBUSY;
  3130. ratemode = priv->bitratemode;
  3131. BUG_ON((ratemode < 0) || (ratemode >= BITRATE_TABLE_SIZE));
  3132. rrq->value = bitrate_table[ratemode].bitrate * 100000;
  3133. rrq->fixed = ! bitrate_table[ratemode].automatic;
  3134. rrq->disabled = 0;
  3135. /* If the interface is running we try to find more about the
  3136. current mode */
  3137. if (netif_running(dev)) {
  3138. err = hermes_read_wordrec(hw, USER_BAP,
  3139. HERMES_RID_CURRENTTXRATE, &val);
  3140. if (err)
  3141. goto out;
  3142. switch (priv->firmware_type) {
  3143. case FIRMWARE_TYPE_AGERE: /* Lucent style rate */
  3144. /* Note : in Lucent firmware, the return value of
  3145. * HERMES_RID_CURRENTTXRATE is the bitrate in Mb/s,
  3146. * and therefore is totally different from the
  3147. * encoding of HERMES_RID_CNFTXRATECONTROL.
  3148. * Don't forget that 6Mb/s is really 5.5Mb/s */
  3149. if (val == 6)
  3150. rrq->value = 5500000;
  3151. else
  3152. rrq->value = val * 1000000;
  3153. break;
  3154. case FIRMWARE_TYPE_INTERSIL: /* Intersil style rate */
  3155. case FIRMWARE_TYPE_SYMBOL: /* Symbol style rate */
  3156. for (i = 0; i < BITRATE_TABLE_SIZE; i++)
  3157. if (bitrate_table[i].intersil_txratectrl == val) {
  3158. ratemode = i;
  3159. break;
  3160. }
  3161. if (i >= BITRATE_TABLE_SIZE)
  3162. printk(KERN_INFO "%s: Unable to determine current bitrate (0x%04hx)\n",
  3163. dev->name, val);
  3164. rrq->value = bitrate_table[ratemode].bitrate * 100000;
  3165. break;
  3166. default:
  3167. BUG();
  3168. }
  3169. }
  3170. out:
  3171. orinoco_unlock(priv, &flags);
  3172. return err;
  3173. }
  3174. static int orinoco_ioctl_setpower(struct net_device *dev,
  3175. struct iw_request_info *info,
  3176. struct iw_param *prq,
  3177. char *extra)
  3178. {
  3179. struct orinoco_private *priv = netdev_priv(dev);
  3180. int err = -EINPROGRESS; /* Call commit handler */
  3181. unsigned long flags;
  3182. if (orinoco_lock(priv, &flags) != 0)
  3183. return -EBUSY;
  3184. if (prq->disabled) {
  3185. priv->pm_on = 0;
  3186. } else {
  3187. switch (prq->flags & IW_POWER_MODE) {
  3188. case IW_POWER_UNICAST_R:
  3189. priv->pm_mcast = 0;
  3190. priv->pm_on = 1;
  3191. break;
  3192. case IW_POWER_ALL_R:
  3193. priv->pm_mcast = 1;
  3194. priv->pm_on = 1;
  3195. break;
  3196. case IW_POWER_ON:
  3197. /* No flags : but we may have a value - Jean II */
  3198. break;
  3199. default:
  3200. err = -EINVAL;
  3201. }
  3202. if (err)
  3203. goto out;
  3204. if (prq->flags & IW_POWER_TIMEOUT) {
  3205. priv->pm_on = 1;
  3206. priv->pm_timeout = prq->value / 1000;
  3207. }
  3208. if (prq->flags & IW_POWER_PERIOD) {
  3209. priv->pm_on = 1;
  3210. priv->pm_period = prq->value / 1000;
  3211. }
  3212. /* It's valid to not have a value if we are just toggling
  3213. * the flags... Jean II */
  3214. if(!priv->pm_on) {
  3215. err = -EINVAL;
  3216. goto out;
  3217. }
  3218. }
  3219. out:
  3220. orinoco_unlock(priv, &flags);
  3221. return err;
  3222. }
  3223. static int orinoco_ioctl_getpower(struct net_device *dev,
  3224. struct iw_request_info *info,
  3225. struct iw_param *prq,
  3226. char *extra)
  3227. {
  3228. struct orinoco_private *priv = netdev_priv(dev);
  3229. hermes_t *hw = &priv->hw;
  3230. int err = 0;
  3231. u16 enable, period, timeout, mcast;
  3232. unsigned long flags;
  3233. if (orinoco_lock(priv, &flags) != 0)
  3234. return -EBUSY;
  3235. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFPMENABLED, &enable);
  3236. if (err)
  3237. goto out;
  3238. err = hermes_read_wordrec(hw, USER_BAP,
  3239. HERMES_RID_CNFMAXSLEEPDURATION, &period);
  3240. if (err)
  3241. goto out;
  3242. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFPMHOLDOVERDURATION, &timeout);
  3243. if (err)
  3244. goto out;
  3245. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFMULTICASTRECEIVE, &mcast);
  3246. if (err)
  3247. goto out;
  3248. prq->disabled = !enable;
  3249. /* Note : by default, display the period */
  3250. if ((prq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
  3251. prq->flags = IW_POWER_TIMEOUT;
  3252. prq->value = timeout * 1000;
  3253. } else {
  3254. prq->flags = IW_POWER_PERIOD;
  3255. prq->value = period * 1000;
  3256. }
  3257. if (mcast)
  3258. prq->flags |= IW_POWER_ALL_R;
  3259. else
  3260. prq->flags |= IW_POWER_UNICAST_R;
  3261. out:
  3262. orinoco_unlock(priv, &flags);
  3263. return err;
  3264. }
  3265. static int orinoco_ioctl_getretry(struct net_device *dev,
  3266. struct iw_request_info *info,
  3267. struct iw_param *rrq,
  3268. char *extra)
  3269. {
  3270. struct orinoco_private *priv = netdev_priv(dev);
  3271. hermes_t *hw = &priv->hw;
  3272. int err = 0;
  3273. u16 short_limit, long_limit, lifetime;
  3274. unsigned long flags;
  3275. if (orinoco_lock(priv, &flags) != 0)
  3276. return -EBUSY;
  3277. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_SHORTRETRYLIMIT,
  3278. &short_limit);
  3279. if (err)
  3280. goto out;
  3281. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_LONGRETRYLIMIT,
  3282. &long_limit);
  3283. if (err)
  3284. goto out;
  3285. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_MAXTRANSMITLIFETIME,
  3286. &lifetime);
  3287. if (err)
  3288. goto out;
  3289. rrq->disabled = 0; /* Can't be disabled */
  3290. /* Note : by default, display the retry number */
  3291. if ((rrq->flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
  3292. rrq->flags = IW_RETRY_LIFETIME;
  3293. rrq->value = lifetime * 1000; /* ??? */
  3294. } else {
  3295. /* By default, display the min number */
  3296. if ((rrq->flags & IW_RETRY_MAX)) {
  3297. rrq->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
  3298. rrq->value = long_limit;
  3299. } else {
  3300. rrq->flags = IW_RETRY_LIMIT;
  3301. rrq->value = short_limit;
  3302. if(short_limit != long_limit)
  3303. rrq->flags |= IW_RETRY_MIN;
  3304. }
  3305. }
  3306. out:
  3307. orinoco_unlock(priv, &flags);
  3308. return err;
  3309. }
  3310. static int orinoco_ioctl_reset(struct net_device *dev,
  3311. struct iw_request_info *info,
  3312. void *wrqu,
  3313. char *extra)
  3314. {
  3315. struct orinoco_private *priv = netdev_priv(dev);
  3316. if (! capable(CAP_NET_ADMIN))
  3317. return -EPERM;
  3318. if (info->cmd == (SIOCIWFIRSTPRIV + 0x1)) {
  3319. printk(KERN_DEBUG "%s: Forcing reset!\n", dev->name);
  3320. /* Firmware reset */
  3321. orinoco_reset(dev);
  3322. } else {
  3323. printk(KERN_DEBUG "%s: Force scheduling reset!\n", dev->name);
  3324. schedule_work(&priv->reset_work);
  3325. }
  3326. return 0;
  3327. }
  3328. static int orinoco_ioctl_setibssport(struct net_device *dev,
  3329. struct iw_request_info *info,
  3330. void *wrqu,
  3331. char *extra)
  3332. {
  3333. struct orinoco_private *priv = netdev_priv(dev);
  3334. int val = *( (int *) extra );
  3335. unsigned long flags;
  3336. if (orinoco_lock(priv, &flags) != 0)
  3337. return -EBUSY;
  3338. priv->ibss_port = val ;
  3339. /* Actually update the mode we are using */
  3340. set_port_type(priv);
  3341. orinoco_unlock(priv, &flags);
  3342. return -EINPROGRESS; /* Call commit handler */
  3343. }
  3344. static int orinoco_ioctl_getibssport(struct net_device *dev,
  3345. struct iw_request_info *info,
  3346. void *wrqu,
  3347. char *extra)
  3348. {
  3349. struct orinoco_private *priv = netdev_priv(dev);
  3350. int *val = (int *) extra;
  3351. *val = priv->ibss_port;
  3352. return 0;
  3353. }
  3354. static int orinoco_ioctl_setport3(struct net_device *dev,
  3355. struct iw_request_info *info,
  3356. void *wrqu,
  3357. char *extra)
  3358. {
  3359. struct orinoco_private *priv = netdev_priv(dev);
  3360. int val = *( (int *) extra );
  3361. int err = 0;
  3362. unsigned long flags;
  3363. if (orinoco_lock(priv, &flags) != 0)
  3364. return -EBUSY;
  3365. switch (val) {
  3366. case 0: /* Try to do IEEE ad-hoc mode */
  3367. if (! priv->has_ibss) {
  3368. err = -EINVAL;
  3369. break;
  3370. }
  3371. priv->prefer_port3 = 0;
  3372. break;
  3373. case 1: /* Try to do Lucent proprietary ad-hoc mode */
  3374. if (! priv->has_port3) {
  3375. err = -EINVAL;
  3376. break;
  3377. }
  3378. priv->prefer_port3 = 1;
  3379. break;
  3380. default:
  3381. err = -EINVAL;
  3382. }
  3383. if (! err) {
  3384. /* Actually update the mode we are using */
  3385. set_port_type(priv);
  3386. err = -EINPROGRESS;
  3387. }
  3388. orinoco_unlock(priv, &flags);
  3389. return err;
  3390. }
  3391. static int orinoco_ioctl_getport3(struct net_device *dev,
  3392. struct iw_request_info *info,
  3393. void *wrqu,
  3394. char *extra)
  3395. {
  3396. struct orinoco_private *priv = netdev_priv(dev);
  3397. int *val = (int *) extra;
  3398. *val = priv->prefer_port3;
  3399. return 0;
  3400. }
  3401. static int orinoco_ioctl_setpreamble(struct net_device *dev,
  3402. struct iw_request_info *info,
  3403. void *wrqu,
  3404. char *extra)
  3405. {
  3406. struct orinoco_private *priv = netdev_priv(dev);
  3407. unsigned long flags;
  3408. int val;
  3409. if (! priv->has_preamble)
  3410. return -EOPNOTSUPP;
  3411. /* 802.11b has recently defined some short preamble.
  3412. * Basically, the Phy header has been reduced in size.
  3413. * This increase performance, especially at high rates
  3414. * (the preamble is transmitted at 1Mb/s), unfortunately
  3415. * this give compatibility troubles... - Jean II */
  3416. val = *( (int *) extra );
  3417. if (orinoco_lock(priv, &flags) != 0)
  3418. return -EBUSY;
  3419. if (val)
  3420. priv->preamble = 1;
  3421. else
  3422. priv->preamble = 0;
  3423. orinoco_unlock(priv, &flags);
  3424. return -EINPROGRESS; /* Call commit handler */
  3425. }
  3426. static int orinoco_ioctl_getpreamble(struct net_device *dev,
  3427. struct iw_request_info *info,
  3428. void *wrqu,
  3429. char *extra)
  3430. {
  3431. struct orinoco_private *priv = netdev_priv(dev);
  3432. int *val = (int *) extra;
  3433. if (! priv->has_preamble)
  3434. return -EOPNOTSUPP;
  3435. *val = priv->preamble;
  3436. return 0;
  3437. }
  3438. /* ioctl interface to hermes_read_ltv()
  3439. * To use with iwpriv, pass the RID as the token argument, e.g.
  3440. * iwpriv get_rid [0xfc00]
  3441. * At least Wireless Tools 25 is required to use iwpriv.
  3442. * For Wireless Tools 25 and 26 append "dummy" are the end. */
  3443. static int orinoco_ioctl_getrid(struct net_device *dev,
  3444. struct iw_request_info *info,
  3445. struct iw_point *data,
  3446. char *extra)
  3447. {
  3448. struct orinoco_private *priv = netdev_priv(dev);
  3449. hermes_t *hw = &priv->hw;
  3450. int rid = data->flags;
  3451. u16 length;
  3452. int err;
  3453. unsigned long flags;
  3454. /* It's a "get" function, but we don't want users to access the
  3455. * WEP key and other raw firmware data */
  3456. if (! capable(CAP_NET_ADMIN))
  3457. return -EPERM;
  3458. if (rid < 0xfc00 || rid > 0xffff)
  3459. return -EINVAL;
  3460. if (orinoco_lock(priv, &flags) != 0)
  3461. return -EBUSY;
  3462. err = hermes_read_ltv(hw, USER_BAP, rid, MAX_RID_LEN, &length,
  3463. extra);
  3464. if (err)
  3465. goto out;
  3466. data->length = min_t(u16, HERMES_RECLEN_TO_BYTES(length),
  3467. MAX_RID_LEN);
  3468. out:
  3469. orinoco_unlock(priv, &flags);
  3470. return err;
  3471. }
  3472. /* Spy is used for link quality/strength measurements in Ad-Hoc mode
  3473. * Jean II */
  3474. static int orinoco_ioctl_setspy(struct net_device *dev,
  3475. struct iw_request_info *info,
  3476. struct iw_point *srq,
  3477. char *extra)
  3478. {
  3479. struct orinoco_private *priv = netdev_priv(dev);
  3480. struct sockaddr *address = (struct sockaddr *) extra;
  3481. int number = srq->length;
  3482. int i;
  3483. unsigned long flags;
  3484. /* Make sure nobody mess with the structure while we do */
  3485. if (orinoco_lock(priv, &flags) != 0)
  3486. return -EBUSY;
  3487. /* orinoco_lock() doesn't disable interrupts, so make sure the
  3488. * interrupt rx path don't get confused while we copy */
  3489. priv->spy_number = 0;
  3490. if (number > 0) {
  3491. /* Extract the addresses */
  3492. for (i = 0; i < number; i++)
  3493. memcpy(priv->spy_address[i], address[i].sa_data,
  3494. ETH_ALEN);
  3495. /* Reset stats */
  3496. memset(priv->spy_stat, 0,
  3497. sizeof(struct iw_quality) * IW_MAX_SPY);
  3498. /* Set number of addresses */
  3499. priv->spy_number = number;
  3500. }
  3501. /* Now, let the others play */
  3502. orinoco_unlock(priv, &flags);
  3503. /* Do NOT call commit handler */
  3504. return 0;
  3505. }
  3506. static int orinoco_ioctl_getspy(struct net_device *dev,
  3507. struct iw_request_info *info,
  3508. struct iw_point *srq,
  3509. char *extra)
  3510. {
  3511. struct orinoco_private *priv = netdev_priv(dev);
  3512. struct sockaddr *address = (struct sockaddr *) extra;
  3513. int number;
  3514. int i;
  3515. unsigned long flags;
  3516. if (orinoco_lock(priv, &flags) != 0)
  3517. return -EBUSY;
  3518. number = priv->spy_number;
  3519. /* Create address struct */
  3520. for (i = 0; i < number; i++) {
  3521. memcpy(address[i].sa_data, priv->spy_address[i], ETH_ALEN);
  3522. address[i].sa_family = AF_UNIX;
  3523. }
  3524. if (number > 0) {
  3525. /* Create address struct */
  3526. for (i = 0; i < number; i++) {
  3527. memcpy(address[i].sa_data, priv->spy_address[i],
  3528. ETH_ALEN);
  3529. address[i].sa_family = AF_UNIX;
  3530. }
  3531. /* Copy stats */
  3532. /* In theory, we should disable irqs while copying the stats
  3533. * because the rx path might update it in the middle...
  3534. * Bah, who care ? - Jean II */
  3535. memcpy(extra + (sizeof(struct sockaddr) * number),
  3536. priv->spy_stat, sizeof(struct iw_quality) * number);
  3537. }
  3538. /* Reset updated flags. */
  3539. for (i = 0; i < number; i++)
  3540. priv->spy_stat[i].updated = 0;
  3541. orinoco_unlock(priv, &flags);
  3542. srq->length = number;
  3543. return 0;
  3544. }
  3545. /* Trigger a scan (look for other cells in the vicinity */
  3546. static int orinoco_ioctl_setscan(struct net_device *dev,
  3547. struct iw_request_info *info,
  3548. struct iw_param *srq,
  3549. char *extra)
  3550. {
  3551. struct orinoco_private *priv = netdev_priv(dev);
  3552. hermes_t *hw = &priv->hw;
  3553. int err = 0;
  3554. unsigned long flags;
  3555. /* Note : you may have realised that, as this is a SET operation,
  3556. * this is priviledged and therefore a normal user can't
  3557. * perform scanning.
  3558. * This is not an error, while the device perform scanning,
  3559. * traffic doesn't flow, so it's a perfect DoS...
  3560. * Jean II */
  3561. if (orinoco_lock(priv, &flags) != 0)
  3562. return -EBUSY;
  3563. /* Scanning with port 0 disabled would fail */
  3564. if (!netif_running(dev)) {
  3565. err = -ENETDOWN;
  3566. goto out;
  3567. }
  3568. /* In monitor mode, the scan results are always empty.
  3569. * Probe responses are passed to the driver as received
  3570. * frames and could be processed in software. */
  3571. if (priv->iw_mode == IW_MODE_MONITOR) {
  3572. err = -EOPNOTSUPP;
  3573. goto out;
  3574. }
  3575. /* Note : because we don't lock out the irq handler, the way
  3576. * we access scan variables in priv is critical.
  3577. * o scan_inprogress : not touched by irq handler
  3578. * o scan_mode : not touched by irq handler
  3579. * o scan_result : irq is strict producer, non-irq is strict
  3580. * consumer.
  3581. * o scan_len : synchronised with scan_result
  3582. * Before modifying anything on those variables, please think hard !
  3583. * Jean II */
  3584. /* If there is still some left-over scan results, get rid of it */
  3585. if (priv->scan_result != NULL) {
  3586. /* What's likely is that a client did crash or was killed
  3587. * between triggering the scan request and reading the
  3588. * results, so we need to reset everything.
  3589. * Some clients that are too slow may suffer from that...
  3590. * Jean II */
  3591. kfree(priv->scan_result);
  3592. priv->scan_result = NULL;
  3593. }
  3594. /* Save flags */
  3595. priv->scan_mode = srq->flags;
  3596. /* Always trigger scanning, even if it's in progress.
  3597. * This way, if the info frame get lost, we will recover somewhat
  3598. * gracefully - Jean II */
  3599. if (priv->has_hostscan) {
  3600. switch (priv->firmware_type) {
  3601. case FIRMWARE_TYPE_SYMBOL:
  3602. err = hermes_write_wordrec(hw, USER_BAP,
  3603. HERMES_RID_CNFHOSTSCAN_SYMBOL,
  3604. HERMES_HOSTSCAN_SYMBOL_ONCE |
  3605. HERMES_HOSTSCAN_SYMBOL_BCAST);
  3606. break;
  3607. case FIRMWARE_TYPE_INTERSIL: {
  3608. u16 req[3];
  3609. req[0] = cpu_to_le16(0x3fff); /* All channels */
  3610. req[1] = cpu_to_le16(0x0001); /* rate 1 Mbps */
  3611. req[2] = 0; /* Any ESSID */
  3612. err = HERMES_WRITE_RECORD(hw, USER_BAP,
  3613. HERMES_RID_CNFHOSTSCAN, &req);
  3614. }
  3615. break;
  3616. case FIRMWARE_TYPE_AGERE:
  3617. err = hermes_write_wordrec(hw, USER_BAP,
  3618. HERMES_RID_CNFSCANSSID_AGERE,
  3619. 0); /* Any ESSID */
  3620. if (err)
  3621. break;
  3622. err = hermes_inquire(hw, HERMES_INQ_SCAN);
  3623. break;
  3624. }
  3625. } else
  3626. err = hermes_inquire(hw, HERMES_INQ_SCAN);
  3627. /* One more client */
  3628. if (! err)
  3629. priv->scan_inprogress = 1;
  3630. out:
  3631. orinoco_unlock(priv, &flags);
  3632. return err;
  3633. }
  3634. /* Translate scan data returned from the card to a card independant
  3635. * format that the Wireless Tools will understand - Jean II */
  3636. static inline int orinoco_translate_scan(struct net_device *dev,
  3637. char *buffer,
  3638. char *scan,
  3639. int scan_len)
  3640. {
  3641. struct orinoco_private *priv = netdev_priv(dev);
  3642. int offset; /* In the scan data */
  3643. union hermes_scan_info *atom;
  3644. int atom_len;
  3645. u16 capabilities;
  3646. u16 channel;
  3647. struct iw_event iwe; /* Temporary buffer */
  3648. char * current_ev = buffer;
  3649. char * end_buf = buffer + IW_SCAN_MAX_DATA;
  3650. switch (priv->firmware_type) {
  3651. case FIRMWARE_TYPE_AGERE:
  3652. atom_len = sizeof(struct agere_scan_apinfo);
  3653. offset = 0;
  3654. break;
  3655. case FIRMWARE_TYPE_SYMBOL:
  3656. /* Lack of documentation necessitates this hack.
  3657. * Different firmwares have 68 or 76 byte long atoms.
  3658. * We try modulo first. If the length divides by both,
  3659. * we check what would be the channel in the second
  3660. * frame for a 68-byte atom. 76-byte atoms have 0 there.
  3661. * Valid channel cannot be 0. */
  3662. if (scan_len % 76)
  3663. atom_len = 68;
  3664. else if (scan_len % 68)
  3665. atom_len = 76;
  3666. else if (scan_len >= 1292 && scan[68] == 0)
  3667. atom_len = 76;
  3668. else
  3669. atom_len = 68;
  3670. offset = 0;
  3671. break;
  3672. case FIRMWARE_TYPE_INTERSIL:
  3673. offset = 4;
  3674. if (priv->has_hostscan)
  3675. atom_len = scan[0] + (scan[1] << 8);
  3676. else
  3677. atom_len = offsetof(struct prism2_scan_apinfo, atim);
  3678. break;
  3679. default:
  3680. return 0;
  3681. }
  3682. /* Check that we got an whole number of atoms */
  3683. if ((scan_len - offset) % atom_len) {
  3684. printk(KERN_ERR "%s: Unexpected scan data length %d, "
  3685. "atom_len %d, offset %d\n", dev->name, scan_len,
  3686. atom_len, offset);
  3687. return 0;
  3688. }
  3689. /* Read the entries one by one */
  3690. for (; offset + atom_len <= scan_len; offset += atom_len) {
  3691. /* Get next atom */
  3692. atom = (union hermes_scan_info *) (scan + offset);
  3693. /* First entry *MUST* be the AP MAC address */
  3694. iwe.cmd = SIOCGIWAP;
  3695. iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
  3696. memcpy(iwe.u.ap_addr.sa_data, atom->a.bssid, ETH_ALEN);
  3697. current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_ADDR_LEN);
  3698. /* Other entries will be displayed in the order we give them */
  3699. /* Add the ESSID */
  3700. iwe.u.data.length = le16_to_cpu(atom->a.essid_len);
  3701. if (iwe.u.data.length > 32)
  3702. iwe.u.data.length = 32;
  3703. iwe.cmd = SIOCGIWESSID;
  3704. iwe.u.data.flags = 1;
  3705. current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, atom->a.essid);
  3706. /* Add mode */
  3707. iwe.cmd = SIOCGIWMODE;
  3708. capabilities = le16_to_cpu(atom->a.capabilities);
  3709. if (capabilities & 0x3) {
  3710. if (capabilities & 0x1)
  3711. iwe.u.mode = IW_MODE_MASTER;
  3712. else
  3713. iwe.u.mode = IW_MODE_ADHOC;
  3714. current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_UINT_LEN);
  3715. }
  3716. channel = atom->s.channel;
  3717. if ( (channel >= 1) && (channel <= NUM_CHANNELS) ) {
  3718. /* Add frequency */
  3719. iwe.cmd = SIOCGIWFREQ;
  3720. iwe.u.freq.m = channel_frequency[channel-1] * 100000;
  3721. iwe.u.freq.e = 1;
  3722. current_ev = iwe_stream_add_event(current_ev, end_buf,
  3723. &iwe, IW_EV_FREQ_LEN);
  3724. }
  3725. /* Add quality statistics */
  3726. iwe.cmd = IWEVQUAL;
  3727. iwe.u.qual.updated = 0x10; /* no link quality */
  3728. iwe.u.qual.level = (__u8) le16_to_cpu(atom->a.level) - 0x95;
  3729. iwe.u.qual.noise = (__u8) le16_to_cpu(atom->a.noise) - 0x95;
  3730. /* Wireless tools prior to 27.pre22 will show link quality
  3731. * anyway, so we provide a reasonable value. */
  3732. if (iwe.u.qual.level > iwe.u.qual.noise)
  3733. iwe.u.qual.qual = iwe.u.qual.level - iwe.u.qual.noise;
  3734. else
  3735. iwe.u.qual.qual = 0;
  3736. current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_QUAL_LEN);
  3737. /* Add encryption capability */
  3738. iwe.cmd = SIOCGIWENCODE;
  3739. if (capabilities & 0x10)
  3740. iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
  3741. else
  3742. iwe.u.data.flags = IW_ENCODE_DISABLED;
  3743. iwe.u.data.length = 0;
  3744. current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, atom->a.essid);
  3745. /* Bit rate is not available in Lucent/Agere firmwares */
  3746. if (priv->firmware_type != FIRMWARE_TYPE_AGERE) {
  3747. char * current_val = current_ev + IW_EV_LCP_LEN;
  3748. int i;
  3749. int step;
  3750. if (priv->firmware_type == FIRMWARE_TYPE_SYMBOL)
  3751. step = 2;
  3752. else
  3753. step = 1;
  3754. iwe.cmd = SIOCGIWRATE;
  3755. /* Those two flags are ignored... */
  3756. iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
  3757. /* Max 10 values */
  3758. for (i = 0; i < 10; i += step) {
  3759. /* NULL terminated */
  3760. if (atom->p.rates[i] == 0x0)
  3761. break;
  3762. /* Bit rate given in 500 kb/s units (+ 0x80) */
  3763. iwe.u.bitrate.value = ((atom->p.rates[i] & 0x7f) * 500000);
  3764. current_val = iwe_stream_add_value(current_ev, current_val,
  3765. end_buf, &iwe,
  3766. IW_EV_PARAM_LEN);
  3767. }
  3768. /* Check if we added any event */
  3769. if ((current_val - current_ev) > IW_EV_LCP_LEN)
  3770. current_ev = current_val;
  3771. }
  3772. /* The other data in the scan result are not really
  3773. * interesting, so for now drop it - Jean II */
  3774. }
  3775. return current_ev - buffer;
  3776. }
  3777. /* Return results of a scan */
  3778. static int orinoco_ioctl_getscan(struct net_device *dev,
  3779. struct iw_request_info *info,
  3780. struct iw_point *srq,
  3781. char *extra)
  3782. {
  3783. struct orinoco_private *priv = netdev_priv(dev);
  3784. int err = 0;
  3785. unsigned long flags;
  3786. if (orinoco_lock(priv, &flags) != 0)
  3787. return -EBUSY;
  3788. /* If no results yet, ask to try again later */
  3789. if (priv->scan_result == NULL) {
  3790. if (priv->scan_inprogress)
  3791. /* Important note : we don't want to block the caller
  3792. * until results are ready for various reasons.
  3793. * First, managing wait queues is complex and racy.
  3794. * Second, we grab some rtnetlink lock before comming
  3795. * here (in dev_ioctl()).
  3796. * Third, we generate an Wireless Event, so the
  3797. * caller can wait itself on that - Jean II */
  3798. err = -EAGAIN;
  3799. else
  3800. /* Client error, no scan results...
  3801. * The caller need to restart the scan. */
  3802. err = -ENODATA;
  3803. } else {
  3804. /* We have some results to push back to user space */
  3805. /* Translate to WE format */
  3806. srq->length = orinoco_translate_scan(dev, extra,
  3807. priv->scan_result,
  3808. priv->scan_len);
  3809. /* Return flags */
  3810. srq->flags = (__u16) priv->scan_mode;
  3811. /* Results are here, so scan no longer in progress */
  3812. priv->scan_inprogress = 0;
  3813. /* In any case, Scan results will be cleaned up in the
  3814. * reset function and when exiting the driver.
  3815. * The person triggering the scanning may never come to
  3816. * pick the results, so we need to do it in those places.
  3817. * Jean II */
  3818. #ifdef SCAN_SINGLE_READ
  3819. /* If you enable this option, only one client (the first
  3820. * one) will be able to read the result (and only one
  3821. * time). If there is multiple concurent clients that
  3822. * want to read scan results, this behavior is not
  3823. * advisable - Jean II */
  3824. kfree(priv->scan_result);
  3825. priv->scan_result = NULL;
  3826. #endif /* SCAN_SINGLE_READ */
  3827. /* Here, if too much time has elapsed since last scan,
  3828. * we may want to clean up scan results... - Jean II */
  3829. }
  3830. orinoco_unlock(priv, &flags);
  3831. return err;
  3832. }
  3833. /* Commit handler, called after set operations */
  3834. static int orinoco_ioctl_commit(struct net_device *dev,
  3835. struct iw_request_info *info,
  3836. void *wrqu,
  3837. char *extra)
  3838. {
  3839. struct orinoco_private *priv = netdev_priv(dev);
  3840. struct hermes *hw = &priv->hw;
  3841. unsigned long flags;
  3842. int err = 0;
  3843. if (!priv->open)
  3844. return 0;
  3845. if (priv->broken_disableport) {
  3846. orinoco_reset(dev);
  3847. return 0;
  3848. }
  3849. if (orinoco_lock(priv, &flags) != 0)
  3850. return err;
  3851. err = hermes_disable_port(hw, 0);
  3852. if (err) {
  3853. printk(KERN_WARNING "%s: Unable to disable port "
  3854. "while reconfiguring card\n", dev->name);
  3855. priv->broken_disableport = 1;
  3856. goto out;
  3857. }
  3858. err = __orinoco_program_rids(dev);
  3859. if (err) {
  3860. printk(KERN_WARNING "%s: Unable to reconfigure card\n",
  3861. dev->name);
  3862. goto out;
  3863. }
  3864. err = hermes_enable_port(hw, 0);
  3865. if (err) {
  3866. printk(KERN_WARNING "%s: Unable to enable port while reconfiguring card\n",
  3867. dev->name);
  3868. goto out;
  3869. }
  3870. out:
  3871. if (err) {
  3872. printk(KERN_WARNING "%s: Resetting instead...\n", dev->name);
  3873. schedule_work(&priv->reset_work);
  3874. err = 0;
  3875. }
  3876. orinoco_unlock(priv, &flags);
  3877. return err;
  3878. }
  3879. static const struct iw_priv_args orinoco_privtab[] = {
  3880. { SIOCIWFIRSTPRIV + 0x0, 0, 0, "force_reset" },
  3881. { SIOCIWFIRSTPRIV + 0x1, 0, 0, "card_reset" },
  3882. { SIOCIWFIRSTPRIV + 0x2, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  3883. 0, "set_port3" },
  3884. { SIOCIWFIRSTPRIV + 0x3, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  3885. "get_port3" },
  3886. { SIOCIWFIRSTPRIV + 0x4, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  3887. 0, "set_preamble" },
  3888. { SIOCIWFIRSTPRIV + 0x5, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  3889. "get_preamble" },
  3890. { SIOCIWFIRSTPRIV + 0x6, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  3891. 0, "set_ibssport" },
  3892. { SIOCIWFIRSTPRIV + 0x7, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  3893. "get_ibssport" },
  3894. { SIOCIWFIRSTPRIV + 0x9, 0, IW_PRIV_TYPE_BYTE | MAX_RID_LEN,
  3895. "get_rid" },
  3896. };
  3897. /*
  3898. * Structures to export the Wireless Handlers
  3899. */
  3900. static const iw_handler orinoco_handler[] = {
  3901. [SIOCSIWCOMMIT-SIOCIWFIRST] (iw_handler) orinoco_ioctl_commit,
  3902. [SIOCGIWNAME -SIOCIWFIRST] (iw_handler) orinoco_ioctl_getname,
  3903. [SIOCSIWFREQ -SIOCIWFIRST] (iw_handler) orinoco_ioctl_setfreq,
  3904. [SIOCGIWFREQ -SIOCIWFIRST] (iw_handler) orinoco_ioctl_getfreq,
  3905. [SIOCSIWMODE -SIOCIWFIRST] (iw_handler) orinoco_ioctl_setmode,
  3906. [SIOCGIWMODE -SIOCIWFIRST] (iw_handler) orinoco_ioctl_getmode,
  3907. [SIOCSIWSENS -SIOCIWFIRST] (iw_handler) orinoco_ioctl_setsens,
  3908. [SIOCGIWSENS -SIOCIWFIRST] (iw_handler) orinoco_ioctl_getsens,
  3909. [SIOCGIWRANGE -SIOCIWFIRST] (iw_handler) orinoco_ioctl_getiwrange,
  3910. [SIOCSIWSPY -SIOCIWFIRST] (iw_handler) orinoco_ioctl_setspy,
  3911. [SIOCGIWSPY -SIOCIWFIRST] (iw_handler) orinoco_ioctl_getspy,
  3912. [SIOCSIWAP -SIOCIWFIRST] (iw_handler) orinoco_ioctl_setwap,
  3913. [SIOCGIWAP -SIOCIWFIRST] (iw_handler) orinoco_ioctl_getwap,
  3914. [SIOCSIWSCAN -SIOCIWFIRST] (iw_handler) orinoco_ioctl_setscan,
  3915. [SIOCGIWSCAN -SIOCIWFIRST] (iw_handler) orinoco_ioctl_getscan,
  3916. [SIOCSIWESSID -SIOCIWFIRST] (iw_handler) orinoco_ioctl_setessid,
  3917. [SIOCGIWESSID -SIOCIWFIRST] (iw_handler) orinoco_ioctl_getessid,
  3918. [SIOCSIWNICKN -SIOCIWFIRST] (iw_handler) orinoco_ioctl_setnick,
  3919. [SIOCGIWNICKN -SIOCIWFIRST] (iw_handler) orinoco_ioctl_getnick,
  3920. [SIOCSIWRATE -SIOCIWFIRST] (iw_handler) orinoco_ioctl_setrate,
  3921. [SIOCGIWRATE -SIOCIWFIRST] (iw_handler) orinoco_ioctl_getrate,
  3922. [SIOCSIWRTS -SIOCIWFIRST] (iw_handler) orinoco_ioctl_setrts,
  3923. [SIOCGIWRTS -SIOCIWFIRST] (iw_handler) orinoco_ioctl_getrts,
  3924. [SIOCSIWFRAG -SIOCIWFIRST] (iw_handler) orinoco_ioctl_setfrag,
  3925. [SIOCGIWFRAG -SIOCIWFIRST] (iw_handler) orinoco_ioctl_getfrag,
  3926. [SIOCGIWRETRY -SIOCIWFIRST] (iw_handler) orinoco_ioctl_getretry,
  3927. [SIOCSIWENCODE-SIOCIWFIRST] (iw_handler) orinoco_ioctl_setiwencode,
  3928. [SIOCGIWENCODE-SIOCIWFIRST] (iw_handler) orinoco_ioctl_getiwencode,
  3929. [SIOCSIWPOWER -SIOCIWFIRST] (iw_handler) orinoco_ioctl_setpower,
  3930. [SIOCGIWPOWER -SIOCIWFIRST] (iw_handler) orinoco_ioctl_getpower,
  3931. };
  3932. /*
  3933. Added typecasting since we no longer use iwreq_data -- Moustafa
  3934. */
  3935. static const iw_handler orinoco_private_handler[] = {
  3936. [0] (iw_handler) orinoco_ioctl_reset,
  3937. [1] (iw_handler) orinoco_ioctl_reset,
  3938. [2] (iw_handler) orinoco_ioctl_setport3,
  3939. [3] (iw_handler) orinoco_ioctl_getport3,
  3940. [4] (iw_handler) orinoco_ioctl_setpreamble,
  3941. [5] (iw_handler) orinoco_ioctl_getpreamble,
  3942. [6] (iw_handler) orinoco_ioctl_setibssport,
  3943. [7] (iw_handler) orinoco_ioctl_getibssport,
  3944. [9] (iw_handler) orinoco_ioctl_getrid,
  3945. };
  3946. static const struct iw_handler_def orinoco_handler_def = {
  3947. .num_standard = ARRAY_SIZE(orinoco_handler),
  3948. .num_private = ARRAY_SIZE(orinoco_private_handler),
  3949. .num_private_args = ARRAY_SIZE(orinoco_privtab),
  3950. .standard = orinoco_handler,
  3951. .private = orinoco_private_handler,
  3952. .private_args = orinoco_privtab,
  3953. };
  3954. static void orinoco_get_drvinfo(struct net_device *dev,
  3955. struct ethtool_drvinfo *info)
  3956. {
  3957. struct orinoco_private *priv = netdev_priv(dev);
  3958. strncpy(info->driver, DRIVER_NAME, sizeof(info->driver) - 1);
  3959. strncpy(info->version, DRIVER_VERSION, sizeof(info->version) - 1);
  3960. strncpy(info->fw_version, priv->fw_name, sizeof(info->fw_version) - 1);
  3961. if (dev->class_dev.dev)
  3962. strncpy(info->bus_info, dev->class_dev.dev->bus_id,
  3963. sizeof(info->bus_info) - 1);
  3964. else
  3965. snprintf(info->bus_info, sizeof(info->bus_info) - 1,
  3966. "PCMCIA %p", priv->hw.iobase);
  3967. }
  3968. static struct ethtool_ops orinoco_ethtool_ops = {
  3969. .get_drvinfo = orinoco_get_drvinfo,
  3970. .get_link = ethtool_op_get_link,
  3971. };
  3972. /********************************************************************/
  3973. /* Debugging */
  3974. /********************************************************************/
  3975. #if 0
  3976. static void show_rx_frame(struct orinoco_rxframe_hdr *frame)
  3977. {
  3978. printk(KERN_DEBUG "RX descriptor:\n");
  3979. printk(KERN_DEBUG " status = 0x%04x\n", frame->desc.status);
  3980. printk(KERN_DEBUG " time = 0x%08x\n", frame->desc.time);
  3981. printk(KERN_DEBUG " silence = 0x%02x\n", frame->desc.silence);
  3982. printk(KERN_DEBUG " signal = 0x%02x\n", frame->desc.signal);
  3983. printk(KERN_DEBUG " rate = 0x%02x\n", frame->desc.rate);
  3984. printk(KERN_DEBUG " rxflow = 0x%02x\n", frame->desc.rxflow);
  3985. printk(KERN_DEBUG " reserved = 0x%08x\n", frame->desc.reserved);
  3986. printk(KERN_DEBUG "IEEE 802.11 header:\n");
  3987. printk(KERN_DEBUG " frame_ctl = 0x%04x\n",
  3988. frame->p80211.frame_ctl);
  3989. printk(KERN_DEBUG " duration_id = 0x%04x\n",
  3990. frame->p80211.duration_id);
  3991. printk(KERN_DEBUG " addr1 = %02x:%02x:%02x:%02x:%02x:%02x\n",
  3992. frame->p80211.addr1[0], frame->p80211.addr1[1],
  3993. frame->p80211.addr1[2], frame->p80211.addr1[3],
  3994. frame->p80211.addr1[4], frame->p80211.addr1[5]);
  3995. printk(KERN_DEBUG " addr2 = %02x:%02x:%02x:%02x:%02x:%02x\n",
  3996. frame->p80211.addr2[0], frame->p80211.addr2[1],
  3997. frame->p80211.addr2[2], frame->p80211.addr2[3],
  3998. frame->p80211.addr2[4], frame->p80211.addr2[5]);
  3999. printk(KERN_DEBUG " addr3 = %02x:%02x:%02x:%02x:%02x:%02x\n",
  4000. frame->p80211.addr3[0], frame->p80211.addr3[1],
  4001. frame->p80211.addr3[2], frame->p80211.addr3[3],
  4002. frame->p80211.addr3[4], frame->p80211.addr3[5]);
  4003. printk(KERN_DEBUG " seq_ctl = 0x%04x\n",
  4004. frame->p80211.seq_ctl);
  4005. printk(KERN_DEBUG " addr4 = %02x:%02x:%02x:%02x:%02x:%02x\n",
  4006. frame->p80211.addr4[0], frame->p80211.addr4[1],
  4007. frame->p80211.addr4[2], frame->p80211.addr4[3],
  4008. frame->p80211.addr4[4], frame->p80211.addr4[5]);
  4009. printk(KERN_DEBUG " data_len = 0x%04x\n",
  4010. frame->p80211.data_len);
  4011. printk(KERN_DEBUG "IEEE 802.3 header:\n");
  4012. printk(KERN_DEBUG " dest = %02x:%02x:%02x:%02x:%02x:%02x\n",
  4013. frame->p8023.h_dest[0], frame->p8023.h_dest[1],
  4014. frame->p8023.h_dest[2], frame->p8023.h_dest[3],
  4015. frame->p8023.h_dest[4], frame->p8023.h_dest[5]);
  4016. printk(KERN_DEBUG " src = %02x:%02x:%02x:%02x:%02x:%02x\n",
  4017. frame->p8023.h_source[0], frame->p8023.h_source[1],
  4018. frame->p8023.h_source[2], frame->p8023.h_source[3],
  4019. frame->p8023.h_source[4], frame->p8023.h_source[5]);
  4020. printk(KERN_DEBUG " len = 0x%04x\n", frame->p8023.h_proto);
  4021. printk(KERN_DEBUG "IEEE 802.2 LLC/SNAP header:\n");
  4022. printk(KERN_DEBUG " DSAP = 0x%02x\n", frame->p8022.dsap);
  4023. printk(KERN_DEBUG " SSAP = 0x%02x\n", frame->p8022.ssap);
  4024. printk(KERN_DEBUG " ctrl = 0x%02x\n", frame->p8022.ctrl);
  4025. printk(KERN_DEBUG " OUI = %02x:%02x:%02x\n",
  4026. frame->p8022.oui[0], frame->p8022.oui[1], frame->p8022.oui[2]);
  4027. printk(KERN_DEBUG " ethertype = 0x%04x\n", frame->ethertype);
  4028. }
  4029. #endif /* 0 */
  4030. /********************************************************************/
  4031. /* Module initialization */
  4032. /********************************************************************/
  4033. EXPORT_SYMBOL(alloc_orinocodev);
  4034. EXPORT_SYMBOL(free_orinocodev);
  4035. EXPORT_SYMBOL(__orinoco_up);
  4036. EXPORT_SYMBOL(__orinoco_down);
  4037. EXPORT_SYMBOL(orinoco_reinit_firmware);
  4038. EXPORT_SYMBOL(orinoco_interrupt);
  4039. /* Can't be declared "const" or the whole __initdata section will
  4040. * become const */
  4041. static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION
  4042. " (David Gibson <hermes@gibson.dropbear.id.au>, "
  4043. "Pavel Roskin <proski@gnu.org>, et al)";
  4044. static int __init init_orinoco(void)
  4045. {
  4046. printk(KERN_DEBUG "%s\n", version);
  4047. return 0;
  4048. }
  4049. static void __exit exit_orinoco(void)
  4050. {
  4051. }
  4052. module_init(init_orinoco);
  4053. module_exit(exit_orinoco);