x86/PCI: use host bridge _CRS info on ASUS M2V-MX SE
[linux-btrfs-devel.git] / drivers / staging / rtl8192u / ieee80211 / dot11d.c
blobce63fc341c6ea4c3745d667d350303f9b830faf8
1 //-----------------------------------------------------------------------------
2 // File:
3 // Dot11d.c
4 //
5 // Description:
6 // Implement 802.11d.
7 //
8 //-----------------------------------------------------------------------------
10 #include "dot11d.h"
12 void
13 Dot11d_Init(struct ieee80211_device *ieee)
15 PRT_DOT11D_INFO pDot11dInfo = GET_DOT11D_INFO(ieee);
17 pDot11dInfo->bEnabled = 0;
19 pDot11dInfo->State = DOT11D_STATE_NONE;
20 pDot11dInfo->CountryIeLen = 0;
21 memset(pDot11dInfo->channel_map, 0, MAX_CHANNEL_NUMBER+1);
22 memset(pDot11dInfo->MaxTxPwrDbmList, 0xFF, MAX_CHANNEL_NUMBER+1);
23 RESET_CIE_WATCHDOG(ieee);
25 printk("Dot11d_Init()\n");
29 // Description:
30 // Reset to the state as we are just entering a regulatory domain.
32 void
33 Dot11d_Reset(struct ieee80211_device *ieee)
35 u32 i;
36 PRT_DOT11D_INFO pDot11dInfo = GET_DOT11D_INFO(ieee);
37 // Clear old channel map
38 memset(pDot11dInfo->channel_map, 0, MAX_CHANNEL_NUMBER+1);
39 memset(pDot11dInfo->MaxTxPwrDbmList, 0xFF, MAX_CHANNEL_NUMBER+1);
40 // Set new channel map
41 for (i=1; i<=11; i++) {
42 (pDot11dInfo->channel_map)[i] = 1;
44 for (i=12; i<=14; i++) {
45 (pDot11dInfo->channel_map)[i] = 2;
48 pDot11dInfo->State = DOT11D_STATE_NONE;
49 pDot11dInfo->CountryIeLen = 0;
50 RESET_CIE_WATCHDOG(ieee);
52 //printk("Dot11d_Reset()\n");
56 // Description:
57 // Update country IE from Beacon or Probe Resopnse
58 // and configure PHY for operation in the regulatory domain.
60 // TODO:
61 // Configure Tx power.
63 // Assumption:
64 // 1. IS_DOT11D_ENABLE() is TRUE.
65 // 2. Input IE is an valid one.
67 void
68 Dot11d_UpdateCountryIe(
69 struct ieee80211_device *dev,
70 u8 * pTaddr,
71 u16 CoutryIeLen,
72 u8 * pCoutryIe
75 PRT_DOT11D_INFO pDot11dInfo = GET_DOT11D_INFO(dev);
76 u8 i, j, NumTriples, MaxChnlNum;
77 PCHNL_TXPOWER_TRIPLE pTriple;
79 memset(pDot11dInfo->channel_map, 0, MAX_CHANNEL_NUMBER+1);
80 memset(pDot11dInfo->MaxTxPwrDbmList, 0xFF, MAX_CHANNEL_NUMBER+1);
81 MaxChnlNum = 0;
82 NumTriples = (CoutryIeLen - 3) / 3; // skip 3-byte country string.
83 pTriple = (PCHNL_TXPOWER_TRIPLE)(pCoutryIe + 3);
84 for(i = 0; i < NumTriples; i++)
86 if(MaxChnlNum >= pTriple->FirstChnl)
87 { // It is not in a monotonically increasing order, so stop processing.
88 printk("Dot11d_UpdateCountryIe(): Invalid country IE, skip it........1\n");
89 return;
91 if(MAX_CHANNEL_NUMBER < (pTriple->FirstChnl + pTriple->NumChnls))
92 { // It is not a valid set of channel id, so stop processing.
93 printk("Dot11d_UpdateCountryIe(): Invalid country IE, skip it........2\n");
94 return;
97 for(j = 0 ; j < pTriple->NumChnls; j++)
99 pDot11dInfo->channel_map[pTriple->FirstChnl + j] = 1;
100 pDot11dInfo->MaxTxPwrDbmList[pTriple->FirstChnl + j] = pTriple->MaxTxPowerInDbm;
101 MaxChnlNum = pTriple->FirstChnl + j;
104 pTriple = (PCHNL_TXPOWER_TRIPLE)((u8*)pTriple + 3);
106 //printk("Dot11d_UpdateCountryIe(): Channel List:\n");
107 printk("Channel List:");
108 for(i=1; i<= MAX_CHANNEL_NUMBER; i++)
109 if(pDot11dInfo->channel_map[i] > 0)
110 printk(" %d", i);
111 printk("\n");
113 UPDATE_CIE_SRC(dev, pTaddr);
115 pDot11dInfo->CountryIeLen = CoutryIeLen;
116 memcpy(pDot11dInfo->CountryIeBuf, pCoutryIe,CoutryIeLen);
117 pDot11dInfo->State = DOT11D_STATE_LEARNED;
122 DOT11D_GetMaxTxPwrInDbm(
123 struct ieee80211_device *dev,
124 u8 Channel
127 PRT_DOT11D_INFO pDot11dInfo = GET_DOT11D_INFO(dev);
128 u8 MaxTxPwrInDbm = 255;
130 if(MAX_CHANNEL_NUMBER < Channel)
132 printk("DOT11D_GetMaxTxPwrInDbm(): Invalid Channel\n");
133 return MaxTxPwrInDbm;
135 if(pDot11dInfo->channel_map[Channel])
137 MaxTxPwrInDbm = pDot11dInfo->MaxTxPwrDbmList[Channel];
140 return MaxTxPwrInDbm;
144 void
145 DOT11D_ScanComplete(
146 struct ieee80211_device * dev
149 PRT_DOT11D_INFO pDot11dInfo = GET_DOT11D_INFO(dev);
151 switch(pDot11dInfo->State)
153 case DOT11D_STATE_LEARNED:
154 pDot11dInfo->State = DOT11D_STATE_DONE;
155 break;
157 case DOT11D_STATE_DONE:
158 if( GET_CIE_WATCHDOG(dev) == 0 )
159 { // Reset country IE if previous one is gone.
160 Dot11d_Reset(dev);
162 break;
163 case DOT11D_STATE_NONE:
164 break;
168 int IsLegalChannel(
169 struct ieee80211_device * dev,
170 u8 channel
173 PRT_DOT11D_INFO pDot11dInfo = GET_DOT11D_INFO(dev);
175 if(MAX_CHANNEL_NUMBER < channel)
177 printk("IsLegalChannel(): Invalid Channel\n");
178 return 0;
180 if(pDot11dInfo->channel_map[channel] > 0)
181 return 1;
182 return 0;
185 int ToLegalChannel(
186 struct ieee80211_device * dev,
187 u8 channel
190 PRT_DOT11D_INFO pDot11dInfo = GET_DOT11D_INFO(dev);
191 u8 default_chn = 0;
192 u32 i = 0;
194 for (i=1; i<= MAX_CHANNEL_NUMBER; i++)
196 if(pDot11dInfo->channel_map[i] > 0)
198 default_chn = i;
199 break;
203 if(MAX_CHANNEL_NUMBER < channel)
205 printk("IsLegalChannel(): Invalid Channel\n");
206 return default_chn;
209 if(pDot11dInfo->channel_map[channel] > 0)
210 return channel;
212 return default_chn;
214 EXPORT_SYMBOL(Dot11d_Init);
215 EXPORT_SYMBOL(Dot11d_Reset);
216 EXPORT_SYMBOL(Dot11d_UpdateCountryIe);
217 EXPORT_SYMBOL(DOT11D_GetMaxTxPwrInDbm);
218 EXPORT_SYMBOL(DOT11D_ScanComplete);
219 EXPORT_SYMBOL(IsLegalChannel);
220 EXPORT_SYMBOL(ToLegalChannel);