rndis_wlan.c 73 KB

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