Commit e76fede8 authored by Thomas Pedersen's avatar Thomas Pedersen Committed by Johannes Berg

cfg80211: add KHz variants of frame RX API

Drivers may wish to report the RX frequency in units of
KHz. Provide cfg80211_rx_mgmt_khz() and wrap it with
cfg80211_rx_mgmt() so exisiting drivers which can't report
KHz anyway don't need to change. Add a similar wrapper for
cfg80211_report_obss_beacon() so the frequency units stay
somewhat consistent.

This doesn't actually change the nl80211 API yet.
Signed-off-by: default avatarThomas Pedersen <thomas@adapt-ip.com>
Link: https://lore.kernel.org/r/20200430172554.18383-2-thomas@adapt-ip.com
[fix mac80211 calling the non-khz version of obss beacon report,
 drop trace point name changes]
Signed-off-by: default avatarJohannes Berg <johannes.berg@intel.com>
parent c0336955
...@@ -3333,6 +3333,8 @@ static inline int ieee80211_get_tdls_action(struct sk_buff *skb, u32 hdr_size) ...@@ -3333,6 +3333,8 @@ static inline int ieee80211_get_tdls_action(struct sk_buff *skb, u32 hdr_size)
/* convert frequencies */ /* convert frequencies */
#define MHZ_TO_KHZ(freq) ((freq) * 1000) #define MHZ_TO_KHZ(freq) ((freq) * 1000)
#define KHZ_TO_MHZ(freq) ((freq) / 1000) #define KHZ_TO_MHZ(freq) ((freq) / 1000)
#define PR_KHZ(f) KHZ_TO_MHZ(f), f % 1000
#define KHZ_F "%d.%03d"
/* convert powers */ /* convert powers */
#define DBI_TO_MBI(gain) ((gain) * 100) #define DBI_TO_MBI(gain) ((gain) * 100)
......
...@@ -6988,6 +6988,26 @@ void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr, ...@@ -6988,6 +6988,26 @@ void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
enum nl80211_connect_failed_reason reason, enum nl80211_connect_failed_reason reason,
gfp_t gfp); gfp_t gfp);
/**
* cfg80211_rx_mgmt_khz - notification of received, unprocessed management frame
* @wdev: wireless device receiving the frame
* @freq: Frequency on which the frame was received in KHz
* @sig_dbm: signal strength in dBm, or 0 if unknown
* @buf: Management frame (header + body)
* @len: length of the frame data
* @flags: flags, as defined in enum nl80211_rxmgmt_flags
*
* This function is called whenever an Action frame is received for a station
* mode interface, but is not processed in kernel.
*
* Return: %true if a user space application has registered for this frame.
* For action frames, that makes it responsible for rejecting unrecognized
* action frames; %false otherwise, in which case for action frames the
* driver is responsible for rejecting the frame.
*/
bool cfg80211_rx_mgmt_khz(struct wireless_dev *wdev, int freq, int sig_dbm,
const u8 *buf, size_t len, u32 flags);
/** /**
* cfg80211_rx_mgmt - notification of received, unprocessed management frame * cfg80211_rx_mgmt - notification of received, unprocessed management frame
* @wdev: wireless device receiving the frame * @wdev: wireless device receiving the frame
...@@ -7005,8 +7025,13 @@ void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr, ...@@ -7005,8 +7025,13 @@ void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
* action frames; %false otherwise, in which case for action frames the * action frames; %false otherwise, in which case for action frames the
* driver is responsible for rejecting the frame. * driver is responsible for rejecting the frame.
*/ */
bool cfg80211_rx_mgmt(struct wireless_dev *wdev, int freq, int sig_dbm, static inline bool cfg80211_rx_mgmt(struct wireless_dev *wdev, int freq,
const u8 *buf, size_t len, u32 flags); int sig_dbm, const u8 *buf, size_t len,
u32 flags)
{
return cfg80211_rx_mgmt_khz(wdev, MHZ_TO_KHZ(freq), sig_dbm, buf, len,
flags);
}
/** /**
* cfg80211_mgmt_tx_status - notification of TX status for management frame * cfg80211_mgmt_tx_status - notification of TX status for management frame
...@@ -7204,6 +7229,21 @@ void cfg80211_probe_status(struct net_device *dev, const u8 *addr, ...@@ -7204,6 +7229,21 @@ void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
u64 cookie, bool acked, s32 ack_signal, u64 cookie, bool acked, s32 ack_signal,
bool is_valid_ack_signal, gfp_t gfp); bool is_valid_ack_signal, gfp_t gfp);
/**
* cfg80211_report_obss_beacon_khz - report beacon from other APs
* @wiphy: The wiphy that received the beacon
* @frame: the frame
* @len: length of the frame
* @freq: frequency the frame was received on in KHz
* @sig_dbm: signal strength in dBm, or 0 if unknown
*
* Use this function to report to userspace when a beacon was
* received. It is not useful to call this when there is no
* netdev that is in AP/GO mode.
*/
void cfg80211_report_obss_beacon_khz(struct wiphy *wiphy, const u8 *frame,
size_t len, int freq, int sig_dbm);
/** /**
* cfg80211_report_obss_beacon - report beacon from other APs * cfg80211_report_obss_beacon - report beacon from other APs
* @wiphy: The wiphy that received the beacon * @wiphy: The wiphy that received the beacon
...@@ -7216,9 +7256,13 @@ void cfg80211_probe_status(struct net_device *dev, const u8 *addr, ...@@ -7216,9 +7256,13 @@ void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
* received. It is not useful to call this when there is no * received. It is not useful to call this when there is no
* netdev that is in AP/GO mode. * netdev that is in AP/GO mode.
*/ */
void cfg80211_report_obss_beacon(struct wiphy *wiphy, static inline void cfg80211_report_obss_beacon(struct wiphy *wiphy,
const u8 *frame, size_t len, const u8 *frame, size_t len,
int freq, int sig_dbm); int freq, int sig_dbm)
{
cfg80211_report_obss_beacon_khz(wiphy, frame, len, MHZ_TO_KHZ(freq),
sig_dbm);
}
/** /**
* cfg80211_reg_can_beacon - check if beaconing is allowed * cfg80211_reg_can_beacon - check if beaconing is allowed
......
...@@ -3095,9 +3095,10 @@ ieee80211_rx_h_mgmt_check(struct ieee80211_rx_data *rx) ...@@ -3095,9 +3095,10 @@ ieee80211_rx_h_mgmt_check(struct ieee80211_rx_data *rx)
!(status->flag & RX_FLAG_NO_SIGNAL_VAL)) !(status->flag & RX_FLAG_NO_SIGNAL_VAL))
sig = status->signal; sig = status->signal;
cfg80211_report_obss_beacon(rx->local->hw.wiphy, cfg80211_report_obss_beacon_khz(rx->local->hw.wiphy,
rx->skb->data, rx->skb->len, rx->skb->data, rx->skb->len,
status->freq, sig); ieee80211_rx_status_to_khz(status),
sig);
rx->flags |= IEEE80211_RX_BEACON_REPORTED; rx->flags |= IEEE80211_RX_BEACON_REPORTED;
} }
...@@ -3443,7 +3444,8 @@ ieee80211_rx_h_userspace_mgmt(struct ieee80211_rx_data *rx) ...@@ -3443,7 +3444,8 @@ ieee80211_rx_h_userspace_mgmt(struct ieee80211_rx_data *rx)
!(status->flag & RX_FLAG_NO_SIGNAL_VAL)) !(status->flag & RX_FLAG_NO_SIGNAL_VAL))
sig = status->signal; sig = status->signal;
if (cfg80211_rx_mgmt(&rx->sdata->wdev, status->freq, sig, if (cfg80211_rx_mgmt_khz(&rx->sdata->wdev,
ieee80211_rx_status_to_khz(status), sig,
rx->skb->data, rx->skb->len, 0)) { rx->skb->data, rx->skb->len, 0)) {
if (rx->sta) if (rx->sta)
rx->sta->rx_stats.packets++; rx->sta->rx_stats.packets++;
......
...@@ -729,7 +729,7 @@ int cfg80211_mlme_mgmt_tx(struct cfg80211_registered_device *rdev, ...@@ -729,7 +729,7 @@ int cfg80211_mlme_mgmt_tx(struct cfg80211_registered_device *rdev,
return rdev_mgmt_tx(rdev, wdev, params, cookie); return rdev_mgmt_tx(rdev, wdev, params, cookie);
} }
bool cfg80211_rx_mgmt(struct wireless_dev *wdev, int freq, int sig_dbm, bool cfg80211_rx_mgmt_khz(struct wireless_dev *wdev, int freq, int sig_dbm,
const u8 *buf, size_t len, u32 flags) const u8 *buf, size_t len, u32 flags)
{ {
struct wiphy *wiphy = wdev->wiphy; struct wiphy *wiphy = wdev->wiphy;
...@@ -785,7 +785,7 @@ bool cfg80211_rx_mgmt(struct wireless_dev *wdev, int freq, int sig_dbm, ...@@ -785,7 +785,7 @@ bool cfg80211_rx_mgmt(struct wireless_dev *wdev, int freq, int sig_dbm,
trace_cfg80211_return_bool(result); trace_cfg80211_return_bool(result);
return result; return result;
} }
EXPORT_SYMBOL(cfg80211_rx_mgmt); EXPORT_SYMBOL(cfg80211_rx_mgmt_khz);
void cfg80211_sched_dfs_chan_update(struct cfg80211_registered_device *rdev) void cfg80211_sched_dfs_chan_update(struct cfg80211_registered_device *rdev)
{ {
......
...@@ -16214,7 +16214,7 @@ int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, ...@@ -16214,7 +16214,7 @@ int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
netdev->ifindex)) || netdev->ifindex)) ||
nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
NL80211_ATTR_PAD) || NL80211_ATTR_PAD) ||
nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, KHZ_TO_MHZ(freq)) ||
(sig_dbm && (sig_dbm &&
nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
nla_put(msg, NL80211_ATTR_FRAME, len, buf) || nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
...@@ -16840,9 +16840,8 @@ void cfg80211_probe_status(struct net_device *dev, const u8 *addr, ...@@ -16840,9 +16840,8 @@ void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
} }
EXPORT_SYMBOL(cfg80211_probe_status); EXPORT_SYMBOL(cfg80211_probe_status);
void cfg80211_report_obss_beacon(struct wiphy *wiphy, void cfg80211_report_obss_beacon_khz(struct wiphy *wiphy, const u8 *frame,
const u8 *frame, size_t len, size_t len, int freq, int sig_dbm)
int freq, int sig_dbm)
{ {
struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
struct sk_buff *msg; struct sk_buff *msg;
...@@ -16865,7 +16864,8 @@ void cfg80211_report_obss_beacon(struct wiphy *wiphy, ...@@ -16865,7 +16864,8 @@ void cfg80211_report_obss_beacon(struct wiphy *wiphy,
if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
(freq && (freq &&
nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
KHZ_TO_MHZ(freq))) ||
(sig_dbm && (sig_dbm &&
nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
nla_put(msg, NL80211_ATTR_FRAME, len, frame)) nla_put(msg, NL80211_ATTR_FRAME, len, frame))
...@@ -16882,7 +16882,7 @@ void cfg80211_report_obss_beacon(struct wiphy *wiphy, ...@@ -16882,7 +16882,7 @@ void cfg80211_report_obss_beacon(struct wiphy *wiphy,
spin_unlock_bh(&rdev->beacon_registrations_lock); spin_unlock_bh(&rdev->beacon_registrations_lock);
nlmsg_free(msg); nlmsg_free(msg);
} }
EXPORT_SYMBOL(cfg80211_report_obss_beacon); EXPORT_SYMBOL(cfg80211_report_obss_beacon_khz);
#ifdef CONFIG_PM #ifdef CONFIG_PM
static int cfg80211_net_detect_results(struct sk_buff *msg, static int cfg80211_net_detect_results(struct sk_buff *msg,
......
...@@ -2840,8 +2840,8 @@ TRACE_EVENT(cfg80211_rx_mgmt, ...@@ -2840,8 +2840,8 @@ TRACE_EVENT(cfg80211_rx_mgmt,
__entry->freq = freq; __entry->freq = freq;
__entry->sig_dbm = sig_dbm; __entry->sig_dbm = sig_dbm;
), ),
TP_printk(WDEV_PR_FMT ", freq: %d, sig dbm: %d", TP_printk(WDEV_PR_FMT ", freq: "KHZ_F", sig dbm: %d",
WDEV_PR_ARG, __entry->freq, __entry->sig_dbm) WDEV_PR_ARG, PR_KHZ(__entry->freq), __entry->sig_dbm)
); );
TRACE_EVENT(cfg80211_mgmt_tx_status, TRACE_EVENT(cfg80211_mgmt_tx_status,
...@@ -3121,8 +3121,8 @@ TRACE_EVENT(cfg80211_report_obss_beacon, ...@@ -3121,8 +3121,8 @@ TRACE_EVENT(cfg80211_report_obss_beacon,
__entry->freq = freq; __entry->freq = freq;
__entry->sig_dbm = sig_dbm; __entry->sig_dbm = sig_dbm;
), ),
TP_printk(WIPHY_PR_FMT ", freq: %d, sig_dbm: %d", TP_printk(WIPHY_PR_FMT ", freq: "KHZ_F", sig_dbm: %d",
WIPHY_PR_ARG, __entry->freq, __entry->sig_dbm) WIPHY_PR_ARG, PR_KHZ(__entry->freq), __entry->sig_dbm)
); );
TRACE_EVENT(cfg80211_tdls_oper_request, TRACE_EVENT(cfg80211_tdls_oper_request,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment