mlme.c 79 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854
  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/rtnetlink.h>
  19. #include <linux/pm_qos.h>
  20. #include <linux/crc32.h>
  21. #include <linux/slab.h>
  22. #include <net/mac80211.h>
  23. #include <asm/unaligned.h>
  24. #include "ieee80211_i.h"
  25. #include "driver-ops.h"
  26. #include "rate.h"
  27. #include "led.h"
  28. static int max_nullfunc_tries = 2;
  29. module_param(max_nullfunc_tries, int, 0644);
  30. MODULE_PARM_DESC(max_nullfunc_tries,
  31. "Maximum nullfunc tx tries before disconnecting (reason 4).");
  32. static int max_probe_tries = 5;
  33. module_param(max_probe_tries, int, 0644);
  34. MODULE_PARM_DESC(max_probe_tries,
  35. "Maximum probe tries before disconnecting (reason 4).");
  36. /*
  37. * Beacon loss timeout is calculated as N frames times the
  38. * advertised beacon interval. This may need to be somewhat
  39. * higher than what hardware might detect to account for
  40. * delays in the host processing frames. But since we also
  41. * probe on beacon miss before declaring the connection lost
  42. * default to what we want.
  43. */
  44. #define IEEE80211_BEACON_LOSS_COUNT 7
  45. /*
  46. * Time the connection can be idle before we probe
  47. * it to see if we can still talk to the AP.
  48. */
  49. #define IEEE80211_CONNECTION_IDLE_TIME (30 * HZ)
  50. /*
  51. * Time we wait for a probe response after sending
  52. * a probe request because of beacon loss or for
  53. * checking the connection still works.
  54. */
  55. static int probe_wait_ms = 500;
  56. module_param(probe_wait_ms, int, 0644);
  57. MODULE_PARM_DESC(probe_wait_ms,
  58. "Maximum time(ms) to wait for probe response"
  59. " before disconnecting (reason 4).");
  60. /*
  61. * Weight given to the latest Beacon frame when calculating average signal
  62. * strength for Beacon frames received in the current BSS. This must be
  63. * between 1 and 15.
  64. */
  65. #define IEEE80211_SIGNAL_AVE_WEIGHT 3
  66. /*
  67. * How many Beacon frames need to have been used in average signal strength
  68. * before starting to indicate signal change events.
  69. */
  70. #define IEEE80211_SIGNAL_AVE_MIN_COUNT 4
  71. #define TMR_RUNNING_TIMER 0
  72. #define TMR_RUNNING_CHANSW 1
  73. /*
  74. * All cfg80211 functions have to be called outside a locked
  75. * section so that they can acquire a lock themselves... This
  76. * is much simpler than queuing up things in cfg80211, but we
  77. * do need some indirection for that here.
  78. */
  79. enum rx_mgmt_action {
  80. /* no action required */
  81. RX_MGMT_NONE,
  82. /* caller must call cfg80211_send_deauth() */
  83. RX_MGMT_CFG80211_DEAUTH,
  84. /* caller must call cfg80211_send_disassoc() */
  85. RX_MGMT_CFG80211_DISASSOC,
  86. };
  87. /* utils */
  88. static inline void ASSERT_MGD_MTX(struct ieee80211_if_managed *ifmgd)
  89. {
  90. lockdep_assert_held(&ifmgd->mtx);
  91. }
  92. /*
  93. * We can have multiple work items (and connection probing)
  94. * scheduling this timer, but we need to take care to only
  95. * reschedule it when it should fire _earlier_ than it was
  96. * asked for before, or if it's not pending right now. This
  97. * function ensures that. Note that it then is required to
  98. * run this function for all timeouts after the first one
  99. * has happened -- the work that runs from this timer will
  100. * do that.
  101. */
  102. static void run_again(struct ieee80211_if_managed *ifmgd,
  103. unsigned long timeout)
  104. {
  105. ASSERT_MGD_MTX(ifmgd);
  106. if (!timer_pending(&ifmgd->timer) ||
  107. time_before(timeout, ifmgd->timer.expires))
  108. mod_timer(&ifmgd->timer, timeout);
  109. }
  110. void ieee80211_sta_reset_beacon_monitor(struct ieee80211_sub_if_data *sdata)
  111. {
  112. if (sdata->local->hw.flags & IEEE80211_HW_BEACON_FILTER)
  113. return;
  114. mod_timer(&sdata->u.mgd.bcn_mon_timer,
  115. round_jiffies_up(jiffies + sdata->u.mgd.beacon_timeout));
  116. }
  117. void ieee80211_sta_reset_conn_monitor(struct ieee80211_sub_if_data *sdata)
  118. {
  119. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  120. if (unlikely(!sdata->u.mgd.associated))
  121. return;
  122. if (sdata->local->hw.flags & IEEE80211_HW_CONNECTION_MONITOR)
  123. return;
  124. mod_timer(&sdata->u.mgd.conn_mon_timer,
  125. round_jiffies_up(jiffies + IEEE80211_CONNECTION_IDLE_TIME));
  126. ifmgd->probe_send_count = 0;
  127. }
  128. static int ecw2cw(int ecw)
  129. {
  130. return (1 << ecw) - 1;
  131. }
  132. /*
  133. * ieee80211_enable_ht should be called only after the operating band
  134. * has been determined as ht configuration depends on the hw's
  135. * HT abilities for a specific band.
  136. */
  137. static u32 ieee80211_enable_ht(struct ieee80211_sub_if_data *sdata,
  138. struct ieee80211_ht_info *hti,
  139. const u8 *bssid, u16 ap_ht_cap_flags,
  140. bool beacon_htcap_ie)
  141. {
  142. struct ieee80211_local *local = sdata->local;
  143. struct ieee80211_supported_band *sband;
  144. struct sta_info *sta;
  145. u32 changed = 0;
  146. int hti_cfreq;
  147. u16 ht_opmode;
  148. bool enable_ht = true;
  149. enum nl80211_channel_type prev_chantype;
  150. enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
  151. sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
  152. prev_chantype = sdata->vif.bss_conf.channel_type;
  153. /* HT is not supported */
  154. if (!sband->ht_cap.ht_supported)
  155. enable_ht = false;
  156. if (enable_ht) {
  157. hti_cfreq = ieee80211_channel_to_frequency(hti->control_chan,
  158. sband->band);
  159. /* check that channel matches the right operating channel */
  160. if (local->hw.conf.channel->center_freq != hti_cfreq) {
  161. /* Some APs mess this up, evidently.
  162. * Netgear WNDR3700 sometimes reports 4 higher than
  163. * the actual channel, for instance.
  164. */
  165. printk(KERN_DEBUG
  166. "%s: Wrong control channel in association"
  167. " response: configured center-freq: %d"
  168. " hti-cfreq: %d hti->control_chan: %d"
  169. " band: %d. Disabling HT.\n",
  170. sdata->name,
  171. local->hw.conf.channel->center_freq,
  172. hti_cfreq, hti->control_chan,
  173. sband->band);
  174. enable_ht = false;
  175. }
  176. }
  177. if (enable_ht) {
  178. channel_type = NL80211_CHAN_HT20;
  179. if (!(ap_ht_cap_flags & IEEE80211_HT_CAP_40MHZ_INTOLERANT) &&
  180. (sband->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) &&
  181. (hti->ht_param & IEEE80211_HT_PARAM_CHAN_WIDTH_ANY)) {
  182. switch(hti->ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) {
  183. case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
  184. if (!(local->hw.conf.channel->flags &
  185. IEEE80211_CHAN_NO_HT40PLUS))
  186. channel_type = NL80211_CHAN_HT40PLUS;
  187. break;
  188. case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
  189. if (!(local->hw.conf.channel->flags &
  190. IEEE80211_CHAN_NO_HT40MINUS))
  191. channel_type = NL80211_CHAN_HT40MINUS;
  192. break;
  193. }
  194. }
  195. }
  196. if (local->tmp_channel)
  197. local->tmp_channel_type = channel_type;
  198. if (!ieee80211_set_channel_type(local, sdata, channel_type)) {
  199. /* can only fail due to HT40+/- mismatch */
  200. channel_type = NL80211_CHAN_HT20;
  201. WARN_ON(!ieee80211_set_channel_type(local, sdata, channel_type));
  202. }
  203. if (beacon_htcap_ie && (prev_chantype != channel_type)) {
  204. /*
  205. * Whenever the AP announces the HT mode change that can be
  206. * 40MHz intolerant or etc., it would be safer to stop tx
  207. * queues before doing hw config to avoid buffer overflow.
  208. */
  209. ieee80211_stop_queues_by_reason(&sdata->local->hw,
  210. IEEE80211_QUEUE_STOP_REASON_CHTYPE_CHANGE);
  211. /* flush out all packets */
  212. synchronize_net();
  213. drv_flush(local, false);
  214. }
  215. /* channel_type change automatically detected */
  216. ieee80211_hw_config(local, 0);
  217. if (prev_chantype != channel_type) {
  218. rcu_read_lock();
  219. sta = sta_info_get(sdata, bssid);
  220. if (sta)
  221. rate_control_rate_update(local, sband, sta,
  222. IEEE80211_RC_HT_CHANGED,
  223. channel_type);
  224. rcu_read_unlock();
  225. if (beacon_htcap_ie)
  226. ieee80211_wake_queues_by_reason(&sdata->local->hw,
  227. IEEE80211_QUEUE_STOP_REASON_CHTYPE_CHANGE);
  228. }
  229. ht_opmode = le16_to_cpu(hti->operation_mode);
  230. /* if bss configuration changed store the new one */
  231. if (sdata->ht_opmode_valid != enable_ht ||
  232. sdata->vif.bss_conf.ht_operation_mode != ht_opmode ||
  233. prev_chantype != channel_type) {
  234. changed |= BSS_CHANGED_HT;
  235. sdata->vif.bss_conf.ht_operation_mode = ht_opmode;
  236. sdata->ht_opmode_valid = enable_ht;
  237. }
  238. return changed;
  239. }
  240. /* frame sending functions */
  241. static void ieee80211_send_deauth_disassoc(struct ieee80211_sub_if_data *sdata,
  242. const u8 *bssid, u16 stype, u16 reason,
  243. void *cookie, bool send_frame)
  244. {
  245. struct ieee80211_local *local = sdata->local;
  246. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  247. struct sk_buff *skb;
  248. struct ieee80211_mgmt *mgmt;
  249. skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*mgmt));
  250. if (!skb)
  251. return;
  252. skb_reserve(skb, local->hw.extra_tx_headroom);
  253. mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
  254. memset(mgmt, 0, 24);
  255. memcpy(mgmt->da, bssid, ETH_ALEN);
  256. memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
  257. memcpy(mgmt->bssid, bssid, ETH_ALEN);
  258. mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | stype);
  259. skb_put(skb, 2);
  260. /* u.deauth.reason_code == u.disassoc.reason_code */
  261. mgmt->u.deauth.reason_code = cpu_to_le16(reason);
  262. if (stype == IEEE80211_STYPE_DEAUTH)
  263. if (cookie)
  264. __cfg80211_send_deauth(sdata->dev, (u8 *)mgmt, skb->len);
  265. else
  266. cfg80211_send_deauth(sdata->dev, (u8 *)mgmt, skb->len);
  267. else
  268. if (cookie)
  269. __cfg80211_send_disassoc(sdata->dev, (u8 *)mgmt, skb->len);
  270. else
  271. cfg80211_send_disassoc(sdata->dev, (u8 *)mgmt, skb->len);
  272. if (!(ifmgd->flags & IEEE80211_STA_MFP_ENABLED))
  273. IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
  274. if (send_frame)
  275. ieee80211_tx_skb(sdata, skb);
  276. else
  277. kfree_skb(skb);
  278. }
  279. void ieee80211_send_pspoll(struct ieee80211_local *local,
  280. struct ieee80211_sub_if_data *sdata)
  281. {
  282. struct ieee80211_pspoll *pspoll;
  283. struct sk_buff *skb;
  284. skb = ieee80211_pspoll_get(&local->hw, &sdata->vif);
  285. if (!skb)
  286. return;
  287. pspoll = (struct ieee80211_pspoll *) skb->data;
  288. pspoll->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
  289. IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
  290. ieee80211_tx_skb(sdata, skb);
  291. }
  292. void ieee80211_send_nullfunc(struct ieee80211_local *local,
  293. struct ieee80211_sub_if_data *sdata,
  294. int powersave)
  295. {
  296. struct sk_buff *skb;
  297. struct ieee80211_hdr_3addr *nullfunc;
  298. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  299. skb = ieee80211_nullfunc_get(&local->hw, &sdata->vif);
  300. if (!skb)
  301. return;
  302. nullfunc = (struct ieee80211_hdr_3addr *) skb->data;
  303. if (powersave)
  304. nullfunc->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
  305. IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
  306. if (ifmgd->flags & (IEEE80211_STA_BEACON_POLL |
  307. IEEE80211_STA_CONNECTION_POLL))
  308. IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_USE_MINRATE;
  309. ieee80211_tx_skb(sdata, skb);
  310. }
  311. static void ieee80211_send_4addr_nullfunc(struct ieee80211_local *local,
  312. struct ieee80211_sub_if_data *sdata)
  313. {
  314. struct sk_buff *skb;
  315. struct ieee80211_hdr *nullfunc;
  316. __le16 fc;
  317. if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
  318. return;
  319. skb = dev_alloc_skb(local->hw.extra_tx_headroom + 30);
  320. if (!skb)
  321. return;
  322. skb_reserve(skb, local->hw.extra_tx_headroom);
  323. nullfunc = (struct ieee80211_hdr *) skb_put(skb, 30);
  324. memset(nullfunc, 0, 30);
  325. fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC |
  326. IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS);
  327. nullfunc->frame_control = fc;
  328. memcpy(nullfunc->addr1, sdata->u.mgd.bssid, ETH_ALEN);
  329. memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
  330. memcpy(nullfunc->addr3, sdata->u.mgd.bssid, ETH_ALEN);
  331. memcpy(nullfunc->addr4, sdata->vif.addr, ETH_ALEN);
  332. IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
  333. ieee80211_tx_skb(sdata, skb);
  334. }
  335. /* spectrum management related things */
  336. static void ieee80211_chswitch_work(struct work_struct *work)
  337. {
  338. struct ieee80211_sub_if_data *sdata =
  339. container_of(work, struct ieee80211_sub_if_data, u.mgd.chswitch_work);
  340. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  341. if (!ieee80211_sdata_running(sdata))
  342. return;
  343. mutex_lock(&ifmgd->mtx);
  344. if (!ifmgd->associated)
  345. goto out;
  346. sdata->local->oper_channel = sdata->local->csa_channel;
  347. if (!sdata->local->ops->channel_switch) {
  348. /* call "hw_config" only if doing sw channel switch */
  349. ieee80211_hw_config(sdata->local,
  350. IEEE80211_CONF_CHANGE_CHANNEL);
  351. } else {
  352. /* update the device channel directly */
  353. sdata->local->hw.conf.channel = sdata->local->oper_channel;
  354. }
  355. /* XXX: shouldn't really modify cfg80211-owned data! */
  356. ifmgd->associated->channel = sdata->local->oper_channel;
  357. ieee80211_wake_queues_by_reason(&sdata->local->hw,
  358. IEEE80211_QUEUE_STOP_REASON_CSA);
  359. out:
  360. ifmgd->flags &= ~IEEE80211_STA_CSA_RECEIVED;
  361. mutex_unlock(&ifmgd->mtx);
  362. }
  363. void ieee80211_chswitch_done(struct ieee80211_vif *vif, bool success)
  364. {
  365. struct ieee80211_sub_if_data *sdata;
  366. struct ieee80211_if_managed *ifmgd;
  367. sdata = vif_to_sdata(vif);
  368. ifmgd = &sdata->u.mgd;
  369. trace_api_chswitch_done(sdata, success);
  370. if (!success) {
  371. /*
  372. * If the channel switch was not successful, stay
  373. * around on the old channel. We currently lack
  374. * good handling of this situation, possibly we
  375. * should just drop the association.
  376. */
  377. sdata->local->csa_channel = sdata->local->oper_channel;
  378. }
  379. ieee80211_queue_work(&sdata->local->hw, &ifmgd->chswitch_work);
  380. }
  381. EXPORT_SYMBOL(ieee80211_chswitch_done);
  382. static void ieee80211_chswitch_timer(unsigned long data)
  383. {
  384. struct ieee80211_sub_if_data *sdata =
  385. (struct ieee80211_sub_if_data *) data;
  386. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  387. if (sdata->local->quiescing) {
  388. set_bit(TMR_RUNNING_CHANSW, &ifmgd->timers_running);
  389. return;
  390. }
  391. ieee80211_queue_work(&sdata->local->hw, &ifmgd->chswitch_work);
  392. }
  393. void ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data *sdata,
  394. struct ieee80211_channel_sw_ie *sw_elem,
  395. struct ieee80211_bss *bss,
  396. u64 timestamp)
  397. {
  398. struct cfg80211_bss *cbss =
  399. container_of((void *)bss, struct cfg80211_bss, priv);
  400. struct ieee80211_channel *new_ch;
  401. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  402. int new_freq = ieee80211_channel_to_frequency(sw_elem->new_ch_num,
  403. cbss->channel->band);
  404. ASSERT_MGD_MTX(ifmgd);
  405. if (!ifmgd->associated)
  406. return;
  407. if (sdata->local->scanning)
  408. return;
  409. /* Disregard subsequent beacons if we are already running a timer
  410. processing a CSA */
  411. if (ifmgd->flags & IEEE80211_STA_CSA_RECEIVED)
  412. return;
  413. new_ch = ieee80211_get_channel(sdata->local->hw.wiphy, new_freq);
  414. if (!new_ch || new_ch->flags & IEEE80211_CHAN_DISABLED)
  415. return;
  416. sdata->local->csa_channel = new_ch;
  417. if (sdata->local->ops->channel_switch) {
  418. /* use driver's channel switch callback */
  419. struct ieee80211_channel_switch ch_switch;
  420. memset(&ch_switch, 0, sizeof(ch_switch));
  421. ch_switch.timestamp = timestamp;
  422. if (sw_elem->mode) {
  423. ch_switch.block_tx = true;
  424. ieee80211_stop_queues_by_reason(&sdata->local->hw,
  425. IEEE80211_QUEUE_STOP_REASON_CSA);
  426. }
  427. ch_switch.channel = new_ch;
  428. ch_switch.count = sw_elem->count;
  429. ifmgd->flags |= IEEE80211_STA_CSA_RECEIVED;
  430. drv_channel_switch(sdata->local, &ch_switch);
  431. return;
  432. }
  433. /* channel switch handled in software */
  434. if (sw_elem->count <= 1) {
  435. ieee80211_queue_work(&sdata->local->hw, &ifmgd->chswitch_work);
  436. } else {
  437. if (sw_elem->mode)
  438. ieee80211_stop_queues_by_reason(&sdata->local->hw,
  439. IEEE80211_QUEUE_STOP_REASON_CSA);
  440. ifmgd->flags |= IEEE80211_STA_CSA_RECEIVED;
  441. mod_timer(&ifmgd->chswitch_timer,
  442. jiffies +
  443. msecs_to_jiffies(sw_elem->count *
  444. cbss->beacon_interval));
  445. }
  446. }
  447. static void ieee80211_handle_pwr_constr(struct ieee80211_sub_if_data *sdata,
  448. u16 capab_info, u8 *pwr_constr_elem,
  449. u8 pwr_constr_elem_len)
  450. {
  451. struct ieee80211_conf *conf = &sdata->local->hw.conf;
  452. if (!(capab_info & WLAN_CAPABILITY_SPECTRUM_MGMT))
  453. return;
  454. /* Power constraint IE length should be 1 octet */
  455. if (pwr_constr_elem_len != 1)
  456. return;
  457. if ((*pwr_constr_elem <= conf->channel->max_power) &&
  458. (*pwr_constr_elem != sdata->local->power_constr_level)) {
  459. sdata->local->power_constr_level = *pwr_constr_elem;
  460. ieee80211_hw_config(sdata->local, 0);
  461. }
  462. }
  463. void ieee80211_enable_dyn_ps(struct ieee80211_vif *vif)
  464. {
  465. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  466. struct ieee80211_local *local = sdata->local;
  467. struct ieee80211_conf *conf = &local->hw.conf;
  468. WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION ||
  469. !(local->hw.flags & IEEE80211_HW_SUPPORTS_PS) ||
  470. (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS));
  471. local->disable_dynamic_ps = false;
  472. conf->dynamic_ps_timeout = local->dynamic_ps_user_timeout;
  473. }
  474. EXPORT_SYMBOL(ieee80211_enable_dyn_ps);
  475. void ieee80211_disable_dyn_ps(struct ieee80211_vif *vif)
  476. {
  477. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  478. struct ieee80211_local *local = sdata->local;
  479. struct ieee80211_conf *conf = &local->hw.conf;
  480. WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION ||
  481. !(local->hw.flags & IEEE80211_HW_SUPPORTS_PS) ||
  482. (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS));
  483. local->disable_dynamic_ps = true;
  484. conf->dynamic_ps_timeout = 0;
  485. del_timer_sync(&local->dynamic_ps_timer);
  486. ieee80211_queue_work(&local->hw,
  487. &local->dynamic_ps_enable_work);
  488. }
  489. EXPORT_SYMBOL(ieee80211_disable_dyn_ps);
  490. /* powersave */
  491. static void ieee80211_enable_ps(struct ieee80211_local *local,
  492. struct ieee80211_sub_if_data *sdata)
  493. {
  494. struct ieee80211_conf *conf = &local->hw.conf;
  495. /*
  496. * If we are scanning right now then the parameters will
  497. * take effect when scan finishes.
  498. */
  499. if (local->scanning)
  500. return;
  501. if (conf->dynamic_ps_timeout > 0 &&
  502. !(local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)) {
  503. mod_timer(&local->dynamic_ps_timer, jiffies +
  504. msecs_to_jiffies(conf->dynamic_ps_timeout));
  505. } else {
  506. if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
  507. ieee80211_send_nullfunc(local, sdata, 1);
  508. if ((local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) &&
  509. (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS))
  510. return;
  511. conf->flags |= IEEE80211_CONF_PS;
  512. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
  513. }
  514. }
  515. static void ieee80211_change_ps(struct ieee80211_local *local)
  516. {
  517. struct ieee80211_conf *conf = &local->hw.conf;
  518. if (local->ps_sdata) {
  519. ieee80211_enable_ps(local, local->ps_sdata);
  520. } else if (conf->flags & IEEE80211_CONF_PS) {
  521. conf->flags &= ~IEEE80211_CONF_PS;
  522. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
  523. del_timer_sync(&local->dynamic_ps_timer);
  524. cancel_work_sync(&local->dynamic_ps_enable_work);
  525. }
  526. }
  527. static bool ieee80211_powersave_allowed(struct ieee80211_sub_if_data *sdata)
  528. {
  529. struct ieee80211_if_managed *mgd = &sdata->u.mgd;
  530. struct sta_info *sta = NULL;
  531. bool authorized = false;
  532. if (!mgd->powersave)
  533. return false;
  534. if (mgd->broken_ap)
  535. return false;
  536. if (!mgd->associated)
  537. return false;
  538. if (!mgd->associated->beacon_ies)
  539. return false;
  540. if (mgd->flags & (IEEE80211_STA_BEACON_POLL |
  541. IEEE80211_STA_CONNECTION_POLL))
  542. return false;
  543. rcu_read_lock();
  544. sta = sta_info_get(sdata, mgd->bssid);
  545. if (sta)
  546. authorized = test_sta_flag(sta, WLAN_STA_AUTHORIZED);
  547. rcu_read_unlock();
  548. return authorized;
  549. }
  550. /* need to hold RTNL or interface lock */
  551. void ieee80211_recalc_ps(struct ieee80211_local *local, s32 latency)
  552. {
  553. struct ieee80211_sub_if_data *sdata, *found = NULL;
  554. int count = 0;
  555. int timeout;
  556. if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS)) {
  557. local->ps_sdata = NULL;
  558. return;
  559. }
  560. if (!list_empty(&local->work_list)) {
  561. local->ps_sdata = NULL;
  562. goto change;
  563. }
  564. list_for_each_entry(sdata, &local->interfaces, list) {
  565. if (!ieee80211_sdata_running(sdata))
  566. continue;
  567. if (sdata->vif.type == NL80211_IFTYPE_AP) {
  568. /* If an AP vif is found, then disable PS
  569. * by setting the count to zero thereby setting
  570. * ps_sdata to NULL.
  571. */
  572. count = 0;
  573. break;
  574. }
  575. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  576. continue;
  577. found = sdata;
  578. count++;
  579. }
  580. if (count == 1 && ieee80211_powersave_allowed(found)) {
  581. struct ieee80211_conf *conf = &local->hw.conf;
  582. s32 beaconint_us;
  583. if (latency < 0)
  584. latency = pm_qos_request(PM_QOS_NETWORK_LATENCY);
  585. beaconint_us = ieee80211_tu_to_usec(
  586. found->vif.bss_conf.beacon_int);
  587. timeout = local->dynamic_ps_forced_timeout;
  588. if (timeout < 0) {
  589. /*
  590. * Go to full PSM if the user configures a very low
  591. * latency requirement.
  592. * The 2000 second value is there for compatibility
  593. * until the PM_QOS_NETWORK_LATENCY is configured
  594. * with real values.
  595. */
  596. if (latency > (1900 * USEC_PER_MSEC) &&
  597. latency != (2000 * USEC_PER_SEC))
  598. timeout = 0;
  599. else
  600. timeout = 100;
  601. }
  602. local->dynamic_ps_user_timeout = timeout;
  603. if (!local->disable_dynamic_ps)
  604. conf->dynamic_ps_timeout =
  605. local->dynamic_ps_user_timeout;
  606. if (beaconint_us > latency) {
  607. local->ps_sdata = NULL;
  608. } else {
  609. struct ieee80211_bss *bss;
  610. int maxslp = 1;
  611. u8 dtimper;
  612. bss = (void *)found->u.mgd.associated->priv;
  613. dtimper = bss->dtim_period;
  614. /* If the TIM IE is invalid, pretend the value is 1 */
  615. if (!dtimper)
  616. dtimper = 1;
  617. else if (dtimper > 1)
  618. maxslp = min_t(int, dtimper,
  619. latency / beaconint_us);
  620. local->hw.conf.max_sleep_period = maxslp;
  621. local->hw.conf.ps_dtim_period = dtimper;
  622. local->ps_sdata = found;
  623. }
  624. } else {
  625. local->ps_sdata = NULL;
  626. }
  627. change:
  628. ieee80211_change_ps(local);
  629. }
  630. void ieee80211_dynamic_ps_disable_work(struct work_struct *work)
  631. {
  632. struct ieee80211_local *local =
  633. container_of(work, struct ieee80211_local,
  634. dynamic_ps_disable_work);
  635. if (local->hw.conf.flags & IEEE80211_CONF_PS) {
  636. local->hw.conf.flags &= ~IEEE80211_CONF_PS;
  637. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
  638. }
  639. ieee80211_wake_queues_by_reason(&local->hw,
  640. IEEE80211_QUEUE_STOP_REASON_PS);
  641. }
  642. void ieee80211_dynamic_ps_enable_work(struct work_struct *work)
  643. {
  644. struct ieee80211_local *local =
  645. container_of(work, struct ieee80211_local,
  646. dynamic_ps_enable_work);
  647. struct ieee80211_sub_if_data *sdata = local->ps_sdata;
  648. struct ieee80211_if_managed *ifmgd;
  649. unsigned long flags;
  650. int q;
  651. /* can only happen when PS was just disabled anyway */
  652. if (!sdata)
  653. return;
  654. ifmgd = &sdata->u.mgd;
  655. if (local->hw.conf.flags & IEEE80211_CONF_PS)
  656. return;
  657. if (!local->disable_dynamic_ps &&
  658. local->hw.conf.dynamic_ps_timeout > 0) {
  659. /* don't enter PS if TX frames are pending */
  660. if (drv_tx_frames_pending(local)) {
  661. mod_timer(&local->dynamic_ps_timer, jiffies +
  662. msecs_to_jiffies(
  663. local->hw.conf.dynamic_ps_timeout));
  664. return;
  665. }
  666. /*
  667. * transmission can be stopped by others which leads to
  668. * dynamic_ps_timer expiry. Postpone the ps timer if it
  669. * is not the actual idle state.
  670. */
  671. spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
  672. for (q = 0; q < local->hw.queues; q++) {
  673. if (local->queue_stop_reasons[q]) {
  674. spin_unlock_irqrestore(&local->queue_stop_reason_lock,
  675. flags);
  676. mod_timer(&local->dynamic_ps_timer, jiffies +
  677. msecs_to_jiffies(
  678. local->hw.conf.dynamic_ps_timeout));
  679. return;
  680. }
  681. }
  682. spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
  683. }
  684. if ((local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) &&
  685. (!(ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED))) {
  686. netif_tx_stop_all_queues(sdata->dev);
  687. if (drv_tx_frames_pending(local))
  688. mod_timer(&local->dynamic_ps_timer, jiffies +
  689. msecs_to_jiffies(
  690. local->hw.conf.dynamic_ps_timeout));
  691. else {
  692. ieee80211_send_nullfunc(local, sdata, 1);
  693. /* Flush to get the tx status of nullfunc frame */
  694. drv_flush(local, false);
  695. }
  696. }
  697. if (!((local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS) &&
  698. (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)) ||
  699. (ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) {
  700. ifmgd->flags &= ~IEEE80211_STA_NULLFUNC_ACKED;
  701. local->hw.conf.flags |= IEEE80211_CONF_PS;
  702. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
  703. }
  704. if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
  705. netif_tx_wake_all_queues(sdata->dev);
  706. }
  707. void ieee80211_dynamic_ps_timer(unsigned long data)
  708. {
  709. struct ieee80211_local *local = (void *) data;
  710. if (local->quiescing || local->suspended)
  711. return;
  712. ieee80211_queue_work(&local->hw, &local->dynamic_ps_enable_work);
  713. }
  714. /* MLME */
  715. static void ieee80211_sta_wmm_params(struct ieee80211_local *local,
  716. struct ieee80211_sub_if_data *sdata,
  717. u8 *wmm_param, size_t wmm_param_len)
  718. {
  719. struct ieee80211_tx_queue_params params;
  720. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  721. size_t left;
  722. int count;
  723. u8 *pos, uapsd_queues = 0;
  724. if (!local->ops->conf_tx)
  725. return;
  726. if (local->hw.queues < 4)
  727. return;
  728. if (!wmm_param)
  729. return;
  730. if (wmm_param_len < 8 || wmm_param[5] /* version */ != 1)
  731. return;
  732. if (ifmgd->flags & IEEE80211_STA_UAPSD_ENABLED)
  733. uapsd_queues = local->uapsd_queues;
  734. count = wmm_param[6] & 0x0f;
  735. if (count == ifmgd->wmm_last_param_set)
  736. return;
  737. ifmgd->wmm_last_param_set = count;
  738. pos = wmm_param + 8;
  739. left = wmm_param_len - 8;
  740. memset(&params, 0, sizeof(params));
  741. local->wmm_acm = 0;
  742. for (; left >= 4; left -= 4, pos += 4) {
  743. int aci = (pos[0] >> 5) & 0x03;
  744. int acm = (pos[0] >> 4) & 0x01;
  745. bool uapsd = false;
  746. int queue;
  747. switch (aci) {
  748. case 1: /* AC_BK */
  749. queue = 3;
  750. if (acm)
  751. local->wmm_acm |= BIT(1) | BIT(2); /* BK/- */
  752. if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
  753. uapsd = true;
  754. break;
  755. case 2: /* AC_VI */
  756. queue = 1;
  757. if (acm)
  758. local->wmm_acm |= BIT(4) | BIT(5); /* CL/VI */
  759. if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
  760. uapsd = true;
  761. break;
  762. case 3: /* AC_VO */
  763. queue = 0;
  764. if (acm)
  765. local->wmm_acm |= BIT(6) | BIT(7); /* VO/NC */
  766. if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
  767. uapsd = true;
  768. break;
  769. case 0: /* AC_BE */
  770. default:
  771. queue = 2;
  772. if (acm)
  773. local->wmm_acm |= BIT(0) | BIT(3); /* BE/EE */
  774. if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
  775. uapsd = true;
  776. break;
  777. }
  778. params.aifs = pos[0] & 0x0f;
  779. params.cw_max = ecw2cw((pos[1] & 0xf0) >> 4);
  780. params.cw_min = ecw2cw(pos[1] & 0x0f);
  781. params.txop = get_unaligned_le16(pos + 2);
  782. params.uapsd = uapsd;
  783. #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
  784. wiphy_debug(local->hw.wiphy,
  785. "WMM queue=%d aci=%d acm=%d aifs=%d "
  786. "cWmin=%d cWmax=%d txop=%d uapsd=%d\n",
  787. queue, aci, acm,
  788. params.aifs, params.cw_min, params.cw_max,
  789. params.txop, params.uapsd);
  790. #endif
  791. sdata->tx_conf[queue] = params;
  792. if (drv_conf_tx(local, sdata, queue, &params))
  793. wiphy_debug(local->hw.wiphy,
  794. "failed to set TX queue parameters for queue %d\n",
  795. queue);
  796. }
  797. /* enable WMM or activate new settings */
  798. sdata->vif.bss_conf.qos = true;
  799. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_QOS);
  800. }
  801. static u32 ieee80211_handle_bss_capability(struct ieee80211_sub_if_data *sdata,
  802. u16 capab, bool erp_valid, u8 erp)
  803. {
  804. struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
  805. u32 changed = 0;
  806. bool use_protection;
  807. bool use_short_preamble;
  808. bool use_short_slot;
  809. if (erp_valid) {
  810. use_protection = (erp & WLAN_ERP_USE_PROTECTION) != 0;
  811. use_short_preamble = (erp & WLAN_ERP_BARKER_PREAMBLE) == 0;
  812. } else {
  813. use_protection = false;
  814. use_short_preamble = !!(capab & WLAN_CAPABILITY_SHORT_PREAMBLE);
  815. }
  816. use_short_slot = !!(capab & WLAN_CAPABILITY_SHORT_SLOT_TIME);
  817. if (sdata->local->hw.conf.channel->band == IEEE80211_BAND_5GHZ)
  818. use_short_slot = true;
  819. if (use_protection != bss_conf->use_cts_prot) {
  820. bss_conf->use_cts_prot = use_protection;
  821. changed |= BSS_CHANGED_ERP_CTS_PROT;
  822. }
  823. if (use_short_preamble != bss_conf->use_short_preamble) {
  824. bss_conf->use_short_preamble = use_short_preamble;
  825. changed |= BSS_CHANGED_ERP_PREAMBLE;
  826. }
  827. if (use_short_slot != bss_conf->use_short_slot) {
  828. bss_conf->use_short_slot = use_short_slot;
  829. changed |= BSS_CHANGED_ERP_SLOT;
  830. }
  831. return changed;
  832. }
  833. static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata,
  834. struct cfg80211_bss *cbss,
  835. u32 bss_info_changed)
  836. {
  837. struct ieee80211_bss *bss = (void *)cbss->priv;
  838. struct ieee80211_local *local = sdata->local;
  839. struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
  840. bss_info_changed |= BSS_CHANGED_ASSOC;
  841. /* set timing information */
  842. bss_conf->beacon_int = cbss->beacon_interval;
  843. bss_conf->timestamp = cbss->tsf;
  844. bss_info_changed |= BSS_CHANGED_BEACON_INT;
  845. bss_info_changed |= ieee80211_handle_bss_capability(sdata,
  846. cbss->capability, bss->has_erp_value, bss->erp_value);
  847. sdata->u.mgd.beacon_timeout = usecs_to_jiffies(ieee80211_tu_to_usec(
  848. IEEE80211_BEACON_LOSS_COUNT * bss_conf->beacon_int));
  849. sdata->u.mgd.associated = cbss;
  850. memcpy(sdata->u.mgd.bssid, cbss->bssid, ETH_ALEN);
  851. sdata->u.mgd.flags |= IEEE80211_STA_RESET_SIGNAL_AVE;
  852. /* just to be sure */
  853. sdata->u.mgd.flags &= ~(IEEE80211_STA_CONNECTION_POLL |
  854. IEEE80211_STA_BEACON_POLL);
  855. ieee80211_led_assoc(local, 1);
  856. if (local->hw.flags & IEEE80211_HW_NEED_DTIM_PERIOD)
  857. bss_conf->dtim_period = bss->dtim_period;
  858. else
  859. bss_conf->dtim_period = 0;
  860. bss_conf->assoc = 1;
  861. /*
  862. * For now just always ask the driver to update the basic rateset
  863. * when we have associated, we aren't checking whether it actually
  864. * changed or not.
  865. */
  866. bss_info_changed |= BSS_CHANGED_BASIC_RATES;
  867. /* And the BSSID changed - we're associated now */
  868. bss_info_changed |= BSS_CHANGED_BSSID;
  869. /* Tell the driver to monitor connection quality (if supported) */
  870. if ((local->hw.flags & IEEE80211_HW_SUPPORTS_CQM_RSSI) &&
  871. bss_conf->cqm_rssi_thold)
  872. bss_info_changed |= BSS_CHANGED_CQM;
  873. /* Enable ARP filtering */
  874. if (bss_conf->arp_filter_enabled != sdata->arp_filter_state) {
  875. bss_conf->arp_filter_enabled = sdata->arp_filter_state;
  876. bss_info_changed |= BSS_CHANGED_ARP_FILTER;
  877. }
  878. ieee80211_bss_info_change_notify(sdata, bss_info_changed);
  879. mutex_lock(&local->iflist_mtx);
  880. ieee80211_recalc_ps(local, -1);
  881. ieee80211_recalc_smps(local);
  882. mutex_unlock(&local->iflist_mtx);
  883. netif_tx_start_all_queues(sdata->dev);
  884. netif_carrier_on(sdata->dev);
  885. }
  886. static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata,
  887. bool remove_sta, bool tx)
  888. {
  889. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  890. struct ieee80211_local *local = sdata->local;
  891. struct sta_info *sta;
  892. u32 changed = 0, config_changed = 0;
  893. u8 bssid[ETH_ALEN];
  894. ASSERT_MGD_MTX(ifmgd);
  895. if (WARN_ON(!ifmgd->associated))
  896. return;
  897. memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN);
  898. ifmgd->associated = NULL;
  899. memset(ifmgd->bssid, 0, ETH_ALEN);
  900. /*
  901. * we need to commit the associated = NULL change because the
  902. * scan code uses that to determine whether this iface should
  903. * go to/wake up from powersave or not -- and could otherwise
  904. * wake the queues erroneously.
  905. */
  906. smp_mb();
  907. /*
  908. * Thus, we can only afterwards stop the queues -- to account
  909. * for the case where another CPU is finishing a scan at this
  910. * time -- we don't want the scan code to enable queues.
  911. */
  912. netif_tx_stop_all_queues(sdata->dev);
  913. netif_carrier_off(sdata->dev);
  914. mutex_lock(&local->sta_mtx);
  915. sta = sta_info_get(sdata, bssid);
  916. if (sta) {
  917. set_sta_flag(sta, WLAN_STA_BLOCK_BA);
  918. ieee80211_sta_tear_down_BA_sessions(sta, tx);
  919. }
  920. mutex_unlock(&local->sta_mtx);
  921. changed |= ieee80211_reset_erp_info(sdata);
  922. ieee80211_led_assoc(local, 0);
  923. changed |= BSS_CHANGED_ASSOC;
  924. sdata->vif.bss_conf.assoc = false;
  925. ieee80211_set_wmm_default(sdata);
  926. /* channel(_type) changes are handled by ieee80211_hw_config */
  927. WARN_ON(!ieee80211_set_channel_type(local, sdata, NL80211_CHAN_NO_HT));
  928. /* on the next assoc, re-program HT parameters */
  929. sdata->ht_opmode_valid = false;
  930. local->power_constr_level = 0;
  931. del_timer_sync(&local->dynamic_ps_timer);
  932. cancel_work_sync(&local->dynamic_ps_enable_work);
  933. if (local->hw.conf.flags & IEEE80211_CONF_PS) {
  934. local->hw.conf.flags &= ~IEEE80211_CONF_PS;
  935. config_changed |= IEEE80211_CONF_CHANGE_PS;
  936. }
  937. local->ps_sdata = NULL;
  938. ieee80211_hw_config(local, config_changed);
  939. /* Disable ARP filtering */
  940. if (sdata->vif.bss_conf.arp_filter_enabled) {
  941. sdata->vif.bss_conf.arp_filter_enabled = false;
  942. changed |= BSS_CHANGED_ARP_FILTER;
  943. }
  944. /* The BSSID (not really interesting) and HT changed */
  945. changed |= BSS_CHANGED_BSSID | BSS_CHANGED_HT;
  946. ieee80211_bss_info_change_notify(sdata, changed);
  947. /* remove AP and TDLS peers */
  948. if (remove_sta)
  949. sta_info_flush(local, sdata);
  950. del_timer_sync(&sdata->u.mgd.conn_mon_timer);
  951. del_timer_sync(&sdata->u.mgd.bcn_mon_timer);
  952. del_timer_sync(&sdata->u.mgd.timer);
  953. del_timer_sync(&sdata->u.mgd.chswitch_timer);
  954. }
  955. void ieee80211_sta_rx_notify(struct ieee80211_sub_if_data *sdata,
  956. struct ieee80211_hdr *hdr)
  957. {
  958. /*
  959. * We can postpone the mgd.timer whenever receiving unicast frames
  960. * from AP because we know that the connection is working both ways
  961. * at that time. But multicast frames (and hence also beacons) must
  962. * be ignored here, because we need to trigger the timer during
  963. * data idle periods for sending the periodic probe request to the
  964. * AP we're connected to.
  965. */
  966. if (is_multicast_ether_addr(hdr->addr1))
  967. return;
  968. ieee80211_sta_reset_conn_monitor(sdata);
  969. }
  970. static void ieee80211_reset_ap_probe(struct ieee80211_sub_if_data *sdata)
  971. {
  972. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  973. if (!(ifmgd->flags & (IEEE80211_STA_BEACON_POLL |
  974. IEEE80211_STA_CONNECTION_POLL)))
  975. return;
  976. ifmgd->flags &= ~(IEEE80211_STA_CONNECTION_POLL |
  977. IEEE80211_STA_BEACON_POLL);
  978. mutex_lock(&sdata->local->iflist_mtx);
  979. ieee80211_recalc_ps(sdata->local, -1);
  980. mutex_unlock(&sdata->local->iflist_mtx);
  981. if (sdata->local->hw.flags & IEEE80211_HW_CONNECTION_MONITOR)
  982. return;
  983. /*
  984. * We've received a probe response, but are not sure whether
  985. * we have or will be receiving any beacons or data, so let's
  986. * schedule the timers again, just in case.
  987. */
  988. ieee80211_sta_reset_beacon_monitor(sdata);
  989. mod_timer(&ifmgd->conn_mon_timer,
  990. round_jiffies_up(jiffies +
  991. IEEE80211_CONNECTION_IDLE_TIME));
  992. }
  993. void ieee80211_sta_tx_notify(struct ieee80211_sub_if_data *sdata,
  994. struct ieee80211_hdr *hdr, bool ack)
  995. {
  996. if (!ieee80211_is_data(hdr->frame_control))
  997. return;
  998. if (ack)
  999. ieee80211_sta_reset_conn_monitor(sdata);
  1000. if (ieee80211_is_nullfunc(hdr->frame_control) &&
  1001. sdata->u.mgd.probe_send_count > 0) {
  1002. if (ack)
  1003. sdata->u.mgd.probe_send_count = 0;
  1004. else
  1005. sdata->u.mgd.nullfunc_failed = true;
  1006. ieee80211_queue_work(&sdata->local->hw, &sdata->work);
  1007. }
  1008. }
  1009. static void ieee80211_mgd_probe_ap_send(struct ieee80211_sub_if_data *sdata)
  1010. {
  1011. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1012. const u8 *ssid;
  1013. u8 *dst = ifmgd->associated->bssid;
  1014. u8 unicast_limit = max(1, max_probe_tries - 3);
  1015. /*
  1016. * Try sending broadcast probe requests for the last three
  1017. * probe requests after the first ones failed since some
  1018. * buggy APs only support broadcast probe requests.
  1019. */
  1020. if (ifmgd->probe_send_count >= unicast_limit)
  1021. dst = NULL;
  1022. /*
  1023. * When the hardware reports an accurate Tx ACK status, it's
  1024. * better to send a nullfunc frame instead of a probe request,
  1025. * as it will kick us off the AP quickly if we aren't associated
  1026. * anymore. The timeout will be reset if the frame is ACKed by
  1027. * the AP.
  1028. */
  1029. if (sdata->local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS) {
  1030. ifmgd->nullfunc_failed = false;
  1031. ieee80211_send_nullfunc(sdata->local, sdata, 0);
  1032. } else {
  1033. ssid = ieee80211_bss_get_ie(ifmgd->associated, WLAN_EID_SSID);
  1034. ieee80211_send_probe_req(sdata, dst, ssid + 2, ssid[1], NULL, 0,
  1035. (u32) -1, true, false);
  1036. }
  1037. ifmgd->probe_send_count++;
  1038. ifmgd->probe_timeout = jiffies + msecs_to_jiffies(probe_wait_ms);
  1039. run_again(ifmgd, ifmgd->probe_timeout);
  1040. }
  1041. static void ieee80211_mgd_probe_ap(struct ieee80211_sub_if_data *sdata,
  1042. bool beacon)
  1043. {
  1044. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1045. bool already = false;
  1046. if (!ieee80211_sdata_running(sdata))
  1047. return;
  1048. if (sdata->local->scanning)
  1049. return;
  1050. if (sdata->local->tmp_channel)
  1051. return;
  1052. mutex_lock(&ifmgd->mtx);
  1053. if (!ifmgd->associated)
  1054. goto out;
  1055. #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
  1056. if (beacon && net_ratelimit())
  1057. printk(KERN_DEBUG "%s: detected beacon loss from AP "
  1058. "- sending probe request\n", sdata->name);
  1059. #endif
  1060. /*
  1061. * The driver/our work has already reported this event or the
  1062. * connection monitoring has kicked in and we have already sent
  1063. * a probe request. Or maybe the AP died and the driver keeps
  1064. * reporting until we disassociate...
  1065. *
  1066. * In either case we have to ignore the current call to this
  1067. * function (except for setting the correct probe reason bit)
  1068. * because otherwise we would reset the timer every time and
  1069. * never check whether we received a probe response!
  1070. */
  1071. if (ifmgd->flags & (IEEE80211_STA_BEACON_POLL |
  1072. IEEE80211_STA_CONNECTION_POLL))
  1073. already = true;
  1074. if (beacon)
  1075. ifmgd->flags |= IEEE80211_STA_BEACON_POLL;
  1076. else
  1077. ifmgd->flags |= IEEE80211_STA_CONNECTION_POLL;
  1078. if (already)
  1079. goto out;
  1080. mutex_lock(&sdata->local->iflist_mtx);
  1081. ieee80211_recalc_ps(sdata->local, -1);
  1082. mutex_unlock(&sdata->local->iflist_mtx);
  1083. ifmgd->probe_send_count = 0;
  1084. ieee80211_mgd_probe_ap_send(sdata);
  1085. out:
  1086. mutex_unlock(&ifmgd->mtx);
  1087. }
  1088. struct sk_buff *ieee80211_ap_probereq_get(struct ieee80211_hw *hw,
  1089. struct ieee80211_vif *vif)
  1090. {
  1091. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  1092. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1093. struct sk_buff *skb;
  1094. const u8 *ssid;
  1095. if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
  1096. return NULL;
  1097. ASSERT_MGD_MTX(ifmgd);
  1098. if (!ifmgd->associated)
  1099. return NULL;
  1100. ssid = ieee80211_bss_get_ie(ifmgd->associated, WLAN_EID_SSID);
  1101. skb = ieee80211_build_probe_req(sdata, ifmgd->associated->bssid,
  1102. (u32) -1, ssid + 2, ssid[1],
  1103. NULL, 0, true);
  1104. return skb;
  1105. }
  1106. EXPORT_SYMBOL(ieee80211_ap_probereq_get);
  1107. static void __ieee80211_connection_loss(struct ieee80211_sub_if_data *sdata)
  1108. {
  1109. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1110. struct ieee80211_local *local = sdata->local;
  1111. u8 bssid[ETH_ALEN];
  1112. mutex_lock(&ifmgd->mtx);
  1113. if (!ifmgd->associated) {
  1114. mutex_unlock(&ifmgd->mtx);
  1115. return;
  1116. }
  1117. memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN);
  1118. printk(KERN_DEBUG "%s: Connection to AP %pM lost.\n",
  1119. sdata->name, bssid);
  1120. ieee80211_set_disassoc(sdata, true, true);
  1121. mutex_unlock(&ifmgd->mtx);
  1122. /*
  1123. * must be outside lock due to cfg80211,
  1124. * but that's not a problem.
  1125. */
  1126. ieee80211_send_deauth_disassoc(sdata, bssid,
  1127. IEEE80211_STYPE_DEAUTH,
  1128. WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
  1129. NULL, true);
  1130. mutex_lock(&local->mtx);
  1131. ieee80211_recalc_idle(local);
  1132. mutex_unlock(&local->mtx);
  1133. }
  1134. void ieee80211_beacon_connection_loss_work(struct work_struct *work)
  1135. {
  1136. struct ieee80211_sub_if_data *sdata =
  1137. container_of(work, struct ieee80211_sub_if_data,
  1138. u.mgd.beacon_connection_loss_work);
  1139. if (sdata->local->hw.flags & IEEE80211_HW_CONNECTION_MONITOR)
  1140. __ieee80211_connection_loss(sdata);
  1141. else
  1142. ieee80211_mgd_probe_ap(sdata, true);
  1143. }
  1144. void ieee80211_beacon_loss(struct ieee80211_vif *vif)
  1145. {
  1146. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  1147. struct ieee80211_hw *hw = &sdata->local->hw;
  1148. trace_api_beacon_loss(sdata);
  1149. WARN_ON(hw->flags & IEEE80211_HW_CONNECTION_MONITOR);
  1150. ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work);
  1151. }
  1152. EXPORT_SYMBOL(ieee80211_beacon_loss);
  1153. void ieee80211_connection_loss(struct ieee80211_vif *vif)
  1154. {
  1155. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  1156. struct ieee80211_hw *hw = &sdata->local->hw;
  1157. trace_api_connection_loss(sdata);
  1158. WARN_ON(!(hw->flags & IEEE80211_HW_CONNECTION_MONITOR));
  1159. ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work);
  1160. }
  1161. EXPORT_SYMBOL(ieee80211_connection_loss);
  1162. static enum rx_mgmt_action __must_check
  1163. ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data *sdata,
  1164. struct ieee80211_mgmt *mgmt, size_t len)
  1165. {
  1166. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1167. const u8 *bssid = NULL;
  1168. u16 reason_code;
  1169. if (len < 24 + 2)
  1170. return RX_MGMT_NONE;
  1171. ASSERT_MGD_MTX(ifmgd);
  1172. bssid = ifmgd->associated->bssid;
  1173. reason_code = le16_to_cpu(mgmt->u.deauth.reason_code);
  1174. printk(KERN_DEBUG "%s: deauthenticated from %pM (Reason: %u)\n",
  1175. sdata->name, bssid, reason_code);
  1176. ieee80211_set_disassoc(sdata, true, false);
  1177. mutex_lock(&sdata->local->mtx);
  1178. ieee80211_recalc_idle(sdata->local);
  1179. mutex_unlock(&sdata->local->mtx);
  1180. return RX_MGMT_CFG80211_DEAUTH;
  1181. }
  1182. static enum rx_mgmt_action __must_check
  1183. ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data *sdata,
  1184. struct ieee80211_mgmt *mgmt, size_t len)
  1185. {
  1186. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1187. u16 reason_code;
  1188. if (len < 24 + 2)
  1189. return RX_MGMT_NONE;
  1190. ASSERT_MGD_MTX(ifmgd);
  1191. if (WARN_ON(!ifmgd->associated))
  1192. return RX_MGMT_NONE;
  1193. if (WARN_ON(memcmp(ifmgd->associated->bssid, mgmt->sa, ETH_ALEN)))
  1194. return RX_MGMT_NONE;
  1195. reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code);
  1196. printk(KERN_DEBUG "%s: disassociated from %pM (Reason: %u)\n",
  1197. sdata->name, mgmt->sa, reason_code);
  1198. ieee80211_set_disassoc(sdata, true, false);
  1199. mutex_lock(&sdata->local->mtx);
  1200. ieee80211_recalc_idle(sdata->local);
  1201. mutex_unlock(&sdata->local->mtx);
  1202. return RX_MGMT_CFG80211_DISASSOC;
  1203. }
  1204. static void ieee80211_get_rates(struct ieee80211_supported_band *sband,
  1205. u8 *supp_rates, unsigned int supp_rates_len,
  1206. u32 *rates, u32 *basic_rates,
  1207. bool *have_higher_than_11mbit,
  1208. int *min_rate, int *min_rate_index)
  1209. {
  1210. int i, j;
  1211. for (i = 0; i < supp_rates_len; i++) {
  1212. int rate = (supp_rates[i] & 0x7f) * 5;
  1213. bool is_basic = !!(supp_rates[i] & 0x80);
  1214. if (rate > 110)
  1215. *have_higher_than_11mbit = true;
  1216. /*
  1217. * BSS_MEMBERSHIP_SELECTOR_HT_PHY is defined in 802.11n-2009
  1218. * 7.3.2.2 as a magic value instead of a rate. Hence, skip it.
  1219. *
  1220. * Note: Even through the membership selector and the basic
  1221. * rate flag share the same bit, they are not exactly
  1222. * the same.
  1223. */
  1224. if (!!(supp_rates[i] & 0x80) &&
  1225. (supp_rates[i] & 0x7f) == BSS_MEMBERSHIP_SELECTOR_HT_PHY)
  1226. continue;
  1227. for (j = 0; j < sband->n_bitrates; j++) {
  1228. if (sband->bitrates[j].bitrate == rate) {
  1229. *rates |= BIT(j);
  1230. if (is_basic)
  1231. *basic_rates |= BIT(j);
  1232. if (rate < *min_rate) {
  1233. *min_rate = rate;
  1234. *min_rate_index = j;
  1235. }
  1236. break;
  1237. }
  1238. }
  1239. }
  1240. }
  1241. static bool ieee80211_assoc_success(struct ieee80211_work *wk,
  1242. struct ieee80211_mgmt *mgmt, size_t len)
  1243. {
  1244. struct ieee80211_sub_if_data *sdata = wk->sdata;
  1245. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1246. struct ieee80211_local *local = sdata->local;
  1247. struct ieee80211_supported_band *sband;
  1248. struct sta_info *sta;
  1249. struct cfg80211_bss *cbss = wk->assoc.bss;
  1250. u8 *pos;
  1251. u32 rates, basic_rates;
  1252. u16 capab_info, aid;
  1253. struct ieee802_11_elems elems;
  1254. struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
  1255. u32 changed = 0;
  1256. int err;
  1257. bool have_higher_than_11mbit = false;
  1258. u16 ap_ht_cap_flags;
  1259. int min_rate = INT_MAX, min_rate_index = -1;
  1260. /* AssocResp and ReassocResp have identical structure */
  1261. aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
  1262. capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
  1263. if ((aid & (BIT(15) | BIT(14))) != (BIT(15) | BIT(14)))
  1264. printk(KERN_DEBUG
  1265. "%s: invalid AID value 0x%x; bits 15:14 not set\n",
  1266. sdata->name, aid);
  1267. aid &= ~(BIT(15) | BIT(14));
  1268. ifmgd->broken_ap = false;
  1269. if (aid == 0 || aid > IEEE80211_MAX_AID) {
  1270. printk(KERN_DEBUG
  1271. "%s: invalid AID value %d (out of range), turn off PS\n",
  1272. sdata->name, aid);
  1273. aid = 0;
  1274. ifmgd->broken_ap = true;
  1275. }
  1276. pos = mgmt->u.assoc_resp.variable;
  1277. ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems);
  1278. if (!elems.supp_rates) {
  1279. printk(KERN_DEBUG "%s: no SuppRates element in AssocResp\n",
  1280. sdata->name);
  1281. return false;
  1282. }
  1283. ifmgd->aid = aid;
  1284. mutex_lock(&sdata->local->sta_mtx);
  1285. /*
  1286. * station info was already allocated and inserted before
  1287. * the association and should be available to us
  1288. */
  1289. sta = sta_info_get_rx(sdata, cbss->bssid);
  1290. if (WARN_ON(!sta)) {
  1291. mutex_unlock(&sdata->local->sta_mtx);
  1292. return false;
  1293. }
  1294. set_sta_flag(sta, WLAN_STA_AUTH);
  1295. set_sta_flag(sta, WLAN_STA_ASSOC);
  1296. if (!(ifmgd->flags & IEEE80211_STA_CONTROL_PORT))
  1297. set_sta_flag(sta, WLAN_STA_AUTHORIZED);
  1298. rates = 0;
  1299. basic_rates = 0;
  1300. sband = local->hw.wiphy->bands[wk->chan->band];
  1301. ieee80211_get_rates(sband, elems.supp_rates, elems.supp_rates_len,
  1302. &rates, &basic_rates, &have_higher_than_11mbit,
  1303. &min_rate, &min_rate_index);
  1304. ieee80211_get_rates(sband, elems.ext_supp_rates,
  1305. elems.ext_supp_rates_len, &rates, &basic_rates,
  1306. &have_higher_than_11mbit,
  1307. &min_rate, &min_rate_index);
  1308. /*
  1309. * some buggy APs don't advertise basic_rates. use the lowest
  1310. * supported rate instead.
  1311. */
  1312. if (unlikely(!basic_rates) && min_rate_index >= 0) {
  1313. printk(KERN_DEBUG "%s: No basic rates in AssocResp. "
  1314. "Using min supported rate instead.\n", sdata->name);
  1315. basic_rates = BIT(min_rate_index);
  1316. }
  1317. sta->sta.supp_rates[wk->chan->band] = rates;
  1318. sdata->vif.bss_conf.basic_rates = basic_rates;
  1319. /* cf. IEEE 802.11 9.2.12 */
  1320. if (wk->chan->band == IEEE80211_BAND_2GHZ &&
  1321. have_higher_than_11mbit)
  1322. sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE;
  1323. else
  1324. sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE;
  1325. if (elems.ht_cap_elem && !(ifmgd->flags & IEEE80211_STA_DISABLE_11N))
  1326. ieee80211_ht_cap_ie_to_sta_ht_cap(sband,
  1327. elems.ht_cap_elem, &sta->sta.ht_cap);
  1328. ap_ht_cap_flags = sta->sta.ht_cap.cap;
  1329. rate_control_rate_init(sta);
  1330. if (ifmgd->flags & IEEE80211_STA_MFP_ENABLED)
  1331. set_sta_flag(sta, WLAN_STA_MFP);
  1332. if (elems.wmm_param)
  1333. set_sta_flag(sta, WLAN_STA_WME);
  1334. /* sta_info_reinsert will also unlock the mutex lock */
  1335. err = sta_info_reinsert(sta);
  1336. sta = NULL;
  1337. if (err) {
  1338. printk(KERN_DEBUG "%s: failed to insert STA entry for"
  1339. " the AP (error %d)\n", sdata->name, err);
  1340. return false;
  1341. }
  1342. /*
  1343. * Always handle WMM once after association regardless
  1344. * of the first value the AP uses. Setting -1 here has
  1345. * that effect because the AP values is an unsigned
  1346. * 4-bit value.
  1347. */
  1348. ifmgd->wmm_last_param_set = -1;
  1349. if (elems.wmm_param)
  1350. ieee80211_sta_wmm_params(local, sdata, elems.wmm_param,
  1351. elems.wmm_param_len);
  1352. else
  1353. ieee80211_set_wmm_default(sdata);
  1354. local->oper_channel = wk->chan;
  1355. if (elems.ht_info_elem && elems.wmm_param &&
  1356. (sdata->local->hw.queues >= 4) &&
  1357. !(ifmgd->flags & IEEE80211_STA_DISABLE_11N))
  1358. changed |= ieee80211_enable_ht(sdata, elems.ht_info_elem,
  1359. cbss->bssid, ap_ht_cap_flags,
  1360. false);
  1361. /* set AID and assoc capability,
  1362. * ieee80211_set_associated() will tell the driver */
  1363. bss_conf->aid = aid;
  1364. bss_conf->assoc_capability = capab_info;
  1365. ieee80211_set_associated(sdata, cbss, changed);
  1366. /*
  1367. * If we're using 4-addr mode, let the AP know that we're
  1368. * doing so, so that it can create the STA VLAN on its side
  1369. */
  1370. if (ifmgd->use_4addr)
  1371. ieee80211_send_4addr_nullfunc(local, sdata);
  1372. /*
  1373. * Start timer to probe the connection to the AP now.
  1374. * Also start the timer that will detect beacon loss.
  1375. */
  1376. ieee80211_sta_rx_notify(sdata, (struct ieee80211_hdr *)mgmt);
  1377. ieee80211_sta_reset_beacon_monitor(sdata);
  1378. return true;
  1379. }
  1380. static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
  1381. struct ieee80211_mgmt *mgmt,
  1382. size_t len,
  1383. struct ieee80211_rx_status *rx_status,
  1384. struct ieee802_11_elems *elems,
  1385. bool beacon)
  1386. {
  1387. struct ieee80211_local *local = sdata->local;
  1388. int freq;
  1389. struct ieee80211_bss *bss;
  1390. struct ieee80211_channel *channel;
  1391. bool need_ps = false;
  1392. if (sdata->u.mgd.associated) {
  1393. bss = (void *)sdata->u.mgd.associated->priv;
  1394. /* not previously set so we may need to recalc */
  1395. need_ps = !bss->dtim_period;
  1396. }
  1397. if (elems->ds_params && elems->ds_params_len == 1)
  1398. freq = ieee80211_channel_to_frequency(elems->ds_params[0],
  1399. rx_status->band);
  1400. else
  1401. freq = rx_status->freq;
  1402. channel = ieee80211_get_channel(local->hw.wiphy, freq);
  1403. if (!channel || channel->flags & IEEE80211_CHAN_DISABLED)
  1404. return;
  1405. bss = ieee80211_bss_info_update(local, rx_status, mgmt, len, elems,
  1406. channel, beacon);
  1407. if (bss)
  1408. ieee80211_rx_bss_put(local, bss);
  1409. if (!sdata->u.mgd.associated)
  1410. return;
  1411. if (need_ps) {
  1412. mutex_lock(&local->iflist_mtx);
  1413. ieee80211_recalc_ps(local, -1);
  1414. mutex_unlock(&local->iflist_mtx);
  1415. }
  1416. if (elems->ch_switch_elem && (elems->ch_switch_elem_len == 3) &&
  1417. (memcmp(mgmt->bssid, sdata->u.mgd.associated->bssid,
  1418. ETH_ALEN) == 0)) {
  1419. struct ieee80211_channel_sw_ie *sw_elem =
  1420. (struct ieee80211_channel_sw_ie *)elems->ch_switch_elem;
  1421. ieee80211_sta_process_chanswitch(sdata, sw_elem,
  1422. bss, rx_status->mactime);
  1423. }
  1424. }
  1425. static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data *sdata,
  1426. struct sk_buff *skb)
  1427. {
  1428. struct ieee80211_mgmt *mgmt = (void *)skb->data;
  1429. struct ieee80211_if_managed *ifmgd;
  1430. struct ieee80211_rx_status *rx_status = (void *) skb->cb;
  1431. size_t baselen, len = skb->len;
  1432. struct ieee802_11_elems elems;
  1433. ifmgd = &sdata->u.mgd;
  1434. ASSERT_MGD_MTX(ifmgd);
  1435. if (memcmp(mgmt->da, sdata->vif.addr, ETH_ALEN))
  1436. return; /* ignore ProbeResp to foreign address */
  1437. baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
  1438. if (baselen > len)
  1439. return;
  1440. ieee802_11_parse_elems(mgmt->u.probe_resp.variable, len - baselen,
  1441. &elems);
  1442. ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems, false);
  1443. if (ifmgd->associated &&
  1444. memcmp(mgmt->bssid, ifmgd->associated->bssid, ETH_ALEN) == 0)
  1445. ieee80211_reset_ap_probe(sdata);
  1446. }
  1447. /*
  1448. * This is the canonical list of information elements we care about,
  1449. * the filter code also gives us all changes to the Microsoft OUI
  1450. * (00:50:F2) vendor IE which is used for WMM which we need to track.
  1451. *
  1452. * We implement beacon filtering in software since that means we can
  1453. * avoid processing the frame here and in cfg80211, and userspace
  1454. * will not be able to tell whether the hardware supports it or not.
  1455. *
  1456. * XXX: This list needs to be dynamic -- userspace needs to be able to
  1457. * add items it requires. It also needs to be able to tell us to
  1458. * look out for other vendor IEs.
  1459. */
  1460. static const u64 care_about_ies =
  1461. (1ULL << WLAN_EID_COUNTRY) |
  1462. (1ULL << WLAN_EID_ERP_INFO) |
  1463. (1ULL << WLAN_EID_CHANNEL_SWITCH) |
  1464. (1ULL << WLAN_EID_PWR_CONSTRAINT) |
  1465. (1ULL << WLAN_EID_HT_CAPABILITY) |
  1466. (1ULL << WLAN_EID_HT_INFORMATION);
  1467. static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata,
  1468. struct ieee80211_mgmt *mgmt,
  1469. size_t len,
  1470. struct ieee80211_rx_status *rx_status)
  1471. {
  1472. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1473. struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
  1474. size_t baselen;
  1475. struct ieee802_11_elems elems;
  1476. struct ieee80211_local *local = sdata->local;
  1477. u32 changed = 0;
  1478. bool erp_valid, directed_tim = false;
  1479. u8 erp_value = 0;
  1480. u32 ncrc;
  1481. u8 *bssid;
  1482. ASSERT_MGD_MTX(ifmgd);
  1483. /* Process beacon from the current BSS */
  1484. baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt;
  1485. if (baselen > len)
  1486. return;
  1487. if (rx_status->freq != local->hw.conf.channel->center_freq)
  1488. return;
  1489. /*
  1490. * We might have received a number of frames, among them a
  1491. * disassoc frame and a beacon...
  1492. */
  1493. if (!ifmgd->associated)
  1494. return;
  1495. bssid = ifmgd->associated->bssid;
  1496. /*
  1497. * And in theory even frames from a different AP we were just
  1498. * associated to a split-second ago!
  1499. */
  1500. if (memcmp(bssid, mgmt->bssid, ETH_ALEN) != 0)
  1501. return;
  1502. /* Track average RSSI from the Beacon frames of the current AP */
  1503. ifmgd->last_beacon_signal = rx_status->signal;
  1504. if (ifmgd->flags & IEEE80211_STA_RESET_SIGNAL_AVE) {
  1505. ifmgd->flags &= ~IEEE80211_STA_RESET_SIGNAL_AVE;
  1506. ifmgd->ave_beacon_signal = rx_status->signal * 16;
  1507. ifmgd->last_cqm_event_signal = 0;
  1508. ifmgd->count_beacon_signal = 1;
  1509. ifmgd->last_ave_beacon_signal = 0;
  1510. } else {
  1511. ifmgd->ave_beacon_signal =
  1512. (IEEE80211_SIGNAL_AVE_WEIGHT * rx_status->signal * 16 +
  1513. (16 - IEEE80211_SIGNAL_AVE_WEIGHT) *
  1514. ifmgd->ave_beacon_signal) / 16;
  1515. ifmgd->count_beacon_signal++;
  1516. }
  1517. if (ifmgd->rssi_min_thold != ifmgd->rssi_max_thold &&
  1518. ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT) {
  1519. int sig = ifmgd->ave_beacon_signal;
  1520. int last_sig = ifmgd->last_ave_beacon_signal;
  1521. /*
  1522. * if signal crosses either of the boundaries, invoke callback
  1523. * with appropriate parameters
  1524. */
  1525. if (sig > ifmgd->rssi_max_thold &&
  1526. (last_sig <= ifmgd->rssi_min_thold || last_sig == 0)) {
  1527. ifmgd->last_ave_beacon_signal = sig;
  1528. drv_rssi_callback(local, RSSI_EVENT_HIGH);
  1529. } else if (sig < ifmgd->rssi_min_thold &&
  1530. (last_sig >= ifmgd->rssi_max_thold ||
  1531. last_sig == 0)) {
  1532. ifmgd->last_ave_beacon_signal = sig;
  1533. drv_rssi_callback(local, RSSI_EVENT_LOW);
  1534. }
  1535. }
  1536. if (bss_conf->cqm_rssi_thold &&
  1537. ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT &&
  1538. !(local->hw.flags & IEEE80211_HW_SUPPORTS_CQM_RSSI)) {
  1539. int sig = ifmgd->ave_beacon_signal / 16;
  1540. int last_event = ifmgd->last_cqm_event_signal;
  1541. int thold = bss_conf->cqm_rssi_thold;
  1542. int hyst = bss_conf->cqm_rssi_hyst;
  1543. if (sig < thold &&
  1544. (last_event == 0 || sig < last_event - hyst)) {
  1545. ifmgd->last_cqm_event_signal = sig;
  1546. ieee80211_cqm_rssi_notify(
  1547. &sdata->vif,
  1548. NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW,
  1549. GFP_KERNEL);
  1550. } else if (sig > thold &&
  1551. (last_event == 0 || sig > last_event + hyst)) {
  1552. ifmgd->last_cqm_event_signal = sig;
  1553. ieee80211_cqm_rssi_notify(
  1554. &sdata->vif,
  1555. NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
  1556. GFP_KERNEL);
  1557. }
  1558. }
  1559. if (ifmgd->flags & IEEE80211_STA_BEACON_POLL) {
  1560. #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
  1561. if (net_ratelimit()) {
  1562. printk(KERN_DEBUG "%s: cancelling probereq poll due "
  1563. "to a received beacon\n", sdata->name);
  1564. }
  1565. #endif
  1566. ifmgd->flags &= ~IEEE80211_STA_BEACON_POLL;
  1567. mutex_lock(&local->iflist_mtx);
  1568. ieee80211_recalc_ps(local, -1);
  1569. mutex_unlock(&local->iflist_mtx);
  1570. }
  1571. /*
  1572. * Push the beacon loss detection into the future since
  1573. * we are processing a beacon from the AP just now.
  1574. */
  1575. ieee80211_sta_reset_beacon_monitor(sdata);
  1576. ncrc = crc32_be(0, (void *)&mgmt->u.beacon.beacon_int, 4);
  1577. ncrc = ieee802_11_parse_elems_crc(mgmt->u.beacon.variable,
  1578. len - baselen, &elems,
  1579. care_about_ies, ncrc);
  1580. if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
  1581. directed_tim = ieee80211_check_tim(elems.tim, elems.tim_len,
  1582. ifmgd->aid);
  1583. if (ncrc != ifmgd->beacon_crc || !ifmgd->beacon_crc_valid) {
  1584. ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems,
  1585. true);
  1586. ieee80211_sta_wmm_params(local, sdata, elems.wmm_param,
  1587. elems.wmm_param_len);
  1588. }
  1589. if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) {
  1590. if (directed_tim) {
  1591. if (local->hw.conf.dynamic_ps_timeout > 0) {
  1592. local->hw.conf.flags &= ~IEEE80211_CONF_PS;
  1593. ieee80211_hw_config(local,
  1594. IEEE80211_CONF_CHANGE_PS);
  1595. ieee80211_send_nullfunc(local, sdata, 0);
  1596. } else {
  1597. local->pspolling = true;
  1598. /*
  1599. * Here is assumed that the driver will be
  1600. * able to send ps-poll frame and receive a
  1601. * response even though power save mode is
  1602. * enabled, but some drivers might require
  1603. * to disable power save here. This needs
  1604. * to be investigated.
  1605. */
  1606. ieee80211_send_pspoll(local, sdata);
  1607. }
  1608. }
  1609. }
  1610. if (ncrc == ifmgd->beacon_crc && ifmgd->beacon_crc_valid)
  1611. return;
  1612. ifmgd->beacon_crc = ncrc;
  1613. ifmgd->beacon_crc_valid = true;
  1614. if (elems.erp_info && elems.erp_info_len >= 1) {
  1615. erp_valid = true;
  1616. erp_value = elems.erp_info[0];
  1617. } else {
  1618. erp_valid = false;
  1619. }
  1620. changed |= ieee80211_handle_bss_capability(sdata,
  1621. le16_to_cpu(mgmt->u.beacon.capab_info),
  1622. erp_valid, erp_value);
  1623. if (elems.ht_cap_elem && elems.ht_info_elem && elems.wmm_param &&
  1624. !(ifmgd->flags & IEEE80211_STA_DISABLE_11N)) {
  1625. struct sta_info *sta;
  1626. struct ieee80211_supported_band *sband;
  1627. u16 ap_ht_cap_flags;
  1628. rcu_read_lock();
  1629. sta = sta_info_get(sdata, bssid);
  1630. if (WARN_ON(!sta)) {
  1631. rcu_read_unlock();
  1632. return;
  1633. }
  1634. sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
  1635. ieee80211_ht_cap_ie_to_sta_ht_cap(sband,
  1636. elems.ht_cap_elem, &sta->sta.ht_cap);
  1637. ap_ht_cap_flags = sta->sta.ht_cap.cap;
  1638. rcu_read_unlock();
  1639. changed |= ieee80211_enable_ht(sdata, elems.ht_info_elem,
  1640. bssid, ap_ht_cap_flags, true);
  1641. }
  1642. /* Note: country IE parsing is done for us by cfg80211 */
  1643. if (elems.country_elem) {
  1644. /* TODO: IBSS also needs this */
  1645. if (elems.pwr_constr_elem)
  1646. ieee80211_handle_pwr_constr(sdata,
  1647. le16_to_cpu(mgmt->u.probe_resp.capab_info),
  1648. elems.pwr_constr_elem,
  1649. elems.pwr_constr_elem_len);
  1650. }
  1651. ieee80211_bss_info_change_notify(sdata, changed);
  1652. }
  1653. void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
  1654. struct sk_buff *skb)
  1655. {
  1656. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1657. struct ieee80211_rx_status *rx_status;
  1658. struct ieee80211_mgmt *mgmt;
  1659. enum rx_mgmt_action rma = RX_MGMT_NONE;
  1660. u16 fc;
  1661. rx_status = (struct ieee80211_rx_status *) skb->cb;
  1662. mgmt = (struct ieee80211_mgmt *) skb->data;
  1663. fc = le16_to_cpu(mgmt->frame_control);
  1664. mutex_lock(&ifmgd->mtx);
  1665. if (ifmgd->associated &&
  1666. memcmp(ifmgd->associated->bssid, mgmt->bssid, ETH_ALEN) == 0) {
  1667. switch (fc & IEEE80211_FCTL_STYPE) {
  1668. case IEEE80211_STYPE_BEACON:
  1669. ieee80211_rx_mgmt_beacon(sdata, mgmt, skb->len,
  1670. rx_status);
  1671. break;
  1672. case IEEE80211_STYPE_PROBE_RESP:
  1673. ieee80211_rx_mgmt_probe_resp(sdata, skb);
  1674. break;
  1675. case IEEE80211_STYPE_DEAUTH:
  1676. rma = ieee80211_rx_mgmt_deauth(sdata, mgmt, skb->len);
  1677. break;
  1678. case IEEE80211_STYPE_DISASSOC:
  1679. rma = ieee80211_rx_mgmt_disassoc(sdata, mgmt, skb->len);
  1680. break;
  1681. case IEEE80211_STYPE_ACTION:
  1682. switch (mgmt->u.action.category) {
  1683. case WLAN_CATEGORY_SPECTRUM_MGMT:
  1684. ieee80211_sta_process_chanswitch(sdata,
  1685. &mgmt->u.action.u.chan_switch.sw_elem,
  1686. (void *)ifmgd->associated->priv,
  1687. rx_status->mactime);
  1688. break;
  1689. }
  1690. }
  1691. mutex_unlock(&ifmgd->mtx);
  1692. switch (rma) {
  1693. case RX_MGMT_NONE:
  1694. /* no action */
  1695. break;
  1696. case RX_MGMT_CFG80211_DEAUTH:
  1697. cfg80211_send_deauth(sdata->dev, (u8 *)mgmt, skb->len);
  1698. break;
  1699. case RX_MGMT_CFG80211_DISASSOC:
  1700. cfg80211_send_disassoc(sdata->dev, (u8 *)mgmt, skb->len);
  1701. break;
  1702. default:
  1703. WARN(1, "unexpected: %d", rma);
  1704. }
  1705. return;
  1706. }
  1707. mutex_unlock(&ifmgd->mtx);
  1708. if (skb->len >= 24 + 2 /* mgmt + deauth reason */ &&
  1709. (fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_DEAUTH) {
  1710. struct ieee80211_local *local = sdata->local;
  1711. struct ieee80211_work *wk;
  1712. mutex_lock(&local->mtx);
  1713. list_for_each_entry(wk, &local->work_list, list) {
  1714. if (wk->sdata != sdata)
  1715. continue;
  1716. if (wk->type != IEEE80211_WORK_ASSOC &&
  1717. wk->type != IEEE80211_WORK_ASSOC_BEACON_WAIT)
  1718. continue;
  1719. if (memcmp(mgmt->bssid, wk->filter_ta, ETH_ALEN))
  1720. continue;
  1721. if (memcmp(mgmt->sa, wk->filter_ta, ETH_ALEN))
  1722. continue;
  1723. /*
  1724. * Printing the message only here means we can't
  1725. * spuriously print it, but it also means that it
  1726. * won't be printed when the frame comes in before
  1727. * we even tried to associate or in similar cases.
  1728. *
  1729. * Ultimately, I suspect cfg80211 should print the
  1730. * messages instead.
  1731. */
  1732. printk(KERN_DEBUG
  1733. "%s: deauthenticated from %pM (Reason: %u)\n",
  1734. sdata->name, mgmt->bssid,
  1735. le16_to_cpu(mgmt->u.deauth.reason_code));
  1736. list_del_rcu(&wk->list);
  1737. free_work(wk);
  1738. break;
  1739. }
  1740. mutex_unlock(&local->mtx);
  1741. cfg80211_send_deauth(sdata->dev, (u8 *)mgmt, skb->len);
  1742. }
  1743. }
  1744. static void ieee80211_sta_timer(unsigned long data)
  1745. {
  1746. struct ieee80211_sub_if_data *sdata =
  1747. (struct ieee80211_sub_if_data *) data;
  1748. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1749. struct ieee80211_local *local = sdata->local;
  1750. if (local->quiescing) {
  1751. set_bit(TMR_RUNNING_TIMER, &ifmgd->timers_running);
  1752. return;
  1753. }
  1754. ieee80211_queue_work(&local->hw, &sdata->work);
  1755. }
  1756. static void ieee80211_sta_connection_lost(struct ieee80211_sub_if_data *sdata,
  1757. u8 *bssid, u8 reason)
  1758. {
  1759. struct ieee80211_local *local = sdata->local;
  1760. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1761. ifmgd->flags &= ~(IEEE80211_STA_CONNECTION_POLL |
  1762. IEEE80211_STA_BEACON_POLL);
  1763. ieee80211_set_disassoc(sdata, true, true);
  1764. mutex_unlock(&ifmgd->mtx);
  1765. /*
  1766. * must be outside lock due to cfg80211,
  1767. * but that's not a problem.
  1768. */
  1769. ieee80211_send_deauth_disassoc(sdata, bssid,
  1770. IEEE80211_STYPE_DEAUTH, reason,
  1771. NULL, true);
  1772. mutex_lock(&local->mtx);
  1773. ieee80211_recalc_idle(local);
  1774. mutex_unlock(&local->mtx);
  1775. mutex_lock(&ifmgd->mtx);
  1776. }
  1777. void ieee80211_sta_work(struct ieee80211_sub_if_data *sdata)
  1778. {
  1779. struct ieee80211_local *local = sdata->local;
  1780. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1781. /* then process the rest of the work */
  1782. mutex_lock(&ifmgd->mtx);
  1783. if (ifmgd->flags & (IEEE80211_STA_BEACON_POLL |
  1784. IEEE80211_STA_CONNECTION_POLL) &&
  1785. ifmgd->associated) {
  1786. u8 bssid[ETH_ALEN];
  1787. int max_tries;
  1788. memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN);
  1789. if (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS)
  1790. max_tries = max_nullfunc_tries;
  1791. else
  1792. max_tries = max_probe_tries;
  1793. /* ACK received for nullfunc probing frame */
  1794. if (!ifmgd->probe_send_count)
  1795. ieee80211_reset_ap_probe(sdata);
  1796. else if (ifmgd->nullfunc_failed) {
  1797. if (ifmgd->probe_send_count < max_tries) {
  1798. #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
  1799. wiphy_debug(local->hw.wiphy,
  1800. "%s: No ack for nullfunc frame to"
  1801. " AP %pM, try %d/%i\n",
  1802. sdata->name, bssid,
  1803. ifmgd->probe_send_count, max_tries);
  1804. #endif
  1805. ieee80211_mgd_probe_ap_send(sdata);
  1806. } else {
  1807. #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
  1808. wiphy_debug(local->hw.wiphy,
  1809. "%s: No ack for nullfunc frame to"
  1810. " AP %pM, disconnecting.\n",
  1811. sdata->name, bssid);
  1812. #endif
  1813. ieee80211_sta_connection_lost(sdata, bssid,
  1814. WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY);
  1815. }
  1816. } else if (time_is_after_jiffies(ifmgd->probe_timeout))
  1817. run_again(ifmgd, ifmgd->probe_timeout);
  1818. else if (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS) {
  1819. #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
  1820. wiphy_debug(local->hw.wiphy,
  1821. "%s: Failed to send nullfunc to AP %pM"
  1822. " after %dms, disconnecting.\n",
  1823. sdata->name,
  1824. bssid, probe_wait_ms);
  1825. #endif
  1826. ieee80211_sta_connection_lost(sdata, bssid,
  1827. WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY);
  1828. } else if (ifmgd->probe_send_count < max_tries) {
  1829. #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
  1830. wiphy_debug(local->hw.wiphy,
  1831. "%s: No probe response from AP %pM"
  1832. " after %dms, try %d/%i\n",
  1833. sdata->name,
  1834. bssid, probe_wait_ms,
  1835. ifmgd->probe_send_count, max_tries);
  1836. #endif
  1837. ieee80211_mgd_probe_ap_send(sdata);
  1838. } else {
  1839. /*
  1840. * We actually lost the connection ... or did we?
  1841. * Let's make sure!
  1842. */
  1843. wiphy_debug(local->hw.wiphy,
  1844. "%s: No probe response from AP %pM"
  1845. " after %dms, disconnecting.\n",
  1846. sdata->name,
  1847. bssid, probe_wait_ms);
  1848. ieee80211_sta_connection_lost(sdata, bssid,
  1849. WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY);
  1850. }
  1851. }
  1852. mutex_unlock(&ifmgd->mtx);
  1853. }
  1854. static void ieee80211_sta_bcn_mon_timer(unsigned long data)
  1855. {
  1856. struct ieee80211_sub_if_data *sdata =
  1857. (struct ieee80211_sub_if_data *) data;
  1858. struct ieee80211_local *local = sdata->local;
  1859. if (local->quiescing)
  1860. return;
  1861. ieee80211_queue_work(&sdata->local->hw,
  1862. &sdata->u.mgd.beacon_connection_loss_work);
  1863. }
  1864. static void ieee80211_sta_conn_mon_timer(unsigned long data)
  1865. {
  1866. struct ieee80211_sub_if_data *sdata =
  1867. (struct ieee80211_sub_if_data *) data;
  1868. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1869. struct ieee80211_local *local = sdata->local;
  1870. if (local->quiescing)
  1871. return;
  1872. ieee80211_queue_work(&local->hw, &ifmgd->monitor_work);
  1873. }
  1874. static void ieee80211_sta_monitor_work(struct work_struct *work)
  1875. {
  1876. struct ieee80211_sub_if_data *sdata =
  1877. container_of(work, struct ieee80211_sub_if_data,
  1878. u.mgd.monitor_work);
  1879. ieee80211_mgd_probe_ap(sdata, false);
  1880. }
  1881. static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data *sdata)
  1882. {
  1883. if (sdata->vif.type == NL80211_IFTYPE_STATION) {
  1884. sdata->u.mgd.flags &= ~(IEEE80211_STA_BEACON_POLL |
  1885. IEEE80211_STA_CONNECTION_POLL);
  1886. /* let's probe the connection once */
  1887. ieee80211_queue_work(&sdata->local->hw,
  1888. &sdata->u.mgd.monitor_work);
  1889. /* and do all the other regular work too */
  1890. ieee80211_queue_work(&sdata->local->hw, &sdata->work);
  1891. }
  1892. }
  1893. #ifdef CONFIG_PM
  1894. void ieee80211_sta_quiesce(struct ieee80211_sub_if_data *sdata)
  1895. {
  1896. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1897. /*
  1898. * we need to use atomic bitops for the running bits
  1899. * only because both timers might fire at the same
  1900. * time -- the code here is properly synchronised.
  1901. */
  1902. cancel_work_sync(&ifmgd->request_smps_work);
  1903. cancel_work_sync(&ifmgd->beacon_connection_loss_work);
  1904. if (del_timer_sync(&ifmgd->timer))
  1905. set_bit(TMR_RUNNING_TIMER, &ifmgd->timers_running);
  1906. cancel_work_sync(&ifmgd->chswitch_work);
  1907. if (del_timer_sync(&ifmgd->chswitch_timer))
  1908. set_bit(TMR_RUNNING_CHANSW, &ifmgd->timers_running);
  1909. cancel_work_sync(&ifmgd->monitor_work);
  1910. /* these will just be re-established on connection */
  1911. del_timer_sync(&ifmgd->conn_mon_timer);
  1912. del_timer_sync(&ifmgd->bcn_mon_timer);
  1913. }
  1914. void ieee80211_sta_restart(struct ieee80211_sub_if_data *sdata)
  1915. {
  1916. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1917. if (!ifmgd->associated)
  1918. return;
  1919. if (sdata->flags & IEEE80211_SDATA_DISCONNECT_RESUME) {
  1920. sdata->flags &= ~IEEE80211_SDATA_DISCONNECT_RESUME;
  1921. mutex_lock(&ifmgd->mtx);
  1922. if (ifmgd->associated) {
  1923. #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
  1924. wiphy_debug(sdata->local->hw.wiphy,
  1925. "%s: driver requested disconnect after resume.\n",
  1926. sdata->name);
  1927. #endif
  1928. ieee80211_sta_connection_lost(sdata,
  1929. ifmgd->associated->bssid,
  1930. WLAN_REASON_UNSPECIFIED);
  1931. mutex_unlock(&ifmgd->mtx);
  1932. return;
  1933. }
  1934. mutex_unlock(&ifmgd->mtx);
  1935. }
  1936. if (test_and_clear_bit(TMR_RUNNING_TIMER, &ifmgd->timers_running))
  1937. add_timer(&ifmgd->timer);
  1938. if (test_and_clear_bit(TMR_RUNNING_CHANSW, &ifmgd->timers_running))
  1939. add_timer(&ifmgd->chswitch_timer);
  1940. ieee80211_sta_reset_beacon_monitor(sdata);
  1941. ieee80211_restart_sta_timer(sdata);
  1942. ieee80211_queue_work(&sdata->local->hw, &sdata->u.mgd.monitor_work);
  1943. }
  1944. #endif
  1945. /* interface setup */
  1946. void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata)
  1947. {
  1948. struct ieee80211_if_managed *ifmgd;
  1949. ifmgd = &sdata->u.mgd;
  1950. INIT_WORK(&ifmgd->monitor_work, ieee80211_sta_monitor_work);
  1951. INIT_WORK(&ifmgd->chswitch_work, ieee80211_chswitch_work);
  1952. INIT_WORK(&ifmgd->beacon_connection_loss_work,
  1953. ieee80211_beacon_connection_loss_work);
  1954. INIT_WORK(&ifmgd->request_smps_work, ieee80211_request_smps_work);
  1955. setup_timer(&ifmgd->timer, ieee80211_sta_timer,
  1956. (unsigned long) sdata);
  1957. setup_timer(&ifmgd->bcn_mon_timer, ieee80211_sta_bcn_mon_timer,
  1958. (unsigned long) sdata);
  1959. setup_timer(&ifmgd->conn_mon_timer, ieee80211_sta_conn_mon_timer,
  1960. (unsigned long) sdata);
  1961. setup_timer(&ifmgd->chswitch_timer, ieee80211_chswitch_timer,
  1962. (unsigned long) sdata);
  1963. ifmgd->flags = 0;
  1964. mutex_init(&ifmgd->mtx);
  1965. if (sdata->local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS)
  1966. ifmgd->req_smps = IEEE80211_SMPS_AUTOMATIC;
  1967. else
  1968. ifmgd->req_smps = IEEE80211_SMPS_OFF;
  1969. }
  1970. /* scan finished notification */
  1971. void ieee80211_mlme_notify_scan_completed(struct ieee80211_local *local)
  1972. {
  1973. struct ieee80211_sub_if_data *sdata = local->scan_sdata;
  1974. /* Restart STA timers */
  1975. rcu_read_lock();
  1976. list_for_each_entry_rcu(sdata, &local->interfaces, list)
  1977. ieee80211_restart_sta_timer(sdata);
  1978. rcu_read_unlock();
  1979. }
  1980. int ieee80211_max_network_latency(struct notifier_block *nb,
  1981. unsigned long data, void *dummy)
  1982. {
  1983. s32 latency_usec = (s32) data;
  1984. struct ieee80211_local *local =
  1985. container_of(nb, struct ieee80211_local,
  1986. network_latency_notifier);
  1987. mutex_lock(&local->iflist_mtx);
  1988. ieee80211_recalc_ps(local, latency_usec);
  1989. mutex_unlock(&local->iflist_mtx);
  1990. return 0;
  1991. }
  1992. /* config hooks */
  1993. static enum work_done_result
  1994. ieee80211_probe_auth_done(struct ieee80211_work *wk,
  1995. struct sk_buff *skb)
  1996. {
  1997. struct ieee80211_local *local = wk->sdata->local;
  1998. if (!skb) {
  1999. cfg80211_send_auth_timeout(wk->sdata->dev, wk->filter_ta);
  2000. goto destroy;
  2001. }
  2002. if (wk->type == IEEE80211_WORK_AUTH) {
  2003. cfg80211_send_rx_auth(wk->sdata->dev, skb->data, skb->len);
  2004. goto destroy;
  2005. }
  2006. mutex_lock(&wk->sdata->u.mgd.mtx);
  2007. ieee80211_rx_mgmt_probe_resp(wk->sdata, skb);
  2008. mutex_unlock(&wk->sdata->u.mgd.mtx);
  2009. wk->type = IEEE80211_WORK_AUTH;
  2010. wk->probe_auth.tries = 0;
  2011. return WORK_DONE_REQUEUE;
  2012. destroy:
  2013. if (wk->probe_auth.synced)
  2014. drv_finish_tx_sync(local, wk->sdata, wk->filter_ta,
  2015. IEEE80211_TX_SYNC_AUTH);
  2016. return WORK_DONE_DESTROY;
  2017. }
  2018. int ieee80211_mgd_auth(struct ieee80211_sub_if_data *sdata,
  2019. struct cfg80211_auth_request *req)
  2020. {
  2021. const u8 *ssid;
  2022. struct ieee80211_work *wk;
  2023. u16 auth_alg;
  2024. if (req->local_state_change)
  2025. return 0; /* no need to update mac80211 state */
  2026. switch (req->auth_type) {
  2027. case NL80211_AUTHTYPE_OPEN_SYSTEM:
  2028. auth_alg = WLAN_AUTH_OPEN;
  2029. break;
  2030. case NL80211_AUTHTYPE_SHARED_KEY:
  2031. if (IS_ERR(sdata->local->wep_tx_tfm))
  2032. return -EOPNOTSUPP;
  2033. auth_alg = WLAN_AUTH_SHARED_KEY;
  2034. break;
  2035. case NL80211_AUTHTYPE_FT:
  2036. auth_alg = WLAN_AUTH_FT;
  2037. break;
  2038. case NL80211_AUTHTYPE_NETWORK_EAP:
  2039. auth_alg = WLAN_AUTH_LEAP;
  2040. break;
  2041. default:
  2042. return -EOPNOTSUPP;
  2043. }
  2044. wk = kzalloc(sizeof(*wk) + req->ie_len, GFP_KERNEL);
  2045. if (!wk)
  2046. return -ENOMEM;
  2047. memcpy(wk->filter_ta, req->bss->bssid, ETH_ALEN);
  2048. if (req->ie && req->ie_len) {
  2049. memcpy(wk->ie, req->ie, req->ie_len);
  2050. wk->ie_len = req->ie_len;
  2051. }
  2052. if (req->key && req->key_len) {
  2053. wk->probe_auth.key_len = req->key_len;
  2054. wk->probe_auth.key_idx = req->key_idx;
  2055. memcpy(wk->probe_auth.key, req->key, req->key_len);
  2056. }
  2057. ssid = ieee80211_bss_get_ie(req->bss, WLAN_EID_SSID);
  2058. memcpy(wk->probe_auth.ssid, ssid + 2, ssid[1]);
  2059. wk->probe_auth.ssid_len = ssid[1];
  2060. wk->probe_auth.algorithm = auth_alg;
  2061. wk->probe_auth.privacy = req->bss->capability & WLAN_CAPABILITY_PRIVACY;
  2062. /* if we already have a probe, don't probe again */
  2063. if (req->bss->proberesp_ies)
  2064. wk->type = IEEE80211_WORK_AUTH;
  2065. else
  2066. wk->type = IEEE80211_WORK_DIRECT_PROBE;
  2067. wk->chan = req->bss->channel;
  2068. wk->chan_type = NL80211_CHAN_NO_HT;
  2069. wk->sdata = sdata;
  2070. wk->done = ieee80211_probe_auth_done;
  2071. ieee80211_add_work(wk);
  2072. return 0;
  2073. }
  2074. /* create and insert a dummy station entry */
  2075. static int ieee80211_pre_assoc(struct ieee80211_sub_if_data *sdata,
  2076. u8 *bssid) {
  2077. struct sta_info *sta;
  2078. int err;
  2079. sta = sta_info_alloc(sdata, bssid, GFP_KERNEL);
  2080. if (!sta)
  2081. return -ENOMEM;
  2082. sta->dummy = true;
  2083. err = sta_info_insert(sta);
  2084. sta = NULL;
  2085. if (err) {
  2086. printk(KERN_DEBUG "%s: failed to insert Dummy STA entry for"
  2087. " the AP (error %d)\n", sdata->name, err);
  2088. return err;
  2089. }
  2090. return 0;
  2091. }
  2092. static enum work_done_result ieee80211_assoc_done(struct ieee80211_work *wk,
  2093. struct sk_buff *skb)
  2094. {
  2095. struct ieee80211_local *local = wk->sdata->local;
  2096. struct ieee80211_mgmt *mgmt;
  2097. struct ieee80211_rx_status *rx_status;
  2098. struct ieee802_11_elems elems;
  2099. struct cfg80211_bss *cbss = wk->assoc.bss;
  2100. u16 status;
  2101. if (!skb) {
  2102. sta_info_destroy_addr(wk->sdata, cbss->bssid);
  2103. cfg80211_send_assoc_timeout(wk->sdata->dev, wk->filter_ta);
  2104. goto destroy;
  2105. }
  2106. if (wk->type == IEEE80211_WORK_ASSOC_BEACON_WAIT) {
  2107. mutex_lock(&wk->sdata->u.mgd.mtx);
  2108. rx_status = (void *) skb->cb;
  2109. ieee802_11_parse_elems(skb->data + 24 + 12, skb->len - 24 - 12, &elems);
  2110. ieee80211_rx_bss_info(wk->sdata, (void *)skb->data, skb->len, rx_status,
  2111. &elems, true);
  2112. mutex_unlock(&wk->sdata->u.mgd.mtx);
  2113. wk->type = IEEE80211_WORK_ASSOC;
  2114. /* not really done yet */
  2115. return WORK_DONE_REQUEUE;
  2116. }
  2117. mgmt = (void *)skb->data;
  2118. status = le16_to_cpu(mgmt->u.assoc_resp.status_code);
  2119. if (status == WLAN_STATUS_SUCCESS) {
  2120. if (wk->assoc.synced)
  2121. drv_finish_tx_sync(local, wk->sdata, wk->filter_ta,
  2122. IEEE80211_TX_SYNC_ASSOC);
  2123. mutex_lock(&wk->sdata->u.mgd.mtx);
  2124. if (!ieee80211_assoc_success(wk, mgmt, skb->len)) {
  2125. mutex_unlock(&wk->sdata->u.mgd.mtx);
  2126. /* oops -- internal error -- send timeout for now */
  2127. sta_info_destroy_addr(wk->sdata, cbss->bssid);
  2128. cfg80211_send_assoc_timeout(wk->sdata->dev,
  2129. wk->filter_ta);
  2130. return WORK_DONE_DESTROY;
  2131. }
  2132. mutex_unlock(&wk->sdata->u.mgd.mtx);
  2133. } else {
  2134. /* assoc failed - destroy the dummy station entry */
  2135. sta_info_destroy_addr(wk->sdata, cbss->bssid);
  2136. }
  2137. cfg80211_send_rx_assoc(wk->sdata->dev, skb->data, skb->len);
  2138. destroy:
  2139. if (wk->assoc.synced)
  2140. drv_finish_tx_sync(local, wk->sdata, wk->filter_ta,
  2141. IEEE80211_TX_SYNC_ASSOC);
  2142. return WORK_DONE_DESTROY;
  2143. }
  2144. int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata,
  2145. struct cfg80211_assoc_request *req)
  2146. {
  2147. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  2148. struct ieee80211_bss *bss = (void *)req->bss->priv;
  2149. struct ieee80211_work *wk;
  2150. const u8 *ssid;
  2151. int i, err;
  2152. mutex_lock(&ifmgd->mtx);
  2153. if (ifmgd->associated) {
  2154. if (!req->prev_bssid ||
  2155. memcmp(req->prev_bssid, ifmgd->associated->bssid,
  2156. ETH_ALEN)) {
  2157. /*
  2158. * We are already associated and the request was not a
  2159. * reassociation request from the current BSS, so
  2160. * reject it.
  2161. */
  2162. mutex_unlock(&ifmgd->mtx);
  2163. return -EALREADY;
  2164. }
  2165. /* Trying to reassociate - clear previous association state */
  2166. ieee80211_set_disassoc(sdata, true, false);
  2167. }
  2168. mutex_unlock(&ifmgd->mtx);
  2169. wk = kzalloc(sizeof(*wk) + req->ie_len, GFP_KERNEL);
  2170. if (!wk)
  2171. return -ENOMEM;
  2172. /*
  2173. * create a dummy station info entry in order
  2174. * to start accepting incoming EAPOL packets from the station
  2175. */
  2176. err = ieee80211_pre_assoc(sdata, req->bss->bssid);
  2177. if (err) {
  2178. kfree(wk);
  2179. return err;
  2180. }
  2181. ifmgd->flags &= ~IEEE80211_STA_DISABLE_11N;
  2182. ifmgd->flags &= ~IEEE80211_STA_NULLFUNC_ACKED;
  2183. ifmgd->beacon_crc_valid = false;
  2184. for (i = 0; i < req->crypto.n_ciphers_pairwise; i++)
  2185. if (req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP40 ||
  2186. req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_TKIP ||
  2187. req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP104)
  2188. ifmgd->flags |= IEEE80211_STA_DISABLE_11N;
  2189. if (req->ie && req->ie_len) {
  2190. memcpy(wk->ie, req->ie, req->ie_len);
  2191. wk->ie_len = req->ie_len;
  2192. } else
  2193. wk->ie_len = 0;
  2194. wk->assoc.bss = req->bss;
  2195. memcpy(wk->filter_ta, req->bss->bssid, ETH_ALEN);
  2196. /* new association always uses requested smps mode */
  2197. if (ifmgd->req_smps == IEEE80211_SMPS_AUTOMATIC) {
  2198. if (ifmgd->powersave)
  2199. ifmgd->ap_smps = IEEE80211_SMPS_DYNAMIC;
  2200. else
  2201. ifmgd->ap_smps = IEEE80211_SMPS_OFF;
  2202. } else
  2203. ifmgd->ap_smps = ifmgd->req_smps;
  2204. wk->assoc.smps = ifmgd->ap_smps;
  2205. /*
  2206. * IEEE802.11n does not allow TKIP/WEP as pairwise ciphers in HT mode.
  2207. * We still associate in non-HT mode (11a/b/g) if any one of these
  2208. * ciphers is configured as pairwise.
  2209. * We can set this to true for non-11n hardware, that'll be checked
  2210. * separately along with the peer capabilities.
  2211. */
  2212. wk->assoc.use_11n = !(ifmgd->flags & IEEE80211_STA_DISABLE_11N);
  2213. wk->assoc.capability = req->bss->capability;
  2214. wk->assoc.wmm_used = bss->wmm_used;
  2215. wk->assoc.supp_rates = bss->supp_rates;
  2216. wk->assoc.supp_rates_len = bss->supp_rates_len;
  2217. wk->assoc.ht_information_ie =
  2218. ieee80211_bss_get_ie(req->bss, WLAN_EID_HT_INFORMATION);
  2219. if (bss->wmm_used && bss->uapsd_supported &&
  2220. (sdata->local->hw.flags & IEEE80211_HW_SUPPORTS_UAPSD)) {
  2221. wk->assoc.uapsd_used = true;
  2222. ifmgd->flags |= IEEE80211_STA_UAPSD_ENABLED;
  2223. } else {
  2224. wk->assoc.uapsd_used = false;
  2225. ifmgd->flags &= ~IEEE80211_STA_UAPSD_ENABLED;
  2226. }
  2227. ssid = ieee80211_bss_get_ie(req->bss, WLAN_EID_SSID);
  2228. memcpy(wk->assoc.ssid, ssid + 2, ssid[1]);
  2229. wk->assoc.ssid_len = ssid[1];
  2230. if (req->prev_bssid)
  2231. memcpy(wk->assoc.prev_bssid, req->prev_bssid, ETH_ALEN);
  2232. wk->chan = req->bss->channel;
  2233. wk->chan_type = NL80211_CHAN_NO_HT;
  2234. wk->sdata = sdata;
  2235. wk->done = ieee80211_assoc_done;
  2236. if (!bss->dtim_period &&
  2237. sdata->local->hw.flags & IEEE80211_HW_NEED_DTIM_PERIOD)
  2238. wk->type = IEEE80211_WORK_ASSOC_BEACON_WAIT;
  2239. else
  2240. wk->type = IEEE80211_WORK_ASSOC;
  2241. if (req->use_mfp) {
  2242. ifmgd->mfp = IEEE80211_MFP_REQUIRED;
  2243. ifmgd->flags |= IEEE80211_STA_MFP_ENABLED;
  2244. } else {
  2245. ifmgd->mfp = IEEE80211_MFP_DISABLED;
  2246. ifmgd->flags &= ~IEEE80211_STA_MFP_ENABLED;
  2247. }
  2248. if (req->crypto.control_port)
  2249. ifmgd->flags |= IEEE80211_STA_CONTROL_PORT;
  2250. else
  2251. ifmgd->flags &= ~IEEE80211_STA_CONTROL_PORT;
  2252. sdata->control_port_protocol = req->crypto.control_port_ethertype;
  2253. sdata->control_port_no_encrypt = req->crypto.control_port_no_encrypt;
  2254. ieee80211_add_work(wk);
  2255. return 0;
  2256. }
  2257. int ieee80211_mgd_deauth(struct ieee80211_sub_if_data *sdata,
  2258. struct cfg80211_deauth_request *req,
  2259. void *cookie)
  2260. {
  2261. struct ieee80211_local *local = sdata->local;
  2262. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  2263. struct ieee80211_work *wk;
  2264. u8 bssid[ETH_ALEN];
  2265. bool assoc_bss = false;
  2266. mutex_lock(&ifmgd->mtx);
  2267. memcpy(bssid, req->bss->bssid, ETH_ALEN);
  2268. if (ifmgd->associated == req->bss) {
  2269. ieee80211_set_disassoc(sdata, false, true);
  2270. mutex_unlock(&ifmgd->mtx);
  2271. assoc_bss = true;
  2272. } else {
  2273. bool not_auth_yet = false;
  2274. mutex_unlock(&ifmgd->mtx);
  2275. mutex_lock(&local->mtx);
  2276. list_for_each_entry(wk, &local->work_list, list) {
  2277. if (wk->sdata != sdata)
  2278. continue;
  2279. if (wk->type != IEEE80211_WORK_DIRECT_PROBE &&
  2280. wk->type != IEEE80211_WORK_AUTH &&
  2281. wk->type != IEEE80211_WORK_ASSOC &&
  2282. wk->type != IEEE80211_WORK_ASSOC_BEACON_WAIT)
  2283. continue;
  2284. if (memcmp(req->bss->bssid, wk->filter_ta, ETH_ALEN))
  2285. continue;
  2286. not_auth_yet = wk->type == IEEE80211_WORK_DIRECT_PROBE;
  2287. list_del_rcu(&wk->list);
  2288. free_work(wk);
  2289. break;
  2290. }
  2291. mutex_unlock(&local->mtx);
  2292. /*
  2293. * If somebody requests authentication and we haven't
  2294. * sent out an auth frame yet there's no need to send
  2295. * out a deauth frame either. If the state was PROBE,
  2296. * then this is the case. If it's AUTH we have sent a
  2297. * frame, and if it's IDLE we have completed the auth
  2298. * process already.
  2299. */
  2300. if (not_auth_yet) {
  2301. __cfg80211_auth_canceled(sdata->dev, bssid);
  2302. return 0;
  2303. }
  2304. }
  2305. printk(KERN_DEBUG "%s: deauthenticating from %pM by local choice (reason=%d)\n",
  2306. sdata->name, bssid, req->reason_code);
  2307. ieee80211_send_deauth_disassoc(sdata, bssid, IEEE80211_STYPE_DEAUTH,
  2308. req->reason_code, cookie,
  2309. !req->local_state_change);
  2310. if (assoc_bss)
  2311. sta_info_flush(sdata->local, sdata);
  2312. mutex_lock(&sdata->local->mtx);
  2313. ieee80211_recalc_idle(sdata->local);
  2314. mutex_unlock(&sdata->local->mtx);
  2315. return 0;
  2316. }
  2317. int ieee80211_mgd_disassoc(struct ieee80211_sub_if_data *sdata,
  2318. struct cfg80211_disassoc_request *req,
  2319. void *cookie)
  2320. {
  2321. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  2322. u8 bssid[ETH_ALEN];
  2323. mutex_lock(&ifmgd->mtx);
  2324. /*
  2325. * cfg80211 should catch this ... but it's racy since
  2326. * we can receive a disassoc frame, process it, hand it
  2327. * to cfg80211 while that's in a locked section already
  2328. * trying to tell us that the user wants to disconnect.
  2329. */
  2330. if (ifmgd->associated != req->bss) {
  2331. mutex_unlock(&ifmgd->mtx);
  2332. return -ENOLINK;
  2333. }
  2334. printk(KERN_DEBUG "%s: disassociating from %pM by local choice (reason=%d)\n",
  2335. sdata->name, req->bss->bssid, req->reason_code);
  2336. memcpy(bssid, req->bss->bssid, ETH_ALEN);
  2337. ieee80211_set_disassoc(sdata, false, true);
  2338. mutex_unlock(&ifmgd->mtx);
  2339. ieee80211_send_deauth_disassoc(sdata, req->bss->bssid,
  2340. IEEE80211_STYPE_DISASSOC, req->reason_code,
  2341. cookie, !req->local_state_change);
  2342. sta_info_flush(sdata->local, sdata);
  2343. mutex_lock(&sdata->local->mtx);
  2344. ieee80211_recalc_idle(sdata->local);
  2345. mutex_unlock(&sdata->local->mtx);
  2346. return 0;
  2347. }
  2348. void ieee80211_cqm_rssi_notify(struct ieee80211_vif *vif,
  2349. enum nl80211_cqm_rssi_threshold_event rssi_event,
  2350. gfp_t gfp)
  2351. {
  2352. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  2353. trace_api_cqm_rssi_notify(sdata, rssi_event);
  2354. cfg80211_cqm_rssi_notify(sdata->dev, rssi_event, gfp);
  2355. }
  2356. EXPORT_SYMBOL(ieee80211_cqm_rssi_notify);
  2357. unsigned char ieee80211_get_operstate(struct ieee80211_vif *vif)
  2358. {
  2359. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  2360. return sdata->dev->operstate;
  2361. }
  2362. EXPORT_SYMBOL(ieee80211_get_operstate);