58f9e9c923f360df7001ec103ef11aba1356728c
[openwrt/staging/pepe2k.git] /
1 From e665988be29ccea3584528967b432a5cfd801ca4 Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <rafal@milecki.pl>
3 Date: Fri, 8 Feb 2019 07:42:30 +0100
4 Subject: [PATCH] brcmfmac: support monitor frames with the hardware/ucode
5 header
6 MIME-Version: 1.0
7 Content-Type: text/plain; charset=UTF-8
8 Content-Transfer-Encoding: 8bit
9
10 So far there were two monitor frame formats:
11 1) 802.11 frames (with frame (sub)type & all addresses)
12 2) 802.11 frames with the radiotap header
13
14 Testing the latest FullMAC firmwares for 4366b1/4366c0 resulted in
15 discovering a new format being used. It seems (almost?) identical to the
16 one known from ucode used in SoftMAC devices which is most likely the
17 same codebase anyway.
18
19 While new firmwares will /announce/ radiotap header support using the
20 "rtap" fw capability string it seems no string was added for the new
21 ucode header format.
22
23 All above means that:
24 1) We need new format support when dealing with a received frame
25 2) A new feature bit & mapping quirks have to be added manually
26
27 As for now only an empty radiotap is being created. Adding support for
28 extracting some info (band, channel, signal, etc.) is planned for the
29 future.
30
31 Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
32 Acked-by: Arend van Spriel <arend.vanspriel@broadcom.com>
33 Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
34 ---
35 .../broadcom/brcm80211/brcmfmac/core.c | 55 +++++++++++++++++++
36 .../broadcom/brcm80211/brcmfmac/feature.c | 4 ++
37 .../broadcom/brcm80211/brcmfmac/feature.h | 4 +-
38 3 files changed, 62 insertions(+), 1 deletion(-)
39
40 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.c
41 +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.c
42 @@ -43,6 +43,36 @@
43
44 #define BRCMF_BSSIDX_INVALID -1
45
46 +#define RXS_PBPRES BIT(2)
47 +
48 +#define D11_PHY_HDR_LEN 6
49 +
50 +struct d11rxhdr_le {
51 + __le16 RxFrameSize;
52 + u16 PAD;
53 + __le16 PhyRxStatus_0;
54 + __le16 PhyRxStatus_1;
55 + __le16 PhyRxStatus_2;
56 + __le16 PhyRxStatus_3;
57 + __le16 PhyRxStatus_4;
58 + __le16 PhyRxStatus_5;
59 + __le16 RxStatus1;
60 + __le16 RxStatus2;
61 + __le16 RxTSFTime;
62 + __le16 RxChan;
63 + u8 unknown[12];
64 +} __packed;
65 +
66 +struct wlc_d11rxhdr {
67 + struct d11rxhdr_le rxhdr;
68 + __le32 tsf_l;
69 + s8 rssi;
70 + s8 rxpwr0;
71 + s8 rxpwr1;
72 + s8 do_rssi_ma;
73 + s8 rxpwr[4];
74 +} __packed;
75 +
76 char *brcmf_ifname(struct brcmf_if *ifp)
77 {
78 if (!ifp)
79 @@ -372,6 +402,35 @@ void brcmf_netif_mon_rx(struct brcmf_if
80 {
81 if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MONITOR_FMT_RADIOTAP)) {
82 /* Do nothing */
83 + } else if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MONITOR_FMT_HW_RX_HDR)) {
84 + struct wlc_d11rxhdr *wlc_rxhdr = (struct wlc_d11rxhdr *)skb->data;
85 + struct ieee80211_radiotap_header *radiotap;
86 + unsigned int offset;
87 + u16 RxStatus1;
88 +
89 + RxStatus1 = le16_to_cpu(wlc_rxhdr->rxhdr.RxStatus1);
90 +
91 + offset = sizeof(struct wlc_d11rxhdr);
92 + /* MAC inserts 2 pad bytes for a4 headers or QoS or A-MSDU
93 + * subframes
94 + */
95 + if (RxStatus1 & RXS_PBPRES)
96 + offset += 2;
97 + offset += D11_PHY_HDR_LEN;
98 +
99 + skb_pull(skb, offset);
100 +
101 + /* TODO: use RX header to fill some radiotap data */
102 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 13, 0)
103 + radiotap = skb_push(skb, sizeof(*radiotap));
104 +#else
105 + radiotap = (struct ieee80211_radiotap_header *)skb_push(skb, sizeof(*radiotap));
106 +#endif
107 + memset(radiotap, 0, sizeof(*radiotap));
108 + radiotap->it_len = cpu_to_le16(sizeof(*radiotap));
109 +
110 + /* TODO: 4 bytes with receive status? */
111 + skb->len -= 4;
112 } else {
113 struct ieee80211_radiotap_header *radiotap;
114
115 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.c
116 +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.c
117 @@ -102,6 +102,10 @@ static const struct brcmf_feat_fwfeat br
118 { "01-6cb8e269", BIT(BRCMF_FEAT_MONITOR) },
119 /* brcmfmac4366b-pcie.bin from linux-firmware.git commit 52442afee990 */
120 { "01-c47a91a4", BIT(BRCMF_FEAT_MONITOR) },
121 + /* brcmfmac4366b-pcie.bin from linux-firmware.git commit 211de1679a68 */
122 + { "01-801fb449", BIT(BRCMF_FEAT_MONITOR_FMT_HW_RX_HDR) },
123 + /* brcmfmac4366c-pcie.bin from linux-firmware.git commit 211de1679a68 */
124 + { "01-d2cbb8fd", BIT(BRCMF_FEAT_MONITOR_FMT_HW_RX_HDR) },
125 };
126
127 static void brcmf_feat_firmware_overrides(struct brcmf_pub *drv)
128 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.h
129 +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.h
130 @@ -33,6 +33,7 @@
131 * MFP: 802.11w Management Frame Protection.
132 * MONITOR: firmware can pass monitor packets to host.
133 * MONITOR_FMT_RADIOTAP: firmware provides monitor packets with radiotap header
134 + * MONITOR_FMT_HW_RX_HDR: firmware provides monitor packets with hw/ucode header
135 */
136 #define BRCMF_FEAT_LIST \
137 BRCMF_FEAT_DEF(MBSS) \
138 @@ -48,7 +49,8 @@
139 BRCMF_FEAT_DEF(WOWL_ARP_ND) \
140 BRCMF_FEAT_DEF(MFP) \
141 BRCMF_FEAT_DEF(MONITOR) \
142 - BRCMF_FEAT_DEF(MONITOR_FMT_RADIOTAP)
143 + BRCMF_FEAT_DEF(MONITOR_FMT_RADIOTAP) \
144 + BRCMF_FEAT_DEF(MONITOR_FMT_HW_RX_HDR)
145
146 /*
147 * Quirks: