blob: 118f2f6198289353241b9caf4f5bea1aa17cb634 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Johannes Berg704232c2007-04-23 12:20:05 -07002/*
3 * Wireless configuration interface internals.
4 *
Johannes Berg5f2aa252010-01-17 15:49:02 +01005 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
Johannes Berga110a3b2024-02-06 16:54:08 +02006 * Copyright (C) 2018-2024 Intel Corporation
Johannes Berg704232c2007-04-23 12:20:05 -07007 */
8#ifndef __NET_WIRELESS_CORE_H
9#define __NET_WIRELESS_CORE_H
Johannes Berg704232c2007-04-23 12:20:05 -070010#include <linux/list.h>
11#include <linux/netdevice.h>
Johannes Berg2a519312009-02-10 21:25:55 +010012#include <linux/rbtree.h>
Luis R. Rodriguez1ac61302009-05-02 00:37:21 -040013#include <linux/debugfs.h>
Johannes Berg1f87f7d2009-06-02 13:01:41 +020014#include <linux/rfkill.h>
15#include <linux/workqueue.h>
Johannes Bergc5a7e582012-07-04 13:28:18 +020016#include <linux/rtnetlink.h>
Johannes Berg704232c2007-04-23 12:20:05 -070017#include <net/genetlink.h>
Johannes Berg704232c2007-04-23 12:20:05 -070018#include <net/cfg80211.h>
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -080019#include "reg.h"
Johannes Berg704232c2007-04-23 12:20:05 -070020
Johannes Bergf4173762012-12-03 18:23:37 +010021
22#define WIPHY_IDX_INVALID -1
23
Johannes Berg704232c2007-04-23 12:20:05 -070024struct cfg80211_registered_device {
David Kilroy3dcf6702009-05-16 23:13:46 +010025 const struct cfg80211_ops *ops;
Johannes Berg704232c2007-04-23 12:20:05 -070026 struct list_head list;
Johannes Berg704232c2007-04-23 12:20:05 -070027
Johannes Berg1f87f7d2009-06-02 13:01:41 +020028 /* rfkill support */
29 struct rfkill_ops rfkill_ops;
Johannes Berg3cfe91c2019-08-30 14:24:44 +030030 struct work_struct rfkill_block;
Johannes Berg1f87f7d2009-06-02 13:01:41 +020031
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -080032 /* ISO / IEC 3166 alpha2 for which this device is receiving
33 * country IEs on, this can help disregard country IEs from APs
34 * on the same alpha2 quickly. The alpha2 may differ from
35 * cfg80211_regdomain's alpha2 when an intersection has occurred.
36 * If the AP is reconfigured this can also be used to tell us if
37 * the country on the country IE changed. */
38 char country_ie_alpha2[2];
39
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020040 /*
41 * the driver requests the regulatory core to set this regulatory
42 * domain as the wiphy's. Only used for %REGULATORY_WIPHY_SELF_MANAGED
43 * devices using the regulatory_set_wiphy_regd() API
44 */
45 const struct ieee80211_regdomain *requested_regd;
46
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -080047 /* If a Country IE has been received this tells us the environment
48 * which its telling us its in. This defaults to ENVIRON_ANY */
49 enum environment_cap env;
50
Johannes Berg704232c2007-04-23 12:20:05 -070051 /* wiphy index, internal only */
Luis R. Rodriguezb5850a7a2009-02-21 00:04:19 -050052 int wiphy_idx;
Johannes Berg704232c2007-04-23 12:20:05 -070053
Johannes Berg53873f12016-05-03 16:52:04 +030054 /* protected by RTNL */
Johannes Berg89a54e42012-06-15 14:33:17 +020055 int devlist_generation, wdev_id;
Johannes Berg8b9b2f02016-05-03 16:26:40 +030056 int opencount;
Johannes Bergad002392009-08-18 19:51:57 +020057 wait_queue_head_t dev_wait;
Johannes Berg704232c2007-04-23 12:20:05 -070058
Ben Greear37c73b52012-10-26 14:49:25 -070059 struct list_head beacon_registrations;
60 spinlock_t beacon_registrations_lock;
Johannes Berg5e760232011-11-04 11:18:17 +010061
Johannes Bergc5a7e582012-07-04 13:28:18 +020062 /* protected by RTNL only */
Michal Kaziordbbae262012-06-29 12:47:01 +020063 int num_running_ifaces;
64 int num_running_monitor_ifaces;
Johannes Bergb60ad342018-10-01 11:52:07 +020065 u64 cookie_counter;
Michal Kaziordbbae262012-06-29 12:47:01 +020066
Johannes Berg2a519312009-02-10 21:25:55 +010067 /* BSSes/scanning */
68 spinlock_t bss_lock;
69 struct list_head bss_list;
70 struct rb_root bss_tree;
71 u32 bss_generation;
Johannes Berg9853a552016-11-15 12:05:11 +010072 u32 bss_entries;
Johannes Berg2a519312009-02-10 21:25:55 +010073 struct cfg80211_scan_request *scan_req; /* protected by RTNL */
Tova Mussaic8cb5b82020-09-18 11:33:13 +020074 struct cfg80211_scan_request *int_scan_req;
Johannes Bergf9d15d12014-01-22 11:14:19 +020075 struct sk_buff *scan_msg;
Arend Van Sprielca986ad2017-04-21 13:05:00 +010076 struct list_head sched_scan_req_list;
Arnd Bergmannfe0984d2018-06-18 17:11:14 +020077 time64_t suspend_at;
Johannes Bergfe0af9f2023-06-06 14:49:33 +020078 struct wiphy_work scan_done_wk;
Johannes Berg2a519312009-02-10 21:25:55 +010079
Johannes Bergad7e7182013-11-13 13:37:47 +010080 struct genl_info *cur_cmd_info;
Johannes Bergaff89a92009-07-01 21:26:51 +020081
Johannes Berg6829c872009-07-02 09:13:27 +020082 struct work_struct conn_work;
Johannes Berg667503d2009-07-07 03:56:11 +020083 struct work_struct event_work;
Johannes Berg6829c872009-07-02 09:13:27 +020084
Simon Wunderlich04f39042013-02-08 18:16:19 +010085 struct delayed_work dfs_update_channels_wk;
86
Lorenzo Bianconia95bfb82021-11-29 14:11:24 +010087 struct wireless_dev *background_radar_wdev;
88 struct cfg80211_chan_def background_radar_chandef;
89 struct delayed_work background_cac_done_wk;
90 struct work_struct background_cac_abort_wk;
Lorenzo Bianconibc2dfc02021-10-23 11:10:50 +020091
Arend van Spriel5de17982013-04-18 15:49:00 +020092 /* netlink port which started critical protocol (0 means not started) */
93 u32 crit_proto_nlportid;
94
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070095 struct cfg80211_coalesce *coalesce;
96
Johannes Berg78f22b62014-03-24 17:57:27 +010097 struct work_struct destroy_work;
Johannes Bergc88d7172023-06-06 14:49:32 +020098 struct wiphy_work sched_scan_stop_wk;
Arend Van Sprielb34939b2017-04-28 13:40:28 +010099 struct work_struct sched_scan_res_wk;
Jukka Rissanen93a1e862014-12-15 13:25:39 +0200100
Vasanthakumar Thiagarajan897667272017-02-27 17:04:35 +0530101 struct cfg80211_chan_def radar_chandef;
102 struct work_struct propagate_radar_detect_wk;
103
104 struct cfg80211_chan_def cac_done_chandef;
105 struct work_struct propagate_cac_done_wk;
106
Johannes Berg79ea1e122020-06-04 12:04:20 +0200107 struct work_struct mgmt_registrations_update_wk;
Johannes Berg09b1d5d2021-10-25 13:31:12 +0200108 /* lock for all wdev lists */
109 spinlock_t mgmt_registrations_lock;
Johannes Berg79ea1e122020-06-04 12:04:20 +0200110
Johannes Berga3ee4dc2023-06-06 14:49:25 +0200111 struct work_struct wiphy_work;
112 struct list_head wiphy_work_list;
113 /* protects the list above */
114 spinlock_t wiphy_work_lock;
115 bool suspended;
116
Johannes Berg704232c2007-04-23 12:20:05 -0700117 /* must be last because of the way we do wiphy_priv(),
118 * and it should at least be aligned to NETDEV_ALIGN */
Johannes Berg1c06ef92012-12-28 12:22:02 +0100119 struct wiphy wiphy __aligned(NETDEV_ALIGN);
Johannes Berg704232c2007-04-23 12:20:05 -0700120};
121
122static inline
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800123struct cfg80211_registered_device *wiphy_to_rdev(struct wiphy *wiphy)
Johannes Berg704232c2007-04-23 12:20:05 -0700124{
125 BUG_ON(!wiphy);
126 return container_of(wiphy, struct cfg80211_registered_device, wiphy);
127}
128
Johannes Bergff1b6e62011-05-04 15:37:28 +0200129static inline void
130cfg80211_rdev_free_wowlan(struct cfg80211_registered_device *rdev)
131{
Johannes Berg6abb9cb2013-05-15 09:30:07 +0200132#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +0200133 int i;
134
Johannes Berg6abb9cb2013-05-15 09:30:07 +0200135 if (!rdev->wiphy.wowlan_config)
Johannes Bergff1b6e62011-05-04 15:37:28 +0200136 return;
Johannes Berg6abb9cb2013-05-15 09:30:07 +0200137 for (i = 0; i < rdev->wiphy.wowlan_config->n_patterns; i++)
138 kfree(rdev->wiphy.wowlan_config->patterns[i].mask);
139 kfree(rdev->wiphy.wowlan_config->patterns);
140 if (rdev->wiphy.wowlan_config->tcp &&
141 rdev->wiphy.wowlan_config->tcp->sock)
142 sock_release(rdev->wiphy.wowlan_config->tcp->sock);
143 kfree(rdev->wiphy.wowlan_config->tcp);
Luciano Coelho8cd4d452014-09-17 11:55:28 +0300144 kfree(rdev->wiphy.wowlan_config->nd_config);
Johannes Berg6abb9cb2013-05-15 09:30:07 +0200145 kfree(rdev->wiphy.wowlan_config);
146#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +0200147}
Alban Browaeyse60d7442009-11-25 15:13:00 +0100148
Johannes Bergb60ad342018-10-01 11:52:07 +0200149static inline u64 cfg80211_assign_cookie(struct cfg80211_registered_device *rdev)
150{
151 u64 r = ++rdev->cookie_counter;
152
153 if (WARN_ON(r == 0))
154 r = ++rdev->cookie_counter;
155
156 return r;
157}
158
Alban Browaeyse60d7442009-11-25 15:13:00 +0100159extern struct workqueue_struct *cfg80211_wq;
Johannes Berg79c97e92009-07-07 03:56:12 +0200160extern struct list_head cfg80211_rdev_list;
Johannes Bergf5ea9122009-08-07 16:17:38 +0200161extern int cfg80211_rdev_list_generation;
Johannes Berg704232c2007-04-23 12:20:05 -0700162
Johannes Berg7483a212023-08-28 13:59:32 +0200163/* This is constructed like this so it can be used in if/else */
164static inline int for_each_rdev_check_rtnl(void)
165{
166 ASSERT_RTNL();
167 return 0;
168}
169#define for_each_rdev(rdev) \
170 if (for_each_rdev_check_rtnl()) {} else \
171 list_for_each_entry(rdev, &cfg80211_rdev_list, list)
172
Johannes Berg2a519312009-02-10 21:25:55 +0100173struct cfg80211_internal_bss {
174 struct list_head list;
Johannes Berg776b3582013-02-01 02:06:18 +0100175 struct list_head hidden_list;
Johannes Berg2a519312009-02-10 21:25:55 +0100176 struct rb_node rbn;
Dmitry Shmidt6e19bc42015-10-07 11:32:53 +0200177 u64 ts_boottime;
Johannes Berg2a519312009-02-10 21:25:55 +0100178 unsigned long ts;
Johannes Berg776b3582013-02-01 02:06:18 +0100179 unsigned long refcount;
Johannes Berg19957bb2009-07-02 17:20:43 +0200180 atomic_t hold;
Kalle Valoa08c1c12009-03-22 21:57:28 +0200181
Avraham Stern1d762502016-07-05 17:10:13 +0300182 /* time at the start of the reception of the first octet of the
183 * timestamp field of the last beacon/probe received for this BSS.
184 * The time is the TSF of the BSS specified by %parent_bssid.
185 */
186 u64 parent_tsf;
187
188 /* the BSS according to which %parent_tsf is set. This is set to
189 * the BSS that the interface that requested the scan was connected to
190 * when the beacon/probe was received.
191 */
192 u8 parent_bssid[ETH_ALEN] __aligned(2);
193
Johannes Berg2a519312009-02-10 21:25:55 +0100194 /* must be last because of priv member */
195 struct cfg80211_bss pub;
196};
197
Johannes Berg19957bb2009-07-02 17:20:43 +0200198static inline struct cfg80211_internal_bss *bss_from_pub(struct cfg80211_bss *pub)
199{
200 return container_of(pub, struct cfg80211_internal_bss, pub);
201}
202
203static inline void cfg80211_hold_bss(struct cfg80211_internal_bss *bss)
204{
205 atomic_inc(&bss->hold);
Sara Sharon7011ba52019-01-21 12:25:59 +0200206 if (bss->pub.transmitted_bss) {
207 bss = container_of(bss->pub.transmitted_bss,
Sara Sharona3584f56d2019-01-21 12:22:21 +0200208 struct cfg80211_internal_bss, pub);
209 atomic_inc(&bss->hold);
210 }
Johannes Berg19957bb2009-07-02 17:20:43 +0200211}
212
213static inline void cfg80211_unhold_bss(struct cfg80211_internal_bss *bss)
214{
215 int r = atomic_dec_return(&bss->hold);
216 WARN_ON(r < 0);
Sara Sharon7011ba52019-01-21 12:25:59 +0200217 if (bss->pub.transmitted_bss) {
218 bss = container_of(bss->pub.transmitted_bss,
Sara Sharona3584f56d2019-01-21 12:22:21 +0200219 struct cfg80211_internal_bss, pub);
220 r = atomic_dec_return(&bss->hold);
221 WARN_ON(r < 0);
222 }
Johannes Berg19957bb2009-07-02 17:20:43 +0200223}
224
225
Johannes Berg79c97e92009-07-07 03:56:12 +0200226struct cfg80211_registered_device *cfg80211_rdev_by_wiphy_idx(int wiphy_idx);
Luis R. Rodriguez806a9e32009-02-21 00:04:26 -0500227int get_wiphy_idx(struct wiphy *wiphy);
228
Luis R. Rodriguez806a9e32009-02-21 00:04:26 -0500229struct wiphy *wiphy_idx_to_wiphy(int wiphy_idx);
230
Johannes Berg463d0182009-07-14 00:33:35 +0200231int cfg80211_switch_netns(struct cfg80211_registered_device *rdev,
232 struct net *net);
Johannes Berg55682962007-09-20 13:09:35 -0400233
Johannes Berg9bdaf3b2020-10-09 13:58:22 +0200234void cfg80211_init_wdev(struct wireless_dev *wdev);
235void cfg80211_register_wdev(struct cfg80211_registered_device *rdev,
236 struct wireless_dev *wdev);
Johannes Berge4d42162018-09-13 14:12:03 +0200237
Michal Kaziordbbae262012-06-29 12:47:01 +0200238static inline bool cfg80211_has_monitors_only(struct cfg80211_registered_device *rdev)
239{
Johannes Berga05829a2021-01-22 16:19:43 +0100240 lockdep_assert_held(&rdev->wiphy.mtx);
Michal Kaziordbbae262012-06-29 12:47:01 +0200241
242 return rdev->num_running_ifaces == rdev->num_running_monitor_ifaces &&
243 rdev->num_running_ifaces > 0;
244}
245
Johannes Berg667503d2009-07-07 03:56:11 +0200246enum cfg80211_event_type {
247 EVENT_CONNECT_RESULT,
248 EVENT_ROAMED,
249 EVENT_DISCONNECTED,
250 EVENT_IBSS_JOINED,
Michal Kaziorf04c2202014-04-09 15:11:01 +0200251 EVENT_STOPPED,
Avraham Stern503c1fb2017-09-29 14:21:49 +0200252 EVENT_PORT_AUTHORIZED,
Johannes Berg667503d2009-07-07 03:56:11 +0200253};
254
255struct cfg80211_event {
256 struct list_head list;
257 enum cfg80211_event_type type;
258
259 union {
Vidyullatha Kanchanapally5349a0f2017-03-31 00:22:33 +0300260 struct cfg80211_connect_resp_params cr;
Avraham Stern29ce6ec2017-04-26 10:58:49 +0300261 struct cfg80211_roam_info rm;
Johannes Berg667503d2009-07-07 03:56:11 +0200262 struct {
263 const u8 *ie;
264 size_t ie_len;
265 u16 reason;
Johannes Berg80279fb2015-05-22 16:22:20 +0200266 bool locally_generated;
Johannes Berg667503d2009-07-07 03:56:11 +0200267 } dc;
268 struct {
269 u8 bssid[ETH_ALEN];
Antonio Quartullife94f3a2014-01-29 17:53:43 +0100270 struct ieee80211_channel *channel;
Johannes Berg667503d2009-07-07 03:56:11 +0200271 } ij;
Avraham Stern503c1fb2017-09-29 14:21:49 +0200272 struct {
Vinayak Yadawade4e7e3a2023-09-26 16:02:22 +0530273 u8 peer_addr[ETH_ALEN];
Vinayak Yadawad0ff57172022-09-07 18:14:48 +0530274 const u8 *td_bitmap;
275 u8 td_bitmap_len;
Avraham Stern503c1fb2017-09-29 14:21:49 +0200276 } pa;
Johannes Berg667503d2009-07-07 03:56:11 +0200277 };
278};
279
Johannes Bergfffd0932009-07-08 14:22:54 +0200280struct cfg80211_cached_keys {
Johannes Berg585b6e12023-01-16 15:24:11 +0100281 struct key_params params[4];
282 u8 data[4][WLAN_KEY_LEN_WEP104];
Johannes Berg89b706f2016-09-13 16:39:38 +0200283 int def;
Johannes Bergfffd0932009-07-08 14:22:54 +0200284};
285
Ben Greear37c73b52012-10-26 14:49:25 -0700286struct cfg80211_beacon_registration {
287 struct list_head list;
288 u32 nlportid;
289};
Johannes Berg667503d2009-07-07 03:56:11 +0200290
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +0100291struct cfg80211_cqm_config {
Johannes Berg37c20b22023-08-16 15:38:04 +0200292 struct rcu_head rcu_head;
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +0100293 u32 rssi_hyst;
294 s32 last_rssi_event_value;
Johannes Berg37c20b22023-08-16 15:38:04 +0200295 enum nl80211_cqm_rssi_threshold_event last_rssi_event_type;
Johannes Berg7e7efdd2023-11-06 23:17:16 +0100296 bool use_range_api;
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +0100297 int n_rssi_thresholds;
Kees Cookd4d3aaf2023-08-17 14:15:24 -0700298 s32 rssi_thresholds[] __counted_by(n_rssi_thresholds);
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +0100299};
300
Johannes Berg37c20b22023-08-16 15:38:04 +0200301void cfg80211_cqm_rssi_notify_work(struct wiphy *wiphy,
302 struct wiphy_work *work);
303
Johannes Berg78f22b62014-03-24 17:57:27 +0100304void cfg80211_destroy_ifaces(struct cfg80211_registered_device *rdev);
305
Johannes Berg704232c2007-04-23 12:20:05 -0700306/* free object */
Joe Perchesc1b12032013-10-18 13:48:25 -0700307void cfg80211_dev_free(struct cfg80211_registered_device *rdev);
Johannes Berg704232c2007-04-23 12:20:05 -0700308
Joe Perchesc1b12032013-10-18 13:48:25 -0700309int cfg80211_dev_rename(struct cfg80211_registered_device *rdev,
310 char *newname);
Johannes Berg55682962007-09-20 13:09:35 -0400311
Johannes Berg8318d782008-01-24 19:38:38 +0100312void ieee80211_set_bitrate_flags(struct wiphy *wiphy);
Johannes Berg8318d782008-01-24 19:38:38 +0100313
Zhao, Gang1b8ec872014-04-21 12:53:02 +0800314void cfg80211_bss_expire(struct cfg80211_registered_device *rdev);
315void cfg80211_bss_age(struct cfg80211_registered_device *rdev,
Dan Williamscb3a8ee2009-02-11 17:14:43 -0500316 unsigned long age_secs);
Sergey Matyukevich0afd4252019-07-26 16:39:34 +0000317void cfg80211_update_assoc_bss_entry(struct wireless_dev *wdev,
Johannes Berg7b0a0e32022-04-14 16:50:57 +0200318 unsigned int link,
Sergey Matyukevich0afd4252019-07-26 16:39:34 +0000319 struct ieee80211_channel *channel);
Johannes Berg2a519312009-02-10 21:25:55 +0100320
Johannes Berg04a773a2009-04-19 21:24:32 +0200321/* IBSS */
Denis Kenziorf8d16d32018-03-26 12:52:45 -0500322int __cfg80211_join_ibss(struct cfg80211_registered_device *rdev,
323 struct net_device *dev,
324 struct cfg80211_ibss_params *params,
325 struct cfg80211_cached_keys *connkeys);
Johannes Berg9d308422009-04-20 18:43:46 +0200326void cfg80211_clear_ibss(struct net_device *dev, bool nowext);
Johannes Berg04a773a2009-04-19 21:24:32 +0200327int cfg80211_leave_ibss(struct cfg80211_registered_device *rdev,
Johannes Berg9d308422009-04-20 18:43:46 +0200328 struct net_device *dev, bool nowext);
Antonio Quartullife94f3a2014-01-29 17:53:43 +0100329void __cfg80211_ibss_joined(struct net_device *dev, const u8 *bssid,
330 struct ieee80211_channel *channel);
Johannes Bergfffd0932009-07-08 14:22:54 +0200331int cfg80211_ibss_wext_join(struct cfg80211_registered_device *rdev,
332 struct wireless_dev *wdev);
Johannes Berg04a773a2009-04-19 21:24:32 +0200333
Johannes Berg29cbe682010-12-03 09:20:44 +0100334/* mesh */
335extern const struct mesh_config default_mesh_config;
Javier Cardonac80d5452010-12-16 17:37:49 -0800336extern const struct mesh_setup default_mesh_setup;
Johannes Berg29cbe682010-12-03 09:20:44 +0100337int __cfg80211_join_mesh(struct cfg80211_registered_device *rdev,
338 struct net_device *dev,
Johannes Bergcc1d2802012-05-16 23:50:20 +0200339 struct mesh_setup *setup,
Johannes Berg29cbe682010-12-03 09:20:44 +0100340 const struct mesh_config *conf);
Johannes Berg29cbe682010-12-03 09:20:44 +0100341int cfg80211_leave_mesh(struct cfg80211_registered_device *rdev,
342 struct net_device *dev);
Johannes Berg683b6d32012-11-08 21:25:48 +0100343int cfg80211_set_mesh_channel(struct cfg80211_registered_device *rdev,
344 struct wireless_dev *wdev,
345 struct cfg80211_chan_def *chandef);
Johannes Berg29cbe682010-12-03 09:20:44 +0100346
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +0100347/* OCB */
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +0100348int cfg80211_join_ocb(struct cfg80211_registered_device *rdev,
349 struct net_device *dev,
350 struct ocb_setup *setup);
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +0100351int cfg80211_leave_ocb(struct cfg80211_registered_device *rdev,
352 struct net_device *dev);
353
Michal Kazior60771782012-06-29 12:46:56 +0200354/* AP */
355int cfg80211_stop_ap(struct cfg80211_registered_device *rdev,
Johannes Berg7b0a0e32022-04-14 16:50:57 +0200356 struct net_device *dev, int link,
357 bool notify);
Michal Kazior60771782012-06-29 12:46:56 +0200358
Johannes Berg19957bb2009-07-02 17:20:43 +0200359/* MLME */
360int cfg80211_mlme_auth(struct cfg80211_registered_device *rdev,
Johannes Berg91bf9b22013-05-15 17:44:01 +0200361 struct net_device *dev,
Johannes Berg325839d2022-06-01 22:42:28 +0200362 struct cfg80211_auth_request *req);
Johannes Berg19957bb2009-07-02 17:20:43 +0200363int cfg80211_mlme_assoc(struct cfg80211_registered_device *rdev,
Johannes Bergf62fab72013-02-21 20:09:09 +0100364 struct net_device *dev,
Johannes Bergccb964b2024-01-02 21:35:44 +0200365 struct cfg80211_assoc_request *req,
366 struct netlink_ext_ack *extack);
Johannes Berg19957bb2009-07-02 17:20:43 +0200367int cfg80211_mlme_deauth(struct cfg80211_registered_device *rdev,
368 struct net_device *dev, const u8 *bssid,
Jouni Malinend5cdfac2010-04-04 09:37:19 +0300369 const u8 *ie, int ie_len, u16 reason,
370 bool local_state_change);
Johannes Berg19957bb2009-07-02 17:20:43 +0200371int cfg80211_mlme_disassoc(struct cfg80211_registered_device *rdev,
Johannes Berg8f6e0df2022-06-27 16:19:18 +0200372 struct net_device *dev, const u8 *ap_addr,
Jouni Malinend5cdfac2010-04-04 09:37:19 +0300373 const u8 *ie, int ie_len, u16 reason,
374 bool local_state_change);
Johannes Berg19957bb2009-07-02 17:20:43 +0200375void cfg80211_mlme_down(struct cfg80211_registered_device *rdev,
376 struct net_device *dev);
Johannes Berg2e161f782010-08-12 15:38:38 +0200377int cfg80211_mlme_register_mgmt(struct wireless_dev *wdev, u32 snd_pid,
378 u16 frame_type, const u8 *match_data,
Johannes Berg9dba48a2020-04-17 12:40:15 +0200379 int match_len, bool multicast_rx,
380 struct netlink_ext_ack *extack);
Johannes Berg6cd536f2020-04-17 12:43:01 +0200381void cfg80211_mgmt_registrations_update_wk(struct work_struct *wk);
Johannes Berg2e161f782010-08-12 15:38:38 +0200382void cfg80211_mlme_unregister_socket(struct wireless_dev *wdev, u32 nlpid);
383void cfg80211_mlme_purge_registrations(struct wireless_dev *wdev);
384int cfg80211_mlme_mgmt_tx(struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +0200385 struct wireless_dev *wdev,
Andrei Otcheretianskib176e622013-11-18 19:06:49 +0200386 struct cfg80211_mgmt_tx_params *params,
387 u64 *cookie);
Ben Greear7e7c8922011-11-18 11:31:59 -0800388void cfg80211_oper_and_ht_capa(struct ieee80211_ht_cap *ht_capa,
389 const struct ieee80211_ht_cap *ht_capa_mask);
Johannes Bergee2aca32013-02-21 17:36:01 +0100390void cfg80211_oper_and_vht_capa(struct ieee80211_vht_cap *vht_capa,
391 const struct ieee80211_vht_cap *vht_capa_mask);
Johannes Berg19957bb2009-07-02 17:20:43 +0200392
Johannes Bergceca7b72013-05-16 00:55:45 +0200393/* SME events */
Samuel Ortizb23aa672009-07-01 21:26:54 +0200394int cfg80211_connect(struct cfg80211_registered_device *rdev,
395 struct net_device *dev,
Johannes Bergfffd0932009-07-08 14:22:54 +0200396 struct cfg80211_connect_params *connect,
Johannes Berg83739b02013-05-15 17:44:01 +0200397 struct cfg80211_cached_keys *connkeys,
398 const u8 *prev_bssid);
Vidyullatha Kanchanapally5349a0f2017-03-31 00:22:33 +0300399void __cfg80211_connect_result(struct net_device *dev,
400 struct cfg80211_connect_resp_params *params,
401 bool wextev);
Johannes Bergceca7b72013-05-16 00:55:45 +0200402void __cfg80211_disconnected(struct net_device *dev, const u8 *ie,
403 size_t ie_len, u16 reason, bool from_ap);
Samuel Ortizb23aa672009-07-01 21:26:54 +0200404int cfg80211_disconnect(struct cfg80211_registered_device *rdev,
Johannes Bergf2129352009-07-01 21:26:56 +0200405 struct net_device *dev, u16 reason,
406 bool wextev);
Jouni Malinened9d0102011-05-16 19:40:15 +0300407void __cfg80211_roamed(struct wireless_dev *wdev,
Avraham Stern29ce6ec2017-04-26 10:58:49 +0300408 struct cfg80211_roam_info *info);
Vinayak Yadawade4e7e3a2023-09-26 16:02:22 +0530409void __cfg80211_port_authorized(struct wireless_dev *wdev, const u8 *peer_addr,
Vinayak Yadawad0ff57172022-09-07 18:14:48 +0530410 const u8 *td_bitmap, u8 td_bitmap_len);
Johannes Bergfffd0932009-07-08 14:22:54 +0200411int cfg80211_mgd_wext_connect(struct cfg80211_registered_device *rdev,
412 struct wireless_dev *wdev);
Andrzej Zaborowskibd2522b2017-01-06 16:33:43 -0500413void cfg80211_autodisconnect_wk(struct work_struct *work);
Samuel Ortizb23aa672009-07-01 21:26:54 +0200414
Johannes Bergceca7b72013-05-16 00:55:45 +0200415/* SME implementation */
Johannes Berg6829c872009-07-02 09:13:27 +0200416void cfg80211_conn_work(struct work_struct *work);
Johannes Bergceca7b72013-05-16 00:55:45 +0200417void cfg80211_sme_scan_done(struct net_device *dev);
418bool cfg80211_sme_rx_assoc_resp(struct wireless_dev *wdev, u16 status);
419void cfg80211_sme_rx_auth(struct wireless_dev *wdev, const u8 *buf, size_t len);
420void cfg80211_sme_disassoc(struct wireless_dev *wdev);
421void cfg80211_sme_deauth(struct wireless_dev *wdev);
422void cfg80211_sme_auth_timeout(struct wireless_dev *wdev);
423void cfg80211_sme_assoc_timeout(struct wireless_dev *wdev);
Johannes Berge6f462d2016-12-08 17:22:09 +0100424void cfg80211_sme_abandon_assoc(struct wireless_dev *wdev);
Johannes Berg6829c872009-07-02 09:13:27 +0200425
Johannes Berg08645122009-05-11 13:54:58 +0200426/* internal helpers */
Jouni Malinen38ba3c52011-09-21 18:14:56 +0300427bool cfg80211_supported_cipher_suite(struct wiphy *wiphy, u32 cipher);
Anant Thazhemadam2d9463082020-12-05 03:28:25 +0530428bool cfg80211_valid_key_idx(struct cfg80211_registered_device *rdev,
429 int key_idx, bool pairwise);
Johannes Bergfffd0932009-07-08 14:22:54 +0200430int cfg80211_validate_key_settings(struct cfg80211_registered_device *rdev,
431 struct key_params *params, int key_idx,
Johannes Berge31b8212010-10-05 19:39:30 +0200432 bool pairwise, const u8 *mac_addr);
Johannes Bergfe0af9f2023-06-06 14:49:33 +0200433void __cfg80211_scan_done(struct wiphy *wiphy, struct wiphy_work *wk);
Johannes Bergf9d15d12014-01-22 11:14:19 +0200434void ___cfg80211_scan_done(struct cfg80211_registered_device *rdev,
435 bool send_message);
Arend Van Sprielca986ad2017-04-21 13:05:00 +0100436void cfg80211_add_sched_scan_req(struct cfg80211_registered_device *rdev,
437 struct cfg80211_sched_scan_request *req);
438int cfg80211_sched_scan_req_possible(struct cfg80211_registered_device *rdev,
439 bool want_multi);
Arend Van Sprielb34939b2017-04-28 13:40:28 +0100440void cfg80211_sched_scan_results_wk(struct work_struct *work);
Arend Van Sprielca986ad2017-04-21 13:05:00 +0100441int cfg80211_stop_sched_scan_req(struct cfg80211_registered_device *rdev,
442 struct cfg80211_sched_scan_request *req,
443 bool driver_initiated);
Luciano Coelho807f8a82011-05-11 17:09:35 +0300444int __cfg80211_stop_sched_scan(struct cfg80211_registered_device *rdev,
Arend Van Sprielca986ad2017-04-21 13:05:00 +0100445 u64 reqid, bool driver_initiated);
Johannes Bergfffd0932009-07-08 14:22:54 +0200446void cfg80211_upload_connect_keys(struct wireless_dev *wdev);
Johannes Berg3d54d252009-08-21 14:51:05 +0200447int cfg80211_change_iface(struct cfg80211_registered_device *rdev,
448 struct net_device *dev, enum nl80211_iftype ntype,
Johannes Berg818a9862017-04-12 11:23:28 +0200449 struct vif_params *params);
Johannes Berg3d54d252009-08-21 14:51:05 +0200450void cfg80211_process_rdev_events(struct cfg80211_registered_device *rdev);
Johannes Berg56cfb8ce2023-08-28 13:59:33 +0200451void cfg80211_process_wiphy_works(struct cfg80211_registered_device *rdev,
452 struct wiphy_work *end);
Daniel Drake1f6fc432012-08-02 18:41:48 +0100453void cfg80211_process_wdev_events(struct wireless_dev *wdev);
Johannes Berg08645122009-05-11 13:54:58 +0200454
Rafał Miłecki4787cfa2017-01-04 18:58:30 +0100455bool cfg80211_does_bw_fit_range(const struct ieee80211_freq_range *freq_range,
456 u32 center_freq_khz, u32 bw_khz);
457
Tova Mussaic8cb5b82020-09-18 11:33:13 +0200458int cfg80211_scan(struct cfg80211_registered_device *rdev);
459
Johannes Berge005bd7d2019-02-01 11:09:54 +0100460extern struct work_struct cfg80211_disconnect_work;
461
Johannes Bergd02a12b2023-12-11 09:05:20 +0200462#define NL80211_BSS_USE_FOR_ALL (NL80211_BSS_USE_FOR_NORMAL | \
463 NL80211_BSS_USE_FOR_MLD_LINK)
464
Simon Wunderlich04f39042013-02-08 18:16:19 +0100465void cfg80211_set_dfs_state(struct wiphy *wiphy,
466 const struct cfg80211_chan_def *chandef,
467 enum nl80211_dfs_state dfs_state);
468
469void cfg80211_dfs_channels_update_work(struct work_struct *work);
470
Vasanthakumar Thiagarajanb35a51c2017-02-27 17:04:33 +0530471void cfg80211_sched_dfs_chan_update(struct cfg80211_registered_device *rdev);
472
Lorenzo Bianconibc2dfc02021-10-23 11:10:50 +0200473int
Lorenzo Bianconia95bfb82021-11-29 14:11:24 +0100474cfg80211_start_background_radar_detection(struct cfg80211_registered_device *rdev,
475 struct wireless_dev *wdev,
476 struct cfg80211_chan_def *chandef);
Lorenzo Bianconibc2dfc02021-10-23 11:10:50 +0200477
Lorenzo Bianconia95bfb82021-11-29 14:11:24 +0100478void cfg80211_stop_background_radar_detection(struct wireless_dev *wdev);
Lorenzo Bianconibc2dfc02021-10-23 11:10:50 +0200479
Lorenzo Bianconia95bfb82021-11-29 14:11:24 +0100480void cfg80211_background_cac_done_wk(struct work_struct *work);
Lorenzo Bianconi1507b152021-10-27 11:03:42 +0200481
Lorenzo Bianconia95bfb82021-11-29 14:11:24 +0100482void cfg80211_background_cac_abort_wk(struct work_struct *work);
Lorenzo Bianconibc2dfc02021-10-23 11:10:50 +0200483
Vasanthakumar Thiagarajanb35a51c2017-02-27 17:04:33 +0530484bool cfg80211_any_wiphy_oper_chan(struct wiphy *wiphy,
485 struct ieee80211_channel *chan);
486
487bool cfg80211_beaconing_iface_active(struct wireless_dev *wdev);
488
489bool cfg80211_is_sub_chan(struct cfg80211_chan_def *chandef,
Johannes Berg7b0a0e32022-04-14 16:50:57 +0200490 struct ieee80211_channel *chan,
491 bool primary_only);
492bool cfg80211_wdev_on_sub_chan(struct wireless_dev *wdev,
493 struct ieee80211_channel *chan,
494 bool primary_only);
Johannes Berga110a3b2024-02-06 16:54:08 +0200495bool _cfg80211_chandef_usable(struct wiphy *wiphy,
496 const struct cfg80211_chan_def *chandef,
497 u32 prohibited_flags, bool monitor);
Vasanthakumar Thiagarajanb35a51c2017-02-27 17:04:33 +0530498
Simon Wunderlich04f39042013-02-08 18:16:19 +0100499static inline unsigned int elapsed_jiffies_msecs(unsigned long start)
500{
501 unsigned long end = jiffies;
502
503 if (end >= start)
504 return jiffies_to_msecs(end - start);
505
Eliad Peller0ce12022014-06-17 13:07:02 +0300506 return jiffies_to_msecs(end + (ULONG_MAX - start) + 1);
Simon Wunderlich04f39042013-02-08 18:16:19 +0100507}
508
Johannes Berge8c9bd52012-06-06 08:18:22 +0200509int cfg80211_set_monitor_channel(struct cfg80211_registered_device *rdev,
Johannes Berg683b6d32012-11-08 21:25:48 +0100510 struct cfg80211_chan_def *chandef);
Johannes Berg59bbb6f2009-08-07 17:22:35 +0200511
Johannes Berg34850ab2011-07-18 18:08:35 +0200512int ieee80211_get_ratemask(struct ieee80211_supported_band *sband,
513 const u8 *rates, unsigned int n_rates,
514 u32 *mask);
515
Johannes Berg56d18932011-05-09 18:41:15 +0200516int cfg80211_validate_beacon_int(struct cfg80211_registered_device *rdev,
Purushottam Kushwaha0c317a02016-10-12 18:26:51 +0530517 enum nl80211_iftype iftype, u32 beacon_int);
Johannes Berg56d18932011-05-09 18:41:15 +0200518
Michal Kaziordbbae262012-06-29 12:47:01 +0200519void cfg80211_update_iface_num(struct cfg80211_registered_device *rdev,
520 enum nl80211_iftype iftype, int num);
521
Stanislaw Gruszka81256962013-02-28 10:55:25 +0100522void cfg80211_leave(struct cfg80211_registered_device *rdev,
523 struct wireless_dev *wdev);
524
Johannes Bergf9f47522013-03-19 15:04:07 +0100525void cfg80211_stop_p2p_device(struct cfg80211_registered_device *rdev,
526 struct wireless_dev *wdev);
527
Ayala Bekercb3b7d82016-09-20 17:31:13 +0300528void cfg80211_stop_nan(struct cfg80211_registered_device *rdev,
529 struct wireless_dev *wdev);
530
Chaitanya Tataa3ce17d2019-05-01 18:25:24 +0530531struct cfg80211_internal_bss *
532cfg80211_bss_update(struct cfg80211_registered_device *rdev,
533 struct cfg80211_internal_bss *tmp,
534 bool signal_valid, unsigned long ts);
Johannes Bergf7969962009-08-21 12:23:49 +0200535#ifdef CONFIG_CFG80211_DEVELOPER_WARNINGS
536#define CFG80211_DEV_WARN_ON(cond) WARN_ON(cond)
537#else
538/*
539 * Trick to enable using it as a condition,
540 * and also not give a warning when it's
541 * not used that way.
542 */
543#define CFG80211_DEV_WARN_ON(cond) ({bool __r = (cond); __r; })
544#endif
545
Johannes Berg9bb7e0f2018-09-10 13:29:12 +0200546void cfg80211_release_pmsr(struct wireless_dev *wdev, u32 portid);
547void cfg80211_pmsr_wdev_down(struct wireless_dev *wdev);
548void cfg80211_pmsr_free_wk(struct work_struct *work);
549
Johannes Bergcdf0a0a2022-07-06 09:57:42 +0200550void cfg80211_remove_link(struct wireless_dev *wdev, unsigned int link_id);
551void cfg80211_remove_links(struct wireless_dev *wdev);
552int cfg80211_remove_virtual_intf(struct cfg80211_registered_device *rdev,
553 struct wireless_dev *wdev);
Veerendranath Jakkam065563b2023-03-17 19:51:53 +0530554void cfg80211_wdev_release_link_bsses(struct wireless_dev *wdev, u16 link_mask);
Johannes Bergcdf0a0a2022-07-06 09:57:42 +0200555
Benjamin Berg45d43932024-01-29 22:09:19 +0100556/**
557 * struct cfg80211_colocated_ap - colocated AP information
558 *
559 * @list: linked list to all colocated APs
560 * @bssid: BSSID of the reported AP
561 * @ssid: SSID of the reported AP
562 * @ssid_len: length of the ssid
563 * @center_freq: frequency the reported AP is on
564 * @unsolicited_probe: the reported AP is part of an ESS, where all the APs
565 * that operate in the same channel as the reported AP and that might be
566 * detected by a STA receiving this frame, are transmitting unsolicited
567 * Probe Response frames every 20 TUs
568 * @oct_recommended: OCT is recommended to exchange MMPDUs with the reported AP
569 * @same_ssid: the reported AP has the same SSID as the reporting AP
570 * @multi_bss: the reported AP is part of a multiple BSSID set
571 * @transmitted_bssid: the reported AP is the transmitting BSSID
572 * @colocated_ess: all the APs that share the same ESS as the reported AP are
573 * colocated and can be discovered via legacy bands.
574 * @short_ssid_valid: short_ssid is valid and can be used
575 * @short_ssid: the short SSID for this SSID
576 * @psd_20: The 20MHz PSD EIRP of the primary 20MHz channel for the reported AP
577 */
578struct cfg80211_colocated_ap {
579 struct list_head list;
580 u8 bssid[ETH_ALEN];
581 u8 ssid[IEEE80211_MAX_SSID_LEN];
582 size_t ssid_len;
583 u32 short_ssid;
584 u32 center_freq;
585 u8 unsolicited_probe:1,
586 oct_recommended:1,
587 same_ssid:1,
588 multi_bss:1,
589 transmitted_bssid:1,
590 colocated_ess:1,
591 short_ssid_valid:1;
592 s8 psd_20;
593};
594
Benjamin Berg9d027a32023-12-20 16:19:52 +0100595#if IS_ENABLED(CONFIG_CFG80211_KUNIT_TEST)
596#define EXPORT_SYMBOL_IF_CFG80211_KUNIT(sym) EXPORT_SYMBOL_IF_KUNIT(sym)
597#define VISIBLE_IF_CFG80211_KUNIT
Benjamin Berg45d43932024-01-29 22:09:19 +0100598void cfg80211_free_coloc_ap_list(struct list_head *coloc_ap_list);
599
600int cfg80211_parse_colocated_ap(const struct cfg80211_bss_ies *ies,
601 struct list_head *list);
602
Benjamin Berg9d027a32023-12-20 16:19:52 +0100603size_t cfg80211_gen_new_ie(const u8 *ie, size_t ielen,
604 const u8 *subie, size_t subie_len,
605 u8 *new_ie, size_t new_ie_len);
606#else
607#define EXPORT_SYMBOL_IF_CFG80211_KUNIT(sym)
608#define VISIBLE_IF_CFG80211_KUNIT static
609#endif /* IS_ENABLED(CONFIG_CFG80211_KUNIT_TEST) */
610
Johannes Berg704232c2007-04-23 12:20:05 -0700611#endif /* __NET_WIRELESS_CORE_H */