rndis_wlan.c 76 KB

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