orinoco.c 115 KB

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