rndis_wlan.c 94 KB

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