orinoco.c 117 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246
  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/wireless.h>
  461. #include <asm/uaccess.h>
  462. #include <asm/io.h>
  463. #include <asm/system.h>
  464. #include "hermes.h"
  465. #include "hermes_rid.h"
  466. #include "orinoco.h"
  467. #include "ieee802_11.h"
  468. /********************************************************************/
  469. /* Module information */
  470. /********************************************************************/
  471. MODULE_AUTHOR("Pavel Roskin <proski@gnu.org> & David Gibson <hermes@gibson.dropbear.id.au>");
  472. MODULE_DESCRIPTION("Driver for Lucent Orinoco, Prism II based and similar wireless cards");
  473. MODULE_LICENSE("Dual MPL/GPL");
  474. /* Level of debugging. Used in the macros in orinoco.h */
  475. #ifdef ORINOCO_DEBUG
  476. int orinoco_debug = ORINOCO_DEBUG;
  477. module_param(orinoco_debug, int, 0644);
  478. MODULE_PARM_DESC(orinoco_debug, "Debug level");
  479. EXPORT_SYMBOL(orinoco_debug);
  480. #endif
  481. static int suppress_linkstatus; /* = 0 */
  482. module_param(suppress_linkstatus, bool, 0644);
  483. MODULE_PARM_DESC(suppress_linkstatus, "Don't log link status changes");
  484. /********************************************************************/
  485. /* Compile time configuration and compatibility stuff */
  486. /********************************************************************/
  487. /* We do this this way to avoid ifdefs in the actual code */
  488. #ifdef WIRELESS_SPY
  489. #define SPY_NUMBER(priv) (priv->spy_number)
  490. #else
  491. #define SPY_NUMBER(priv) 0
  492. #endif /* WIRELESS_SPY */
  493. /********************************************************************/
  494. /* Internal constants */
  495. /********************************************************************/
  496. #define ORINOCO_MIN_MTU 256
  497. #define ORINOCO_MAX_MTU (IEEE802_11_DATA_LEN - ENCAPS_OVERHEAD)
  498. #define SYMBOL_MAX_VER_LEN (14)
  499. #define USER_BAP 0
  500. #define IRQ_BAP 1
  501. #define MAX_IRQLOOPS_PER_IRQ 10
  502. #define MAX_IRQLOOPS_PER_JIFFY (20000/HZ) /* Based on a guestimate of
  503. * how many events the
  504. * device could
  505. * legitimately generate */
  506. #define SMALL_KEY_SIZE 5
  507. #define LARGE_KEY_SIZE 13
  508. #define TX_NICBUF_SIZE_BUG 1585 /* Bug in Symbol firmware */
  509. #define DUMMY_FID 0xFFFF
  510. /*#define MAX_MULTICAST(priv) (priv->firmware_type == FIRMWARE_TYPE_AGERE ? \
  511. HERMES_MAX_MULTICAST : 0)*/
  512. #define MAX_MULTICAST(priv) (HERMES_MAX_MULTICAST)
  513. #define ORINOCO_INTEN (HERMES_EV_RX | HERMES_EV_ALLOC \
  514. | HERMES_EV_TX | HERMES_EV_TXEXC \
  515. | HERMES_EV_WTERR | HERMES_EV_INFO \
  516. | HERMES_EV_INFDROP )
  517. /********************************************************************/
  518. /* Data tables */
  519. /********************************************************************/
  520. /* The frequency of each channel in MHz */
  521. static const long channel_frequency[] = {
  522. 2412, 2417, 2422, 2427, 2432, 2437, 2442,
  523. 2447, 2452, 2457, 2462, 2467, 2472, 2484
  524. };
  525. #define NUM_CHANNELS ARRAY_SIZE(channel_frequency)
  526. /* This tables gives the actual meanings of the bitrate IDs returned
  527. * by the firmware. */
  528. static struct {
  529. int bitrate; /* in 100s of kilobits */
  530. int automatic;
  531. u16 agere_txratectrl;
  532. u16 intersil_txratectrl;
  533. } bitrate_table[] = {
  534. {110, 1, 3, 15}, /* Entry 0 is the default */
  535. {10, 0, 1, 1},
  536. {10, 1, 1, 1},
  537. {20, 0, 2, 2},
  538. {20, 1, 6, 3},
  539. {55, 0, 4, 4},
  540. {55, 1, 7, 7},
  541. {110, 0, 5, 8},
  542. };
  543. #define BITRATE_TABLE_SIZE ARRAY_SIZE(bitrate_table)
  544. /********************************************************************/
  545. /* Data types */
  546. /********************************************************************/
  547. struct header_struct {
  548. /* 802.3 */
  549. u8 dest[ETH_ALEN];
  550. u8 src[ETH_ALEN];
  551. u16 len;
  552. /* 802.2 */
  553. u8 dsap;
  554. u8 ssap;
  555. u8 ctrl;
  556. /* SNAP */
  557. u8 oui[3];
  558. u16 ethertype;
  559. } __attribute__ ((packed));
  560. /* 802.2 LLC/SNAP header used for Ethernet encapsulation over 802.11 */
  561. u8 encaps_hdr[] = {0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00};
  562. #define ENCAPS_OVERHEAD (sizeof(encaps_hdr) + 2)
  563. struct hermes_rx_descriptor {
  564. u16 status;
  565. u32 time;
  566. u8 silence;
  567. u8 signal;
  568. u8 rate;
  569. u8 rxflow;
  570. u32 reserved;
  571. } __attribute__ ((packed));
  572. /********************************************************************/
  573. /* Function prototypes */
  574. /********************************************************************/
  575. static int orinoco_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
  576. static int __orinoco_program_rids(struct net_device *dev);
  577. static void __orinoco_set_multicast_list(struct net_device *dev);
  578. static int orinoco_debug_dump_recs(struct net_device *dev);
  579. /********************************************************************/
  580. /* Internal helper functions */
  581. /********************************************************************/
  582. static inline void set_port_type(struct orinoco_private *priv)
  583. {
  584. switch (priv->iw_mode) {
  585. case IW_MODE_INFRA:
  586. priv->port_type = 1;
  587. priv->createibss = 0;
  588. break;
  589. case IW_MODE_ADHOC:
  590. if (priv->prefer_port3) {
  591. priv->port_type = 3;
  592. priv->createibss = 0;
  593. } else {
  594. priv->port_type = priv->ibss_port;
  595. priv->createibss = 1;
  596. }
  597. break;
  598. default:
  599. printk(KERN_ERR "%s: Invalid priv->iw_mode in set_port_type()\n",
  600. priv->ndev->name);
  601. }
  602. }
  603. /********************************************************************/
  604. /* Device methods */
  605. /********************************************************************/
  606. static int orinoco_open(struct net_device *dev)
  607. {
  608. struct orinoco_private *priv = netdev_priv(dev);
  609. unsigned long flags;
  610. int err;
  611. if (orinoco_lock(priv, &flags) != 0)
  612. return -EBUSY;
  613. err = __orinoco_up(dev);
  614. if (! err)
  615. priv->open = 1;
  616. orinoco_unlock(priv, &flags);
  617. return err;
  618. }
  619. int orinoco_stop(struct net_device *dev)
  620. {
  621. struct orinoco_private *priv = netdev_priv(dev);
  622. int err = 0;
  623. /* We mustn't use orinoco_lock() here, because we need to be
  624. able to close the interface even if hw_unavailable is set
  625. (e.g. as we're released after a PC Card removal) */
  626. spin_lock_irq(&priv->lock);
  627. priv->open = 0;
  628. err = __orinoco_down(dev);
  629. spin_unlock_irq(&priv->lock);
  630. return err;
  631. }
  632. static struct net_device_stats *orinoco_get_stats(struct net_device *dev)
  633. {
  634. struct orinoco_private *priv = netdev_priv(dev);
  635. return &priv->stats;
  636. }
  637. static struct iw_statistics *orinoco_get_wireless_stats(struct net_device *dev)
  638. {
  639. struct orinoco_private *priv = netdev_priv(dev);
  640. hermes_t *hw = &priv->hw;
  641. struct iw_statistics *wstats = &priv->wstats;
  642. int err;
  643. unsigned long flags;
  644. if (! netif_device_present(dev)) {
  645. printk(KERN_WARNING "%s: get_wireless_stats() called while device not present\n",
  646. dev->name);
  647. return NULL; /* FIXME: Can we do better than this? */
  648. }
  649. /* If busy, return the old stats. Returning NULL may cause
  650. * the interface to disappear from /proc/net/wireless */
  651. if (orinoco_lock(priv, &flags) != 0)
  652. return wstats;
  653. /* We can't really wait for the tallies inquiry command to
  654. * complete, so we just use the previous results and trigger
  655. * a new tallies inquiry command for next time - Jean II */
  656. /* FIXME: Really we should wait for the inquiry to come back -
  657. * as it is the stats we give don't make a whole lot of sense.
  658. * Unfortunately, it's not clear how to do that within the
  659. * wireless extensions framework: I think we're in user
  660. * context, but a lock seems to be held by the time we get in
  661. * here so we're not safe to sleep here. */
  662. hermes_inquire(hw, HERMES_INQ_TALLIES);
  663. if (priv->iw_mode == IW_MODE_ADHOC) {
  664. memset(&wstats->qual, 0, sizeof(wstats->qual));
  665. /* If a spy address is defined, we report stats of the
  666. * first spy address - Jean II */
  667. if (SPY_NUMBER(priv)) {
  668. wstats->qual.qual = priv->spy_stat[0].qual;
  669. wstats->qual.level = priv->spy_stat[0].level;
  670. wstats->qual.noise = priv->spy_stat[0].noise;
  671. wstats->qual.updated = priv->spy_stat[0].updated;
  672. }
  673. } else {
  674. struct {
  675. u16 qual, signal, noise;
  676. } __attribute__ ((packed)) cq;
  677. err = HERMES_READ_RECORD(hw, USER_BAP,
  678. HERMES_RID_COMMSQUALITY, &cq);
  679. if (!err) {
  680. wstats->qual.qual = (int)le16_to_cpu(cq.qual);
  681. wstats->qual.level = (int)le16_to_cpu(cq.signal) - 0x95;
  682. wstats->qual.noise = (int)le16_to_cpu(cq.noise) - 0x95;
  683. wstats->qual.updated = 7;
  684. }
  685. }
  686. orinoco_unlock(priv, &flags);
  687. return wstats;
  688. }
  689. static void orinoco_set_multicast_list(struct net_device *dev)
  690. {
  691. struct orinoco_private *priv = netdev_priv(dev);
  692. unsigned long flags;
  693. if (orinoco_lock(priv, &flags) != 0) {
  694. printk(KERN_DEBUG "%s: orinoco_set_multicast_list() "
  695. "called when hw_unavailable\n", dev->name);
  696. return;
  697. }
  698. __orinoco_set_multicast_list(dev);
  699. orinoco_unlock(priv, &flags);
  700. }
  701. static int orinoco_change_mtu(struct net_device *dev, int new_mtu)
  702. {
  703. struct orinoco_private *priv = netdev_priv(dev);
  704. if ( (new_mtu < ORINOCO_MIN_MTU) || (new_mtu > ORINOCO_MAX_MTU) )
  705. return -EINVAL;
  706. if ( (new_mtu + ENCAPS_OVERHEAD + IEEE802_11_HLEN) >
  707. (priv->nicbuf_size - ETH_HLEN) )
  708. return -EINVAL;
  709. dev->mtu = new_mtu;
  710. return 0;
  711. }
  712. /********************************************************************/
  713. /* Tx path */
  714. /********************************************************************/
  715. static int orinoco_xmit(struct sk_buff *skb, struct net_device *dev)
  716. {
  717. struct orinoco_private *priv = netdev_priv(dev);
  718. struct net_device_stats *stats = &priv->stats;
  719. hermes_t *hw = &priv->hw;
  720. int err = 0;
  721. u16 txfid = priv->txfid;
  722. char *p;
  723. struct ethhdr *eh;
  724. int len, data_len, data_off;
  725. struct hermes_tx_descriptor desc;
  726. unsigned long flags;
  727. TRACE_ENTER(dev->name);
  728. if (! netif_running(dev)) {
  729. printk(KERN_ERR "%s: Tx on stopped device!\n",
  730. dev->name);
  731. TRACE_EXIT(dev->name);
  732. return 1;
  733. }
  734. if (netif_queue_stopped(dev)) {
  735. printk(KERN_DEBUG "%s: Tx while transmitter busy!\n",
  736. dev->name);
  737. TRACE_EXIT(dev->name);
  738. return 1;
  739. }
  740. if (orinoco_lock(priv, &flags) != 0) {
  741. printk(KERN_ERR "%s: orinoco_xmit() called while hw_unavailable\n",
  742. dev->name);
  743. TRACE_EXIT(dev->name);
  744. return 1;
  745. }
  746. if (! netif_carrier_ok(dev)) {
  747. /* Oops, the firmware hasn't established a connection,
  748. silently drop the packet (this seems to be the
  749. safest approach). */
  750. stats->tx_errors++;
  751. orinoco_unlock(priv, &flags);
  752. dev_kfree_skb(skb);
  753. TRACE_EXIT(dev->name);
  754. return 0;
  755. }
  756. /* Length of the packet body */
  757. /* FIXME: what if the skb is smaller than this? */
  758. len = max_t(int,skb->len - ETH_HLEN, ETH_ZLEN - ETH_HLEN);
  759. eh = (struct ethhdr *)skb->data;
  760. memset(&desc, 0, sizeof(desc));
  761. desc.tx_control = cpu_to_le16(HERMES_TXCTRL_TX_OK | HERMES_TXCTRL_TX_EX);
  762. err = hermes_bap_pwrite(hw, USER_BAP, &desc, sizeof(desc), txfid, 0);
  763. if (err) {
  764. if (net_ratelimit())
  765. printk(KERN_ERR "%s: Error %d writing Tx descriptor "
  766. "to BAP\n", dev->name, err);
  767. stats->tx_errors++;
  768. goto fail;
  769. }
  770. /* Clear the 802.11 header and data length fields - some
  771. * firmwares (e.g. Lucent/Agere 8.xx) appear to get confused
  772. * if this isn't done. */
  773. hermes_clear_words(hw, HERMES_DATA0,
  774. HERMES_802_3_OFFSET - HERMES_802_11_OFFSET);
  775. /* Encapsulate Ethernet-II frames */
  776. if (ntohs(eh->h_proto) > ETH_DATA_LEN) { /* Ethernet-II frame */
  777. struct header_struct hdr;
  778. data_len = len;
  779. data_off = HERMES_802_3_OFFSET + sizeof(hdr);
  780. p = skb->data + ETH_HLEN;
  781. /* 802.3 header */
  782. memcpy(hdr.dest, eh->h_dest, ETH_ALEN);
  783. memcpy(hdr.src, eh->h_source, ETH_ALEN);
  784. hdr.len = htons(data_len + ENCAPS_OVERHEAD);
  785. /* 802.2 header */
  786. memcpy(&hdr.dsap, &encaps_hdr, sizeof(encaps_hdr));
  787. hdr.ethertype = eh->h_proto;
  788. err = hermes_bap_pwrite(hw, USER_BAP, &hdr, sizeof(hdr),
  789. txfid, HERMES_802_3_OFFSET);
  790. if (err) {
  791. if (net_ratelimit())
  792. printk(KERN_ERR "%s: Error %d writing packet "
  793. "header to BAP\n", dev->name, err);
  794. stats->tx_errors++;
  795. goto fail;
  796. }
  797. } else { /* IEEE 802.3 frame */
  798. data_len = len + ETH_HLEN;
  799. data_off = HERMES_802_3_OFFSET;
  800. p = skb->data;
  801. }
  802. /* Round up for odd length packets */
  803. err = hermes_bap_pwrite(hw, USER_BAP, p, ALIGN(data_len, 2),
  804. txfid, data_off);
  805. if (err) {
  806. printk(KERN_ERR "%s: Error %d writing packet to BAP\n",
  807. dev->name, err);
  808. stats->tx_errors++;
  809. goto fail;
  810. }
  811. /* Finally, we actually initiate the send */
  812. netif_stop_queue(dev);
  813. err = hermes_docmd_wait(hw, HERMES_CMD_TX | HERMES_CMD_RECL,
  814. txfid, NULL);
  815. if (err) {
  816. netif_start_queue(dev);
  817. printk(KERN_ERR "%s: Error %d transmitting packet\n",
  818. dev->name, err);
  819. stats->tx_errors++;
  820. goto fail;
  821. }
  822. dev->trans_start = jiffies;
  823. stats->tx_bytes += data_off + data_len;
  824. orinoco_unlock(priv, &flags);
  825. dev_kfree_skb(skb);
  826. TRACE_EXIT(dev->name);
  827. return 0;
  828. fail:
  829. TRACE_EXIT(dev->name);
  830. orinoco_unlock(priv, &flags);
  831. return err;
  832. }
  833. static void __orinoco_ev_alloc(struct net_device *dev, hermes_t *hw)
  834. {
  835. struct orinoco_private *priv = netdev_priv(dev);
  836. u16 fid = hermes_read_regn(hw, ALLOCFID);
  837. if (fid != priv->txfid) {
  838. if (fid != DUMMY_FID)
  839. printk(KERN_WARNING "%s: Allocate event on unexpected fid (%04X)\n",
  840. dev->name, fid);
  841. return;
  842. }
  843. hermes_write_regn(hw, ALLOCFID, DUMMY_FID);
  844. }
  845. static void __orinoco_ev_tx(struct net_device *dev, hermes_t *hw)
  846. {
  847. struct orinoco_private *priv = netdev_priv(dev);
  848. struct net_device_stats *stats = &priv->stats;
  849. stats->tx_packets++;
  850. netif_wake_queue(dev);
  851. hermes_write_regn(hw, TXCOMPLFID, DUMMY_FID);
  852. }
  853. static void __orinoco_ev_txexc(struct net_device *dev, hermes_t *hw)
  854. {
  855. struct orinoco_private *priv = netdev_priv(dev);
  856. struct net_device_stats *stats = &priv->stats;
  857. u16 fid = hermes_read_regn(hw, TXCOMPLFID);
  858. struct hermes_tx_descriptor desc;
  859. int err = 0;
  860. if (fid == DUMMY_FID)
  861. return; /* Nothing's really happened */
  862. err = hermes_bap_pread(hw, IRQ_BAP, &desc, sizeof(desc), fid, 0);
  863. if (err) {
  864. printk(KERN_WARNING "%s: Unable to read descriptor on Tx error "
  865. "(FID=%04X error %d)\n",
  866. dev->name, fid, err);
  867. } else {
  868. DEBUG(1, "%s: Tx error, status %d\n",
  869. dev->name, le16_to_cpu(desc.status));
  870. }
  871. stats->tx_errors++;
  872. netif_wake_queue(dev);
  873. hermes_write_regn(hw, TXCOMPLFID, DUMMY_FID);
  874. }
  875. static void orinoco_tx_timeout(struct net_device *dev)
  876. {
  877. struct orinoco_private *priv = netdev_priv(dev);
  878. struct net_device_stats *stats = &priv->stats;
  879. struct hermes *hw = &priv->hw;
  880. printk(KERN_WARNING "%s: Tx timeout! "
  881. "ALLOCFID=%04x, TXCOMPLFID=%04x, EVSTAT=%04x\n",
  882. dev->name, hermes_read_regn(hw, ALLOCFID),
  883. hermes_read_regn(hw, TXCOMPLFID), hermes_read_regn(hw, EVSTAT));
  884. stats->tx_errors++;
  885. schedule_work(&priv->reset_work);
  886. }
  887. /********************************************************************/
  888. /* Rx path (data frames) */
  889. /********************************************************************/
  890. /* Does the frame have a SNAP header indicating it should be
  891. * de-encapsulated to Ethernet-II? */
  892. static inline int is_ethersnap(void *_hdr)
  893. {
  894. u8 *hdr = _hdr;
  895. /* We de-encapsulate all packets which, a) have SNAP headers
  896. * (i.e. SSAP=DSAP=0xaa and CTRL=0x3 in the 802.2 LLC header
  897. * and where b) the OUI of the SNAP header is 00:00:00 or
  898. * 00:00:f8 - we need both because different APs appear to use
  899. * different OUIs for some reason */
  900. return (memcmp(hdr, &encaps_hdr, 5) == 0)
  901. && ( (hdr[5] == 0x00) || (hdr[5] == 0xf8) );
  902. }
  903. static inline void orinoco_spy_gather(struct net_device *dev, u_char *mac,
  904. int level, int noise)
  905. {
  906. struct orinoco_private *priv = netdev_priv(dev);
  907. int i;
  908. /* Gather wireless spy statistics: for each packet, compare the
  909. * source address with out list, and if match, get the stats... */
  910. for (i = 0; i < priv->spy_number; i++)
  911. if (!memcmp(mac, priv->spy_address[i], ETH_ALEN)) {
  912. priv->spy_stat[i].level = level - 0x95;
  913. priv->spy_stat[i].noise = noise - 0x95;
  914. priv->spy_stat[i].qual = (level > noise) ? (level - noise) : 0;
  915. priv->spy_stat[i].updated = 7;
  916. }
  917. }
  918. static void orinoco_stat_gather(struct net_device *dev,
  919. struct sk_buff *skb,
  920. struct hermes_rx_descriptor *desc)
  921. {
  922. struct orinoco_private *priv = netdev_priv(dev);
  923. /* Using spy support with lots of Rx packets, like in an
  924. * infrastructure (AP), will really slow down everything, because
  925. * the MAC address must be compared to each entry of the spy list.
  926. * If the user really asks for it (set some address in the
  927. * spy list), we do it, but he will pay the price.
  928. * Note that to get here, you need both WIRELESS_SPY
  929. * compiled in AND some addresses in the list !!!
  930. */
  931. /* Note : gcc will optimise the whole section away if
  932. * WIRELESS_SPY is not defined... - Jean II */
  933. if (SPY_NUMBER(priv)) {
  934. orinoco_spy_gather(dev, skb->mac.raw + ETH_ALEN,
  935. desc->signal, desc->silence);
  936. }
  937. }
  938. static void __orinoco_ev_rx(struct net_device *dev, hermes_t *hw)
  939. {
  940. struct orinoco_private *priv = netdev_priv(dev);
  941. struct net_device_stats *stats = &priv->stats;
  942. struct iw_statistics *wstats = &priv->wstats;
  943. struct sk_buff *skb = NULL;
  944. u16 rxfid, status;
  945. int length, data_len, data_off;
  946. char *p;
  947. struct hermes_rx_descriptor desc;
  948. struct header_struct hdr;
  949. struct ethhdr *eh;
  950. int err;
  951. rxfid = hermes_read_regn(hw, RXFID);
  952. err = hermes_bap_pread(hw, IRQ_BAP, &desc, sizeof(desc),
  953. rxfid, 0);
  954. if (err) {
  955. printk(KERN_ERR "%s: error %d reading Rx descriptor. "
  956. "Frame dropped.\n", dev->name, err);
  957. stats->rx_errors++;
  958. goto drop;
  959. }
  960. status = le16_to_cpu(desc.status);
  961. if (status & HERMES_RXSTAT_ERR) {
  962. if (status & HERMES_RXSTAT_UNDECRYPTABLE) {
  963. wstats->discard.code++;
  964. DEBUG(1, "%s: Undecryptable frame on Rx. Frame dropped.\n",
  965. dev->name);
  966. } else {
  967. stats->rx_crc_errors++;
  968. DEBUG(1, "%s: Bad CRC on Rx. Frame dropped.\n", dev->name);
  969. }
  970. stats->rx_errors++;
  971. goto drop;
  972. }
  973. /* For now we ignore the 802.11 header completely, assuming
  974. that the card's firmware has handled anything vital */
  975. err = hermes_bap_pread(hw, IRQ_BAP, &hdr, sizeof(hdr),
  976. rxfid, HERMES_802_3_OFFSET);
  977. if (err) {
  978. printk(KERN_ERR "%s: error %d reading frame header. "
  979. "Frame dropped.\n", dev->name, err);
  980. stats->rx_errors++;
  981. goto drop;
  982. }
  983. length = ntohs(hdr.len);
  984. /* Sanity checks */
  985. if (length < 3) { /* No for even an 802.2 LLC header */
  986. /* At least on Symbol firmware with PCF we get quite a
  987. lot of these legitimately - Poll frames with no
  988. data. */
  989. stats->rx_dropped++;
  990. goto drop;
  991. }
  992. if (length > IEEE802_11_DATA_LEN) {
  993. printk(KERN_WARNING "%s: Oversized frame received (%d bytes)\n",
  994. dev->name, length);
  995. stats->rx_length_errors++;
  996. stats->rx_errors++;
  997. goto drop;
  998. }
  999. /* We need space for the packet data itself, plus an ethernet
  1000. header, plus 2 bytes so we can align the IP header on a
  1001. 32bit boundary, plus 1 byte so we can read in odd length
  1002. packets from the card, which has an IO granularity of 16
  1003. bits */
  1004. skb = dev_alloc_skb(length+ETH_HLEN+2+1);
  1005. if (!skb) {
  1006. printk(KERN_WARNING "%s: Can't allocate skb for Rx\n",
  1007. dev->name);
  1008. goto drop;
  1009. }
  1010. skb_reserve(skb, 2); /* This way the IP header is aligned */
  1011. /* Handle decapsulation
  1012. * In most cases, the firmware tell us about SNAP frames.
  1013. * For some reason, the SNAP frames sent by LinkSys APs
  1014. * are not properly recognised by most firmwares.
  1015. * So, check ourselves */
  1016. if (((status & HERMES_RXSTAT_MSGTYPE) == HERMES_RXSTAT_1042) ||
  1017. ((status & HERMES_RXSTAT_MSGTYPE) == HERMES_RXSTAT_TUNNEL) ||
  1018. is_ethersnap(&hdr)) {
  1019. /* These indicate a SNAP within 802.2 LLC within
  1020. 802.11 frame which we'll need to de-encapsulate to
  1021. the original EthernetII frame. */
  1022. if (length < ENCAPS_OVERHEAD) { /* No room for full LLC+SNAP */
  1023. stats->rx_length_errors++;
  1024. goto drop;
  1025. }
  1026. /* Remove SNAP header, reconstruct EthernetII frame */
  1027. data_len = length - ENCAPS_OVERHEAD;
  1028. data_off = HERMES_802_3_OFFSET + sizeof(hdr);
  1029. eh = (struct ethhdr *)skb_put(skb, ETH_HLEN);
  1030. memcpy(eh, &hdr, 2 * ETH_ALEN);
  1031. eh->h_proto = hdr.ethertype;
  1032. } else {
  1033. /* All other cases indicate a genuine 802.3 frame. No
  1034. decapsulation needed. We just throw the whole
  1035. thing in, and hope the protocol layer can deal with
  1036. it as 802.3 */
  1037. data_len = length;
  1038. data_off = HERMES_802_3_OFFSET;
  1039. /* FIXME: we re-read from the card data we already read here */
  1040. }
  1041. p = skb_put(skb, data_len);
  1042. err = hermes_bap_pread(hw, IRQ_BAP, p, ALIGN(data_len, 2),
  1043. rxfid, data_off);
  1044. if (err) {
  1045. printk(KERN_ERR "%s: error %d reading frame. "
  1046. "Frame dropped.\n", dev->name, err);
  1047. stats->rx_errors++;
  1048. goto drop;
  1049. }
  1050. dev->last_rx = jiffies;
  1051. skb->dev = dev;
  1052. skb->protocol = eth_type_trans(skb, dev);
  1053. skb->ip_summed = CHECKSUM_NONE;
  1054. /* Process the wireless stats if needed */
  1055. orinoco_stat_gather(dev, skb, &desc);
  1056. /* Pass the packet to the networking stack */
  1057. netif_rx(skb);
  1058. stats->rx_packets++;
  1059. stats->rx_bytes += length;
  1060. return;
  1061. drop:
  1062. stats->rx_dropped++;
  1063. if (skb)
  1064. dev_kfree_skb_irq(skb);
  1065. return;
  1066. }
  1067. /********************************************************************/
  1068. /* Rx path (info frames) */
  1069. /********************************************************************/
  1070. static void print_linkstatus(struct net_device *dev, u16 status)
  1071. {
  1072. char * s;
  1073. if (suppress_linkstatus)
  1074. return;
  1075. switch (status) {
  1076. case HERMES_LINKSTATUS_NOT_CONNECTED:
  1077. s = "Not Connected";
  1078. break;
  1079. case HERMES_LINKSTATUS_CONNECTED:
  1080. s = "Connected";
  1081. break;
  1082. case HERMES_LINKSTATUS_DISCONNECTED:
  1083. s = "Disconnected";
  1084. break;
  1085. case HERMES_LINKSTATUS_AP_CHANGE:
  1086. s = "AP Changed";
  1087. break;
  1088. case HERMES_LINKSTATUS_AP_OUT_OF_RANGE:
  1089. s = "AP Out of Range";
  1090. break;
  1091. case HERMES_LINKSTATUS_AP_IN_RANGE:
  1092. s = "AP In Range";
  1093. break;
  1094. case HERMES_LINKSTATUS_ASSOC_FAILED:
  1095. s = "Association Failed";
  1096. break;
  1097. default:
  1098. s = "UNKNOWN";
  1099. }
  1100. printk(KERN_INFO "%s: New link status: %s (%04x)\n",
  1101. dev->name, s, status);
  1102. }
  1103. static void __orinoco_ev_info(struct net_device *dev, hermes_t *hw)
  1104. {
  1105. struct orinoco_private *priv = netdev_priv(dev);
  1106. u16 infofid;
  1107. struct {
  1108. u16 len;
  1109. u16 type;
  1110. } __attribute__ ((packed)) info;
  1111. int len, type;
  1112. int err;
  1113. /* This is an answer to an INQUIRE command that we did earlier,
  1114. * or an information "event" generated by the card
  1115. * The controller return to us a pseudo frame containing
  1116. * the information in question - Jean II */
  1117. infofid = hermes_read_regn(hw, INFOFID);
  1118. /* Read the info frame header - don't try too hard */
  1119. err = hermes_bap_pread(hw, IRQ_BAP, &info, sizeof(info),
  1120. infofid, 0);
  1121. if (err) {
  1122. printk(KERN_ERR "%s: error %d reading info frame. "
  1123. "Frame dropped.\n", dev->name, err);
  1124. return;
  1125. }
  1126. len = HERMES_RECLEN_TO_BYTES(le16_to_cpu(info.len));
  1127. type = le16_to_cpu(info.type);
  1128. switch (type) {
  1129. case HERMES_INQ_TALLIES: {
  1130. struct hermes_tallies_frame tallies;
  1131. struct iw_statistics *wstats = &priv->wstats;
  1132. if (len > sizeof(tallies)) {
  1133. printk(KERN_WARNING "%s: Tallies frame too long (%d bytes)\n",
  1134. dev->name, len);
  1135. len = sizeof(tallies);
  1136. }
  1137. /* Read directly the data (no seek) */
  1138. hermes_read_words(hw, HERMES_DATA1, (void *) &tallies,
  1139. len / 2); /* FIXME: blech! */
  1140. /* Increment our various counters */
  1141. /* wstats->discard.nwid - no wrong BSSID stuff */
  1142. wstats->discard.code +=
  1143. le16_to_cpu(tallies.RxWEPUndecryptable);
  1144. if (len == sizeof(tallies))
  1145. wstats->discard.code +=
  1146. le16_to_cpu(tallies.RxDiscards_WEPICVError) +
  1147. le16_to_cpu(tallies.RxDiscards_WEPExcluded);
  1148. wstats->discard.misc +=
  1149. le16_to_cpu(tallies.TxDiscardsWrongSA);
  1150. wstats->discard.fragment +=
  1151. le16_to_cpu(tallies.RxMsgInBadMsgFragments);
  1152. wstats->discard.retries +=
  1153. le16_to_cpu(tallies.TxRetryLimitExceeded);
  1154. /* wstats->miss.beacon - no match */
  1155. }
  1156. break;
  1157. case HERMES_INQ_LINKSTATUS: {
  1158. struct hermes_linkstatus linkstatus;
  1159. u16 newstatus;
  1160. int connected;
  1161. if (len != sizeof(linkstatus)) {
  1162. printk(KERN_WARNING "%s: Unexpected size for linkstatus frame (%d bytes)\n",
  1163. dev->name, len);
  1164. break;
  1165. }
  1166. hermes_read_words(hw, HERMES_DATA1, (void *) &linkstatus,
  1167. len / 2);
  1168. newstatus = le16_to_cpu(linkstatus.linkstatus);
  1169. connected = (newstatus == HERMES_LINKSTATUS_CONNECTED)
  1170. || (newstatus == HERMES_LINKSTATUS_AP_CHANGE)
  1171. || (newstatus == HERMES_LINKSTATUS_AP_IN_RANGE);
  1172. if (connected)
  1173. netif_carrier_on(dev);
  1174. else
  1175. netif_carrier_off(dev);
  1176. if (newstatus != priv->last_linkstatus)
  1177. print_linkstatus(dev, newstatus);
  1178. priv->last_linkstatus = newstatus;
  1179. }
  1180. break;
  1181. default:
  1182. printk(KERN_DEBUG "%s: Unknown information frame received: "
  1183. "type 0x%04x, length %d\n", dev->name, type, len);
  1184. /* We don't actually do anything about it */
  1185. break;
  1186. }
  1187. }
  1188. static void __orinoco_ev_infdrop(struct net_device *dev, hermes_t *hw)
  1189. {
  1190. if (net_ratelimit())
  1191. printk(KERN_DEBUG "%s: Information frame lost.\n", dev->name);
  1192. }
  1193. /********************************************************************/
  1194. /* Internal hardware control routines */
  1195. /********************************************************************/
  1196. int __orinoco_up(struct net_device *dev)
  1197. {
  1198. struct orinoco_private *priv = netdev_priv(dev);
  1199. struct hermes *hw = &priv->hw;
  1200. int err;
  1201. err = __orinoco_program_rids(dev);
  1202. if (err) {
  1203. printk(KERN_ERR "%s: Error %d configuring card\n",
  1204. dev->name, err);
  1205. return err;
  1206. }
  1207. /* Fire things up again */
  1208. hermes_set_irqmask(hw, ORINOCO_INTEN);
  1209. err = hermes_enable_port(hw, 0);
  1210. if (err) {
  1211. printk(KERN_ERR "%s: Error %d enabling MAC port\n",
  1212. dev->name, err);
  1213. return err;
  1214. }
  1215. netif_start_queue(dev);
  1216. return 0;
  1217. }
  1218. int __orinoco_down(struct net_device *dev)
  1219. {
  1220. struct orinoco_private *priv = netdev_priv(dev);
  1221. struct hermes *hw = &priv->hw;
  1222. int err;
  1223. netif_stop_queue(dev);
  1224. if (! priv->hw_unavailable) {
  1225. if (! priv->broken_disableport) {
  1226. err = hermes_disable_port(hw, 0);
  1227. if (err) {
  1228. /* Some firmwares (e.g. Intersil 1.3.x) seem
  1229. * to have problems disabling the port, oh
  1230. * well, too bad. */
  1231. printk(KERN_WARNING "%s: Error %d disabling MAC port\n",
  1232. dev->name, err);
  1233. priv->broken_disableport = 1;
  1234. }
  1235. }
  1236. hermes_set_irqmask(hw, 0);
  1237. hermes_write_regn(hw, EVACK, 0xffff);
  1238. }
  1239. /* firmware will have to reassociate */
  1240. netif_carrier_off(dev);
  1241. priv->last_linkstatus = 0xffff;
  1242. return 0;
  1243. }
  1244. int orinoco_reinit_firmware(struct net_device *dev)
  1245. {
  1246. struct orinoco_private *priv = netdev_priv(dev);
  1247. struct hermes *hw = &priv->hw;
  1248. int err;
  1249. err = hermes_init(hw);
  1250. if (err)
  1251. return err;
  1252. err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid);
  1253. if (err == -EIO) {
  1254. /* Try workaround for old Symbol firmware bug */
  1255. printk(KERN_WARNING "%s: firmware ALLOC bug detected "
  1256. "(old Symbol firmware?). Trying to work around... ",
  1257. dev->name);
  1258. priv->nicbuf_size = TX_NICBUF_SIZE_BUG;
  1259. err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid);
  1260. if (err)
  1261. printk("failed!\n");
  1262. else
  1263. printk("ok.\n");
  1264. }
  1265. return err;
  1266. }
  1267. static int __orinoco_hw_set_bitrate(struct orinoco_private *priv)
  1268. {
  1269. hermes_t *hw = &priv->hw;
  1270. int err = 0;
  1271. if (priv->bitratemode >= BITRATE_TABLE_SIZE) {
  1272. printk(KERN_ERR "%s: BUG: Invalid bitrate mode %d\n",
  1273. priv->ndev->name, priv->bitratemode);
  1274. return -EINVAL;
  1275. }
  1276. switch (priv->firmware_type) {
  1277. case FIRMWARE_TYPE_AGERE:
  1278. err = hermes_write_wordrec(hw, USER_BAP,
  1279. HERMES_RID_CNFTXRATECONTROL,
  1280. bitrate_table[priv->bitratemode].agere_txratectrl);
  1281. break;
  1282. case FIRMWARE_TYPE_INTERSIL:
  1283. case FIRMWARE_TYPE_SYMBOL:
  1284. err = hermes_write_wordrec(hw, USER_BAP,
  1285. HERMES_RID_CNFTXRATECONTROL,
  1286. bitrate_table[priv->bitratemode].intersil_txratectrl);
  1287. break;
  1288. default:
  1289. BUG();
  1290. }
  1291. return err;
  1292. }
  1293. /* Change the WEP keys and/or the current keys. Can be called
  1294. * either from __orinoco_hw_setup_wep() or directly from
  1295. * orinoco_ioctl_setiwencode(). In the later case the association
  1296. * with the AP is not broken (if the firmware can handle it),
  1297. * which is needed for 802.1x implementations. */
  1298. static int __orinoco_hw_setup_wepkeys(struct orinoco_private *priv)
  1299. {
  1300. hermes_t *hw = &priv->hw;
  1301. int err = 0;
  1302. switch (priv->firmware_type) {
  1303. case FIRMWARE_TYPE_AGERE:
  1304. err = HERMES_WRITE_RECORD(hw, USER_BAP,
  1305. HERMES_RID_CNFWEPKEYS_AGERE,
  1306. &priv->keys);
  1307. if (err)
  1308. return err;
  1309. err = hermes_write_wordrec(hw, USER_BAP,
  1310. HERMES_RID_CNFTXKEY_AGERE,
  1311. priv->tx_key);
  1312. if (err)
  1313. return err;
  1314. break;
  1315. case FIRMWARE_TYPE_INTERSIL:
  1316. case FIRMWARE_TYPE_SYMBOL:
  1317. {
  1318. int keylen;
  1319. int i;
  1320. /* Force uniform key length to work around firmware bugs */
  1321. keylen = le16_to_cpu(priv->keys[priv->tx_key].len);
  1322. if (keylen > LARGE_KEY_SIZE) {
  1323. printk(KERN_ERR "%s: BUG: Key %d has oversize length %d.\n",
  1324. priv->ndev->name, priv->tx_key, keylen);
  1325. return -E2BIG;
  1326. }
  1327. /* Write all 4 keys */
  1328. for(i = 0; i < ORINOCO_MAX_KEYS; i++) {
  1329. err = hermes_write_ltv(hw, USER_BAP,
  1330. HERMES_RID_CNFDEFAULTKEY0 + i,
  1331. HERMES_BYTES_TO_RECLEN(keylen),
  1332. priv->keys[i].data);
  1333. if (err)
  1334. return err;
  1335. }
  1336. /* Write the index of the key used in transmission */
  1337. err = hermes_write_wordrec(hw, USER_BAP,
  1338. HERMES_RID_CNFWEPDEFAULTKEYID,
  1339. priv->tx_key);
  1340. if (err)
  1341. return err;
  1342. }
  1343. break;
  1344. }
  1345. return 0;
  1346. }
  1347. static int __orinoco_hw_setup_wep(struct orinoco_private *priv)
  1348. {
  1349. hermes_t *hw = &priv->hw;
  1350. int err = 0;
  1351. int master_wep_flag;
  1352. int auth_flag;
  1353. if (priv->wep_on)
  1354. __orinoco_hw_setup_wepkeys(priv);
  1355. if (priv->wep_restrict)
  1356. auth_flag = HERMES_AUTH_SHARED_KEY;
  1357. else
  1358. auth_flag = HERMES_AUTH_OPEN;
  1359. switch (priv->firmware_type) {
  1360. case FIRMWARE_TYPE_AGERE: /* Agere style WEP */
  1361. if (priv->wep_on) {
  1362. /* Enable the shared-key authentication. */
  1363. err = hermes_write_wordrec(hw, USER_BAP,
  1364. HERMES_RID_CNFAUTHENTICATION_AGERE,
  1365. auth_flag);
  1366. }
  1367. err = hermes_write_wordrec(hw, USER_BAP,
  1368. HERMES_RID_CNFWEPENABLED_AGERE,
  1369. priv->wep_on);
  1370. if (err)
  1371. return err;
  1372. break;
  1373. case FIRMWARE_TYPE_INTERSIL: /* Intersil style WEP */
  1374. case FIRMWARE_TYPE_SYMBOL: /* Symbol style WEP */
  1375. if (priv->wep_on) {
  1376. if (priv->wep_restrict ||
  1377. (priv->firmware_type == FIRMWARE_TYPE_SYMBOL))
  1378. master_wep_flag = HERMES_WEP_PRIVACY_INVOKED |
  1379. HERMES_WEP_EXCL_UNENCRYPTED;
  1380. else
  1381. master_wep_flag = HERMES_WEP_PRIVACY_INVOKED;
  1382. err = hermes_write_wordrec(hw, USER_BAP,
  1383. HERMES_RID_CNFAUTHENTICATION,
  1384. auth_flag);
  1385. if (err)
  1386. return err;
  1387. } else
  1388. master_wep_flag = 0;
  1389. if (priv->iw_mode == IW_MODE_MONITOR)
  1390. master_wep_flag |= HERMES_WEP_HOST_DECRYPT;
  1391. /* Master WEP setting : on/off */
  1392. err = hermes_write_wordrec(hw, USER_BAP,
  1393. HERMES_RID_CNFWEPFLAGS_INTERSIL,
  1394. master_wep_flag);
  1395. if (err)
  1396. return err;
  1397. break;
  1398. }
  1399. return 0;
  1400. }
  1401. static int __orinoco_program_rids(struct net_device *dev)
  1402. {
  1403. struct orinoco_private *priv = netdev_priv(dev);
  1404. hermes_t *hw = &priv->hw;
  1405. int err;
  1406. struct hermes_idstring idbuf;
  1407. /* Set the MAC address */
  1408. err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNMACADDR,
  1409. HERMES_BYTES_TO_RECLEN(ETH_ALEN), dev->dev_addr);
  1410. if (err) {
  1411. printk(KERN_ERR "%s: Error %d setting MAC address\n",
  1412. dev->name, err);
  1413. return err;
  1414. }
  1415. /* Set up the link mode */
  1416. err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFPORTTYPE,
  1417. priv->port_type);
  1418. if (err) {
  1419. printk(KERN_ERR "%s: Error %d setting port type\n",
  1420. dev->name, err);
  1421. return err;
  1422. }
  1423. /* Set the channel/frequency */
  1424. if (priv->channel == 0) {
  1425. printk(KERN_DEBUG "%s: Channel is 0 in __orinoco_program_rids()\n", dev->name);
  1426. if (priv->createibss)
  1427. priv->channel = 10;
  1428. }
  1429. err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFOWNCHANNEL,
  1430. priv->channel);
  1431. if (err) {
  1432. printk(KERN_ERR "%s: Error %d setting channel\n",
  1433. dev->name, err);
  1434. return err;
  1435. }
  1436. if (priv->has_ibss) {
  1437. u16 createibss;
  1438. if ((strlen(priv->desired_essid) == 0) && (priv->createibss)) {
  1439. printk(KERN_WARNING "%s: This firmware requires an "
  1440. "ESSID in IBSS-Ad-Hoc mode.\n", dev->name);
  1441. /* With wvlan_cs, in this case, we would crash.
  1442. * hopefully, this driver will behave better...
  1443. * Jean II */
  1444. createibss = 0;
  1445. } else {
  1446. createibss = priv->createibss;
  1447. }
  1448. err = hermes_write_wordrec(hw, USER_BAP,
  1449. HERMES_RID_CNFCREATEIBSS,
  1450. createibss);
  1451. if (err) {
  1452. printk(KERN_ERR "%s: Error %d setting CREATEIBSS\n",
  1453. dev->name, err);
  1454. return err;
  1455. }
  1456. }
  1457. /* Set the desired ESSID */
  1458. idbuf.len = cpu_to_le16(strlen(priv->desired_essid));
  1459. memcpy(&idbuf.val, priv->desired_essid, sizeof(idbuf.val));
  1460. /* WinXP wants partner to configure OWNSSID even in IBSS mode. (jimc) */
  1461. err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNSSID,
  1462. HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid)+2),
  1463. &idbuf);
  1464. if (err) {
  1465. printk(KERN_ERR "%s: Error %d setting OWNSSID\n",
  1466. dev->name, err);
  1467. return err;
  1468. }
  1469. err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFDESIREDSSID,
  1470. HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid)+2),
  1471. &idbuf);
  1472. if (err) {
  1473. printk(KERN_ERR "%s: Error %d setting DESIREDSSID\n",
  1474. dev->name, err);
  1475. return err;
  1476. }
  1477. /* Set the station name */
  1478. idbuf.len = cpu_to_le16(strlen(priv->nick));
  1479. memcpy(&idbuf.val, priv->nick, sizeof(idbuf.val));
  1480. err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNNAME,
  1481. HERMES_BYTES_TO_RECLEN(strlen(priv->nick)+2),
  1482. &idbuf);
  1483. if (err) {
  1484. printk(KERN_ERR "%s: Error %d setting nickname\n",
  1485. dev->name, err);
  1486. return err;
  1487. }
  1488. /* Set AP density */
  1489. if (priv->has_sensitivity) {
  1490. err = hermes_write_wordrec(hw, USER_BAP,
  1491. HERMES_RID_CNFSYSTEMSCALE,
  1492. priv->ap_density);
  1493. if (err) {
  1494. printk(KERN_WARNING "%s: Error %d setting SYSTEMSCALE. "
  1495. "Disabling sensitivity control\n",
  1496. dev->name, err);
  1497. priv->has_sensitivity = 0;
  1498. }
  1499. }
  1500. /* Set RTS threshold */
  1501. err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFRTSTHRESHOLD,
  1502. priv->rts_thresh);
  1503. if (err) {
  1504. printk(KERN_ERR "%s: Error %d setting RTS threshold\n",
  1505. dev->name, err);
  1506. return err;
  1507. }
  1508. /* Set fragmentation threshold or MWO robustness */
  1509. if (priv->has_mwo)
  1510. err = hermes_write_wordrec(hw, USER_BAP,
  1511. HERMES_RID_CNFMWOROBUST_AGERE,
  1512. priv->mwo_robust);
  1513. else
  1514. err = hermes_write_wordrec(hw, USER_BAP,
  1515. HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
  1516. priv->frag_thresh);
  1517. if (err) {
  1518. printk(KERN_ERR "%s: Error %d setting fragmentation\n",
  1519. dev->name, err);
  1520. return err;
  1521. }
  1522. /* Set bitrate */
  1523. err = __orinoco_hw_set_bitrate(priv);
  1524. if (err) {
  1525. printk(KERN_ERR "%s: Error %d setting bitrate\n",
  1526. dev->name, err);
  1527. return err;
  1528. }
  1529. /* Set power management */
  1530. if (priv->has_pm) {
  1531. err = hermes_write_wordrec(hw, USER_BAP,
  1532. HERMES_RID_CNFPMENABLED,
  1533. priv->pm_on);
  1534. if (err) {
  1535. printk(KERN_ERR "%s: Error %d setting up PM\n",
  1536. dev->name, err);
  1537. return err;
  1538. }
  1539. err = hermes_write_wordrec(hw, USER_BAP,
  1540. HERMES_RID_CNFMULTICASTRECEIVE,
  1541. priv->pm_mcast);
  1542. if (err) {
  1543. printk(KERN_ERR "%s: Error %d setting up PM\n",
  1544. dev->name, err);
  1545. return err;
  1546. }
  1547. err = hermes_write_wordrec(hw, USER_BAP,
  1548. HERMES_RID_CNFMAXSLEEPDURATION,
  1549. priv->pm_period);
  1550. if (err) {
  1551. printk(KERN_ERR "%s: Error %d setting up PM\n",
  1552. dev->name, err);
  1553. return err;
  1554. }
  1555. err = hermes_write_wordrec(hw, USER_BAP,
  1556. HERMES_RID_CNFPMHOLDOVERDURATION,
  1557. priv->pm_timeout);
  1558. if (err) {
  1559. printk(KERN_ERR "%s: Error %d setting up PM\n",
  1560. dev->name, err);
  1561. return err;
  1562. }
  1563. }
  1564. /* Set preamble - only for Symbol so far... */
  1565. if (priv->has_preamble) {
  1566. err = hermes_write_wordrec(hw, USER_BAP,
  1567. HERMES_RID_CNFPREAMBLE_SYMBOL,
  1568. priv->preamble);
  1569. if (err) {
  1570. printk(KERN_ERR "%s: Error %d setting preamble\n",
  1571. dev->name, err);
  1572. return err;
  1573. }
  1574. }
  1575. /* Set up encryption */
  1576. if (priv->has_wep) {
  1577. err = __orinoco_hw_setup_wep(priv);
  1578. if (err) {
  1579. printk(KERN_ERR "%s: Error %d activating WEP\n",
  1580. dev->name, err);
  1581. return err;
  1582. }
  1583. }
  1584. /* Set promiscuity / multicast*/
  1585. priv->promiscuous = 0;
  1586. priv->mc_count = 0;
  1587. __orinoco_set_multicast_list(dev); /* FIXME: what about the xmit_lock */
  1588. return 0;
  1589. }
  1590. /* FIXME: return int? */
  1591. static void
  1592. __orinoco_set_multicast_list(struct net_device *dev)
  1593. {
  1594. struct orinoco_private *priv = netdev_priv(dev);
  1595. hermes_t *hw = &priv->hw;
  1596. int err = 0;
  1597. int promisc, mc_count;
  1598. /* The Hermes doesn't seem to have an allmulti mode, so we go
  1599. * into promiscuous mode and let the upper levels deal. */
  1600. if ( (dev->flags & IFF_PROMISC) || (dev->flags & IFF_ALLMULTI) ||
  1601. (dev->mc_count > MAX_MULTICAST(priv)) ) {
  1602. promisc = 1;
  1603. mc_count = 0;
  1604. } else {
  1605. promisc = 0;
  1606. mc_count = dev->mc_count;
  1607. }
  1608. if (promisc != priv->promiscuous) {
  1609. err = hermes_write_wordrec(hw, USER_BAP,
  1610. HERMES_RID_CNFPROMISCUOUSMODE,
  1611. promisc);
  1612. if (err) {
  1613. printk(KERN_ERR "%s: Error %d setting PROMISCUOUSMODE to 1.\n",
  1614. dev->name, err);
  1615. } else
  1616. priv->promiscuous = promisc;
  1617. }
  1618. if (! promisc && (mc_count || priv->mc_count) ) {
  1619. struct dev_mc_list *p = dev->mc_list;
  1620. struct hermes_multicast mclist;
  1621. int i;
  1622. for (i = 0; i < mc_count; i++) {
  1623. /* paranoia: is list shorter than mc_count? */
  1624. BUG_ON(! p);
  1625. /* paranoia: bad address size in list? */
  1626. BUG_ON(p->dmi_addrlen != ETH_ALEN);
  1627. memcpy(mclist.addr[i], p->dmi_addr, ETH_ALEN);
  1628. p = p->next;
  1629. }
  1630. if (p)
  1631. printk(KERN_WARNING "%s: Multicast list is "
  1632. "longer than mc_count\n", dev->name);
  1633. err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFGROUPADDRESSES,
  1634. HERMES_BYTES_TO_RECLEN(priv->mc_count * ETH_ALEN),
  1635. &mclist);
  1636. if (err)
  1637. printk(KERN_ERR "%s: Error %d setting multicast list.\n",
  1638. dev->name, err);
  1639. else
  1640. priv->mc_count = mc_count;
  1641. }
  1642. /* Since we can set the promiscuous flag when it wasn't asked
  1643. for, make sure the net_device knows about it. */
  1644. if (priv->promiscuous)
  1645. dev->flags |= IFF_PROMISC;
  1646. else
  1647. dev->flags &= ~IFF_PROMISC;
  1648. }
  1649. static int orinoco_reconfigure(struct net_device *dev)
  1650. {
  1651. struct orinoco_private *priv = netdev_priv(dev);
  1652. struct hermes *hw = &priv->hw;
  1653. unsigned long flags;
  1654. int err = 0;
  1655. if (priv->broken_disableport) {
  1656. schedule_work(&priv->reset_work);
  1657. return 0;
  1658. }
  1659. if (orinoco_lock(priv, &flags) != 0)
  1660. return -EBUSY;
  1661. err = hermes_disable_port(hw, 0);
  1662. if (err) {
  1663. printk(KERN_WARNING "%s: Unable to disable port while reconfiguring card\n",
  1664. dev->name);
  1665. priv->broken_disableport = 1;
  1666. goto out;
  1667. }
  1668. err = __orinoco_program_rids(dev);
  1669. if (err) {
  1670. printk(KERN_WARNING "%s: Unable to reconfigure card\n",
  1671. dev->name);
  1672. goto out;
  1673. }
  1674. err = hermes_enable_port(hw, 0);
  1675. if (err) {
  1676. printk(KERN_WARNING "%s: Unable to enable port while reconfiguring card\n",
  1677. dev->name);
  1678. goto out;
  1679. }
  1680. out:
  1681. if (err) {
  1682. printk(KERN_WARNING "%s: Resetting instead...\n", dev->name);
  1683. schedule_work(&priv->reset_work);
  1684. err = 0;
  1685. }
  1686. orinoco_unlock(priv, &flags);
  1687. return err;
  1688. }
  1689. /* This must be called from user context, without locks held - use
  1690. * schedule_work() */
  1691. static void orinoco_reset(struct net_device *dev)
  1692. {
  1693. struct orinoco_private *priv = netdev_priv(dev);
  1694. struct hermes *hw = &priv->hw;
  1695. int err = 0;
  1696. unsigned long flags;
  1697. if (orinoco_lock(priv, &flags) != 0)
  1698. /* When the hardware becomes available again, whatever
  1699. * detects that is responsible for re-initializing
  1700. * it. So no need for anything further */
  1701. return;
  1702. netif_stop_queue(dev);
  1703. /* Shut off interrupts. Depending on what state the hardware
  1704. * is in, this might not work, but we'll try anyway */
  1705. hermes_set_irqmask(hw, 0);
  1706. hermes_write_regn(hw, EVACK, 0xffff);
  1707. priv->hw_unavailable++;
  1708. priv->last_linkstatus = 0xffff; /* firmware will have to reassociate */
  1709. netif_carrier_off(dev);
  1710. orinoco_unlock(priv, &flags);
  1711. if (priv->hard_reset)
  1712. err = (*priv->hard_reset)(priv);
  1713. if (err) {
  1714. printk(KERN_ERR "%s: orinoco_reset: Error %d "
  1715. "performing hard reset\n", dev->name, err);
  1716. /* FIXME: shutdown of some sort */
  1717. return;
  1718. }
  1719. err = orinoco_reinit_firmware(dev);
  1720. if (err) {
  1721. printk(KERN_ERR "%s: orinoco_reset: Error %d re-initializing firmware\n",
  1722. dev->name, err);
  1723. return;
  1724. }
  1725. spin_lock_irq(&priv->lock); /* This has to be called from user context */
  1726. priv->hw_unavailable--;
  1727. /* priv->open or priv->hw_unavailable might have changed while
  1728. * we dropped the lock */
  1729. if (priv->open && (! priv->hw_unavailable)) {
  1730. err = __orinoco_up(dev);
  1731. if (err) {
  1732. printk(KERN_ERR "%s: orinoco_reset: Error %d reenabling card\n",
  1733. dev->name, err);
  1734. } else
  1735. dev->trans_start = jiffies;
  1736. }
  1737. spin_unlock_irq(&priv->lock);
  1738. return;
  1739. }
  1740. /********************************************************************/
  1741. /* Interrupt handler */
  1742. /********************************************************************/
  1743. static void __orinoco_ev_tick(struct net_device *dev, hermes_t *hw)
  1744. {
  1745. printk(KERN_DEBUG "%s: TICK\n", dev->name);
  1746. }
  1747. static void __orinoco_ev_wterr(struct net_device *dev, hermes_t *hw)
  1748. {
  1749. /* This seems to happen a fair bit under load, but ignoring it
  1750. seems to work fine...*/
  1751. printk(KERN_DEBUG "%s: MAC controller error (WTERR). Ignoring.\n",
  1752. dev->name);
  1753. }
  1754. irqreturn_t orinoco_interrupt(int irq, void *dev_id, struct pt_regs *regs)
  1755. {
  1756. struct net_device *dev = (struct net_device *)dev_id;
  1757. struct orinoco_private *priv = netdev_priv(dev);
  1758. hermes_t *hw = &priv->hw;
  1759. int count = MAX_IRQLOOPS_PER_IRQ;
  1760. u16 evstat, events;
  1761. /* These are used to detect a runaway interrupt situation */
  1762. /* If we get more than MAX_IRQLOOPS_PER_JIFFY iterations in a jiffy,
  1763. * we panic and shut down the hardware */
  1764. static int last_irq_jiffy = 0; /* jiffies value the last time
  1765. * we were called */
  1766. static int loops_this_jiffy = 0;
  1767. unsigned long flags;
  1768. if (orinoco_lock(priv, &flags) != 0) {
  1769. /* If hw is unavailable - we don't know if the irq was
  1770. * for us or not */
  1771. return IRQ_HANDLED;
  1772. }
  1773. evstat = hermes_read_regn(hw, EVSTAT);
  1774. events = evstat & hw->inten;
  1775. if (! events) {
  1776. orinoco_unlock(priv, &flags);
  1777. return IRQ_NONE;
  1778. }
  1779. if (jiffies != last_irq_jiffy)
  1780. loops_this_jiffy = 0;
  1781. last_irq_jiffy = jiffies;
  1782. while (events && count--) {
  1783. if (++loops_this_jiffy > MAX_IRQLOOPS_PER_JIFFY) {
  1784. printk(KERN_WARNING "%s: IRQ handler is looping too "
  1785. "much! Resetting.\n", dev->name);
  1786. /* Disable interrupts for now */
  1787. hermes_set_irqmask(hw, 0);
  1788. schedule_work(&priv->reset_work);
  1789. break;
  1790. }
  1791. /* Check the card hasn't been removed */
  1792. if (! hermes_present(hw)) {
  1793. DEBUG(0, "orinoco_interrupt(): card removed\n");
  1794. break;
  1795. }
  1796. if (events & HERMES_EV_TICK)
  1797. __orinoco_ev_tick(dev, hw);
  1798. if (events & HERMES_EV_WTERR)
  1799. __orinoco_ev_wterr(dev, hw);
  1800. if (events & HERMES_EV_INFDROP)
  1801. __orinoco_ev_infdrop(dev, hw);
  1802. if (events & HERMES_EV_INFO)
  1803. __orinoco_ev_info(dev, hw);
  1804. if (events & HERMES_EV_RX)
  1805. __orinoco_ev_rx(dev, hw);
  1806. if (events & HERMES_EV_TXEXC)
  1807. __orinoco_ev_txexc(dev, hw);
  1808. if (events & HERMES_EV_TX)
  1809. __orinoco_ev_tx(dev, hw);
  1810. if (events & HERMES_EV_ALLOC)
  1811. __orinoco_ev_alloc(dev, hw);
  1812. hermes_write_regn(hw, EVACK, events);
  1813. evstat = hermes_read_regn(hw, EVSTAT);
  1814. events = evstat & hw->inten;
  1815. };
  1816. orinoco_unlock(priv, &flags);
  1817. return IRQ_HANDLED;
  1818. }
  1819. /********************************************************************/
  1820. /* Initialization */
  1821. /********************************************************************/
  1822. struct comp_id {
  1823. u16 id, variant, major, minor;
  1824. } __attribute__ ((packed));
  1825. static inline fwtype_t determine_firmware_type(struct comp_id *nic_id)
  1826. {
  1827. if (nic_id->id < 0x8000)
  1828. return FIRMWARE_TYPE_AGERE;
  1829. else if (nic_id->id == 0x8000 && nic_id->major == 0)
  1830. return FIRMWARE_TYPE_SYMBOL;
  1831. else
  1832. return FIRMWARE_TYPE_INTERSIL;
  1833. }
  1834. /* Set priv->firmware type, determine firmware properties */
  1835. static int determine_firmware(struct net_device *dev)
  1836. {
  1837. struct orinoco_private *priv = netdev_priv(dev);
  1838. hermes_t *hw = &priv->hw;
  1839. int err;
  1840. struct comp_id nic_id, sta_id;
  1841. unsigned int firmver;
  1842. char tmp[SYMBOL_MAX_VER_LEN+1];
  1843. /* Get the hardware version */
  1844. err = HERMES_READ_RECORD(hw, USER_BAP, HERMES_RID_NICID, &nic_id);
  1845. if (err) {
  1846. printk(KERN_ERR "%s: Cannot read hardware identity: error %d\n",
  1847. dev->name, err);
  1848. return err;
  1849. }
  1850. le16_to_cpus(&nic_id.id);
  1851. le16_to_cpus(&nic_id.variant);
  1852. le16_to_cpus(&nic_id.major);
  1853. le16_to_cpus(&nic_id.minor);
  1854. printk(KERN_DEBUG "%s: Hardware identity %04x:%04x:%04x:%04x\n",
  1855. dev->name, nic_id.id, nic_id.variant,
  1856. nic_id.major, nic_id.minor);
  1857. priv->firmware_type = determine_firmware_type(&nic_id);
  1858. /* Get the firmware version */
  1859. err = HERMES_READ_RECORD(hw, USER_BAP, HERMES_RID_STAID, &sta_id);
  1860. if (err) {
  1861. printk(KERN_ERR "%s: Cannot read station identity: error %d\n",
  1862. dev->name, err);
  1863. return err;
  1864. }
  1865. le16_to_cpus(&sta_id.id);
  1866. le16_to_cpus(&sta_id.variant);
  1867. le16_to_cpus(&sta_id.major);
  1868. le16_to_cpus(&sta_id.minor);
  1869. printk(KERN_DEBUG "%s: Station identity %04x:%04x:%04x:%04x\n",
  1870. dev->name, sta_id.id, sta_id.variant,
  1871. sta_id.major, sta_id.minor);
  1872. switch (sta_id.id) {
  1873. case 0x15:
  1874. printk(KERN_ERR "%s: Primary firmware is active\n",
  1875. dev->name);
  1876. return -ENODEV;
  1877. case 0x14b:
  1878. printk(KERN_ERR "%s: Tertiary firmware is active\n",
  1879. dev->name);
  1880. return -ENODEV;
  1881. case 0x1f: /* Intersil, Agere, Symbol Spectrum24 */
  1882. case 0x21: /* Symbol Spectrum24 Trilogy */
  1883. break;
  1884. default:
  1885. printk(KERN_NOTICE "%s: Unknown station ID, please report\n",
  1886. dev->name);
  1887. break;
  1888. }
  1889. /* Default capabilities */
  1890. priv->has_sensitivity = 1;
  1891. priv->has_mwo = 0;
  1892. priv->has_preamble = 0;
  1893. priv->has_port3 = 1;
  1894. priv->has_ibss = 1;
  1895. priv->has_wep = 0;
  1896. priv->has_big_wep = 0;
  1897. /* Determine capabilities from the firmware version */
  1898. switch (priv->firmware_type) {
  1899. case FIRMWARE_TYPE_AGERE:
  1900. /* Lucent Wavelan IEEE, Lucent Orinoco, Cabletron RoamAbout,
  1901. ELSA, Melco, HP, IBM, Dell 1150, Compaq 110/210 */
  1902. snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
  1903. "Lucent/Agere %d.%02d", sta_id.major, sta_id.minor);
  1904. firmver = ((unsigned long)sta_id.major << 16) | sta_id.minor;
  1905. priv->has_ibss = (firmver >= 0x60006);
  1906. priv->has_wep = (firmver >= 0x40020);
  1907. priv->has_big_wep = 1; /* FIXME: this is wrong - how do we tell
  1908. Gold cards from the others? */
  1909. priv->has_mwo = (firmver >= 0x60000);
  1910. priv->has_pm = (firmver >= 0x40020); /* Don't work in 7.52 ? */
  1911. priv->ibss_port = 1;
  1912. /* Tested with Agere firmware :
  1913. * 1.16 ; 4.08 ; 4.52 ; 6.04 ; 6.16 ; 7.28 => Jean II
  1914. * Tested CableTron firmware : 4.32 => Anton */
  1915. break;
  1916. case FIRMWARE_TYPE_SYMBOL:
  1917. /* Symbol , 3Com AirConnect, Intel, Ericsson WLAN */
  1918. /* Intel MAC : 00:02:B3:* */
  1919. /* 3Com MAC : 00:50:DA:* */
  1920. memset(tmp, 0, sizeof(tmp));
  1921. /* Get the Symbol firmware version */
  1922. err = hermes_read_ltv(hw, USER_BAP,
  1923. HERMES_RID_SECONDARYVERSION_SYMBOL,
  1924. SYMBOL_MAX_VER_LEN, NULL, &tmp);
  1925. if (err) {
  1926. printk(KERN_WARNING
  1927. "%s: Error %d reading Symbol firmware info. Wildly guessing capabilities...\n",
  1928. dev->name, err);
  1929. firmver = 0;
  1930. tmp[0] = '\0';
  1931. } else {
  1932. /* The firmware revision is a string, the format is
  1933. * something like : "V2.20-01".
  1934. * Quick and dirty parsing... - Jean II
  1935. */
  1936. firmver = ((tmp[1] - '0') << 16) | ((tmp[3] - '0') << 12)
  1937. | ((tmp[4] - '0') << 8) | ((tmp[6] - '0') << 4)
  1938. | (tmp[7] - '0');
  1939. tmp[SYMBOL_MAX_VER_LEN] = '\0';
  1940. }
  1941. snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
  1942. "Symbol %s", tmp);
  1943. priv->has_ibss = (firmver >= 0x20000);
  1944. priv->has_wep = (firmver >= 0x15012);
  1945. priv->has_big_wep = (firmver >= 0x20000);
  1946. priv->has_pm = (firmver >= 0x20000 && firmver < 0x22000) ||
  1947. (firmver >= 0x29000 && firmver < 0x30000) ||
  1948. firmver >= 0x31000;
  1949. priv->has_preamble = (firmver >= 0x20000);
  1950. priv->ibss_port = 4;
  1951. /* Tested with Intel firmware : 0x20015 => Jean II */
  1952. /* Tested with 3Com firmware : 0x15012 & 0x22001 => Jean II */
  1953. break;
  1954. case FIRMWARE_TYPE_INTERSIL:
  1955. /* D-Link, Linksys, Adtron, ZoomAir, and many others...
  1956. * Samsung, Compaq 100/200 and Proxim are slightly
  1957. * different and less well tested */
  1958. /* D-Link MAC : 00:40:05:* */
  1959. /* Addtron MAC : 00:90:D1:* */
  1960. snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
  1961. "Intersil %d.%d.%d", sta_id.major, sta_id.minor,
  1962. sta_id.variant);
  1963. firmver = ((unsigned long)sta_id.major << 16) |
  1964. ((unsigned long)sta_id.minor << 8) | sta_id.variant;
  1965. priv->has_ibss = (firmver >= 0x000700); /* FIXME */
  1966. priv->has_big_wep = priv->has_wep = (firmver >= 0x000800);
  1967. priv->has_pm = (firmver >= 0x000700);
  1968. if (firmver >= 0x000800)
  1969. priv->ibss_port = 0;
  1970. else {
  1971. printk(KERN_NOTICE "%s: Intersil firmware earlier "
  1972. "than v0.8.x - several features not supported\n",
  1973. dev->name);
  1974. priv->ibss_port = 1;
  1975. }
  1976. break;
  1977. }
  1978. printk(KERN_DEBUG "%s: Firmware determined as %s\n", dev->name,
  1979. priv->fw_name);
  1980. return 0;
  1981. }
  1982. static int orinoco_init(struct net_device *dev)
  1983. {
  1984. struct orinoco_private *priv = netdev_priv(dev);
  1985. hermes_t *hw = &priv->hw;
  1986. int err = 0;
  1987. struct hermes_idstring nickbuf;
  1988. u16 reclen;
  1989. int len;
  1990. TRACE_ENTER(dev->name);
  1991. /* No need to lock, the hw_unavailable flag is already set in
  1992. * alloc_orinocodev() */
  1993. priv->nicbuf_size = IEEE802_11_FRAME_LEN + ETH_HLEN;
  1994. /* Initialize the firmware */
  1995. err = hermes_init(hw);
  1996. if (err != 0) {
  1997. printk(KERN_ERR "%s: failed to initialize firmware (err = %d)\n",
  1998. dev->name, err);
  1999. goto out;
  2000. }
  2001. err = determine_firmware(dev);
  2002. if (err != 0) {
  2003. printk(KERN_ERR "%s: Incompatible firmware, aborting\n",
  2004. dev->name);
  2005. goto out;
  2006. }
  2007. if (priv->has_port3)
  2008. printk(KERN_DEBUG "%s: Ad-hoc demo mode supported\n", dev->name);
  2009. if (priv->has_ibss)
  2010. printk(KERN_DEBUG "%s: IEEE standard IBSS ad-hoc mode supported\n",
  2011. dev->name);
  2012. if (priv->has_wep) {
  2013. printk(KERN_DEBUG "%s: WEP supported, ", dev->name);
  2014. if (priv->has_big_wep)
  2015. printk("104-bit key\n");
  2016. else
  2017. printk("40-bit key\n");
  2018. }
  2019. /* Get the MAC address */
  2020. err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CNFOWNMACADDR,
  2021. ETH_ALEN, NULL, dev->dev_addr);
  2022. if (err) {
  2023. printk(KERN_WARNING "%s: failed to read MAC address!\n",
  2024. dev->name);
  2025. goto out;
  2026. }
  2027. printk(KERN_DEBUG "%s: MAC address %02X:%02X:%02X:%02X:%02X:%02X\n",
  2028. dev->name, dev->dev_addr[0], dev->dev_addr[1],
  2029. dev->dev_addr[2], dev->dev_addr[3], dev->dev_addr[4],
  2030. dev->dev_addr[5]);
  2031. /* Get the station name */
  2032. err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CNFOWNNAME,
  2033. sizeof(nickbuf), &reclen, &nickbuf);
  2034. if (err) {
  2035. printk(KERN_ERR "%s: failed to read station name\n",
  2036. dev->name);
  2037. goto out;
  2038. }
  2039. if (nickbuf.len)
  2040. len = min(IW_ESSID_MAX_SIZE, (int)le16_to_cpu(nickbuf.len));
  2041. else
  2042. len = min(IW_ESSID_MAX_SIZE, 2 * reclen);
  2043. memcpy(priv->nick, &nickbuf.val, len);
  2044. priv->nick[len] = '\0';
  2045. printk(KERN_DEBUG "%s: Station name \"%s\"\n", dev->name, priv->nick);
  2046. /* Get allowed channels */
  2047. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CHANNELLIST,
  2048. &priv->channel_mask);
  2049. if (err) {
  2050. printk(KERN_ERR "%s: failed to read channel list!\n",
  2051. dev->name);
  2052. goto out;
  2053. }
  2054. /* Get initial AP density */
  2055. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFSYSTEMSCALE,
  2056. &priv->ap_density);
  2057. if (err || priv->ap_density < 1 || priv->ap_density > 3) {
  2058. priv->has_sensitivity = 0;
  2059. }
  2060. /* Get initial RTS threshold */
  2061. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFRTSTHRESHOLD,
  2062. &priv->rts_thresh);
  2063. if (err) {
  2064. printk(KERN_ERR "%s: failed to read RTS threshold!\n",
  2065. dev->name);
  2066. goto out;
  2067. }
  2068. /* Get initial fragmentation settings */
  2069. if (priv->has_mwo)
  2070. err = hermes_read_wordrec(hw, USER_BAP,
  2071. HERMES_RID_CNFMWOROBUST_AGERE,
  2072. &priv->mwo_robust);
  2073. else
  2074. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
  2075. &priv->frag_thresh);
  2076. if (err) {
  2077. printk(KERN_ERR "%s: failed to read fragmentation settings!\n",
  2078. dev->name);
  2079. goto out;
  2080. }
  2081. /* Power management setup */
  2082. if (priv->has_pm) {
  2083. priv->pm_on = 0;
  2084. priv->pm_mcast = 1;
  2085. err = hermes_read_wordrec(hw, USER_BAP,
  2086. HERMES_RID_CNFMAXSLEEPDURATION,
  2087. &priv->pm_period);
  2088. if (err) {
  2089. printk(KERN_ERR "%s: failed to read power management period!\n",
  2090. dev->name);
  2091. goto out;
  2092. }
  2093. err = hermes_read_wordrec(hw, USER_BAP,
  2094. HERMES_RID_CNFPMHOLDOVERDURATION,
  2095. &priv->pm_timeout);
  2096. if (err) {
  2097. printk(KERN_ERR "%s: failed to read power management timeout!\n",
  2098. dev->name);
  2099. goto out;
  2100. }
  2101. }
  2102. /* Preamble setup */
  2103. if (priv->has_preamble) {
  2104. err = hermes_read_wordrec(hw, USER_BAP,
  2105. HERMES_RID_CNFPREAMBLE_SYMBOL,
  2106. &priv->preamble);
  2107. if (err)
  2108. goto out;
  2109. }
  2110. /* Set up the default configuration */
  2111. priv->iw_mode = IW_MODE_INFRA;
  2112. /* By default use IEEE/IBSS ad-hoc mode if we have it */
  2113. priv->prefer_port3 = priv->has_port3 && (! priv->has_ibss);
  2114. set_port_type(priv);
  2115. priv->channel = 10; /* default channel, more-or-less arbitrary */
  2116. priv->promiscuous = 0;
  2117. priv->wep_on = 0;
  2118. priv->tx_key = 0;
  2119. err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid);
  2120. if (err == -EIO) {
  2121. /* Try workaround for old Symbol firmware bug */
  2122. printk(KERN_WARNING "%s: firmware ALLOC bug detected "
  2123. "(old Symbol firmware?). Trying to work around... ",
  2124. dev->name);
  2125. priv->nicbuf_size = TX_NICBUF_SIZE_BUG;
  2126. err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid);
  2127. if (err)
  2128. printk("failed!\n");
  2129. else
  2130. printk("ok.\n");
  2131. }
  2132. if (err) {
  2133. printk("%s: Error %d allocating Tx buffer\n", dev->name, err);
  2134. goto out;
  2135. }
  2136. /* Make the hardware available, as long as it hasn't been
  2137. * removed elsewhere (e.g. by PCMCIA hot unplug) */
  2138. spin_lock_irq(&priv->lock);
  2139. priv->hw_unavailable--;
  2140. spin_unlock_irq(&priv->lock);
  2141. printk(KERN_DEBUG "%s: ready\n", dev->name);
  2142. out:
  2143. TRACE_EXIT(dev->name);
  2144. return err;
  2145. }
  2146. struct net_device *alloc_orinocodev(int sizeof_card,
  2147. int (*hard_reset)(struct orinoco_private *))
  2148. {
  2149. struct net_device *dev;
  2150. struct orinoco_private *priv;
  2151. dev = alloc_etherdev(sizeof(struct orinoco_private) + sizeof_card);
  2152. if (! dev)
  2153. return NULL;
  2154. priv = netdev_priv(dev);
  2155. priv->ndev = dev;
  2156. if (sizeof_card)
  2157. priv->card = (void *)((unsigned long)netdev_priv(dev)
  2158. + sizeof(struct orinoco_private));
  2159. else
  2160. priv->card = NULL;
  2161. /* Setup / override net_device fields */
  2162. dev->init = orinoco_init;
  2163. dev->hard_start_xmit = orinoco_xmit;
  2164. dev->tx_timeout = orinoco_tx_timeout;
  2165. dev->watchdog_timeo = HZ; /* 1 second timeout */
  2166. dev->get_stats = orinoco_get_stats;
  2167. dev->get_wireless_stats = orinoco_get_wireless_stats;
  2168. dev->do_ioctl = orinoco_ioctl;
  2169. dev->change_mtu = orinoco_change_mtu;
  2170. dev->set_multicast_list = orinoco_set_multicast_list;
  2171. /* we use the default eth_mac_addr for setting the MAC addr */
  2172. /* Set up default callbacks */
  2173. dev->open = orinoco_open;
  2174. dev->stop = orinoco_stop;
  2175. priv->hard_reset = hard_reset;
  2176. spin_lock_init(&priv->lock);
  2177. priv->open = 0;
  2178. priv->hw_unavailable = 1; /* orinoco_init() must clear this
  2179. * before anything else touches the
  2180. * hardware */
  2181. INIT_WORK(&priv->reset_work, (void (*)(void *))orinoco_reset, dev);
  2182. netif_carrier_off(dev);
  2183. priv->last_linkstatus = 0xffff;
  2184. return dev;
  2185. }
  2186. void free_orinocodev(struct net_device *dev)
  2187. {
  2188. free_netdev(dev);
  2189. }
  2190. /********************************************************************/
  2191. /* Wireless extensions */
  2192. /********************************************************************/
  2193. static int orinoco_hw_get_bssid(struct orinoco_private *priv,
  2194. char buf[ETH_ALEN])
  2195. {
  2196. hermes_t *hw = &priv->hw;
  2197. int err = 0;
  2198. unsigned long flags;
  2199. if (orinoco_lock(priv, &flags) != 0)
  2200. return -EBUSY;
  2201. err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTBSSID,
  2202. ETH_ALEN, NULL, buf);
  2203. orinoco_unlock(priv, &flags);
  2204. return err;
  2205. }
  2206. static int orinoco_hw_get_essid(struct orinoco_private *priv, int *active,
  2207. char buf[IW_ESSID_MAX_SIZE+1])
  2208. {
  2209. hermes_t *hw = &priv->hw;
  2210. int err = 0;
  2211. struct hermes_idstring essidbuf;
  2212. char *p = (char *)(&essidbuf.val);
  2213. int len;
  2214. unsigned long flags;
  2215. if (orinoco_lock(priv, &flags) != 0)
  2216. return -EBUSY;
  2217. if (strlen(priv->desired_essid) > 0) {
  2218. /* We read the desired SSID from the hardware rather
  2219. than from priv->desired_essid, just in case the
  2220. firmware is allowed to change it on us. I'm not
  2221. sure about this */
  2222. /* My guess is that the OWNSSID should always be whatever
  2223. * we set to the card, whereas CURRENT_SSID is the one that
  2224. * may change... - Jean II */
  2225. u16 rid;
  2226. *active = 1;
  2227. rid = (priv->port_type == 3) ? HERMES_RID_CNFOWNSSID :
  2228. HERMES_RID_CNFDESIREDSSID;
  2229. err = hermes_read_ltv(hw, USER_BAP, rid, sizeof(essidbuf),
  2230. NULL, &essidbuf);
  2231. if (err)
  2232. goto fail_unlock;
  2233. } else {
  2234. *active = 0;
  2235. err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTSSID,
  2236. sizeof(essidbuf), NULL, &essidbuf);
  2237. if (err)
  2238. goto fail_unlock;
  2239. }
  2240. len = le16_to_cpu(essidbuf.len);
  2241. memset(buf, 0, IW_ESSID_MAX_SIZE+1);
  2242. memcpy(buf, p, len);
  2243. buf[len] = '\0';
  2244. fail_unlock:
  2245. orinoco_unlock(priv, &flags);
  2246. return err;
  2247. }
  2248. static long orinoco_hw_get_freq(struct orinoco_private *priv)
  2249. {
  2250. hermes_t *hw = &priv->hw;
  2251. int err = 0;
  2252. u16 channel;
  2253. long freq = 0;
  2254. unsigned long flags;
  2255. if (orinoco_lock(priv, &flags) != 0)
  2256. return -EBUSY;
  2257. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CURRENTCHANNEL, &channel);
  2258. if (err)
  2259. goto out;
  2260. /* Intersil firmware 1.3.5 returns 0 when the interface is down */
  2261. if (channel == 0) {
  2262. err = -EBUSY;
  2263. goto out;
  2264. }
  2265. if ( (channel < 1) || (channel > NUM_CHANNELS) ) {
  2266. printk(KERN_WARNING "%s: Channel out of range (%d)!\n",
  2267. priv->ndev->name, channel);
  2268. err = -EBUSY;
  2269. goto out;
  2270. }
  2271. freq = channel_frequency[channel-1] * 100000;
  2272. out:
  2273. orinoco_unlock(priv, &flags);
  2274. if (err > 0)
  2275. err = -EBUSY;
  2276. return err ? err : freq;
  2277. }
  2278. static int orinoco_hw_get_bitratelist(struct orinoco_private *priv,
  2279. int *numrates, s32 *rates, int max)
  2280. {
  2281. hermes_t *hw = &priv->hw;
  2282. struct hermes_idstring list;
  2283. unsigned char *p = (unsigned char *)&list.val;
  2284. int err = 0;
  2285. int num;
  2286. int i;
  2287. unsigned long flags;
  2288. if (orinoco_lock(priv, &flags) != 0)
  2289. return -EBUSY;
  2290. err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_SUPPORTEDDATARATES,
  2291. sizeof(list), NULL, &list);
  2292. orinoco_unlock(priv, &flags);
  2293. if (err)
  2294. return err;
  2295. num = le16_to_cpu(list.len);
  2296. *numrates = num;
  2297. num = min(num, max);
  2298. for (i = 0; i < num; i++) {
  2299. rates[i] = (p[i] & 0x7f) * 500000; /* convert to bps */
  2300. }
  2301. return 0;
  2302. }
  2303. static int orinoco_ioctl_getiwrange(struct net_device *dev, struct iw_point *rrq)
  2304. {
  2305. struct orinoco_private *priv = netdev_priv(dev);
  2306. int err = 0;
  2307. int mode;
  2308. struct iw_range range;
  2309. int numrates;
  2310. int i, k;
  2311. unsigned long flags;
  2312. TRACE_ENTER(dev->name);
  2313. if (!access_ok(VERIFY_WRITE, rrq->pointer, sizeof(range)))
  2314. return -EFAULT;
  2315. rrq->length = sizeof(range);
  2316. if (orinoco_lock(priv, &flags) != 0)
  2317. return -EBUSY;
  2318. mode = priv->iw_mode;
  2319. orinoco_unlock(priv, &flags);
  2320. memset(&range, 0, sizeof(range));
  2321. /* Much of this shamelessly taken from wvlan_cs.c. No idea
  2322. * what it all means -dgibson */
  2323. range.we_version_compiled = WIRELESS_EXT;
  2324. range.we_version_source = 11;
  2325. range.min_nwid = range.max_nwid = 0; /* We don't use nwids */
  2326. /* Set available channels/frequencies */
  2327. range.num_channels = NUM_CHANNELS;
  2328. k = 0;
  2329. for (i = 0; i < NUM_CHANNELS; i++) {
  2330. if (priv->channel_mask & (1 << i)) {
  2331. range.freq[k].i = i + 1;
  2332. range.freq[k].m = channel_frequency[i] * 100000;
  2333. range.freq[k].e = 1;
  2334. k++;
  2335. }
  2336. if (k >= IW_MAX_FREQUENCIES)
  2337. break;
  2338. }
  2339. range.num_frequency = k;
  2340. range.sensitivity = 3;
  2341. if ((mode == IW_MODE_ADHOC) && (priv->spy_number == 0)){
  2342. /* Quality stats meaningless in ad-hoc mode */
  2343. range.max_qual.qual = 0;
  2344. range.max_qual.level = 0;
  2345. range.max_qual.noise = 0;
  2346. range.avg_qual.qual = 0;
  2347. range.avg_qual.level = 0;
  2348. range.avg_qual.noise = 0;
  2349. } else {
  2350. range.max_qual.qual = 0x8b - 0x2f;
  2351. range.max_qual.level = 0x2f - 0x95 - 1;
  2352. range.max_qual.noise = 0x2f - 0x95 - 1;
  2353. /* Need to get better values */
  2354. range.avg_qual.qual = 0x24;
  2355. range.avg_qual.level = 0xC2;
  2356. range.avg_qual.noise = 0x9E;
  2357. }
  2358. err = orinoco_hw_get_bitratelist(priv, &numrates,
  2359. range.bitrate, IW_MAX_BITRATES);
  2360. if (err)
  2361. return err;
  2362. range.num_bitrates = numrates;
  2363. /* Set an indication of the max TCP throughput in bit/s that we can
  2364. * expect using this interface. May be use for QoS stuff...
  2365. * Jean II */
  2366. if(numrates > 2)
  2367. range.throughput = 5 * 1000 * 1000; /* ~5 Mb/s */
  2368. else
  2369. range.throughput = 1.5 * 1000 * 1000; /* ~1.5 Mb/s */
  2370. range.min_rts = 0;
  2371. range.max_rts = 2347;
  2372. range.min_frag = 256;
  2373. range.max_frag = 2346;
  2374. if (orinoco_lock(priv, &flags) != 0)
  2375. return -EBUSY;
  2376. if (priv->has_wep) {
  2377. range.max_encoding_tokens = ORINOCO_MAX_KEYS;
  2378. range.encoding_size[0] = SMALL_KEY_SIZE;
  2379. range.num_encoding_sizes = 1;
  2380. if (priv->has_big_wep) {
  2381. range.encoding_size[1] = LARGE_KEY_SIZE;
  2382. range.num_encoding_sizes = 2;
  2383. }
  2384. } else {
  2385. range.num_encoding_sizes = 0;
  2386. range.max_encoding_tokens = 0;
  2387. }
  2388. orinoco_unlock(priv, &flags);
  2389. range.min_pmp = 0;
  2390. range.max_pmp = 65535000;
  2391. range.min_pmt = 0;
  2392. range.max_pmt = 65535 * 1000; /* ??? */
  2393. range.pmp_flags = IW_POWER_PERIOD;
  2394. range.pmt_flags = IW_POWER_TIMEOUT;
  2395. range.pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT | IW_POWER_UNICAST_R;
  2396. range.num_txpower = 1;
  2397. range.txpower[0] = 15; /* 15dBm */
  2398. range.txpower_capa = IW_TXPOW_DBM;
  2399. range.retry_capa = IW_RETRY_LIMIT | IW_RETRY_LIFETIME;
  2400. range.retry_flags = IW_RETRY_LIMIT;
  2401. range.r_time_flags = IW_RETRY_LIFETIME;
  2402. range.min_retry = 0;
  2403. range.max_retry = 65535; /* ??? */
  2404. range.min_r_time = 0;
  2405. range.max_r_time = 65535 * 1000; /* ??? */
  2406. if (copy_to_user(rrq->pointer, &range, sizeof(range)))
  2407. return -EFAULT;
  2408. TRACE_EXIT(dev->name);
  2409. return 0;
  2410. }
  2411. static int orinoco_ioctl_setiwencode(struct net_device *dev, struct iw_point *erq)
  2412. {
  2413. struct orinoco_private *priv = netdev_priv(dev);
  2414. int index = (erq->flags & IW_ENCODE_INDEX) - 1;
  2415. int setindex = priv->tx_key;
  2416. int enable = priv->wep_on;
  2417. int restricted = priv->wep_restrict;
  2418. u16 xlen = 0;
  2419. int err = 0;
  2420. char keybuf[ORINOCO_MAX_KEY_SIZE];
  2421. unsigned long flags;
  2422. if (! priv->has_wep)
  2423. return -EOPNOTSUPP;
  2424. if (erq->pointer) {
  2425. /* We actually have a key to set - check its length */
  2426. if (erq->length > LARGE_KEY_SIZE)
  2427. return -E2BIG;
  2428. if ( (erq->length > SMALL_KEY_SIZE) && !priv->has_big_wep )
  2429. return -E2BIG;
  2430. if (copy_from_user(keybuf, erq->pointer, erq->length))
  2431. return -EFAULT;
  2432. }
  2433. if (orinoco_lock(priv, &flags) != 0)
  2434. return -EBUSY;
  2435. if (erq->pointer) {
  2436. if ((index < 0) || (index >= ORINOCO_MAX_KEYS))
  2437. index = priv->tx_key;
  2438. /* Adjust key length to a supported value */
  2439. if (erq->length > SMALL_KEY_SIZE) {
  2440. xlen = LARGE_KEY_SIZE;
  2441. } else if (erq->length > 0) {
  2442. xlen = SMALL_KEY_SIZE;
  2443. } else
  2444. xlen = 0;
  2445. /* Switch on WEP if off */
  2446. if ((!enable) && (xlen > 0)) {
  2447. setindex = index;
  2448. enable = 1;
  2449. }
  2450. } else {
  2451. /* Important note : if the user do "iwconfig eth0 enc off",
  2452. * we will arrive there with an index of -1. This is valid
  2453. * but need to be taken care off... Jean II */
  2454. if ((index < 0) || (index >= ORINOCO_MAX_KEYS)) {
  2455. if((index != -1) || (erq->flags == 0)) {
  2456. err = -EINVAL;
  2457. goto out;
  2458. }
  2459. } else {
  2460. /* Set the index : Check that the key is valid */
  2461. if(priv->keys[index].len == 0) {
  2462. err = -EINVAL;
  2463. goto out;
  2464. }
  2465. setindex = index;
  2466. }
  2467. }
  2468. if (erq->flags & IW_ENCODE_DISABLED)
  2469. enable = 0;
  2470. if (erq->flags & IW_ENCODE_OPEN)
  2471. restricted = 0;
  2472. if (erq->flags & IW_ENCODE_RESTRICTED)
  2473. restricted = 1;
  2474. if (erq->pointer) {
  2475. priv->keys[index].len = cpu_to_le16(xlen);
  2476. memset(priv->keys[index].data, 0,
  2477. sizeof(priv->keys[index].data));
  2478. memcpy(priv->keys[index].data, keybuf, erq->length);
  2479. }
  2480. priv->tx_key = setindex;
  2481. /* Try fast key change if connected and only keys are changed */
  2482. if (priv->wep_on && enable && (priv->wep_restrict == restricted) &&
  2483. netif_carrier_ok(dev)) {
  2484. err = __orinoco_hw_setup_wepkeys(priv);
  2485. /* No need to commit if successful */
  2486. goto out;
  2487. }
  2488. priv->wep_on = enable;
  2489. priv->wep_restrict = restricted;
  2490. out:
  2491. orinoco_unlock(priv, &flags);
  2492. return err;
  2493. }
  2494. static int orinoco_ioctl_getiwencode(struct net_device *dev, struct iw_point *erq)
  2495. {
  2496. struct orinoco_private *priv = netdev_priv(dev);
  2497. int index = (erq->flags & IW_ENCODE_INDEX) - 1;
  2498. u16 xlen = 0;
  2499. char keybuf[ORINOCO_MAX_KEY_SIZE];
  2500. unsigned long flags;
  2501. if (! priv->has_wep)
  2502. return -EOPNOTSUPP;
  2503. if (orinoco_lock(priv, &flags) != 0)
  2504. return -EBUSY;
  2505. if ((index < 0) || (index >= ORINOCO_MAX_KEYS))
  2506. index = priv->tx_key;
  2507. erq->flags = 0;
  2508. if (! priv->wep_on)
  2509. erq->flags |= IW_ENCODE_DISABLED;
  2510. erq->flags |= index + 1;
  2511. if (priv->wep_restrict)
  2512. erq->flags |= IW_ENCODE_RESTRICTED;
  2513. else
  2514. erq->flags |= IW_ENCODE_OPEN;
  2515. xlen = le16_to_cpu(priv->keys[index].len);
  2516. erq->length = xlen;
  2517. memcpy(keybuf, priv->keys[index].data, ORINOCO_MAX_KEY_SIZE);
  2518. orinoco_unlock(priv, &flags);
  2519. if (erq->pointer) {
  2520. if (copy_to_user(erq->pointer, keybuf, xlen))
  2521. return -EFAULT;
  2522. }
  2523. return 0;
  2524. }
  2525. static int orinoco_ioctl_setessid(struct net_device *dev, struct iw_point *erq)
  2526. {
  2527. struct orinoco_private *priv = netdev_priv(dev);
  2528. char essidbuf[IW_ESSID_MAX_SIZE+1];
  2529. unsigned long flags;
  2530. /* Note : ESSID is ignored in Ad-Hoc demo mode, but we can set it
  2531. * anyway... - Jean II */
  2532. memset(&essidbuf, 0, sizeof(essidbuf));
  2533. if (erq->flags) {
  2534. if (erq->length > IW_ESSID_MAX_SIZE)
  2535. return -E2BIG;
  2536. if (copy_from_user(&essidbuf, erq->pointer, erq->length))
  2537. return -EFAULT;
  2538. essidbuf[erq->length] = '\0';
  2539. }
  2540. if (orinoco_lock(priv, &flags) != 0)
  2541. return -EBUSY;
  2542. memcpy(priv->desired_essid, essidbuf, sizeof(priv->desired_essid));
  2543. orinoco_unlock(priv, &flags);
  2544. return 0;
  2545. }
  2546. static int orinoco_ioctl_getessid(struct net_device *dev, struct iw_point *erq)
  2547. {
  2548. struct orinoco_private *priv = netdev_priv(dev);
  2549. char essidbuf[IW_ESSID_MAX_SIZE+1];
  2550. int active;
  2551. int err = 0;
  2552. unsigned long flags;
  2553. TRACE_ENTER(dev->name);
  2554. if (netif_running(dev)) {
  2555. err = orinoco_hw_get_essid(priv, &active, essidbuf);
  2556. if (err)
  2557. return err;
  2558. } else {
  2559. if (orinoco_lock(priv, &flags) != 0)
  2560. return -EBUSY;
  2561. memcpy(essidbuf, priv->desired_essid, sizeof(essidbuf));
  2562. orinoco_unlock(priv, &flags);
  2563. }
  2564. erq->flags = 1;
  2565. erq->length = strlen(essidbuf) + 1;
  2566. if (erq->pointer)
  2567. if (copy_to_user(erq->pointer, essidbuf, erq->length))
  2568. return -EFAULT;
  2569. TRACE_EXIT(dev->name);
  2570. return 0;
  2571. }
  2572. static int orinoco_ioctl_setnick(struct net_device *dev, struct iw_point *nrq)
  2573. {
  2574. struct orinoco_private *priv = netdev_priv(dev);
  2575. char nickbuf[IW_ESSID_MAX_SIZE+1];
  2576. unsigned long flags;
  2577. if (nrq->length > IW_ESSID_MAX_SIZE)
  2578. return -E2BIG;
  2579. memset(nickbuf, 0, sizeof(nickbuf));
  2580. if (copy_from_user(nickbuf, nrq->pointer, nrq->length))
  2581. return -EFAULT;
  2582. nickbuf[nrq->length] = '\0';
  2583. if (orinoco_lock(priv, &flags) != 0)
  2584. return -EBUSY;
  2585. memcpy(priv->nick, nickbuf, sizeof(priv->nick));
  2586. orinoco_unlock(priv, &flags);
  2587. return 0;
  2588. }
  2589. static int orinoco_ioctl_getnick(struct net_device *dev, struct iw_point *nrq)
  2590. {
  2591. struct orinoco_private *priv = netdev_priv(dev);
  2592. char nickbuf[IW_ESSID_MAX_SIZE+1];
  2593. unsigned long flags;
  2594. if (orinoco_lock(priv, &flags) != 0)
  2595. return -EBUSY;
  2596. memcpy(nickbuf, priv->nick, IW_ESSID_MAX_SIZE+1);
  2597. orinoco_unlock(priv, &flags);
  2598. nrq->length = strlen(nickbuf)+1;
  2599. if (copy_to_user(nrq->pointer, nickbuf, sizeof(nickbuf)))
  2600. return -EFAULT;
  2601. return 0;
  2602. }
  2603. static int orinoco_ioctl_setfreq(struct net_device *dev, struct iw_freq *frq)
  2604. {
  2605. struct orinoco_private *priv = netdev_priv(dev);
  2606. int chan = -1;
  2607. unsigned long flags;
  2608. /* We can only use this in Ad-Hoc demo mode to set the operating
  2609. * frequency, or in IBSS mode to set the frequency where the IBSS
  2610. * will be created - Jean II */
  2611. if (priv->iw_mode != IW_MODE_ADHOC)
  2612. return -EOPNOTSUPP;
  2613. if ( (frq->e == 0) && (frq->m <= 1000) ) {
  2614. /* Setting by channel number */
  2615. chan = frq->m;
  2616. } else {
  2617. /* Setting by frequency - search the table */
  2618. int mult = 1;
  2619. int i;
  2620. for (i = 0; i < (6 - frq->e); i++)
  2621. mult *= 10;
  2622. for (i = 0; i < NUM_CHANNELS; i++)
  2623. if (frq->m == (channel_frequency[i] * mult))
  2624. chan = i+1;
  2625. }
  2626. if ( (chan < 1) || (chan > NUM_CHANNELS) ||
  2627. ! (priv->channel_mask & (1 << (chan-1)) ) )
  2628. return -EINVAL;
  2629. if (orinoco_lock(priv, &flags) != 0)
  2630. return -EBUSY;
  2631. priv->channel = chan;
  2632. orinoco_unlock(priv, &flags);
  2633. return 0;
  2634. }
  2635. static int orinoco_ioctl_getsens(struct net_device *dev, struct iw_param *srq)
  2636. {
  2637. struct orinoco_private *priv = netdev_priv(dev);
  2638. hermes_t *hw = &priv->hw;
  2639. u16 val;
  2640. int err;
  2641. unsigned long flags;
  2642. if (!priv->has_sensitivity)
  2643. return -EOPNOTSUPP;
  2644. if (orinoco_lock(priv, &flags) != 0)
  2645. return -EBUSY;
  2646. err = hermes_read_wordrec(hw, USER_BAP,
  2647. HERMES_RID_CNFSYSTEMSCALE, &val);
  2648. orinoco_unlock(priv, &flags);
  2649. if (err)
  2650. return err;
  2651. srq->value = val;
  2652. srq->fixed = 0; /* auto */
  2653. return 0;
  2654. }
  2655. static int orinoco_ioctl_setsens(struct net_device *dev, struct iw_param *srq)
  2656. {
  2657. struct orinoco_private *priv = netdev_priv(dev);
  2658. int val = srq->value;
  2659. unsigned long flags;
  2660. if (!priv->has_sensitivity)
  2661. return -EOPNOTSUPP;
  2662. if ((val < 1) || (val > 3))
  2663. return -EINVAL;
  2664. if (orinoco_lock(priv, &flags) != 0)
  2665. return -EBUSY;
  2666. priv->ap_density = val;
  2667. orinoco_unlock(priv, &flags);
  2668. return 0;
  2669. }
  2670. static int orinoco_ioctl_setrts(struct net_device *dev, struct iw_param *rrq)
  2671. {
  2672. struct orinoco_private *priv = netdev_priv(dev);
  2673. int val = rrq->value;
  2674. unsigned long flags;
  2675. if (rrq->disabled)
  2676. val = 2347;
  2677. if ( (val < 0) || (val > 2347) )
  2678. return -EINVAL;
  2679. if (orinoco_lock(priv, &flags) != 0)
  2680. return -EBUSY;
  2681. priv->rts_thresh = val;
  2682. orinoco_unlock(priv, &flags);
  2683. return 0;
  2684. }
  2685. static int orinoco_ioctl_setfrag(struct net_device *dev, struct iw_param *frq)
  2686. {
  2687. struct orinoco_private *priv = netdev_priv(dev);
  2688. int err = 0;
  2689. unsigned long flags;
  2690. if (orinoco_lock(priv, &flags) != 0)
  2691. return -EBUSY;
  2692. if (priv->has_mwo) {
  2693. if (frq->disabled)
  2694. priv->mwo_robust = 0;
  2695. else {
  2696. if (frq->fixed)
  2697. printk(KERN_WARNING "%s: Fixed fragmentation is "
  2698. "not supported on this firmware. "
  2699. "Using MWO robust instead.\n", dev->name);
  2700. priv->mwo_robust = 1;
  2701. }
  2702. } else {
  2703. if (frq->disabled)
  2704. priv->frag_thresh = 2346;
  2705. else {
  2706. if ( (frq->value < 256) || (frq->value > 2346) )
  2707. err = -EINVAL;
  2708. else
  2709. priv->frag_thresh = frq->value & ~0x1; /* must be even */
  2710. }
  2711. }
  2712. orinoco_unlock(priv, &flags);
  2713. return err;
  2714. }
  2715. static int orinoco_ioctl_getfrag(struct net_device *dev, struct iw_param *frq)
  2716. {
  2717. struct orinoco_private *priv = netdev_priv(dev);
  2718. hermes_t *hw = &priv->hw;
  2719. int err = 0;
  2720. u16 val;
  2721. unsigned long flags;
  2722. if (orinoco_lock(priv, &flags) != 0)
  2723. return -EBUSY;
  2724. if (priv->has_mwo) {
  2725. err = hermes_read_wordrec(hw, USER_BAP,
  2726. HERMES_RID_CNFMWOROBUST_AGERE,
  2727. &val);
  2728. if (err)
  2729. val = 0;
  2730. frq->value = val ? 2347 : 0;
  2731. frq->disabled = ! val;
  2732. frq->fixed = 0;
  2733. } else {
  2734. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
  2735. &val);
  2736. if (err)
  2737. val = 0;
  2738. frq->value = val;
  2739. frq->disabled = (val >= 2346);
  2740. frq->fixed = 1;
  2741. }
  2742. orinoco_unlock(priv, &flags);
  2743. return err;
  2744. }
  2745. static int orinoco_ioctl_setrate(struct net_device *dev, struct iw_param *rrq)
  2746. {
  2747. struct orinoco_private *priv = netdev_priv(dev);
  2748. int err = 0;
  2749. int ratemode = -1;
  2750. int bitrate; /* 100s of kilobits */
  2751. int i;
  2752. unsigned long flags;
  2753. /* As the user space doesn't know our highest rate, it uses -1
  2754. * to ask us to set the highest rate. Test it using "iwconfig
  2755. * ethX rate auto" - Jean II */
  2756. if (rrq->value == -1)
  2757. bitrate = 110;
  2758. else {
  2759. if (rrq->value % 100000)
  2760. return -EINVAL;
  2761. bitrate = rrq->value / 100000;
  2762. }
  2763. if ( (bitrate != 10) && (bitrate != 20) &&
  2764. (bitrate != 55) && (bitrate != 110) )
  2765. return -EINVAL;
  2766. for (i = 0; i < BITRATE_TABLE_SIZE; i++)
  2767. if ( (bitrate_table[i].bitrate == bitrate) &&
  2768. (bitrate_table[i].automatic == ! rrq->fixed) ) {
  2769. ratemode = i;
  2770. break;
  2771. }
  2772. if (ratemode == -1)
  2773. return -EINVAL;
  2774. if (orinoco_lock(priv, &flags) != 0)
  2775. return -EBUSY;
  2776. priv->bitratemode = ratemode;
  2777. orinoco_unlock(priv, &flags);
  2778. return err;
  2779. }
  2780. static int orinoco_ioctl_getrate(struct net_device *dev, struct iw_param *rrq)
  2781. {
  2782. struct orinoco_private *priv = netdev_priv(dev);
  2783. hermes_t *hw = &priv->hw;
  2784. int err = 0;
  2785. int ratemode;
  2786. int i;
  2787. u16 val;
  2788. unsigned long flags;
  2789. if (orinoco_lock(priv, &flags) != 0)
  2790. return -EBUSY;
  2791. ratemode = priv->bitratemode;
  2792. BUG_ON((ratemode < 0) || (ratemode >= BITRATE_TABLE_SIZE));
  2793. rrq->value = bitrate_table[ratemode].bitrate * 100000;
  2794. rrq->fixed = ! bitrate_table[ratemode].automatic;
  2795. rrq->disabled = 0;
  2796. /* If the interface is running we try to find more about the
  2797. current mode */
  2798. if (netif_running(dev)) {
  2799. err = hermes_read_wordrec(hw, USER_BAP,
  2800. HERMES_RID_CURRENTTXRATE, &val);
  2801. if (err)
  2802. goto out;
  2803. switch (priv->firmware_type) {
  2804. case FIRMWARE_TYPE_AGERE: /* Lucent style rate */
  2805. /* Note : in Lucent firmware, the return value of
  2806. * HERMES_RID_CURRENTTXRATE is the bitrate in Mb/s,
  2807. * and therefore is totally different from the
  2808. * encoding of HERMES_RID_CNFTXRATECONTROL.
  2809. * Don't forget that 6Mb/s is really 5.5Mb/s */
  2810. if (val == 6)
  2811. rrq->value = 5500000;
  2812. else
  2813. rrq->value = val * 1000000;
  2814. break;
  2815. case FIRMWARE_TYPE_INTERSIL: /* Intersil style rate */
  2816. case FIRMWARE_TYPE_SYMBOL: /* Symbol style rate */
  2817. for (i = 0; i < BITRATE_TABLE_SIZE; i++)
  2818. if (bitrate_table[i].intersil_txratectrl == val) {
  2819. ratemode = i;
  2820. break;
  2821. }
  2822. if (i >= BITRATE_TABLE_SIZE)
  2823. printk(KERN_INFO "%s: Unable to determine current bitrate (0x%04hx)\n",
  2824. dev->name, val);
  2825. rrq->value = bitrate_table[ratemode].bitrate * 100000;
  2826. break;
  2827. default:
  2828. BUG();
  2829. }
  2830. }
  2831. out:
  2832. orinoco_unlock(priv, &flags);
  2833. return err;
  2834. }
  2835. static int orinoco_ioctl_setpower(struct net_device *dev, struct iw_param *prq)
  2836. {
  2837. struct orinoco_private *priv = netdev_priv(dev);
  2838. int err = 0;
  2839. unsigned long flags;
  2840. if (orinoco_lock(priv, &flags) != 0)
  2841. return -EBUSY;
  2842. if (prq->disabled) {
  2843. priv->pm_on = 0;
  2844. } else {
  2845. switch (prq->flags & IW_POWER_MODE) {
  2846. case IW_POWER_UNICAST_R:
  2847. priv->pm_mcast = 0;
  2848. priv->pm_on = 1;
  2849. break;
  2850. case IW_POWER_ALL_R:
  2851. priv->pm_mcast = 1;
  2852. priv->pm_on = 1;
  2853. break;
  2854. case IW_POWER_ON:
  2855. /* No flags : but we may have a value - Jean II */
  2856. break;
  2857. default:
  2858. err = -EINVAL;
  2859. }
  2860. if (err)
  2861. goto out;
  2862. if (prq->flags & IW_POWER_TIMEOUT) {
  2863. priv->pm_on = 1;
  2864. priv->pm_timeout = prq->value / 1000;
  2865. }
  2866. if (prq->flags & IW_POWER_PERIOD) {
  2867. priv->pm_on = 1;
  2868. priv->pm_period = prq->value / 1000;
  2869. }
  2870. /* It's valid to not have a value if we are just toggling
  2871. * the flags... Jean II */
  2872. if(!priv->pm_on) {
  2873. err = -EINVAL;
  2874. goto out;
  2875. }
  2876. }
  2877. out:
  2878. orinoco_unlock(priv, &flags);
  2879. return err;
  2880. }
  2881. static int orinoco_ioctl_getpower(struct net_device *dev, struct iw_param *prq)
  2882. {
  2883. struct orinoco_private *priv = netdev_priv(dev);
  2884. hermes_t *hw = &priv->hw;
  2885. int err = 0;
  2886. u16 enable, period, timeout, mcast;
  2887. unsigned long flags;
  2888. if (orinoco_lock(priv, &flags) != 0)
  2889. return -EBUSY;
  2890. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFPMENABLED, &enable);
  2891. if (err)
  2892. goto out;
  2893. err = hermes_read_wordrec(hw, USER_BAP,
  2894. HERMES_RID_CNFMAXSLEEPDURATION, &period);
  2895. if (err)
  2896. goto out;
  2897. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFPMHOLDOVERDURATION, &timeout);
  2898. if (err)
  2899. goto out;
  2900. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFMULTICASTRECEIVE, &mcast);
  2901. if (err)
  2902. goto out;
  2903. prq->disabled = !enable;
  2904. /* Note : by default, display the period */
  2905. if ((prq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
  2906. prq->flags = IW_POWER_TIMEOUT;
  2907. prq->value = timeout * 1000;
  2908. } else {
  2909. prq->flags = IW_POWER_PERIOD;
  2910. prq->value = period * 1000;
  2911. }
  2912. if (mcast)
  2913. prq->flags |= IW_POWER_ALL_R;
  2914. else
  2915. prq->flags |= IW_POWER_UNICAST_R;
  2916. out:
  2917. orinoco_unlock(priv, &flags);
  2918. return err;
  2919. }
  2920. static int orinoco_ioctl_getretry(struct net_device *dev, struct iw_param *rrq)
  2921. {
  2922. struct orinoco_private *priv = netdev_priv(dev);
  2923. hermes_t *hw = &priv->hw;
  2924. int err = 0;
  2925. u16 short_limit, long_limit, lifetime;
  2926. unsigned long flags;
  2927. if (orinoco_lock(priv, &flags) != 0)
  2928. return -EBUSY;
  2929. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_SHORTRETRYLIMIT,
  2930. &short_limit);
  2931. if (err)
  2932. goto out;
  2933. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_LONGRETRYLIMIT,
  2934. &long_limit);
  2935. if (err)
  2936. goto out;
  2937. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_MAXTRANSMITLIFETIME,
  2938. &lifetime);
  2939. if (err)
  2940. goto out;
  2941. rrq->disabled = 0; /* Can't be disabled */
  2942. /* Note : by default, display the retry number */
  2943. if ((rrq->flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
  2944. rrq->flags = IW_RETRY_LIFETIME;
  2945. rrq->value = lifetime * 1000; /* ??? */
  2946. } else {
  2947. /* By default, display the min number */
  2948. if ((rrq->flags & IW_RETRY_MAX)) {
  2949. rrq->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
  2950. rrq->value = long_limit;
  2951. } else {
  2952. rrq->flags = IW_RETRY_LIMIT;
  2953. rrq->value = short_limit;
  2954. if(short_limit != long_limit)
  2955. rrq->flags |= IW_RETRY_MIN;
  2956. }
  2957. }
  2958. out:
  2959. orinoco_unlock(priv, &flags);
  2960. return err;
  2961. }
  2962. static int orinoco_ioctl_setibssport(struct net_device *dev, struct iwreq *wrq)
  2963. {
  2964. struct orinoco_private *priv = netdev_priv(dev);
  2965. int val = *( (int *) wrq->u.name );
  2966. unsigned long flags;
  2967. if (orinoco_lock(priv, &flags) != 0)
  2968. return -EBUSY;
  2969. priv->ibss_port = val ;
  2970. /* Actually update the mode we are using */
  2971. set_port_type(priv);
  2972. orinoco_unlock(priv, &flags);
  2973. return 0;
  2974. }
  2975. static int orinoco_ioctl_getibssport(struct net_device *dev, struct iwreq *wrq)
  2976. {
  2977. struct orinoco_private *priv = netdev_priv(dev);
  2978. int *val = (int *)wrq->u.name;
  2979. unsigned long flags;
  2980. if (orinoco_lock(priv, &flags) != 0)
  2981. return -EBUSY;
  2982. *val = priv->ibss_port;
  2983. orinoco_unlock(priv, &flags);
  2984. return 0;
  2985. }
  2986. static int orinoco_ioctl_setport3(struct net_device *dev, struct iwreq *wrq)
  2987. {
  2988. struct orinoco_private *priv = netdev_priv(dev);
  2989. int val = *( (int *) wrq->u.name );
  2990. int err = 0;
  2991. unsigned long flags;
  2992. if (orinoco_lock(priv, &flags) != 0)
  2993. return -EBUSY;
  2994. switch (val) {
  2995. case 0: /* Try to do IEEE ad-hoc mode */
  2996. if (! priv->has_ibss) {
  2997. err = -EINVAL;
  2998. break;
  2999. }
  3000. priv->prefer_port3 = 0;
  3001. break;
  3002. case 1: /* Try to do Lucent proprietary ad-hoc mode */
  3003. if (! priv->has_port3) {
  3004. err = -EINVAL;
  3005. break;
  3006. }
  3007. priv->prefer_port3 = 1;
  3008. break;
  3009. default:
  3010. err = -EINVAL;
  3011. }
  3012. if (! err)
  3013. /* Actually update the mode we are using */
  3014. set_port_type(priv);
  3015. orinoco_unlock(priv, &flags);
  3016. return err;
  3017. }
  3018. static int orinoco_ioctl_getport3(struct net_device *dev, struct iwreq *wrq)
  3019. {
  3020. struct orinoco_private *priv = netdev_priv(dev);
  3021. int *val = (int *)wrq->u.name;
  3022. unsigned long flags;
  3023. if (orinoco_lock(priv, &flags) != 0)
  3024. return -EBUSY;
  3025. *val = priv->prefer_port3;
  3026. orinoco_unlock(priv, &flags);
  3027. return 0;
  3028. }
  3029. /* Spy is used for link quality/strength measurements in Ad-Hoc mode
  3030. * Jean II */
  3031. static int orinoco_ioctl_setspy(struct net_device *dev, struct iw_point *srq)
  3032. {
  3033. struct orinoco_private *priv = netdev_priv(dev);
  3034. struct sockaddr address[IW_MAX_SPY];
  3035. int number = srq->length;
  3036. int i;
  3037. int err = 0;
  3038. unsigned long flags;
  3039. /* Check the number of addresses */
  3040. if (number > IW_MAX_SPY)
  3041. return -E2BIG;
  3042. /* Get the data in the driver */
  3043. if (srq->pointer) {
  3044. if (copy_from_user(address, srq->pointer,
  3045. sizeof(struct sockaddr) * number))
  3046. return -EFAULT;
  3047. }
  3048. /* Make sure nobody mess with the structure while we do */
  3049. if (orinoco_lock(priv, &flags) != 0)
  3050. return -EBUSY;
  3051. /* orinoco_lock() doesn't disable interrupts, so make sure the
  3052. * interrupt rx path don't get confused while we copy */
  3053. priv->spy_number = 0;
  3054. if (number > 0) {
  3055. /* Extract the addresses */
  3056. for (i = 0; i < number; i++)
  3057. memcpy(priv->spy_address[i], address[i].sa_data,
  3058. ETH_ALEN);
  3059. /* Reset stats */
  3060. memset(priv->spy_stat, 0,
  3061. sizeof(struct iw_quality) * IW_MAX_SPY);
  3062. /* Set number of addresses */
  3063. priv->spy_number = number;
  3064. }
  3065. /* Now, let the others play */
  3066. orinoco_unlock(priv, &flags);
  3067. return err;
  3068. }
  3069. static int orinoco_ioctl_getspy(struct net_device *dev, struct iw_point *srq)
  3070. {
  3071. struct orinoco_private *priv = netdev_priv(dev);
  3072. struct sockaddr address[IW_MAX_SPY];
  3073. struct iw_quality spy_stat[IW_MAX_SPY];
  3074. int number;
  3075. int i;
  3076. unsigned long flags;
  3077. if (orinoco_lock(priv, &flags) != 0)
  3078. return -EBUSY;
  3079. number = priv->spy_number;
  3080. if ((number > 0) && (srq->pointer)) {
  3081. /* Create address struct */
  3082. for (i = 0; i < number; i++) {
  3083. memcpy(address[i].sa_data, priv->spy_address[i],
  3084. ETH_ALEN);
  3085. address[i].sa_family = AF_UNIX;
  3086. }
  3087. /* Copy stats */
  3088. /* In theory, we should disable irqs while copying the stats
  3089. * because the rx path might update it in the middle...
  3090. * Bah, who care ? - Jean II */
  3091. memcpy(&spy_stat, priv->spy_stat,
  3092. sizeof(struct iw_quality) * IW_MAX_SPY);
  3093. for (i=0; i < number; i++)
  3094. priv->spy_stat[i].updated = 0;
  3095. }
  3096. orinoco_unlock(priv, &flags);
  3097. /* Push stuff to user space */
  3098. srq->length = number;
  3099. if(copy_to_user(srq->pointer, address,
  3100. sizeof(struct sockaddr) * number))
  3101. return -EFAULT;
  3102. if(copy_to_user(srq->pointer + (sizeof(struct sockaddr)*number),
  3103. &spy_stat, sizeof(struct iw_quality) * number))
  3104. return -EFAULT;
  3105. return 0;
  3106. }
  3107. static int
  3108. orinoco_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
  3109. {
  3110. struct orinoco_private *priv = netdev_priv(dev);
  3111. struct iwreq *wrq = (struct iwreq *)rq;
  3112. int err = 0;
  3113. int tmp;
  3114. int changed = 0;
  3115. unsigned long flags;
  3116. TRACE_ENTER(dev->name);
  3117. /* In theory, we could allow most of the the SET stuff to be
  3118. * done. In practice, the lapse of time at startup when the
  3119. * card is not ready is very short, so why bother... Note
  3120. * that netif_device_present is different from up/down
  3121. * (ifconfig), when the device is not yet up, it is usually
  3122. * already ready... Jean II */
  3123. if (! netif_device_present(dev))
  3124. return -ENODEV;
  3125. switch (cmd) {
  3126. case SIOCGIWNAME:
  3127. strcpy(wrq->u.name, "IEEE 802.11-DS");
  3128. break;
  3129. case SIOCGIWAP:
  3130. wrq->u.ap_addr.sa_family = ARPHRD_ETHER;
  3131. err = orinoco_hw_get_bssid(priv, wrq->u.ap_addr.sa_data);
  3132. break;
  3133. case SIOCGIWRANGE:
  3134. err = orinoco_ioctl_getiwrange(dev, &wrq->u.data);
  3135. break;
  3136. case SIOCSIWMODE:
  3137. if (orinoco_lock(priv, &flags) != 0)
  3138. return -EBUSY;
  3139. switch (wrq->u.mode) {
  3140. case IW_MODE_ADHOC:
  3141. if (! (priv->has_ibss || priv->has_port3) )
  3142. err = -EINVAL;
  3143. else {
  3144. priv->iw_mode = IW_MODE_ADHOC;
  3145. changed = 1;
  3146. }
  3147. break;
  3148. case IW_MODE_INFRA:
  3149. priv->iw_mode = IW_MODE_INFRA;
  3150. changed = 1;
  3151. break;
  3152. default:
  3153. err = -EINVAL;
  3154. break;
  3155. }
  3156. set_port_type(priv);
  3157. orinoco_unlock(priv, &flags);
  3158. break;
  3159. case SIOCGIWMODE:
  3160. if (orinoco_lock(priv, &flags) != 0)
  3161. return -EBUSY;
  3162. wrq->u.mode = priv->iw_mode;
  3163. orinoco_unlock(priv, &flags);
  3164. break;
  3165. case SIOCSIWENCODE:
  3166. err = orinoco_ioctl_setiwencode(dev, &wrq->u.encoding);
  3167. if (! err)
  3168. changed = 1;
  3169. break;
  3170. case SIOCGIWENCODE:
  3171. if (! capable(CAP_NET_ADMIN)) {
  3172. err = -EPERM;
  3173. break;
  3174. }
  3175. err = orinoco_ioctl_getiwencode(dev, &wrq->u.encoding);
  3176. break;
  3177. case SIOCSIWESSID:
  3178. err = orinoco_ioctl_setessid(dev, &wrq->u.essid);
  3179. if (! err)
  3180. changed = 1;
  3181. break;
  3182. case SIOCGIWESSID:
  3183. err = orinoco_ioctl_getessid(dev, &wrq->u.essid);
  3184. break;
  3185. case SIOCSIWNICKN:
  3186. err = orinoco_ioctl_setnick(dev, &wrq->u.data);
  3187. if (! err)
  3188. changed = 1;
  3189. break;
  3190. case SIOCGIWNICKN:
  3191. err = orinoco_ioctl_getnick(dev, &wrq->u.data);
  3192. break;
  3193. case SIOCGIWFREQ:
  3194. tmp = orinoco_hw_get_freq(priv);
  3195. if (tmp < 0) {
  3196. err = tmp;
  3197. } else {
  3198. wrq->u.freq.m = tmp;
  3199. wrq->u.freq.e = 1;
  3200. }
  3201. break;
  3202. case SIOCSIWFREQ:
  3203. err = orinoco_ioctl_setfreq(dev, &wrq->u.freq);
  3204. if (! err)
  3205. changed = 1;
  3206. break;
  3207. case SIOCGIWSENS:
  3208. err = orinoco_ioctl_getsens(dev, &wrq->u.sens);
  3209. break;
  3210. case SIOCSIWSENS:
  3211. err = orinoco_ioctl_setsens(dev, &wrq->u.sens);
  3212. if (! err)
  3213. changed = 1;
  3214. break;
  3215. case SIOCGIWRTS:
  3216. wrq->u.rts.value = priv->rts_thresh;
  3217. wrq->u.rts.disabled = (wrq->u.rts.value == 2347);
  3218. wrq->u.rts.fixed = 1;
  3219. break;
  3220. case SIOCSIWRTS:
  3221. err = orinoco_ioctl_setrts(dev, &wrq->u.rts);
  3222. if (! err)
  3223. changed = 1;
  3224. break;
  3225. case SIOCSIWFRAG:
  3226. err = orinoco_ioctl_setfrag(dev, &wrq->u.frag);
  3227. if (! err)
  3228. changed = 1;
  3229. break;
  3230. case SIOCGIWFRAG:
  3231. err = orinoco_ioctl_getfrag(dev, &wrq->u.frag);
  3232. break;
  3233. case SIOCSIWRATE:
  3234. err = orinoco_ioctl_setrate(dev, &wrq->u.bitrate);
  3235. if (! err)
  3236. changed = 1;
  3237. break;
  3238. case SIOCGIWRATE:
  3239. err = orinoco_ioctl_getrate(dev, &wrq->u.bitrate);
  3240. break;
  3241. case SIOCSIWPOWER:
  3242. err = orinoco_ioctl_setpower(dev, &wrq->u.power);
  3243. if (! err)
  3244. changed = 1;
  3245. break;
  3246. case SIOCGIWPOWER:
  3247. err = orinoco_ioctl_getpower(dev, &wrq->u.power);
  3248. break;
  3249. case SIOCGIWTXPOW:
  3250. /* The card only supports one tx power, so this is easy */
  3251. wrq->u.txpower.value = 15; /* dBm */
  3252. wrq->u.txpower.fixed = 1;
  3253. wrq->u.txpower.disabled = 0;
  3254. wrq->u.txpower.flags = IW_TXPOW_DBM;
  3255. break;
  3256. case SIOCSIWRETRY:
  3257. err = -EOPNOTSUPP;
  3258. break;
  3259. case SIOCGIWRETRY:
  3260. err = orinoco_ioctl_getretry(dev, &wrq->u.retry);
  3261. break;
  3262. case SIOCSIWSPY:
  3263. err = orinoco_ioctl_setspy(dev, &wrq->u.data);
  3264. break;
  3265. case SIOCGIWSPY:
  3266. err = orinoco_ioctl_getspy(dev, &wrq->u.data);
  3267. break;
  3268. case SIOCGIWPRIV:
  3269. if (wrq->u.data.pointer) {
  3270. struct iw_priv_args privtab[] = {
  3271. { SIOCIWFIRSTPRIV + 0x0, 0, 0, "force_reset" },
  3272. { SIOCIWFIRSTPRIV + 0x1, 0, 0, "card_reset" },
  3273. { SIOCIWFIRSTPRIV + 0x2,
  3274. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  3275. 0, "set_port3" },
  3276. { SIOCIWFIRSTPRIV + 0x3, 0,
  3277. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  3278. "get_port3" },
  3279. { SIOCIWFIRSTPRIV + 0x4,
  3280. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  3281. 0, "set_preamble" },
  3282. { SIOCIWFIRSTPRIV + 0x5, 0,
  3283. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  3284. "get_preamble" },
  3285. { SIOCIWFIRSTPRIV + 0x6,
  3286. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  3287. 0, "set_ibssport" },
  3288. { SIOCIWFIRSTPRIV + 0x7, 0,
  3289. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  3290. "get_ibssport" },
  3291. { SIOCIWLASTPRIV, 0, 0, "dump_recs" },
  3292. };
  3293. wrq->u.data.length = sizeof(privtab) / sizeof(privtab[0]);
  3294. if (copy_to_user(wrq->u.data.pointer, privtab, sizeof(privtab)))
  3295. err = -EFAULT;
  3296. }
  3297. break;
  3298. case SIOCIWFIRSTPRIV + 0x0: /* force_reset */
  3299. case SIOCIWFIRSTPRIV + 0x1: /* card_reset */
  3300. if (! capable(CAP_NET_ADMIN)) {
  3301. err = -EPERM;
  3302. break;
  3303. }
  3304. printk(KERN_DEBUG "%s: Force scheduling reset!\n", dev->name);
  3305. schedule_work(&priv->reset_work);
  3306. break;
  3307. case SIOCIWFIRSTPRIV + 0x2: /* set_port3 */
  3308. if (! capable(CAP_NET_ADMIN)) {
  3309. err = -EPERM;
  3310. break;
  3311. }
  3312. err = orinoco_ioctl_setport3(dev, wrq);
  3313. if (! err)
  3314. changed = 1;
  3315. break;
  3316. case SIOCIWFIRSTPRIV + 0x3: /* get_port3 */
  3317. err = orinoco_ioctl_getport3(dev, wrq);
  3318. break;
  3319. case SIOCIWFIRSTPRIV + 0x4: /* set_preamble */
  3320. if (! capable(CAP_NET_ADMIN)) {
  3321. err = -EPERM;
  3322. break;
  3323. }
  3324. /* 802.11b has recently defined some short preamble.
  3325. * Basically, the Phy header has been reduced in size.
  3326. * This increase performance, especially at high rates
  3327. * (the preamble is transmitted at 1Mb/s), unfortunately
  3328. * this give compatibility troubles... - Jean II */
  3329. if(priv->has_preamble) {
  3330. int val = *( (int *) wrq->u.name );
  3331. if (orinoco_lock(priv, &flags) != 0)
  3332. return -EBUSY;
  3333. if (val)
  3334. priv->preamble = 1;
  3335. else
  3336. priv->preamble = 0;
  3337. orinoco_unlock(priv, &flags);
  3338. changed = 1;
  3339. } else
  3340. err = -EOPNOTSUPP;
  3341. break;
  3342. case SIOCIWFIRSTPRIV + 0x5: /* get_preamble */
  3343. if(priv->has_preamble) {
  3344. int *val = (int *)wrq->u.name;
  3345. if (orinoco_lock(priv, &flags) != 0)
  3346. return -EBUSY;
  3347. *val = priv->preamble;
  3348. orinoco_unlock(priv, &flags);
  3349. } else
  3350. err = -EOPNOTSUPP;
  3351. break;
  3352. case SIOCIWFIRSTPRIV + 0x6: /* set_ibssport */
  3353. if (! capable(CAP_NET_ADMIN)) {
  3354. err = -EPERM;
  3355. break;
  3356. }
  3357. err = orinoco_ioctl_setibssport(dev, wrq);
  3358. if (! err)
  3359. changed = 1;
  3360. break;
  3361. case SIOCIWFIRSTPRIV + 0x7: /* get_ibssport */
  3362. err = orinoco_ioctl_getibssport(dev, wrq);
  3363. break;
  3364. case SIOCIWLASTPRIV:
  3365. err = orinoco_debug_dump_recs(dev);
  3366. if (err)
  3367. printk(KERN_ERR "%s: Unable to dump records (%d)\n",
  3368. dev->name, err);
  3369. break;
  3370. default:
  3371. err = -EOPNOTSUPP;
  3372. }
  3373. if (! err && changed && netif_running(dev)) {
  3374. err = orinoco_reconfigure(dev);
  3375. }
  3376. TRACE_EXIT(dev->name);
  3377. return err;
  3378. }
  3379. struct {
  3380. u16 rid;
  3381. char *name;
  3382. int displaytype;
  3383. #define DISPLAY_WORDS 0
  3384. #define DISPLAY_BYTES 1
  3385. #define DISPLAY_STRING 2
  3386. #define DISPLAY_XSTRING 3
  3387. } record_table[] = {
  3388. #define DEBUG_REC(name,type) { HERMES_RID_##name, #name, DISPLAY_##type }
  3389. DEBUG_REC(CNFPORTTYPE,WORDS),
  3390. DEBUG_REC(CNFOWNMACADDR,BYTES),
  3391. DEBUG_REC(CNFDESIREDSSID,STRING),
  3392. DEBUG_REC(CNFOWNCHANNEL,WORDS),
  3393. DEBUG_REC(CNFOWNSSID,STRING),
  3394. DEBUG_REC(CNFOWNATIMWINDOW,WORDS),
  3395. DEBUG_REC(CNFSYSTEMSCALE,WORDS),
  3396. DEBUG_REC(CNFMAXDATALEN,WORDS),
  3397. DEBUG_REC(CNFPMENABLED,WORDS),
  3398. DEBUG_REC(CNFPMEPS,WORDS),
  3399. DEBUG_REC(CNFMULTICASTRECEIVE,WORDS),
  3400. DEBUG_REC(CNFMAXSLEEPDURATION,WORDS),
  3401. DEBUG_REC(CNFPMHOLDOVERDURATION,WORDS),
  3402. DEBUG_REC(CNFOWNNAME,STRING),
  3403. DEBUG_REC(CNFOWNDTIMPERIOD,WORDS),
  3404. DEBUG_REC(CNFMULTICASTPMBUFFERING,WORDS),
  3405. DEBUG_REC(CNFWEPENABLED_AGERE,WORDS),
  3406. DEBUG_REC(CNFMANDATORYBSSID_SYMBOL,WORDS),
  3407. DEBUG_REC(CNFWEPDEFAULTKEYID,WORDS),
  3408. DEBUG_REC(CNFDEFAULTKEY0,BYTES),
  3409. DEBUG_REC(CNFDEFAULTKEY1,BYTES),
  3410. DEBUG_REC(CNFMWOROBUST_AGERE,WORDS),
  3411. DEBUG_REC(CNFDEFAULTKEY2,BYTES),
  3412. DEBUG_REC(CNFDEFAULTKEY3,BYTES),
  3413. DEBUG_REC(CNFWEPFLAGS_INTERSIL,WORDS),
  3414. DEBUG_REC(CNFWEPKEYMAPPINGTABLE,WORDS),
  3415. DEBUG_REC(CNFAUTHENTICATION,WORDS),
  3416. DEBUG_REC(CNFMAXASSOCSTA,WORDS),
  3417. DEBUG_REC(CNFKEYLENGTH_SYMBOL,WORDS),
  3418. DEBUG_REC(CNFTXCONTROL,WORDS),
  3419. DEBUG_REC(CNFROAMINGMODE,WORDS),
  3420. DEBUG_REC(CNFHOSTAUTHENTICATION,WORDS),
  3421. DEBUG_REC(CNFRCVCRCERROR,WORDS),
  3422. DEBUG_REC(CNFMMLIFE,WORDS),
  3423. DEBUG_REC(CNFALTRETRYCOUNT,WORDS),
  3424. DEBUG_REC(CNFBEACONINT,WORDS),
  3425. DEBUG_REC(CNFAPPCFINFO,WORDS),
  3426. DEBUG_REC(CNFSTAPCFINFO,WORDS),
  3427. DEBUG_REC(CNFPRIORITYQUSAGE,WORDS),
  3428. DEBUG_REC(CNFTIMCTRL,WORDS),
  3429. DEBUG_REC(CNFTHIRTY2TALLY,WORDS),
  3430. DEBUG_REC(CNFENHSECURITY,WORDS),
  3431. DEBUG_REC(CNFGROUPADDRESSES,BYTES),
  3432. DEBUG_REC(CNFCREATEIBSS,WORDS),
  3433. DEBUG_REC(CNFFRAGMENTATIONTHRESHOLD,WORDS),
  3434. DEBUG_REC(CNFRTSTHRESHOLD,WORDS),
  3435. DEBUG_REC(CNFTXRATECONTROL,WORDS),
  3436. DEBUG_REC(CNFPROMISCUOUSMODE,WORDS),
  3437. DEBUG_REC(CNFBASICRATES_SYMBOL,WORDS),
  3438. DEBUG_REC(CNFPREAMBLE_SYMBOL,WORDS),
  3439. DEBUG_REC(CNFSHORTPREAMBLE,WORDS),
  3440. DEBUG_REC(CNFWEPKEYS_AGERE,BYTES),
  3441. DEBUG_REC(CNFEXCLUDELONGPREAMBLE,WORDS),
  3442. DEBUG_REC(CNFTXKEY_AGERE,WORDS),
  3443. DEBUG_REC(CNFAUTHENTICATIONRSPTO,WORDS),
  3444. DEBUG_REC(CNFBASICRATES,WORDS),
  3445. DEBUG_REC(CNFSUPPORTEDRATES,WORDS),
  3446. DEBUG_REC(CNFTICKTIME,WORDS),
  3447. DEBUG_REC(CNFSCANREQUEST,WORDS),
  3448. DEBUG_REC(CNFJOINREQUEST,WORDS),
  3449. DEBUG_REC(CNFAUTHENTICATESTATION,WORDS),
  3450. DEBUG_REC(CNFCHANNELINFOREQUEST,WORDS),
  3451. DEBUG_REC(MAXLOADTIME,WORDS),
  3452. DEBUG_REC(DOWNLOADBUFFER,WORDS),
  3453. DEBUG_REC(PRIID,WORDS),
  3454. DEBUG_REC(PRISUPRANGE,WORDS),
  3455. DEBUG_REC(CFIACTRANGES,WORDS),
  3456. DEBUG_REC(NICSERNUM,XSTRING),
  3457. DEBUG_REC(NICID,WORDS),
  3458. DEBUG_REC(MFISUPRANGE,WORDS),
  3459. DEBUG_REC(CFISUPRANGE,WORDS),
  3460. DEBUG_REC(CHANNELLIST,WORDS),
  3461. DEBUG_REC(REGULATORYDOMAINS,WORDS),
  3462. DEBUG_REC(TEMPTYPE,WORDS),
  3463. /* DEBUG_REC(CIS,BYTES), */
  3464. DEBUG_REC(STAID,WORDS),
  3465. DEBUG_REC(CURRENTSSID,STRING),
  3466. DEBUG_REC(CURRENTBSSID,BYTES),
  3467. DEBUG_REC(COMMSQUALITY,WORDS),
  3468. DEBUG_REC(CURRENTTXRATE,WORDS),
  3469. DEBUG_REC(CURRENTBEACONINTERVAL,WORDS),
  3470. DEBUG_REC(CURRENTSCALETHRESHOLDS,WORDS),
  3471. DEBUG_REC(PROTOCOLRSPTIME,WORDS),
  3472. DEBUG_REC(SHORTRETRYLIMIT,WORDS),
  3473. DEBUG_REC(LONGRETRYLIMIT,WORDS),
  3474. DEBUG_REC(MAXTRANSMITLIFETIME,WORDS),
  3475. DEBUG_REC(MAXRECEIVELIFETIME,WORDS),
  3476. DEBUG_REC(CFPOLLABLE,WORDS),
  3477. DEBUG_REC(AUTHENTICATIONALGORITHMS,WORDS),
  3478. DEBUG_REC(PRIVACYOPTIONIMPLEMENTED,WORDS),
  3479. DEBUG_REC(OWNMACADDR,BYTES),
  3480. DEBUG_REC(SCANRESULTSTABLE,WORDS),
  3481. DEBUG_REC(PHYTYPE,WORDS),
  3482. DEBUG_REC(CURRENTCHANNEL,WORDS),
  3483. DEBUG_REC(CURRENTPOWERSTATE,WORDS),
  3484. DEBUG_REC(CCAMODE,WORDS),
  3485. DEBUG_REC(SUPPORTEDDATARATES,WORDS),
  3486. DEBUG_REC(BUILDSEQ,BYTES),
  3487. DEBUG_REC(FWID,XSTRING)
  3488. #undef DEBUG_REC
  3489. };
  3490. #define DEBUG_LTV_SIZE 128
  3491. static int orinoco_debug_dump_recs(struct net_device *dev)
  3492. {
  3493. struct orinoco_private *priv = netdev_priv(dev);
  3494. hermes_t *hw = &priv->hw;
  3495. u8 *val8;
  3496. u16 *val16;
  3497. int i,j;
  3498. u16 length;
  3499. int err;
  3500. /* I'm not sure: we might have a lock here, so we'd better go
  3501. atomic, just in case. */
  3502. val8 = kmalloc(DEBUG_LTV_SIZE + 2, GFP_ATOMIC);
  3503. if (! val8)
  3504. return -ENOMEM;
  3505. val16 = (u16 *)val8;
  3506. for (i = 0; i < ARRAY_SIZE(record_table); i++) {
  3507. u16 rid = record_table[i].rid;
  3508. int len;
  3509. memset(val8, 0, DEBUG_LTV_SIZE + 2);
  3510. err = hermes_read_ltv(hw, USER_BAP, rid, DEBUG_LTV_SIZE,
  3511. &length, val8);
  3512. if (err) {
  3513. DEBUG(0, "Error %d reading RID 0x%04x\n", err, rid);
  3514. continue;
  3515. }
  3516. val16 = (u16 *)val8;
  3517. if (length == 0)
  3518. continue;
  3519. printk(KERN_DEBUG "%-15s (0x%04x): length=%d (%d bytes)\tvalue=",
  3520. record_table[i].name,
  3521. rid, length, (length-1)*2);
  3522. len = min(((int)length-1)*2, DEBUG_LTV_SIZE);
  3523. switch (record_table[i].displaytype) {
  3524. case DISPLAY_WORDS:
  3525. for (j = 0; j < len / 2; j++)
  3526. printk("%04X-", le16_to_cpu(val16[j]));
  3527. break;
  3528. case DISPLAY_BYTES:
  3529. default:
  3530. for (j = 0; j < len; j++)
  3531. printk("%02X:", val8[j]);
  3532. break;
  3533. case DISPLAY_STRING:
  3534. len = min(len, le16_to_cpu(val16[0])+2);
  3535. val8[len] = '\0';
  3536. printk("\"%s\"", (char *)&val16[1]);
  3537. break;
  3538. case DISPLAY_XSTRING:
  3539. printk("'%s'", (char *)val8);
  3540. }
  3541. printk("\n");
  3542. }
  3543. kfree(val8);
  3544. return 0;
  3545. }
  3546. /********************************************************************/
  3547. /* Debugging */
  3548. /********************************************************************/
  3549. #if 0
  3550. static void show_rx_frame(struct orinoco_rxframe_hdr *frame)
  3551. {
  3552. printk(KERN_DEBUG "RX descriptor:\n");
  3553. printk(KERN_DEBUG " status = 0x%04x\n", frame->desc.status);
  3554. printk(KERN_DEBUG " time = 0x%08x\n", frame->desc.time);
  3555. printk(KERN_DEBUG " silence = 0x%02x\n", frame->desc.silence);
  3556. printk(KERN_DEBUG " signal = 0x%02x\n", frame->desc.signal);
  3557. printk(KERN_DEBUG " rate = 0x%02x\n", frame->desc.rate);
  3558. printk(KERN_DEBUG " rxflow = 0x%02x\n", frame->desc.rxflow);
  3559. printk(KERN_DEBUG " reserved = 0x%08x\n", frame->desc.reserved);
  3560. printk(KERN_DEBUG "IEEE 802.11 header:\n");
  3561. printk(KERN_DEBUG " frame_ctl = 0x%04x\n",
  3562. frame->p80211.frame_ctl);
  3563. printk(KERN_DEBUG " duration_id = 0x%04x\n",
  3564. frame->p80211.duration_id);
  3565. printk(KERN_DEBUG " addr1 = %02x:%02x:%02x:%02x:%02x:%02x\n",
  3566. frame->p80211.addr1[0], frame->p80211.addr1[1],
  3567. frame->p80211.addr1[2], frame->p80211.addr1[3],
  3568. frame->p80211.addr1[4], frame->p80211.addr1[5]);
  3569. printk(KERN_DEBUG " addr2 = %02x:%02x:%02x:%02x:%02x:%02x\n",
  3570. frame->p80211.addr2[0], frame->p80211.addr2[1],
  3571. frame->p80211.addr2[2], frame->p80211.addr2[3],
  3572. frame->p80211.addr2[4], frame->p80211.addr2[5]);
  3573. printk(KERN_DEBUG " addr3 = %02x:%02x:%02x:%02x:%02x:%02x\n",
  3574. frame->p80211.addr3[0], frame->p80211.addr3[1],
  3575. frame->p80211.addr3[2], frame->p80211.addr3[3],
  3576. frame->p80211.addr3[4], frame->p80211.addr3[5]);
  3577. printk(KERN_DEBUG " seq_ctl = 0x%04x\n",
  3578. frame->p80211.seq_ctl);
  3579. printk(KERN_DEBUG " addr4 = %02x:%02x:%02x:%02x:%02x:%02x\n",
  3580. frame->p80211.addr4[0], frame->p80211.addr4[1],
  3581. frame->p80211.addr4[2], frame->p80211.addr4[3],
  3582. frame->p80211.addr4[4], frame->p80211.addr4[5]);
  3583. printk(KERN_DEBUG " data_len = 0x%04x\n",
  3584. frame->p80211.data_len);
  3585. printk(KERN_DEBUG "IEEE 802.3 header:\n");
  3586. printk(KERN_DEBUG " dest = %02x:%02x:%02x:%02x:%02x:%02x\n",
  3587. frame->p8023.h_dest[0], frame->p8023.h_dest[1],
  3588. frame->p8023.h_dest[2], frame->p8023.h_dest[3],
  3589. frame->p8023.h_dest[4], frame->p8023.h_dest[5]);
  3590. printk(KERN_DEBUG " src = %02x:%02x:%02x:%02x:%02x:%02x\n",
  3591. frame->p8023.h_source[0], frame->p8023.h_source[1],
  3592. frame->p8023.h_source[2], frame->p8023.h_source[3],
  3593. frame->p8023.h_source[4], frame->p8023.h_source[5]);
  3594. printk(KERN_DEBUG " len = 0x%04x\n", frame->p8023.h_proto);
  3595. printk(KERN_DEBUG "IEEE 802.2 LLC/SNAP header:\n");
  3596. printk(KERN_DEBUG " DSAP = 0x%02x\n", frame->p8022.dsap);
  3597. printk(KERN_DEBUG " SSAP = 0x%02x\n", frame->p8022.ssap);
  3598. printk(KERN_DEBUG " ctrl = 0x%02x\n", frame->p8022.ctrl);
  3599. printk(KERN_DEBUG " OUI = %02x:%02x:%02x\n",
  3600. frame->p8022.oui[0], frame->p8022.oui[1], frame->p8022.oui[2]);
  3601. printk(KERN_DEBUG " ethertype = 0x%04x\n", frame->ethertype);
  3602. }
  3603. #endif /* 0 */
  3604. /********************************************************************/
  3605. /* Module initialization */
  3606. /********************************************************************/
  3607. EXPORT_SYMBOL(alloc_orinocodev);
  3608. EXPORT_SYMBOL(free_orinocodev);
  3609. EXPORT_SYMBOL(__orinoco_up);
  3610. EXPORT_SYMBOL(__orinoco_down);
  3611. EXPORT_SYMBOL(orinoco_stop);
  3612. EXPORT_SYMBOL(orinoco_reinit_firmware);
  3613. EXPORT_SYMBOL(orinoco_interrupt);
  3614. /* Can't be declared "const" or the whole __initdata section will
  3615. * become const */
  3616. static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION
  3617. " (David Gibson <hermes@gibson.dropbear.id.au>, "
  3618. "Pavel Roskin <proski@gnu.org>, et al)";
  3619. static int __init init_orinoco(void)
  3620. {
  3621. printk(KERN_DEBUG "%s\n", version);
  3622. return 0;
  3623. }
  3624. static void __exit exit_orinoco(void)
  3625. {
  3626. }
  3627. module_init(init_orinoco);
  3628. module_exit(exit_orinoco);