Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

+127 -151
+27 -27
include/net/cfg80211.h
··· 4643 4643 gfp_t gfp); 4644 4644 4645 4645 /** 4646 - * cfg80211_radar_event - radar detection event 4647 - * @wiphy: the wiphy 4648 - * @chandef: chandef for the current channel 4649 - * @gfp: context flags 4650 - * 4651 - * This function is called when a radar is detected on the current chanenl. 4652 - */ 4653 - void cfg80211_radar_event(struct wiphy *wiphy, 4654 - struct cfg80211_chan_def *chandef, gfp_t gfp); 4655 - 4656 - /** 4657 - * cfg80211_cac_event - Channel availability check (CAC) event 4658 - * @netdev: network device 4659 - * @chandef: chandef for the current channel 4660 - * @event: type of event 4661 - * @gfp: context flags 4662 - * 4663 - * This function is called when a Channel availability check (CAC) is finished 4664 - * or aborted. This must be called to notify the completion of a CAC process, 4665 - * also by full-MAC drivers. 4666 - */ 4667 - void cfg80211_cac_event(struct net_device *netdev, 4668 - const struct cfg80211_chan_def *chandef, 4669 - enum nl80211_radar_event event, gfp_t gfp); 4670 - 4671 - 4672 - /** 4673 4646 * cfg80211_cqm_pktloss_notify - notify userspace about packetloss to peer 4674 4647 * @dev: network device 4675 4648 * @peer: peer's MAC address ··· 4668 4695 */ 4669 4696 void cfg80211_cqm_txe_notify(struct net_device *dev, const u8 *peer, 4670 4697 u32 num_packets, u32 rate, u32 intvl, gfp_t gfp); 4698 + 4699 + /** 4700 + * cfg80211_radar_event - radar detection event 4701 + * @wiphy: the wiphy 4702 + * @chandef: chandef for the current channel 4703 + * @gfp: context flags 4704 + * 4705 + * This function is called when a radar is detected on the current chanenl. 4706 + */ 4707 + void cfg80211_radar_event(struct wiphy *wiphy, 4708 + struct cfg80211_chan_def *chandef, gfp_t gfp); 4709 + 4710 + /** 4711 + * cfg80211_cac_event - Channel availability check (CAC) event 4712 + * @netdev: network device 4713 + * @chandef: chandef for the current channel 4714 + * @event: type of event 4715 + * @gfp: context flags 4716 + * 4717 + * This function is called when a Channel availability check (CAC) is finished 4718 + * or aborted. This must be called to notify the completion of a CAC process, 4719 + * also by full-MAC drivers. 4720 + */ 4721 + void cfg80211_cac_event(struct net_device *netdev, 4722 + const struct cfg80211_chan_def *chandef, 4723 + enum nl80211_radar_event event, gfp_t gfp); 4724 + 4671 4725 4672 4726 /** 4673 4727 * cfg80211_gtk_rekey_notify - notify userspace about driver rekeying
+100 -124
net/wireless/nl80211.c
··· 11766 11766 } 11767 11767 EXPORT_SYMBOL(cfg80211_mgmt_tx_status); 11768 11768 11769 - void cfg80211_cqm_rssi_notify(struct net_device *dev, 11770 - enum nl80211_cqm_rssi_threshold_event rssi_event, 11771 - gfp_t gfp) 11769 + static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev, 11770 + const char *mac, gfp_t gfp) 11772 11771 { 11773 11772 struct wireless_dev *wdev = dev->ieee80211_ptr; 11774 - struct wiphy *wiphy = wdev->wiphy; 11775 - struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 11776 - struct sk_buff *msg; 11777 - struct nlattr *pinfoattr; 11778 - void *hdr; 11773 + struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); 11774 + struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 11775 + void **cb; 11779 11776 11780 - trace_cfg80211_cqm_rssi_notify(dev, rssi_event); 11781 - 11782 - msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 11783 11777 if (!msg) 11784 - return; 11778 + return NULL; 11785 11779 11786 - hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); 11787 - if (!hdr) { 11780 + cb = (void **)msg->cb; 11781 + 11782 + cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); 11783 + if (!cb[0]) { 11788 11784 nlmsg_free(msg); 11789 - return; 11785 + return NULL; 11790 11786 } 11791 11787 11792 11788 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 11793 11789 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) 11794 11790 goto nla_put_failure; 11795 11791 11796 - pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); 11797 - if (!pinfoattr) 11792 + if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac)) 11798 11793 goto nla_put_failure; 11794 + 11795 + cb[1] = nla_nest_start(msg, NL80211_ATTR_CQM); 11796 + if (!cb[1]) 11797 + goto nla_put_failure; 11798 + 11799 + cb[2] = rdev; 11800 + 11801 + return msg; 11802 + nla_put_failure: 11803 + nlmsg_free(msg); 11804 + return NULL; 11805 + } 11806 + 11807 + static 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)); 11816 + 11817 + genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 11818 + NL80211_MCGRP_MLME, gfp); 11819 + } 11820 + 11821 + void 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; 11799 11832 11800 11833 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, 11801 11834 rssi_event)) 11802 11835 goto nla_put_failure; 11803 11836 11804 - nla_nest_end(msg, pinfoattr); 11837 + cfg80211_send_cqm(msg, gfp); 11805 11838 11806 - genlmsg_end(msg, hdr); 11807 - 11808 - genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 11809 - NL80211_MCGRP_MLME, gfp); 11810 11839 return; 11811 11840 11812 11841 nla_put_failure: 11813 - genlmsg_cancel(msg, hdr); 11814 11842 nlmsg_free(msg); 11815 11843 } 11816 11844 EXPORT_SYMBOL(cfg80211_cqm_rssi_notify); 11845 + 11846 + void 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 + } 11871 + EXPORT_SYMBOL(cfg80211_cqm_txe_notify); 11872 + 11873 + void 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 + } 11893 + EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify); 11817 11894 11818 11895 static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, 11819 11896 struct net_device *netdev, const u8 *bssid, ··· 12080 12003 } 12081 12004 EXPORT_SYMBOL(cfg80211_ch_switch_started_notify); 12082 12005 12083 - void cfg80211_cqm_txe_notify(struct net_device *dev, 12084 - const u8 *peer, u32 num_packets, 12085 - u32 rate, u32 intvl, gfp_t gfp) 12086 - { 12087 - struct wireless_dev *wdev = dev->ieee80211_ptr; 12088 - struct wiphy *wiphy = wdev->wiphy; 12089 - struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 12090 - struct sk_buff *msg; 12091 - struct nlattr *pinfoattr; 12092 - void *hdr; 12093 - 12094 - msg = nlmsg_new(NLMSG_GOODSIZE, gfp); 12095 - if (!msg) 12096 - return; 12097 - 12098 - hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); 12099 - if (!hdr) { 12100 - nlmsg_free(msg); 12101 - return; 12102 - } 12103 - 12104 - if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 12105 - nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || 12106 - nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) 12107 - goto nla_put_failure; 12108 - 12109 - pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); 12110 - if (!pinfoattr) 12111 - goto nla_put_failure; 12112 - 12113 - if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) 12114 - goto nla_put_failure; 12115 - 12116 - if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) 12117 - goto nla_put_failure; 12118 - 12119 - if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) 12120 - goto nla_put_failure; 12121 - 12122 - nla_nest_end(msg, pinfoattr); 12123 - 12124 - genlmsg_end(msg, hdr); 12125 - 12126 - genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 12127 - NL80211_MCGRP_MLME, gfp); 12128 - return; 12129 - 12130 - nla_put_failure: 12131 - genlmsg_cancel(msg, hdr); 12132 - nlmsg_free(msg); 12133 - } 12134 - EXPORT_SYMBOL(cfg80211_cqm_txe_notify); 12135 - 12136 12006 void 12137 12007 nl80211_radar_notify(struct cfg80211_registered_device *rdev, 12138 12008 const struct cfg80211_chan_def *chandef, ··· 12127 12103 genlmsg_cancel(msg, hdr); 12128 12104 nlmsg_free(msg); 12129 12105 } 12130 - 12131 - void cfg80211_cqm_pktloss_notify(struct net_device *dev, 12132 - const u8 *peer, u32 num_packets, gfp_t gfp) 12133 - { 12134 - struct wireless_dev *wdev = dev->ieee80211_ptr; 12135 - struct wiphy *wiphy = wdev->wiphy; 12136 - struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 12137 - struct sk_buff *msg; 12138 - struct nlattr *pinfoattr; 12139 - void *hdr; 12140 - 12141 - trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets); 12142 - 12143 - msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 12144 - if (!msg) 12145 - return; 12146 - 12147 - hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); 12148 - if (!hdr) { 12149 - nlmsg_free(msg); 12150 - return; 12151 - } 12152 - 12153 - if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 12154 - nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || 12155 - nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) 12156 - goto nla_put_failure; 12157 - 12158 - pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); 12159 - if (!pinfoattr) 12160 - goto nla_put_failure; 12161 - 12162 - if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) 12163 - goto nla_put_failure; 12164 - 12165 - nla_nest_end(msg, pinfoattr); 12166 - 12167 - genlmsg_end(msg, hdr); 12168 - 12169 - genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 12170 - NL80211_MCGRP_MLME, gfp); 12171 - return; 12172 - 12173 - nla_put_failure: 12174 - genlmsg_cancel(msg, hdr); 12175 - nlmsg_free(msg); 12176 - } 12177 - EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify); 12178 12106 12179 12107 void cfg80211_probe_status(struct net_device *dev, const u8 *addr, 12180 12108 u64 cookie, bool acked, gfp_t gfp)