]> git.karo-electronics.de Git - mv-sheeva.git/blob - drivers/staging/rtl8192su/ieee80211/dot11d.c
6275cc75ec8572553b160279bc6a6870cd07c718
[mv-sheeva.git] / drivers / staging / rtl8192su / ieee80211 / dot11d.c
1 /******************************************************************************
2  * Copyright(c) 2008 - 2010 Realtek Corporation. All rights reserved.
3  *
4  * This program is distributed in the hope that it will be useful, but WITHOUT
5  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
6  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
7  * more details.
8  *
9  * You should have received a copy of the GNU General Public License along with
10  * this program; if not, write to the Free Software Foundation, Inc.,
11  * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
12  *
13  * The full GNU General Public License is included in this distribution in the
14  * file called LICENSE.
15  *
16  * Contact Information:
17  * wlanfae <wlanfae@realtek.com>
18 ******************************************************************************/
19
20 #include "dot11d.h"
21
22 void
23 Dot11d_Init(struct ieee80211_device *ieee)
24 {
25         PRT_DOT11D_INFO pDot11dInfo = GET_DOT11D_INFO(ieee);
26
27         pDot11dInfo->bEnabled = 0;
28
29         pDot11dInfo->State = DOT11D_STATE_NONE;
30         pDot11dInfo->CountryIeLen = 0;
31         memset(pDot11dInfo->channel_map, 0, MAX_CHANNEL_NUMBER+1);
32         memset(pDot11dInfo->MaxTxPwrDbmList, 0xFF, MAX_CHANNEL_NUMBER+1);
33         RESET_CIE_WATCHDOG(ieee);
34
35         printk("Dot11d_Init()\n");
36 }
37
38 //
39 //      Description:
40 //              Reset to the state as we are just entering a regulatory domain.
41 //
42 void
43 Dot11d_Reset(struct ieee80211_device *ieee)
44 {
45         u32 i;
46         PRT_DOT11D_INFO pDot11dInfo = GET_DOT11D_INFO(ieee);
47
48         // Clear old channel map
49         memset(pDot11dInfo->channel_map, 0, MAX_CHANNEL_NUMBER+1);
50         memset(pDot11dInfo->MaxTxPwrDbmList, 0xFF, MAX_CHANNEL_NUMBER+1);
51         // Set new channel map
52         for (i=1; i<=11; i++) {
53                 (pDot11dInfo->channel_map)[i] = 1;
54         }
55         for (i=12; i<=14; i++) {
56                 (pDot11dInfo->channel_map)[i] = 2;
57         }
58
59         pDot11dInfo->State = DOT11D_STATE_NONE;
60         pDot11dInfo->CountryIeLen = 0;
61         RESET_CIE_WATCHDOG(ieee);
62
63 }
64
65 //
66 //      Description:
67 //              Update country IE from Beacon or Probe Resopnse
68 //              and configure PHY for operation in the regulatory domain.
69 //
70 //      TODO:
71 //              Configure Tx power.
72 //
73 //      Assumption:
74 //              1. IS_DOT11D_ENABLE() is TRUE.
75 //              2. Input IE is an valid one.
76 //
77 void
78 Dot11d_UpdateCountryIe(
79         struct ieee80211_device *dev,
80         u8 *            pTaddr,
81         u16     CoutryIeLen,
82         u8 * pCoutryIe
83         )
84 {
85         PRT_DOT11D_INFO pDot11dInfo = GET_DOT11D_INFO(dev);
86         u8 i, j, NumTriples, MaxChnlNum;
87         PCHNL_TXPOWER_TRIPLE pTriple;
88
89         memset(pDot11dInfo->channel_map, 0, MAX_CHANNEL_NUMBER+1);
90         memset(pDot11dInfo->MaxTxPwrDbmList, 0xFF, MAX_CHANNEL_NUMBER+1);
91         MaxChnlNum = 0;
92         NumTriples = (CoutryIeLen - 3) / 3; // skip 3-byte country string.
93         pTriple = (PCHNL_TXPOWER_TRIPLE)(pCoutryIe + 3);
94         for(i = 0; i < NumTriples; i++)
95         {
96                 if(MaxChnlNum >= pTriple->FirstChnl)
97                 { // It is not in a monotonically increasing order, so stop processing.
98                         printk("Dot11d_UpdateCountryIe(): Invalid country IE, skip it........1\n");
99                         return;
100                 }
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                         return;
105                 }
106
107                 for(j = 0 ; j < pTriple->NumChnls; j++)
108                 {
109                         pDot11dInfo->channel_map[pTriple->FirstChnl + j] = 1;
110                         pDot11dInfo->MaxTxPwrDbmList[pTriple->FirstChnl + j] = pTriple->MaxTxPowerInDbm;
111                         MaxChnlNum = pTriple->FirstChnl + j;
112                 }
113
114                 pTriple = (PCHNL_TXPOWER_TRIPLE)((u8*)pTriple + 3);
115         }
116 #if 1
117         printk("Channel List:");
118         for(i=1; i<= MAX_CHANNEL_NUMBER; i++)
119                 if(pDot11dInfo->channel_map[i] > 0)
120                         printk(" %d", i);
121         printk("\n");
122 #endif
123
124         UPDATE_CIE_SRC(dev, pTaddr);
125
126         pDot11dInfo->CountryIeLen = CoutryIeLen;
127         memcpy(pDot11dInfo->CountryIeBuf, pCoutryIe,CoutryIeLen);
128         pDot11dInfo->State = DOT11D_STATE_LEARNED;
129 }
130
131
132 u8
133 DOT11D_GetMaxTxPwrInDbm(
134         struct ieee80211_device *dev,
135         u8 Channel
136         )
137 {
138         PRT_DOT11D_INFO pDot11dInfo = GET_DOT11D_INFO(dev);
139         u8 MaxTxPwrInDbm = 255;
140
141         if(MAX_CHANNEL_NUMBER < Channel)
142         {
143                 printk("DOT11D_GetMaxTxPwrInDbm(): Invalid Channel\n");
144                 return MaxTxPwrInDbm;
145         }
146         if(pDot11dInfo->channel_map[Channel])
147         {
148                 MaxTxPwrInDbm = pDot11dInfo->MaxTxPwrDbmList[Channel];
149         }
150
151         return MaxTxPwrInDbm;
152 }
153
154
155 void
156 DOT11D_ScanComplete(
157         struct ieee80211_device * dev
158         )
159 {
160         PRT_DOT11D_INFO pDot11dInfo = GET_DOT11D_INFO(dev);
161
162         switch(pDot11dInfo->State)
163         {
164         case DOT11D_STATE_LEARNED:
165                 pDot11dInfo->State = DOT11D_STATE_DONE;
166                 break;
167
168         case DOT11D_STATE_DONE:
169                 if( GET_CIE_WATCHDOG(dev) == 0 )
170                 { // Reset country IE if previous one is gone.
171                         Dot11d_Reset(dev);
172                 }
173                 break;
174         case DOT11D_STATE_NONE:
175                 break;
176         }
177 }
178
179 int IsLegalChannel(
180         struct ieee80211_device * dev,
181         u8 channel
182 )
183 {
184         PRT_DOT11D_INFO pDot11dInfo = GET_DOT11D_INFO(dev);
185
186         if(MAX_CHANNEL_NUMBER < channel)
187         {
188                 printk("IsLegalChannel(): Invalid Channel\n");
189                 return 0;
190         }
191         if(pDot11dInfo->channel_map[channel] > 0)
192                 return 1;
193         return 0;
194 }
195
196 int ToLegalChannel(
197         struct ieee80211_device * dev,
198         u8 channel
199 )
200 {
201         PRT_DOT11D_INFO pDot11dInfo = GET_DOT11D_INFO(dev);
202         u8 default_chn = 0;
203         u32 i = 0;
204
205         for (i=1; i<= MAX_CHANNEL_NUMBER; i++)
206         {
207                 if(pDot11dInfo->channel_map[i] > 0)
208                 {
209                         default_chn = i;
210                         break;
211                 }
212         }
213
214         if(MAX_CHANNEL_NUMBER < channel)
215         {
216                 printk("IsLegalChannel(): Invalid Channel\n");
217                 return default_chn;
218         }
219
220         if(pDot11dInfo->channel_map[channel] > 0)
221                 return channel;
222
223         return default_chn;
224 }