xref: /linux/net/wireless/ap.c (revision 0e59523b440c90ed1899476f32ad4e949282f43e)
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Parts of this file are
4  * Copyright (C) 2022-2023, 2026 Intel Corporation
5  */
6 #include <linux/ieee80211.h>
7 #include <linux/export.h>
8 #include <net/cfg80211.h>
9 #include "nl80211.h"
10 #include "core.h"
11 #include "rdev-ops.h"
12 
13 
14 static int ___cfg80211_stop_ap(struct cfg80211_registered_device *rdev,
15 			       struct net_device *dev, unsigned int link_id,
16 			       bool notify)
17 {
18 	struct wireless_dev *wdev = dev->ieee80211_ptr;
19 	int err;
20 
21 	lockdep_assert_wiphy(wdev->wiphy);
22 
23 	if (!rdev->ops->stop_ap)
24 		return -EOPNOTSUPP;
25 
26 	if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
27 	    dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
28 		return -EOPNOTSUPP;
29 
30 	if (!wdev->links[link_id].ap.beacon_interval)
31 		return -ENOENT;
32 
33 	err = rdev_stop_ap(rdev, dev, link_id);
34 	if (!err) {
35 		wdev->conn_owner_nlportid = 0;
36 		memset(&wdev->links[link_id].ap, 0,
37 		       sizeof(wdev->links[link_id].ap));
38 		wdev->u.ap.ssid_len = 0;
39 		rdev_set_qos_map(rdev, dev, NULL);
40 		if (notify)
41 			nl80211_send_ap_stopped(wdev, link_id);
42 
43 		/* Should we apply the grace period during beaconing interface
44 		 * shutdown also?
45 		 */
46 		cfg80211_sched_dfs_chan_update(rdev);
47 	}
48 
49 	schedule_work(&cfg80211_disconnect_work);
50 
51 	return err;
52 }
53 
54 int cfg80211_stop_ap(struct cfg80211_registered_device *rdev,
55 		     struct net_device *dev, int link_id,
56 		     bool notify)
57 {
58 	unsigned int link;
59 	int ret = 0;
60 
61 	if (link_id >= 0)
62 		return ___cfg80211_stop_ap(rdev, dev, link_id, notify);
63 
64 	for_each_valid_link(dev->ieee80211_ptr, link) {
65 		int ret1 = ___cfg80211_stop_ap(rdev, dev, link, notify);
66 
67 		if (ret1)
68 			ret = ret1;
69 		/* try the next one also if one errored */
70 	}
71 
72 	return ret;
73 }
74