332-v4.19-0003-brcmfmac-handle-msgbuf-packets-marked-with-monitor-m.patch 4.9 KB

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