rndis_wlan.c 75 KB

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