rndis_wlan.c 75 KB

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