rndis_wlan.c 91 KB

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