rndis_wlan.c 73 KB

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