added 2.6.29.6 aldebaran kernel
[nao-ulib.git] / kernel / 2.6.29.6-aldebaran-rt / drivers / staging / rtl8187se / ieee80211 / dot11d.c
blob5d8b752fc0fb98744b48b7cd596ef7aefa9a903f
1 #ifdef ENABLE_DOT11D
2 //-----------------------------------------------------------------------------
3 // File:
4 // Dot11d.c
5 //
6 // Description:
7 // Implement 802.11d.
8 //
9 //-----------------------------------------------------------------------------
11 #include "dot11d.h"
13 void
14 Dot11d_Init(struct ieee80211_device *ieee)
16 PRT_DOT11D_INFO pDot11dInfo = GET_DOT11D_INFO(ieee);
18 pDot11dInfo->bEnabled = 0;
20 pDot11dInfo->State = DOT11D_STATE_NONE;
21 pDot11dInfo->CountryIeLen = 0;
22 memset(pDot11dInfo->channel_map, 0, MAX_CHANNEL_NUMBER+1);
23 memset(pDot11dInfo->MaxTxPwrDbmList, 0xFF, MAX_CHANNEL_NUMBER+1);
24 RESET_CIE_WATCHDOG(ieee);
26 printk("Dot11d_Init()\n");
30 // Description:
31 // Reset to the state as we are just entering a regulatory domain.
33 void
34 Dot11d_Reset(struct ieee80211_device *ieee)
36 u32 i;
37 PRT_DOT11D_INFO pDot11dInfo = GET_DOT11D_INFO(ieee);
39 // Clear old channel map
40 memset(pDot11dInfo->channel_map, 0, MAX_CHANNEL_NUMBER+1);
41 memset(pDot11dInfo->MaxTxPwrDbmList, 0xFF, MAX_CHANNEL_NUMBER+1);
42 // Set new channel map
43 for (i=1; i<=11; i++) {
44 (pDot11dInfo->channel_map)[i] = 1;
46 for (i=12; i<=14; i++) {
47 (pDot11dInfo->channel_map)[i] = 2;
50 pDot11dInfo->State = DOT11D_STATE_NONE;
51 pDot11dInfo->CountryIeLen = 0;
52 RESET_CIE_WATCHDOG(ieee);
54 //printk("Dot11d_Reset()\n");
58 // Description:
59 // Update country IE from Beacon or Probe Resopnse
60 // and configure PHY for operation in the regulatory domain.
62 // TODO:
63 // Configure Tx power.
65 // Assumption:
66 // 1. IS_DOT11D_ENABLE() is TRUE.
67 // 2. Input IE is an valid one.
69 void
70 Dot11d_UpdateCountryIe(
71 struct ieee80211_device *dev,
72 u8 * pTaddr,
73 u16 CoutryIeLen,
74 u8 * pCoutryIe
77 PRT_DOT11D_INFO pDot11dInfo = GET_DOT11D_INFO(dev);
78 u8 i, j, NumTriples, MaxChnlNum;
79 PCHNL_TXPOWER_TRIPLE pTriple;
81 if((CoutryIeLen - 3)%3 != 0)
83 printk("Dot11d_UpdateCountryIe(): Invalid country IE, skip it........1\n");
84 Dot11d_Reset(dev);
85 return;
88 memset(pDot11dInfo->channel_map, 0, MAX_CHANNEL_NUMBER+1);
89 memset(pDot11dInfo->MaxTxPwrDbmList, 0xFF, MAX_CHANNEL_NUMBER+1);
90 MaxChnlNum = 0;
91 NumTriples = (CoutryIeLen - 3) / 3; // skip 3-byte country string.
92 pTriple = (PCHNL_TXPOWER_TRIPLE)(pCoutryIe + 3);
93 for(i = 0; i < NumTriples; i++)
95 if(MaxChnlNum >= pTriple->FirstChnl)
96 { // It is not in a monotonically increasing order, so stop processing.
97 printk("Dot11d_UpdateCountryIe(): Invalid country IE, skip it........1\n");
98 Dot11d_Reset(dev);
99 return;
101 if(MAX_CHANNEL_NUMBER < (pTriple->FirstChnl + pTriple->NumChnls))
102 { // It is not a valid set of channel id, so stop processing.
103 printk("Dot11d_UpdateCountryIe(): Invalid country IE, skip it........2\n");
104 Dot11d_Reset(dev);
105 return;
108 for(j = 0 ; j < pTriple->NumChnls; j++)
110 pDot11dInfo->channel_map[pTriple->FirstChnl + j] = 1;
111 pDot11dInfo->MaxTxPwrDbmList[pTriple->FirstChnl + j] = pTriple->MaxTxPowerInDbm;
112 MaxChnlNum = pTriple->FirstChnl + j;
115 pTriple = (PCHNL_TXPOWER_TRIPLE)((u8*)pTriple + 3);
117 #if 1
118 //printk("Dot11d_UpdateCountryIe(): Channel List:\n");
119 printk("Channel List:");
120 for(i=1; i<= MAX_CHANNEL_NUMBER; i++)
121 if(pDot11dInfo->channel_map[i] > 0)
122 printk(" %d", i);
123 printk("\n");
124 #endif
126 UPDATE_CIE_SRC(dev, pTaddr);
128 pDot11dInfo->CountryIeLen = CoutryIeLen;
129 memcpy(pDot11dInfo->CountryIeBuf, pCoutryIe,CoutryIeLen);
130 pDot11dInfo->State = DOT11D_STATE_LEARNED;
133 void dump_chnl_map(u8 * channel_map)
135 int i;
136 printk("Channel List:");
137 for(i=1; i<= MAX_CHANNEL_NUMBER; i++)
138 if(channel_map[i] > 0)
139 printk(" %d(%d)", i, channel_map[i]);
140 printk("\n");
144 DOT11D_GetMaxTxPwrInDbm(
145 struct ieee80211_device *dev,
146 u8 Channel
149 PRT_DOT11D_INFO pDot11dInfo = GET_DOT11D_INFO(dev);
150 u8 MaxTxPwrInDbm = 255;
152 if(MAX_CHANNEL_NUMBER < Channel)
154 printk("DOT11D_GetMaxTxPwrInDbm(): Invalid Channel\n");
155 return MaxTxPwrInDbm;
157 if(pDot11dInfo->channel_map[Channel])
159 MaxTxPwrInDbm = pDot11dInfo->MaxTxPwrDbmList[Channel];
162 return MaxTxPwrInDbm;
166 void
167 DOT11D_ScanComplete(
168 struct ieee80211_device * dev
171 PRT_DOT11D_INFO pDot11dInfo = GET_DOT11D_INFO(dev);
173 switch(pDot11dInfo->State)
175 case DOT11D_STATE_LEARNED:
176 pDot11dInfo->State = DOT11D_STATE_DONE;
177 break;
179 case DOT11D_STATE_DONE:
180 if( GET_CIE_WATCHDOG(dev) == 0 )
181 { // Reset country IE if previous one is gone.
182 Dot11d_Reset(dev);
184 break;
185 case DOT11D_STATE_NONE:
186 break;
190 int IsLegalChannel(
191 struct ieee80211_device * dev,
192 u8 channel
195 PRT_DOT11D_INFO pDot11dInfo = GET_DOT11D_INFO(dev);
197 if(MAX_CHANNEL_NUMBER < channel)
199 printk("IsLegalChannel(): Invalid Channel\n");
200 return 0;
202 if(pDot11dInfo->channel_map[channel] > 0)
203 return 1;
204 return 0;
207 int ToLegalChannel(
208 struct ieee80211_device * dev,
209 u8 channel
212 PRT_DOT11D_INFO pDot11dInfo = GET_DOT11D_INFO(dev);
213 u8 default_chn = 0;
214 u32 i = 0;
216 for (i=1; i<= MAX_CHANNEL_NUMBER; i++)
218 if(pDot11dInfo->channel_map[i] > 0)
220 default_chn = i;
221 break;
225 if(MAX_CHANNEL_NUMBER < channel)
227 printk("IsLegalChannel(): Invalid Channel\n");
228 return default_chn;
231 if(pDot11dInfo->channel_map[channel] > 0)
232 return channel;
234 return default_chn;
237 #if 0
238 EXPORT_SYMBOL(Dot11d_Init);
239 EXPORT_SYMBOL(Dot11d_Reset);
240 EXPORT_SYMBOL(Dot11d_UpdateCountryIe);
241 EXPORT_SYMBOL(DOT11D_GetMaxTxPwrInDbm);
242 EXPORT_SYMBOL(DOT11D_ScanComplete);
243 EXPORT_SYMBOL(IsLegalChannel);
244 EXPORT_SYMBOL(ToLegalChannel);
245 #endif
246 #endif