rx.c 61 KB

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