orinoco.c 117 KB

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