mlme.c 78 KB

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