xref: /linux/drivers/net/wireless/realtek/rtw88/util.h (revision 9f2c9170934eace462499ba0bfe042cc72900173)
1 /* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
2 /* Copyright(c) 2018-2019  Realtek Corporation
3  */
4 
5 #ifndef __RTW_UTIL_H__
6 #define __RTW_UTIL_H__
7 
8 struct rtw_dev;
9 
10 #define rtw_iterate_vifs_atomic(rtwdev, iterator, data)                        \
11 	ieee80211_iterate_active_interfaces_atomic(rtwdev->hw,                 \
12 			IEEE80211_IFACE_ITER_NORMAL, iterator, data)
13 #define rtw_iterate_stas_atomic(rtwdev, iterator, data)                        \
14 	ieee80211_iterate_stations_atomic(rtwdev->hw, iterator, data)
15 #define rtw_iterate_keys(rtwdev, vif, iterator, data)			       \
16 	ieee80211_iter_keys(rtwdev->hw, vif, iterator, data)
17 #define rtw_iterate_keys_rcu(rtwdev, vif, iterator, data)		       \
18 	ieee80211_iter_keys_rcu((rtwdev)->hw, vif, iterator, data)
19 
20 void rtw_iterate_vifs(struct rtw_dev *rtwdev,
21 		      void (*iterator)(void *data, u8 *mac,
22 				       struct ieee80211_vif *vif),
23 		      void *data);
24 void rtw_iterate_stas(struct rtw_dev *rtwdev,
25 		      void (*iterator)(void *data,
26 				       struct ieee80211_sta *sta),
27 				       void *data);
28 
29 static inline u8 *get_hdr_bssid(struct ieee80211_hdr *hdr)
30 {
31 	__le16 fc = hdr->frame_control;
32 	u8 *bssid;
33 
34 	if (ieee80211_has_tods(fc))
35 		bssid = hdr->addr1;
36 	else if (ieee80211_has_fromds(fc))
37 		bssid = hdr->addr2;
38 	else
39 		bssid = hdr->addr3;
40 
41 	return bssid;
42 }
43 
44 #endif
45