aboutsummaryrefslogtreecommitdiffstats
path: root/net/wireless/nl80211.c
diff options
context:
space:
mode:
authorJohannes Berg <johannes.berg@intel.com>2014-11-26 06:37:43 -0500
committerJohannes Berg <johannes.berg@intel.com>2014-11-26 06:47:38 -0500
commit5b97f49d653d366d8cb03cab40f8c45eb59dc70c (patch)
tree4ace82936a0c06750393841c616e13219ced695b /net/wireless/nl80211.c
parent40a11ca83de91f6bb2306580e7732ad3d97f201a (diff)
cfg80211: refactor the various CQM event sending code
Much of the code can be shared by moving it into helper functions for the CQM event sending. Also move the code closer together, even in the header file. Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Diffstat (limited to 'net/wireless/nl80211.c')
-rw-r--r--net/wireless/nl80211.c222
1 files changed, 99 insertions, 123 deletions
diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c
index b5e3c489239d..9c4d0102d34d 100644
--- a/net/wireless/nl80211.c
+++ b/net/wireless/nl80211.c
@@ -11766,55 +11766,132 @@ void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
11766} 11766}
11767EXPORT_SYMBOL(cfg80211_mgmt_tx_status); 11767EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
11768 11768
11769void cfg80211_cqm_rssi_notify(struct net_device *dev, 11769static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev,
11770 enum nl80211_cqm_rssi_threshold_event rssi_event, 11770 const char *mac, gfp_t gfp)
11771 gfp_t gfp)
11772{ 11771{
11773 struct wireless_dev *wdev = dev->ieee80211_ptr; 11772 struct wireless_dev *wdev = dev->ieee80211_ptr;
11774 struct wiphy *wiphy = wdev->wiphy; 11773 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
11775 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 11774 struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11776 struct sk_buff *msg; 11775 void **cb;
11777 struct nlattr *pinfoattr;
11778 void *hdr;
11779
11780 trace_cfg80211_cqm_rssi_notify(dev, rssi_event);
11781 11776
11782 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11783 if (!msg) 11777 if (!msg)
11784 return; 11778 return NULL;
11785 11779
11786 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); 11780 cb = (void **)msg->cb;
11787 if (!hdr) { 11781
11782 cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
11783 if (!cb[0]) {
11788 nlmsg_free(msg); 11784 nlmsg_free(msg);
11789 return; 11785 return NULL;
11790 } 11786 }
11791 11787
11792 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 11788 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11793 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) 11789 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
11794 goto nla_put_failure; 11790 goto nla_put_failure;
11795 11791
11796 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); 11792 if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac))
11797 if (!pinfoattr)
11798 goto nla_put_failure; 11793 goto nla_put_failure;
11799 11794
11800 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, 11795 cb[1] = nla_nest_start(msg, NL80211_ATTR_CQM);
11801 rssi_event)) 11796 if (!cb[1])
11802 goto nla_put_failure; 11797 goto nla_put_failure;
11803 11798
11804 nla_nest_end(msg, pinfoattr); 11799 cb[2] = rdev;
11805 11800
11806 genlmsg_end(msg, hdr); 11801 return msg;
11802 nla_put_failure:
11803 nlmsg_free(msg);
11804 return NULL;
11805}
11806
11807static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp)
11808{
11809 void **cb = (void **)msg->cb;
11810 struct cfg80211_registered_device *rdev = cb[2];
11811
11812 nla_nest_end(msg, cb[1]);
11813 genlmsg_end(msg, cb[0]);
11814
11815 memset(msg->cb, 0, sizeof(msg->cb));
11807 11816
11808 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 11817 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
11809 NL80211_MCGRP_MLME, gfp); 11818 NL80211_MCGRP_MLME, gfp);
11819}
11820
11821void cfg80211_cqm_rssi_notify(struct net_device *dev,
11822 enum nl80211_cqm_rssi_threshold_event rssi_event,
11823 gfp_t gfp)
11824{
11825 struct sk_buff *msg;
11826
11827 trace_cfg80211_cqm_rssi_notify(dev, rssi_event);
11828
11829 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
11830 if (!msg)
11831 return;
11832
11833 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
11834 rssi_event))
11835 goto nla_put_failure;
11836
11837 cfg80211_send_cqm(msg, gfp);
11838
11810 return; 11839 return;
11811 11840
11812 nla_put_failure: 11841 nla_put_failure:
11813 genlmsg_cancel(msg, hdr);
11814 nlmsg_free(msg); 11842 nlmsg_free(msg);
11815} 11843}
11816EXPORT_SYMBOL(cfg80211_cqm_rssi_notify); 11844EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
11817 11845
11846void cfg80211_cqm_txe_notify(struct net_device *dev,
11847 const u8 *peer, u32 num_packets,
11848 u32 rate, u32 intvl, gfp_t gfp)
11849{
11850 struct sk_buff *msg;
11851
11852 msg = cfg80211_prepare_cqm(dev, peer, gfp);
11853 if (!msg)
11854 return;
11855
11856 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
11857 goto nla_put_failure;
11858
11859 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
11860 goto nla_put_failure;
11861
11862 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
11863 goto nla_put_failure;
11864
11865 cfg80211_send_cqm(msg, gfp);
11866 return;
11867
11868 nla_put_failure:
11869 nlmsg_free(msg);
11870}
11871EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
11872
11873void cfg80211_cqm_pktloss_notify(struct net_device *dev,
11874 const u8 *peer, u32 num_packets, gfp_t gfp)
11875{
11876 struct sk_buff *msg;
11877
11878 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
11879
11880 msg = cfg80211_prepare_cqm(dev, peer, gfp);
11881 if (!msg)
11882 return;
11883
11884 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
11885 goto nla_put_failure;
11886
11887 cfg80211_send_cqm(msg, gfp);
11888 return;
11889
11890 nla_put_failure:
11891 nlmsg_free(msg);
11892}
11893EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
11894
11818static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, 11895static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
11819 struct net_device *netdev, const u8 *bssid, 11896 struct net_device *netdev, const u8 *bssid,
11820 const u8 *replay_ctr, gfp_t gfp) 11897 const u8 *replay_ctr, gfp_t gfp)
@@ -12003,59 +12080,6 @@ void cfg80211_ch_switch_started_notify(struct net_device *dev,
12003} 12080}
12004EXPORT_SYMBOL(cfg80211_ch_switch_started_notify); 12081EXPORT_SYMBOL(cfg80211_ch_switch_started_notify);
12005 12082
12006void cfg80211_cqm_txe_notify(struct net_device *dev,
12007 const u8 *peer, u32 num_packets,
12008 u32 rate, u32 intvl, gfp_t gfp)
12009{
12010 struct wireless_dev *wdev = dev->ieee80211_ptr;
12011 struct wiphy *wiphy = wdev->wiphy;
12012 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
12013 struct sk_buff *msg;
12014 struct nlattr *pinfoattr;
12015 void *hdr;
12016
12017 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
12018 if (!msg)
12019 return;
12020
12021 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
12022 if (!hdr) {
12023 nlmsg_free(msg);
12024 return;
12025 }
12026
12027 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12028 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
12029 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
12030 goto nla_put_failure;
12031
12032 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
12033 if (!pinfoattr)
12034 goto nla_put_failure;
12035
12036 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
12037 goto nla_put_failure;
12038
12039 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
12040 goto nla_put_failure;
12041
12042 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
12043 goto nla_put_failure;
12044
12045 nla_nest_end(msg, pinfoattr);
12046
12047 genlmsg_end(msg, hdr);
12048
12049 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
12050 NL80211_MCGRP_MLME, gfp);
12051 return;
12052
12053 nla_put_failure:
12054 genlmsg_cancel(msg, hdr);
12055 nlmsg_free(msg);
12056}
12057EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
12058
12059void 12083void
12060nl80211_radar_notify(struct cfg80211_registered_device *rdev, 12084nl80211_radar_notify(struct cfg80211_registered_device *rdev,
12061 const struct cfg80211_chan_def *chandef, 12085 const struct cfg80211_chan_def *chandef,
@@ -12104,54 +12128,6 @@ nl80211_radar_notify(struct cfg80211_registered_device *rdev,
12104 nlmsg_free(msg); 12128 nlmsg_free(msg);
12105} 12129}
12106 12130
12107void cfg80211_cqm_pktloss_notify(struct net_device *dev,
12108 const u8 *peer, u32 num_packets, gfp_t gfp)
12109{
12110 struct wireless_dev *wdev = dev->ieee80211_ptr;
12111 struct wiphy *wiphy = wdev->wiphy;
12112 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
12113 struct sk_buff *msg;
12114 struct nlattr *pinfoattr;
12115 void *hdr;
12116
12117 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
12118
12119 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12120 if (!msg)
12121 return;
12122
12123 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
12124 if (!hdr) {
12125 nlmsg_free(msg);
12126 return;
12127 }
12128
12129 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12130 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
12131 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
12132 goto nla_put_failure;
12133
12134 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
12135 if (!pinfoattr)
12136 goto nla_put_failure;
12137
12138 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
12139 goto nla_put_failure;
12140
12141 nla_nest_end(msg, pinfoattr);
12142
12143 genlmsg_end(msg, hdr);
12144
12145 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
12146 NL80211_MCGRP_MLME, gfp);
12147 return;
12148
12149 nla_put_failure:
12150 genlmsg_cancel(msg, hdr);
12151 nlmsg_free(msg);
12152}
12153EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
12154
12155void cfg80211_probe_status(struct net_device *dev, const u8 *addr, 12131void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
12156 u64 cookie, bool acked, gfp_t gfp) 12132 u64 cookie, bool acked, gfp_t gfp)
12157{ 12133{