rndis_wlan.c 92 KB

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