orinoco.c 115 KB

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