]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
wifi: cfg80211: add start/stop proximity detection commands
authorPeddolla Harshavardhan Reddy <peddolla.reddy@oss.qualcomm.com>
Mon, 20 Apr 2026 09:08:47 +0000 (14:38 +0530)
committerJohannes Berg <johannes.berg@intel.com>
Tue, 5 May 2026 11:36:30 +0000 (13:36 +0200)
Currently, the proximity detection (PD) interface type has no
start/stop commands defined, preventing user space from
controlling PD operations through the nl80211 interface.

Add NL80211_CMD_START_PD and NL80211_CMD_STOP_PD commands to
allow user space to start and stop a PD interface. Add the
corresponding start_pd and stop_pd operations to cfg80211_ops
and ieee80211_ops, along with nl80211 command handlers, rdev
wrappers, and tracing support. Validate that drivers advertising
PD interface support implement the required operations. Handle
PD interface teardown during device unregistration and when
the interface leaves the network.

Signed-off-by: Peddolla Harshavardhan Reddy <peddolla.reddy@oss.qualcomm.com>
Link: https://patch.msgid.link/20260420090856.2152905-5-peddolla.reddy@oss.qualcomm.com
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
include/net/cfg80211.h
include/uapi/linux/nl80211.h
net/wireless/core.c
net/wireless/core.h
net/wireless/nl80211.c
net/wireless/rdev-ops.h
net/wireless/trace.h

index 897dbe325b7e5a65a650e4ee19e5389ec204da34..8f010af419bf788dc0605b135eb45f2899a80b96 100644 (file)
@@ -5088,6 +5088,9 @@ struct mgmt_frame_regs {
  *     links by calling cfg80211_mlo_reconf_add_done(). When calling
  *     cfg80211_mlo_reconf_add_done() the bss pointer must be given for each
  *     link for which MLO reconfiguration 'add' operation was requested.
+ *
+ * @start_pd: Start the PD interface.
+ * @stop_pd: Stop the PD interface.
  */
 struct cfg80211_ops {
        int     (*suspend)(struct wiphy *wiphy, struct cfg80211_wowlan *wow);
@@ -5464,6 +5467,8 @@ struct cfg80211_ops {
                                   struct cfg80211_ml_reconf_req *req);
        int     (*set_epcs)(struct wiphy *wiphy, struct net_device *dev,
                            bool val);
+       int     (*start_pd)(struct wiphy *wiphy, struct wireless_dev *wdev);
+       void    (*stop_pd)(struct wiphy *wiphy, struct wireless_dev *wdev);
 };
 
 /*
index 69e13cd7978a1618f628d39d2bc9ed02813e0130..704607824b8a2b1eaaa12c10cce308f5751a608c 100644 (file)
  *     identifying the evacuated channel.
  *     User space may reconfigure the local schedule in response to this
  *     notification.
+ * @NL80211_CMD_START_PD: Start PD operation, identified by its
+ *     %NL80211_ATTR_WDEV interface. This interface must have been previously
+ *     created with %NL80211_CMD_NEW_INTERFACE.
+ * @NL80211_CMD_STOP_PD: Stop the PD operation, identified by
+ *     its %NL80211_ATTR_WDEV interface.
+ *
  * @NL80211_CMD_MAX: highest used command number
  * @__NL80211_CMD_AFTER_LAST: internal use
  */
@@ -1694,6 +1700,9 @@ enum nl80211_commands {
 
        NL80211_CMD_NAN_CHANNEL_EVAC,
 
+       NL80211_CMD_START_PD,
+       NL80211_CMD_STOP_PD,
+
        /* add new commands above here */
 
        /* used to define NL80211_CMD_MAX below */
index 9a6f8ffe7ba9dc2b93c7a20662ecb4a2d00d060d..4dd1981a36296c8c0569e1efbc3a7c71bb0e364a 100644 (file)
@@ -322,6 +322,28 @@ int cfg80211_nan_set_local_schedule(struct cfg80211_registered_device *rdev,
        return 0;
 }
 
+void cfg80211_stop_pd(struct cfg80211_registered_device *rdev,
+                     struct wireless_dev *wdev)
+{
+       lockdep_assert_held(&rdev->wiphy.mtx);
+
+       if (WARN_ON(wdev->iftype != NL80211_IFTYPE_PD))
+               return;
+
+       if (!rdev->ops->stop_pd)
+               return;
+
+       if (!wdev_running(wdev))
+               return;
+
+       cfg80211_pmsr_wdev_down(wdev);
+
+       rdev_stop_pd(rdev, wdev);
+       wdev->is_running = false;
+
+       rdev->opencount--;
+}
+
 void cfg80211_shutdown_all_interfaces(struct wiphy *wiphy)
 {
        struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
@@ -351,6 +373,9 @@ void cfg80211_shutdown_all_interfaces(struct wiphy *wiphy)
                case NL80211_IFTYPE_NAN:
                        cfg80211_stop_nan(rdev, wdev);
                        break;
+               case NL80211_IFTYPE_PD:
+                       cfg80211_stop_pd(rdev, wdev);
+                       break;
                default:
                        break;
                }
@@ -846,6 +871,9 @@ int wiphy_register(struct wiphy *wiphy)
                    (!rdev->ops->tdls_channel_switch ||
                     !rdev->ops->tdls_cancel_channel_switch)))
                return -EINVAL;
