[RFC PATCH v2 11/23] nl80211: Support key operations on wdev-only interfaces

Peddolla Harshavardhan Reddy peddolla.reddy at oss.qualcomm.com
Thu Apr 2 05:24:16 PDT 2026


The set_key implementation always uses nl80211_ifindex_msg()
which includes NL80211_ATTR_IFINDEX in the netlink message.
Non-netdev virtual interfaces such as PD (Proximity Detection)
are created without a real ifindex, so key install and delete
commands fail when ifindex is zero.

Use nl80211_cmd_msg() instead when ifindex is zero to include
NL80211_ATTR_WDEV in the message for SET_KEY, DEL_KEY, and
NEW_KEY commands. Also skip NL80211_CMD_SET_INTERFACE in
nl80211_set_mode() for non-netdev interface types (P2P_DEVICE,
NAN, PD) since these interfaces are created with the correct
type and NL80211_CMD_SET_INTERFACE requires a valid ifindex.

Signed-off-by: Peddolla Harshavardhan Reddy <peddolla.reddy at oss.qualcomm.com>
---
 src/drivers/driver_nl80211.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/src/drivers/driver_nl80211.c b/src/drivers/driver_nl80211.c
index 8acf0243d..aa1ea3c61 100644
--- a/src/drivers/driver_nl80211.c
+++ b/src/drivers/driver_nl80211.c
@@ -3958,7 +3958,10 @@ static int wpa_driver_nl80211_set_key(struct i802_bss *bss,
 	    KEY_FLAG_PAIRWISE_RX_TX_MODIFY) {
 		wpa_printf(MSG_DEBUG,
 			   "nl80211: SET_KEY (pairwise RX/TX modify)");
-		msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_SET_KEY);
+		msg = ifindex ?
+			nl80211_ifindex_msg(drv, ifindex, 0,
+					    NL80211_CMD_SET_KEY) :
+			nl80211_cmd_msg(bss, 0, NL80211_CMD_SET_KEY);
 		if (!msg)
 			goto fail2;
 	} else if (alg == WPA_ALG_NONE && (key_flag & KEY_FLAG_RX_TX)) {
@@ -3968,7 +3971,10 @@ static int wpa_driver_nl80211_set_key(struct i802_bss *bss,
 		goto fail2;
 	} else if (alg == WPA_ALG_NONE) {
 		wpa_printf(MSG_DEBUG, "nl80211: DEL_KEY");
-		msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_DEL_KEY);
+		msg = ifindex ?
+			nl80211_ifindex_msg(drv, ifindex, 0,
+					    NL80211_CMD_DEL_KEY) :
+			nl80211_cmd_msg(bss, 0, NL80211_CMD_DEL_KEY);
 		if (!msg)
 			goto fail2;
 	} else {
@@ -3980,7 +3986,10 @@ static int wpa_driver_nl80211_set_key(struct i802_bss *bss,
 			goto fail2;
 		}
 		wpa_printf(MSG_DEBUG, "nl80211: NEW_KEY");
-		msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_NEW_KEY);
+		msg = ifindex ?
+			nl80211_ifindex_msg(drv, ifindex, 0,
+					    NL80211_CMD_NEW_KEY) :
+			nl80211_cmd_msg(bss, 0, NL80211_CMD_NEW_KEY);
 		if (!msg)
 			goto fail2;
 		if (nla_put(key_msg, NL80211_KEY_DATA, key_len, key) ||
-- 
2.34.1




More information about the Hostap mailing list