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
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
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.
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.
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).
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>
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(+)
31 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.c
32 +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.c
34 #include <net/cfg80211.h>
35 #include <net/rtnetlink.h>
36 #include <net/addrconf.h>
37 +#include <net/ieee80211_radiotap.h>
39 #include <brcmu_utils.h>
40 #include <brcmu_wifi.h>
41 @@ -367,6 +368,34 @@ void brcmf_netif_rx(struct brcmf_if *ifp
45 +void brcmf_netif_mon_rx(struct brcmf_if *ifp, struct sk_buff *skb)
47 + if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MONITOR_FMT_RADIOTAP)) {
50 + struct ieee80211_radiotap_header *radiotap;
52 + /* TODO: use RX status to fill some radiotap data */
53 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 13, 0)
54 + radiotap = skb_push(skb, sizeof(*radiotap));
56 + radiotap = (struct ieee80211_radiotap_header *)skb_push(skb, sizeof(*radiotap));
58 + memset(radiotap, 0, sizeof(*radiotap));
59 + radiotap->it_len = cpu_to_le16(sizeof(*radiotap));
61 + /* TODO: 4 bytes with receive status? */
65 + skb->dev = ifp->ndev;
66 + skb_reset_mac_header(skb);
67 + skb->pkt_type = PACKET_OTHERHOST;
68 + skb->protocol = htons(ETH_P_802_2);
70 + brcmf_netif_rx(ifp, skb);
73 static int brcmf_rx_hdrpull(struct brcmf_pub *drvr, struct sk_buff *skb,
74 struct brcmf_if **ifp)
76 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.h
77 +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.h
78 @@ -121,6 +121,7 @@ struct brcmf_pub {
80 struct brcmf_if *iflist[BRCMF_MAX_IFS];
81 s32 if2bss[BRCMF_MAX_IFS];
82 + struct brcmf_if *mon_if;
84 struct mutex proto_block;
85 unsigned char proto_buf[BRCMF_DCMD_MAXLEN];
86 @@ -215,6 +216,7 @@ void brcmf_txflowblock_if(struct brcmf_i
87 enum brcmf_netif_stop_reason reason, bool state);
88 void brcmf_txfinalize(struct brcmf_if *ifp, struct sk_buff *txp, bool success);
89 void brcmf_netif_rx(struct brcmf_if *ifp, struct sk_buff *skb);
90 +void brcmf_netif_mon_rx(struct brcmf_if *ifp, struct sk_buff *skb);
91 void brcmf_net_setcarrier(struct brcmf_if *ifp, bool on);
92 int __init brcmf_core_init(void);
93 void __exit brcmf_core_exit(void);
94 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/msgbuf.c
95 +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/msgbuf.c
97 #define BRCMF_MSGBUF_MAX_EVENTBUF_POST 8
99 #define BRCMF_MSGBUF_PKT_FLAGS_FRAME_802_3 0x01
100 +#define BRCMF_MSGBUF_PKT_FLAGS_FRAME_802_11 0x02
101 +#define BRCMF_MSGBUF_PKT_FLAGS_FRAME_MASK 0x07
102 #define BRCMF_MSGBUF_PKT_FLAGS_PRIO_SHIFT 5
104 #define BRCMF_MSGBUF_TX_FLUSH_CNT1 32
105 @@ -1126,6 +1128,7 @@ brcmf_msgbuf_process_rx_complete(struct
111 struct brcmf_if *ifp;
113 @@ -1135,6 +1138,7 @@ brcmf_msgbuf_process_rx_complete(struct
114 data_offset = le16_to_cpu(rx_complete->data_offset);
115 buflen = le16_to_cpu(rx_complete->data_len);
116 idx = le32_to_cpu(rx_complete->msg.request_id);
117 + flags = le16_to_cpu(rx_complete->flags);
119 skb = brcmf_msgbuf_get_pktid(msgbuf->drvr->bus_if->dev,
120 msgbuf->rx_pktids, idx);
121 @@ -1148,6 +1152,20 @@ brcmf_msgbuf_process_rx_complete(struct
123 skb_trim(skb, buflen);
125 + if ((flags & BRCMF_MSGBUF_PKT_FLAGS_FRAME_MASK) ==
126 + BRCMF_MSGBUF_PKT_FLAGS_FRAME_802_11) {
127 + ifp = msgbuf->drvr->mon_if;
130 + brcmf_err("Received unexpected monitor pkt\n");
131 + brcmu_pkt_buf_free_skb(skb);
135 + brcmf_netif_mon_rx(ifp, skb);
139 ifp = brcmf_get_ifp(msgbuf->drvr, rx_complete->msg.ifidx);
140 if (!ifp || !ifp->ndev) {
141 brcmf_err("Received pkt for invalid ifidx %d\n",