rndis_wlan.c 94 KB

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