orinoco.c 120 KB

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