brcmfmac: detect firmware support for monitor interface
PATCH v4 1/3 brcmfmac: detect firmware support for monitor interface
From: Rafał Miłecki <[email protected]>
Many/most of firmwares support creating monitor interface but only the most recent ones explicitly /announce/ it using a "monitor" entry in the list of capabilities.
Check for that entry and store internally info about monitor mode support using a new feature flag. Once we sort out all details of handling monitor interface it will be used when reporting available interfaces to the cfg80211.
Later some fallback detecion method may be added for older firmwares. For now just stick to the "monitor" capability which should be 100% reliable.
---
V3: Patch added to the series
V4: Dropped fallback code as it was reported to be incorrect
Updated new feature flag description as preferred by Arend
--- drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.c | 1 + drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.h | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-)
drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.c +1 -0
@@ -48,6 +48,7 @@ static const struct brcmf_feat_fwcap brcmf_fwcap_map[] = { { BRCMF_FEAT_MBSS, "mbss" }, { BRCMF_FEAT_MCHAN, "mchan" }, { BRCMF_FEAT_P2P, "p2p" }, + { BRCMF_FEAT_MONITOR, "monitor" }, };#ifdef DEBUG
drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.h +3 -1
@@ -33,6 +33,7 @@* MFP: 802.11w Management Frame Protection. * GSCAN: enhanced scan offload feature. * FWSUP: Firmware supplicant. +* MONITOR: firmware can pass monitor packets to host. */ #define BRCMF_FEAT_LIST \ BRCMF_FEAT_DEF(MBSS) \
@@ -48,7 +49,8 @@ BRCMF_FEAT_DEF(WOWL_ARP_ND) \ BRCMF_FEAT_DEF(MFP) \ BRCMF_FEAT_DEF(GSCAN) \ - BRCMF_FEAT_DEF(FWSUP) + BRCMF_FEAT_DEF(FWSUP) \ + BRCMF_FEAT_DEF(MONITOR)/* * Quirks:
Signature · 1 line
2.13.7
PATCH v4 2/3 brcmfmac: detect firmware support for radiotap monitor frames
From: Rafał Miłecki <[email protected]>
Depending on used build-time options some firmwares may already include radiotap header in passed monitor frames. Add a new feature flag to store info about it. It's needed for proper handling of received frames before passing them up.
---
V4: Patch extracted out of:
[PATCH V3 2/2] brcmfmac: handle monitor mode marked msgbuf packets Added mapping for the "rtap" string as reported by Arend Updated new feature flag description as preferred by Arend
--- drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.c | 1 + drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.h | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-)
drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.c +1 -0
@@ -49,6 +49,7 @@ static const struct brcmf_feat_fwcap brcmf_fwcap_map[] = { { BRCMF_FEAT_MCHAN, "mchan" }, { BRCMF_FEAT_P2P, "p2p" }, { BRCMF_FEAT_MONITOR, "monitor" }, + { BRCMF_FEAT_MONITOR_FMT_RADIOTAP, "rtap" }, };#ifdef DEBUG
drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.h +3 -1
@@ -34,6 +34,7 @@* GSCAN: enhanced scan offload feature. * FWSUP: Firmware supplicant. * MONITOR: firmware can pass monitor packets to host. +* MONITOR_FMT_RADIOTAP: firmware provides monitor packets with radiotap header */ #define BRCMF_FEAT_LIST \ BRCMF_FEAT_DEF(MBSS) \
@@ -50,7 +51,8 @@ BRCMF_FEAT_DEF(MFP) \ BRCMF_FEAT_DEF(GSCAN) \ BRCMF_FEAT_DEF(FWSUP) \ - BRCMF_FEAT_DEF(MONITOR) + BRCMF_FEAT_DEF(MONITOR) \ + BRCMF_FEAT_DEF(MONITOR_FMT_RADIOTAP)/* * Quirks:
Signature · 1 line
2.13.7
Re: [PATCH V4 2/3] brcmfmac: detect firmware support for radiotap monitor frames
Quoted 9 lines · Rafa=C5=82 Mi=C5=82ecki <[email protected]> writes:
From: Rafa=C5=82 Mi=C5=82ecki <[email protected]>
Depending on used build-time options some firmwares may already include radiotap header in passed monitor frames. Add a new feature flag to store info about it. It's needed for proper handling of received frames before passing them up.
Signed-off-by Rafa=C5=82 Mi=C5=82ecki <[email protected]>Signed-off-by Arend van Spriel <[email protected]>
BTW, we now have Co-Developed-by:
https://www.kernel.org/doc/html/latest/process/submitting-patches.html#when=
-to-use-acked-by-cc-and-co-developed-by
But no need to change this patch, just a tip for the future. I assume this patchset is good to go and will apply it soon.
--=20
Kalle Valo
Re: [PATCH V4 2/3] brcmfmac: detect firmware support for radiotap monitor frames
Quoted 12 lines · Kalle Valo
Quoted 9 lines · Rafał Miłecki
From: Rafał Miłecki <[email protected]>
Depending on used build-time options some firmwares may already include radiotap header in passed monitor frames. Add a new feature flag to store info about it. It's needed for proper handling of received frames before passing them up.
Signed-off-by Rafał Miłecki <[email protected]>Signed-off-by Arend van Spriel <[email protected]>
Quoted 6 lines
BTW, we now have Co-Developed-by:
But no need to change this patch, just a tip for the future. I assume this patchset is good to go and will apply it soon.
Nice to know, thanks!
PATCH v4 3/3 brcmfmac: handle msgbuf packets marked with monitor mode flag
In reply to Rafał MiłeckiFrom: Rafał Miłecki <[email protected]>
New Broadcom firmwares mark monitor mode packets using a newly defined bit in the flags field. Use it to filter them out and pass to the monitor interface. These defines were found in bcmmsgbuf.h from SDK.
As not every firmware generates radiotap header this commit introduces BRCMF_FEAT_MONITOR_FMT_RADIOTAP flag. It has to be has based on firmware capabilities. If not present brcmf_netif_mon_rx() will assume packet is a raw 802.11 frame and will prepend it with an empty radiotap header.
This new code is limited to the msgbuf protocol at this point. Adding support for SDIO/USB devices will require some extra work (possibly a new firmware release).
---
V2: Use cpu_to_le16 when setting it_len
V3: Update TODO comments
Rename flag (after adding MONITOR)
Update commit message
V4: Added missing return; after brcmu_pkt_buf_free_skb() call
--- .../wireless/broadcom/brcm80211/brcmfmac/core.c | 25 ++++++++++++++++++++++ .../wireless/broadcom/brcm80211/brcmfmac/core.h | 2 ++ .../wireless/broadcom/brcm80211/brcmfmac/msgbuf.c | 18 ++++++++++++++++ 3 files changed, 45 insertions(+)
drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.c +25 -0
@@ -21,6 +21,7 @@#include <net/cfg80211.h> #include <net/rtnetlink.h> #include <net/addrconf.h> +#include <net/ieee80211_radiotap.h> #include <net/ipv6.h> #include <brcmu_utils.h> #include <brcmu_wifi.h>
@@ -404,6 +405,30 @@ void brcmf_netif_rx(struct brcmf_if *ifp, struct sk_buff *skb)netif_rx_ni (skb); } +void brcmf_netif_mon_rx (struct brcmf_if *ifp,struct sk_buff *skb) +{ +if (brcmf_feat_is_enabled (ifp,BRCMF_FEAT_MONITOR_FMT_RADIOTAP )) { +/* Do nothing */ + }else { +struct ieee80211_radiotap_header *radiotap; + +/* TODO: use RX status to fill some radiotap data */ + radiotap =skb_push (skb,sizeof (*radiotap)); +memset (radiotap,0 ,sizeof (*radiotap)); + radiotap->it_len =cpu_to_le16 (sizeof (*radiotap)); + +/* TODO: 4 bytes with receive status? */ + skb->len -=4 ; + } + + skb->dev = ifp->ndev; +skb_reset_mac_header (skb); + skb->pkt_type =PACKET_OTHERHOST ; + skb->protocol =htons (ETH_P_802_2 ); + +brcmf_netif_rx (ifp, skb); +} +static int brcmf_rx_hdrpull (struct brcmf_pub *drvr,struct sk_buff *skb,struct brcmf_if **ifp) {
drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.h +2 -0
@@ -121,6 +121,7 @@ struct brcmf_pub {struct brcmf_if *iflist[BRCMF_MAX_IFS ];s32 if2bss[BRCMF_MAX_IFS ]; +struct brcmf_if *mon_if;struct mutex proto_block;unsigned char proto_buf[BRCMF_DCMD_MAXLEN ];
@@ -216,6 +217,7 @@ void brcmf_txflowblock_if(struct brcmf_if *ifp, enum brcmf_netif_stop_reason reason, bool state);void brcmf_txfinalize (struct brcmf_if *ifp,struct sk_buff *txp,bool success);void brcmf_netif_rx (struct brcmf_if *ifp,struct sk_buff *skb); +void brcmf_netif_mon_rx (struct brcmf_if *ifp,struct sk_buff *skb);void brcmf_net_setcarrier (struct brcmf_if *ifp,bool on);int __init brcmf_core_init (void ); void __exit brcmf_core_exit(void);
drivers/net/wireless/broadcom/brcm80211/brcmfmac/msgbuf.c +18 -0
@@ -69,6 +69,8 @@#define BRCMF_MSGBUF_MAX_EVENTBUF_POST 8#define BRCMF_MSGBUF_PKT_FLAGS_FRAME_802_3 0x01 +#define BRCMF_MSGBUF_PKT_FLAGS_FRAME_802_11 0x02 +#define BRCMF_MSGBUF_PKT_FLAGS_FRAME_MASK 0x07#define BRCMF_MSGBUF_PKT_FLAGS_PRIO_SHIFT 5#define BRCMF_MSGBUF_TX_FLUSH_CNT1 32
@@ -1128,6 +1130,7 @@ brcmf_msgbuf_process_rx_complete(struct brcmf_msgbuf *msgbuf, void *buf)struct sk_buff *skb;u16 data_offset;u16 buflen; +u16 flags;u32 idx;struct brcmf_if *ifp;
@@ -1137,6 +1140,7 @@ brcmf_msgbuf_process_rx_complete(struct brcmf_msgbuf *msgbuf, void *buf) data_offset =le16_to_cpu (rx_complete->data_offset); buflen =le16_to_cpu (rx_complete->data_len); idx =le32_to_cpu (rx_complete->msg.request_id); + flags =le16_to_cpu (rx_complete->flags); skb =brcmf_msgbuf_get_pktid (msgbuf->drvr->bus_if->dev, msgbuf->rx_pktids, idx);
@@ -1150,6 +1154,20 @@ brcmf_msgbuf_process_rx_complete(struct brcmf_msgbuf *msgbuf, void *buf)skb_trim (skb, buflen); +if ((flags &BRCMF_MSGBUF_PKT_FLAGS_FRAME_MASK ) == +BRCMF_MSGBUF_PKT_FLAGS_FRAME_802_11 ) { + ifp = msgbuf->drvr->mon_if; + +if (!ifp) { +brcmf_err ("Received unexpected monitor pkt\n" ); +brcmu_pkt_buf_free_skb (skb); +return ; + } + +brcmf_netif_mon_rx (ifp, skb); +return ; + } + ifp =brcmf_get_ifp (msgbuf->drvr, rx_complete->msg.ifidx);if (!ifp || !ifp->ndev) { brcmf_err("Received pkt for invalid ifidx %d\n",
Signature · 1 line
2.13.7
Quoted 11 lines · Rafał Miłecki
From: Rafał Miłecki <[email protected]>
Many/most of firmwares support creating monitor interface but only the most recent ones explicitly /announce/ it using a "monitor" entry in the list of capabilities.
Check for that entry and store internally info about monitor mode support using a new feature flag. Once we sort out all details of handling monitor interface it will be used when reporting available interfaces to the cfg80211.
Quoted 6 lines
Later some fallback detecion method may be added for older firmwares. For now just stick to the "monitor" capability which should be 100% reliable.
Signed-off-by Rafał Miłecki <[email protected]>Acked-by Arend van Spriel <[email protected]>
3 patches applied to wireless-drivers-next.git, thanks.
01f69dfafdbe brcmfmac: detect firmware support for monitor interface e63410ac65e0 brcmfmac: detect firmware support for radiotap monitor frames a8d7631858af brcmfmac: handle msgbuf packets marked with monitor mode flag
Signature · 3 lines
https://patchwork.kernel.org/patch/10484843/ https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches