orinoco.c 118 KB

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