orinoco.c 118 KB

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