rndis_wlan.c 73 KB

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