rndis_wlan.c 92 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420
  1. /*
  2. * Driver for RNDIS based wireless USB devices.
  3. *
  4. * Copyright (C) 2007 by Bjorge Dijkstra <bjd@jooz.net>
  5. * Copyright (C) 2008-2009 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 <net/cfg80211.h>
  44. #include <linux/usb/usbnet.h>
  45. #include <linux/usb/rndis_host.h>
  46. /* NOTE: All these are settings for Broadcom chipset */
  47. static char modparam_country[4] = "EU";
  48. module_param_string(country, modparam_country, 4, 0444);
  49. MODULE_PARM_DESC(country, "Country code (ISO 3166-1 alpha-2), default: EU");
  50. static int modparam_frameburst = 1;
  51. module_param_named(frameburst, modparam_frameburst, int, 0444);
  52. MODULE_PARM_DESC(frameburst, "enable frame bursting (default: on)");
  53. static int modparam_afterburner = 0;
  54. module_param_named(afterburner, modparam_afterburner, int, 0444);
  55. MODULE_PARM_DESC(afterburner,
  56. "enable afterburner aka '125 High Speed Mode' (default: off)");
  57. static int modparam_power_save = 0;
  58. module_param_named(power_save, modparam_power_save, int, 0444);
  59. MODULE_PARM_DESC(power_save,
  60. "set power save mode: 0=off, 1=on, 2=fast (default: off)");
  61. static int modparam_power_output = 3;
  62. module_param_named(power_output, modparam_power_output, int, 0444);
  63. MODULE_PARM_DESC(power_output,
  64. "set power output: 0=25%, 1=50%, 2=75%, 3=100% (default: 100%)");
  65. static int modparam_roamtrigger = -70;
  66. module_param_named(roamtrigger, modparam_roamtrigger, int, 0444);
  67. MODULE_PARM_DESC(roamtrigger,
  68. "set roaming dBm trigger: -80=optimize for distance, "
  69. "-60=bandwidth (default: -70)");
  70. static int modparam_roamdelta = 1;
  71. module_param_named(roamdelta, modparam_roamdelta, int, 0444);
  72. MODULE_PARM_DESC(roamdelta,
  73. "set roaming tendency: 0=aggressive, 1=moderate, "
  74. "2=conservative (default: moderate)");
  75. static int modparam_workaround_interval;
  76. module_param_named(workaround_interval, modparam_workaround_interval,
  77. int, 0444);
  78. MODULE_PARM_DESC(workaround_interval,
  79. "set stall workaround interval in msecs (0=disabled) (default: 0)");
  80. /* various RNDIS OID defs */
  81. #define OID_GEN_LINK_SPEED cpu_to_le32(0x00010107)
  82. #define OID_GEN_RNDIS_CONFIG_PARAMETER cpu_to_le32(0x0001021b)
  83. #define OID_GEN_XMIT_OK cpu_to_le32(0x00020101)
  84. #define OID_GEN_RCV_OK cpu_to_le32(0x00020102)
  85. #define OID_GEN_XMIT_ERROR cpu_to_le32(0x00020103)
  86. #define OID_GEN_RCV_ERROR cpu_to_le32(0x00020104)
  87. #define OID_GEN_RCV_NO_BUFFER cpu_to_le32(0x00020105)
  88. #define OID_802_3_CURRENT_ADDRESS cpu_to_le32(0x01010102)
  89. #define OID_802_3_MULTICAST_LIST cpu_to_le32(0x01010103)
  90. #define OID_802_3_MAXIMUM_LIST_SIZE cpu_to_le32(0x01010104)
  91. #define OID_802_11_BSSID cpu_to_le32(0x0d010101)
  92. #define OID_802_11_SSID cpu_to_le32(0x0d010102)
  93. #define OID_802_11_INFRASTRUCTURE_MODE cpu_to_le32(0x0d010108)
  94. #define OID_802_11_ADD_WEP cpu_to_le32(0x0d010113)
  95. #define OID_802_11_REMOVE_WEP cpu_to_le32(0x0d010114)
  96. #define OID_802_11_DISASSOCIATE cpu_to_le32(0x0d010115)
  97. #define OID_802_11_AUTHENTICATION_MODE cpu_to_le32(0x0d010118)
  98. #define OID_802_11_PRIVACY_FILTER cpu_to_le32(0x0d010119)
  99. #define OID_802_11_BSSID_LIST_SCAN cpu_to_le32(0x0d01011a)
  100. #define OID_802_11_ENCRYPTION_STATUS cpu_to_le32(0x0d01011b)
  101. #define OID_802_11_ADD_KEY cpu_to_le32(0x0d01011d)
  102. #define OID_802_11_REMOVE_KEY cpu_to_le32(0x0d01011e)
  103. #define OID_802_11_ASSOCIATION_INFORMATION cpu_to_le32(0x0d01011f)
  104. #define OID_802_11_CAPABILITY cpu_to_le32(0x0d010122)
  105. #define OID_802_11_PMKID cpu_to_le32(0x0d010123)
  106. #define OID_802_11_NETWORK_TYPES_SUPPORTED cpu_to_le32(0x0d010203)
  107. #define OID_802_11_NETWORK_TYPE_IN_USE cpu_to_le32(0x0d010204)
  108. #define OID_802_11_TX_POWER_LEVEL cpu_to_le32(0x0d010205)
  109. #define OID_802_11_RSSI cpu_to_le32(0x0d010206)
  110. #define OID_802_11_RSSI_TRIGGER cpu_to_le32(0x0d010207)
  111. #define OID_802_11_FRAGMENTATION_THRESHOLD cpu_to_le32(0x0d010209)
  112. #define OID_802_11_RTS_THRESHOLD cpu_to_le32(0x0d01020a)
  113. #define OID_802_11_SUPPORTED_RATES cpu_to_le32(0x0d01020e)
  114. #define OID_802_11_CONFIGURATION cpu_to_le32(0x0d010211)
  115. #define OID_802_11_BSSID_LIST cpu_to_le32(0x0d010217)
  116. /* Typical noise/maximum signal level values taken from ndiswrapper iw_ndis.h */
  117. #define WL_NOISE -96 /* typical noise level in dBm */
  118. #define WL_SIGMAX -32 /* typical maximum signal level in dBm */
  119. /* Assume that Broadcom 4320 (only chipset at time of writing known to be
  120. * based on wireless rndis) has default txpower of 13dBm.
  121. * This value is from Linksys WUSB54GSC User Guide, Appendix F: Specifications.
  122. * 100% : 20 mW ~ 13dBm
  123. * 75% : 15 mW ~ 12dBm
  124. * 50% : 10 mW ~ 10dBm
  125. * 25% : 5 mW ~ 7dBm
  126. */
  127. #define BCM4320_DEFAULT_TXPOWER_DBM_100 13
  128. #define BCM4320_DEFAULT_TXPOWER_DBM_75 12
  129. #define BCM4320_DEFAULT_TXPOWER_DBM_50 10
  130. #define BCM4320_DEFAULT_TXPOWER_DBM_25 7
  131. /* codes for "status" field of completion messages */
  132. #define RNDIS_STATUS_ADAPTER_NOT_READY cpu_to_le32(0xc0010011)
  133. #define RNDIS_STATUS_ADAPTER_NOT_OPEN cpu_to_le32(0xc0010012)
  134. /* NDIS data structures. Taken from wpa_supplicant driver_ndis.c
  135. * slightly modified for datatype endianess, etc
  136. */
  137. #define NDIS_802_11_LENGTH_SSID 32
  138. #define NDIS_802_11_LENGTH_RATES 8
  139. #define NDIS_802_11_LENGTH_RATES_EX 16
  140. enum ndis_80211_net_type {
  141. NDIS_80211_TYPE_FREQ_HOP,
  142. NDIS_80211_TYPE_DIRECT_SEQ,
  143. NDIS_80211_TYPE_OFDM_A,
  144. NDIS_80211_TYPE_OFDM_G
  145. };
  146. enum ndis_80211_net_infra {
  147. NDIS_80211_INFRA_ADHOC,
  148. NDIS_80211_INFRA_INFRA,
  149. NDIS_80211_INFRA_AUTO_UNKNOWN
  150. };
  151. enum ndis_80211_auth_mode {
  152. NDIS_80211_AUTH_OPEN,
  153. NDIS_80211_AUTH_SHARED,
  154. NDIS_80211_AUTH_AUTO_SWITCH,
  155. NDIS_80211_AUTH_WPA,
  156. NDIS_80211_AUTH_WPA_PSK,
  157. NDIS_80211_AUTH_WPA_NONE,
  158. NDIS_80211_AUTH_WPA2,
  159. NDIS_80211_AUTH_WPA2_PSK
  160. };
  161. enum ndis_80211_encr_status {
  162. NDIS_80211_ENCR_WEP_ENABLED,
  163. NDIS_80211_ENCR_DISABLED,
  164. NDIS_80211_ENCR_WEP_KEY_ABSENT,
  165. NDIS_80211_ENCR_NOT_SUPPORTED,
  166. NDIS_80211_ENCR_TKIP_ENABLED,
  167. NDIS_80211_ENCR_TKIP_KEY_ABSENT,
  168. NDIS_80211_ENCR_CCMP_ENABLED,
  169. NDIS_80211_ENCR_CCMP_KEY_ABSENT
  170. };
  171. enum ndis_80211_priv_filter {
  172. NDIS_80211_PRIV_ACCEPT_ALL,
  173. NDIS_80211_PRIV_8021X_WEP
  174. };
  175. enum ndis_80211_status_type {
  176. NDIS_80211_STATUSTYPE_AUTHENTICATION,
  177. NDIS_80211_STATUSTYPE_MEDIASTREAMMODE,
  178. NDIS_80211_STATUSTYPE_PMKID_CANDIDATELIST,
  179. NDIS_80211_STATUSTYPE_RADIOSTATE,
  180. };
  181. enum ndis_80211_media_stream_mode {
  182. NDIS_80211_MEDIA_STREAM_OFF,
  183. NDIS_80211_MEDIA_STREAM_ON
  184. };
  185. enum ndis_80211_radio_status {
  186. NDIS_80211_RADIO_STATUS_ON,
  187. NDIS_80211_RADIO_STATUS_HARDWARE_OFF,
  188. NDIS_80211_RADIO_STATUS_SOFTWARE_OFF,
  189. };
  190. enum ndis_80211_addkey_bits {
  191. NDIS_80211_ADDKEY_8021X_AUTH = cpu_to_le32(1 << 28),
  192. NDIS_80211_ADDKEY_SET_INIT_RECV_SEQ = cpu_to_le32(1 << 29),
  193. NDIS_80211_ADDKEY_PAIRWISE_KEY = cpu_to_le32(1 << 30),
  194. NDIS_80211_ADDKEY_TRANSMIT_KEY = cpu_to_le32(1 << 31)
  195. };
  196. enum ndis_80211_addwep_bits {
  197. NDIS_80211_ADDWEP_PERCLIENT_KEY = cpu_to_le32(1 << 30),
  198. NDIS_80211_ADDWEP_TRANSMIT_KEY = cpu_to_le32(1 << 31)
  199. };
  200. struct ndis_80211_auth_request {
  201. __le32 length;
  202. u8 bssid[6];
  203. u8 padding[2];
  204. __le32 flags;
  205. } __attribute__((packed));
  206. struct ndis_80211_pmkid_candidate {
  207. u8 bssid[6];
  208. u8 padding[2];
  209. __le32 flags;
  210. } __attribute__((packed));
  211. struct ndis_80211_pmkid_cand_list {
  212. __le32 version;
  213. __le32 num_candidates;
  214. struct ndis_80211_pmkid_candidate candidate_list[0];
  215. } __attribute__((packed));
  216. struct ndis_80211_status_indication {
  217. __le32 status_type;
  218. union {
  219. __le32 media_stream_mode;
  220. __le32 radio_status;
  221. struct ndis_80211_auth_request auth_request[0];
  222. struct ndis_80211_pmkid_cand_list cand_list;
  223. } u;
  224. } __attribute__((packed));
  225. struct ndis_80211_ssid {
  226. __le32 length;
  227. u8 essid[NDIS_802_11_LENGTH_SSID];
  228. } __attribute__((packed));
  229. struct ndis_80211_conf_freq_hop {
  230. __le32 length;
  231. __le32 hop_pattern;
  232. __le32 hop_set;
  233. __le32 dwell_time;
  234. } __attribute__((packed));
  235. struct ndis_80211_conf {
  236. __le32 length;
  237. __le32 beacon_period;
  238. __le32 atim_window;
  239. __le32 ds_config;
  240. struct ndis_80211_conf_freq_hop fh_config;
  241. } __attribute__((packed));
  242. struct ndis_80211_bssid_ex {
  243. __le32 length;
  244. u8 mac[6];
  245. u8 padding[2];
  246. struct ndis_80211_ssid ssid;
  247. __le32 privacy;
  248. __le32 rssi;
  249. __le32 net_type;
  250. struct ndis_80211_conf config;
  251. __le32 net_infra;
  252. u8 rates[NDIS_802_11_LENGTH_RATES_EX];
  253. __le32 ie_length;
  254. u8 ies[0];
  255. } __attribute__((packed));
  256. struct ndis_80211_bssid_list_ex {
  257. __le32 num_items;
  258. struct ndis_80211_bssid_ex bssid[0];
  259. } __attribute__((packed));
  260. struct ndis_80211_fixed_ies {
  261. u8 timestamp[8];
  262. __le16 beacon_interval;
  263. __le16 capabilities;
  264. } __attribute__((packed));
  265. struct ndis_80211_wep_key {
  266. __le32 size;
  267. __le32 index;
  268. __le32 length;
  269. u8 material[32];
  270. } __attribute__((packed));
  271. struct ndis_80211_key {
  272. __le32 size;
  273. __le32 index;
  274. __le32 length;
  275. u8 bssid[6];
  276. u8 padding[6];
  277. u8 rsc[8];
  278. u8 material[32];
  279. } __attribute__((packed));
  280. struct ndis_80211_remove_key {
  281. __le32 size;
  282. __le32 index;
  283. u8 bssid[6];
  284. u8 padding[2];
  285. } __attribute__((packed));
  286. struct ndis_config_param {
  287. __le32 name_offs;
  288. __le32 name_length;
  289. __le32 type;
  290. __le32 value_offs;
  291. __le32 value_length;
  292. } __attribute__((packed));
  293. struct ndis_80211_assoc_info {
  294. __le32 length;
  295. __le16 req_ies;
  296. struct req_ie {
  297. __le16 capa;
  298. __le16 listen_interval;
  299. u8 cur_ap_address[6];
  300. } req_ie;
  301. __le32 req_ie_length;
  302. __le32 offset_req_ies;
  303. __le16 resp_ies;
  304. struct resp_ie {
  305. __le16 capa;
  306. __le16 status_code;
  307. __le16 assoc_id;
  308. } resp_ie;
  309. __le32 resp_ie_length;
  310. __le32 offset_resp_ies;
  311. } __attribute__((packed));
  312. struct ndis_80211_auth_encr_pair {
  313. __le32 auth_mode;
  314. __le32 encr_mode;
  315. } __attribute__((packed));
  316. struct ndis_80211_capability {
  317. __le32 length;
  318. __le32 version;
  319. __le32 num_pmkids;
  320. __le32 num_auth_encr_pair;
  321. struct ndis_80211_auth_encr_pair auth_encr_pair[0];
  322. } __attribute__((packed));
  323. struct ndis_80211_bssid_info {
  324. u8 bssid[6];
  325. u8 pmkid[16];
  326. };
  327. struct ndis_80211_pmkid {
  328. __le32 length;
  329. __le32 bssid_info_count;
  330. struct ndis_80211_bssid_info bssid_info[0];
  331. };
  332. /*
  333. * private data
  334. */
  335. #define NET_TYPE_11FB 0
  336. #define CAP_MODE_80211A 1
  337. #define CAP_MODE_80211B 2
  338. #define CAP_MODE_80211G 4
  339. #define CAP_MODE_MASK 7
  340. #define WORK_LINK_UP (1<<0)
  341. #define WORK_LINK_DOWN (1<<1)
  342. #define WORK_SET_MULTICAST_LIST (1<<2)
  343. #define RNDIS_WLAN_ALG_NONE 0
  344. #define RNDIS_WLAN_ALG_WEP (1<<0)
  345. #define RNDIS_WLAN_ALG_TKIP (1<<1)
  346. #define RNDIS_WLAN_ALG_CCMP (1<<2)
  347. #define RNDIS_WLAN_KEY_MGMT_NONE 0
  348. #define RNDIS_WLAN_KEY_MGMT_802_1X (1<<0)
  349. #define RNDIS_WLAN_KEY_MGMT_PSK (1<<1)
  350. #define COMMAND_BUFFER_SIZE (CONTROL_BUFFER_SIZE + sizeof(struct rndis_set))
  351. static const struct ieee80211_channel rndis_channels[] = {
  352. { .center_freq = 2412 },
  353. { .center_freq = 2417 },
  354. { .center_freq = 2422 },
  355. { .center_freq = 2427 },
  356. { .center_freq = 2432 },
  357. { .center_freq = 2437 },
  358. { .center_freq = 2442 },
  359. { .center_freq = 2447 },
  360. { .center_freq = 2452 },
  361. { .center_freq = 2457 },
  362. { .center_freq = 2462 },
  363. { .center_freq = 2467 },
  364. { .center_freq = 2472 },
  365. { .center_freq = 2484 },
  366. };
  367. static const struct ieee80211_rate rndis_rates[] = {
  368. { .bitrate = 10 },
  369. { .bitrate = 20, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
  370. { .bitrate = 55, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
  371. { .bitrate = 110, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
  372. { .bitrate = 60 },
  373. { .bitrate = 90 },
  374. { .bitrate = 120 },
  375. { .bitrate = 180 },
  376. { .bitrate = 240 },
  377. { .bitrate = 360 },
  378. { .bitrate = 480 },
  379. { .bitrate = 540 }
  380. };
  381. static const u32 rndis_cipher_suites[] = {
  382. WLAN_CIPHER_SUITE_WEP40,
  383. WLAN_CIPHER_SUITE_WEP104,
  384. WLAN_CIPHER_SUITE_TKIP,
  385. WLAN_CIPHER_SUITE_CCMP,
  386. };
  387. struct rndis_wlan_encr_key {
  388. int len;
  389. u32 cipher;
  390. u8 material[32];
  391. u8 bssid[ETH_ALEN];
  392. bool pairwise;
  393. bool tx_key;
  394. };
  395. /* RNDIS device private data */
  396. struct rndis_wlan_private {
  397. struct usbnet *usbdev;
  398. struct wireless_dev wdev;
  399. struct cfg80211_scan_request *scan_request;
  400. struct workqueue_struct *workqueue;
  401. struct delayed_work dev_poller_work;
  402. struct delayed_work scan_work;
  403. struct work_struct work;
  404. struct mutex command_lock;
  405. unsigned long work_pending;
  406. int last_qual;
  407. struct ieee80211_supported_band band;
  408. struct ieee80211_channel channels[ARRAY_SIZE(rndis_channels)];
  409. struct ieee80211_rate rates[ARRAY_SIZE(rndis_rates)];
  410. u32 cipher_suites[ARRAY_SIZE(rndis_cipher_suites)];
  411. int caps;
  412. int multicast_size;
  413. /* module parameters */
  414. char param_country[4];
  415. int param_frameburst;
  416. int param_afterburner;
  417. int param_power_save;
  418. int param_power_output;
  419. int param_roamtrigger;
  420. int param_roamdelta;
  421. u32 param_workaround_interval;
  422. /* hardware state */
  423. bool radio_on;
  424. int infra_mode;
  425. bool connected;
  426. u8 bssid[ETH_ALEN];
  427. struct ndis_80211_ssid essid;
  428. __le32 current_command_oid;
  429. /* encryption stuff */
  430. int encr_tx_key_index;
  431. struct rndis_wlan_encr_key encr_keys[4];
  432. int wpa_version;
  433. u8 command_buffer[COMMAND_BUFFER_SIZE];
  434. };
  435. /*
  436. * cfg80211 ops
  437. */
  438. static int rndis_change_virtual_intf(struct wiphy *wiphy,
  439. struct net_device *dev,
  440. enum nl80211_iftype type, u32 *flags,
  441. struct vif_params *params);
  442. static int rndis_scan(struct wiphy *wiphy, struct net_device *dev,
  443. struct cfg80211_scan_request *request);
  444. static int rndis_set_wiphy_params(struct wiphy *wiphy, u32 changed);
  445. static int rndis_set_tx_power(struct wiphy *wiphy, enum tx_power_setting type,
  446. int dbm);
  447. static int rndis_get_tx_power(struct wiphy *wiphy, int *dbm);
  448. static int rndis_connect(struct wiphy *wiphy, struct net_device *dev,
  449. struct cfg80211_connect_params *sme);
  450. static int rndis_disconnect(struct wiphy *wiphy, struct net_device *dev,
  451. u16 reason_code);
  452. static int rndis_join_ibss(struct wiphy *wiphy, struct net_device *dev,
  453. struct cfg80211_ibss_params *params);
  454. static int rndis_leave_ibss(struct wiphy *wiphy, struct net_device *dev);
  455. static int rndis_set_channel(struct wiphy *wiphy,
  456. struct ieee80211_channel *chan, enum nl80211_channel_type channel_type);
  457. static int rndis_add_key(struct wiphy *wiphy, struct net_device *netdev,
  458. u8 key_index, const u8 *mac_addr,
  459. struct key_params *params);
  460. static int rndis_del_key(struct wiphy *wiphy, struct net_device *netdev,
  461. u8 key_index, const u8 *mac_addr);
  462. static int rndis_set_default_key(struct wiphy *wiphy, struct net_device *netdev,
  463. u8 key_index);
  464. static int rndis_get_station(struct wiphy *wiphy, struct net_device *dev,
  465. u8 *mac, struct station_info *sinfo);
  466. static int rndis_dump_station(struct wiphy *wiphy, struct net_device *dev,
  467. int idx, u8 *mac, struct station_info *sinfo);
  468. static int rndis_set_pmksa(struct wiphy *wiphy, struct net_device *netdev,
  469. struct cfg80211_pmksa *pmksa);
  470. static int rndis_del_pmksa(struct wiphy *wiphy, struct net_device *netdev,
  471. struct cfg80211_pmksa *pmksa);
  472. static int rndis_flush_pmksa(struct wiphy *wiphy, struct net_device *netdev);
  473. static struct cfg80211_ops rndis_config_ops = {
  474. .change_virtual_intf = rndis_change_virtual_intf,
  475. .scan = rndis_scan,
  476. .set_wiphy_params = rndis_set_wiphy_params,
  477. .set_tx_power = rndis_set_tx_power,
  478. .get_tx_power = rndis_get_tx_power,
  479. .connect = rndis_connect,
  480. .disconnect = rndis_disconnect,
  481. .join_ibss = rndis_join_ibss,
  482. .leave_ibss = rndis_leave_ibss,
  483. .set_channel = rndis_set_channel,
  484. .add_key = rndis_add_key,
  485. .del_key = rndis_del_key,
  486. .set_default_key = rndis_set_default_key,
  487. .get_station = rndis_get_station,
  488. .dump_station = rndis_dump_station,
  489. .set_pmksa = rndis_set_pmksa,
  490. .del_pmksa = rndis_del_pmksa,
  491. .flush_pmksa = rndis_flush_pmksa,
  492. };
  493. static void *rndis_wiphy_privid = &rndis_wiphy_privid;
  494. static struct rndis_wlan_private *get_rndis_wlan_priv(struct usbnet *dev)
  495. {
  496. return (struct rndis_wlan_private *)dev->driver_priv;
  497. }
  498. static u32 get_bcm4320_power_dbm(struct rndis_wlan_private *priv)
  499. {
  500. switch (priv->param_power_output) {
  501. default:
  502. case 3:
  503. return BCM4320_DEFAULT_TXPOWER_DBM_100;
  504. case 2:
  505. return BCM4320_DEFAULT_TXPOWER_DBM_75;
  506. case 1:
  507. return BCM4320_DEFAULT_TXPOWER_DBM_50;
  508. case 0:
  509. return BCM4320_DEFAULT_TXPOWER_DBM_25;
  510. }
  511. }
  512. static bool is_wpa_key(struct rndis_wlan_private *priv, int idx)
  513. {
  514. int cipher = priv->encr_keys[idx].cipher;
  515. return (cipher == WLAN_CIPHER_SUITE_CCMP ||
  516. cipher == WLAN_CIPHER_SUITE_TKIP);
  517. }
  518. static int rndis_cipher_to_alg(u32 cipher)
  519. {
  520. switch (cipher) {
  521. default:
  522. return RNDIS_WLAN_ALG_NONE;
  523. case WLAN_CIPHER_SUITE_WEP40:
  524. case WLAN_CIPHER_SUITE_WEP104:
  525. return RNDIS_WLAN_ALG_WEP;
  526. case WLAN_CIPHER_SUITE_TKIP:
  527. return RNDIS_WLAN_ALG_TKIP;
  528. case WLAN_CIPHER_SUITE_CCMP:
  529. return RNDIS_WLAN_ALG_CCMP;
  530. }
  531. }
  532. static int rndis_akm_suite_to_key_mgmt(u32 akm_suite)
  533. {
  534. switch (akm_suite) {
  535. default:
  536. return RNDIS_WLAN_KEY_MGMT_NONE;
  537. case WLAN_AKM_SUITE_8021X:
  538. return RNDIS_WLAN_KEY_MGMT_802_1X;
  539. case WLAN_AKM_SUITE_PSK:
  540. return RNDIS_WLAN_KEY_MGMT_PSK;
  541. }
  542. }
  543. #ifdef DEBUG
  544. static const char *oid_to_string(__le32 oid)
  545. {
  546. switch (oid) {
  547. #define OID_STR(oid) case oid: return(#oid)
  548. /* from rndis_host.h */
  549. OID_STR(OID_802_3_PERMANENT_ADDRESS);
  550. OID_STR(OID_GEN_MAXIMUM_FRAME_SIZE);
  551. OID_STR(OID_GEN_CURRENT_PACKET_FILTER);
  552. OID_STR(OID_GEN_PHYSICAL_MEDIUM);
  553. /* from rndis_wlan.c */
  554. OID_STR(OID_GEN_LINK_SPEED);
  555. OID_STR(OID_GEN_RNDIS_CONFIG_PARAMETER);
  556. OID_STR(OID_GEN_XMIT_OK);
  557. OID_STR(OID_GEN_RCV_OK);
  558. OID_STR(OID_GEN_XMIT_ERROR);
  559. OID_STR(OID_GEN_RCV_ERROR);
  560. OID_STR(OID_GEN_RCV_NO_BUFFER);
  561. OID_STR(OID_802_3_CURRENT_ADDRESS);
  562. OID_STR(OID_802_3_MULTICAST_LIST);
  563. OID_STR(OID_802_3_MAXIMUM_LIST_SIZE);
  564. OID_STR(OID_802_11_BSSID);
  565. OID_STR(OID_802_11_SSID);
  566. OID_STR(OID_802_11_INFRASTRUCTURE_MODE);
  567. OID_STR(OID_802_11_ADD_WEP);
  568. OID_STR(OID_802_11_REMOVE_WEP);
  569. OID_STR(OID_802_11_DISASSOCIATE);
  570. OID_STR(OID_802_11_AUTHENTICATION_MODE);
  571. OID_STR(OID_802_11_PRIVACY_FILTER);
  572. OID_STR(OID_802_11_BSSID_LIST_SCAN);
  573. OID_STR(OID_802_11_ENCRYPTION_STATUS);
  574. OID_STR(OID_802_11_ADD_KEY);
  575. OID_STR(OID_802_11_REMOVE_KEY);
  576. OID_STR(OID_802_11_ASSOCIATION_INFORMATION);
  577. OID_STR(OID_802_11_PMKID);
  578. OID_STR(OID_802_11_NETWORK_TYPES_SUPPORTED);
  579. OID_STR(OID_802_11_NETWORK_TYPE_IN_USE);
  580. OID_STR(OID_802_11_TX_POWER_LEVEL);
  581. OID_STR(OID_802_11_RSSI);
  582. OID_STR(OID_802_11_RSSI_TRIGGER);
  583. OID_STR(OID_802_11_FRAGMENTATION_THRESHOLD);
  584. OID_STR(OID_802_11_RTS_THRESHOLD);
  585. OID_STR(OID_802_11_SUPPORTED_RATES);
  586. OID_STR(OID_802_11_CONFIGURATION);
  587. OID_STR(OID_802_11_BSSID_LIST);
  588. #undef OID_STR
  589. }
  590. return "?";
  591. }
  592. #else
  593. static const char *oid_to_string(__le32 oid)
  594. {
  595. return "?";
  596. }
  597. #endif
  598. /* translate error code */
  599. static int rndis_error_status(__le32 rndis_status)
  600. {
  601. int ret = -EINVAL;
  602. switch (rndis_status) {
  603. case RNDIS_STATUS_SUCCESS:
  604. ret = 0;
  605. break;
  606. case RNDIS_STATUS_FAILURE:
  607. case RNDIS_STATUS_INVALID_DATA:
  608. ret = -EINVAL;
  609. break;
  610. case RNDIS_STATUS_NOT_SUPPORTED:
  611. ret = -EOPNOTSUPP;
  612. break;
  613. case RNDIS_STATUS_ADAPTER_NOT_READY:
  614. case RNDIS_STATUS_ADAPTER_NOT_OPEN:
  615. ret = -EBUSY;
  616. break;
  617. }
  618. return ret;
  619. }
  620. static int rndis_query_oid(struct usbnet *dev, __le32 oid, void *data, int *len)
  621. {
  622. struct rndis_wlan_private *priv = get_rndis_wlan_priv(dev);
  623. union {
  624. void *buf;
  625. struct rndis_msg_hdr *header;
  626. struct rndis_query *get;
  627. struct rndis_query_c *get_c;
  628. } u;
  629. int ret, buflen;
  630. int resplen, respoffs, copylen;
  631. buflen = *len + sizeof(*u.get);
  632. if (buflen < CONTROL_BUFFER_SIZE)
  633. buflen = CONTROL_BUFFER_SIZE;
  634. if (buflen > COMMAND_BUFFER_SIZE) {
  635. u.buf = kmalloc(buflen, GFP_KERNEL);
  636. if (!u.buf)
  637. return -ENOMEM;
  638. } else {
  639. u.buf = priv->command_buffer;
  640. }
  641. mutex_lock(&priv->command_lock);
  642. memset(u.get, 0, sizeof *u.get);
  643. u.get->msg_type = RNDIS_MSG_QUERY;
  644. u.get->msg_len = cpu_to_le32(sizeof *u.get);
  645. u.get->oid = oid;
  646. priv->current_command_oid = oid;
  647. ret = rndis_command(dev, u.header, buflen);
  648. priv->current_command_oid = 0;
  649. if (ret < 0)
  650. netdev_dbg(dev->net, "%s(%s): rndis_command() failed, %d (%08x)\n",
  651. __func__, oid_to_string(oid), ret,
  652. le32_to_cpu(u.get_c->status));
  653. if (ret == 0) {
  654. resplen = le32_to_cpu(u.get_c->len);
  655. respoffs = le32_to_cpu(u.get_c->offset) + 8;
  656. if (respoffs > buflen) {
  657. /* Device returned data offset outside buffer, error. */
  658. netdev_dbg(dev->net, "%s(%s): received invalid "
  659. "data offset: %d > %d\n", __func__,
  660. oid_to_string(oid), respoffs, buflen);
  661. ret = -EINVAL;
  662. goto exit_unlock;
  663. }
  664. if ((resplen + respoffs) > buflen) {
  665. /* Device would have returned more data if buffer would
  666. * have been big enough. Copy just the bits that we got.
  667. */
  668. copylen = buflen - respoffs;
  669. } else {
  670. copylen = resplen;
  671. }
  672. if (copylen > *len)
  673. copylen = *len;
  674. memcpy(data, u.buf + respoffs, copylen);
  675. *len = resplen;
  676. ret = rndis_error_status(u.get_c->status);
  677. if (ret < 0)
  678. netdev_dbg(dev->net, "%s(%s): device returned error, 0x%08x (%d)\n",
  679. __func__, oid_to_string(oid),
  680. le32_to_cpu(u.get_c->status), ret);
  681. }
  682. exit_unlock:
  683. mutex_unlock(&priv->command_lock);
  684. if (u.buf != priv->command_buffer)
  685. kfree(u.buf);
  686. return ret;
  687. }
  688. static int rndis_set_oid(struct usbnet *dev, __le32 oid, void *data, int len)
  689. {
  690. struct rndis_wlan_private *priv = get_rndis_wlan_priv(dev);
  691. union {
  692. void *buf;
  693. struct rndis_msg_hdr *header;
  694. struct rndis_set *set;
  695. struct rndis_set_c *set_c;
  696. } u;
  697. int ret, buflen;
  698. buflen = len + sizeof(*u.set);
  699. if (buflen < CONTROL_BUFFER_SIZE)
  700. buflen = CONTROL_BUFFER_SIZE;
  701. if (buflen > COMMAND_BUFFER_SIZE) {
  702. u.buf = kmalloc(buflen, GFP_KERNEL);
  703. if (!u.buf)
  704. return -ENOMEM;
  705. } else {
  706. u.buf = priv->command_buffer;
  707. }
  708. mutex_lock(&priv->command_lock);
  709. memset(u.set, 0, sizeof *u.set);
  710. u.set->msg_type = RNDIS_MSG_SET;
  711. u.set->msg_len = cpu_to_le32(sizeof(*u.set) + len);
  712. u.set->oid = oid;
  713. u.set->len = cpu_to_le32(len);
  714. u.set->offset = cpu_to_le32(sizeof(*u.set) - 8);
  715. u.set->handle = cpu_to_le32(0);
  716. memcpy(u.buf + sizeof(*u.set), data, len);
  717. priv->current_command_oid = oid;
  718. ret = rndis_command(dev, u.header, buflen);
  719. priv->current_command_oid = 0;
  720. if (ret < 0)
  721. netdev_dbg(dev->net, "%s(%s): rndis_command() failed, %d (%08x)\n",
  722. __func__, oid_to_string(oid), ret,
  723. le32_to_cpu(u.set_c->status));
  724. if (ret == 0) {
  725. ret = rndis_error_status(u.set_c->status);
  726. if (ret < 0)
  727. netdev_dbg(dev->net, "%s(%s): device returned error, 0x%08x (%d)\n",
  728. __func__, oid_to_string(oid),
  729. le32_to_cpu(u.set_c->status), ret);
  730. }
  731. mutex_unlock(&priv->command_lock);
  732. if (u.buf != priv->command_buffer)
  733. kfree(u.buf);
  734. return ret;
  735. }
  736. static int rndis_reset(struct usbnet *usbdev)
  737. {
  738. struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
  739. struct rndis_reset *reset;
  740. int ret;
  741. mutex_lock(&priv->command_lock);
  742. reset = (void *)priv->command_buffer;
  743. memset(reset, 0, sizeof(*reset));
  744. reset->msg_type = RNDIS_MSG_RESET;
  745. reset->msg_len = cpu_to_le32(sizeof(*reset));
  746. priv->current_command_oid = 0;
  747. ret = rndis_command(usbdev, (void *)reset, CONTROL_BUFFER_SIZE);
  748. mutex_unlock(&priv->command_lock);
  749. if (ret < 0)
  750. return ret;
  751. return 0;
  752. }
  753. /*
  754. * Specs say that we can only set config parameters only soon after device
  755. * initialization.
  756. * value_type: 0 = u32, 2 = unicode string
  757. */
  758. static int rndis_set_config_parameter(struct usbnet *dev, char *param,
  759. int value_type, void *value)
  760. {
  761. struct ndis_config_param *infobuf;
  762. int value_len, info_len, param_len, ret, i;
  763. __le16 *unibuf;
  764. __le32 *dst_value;
  765. if (value_type == 0)
  766. value_len = sizeof(__le32);
  767. else if (value_type == 2)
  768. value_len = strlen(value) * sizeof(__le16);
  769. else
  770. return -EINVAL;
  771. param_len = strlen(param) * sizeof(__le16);
  772. info_len = sizeof(*infobuf) + param_len + value_len;
  773. #ifdef DEBUG
  774. info_len += 12;
  775. #endif
  776. infobuf = kmalloc(info_len, GFP_KERNEL);
  777. if (!infobuf)
  778. return -ENOMEM;
  779. #ifdef DEBUG
  780. info_len -= 12;
  781. /* extra 12 bytes are for padding (debug output) */
  782. memset(infobuf, 0xCC, info_len + 12);
  783. #endif
  784. if (value_type == 2)
  785. netdev_dbg(dev->net, "setting config parameter: %s, value: %s\n",
  786. param, (u8 *)value);
  787. else
  788. netdev_dbg(dev->net, "setting config parameter: %s, value: %d\n",
  789. param, *(u32 *)value);
  790. infobuf->name_offs = cpu_to_le32(sizeof(*infobuf));
  791. infobuf->name_length = cpu_to_le32(param_len);
  792. infobuf->type = cpu_to_le32(value_type);
  793. infobuf->value_offs = cpu_to_le32(sizeof(*infobuf) + param_len);
  794. infobuf->value_length = cpu_to_le32(value_len);
  795. /* simple string to unicode string conversion */
  796. unibuf = (void *)infobuf + sizeof(*infobuf);
  797. for (i = 0; i < param_len / sizeof(__le16); i++)
  798. unibuf[i] = cpu_to_le16(param[i]);
  799. if (value_type == 2) {
  800. unibuf = (void *)infobuf + sizeof(*infobuf) + param_len;
  801. for (i = 0; i < value_len / sizeof(__le16); i++)
  802. unibuf[i] = cpu_to_le16(((u8 *)value)[i]);
  803. } else {
  804. dst_value = (void *)infobuf + sizeof(*infobuf) + param_len;
  805. *dst_value = cpu_to_le32(*(u32 *)value);
  806. }
  807. #ifdef DEBUG
  808. netdev_dbg(dev->net, "info buffer (len: %d)\n", info_len);
  809. for (i = 0; i < info_len; i += 12) {
  810. u32 *tmp = (u32 *)((u8 *)infobuf + i);
  811. netdev_dbg(dev->net, "%08X:%08X:%08X\n",
  812. cpu_to_be32(tmp[0]),
  813. cpu_to_be32(tmp[1]),
  814. cpu_to_be32(tmp[2]));
  815. }
  816. #endif
  817. ret = rndis_set_oid(dev, OID_GEN_RNDIS_CONFIG_PARAMETER,
  818. infobuf, info_len);
  819. if (ret != 0)
  820. netdev_dbg(dev->net, "setting rndis config parameter failed, %d\n",
  821. ret);
  822. kfree(infobuf);
  823. return ret;
  824. }
  825. static int rndis_set_config_parameter_str(struct usbnet *dev,
  826. char *param, char *value)
  827. {
  828. return rndis_set_config_parameter(dev, param, 2, value);
  829. }
  830. /*
  831. * data conversion functions
  832. */
  833. static int level_to_qual(int level)
  834. {
  835. int qual = 100 * (level - WL_NOISE) / (WL_SIGMAX - WL_NOISE);
  836. return qual >= 0 ? (qual <= 100 ? qual : 100) : 0;
  837. }
  838. /*
  839. * common functions
  840. */
  841. static int set_infra_mode(struct usbnet *usbdev, int mode);
  842. static void restore_keys(struct usbnet *usbdev);
  843. static int rndis_check_bssid_list(struct usbnet *usbdev);
  844. static int set_essid(struct usbnet *usbdev, struct ndis_80211_ssid *ssid)
  845. {
  846. struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
  847. int ret;
  848. ret = rndis_set_oid(usbdev, OID_802_11_SSID, ssid, sizeof(*ssid));
  849. if (ret < 0) {
  850. netdev_warn(usbdev->net, "setting SSID failed (%08X)\n", ret);
  851. return ret;
  852. }
  853. if (ret == 0) {
  854. memcpy(&priv->essid, ssid, sizeof(priv->essid));
  855. priv->radio_on = true;
  856. netdev_dbg(usbdev->net, "%s(): radio_on = true\n", __func__);
  857. }
  858. return ret;
  859. }
  860. static int set_bssid(struct usbnet *usbdev, u8 bssid[ETH_ALEN])
  861. {
  862. int ret;
  863. ret = rndis_set_oid(usbdev, OID_802_11_BSSID, bssid, ETH_ALEN);
  864. if (ret < 0) {
  865. netdev_warn(usbdev->net, "setting BSSID[%pM] failed (%08X)\n",
  866. bssid, ret);
  867. return ret;
  868. }
  869. return ret;
  870. }
  871. static int clear_bssid(struct usbnet *usbdev)
  872. {
  873. u8 broadcast_mac[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
  874. return set_bssid(usbdev, broadcast_mac);
  875. }
  876. static int get_bssid(struct usbnet *usbdev, u8 bssid[ETH_ALEN])
  877. {
  878. int ret, len;
  879. len = ETH_ALEN;
  880. ret = rndis_query_oid(usbdev, OID_802_11_BSSID, bssid, &len);
  881. if (ret != 0)
  882. memset(bssid, 0, ETH_ALEN);
  883. return ret;
  884. }
  885. static int get_association_info(struct usbnet *usbdev,
  886. struct ndis_80211_assoc_info *info, int len)
  887. {
  888. return rndis_query_oid(usbdev, OID_802_11_ASSOCIATION_INFORMATION,
  889. info, &len);
  890. }
  891. static bool is_associated(struct usbnet *usbdev)
  892. {
  893. struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
  894. u8 bssid[ETH_ALEN];
  895. int ret;
  896. if (!priv->radio_on)
  897. return false;
  898. ret = get_bssid(usbdev, bssid);
  899. return (ret == 0 && !is_zero_ether_addr(bssid));
  900. }
  901. static int disassociate(struct usbnet *usbdev, bool reset_ssid)
  902. {
  903. struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
  904. struct ndis_80211_ssid ssid;
  905. int i, ret = 0;
  906. if (priv->radio_on) {
  907. ret = rndis_set_oid(usbdev, OID_802_11_DISASSOCIATE, NULL, 0);
  908. if (ret == 0) {
  909. priv->radio_on = false;
  910. netdev_dbg(usbdev->net, "%s(): radio_on = false\n",
  911. __func__);
  912. if (reset_ssid)
  913. msleep(100);
  914. }
  915. }
  916. /* disassociate causes radio to be turned off; if reset_ssid
  917. * is given, set random ssid to enable radio */
  918. if (reset_ssid) {
  919. /* Set device to infrastructure mode so we don't get ad-hoc
  920. * 'media connect' indications with the random ssid.
  921. */
  922. set_infra_mode(usbdev, NDIS_80211_INFRA_INFRA);
  923. ssid.length = cpu_to_le32(sizeof(ssid.essid));
  924. get_random_bytes(&ssid.essid[2], sizeof(ssid.essid)-2);
  925. ssid.essid[0] = 0x1;
  926. ssid.essid[1] = 0xff;
  927. for (i = 2; i < sizeof(ssid.essid); i++)
  928. ssid.essid[i] = 0x1 + (ssid.essid[i] * 0xfe / 0xff);
  929. ret = set_essid(usbdev, &ssid);
  930. }
  931. return ret;
  932. }
  933. static int set_auth_mode(struct usbnet *usbdev, u32 wpa_version,
  934. enum nl80211_auth_type auth_type, int keymgmt)
  935. {
  936. struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
  937. __le32 tmp;
  938. int auth_mode, ret;
  939. netdev_dbg(usbdev->net, "%s(): wpa_version=0x%x authalg=0x%x keymgmt=0x%x\n",
  940. __func__, wpa_version, auth_type, keymgmt);
  941. if (wpa_version & NL80211_WPA_VERSION_2) {
  942. if (keymgmt & RNDIS_WLAN_KEY_MGMT_802_1X)
  943. auth_mode = NDIS_80211_AUTH_WPA2;
  944. else
  945. auth_mode = NDIS_80211_AUTH_WPA2_PSK;
  946. } else if (wpa_version & NL80211_WPA_VERSION_1) {
  947. if (keymgmt & RNDIS_WLAN_KEY_MGMT_802_1X)
  948. auth_mode = NDIS_80211_AUTH_WPA;
  949. else if (keymgmt & RNDIS_WLAN_KEY_MGMT_PSK)
  950. auth_mode = NDIS_80211_AUTH_WPA_PSK;
  951. else
  952. auth_mode = NDIS_80211_AUTH_WPA_NONE;
  953. } else if (auth_type == NL80211_AUTHTYPE_SHARED_KEY)
  954. auth_mode = NDIS_80211_AUTH_SHARED;
  955. else if (auth_type == NL80211_AUTHTYPE_OPEN_SYSTEM)
  956. auth_mode = NDIS_80211_AUTH_OPEN;
  957. else if (auth_type == NL80211_AUTHTYPE_AUTOMATIC)
  958. auth_mode = NDIS_80211_AUTH_AUTO_SWITCH;
  959. else
  960. return -ENOTSUPP;
  961. tmp = cpu_to_le32(auth_mode);
  962. ret = rndis_set_oid(usbdev, OID_802_11_AUTHENTICATION_MODE, &tmp,
  963. sizeof(tmp));
  964. if (ret != 0) {
  965. netdev_warn(usbdev->net, "setting auth mode failed (%08X)\n",
  966. ret);
  967. return ret;
  968. }
  969. priv->wpa_version = wpa_version;
  970. return 0;
  971. }
  972. static int set_priv_filter(struct usbnet *usbdev)
  973. {
  974. struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
  975. __le32 tmp;
  976. netdev_dbg(usbdev->net, "%s(): wpa_version=0x%x\n",
  977. __func__, priv->wpa_version);
  978. if (priv->wpa_version & NL80211_WPA_VERSION_2 ||
  979. priv->wpa_version & NL80211_WPA_VERSION_1)
  980. tmp = cpu_to_le32(NDIS_80211_PRIV_8021X_WEP);
  981. else
  982. tmp = cpu_to_le32(NDIS_80211_PRIV_ACCEPT_ALL);
  983. return rndis_set_oid(usbdev, OID_802_11_PRIVACY_FILTER, &tmp,
  984. sizeof(tmp));
  985. }
  986. static int set_encr_mode(struct usbnet *usbdev, int pairwise, int groupwise)
  987. {
  988. __le32 tmp;
  989. int encr_mode, ret;
  990. netdev_dbg(usbdev->net, "%s(): cipher_pair=0x%x cipher_group=0x%x\n",
  991. __func__, pairwise, groupwise);
  992. if (pairwise & RNDIS_WLAN_ALG_CCMP)
  993. encr_mode = NDIS_80211_ENCR_CCMP_ENABLED;
  994. else if (pairwise & RNDIS_WLAN_ALG_TKIP)
  995. encr_mode = NDIS_80211_ENCR_TKIP_ENABLED;
  996. else if (pairwise & RNDIS_WLAN_ALG_WEP)
  997. encr_mode = NDIS_80211_ENCR_WEP_ENABLED;
  998. else if (groupwise & RNDIS_WLAN_ALG_CCMP)
  999. encr_mode = NDIS_80211_ENCR_CCMP_ENABLED;
  1000. else if (groupwise & RNDIS_WLAN_ALG_TKIP)
  1001. encr_mode = NDIS_80211_ENCR_TKIP_ENABLED;
  1002. else
  1003. encr_mode = NDIS_80211_ENCR_DISABLED;
  1004. tmp = cpu_to_le32(encr_mode);
  1005. ret = rndis_set_oid(usbdev, OID_802_11_ENCRYPTION_STATUS, &tmp,
  1006. sizeof(tmp));
  1007. if (ret != 0) {
  1008. netdev_warn(usbdev->net, "setting encr mode failed (%08X)\n",
  1009. ret);
  1010. return ret;
  1011. }
  1012. return 0;
  1013. }
  1014. static int set_infra_mode(struct usbnet *usbdev, int mode)
  1015. {
  1016. struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
  1017. __le32 tmp;
  1018. int ret;
  1019. netdev_dbg(usbdev->net, "%s(): infra_mode=0x%x\n",
  1020. __func__, priv->infra_mode);
  1021. tmp = cpu_to_le32(mode);
  1022. ret = rndis_set_oid(usbdev, OID_802_11_INFRASTRUCTURE_MODE, &tmp,
  1023. sizeof(tmp));
  1024. if (ret != 0) {
  1025. netdev_warn(usbdev->net, "setting infra mode failed (%08X)\n",
  1026. ret);
  1027. return ret;
  1028. }
  1029. /* NDIS drivers clear keys when infrastructure mode is
  1030. * changed. But Linux tools assume otherwise. So set the
  1031. * keys */
  1032. restore_keys(usbdev);
  1033. priv->infra_mode = mode;
  1034. return 0;
  1035. }
  1036. static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
  1037. {
  1038. __le32 tmp;
  1039. netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
  1040. if (rts_threshold < 0 || rts_threshold > 2347)
  1041. rts_threshold = 2347;
  1042. tmp = cpu_to_le32(rts_threshold);
  1043. return rndis_set_oid(usbdev, OID_802_11_RTS_THRESHOLD, &tmp,
  1044. sizeof(tmp));
  1045. }
  1046. static int set_frag_threshold(struct usbnet *usbdev, u32 frag_threshold)
  1047. {
  1048. __le32 tmp;
  1049. netdev_dbg(usbdev->net, "%s(): %i\n", __func__, frag_threshold);
  1050. if (frag_threshold < 256 || frag_threshold > 2346)
  1051. frag_threshold = 2346;
  1052. tmp = cpu_to_le32(frag_threshold);
  1053. return rndis_set_oid(usbdev, OID_802_11_FRAGMENTATION_THRESHOLD, &tmp,
  1054. sizeof(tmp));
  1055. }
  1056. static void set_default_iw_params(struct usbnet *usbdev)
  1057. {
  1058. set_infra_mode(usbdev, NDIS_80211_INFRA_INFRA);
  1059. set_auth_mode(usbdev, 0, NL80211_AUTHTYPE_OPEN_SYSTEM,
  1060. RNDIS_WLAN_KEY_MGMT_NONE);
  1061. set_priv_filter(usbdev);
  1062. set_encr_mode(usbdev, RNDIS_WLAN_ALG_NONE, RNDIS_WLAN_ALG_NONE);
  1063. }
  1064. static int deauthenticate(struct usbnet *usbdev)
  1065. {
  1066. int ret;
  1067. ret = disassociate(usbdev, true);
  1068. set_default_iw_params(usbdev);
  1069. return ret;
  1070. }
  1071. static int set_channel(struct usbnet *usbdev, int channel)
  1072. {
  1073. struct ndis_80211_conf config;
  1074. unsigned int dsconfig;
  1075. int len, ret;
  1076. netdev_dbg(usbdev->net, "%s(%d)\n", __func__, channel);
  1077. /* this OID is valid only when not associated */
  1078. if (is_associated(usbdev))
  1079. return 0;
  1080. dsconfig = ieee80211_dsss_chan_to_freq(channel) * 1000;
  1081. len = sizeof(config);
  1082. ret = rndis_query_oid(usbdev, OID_802_11_CONFIGURATION, &config, &len);
  1083. if (ret < 0) {
  1084. netdev_dbg(usbdev->net, "%s(): querying configuration failed\n",
  1085. __func__);
  1086. return ret;
  1087. }
  1088. config.ds_config = cpu_to_le32(dsconfig);
  1089. ret = rndis_set_oid(usbdev, OID_802_11_CONFIGURATION, &config,
  1090. sizeof(config));
  1091. netdev_dbg(usbdev->net, "%s(): %d -> %d\n", __func__, channel, ret);
  1092. return ret;
  1093. }
  1094. /* index must be 0 - N, as per NDIS */
  1095. static int add_wep_key(struct usbnet *usbdev, const u8 *key, int key_len,
  1096. int index)
  1097. {
  1098. struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
  1099. struct ndis_80211_wep_key ndis_key;
  1100. u32 cipher;
  1101. int ret;
  1102. netdev_dbg(usbdev->net, "%s(idx: %d, len: %d)\n",
  1103. __func__, index, key_len);
  1104. if ((key_len != 5 && key_len != 13) || index < 0 || index > 3)
  1105. return -EINVAL;
  1106. if (key_len == 5)
  1107. cipher = WLAN_CIPHER_SUITE_WEP40;
  1108. else
  1109. cipher = WLAN_CIPHER_SUITE_WEP104;
  1110. memset(&ndis_key, 0, sizeof(ndis_key));
  1111. ndis_key.size = cpu_to_le32(sizeof(ndis_key));
  1112. ndis_key.length = cpu_to_le32(key_len);
  1113. ndis_key.index = cpu_to_le32(index);
  1114. memcpy(&ndis_key.material, key, key_len);
  1115. if (index == priv->encr_tx_key_index) {
  1116. ndis_key.index |= NDIS_80211_ADDWEP_TRANSMIT_KEY;
  1117. ret = set_encr_mode(usbdev, RNDIS_WLAN_ALG_WEP,
  1118. RNDIS_WLAN_ALG_NONE);
  1119. if (ret)
  1120. netdev_warn(usbdev->net, "encryption couldn't be enabled (%08X)\n",
  1121. ret);
  1122. }
  1123. ret = rndis_set_oid(usbdev, OID_802_11_ADD_WEP, &ndis_key,
  1124. sizeof(ndis_key));
  1125. if (ret != 0) {
  1126. netdev_warn(usbdev->net, "adding encryption key %d failed (%08X)\n",
  1127. index + 1, ret);
  1128. return ret;
  1129. }
  1130. priv->encr_keys[index].len = key_len;
  1131. priv->encr_keys[index].cipher = cipher;
  1132. memcpy(&priv->encr_keys[index].material, key, key_len);
  1133. memset(&priv->encr_keys[index].bssid, 0xff, ETH_ALEN);
  1134. return 0;
  1135. }
  1136. static int add_wpa_key(struct usbnet *usbdev, const u8 *key, int key_len,
  1137. int index, const u8 *addr, const u8 *rx_seq,
  1138. int seq_len, u32 cipher, __le32 flags)
  1139. {
  1140. struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
  1141. struct ndis_80211_key ndis_key;
  1142. bool is_addr_ok;
  1143. int ret;
  1144. if (index < 0 || index >= 4) {
  1145. netdev_dbg(usbdev->net, "%s(): index out of range (%i)\n",
  1146. __func__, index);
  1147. return -EINVAL;
  1148. }
  1149. if (key_len > sizeof(ndis_key.material) || key_len < 0) {
  1150. netdev_dbg(usbdev->net, "%s(): key length out of range (%i)\n",
  1151. __func__, key_len);
  1152. return -EINVAL;
  1153. }
  1154. if (flags & NDIS_80211_ADDKEY_SET_INIT_RECV_SEQ) {
  1155. if (!rx_seq || seq_len <= 0) {
  1156. netdev_dbg(usbdev->net, "%s(): recv seq flag without buffer\n",
  1157. __func__);
  1158. return -EINVAL;
  1159. }
  1160. if (rx_seq && seq_len > sizeof(ndis_key.rsc)) {
  1161. netdev_dbg(usbdev->net, "%s(): too big recv seq buffer\n", __func__);
  1162. return -EINVAL;
  1163. }
  1164. }
  1165. is_addr_ok = addr && !is_zero_ether_addr(addr) &&
  1166. !is_broadcast_ether_addr(addr);
  1167. if ((flags & NDIS_80211_ADDKEY_PAIRWISE_KEY) && !is_addr_ok) {
  1168. netdev_dbg(usbdev->net, "%s(): pairwise but bssid invalid (%pM)\n",
  1169. __func__, addr);
  1170. return -EINVAL;
  1171. }
  1172. netdev_dbg(usbdev->net, "%s(%i): flags:%i%i%i\n",
  1173. __func__, index,
  1174. !!(flags & NDIS_80211_ADDKEY_TRANSMIT_KEY),
  1175. !!(flags & NDIS_80211_ADDKEY_PAIRWISE_KEY),
  1176. !!(flags & NDIS_80211_ADDKEY_SET_INIT_RECV_SEQ));
  1177. memset(&ndis_key, 0, sizeof(ndis_key));
  1178. ndis_key.size = cpu_to_le32(sizeof(ndis_key) -
  1179. sizeof(ndis_key.material) + key_len);
  1180. ndis_key.length = cpu_to_le32(key_len);
  1181. ndis_key.index = cpu_to_le32(index) | flags;
  1182. if (cipher == WLAN_CIPHER_SUITE_TKIP && key_len == 32) {
  1183. /* wpa_supplicant gives us the Michael MIC RX/TX keys in
  1184. * different order than NDIS spec, so swap the order here. */
  1185. memcpy(ndis_key.material, key, 16);
  1186. memcpy(ndis_key.material + 16, key + 24, 8);
  1187. memcpy(ndis_key.material + 24, key + 16, 8);
  1188. } else
  1189. memcpy(ndis_key.material, key, key_len);
  1190. if (flags & NDIS_80211_ADDKEY_SET_INIT_RECV_SEQ)
  1191. memcpy(ndis_key.rsc, rx_seq, seq_len);
  1192. if (flags & NDIS_80211_ADDKEY_PAIRWISE_KEY) {
  1193. /* pairwise key */
  1194. memcpy(ndis_key.bssid, addr, ETH_ALEN);
  1195. } else {
  1196. /* group key */
  1197. if (priv->infra_mode == NDIS_80211_INFRA_ADHOC)
  1198. memset(ndis_key.bssid, 0xff, ETH_ALEN);
  1199. else
  1200. get_bssid(usbdev, ndis_key.bssid);
  1201. }
  1202. ret = rndis_set_oid(usbdev, OID_802_11_ADD_KEY, &ndis_key,
  1203. le32_to_cpu(ndis_key.size));
  1204. netdev_dbg(usbdev->net, "%s(): OID_802_11_ADD_KEY -> %08X\n",
  1205. __func__, ret);
  1206. if (ret != 0)
  1207. return ret;
  1208. memset(&priv->encr_keys[index], 0, sizeof(priv->encr_keys[index]));
  1209. priv->encr_keys[index].len = key_len;
  1210. priv->encr_keys[index].cipher = cipher;
  1211. memcpy(&priv->encr_keys[index].material, key, key_len);
  1212. if (flags & NDIS_80211_ADDKEY_PAIRWISE_KEY)
  1213. memcpy(&priv->encr_keys[index].bssid, ndis_key.bssid, ETH_ALEN);
  1214. else
  1215. memset(&priv->encr_keys[index].bssid, 0xff, ETH_ALEN);
  1216. if (flags & NDIS_80211_ADDKEY_TRANSMIT_KEY)
  1217. priv->encr_tx_key_index = index;
  1218. return 0;
  1219. }
  1220. static int restore_key(struct usbnet *usbdev, int key_idx)
  1221. {
  1222. struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
  1223. struct rndis_wlan_encr_key key;
  1224. if (is_wpa_key(priv, key_idx))
  1225. return 0;
  1226. key = priv->encr_keys[key_idx];
  1227. netdev_dbg(usbdev->net, "%s(): %i:%i\n", __func__, key_idx, key.len);
  1228. if (key.len == 0)
  1229. return 0;
  1230. return add_wep_key(usbdev, key.material, key.len, key_idx);
  1231. }
  1232. static void restore_keys(struct usbnet *usbdev)
  1233. {
  1234. int i;
  1235. for (i = 0; i < 4; i++)
  1236. restore_key(usbdev, i);
  1237. }
  1238. static void clear_key(struct rndis_wlan_private *priv, int idx)
  1239. {
  1240. memset(&priv->encr_keys[idx], 0, sizeof(priv->encr_keys[idx]));
  1241. }
  1242. /* remove_key is for both wep and wpa */
  1243. static int remove_key(struct usbnet *usbdev, int index, const u8 *bssid)
  1244. {
  1245. struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
  1246. struct ndis_80211_remove_key remove_key;
  1247. __le32 keyindex;
  1248. bool is_wpa;
  1249. int ret;
  1250. if (priv->encr_keys[index].len == 0)
  1251. return 0;
  1252. is_wpa = is_wpa_key(priv, index);
  1253. netdev_dbg(usbdev->net, "%s(): %i:%s:%i\n",
  1254. __func__, index, is_wpa ? "wpa" : "wep",
  1255. priv->encr_keys[index].len);
  1256. clear_key(priv, index);
  1257. if (is_wpa) {
  1258. remove_key.size = cpu_to_le32(sizeof(remove_key));
  1259. remove_key.index = cpu_to_le32(index);
  1260. if (bssid) {
  1261. /* pairwise key */
  1262. if (!is_broadcast_ether_addr(bssid))
  1263. remove_key.index |=
  1264. NDIS_80211_ADDKEY_PAIRWISE_KEY;
  1265. memcpy(remove_key.bssid, bssid,
  1266. sizeof(remove_key.bssid));
  1267. } else
  1268. memset(remove_key.bssid, 0xff,
  1269. sizeof(remove_key.bssid));
  1270. ret = rndis_set_oid(usbdev, OID_802_11_REMOVE_KEY, &remove_key,
  1271. sizeof(remove_key));
  1272. if (ret != 0)
  1273. return ret;
  1274. } else {
  1275. keyindex = cpu_to_le32(index);
  1276. ret = rndis_set_oid(usbdev, OID_802_11_REMOVE_WEP, &keyindex,
  1277. sizeof(keyindex));
  1278. if (ret != 0) {
  1279. netdev_warn(usbdev->net,
  1280. "removing encryption key %d failed (%08X)\n",
  1281. index, ret);
  1282. return ret;
  1283. }
  1284. }
  1285. /* if it is transmit key, disable encryption */
  1286. if (index == priv->encr_tx_key_index)
  1287. set_encr_mode(usbdev, RNDIS_WLAN_ALG_NONE, RNDIS_WLAN_ALG_NONE);
  1288. return 0;
  1289. }
  1290. static void set_multicast_list(struct usbnet *usbdev)
  1291. {
  1292. struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
  1293. struct dev_mc_list *mclist;
  1294. __le32 filter;
  1295. int ret, i, size;
  1296. char *buf;
  1297. filter = RNDIS_PACKET_TYPE_DIRECTED | RNDIS_PACKET_TYPE_BROADCAST;
  1298. netif_addr_lock_bh(usbdev->net);
  1299. if (usbdev->net->flags & IFF_PROMISC) {
  1300. filter |= RNDIS_PACKET_TYPE_PROMISCUOUS |
  1301. RNDIS_PACKET_TYPE_ALL_LOCAL;
  1302. } else if (usbdev->net->flags & IFF_ALLMULTI ||
  1303. netdev_mc_count(usbdev->net) > priv->multicast_size) {
  1304. filter |= RNDIS_PACKET_TYPE_ALL_MULTICAST;
  1305. } else if (!netdev_mc_empty(usbdev->net)) {
  1306. size = min(priv->multicast_size, netdev_mc_count(usbdev->net));
  1307. buf = kmalloc(size * ETH_ALEN, GFP_KERNEL);
  1308. if (!buf) {
  1309. netdev_warn(usbdev->net,
  1310. "couldn't alloc %d bytes of memory\n",
  1311. size * ETH_ALEN);
  1312. netif_addr_unlock_bh(usbdev->net);
  1313. return;
  1314. }
  1315. i = 0;
  1316. netdev_for_each_mc_addr(mclist, usbdev->net) {
  1317. if (i == size)
  1318. break;
  1319. memcpy(buf + i++ * ETH_ALEN, mclist->dmi_addr, ETH_ALEN);
  1320. }
  1321. ret = rndis_set_oid(usbdev, OID_802_3_MULTICAST_LIST, buf,
  1322. i * ETH_ALEN);
  1323. if (ret == 0 && i > 0)
  1324. filter |= RNDIS_PACKET_TYPE_MULTICAST;
  1325. else
  1326. filter |= RNDIS_PACKET_TYPE_ALL_MULTICAST;
  1327. netdev_dbg(usbdev->net, "OID_802_3_MULTICAST_LIST(%d, max: %d) -> %d\n",
  1328. i, priv->multicast_size, ret);
  1329. kfree(buf);
  1330. }
  1331. netif_addr_unlock_bh(usbdev->net);
  1332. ret = rndis_set_oid(usbdev, OID_GEN_CURRENT_PACKET_FILTER, &filter,
  1333. sizeof(filter));
  1334. if (ret < 0) {
  1335. netdev_warn(usbdev->net, "couldn't set packet filter: %08x\n",
  1336. le32_to_cpu(filter));
  1337. }
  1338. netdev_dbg(usbdev->net, "OID_GEN_CURRENT_PACKET_FILTER(%08x) -> %d\n",
  1339. le32_to_cpu(filter), ret);
  1340. }
  1341. #ifdef DEBUG
  1342. static void debug_print_pmkids(struct usbnet *usbdev,
  1343. struct ndis_80211_pmkid *pmkids,
  1344. const char *func_str)
  1345. {
  1346. struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
  1347. int i, len, count, max_pmkids, entry_len;
  1348. max_pmkids = priv->wdev.wiphy->max_num_pmkids;
  1349. len = le32_to_cpu(pmkids->length);
  1350. count = le32_to_cpu(pmkids->bssid_info_count);
  1351. entry_len = (count > 0) ? (len - sizeof(*pmkids)) / count : -1;
  1352. netdev_dbg(usbdev->net, "%s(): %d PMKIDs (data len: %d, entry len: "
  1353. "%d)\n", func_str, count, len, entry_len);
  1354. if (count > max_pmkids)
  1355. count = max_pmkids;
  1356. for (i = 0; i < count; i++) {
  1357. u32 *tmp = (u32 *)pmkids->bssid_info[i].pmkid;
  1358. netdev_dbg(usbdev->net, "%s(): bssid: %pM, "
  1359. "pmkid: %08X:%08X:%08X:%08X\n",
  1360. func_str, pmkids->bssid_info[i].bssid,
  1361. cpu_to_be32(tmp[0]), cpu_to_be32(tmp[1]),
  1362. cpu_to_be32(tmp[2]), cpu_to_be32(tmp[3]));
  1363. }
  1364. }
  1365. #else
  1366. static void debug_print_pmkids(struct usbnet *usbdev,
  1367. struct ndis_80211_pmkid *pmkids,
  1368. const char *func_str)
  1369. {
  1370. return;
  1371. }
  1372. #endif
  1373. static struct ndis_80211_pmkid *get_device_pmkids(struct usbnet *usbdev)
  1374. {
  1375. struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
  1376. struct ndis_80211_pmkid *pmkids;
  1377. int len, ret, max_pmkids;
  1378. max_pmkids = priv->wdev.wiphy->max_num_pmkids;
  1379. len = sizeof(*pmkids) + max_pmkids * sizeof(pmkids->bssid_info[0]);
  1380. pmkids = kzalloc(len, GFP_KERNEL);
  1381. if (!pmkids)
  1382. return ERR_PTR(-ENOMEM);
  1383. pmkids->length = cpu_to_le32(len);
  1384. pmkids->bssid_info_count = cpu_to_le32(max_pmkids);
  1385. ret = rndis_query_oid(usbdev, OID_802_11_PMKID, pmkids, &len);
  1386. if (ret < 0) {
  1387. netdev_dbg(usbdev->net, "%s(): OID_802_11_PMKID(%d, %d)"
  1388. " -> %d\n", __func__, len, max_pmkids, ret);
  1389. kfree(pmkids);
  1390. return ERR_PTR(ret);
  1391. }
  1392. if (le32_to_cpu(pmkids->bssid_info_count) > max_pmkids)
  1393. pmkids->bssid_info_count = cpu_to_le32(max_pmkids);
  1394. debug_print_pmkids(usbdev, pmkids, __func__);
  1395. return pmkids;
  1396. }
  1397. static int set_device_pmkids(struct usbnet *usbdev,
  1398. struct ndis_80211_pmkid *pmkids)
  1399. {
  1400. int ret, len, num_pmkids;
  1401. num_pmkids = le32_to_cpu(pmkids->bssid_info_count);
  1402. len = sizeof(*pmkids) + num_pmkids * sizeof(pmkids->bssid_info[0]);
  1403. pmkids->length = cpu_to_le32(len);
  1404. debug_print_pmkids(usbdev, pmkids, __func__);
  1405. ret = rndis_set_oid(usbdev, OID_802_11_PMKID, pmkids,
  1406. le32_to_cpu(pmkids->length));
  1407. if (ret < 0) {
  1408. netdev_dbg(usbdev->net, "%s(): OID_802_11_PMKID(%d, %d) -> %d"
  1409. "\n", __func__, len, num_pmkids, ret);
  1410. }
  1411. kfree(pmkids);
  1412. return ret;
  1413. }
  1414. static struct ndis_80211_pmkid *remove_pmkid(struct usbnet *usbdev,
  1415. struct ndis_80211_pmkid *pmkids,
  1416. struct cfg80211_pmksa *pmksa,
  1417. int max_pmkids)
  1418. {
  1419. int i, len, count, newlen, err;
  1420. len = le32_to_cpu(pmkids->length);
  1421. count = le32_to_cpu(pmkids->bssid_info_count);
  1422. if (count > max_pmkids)
  1423. count = max_pmkids;
  1424. for (i = 0; i < count; i++)
  1425. if (!compare_ether_addr(pmkids->bssid_info[i].bssid,
  1426. pmksa->bssid))
  1427. break;
  1428. /* pmkid not found */
  1429. if (i == count) {
  1430. netdev_dbg(usbdev->net, "%s(): bssid not found (%pM)\n",
  1431. __func__, pmksa->bssid);
  1432. err = -ENOENT;
  1433. goto error;
  1434. }
  1435. for (; i + 1 < count; i++)
  1436. pmkids->bssid_info[i] = pmkids->bssid_info[i + 1];
  1437. count--;
  1438. newlen = sizeof(*pmkids) + count * sizeof(pmkids->bssid_info[0]);
  1439. pmkids->length = cpu_to_le32(newlen);
  1440. pmkids->bssid_info_count = cpu_to_le32(count);
  1441. return pmkids;
  1442. error:
  1443. kfree(pmkids);
  1444. return ERR_PTR(err);
  1445. }
  1446. static struct ndis_80211_pmkid *update_pmkid(struct usbnet *usbdev,
  1447. struct ndis_80211_pmkid *pmkids,
  1448. struct cfg80211_pmksa *pmksa,
  1449. int max_pmkids)
  1450. {
  1451. int i, err, len, count, newlen;
  1452. len = le32_to_cpu(pmkids->length);
  1453. count = le32_to_cpu(pmkids->bssid_info_count);
  1454. if (count > max_pmkids)
  1455. count = max_pmkids;
  1456. /* update with new pmkid */
  1457. for (i = 0; i < count; i++) {
  1458. if (compare_ether_addr(pmkids->bssid_info[i].bssid,
  1459. pmksa->bssid))
  1460. continue;
  1461. memcpy(pmkids->bssid_info[i].pmkid, pmksa->pmkid,
  1462. WLAN_PMKID_LEN);
  1463. return pmkids;
  1464. }
  1465. /* out of space, return error */
  1466. if (i == max_pmkids) {
  1467. netdev_dbg(usbdev->net, "%s(): out of space\n", __func__);
  1468. err = -ENOSPC;
  1469. goto error;
  1470. }
  1471. /* add new pmkid */
  1472. newlen = sizeof(*pmkids) + (count + 1) * sizeof(pmkids->bssid_info[0]);
  1473. pmkids = krealloc(pmkids, newlen, GFP_KERNEL);
  1474. if (!pmkids) {
  1475. err = -ENOMEM;
  1476. goto error;
  1477. }
  1478. pmkids->length = cpu_to_le32(newlen);
  1479. pmkids->bssid_info_count = cpu_to_le32(count + 1);
  1480. memcpy(pmkids->bssid_info[count].bssid, pmksa->bssid, ETH_ALEN);
  1481. memcpy(pmkids->bssid_info[count].pmkid, pmksa->pmkid, WLAN_PMKID_LEN);
  1482. return pmkids;
  1483. error:
  1484. kfree(pmkids);
  1485. return ERR_PTR(err);
  1486. }
  1487. /*
  1488. * cfg80211 ops
  1489. */
  1490. static int rndis_change_virtual_intf(struct wiphy *wiphy,
  1491. struct net_device *dev,
  1492. enum nl80211_iftype type, u32 *flags,
  1493. struct vif_params *params)
  1494. {
  1495. struct rndis_wlan_private *priv = wiphy_priv(wiphy);
  1496. struct usbnet *usbdev = priv->usbdev;
  1497. int mode;
  1498. switch (type) {
  1499. case NL80211_IFTYPE_ADHOC:
  1500. mode = NDIS_80211_INFRA_ADHOC;
  1501. break;
  1502. case NL80211_IFTYPE_STATION:
  1503. mode = NDIS_80211_INFRA_INFRA;
  1504. break;
  1505. default:
  1506. return -EINVAL;
  1507. }
  1508. priv->wdev.iftype = type;
  1509. return set_infra_mode(usbdev, mode);
  1510. }
  1511. static int rndis_set_wiphy_params(struct wiphy *wiphy, u32 changed)
  1512. {
  1513. struct rndis_wlan_private *priv = wiphy_priv(wiphy);
  1514. struct usbnet *usbdev = priv->usbdev;
  1515. int err;
  1516. if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
  1517. err = set_frag_threshold(usbdev, wiphy->frag_threshold);
  1518. if (err < 0)
  1519. return err;
  1520. }
  1521. if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
  1522. err = set_rts_threshold(usbdev, wiphy->rts_threshold);
  1523. if (err < 0)
  1524. return err;
  1525. }
  1526. return 0;
  1527. }
  1528. static int rndis_set_tx_power(struct wiphy *wiphy, enum tx_power_setting type,
  1529. int dbm)
  1530. {
  1531. struct rndis_wlan_private *priv = wiphy_priv(wiphy);
  1532. struct usbnet *usbdev = priv->usbdev;
  1533. netdev_dbg(usbdev->net, "%s(): type:0x%x dbm:%i\n",
  1534. __func__, type, dbm);
  1535. /* Device doesn't support changing txpower after initialization, only
  1536. * turn off/on radio. Support 'auto' mode and setting same dBm that is
  1537. * currently used.
  1538. */
  1539. if (type == TX_POWER_AUTOMATIC || dbm == get_bcm4320_power_dbm(priv)) {
  1540. if (!priv->radio_on)
  1541. disassociate(usbdev, true); /* turn on radio */
  1542. return 0;
  1543. }
  1544. return -ENOTSUPP;
  1545. }
  1546. static int rndis_get_tx_power(struct wiphy *wiphy, int *dbm)
  1547. {
  1548. struct rndis_wlan_private *priv = wiphy_priv(wiphy);
  1549. struct usbnet *usbdev = priv->usbdev;
  1550. *dbm = get_bcm4320_power_dbm(priv);
  1551. netdev_dbg(usbdev->net, "%s(): dbm:%i\n", __func__, *dbm);
  1552. return 0;
  1553. }
  1554. #define SCAN_DELAY_JIFFIES (6 * HZ)
  1555. static int rndis_scan(struct wiphy *wiphy, struct net_device *dev,
  1556. struct cfg80211_scan_request *request)
  1557. {
  1558. struct usbnet *usbdev = netdev_priv(dev);
  1559. struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
  1560. int ret;
  1561. __le32 tmp;
  1562. netdev_dbg(usbdev->net, "cfg80211.scan\n");
  1563. /* Get current bssid list from device before new scan, as new scan
  1564. * clears internal bssid list.
  1565. */
  1566. rndis_check_bssid_list(usbdev);
  1567. if (!request)
  1568. return -EINVAL;
  1569. if (priv->scan_request && priv->scan_request != request)
  1570. return -EBUSY;
  1571. priv->scan_request = request;
  1572. tmp = cpu_to_le32(1);
  1573. ret = rndis_set_oid(usbdev, OID_802_11_BSSID_LIST_SCAN, &tmp,
  1574. sizeof(tmp));
  1575. if (ret == 0) {
  1576. /* Wait before retrieving scan results from device */
  1577. queue_delayed_work(priv->workqueue, &priv->scan_work,
  1578. SCAN_DELAY_JIFFIES);
  1579. }
  1580. return ret;
  1581. }
  1582. static struct cfg80211_bss *rndis_bss_info_update(struct usbnet *usbdev,
  1583. struct ndis_80211_bssid_ex *bssid)
  1584. {
  1585. struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
  1586. struct ieee80211_channel *channel;
  1587. s32 signal;
  1588. u64 timestamp;
  1589. u16 capability;
  1590. u16 beacon_interval;
  1591. struct ndis_80211_fixed_ies *fixed;
  1592. int ie_len, bssid_len;
  1593. u8 *ie;
  1594. netdev_dbg(usbdev->net, " found bssid: '%.32s' [%pM]\n",
  1595. bssid->ssid.essid, bssid->mac);
  1596. /* parse bssid structure */
  1597. bssid_len = le32_to_cpu(bssid->length);
  1598. if (bssid_len < sizeof(struct ndis_80211_bssid_ex) +
  1599. sizeof(struct ndis_80211_fixed_ies))
  1600. return NULL;
  1601. fixed = (struct ndis_80211_fixed_ies *)bssid->ies;
  1602. ie = (void *)(bssid->ies + sizeof(struct ndis_80211_fixed_ies));
  1603. ie_len = min(bssid_len - (int)sizeof(*bssid),
  1604. (int)le32_to_cpu(bssid->ie_length));
  1605. ie_len -= sizeof(struct ndis_80211_fixed_ies);
  1606. if (ie_len < 0)
  1607. return NULL;
  1608. /* extract data for cfg80211_inform_bss */
  1609. channel = ieee80211_get_channel(priv->wdev.wiphy,
  1610. KHZ_TO_MHZ(le32_to_cpu(bssid->config.ds_config)));
  1611. if (!channel)
  1612. return NULL;
  1613. signal = level_to_qual(le32_to_cpu(bssid->rssi));
  1614. timestamp = le64_to_cpu(*(__le64 *)fixed->timestamp);
  1615. capability = le16_to_cpu(fixed->capabilities);
  1616. beacon_interval = le16_to_cpu(fixed->beacon_interval);
  1617. return cfg80211_inform_bss(priv->wdev.wiphy, channel, bssid->mac,
  1618. timestamp, capability, beacon_interval, ie, ie_len, signal,
  1619. GFP_KERNEL);
  1620. }
  1621. static int rndis_check_bssid_list(struct usbnet *usbdev)
  1622. {
  1623. void *buf = NULL;
  1624. struct ndis_80211_bssid_list_ex *bssid_list;
  1625. struct ndis_80211_bssid_ex *bssid;
  1626. int ret = -EINVAL, len, count, bssid_len;
  1627. bool resized = false;
  1628. netdev_dbg(usbdev->net, "check_bssid_list\n");
  1629. len = CONTROL_BUFFER_SIZE;
  1630. resize_buf:
  1631. buf = kmalloc(len, GFP_KERNEL);
  1632. if (!buf) {
  1633. ret = -ENOMEM;
  1634. goto out;
  1635. }
  1636. ret = rndis_query_oid(usbdev, OID_802_11_BSSID_LIST, buf, &len);
  1637. if (ret != 0)
  1638. goto out;
  1639. if (!resized && len > CONTROL_BUFFER_SIZE) {
  1640. resized = true;
  1641. kfree(buf);
  1642. goto resize_buf;
  1643. }
  1644. bssid_list = buf;
  1645. bssid = bssid_list->bssid;
  1646. bssid_len = le32_to_cpu(bssid->length);
  1647. count = le32_to_cpu(bssid_list->num_items);
  1648. netdev_dbg(usbdev->net, "check_bssid_list: %d BSSIDs found (buflen: %d)\n",
  1649. count, len);
  1650. while (count && ((void *)bssid + bssid_len) <= (buf + len)) {
  1651. rndis_bss_info_update(usbdev, bssid);
  1652. bssid = (void *)bssid + bssid_len;
  1653. bssid_len = le32_to_cpu(bssid->length);
  1654. count--;
  1655. }
  1656. out:
  1657. kfree(buf);
  1658. return ret;
  1659. }
  1660. static void rndis_get_scan_results(struct work_struct *work)
  1661. {
  1662. struct rndis_wlan_private *priv =
  1663. container_of(work, struct rndis_wlan_private, scan_work.work);
  1664. struct usbnet *usbdev = priv->usbdev;
  1665. int ret;
  1666. netdev_dbg(usbdev->net, "get_scan_results\n");
  1667. if (!priv->scan_request)
  1668. return;
  1669. ret = rndis_check_bssid_list(usbdev);
  1670. cfg80211_scan_done(priv->scan_request, ret < 0);
  1671. priv->scan_request = NULL;
  1672. }
  1673. static int rndis_connect(struct wiphy *wiphy, struct net_device *dev,
  1674. struct cfg80211_connect_params *sme)
  1675. {
  1676. struct rndis_wlan_private *priv = wiphy_priv(wiphy);
  1677. struct usbnet *usbdev = priv->usbdev;
  1678. struct ieee80211_channel *channel = sme->channel;
  1679. struct ndis_80211_ssid ssid;
  1680. int pairwise = RNDIS_WLAN_ALG_NONE;
  1681. int groupwise = RNDIS_WLAN_ALG_NONE;
  1682. int keymgmt = RNDIS_WLAN_KEY_MGMT_NONE;
  1683. int length, i, ret, chan = -1;
  1684. if (channel)
  1685. chan = ieee80211_frequency_to_channel(channel->center_freq);
  1686. groupwise = rndis_cipher_to_alg(sme->crypto.cipher_group);
  1687. for (i = 0; i < sme->crypto.n_ciphers_pairwise; i++)
  1688. pairwise |=
  1689. rndis_cipher_to_alg(sme->crypto.ciphers_pairwise[i]);
  1690. if (sme->crypto.n_ciphers_pairwise > 0 &&
  1691. pairwise == RNDIS_WLAN_ALG_NONE) {
  1692. netdev_err(usbdev->net, "Unsupported pairwise cipher\n");
  1693. return -ENOTSUPP;
  1694. }
  1695. for (i = 0; i < sme->crypto.n_akm_suites; i++)
  1696. keymgmt |=
  1697. rndis_akm_suite_to_key_mgmt(sme->crypto.akm_suites[i]);
  1698. if (sme->crypto.n_akm_suites > 0 &&
  1699. keymgmt == RNDIS_WLAN_KEY_MGMT_NONE) {
  1700. netdev_err(usbdev->net, "Invalid keymgmt\n");
  1701. return -ENOTSUPP;
  1702. }
  1703. netdev_dbg(usbdev->net, "cfg80211.connect('%.32s':[%pM]:%d:[%d,0x%x:0x%x]:[0x%x:0x%x]:0x%x)\n",
  1704. sme->ssid, sme->bssid, chan,
  1705. sme->privacy, sme->crypto.wpa_versions, sme->auth_type,
  1706. groupwise, pairwise, keymgmt);
  1707. if (is_associated(usbdev))
  1708. disassociate(usbdev, false);
  1709. ret = set_infra_mode(usbdev, NDIS_80211_INFRA_INFRA);
  1710. if (ret < 0) {
  1711. netdev_dbg(usbdev->net, "connect: set_infra_mode failed, %d\n",
  1712. ret);
  1713. goto err_turn_radio_on;
  1714. }
  1715. ret = set_auth_mode(usbdev, sme->crypto.wpa_versions, sme->auth_type,
  1716. keymgmt);
  1717. if (ret < 0) {
  1718. netdev_dbg(usbdev->net, "connect: set_auth_mode failed, %d\n",
  1719. ret);
  1720. goto err_turn_radio_on;
  1721. }
  1722. set_priv_filter(usbdev);
  1723. ret = set_encr_mode(usbdev, pairwise, groupwise);
  1724. if (ret < 0) {
  1725. netdev_dbg(usbdev->net, "connect: set_encr_mode failed, %d\n",
  1726. ret);
  1727. goto err_turn_radio_on;
  1728. }
  1729. if (channel) {
  1730. ret = set_channel(usbdev, chan);
  1731. if (ret < 0) {
  1732. netdev_dbg(usbdev->net, "connect: set_channel failed, %d\n",
  1733. ret);
  1734. goto err_turn_radio_on;
  1735. }
  1736. }
  1737. if (sme->key && ((groupwise | pairwise) & RNDIS_WLAN_ALG_WEP)) {
  1738. priv->encr_tx_key_index = sme->key_idx;
  1739. ret = add_wep_key(usbdev, sme->key, sme->key_len, sme->key_idx);
  1740. if (ret < 0) {
  1741. netdev_dbg(usbdev->net, "connect: add_wep_key failed, %d (%d, %d)\n",
  1742. ret, sme->key_len, sme->key_idx);
  1743. goto err_turn_radio_on;
  1744. }
  1745. }
  1746. if (sme->bssid && !is_zero_ether_addr(sme->bssid) &&
  1747. !is_broadcast_ether_addr(sme->bssid)) {
  1748. ret = set_bssid(usbdev, sme->bssid);
  1749. if (ret < 0) {
  1750. netdev_dbg(usbdev->net, "connect: set_bssid failed, %d\n",
  1751. ret);
  1752. goto err_turn_radio_on;
  1753. }
  1754. } else
  1755. clear_bssid(usbdev);
  1756. length = sme->ssid_len;
  1757. if (length > NDIS_802_11_LENGTH_SSID)
  1758. length = NDIS_802_11_LENGTH_SSID;
  1759. memset(&ssid, 0, sizeof(ssid));
  1760. ssid.length = cpu_to_le32(length);
  1761. memcpy(ssid.essid, sme->ssid, length);
  1762. /* Pause and purge rx queue, so we don't pass packets before
  1763. * 'media connect'-indication.
  1764. */
  1765. usbnet_pause_rx(usbdev);
  1766. usbnet_purge_paused_rxq(usbdev);
  1767. ret = set_essid(usbdev, &ssid);
  1768. if (ret < 0)
  1769. netdev_dbg(usbdev->net, "connect: set_essid failed, %d\n", ret);
  1770. return ret;
  1771. err_turn_radio_on:
  1772. disassociate(usbdev, true);
  1773. return ret;
  1774. }
  1775. static int rndis_disconnect(struct wiphy *wiphy, struct net_device *dev,
  1776. u16 reason_code)
  1777. {
  1778. struct rndis_wlan_private *priv = wiphy_priv(wiphy);
  1779. struct usbnet *usbdev = priv->usbdev;
  1780. netdev_dbg(usbdev->net, "cfg80211.disconnect(%d)\n", reason_code);
  1781. priv->connected = false;
  1782. memset(priv->bssid, 0, ETH_ALEN);
  1783. return deauthenticate(usbdev);
  1784. }
  1785. static int rndis_join_ibss(struct wiphy *wiphy, struct net_device *dev,
  1786. struct cfg80211_ibss_params *params)
  1787. {
  1788. struct rndis_wlan_private *priv = wiphy_priv(wiphy);
  1789. struct usbnet *usbdev = priv->usbdev;
  1790. struct ieee80211_channel *channel = params->channel;
  1791. struct ndis_80211_ssid ssid;
  1792. enum nl80211_auth_type auth_type;
  1793. int ret, alg, length, chan = -1;
  1794. if (channel)
  1795. chan = ieee80211_frequency_to_channel(channel->center_freq);
  1796. /* TODO: How to handle ad-hoc encryption?
  1797. * connect() has *key, join_ibss() doesn't. RNDIS requires key to be
  1798. * pre-shared for encryption (open/shared/wpa), is key set before
  1799. * join_ibss? Which auth_type to use (not in params)? What about WPA?
  1800. */
  1801. if (params->privacy) {
  1802. auth_type = NL80211_AUTHTYPE_SHARED_KEY;
  1803. alg = RNDIS_WLAN_ALG_WEP;
  1804. } else {
  1805. auth_type = NL80211_AUTHTYPE_OPEN_SYSTEM;
  1806. alg = RNDIS_WLAN_ALG_NONE;
  1807. }
  1808. netdev_dbg(usbdev->net, "cfg80211.join_ibss('%.32s':[%pM]:%d:%d)\n",
  1809. params->ssid, params->bssid, chan, params->privacy);
  1810. if (is_associated(usbdev))
  1811. disassociate(usbdev, false);
  1812. ret = set_infra_mode(usbdev, NDIS_80211_INFRA_ADHOC);
  1813. if (ret < 0) {
  1814. netdev_dbg(usbdev->net, "join_ibss: set_infra_mode failed, %d\n",
  1815. ret);
  1816. goto err_turn_radio_on;
  1817. }
  1818. ret = set_auth_mode(usbdev, 0, auth_type, RNDIS_WLAN_KEY_MGMT_NONE);
  1819. if (ret < 0) {
  1820. netdev_dbg(usbdev->net, "join_ibss: set_auth_mode failed, %d\n",
  1821. ret);
  1822. goto err_turn_radio_on;
  1823. }
  1824. set_priv_filter(usbdev);
  1825. ret = set_encr_mode(usbdev, alg, RNDIS_WLAN_ALG_NONE);
  1826. if (ret < 0) {
  1827. netdev_dbg(usbdev->net, "join_ibss: set_encr_mode failed, %d\n",
  1828. ret);
  1829. goto err_turn_radio_on;
  1830. }
  1831. if (channel) {
  1832. ret = set_channel(usbdev, chan);
  1833. if (ret < 0) {
  1834. netdev_dbg(usbdev->net, "join_ibss: set_channel failed, %d\n",
  1835. ret);
  1836. goto err_turn_radio_on;
  1837. }
  1838. }
  1839. if (params->bssid && !is_zero_ether_addr(params->bssid) &&
  1840. !is_broadcast_ether_addr(params->bssid)) {
  1841. ret = set_bssid(usbdev, params->bssid);
  1842. if (ret < 0) {
  1843. netdev_dbg(usbdev->net, "join_ibss: set_bssid failed, %d\n",
  1844. ret);
  1845. goto err_turn_radio_on;
  1846. }
  1847. } else
  1848. clear_bssid(usbdev);
  1849. length = params->ssid_len;
  1850. if (length > NDIS_802_11_LENGTH_SSID)
  1851. length = NDIS_802_11_LENGTH_SSID;
  1852. memset(&ssid, 0, sizeof(ssid));
  1853. ssid.length = cpu_to_le32(length);
  1854. memcpy(ssid.essid, params->ssid, length);
  1855. /* Don't need to pause rx queue for ad-hoc. */
  1856. usbnet_purge_paused_rxq(usbdev);
  1857. usbnet_resume_rx(usbdev);
  1858. ret = set_essid(usbdev, &ssid);
  1859. if (ret < 0)
  1860. netdev_dbg(usbdev->net, "join_ibss: set_essid failed, %d\n",
  1861. ret);
  1862. return ret;
  1863. err_turn_radio_on:
  1864. disassociate(usbdev, true);
  1865. return ret;
  1866. }
  1867. static int rndis_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
  1868. {
  1869. struct rndis_wlan_private *priv = wiphy_priv(wiphy);
  1870. struct usbnet *usbdev = priv->usbdev;
  1871. netdev_dbg(usbdev->net, "cfg80211.leave_ibss()\n");
  1872. priv->connected = false;
  1873. memset(priv->bssid, 0, ETH_ALEN);
  1874. return deauthenticate(usbdev);
  1875. }
  1876. static int rndis_set_channel(struct wiphy *wiphy,
  1877. struct ieee80211_channel *chan, enum nl80211_channel_type channel_type)
  1878. {
  1879. struct rndis_wlan_private *priv = wiphy_priv(wiphy);
  1880. struct usbnet *usbdev = priv->usbdev;
  1881. return set_channel(usbdev,
  1882. ieee80211_frequency_to_channel(chan->center_freq));
  1883. }
  1884. static int rndis_add_key(struct wiphy *wiphy, struct net_device *netdev,
  1885. u8 key_index, const u8 *mac_addr,
  1886. struct key_params *params)
  1887. {
  1888. struct rndis_wlan_private *priv = wiphy_priv(wiphy);
  1889. struct usbnet *usbdev = priv->usbdev;
  1890. __le32 flags;
  1891. netdev_dbg(usbdev->net, "%s(%i, %pM, %08x)\n",
  1892. __func__, key_index, mac_addr, params->cipher);
  1893. switch (params->cipher) {
  1894. case WLAN_CIPHER_SUITE_WEP40:
  1895. case WLAN_CIPHER_SUITE_WEP104:
  1896. return add_wep_key(usbdev, params->key, params->key_len,
  1897. key_index);
  1898. case WLAN_CIPHER_SUITE_TKIP:
  1899. case WLAN_CIPHER_SUITE_CCMP:
  1900. flags = 0;
  1901. if (params->seq && params->seq_len > 0)
  1902. flags |= NDIS_80211_ADDKEY_SET_INIT_RECV_SEQ;
  1903. if (mac_addr)
  1904. flags |= NDIS_80211_ADDKEY_PAIRWISE_KEY |
  1905. NDIS_80211_ADDKEY_TRANSMIT_KEY;
  1906. return add_wpa_key(usbdev, params->key, params->key_len,
  1907. key_index, mac_addr, params->seq,
  1908. params->seq_len, params->cipher, flags);
  1909. default:
  1910. netdev_dbg(usbdev->net, "%s(): unsupported cipher %08x\n",
  1911. __func__, params->cipher);
  1912. return -ENOTSUPP;
  1913. }
  1914. }
  1915. static int rndis_del_key(struct wiphy *wiphy, struct net_device *netdev,
  1916. u8 key_index, const u8 *mac_addr)
  1917. {
  1918. struct rndis_wlan_private *priv = wiphy_priv(wiphy);
  1919. struct usbnet *usbdev = priv->usbdev;
  1920. netdev_dbg(usbdev->net, "%s(%i, %pM)\n", __func__, key_index, mac_addr);
  1921. return remove_key(usbdev, key_index, mac_addr);
  1922. }
  1923. static int rndis_set_default_key(struct wiphy *wiphy, struct net_device *netdev,
  1924. u8 key_index)
  1925. {
  1926. struct rndis_wlan_private *priv = wiphy_priv(wiphy);
  1927. struct usbnet *usbdev = priv->usbdev;
  1928. struct rndis_wlan_encr_key key;
  1929. netdev_dbg(usbdev->net, "%s(%i)\n", __func__, key_index);
  1930. priv->encr_tx_key_index = key_index;
  1931. key = priv->encr_keys[key_index];
  1932. return add_wep_key(usbdev, key.material, key.len, key_index);
  1933. }
  1934. static void rndis_fill_station_info(struct usbnet *usbdev,
  1935. struct station_info *sinfo)
  1936. {
  1937. __le32 linkspeed, rssi;
  1938. int ret, len;
  1939. memset(sinfo, 0, sizeof(*sinfo));
  1940. len = sizeof(linkspeed);
  1941. ret = rndis_query_oid(usbdev, OID_GEN_LINK_SPEED, &linkspeed, &len);
  1942. if (ret == 0) {
  1943. sinfo->txrate.legacy = le32_to_cpu(linkspeed) / 1000;
  1944. sinfo->filled |= STATION_INFO_TX_BITRATE;
  1945. }
  1946. len = sizeof(rssi);
  1947. ret = rndis_query_oid(usbdev, OID_802_11_RSSI, &rssi, &len);
  1948. if (ret == 0) {
  1949. sinfo->signal = level_to_qual(le32_to_cpu(rssi));
  1950. sinfo->filled |= STATION_INFO_SIGNAL;
  1951. }
  1952. }
  1953. static int rndis_get_station(struct wiphy *wiphy, struct net_device *dev,
  1954. u8 *mac, struct station_info *sinfo)
  1955. {
  1956. struct rndis_wlan_private *priv = wiphy_priv(wiphy);
  1957. struct usbnet *usbdev = priv->usbdev;
  1958. if (compare_ether_addr(priv->bssid, mac))
  1959. return -ENOENT;
  1960. rndis_fill_station_info(usbdev, sinfo);
  1961. return 0;
  1962. }
  1963. static int rndis_dump_station(struct wiphy *wiphy, struct net_device *dev,
  1964. int idx, u8 *mac, struct station_info *sinfo)
  1965. {
  1966. struct rndis_wlan_private *priv = wiphy_priv(wiphy);
  1967. struct usbnet *usbdev = priv->usbdev;
  1968. if (idx != 0)
  1969. return -ENOENT;
  1970. memcpy(mac, priv->bssid, ETH_ALEN);
  1971. rndis_fill_station_info(usbdev, sinfo);
  1972. return 0;
  1973. }
  1974. static int rndis_set_pmksa(struct wiphy *wiphy, struct net_device *netdev,
  1975. struct cfg80211_pmksa *pmksa)
  1976. {
  1977. struct rndis_wlan_private *priv = wiphy_priv(wiphy);
  1978. struct usbnet *usbdev = priv->usbdev;
  1979. struct ndis_80211_pmkid *pmkids;
  1980. u32 *tmp = (u32 *)pmksa->pmkid;
  1981. netdev_dbg(usbdev->net, "%s(%pM, %08X:%08X:%08X:%08X)\n", __func__,
  1982. pmksa->bssid,
  1983. cpu_to_be32(tmp[0]), cpu_to_be32(tmp[1]),
  1984. cpu_to_be32(tmp[2]), cpu_to_be32(tmp[3]));
  1985. pmkids = get_device_pmkids(usbdev);
  1986. if (IS_ERR(pmkids)) {
  1987. /* couldn't read PMKID cache from device */
  1988. return PTR_ERR(pmkids);
  1989. }
  1990. pmkids = update_pmkid(usbdev, pmkids, pmksa, wiphy->max_num_pmkids);
  1991. if (IS_ERR(pmkids)) {
  1992. /* not found, list full, etc */
  1993. return PTR_ERR(pmkids);
  1994. }
  1995. return set_device_pmkids(usbdev, pmkids);
  1996. }
  1997. static int rndis_del_pmksa(struct wiphy *wiphy, struct net_device *netdev,
  1998. struct cfg80211_pmksa *pmksa)
  1999. {
  2000. struct rndis_wlan_private *priv = wiphy_priv(wiphy);
  2001. struct usbnet *usbdev = priv->usbdev;
  2002. struct ndis_80211_pmkid *pmkids;
  2003. u32 *tmp = (u32 *)pmksa->pmkid;
  2004. netdev_dbg(usbdev->net, "%s(%pM, %08X:%08X:%08X:%08X)\n", __func__,
  2005. pmksa->bssid,
  2006. cpu_to_be32(tmp[0]), cpu_to_be32(tmp[1]),
  2007. cpu_to_be32(tmp[2]), cpu_to_be32(tmp[3]));
  2008. pmkids = get_device_pmkids(usbdev);
  2009. if (IS_ERR(pmkids)) {
  2010. /* Couldn't read PMKID cache from device */
  2011. return PTR_ERR(pmkids);
  2012. }
  2013. pmkids = remove_pmkid(usbdev, pmkids, pmksa, wiphy->max_num_pmkids);
  2014. if (IS_ERR(pmkids)) {
  2015. /* not found, etc */
  2016. return PTR_ERR(pmkids);
  2017. }
  2018. return set_device_pmkids(usbdev, pmkids);
  2019. }
  2020. static int rndis_flush_pmksa(struct wiphy *wiphy, struct net_device *netdev)
  2021. {
  2022. struct rndis_wlan_private *priv = wiphy_priv(wiphy);
  2023. struct usbnet *usbdev = priv->usbdev;
  2024. struct ndis_80211_pmkid pmkid;
  2025. netdev_dbg(usbdev->net, "%s()\n", __func__);
  2026. memset(&pmkid, 0, sizeof(pmkid));
  2027. pmkid.length = cpu_to_le32(sizeof(pmkid));
  2028. pmkid.bssid_info_count = cpu_to_le32(0);
  2029. return rndis_set_oid(usbdev, OID_802_11_PMKID, &pmkid, sizeof(pmkid));
  2030. }
  2031. /*
  2032. * workers, indication handlers, device poller
  2033. */
  2034. static void rndis_wlan_do_link_up_work(struct usbnet *usbdev)
  2035. {
  2036. struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
  2037. struct ndis_80211_assoc_info *info;
  2038. u8 assoc_buf[sizeof(*info) + IW_CUSTOM_MAX + 32];
  2039. u8 bssid[ETH_ALEN];
  2040. int resp_ie_len, req_ie_len;
  2041. u8 *req_ie, *resp_ie;
  2042. int ret, offset;
  2043. bool roamed = false;
  2044. if (priv->infra_mode == NDIS_80211_INFRA_INFRA && priv->connected) {
  2045. /* received media connect indication while connected, either
  2046. * device reassociated with same AP or roamed to new. */
  2047. roamed = true;
  2048. }
  2049. req_ie_len = 0;
  2050. resp_ie_len = 0;
  2051. req_ie = NULL;
  2052. resp_ie = NULL;
  2053. if (priv->infra_mode == NDIS_80211_INFRA_INFRA) {
  2054. memset(assoc_buf, 0, sizeof(assoc_buf));
  2055. info = (void *)assoc_buf;
  2056. /* Get association info IEs from device and send them back to
  2057. * userspace. */
  2058. ret = get_association_info(usbdev, info, sizeof(assoc_buf));
  2059. if (!ret) {
  2060. req_ie_len = le32_to_cpu(info->req_ie_length);
  2061. if (req_ie_len > 0) {
  2062. offset = le32_to_cpu(info->offset_req_ies);
  2063. req_ie = (u8 *)info + offset;
  2064. }
  2065. resp_ie_len = le32_to_cpu(info->resp_ie_length);
  2066. if (resp_ie_len > 0) {
  2067. offset = le32_to_cpu(info->offset_resp_ies);
  2068. resp_ie = (u8 *)info + offset;
  2069. }
  2070. }
  2071. } else if (WARN_ON(priv->infra_mode != NDIS_80211_INFRA_ADHOC))
  2072. return;
  2073. ret = get_bssid(usbdev, bssid);
  2074. if (ret < 0)
  2075. memset(bssid, 0, sizeof(bssid));
  2076. netdev_dbg(usbdev->net, "link up work: [%pM]%s\n",
  2077. bssid, roamed ? " roamed" : "");
  2078. /* Internal bss list in device always contains at least the currently
  2079. * connected bss and we can get it to cfg80211 with
  2080. * rndis_check_bssid_list().
  2081. * NOTE: This is true for Broadcom chip, but not mentioned in RNDIS
  2082. * spec.
  2083. */
  2084. rndis_check_bssid_list(usbdev);
  2085. if (priv->infra_mode == NDIS_80211_INFRA_INFRA) {
  2086. if (!roamed)
  2087. cfg80211_connect_result(usbdev->net, bssid, req_ie,
  2088. req_ie_len, resp_ie,
  2089. resp_ie_len, 0, GFP_KERNEL);
  2090. else
  2091. cfg80211_roamed(usbdev->net, bssid, req_ie, req_ie_len,
  2092. resp_ie, resp_ie_len, GFP_KERNEL);
  2093. } else if (priv->infra_mode == NDIS_80211_INFRA_ADHOC)
  2094. cfg80211_ibss_joined(usbdev->net, bssid, GFP_KERNEL);
  2095. priv->connected = true;
  2096. memcpy(priv->bssid, bssid, ETH_ALEN);
  2097. usbnet_resume_rx(usbdev);
  2098. netif_carrier_on(usbdev->net);
  2099. }
  2100. static void rndis_wlan_do_link_down_work(struct usbnet *usbdev)
  2101. {
  2102. union iwreq_data evt;
  2103. netif_carrier_off(usbdev->net);
  2104. evt.data.flags = 0;
  2105. evt.data.length = 0;
  2106. memset(evt.ap_addr.sa_data, 0, ETH_ALEN);
  2107. wireless_send_event(usbdev->net, SIOCGIWAP, &evt, NULL);
  2108. }
  2109. static void rndis_wlan_worker(struct work_struct *work)
  2110. {
  2111. struct rndis_wlan_private *priv =
  2112. container_of(work, struct rndis_wlan_private, work);
  2113. struct usbnet *usbdev = priv->usbdev;
  2114. if (test_and_clear_bit(WORK_LINK_UP, &priv->work_pending))
  2115. rndis_wlan_do_link_up_work(usbdev);
  2116. if (test_and_clear_bit(WORK_LINK_DOWN, &priv->work_pending))
  2117. rndis_wlan_do_link_down_work(usbdev);
  2118. if (test_and_clear_bit(WORK_SET_MULTICAST_LIST, &priv->work_pending))
  2119. set_multicast_list(usbdev);
  2120. }
  2121. static void rndis_wlan_set_multicast_list(struct net_device *dev)
  2122. {
  2123. struct usbnet *usbdev = netdev_priv(dev);
  2124. struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
  2125. if (test_bit(WORK_SET_MULTICAST_LIST, &priv->work_pending))
  2126. return;
  2127. set_bit(WORK_SET_MULTICAST_LIST, &priv->work_pending);
  2128. queue_work(priv->workqueue, &priv->work);
  2129. }
  2130. static void rndis_wlan_auth_indication(struct usbnet *usbdev,
  2131. struct ndis_80211_status_indication *indication,
  2132. int len)
  2133. {
  2134. u8 *buf;
  2135. const char *type;
  2136. int flags, buflen, key_id;
  2137. bool pairwise_error, group_error;
  2138. struct ndis_80211_auth_request *auth_req;
  2139. enum nl80211_key_type key_type;
  2140. /* must have at least one array entry */
  2141. if (len < offsetof(struct ndis_80211_status_indication, u) +
  2142. sizeof(struct ndis_80211_auth_request)) {
  2143. netdev_info(usbdev->net, "authentication indication: too short message (%i)\n",
  2144. len);
  2145. return;
  2146. }
  2147. buf = (void *)&indication->u.auth_request[0];
  2148. buflen = len - offsetof(struct ndis_80211_status_indication, u);
  2149. while (buflen >= sizeof(*auth_req)) {
  2150. auth_req = (void *)buf;
  2151. type = "unknown";
  2152. flags = le32_to_cpu(auth_req->flags);
  2153. pairwise_error = false;
  2154. group_error = false;
  2155. if (flags & 0x1)
  2156. type = "reauth request";
  2157. if (flags & 0x2)
  2158. type = "key update request";
  2159. if (flags & 0x6) {
  2160. pairwise_error = true;
  2161. type = "pairwise_error";
  2162. }
  2163. if (flags & 0xe) {
  2164. group_error = true;
  2165. type = "group_error";
  2166. }
  2167. netdev_info(usbdev->net, "authentication indication: %s (0x%08x)\n",
  2168. type, le32_to_cpu(auth_req->flags));
  2169. if (pairwise_error) {
  2170. key_type = NL80211_KEYTYPE_PAIRWISE;
  2171. key_id = -1;
  2172. cfg80211_michael_mic_failure(usbdev->net,
  2173. auth_req->bssid,
  2174. key_type, key_id, NULL,
  2175. GFP_KERNEL);
  2176. }
  2177. if (group_error) {
  2178. key_type = NL80211_KEYTYPE_GROUP;
  2179. key_id = -1;
  2180. cfg80211_michael_mic_failure(usbdev->net,
  2181. auth_req->bssid,
  2182. key_type, key_id, NULL,
  2183. GFP_KERNEL);
  2184. }
  2185. buflen -= le32_to_cpu(auth_req->length);
  2186. buf += le32_to_cpu(auth_req->length);
  2187. }
  2188. }
  2189. static void rndis_wlan_pmkid_cand_list_indication(struct usbnet *usbdev,
  2190. struct ndis_80211_status_indication *indication,
  2191. int len)
  2192. {
  2193. struct ndis_80211_pmkid_cand_list *cand_list;
  2194. int list_len, expected_len, i;
  2195. if (len < offsetof(struct ndis_80211_status_indication, u) +
  2196. sizeof(struct ndis_80211_pmkid_cand_list)) {
  2197. netdev_info(usbdev->net, "pmkid candidate list indication: too short message (%i)\n",
  2198. len);
  2199. return;
  2200. }
  2201. list_len = le32_to_cpu(indication->u.cand_list.num_candidates) *
  2202. sizeof(struct ndis_80211_pmkid_candidate);
  2203. expected_len = sizeof(struct ndis_80211_pmkid_cand_list) + list_len +
  2204. offsetof(struct ndis_80211_status_indication, u);
  2205. if (len < expected_len) {
  2206. netdev_info(usbdev->net, "pmkid candidate list indication: list larger than buffer (%i < %i)\n",
  2207. len, expected_len);
  2208. return;
  2209. }
  2210. cand_list = &indication->u.cand_list;
  2211. netdev_info(usbdev->net, "pmkid candidate list indication: version %i, candidates %i\n",
  2212. le32_to_cpu(cand_list->version),
  2213. le32_to_cpu(cand_list->num_candidates));
  2214. if (le32_to_cpu(cand_list->version) != 1)
  2215. return;
  2216. for (i = 0; i < le32_to_cpu(cand_list->num_candidates); i++) {
  2217. struct ndis_80211_pmkid_candidate *cand =
  2218. &cand_list->candidate_list[i];
  2219. netdev_dbg(usbdev->net, "cand[%i]: flags: 0x%08x, bssid: %pM\n",
  2220. i, le32_to_cpu(cand->flags), cand->bssid);
  2221. #if 0
  2222. struct iw_pmkid_cand pcand;
  2223. union iwreq_data wrqu;
  2224. memset(&pcand, 0, sizeof(pcand));
  2225. if (le32_to_cpu(cand->flags) & 0x01)
  2226. pcand.flags |= IW_PMKID_CAND_PREAUTH;
  2227. pcand.index = i;
  2228. memcpy(pcand.bssid.sa_data, cand->bssid, ETH_ALEN);
  2229. memset(&wrqu, 0, sizeof(wrqu));
  2230. wrqu.data.length = sizeof(pcand);
  2231. wireless_send_event(usbdev->net, IWEVPMKIDCAND, &wrqu,
  2232. (u8 *)&pcand);
  2233. #endif
  2234. }
  2235. }
  2236. static void rndis_wlan_media_specific_indication(struct usbnet *usbdev,
  2237. struct rndis_indicate *msg, int buflen)
  2238. {
  2239. struct ndis_80211_status_indication *indication;
  2240. int len, offset;
  2241. offset = offsetof(struct rndis_indicate, status) +
  2242. le32_to_cpu(msg->offset);
  2243. len = le32_to_cpu(msg->length);
  2244. if (len < 8) {
  2245. netdev_info(usbdev->net, "media specific indication, ignore too short message (%i < 8)\n",
  2246. len);
  2247. return;
  2248. }
  2249. if (offset + len > buflen) {
  2250. netdev_info(usbdev->net, "media specific indication, too large to fit to buffer (%i > %i)\n",
  2251. offset + len, buflen);
  2252. return;
  2253. }
  2254. indication = (void *)((u8 *)msg + offset);
  2255. switch (le32_to_cpu(indication->status_type)) {
  2256. case NDIS_80211_STATUSTYPE_RADIOSTATE:
  2257. netdev_info(usbdev->net, "radio state indication: %i\n",
  2258. le32_to_cpu(indication->u.radio_status));
  2259. return;
  2260. case NDIS_80211_STATUSTYPE_MEDIASTREAMMODE:
  2261. netdev_info(usbdev->net, "media stream mode indication: %i\n",
  2262. le32_to_cpu(indication->u.media_stream_mode));
  2263. return;
  2264. case NDIS_80211_STATUSTYPE_AUTHENTICATION:
  2265. rndis_wlan_auth_indication(usbdev, indication, len);
  2266. return;
  2267. case NDIS_80211_STATUSTYPE_PMKID_CANDIDATELIST:
  2268. rndis_wlan_pmkid_cand_list_indication(usbdev, indication, len);
  2269. return;
  2270. default:
  2271. netdev_info(usbdev->net, "media specific indication: unknown status type 0x%08x\n",
  2272. le32_to_cpu(indication->status_type));
  2273. }
  2274. }
  2275. static void rndis_wlan_indication(struct usbnet *usbdev, void *ind, int buflen)
  2276. {
  2277. struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
  2278. struct rndis_indicate *msg = ind;
  2279. switch (msg->status) {
  2280. case RNDIS_STATUS_MEDIA_CONNECT:
  2281. if (priv->current_command_oid == OID_802_11_ADD_KEY) {
  2282. /* OID_802_11_ADD_KEY causes sometimes extra
  2283. * "media connect" indications which confuses driver
  2284. * and userspace to think that device is
  2285. * roaming/reassociating when it isn't.
  2286. */
  2287. netdev_dbg(usbdev->net, "ignored OID_802_11_ADD_KEY triggered 'media connect'\n");
  2288. return;
  2289. }
  2290. usbnet_pause_rx(usbdev);
  2291. netdev_info(usbdev->net, "media connect\n");
  2292. /* queue work to avoid recursive calls into rndis_command */
  2293. set_bit(WORK_LINK_UP, &priv->work_pending);
  2294. queue_work(priv->workqueue, &priv->work);
  2295. break;
  2296. case RNDIS_STATUS_MEDIA_DISCONNECT:
  2297. netdev_info(usbdev->net, "media disconnect\n");
  2298. /* queue work to avoid recursive calls into rndis_command */
  2299. set_bit(WORK_LINK_DOWN, &priv->work_pending);
  2300. queue_work(priv->workqueue, &priv->work);
  2301. break;
  2302. case RNDIS_STATUS_MEDIA_SPECIFIC_INDICATION:
  2303. rndis_wlan_media_specific_indication(usbdev, msg, buflen);
  2304. break;
  2305. default:
  2306. netdev_info(usbdev->net, "indication: 0x%08x\n",
  2307. le32_to_cpu(msg->status));
  2308. break;
  2309. }
  2310. }
  2311. static int rndis_wlan_get_caps(struct usbnet *usbdev, struct wiphy *wiphy)
  2312. {
  2313. struct {
  2314. __le32 num_items;
  2315. __le32 items[8];
  2316. } networks_supported;
  2317. struct ndis_80211_capability *caps;
  2318. u8 caps_buf[sizeof(*caps) + sizeof(caps->auth_encr_pair) * 16];
  2319. int len, retval, i, n;
  2320. struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
  2321. /* determine supported modes */
  2322. len = sizeof(networks_supported);
  2323. retval = rndis_query_oid(usbdev, OID_802_11_NETWORK_TYPES_SUPPORTED,
  2324. &networks_supported, &len);
  2325. if (retval >= 0) {
  2326. n = le32_to_cpu(networks_supported.num_items);
  2327. if (n > 8)
  2328. n = 8;
  2329. for (i = 0; i < n; i++) {
  2330. switch (le32_to_cpu(networks_supported.items[i])) {
  2331. case NDIS_80211_TYPE_FREQ_HOP:
  2332. case NDIS_80211_TYPE_DIRECT_SEQ:
  2333. priv->caps |= CAP_MODE_80211B;
  2334. break;
  2335. case NDIS_80211_TYPE_OFDM_A:
  2336. priv->caps |= CAP_MODE_80211A;
  2337. break;
  2338. case NDIS_80211_TYPE_OFDM_G:
  2339. priv->caps |= CAP_MODE_80211G;
  2340. break;
  2341. }
  2342. }
  2343. }
  2344. /* get device 802.11 capabilities, number of PMKIDs */
  2345. caps = (struct ndis_80211_capability *)caps_buf;
  2346. len = sizeof(caps_buf);
  2347. retval = rndis_query_oid(usbdev, OID_802_11_CAPABILITY, caps, &len);
  2348. if (retval >= 0) {
  2349. netdev_dbg(usbdev->net, "OID_802_11_CAPABILITY -> len %d, "
  2350. "ver %d, pmkids %d, auth-encr-pairs %d\n",
  2351. le32_to_cpu(caps->length),
  2352. le32_to_cpu(caps->version),
  2353. le32_to_cpu(caps->num_pmkids),
  2354. le32_to_cpu(caps->num_auth_encr_pair));
  2355. wiphy->max_num_pmkids = le32_to_cpu(caps->num_pmkids);
  2356. } else
  2357. wiphy->max_num_pmkids = 0;
  2358. return retval;
  2359. }
  2360. #define DEVICE_POLLER_JIFFIES (HZ)
  2361. static void rndis_device_poller(struct work_struct *work)
  2362. {
  2363. struct rndis_wlan_private *priv =
  2364. container_of(work, struct rndis_wlan_private,
  2365. dev_poller_work.work);
  2366. struct usbnet *usbdev = priv->usbdev;
  2367. __le32 rssi, tmp;
  2368. int len, ret, j;
  2369. int update_jiffies = DEVICE_POLLER_JIFFIES;
  2370. void *buf;
  2371. /* Only check/do workaround when connected. Calling is_associated()
  2372. * also polls device with rndis_command() and catches for media link
  2373. * indications.
  2374. */
  2375. if (!is_associated(usbdev))
  2376. goto end;
  2377. len = sizeof(rssi);
  2378. ret = rndis_query_oid(usbdev, OID_802_11_RSSI, &rssi, &len);
  2379. if (ret == 0)
  2380. priv->last_qual = level_to_qual(le32_to_cpu(rssi));
  2381. netdev_dbg(usbdev->net, "dev-poller: OID_802_11_RSSI -> %d, rssi:%d, qual: %d\n",
  2382. ret, le32_to_cpu(rssi), level_to_qual(le32_to_cpu(rssi)));
  2383. /* Workaround transfer stalls on poor quality links.
  2384. * TODO: find right way to fix these stalls (as stalls do not happen
  2385. * with ndiswrapper/windows driver). */
  2386. if (priv->param_workaround_interval > 0 && priv->last_qual <= 25) {
  2387. /* Decrease stats worker interval to catch stalls.
  2388. * faster. Faster than 400-500ms causes packet loss,
  2389. * Slower doesn't catch stalls fast enough.
  2390. */
  2391. j = msecs_to_jiffies(priv->param_workaround_interval);
  2392. if (j > DEVICE_POLLER_JIFFIES)
  2393. j = DEVICE_POLLER_JIFFIES;
  2394. else if (j <= 0)
  2395. j = 1;
  2396. update_jiffies = j;
  2397. /* Send scan OID. Use of both OIDs is required to get device
  2398. * working.
  2399. */
  2400. tmp = cpu_to_le32(1);
  2401. rndis_set_oid(usbdev, OID_802_11_BSSID_LIST_SCAN, &tmp,
  2402. sizeof(tmp));
  2403. len = CONTROL_BUFFER_SIZE;
  2404. buf = kmalloc(len, GFP_KERNEL);
  2405. if (!buf)
  2406. goto end;
  2407. rndis_query_oid(usbdev, OID_802_11_BSSID_LIST, buf, &len);
  2408. kfree(buf);
  2409. }
  2410. end:
  2411. if (update_jiffies >= HZ)
  2412. update_jiffies = round_jiffies_relative(update_jiffies);
  2413. else {
  2414. j = round_jiffies_relative(update_jiffies);
  2415. if (abs(j - update_jiffies) <= 10)
  2416. update_jiffies = j;
  2417. }
  2418. queue_delayed_work(priv->workqueue, &priv->dev_poller_work,
  2419. update_jiffies);
  2420. }
  2421. /*
  2422. * driver/device initialization
  2423. */
  2424. static void rndis_copy_module_params(struct usbnet *usbdev)
  2425. {
  2426. struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
  2427. priv->param_country[0] = modparam_country[0];
  2428. priv->param_country[1] = modparam_country[1];
  2429. priv->param_country[2] = 0;
  2430. priv->param_frameburst = modparam_frameburst;
  2431. priv->param_afterburner = modparam_afterburner;
  2432. priv->param_power_save = modparam_power_save;
  2433. priv->param_power_output = modparam_power_output;
  2434. priv->param_roamtrigger = modparam_roamtrigger;
  2435. priv->param_roamdelta = modparam_roamdelta;
  2436. priv->param_country[0] = toupper(priv->param_country[0]);
  2437. priv->param_country[1] = toupper(priv->param_country[1]);
  2438. /* doesn't support EU as country code, use FI instead */
  2439. if (!strcmp(priv->param_country, "EU"))
  2440. strcpy(priv->param_country, "FI");
  2441. if (priv->param_power_save < 0)
  2442. priv->param_power_save = 0;
  2443. else if (priv->param_power_save > 2)
  2444. priv->param_power_save = 2;
  2445. if (priv->param_power_output < 0)
  2446. priv->param_power_output = 0;
  2447. else if (priv->param_power_output > 3)
  2448. priv->param_power_output = 3;
  2449. if (priv->param_roamtrigger < -80)
  2450. priv->param_roamtrigger = -80;
  2451. else if (priv->param_roamtrigger > -60)
  2452. priv->param_roamtrigger = -60;
  2453. if (priv->param_roamdelta < 0)
  2454. priv->param_roamdelta = 0;
  2455. else if (priv->param_roamdelta > 2)
  2456. priv->param_roamdelta = 2;
  2457. if (modparam_workaround_interval < 0)
  2458. priv->param_workaround_interval = 500;
  2459. else
  2460. priv->param_workaround_interval = modparam_workaround_interval;
  2461. }
  2462. static int bcm4320a_early_init(struct usbnet *usbdev)
  2463. {
  2464. /* copy module parameters for bcm4320a so that iwconfig reports txpower
  2465. * and workaround parameter is copied to private structure correctly.
  2466. */
  2467. rndis_copy_module_params(usbdev);
  2468. /* bcm4320a doesn't handle configuration parameters well. Try
  2469. * set any and you get partially zeroed mac and broken device.
  2470. */
  2471. return 0;
  2472. }
  2473. static int bcm4320b_early_init(struct usbnet *usbdev)
  2474. {
  2475. struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
  2476. char buf[8];
  2477. rndis_copy_module_params(usbdev);
  2478. /* Early initialization settings, setting these won't have effect
  2479. * if called after generic_rndis_bind().
  2480. */
  2481. rndis_set_config_parameter_str(usbdev, "Country", priv->param_country);
  2482. rndis_set_config_parameter_str(usbdev, "FrameBursting",
  2483. priv->param_frameburst ? "1" : "0");
  2484. rndis_set_config_parameter_str(usbdev, "Afterburner",
  2485. priv->param_afterburner ? "1" : "0");
  2486. sprintf(buf, "%d", priv->param_power_save);
  2487. rndis_set_config_parameter_str(usbdev, "PowerSaveMode", buf);
  2488. sprintf(buf, "%d", priv->param_power_output);
  2489. rndis_set_config_parameter_str(usbdev, "PwrOut", buf);
  2490. sprintf(buf, "%d", priv->param_roamtrigger);
  2491. rndis_set_config_parameter_str(usbdev, "RoamTrigger", buf);
  2492. sprintf(buf, "%d", priv->param_roamdelta);
  2493. rndis_set_config_parameter_str(usbdev, "RoamDelta", buf);
  2494. return 0;
  2495. }
  2496. /* same as rndis_netdev_ops but with local multicast handler */
  2497. static const struct net_device_ops rndis_wlan_netdev_ops = {
  2498. .ndo_open = usbnet_open,
  2499. .ndo_stop = usbnet_stop,
  2500. .ndo_start_xmit = usbnet_start_xmit,
  2501. .ndo_tx_timeout = usbnet_tx_timeout,
  2502. .ndo_set_mac_address = eth_mac_addr,
  2503. .ndo_validate_addr = eth_validate_addr,
  2504. .ndo_set_multicast_list = rndis_wlan_set_multicast_list,
  2505. };
  2506. static int rndis_wlan_bind(struct usbnet *usbdev, struct usb_interface *intf)
  2507. {
  2508. struct wiphy *wiphy;
  2509. struct rndis_wlan_private *priv;
  2510. int retval, len;
  2511. __le32 tmp;
  2512. /* allocate wiphy and rndis private data
  2513. * NOTE: We only support a single virtual interface, so wiphy
  2514. * and wireless_dev are somewhat synonymous for this device.
  2515. */
  2516. wiphy = wiphy_new(&rndis_config_ops, sizeof(struct rndis_wlan_private));
  2517. if (!wiphy)
  2518. return -ENOMEM;
  2519. priv = wiphy_priv(wiphy);
  2520. usbdev->net->ieee80211_ptr = &priv->wdev;
  2521. priv->wdev.wiphy = wiphy;
  2522. priv->wdev.iftype = NL80211_IFTYPE_STATION;
  2523. /* These have to be initialized before calling generic_rndis_bind().
  2524. * Otherwise we'll be in big trouble in rndis_wlan_early_init().
  2525. */
  2526. usbdev->driver_priv = priv;
  2527. priv->usbdev = usbdev;
  2528. mutex_init(&priv->command_lock);
  2529. /* because rndis_command() sleeps we need to use workqueue */
  2530. priv->workqueue = create_singlethread_workqueue("rndis_wlan");
  2531. INIT_WORK(&priv->work, rndis_wlan_worker);
  2532. INIT_DELAYED_WORK(&priv->dev_poller_work, rndis_device_poller);
  2533. INIT_DELAYED_WORK(&priv->scan_work, rndis_get_scan_results);
  2534. /* try bind rndis_host */
  2535. retval = generic_rndis_bind(usbdev, intf, FLAG_RNDIS_PHYM_WIRELESS);
  2536. if (retval < 0)
  2537. goto fail;
  2538. /* generic_rndis_bind set packet filter to multicast_all+
  2539. * promisc mode which doesn't work well for our devices (device
  2540. * picks up rssi to closest station instead of to access point).
  2541. *
  2542. * rndis_host wants to avoid all OID as much as possible
  2543. * so do promisc/multicast handling in rndis_wlan.
  2544. */
  2545. usbdev->net->netdev_ops = &rndis_wlan_netdev_ops;
  2546. tmp = RNDIS_PACKET_TYPE_DIRECTED | RNDIS_PACKET_TYPE_BROADCAST;
  2547. retval = rndis_set_oid(usbdev, OID_GEN_CURRENT_PACKET_FILTER, &tmp,
  2548. sizeof(tmp));
  2549. len = sizeof(tmp);
  2550. retval = rndis_query_oid(usbdev, OID_802_3_MAXIMUM_LIST_SIZE, &tmp,
  2551. &len);
  2552. priv->multicast_size = le32_to_cpu(tmp);
  2553. if (retval < 0 || priv->multicast_size < 0)
  2554. priv->multicast_size = 0;
  2555. if (priv->multicast_size > 0)
  2556. usbdev->net->flags |= IFF_MULTICAST;
  2557. else
  2558. usbdev->net->flags &= ~IFF_MULTICAST;
  2559. /* fill-out wiphy structure and register w/ cfg80211 */
  2560. memcpy(wiphy->perm_addr, usbdev->net->dev_addr, ETH_ALEN);
  2561. wiphy->privid = rndis_wiphy_privid;
  2562. wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION)
  2563. | BIT(NL80211_IFTYPE_ADHOC);
  2564. wiphy->max_scan_ssids = 1;
  2565. /* TODO: fill-out band/encr information based on priv->caps */
  2566. rndis_wlan_get_caps(usbdev, wiphy);
  2567. memcpy(priv->channels, rndis_channels, sizeof(rndis_channels));
  2568. memcpy(priv->rates, rndis_rates, sizeof(rndis_rates));
  2569. priv->band.channels = priv->channels;
  2570. priv->band.n_channels = ARRAY_SIZE(rndis_channels);
  2571. priv->band.bitrates = priv->rates;
  2572. priv->band.n_bitrates = ARRAY_SIZE(rndis_rates);
  2573. wiphy->bands[IEEE80211_BAND_2GHZ] = &priv->band;
  2574. wiphy->signal_type = CFG80211_SIGNAL_TYPE_UNSPEC;
  2575. memcpy(priv->cipher_suites, rndis_cipher_suites,
  2576. sizeof(rndis_cipher_suites));
  2577. wiphy->cipher_suites = priv->cipher_suites;
  2578. wiphy->n_cipher_suites = ARRAY_SIZE(rndis_cipher_suites);
  2579. set_wiphy_dev(wiphy, &usbdev->udev->dev);
  2580. if (wiphy_register(wiphy)) {
  2581. retval = -ENODEV;
  2582. goto fail;
  2583. }
  2584. set_default_iw_params(usbdev);
  2585. /* set default rts/frag */
  2586. rndis_set_wiphy_params(wiphy,
  2587. WIPHY_PARAM_FRAG_THRESHOLD | WIPHY_PARAM_RTS_THRESHOLD);
  2588. /* turn radio on */
  2589. priv->radio_on = true;
  2590. disassociate(usbdev, true);
  2591. netif_carrier_off(usbdev->net);
  2592. return 0;
  2593. fail:
  2594. cancel_delayed_work_sync(&priv->dev_poller_work);
  2595. cancel_delayed_work_sync(&priv->scan_work);
  2596. cancel_work_sync(&priv->work);
  2597. flush_workqueue(priv->workqueue);
  2598. destroy_workqueue(priv->workqueue);
  2599. wiphy_free(wiphy);
  2600. return retval;
  2601. }
  2602. static void rndis_wlan_unbind(struct usbnet *usbdev, struct usb_interface *intf)
  2603. {
  2604. struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
  2605. /* turn radio off */
  2606. disassociate(usbdev, false);
  2607. cancel_delayed_work_sync(&priv->dev_poller_work);
  2608. cancel_delayed_work_sync(&priv->scan_work);
  2609. cancel_work_sync(&priv->work);
  2610. flush_workqueue(priv->workqueue);
  2611. destroy_workqueue(priv->workqueue);
  2612. rndis_unbind(usbdev, intf);
  2613. wiphy_unregister(priv->wdev.wiphy);
  2614. wiphy_free(priv->wdev.wiphy);
  2615. }
  2616. static int rndis_wlan_reset(struct usbnet *usbdev)
  2617. {
  2618. struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
  2619. int retval;
  2620. netdev_dbg(usbdev->net, "%s()\n", __func__);
  2621. retval = rndis_reset(usbdev);
  2622. if (retval)
  2623. netdev_warn(usbdev->net, "rndis_reset failed: %d\n", retval);
  2624. /* rndis_reset cleared multicast list, so restore here.
  2625. (set_multicast_list() also turns on current packet filter) */
  2626. set_multicast_list(usbdev);
  2627. queue_delayed_work(priv->workqueue, &priv->dev_poller_work,
  2628. round_jiffies_relative(DEVICE_POLLER_JIFFIES));
  2629. return deauthenticate(usbdev);
  2630. }
  2631. static int rndis_wlan_stop(struct usbnet *usbdev)
  2632. {
  2633. struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
  2634. int retval;
  2635. __le32 filter;
  2636. netdev_dbg(usbdev->net, "%s()\n", __func__);
  2637. retval = disassociate(usbdev, false);
  2638. priv->work_pending = 0;
  2639. cancel_delayed_work_sync(&priv->dev_poller_work);
  2640. cancel_delayed_work_sync(&priv->scan_work);
  2641. cancel_work_sync(&priv->work);
  2642. flush_workqueue(priv->workqueue);
  2643. if (priv->scan_request) {
  2644. cfg80211_scan_done(priv->scan_request, true);
  2645. priv->scan_request = NULL;
  2646. }
  2647. /* Set current packet filter zero to block receiving data packets from
  2648. device. */
  2649. filter = 0;
  2650. rndis_set_oid(usbdev, OID_GEN_CURRENT_PACKET_FILTER, &filter,
  2651. sizeof(filter));
  2652. return retval;
  2653. }
  2654. static const struct driver_info bcm4320b_info = {
  2655. .description = "Wireless RNDIS device, BCM4320b based",
  2656. .flags = FLAG_WLAN | FLAG_FRAMING_RN | FLAG_NO_SETINT |
  2657. FLAG_AVOID_UNLINK_URBS,
  2658. .bind = rndis_wlan_bind,
  2659. .unbind = rndis_wlan_unbind,
  2660. .status = rndis_status,
  2661. .rx_fixup = rndis_rx_fixup,
  2662. .tx_fixup = rndis_tx_fixup,
  2663. .reset = rndis_wlan_reset,
  2664. .stop = rndis_wlan_stop,
  2665. .early_init = bcm4320b_early_init,
  2666. .indication = rndis_wlan_indication,
  2667. };
  2668. static const struct driver_info bcm4320a_info = {
  2669. .description = "Wireless RNDIS device, BCM4320a based",
  2670. .flags = FLAG_WLAN | FLAG_FRAMING_RN | FLAG_NO_SETINT |
  2671. FLAG_AVOID_UNLINK_URBS,
  2672. .bind = rndis_wlan_bind,
  2673. .unbind = rndis_wlan_unbind,
  2674. .status = rndis_status,
  2675. .rx_fixup = rndis_rx_fixup,
  2676. .tx_fixup = rndis_tx_fixup,
  2677. .reset = rndis_wlan_reset,
  2678. .stop = rndis_wlan_stop,
  2679. .early_init = bcm4320a_early_init,
  2680. .indication = rndis_wlan_indication,
  2681. };
  2682. static const struct driver_info rndis_wlan_info = {
  2683. .description = "Wireless RNDIS device",
  2684. .flags = FLAG_WLAN | FLAG_FRAMING_RN | FLAG_NO_SETINT |
  2685. FLAG_AVOID_UNLINK_URBS,
  2686. .bind = rndis_wlan_bind,
  2687. .unbind = rndis_wlan_unbind,
  2688. .status = rndis_status,
  2689. .rx_fixup = rndis_rx_fixup,
  2690. .tx_fixup = rndis_tx_fixup,
  2691. .reset = rndis_wlan_reset,
  2692. .stop = rndis_wlan_stop,
  2693. .early_init = bcm4320a_early_init,
  2694. .indication = rndis_wlan_indication,
  2695. };
  2696. /*-------------------------------------------------------------------------*/
  2697. static const struct usb_device_id products [] = {
  2698. #define RNDIS_MASTER_INTERFACE \
  2699. .bInterfaceClass = USB_CLASS_COMM, \
  2700. .bInterfaceSubClass = 2 /* ACM */, \
  2701. .bInterfaceProtocol = 0x0ff
  2702. /* INF driver for these devices have DriverVer >= 4.xx.xx.xx and many custom
  2703. * parameters available. Chipset marked as 'BCM4320SKFBG' in NDISwrapper-wiki.
  2704. */
  2705. {
  2706. .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
  2707. | USB_DEVICE_ID_MATCH_DEVICE,
  2708. .idVendor = 0x0411,
  2709. .idProduct = 0x00bc, /* Buffalo WLI-U2-KG125S */
  2710. RNDIS_MASTER_INTERFACE,
  2711. .driver_info = (unsigned long) &bcm4320b_info,
  2712. }, {
  2713. .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
  2714. | USB_DEVICE_ID_MATCH_DEVICE,
  2715. .idVendor = 0x0baf,
  2716. .idProduct = 0x011b, /* U.S. Robotics USR5421 */
  2717. RNDIS_MASTER_INTERFACE,
  2718. .driver_info = (unsigned long) &bcm4320b_info,
  2719. }, {
  2720. .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
  2721. | USB_DEVICE_ID_MATCH_DEVICE,
  2722. .idVendor = 0x050d,
  2723. .idProduct = 0x011b, /* Belkin F5D7051 */
  2724. RNDIS_MASTER_INTERFACE,
  2725. .driver_info = (unsigned long) &bcm4320b_info,
  2726. }, {
  2727. .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
  2728. | USB_DEVICE_ID_MATCH_DEVICE,
  2729. .idVendor = 0x1799, /* Belkin has two vendor ids */
  2730. .idProduct = 0x011b, /* Belkin F5D7051 */
  2731. RNDIS_MASTER_INTERFACE,
  2732. .driver_info = (unsigned long) &bcm4320b_info,
  2733. }, {
  2734. .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
  2735. | USB_DEVICE_ID_MATCH_DEVICE,
  2736. .idVendor = 0x13b1,
  2737. .idProduct = 0x0014, /* Linksys WUSB54GSv2 */
  2738. RNDIS_MASTER_INTERFACE,
  2739. .driver_info = (unsigned long) &bcm4320b_info,
  2740. }, {
  2741. .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
  2742. | USB_DEVICE_ID_MATCH_DEVICE,
  2743. .idVendor = 0x13b1,
  2744. .idProduct = 0x0026, /* Linksys WUSB54GSC */
  2745. RNDIS_MASTER_INTERFACE,
  2746. .driver_info = (unsigned long) &bcm4320b_info,
  2747. }, {
  2748. .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
  2749. | USB_DEVICE_ID_MATCH_DEVICE,
  2750. .idVendor = 0x0b05,
  2751. .idProduct = 0x1717, /* Asus WL169gE */
  2752. RNDIS_MASTER_INTERFACE,
  2753. .driver_info = (unsigned long) &bcm4320b_info,
  2754. }, {
  2755. .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
  2756. | USB_DEVICE_ID_MATCH_DEVICE,
  2757. .idVendor = 0x0a5c,
  2758. .idProduct = 0xd11b, /* Eminent EM4045 */
  2759. RNDIS_MASTER_INTERFACE,
  2760. .driver_info = (unsigned long) &bcm4320b_info,
  2761. }, {
  2762. .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
  2763. | USB_DEVICE_ID_MATCH_DEVICE,
  2764. .idVendor = 0x1690,
  2765. .idProduct = 0x0715, /* BT Voyager 1055 */
  2766. RNDIS_MASTER_INTERFACE,
  2767. .driver_info = (unsigned long) &bcm4320b_info,
  2768. },
  2769. /* These devices have DriverVer < 4.xx.xx.xx and do not have any custom
  2770. * parameters available, hardware probably contain older firmware version with
  2771. * no way of updating. Chipset marked as 'BCM4320????' in NDISwrapper-wiki.
  2772. */
  2773. {
  2774. .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
  2775. | USB_DEVICE_ID_MATCH_DEVICE,
  2776. .idVendor = 0x13b1,
  2777. .idProduct = 0x000e, /* Linksys WUSB54GSv1 */
  2778. RNDIS_MASTER_INTERFACE,
  2779. .driver_info = (unsigned long) &bcm4320a_info,
  2780. }, {
  2781. .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
  2782. | USB_DEVICE_ID_MATCH_DEVICE,
  2783. .idVendor = 0x0baf,
  2784. .idProduct = 0x0111, /* U.S. Robotics USR5420 */
  2785. RNDIS_MASTER_INTERFACE,
  2786. .driver_info = (unsigned long) &bcm4320a_info,
  2787. }, {
  2788. .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
  2789. | USB_DEVICE_ID_MATCH_DEVICE,
  2790. .idVendor = 0x0411,
  2791. .idProduct = 0x004b, /* BUFFALO WLI-USB-G54 */
  2792. RNDIS_MASTER_INTERFACE,
  2793. .driver_info = (unsigned long) &bcm4320a_info,
  2794. },
  2795. /* Generic Wireless RNDIS devices that we don't have exact
  2796. * idVendor/idProduct/chip yet.
  2797. */
  2798. {
  2799. /* RNDIS is MSFT's un-official variant of CDC ACM */
  2800. USB_INTERFACE_INFO(USB_CLASS_COMM, 2 /* ACM */, 0x0ff),
  2801. .driver_info = (unsigned long) &rndis_wlan_info,
  2802. }, {
  2803. /* "ActiveSync" is an undocumented variant of RNDIS, used in WM5 */
  2804. USB_INTERFACE_INFO(USB_CLASS_MISC, 1, 1),
  2805. .driver_info = (unsigned long) &rndis_wlan_info,
  2806. },
  2807. { }, // END
  2808. };
  2809. MODULE_DEVICE_TABLE(usb, products);
  2810. static struct usb_driver rndis_wlan_driver = {
  2811. .name = "rndis_wlan",
  2812. .id_table = products,
  2813. .probe = usbnet_probe,
  2814. .disconnect = usbnet_disconnect,
  2815. .suspend = usbnet_suspend,
  2816. .resume = usbnet_resume,
  2817. };
  2818. static int __init rndis_wlan_init(void)
  2819. {
  2820. return usb_register(&rndis_wlan_driver);
  2821. }
  2822. module_init(rndis_wlan_init);
  2823. static void __exit rndis_wlan_exit(void)
  2824. {
  2825. usb_deregister(&rndis_wlan_driver);
  2826. }
  2827. module_exit(rndis_wlan_exit);
  2828. MODULE_AUTHOR("Bjorge Dijkstra");
  2829. MODULE_AUTHOR("Jussi Kivilinna");
  2830. MODULE_DESCRIPTION("Driver for RNDIS based USB Wireless adapters");
  2831. MODULE_LICENSE("GPL");