rndis_wlan.c 93 KB

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