orinoco.c 114 KB

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