1 // SPDX-License-Identifier: GPL-2.0
2 /* Implement 802.11d. */
6 void rtl8192u_dot11d_init(struct ieee80211_device *ieee)
8 struct rt_dot11d_info *dot11d_info = GET_DOT11D_INFO(ieee);
10 dot11d_info->dot11d_enabled = false;
12 dot11d_info->state = DOT11D_STATE_NONE;
13 dot11d_info->country_ie_len = 0;
14 memset(dot11d_info->channel_map, 0, MAX_CHANNEL_NUMBER + 1);
15 memset(dot11d_info->max_tx_pwr_dbm_list, 0xFF, MAX_CHANNEL_NUMBER+1);
16 RESET_CIE_WATCHDOG(ieee);
18 netdev_info(ieee->dev, "rtl8192u_dot11d_init()\n");
20 EXPORT_SYMBOL(rtl8192u_dot11d_init);
22 /* Reset to the state as we are just entering a regulatory domain. */
23 void dot11d_reset(struct ieee80211_device *ieee)
26 struct rt_dot11d_info *dot11d_info = GET_DOT11D_INFO(ieee);
27 /* Clear old channel map */
28 memset(dot11d_info->channel_map, 0, MAX_CHANNEL_NUMBER+1);
29 memset(dot11d_info->max_tx_pwr_dbm_list, 0xFF, MAX_CHANNEL_NUMBER+1);
30 /* Set new channel map */
31 for (i = 1; i <= 11; i++)
32 (dot11d_info->channel_map)[i] = 1;
34 for (i = 12; i <= 14; i++)
35 (dot11d_info->channel_map)[i] = 2;
37 dot11d_info->state = DOT11D_STATE_NONE;
38 dot11d_info->country_ie_len = 0;
39 RESET_CIE_WATCHDOG(ieee);
41 EXPORT_SYMBOL(dot11d_reset);
44 * Update country IE from Beacon or Probe Resopnse and configure PHY for
45 * operation in the regulatory domain.
47 * TODO: Configure Tx power.
49 * 1. IS_DOT11D_ENABLE() is TRUE.
50 * 2. Input IE is an valid one.
52 void dot11d_update_country_ie(struct ieee80211_device *dev, u8 *pTaddr,
53 u16 CoutryIeLen, u8 *pCoutryIe)
55 struct rt_dot11d_info *dot11d_info = GET_DOT11D_INFO(dev);
56 u8 i, j, NumTriples, MaxChnlNum;
57 struct chnl_txpower_triple *pTriple;
59 memset(dot11d_info->channel_map, 0, MAX_CHANNEL_NUMBER+1);
60 memset(dot11d_info->max_tx_pwr_dbm_list, 0xFF, MAX_CHANNEL_NUMBER+1);
62 NumTriples = (CoutryIeLen - 3) / 3; /* skip 3-byte country string. */
63 pTriple = (struct chnl_txpower_triple *)(pCoutryIe + 3);
64 for (i = 0; i < NumTriples; i++) {
65 if (MaxChnlNum >= pTriple->first_channel) {
66 /* It is not in a monotonically increasing order, so
69 netdev_err(dev->dev, "dot11d_update_country_ie(): Invalid country IE, skip it........1\n");
72 if (MAX_CHANNEL_NUMBER < (pTriple->first_channel + pTriple->num_channels)) {
73 /* It is not a valid set of channel id, so stop
76 netdev_err(dev->dev, "dot11d_update_country_ie(): Invalid country IE, skip it........2\n");
80 for (j = 0; j < pTriple->num_channels; j++) {
81 dot11d_info->channel_map[pTriple->first_channel + j] = 1;
82 dot11d_info->max_tx_pwr_dbm_list[pTriple->first_channel + j] = pTriple->max_tx_pwr_dbm;
83 MaxChnlNum = pTriple->first_channel + j;
86 pTriple = (struct chnl_txpower_triple *)((u8 *)pTriple + 3);
88 netdev_info(dev->dev, "Channel List:");
89 for (i = 1; i <= MAX_CHANNEL_NUMBER; i++)
90 if (dot11d_info->channel_map[i] > 0)
91 netdev_info(dev->dev, " %d", i);
92 netdev_info(dev->dev, "\n");
94 UPDATE_CIE_SRC(dev, pTaddr);
96 dot11d_info->country_ie_len = CoutryIeLen;
97 memcpy(dot11d_info->country_ie_buf, pCoutryIe, CoutryIeLen);
98 dot11d_info->state = DOT11D_STATE_LEARNED;
100 EXPORT_SYMBOL(dot11d_update_country_ie);
102 u8 dot11d_get_max_tx_pwr_in_dbm(struct ieee80211_device *dev, u8 Channel)
104 struct rt_dot11d_info *dot11d_info = GET_DOT11D_INFO(dev);
105 u8 MaxTxPwrInDbm = 255;
107 if (Channel > MAX_CHANNEL_NUMBER) {
108 netdev_err(dev->dev, "dot11d_get_max_tx_pwr_in_dbm(): Invalid Channel\n");
109 return MaxTxPwrInDbm;
111 if (dot11d_info->channel_map[Channel])
112 MaxTxPwrInDbm = dot11d_info->max_tx_pwr_dbm_list[Channel];
114 return MaxTxPwrInDbm;
116 EXPORT_SYMBOL(dot11d_get_max_tx_pwr_in_dbm);
118 void dot11d_scan_complete(struct ieee80211_device *dev)
120 struct rt_dot11d_info *dot11d_info = GET_DOT11D_INFO(dev);
122 switch (dot11d_info->state) {
123 case DOT11D_STATE_LEARNED:
124 dot11d_info->state = DOT11D_STATE_DONE;
127 case DOT11D_STATE_DONE:
128 if (GET_CIE_WATCHDOG(dev) == 0) {
129 /* Reset country IE if previous one is gone. */
133 case DOT11D_STATE_NONE:
137 EXPORT_SYMBOL(dot11d_scan_complete);
139 int is_legal_channel(struct ieee80211_device *dev, u8 channel)
141 struct rt_dot11d_info *dot11d_info = GET_DOT11D_INFO(dev);
143 if (channel > MAX_CHANNEL_NUMBER) {
144 netdev_err(dev->dev, "is_legal_channel(): Invalid Channel\n");
147 if (dot11d_info->channel_map[channel] > 0)
151 EXPORT_SYMBOL(is_legal_channel);
153 int to_legal_channel(struct ieee80211_device *dev, u8 channel)
155 struct rt_dot11d_info *dot11d_info = GET_DOT11D_INFO(dev);
159 for (i = 1; i <= MAX_CHANNEL_NUMBER; i++) {
160 if (dot11d_info->channel_map[i] > 0) {
166 if (channel > MAX_CHANNEL_NUMBER) {
167 netdev_err(dev->dev, "is_legal_channel(): Invalid Channel\n");
171 if (dot11d_info->channel_map[channel] > 0)
176 EXPORT_SYMBOL(to_legal_channel);