rx.c 62 KB

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