rx.c 62 KB

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