|
1 /* |
|
2 * Copyright (c) 2005-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 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: Implementation of the WlanDot11AssociationPending class |
|
15 * |
|
16 */ |
|
17 |
|
18 /* |
|
19 * %version: 45 % |
|
20 */ |
|
21 |
|
22 #include "config.h" |
|
23 #include "UmacDot11AssociationPending.h" |
|
24 #include "UmacContextImpl.h" |
|
25 #include "umacelementlocator.h" |
|
26 #include "umacwhaconfigureac.h" |
|
27 #include "802dot11DefaultValues.h" |
|
28 |
|
29 #ifndef NDEBUG |
|
30 const TInt8 WlanDot11AssociationPending::iName[] = "dot11-associationpending"; |
|
31 |
|
32 const TUint8 WlanDot11AssociationPending::iStateName |
|
33 [ESTATEMAX][KMaxStateStringLength] = |
|
34 { |
|
35 {"EINIT"}, |
|
36 {"ETXASSOCREQFRAME"}, |
|
37 {"EWAIT4ASSOCRESPONSE"}, |
|
38 {"ECONFIGUREAC"}, |
|
39 {"EWAIT4PUSHPACKET"}, |
|
40 {"ECONTINUEDOT11TRAVERSE"} |
|
41 }; |
|
42 |
|
43 const TUint8 WlanDot11AssociationPending::iEventName |
|
44 [EEVENTMAX][KMaxEventStringLength] = |
|
45 { |
|
46 {"ESTATEENTRY"}, |
|
47 {"ERXASSOCRESPONSE"}, |
|
48 {"ETX_ASSOCFRAME_XFER"}, |
|
49 {"ETXCOMPLETE"}, |
|
50 {"ETIMEOUT"}, |
|
51 {"ETX_SCHEDULER_FULL"}, |
|
52 {"EPUSHPACKET"} |
|
53 }; |
|
54 #endif |
|
55 |
|
56 // ================= MEMBER FUNCTIONS ======================= |
|
57 |
|
58 // ----------------------------------------------------------------------------- |
|
59 // ----------------------------------------------------------------------------- |
|
60 // |
|
61 void WlanDot11AssociationPending::Entry( |
|
62 WlanContextImpl& aCtxImpl ) |
|
63 { |
|
64 OsTracePrint( KUmacProtocolState | KUmacAssoc, |
|
65 (TUint8*)("UMAC: WlanDot11AssociationPending::Entry()")); |
|
66 |
|
67 if ( aCtxImpl.WsaCmdActive() ) |
|
68 { |
|
69 // sanity checking code |
|
70 OsAssert( (TUint8*)("UMAC: panic"), (TUint8*)(WLAN_FILE), __LINE__ ); |
|
71 } |
|
72 |
|
73 // no need to do event dispatching as this |
|
74 // thing is triggered by the user and |
|
75 // is executed synchronously as we only do OID completion |
|
76 // at the end of authenticate + association process |
|
77 |
|
78 if ( iState == EINIT ) |
|
79 { |
|
80 // this is the start of the the FSM actions |
|
81 Fsm( aCtxImpl, ESTATEENTRY ); |
|
82 } |
|
83 else |
|
84 { |
|
85 // this is NOT the start of the the FSM actions |
|
86 // note that we send the ETXCOMPLETE event as the states |
|
87 // that wait for it are the only ones that can be interrupted |
|
88 // as they are asynchronous operations by nature |
|
89 // and wait for corresponding WHA completion method |
|
90 Fsm( aCtxImpl, ETXCOMPLETE ); |
|
91 } |
|
92 } |
|
93 |
|
94 // ----------------------------------------------------------------------------- |
|
95 // |
|
96 // ----------------------------------------------------------------------------- |
|
97 // |
|
98 void WlanDot11AssociationPending::Exit( |
|
99 WlanContextImpl& /*aCtxImpl*/ ) |
|
100 { |
|
101 // reset our local FSM for the next time... |
|
102 iState = EINIT; |
|
103 } |
|
104 |
|
105 // ----------------------------------------------------------------------------- |
|
106 // |
|
107 // ----------------------------------------------------------------------------- |
|
108 // |
|
109 void WlanDot11AssociationPending::Fsm( |
|
110 WlanContextImpl& aCtxImpl, |
|
111 TEvent aEvent ) |
|
112 { |
|
113 OsTracePrint( KUmacAssoc, |
|
114 (TUint8*)("UMAC: WlanDot11AssociationPending::Fsm(): FSM EVENT") ); |
|
115 #ifndef NDEBUG |
|
116 OsTracePrint( KUmacAssoc, (TUint8*)("UMAC: event:")); |
|
117 OsTracePrint( KUmacAssoc, iEventName[aEvent] ); |
|
118 OsTracePrint( KUmacAssoc, (TUint8*)("UMAC: state:")); |
|
119 OsTracePrint( KUmacAssoc, iStateName[iState] ); |
|
120 #endif |
|
121 |
|
122 switch ( aEvent ) |
|
123 { |
|
124 case ESTATEENTRY: |
|
125 OnStateEntryEvent( aCtxImpl ); |
|
126 break; |
|
127 case ETX_ASSOCFRAME_XFER: |
|
128 OnTxAssocFrameXferEvent( aCtxImpl ); |
|
129 break; |
|
130 case ERXASSOCRESPONSE: |
|
131 OnRxAssociationResponseEvent( aCtxImpl ); |
|
132 break; |
|
133 case ETXCOMPLETE: |
|
134 OnTxCompleteEvent( aCtxImpl ); |
|
135 break; |
|
136 case ETIMEOUT: |
|
137 OnTimeoutEvent( aCtxImpl ); |
|
138 break; |
|
139 case ETX_SCHEDULER_FULL: |
|
140 OnTxSchedulerFullEvent( aCtxImpl ); |
|
141 break; |
|
142 case EPUSHPACKET: |
|
143 OnPushPacketEvent( aCtxImpl ); |
|
144 break; |
|
145 default: |
|
146 // cath internal FSM programming error |
|
147 OsAssert( (TUint8*)("UMAC: panic"), (TUint8*)(WLAN_FILE), __LINE__ ); |
|
148 break; |
|
149 } |
|
150 } |
|
151 |
|
152 // ----------------------------------------------------------------------------- |
|
153 // Handler for state entry event. |
|
154 // ----------------------------------------------------------------------------- |
|
155 // |
|
156 void WlanDot11AssociationPending::OnStateEntryEvent( |
|
157 WlanContextImpl& aCtxImpl ) |
|
158 { |
|
159 OsTracePrint( |
|
160 KUmacAssoc, |
|
161 (TUint8*)("UMAC: WlanDot11AssociationPending::OnStateEntryEvent()")); |
|
162 |
|
163 switch ( iState ) |
|
164 { |
|
165 case EINIT: |
|
166 iFlags = 0; |
|
167 ChangeInternalState( aCtxImpl, ETXASSOCREQFRAME ); |
|
168 break; |
|
169 case ETXASSOCREQFRAME: |
|
170 // send the associate frame |
|
171 if ( !SendAssociationRequest( aCtxImpl ) ) |
|
172 { |
|
173 // tx of dot11-associate frame failed |
|
174 // because packet scheduler was full |
|
175 // or because we didn't get a Tx buffer |
|
176 // so we enter to a wait state |
|
177 Fsm( aCtxImpl, ETX_SCHEDULER_FULL ); |
|
178 } |
|
179 break; |
|
180 case EWAIT4ASSOCRESPONSE: |
|
181 // start a timer to wait for the response frame |
|
182 StartAssociationFrameResponseTimer( aCtxImpl ); |
|
183 break; |
|
184 case ECONFIGUREAC: |
|
185 ConfigureAc( aCtxImpl ); |
|
186 break; |
|
187 case ECONTINUEDOT11TRAVERSE: |
|
188 ContinueDot11StateTraversal( aCtxImpl ); |
|
189 break; |
|
190 case EWAIT4PUSHPACKET: |
|
191 // nothing to do here than wait |
|
192 break; |
|
193 default: |
|
194 // catch internal FSM programming error |
|
195 #ifndef NDEBUG |
|
196 OsTracePrint( KErrorLevel, (TUint8*)("state:")); |
|
197 OsTracePrint( KErrorLevel, iStateName[iState] ); |
|
198 #endif |
|
199 OsAssert( (TUint8*)("* UMAC * panic"), |
|
200 (TUint8*)(WLAN_FILE), __LINE__ ); |
|
201 break; |
|
202 } |
|
203 } |
|
204 |
|
205 // ----------------------------------------------------------------------------- |
|
206 // Handler for association response timeout event. |
|
207 // ----------------------------------------------------------------------------- |
|
208 // |
|
209 void WlanDot11AssociationPending::OnTimeoutEvent( |
|
210 WlanContextImpl& aCtxImpl ) |
|
211 { |
|
212 // set completion code |
|
213 // as dot11idle state does the OID completion |
|
214 aCtxImpl.iStates.iIdleState.Set( KErrTimedOut ); |
|
215 ChangeInternalState( aCtxImpl, ECONTINUEDOT11TRAVERSE ); |
|
216 } |
|
217 |
|
218 // ----------------------------------------------------------------------------- |
|
219 // Handler for associate request frame |
|
220 // has been xferred to the WLAN device event |
|
221 // ----------------------------------------------------------------------------- |
|
222 // |
|
223 void WlanDot11AssociationPending::OnTxAssocFrameXferEvent( |
|
224 WlanContextImpl& aCtxImpl ) |
|
225 { |
|
226 // change state |
|
227 ChangeInternalState( aCtxImpl, EWAIT4ASSOCRESPONSE ); |
|
228 } |
|
229 |
|
230 // ----------------------------------------------------------------------------- |
|
231 // Handler for rx association response event. |
|
232 // ----------------------------------------------------------------------------- |
|
233 // |
|
234 void WlanDot11AssociationPending::OnRxAssociationResponseEvent( |
|
235 WlanContextImpl& aCtxImpl ) |
|
236 { |
|
237 switch ( iState ) |
|
238 { |
|
239 case EWAIT4ASSOCRESPONSE: |
|
240 if ( iFlags & KConfigureAc ) |
|
241 { |
|
242 ChangeInternalState( aCtxImpl, ECONFIGUREAC ); |
|
243 } |
|
244 else |
|
245 { |
|
246 ChangeInternalState( aCtxImpl, ECONTINUEDOT11TRAVERSE ); |
|
247 } |
|
248 break; |
|
249 default: |
|
250 // this means that we have recieved a valid dot11 |
|
251 // associate response frame that we are waiting for |
|
252 // but we are not internally in such a state |
|
253 // only feasible situation for this is that |
|
254 // someone has skipped a call to the packet xfer method |
|
255 // that informs of associate request frame |
|
256 // xfer to the WLAN device. |
|
257 // other case is that our fsm is totally messed up |
|
258 // so we catch this |
|
259 #ifndef NDEBUG |
|
260 OsTracePrint( KErrorLevel, (TUint8*)("state:")); |
|
261 OsTracePrint( KErrorLevel, iStateName[iState] ); |
|
262 #endif |
|
263 OsAssert( (TUint8*)("* UMAC * panic"), |
|
264 (TUint8*)(WLAN_FILE), __LINE__ ); |
|
265 break; |
|
266 } |
|
267 } |
|
268 |
|
269 // ----------------------------------------------------------------------------- |
|
270 // |
|
271 // ----------------------------------------------------------------------------- |
|
272 // |
|
273 void WlanDot11AssociationPending::OnTxCompleteEvent( |
|
274 WlanContextImpl& aCtxImpl ) |
|
275 { |
|
276 switch ( iState ) |
|
277 { |
|
278 case ECONFIGUREAC: |
|
279 // continue state traversal |
|
280 ChangeInternalState( aCtxImpl, ECONTINUEDOT11TRAVERSE ); |
|
281 break; |
|
282 default: |
|
283 // catch internal FSM programming error |
|
284 OsTracePrint( KErrorLevel, (TUint8*)("UMAC: state: %d"), iState); |
|
285 OsAssert( (TUint8*)("UMAC: panic"), (TUint8*)(WLAN_FILE), __LINE__ ); |
|
286 break; |
|
287 } |
|
288 } |
|
289 |
|
290 // ----------------------------------------------------------------------------- |
|
291 // Handler for scheduler full event upon trying to tx dot11-associate frame |
|
292 // ----------------------------------------------------------------------------- |
|
293 // |
|
294 void WlanDot11AssociationPending::OnTxSchedulerFullEvent( |
|
295 WlanContextImpl& aCtxImpl ) |
|
296 { |
|
297 // change state |
|
298 OsTracePrint( KWarningLevel | KUmacAssoc, (TUint8*) |
|
299 ("UMAC: packet scheduler full during association process") ); |
|
300 |
|
301 ChangeInternalState( aCtxImpl, EWAIT4PUSHPACKET ); |
|
302 } |
|
303 |
|
304 // ----------------------------------------------------------------------------- |
|
305 // Handler for push packet to packet scheduler possible event |
|
306 // ----------------------------------------------------------------------------- |
|
307 // |
|
308 void WlanDot11AssociationPending::OnPushPacketEvent( |
|
309 WlanContextImpl& aCtxImpl ) |
|
310 { |
|
311 if ( iState == EWAIT4PUSHPACKET ) |
|
312 { |
|
313 ChangeInternalState( aCtxImpl, ETXASSOCREQFRAME ); |
|
314 } |
|
315 } |
|
316 |
|
317 // ----------------------------------------------------------------------------- |
|
318 // |
|
319 // ----------------------------------------------------------------------------- |
|
320 // |
|
321 void WlanDot11AssociationPending::ContinueDot11StateTraversal( |
|
322 WlanContextImpl& aCtxImpl ) |
|
323 { |
|
324 if ( iFlags & KAssocSuccess ) |
|
325 { |
|
326 // traverse to next dot11state |
|
327 ChangeState( aCtxImpl, |
|
328 *this, // prev state |
|
329 aCtxImpl.iStates.iInfrastructureModeInit // next state |
|
330 ); |
|
331 } |
|
332 else |
|
333 { |
|
334 // proceed back to idle |
|
335 // |
|
336 ChangeState( aCtxImpl, |
|
337 *this, // prev state |
|
338 aCtxImpl.iStates.iIdleState // next state |
|
339 ); |
|
340 } |
|
341 } |
|
342 |
|
343 // ----------------------------------------------------------------------------- |
|
344 // |
|
345 // ----------------------------------------------------------------------------- |
|
346 // |
|
347 void WlanDot11AssociationPending::ChangeInternalState( |
|
348 WlanContextImpl& aCtxImpl, |
|
349 TState aNewState ) |
|
350 { |
|
351 OsTracePrint( KUmacAssoc, (TUint8*) |
|
352 ("UMAC: WlanDot11AssociationPending::ChangeInternalState(): old state:")); |
|
353 #ifndef NDEBUG |
|
354 OsTracePrint( KUmacAssoc, iStateName[iState] ); |
|
355 OsTracePrint( KUmacAssoc, (TUint8*)("new state:")); |
|
356 OsTracePrint( KUmacAssoc, iStateName[aNewState] ); |
|
357 #endif |
|
358 iState = aNewState; |
|
359 Fsm( aCtxImpl, ESTATEENTRY ); |
|
360 } |
|
361 |
|
362 // ----------------------------------------------------------------------------- |
|
363 // |
|
364 // ----------------------------------------------------------------------------- |
|
365 // |
|
366 #ifndef NDEBUG |
|
367 const TInt8* WlanDot11AssociationPending::GetStateName( |
|
368 TUint8& aLength ) const |
|
369 { |
|
370 aLength = sizeof( iName ); |
|
371 return iName; |
|
372 } |
|
373 #endif |
|
374 |
|
375 // ----------------------------------------------------------------------------- |
|
376 // |
|
377 // ----------------------------------------------------------------------------- |
|
378 // |
|
379 TBool WlanDot11AssociationPending::SendAssociationRequest( |
|
380 WlanContextImpl& aCtxImpl ) |
|
381 { |
|
382 OsTracePrint( KUmacAssoc, (TUint8*) |
|
383 ("UMAC: WlanDot11AssociationPending::SendAssociationRequest")); |
|
384 |
|
385 TBool status ( EFalse ); |
|
386 TUint8* startOfFrame ( NULL ); |
|
387 |
|
388 const TUint32 length_of_frame |
|
389 = ConstructAssociationRequestFrame( aCtxImpl, startOfFrame ); |
|
390 |
|
391 if ( length_of_frame ) |
|
392 { |
|
393 // frame is ready for delivery in the tx buffer |
|
394 // send association request message to the AP |
|
395 |
|
396 const WHA::TQueueId queue_id |
|
397 = QueueId( aCtxImpl, startOfFrame ); |
|
398 |
|
399 // push the frame to packet scheduler for transmission |
|
400 status = aCtxImpl.PushPacketToPacketScheduler( |
|
401 startOfFrame, |
|
402 length_of_frame, |
|
403 queue_id, |
|
404 E802Dot11FrameTypeAssociationReq, |
|
405 NULL, |
|
406 EFalse, |
|
407 EFalse, |
|
408 ETrue ); |
|
409 |
|
410 if ( !status ) |
|
411 { |
|
412 // as we came here we did get an internal Tx buffer for the frame |
|
413 // but packet push to scheduler failed. In this case we need cancel |
|
414 // the internal Tx buffer reservation as we will request it again |
|
415 // when the Packet Scheduler is again ready for packet push |
|
416 aCtxImpl.MarkInternalTxBufFree(); |
|
417 } |
|
418 } |
|
419 else |
|
420 { |
|
421 // frame not ready for delivery. EFalse will be returned |
|
422 } |
|
423 |
|
424 return status; |
|
425 } |
|
426 |
|
427 // ----------------------------------------------------------------------------- |
|
428 // |
|
429 // ----------------------------------------------------------------------------- |
|
430 // |
|
431 TUint WlanDot11AssociationPending::ConstructAssociationRequestFrame( |
|
432 WlanContextImpl& aCtxImpl, |
|
433 TUint8*& aStartOfFrame ) |
|
434 { |
|
435 OsTracePrint( KUmacAssoc, (TUint8*) |
|
436 ("UMAC: WlanDot11AssociationPending::ConstructAssociationRequestFrame") ); |
|
437 |
|
438 TUint32 lengthOfFrame ( 0 ); |
|
439 |
|
440 // client doesn't have to take care of the tx buffer header space |
|
441 // as the method below does that by itself |
|
442 aStartOfFrame = aCtxImpl.TxBuffer( ETrue ); |
|
443 |
|
444 if ( aStartOfFrame ) |
|
445 { |
|
446 // construct association request frame |
|
447 // note that we don't need to set SA because we have already set it |
|
448 // in the initialization phase of the state machine |
|
449 // Also capabilty information field is already set to frame template |
|
450 // in AreNetworkRequirementsMet() method |
|
451 |
|
452 TUint8* buffer_ptr = aStartOfFrame; |
|
453 |
|
454 if ( aCtxImpl.HtSupportedByNw() && aCtxImpl.QosEnabled() ) |
|
455 { |
|
456 // set the BSSID field |
|
457 (aCtxImpl.GetHtAssociationRequestFrame()).iHeader.iBSSID = |
|
458 aCtxImpl.GetBssId(); |
|
459 // set the DA field |
|
460 (aCtxImpl.GetHtAssociationRequestFrame()).iHeader.iDA = |
|
461 aCtxImpl.GetBssId(); |
|
462 // set listen interval (in units of beacon interval) |
|
463 (aCtxImpl.GetHtAssociationRequestFrame()).iFixedFields.iListenInterval |
|
464 = KDot11ListenIntervalInMs / aCtxImpl.NetworkBeaconInterval(); |
|
465 |
|
466 // copy frame to tx-buffer to correct offset |
|
467 os_memcpy( |
|
468 buffer_ptr, |
|
469 &(aCtxImpl.GetHtAssociationRequestFrame()), |
|
470 sizeof( SHtAssociationRequestFrame ) ); |
|
471 |
|
472 buffer_ptr += sizeof( SHtAssociationRequestFrame ); |
|
473 } |
|
474 else |
|
475 { |
|
476 // set the BSSID field |
|
477 (aCtxImpl.GetAssociationRequestFrame()).iHeader.iBSSID = |
|
478 aCtxImpl.GetBssId(); |
|
479 // set the DA field |
|
480 (aCtxImpl.GetAssociationRequestFrame()).iHeader.iDA = |
|
481 aCtxImpl.GetBssId(); |
|
482 // set listen interval (in units of beacon interval) |
|
483 (aCtxImpl.GetAssociationRequestFrame()).iFixedFields.iListenInterval |
|
484 = KDot11ListenIntervalInMs / aCtxImpl.NetworkBeaconInterval(); |
|
485 |
|
486 // copy frame to tx-buffer to correct offset |
|
487 os_memcpy( |
|
488 buffer_ptr, |
|
489 &(aCtxImpl.GetAssociationRequestFrame()), |
|
490 sizeof( SAssociationRequestFrame ) ); |
|
491 |
|
492 buffer_ptr += sizeof( SAssociationRequestFrame ); |
|
493 } |
|
494 |
|
495 // set SSID IE |
|
496 |
|
497 SSsIdIE ssid_ie( (aCtxImpl.GetSsId()).ssid, |
|
498 (aCtxImpl.GetSsId()).ssidLength ); |
|
499 |
|
500 const TUint8 ssidIeLength( ssid_ie.GetIeLength() ); |
|
501 |
|
502 os_memcpy( |
|
503 buffer_ptr, |
|
504 &ssid_ie, |
|
505 ssidIeLength ); |
|
506 |
|
507 buffer_ptr += ssidIeLength; |
|
508 |
|
509 // set supported rates IE |
|
510 |
|
511 const TUint8 supportedRatesIeLength( |
|
512 aCtxImpl.GetOurSupportedRatesIE().GetIeLength() ); |
|
513 |
|
514 os_memcpy( |
|
515 buffer_ptr, |
|
516 &(aCtxImpl.GetOurSupportedRatesIE()), |
|
517 supportedRatesIeLength ); |
|
518 |
|
519 buffer_ptr += supportedRatesIeLength; |
|
520 |
|
521 if ( aCtxImpl.HtSupportedByNw() ) |
|
522 { |
|
523 // set HT capabilities element |
|
524 |
|
525 const TUint8 htCapabilitiesIeLength( |
|
526 aCtxImpl.GetOurHtCapabilitiesIe().GetIeLength() ); |
|
527 |
|
528 os_memcpy( |
|
529 buffer_ptr, |
|
530 &(aCtxImpl.GetOurHtCapabilitiesIe()), |
|
531 htCapabilitiesIeLength ); |
|
532 |
|
533 buffer_ptr += htCapabilitiesIeLength; |
|
534 |
|
535 OsTracePrint( KUmacAssoc, (TUint8*) |
|
536 ("UMAC: HT capabilities element added") ); |
|
537 } |
|
538 |
|
539 // set extended supported rates IE if it's not empty |
|
540 if ( aCtxImpl.GetOurExtendedSupportedRatesIE().GetElementLength() ) |
|
541 { |
|
542 const TUint8 extSupportedRatesIeLength( |
|
543 aCtxImpl.GetOurExtendedSupportedRatesIE().GetIeLength() ); |
|
544 |
|
545 os_memcpy( |
|
546 buffer_ptr, |
|
547 &(aCtxImpl.GetOurExtendedSupportedRatesIE()), |
|
548 extSupportedRatesIeLength ); |
|
549 |
|
550 buffer_ptr += extSupportedRatesIeLength; |
|
551 } |
|
552 |
|
553 // set any IEs possibly provided by management client |
|
554 const TUint8* ieData( aCtxImpl.IeData() ); |
|
555 if ( ieData ) |
|
556 { |
|
557 const TUint16 ieDataLength( aCtxImpl.IeDataLength() ); |
|
558 |
|
559 os_memcpy( buffer_ptr, ieData, ieDataLength ); |
|
560 buffer_ptr += ieDataLength; |
|
561 |
|
562 OsTracePrint( KUmacAssoc, (TUint8*) |
|
563 ("UMAC: management client supplied IE(s) added") ); |
|
564 } |
|
565 |
|
566 // set WMM IE if needed |
|
567 if ( aCtxImpl.QosEnabled() ) |
|
568 { |
|
569 const TUint8 wmmIeLength( aCtxImpl.OurWmmIe().GetIeLength() ); |
|
570 |
|
571 os_memcpy( |
|
572 buffer_ptr, |
|
573 &(aCtxImpl.OurWmmIe()), |
|
574 wmmIeLength); |
|
575 |
|
576 buffer_ptr += wmmIeLength; |
|
577 |
|
578 OsTracePrint( KUmacAssoc, (TUint8*) |
|
579 ("UMAC: WMM IE added") ); |
|
580 } |
|
581 |
|
582 // length of frame |
|
583 lengthOfFrame = buffer_ptr - aStartOfFrame; |
|
584 } |
|
585 else |
|
586 { |
|
587 // we didn't get a Tx buffer => frame not sent. Zero will be returned |
|
588 // as the frame length to indicate that |
|
589 OsTracePrint( KUmacAssoc, (TUint8*) |
|
590 ("UMAC: WlanDot11AssociationPending::ConstructAssociationRequestFrame: no internal Tx buffer available") ); |
|
591 } |
|
592 |
|
593 return lengthOfFrame; |
|
594 } |
|
595 |
|
596 // ----------------------------------------------------------------------------- |
|
597 // |
|
598 // ----------------------------------------------------------------------------- |
|
599 // |
|
600 T802Dot11ManagementStatusCode |
|
601 WlanDot11AssociationPending::IsRxAssociationSuccess( |
|
602 WlanContextImpl& aCtxImpl, |
|
603 const void* aFrame, |
|
604 TUint32 aFlags ) |
|
605 { |
|
606 OsTracePrint( KUmacAssoc, (TUint8*) |
|
607 ("UMAC: WlanDot11AssociationPending::IsRxAssociationSuccess")); |
|
608 // get the fixed fields from association response |
|
609 const SAssociationResponseFixedFields* fields = |
|
610 HtcFieldPresent( aCtxImpl, aFrame, aFlags ) ? |
|
611 reinterpret_cast<const SAssociationResponseFixedFields*> |
|
612 (reinterpret_cast<const TUint8*>(aFrame) + |
|
613 sizeof( SHtManagementFrameHeader )) : |
|
614 reinterpret_cast<const SAssociationResponseFixedFields*> |
|
615 (reinterpret_cast<const TUint8*>(aFrame) + |
|
616 sizeof( SManagementFrameHeader ) ); |
|
617 |
|
618 // store AID |
|
619 OsTracePrint( KUmacAssoc, (TUint8*) |
|
620 ("UMAC: WlanDot11AssociationPending::IsRxAssociationSuccess: AID extracted from association response: 0x%04x"), |
|
621 fields->Aid() ); |
|
622 aCtxImpl.Aid( fields->Aid() ); |
|
623 |
|
624 return static_cast<T802Dot11ManagementStatusCode>( |
|
625 fields->StatusCode() ); |
|
626 } |
|
627 |
|
628 // ----------------------------------------------------------------------------- |
|
629 // |
|
630 // ----------------------------------------------------------------------------- |
|
631 // |
|
632 void WlanDot11AssociationPending::StartAssociationFrameResponseTimer( |
|
633 WlanContextImpl& aCtxImpl ) |
|
634 { |
|
635 // start association response timeout timer |
|
636 const TUint32 timeout( dot11AssociateResponseTimeout * KTU ); |
|
637 |
|
638 OsTracePrint( KUmacAssoc, (TUint8*) |
|
639 ("UMAC: WlanDot11AssociationPending::StartAssociationFrameResponseTimer: timeout in microseconds: %d"), |
|
640 timeout); |
|
641 |
|
642 aCtxImpl.iUmac.RegisterTimeout( timeout ); |
|
643 } |
|
644 |
|
645 // ----------------------------------------------------------------------------- |
|
646 // |
|
647 // ----------------------------------------------------------------------------- |
|
648 // |
|
649 void WlanDot11AssociationPending::ConfigureAc( |
|
650 WlanContextImpl& aCtxImpl ) |
|
651 { |
|
652 ConfigureAcParams( aCtxImpl ); |
|
653 } |
|
654 |
|
655 // ----------------------------------------------------------------------------- |
|
656 // |
|
657 // ----------------------------------------------------------------------------- |
|
658 // |
|
659 void WlanDot11AssociationPending::ReceivePacket( |
|
660 WlanContextImpl& aCtxImpl, |
|
661 WHA::TStatus aStatus, |
|
662 const void* aFrame, |
|
663 TUint16 aLength, |
|
664 WHA::TRate /*aRate*/, |
|
665 WHA::TRcpi aRcpi, |
|
666 WHA::TChannelNumber /*aChannel*/, |
|
667 TUint8* aBuffer, |
|
668 TUint32 aFlags ) |
|
669 { |
|
670 OsTracePrint( KUmacAssoc, (TUint8*) |
|
671 ("UMAC: dot11-associatepending::ReceivePacket()") ); |
|
672 |
|
673 if ( aStatus == WHA::KSuccess ) |
|
674 { |
|
675 // receive success |
|
676 const Sdot11MacHeader* dot11_hdr( |
|
677 static_cast<const Sdot11MacHeader*>(aFrame) ); |
|
678 |
|
679 // we accept only frames with ToDS bit cleared |
|
680 if ( dot11_hdr->IsToDsBitSet() ) |
|
681 { |
|
682 OsTracePrint( KWarningLevel | KUmacAssoc, |
|
683 (TUint8*)("UMAC: associating to BSS:") ); |
|
684 OsTracePrint( KWarningLevel | KUmacAssoc, |
|
685 (TUint8*)("UMAC: rx-frame: ToDs bit set, discard frame") ); |
|
686 |
|
687 // release the Rx buffer & abort |
|
688 aCtxImpl.iUmac.MarkRxBufFree( aBuffer ); |
|
689 return; |
|
690 } |
|
691 |
|
692 const TBool class3_frame( IsClass3Frame( |
|
693 dot11_hdr->iFrameControl.iType ) ); |
|
694 const TBool unicast_addr( !IsGroupBitSet( dot11_hdr->iAddress1 ) ); |
|
695 |
|
696 if ( class3_frame && unicast_addr ) |
|
697 { |
|
698 OsTracePrint( KWarningLevel | KUmacAssoc, |
|
699 (TUint8*)("UMAC: associating to BSS:") ); |
|
700 OsTracePrint( KWarningLevel | KUmacAssoc, |
|
701 (TUint8*)("rx class3 frame with unicast DA address") ); |
|
702 |
|
703 // class 3 frame rx and unicast address in address1 field |
|
704 |
|
705 // That's not the frame we are expecting so release the Rx buffer |
|
706 aCtxImpl.iUmac.MarkRxBufFree( aBuffer ); |
|
707 |
|
708 if ( !Associated() ) |
|
709 { |
|
710 // we do not have a valid association with the |
|
711 // BSS where the frame came |
|
712 OsTracePrint( KWarningLevel | KUmacAssoc, |
|
713 (TUint8*)("UMAC: TxDisassociate") ); |
|
714 |
|
715 // set the BSSID of the existing network; and the DA |
|
716 if ( aCtxImpl.HtSupportedByNw() ) |
|
717 { |
|
718 (aCtxImpl.GetHtDisassociationFrame()).iHeader.iBSSID |
|
719 = aCtxImpl.GetBssId(); |
|
720 (aCtxImpl.GetHtDisassociationFrame()).iHeader.iDA |
|
721 = aCtxImpl.GetBssId(); |
|
722 } |
|
723 else |
|
724 { |
|
725 (aCtxImpl.GetDisassociationFrame()).iHeader.iBSSID |
|
726 = aCtxImpl.GetBssId(); |
|
727 (aCtxImpl.GetDisassociationFrame()).iHeader.iDA |
|
728 = aCtxImpl.GetBssId(); |
|
729 } |
|
730 if ( !TxDisassociate( |
|
731 aCtxImpl, |
|
732 E802Dot11ReasonClass3FrameWhenNotAssoc ) ) |
|
733 { |
|
734 // frame was not sent because either packet scheduler was |
|
735 // full or because we didn't get a Tx buffer. In any case |
|
736 // we won't try to send it again. |
|
737 } |
|
738 } |
|
739 else |
|
740 { |
|
741 // this section is left intentionally empty |
|
742 } |
|
743 } |
|
744 else |
|
745 { |
|
746 // default handler |
|
747 OnReceiveFrameSuccess( |
|
748 aCtxImpl, |
|
749 aFrame, |
|
750 aLength, |
|
751 aRcpi, |
|
752 aFlags, |
|
753 aBuffer ); |
|
754 } |
|
755 } |
|
756 else // --- aStatus == WHA::KSuccess --- |
|
757 { |
|
758 // receive failed, so discard and release the Rx buffer |
|
759 aCtxImpl.iUmac.MarkRxBufFree( aBuffer ); |
|
760 } |
|
761 } |
|
762 |
|
763 // ----------------------------------------------------------------------------- |
|
764 // |
|
765 // ----------------------------------------------------------------------------- |
|
766 // |
|
767 void WlanDot11AssociationPending::OnReceiveFrameSuccess( |
|
768 WlanContextImpl& aCtxImpl, |
|
769 const void* aFrame, |
|
770 TUint16 aLength, |
|
771 WHA::TRcpi aRcpi, |
|
772 TUint32 aFlags, |
|
773 TUint8* aBuffer ) |
|
774 { |
|
775 // receive success |
|
776 // parse frame in order to determine if it is what we are expecting |
|
777 SManagementFrameHeader* frame_hdr |
|
778 = static_cast<SManagementFrameHeader*> |
|
779 (const_cast<TAny*>(aFrame)); |
|
780 |
|
781 TBool type_match( EFalse ); |
|
782 |
|
783 if ( // this an association response frame |
|
784 IsRequestedFrameType( |
|
785 frame_hdr->iFrameControl.iType, |
|
786 E802Dot11FrameTypeAssociationResp, type_match ) |
|
787 // AND our MAC address is DA |
|
788 && ( frame_hdr->iDA == aCtxImpl.iWlanMib.dot11StationId ) |
|
789 // AND we haven't received the assoc response yet |
|
790 && ( !( iFlags & KAssocReceived ) ) ) |
|
791 { |
|
792 T802Dot11ManagementStatusCode status |
|
793 = IsRxAssociationSuccess( aCtxImpl, aFrame, aFlags ); |
|
794 |
|
795 if ( status == E802Dot11StatusSuccess ) |
|
796 { |
|
797 // --- begin WMM |
|
798 if ( aCtxImpl.QosEnabled() ) |
|
799 { |
|
800 WlanElementLocator elementLocator( |
|
801 reinterpret_cast<const TUint8*>( aFrame ) + |
|
802 sizeof( SManagementFrameHeader ) + |
|
803 sizeof( SAssociationResponseFixedFields ), |
|
804 aLength - |
|
805 sizeof( SManagementFrameHeader ) + |
|
806 sizeof( SAssociationResponseFixedFields ) ); |
|
807 |
|
808 TUint8 length( 0 ); |
|
809 const TUint8* data( NULL ); |
|
810 |
|
811 // is WMM Parameter Element present |
|
812 if ( elementLocator.InformationElement( |
|
813 E802Dot11VendorSpecificIE, |
|
814 KWmmElemOui, |
|
815 KWmmElemOuiType, |
|
816 KWmmParamElemOuiSubtype, |
|
817 length, |
|
818 &data ) == WlanElementLocator::EWlanLocateOk ) |
|
819 { |
|
820 // WMM Parameter Element found |
|
821 OsTracePrint( KUmacAssoc, (TUint8*) |
|
822 ("UMAC: WlanDot11AssociationPending::ReceivePacket(): WMM param set cnt: %d"), |
|
823 (reinterpret_cast<const SWmmParamElemData*>(data))->ParameterSetCount() ); |
|
824 |
|
825 if ( (reinterpret_cast<const SWmmParamElemData*> |
|
826 (data))->ParameterSetCount() |
|
827 != aCtxImpl.WmmParameterSetCount() ) |
|
828 { |
|
829 // AC parameters have changed => parse again |
|
830 ParseAcParameters( |
|
831 aCtxImpl, |
|
832 reinterpret_cast<const SWmmParamElemData&>(*data ) ); |
|
833 // in this case we need to re-issue configure AC wha cmd |
|
834 // so make a note of that |
|
835 iFlags |= KConfigureAc; |
|
836 } |
|
837 } |
|
838 else |
|
839 { |
|
840 // protocol error from AP; just try to continue with |
|
841 // current WMM parameters |
|
842 OsTracePrint( KWarningLevel | KUmacAssoc, (TUint8*) |
|
843 ("UMAC: WlanDot11AssociationPending::ReceivePacket(): PROTOCOL ERROR from AP side") ); |
|
844 } |
|
845 } |
|
846 // --- end WMM |
|
847 } |
|
848 else |
|
849 { |
|
850 // association failed |
|
851 OsTracePrint( KWarningLevel | KUmacAssoc, (TUint8*) |
|
852 ("UMAC: dot11-association denied; status code: %d"), |
|
853 status); |
|
854 |
|
855 // in this case we will go back to idle state |
|
856 // where the connect oid will be completed. |
|
857 // So set the completion code value to be returned to user mode |
|
858 aCtxImpl.iStates.iIdleState.Set( status ); |
|
859 } |
|
860 |
|
861 // forward the association response frame to Wlan Mgmt client |
|
862 if ( XferDot11FrameToMgmtClient( |
|
863 aCtxImpl, |
|
864 aFrame, |
|
865 aLength, |
|
866 aRcpi, |
|
867 aBuffer ) ) |
|
868 { |
|
869 // forwarding succeeded. Now we can say that we have received |
|
870 // the assoc response successfully |
|
871 |
|
872 iFlags |= KAssocReceived; |
|
873 aCtxImpl.CancelTimer(); |
|
874 |
|
875 if ( status == E802Dot11StatusSuccess ) |
|
876 { |
|
877 OsTracePrint( KUmacAssoc, (TUint8*) |
|
878 ("UMAC: association pending: association success") ); |
|
879 |
|
880 iFlags |= KAssocSuccess; |
|
881 } |
|
882 |
|
883 Fsm( aCtxImpl, ERXASSOCRESPONSE ); |
|
884 } |
|
885 else |
|
886 { |
|
887 // forwarding the frame to WLAN Mgmt client failed, which |
|
888 // won't happen in this situation under the normal circumstances. |
|
889 // Anyhow, it has happened now, so we have no other choice than to |
|
890 // discard the frame. The Rx buffer has already been |
|
891 // released. So no action here |
|
892 } |
|
893 } |
|
894 else |
|
895 { |
|
896 // not a valid frame in this situation; we just silently discard it |
|
897 OsTracePrint( KUmacAssoc | KUmacDetails, (TUint8*) |
|
898 ("UMAC: WlanDot11AssociationPending::OnReceiveFrameSuccess: " |
|
899 "not relevant frame; ignore")); |
|
900 |
|
901 // release the Rx buffer |
|
902 aCtxImpl.iUmac.MarkRxBufFree( aBuffer ); |
|
903 } |
|
904 } |
|
905 |
|
906 // ----------------------------------------------------------------------------- |
|
907 // completion method called when packet has been xferred to the WLAN device |
|
908 // ----------------------------------------------------------------------------- |
|
909 // |
|
910 void WlanDot11AssociationPending::OnPacketTransferComplete( |
|
911 WlanContextImpl& aCtxImpl, |
|
912 TUint32 aPacketId, |
|
913 TDataBuffer* aMetaHeader ) |
|
914 { |
|
915 OsTracePrint( KUmacAssoc, (TUint8*) |
|
916 ("UMAC: WlanDot11AssociationPending::OnPacketTransferComplete")); |
|
917 |
|
918 if ( aPacketId == E802Dot11FrameTypeData ) |
|
919 { |
|
920 OnTxProtocolStackDataComplete( aCtxImpl, aMetaHeader ); |
|
921 } |
|
922 else if ( aPacketId == E802Dot11FrameTypeDataEapol || |
|
923 aPacketId == E802Dot11FrameTypeManagementAction || |
|
924 aPacketId == E802Dot11FrameTypeTestFrame ) |
|
925 { |
|
926 OnMgmtPathWriteComplete( aCtxImpl ); |
|
927 } |
|
928 else |
|
929 { |
|
930 // this frame Tx request didn't come from above us (i.e. neither |
|
931 // through the user data nor the management data API) but is |
|
932 // related to a frame Tx we have done internally. So we need to mark |
|
933 // the internal Tx buffer free again |
|
934 aCtxImpl.MarkInternalTxBufFree(); |
|
935 } |
|
936 |
|
937 if ( aPacketId == E802Dot11FrameTypeAssociationReq ) |
|
938 { |
|
939 // associate tx message has been xferred to the WLAN device |
|
940 |
|
941 Fsm( aCtxImpl, ETX_ASSOCFRAME_XFER ); |
|
942 } |
|
943 } |
|
944 |
|
945 // ----------------------------------------------------------------------------- |
|
946 // |
|
947 // ----------------------------------------------------------------------------- |
|
948 // |
|
949 TBool WlanDot11AssociationPending::OnTimeout( |
|
950 WlanContextImpl& aCtxImpl ) |
|
951 { |
|
952 TBool stateChange ( ETrue ); |
|
953 |
|
954 switch ( iState ) |
|
955 { |
|
956 case EWAIT4ASSOCRESPONSE: |
|
957 // association timeout |
|
958 |
|
959 OsTracePrint( KWarningLevel | KUmacAssoc, (TUint8*) |
|
960 ("UMAC: WlanDot11AssociationPending::OnTimeout: timeout => association failed!") ); |
|
961 |
|
962 Fsm( aCtxImpl, ETIMEOUT ); |
|
963 |
|
964 // in this case we return ETrue, i.e. signal the caller that a |
|
965 // state change occurred |
|
966 |
|
967 break; |
|
968 default: |
|
969 // a timeout occurred when we weren't expecting it (yet). This |
|
970 // means that a timeout callback had already been registered when |
|
971 // we tried to cancel this timer the previous time (regarding |
|
972 // authentication). So this callback is not relevant for |
|
973 // association and can be ignored. |
|
974 |
|
975 OsTracePrint( KWarningLevel | KUmacAssoc, (TUint8*) |
|
976 ("UMAC: WlanDot11AssociationPending::OnTimeout: irrelevant timeout; ignored") ); |
|
977 |
|
978 // Signal the caller that no state change occurred |
|
979 stateChange = EFalse; |
|
980 } |
|
981 |
|
982 return stateChange; |
|
983 } |
|
984 |
|
985 // ----------------------------------------------------------------------------- |
|
986 // packet sceduler notification that a packet push is guaranteed to succeed |
|
987 // ----------------------------------------------------------------------------- |
|
988 // |
|
989 void WlanDot11AssociationPending::OnPacketPushPossible( |
|
990 WlanContextImpl& aCtxImpl ) |
|
991 { |
|
992 // feed a critter to the fsm |
|
993 Fsm( aCtxImpl, EPUSHPACKET ); |
|
994 } |