rx.c 76 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782
  1. /*
  2. * Copyright 2002-2005, Instant802 Networks, Inc.
  3. * Copyright 2005-2006, Devicescape Software, Inc.
  4. * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
  5. * Copyright 2007-2010 Johannes Berg <johannes@sipsolutions.net>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. */
  11. #include <linux/jiffies.h>
  12. #include <linux/slab.h>
  13. #include <linux/kernel.h>
  14. #include <linux/skbuff.h>
  15. #include <linux/netdevice.h>
  16. #include <linux/etherdevice.h>
  17. #include <linux/rcupdate.h>
  18. #include <net/mac80211.h>
  19. #include <net/ieee80211_radiotap.h>
  20. #include "ieee80211_i.h"
  21. #include "driver-ops.h"
  22. #include "led.h"
  23. #include "mesh.h"
  24. #include "wep.h"
  25. #include "wpa.h"
  26. #include "tkip.h"
  27. #include "wme.h"
  28. /*
  29. * monitor mode reception
  30. *
  31. * This function cleans up the SKB, i.e. it removes all the stuff
  32. * only useful for monitoring.
  33. */
  34. static struct sk_buff *remove_monitor_info(struct ieee80211_local *local,
  35. struct sk_buff *skb)
  36. {
  37. if (local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS) {
  38. if (likely(skb->len > FCS_LEN))
  39. __pskb_trim(skb, skb->len - FCS_LEN);
  40. else {
  41. /* driver bug */
  42. WARN_ON(1);
  43. dev_kfree_skb(skb);
  44. skb = NULL;
  45. }
  46. }
  47. return skb;
  48. }
  49. static inline int should_drop_frame(struct sk_buff *skb,
  50. int present_fcs_len)
  51. {
  52. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
  53. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
  54. if (status->flag & (RX_FLAG_FAILED_FCS_CRC | RX_FLAG_FAILED_PLCP_CRC))
  55. return 1;
  56. if (unlikely(skb->len < 16 + present_fcs_len))
  57. return 1;
  58. if (ieee80211_is_ctl(hdr->frame_control) &&
  59. !ieee80211_is_pspoll(hdr->frame_control) &&
  60. !ieee80211_is_back_req(hdr->frame_control))
  61. return 1;
  62. return 0;
  63. }
  64. static int
  65. ieee80211_rx_radiotap_len(struct ieee80211_local *local,
  66. struct ieee80211_rx_status *status)
  67. {
  68. int len;
  69. /* always present fields */
  70. len = sizeof(struct ieee80211_radiotap_header) + 9;
  71. if (status->flag & RX_FLAG_TSFT)
  72. len += 8;
  73. if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM)
  74. len += 1;
  75. if (len & 1) /* padding for RX_FLAGS if necessary */
  76. len++;
  77. return len;
  78. }
  79. /*
  80. * ieee80211_add_rx_radiotap_header - add radiotap header
  81. *
  82. * add a radiotap header containing all the fields which the hardware provided.
  83. */
  84. static void
  85. ieee80211_add_rx_radiotap_header(struct ieee80211_local *local,
  86. struct sk_buff *skb,
  87. struct ieee80211_rate *rate,
  88. int rtap_len)
  89. {
  90. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
  91. struct ieee80211_radiotap_header *rthdr;
  92. unsigned char *pos;
  93. u16 rx_flags = 0;
  94. rthdr = (struct ieee80211_radiotap_header *)skb_push(skb, rtap_len);
  95. memset(rthdr, 0, rtap_len);
  96. /* radiotap header, set always present flags */
  97. rthdr->it_present =
  98. cpu_to_le32((1 << IEEE80211_RADIOTAP_FLAGS) |
  99. (1 << IEEE80211_RADIOTAP_CHANNEL) |
  100. (1 << IEEE80211_RADIOTAP_ANTENNA) |
  101. (1 << IEEE80211_RADIOTAP_RX_FLAGS));
  102. rthdr->it_len = cpu_to_le16(rtap_len);
  103. pos = (unsigned char *)(rthdr+1);
  104. /* the order of the following fields is important */
  105. /* IEEE80211_RADIOTAP_TSFT */
  106. if (status->flag & RX_FLAG_TSFT) {
  107. put_unaligned_le64(status->mactime, pos);
  108. rthdr->it_present |=
  109. cpu_to_le32(1 << IEEE80211_RADIOTAP_TSFT);
  110. pos += 8;
  111. }
  112. /* IEEE80211_RADIOTAP_FLAGS */
  113. if (local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS)
  114. *pos |= IEEE80211_RADIOTAP_F_FCS;
  115. if (status->flag & (RX_FLAG_FAILED_FCS_CRC | RX_FLAG_FAILED_PLCP_CRC))
  116. *pos |= IEEE80211_RADIOTAP_F_BADFCS;
  117. if (status->flag & RX_FLAG_SHORTPRE)
  118. *pos |= IEEE80211_RADIOTAP_F_SHORTPRE;
  119. pos++;
  120. /* IEEE80211_RADIOTAP_RATE */
  121. if (status->flag & RX_FLAG_HT) {
  122. /*
  123. * TODO: add following information into radiotap header once
  124. * suitable fields are defined for it:
  125. * - MCS index (status->rate_idx)
  126. * - HT40 (status->flag & RX_FLAG_40MHZ)
  127. * - short-GI (status->flag & RX_FLAG_SHORT_GI)
  128. */
  129. *pos = 0;
  130. } else {
  131. rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_RATE);
  132. *pos = rate->bitrate / 5;
  133. }
  134. pos++;
  135. /* IEEE80211_RADIOTAP_CHANNEL */
  136. put_unaligned_le16(status->freq, pos);
  137. pos += 2;
  138. if (status->band == IEEE80211_BAND_5GHZ)
  139. put_unaligned_le16(IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ,
  140. pos);
  141. else if (status->flag & RX_FLAG_HT)
  142. put_unaligned_le16(IEEE80211_CHAN_DYN | IEEE80211_CHAN_2GHZ,
  143. pos);
  144. else if (rate->flags & IEEE80211_RATE_ERP_G)
  145. put_unaligned_le16(IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ,
  146. pos);
  147. else
  148. put_unaligned_le16(IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ,
  149. pos);
  150. pos += 2;
  151. /* IEEE80211_RADIOTAP_DBM_ANTSIGNAL */
  152. if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM) {
  153. *pos = status->signal;
  154. rthdr->it_present |=
  155. cpu_to_le32(1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL);
  156. pos++;
  157. }
  158. /* IEEE80211_RADIOTAP_LOCK_QUALITY is missing */
  159. /* IEEE80211_RADIOTAP_ANTENNA */
  160. *pos = status->antenna;
  161. pos++;
  162. /* IEEE80211_RADIOTAP_DB_ANTNOISE is not used */
  163. /* IEEE80211_RADIOTAP_RX_FLAGS */
  164. /* ensure 2 byte alignment for the 2 byte field as required */
  165. if ((pos - (u8 *)rthdr) & 1)
  166. pos++;
  167. if (status->flag & RX_FLAG_FAILED_PLCP_CRC)
  168. rx_flags |= IEEE80211_RADIOTAP_F_RX_BADPLCP;
  169. put_unaligned_le16(rx_flags, pos);
  170. pos += 2;
  171. }
  172. /*
  173. * This function copies a received frame to all monitor interfaces and
  174. * returns a cleaned-up SKB that no longer includes the FCS nor the
  175. * radiotap header the driver might have added.
  176. */
  177. static struct sk_buff *
  178. ieee80211_rx_monitor(struct ieee80211_local *local, struct sk_buff *origskb,
  179. struct ieee80211_rate *rate)
  180. {
  181. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(origskb);
  182. struct ieee80211_sub_if_data *sdata;
  183. int needed_headroom = 0;
  184. struct sk_buff *skb, *skb2;
  185. struct net_device *prev_dev = NULL;
  186. int present_fcs_len = 0;
  187. /*
  188. * First, we may need to make a copy of the skb because
  189. * (1) we need to modify it for radiotap (if not present), and
  190. * (2) the other RX handlers will modify the skb we got.
  191. *
  192. * We don't need to, of course, if we aren't going to return
  193. * the SKB because it has a bad FCS/PLCP checksum.
  194. */
  195. /* room for the radiotap header based on driver features */
  196. needed_headroom = ieee80211_rx_radiotap_len(local, status);
  197. if (local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS)
  198. present_fcs_len = FCS_LEN;
  199. /* make sure hdr->frame_control is on the linear part */
  200. if (!pskb_may_pull(origskb, 2)) {
  201. dev_kfree_skb(origskb);
  202. return NULL;
  203. }
  204. if (!local->monitors) {
  205. if (should_drop_frame(origskb, present_fcs_len)) {
  206. dev_kfree_skb(origskb);
  207. return NULL;
  208. }
  209. return remove_monitor_info(local, origskb);
  210. }
  211. if (should_drop_frame(origskb, present_fcs_len)) {
  212. /* only need to expand headroom if necessary */
  213. skb = origskb;
  214. origskb = NULL;
  215. /*
  216. * This shouldn't trigger often because most devices have an
  217. * RX header they pull before we get here, and that should
  218. * be big enough for our radiotap information. We should
  219. * probably export the length to drivers so that we can have
  220. * them allocate enough headroom to start with.
  221. */
  222. if (skb_headroom(skb) < needed_headroom &&
  223. pskb_expand_head(skb, needed_headroom, 0, GFP_ATOMIC)) {
  224. dev_kfree_skb(skb);
  225. return NULL;
  226. }
  227. } else {
  228. /*
  229. * Need to make a copy and possibly remove radiotap header
  230. * and FCS from the original.
  231. */
  232. skb = skb_copy_expand(origskb, needed_headroom, 0, GFP_ATOMIC);
  233. origskb = remove_monitor_info(local, origskb);
  234. if (!skb)
  235. return origskb;
  236. }
  237. /* prepend radiotap information */
  238. ieee80211_add_rx_radiotap_header(local, skb, rate, needed_headroom);
  239. skb_reset_mac_header(skb);
  240. skb->ip_summed = CHECKSUM_UNNECESSARY;
  241. skb->pkt_type = PACKET_OTHERHOST;
  242. skb->protocol = htons(ETH_P_802_2);
  243. list_for_each_entry_rcu(sdata, &local->interfaces, list) {
  244. if (sdata->vif.type != NL80211_IFTYPE_MONITOR)
  245. continue;
  246. if (sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES)
  247. continue;
  248. if (!ieee80211_sdata_running(sdata))
  249. continue;
  250. if (prev_dev) {
  251. skb2 = skb_clone(skb, GFP_ATOMIC);
  252. if (skb2) {
  253. skb2->dev = prev_dev;
  254. netif_receive_skb(skb2);
  255. }
  256. }
  257. prev_dev = sdata->dev;
  258. sdata->dev->stats.rx_packets++;
  259. sdata->dev->stats.rx_bytes += skb->len;
  260. }
  261. if (prev_dev) {
  262. skb->dev = prev_dev;
  263. netif_receive_skb(skb);
  264. } else
  265. dev_kfree_skb(skb);
  266. return origskb;
  267. }
  268. static void ieee80211_parse_qos(struct ieee80211_rx_data *rx)
  269. {
  270. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
  271. int tid;
  272. /* does the frame have a qos control field? */
  273. if (ieee80211_is_data_qos(hdr->frame_control)) {
  274. u8 *qc = ieee80211_get_qos_ctl(hdr);
  275. /* frame has qos control */
  276. tid = *qc & IEEE80211_QOS_CTL_TID_MASK;
  277. if (*qc & IEEE80211_QOS_CONTROL_A_MSDU_PRESENT)
  278. rx->flags |= IEEE80211_RX_AMSDU;
  279. else
  280. rx->flags &= ~IEEE80211_RX_AMSDU;
  281. } else {
  282. /*
  283. * IEEE 802.11-2007, 7.1.3.4.1 ("Sequence Number field"):
  284. *
  285. * Sequence numbers for management frames, QoS data
  286. * frames with a broadcast/multicast address in the
  287. * Address 1 field, and all non-QoS data frames sent
  288. * by QoS STAs are assigned using an additional single
  289. * modulo-4096 counter, [...]
  290. *
  291. * We also use that counter for non-QoS STAs.
  292. */
  293. tid = NUM_RX_DATA_QUEUES - 1;
  294. }
  295. rx->queue = tid;
  296. /* Set skb->priority to 1d tag if highest order bit of TID is not set.
  297. * For now, set skb->priority to 0 for other cases. */
  298. rx->skb->priority = (tid > 7) ? 0 : tid;
  299. }
  300. /**
  301. * DOC: Packet alignment
  302. *
  303. * Drivers always need to pass packets that are aligned to two-byte boundaries
  304. * to the stack.
  305. *
  306. * Additionally, should, if possible, align the payload data in a way that
  307. * guarantees that the contained IP header is aligned to a four-byte
  308. * boundary. In the case of regular frames, this simply means aligning the
  309. * payload to a four-byte boundary (because either the IP header is directly
  310. * contained, or IV/RFC1042 headers that have a length divisible by four are
  311. * in front of it). If the payload data is not properly aligned and the
  312. * architecture doesn't support efficient unaligned operations, mac80211
  313. * will align the data.
  314. *
  315. * With A-MSDU frames, however, the payload data address must yield two modulo
  316. * four because there are 14-byte 802.3 headers within the A-MSDU frames that
  317. * push the IP header further back to a multiple of four again. Thankfully, the
  318. * specs were sane enough this time around to require padding each A-MSDU
  319. * subframe to a length that is a multiple of four.
  320. *
  321. * Padding like Atheros hardware adds which is inbetween the 802.11 header and
  322. * the payload is not supported, the driver is required to move the 802.11
  323. * header to be directly in front of the payload in that case.
  324. */
  325. static void ieee80211_verify_alignment(struct ieee80211_rx_data *rx)
  326. {
  327. #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
  328. WARN_ONCE((unsigned long)rx->skb->data & 1,
  329. "unaligned packet at 0x%p\n", rx->skb->data);
  330. #endif
  331. }
  332. /* rx handlers */
  333. static ieee80211_rx_result debug_noinline
  334. ieee80211_rx_h_passive_scan(struct ieee80211_rx_data *rx)
  335. {
  336. struct ieee80211_local *local = rx->local;
  337. struct sk_buff *skb = rx->skb;
  338. if (unlikely(test_bit(SCAN_HW_SCANNING, &local->scanning)))
  339. return ieee80211_scan_rx(rx->sdata, skb);
  340. if (unlikely(test_bit(SCAN_SW_SCANNING, &local->scanning) &&
  341. (rx->flags & IEEE80211_RX_IN_SCAN))) {
  342. /* drop all the other packets during a software scan anyway */
  343. if (ieee80211_scan_rx(rx->sdata, skb) != RX_QUEUED)
  344. dev_kfree_skb(skb);
  345. return RX_QUEUED;
  346. }
  347. if (unlikely(rx->flags & IEEE80211_RX_IN_SCAN)) {
  348. /* scanning finished during invoking of handlers */
  349. I802_DEBUG_INC(local->rx_handlers_drop_passive_scan);
  350. return RX_DROP_UNUSABLE;
  351. }
  352. return RX_CONTINUE;
  353. }
  354. static int ieee80211_is_unicast_robust_mgmt_frame(struct sk_buff *skb)
  355. {
  356. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
  357. if (skb->len < 24 || is_multicast_ether_addr(hdr->addr1))
  358. return 0;
  359. return ieee80211_is_robust_mgmt_frame(hdr);
  360. }
  361. static int ieee80211_is_multicast_robust_mgmt_frame(struct sk_buff *skb)
  362. {
  363. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
  364. if (skb->len < 24 || !is_multicast_ether_addr(hdr->addr1))
  365. return 0;
  366. return ieee80211_is_robust_mgmt_frame(hdr);
  367. }
  368. /* Get the BIP key index from MMIE; return -1 if this is not a BIP frame */
  369. static int ieee80211_get_mmie_keyidx(struct sk_buff *skb)
  370. {
  371. struct ieee80211_mgmt *hdr = (struct ieee80211_mgmt *) skb->data;
  372. struct ieee80211_mmie *mmie;
  373. if (skb->len < 24 + sizeof(*mmie) ||
  374. !is_multicast_ether_addr(hdr->da))
  375. return -1;
  376. if (!ieee80211_is_robust_mgmt_frame((struct ieee80211_hdr *) hdr))
  377. return -1; /* not a robust management frame */
  378. mmie = (struct ieee80211_mmie *)
  379. (skb->data + skb->len - sizeof(*mmie));
  380. if (mmie->element_id != WLAN_EID_MMIE ||
  381. mmie->length != sizeof(*mmie) - 2)
  382. return -1;
  383. return le16_to_cpu(mmie->key_id);
  384. }
  385. static ieee80211_rx_result
  386. ieee80211_rx_mesh_check(struct ieee80211_rx_data *rx)
  387. {
  388. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
  389. unsigned int hdrlen = ieee80211_hdrlen(hdr->frame_control);
  390. char *dev_addr = rx->sdata->vif.addr;
  391. if (ieee80211_is_data(hdr->frame_control)) {
  392. if (is_multicast_ether_addr(hdr->addr1)) {
  393. if (ieee80211_has_tods(hdr->frame_control) ||
  394. !ieee80211_has_fromds(hdr->frame_control))
  395. return RX_DROP_MONITOR;
  396. if (memcmp(hdr->addr3, dev_addr, ETH_ALEN) == 0)
  397. return RX_DROP_MONITOR;
  398. } else {
  399. if (!ieee80211_has_a4(hdr->frame_control))
  400. return RX_DROP_MONITOR;
  401. if (memcmp(hdr->addr4, dev_addr, ETH_ALEN) == 0)
  402. return RX_DROP_MONITOR;
  403. }
  404. }
  405. /* If there is not an established peer link and this is not a peer link
  406. * establisment frame, beacon or probe, drop the frame.
  407. */
  408. if (!rx->sta || sta_plink_state(rx->sta) != PLINK_ESTAB) {
  409. struct ieee80211_mgmt *mgmt;
  410. if (!ieee80211_is_mgmt(hdr->frame_control))
  411. return RX_DROP_MONITOR;
  412. if (ieee80211_is_action(hdr->frame_control)) {
  413. mgmt = (struct ieee80211_mgmt *)hdr;
  414. if (mgmt->u.action.category != WLAN_CATEGORY_MESH_PLINK)
  415. return RX_DROP_MONITOR;
  416. return RX_CONTINUE;
  417. }
  418. if (ieee80211_is_probe_req(hdr->frame_control) ||
  419. ieee80211_is_probe_resp(hdr->frame_control) ||
  420. ieee80211_is_beacon(hdr->frame_control))
  421. return RX_CONTINUE;
  422. return RX_DROP_MONITOR;
  423. }
  424. #define msh_h_get(h, l) ((struct ieee80211s_hdr *) ((u8 *)h + l))
  425. if (ieee80211_is_data(hdr->frame_control) &&
  426. is_multicast_ether_addr(hdr->addr1) &&
  427. mesh_rmc_check(hdr->addr3, msh_h_get(hdr, hdrlen), rx->sdata))
  428. return RX_DROP_MONITOR;
  429. #undef msh_h_get
  430. return RX_CONTINUE;
  431. }
  432. #define SEQ_MODULO 0x1000
  433. #define SEQ_MASK 0xfff
  434. static inline int seq_less(u16 sq1, u16 sq2)
  435. {
  436. return ((sq1 - sq2) & SEQ_MASK) > (SEQ_MODULO >> 1);
  437. }
  438. static inline u16 seq_inc(u16 sq)
  439. {
  440. return (sq + 1) & SEQ_MASK;
  441. }
  442. static inline u16 seq_sub(u16 sq1, u16 sq2)
  443. {
  444. return (sq1 - sq2) & SEQ_MASK;
  445. }
  446. static void ieee80211_release_reorder_frame(struct ieee80211_hw *hw,
  447. struct tid_ampdu_rx *tid_agg_rx,
  448. int index,
  449. struct sk_buff_head *frames)
  450. {
  451. struct sk_buff *skb = tid_agg_rx->reorder_buf[index];
  452. if (!skb)
  453. goto no_frame;
  454. /* release the frame from the reorder ring buffer */
  455. tid_agg_rx->stored_mpdu_num--;
  456. tid_agg_rx->reorder_buf[index] = NULL;
  457. __skb_queue_tail(frames, skb);
  458. no_frame:
  459. tid_agg_rx->head_seq_num = seq_inc(tid_agg_rx->head_seq_num);
  460. }
  461. static void ieee80211_release_reorder_frames(struct ieee80211_hw *hw,
  462. struct tid_ampdu_rx *tid_agg_rx,
  463. u16 head_seq_num,
  464. struct sk_buff_head *frames)
  465. {
  466. int index;
  467. while (seq_less(tid_agg_rx->head_seq_num, head_seq_num)) {
  468. index = seq_sub(tid_agg_rx->head_seq_num, tid_agg_rx->ssn) %
  469. tid_agg_rx->buf_size;
  470. ieee80211_release_reorder_frame(hw, tid_agg_rx, index, frames);
  471. }
  472. }
  473. /*
  474. * Timeout (in jiffies) for skb's that are waiting in the RX reorder buffer. If
  475. * the skb was added to the buffer longer than this time ago, the earlier
  476. * frames that have not yet been received are assumed to be lost and the skb
  477. * can be released for processing. This may also release other skb's from the
  478. * reorder buffer if there are no additional gaps between the frames.
  479. *
  480. * Callers must hold tid_agg_rx->reorder_lock.
  481. */
  482. #define HT_RX_REORDER_BUF_TIMEOUT (HZ / 10)
  483. static void ieee80211_sta_reorder_release(struct ieee80211_hw *hw,
  484. struct tid_ampdu_rx *tid_agg_rx,
  485. struct sk_buff_head *frames)
  486. {
  487. int index, j;
  488. /* release the buffer until next missing frame */
  489. index = seq_sub(tid_agg_rx->head_seq_num, tid_agg_rx->ssn) %
  490. tid_agg_rx->buf_size;
  491. if (!tid_agg_rx->reorder_buf[index] &&
  492. tid_agg_rx->stored_mpdu_num > 1) {
  493. /*
  494. * No buffers ready to be released, but check whether any
  495. * frames in the reorder buffer have timed out.
  496. */
  497. int skipped = 1;
  498. for (j = (index + 1) % tid_agg_rx->buf_size; j != index;
  499. j = (j + 1) % tid_agg_rx->buf_size) {
  500. if (!tid_agg_rx->reorder_buf[j]) {
  501. skipped++;
  502. continue;
  503. }
  504. if (!time_after(jiffies, tid_agg_rx->reorder_time[j] +
  505. HT_RX_REORDER_BUF_TIMEOUT))
  506. goto set_release_timer;
  507. #ifdef CONFIG_MAC80211_HT_DEBUG
  508. if (net_ratelimit())
  509. printk(KERN_DEBUG "%s: release an RX reorder "
  510. "frame due to timeout on earlier "
  511. "frames\n",
  512. wiphy_name(hw->wiphy));
  513. #endif
  514. ieee80211_release_reorder_frame(hw, tid_agg_rx,
  515. j, frames);
  516. /*
  517. * Increment the head seq# also for the skipped slots.
  518. */
  519. tid_agg_rx->head_seq_num =
  520. (tid_agg_rx->head_seq_num + skipped) & SEQ_MASK;
  521. skipped = 0;
  522. }
  523. } else while (tid_agg_rx->reorder_buf[index]) {
  524. ieee80211_release_reorder_frame(hw, tid_agg_rx, index, frames);
  525. index = seq_sub(tid_agg_rx->head_seq_num, tid_agg_rx->ssn) %
  526. tid_agg_rx->buf_size;
  527. }
  528. if (tid_agg_rx->stored_mpdu_num) {
  529. j = index = seq_sub(tid_agg_rx->head_seq_num,
  530. tid_agg_rx->ssn) % tid_agg_rx->buf_size;
  531. for (; j != (index - 1) % tid_agg_rx->buf_size;
  532. j = (j + 1) % tid_agg_rx->buf_size) {
  533. if (tid_agg_rx->reorder_buf[j])
  534. break;
  535. }
  536. set_release_timer:
  537. mod_timer(&tid_agg_rx->reorder_timer,
  538. tid_agg_rx->reorder_time[j] +
  539. HT_RX_REORDER_BUF_TIMEOUT);
  540. } else {
  541. del_timer(&tid_agg_rx->reorder_timer);
  542. }
  543. }
  544. /*
  545. * As this function belongs to the RX path it must be under
  546. * rcu_read_lock protection. It returns false if the frame
  547. * can be processed immediately, true if it was consumed.
  548. */
  549. static bool ieee80211_sta_manage_reorder_buf(struct ieee80211_hw *hw,
  550. struct tid_ampdu_rx *tid_agg_rx,
  551. struct sk_buff *skb,
  552. struct sk_buff_head *frames)
  553. {
  554. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
  555. u16 sc = le16_to_cpu(hdr->seq_ctrl);
  556. u16 mpdu_seq_num = (sc & IEEE80211_SCTL_SEQ) >> 4;
  557. u16 head_seq_num, buf_size;
  558. int index;
  559. bool ret = true;
  560. buf_size = tid_agg_rx->buf_size;
  561. head_seq_num = tid_agg_rx->head_seq_num;
  562. spin_lock(&tid_agg_rx->reorder_lock);
  563. /* frame with out of date sequence number */
  564. if (seq_less(mpdu_seq_num, head_seq_num)) {
  565. dev_kfree_skb(skb);
  566. goto out;
  567. }
  568. /*
  569. * If frame the sequence number exceeds our buffering window
  570. * size release some previous frames to make room for this one.
  571. */
  572. if (!seq_less(mpdu_seq_num, head_seq_num + buf_size)) {
  573. head_seq_num = seq_inc(seq_sub(mpdu_seq_num, buf_size));
  574. /* release stored frames up to new head to stack */
  575. ieee80211_release_reorder_frames(hw, tid_agg_rx, head_seq_num,
  576. frames);
  577. }
  578. /* Now the new frame is always in the range of the reordering buffer */
  579. index = seq_sub(mpdu_seq_num, tid_agg_rx->ssn) % tid_agg_rx->buf_size;
  580. /* check if we already stored this frame */
  581. if (tid_agg_rx->reorder_buf[index]) {
  582. dev_kfree_skb(skb);
  583. goto out;
  584. }
  585. /*
  586. * If the current MPDU is in the right order and nothing else
  587. * is stored we can process it directly, no need to buffer it.
  588. */
  589. if (mpdu_seq_num == tid_agg_rx->head_seq_num &&
  590. tid_agg_rx->stored_mpdu_num == 0) {
  591. tid_agg_rx->head_seq_num = seq_inc(tid_agg_rx->head_seq_num);
  592. ret = false;
  593. goto out;
  594. }
  595. /* put the frame in the reordering buffer */
  596. tid_agg_rx->reorder_buf[index] = skb;
  597. tid_agg_rx->reorder_time[index] = jiffies;
  598. tid_agg_rx->stored_mpdu_num++;
  599. ieee80211_sta_reorder_release(hw, tid_agg_rx, frames);
  600. out:
  601. spin_unlock(&tid_agg_rx->reorder_lock);
  602. return ret;
  603. }
  604. /*
  605. * Reorder MPDUs from A-MPDUs, keeping them on a buffer. Returns
  606. * true if the MPDU was buffered, false if it should be processed.
  607. */
  608. static void ieee80211_rx_reorder_ampdu(struct ieee80211_rx_data *rx,
  609. struct sk_buff_head *frames)
  610. {
  611. struct sk_buff *skb = rx->skb;
  612. struct ieee80211_local *local = rx->local;
  613. struct ieee80211_hw *hw = &local->hw;
  614. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
  615. struct sta_info *sta = rx->sta;
  616. struct tid_ampdu_rx *tid_agg_rx;
  617. u16 sc;
  618. int tid;
  619. if (!ieee80211_is_data_qos(hdr->frame_control))
  620. goto dont_reorder;
  621. /*
  622. * filter the QoS data rx stream according to
  623. * STA/TID and check if this STA/TID is on aggregation
  624. */
  625. if (!sta)
  626. goto dont_reorder;
  627. tid = *ieee80211_get_qos_ctl(hdr) & IEEE80211_QOS_CTL_TID_MASK;
  628. tid_agg_rx = rcu_dereference(sta->ampdu_mlme.tid_rx[tid]);
  629. if (!tid_agg_rx)
  630. goto dont_reorder;
  631. /* qos null data frames are excluded */
  632. if (unlikely(hdr->frame_control & cpu_to_le16(IEEE80211_STYPE_NULLFUNC)))
  633. goto dont_reorder;
  634. /* new, potentially un-ordered, ampdu frame - process it */
  635. /* reset session timer */
  636. if (tid_agg_rx->timeout)
  637. mod_timer(&tid_agg_rx->session_timer,
  638. TU_TO_EXP_TIME(tid_agg_rx->timeout));
  639. /* if this mpdu is fragmented - terminate rx aggregation session */
  640. sc = le16_to_cpu(hdr->seq_ctrl);
  641. if (sc & IEEE80211_SCTL_FRAG) {
  642. skb->pkt_type = IEEE80211_SDATA_QUEUE_TYPE_FRAME;
  643. skb_queue_tail(&rx->sdata->skb_queue, skb);
  644. ieee80211_queue_work(&local->hw, &rx->sdata->work);
  645. return;
  646. }
  647. /*
  648. * No locking needed -- we will only ever process one
  649. * RX packet at a time, and thus own tid_agg_rx. All
  650. * other code manipulating it needs to (and does) make
  651. * sure that we cannot get to it any more before doing
  652. * anything with it.
  653. */
  654. if (ieee80211_sta_manage_reorder_buf(hw, tid_agg_rx, skb, frames))
  655. return;
  656. dont_reorder:
  657. __skb_queue_tail(frames, skb);
  658. }
  659. static ieee80211_rx_result debug_noinline
  660. ieee80211_rx_h_check(struct ieee80211_rx_data *rx)
  661. {
  662. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
  663. /* Drop duplicate 802.11 retransmissions (IEEE 802.11 Chap. 9.2.9) */
  664. if (rx->sta && !is_multicast_ether_addr(hdr->addr1)) {
  665. if (unlikely(ieee80211_has_retry(hdr->frame_control) &&
  666. rx->sta->last_seq_ctrl[rx->queue] ==
  667. hdr->seq_ctrl)) {
  668. if (rx->flags & IEEE80211_RX_RA_MATCH) {
  669. rx->local->dot11FrameDuplicateCount++;
  670. rx->sta->num_duplicates++;
  671. }
  672. return RX_DROP_MONITOR;
  673. } else
  674. rx->sta->last_seq_ctrl[rx->queue] = hdr->seq_ctrl;
  675. }
  676. if (unlikely(rx->skb->len < 16)) {
  677. I802_DEBUG_INC(rx->local->rx_handlers_drop_short);
  678. return RX_DROP_MONITOR;
  679. }
  680. /* Drop disallowed frame classes based on STA auth/assoc state;
  681. * IEEE 802.11, Chap 5.5.
  682. *
  683. * mac80211 filters only based on association state, i.e. it drops
  684. * Class 3 frames from not associated stations. hostapd sends
  685. * deauth/disassoc frames when needed. In addition, hostapd is
  686. * responsible for filtering on both auth and assoc states.
  687. */
  688. if (ieee80211_vif_is_mesh(&rx->sdata->vif))
  689. return ieee80211_rx_mesh_check(rx);
  690. if (unlikely((ieee80211_is_data(hdr->frame_control) ||
  691. ieee80211_is_pspoll(hdr->frame_control)) &&
  692. rx->sdata->vif.type != NL80211_IFTYPE_ADHOC &&
  693. (!rx->sta || !test_sta_flags(rx->sta, WLAN_STA_ASSOC)))) {
  694. if ((!ieee80211_has_fromds(hdr->frame_control) &&
  695. !ieee80211_has_tods(hdr->frame_control) &&
  696. ieee80211_is_data(hdr->frame_control)) ||
  697. !(rx->flags & IEEE80211_RX_RA_MATCH)) {
  698. /* Drop IBSS frames and frames for other hosts
  699. * silently. */
  700. return RX_DROP_MONITOR;
  701. }
  702. return RX_DROP_MONITOR;
  703. }
  704. return RX_CONTINUE;
  705. }
  706. static ieee80211_rx_result debug_noinline
  707. ieee80211_rx_h_decrypt(struct ieee80211_rx_data *rx)
  708. {
  709. struct sk_buff *skb = rx->skb;
  710. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
  711. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
  712. int keyidx;
  713. int hdrlen;
  714. ieee80211_rx_result result = RX_DROP_UNUSABLE;
  715. struct ieee80211_key *stakey = NULL;
  716. int mmie_keyidx = -1;
  717. __le16 fc;
  718. /*
  719. * Key selection 101
  720. *
  721. * There are four types of keys:
  722. * - GTK (group keys)
  723. * - IGTK (group keys for management frames)
  724. * - PTK (pairwise keys)
  725. * - STK (station-to-station pairwise keys)
  726. *
  727. * When selecting a key, we have to distinguish between multicast
  728. * (including broadcast) and unicast frames, the latter can only
  729. * use PTKs and STKs while the former always use GTKs and IGTKs.
  730. * Unless, of course, actual WEP keys ("pre-RSNA") are used, then
  731. * unicast frames can also use key indices like GTKs. Hence, if we
  732. * don't have a PTK/STK we check the key index for a WEP key.
  733. *
  734. * Note that in a regular BSS, multicast frames are sent by the
  735. * AP only, associated stations unicast the frame to the AP first
  736. * which then multicasts it on their behalf.
  737. *
  738. * There is also a slight problem in IBSS mode: GTKs are negotiated
  739. * with each station, that is something we don't currently handle.
  740. * The spec seems to expect that one negotiates the same key with
  741. * every station but there's no such requirement; VLANs could be
  742. * possible.
  743. */
  744. /*
  745. * No point in finding a key and decrypting if the frame is neither
  746. * addressed to us nor a multicast frame.
  747. */
  748. if (!(rx->flags & IEEE80211_RX_RA_MATCH))
  749. return RX_CONTINUE;
  750. /* start without a key */
  751. rx->key = NULL;
  752. if (rx->sta)
  753. stakey = rcu_dereference(rx->sta->key);
  754. fc = hdr->frame_control;
  755. if (!ieee80211_has_protected(fc))
  756. mmie_keyidx = ieee80211_get_mmie_keyidx(rx->skb);
  757. if (!is_multicast_ether_addr(hdr->addr1) && stakey) {
  758. rx->key = stakey;
  759. /* Skip decryption if the frame is not protected. */
  760. if (!ieee80211_has_protected(fc))
  761. return RX_CONTINUE;
  762. } else if (mmie_keyidx >= 0) {
  763. /* Broadcast/multicast robust management frame / BIP */
  764. if ((status->flag & RX_FLAG_DECRYPTED) &&
  765. (status->flag & RX_FLAG_IV_STRIPPED))
  766. return RX_CONTINUE;
  767. if (mmie_keyidx < NUM_DEFAULT_KEYS ||
  768. mmie_keyidx >= NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS)
  769. return RX_DROP_MONITOR; /* unexpected BIP keyidx */
  770. rx->key = rcu_dereference(rx->sdata->keys[mmie_keyidx]);
  771. } else if (!ieee80211_has_protected(fc)) {
  772. /*
  773. * The frame was not protected, so skip decryption. However, we
  774. * need to set rx->key if there is a key that could have been
  775. * used so that the frame may be dropped if encryption would
  776. * have been expected.
  777. */
  778. struct ieee80211_key *key = NULL;
  779. if (ieee80211_is_mgmt(fc) &&
  780. is_multicast_ether_addr(hdr->addr1) &&
  781. (key = rcu_dereference(rx->sdata->default_mgmt_key)))
  782. rx->key = key;
  783. else if ((key = rcu_dereference(rx->sdata->default_key)))
  784. rx->key = key;
  785. return RX_CONTINUE;
  786. } else {
  787. u8 keyid;
  788. /*
  789. * The device doesn't give us the IV so we won't be
  790. * able to look up the key. That's ok though, we
  791. * don't need to decrypt the frame, we just won't
  792. * be able to keep statistics accurate.
  793. * Except for key threshold notifications, should
  794. * we somehow allow the driver to tell us which key
  795. * the hardware used if this flag is set?
  796. */
  797. if ((status->flag & RX_FLAG_DECRYPTED) &&
  798. (status->flag & RX_FLAG_IV_STRIPPED))
  799. return RX_CONTINUE;
  800. hdrlen = ieee80211_hdrlen(fc);
  801. if (rx->skb->len < 8 + hdrlen)
  802. return RX_DROP_UNUSABLE; /* TODO: count this? */
  803. /*
  804. * no need to call ieee80211_wep_get_keyidx,
  805. * it verifies a bunch of things we've done already
  806. */
  807. skb_copy_bits(rx->skb, hdrlen + 3, &keyid, 1);
  808. keyidx = keyid >> 6;
  809. rx->key = rcu_dereference(rx->sdata->keys[keyidx]);
  810. /*
  811. * RSNA-protected unicast frames should always be sent with
  812. * pairwise or station-to-station keys, but for WEP we allow
  813. * using a key index as well.
  814. */
  815. if (rx->key && rx->key->conf.cipher != WLAN_CIPHER_SUITE_WEP40 &&
  816. rx->key->conf.cipher != WLAN_CIPHER_SUITE_WEP104 &&
  817. !is_multicast_ether_addr(hdr->addr1))
  818. rx->key = NULL;
  819. }
  820. if (rx->key) {
  821. rx->key->tx_rx_count++;
  822. /* TODO: add threshold stuff again */
  823. } else {
  824. return RX_DROP_MONITOR;
  825. }
  826. if (skb_linearize(rx->skb))
  827. return RX_DROP_UNUSABLE;
  828. /* the hdr variable is invalid now! */
  829. switch (rx->key->conf.cipher) {
  830. case WLAN_CIPHER_SUITE_WEP40:
  831. case WLAN_CIPHER_SUITE_WEP104:
  832. /* Check for weak IVs if possible */
  833. if (rx->sta && ieee80211_is_data(fc) &&
  834. (!(status->flag & RX_FLAG_IV_STRIPPED) ||
  835. !(status->flag & RX_FLAG_DECRYPTED)) &&
  836. ieee80211_wep_is_weak_iv(rx->skb, rx->key))
  837. rx->sta->wep_weak_iv_count++;
  838. result = ieee80211_crypto_wep_decrypt(rx);
  839. break;
  840. case WLAN_CIPHER_SUITE_TKIP:
  841. result = ieee80211_crypto_tkip_decrypt(rx);
  842. break;
  843. case WLAN_CIPHER_SUITE_CCMP:
  844. result = ieee80211_crypto_ccmp_decrypt(rx);
  845. break;
  846. case WLAN_CIPHER_SUITE_AES_CMAC:
  847. result = ieee80211_crypto_aes_cmac_decrypt(rx);
  848. break;
  849. }
  850. /* either the frame has been decrypted or will be dropped */
  851. status->flag |= RX_FLAG_DECRYPTED;
  852. return result;
  853. }
  854. static ieee80211_rx_result debug_noinline
  855. ieee80211_rx_h_check_more_data(struct ieee80211_rx_data *rx)
  856. {
  857. struct ieee80211_local *local;
  858. struct ieee80211_hdr *hdr;
  859. struct sk_buff *skb;
  860. local = rx->local;
  861. skb = rx->skb;
  862. hdr = (struct ieee80211_hdr *) skb->data;
  863. if (!local->pspolling)
  864. return RX_CONTINUE;
  865. if (!ieee80211_has_fromds(hdr->frame_control))
  866. /* this is not from AP */
  867. return RX_CONTINUE;
  868. if (!ieee80211_is_data(hdr->frame_control))
  869. return RX_CONTINUE;
  870. if (!ieee80211_has_moredata(hdr->frame_control)) {
  871. /* AP has no more frames buffered for us */
  872. local->pspolling = false;
  873. return RX_CONTINUE;
  874. }
  875. /* more data bit is set, let's request a new frame from the AP */
  876. ieee80211_send_pspoll(local, rx->sdata);
  877. return RX_CONTINUE;
  878. }
  879. static void ap_sta_ps_start(struct sta_info *sta)
  880. {
  881. struct ieee80211_sub_if_data *sdata = sta->sdata;
  882. struct ieee80211_local *local = sdata->local;
  883. atomic_inc(&sdata->bss->num_sta_ps);
  884. set_sta_flags(sta, WLAN_STA_PS_STA);
  885. drv_sta_notify(local, sdata, STA_NOTIFY_SLEEP, &sta->sta);
  886. #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
  887. printk(KERN_DEBUG "%s: STA %pM aid %d enters power save mode\n",
  888. sdata->name, sta->sta.addr, sta->sta.aid);
  889. #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
  890. }
  891. static void ap_sta_ps_end(struct sta_info *sta)
  892. {
  893. struct ieee80211_sub_if_data *sdata = sta->sdata;
  894. atomic_dec(&sdata->bss->num_sta_ps);
  895. clear_sta_flags(sta, WLAN_STA_PS_STA);
  896. #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
  897. printk(KERN_DEBUG "%s: STA %pM aid %d exits power save mode\n",
  898. sdata->name, sta->sta.addr, sta->sta.aid);
  899. #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
  900. if (test_sta_flags(sta, WLAN_STA_PS_DRIVER)) {
  901. #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
  902. printk(KERN_DEBUG "%s: STA %pM aid %d driver-ps-blocked\n",
  903. sdata->name, sta->sta.addr, sta->sta.aid);
  904. #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
  905. return;
  906. }
  907. ieee80211_sta_ps_deliver_wakeup(sta);
  908. }
  909. static ieee80211_rx_result debug_noinline
  910. ieee80211_rx_h_sta_process(struct ieee80211_rx_data *rx)
  911. {
  912. struct sta_info *sta = rx->sta;
  913. struct sk_buff *skb = rx->skb;
  914. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
  915. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
  916. if (!sta)
  917. return RX_CONTINUE;
  918. /*
  919. * Update last_rx only for IBSS packets which are for the current
  920. * BSSID to avoid keeping the current IBSS network alive in cases
  921. * where other STAs start using different BSSID.
  922. */
  923. if (rx->sdata->vif.type == NL80211_IFTYPE_ADHOC) {
  924. u8 *bssid = ieee80211_get_bssid(hdr, rx->skb->len,
  925. NL80211_IFTYPE_ADHOC);
  926. if (compare_ether_addr(bssid, rx->sdata->u.ibss.bssid) == 0)
  927. sta->last_rx = jiffies;
  928. } else if (!is_multicast_ether_addr(hdr->addr1)) {
  929. /*
  930. * Mesh beacons will update last_rx when if they are found to
  931. * match the current local configuration when processed.
  932. */
  933. sta->last_rx = jiffies;
  934. }
  935. if (!(rx->flags & IEEE80211_RX_RA_MATCH))
  936. return RX_CONTINUE;
  937. if (rx->sdata->vif.type == NL80211_IFTYPE_STATION)
  938. ieee80211_sta_rx_notify(rx->sdata, hdr);
  939. sta->rx_fragments++;
  940. sta->rx_bytes += rx->skb->len;
  941. sta->last_signal = status->signal;
  942. /*
  943. * Change STA power saving mode only at the end of a frame
  944. * exchange sequence.
  945. */
  946. if (!ieee80211_has_morefrags(hdr->frame_control) &&
  947. (rx->sdata->vif.type == NL80211_IFTYPE_AP ||
  948. rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN)) {
  949. if (test_sta_flags(sta, WLAN_STA_PS_STA)) {
  950. /*
  951. * Ignore doze->wake transitions that are
  952. * indicated by non-data frames, the standard
  953. * is unclear here, but for example going to
  954. * PS mode and then scanning would cause a
  955. * doze->wake transition for the probe request,
  956. * and that is clearly undesirable.
  957. */
  958. if (ieee80211_is_data(hdr->frame_control) &&
  959. !ieee80211_has_pm(hdr->frame_control))
  960. ap_sta_ps_end(sta);
  961. } else {
  962. if (ieee80211_has_pm(hdr->frame_control))
  963. ap_sta_ps_start(sta);
  964. }
  965. }
  966. /*
  967. * Drop (qos-)data::nullfunc frames silently, since they
  968. * are used only to control station power saving mode.
  969. */
  970. if (ieee80211_is_nullfunc(hdr->frame_control) ||
  971. ieee80211_is_qos_nullfunc(hdr->frame_control)) {
  972. I802_DEBUG_INC(rx->local->rx_handlers_drop_nullfunc);
  973. /*
  974. * If we receive a 4-addr nullfunc frame from a STA
  975. * that was not moved to a 4-addr STA vlan yet, drop
  976. * the frame to the monitor interface, to make sure
  977. * that hostapd sees it
  978. */
  979. if (ieee80211_has_a4(hdr->frame_control) &&
  980. (rx->sdata->vif.type == NL80211_IFTYPE_AP ||
  981. (rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
  982. !rx->sdata->u.vlan.sta)))
  983. return RX_DROP_MONITOR;
  984. /*
  985. * Update counter and free packet here to avoid
  986. * counting this as a dropped packed.
  987. */
  988. sta->rx_packets++;
  989. dev_kfree_skb(rx->skb);
  990. return RX_QUEUED;
  991. }
  992. return RX_CONTINUE;
  993. } /* ieee80211_rx_h_sta_process */
  994. static inline struct ieee80211_fragment_entry *
  995. ieee80211_reassemble_add(struct ieee80211_sub_if_data *sdata,
  996. unsigned int frag, unsigned int seq, int rx_queue,
  997. struct sk_buff **skb)
  998. {
  999. struct ieee80211_fragment_entry *entry;
  1000. int idx;
  1001. idx = sdata->fragment_next;
  1002. entry = &sdata->fragments[sdata->fragment_next++];
  1003. if (sdata->fragment_next >= IEEE80211_FRAGMENT_MAX)
  1004. sdata->fragment_next = 0;
  1005. if (!skb_queue_empty(&entry->skb_list)) {
  1006. #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
  1007. struct ieee80211_hdr *hdr =
  1008. (struct ieee80211_hdr *) entry->skb_list.next->data;
  1009. printk(KERN_DEBUG "%s: RX reassembly removed oldest "
  1010. "fragment entry (idx=%d age=%lu seq=%d last_frag=%d "
  1011. "addr1=%pM addr2=%pM\n",
  1012. sdata->name, idx,
  1013. jiffies - entry->first_frag_time, entry->seq,
  1014. entry->last_frag, hdr->addr1, hdr->addr2);
  1015. #endif
  1016. __skb_queue_purge(&entry->skb_list);
  1017. }
  1018. __skb_queue_tail(&entry->skb_list, *skb); /* no need for locking */
  1019. *skb = NULL;
  1020. entry->first_frag_time = jiffies;
  1021. entry->seq = seq;
  1022. entry->rx_queue = rx_queue;
  1023. entry->last_frag = frag;
  1024. entry->ccmp = 0;
  1025. entry->extra_len = 0;
  1026. return entry;
  1027. }
  1028. static inline struct ieee80211_fragment_entry *
  1029. ieee80211_reassemble_find(struct ieee80211_sub_if_data *sdata,
  1030. unsigned int frag, unsigned int seq,
  1031. int rx_queue, struct ieee80211_hdr *hdr)
  1032. {
  1033. struct ieee80211_fragment_entry *entry;
  1034. int i, idx;
  1035. idx = sdata->fragment_next;
  1036. for (i = 0; i < IEEE80211_FRAGMENT_MAX; i++) {
  1037. struct ieee80211_hdr *f_hdr;
  1038. idx--;
  1039. if (idx < 0)
  1040. idx = IEEE80211_FRAGMENT_MAX - 1;
  1041. entry = &sdata->fragments[idx];
  1042. if (skb_queue_empty(&entry->skb_list) || entry->seq != seq ||
  1043. entry->rx_queue != rx_queue ||
  1044. entry->last_frag + 1 != frag)
  1045. continue;
  1046. f_hdr = (struct ieee80211_hdr *)entry->skb_list.next->data;
  1047. /*
  1048. * Check ftype and addresses are equal, else check next fragment
  1049. */
  1050. if (((hdr->frame_control ^ f_hdr->frame_control) &
  1051. cpu_to_le16(IEEE80211_FCTL_FTYPE)) ||
  1052. compare_ether_addr(hdr->addr1, f_hdr->addr1) != 0 ||
  1053. compare_ether_addr(hdr->addr2, f_hdr->addr2) != 0)
  1054. continue;
  1055. if (time_after(jiffies, entry->first_frag_time + 2 * HZ)) {
  1056. __skb_queue_purge(&entry->skb_list);
  1057. continue;
  1058. }
  1059. return entry;
  1060. }
  1061. return NULL;
  1062. }
  1063. static ieee80211_rx_result debug_noinline
  1064. ieee80211_rx_h_defragment(struct ieee80211_rx_data *rx)
  1065. {
  1066. struct ieee80211_hdr *hdr;
  1067. u16 sc;
  1068. __le16 fc;
  1069. unsigned int frag, seq;
  1070. struct ieee80211_fragment_entry *entry;
  1071. struct sk_buff *skb;
  1072. hdr = (struct ieee80211_hdr *)rx->skb->data;
  1073. fc = hdr->frame_control;
  1074. sc = le16_to_cpu(hdr->seq_ctrl);
  1075. frag = sc & IEEE80211_SCTL_FRAG;
  1076. if (likely((!ieee80211_has_morefrags(fc) && frag == 0) ||
  1077. (rx->skb)->len < 24 ||
  1078. is_multicast_ether_addr(hdr->addr1))) {
  1079. /* not fragmented */
  1080. goto out;
  1081. }
  1082. I802_DEBUG_INC(rx->local->rx_handlers_fragments);
  1083. if (skb_linearize(rx->skb))
  1084. return RX_DROP_UNUSABLE;
  1085. /*
  1086. * skb_linearize() might change the skb->data and
  1087. * previously cached variables (in this case, hdr) need to
  1088. * be refreshed with the new data.
  1089. */
  1090. hdr = (struct ieee80211_hdr *)rx->skb->data;
  1091. seq = (sc & IEEE80211_SCTL_SEQ) >> 4;
  1092. if (frag == 0) {
  1093. /* This is the first fragment of a new frame. */
  1094. entry = ieee80211_reassemble_add(rx->sdata, frag, seq,
  1095. rx->queue, &(rx->skb));
  1096. if (rx->key && rx->key->conf.cipher == WLAN_CIPHER_SUITE_CCMP &&
  1097. ieee80211_has_protected(fc)) {
  1098. int queue = ieee80211_is_mgmt(fc) ?
  1099. NUM_RX_DATA_QUEUES : rx->queue;
  1100. /* Store CCMP PN so that we can verify that the next
  1101. * fragment has a sequential PN value. */
  1102. entry->ccmp = 1;
  1103. memcpy(entry->last_pn,
  1104. rx->key->u.ccmp.rx_pn[queue],
  1105. CCMP_PN_LEN);
  1106. }
  1107. return RX_QUEUED;
  1108. }
  1109. /* This is a fragment for a frame that should already be pending in
  1110. * fragment cache. Add this fragment to the end of the pending entry.
  1111. */
  1112. entry = ieee80211_reassemble_find(rx->sdata, frag, seq, rx->queue, hdr);
  1113. if (!entry) {
  1114. I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag);
  1115. return RX_DROP_MONITOR;
  1116. }
  1117. /* Verify that MPDUs within one MSDU have sequential PN values.
  1118. * (IEEE 802.11i, 8.3.3.4.5) */
  1119. if (entry->ccmp) {
  1120. int i;
  1121. u8 pn[CCMP_PN_LEN], *rpn;
  1122. int queue;
  1123. if (!rx->key || rx->key->conf.cipher != WLAN_CIPHER_SUITE_CCMP)
  1124. return RX_DROP_UNUSABLE;
  1125. memcpy(pn, entry->last_pn, CCMP_PN_LEN);
  1126. for (i = CCMP_PN_LEN - 1; i >= 0; i--) {
  1127. pn[i]++;
  1128. if (pn[i])
  1129. break;
  1130. }
  1131. queue = ieee80211_is_mgmt(fc) ?
  1132. NUM_RX_DATA_QUEUES : rx->queue;
  1133. rpn = rx->key->u.ccmp.rx_pn[queue];
  1134. if (memcmp(pn, rpn, CCMP_PN_LEN))
  1135. return RX_DROP_UNUSABLE;
  1136. memcpy(entry->last_pn, pn, CCMP_PN_LEN);
  1137. }
  1138. skb_pull(rx->skb, ieee80211_hdrlen(fc));
  1139. __skb_queue_tail(&entry->skb_list, rx->skb);
  1140. entry->last_frag = frag;
  1141. entry->extra_len += rx->skb->len;
  1142. if (ieee80211_has_morefrags(fc)) {
  1143. rx->skb = NULL;
  1144. return RX_QUEUED;
  1145. }
  1146. rx->skb = __skb_dequeue(&entry->skb_list);
  1147. if (skb_tailroom(rx->skb) < entry->extra_len) {
  1148. I802_DEBUG_INC(rx->local->rx_expand_skb_head2);
  1149. if (unlikely(pskb_expand_head(rx->skb, 0, entry->extra_len,
  1150. GFP_ATOMIC))) {
  1151. I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag);
  1152. __skb_queue_purge(&entry->skb_list);
  1153. return RX_DROP_UNUSABLE;
  1154. }
  1155. }
  1156. while ((skb = __skb_dequeue(&entry->skb_list))) {
  1157. memcpy(skb_put(rx->skb, skb->len), skb->data, skb->len);
  1158. dev_kfree_skb(skb);
  1159. }
  1160. /* Complete frame has been reassembled - process it now */
  1161. rx->flags |= IEEE80211_RX_FRAGMENTED;
  1162. out:
  1163. if (rx->sta)
  1164. rx->sta->rx_packets++;
  1165. if (is_multicast_ether_addr(hdr->addr1))
  1166. rx->local->dot11MulticastReceivedFrameCount++;
  1167. else
  1168. ieee80211_led_rx(rx->local);
  1169. return RX_CONTINUE;
  1170. }
  1171. static ieee80211_rx_result debug_noinline
  1172. ieee80211_rx_h_ps_poll(struct ieee80211_rx_data *rx)
  1173. {
  1174. struct ieee80211_sub_if_data *sdata = rx->sdata;
  1175. __le16 fc = ((struct ieee80211_hdr *)rx->skb->data)->frame_control;
  1176. if (likely(!rx->sta || !ieee80211_is_pspoll(fc) ||
  1177. !(rx->flags & IEEE80211_RX_RA_MATCH)))
  1178. return RX_CONTINUE;
  1179. if ((sdata->vif.type != NL80211_IFTYPE_AP) &&
  1180. (sdata->vif.type != NL80211_IFTYPE_AP_VLAN))
  1181. return RX_DROP_UNUSABLE;
  1182. if (!test_sta_flags(rx->sta, WLAN_STA_PS_DRIVER))
  1183. ieee80211_sta_ps_deliver_poll_response(rx->sta);
  1184. else
  1185. set_sta_flags(rx->sta, WLAN_STA_PSPOLL);
  1186. /* Free PS Poll skb here instead of returning RX_DROP that would
  1187. * count as an dropped frame. */
  1188. dev_kfree_skb(rx->skb);
  1189. return RX_QUEUED;
  1190. }
  1191. static ieee80211_rx_result debug_noinline
  1192. ieee80211_rx_h_remove_qos_control(struct ieee80211_rx_data *rx)
  1193. {
  1194. u8 *data = rx->skb->data;
  1195. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)data;
  1196. if (!ieee80211_is_data_qos(hdr->frame_control))
  1197. return RX_CONTINUE;
  1198. /* remove the qos control field, update frame type and meta-data */
  1199. memmove(data + IEEE80211_QOS_CTL_LEN, data,
  1200. ieee80211_hdrlen(hdr->frame_control) - IEEE80211_QOS_CTL_LEN);
  1201. hdr = (struct ieee80211_hdr *)skb_pull(rx->skb, IEEE80211_QOS_CTL_LEN);
  1202. /* change frame type to non QOS */
  1203. hdr->frame_control &= ~cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
  1204. return RX_CONTINUE;
  1205. }
  1206. static int
  1207. ieee80211_802_1x_port_control(struct ieee80211_rx_data *rx)
  1208. {
  1209. if (unlikely(!rx->sta ||
  1210. !test_sta_flags(rx->sta, WLAN_STA_AUTHORIZED)))
  1211. return -EACCES;
  1212. return 0;
  1213. }
  1214. static int
  1215. ieee80211_drop_unencrypted(struct ieee80211_rx_data *rx, __le16 fc)
  1216. {
  1217. struct sk_buff *skb = rx->skb;
  1218. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
  1219. /*
  1220. * Pass through unencrypted frames if the hardware has
  1221. * decrypted them already.
  1222. */
  1223. if (status->flag & RX_FLAG_DECRYPTED)
  1224. return 0;
  1225. /* Drop unencrypted frames if key is set. */
  1226. if (unlikely(!ieee80211_has_protected(fc) &&
  1227. !ieee80211_is_nullfunc(fc) &&
  1228. ieee80211_is_data(fc) &&
  1229. (rx->key || rx->sdata->drop_unencrypted)))
  1230. return -EACCES;
  1231. return 0;
  1232. }
  1233. static int
  1234. ieee80211_drop_unencrypted_mgmt(struct ieee80211_rx_data *rx)
  1235. {
  1236. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
  1237. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
  1238. __le16 fc = hdr->frame_control;
  1239. /*
  1240. * Pass through unencrypted frames if the hardware has
  1241. * decrypted them already.
  1242. */
  1243. if (status->flag & RX_FLAG_DECRYPTED)
  1244. return 0;
  1245. if (rx->sta && test_sta_flags(rx->sta, WLAN_STA_MFP)) {
  1246. if (unlikely(!ieee80211_has_protected(fc) &&
  1247. ieee80211_is_unicast_robust_mgmt_frame(rx->skb) &&
  1248. rx->key))
  1249. return -EACCES;
  1250. /* BIP does not use Protected field, so need to check MMIE */
  1251. if (unlikely(ieee80211_is_multicast_robust_mgmt_frame(rx->skb) &&
  1252. ieee80211_get_mmie_keyidx(rx->skb) < 0))
  1253. return -EACCES;
  1254. /*
  1255. * When using MFP, Action frames are not allowed prior to
  1256. * having configured keys.
  1257. */
  1258. if (unlikely(ieee80211_is_action(fc) && !rx->key &&
  1259. ieee80211_is_robust_mgmt_frame(
  1260. (struct ieee80211_hdr *) rx->skb->data)))
  1261. return -EACCES;
  1262. }
  1263. return 0;
  1264. }
  1265. static int
  1266. __ieee80211_data_to_8023(struct ieee80211_rx_data *rx)
  1267. {
  1268. struct ieee80211_sub_if_data *sdata = rx->sdata;
  1269. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
  1270. if (ieee80211_has_a4(hdr->frame_control) &&
  1271. sdata->vif.type == NL80211_IFTYPE_AP_VLAN && !sdata->u.vlan.sta)
  1272. return -1;
  1273. if (is_multicast_ether_addr(hdr->addr1) &&
  1274. ((sdata->vif.type == NL80211_IFTYPE_AP_VLAN && sdata->u.vlan.sta) ||
  1275. (sdata->vif.type == NL80211_IFTYPE_STATION && sdata->u.mgd.use_4addr)))
  1276. return -1;
  1277. return ieee80211_data_to_8023(rx->skb, sdata->vif.addr, sdata->vif.type);
  1278. }
  1279. /*
  1280. * requires that rx->skb is a frame with ethernet header
  1281. */
  1282. static bool ieee80211_frame_allowed(struct ieee80211_rx_data *rx, __le16 fc)
  1283. {
  1284. static const u8 pae_group_addr[ETH_ALEN] __aligned(2)
  1285. = { 0x01, 0x80, 0xC2, 0x00, 0x00, 0x03 };
  1286. struct ethhdr *ehdr = (struct ethhdr *) rx->skb->data;
  1287. /*
  1288. * Allow EAPOL frames to us/the PAE group address regardless
  1289. * of whether the frame was encrypted or not.
  1290. */
  1291. if (ehdr->h_proto == htons(ETH_P_PAE) &&
  1292. (compare_ether_addr(ehdr->h_dest, rx->sdata->vif.addr) == 0 ||
  1293. compare_ether_addr(ehdr->h_dest, pae_group_addr) == 0))
  1294. return true;
  1295. if (ieee80211_802_1x_port_control(rx) ||
  1296. ieee80211_drop_unencrypted(rx, fc))
  1297. return false;
  1298. return true;
  1299. }
  1300. /*
  1301. * requires that rx->skb is a frame with ethernet header
  1302. */
  1303. static void
  1304. ieee80211_deliver_skb(struct ieee80211_rx_data *rx)
  1305. {
  1306. struct ieee80211_sub_if_data *sdata = rx->sdata;
  1307. struct net_device *dev = sdata->dev;
  1308. struct sk_buff *skb, *xmit_skb;
  1309. struct ethhdr *ehdr = (struct ethhdr *) rx->skb->data;
  1310. struct sta_info *dsta;
  1311. skb = rx->skb;
  1312. xmit_skb = NULL;
  1313. if ((sdata->vif.type == NL80211_IFTYPE_AP ||
  1314. sdata->vif.type == NL80211_IFTYPE_AP_VLAN) &&
  1315. !(sdata->flags & IEEE80211_SDATA_DONT_BRIDGE_PACKETS) &&
  1316. (rx->flags & IEEE80211_RX_RA_MATCH) &&
  1317. (sdata->vif.type != NL80211_IFTYPE_AP_VLAN || !sdata->u.vlan.sta)) {
  1318. if (is_multicast_ether_addr(ehdr->h_dest)) {
  1319. /*
  1320. * send multicast frames both to higher layers in
  1321. * local net stack and back to the wireless medium
  1322. */
  1323. xmit_skb = skb_copy(skb, GFP_ATOMIC);
  1324. if (!xmit_skb && net_ratelimit())
  1325. printk(KERN_DEBUG "%s: failed to clone "
  1326. "multicast frame\n", dev->name);
  1327. } else {
  1328. dsta = sta_info_get(sdata, skb->data);
  1329. if (dsta) {
  1330. /*
  1331. * The destination station is associated to
  1332. * this AP (in this VLAN), so send the frame
  1333. * directly to it and do not pass it to local
  1334. * net stack.
  1335. */
  1336. xmit_skb = skb;
  1337. skb = NULL;
  1338. }
  1339. }
  1340. }
  1341. if (skb) {
  1342. int align __maybe_unused;
  1343. #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
  1344. /*
  1345. * 'align' will only take the values 0 or 2 here
  1346. * since all frames are required to be aligned
  1347. * to 2-byte boundaries when being passed to
  1348. * mac80211. That also explains the __skb_push()
  1349. * below.
  1350. */
  1351. align = ((unsigned long)(skb->data + sizeof(struct ethhdr))) & 3;
  1352. if (align) {
  1353. if (WARN_ON(skb_headroom(skb) < 3)) {
  1354. dev_kfree_skb(skb);
  1355. skb = NULL;
  1356. } else {
  1357. u8 *data = skb->data;
  1358. size_t len = skb_headlen(skb);
  1359. skb->data -= align;
  1360. memmove(skb->data, data, len);
  1361. skb_set_tail_pointer(skb, len);
  1362. }
  1363. }
  1364. #endif
  1365. if (skb) {
  1366. /* deliver to local stack */
  1367. skb->protocol = eth_type_trans(skb, dev);
  1368. memset(skb->cb, 0, sizeof(skb->cb));
  1369. netif_receive_skb(skb);
  1370. }
  1371. }
  1372. if (xmit_skb) {
  1373. /* send to wireless media */
  1374. xmit_skb->protocol = htons(ETH_P_802_3);
  1375. skb_reset_network_header(xmit_skb);
  1376. skb_reset_mac_header(xmit_skb);
  1377. dev_queue_xmit(xmit_skb);
  1378. }
  1379. }
  1380. static ieee80211_rx_result debug_noinline
  1381. ieee80211_rx_h_amsdu(struct ieee80211_rx_data *rx)
  1382. {
  1383. struct net_device *dev = rx->sdata->dev;
  1384. struct sk_buff *skb = rx->skb;
  1385. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
  1386. __le16 fc = hdr->frame_control;
  1387. struct sk_buff_head frame_list;
  1388. if (unlikely(!ieee80211_is_data(fc)))
  1389. return RX_CONTINUE;
  1390. if (unlikely(!ieee80211_is_data_present(fc)))
  1391. return RX_DROP_MONITOR;
  1392. if (!(rx->flags & IEEE80211_RX_AMSDU))
  1393. return RX_CONTINUE;
  1394. if (ieee80211_has_a4(hdr->frame_control) &&
  1395. rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
  1396. !rx->sdata->u.vlan.sta)
  1397. return RX_DROP_UNUSABLE;
  1398. if (is_multicast_ether_addr(hdr->addr1) &&
  1399. ((rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
  1400. rx->sdata->u.vlan.sta) ||
  1401. (rx->sdata->vif.type == NL80211_IFTYPE_STATION &&
  1402. rx->sdata->u.mgd.use_4addr)))
  1403. return RX_DROP_UNUSABLE;
  1404. skb->dev = dev;
  1405. __skb_queue_head_init(&frame_list);
  1406. if (skb_linearize(skb))
  1407. return RX_DROP_UNUSABLE;
  1408. ieee80211_amsdu_to_8023s(skb, &frame_list, dev->dev_addr,
  1409. rx->sdata->vif.type,
  1410. rx->local->hw.extra_tx_headroom);
  1411. while (!skb_queue_empty(&frame_list)) {
  1412. rx->skb = __skb_dequeue(&frame_list);
  1413. if (!ieee80211_frame_allowed(rx, fc)) {
  1414. dev_kfree_skb(rx->skb);
  1415. continue;
  1416. }
  1417. dev->stats.rx_packets++;
  1418. dev->stats.rx_bytes += rx->skb->len;
  1419. ieee80211_deliver_skb(rx);
  1420. }
  1421. return RX_QUEUED;
  1422. }
  1423. #ifdef CONFIG_MAC80211_MESH
  1424. static ieee80211_rx_result
  1425. ieee80211_rx_h_mesh_fwding(struct ieee80211_rx_data *rx)
  1426. {
  1427. struct ieee80211_hdr *hdr;
  1428. struct ieee80211s_hdr *mesh_hdr;
  1429. unsigned int hdrlen;
  1430. struct sk_buff *skb = rx->skb, *fwd_skb;
  1431. struct ieee80211_local *local = rx->local;
  1432. struct ieee80211_sub_if_data *sdata = rx->sdata;
  1433. hdr = (struct ieee80211_hdr *) skb->data;
  1434. hdrlen = ieee80211_hdrlen(hdr->frame_control);
  1435. mesh_hdr = (struct ieee80211s_hdr *) (skb->data + hdrlen);
  1436. if (!ieee80211_is_data(hdr->frame_control))
  1437. return RX_CONTINUE;
  1438. if (!mesh_hdr->ttl)
  1439. /* illegal frame */
  1440. return RX_DROP_MONITOR;
  1441. if (mesh_hdr->flags & MESH_FLAGS_AE) {
  1442. struct mesh_path *mppath;
  1443. char *proxied_addr;
  1444. char *mpp_addr;
  1445. if (is_multicast_ether_addr(hdr->addr1)) {
  1446. mpp_addr = hdr->addr3;
  1447. proxied_addr = mesh_hdr->eaddr1;
  1448. } else {
  1449. mpp_addr = hdr->addr4;
  1450. proxied_addr = mesh_hdr->eaddr2;
  1451. }
  1452. rcu_read_lock();
  1453. mppath = mpp_path_lookup(proxied_addr, sdata);
  1454. if (!mppath) {
  1455. mpp_path_add(proxied_addr, mpp_addr, sdata);
  1456. } else {
  1457. spin_lock_bh(&mppath->state_lock);
  1458. if (compare_ether_addr(mppath->mpp, mpp_addr) != 0)
  1459. memcpy(mppath->mpp, mpp_addr, ETH_ALEN);
  1460. spin_unlock_bh(&mppath->state_lock);
  1461. }
  1462. rcu_read_unlock();
  1463. }
  1464. /* Frame has reached destination. Don't forward */
  1465. if (!is_multicast_ether_addr(hdr->addr1) &&
  1466. compare_ether_addr(sdata->vif.addr, hdr->addr3) == 0)
  1467. return RX_CONTINUE;
  1468. mesh_hdr->ttl--;
  1469. if (rx->flags & IEEE80211_RX_RA_MATCH) {
  1470. if (!mesh_hdr->ttl)
  1471. IEEE80211_IFSTA_MESH_CTR_INC(&rx->sdata->u.mesh,
  1472. dropped_frames_ttl);
  1473. else {
  1474. struct ieee80211_hdr *fwd_hdr;
  1475. struct ieee80211_tx_info *info;
  1476. fwd_skb = skb_copy(skb, GFP_ATOMIC);
  1477. if (!fwd_skb && net_ratelimit())
  1478. printk(KERN_DEBUG "%s: failed to clone mesh frame\n",
  1479. sdata->name);
  1480. fwd_hdr = (struct ieee80211_hdr *) fwd_skb->data;
  1481. memcpy(fwd_hdr->addr2, sdata->vif.addr, ETH_ALEN);
  1482. info = IEEE80211_SKB_CB(fwd_skb);
  1483. memset(info, 0, sizeof(*info));
  1484. info->flags |= IEEE80211_TX_INTFL_NEED_TXPROCESSING;
  1485. info->control.vif = &rx->sdata->vif;
  1486. skb_set_queue_mapping(skb,
  1487. ieee80211_select_queue(rx->sdata, fwd_skb));
  1488. ieee80211_set_qos_hdr(local, skb);
  1489. if (is_multicast_ether_addr(fwd_hdr->addr1))
  1490. IEEE80211_IFSTA_MESH_CTR_INC(&sdata->u.mesh,
  1491. fwded_mcast);
  1492. else {
  1493. int err;
  1494. /*
  1495. * Save TA to addr1 to send TA a path error if a
  1496. * suitable next hop is not found
  1497. */
  1498. memcpy(fwd_hdr->addr1, fwd_hdr->addr2,
  1499. ETH_ALEN);
  1500. err = mesh_nexthop_lookup(fwd_skb, sdata);
  1501. /* Failed to immediately resolve next hop:
  1502. * fwded frame was dropped or will be added
  1503. * later to the pending skb queue. */
  1504. if (err)
  1505. return RX_DROP_MONITOR;
  1506. IEEE80211_IFSTA_MESH_CTR_INC(&sdata->u.mesh,
  1507. fwded_unicast);
  1508. }
  1509. IEEE80211_IFSTA_MESH_CTR_INC(&sdata->u.mesh,
  1510. fwded_frames);
  1511. ieee80211_add_pending_skb(local, fwd_skb);
  1512. }
  1513. }
  1514. if (is_multicast_ether_addr(hdr->addr1) ||
  1515. sdata->dev->flags & IFF_PROMISC)
  1516. return RX_CONTINUE;
  1517. else
  1518. return RX_DROP_MONITOR;
  1519. }
  1520. #endif
  1521. static ieee80211_rx_result debug_noinline
  1522. ieee80211_rx_h_data(struct ieee80211_rx_data *rx)
  1523. {
  1524. struct ieee80211_sub_if_data *sdata = rx->sdata;
  1525. struct ieee80211_local *local = rx->local;
  1526. struct net_device *dev = sdata->dev;
  1527. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
  1528. __le16 fc = hdr->frame_control;
  1529. int err;
  1530. if (unlikely(!ieee80211_is_data(hdr->frame_control)))
  1531. return RX_CONTINUE;
  1532. if (unlikely(!ieee80211_is_data_present(hdr->frame_control)))
  1533. return RX_DROP_MONITOR;
  1534. /*
  1535. * Allow the cooked monitor interface of an AP to see 4-addr frames so
  1536. * that a 4-addr station can be detected and moved into a separate VLAN
  1537. */
  1538. if (ieee80211_has_a4(hdr->frame_control) &&
  1539. sdata->vif.type == NL80211_IFTYPE_AP)
  1540. return RX_DROP_MONITOR;
  1541. err = __ieee80211_data_to_8023(rx);
  1542. if (unlikely(err))
  1543. return RX_DROP_UNUSABLE;
  1544. if (!ieee80211_frame_allowed(rx, fc))
  1545. return RX_DROP_MONITOR;
  1546. rx->skb->dev = dev;
  1547. dev->stats.rx_packets++;
  1548. dev->stats.rx_bytes += rx->skb->len;
  1549. if (ieee80211_is_data(hdr->frame_control) &&
  1550. !is_multicast_ether_addr(hdr->addr1) &&
  1551. local->hw.conf.dynamic_ps_timeout > 0 && local->ps_sdata) {
  1552. mod_timer(&local->dynamic_ps_timer, jiffies +
  1553. msecs_to_jiffies(local->hw.conf.dynamic_ps_timeout));
  1554. }
  1555. ieee80211_deliver_skb(rx);
  1556. return RX_QUEUED;
  1557. }
  1558. static ieee80211_rx_result debug_noinline
  1559. ieee80211_rx_h_ctrl(struct ieee80211_rx_data *rx, struct sk_buff_head *frames)
  1560. {
  1561. struct ieee80211_local *local = rx->local;
  1562. struct ieee80211_hw *hw = &local->hw;
  1563. struct sk_buff *skb = rx->skb;
  1564. struct ieee80211_bar *bar = (struct ieee80211_bar *)skb->data;
  1565. struct tid_ampdu_rx *tid_agg_rx;
  1566. u16 start_seq_num;
  1567. u16 tid;
  1568. if (likely(!ieee80211_is_ctl(bar->frame_control)))
  1569. return RX_CONTINUE;
  1570. if (ieee80211_is_back_req(bar->frame_control)) {
  1571. struct {
  1572. __le16 control, start_seq_num;
  1573. } __packed bar_data;
  1574. if (!rx->sta)
  1575. return RX_DROP_MONITOR;
  1576. if (skb_copy_bits(skb, offsetof(struct ieee80211_bar, control),
  1577. &bar_data, sizeof(bar_data)))
  1578. return RX_DROP_MONITOR;
  1579. tid = le16_to_cpu(bar_data.control) >> 12;
  1580. tid_agg_rx = rcu_dereference(rx->sta->ampdu_mlme.tid_rx[tid]);
  1581. if (!tid_agg_rx)
  1582. return RX_DROP_MONITOR;
  1583. start_seq_num = le16_to_cpu(bar_data.start_seq_num) >> 4;
  1584. /* reset session timer */
  1585. if (tid_agg_rx->timeout)
  1586. mod_timer(&tid_agg_rx->session_timer,
  1587. TU_TO_EXP_TIME(tid_agg_rx->timeout));
  1588. /* release stored frames up to start of BAR */
  1589. ieee80211_release_reorder_frames(hw, tid_agg_rx, start_seq_num,
  1590. frames);
  1591. kfree_skb(skb);
  1592. return RX_QUEUED;
  1593. }
  1594. /*
  1595. * After this point, we only want management frames,
  1596. * so we can drop all remaining control frames to
  1597. * cooked monitor interfaces.
  1598. */
  1599. return RX_DROP_MONITOR;
  1600. }
  1601. static void ieee80211_process_sa_query_req(struct ieee80211_sub_if_data *sdata,
  1602. struct ieee80211_mgmt *mgmt,
  1603. size_t len)
  1604. {
  1605. struct ieee80211_local *local = sdata->local;
  1606. struct sk_buff *skb;
  1607. struct ieee80211_mgmt *resp;
  1608. if (compare_ether_addr(mgmt->da, sdata->vif.addr) != 0) {
  1609. /* Not to own unicast address */
  1610. return;
  1611. }
  1612. if (compare_ether_addr(mgmt->sa, sdata->u.mgd.bssid) != 0 ||
  1613. compare_ether_addr(mgmt->bssid, sdata->u.mgd.bssid) != 0) {
  1614. /* Not from the current AP or not associated yet. */
  1615. return;
  1616. }
  1617. if (len < 24 + 1 + sizeof(resp->u.action.u.sa_query)) {
  1618. /* Too short SA Query request frame */
  1619. return;
  1620. }
  1621. skb = dev_alloc_skb(sizeof(*resp) + local->hw.extra_tx_headroom);
  1622. if (skb == NULL)
  1623. return;
  1624. skb_reserve(skb, local->hw.extra_tx_headroom);
  1625. resp = (struct ieee80211_mgmt *) skb_put(skb, 24);
  1626. memset(resp, 0, 24);
  1627. memcpy(resp->da, mgmt->sa, ETH_ALEN);
  1628. memcpy(resp->sa, sdata->vif.addr, ETH_ALEN);
  1629. memcpy(resp->bssid, sdata->u.mgd.bssid, ETH_ALEN);
  1630. resp->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  1631. IEEE80211_STYPE_ACTION);
  1632. skb_put(skb, 1 + sizeof(resp->u.action.u.sa_query));
  1633. resp->u.action.category = WLAN_CATEGORY_SA_QUERY;
  1634. resp->u.action.u.sa_query.action = WLAN_ACTION_SA_QUERY_RESPONSE;
  1635. memcpy(resp->u.action.u.sa_query.trans_id,
  1636. mgmt->u.action.u.sa_query.trans_id,
  1637. WLAN_SA_QUERY_TR_ID_LEN);
  1638. ieee80211_tx_skb(sdata, skb);
  1639. }
  1640. static ieee80211_rx_result debug_noinline
  1641. ieee80211_rx_h_action(struct ieee80211_rx_data *rx)
  1642. {
  1643. struct ieee80211_local *local = rx->local;
  1644. struct ieee80211_sub_if_data *sdata = rx->sdata;
  1645. struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data;
  1646. struct sk_buff *nskb;
  1647. struct ieee80211_rx_status *status;
  1648. int len = rx->skb->len;
  1649. if (!ieee80211_is_action(mgmt->frame_control))
  1650. return RX_CONTINUE;
  1651. /* drop too small frames */
  1652. if (len < IEEE80211_MIN_ACTION_SIZE)
  1653. return RX_DROP_UNUSABLE;
  1654. if (!rx->sta && mgmt->u.action.category != WLAN_CATEGORY_PUBLIC)
  1655. return RX_DROP_UNUSABLE;
  1656. if (!(rx->flags & IEEE80211_RX_RA_MATCH))
  1657. return RX_DROP_UNUSABLE;
  1658. if (ieee80211_drop_unencrypted_mgmt(rx))
  1659. return RX_DROP_UNUSABLE;
  1660. switch (mgmt->u.action.category) {
  1661. case WLAN_CATEGORY_BACK:
  1662. /*
  1663. * The aggregation code is not prepared to handle
  1664. * anything but STA/AP due to the BSSID handling;
  1665. * IBSS could work in the code but isn't supported
  1666. * by drivers or the standard.
  1667. */
  1668. if (sdata->vif.type != NL80211_IFTYPE_STATION &&
  1669. sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
  1670. sdata->vif.type != NL80211_IFTYPE_AP)
  1671. break;
  1672. /* verify action_code is present */
  1673. if (len < IEEE80211_MIN_ACTION_SIZE + 1)
  1674. break;
  1675. switch (mgmt->u.action.u.addba_req.action_code) {
  1676. case WLAN_ACTION_ADDBA_REQ:
  1677. if (len < (IEEE80211_MIN_ACTION_SIZE +
  1678. sizeof(mgmt->u.action.u.addba_req)))
  1679. goto invalid;
  1680. break;
  1681. case WLAN_ACTION_ADDBA_RESP:
  1682. if (len < (IEEE80211_MIN_ACTION_SIZE +
  1683. sizeof(mgmt->u.action.u.addba_resp)))
  1684. goto invalid;
  1685. break;
  1686. case WLAN_ACTION_DELBA:
  1687. if (len < (IEEE80211_MIN_ACTION_SIZE +
  1688. sizeof(mgmt->u.action.u.delba)))
  1689. goto invalid;
  1690. break;
  1691. default:
  1692. goto invalid;
  1693. }
  1694. goto queue;
  1695. case WLAN_CATEGORY_SPECTRUM_MGMT:
  1696. if (local->hw.conf.channel->band != IEEE80211_BAND_5GHZ)
  1697. break;
  1698. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  1699. break;
  1700. /* verify action_code is present */
  1701. if (len < IEEE80211_MIN_ACTION_SIZE + 1)
  1702. break;
  1703. switch (mgmt->u.action.u.measurement.action_code) {
  1704. case WLAN_ACTION_SPCT_MSR_REQ:
  1705. if (len < (IEEE80211_MIN_ACTION_SIZE +
  1706. sizeof(mgmt->u.action.u.measurement)))
  1707. break;
  1708. ieee80211_process_measurement_req(sdata, mgmt, len);
  1709. goto handled;
  1710. case WLAN_ACTION_SPCT_CHL_SWITCH:
  1711. if (len < (IEEE80211_MIN_ACTION_SIZE +
  1712. sizeof(mgmt->u.action.u.chan_switch)))
  1713. break;
  1714. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  1715. break;
  1716. if (memcmp(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN))
  1717. break;
  1718. goto queue;
  1719. }
  1720. break;
  1721. case WLAN_CATEGORY_SA_QUERY:
  1722. if (len < (IEEE80211_MIN_ACTION_SIZE +
  1723. sizeof(mgmt->u.action.u.sa_query)))
  1724. break;
  1725. switch (mgmt->u.action.u.sa_query.action) {
  1726. case WLAN_ACTION_SA_QUERY_REQUEST:
  1727. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  1728. break;
  1729. ieee80211_process_sa_query_req(sdata, mgmt, len);
  1730. goto handled;
  1731. }
  1732. break;
  1733. case WLAN_CATEGORY_MESH_PLINK:
  1734. case WLAN_CATEGORY_MESH_PATH_SEL:
  1735. if (!ieee80211_vif_is_mesh(&sdata->vif))
  1736. break;
  1737. goto queue;
  1738. }
  1739. invalid:
  1740. /*
  1741. * For AP mode, hostapd is responsible for handling any action
  1742. * frames that we didn't handle, including returning unknown
  1743. * ones. For all other modes we will return them to the sender,
  1744. * setting the 0x80 bit in the action category, as required by
  1745. * 802.11-2007 7.3.1.11.
  1746. */
  1747. if (sdata->vif.type == NL80211_IFTYPE_AP ||
  1748. sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
  1749. return RX_DROP_MONITOR;
  1750. /*
  1751. * Getting here means the kernel doesn't know how to handle
  1752. * it, but maybe userspace does ... include returned frames
  1753. * so userspace can register for those to know whether ones
  1754. * it transmitted were processed or returned.
  1755. */
  1756. status = IEEE80211_SKB_RXCB(rx->skb);
  1757. if (cfg80211_rx_action(rx->sdata->dev, status->freq,
  1758. rx->skb->data, rx->skb->len,
  1759. GFP_ATOMIC))
  1760. goto handled;
  1761. /* do not return rejected action frames */
  1762. if (mgmt->u.action.category & 0x80)
  1763. return RX_DROP_UNUSABLE;
  1764. nskb = skb_copy_expand(rx->skb, local->hw.extra_tx_headroom, 0,
  1765. GFP_ATOMIC);
  1766. if (nskb) {
  1767. struct ieee80211_mgmt *nmgmt = (void *)nskb->data;
  1768. nmgmt->u.action.category |= 0x80;
  1769. memcpy(nmgmt->da, nmgmt->sa, ETH_ALEN);
  1770. memcpy(nmgmt->sa, rx->sdata->vif.addr, ETH_ALEN);
  1771. memset(nskb->cb, 0, sizeof(nskb->cb));
  1772. ieee80211_tx_skb(rx->sdata, nskb);
  1773. }
  1774. handled:
  1775. if (rx->sta)
  1776. rx->sta->rx_packets++;
  1777. dev_kfree_skb(rx->skb);
  1778. return RX_QUEUED;
  1779. queue:
  1780. rx->skb->pkt_type = IEEE80211_SDATA_QUEUE_TYPE_FRAME;
  1781. skb_queue_tail(&sdata->skb_queue, rx->skb);
  1782. ieee80211_queue_work(&local->hw, &sdata->work);
  1783. if (rx->sta)
  1784. rx->sta->rx_packets++;
  1785. return RX_QUEUED;
  1786. }
  1787. static ieee80211_rx_result debug_noinline
  1788. ieee80211_rx_h_mgmt(struct ieee80211_rx_data *rx)
  1789. {
  1790. struct ieee80211_sub_if_data *sdata = rx->sdata;
  1791. ieee80211_rx_result rxs;
  1792. struct ieee80211_mgmt *mgmt = (void *)rx->skb->data;
  1793. __le16 stype;
  1794. if (!(rx->flags & IEEE80211_RX_RA_MATCH))
  1795. return RX_DROP_MONITOR;
  1796. if (rx->skb->len < 24)
  1797. return RX_DROP_MONITOR;
  1798. if (ieee80211_drop_unencrypted_mgmt(rx))
  1799. return RX_DROP_UNUSABLE;
  1800. rxs = ieee80211_work_rx_mgmt(rx->sdata, rx->skb);
  1801. if (rxs != RX_CONTINUE)
  1802. return rxs;
  1803. stype = mgmt->frame_control & cpu_to_le16(IEEE80211_FCTL_STYPE);
  1804. if (!ieee80211_vif_is_mesh(&sdata->vif) &&
  1805. sdata->vif.type != NL80211_IFTYPE_ADHOC &&
  1806. sdata->vif.type != NL80211_IFTYPE_STATION)
  1807. return RX_DROP_MONITOR;
  1808. switch (stype) {
  1809. case cpu_to_le16(IEEE80211_STYPE_BEACON):
  1810. case cpu_to_le16(IEEE80211_STYPE_PROBE_RESP):
  1811. /* process for all: mesh, mlme, ibss */
  1812. break;
  1813. case cpu_to_le16(IEEE80211_STYPE_DEAUTH):
  1814. case cpu_to_le16(IEEE80211_STYPE_DISASSOC):
  1815. /* process only for station */
  1816. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  1817. return RX_DROP_MONITOR;
  1818. break;
  1819. case cpu_to_le16(IEEE80211_STYPE_PROBE_REQ):
  1820. case cpu_to_le16(IEEE80211_STYPE_AUTH):
  1821. /* process only for ibss */
  1822. if (sdata->vif.type != NL80211_IFTYPE_ADHOC)
  1823. return RX_DROP_MONITOR;
  1824. break;
  1825. default:
  1826. return RX_DROP_MONITOR;
  1827. }
  1828. /* queue up frame and kick off work to process it */
  1829. rx->skb->pkt_type = IEEE80211_SDATA_QUEUE_TYPE_FRAME;
  1830. skb_queue_tail(&sdata->skb_queue, rx->skb);
  1831. ieee80211_queue_work(&rx->local->hw, &sdata->work);
  1832. if (rx->sta)
  1833. rx->sta->rx_packets++;
  1834. return RX_QUEUED;
  1835. }
  1836. static void ieee80211_rx_michael_mic_report(struct ieee80211_hdr *hdr,
  1837. struct ieee80211_rx_data *rx)
  1838. {
  1839. int keyidx;
  1840. unsigned int hdrlen;
  1841. hdrlen = ieee80211_hdrlen(hdr->frame_control);
  1842. if (rx->skb->len >= hdrlen + 4)
  1843. keyidx = rx->skb->data[hdrlen + 3] >> 6;
  1844. else
  1845. keyidx = -1;
  1846. if (!rx->sta) {
  1847. /*
  1848. * Some hardware seem to generate incorrect Michael MIC
  1849. * reports; ignore them to avoid triggering countermeasures.
  1850. */
  1851. return;
  1852. }
  1853. if (!ieee80211_has_protected(hdr->frame_control))
  1854. return;
  1855. if (rx->sdata->vif.type == NL80211_IFTYPE_AP && keyidx) {
  1856. /*
  1857. * APs with pairwise keys should never receive Michael MIC
  1858. * errors for non-zero keyidx because these are reserved for
  1859. * group keys and only the AP is sending real multicast
  1860. * frames in the BSS.
  1861. */
  1862. return;
  1863. }
  1864. if (!ieee80211_is_data(hdr->frame_control) &&
  1865. !ieee80211_is_auth(hdr->frame_control))
  1866. return;
  1867. mac80211_ev_michael_mic_failure(rx->sdata, keyidx, hdr, NULL,
  1868. GFP_ATOMIC);
  1869. }
  1870. /* TODO: use IEEE80211_RX_FRAGMENTED */
  1871. static void ieee80211_rx_cooked_monitor(struct ieee80211_rx_data *rx,
  1872. struct ieee80211_rate *rate)
  1873. {
  1874. struct ieee80211_sub_if_data *sdata;
  1875. struct ieee80211_local *local = rx->local;
  1876. struct ieee80211_rtap_hdr {
  1877. struct ieee80211_radiotap_header hdr;
  1878. u8 flags;
  1879. u8 rate_or_pad;
  1880. __le16 chan_freq;
  1881. __le16 chan_flags;
  1882. } __packed *rthdr;
  1883. struct sk_buff *skb = rx->skb, *skb2;
  1884. struct net_device *prev_dev = NULL;
  1885. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
  1886. if (status->flag & RX_FLAG_INTERNAL_CMTR)
  1887. goto out_free_skb;
  1888. if (skb_headroom(skb) < sizeof(*rthdr) &&
  1889. pskb_expand_head(skb, sizeof(*rthdr), 0, GFP_ATOMIC))
  1890. goto out_free_skb;
  1891. rthdr = (void *)skb_push(skb, sizeof(*rthdr));
  1892. memset(rthdr, 0, sizeof(*rthdr));
  1893. rthdr->hdr.it_len = cpu_to_le16(sizeof(*rthdr));
  1894. rthdr->hdr.it_present =
  1895. cpu_to_le32((1 << IEEE80211_RADIOTAP_FLAGS) |
  1896. (1 << IEEE80211_RADIOTAP_CHANNEL));
  1897. if (rate) {
  1898. rthdr->rate_or_pad = rate->bitrate / 5;
  1899. rthdr->hdr.it_present |=
  1900. cpu_to_le32(1 << IEEE80211_RADIOTAP_RATE);
  1901. }
  1902. rthdr->chan_freq = cpu_to_le16(status->freq);
  1903. if (status->band == IEEE80211_BAND_5GHZ)
  1904. rthdr->chan_flags = cpu_to_le16(IEEE80211_CHAN_OFDM |
  1905. IEEE80211_CHAN_5GHZ);
  1906. else
  1907. rthdr->chan_flags = cpu_to_le16(IEEE80211_CHAN_DYN |
  1908. IEEE80211_CHAN_2GHZ);
  1909. skb_set_mac_header(skb, 0);
  1910. skb->ip_summed = CHECKSUM_UNNECESSARY;
  1911. skb->pkt_type = PACKET_OTHERHOST;
  1912. skb->protocol = htons(ETH_P_802_2);
  1913. list_for_each_entry_rcu(sdata, &local->interfaces, list) {
  1914. if (!ieee80211_sdata_running(sdata))
  1915. continue;
  1916. if (sdata->vif.type != NL80211_IFTYPE_MONITOR ||
  1917. !(sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES))
  1918. continue;
  1919. if (prev_dev) {
  1920. skb2 = skb_clone(skb, GFP_ATOMIC);
  1921. if (skb2) {
  1922. skb2->dev = prev_dev;
  1923. netif_receive_skb(skb2);
  1924. }
  1925. }
  1926. prev_dev = sdata->dev;
  1927. sdata->dev->stats.rx_packets++;
  1928. sdata->dev->stats.rx_bytes += skb->len;
  1929. }
  1930. if (prev_dev) {
  1931. skb->dev = prev_dev;
  1932. netif_receive_skb(skb);
  1933. skb = NULL;
  1934. } else
  1935. goto out_free_skb;
  1936. status->flag |= RX_FLAG_INTERNAL_CMTR;
  1937. return;
  1938. out_free_skb:
  1939. dev_kfree_skb(skb);
  1940. }
  1941. static void ieee80211_rx_handlers_result(struct ieee80211_rx_data *rx,
  1942. ieee80211_rx_result res)
  1943. {
  1944. switch (res) {
  1945. case RX_DROP_MONITOR:
  1946. I802_DEBUG_INC(rx->sdata->local->rx_handlers_drop);
  1947. if (rx->sta)
  1948. rx->sta->rx_dropped++;
  1949. /* fall through */
  1950. case RX_CONTINUE: {
  1951. struct ieee80211_rate *rate = NULL;
  1952. struct ieee80211_supported_band *sband;
  1953. struct ieee80211_rx_status *status;
  1954. status = IEEE80211_SKB_RXCB((rx->skb));
  1955. sband = rx->local->hw.wiphy->bands[status->band];
  1956. if (!(status->flag & RX_FLAG_HT))
  1957. rate = &sband->bitrates[status->rate_idx];
  1958. ieee80211_rx_cooked_monitor(rx, rate);
  1959. break;
  1960. }
  1961. case RX_DROP_UNUSABLE:
  1962. I802_DEBUG_INC(rx->sdata->local->rx_handlers_drop);
  1963. if (rx->sta)
  1964. rx->sta->rx_dropped++;
  1965. dev_kfree_skb(rx->skb);
  1966. break;
  1967. case RX_QUEUED:
  1968. I802_DEBUG_INC(rx->sdata->local->rx_handlers_queued);
  1969. break;
  1970. }
  1971. }
  1972. static void ieee80211_rx_handlers(struct ieee80211_rx_data *rx,
  1973. struct sk_buff_head *frames)
  1974. {
  1975. ieee80211_rx_result res = RX_DROP_MONITOR;
  1976. struct sk_buff *skb;
  1977. #define CALL_RXH(rxh) \
  1978. do { \
  1979. res = rxh(rx); \
  1980. if (res != RX_CONTINUE) \
  1981. goto rxh_next; \
  1982. } while (0);
  1983. while ((skb = __skb_dequeue(frames))) {
  1984. /*
  1985. * all the other fields are valid across frames
  1986. * that belong to an aMPDU since they are on the
  1987. * same TID from the same station
  1988. */
  1989. rx->skb = skb;
  1990. CALL_RXH(ieee80211_rx_h_decrypt)
  1991. CALL_RXH(ieee80211_rx_h_check_more_data)
  1992. CALL_RXH(ieee80211_rx_h_sta_process)
  1993. CALL_RXH(ieee80211_rx_h_defragment)
  1994. CALL_RXH(ieee80211_rx_h_ps_poll)
  1995. CALL_RXH(ieee80211_rx_h_michael_mic_verify)
  1996. /* must be after MMIC verify so header is counted in MPDU mic */
  1997. CALL_RXH(ieee80211_rx_h_remove_qos_control)
  1998. CALL_RXH(ieee80211_rx_h_amsdu)
  1999. #ifdef CONFIG_MAC80211_MESH
  2000. if (ieee80211_vif_is_mesh(&rx->sdata->vif))
  2001. CALL_RXH(ieee80211_rx_h_mesh_fwding);
  2002. #endif
  2003. CALL_RXH(ieee80211_rx_h_data)
  2004. /* special treatment -- needs the queue */
  2005. res = ieee80211_rx_h_ctrl(rx, frames);
  2006. if (res != RX_CONTINUE)
  2007. goto rxh_next;
  2008. CALL_RXH(ieee80211_rx_h_action)
  2009. CALL_RXH(ieee80211_rx_h_mgmt)
  2010. rxh_next:
  2011. ieee80211_rx_handlers_result(rx, res);
  2012. #undef CALL_RXH
  2013. }
  2014. }
  2015. static void ieee80211_invoke_rx_handlers(struct ieee80211_sub_if_data *sdata,
  2016. struct ieee80211_rx_data *rx,
  2017. struct sk_buff *skb)
  2018. {
  2019. struct sk_buff_head reorder_release;
  2020. ieee80211_rx_result res = RX_DROP_MONITOR;
  2021. __skb_queue_head_init(&reorder_release);
  2022. rx->skb = skb;
  2023. rx->sdata = sdata;
  2024. #define CALL_RXH(rxh) \
  2025. do { \
  2026. res = rxh(rx); \
  2027. if (res != RX_CONTINUE) \
  2028. goto rxh_next; \
  2029. } while (0);
  2030. CALL_RXH(ieee80211_rx_h_passive_scan)
  2031. CALL_RXH(ieee80211_rx_h_check)
  2032. ieee80211_rx_reorder_ampdu(rx, &reorder_release);
  2033. ieee80211_rx_handlers(rx, &reorder_release);
  2034. return;
  2035. rxh_next:
  2036. ieee80211_rx_handlers_result(rx, res);
  2037. #undef CALL_RXH
  2038. }
  2039. /*
  2040. * This function makes calls into the RX path. Therefore the
  2041. * caller must hold the sta_info->lock and everything has to
  2042. * be under rcu_read_lock protection as well.
  2043. */
  2044. void ieee80211_release_reorder_timeout(struct sta_info *sta, int tid)
  2045. {
  2046. struct sk_buff_head frames;
  2047. struct ieee80211_rx_data rx = { };
  2048. __skb_queue_head_init(&frames);
  2049. /* construct rx struct */
  2050. rx.sta = sta;
  2051. rx.sdata = sta->sdata;
  2052. rx.local = sta->local;
  2053. rx.queue = tid;
  2054. rx.flags |= IEEE80211_RX_RA_MATCH;
  2055. if (unlikely(test_bit(SCAN_HW_SCANNING, &sta->local->scanning) ||
  2056. test_bit(SCAN_OFF_CHANNEL, &sta->local->scanning)))
  2057. rx.flags |= IEEE80211_RX_IN_SCAN;
  2058. spin_lock(&sta->ampdu_mlme.tid_rx[tid]->reorder_lock);
  2059. ieee80211_sta_reorder_release(&sta->local->hw,
  2060. sta->ampdu_mlme.tid_rx[tid], &frames);
  2061. spin_unlock(&sta->ampdu_mlme.tid_rx[tid]->reorder_lock);
  2062. ieee80211_rx_handlers(&rx, &frames);
  2063. }
  2064. /* main receive path */
  2065. static int prepare_for_handlers(struct ieee80211_sub_if_data *sdata,
  2066. struct ieee80211_rx_data *rx,
  2067. struct ieee80211_hdr *hdr)
  2068. {
  2069. struct sk_buff *skb = rx->skb;
  2070. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
  2071. u8 *bssid = ieee80211_get_bssid(hdr, skb->len, sdata->vif.type);
  2072. int multicast = is_multicast_ether_addr(hdr->addr1);
  2073. switch (sdata->vif.type) {
  2074. case NL80211_IFTYPE_STATION:
  2075. if (!bssid && !sdata->u.mgd.use_4addr)
  2076. return 0;
  2077. if (!multicast &&
  2078. compare_ether_addr(sdata->vif.addr, hdr->addr1) != 0) {
  2079. if (!(sdata->dev->flags & IFF_PROMISC))
  2080. return 0;
  2081. rx->flags &= ~IEEE80211_RX_RA_MATCH;
  2082. }
  2083. break;
  2084. case NL80211_IFTYPE_ADHOC:
  2085. if (!bssid)
  2086. return 0;
  2087. if (ieee80211_is_beacon(hdr->frame_control)) {
  2088. return 1;
  2089. }
  2090. else if (!ieee80211_bssid_match(bssid, sdata->u.ibss.bssid)) {
  2091. if (!(rx->flags & IEEE80211_RX_IN_SCAN))
  2092. return 0;
  2093. rx->flags &= ~IEEE80211_RX_RA_MATCH;
  2094. } else if (!multicast &&
  2095. compare_ether_addr(sdata->vif.addr,
  2096. hdr->addr1) != 0) {
  2097. if (!(sdata->dev->flags & IFF_PROMISC))
  2098. return 0;
  2099. rx->flags &= ~IEEE80211_RX_RA_MATCH;
  2100. } else if (!rx->sta) {
  2101. int rate_idx;
  2102. if (status->flag & RX_FLAG_HT)
  2103. rate_idx = 0; /* TODO: HT rates */
  2104. else
  2105. rate_idx = status->rate_idx;
  2106. rx->sta = ieee80211_ibss_add_sta(sdata, bssid,
  2107. hdr->addr2, BIT(rate_idx), GFP_ATOMIC);
  2108. }
  2109. break;
  2110. case NL80211_IFTYPE_MESH_POINT:
  2111. if (!multicast &&
  2112. compare_ether_addr(sdata->vif.addr,
  2113. hdr->addr1) != 0) {
  2114. if (!(sdata->dev->flags & IFF_PROMISC))
  2115. return 0;
  2116. rx->flags &= ~IEEE80211_RX_RA_MATCH;
  2117. }
  2118. break;
  2119. case NL80211_IFTYPE_AP_VLAN:
  2120. case NL80211_IFTYPE_AP:
  2121. if (!bssid) {
  2122. if (compare_ether_addr(sdata->vif.addr,
  2123. hdr->addr1))
  2124. return 0;
  2125. } else if (!ieee80211_bssid_match(bssid,
  2126. sdata->vif.addr)) {
  2127. if (!(rx->flags & IEEE80211_RX_IN_SCAN))
  2128. return 0;
  2129. rx->flags &= ~IEEE80211_RX_RA_MATCH;
  2130. }
  2131. break;
  2132. case NL80211_IFTYPE_WDS:
  2133. if (bssid || !ieee80211_is_data(hdr->frame_control))
  2134. return 0;
  2135. if (compare_ether_addr(sdata->u.wds.remote_addr, hdr->addr2))
  2136. return 0;
  2137. break;
  2138. case NL80211_IFTYPE_MONITOR:
  2139. case NL80211_IFTYPE_UNSPECIFIED:
  2140. case __NL80211_IFTYPE_AFTER_LAST:
  2141. /* should never get here */
  2142. WARN_ON(1);
  2143. break;
  2144. }
  2145. return 1;
  2146. }
  2147. /*
  2148. * This is the actual Rx frames handler. as it blongs to Rx path it must
  2149. * be called with rcu_read_lock protection.
  2150. */
  2151. static void __ieee80211_rx_handle_packet(struct ieee80211_hw *hw,
  2152. struct sk_buff *skb)
  2153. {
  2154. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
  2155. struct ieee80211_local *local = hw_to_local(hw);
  2156. struct ieee80211_sub_if_data *sdata;
  2157. struct ieee80211_hdr *hdr;
  2158. __le16 fc;
  2159. struct ieee80211_rx_data rx;
  2160. int prepares;
  2161. struct ieee80211_sub_if_data *prev = NULL;
  2162. struct sk_buff *skb_new;
  2163. struct sta_info *sta, *tmp;
  2164. bool found_sta = false;
  2165. int err = 0;
  2166. fc = ((struct ieee80211_hdr *)skb->data)->frame_control;
  2167. memset(&rx, 0, sizeof(rx));
  2168. rx.skb = skb;
  2169. rx.local = local;
  2170. if (ieee80211_is_data(fc) || ieee80211_is_mgmt(fc))
  2171. local->dot11ReceivedFragmentCount++;
  2172. if (unlikely(test_bit(SCAN_HW_SCANNING, &local->scanning) ||
  2173. test_bit(SCAN_OFF_CHANNEL, &local->scanning)))
  2174. rx.flags |= IEEE80211_RX_IN_SCAN;
  2175. if (ieee80211_is_mgmt(fc))
  2176. err = skb_linearize(skb);
  2177. else
  2178. err = !pskb_may_pull(skb, ieee80211_hdrlen(fc));
  2179. if (err) {
  2180. dev_kfree_skb(skb);
  2181. return;
  2182. }
  2183. hdr = (struct ieee80211_hdr *)skb->data;
  2184. ieee80211_parse_qos(&rx);
  2185. ieee80211_verify_alignment(&rx);
  2186. if (ieee80211_is_data(fc)) {
  2187. for_each_sta_info(local, hdr->addr2, sta, tmp) {
  2188. rx.sta = sta;
  2189. found_sta = true;
  2190. rx.sdata = sta->sdata;
  2191. rx.flags |= IEEE80211_RX_RA_MATCH;
  2192. prepares = prepare_for_handlers(rx.sdata, &rx, hdr);
  2193. if (prepares) {
  2194. if (status->flag & RX_FLAG_MMIC_ERROR) {
  2195. if (rx.flags & IEEE80211_RX_RA_MATCH)
  2196. ieee80211_rx_michael_mic_report(hdr, &rx);
  2197. } else
  2198. prev = rx.sdata;
  2199. }
  2200. }
  2201. }
  2202. if (!found_sta) {
  2203. list_for_each_entry_rcu(sdata, &local->interfaces, list) {
  2204. if (!ieee80211_sdata_running(sdata))
  2205. continue;
  2206. if (sdata->vif.type == NL80211_IFTYPE_MONITOR ||
  2207. sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
  2208. continue;
  2209. /*
  2210. * frame is destined for this interface, but if it's
  2211. * not also for the previous one we handle that after
  2212. * the loop to avoid copying the SKB once too much
  2213. */
  2214. if (!prev) {
  2215. prev = sdata;
  2216. continue;
  2217. }
  2218. rx.sta = sta_info_get_bss(prev, hdr->addr2);
  2219. rx.flags |= IEEE80211_RX_RA_MATCH;
  2220. prepares = prepare_for_handlers(prev, &rx, hdr);
  2221. if (!prepares)
  2222. goto next;
  2223. if (status->flag & RX_FLAG_MMIC_ERROR) {
  2224. rx.sdata = prev;
  2225. if (rx.flags & IEEE80211_RX_RA_MATCH)
  2226. ieee80211_rx_michael_mic_report(hdr,
  2227. &rx);
  2228. goto next;
  2229. }
  2230. /*
  2231. * frame was destined for the previous interface
  2232. * so invoke RX handlers for it
  2233. */
  2234. skb_new = skb_copy(skb, GFP_ATOMIC);
  2235. if (!skb_new) {
  2236. if (net_ratelimit())
  2237. printk(KERN_DEBUG "%s: failed to copy "
  2238. "multicast frame for %s\n",
  2239. wiphy_name(local->hw.wiphy),
  2240. prev->name);
  2241. goto next;
  2242. }
  2243. ieee80211_invoke_rx_handlers(prev, &rx, skb_new);
  2244. next:
  2245. prev = sdata;
  2246. }
  2247. if (prev) {
  2248. rx.sta = sta_info_get_bss(prev, hdr->addr2);
  2249. rx.flags |= IEEE80211_RX_RA_MATCH;
  2250. prepares = prepare_for_handlers(prev, &rx, hdr);
  2251. if (!prepares)
  2252. prev = NULL;
  2253. }
  2254. }
  2255. if (prev)
  2256. ieee80211_invoke_rx_handlers(prev, &rx, skb);
  2257. else
  2258. dev_kfree_skb(skb);
  2259. }
  2260. /*
  2261. * This is the receive path handler. It is called by a low level driver when an
  2262. * 802.11 MPDU is received from the hardware.
  2263. */
  2264. void ieee80211_rx(struct ieee80211_hw *hw, struct sk_buff *skb)
  2265. {
  2266. struct ieee80211_local *local = hw_to_local(hw);
  2267. struct ieee80211_rate *rate = NULL;
  2268. struct ieee80211_supported_band *sband;
  2269. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
  2270. WARN_ON_ONCE(softirq_count() == 0);
  2271. if (WARN_ON(status->band < 0 ||
  2272. status->band >= IEEE80211_NUM_BANDS))
  2273. goto drop;
  2274. sband = local->hw.wiphy->bands[status->band];
  2275. if (WARN_ON(!sband))
  2276. goto drop;
  2277. /*
  2278. * If we're suspending, it is possible although not too likely
  2279. * that we'd be receiving frames after having already partially
  2280. * quiesced the stack. We can't process such frames then since
  2281. * that might, for example, cause stations to be added or other
  2282. * driver callbacks be invoked.
  2283. */
  2284. if (unlikely(local->quiescing || local->suspended))
  2285. goto drop;
  2286. /*
  2287. * The same happens when we're not even started,
  2288. * but that's worth a warning.
  2289. */
  2290. if (WARN_ON(!local->started))
  2291. goto drop;
  2292. if (likely(!(status->flag & RX_FLAG_FAILED_PLCP_CRC))) {
  2293. /*
  2294. * Validate the rate, unless a PLCP error means that
  2295. * we probably can't have a valid rate here anyway.
  2296. */
  2297. if (status->flag & RX_FLAG_HT) {
  2298. /*
  2299. * rate_idx is MCS index, which can be [0-76]
  2300. * as documented on:
  2301. *
  2302. * http://wireless.kernel.org/en/developers/Documentation/ieee80211/802.11n
  2303. *
  2304. * Anything else would be some sort of driver or
  2305. * hardware error. The driver should catch hardware
  2306. * errors.
  2307. */
  2308. if (WARN((status->rate_idx < 0 ||
  2309. status->rate_idx > 76),
  2310. "Rate marked as an HT rate but passed "
  2311. "status->rate_idx is not "
  2312. "an MCS index [0-76]: %d (0x%02x)\n",
  2313. status->rate_idx,
  2314. status->rate_idx))
  2315. goto drop;
  2316. } else {
  2317. if (WARN_ON(status->rate_idx < 0 ||
  2318. status->rate_idx >= sband->n_bitrates))
  2319. goto drop;
  2320. rate = &sband->bitrates[status->rate_idx];
  2321. }
  2322. }
  2323. /*
  2324. * key references and virtual interfaces are protected using RCU
  2325. * and this requires that we are in a read-side RCU section during
  2326. * receive processing
  2327. */
  2328. rcu_read_lock();
  2329. /*
  2330. * Frames with failed FCS/PLCP checksum are not returned,
  2331. * all other frames are returned without radiotap header
  2332. * if it was previously present.
  2333. * Also, frames with less than 16 bytes are dropped.
  2334. */
  2335. skb = ieee80211_rx_monitor(local, skb, rate);
  2336. if (!skb) {
  2337. rcu_read_unlock();
  2338. return;
  2339. }
  2340. __ieee80211_rx_handle_packet(hw, skb);
  2341. rcu_read_unlock();
  2342. return;
  2343. drop:
  2344. kfree_skb(skb);
  2345. }
  2346. EXPORT_SYMBOL(ieee80211_rx);
  2347. /* This is a version of the rx handler that can be called from hard irq
  2348. * context. Post the skb on the queue and schedule the tasklet */
  2349. void ieee80211_rx_irqsafe(struct ieee80211_hw *hw, struct sk_buff *skb)
  2350. {
  2351. struct ieee80211_local *local = hw_to_local(hw);
  2352. BUILD_BUG_ON(sizeof(struct ieee80211_rx_status) > sizeof(skb->cb));
  2353. skb->pkt_type = IEEE80211_RX_MSG;
  2354. skb_queue_tail(&local->skb_queue, skb);
  2355. tasklet_schedule(&local->tasklet);
  2356. }
  2357. EXPORT_SYMBOL(ieee80211_rx_irqsafe);