+       if (WARN_ON((wiphy->interface_modes & BIT(NL80211_IFTYPE_PD)) &&
+                   (!rdev->ops->start_pd || !rdev->ops->stop_pd)))
+               return -EINVAL;
 
        if (WARN_ON((wiphy->interface_modes & BIT(NL80211_IFTYPE_NAN)) &&
                    (!rdev->ops->start_nan || !rdev->ops->stop_nan ||
@@ -1408,6 +1436,9 @@ static void _cfg80211_unregister_wdev(struct wireless_dev *wdev,
        case NL80211_IFTYPE_NAN:
                cfg80211_stop_nan(rdev, wdev);
                break;
+       case NL80211_IFTYPE_PD:
+               cfg80211_stop_pd(rdev, wdev);
+               break;
        default:
                break;
        }
@@ -1516,10 +1547,12 @@ void cfg80211_leave_locked(struct cfg80211_registered_device *rdev,
        case NL80211_IFTYPE_NAN:
                cfg80211_stop_nan(rdev, wdev);
                break;
+       case NL80211_IFTYPE_PD:
+               cfg80211_stop_pd(rdev, wdev);
+               break;
        case NL80211_IFTYPE_AP_VLAN:
        case NL80211_IFTYPE_MONITOR:
        case NL80211_IFTYPE_NAN_DATA:
-       case NL80211_IFTYPE_PD:
                /* nothing to do */
                break;
        case NL80211_IFTYPE_UNSPECIFIED:
index 0e6f9bd4ba1b80b18017db9c855ac8fe238ff400..df47ed6208a50de3c680c0302591b8b752fcbcc4 100644 (file)
@@ -557,6 +557,8 @@ void cfg80211_stop_p2p_device(struct cfg80211_registered_device *rdev,
 
 void cfg80211_stop_nan(struct cfg80211_registered_device *rdev,
                       struct wireless_dev *wdev);
+void cfg80211_stop_pd(struct cfg80211_registered_device *rdev,
+                     struct wireless_dev *wdev);
 
 int cfg80211_nan_set_local_schedule(struct cfg80211_registered_device *rdev,
                                    struct wireless_dev *wdev,
index 85096c8964ff03d19bf9962b0dc7f8752f59357e..8e20fb714eff9da3f1b4c99a16442916b8e8a698 100644 (file)
@@ -16638,6 +16638,46 @@ static int nl80211_nan_change_config(struct sk_buff *skb,
        return rdev_nan_change_conf(rdev, wdev, &conf, changed);
 }
 
+static int nl80211_start_pd(struct sk_buff *skb, struct genl_info *info)
+{
+       struct cfg80211_registered_device *rdev = info->user_ptr[0];
+       struct wireless_dev *wdev = info->user_ptr[1];
+       int err;
+
+       if (wdev->iftype != NL80211_IFTYPE_PD)
+               return -EOPNOTSUPP;
+
+       if (wdev_running(wdev))
+               return -EEXIST;
+
+       if (rfkill_blocked(rdev->wiphy.rfkill))
+               return -ERFKILL;
+
+       if (!rdev->ops->start_pd)
+               return -EOPNOTSUPP;
+
+       err = rdev_start_pd(rdev, wdev);
+       if (err)
+               return err;
+       wdev->is_running = true;
+       rdev->opencount++;
+
+       return 0;
+}
+
+static int nl80211_stop_pd(struct sk_buff *skb, struct genl_info *info)
+{
+       struct cfg80211_registered_device *rdev = info->user_ptr[0];
+       struct wireless_dev *wdev = info->user_ptr[1];
+
+       if (wdev->iftype != NL80211_IFTYPE_PD)
+               return -EOPNOTSUPP;
+
+       cfg80211_stop_pd(rdev, wdev);
+
+       return 0;
+}
+
 void cfg80211_nan_match(struct wireless_dev *wdev,
                        struct cfg80211_nan_match_params *match, gfp_t gfp)
 {
@@ -19805,6 +19845,20 @@ static const struct genl_small_ops nl80211_small_ops[] = {
                .flags = GENL_ADMIN_PERM,
                .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP),
        },
+       {
+               .cmd = NL80211_CMD_START_PD,
+               .doit = nl80211_start_pd,
+               .flags = GENL_ADMIN_PERM,
+               .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV |
+                                        NL80211_FLAG_NEED_RTNL),
+       },
+       {
+               .cmd = NL80211_CMD_STOP_PD,
+               .doit = nl80211_stop_pd,
+               .flags = GENL_ADMIN_PERM,
+               .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP |
+                                        NL80211_FLAG_NEED_RTNL),
+       },
        {
                .cmd = NL80211_CMD_SET_MCAST_RATE,
                .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
index d97d5c08d1359af07935f0bdf70240db1c679d1b..63c26e8b113954a97d1686fe38553430622ee671 100644 (file)
@@ -1093,6 +1093,25 @@ rdev_nan_set_peer_sched(struct cfg80211_registered_device *rdev,
        return ret;
 }
 
+static inline int rdev_start_pd(struct cfg80211_registered_device *rdev,
+                               struct wireless_dev *wdev)
+{
+       int ret;
+
+       trace_rdev_start_pd(&rdev->wiphy, wdev);
+       ret = rdev->ops->start_pd(&rdev->wiphy, wdev);
+       trace_rdev_return_int(&rdev->wiphy, ret);
+       return ret;
+}
+
+static inline void rdev_stop_pd(struct cfg80211_registered_device *rdev,
+                               struct wireless_dev *wdev)
+{
+       trace_rdev_stop_pd(&rdev->wiphy, wdev);
+       rdev->ops->stop_pd(&rdev->wiphy, wdev);
+       trace_rdev_return_void(&rdev->wiphy);
+}
+
 static inline int rdev_set_mac_acl(struct cfg80211_registered_device *rdev,
                                   struct net_device *dev,
                                   struct cfg80211_acl_data *params)
index 938fea1fe9d802dd7bd56d40bd1373720a83a8ca..a68d356fe127502db923ba35ed49917c28a49de3 100644 (file)
@@ -2375,6 +2375,16 @@ DEFINE_EVENT(wiphy_wdev_evt, rdev_stop_nan,
        TP_ARGS(wiphy, wdev)
 );
 
+DEFINE_EVENT(wiphy_wdev_evt, rdev_start_pd,
+       TP_PROTO(struct wiphy *wiphy, struct wireless_dev *wdev),
+       TP_ARGS(wiphy, wdev)
+);
+
+DEFINE_EVENT(wiphy_wdev_evt, rdev_stop_pd,
+       TP_PROTO(struct wiphy *wiphy, struct wireless_dev *wdev),
+       TP_ARGS(wiphy, wdev)
+);
+
 TRACE_EVENT(rdev_add_nan_func,
        TP_PROTO(struct wiphy *wiphy, struct wireless_dev *wdev,
                 const struct cfg80211_nan_func *func),