rx.c 62 KB

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