rx.c 62 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242
  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 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/kernel.h>
  13. #include <linux/skbuff.h>
  14. #include <linux/netdevice.h>
  15. #include <linux/etherdevice.h>
  16. #include <linux/rcupdate.h>
  17. #include <net/mac80211.h>
  18. #include <net/ieee80211_radiotap.h>
  19. #include "ieee80211_i.h"
  20. #include "ieee80211_led.h"
  21. #include "mesh.h"
  22. #include "wep.h"
  23. #include "wpa.h"
  24. #include "tkip.h"
  25. #include "wme.h"
  26. u8 ieee80211_sta_manage_reorder_buf(struct ieee80211_hw *hw,
  27. struct tid_ampdu_rx *tid_agg_rx,
  28. struct sk_buff *skb, u16 mpdu_seq_num,
  29. int bar_req);
  30. /*
  31. * monitor mode reception
  32. *
  33. * This function cleans up the SKB, i.e. it removes all the stuff
  34. * only useful for monitoring.
  35. */
  36. static struct sk_buff *remove_monitor_info(struct ieee80211_local *local,
  37. struct sk_buff *skb,
  38. int rtap_len)
  39. {
  40. skb_pull(skb, rtap_len);
  41. if (local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS) {
  42. if (likely(skb->len > FCS_LEN))
  43. skb_trim(skb, skb->len - FCS_LEN);
  44. else {
  45. /* driver bug */
  46. WARN_ON(1);
  47. dev_kfree_skb(skb);
  48. skb = NULL;
  49. }
  50. }
  51. return skb;
  52. }
  53. static inline int should_drop_frame(struct ieee80211_rx_status *status,
  54. struct sk_buff *skb,
  55. int present_fcs_len,
  56. int radiotap_len)
  57. {
  58. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
  59. if (status->flag & (RX_FLAG_FAILED_FCS_CRC | RX_FLAG_FAILED_PLCP_CRC))
  60. return 1;
  61. if (unlikely(skb->len < 16 + present_fcs_len + radiotap_len))
  62. return 1;
  63. if (((hdr->frame_control & cpu_to_le16(IEEE80211_FCTL_FTYPE)) ==
  64. cpu_to_le16(IEEE80211_FTYPE_CTL)) &&
  65. ((hdr->frame_control & cpu_to_le16(IEEE80211_FCTL_STYPE)) !=
  66. cpu_to_le16(IEEE80211_STYPE_PSPOLL)) &&
  67. ((hdr->frame_control & cpu_to_le16(IEEE80211_FCTL_STYPE)) !=
  68. cpu_to_le16(IEEE80211_STYPE_BACK_REQ)))
  69. return 1;
  70. return 0;
  71. }
  72. /*
  73. * This function copies a received frame to all monitor interfaces and
  74. * returns a cleaned-up SKB that no longer includes the FCS nor the
  75. * radiotap header the driver might have added.
  76. */
  77. static struct sk_buff *
  78. ieee80211_rx_monitor(struct ieee80211_local *local, struct sk_buff *origskb,
  79. struct ieee80211_rx_status *status,
  80. struct ieee80211_rate *rate)
  81. {
  82. struct ieee80211_sub_if_data *sdata;
  83. int needed_headroom = 0;
  84. struct ieee80211_radiotap_header *rthdr;
  85. __le64 *rttsft = NULL;
  86. struct ieee80211_rtap_fixed_data {
  87. u8 flags;
  88. u8 rate;
  89. __le16 chan_freq;
  90. __le16 chan_flags;
  91. u8 antsignal;
  92. u8 padding_for_rxflags;
  93. __le16 rx_flags;
  94. } __attribute__ ((packed)) *rtfixed;
  95. struct sk_buff *skb, *skb2;
  96. struct net_device *prev_dev = NULL;
  97. int present_fcs_len = 0;
  98. int rtap_len = 0;
  99. /*
  100. * First, we may need to make a copy of the skb because
  101. * (1) we need to modify it for radiotap (if not present), and
  102. * (2) the other RX handlers will modify the skb we got.
  103. *
  104. * We don't need to, of course, if we aren't going to return
  105. * the SKB because it has a bad FCS/PLCP checksum.
  106. */
  107. if (status->flag & RX_FLAG_RADIOTAP)
  108. rtap_len = ieee80211_get_radiotap_len(origskb->data);
  109. else
  110. /* room for radiotap header, always present fields and TSFT */
  111. needed_headroom = sizeof(*rthdr) + sizeof(*rtfixed) + 8;
  112. if (local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS)
  113. present_fcs_len = FCS_LEN;
  114. if (!local->monitors) {
  115. if (should_drop_frame(status, origskb, present_fcs_len,
  116. rtap_len)) {
  117. dev_kfree_skb(origskb);
  118. return NULL;
  119. }
  120. return remove_monitor_info(local, origskb, rtap_len);
  121. }
  122. if (should_drop_frame(status, origskb, present_fcs_len, rtap_len)) {
  123. /* only need to expand headroom if necessary */
  124. skb = origskb;
  125. origskb = NULL;
  126. /*
  127. * This shouldn't trigger often because most devices have an
  128. * RX header they pull before we get here, and that should
  129. * be big enough for our radiotap information. We should
  130. * probably export the length to drivers so that we can have
  131. * them allocate enough headroom to start with.
  132. */
  133. if (skb_headroom(skb) < needed_headroom &&
  134. pskb_expand_head(skb, needed_headroom, 0, GFP_ATOMIC)) {
  135. dev_kfree_skb(skb);
  136. return NULL;
  137. }
  138. } else {
  139. /*
  140. * Need to make a copy and possibly remove radiotap header
  141. * and FCS from the original.
  142. */
  143. skb = skb_copy_expand(origskb, needed_headroom, 0, GFP_ATOMIC);
  144. origskb = remove_monitor_info(local, origskb, rtap_len);
  145. if (!skb)
  146. return origskb;
  147. }
  148. /* if necessary, prepend radiotap information */
  149. if (!(status->flag & RX_FLAG_RADIOTAP)) {
  150. rtfixed = (void *) skb_push(skb, sizeof(*rtfixed));
  151. rtap_len = sizeof(*rthdr) + sizeof(*rtfixed);
  152. if (status->flag & RX_FLAG_TSFT) {
  153. rttsft = (void *) skb_push(skb, sizeof(*rttsft));
  154. rtap_len += 8;
  155. }
  156. rthdr = (void *) skb_push(skb, sizeof(*rthdr));
  157. memset(rthdr, 0, sizeof(*rthdr));
  158. memset(rtfixed, 0, sizeof(*rtfixed));
  159. rthdr->it_present =
  160. cpu_to_le32((1 << IEEE80211_RADIOTAP_FLAGS) |
  161. (1 << IEEE80211_RADIOTAP_RATE) |
  162. (1 << IEEE80211_RADIOTAP_CHANNEL) |
  163. (1 << IEEE80211_RADIOTAP_DB_ANTSIGNAL) |
  164. (1 << IEEE80211_RADIOTAP_RX_FLAGS));
  165. rtfixed->flags = 0;
  166. if (local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS)
  167. rtfixed->flags |= IEEE80211_RADIOTAP_F_FCS;
  168. if (rttsft) {
  169. *rttsft = cpu_to_le64(status->mactime);
  170. rthdr->it_present |=
  171. cpu_to_le32(1 << IEEE80211_RADIOTAP_TSFT);
  172. }
  173. /* FIXME: when radiotap gets a 'bad PLCP' flag use it here */
  174. rtfixed->rx_flags = 0;
  175. if (status->flag &
  176. (RX_FLAG_FAILED_FCS_CRC | RX_FLAG_FAILED_PLCP_CRC))
  177. rtfixed->rx_flags |=
  178. cpu_to_le16(IEEE80211_RADIOTAP_F_RX_BADFCS);
  179. rtfixed->rate = rate->bitrate / 5;
  180. rtfixed->chan_freq = cpu_to_le16(status->freq);
  181. if (status->band == IEEE80211_BAND_5GHZ)
  182. rtfixed->chan_flags =
  183. cpu_to_le16(IEEE80211_CHAN_OFDM |
  184. IEEE80211_CHAN_5GHZ);
  185. else
  186. rtfixed->chan_flags =
  187. cpu_to_le16(IEEE80211_CHAN_DYN |
  188. IEEE80211_CHAN_2GHZ);
  189. rtfixed->antsignal = status->ssi;
  190. rthdr->it_len = cpu_to_le16(rtap_len);
  191. }
  192. skb_reset_mac_header(skb);
  193. skb->ip_summed = CHECKSUM_UNNECESSARY;
  194. skb->pkt_type = PACKET_OTHERHOST;
  195. skb->protocol = htons(ETH_P_802_2);
  196. list_for_each_entry_rcu(sdata, &local->interfaces, list) {
  197. if (!netif_running(sdata->dev))
  198. continue;
  199. if (sdata->vif.type != IEEE80211_IF_TYPE_MNTR)
  200. continue;
  201. if (sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES)
  202. continue;
  203. if (prev_dev) {
  204. skb2 = skb_clone(skb, GFP_ATOMIC);
  205. if (skb2) {
  206. skb2->dev = prev_dev;
  207. netif_rx(skb2);
  208. }
  209. }
  210. prev_dev = sdata->dev;
  211. sdata->dev->stats.rx_packets++;
  212. sdata->dev->stats.rx_bytes += skb->len;
  213. }
  214. if (prev_dev) {
  215. skb->dev = prev_dev;
  216. netif_rx(skb);
  217. } else
  218. dev_kfree_skb(skb);
  219. return origskb;
  220. }
  221. static void ieee80211_parse_qos(struct ieee80211_txrx_data *rx)
  222. {
  223. u8 *data = rx->skb->data;
  224. int tid;
  225. /* does the frame have a qos control field? */
  226. if (WLAN_FC_IS_QOS_DATA(rx->fc)) {
  227. u8 *qc = data + ieee80211_get_hdrlen(rx->fc) - QOS_CONTROL_LEN;
  228. /* frame has qos control */
  229. tid = qc[0] & QOS_CONTROL_TID_MASK;
  230. if (qc[0] & IEEE80211_QOS_CONTROL_A_MSDU_PRESENT)
  231. rx->flags |= IEEE80211_TXRXD_RX_AMSDU;
  232. else
  233. rx->flags &= ~IEEE80211_TXRXD_RX_AMSDU;
  234. } else {
  235. if (unlikely((rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT)) {
  236. /* Separate TID for management frames */
  237. tid = NUM_RX_DATA_QUEUES - 1;
  238. } else {
  239. /* no qos control present */
  240. tid = 0; /* 802.1d - Best Effort */
  241. }
  242. }
  243. I802_DEBUG_INC(rx->local->wme_rx_queue[tid]);
  244. /* only a debug counter, sta might not be assigned properly yet */
  245. if (rx->sta)
  246. I802_DEBUG_INC(rx->sta->wme_rx_queue[tid]);
  247. rx->u.rx.queue = tid;
  248. /* Set skb->priority to 1d tag if highest order bit of TID is not set.
  249. * For now, set skb->priority to 0 for other cases. */
  250. rx->skb->priority = (tid > 7) ? 0 : tid;
  251. }
  252. static void ieee80211_verify_ip_alignment(struct ieee80211_txrx_data *rx)
  253. {
  254. #ifdef CONFIG_MAC80211_DEBUG_PACKET_ALIGNMENT
  255. int hdrlen;
  256. if (!WLAN_FC_DATA_PRESENT(rx->fc))
  257. return;
  258. /*
  259. * Drivers are required to align the payload data in a way that
  260. * guarantees that the contained IP header is aligned to a four-
  261. * byte boundary. In the case of regular frames, this simply means
  262. * aligning the payload to a four-byte boundary (because either
  263. * the IP header is directly contained, or IV/RFC1042 headers that
  264. * have a length divisible by four are in front of it.
  265. *
  266. * With A-MSDU frames, however, the payload data address must
  267. * yield two modulo four because there are 14-byte 802.3 headers
  268. * within the A-MSDU frames that push the IP header further back
  269. * to a multiple of four again. Thankfully, the specs were sane
  270. * enough this time around to require padding each A-MSDU subframe
  271. * to a length that is a multiple of four.
  272. *
  273. * Padding like atheros hardware adds which is inbetween the 802.11
  274. * header and the payload is not supported, the driver is required
  275. * to move the 802.11 header further back in that case.
  276. */
  277. hdrlen = ieee80211_get_hdrlen(rx->fc);
  278. if (rx->flags & IEEE80211_TXRXD_RX_AMSDU)
  279. hdrlen += ETH_HLEN;
  280. WARN_ON_ONCE(((unsigned long)(rx->skb->data + hdrlen)) & 3);
  281. #endif
  282. }
  283. static u32 ieee80211_rx_load_stats(struct ieee80211_local *local,
  284. struct sk_buff *skb,
  285. struct ieee80211_rx_status *status,
  286. struct ieee80211_rate *rate)
  287. {
  288. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
  289. u32 load = 0, hdrtime;
  290. /* Estimate total channel use caused by this frame */
  291. /* 1 bit at 1 Mbit/s takes 1 usec; in channel_use values,
  292. * 1 usec = 1/8 * (1080 / 10) = 13.5 */
  293. if (status->band == IEEE80211_BAND_5GHZ ||
  294. (status->band == IEEE80211_BAND_5GHZ &&
  295. rate->flags & IEEE80211_RATE_ERP_G))
  296. hdrtime = CHAN_UTIL_HDR_SHORT;
  297. else
  298. hdrtime = CHAN_UTIL_HDR_LONG;
  299. load = hdrtime;
  300. if (!is_multicast_ether_addr(hdr->addr1))
  301. load += hdrtime;
  302. /* TODO: optimise again */
  303. load += skb->len * CHAN_UTIL_RATE_LCM / rate->bitrate;
  304. /* Divide channel_use by 8 to avoid wrapping around the counter */
  305. load >>= CHAN_UTIL_SHIFT;
  306. return load;
  307. }
  308. /* rx handlers */
  309. static ieee80211_rx_result
  310. ieee80211_rx_h_if_stats(struct ieee80211_txrx_data *rx)
  311. {
  312. if (rx->sta)
  313. rx->sta->channel_use_raw += rx->u.rx.load;
  314. rx->sdata->channel_use_raw += rx->u.rx.load;
  315. return RX_CONTINUE;
  316. }
  317. static ieee80211_rx_result
  318. ieee80211_rx_h_passive_scan(struct ieee80211_txrx_data *rx)
  319. {
  320. struct ieee80211_local *local = rx->local;
  321. struct sk_buff *skb = rx->skb;
  322. if (unlikely(local->sta_hw_scanning))
  323. return ieee80211_sta_rx_scan(rx->dev, skb, rx->u.rx.status);
  324. if (unlikely(local->sta_sw_scanning)) {
  325. /* drop all the other packets during a software scan anyway */
  326. if (ieee80211_sta_rx_scan(rx->dev, skb, rx->u.rx.status)
  327. != RX_QUEUED)
  328. dev_kfree_skb(skb);
  329. return RX_QUEUED;
  330. }
  331. if (unlikely(rx->flags & IEEE80211_TXRXD_RXIN_SCAN)) {
  332. /* scanning finished during invoking of handlers */
  333. I802_DEBUG_INC(local->rx_handlers_drop_passive_scan);
  334. return RX_DROP_UNUSABLE;
  335. }
  336. return RX_CONTINUE;
  337. }
  338. static ieee80211_rx_result
  339. ieee80211_rx_mesh_check(struct ieee80211_txrx_data *rx)
  340. {
  341. int hdrlen = ieee80211_get_hdrlen(rx->fc);
  342. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) rx->skb->data;
  343. #define msh_h_get(h, l) ((struct ieee80211s_hdr *) ((u8 *)h + l))
  344. if ((rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA) {
  345. if (!((rx->fc & IEEE80211_FCTL_FROMDS) &&
  346. (rx->fc & IEEE80211_FCTL_TODS)))
  347. return RX_DROP_MONITOR;
  348. if (memcmp(hdr->addr4, rx->dev->dev_addr, ETH_ALEN) == 0)
  349. return RX_DROP_MONITOR;
  350. }
  351. /* If there is not an established peer link and this is not a peer link
  352. * establisment frame, beacon or probe, drop the frame.
  353. */
  354. if (!rx->sta || sta_plink_state(rx->sta) != ESTAB) {
  355. struct ieee80211_mgmt *mgmt;
  356. if ((rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_MGMT)
  357. return RX_DROP_MONITOR;
  358. switch (rx->fc & IEEE80211_FCTL_STYPE) {
  359. case IEEE80211_STYPE_ACTION:
  360. mgmt = (struct ieee80211_mgmt *)hdr;
  361. if (mgmt->u.action.category != PLINK_CATEGORY)
  362. return RX_DROP_MONITOR;
  363. /* fall through on else */
  364. case IEEE80211_STYPE_PROBE_REQ:
  365. case IEEE80211_STYPE_PROBE_RESP:
  366. case IEEE80211_STYPE_BEACON:
  367. return RX_CONTINUE;
  368. break;
  369. default:
  370. return RX_DROP_MONITOR;
  371. }
  372. } else if ((rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA &&
  373. is_broadcast_ether_addr(hdr->addr1) &&
  374. mesh_rmc_check(hdr->addr4, msh_h_get(hdr, hdrlen), rx->dev))
  375. return RX_DROP_MONITOR;
  376. #undef msh_h_get
  377. return RX_CONTINUE;
  378. }
  379. static ieee80211_rx_result
  380. ieee80211_rx_h_check(struct ieee80211_txrx_data *rx)
  381. {
  382. struct ieee80211_hdr *hdr;
  383. hdr = (struct ieee80211_hdr *) rx->skb->data;
  384. /* Drop duplicate 802.11 retransmissions (IEEE 802.11 Chap. 9.2.9) */
  385. if (rx->sta && !is_multicast_ether_addr(hdr->addr1)) {
  386. if (unlikely(rx->fc & IEEE80211_FCTL_RETRY &&
  387. rx->sta->last_seq_ctrl[rx->u.rx.queue] ==
  388. hdr->seq_ctrl)) {
  389. if (rx->flags & IEEE80211_TXRXD_RXRA_MATCH) {
  390. rx->local->dot11FrameDuplicateCount++;
  391. rx->sta->num_duplicates++;
  392. }
  393. return RX_DROP_MONITOR;
  394. } else
  395. rx->sta->last_seq_ctrl[rx->u.rx.queue] = hdr->seq_ctrl;
  396. }
  397. if (unlikely(rx->skb->len < 16)) {
  398. I802_DEBUG_INC(rx->local->rx_handlers_drop_short);
  399. return RX_DROP_MONITOR;
  400. }
  401. /* Drop disallowed frame classes based on STA auth/assoc state;
  402. * IEEE 802.11, Chap 5.5.
  403. *
  404. * 80211.o does filtering only based on association state, i.e., it
  405. * drops Class 3 frames from not associated stations. hostapd sends
  406. * deauth/disassoc frames when needed. In addition, hostapd is
  407. * responsible for filtering on both auth and assoc states.
  408. */
  409. if (ieee80211_vif_is_mesh(&rx->sdata->vif))
  410. return ieee80211_rx_mesh_check(rx);
  411. if (unlikely(((rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA ||
  412. ((rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_CTL &&
  413. (rx->fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_PSPOLL)) &&
  414. rx->sdata->vif.type != IEEE80211_IF_TYPE_IBSS &&
  415. (!rx->sta || !(rx->sta->flags & WLAN_STA_ASSOC)))) {
  416. if ((!(rx->fc & IEEE80211_FCTL_FROMDS) &&
  417. !(rx->fc & IEEE80211_FCTL_TODS) &&
  418. (rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA)
  419. || !(rx->flags & IEEE80211_TXRXD_RXRA_MATCH)) {
  420. /* Drop IBSS frames and frames for other hosts
  421. * silently. */
  422. return RX_DROP_MONITOR;
  423. }
  424. return RX_DROP_MONITOR;
  425. }
  426. return RX_CONTINUE;
  427. }
  428. static ieee80211_rx_result
  429. ieee80211_rx_h_decrypt(struct ieee80211_txrx_data *rx)
  430. {
  431. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) rx->skb->data;
  432. int keyidx;
  433. int hdrlen;
  434. ieee80211_rx_result result = RX_DROP_UNUSABLE;
  435. struct ieee80211_key *stakey = NULL;
  436. /*
  437. * Key selection 101
  438. *
  439. * There are three types of keys:
  440. * - GTK (group keys)
  441. * - PTK (pairwise keys)
  442. * - STK (station-to-station pairwise keys)
  443. *
  444. * When selecting a key, we have to distinguish between multicast
  445. * (including broadcast) and unicast frames, the latter can only
  446. * use PTKs and STKs while the former always use GTKs. Unless, of
  447. * course, actual WEP keys ("pre-RSNA") are used, then unicast
  448. * frames can also use key indizes like GTKs. Hence, if we don't
  449. * have a PTK/STK we check the key index for a WEP key.
  450. *
  451. * Note that in a regular BSS, multicast frames are sent by the
  452. * AP only, associated stations unicast the frame to the AP first
  453. * which then multicasts it on their behalf.
  454. *
  455. * There is also a slight problem in IBSS mode: GTKs are negotiated
  456. * with each station, that is something we don't currently handle.
  457. * The spec seems to expect that one negotiates the same key with
  458. * every station but there's no such requirement; VLANs could be
  459. * possible.
  460. */
  461. if (!(rx->fc & IEEE80211_FCTL_PROTECTED))
  462. return RX_CONTINUE;
  463. /*
  464. * No point in finding a key and decrypting if the frame is neither
  465. * addressed to us nor a multicast frame.
  466. */
  467. if (!(rx->flags & IEEE80211_TXRXD_RXRA_MATCH))
  468. return RX_CONTINUE;
  469. if (rx->sta)
  470. stakey = rcu_dereference(rx->sta->key);
  471. if (!is_multicast_ether_addr(hdr->addr1) && stakey) {
  472. rx->key = stakey;
  473. } else {
  474. /*
  475. * The device doesn't give us the IV so we won't be
  476. * able to look up the key. That's ok though, we
  477. * don't need to decrypt the frame, we just won't
  478. * be able to keep statistics accurate.
  479. * Except for key threshold notifications, should
  480. * we somehow allow the driver to tell us which key
  481. * the hardware used if this flag is set?
  482. */
  483. if ((rx->u.rx.status->flag & RX_FLAG_DECRYPTED) &&
  484. (rx->u.rx.status->flag & RX_FLAG_IV_STRIPPED))
  485. return RX_CONTINUE;
  486. hdrlen = ieee80211_get_hdrlen(rx->fc);
  487. if (rx->skb->len < 8 + hdrlen)
  488. return RX_DROP_UNUSABLE; /* TODO: count this? */
  489. /*
  490. * no need to call ieee80211_wep_get_keyidx,
  491. * it verifies a bunch of things we've done already
  492. */
  493. keyidx = rx->skb->data[hdrlen + 3] >> 6;
  494. rx->key = rcu_dereference(rx->sdata->keys[keyidx]);
  495. /*
  496. * RSNA-protected unicast frames should always be sent with
  497. * pairwise or station-to-station keys, but for WEP we allow
  498. * using a key index as well.
  499. */
  500. if (rx->key && rx->key->conf.alg != ALG_WEP &&
  501. !is_multicast_ether_addr(hdr->addr1))
  502. rx->key = NULL;
  503. }
  504. if (rx->key) {
  505. rx->key->tx_rx_count++;
  506. /* TODO: add threshold stuff again */
  507. } else {
  508. #ifdef CONFIG_MAC80211_DEBUG
  509. if (net_ratelimit())
  510. printk(KERN_DEBUG "%s: RX protected frame,"
  511. " but have no key\n", rx->dev->name);
  512. #endif /* CONFIG_MAC80211_DEBUG */
  513. return RX_DROP_MONITOR;
  514. }
  515. /* Check for weak IVs if possible */
  516. if (rx->sta && rx->key->conf.alg == ALG_WEP &&
  517. ((rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA) &&
  518. (!(rx->u.rx.status->flag & RX_FLAG_IV_STRIPPED) ||
  519. !(rx->u.rx.status->flag & RX_FLAG_DECRYPTED)) &&
  520. ieee80211_wep_is_weak_iv(rx->skb, rx->key))
  521. rx->sta->wep_weak_iv_count++;
  522. switch (rx->key->conf.alg) {
  523. case ALG_WEP:
  524. result = ieee80211_crypto_wep_decrypt(rx);
  525. break;
  526. case ALG_TKIP:
  527. result = ieee80211_crypto_tkip_decrypt(rx);
  528. break;
  529. case ALG_CCMP:
  530. result = ieee80211_crypto_ccmp_decrypt(rx);
  531. break;
  532. }
  533. /* either the frame has been decrypted or will be dropped */
  534. rx->u.rx.status->flag |= RX_FLAG_DECRYPTED;
  535. return result;
  536. }
  537. static void ap_sta_ps_start(struct net_device *dev, struct sta_info *sta)
  538. {
  539. struct ieee80211_sub_if_data *sdata;
  540. DECLARE_MAC_BUF(mac);
  541. sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev);
  542. if (sdata->bss)
  543. atomic_inc(&sdata->bss->num_sta_ps);
  544. sta->flags |= WLAN_STA_PS;
  545. sta->flags &= ~WLAN_STA_PSPOLL;
  546. #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
  547. printk(KERN_DEBUG "%s: STA %s aid %d enters power save mode\n",
  548. dev->name, print_mac(mac, sta->addr), sta->aid);
  549. #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
  550. }
  551. static int ap_sta_ps_end(struct net_device *dev, struct sta_info *sta)
  552. {
  553. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  554. struct sk_buff *skb;
  555. int sent = 0;
  556. struct ieee80211_sub_if_data *sdata;
  557. struct ieee80211_tx_packet_data *pkt_data;
  558. DECLARE_MAC_BUF(mac);
  559. sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev);
  560. if (sdata->bss)
  561. atomic_dec(&sdata->bss->num_sta_ps);
  562. sta->flags &= ~(WLAN_STA_PS | WLAN_STA_PSPOLL);
  563. if (!skb_queue_empty(&sta->ps_tx_buf))
  564. sta_info_clear_tim_bit(sta);
  565. #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
  566. printk(KERN_DEBUG "%s: STA %s aid %d exits power save mode\n",
  567. dev->name, print_mac(mac, sta->addr), sta->aid);
  568. #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
  569. /* Send all buffered frames to the station */
  570. while ((skb = skb_dequeue(&sta->tx_filtered)) != NULL) {
  571. pkt_data = (struct ieee80211_tx_packet_data *) skb->cb;
  572. sent++;
  573. pkt_data->flags |= IEEE80211_TXPD_REQUEUE;
  574. dev_queue_xmit(skb);
  575. }
  576. while ((skb = skb_dequeue(&sta->ps_tx_buf)) != NULL) {
  577. pkt_data = (struct ieee80211_tx_packet_data *) skb->cb;
  578. local->total_ps_buffered--;
  579. sent++;
  580. #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
  581. printk(KERN_DEBUG "%s: STA %s aid %d send PS frame "
  582. "since STA not sleeping anymore\n", dev->name,
  583. print_mac(mac, sta->addr), sta->aid);
  584. #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
  585. pkt_data->flags |= IEEE80211_TXPD_REQUEUE;
  586. dev_queue_xmit(skb);
  587. }
  588. return sent;
  589. }
  590. static ieee80211_rx_result
  591. ieee80211_rx_h_sta_process(struct ieee80211_txrx_data *rx)
  592. {
  593. struct sta_info *sta = rx->sta;
  594. struct net_device *dev = rx->dev;
  595. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) rx->skb->data;
  596. if (!sta)
  597. return RX_CONTINUE;
  598. /* Update last_rx only for IBSS packets which are for the current
  599. * BSSID to avoid keeping the current IBSS network alive in cases where
  600. * other STAs are using different BSSID. */
  601. if (rx->sdata->vif.type == IEEE80211_IF_TYPE_IBSS) {
  602. u8 *bssid = ieee80211_get_bssid(hdr, rx->skb->len,
  603. IEEE80211_IF_TYPE_IBSS);
  604. if (compare_ether_addr(bssid, rx->sdata->u.sta.bssid) == 0)
  605. sta->last_rx = jiffies;
  606. } else
  607. if (!is_multicast_ether_addr(hdr->addr1) ||
  608. rx->sdata->vif.type == IEEE80211_IF_TYPE_STA) {
  609. /* Update last_rx only for unicast frames in order to prevent
  610. * the Probe Request frames (the only broadcast frames from a
  611. * STA in infrastructure mode) from keeping a connection alive.
  612. * Mesh beacons will update last_rx when if they are found to
  613. * match the current local configuration when processed.
  614. */
  615. sta->last_rx = jiffies;
  616. }
  617. if (!(rx->flags & IEEE80211_TXRXD_RXRA_MATCH))
  618. return RX_CONTINUE;
  619. sta->rx_fragments++;
  620. sta->rx_bytes += rx->skb->len;
  621. sta->last_rssi = rx->u.rx.status->ssi;
  622. sta->last_signal = rx->u.rx.status->signal;
  623. sta->last_noise = rx->u.rx.status->noise;
  624. if (!(rx->fc & IEEE80211_FCTL_MOREFRAGS)) {
  625. /* Change STA power saving mode only in the end of a frame
  626. * exchange sequence */
  627. if ((sta->flags & WLAN_STA_PS) && !(rx->fc & IEEE80211_FCTL_PM))
  628. rx->u.rx.sent_ps_buffered += ap_sta_ps_end(dev, sta);
  629. else if (!(sta->flags & WLAN_STA_PS) &&
  630. (rx->fc & IEEE80211_FCTL_PM))
  631. ap_sta_ps_start(dev, sta);
  632. }
  633. /* Drop data::nullfunc frames silently, since they are used only to
  634. * control station power saving mode. */
  635. if ((rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA &&
  636. (rx->fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_NULLFUNC) {
  637. I802_DEBUG_INC(rx->local->rx_handlers_drop_nullfunc);
  638. /* Update counter and free packet here to avoid counting this
  639. * as a dropped packed. */
  640. sta->rx_packets++;
  641. dev_kfree_skb(rx->skb);
  642. return RX_QUEUED;
  643. }
  644. return RX_CONTINUE;
  645. } /* ieee80211_rx_h_sta_process */
  646. static inline struct ieee80211_fragment_entry *
  647. ieee80211_reassemble_add(struct ieee80211_sub_if_data *sdata,
  648. unsigned int frag, unsigned int seq, int rx_queue,
  649. struct sk_buff **skb)
  650. {
  651. struct ieee80211_fragment_entry *entry;
  652. int idx;
  653. idx = sdata->fragment_next;
  654. entry = &sdata->fragments[sdata->fragment_next++];
  655. if (sdata->fragment_next >= IEEE80211_FRAGMENT_MAX)
  656. sdata->fragment_next = 0;
  657. if (!skb_queue_empty(&entry->skb_list)) {
  658. #ifdef CONFIG_MAC80211_DEBUG
  659. struct ieee80211_hdr *hdr =
  660. (struct ieee80211_hdr *) entry->skb_list.next->data;
  661. DECLARE_MAC_BUF(mac);
  662. DECLARE_MAC_BUF(mac2);
  663. printk(KERN_DEBUG "%s: RX reassembly removed oldest "
  664. "fragment entry (idx=%d age=%lu seq=%d last_frag=%d "
  665. "addr1=%s addr2=%s\n",
  666. sdata->dev->name, idx,
  667. jiffies - entry->first_frag_time, entry->seq,
  668. entry->last_frag, print_mac(mac, hdr->addr1),
  669. print_mac(mac2, hdr->addr2));
  670. #endif /* CONFIG_MAC80211_DEBUG */
  671. __skb_queue_purge(&entry->skb_list);
  672. }
  673. __skb_queue_tail(&entry->skb_list, *skb); /* no need for locking */
  674. *skb = NULL;
  675. entry->first_frag_time = jiffies;
  676. entry->seq = seq;
  677. entry->rx_queue = rx_queue;
  678. entry->last_frag = frag;
  679. entry->ccmp = 0;
  680. entry->extra_len = 0;
  681. return entry;
  682. }
  683. static inline struct ieee80211_fragment_entry *
  684. ieee80211_reassemble_find(struct ieee80211_sub_if_data *sdata,
  685. u16 fc, unsigned int frag, unsigned int seq,
  686. int rx_queue, struct ieee80211_hdr *hdr)
  687. {
  688. struct ieee80211_fragment_entry *entry;
  689. int i, idx;
  690. idx = sdata->fragment_next;
  691. for (i = 0; i < IEEE80211_FRAGMENT_MAX; i++) {
  692. struct ieee80211_hdr *f_hdr;
  693. u16 f_fc;
  694. idx--;
  695. if (idx < 0)
  696. idx = IEEE80211_FRAGMENT_MAX - 1;
  697. entry = &sdata->fragments[idx];
  698. if (skb_queue_empty(&entry->skb_list) || entry->seq != seq ||
  699. entry->rx_queue != rx_queue ||
  700. entry->last_frag + 1 != frag)
  701. continue;
  702. f_hdr = (struct ieee80211_hdr *) entry->skb_list.next->data;
  703. f_fc = le16_to_cpu(f_hdr->frame_control);
  704. if ((fc & IEEE80211_FCTL_FTYPE) != (f_fc & IEEE80211_FCTL_FTYPE) ||
  705. compare_ether_addr(hdr->addr1, f_hdr->addr1) != 0 ||
  706. compare_ether_addr(hdr->addr2, f_hdr->addr2) != 0)
  707. continue;
  708. if (time_after(jiffies, entry->first_frag_time + 2 * HZ)) {
  709. __skb_queue_purge(&entry->skb_list);
  710. continue;
  711. }
  712. return entry;
  713. }
  714. return NULL;
  715. }
  716. static ieee80211_rx_result
  717. ieee80211_rx_h_defragment(struct ieee80211_txrx_data *rx)
  718. {
  719. struct ieee80211_hdr *hdr;
  720. u16 sc;
  721. unsigned int frag, seq;
  722. struct ieee80211_fragment_entry *entry;
  723. struct sk_buff *skb;
  724. DECLARE_MAC_BUF(mac);
  725. hdr = (struct ieee80211_hdr *) rx->skb->data;
  726. sc = le16_to_cpu(hdr->seq_ctrl);
  727. frag = sc & IEEE80211_SCTL_FRAG;
  728. if (likely((!(rx->fc & IEEE80211_FCTL_MOREFRAGS) && frag == 0) ||
  729. (rx->skb)->len < 24 ||
  730. is_multicast_ether_addr(hdr->addr1))) {
  731. /* not fragmented */
  732. goto out;
  733. }
  734. I802_DEBUG_INC(rx->local->rx_handlers_fragments);
  735. seq = (sc & IEEE80211_SCTL_SEQ) >> 4;
  736. if (frag == 0) {
  737. /* This is the first fragment of a new frame. */
  738. entry = ieee80211_reassemble_add(rx->sdata, frag, seq,
  739. rx->u.rx.queue, &(rx->skb));
  740. if (rx->key && rx->key->conf.alg == ALG_CCMP &&
  741. (rx->fc & IEEE80211_FCTL_PROTECTED)) {
  742. /* Store CCMP PN so that we can verify that the next
  743. * fragment has a sequential PN value. */
  744. entry->ccmp = 1;
  745. memcpy(entry->last_pn,
  746. rx->key->u.ccmp.rx_pn[rx->u.rx.queue],
  747. CCMP_PN_LEN);
  748. }
  749. return RX_QUEUED;
  750. }
  751. /* This is a fragment for a frame that should already be pending in
  752. * fragment cache. Add this fragment to the end of the pending entry.
  753. */
  754. entry = ieee80211_reassemble_find(rx->sdata, rx->fc, frag, seq,
  755. rx->u.rx.queue, hdr);
  756. if (!entry) {
  757. I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag);
  758. return RX_DROP_MONITOR;
  759. }
  760. /* Verify that MPDUs within one MSDU have sequential PN values.
  761. * (IEEE 802.11i, 8.3.3.4.5) */
  762. if (entry->ccmp) {
  763. int i;
  764. u8 pn[CCMP_PN_LEN], *rpn;
  765. if (!rx->key || rx->key->conf.alg != ALG_CCMP)
  766. return RX_DROP_UNUSABLE;
  767. memcpy(pn, entry->last_pn, CCMP_PN_LEN);
  768. for (i = CCMP_PN_LEN - 1; i >= 0; i--) {
  769. pn[i]++;
  770. if (pn[i])
  771. break;
  772. }
  773. rpn = rx->key->u.ccmp.rx_pn[rx->u.rx.queue];
  774. if (memcmp(pn, rpn, CCMP_PN_LEN) != 0) {
  775. if (net_ratelimit())
  776. printk(KERN_DEBUG "%s: defrag: CCMP PN not "
  777. "sequential A2=%s"
  778. " PN=%02x%02x%02x%02x%02x%02x "
  779. "(expected %02x%02x%02x%02x%02x%02x)\n",
  780. rx->dev->name, print_mac(mac, hdr->addr2),
  781. rpn[0], rpn[1], rpn[2], rpn[3], rpn[4],
  782. rpn[5], pn[0], pn[1], pn[2], pn[3],
  783. pn[4], pn[5]);
  784. return RX_DROP_UNUSABLE;
  785. }
  786. memcpy(entry->last_pn, pn, CCMP_PN_LEN);
  787. }
  788. skb_pull(rx->skb, ieee80211_get_hdrlen(rx->fc));
  789. __skb_queue_tail(&entry->skb_list, rx->skb);
  790. entry->last_frag = frag;
  791. entry->extra_len += rx->skb->len;
  792. if (rx->fc & IEEE80211_FCTL_MOREFRAGS) {
  793. rx->skb = NULL;
  794. return RX_QUEUED;
  795. }
  796. rx->skb = __skb_dequeue(&entry->skb_list);
  797. if (skb_tailroom(rx->skb) < entry->extra_len) {
  798. I802_DEBUG_INC(rx->local->rx_expand_skb_head2);
  799. if (unlikely(pskb_expand_head(rx->skb, 0, entry->extra_len,
  800. GFP_ATOMIC))) {
  801. I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag);
  802. __skb_queue_purge(&entry->skb_list);
  803. return RX_DROP_UNUSABLE;
  804. }
  805. }
  806. while ((skb = __skb_dequeue(&entry->skb_list))) {
  807. memcpy(skb_put(rx->skb, skb->len), skb->data, skb->len);
  808. dev_kfree_skb(skb);
  809. }
  810. /* Complete frame has been reassembled - process it now */
  811. rx->flags |= IEEE80211_TXRXD_FRAGMENTED;
  812. out:
  813. if (rx->sta)
  814. rx->sta->rx_packets++;
  815. if (is_multicast_ether_addr(hdr->addr1))
  816. rx->local->dot11MulticastReceivedFrameCount++;
  817. else
  818. ieee80211_led_rx(rx->local);
  819. return RX_CONTINUE;
  820. }
  821. static ieee80211_rx_result
  822. ieee80211_rx_h_ps_poll(struct ieee80211_txrx_data *rx)
  823. {
  824. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(rx->dev);
  825. struct sk_buff *skb;
  826. int no_pending_pkts;
  827. DECLARE_MAC_BUF(mac);
  828. if (likely(!rx->sta ||
  829. (rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_CTL ||
  830. (rx->fc & IEEE80211_FCTL_STYPE) != IEEE80211_STYPE_PSPOLL ||
  831. !(rx->flags & IEEE80211_TXRXD_RXRA_MATCH)))
  832. return RX_CONTINUE;
  833. if ((sdata->vif.type != IEEE80211_IF_TYPE_AP) &&
  834. (sdata->vif.type != IEEE80211_IF_TYPE_VLAN))
  835. return RX_DROP_UNUSABLE;
  836. skb = skb_dequeue(&rx->sta->tx_filtered);
  837. if (!skb) {
  838. skb = skb_dequeue(&rx->sta->ps_tx_buf);
  839. if (skb)
  840. rx->local->total_ps_buffered--;
  841. }
  842. no_pending_pkts = skb_queue_empty(&rx->sta->tx_filtered) &&
  843. skb_queue_empty(&rx->sta->ps_tx_buf);
  844. if (skb) {
  845. struct ieee80211_hdr *hdr =
  846. (struct ieee80211_hdr *) skb->data;
  847. /*
  848. * Tell TX path to send one frame even though the STA may
  849. * still remain is PS mode after this frame exchange.
  850. */
  851. rx->sta->flags |= WLAN_STA_PSPOLL;
  852. #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
  853. printk(KERN_DEBUG "STA %s aid %d: PS Poll (entries after %d)\n",
  854. print_mac(mac, rx->sta->addr), rx->sta->aid,
  855. skb_queue_len(&rx->sta->ps_tx_buf));
  856. #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
  857. /* Use MoreData flag to indicate whether there are more
  858. * buffered frames for this STA */
  859. if (no_pending_pkts)
  860. hdr->frame_control &= cpu_to_le16(~IEEE80211_FCTL_MOREDATA);
  861. else
  862. hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_MOREDATA);
  863. dev_queue_xmit(skb);
  864. if (no_pending_pkts)
  865. sta_info_clear_tim_bit(rx->sta);
  866. #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
  867. } else if (!rx->u.rx.sent_ps_buffered) {
  868. /*
  869. * FIXME: This can be the result of a race condition between
  870. * us expiring a frame and the station polling for it.
  871. * Should we send it a null-func frame indicating we
  872. * have nothing buffered for it?
  873. */
  874. printk(KERN_DEBUG "%s: STA %s sent PS Poll even "
  875. "though there is no buffered frames for it\n",
  876. rx->dev->name, print_mac(mac, rx->sta->addr));
  877. #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
  878. }
  879. /* Free PS Poll skb here instead of returning RX_DROP that would
  880. * count as an dropped frame. */
  881. dev_kfree_skb(rx->skb);
  882. return RX_QUEUED;
  883. }
  884. static ieee80211_rx_result
  885. ieee80211_rx_h_remove_qos_control(struct ieee80211_txrx_data *rx)
  886. {
  887. u16 fc = rx->fc;
  888. u8 *data = rx->skb->data;
  889. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) data;
  890. if (!WLAN_FC_IS_QOS_DATA(fc))
  891. return RX_CONTINUE;
  892. /* remove the qos control field, update frame type and meta-data */
  893. memmove(data + 2, data, ieee80211_get_hdrlen(fc) - 2);
  894. hdr = (struct ieee80211_hdr *) skb_pull(rx->skb, 2);
  895. /* change frame type to non QOS */
  896. rx->fc = fc &= ~IEEE80211_STYPE_QOS_DATA;
  897. hdr->frame_control = cpu_to_le16(fc);
  898. return RX_CONTINUE;
  899. }
  900. static int
  901. ieee80211_802_1x_port_control(struct ieee80211_txrx_data *rx)
  902. {
  903. if (unlikely(!rx->sta || !(rx->sta->flags & WLAN_STA_AUTHORIZED))) {
  904. #ifdef CONFIG_MAC80211_DEBUG
  905. if (net_ratelimit())
  906. printk(KERN_DEBUG "%s: dropped frame "
  907. "(unauthorized port)\n", rx->dev->name);
  908. #endif /* CONFIG_MAC80211_DEBUG */
  909. return -EACCES;
  910. }
  911. return 0;
  912. }
  913. static int
  914. ieee80211_drop_unencrypted(struct ieee80211_txrx_data *rx)
  915. {
  916. /*
  917. * Pass through unencrypted frames if the hardware has
  918. * decrypted them already.
  919. */
  920. if (rx->u.rx.status->flag & RX_FLAG_DECRYPTED)
  921. return 0;
  922. /* Drop unencrypted frames if key is set. */
  923. if (unlikely(!(rx->fc & IEEE80211_FCTL_PROTECTED) &&
  924. (rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA &&
  925. (rx->fc & IEEE80211_FCTL_STYPE) != IEEE80211_STYPE_NULLFUNC &&
  926. (rx->key || rx->sdata->drop_unencrypted))) {
  927. if (net_ratelimit())
  928. printk(KERN_DEBUG "%s: RX non-WEP frame, but expected "
  929. "encryption\n", rx->dev->name);
  930. return -EACCES;
  931. }
  932. return 0;
  933. }
  934. static int
  935. ieee80211_data_to_8023(struct ieee80211_txrx_data *rx)
  936. {
  937. struct net_device *dev = rx->dev;
  938. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) rx->skb->data;
  939. u16 fc, hdrlen, ethertype;
  940. u8 *payload;
  941. u8 dst[ETH_ALEN];
  942. u8 src[ETH_ALEN];
  943. struct sk_buff *skb = rx->skb;
  944. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  945. DECLARE_MAC_BUF(mac);
  946. DECLARE_MAC_BUF(mac2);
  947. DECLARE_MAC_BUF(mac3);
  948. DECLARE_MAC_BUF(mac4);
  949. fc = rx->fc;
  950. if (unlikely(!WLAN_FC_DATA_PRESENT(fc)))
  951. return -1;
  952. hdrlen = ieee80211_get_hdrlen(fc);
  953. if (ieee80211_vif_is_mesh(&sdata->vif)) {
  954. int meshhdrlen = ieee80211_get_mesh_hdrlen(
  955. (struct ieee80211s_hdr *) (skb->data + hdrlen));
  956. /* Copy on cb:
  957. * - mesh header: to be used for mesh forwarding
  958. * decision. It will also be used as mesh header template at
  959. * tx.c:ieee80211_subif_start_xmit() if interface
  960. * type is mesh and skb->pkt_type == PACKET_OTHERHOST
  961. * - ta: to be used if a RERR needs to be sent.
  962. */
  963. memcpy(skb->cb, skb->data + hdrlen, meshhdrlen);
  964. memcpy(MESH_PREQ(skb), hdr->addr2, ETH_ALEN);
  965. hdrlen += meshhdrlen;
  966. }
  967. /* convert IEEE 802.11 header + possible LLC headers into Ethernet
  968. * header
  969. * IEEE 802.11 address fields:
  970. * ToDS FromDS Addr1 Addr2 Addr3 Addr4
  971. * 0 0 DA SA BSSID n/a
  972. * 0 1 DA BSSID SA n/a
  973. * 1 0 BSSID SA DA n/a
  974. * 1 1 RA TA DA SA
  975. */
  976. switch (fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) {
  977. case IEEE80211_FCTL_TODS:
  978. /* BSSID SA DA */
  979. memcpy(dst, hdr->addr3, ETH_ALEN);
  980. memcpy(src, hdr->addr2, ETH_ALEN);
  981. if (unlikely(sdata->vif.type != IEEE80211_IF_TYPE_AP &&
  982. sdata->vif.type != IEEE80211_IF_TYPE_VLAN)) {
  983. if (net_ratelimit())
  984. printk(KERN_DEBUG "%s: dropped ToDS frame "
  985. "(BSSID=%s SA=%s DA=%s)\n",
  986. dev->name,
  987. print_mac(mac, hdr->addr1),
  988. print_mac(mac2, hdr->addr2),
  989. print_mac(mac3, hdr->addr3));
  990. return -1;
  991. }
  992. break;
  993. case (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS):
  994. /* RA TA DA SA */
  995. memcpy(dst, hdr->addr3, ETH_ALEN);
  996. memcpy(src, hdr->addr4, ETH_ALEN);
  997. if (unlikely(sdata->vif.type != IEEE80211_IF_TYPE_WDS &&
  998. sdata->vif.type != IEEE80211_IF_TYPE_MESH_POINT)) {
  999. if (net_ratelimit())
  1000. printk(KERN_DEBUG "%s: dropped FromDS&ToDS "
  1001. "frame (RA=%s TA=%s DA=%s SA=%s)\n",
  1002. rx->dev->name,
  1003. print_mac(mac, hdr->addr1),
  1004. print_mac(mac2, hdr->addr2),
  1005. print_mac(mac3, hdr->addr3),
  1006. print_mac(mac4, hdr->addr4));
  1007. return -1;
  1008. }
  1009. break;
  1010. case IEEE80211_FCTL_FROMDS:
  1011. /* DA BSSID SA */
  1012. memcpy(dst, hdr->addr1, ETH_ALEN);
  1013. memcpy(src, hdr->addr3, ETH_ALEN);
  1014. if (sdata->vif.type != IEEE80211_IF_TYPE_STA ||
  1015. (is_multicast_ether_addr(dst) &&
  1016. !compare_ether_addr(src, dev->dev_addr)))
  1017. return -1;
  1018. break;
  1019. case 0:
  1020. /* DA SA BSSID */
  1021. memcpy(dst, hdr->addr1, ETH_ALEN);
  1022. memcpy(src, hdr->addr2, ETH_ALEN);
  1023. if (sdata->vif.type != IEEE80211_IF_TYPE_IBSS) {
  1024. if (net_ratelimit()) {
  1025. printk(KERN_DEBUG "%s: dropped IBSS frame "
  1026. "(DA=%s SA=%s BSSID=%s)\n",
  1027. dev->name,
  1028. print_mac(mac, hdr->addr1),
  1029. print_mac(mac2, hdr->addr2),
  1030. print_mac(mac3, hdr->addr3));
  1031. }
  1032. return -1;
  1033. }
  1034. break;
  1035. }
  1036. if (unlikely(skb->len - hdrlen < 8)) {
  1037. if (net_ratelimit()) {
  1038. printk(KERN_DEBUG "%s: RX too short data frame "
  1039. "payload\n", dev->name);
  1040. }
  1041. return -1;
  1042. }
  1043. payload = skb->data + hdrlen;
  1044. ethertype = (payload[6] << 8) | payload[7];
  1045. if (likely((compare_ether_addr(payload, rfc1042_header) == 0 &&
  1046. ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) ||
  1047. compare_ether_addr(payload, bridge_tunnel_header) == 0)) {
  1048. /* remove RFC1042 or Bridge-Tunnel encapsulation and
  1049. * replace EtherType */
  1050. skb_pull(skb, hdrlen + 6);
  1051. memcpy(skb_push(skb, ETH_ALEN), src, ETH_ALEN);
  1052. memcpy(skb_push(skb, ETH_ALEN), dst, ETH_ALEN);
  1053. } else {
  1054. struct ethhdr *ehdr;
  1055. __be16 len;
  1056. skb_pull(skb, hdrlen);
  1057. len = htons(skb->len);
  1058. ehdr = (struct ethhdr *) skb_push(skb, sizeof(struct ethhdr));
  1059. memcpy(ehdr->h_dest, dst, ETH_ALEN);
  1060. memcpy(ehdr->h_source, src, ETH_ALEN);
  1061. ehdr->h_proto = len;
  1062. }
  1063. return 0;
  1064. }
  1065. /*
  1066. * requires that rx->skb is a frame with ethernet header
  1067. */
  1068. static bool ieee80211_frame_allowed(struct ieee80211_txrx_data *rx)
  1069. {
  1070. static const u8 pae_group_addr[ETH_ALEN]
  1071. = { 0x01, 0x80, 0xC2, 0x00, 0x00, 0x03 };
  1072. struct ethhdr *ehdr = (struct ethhdr *) rx->skb->data;
  1073. /*
  1074. * Allow EAPOL frames to us/the PAE group address regardless
  1075. * of whether the frame was encrypted or not.
  1076. */
  1077. if (ehdr->h_proto == htons(ETH_P_PAE) &&
  1078. (compare_ether_addr(ehdr->h_dest, rx->dev->dev_addr) == 0 ||
  1079. compare_ether_addr(ehdr->h_dest, pae_group_addr) == 0))
  1080. return true;
  1081. if (ieee80211_802_1x_port_control(rx) ||
  1082. ieee80211_drop_unencrypted(rx))
  1083. return false;
  1084. return true;
  1085. }
  1086. /*
  1087. * requires that rx->skb is a frame with ethernet header
  1088. */
  1089. static void
  1090. ieee80211_deliver_skb(struct ieee80211_txrx_data *rx)
  1091. {
  1092. struct net_device *dev = rx->dev;
  1093. struct ieee80211_local *local = rx->local;
  1094. struct sk_buff *skb, *xmit_skb;
  1095. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1096. struct ethhdr *ehdr = (struct ethhdr *) rx->skb->data;
  1097. struct sta_info *dsta;
  1098. skb = rx->skb;
  1099. xmit_skb = NULL;
  1100. if (local->bridge_packets && (sdata->vif.type == IEEE80211_IF_TYPE_AP ||
  1101. sdata->vif.type == IEEE80211_IF_TYPE_VLAN) &&
  1102. (rx->flags & IEEE80211_TXRXD_RXRA_MATCH)) {
  1103. if (is_multicast_ether_addr(ehdr->h_dest)) {
  1104. /*
  1105. * send multicast frames both to higher layers in
  1106. * local net stack and back to the wireless medium
  1107. */
  1108. xmit_skb = skb_copy(skb, GFP_ATOMIC);
  1109. if (!xmit_skb && net_ratelimit())
  1110. printk(KERN_DEBUG "%s: failed to clone "
  1111. "multicast frame\n", dev->name);
  1112. } else {
  1113. dsta = sta_info_get(local, skb->data);
  1114. if (dsta && dsta->dev == dev) {
  1115. /*
  1116. * The destination station is associated to
  1117. * this AP (in this VLAN), so send the frame
  1118. * directly to it and do not pass it to local
  1119. * net stack.
  1120. */
  1121. xmit_skb = skb;
  1122. skb = NULL;
  1123. }
  1124. if (dsta)
  1125. sta_info_put(dsta);
  1126. }
  1127. }
  1128. /* Mesh forwarding */
  1129. if (ieee80211_vif_is_mesh(&sdata->vif)) {
  1130. u8 *mesh_ttl = &((struct ieee80211s_hdr *)skb->cb)->ttl;
  1131. (*mesh_ttl)--;
  1132. if (is_multicast_ether_addr(skb->data)) {
  1133. if (*mesh_ttl > 0) {
  1134. xmit_skb = skb_copy(skb, GFP_ATOMIC);
  1135. if (!xmit_skb && net_ratelimit())
  1136. printk(KERN_DEBUG "%s: failed to clone "
  1137. "multicast frame\n", dev->name);
  1138. else
  1139. xmit_skb->pkt_type = PACKET_OTHERHOST;
  1140. } else
  1141. IEEE80211_IFSTA_MESH_CTR_INC(&sdata->u.sta,
  1142. dropped_frames_ttl);
  1143. } else if (skb->pkt_type != PACKET_OTHERHOST &&
  1144. compare_ether_addr(dev->dev_addr, skb->data) != 0) {
  1145. if (*mesh_ttl == 0) {
  1146. IEEE80211_IFSTA_MESH_CTR_INC(&sdata->u.sta,
  1147. dropped_frames_ttl);
  1148. dev_kfree_skb(skb);
  1149. skb = NULL;
  1150. } else {
  1151. xmit_skb = skb;
  1152. xmit_skb->pkt_type = PACKET_OTHERHOST;
  1153. if (!(dev->flags & IFF_PROMISC))
  1154. skb = NULL;
  1155. }
  1156. }
  1157. }
  1158. if (skb) {
  1159. /* deliver to local stack */
  1160. skb->protocol = eth_type_trans(skb, dev);
  1161. memset(skb->cb, 0, sizeof(skb->cb));
  1162. netif_rx(skb);
  1163. }
  1164. if (xmit_skb) {
  1165. /* send to wireless media */
  1166. xmit_skb->protocol = htons(ETH_P_802_3);
  1167. skb_reset_network_header(xmit_skb);
  1168. skb_reset_mac_header(xmit_skb);
  1169. dev_queue_xmit(xmit_skb);
  1170. }
  1171. }
  1172. static ieee80211_rx_result
  1173. ieee80211_rx_h_amsdu(struct ieee80211_txrx_data *rx)
  1174. {
  1175. struct net_device *dev = rx->dev;
  1176. struct ieee80211_local *local = rx->local;
  1177. u16 fc, ethertype;
  1178. u8 *payload;
  1179. struct sk_buff *skb = rx->skb, *frame = NULL;
  1180. const struct ethhdr *eth;
  1181. int remaining, err;
  1182. u8 dst[ETH_ALEN];
  1183. u8 src[ETH_ALEN];
  1184. DECLARE_MAC_BUF(mac);
  1185. fc = rx->fc;
  1186. if (unlikely((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA))
  1187. return RX_CONTINUE;
  1188. if (unlikely(!WLAN_FC_DATA_PRESENT(fc)))
  1189. return RX_DROP_MONITOR;
  1190. if (!(rx->flags & IEEE80211_TXRXD_RX_AMSDU))
  1191. return RX_CONTINUE;
  1192. err = ieee80211_data_to_8023(rx);
  1193. if (unlikely(err))
  1194. return RX_DROP_UNUSABLE;
  1195. skb->dev = dev;
  1196. dev->stats.rx_packets++;
  1197. dev->stats.rx_bytes += skb->len;
  1198. /* skip the wrapping header */
  1199. eth = (struct ethhdr *) skb_pull(skb, sizeof(struct ethhdr));
  1200. if (!eth)
  1201. return RX_DROP_UNUSABLE;
  1202. while (skb != frame) {
  1203. u8 padding;
  1204. __be16 len = eth->h_proto;
  1205. unsigned int subframe_len = sizeof(struct ethhdr) + ntohs(len);
  1206. remaining = skb->len;
  1207. memcpy(dst, eth->h_dest, ETH_ALEN);
  1208. memcpy(src, eth->h_source, ETH_ALEN);
  1209. padding = ((4 - subframe_len) & 0x3);
  1210. /* the last MSDU has no padding */
  1211. if (subframe_len > remaining) {
  1212. printk(KERN_DEBUG "%s: wrong buffer size", dev->name);
  1213. return RX_DROP_UNUSABLE;
  1214. }
  1215. skb_pull(skb, sizeof(struct ethhdr));
  1216. /* if last subframe reuse skb */
  1217. if (remaining <= subframe_len + padding)
  1218. frame = skb;
  1219. else {
  1220. frame = dev_alloc_skb(local->hw.extra_tx_headroom +
  1221. subframe_len);
  1222. if (frame == NULL)
  1223. return RX_DROP_UNUSABLE;
  1224. skb_reserve(frame, local->hw.extra_tx_headroom +
  1225. sizeof(struct ethhdr));
  1226. memcpy(skb_put(frame, ntohs(len)), skb->data,
  1227. ntohs(len));
  1228. eth = (struct ethhdr *) skb_pull(skb, ntohs(len) +
  1229. padding);
  1230. if (!eth) {
  1231. printk(KERN_DEBUG "%s: wrong buffer size ",
  1232. dev->name);
  1233. dev_kfree_skb(frame);
  1234. return RX_DROP_UNUSABLE;
  1235. }
  1236. }
  1237. skb_reset_network_header(frame);
  1238. frame->dev = dev;
  1239. frame->priority = skb->priority;
  1240. rx->skb = frame;
  1241. payload = frame->data;
  1242. ethertype = (payload[6] << 8) | payload[7];
  1243. if (likely((compare_ether_addr(payload, rfc1042_header) == 0 &&
  1244. ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) ||
  1245. compare_ether_addr(payload,
  1246. bridge_tunnel_header) == 0)) {
  1247. /* remove RFC1042 or Bridge-Tunnel
  1248. * encapsulation and replace EtherType */
  1249. skb_pull(frame, 6);
  1250. memcpy(skb_push(frame, ETH_ALEN), src, ETH_ALEN);
  1251. memcpy(skb_push(frame, ETH_ALEN), dst, ETH_ALEN);
  1252. } else {
  1253. memcpy(skb_push(frame, sizeof(__be16)),
  1254. &len, sizeof(__be16));
  1255. memcpy(skb_push(frame, ETH_ALEN), src, ETH_ALEN);
  1256. memcpy(skb_push(frame, ETH_ALEN), dst, ETH_ALEN);
  1257. }
  1258. if (!ieee80211_frame_allowed(rx)) {
  1259. if (skb == frame) /* last frame */
  1260. return RX_DROP_UNUSABLE;
  1261. dev_kfree_skb(frame);
  1262. continue;
  1263. }
  1264. ieee80211_deliver_skb(rx);
  1265. }
  1266. return RX_QUEUED;
  1267. }
  1268. static ieee80211_rx_result
  1269. ieee80211_rx_h_data(struct ieee80211_txrx_data *rx)
  1270. {
  1271. struct net_device *dev = rx->dev;
  1272. u16 fc;
  1273. int err;
  1274. fc = rx->fc;
  1275. if (unlikely((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA))
  1276. return RX_CONTINUE;
  1277. if (unlikely(!WLAN_FC_DATA_PRESENT(fc)))
  1278. return RX_DROP_MONITOR;
  1279. err = ieee80211_data_to_8023(rx);
  1280. if (unlikely(err))
  1281. return RX_DROP_UNUSABLE;
  1282. if (!ieee80211_frame_allowed(rx))
  1283. return RX_DROP_MONITOR;
  1284. rx->skb->dev = dev;
  1285. dev->stats.rx_packets++;
  1286. dev->stats.rx_bytes += rx->skb->len;
  1287. ieee80211_deliver_skb(rx);
  1288. return RX_QUEUED;
  1289. }
  1290. static ieee80211_rx_result
  1291. ieee80211_rx_h_ctrl(struct ieee80211_txrx_data *rx)
  1292. {
  1293. struct ieee80211_local *local = rx->local;
  1294. struct ieee80211_hw *hw = &local->hw;
  1295. struct sk_buff *skb = rx->skb;
  1296. struct ieee80211_bar *bar = (struct ieee80211_bar *) skb->data;
  1297. struct tid_ampdu_rx *tid_agg_rx;
  1298. u16 start_seq_num;
  1299. u16 tid;
  1300. if (likely((rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_CTL))
  1301. return RX_CONTINUE;
  1302. if ((rx->fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_BACK_REQ) {
  1303. if (!rx->sta)
  1304. return RX_CONTINUE;
  1305. tid = le16_to_cpu(bar->control) >> 12;
  1306. tid_agg_rx = &(rx->sta->ampdu_mlme.tid_rx[tid]);
  1307. if (tid_agg_rx->state != HT_AGG_STATE_OPERATIONAL)
  1308. return RX_CONTINUE;
  1309. start_seq_num = le16_to_cpu(bar->start_seq_num) >> 4;
  1310. /* reset session timer */
  1311. if (tid_agg_rx->timeout) {
  1312. unsigned long expires =
  1313. jiffies + (tid_agg_rx->timeout / 1000) * HZ;
  1314. mod_timer(&tid_agg_rx->session_timer, expires);
  1315. }
  1316. /* manage reordering buffer according to requested */
  1317. /* sequence number */
  1318. rcu_read_lock();
  1319. ieee80211_sta_manage_reorder_buf(hw, tid_agg_rx, NULL,
  1320. start_seq_num, 1);
  1321. rcu_read_unlock();
  1322. return RX_DROP_UNUSABLE;
  1323. }
  1324. return RX_CONTINUE;
  1325. }
  1326. static ieee80211_rx_result
  1327. ieee80211_rx_h_mgmt(struct ieee80211_txrx_data *rx)
  1328. {
  1329. struct ieee80211_sub_if_data *sdata;
  1330. if (!(rx->flags & IEEE80211_TXRXD_RXRA_MATCH))
  1331. return RX_DROP_MONITOR;
  1332. sdata = IEEE80211_DEV_TO_SUB_IF(rx->dev);
  1333. if ((sdata->vif.type == IEEE80211_IF_TYPE_STA ||
  1334. sdata->vif.type == IEEE80211_IF_TYPE_IBSS ||
  1335. sdata->vif.type == IEEE80211_IF_TYPE_MESH_POINT) &&
  1336. !(sdata->flags & IEEE80211_SDATA_USERSPACE_MLME))
  1337. ieee80211_sta_rx_mgmt(rx->dev, rx->skb, rx->u.rx.status);
  1338. else
  1339. return RX_DROP_MONITOR;
  1340. return RX_QUEUED;
  1341. }
  1342. static void ieee80211_rx_michael_mic_report(struct net_device *dev,
  1343. struct ieee80211_hdr *hdr,
  1344. struct ieee80211_txrx_data *rx)
  1345. {
  1346. int keyidx, hdrlen;
  1347. DECLARE_MAC_BUF(mac);
  1348. DECLARE_MAC_BUF(mac2);
  1349. hdrlen = ieee80211_get_hdrlen_from_skb(rx->skb);
  1350. if (rx->skb->len >= hdrlen + 4)
  1351. keyidx = rx->skb->data[hdrlen + 3] >> 6;
  1352. else
  1353. keyidx = -1;
  1354. if (net_ratelimit())
  1355. printk(KERN_DEBUG "%s: TKIP hwaccel reported Michael MIC "
  1356. "failure from %s to %s keyidx=%d\n",
  1357. dev->name, print_mac(mac, hdr->addr2),
  1358. print_mac(mac2, hdr->addr1), keyidx);
  1359. if (!rx->sta) {
  1360. /*
  1361. * Some hardware seem to generate incorrect Michael MIC
  1362. * reports; ignore them to avoid triggering countermeasures.
  1363. */
  1364. if (net_ratelimit())
  1365. printk(KERN_DEBUG "%s: ignored spurious Michael MIC "
  1366. "error for unknown address %s\n",
  1367. dev->name, print_mac(mac, hdr->addr2));
  1368. goto ignore;
  1369. }
  1370. if (!(rx->fc & IEEE80211_FCTL_PROTECTED)) {
  1371. if (net_ratelimit())
  1372. printk(KERN_DEBUG "%s: ignored spurious Michael MIC "
  1373. "error for a frame with no PROTECTED flag (src "
  1374. "%s)\n", dev->name, print_mac(mac, hdr->addr2));
  1375. goto ignore;
  1376. }
  1377. if (rx->sdata->vif.type == IEEE80211_IF_TYPE_AP && keyidx) {
  1378. /*
  1379. * APs with pairwise keys should never receive Michael MIC
  1380. * errors for non-zero keyidx because these are reserved for
  1381. * group keys and only the AP is sending real multicast
  1382. * frames in the BSS.
  1383. */
  1384. if (net_ratelimit())
  1385. printk(KERN_DEBUG "%s: ignored Michael MIC error for "
  1386. "a frame with non-zero keyidx (%d)"
  1387. " (src %s)\n", dev->name, keyidx,
  1388. print_mac(mac, hdr->addr2));
  1389. goto ignore;
  1390. }
  1391. if ((rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA &&
  1392. ((rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_MGMT ||
  1393. (rx->fc & IEEE80211_FCTL_STYPE) != IEEE80211_STYPE_AUTH)) {
  1394. if (net_ratelimit())
  1395. printk(KERN_DEBUG "%s: ignored spurious Michael MIC "
  1396. "error for a frame that cannot be encrypted "
  1397. "(fc=0x%04x) (src %s)\n",
  1398. dev->name, rx->fc, print_mac(mac, hdr->addr2));
  1399. goto ignore;
  1400. }
  1401. mac80211_ev_michael_mic_failure(rx->dev, keyidx, hdr);
  1402. ignore:
  1403. dev_kfree_skb(rx->skb);
  1404. rx->skb = NULL;
  1405. }
  1406. static void ieee80211_rx_cooked_monitor(struct ieee80211_txrx_data *rx)
  1407. {
  1408. struct ieee80211_sub_if_data *sdata;
  1409. struct ieee80211_local *local = rx->local;
  1410. struct ieee80211_rtap_hdr {
  1411. struct ieee80211_radiotap_header hdr;
  1412. u8 flags;
  1413. u8 rate;
  1414. __le16 chan_freq;
  1415. __le16 chan_flags;
  1416. } __attribute__ ((packed)) *rthdr;
  1417. struct sk_buff *skb = rx->skb, *skb2;
  1418. struct net_device *prev_dev = NULL;
  1419. struct ieee80211_rx_status *status = rx->u.rx.status;
  1420. if (rx->flags & IEEE80211_TXRXD_RX_CMNTR_REPORTED)
  1421. goto out_free_skb;
  1422. if (skb_headroom(skb) < sizeof(*rthdr) &&
  1423. pskb_expand_head(skb, sizeof(*rthdr), 0, GFP_ATOMIC))
  1424. goto out_free_skb;
  1425. rthdr = (void *)skb_push(skb, sizeof(*rthdr));
  1426. memset(rthdr, 0, sizeof(*rthdr));
  1427. rthdr->hdr.it_len = cpu_to_le16(sizeof(*rthdr));
  1428. rthdr->hdr.it_present =
  1429. cpu_to_le32((1 << IEEE80211_RADIOTAP_FLAGS) |
  1430. (1 << IEEE80211_RADIOTAP_RATE) |
  1431. (1 << IEEE80211_RADIOTAP_CHANNEL));
  1432. rthdr->rate = rx->u.rx.rate->bitrate / 5;
  1433. rthdr->chan_freq = cpu_to_le16(status->freq);
  1434. if (status->band == IEEE80211_BAND_5GHZ)
  1435. rthdr->chan_flags = cpu_to_le16(IEEE80211_CHAN_OFDM |
  1436. IEEE80211_CHAN_5GHZ);
  1437. else
  1438. rthdr->chan_flags = cpu_to_le16(IEEE80211_CHAN_DYN |
  1439. IEEE80211_CHAN_2GHZ);
  1440. skb_set_mac_header(skb, 0);
  1441. skb->ip_summed = CHECKSUM_UNNECESSARY;
  1442. skb->pkt_type = PACKET_OTHERHOST;
  1443. skb->protocol = htons(ETH_P_802_2);
  1444. list_for_each_entry_rcu(sdata, &local->interfaces, list) {
  1445. if (!netif_running(sdata->dev))
  1446. continue;
  1447. if (sdata->vif.type != IEEE80211_IF_TYPE_MNTR ||
  1448. !(sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES))
  1449. continue;
  1450. if (prev_dev) {
  1451. skb2 = skb_clone(skb, GFP_ATOMIC);
  1452. if (skb2) {
  1453. skb2->dev = prev_dev;
  1454. netif_rx(skb2);
  1455. }
  1456. }
  1457. prev_dev = sdata->dev;
  1458. sdata->dev->stats.rx_packets++;
  1459. sdata->dev->stats.rx_bytes += skb->len;
  1460. }
  1461. if (prev_dev) {
  1462. skb->dev = prev_dev;
  1463. netif_rx(skb);
  1464. skb = NULL;
  1465. } else
  1466. goto out_free_skb;
  1467. rx->flags |= IEEE80211_TXRXD_RX_CMNTR_REPORTED;
  1468. return;
  1469. out_free_skb:
  1470. dev_kfree_skb(skb);
  1471. }
  1472. typedef ieee80211_rx_result (*ieee80211_rx_handler)(struct ieee80211_txrx_data *);
  1473. static ieee80211_rx_handler ieee80211_rx_handlers[] =
  1474. {
  1475. ieee80211_rx_h_if_stats,
  1476. ieee80211_rx_h_passive_scan,
  1477. ieee80211_rx_h_check,
  1478. ieee80211_rx_h_decrypt,
  1479. ieee80211_rx_h_sta_process,
  1480. ieee80211_rx_h_defragment,
  1481. ieee80211_rx_h_ps_poll,
  1482. ieee80211_rx_h_michael_mic_verify,
  1483. /* this must be after decryption - so header is counted in MPDU mic
  1484. * must be before pae and data, so QOS_DATA format frames
  1485. * are not passed to user space by these functions
  1486. */
  1487. ieee80211_rx_h_remove_qos_control,
  1488. ieee80211_rx_h_amsdu,
  1489. ieee80211_rx_h_data,
  1490. ieee80211_rx_h_ctrl,
  1491. ieee80211_rx_h_mgmt,
  1492. NULL
  1493. };
  1494. static void ieee80211_invoke_rx_handlers(struct ieee80211_sub_if_data *sdata,
  1495. struct ieee80211_txrx_data *rx,
  1496. struct sk_buff *skb)
  1497. {
  1498. ieee80211_rx_handler *handler;
  1499. ieee80211_rx_result res = RX_DROP_MONITOR;
  1500. rx->skb = skb;
  1501. rx->sdata = sdata;
  1502. rx->dev = sdata->dev;
  1503. for (handler = ieee80211_rx_handlers; *handler != NULL; handler++) {
  1504. res = (*handler)(rx);
  1505. switch (res) {
  1506. case RX_CONTINUE:
  1507. continue;
  1508. case RX_DROP_UNUSABLE:
  1509. case RX_DROP_MONITOR:
  1510. I802_DEBUG_INC(sdata->local->rx_handlers_drop);
  1511. if (rx->sta)
  1512. rx->sta->rx_dropped++;
  1513. break;
  1514. case RX_QUEUED:
  1515. I802_DEBUG_INC(sdata->local->rx_handlers_queued);
  1516. break;
  1517. }
  1518. break;
  1519. }
  1520. switch (res) {
  1521. case RX_CONTINUE:
  1522. case RX_DROP_MONITOR:
  1523. ieee80211_rx_cooked_monitor(rx);
  1524. break;
  1525. case RX_DROP_UNUSABLE:
  1526. dev_kfree_skb(rx->skb);
  1527. break;
  1528. }
  1529. }
  1530. /* main receive path */
  1531. static int prepare_for_handlers(struct ieee80211_sub_if_data *sdata,
  1532. u8 *bssid, struct ieee80211_txrx_data *rx,
  1533. struct ieee80211_hdr *hdr)
  1534. {
  1535. int multicast = is_multicast_ether_addr(hdr->addr1);
  1536. switch (sdata->vif.type) {
  1537. case IEEE80211_IF_TYPE_STA:
  1538. if (!bssid)
  1539. return 0;
  1540. if (!ieee80211_bssid_match(bssid, sdata->u.sta.bssid)) {
  1541. if (!(rx->flags & IEEE80211_TXRXD_RXIN_SCAN))
  1542. return 0;
  1543. rx->flags &= ~IEEE80211_TXRXD_RXRA_MATCH;
  1544. } else if (!multicast &&
  1545. compare_ether_addr(sdata->dev->dev_addr,
  1546. hdr->addr1) != 0) {
  1547. if (!(sdata->dev->flags & IFF_PROMISC))
  1548. return 0;
  1549. rx->flags &= ~IEEE80211_TXRXD_RXRA_MATCH;
  1550. }
  1551. break;
  1552. case IEEE80211_IF_TYPE_IBSS:
  1553. if (!bssid)
  1554. return 0;
  1555. if ((rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT &&
  1556. (rx->fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_BEACON)
  1557. return 1;
  1558. else if (!ieee80211_bssid_match(bssid, sdata->u.sta.bssid)) {
  1559. if (!(rx->flags & IEEE80211_TXRXD_RXIN_SCAN))
  1560. return 0;
  1561. rx->flags &= ~IEEE80211_TXRXD_RXRA_MATCH;
  1562. } else if (!multicast &&
  1563. compare_ether_addr(sdata->dev->dev_addr,
  1564. hdr->addr1) != 0) {
  1565. if (!(sdata->dev->flags & IFF_PROMISC))
  1566. return 0;
  1567. rx->flags &= ~IEEE80211_TXRXD_RXRA_MATCH;
  1568. } else if (!rx->sta)
  1569. rx->sta = ieee80211_ibss_add_sta(sdata->dev, rx->skb,
  1570. bssid, hdr->addr2);
  1571. break;
  1572. case IEEE80211_IF_TYPE_MESH_POINT:
  1573. if (!multicast &&
  1574. compare_ether_addr(sdata->dev->dev_addr,
  1575. hdr->addr1) != 0) {
  1576. if (!(sdata->dev->flags & IFF_PROMISC))
  1577. return 0;
  1578. rx->flags &= ~IEEE80211_TXRXD_RXRA_MATCH;
  1579. }
  1580. break;
  1581. case IEEE80211_IF_TYPE_VLAN:
  1582. case IEEE80211_IF_TYPE_AP:
  1583. if (!bssid) {
  1584. if (compare_ether_addr(sdata->dev->dev_addr,
  1585. hdr->addr1))
  1586. return 0;
  1587. } else if (!ieee80211_bssid_match(bssid,
  1588. sdata->dev->dev_addr)) {
  1589. if (!(rx->flags & IEEE80211_TXRXD_RXIN_SCAN))
  1590. return 0;
  1591. rx->flags &= ~IEEE80211_TXRXD_RXRA_MATCH;
  1592. }
  1593. if (sdata->dev == sdata->local->mdev &&
  1594. !(rx->flags & IEEE80211_TXRXD_RXIN_SCAN))
  1595. /* do not receive anything via
  1596. * master device when not scanning */
  1597. return 0;
  1598. break;
  1599. case IEEE80211_IF_TYPE_WDS:
  1600. if (bssid ||
  1601. (rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA)
  1602. return 0;
  1603. if (compare_ether_addr(sdata->u.wds.remote_addr, hdr->addr2))
  1604. return 0;
  1605. break;
  1606. case IEEE80211_IF_TYPE_MNTR:
  1607. /* take everything */
  1608. break;
  1609. case IEEE80211_IF_TYPE_INVALID:
  1610. /* should never get here */
  1611. WARN_ON(1);
  1612. break;
  1613. }
  1614. return 1;
  1615. }
  1616. /*
  1617. * This is the actual Rx frames handler. as it blongs to Rx path it must
  1618. * be called with rcu_read_lock protection.
  1619. */
  1620. static void __ieee80211_rx_handle_packet(struct ieee80211_hw *hw,
  1621. struct sk_buff *skb,
  1622. struct ieee80211_rx_status *status,
  1623. u32 load,
  1624. struct ieee80211_rate *rate)
  1625. {
  1626. struct ieee80211_local *local = hw_to_local(hw);
  1627. struct ieee80211_sub_if_data *sdata;
  1628. struct ieee80211_hdr *hdr;
  1629. struct ieee80211_txrx_data rx;
  1630. u16 type;
  1631. int prepares;
  1632. struct ieee80211_sub_if_data *prev = NULL;
  1633. struct sk_buff *skb_new;
  1634. u8 *bssid;
  1635. hdr = (struct ieee80211_hdr *) skb->data;
  1636. memset(&rx, 0, sizeof(rx));
  1637. rx.skb = skb;
  1638. rx.local = local;
  1639. rx.u.rx.status = status;
  1640. rx.u.rx.load = load;
  1641. rx.u.rx.rate = rate;
  1642. rx.fc = le16_to_cpu(hdr->frame_control);
  1643. type = rx.fc & IEEE80211_FCTL_FTYPE;
  1644. if (type == IEEE80211_FTYPE_DATA || type == IEEE80211_FTYPE_MGMT)
  1645. local->dot11ReceivedFragmentCount++;
  1646. rx.sta = sta_info_get(local, hdr->addr2);
  1647. if (rx.sta) {
  1648. rx.dev = rx.sta->dev;
  1649. rx.sdata = IEEE80211_DEV_TO_SUB_IF(rx.dev);
  1650. }
  1651. if ((status->flag & RX_FLAG_MMIC_ERROR)) {
  1652. ieee80211_rx_michael_mic_report(local->mdev, hdr, &rx);
  1653. goto end;
  1654. }
  1655. if (unlikely(local->sta_sw_scanning || local->sta_hw_scanning))
  1656. rx.flags |= IEEE80211_TXRXD_RXIN_SCAN;
  1657. ieee80211_parse_qos(&rx);
  1658. ieee80211_verify_ip_alignment(&rx);
  1659. skb = rx.skb;
  1660. list_for_each_entry_rcu(sdata, &local->interfaces, list) {
  1661. if (!netif_running(sdata->dev))
  1662. continue;
  1663. if (sdata->vif.type == IEEE80211_IF_TYPE_MNTR)
  1664. continue;
  1665. bssid = ieee80211_get_bssid(hdr, skb->len, sdata->vif.type);
  1666. rx.flags |= IEEE80211_TXRXD_RXRA_MATCH;
  1667. prepares = prepare_for_handlers(sdata, bssid, &rx, hdr);
  1668. if (!prepares)
  1669. continue;
  1670. /*
  1671. * frame is destined for this interface, but if it's not
  1672. * also for the previous one we handle that after the
  1673. * loop to avoid copying the SKB once too much
  1674. */
  1675. if (!prev) {
  1676. prev = sdata;
  1677. continue;
  1678. }
  1679. /*
  1680. * frame was destined for the previous interface
  1681. * so invoke RX handlers for it
  1682. */
  1683. skb_new = skb_copy(skb, GFP_ATOMIC);
  1684. if (!skb_new) {
  1685. if (net_ratelimit())
  1686. printk(KERN_DEBUG "%s: failed to copy "
  1687. "multicast frame for %s",
  1688. wiphy_name(local->hw.wiphy),
  1689. prev->dev->name);
  1690. continue;
  1691. }
  1692. rx.fc = le16_to_cpu(hdr->frame_control);
  1693. ieee80211_invoke_rx_handlers(prev, &rx, skb_new);
  1694. prev = sdata;
  1695. }
  1696. if (prev) {
  1697. rx.fc = le16_to_cpu(hdr->frame_control);
  1698. ieee80211_invoke_rx_handlers(prev, &rx, skb);
  1699. } else
  1700. dev_kfree_skb(skb);
  1701. end:
  1702. if (rx.sta)
  1703. sta_info_put(rx.sta);
  1704. }
  1705. #define SEQ_MODULO 0x1000
  1706. #define SEQ_MASK 0xfff
  1707. static inline int seq_less(u16 sq1, u16 sq2)
  1708. {
  1709. return (((sq1 - sq2) & SEQ_MASK) > (SEQ_MODULO >> 1));
  1710. }
  1711. static inline u16 seq_inc(u16 sq)
  1712. {
  1713. return ((sq + 1) & SEQ_MASK);
  1714. }
  1715. static inline u16 seq_sub(u16 sq1, u16 sq2)
  1716. {
  1717. return ((sq1 - sq2) & SEQ_MASK);
  1718. }
  1719. /*
  1720. * As it function blongs to Rx path it must be called with
  1721. * the proper rcu_read_lock protection for its flow.
  1722. */
  1723. u8 ieee80211_sta_manage_reorder_buf(struct ieee80211_hw *hw,
  1724. struct tid_ampdu_rx *tid_agg_rx,
  1725. struct sk_buff *skb, u16 mpdu_seq_num,
  1726. int bar_req)
  1727. {
  1728. struct ieee80211_local *local = hw_to_local(hw);
  1729. struct ieee80211_rx_status status;
  1730. u16 head_seq_num, buf_size;
  1731. int index;
  1732. u32 pkt_load;
  1733. struct ieee80211_supported_band *sband;
  1734. struct ieee80211_rate *rate;
  1735. buf_size = tid_agg_rx->buf_size;
  1736. head_seq_num = tid_agg_rx->head_seq_num;
  1737. /* frame with out of date sequence number */
  1738. if (seq_less(mpdu_seq_num, head_seq_num)) {
  1739. dev_kfree_skb(skb);
  1740. return 1;
  1741. }
  1742. /* if frame sequence number exceeds our buffering window size or
  1743. * block Ack Request arrived - release stored frames */
  1744. if ((!seq_less(mpdu_seq_num, head_seq_num + buf_size)) || (bar_req)) {
  1745. /* new head to the ordering buffer */
  1746. if (bar_req)
  1747. head_seq_num = mpdu_seq_num;
  1748. else
  1749. head_seq_num =
  1750. seq_inc(seq_sub(mpdu_seq_num, buf_size));
  1751. /* release stored frames up to new head to stack */
  1752. while (seq_less(tid_agg_rx->head_seq_num, head_seq_num)) {
  1753. index = seq_sub(tid_agg_rx->head_seq_num,
  1754. tid_agg_rx->ssn)
  1755. % tid_agg_rx->buf_size;
  1756. if (tid_agg_rx->reorder_buf[index]) {
  1757. /* release the reordered frames to stack */
  1758. memcpy(&status,
  1759. tid_agg_rx->reorder_buf[index]->cb,
  1760. sizeof(status));
  1761. sband = local->hw.wiphy->bands[status.band];
  1762. rate = &sband->bitrates[status.rate_idx];
  1763. pkt_load = ieee80211_rx_load_stats(local,
  1764. tid_agg_rx->reorder_buf[index],
  1765. &status, rate);
  1766. __ieee80211_rx_handle_packet(hw,
  1767. tid_agg_rx->reorder_buf[index],
  1768. &status, pkt_load, rate);
  1769. tid_agg_rx->stored_mpdu_num--;
  1770. tid_agg_rx->reorder_buf[index] = NULL;
  1771. }
  1772. tid_agg_rx->head_seq_num =
  1773. seq_inc(tid_agg_rx->head_seq_num);
  1774. }
  1775. if (bar_req)
  1776. return 1;
  1777. }
  1778. /* now the new frame is always in the range of the reordering */
  1779. /* buffer window */
  1780. index = seq_sub(mpdu_seq_num, tid_agg_rx->ssn)
  1781. % tid_agg_rx->buf_size;
  1782. /* check if we already stored this frame */
  1783. if (tid_agg_rx->reorder_buf[index]) {
  1784. dev_kfree_skb(skb);
  1785. return 1;
  1786. }
  1787. /* if arrived mpdu is in the right order and nothing else stored */
  1788. /* release it immediately */
  1789. if (mpdu_seq_num == tid_agg_rx->head_seq_num &&
  1790. tid_agg_rx->stored_mpdu_num == 0) {
  1791. tid_agg_rx->head_seq_num =
  1792. seq_inc(tid_agg_rx->head_seq_num);
  1793. return 0;
  1794. }
  1795. /* put the frame in the reordering buffer */
  1796. tid_agg_rx->reorder_buf[index] = skb;
  1797. tid_agg_rx->stored_mpdu_num++;
  1798. /* release the buffer until next missing frame */
  1799. index = seq_sub(tid_agg_rx->head_seq_num, tid_agg_rx->ssn)
  1800. % tid_agg_rx->buf_size;
  1801. while (tid_agg_rx->reorder_buf[index]) {
  1802. /* release the reordered frame back to stack */
  1803. memcpy(&status, tid_agg_rx->reorder_buf[index]->cb,
  1804. sizeof(status));
  1805. sband = local->hw.wiphy->bands[status.band];
  1806. rate = &sband->bitrates[status.rate_idx];
  1807. pkt_load = ieee80211_rx_load_stats(local,
  1808. tid_agg_rx->reorder_buf[index],
  1809. &status, rate);
  1810. __ieee80211_rx_handle_packet(hw, tid_agg_rx->reorder_buf[index],
  1811. &status, pkt_load, rate);
  1812. tid_agg_rx->stored_mpdu_num--;
  1813. tid_agg_rx->reorder_buf[index] = NULL;
  1814. tid_agg_rx->head_seq_num = seq_inc(tid_agg_rx->head_seq_num);
  1815. index = seq_sub(tid_agg_rx->head_seq_num,
  1816. tid_agg_rx->ssn) % tid_agg_rx->buf_size;
  1817. }
  1818. return 1;
  1819. }
  1820. static u8 ieee80211_rx_reorder_ampdu(struct ieee80211_local *local,
  1821. struct sk_buff *skb)
  1822. {
  1823. struct ieee80211_hw *hw = &local->hw;
  1824. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
  1825. struct sta_info *sta;
  1826. struct tid_ampdu_rx *tid_agg_rx;
  1827. u16 fc, sc;
  1828. u16 mpdu_seq_num;
  1829. u8 ret = 0, *qc;
  1830. int tid;
  1831. sta = sta_info_get(local, hdr->addr2);
  1832. if (!sta)
  1833. return ret;
  1834. fc = le16_to_cpu(hdr->frame_control);
  1835. /* filter the QoS data rx stream according to
  1836. * STA/TID and check if this STA/TID is on aggregation */
  1837. if (!WLAN_FC_IS_QOS_DATA(fc))
  1838. goto end_reorder;
  1839. qc = skb->data + ieee80211_get_hdrlen(fc) - QOS_CONTROL_LEN;
  1840. tid = qc[0] & QOS_CONTROL_TID_MASK;
  1841. tid_agg_rx = &(sta->ampdu_mlme.tid_rx[tid]);
  1842. if (tid_agg_rx->state != HT_AGG_STATE_OPERATIONAL)
  1843. goto end_reorder;
  1844. /* null data frames are excluded */
  1845. if (unlikely(fc & IEEE80211_STYPE_NULLFUNC))
  1846. goto end_reorder;
  1847. /* new un-ordered ampdu frame - process it */
  1848. /* reset session timer */
  1849. if (tid_agg_rx->timeout) {
  1850. unsigned long expires =
  1851. jiffies + (tid_agg_rx->timeout / 1000) * HZ;
  1852. mod_timer(&tid_agg_rx->session_timer, expires);
  1853. }
  1854. /* if this mpdu is fragmented - terminate rx aggregation session */
  1855. sc = le16_to_cpu(hdr->seq_ctrl);
  1856. if (sc & IEEE80211_SCTL_FRAG) {
  1857. ieee80211_sta_stop_rx_ba_session(sta->dev, sta->addr,
  1858. tid, 0, WLAN_REASON_QSTA_REQUIRE_SETUP);
  1859. ret = 1;
  1860. goto end_reorder;
  1861. }
  1862. /* according to mpdu sequence number deal with reordering buffer */
  1863. mpdu_seq_num = (sc & IEEE80211_SCTL_SEQ) >> 4;
  1864. ret = ieee80211_sta_manage_reorder_buf(hw, tid_agg_rx, skb,
  1865. mpdu_seq_num, 0);
  1866. end_reorder:
  1867. if (sta)
  1868. sta_info_put(sta);
  1869. return ret;
  1870. }
  1871. /*
  1872. * This is the receive path handler. It is called by a low level driver when an
  1873. * 802.11 MPDU is received from the hardware.
  1874. */
  1875. void __ieee80211_rx(struct ieee80211_hw *hw, struct sk_buff *skb,
  1876. struct ieee80211_rx_status *status)
  1877. {
  1878. struct ieee80211_local *local = hw_to_local(hw);
  1879. u32 pkt_load;
  1880. struct ieee80211_rate *rate = NULL;
  1881. struct ieee80211_supported_band *sband;
  1882. if (status->band < 0 ||
  1883. status->band > IEEE80211_NUM_BANDS) {
  1884. WARN_ON(1);
  1885. return;
  1886. }
  1887. sband = local->hw.wiphy->bands[status->band];
  1888. if (!sband ||
  1889. status->rate_idx < 0 ||
  1890. status->rate_idx >= sband->n_bitrates) {
  1891. WARN_ON(1);
  1892. return;
  1893. }
  1894. rate = &sband->bitrates[status->rate_idx];
  1895. /*
  1896. * key references and virtual interfaces are protected using RCU
  1897. * and this requires that we are in a read-side RCU section during
  1898. * receive processing
  1899. */
  1900. rcu_read_lock();
  1901. /*
  1902. * Frames with failed FCS/PLCP checksum are not returned,
  1903. * all other frames are returned without radiotap header
  1904. * if it was previously present.
  1905. * Also, frames with less than 16 bytes are dropped.
  1906. */
  1907. skb = ieee80211_rx_monitor(local, skb, status, rate);
  1908. if (!skb) {
  1909. rcu_read_unlock();
  1910. return;
  1911. }
  1912. pkt_load = ieee80211_rx_load_stats(local, skb, status, rate);
  1913. local->channel_use_raw += pkt_load;
  1914. if (!ieee80211_rx_reorder_ampdu(local, skb))
  1915. __ieee80211_rx_handle_packet(hw, skb, status, pkt_load, rate);
  1916. rcu_read_unlock();
  1917. }
  1918. EXPORT_SYMBOL(__ieee80211_rx);
  1919. /* This is a version of the rx handler that can be called from hard irq
  1920. * context. Post the skb on the queue and schedule the tasklet */
  1921. void ieee80211_rx_irqsafe(struct ieee80211_hw *hw, struct sk_buff *skb,
  1922. struct ieee80211_rx_status *status)
  1923. {
  1924. struct ieee80211_local *local = hw_to_local(hw);
  1925. BUILD_BUG_ON(sizeof(struct ieee80211_rx_status) > sizeof(skb->cb));
  1926. skb->dev = local->mdev;
  1927. /* copy status into skb->cb for use by tasklet */
  1928. memcpy(skb->cb, status, sizeof(*status));
  1929. skb->pkt_type = IEEE80211_RX_MSG;
  1930. skb_queue_tail(&local->skb_queue, skb);
  1931. tasklet_schedule(&local->tasklet);
  1932. }
  1933. EXPORT_SYMBOL(ieee80211_rx_irqsafe);