There is some ambiguity in how various drivers support
NL80211_CMD_SET_INTERFACE on devices where the underlying netdev is UP.
mac80211 for example supports this if the underlying driver provides a
change_interface operation.  However, most devices do not.  For FullMac
devices, the situation is even less clear.

This patch introduces a new feature flag that lets userspace know
whether it can expect a mode change (via SET_INTERFACE) to work while
the device is still UP or it should bring down the device first.

This commit also updates the documentation for SET_INTERFACE with hints
as to how it should be used.

Signed-off-by: Denis Kenzior <[email protected]>
---
 include/uapi/linux/nl80211.h | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

diff --git a/include/uapi/linux/nl80211.h b/include/uapi/linux/nl80211.h
index bf7c4222f512..a9ca2fe67f52 100644
--- a/include/uapi/linux/nl80211.h
+++ b/include/uapi/linux/nl80211.h
@@ -275,6 +275,29 @@
  *     single %NL80211_ATTR_IFINDEX is supported.
  * @NL80211_CMD_SET_INTERFACE: Set type of a virtual interface, requires
  *     %NL80211_ATTR_IFINDEX and %NL80211_ATTR_IFTYPE.
+ *
+ *     Note that it is driver-dependent whether a SET_INTERFACE will be
+ *     allowed if the underlying netdev is currently UP.  Userspace
+ *     can obtain a hint as to whether this is allowed by looking at
+ *     the %NL80211_EXT_FEATURE_LIVE_IFTYPE_CHANGE, but certain restrictions
+ *     will still apply.
+ *
+ *     Prior to Kernel 5.4, userspace applications should implement the
+ *     following behavior:
+ *             1. (Optionally) Attempt SET_INTERFACE on a wireless device
+ *                with the underlying netdev in the UP state.  If -EBUSY
+ *                is returned proceed to 2.  Note that a SET_INTERFACE
+ *                which results in -EBUSY might still result in other
+ *                side-effects, such as Deauthentication, exiting AP mode,
+ *                etc.
+ *             2. Bring the netdev DOWN via RTNL
+ *             3. Attempt SET_INTERFACE on the underlying netdev in the DOWN
+ *                state.  If successful, proceed to 4.
+ *             4. Bring the netdev UP via RTNL
+ *
+ *     Note that bringing down the device might trigger a firmware reset /
+ *     power cycling and/or other effects that are driver dependent.
+ *
  * @NL80211_CMD_NEW_INTERFACE: Newly created virtual interface or response
  *     to %NL80211_CMD_GET_INTERFACE. Has %NL80211_ATTR_IFINDEX,
  *     %NL80211_ATTR_WIPHY and %NL80211_ATTR_IFTYPE attributes. Can also
@@ -5481,6 +5504,18 @@ enum nl80211_feature_flags {
  * @NL80211_EXT_FEATURE_SAE_OFFLOAD: Device wants to do SAE authentication in
  *     station mode (SAE password is passed as part of the connect command).
  *
+ * @NL80211_EXT_FEATURE_LIVE_IFTYPE_CHANGE: This device supports switching
+ *     the IFTYPE of an interface without having to bring the device DOWN
+ *     first via RTNL.  Exact semantics of this feature is driver
+ *     implementation dependent.  For mac80211, the following restrictions
+ *     apply:
+ *             - Only devices currently in IFTYPE AP, P2P_GO, P2P_CLIENT,
+ *               STATION, ADHOC and OCB can be switched.
+ *             - The target IFTYPE must be one of: AP, P2P_GO, P2P_CLIENT,
+ *               STATION, ADHOC or OCB.
+ *     Other drivers are expected to follow similar restrictions.
+ *     This flag was introduced in Kernel v5.4
+ *
  * @NUM_NL80211_EXT_FEATURES: number of extended features.
  * @MAX_NL80211_EXT_FEATURES: highest extended feature index.
  */
@@ -5526,6 +5561,7 @@ enum nl80211_ext_feature_index {
        NL80211_EXT_FEATURE_EXT_KEY_ID,
        NL80211_EXT_FEATURE_STA_TX_PWR,
        NL80211_EXT_FEATURE_SAE_OFFLOAD,
+       NL80211_EXT_FEATURE_LIVE_IFTYPE_CHANGE,
 
        /* add new features before the definition below */
        NUM_NL80211_EXT_FEATURES,
-- 
2.19.2

Reply via email to