orinoco.c 114 KB

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