c93bcf0ce91333f5c1adb67d1f4b81396acb12ea
[openwrt/openwrt.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 @@ -409,6 +439,31 @@ 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 + radiotap = skb_push(skb, sizeof(*radiotap));
103 + memset(radiotap, 0, sizeof(*radiotap));
104 + radiotap->it_len = cpu_to_le16(sizeof(*radiotap));
105 +
106 + /* TODO: 4 bytes with receive status? */
107 + skb->len -= 4;
108 } else {
109 struct ieee80211_radiotap_header *radiotap;
110
111 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.c
112 +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.c
113 @@ -103,6 +103,10 @@ static const struct brcmf_feat_fwfeat br
114 { "01-6cb8e269", BIT(BRCMF_FEAT_MONITOR) },
115 /* brcmfmac4366b-pcie.bin from linux-firmware.git commit 52442afee990 */
116 { "01-c47a91a4", BIT(BRCMF_FEAT_MONITOR) },
117 + /* brcmfmac4366b-pcie.bin from linux-firmware.git commit 211de1679a68 */
118 + { "01-801fb449", BIT(BRCMF_FEAT_MONITOR_FMT_HW_RX_HDR) },
119 + /* brcmfmac4366c-pcie.bin from linux-firmware.git commit 211de1679a68 */
120 + { "01-d2cbb8fd", BIT(BRCMF_FEAT_MONITOR_FMT_HW_RX_HDR) },
121 };
122
123 static void brcmf_feat_firmware_overrides(struct brcmf_pub *drv)
124 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.h
125 +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.h
126 @@ -35,6 +35,7 @@
127 * FWSUP: Firmware supplicant.
128 * MONITOR: firmware can pass monitor packets to host.
129 * MONITOR_FMT_RADIOTAP: firmware provides monitor packets with radiotap header
130 + * MONITOR_FMT_HW_RX_HDR: firmware provides monitor packets with hw/ucode header
131 */
132 #define BRCMF_FEAT_LIST \
133 BRCMF_FEAT_DEF(MBSS) \
134 @@ -52,7 +53,8 @@
135 BRCMF_FEAT_DEF(GSCAN) \
136 BRCMF_FEAT_DEF(FWSUP) \
137 BRCMF_FEAT_DEF(MONITOR) \
138 - BRCMF_FEAT_DEF(MONITOR_FMT_RADIOTAP)
139 + BRCMF_FEAT_DEF(MONITOR_FMT_RADIOTAP) \
140 + BRCMF_FEAT_DEF(MONITOR_FMT_HW_RX_HDR)
141
142 /*
143 * Quirks: