rx.c 63 KB

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