rndis_wlan.c 93 KB

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