rndis_wlan.c 75 KB

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