History

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.

Thomas Pedersen committed 6 years ago

Commit e76fede1 parent c0336956 files · +71 −23Browse files

Unified · Split

6 files
  1. include/linux/ieee80211.h +2 −0
  2. include/net/cfg80211.h +49 −5
  3. net/mac80211/rx.c +7 −5
  4. net/wireless/mlme.c +3 −3
  5. net/wireless/nl80211.c +6 −6
  6. net/wireless/trace.h +4 −4
include/linux/ieee80211.h+2−0
@@ -3333,6 +3333,8 @@ static inline int ieee80211_get_tdls_action(struct sk_buff *skb, u32 hdr_size) · 3332 unmodified lines
33333333 /* convert frequencies */
33343334 #define MHZ_TO_KHZ(freq) ((freq) * 1000)
33353335 #define KHZ_TO_MHZ(freq) ((freq) / 1000)
3336+#define PR_KHZ(f) KHZ_TO_MHZ(f), f % 1000
3337+#define KHZ_F "%d.%03d"
33363338
33373339 /* convert powers */
33383340 #define DBI_TO_MBI(gain) ((gain) * 100)
include/net/cfg80211.h+49−5
@@ -6988,6 +6988,26 @@ void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr, · 6987 unmodified lines
69886988 enum nl80211_connect_failed_reason reason,
69896989 gfp_t gfp);
69906990
6991+/**
6992+ * cfg80211_rx_mgmt_khz - notification of received, unprocessed management frame
6993+ * @wdev: wireless device receiving the frame
6994+ * @freq: Frequency on which the frame was received in KHz
6995+ * @sig_dbm: signal strength in dBm, or 0 if unknown
6996+ * @buf: Management frame (header + body)
6997+ * @len: length of the frame data
6998+ * @flags: flags, as defined in enum nl80211_rxmgmt_flags
6999+ *
7000+ * This function is called whenever an Action frame is received for a station
7001+ * mode interface, but is not processed in kernel.
7002+ *
7003+ * Return: %true if a user space application has registered for this frame.
7004+ * For action frames, that makes it responsible for rejecting unrecognized
7005+ * action frames; %false otherwise, in which case for action frames the
7006+ * driver is responsible for rejecting the frame.
7007+ */
7008+bool cfg80211_rx_mgmt_khz(struct wireless_dev *wdev, int freq, int sig_dbm,
7009+ const u8 *buf, size_t len, u32 flags);
7010+
69917011 /**
69927012 * cfg80211_rx_mgmt - notification of received, unprocessed management frame
69937013 * @wdev: wireless device receiving the frame
@@ -7005,8 +7025,13 @@ void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr, · 11 unmodified lines
70057025 * action frames; %false otherwise, in which case for action frames the
70067026 * driver is responsible for rejecting the frame.
70077027 */
7008−bool cfg80211_rx_mgmt(struct wireless_dev *wdev, int freq, int sig_dbm,
7009− const u8 *buf, size_t len, u32 flags);
7028+static inline bool cfg80211_rx_mgmt(struct wireless_dev *wdev, int freq,
7029+ int sig_dbm, const u8 *buf, size_t len,
7030+ u32 flags)
7031+{
7032+ return cfg80211_rx_mgmt_khz(wdev, MHZ_TO_KHZ(freq), sig_dbm, buf, len,
7033+ flags);
7034+}
70107035
70117036 /**
70127037 * 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, · 191 unmodified lines
72047229 u64 cookie, bool acked, s32 ack_signal,
72057230 bool is_valid_ack_signal, gfp_t gfp);
72067231
7232+/**
7233+ * cfg80211_report_obss_beacon_khz - report beacon from other APs
7234+ * @wiphy: The wiphy that received the beacon
7235+ * @frame: the frame
7236+ * @len: length of the frame
7237+ * @freq: frequency the frame was received on in KHz
7238+ * @sig_dbm: signal strength in dBm, or 0 if unknown
7239+ *
7240+ * Use this function to report to userspace when a beacon was
7241+ * received. It is not useful to call this when there is no
7242+ * netdev that is in AP/GO mode.
7243+ */
7244+void cfg80211_report_obss_beacon_khz(struct wiphy *wiphy, const u8 *frame,
7245+ size_t len, int freq, int sig_dbm);
7246+
72077247 /**
72087248 * cfg80211_report_obss_beacon - report beacon from other APs
72097249 * @wiphy: The wiphy that received the beacon
@@ -7216,9 +7256,13 @@ void cfg80211_probe_status(struct net_device *dev, const u8 *addr, · 6 unmodified lines
72167256 * received. It is not useful to call this when there is no
72177257 * netdev that is in AP/GO mode.
72187258 */
7219−void cfg80211_report_obss_beacon(struct wiphy *wiphy,
7220− const u8 *frame, size_t len,
7221− int freq, int sig_dbm);
7259+static inline void cfg80211_report_obss_beacon(struct wiphy *wiphy,
7260+ const u8 *frame, size_t len,
7261+ int freq, int sig_dbm)
7262+{
7263+ cfg80211_report_obss_beacon_khz(wiphy, frame, len, MHZ_TO_KHZ(freq),
7264+ sig_dbm);
7265+}
72227266
72237267 /**
72247268 * cfg80211_reg_can_beacon - check if beaconing is allowed
net/mac80211/rx.c+7−5
@@ -3095,9 +3095,10 @@ ieee80211_rx_h_mgmt_check(struct ieee80211_rx_data *rx) · 3094 unmodified lines
30953095 !(status->flag & RX_FLAG_NO_SIGNAL_VAL))
30963096 sig = status->signal;
30973097
3098− cfg80211_report_obss_beacon(rx->local->hw.wiphy,
3099− rx->skb->data, rx->skb->len,
3100− status->freq, sig);
3098+ cfg80211_report_obss_beacon_khz(rx->local->hw.wiphy,
3099+ rx->skb->data, rx->skb->len,
3100+ ieee80211_rx_status_to_khz(status),
3101+ sig);
31013102 rx->flags |= IEEE80211_RX_BEACON_REPORTED;
31023103 }
31033104
@@ -3443,8 +3444,9 @@ ieee80211_rx_h_userspace_mgmt(struct ieee80211_rx_data *rx) · 339 unmodified lines
34433444 !(status->flag & RX_FLAG_NO_SIGNAL_VAL))
34443445 sig = status->signal;
34453446
3446− if (cfg80211_rx_mgmt(&rx->sdata->wdev, status->freq, sig,
3447− rx->skb->data, rx->skb->len, 0)) {
3447+ if (cfg80211_rx_mgmt_khz(&rx->sdata->wdev,
3448+ ieee80211_rx_status_to_khz(status), sig,
3449+ rx->skb->data, rx->skb->len, 0)) {
34483450 if (rx->sta)
34493451 rx->sta->rx_stats.packets++;
34503452 dev_kfree_skb(rx->skb);
net/wireless/mlme.c+3−3
@@ -729,8 +729,8 @@ int cfg80211_mlme_mgmt_tx(struct cfg80211_registered_device *rdev, · 728 unmodified lines
729729 return rdev_mgmt_tx(rdev, wdev, params, cookie);
730730 }
731731
732−bool cfg80211_rx_mgmt(struct wireless_dev *wdev, int freq, int sig_dbm,
733− const u8 *buf, size_t len, u32 flags)
732+bool cfg80211_rx_mgmt_khz(struct wireless_dev *wdev, int freq, int sig_dbm,
733+ const u8 *buf, size_t len, u32 flags)
734734 {
735735 struct wiphy *wiphy = wdev->wiphy;
736736 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
@@ -785,7 +785,7 @@ bool cfg80211_rx_mgmt(struct wireless_dev *wdev, int freq, int sig_dbm, · 48 unmodified lines
785785 trace_cfg80211_return_bool(result);
786786 return result;
787787 }
788−EXPORT_SYMBOL(cfg80211_rx_mgmt);
788+EXPORT_SYMBOL(cfg80211_rx_mgmt_khz);
789789
790790 void cfg80211_sched_dfs_chan_update(struct cfg80211_registered_device *rdev)
791791 {
net/wireless/nl80211.c+6−6
@@ -16214,7 +16214,7 @@ int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, · 16213 unmodified lines
1621416214 netdev->ifindex)) ||
1621516215 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
1621616216 NL80211_ATTR_PAD) ||
16217− nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
16217+ nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, KHZ_TO_MHZ(freq)) ||
1621816218 (sig_dbm &&
1621916219 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
1622016220 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
@@ -16840,9 +16840,8 @@ void cfg80211_probe_status(struct net_device *dev, const u8 *addr, · 619 unmodified lines
1684016840 }
1684116841 EXPORT_SYMBOL(cfg80211_probe_status);
1684216842
16843−void cfg80211_report_obss_beacon(struct wiphy *wiphy,
16844− const u8 *frame, size_t len,
16845− int freq, int sig_dbm)
16843+void cfg80211_report_obss_beacon_khz(struct wiphy *wiphy, const u8 *frame,
16844+ size_t len, int freq, int sig_dbm)
1684616845 {
1684716846 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
1684816847 struct sk_buff *msg;
@@ -16865,7 +16864,8 @@ void cfg80211_report_obss_beacon(struct wiphy *wiphy, · 16 unmodified lines
1686516864
1686616865 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
1686716866 (freq &&
16868− nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
16867+ nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
16868+ KHZ_TO_MHZ(freq))) ||
1686916869 (sig_dbm &&
1687016870 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
1687116871 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
@@ -16882,7 +16882,7 @@ void cfg80211_report_obss_beacon(struct wiphy *wiphy, · 10 unmodified lines
1688216882 spin_unlock_bh(&rdev->beacon_registrations_lock);
1688316883 nlmsg_free(msg);
1688416884 }
16885−EXPORT_SYMBOL(cfg80211_report_obss_beacon);
16885+EXPORT_SYMBOL(cfg80211_report_obss_beacon_khz);
1688616886
1688716887 #ifdef CONFIG_PM
1688816888 static int cfg80211_net_detect_results(struct sk_buff *msg,
net/wireless/trace.h+4−4
@@ -2840,8 +2840,8 @@ TRACE_EVENT(cfg80211_rx_mgmt, · 2839 unmodified lines
28402840 __entry->freq = freq;
28412841 __entry->sig_dbm = sig_dbm;
28422842 ),
2843− TP_printk(WDEV_PR_FMT ", freq: %d, sig dbm: %d",
2844− WDEV_PR_ARG, __entry->freq, __entry->sig_dbm)
2843+ TP_printk(WDEV_PR_FMT ", freq: "KHZ_F", sig dbm: %d",
2844+ WDEV_PR_ARG, PR_KHZ(__entry->freq), __entry->sig_dbm)
28452845 );
28462846
28472847 TRACE_EVENT(cfg80211_mgmt_tx_status,
@@ -3121,8 +3121,8 @@ TRACE_EVENT(cfg80211_report_obss_beacon, · 273 unmodified lines
31213121 __entry->freq = freq;
31223122 __entry->sig_dbm = sig_dbm;
31233123 ),
3124− TP_printk(WIPHY_PR_FMT ", freq: %d, sig_dbm: %d",
3125− WIPHY_PR_ARG, __entry->freq, __entry->sig_dbm)
3124+ TP_printk(WIPHY_PR_FMT ", freq: "KHZ_F", sig_dbm: %d",
3125+ WIPHY_PR_ARG, PR_KHZ(__entry->freq), __entry->sig_dbm)
31263126 );
31273127
31283128 TRACE_EVENT(cfg80211_tdls_oper_request,