mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH wireless-next v2 0/6] wifi: brcmfmac: AWDL for AirDrop on Apple T2 Macs
@ 2026-11-25 19:02 Andre Eikmeyer
  2026-11-25 19:02 ` [PATCH wireless-next v2 1/6] wifi: brcmfmac: move the interface_create definitions to fwil_types.h Andre Eikmeyer
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Andre Eikmeyer @ 2026-11-25 19:02 UTC (permalink / raw)
  To: arend.vanspriel
  Cc: linux-wireless, brcm80211, brcm80211-dev-list.pdl, linux-kernel,
	Sasha Finkelstein, Sven Peter, Janne Grunau, Aditya Garg,
	Andre Eikmeyer

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.
v1 ran on the BCM4364 and BCM4377 machines of the T2 Linux community.

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

v1: https://lore.kernel.org/all/20261104151547.70333-1-dev@deq.rocks/

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        | 1111 +++++++++++++++++
 .../broadcom/brcm80211/brcmfmac/awdl.h        |  116 ++
 .../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      |  104 ++
 .../broadcom/brcm80211/brcmfmac/wcc/core.c    |   39 +
 14 files changed, 1659 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
-- 
2.56.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH wireless-next v2 1/6] wifi: brcmfmac: move the interface_create definitions to fwil_types.h
  2026-11-25 19:02 [PATCH wireless-next v2 0/6] wifi: brcmfmac: AWDL for AirDrop on Apple T2 Macs Andre Eikmeyer
@ 2026-11-25 19:02 ` Andre Eikmeyer
  2026-11-25 19:02 ` [PATCH wireless-next v2 2/6] wifi: brcmfmac: detect AWDL support of the firmware Andre Eikmeyer
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Andre Eikmeyer @ 2026-11-25 19:02 UTC (permalink / raw)
  To: arend.vanspriel
  Cc: linux-wireless, brcm80211, brcm80211-dev-list.pdl, linux-kernel,
	Sasha Finkelstein, Sven Peter, Janne Grunau, Aditya Garg,
	Andre Eikmeyer, Yossef Osman

The 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.

Tested-by: Yossef Osman <Yossef.Osman@proton.me>
Tested-by: Aditya Garg <aditya.garg@linux.dev>
Acked-by: Arend van Spriel <arend.vanspriel@broadcom.com>
Signed-off-by: Andre Eikmeyer <dev@deq.rocks>
---
 .../broadcom/brcm80211/brcmfmac/cfg80211.c    | 42 ------------------
 .../broadcom/brcm80211/brcmfmac/fwil_types.h  | 43 +++++++++++++++++++
 2 files changed, 43 insertions(+), 42 deletions(-)

diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c
index 57689026525e..2035535b753f 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c
@@ -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) {
diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fwil_types.h b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fwil_types.h
index 37d9414546d5..973598d43368 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fwil_types.h
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fwil_types.h
@@ -1375,4 +1375,47 @@ struct brcmf_eventmsgs_ext_le {
 	u8 mask[] __counted_by(len);
 };
 
+/* interface_create iovar */
+#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 */
+};
+
 #endif /* FWIL_TYPES_H_ */
-- 
2.56.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH wireless-next v2 2/6] wifi: brcmfmac: detect AWDL support of the firmware
  2026-11-25 19:02 [PATCH wireless-next v2 0/6] wifi: brcmfmac: AWDL for AirDrop on Apple T2 Macs Andre Eikmeyer
  2026-11-25 19:02 ` [PATCH wireless-next v2 1/6] wifi: brcmfmac: move the interface_create definitions to fwil_types.h Andre Eikmeyer
@ 2026-11-25 19:02 ` Andre Eikmeyer
  2026-11-25 19:02 ` [PATCH wireless-next v2 3/6] wifi: brcmfmac: create and remove the AWDL interface Andre Eikmeyer
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Andre Eikmeyer @ 2026-11-25 19:02 UTC (permalink / raw)
  To: arend.vanspriel
  Cc: linux-wireless, brcm80211, brcm80211-dev-list.pdl, linux-kernel,
	Sasha Finkelstein, Sven Peter, Janne Grunau, Aditya Garg,
	Andre Eikmeyer, Yossef Osman

The 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.

Tested-by: Yossef Osman <Yossef.Osman@proton.me>
Tested-by: Aditya Garg <aditya.garg@linux.dev>
Acked-by: Arend van Spriel <arend.vanspriel@broadcom.com>
Signed-off-by: Andre Eikmeyer <dev@deq.rocks>
---
 .../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(-)

diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.c
index 27fa3a7941d9..898a991885a8 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.c
@@ -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 &&
diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.h b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.h
index 45a05642bbed..8574731418fc 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.h
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.h
@@ -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:
diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fwil_types.h b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fwil_types.h
index 973598d43368..b87222b2bdd9 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fwil_types.h
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fwil_types.h
@@ -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	0x2
 
 struct wl_interface_create_v1 {
 	u16	ver;			/* structure version */
-- 
2.56.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH wireless-next v2 3/6] wifi: brcmfmac: create and remove the AWDL interface
  2026-11-25 19:02 [PATCH wireless-next v2 0/6] wifi: brcmfmac: AWDL for AirDrop on Apple T2 Macs Andre Eikmeyer
  2026-11-25 19:02 ` [PATCH wireless-next v2 1/6] wifi: brcmfmac: move the interface_create definitions to fwil_types.h Andre Eikmeyer
  2026-11-25 19:02 ` [PATCH wireless-next v2 2/6] wifi: brcmfmac: detect AWDL support of the firmware Andre Eikmeyer
@ 2026-11-25 19:02 ` Andre Eikmeyer
  2026-11-25 19:02 ` [PATCH wireless-next v2 4/6] wifi: brcmfmac: add the AWDL data path Andre Eikmeyer
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Andre Eikmeyer @ 2026-11-25 19:02 UTC (permalink / raw)
  To: arend.vanspriel
  Cc: linux-wireless, brcm80211, brcm80211-dev-list.pdl, linux-kernel,
	Sasha Finkelstein, Sven Peter, Janne Grunau, Aditya Garg,
	Andre Eikmeyer, Yossef Osman

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.

