wifi: brcmfmac: AWDL for AirDrop on Apple T2 Macs
v3 cover wifi: brcmfmac: AWDL for AirDrop on Apple T2 Macs
This series adds AWDL support to brcmfmac, so Linux on the Apple T2 Macs can send and receive files over AirDrop with Apple and latest Google or Samsung devices.
On these Macs the Apple firmware runs AWDL itself. The host creates an AWDL interface and sets its parameters, the firmware keeps the AWDL schedule and carries the AWDL frames and data. Election, peer discovery and AirDrop run in user space, which talks to the driver through vendor commands and events of the Broadcom OUI. As discussed on v1, vendor commands are the exception agreed for AWDL, so the vendor header becomes ABI with this series.
The user space side is t2-drop, published under GPL license
https://github.com/kaiT2en/KaiT2en-Fedora/tree/main/apps/t2-drop
Tested on a MacBookPro15,1 (BCM4364, firmware 9.30.514.0.32.5.94) with a MacBook Air M4 as peer. AirDrop in both directions with varying file sizes up to 2GB.
v2 runs on the BCM4364 and BCM4377 machines of the T2 Linux community.
Changes in v3:
- awdl.c and awdl.h are ISC
- Patch 3: keep the abandoned AWDL interface until its late event is claimed, and take an interface event that arrives right after the timeout instead of failing
- Patch 5: remove an AWDL interface the firmware removed on its own from a work item with RTNL and the wiphy mutex. Then send AWDL_STOPPED. Answer a START dropped before system sleep with -ECANCELED. Document that SET_SYNC fails with -EBADE while the firmware does not know a new master yet
- All patches except 3 and 5 are acknowledged by Arend
Changes in v2:
- Drop v1 patch 1, wireless-next matches the firmware capabilities as whole words already
- Rebase on wireless-next, patches 1, 2 and 4 have Arend's Ack
- Patch 3: remove an AWDL interface that shows up after the interface event timed out, tie the network device to the wiphy device in sysfs and keep its name, keep the AWDL address out of the ARP offload table of the primary interface, kernel-doc for the return values
- Patch 4: add the AWDL header in brcmf_netdev_start_xmit(), so tx and rx count the bytes of the Ethernet frame, kernel-doc. The MTU stays at 1500, the firmware takes full size frames with the added header
- Patch 5: document where the parameter tables come from and the firmware versions they are used with, fail AWDL_START when awdl, awdl_config or slot_bss are rejected, return firmware errors from SET_FRAMES and SET_SYNC, a quirk in feature.c instead of the chip check, reject AWDL_STOP while a start is queued, AWDL_STOPPED with -ENOLINK when the firmware removes the interface, UNSPEC first in the vendor events
- Patch 6: abstract event codes for the AWDL events, mapped and registered by the WCC vendor module, log dropped events
v2: https://lore.kernel.org/all/[email protected]/
v1: https://lore.kernel.org/all/[email protected]/
Andre Eikmeyer (6):
wifi: brcmfmac: move the interface_create definitions to fwil_types.h
wifi: brcmfmac: detect AWDL support of the firmware
wifi: brcmfmac: create and remove the AWDL interface
wifi: brcmfmac: add the AWDL data path
wifi: brcmfmac: add vendor commands for AWDL
wifi: brcmfmac: pass AWDL frames and role changes to user space
.../broadcom/brcm80211/brcmfmac/Makefile | 3 +- .../broadcom/brcm80211/brcmfmac/awdl.c | 1163 +++++++++++++++++ .../broadcom/brcm80211/brcmfmac/awdl.h | 123 ++ .../broadcom/brcm80211/brcmfmac/cfg80211.c | 49 +- .../broadcom/brcm80211/brcmfmac/core.c | 82 +- .../broadcom/brcm80211/brcmfmac/core.h | 7 + .../broadcom/brcm80211/brcmfmac/feature.c | 32 + .../broadcom/brcm80211/brcmfmac/feature.h | 8 +- .../broadcom/brcm80211/brcmfmac/fweh.c | 19 + .../broadcom/brcm80211/brcmfmac/fweh.h | 7 +- .../broadcom/brcm80211/brcmfmac/fwil_types.h | 46 + .../broadcom/brcm80211/brcmfmac/vendor.c | 90 ++ .../broadcom/brcm80211/brcmfmac/vendor.h | 109 ++ .../broadcom/brcm80211/brcmfmac/wcc/core.c | 39 + 14 files changed, 1723 insertions(+), 54 deletions(-) create mode 100644 drivers/net/wireless/broadcom/brcm80211/brcmfmac/awdl.c create mode 100644 drivers/net/wireless/broadcom/brcm80211/brcmfmac/awdl.h
base-commit: 18d0bedbb5f0538396cb7f763ed9cd1dd69c5b23
Signature · 1 line
2.56.0
PATCH v3 3/6 wifi: brcmfmac: create and remove the AWDL interface
Firmware with AWDL support creates an interface of type AWDL with interface_create. The host gives the MAC address, the firmware interface index 2 and the AWDL BSSID 00:25:00:ff:94:73.
The AWDL interface has no cfg80211 vif. Add brcmf_awdl_add() and brcmf_awdl_del(), called with RTNL and the wiphy mutex held, which create and remove it together with a network device "awdl%d". Its interface events complete a wait in these functions instead of going to the cfg80211 handler, and brcmf_net_attach() and brcmf_net_detach() register the network device outside cfg80211.
Like an AP, the AWDL interface gives every peer its own flowrings. It is removed in the cfg80211 suspend callback while the firmware still takes commands.
--- .../broadcom/brcm80211/brcmfmac/Makefile | 3 +- .../broadcom/brcm80211/brcmfmac/awdl.c | 292 ++++++++++++++++++ .../broadcom/brcm80211/brcmfmac/awdl.h | 53 ++++ .../broadcom/brcm80211/brcmfmac/cfg80211.c | 6 + .../broadcom/brcm80211/brcmfmac/core.c | 65 +++- .../broadcom/brcm80211/brcmfmac/core.h | 7 + .../broadcom/brcm80211/brcmfmac/fweh.c | 17 + 7 files changed, 434 insertions(+), 9 deletions(-) create mode 100644 drivers/net/wireless/broadcom/brcm80211/brcmfmac/awdl.c create mode 100644 drivers/net/wireless/broadcom/brcm80211/brcmfmac/awdl.h
drivers/net/wireless/broadcom/brcm80211/brcmfmac/Makefile +2 -1
@@ -26,7 +26,8 @@ brcmfmac-objs += \ vendor.o \ pno.o \ scan_param.o \ - xtlv.o + xtlv.o \ + awdl.o brcmfmac-$(CONFIG_BRCMFMAC_PROTO_BCDC) += \ bcdc.o \ fwsignal.o
drivers/net/wireless/broadcom/brcm80211/brcmfmac/awdl.c new file +292 -0
292 lines not on this page · raw message
drivers/net/wireless/broadcom/brcm80211/brcmfmac/awdl.h new file +53 -0
53 lines not on this page · raw message
drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c +6 -0
@@ -4243,6 +4243,12 @@ static s32 brcmf_cfg80211_suspend(struct wiphy *wiphy,brcmf_dbg (TRACE ,"Enter\n" ); +/* The AWDL interface does not survive sleep, the firmware still +* takes commands here. User space creates it again after resume. +*/ +if (cfg->pub->awdl.ifp) +brcmf_awdl_del (cfg->pub); +/* if the primary net_device is not READY there is nothing * we can do but pray resume goes smoothly. */
drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.c +57 -8
123 lines not on this page · raw message
drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.h +7 -0
@@ -12,6 +12,7 @@#include <net/cfg80211.h> #include "fweh.h" +#include "awdl.h" #if IS_MODULE (CONFIG_BRCMFMAC )#define BRCMF_EXPORT_SYMBOL_GPL (__sym) EXPORT_SYMBOL_NS_GPL(__sym, "BRCMFMAC")
@@ -25,6 +26,8 @@/* For supporting multiple interfaces */ #define BRCMF_MAX_IFS 16 +#define BRCMF_BSSIDX_INVALID -1 +/* Small, medium and maximum buffer size for dcmd */ #define BRCMF_DCMD_SMLEN 256
@@ -163,6 +166,8 @@ struct brcmf_pub {void *vdata;struct scan_param_struct_handler scan_param_handler;u16 join_version; + +struct brcmf_awdl awdl; };/* forward declarations */
@@ -202,6 +207,7 @@ enum brcmf_netif_stop_reason {* @pend_8021x_cnt: tracks outstanding number of 802.1x frames. * @pend_8021x_wait: used for signalling change in count. * @fwil_fwerr: flag indicating fwil layer should return firmware error codes. +* @awdl: this is the AWDL interface, it has no cfg80211 vif. */ struct brcmf_if {struct brcmf_pub *drvr;
@@ -220,6 +226,7 @@ struct brcmf_if {struct in6_addr ipv6_addr_tbl[NDOL_MAX_ENTRIES ];u8 ipv6addr_idx;bool fwil_fwerr; +bool awdl; };int brcmf_netdev_wait_pend8021x (struct brcmf_if *ifp);
drivers/net/wireless/broadcom/brcm80211/brcmfmac/fweh.c +17 -0
@@ -172,6 +172,9 @@ static void brcmf_fweh_handle_if_event(struct brcmf_pub *drvr,return ;if (!is_p2pdev)brcmf_proto_add_if (drvr, ifp); +/* The AWDL interface is attached by brcmf_awdl_add() */ +if (brcmf_awdl_if_added (drvr, ifp)) +return ;if (!drvr->fweh->evt_handler[BRCMF_E_IF ])if (brcmf_net_attach (ifp, false) <0 )return ;
@@ -180,6 +183,14 @@ static void brcmf_fweh_handle_if_event(struct brcmf_pub *drvr,if (ifp && ifevent->action ==BRCMF_E_IF_CHANGE )brcmf_proto_reset_if (drvr, ifp); +/* The AWDL interface has no vif, cfg80211 does not know it */ +if (ifp && ifp->awdl) { +if (ifevent->action ==BRCMF_E_IF_DEL && + !brcmf_awdl_if_removed (drvr, ifp)) +brcmf_remove_interface (ifp, false); +return ; + } +brcmf_fweh_call_event_handler (drvr, ifp, emsg->event_code, emsg, data);
@@ -315,6 +326,12 @@ static void brcmf_fweh_event_worker(struct work_struct *work) ifp = drvr->iflist[0 ]; else ifp = drvr->iflist[emsg.bsscfgidx]; +/* The AWDL interface has no vif, its events are not for +* the cfg80211 handlers +*/ +if (ifp && ifp->awdl) + goto event_free; + err =brcmf_fweh_call_event_handler (drvr, ifp, event->code, &emsg, event->data);if (err) {
Signature · 1 line
2.56.0
PATCH v3 1/6 wifi: brcmfmac: move the interface_create definitions to fwil_types.h
In reply to Andre EikmeyerThe interface_create iovar structures and flags are firmware interface types like the others in fwil_types.h. Move them there so code outside cfg80211.c can create firmware interfaces as well.
--- .../broadcom/brcm80211/brcmfmac/cfg80211.c | 42 ------------------ .../broadcom/brcm80211/brcmfmac/fwil_types.h | 43 +++++++++++++++++++ 2 files changed, 43 insertions(+), 42 deletions(-)
drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c +0 -42
@@ -271,48 +271,6 @@ struct parsed_vndr_ies {struct parsed_vndr_ie_info ie_info[VNDR_IE_PARSE_LIMIT ]; }; -#define WL_INTERFACE_CREATE_VER_1 1 -#define WL_INTERFACE_CREATE_VER_2 2 -#define WL_INTERFACE_CREATE_VER_3 3 -#define WL_INTERFACE_CREATE_VER_MAX WL_INTERFACE_CREATE_VER_3 - -#define WL_INTERFACE_MAC_DONT_USE 0x0 -#define WL_INTERFACE_MAC_USE 0x2 - -#define WL_INTERFACE_CREATE_STA 0x0 -#define WL_INTERFACE_CREATE_AP 0x1 - -struct wl_interface_create_v1 { -u16 ver;/* structure version */ -u32 flags;/* flags for operation */ -u8 mac_addr[ETH_ALEN ];/* MAC address */ -u32 wlc_index;/* optional for wlc index */ -}; - -struct wl_interface_create_v2 { -u16 ver;/* structure version */ -u8 pad1[2 ]; -u32 flags;/* flags for operation */ -u8 mac_addr[ETH_ALEN ];/* MAC address */ -u8 iftype;/* type of interface created */ -u8 pad2; -u32 wlc_index;/* optional for wlc index */ -}; - -struct wl_interface_create_v3 { -u16 ver;/* structure version */ -u16 len;/* length of structure + data */ -u16 fixed_len;/* length of structure */ -u8 iftype;/* type of interface created */ -u8 wlc_index;/* optional for wlc index */ -u32 flags;/* flags for operation */ -u8 mac_addr[ETH_ALEN ];/* MAC address */ -u8 bssid[ETH_ALEN ];/* optional for BSSID */ -u8 if_index;/* interface index request */ -u8 pad[3 ]; -u8 data[];/* Optional for specific data */ -}; -static u8 nl80211_band_to_fwil (enum nl80211_band band) {switch (band) {
drivers/net/wireless/broadcom/brcm80211/brcmfmac/fwil_types.h +43 -0
47 lines not on this page · raw message
Signature · 1 line
2.56.0
PATCH v3 4/6 wifi: brcmfmac: add the AWDL data path
In reply to Andre EikmeyerThe firmware passes AWDL data frames as 802.3 frames. An LLC/SNAP header with the Apple OUI (aa aa 03 00 17 f2 08 00) is followed by the AWDL data header 03 04, a 16 bit sequence number, two reserved bytes and the ethertype.
Let the AWDL network device send and receive plain Ethernet frames. brcmf_netdev_start_xmit() adds the headers and brcmf_netif_rx() removes them, so both count Ethernet frames. The addresses of received frames are moved so that they form an Ethernet header with the ethertype again, which keeps packet taps consistent.
--- .../broadcom/brcm80211/brcmfmac/awdl.c | 87 +++++++++++++++++++ .../broadcom/brcm80211/brcmfmac/awdl.h | 9 ++ .../broadcom/brcm80211/brcmfmac/core.c | 17 ++++ 3 files changed, 113 insertions(+)
drivers/net/wireless/broadcom/brcm80211/brcmfmac/awdl.c +87 -0
@@ -8,11 +8,25 @@* an interface of type AWDL with interface_create and configures it through * the awdl_* iovars. The AWDL interface has a network device but no cfg80211 * vif. Its interface events are handled here and not by cfg80211. +* +* The firmware passes AWDL data frames as 802.3 frames with an LLC/SNAP +* header with the Apple OUI and an AWDL data header: +* +* aa aa 03 00 17 f2 08 00 LLC/SNAP, OUI 00:17:f2, protocol 0x0800 +* 03 04 AWDL data header +* seq (le16) 00 00 sequence number, reserved +* ethertype (be16) +* +* The network device of the AWDL interface sends and receives plain +* Ethernet frames. The header is added before frames are sent and removed +* from received frames. */ #include <linux/etherdevice.h> #include <linux/netdevice.h> #include <linux/rtnetlink.h> +#include <linux/skbuff.h> +#include <linux/unaligned.h> #include "core.h" #include "debug.h"
@@ -26,6 +40,14 @@#define BRCMF_AWDL_IFIDX 2#define BRCMF_AWDL_IF_TIMEOUT msecs_to_jiffies(2000) +/* LLC/SNAP with the Apple OUI and the start of the AWDL data header */ +static const u8 brcmf_awdl_llc[10 ] = { +0xaa ,0xaa ,0x03 ,0x00 ,0x17 ,0xf2 ,0x08 ,0x00 ,0x03 ,0x04 , +}; + +#define BRCMF_AWDL_SEQ_OFF 10 +#define BRCMF_AWDL_ETHERTYPE_OFF 14 +/* The BSSID of all AWDL frames */ static const u8 brcmf_awdl_bssid[ETH_ALEN ] = {0x00 ,0x25 ,0x00 ,0xff ,0x94 ,0x73 ,
@@ -276,6 +298,71 @@ int brcmf_awdl_del(struct brcmf_pub *drvr)return err; } +/** +* brcmf_awdl_encap() - add the AWDL data header to a frame to be sent. +* +* @ifp: the AWDL interface. +* @skb: Ethernet frame, an 802.3 frame on return. +* +* Called in the transmit path of the AWDL network device, which serializes +* it. +* +* Return: 0 or a negative error code, the caller frees @skb on error. +*/ +int brcmf_awdl_encap (struct brcmf_if *ifp,struct sk_buff *skb) +{ +struct brcmf_awdl *awdl = &ifp->drvr->awdl; +__be16 proto; +u8 *hdr; + +if (skb->len <ETH_HLEN ||skb_cow_head (skb,BRCMF_AWDL_HDR_LEN )) +return -EINVAL ; + + proto =eth_hdr (skb)->h_proto; + hdr =skb_push (skb,BRCMF_AWDL_HDR_LEN ); +memmove (hdr, hdr +BRCMF_AWDL_HDR_LEN ,2 *ETH_ALEN ); +put_unaligned_be16 (skb->len -ETH_HLEN , hdr +2 *ETH_ALEN ); + hdr +=ETH_HLEN ; +memcpy (hdr, brcmf_awdl_llc,sizeof (brcmf_awdl_llc)); +put_unaligned_le16 (awdl->tx_seq++, hdr +BRCMF_AWDL_SEQ_OFF ); +put_unaligned_le16 (0 , hdr +BRCMF_AWDL_SEQ_OFF +2 ); +put_unaligned (proto, (__be16 *)(hdr +BRCMF_AWDL_ETHERTYPE_OFF )); +skb_reset_mac_header (skb); +return 0 ; +} + +/** +* brcmf_awdl_decap() - remove the AWDL data header from a received frame. +* +* @skb: frame after eth_type_trans(), an Ethernet frame on return. +* +* The addresses are moved behind the AWDL data header, where they form an +* Ethernet header with the ethertype of the AWDL data header. +* +* Return: 0 or a negative error code for frames that are not AWDL data +* frames. +*/ +int brcmf_awdl_decap (struct sk_buff *skb) +{ +__be16 proto; +u8 *eth; + +if (skb->protocol !=htons (ETH_P_802_2 ) || + !pskb_may_pull (skb,BRCMF_AWDL_HDR_LEN ) || +memcmp (skb->data, brcmf_awdl_llc,sizeof (brcmf_awdl_llc)) || +skb_cow_head (skb,0 )) +return -EINVAL ; + + proto =get_unaligned ((__be16 *)(skb->data +BRCMF_AWDL_ETHERTYPE_OFF )); + eth = skb->data +BRCMF_AWDL_HDR_LEN -ETH_HLEN ; +memmove (eth,skb_mac_header (skb),2 *ETH_ALEN ); +skb_pull_rcsum (skb,BRCMF_AWDL_HDR_LEN ); +skb_set_mac_header (skb, -ETH_HLEN ); +skb_reset_network_header (skb); + skb->protocol = proto; +return 0 ; +} +/* Called before the interfaces of the device are removed */ void brcmf_awdl_detach (struct brcmf_pub *drvr) {
drivers/net/wireless/broadcom/brcm80211/brcmfmac/awdl.h +9 -0
@@ -13,6 +13,8 @@struct brcmf_pub ;struct brcmf_if ; +struct net_device ; +struct sk_buff ;/** * struct brcmf_awdl - AWDL interface of a device.
@@ -29,6 +31,7 @@ struct brcmf_if;* @removing: interface_remove was sent, its interface event is awaited. * @detached: the device goes away, no new AWDL interface is created. * @ifp: the AWDL interface, NULL when there is none. +* @tx_seq: sequence number of the next data frame sent. */ struct brcmf_awdl {spinlock_t lock;/* AWDL state against the event worker */
@@ -40,8 +43,12 @@ struct brcmf_awdl {bool removing;bool detached;struct brcmf_if *ifp; +u16 tx_seq; }; +/* Length of the LLC/SNAP and AWDL data header of AWDL data frames */ +#define BRCMF_AWDL_HDR_LEN 16 +void brcmf_awdl_attach (struct brcmf_pub *drvr);void brcmf_awdl_detach (struct brcmf_pub *drvr); int brcmf_awdl_add(struct brcmf_pub *drvr, const u8 *mac,
@@ -49,5 +56,7 @@ int brcmf_awdl_add(struct brcmf_pub *drvr, const u8 *mac,int brcmf_awdl_del (struct brcmf_pub *drvr);bool brcmf_awdl_if_added (struct brcmf_pub *drvr,struct brcmf_if *ifp);bool brcmf_awdl_if_removed (struct brcmf_pub *drvr,struct brcmf_if *ifp); +int brcmf_awdl_encap (struct brcmf_if *ifp,struct sk_buff *skb); +int brcmf_awdl_decap (struct sk_buff *skb);#endif /* BRCMFMAC_AWDL_H */
drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.c +17 -0
@@ -309,6 +309,15 @@ static netdev_tx_t brcmf_netdev_start_xmit(struct sk_buff *skb, goto done; } +/* tx_bytes counts the Ethernet frame, the AWDL header is added here */ +if (ifp->awdl) { + ret =brcmf_awdl_encap (ifp, skb); +if (ret) { +dev_kfree_skb (skb); + goto done; + } + } +/* Some recent Broadcom's firmwares disassociate STA when they receive * an 802.11f ADD frame. This behavior can lead to a local DoS security * issue. Attacker may trigger disassociation of any STA by sending a
@@ -422,6 +431,12 @@ void brcmf_netif_rx(struct brcmf_if *ifp, struct sk_buff *skb)return ; } +if (ifp->awdl &&brcmf_awdl_decap (skb)) { + ifp->ndev->stats.rx_dropped++; +brcmu_pkt_buf_free_skb (skb); +return ; + } + ifp->ndev->stats.rx_bytes += skb->len; ifp->ndev->stats.rx_packets++;
@@ -693,6 +708,8 @@ int brcmf_net_attach(struct brcmf_if *ifp, bool locked) ndev->netdev_ops = &brcmf_netdev_ops_pri; ndev->needed_headroom += drvr->hdrlen; +if (ifp->awdl) + ndev->needed_headroom +=BRCMF_AWDL_HDR_LEN ; ndev->ethtool_ops = &brcmf_ethtool_ops;/* set the mac address & netns */
Signature · 1 line
2.56.0
PATCH v3 2/6 wifi: brcmfmac: detect AWDL support of the firmware
In reply to Andre EikmeyerThe Apple firmware of the BCM4364 and BCM4377 runs Apple Wireless Direct Link (AWDL) itself and announces it with "awdl" in its capabilities. Add the feature flag for it.
An AWDL interface is created with interface_create version 3 and interface type 2. The host gives the MAC address, the interface index and the BSSID, which the flags 0x2, 0x8 and 0x10 select. Add the definitions for the interface type and the two new flags.
The BCM4350 firmware 7.35.180.133 lists "awdl" as well and answers every interface_create, including the version query, with BCME_UNSUPPORTED. Keep the flag only when the firmware reports interface_create version 3.
--- .../broadcom/brcm80211/brcmfmac/feature.c | 26 +++++++++++++++++++ .../broadcom/brcm80211/brcmfmac/feature.h | 3 ++- .../broadcom/brcm80211/brcmfmac/fwil_types.h | 3 +++ 3 files changed, 31 insertions(+), 1 deletion(-)
drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.c +26 -0
@@ -49,6 +49,7 @@ static const struct brcmf_feat_fwcap brcmf_fwcap_map[] = { { BRCMF_FEAT_SAE_EXT, "sae_ext" }, { BRCMF_FEAT_FBT, "fbt" }, { BRCMF_FEAT_OKC, "okc" }, + { BRCMF_FEAT_AWDL, "awdl" }, };#ifdef DEBUG
@@ -391,6 +392,29 @@ static int brcmf_feat_fwcap_debugfs_read(struct seq_file *seq, void *data)return 0 ; } +/** +* brcmf_feat_awdl_check() - keep AWDL only with interface_create version 3. +* +* @ifp: interface to query. +* +* The AWDL interface is created with interface_create version 3. The +* BCM4350 firmware 7.35.180.133 lists "awdl" but answers every +* interface_create with BCME_UNSUPPORTED. +*/ +static void brcmf_feat_awdl_check (struct brcmf_if *ifp) +{ +u32 ver =0 ; +s32 err; + + err =brcmf_fil_bsscfg_int_query (ifp,"interface_create" , &ver); +if (!err && ver ==WL_INTERFACE_CREATE_VER_3 ) +return ; + +brcmf_dbg (INFO ,"disabling AWDL, interface_create version %u (%d)\n" , + ver, err); + ifp->drvr->feat_flags &= ~BIT (BRCMF_FEAT_AWDL ); +} +void brcmf_feat_attach (struct brcmf_pub *drvr) {struct brcmf_if *ifp =brcmf_get_ifp (drvr,0 );
@@ -400,6 +424,8 @@ void brcmf_feat_attach(struct brcmf_pub *drvr)s32 err;brcmf_feat_firmware_capabilities (ifp); +if (brcmf_feat_is_enabled (ifp,BRCMF_FEAT_AWDL )) +brcmf_feat_awdl_check (ifp);memset (&gscan_cfg,0 ,sizeof (gscan_cfg)); if (drvr->bus_if->chip != BRCM_CC_43430_CHIP_ID && drvr->bus_if->chip != BRCM_CC_4345_CHIP_ID &&
drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.h +2 -1
@@ -63,7 +63,8 @@ BRCMF_FEAT_DEF(EVENT_MSGS_EXT) \ BRCMF_FEAT_DEF(SAE_EXT) \ BRCMF_FEAT_DEF(FBT) \ - BRCMF_FEAT_DEF(OKC) + BRCMF_FEAT_DEF(OKC) \ + BRCMF_FEAT_DEF(AWDL)/* * Quirks:
drivers/net/wireless/broadcom/brcm80211/brcmfmac/fwil_types.h +3 -0
@@ -1383,9 +1383,12 @@ struct brcmf_eventmsgs_ext_le {#define WL_INTERFACE_MAC_DONT_USE 0x0#define WL_INTERFACE_MAC_USE 0x2 +#define WL_INTERFACE_IF_INDEX_USE 0x8 +#define WL_INTERFACE_BSSID_USE 0x10#define WL_INTERFACE_CREATE_STA 0x0#define WL_INTERFACE_CREATE_AP 0x1 +#define WL_INTERFACE_CREATE_AWDL 0x2struct wl_interface_create_v1 {u16 ver;/* structure version */
Signature · 1 line
2.56.0
PATCH v3 5/6 wifi: brcmfmac: add vendor commands for AWDL
In reply to Andre EikmeyerAWDL election, peer discovery and services run in user space, the firmware carries the AWDL frames and data. Add vendor commands of the Broadcom OUI on the primary interface, described in vendor.h:
- AWDL_START and AWDL_STOP create and remove the AWDL interface. They need RTNL, so they run in a work item and report their result with the vendor events AWDL_STARTED and AWDL_STOPPED.
- AWDL_SET_FRAMES and AWDL_SET_SYNC set the TLVs the firmware sends and the master to synchronize to.
- AWDL_PEER_ADD and AWDL_PEER_DEL add and remove the peers data frames go to.
The driver sets the other AWDL parameters in the order and with the values macOS 15.4.1 sets on a MacBookAir9,1. awdl_opmode fails while the firmware does not know a new master yet, so every refresh sends the frames and the synchronization state, and SET_FRAMES and SET_SYNC report only the errors of their own part. The BCM4364 firmware traps with the SDB form of slot_bss while the station is on 5 GHz, the new quirk AWDL_NO_SDB selects the other form.
When the firmware removes the AWDL interface on its own, a work item removes it on the host with RTNL and the wiphy mutex held and then sends AWDL_STOPPED.
--- .../broadcom/brcm80211/brcmfmac/awdl.c | 726 +++++++++++++++++- .../broadcom/brcm80211/brcmfmac/awdl.h | 64 +- .../broadcom/brcm80211/brcmfmac/cfg80211.c | 5 +- .../broadcom/brcm80211/brcmfmac/feature.c | 6 + .../broadcom/brcm80211/brcmfmac/feature.h | 5 +- .../broadcom/brcm80211/brcmfmac/vendor.c | 82 ++ .../broadcom/brcm80211/brcmfmac/vendor.h | 97 +++ 7 files changed, 959 insertions(+), 26 deletions(-)
drivers/net/wireless/broadcom/brcm80211/brcmfmac/awdl.c +706 -20
@@ -27,13 +27,17 @@#include <linux/rtnetlink.h> #include <linux/skbuff.h> #include <linux/unaligned.h> +#include <net/netlink.h> #include "core.h" #include "debug.h" #include "feature.h" #include "fwil.h" #include "fwil_types.h" +#include "bus.h" #include "proto.h" +#include "cfg80211.h" +#include "vendor.h" #include "awdl.h" /* The firmware interface index of the AWDL interface */
@@ -53,10 +57,128 @@ static const u8 brcmf_awdl_bssid[ETH_ALEN] = { 0x00, 0x25, 0x00, 0xff, 0x94, 0x73, }; +/* +* Firmware parameters the host sets for AWDL. The tables below and the +* offsets patched into them, in awdl_election_tree, awdl_opmode, slot_bss +* and awdl_peer_op, are copied from an iovar trace of macOS 15.4.1 on a +* MacBookAir9,1. They are not documented otherwise, their fields are not +* known beyond what the comments say. They are used with the firmware +* 9.30.514.0.32.5.94 of the BCM4364 and 16.20.380.0.3.6.130 of the BCM4377. +*/ +#define BRCMF_AWDL_CONFIG_START 0x83 +#define BRCMF_AWDL_CONFIG_SETTLED 0x73 +#define BRCMF_AWDL_PRESENCEMODE 4 +#define BRCMF_AWDL_OSOC_CHAN 44 +#define BRCMF_AWDL_AFTX_DELAY msecs_to_jiffies(500) +#define BRCMF_AWDL_SETTLE_DELAY msecs_to_jiffies(5000) +#define BRCMF_AWDL_TLV_MAX 2048 + +static const u8 brcmf_awdl_sync_params[] = { +0x00 ,0x24 ,0x00 ,0x00 ,0x00 ,0x00 ,0x06 ,0x00 , +0x10 ,0x00 ,0x6e ,0x00 ,0x00 ,0x00 ,0x10 ,0x00 , +0x10 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 , +0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 , +0x00 ,0x00 ,0x00 ,0x00 , +}; + +static const u8 brcmf_awdl_psf_dwell[] = { +0x00 ,0x00 ,0x00 ,0x00 ,0x6e ,0x00 ,0x6e ,0x00 , +}; + +/* Header of awdl_oob_af_auto, the AWDL BSSID at 8, then the TLV length */ +static const u8 brcmf_awdl_oob_hdr[] = { +0xff ,0xff ,0xff ,0xff ,0xd8 ,0x40 ,0x00 ,0x00 , +0x00 ,0x25 ,0x00 ,0xff ,0x94 ,0x73 ,0xff ,0xff , +0xff ,0xff ,0xff ,0xff ,0x00 ,0x00 ,0x00 ,0x00 , +0x00 ,0x00 ,0x00 ,0x00 ,0x06 ,0x00 ,0x00 ,0x00 , +0x00 ,0x00 ,0x00 ,0x00 ,0x0c ,0x00 ,0x00 ,0x00 , +0x00 ,0x00 ,0x00 ,0x00 , +}; + +/* awdl_opmode: byte 1 the role, 2 master and 0 slave, 4 to 9 the master */ +#define BRCMF_AWDL_OPMODE_ROLE 1 +#define BRCMF_AWDL_OPMODE_ROLE_MASTER 2 +#define BRCMF_AWDL_OPMODE_ROLE_SLAVE 0 +#define BRCMF_AWDL_OPMODE_ADDR 4 +static const u8 brcmf_awdl_opmode[] = { +0x01 ,0x02 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 , +0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 , +0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 , +0x00 ,0x00 ,0x00 ,0x00 , +}; + +/* awdl_election_tree: the master at 0x0f, its metric at 0x15, distance 0x19 */ +#define BRCMF_AWDL_ELECTION_ADDR 0x0f +#define BRCMF_AWDL_ELECTION_METRIC 0x15 +#define BRCMF_AWDL_ELECTION_DISTANCE 0x19 +static const u8 brcmf_awdl_election_tree[] = { +0x00 ,0x00 ,0x00 ,0x41 ,0x00 ,0x00 ,0x00 ,0x00 , +0x05 ,0xba ,0x00 ,0x00 ,0x01 ,0x03 ,0x04 ,0x00 , +0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x41 ,0x00 ,0x00 , +0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 , +0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 , +0x00 ,0x00 , +}; + +/* +* slot_bss with the chanspecs of slice 0 at 0x4c and of slice 1 at 0x78, 16 +* each. Chips without SDB get 9 at 0x0c and all chanspecs in slice 0. +*/ +#define BRCMF_AWDL_SLOT_SDB 0x0c +#define BRCMF_AWDL_SLOT_SDB_OFF 9 +#define BRCMF_AWDL_SLOT_SLICE0 0x4c +#define BRCMF_AWDL_SLOT_SLICE1 0x78 +#define BRCMF_AWDL_SLOTS 16 +static const u8 brcmf_awdl_slot_bss[] = { +0x00 ,0x80 ,0x01 ,0x01 ,0x01 ,0x00 ,0x90 ,0x00 , +0x01 ,0x00 ,0x00 ,0x00 ,0x04 ,0x03 ,0x00 ,0x00 , +0x01 ,0x00 ,0x2a ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 , +0x0f ,0x02 ,0x00 ,0x03 ,0xff ,0xff ,0xe2 ,0x2a , +0xe2 ,0x2a ,0xe2 ,0x2a ,0xe2 ,0x2a ,0xe2 ,0x2a , +0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x10 ,0x06 , +0xe2 ,0x2a ,0xe2 ,0x2a ,0xe2 ,0x2a ,0xe2 ,0x2a , +0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 , +0x02 ,0x00 ,0x28 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 , +0x00 ,0x10 ,0x02 ,0x00 ,0xe2 ,0x2a ,0xe2 ,0x2a , +0xe2 ,0x2a ,0xe2 ,0x2a ,0xe2 ,0x2a ,0x00 ,0x00 , +0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0xe2 ,0x2a , +0xe2 ,0x2a ,0xe2 ,0x2a ,0xe2 ,0x2a ,0x00 ,0x00 , +0x00 ,0x00 ,0x00 ,0x00 ,0x02 ,0x00 ,0x28 ,0x00 , +0x00 ,0x00 ,0x00 ,0x00 ,0x01 ,0x10 ,0x02 ,0x00 , +0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 , +0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 , +0x10 ,0x06 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 , +0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 , +0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 , +}; + +/* +* awdl_peer_op: byte 1 the operation, 2 to 7 the peer, 8 the flags, from 9 +* the HT and VHT capabilities elements of the peer. An add without them is +* 0x25 bytes long. +*/ +#define BRCMF_AWDL_PEER_OP_ADD 0 +#define BRCMF_AWDL_PEER_OP_DEL 1 +#define BRCMF_AWDL_PEER_OP_HDR_LEN 9 +#define BRCMF_AWDL_PEER_OP_ADD_LEN 0x25 +#define BRCMF_AWDL_PEER_IES_MAX 128 + +static void brcmf_awdl_ctrl_work (struct work_struct *work); +static void brcmf_awdl_remove_work (struct work_struct *work); +static void brcmf_awdl_aftx_work (struct wiphy *wiphy,struct wiphy_work *work); +static void brcmf_awdl_settle_work (struct wiphy *wiphy, +struct wiphy_work *work); +void brcmf_awdl_attach (struct brcmf_pub *drvr) { -spin_lock_init (&drvr->awdl.lock); -init_completion (&drvr->awdl.if_event); +struct brcmf_awdl *awdl = &drvr->awdl; + +spin_lock_init (&awdl->lock); +init_completion (&awdl->if_event); +INIT_WORK (&awdl->ctrl_work, brcmf_awdl_ctrl_work); +INIT_WORK (&awdl->remove_work, brcmf_awdl_remove_work); +wiphy_delayed_work_init (&awdl->aftx_work, brcmf_awdl_aftx_work); +wiphy_delayed_work_init (&awdl->settle_work, brcmf_awdl_settle_work); }/*
@@ -64,6 +186,8 @@ void brcmf_awdl_attach(struct brcmf_pub *drvr)* the interface if it is the AWDL interface being created. */ static void brcmf_awdl_drop_if (struct brcmf_pub *drvr,struct brcmf_if *ifp); +static void brcmf_awdl_send_result (struct brcmf_pub *drvr,int event, +int status,struct net_device *ndev);bool brcmf_awdl_if_added (struct brcmf_pub *drvr,struct brcmf_if *ifp) {
@@ -96,31 +220,34 @@ bool brcmf_awdl_if_added(struct brcmf_pub *drvr, struct brcmf_if *ifp)/* * Called from the firmware event worker before an interface is removed. -* Returns true if the removal of the AWDL interface was requested by -* brcmf_awdl_del(), which then removes it. When the firmware removes the -* AWDL interface on its own, it is forgotten here and removed by the caller. +* Returns true for the AWDL interface, which is then removed by +* brcmf_awdl_del() when it requested the removal, or by +* brcmf_awdl_remove_work() when the firmware removed it on its own. */ bool brcmf_awdl_if_removed (struct brcmf_pub *drvr,struct brcmf_if *ifp) {struct brcmf_awdl *awdl = &drvr->awdl; -bool requested = false; +bool requested = false, own = false;if (!ifp->awdl)return false;spin_lock (&awdl->lock);if (awdl->ifp == ifp) { + own = true; requested = awdl->removing;if (requested)complete (&awdl->if_event);else - awdl->ifp =NULL ; + awdl->fw_removed = true; }spin_unlock (&awdl->lock); -if (!requested) -brcmf_proto_configure_addr_mode (drvr, ifp->ifidx, -ADDR_INDIRECT ); -return requested; +/* The event worker cannot take RTNL and the wiphy mutex, which +* brcmf_awdl_add() and brcmf_awdl_del() hold while they wait for it +*/ +if (own && !requested) +schedule_work (&awdl->remove_work); +return own; }/* The firmware interface index of the AWDL interface must be free */
@@ -248,6 +375,21 @@ int brcmf_awdl_add(struct brcmf_pub *drvr, const u8 *mac,return 0 ; } +/* Stops AWDL and removes the AWDL interface in the firmware */ +static int brcmf_awdl_fw_del (struct brcmf_pub *drvr,struct brcmf_if *ifp) +{ +int err; + +brcmf_fil_iovar_int_set (ifp,"awdl" ,0 ); + err =brcmf_fil_iovar_data_set (ifp,"interface_remove" ,NULL ,0 ); +if (!err && !wait_for_completion_timeout (&drvr->awdl.if_event, +BRCMF_AWDL_IF_TIMEOUT )) { +bphy_err (drvr,"no interface event for the AWDL removal\n" ); + err = -ETIMEDOUT ; + } +return err; +} +/** * brcmf_awdl_del() - remove the AWDL interface. *
@@ -255,7 +397,8 @@ int brcmf_awdl_add(struct brcmf_pub *drvr, const u8 *mac,* * Called with RTNL and the wiphy mutex held. Deletes the flowrings of the * AWDL interface, stops AWDL and removes the interface in the firmware and on -* the host. +* the host. After the firmware removed it on its own, only the host side is +* removed. * * Return: 0 or a negative error code. */
@@ -263,6 +406,7 @@ int brcmf_awdl_del(struct brcmf_pub *drvr) {struct brcmf_awdl *awdl = &drvr->awdl;struct brcmf_if *ifp; +bool fw_removed;int err;ASSERT_RTNL ();
@@ -272,25 +416,24 @@ int brcmf_awdl_del(struct brcmf_pub *drvr)if (!ifp)return -ENOENT ; +wiphy_delayed_work_cancel (drvr->wiphy, &awdl->aftx_work); +wiphy_delayed_work_cancel (drvr->wiphy, &awdl->settle_work);netif_tx_disable (ifp->ndev);/* Deletes the flowrings of all peers */ brcmf_proto_configure_addr_mode (drvr, ifp->ifidx,ADDR_INDIRECT ); -brcmf_fil_iovar_int_set (ifp,"awdl" ,0 );spin_lock (&awdl->lock); - awdl->removing = true; + fw_removed = awdl->fw_removed; + awdl->removing = !fw_removed;reinit_completion (&awdl->if_event);spin_unlock (&awdl->lock); - err =brcmf_fil_iovar_data_set (ifp,"interface_remove" ,NULL ,0 ); -if (!err && !wait_for_completion_timeout (&awdl->if_event, -BRCMF_AWDL_IF_TIMEOUT )) { -bphy_err (drvr,"no interface event for the AWDL removal\n" ); - err = -ETIMEDOUT ; - } +/* After the firmware removed it, only the host side is left */ + err = fw_removed ?0 :brcmf_awdl_fw_del (drvr, ifp);spin_lock (&awdl->lock); awdl->removing = false; + awdl->fw_removed = false; awdl->ifp =NULL ;spin_unlock (&awdl->lock);
@@ -363,6 +506,541 @@ int brcmf_awdl_decap(struct sk_buff *skb)return 0 ; } +/* Sets a firmware parameter of the AWDL interface */ +static int brcmf_awdl_set (struct brcmf_if *ifp,const char *name, +const void *data,u32 len) +{ +int err; + + err =brcmf_fil_iovar_data_set (ifp, name, data, len); +if (err) +bphy_err (ifp->drvr,"AWDL %s failed: %d\n" , name, err); +return err; +} + +static int brcmf_awdl_set_u32 (struct brcmf_if *ifp,const char *name, +u32 val) +{ +__le32 data =cpu_to_le32 (val); + +return brcmf_awdl_set (ifp, name, &data,sizeof (data)); +} + +static void brcmf_awdl_free_frames (struct brcmf_awdl *awdl) +{ +kfree (awdl->payload); +kfree (awdl->oob); + awdl->payload =NULL ; + awdl->oob =NULL ; + awdl->payload_len =0 ; + awdl->oob_len =0 ; +} + +/* Builds awdl_payload and awdl_oob_af_auto around the TLVs of user space */ +static int brcmf_awdl_store_frames (struct brcmf_awdl *awdl, +const struct nlattr *payload, +const struct nlattr *oob) +{ +u32 plen =nla_len (payload), olen =nla_len (oob); +u8 *p, *o; + + p =kmalloc (2 + plen,GFP_KERNEL ); + o =kmalloc (sizeof (brcmf_awdl_oob_hdr) +2 + olen,GFP_KERNEL ); +if (!p || !o) { +kfree (p); +kfree (o); +return -ENOMEM ; + } +put_unaligned_le16 (plen, p); +memcpy (p +2 ,nla_data (payload), plen); +memcpy (o, brcmf_awdl_oob_hdr,sizeof (brcmf_awdl_oob_hdr)); +put_unaligned_le16 (olen, o +sizeof (brcmf_awdl_oob_hdr)); +memcpy (o +sizeof (brcmf_awdl_oob_hdr) +2 ,nla_data (oob), olen); + +brcmf_awdl_free_frames (awdl); + awdl->payload = p; + awdl->payload_len =2 + plen; + awdl->oob = o; + awdl->oob_len =sizeof (brcmf_awdl_oob_hdr) +2 + olen; +return 0 ; +} + +static int brcmf_awdl_set_payload (struct brcmf_awdl *awdl) +{ +return brcmf_awdl_set (awdl->ifp,"awdl_payload" , awdl->payload, + awdl->payload_len); +} + +static int brcmf_awdl_set_opmode (struct brcmf_awdl *awdl) +{ +u8 buf[sizeof (brcmf_awdl_opmode)]; + +memcpy (buf, brcmf_awdl_opmode,sizeof (buf)); +if (awdl->has_master) { + buf[BRCMF_AWDL_OPMODE_ROLE ] =BRCMF_AWDL_OPMODE_ROLE_SLAVE ; +ether_addr_copy (buf +BRCMF_AWDL_OPMODE_ADDR , awdl->master); + }else { + buf[BRCMF_AWDL_OPMODE_ROLE ] =BRCMF_AWDL_OPMODE_ROLE_MASTER ; +ether_addr_copy (buf +BRCMF_AWDL_OPMODE_ADDR , awdl->mac); + } +return brcmf_awdl_set (awdl->ifp,"awdl_opmode" , buf,sizeof (buf)); +} + +static int brcmf_awdl_set_election (struct brcmf_awdl *awdl) +{ +u8 buf[sizeof (brcmf_awdl_election_tree)]; + +memcpy (buf, brcmf_awdl_election_tree,sizeof (buf)); +if (awdl->has_master) { +ether_addr_copy (buf +BRCMF_AWDL_ELECTION_ADDR , awdl->master); +put_unaligned_le32 (awdl->master_metric, + buf +BRCMF_AWDL_ELECTION_METRIC ); + buf[BRCMF_AWDL_ELECTION_DISTANCE ] = awdl->master_distance; + }else { +ether_addr_copy (buf +BRCMF_AWDL_ELECTION_ADDR , awdl->mac); + } +return brcmf_awdl_set (awdl->ifp,"awdl_election_tree" , buf, +sizeof (buf)); +} + +static int brcmf_awdl_set_slots (struct brcmf_pub *drvr) +{ +u8 buf[sizeof (brcmf_awdl_slot_bss)]; +u8 *s0, *s1; +int i; + +memcpy (buf, brcmf_awdl_slot_bss,sizeof (buf)); +if (brcmf_feat_is_quirk_enabled (drvr->awdl.ifp, +BRCMF_FEAT_QUIRK_AWDL_NO_SDB )) { + buf[BRCMF_AWDL_SLOT_SDB ] =BRCMF_AWDL_SLOT_SDB_OFF ; +for (i =0 ; i <BRCMF_AWDL_SLOTS ; i++) { + s0 = buf +BRCMF_AWDL_SLOT_SLICE0 +2 * i; + s1 = buf +BRCMF_AWDL_SLOT_SLICE1 +2 * i; +if (!get_unaligned_le16 (s0)) +memcpy (s0, s1,2 ); +memset (s1,0 ,2 ); + } + } +return brcmf_awdl_set (drvr->awdl.ifp,"slot_bss" , buf,sizeof (buf)); +} + +/* +* The firmware takes the frames and then the synchronization state, each +* refresh sends both. A vendor command returns the errors of the part it +* changes, the errors of the other part are only logged. +* +* brcmf_awdl_refresh_frames() sends the frames and returns the first error. +*/ +static int brcmf_awdl_refresh_frames (struct brcmf_awdl *awdl) +{ +int err, ret; + + ret =brcmf_awdl_set (awdl->ifp,"awdl_oob_af_auto" , awdl->oob, + awdl->oob_len); + err =brcmf_awdl_set_payload (awdl); +return ret ?: err; +} + +/* +* Sends the synchronization state, returns the first error. awdl_opmode +* fails while the firmware does not know the new master yet, the next +* refresh sends it again. +*/ +static int brcmf_awdl_refresh_sync (struct brcmf_awdl *awdl) +{ +int err, ret; + + ret =brcmf_awdl_set (awdl->ifp,"awdl_sync_params" , + brcmf_awdl_sync_params, +sizeof (brcmf_awdl_sync_params)); + err =brcmf_awdl_set_opmode (awdl); + ret = ret ?: err; + err =brcmf_awdl_set_election (awdl); + ret = ret ?: err; + err =brcmf_awdl_set (awdl->ifp,"awdl_sync_params" , + brcmf_awdl_sync_params, +sizeof (brcmf_awdl_sync_params)); +return ret ?: err; +} + +/* +* Starts AWDL on the AWDL interface, the firmware expects this order. AWDL +* does not run without awdl_config, slot_bss and awdl, a failure of one of +* them fails the start. The other parameters are retried by the next +* refresh. +*/ +static int brcmf_awdl_enable (struct brcmf_pub *drvr) +{ +struct brcmf_awdl *awdl = &drvr->awdl; +struct brcmf_if *ifp = awdl->ifp; +int err; + +brcmf_awdl_set_payload (awdl); +brcmf_awdl_set_u32 (ifp,"awdl_aftxmode" ,0 ); +brcmf_awdl_set (ifp,"awdl_sync_params" , brcmf_awdl_sync_params, +sizeof (brcmf_awdl_sync_params)); +brcmf_awdl_set_u32 (ifp,"awdl_osoc_chan" ,0 ); + err =brcmf_awdl_set_u32 (ifp,"awdl_config" ,BRCMF_AWDL_CONFIG_START ); +if (err) +return err; +brcmf_awdl_set (ifp,"awdl_psf_dwell" , brcmf_awdl_psf_dwell, +sizeof (brcmf_awdl_psf_dwell)); + err =brcmf_awdl_set_slots (drvr); +if (err) +return err; +brcmf_awdl_set_payload (awdl); +brcmf_awdl_set_election (awdl); + err =brcmf_awdl_set_u32 (ifp,"awdl" ,1 ); +if (err) +return err; +brcmf_awdl_set_u32 (ifp,"awdl_presencemode" ,BRCMF_AWDL_PRESENCEMODE ); + err =brcmf_awdl_set_slots (drvr); +if (err) +return err; +brcmf_awdl_refresh_frames (awdl); +brcmf_awdl_refresh_sync (awdl); +wiphy_delayed_work_queue (drvr->wiphy, &awdl->aftx_work, +BRCMF_AWDL_AFTX_DELAY ); +wiphy_delayed_work_queue (drvr->wiphy, &awdl->settle_work, +BRCMF_AWDL_SETTLE_DELAY ); +return 0 ; +} + +static void brcmf_awdl_aftx_work (struct wiphy *wiphy,struct wiphy_work *work) +{ + struct brcmf_awdl *awdl = container_of(work, struct brcmf_awdl, + aftx_work.work); + +if (!awdl->ifp) +return ; +brcmf_awdl_set_u32 (awdl->ifp,"awdl_aftxmode" ,0 ); +brcmf_awdl_set_u32 (awdl->ifp,"awdl_osoc_chan" ,BRCMF_AWDL_OSOC_CHAN ); +} + +static void brcmf_awdl_settle_work (struct wiphy *wiphy, +struct wiphy_work *work) +{ + struct brcmf_awdl *awdl = container_of(work, struct brcmf_awdl, + settle_work.work); +static const u8 dwell_off[sizeof (brcmf_awdl_psf_dwell)]; + +if (!awdl->ifp) +return ; +brcmf_awdl_set_u32 (awdl->ifp,"awdl_config" ,BRCMF_AWDL_CONFIG_SETTLED ); +brcmf_awdl_set (awdl->ifp,"awdl_psf_dwell" , dwell_off, +sizeof (dwell_off)); +} + +static void brcmf_awdl_send_result (struct brcmf_pub *drvr,int event, +int status,struct net_device *ndev) +{ +struct brcmf_if *pri =brcmf_get_ifp (drvr,0 ); +struct sk_buff *skb; + + skb =cfg80211_vendor_event_alloc (drvr->wiphy, + pri && pri->vif ? &pri->vif->wdev : +NULL , +NLMSG_DEFAULT_SIZE , event, +GFP_KERNEL ); +if (!skb) +return ; +if (nla_put_s32 (skb,BRCMF_AWDL_ATTR_STATUS , status) || + (ndev &&nla_put_u32 (skb,BRCMF_AWDL_ATTR_IFINDEX , + ndev->ifindex))) { +kfree_skb (skb); +return ; + } +cfg80211_vendor_event (skb,GFP_KERNEL ); +} + +/* Runs the AWDL_START and AWDL_STOP vendor commands with RTNL */ +static void brcmf_awdl_ctrl_work (struct work_struct *work) +{ + struct brcmf_awdl *awdl = container_of(work, struct brcmf_awdl, + ctrl_work); + struct brcmf_pub *drvr = container_of(awdl, struct brcmf_pub, awdl); +struct net_device *ndev =NULL ; +enum brcmf_awdl_op op; +int err; + +rtnl_lock (); +wiphy_lock (drvr->wiphy); +spin_lock (&awdl->lock); + op = awdl->op; + awdl->op =BRCMF_AWDL_OP_NONE ; +spin_unlock (&awdl->lock); + +switch (op) { +case BRCMF_AWDL_OP_START : + err =brcmf_awdl_add (drvr, awdl->start_mac, &ndev); +if (!err) { + awdl->has_master = false; + err =brcmf_awdl_enable (drvr); +if (err) { +brcmf_awdl_del (drvr); + ndev =NULL ; + } + } +brcmf_awdl_send_result (drvr,BRCMF_VNDR_EVTS_AWDL_STARTED , err, + ndev); +break ; +case BRCMF_AWDL_OP_STOP : + err =brcmf_awdl_del (drvr); +brcmf_awdl_send_result (drvr,BRCMF_VNDR_EVTS_AWDL_STOPPED , err, +NULL ); +break ; +default : +break ; + } +wiphy_unlock (drvr->wiphy); +rtnl_unlock (); +} + +/* +* Removes the AWDL interface on the host after the firmware removed it on +* its own. It holds RTNL and the wiphy mutex like brcmf_awdl_del(), so the +* vendor commands and the delayed works never see the interface go away. +* AWDL_STOPPED is sent once the interface is gone. +*/ +static void brcmf_awdl_remove_work (struct work_struct *work) +{ + struct brcmf_awdl *awdl = container_of(work, struct brcmf_awdl, + remove_work); + struct brcmf_pub *drvr = container_of(awdl, struct brcmf_pub, awdl); +bool gone; + +rtnl_lock (); +wiphy_lock (drvr->wiphy); +/* After a STOP, a suspend or the detach there is nothing left */ +spin_lock (&awdl->lock); + gone = awdl->ifp && awdl->fw_removed; +spin_unlock (&awdl->lock); +if (gone && !brcmf_awdl_del (drvr)) +brcmf_awdl_send_result (drvr,BRCMF_VNDR_EVTS_AWDL_STOPPED , + -ENOLINK ,NULL ); +wiphy_unlock (drvr->wiphy); +rtnl_unlock (); +} + +/* +* Removes the AWDL interface before system sleep, with RTNL and the wiphy +* mutex held, while the firmware still takes commands. A queued START is +* answered with -ECANCELED, a queued STOP is done here. +*/ +void brcmf_awdl_suspend (struct brcmf_pub *drvr) +{ +struct brcmf_awdl *awdl = &drvr->awdl; +enum brcmf_awdl_op op; +int err; + +spin_lock (&awdl->lock); + op = awdl->op; + awdl->op =BRCMF_AWDL_OP_NONE ; +spin_unlock (&awdl->lock); +if (op ==BRCMF_AWDL_OP_START ) +brcmf_awdl_send_result (drvr,BRCMF_VNDR_EVTS_AWDL_STARTED , + -ECANCELED ,NULL ); +if (!awdl->ifp) +return ; + err =brcmf_awdl_del (drvr); +brcmf_awdl_send_result (drvr,BRCMF_VNDR_EVTS_AWDL_STOPPED , err,NULL ); +} + +const struct nla_policy brcmf_awdl_vndr_policy[BRCMF_AWDL_ATTR_MAX +1 ] = { + [BRCMF_AWDL_ATTR_ADDR ] =NLA_POLICY_ETH_ADDR , + [BRCMF_AWDL_ATTR_PAYLOAD ] = { .type =NLA_BINARY , + .len =BRCMF_AWDL_TLV_MAX }, + [BRCMF_AWDL_ATTR_OOB ] = { .type =NLA_BINARY , + .len =BRCMF_AWDL_TLV_MAX }, + [BRCMF_AWDL_ATTR_MASTER ] =NLA_POLICY_ETH_ADDR , + [BRCMF_AWDL_ATTR_MASTER_METRIC ] = { .type =NLA_U32 }, + [BRCMF_AWDL_ATTR_MASTER_DISTANCE ] = { .type =NLA_U8 }, + [BRCMF_AWDL_ATTR_STATUS ] = { .type =NLA_REJECT }, + [BRCMF_AWDL_ATTR_IFINDEX ] = { .type =NLA_REJECT }, + [BRCMF_AWDL_ATTR_PEER_IES ] = { .type =NLA_BINARY , + .len =BRCMF_AWDL_PEER_IES_MAX }, +}; + +/* The device of a vendor command and its parsed attributes */ +static struct brcmf_pub *brcmf_awdl_vndr_parse (struct wiphy *wiphy, +const void *data,int len, +struct nlattr **tb) +{ +struct brcmf_cfg80211_info *cfg =wiphy_to_cfg (wiphy); +struct brcmf_pub *drvr = cfg->pub; +struct brcmf_if *pri =brcmf_get_ifp (drvr,0 ); +int err; + +if (!pri || !brcmf_feat_is_enabled (pri,BRCMF_FEAT_AWDL )) +return ERR_PTR (-EOPNOTSUPP ); + err =nla_parse (tb,BRCMF_AWDL_ATTR_MAX , data, len, + brcmf_awdl_vndr_policy,NULL ); +if (err) +return ERR_PTR (err); +return drvr; +} + +int brcmf_awdl_vndr_start (struct wiphy *wiphy,struct wireless_dev *wdev, +const void *data,int len) +{ +struct nlattr *tb[BRCMF_AWDL_ATTR_MAX +1 ]; +struct brcmf_pub *drvr; +struct brcmf_awdl *awdl; +int err; + + drvr =brcmf_awdl_vndr_parse (wiphy, data, len, tb); +if (IS_ERR (drvr)) +return PTR_ERR (drvr); + awdl = &drvr->awdl; +if (!tb[BRCMF_AWDL_ATTR_ADDR ] || !tb[BRCMF_AWDL_ATTR_PAYLOAD ] || + !tb[BRCMF_AWDL_ATTR_OOB ]) +return -EINVAL ; +if (!is_valid_ether_addr (nla_data (tb[BRCMF_AWDL_ATTR_ADDR ]))) +return -EINVAL ; +if (awdl->detached) +return -ENODEV ; +if (awdl->ifp || awdl->op !=BRCMF_AWDL_OP_NONE ) +return -EBUSY ; + + err =brcmf_awdl_store_frames (awdl, tb[BRCMF_AWDL_ATTR_PAYLOAD ], + tb[BRCMF_AWDL_ATTR_OOB ]); +if (err) +return err; +ether_addr_copy (awdl->start_mac,nla_data (tb[BRCMF_AWDL_ATTR_ADDR ])); +spin_lock (&awdl->lock); + awdl->op =BRCMF_AWDL_OP_START ; +spin_unlock (&awdl->lock); +schedule_work (&awdl->ctrl_work); +return 0 ; +} + +int brcmf_awdl_vndr_stop (struct wiphy *wiphy,struct wireless_dev *wdev, +const void *data,int len) +{ +struct nlattr *tb[BRCMF_AWDL_ATTR_MAX +1 ]; +struct brcmf_pub *drvr; +struct brcmf_awdl *awdl; + + drvr =brcmf_awdl_vndr_parse (wiphy, data, len, tb); +if (IS_ERR (drvr)) +return PTR_ERR (drvr); + awdl = &drvr->awdl; +if (awdl->detached) +return -ENODEV ; +/* A queued START is answered with AWDL_STARTED first */ +if (awdl->op !=BRCMF_AWDL_OP_NONE ) +return -EBUSY ; +if (!awdl->ifp) +return -ENOENT ; + +spin_lock (&awdl->lock); + awdl->op =BRCMF_AWDL_OP_STOP ; +spin_unlock (&awdl->lock); +schedule_work (&awdl->ctrl_work); +return 0 ; +} + +int brcmf_awdl_vndr_set_frames (struct wiphy *wiphy,struct wireless_dev *wdev, +const void *data,int len) +{ +struct nlattr *tb[BRCMF_AWDL_ATTR_MAX +1 ]; +struct brcmf_pub *drvr; +int err; + + drvr =brcmf_awdl_vndr_parse (wiphy, data, len, tb); +if (IS_ERR (drvr)) +return PTR_ERR (drvr); +if (!tb[BRCMF_AWDL_ATTR_PAYLOAD ] || !tb[BRCMF_AWDL_ATTR_OOB ]) +return -EINVAL ; +if (!drvr->awdl.ifp) +return -ENOENT ; + + err =brcmf_awdl_store_frames (&drvr->awdl, tb[BRCMF_AWDL_ATTR_PAYLOAD ], + tb[BRCMF_AWDL_ATTR_OOB ]); +if (err) +return err; + err =brcmf_awdl_refresh_frames (&drvr->awdl); +brcmf_awdl_refresh_sync (&drvr->awdl); +return err; +} + +int brcmf_awdl_vndr_set_sync (struct wiphy *wiphy,struct wireless_dev *wdev, +const void *data,int len) +{ +struct nlattr *tb[BRCMF_AWDL_ATTR_MAX +1 ]; +struct brcmf_pub *drvr; +struct brcmf_awdl *awdl; + + drvr =brcmf_awdl_vndr_parse (wiphy, data, len, tb); +if (IS_ERR (drvr)) +return PTR_ERR (drvr); + awdl = &drvr->awdl; +if (!awdl->ifp) +return -ENOENT ; + +if (tb[BRCMF_AWDL_ATTR_MASTER ]) { +if (!tb[BRCMF_AWDL_ATTR_MASTER_METRIC ] || + !tb[BRCMF_AWDL_ATTR_MASTER_DISTANCE ]) +return -EINVAL ; + awdl->has_master = true; +ether_addr_copy (awdl->master, +nla_data (tb[BRCMF_AWDL_ATTR_MASTER ])); + awdl->master_metric = +nla_get_u32 (tb[BRCMF_AWDL_ATTR_MASTER_METRIC ]); + awdl->master_distance = +nla_get_u8 (tb[BRCMF_AWDL_ATTR_MASTER_DISTANCE ]); + }else { + awdl->has_master = false; + } +brcmf_awdl_refresh_frames (awdl); +return brcmf_awdl_refresh_sync (awdl); +} + +static int brcmf_awdl_peer_op (struct wiphy *wiphy,const void *data,int len, +bool add) +{ +u8 op[BRCMF_AWDL_PEER_OP_HDR_LEN +BRCMF_AWDL_PEER_IES_MAX ] = {}; +struct nlattr *tb[BRCMF_AWDL_ATTR_MAX +1 ]; +u32 op_len =BRCMF_AWDL_PEER_OP_HDR_LEN ; +struct brcmf_pub *drvr; +struct nlattr *ies; + + drvr =brcmf_awdl_vndr_parse (wiphy, data, len, tb); +if (IS_ERR (drvr)) +return PTR_ERR (drvr); +if (!tb[BRCMF_AWDL_ATTR_ADDR ]) +return -EINVAL ; +if (!drvr->awdl.ifp) +return -ENOENT ; + + op[1 ] = add ?BRCMF_AWDL_PEER_OP_ADD :BRCMF_AWDL_PEER_OP_DEL ; +ether_addr_copy (op +2 ,nla_data (tb[BRCMF_AWDL_ATTR_ADDR ])); + op[8 ] = add; +if (add) { + ies = tb[BRCMF_AWDL_ATTR_PEER_IES ]; +if (ies) { +memcpy (op +BRCMF_AWDL_PEER_OP_HDR_LEN ,nla_data (ies), +nla_len (ies)); + op_len +=nla_len (ies); + } + op_len =max_t (u32, op_len,BRCMF_AWDL_PEER_OP_ADD_LEN ); + } +return brcmf_fil_iovar_data_set (drvr->awdl.ifp,"awdl_peer_op" , op, + op_len); +} + +int brcmf_awdl_vndr_peer_add (struct wiphy *wiphy,struct wireless_dev *wdev, +const void *data,int len) +{ +return brcmf_awdl_peer_op (wiphy, data, len, true); +} + +int brcmf_awdl_vndr_peer_del (struct wiphy *wiphy,struct wireless_dev *wdev, +const void *data,int len) +{ +return brcmf_awdl_peer_op (wiphy, data, len, false); +} +/* Called before the interfaces of the device are removed */ void brcmf_awdl_detach (struct brcmf_pub *drvr) {
@@ -370,10 +1048,18 @@ void brcmf_awdl_detach(struct brcmf_pub *drvr)rtnl_lock ();wiphy_lock (drvr->wiphy); +wiphy_delayed_work_cancel (drvr->wiphy, &awdl->aftx_work); +wiphy_delayed_work_cancel (drvr->wiphy, &awdl->settle_work);spin_lock (&awdl->lock); awdl->detached = true; + awdl->op =BRCMF_AWDL_OP_NONE ; awdl->ifp =NULL ;spin_unlock (&awdl->lock); +brcmf_awdl_free_frames (awdl);wiphy_unlock (drvr->wiphy);rtnl_unlock (); + +/* A queued operation finds the device detached */ +cancel_work_sync (&awdl->ctrl_work); +cancel_work_sync (&awdl->remove_work); }
drivers/net/wireless/broadcom/brcm80211/brcmfmac/awdl.h +61 -3
106 lines not on this page · raw message
drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c +3 -2
@@ -4246,8 +4246,7 @@ static s32 brcmf_cfg80211_suspend(struct wiphy *wiphy,/* The AWDL interface does not survive sleep, the firmware still * takes commands here. User space creates it again after resume. */ -if (cfg->pub->awdl.ifp) -brcmf_awdl_del (cfg->pub); +brcmf_awdl_suspend (cfg->pub);/* if the primary net_device is not READY there is nothing * we can do but pray resume goes smoothly.
@@ -7867,6 +7866,8 @@ static int brcmf_setup_wiphy(struct wiphy *wiphy, struct brcmf_if *ifp)/* vendor commands/events support */ wiphy->vendor_commands = brcmf_vendor_cmds; wiphy->n_vendor_commands =BRCMF_VNDR_CMDS_LAST -1 ; + wiphy->vendor_events = brcmf_vendor_events; + wiphy->n_vendor_events =BRCMF_VNDR_EVTS_LAST ;if (brcmf_feat_is_enabled (ifp,BRCMF_FEAT_WOWL ))brcmf_wiphy_wowl_params (wiphy, ifp);
drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.c +6 -0
@@ -497,6 +497,12 @@ void brcmf_feat_attach(struct brcmf_pub *drvr)case BRCM_CC_4329_CHIP_ID : drvr->chip_quirks |=BIT (BRCMF_FEAT_QUIRK_NEED_MPC );break ; +case BRCM_CC_4364_CHIP_ID : +/* The firmware traps with the SDB form of slot_bss while the +* station is on 5 GHz +*/ + drvr->chip_quirks |=BIT (BRCMF_FEAT_QUIRK_AWDL_NO_SDB ); +break ;default :/* no quirks */ break ;
drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.h +4 -1
@@ -71,10 +71,13 @@* * AUTO_AUTH: workaround needed for automatic authentication type. * NEED_MPC: driver needs to disable MPC during scanning operation. +* AWDL_NO_SDB: AWDL takes the slot_bss form without SDB, all channels in +* slice 0. */ #define BRCMF_QUIRK_LIST \ BRCMF_QUIRK_DEF(AUTO_AUTH) \ - BRCMF_QUIRK_DEF(NEED_MPC) + BRCMF_QUIRK_DEF(NEED_MPC) \ + BRCMF_QUIRK_DEF(AWDL_NO_SDB)#define BRCMF_FEAT_DEF (_f) \ BRCMF_FEAT_ ## _f,
drivers/net/wireless/broadcom/brcm80211/brcmfmac/vendor.c +82 -0
92 lines not on this page · raw message
drivers/net/wireless/broadcom/brcm80211/brcmfmac/vendor.h +97 -0
114 lines not on this page · raw message
Signature · 1 line
2.56.0
PATCH v3 6/6 wifi: brcmfmac: pass AWDL frames and role changes to user space
In reply to Andre EikmeyerUser space runs the AWDL election and peer discovery from the AWDL action frames of other devices. The firmware reports them on the AWDL interface with ACTION_FRAME_RX and AWDL_EVENT, behind a header of version 1 (16 bytes) or 2 (24 bytes), and its AWDL role with AWDL_ROLE.
AWDL_AW, AWDL_ROLE, AWDL_EVENT, AWDL_STATS and SDB_STATE are event codes of the Apple firmware. Add them as abstract event codes, mapped and registered by the WCC vendor module like the CYW module does for its events.
Pass the AWDL action frames and role changes to user space as the vendor events AWDL_FRAME and AWDL_ROLE.
--- .../broadcom/brcm80211/brcmfmac/awdl.c | 110 +++++++++++++++++- .../broadcom/brcm80211/brcmfmac/awdl.h | 3 + .../broadcom/brcm80211/brcmfmac/fweh.c | 8 +- .../broadcom/brcm80211/brcmfmac/fweh.h | 7 +- .../broadcom/brcm80211/brcmfmac/vendor.c | 8 ++ .../broadcom/brcm80211/brcmfmac/vendor.h | 12 ++ .../broadcom/brcm80211/brcmfmac/wcc/core.c | 39 +++++++ 7 files changed, 177 insertions(+), 10 deletions(-)
drivers/net/wireless/broadcom/brcm80211/brcmfmac/awdl.c +104 -6
@@ -731,17 +731,113 @@ static void brcmf_awdl_settle_work(struct wiphy *wiphy, sizeof(dwell_off)); } +/* +* ACTION_FRAME_RX and AWDL_EVENT put a header in front of a received frame. +* Its first 16 bits, high byte first, are the version: 1 is struct +* brcmf_rx_mgmt_data with 16 bytes, 2 has 24 bytes. +*/ +#define BRCMF_AWDL_RX_HDR_V1_LEN 16 +#define BRCMF_AWDL_RX_HDR_V2_LEN 24 + +/* AWDL action frame: vendor specific category, Apple OUI, type AWDL */ +static const u8 brcmf_awdl_af[] = {0x7f ,0x00 ,0x17 ,0xf2 ,0x08 }; + +static struct sk_buff *brcmf_awdl_event_alloc (struct brcmf_pub *drvr, +int event,int len) +{ +struct brcmf_if *pri =brcmf_get_ifp (drvr,0 ); + +return cfg80211_vendor_event_alloc (drvr->wiphy, + pri && pri->vif ? &pri->vif->wdev : +NULL , + len, event,GFP_KERNEL ); +} + +/** +* brcmf_awdl_fweh_event() - pass a firmware event of the AWDL interface on. +* +* @ifp: interface of the event. +* @e: event message. +* @data: event data. +* +* Called from the firmware event worker for the events of the AWDL +* interface, which do not go to the cfg80211 handlers. Received AWDL action +* frames and role changes become vendor events, other events are dropped. +* AWDL_EVENT carries an AWDL action frame with some of its status values. +* Return: 0 or a negative error code. +*/ +int brcmf_awdl_fweh_event (struct brcmf_if *ifp, +const struct brcmf_event_msg *e,void *data) +{ +struct brcmf_pub *drvr = ifp->drvr; +struct sk_buff *skb; +u32 hdr; + +if (!ifp->awdl) +return 0 ; + +switch (e->event_code) { +case BRCMF_E_ACTION_FRAME_RX : +case BRCMF_E_AWDL_EVENT : +break ; +case BRCMF_E_AWDL_ROLE : + skb =brcmf_awdl_event_alloc (drvr,BRCMF_VNDR_EVTS_AWDL_ROLE , +NLMSG_DEFAULT_SIZE ); +if (!skb) { +bphy_err (drvr,"AWDL role event dropped\n" ); +return -ENOMEM ; + } +if (nla_put_u32 (skb,BRCMF_AWDL_ATTR_ROLE , e->status)) { +bphy_err (drvr,"AWDL role event too large\n" ); +kfree_skb (skb); +return -EMSGSIZE ; + } +cfg80211_vendor_event (skb,GFP_KERNEL ); +return 0 ; +default : +return 0 ; + } + +if (e->datalen <2 ) +return 0 ; +switch (get_unaligned_be16 (data)) { +case 1 : + hdr =BRCMF_AWDL_RX_HDR_V1_LEN ; +break ; +case 2 : + hdr =BRCMF_AWDL_RX_HDR_V2_LEN ; +break ; +default : +return 0 ; + } +if (e->datalen < hdr +sizeof (brcmf_awdl_af) || +memcmp ((u8 *)data + hdr, brcmf_awdl_af,sizeof (brcmf_awdl_af))) +return 0 ; + + skb =brcmf_awdl_event_alloc (drvr,BRCMF_VNDR_EVTS_AWDL_FRAME , + e->datalen); +if (!skb) { +bphy_err (drvr,"AWDL frame from %pM dropped\n" , e->addr); +return -ENOMEM ; + } +if (nla_put (skb,BRCMF_AWDL_ATTR_ADDR ,ETH_ALEN , e->addr) || +nla_put (skb,BRCMF_AWDL_ATTR_FRAME , e->datalen - hdr, + (u8 *)data + hdr)) { +bphy_err (drvr,"AWDL frame from %pM too large\n" , e->addr); +kfree_skb (skb); +return -EMSGSIZE ; + } +cfg80211_vendor_event (skb,GFP_KERNEL ); +return 0 ; +} +BRCMF_EXPORT_SYMBOL_GPL (brcmf_awdl_fweh_event); +static void brcmf_awdl_send_result (struct brcmf_pub *drvr,int event,int status,struct net_device *ndev) { -struct brcmf_if *pri =brcmf_get_ifp (drvr,0 );struct sk_buff *skb; - skb =cfg80211_vendor_event_alloc (drvr->wiphy, - pri && pri->vif ? &pri->vif->wdev : -NULL , -NLMSG_DEFAULT_SIZE , event, -GFP_KERNEL ); + skb =brcmf_awdl_event_alloc (drvr, event,NLMSG_DEFAULT_SIZE );if (!skb)return ; if (nla_put_s32(skb, BRCMF_AWDL_ATTR_STATUS, status) ||
@@ -859,6 +955,8 @@ const struct nla_policy brcmf_awdl_vndr_policy[BRCMF_AWDL_ATTR_MAX + 1] = { [BRCMF_AWDL_ATTR_IFINDEX] = { .type = NLA_REJECT }, [BRCMF_AWDL_ATTR_PEER_IES ] = { .type =NLA_BINARY , .len = BRCMF_AWDL_PEER_IES_MAX }, + [BRCMF_AWDL_ATTR_FRAME] = { .type = NLA_REJECT }, + [BRCMF_AWDL_ATTR_ROLE] = { .type = NLA_REJECT }, };/* The device of a vendor command and its parsed attributes */
drivers/net/wireless/broadcom/brcm80211/brcmfmac/awdl.h +3 -0
@@ -18,6 +18,7 @@ struct brcmf_pub;struct brcmf_if ;struct net_device ;struct sk_buff ; +struct brcmf_event_msg ;enum brcmf_awdl_op {BRCMF_AWDL_OP_NONE ,
@@ -98,6 +99,8 @@ int brcmf_awdl_add(struct brcmf_pub *drvr, const u8 *mac, struct net_device **ndev);int brcmf_awdl_del (struct brcmf_pub *drvr);void brcmf_awdl_suspend (struct brcmf_pub *drvr); +int brcmf_awdl_fweh_event (struct brcmf_if *ifp, +const struct brcmf_event_msg *e,void *data);bool brcmf_awdl_if_added (struct brcmf_pub *drvr,struct brcmf_if *ifp);bool brcmf_awdl_if_removed (struct brcmf_pub *drvr,struct brcmf_if *ifp);int brcmf_awdl_encap (struct brcmf_if *ifp,struct sk_buff *skb);
drivers/net/wireless/broadcom/brcm80211/brcmfmac/fweh.c +5 -3
@@ -326,11 +326,13 @@ static void brcmf_fweh_event_worker(struct work_struct *work) ifp = drvr->iflist[0 ]; else ifp = drvr->iflist[emsg.bsscfgidx]; -/* The AWDL interface has no vif, its events are not for -* the cfg80211 handlers +/* The AWDL interface has no vif, its events go to user +* space and not to the cfg80211 handlers */ -if (ifp && ifp->awdl) +if (ifp && ifp->awdl) { +brcmf_awdl_fweh_event (ifp, &emsg, event->data); goto event_free; + } err =brcmf_fweh_call_event_handler (drvr, ifp, event->code, &emsg, event->data);
drivers/net/wireless/broadcom/brcm80211/brcmfmac/fweh.h +6 -1
@@ -98,7 +98,12 @@ struct brcmf_cfg80211_info; BRCMF_ABSTRACT_ENUM_DEF(EXT_AUTH_REQ, 0) \ BRCMF_ABSTRACT_ENUM_DEF(EXT_AUTH_FRAME_RX, 1) \ BRCMF_ABSTRACT_ENUM_DEF(MGMT_FRAME_TXSTATUS, 2) \ - BRCMF_ABSTRACT_ENUM_DEF(MGMT_FRAME_OFFCHAN_DONE, 3) + BRCMF_ABSTRACT_ENUM_DEF(MGMT_FRAME_OFFCHAN_DONE, 3) \ + BRCMF_ABSTRACT_ENUM_DEF(AWDL_AW, 4) \ + BRCMF_ABSTRACT_ENUM_DEF(AWDL_ROLE, 5) \ + BRCMF_ABSTRACT_ENUM_DEF(AWDL_EVENT, 6) \ + BRCMF_ABSTRACT_ENUM_DEF(AWDL_STATS, 7) \ + BRCMF_ABSTRACT_ENUM_DEF(SDB_STATE, 8)#define BRCMF_ENUM_DEF (id, val) \ BRCMF_E_##id = (val),
drivers/net/wireless/broadcom/brcm80211/brcmfmac/vendor.c +8 -0
@@ -197,4 +197,12 @@ const struct nl80211_vendor_cmd_info brcmf_vendor_events[] = { .vendor_id = BROADCOM_OUI, .subcmd =BRCMF_VNDR_EVTS_AWDL_STOPPED }, + [BRCMF_VNDR_EVTS_AWDL_FRAME] = { + .vendor_id = BROADCOM_OUI, + .subcmd =BRCMF_VNDR_EVTS_AWDL_FRAME + }, + [BRCMF_VNDR_EVTS_AWDL_ROLE] = { + .vendor_id = BROADCOM_OUI, + .subcmd =BRCMF_VNDR_EVTS_AWDL_ROLE + }, };
drivers/net/wireless/broadcom/brcm80211/brcmfmac/vendor.h +12 -0
@@ -62,6 +62,11 @@ enum brcmf_vndr_cmds {* system sleep the status is 0 or the error of the removal. When the * firmware removed the interface on its own it is -%ENOLINK, sent once * the interface is gone on the host. +* @BRCMF_VNDR_EVTS_AWDL_FRAME: AWDL action frame received from +* %BRCMF_AWDL_ATTR_ADDR, the frame body from the category on in +* %BRCMF_AWDL_ATTR_FRAME. +* @BRCMF_VNDR_EVTS_AWDL_ROLE: the firmware changed its AWDL role to +* %BRCMF_AWDL_ATTR_ROLE. * @BRCMF_VNDR_EVTS_LAST: number of vendor events. * * The value of an event is its index in the vendor events and its vendor
@@ -71,6 +76,8 @@ enum brcmf_vndr_evts {BRCMF_VNDR_EVTS_UNSPEC ,BRCMF_VNDR_EVTS_AWDL_STARTED ,BRCMF_VNDR_EVTS_AWDL_STOPPED , +BRCMF_VNDR_EVTS_AWDL_FRAME , +BRCMF_VNDR_EVTS_AWDL_ROLE , BRCMF_VNDR_EVTS_LAST };
@@ -90,6 +97,9 @@ enum brcmf_vndr_evts {* @BRCMF_AWDL_ATTR_IFINDEX: interface index of the AWDL interface (u32). * @BRCMF_AWDL_ATTR_PEER_IES: HT and VHT capabilities elements of a peer, * built from the AWDL TLVs it sends, as macOS passes them. +* @BRCMF_AWDL_ATTR_FRAME: received action frame body. +* @BRCMF_AWDL_ATTR_ROLE: AWDL role of the firmware (u32), 0 slave, 1 master +* not taking part in the election, 2 master. * @__BRCMF_AWDL_ATTR_AFTER_LAST: internal use. * @BRCMF_AWDL_ATTR_MAX: highest attribute. */
@@ -105,6 +115,8 @@ enum brcmf_awdl_attrs {BRCMF_AWDL_ATTR_STATUS ,BRCMF_AWDL_ATTR_IFINDEX ,BRCMF_AWDL_ATTR_PEER_IES , +BRCMF_AWDL_ATTR_FRAME , +BRCMF_AWDL_ATTR_ROLE , __BRCMF_AWDL_ATTR_AFTER_LAST,BRCMF_AWDL_ATTR_MAX = __BRCMF_AWDL_ATTR_AFTER_LAST -1
drivers/net/wireless/broadcom/brcm80211/brcmfmac/wcc/core.c +39 -0
@@ -8,11 +8,30 @@#include <bus.h> #include <fwvid.h> #include <cfg80211.h> +#include <feature.h> +#include <fweh.h> #include "vops.h" +/* Firmware events of the Apple firmware for its AWDL interface */ +#define BRCMF_WCC_E_AWDL_AW 96 +#define BRCMF_WCC_E_AWDL_ROLE 97 +#define BRCMF_WCC_E_AWDL_EVENT 98 +#define BRCMF_WCC_E_AWDL_STATS 150 +#define BRCMF_WCC_E_SDB_STATE 152#define BRCMF_WCC_E_LAST 213 +static const struct brcmf_fweh_event_map brcmf_wcc_event_map = { + .items = { + {BRCMF_E_AWDL_AW ,BRCMF_WCC_E_AWDL_AW }, + {BRCMF_E_AWDL_ROLE ,BRCMF_WCC_E_AWDL_ROLE }, + {BRCMF_E_AWDL_EVENT ,BRCMF_WCC_E_AWDL_EVENT }, + {BRCMF_E_AWDL_STATS ,BRCMF_WCC_E_AWDL_STATS }, + {BRCMF_E_SDB_STATE ,BRCMF_WCC_E_SDB_STATE }, + }, + .n_items =5 +}; +static int brcmf_wcc_set_sae_pwd (struct brcmf_if *ifp,struct cfg80211_crypto_settings *crypto) {
@@ -29,11 +48,31 @@ static int brcmf_wcc_alloc_fweh_info(struct brcmf_pub *drvr)return -ENOMEM ; fweh->num_event_codes =BRCMF_WCC_E_LAST ; + fweh->event_map = &brcmf_wcc_event_map; drvr->fweh = fweh;return 0 ; } +/* +* The AWDL interface reports these events, they go to user space. The +* firmware runs AWDL with all of them enabled in the event mask. +*/ +static void brcmf_wcc_register_event_handlers (struct brcmf_pub *drvr) +{ +static const enum brcmf_fweh_event_code events[] = { +BRCMF_E_AWDL_AW ,BRCMF_E_AWDL_ROLE ,BRCMF_E_AWDL_EVENT , +BRCMF_E_AWDL_STATS ,BRCMF_E_SDB_STATE , + }; +int i; + +if (!(drvr->feat_flags &BIT (BRCMF_FEAT_AWDL ))) +return ; +for (i =0 ; i <ARRAY_SIZE (events); i++) +brcmf_fweh_register (drvr, events[i], brcmf_awdl_fweh_event); +} +const struct brcmf_fwvid_ops brcmf_wcc_ops = { .set_sae_password = brcmf_wcc_set_sae_pwd, .alloc_fweh_info = brcmf_wcc_alloc_fweh_info, + .register_event_handlers = brcmf_wcc_register_event_handlers, };
Signature · 1 line
2.56.0