rndis_wlan.c 73 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738
  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_workaround_interval = modparam_workaround_interval;
  1979. priv->param_country[0] = toupper(priv->param_country[0]);
  1980. priv->param_country[1] = toupper(priv->param_country[1]);
  1981. /* doesn't support EU as country code, use FI instead */
  1982. if (!strcmp(priv->param_country, "EU"))
  1983. strcpy(priv->param_country, "FI");
  1984. if (priv->param_power_save < 0)
  1985. priv->param_power_save = 0;
  1986. else if (priv->param_power_save > 2)
  1987. priv->param_power_save = 2;
  1988. if (priv->param_roamtrigger < -80)
  1989. priv->param_roamtrigger = -80;
  1990. else if (priv->param_roamtrigger > -60)
  1991. priv->param_roamtrigger = -60;
  1992. if (priv->param_roamdelta < 0)
  1993. priv->param_roamdelta = 0;
  1994. else if (priv->param_roamdelta > 2)
  1995. priv->param_roamdelta = 2;
  1996. if (priv->param_workaround_interval < 0)
  1997. priv->param_workaround_interval = 500;
  1998. rndis_set_config_parameter_str(dev, "Country", priv->param_country);
  1999. rndis_set_config_parameter_str(dev, "FrameBursting",
  2000. priv->param_frameburst ? "1" : "0");
  2001. rndis_set_config_parameter_str(dev, "Afterburner",
  2002. priv->param_afterburner ? "1" : "0");
  2003. sprintf(buf, "%d", priv->param_power_save);
  2004. rndis_set_config_parameter_str(dev, "PowerSaveMode", buf);
  2005. sprintf(buf, "%d", priv->param_power_output);
  2006. rndis_set_config_parameter_str(dev, "PwrOut", buf);
  2007. sprintf(buf, "%d", priv->param_roamtrigger);
  2008. rndis_set_config_parameter_str(dev, "RoamTrigger", buf);
  2009. sprintf(buf, "%d", priv->param_roamdelta);
  2010. rndis_set_config_parameter_str(dev, "RoamDelta", buf);
  2011. return 0;
  2012. }
  2013. static int rndis_wext_bind(struct usbnet *dev, struct usb_interface *intf)
  2014. {
  2015. struct net_device *net = dev->net;
  2016. struct rndis_wext_private *priv;
  2017. int retval, len;
  2018. __le32 tmp;
  2019. /* allocate rndis private data */
  2020. priv = kmalloc(sizeof(struct rndis_wext_private), GFP_KERNEL);
  2021. if (!priv)
  2022. return -ENOMEM;
  2023. /* These have to be initialized before calling generic_rndis_bind().
  2024. * Otherwise we'll be in big trouble in rndis_wext_early_init().
  2025. */
  2026. dev->driver_priv = priv;
  2027. memset(priv, 0, sizeof(*priv));
  2028. memset(priv->name, 0, sizeof(priv->name));
  2029. strcpy(priv->name, "IEEE802.11");
  2030. net->wireless_handlers = &rndis_iw_handlers;
  2031. priv->usbdev = dev;
  2032. mutex_init(&priv->command_lock);
  2033. spin_lock_init(&priv->stats_lock);
  2034. /* try bind rndis_host */
  2035. retval = generic_rndis_bind(dev, intf, FLAG_RNDIS_PHYM_WIRELESS);
  2036. if (retval < 0)
  2037. goto fail;
  2038. /* generic_rndis_bind set packet filter to multicast_all+
  2039. * promisc mode which doesn't work well for our devices (device
  2040. * picks up rssi to closest station instead of to access point).
  2041. *
  2042. * rndis_host wants to avoid all OID as much as possible
  2043. * so do promisc/multicast handling in rndis_wext.
  2044. */
  2045. dev->net->set_multicast_list = rndis_wext_set_multicast_list;
  2046. tmp = RNDIS_PACKET_TYPE_DIRECTED | RNDIS_PACKET_TYPE_BROADCAST;
  2047. retval = rndis_set_oid(dev, OID_GEN_CURRENT_PACKET_FILTER, &tmp,
  2048. sizeof(tmp));
  2049. len = sizeof(tmp);
  2050. retval = rndis_query_oid(dev, OID_802_3_MAXIMUM_LIST_SIZE, &tmp, &len);
  2051. priv->multicast_size = le32_to_cpu(tmp);
  2052. if (retval < 0 || priv->multicast_size < 0)
  2053. priv->multicast_size = 0;
  2054. if (priv->multicast_size > 0)
  2055. dev->net->flags |= IFF_MULTICAST;
  2056. else
  2057. dev->net->flags &= ~IFF_MULTICAST;
  2058. priv->iwstats.qual.qual = 0;
  2059. priv->iwstats.qual.level = 0;
  2060. priv->iwstats.qual.updated = IW_QUAL_QUAL_UPDATED
  2061. | IW_QUAL_LEVEL_UPDATED
  2062. | IW_QUAL_NOISE_INVALID
  2063. | IW_QUAL_QUAL_INVALID
  2064. | IW_QUAL_LEVEL_INVALID;
  2065. rndis_wext_get_caps(dev);
  2066. set_default_iw_params(dev);
  2067. /* turn radio on */
  2068. priv->radio_on = 1;
  2069. disassociate(dev, 1);
  2070. /* because rndis_command() sleeps we need to use workqueue */
  2071. priv->workqueue = create_singlethread_workqueue("rndis_wlan");
  2072. INIT_DELAYED_WORK(&priv->stats_work, rndis_update_wireless_stats);
  2073. queue_delayed_work(priv->workqueue, &priv->stats_work,
  2074. round_jiffies_relative(STATS_UPDATE_JIFFIES));
  2075. INIT_WORK(&priv->work, rndis_wext_worker);
  2076. return 0;
  2077. fail:
  2078. kfree(priv);
  2079. return retval;
  2080. }
  2081. static void rndis_wext_unbind(struct usbnet *dev, struct usb_interface *intf)
  2082. {
  2083. struct rndis_wext_private *priv = get_rndis_wext_priv(dev);
  2084. /* turn radio off */
  2085. disassociate(dev, 0);
  2086. cancel_delayed_work_sync(&priv->stats_work);
  2087. cancel_work_sync(&priv->work);
  2088. flush_workqueue(priv->workqueue);
  2089. destroy_workqueue(priv->workqueue);
  2090. if (priv && priv->wpa_ie_len)
  2091. kfree(priv->wpa_ie);
  2092. kfree(priv);
  2093. rndis_unbind(dev, intf);
  2094. }
  2095. static int rndis_wext_reset(struct usbnet *dev)
  2096. {
  2097. return deauthenticate(dev);
  2098. }
  2099. static const struct driver_info bcm4320b_info = {
  2100. .description = "Wireless RNDIS device, BCM4320b based",
  2101. .flags = FLAG_WLAN | FLAG_FRAMING_RN | FLAG_NO_SETINT,
  2102. .bind = rndis_wext_bind,
  2103. .unbind = rndis_wext_unbind,
  2104. .status = rndis_status,
  2105. .rx_fixup = rndis_rx_fixup,
  2106. .tx_fixup = rndis_tx_fixup,
  2107. .reset = rndis_wext_reset,
  2108. .early_init = bcm4320_early_init,
  2109. .link_change = rndis_wext_link_change,
  2110. };
  2111. static const struct driver_info bcm4320a_info = {
  2112. .description = "Wireless RNDIS device, BCM4320a based",
  2113. .flags = FLAG_WLAN | FLAG_FRAMING_RN | FLAG_NO_SETINT,
  2114. .bind = rndis_wext_bind,
  2115. .unbind = rndis_wext_unbind,
  2116. .status = rndis_status,
  2117. .rx_fixup = rndis_rx_fixup,
  2118. .tx_fixup = rndis_tx_fixup,
  2119. .reset = rndis_wext_reset,
  2120. .early_init = bcm4320_early_init,
  2121. .link_change = rndis_wext_link_change,
  2122. };
  2123. static const struct driver_info rndis_wext_info = {
  2124. .description = "Wireless RNDIS device",
  2125. .flags = FLAG_WLAN | FLAG_FRAMING_RN | FLAG_NO_SETINT,
  2126. .bind = rndis_wext_bind,
  2127. .unbind = rndis_wext_unbind,
  2128. .status = rndis_status,
  2129. .rx_fixup = rndis_rx_fixup,
  2130. .tx_fixup = rndis_tx_fixup,
  2131. .reset = rndis_wext_reset,
  2132. .early_init = bcm4320_early_init,
  2133. .link_change = rndis_wext_link_change,
  2134. };
  2135. /*-------------------------------------------------------------------------*/
  2136. static const struct usb_device_id products [] = {
  2137. #define RNDIS_MASTER_INTERFACE \
  2138. .bInterfaceClass = USB_CLASS_COMM, \
  2139. .bInterfaceSubClass = 2 /* ACM */, \
  2140. .bInterfaceProtocol = 0x0ff
  2141. /* INF driver for these devices have DriverVer >= 4.xx.xx.xx and many custom
  2142. * parameters available. Chipset marked as 'BCM4320SKFBG' in NDISwrapper-wiki.
  2143. */
  2144. {
  2145. .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
  2146. | USB_DEVICE_ID_MATCH_DEVICE,
  2147. .idVendor = 0x0411,
  2148. .idProduct = 0x00bc, /* Buffalo WLI-U2-KG125S */
  2149. RNDIS_MASTER_INTERFACE,
  2150. .driver_info = (unsigned long) &bcm4320b_info,
  2151. }, {
  2152. .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
  2153. | USB_DEVICE_ID_MATCH_DEVICE,
  2154. .idVendor = 0x0baf,
  2155. .idProduct = 0x011b, /* U.S. Robotics USR5421 */
  2156. RNDIS_MASTER_INTERFACE,
  2157. .driver_info = (unsigned long) &bcm4320b_info,
  2158. }, {
  2159. .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
  2160. | USB_DEVICE_ID_MATCH_DEVICE,
  2161. .idVendor = 0x050d,
  2162. .idProduct = 0x011b, /* Belkin F5D7051 */
  2163. RNDIS_MASTER_INTERFACE,
  2164. .driver_info = (unsigned long) &bcm4320b_info,
  2165. }, {
  2166. .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
  2167. | USB_DEVICE_ID_MATCH_DEVICE,
  2168. .idVendor = 0x1799, /* Belkin has two vendor ids */
  2169. .idProduct = 0x011b, /* Belkin F5D7051 */
  2170. RNDIS_MASTER_INTERFACE,
  2171. .driver_info = (unsigned long) &bcm4320b_info,
  2172. }, {
  2173. .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
  2174. | USB_DEVICE_ID_MATCH_DEVICE,
  2175. .idVendor = 0x13b1,
  2176. .idProduct = 0x0014, /* Linksys WUSB54GSv2 */
  2177. RNDIS_MASTER_INTERFACE,
  2178. .driver_info = (unsigned long) &bcm4320b_info,
  2179. }, {
  2180. .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
  2181. | USB_DEVICE_ID_MATCH_DEVICE,
  2182. .idVendor = 0x13b1,
  2183. .idProduct = 0x0026, /* Linksys WUSB54GSC */
  2184. RNDIS_MASTER_INTERFACE,
  2185. .driver_info = (unsigned long) &bcm4320b_info,
  2186. }, {
  2187. .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
  2188. | USB_DEVICE_ID_MATCH_DEVICE,
  2189. .idVendor = 0x0b05,
  2190. .idProduct = 0x1717, /* Asus WL169gE */
  2191. RNDIS_MASTER_INTERFACE,
  2192. .driver_info = (unsigned long) &bcm4320b_info,
  2193. }, {
  2194. .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
  2195. | USB_DEVICE_ID_MATCH_DEVICE,
  2196. .idVendor = 0x0a5c,
  2197. .idProduct = 0xd11b, /* Eminent EM4045 */
  2198. RNDIS_MASTER_INTERFACE,
  2199. .driver_info = (unsigned long) &bcm4320b_info,
  2200. }, {
  2201. .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
  2202. | USB_DEVICE_ID_MATCH_DEVICE,
  2203. .idVendor = 0x1690,
  2204. .idProduct = 0x0715, /* BT Voyager 1055 */
  2205. RNDIS_MASTER_INTERFACE,
  2206. .driver_info = (unsigned long) &bcm4320b_info,
  2207. },
  2208. /* These devices have DriverVer < 4.xx.xx.xx and do not have any custom
  2209. * parameters available, hardware probably contain older firmware version with
  2210. * no way of updating. Chipset marked as 'BCM4320????' in NDISwrapper-wiki.
  2211. */
  2212. {
  2213. .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
  2214. | USB_DEVICE_ID_MATCH_DEVICE,
  2215. .idVendor = 0x13b1,
  2216. .idProduct = 0x000e, /* Linksys WUSB54GSv1 */
  2217. RNDIS_MASTER_INTERFACE,
  2218. .driver_info = (unsigned long) &bcm4320a_info,
  2219. }, {
  2220. .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
  2221. | USB_DEVICE_ID_MATCH_DEVICE,
  2222. .idVendor = 0x0baf,
  2223. .idProduct = 0x0111, /* U.S. Robotics USR5420 */
  2224. RNDIS_MASTER_INTERFACE,
  2225. .driver_info = (unsigned long) &bcm4320a_info,
  2226. }, {
  2227. .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
  2228. | USB_DEVICE_ID_MATCH_DEVICE,
  2229. .idVendor = 0x0411,
  2230. .idProduct = 0x004b, /* BUFFALO WLI-USB-G54 */
  2231. RNDIS_MASTER_INTERFACE,
  2232. .driver_info = (unsigned long) &bcm4320a_info,
  2233. },
  2234. /* Generic Wireless RNDIS devices that we don't have exact
  2235. * idVendor/idProduct/chip yet.
  2236. */
  2237. {
  2238. /* RNDIS is MSFT's un-official variant of CDC ACM */
  2239. USB_INTERFACE_INFO(USB_CLASS_COMM, 2 /* ACM */, 0x0ff),
  2240. .driver_info = (unsigned long) &rndis_wext_info,
  2241. }, {
  2242. /* "ActiveSync" is an undocumented variant of RNDIS, used in WM5 */
  2243. USB_INTERFACE_INFO(USB_CLASS_MISC, 1, 1),
  2244. .driver_info = (unsigned long) &rndis_wext_info,
  2245. },
  2246. { }, // END
  2247. };
  2248. MODULE_DEVICE_TABLE(usb, products);
  2249. static struct usb_driver rndis_wlan_driver = {
  2250. .name = "rndis_wlan",
  2251. .id_table = products,
  2252. .probe = usbnet_probe,
  2253. .disconnect = usbnet_disconnect,
  2254. .suspend = usbnet_suspend,
  2255. .resume = usbnet_resume,
  2256. };
  2257. static int __init rndis_wlan_init(void)
  2258. {
  2259. return usb_register(&rndis_wlan_driver);
  2260. }
  2261. module_init(rndis_wlan_init);
  2262. static void __exit rndis_wlan_exit(void)
  2263. {
  2264. usb_deregister(&rndis_wlan_driver);
  2265. }
  2266. module_exit(rndis_wlan_exit);
  2267. MODULE_AUTHOR("Bjorge Dijkstra");
  2268. MODULE_AUTHOR("Jussi Kivilinna");
  2269. MODULE_DESCRIPTION("Driver for RNDIS based USB Wireless adapters");
  2270. MODULE_LICENSE("GPL");