rx.c 63 KB

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