Tested-by: Yossef Osman <Yossef.Osman@proton.me>
Tested-by: Aditya Garg <aditya.garg@linux.dev>
Signed-off-by: Andre Eikmeyer <dev@deq.rocks>
---
 .../broadcom/brcm80211/brcmfmac/Makefile      |   3 +-
 .../broadcom/brcm80211/brcmfmac/awdl.c        | 288 ++++++++++++++++++
 .../broadcom/brcm80211/brcmfmac/awdl.h        |  51 ++++
 .../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, 428 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

diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/Makefile b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/Makefile
index 5281922867b5..68c4121c197f 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/Makefile
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/Makefile
@@ -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
diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/awdl.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/awdl.c
new file mode 100644
index 000000000000..1ef6dd50958f
--- /dev/null
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/awdl.c
@@ -0,0 +1,288 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2026 André Eikmeyer <dev@deq.rocks>
+ *
+ * AWDL interface of the Apple firmware of the BCM4364 and BCM4377.
+ *
+ * The firmware runs Apple Wireless Direct Link itself once the host creates
+ * 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.
+ */
+
+#include <linux/etherdevice.h>
+#include <linux/netdevice.h>
+#include <linux/rtnetlink.h>
+
+#include "core.h"
+#include "debug.h"
+#include "feature.h"
+#include "fwil.h"
+#include "fwil_types.h"
+#include "proto.h"
+#include "awdl.h"
+
+/* The firmware interface index of the AWDL interface */
+#define BRCMF_AWDL_IFIDX		2
+#define BRCMF_AWDL_IF_TIMEOUT		msecs_to_jiffies(2000)
+
+/* The BSSID of all AWDL frames */
+static const u8 brcmf_awdl_bssid[ETH_ALEN] = {
+	0x00, 0x25, 0x00, 0xff, 0x94, 0x73,
+};
+
+void brcmf_awdl_attach(struct brcmf_pub *drvr)
+{
+	spin_lock_init(&drvr->awdl.lock);
+	init_completion(&drvr->awdl.if_event);
+}
+
+/*
+ * Called from the firmware event worker after an interface was added. Takes
+ * the interface if it is the AWDL interface being created.
+ */
+static void brcmf_awdl_drop_if(struct brcmf_pub *drvr, struct brcmf_if *ifp);
+
+bool brcmf_awdl_if_added(struct brcmf_pub *drvr, struct brcmf_if *ifp)
+{
+	struct brcmf_awdl *awdl = &drvr->awdl;
+	bool own, late = false;
+
+	spin_lock(&awdl->lock);
+	own = (awdl->adding || awdl->abandoned) && ifp->ndev &&
+	      ether_addr_equal(ifp->mac_addr, awdl->mac);
+	if (own && awdl->adding) {
+		ifp->awdl = true;
+		strscpy(ifp->ndev->name, "awdl%d", IFNAMSIZ);
+		/* Keeps udev from giving it a name from the bus path */
+		ifp->ndev->name_assign_type = NET_NAME_PREDICTABLE;
+		awdl->ifp = ifp;
+		awdl->adding = false;
+		complete(&awdl->if_event);
+	} else if (own) {
+		awdl->abandoned = false;
+		late = true;
+	}
+	spin_unlock(&awdl->lock);
+
+	/* brcmf_awdl_add() gave up on this interface */
+	if (late)
+		brcmf_awdl_drop_if(drvr, ifp);
+	return own;
+}
+
+/*
+ * 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.
+ */
+bool brcmf_awdl_if_removed(struct brcmf_pub *drvr, struct brcmf_if *ifp)
+{
+	struct brcmf_awdl *awdl = &drvr->awdl;
+	bool requested = false;
+
+	if (!ifp->awdl)
+		return false;
+
+	spin_lock(&awdl->lock);
+	if (awdl->ifp == ifp) {
+		requested = awdl->removing;
+		if (requested)
+			complete(&awdl->if_event);
+		else
+			awdl->ifp = NULL;
+	}
+	spin_unlock(&awdl->lock);
+	if (!requested)
+		brcmf_proto_configure_addr_mode(drvr, ifp->ifidx,
+						ADDR_INDIRECT);
+	return requested;
+}
+
+/* The firmware interface index of the AWDL interface must be free */
+static bool brcmf_awdl_ifidx_used(struct brcmf_pub *drvr)
+{
+	int i;
+
+	for (i = 1; i < BRCMF_MAX_IFS; i++)
+		if (drvr->iflist[i] && drvr->iflist[i]->ifidx == BRCMF_AWDL_IFIDX)
+			return true;
+	return false;
+}
+
+/* Undoes interface_create for an interface that was not attached */
+static void brcmf_awdl_drop_if(struct brcmf_pub *drvr, struct brcmf_if *ifp)
+{
+	struct net_device *ndev = ifp->ndev;
+
+	brcmf_fil_iovar_data_set(ifp, "interface_remove", NULL, 0);
+	brcmf_proto_configure_addr_mode(drvr, ifp->ifidx, ADDR_INDIRECT);
+	brcmf_proto_del_if(drvr, ifp);
+	if (drvr->iflist[ifp->bsscfgidx] == ifp)
+		drvr->iflist[ifp->bsscfgidx] = NULL;
+	if (drvr->if2bss[ifp->ifidx] == ifp->bsscfgidx)
+		drvr->if2bss[ifp->ifidx] = BRCMF_BSSIDX_INVALID;
+	free_netdev(ndev);
+}
+
+/**
+ * brcmf_awdl_add() - create the AWDL interface.
+ *
+ * @drvr: device.
+ * @mac: MAC address of the AWDL interface.
+ * @ndev: set to the network device of the AWDL interface.
+ *
+ * Called with RTNL and the wiphy mutex held. The interface uses the firmware
+ * interface index 2 and the AWDL BSSID 00:25:00:ff:94:73, which the host
+ * passes to the firmware.
+ *
+ * Return: 0 or a negative error code.
+ */
+int brcmf_awdl_add(struct brcmf_pub *drvr, const u8 *mac,
+		   struct net_device **ndev)
+{
+	struct brcmf_awdl *awdl = &drvr->awdl;
+	struct brcmf_if *pri = brcmf_get_ifp(drvr, 0);
+	struct wl_interface_create_v3 req = {};
+	struct brcmf_if *ifp;
+	long left = 0;
+	int err;
+
+	ASSERT_RTNL();
+	lockdep_assert_wiphy(drvr->wiphy);
+
+	if (!pri || !brcmf_feat_is_enabled(pri, BRCMF_FEAT_AWDL))
+		return -EOPNOTSUPP;
+	if (!is_valid_ether_addr(mac))
+		return -EINVAL;
+	if (awdl->detached)
+		return -ENODEV;
+	if (awdl->ifp)
+		return -EBUSY;
+	if (brcmf_awdl_ifidx_used(drvr)) {
+		bphy_err(drvr, "interface index %d is in use, no AWDL\n",
+			 BRCMF_AWDL_IFIDX);
+		return -EBUSY;
+	}
+
+	spin_lock(&awdl->lock);
+	ether_addr_copy(awdl->mac, mac);
+	awdl->adding = true;
+	awdl->abandoned = false;
+	reinit_completion(&awdl->if_event);
+	spin_unlock(&awdl->lock);
+
+	req.ver = WL_INTERFACE_CREATE_VER_3;
+	req.len = sizeof(req);
+	req.fixed_len = sizeof(req);
+	req.iftype = WL_INTERFACE_CREATE_AWDL;
+	req.flags = WL_INTERFACE_MAC_USE | WL_INTERFACE_IF_INDEX_USE |
+		    WL_INTERFACE_BSSID_USE;
+	ether_addr_copy(req.mac_addr, mac);
+	ether_addr_copy(req.bssid, brcmf_awdl_bssid);
+	req.if_index = BRCMF_AWDL_IFIDX;
+	err = brcmf_fil_iovar_data_get(pri, "interface_create", &req,
+				       sizeof(req));
+	if (!err)
+		left = wait_for_completion_timeout(&awdl->if_event,
+						   BRCMF_AWDL_IF_TIMEOUT);
+
+	spin_lock(&awdl->lock);
+	awdl->adding = false;
+	ifp = awdl->ifp;
+	/* The firmware created the interface, its event may still come */
+	if (!err && !ifp)
+		awdl->abandoned = true;
+	spin_unlock(&awdl->lock);
+
+	if (err) {
+		bphy_err(drvr, "AWDL interface_create failed: %d\n", err);
+		return err;
+	}
+	if (!left || !ifp) {
+		bphy_err(drvr, "no interface event for the AWDL interface\n");
+		return -ETIMEDOUT;
+	}
+
+	/* Like an AP, AWDL sends to each peer through its own flowrings */
+	brcmf_proto_configure_addr_mode(drvr, ifp->ifidx, ADDR_DIRECT);
+	SET_NETDEV_DEV(ifp->ndev, wiphy_dev(drvr->wiphy));
+	err = brcmf_net_attach(ifp, true);
+	if (err) {
+		spin_lock(&awdl->lock);
+		awdl->ifp = NULL;
+		spin_unlock(&awdl->lock);
+		brcmf_awdl_drop_if(drvr, ifp);
+		return err;
+	}
+	brcmf_dbg(INFO, "%s: AWDL interface, bsscfgidx %d ifidx %d\n",
+		  ifp->ndev->name, ifp->bsscfgidx, ifp->ifidx);
+	*ndev = ifp->ndev;
+	return 0;
+}
+
+/**
+ * brcmf_awdl_del() - remove the AWDL interface.
+ *
+ * @drvr: device.
+ *
+ * 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.
+ *
+ * Return: 0 or a negative error code.
+ */
+int brcmf_awdl_del(struct brcmf_pub *drvr)
+{
+	struct brcmf_awdl *awdl = &drvr->awdl;
+	struct brcmf_if *ifp;
+	int err;
+
+	ASSERT_RTNL();
+	lockdep_assert_wiphy(drvr->wiphy);
+
+	ifp = awdl->ifp;
+	if (!ifp)
+		return -ENOENT;
+
+	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;
+	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;
+	}
+
+	spin_lock(&awdl->lock);
+	awdl->removing = false;
+	awdl->ifp = NULL;
+	spin_unlock(&awdl->lock);
+
+	brcmf_remove_interface(ifp, true);
+	return err;
+}
+
+/* Called before the interfaces of the device are removed */
+void brcmf_awdl_detach(struct brcmf_pub *drvr)
+{
+	struct brcmf_awdl *awdl = &drvr->awdl;
+
+	rtnl_lock();
+	wiphy_lock(drvr->wiphy);
+	spin_lock(&awdl->lock);
+	awdl->detached = true;
+	awdl->ifp = NULL;
+	spin_unlock(&awdl->lock);
+	wiphy_unlock(drvr->wiphy);
+	rtnl_unlock();
+}
diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/awdl.h b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/awdl.h
new file mode 100644
index 000000000000..361958c278f6
--- /dev/null
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/awdl.h
@@ -0,0 +1,51 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (c) 2026 André Eikmeyer <dev@deq.rocks>
+ *
+ * AWDL interface of the Apple firmware, see awdl.c
+ */
+#ifndef BRCMFMAC_AWDL_H
+#define BRCMFMAC_AWDL_H
+
+#include <linux/completion.h>
+#include <linux/if_ether.h>
+#include <linux/spinlock.h>
+
+struct brcmf_pub;
+struct brcmf_if;
+
+/**
+ * struct brcmf_awdl - AWDL interface of a device.
+ *
+ * @lock: protects @mac, @adding, @abandoned, @removing and @ifp against the
+ *	firmware event worker. Changes of @ifp also hold RTNL and the wiphy
+ *	mutex.
+ * @if_event: completed by the interface event of the AWDL interface.
+ * @mac: MAC address requested for the AWDL interface.
+ * @adding: interface_create was sent, its interface event is awaited.
+ * @abandoned: the interface event did not come in time, an AWDL interface
+ *	that shows up later is removed again.
+ * @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.
+ */
+struct brcmf_awdl {
+	spinlock_t lock; /* AWDL state against the event worker */
+	struct completion if_event;
+	u8 mac[ETH_ALEN];
+	bool adding;
+	bool abandoned;
+	bool removing;
+	bool detached;
+	struct brcmf_if *ifp;
+};
+
+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,
+		   struct net_device **ndev);
+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);
+
+#endif /* BRCMFMAC_AWDL_H */
diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c
index 2035535b753f..5a1937d44c54 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c
@@ -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.
 	 */
diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.c
index 01c386c530f3..5efaec7fc9a4 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.c
@@ -32,8 +32,6 @@
 
 #define MAX_WAIT_FOR_8021X_TX			msecs_to_jiffies(950)
 
-#define BRCMF_BSSIDX_INVALID			-1
-
 #define	RXS_PBPRES				BIT(2)
 
 #define	D11_PHY_HDR_LEN				6
@@ -642,6 +640,42 @@ static const struct net_device_ops brcmf_netdev_ops_pri = {
 	.ndo_set_rx_mode = brcmf_netdev_set_multicast_list
 };
 
+static int brcmf_awdl_netdev_open(struct net_device *ndev)
+{
+	struct brcmf_if *ifp = netdev_priv(ndev);
+
+	if (ifp->drvr->bus_if->state != BRCMF_BUS_UP)
+		return -EAGAIN;
+
+	/* The firmware runs AWDL, the link is there while it exists */
+	netif_carrier_on(ndev);
+	netif_start_queue(ndev);
+	return 0;
+}
+
+static int brcmf_awdl_netdev_stop(struct net_device *ndev)
+{
+	netif_stop_queue(ndev);
+	netif_carrier_off(ndev);
+	return 0;
+}
+
+/*
+ * The AWDL interface gets no multicast list and no MAC address change, the
+ * firmware filters AWDL traffic itself.
+ */
+static const struct net_device_ops brcmf_netdev_ops_awdl = {
+	.ndo_open = brcmf_awdl_netdev_open,
+	.ndo_stop = brcmf_awdl_netdev_stop,
+	.ndo_start_xmit = brcmf_netdev_start_xmit,
+};
+
+static bool brcmf_netdev_is_brcmf(struct net_device *ndev)
+{
+	return ndev->netdev_ops == &brcmf_netdev_ops_pri ||
+	       ndev->netdev_ops == &brcmf_netdev_ops_awdl;
+}
+
 int brcmf_net_attach(struct brcmf_if *ifp, bool locked)
 {
 	struct brcmf_pub *drvr = ifp->drvr;
@@ -653,7 +687,10 @@ int brcmf_net_attach(struct brcmf_if *ifp, bool locked)
 	ndev = ifp->ndev;
 
 	/* set appropriate operations */
-	ndev->netdev_ops = &brcmf_netdev_ops_pri;
+	if (ifp->awdl)
+		ndev->netdev_ops = &brcmf_netdev_ops_awdl;
+	else
+		ndev->netdev_ops = &brcmf_netdev_ops_pri;
 
 	ndev->needed_headroom += drvr->hdrlen;
 	ndev->ethtool_ops = &brcmf_ethtool_ops;
@@ -665,10 +702,12 @@ int brcmf_net_attach(struct brcmf_if *ifp, bool locked)
 	INIT_WORK(&ifp->multicast_work, _brcmf_set_multicast_list);
 	INIT_WORK(&ifp->ndoffload_work, _brcmf_update_ndtable);
 
-	if (locked)
+	if (!locked)
+		err = register_netdev(ndev);
+	else if (ndev->ieee80211_ptr)
 		err = cfg80211_register_netdevice(ndev);
 	else
-		err = register_netdev(ndev);
+		err = register_netdevice(ndev);
 	if (err != 0) {
 		bphy_err(drvr, "couldn't register the net device\n");
 		goto fail;
@@ -689,10 +728,12 @@ int brcmf_net_attach(struct brcmf_if *ifp, bool locked)
 void brcmf_net_detach(struct net_device *ndev, bool locked)
 {
 	if (ndev->reg_state == NETREG_REGISTERED) {
-		if (locked)
+		if (!locked)
+			unregister_netdev(ndev);
+		else if (ndev->ieee80211_ptr)
 			cfg80211_unregister_netdevice(ndev);
 		else
-			unregister_netdev(ndev);
+			unregister_netdevice(ndev);
 	} else {
 		brcmf_cfg80211_free_vif(ndev);
 		free_netdev(ndev);
@@ -943,7 +984,7 @@ static void brcmf_del_if(struct brcmf_pub *drvr, s32 bsscfgidx,
 			netif_stop_queue(ifp->ndev);
 		}
 
-		if (ifp->ndev->netdev_ops == &brcmf_netdev_ops_pri) {
+		if (brcmf_netdev_is_brcmf(ifp->ndev)) {
 			cancel_work_sync(&ifp->multicast_work);
 			cancel_work_sync(&ifp->ndoffload_work);
 		}
@@ -1017,6 +1058,12 @@ static int brcmf_inetaddr_changed(struct notifier_block *nb,
 			return NOTIFY_DONE;
 	}
 
+	/* ARP offload would put the address into the table of the primary
+	 * interface, the AWDL interface has none of its own
+	 */
+	if (ifp->awdl)
+		return NOTIFY_DONE;
+
 	/* check if arp offload is supported */
 	ret = brcmf_fil_iovar_int_get(ifp, "arpoe", &val);
 	if (ret)
@@ -1375,6 +1422,7 @@ int brcmf_attach(struct device *dev)
 		drvr->if2bss[i] = BRCMF_BSSIDX_INVALID;
 
 	mutex_init(&drvr->proto_block);
+	brcmf_awdl_attach(drvr);
 
 	/* Link to bus module */
 	drvr->hdrlen = 0;
@@ -1490,6 +1538,7 @@ void brcmf_detach(struct device *dev)
 	unregister_inet6addr_notifier(&drvr->inet6addr_notifier);
 #endif
 
+	brcmf_awdl_detach(drvr);
 	brcmf_bus_change_state(bus_if, BRCMF_BUS_DOWN);
 	/* make sure primary interface removed last */
 	for (i = BRCMF_MAX_IFS - 1; i > -1; i--) {
diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.h b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.h
index 320473970df3..b04be54d412d 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.h
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.h
@@ -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);
diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fweh.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fweh.c
index 034f90ad6cbe..297590cebbdf 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fweh.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fweh.c
@@ -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) {
-- 
2.56.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH wireless-next v2 4/6] wifi: brcmfmac: add the AWDL data path
  2026-11-25 19:02 [PATCH wireless-next v2 0/6] wifi: brcmfmac: AWDL for AirDrop on Apple T2 Macs Andre Eikmeyer
                   ` (2 preceding siblings ...)
  2026-11-25 19:02 ` [PATCH wireless-next v2 3/6] wifi: brcmfmac: create and remove the AWDL interface Andre Eikmeyer
@ 2026-11-25 19:02 ` Andre Eikmeyer
  2026-11-25 19:02 ` [PATCH wireless-next v2 5/6] wifi: brcmfmac: add vendor commands for AWDL Andre Eikmeyer
  2026-11-25 19:02 ` [PATCH wireless-next v2 6/6] wifi: brcmfmac: pass AWDL frames and role changes to user space Andre Eikmeyer
  5 siblings, 0 replies; 7+ messages in thread
From: Andre Eikmeyer @ 2026-11-25 19:02 UTC (permalink / raw)
  To: arend.vanspriel
  Cc: linux-wireless, brcm80211, brcm80211-dev-list.pdl, linux-kernel,
	Sasha Finkelstein, Sven Peter, Janne Grunau, Aditya Garg,
	Andre Eikmeyer, Yossef Osman

The 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.

Tested-by: Yossef Osman <Yossef.Osman@proton.me>
Tested-by: Aditya Garg <aditya.garg@linux.dev>
Acked-by: Arend van Spriel <arend.vanspriel@broadcom.com>
Signed-off-by: Andre Eikmeyer <dev@deq.rocks>
---
 .../broadcom/brcm80211/brcmfmac/awdl.c        | 87 +++++++++++++++++++
 .../broadcom/brcm80211/brcmfmac/awdl.h        |  9 ++
 .../broadcom/brcm80211/brcmfmac/core.c        | 17 ++++
 3 files changed, 113 insertions(+)

diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/awdl.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/awdl.c
index 1ef6dd50958f..607cc8dc9c75 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/awdl.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/awdl.c
@@ -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,
@@ -272,6 +294,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)
 {
diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/awdl.h b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/awdl.h
index 361958c278f6..d41a79e42b54 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/awdl.h
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/awdl.h
@@ -13,6 +13,8 @@
 
 struct brcmf_pub;
 struct brcmf_if;
+struct net_device;
+struct sk_buff;
 
 /**
  * struct brcmf_awdl - AWDL interface of a device.
@@ -28,6 +30,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 */
@@ -38,8 +41,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,
@@ -47,5 +54,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 */
diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.c
index 5efaec7fc9a4..859f97f8e98b 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.c
@@ -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 */
-- 
2.56.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH wireless-next v2 5/6] wifi: brcmfmac: add vendor commands for AWDL
  2026-11-25 19:02 [PATCH wireless-next v2 0/6] wifi: brcmfmac: AWDL for AirDrop on Apple T2 Macs Andre Eikmeyer
                   ` (3 preceding siblings ...)
  2026-11-25 19:02 ` [PATCH wireless-next v2 4/6] wifi: brcmfmac: add the AWDL data path Andre Eikmeyer
@ 2026-11-25 19:02 ` Andre Eikmeyer
  2026-11-25 19:02 ` [PATCH wireless-next v2 6/6] wifi: brcmfmac: pass AWDL frames and role changes to user space Andre Eikmeyer
  5 siblings, 0 replies; 7+ messages in thread
From: Andre Eikmeyer @ 2026-11-25 19:02 UTC (permalink / raw)
  To: arend.vanspriel
  Cc: linux-wireless, brcm80211, brcm80211-dev-list.pdl, linux-kernel,
	Sasha Finkelstein, Sven Peter, Janne Grunau, Aditya Garg,
	Andre Eikmeyer, Yossef Osman

AWDL 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 MacBookAir 9,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.

Tested-by: Yossef Osman <Yossef.Osman@proton.me>
Tested-by: Aditya Garg <aditya.garg@linux.dev>
Signed-off-by: Andre Eikmeyer <dev@deq.rocks>
---
 .../broadcom/brcm80211/brcmfmac/awdl.c        | 644 +++++++++++++++++-
 .../broadcom/brcm80211/brcmfmac/awdl.h        |  53 ++
 .../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      |  92 +++
 7 files changed, 881 insertions(+), 6 deletions(-)

diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/awdl.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/awdl.c
index 607cc8dc9c75..a3db05fab216 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/awdl.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/awdl.c
@@ -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,126 @@ 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, followed by 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_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);
+	wiphy_delayed_work_init(&awdl->aftx_work, brcmf_awdl_aftx_work);
+	wiphy_delayed_work_init(&awdl->settle_work, brcmf_awdl_settle_work);
 }
 
 /*
@@ -64,6 +184,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)
 {
@@ -116,9 +238,12 @@ bool brcmf_awdl_if_removed(struct brcmf_pub *drvr, struct brcmf_if *ifp)
 			awdl->ifp = NULL;
 	}
 	spin_unlock(&awdl->lock);
-	if (!requested)
+	if (!requested) {
 		brcmf_proto_configure_addr_mode(drvr, ifp->ifidx,
 						ADDR_INDIRECT);
+		brcmf_awdl_send_result(drvr, BRCMF_VNDR_EVTS_AWDL_STOPPED,
+				       -ENOLINK, NULL);
+	}
 	return requested;
 }
 
@@ -268,6 +393,8 @@ 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);
@@ -359,6 +486,510 @@ 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 before system sleep, with RTNL and the wiphy
+ * mutex held, while the firmware still takes commands. A queued operation is
+ * dropped.
+ */
+void brcmf_awdl_suspend(struct brcmf_pub *drvr)
+{
+	struct brcmf_awdl *awdl = &drvr->awdl;
+	int err;
+
+	spin_lock(&awdl->lock);
+	awdl->op = BRCMF_AWDL_OP_NONE;
+	spin_unlock(&awdl->lock);
+	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)
 {
@@ -366,10 +997,17 @@ 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);
 }
diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/awdl.h b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/awdl.h
index d41a79e42b54..d8bc90bea290 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/awdl.h
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/awdl.h
@@ -10,12 +10,21 @@
 #include <linux/completion.h>
 #include <linux/if_ether.h>
 #include <linux/spinlock.h>
+#include <linux/workqueue.h>
+#include <net/cfg80211.h>
+#include <net/netlink.h>
 
 struct brcmf_pub;
 struct brcmf_if;
 struct net_device;
 struct sk_buff;
 
+enum brcmf_awdl_op {
+	BRCMF_AWDL_OP_NONE,
+	BRCMF_AWDL_OP_START,
+	BRCMF_AWDL_OP_STOP,
+};
+
 /**
  * struct brcmf_awdl - AWDL interface of a device.
  *
@@ -31,6 +40,22 @@ struct sk_buff;
  * @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.
+ * @ctrl_work: creates or removes the AWDL interface for the vendor commands,
+ *	which run without RTNL.
+ * @op: operation of @ctrl_work, under @lock.
+ * @start_mac: MAC address for %BRCMF_AWDL_OP_START.
+ * @payload: awdl_payload with the TLVs of user space.
+ * @payload_len: length of @payload.
+ * @oob: awdl_oob_af_auto with the TLVs of user space.
+ * @oob_len: length of @oob.
+ * @has_master: another device is the master.
+ * @master: MAC address of the master.
+ * @master_metric: metric of the master.
+ * @master_distance: hops to the master.
+ * @aftx_work: changes the firmware parameters 500 ms after the start.
+ * @settle_work: changes the firmware parameters 5 s after the start.
+ *
+ * The members from @start_mac on are protected by the wiphy mutex.
  */
 struct brcmf_awdl {
 	spinlock_t lock; /* AWDL state against the event worker */
@@ -42,6 +67,19 @@ struct brcmf_awdl {
 	bool detached;
 	struct brcmf_if *ifp;
 	u16 tx_seq;
+	struct work_struct ctrl_work;
+	enum brcmf_awdl_op op;
+	u8 start_mac[ETH_ALEN];
+	u8 *payload;
+	u32 payload_len;
+	u8 *oob;
+	u32 oob_len;
+	bool has_master;
+	u8 master[ETH_ALEN];
+	u32 master_metric;
+	u8 master_distance;
+	struct wiphy_delayed_work aftx_work;
+	struct wiphy_delayed_work settle_work;
 };
 
 /* Length of the LLC/SNAP and AWDL data header of AWDL data frames */
@@ -52,9 +90,24 @@ void brcmf_awdl_detach(struct brcmf_pub *drvr);
 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);
 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);
 
+extern const struct nla_policy brcmf_awdl_vndr_policy[];
+int brcmf_awdl_vndr_start(struct wiphy *wiphy, struct wireless_dev *wdev,
+			  const void *data, int len);
+int brcmf_awdl_vndr_stop(struct wiphy *wiphy, struct wireless_dev *wdev,
+			 const void *data, int len);
+int brcmf_awdl_vndr_set_frames(struct wiphy *wiphy, struct wireless_dev *wdev,
+			       const void *data, int len);
+int brcmf_awdl_vndr_set_sync(struct wiphy *wiphy, struct wireless_dev *wdev,
+			     const void *data, int len);
+int brcmf_awdl_vndr_peer_add(struct wiphy *wiphy, struct wireless_dev *wdev,
+			     const void *data, int len);
+int brcmf_awdl_vndr_peer_del(struct wiphy *wiphy, struct wireless_dev *wdev,
+			     const void *data, int len);
+
 #endif /* BRCMFMAC_AWDL_H */
diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c
index 5a1937d44c54..edba69e22b6c 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c
@@ -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);
diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.c
index 898a991885a8..e2ec4da7c7f3 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.c
@@ -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;
diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.h b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.h
index 8574731418fc..2721a1d50cbd 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.h
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.h
@@ -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,
diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/vendor.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/vendor.c
index d07e7c7355d9..34215aa4fe70 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/vendor.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/vendor.c
@@ -15,6 +15,7 @@
 #include "cfg80211.h"
 #include "vendor.h"
 #include "fwil.h"
+#include "awdl.h"
 
 static int brcmf_cfg80211_vndr_cmds_dcmd_handler(struct wiphy *wiphy,
 						 struct wireless_dev *wdev,
@@ -115,4 +116,85 @@ const struct wiphy_vendor_command brcmf_vendor_cmds[] = {
 		.policy = VENDOR_CMD_RAW_DATA,
 		.doit = brcmf_cfg80211_vndr_cmds_dcmd_handler
 	},
+	{
+		{
+			.vendor_id = BROADCOM_OUI,
+			.subcmd = BRCMF_VNDR_CMDS_AWDL_START
+		},
+		.flags = WIPHY_VENDOR_CMD_NEED_WDEV |
+			 WIPHY_VENDOR_CMD_NEED_NETDEV,
+		.policy = brcmf_awdl_vndr_policy,
+		.maxattr = BRCMF_AWDL_ATTR_MAX,
+		.doit = brcmf_awdl_vndr_start
+	},
+	{
+		{
+			.vendor_id = BROADCOM_OUI,
+			.subcmd = BRCMF_VNDR_CMDS_AWDL_STOP
+		},
+		.flags = WIPHY_VENDOR_CMD_NEED_WDEV |
+			 WIPHY_VENDOR_CMD_NEED_NETDEV,
+		.policy = brcmf_awdl_vndr_policy,
+		.maxattr = BRCMF_AWDL_ATTR_MAX,
+		.doit = brcmf_awdl_vndr_stop
+	},
+	{
+		{
+			.vendor_id = BROADCOM_OUI,
+			.subcmd = BRCMF_VNDR_CMDS_AWDL_SET_FRAMES
+		},
+		.flags = WIPHY_VENDOR_CMD_NEED_WDEV |
+			 WIPHY_VENDOR_CMD_NEED_NETDEV,
+		.policy = brcmf_awdl_vndr_policy,
+		.maxattr = BRCMF_AWDL_ATTR_MAX,
+		.doit = brcmf_awdl_vndr_set_frames
+	},
+	{
+		{
+			.vendor_id = BROADCOM_OUI,
+			.subcmd = BRCMF_VNDR_CMDS_AWDL_SET_SYNC
+		},
+		.flags = WIPHY_VENDOR_CMD_NEED_WDEV |
+			 WIPHY_VENDOR_CMD_NEED_NETDEV,
+		.policy = brcmf_awdl_vndr_policy,
+		.maxattr = BRCMF_AWDL_ATTR_MAX,
+		.doit = brcmf_awdl_vndr_set_sync
+	},
+	{
+		{
+			.vendor_id = BROADCOM_OUI,
+			.subcmd = BRCMF_VNDR_CMDS_AWDL_PEER_ADD
+		},
+		.flags = WIPHY_VENDOR_CMD_NEED_WDEV |
+			 WIPHY_VENDOR_CMD_NEED_NETDEV,
+		.policy = brcmf_awdl_vndr_policy,
+		.maxattr = BRCMF_AWDL_ATTR_MAX,
+		.doit = brcmf_awdl_vndr_peer_add
+	},
+	{
+		{
+			.vendor_id = BROADCOM_OUI,
+			.subcmd = BRCMF_VNDR_CMDS_AWDL_PEER_DEL
+		},
+		.flags = WIPHY_VENDOR_CMD_NEED_WDEV |
+			 WIPHY_VENDOR_CMD_NEED_NETDEV,
+		.policy = brcmf_awdl_vndr_policy,
+		.maxattr = BRCMF_AWDL_ATTR_MAX,
+		.doit = brcmf_awdl_vndr_peer_del
+	},
+};
+
+const struct nl80211_vendor_cmd_info brcmf_vendor_events[] = {
+	[BRCMF_VNDR_EVTS_UNSPEC] = {
+		.vendor_id = BROADCOM_OUI,
+		.subcmd = BRCMF_VNDR_EVTS_UNSPEC
+	},
+	[BRCMF_VNDR_EVTS_AWDL_STARTED] = {
+		.vendor_id = BROADCOM_OUI,
+		.subcmd = BRCMF_VNDR_EVTS_AWDL_STARTED
+	},
+	[BRCMF_VNDR_EVTS_AWDL_STOPPED] = {
+		.vendor_id = BROADCOM_OUI,
+		.subcmd = BRCMF_VNDR_EVTS_AWDL_STOPPED
+	},
 };
diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/vendor.h b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/vendor.h
index 418f33ea6fd3..63e59960802c 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/vendor.h
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/vendor.h
@@ -8,12 +8,103 @@
 
 #define BROADCOM_OUI	0x001018
 
+/**
+ * enum brcmf_vndr_cmds - vendor commands of the Broadcom OUI
+ *
+ * @BRCMF_VNDR_CMDS_UNSPEC: not used.
+ * @BRCMF_VNDR_CMDS_DCMD: firmware command, see struct brcmf_vndr_dcmd_hdr.
+ * @BRCMF_VNDR_CMDS_AWDL_START: create the AWDL interface with
+ *	%BRCMF_AWDL_ATTR_ADDR and start AWDL with the TLVs of
+ *	%BRCMF_AWDL_ATTR_PAYLOAD and %BRCMF_AWDL_ATTR_OOB. Runs asynchronously,
+ *	the result comes with %BRCMF_VNDR_EVTS_AWDL_STARTED.
+ * @BRCMF_VNDR_CMDS_AWDL_STOP: stop AWDL and remove the AWDL interface. Runs
+ *	asynchronously, the result comes with %BRCMF_VNDR_EVTS_AWDL_STOPPED.
+ * @BRCMF_VNDR_CMDS_AWDL_SET_FRAMES: replace the TLVs of
+ *	%BRCMF_AWDL_ATTR_PAYLOAD and %BRCMF_AWDL_ATTR_OOB.
+ * @BRCMF_VNDR_CMDS_AWDL_SET_SYNC: synchronize to the master of
+ *	%BRCMF_AWDL_ATTR_MASTER, %BRCMF_AWDL_ATTR_MASTER_METRIC and
+ *	%BRCMF_AWDL_ATTR_MASTER_DISTANCE. Without %BRCMF_AWDL_ATTR_MASTER the
+ *	device is its own master.
+ * @BRCMF_VNDR_CMDS_AWDL_PEER_ADD: add the peer %BRCMF_AWDL_ATTR_ADDR, data
+ *	frames to it are sent from then on. %BRCMF_AWDL_ATTR_PEER_IES gives its
+ *	HT and VHT capabilities, sent again it updates them.
+ * @BRCMF_VNDR_CMDS_AWDL_PEER_DEL: remove the peer %BRCMF_AWDL_ATTR_ADDR.
+ * @BRCMF_VNDR_CMDS_LAST: number of vendor commands plus one.
+ *
+ * The AWDL commands are sent to the primary interface. Election, peer
+ * discovery and services are left to user space, the firmware sends and
+ * receives the AWDL frames and data.
+ */
 enum brcmf_vndr_cmds {
 	BRCMF_VNDR_CMDS_UNSPEC,
 	BRCMF_VNDR_CMDS_DCMD,
+	BRCMF_VNDR_CMDS_AWDL_START,
+	BRCMF_VNDR_CMDS_AWDL_STOP,
+	BRCMF_VNDR_CMDS_AWDL_SET_FRAMES,
+	BRCMF_VNDR_CMDS_AWDL_SET_SYNC,
+	BRCMF_VNDR_CMDS_AWDL_PEER_ADD,
+	BRCMF_VNDR_CMDS_AWDL_PEER_DEL,
 	BRCMF_VNDR_CMDS_LAST
 };
 
+/**
+ * enum brcmf_vndr_evts - vendor events of the Broadcom OUI
+ *
+ * @BRCMF_VNDR_EVTS_UNSPEC: not used.
+ * @BRCMF_VNDR_EVTS_AWDL_STARTED: result of %BRCMF_VNDR_CMDS_AWDL_START with
+ *	%BRCMF_AWDL_ATTR_STATUS and, on success, %BRCMF_AWDL_ATTR_IFINDEX.
+ * @BRCMF_VNDR_EVTS_AWDL_STOPPED: the AWDL interface was removed, with
+ *	%BRCMF_AWDL_ATTR_STATUS. After %BRCMF_VNDR_CMDS_AWDL_STOP and before
+ *	system sleep the status is 0 or the error of the removal. When the
+ *	firmware removed the interface on its own it is -%ENOLINK.
+ * @BRCMF_VNDR_EVTS_LAST: number of vendor events.
+ *
+ * The value of an event is its index in the vendor events and its vendor
+ * subcommand.
+ */
+enum brcmf_vndr_evts {
+	BRCMF_VNDR_EVTS_UNSPEC,
+	BRCMF_VNDR_EVTS_AWDL_STARTED,
+	BRCMF_VNDR_EVTS_AWDL_STOPPED,
+	BRCMF_VNDR_EVTS_LAST
+};
+
+/**
+ * enum brcmf_awdl_attrs - attributes of the AWDL vendor commands and events
+ *
+ * @BRCMF_AWDL_ATTR_UNSPEC: not used.
+ * @BRCMF_AWDL_ATTR_ADDR: MAC address, of the AWDL interface or of a peer.
+ * @BRCMF_AWDL_ATTR_PAYLOAD: AWDL TLVs for the firmware parameter
+ *	awdl_payload.
+ * @BRCMF_AWDL_ATTR_OOB: AWDL TLVs for the firmware parameter
+ *	awdl_oob_af_auto.
+ * @BRCMF_AWDL_ATTR_MASTER: MAC address of the master (u8[6]).
+ * @BRCMF_AWDL_ATTR_MASTER_METRIC: metric of the master (u32).
+ * @BRCMF_AWDL_ATTR_MASTER_DISTANCE: hops from this device to the master (u8).
+ * @BRCMF_AWDL_ATTR_STATUS: 0 or a negative error code (s32).
+ * @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_AFTER_LAST: internal use.
+ * @BRCMF_AWDL_ATTR_MAX: highest attribute.
+ */
+enum brcmf_awdl_attrs {
+	BRCMF_AWDL_ATTR_UNSPEC,
+
+	BRCMF_AWDL_ATTR_ADDR,
+	BRCMF_AWDL_ATTR_PAYLOAD,
+	BRCMF_AWDL_ATTR_OOB,
+	BRCMF_AWDL_ATTR_MASTER,
+	BRCMF_AWDL_ATTR_MASTER_METRIC,
+	BRCMF_AWDL_ATTR_MASTER_DISTANCE,
+	BRCMF_AWDL_ATTR_STATUS,
+	BRCMF_AWDL_ATTR_IFINDEX,
+	BRCMF_AWDL_ATTR_PEER_IES,
+
+	__BRCMF_AWDL_ATTR_AFTER_LAST,
+	BRCMF_AWDL_ATTR_MAX = __BRCMF_AWDL_ATTR_AFTER_LAST - 1
+};
+
 /**
  * enum brcmf_nlattrs - nl80211 message attributes
  *
@@ -49,5 +140,6 @@ struct brcmf_vndr_dcmd_hdr {
 };
 
 extern const struct wiphy_vendor_command brcmf_vendor_cmds[];
+extern const struct nl80211_vendor_cmd_info brcmf_vendor_events[];
 
 #endif /* _vendor_h_ */
-- 
2.56.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH wireless-next v2 6/6] wifi: brcmfmac: pass AWDL frames and role changes to user space
  2026-11-25 19:02 [PATCH wireless-next v2 0/6] wifi: brcmfmac: AWDL for AirDrop on Apple T2 Macs Andre Eikmeyer
                   ` (4 preceding siblings ...)
  2026-11-25 19:02 ` [PATCH wireless-next v2 5/6] wifi: brcmfmac: add vendor commands for AWDL Andre Eikmeyer
@ 2026-11-25 19:02 ` Andre Eikmeyer
  5 siblings, 0 replies; 7+ messages in thread
From: Andre Eikmeyer @ 2026-11-25 19:02 UTC (permalink / raw)
  To: arend.vanspriel
  Cc: linux-wireless, brcm80211, brcm80211-dev-list.pdl, linux-kernel,
	Sasha Finkelstein, Sven Peter, Janne Grunau, Aditya Garg,
	Andre Eikmeyer, Yossef Osman

User 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.

Tested-by: Yossef Osman <Yossef.Osman@proton.me>
Tested-by: Aditya Garg <aditya.garg@linux.dev>
Signed-off-by: Andre Eikmeyer <dev@deq.rocks>
---
 .../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(-)

diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/awdl.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/awdl.c
index a3db05fab216..aed199b0f307 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/awdl.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/awdl.c
@@ -711,17 +711,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) ||
@@ -808,6 +904,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 */
diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/awdl.h b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/awdl.h
index d8bc90bea290..47dab408150d 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/awdl.h
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/awdl.h
@@ -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,
@@ -91,6 +92,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);
diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fweh.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fweh.c
index 297590cebbdf..6cfe2cf1e22c 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fweh.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fweh.c
@@ -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);
diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fweh.h b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fweh.h
index 53c4b58e6323..2faa4215e9ab 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fweh.h
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fweh.h
@@ -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),
diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/vendor.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/vendor.c
index 34215aa4fe70..c4a8b68e520d 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/vendor.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/vendor.c
@@ -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
+	},
 };
diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/vendor.h b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/vendor.h
index 63e59960802c..889d1c43e72f 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/vendor.h
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/vendor.h
@@ -57,6 +57,11 @@ enum brcmf_vndr_cmds {
  *	%BRCMF_AWDL_ATTR_STATUS. After %BRCMF_VNDR_CMDS_AWDL_STOP and before
  *	system sleep the status is 0 or the error of the removal. When the
  *	firmware removed the interface on its own it is -%ENOLINK.
+ * @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
@@ -66,6 +71,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
 };
 
@@ -85,6 +92,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.
  */
@@ -100,6 +110,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
diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/wcc/core.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/wcc/core.c
index e14b5530f720..0a14f318f14a 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/wcc/core.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/wcc/core.c
@@ -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,
 };
-- 
2.56.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-11-25 19:03 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-25 19:02 [PATCH wireless-next v2 0/6] wifi: brcmfmac: AWDL for AirDrop on Apple T2 Macs Andre Eikmeyer
2026-11-25 19:02 ` [PATCH wireless-next v2 1/6] wifi: brcmfmac: move the interface_create definitions to fwil_types.h Andre Eikmeyer
2026-11-25 19:02 ` [PATCH wireless-next v2 2/6] wifi: brcmfmac: detect AWDL support of the firmware Andre Eikmeyer
2026-11-25 19:02 ` [PATCH wireless-next v2 3/6] wifi: brcmfmac: create and remove the AWDL interface Andre Eikmeyer
2026-11-25 19:02 ` [PATCH wireless-next v2 4/6] wifi: brcmfmac: add the AWDL data path Andre Eikmeyer
2026-11-25 19:02 ` [PATCH wireless-next v2 5/6] wifi: brcmfmac: add vendor commands for AWDL Andre Eikmeyer
2026-11-25 19:02 ` [PATCH wireless-next v2 6/6] wifi: brcmfmac: pass AWDL frames and role changes to user space Andre Eikmeyer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®