rndis_wlan.c 93 KB

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