|
1 /* |
|
2 * Copyright (c) 2005-2008 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Converter between WHA types and dot11 types. |
|
15 * |
|
16 */ |
|
17 |
|
18 /* |
|
19 * %version: 10 % |
|
20 */ |
|
21 |
|
22 #include "config.h" |
|
23 #include "umacwhatodot11typeconverter.h" |
|
24 #include "802dot11.h" |
|
25 #include "UmacContextImpl.h" |
|
26 |
|
27 struct TWhaRate2Dot11Rate |
|
28 { |
|
29 WHA::TRate iWhaRate; |
|
30 T802Dot11SupportedRate iDot11Rate; |
|
31 }; |
|
32 |
|
33 const TWhaRate2Dot11Rate KWhaRate2Dot11RateTable[] = |
|
34 { |
|
35 { WHA::KRate1Mbits, E802Dot11Rate1MBit }, |
|
36 { WHA::KRate2Mbits, E802Dot11Rate2MBit }, |
|
37 { WHA::KRate5_5Mbits, E802Dot11Rate5p5MBit }, |
|
38 { WHA::KRate6Mbits, E802Dot11Rate6MBit }, |
|
39 { WHA::KRate9Mbits, E802Dot11Rate9MBit }, |
|
40 { WHA::KRate11Mbits, E802Dot11Rate11MBit }, |
|
41 { WHA::KRate12Mbits, E802Dot11Rate12MBit }, |
|
42 { WHA::KRate18Mbits, E802Dot11Rate18MBit }, |
|
43 { WHA::KRate22Mbits, E802Dot11Rate22MBit }, |
|
44 { WHA::KRate24Mbits, E802Dot11Rate24MBit }, |
|
45 { WHA::KRate33Mbits, E802Dot11Rate33MBit }, |
|
46 { WHA::KRate36Mbits, E802Dot11Rate36MBit }, |
|
47 { WHA::KRate48Mbits, E802Dot11Rate48MBit }, |
|
48 { WHA::KRate54Mbits, E802Dot11Rate54MBit }, |
|
49 }; |
|
50 |
|
51 // ============================ MEMBER FUNCTIONS =============================== |
|
52 |
|
53 // ----------------------------------------------------------------------------- |
|
54 // |
|
55 // ----------------------------------------------------------------------------- |
|
56 // |
|
57 void WlanWhaToDot11TypeConverter::Convert( |
|
58 WHA::TRate aRateMask, |
|
59 SSupportedRatesIE& aRateIe, |
|
60 SExtendedSupportedRatesIE& aExtRateIe ) |
|
61 { |
|
62 aRateIe.Clear(); // make zero length |
|
63 aExtRateIe.Clear(); |
|
64 |
|
65 const TWhaRate2Dot11Rate* pos = KWhaRate2Dot11RateTable; |
|
66 const TWhaRate2Dot11Rate* end = |
|
67 pos + sizeof(KWhaRate2Dot11RateTable) / sizeof( TWhaRate2Dot11Rate); |
|
68 |
|
69 TUint32 cntr( 0 ); |
|
70 while ( pos != end ) |
|
71 { |
|
72 if ( aRateMask & pos->iWhaRate ) |
|
73 { |
|
74 // we have a hit |
|
75 if ( cntr < KMaxNumberOfRates ) |
|
76 { |
|
77 // space left in this IE |
|
78 aRateIe.Append( pos->iDot11Rate ); |
|
79 } |
|
80 else |
|
81 { |
|
82 // have to use the extended rates IE |
|
83 aExtRateIe.Append( pos->iDot11Rate ); |
|
84 } |
|
85 ++cntr; |
|
86 } |
|
87 else |
|
88 { |
|
89 // no hit |
|
90 } |
|
91 |
|
92 ++pos; |
|
93 } |
|
94 } |
|
95 |
|
96 // ----------------------------------------------------------------------------- |
|
97 // |
|
98 // ----------------------------------------------------------------------------- |
|
99 // |
|
100 TBool WlanWhaToDot11TypeConverter::ConvertToWhaTypes( |
|
101 WlanContextImpl& aCtxImpl, |
|
102 const TSSID* aSsid, |
|
103 WHA::SSSID& aWhaSsid, |
|
104 const SChannels* aChannels, |
|
105 TUint32 aMinChannelTime, |
|
106 TUint32 aMaxChannelTime, |
|
107 WHA::SChannels*& aWhaChannels, |
|
108 TUint8& aWhaChannelCount ) |
|
109 { |
|
110 const TUint32 endMask2dot4 = 0x00004000; |
|
111 const TUint32 endMask4dot9 = 0x00100000; |
|
112 |
|
113 TBool status ( ETrue ); |
|
114 |
|
115 // ========================================================================= |
|
116 // handle SSID |
|
117 // ========================================================================= |
|
118 |
|
119 aWhaSsid.iSSIDLength = aSsid->ssidLength; |
|
120 os_memcpy( aWhaSsid.iSSID, aSsid->ssid, aWhaSsid.iSSIDLength ); |
|
121 |
|
122 |
|
123 // ========================================================================= |
|
124 // handle channels & bands |
|
125 // Note that only one band is allowed to be specified at a time |
|
126 // ========================================================================= |
|
127 |
|
128 OsTracePrint( KScan, (TUint8*) |
|
129 ("UMAC: WlanWhaToDot11TypeConverter::ConvertToWhaTypes: frequency band mask: 0x%02x"), |
|
130 aChannels->iBand ); |
|
131 |
|
132 TUint32 channelMask ( 0 ); |
|
133 aWhaChannelCount = 0; |
|
134 |
|
135 if ( aChannels->iBand & WHA::KBand2dot4GHzMask ) |
|
136 { |
|
137 // channels in the 2.4GHz band |
|
138 // |
|
139 |
|
140 channelMask = aChannels->iChannels2dot4GHz[1]; // HI part |
|
141 channelMask <<= 8; |
|
142 channelMask |= aChannels->iChannels2dot4GHz[0]; // LO part |
|
143 |
|
144 // so how many channels have been specified to be scanned |
|
145 for ( TUint32 bit = 1; !(bit & endMask2dot4); bit <<= 1 ) |
|
146 { |
|
147 if ( channelMask & bit ) |
|
148 { |
|
149 ++aWhaChannelCount; |
|
150 } |
|
151 } |
|
152 } |
|
153 else if ( aChannels->iBand & WHA::KBand4dot9GHzMask ) |
|
154 { |
|
155 // channels in the 4.9GHz band |
|
156 // |
|
157 |
|
158 channelMask = aChannels->iChannels4dot9GHz[2]; |
|
159 channelMask <<= 8; |
|
160 channelMask |= aChannels->iChannels4dot9GHz[1]; |
|
161 channelMask <<= 8; |
|
162 channelMask |= aChannels->iChannels4dot9GHz[0]; |
|
163 |
|
164 // so how many channels have been specified to be scanned |
|
165 for ( TUint32 bit = 1; !(bit & endMask4dot9); bit <<= 1 ) |
|
166 { |
|
167 if ( channelMask & bit ) |
|
168 { |
|
169 ++aWhaChannelCount; |
|
170 } |
|
171 } |
|
172 } |
|
173 else |
|
174 { |
|
175 OsTracePrint( |
|
176 KErrorLevel, |
|
177 (TUint8*) |
|
178 ("UMAC: WlanWhaToDot11TypeConverter::ConvertToWhaTypes: ERROR: neither 2.4 nor 4.9 GHz band specified")); |
|
179 |
|
180 // implementation error |
|
181 OsAssert( (TUint8*)("UMAC: panic"), (TUint8*)(WLAN_FILE), __LINE__ ); |
|
182 } |
|
183 |
|
184 OsTracePrint( |
|
185 KScan, (TUint8*) |
|
186 ("UMAC: WlanWhaToDot11TypeConverter::ConvertToWhaTypes: channel bitmask: 0x%04x"), |
|
187 channelMask ); |
|
188 OsTracePrint( |
|
189 KScan, (TUint8*) |
|
190 ("UMAC: WlanWhaToDot11TypeConverter::ConvertToWhaTypes: %d channels specified to be scanned"), |
|
191 aWhaChannelCount ); |
|
192 |
|
193 if ( !aWhaChannelCount ) |
|
194 { |
|
195 // no channels specified to be scanned. That's an implementation error |
|
196 |
|
197 OsTracePrint( KErrorLevel, (TUint8*) |
|
198 ("UMAC: WlanWhaToDot11TypeConverter::ConvertToWhaTypes: ERROR: no channels specified to be scanned") ); |
|
199 OsAssert( (TUint8*)("UMAC: panic"), (TUint8*)(WLAN_FILE), __LINE__ ); |
|
200 } |
|
201 |
|
202 // allocate memory for the channels |
|
203 aWhaChannels = |
|
204 static_cast<WHA::SChannels*>(os_alloc( |
|
205 sizeof( WHA::SChannels ) * aWhaChannelCount )); |
|
206 WHA::SChannels* ptr = aWhaChannels; |
|
207 |
|
208 if ( !aWhaChannels ) |
|
209 { |
|
210 // alloc failed; we can't continue |
|
211 status = EFalse; |
|
212 } |
|
213 else // alloc success, continue |
|
214 { |
|
215 // convert to WHA channels |
|
216 // |
|
217 |
|
218 WHA::TChannelNumber channelNumber( 1 ); |
|
219 |
|
220 if ( aChannels->iBand & WHA::KBand2dot4GHzMask ) |
|
221 { |
|
222 for ( TUint32 bit = 1; !(bit & endMask2dot4); bit <<= 1 ) |
|
223 { |
|
224 if ( channelMask & bit ) |
|
225 { |
|
226 ptr->iChannel = channelNumber; |
|
227 ptr->iMinChannelTime = aMinChannelTime; |
|
228 ptr->iMaxChannelTime = aMaxChannelTime; |
|
229 ptr->iTxPowerLevel = aCtxImpl.iWlanMib.dot11CurrentTxPowerLevel; |
|
230 ++ptr; |
|
231 } |
|
232 ++channelNumber; |
|
233 } |
|
234 } |
|
235 else if ( aChannels->iBand & WHA::KBand4dot9GHzMask ) |
|
236 { |
|
237 for ( TUint32 bit = 1; !(bit & endMask4dot9); bit <<= 1 ) |
|
238 { |
|
239 if ( channelMask & bit ) |
|
240 { |
|
241 ptr->iChannel = channelNumber; |
|
242 ptr->iMinChannelTime = aMinChannelTime; |
|
243 ptr->iMaxChannelTime = aMaxChannelTime; |
|
244 ptr->iTxPowerLevel = aCtxImpl.iWlanMib.dot11CurrentTxPowerLevel; |
|
245 ++ptr; |
|
246 } |
|
247 ++channelNumber; |
|
248 } |
|
249 } |
|
250 |
|
251 #ifndef NDEBUG |
|
252 // trace WHA channels |
|
253 ptr = aWhaChannels; |
|
254 OsTracePrint( |
|
255 KScan, |
|
256 (TUint8*) |
|
257 ("UMAC: WlanWhaToDot11TypeConverter::ConvertToWhaTypes: dump channels")); |
|
258 |
|
259 for ( TUint8 index = 0; index < aWhaChannelCount; ++index ) |
|
260 { |
|
261 OsTracePrint( |
|
262 KScan, (TUint8*) |
|
263 ("UMAC: WlanWhaToDot11TypeConverter::ConvertToWhaTypes: channelNumber: %d "), |
|
264 ptr->iChannel ); |
|
265 ++ptr; |
|
266 } |
|
267 #endif |
|
268 } // else (alloc success) |
|
269 |
|
270 return status; |
|
271 } |