rx.c 63 KB

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