d640bcfecc2e3cf9c3de1f8d83d5cdf952699682
[openwrt/staging/linusw.git] /
1 From a8d7631858aff156b72f807ee7cc062048e63836 Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <rafal@milecki.pl>
3 Date: Sun, 24 Jun 2018 21:44:37 +0200
4 Subject: [PATCH] brcmfmac: handle msgbuf packets marked with monitor mode flag
5 MIME-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
8
9 New Broadcom firmwares mark monitor mode packets using a newly defined
10 bit in the flags field. Use it to filter them out and pass to the
11 monitor interface. These defines were found in bcmmsgbuf.h from SDK.
12
13 As not every firmware generates radiotap header this commit introduces
14 BRCMF_FEAT_MONITOR_FMT_RADIOTAP flag. It has to be has based on firmware
15 capabilities. If not present brcmf_netif_mon_rx() will assume packet is
16 a raw 802.11 frame and will prepend it with an empty radiotap header.
17
18 This new code is limited to the msgbuf protocol at this point. Adding
19 support for SDIO/USB devices will require some extra work (possibly a
20 new firmware release).
21
22 Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
23 Acked-by: Arend van Spriel <arend.vanspriel@broadcom.com>
24 Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
25 ---
26 .../wireless/broadcom/brcm80211/brcmfmac/core.c | 25 ++++++++++++++++++++++
27 .../wireless/broadcom/brcm80211/brcmfmac/core.h | 2 ++
28 .../wireless/broadcom/brcm80211/brcmfmac/msgbuf.c | 18 ++++++++++++++++
29 3 files changed, 45 insertions(+)
30
31 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.c
32 +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.c
33 @@ -21,6 +21,7 @@
34 #include <net/cfg80211.h>
35 #include <net/rtnetlink.h>
36 #include <net/addrconf.h>
37 +#include <net/ieee80211_radiotap.h>
38 #include <net/ipv6.h>
39 #include <brcmu_utils.h>
40 #include <brcmu_wifi.h>
41 @@ -404,6 +405,30 @@ void brcmf_netif_rx(struct brcmf_if *ifp
42 netif_rx_ni(skb);
43 }
44
45 +void brcmf_netif_mon_rx(struct brcmf_if *ifp, struct sk_buff *skb)
46 +{
47 + if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MONITOR_FMT_RADIOTAP)) {
48 + /* Do nothing */
49 + } else {
50 + struct ieee80211_radiotap_header *radiotap;
51 +
52 + /* TODO: use RX status to fill some radiotap data */
53 + radiotap = skb_push(skb, sizeof(*radiotap));
54 + memset(radiotap, 0, sizeof(*radiotap));
55 + radiotap->it_len = cpu_to_le16(sizeof(*radiotap));
56 +
57 + /* TODO: 4 bytes with receive status? */
58 + skb->len -= 4;
59 + }
60 +
61 + skb->dev = ifp->ndev;
62 + skb_reset_mac_header(skb);
63 + skb->pkt_type = PACKET_OTHERHOST;
64 + skb->protocol = htons(ETH_P_802_2);
65 +
66 + brcmf_netif_rx(ifp, skb);
67 +}
68 +
69 static int brcmf_rx_hdrpull(struct brcmf_pub *drvr, struct sk_buff *skb,
70 struct brcmf_if **ifp)
71 {
72 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.h
73 +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.h
74 @@ -121,6 +121,7 @@ struct brcmf_pub {
75
76 struct brcmf_if *iflist[BRCMF_MAX_IFS];
77 s32 if2bss[BRCMF_MAX_IFS];
78 + struct brcmf_if *mon_if;
79
80 struct mutex proto_block;
81 unsigned char proto_buf[BRCMF_DCMD_MAXLEN];
82 @@ -216,6 +217,7 @@ void brcmf_txflowblock_if(struct brcmf_i
83 enum brcmf_netif_stop_reason reason, bool state);
84 void brcmf_txfinalize(struct brcmf_if *ifp, struct sk_buff *txp, bool success);
85 void brcmf_netif_rx(struct brcmf_if *ifp, struct sk_buff *skb);
86 +void brcmf_netif_mon_rx(struct brcmf_if *ifp, struct sk_buff *skb);
87 void brcmf_net_setcarrier(struct brcmf_if *ifp, bool on);
88 int __init brcmf_core_init(void);
89 void __exit brcmf_core_exit(void);
90 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/msgbuf.c
91 +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/msgbuf.c
92 @@ -69,6 +69,8 @@
93 #define BRCMF_MSGBUF_MAX_EVENTBUF_POST 8
94
95 #define BRCMF_MSGBUF_PKT_FLAGS_FRAME_802_3 0x01
96 +#define BRCMF_MSGBUF_PKT_FLAGS_FRAME_802_11 0x02
97 +#define BRCMF_MSGBUF_PKT_FLAGS_FRAME_MASK 0x07
98 #define BRCMF_MSGBUF_PKT_FLAGS_PRIO_SHIFT 5
99
100 #define BRCMF_MSGBUF_TX_FLUSH_CNT1 32
101 @@ -1128,6 +1130,7 @@ brcmf_msgbuf_process_rx_complete(struct
102 struct sk_buff *skb;
103 u16 data_offset;
104 u16 buflen;
105 + u16 flags;
106 u32 idx;
107 struct brcmf_if *ifp;
108
109 @@ -1137,6 +1140,7 @@ brcmf_msgbuf_process_rx_complete(struct
110 data_offset = le16_to_cpu(rx_complete->data_offset);
111 buflen = le16_to_cpu(rx_complete->data_len);
112 idx = le32_to_cpu(rx_complete->msg.request_id);
113 + flags = le16_to_cpu(rx_complete->flags);
114
115 skb = brcmf_msgbuf_get_pktid(msgbuf->drvr->bus_if->dev,
116 msgbuf->rx_pktids, idx);
117 @@ -1150,6 +1154,20 @@ brcmf_msgbuf_process_rx_complete(struct
118
119 skb_trim(skb, buflen);
120
121 + if ((flags & BRCMF_MSGBUF_PKT_FLAGS_FRAME_MASK) ==
122 + BRCMF_MSGBUF_PKT_FLAGS_FRAME_802_11) {
123 + ifp = msgbuf->drvr->mon_if;
124 +
125 + if (!ifp) {
126 + brcmf_err("Received unexpected monitor pkt\n");
127 + brcmu_pkt_buf_free_skb(skb);
128 + return;
129 + }
130 +
131 + brcmf_netif_mon_rx(ifp, skb);
132 + return;
133 + }
134 +
135 ifp = brcmf_get_ifp(msgbuf->drvr, rx_complete->msg.ifidx);
136 if (!ifp || !ifp->ndev) {
137 brcmf_err("Received pkt for invalid ifidx %d\n",