mlme.c 120 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303
  1. /*
  2. * BSS client mode implementation
  3. * Copyright 2003-2008, Jouni Malinen <j@w1.fi>
  4. * Copyright 2004, Instant802 Networks, Inc.
  5. * Copyright 2005, Devicescape Software, Inc.
  6. * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
  7. * Copyright 2007, Michael Wu <flamingice@sourmilk.net>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as
  11. * published by the Free Software Foundation.
  12. */
  13. #include <linux/delay.h>
  14. #include <linux/if_ether.h>
  15. #include <linux/skbuff.h>
  16. #include <linux/if_arp.h>
  17. #include <linux/etherdevice.h>
  18. #include <linux/moduleparam.h>
  19. #include <linux/rtnetlink.h>
  20. #include <linux/pm_qos.h>
  21. #include <linux/crc32.h>
  22. #include <linux/slab.h>
  23. #include <linux/export.h>
  24. #include <net/mac80211.h>
  25. #include <asm/unaligned.h>
  26. #include "ieee80211_i.h"
  27. #include "driver-ops.h"
  28. #include "rate.h"
  29. #include "led.h"
  30. #define IEEE80211_AUTH_TIMEOUT (HZ / 5)
  31. #define IEEE80211_AUTH_TIMEOUT_LONG (HZ / 2)
  32. #define IEEE80211_AUTH_TIMEOUT_SHORT (HZ / 10)
  33. #define IEEE80211_AUTH_MAX_TRIES 3
  34. #define IEEE80211_AUTH_WAIT_ASSOC (HZ * 5)
  35. #define IEEE80211_ASSOC_TIMEOUT (HZ / 5)
  36. #define IEEE80211_ASSOC_TIMEOUT_LONG (HZ / 2)
  37. #define IEEE80211_ASSOC_TIMEOUT_SHORT (HZ / 10)
  38. #define IEEE80211_ASSOC_MAX_TRIES 3
  39. static int max_nullfunc_tries = 2;
  40. module_param(max_nullfunc_tries, int, 0644);
  41. MODULE_PARM_DESC(max_nullfunc_tries,
  42. "Maximum nullfunc tx tries before disconnecting (reason 4).");
  43. static int max_probe_tries = 5;
  44. module_param(max_probe_tries, int, 0644);
  45. MODULE_PARM_DESC(max_probe_tries,
  46. "Maximum probe tries before disconnecting (reason 4).");
  47. /*
  48. * Beacon loss timeout is calculated as N frames times the
  49. * advertised beacon interval. This may need to be somewhat
  50. * higher than what hardware might detect to account for
  51. * delays in the host processing frames. But since we also
  52. * probe on beacon miss before declaring the connection lost
  53. * default to what we want.
  54. */
  55. static int beacon_loss_count = 7;
  56. module_param(beacon_loss_count, int, 0644);
  57. MODULE_PARM_DESC(beacon_loss_count,
  58. "Number of beacon intervals before we decide beacon was lost.");
  59. /*
  60. * Time the connection can be idle before we probe
  61. * it to see if we can still talk to the AP.
  62. */
  63. #define IEEE80211_CONNECTION_IDLE_TIME (30 * HZ)
  64. /*
  65. * Time we wait for a probe response after sending
  66. * a probe request because of beacon loss or for
  67. * checking the connection still works.
  68. */
  69. static int probe_wait_ms = 500;
  70. module_param(probe_wait_ms, int, 0644);
  71. MODULE_PARM_DESC(probe_wait_ms,
  72. "Maximum time(ms) to wait for probe response"
  73. " before disconnecting (reason 4).");
  74. /*
  75. * Weight given to the latest Beacon frame when calculating average signal
  76. * strength for Beacon frames received in the current BSS. This must be
  77. * between 1 and 15.
  78. */
  79. #define IEEE80211_SIGNAL_AVE_WEIGHT 3
  80. /*
  81. * How many Beacon frames need to have been used in average signal strength
  82. * before starting to indicate signal change events.
  83. */
  84. #define IEEE80211_SIGNAL_AVE_MIN_COUNT 4
  85. /*
  86. * We can have multiple work items (and connection probing)
  87. * scheduling this timer, but we need to take care to only
  88. * reschedule it when it should fire _earlier_ than it was
  89. * asked for before, or if it's not pending right now. This
  90. * function ensures that. Note that it then is required to
  91. * run this function for all timeouts after the first one
  92. * has happened -- the work that runs from this timer will
  93. * do that.
  94. */
  95. static void run_again(struct ieee80211_sub_if_data *sdata,
  96. unsigned long timeout)
  97. {
  98. sdata_assert_lock(sdata);
  99. if (!timer_pending(&sdata->u.mgd.timer) ||
  100. time_before(timeout, sdata->u.mgd.timer.expires))
  101. mod_timer(&sdata->u.mgd.timer, timeout);
  102. }
  103. void ieee80211_sta_reset_beacon_monitor(struct ieee80211_sub_if_data *sdata)
  104. {
  105. if (sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER)
  106. return;
  107. if (sdata->local->hw.flags & IEEE80211_HW_CONNECTION_MONITOR)
  108. return;
  109. mod_timer(&sdata->u.mgd.bcn_mon_timer,
  110. round_jiffies_up(jiffies + sdata->u.mgd.beacon_timeout));
  111. }
  112. void ieee80211_sta_reset_conn_monitor(struct ieee80211_sub_if_data *sdata)
  113. {
  114. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  115. if (unlikely(!sdata->u.mgd.associated))
  116. return;
  117. if (sdata->local->hw.flags & IEEE80211_HW_CONNECTION_MONITOR)
  118. return;
  119. mod_timer(&sdata->u.mgd.conn_mon_timer,
  120. round_jiffies_up(jiffies + IEEE80211_CONNECTION_IDLE_TIME));
  121. ifmgd->probe_send_count = 0;
  122. }
  123. static int ecw2cw(int ecw)
  124. {
  125. return (1 << ecw) - 1;
  126. }
  127. static u32
  128. ieee80211_determine_chantype(struct ieee80211_sub_if_data *sdata,
  129. struct ieee80211_supported_band *sband,
  130. struct ieee80211_channel *channel,
  131. const struct ieee80211_ht_operation *ht_oper,
  132. const struct ieee80211_vht_operation *vht_oper,
  133. struct cfg80211_chan_def *chandef, bool tracking)
  134. {
  135. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  136. struct cfg80211_chan_def vht_chandef;
  137. u32 ht_cfreq, ret;
  138. chandef->chan = channel;
  139. chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
  140. chandef->center_freq1 = channel->center_freq;
  141. chandef->center_freq2 = 0;
  142. if (!ht_oper || !sband->ht_cap.ht_supported) {
  143. ret = IEEE80211_STA_DISABLE_HT | IEEE80211_STA_DISABLE_VHT;
  144. goto out;
  145. }
  146. chandef->width = NL80211_CHAN_WIDTH_20;
  147. ht_cfreq = ieee80211_channel_to_frequency(ht_oper->primary_chan,
  148. channel->band);
  149. /* check that channel matches the right operating channel */
  150. if (!tracking && channel->center_freq != ht_cfreq) {
  151. /*
  152. * It's possible that some APs are confused here;
  153. * Netgear WNDR3700 sometimes reports 4 higher than
  154. * the actual channel in association responses, but
  155. * since we look at probe response/beacon data here
  156. * it should be OK.
  157. */
  158. sdata_info(sdata,
  159. "Wrong control channel: center-freq: %d ht-cfreq: %d ht->primary_chan: %d band: %d - Disabling HT\n",
  160. channel->center_freq, ht_cfreq,
  161. ht_oper->primary_chan, channel->band);
  162. ret = IEEE80211_STA_DISABLE_HT | IEEE80211_STA_DISABLE_VHT;
  163. goto out;
  164. }
  165. /* check 40 MHz support, if we have it */
  166. if (sband->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) {
  167. switch (ht_oper->ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) {
  168. case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
  169. chandef->width = NL80211_CHAN_WIDTH_40;
  170. chandef->center_freq1 += 10;
  171. break;
  172. case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
  173. chandef->width = NL80211_CHAN_WIDTH_40;
  174. chandef->center_freq1 -= 10;
  175. break;
  176. }
  177. } else {
  178. /* 40 MHz (and 80 MHz) must be supported for VHT */
  179. ret = IEEE80211_STA_DISABLE_VHT;
  180. /* also mark 40 MHz disabled */
  181. ret |= IEEE80211_STA_DISABLE_40MHZ;
  182. goto out;
  183. }
  184. if (!vht_oper || !sband->vht_cap.vht_supported) {
  185. ret = IEEE80211_STA_DISABLE_VHT;
  186. goto out;
  187. }
  188. vht_chandef.chan = channel;
  189. vht_chandef.center_freq1 =
  190. ieee80211_channel_to_frequency(vht_oper->center_freq_seg1_idx,
  191. channel->band);
  192. vht_chandef.center_freq2 = 0;
  193. switch (vht_oper->chan_width) {
  194. case IEEE80211_VHT_CHANWIDTH_USE_HT:
  195. vht_chandef.width = chandef->width;
  196. break;
  197. case IEEE80211_VHT_CHANWIDTH_80MHZ:
  198. vht_chandef.width = NL80211_CHAN_WIDTH_80;
  199. break;
  200. case IEEE80211_VHT_CHANWIDTH_160MHZ:
  201. vht_chandef.width = NL80211_CHAN_WIDTH_160;
  202. break;
  203. case IEEE80211_VHT_CHANWIDTH_80P80MHZ:
  204. vht_chandef.width = NL80211_CHAN_WIDTH_80P80;
  205. vht_chandef.center_freq2 =
  206. ieee80211_channel_to_frequency(
  207. vht_oper->center_freq_seg2_idx,
  208. channel->band);
  209. break;
  210. default:
  211. if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
  212. sdata_info(sdata,
  213. "AP VHT operation IE has invalid channel width (%d), disable VHT\n",
  214. vht_oper->chan_width);
  215. ret = IEEE80211_STA_DISABLE_VHT;
  216. goto out;
  217. }
  218. if (!cfg80211_chandef_valid(&vht_chandef)) {
  219. if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
  220. sdata_info(sdata,
  221. "AP VHT information is invalid, disable VHT\n");
  222. ret = IEEE80211_STA_DISABLE_VHT;
  223. goto out;
  224. }
  225. if (cfg80211_chandef_identical(chandef, &vht_chandef)) {
  226. ret = 0;
  227. goto out;
  228. }
  229. if (!cfg80211_chandef_compatible(chandef, &vht_chandef)) {
  230. if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
  231. sdata_info(sdata,
  232. "AP VHT information doesn't match HT, disable VHT\n");
  233. ret = IEEE80211_STA_DISABLE_VHT;
  234. goto out;
  235. }
  236. *chandef = vht_chandef;
  237. ret = 0;
  238. out:
  239. /* don't print the message below for VHT mismatch if VHT is disabled */
  240. if (ret & IEEE80211_STA_DISABLE_VHT)
  241. vht_chandef = *chandef;
  242. /*
  243. * Ignore the DISABLED flag when we're already connected and only
  244. * tracking the APs beacon for bandwidth changes - otherwise we
  245. * might get disconnected here if we connect to an AP, update our
  246. * regulatory information based on the AP's country IE and the
  247. * information we have is wrong/outdated and disables the channel
  248. * that we're actually using for the connection to the AP.
  249. */
  250. while (!cfg80211_chandef_usable(sdata->local->hw.wiphy, chandef,
  251. tracking ? 0 :
  252. IEEE80211_CHAN_DISABLED)) {
  253. if (WARN_ON(chandef->width == NL80211_CHAN_WIDTH_20_NOHT)) {
  254. ret = IEEE80211_STA_DISABLE_HT |
  255. IEEE80211_STA_DISABLE_VHT;
  256. break;
  257. }
  258. ret |= ieee80211_chandef_downgrade(chandef);
  259. }
  260. if (chandef->width != vht_chandef.width && !tracking)
  261. sdata_info(sdata,
  262. "capabilities/regulatory prevented using AP HT/VHT configuration, downgraded\n");
  263. WARN_ON_ONCE(!cfg80211_chandef_valid(chandef));
  264. return ret;
  265. }
  266. static int ieee80211_config_bw(struct ieee80211_sub_if_data *sdata,
  267. struct sta_info *sta,
  268. const struct ieee80211_ht_operation *ht_oper,
  269. const struct ieee80211_vht_operation *vht_oper,
  270. const u8 *bssid, u32 *changed)
  271. {
  272. struct ieee80211_local *local = sdata->local;
  273. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  274. struct ieee80211_supported_band *sband;
  275. struct ieee80211_channel *chan;
  276. struct cfg80211_chan_def chandef;
  277. u16 ht_opmode;
  278. u32 flags;
  279. enum ieee80211_sta_rx_bandwidth new_sta_bw;
  280. int ret;
  281. /* if HT was/is disabled, don't track any bandwidth changes */
  282. if (ifmgd->flags & IEEE80211_STA_DISABLE_HT || !ht_oper)
  283. return 0;
  284. /* don't check VHT if we associated as non-VHT station */
  285. if (ifmgd->flags & IEEE80211_STA_DISABLE_VHT)
  286. vht_oper = NULL;
  287. if (WARN_ON_ONCE(!sta))
  288. return -EINVAL;
  289. chan = sdata->vif.bss_conf.chandef.chan;
  290. sband = local->hw.wiphy->bands[chan->band];
  291. /* calculate new channel (type) based on HT/VHT operation IEs */
  292. flags = ieee80211_determine_chantype(sdata, sband, chan, ht_oper,
  293. vht_oper, &chandef, true);
  294. /*
  295. * Downgrade the new channel if we associated with restricted
  296. * capabilities. For example, if we associated as a 20 MHz STA
  297. * to a 40 MHz AP (due to regulatory, capabilities or config
  298. * reasons) then switching to a 40 MHz channel now won't do us
  299. * any good -- we couldn't use it with the AP.
  300. */
  301. if (ifmgd->flags & IEEE80211_STA_DISABLE_80P80MHZ &&
  302. chandef.width == NL80211_CHAN_WIDTH_80P80)
  303. flags |= ieee80211_chandef_downgrade(&chandef);
  304. if (ifmgd->flags & IEEE80211_STA_DISABLE_160MHZ &&
  305. chandef.width == NL80211_CHAN_WIDTH_160)
  306. flags |= ieee80211_chandef_downgrade(&chandef);
  307. if (ifmgd->flags & IEEE80211_STA_DISABLE_40MHZ &&
  308. chandef.width > NL80211_CHAN_WIDTH_20)
  309. flags |= ieee80211_chandef_downgrade(&chandef);
  310. if (cfg80211_chandef_identical(&chandef, &sdata->vif.bss_conf.chandef))
  311. return 0;
  312. sdata_info(sdata,
  313. "AP %pM changed bandwidth, new config is %d MHz, width %d (%d/%d MHz)\n",
  314. ifmgd->bssid, chandef.chan->center_freq, chandef.width,
  315. chandef.center_freq1, chandef.center_freq2);
  316. if (flags != (ifmgd->flags & (IEEE80211_STA_DISABLE_HT |
  317. IEEE80211_STA_DISABLE_VHT |
  318. IEEE80211_STA_DISABLE_40MHZ |
  319. IEEE80211_STA_DISABLE_80P80MHZ |
  320. IEEE80211_STA_DISABLE_160MHZ)) ||
  321. !cfg80211_chandef_valid(&chandef)) {
  322. sdata_info(sdata,
  323. "AP %pM changed bandwidth in a way we can't support - disconnect\n",
  324. ifmgd->bssid);
  325. return -EINVAL;
  326. }
  327. switch (chandef.width) {
  328. case NL80211_CHAN_WIDTH_20_NOHT:
  329. case NL80211_CHAN_WIDTH_20:
  330. new_sta_bw = IEEE80211_STA_RX_BW_20;
  331. break;
  332. case NL80211_CHAN_WIDTH_40:
  333. new_sta_bw = IEEE80211_STA_RX_BW_40;
  334. break;
  335. case NL80211_CHAN_WIDTH_80:
  336. new_sta_bw = IEEE80211_STA_RX_BW_80;
  337. break;
  338. case NL80211_CHAN_WIDTH_80P80:
  339. case NL80211_CHAN_WIDTH_160:
  340. new_sta_bw = IEEE80211_STA_RX_BW_160;
  341. break;
  342. default:
  343. return -EINVAL;
  344. }
  345. if (new_sta_bw > sta->cur_max_bandwidth)
  346. new_sta_bw = sta->cur_max_bandwidth;
  347. if (new_sta_bw < sta->sta.bandwidth) {
  348. sta->sta.bandwidth = new_sta_bw;
  349. rate_control_rate_update(local, sband, sta,
  350. IEEE80211_RC_BW_CHANGED);
  351. }
  352. ret = ieee80211_vif_change_bandwidth(sdata, &chandef, changed);
  353. if (ret) {
  354. sdata_info(sdata,
  355. "AP %pM changed bandwidth to incompatible one - disconnect\n",
  356. ifmgd->bssid);
  357. return ret;
  358. }
  359. if (new_sta_bw > sta->sta.bandwidth) {
  360. sta->sta.bandwidth = new_sta_bw;
  361. rate_control_rate_update(local, sband, sta,
  362. IEEE80211_RC_BW_CHANGED);
  363. }
  364. ht_opmode = le16_to_cpu(ht_oper->operation_mode);
  365. /* if bss configuration changed store the new one */
  366. if (sdata->vif.bss_conf.ht_operation_mode != ht_opmode) {
  367. *changed |= BSS_CHANGED_HT;
  368. sdata->vif.bss_conf.ht_operation_mode = ht_opmode;
  369. }
  370. return 0;
  371. }
  372. /* frame sending functions */
  373. static void ieee80211_add_ht_ie(struct ieee80211_sub_if_data *sdata,
  374. struct sk_buff *skb, u8 ap_ht_param,
  375. struct ieee80211_supported_band *sband,
  376. struct ieee80211_channel *channel,
  377. enum ieee80211_smps_mode smps)
  378. {
  379. u8 *pos;
  380. u32 flags = channel->flags;
  381. u16 cap;
  382. struct ieee80211_sta_ht_cap ht_cap;
  383. BUILD_BUG_ON(sizeof(ht_cap) != sizeof(sband->ht_cap));
  384. memcpy(&ht_cap, &sband->ht_cap, sizeof(ht_cap));
  385. ieee80211_apply_htcap_overrides(sdata, &ht_cap);
  386. /* determine capability flags */
  387. cap = ht_cap.cap;
  388. switch (ap_ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) {
  389. case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
  390. if (flags & IEEE80211_CHAN_NO_HT40PLUS) {
  391. cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
  392. cap &= ~IEEE80211_HT_CAP_SGI_40;
  393. }
  394. break;
  395. case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
  396. if (flags & IEEE80211_CHAN_NO_HT40MINUS) {
  397. cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
  398. cap &= ~IEEE80211_HT_CAP_SGI_40;
  399. }
  400. break;
  401. }
  402. /*
  403. * If 40 MHz was disabled associate as though we weren't
  404. * capable of 40 MHz -- some broken APs will never fall
  405. * back to trying to transmit in 20 MHz.
  406. */
  407. if (sdata->u.mgd.flags & IEEE80211_STA_DISABLE_40MHZ) {
  408. cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
  409. cap &= ~IEEE80211_HT_CAP_SGI_40;
  410. }
  411. /* set SM PS mode properly */
  412. cap &= ~IEEE80211_HT_CAP_SM_PS;
  413. switch (smps) {
  414. case IEEE80211_SMPS_AUTOMATIC:
  415. case IEEE80211_SMPS_NUM_MODES:
  416. WARN_ON(1);
  417. case IEEE80211_SMPS_OFF:
  418. cap |= WLAN_HT_CAP_SM_PS_DISABLED <<
  419. IEEE80211_HT_CAP_SM_PS_SHIFT;
  420. break;
  421. case IEEE80211_SMPS_STATIC:
  422. cap |= WLAN_HT_CAP_SM_PS_STATIC <<
  423. IEEE80211_HT_CAP_SM_PS_SHIFT;
  424. break;
  425. case IEEE80211_SMPS_DYNAMIC:
  426. cap |= WLAN_HT_CAP_SM_PS_DYNAMIC <<
  427. IEEE80211_HT_CAP_SM_PS_SHIFT;
  428. break;
  429. }
  430. /* reserve and fill IE */
  431. pos = skb_put(skb, sizeof(struct ieee80211_ht_cap) + 2);
  432. ieee80211_ie_build_ht_cap(pos, &ht_cap, cap);
  433. }
  434. static void ieee80211_add_vht_ie(struct ieee80211_sub_if_data *sdata,
  435. struct sk_buff *skb,
  436. struct ieee80211_supported_band *sband,
  437. struct ieee80211_vht_cap *ap_vht_cap)
  438. {
  439. u8 *pos;
  440. u32 cap;
  441. struct ieee80211_sta_vht_cap vht_cap;
  442. BUILD_BUG_ON(sizeof(vht_cap) != sizeof(sband->vht_cap));
  443. memcpy(&vht_cap, &sband->vht_cap, sizeof(vht_cap));
  444. ieee80211_apply_vhtcap_overrides(sdata, &vht_cap);
  445. /* determine capability flags */
  446. cap = vht_cap.cap;
  447. if (sdata->u.mgd.flags & IEEE80211_STA_DISABLE_80P80MHZ) {
  448. cap &= ~IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
  449. cap |= IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
  450. }
  451. if (sdata->u.mgd.flags & IEEE80211_STA_DISABLE_160MHZ) {
  452. cap &= ~IEEE80211_VHT_CAP_SHORT_GI_160;
  453. cap &= ~IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
  454. }
  455. /*
  456. * Some APs apparently get confused if our capabilities are better
  457. * than theirs, so restrict what we advertise in the assoc request.
  458. */
  459. if (!(ap_vht_cap->vht_cap_info &
  460. cpu_to_le32(IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)))
  461. cap &= ~IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE;
  462. /* reserve and fill IE */
  463. pos = skb_put(skb, sizeof(struct ieee80211_vht_cap) + 2);
  464. ieee80211_ie_build_vht_cap(pos, &vht_cap, cap);
  465. }
  466. static void ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata)
  467. {
  468. struct ieee80211_local *local = sdata->local;
  469. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  470. struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
  471. struct sk_buff *skb;
  472. struct ieee80211_mgmt *mgmt;
  473. u8 *pos, qos_info;
  474. size_t offset = 0, noffset;
  475. int i, count, rates_len, supp_rates_len, shift;
  476. u16 capab;
  477. struct ieee80211_supported_band *sband;
  478. struct ieee80211_chanctx_conf *chanctx_conf;
  479. struct ieee80211_channel *chan;
  480. u32 rate_flags, rates = 0;
  481. sdata_assert_lock(sdata);
  482. rcu_read_lock();
  483. chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
  484. if (WARN_ON(!chanctx_conf)) {
  485. rcu_read_unlock();
  486. return;
  487. }
  488. chan = chanctx_conf->def.chan;
  489. rate_flags = ieee80211_chandef_rate_flags(&chanctx_conf->def);
  490. rcu_read_unlock();
  491. sband = local->hw.wiphy->bands[chan->band];
  492. shift = ieee80211_vif_get_shift(&sdata->vif);
  493. if (assoc_data->supp_rates_len) {
  494. /*
  495. * Get all rates supported by the device and the AP as
  496. * some APs don't like getting a superset of their rates
  497. * in the association request (e.g. D-Link DAP 1353 in
  498. * b-only mode)...
  499. */
  500. rates_len = ieee80211_parse_bitrates(&chanctx_conf->def, sband,
  501. assoc_data->supp_rates,
  502. assoc_data->supp_rates_len,
  503. &rates);
  504. } else {
  505. /*
  506. * In case AP not provide any supported rates information
  507. * before association, we send information element(s) with
  508. * all rates that we support.
  509. */
  510. rates_len = 0;
  511. for (i = 0; i < sband->n_bitrates; i++) {
  512. if ((rate_flags & sband->bitrates[i].flags)
  513. != rate_flags)
  514. continue;
  515. rates |= BIT(i);
  516. rates_len++;
  517. }
  518. }
  519. skb = alloc_skb(local->hw.extra_tx_headroom +
  520. sizeof(*mgmt) + /* bit too much but doesn't matter */
  521. 2 + assoc_data->ssid_len + /* SSID */
  522. 4 + rates_len + /* (extended) rates */
  523. 4 + /* power capability */
  524. 2 + 2 * sband->n_channels + /* supported channels */
  525. 2 + sizeof(struct ieee80211_ht_cap) + /* HT */
  526. 2 + sizeof(struct ieee80211_vht_cap) + /* VHT */
  527. assoc_data->ie_len + /* extra IEs */
  528. 9, /* WMM */
  529. GFP_KERNEL);
  530. if (!skb)
  531. return;
  532. skb_reserve(skb, local->hw.extra_tx_headroom);
  533. capab = WLAN_CAPABILITY_ESS;
  534. if (sband->band == IEEE80211_BAND_2GHZ) {
  535. if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE))
  536. capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
  537. if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE))
  538. capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
  539. }
  540. if (assoc_data->capability & WLAN_CAPABILITY_PRIVACY)
  541. capab |= WLAN_CAPABILITY_PRIVACY;
  542. if ((assoc_data->capability & WLAN_CAPABILITY_SPECTRUM_MGMT) &&
  543. (local->hw.flags & IEEE80211_HW_SPECTRUM_MGMT))
  544. capab |= WLAN_CAPABILITY_SPECTRUM_MGMT;
  545. mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
  546. memset(mgmt, 0, 24);
  547. memcpy(mgmt->da, assoc_data->bss->bssid, ETH_ALEN);
  548. memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
  549. memcpy(mgmt->bssid, assoc_data->bss->bssid, ETH_ALEN);
  550. if (!is_zero_ether_addr(assoc_data->prev_bssid)) {
  551. skb_put(skb, 10);
  552. mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  553. IEEE80211_STYPE_REASSOC_REQ);
  554. mgmt->u.reassoc_req.capab_info = cpu_to_le16(capab);
  555. mgmt->u.reassoc_req.listen_interval =
  556. cpu_to_le16(local->hw.conf.listen_interval);
  557. memcpy(mgmt->u.reassoc_req.current_ap, assoc_data->prev_bssid,
  558. ETH_ALEN);
  559. } else {
  560. skb_put(skb, 4);
  561. mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  562. IEEE80211_STYPE_ASSOC_REQ);
  563. mgmt->u.assoc_req.capab_info = cpu_to_le16(capab);
  564. mgmt->u.assoc_req.listen_interval =
  565. cpu_to_le16(local->hw.conf.listen_interval);
  566. }
  567. /* SSID */
  568. pos = skb_put(skb, 2 + assoc_data->ssid_len);
  569. *pos++ = WLAN_EID_SSID;
  570. *pos++ = assoc_data->ssid_len;
  571. memcpy(pos, assoc_data->ssid, assoc_data->ssid_len);
  572. /* add all rates which were marked to be used above */
  573. supp_rates_len = rates_len;
  574. if (supp_rates_len > 8)
  575. supp_rates_len = 8;
  576. pos = skb_put(skb, supp_rates_len + 2);
  577. *pos++ = WLAN_EID_SUPP_RATES;
  578. *pos++ = supp_rates_len;
  579. count = 0;
  580. for (i = 0; i < sband->n_bitrates; i++) {
  581. if (BIT(i) & rates) {
  582. int rate = DIV_ROUND_UP(sband->bitrates[i].bitrate,
  583. 5 * (1 << shift));
  584. *pos++ = (u8) rate;
  585. if (++count == 8)
  586. break;
  587. }
  588. }
  589. if (rates_len > count) {
  590. pos = skb_put(skb, rates_len - count + 2);
  591. *pos++ = WLAN_EID_EXT_SUPP_RATES;
  592. *pos++ = rates_len - count;
  593. for (i++; i < sband->n_bitrates; i++) {
  594. if (BIT(i) & rates) {
  595. int rate;
  596. rate = DIV_ROUND_UP(sband->bitrates[i].bitrate,
  597. 5 * (1 << shift));
  598. *pos++ = (u8) rate;
  599. }
  600. }
  601. }
  602. if (capab & WLAN_CAPABILITY_SPECTRUM_MGMT) {
  603. /* 1. power capabilities */
  604. pos = skb_put(skb, 4);
  605. *pos++ = WLAN_EID_PWR_CAPABILITY;
  606. *pos++ = 2;
  607. *pos++ = 0; /* min tx power */
  608. /* max tx power */
  609. *pos++ = ieee80211_chandef_max_power(&chanctx_conf->def);
  610. /* 2. supported channels */
  611. /* TODO: get this in reg domain format */
  612. pos = skb_put(skb, 2 * sband->n_channels + 2);
  613. *pos++ = WLAN_EID_SUPPORTED_CHANNELS;
  614. *pos++ = 2 * sband->n_channels;
  615. for (i = 0; i < sband->n_channels; i++) {
  616. *pos++ = ieee80211_frequency_to_channel(
  617. sband->channels[i].center_freq);
  618. *pos++ = 1; /* one channel in the subband*/
  619. }
  620. }
  621. /* if present, add any custom IEs that go before HT */
  622. if (assoc_data->ie_len && assoc_data->ie) {
  623. static const u8 before_ht[] = {
  624. WLAN_EID_SSID,
  625. WLAN_EID_SUPP_RATES,
  626. WLAN_EID_EXT_SUPP_RATES,
  627. WLAN_EID_PWR_CAPABILITY,
  628. WLAN_EID_SUPPORTED_CHANNELS,
  629. WLAN_EID_RSN,
  630. WLAN_EID_QOS_CAPA,
  631. WLAN_EID_RRM_ENABLED_CAPABILITIES,
  632. WLAN_EID_MOBILITY_DOMAIN,
  633. WLAN_EID_SUPPORTED_REGULATORY_CLASSES,
  634. };
  635. noffset = ieee80211_ie_split(assoc_data->ie, assoc_data->ie_len,
  636. before_ht, ARRAY_SIZE(before_ht),
  637. offset);
  638. pos = skb_put(skb, noffset - offset);
  639. memcpy(pos, assoc_data->ie + offset, noffset - offset);
  640. offset = noffset;
  641. }
  642. if (WARN_ON_ONCE((ifmgd->flags & IEEE80211_STA_DISABLE_HT) &&
  643. !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)))
  644. ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
  645. if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT))
  646. ieee80211_add_ht_ie(sdata, skb, assoc_data->ap_ht_param,
  647. sband, chan, sdata->smps_mode);
  648. if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
  649. ieee80211_add_vht_ie(sdata, skb, sband,
  650. &assoc_data->ap_vht_cap);
  651. /* if present, add any custom non-vendor IEs that go after HT */
  652. if (assoc_data->ie_len && assoc_data->ie) {
  653. noffset = ieee80211_ie_split_vendor(assoc_data->ie,
  654. assoc_data->ie_len,
  655. offset);
  656. pos = skb_put(skb, noffset - offset);
  657. memcpy(pos, assoc_data->ie + offset, noffset - offset);
  658. offset = noffset;
  659. }
  660. if (assoc_data->wmm) {
  661. if (assoc_data->uapsd) {
  662. qos_info = ifmgd->uapsd_queues;
  663. qos_info |= (ifmgd->uapsd_max_sp_len <<
  664. IEEE80211_WMM_IE_STA_QOSINFO_SP_SHIFT);
  665. } else {
  666. qos_info = 0;
  667. }
  668. pos = skb_put(skb, 9);
  669. *pos++ = WLAN_EID_VENDOR_SPECIFIC;
  670. *pos++ = 7; /* len */
  671. *pos++ = 0x00; /* Microsoft OUI 00:50:F2 */
  672. *pos++ = 0x50;
  673. *pos++ = 0xf2;
  674. *pos++ = 2; /* WME */
  675. *pos++ = 0; /* WME info */
  676. *pos++ = 1; /* WME ver */
  677. *pos++ = qos_info;
  678. }
  679. /* add any remaining custom (i.e. vendor specific here) IEs */
  680. if (assoc_data->ie_len && assoc_data->ie) {
  681. noffset = assoc_data->ie_len;
  682. pos = skb_put(skb, noffset - offset);
  683. memcpy(pos, assoc_data->ie + offset, noffset - offset);
  684. }
  685. drv_mgd_prepare_tx(local, sdata);
  686. IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
  687. if (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS)
  688. IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS |
  689. IEEE80211_TX_INTFL_MLME_CONN_TX;
  690. ieee80211_tx_skb(sdata, skb);
  691. }
  692. void ieee80211_send_pspoll(struct ieee80211_local *local,
  693. struct ieee80211_sub_if_data *sdata)
  694. {
  695. struct ieee80211_pspoll *pspoll;
  696. struct sk_buff *skb;
  697. skb = ieee80211_pspoll_get(&local->hw, &sdata->vif);
  698. if (!skb)
  699. return;
  700. pspoll = (struct ieee80211_pspoll *) skb->data;
  701. pspoll->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
  702. IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
  703. ieee80211_tx_skb(sdata, skb);
  704. }
  705. void ieee80211_send_nullfunc(struct ieee80211_local *local,
  706. struct ieee80211_sub_if_data *sdata,
  707. int powersave)
  708. {
  709. struct sk_buff *skb;
  710. struct ieee80211_hdr_3addr *nullfunc;
  711. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  712. skb = ieee80211_nullfunc_get(&local->hw, &sdata->vif);
  713. if (!skb)
  714. return;
  715. nullfunc = (struct ieee80211_hdr_3addr *) skb->data;
  716. if (powersave)
  717. nullfunc->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
  718. IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT |
  719. IEEE80211_TX_INTFL_OFFCHAN_TX_OK;
  720. if (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS)
  721. IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS;
  722. if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL)
  723. IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_USE_MINRATE;
  724. ieee80211_tx_skb(sdata, skb);
  725. }
  726. static void ieee80211_send_4addr_nullfunc(struct ieee80211_local *local,
  727. struct ieee80211_sub_if_data *sdata)
  728. {
  729. struct sk_buff *skb;
  730. struct ieee80211_hdr *nullfunc;
  731. __le16 fc;
  732. if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
  733. return;
  734. skb = dev_alloc_skb(local->hw.extra_tx_headroom + 30);
  735. if (!skb)
  736. return;
  737. skb_reserve(skb, local->hw.extra_tx_headroom);
  738. nullfunc = (struct ieee80211_hdr *) skb_put(skb, 30);
  739. memset(nullfunc, 0, 30);
  740. fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC |
  741. IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS);
  742. nullfunc->frame_control = fc;
  743. memcpy(nullfunc->addr1, sdata->u.mgd.bssid, ETH_ALEN);
  744. memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
  745. memcpy(nullfunc->addr3, sdata->u.mgd.bssid, ETH_ALEN);
  746. memcpy(nullfunc->addr4, sdata->vif.addr, ETH_ALEN);
  747. IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
  748. ieee80211_tx_skb(sdata, skb);
  749. }
  750. /* spectrum management related things */
  751. static void ieee80211_chswitch_work(struct work_struct *work)
  752. {
  753. struct ieee80211_sub_if_data *sdata =
  754. container_of(work, struct ieee80211_sub_if_data, u.mgd.chswitch_work);
  755. struct ieee80211_local *local = sdata->local;
  756. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  757. u32 changed = 0;
  758. int ret;
  759. if (!ieee80211_sdata_running(sdata))
  760. return;
  761. sdata_lock(sdata);
  762. if (!ifmgd->associated)
  763. goto out;
  764. ret = ieee80211_vif_change_channel(sdata, &local->csa_chandef,
  765. &changed);
  766. if (ret) {
  767. sdata_info(sdata,
  768. "vif channel switch failed, disconnecting\n");
  769. ieee80211_queue_work(&sdata->local->hw,
  770. &ifmgd->csa_connection_drop_work);
  771. goto out;
  772. }
  773. if (!local->use_chanctx) {
  774. local->_oper_chandef = local->csa_chandef;
  775. /* Call "hw_config" only if doing sw channel switch.
  776. * Otherwise update the channel directly
  777. */
  778. if (!local->ops->channel_switch)
  779. ieee80211_hw_config(local, 0);
  780. else
  781. local->hw.conf.chandef = local->_oper_chandef;
  782. }
  783. /* XXX: shouldn't really modify cfg80211-owned data! */
  784. ifmgd->associated->channel = local->csa_chandef.chan;
  785. /* XXX: wait for a beacon first? */
  786. ieee80211_wake_queues_by_reason(&local->hw,
  787. IEEE80211_MAX_QUEUE_MAP,
  788. IEEE80211_QUEUE_STOP_REASON_CSA);
  789. ieee80211_bss_info_change_notify(sdata, changed);
  790. out:
  791. sdata->vif.csa_active = false;
  792. ifmgd->flags &= ~IEEE80211_STA_CSA_RECEIVED;
  793. sdata_unlock(sdata);
  794. }
  795. void ieee80211_chswitch_done(struct ieee80211_vif *vif, bool success)
  796. {
  797. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  798. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  799. trace_api_chswitch_done(sdata, success);
  800. if (!success) {
  801. sdata_info(sdata,
  802. "driver channel switch failed, disconnecting\n");
  803. ieee80211_queue_work(&sdata->local->hw,
  804. &ifmgd->csa_connection_drop_work);
  805. } else {
  806. ieee80211_queue_work(&sdata->local->hw, &ifmgd->chswitch_work);
  807. }
  808. }
  809. EXPORT_SYMBOL(ieee80211_chswitch_done);
  810. static void ieee80211_chswitch_timer(unsigned long data)
  811. {
  812. struct ieee80211_sub_if_data *sdata =
  813. (struct ieee80211_sub_if_data *) data;
  814. ieee80211_queue_work(&sdata->local->hw, &sdata->u.mgd.chswitch_work);
  815. }
  816. static void
  817. ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data *sdata,
  818. u64 timestamp, struct ieee802_11_elems *elems,
  819. bool beacon)
  820. {
  821. struct ieee80211_local *local = sdata->local;
  822. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  823. struct cfg80211_bss *cbss = ifmgd->associated;
  824. struct ieee80211_chanctx *chanctx;
  825. enum ieee80211_band current_band;
  826. u8 count;
  827. u8 mode;
  828. struct cfg80211_chan_def new_chandef = {};
  829. int res;
  830. sdata_assert_lock(sdata);
  831. if (!cbss)
  832. return;
  833. if (local->scanning)
  834. return;
  835. /* disregard subsequent announcements if we are already processing */
  836. if (ifmgd->flags & IEEE80211_STA_CSA_RECEIVED)
  837. return;
  838. current_band = cbss->channel->band;
  839. res = ieee80211_parse_ch_switch_ie(sdata, elems, beacon, current_band,
  840. ifmgd->flags,
  841. ifmgd->associated->bssid, &count,
  842. &mode, &new_chandef);
  843. if (res < 0)
  844. ieee80211_queue_work(&local->hw,
  845. &ifmgd->csa_connection_drop_work);
  846. if (res)
  847. return;
  848. if (!cfg80211_chandef_usable(local->hw.wiphy, &new_chandef,
  849. IEEE80211_CHAN_DISABLED)) {
  850. sdata_info(sdata,
  851. "AP %pM switches to unsupported channel (%d MHz, width:%d, CF1/2: %d/%d MHz), disconnecting\n",
  852. ifmgd->associated->bssid,
  853. new_chandef.chan->center_freq,
  854. new_chandef.width, new_chandef.center_freq1,
  855. new_chandef.center_freq2);
  856. ieee80211_queue_work(&local->hw,
  857. &ifmgd->csa_connection_drop_work);
  858. return;
  859. }
  860. ifmgd->flags |= IEEE80211_STA_CSA_RECEIVED;
  861. sdata->vif.csa_active = true;
  862. mutex_lock(&local->chanctx_mtx);
  863. if (local->use_chanctx) {
  864. u32 num_chanctx = 0;
  865. list_for_each_entry(chanctx, &local->chanctx_list, list)
  866. num_chanctx++;
  867. if (num_chanctx > 1 ||
  868. !(local->hw.flags & IEEE80211_HW_CHANCTX_STA_CSA)) {
  869. sdata_info(sdata,
  870. "not handling chan-switch with channel contexts\n");
  871. ieee80211_queue_work(&local->hw,
  872. &ifmgd->csa_connection_drop_work);
  873. mutex_unlock(&local->chanctx_mtx);
  874. return;
  875. }
  876. }
  877. if (WARN_ON(!rcu_access_pointer(sdata->vif.chanctx_conf))) {
  878. ieee80211_queue_work(&local->hw,
  879. &ifmgd->csa_connection_drop_work);
  880. mutex_unlock(&local->chanctx_mtx);
  881. return;
  882. }
  883. chanctx = container_of(rcu_access_pointer(sdata->vif.chanctx_conf),
  884. struct ieee80211_chanctx, conf);
  885. if (chanctx->refcount > 1) {
  886. sdata_info(sdata,
  887. "channel switch with multiple interfaces on the same channel, disconnecting\n");
  888. ieee80211_queue_work(&local->hw,
  889. &ifmgd->csa_connection_drop_work);
  890. mutex_unlock(&local->chanctx_mtx);
  891. return;
  892. }
  893. mutex_unlock(&local->chanctx_mtx);
  894. local->csa_chandef = new_chandef;
  895. if (mode)
  896. ieee80211_stop_queues_by_reason(&local->hw,
  897. IEEE80211_MAX_QUEUE_MAP,
  898. IEEE80211_QUEUE_STOP_REASON_CSA);
  899. if (local->ops->channel_switch) {
  900. /* use driver's channel switch callback */
  901. struct ieee80211_channel_switch ch_switch = {
  902. .timestamp = timestamp,
  903. .block_tx = mode,
  904. .chandef = new_chandef,
  905. .count = count,
  906. };
  907. drv_channel_switch(local, &ch_switch);
  908. return;
  909. }
  910. /* channel switch handled in software */
  911. if (count <= 1)
  912. ieee80211_queue_work(&local->hw, &ifmgd->chswitch_work);
  913. else
  914. mod_timer(&ifmgd->chswitch_timer,
  915. TU_TO_EXP_TIME(count * cbss->beacon_interval));
  916. }
  917. static u32 ieee80211_handle_pwr_constr(struct ieee80211_sub_if_data *sdata,
  918. struct ieee80211_channel *channel,
  919. const u8 *country_ie, u8 country_ie_len,
  920. const u8 *pwr_constr_elem)
  921. {
  922. struct ieee80211_country_ie_triplet *triplet;
  923. int chan = ieee80211_frequency_to_channel(channel->center_freq);
  924. int i, chan_pwr, chan_increment, new_ap_level;
  925. bool have_chan_pwr = false;
  926. /* Invalid IE */
  927. if (country_ie_len % 2 || country_ie_len < IEEE80211_COUNTRY_IE_MIN_LEN)
  928. return 0;
  929. triplet = (void *)(country_ie + 3);
  930. country_ie_len -= 3;
  931. switch (channel->band) {
  932. default:
  933. WARN_ON_ONCE(1);
  934. /* fall through */
  935. case IEEE80211_BAND_2GHZ:
  936. case IEEE80211_BAND_60GHZ:
  937. chan_increment = 1;
  938. break;
  939. case IEEE80211_BAND_5GHZ:
  940. chan_increment = 4;
  941. break;
  942. }
  943. /* find channel */
  944. while (country_ie_len >= 3) {
  945. u8 first_channel = triplet->chans.first_channel;
  946. if (first_channel >= IEEE80211_COUNTRY_EXTENSION_ID)
  947. goto next;
  948. for (i = 0; i < triplet->chans.num_channels; i++) {
  949. if (first_channel + i * chan_increment == chan) {
  950. have_chan_pwr = true;
  951. chan_pwr = triplet->chans.max_power;
  952. break;
  953. }
  954. }
  955. if (have_chan_pwr)
  956. break;
  957. next:
  958. triplet++;
  959. country_ie_len -= 3;
  960. }
  961. if (!have_chan_pwr)
  962. return 0;
  963. new_ap_level = max_t(int, 0, chan_pwr - *pwr_constr_elem);
  964. if (sdata->ap_power_level == new_ap_level)
  965. return 0;
  966. sdata_info(sdata,
  967. "Limiting TX power to %d (%d - %d) dBm as advertised by %pM\n",
  968. new_ap_level, chan_pwr, *pwr_constr_elem,
  969. sdata->u.mgd.bssid);
  970. sdata->ap_power_level = new_ap_level;
  971. if (__ieee80211_recalc_txpower(sdata))
  972. return BSS_CHANGED_TXPOWER;
  973. return 0;
  974. }
  975. /* powersave */
  976. static void ieee80211_enable_ps(struct ieee80211_local *local,
  977. struct ieee80211_sub_if_data *sdata)
  978. {
  979. struct ieee80211_conf *conf = &local->hw.conf;
  980. /*
  981. * If we are scanning right now then the parameters will
  982. * take effect when scan finishes.
  983. */
  984. if (local->scanning)
  985. return;
  986. if (conf->dynamic_ps_timeout > 0 &&
  987. !(local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)) {
  988. mod_timer(&local->dynamic_ps_timer, jiffies +
  989. msecs_to_jiffies(conf->dynamic_ps_timeout));
  990. } else {
  991. if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
  992. ieee80211_send_nullfunc(local, sdata, 1);
  993. if ((local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) &&
  994. (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS))
  995. return;
  996. conf->flags |= IEEE80211_CONF_PS;
  997. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
  998. }
  999. }
  1000. static void ieee80211_change_ps(struct ieee80211_local *local)
  1001. {
  1002. struct ieee80211_conf *conf = &local->hw.conf;
  1003. if (local->ps_sdata) {
  1004. ieee80211_enable_ps(local, local->ps_sdata);
  1005. } else if (conf->flags & IEEE80211_CONF_PS) {
  1006. conf->flags &= ~IEEE80211_CONF_PS;
  1007. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
  1008. del_timer_sync(&local->dynamic_ps_timer);
  1009. cancel_work_sync(&local->dynamic_ps_enable_work);
  1010. }
  1011. }
  1012. static bool ieee80211_powersave_allowed(struct ieee80211_sub_if_data *sdata)
  1013. {
  1014. struct ieee80211_if_managed *mgd = &sdata->u.mgd;
  1015. struct sta_info *sta = NULL;
  1016. bool authorized = false;
  1017. if (!mgd->powersave)
  1018. return false;
  1019. if (mgd->broken_ap)
  1020. return false;
  1021. if (!mgd->associated)
  1022. return false;
  1023. if (mgd->flags & IEEE80211_STA_CONNECTION_POLL)
  1024. return false;
  1025. if (!mgd->have_beacon)
  1026. return false;
  1027. rcu_read_lock();
  1028. sta = sta_info_get(sdata, mgd->bssid);
  1029. if (sta)
  1030. authorized = test_sta_flag(sta, WLAN_STA_AUTHORIZED);
  1031. rcu_read_unlock();
  1032. return authorized;
  1033. }
  1034. /* need to hold RTNL or interface lock */
  1035. void ieee80211_recalc_ps(struct ieee80211_local *local, s32 latency)
  1036. {
  1037. struct ieee80211_sub_if_data *sdata, *found = NULL;
  1038. int count = 0;
  1039. int timeout;
  1040. if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS)) {
  1041. local->ps_sdata = NULL;
  1042. return;
  1043. }
  1044. list_for_each_entry(sdata, &local->interfaces, list) {
  1045. if (!ieee80211_sdata_running(sdata))
  1046. continue;
  1047. if (sdata->vif.type == NL80211_IFTYPE_AP) {
  1048. /* If an AP vif is found, then disable PS
  1049. * by setting the count to zero thereby setting
  1050. * ps_sdata to NULL.
  1051. */
  1052. count = 0;
  1053. break;
  1054. }
  1055. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  1056. continue;
  1057. found = sdata;
  1058. count++;
  1059. }
  1060. if (count == 1 && ieee80211_powersave_allowed(found)) {
  1061. s32 beaconint_us;
  1062. if (latency < 0)
  1063. latency = pm_qos_request(PM_QOS_NETWORK_LATENCY);
  1064. beaconint_us = ieee80211_tu_to_usec(
  1065. found->vif.bss_conf.beacon_int);
  1066. timeout = local->dynamic_ps_forced_timeout;
  1067. if (timeout < 0) {
  1068. /*
  1069. * Go to full PSM if the user configures a very low
  1070. * latency requirement.
  1071. * The 2000 second value is there for compatibility
  1072. * until the PM_QOS_NETWORK_LATENCY is configured
  1073. * with real values.
  1074. */
  1075. if (latency > (1900 * USEC_PER_MSEC) &&
  1076. latency != (2000 * USEC_PER_SEC))
  1077. timeout = 0;
  1078. else
  1079. timeout = 100;
  1080. }
  1081. local->hw.conf.dynamic_ps_timeout = timeout;
  1082. if (beaconint_us > latency) {
  1083. local->ps_sdata = NULL;
  1084. } else {
  1085. int maxslp = 1;
  1086. u8 dtimper = found->u.mgd.dtim_period;
  1087. /* If the TIM IE is invalid, pretend the value is 1 */
  1088. if (!dtimper)
  1089. dtimper = 1;
  1090. else if (dtimper > 1)
  1091. maxslp = min_t(int, dtimper,
  1092. latency / beaconint_us);
  1093. local->hw.conf.max_sleep_period = maxslp;
  1094. local->hw.conf.ps_dtim_period = dtimper;
  1095. local->ps_sdata = found;
  1096. }
  1097. } else {
  1098. local->ps_sdata = NULL;
  1099. }
  1100. ieee80211_change_ps(local);
  1101. }
  1102. void ieee80211_recalc_ps_vif(struct ieee80211_sub_if_data *sdata)
  1103. {
  1104. bool ps_allowed = ieee80211_powersave_allowed(sdata);
  1105. if (sdata->vif.bss_conf.ps != ps_allowed) {
  1106. sdata->vif.bss_conf.ps = ps_allowed;
  1107. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_PS);
  1108. }
  1109. }
  1110. void ieee80211_dynamic_ps_disable_work(struct work_struct *work)
  1111. {
  1112. struct ieee80211_local *local =
  1113. container_of(work, struct ieee80211_local,
  1114. dynamic_ps_disable_work);
  1115. if (local->hw.conf.flags & IEEE80211_CONF_PS) {
  1116. local->hw.conf.flags &= ~IEEE80211_CONF_PS;
  1117. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
  1118. }
  1119. ieee80211_wake_queues_by_reason(&local->hw,
  1120. IEEE80211_MAX_QUEUE_MAP,
  1121. IEEE80211_QUEUE_STOP_REASON_PS);
  1122. }
  1123. void ieee80211_dynamic_ps_enable_work(struct work_struct *work)
  1124. {
  1125. struct ieee80211_local *local =
  1126. container_of(work, struct ieee80211_local,
  1127. dynamic_ps_enable_work);
  1128. struct ieee80211_sub_if_data *sdata = local->ps_sdata;
  1129. struct ieee80211_if_managed *ifmgd;
  1130. unsigned long flags;
  1131. int q;
  1132. /* can only happen when PS was just disabled anyway */
  1133. if (!sdata)
  1134. return;
  1135. ifmgd = &sdata->u.mgd;
  1136. if (local->hw.conf.flags & IEEE80211_CONF_PS)
  1137. return;
  1138. if (local->hw.conf.dynamic_ps_timeout > 0) {
  1139. /* don't enter PS if TX frames are pending */
  1140. if (drv_tx_frames_pending(local)) {
  1141. mod_timer(&local->dynamic_ps_timer, jiffies +
  1142. msecs_to_jiffies(
  1143. local->hw.conf.dynamic_ps_timeout));
  1144. return;
  1145. }
  1146. /*
  1147. * transmission can be stopped by others which leads to
  1148. * dynamic_ps_timer expiry. Postpone the ps timer if it
  1149. * is not the actual idle state.
  1150. */
  1151. spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
  1152. for (q = 0; q < local->hw.queues; q++) {
  1153. if (local->queue_stop_reasons[q]) {
  1154. spin_unlock_irqrestore(&local->queue_stop_reason_lock,
  1155. flags);
  1156. mod_timer(&local->dynamic_ps_timer, jiffies +
  1157. msecs_to_jiffies(
  1158. local->hw.conf.dynamic_ps_timeout));
  1159. return;
  1160. }
  1161. }
  1162. spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
  1163. }
  1164. if ((local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) &&
  1165. !(ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) {
  1166. if (drv_tx_frames_pending(local)) {
  1167. mod_timer(&local->dynamic_ps_timer, jiffies +
  1168. msecs_to_jiffies(
  1169. local->hw.conf.dynamic_ps_timeout));
  1170. } else {
  1171. ieee80211_send_nullfunc(local, sdata, 1);
  1172. /* Flush to get the tx status of nullfunc frame */
  1173. ieee80211_flush_queues(local, sdata);
  1174. }
  1175. }
  1176. if (!((local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS) &&
  1177. (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)) ||
  1178. (ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) {
  1179. ifmgd->flags &= ~IEEE80211_STA_NULLFUNC_ACKED;
  1180. local->hw.conf.flags |= IEEE80211_CONF_PS;
  1181. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
  1182. }
  1183. }
  1184. void ieee80211_dynamic_ps_timer(unsigned long data)
  1185. {
  1186. struct ieee80211_local *local = (void *) data;
  1187. if (local->quiescing || local->suspended)
  1188. return;
  1189. ieee80211_queue_work(&local->hw, &local->dynamic_ps_enable_work);
  1190. }
  1191. void ieee80211_dfs_cac_timer_work(struct work_struct *work)
  1192. {
  1193. struct delayed_work *delayed_work =
  1194. container_of(work, struct delayed_work, work);
  1195. struct ieee80211_sub_if_data *sdata =
  1196. container_of(delayed_work, struct ieee80211_sub_if_data,
  1197. dfs_cac_timer_work);
  1198. ieee80211_vif_release_channel(sdata);
  1199. cfg80211_cac_event(sdata->dev, NL80211_RADAR_CAC_FINISHED, GFP_KERNEL);
  1200. }
  1201. /* MLME */
  1202. static bool ieee80211_sta_wmm_params(struct ieee80211_local *local,
  1203. struct ieee80211_sub_if_data *sdata,
  1204. const u8 *wmm_param, size_t wmm_param_len)
  1205. {
  1206. struct ieee80211_tx_queue_params params;
  1207. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1208. size_t left;
  1209. int count;
  1210. const u8 *pos;
  1211. u8 uapsd_queues = 0;
  1212. if (!local->ops->conf_tx)
  1213. return false;
  1214. if (local->hw.queues < IEEE80211_NUM_ACS)
  1215. return false;
  1216. if (!wmm_param)
  1217. return false;
  1218. if (wmm_param_len < 8 || wmm_param[5] /* version */ != 1)
  1219. return false;
  1220. if (ifmgd->flags & IEEE80211_STA_UAPSD_ENABLED)
  1221. uapsd_queues = ifmgd->uapsd_queues;
  1222. count = wmm_param[6] & 0x0f;
  1223. if (count == ifmgd->wmm_last_param_set)
  1224. return false;
  1225. ifmgd->wmm_last_param_set = count;
  1226. pos = wmm_param + 8;
  1227. left = wmm_param_len - 8;
  1228. memset(&params, 0, sizeof(params));
  1229. sdata->wmm_acm = 0;
  1230. for (; left >= 4; left -= 4, pos += 4) {
  1231. int aci = (pos[0] >> 5) & 0x03;
  1232. int acm = (pos[0] >> 4) & 0x01;
  1233. bool uapsd = false;
  1234. int queue;
  1235. switch (aci) {
  1236. case 1: /* AC_BK */
  1237. queue = 3;
  1238. if (acm)
  1239. sdata->wmm_acm |= BIT(1) | BIT(2); /* BK/- */
  1240. if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
  1241. uapsd = true;
  1242. break;
  1243. case 2: /* AC_VI */
  1244. queue = 1;
  1245. if (acm)
  1246. sdata->wmm_acm |= BIT(4) | BIT(5); /* CL/VI */
  1247. if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
  1248. uapsd = true;
  1249. break;
  1250. case 3: /* AC_VO */
  1251. queue = 0;
  1252. if (acm)
  1253. sdata->wmm_acm |= BIT(6) | BIT(7); /* VO/NC */
  1254. if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
  1255. uapsd = true;
  1256. break;
  1257. case 0: /* AC_BE */
  1258. default:
  1259. queue = 2;
  1260. if (acm)
  1261. sdata->wmm_acm |= BIT(0) | BIT(3); /* BE/EE */
  1262. if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
  1263. uapsd = true;
  1264. break;
  1265. }
  1266. params.aifs = pos[0] & 0x0f;
  1267. params.cw_max = ecw2cw((pos[1] & 0xf0) >> 4);
  1268. params.cw_min = ecw2cw(pos[1] & 0x0f);
  1269. params.txop = get_unaligned_le16(pos + 2);
  1270. params.acm = acm;
  1271. params.uapsd = uapsd;
  1272. mlme_dbg(sdata,
  1273. "WMM queue=%d aci=%d acm=%d aifs=%d cWmin=%d cWmax=%d txop=%d uapsd=%d\n",
  1274. queue, aci, acm,
  1275. params.aifs, params.cw_min, params.cw_max,
  1276. params.txop, params.uapsd);
  1277. sdata->tx_conf[queue] = params;
  1278. if (drv_conf_tx(local, sdata, queue, &params))
  1279. sdata_err(sdata,
  1280. "failed to set TX queue parameters for queue %d\n",
  1281. queue);
  1282. }
  1283. /* enable WMM or activate new settings */
  1284. sdata->vif.bss_conf.qos = true;
  1285. return true;
  1286. }
  1287. static void __ieee80211_stop_poll(struct ieee80211_sub_if_data *sdata)
  1288. {
  1289. lockdep_assert_held(&sdata->local->mtx);
  1290. sdata->u.mgd.flags &= ~IEEE80211_STA_CONNECTION_POLL;
  1291. ieee80211_run_deferred_scan(sdata->local);
  1292. }
  1293. static void ieee80211_stop_poll(struct ieee80211_sub_if_data *sdata)
  1294. {
  1295. mutex_lock(&sdata->local->mtx);
  1296. __ieee80211_stop_poll(sdata);
  1297. mutex_unlock(&sdata->local->mtx);
  1298. }
  1299. static u32 ieee80211_handle_bss_capability(struct ieee80211_sub_if_data *sdata,
  1300. u16 capab, bool erp_valid, u8 erp)
  1301. {
  1302. struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
  1303. u32 changed = 0;
  1304. bool use_protection;
  1305. bool use_short_preamble;
  1306. bool use_short_slot;
  1307. if (erp_valid) {
  1308. use_protection = (erp & WLAN_ERP_USE_PROTECTION) != 0;
  1309. use_short_preamble = (erp & WLAN_ERP_BARKER_PREAMBLE) == 0;
  1310. } else {
  1311. use_protection = false;
  1312. use_short_preamble = !!(capab & WLAN_CAPABILITY_SHORT_PREAMBLE);
  1313. }
  1314. use_short_slot = !!(capab & WLAN_CAPABILITY_SHORT_SLOT_TIME);
  1315. if (ieee80211_get_sdata_band(sdata) == IEEE80211_BAND_5GHZ)
  1316. use_short_slot = true;
  1317. if (use_protection != bss_conf->use_cts_prot) {
  1318. bss_conf->use_cts_prot = use_protection;
  1319. changed |= BSS_CHANGED_ERP_CTS_PROT;
  1320. }
  1321. if (use_short_preamble != bss_conf->use_short_preamble) {
  1322. bss_conf->use_short_preamble = use_short_preamble;
  1323. changed |= BSS_CHANGED_ERP_PREAMBLE;
  1324. }
  1325. if (use_short_slot != bss_conf->use_short_slot) {
  1326. bss_conf->use_short_slot = use_short_slot;
  1327. changed |= BSS_CHANGED_ERP_SLOT;
  1328. }
  1329. return changed;
  1330. }
  1331. static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata,
  1332. struct cfg80211_bss *cbss,
  1333. u32 bss_info_changed)
  1334. {
  1335. struct ieee80211_bss *bss = (void *)cbss->priv;
  1336. struct ieee80211_local *local = sdata->local;
  1337. struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
  1338. bss_info_changed |= BSS_CHANGED_ASSOC;
  1339. bss_info_changed |= ieee80211_handle_bss_capability(sdata,
  1340. bss_conf->assoc_capability, bss->has_erp_value, bss->erp_value);
  1341. sdata->u.mgd.beacon_timeout = usecs_to_jiffies(ieee80211_tu_to_usec(
  1342. beacon_loss_count * bss_conf->beacon_int));
  1343. sdata->u.mgd.associated = cbss;
  1344. memcpy(sdata->u.mgd.bssid, cbss->bssid, ETH_ALEN);
  1345. sdata->u.mgd.flags |= IEEE80211_STA_RESET_SIGNAL_AVE;
  1346. if (sdata->vif.p2p) {
  1347. const struct cfg80211_bss_ies *ies;
  1348. rcu_read_lock();
  1349. ies = rcu_dereference(cbss->ies);
  1350. if (ies) {
  1351. int ret;
  1352. ret = cfg80211_get_p2p_attr(
  1353. ies->data, ies->len,
  1354. IEEE80211_P2P_ATTR_ABSENCE_NOTICE,
  1355. (u8 *) &bss_conf->p2p_noa_attr,
  1356. sizeof(bss_conf->p2p_noa_attr));
  1357. if (ret >= 2) {
  1358. sdata->u.mgd.p2p_noa_index =
  1359. bss_conf->p2p_noa_attr.index;
  1360. bss_info_changed |= BSS_CHANGED_P2P_PS;
  1361. }
  1362. }
  1363. rcu_read_unlock();
  1364. }
  1365. /* just to be sure */
  1366. ieee80211_stop_poll(sdata);
  1367. ieee80211_led_assoc(local, 1);
  1368. if (sdata->u.mgd.have_beacon) {
  1369. /*
  1370. * If the AP is buggy we may get here with no DTIM period
  1371. * known, so assume it's 1 which is the only safe assumption
  1372. * in that case, although if the TIM IE is broken powersave
  1373. * probably just won't work at all.
  1374. */
  1375. bss_conf->dtim_period = sdata->u.mgd.dtim_period ?: 1;
  1376. bss_conf->beacon_rate = bss->beacon_rate;
  1377. bss_info_changed |= BSS_CHANGED_BEACON_INFO;
  1378. } else {
  1379. bss_conf->beacon_rate = NULL;
  1380. bss_conf->dtim_period = 0;
  1381. }
  1382. bss_conf->assoc = 1;
  1383. /* Tell the driver to monitor connection quality (if supported) */
  1384. if (sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI &&
  1385. bss_conf->cqm_rssi_thold)
  1386. bss_info_changed |= BSS_CHANGED_CQM;
  1387. /* Enable ARP filtering */
  1388. if (bss_conf->arp_addr_cnt)
  1389. bss_info_changed |= BSS_CHANGED_ARP_FILTER;
  1390. ieee80211_bss_info_change_notify(sdata, bss_info_changed);
  1391. mutex_lock(&local->iflist_mtx);
  1392. ieee80211_recalc_ps(local, -1);
  1393. mutex_unlock(&local->iflist_mtx);
  1394. ieee80211_recalc_smps(sdata);
  1395. ieee80211_recalc_ps_vif(sdata);
  1396. netif_carrier_on(sdata->dev);
  1397. }
  1398. static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata,
  1399. u16 stype, u16 reason, bool tx,
  1400. u8 *frame_buf)
  1401. {
  1402. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1403. struct ieee80211_local *local = sdata->local;
  1404. u32 changed = 0;
  1405. sdata_assert_lock(sdata);
  1406. if (WARN_ON_ONCE(tx && !frame_buf))
  1407. return;
  1408. if (WARN_ON(!ifmgd->associated))
  1409. return;
  1410. ieee80211_stop_poll(sdata);
  1411. ifmgd->associated = NULL;
  1412. netif_carrier_off(sdata->dev);
  1413. /*
  1414. * if we want to get out of ps before disassoc (why?) we have
  1415. * to do it before sending disassoc, as otherwise the null-packet
  1416. * won't be valid.
  1417. */
  1418. if (local->hw.conf.flags & IEEE80211_CONF_PS) {
  1419. local->hw.conf.flags &= ~IEEE80211_CONF_PS;
  1420. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
  1421. }
  1422. local->ps_sdata = NULL;
  1423. /* disable per-vif ps */
  1424. ieee80211_recalc_ps_vif(sdata);
  1425. /* flush out any pending frame (e.g. DELBA) before deauth/disassoc */
  1426. if (tx)
  1427. ieee80211_flush_queues(local, sdata);
  1428. /* deauthenticate/disassociate now */
  1429. if (tx || frame_buf)
  1430. ieee80211_send_deauth_disassoc(sdata, ifmgd->bssid, stype,
  1431. reason, tx, frame_buf);
  1432. /* flush out frame */
  1433. if (tx)
  1434. ieee80211_flush_queues(local, sdata);
  1435. /* clear bssid only after building the needed mgmt frames */
  1436. memset(ifmgd->bssid, 0, ETH_ALEN);
  1437. /* remove AP and TDLS peers */
  1438. sta_info_flush_defer(sdata);
  1439. /* finally reset all BSS / config parameters */
  1440. changed |= ieee80211_reset_erp_info(sdata);
  1441. ieee80211_led_assoc(local, 0);
  1442. changed |= BSS_CHANGED_ASSOC;
  1443. sdata->vif.bss_conf.assoc = false;
  1444. ifmgd->p2p_noa_index = -1;
  1445. memset(&sdata->vif.bss_conf.p2p_noa_attr, 0,
  1446. sizeof(sdata->vif.bss_conf.p2p_noa_attr));
  1447. /* on the next assoc, re-program HT/VHT parameters */
  1448. memset(&ifmgd->ht_capa, 0, sizeof(ifmgd->ht_capa));
  1449. memset(&ifmgd->ht_capa_mask, 0, sizeof(ifmgd->ht_capa_mask));
  1450. memset(&ifmgd->vht_capa, 0, sizeof(ifmgd->vht_capa));
  1451. memset(&ifmgd->vht_capa_mask, 0, sizeof(ifmgd->vht_capa_mask));
  1452. sdata->ap_power_level = IEEE80211_UNSET_POWER_LEVEL;
  1453. del_timer_sync(&local->dynamic_ps_timer);
  1454. cancel_work_sync(&local->dynamic_ps_enable_work);
  1455. /* Disable ARP filtering */
  1456. if (sdata->vif.bss_conf.arp_addr_cnt)
  1457. changed |= BSS_CHANGED_ARP_FILTER;
  1458. sdata->vif.bss_conf.qos = false;
  1459. changed |= BSS_CHANGED_QOS;
  1460. /* The BSSID (not really interesting) and HT changed */
  1461. changed |= BSS_CHANGED_BSSID | BSS_CHANGED_HT;
  1462. ieee80211_bss_info_change_notify(sdata, changed);
  1463. /* disassociated - set to defaults now */
  1464. ieee80211_set_wmm_default(sdata, false);
  1465. del_timer_sync(&sdata->u.mgd.conn_mon_timer);
  1466. del_timer_sync(&sdata->u.mgd.bcn_mon_timer);
  1467. del_timer_sync(&sdata->u.mgd.timer);
  1468. del_timer_sync(&sdata->u.mgd.chswitch_timer);
  1469. sdata->vif.bss_conf.dtim_period = 0;
  1470. sdata->vif.bss_conf.beacon_rate = NULL;
  1471. ifmgd->have_beacon = false;
  1472. ifmgd->flags = 0;
  1473. ieee80211_vif_release_channel(sdata);
  1474. }
  1475. void ieee80211_sta_rx_notify(struct ieee80211_sub_if_data *sdata,
  1476. struct ieee80211_hdr *hdr)
  1477. {
  1478. /*
  1479. * We can postpone the mgd.timer whenever receiving unicast frames
  1480. * from AP because we know that the connection is working both ways
  1481. * at that time. But multicast frames (and hence also beacons) must
  1482. * be ignored here, because we need to trigger the timer during
  1483. * data idle periods for sending the periodic probe request to the
  1484. * AP we're connected to.
  1485. */
  1486. if (is_multicast_ether_addr(hdr->addr1))
  1487. return;
  1488. ieee80211_sta_reset_conn_monitor(sdata);
  1489. }
  1490. static void ieee80211_reset_ap_probe(struct ieee80211_sub_if_data *sdata)
  1491. {
  1492. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1493. struct ieee80211_local *local = sdata->local;
  1494. mutex_lock(&local->mtx);
  1495. if (!(ifmgd->flags & IEEE80211_STA_CONNECTION_POLL))
  1496. goto out;
  1497. __ieee80211_stop_poll(sdata);
  1498. mutex_lock(&local->iflist_mtx);
  1499. ieee80211_recalc_ps(local, -1);
  1500. mutex_unlock(&local->iflist_mtx);
  1501. if (sdata->local->hw.flags & IEEE80211_HW_CONNECTION_MONITOR)
  1502. goto out;
  1503. /*
  1504. * We've received a probe response, but are not sure whether
  1505. * we have or will be receiving any beacons or data, so let's
  1506. * schedule the timers again, just in case.
  1507. */
  1508. ieee80211_sta_reset_beacon_monitor(sdata);
  1509. mod_timer(&ifmgd->conn_mon_timer,
  1510. round_jiffies_up(jiffies +
  1511. IEEE80211_CONNECTION_IDLE_TIME));
  1512. out:
  1513. mutex_unlock(&local->mtx);
  1514. }
  1515. void ieee80211_sta_tx_notify(struct ieee80211_sub_if_data *sdata,
  1516. struct ieee80211_hdr *hdr, bool ack)
  1517. {
  1518. if (!ieee80211_is_data(hdr->frame_control))
  1519. return;
  1520. if (ieee80211_is_nullfunc(hdr->frame_control) &&
  1521. sdata->u.mgd.probe_send_count > 0) {
  1522. if (ack)
  1523. ieee80211_sta_reset_conn_monitor(sdata);
  1524. else
  1525. sdata->u.mgd.nullfunc_failed = true;
  1526. ieee80211_queue_work(&sdata->local->hw, &sdata->work);
  1527. return;
  1528. }
  1529. if (ack)
  1530. ieee80211_sta_reset_conn_monitor(sdata);
  1531. }
  1532. static void ieee80211_mgd_probe_ap_send(struct ieee80211_sub_if_data *sdata)
  1533. {
  1534. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1535. const u8 *ssid;
  1536. u8 *dst = ifmgd->associated->bssid;
  1537. u8 unicast_limit = max(1, max_probe_tries - 3);
  1538. /*
  1539. * Try sending broadcast probe requests for the last three
  1540. * probe requests after the first ones failed since some
  1541. * buggy APs only support broadcast probe requests.
  1542. */
  1543. if (ifmgd->probe_send_count >= unicast_limit)
  1544. dst = NULL;
  1545. /*
  1546. * When the hardware reports an accurate Tx ACK status, it's
  1547. * better to send a nullfunc frame instead of a probe request,
  1548. * as it will kick us off the AP quickly if we aren't associated
  1549. * anymore. The timeout will be reset if the frame is ACKed by
  1550. * the AP.
  1551. */
  1552. ifmgd->probe_send_count++;
  1553. if (sdata->local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS) {
  1554. ifmgd->nullfunc_failed = false;
  1555. ieee80211_send_nullfunc(sdata->local, sdata, 0);
  1556. } else {
  1557. int ssid_len;
  1558. rcu_read_lock();
  1559. ssid = ieee80211_bss_get_ie(ifmgd->associated, WLAN_EID_SSID);
  1560. if (WARN_ON_ONCE(ssid == NULL))
  1561. ssid_len = 0;
  1562. else
  1563. ssid_len = ssid[1];
  1564. ieee80211_send_probe_req(sdata, dst, ssid + 2, ssid_len, NULL,
  1565. 0, (u32) -1, true, 0,
  1566. ifmgd->associated->channel, false);
  1567. rcu_read_unlock();
  1568. }
  1569. ifmgd->probe_timeout = jiffies + msecs_to_jiffies(probe_wait_ms);
  1570. run_again(sdata, ifmgd->probe_timeout);
  1571. if (sdata->local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS)
  1572. ieee80211_flush_queues(sdata->local, sdata);
  1573. }
  1574. static void ieee80211_mgd_probe_ap(struct ieee80211_sub_if_data *sdata,
  1575. bool beacon)
  1576. {
  1577. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1578. bool already = false;
  1579. if (!ieee80211_sdata_running(sdata))
  1580. return;
  1581. sdata_lock(sdata);
  1582. if (!ifmgd->associated)
  1583. goto out;
  1584. mutex_lock(&sdata->local->mtx);
  1585. if (sdata->local->tmp_channel || sdata->local->scanning) {
  1586. mutex_unlock(&sdata->local->mtx);
  1587. goto out;
  1588. }
  1589. if (beacon) {
  1590. mlme_dbg_ratelimited(sdata,
  1591. "detected beacon loss from AP (missed %d beacons) - probing\n",
  1592. beacon_loss_count);
  1593. ieee80211_cqm_rssi_notify(&sdata->vif,
  1594. NL80211_CQM_RSSI_BEACON_LOSS_EVENT,
  1595. GFP_KERNEL);
  1596. }
  1597. /*
  1598. * The driver/our work has already reported this event or the
  1599. * connection monitoring has kicked in and we have already sent
  1600. * a probe request. Or maybe the AP died and the driver keeps
  1601. * reporting until we disassociate...
  1602. *
  1603. * In either case we have to ignore the current call to this
  1604. * function (except for setting the correct probe reason bit)
  1605. * because otherwise we would reset the timer every time and
  1606. * never check whether we received a probe response!
  1607. */
  1608. if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL)
  1609. already = true;
  1610. mutex_unlock(&sdata->local->mtx);
  1611. if (already)
  1612. goto out;
  1613. mutex_lock(&sdata->local->iflist_mtx);
  1614. ieee80211_recalc_ps(sdata->local, -1);
  1615. mutex_unlock(&sdata->local->iflist_mtx);
  1616. ifmgd->probe_send_count = 0;
  1617. ieee80211_mgd_probe_ap_send(sdata);
  1618. out:
  1619. sdata_unlock(sdata);
  1620. }
  1621. struct sk_buff *ieee80211_ap_probereq_get(struct ieee80211_hw *hw,
  1622. struct ieee80211_vif *vif)
  1623. {
  1624. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  1625. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1626. struct cfg80211_bss *cbss;
  1627. struct sk_buff *skb;
  1628. const u8 *ssid;
  1629. int ssid_len;
  1630. if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
  1631. return NULL;
  1632. sdata_assert_lock(sdata);
  1633. if (ifmgd->associated)
  1634. cbss = ifmgd->associated;
  1635. else if (ifmgd->auth_data)
  1636. cbss = ifmgd->auth_data->bss;
  1637. else if (ifmgd->assoc_data)
  1638. cbss = ifmgd->assoc_data->bss;
  1639. else
  1640. return NULL;
  1641. rcu_read_lock();
  1642. ssid = ieee80211_bss_get_ie(cbss, WLAN_EID_SSID);
  1643. if (WARN_ON_ONCE(ssid == NULL))
  1644. ssid_len = 0;
  1645. else
  1646. ssid_len = ssid[1];
  1647. skb = ieee80211_build_probe_req(sdata, cbss->bssid,
  1648. (u32) -1, cbss->channel,
  1649. ssid + 2, ssid_len,
  1650. NULL, 0, true);
  1651. rcu_read_unlock();
  1652. return skb;
  1653. }
  1654. EXPORT_SYMBOL(ieee80211_ap_probereq_get);
  1655. static void __ieee80211_disconnect(struct ieee80211_sub_if_data *sdata)
  1656. {
  1657. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1658. u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
  1659. sdata_lock(sdata);
  1660. if (!ifmgd->associated) {
  1661. sdata_unlock(sdata);
  1662. return;
  1663. }
  1664. ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
  1665. WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
  1666. true, frame_buf);
  1667. ifmgd->flags &= ~IEEE80211_STA_CSA_RECEIVED;
  1668. sdata->vif.csa_active = false;
  1669. ieee80211_wake_queues_by_reason(&sdata->local->hw,
  1670. IEEE80211_MAX_QUEUE_MAP,
  1671. IEEE80211_QUEUE_STOP_REASON_CSA);
  1672. cfg80211_tx_mlme_mgmt(sdata->dev, frame_buf,
  1673. IEEE80211_DEAUTH_FRAME_LEN);
  1674. sdata_unlock(sdata);
  1675. }
  1676. static void ieee80211_beacon_connection_loss_work(struct work_struct *work)
  1677. {
  1678. struct ieee80211_sub_if_data *sdata =
  1679. container_of(work, struct ieee80211_sub_if_data,
  1680. u.mgd.beacon_connection_loss_work);
  1681. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1682. struct sta_info *sta;
  1683. if (ifmgd->associated) {
  1684. rcu_read_lock();
  1685. sta = sta_info_get(sdata, ifmgd->bssid);
  1686. if (sta)
  1687. sta->beacon_loss_count++;
  1688. rcu_read_unlock();
  1689. }
  1690. if (ifmgd->connection_loss) {
  1691. sdata_info(sdata, "Connection to AP %pM lost\n",
  1692. ifmgd->bssid);
  1693. __ieee80211_disconnect(sdata);
  1694. } else {
  1695. ieee80211_mgd_probe_ap(sdata, true);
  1696. }
  1697. }
  1698. static void ieee80211_csa_connection_drop_work(struct work_struct *work)
  1699. {
  1700. struct ieee80211_sub_if_data *sdata =
  1701. container_of(work, struct ieee80211_sub_if_data,
  1702. u.mgd.csa_connection_drop_work);
  1703. __ieee80211_disconnect(sdata);
  1704. }
  1705. void ieee80211_beacon_loss(struct ieee80211_vif *vif)
  1706. {
  1707. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  1708. struct ieee80211_hw *hw = &sdata->local->hw;
  1709. trace_api_beacon_loss(sdata);
  1710. sdata->u.mgd.connection_loss = false;
  1711. ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work);
  1712. }
  1713. EXPORT_SYMBOL(ieee80211_beacon_loss);
  1714. void ieee80211_connection_loss(struct ieee80211_vif *vif)
  1715. {
  1716. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  1717. struct ieee80211_hw *hw = &sdata->local->hw;
  1718. trace_api_connection_loss(sdata);
  1719. sdata->u.mgd.connection_loss = true;
  1720. ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work);
  1721. }
  1722. EXPORT_SYMBOL(ieee80211_connection_loss);
  1723. static void ieee80211_destroy_auth_data(struct ieee80211_sub_if_data *sdata,
  1724. bool assoc)
  1725. {
  1726. struct ieee80211_mgd_auth_data *auth_data = sdata->u.mgd.auth_data;
  1727. sdata_assert_lock(sdata);
  1728. if (!assoc) {
  1729. sta_info_destroy_addr(sdata, auth_data->bss->bssid);
  1730. memset(sdata->u.mgd.bssid, 0, ETH_ALEN);
  1731. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
  1732. sdata->u.mgd.flags = 0;
  1733. ieee80211_vif_release_channel(sdata);
  1734. }
  1735. cfg80211_put_bss(sdata->local->hw.wiphy, auth_data->bss);
  1736. kfree(auth_data);
  1737. sdata->u.mgd.auth_data = NULL;
  1738. }
  1739. static void ieee80211_auth_challenge(struct ieee80211_sub_if_data *sdata,
  1740. struct ieee80211_mgmt *mgmt, size_t len)
  1741. {
  1742. struct ieee80211_local *local = sdata->local;
  1743. struct ieee80211_mgd_auth_data *auth_data = sdata->u.mgd.auth_data;
  1744. u8 *pos;
  1745. struct ieee802_11_elems elems;
  1746. u32 tx_flags = 0;
  1747. pos = mgmt->u.auth.variable;
  1748. ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), false, &elems);
  1749. if (!elems.challenge)
  1750. return;
  1751. auth_data->expected_transaction = 4;
  1752. drv_mgd_prepare_tx(sdata->local, sdata);
  1753. if (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS)
  1754. tx_flags = IEEE80211_TX_CTL_REQ_TX_STATUS |
  1755. IEEE80211_TX_INTFL_MLME_CONN_TX;
  1756. ieee80211_send_auth(sdata, 3, auth_data->algorithm, 0,
  1757. elems.challenge - 2, elems.challenge_len + 2,
  1758. auth_data->bss->bssid, auth_data->bss->bssid,
  1759. auth_data->key, auth_data->key_len,
  1760. auth_data->key_idx, tx_flags);
  1761. }
  1762. static void ieee80211_rx_mgmt_auth(struct ieee80211_sub_if_data *sdata,
  1763. struct ieee80211_mgmt *mgmt, size_t len)
  1764. {
  1765. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1766. u8 bssid[ETH_ALEN];
  1767. u16 auth_alg, auth_transaction, status_code;
  1768. struct sta_info *sta;
  1769. sdata_assert_lock(sdata);
  1770. if (len < 24 + 6)
  1771. return;
  1772. if (!ifmgd->auth_data || ifmgd->auth_data->done)
  1773. return;
  1774. memcpy(bssid, ifmgd->auth_data->bss->bssid, ETH_ALEN);
  1775. if (!ether_addr_equal(bssid, mgmt->bssid))
  1776. return;
  1777. auth_alg = le16_to_cpu(mgmt->u.auth.auth_alg);
  1778. auth_transaction = le16_to_cpu(mgmt->u.auth.auth_transaction);
  1779. status_code = le16_to_cpu(mgmt->u.auth.status_code);
  1780. if (auth_alg != ifmgd->auth_data->algorithm ||
  1781. auth_transaction != ifmgd->auth_data->expected_transaction) {
  1782. sdata_info(sdata, "%pM unexpected authentication state: alg %d (expected %d) transact %d (expected %d)\n",
  1783. mgmt->sa, auth_alg, ifmgd->auth_data->algorithm,
  1784. auth_transaction,
  1785. ifmgd->auth_data->expected_transaction);
  1786. return;
  1787. }
  1788. if (status_code != WLAN_STATUS_SUCCESS) {
  1789. sdata_info(sdata, "%pM denied authentication (status %d)\n",
  1790. mgmt->sa, status_code);
  1791. ieee80211_destroy_auth_data(sdata, false);
  1792. cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
  1793. return;
  1794. }
  1795. switch (ifmgd->auth_data->algorithm) {
  1796. case WLAN_AUTH_OPEN:
  1797. case WLAN_AUTH_LEAP:
  1798. case WLAN_AUTH_FT:
  1799. case WLAN_AUTH_SAE:
  1800. break;
  1801. case WLAN_AUTH_SHARED_KEY:
  1802. if (ifmgd->auth_data->expected_transaction != 4) {
  1803. ieee80211_auth_challenge(sdata, mgmt, len);
  1804. /* need another frame */
  1805. return;
  1806. }
  1807. break;
  1808. default:
  1809. WARN_ONCE(1, "invalid auth alg %d",
  1810. ifmgd->auth_data->algorithm);
  1811. return;
  1812. }
  1813. sdata_info(sdata, "authenticated\n");
  1814. ifmgd->auth_data->done = true;
  1815. ifmgd->auth_data->timeout = jiffies + IEEE80211_AUTH_WAIT_ASSOC;
  1816. ifmgd->auth_data->timeout_started = true;
  1817. run_again(sdata, ifmgd->auth_data->timeout);
  1818. if (ifmgd->auth_data->algorithm == WLAN_AUTH_SAE &&
  1819. ifmgd->auth_data->expected_transaction != 2) {
  1820. /*
  1821. * Report auth frame to user space for processing since another
  1822. * round of Authentication frames is still needed.
  1823. */
  1824. cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
  1825. return;
  1826. }
  1827. /* move station state to auth */
  1828. mutex_lock(&sdata->local->sta_mtx);
  1829. sta = sta_info_get(sdata, bssid);
  1830. if (!sta) {
  1831. WARN_ONCE(1, "%s: STA %pM not found", sdata->name, bssid);
  1832. goto out_err;
  1833. }
  1834. if (sta_info_move_state(sta, IEEE80211_STA_AUTH)) {
  1835. sdata_info(sdata, "failed moving %pM to auth\n", bssid);
  1836. goto out_err;
  1837. }
  1838. mutex_unlock(&sdata->local->sta_mtx);
  1839. cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
  1840. return;
  1841. out_err:
  1842. mutex_unlock(&sdata->local->sta_mtx);
  1843. /* ignore frame -- wait for timeout */
  1844. }
  1845. static void ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data *sdata,
  1846. struct ieee80211_mgmt *mgmt, size_t len)
  1847. {
  1848. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1849. const u8 *bssid = NULL;
  1850. u16 reason_code;
  1851. sdata_assert_lock(sdata);
  1852. if (len < 24 + 2)
  1853. return;
  1854. if (!ifmgd->associated ||
  1855. !ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid))
  1856. return;
  1857. bssid = ifmgd->associated->bssid;
  1858. reason_code = le16_to_cpu(mgmt->u.deauth.reason_code);
  1859. sdata_info(sdata, "deauthenticated from %pM (Reason: %u)\n",
  1860. bssid, reason_code);
  1861. ieee80211_set_disassoc(sdata, 0, 0, false, NULL);
  1862. cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
  1863. }
  1864. static void ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data *sdata,
  1865. struct ieee80211_mgmt *mgmt, size_t len)
  1866. {
  1867. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1868. u16 reason_code;
  1869. sdata_assert_lock(sdata);
  1870. if (len < 24 + 2)
  1871. return;
  1872. if (!ifmgd->associated ||
  1873. !ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid))
  1874. return;
  1875. reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code);
  1876. sdata_info(sdata, "disassociated from %pM (Reason: %u)\n",
  1877. mgmt->sa, reason_code);
  1878. ieee80211_set_disassoc(sdata, 0, 0, false, NULL);
  1879. cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
  1880. }
  1881. static void ieee80211_get_rates(struct ieee80211_supported_band *sband,
  1882. u8 *supp_rates, unsigned int supp_rates_len,
  1883. u32 *rates, u32 *basic_rates,
  1884. bool *have_higher_than_11mbit,
  1885. int *min_rate, int *min_rate_index,
  1886. int shift, u32 rate_flags)
  1887. {
  1888. int i, j;
  1889. for (i = 0; i < supp_rates_len; i++) {
  1890. int rate = supp_rates[i] & 0x7f;
  1891. bool is_basic = !!(supp_rates[i] & 0x80);
  1892. if ((rate * 5 * (1 << shift)) > 110)
  1893. *have_higher_than_11mbit = true;
  1894. /*
  1895. * BSS_MEMBERSHIP_SELECTOR_HT_PHY is defined in 802.11n-2009
  1896. * 7.3.2.2 as a magic value instead of a rate. Hence, skip it.
  1897. *
  1898. * Note: Even through the membership selector and the basic
  1899. * rate flag share the same bit, they are not exactly
  1900. * the same.
  1901. */
  1902. if (!!(supp_rates[i] & 0x80) &&
  1903. (supp_rates[i] & 0x7f) == BSS_MEMBERSHIP_SELECTOR_HT_PHY)
  1904. continue;
  1905. for (j = 0; j < sband->n_bitrates; j++) {
  1906. struct ieee80211_rate *br;
  1907. int brate;
  1908. br = &sband->bitrates[j];
  1909. if ((rate_flags & br->flags) != rate_flags)
  1910. continue;
  1911. brate = DIV_ROUND_UP(br->bitrate, (1 << shift) * 5);
  1912. if (brate == rate) {
  1913. *rates |= BIT(j);
  1914. if (is_basic)
  1915. *basic_rates |= BIT(j);
  1916. if ((rate * 5) < *min_rate) {
  1917. *min_rate = rate * 5;
  1918. *min_rate_index = j;
  1919. }
  1920. break;
  1921. }
  1922. }
  1923. }
  1924. }
  1925. static void ieee80211_destroy_assoc_data(struct ieee80211_sub_if_data *sdata,
  1926. bool assoc)
  1927. {
  1928. struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data;
  1929. sdata_assert_lock(sdata);
  1930. if (!assoc) {
  1931. sta_info_destroy_addr(sdata, assoc_data->bss->bssid);
  1932. memset(sdata->u.mgd.bssid, 0, ETH_ALEN);
  1933. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
  1934. sdata->u.mgd.flags = 0;
  1935. ieee80211_vif_release_channel(sdata);
  1936. }
  1937. kfree(assoc_data);
  1938. sdata->u.mgd.assoc_data = NULL;
  1939. }
  1940. static bool ieee80211_assoc_success(struct ieee80211_sub_if_data *sdata,
  1941. struct cfg80211_bss *cbss,
  1942. struct ieee80211_mgmt *mgmt, size_t len)
  1943. {
  1944. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1945. struct ieee80211_local *local = sdata->local;
  1946. struct ieee80211_supported_band *sband;
  1947. struct sta_info *sta;
  1948. u8 *pos;
  1949. u16 capab_info, aid;
  1950. struct ieee802_11_elems elems;
  1951. struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
  1952. const struct cfg80211_bss_ies *bss_ies = NULL;
  1953. struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
  1954. u32 changed = 0;
  1955. int err;
  1956. bool ret;
  1957. /* AssocResp and ReassocResp have identical structure */
  1958. aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
  1959. capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
  1960. if ((aid & (BIT(15) | BIT(14))) != (BIT(15) | BIT(14)))
  1961. sdata_info(sdata, "invalid AID value 0x%x; bits 15:14 not set\n",
  1962. aid);
  1963. aid &= ~(BIT(15) | BIT(14));
  1964. ifmgd->broken_ap = false;
  1965. if (aid == 0 || aid > IEEE80211_MAX_AID) {
  1966. sdata_info(sdata, "invalid AID value %d (out of range), turn off PS\n",
  1967. aid);
  1968. aid = 0;
  1969. ifmgd->broken_ap = true;
  1970. }
  1971. pos = mgmt->u.assoc_resp.variable;
  1972. ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), false, &elems);
  1973. if (!elems.supp_rates) {
  1974. sdata_info(sdata, "no SuppRates element in AssocResp\n");
  1975. return false;
  1976. }
  1977. ifmgd->aid = aid;
  1978. /*
  1979. * Some APs are erroneously not including some information in their
  1980. * (re)association response frames. Try to recover by using the data
  1981. * from the beacon or probe response. This seems to afflict mobile
  1982. * 2G/3G/4G wifi routers, reported models include the "Onda PN51T",
  1983. * "Vodafone PocketWiFi 2", "ZTE MF60" and a similar T-Mobile device.
  1984. */
  1985. if ((assoc_data->wmm && !elems.wmm_param) ||
  1986. (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT) &&
  1987. (!elems.ht_cap_elem || !elems.ht_operation)) ||
  1988. (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) &&
  1989. (!elems.vht_cap_elem || !elems.vht_operation))) {
  1990. const struct cfg80211_bss_ies *ies;
  1991. struct ieee802_11_elems bss_elems;
  1992. rcu_read_lock();
  1993. ies = rcu_dereference(cbss->ies);
  1994. if (ies)
  1995. bss_ies = kmemdup(ies, sizeof(*ies) + ies->len,
  1996. GFP_ATOMIC);
  1997. rcu_read_unlock();
  1998. if (!bss_ies)
  1999. return false;
  2000. ieee802_11_parse_elems(bss_ies->data, bss_ies->len,
  2001. false, &bss_elems);
  2002. if (assoc_data->wmm &&
  2003. !elems.wmm_param && bss_elems.wmm_param) {
  2004. elems.wmm_param = bss_elems.wmm_param;
  2005. sdata_info(sdata,
  2006. "AP bug: WMM param missing from AssocResp\n");
  2007. }
  2008. /*
  2009. * Also check if we requested HT/VHT, otherwise the AP doesn't
  2010. * have to include the IEs in the (re)association response.
  2011. */
  2012. if (!elems.ht_cap_elem && bss_elems.ht_cap_elem &&
  2013. !(ifmgd->flags & IEEE80211_STA_DISABLE_HT)) {
  2014. elems.ht_cap_elem = bss_elems.ht_cap_elem;
  2015. sdata_info(sdata,
  2016. "AP bug: HT capability missing from AssocResp\n");
  2017. }
  2018. if (!elems.ht_operation && bss_elems.ht_operation &&
  2019. !(ifmgd->flags & IEEE80211_STA_DISABLE_HT)) {
  2020. elems.ht_operation = bss_elems.ht_operation;
  2021. sdata_info(sdata,
  2022. "AP bug: HT operation missing from AssocResp\n");
  2023. }
  2024. if (!elems.vht_cap_elem && bss_elems.vht_cap_elem &&
  2025. !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)) {
  2026. elems.vht_cap_elem = bss_elems.vht_cap_elem;
  2027. sdata_info(sdata,
  2028. "AP bug: VHT capa missing from AssocResp\n");
  2029. }
  2030. if (!elems.vht_operation && bss_elems.vht_operation &&
  2031. !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)) {
  2032. elems.vht_operation = bss_elems.vht_operation;
  2033. sdata_info(sdata,
  2034. "AP bug: VHT operation missing from AssocResp\n");
  2035. }
  2036. }
  2037. /*
  2038. * We previously checked these in the beacon/probe response, so
  2039. * they should be present here. This is just a safety net.
  2040. */
  2041. if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT) &&
  2042. (!elems.wmm_param || !elems.ht_cap_elem || !elems.ht_operation)) {
  2043. sdata_info(sdata,
  2044. "HT AP is missing WMM params or HT capability/operation\n");
  2045. ret = false;
  2046. goto out;
  2047. }
  2048. if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) &&
  2049. (!elems.vht_cap_elem || !elems.vht_operation)) {
  2050. sdata_info(sdata,
  2051. "VHT AP is missing VHT capability/operation\n");
  2052. ret = false;
  2053. goto out;
  2054. }
  2055. mutex_lock(&sdata->local->sta_mtx);
  2056. /*
  2057. * station info was already allocated and inserted before
  2058. * the association and should be available to us
  2059. */
  2060. sta = sta_info_get(sdata, cbss->bssid);
  2061. if (WARN_ON(!sta)) {
  2062. mutex_unlock(&sdata->local->sta_mtx);
  2063. ret = false;
  2064. goto out;
  2065. }
  2066. sband = local->hw.wiphy->bands[ieee80211_get_sdata_band(sdata)];
  2067. /* Set up internal HT/VHT capabilities */
  2068. if (elems.ht_cap_elem && !(ifmgd->flags & IEEE80211_STA_DISABLE_HT))
  2069. ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
  2070. elems.ht_cap_elem, sta);
  2071. if (elems.vht_cap_elem && !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
  2072. ieee80211_vht_cap_ie_to_sta_vht_cap(sdata, sband,
  2073. elems.vht_cap_elem, sta);
  2074. /*
  2075. * Some APs, e.g. Netgear WNDR3700, report invalid HT operation data
  2076. * in their association response, so ignore that data for our own
  2077. * configuration. If it changed since the last beacon, we'll get the
  2078. * next beacon and update then.
  2079. */
  2080. /*
  2081. * If an operating mode notification IE is present, override the
  2082. * NSS calculation (that would be done in rate_control_rate_init())
  2083. * and use the # of streams from that element.
  2084. */
  2085. if (elems.opmode_notif &&
  2086. !(*elems.opmode_notif & IEEE80211_OPMODE_NOTIF_RX_NSS_TYPE_BF)) {
  2087. u8 nss;
  2088. nss = *elems.opmode_notif & IEEE80211_OPMODE_NOTIF_RX_NSS_MASK;
  2089. nss >>= IEEE80211_OPMODE_NOTIF_RX_NSS_SHIFT;
  2090. nss += 1;
  2091. sta->sta.rx_nss = nss;
  2092. }
  2093. rate_control_rate_init(sta);
  2094. if (ifmgd->flags & IEEE80211_STA_MFP_ENABLED)
  2095. set_sta_flag(sta, WLAN_STA_MFP);
  2096. if (elems.wmm_param)
  2097. set_sta_flag(sta, WLAN_STA_WME);
  2098. err = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
  2099. if (!err && !(ifmgd->flags & IEEE80211_STA_CONTROL_PORT))
  2100. err = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED);
  2101. if (err) {
  2102. sdata_info(sdata,
  2103. "failed to move station %pM to desired state\n",
  2104. sta->sta.addr);
  2105. WARN_ON(__sta_info_destroy(sta));
  2106. mutex_unlock(&sdata->local->sta_mtx);
  2107. ret = false;
  2108. goto out;
  2109. }
  2110. mutex_unlock(&sdata->local->sta_mtx);
  2111. /*
  2112. * Always handle WMM once after association regardless
  2113. * of the first value the AP uses. Setting -1 here has
  2114. * that effect because the AP values is an unsigned
  2115. * 4-bit value.
  2116. */
  2117. ifmgd->wmm_last_param_set = -1;
  2118. if (elems.wmm_param)
  2119. ieee80211_sta_wmm_params(local, sdata, elems.wmm_param,
  2120. elems.wmm_param_len);
  2121. else
  2122. ieee80211_set_wmm_default(sdata, false);
  2123. changed |= BSS_CHANGED_QOS;
  2124. /* set AID and assoc capability,
  2125. * ieee80211_set_associated() will tell the driver */
  2126. bss_conf->aid = aid;
  2127. bss_conf->assoc_capability = capab_info;
  2128. ieee80211_set_associated(sdata, cbss, changed);
  2129. /*
  2130. * If we're using 4-addr mode, let the AP know that we're
  2131. * doing so, so that it can create the STA VLAN on its side
  2132. */
  2133. if (ifmgd->use_4addr)
  2134. ieee80211_send_4addr_nullfunc(local, sdata);
  2135. /*
  2136. * Start timer to probe the connection to the AP now.
  2137. * Also start the timer that will detect beacon loss.
  2138. */
  2139. ieee80211_sta_rx_notify(sdata, (struct ieee80211_hdr *)mgmt);
  2140. ieee80211_sta_reset_beacon_monitor(sdata);
  2141. ret = true;
  2142. out:
  2143. kfree(bss_ies);
  2144. return ret;
  2145. }
  2146. static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
  2147. struct ieee80211_mgmt *mgmt,
  2148. size_t len)
  2149. {
  2150. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  2151. struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
  2152. u16 capab_info, status_code, aid;
  2153. struct ieee802_11_elems elems;
  2154. u8 *pos;
  2155. bool reassoc;
  2156. struct cfg80211_bss *bss;
  2157. sdata_assert_lock(sdata);
  2158. if (!assoc_data)
  2159. return;
  2160. if (!ether_addr_equal(assoc_data->bss->bssid, mgmt->bssid))
  2161. return;
  2162. /*
  2163. * AssocResp and ReassocResp have identical structure, so process both
  2164. * of them in this function.
  2165. */
  2166. if (len < 24 + 6)
  2167. return;
  2168. reassoc = ieee80211_is_reassoc_req(mgmt->frame_control);
  2169. capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
  2170. status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code);
  2171. aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
  2172. sdata_info(sdata,
  2173. "RX %sssocResp from %pM (capab=0x%x status=%d aid=%d)\n",
  2174. reassoc ? "Rea" : "A", mgmt->sa,
  2175. capab_info, status_code, (u16)(aid & ~(BIT(15) | BIT(14))));
  2176. pos = mgmt->u.assoc_resp.variable;
  2177. ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), false, &elems);
  2178. if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY &&
  2179. elems.timeout_int &&
  2180. elems.timeout_int->type == WLAN_TIMEOUT_ASSOC_COMEBACK) {
  2181. u32 tu, ms;
  2182. tu = le32_to_cpu(elems.timeout_int->value);
  2183. ms = tu * 1024 / 1000;
  2184. sdata_info(sdata,
  2185. "%pM rejected association temporarily; comeback duration %u TU (%u ms)\n",
  2186. mgmt->sa, tu, ms);
  2187. assoc_data->timeout = jiffies + msecs_to_jiffies(ms);
  2188. assoc_data->timeout_started = true;
  2189. if (ms > IEEE80211_ASSOC_TIMEOUT)
  2190. run_again(sdata, assoc_data->timeout);
  2191. return;
  2192. }
  2193. bss = assoc_data->bss;
  2194. if (status_code != WLAN_STATUS_SUCCESS) {
  2195. sdata_info(sdata, "%pM denied association (code=%d)\n",
  2196. mgmt->sa, status_code);
  2197. ieee80211_destroy_assoc_data(sdata, false);
  2198. } else {
  2199. if (!ieee80211_assoc_success(sdata, bss, mgmt, len)) {
  2200. /* oops -- internal error -- send timeout for now */
  2201. ieee80211_destroy_assoc_data(sdata, false);
  2202. cfg80211_assoc_timeout(sdata->dev, bss);
  2203. return;
  2204. }
  2205. sdata_info(sdata, "associated\n");
  2206. /*
  2207. * destroy assoc_data afterwards, as otherwise an idle
  2208. * recalc after assoc_data is NULL but before associated
  2209. * is set can cause the interface to go idle
  2210. */
  2211. ieee80211_destroy_assoc_data(sdata, true);
  2212. }
  2213. cfg80211_rx_assoc_resp(sdata->dev, bss, (u8 *)mgmt, len);
  2214. }
  2215. static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
  2216. struct ieee80211_mgmt *mgmt, size_t len,
  2217. struct ieee80211_rx_status *rx_status,
  2218. struct ieee802_11_elems *elems)
  2219. {
  2220. struct ieee80211_local *local = sdata->local;
  2221. int freq;
  2222. struct ieee80211_bss *bss;
  2223. struct ieee80211_channel *channel;
  2224. sdata_assert_lock(sdata);
  2225. if (elems->ds_params)
  2226. freq = ieee80211_channel_to_frequency(elems->ds_params[0],
  2227. rx_status->band);
  2228. else
  2229. freq = rx_status->freq;
  2230. channel = ieee80211_get_channel(local->hw.wiphy, freq);
  2231. if (!channel || channel->flags & IEEE80211_CHAN_DISABLED)
  2232. return;
  2233. bss = ieee80211_bss_info_update(local, rx_status, mgmt, len, elems,
  2234. channel);
  2235. if (bss) {
  2236. ieee80211_rx_bss_put(local, bss);
  2237. sdata->vif.bss_conf.beacon_rate = bss->beacon_rate;
  2238. }
  2239. }
  2240. static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data *sdata,
  2241. struct sk_buff *skb)
  2242. {
  2243. struct ieee80211_mgmt *mgmt = (void *)skb->data;
  2244. struct ieee80211_if_managed *ifmgd;
  2245. struct ieee80211_rx_status *rx_status = (void *) skb->cb;
  2246. size_t baselen, len = skb->len;
  2247. struct ieee802_11_elems elems;
  2248. ifmgd = &sdata->u.mgd;
  2249. sdata_assert_lock(sdata);
  2250. if (!ether_addr_equal(mgmt->da, sdata->vif.addr))
  2251. return; /* ignore ProbeResp to foreign address */
  2252. baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
  2253. if (baselen > len)
  2254. return;
  2255. ieee802_11_parse_elems(mgmt->u.probe_resp.variable, len - baselen,
  2256. false, &elems);
  2257. ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems);
  2258. if (ifmgd->associated &&
  2259. ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid))
  2260. ieee80211_reset_ap_probe(sdata);
  2261. if (ifmgd->auth_data && !ifmgd->auth_data->bss->proberesp_ies &&
  2262. ether_addr_equal(mgmt->bssid, ifmgd->auth_data->bss->bssid)) {
  2263. /* got probe response, continue with auth */
  2264. sdata_info(sdata, "direct probe responded\n");
  2265. ifmgd->auth_data->tries = 0;
  2266. ifmgd->auth_data->timeout = jiffies;
  2267. ifmgd->auth_data->timeout_started = true;
  2268. run_again(sdata, ifmgd->auth_data->timeout);
  2269. }
  2270. }
  2271. /*
  2272. * This is the canonical list of information elements we care about,
  2273. * the filter code also gives us all changes to the Microsoft OUI
  2274. * (00:50:F2) vendor IE which is used for WMM which we need to track.
  2275. *
  2276. * We implement beacon filtering in software since that means we can
  2277. * avoid processing the frame here and in cfg80211, and userspace
  2278. * will not be able to tell whether the hardware supports it or not.
  2279. *
  2280. * XXX: This list needs to be dynamic -- userspace needs to be able to
  2281. * add items it requires. It also needs to be able to tell us to
  2282. * look out for other vendor IEs.
  2283. */
  2284. static const u64 care_about_ies =
  2285. (1ULL << WLAN_EID_COUNTRY) |
  2286. (1ULL << WLAN_EID_ERP_INFO) |
  2287. (1ULL << WLAN_EID_CHANNEL_SWITCH) |
  2288. (1ULL << WLAN_EID_PWR_CONSTRAINT) |
  2289. (1ULL << WLAN_EID_HT_CAPABILITY) |
  2290. (1ULL << WLAN_EID_HT_OPERATION);
  2291. static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata,
  2292. struct ieee80211_mgmt *mgmt, size_t len,
  2293. struct ieee80211_rx_status *rx_status)
  2294. {
  2295. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  2296. struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
  2297. size_t baselen;
  2298. struct ieee802_11_elems elems;
  2299. struct ieee80211_local *local = sdata->local;
  2300. struct ieee80211_chanctx_conf *chanctx_conf;
  2301. struct ieee80211_channel *chan;
  2302. struct sta_info *sta;
  2303. u32 changed = 0;
  2304. bool erp_valid;
  2305. u8 erp_value = 0;
  2306. u32 ncrc;
  2307. u8 *bssid;
  2308. u8 deauth_buf[IEEE80211_DEAUTH_FRAME_LEN];
  2309. sdata_assert_lock(sdata);
  2310. /* Process beacon from the current BSS */
  2311. baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt;
  2312. if (baselen > len)
  2313. return;
  2314. rcu_read_lock();
  2315. chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
  2316. if (!chanctx_conf) {
  2317. rcu_read_unlock();
  2318. return;
  2319. }
  2320. if (rx_status->freq != chanctx_conf->def.chan->center_freq) {
  2321. rcu_read_unlock();
  2322. return;
  2323. }
  2324. chan = chanctx_conf->def.chan;
  2325. rcu_read_unlock();
  2326. if (ifmgd->assoc_data && ifmgd->assoc_data->need_beacon &&
  2327. ether_addr_equal(mgmt->bssid, ifmgd->assoc_data->bss->bssid)) {
  2328. ieee802_11_parse_elems(mgmt->u.beacon.variable,
  2329. len - baselen, false, &elems);
  2330. ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems);
  2331. if (elems.tim && !elems.parse_error) {
  2332. const struct ieee80211_tim_ie *tim_ie = elems.tim;
  2333. ifmgd->dtim_period = tim_ie->dtim_period;
  2334. }
  2335. ifmgd->have_beacon = true;
  2336. ifmgd->assoc_data->need_beacon = false;
  2337. if (local->hw.flags & IEEE80211_HW_TIMING_BEACON_ONLY) {
  2338. sdata->vif.bss_conf.sync_tsf =
  2339. le64_to_cpu(mgmt->u.beacon.timestamp);
  2340. sdata->vif.bss_conf.sync_device_ts =
  2341. rx_status->device_timestamp;
  2342. if (elems.tim)
  2343. sdata->vif.bss_conf.sync_dtim_count =
  2344. elems.tim->dtim_count;
  2345. else
  2346. sdata->vif.bss_conf.sync_dtim_count = 0;
  2347. }
  2348. /* continue assoc process */
  2349. ifmgd->assoc_data->timeout = jiffies;
  2350. ifmgd->assoc_data->timeout_started = true;
  2351. run_again(sdata, ifmgd->assoc_data->timeout);
  2352. return;
  2353. }
  2354. if (!ifmgd->associated ||
  2355. !ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid))
  2356. return;
  2357. bssid = ifmgd->associated->bssid;
  2358. /* Track average RSSI from the Beacon frames of the current AP */
  2359. ifmgd->last_beacon_signal = rx_status->signal;
  2360. if (ifmgd->flags & IEEE80211_STA_RESET_SIGNAL_AVE) {
  2361. ifmgd->flags &= ~IEEE80211_STA_RESET_SIGNAL_AVE;
  2362. ifmgd->ave_beacon_signal = rx_status->signal * 16;
  2363. ifmgd->last_cqm_event_signal = 0;
  2364. ifmgd->count_beacon_signal = 1;
  2365. ifmgd->last_ave_beacon_signal = 0;
  2366. } else {
  2367. ifmgd->ave_beacon_signal =
  2368. (IEEE80211_SIGNAL_AVE_WEIGHT * rx_status->signal * 16 +
  2369. (16 - IEEE80211_SIGNAL_AVE_WEIGHT) *
  2370. ifmgd->ave_beacon_signal) / 16;
  2371. ifmgd->count_beacon_signal++;
  2372. }
  2373. if (ifmgd->rssi_min_thold != ifmgd->rssi_max_thold &&
  2374. ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT) {
  2375. int sig = ifmgd->ave_beacon_signal;
  2376. int last_sig = ifmgd->last_ave_beacon_signal;
  2377. /*
  2378. * if signal crosses either of the boundaries, invoke callback
  2379. * with appropriate parameters
  2380. */
  2381. if (sig > ifmgd->rssi_max_thold &&
  2382. (last_sig <= ifmgd->rssi_min_thold || last_sig == 0)) {
  2383. ifmgd->last_ave_beacon_signal = sig;
  2384. drv_rssi_callback(local, sdata, RSSI_EVENT_HIGH);
  2385. } else if (sig < ifmgd->rssi_min_thold &&
  2386. (last_sig >= ifmgd->rssi_max_thold ||
  2387. last_sig == 0)) {
  2388. ifmgd->last_ave_beacon_signal = sig;
  2389. drv_rssi_callback(local, sdata, RSSI_EVENT_LOW);
  2390. }
  2391. }
  2392. if (bss_conf->cqm_rssi_thold &&
  2393. ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT &&
  2394. !(sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)) {
  2395. int sig = ifmgd->ave_beacon_signal / 16;
  2396. int last_event = ifmgd->last_cqm_event_signal;
  2397. int thold = bss_conf->cqm_rssi_thold;
  2398. int hyst = bss_conf->cqm_rssi_hyst;
  2399. if (sig < thold &&
  2400. (last_event == 0 || sig < last_event - hyst)) {
  2401. ifmgd->last_cqm_event_signal = sig;
  2402. ieee80211_cqm_rssi_notify(
  2403. &sdata->vif,
  2404. NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW,
  2405. GFP_KERNEL);
  2406. } else if (sig > thold &&
  2407. (last_event == 0 || sig > last_event + hyst)) {
  2408. ifmgd->last_cqm_event_signal = sig;
  2409. ieee80211_cqm_rssi_notify(
  2410. &sdata->vif,
  2411. NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
  2412. GFP_KERNEL);
  2413. }
  2414. }
  2415. if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL) {
  2416. mlme_dbg_ratelimited(sdata,
  2417. "cancelling AP probe due to a received beacon\n");
  2418. ieee80211_reset_ap_probe(sdata);
  2419. }
  2420. /*
  2421. * Push the beacon loss detection into the future since
  2422. * we are processing a beacon from the AP just now.
  2423. */
  2424. ieee80211_sta_reset_beacon_monitor(sdata);
  2425. ncrc = crc32_be(0, (void *)&mgmt->u.beacon.beacon_int, 4);
  2426. ncrc = ieee802_11_parse_elems_crc(mgmt->u.beacon.variable,
  2427. len - baselen, false, &elems,
  2428. care_about_ies, ncrc);
  2429. if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) {
  2430. bool directed_tim = ieee80211_check_tim(elems.tim,
  2431. elems.tim_len,
  2432. ifmgd->aid);
  2433. if (directed_tim) {
  2434. if (local->hw.conf.dynamic_ps_timeout > 0) {
  2435. if (local->hw.conf.flags & IEEE80211_CONF_PS) {
  2436. local->hw.conf.flags &= ~IEEE80211_CONF_PS;
  2437. ieee80211_hw_config(local,
  2438. IEEE80211_CONF_CHANGE_PS);
  2439. }
  2440. ieee80211_send_nullfunc(local, sdata, 0);
  2441. } else if (!local->pspolling && sdata->u.mgd.powersave) {
  2442. local->pspolling = true;
  2443. /*
  2444. * Here is assumed that the driver will be
  2445. * able to send ps-poll frame and receive a
  2446. * response even though power save mode is
  2447. * enabled, but some drivers might require
  2448. * to disable power save here. This needs
  2449. * to be investigated.
  2450. */
  2451. ieee80211_send_pspoll(local, sdata);
  2452. }
  2453. }
  2454. }
  2455. if (sdata->vif.p2p) {
  2456. struct ieee80211_p2p_noa_attr noa = {};
  2457. int ret;
  2458. ret = cfg80211_get_p2p_attr(mgmt->u.beacon.variable,
  2459. len - baselen,
  2460. IEEE80211_P2P_ATTR_ABSENCE_NOTICE,
  2461. (u8 *) &noa, sizeof(noa));
  2462. if (ret >= 2) {
  2463. if (sdata->u.mgd.p2p_noa_index != noa.index) {
  2464. /* valid noa_attr and index changed */
  2465. sdata->u.mgd.p2p_noa_index = noa.index;
  2466. memcpy(&bss_conf->p2p_noa_attr, &noa, sizeof(noa));
  2467. changed |= BSS_CHANGED_P2P_PS;
  2468. /*
  2469. * make sure we update all information, the CRC
  2470. * mechanism doesn't look at P2P attributes.
  2471. */
  2472. ifmgd->beacon_crc_valid = false;
  2473. }
  2474. } else if (sdata->u.mgd.p2p_noa_index != -1) {
  2475. /* noa_attr not found and we had valid noa_attr before */
  2476. sdata->u.mgd.p2p_noa_index = -1;
  2477. memset(&bss_conf->p2p_noa_attr, 0, sizeof(bss_conf->p2p_noa_attr));
  2478. changed |= BSS_CHANGED_P2P_PS;
  2479. ifmgd->beacon_crc_valid = false;
  2480. }
  2481. }
  2482. if (ncrc == ifmgd->beacon_crc && ifmgd->beacon_crc_valid)
  2483. return;
  2484. ifmgd->beacon_crc = ncrc;
  2485. ifmgd->beacon_crc_valid = true;
  2486. ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems);
  2487. ieee80211_sta_process_chanswitch(sdata, rx_status->mactime,
  2488. &elems, true);
  2489. if (ieee80211_sta_wmm_params(local, sdata, elems.wmm_param,
  2490. elems.wmm_param_len))
  2491. changed |= BSS_CHANGED_QOS;
  2492. /*
  2493. * If we haven't had a beacon before, tell the driver about the
  2494. * DTIM period (and beacon timing if desired) now.
  2495. */
  2496. if (!ifmgd->have_beacon) {
  2497. /* a few bogus AP send dtim_period = 0 or no TIM IE */
  2498. if (elems.tim)
  2499. bss_conf->dtim_period = elems.tim->dtim_period ?: 1;
  2500. else
  2501. bss_conf->dtim_period = 1;
  2502. if (local->hw.flags & IEEE80211_HW_TIMING_BEACON_ONLY) {
  2503. sdata->vif.bss_conf.sync_tsf =
  2504. le64_to_cpu(mgmt->u.beacon.timestamp);
  2505. sdata->vif.bss_conf.sync_device_ts =
  2506. rx_status->device_timestamp;
  2507. if (elems.tim)
  2508. sdata->vif.bss_conf.sync_dtim_count =
  2509. elems.tim->dtim_count;
  2510. else
  2511. sdata->vif.bss_conf.sync_dtim_count = 0;
  2512. }
  2513. changed |= BSS_CHANGED_BEACON_INFO;
  2514. ifmgd->have_beacon = true;
  2515. mutex_lock(&local->iflist_mtx);
  2516. ieee80211_recalc_ps(local, -1);
  2517. mutex_unlock(&local->iflist_mtx);
  2518. ieee80211_recalc_ps_vif(sdata);
  2519. }
  2520. if (elems.erp_info) {
  2521. erp_valid = true;
  2522. erp_value = elems.erp_info[0];
  2523. } else {
  2524. erp_valid = false;
  2525. }
  2526. changed |= ieee80211_handle_bss_capability(sdata,
  2527. le16_to_cpu(mgmt->u.beacon.capab_info),
  2528. erp_valid, erp_value);
  2529. mutex_lock(&local->sta_mtx);
  2530. sta = sta_info_get(sdata, bssid);
  2531. if (ieee80211_config_bw(sdata, sta, elems.ht_operation,
  2532. elems.vht_operation, bssid, &changed)) {
  2533. mutex_unlock(&local->sta_mtx);
  2534. ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
  2535. WLAN_REASON_DEAUTH_LEAVING,
  2536. true, deauth_buf);
  2537. cfg80211_tx_mlme_mgmt(sdata->dev, deauth_buf,
  2538. sizeof(deauth_buf));
  2539. return;
  2540. }
  2541. if (sta && elems.opmode_notif)
  2542. ieee80211_vht_handle_opmode(sdata, sta, *elems.opmode_notif,
  2543. rx_status->band, true);
  2544. mutex_unlock(&local->sta_mtx);
  2545. if (elems.country_elem && elems.pwr_constr_elem &&
  2546. mgmt->u.probe_resp.capab_info &
  2547. cpu_to_le16(WLAN_CAPABILITY_SPECTRUM_MGMT))
  2548. changed |= ieee80211_handle_pwr_constr(sdata, chan,
  2549. elems.country_elem,
  2550. elems.country_elem_len,
  2551. elems.pwr_constr_elem);
  2552. ieee80211_bss_info_change_notify(sdata, changed);
  2553. }
  2554. void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
  2555. struct sk_buff *skb)
  2556. {
  2557. struct ieee80211_rx_status *rx_status;
  2558. struct ieee80211_mgmt *mgmt;
  2559. u16 fc;
  2560. struct ieee802_11_elems elems;
  2561. int ies_len;
  2562. rx_status = (struct ieee80211_rx_status *) skb->cb;
  2563. mgmt = (struct ieee80211_mgmt *) skb->data;
  2564. fc = le16_to_cpu(mgmt->frame_control);
  2565. sdata_lock(sdata);
  2566. switch (fc & IEEE80211_FCTL_STYPE) {
  2567. case IEEE80211_STYPE_BEACON:
  2568. ieee80211_rx_mgmt_beacon(sdata, mgmt, skb->len, rx_status);
  2569. break;
  2570. case IEEE80211_STYPE_PROBE_RESP:
  2571. ieee80211_rx_mgmt_probe_resp(sdata, skb);
  2572. break;
  2573. case IEEE80211_STYPE_AUTH:
  2574. ieee80211_rx_mgmt_auth(sdata, mgmt, skb->len);
  2575. break;
  2576. case IEEE80211_STYPE_DEAUTH:
  2577. ieee80211_rx_mgmt_deauth(sdata, mgmt, skb->len);
  2578. break;
  2579. case IEEE80211_STYPE_DISASSOC:
  2580. ieee80211_rx_mgmt_disassoc(sdata, mgmt, skb->len);
  2581. break;
  2582. case IEEE80211_STYPE_ASSOC_RESP:
  2583. case IEEE80211_STYPE_REASSOC_RESP:
  2584. ieee80211_rx_mgmt_assoc_resp(sdata, mgmt, skb->len);
  2585. break;
  2586. case IEEE80211_STYPE_ACTION:
  2587. if (mgmt->u.action.category == WLAN_CATEGORY_SPECTRUM_MGMT) {
  2588. ies_len = skb->len -
  2589. offsetof(struct ieee80211_mgmt,
  2590. u.action.u.chan_switch.variable);
  2591. if (ies_len < 0)
  2592. break;
  2593. ieee802_11_parse_elems(
  2594. mgmt->u.action.u.chan_switch.variable,
  2595. ies_len, true, &elems);
  2596. if (elems.parse_error)
  2597. break;
  2598. ieee80211_sta_process_chanswitch(sdata,
  2599. rx_status->mactime,
  2600. &elems, false);
  2601. } else if (mgmt->u.action.category == WLAN_CATEGORY_PUBLIC) {
  2602. ies_len = skb->len -
  2603. offsetof(struct ieee80211_mgmt,
  2604. u.action.u.ext_chan_switch.variable);
  2605. if (ies_len < 0)
  2606. break;
  2607. ieee802_11_parse_elems(
  2608. mgmt->u.action.u.ext_chan_switch.variable,
  2609. ies_len, true, &elems);
  2610. if (elems.parse_error)
  2611. break;
  2612. /* for the handling code pretend this was also an IE */
  2613. elems.ext_chansw_ie =
  2614. &mgmt->u.action.u.ext_chan_switch.data;
  2615. ieee80211_sta_process_chanswitch(sdata,
  2616. rx_status->mactime,
  2617. &elems, false);
  2618. }
  2619. break;
  2620. }
  2621. sdata_unlock(sdata);
  2622. }
  2623. static void ieee80211_sta_timer(unsigned long data)
  2624. {
  2625. struct ieee80211_sub_if_data *sdata =
  2626. (struct ieee80211_sub_if_data *) data;
  2627. ieee80211_queue_work(&sdata->local->hw, &sdata->work);
  2628. }
  2629. static void ieee80211_sta_connection_lost(struct ieee80211_sub_if_data *sdata,
  2630. u8 *bssid, u8 reason, bool tx)
  2631. {
  2632. u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
  2633. ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH, reason,
  2634. tx, frame_buf);
  2635. cfg80211_tx_mlme_mgmt(sdata->dev, frame_buf,
  2636. IEEE80211_DEAUTH_FRAME_LEN);
  2637. }
  2638. static int ieee80211_probe_auth(struct ieee80211_sub_if_data *sdata)
  2639. {
  2640. struct ieee80211_local *local = sdata->local;
  2641. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  2642. struct ieee80211_mgd_auth_data *auth_data = ifmgd->auth_data;
  2643. u32 tx_flags = 0;
  2644. sdata_assert_lock(sdata);
  2645. if (WARN_ON_ONCE(!auth_data))
  2646. return -EINVAL;
  2647. auth_data->tries++;
  2648. if (auth_data->tries > IEEE80211_AUTH_MAX_TRIES) {
  2649. sdata_info(sdata, "authentication with %pM timed out\n",
  2650. auth_data->bss->bssid);
  2651. /*
  2652. * Most likely AP is not in the range so remove the
  2653. * bss struct for that AP.
  2654. */
  2655. cfg80211_unlink_bss(local->hw.wiphy, auth_data->bss);
  2656. return -ETIMEDOUT;
  2657. }
  2658. drv_mgd_prepare_tx(local, sdata);
  2659. if (auth_data->bss->proberesp_ies) {
  2660. u16 trans = 1;
  2661. u16 status = 0;
  2662. sdata_info(sdata, "send auth to %pM (try %d/%d)\n",
  2663. auth_data->bss->bssid, auth_data->tries,
  2664. IEEE80211_AUTH_MAX_TRIES);
  2665. auth_data->expected_transaction = 2;
  2666. if (auth_data->algorithm == WLAN_AUTH_SAE) {
  2667. trans = auth_data->sae_trans;
  2668. status = auth_data->sae_status;
  2669. auth_data->expected_transaction = trans;
  2670. }
  2671. if (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS)
  2672. tx_flags = IEEE80211_TX_CTL_REQ_TX_STATUS |
  2673. IEEE80211_TX_INTFL_MLME_CONN_TX;
  2674. ieee80211_send_auth(sdata, trans, auth_data->algorithm, status,
  2675. auth_data->data, auth_data->data_len,
  2676. auth_data->bss->bssid,
  2677. auth_data->bss->bssid, NULL, 0, 0,
  2678. tx_flags);
  2679. } else {
  2680. const u8 *ssidie;
  2681. sdata_info(sdata, "direct probe to %pM (try %d/%i)\n",
  2682. auth_data->bss->bssid, auth_data->tries,
  2683. IEEE80211_AUTH_MAX_TRIES);
  2684. rcu_read_lock();
  2685. ssidie = ieee80211_bss_get_ie(auth_data->bss, WLAN_EID_SSID);
  2686. if (!ssidie) {
  2687. rcu_read_unlock();
  2688. return -EINVAL;
  2689. }
  2690. /*
  2691. * Direct probe is sent to broadcast address as some APs
  2692. * will not answer to direct packet in unassociated state.
  2693. */
  2694. ieee80211_send_probe_req(sdata, NULL, ssidie + 2, ssidie[1],
  2695. NULL, 0, (u32) -1, true, 0,
  2696. auth_data->bss->channel, false);
  2697. rcu_read_unlock();
  2698. }
  2699. if (tx_flags == 0) {
  2700. auth_data->timeout = jiffies + IEEE80211_AUTH_TIMEOUT;
  2701. auth_data->timeout_started = true;
  2702. run_again(sdata, auth_data->timeout);
  2703. } else {
  2704. auth_data->timeout =
  2705. round_jiffies_up(jiffies + IEEE80211_AUTH_TIMEOUT_LONG);
  2706. auth_data->timeout_started = true;
  2707. run_again(sdata, auth_data->timeout);
  2708. }
  2709. return 0;
  2710. }
  2711. static int ieee80211_do_assoc(struct ieee80211_sub_if_data *sdata)
  2712. {
  2713. struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data;
  2714. struct ieee80211_local *local = sdata->local;
  2715. sdata_assert_lock(sdata);
  2716. assoc_data->tries++;
  2717. if (assoc_data->tries > IEEE80211_ASSOC_MAX_TRIES) {
  2718. sdata_info(sdata, "association with %pM timed out\n",
  2719. assoc_data->bss->bssid);
  2720. /*
  2721. * Most likely AP is not in the range so remove the
  2722. * bss struct for that AP.
  2723. */
  2724. cfg80211_unlink_bss(local->hw.wiphy, assoc_data->bss);
  2725. return -ETIMEDOUT;
  2726. }
  2727. sdata_info(sdata, "associate with %pM (try %d/%d)\n",
  2728. assoc_data->bss->bssid, assoc_data->tries,
  2729. IEEE80211_ASSOC_MAX_TRIES);
  2730. ieee80211_send_assoc(sdata);
  2731. if (!(local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS)) {
  2732. assoc_data->timeout = jiffies + IEEE80211_ASSOC_TIMEOUT;
  2733. assoc_data->timeout_started = true;
  2734. run_again(sdata, assoc_data->timeout);
  2735. } else {
  2736. assoc_data->timeout =
  2737. round_jiffies_up(jiffies +
  2738. IEEE80211_ASSOC_TIMEOUT_LONG);
  2739. assoc_data->timeout_started = true;
  2740. run_again(sdata, assoc_data->timeout);
  2741. }
  2742. return 0;
  2743. }
  2744. void ieee80211_mgd_conn_tx_status(struct ieee80211_sub_if_data *sdata,
  2745. __le16 fc, bool acked)
  2746. {
  2747. struct ieee80211_local *local = sdata->local;
  2748. sdata->u.mgd.status_fc = fc;
  2749. sdata->u.mgd.status_acked = acked;
  2750. sdata->u.mgd.status_received = true;
  2751. ieee80211_queue_work(&local->hw, &sdata->work);
  2752. }
  2753. void ieee80211_sta_work(struct ieee80211_sub_if_data *sdata)
  2754. {
  2755. struct ieee80211_local *local = sdata->local;
  2756. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  2757. sdata_lock(sdata);
  2758. if (ifmgd->status_received) {
  2759. __le16 fc = ifmgd->status_fc;
  2760. bool status_acked = ifmgd->status_acked;
  2761. ifmgd->status_received = false;
  2762. if (ifmgd->auth_data &&
  2763. (ieee80211_is_probe_req(fc) || ieee80211_is_auth(fc))) {
  2764. if (status_acked) {
  2765. ifmgd->auth_data->timeout =
  2766. jiffies + IEEE80211_AUTH_TIMEOUT_SHORT;
  2767. run_again(sdata, ifmgd->auth_data->timeout);
  2768. } else {
  2769. ifmgd->auth_data->timeout = jiffies - 1;
  2770. }
  2771. ifmgd->auth_data->timeout_started = true;
  2772. } else if (ifmgd->assoc_data &&
  2773. (ieee80211_is_assoc_req(fc) ||
  2774. ieee80211_is_reassoc_req(fc))) {
  2775. if (status_acked) {
  2776. ifmgd->assoc_data->timeout =
  2777. jiffies + IEEE80211_ASSOC_TIMEOUT_SHORT;
  2778. run_again(sdata, ifmgd->assoc_data->timeout);
  2779. } else {
  2780. ifmgd->assoc_data->timeout = jiffies - 1;
  2781. }
  2782. ifmgd->assoc_data->timeout_started = true;
  2783. }
  2784. }
  2785. if (ifmgd->auth_data && ifmgd->auth_data->timeout_started &&
  2786. time_after(jiffies, ifmgd->auth_data->timeout)) {
  2787. if (ifmgd->auth_data->done) {
  2788. /*
  2789. * ok ... we waited for assoc but userspace didn't,
  2790. * so let's just kill the auth data
  2791. */
  2792. ieee80211_destroy_auth_data(sdata, false);
  2793. } else if (ieee80211_probe_auth(sdata)) {
  2794. u8 bssid[ETH_ALEN];
  2795. memcpy(bssid, ifmgd->auth_data->bss->bssid, ETH_ALEN);
  2796. ieee80211_destroy_auth_data(sdata, false);
  2797. cfg80211_auth_timeout(sdata->dev, bssid);
  2798. }
  2799. } else if (ifmgd->auth_data && ifmgd->auth_data->timeout_started)
  2800. run_again(sdata, ifmgd->auth_data->timeout);
  2801. if (ifmgd->assoc_data && ifmgd->assoc_data->timeout_started &&
  2802. time_after(jiffies, ifmgd->assoc_data->timeout)) {
  2803. if ((ifmgd->assoc_data->need_beacon && !ifmgd->have_beacon) ||
  2804. ieee80211_do_assoc(sdata)) {
  2805. struct cfg80211_bss *bss = ifmgd->assoc_data->bss;
  2806. ieee80211_destroy_assoc_data(sdata, false);
  2807. cfg80211_assoc_timeout(sdata->dev, bss);
  2808. }
  2809. } else if (ifmgd->assoc_data && ifmgd->assoc_data->timeout_started)
  2810. run_again(sdata, ifmgd->assoc_data->timeout);
  2811. if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL &&
  2812. ifmgd->associated) {
  2813. u8 bssid[ETH_ALEN];
  2814. int max_tries;
  2815. memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN);
  2816. if (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS)
  2817. max_tries = max_nullfunc_tries;
  2818. else
  2819. max_tries = max_probe_tries;
  2820. /* ACK received for nullfunc probing frame */
  2821. if (!ifmgd->probe_send_count)
  2822. ieee80211_reset_ap_probe(sdata);
  2823. else if (ifmgd->nullfunc_failed) {
  2824. if (ifmgd->probe_send_count < max_tries) {
  2825. mlme_dbg(sdata,
  2826. "No ack for nullfunc frame to AP %pM, try %d/%i\n",
  2827. bssid, ifmgd->probe_send_count,
  2828. max_tries);
  2829. ieee80211_mgd_probe_ap_send(sdata);
  2830. } else {
  2831. mlme_dbg(sdata,
  2832. "No ack for nullfunc frame to AP %pM, disconnecting.\n",
  2833. bssid);
  2834. ieee80211_sta_connection_lost(sdata, bssid,
  2835. WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
  2836. false);
  2837. }
  2838. } else if (time_is_after_jiffies(ifmgd->probe_timeout))
  2839. run_again(sdata, ifmgd->probe_timeout);
  2840. else if (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS) {
  2841. mlme_dbg(sdata,
  2842. "Failed to send nullfunc to AP %pM after %dms, disconnecting\n",
  2843. bssid, probe_wait_ms);
  2844. ieee80211_sta_connection_lost(sdata, bssid,
  2845. WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, false);
  2846. } else if (ifmgd->probe_send_count < max_tries) {
  2847. mlme_dbg(sdata,
  2848. "No probe response from AP %pM after %dms, try %d/%i\n",
  2849. bssid, probe_wait_ms,
  2850. ifmgd->probe_send_count, max_tries);
  2851. ieee80211_mgd_probe_ap_send(sdata);
  2852. } else {
  2853. /*
  2854. * We actually lost the connection ... or did we?
  2855. * Let's make sure!
  2856. */
  2857. wiphy_debug(local->hw.wiphy,
  2858. "%s: No probe response from AP %pM"
  2859. " after %dms, disconnecting.\n",
  2860. sdata->name,
  2861. bssid, probe_wait_ms);
  2862. ieee80211_sta_connection_lost(sdata, bssid,
  2863. WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, false);
  2864. }
  2865. }
  2866. sdata_unlock(sdata);
  2867. }
  2868. static void ieee80211_sta_bcn_mon_timer(unsigned long data)
  2869. {
  2870. struct ieee80211_sub_if_data *sdata =
  2871. (struct ieee80211_sub_if_data *) data;
  2872. struct ieee80211_local *local = sdata->local;
  2873. if (local->quiescing)
  2874. return;
  2875. sdata->u.mgd.connection_loss = false;
  2876. ieee80211_queue_work(&sdata->local->hw,
  2877. &sdata->u.mgd.beacon_connection_loss_work);
  2878. }
  2879. static void ieee80211_sta_conn_mon_timer(unsigned long data)
  2880. {
  2881. struct ieee80211_sub_if_data *sdata =
  2882. (struct ieee80211_sub_if_data *) data;
  2883. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  2884. struct ieee80211_local *local = sdata->local;
  2885. if (local->quiescing)
  2886. return;
  2887. ieee80211_queue_work(&local->hw, &ifmgd->monitor_work);
  2888. }
  2889. static void ieee80211_sta_monitor_work(struct work_struct *work)
  2890. {
  2891. struct ieee80211_sub_if_data *sdata =
  2892. container_of(work, struct ieee80211_sub_if_data,
  2893. u.mgd.monitor_work);
  2894. ieee80211_mgd_probe_ap(sdata, false);
  2895. }
  2896. static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data *sdata)
  2897. {
  2898. u32 flags;
  2899. if (sdata->vif.type == NL80211_IFTYPE_STATION) {
  2900. __ieee80211_stop_poll(sdata);
  2901. /* let's probe the connection once */
  2902. flags = sdata->local->hw.flags;
  2903. if (!(flags & IEEE80211_HW_CONNECTION_MONITOR))
  2904. ieee80211_queue_work(&sdata->local->hw,
  2905. &sdata->u.mgd.monitor_work);
  2906. /* and do all the other regular work too */
  2907. ieee80211_queue_work(&sdata->local->hw, &sdata->work);
  2908. }
  2909. }
  2910. #ifdef CONFIG_PM
  2911. void ieee80211_sta_restart(struct ieee80211_sub_if_data *sdata)
  2912. {
  2913. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  2914. sdata_lock(sdata);
  2915. if (!ifmgd->associated) {
  2916. sdata_unlock(sdata);
  2917. return;
  2918. }
  2919. if (sdata->flags & IEEE80211_SDATA_DISCONNECT_RESUME) {
  2920. sdata->flags &= ~IEEE80211_SDATA_DISCONNECT_RESUME;
  2921. mlme_dbg(sdata, "driver requested disconnect after resume\n");
  2922. ieee80211_sta_connection_lost(sdata,
  2923. ifmgd->associated->bssid,
  2924. WLAN_REASON_UNSPECIFIED,
  2925. true);
  2926. sdata_unlock(sdata);
  2927. return;
  2928. }
  2929. sdata_unlock(sdata);
  2930. }
  2931. #endif
  2932. /* interface setup */
  2933. void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata)
  2934. {
  2935. struct ieee80211_if_managed *ifmgd;
  2936. ifmgd = &sdata->u.mgd;
  2937. INIT_WORK(&ifmgd->monitor_work, ieee80211_sta_monitor_work);
  2938. INIT_WORK(&ifmgd->chswitch_work, ieee80211_chswitch_work);
  2939. INIT_WORK(&ifmgd->beacon_connection_loss_work,
  2940. ieee80211_beacon_connection_loss_work);
  2941. INIT_WORK(&ifmgd->csa_connection_drop_work,
  2942. ieee80211_csa_connection_drop_work);
  2943. INIT_WORK(&ifmgd->request_smps_work, ieee80211_request_smps_work);
  2944. setup_timer(&ifmgd->timer, ieee80211_sta_timer,
  2945. (unsigned long) sdata);
  2946. setup_timer(&ifmgd->bcn_mon_timer, ieee80211_sta_bcn_mon_timer,
  2947. (unsigned long) sdata);
  2948. setup_timer(&ifmgd->conn_mon_timer, ieee80211_sta_conn_mon_timer,
  2949. (unsigned long) sdata);
  2950. setup_timer(&ifmgd->chswitch_timer, ieee80211_chswitch_timer,
  2951. (unsigned long) sdata);
  2952. ifmgd->flags = 0;
  2953. ifmgd->powersave = sdata->wdev.ps;
  2954. ifmgd->uapsd_queues = sdata->local->hw.uapsd_queues;
  2955. ifmgd->uapsd_max_sp_len = sdata->local->hw.uapsd_max_sp_len;
  2956. ifmgd->p2p_noa_index = -1;
  2957. if (sdata->local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS)
  2958. ifmgd->req_smps = IEEE80211_SMPS_AUTOMATIC;
  2959. else
  2960. ifmgd->req_smps = IEEE80211_SMPS_OFF;
  2961. }
  2962. /* scan finished notification */
  2963. void ieee80211_mlme_notify_scan_completed(struct ieee80211_local *local)
  2964. {
  2965. struct ieee80211_sub_if_data *sdata;
  2966. /* Restart STA timers */
  2967. rcu_read_lock();
  2968. list_for_each_entry_rcu(sdata, &local->interfaces, list) {
  2969. if (ieee80211_sdata_running(sdata))
  2970. ieee80211_restart_sta_timer(sdata);
  2971. }
  2972. rcu_read_unlock();
  2973. }
  2974. int ieee80211_max_network_latency(struct notifier_block *nb,
  2975. unsigned long data, void *dummy)
  2976. {
  2977. s32 latency_usec = (s32) data;
  2978. struct ieee80211_local *local =
  2979. container_of(nb, struct ieee80211_local,
  2980. network_latency_notifier);
  2981. mutex_lock(&local->iflist_mtx);
  2982. ieee80211_recalc_ps(local, latency_usec);
  2983. mutex_unlock(&local->iflist_mtx);
  2984. return 0;
  2985. }
  2986. static u8 ieee80211_ht_vht_rx_chains(struct ieee80211_sub_if_data *sdata,
  2987. struct cfg80211_bss *cbss)
  2988. {
  2989. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  2990. const u8 *ht_cap_ie, *vht_cap_ie;
  2991. const struct ieee80211_ht_cap *ht_cap;
  2992. const struct ieee80211_vht_cap *vht_cap;
  2993. u8 chains = 1;
  2994. if (ifmgd->flags & IEEE80211_STA_DISABLE_HT)
  2995. return chains;
  2996. ht_cap_ie = ieee80211_bss_get_ie(cbss, WLAN_EID_HT_CAPABILITY);
  2997. if (ht_cap_ie && ht_cap_ie[1] >= sizeof(*ht_cap)) {
  2998. ht_cap = (void *)(ht_cap_ie + 2);
  2999. chains = ieee80211_mcs_to_chains(&ht_cap->mcs);
  3000. /*
  3001. * TODO: use "Tx Maximum Number Spatial Streams Supported" and
  3002. * "Tx Unequal Modulation Supported" fields.
  3003. */
  3004. }
  3005. if (ifmgd->flags & IEEE80211_STA_DISABLE_VHT)
  3006. return chains;
  3007. vht_cap_ie = ieee80211_bss_get_ie(cbss, WLAN_EID_VHT_CAPABILITY);
  3008. if (vht_cap_ie && vht_cap_ie[1] >= sizeof(*vht_cap)) {
  3009. u8 nss;
  3010. u16 tx_mcs_map;
  3011. vht_cap = (void *)(vht_cap_ie + 2);
  3012. tx_mcs_map = le16_to_cpu(vht_cap->supp_mcs.tx_mcs_map);
  3013. for (nss = 8; nss > 0; nss--) {
  3014. if (((tx_mcs_map >> (2 * (nss - 1))) & 3) !=
  3015. IEEE80211_VHT_MCS_NOT_SUPPORTED)
  3016. break;
  3017. }
  3018. /* TODO: use "Tx Highest Supported Long GI Data Rate" field? */
  3019. chains = max(chains, nss);
  3020. }
  3021. return chains;
  3022. }
  3023. static int ieee80211_prep_channel(struct ieee80211_sub_if_data *sdata,
  3024. struct cfg80211_bss *cbss)
  3025. {
  3026. struct ieee80211_local *local = sdata->local;
  3027. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  3028. const struct ieee80211_ht_operation *ht_oper = NULL;
  3029. const struct ieee80211_vht_operation *vht_oper = NULL;
  3030. struct ieee80211_supported_band *sband;
  3031. struct cfg80211_chan_def chandef;
  3032. int ret;
  3033. sband = local->hw.wiphy->bands[cbss->channel->band];
  3034. ifmgd->flags &= ~(IEEE80211_STA_DISABLE_40MHZ |
  3035. IEEE80211_STA_DISABLE_80P80MHZ |
  3036. IEEE80211_STA_DISABLE_160MHZ);
  3037. rcu_read_lock();
  3038. if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT) &&
  3039. sband->ht_cap.ht_supported) {
  3040. const u8 *ht_oper_ie, *ht_cap;
  3041. ht_oper_ie = ieee80211_bss_get_ie(cbss, WLAN_EID_HT_OPERATION);
  3042. if (ht_oper_ie && ht_oper_ie[1] >= sizeof(*ht_oper))
  3043. ht_oper = (void *)(ht_oper_ie + 2);
  3044. ht_cap = ieee80211_bss_get_ie(cbss, WLAN_EID_HT_CAPABILITY);
  3045. if (!ht_cap || ht_cap[1] < sizeof(struct ieee80211_ht_cap)) {
  3046. ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
  3047. ht_oper = NULL;
  3048. }
  3049. }
  3050. if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) &&
  3051. sband->vht_cap.vht_supported) {
  3052. const u8 *vht_oper_ie, *vht_cap;
  3053. vht_oper_ie = ieee80211_bss_get_ie(cbss,
  3054. WLAN_EID_VHT_OPERATION);
  3055. if (vht_oper_ie && vht_oper_ie[1] >= sizeof(*vht_oper))
  3056. vht_oper = (void *)(vht_oper_ie + 2);
  3057. if (vht_oper && !ht_oper) {
  3058. vht_oper = NULL;
  3059. sdata_info(sdata,
  3060. "AP advertised VHT without HT, disabling both\n");
  3061. ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
  3062. ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
  3063. }
  3064. vht_cap = ieee80211_bss_get_ie(cbss, WLAN_EID_VHT_CAPABILITY);
  3065. if (!vht_cap || vht_cap[1] < sizeof(struct ieee80211_vht_cap)) {
  3066. ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
  3067. vht_oper = NULL;
  3068. }
  3069. }
  3070. ifmgd->flags |= ieee80211_determine_chantype(sdata, sband,
  3071. cbss->channel,
  3072. ht_oper, vht_oper,
  3073. &chandef, false);
  3074. sdata->needed_rx_chains = min(ieee80211_ht_vht_rx_chains(sdata, cbss),
  3075. local->rx_chains);
  3076. rcu_read_unlock();
  3077. /* will change later if needed */
  3078. sdata->smps_mode = IEEE80211_SMPS_OFF;
  3079. /*
  3080. * If this fails (possibly due to channel context sharing
  3081. * on incompatible channels, e.g. 80+80 and 160 sharing the
  3082. * same control channel) try to use a smaller bandwidth.
  3083. */
  3084. ret = ieee80211_vif_use_channel(sdata, &chandef,
  3085. IEEE80211_CHANCTX_SHARED);
  3086. /* don't downgrade for 5 and 10 MHz channels, though. */
  3087. if (chandef.width == NL80211_CHAN_WIDTH_5 ||
  3088. chandef.width == NL80211_CHAN_WIDTH_10)
  3089. return ret;
  3090. while (ret && chandef.width != NL80211_CHAN_WIDTH_20_NOHT) {
  3091. ifmgd->flags |= ieee80211_chandef_downgrade(&chandef);
  3092. ret = ieee80211_vif_use_channel(sdata, &chandef,
  3093. IEEE80211_CHANCTX_SHARED);
  3094. }
  3095. return ret;
  3096. }
  3097. static int ieee80211_prep_connection(struct ieee80211_sub_if_data *sdata,
  3098. struct cfg80211_bss *cbss, bool assoc)
  3099. {
  3100. struct ieee80211_local *local = sdata->local;
  3101. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  3102. struct ieee80211_bss *bss = (void *)cbss->priv;
  3103. struct sta_info *new_sta = NULL;
  3104. bool have_sta = false;
  3105. int err;
  3106. if (WARN_ON(!ifmgd->auth_data && !ifmgd->assoc_data))
  3107. return -EINVAL;
  3108. if (assoc) {
  3109. rcu_read_lock();
  3110. have_sta = sta_info_get(sdata, cbss->bssid);
  3111. rcu_read_unlock();
  3112. }
  3113. if (!have_sta) {
  3114. new_sta = sta_info_alloc(sdata, cbss->bssid, GFP_KERNEL);
  3115. if (!new_sta)
  3116. return -ENOMEM;
  3117. }
  3118. if (new_sta) {
  3119. u32 rates = 0, basic_rates = 0;
  3120. bool have_higher_than_11mbit;
  3121. int min_rate = INT_MAX, min_rate_index = -1;
  3122. struct ieee80211_chanctx_conf *chanctx_conf;
  3123. struct ieee80211_supported_band *sband;
  3124. const struct cfg80211_bss_ies *ies;
  3125. int shift;
  3126. u32 rate_flags;
  3127. sband = local->hw.wiphy->bands[cbss->channel->band];
  3128. err = ieee80211_prep_channel(sdata, cbss);
  3129. if (err) {
  3130. sta_info_free(local, new_sta);
  3131. return -EINVAL;
  3132. }
  3133. shift = ieee80211_vif_get_shift(&sdata->vif);
  3134. rcu_read_lock();
  3135. chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
  3136. if (WARN_ON(!chanctx_conf)) {
  3137. rcu_read_unlock();
  3138. return -EINVAL;
  3139. }
  3140. rate_flags = ieee80211_chandef_rate_flags(&chanctx_conf->def);
  3141. rcu_read_unlock();
  3142. ieee80211_get_rates(sband, bss->supp_rates,
  3143. bss->supp_rates_len,
  3144. &rates, &basic_rates,
  3145. &have_higher_than_11mbit,
  3146. &min_rate, &min_rate_index,
  3147. shift, rate_flags);
  3148. /*
  3149. * This used to be a workaround for basic rates missing
  3150. * in the association response frame. Now that we no
  3151. * longer use the basic rates from there, it probably
  3152. * doesn't happen any more, but keep the workaround so
  3153. * in case some *other* APs are buggy in different ways
  3154. * we can connect -- with a warning.
  3155. */
  3156. if (!basic_rates && min_rate_index >= 0) {
  3157. sdata_info(sdata,
  3158. "No basic rates, using min rate instead\n");
  3159. basic_rates = BIT(min_rate_index);
  3160. }
  3161. new_sta->sta.supp_rates[cbss->channel->band] = rates;
  3162. sdata->vif.bss_conf.basic_rates = basic_rates;
  3163. /* cf. IEEE 802.11 9.2.12 */
  3164. if (cbss->channel->band == IEEE80211_BAND_2GHZ &&
  3165. have_higher_than_11mbit)
  3166. sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE;
  3167. else
  3168. sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE;
  3169. memcpy(ifmgd->bssid, cbss->bssid, ETH_ALEN);
  3170. /* set timing information */
  3171. sdata->vif.bss_conf.beacon_int = cbss->beacon_interval;
  3172. rcu_read_lock();
  3173. ies = rcu_dereference(cbss->beacon_ies);
  3174. if (ies) {
  3175. const u8 *tim_ie;
  3176. sdata->vif.bss_conf.sync_tsf = ies->tsf;
  3177. sdata->vif.bss_conf.sync_device_ts =
  3178. bss->device_ts_beacon;
  3179. tim_ie = cfg80211_find_ie(WLAN_EID_TIM,
  3180. ies->data, ies->len);
  3181. if (tim_ie && tim_ie[1] >= 2)
  3182. sdata->vif.bss_conf.sync_dtim_count = tim_ie[2];
  3183. else
  3184. sdata->vif.bss_conf.sync_dtim_count = 0;
  3185. } else if (!(local->hw.flags &
  3186. IEEE80211_HW_TIMING_BEACON_ONLY)) {
  3187. ies = rcu_dereference(cbss->proberesp_ies);
  3188. /* must be non-NULL since beacon IEs were NULL */
  3189. sdata->vif.bss_conf.sync_tsf = ies->tsf;
  3190. sdata->vif.bss_conf.sync_device_ts =
  3191. bss->device_ts_presp;
  3192. sdata->vif.bss_conf.sync_dtim_count = 0;
  3193. } else {
  3194. sdata->vif.bss_conf.sync_tsf = 0;
  3195. sdata->vif.bss_conf.sync_device_ts = 0;
  3196. sdata->vif.bss_conf.sync_dtim_count = 0;
  3197. }
  3198. rcu_read_unlock();
  3199. /* tell driver about BSSID, basic rates and timing */
  3200. ieee80211_bss_info_change_notify(sdata,
  3201. BSS_CHANGED_BSSID | BSS_CHANGED_BASIC_RATES |
  3202. BSS_CHANGED_BEACON_INT);
  3203. if (assoc)
  3204. sta_info_pre_move_state(new_sta, IEEE80211_STA_AUTH);
  3205. err = sta_info_insert(new_sta);
  3206. new_sta = NULL;
  3207. if (err) {
  3208. sdata_info(sdata,
  3209. "failed to insert STA entry for the AP (error %d)\n",
  3210. err);
  3211. return err;
  3212. }
  3213. } else
  3214. WARN_ON_ONCE(!ether_addr_equal(ifmgd->bssid, cbss->bssid));
  3215. return 0;
  3216. }
  3217. /* config hooks */
  3218. int ieee80211_mgd_auth(struct ieee80211_sub_if_data *sdata,
  3219. struct cfg80211_auth_request *req)
  3220. {
  3221. struct ieee80211_local *local = sdata->local;
  3222. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  3223. struct ieee80211_mgd_auth_data *auth_data;
  3224. u16 auth_alg;
  3225. int err;
  3226. /* prepare auth data structure */
  3227. switch (req->auth_type) {
  3228. case NL80211_AUTHTYPE_OPEN_SYSTEM:
  3229. auth_alg = WLAN_AUTH_OPEN;
  3230. break;
  3231. case NL80211_AUTHTYPE_SHARED_KEY:
  3232. if (IS_ERR(local->wep_tx_tfm))
  3233. return -EOPNOTSUPP;
  3234. auth_alg = WLAN_AUTH_SHARED_KEY;
  3235. break;
  3236. case NL80211_AUTHTYPE_FT:
  3237. auth_alg = WLAN_AUTH_FT;
  3238. break;
  3239. case NL80211_AUTHTYPE_NETWORK_EAP:
  3240. auth_alg = WLAN_AUTH_LEAP;
  3241. break;
  3242. case NL80211_AUTHTYPE_SAE:
  3243. auth_alg = WLAN_AUTH_SAE;
  3244. break;
  3245. default:
  3246. return -EOPNOTSUPP;
  3247. }
  3248. auth_data = kzalloc(sizeof(*auth_data) + req->sae_data_len +
  3249. req->ie_len, GFP_KERNEL);
  3250. if (!auth_data)
  3251. return -ENOMEM;
  3252. auth_data->bss = req->bss;
  3253. if (req->sae_data_len >= 4) {
  3254. __le16 *pos = (__le16 *) req->sae_data;
  3255. auth_data->sae_trans = le16_to_cpu(pos[0]);
  3256. auth_data->sae_status = le16_to_cpu(pos[1]);
  3257. memcpy(auth_data->data, req->sae_data + 4,
  3258. req->sae_data_len - 4);
  3259. auth_data->data_len += req->sae_data_len - 4;
  3260. }
  3261. if (req->ie && req->ie_len) {
  3262. memcpy(&auth_data->data[auth_data->data_len],
  3263. req->ie, req->ie_len);
  3264. auth_data->data_len += req->ie_len;
  3265. }
  3266. if (req->key && req->key_len) {
  3267. auth_data->key_len = req->key_len;
  3268. auth_data->key_idx = req->key_idx;
  3269. memcpy(auth_data->key, req->key, req->key_len);
  3270. }
  3271. auth_data->algorithm = auth_alg;
  3272. /* try to authenticate/probe */
  3273. if ((ifmgd->auth_data && !ifmgd->auth_data->done) ||
  3274. ifmgd->assoc_data) {
  3275. err = -EBUSY;
  3276. goto err_free;
  3277. }
  3278. if (ifmgd->auth_data)
  3279. ieee80211_destroy_auth_data(sdata, false);
  3280. /* prep auth_data so we don't go into idle on disassoc */
  3281. ifmgd->auth_data = auth_data;
  3282. if (ifmgd->associated) {
  3283. u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
  3284. ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
  3285. WLAN_REASON_UNSPECIFIED,
  3286. false, frame_buf);
  3287. cfg80211_tx_mlme_mgmt(sdata->dev, frame_buf,
  3288. sizeof(frame_buf));
  3289. }
  3290. sdata_info(sdata, "authenticate with %pM\n", req->bss->bssid);
  3291. err = ieee80211_prep_connection(sdata, req->bss, false);
  3292. if (err)
  3293. goto err_clear;
  3294. err = ieee80211_probe_auth(sdata);
  3295. if (err) {
  3296. sta_info_destroy_addr(sdata, req->bss->bssid);
  3297. goto err_clear;
  3298. }
  3299. /* hold our own reference */
  3300. cfg80211_ref_bss(local->hw.wiphy, auth_data->bss);
  3301. return 0;
  3302. err_clear:
  3303. memset(ifmgd->bssid, 0, ETH_ALEN);
  3304. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
  3305. ifmgd->auth_data = NULL;
  3306. err_free:
  3307. kfree(auth_data);
  3308. return err;
  3309. }
  3310. int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata,
  3311. struct cfg80211_assoc_request *req)
  3312. {
  3313. struct ieee80211_local *local = sdata->local;
  3314. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  3315. struct ieee80211_bss *bss = (void *)req->bss->priv;
  3316. struct ieee80211_mgd_assoc_data *assoc_data;
  3317. const struct cfg80211_bss_ies *beacon_ies;
  3318. struct ieee80211_supported_band *sband;
  3319. const u8 *ssidie, *ht_ie, *vht_ie;
  3320. int i, err;
  3321. assoc_data = kzalloc(sizeof(*assoc_data) + req->ie_len, GFP_KERNEL);
  3322. if (!assoc_data)
  3323. return -ENOMEM;
  3324. rcu_read_lock();
  3325. ssidie = ieee80211_bss_get_ie(req->bss, WLAN_EID_SSID);
  3326. if (!ssidie) {
  3327. rcu_read_unlock();
  3328. kfree(assoc_data);
  3329. return -EINVAL;
  3330. }
  3331. memcpy(assoc_data->ssid, ssidie + 2, ssidie[1]);
  3332. assoc_data->ssid_len = ssidie[1];
  3333. rcu_read_unlock();
  3334. if (ifmgd->associated) {
  3335. u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
  3336. ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
  3337. WLAN_REASON_UNSPECIFIED,
  3338. false, frame_buf);
  3339. cfg80211_tx_mlme_mgmt(sdata->dev, frame_buf,
  3340. sizeof(frame_buf));
  3341. }
  3342. if (ifmgd->auth_data && !ifmgd->auth_data->done) {
  3343. err = -EBUSY;
  3344. goto err_free;
  3345. }
  3346. if (ifmgd->assoc_data) {
  3347. err = -EBUSY;
  3348. goto err_free;
  3349. }
  3350. if (ifmgd->auth_data) {
  3351. bool match;
  3352. /* keep sta info, bssid if matching */
  3353. match = ether_addr_equal(ifmgd->bssid, req->bss->bssid);
  3354. ieee80211_destroy_auth_data(sdata, match);
  3355. }
  3356. /* prepare assoc data */
  3357. ifmgd->beacon_crc_valid = false;
  3358. /*
  3359. * IEEE802.11n does not allow TKIP/WEP as pairwise ciphers in HT mode.
  3360. * We still associate in non-HT mode (11a/b/g) if any one of these
  3361. * ciphers is configured as pairwise.
  3362. * We can set this to true for non-11n hardware, that'll be checked
  3363. * separately along with the peer capabilities.
  3364. */
  3365. for (i = 0; i < req->crypto.n_ciphers_pairwise; i++) {
  3366. if (req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP40 ||
  3367. req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_TKIP ||
  3368. req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP104) {
  3369. ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
  3370. ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
  3371. netdev_info(sdata->dev,
  3372. "disabling HT/VHT due to WEP/TKIP use\n");
  3373. }
  3374. }
  3375. if (req->flags & ASSOC_REQ_DISABLE_HT) {
  3376. ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
  3377. ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
  3378. }
  3379. if (req->flags & ASSOC_REQ_DISABLE_VHT)
  3380. ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
  3381. /* Also disable HT if we don't support it or the AP doesn't use WMM */
  3382. sband = local->hw.wiphy->bands[req->bss->channel->band];
  3383. if (!sband->ht_cap.ht_supported ||
  3384. local->hw.queues < IEEE80211_NUM_ACS || !bss->wmm_used) {
  3385. ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
  3386. if (!bss->wmm_used)
  3387. netdev_info(sdata->dev,
  3388. "disabling HT as WMM/QoS is not supported by the AP\n");
  3389. }
  3390. /* disable VHT if we don't support it or the AP doesn't use WMM */
  3391. if (!sband->vht_cap.vht_supported ||
  3392. local->hw.queues < IEEE80211_NUM_ACS || !bss->wmm_used) {
  3393. ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
  3394. if (!bss->wmm_used)
  3395. netdev_info(sdata->dev,
  3396. "disabling VHT as WMM/QoS is not supported by the AP\n");
  3397. }
  3398. memcpy(&ifmgd->ht_capa, &req->ht_capa, sizeof(ifmgd->ht_capa));
  3399. memcpy(&ifmgd->ht_capa_mask, &req->ht_capa_mask,
  3400. sizeof(ifmgd->ht_capa_mask));
  3401. memcpy(&ifmgd->vht_capa, &req->vht_capa, sizeof(ifmgd->vht_capa));
  3402. memcpy(&ifmgd->vht_capa_mask, &req->vht_capa_mask,
  3403. sizeof(ifmgd->vht_capa_mask));
  3404. if (req->ie && req->ie_len) {
  3405. memcpy(assoc_data->ie, req->ie, req->ie_len);
  3406. assoc_data->ie_len = req->ie_len;
  3407. }
  3408. assoc_data->bss = req->bss;
  3409. if (ifmgd->req_smps == IEEE80211_SMPS_AUTOMATIC) {
  3410. if (ifmgd->powersave)
  3411. sdata->smps_mode = IEEE80211_SMPS_DYNAMIC;
  3412. else
  3413. sdata->smps_mode = IEEE80211_SMPS_OFF;
  3414. } else
  3415. sdata->smps_mode = ifmgd->req_smps;
  3416. assoc_data->capability = req->bss->capability;
  3417. assoc_data->wmm = bss->wmm_used &&
  3418. (local->hw.queues >= IEEE80211_NUM_ACS);
  3419. assoc_data->supp_rates = bss->supp_rates;
  3420. assoc_data->supp_rates_len = bss->supp_rates_len;
  3421. rcu_read_lock();
  3422. ht_ie = ieee80211_bss_get_ie(req->bss, WLAN_EID_HT_OPERATION);
  3423. if (ht_ie && ht_ie[1] >= sizeof(struct ieee80211_ht_operation))
  3424. assoc_data->ap_ht_param =
  3425. ((struct ieee80211_ht_operation *)(ht_ie + 2))->ht_param;
  3426. else
  3427. ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
  3428. vht_ie = ieee80211_bss_get_ie(req->bss, WLAN_EID_VHT_CAPABILITY);
  3429. if (vht_ie && vht_ie[1] >= sizeof(struct ieee80211_vht_cap))
  3430. memcpy(&assoc_data->ap_vht_cap, vht_ie + 2,
  3431. sizeof(struct ieee80211_vht_cap));
  3432. else
  3433. ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
  3434. rcu_read_unlock();
  3435. if (bss->wmm_used && bss->uapsd_supported &&
  3436. (sdata->local->hw.flags & IEEE80211_HW_SUPPORTS_UAPSD) &&
  3437. sdata->wmm_acm != 0xff) {
  3438. assoc_data->uapsd = true;
  3439. ifmgd->flags |= IEEE80211_STA_UAPSD_ENABLED;
  3440. } else {
  3441. assoc_data->uapsd = false;
  3442. ifmgd->flags &= ~IEEE80211_STA_UAPSD_ENABLED;
  3443. }
  3444. if (req->prev_bssid)
  3445. memcpy(assoc_data->prev_bssid, req->prev_bssid, ETH_ALEN);
  3446. if (req->use_mfp) {
  3447. ifmgd->mfp = IEEE80211_MFP_REQUIRED;
  3448. ifmgd->flags |= IEEE80211_STA_MFP_ENABLED;
  3449. } else {
  3450. ifmgd->mfp = IEEE80211_MFP_DISABLED;
  3451. ifmgd->flags &= ~IEEE80211_STA_MFP_ENABLED;
  3452. }
  3453. if (req->crypto.control_port)
  3454. ifmgd->flags |= IEEE80211_STA_CONTROL_PORT;
  3455. else
  3456. ifmgd->flags &= ~IEEE80211_STA_CONTROL_PORT;
  3457. sdata->control_port_protocol = req->crypto.control_port_ethertype;
  3458. sdata->control_port_no_encrypt = req->crypto.control_port_no_encrypt;
  3459. /* kick off associate process */
  3460. ifmgd->assoc_data = assoc_data;
  3461. ifmgd->dtim_period = 0;
  3462. ifmgd->have_beacon = false;
  3463. err = ieee80211_prep_connection(sdata, req->bss, true);
  3464. if (err)
  3465. goto err_clear;
  3466. rcu_read_lock();
  3467. beacon_ies = rcu_dereference(req->bss->beacon_ies);
  3468. if (sdata->local->hw.flags & IEEE80211_HW_NEED_DTIM_BEFORE_ASSOC &&
  3469. !beacon_ies) {
  3470. /*
  3471. * Wait up to one beacon interval ...
  3472. * should this be more if we miss one?
  3473. */
  3474. sdata_info(sdata, "waiting for beacon from %pM\n",
  3475. ifmgd->bssid);
  3476. assoc_data->timeout = TU_TO_EXP_TIME(req->bss->beacon_interval);
  3477. assoc_data->timeout_started = true;
  3478. assoc_data->need_beacon = true;
  3479. } else if (beacon_ies) {
  3480. const u8 *tim_ie = cfg80211_find_ie(WLAN_EID_TIM,
  3481. beacon_ies->data,
  3482. beacon_ies->len);
  3483. u8 dtim_count = 0;
  3484. if (tim_ie && tim_ie[1] >= sizeof(struct ieee80211_tim_ie)) {
  3485. const struct ieee80211_tim_ie *tim;
  3486. tim = (void *)(tim_ie + 2);
  3487. ifmgd->dtim_period = tim->dtim_period;
  3488. dtim_count = tim->dtim_count;
  3489. }
  3490. ifmgd->have_beacon = true;
  3491. assoc_data->timeout = jiffies;
  3492. assoc_data->timeout_started = true;
  3493. if (local->hw.flags & IEEE80211_HW_TIMING_BEACON_ONLY) {
  3494. sdata->vif.bss_conf.sync_tsf = beacon_ies->tsf;
  3495. sdata->vif.bss_conf.sync_device_ts =
  3496. bss->device_ts_beacon;
  3497. sdata->vif.bss_conf.sync_dtim_count = dtim_count;
  3498. }
  3499. } else {
  3500. assoc_data->timeout = jiffies;
  3501. assoc_data->timeout_started = true;
  3502. }
  3503. rcu_read_unlock();
  3504. run_again(sdata, assoc_data->timeout);
  3505. if (bss->corrupt_data) {
  3506. char *corrupt_type = "data";
  3507. if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_BEACON) {
  3508. if (bss->corrupt_data &
  3509. IEEE80211_BSS_CORRUPT_PROBE_RESP)
  3510. corrupt_type = "beacon and probe response";
  3511. else
  3512. corrupt_type = "beacon";
  3513. } else if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_PROBE_RESP)
  3514. corrupt_type = "probe response";
  3515. sdata_info(sdata, "associating with AP with corrupt %s\n",
  3516. corrupt_type);
  3517. }
  3518. return 0;
  3519. err_clear:
  3520. memset(ifmgd->bssid, 0, ETH_ALEN);
  3521. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
  3522. ifmgd->assoc_data = NULL;
  3523. err_free:
  3524. kfree(assoc_data);
  3525. return err;
  3526. }
  3527. int ieee80211_mgd_deauth(struct ieee80211_sub_if_data *sdata,
  3528. struct cfg80211_deauth_request *req)
  3529. {
  3530. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  3531. u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
  3532. bool tx = !req->local_state_change;
  3533. bool report_frame = false;
  3534. sdata_info(sdata,
  3535. "deauthenticating from %pM by local choice (reason=%d)\n",
  3536. req->bssid, req->reason_code);
  3537. if (ifmgd->auth_data) {
  3538. drv_mgd_prepare_tx(sdata->local, sdata);
  3539. ieee80211_send_deauth_disassoc(sdata, req->bssid,
  3540. IEEE80211_STYPE_DEAUTH,
  3541. req->reason_code, tx,
  3542. frame_buf);
  3543. ieee80211_destroy_auth_data(sdata, false);
  3544. report_frame = true;
  3545. goto out;
  3546. }
  3547. if (ifmgd->associated &&
  3548. ether_addr_equal(ifmgd->associated->bssid, req->bssid)) {
  3549. ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
  3550. req->reason_code, tx, frame_buf);
  3551. report_frame = true;
  3552. }
  3553. out:
  3554. if (report_frame)
  3555. cfg80211_tx_mlme_mgmt(sdata->dev, frame_buf,
  3556. IEEE80211_DEAUTH_FRAME_LEN);
  3557. return 0;
  3558. }
  3559. int ieee80211_mgd_disassoc(struct ieee80211_sub_if_data *sdata,
  3560. struct cfg80211_disassoc_request *req)
  3561. {
  3562. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  3563. u8 bssid[ETH_ALEN];
  3564. u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
  3565. /*
  3566. * cfg80211 should catch this ... but it's racy since
  3567. * we can receive a disassoc frame, process it, hand it
  3568. * to cfg80211 while that's in a locked section already
  3569. * trying to tell us that the user wants to disconnect.
  3570. */
  3571. if (ifmgd->associated != req->bss)
  3572. return -ENOLINK;
  3573. sdata_info(sdata,
  3574. "disassociating from %pM by local choice (reason=%d)\n",
  3575. req->bss->bssid, req->reason_code);
  3576. memcpy(bssid, req->bss->bssid, ETH_ALEN);
  3577. ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DISASSOC,
  3578. req->reason_code, !req->local_state_change,
  3579. frame_buf);
  3580. cfg80211_tx_mlme_mgmt(sdata->dev, frame_buf,
  3581. IEEE80211_DEAUTH_FRAME_LEN);
  3582. return 0;
  3583. }
  3584. void ieee80211_mgd_stop(struct ieee80211_sub_if_data *sdata)
  3585. {
  3586. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  3587. /*
  3588. * Make sure some work items will not run after this,
  3589. * they will not do anything but might not have been
  3590. * cancelled when disconnecting.
  3591. */
  3592. cancel_work_sync(&ifmgd->monitor_work);
  3593. cancel_work_sync(&ifmgd->beacon_connection_loss_work);
  3594. cancel_work_sync(&ifmgd->request_smps_work);
  3595. cancel_work_sync(&ifmgd->csa_connection_drop_work);
  3596. cancel_work_sync(&ifmgd->chswitch_work);
  3597. sdata_lock(sdata);
  3598. if (ifmgd->assoc_data) {
  3599. struct cfg80211_bss *bss = ifmgd->assoc_data->bss;
  3600. ieee80211_destroy_assoc_data(sdata, false);
  3601. cfg80211_assoc_timeout(sdata->dev, bss);
  3602. }
  3603. if (ifmgd->auth_data)
  3604. ieee80211_destroy_auth_data(sdata, false);
  3605. del_timer_sync(&ifmgd->timer);
  3606. sdata_unlock(sdata);
  3607. }
  3608. void ieee80211_cqm_rssi_notify(struct ieee80211_vif *vif,
  3609. enum nl80211_cqm_rssi_threshold_event rssi_event,
  3610. gfp_t gfp)
  3611. {
  3612. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  3613. trace_api_cqm_rssi_notify(sdata, rssi_event);
  3614. cfg80211_cqm_rssi_notify(sdata->dev, rssi_event, gfp);
  3615. }
  3616. EXPORT_SYMBOL(ieee80211_cqm_rssi_notify);