rndis_wlan.c 75 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819
  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/ieee80211.h>
  39. #include <linux/if_arp.h>
  40. #include <linux/ctype.h>
  41. #include <linux/spinlock.h>
  42. #include <net/iw_handler.h>
  43. #include <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, buflen);
  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, buflen);
  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 = netdev_priv(dev);
  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 = netdev_priv(dev);
  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 = netdev_priv(dev);
  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 = netdev_priv(dev);
  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 = netdev_priv(dev);
  1048. unsigned char bssid[ETH_ALEN];
  1049. int ret;
  1050. ret = get_bssid(usbdev, bssid);
  1051. if (ret == 0)
  1052. devdbg(usbdev, "SIOCGIWAP: %pM", bssid);
  1053. else
  1054. devdbg(usbdev, "SIOCGIWAP: <not associated>");
  1055. wrqu->ap_addr.sa_family = ARPHRD_ETHER;
  1056. memcpy(wrqu->ap_addr.sa_data, bssid, ETH_ALEN);
  1057. return ret;
  1058. }
  1059. static int rndis_iw_set_bssid(struct net_device *dev,
  1060. struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
  1061. {
  1062. struct usbnet *usbdev = netdev_priv(dev);
  1063. u8 *bssid = (u8 *)wrqu->ap_addr.sa_data;
  1064. int ret;
  1065. devdbg(usbdev, "SIOCSIWAP: %pM", bssid);
  1066. ret = rndis_set_oid(usbdev, OID_802_11_BSSID, bssid, ETH_ALEN);
  1067. /* user apps may set ap's mac address, which is not required;
  1068. * they may fail to work if this function fails, so return
  1069. * success */
  1070. if (ret)
  1071. devwarn(usbdev, "setting AP mac address failed (%08X)", ret);
  1072. return 0;
  1073. }
  1074. static int rndis_iw_set_auth(struct net_device *dev,
  1075. struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
  1076. {
  1077. struct iw_param *p = &wrqu->param;
  1078. struct usbnet *usbdev = netdev_priv(dev);
  1079. struct rndis_wext_private *priv = get_rndis_wext_priv(usbdev);
  1080. int ret = -ENOTSUPP;
  1081. switch (p->flags & IW_AUTH_INDEX) {
  1082. case IW_AUTH_WPA_VERSION:
  1083. devdbg(usbdev, "SIOCSIWAUTH: WPA_VERSION, %08x", p->value);
  1084. priv->wpa_version = p->value;
  1085. ret = 0;
  1086. break;
  1087. case IW_AUTH_CIPHER_PAIRWISE:
  1088. devdbg(usbdev, "SIOCSIWAUTH: CIPHER_PAIRWISE, %08x", p->value);
  1089. priv->wpa_cipher_pair = p->value;
  1090. ret = 0;
  1091. break;
  1092. case IW_AUTH_CIPHER_GROUP:
  1093. devdbg(usbdev, "SIOCSIWAUTH: CIPHER_GROUP, %08x", p->value);
  1094. priv->wpa_cipher_group = p->value;
  1095. ret = 0;
  1096. break;
  1097. case IW_AUTH_KEY_MGMT:
  1098. devdbg(usbdev, "SIOCSIWAUTH: KEY_MGMT, %08x", p->value);
  1099. priv->wpa_keymgmt = p->value;
  1100. ret = 0;
  1101. break;
  1102. case IW_AUTH_TKIP_COUNTERMEASURES:
  1103. devdbg(usbdev, "SIOCSIWAUTH: TKIP_COUNTERMEASURES, %08x",
  1104. p->value);
  1105. ret = 0;
  1106. break;
  1107. case IW_AUTH_DROP_UNENCRYPTED:
  1108. devdbg(usbdev, "SIOCSIWAUTH: DROP_UNENCRYPTED, %08x", p->value);
  1109. ret = 0;
  1110. break;
  1111. case IW_AUTH_80211_AUTH_ALG:
  1112. devdbg(usbdev, "SIOCSIWAUTH: 80211_AUTH_ALG, %08x", p->value);
  1113. priv->wpa_authalg = p->value;
  1114. ret = 0;
  1115. break;
  1116. case IW_AUTH_WPA_ENABLED:
  1117. devdbg(usbdev, "SIOCSIWAUTH: WPA_ENABLED, %08x", p->value);
  1118. if (wrqu->param.value)
  1119. deauthenticate(usbdev);
  1120. ret = 0;
  1121. break;
  1122. case IW_AUTH_RX_UNENCRYPTED_EAPOL:
  1123. devdbg(usbdev, "SIOCSIWAUTH: RX_UNENCRYPTED_EAPOL, %08x",
  1124. p->value);
  1125. ret = 0;
  1126. break;
  1127. case IW_AUTH_ROAMING_CONTROL:
  1128. devdbg(usbdev, "SIOCSIWAUTH: ROAMING_CONTROL, %08x", p->value);
  1129. ret = 0;
  1130. break;
  1131. case IW_AUTH_PRIVACY_INVOKED:
  1132. devdbg(usbdev, "SIOCSIWAUTH: invalid cmd %d",
  1133. wrqu->param.flags & IW_AUTH_INDEX);
  1134. return -EOPNOTSUPP;
  1135. default:
  1136. devdbg(usbdev, "SIOCSIWAUTH: UNKNOWN %08x, %08x",
  1137. p->flags & IW_AUTH_INDEX, p->value);
  1138. }
  1139. return ret;
  1140. }
  1141. static int rndis_iw_get_auth(struct net_device *dev,
  1142. struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
  1143. {
  1144. struct iw_param *p = &wrqu->param;
  1145. struct usbnet *usbdev = netdev_priv(dev);
  1146. struct rndis_wext_private *priv = get_rndis_wext_priv(usbdev);
  1147. switch (p->flags & IW_AUTH_INDEX) {
  1148. case IW_AUTH_WPA_VERSION:
  1149. p->value = priv->wpa_version;
  1150. break;
  1151. case IW_AUTH_CIPHER_PAIRWISE:
  1152. p->value = priv->wpa_cipher_pair;
  1153. break;
  1154. case IW_AUTH_CIPHER_GROUP:
  1155. p->value = priv->wpa_cipher_group;
  1156. break;
  1157. case IW_AUTH_KEY_MGMT:
  1158. p->value = priv->wpa_keymgmt;
  1159. break;
  1160. case IW_AUTH_80211_AUTH_ALG:
  1161. p->value = priv->wpa_authalg;
  1162. break;
  1163. default:
  1164. devdbg(usbdev, "SIOCGIWAUTH: invalid cmd %d",
  1165. wrqu->param.flags & IW_AUTH_INDEX);
  1166. return -EOPNOTSUPP;
  1167. }
  1168. return 0;
  1169. }
  1170. static int rndis_iw_get_mode(struct net_device *dev,
  1171. struct iw_request_info *info,
  1172. union iwreq_data *wrqu, char *extra)
  1173. {
  1174. struct usbnet *usbdev = netdev_priv(dev);
  1175. struct rndis_wext_private *priv = get_rndis_wext_priv(usbdev);
  1176. switch (priv->infra_mode) {
  1177. case ndis_80211_infra_adhoc:
  1178. wrqu->mode = IW_MODE_ADHOC;
  1179. break;
  1180. case ndis_80211_infra_infra:
  1181. wrqu->mode = IW_MODE_INFRA;
  1182. break;
  1183. /*case ndis_80211_infra_auto_unknown:*/
  1184. default:
  1185. wrqu->mode = IW_MODE_AUTO;
  1186. break;
  1187. }
  1188. devdbg(usbdev, "SIOCGIWMODE: %08x", wrqu->mode);
  1189. return 0;
  1190. }
  1191. static int rndis_iw_set_mode(struct net_device *dev,
  1192. struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
  1193. {
  1194. struct usbnet *usbdev = netdev_priv(dev);
  1195. int mode;
  1196. devdbg(usbdev, "SIOCSIWMODE: %08x", wrqu->mode);
  1197. switch (wrqu->mode) {
  1198. case IW_MODE_ADHOC:
  1199. mode = ndis_80211_infra_adhoc;
  1200. break;
  1201. case IW_MODE_INFRA:
  1202. mode = ndis_80211_infra_infra;
  1203. break;
  1204. /*case IW_MODE_AUTO:*/
  1205. default:
  1206. mode = ndis_80211_infra_auto_unknown;
  1207. break;
  1208. }
  1209. return set_infra_mode(usbdev, mode);
  1210. }
  1211. static int rndis_iw_set_encode(struct net_device *dev,
  1212. struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
  1213. {
  1214. struct usbnet *usbdev = netdev_priv(dev);
  1215. struct rndis_wext_private *priv = get_rndis_wext_priv(usbdev);
  1216. int ret, index, key_len;
  1217. u8 *key;
  1218. index = (wrqu->encoding.flags & IW_ENCODE_INDEX);
  1219. /* iwconfig gives index as 1 - N */
  1220. if (index > 0)
  1221. index--;
  1222. else
  1223. index = priv->encr_tx_key_index;
  1224. if (index < 0 || index >= 4) {
  1225. devwarn(usbdev, "encryption index out of range (%u)", index);
  1226. return -EINVAL;
  1227. }
  1228. /* remove key if disabled */
  1229. if (wrqu->data.flags & IW_ENCODE_DISABLED) {
  1230. if (remove_key(usbdev, index, NULL))
  1231. return -EINVAL;
  1232. else
  1233. return 0;
  1234. }
  1235. /* global encryption state (for all keys) */
  1236. if (wrqu->data.flags & IW_ENCODE_OPEN)
  1237. ret = set_auth_mode(usbdev, IW_AUTH_WPA_VERSION_DISABLED,
  1238. IW_AUTH_ALG_OPEN_SYSTEM);
  1239. else /*if (wrqu->data.flags & IW_ENCODE_RESTRICTED)*/
  1240. ret = set_auth_mode(usbdev, IW_AUTH_WPA_VERSION_DISABLED,
  1241. IW_AUTH_ALG_SHARED_KEY);
  1242. if (ret != 0)
  1243. return ret;
  1244. if (wrqu->data.length > 0) {
  1245. key_len = wrqu->data.length;
  1246. key = extra;
  1247. } else {
  1248. /* must be set as tx key */
  1249. if (priv->encr_key_len[index] == 0)
  1250. return -EINVAL;
  1251. key_len = priv->encr_key_len[index];
  1252. key = priv->encr_keys[index];
  1253. priv->encr_tx_key_index = index;
  1254. }
  1255. if (add_wep_key(usbdev, key, key_len, index) != 0)
  1256. return -EINVAL;
  1257. if (index == priv->encr_tx_key_index)
  1258. /* ndis drivers want essid to be set after setting encr */
  1259. set_essid(usbdev, &priv->essid);
  1260. return 0;
  1261. }
  1262. static int rndis_iw_set_encode_ext(struct net_device *dev,
  1263. struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
  1264. {
  1265. struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
  1266. struct usbnet *usbdev = netdev_priv(dev);
  1267. struct rndis_wext_private *priv = get_rndis_wext_priv(usbdev);
  1268. struct ndis_80211_key ndis_key;
  1269. int keyidx, ret;
  1270. u8 *addr;
  1271. keyidx = wrqu->encoding.flags & IW_ENCODE_INDEX;
  1272. /* iwconfig gives index as 1 - N */
  1273. if (keyidx)
  1274. keyidx--;
  1275. else
  1276. keyidx = priv->encr_tx_key_index;
  1277. if (keyidx < 0 || keyidx >= 4)
  1278. return -EINVAL;
  1279. if (ext->alg == WPA_ALG_WEP) {
  1280. if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)
  1281. priv->encr_tx_key_index = keyidx;
  1282. return add_wep_key(usbdev, ext->key, ext->key_len, keyidx);
  1283. }
  1284. if ((wrqu->encoding.flags & IW_ENCODE_DISABLED) ||
  1285. ext->alg == IW_ENCODE_ALG_NONE || ext->key_len == 0)
  1286. return remove_key(usbdev, keyidx, NULL);
  1287. if (ext->key_len > sizeof(ndis_key.material))
  1288. return -1;
  1289. memset(&ndis_key, 0, sizeof(ndis_key));
  1290. ndis_key.size = cpu_to_le32(sizeof(ndis_key) -
  1291. sizeof(ndis_key.material) + ext->key_len);
  1292. ndis_key.length = cpu_to_le32(ext->key_len);
  1293. ndis_key.index = cpu_to_le32(keyidx);
  1294. if (ext->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID) {
  1295. memcpy(ndis_key.rsc, ext->rx_seq, 6);
  1296. ndis_key.index |= cpu_to_le32(1 << 29);
  1297. }
  1298. addr = ext->addr.sa_data;
  1299. if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) {
  1300. /* group key */
  1301. if (priv->infra_mode == ndis_80211_infra_adhoc)
  1302. memset(ndis_key.bssid, 0xff, ETH_ALEN);
  1303. else
  1304. get_bssid(usbdev, ndis_key.bssid);
  1305. } else {
  1306. /* pairwise key */
  1307. ndis_key.index |= cpu_to_le32(1 << 30);
  1308. memcpy(ndis_key.bssid, addr, ETH_ALEN);
  1309. }
  1310. if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)
  1311. ndis_key.index |= cpu_to_le32(1 << 31);
  1312. if (ext->alg == IW_ENCODE_ALG_TKIP && ext->key_len == 32) {
  1313. /* wpa_supplicant gives us the Michael MIC RX/TX keys in
  1314. * different order than NDIS spec, so swap the order here. */
  1315. memcpy(ndis_key.material, ext->key, 16);
  1316. memcpy(ndis_key.material + 16, ext->key + 24, 8);
  1317. memcpy(ndis_key.material + 24, ext->key + 16, 8);
  1318. } else
  1319. memcpy(ndis_key.material, ext->key, ext->key_len);
  1320. ret = rndis_set_oid(usbdev, OID_802_11_ADD_KEY, &ndis_key,
  1321. le32_to_cpu(ndis_key.size));
  1322. devdbg(usbdev, "SIOCSIWENCODEEXT: OID_802_11_ADD_KEY -> %08X", ret);
  1323. if (ret != 0)
  1324. return ret;
  1325. priv->encr_key_len[keyidx] = ext->key_len;
  1326. memcpy(&priv->encr_keys[keyidx], ndis_key.material, ext->key_len);
  1327. if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)
  1328. priv->encr_tx_key_index = keyidx;
  1329. return 0;
  1330. }
  1331. static int rndis_iw_set_scan(struct net_device *dev,
  1332. struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
  1333. {
  1334. struct usbnet *usbdev = netdev_priv(dev);
  1335. union iwreq_data evt;
  1336. int ret = -EINVAL;
  1337. __le32 tmp;
  1338. devdbg(usbdev, "SIOCSIWSCAN");
  1339. if (wrqu->data.flags == 0) {
  1340. tmp = ccpu2(1);
  1341. ret = rndis_set_oid(usbdev, OID_802_11_BSSID_LIST_SCAN, &tmp,
  1342. sizeof(tmp));
  1343. evt.data.flags = 0;
  1344. evt.data.length = 0;
  1345. wireless_send_event(dev, SIOCGIWSCAN, &evt, NULL);
  1346. }
  1347. return ret;
  1348. }
  1349. static char *rndis_translate_scan(struct net_device *dev,
  1350. struct iw_request_info *info, char *cev,
  1351. char *end_buf,
  1352. struct ndis_80211_bssid_ex *bssid)
  1353. {
  1354. struct usbnet *usbdev = netdev_priv(dev);
  1355. u8 *ie;
  1356. char *current_val;
  1357. int bssid_len, ie_len, i;
  1358. u32 beacon, atim;
  1359. struct iw_event iwe;
  1360. unsigned char sbuf[32];
  1361. bssid_len = le32_to_cpu(bssid->length);
  1362. devdbg(usbdev, "BSSID %pM", bssid->mac);
  1363. iwe.cmd = SIOCGIWAP;
  1364. iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
  1365. memcpy(iwe.u.ap_addr.sa_data, bssid->mac, ETH_ALEN);
  1366. cev = iwe_stream_add_event(info, cev, end_buf, &iwe, IW_EV_ADDR_LEN);
  1367. devdbg(usbdev, "SSID(%d) %s", le32_to_cpu(bssid->ssid.length),
  1368. bssid->ssid.essid);
  1369. iwe.cmd = SIOCGIWESSID;
  1370. iwe.u.essid.length = le32_to_cpu(bssid->ssid.length);
  1371. iwe.u.essid.flags = 1;
  1372. cev = iwe_stream_add_point(info, cev, end_buf, &iwe, bssid->ssid.essid);
  1373. devdbg(usbdev, "MODE %d", le32_to_cpu(bssid->net_infra));
  1374. iwe.cmd = SIOCGIWMODE;
  1375. switch (le32_to_cpu(bssid->net_infra)) {
  1376. case ndis_80211_infra_adhoc:
  1377. iwe.u.mode = IW_MODE_ADHOC;
  1378. break;
  1379. case ndis_80211_infra_infra:
  1380. iwe.u.mode = IW_MODE_INFRA;
  1381. break;
  1382. /*case ndis_80211_infra_auto_unknown:*/
  1383. default:
  1384. iwe.u.mode = IW_MODE_AUTO;
  1385. break;
  1386. }
  1387. cev = iwe_stream_add_event(info, cev, end_buf, &iwe, IW_EV_UINT_LEN);
  1388. devdbg(usbdev, "FREQ %d kHz", le32_to_cpu(bssid->config.ds_config));
  1389. iwe.cmd = SIOCGIWFREQ;
  1390. dsconfig_to_freq(le32_to_cpu(bssid->config.ds_config), &iwe.u.freq);
  1391. cev = iwe_stream_add_event(info, cev, end_buf, &iwe, IW_EV_FREQ_LEN);
  1392. devdbg(usbdev, "QUAL %d", le32_to_cpu(bssid->rssi));
  1393. iwe.cmd = IWEVQUAL;
  1394. iwe.u.qual.qual = level_to_qual(le32_to_cpu(bssid->rssi));
  1395. iwe.u.qual.level = le32_to_cpu(bssid->rssi);
  1396. iwe.u.qual.updated = IW_QUAL_QUAL_UPDATED
  1397. | IW_QUAL_LEVEL_UPDATED
  1398. | IW_QUAL_NOISE_INVALID;
  1399. cev = iwe_stream_add_event(info, cev, end_buf, &iwe, IW_EV_QUAL_LEN);
  1400. devdbg(usbdev, "ENCODE %d", le32_to_cpu(bssid->privacy));
  1401. iwe.cmd = SIOCGIWENCODE;
  1402. iwe.u.data.length = 0;
  1403. if (le32_to_cpu(bssid->privacy) == ndis_80211_priv_accept_all)
  1404. iwe.u.data.flags = IW_ENCODE_DISABLED;
  1405. else
  1406. iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
  1407. cev = iwe_stream_add_point(info, cev, end_buf, &iwe, NULL);
  1408. devdbg(usbdev, "RATES:");
  1409. current_val = cev + iwe_stream_lcp_len(info);
  1410. iwe.cmd = SIOCGIWRATE;
  1411. for (i = 0; i < sizeof(bssid->rates); i++) {
  1412. if (bssid->rates[i] & 0x7f) {
  1413. iwe.u.bitrate.value =
  1414. ((bssid->rates[i] & 0x7f) *
  1415. 500000);
  1416. devdbg(usbdev, " %d", iwe.u.bitrate.value);
  1417. current_val = iwe_stream_add_value(info, cev,
  1418. current_val, end_buf, &iwe,
  1419. IW_EV_PARAM_LEN);
  1420. }
  1421. }
  1422. if ((current_val - cev) > iwe_stream_lcp_len(info))
  1423. cev = current_val;
  1424. beacon = le32_to_cpu(bssid->config.beacon_period);
  1425. devdbg(usbdev, "BCN_INT %d", beacon);
  1426. iwe.cmd = IWEVCUSTOM;
  1427. snprintf(sbuf, sizeof(sbuf), "bcn_int=%d", beacon);
  1428. iwe.u.data.length = strlen(sbuf);
  1429. cev = iwe_stream_add_point(info, cev, end_buf, &iwe, sbuf);
  1430. atim = le32_to_cpu(bssid->config.atim_window);
  1431. devdbg(usbdev, "ATIM %d", atim);
  1432. iwe.cmd = IWEVCUSTOM;
  1433. snprintf(sbuf, sizeof(sbuf), "atim=%u", atim);
  1434. iwe.u.data.length = strlen(sbuf);
  1435. cev = iwe_stream_add_point(info, cev, end_buf, &iwe, sbuf);
  1436. ie = (void *)(bssid->ies + sizeof(struct ndis_80211_fixed_ies));
  1437. ie_len = min(bssid_len - (int)sizeof(*bssid),
  1438. (int)le32_to_cpu(bssid->ie_length));
  1439. ie_len -= sizeof(struct ndis_80211_fixed_ies);
  1440. while (ie_len >= 2 && 2 + ie[1] <= ie_len) {
  1441. if ((ie[0] == WLAN_EID_GENERIC && ie[1] >= 4 &&
  1442. memcmp(ie + 2, "\x00\x50\xf2\x01", 4) == 0) ||
  1443. ie[0] == WLAN_EID_RSN) {
  1444. devdbg(usbdev, "IE: WPA%d",
  1445. (ie[0] == WLAN_EID_RSN) ? 2 : 1);
  1446. iwe.cmd = IWEVGENIE;
  1447. /* arbitrary cut-off at 64 */
  1448. iwe.u.data.length = min(ie[1] + 2, 64);
  1449. cev = iwe_stream_add_point(info, cev, end_buf, &iwe, ie);
  1450. }
  1451. ie_len -= 2 + ie[1];
  1452. ie += 2 + ie[1];
  1453. }
  1454. return cev;
  1455. }
  1456. static int rndis_iw_get_scan(struct net_device *dev,
  1457. struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
  1458. {
  1459. struct usbnet *usbdev = netdev_priv(dev);
  1460. void *buf = NULL;
  1461. char *cev = extra;
  1462. struct ndis_80211_bssid_list_ex *bssid_list;
  1463. struct ndis_80211_bssid_ex *bssid;
  1464. int ret = -EINVAL, len, count, bssid_len;
  1465. devdbg(usbdev, "SIOCGIWSCAN");
  1466. len = CONTROL_BUFFER_SIZE;
  1467. buf = kmalloc(len, GFP_KERNEL);
  1468. if (!buf) {
  1469. ret = -ENOMEM;
  1470. goto out;
  1471. }
  1472. ret = rndis_query_oid(usbdev, OID_802_11_BSSID_LIST, buf, &len);
  1473. if (ret != 0)
  1474. goto out;
  1475. bssid_list = buf;
  1476. bssid = bssid_list->bssid;
  1477. bssid_len = le32_to_cpu(bssid->length);
  1478. count = le32_to_cpu(bssid_list->num_items);
  1479. devdbg(usbdev, "SIOCGIWSCAN: %d BSSIDs found", count);
  1480. while (count && ((void *)bssid + bssid_len) <= (buf + len)) {
  1481. cev = rndis_translate_scan(dev, info, cev,
  1482. extra + IW_SCAN_MAX_DATA, bssid);
  1483. bssid = (void *)bssid + bssid_len;
  1484. bssid_len = le32_to_cpu(bssid->length);
  1485. count--;
  1486. }
  1487. out:
  1488. wrqu->data.length = cev - extra;
  1489. wrqu->data.flags = 0;
  1490. kfree(buf);
  1491. return ret;
  1492. }
  1493. static int rndis_iw_set_genie(struct net_device *dev,
  1494. struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
  1495. {
  1496. struct usbnet *usbdev = netdev_priv(dev);
  1497. struct rndis_wext_private *priv = get_rndis_wext_priv(usbdev);
  1498. int ret = 0;
  1499. #ifdef DEBUG
  1500. int j;
  1501. u8 *gie = extra;
  1502. for (j = 0; j < wrqu->data.length; j += 8)
  1503. devdbg(usbdev,
  1504. "SIOCSIWGENIE %04x - "
  1505. "%02x %02x %02x %02x %02x %02x %02x %02x", j,
  1506. gie[j + 0], gie[j + 1], gie[j + 2], gie[j + 3],
  1507. gie[j + 4], gie[j + 5], gie[j + 6], gie[j + 7]);
  1508. #endif
  1509. /* clear existing IEs */
  1510. if (priv->wpa_ie_len) {
  1511. kfree(priv->wpa_ie);
  1512. priv->wpa_ie_len = 0;
  1513. }
  1514. /* set new IEs */
  1515. priv->wpa_ie = kmalloc(wrqu->data.length, GFP_KERNEL);
  1516. if (priv->wpa_ie) {
  1517. priv->wpa_ie_len = wrqu->data.length;
  1518. memcpy(priv->wpa_ie, extra, priv->wpa_ie_len);
  1519. } else
  1520. ret = -ENOMEM;
  1521. return ret;
  1522. }
  1523. static int rndis_iw_get_genie(struct net_device *dev,
  1524. struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
  1525. {
  1526. struct usbnet *usbdev = netdev_priv(dev);
  1527. struct rndis_wext_private *priv = get_rndis_wext_priv(usbdev);
  1528. devdbg(usbdev, "SIOCGIWGENIE");
  1529. if (priv->wpa_ie_len == 0 || priv->wpa_ie == NULL) {
  1530. wrqu->data.length = 0;
  1531. return 0;
  1532. }
  1533. if (wrqu->data.length < priv->wpa_ie_len)
  1534. return -E2BIG;
  1535. wrqu->data.length = priv->wpa_ie_len;
  1536. memcpy(extra, priv->wpa_ie, priv->wpa_ie_len);
  1537. return 0;
  1538. }
  1539. static int rndis_iw_set_rts(struct net_device *dev,
  1540. struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
  1541. {
  1542. struct usbnet *usbdev = netdev_priv(dev);
  1543. __le32 tmp;
  1544. devdbg(usbdev, "SIOCSIWRTS");
  1545. tmp = cpu_to_le32(wrqu->rts.value);
  1546. return rndis_set_oid(usbdev, OID_802_11_RTS_THRESHOLD, &tmp,
  1547. sizeof(tmp));
  1548. }
  1549. static int rndis_iw_get_rts(struct net_device *dev,
  1550. struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
  1551. {
  1552. struct usbnet *usbdev = netdev_priv(dev);
  1553. __le32 tmp;
  1554. int len, ret;
  1555. len = sizeof(tmp);
  1556. ret = rndis_query_oid(usbdev, OID_802_11_RTS_THRESHOLD, &tmp, &len);
  1557. if (ret == 0) {
  1558. wrqu->rts.value = le32_to_cpu(tmp);
  1559. wrqu->rts.flags = 1;
  1560. wrqu->rts.disabled = 0;
  1561. }
  1562. devdbg(usbdev, "SIOCGIWRTS: %d", wrqu->rts.value);
  1563. return ret;
  1564. }
  1565. static int rndis_iw_set_frag(struct net_device *dev,
  1566. struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
  1567. {
  1568. struct usbnet *usbdev = netdev_priv(dev);
  1569. __le32 tmp;
  1570. devdbg(usbdev, "SIOCSIWFRAG");
  1571. tmp = cpu_to_le32(wrqu->frag.value);
  1572. return rndis_set_oid(usbdev, OID_802_11_FRAGMENTATION_THRESHOLD, &tmp,
  1573. sizeof(tmp));
  1574. }
  1575. static int rndis_iw_get_frag(struct net_device *dev,
  1576. struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
  1577. {
  1578. struct usbnet *usbdev = netdev_priv(dev);
  1579. __le32 tmp;
  1580. int len, ret;
  1581. len = sizeof(tmp);
  1582. ret = rndis_query_oid(usbdev, OID_802_11_FRAGMENTATION_THRESHOLD, &tmp,
  1583. &len);
  1584. if (ret == 0) {
  1585. wrqu->frag.value = le32_to_cpu(tmp);
  1586. wrqu->frag.flags = 1;
  1587. wrqu->frag.disabled = 0;
  1588. }
  1589. devdbg(usbdev, "SIOCGIWFRAG: %d", wrqu->frag.value);
  1590. return ret;
  1591. }
  1592. static int rndis_iw_set_nick(struct net_device *dev,
  1593. struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
  1594. {
  1595. struct usbnet *usbdev = netdev_priv(dev);
  1596. struct rndis_wext_private *priv = get_rndis_wext_priv(usbdev);
  1597. devdbg(usbdev, "SIOCSIWNICK");
  1598. priv->nick_len = wrqu->data.length;
  1599. if (priv->nick_len > 32)
  1600. priv->nick_len = 32;
  1601. memcpy(priv->nick, extra, priv->nick_len);
  1602. return 0;
  1603. }
  1604. static int rndis_iw_get_nick(struct net_device *dev,
  1605. struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
  1606. {
  1607. struct usbnet *usbdev = netdev_priv(dev);
  1608. struct rndis_wext_private *priv = get_rndis_wext_priv(usbdev);
  1609. wrqu->data.flags = 1;
  1610. wrqu->data.length = priv->nick_len;
  1611. memcpy(extra, priv->nick, priv->nick_len);
  1612. devdbg(usbdev, "SIOCGIWNICK: '%s'", priv->nick);
  1613. return 0;
  1614. }
  1615. static int rndis_iw_set_freq(struct net_device *dev,
  1616. struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
  1617. {
  1618. struct usbnet *usbdev = netdev_priv(dev);
  1619. struct ndis_80211_conf config;
  1620. unsigned int dsconfig;
  1621. int len, ret;
  1622. /* this OID is valid only when not associated */
  1623. if (is_associated(usbdev))
  1624. return 0;
  1625. dsconfig = 0;
  1626. if (freq_to_dsconfig(&wrqu->freq, &dsconfig))
  1627. return -EINVAL;
  1628. len = sizeof(config);
  1629. ret = rndis_query_oid(usbdev, OID_802_11_CONFIGURATION, &config, &len);
  1630. if (ret != 0) {
  1631. devdbg(usbdev, "SIOCSIWFREQ: querying configuration failed");
  1632. return 0;
  1633. }
  1634. config.ds_config = cpu_to_le32(dsconfig);
  1635. devdbg(usbdev, "SIOCSIWFREQ: %d * 10^%d", wrqu->freq.m, wrqu->freq.e);
  1636. return rndis_set_oid(usbdev, OID_802_11_CONFIGURATION, &config,
  1637. sizeof(config));
  1638. }
  1639. static int rndis_iw_get_freq(struct net_device *dev,
  1640. struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
  1641. {
  1642. struct usbnet *usbdev = netdev_priv(dev);
  1643. struct ndis_80211_conf config;
  1644. int len, ret;
  1645. len = sizeof(config);
  1646. ret = rndis_query_oid(usbdev, OID_802_11_CONFIGURATION, &config, &len);
  1647. if (ret == 0)
  1648. dsconfig_to_freq(le32_to_cpu(config.ds_config), &wrqu->freq);
  1649. devdbg(usbdev, "SIOCGIWFREQ: %d", wrqu->freq.m);
  1650. return ret;
  1651. }
  1652. static int rndis_iw_get_txpower(struct net_device *dev,
  1653. struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
  1654. {
  1655. struct usbnet *usbdev = netdev_priv(dev);
  1656. struct rndis_wext_private *priv = get_rndis_wext_priv(usbdev);
  1657. __le32 tx_power;
  1658. int ret = 0, len;
  1659. if (priv->radio_on) {
  1660. if (priv->caps & CAP_SUPPORT_TXPOWER) {
  1661. len = sizeof(tx_power);
  1662. ret = rndis_query_oid(usbdev, OID_802_11_TX_POWER_LEVEL,
  1663. &tx_power, &len);
  1664. if (ret != 0)
  1665. return ret;
  1666. } else
  1667. /* fake incase not supported */
  1668. tx_power = cpu_to_le32(get_bcm4320_power(priv));
  1669. wrqu->txpower.flags = IW_TXPOW_MWATT;
  1670. wrqu->txpower.value = le32_to_cpu(tx_power);
  1671. wrqu->txpower.disabled = 0;
  1672. } else {
  1673. wrqu->txpower.flags = IW_TXPOW_MWATT;
  1674. wrqu->txpower.value = 0;
  1675. wrqu->txpower.disabled = 1;
  1676. }
  1677. devdbg(usbdev, "SIOCGIWTXPOW: %d", wrqu->txpower.value);
  1678. return ret;
  1679. }
  1680. static int rndis_iw_set_txpower(struct net_device *dev,
  1681. struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
  1682. {
  1683. struct usbnet *usbdev = netdev_priv(dev);
  1684. struct rndis_wext_private *priv = get_rndis_wext_priv(usbdev);
  1685. __le32 tx_power = 0;
  1686. int ret = 0;
  1687. if (!wrqu->txpower.disabled) {
  1688. if (wrqu->txpower.flags == IW_TXPOW_MWATT)
  1689. tx_power = cpu_to_le32(wrqu->txpower.value);
  1690. else { /* wrqu->txpower.flags == IW_TXPOW_DBM */
  1691. if (wrqu->txpower.value > 20)
  1692. tx_power = cpu_to_le32(128);
  1693. else if (wrqu->txpower.value < -43)
  1694. tx_power = cpu_to_le32(127);
  1695. else {
  1696. signed char tmp;
  1697. tmp = wrqu->txpower.value;
  1698. tmp = -12 - tmp;
  1699. tmp <<= 2;
  1700. tx_power = cpu_to_le32((unsigned char)tmp);
  1701. }
  1702. }
  1703. }
  1704. devdbg(usbdev, "SIOCSIWTXPOW: %d", le32_to_cpu(tx_power));
  1705. if (le32_to_cpu(tx_power) != 0) {
  1706. if (priv->caps & CAP_SUPPORT_TXPOWER) {
  1707. /* turn radio on first */
  1708. if (!priv->radio_on)
  1709. disassociate(usbdev, 1);
  1710. ret = rndis_set_oid(usbdev, OID_802_11_TX_POWER_LEVEL,
  1711. &tx_power, sizeof(tx_power));
  1712. if (ret != 0)
  1713. ret = -EOPNOTSUPP;
  1714. return ret;
  1715. } else {
  1716. /* txpower unsupported, just turn radio on */
  1717. if (!priv->radio_on)
  1718. return disassociate(usbdev, 1);
  1719. return 0; /* all ready on */
  1720. }
  1721. }
  1722. /* tx_power == 0, turn off radio */
  1723. return disassociate(usbdev, 0);
  1724. }
  1725. static int rndis_iw_get_rate(struct net_device *dev,
  1726. struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
  1727. {
  1728. struct usbnet *usbdev = netdev_priv(dev);
  1729. __le32 tmp;
  1730. int ret, len;
  1731. len = sizeof(tmp);
  1732. ret = rndis_query_oid(usbdev, OID_GEN_LINK_SPEED, &tmp, &len);
  1733. if (ret == 0) {
  1734. wrqu->bitrate.value = le32_to_cpu(tmp) * 100;
  1735. wrqu->bitrate.disabled = 0;
  1736. wrqu->bitrate.flags = 1;
  1737. }
  1738. return ret;
  1739. }
  1740. static int rndis_iw_set_mlme(struct net_device *dev,
  1741. struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
  1742. {
  1743. struct usbnet *usbdev = netdev_priv(dev);
  1744. struct rndis_wext_private *priv = get_rndis_wext_priv(usbdev);
  1745. struct iw_mlme *mlme = (struct iw_mlme *)extra;
  1746. unsigned char bssid[ETH_ALEN];
  1747. get_bssid(usbdev, bssid);
  1748. if (memcmp(bssid, mlme->addr.sa_data, ETH_ALEN))
  1749. return -EINVAL;
  1750. switch (mlme->cmd) {
  1751. case IW_MLME_DEAUTH:
  1752. return deauthenticate(usbdev);
  1753. case IW_MLME_DISASSOC:
  1754. return disassociate(usbdev, priv->radio_on);
  1755. default:
  1756. return -EOPNOTSUPP;
  1757. }
  1758. return 0;
  1759. }
  1760. static struct iw_statistics *rndis_get_wireless_stats(struct net_device *dev)
  1761. {
  1762. struct usbnet *usbdev = netdev_priv(dev);
  1763. struct rndis_wext_private *priv = get_rndis_wext_priv(usbdev);
  1764. unsigned long flags;
  1765. spin_lock_irqsave(&priv->stats_lock, flags);
  1766. memcpy(&priv->iwstats, &priv->privstats, sizeof(priv->iwstats));
  1767. spin_unlock_irqrestore(&priv->stats_lock, flags);
  1768. return &priv->iwstats;
  1769. }
  1770. #define IW_IOCTL(x) [(x) - SIOCSIWCOMMIT]
  1771. static const iw_handler rndis_iw_handler[] =
  1772. {
  1773. IW_IOCTL(SIOCSIWCOMMIT) = rndis_iw_commit,
  1774. IW_IOCTL(SIOCGIWNAME) = rndis_iw_get_name,
  1775. IW_IOCTL(SIOCSIWFREQ) = rndis_iw_set_freq,
  1776. IW_IOCTL(SIOCGIWFREQ) = rndis_iw_get_freq,
  1777. IW_IOCTL(SIOCSIWMODE) = rndis_iw_set_mode,
  1778. IW_IOCTL(SIOCGIWMODE) = rndis_iw_get_mode,
  1779. IW_IOCTL(SIOCGIWRANGE) = rndis_iw_get_range,
  1780. IW_IOCTL(SIOCSIWAP) = rndis_iw_set_bssid,
  1781. IW_IOCTL(SIOCGIWAP) = rndis_iw_get_bssid,
  1782. IW_IOCTL(SIOCSIWSCAN) = rndis_iw_set_scan,
  1783. IW_IOCTL(SIOCGIWSCAN) = rndis_iw_get_scan,
  1784. IW_IOCTL(SIOCSIWESSID) = rndis_iw_set_essid,
  1785. IW_IOCTL(SIOCGIWESSID) = rndis_iw_get_essid,
  1786. IW_IOCTL(SIOCSIWNICKN) = rndis_iw_set_nick,
  1787. IW_IOCTL(SIOCGIWNICKN) = rndis_iw_get_nick,
  1788. IW_IOCTL(SIOCGIWRATE) = rndis_iw_get_rate,
  1789. IW_IOCTL(SIOCSIWRTS) = rndis_iw_set_rts,
  1790. IW_IOCTL(SIOCGIWRTS) = rndis_iw_get_rts,
  1791. IW_IOCTL(SIOCSIWFRAG) = rndis_iw_set_frag,
  1792. IW_IOCTL(SIOCGIWFRAG) = rndis_iw_get_frag,
  1793. IW_IOCTL(SIOCSIWTXPOW) = rndis_iw_set_txpower,
  1794. IW_IOCTL(SIOCGIWTXPOW) = rndis_iw_get_txpower,
  1795. IW_IOCTL(SIOCSIWENCODE) = rndis_iw_set_encode,
  1796. IW_IOCTL(SIOCSIWENCODEEXT) = rndis_iw_set_encode_ext,
  1797. IW_IOCTL(SIOCSIWAUTH) = rndis_iw_set_auth,
  1798. IW_IOCTL(SIOCGIWAUTH) = rndis_iw_get_auth,
  1799. IW_IOCTL(SIOCSIWGENIE) = rndis_iw_set_genie,
  1800. IW_IOCTL(SIOCGIWGENIE) = rndis_iw_get_genie,
  1801. IW_IOCTL(SIOCSIWMLME) = rndis_iw_set_mlme,
  1802. };
  1803. static const iw_handler rndis_wext_private_handler[] = {
  1804. };
  1805. static const struct iw_priv_args rndis_wext_private_args[] = {
  1806. };
  1807. static const struct iw_handler_def rndis_iw_handlers = {
  1808. .num_standard = ARRAY_SIZE(rndis_iw_handler),
  1809. .num_private = ARRAY_SIZE(rndis_wext_private_handler),
  1810. .num_private_args = ARRAY_SIZE(rndis_wext_private_args),
  1811. .standard = (iw_handler *)rndis_iw_handler,
  1812. .private = (iw_handler *)rndis_wext_private_handler,
  1813. .private_args = (struct iw_priv_args *)rndis_wext_private_args,
  1814. .get_wireless_stats = rndis_get_wireless_stats,
  1815. };
  1816. static void rndis_wext_worker(struct work_struct *work)
  1817. {
  1818. struct rndis_wext_private *priv =
  1819. container_of(work, struct rndis_wext_private, work);
  1820. struct usbnet *usbdev = priv->usbdev;
  1821. union iwreq_data evt;
  1822. unsigned char bssid[ETH_ALEN];
  1823. struct ndis_80211_assoc_info *info;
  1824. int assoc_size = sizeof(*info) + IW_CUSTOM_MAX + 32;
  1825. int ret, offset;
  1826. if (test_and_clear_bit(WORK_LINK_UP, &priv->work_pending)) {
  1827. netif_carrier_on(usbdev->net);
  1828. info = kzalloc(assoc_size, GFP_KERNEL);
  1829. if (!info)
  1830. goto get_bssid;
  1831. /* Get association info IEs from device and send them back to
  1832. * userspace. */
  1833. ret = get_association_info(usbdev, info, assoc_size);
  1834. if (!ret) {
  1835. evt.data.length = le32_to_cpu(info->req_ie_length);
  1836. if (evt.data.length > 0) {
  1837. offset = le32_to_cpu(info->offset_req_ies);
  1838. wireless_send_event(usbdev->net,
  1839. IWEVASSOCREQIE, &evt,
  1840. (char *)info + offset);
  1841. }
  1842. evt.data.length = le32_to_cpu(info->resp_ie_length);
  1843. if (evt.data.length > 0) {
  1844. offset = le32_to_cpu(info->offset_resp_ies);
  1845. wireless_send_event(usbdev->net,
  1846. IWEVASSOCRESPIE, &evt,
  1847. (char *)info + offset);
  1848. }
  1849. }
  1850. kfree(info);
  1851. get_bssid:
  1852. ret = get_bssid(usbdev, bssid);
  1853. if (!ret) {
  1854. evt.data.flags = 0;
  1855. evt.data.length = 0;
  1856. memcpy(evt.ap_addr.sa_data, bssid, ETH_ALEN);
  1857. wireless_send_event(usbdev->net, SIOCGIWAP, &evt, NULL);
  1858. }
  1859. }
  1860. if (test_and_clear_bit(WORK_LINK_DOWN, &priv->work_pending)) {
  1861. netif_carrier_off(usbdev->net);
  1862. evt.data.flags = 0;
  1863. evt.data.length = 0;
  1864. memset(evt.ap_addr.sa_data, 0, ETH_ALEN);
  1865. wireless_send_event(usbdev->net, SIOCGIWAP, &evt, NULL);
  1866. }
  1867. if (test_and_clear_bit(WORK_SET_MULTICAST_LIST, &priv->work_pending))
  1868. set_multicast_list(usbdev);
  1869. }
  1870. static void rndis_wext_set_multicast_list(struct net_device *dev)
  1871. {
  1872. struct usbnet *usbdev = netdev_priv(dev);
  1873. struct rndis_wext_private *priv = get_rndis_wext_priv(usbdev);
  1874. if (test_bit(WORK_SET_MULTICAST_LIST, &priv->work_pending))
  1875. return;
  1876. set_bit(WORK_SET_MULTICAST_LIST, &priv->work_pending);
  1877. queue_work(priv->workqueue, &priv->work);
  1878. }
  1879. static void rndis_wext_link_change(struct usbnet *usbdev, int state)
  1880. {
  1881. struct rndis_wext_private *priv = get_rndis_wext_priv(usbdev);
  1882. /* queue work to avoid recursive calls into rndis_command */
  1883. set_bit(state ? WORK_LINK_UP : WORK_LINK_DOWN, &priv->work_pending);
  1884. queue_work(priv->workqueue, &priv->work);
  1885. }
  1886. static int rndis_wext_get_caps(struct usbnet *usbdev)
  1887. {
  1888. struct {
  1889. __le32 num_items;
  1890. __le32 items[8];
  1891. } networks_supported;
  1892. int len, retval, i, n;
  1893. __le32 tx_power;
  1894. struct rndis_wext_private *priv = get_rndis_wext_priv(usbdev);
  1895. /* determine if supports setting txpower */
  1896. len = sizeof(tx_power);
  1897. retval = rndis_query_oid(usbdev, OID_802_11_TX_POWER_LEVEL, &tx_power,
  1898. &len);
  1899. if (retval == 0 && le32_to_cpu(tx_power) != 0xFF)
  1900. priv->caps |= CAP_SUPPORT_TXPOWER;
  1901. /* determine supported modes */
  1902. len = sizeof(networks_supported);
  1903. retval = rndis_query_oid(usbdev, OID_802_11_NETWORK_TYPES_SUPPORTED,
  1904. &networks_supported, &len);
  1905. if (retval >= 0) {
  1906. n = le32_to_cpu(networks_supported.num_items);
  1907. if (n > 8)
  1908. n = 8;
  1909. for (i = 0; i < n; i++) {
  1910. switch (le32_to_cpu(networks_supported.items[i])) {
  1911. case ndis_80211_type_freq_hop:
  1912. case ndis_80211_type_direct_seq:
  1913. priv->caps |= CAP_MODE_80211B;
  1914. break;
  1915. case ndis_80211_type_ofdm_a:
  1916. priv->caps |= CAP_MODE_80211A;
  1917. break;
  1918. case ndis_80211_type_ofdm_g:
  1919. priv->caps |= CAP_MODE_80211G;
  1920. break;
  1921. }
  1922. }
  1923. if (priv->caps & CAP_MODE_80211A)
  1924. strcat(priv->name, "a");
  1925. if (priv->caps & CAP_MODE_80211B)
  1926. strcat(priv->name, "b");
  1927. if (priv->caps & CAP_MODE_80211G)
  1928. strcat(priv->name, "g");
  1929. }
  1930. return retval;
  1931. }
  1932. #define STATS_UPDATE_JIFFIES (HZ)
  1933. static void rndis_update_wireless_stats(struct work_struct *work)
  1934. {
  1935. struct rndis_wext_private *priv =
  1936. container_of(work, struct rndis_wext_private, stats_work.work);
  1937. struct usbnet *usbdev = priv->usbdev;
  1938. struct iw_statistics iwstats;
  1939. __le32 rssi, tmp;
  1940. int len, ret, j;
  1941. unsigned long flags;
  1942. int update_jiffies = STATS_UPDATE_JIFFIES;
  1943. void *buf;
  1944. spin_lock_irqsave(&priv->stats_lock, flags);
  1945. memcpy(&iwstats, &priv->privstats, sizeof(iwstats));
  1946. spin_unlock_irqrestore(&priv->stats_lock, flags);
  1947. /* only update stats when connected */
  1948. if (!is_associated(usbdev)) {
  1949. iwstats.qual.qual = 0;
  1950. iwstats.qual.level = 0;
  1951. iwstats.qual.updated = IW_QUAL_QUAL_UPDATED
  1952. | IW_QUAL_LEVEL_UPDATED
  1953. | IW_QUAL_NOISE_INVALID
  1954. | IW_QUAL_QUAL_INVALID
  1955. | IW_QUAL_LEVEL_INVALID;
  1956. goto end;
  1957. }
  1958. len = sizeof(rssi);
  1959. ret = rndis_query_oid(usbdev, OID_802_11_RSSI, &rssi, &len);
  1960. devdbg(usbdev, "stats: OID_802_11_RSSI -> %d, rssi:%d", ret,
  1961. le32_to_cpu(rssi));
  1962. if (ret == 0) {
  1963. memset(&iwstats.qual, 0, sizeof(iwstats.qual));
  1964. iwstats.qual.qual = level_to_qual(le32_to_cpu(rssi));
  1965. iwstats.qual.level = le32_to_cpu(rssi);
  1966. iwstats.qual.updated = IW_QUAL_QUAL_UPDATED
  1967. | IW_QUAL_LEVEL_UPDATED
  1968. | IW_QUAL_NOISE_INVALID;
  1969. }
  1970. memset(&iwstats.discard, 0, sizeof(iwstats.discard));
  1971. len = sizeof(tmp);
  1972. ret = rndis_query_oid(usbdev, OID_GEN_XMIT_ERROR, &tmp, &len);
  1973. if (ret == 0)
  1974. iwstats.discard.misc += le32_to_cpu(tmp);
  1975. len = sizeof(tmp);
  1976. ret = rndis_query_oid(usbdev, OID_GEN_RCV_ERROR, &tmp, &len);
  1977. if (ret == 0)
  1978. iwstats.discard.misc += le32_to_cpu(tmp);
  1979. len = sizeof(tmp);
  1980. ret = rndis_query_oid(usbdev, OID_GEN_RCV_NO_BUFFER, &tmp, &len);
  1981. if (ret == 0)
  1982. iwstats.discard.misc += le32_to_cpu(tmp);
  1983. /* Workaround transfer stalls on poor quality links.
  1984. * TODO: find right way to fix these stalls (as stalls do not happen
  1985. * with ndiswrapper/windows driver). */
  1986. if (iwstats.qual.qual <= 25) {
  1987. /* Decrease stats worker interval to catch stalls.
  1988. * faster. Faster than 400-500ms causes packet loss,
  1989. * Slower doesn't catch stalls fast enough.
  1990. */
  1991. j = msecs_to_jiffies(priv->param_workaround_interval);
  1992. if (j > STATS_UPDATE_JIFFIES)
  1993. j = STATS_UPDATE_JIFFIES;
  1994. else if (j <= 0)
  1995. j = 1;
  1996. update_jiffies = j;
  1997. /* Send scan OID. Use of both OIDs is required to get device
  1998. * working.
  1999. */
  2000. tmp = ccpu2(1);
  2001. rndis_set_oid(usbdev, OID_802_11_BSSID_LIST_SCAN, &tmp,
  2002. sizeof(tmp));
  2003. len = CONTROL_BUFFER_SIZE;
  2004. buf = kmalloc(len, GFP_KERNEL);
  2005. if (!buf)
  2006. goto end;
  2007. rndis_query_oid(usbdev, OID_802_11_BSSID_LIST, buf, &len);
  2008. kfree(buf);
  2009. }
  2010. end:
  2011. spin_lock_irqsave(&priv->stats_lock, flags);
  2012. memcpy(&priv->privstats, &iwstats, sizeof(iwstats));
  2013. spin_unlock_irqrestore(&priv->stats_lock, flags);
  2014. if (update_jiffies >= HZ)
  2015. update_jiffies = round_jiffies_relative(update_jiffies);
  2016. else {
  2017. j = round_jiffies_relative(update_jiffies);
  2018. if (abs(j - update_jiffies) <= 10)
  2019. update_jiffies = j;
  2020. }
  2021. queue_delayed_work(priv->workqueue, &priv->stats_work, update_jiffies);
  2022. }
  2023. static int bcm4320_early_init(struct usbnet *usbdev)
  2024. {
  2025. struct rndis_wext_private *priv = get_rndis_wext_priv(usbdev);
  2026. char buf[8];
  2027. /* Early initialization settings, setting these won't have effect
  2028. * if called after generic_rndis_bind().
  2029. */
  2030. priv->param_country[0] = modparam_country[0];
  2031. priv->param_country[1] = modparam_country[1];
  2032. priv->param_country[2] = 0;
  2033. priv->param_frameburst = modparam_frameburst;
  2034. priv->param_afterburner = modparam_afterburner;
  2035. priv->param_power_save = modparam_power_save;
  2036. priv->param_power_output = modparam_power_output;
  2037. priv->param_roamtrigger = modparam_roamtrigger;
  2038. priv->param_roamdelta = modparam_roamdelta;
  2039. priv->param_country[0] = toupper(priv->param_country[0]);
  2040. priv->param_country[1] = toupper(priv->param_country[1]);
  2041. /* doesn't support EU as country code, use FI instead */
  2042. if (!strcmp(priv->param_country, "EU"))
  2043. strcpy(priv->param_country, "FI");
  2044. if (priv->param_power_save < 0)
  2045. priv->param_power_save = 0;
  2046. else if (priv->param_power_save > 2)
  2047. priv->param_power_save = 2;
  2048. if (priv->param_power_output < 0)
  2049. priv->param_power_output = 0;
  2050. else if (priv->param_power_output > 3)
  2051. priv->param_power_output = 3;
  2052. if (priv->param_roamtrigger < -80)
  2053. priv->param_roamtrigger = -80;
  2054. else if (priv->param_roamtrigger > -60)
  2055. priv->param_roamtrigger = -60;
  2056. if (priv->param_roamdelta < 0)
  2057. priv->param_roamdelta = 0;
  2058. else if (priv->param_roamdelta > 2)
  2059. priv->param_roamdelta = 2;
  2060. if (modparam_workaround_interval < 0)
  2061. priv->param_workaround_interval = 500;
  2062. else
  2063. priv->param_workaround_interval = modparam_workaround_interval;
  2064. rndis_set_config_parameter_str(usbdev, "Country", priv->param_country);
  2065. rndis_set_config_parameter_str(usbdev, "FrameBursting",
  2066. priv->param_frameburst ? "1" : "0");
  2067. rndis_set_config_parameter_str(usbdev, "Afterburner",
  2068. priv->param_afterburner ? "1" : "0");
  2069. sprintf(buf, "%d", priv->param_power_save);
  2070. rndis_set_config_parameter_str(usbdev, "PowerSaveMode", buf);
  2071. sprintf(buf, "%d", priv->param_power_output);
  2072. rndis_set_config_parameter_str(usbdev, "PwrOut", buf);
  2073. sprintf(buf, "%d", priv->param_roamtrigger);
  2074. rndis_set_config_parameter_str(usbdev, "RoamTrigger", buf);
  2075. sprintf(buf, "%d", priv->param_roamdelta);
  2076. rndis_set_config_parameter_str(usbdev, "RoamDelta", buf);
  2077. return 0;
  2078. }
  2079. static int rndis_wext_bind(struct usbnet *usbdev, struct usb_interface *intf)
  2080. {
  2081. struct rndis_wext_private *priv;
  2082. int retval, len;
  2083. __le32 tmp;
  2084. /* allocate rndis private data */
  2085. priv = kzalloc(sizeof(struct rndis_wext_private), GFP_KERNEL);
  2086. if (!priv)
  2087. return -ENOMEM;
  2088. /* These have to be initialized before calling generic_rndis_bind().
  2089. * Otherwise we'll be in big trouble in rndis_wext_early_init().
  2090. */
  2091. usbdev->driver_priv = priv;
  2092. strcpy(priv->name, "IEEE802.11");
  2093. usbdev->net->wireless_handlers = &rndis_iw_handlers;
  2094. priv->usbdev = usbdev;
  2095. mutex_init(&priv->command_lock);
  2096. spin_lock_init(&priv->stats_lock);
  2097. /* try bind rndis_host */
  2098. retval = generic_rndis_bind(usbdev, intf, FLAG_RNDIS_PHYM_WIRELESS);
  2099. if (retval < 0)
  2100. goto fail;
  2101. /* generic_rndis_bind set packet filter to multicast_all+
  2102. * promisc mode which doesn't work well for our devices (device
  2103. * picks up rssi to closest station instead of to access point).
  2104. *
  2105. * rndis_host wants to avoid all OID as much as possible
  2106. * so do promisc/multicast handling in rndis_wext.
  2107. */
  2108. usbdev->net->set_multicast_list = rndis_wext_set_multicast_list;
  2109. tmp = RNDIS_PACKET_TYPE_DIRECTED | RNDIS_PACKET_TYPE_BROADCAST;
  2110. retval = rndis_set_oid(usbdev, OID_GEN_CURRENT_PACKET_FILTER, &tmp,
  2111. sizeof(tmp));
  2112. len = sizeof(tmp);
  2113. retval = rndis_query_oid(usbdev, OID_802_3_MAXIMUM_LIST_SIZE, &tmp,
  2114. &len);
  2115. priv->multicast_size = le32_to_cpu(tmp);
  2116. if (retval < 0 || priv->multicast_size < 0)
  2117. priv->multicast_size = 0;
  2118. if (priv->multicast_size > 0)
  2119. usbdev->net->flags |= IFF_MULTICAST;
  2120. else
  2121. usbdev->net->flags &= ~IFF_MULTICAST;
  2122. priv->iwstats.qual.qual = 0;
  2123. priv->iwstats.qual.level = 0;
  2124. priv->iwstats.qual.updated = IW_QUAL_QUAL_UPDATED
  2125. | IW_QUAL_LEVEL_UPDATED
  2126. | IW_QUAL_NOISE_INVALID
  2127. | IW_QUAL_QUAL_INVALID
  2128. | IW_QUAL_LEVEL_INVALID;
  2129. rndis_wext_get_caps(usbdev);
  2130. set_default_iw_params(usbdev);
  2131. /* turn radio on */
  2132. priv->radio_on = 1;
  2133. disassociate(usbdev, 1);
  2134. netif_carrier_off(usbdev->net);
  2135. /* because rndis_command() sleeps we need to use workqueue */
  2136. priv->workqueue = create_singlethread_workqueue("rndis_wlan");
  2137. INIT_DELAYED_WORK(&priv->stats_work, rndis_update_wireless_stats);
  2138. queue_delayed_work(priv->workqueue, &priv->stats_work,
  2139. round_jiffies_relative(STATS_UPDATE_JIFFIES));
  2140. INIT_WORK(&priv->work, rndis_wext_worker);
  2141. return 0;
  2142. fail:
  2143. kfree(priv);
  2144. return retval;
  2145. }
  2146. static void rndis_wext_unbind(struct usbnet *usbdev, struct usb_interface *intf)
  2147. {
  2148. struct rndis_wext_private *priv = get_rndis_wext_priv(usbdev);
  2149. /* turn radio off */
  2150. disassociate(usbdev, 0);
  2151. cancel_delayed_work_sync(&priv->stats_work);
  2152. cancel_work_sync(&priv->work);
  2153. flush_workqueue(priv->workqueue);
  2154. destroy_workqueue(priv->workqueue);
  2155. if (priv && priv->wpa_ie_len)
  2156. kfree(priv->wpa_ie);
  2157. kfree(priv);
  2158. rndis_unbind(usbdev, intf);
  2159. }
  2160. static int rndis_wext_reset(struct usbnet *usbdev)
  2161. {
  2162. return deauthenticate(usbdev);
  2163. }
  2164. static const struct driver_info bcm4320b_info = {
  2165. .description = "Wireless RNDIS device, BCM4320b based",
  2166. .flags = FLAG_WLAN | FLAG_FRAMING_RN | FLAG_NO_SETINT,
  2167. .bind = rndis_wext_bind,
  2168. .unbind = rndis_wext_unbind,
  2169. .status = rndis_status,
  2170. .rx_fixup = rndis_rx_fixup,
  2171. .tx_fixup = rndis_tx_fixup,
  2172. .reset = rndis_wext_reset,
  2173. .early_init = bcm4320_early_init,
  2174. .link_change = rndis_wext_link_change,
  2175. };
  2176. static const struct driver_info bcm4320a_info = {
  2177. .description = "Wireless RNDIS device, BCM4320a based",
  2178. .flags = FLAG_WLAN | FLAG_FRAMING_RN | FLAG_NO_SETINT,
  2179. .bind = rndis_wext_bind,
  2180. .unbind = rndis_wext_unbind,
  2181. .status = rndis_status,
  2182. .rx_fixup = rndis_rx_fixup,
  2183. .tx_fixup = rndis_tx_fixup,
  2184. .reset = rndis_wext_reset,
  2185. .early_init = bcm4320_early_init,
  2186. .link_change = rndis_wext_link_change,
  2187. };
  2188. static const struct driver_info rndis_wext_info = {
  2189. .description = "Wireless RNDIS device",
  2190. .flags = FLAG_WLAN | FLAG_FRAMING_RN | FLAG_NO_SETINT,
  2191. .bind = rndis_wext_bind,
  2192. .unbind = rndis_wext_unbind,
  2193. .status = rndis_status,
  2194. .rx_fixup = rndis_rx_fixup,
  2195. .tx_fixup = rndis_tx_fixup,
  2196. .reset = rndis_wext_reset,
  2197. .early_init = bcm4320_early_init,
  2198. .link_change = rndis_wext_link_change,
  2199. };
  2200. /*-------------------------------------------------------------------------*/
  2201. static const struct usb_device_id products [] = {
  2202. #define RNDIS_MASTER_INTERFACE \
  2203. .bInterfaceClass = USB_CLASS_COMM, \
  2204. .bInterfaceSubClass = 2 /* ACM */, \
  2205. .bInterfaceProtocol = 0x0ff
  2206. /* INF driver for these devices have DriverVer >= 4.xx.xx.xx and many custom
  2207. * parameters available. Chipset marked as 'BCM4320SKFBG' in NDISwrapper-wiki.
  2208. */
  2209. {
  2210. .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
  2211. | USB_DEVICE_ID_MATCH_DEVICE,
  2212. .idVendor = 0x0411,
  2213. .idProduct = 0x00bc, /* Buffalo WLI-U2-KG125S */
  2214. RNDIS_MASTER_INTERFACE,
  2215. .driver_info = (unsigned long) &bcm4320b_info,
  2216. }, {
  2217. .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
  2218. | USB_DEVICE_ID_MATCH_DEVICE,
  2219. .idVendor = 0x0baf,
  2220. .idProduct = 0x011b, /* U.S. Robotics USR5421 */
  2221. RNDIS_MASTER_INTERFACE,
  2222. .driver_info = (unsigned long) &bcm4320b_info,
  2223. }, {
  2224. .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
  2225. | USB_DEVICE_ID_MATCH_DEVICE,
  2226. .idVendor = 0x050d,
  2227. .idProduct = 0x011b, /* Belkin F5D7051 */
  2228. RNDIS_MASTER_INTERFACE,
  2229. .driver_info = (unsigned long) &bcm4320b_info,
  2230. }, {
  2231. .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
  2232. | USB_DEVICE_ID_MATCH_DEVICE,
  2233. .idVendor = 0x1799, /* Belkin has two vendor ids */
  2234. .idProduct = 0x011b, /* Belkin F5D7051 */
  2235. RNDIS_MASTER_INTERFACE,
  2236. .driver_info = (unsigned long) &bcm4320b_info,
  2237. }, {
  2238. .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
  2239. | USB_DEVICE_ID_MATCH_DEVICE,
  2240. .idVendor = 0x13b1,
  2241. .idProduct = 0x0014, /* Linksys WUSB54GSv2 */
  2242. RNDIS_MASTER_INTERFACE,
  2243. .driver_info = (unsigned long) &bcm4320b_info,
  2244. }, {
  2245. .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
  2246. | USB_DEVICE_ID_MATCH_DEVICE,
  2247. .idVendor = 0x13b1,
  2248. .idProduct = 0x0026, /* Linksys WUSB54GSC */
  2249. RNDIS_MASTER_INTERFACE,
  2250. .driver_info = (unsigned long) &bcm4320b_info,
  2251. }, {
  2252. .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
  2253. | USB_DEVICE_ID_MATCH_DEVICE,
  2254. .idVendor = 0x0b05,
  2255. .idProduct = 0x1717, /* Asus WL169gE */
  2256. RNDIS_MASTER_INTERFACE,
  2257. .driver_info = (unsigned long) &bcm4320b_info,
  2258. }, {
  2259. .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
  2260. | USB_DEVICE_ID_MATCH_DEVICE,
  2261. .idVendor = 0x0a5c,
  2262. .idProduct = 0xd11b, /* Eminent EM4045 */
  2263. RNDIS_MASTER_INTERFACE,
  2264. .driver_info = (unsigned long) &bcm4320b_info,
  2265. }, {
  2266. .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
  2267. | USB_DEVICE_ID_MATCH_DEVICE,
  2268. .idVendor = 0x1690,
  2269. .idProduct = 0x0715, /* BT Voyager 1055 */
  2270. RNDIS_MASTER_INTERFACE,
  2271. .driver_info = (unsigned long) &bcm4320b_info,
  2272. },
  2273. /* These devices have DriverVer < 4.xx.xx.xx and do not have any custom
  2274. * parameters available, hardware probably contain older firmware version with
  2275. * no way of updating. Chipset marked as 'BCM4320????' in NDISwrapper-wiki.
  2276. */
  2277. {
  2278. .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
  2279. | USB_DEVICE_ID_MATCH_DEVICE,
  2280. .idVendor = 0x13b1,
  2281. .idProduct = 0x000e, /* Linksys WUSB54GSv1 */
  2282. RNDIS_MASTER_INTERFACE,
  2283. .driver_info = (unsigned long) &bcm4320a_info,
  2284. }, {
  2285. .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
  2286. | USB_DEVICE_ID_MATCH_DEVICE,
  2287. .idVendor = 0x0baf,
  2288. .idProduct = 0x0111, /* U.S. Robotics USR5420 */
  2289. RNDIS_MASTER_INTERFACE,
  2290. .driver_info = (unsigned long) &bcm4320a_info,
  2291. }, {
  2292. .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
  2293. | USB_DEVICE_ID_MATCH_DEVICE,
  2294. .idVendor = 0x0411,
  2295. .idProduct = 0x004b, /* BUFFALO WLI-USB-G54 */
  2296. RNDIS_MASTER_INTERFACE,
  2297. .driver_info = (unsigned long) &bcm4320a_info,
  2298. },
  2299. /* Generic Wireless RNDIS devices that we don't have exact
  2300. * idVendor/idProduct/chip yet.
  2301. */
  2302. {
  2303. /* RNDIS is MSFT's un-official variant of CDC ACM */
  2304. USB_INTERFACE_INFO(USB_CLASS_COMM, 2 /* ACM */, 0x0ff),
  2305. .driver_info = (unsigned long) &rndis_wext_info,
  2306. }, {
  2307. /* "ActiveSync" is an undocumented variant of RNDIS, used in WM5 */
  2308. USB_INTERFACE_INFO(USB_CLASS_MISC, 1, 1),
  2309. .driver_info = (unsigned long) &rndis_wext_info,
  2310. },
  2311. { }, // END
  2312. };
  2313. MODULE_DEVICE_TABLE(usb, products);
  2314. static struct usb_driver rndis_wlan_driver = {
  2315. .name = "rndis_wlan",
  2316. .id_table = products,
  2317. .probe = usbnet_probe,
  2318. .disconnect = usbnet_disconnect,
  2319. .suspend = usbnet_suspend,
  2320. .resume = usbnet_resume,
  2321. };
  2322. static int __init rndis_wlan_init(void)
  2323. {
  2324. return usb_register(&rndis_wlan_driver);
  2325. }
  2326. module_init(rndis_wlan_init);
  2327. static void __exit rndis_wlan_exit(void)
  2328. {
  2329. usb_deregister(&rndis_wlan_driver);
  2330. }
  2331. module_exit(rndis_wlan_exit);
  2332. MODULE_AUTHOR("Bjorge Dijkstra");
  2333. MODULE_AUTHOR("Jussi Kivilinna");
  2334. MODULE_DESCRIPTION("Driver for RNDIS based USB Wireless adapters");
  2335. MODULE_LICENSE("GPL");