rndis_wlan.c 93 KB

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