First Support on Ginger and OMAP TI
[linux-ginger.git] / drivers / staging / rtl8192su / ieee80211 / dot11d.c
blob22484621478084a6386ca6646f3502d0706f247f
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);
38 // Clear old channel map
39 memset(pDot11dInfo->channel_map, 0, MAX_CHANNEL_NUMBER+1);
40 memset(pDot11dInfo->MaxTxPwrDbmList, 0xFF, MAX_CHANNEL_NUMBER+1);
41 // Set new channel map
42 for (i=1; i<=11; i++) {
43 (pDot11dInfo->channel_map)[i] = 1;
45 for (i=12; i<=14; i++) {
46 (pDot11dInfo->channel_map)[i] = 2;
49 pDot11dInfo->State = DOT11D_STATE_NONE;
50 pDot11dInfo->CountryIeLen = 0;
51 RESET_CIE_WATCHDOG(ieee);
53 //printk("Dot11d_Reset()\n");
57 // Description:
58 // Update country IE from Beacon or Probe Resopnse
59 // and configure PHY for operation in the regulatory domain.
61 // TODO:
62 // Configure Tx power.
64 // Assumption:
65 // 1. IS_DOT11D_ENABLE() is TRUE.
66 // 2. Input IE is an valid one.
68 void
69 Dot11d_UpdateCountryIe(
70 struct ieee80211_device *dev,
71 u8 * pTaddr,
72 u16 CoutryIeLen,
73 u8 * pCoutryIe
76 PRT_DOT11D_INFO pDot11dInfo = GET_DOT11D_INFO(dev);
77 u8 i, j, NumTriples, MaxChnlNum;
78 PCHNL_TXPOWER_TRIPLE pTriple;
80 memset(pDot11dInfo->channel_map, 0, MAX_CHANNEL_NUMBER+1);
81 memset(pDot11dInfo->MaxTxPwrDbmList, 0xFF, MAX_CHANNEL_NUMBER+1);
82 MaxChnlNum = 0;
83 NumTriples = (CoutryIeLen - 3) / 3; // skip 3-byte country string.
84 pTriple = (PCHNL_TXPOWER_TRIPLE)(pCoutryIe + 3);
85 for(i = 0; i < NumTriples; i++)
87 if(MaxChnlNum >= pTriple->FirstChnl)
88 { // It is not in a monotonically increasing order, so stop processing.
89 printk("Dot11d_UpdateCountryIe(): Invalid country IE, skip it........1\n");
90 return;
92 if(MAX_CHANNEL_NUMBER < (pTriple->FirstChnl + pTriple->NumChnls))
93 { // It is not a valid set of channel id, so stop processing.
94 printk("Dot11d_UpdateCountryIe(): Invalid country IE, skip it........2\n");
95 return;
98 for(j = 0 ; j < pTriple->NumChnls; j++)
100 pDot11dInfo->channel_map[pTriple->FirstChnl + j] = 1;
101 pDot11dInfo->MaxTxPwrDbmList[pTriple->FirstChnl + j] = pTriple->MaxTxPowerInDbm;
102 MaxChnlNum = pTriple->FirstChnl + j;
105 pTriple = (PCHNL_TXPOWER_TRIPLE)((u8*)pTriple + 3);
107 #if 1
108 //printk("Dot11d_UpdateCountryIe(): Channel List:\n");
109 printk("Channel List:");
110 for(i=1; i<= MAX_CHANNEL_NUMBER; i++)
111 if(pDot11dInfo->channel_map[i] > 0)
112 printk(" %d", i);
113 printk("\n");
114 #endif
116 UPDATE_CIE_SRC(dev, pTaddr);
118 pDot11dInfo->CountryIeLen = CoutryIeLen;
119 memcpy(pDot11dInfo->CountryIeBuf, pCoutryIe,CoutryIeLen);
120 pDot11dInfo->State = DOT11D_STATE_LEARNED;
125 DOT11D_GetMaxTxPwrInDbm(
126 struct ieee80211_device *dev,
127 u8 Channel
130 PRT_DOT11D_INFO pDot11dInfo = GET_DOT11D_INFO(dev);
131 u8 MaxTxPwrInDbm = 255;
133 if(MAX_CHANNEL_NUMBER < Channel)
135 printk("DOT11D_GetMaxTxPwrInDbm(): Invalid Channel\n");
136 return MaxTxPwrInDbm;
138 if(pDot11dInfo->channel_map[Channel])
140 MaxTxPwrInDbm = pDot11dInfo->MaxTxPwrDbmList[Channel];
143 return MaxTxPwrInDbm;
147 void
148 DOT11D_ScanComplete(
149 struct ieee80211_device * dev
152 PRT_DOT11D_INFO pDot11dInfo = GET_DOT11D_INFO(dev);
154 switch(pDot11dInfo->State)
156 case DOT11D_STATE_LEARNED:
157 pDot11dInfo->State = DOT11D_STATE_DONE;
158 break;
160 case DOT11D_STATE_DONE:
161 if( GET_CIE_WATCHDOG(dev) == 0 )
162 { // Reset country IE if previous one is gone.
163 Dot11d_Reset(dev);
165 break;
166 case DOT11D_STATE_NONE:
167 break;
171 int IsLegalChannel(
172 struct ieee80211_device * dev,
173 u8 channel
176 PRT_DOT11D_INFO pDot11dInfo = GET_DOT11D_INFO(dev);
178 if(MAX_CHANNEL_NUMBER < channel)
180 printk("IsLegalChannel(): Invalid Channel\n");
181 return 0;
183 if(pDot11dInfo->channel_map[channel] > 0)
184 return 1;
185 return 0;
188 int ToLegalChannel(
189 struct ieee80211_device * dev,
190 u8 channel
193 PRT_DOT11D_INFO pDot11dInfo = GET_DOT11D_INFO(dev);
194 u8 default_chn = 0;
195 u32 i = 0;
197 for (i=1; i<= MAX_CHANNEL_NUMBER; i++)
199 if(pDot11dInfo->channel_map[i] > 0)
201 default_chn = i;
202 break;
206 if(MAX_CHANNEL_NUMBER < channel)
208 printk("IsLegalChannel(): Invalid Channel\n");
209 return default_chn;
212 if(pDot11dInfo->channel_map[channel] > 0)
213 return channel;
215 return default_chn;