rndis_wlan.c 92 KB

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