|
1 /* |
|
2 * Copyright (c) 2002-2009 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 "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: Implements interaction with WLMServer for Admission control purpose |
|
15 * |
|
16 */ |
|
17 |
|
18 /* |
|
19 * %version: 7 % |
|
20 */ |
|
21 |
|
22 #include "NifWLMServerIf.h" |
|
23 #include "WlanProto.h" |
|
24 #include "am_debug.h" |
|
25 |
|
26 // ============================ MEMBER FUNCTIONS =============================== |
|
27 |
|
28 // ----------------------------------------------------------------------------- |
|
29 // CLANNifWLMServerPerAC::NewL |
|
30 // ----------------------------------------------------------------------------- |
|
31 // |
|
32 CLANNifWLMServerPerAC* CLANNifWLMServerPerAC::NewL( |
|
33 TWlmAccessClass aAccessClass, |
|
34 TUint aInactivityTime, |
|
35 TBool aIsAutomaticMgmt ) |
|
36 { |
|
37 DEBUG( "CLANNifWLMServerPerAC::NewL()" ); |
|
38 CLANNifWLMServerPerAC* self = |
|
39 new (ELeave) CLANNifWLMServerPerAC( aAccessClass, aInactivityTime, aIsAutomaticMgmt ); |
|
40 |
|
41 CleanupStack::PushL( self ); |
|
42 self->ConstructL(); |
|
43 CleanupStack::Pop( self ); |
|
44 |
|
45 return self; |
|
46 } |
|
47 |
|
48 // ----------------------------------------------------------------------------- |
|
49 // CLANNifWLMServerPerAC::CLANNifWLMServerPerAC |
|
50 // ----------------------------------------------------------------------------- |
|
51 // |
|
52 CLANNifWLMServerPerAC::CLANNifWLMServerPerAC( |
|
53 TWlmAccessClass aAccessClass, |
|
54 TUint aInactivityTime, |
|
55 TBool aIsAutomaticMgmt ): |
|
56 CActive( CActive::EPriorityStandard ), |
|
57 iAccessClass( aAccessClass ), |
|
58 iTrafficMode( EWlmAcTrafficModeAutomatic ), |
|
59 iTrafficStatus( EWlmAcTrafficStatusAdmitted ), |
|
60 iContext( ETSCreateRequest ), |
|
61 iIsTsCreated( EFalse ), |
|
62 iTsId( 0 ), |
|
63 iTsParams( KACtoUP[iAccessClass] ), |
|
64 iTsStatus( EWlanTrafficStreamStatusActive ), |
|
65 iTsInactivityTime( aInactivityTime ), |
|
66 iTsDelOrigTime( 0 ), |
|
67 iTsDelRemainTime( 0 ), |
|
68 iTsDelStartTime( 0 ), |
|
69 iIsAutomaticMgmt( aIsAutomaticMgmt ) |
|
70 { |
|
71 DEBUG( "CLANNifWLMServerPerAC::CLANNifWLMServerPerAC()" ); |
|
72 |
|
73 CActiveScheduler::Add(this); |
|
74 } |
|
75 |
|
76 // ----------------------------------------------------------------------------- |
|
77 // CLANNifWLMServerPerAC::~CLANNifWLMServerPerAC |
|
78 // ----------------------------------------------------------------------------- |
|
79 // |
|
80 CLANNifWLMServerPerAC::~CLANNifWLMServerPerAC() |
|
81 { |
|
82 DEBUG( "CLANNifWLMServerPerAC::~CLANNifWLMServerPerAC()" ); |
|
83 |
|
84 Cancel(); |
|
85 iTsDelTimer.Close(); |
|
86 iWlmServer.Close(); |
|
87 } |
|
88 |
|
89 // ----------------------------------------------------------------------------- |
|
90 // CLANNifWLMServerPerAC::ConstructL |
|
91 // ----------------------------------------------------------------------------- |
|
92 // |
|
93 void CLANNifWLMServerPerAC::ConstructL() |
|
94 { |
|
95 DEBUG( "CLANNifWLMServerPerAC::ConstructL()" ); |
|
96 |
|
97 User::LeaveIfError( iWlmServer.Connect() ); |
|
98 User::LeaveIfError( iTsDelTimer.CreateLocal() ); |
|
99 } |
|
100 |
|
101 // ----------------------------------------------------------------------------- |
|
102 // CLANNifWLMServerPerAC::IsAdmitted |
|
103 // ----------------------------------------------------------------------------- |
|
104 // |
|
105 TBool CLANNifWLMServerPerAC::IsAdmitted() |
|
106 { |
|
107 return ( iTrafficStatus == EWlmAcTrafficStatusAdmitted ); |
|
108 } |
|
109 |
|
110 // ----------------------------------------------------------------------------- |
|
111 // CLANNifWLMServerPerAC::SetTrafficMode |
|
112 // ----------------------------------------------------------------------------- |
|
113 // |
|
114 void CLANNifWLMServerPerAC::SetTrafficMode( |
|
115 TWlmAcTrafficMode aMode ) |
|
116 { |
|
117 iTrafficMode = aMode; |
|
118 |
|
119 if( aMode == EWlmAcTrafficModeAutomatic ) |
|
120 { |
|
121 DEBUG1( "CLANNifWLMServerPerAC::SetTrafficMode() - traffic mode set to automatic for AC %u", |
|
122 iAccessClass ); |
|
123 } |
|
124 else if( aMode == EWlmAcTrafficModeManual ) |
|
125 { |
|
126 DEBUG1( "CLANNifWLMServerPerAC::SetTrafficMode() - traffic mode set to manual for AC %u", |
|
127 iAccessClass ); |
|
128 |
|
129 // If mode is changed from automatic to manual, it means NIF's |
|
130 // traffic streams for this AC have been deleted. |
|
131 |
|
132 Cancel(); |
|
133 iIsTsCreated = EFalse; |
|
134 } |
|
135 } |
|
136 |
|
137 // ----------------------------------------------------------------------------- |
|
138 // CLANNifWLMServerPerAC::SetTrafficStatus |
|
139 // ----------------------------------------------------------------------------- |
|
140 // |
|
141 void CLANNifWLMServerPerAC::SetTrafficStatus( |
|
142 TWlmAcTrafficStatus aStatus ) |
|
143 { |
|
144 iTrafficStatus = aStatus; |
|
145 |
|
146 if( aStatus == EWlmAcTrafficStatusAdmitted ) |
|
147 { |
|
148 DEBUG1( "CLANNifWLMServerPerAC::SetTrafficStatus() - traffic admitted on AC %u", |
|
149 iAccessClass ); |
|
150 } |
|
151 else if( aStatus == EWlmAcTrafficModeManual ) |
|
152 { |
|
153 DEBUG1( "CLANNifWLMServerPerAC::SetTrafficStatus() - traffic NOT admitted on AC %u", |
|
154 iAccessClass ); |
|
155 } |
|
156 } |
|
157 |
|
158 // ----------------------------------------------------------------------------- |
|
159 // CLANNifWLMServerPerAC::SuspendInactivityTimer |
|
160 // ----------------------------------------------------------------------------- |
|
161 // |
|
162 void CLANNifWLMServerPerAC::SuspendInactivityTimer() |
|
163 { |
|
164 if( !iIsTsCreated ) |
|
165 { |
|
166 DEBUG( "CLANNifWLMServerPerAC::SuspendInactivityTimer() - no traffic stream created, nothing to suspend" ); |
|
167 |
|
168 return; |
|
169 } |
|
170 |
|
171 if( !IsActive() ) |
|
172 { |
|
173 DEBUG( "CLANNifWLMServerPerAC::SuspendInactivityTimer() - timer is already suspended" ); |
|
174 |
|
175 return; |
|
176 } |
|
177 |
|
178 DEBUG1( "CLANNifWLMServerPerAC::SuspendInactivityTimer() - AC: %u", |
|
179 iAccessClass ); |
|
180 |
|
181 //First, cancel the running timer |
|
182 Cancel(); |
|
183 |
|
184 TTime time; |
|
185 time.UniversalTime(); |
|
186 TTimeIntervalMicroSeconds difference; |
|
187 difference = time.MicroSecondsFrom( iTsDelStartTime ); |
|
188 iTsDelRemainTime = iTsDelRemainTime.Int() - difference.Int64(); |
|
189 } |
|
190 |
|
191 // ----------------------------------------------------------------------------- |
|
192 // CLANNifWLMServerPerAC::ResumeInactivityTimer |
|
193 // ----------------------------------------------------------------------------- |
|
194 // |
|
195 void CLANNifWLMServerPerAC::ResumeInactivityTimer() |
|
196 { |
|
197 if( !iIsTsCreated ) |
|
198 { |
|
199 DEBUG( "CLANNifWLMServerPerAC::ResumeInactivityTimer() - no traffic stream created, nothing to resume" ); |
|
200 |
|
201 return; |
|
202 } |
|
203 |
|
204 if( IsActive() ) |
|
205 { |
|
206 DEBUG( "CLANNifWLMServerPerAC::ResumeInactivityTimer() - timer is already resumed" ); |
|
207 |
|
208 return; |
|
209 } |
|
210 |
|
211 DEBUG2( "CLANNifWLMServerPerAC::ResumeInactivityTimer() - AC: %u, remaining time(us): %u", |
|
212 iAccessClass, iTsDelRemainTime.Int() ); |
|
213 |
|
214 //Remember the time the timer is started |
|
215 iTsDelStartTime.UniversalTime(); |
|
216 iTsDelTimer.After(iStatus, iTsDelRemainTime); |
|
217 SetActive(); |
|
218 } |
|
219 |
|
220 // ----------------------------------------------------------------------------- |
|
221 // CLANNifWLMServerPerAC::OnFrameSend |
|
222 // ----------------------------------------------------------------------------- |
|
223 // |
|
224 void CLANNifWLMServerPerAC::OnFrameSend() |
|
225 { |
|
226 DEBUG6( "CLanLinkCommon::OnFrameSend() - iAccessClass: %u, iTrafficStatus: %u, iTrafficMode: %u, iIsTsCreated: %u, iIsAutomaticMgmt: %u, IsActive(): %u", |
|
227 iAccessClass, iTrafficStatus, iTrafficMode, iIsTsCreated, iIsAutomaticMgmt, IsActive() ); |
|
228 |
|
229 if( iIsAutomaticMgmt && |
|
230 iTrafficStatus == EWlmAcTrafficStatusNotAdmitted && |
|
231 iTrafficMode == EWlmAcTrafficModeAutomatic && |
|
232 !iIsTsCreated && |
|
233 !IsActive() ) |
|
234 { |
|
235 DEBUG1( "CLanLinkCommon::OnFrameSend() - requesting a virtual traffic stream for AC %u", |
|
236 iAccessClass ); |
|
237 |
|
238 iWlmServer.CreateTrafficStream( |
|
239 iStatus, |
|
240 iTsParams, |
|
241 ETrue, |
|
242 iTsId, |
|
243 iTsStatus ); |
|
244 iContext = ETSCreateRequest; |
|
245 SetActive(); |
|
246 } |
|
247 else if( iIsTsCreated ) |
|
248 { |
|
249 // Refresh the inactivity timer. |
|
250 |
|
251 Cancel(); |
|
252 iTsDelRemainTime = iTsDelOrigTime; |
|
253 iTsDelStartTime.UniversalTime(); |
|
254 iTsDelTimer.After( iStatus, iTsDelOrigTime ); |
|
255 SetActive(); |
|
256 } |
|
257 } |
|
258 |
|
259 // ----------------------------------------------------------------------------- |
|
260 // CLANNifWLMServerPerAC::OnFrameReceive |
|
261 // ----------------------------------------------------------------------------- |
|
262 // |
|
263 void CLANNifWLMServerPerAC::OnFrameReceive() |
|
264 { |
|
265 DEBUG6( "CLanLinkCommon::OnFrameReceive() - iAccessClass: %u, iTrafficStatus: %u, iTrafficMode: %u, iIsTsCreated: %u, iIsAutomaticMgmt: %u, IsActive(): %u", |
|
266 iAccessClass, iTrafficStatus, iTrafficMode, iIsTsCreated, iIsAutomaticMgmt, IsActive() ); |
|
267 |
|
268 if( iIsTsCreated && |
|
269 IsActive() ) |
|
270 { |
|
271 // Refresh the inactivity timer. |
|
272 |
|
273 Cancel(); |
|
274 iTsDelRemainTime = iTsDelOrigTime; |
|
275 iTsDelStartTime.UniversalTime(); |
|
276 iTsDelTimer.After( iStatus, iTsDelOrigTime ); |
|
277 SetActive(); |
|
278 } |
|
279 } |
|
280 |
|
281 // ----------------------------------------------------------------------------- |
|
282 // CLANNifWLMServerPerAC::RunL |
|
283 // ----------------------------------------------------------------------------- |
|
284 // |
|
285 void CLANNifWLMServerPerAC::RunL() |
|
286 { |
|
287 DEBUG1( "CLANNifWLMServerPerAC::RunL() - iStatus: %d", |
|
288 iStatus.Int() ); |
|
289 |
|
290 if( iContext == ETSCreateRequest ) |
|
291 { |
|
292 if( iStatus.Int() == KErrNone ) |
|
293 { |
|
294 DEBUG1("CLANNifWLMServerPerAC::RunL() - virtual traffic stream successfully created for AC %u", |
|
295 iAccessClass ); |
|
296 |
|
297 iIsTsCreated = ETrue; |
|
298 |
|
299 // Start the inactivity timer. |
|
300 iTsDelOrigTime = iTsDelRemainTime = iTsInactivityTime; |
|
301 iTsDelStartTime.UniversalTime(); |
|
302 iContext = ETSDelTimer; |
|
303 iTsDelTimer.After( iStatus, iTsDelOrigTime ); |
|
304 SetActive(); |
|
305 } |
|
306 else |
|
307 { |
|
308 DEBUG2("CLANNifWLMServerPerAC::RunL() - virtual traffic stream creation for AC %u failed with %d", |
|
309 iAccessClass, iStatus.Int() ); |
|
310 |
|
311 iIsTsCreated = EFalse; |
|
312 } |
|
313 } |
|
314 else if( iContext == ETSDelTimer ) |
|
315 { |
|
316 DEBUG1( "CLANNifWLMServerPerAC::RunL() - inactivity timer expired for AC %u, deleting the virtual traffic stream", |
|
317 iAccessClass ); |
|
318 |
|
319 iWlmServer.DeleteTrafficStream( iStatus, iTsId ); |
|
320 User::WaitForRequest( iStatus ); |
|
321 |
|
322 iIsTsCreated = EFalse; |
|
323 } |
|
324 } |
|
325 |
|
326 // --------------------------------------------------------------------------- |
|
327 // CLANNifWLMServerPerAC::RunError |
|
328 // --------------------------------------------------------------------------- |
|
329 // |
|
330 TInt CLANNifWLMServerPerAC::RunError( |
|
331 TInt /* aError */ ) |
|
332 { |
|
333 DEBUG( "CLANNifWLMServerPerAC::RunError()" ); |
|
334 |
|
335 return KErrNone; |
|
336 } |
|
337 |
|
338 // ----------------------------------------------------------------------------- |
|
339 // CLANNifWLMServerPerAC::DoCancel |
|
340 // ----------------------------------------------------------------------------- |
|
341 // |
|
342 void CLANNifWLMServerPerAC::DoCancel() |
|
343 { |
|
344 if( iContext == ETSCreateRequest ) |
|
345 { |
|
346 DEBUG1( "CLANNifWLMServerPerAC::DoCancel() - cancelling TS create request for AC %u", |
|
347 iAccessClass ); |
|
348 |
|
349 iWlmServer.CancelCreateTrafficStream(); |
|
350 } |
|
351 else |
|
352 { |
|
353 DEBUG1( "CLANNifWLMServerPerAC::DoCancel() - cancelling TS delete timer for AC %u", |
|
354 iAccessClass ); |
|
355 |
|
356 iTsDelTimer.Cancel(); |
|
357 } |
|
358 } |
|
359 |
|
360 // ============================ MEMBER FUNCTIONS =============================== |
|
361 |
|
362 // ----------------------------------------------------------------------------- |
|
363 // CLANNifWLMServerCommon::CLANNifWLMServerCommon |
|
364 // ----------------------------------------------------------------------------- |
|
365 // |
|
366 CLANNifWLMServerCommon::CLANNifWLMServerCommon( |
|
367 CLANLinkCommon* aLinkCommon ) : |
|
368 iLinkCommon( aLinkCommon ) |
|
369 { |
|
370 DEBUG( "CLANNifWLMServerCommon::CLANNifWLMServerCommon()" ); |
|
371 } |
|
372 |
|
373 // ----------------------------------------------------------------------------- |
|
374 // CLANNifWLMServerCommon::~CLANNifWLMServerCommon |
|
375 // ----------------------------------------------------------------------------- |
|
376 // |
|
377 CLANNifWLMServerCommon::~CLANNifWLMServerCommon() |
|
378 { |
|
379 DEBUG( "CLANNifWLMServerCommon::~CLANNifWLMServerCommon" ); |
|
380 |
|
381 iWlmServer.CancelNotifies(); |
|
382 iWlmServer.Close(); |
|
383 } |
|
384 |
|
385 // ----------------------------------------------------------------------------- |
|
386 // CLANNifWLMServerCommon::ConstructL |
|
387 // ----------------------------------------------------------------------------- |
|
388 // |
|
389 void CLANNifWLMServerCommon::ConstructL() |
|
390 { |
|
391 DEBUG( "CLANNifWLMServerCommon::ConstructL()" ); |
|
392 |
|
393 User::LeaveIfError( iWlmServer.Connect() ); |
|
394 iWlmServer.ActivateNotifiesL( |
|
395 *this, |
|
396 EWlmNotifyAcTrafficModeChanged | EWlmNotifyAcTrafficStatusChanged ); |
|
397 } |
|
398 |
|
399 // ----------------------------------------------------------------------------- |
|
400 // CLANNifWLMServerCommon::GetAcTrafficStatus |
|
401 // ----------------------------------------------------------------------------- |
|
402 // |
|
403 TInt CLANNifWLMServerCommon::GetAcTrafficStatus( |
|
404 TWlmAcTrafficStatusArray& aArray ) |
|
405 { |
|
406 DEBUG( "CLANNifWLMServerCommon::GetAcTrafficStatus()" ); |
|
407 |
|
408 return iWlmServer.GetAcTrafficStatus( aArray ); |
|
409 } |
|
410 |
|
411 // ----------------------------------------------------------------------------- |
|
412 // CLANNifWLMServerCommon::AccessClassTrafficModeChanged |
|
413 // ----------------------------------------------------------------------------- |
|
414 // |
|
415 void CLANNifWLMServerCommon::AccessClassTrafficModeChanged( |
|
416 TWlmAccessClass aAccessClass, |
|
417 TWlmAcTrafficMode aMode ) |
|
418 { |
|
419 DEBUG( "CLANNifWLMServerCommon::AccessClassTrafficModeChanged()" ); |
|
420 |
|
421 iLinkCommon->AcTrafficModeChanged( |
|
422 aAccessClass, aMode ); |
|
423 } |
|
424 |
|
425 // ----------------------------------------------------------------------------- |
|
426 // CLANNifWLMServerCommon::ConstructL |
|
427 // ----------------------------------------------------------------------------- |
|
428 // |
|
429 void CLANNifWLMServerCommon::AccessClassTrafficStatusChanged( |
|
430 TWlmAccessClass aAccessClass, |
|
431 TWlmAcTrafficStatus aStatus ) |
|
432 { |
|
433 DEBUG( "CLANNifWLMServerCommon::AccessClassTrafficStatusChanged()" ); |
|
434 |
|
435 iLinkCommon->AcTrafficStatusChanged( |
|
436 aAccessClass, aStatus ); |
|
437 } |