rndis_wlan.c 94 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523
  1. /*
  2. * Driver for RNDIS based wireless USB devices.
  3. *
  4. * Copyright (C) 2007 by Bjorge Dijkstra <bjd@jooz.net>
  5. * Copyright (C) 2008-2009 by Jussi Kivilinna <jussi.kivilinna@mbnet.fi>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. *
  21. * Portions of this file are based on NDISwrapper project,
  22. * Copyright (C) 2003-2005 Pontus Fuchs, Giridhar Pemmasani
  23. * http://ndiswrapper.sourceforge.net/
  24. */
  25. // #define DEBUG // error path messages, extra info
  26. // #define VERBOSE // more; success messages
  27. #include <linux/module.h>
  28. #include <linux/init.h>
  29. #include <linux/netdevice.h>
  30. #include <linux/etherdevice.h>
  31. #include <linux/ethtool.h>
  32. #include <linux/workqueue.h>
  33. #include <linux/mutex.h>
  34. #include <linux/mii.h>
  35. #include <linux/usb.h>
  36. #include <linux/usb/cdc.h>
  37. #include <linux/wireless.h>
  38. #include <linux/ieee80211.h>
  39. #include <linux/if_arp.h>
  40. #include <linux/ctype.h>
  41. #include <linux/spinlock.h>
  42. #include <net/iw_handler.h>
  43. #include <net/cfg80211.h>
  44. #include <linux/usb/usbnet.h>
  45. #include <linux/usb/rndis_host.h>
  46. /* NOTE: All these are settings for Broadcom chipset */
  47. static char modparam_country[4] = "EU";
  48. module_param_string(country, modparam_country, 4, 0444);
  49. MODULE_PARM_DESC(country, "Country code (ISO 3166-1 alpha-2), default: EU");
  50. static int modparam_frameburst = 1;
  51. module_param_named(frameburst, modparam_frameburst, int, 0444);
  52. MODULE_PARM_DESC(frameburst, "enable frame bursting (default: on)");
  53. static int modparam_afterburner = 0;
  54. module_param_named(afterburner, modparam_afterburner, int, 0444);
  55. MODULE_PARM_DESC(afterburner,
  56. "enable afterburner aka '125 High Speed Mode' (default: off)");
  57. static int modparam_power_save = 0;
  58. module_param_named(power_save, modparam_power_save, int, 0444);
  59. MODULE_PARM_DESC(power_save,
  60. "set power save mode: 0=off, 1=on, 2=fast (default: off)");
  61. static int modparam_power_output = 3;
  62. module_param_named(power_output, modparam_power_output, int, 0444);
  63. MODULE_PARM_DESC(power_output,
  64. "set power output: 0=25%, 1=50%, 2=75%, 3=100% (default: 100%)");
  65. static int modparam_roamtrigger = -70;
  66. module_param_named(roamtrigger, modparam_roamtrigger, int, 0444);
  67. MODULE_PARM_DESC(roamtrigger,
  68. "set roaming dBm trigger: -80=optimize for distance, "
  69. "-60=bandwidth (default: -70)");
  70. static int modparam_roamdelta = 1;
  71. module_param_named(roamdelta, modparam_roamdelta, int, 0444);
  72. MODULE_PARM_DESC(roamdelta,
  73. "set roaming tendency: 0=aggressive, 1=moderate, "
  74. "2=conservative (default: moderate)");
  75. static int modparam_workaround_interval = 500;
  76. module_param_named(workaround_interval, modparam_workaround_interval,
  77. int, 0444);
  78. MODULE_PARM_DESC(workaround_interval,
  79. "set stall workaround interval in msecs (default: 500)");
  80. /* various RNDIS OID defs */
  81. #define OID_GEN_LINK_SPEED cpu_to_le32(0x00010107)
  82. #define OID_GEN_RNDIS_CONFIG_PARAMETER cpu_to_le32(0x0001021b)
  83. #define OID_GEN_XMIT_OK cpu_to_le32(0x00020101)
  84. #define OID_GEN_RCV_OK cpu_to_le32(0x00020102)
  85. #define OID_GEN_XMIT_ERROR cpu_to_le32(0x00020103)
  86. #define OID_GEN_RCV_ERROR cpu_to_le32(0x00020104)
  87. #define OID_GEN_RCV_NO_BUFFER cpu_to_le32(0x00020105)
  88. #define OID_802_3_CURRENT_ADDRESS cpu_to_le32(0x01010102)
  89. #define OID_802_3_MULTICAST_LIST cpu_to_le32(0x01010103)
  90. #define OID_802_3_MAXIMUM_LIST_SIZE cpu_to_le32(0x01010104)
  91. #define OID_802_11_BSSID cpu_to_le32(0x0d010101)
  92. #define OID_802_11_SSID cpu_to_le32(0x0d010102)
  93. #define OID_802_11_INFRASTRUCTURE_MODE cpu_to_le32(0x0d010108)
  94. #define OID_802_11_ADD_WEP cpu_to_le32(0x0d010113)
  95. #define OID_802_11_REMOVE_WEP cpu_to_le32(0x0d010114)
  96. #define OID_802_11_DISASSOCIATE cpu_to_le32(0x0d010115)
  97. #define OID_802_11_AUTHENTICATION_MODE cpu_to_le32(0x0d010118)
  98. #define OID_802_11_PRIVACY_FILTER cpu_to_le32(0x0d010119)
  99. #define OID_802_11_BSSID_LIST_SCAN cpu_to_le32(0x0d01011a)
  100. #define OID_802_11_ENCRYPTION_STATUS cpu_to_le32(0x0d01011b)
  101. #define OID_802_11_ADD_KEY cpu_to_le32(0x0d01011d)
  102. #define OID_802_11_REMOVE_KEY cpu_to_le32(0x0d01011e)
  103. #define OID_802_11_ASSOCIATION_INFORMATION cpu_to_le32(0x0d01011f)
  104. #define OID_802_11_PMKID cpu_to_le32(0x0d010123)
  105. #define OID_802_11_NETWORK_TYPES_SUPPORTED cpu_to_le32(0x0d010203)
  106. #define OID_802_11_NETWORK_TYPE_IN_USE cpu_to_le32(0x0d010204)
  107. #define OID_802_11_TX_POWER_LEVEL cpu_to_le32(0x0d010205)
  108. #define OID_802_11_RSSI cpu_to_le32(0x0d010206)
  109. #define OID_802_11_RSSI_TRIGGER cpu_to_le32(0x0d010207)
  110. #define OID_802_11_FRAGMENTATION_THRESHOLD cpu_to_le32(0x0d010209)
  111. #define OID_802_11_RTS_THRESHOLD cpu_to_le32(0x0d01020a)
  112. #define OID_802_11_SUPPORTED_RATES cpu_to_le32(0x0d01020e)
  113. #define OID_802_11_CONFIGURATION cpu_to_le32(0x0d010211)
  114. #define OID_802_11_BSSID_LIST cpu_to_le32(0x0d010217)
  115. /* Typical noise/maximum signal level values taken from ndiswrapper iw_ndis.h */
  116. #define WL_NOISE -96 /* typical noise level in dBm */
  117. #define WL_SIGMAX -32 /* typical maximum signal level in dBm */
  118. /* Assume that Broadcom 4320 (only chipset at time of writing known to be
  119. * based on wireless rndis) has default txpower of 13dBm.
  120. * This value is from Linksys WUSB54GSC User Guide, Appendix F: Specifications.
  121. * 100% : 20 mW ~ 13dBm
  122. * 75% : 15 mW ~ 12dBm
  123. * 50% : 10 mW ~ 10dBm
  124. * 25% : 5 mW ~ 7dBm
  125. */
  126. #define BCM4320_DEFAULT_TXPOWER_DBM_100 13
  127. #define BCM4320_DEFAULT_TXPOWER_DBM_75 12
  128. #define BCM4320_DEFAULT_TXPOWER_DBM_50 10
  129. #define BCM4320_DEFAULT_TXPOWER_DBM_25 7
  130. /* codes for "status" field of completion messages */
  131. #define RNDIS_STATUS_ADAPTER_NOT_READY cpu_to_le32(0xc0010011)
  132. #define RNDIS_STATUS_ADAPTER_NOT_OPEN cpu_to_le32(0xc0010012)
  133. /* NDIS data structures. Taken from wpa_supplicant driver_ndis.c
  134. * slightly modified for datatype endianess, etc
  135. */
  136. #define NDIS_802_11_LENGTH_SSID 32
  137. #define NDIS_802_11_LENGTH_RATES 8
  138. #define NDIS_802_11_LENGTH_RATES_EX 16
  139. enum ndis_80211_net_type {
  140. NDIS_80211_TYPE_FREQ_HOP,
  141. NDIS_80211_TYPE_DIRECT_SEQ,
  142. NDIS_80211_TYPE_OFDM_A,
  143. NDIS_80211_TYPE_OFDM_G
  144. };
  145. enum ndis_80211_net_infra {
  146. NDIS_80211_INFRA_ADHOC,
  147. NDIS_80211_INFRA_INFRA,
  148. NDIS_80211_INFRA_AUTO_UNKNOWN
  149. };
  150. enum ndis_80211_auth_mode {
  151. NDIS_80211_AUTH_OPEN,
  152. NDIS_80211_AUTH_SHARED,
  153. NDIS_80211_AUTH_AUTO_SWITCH,
  154. NDIS_80211_AUTH_WPA,
  155. NDIS_80211_AUTH_WPA_PSK,
  156. NDIS_80211_AUTH_WPA_NONE,
  157. NDIS_80211_AUTH_WPA2,
  158. NDIS_80211_AUTH_WPA2_PSK
  159. };
  160. enum ndis_80211_encr_status {
  161. NDIS_80211_ENCR_WEP_ENABLED,
  162. NDIS_80211_ENCR_DISABLED,
  163. NDIS_80211_ENCR_WEP_KEY_ABSENT,
  164. NDIS_80211_ENCR_NOT_SUPPORTED,
  165. NDIS_80211_ENCR_TKIP_ENABLED,
  166. NDIS_80211_ENCR_TKIP_KEY_ABSENT,
  167. NDIS_80211_ENCR_CCMP_ENABLED,
  168. NDIS_80211_ENCR_CCMP_KEY_ABSENT
  169. };
  170. enum ndis_80211_priv_filter {
  171. NDIS_80211_PRIV_ACCEPT_ALL,
  172. NDIS_80211_PRIV_8021X_WEP
  173. };
  174. enum ndis_80211_status_type {
  175. NDIS_80211_STATUSTYPE_AUTHENTICATION,
  176. NDIS_80211_STATUSTYPE_MEDIASTREAMMODE,
  177. NDIS_80211_STATUSTYPE_PMKID_CANDIDATELIST,
  178. NDIS_80211_STATUSTYPE_RADIOSTATE,
  179. };
  180. enum ndis_80211_media_stream_mode {
  181. NDIS_80211_MEDIA_STREAM_OFF,
  182. NDIS_80211_MEDIA_STREAM_ON
  183. };
  184. enum ndis_80211_radio_status {
  185. NDIS_80211_RADIO_STATUS_ON,
  186. NDIS_80211_RADIO_STATUS_HARDWARE_OFF,
  187. NDIS_80211_RADIO_STATUS_SOFTWARE_OFF,
  188. };
  189. enum ndis_80211_addkey_bits {
  190. NDIS_80211_ADDKEY_8021X_AUTH = cpu_to_le32(1 << 28),
  191. NDIS_80211_ADDKEY_SET_INIT_RECV_SEQ = cpu_to_le32(1 << 29),
  192. NDIS_80211_ADDKEY_PAIRWISE_KEY = cpu_to_le32(1 << 30),
  193. NDIS_80211_ADDKEY_TRANSMIT_KEY = cpu_to_le32(1 << 31)
  194. };
  195. enum ndis_80211_addwep_bits {
  196. NDIS_80211_ADDWEP_PERCLIENT_KEY = cpu_to_le32(1 << 30),
  197. NDIS_80211_ADDWEP_TRANSMIT_KEY = cpu_to_le32(1 << 31)
  198. };
  199. struct ndis_80211_auth_request {
  200. __le32 length;
  201. u8 bssid[6];
  202. u8 padding[2];
  203. __le32 flags;
  204. } __attribute__((packed));
  205. struct ndis_80211_pmkid_candidate {
  206. u8 bssid[6];
  207. u8 padding[2];
  208. __le32 flags;
  209. } __attribute__((packed));
  210. struct ndis_80211_pmkid_cand_list {
  211. __le32 version;
  212. __le32 num_candidates;
  213. struct ndis_80211_pmkid_candidate candidate_list[0];
  214. } __attribute__((packed));
  215. struct ndis_80211_status_indication {
  216. __le32 status_type;
  217. union {
  218. enum ndis_80211_media_stream_mode media_stream_mode;
  219. enum ndis_80211_radio_status radio_status;
  220. struct ndis_80211_auth_request auth_request[0];
  221. struct ndis_80211_pmkid_cand_list cand_list;
  222. } u;
  223. } __attribute__((packed));
  224. struct ndis_80211_ssid {
  225. __le32 length;
  226. u8 essid[NDIS_802_11_LENGTH_SSID];
  227. } __attribute__((packed));
  228. struct ndis_80211_conf_freq_hop {
  229. __le32 length;
  230. __le32 hop_pattern;
  231. __le32 hop_set;
  232. __le32 dwell_time;
  233. } __attribute__((packed));
  234. struct ndis_80211_conf {
  235. __le32 length;
  236. __le32 beacon_period;
  237. __le32 atim_window;
  238. __le32 ds_config;
  239. struct ndis_80211_conf_freq_hop fh_config;
  240. } __attribute__((packed));
  241. struct ndis_80211_bssid_ex {
  242. __le32 length;
  243. u8 mac[6];
  244. u8 padding[2];
  245. struct ndis_80211_ssid ssid;
  246. __le32 privacy;
  247. __le32 rssi;
  248. __le32 net_type;
  249. struct ndis_80211_conf config;
  250. __le32 net_infra;
  251. u8 rates[NDIS_802_11_LENGTH_RATES_EX];
  252. __le32 ie_length;
  253. u8 ies[0];
  254. } __attribute__((packed));
  255. struct ndis_80211_bssid_list_ex {
  256. __le32 num_items;
  257. struct ndis_80211_bssid_ex bssid[0];
  258. } __attribute__((packed));
  259. struct ndis_80211_fixed_ies {
  260. u8 timestamp[8];
  261. __le16 beacon_interval;
  262. __le16 capabilities;
  263. } __attribute__((packed));
  264. struct ndis_80211_wep_key {
  265. __le32 size;
  266. __le32 index;
  267. __le32 length;
  268. u8 material[32];
  269. } __attribute__((packed));
  270. struct ndis_80211_key {
  271. __le32 size;
  272. __le32 index;
  273. __le32 length;
  274. u8 bssid[6];
  275. u8 padding[6];
  276. u8 rsc[8];
  277. u8 material[32];
  278. } __attribute__((packed));
  279. struct ndis_80211_remove_key {
  280. __le32 size;
  281. __le32 index;
  282. u8 bssid[6];
  283. u8 padding[2];
  284. } __attribute__((packed));
  285. struct ndis_config_param {
  286. __le32 name_offs;
  287. __le32 name_length;
  288. __le32 type;
  289. __le32 value_offs;
  290. __le32 value_length;
  291. } __attribute__((packed));
  292. struct ndis_80211_assoc_info {
  293. __le32 length;
  294. __le16 req_ies;
  295. struct req_ie {
  296. __le16 capa;
  297. __le16 listen_interval;
  298. u8 cur_ap_address[6];
  299. } req_ie;
  300. __le32 req_ie_length;
  301. __le32 offset_req_ies;
  302. __le16 resp_ies;
  303. struct resp_ie {
  304. __le16 capa;
  305. __le16 status_code;
  306. __le16 assoc_id;
  307. } resp_ie;
  308. __le32 resp_ie_length;
  309. __le32 offset_resp_ies;
  310. } __attribute__((packed));
  311. /*
  312. * private data
  313. */
  314. #define NET_TYPE_11FB 0
  315. #define CAP_MODE_80211A 1
  316. #define CAP_MODE_80211B 2
  317. #define CAP_MODE_80211G 4
  318. #define CAP_MODE_MASK 7
  319. #define WORK_LINK_UP (1<<0)
  320. #define WORK_LINK_DOWN (1<<1)
  321. #define WORK_SET_MULTICAST_LIST (1<<2)
  322. #define RNDIS_WLAN_ALG_NONE 0
  323. #define RNDIS_WLAN_ALG_WEP (1<<0)
  324. #define RNDIS_WLAN_ALG_TKIP (1<<1)
  325. #define RNDIS_WLAN_ALG_CCMP (1<<2)
  326. #define RNDIS_WLAN_KEY_MGMT_NONE 0
  327. #define RNDIS_WLAN_KEY_MGMT_802_1X (1<<0)
  328. #define RNDIS_WLAN_KEY_MGMT_PSK (1<<1)
  329. #define COMMAND_BUFFER_SIZE (CONTROL_BUFFER_SIZE + sizeof(struct rndis_set))
  330. static const struct ieee80211_channel rndis_channels[] = {
  331. { .center_freq = 2412 },
  332. { .center_freq = 2417 },
  333. { .center_freq = 2422 },
  334. { .center_freq = 2427 },
  335. { .center_freq = 2432 },
  336. { .center_freq = 2437 },
  337. { .center_freq = 2442 },
  338. { .center_freq = 2447 },
  339. { .center_freq = 2452 },
  340. { .center_freq = 2457 },
  341. { .center_freq = 2462 },
  342. { .center_freq = 2467 },
  343. { .center_freq = 2472 },
  344. { .center_freq = 2484 },
  345. };
  346. static const struct ieee80211_rate rndis_rates[] = {
  347. { .bitrate = 10 },
  348. { .bitrate = 20, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
  349. { .bitrate = 55, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
  350. { .bitrate = 110, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
  351. { .bitrate = 60 },
  352. { .bitrate = 90 },
  353. { .bitrate = 120 },
  354. { .bitrate = 180 },
  355. { .bitrate = 240 },
  356. { .bitrate = 360 },
  357. { .bitrate = 480 },
  358. { .bitrate = 540 }
  359. };
  360. static const u32 rndis_cipher_suites[] = {
  361. WLAN_CIPHER_SUITE_WEP40,
  362. WLAN_CIPHER_SUITE_WEP104,
  363. WLAN_CIPHER_SUITE_TKIP,
  364. WLAN_CIPHER_SUITE_CCMP,
  365. };
  366. struct rndis_wlan_encr_key {
  367. int len;
  368. u32 cipher;
  369. u8 material[32];
  370. u8 bssid[ETH_ALEN];
  371. bool pairwise;
  372. bool tx_key;
  373. };
  374. /* RNDIS device private data */
  375. struct rndis_wlan_private {
  376. struct usbnet *usbdev;
  377. struct wireless_dev wdev;
  378. struct cfg80211_scan_request *scan_request;
  379. struct workqueue_struct *workqueue;
  380. struct delayed_work dev_poller_work;
  381. struct delayed_work scan_work;
  382. struct work_struct work;
  383. struct mutex command_lock;
  384. unsigned long work_pending;
  385. int last_qual;
  386. struct ieee80211_supported_band band;
  387. struct ieee80211_channel channels[ARRAY_SIZE(rndis_channels)];
  388. struct ieee80211_rate rates[ARRAY_SIZE(rndis_rates)];
  389. u32 cipher_suites[ARRAY_SIZE(rndis_cipher_suites)];
  390. int caps;
  391. int multicast_size;
  392. /* module parameters */
  393. char param_country[4];
  394. int param_frameburst;
  395. int param_afterburner;
  396. int param_power_save;
  397. int param_power_output;
  398. int param_roamtrigger;
  399. int param_roamdelta;
  400. u32 param_workaround_interval;
  401. /* hardware state */
  402. int radio_on;
  403. int infra_mode;
  404. bool connected;
  405. u8 bssid[ETH_ALEN];
  406. struct ndis_80211_ssid essid;
  407. __le32 current_command_oid;
  408. /* encryption stuff */
  409. int encr_tx_key_index;
  410. struct rndis_wlan_encr_key encr_keys[4];
  411. enum nl80211_auth_type wpa_auth_type;
  412. int wpa_version;
  413. int wpa_keymgmt;
  414. int wpa_ie_len;
  415. u8 *wpa_ie;
  416. int wpa_cipher_pair;
  417. int wpa_cipher_group;
  418. u8 command_buffer[COMMAND_BUFFER_SIZE];
  419. };
  420. /*
  421. * cfg80211 ops
  422. */
  423. static int rndis_change_virtual_intf(struct wiphy *wiphy,
  424. struct net_device *dev,
  425. enum nl80211_iftype type, u32 *flags,
  426. struct vif_params *params);
  427. static int rndis_scan(struct wiphy *wiphy, struct net_device *dev,
  428. struct cfg80211_scan_request *request);
  429. static int rndis_set_wiphy_params(struct wiphy *wiphy, u32 changed);
  430. static int rndis_set_tx_power(struct wiphy *wiphy, enum tx_power_setting type,
  431. int dbm);
  432. static int rndis_get_tx_power(struct wiphy *wiphy, int *dbm);
  433. static int rndis_connect(struct wiphy *wiphy, struct net_device *dev,
  434. struct cfg80211_connect_params *sme);
  435. static int rndis_disconnect(struct wiphy *wiphy, struct net_device *dev,
  436. u16 reason_code);
  437. static int rndis_join_ibss(struct wiphy *wiphy, struct net_device *dev,
  438. struct cfg80211_ibss_params *params);
  439. static int rndis_leave_ibss(struct wiphy *wiphy, struct net_device *dev);
  440. static int rndis_set_channel(struct wiphy *wiphy,
  441. struct ieee80211_channel *chan, enum nl80211_channel_type channel_type);
  442. static int rndis_add_key(struct wiphy *wiphy, struct net_device *netdev,
  443. u8 key_index, const u8 *mac_addr,
  444. struct key_params *params);
  445. static int rndis_del_key(struct wiphy *wiphy, struct net_device *netdev,
  446. u8 key_index, const u8 *mac_addr);
  447. static int rndis_set_default_key(struct wiphy *wiphy, struct net_device *netdev,
  448. u8 key_index);
  449. static int rndis_get_station(struct wiphy *wiphy, struct net_device *dev,
  450. u8 *mac, struct station_info *sinfo);
  451. static int rndis_dump_station(struct wiphy *wiphy, struct net_device *dev,
  452. int idx, u8 *mac, struct station_info *sinfo);
  453. static struct cfg80211_ops rndis_config_ops = {
  454. .change_virtual_intf = rndis_change_virtual_intf,
  455. .scan = rndis_scan,
  456. .set_wiphy_params = rndis_set_wiphy_params,
  457. .set_tx_power = rndis_set_tx_power,
  458. .get_tx_power = rndis_get_tx_power,
  459. .connect = rndis_connect,
  460. .disconnect = rndis_disconnect,
  461. .join_ibss = rndis_join_ibss,
  462. .leave_ibss = rndis_leave_ibss,
  463. .set_channel = rndis_set_channel,
  464. .add_key = rndis_add_key,
  465. .del_key = rndis_del_key,
  466. .set_default_key = rndis_set_default_key,
  467. .get_station = rndis_get_station,
  468. .dump_station = rndis_dump_station,
  469. };
  470. static void *rndis_wiphy_privid = &rndis_wiphy_privid;
  471. static struct rndis_wlan_private *get_rndis_wlan_priv(struct usbnet *dev)
  472. {
  473. return (struct rndis_wlan_private *)dev->driver_priv;
  474. }
  475. static u32 get_bcm4320_power_dbm(struct rndis_wlan_private *priv)
  476. {
  477. switch (priv->param_power_output) {
  478. default:
  479. case 3:
  480. return BCM4320_DEFAULT_TXPOWER_DBM_100;
  481. case 2:
  482. return BCM4320_DEFAULT_TXPOWER_DBM_75;
  483. case 1:
  484. return BCM4320_DEFAULT_TXPOWER_DBM_50;
  485. case 0:
  486. return BCM4320_DEFAULT_TXPOWER_DBM_25;
  487. }
  488. }
  489. static bool is_wpa_key(struct rndis_wlan_private *priv, int idx)
  490. {
  491. int cipher = priv->encr_keys[idx].cipher;
  492. return (cipher == WLAN_CIPHER_SUITE_CCMP ||
  493. cipher == WLAN_CIPHER_SUITE_TKIP);
  494. }
  495. static int rndis_cipher_to_alg(u32 cipher)
  496. {
  497. switch (cipher) {
  498. default:
  499. return RNDIS_WLAN_ALG_NONE;
  500. case WLAN_CIPHER_SUITE_WEP40:
  501. case WLAN_CIPHER_SUITE_WEP104:
  502. return RNDIS_WLAN_ALG_WEP;
  503. case WLAN_CIPHER_SUITE_TKIP:
  504. return RNDIS_WLAN_ALG_TKIP;
  505. case WLAN_CIPHER_SUITE_CCMP:
  506. return RNDIS_WLAN_ALG_CCMP;
  507. }
  508. }
  509. static int rndis_akm_suite_to_key_mgmt(u32 akm_suite)
  510. {
  511. switch (akm_suite) {
  512. default:
  513. return RNDIS_WLAN_KEY_MGMT_NONE;
  514. case WLAN_AKM_SUITE_8021X:
  515. return RNDIS_WLAN_KEY_MGMT_802_1X;
  516. case WLAN_AKM_SUITE_PSK:
  517. return RNDIS_WLAN_KEY_MGMT_PSK;
  518. }
  519. }
  520. #ifdef DEBUG
  521. static const char *oid_to_string(__le32 oid)
  522. {
  523. switch (oid) {
  524. #define OID_STR(oid) case oid: return(#oid)
  525. /* from rndis_host.h */
  526. OID_STR(OID_802_3_PERMANENT_ADDRESS);
  527. OID_STR(OID_GEN_MAXIMUM_FRAME_SIZE);
  528. OID_STR(OID_GEN_CURRENT_PACKET_FILTER);
  529. OID_STR(OID_GEN_PHYSICAL_MEDIUM);
  530. /* from rndis_wlan.c */
  531. OID_STR(OID_GEN_LINK_SPEED);
  532. OID_STR(OID_GEN_RNDIS_CONFIG_PARAMETER);
  533. OID_STR(OID_GEN_XMIT_OK);
  534. OID_STR(OID_GEN_RCV_OK);
  535. OID_STR(OID_GEN_XMIT_ERROR);
  536. OID_STR(OID_GEN_RCV_ERROR);
  537. OID_STR(OID_GEN_RCV_NO_BUFFER);
  538. OID_STR(OID_802_3_CURRENT_ADDRESS);
  539. OID_STR(OID_802_3_MULTICAST_LIST);
  540. OID_STR(OID_802_3_MAXIMUM_LIST_SIZE);
  541. OID_STR(OID_802_11_BSSID);
  542. OID_STR(OID_802_11_SSID);
  543. OID_STR(OID_802_11_INFRASTRUCTURE_MODE);
  544. OID_STR(OID_802_11_ADD_WEP);
  545. OID_STR(OID_802_11_REMOVE_WEP);
  546. OID_STR(OID_802_11_DISASSOCIATE);
  547. OID_STR(OID_802_11_AUTHENTICATION_MODE);
  548. OID_STR(OID_802_11_PRIVACY_FILTER);
  549. OID_STR(OID_802_11_BSSID_LIST_SCAN);
  550. OID_STR(OID_802_11_ENCRYPTION_STATUS);
  551. OID_STR(OID_802_11_ADD_KEY);
  552. OID_STR(OID_802_11_REMOVE_KEY);
  553. OID_STR(OID_802_11_ASSOCIATION_INFORMATION);
  554. OID_STR(OID_802_11_PMKID);
  555. OID_STR(OID_802_11_NETWORK_TYPES_SUPPORTED);
  556. OID_STR(OID_802_11_NETWORK_TYPE_IN_USE);
  557. OID_STR(OID_802_11_TX_POWER_LEVEL);
  558. OID_STR(OID_802_11_RSSI);
  559. OID_STR(OID_802_11_RSSI_TRIGGER);
  560. OID_STR(OID_802_11_FRAGMENTATION_THRESHOLD);
  561. OID_STR(OID_802_11_RTS_THRESHOLD);
  562. OID_STR(OID_802_11_SUPPORTED_RATES);
  563. OID_STR(OID_802_11_CONFIGURATION);
  564. OID_STR(OID_802_11_BSSID_LIST);
  565. #undef OID_STR
  566. }
  567. return "?";
  568. }
  569. #else
  570. static const char *oid_to_string(__le32 oid)
  571. {
  572. return "?";
  573. }
  574. #endif
  575. /* translate error code */
  576. static int rndis_error_status(__le32 rndis_status)
  577. {
  578. int ret = -EINVAL;
  579. switch (rndis_status) {
  580. case RNDIS_STATUS_SUCCESS:
  581. ret = 0;
  582. break;
  583. case RNDIS_STATUS_FAILURE:
  584. case RNDIS_STATUS_INVALID_DATA:
  585. ret = -EINVAL;
  586. break;
  587. case RNDIS_STATUS_NOT_SUPPORTED:
  588. ret = -EOPNOTSUPP;
  589. break;
  590. case RNDIS_STATUS_ADAPTER_NOT_READY:
  591. case RNDIS_STATUS_ADAPTER_NOT_OPEN:
  592. ret = -EBUSY;
  593. break;
  594. }
  595. return ret;
  596. }
  597. static int rndis_query_oid(struct usbnet *dev, __le32 oid, void *data, int *len)
  598. {
  599. struct rndis_wlan_private *priv = get_rndis_wlan_priv(dev);
  600. union {
  601. void *buf;
  602. struct rndis_msg_hdr *header;
  603. struct rndis_query *get;
  604. struct rndis_query_c *get_c;
  605. } u;
  606. int ret, buflen;
  607. buflen = *len + sizeof(*u.get);
  608. if (buflen < CONTROL_BUFFER_SIZE)
  609. buflen = CONTROL_BUFFER_SIZE;
  610. if (buflen > COMMAND_BUFFER_SIZE) {
  611. u.buf = kmalloc(buflen, GFP_KERNEL);
  612. if (!u.buf)
  613. return -ENOMEM;
  614. } else {
  615. u.buf = priv->command_buffer;
  616. }
  617. mutex_lock(&priv->command_lock);
  618. memset(u.get, 0, sizeof *u.get);
  619. u.get->msg_type = RNDIS_MSG_QUERY;
  620. u.get->msg_len = cpu_to_le32(sizeof *u.get);
  621. u.get->oid = oid;
  622. priv->current_command_oid = oid;
  623. ret = rndis_command(dev, u.header, buflen);
  624. priv->current_command_oid = 0;
  625. if (ret < 0)
  626. devdbg(dev, "rndis_query_oid(%s): rndis_command() failed, %d "
  627. "(%08x)", oid_to_string(oid), ret,
  628. le32_to_cpu(u.get_c->status));
  629. if (ret == 0) {
  630. ret = le32_to_cpu(u.get_c->len);
  631. if (ret > *len)
  632. *len = ret;
  633. memcpy(data, u.buf + le32_to_cpu(u.get_c->offset) + 8, *len);
  634. ret = rndis_error_status(u.get_c->status);
  635. if (ret < 0)
  636. devdbg(dev, "rndis_query_oid(%s): device returned "
  637. "error, 0x%08x (%d)", oid_to_string(oid),
  638. le32_to_cpu(u.get_c->status), ret);
  639. }
  640. mutex_unlock(&priv->command_lock);
  641. if (u.buf != priv->command_buffer)
  642. kfree(u.buf);
  643. return ret;
  644. }
  645. static int rndis_set_oid(struct usbnet *dev, __le32 oid, void *data, int len)
  646. {
  647. struct rndis_wlan_private *priv = get_rndis_wlan_priv(dev);
  648. union {
  649. void *buf;
  650. struct rndis_msg_hdr *header;
  651. struct rndis_set *set;
  652. struct rndis_set_c *set_c;
  653. } u;
  654. int ret, buflen;
  655. buflen = len + sizeof(*u.set);
  656. if (buflen < CONTROL_BUFFER_SIZE)
  657. buflen = CONTROL_BUFFER_SIZE;
  658. if (buflen > COMMAND_BUFFER_SIZE) {
  659. u.buf = kmalloc(buflen, GFP_KERNEL);
  660. if (!u.buf)
  661. return -ENOMEM;
  662. } else {
  663. u.buf = priv->command_buffer;
  664. }
  665. mutex_lock(&priv->command_lock);
  666. memset(u.set, 0, sizeof *u.set);
  667. u.set->msg_type = RNDIS_MSG_SET;
  668. u.set->msg_len = cpu_to_le32(sizeof(*u.set) + len);
  669. u.set->oid = oid;
  670. u.set->len = cpu_to_le32(len);
  671. u.set->offset = cpu_to_le32(sizeof(*u.set) - 8);
  672. u.set->handle = cpu_to_le32(0);
  673. memcpy(u.buf + sizeof(*u.set), data, len);
  674. priv->current_command_oid = oid;
  675. ret = rndis_command(dev, u.header, buflen);
  676. priv->current_command_oid = 0;
  677. if (ret < 0)
  678. devdbg(dev, "rndis_set_oid(%s): rndis_command() failed, %d "
  679. "(%08x)", oid_to_string(oid), ret,
  680. le32_to_cpu(u.set_c->status));
  681. if (ret == 0) {
  682. ret = rndis_error_status(u.set_c->status);
  683. if (ret < 0)
  684. devdbg(dev, "rndis_set_oid(%s): device returned error, "
  685. "0x%08x (%d)", oid_to_string(oid),
  686. le32_to_cpu(u.set_c->status), ret);
  687. }
  688. mutex_unlock(&priv->command_lock);
  689. if (u.buf != priv->command_buffer)
  690. kfree(u.buf);
  691. return ret;
  692. }
  693. static int rndis_reset(struct usbnet *usbdev)
  694. {
  695. struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
  696. struct rndis_reset *reset;
  697. int ret;
  698. mutex_lock(&priv->command_lock);
  699. reset = (void *)priv->command_buffer;
  700. memset(reset, 0, sizeof(*reset));
  701. reset->msg_type = RNDIS_MSG_RESET;
  702. reset->msg_len = cpu_to_le32(sizeof(*reset));
  703. priv->current_command_oid = 0;
  704. ret = rndis_command(usbdev, (void *)reset, CONTROL_BUFFER_SIZE);
  705. mutex_unlock(&priv->command_lock);
  706. if (ret < 0)
  707. return ret;
  708. return 0;
  709. }
  710. /*
  711. * Specs say that we can only set config parameters only soon after device
  712. * initialization.
  713. * value_type: 0 = u32, 2 = unicode string
  714. */
  715. static int rndis_set_config_parameter(struct usbnet *dev, char *param,
  716. int value_type, void *value)
  717. {
  718. struct ndis_config_param *infobuf;
  719. int value_len, info_len, param_len, ret, i;
  720. __le16 *unibuf;
  721. __le32 *dst_value;
  722. if (value_type == 0)
  723. value_len = sizeof(__le32);
  724. else if (value_type == 2)
  725. value_len = strlen(value) * sizeof(__le16);
  726. else
  727. return -EINVAL;
  728. param_len = strlen(param) * sizeof(__le16);
  729. info_len = sizeof(*infobuf) + param_len + value_len;
  730. #ifdef DEBUG
  731. info_len += 12;
  732. #endif
  733. infobuf = kmalloc(info_len, GFP_KERNEL);
  734. if (!infobuf)
  735. return -ENOMEM;
  736. #ifdef DEBUG
  737. info_len -= 12;
  738. /* extra 12 bytes are for padding (debug output) */
  739. memset(infobuf, 0xCC, info_len + 12);
  740. #endif
  741. if (value_type == 2)
  742. devdbg(dev, "setting config parameter: %s, value: %s",
  743. param, (u8 *)value);
  744. else
  745. devdbg(dev, "setting config parameter: %s, value: %d",
  746. param, *(u32 *)value);
  747. infobuf->name_offs = cpu_to_le32(sizeof(*infobuf));
  748. infobuf->name_length = cpu_to_le32(param_len);
  749. infobuf->type = cpu_to_le32(value_type);
  750. infobuf->value_offs = cpu_to_le32(sizeof(*infobuf) + param_len);
  751. infobuf->value_length = cpu_to_le32(value_len);
  752. /* simple string to unicode string conversion */
  753. unibuf = (void *)infobuf + sizeof(*infobuf);
  754. for (i = 0; i < param_len / sizeof(__le16); i++)
  755. unibuf[i] = cpu_to_le16(param[i]);
  756. if (value_type == 2) {
  757. unibuf = (void *)infobuf + sizeof(*infobuf) + param_len;
  758. for (i = 0; i < value_len / sizeof(__le16); i++)
  759. unibuf[i] = cpu_to_le16(((u8 *)value)[i]);
  760. } else {
  761. dst_value = (void *)infobuf + sizeof(*infobuf) + param_len;
  762. *dst_value = cpu_to_le32(*(u32 *)value);
  763. }
  764. #ifdef DEBUG
  765. devdbg(dev, "info buffer (len: %d):", info_len);
  766. for (i = 0; i < info_len; i += 12) {
  767. u32 *tmp = (u32 *)((u8 *)infobuf + i);
  768. devdbg(dev, "%08X:%08X:%08X",
  769. cpu_to_be32(tmp[0]),
  770. cpu_to_be32(tmp[1]),
  771. cpu_to_be32(tmp[2]));
  772. }
  773. #endif
  774. ret = rndis_set_oid(dev, OID_GEN_RNDIS_CONFIG_PARAMETER,
  775. infobuf, info_len);
  776. if (ret != 0)
  777. devdbg(dev, "setting rndis config parameter failed, %d.", ret);
  778. kfree(infobuf);
  779. return ret;
  780. }
  781. static int rndis_set_config_parameter_str(struct usbnet *dev,
  782. char *param, char *value)
  783. {
  784. return(rndis_set_config_parameter(dev, param, 2, value));
  785. }
  786. /*static int rndis_set_config_parameter_u32(struct usbnet *dev,
  787. char *param, u32 value)
  788. {
  789. return(rndis_set_config_parameter(dev, param, 0, &value));
  790. }*/
  791. /*
  792. * data conversion functions
  793. */
  794. static int level_to_qual(int level)
  795. {
  796. int qual = 100 * (level - WL_NOISE) / (WL_SIGMAX - WL_NOISE);
  797. return qual >= 0 ? (qual <= 100 ? qual : 100) : 0;
  798. }
  799. /*
  800. * common functions
  801. */
  802. static int set_infra_mode(struct usbnet *usbdev, int mode);
  803. static void restore_keys(struct usbnet *usbdev);
  804. static int rndis_check_bssid_list(struct usbnet *usbdev);
  805. static int set_essid(struct usbnet *usbdev, struct ndis_80211_ssid *ssid)
  806. {
  807. struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
  808. int ret;
  809. ret = rndis_set_oid(usbdev, OID_802_11_SSID, ssid, sizeof(*ssid));
  810. if (ret < 0) {
  811. devwarn(usbdev, "setting SSID failed (%08X)", ret);
  812. return ret;
  813. }
  814. if (ret == 0) {
  815. memcpy(&priv->essid, ssid, sizeof(priv->essid));
  816. priv->radio_on = 1;
  817. devdbg(usbdev, "set_essid: radio_on = 1");
  818. }
  819. return ret;
  820. }
  821. static int set_bssid(struct usbnet *usbdev, u8 bssid[ETH_ALEN])
  822. {
  823. int ret;
  824. ret = rndis_set_oid(usbdev, OID_802_11_BSSID, bssid, ETH_ALEN);
  825. if (ret < 0) {
  826. devwarn(usbdev, "setting BSSID[%pM] failed (%08X)", bssid, ret);
  827. return ret;
  828. }
  829. return ret;
  830. }
  831. static int clear_bssid(struct usbnet *usbdev)
  832. {
  833. u8 broadcast_mac[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
  834. return set_bssid(usbdev, broadcast_mac);
  835. }
  836. static int get_bssid(struct usbnet *usbdev, u8 bssid[ETH_ALEN])
  837. {
  838. int ret, len;
  839. len = ETH_ALEN;
  840. ret = rndis_query_oid(usbdev, OID_802_11_BSSID, bssid, &len);
  841. if (ret != 0)
  842. memset(bssid, 0, ETH_ALEN);
  843. return ret;
  844. }
  845. static int get_association_info(struct usbnet *usbdev,
  846. struct ndis_80211_assoc_info *info, int len)
  847. {
  848. return rndis_query_oid(usbdev, OID_802_11_ASSOCIATION_INFORMATION,
  849. info, &len);
  850. }
  851. static bool is_associated(struct usbnet *usbdev)
  852. {
  853. struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
  854. u8 bssid[ETH_ALEN];
  855. int ret;
  856. if (!priv->radio_on)
  857. return false;
  858. ret = get_bssid(usbdev, bssid);
  859. return (ret == 0 && !is_zero_ether_addr(bssid));
  860. }
  861. static int disassociate(struct usbnet *usbdev, int reset_ssid)
  862. {
  863. struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
  864. struct ndis_80211_ssid ssid;
  865. int i, ret = 0;
  866. if (priv->radio_on) {
  867. ret = rndis_set_oid(usbdev, OID_802_11_DISASSOCIATE, NULL, 0);
  868. if (ret == 0) {
  869. priv->radio_on = 0;
  870. devdbg(usbdev, "disassociate: radio_on = 0");
  871. if (reset_ssid)
  872. msleep(100);
  873. }
  874. }
  875. /* disassociate causes radio to be turned off; if reset_ssid
  876. * is given, set random ssid to enable radio */
  877. if (reset_ssid) {
  878. /* Set device to infrastructure mode so we don't get ad-hoc
  879. * 'media connect' indications with the random ssid.
  880. */
  881. set_infra_mode(usbdev, NDIS_80211_INFRA_INFRA);
  882. ssid.length = cpu_to_le32(sizeof(ssid.essid));
  883. get_random_bytes(&ssid.essid[2], sizeof(ssid.essid)-2);
  884. ssid.essid[0] = 0x1;
  885. ssid.essid[1] = 0xff;
  886. for (i = 2; i < sizeof(ssid.essid); i++)
  887. ssid.essid[i] = 0x1 + (ssid.essid[i] * 0xfe / 0xff);
  888. ret = set_essid(usbdev, &ssid);
  889. }
  890. return ret;
  891. }
  892. static int set_auth_mode(struct usbnet *usbdev, u32 wpa_version,
  893. enum nl80211_auth_type auth_type, int keymgmt)
  894. {
  895. struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
  896. __le32 tmp;
  897. int auth_mode, ret;
  898. devdbg(usbdev, "set_auth_mode: wpa_version=0x%x authalg=0x%x "
  899. "keymgmt=0x%x", wpa_version, auth_type, keymgmt);
  900. if (wpa_version & NL80211_WPA_VERSION_2) {
  901. if (keymgmt & RNDIS_WLAN_KEY_MGMT_802_1X)
  902. auth_mode = NDIS_80211_AUTH_WPA2;
  903. else
  904. auth_mode = NDIS_80211_AUTH_WPA2_PSK;
  905. } else if (wpa_version & NL80211_WPA_VERSION_1) {
  906. if (keymgmt & RNDIS_WLAN_KEY_MGMT_802_1X)
  907. auth_mode = NDIS_80211_AUTH_WPA;
  908. else if (keymgmt & RNDIS_WLAN_KEY_MGMT_PSK)
  909. auth_mode = NDIS_80211_AUTH_WPA_PSK;
  910. else
  911. auth_mode = NDIS_80211_AUTH_WPA_NONE;
  912. } else if (auth_type == NL80211_AUTHTYPE_SHARED_KEY)
  913. auth_mode = NDIS_80211_AUTH_SHARED;
  914. else if (auth_type == NL80211_AUTHTYPE_OPEN_SYSTEM)
  915. auth_mode = NDIS_80211_AUTH_OPEN;
  916. else
  917. return -ENOTSUPP;
  918. tmp = cpu_to_le32(auth_mode);
  919. ret = rndis_set_oid(usbdev, OID_802_11_AUTHENTICATION_MODE, &tmp,
  920. sizeof(tmp));
  921. if (ret != 0) {
  922. devwarn(usbdev, "setting auth mode failed (%08X)", ret);
  923. return ret;
  924. }
  925. priv->wpa_version = wpa_version;
  926. priv->wpa_auth_type = auth_type;
  927. priv->wpa_keymgmt = keymgmt;
  928. return 0;
  929. }
  930. static int set_priv_filter(struct usbnet *usbdev)
  931. {
  932. struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
  933. __le32 tmp;
  934. devdbg(usbdev, "set_priv_filter: wpa_version=0x%x", priv->wpa_version);
  935. if (priv->wpa_version & NL80211_WPA_VERSION_2 ||
  936. priv->wpa_version & NL80211_WPA_VERSION_1)
  937. tmp = cpu_to_le32(NDIS_80211_PRIV_8021X_WEP);
  938. else
  939. tmp = cpu_to_le32(NDIS_80211_PRIV_ACCEPT_ALL);
  940. return rndis_set_oid(usbdev, OID_802_11_PRIVACY_FILTER, &tmp,
  941. sizeof(tmp));
  942. }
  943. static int set_encr_mode(struct usbnet *usbdev, int pairwise, int groupwise)
  944. {
  945. struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
  946. __le32 tmp;
  947. int encr_mode, ret;
  948. devdbg(usbdev, "set_encr_mode: cipher_pair=0x%x cipher_group=0x%x",
  949. pairwise, groupwise);
  950. if (pairwise & RNDIS_WLAN_ALG_CCMP)
  951. encr_mode = NDIS_80211_ENCR_CCMP_ENABLED;
  952. else if (pairwise & RNDIS_WLAN_ALG_TKIP)
  953. encr_mode = NDIS_80211_ENCR_TKIP_ENABLED;
  954. else if (pairwise & RNDIS_WLAN_ALG_WEP)
  955. encr_mode = NDIS_80211_ENCR_WEP_ENABLED;
  956. else if (groupwise & RNDIS_WLAN_ALG_CCMP)
  957. encr_mode = NDIS_80211_ENCR_CCMP_ENABLED;
  958. else if (groupwise & RNDIS_WLAN_ALG_TKIP)
  959. encr_mode = NDIS_80211_ENCR_TKIP_ENABLED;
  960. else
  961. encr_mode = NDIS_80211_ENCR_DISABLED;
  962. tmp = cpu_to_le32(encr_mode);
  963. ret = rndis_set_oid(usbdev, OID_802_11_ENCRYPTION_STATUS, &tmp,
  964. sizeof(tmp));
  965. if (ret != 0) {
  966. devwarn(usbdev, "setting encr mode failed (%08X)", ret);
  967. return ret;
  968. }
  969. priv->wpa_cipher_pair = pairwise;
  970. priv->wpa_cipher_group = groupwise;
  971. return 0;
  972. }
  973. static int set_infra_mode(struct usbnet *usbdev, int mode)
  974. {
  975. struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
  976. __le32 tmp;
  977. int ret;
  978. devdbg(usbdev, "set_infra_mode: infra_mode=0x%x", priv->infra_mode);
  979. tmp = cpu_to_le32(mode);
  980. ret = rndis_set_oid(usbdev, OID_802_11_INFRASTRUCTURE_MODE, &tmp,
  981. sizeof(tmp));
  982. if (ret != 0) {
  983. devwarn(usbdev, "setting infra mode failed (%08X)", ret);
  984. return ret;
  985. }
  986. /* NDIS drivers clear keys when infrastructure mode is
  987. * changed. But Linux tools assume otherwise. So set the
  988. * keys */
  989. restore_keys(usbdev);
  990. priv->infra_mode = mode;
  991. return 0;
  992. }
  993. static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
  994. {
  995. __le32 tmp;
  996. devdbg(usbdev, "set_rts_threshold %i", rts_threshold);
  997. if (rts_threshold < 0 || rts_threshold > 2347)
  998. rts_threshold = 2347;
  999. tmp = cpu_to_le32(rts_threshold);
  1000. return rndis_set_oid(usbdev, OID_802_11_RTS_THRESHOLD, &tmp,
  1001. sizeof(tmp));
  1002. }
  1003. static int set_frag_threshold(struct usbnet *usbdev, u32 frag_threshold)
  1004. {
  1005. __le32 tmp;
  1006. devdbg(usbdev, "set_frag_threshold %i", frag_threshold);
  1007. if (frag_threshold < 256 || frag_threshold > 2346)
  1008. frag_threshold = 2346;
  1009. tmp = cpu_to_le32(frag_threshold);
  1010. return rndis_set_oid(usbdev, OID_802_11_FRAGMENTATION_THRESHOLD, &tmp,
  1011. sizeof(tmp));
  1012. }
  1013. static void set_default_iw_params(struct usbnet *usbdev)
  1014. {
  1015. set_infra_mode(usbdev, NDIS_80211_INFRA_INFRA);
  1016. set_auth_mode(usbdev, 0, NL80211_AUTHTYPE_OPEN_SYSTEM,
  1017. RNDIS_WLAN_KEY_MGMT_NONE);
  1018. set_priv_filter(usbdev);
  1019. set_encr_mode(usbdev, RNDIS_WLAN_ALG_NONE, RNDIS_WLAN_ALG_NONE);
  1020. }
  1021. static int deauthenticate(struct usbnet *usbdev)
  1022. {
  1023. int ret;
  1024. ret = disassociate(usbdev, 1);
  1025. set_default_iw_params(usbdev);
  1026. return ret;
  1027. }
  1028. static int set_channel(struct usbnet *usbdev, int channel)
  1029. {
  1030. struct ndis_80211_conf config;
  1031. unsigned int dsconfig;
  1032. int len, ret;
  1033. devdbg(usbdev, "set_channel(%d)", channel);
  1034. /* this OID is valid only when not associated */
  1035. if (is_associated(usbdev))
  1036. return 0;
  1037. dsconfig = ieee80211_dsss_chan_to_freq(channel) * 1000;
  1038. len = sizeof(config);
  1039. ret = rndis_query_oid(usbdev, OID_802_11_CONFIGURATION, &config, &len);
  1040. if (ret < 0) {
  1041. devdbg(usbdev, "set_channel: querying configuration failed");
  1042. return ret;
  1043. }
  1044. config.ds_config = cpu_to_le32(dsconfig);
  1045. ret = rndis_set_oid(usbdev, OID_802_11_CONFIGURATION, &config,
  1046. sizeof(config));
  1047. devdbg(usbdev, "set_channel: %d -> %d", channel, ret);
  1048. return ret;
  1049. }
  1050. /* index must be 0 - N, as per NDIS */
  1051. static int add_wep_key(struct usbnet *usbdev, const u8 *key, int key_len,
  1052. int index)
  1053. {
  1054. struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
  1055. struct ndis_80211_wep_key ndis_key;
  1056. u32 cipher;
  1057. int ret;
  1058. devdbg(usbdev, "add_wep_key(idx: %d, len: %d)", index, key_len);
  1059. if ((key_len != 5 && key_len != 13) || index < 0 || index > 3)
  1060. return -EINVAL;
  1061. if (key_len == 5)
  1062. cipher = WLAN_CIPHER_SUITE_WEP40;
  1063. else
  1064. cipher = WLAN_CIPHER_SUITE_WEP104;
  1065. memset(&ndis_key, 0, sizeof(ndis_key));
  1066. ndis_key.size = cpu_to_le32(sizeof(ndis_key));
  1067. ndis_key.length = cpu_to_le32(key_len);
  1068. ndis_key.index = cpu_to_le32(index);
  1069. memcpy(&ndis_key.material, key, key_len);
  1070. if (index == priv->encr_tx_key_index) {
  1071. ndis_key.index |= NDIS_80211_ADDWEP_TRANSMIT_KEY;
  1072. ret = set_encr_mode(usbdev, RNDIS_WLAN_ALG_WEP,
  1073. RNDIS_WLAN_ALG_NONE);
  1074. if (ret)
  1075. devwarn(usbdev, "encryption couldn't be enabled (%08X)",
  1076. ret);
  1077. }
  1078. ret = rndis_set_oid(usbdev, OID_802_11_ADD_WEP, &ndis_key,
  1079. sizeof(ndis_key));
  1080. if (ret != 0) {
  1081. devwarn(usbdev, "adding encryption key %d failed (%08X)",
  1082. index+1, ret);
  1083. return ret;
  1084. }
  1085. priv->encr_keys[index].len = key_len;
  1086. priv->encr_keys[index].cipher = cipher;
  1087. memcpy(&priv->encr_keys[index].material, key, key_len);
  1088. memset(&priv->encr_keys[index].bssid, 0xff, ETH_ALEN);
  1089. return 0;
  1090. }
  1091. static int add_wpa_key(struct usbnet *usbdev, const u8 *key, int key_len,
  1092. int index, const u8 *addr, const u8 *rx_seq,
  1093. int seq_len, u32 cipher, int flags)
  1094. {
  1095. struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
  1096. struct ndis_80211_key ndis_key;
  1097. bool is_addr_ok;
  1098. int ret;
  1099. if (index < 0 || index >= 4) {
  1100. devdbg(usbdev, "add_wpa_key: index out of range (%i)", index);
  1101. return -EINVAL;
  1102. }
  1103. if (key_len > sizeof(ndis_key.material) || key_len < 0) {
  1104. devdbg(usbdev, "add_wpa_key: key length out of range (%i)",
  1105. key_len);
  1106. return -EINVAL;
  1107. }
  1108. if (flags & NDIS_80211_ADDKEY_SET_INIT_RECV_SEQ) {
  1109. if (!rx_seq || seq_len <= 0) {
  1110. devdbg(usbdev, "add_wpa_key: recv seq flag without"
  1111. "buffer");
  1112. return -EINVAL;
  1113. }
  1114. if (rx_seq && seq_len > sizeof(ndis_key.rsc)) {
  1115. devdbg(usbdev, "add_wpa_key: too big recv seq buffer");
  1116. return -EINVAL;
  1117. }
  1118. }
  1119. is_addr_ok = addr && !is_zero_ether_addr(addr) &&
  1120. !is_broadcast_ether_addr(addr);
  1121. if ((flags & NDIS_80211_ADDKEY_PAIRWISE_KEY) && !is_addr_ok) {
  1122. devdbg(usbdev, "add_wpa_key: pairwise but bssid invalid (%pM)",
  1123. addr);
  1124. return -EINVAL;
  1125. }
  1126. devdbg(usbdev, "add_wpa_key(%i): flags:%i%i%i", index,
  1127. !!(flags & NDIS_80211_ADDKEY_TRANSMIT_KEY),
  1128. !!(flags & NDIS_80211_ADDKEY_PAIRWISE_KEY),
  1129. !!(flags & NDIS_80211_ADDKEY_SET_INIT_RECV_SEQ));
  1130. memset(&ndis_key, 0, sizeof(ndis_key));
  1131. ndis_key.size = cpu_to_le32(sizeof(ndis_key) -
  1132. sizeof(ndis_key.material) + key_len);
  1133. ndis_key.length = cpu_to_le32(key_len);
  1134. ndis_key.index = cpu_to_le32(index) | flags;
  1135. if (cipher == WLAN_CIPHER_SUITE_TKIP && key_len == 32) {
  1136. /* wpa_supplicant gives us the Michael MIC RX/TX keys in
  1137. * different order than NDIS spec, so swap the order here. */
  1138. memcpy(ndis_key.material, key, 16);
  1139. memcpy(ndis_key.material + 16, key + 24, 8);
  1140. memcpy(ndis_key.material + 24, key + 16, 8);
  1141. } else
  1142. memcpy(ndis_key.material, key, key_len);
  1143. if (flags & NDIS_80211_ADDKEY_SET_INIT_RECV_SEQ)
  1144. memcpy(ndis_key.rsc, rx_seq, seq_len);
  1145. if (flags & NDIS_80211_ADDKEY_PAIRWISE_KEY) {
  1146. /* pairwise key */
  1147. memcpy(ndis_key.bssid, addr, ETH_ALEN);
  1148. } else {
  1149. /* group key */
  1150. if (priv->infra_mode == NDIS_80211_INFRA_ADHOC)
  1151. memset(ndis_key.bssid, 0xff, ETH_ALEN);
  1152. else
  1153. get_bssid(usbdev, ndis_key.bssid);
  1154. }
  1155. ret = rndis_set_oid(usbdev, OID_802_11_ADD_KEY, &ndis_key,
  1156. le32_to_cpu(ndis_key.size));
  1157. devdbg(usbdev, "add_wpa_key: OID_802_11_ADD_KEY -> %08X", ret);
  1158. if (ret != 0)
  1159. return ret;
  1160. memset(&priv->encr_keys[index], 0, sizeof(priv->encr_keys[index]));
  1161. priv->encr_keys[index].len = key_len;
  1162. priv->encr_keys[index].cipher = cipher;
  1163. memcpy(&priv->encr_keys[index].material, key, key_len);
  1164. if (flags & NDIS_80211_ADDKEY_PAIRWISE_KEY)
  1165. memcpy(&priv->encr_keys[index].bssid, ndis_key.bssid, ETH_ALEN);
  1166. else
  1167. memset(&priv->encr_keys[index].bssid, 0xff, ETH_ALEN);
  1168. if (flags & NDIS_80211_ADDKEY_TRANSMIT_KEY)
  1169. priv->encr_tx_key_index = index;
  1170. return 0;
  1171. }
  1172. static int restore_key(struct usbnet *usbdev, int key_idx)
  1173. {
  1174. struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
  1175. struct rndis_wlan_encr_key key;
  1176. if (is_wpa_key(priv, key_idx))
  1177. return 0;
  1178. key = priv->encr_keys[key_idx];
  1179. devdbg(usbdev, "restore_key: %i:%i", key_idx, key.len);
  1180. if (key.len == 0)
  1181. return 0;
  1182. return add_wep_key(usbdev, key.material, key.len, key_idx);
  1183. }
  1184. static void restore_keys(struct usbnet *usbdev)
  1185. {
  1186. int i;
  1187. for (i = 0; i < 4; i++)
  1188. restore_key(usbdev, i);
  1189. }
  1190. static void clear_key(struct rndis_wlan_private *priv, int idx)
  1191. {
  1192. memset(&priv->encr_keys[idx], 0, sizeof(priv->encr_keys[idx]));
  1193. }
  1194. /* remove_key is for both wep and wpa */
  1195. static int remove_key(struct usbnet *usbdev, int index, const u8 *bssid)
  1196. {
  1197. struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
  1198. struct ndis_80211_remove_key remove_key;
  1199. __le32 keyindex;
  1200. bool is_wpa;
  1201. int ret;
  1202. if (priv->encr_keys[index].len == 0)
  1203. return 0;
  1204. is_wpa = is_wpa_key(priv, index);
  1205. devdbg(usbdev, "remove_key: %i:%s:%i", index, is_wpa ? "wpa" : "wep",
  1206. priv->encr_keys[index].len);
  1207. clear_key(priv, index);
  1208. if (is_wpa) {
  1209. remove_key.size = cpu_to_le32(sizeof(remove_key));
  1210. remove_key.index = cpu_to_le32(index);
  1211. if (bssid) {
  1212. /* pairwise key */
  1213. if (!is_broadcast_ether_addr(bssid))
  1214. remove_key.index |=
  1215. NDIS_80211_ADDKEY_PAIRWISE_KEY;
  1216. memcpy(remove_key.bssid, bssid,
  1217. sizeof(remove_key.bssid));
  1218. } else
  1219. memset(remove_key.bssid, 0xff,
  1220. sizeof(remove_key.bssid));
  1221. ret = rndis_set_oid(usbdev, OID_802_11_REMOVE_KEY, &remove_key,
  1222. sizeof(remove_key));
  1223. if (ret != 0)
  1224. return ret;
  1225. } else {
  1226. keyindex = cpu_to_le32(index);
  1227. ret = rndis_set_oid(usbdev, OID_802_11_REMOVE_WEP, &keyindex,
  1228. sizeof(keyindex));
  1229. if (ret != 0) {
  1230. devwarn(usbdev,
  1231. "removing encryption key %d failed (%08X)",
  1232. index, ret);
  1233. return ret;
  1234. }
  1235. }
  1236. /* if it is transmit key, disable encryption */
  1237. if (index == priv->encr_tx_key_index)
  1238. set_encr_mode(usbdev, RNDIS_WLAN_ALG_NONE, RNDIS_WLAN_ALG_NONE);
  1239. return 0;
  1240. }
  1241. static void set_multicast_list(struct usbnet *usbdev)
  1242. {
  1243. struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
  1244. struct dev_mc_list *mclist;
  1245. __le32 filter;
  1246. int ret, i, size;
  1247. char *buf;
  1248. filter = RNDIS_PACKET_TYPE_DIRECTED | RNDIS_PACKET_TYPE_BROADCAST;
  1249. if (usbdev->net->flags & IFF_PROMISC) {
  1250. filter |= RNDIS_PACKET_TYPE_PROMISCUOUS |
  1251. RNDIS_PACKET_TYPE_ALL_LOCAL;
  1252. } else if (usbdev->net->flags & IFF_ALLMULTI ||
  1253. usbdev->net->mc_count > priv->multicast_size) {
  1254. filter |= RNDIS_PACKET_TYPE_ALL_MULTICAST;
  1255. } else if (usbdev->net->mc_count > 0) {
  1256. size = min(priv->multicast_size, usbdev->net->mc_count);
  1257. buf = kmalloc(size * ETH_ALEN, GFP_KERNEL);
  1258. if (!buf) {
  1259. devwarn(usbdev,
  1260. "couldn't alloc %d bytes of memory",
  1261. size * ETH_ALEN);
  1262. return;
  1263. }
  1264. mclist = usbdev->net->mc_list;
  1265. for (i = 0; i < size && mclist; mclist = mclist->next) {
  1266. if (mclist->dmi_addrlen != ETH_ALEN)
  1267. continue;
  1268. memcpy(buf + i * ETH_ALEN, mclist->dmi_addr, ETH_ALEN);
  1269. i++;
  1270. }
  1271. ret = rndis_set_oid(usbdev, OID_802_3_MULTICAST_LIST, buf,
  1272. i * ETH_ALEN);
  1273. if (ret == 0 && i > 0)
  1274. filter |= RNDIS_PACKET_TYPE_MULTICAST;
  1275. else
  1276. filter |= RNDIS_PACKET_TYPE_ALL_MULTICAST;
  1277. devdbg(usbdev, "OID_802_3_MULTICAST_LIST(%d, max: %d) -> %d",
  1278. i, priv->multicast_size, ret);
  1279. kfree(buf);
  1280. }
  1281. ret = rndis_set_oid(usbdev, OID_GEN_CURRENT_PACKET_FILTER, &filter,
  1282. sizeof(filter));
  1283. if (ret < 0) {
  1284. devwarn(usbdev, "couldn't set packet filter: %08x",
  1285. le32_to_cpu(filter));
  1286. }
  1287. devdbg(usbdev, "OID_GEN_CURRENT_PACKET_FILTER(%08x) -> %d",
  1288. le32_to_cpu(filter), ret);
  1289. }
  1290. /*
  1291. * cfg80211 ops
  1292. */
  1293. static int rndis_change_virtual_intf(struct wiphy *wiphy,
  1294. struct net_device *dev,
  1295. enum nl80211_iftype type, u32 *flags,
  1296. struct vif_params *params)
  1297. {
  1298. struct rndis_wlan_private *priv = wiphy_priv(wiphy);
  1299. struct usbnet *usbdev = priv->usbdev;
  1300. int mode;
  1301. switch (type) {
  1302. case NL80211_IFTYPE_ADHOC:
  1303. mode = NDIS_80211_INFRA_ADHOC;
  1304. break;
  1305. case NL80211_IFTYPE_STATION:
  1306. mode = NDIS_80211_INFRA_INFRA;
  1307. break;
  1308. default:
  1309. return -EINVAL;
  1310. }
  1311. priv->wdev.iftype = type;
  1312. return set_infra_mode(usbdev, mode);
  1313. }
  1314. static int rndis_set_wiphy_params(struct wiphy *wiphy, u32 changed)
  1315. {
  1316. struct rndis_wlan_private *priv = wiphy_priv(wiphy);
  1317. struct usbnet *usbdev = priv->usbdev;
  1318. int err;
  1319. if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
  1320. err = set_frag_threshold(usbdev, wiphy->frag_threshold);
  1321. if (err < 0)
  1322. return err;
  1323. }
  1324. if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
  1325. err = set_rts_threshold(usbdev, wiphy->rts_threshold);
  1326. if (err < 0)
  1327. return err;
  1328. }
  1329. return 0;
  1330. }
  1331. static int rndis_set_tx_power(struct wiphy *wiphy, enum tx_power_setting type,
  1332. int dbm)
  1333. {
  1334. struct rndis_wlan_private *priv = wiphy_priv(wiphy);
  1335. struct usbnet *usbdev = priv->usbdev;
  1336. devdbg(usbdev, "rndis_set_tx_power type:0x%x dbm:%i", type, dbm);
  1337. /* Device doesn't support changing txpower after initialization, only
  1338. * turn off/on radio. Support 'auto' mode and setting same dBm that is
  1339. * currently used.
  1340. */
  1341. if (type == TX_POWER_AUTOMATIC || dbm == get_bcm4320_power_dbm(priv)) {
  1342. if (!priv->radio_on)
  1343. disassociate(usbdev, 1); /* turn on radio */
  1344. return 0;
  1345. }
  1346. return -ENOTSUPP;
  1347. }
  1348. static int rndis_get_tx_power(struct wiphy *wiphy, int *dbm)
  1349. {
  1350. struct rndis_wlan_private *priv = wiphy_priv(wiphy);
  1351. struct usbnet *usbdev = priv->usbdev;
  1352. *dbm = get_bcm4320_power_dbm(priv);
  1353. devdbg(usbdev, "rndis_get_tx_power dbm:%i", *dbm);
  1354. return 0;
  1355. }
  1356. #define SCAN_DELAY_JIFFIES (6 * HZ)
  1357. static int rndis_scan(struct wiphy *wiphy, struct net_device *dev,
  1358. struct cfg80211_scan_request *request)
  1359. {
  1360. struct usbnet *usbdev = netdev_priv(dev);
  1361. struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
  1362. int ret;
  1363. __le32 tmp;
  1364. devdbg(usbdev, "cfg80211.scan");
  1365. /* Get current bssid list from device before new scan, as new scan
  1366. * clears internal bssid list.
  1367. */
  1368. rndis_check_bssid_list(usbdev);
  1369. if (!request)
  1370. return -EINVAL;
  1371. if (priv->scan_request && priv->scan_request != request)
  1372. return -EBUSY;
  1373. priv->scan_request = request;
  1374. tmp = cpu_to_le32(1);
  1375. ret = rndis_set_oid(usbdev, OID_802_11_BSSID_LIST_SCAN, &tmp,
  1376. sizeof(tmp));
  1377. if (ret == 0) {
  1378. /* Wait before retrieving scan results from device */
  1379. queue_delayed_work(priv->workqueue, &priv->scan_work,
  1380. SCAN_DELAY_JIFFIES);
  1381. }
  1382. return ret;
  1383. }
  1384. static struct cfg80211_bss *rndis_bss_info_update(struct usbnet *usbdev,
  1385. struct ndis_80211_bssid_ex *bssid)
  1386. {
  1387. struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
  1388. struct ieee80211_channel *channel;
  1389. s32 signal;
  1390. u64 timestamp;
  1391. u16 capability;
  1392. u16 beacon_interval;
  1393. struct ndis_80211_fixed_ies *fixed;
  1394. int ie_len, bssid_len;
  1395. u8 *ie;
  1396. devdbg(usbdev, " found bssid: '%.32s' [%pM]", bssid->ssid.essid,
  1397. bssid->mac);
  1398. /* parse bssid structure */
  1399. bssid_len = le32_to_cpu(bssid->length);
  1400. if (bssid_len < sizeof(struct ndis_80211_bssid_ex) +
  1401. sizeof(struct ndis_80211_fixed_ies))
  1402. return NULL;
  1403. fixed = (struct ndis_80211_fixed_ies *)bssid->ies;
  1404. ie = (void *)(bssid->ies + sizeof(struct ndis_80211_fixed_ies));
  1405. ie_len = min(bssid_len - (int)sizeof(*bssid),
  1406. (int)le32_to_cpu(bssid->ie_length));
  1407. ie_len -= sizeof(struct ndis_80211_fixed_ies);
  1408. if (ie_len < 0)
  1409. return NULL;
  1410. /* extract data for cfg80211_inform_bss */
  1411. channel = ieee80211_get_channel(priv->wdev.wiphy,
  1412. KHZ_TO_MHZ(le32_to_cpu(bssid->config.ds_config)));
  1413. if (!channel)
  1414. return NULL;
  1415. signal = level_to_qual(le32_to_cpu(bssid->rssi));
  1416. timestamp = le64_to_cpu(*(__le64 *)fixed->timestamp);
  1417. capability = le16_to_cpu(fixed->capabilities);
  1418. beacon_interval = le16_to_cpu(fixed->beacon_interval);
  1419. return cfg80211_inform_bss(priv->wdev.wiphy, channel, bssid->mac,
  1420. timestamp, capability, beacon_interval, ie, ie_len, signal,
  1421. GFP_KERNEL);
  1422. }
  1423. static int rndis_check_bssid_list(struct usbnet *usbdev)
  1424. {
  1425. void *buf = NULL;
  1426. struct ndis_80211_bssid_list_ex *bssid_list;
  1427. struct ndis_80211_bssid_ex *bssid;
  1428. int ret = -EINVAL, len, count, bssid_len;
  1429. bool resized = false;
  1430. devdbg(usbdev, "check_bssid_list");
  1431. len = CONTROL_BUFFER_SIZE;
  1432. resize_buf:
  1433. buf = kmalloc(len, GFP_KERNEL);
  1434. if (!buf) {
  1435. ret = -ENOMEM;
  1436. goto out;
  1437. }
  1438. ret = rndis_query_oid(usbdev, OID_802_11_BSSID_LIST, buf, &len);
  1439. if (ret != 0)
  1440. goto out;
  1441. if (!resized && len > CONTROL_BUFFER_SIZE) {
  1442. resized = true;
  1443. kfree(buf);
  1444. goto resize_buf;
  1445. }
  1446. bssid_list = buf;
  1447. bssid = bssid_list->bssid;
  1448. bssid_len = le32_to_cpu(bssid->length);
  1449. count = le32_to_cpu(bssid_list->num_items);
  1450. devdbg(usbdev, "check_bssid_list: %d BSSIDs found (buflen: %d)", count,
  1451. len);
  1452. while (count && ((void *)bssid + bssid_len) <= (buf + len)) {
  1453. rndis_bss_info_update(usbdev, bssid);
  1454. bssid = (void *)bssid + bssid_len;
  1455. bssid_len = le32_to_cpu(bssid->length);
  1456. count--;
  1457. }
  1458. out:
  1459. kfree(buf);
  1460. return ret;
  1461. }
  1462. static void rndis_get_scan_results(struct work_struct *work)
  1463. {
  1464. struct rndis_wlan_private *priv =
  1465. container_of(work, struct rndis_wlan_private, scan_work.work);
  1466. struct usbnet *usbdev = priv->usbdev;
  1467. int ret;
  1468. devdbg(usbdev, "get_scan_results");
  1469. if (!priv->scan_request)
  1470. return;
  1471. ret = rndis_check_bssid_list(usbdev);
  1472. cfg80211_scan_done(priv->scan_request, ret < 0);
  1473. priv->scan_request = NULL;
  1474. }
  1475. static int rndis_connect(struct wiphy *wiphy, struct net_device *dev,
  1476. struct cfg80211_connect_params *sme)
  1477. {
  1478. struct rndis_wlan_private *priv = wiphy_priv(wiphy);
  1479. struct usbnet *usbdev = priv->usbdev;
  1480. struct ieee80211_channel *channel = sme->channel;
  1481. struct ndis_80211_ssid ssid;
  1482. int pairwise = RNDIS_WLAN_ALG_NONE;
  1483. int groupwise = RNDIS_WLAN_ALG_NONE;
  1484. int keymgmt = RNDIS_WLAN_KEY_MGMT_NONE;
  1485. int length, i, ret, chan = -1;
  1486. if (channel)
  1487. chan = ieee80211_frequency_to_channel(channel->center_freq);
  1488. groupwise = rndis_cipher_to_alg(sme->crypto.cipher_group);
  1489. for (i = 0; i < sme->crypto.n_ciphers_pairwise; i++)
  1490. pairwise |=
  1491. rndis_cipher_to_alg(sme->crypto.ciphers_pairwise[i]);
  1492. if (sme->crypto.n_ciphers_pairwise > 0 &&
  1493. pairwise == RNDIS_WLAN_ALG_NONE) {
  1494. deverr(usbdev, "Unsupported pairwise cipher");
  1495. return -ENOTSUPP;
  1496. }
  1497. for (i = 0; i < sme->crypto.n_akm_suites; i++)
  1498. keymgmt |=
  1499. rndis_akm_suite_to_key_mgmt(sme->crypto.akm_suites[i]);
  1500. if (sme->crypto.n_akm_suites > 0 &&
  1501. keymgmt == RNDIS_WLAN_KEY_MGMT_NONE) {
  1502. deverr(usbdev, "Invalid keymgmt");
  1503. return -ENOTSUPP;
  1504. }
  1505. devdbg(usbdev, "cfg80211.connect('%.32s':[%pM]:%d:[%d,0x%x:0x%x]:[0x%x:"
  1506. "0x%x]:0x%x)", sme->ssid, sme->bssid, chan,
  1507. sme->privacy, sme->crypto.wpa_versions, sme->auth_type,
  1508. groupwise, pairwise, keymgmt);
  1509. if (is_associated(usbdev))
  1510. disassociate(usbdev, false);
  1511. ret = set_infra_mode(usbdev, NDIS_80211_INFRA_INFRA);
  1512. if (ret < 0) {
  1513. devdbg(usbdev, "connect: set_infra_mode failed, %d", ret);
  1514. goto err_turn_radio_on;
  1515. }
  1516. ret = set_auth_mode(usbdev, sme->crypto.wpa_versions, sme->auth_type,
  1517. keymgmt);
  1518. if (ret < 0) {
  1519. devdbg(usbdev, "connect: set_auth_mode failed, %d", ret);
  1520. goto err_turn_radio_on;
  1521. }
  1522. set_priv_filter(usbdev);
  1523. ret = set_encr_mode(usbdev, pairwise, groupwise);
  1524. if (ret < 0) {
  1525. devdbg(usbdev, "connect: set_encr_mode failed, %d", ret);
  1526. goto err_turn_radio_on;
  1527. }
  1528. if (channel) {
  1529. ret = set_channel(usbdev, chan);
  1530. if (ret < 0) {
  1531. devdbg(usbdev, "connect: set_channel failed, %d", ret);
  1532. goto err_turn_radio_on;
  1533. }
  1534. }
  1535. if (sme->key && ((groupwise | pairwise) & RNDIS_WLAN_ALG_WEP)) {
  1536. priv->encr_tx_key_index = sme->key_idx;
  1537. ret = add_wep_key(usbdev, sme->key, sme->key_len, sme->key_idx);
  1538. if (ret < 0) {
  1539. devdbg(usbdev, "connect: add_wep_key failed, %d "
  1540. "(%d, %d)", ret, sme->key_len, sme->key_idx);
  1541. goto err_turn_radio_on;
  1542. }
  1543. }
  1544. if (sme->bssid && !is_zero_ether_addr(sme->bssid) &&
  1545. !is_broadcast_ether_addr(sme->bssid)) {
  1546. ret = set_bssid(usbdev, sme->bssid);
  1547. if (ret < 0) {
  1548. devdbg(usbdev, "connect: set_bssid failed, %d", ret);
  1549. goto err_turn_radio_on;
  1550. }
  1551. } else
  1552. clear_bssid(usbdev);
  1553. length = sme->ssid_len;
  1554. if (length > NDIS_802_11_LENGTH_SSID)
  1555. length = NDIS_802_11_LENGTH_SSID;
  1556. memset(&ssid, 0, sizeof(ssid));
  1557. ssid.length = cpu_to_le32(length);
  1558. memcpy(ssid.essid, sme->ssid, length);
  1559. /* Pause and purge rx queue, so we don't pass packets before
  1560. * 'media connect'-indication.
  1561. */
  1562. usbnet_pause_rx(usbdev);
  1563. usbnet_purge_paused_rxq(usbdev);
  1564. ret = set_essid(usbdev, &ssid);
  1565. if (ret < 0)
  1566. devdbg(usbdev, "connect: set_essid failed, %d", ret);
  1567. return ret;
  1568. err_turn_radio_on:
  1569. disassociate(usbdev, 1);
  1570. return ret;
  1571. }
  1572. static int rndis_disconnect(struct wiphy *wiphy, struct net_device *dev,
  1573. u16 reason_code)
  1574. {
  1575. struct rndis_wlan_private *priv = wiphy_priv(wiphy);
  1576. struct usbnet *usbdev = priv->usbdev;
  1577. devdbg(usbdev, "cfg80211.disconnect(%d)", reason_code);
  1578. priv->connected = false;
  1579. memset(priv->bssid, 0, ETH_ALEN);
  1580. return deauthenticate(usbdev);
  1581. }
  1582. static int rndis_join_ibss(struct wiphy *wiphy, struct net_device *dev,
  1583. struct cfg80211_ibss_params *params)
  1584. {
  1585. struct rndis_wlan_private *priv = wiphy_priv(wiphy);
  1586. struct usbnet *usbdev = priv->usbdev;
  1587. struct ieee80211_channel *channel = params->channel;
  1588. struct ndis_80211_ssid ssid;
  1589. enum nl80211_auth_type auth_type;
  1590. int ret, alg, length, chan = -1;
  1591. if (channel)
  1592. chan = ieee80211_frequency_to_channel(channel->center_freq);
  1593. /* TODO: How to handle ad-hoc encryption?
  1594. * connect() has *key, join_ibss() doesn't. RNDIS requires key to be
  1595. * pre-shared for encryption (open/shared/wpa), is key set before
  1596. * join_ibss? Which auth_type to use (not in params)? What about WPA?
  1597. */
  1598. if (params->privacy) {
  1599. auth_type = NL80211_AUTHTYPE_SHARED_KEY;
  1600. alg = RNDIS_WLAN_ALG_WEP;
  1601. } else {
  1602. auth_type = NL80211_AUTHTYPE_OPEN_SYSTEM;
  1603. alg = RNDIS_WLAN_ALG_NONE;
  1604. }
  1605. devdbg(usbdev, "cfg80211.join_ibss('%.32s':[%pM]:%d:%d)", params->ssid,
  1606. params->bssid, chan, params->privacy);
  1607. if (is_associated(usbdev))
  1608. disassociate(usbdev, false);
  1609. ret = set_infra_mode(usbdev, NDIS_80211_INFRA_ADHOC);
  1610. if (ret < 0) {
  1611. devdbg(usbdev, "join_ibss: set_infra_mode failed, %d", ret);
  1612. goto err_turn_radio_on;
  1613. }
  1614. ret = set_auth_mode(usbdev, 0, auth_type, RNDIS_WLAN_KEY_MGMT_NONE);
  1615. if (ret < 0) {
  1616. devdbg(usbdev, "join_ibss: set_auth_mode failed, %d", ret);
  1617. goto err_turn_radio_on;
  1618. }
  1619. set_priv_filter(usbdev);
  1620. ret = set_encr_mode(usbdev, alg, RNDIS_WLAN_ALG_NONE);
  1621. if (ret < 0) {
  1622. devdbg(usbdev, "join_ibss: set_encr_mode failed, %d", ret);
  1623. goto err_turn_radio_on;
  1624. }
  1625. if (channel) {
  1626. ret = set_channel(usbdev, chan);
  1627. if (ret < 0) {
  1628. devdbg(usbdev, "join_ibss: set_channel failed, %d",
  1629. ret);
  1630. goto err_turn_radio_on;
  1631. }
  1632. }
  1633. if (params->bssid && !is_zero_ether_addr(params->bssid) &&
  1634. !is_broadcast_ether_addr(params->bssid)) {
  1635. ret = set_bssid(usbdev, params->bssid);
  1636. if (ret < 0) {
  1637. devdbg(usbdev, "join_ibss: set_bssid failed, %d", ret);
  1638. goto err_turn_radio_on;
  1639. }
  1640. } else
  1641. clear_bssid(usbdev);
  1642. length = params->ssid_len;
  1643. if (length > NDIS_802_11_LENGTH_SSID)
  1644. length = NDIS_802_11_LENGTH_SSID;
  1645. memset(&ssid, 0, sizeof(ssid));
  1646. ssid.length = cpu_to_le32(length);
  1647. memcpy(ssid.essid, params->ssid, length);
  1648. /* Don't need to pause rx queue for ad-hoc. */
  1649. usbnet_purge_paused_rxq(usbdev);
  1650. usbnet_resume_rx(usbdev);
  1651. ret = set_essid(usbdev, &ssid);
  1652. if (ret < 0)
  1653. devdbg(usbdev, "join_ibss: set_essid failed, %d", ret);
  1654. return ret;
  1655. err_turn_radio_on:
  1656. disassociate(usbdev, 1);
  1657. return ret;
  1658. }
  1659. static int rndis_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
  1660. {
  1661. struct rndis_wlan_private *priv = wiphy_priv(wiphy);
  1662. struct usbnet *usbdev = priv->usbdev;
  1663. devdbg(usbdev, "cfg80211.leave_ibss()");
  1664. priv->connected = false;
  1665. memset(priv->bssid, 0, ETH_ALEN);
  1666. return deauthenticate(usbdev);
  1667. }
  1668. static int rndis_set_channel(struct wiphy *wiphy,
  1669. struct ieee80211_channel *chan, enum nl80211_channel_type channel_type)
  1670. {
  1671. struct rndis_wlan_private *priv = wiphy_priv(wiphy);
  1672. struct usbnet *usbdev = priv->usbdev;
  1673. return set_channel(usbdev,
  1674. ieee80211_frequency_to_channel(chan->center_freq));
  1675. }
  1676. static int rndis_add_key(struct wiphy *wiphy, struct net_device *netdev,
  1677. u8 key_index, const u8 *mac_addr,
  1678. struct key_params *params)
  1679. {
  1680. struct rndis_wlan_private *priv = wiphy_priv(wiphy);
  1681. struct usbnet *usbdev = priv->usbdev;
  1682. int flags;
  1683. devdbg(usbdev, "rndis_add_key(%i, %pM, %08x)", key_index, mac_addr,
  1684. params->cipher);
  1685. switch (params->cipher) {
  1686. case WLAN_CIPHER_SUITE_WEP40:
  1687. case WLAN_CIPHER_SUITE_WEP104:
  1688. return add_wep_key(usbdev, params->key, params->key_len,
  1689. key_index);
  1690. case WLAN_CIPHER_SUITE_TKIP:
  1691. case WLAN_CIPHER_SUITE_CCMP:
  1692. flags = 0;
  1693. if (params->seq && params->seq_len > 0)
  1694. flags |= NDIS_80211_ADDKEY_SET_INIT_RECV_SEQ;
  1695. if (mac_addr)
  1696. flags |= NDIS_80211_ADDKEY_PAIRWISE_KEY |
  1697. NDIS_80211_ADDKEY_TRANSMIT_KEY;
  1698. return add_wpa_key(usbdev, params->key, params->key_len,
  1699. key_index, mac_addr, params->seq,
  1700. params->seq_len, params->cipher, flags);
  1701. default:
  1702. devdbg(usbdev, "rndis_add_key: unsupported cipher %08x",
  1703. params->cipher);
  1704. return -ENOTSUPP;
  1705. }
  1706. }
  1707. static int rndis_del_key(struct wiphy *wiphy, struct net_device *netdev,
  1708. u8 key_index, const u8 *mac_addr)
  1709. {
  1710. struct rndis_wlan_private *priv = wiphy_priv(wiphy);
  1711. struct usbnet *usbdev = priv->usbdev;
  1712. devdbg(usbdev, "rndis_del_key(%i, %pM)", key_index, mac_addr);
  1713. return remove_key(usbdev, key_index, mac_addr);
  1714. }
  1715. static int rndis_set_default_key(struct wiphy *wiphy, struct net_device *netdev,
  1716. u8 key_index)
  1717. {
  1718. struct rndis_wlan_private *priv = wiphy_priv(wiphy);
  1719. struct usbnet *usbdev = priv->usbdev;
  1720. struct rndis_wlan_encr_key key;
  1721. devdbg(usbdev, "rndis_set_default_key(%i)", key_index);
  1722. priv->encr_tx_key_index = key_index;
  1723. key = priv->encr_keys[key_index];
  1724. return add_wep_key(usbdev, key.material, key.len, key_index);
  1725. }
  1726. static void rndis_fill_station_info(struct usbnet *usbdev,
  1727. struct station_info *sinfo)
  1728. {
  1729. __le32 linkspeed, rssi;
  1730. int ret, len;
  1731. memset(sinfo, 0, sizeof(*sinfo));
  1732. len = sizeof(linkspeed);
  1733. ret = rndis_query_oid(usbdev, OID_GEN_LINK_SPEED, &linkspeed, &len);
  1734. if (ret == 0) {
  1735. sinfo->txrate.legacy = le32_to_cpu(linkspeed) / 1000;
  1736. sinfo->filled |= STATION_INFO_TX_BITRATE;
  1737. }
  1738. len = sizeof(rssi);
  1739. ret = rndis_query_oid(usbdev, OID_802_11_RSSI, &rssi, &len);
  1740. if (ret == 0) {
  1741. sinfo->signal = level_to_qual(le32_to_cpu(rssi));
  1742. sinfo->filled |= STATION_INFO_SIGNAL;
  1743. }
  1744. }
  1745. static int rndis_get_station(struct wiphy *wiphy, struct net_device *dev,
  1746. u8 *mac, struct station_info *sinfo)
  1747. {
  1748. struct rndis_wlan_private *priv = wiphy_priv(wiphy);
  1749. struct usbnet *usbdev = priv->usbdev;
  1750. if (compare_ether_addr(priv->bssid, mac))
  1751. return -ENOENT;
  1752. rndis_fill_station_info(usbdev, sinfo);
  1753. return 0;
  1754. }
  1755. static int rndis_dump_station(struct wiphy *wiphy, struct net_device *dev,
  1756. int idx, u8 *mac, struct station_info *sinfo)
  1757. {
  1758. struct rndis_wlan_private *priv = wiphy_priv(wiphy);
  1759. struct usbnet *usbdev = priv->usbdev;
  1760. if (idx != 0)
  1761. return -ENOENT;
  1762. memcpy(mac, priv->bssid, ETH_ALEN);
  1763. rndis_fill_station_info(usbdev, sinfo);
  1764. return 0;
  1765. }
  1766. /*
  1767. * wireless extension handlers
  1768. */
  1769. #if 0
  1770. /* Commented code out instead of removing to have more sane patch for review.
  1771. * Will be removed later in the set.
  1772. */
  1773. static int rndis_iw_set_essid(struct net_device *dev,
  1774. struct iw_request_info *info, union iwreq_data *wrqu, char *essid)
  1775. {
  1776. struct ndis_80211_ssid ssid;
  1777. int length = wrqu->essid.length;
  1778. struct usbnet *usbdev = netdev_priv(dev);
  1779. devdbg(usbdev, "SIOCSIWESSID: [flags:%d,len:%d] '%.32s'",
  1780. wrqu->essid.flags, wrqu->essid.length, essid);
  1781. if (length > NDIS_802_11_LENGTH_SSID)
  1782. length = NDIS_802_11_LENGTH_SSID;
  1783. ssid.length = cpu_to_le32(length);
  1784. if (length > 0)
  1785. memcpy(ssid.essid, essid, length);
  1786. else
  1787. memset(ssid.essid, 0, NDIS_802_11_LENGTH_SSID);
  1788. set_assoc_params(usbdev);
  1789. if (!wrqu->essid.flags || length == 0)
  1790. return disassociate(usbdev, 1);
  1791. else {
  1792. /* Pause and purge rx queue, so we don't pass packets before
  1793. * 'media connect'-indication.
  1794. */
  1795. usbnet_pause_rx(usbdev);
  1796. usbnet_purge_paused_rxq(usbdev);
  1797. return set_essid(usbdev, &ssid);
  1798. }
  1799. }
  1800. static int rndis_iw_get_essid(struct net_device *dev,
  1801. struct iw_request_info *info, union iwreq_data *wrqu, char *essid)
  1802. {
  1803. struct ndis_80211_ssid ssid;
  1804. struct usbnet *usbdev = netdev_priv(dev);
  1805. int ret;
  1806. ret = get_essid(usbdev, &ssid);
  1807. if (ret == 0 && le32_to_cpu(ssid.length) > 0) {
  1808. wrqu->essid.flags = 1;
  1809. wrqu->essid.length = le32_to_cpu(ssid.length);
  1810. memcpy(essid, ssid.essid, wrqu->essid.length);
  1811. essid[wrqu->essid.length] = 0;
  1812. } else {
  1813. memset(essid, 0, sizeof(NDIS_802_11_LENGTH_SSID));
  1814. wrqu->essid.flags = 0;
  1815. wrqu->essid.length = 0;
  1816. }
  1817. devdbg(usbdev, "SIOCGIWESSID: %s", essid);
  1818. return ret;
  1819. }
  1820. static int rndis_iw_get_bssid(struct net_device *dev,
  1821. struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
  1822. {
  1823. struct usbnet *usbdev = netdev_priv(dev);
  1824. unsigned char bssid[ETH_ALEN];
  1825. int ret;
  1826. ret = get_bssid(usbdev, bssid);
  1827. if (ret == 0)
  1828. devdbg(usbdev, "SIOCGIWAP: %pM", bssid);
  1829. else
  1830. devdbg(usbdev, "SIOCGIWAP: <not associated>");
  1831. wrqu->ap_addr.sa_family = ARPHRD_ETHER;
  1832. memcpy(wrqu->ap_addr.sa_data, bssid, ETH_ALEN);
  1833. return ret;
  1834. }
  1835. static int rndis_iw_set_bssid(struct net_device *dev,
  1836. struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
  1837. {
  1838. struct usbnet *usbdev = netdev_priv(dev);
  1839. u8 *bssid = (u8 *)wrqu->ap_addr.sa_data;
  1840. int ret;
  1841. devdbg(usbdev, "SIOCSIWAP: %pM", bssid);
  1842. ret = rndis_set_oid(usbdev, OID_802_11_BSSID, bssid, ETH_ALEN);
  1843. /* user apps may set ap's mac address, which is not required;
  1844. * they may fail to work if this function fails, so return
  1845. * success */
  1846. if (ret)
  1847. devwarn(usbdev, "setting AP mac address failed (%08X)", ret);
  1848. return 0;
  1849. }
  1850. static int rndis_iw_set_auth(struct net_device *dev,
  1851. struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
  1852. {
  1853. struct iw_param *p = &wrqu->param;
  1854. struct usbnet *usbdev = netdev_priv(dev);
  1855. struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
  1856. int ret = -ENOTSUPP;
  1857. switch (p->flags & IW_AUTH_INDEX) {
  1858. case IW_AUTH_WPA_VERSION:
  1859. devdbg(usbdev, "SIOCSIWAUTH: WPA_VERSION, %08x", p->value);
  1860. priv->wpa_version = p->value;
  1861. ret = 0;
  1862. break;
  1863. case IW_AUTH_CIPHER_PAIRWISE:
  1864. devdbg(usbdev, "SIOCSIWAUTH: CIPHER_PAIRWISE, %08x", p->value);
  1865. priv->wpa_cipher_pair = p->value;
  1866. ret = 0;
  1867. break;
  1868. case IW_AUTH_CIPHER_GROUP:
  1869. devdbg(usbdev, "SIOCSIWAUTH: CIPHER_GROUP, %08x", p->value);
  1870. priv->wpa_cipher_group = p->value;
  1871. ret = 0;
  1872. break;
  1873. case IW_AUTH_KEY_MGMT:
  1874. devdbg(usbdev, "SIOCSIWAUTH: KEY_MGMT, %08x", p->value);
  1875. priv->wpa_keymgmt = p->value;
  1876. ret = 0;
  1877. break;
  1878. case IW_AUTH_TKIP_COUNTERMEASURES:
  1879. devdbg(usbdev, "SIOCSIWAUTH: TKIP_COUNTERMEASURES, %08x",
  1880. p->value);
  1881. ret = 0;
  1882. break;
  1883. case IW_AUTH_DROP_UNENCRYPTED:
  1884. devdbg(usbdev, "SIOCSIWAUTH: DROP_UNENCRYPTED, %08x", p->value);
  1885. ret = 0;
  1886. break;
  1887. case IW_AUTH_80211_AUTH_ALG:
  1888. devdbg(usbdev, "SIOCSIWAUTH: 80211_AUTH_ALG, %08x", p->value);
  1889. priv->wpa_authalg = p->value;
  1890. ret = 0;
  1891. break;
  1892. case IW_AUTH_WPA_ENABLED:
  1893. devdbg(usbdev, "SIOCSIWAUTH: WPA_ENABLED, %08x", p->value);
  1894. if (wrqu->param.value)
  1895. deauthenticate(usbdev);
  1896. ret = 0;
  1897. break;
  1898. case IW_AUTH_RX_UNENCRYPTED_EAPOL:
  1899. devdbg(usbdev, "SIOCSIWAUTH: RX_UNENCRYPTED_EAPOL, %08x",
  1900. p->value);
  1901. ret = 0;
  1902. break;
  1903. case IW_AUTH_ROAMING_CONTROL:
  1904. devdbg(usbdev, "SIOCSIWAUTH: ROAMING_CONTROL, %08x", p->value);
  1905. ret = 0;
  1906. break;
  1907. case IW_AUTH_PRIVACY_INVOKED:
  1908. devdbg(usbdev, "SIOCSIWAUTH: invalid cmd %d",
  1909. wrqu->param.flags & IW_AUTH_INDEX);
  1910. return -EOPNOTSUPP;
  1911. default:
  1912. devdbg(usbdev, "SIOCSIWAUTH: UNKNOWN %08x, %08x",
  1913. p->flags & IW_AUTH_INDEX, p->value);
  1914. }
  1915. return ret;
  1916. }
  1917. static int rndis_iw_get_auth(struct net_device *dev,
  1918. struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
  1919. {
  1920. struct iw_param *p = &wrqu->param;
  1921. struct usbnet *usbdev = netdev_priv(dev);
  1922. struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
  1923. switch (p->flags & IW_AUTH_INDEX) {
  1924. case IW_AUTH_WPA_VERSION:
  1925. p->value = priv->wpa_version;
  1926. break;
  1927. case IW_AUTH_CIPHER_PAIRWISE:
  1928. p->value = priv->wpa_cipher_pair;
  1929. break;
  1930. case IW_AUTH_CIPHER_GROUP:
  1931. p->value = priv->wpa_cipher_group;
  1932. break;
  1933. case IW_AUTH_KEY_MGMT:
  1934. p->value = priv->wpa_keymgmt;
  1935. break;
  1936. case IW_AUTH_80211_AUTH_ALG:
  1937. p->value = priv->wpa_authalg;
  1938. break;
  1939. default:
  1940. devdbg(usbdev, "SIOCGIWAUTH: invalid cmd %d",
  1941. wrqu->param.flags & IW_AUTH_INDEX);
  1942. return -EOPNOTSUPP;
  1943. }
  1944. return 0;
  1945. }
  1946. static int rndis_iw_set_encode(struct net_device *dev,
  1947. struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
  1948. {
  1949. struct usbnet *usbdev = netdev_priv(dev);
  1950. struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
  1951. struct rndis_wlan_encr_key key;
  1952. int ret, index, key_len;
  1953. u8 *keybuf;
  1954. index = (wrqu->encoding.flags & IW_ENCODE_INDEX);
  1955. /* iwconfig gives index as 1 - N */
  1956. if (index > 0)
  1957. index--;
  1958. else
  1959. index = priv->encr_tx_key_index;
  1960. if (index < 0 || index >= 4) {
  1961. devwarn(usbdev, "encryption index out of range (%u)", index);
  1962. return -EINVAL;
  1963. }
  1964. /* remove key if disabled */
  1965. if (wrqu->data.flags & IW_ENCODE_DISABLED) {
  1966. if (remove_key(usbdev, index, NULL))
  1967. return -EINVAL;
  1968. else
  1969. return 0;
  1970. }
  1971. /* global encryption state (for all keys) */
  1972. if (wrqu->data.flags & IW_ENCODE_OPEN)
  1973. ret = set_auth_mode(usbdev, 0, NL80211_AUTHTYPE_OPEN_SYSTEM,
  1974. RNDIS_WLAN_KEY_MGMT_NONE);
  1975. else /*if (wrqu->data.flags & IW_ENCODE_RESTRICTED)*/
  1976. ret = set_auth_mode(usbdev, 0, NL80211_AUTHTYPE_SHARED_KEY,
  1977. RNDIS_WLAN_KEY_MGMT_NONE);
  1978. if (ret != 0)
  1979. return ret;
  1980. if (wrqu->data.length > 0) {
  1981. key_len = wrqu->data.length;
  1982. keybuf = extra;
  1983. } else {
  1984. /* must be set as tx key */
  1985. if (priv->encr_keys[index].len == 0)
  1986. return -EINVAL;
  1987. key = priv->encr_keys[index];
  1988. key_len = key.len;
  1989. keybuf = key.material;
  1990. priv->encr_tx_key_index = index;
  1991. }
  1992. if (add_wep_key(usbdev, keybuf, key_len, index) != 0)
  1993. return -EINVAL;
  1994. if (index == priv->encr_tx_key_index)
  1995. /* ndis drivers want essid to be set after setting encr */
  1996. set_essid(usbdev, &priv->essid);
  1997. return 0;
  1998. }
  1999. static int rndis_iw_set_encode_ext(struct net_device *dev,
  2000. struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
  2001. {
  2002. struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
  2003. struct usbnet *usbdev = netdev_priv(dev);
  2004. struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
  2005. int keyidx, flags, cipher;
  2006. keyidx = wrqu->encoding.flags & IW_ENCODE_INDEX;
  2007. /* iwconfig gives index as 1 - N */
  2008. if (keyidx)
  2009. keyidx--;
  2010. else
  2011. keyidx = priv->encr_tx_key_index;
  2012. if (keyidx < 0 || keyidx >= 4) {
  2013. devwarn(usbdev, "encryption index out of range (%u)", keyidx);
  2014. return -EINVAL;
  2015. }
  2016. if (ext->alg == IW_ENCODE_ALG_WEP) {
  2017. if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)
  2018. priv->encr_tx_key_index = keyidx;
  2019. return add_wep_key(usbdev, ext->key, ext->key_len, keyidx);
  2020. }
  2021. cipher = -1;
  2022. if (ext->alg == IW_ENCODE_ALG_TKIP)
  2023. cipher = WLAN_CIPHER_SUITE_TKIP;
  2024. else if (ext->alg == IW_ENCODE_ALG_CCMP)
  2025. cipher = WLAN_CIPHER_SUITE_CCMP;
  2026. if ((wrqu->encoding.flags & IW_ENCODE_DISABLED) ||
  2027. ext->alg == IW_ENCODE_ALG_NONE || ext->key_len == 0)
  2028. return remove_key(usbdev, keyidx, NULL);
  2029. if (cipher == -1)
  2030. return -EOPNOTSUPP;
  2031. flags = 0;
  2032. if (ext->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID)
  2033. flags |= NDIS_80211_ADDKEY_SET_INIT_RECV_SEQ;
  2034. if (!(ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY))
  2035. flags |= NDIS_80211_ADDKEY_PAIRWISE_KEY;
  2036. if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)
  2037. flags |= NDIS_80211_ADDKEY_TRANSMIT_KEY;
  2038. return add_wpa_key(usbdev, ext->key, ext->key_len, keyidx,
  2039. (u8 *)&ext->addr.sa_data, ext->rx_seq, cipher,
  2040. flags);
  2041. }
  2042. static int rndis_iw_get_rate(struct net_device *dev,
  2043. struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
  2044. {
  2045. struct usbnet *usbdev = netdev_priv(dev);
  2046. __le32 tmp;
  2047. int ret, len;
  2048. len = sizeof(tmp);
  2049. ret = rndis_query_oid(usbdev, OID_GEN_LINK_SPEED, &tmp, &len);
  2050. if (ret == 0) {
  2051. wrqu->bitrate.value = le32_to_cpu(tmp) * 100;
  2052. wrqu->bitrate.disabled = 0;
  2053. wrqu->bitrate.flags = 1;
  2054. }
  2055. return ret;
  2056. }
  2057. static struct iw_statistics *rndis_get_wireless_stats(struct net_device *dev)
  2058. {
  2059. struct usbnet *usbdev = netdev_priv(dev);
  2060. struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
  2061. unsigned long flags;
  2062. spin_lock_irqsave(&priv->stats_lock, flags);
  2063. memcpy(&priv->iwstats, &priv->privstats, sizeof(priv->iwstats));
  2064. spin_unlock_irqrestore(&priv->stats_lock, flags);
  2065. return &priv->iwstats;
  2066. }
  2067. #endif
  2068. #define IW_IOCTL(x) [(x) - SIOCSIWCOMMIT]
  2069. static const iw_handler rndis_iw_handler[] =
  2070. {
  2071. IW_IOCTL(SIOCGIWNAME) = (iw_handler) cfg80211_wext_giwname,
  2072. IW_IOCTL(SIOCSIWFREQ) = (iw_handler) cfg80211_wext_siwfreq,
  2073. IW_IOCTL(SIOCGIWFREQ) = (iw_handler) cfg80211_wext_giwfreq,
  2074. IW_IOCTL(SIOCSIWMODE) = (iw_handler) cfg80211_wext_siwmode,
  2075. IW_IOCTL(SIOCGIWMODE) = (iw_handler) cfg80211_wext_giwmode,
  2076. IW_IOCTL(SIOCGIWRANGE) = (iw_handler) cfg80211_wext_giwrange,
  2077. IW_IOCTL(SIOCSIWAP) = (iw_handler) cfg80211_wext_siwap,
  2078. IW_IOCTL(SIOCGIWAP) = (iw_handler) cfg80211_wext_giwap,
  2079. IW_IOCTL(SIOCSIWSCAN) = (iw_handler) cfg80211_wext_siwscan,
  2080. IW_IOCTL(SIOCGIWSCAN) = (iw_handler) cfg80211_wext_giwscan,
  2081. IW_IOCTL(SIOCSIWESSID) = (iw_handler) cfg80211_wext_siwessid,
  2082. IW_IOCTL(SIOCGIWESSID) = (iw_handler) cfg80211_wext_giwessid,
  2083. IW_IOCTL(SIOCGIWRATE) = (iw_handler) cfg80211_wext_giwrate,
  2084. IW_IOCTL(SIOCSIWRTS) = (iw_handler) cfg80211_wext_siwrts,
  2085. IW_IOCTL(SIOCGIWRTS) = (iw_handler) cfg80211_wext_giwrts,
  2086. IW_IOCTL(SIOCSIWFRAG) = (iw_handler) cfg80211_wext_siwfrag,
  2087. IW_IOCTL(SIOCGIWFRAG) = (iw_handler) cfg80211_wext_giwfrag,
  2088. IW_IOCTL(SIOCSIWTXPOW) = (iw_handler) cfg80211_wext_siwtxpower,
  2089. IW_IOCTL(SIOCGIWTXPOW) = (iw_handler) cfg80211_wext_giwtxpower,
  2090. IW_IOCTL(SIOCSIWENCODE) = (iw_handler) cfg80211_wext_siwencode,
  2091. IW_IOCTL(SIOCSIWENCODEEXT) = (iw_handler) cfg80211_wext_siwencodeext,
  2092. IW_IOCTL(SIOCSIWAUTH) = (iw_handler) cfg80211_wext_siwauth,
  2093. IW_IOCTL(SIOCGIWAUTH) = (iw_handler) cfg80211_wext_giwauth,
  2094. IW_IOCTL(SIOCSIWGENIE) = (iw_handler) cfg80211_wext_siwgenie,
  2095. IW_IOCTL(SIOCSIWMLME) = (iw_handler) cfg80211_wext_siwmlme,
  2096. };
  2097. static const iw_handler rndis_wlan_private_handler[] = {
  2098. };
  2099. static const struct iw_priv_args rndis_wlan_private_args[] = {
  2100. };
  2101. static const struct iw_handler_def rndis_iw_handlers = {
  2102. .num_standard = ARRAY_SIZE(rndis_iw_handler),
  2103. .num_private = ARRAY_SIZE(rndis_wlan_private_handler),
  2104. .num_private_args = ARRAY_SIZE(rndis_wlan_private_args),
  2105. .standard = (iw_handler *)rndis_iw_handler,
  2106. .private = (iw_handler *)rndis_wlan_private_handler,
  2107. .private_args = (struct iw_priv_args *)rndis_wlan_private_args,
  2108. .get_wireless_stats = cfg80211_wireless_stats,
  2109. };
  2110. static void rndis_wlan_do_link_up_work(struct usbnet *usbdev)
  2111. {
  2112. struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
  2113. struct ndis_80211_assoc_info *info;
  2114. u8 assoc_buf[sizeof(*info) + IW_CUSTOM_MAX + 32];
  2115. u8 bssid[ETH_ALEN];
  2116. int resp_ie_len, req_ie_len;
  2117. u8 *req_ie, *resp_ie;
  2118. int ret, offset;
  2119. bool roamed = false;
  2120. if (priv->infra_mode == NDIS_80211_INFRA_INFRA && priv->connected) {
  2121. /* received media connect indication while connected, either
  2122. * device reassociated with same AP or roamed to new. */
  2123. roamed = true;
  2124. }
  2125. req_ie_len = 0;
  2126. resp_ie_len = 0;
  2127. req_ie = NULL;
  2128. resp_ie = NULL;
  2129. if (priv->infra_mode == NDIS_80211_INFRA_INFRA) {
  2130. memset(assoc_buf, 0, sizeof(assoc_buf));
  2131. info = (void *)assoc_buf;
  2132. /* Get association info IEs from device and send them back to
  2133. * userspace. */
  2134. ret = get_association_info(usbdev, info, sizeof(assoc_buf));
  2135. if (!ret) {
  2136. req_ie_len = le32_to_cpu(info->req_ie_length);
  2137. if (req_ie_len > 0) {
  2138. offset = le32_to_cpu(info->offset_req_ies);
  2139. req_ie = (u8 *)info + offset;
  2140. }
  2141. resp_ie_len = le32_to_cpu(info->resp_ie_length);
  2142. if (resp_ie_len > 0) {
  2143. offset = le32_to_cpu(info->offset_resp_ies);
  2144. resp_ie = (u8 *)info + offset;
  2145. }
  2146. }
  2147. } else if (WARN_ON(priv->infra_mode != NDIS_80211_INFRA_ADHOC))
  2148. return;
  2149. ret = get_bssid(usbdev, bssid);
  2150. if (ret < 0)
  2151. memset(bssid, 0, sizeof(bssid));
  2152. devdbg(usbdev, "link up work: [%pM] %s", bssid, roamed ? "roamed" : "");
  2153. /* Internal bss list in device always contains at least the currently
  2154. * connected bss and we can get it to cfg80211 with
  2155. * rndis_check_bssid_list().
  2156. * NOTE: This is true for Broadcom chip, but not mentioned in RNDIS
  2157. * spec.
  2158. */
  2159. rndis_check_bssid_list(usbdev);
  2160. if (priv->infra_mode == NDIS_80211_INFRA_INFRA) {
  2161. if (!roamed)
  2162. cfg80211_connect_result(usbdev->net, bssid, req_ie,
  2163. req_ie_len, resp_ie,
  2164. resp_ie_len, 0, GFP_KERNEL);
  2165. else
  2166. cfg80211_roamed(usbdev->net, bssid, req_ie, req_ie_len,
  2167. resp_ie, resp_ie_len, GFP_KERNEL);
  2168. } else if (priv->infra_mode == NDIS_80211_INFRA_ADHOC)
  2169. cfg80211_ibss_joined(usbdev->net, bssid, GFP_KERNEL);
  2170. priv->connected = true;
  2171. memcpy(priv->bssid, bssid, ETH_ALEN);
  2172. usbnet_resume_rx(usbdev);
  2173. netif_carrier_on(usbdev->net);
  2174. }
  2175. static void rndis_wlan_do_link_down_work(struct usbnet *usbdev)
  2176. {
  2177. union iwreq_data evt;
  2178. netif_carrier_off(usbdev->net);
  2179. evt.data.flags = 0;
  2180. evt.data.length = 0;
  2181. memset(evt.ap_addr.sa_data, 0, ETH_ALEN);
  2182. wireless_send_event(usbdev->net, SIOCGIWAP, &evt, NULL);
  2183. }
  2184. static void rndis_wlan_worker(struct work_struct *work)
  2185. {
  2186. struct rndis_wlan_private *priv =
  2187. container_of(work, struct rndis_wlan_private, work);
  2188. struct usbnet *usbdev = priv->usbdev;
  2189. if (test_and_clear_bit(WORK_LINK_UP, &priv->work_pending))
  2190. rndis_wlan_do_link_up_work(usbdev);
  2191. if (test_and_clear_bit(WORK_LINK_DOWN, &priv->work_pending))
  2192. rndis_wlan_do_link_down_work(usbdev);
  2193. if (test_and_clear_bit(WORK_SET_MULTICAST_LIST, &priv->work_pending))
  2194. set_multicast_list(usbdev);
  2195. }
  2196. static void rndis_wlan_set_multicast_list(struct net_device *dev)
  2197. {
  2198. struct usbnet *usbdev = netdev_priv(dev);
  2199. struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
  2200. if (test_bit(WORK_SET_MULTICAST_LIST, &priv->work_pending))
  2201. return;
  2202. set_bit(WORK_SET_MULTICAST_LIST, &priv->work_pending);
  2203. queue_work(priv->workqueue, &priv->work);
  2204. }
  2205. static void rndis_wlan_auth_indication(struct usbnet *usbdev,
  2206. struct ndis_80211_status_indication *indication,
  2207. int len)
  2208. {
  2209. u8 *buf;
  2210. const char *type;
  2211. int flags, buflen;
  2212. bool pairwise_error, group_error;
  2213. struct ndis_80211_auth_request *auth_req;
  2214. /* must have at least one array entry */
  2215. if (len < offsetof(struct ndis_80211_status_indication, u) +
  2216. sizeof(struct ndis_80211_auth_request)) {
  2217. devinfo(usbdev, "authentication indication: "
  2218. "too short message (%i)", len);
  2219. return;
  2220. }
  2221. buf = (void *)&indication->u.auth_request[0];
  2222. buflen = len - offsetof(struct ndis_80211_status_indication, u);
  2223. while (buflen >= sizeof(*auth_req)) {
  2224. auth_req = (void *)buf;
  2225. type = "unknown";
  2226. flags = le32_to_cpu(auth_req->flags);
  2227. pairwise_error = false;
  2228. group_error = false;
  2229. if (flags & 0x1)
  2230. type = "reauth request";
  2231. if (flags & 0x2)
  2232. type = "key update request";
  2233. if (flags & 0x6) {
  2234. pairwise_error = true;
  2235. type = "pairwise_error";
  2236. }
  2237. if (flags & 0xe) {
  2238. group_error = true;
  2239. type = "group_error";
  2240. }
  2241. devinfo(usbdev, "authentication indication: %s (0x%08x)", type,
  2242. le32_to_cpu(auth_req->flags));
  2243. if (pairwise_error || group_error) {
  2244. union iwreq_data wrqu;
  2245. struct iw_michaelmicfailure micfailure;
  2246. memset(&micfailure, 0, sizeof(micfailure));
  2247. if (pairwise_error)
  2248. micfailure.flags |= IW_MICFAILURE_PAIRWISE;
  2249. if (group_error)
  2250. micfailure.flags |= IW_MICFAILURE_GROUP;
  2251. memcpy(micfailure.src_addr.sa_data, auth_req->bssid,
  2252. ETH_ALEN);
  2253. memset(&wrqu, 0, sizeof(wrqu));
  2254. wrqu.data.length = sizeof(micfailure);
  2255. wireless_send_event(usbdev->net, IWEVMICHAELMICFAILURE,
  2256. &wrqu, (u8 *)&micfailure);
  2257. }
  2258. buflen -= le32_to_cpu(auth_req->length);
  2259. buf += le32_to_cpu(auth_req->length);
  2260. }
  2261. }
  2262. static void rndis_wlan_pmkid_cand_list_indication(struct usbnet *usbdev,
  2263. struct ndis_80211_status_indication *indication,
  2264. int len)
  2265. {
  2266. struct ndis_80211_pmkid_cand_list *cand_list;
  2267. int list_len, expected_len, i;
  2268. if (len < offsetof(struct ndis_80211_status_indication, u) +
  2269. sizeof(struct ndis_80211_pmkid_cand_list)) {
  2270. devinfo(usbdev, "pmkid candidate list indication: "
  2271. "too short message (%i)", len);
  2272. return;
  2273. }
  2274. list_len = le32_to_cpu(indication->u.cand_list.num_candidates) *
  2275. sizeof(struct ndis_80211_pmkid_candidate);
  2276. expected_len = sizeof(struct ndis_80211_pmkid_cand_list) + list_len +
  2277. offsetof(struct ndis_80211_status_indication, u);
  2278. if (len < expected_len) {
  2279. devinfo(usbdev, "pmkid candidate list indication: "
  2280. "list larger than buffer (%i < %i)",
  2281. len, expected_len);
  2282. return;
  2283. }
  2284. cand_list = &indication->u.cand_list;
  2285. devinfo(usbdev, "pmkid candidate list indication: "
  2286. "version %i, candidates %i",
  2287. le32_to_cpu(cand_list->version),
  2288. le32_to_cpu(cand_list->num_candidates));
  2289. if (le32_to_cpu(cand_list->version) != 1)
  2290. return;
  2291. for (i = 0; i < le32_to_cpu(cand_list->num_candidates); i++) {
  2292. struct iw_pmkid_cand pcand;
  2293. union iwreq_data wrqu;
  2294. struct ndis_80211_pmkid_candidate *cand =
  2295. &cand_list->candidate_list[i];
  2296. devdbg(usbdev, "cand[%i]: flags: 0x%08x, bssid: %pM",
  2297. i, le32_to_cpu(cand->flags), cand->bssid);
  2298. memset(&pcand, 0, sizeof(pcand));
  2299. if (le32_to_cpu(cand->flags) & 0x01)
  2300. pcand.flags |= IW_PMKID_CAND_PREAUTH;
  2301. pcand.index = i;
  2302. memcpy(pcand.bssid.sa_data, cand->bssid, ETH_ALEN);
  2303. memset(&wrqu, 0, sizeof(wrqu));
  2304. wrqu.data.length = sizeof(pcand);
  2305. wireless_send_event(usbdev->net, IWEVPMKIDCAND, &wrqu,
  2306. (u8 *)&pcand);
  2307. }
  2308. }
  2309. static void rndis_wlan_media_specific_indication(struct usbnet *usbdev,
  2310. struct rndis_indicate *msg, int buflen)
  2311. {
  2312. struct ndis_80211_status_indication *indication;
  2313. int len, offset;
  2314. offset = offsetof(struct rndis_indicate, status) +
  2315. le32_to_cpu(msg->offset);
  2316. len = le32_to_cpu(msg->length);
  2317. if (len < 8) {
  2318. devinfo(usbdev, "media specific indication, "
  2319. "ignore too short message (%i < 8)", len);
  2320. return;
  2321. }
  2322. if (offset + len > buflen) {
  2323. devinfo(usbdev, "media specific indication, "
  2324. "too large to fit to buffer (%i > %i)",
  2325. offset + len, buflen);
  2326. return;
  2327. }
  2328. indication = (void *)((u8 *)msg + offset);
  2329. switch (le32_to_cpu(indication->status_type)) {
  2330. case NDIS_80211_STATUSTYPE_RADIOSTATE:
  2331. devinfo(usbdev, "radio state indication: %i",
  2332. le32_to_cpu(indication->u.radio_status));
  2333. return;
  2334. case NDIS_80211_STATUSTYPE_MEDIASTREAMMODE:
  2335. devinfo(usbdev, "media stream mode indication: %i",
  2336. le32_to_cpu(indication->u.media_stream_mode));
  2337. return;
  2338. case NDIS_80211_STATUSTYPE_AUTHENTICATION:
  2339. rndis_wlan_auth_indication(usbdev, indication, len);
  2340. return;
  2341. case NDIS_80211_STATUSTYPE_PMKID_CANDIDATELIST:
  2342. rndis_wlan_pmkid_cand_list_indication(usbdev, indication, len);
  2343. return;
  2344. default:
  2345. devinfo(usbdev, "media specific indication: "
  2346. "unknown status type 0x%08x",
  2347. le32_to_cpu(indication->status_type));
  2348. }
  2349. }
  2350. static void rndis_wlan_indication(struct usbnet *usbdev, void *ind, int buflen)
  2351. {
  2352. struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
  2353. struct rndis_indicate *msg = ind;
  2354. switch (msg->status) {
  2355. case RNDIS_STATUS_MEDIA_CONNECT:
  2356. if (priv->current_command_oid == OID_802_11_ADD_KEY) {
  2357. /* OID_802_11_ADD_KEY causes sometimes extra
  2358. * "media connect" indications which confuses driver
  2359. * and userspace to think that device is
  2360. * roaming/reassociating when it isn't.
  2361. */
  2362. devdbg(usbdev, "ignored OID_802_11_ADD_KEY triggered "
  2363. "'media connect'");
  2364. return;
  2365. }
  2366. usbnet_pause_rx(usbdev);
  2367. devinfo(usbdev, "media connect");
  2368. /* queue work to avoid recursive calls into rndis_command */
  2369. set_bit(WORK_LINK_UP, &priv->work_pending);
  2370. queue_work(priv->workqueue, &priv->work);
  2371. break;
  2372. case RNDIS_STATUS_MEDIA_DISCONNECT:
  2373. devinfo(usbdev, "media disconnect");
  2374. /* queue work to avoid recursive calls into rndis_command */
  2375. set_bit(WORK_LINK_DOWN, &priv->work_pending);
  2376. queue_work(priv->workqueue, &priv->work);
  2377. break;
  2378. case RNDIS_STATUS_MEDIA_SPECIFIC_INDICATION:
  2379. rndis_wlan_media_specific_indication(usbdev, msg, buflen);
  2380. break;
  2381. default:
  2382. devinfo(usbdev, "indication: 0x%08x",
  2383. le32_to_cpu(msg->status));
  2384. break;
  2385. }
  2386. }
  2387. static int rndis_wlan_get_caps(struct usbnet *usbdev)
  2388. {
  2389. struct {
  2390. __le32 num_items;
  2391. __le32 items[8];
  2392. } networks_supported;
  2393. int len, retval, i, n;
  2394. struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
  2395. /* determine supported modes */
  2396. len = sizeof(networks_supported);
  2397. retval = rndis_query_oid(usbdev, OID_802_11_NETWORK_TYPES_SUPPORTED,
  2398. &networks_supported, &len);
  2399. if (retval >= 0) {
  2400. n = le32_to_cpu(networks_supported.num_items);
  2401. if (n > 8)
  2402. n = 8;
  2403. for (i = 0; i < n; i++) {
  2404. switch (le32_to_cpu(networks_supported.items[i])) {
  2405. case NDIS_80211_TYPE_FREQ_HOP:
  2406. case NDIS_80211_TYPE_DIRECT_SEQ:
  2407. priv->caps |= CAP_MODE_80211B;
  2408. break;
  2409. case NDIS_80211_TYPE_OFDM_A:
  2410. priv->caps |= CAP_MODE_80211A;
  2411. break;
  2412. case NDIS_80211_TYPE_OFDM_G:
  2413. priv->caps |= CAP_MODE_80211G;
  2414. break;
  2415. }
  2416. }
  2417. }
  2418. return retval;
  2419. }
  2420. #define DEVICE_POLLER_JIFFIES (HZ)
  2421. static void rndis_device_poller(struct work_struct *work)
  2422. {
  2423. struct rndis_wlan_private *priv =
  2424. container_of(work, struct rndis_wlan_private,
  2425. dev_poller_work.work);
  2426. struct usbnet *usbdev = priv->usbdev;
  2427. __le32 rssi, tmp;
  2428. int len, ret, j;
  2429. int update_jiffies = DEVICE_POLLER_JIFFIES;
  2430. void *buf;
  2431. /* Only check/do workaround when connected. Calling is_associated()
  2432. * also polls device with rndis_command() and catches for media link
  2433. * indications.
  2434. */
  2435. if (!is_associated(usbdev))
  2436. goto end;
  2437. len = sizeof(rssi);
  2438. ret = rndis_query_oid(usbdev, OID_802_11_RSSI, &rssi, &len);
  2439. if (ret == 0)
  2440. priv->last_qual = level_to_qual(le32_to_cpu(rssi));
  2441. devdbg(usbdev, "dev-poller: OID_802_11_RSSI -> %d, rssi:%d, qual: %d",
  2442. ret, le32_to_cpu(rssi), level_to_qual(le32_to_cpu(rssi)));
  2443. /* Workaround transfer stalls on poor quality links.
  2444. * TODO: find right way to fix these stalls (as stalls do not happen
  2445. * with ndiswrapper/windows driver). */
  2446. if (priv->last_qual <= 25) {
  2447. /* Decrease stats worker interval to catch stalls.
  2448. * faster. Faster than 400-500ms causes packet loss,
  2449. * Slower doesn't catch stalls fast enough.
  2450. */
  2451. j = msecs_to_jiffies(priv->param_workaround_interval);
  2452. if (j > DEVICE_POLLER_JIFFIES)
  2453. j = DEVICE_POLLER_JIFFIES;
  2454. else if (j <= 0)
  2455. j = 1;
  2456. update_jiffies = j;
  2457. /* Send scan OID. Use of both OIDs is required to get device
  2458. * working.
  2459. */
  2460. tmp = cpu_to_le32(1);
  2461. rndis_set_oid(usbdev, OID_802_11_BSSID_LIST_SCAN, &tmp,
  2462. sizeof(tmp));
  2463. len = CONTROL_BUFFER_SIZE;
  2464. buf = kmalloc(len, GFP_KERNEL);
  2465. if (!buf)
  2466. goto end;
  2467. rndis_query_oid(usbdev, OID_802_11_BSSID_LIST, buf, &len);
  2468. kfree(buf);
  2469. }
  2470. end:
  2471. if (update_jiffies >= HZ)
  2472. update_jiffies = round_jiffies_relative(update_jiffies);
  2473. else {
  2474. j = round_jiffies_relative(update_jiffies);
  2475. if (abs(j - update_jiffies) <= 10)
  2476. update_jiffies = j;
  2477. }
  2478. queue_delayed_work(priv->workqueue, &priv->dev_poller_work,
  2479. update_jiffies);
  2480. }
  2481. static int bcm4320a_early_init(struct usbnet *usbdev)
  2482. {
  2483. /* bcm4320a doesn't handle configuration parameters well. Try
  2484. * set any and you get partially zeroed mac and broken device.
  2485. */
  2486. return 0;
  2487. }
  2488. static int bcm4320b_early_init(struct usbnet *usbdev)
  2489. {
  2490. struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
  2491. char buf[8];
  2492. /* Early initialization settings, setting these won't have effect
  2493. * if called after generic_rndis_bind().
  2494. */
  2495. priv->param_country[0] = modparam_country[0];
  2496. priv->param_country[1] = modparam_country[1];
  2497. priv->param_country[2] = 0;
  2498. priv->param_frameburst = modparam_frameburst;
  2499. priv->param_afterburner = modparam_afterburner;
  2500. priv->param_power_save = modparam_power_save;
  2501. priv->param_power_output = modparam_power_output;
  2502. priv->param_roamtrigger = modparam_roamtrigger;
  2503. priv->param_roamdelta = modparam_roamdelta;
  2504. priv->param_country[0] = toupper(priv->param_country[0]);
  2505. priv->param_country[1] = toupper(priv->param_country[1]);
  2506. /* doesn't support EU as country code, use FI instead */
  2507. if (!strcmp(priv->param_country, "EU"))
  2508. strcpy(priv->param_country, "FI");
  2509. if (priv->param_power_save < 0)
  2510. priv->param_power_save = 0;
  2511. else if (priv->param_power_save > 2)
  2512. priv->param_power_save = 2;
  2513. if (priv->param_power_output < 0)
  2514. priv->param_power_output = 0;
  2515. else if (priv->param_power_output > 3)
  2516. priv->param_power_output = 3;
  2517. if (priv->param_roamtrigger < -80)
  2518. priv->param_roamtrigger = -80;
  2519. else if (priv->param_roamtrigger > -60)
  2520. priv->param_roamtrigger = -60;
  2521. if (priv->param_roamdelta < 0)
  2522. priv->param_roamdelta = 0;
  2523. else if (priv->param_roamdelta > 2)
  2524. priv->param_roamdelta = 2;
  2525. if (modparam_workaround_interval < 0)
  2526. priv->param_workaround_interval = 500;
  2527. else
  2528. priv->param_workaround_interval = modparam_workaround_interval;
  2529. rndis_set_config_parameter_str(usbdev, "Country", priv->param_country);
  2530. rndis_set_config_parameter_str(usbdev, "FrameBursting",
  2531. priv->param_frameburst ? "1" : "0");
  2532. rndis_set_config_parameter_str(usbdev, "Afterburner",
  2533. priv->param_afterburner ? "1" : "0");
  2534. sprintf(buf, "%d", priv->param_power_save);
  2535. rndis_set_config_parameter_str(usbdev, "PowerSaveMode", buf);
  2536. sprintf(buf, "%d", priv->param_power_output);
  2537. rndis_set_config_parameter_str(usbdev, "PwrOut", buf);
  2538. sprintf(buf, "%d", priv->param_roamtrigger);
  2539. rndis_set_config_parameter_str(usbdev, "RoamTrigger", buf);
  2540. sprintf(buf, "%d", priv->param_roamdelta);
  2541. rndis_set_config_parameter_str(usbdev, "RoamDelta", buf);
  2542. return 0;
  2543. }
  2544. /* same as rndis_netdev_ops but with local multicast handler */
  2545. static const struct net_device_ops rndis_wlan_netdev_ops = {
  2546. .ndo_open = usbnet_open,
  2547. .ndo_stop = usbnet_stop,
  2548. .ndo_start_xmit = usbnet_start_xmit,
  2549. .ndo_tx_timeout = usbnet_tx_timeout,
  2550. .ndo_set_mac_address = eth_mac_addr,
  2551. .ndo_validate_addr = eth_validate_addr,
  2552. .ndo_set_multicast_list = rndis_wlan_set_multicast_list,
  2553. };
  2554. static int rndis_wlan_bind(struct usbnet *usbdev, struct usb_interface *intf)
  2555. {
  2556. struct wiphy *wiphy;
  2557. struct rndis_wlan_private *priv;
  2558. int retval, len;
  2559. __le32 tmp;
  2560. /* allocate wiphy and rndis private data
  2561. * NOTE: We only support a single virtual interface, so wiphy
  2562. * and wireless_dev are somewhat synonymous for this device.
  2563. */
  2564. wiphy = wiphy_new(&rndis_config_ops, sizeof(struct rndis_wlan_private));
  2565. if (!wiphy)
  2566. return -ENOMEM;
  2567. priv = wiphy_priv(wiphy);
  2568. usbdev->net->ieee80211_ptr = &priv->wdev;
  2569. priv->wdev.wiphy = wiphy;
  2570. priv->wdev.iftype = NL80211_IFTYPE_STATION;
  2571. /* These have to be initialized before calling generic_rndis_bind().
  2572. * Otherwise we'll be in big trouble in rndis_wlan_early_init().
  2573. */
  2574. usbdev->driver_priv = priv;
  2575. usbdev->net->wireless_handlers = &rndis_iw_handlers;
  2576. priv->usbdev = usbdev;
  2577. mutex_init(&priv->command_lock);
  2578. /* because rndis_command() sleeps we need to use workqueue */
  2579. priv->workqueue = create_singlethread_workqueue("rndis_wlan");
  2580. INIT_WORK(&priv->work, rndis_wlan_worker);
  2581. INIT_DELAYED_WORK(&priv->dev_poller_work, rndis_device_poller);
  2582. INIT_DELAYED_WORK(&priv->scan_work, rndis_get_scan_results);
  2583. /* try bind rndis_host */
  2584. retval = generic_rndis_bind(usbdev, intf, FLAG_RNDIS_PHYM_WIRELESS);
  2585. if (retval < 0)
  2586. goto fail;
  2587. /* generic_rndis_bind set packet filter to multicast_all+
  2588. * promisc mode which doesn't work well for our devices (device
  2589. * picks up rssi to closest station instead of to access point).
  2590. *
  2591. * rndis_host wants to avoid all OID as much as possible
  2592. * so do promisc/multicast handling in rndis_wlan.
  2593. */
  2594. usbdev->net->netdev_ops = &rndis_wlan_netdev_ops;
  2595. tmp = RNDIS_PACKET_TYPE_DIRECTED | RNDIS_PACKET_TYPE_BROADCAST;
  2596. retval = rndis_set_oid(usbdev, OID_GEN_CURRENT_PACKET_FILTER, &tmp,
  2597. sizeof(tmp));
  2598. len = sizeof(tmp);
  2599. retval = rndis_query_oid(usbdev, OID_802_3_MAXIMUM_LIST_SIZE, &tmp,
  2600. &len);
  2601. priv->multicast_size = le32_to_cpu(tmp);
  2602. if (retval < 0 || priv->multicast_size < 0)
  2603. priv->multicast_size = 0;
  2604. if (priv->multicast_size > 0)
  2605. usbdev->net->flags |= IFF_MULTICAST;
  2606. else
  2607. usbdev->net->flags &= ~IFF_MULTICAST;
  2608. /* fill-out wiphy structure and register w/ cfg80211 */
  2609. memcpy(wiphy->perm_addr, usbdev->net->dev_addr, ETH_ALEN);
  2610. wiphy->privid = rndis_wiphy_privid;
  2611. wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION)
  2612. | BIT(NL80211_IFTYPE_ADHOC);
  2613. wiphy->max_scan_ssids = 1;
  2614. /* TODO: fill-out band/encr information based on priv->caps */
  2615. rndis_wlan_get_caps(usbdev);
  2616. memcpy(priv->channels, rndis_channels, sizeof(rndis_channels));
  2617. memcpy(priv->rates, rndis_rates, sizeof(rndis_rates));
  2618. priv->band.channels = priv->channels;
  2619. priv->band.n_channels = ARRAY_SIZE(rndis_channels);
  2620. priv->band.bitrates = priv->rates;
  2621. priv->band.n_bitrates = ARRAY_SIZE(rndis_rates);
  2622. wiphy->bands[IEEE80211_BAND_2GHZ] = &priv->band;
  2623. wiphy->signal_type = CFG80211_SIGNAL_TYPE_UNSPEC;
  2624. memcpy(priv->cipher_suites, rndis_cipher_suites,
  2625. sizeof(rndis_cipher_suites));
  2626. wiphy->cipher_suites = priv->cipher_suites;
  2627. wiphy->n_cipher_suites = ARRAY_SIZE(rndis_cipher_suites);
  2628. set_wiphy_dev(wiphy, &usbdev->udev->dev);
  2629. if (wiphy_register(wiphy)) {
  2630. retval = -ENODEV;
  2631. goto fail;
  2632. }
  2633. set_default_iw_params(usbdev);
  2634. /* set default rts/frag */
  2635. rndis_set_wiphy_params(wiphy,
  2636. WIPHY_PARAM_FRAG_THRESHOLD | WIPHY_PARAM_RTS_THRESHOLD);
  2637. /* turn radio on */
  2638. priv->radio_on = 1;
  2639. disassociate(usbdev, 1);
  2640. netif_carrier_off(usbdev->net);
  2641. return 0;
  2642. fail:
  2643. cancel_delayed_work_sync(&priv->dev_poller_work);
  2644. cancel_delayed_work_sync(&priv->scan_work);
  2645. cancel_work_sync(&priv->work);
  2646. flush_workqueue(priv->workqueue);
  2647. destroy_workqueue(priv->workqueue);
  2648. wiphy_free(wiphy);
  2649. return retval;
  2650. }
  2651. static void rndis_wlan_unbind(struct usbnet *usbdev, struct usb_interface *intf)
  2652. {
  2653. struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
  2654. /* turn radio off */
  2655. disassociate(usbdev, 0);
  2656. cancel_delayed_work_sync(&priv->dev_poller_work);
  2657. cancel_delayed_work_sync(&priv->scan_work);
  2658. cancel_work_sync(&priv->work);
  2659. flush_workqueue(priv->workqueue);
  2660. destroy_workqueue(priv->workqueue);
  2661. if (priv && priv->wpa_ie_len)
  2662. kfree(priv->wpa_ie);
  2663. rndis_unbind(usbdev, intf);
  2664. wiphy_unregister(priv->wdev.wiphy);
  2665. wiphy_free(priv->wdev.wiphy);
  2666. }
  2667. static int rndis_wlan_reset(struct usbnet *usbdev)
  2668. {
  2669. struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
  2670. int retval;
  2671. devdbg(usbdev, "rndis_wlan_reset");
  2672. retval = rndis_reset(usbdev);
  2673. if (retval)
  2674. devwarn(usbdev, "rndis_reset() failed: %d", retval);
  2675. /* rndis_reset cleared multicast list, so restore here.
  2676. (set_multicast_list() also turns on current packet filter) */
  2677. set_multicast_list(usbdev);
  2678. queue_delayed_work(priv->workqueue, &priv->dev_poller_work,
  2679. round_jiffies_relative(DEVICE_POLLER_JIFFIES));
  2680. return deauthenticate(usbdev);
  2681. }
  2682. static int rndis_wlan_stop(struct usbnet *usbdev)
  2683. {
  2684. struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
  2685. int retval;
  2686. __le32 filter;
  2687. devdbg(usbdev, "rndis_wlan_stop");
  2688. retval = disassociate(usbdev, 0);
  2689. priv->work_pending = 0;
  2690. cancel_delayed_work_sync(&priv->dev_poller_work);
  2691. cancel_delayed_work_sync(&priv->scan_work);
  2692. cancel_work_sync(&priv->work);
  2693. flush_workqueue(priv->workqueue);
  2694. if (priv->scan_request) {
  2695. cfg80211_scan_done(priv->scan_request, true);
  2696. priv->scan_request = NULL;
  2697. }
  2698. /* Set current packet filter zero to block receiving data packets from
  2699. device. */
  2700. filter = 0;
  2701. rndis_set_oid(usbdev, OID_GEN_CURRENT_PACKET_FILTER, &filter,
  2702. sizeof(filter));
  2703. return retval;
  2704. }
  2705. static const struct driver_info bcm4320b_info = {
  2706. .description = "Wireless RNDIS device, BCM4320b based",
  2707. .flags = FLAG_WLAN | FLAG_FRAMING_RN | FLAG_NO_SETINT |
  2708. FLAG_AVOID_UNLINK_URBS,
  2709. .bind = rndis_wlan_bind,
  2710. .unbind = rndis_wlan_unbind,
  2711. .status = rndis_status,
  2712. .rx_fixup = rndis_rx_fixup,
  2713. .tx_fixup = rndis_tx_fixup,
  2714. .reset = rndis_wlan_reset,
  2715. .stop = rndis_wlan_stop,
  2716. .early_init = bcm4320b_early_init,
  2717. .indication = rndis_wlan_indication,
  2718. };
  2719. static const struct driver_info bcm4320a_info = {
  2720. .description = "Wireless RNDIS device, BCM4320a based",
  2721. .flags = FLAG_WLAN | FLAG_FRAMING_RN | FLAG_NO_SETINT |
  2722. FLAG_AVOID_UNLINK_URBS,
  2723. .bind = rndis_wlan_bind,
  2724. .unbind = rndis_wlan_unbind,
  2725. .status = rndis_status,
  2726. .rx_fixup = rndis_rx_fixup,
  2727. .tx_fixup = rndis_tx_fixup,
  2728. .reset = rndis_wlan_reset,
  2729. .stop = rndis_wlan_stop,
  2730. .early_init = bcm4320a_early_init,
  2731. .indication = rndis_wlan_indication,
  2732. };
  2733. static const struct driver_info rndis_wlan_info = {
  2734. .description = "Wireless RNDIS device",
  2735. .flags = FLAG_WLAN | FLAG_FRAMING_RN | FLAG_NO_SETINT |
  2736. FLAG_AVOID_UNLINK_URBS,
  2737. .bind = rndis_wlan_bind,
  2738. .unbind = rndis_wlan_unbind,
  2739. .status = rndis_status,
  2740. .rx_fixup = rndis_rx_fixup,
  2741. .tx_fixup = rndis_tx_fixup,
  2742. .reset = rndis_wlan_reset,
  2743. .stop = rndis_wlan_stop,
  2744. .early_init = bcm4320a_early_init,
  2745. .indication = rndis_wlan_indication,
  2746. };
  2747. /*-------------------------------------------------------------------------*/
  2748. static const struct usb_device_id products [] = {
  2749. #define RNDIS_MASTER_INTERFACE \
  2750. .bInterfaceClass = USB_CLASS_COMM, \
  2751. .bInterfaceSubClass = 2 /* ACM */, \
  2752. .bInterfaceProtocol = 0x0ff
  2753. /* INF driver for these devices have DriverVer >= 4.xx.xx.xx and many custom
  2754. * parameters available. Chipset marked as 'BCM4320SKFBG' in NDISwrapper-wiki.
  2755. */
  2756. {
  2757. .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
  2758. | USB_DEVICE_ID_MATCH_DEVICE,
  2759. .idVendor = 0x0411,
  2760. .idProduct = 0x00bc, /* Buffalo WLI-U2-KG125S */
  2761. RNDIS_MASTER_INTERFACE,
  2762. .driver_info = (unsigned long) &bcm4320b_info,
  2763. }, {
  2764. .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
  2765. | USB_DEVICE_ID_MATCH_DEVICE,
  2766. .idVendor = 0x0baf,
  2767. .idProduct = 0x011b, /* U.S. Robotics USR5421 */
  2768. RNDIS_MASTER_INTERFACE,
  2769. .driver_info = (unsigned long) &bcm4320b_info,
  2770. }, {
  2771. .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
  2772. | USB_DEVICE_ID_MATCH_DEVICE,
  2773. .idVendor = 0x050d,
  2774. .idProduct = 0x011b, /* Belkin F5D7051 */
  2775. RNDIS_MASTER_INTERFACE,
  2776. .driver_info = (unsigned long) &bcm4320b_info,
  2777. }, {
  2778. .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
  2779. | USB_DEVICE_ID_MATCH_DEVICE,
  2780. .idVendor = 0x1799, /* Belkin has two vendor ids */
  2781. .idProduct = 0x011b, /* Belkin F5D7051 */
  2782. RNDIS_MASTER_INTERFACE,
  2783. .driver_info = (unsigned long) &bcm4320b_info,
  2784. }, {
  2785. .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
  2786. | USB_DEVICE_ID_MATCH_DEVICE,
  2787. .idVendor = 0x13b1,
  2788. .idProduct = 0x0014, /* Linksys WUSB54GSv2 */
  2789. RNDIS_MASTER_INTERFACE,
  2790. .driver_info = (unsigned long) &bcm4320b_info,
  2791. }, {
  2792. .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
  2793. | USB_DEVICE_ID_MATCH_DEVICE,
  2794. .idVendor = 0x13b1,
  2795. .idProduct = 0x0026, /* Linksys WUSB54GSC */
  2796. RNDIS_MASTER_INTERFACE,
  2797. .driver_info = (unsigned long) &bcm4320b_info,
  2798. }, {
  2799. .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
  2800. | USB_DEVICE_ID_MATCH_DEVICE,
  2801. .idVendor = 0x0b05,
  2802. .idProduct = 0x1717, /* Asus WL169gE */
  2803. RNDIS_MASTER_INTERFACE,
  2804. .driver_info = (unsigned long) &bcm4320b_info,
  2805. }, {
  2806. .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
  2807. | USB_DEVICE_ID_MATCH_DEVICE,
  2808. .idVendor = 0x0a5c,
  2809. .idProduct = 0xd11b, /* Eminent EM4045 */
  2810. RNDIS_MASTER_INTERFACE,
  2811. .driver_info = (unsigned long) &bcm4320b_info,
  2812. }, {
  2813. .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
  2814. | USB_DEVICE_ID_MATCH_DEVICE,
  2815. .idVendor = 0x1690,
  2816. .idProduct = 0x0715, /* BT Voyager 1055 */
  2817. RNDIS_MASTER_INTERFACE,
  2818. .driver_info = (unsigned long) &bcm4320b_info,
  2819. },
  2820. /* These devices have DriverVer < 4.xx.xx.xx and do not have any custom
  2821. * parameters available, hardware probably contain older firmware version with
  2822. * no way of updating. Chipset marked as 'BCM4320????' in NDISwrapper-wiki.
  2823. */
  2824. {
  2825. .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
  2826. | USB_DEVICE_ID_MATCH_DEVICE,
  2827. .idVendor = 0x13b1,
  2828. .idProduct = 0x000e, /* Linksys WUSB54GSv1 */
  2829. RNDIS_MASTER_INTERFACE,
  2830. .driver_info = (unsigned long) &bcm4320a_info,
  2831. }, {
  2832. .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
  2833. | USB_DEVICE_ID_MATCH_DEVICE,
  2834. .idVendor = 0x0baf,
  2835. .idProduct = 0x0111, /* U.S. Robotics USR5420 */
  2836. RNDIS_MASTER_INTERFACE,
  2837. .driver_info = (unsigned long) &bcm4320a_info,
  2838. }, {
  2839. .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
  2840. | USB_DEVICE_ID_MATCH_DEVICE,
  2841. .idVendor = 0x0411,
  2842. .idProduct = 0x004b, /* BUFFALO WLI-USB-G54 */
  2843. RNDIS_MASTER_INTERFACE,
  2844. .driver_info = (unsigned long) &bcm4320a_info,
  2845. },
  2846. /* Generic Wireless RNDIS devices that we don't have exact
  2847. * idVendor/idProduct/chip yet.
  2848. */
  2849. {
  2850. /* RNDIS is MSFT's un-official variant of CDC ACM */
  2851. USB_INTERFACE_INFO(USB_CLASS_COMM, 2 /* ACM */, 0x0ff),
  2852. .driver_info = (unsigned long) &rndis_wlan_info,
  2853. }, {
  2854. /* "ActiveSync" is an undocumented variant of RNDIS, used in WM5 */
  2855. USB_INTERFACE_INFO(USB_CLASS_MISC, 1, 1),
  2856. .driver_info = (unsigned long) &rndis_wlan_info,
  2857. },
  2858. { }, // END
  2859. };
  2860. MODULE_DEVICE_TABLE(usb, products);
  2861. static struct usb_driver rndis_wlan_driver = {
  2862. .name = "rndis_wlan",
  2863. .id_table = products,
  2864. .probe = usbnet_probe,
  2865. .disconnect = usbnet_disconnect,
  2866. .suspend = usbnet_suspend,
  2867. .resume = usbnet_resume,
  2868. };
  2869. static int __init rndis_wlan_init(void)
  2870. {
  2871. return usb_register(&rndis_wlan_driver);
  2872. }
  2873. module_init(rndis_wlan_init);
  2874. static void __exit rndis_wlan_exit(void)
  2875. {
  2876. usb_deregister(&rndis_wlan_driver);
  2877. }
  2878. module_exit(rndis_wlan_exit);
  2879. MODULE_AUTHOR("Bjorge Dijkstra");
  2880. MODULE_AUTHOR("Jussi Kivilinna");
  2881. MODULE_DESCRIPTION("Driver for RNDIS based USB Wireless adapters");
  2882. MODULE_LICENSE("GPL");