13 #include <linux/slab.h>
14 #include <linux/kernel.h>
16 #include <linux/netdevice.h>
19 #include <linux/export.h>
22 #include <asm/unaligned.h>
57 static inline int should_drop_frame(
struct sk_buff *skb,
115 int rtap_len,
bool has_fcs)
123 memset(rthdr, 0, rtap_len);
133 pos = (
unsigned char *)(rthdr+1);
170 put_unaligned_le16(status->
freq, pos);
207 if ((pos - (
u8 *)rthdr) & 1)
211 put_unaligned_le16(rx_flags, pos);
216 *pos++ = local->
hw.radiotap_mcs_details;
232 while ((pos - (
u8 *)rthdr) & 3)
250 put_unaligned_le16(flags, pos);
274 int present_fcs_len = 0;
286 needed_headroom = ieee80211_rx_radiotap_len(local, status);
292 if (!pskb_may_pull(origskb, 2)) {
293 dev_kfree_skb(origskb);
298 if (should_drop_frame(origskb, present_fcs_len)) {
299 dev_kfree_skb(origskb);
303 return remove_monitor_info(local, origskb);
306 if (should_drop_frame(origskb, present_fcs_len)) {
318 if (skb_headroom(skb) < needed_headroom &&
330 origskb = remove_monitor_info(local, origskb);
337 ieee80211_add_rx_radiotap_header(local, skb, rate, needed_headroom,
340 skb_reset_mac_header(skb);
352 if (!ieee80211_sdata_running(sdata))
358 skb2->
dev = prev_dev;
363 prev_dev = sdata->
dev;
364 sdata->
dev->stats.rx_packets++;
365 sdata->
dev->stats.rx_bytes += skb->
len;
382 int tid, seqno_idx, security_idx;
386 u8 *qc = ieee80211_get_qos_ctl(hdr);
417 rx->
skb->priority = (tid > 7) ? 0 : tid;
447 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
449 "unaligned packet at 0x%p\n", rx->
skb->data);
456 static int ieee80211_is_unicast_robust_mgmt_frame(
struct sk_buff *skb)
460 if (skb->
len < 24 || is_multicast_ether_addr(hdr->
addr1))
463 return ieee80211_is_robust_mgmt_frame(hdr);
467 static int ieee80211_is_multicast_robust_mgmt_frame(
struct sk_buff *skb)
471 if (skb->
len < 24 || !is_multicast_ether_addr(hdr->
addr1))
474 return ieee80211_is_robust_mgmt_frame(hdr);
479 static int ieee80211_get_mmie_keyidx(
struct sk_buff *skb)
484 if (skb->
len < 24 +
sizeof(*mmie) ||
485 !is_multicast_ether_addr(hdr->
da))
488 if (!ieee80211_is_robust_mgmt_frame((
struct ieee80211_hdr *) hdr))
492 (skb->
data + skb->
len -
sizeof(*mmie));
494 mmie->length !=
sizeof(*mmie) - 2)
505 char *dev_addr = rx->
sdata->vif.addr;
508 if (is_multicast_ether_addr(hdr->
addr1)) {
512 if (ether_addr_equal(hdr->
addr3, dev_addr))
517 if (ether_addr_equal(hdr->
addr4, dev_addr))
540 category = mgmt->
u.action.category;
560 #define SEQ_MODULO 0x1000
561 #define SEQ_MASK 0xfff
563 static inline int seq_less(
u16 sq1,
u16 sq2)
568 static inline u16 seq_inc(
u16 sq)
573 static inline u16 seq_sub(
u16 sq1,
u16 sq2)
595 status = IEEE80211_SKB_RXCB(skb);
611 while (seq_less(tid_agg_rx->
head_seq_num, head_seq_num)) {
614 ieee80211_release_reorder_frame(sdata, tid_agg_rx, index);
627 #define HT_RX_REORDER_BUF_TIMEOUT (HZ / 10)
646 for (j = (index + 1) % tid_agg_rx->
buf_size; j != index;
647 j = (j + 1) % tid_agg_rx->
buf_size) {
655 goto set_release_timer;
658 "release an RX reorder frame due to timeout on earlier frames\n");
659 ieee80211_release_reorder_frame(sdata, tid_agg_rx, j);
669 ieee80211_release_reorder_frame(sdata, tid_agg_rx, index);
678 for (; j != (index - 1) % tid_agg_rx->
buf_size;
679 j = (j + 1) % tid_agg_rx->
buf_size) {
716 if (seq_less(mpdu_seq_num, head_seq_num)) {
725 if (!seq_less(mpdu_seq_num, head_seq_num + buf_size)) {
726 head_seq_num = seq_inc(seq_sub(mpdu_seq_num, buf_size));
728 ieee80211_release_reorder_frames(sdata, tid_agg_rx,
734 index = seq_sub(mpdu_seq_num, tid_agg_rx->
ssn) % tid_agg_rx->
buf_size;
759 ieee80211_sta_reorder_release(sdata, tid_agg_rx);
792 ack_policy = *ieee80211_get_qos_ctl(hdr) &
835 if (ieee80211_sta_manage_reorder_buf(rx->
sdata, tid_agg_rx, skb))
849 if (rx->
sta && !is_multicast_ether_addr(hdr->
addr1)) {
854 rx->
local->dot11FrameDuplicateCount++;
855 rx->
sta->num_duplicates++;
876 if (ieee80211_vif_is_mesh(&rx->
sdata->vif))
877 return ieee80211_rx_mesh_check(rx);
896 if (rx->
skb->len < hdrlen + 8)
900 if (ethertype == rx->
sdata->control_port_protocol)
927 int mmie_keyidx = -1;
972 if (!ieee80211_has_protected(
fc))
973 mmie_keyidx = ieee80211_get_mmie_keyidx(rx->
skb);
975 if (!is_multicast_ether_addr(hdr->
addr1) && sta_ptk) {
981 if (!ieee80211_has_protected(
fc))
983 }
else if (mmie_keyidx >= 0) {
996 }
else if (!ieee80211_has_protected(
fc)) {
1007 if (ieee80211_is_mgmt(
fc) &&
1008 is_multicast_ether_addr(hdr->
addr1) &&
1047 if (rx->
skb->len < 8 + hdrlen)
1055 keyidx = keyid >> 6;
1058 if (is_multicast_ether_addr(hdr->
addr1) && rx->
sta)
1073 !is_multicast_ether_addr(hdr->
addr1))
1082 rx->
key->tx_rx_count++;
1088 switch (rx->
key->conf.cipher) {
1151 static void ap_sta_ps_start(
struct sta_info *sta)
1160 ps_dbg(sdata,
"STA %pM aid %d enters power save mode\n",
1161 sta->
sta.addr, sta->
sta.aid);
1164 static void ap_sta_ps_end(
struct sta_info *sta)
1166 ps_dbg(sta->
sdata,
"STA %pM aid %d exits power save mode\n",
1167 sta->
sta.addr, sta->
sta.aid);
1170 ps_dbg(sta->
sdata,
"STA %pM aid %d driver-ps-blocked\n",
1171 sta->
sta.addr, sta->
sta.aid);
1187 if ((start && in_ps) || (!start && !in_ps))
1191 ap_sta_ps_start(sta_inf);
1193 ap_sta_ps_end(sta_inf);
1240 dev_kfree_skb(rx->
skb);
1258 if (!(rx->
sta->sta.uapsd_queues &
BIT(ac)))
1293 if (ether_addr_equal(bssid, rx->
sdata->u.ibss.bssid)) {
1300 }
else if (!is_multicast_ether_addr(hdr->
addr1)) {
1348 ap_sta_ps_start(sta);
1369 !rx->
sdata->u.vlan.sta))) {
1381 dev_kfree_skb(rx->
skb);
1401 if (!skb_queue_empty(&entry->
skb_list))
1402 __skb_queue_purge(&entry->
skb_list);
1404 __skb_queue_tail(&entry->
skb_list, *skb);
1418 unsigned int frag,
unsigned int seq,
1430 idx = IEEE80211_FRAGMENT_MAX - 1;
1433 if (skb_queue_empty(&entry->
skb_list) || entry->
seq != seq ||
1445 !ether_addr_equal(hdr->
addr1, f_hdr->
addr1) ||
1450 __skb_queue_purge(&entry->
skb_list);
1465 unsigned int frag, seq;
1473 if (ieee80211_is_ctl(fc))
1479 if (
likely((!ieee80211_has_morefrags(fc) && frag == 0) ||
1480 is_multicast_ether_addr(hdr->
addr1))) {
1486 if (skb_linearize(rx->
skb))
1499 entry = ieee80211_reassemble_add(rx->
sdata, frag, seq,
1502 ieee80211_has_protected(fc)) {
1508 rx->
key->u.ccmp.rx_pn[queue],
1517 entry = ieee80211_reassemble_find(rx->
sdata, frag, seq,
1539 rpn = rx->
key->u.ccmp.rx_pn[queue];
1549 if (ieee80211_has_morefrags(fc)) {
1560 __skb_queue_purge(&entry->
skb_list);
1564 while ((skb = __skb_dequeue(&entry->
skb_list))) {
1570 status = IEEE80211_SKB_RXCB(rx->
skb);
1575 rx->
sta->rx_packets++;
1576 if (is_multicast_ether_addr(hdr->
addr1))
1577 rx->
local->dot11MulticastReceivedFrameCount++;
1607 if (
unlikely(!ieee80211_has_protected(fc) &&
1608 !ieee80211_is_nullfunc(fc) &&
1609 ieee80211_is_data(fc) &&
1610 (rx->
key || rx->
sdata->drop_unencrypted)))
1631 if (
unlikely(!ieee80211_has_protected(fc) &&
1632 ieee80211_is_unicast_robust_mgmt_frame(rx->
skb) &&
1634 if (ieee80211_is_deauth(fc))
1638 else if (ieee80211_is_disassoc(fc))
1645 if (
unlikely(ieee80211_is_multicast_robust_mgmt_frame(rx->
skb) &&
1646 ieee80211_get_mmie_keyidx(rx->
skb) < 0)) {
1647 if (ieee80211_is_deauth(fc))
1651 else if (ieee80211_is_disassoc(fc))
1661 if (
unlikely(ieee80211_is_action(fc) && !rx->
key &&
1662 ieee80211_is_robust_mgmt_frame(
1675 bool check_port_control =
false;
1679 *port_control =
false;
1687 if (!sdata->
u.
mgd.use_4addr)
1690 check_port_control =
true;
1693 if (is_multicast_ether_addr(hdr->
addr1) &&
1702 if (ehdr->h_proto == rx->
sdata->control_port_protocol)
1703 *port_control =
true;
1704 else if (check_port_control)
1716 = { 0x01, 0x80, 0xC2, 0x00, 0x00, 0x03 };
1724 (ether_addr_equal(ehdr->
h_dest, rx->
sdata->vif.addr) ||
1725 ether_addr_equal(ehdr->
h_dest, pae_group_addr)))
1728 if (ieee80211_802_1x_port_control(rx) ||
1729 ieee80211_drop_unencrypted(rx, fc))
1756 if (is_multicast_ether_addr(ehdr->
h_dest)) {
1783 #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
1793 if (
WARN_ON(skb_headroom(skb) < 3)) {
1798 size_t len = skb_headlen(skb);
1801 skb_set_tail_pointer(skb, len);
1809 memset(skb->cb, 0,
sizeof(skb->cb));
1822 skb_reset_network_header(xmit_skb);
1823 skb_reset_mac_header(xmit_skb);
1838 if (
unlikely(!ieee80211_is_data(fc)))
1841 if (
unlikely(!ieee80211_is_data_present(fc)))
1849 !rx->
sdata->u.vlan.sta)
1852 if (is_multicast_ether_addr(hdr->
addr1) &&
1854 rx->
sdata->u.vlan.sta) ||
1856 rx->
sdata->u.mgd.use_4addr)))
1862 if (skb_linearize(skb))
1866 rx->
sdata->vif.type,
1867 rx->
local->hw.extra_tx_headroom,
true);
1872 if (!ieee80211_frame_allowed(rx, fc)) {
1873 dev_kfree_skb(rx->
skb);
1876 dev->
stats.rx_packets++;
1877 dev->
stats.rx_bytes += rx->
skb->len;
1879 ieee80211_deliver_skb(rx);
1885 #ifdef CONFIG_MAC80211_MESH
1904 if (!pskb_may_pull(rx->
skb, hdrlen + 6))
1910 if (!pskb_may_pull(rx->
skb,
1920 is_multicast_ether_addr(hdr->
addr1) &&
1936 if (is_multicast_ether_addr(hdr->
addr1)) {
1937 mpp_addr = hdr->
addr3;
1938 proxied_addr = mesh_hdr->
eaddr1;
1941 mpp_addr = hdr->
addr4;
1942 proxied_addr = mesh_hdr->
eaddr2;
1953 if (!ether_addr_equal(mppath->
mpp, mpp_addr))
1961 if (!is_multicast_ether_addr(hdr->
addr1) &&
1962 ether_addr_equal(sdata->
vif.addr, hdr->
addr3))
1970 skb_set_queue_mapping(skb, q);
1972 if (!--mesh_hdr->
ttl) {
1977 if (!ifmsh->
mshcfg.dot11MeshForwarding)
1988 info = IEEE80211_SKB_CB(fwd_skb);
1989 memset(info, 0,
sizeof(*info));
1993 if (is_multicast_ether_addr(fwd_hdr->
addr1)) {
2001 0, reason, fwd_hdr->
addr2, sdata);
2010 if (is_multicast_ether_addr(hdr->
addr1) ||
2048 err = __ieee80211_data_to_8023(rx, &port_control);
2052 if (!ieee80211_frame_allowed(rx, fc))
2065 dev->
stats.rx_packets++;
2066 dev->
stats.rx_bytes += rx->
skb->len;
2068 if (local->
ps_sdata && local->
hw.conf.dynamic_ps_timeout > 0 &&
2069 !is_multicast_ether_addr(
2070 ((
struct ethhdr *)rx->
skb->data)->h_dest) &&
2077 ieee80211_deliver_skb(rx);
2103 &bar_data,
sizeof(bar_data)))
2121 ieee80211_release_reorder_frames(rx->
sdata, tid_agg_rx,
2145 if (!ether_addr_equal(mgmt->
da, sdata->
vif.addr)) {
2150 if (!ether_addr_equal(mgmt->
sa, sdata->
u.
mgd.bssid) ||
2151 !ether_addr_equal(mgmt->
bssid, sdata->
u.
mgd.bssid)) {
2156 if (len < 24 + 1 +
sizeof(resp->
u.action.u.sa_query)) {
2161 skb = dev_alloc_skb(
sizeof(*resp) + local->
hw.extra_tx_headroom);
2165 skb_reserve(skb, local->
hw.extra_tx_headroom);
2173 skb_put(skb, 1 +
sizeof(resp->
u.action.u.sa_query));
2176 memcpy(resp->
u.action.u.sa_query.trans_id,
2177 mgmt->
u.action.u.sa_query.trans_id,
2180 ieee80211_tx_skb(sdata, skb);
2194 if (rx->
skb->len < 24)
2209 rx->
skb->data, rx->
skb->len,
2217 if (ieee80211_drop_unencrypted_mgmt(rx))
2230 int len = rx->
skb->len;
2245 switch (mgmt->
u.action.category) {
2248 if (!rx->
sta->sta.ht_cap.ht_supported)
2262 switch (mgmt->
u.action.u.ht_smps.action) {
2268 switch (mgmt->
u.action.u.ht_smps.smps_control) {
2284 if ((rx->
sta->sta.ht_cap.cap &
2289 rx->
sta->sta.ht_cap.cap |= smps;
2291 sband = rx->
local->hw.wiphy->bands[status->
band];
2293 rate_control_rate_update(local, sband, rx->
sta,
2314 switch (mgmt->
u.action.u.addba_req.action_code) {
2317 sizeof(mgmt->
u.action.u.addba_req)))
2322 sizeof(mgmt->
u.action.u.addba_resp)))
2327 sizeof(mgmt->
u.action.u.delba)))
2346 switch (mgmt->
u.action.u.measurement.action_code) {
2349 sizeof(mgmt->
u.action.u.measurement)))
2355 sizeof(mgmt->
u.action.u.chan_switch)))
2361 if (!ether_addr_equal(mgmt->
bssid, sdata->
u.
mgd.bssid))
2369 sizeof(mgmt->
u.action.u.sa_query)))
2372 switch (mgmt->
u.action.u.sa_query.action) {
2376 ieee80211_process_sa_query_req(sdata, mgmt, len);
2382 sizeof(mgmt->
u.action.u.self_prot.action_code)))
2385 switch (mgmt->
u.action.u.self_prot.action_code) {
2389 if (!ieee80211_vif_is_mesh(&sdata->
vif))
2391 if (sdata->
u.
mesh.security != IEEE80211_MESH_SEC_NONE)
2397 if (!ieee80211_vif_is_mesh(&sdata->
vif))
2404 sizeof(mgmt->
u.action.u.mesh_action.action_code)))
2407 if (!ieee80211_vif_is_mesh(&sdata->
vif))
2410 (!mesh_path_sel_is_hwmp(sdata)))
2424 rx->
sta->rx_packets++;
2425 dev_kfree_skb(rx->
skb);
2433 rx->
sta->rx_packets++;
2458 rx->
skb->data, rx->
skb->len,
2461 rx->
sta->rx_packets++;
2462 dev_kfree_skb(rx->
skb);
2497 if (is_multicast_ether_addr(mgmt->
da))
2501 if (mgmt->
u.action.category & 0x80)
2509 nmgmt->
u.action.category |= 0x80;
2513 memset(nskb->cb, 0,
sizeof(nskb->cb));
2515 ieee80211_tx_skb(rx->
sdata, nskb);
2517 dev_kfree_skb(rx->
skb);
2530 if (!ieee80211_vif_is_mesh(&sdata->
vif) &&
2545 if (is_multicast_ether_addr(mgmt->
da) &&
2546 !is_broadcast_ether_addr(mgmt->
da))
2567 rx->
sta->rx_packets++;
2581 int needed_headroom;
2596 needed_headroom = ieee80211_rx_radiotap_len(local, status);
2598 if (skb_headroom(skb) < needed_headroom &&
2603 ieee80211_add_rx_radiotap_header(local, skb, rate, needed_headroom,
2606 skb_set_mac_header(skb, 0);
2612 if (!ieee80211_sdata_running(sdata))
2622 skb2->
dev = prev_dev;
2627 prev_dev = sdata->
dev;
2628 sdata->
dev->stats.rx_packets++;
2629 sdata->
dev->stats.rx_bytes += skb->
len;
2633 skb->
dev = prev_dev;
2649 rx->
sta->rx_dropped++;
2656 status = IEEE80211_SKB_RXCB((rx->
skb));
2658 sband = rx->
local->hw.wiphy->bands[status->
band];
2662 ieee80211_rx_cooked_monitor(rx, rate);
2668 rx->
sta->rx_dropped++;
2669 dev_kfree_skb(rx->
skb);
2682 #define CALL_RXH(rxh) \
2685 if (res != RX_CONTINUE) \
2689 spin_lock(&rx->
local->rx_skb_queue.lock);
2690 if (rx->
local->running_rx_handler)
2693 rx->
local->running_rx_handler =
true;
2695 while ((skb = __skb_dequeue(&rx->
local->rx_skb_queue))) {
2696 spin_unlock(&rx->
local->rx_skb_queue.lock);
2706 CALL_RXH(ieee80211_rx_h_check_more_data)
2707 CALL_RXH(ieee80211_rx_h_uapsd_and_pspoll)
2708 CALL_RXH(ieee80211_rx_h_sta_process)
2709 CALL_RXH(ieee80211_rx_h_defragment)
2712 #ifdef CONFIG_MAC80211_MESH
2713 if (ieee80211_vif_is_mesh(&rx->
sdata->vif))
2714 CALL_RXH(ieee80211_rx_h_mesh_fwding);
2717 CALL_RXH(ieee80211_rx_h_data)
2718 CALL_RXH(ieee80211_rx_h_ctrl);
2719 CALL_RXH(ieee80211_rx_h_mgmt_check)
2720 CALL_RXH(ieee80211_rx_h_action)
2721 CALL_RXH(ieee80211_rx_h_userspace_mgmt)
2722 CALL_RXH(ieee80211_rx_h_action_return)
2723 CALL_RXH(ieee80211_rx_h_mgmt)
2726 ieee80211_rx_handlers_result(rx, res);
2727 spin_lock(&rx->local->rx_skb_queue.lock);
2731 rx->
local->running_rx_handler =
false;
2734 spin_unlock(&rx->
local->rx_skb_queue.lock);
2741 #define CALL_RXH(rxh) \
2744 if (res != RX_CONTINUE) \
2750 ieee80211_rx_reorder_ampdu(rx);
2752 ieee80211_rx_handlers(rx);
2756 ieee80211_rx_handlers_result(rx, res);
2769 .sdata = sta->
sdata,
2770 .local = sta->
local,
2772 .security_idx = tid,
2783 ieee80211_sta_reorder_release(sta->
sdata, tid_agg_rx);
2786 ieee80211_rx_handlers(&rx);
2798 int multicast = is_multicast_ether_addr(hdr->
addr1);
2800 switch (sdata->
vif.type) {
2802 if (!bssid && !sdata->
u.
mgd.use_4addr)
2805 !ether_addr_equal(sdata->
vif.addr, hdr->
addr1)) {
2807 sdata->
u.
mgd.use_4addr)
2817 }
else if (!ieee80211_bssid_match(bssid, sdata->
u.
ibss.bssid)) {
2819 }
else if (!multicast &&
2820 !ether_addr_equal(sdata->
vif.addr, hdr->
addr1)) {
2824 }
else if (!rx->
sta) {
2836 !ether_addr_equal(sdata->
vif.addr, hdr->
addr1)) {
2846 if (!ether_addr_equal(sdata->
vif.addr, hdr->
addr1))
2848 }
else if (!ieee80211_bssid_match(bssid, sdata->
vif.addr)) {
2855 if (ieee80211_is_public_action(hdr, skb->
len))
2865 if (!ether_addr_equal(sdata->
u.
wds.remote_addr, hdr->
addr2))
2869 if (!ieee80211_is_public_action(hdr, skb->
len) &&
2874 if (!ether_addr_equal(sdata->
vif.addr, hdr->
addr1))
2893 struct sk_buff *skb,
bool consume)
2903 prepares = prepare_for_handlers(rx, hdr);
2913 "failed to copy skb for %s\n",
2921 ieee80211_invoke_rx_handlers(rx);
2929 static void __ieee80211_rx_handle_packet(
struct ieee80211_hw *
hw,
2942 memset(&rx, 0,
sizeof(rx));
2946 if (ieee80211_is_data(fc) || ieee80211_is_mgmt(fc))
2949 if (ieee80211_is_mgmt(fc)) {
2954 err = skb_linearize(skb);
2965 ieee80211_parse_qos(&rx);
2966 ieee80211_verify_alignment(&rx);
2972 if (ieee80211_is_data(fc)) {
2983 ieee80211_prepare_and_rx_handle(&rx, skb,
false);
2992 if (ieee80211_prepare_and_rx_handle(&rx, skb,
true))
3001 if (!ieee80211_sdata_running(sdata))
3021 ieee80211_prepare_and_rx_handle(&rx, skb,
false);
3030 if (ieee80211_prepare_and_rx_handle(&rx, skb,
true))
3055 sband = local->
hw.wiphy->bands[status->
band];
3099 "Rate marked as an HT rate but passed "
3100 "status->rate_idx is not "
3101 "an MCS index [0-76]: %d (0x%02x)\n",
3128 skb = ieee80211_rx_monitor(local, skb, rate);
3134 ieee80211_tpt_led_trig_rx(local,
3137 __ieee80211_rx_handle_packet(hw, skb);
3157 tasklet_schedule(&local->
tasklet);