1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __INC_DOT11D_H
3 #define __INC_DOT11D_H
4 
5 #include "ieee80211.h"
6 
7 struct chnl_txpower_triple {
8 	u8  first_channel;
9 	u8  num_channels;
10 	u8  max_tx_pwr_dbm;
11 };
12 
13 enum dot11d_state {
14 	DOT11D_STATE_NONE = 0,
15 	DOT11D_STATE_LEARNED,
16 	DOT11D_STATE_DONE,
17 };
18 
19 struct rt_dot11d_info {
20 	bool enabled; /* dot11MultiDomainCapabilityEnabled */
21 
22 	u16 country_ie_len; /* > 0 if country_ie_buf[] contains valid country information element. */
23 	u8  country_ie_buf[MAX_IE_LEN];
24 	u8  country_ie_src_addr[6]; /* Source AP of the country IE. */
25 	u8  country_ie_watchdog;
26 
27 	u8  channel_map[MAX_CHANNEL_NUMBER + 1];  /* !Value 0: Invalid, 1: Valid (active scan), 2: Valid (passive scan) */
28 	u8  max_tx_pwr_dbm_list[MAX_CHANNEL_NUMBER + 1];
29 
30 	enum dot11d_state state;
31 };
32 
33 #define eqMacAddr(a, b)		(((a)[0] == (b)[0] &&		    \
34 	(a)[1] == (b)[1] && (a)[2] == (b)[2] && (a)[3] == (b)[3] && \
35 	(a)[4] == (b)[4] && (a)[5] == (b)[5]) ? 1 : 0)
36 #define cpMacAddr(des, src)	      ((des)[0] = (src)[0], \
37 	(des)[1] = (src)[1], (des)[2] = (src)[2], \
38 	(des)[3] = (src)[3], (des)[4] = (src)[4], \
39 	(des)[5] = (src)[5])
40 #define GET_DOT11D_INFO(__pIeeeDev) ((struct rt_dot11d_info *)((__pIeeeDev)->pDot11dInfo))
41 
42 #define IS_DOT11D_ENABLE(__pIeeeDev) (GET_DOT11D_INFO(__pIeeeDev)->enabled)
43 #define IS_COUNTRY_IE_VALID(__pIeeeDev) (GET_DOT11D_INFO(__pIeeeDev)->country_ie_len > 0)
44 
45 #define IS_EQUAL_CIE_SRC(__pIeeeDev, __pTa) eqMacAddr(GET_DOT11D_INFO(__pIeeeDev)->country_ie_src_addr, __pTa)
46 #define UPDATE_CIE_SRC(__pIeeeDev, __pTa) cpMacAddr(GET_DOT11D_INFO(__pIeeeDev)->country_ie_src_addr, __pTa)
47 
48 #define GET_CIE_WATCHDOG(__pIeeeDev) (GET_DOT11D_INFO(__pIeeeDev)->country_ie_watchdog)
49 #define RESET_CIE_WATCHDOG(__pIeeeDev) (GET_CIE_WATCHDOG(__pIeeeDev) = 0)
50 #define UPDATE_CIE_WATCHDOG(__pIeeeDev) (++GET_CIE_WATCHDOG(__pIeeeDev))
51 
52 void
53 Dot11d_Init(
54 	struct ieee80211_device *dev
55 	);
56 
57 void
58 Dot11d_Reset(
59 	struct ieee80211_device *dev
60 	);
61 
62 void
63 Dot11d_UpdateCountryIe(
64 	struct ieee80211_device *dev,
65 	u8 *pTaddr,
66 	u16 CoutryIeLen,
67 	u8 *pCoutryIe
68 	);
69 
70 u8
71 DOT11D_GetMaxTxPwrInDbm(
72 	struct ieee80211_device *dev,
73 	u8 Channel
74 	);
75 
76 void
77 DOT11D_ScanComplete(
78 	struct ieee80211_device *dev
79 	);
80 
81 int IsLegalChannel(
82 	struct ieee80211_device *dev,
83 	u8 channel
84 );
85 
86 int ToLegalChannel(
87 	struct ieee80211_device *dev,
88 	u8 channel
89 );
90 #endif /* #ifndef __INC_DOT11D_H */
91