|
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 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 WlanDot11SharedAuthPending class |
|
15 * |
|
16 */ |
|
17 |
|
18 /* |
|
19 * %version: 27 % |
|
20 */ |
|
21 |
|
22 #include "config.h" |
|
23 #include "UmacDot11SharedAuthPending.h" |
|
24 #include "UmacContextImpl.h" |
|
25 |
|
26 #ifndef NDEBUG |
|
27 const TInt8 WlanDot11SharedAuthPending::iName[] |
|
28 = "dot11-sharedauthpending"; |
|
29 #endif // !NDEBUG |
|
30 |
|
31 // ================= MEMBER FUNCTIONS ======================= |
|
32 |
|
33 // ----------------------------------------------------------------------------- |
|
34 // |
|
35 // ----------------------------------------------------------------------------- |
|
36 // |
|
37 #ifndef NDEBUG |
|
38 const TInt8* WlanDot11SharedAuthPending::GetStateName( |
|
39 TUint8& aLength ) const |
|
40 { |
|
41 aLength = sizeof( iName ); |
|
42 return iName; |
|
43 } |
|
44 #endif |
|
45 |
|
46 // ----------------------------------------------------------------------------- |
|
47 // set appropriate used algorithm number to authenticate request frame |
|
48 // ----------------------------------------------------------------------------- |
|
49 // |
|
50 void WlanDot11SharedAuthPending::OnSetAlgorithmNumber( |
|
51 WlanContextImpl& aCtxImpl ) |
|
52 { |
|
53 if ( aCtxImpl.HtSupportedByNw() ) |
|
54 { |
|
55 aCtxImpl.GetHtAuthenticationFrame().SetAlgorithmNmbr( |
|
56 K802Dot11AuthModeShared ); |
|
57 } |
|
58 else |
|
59 { |
|
60 aCtxImpl.GetAuthenticationFrame().SetAlgorithmNmbr( |
|
61 K802Dot11AuthModeShared ); |
|
62 } |
|
63 } |
|
64 |
|
65 // ----------------------------------------------------------------------------- |
|
66 // Handler for state entry event. |
|
67 // ----------------------------------------------------------------------------- |
|
68 // |
|
69 void WlanDot11SharedAuthPending::OnStateEntryEvent( |
|
70 WlanContextImpl& aCtxImpl ) |
|
71 { |
|
72 TBool ret( ETrue ); |
|
73 |
|
74 switch ( iState ) |
|
75 { |
|
76 case EINIT: |
|
77 // do all the synchronous |
|
78 // composite state entry actions |
|
79 StateEntryActions( aCtxImpl ); |
|
80 // continue with the state traversal |
|
81 Fsm( aCtxImpl, ECONTINUE ); |
|
82 break; |
|
83 case ETXAUTHFRAME: |
|
84 // send correct authenticate frame |
|
85 if ( aCtxImpl.GetAuthSeqNmbrExpected() |
|
86 == E802Dot11AuthenticationSeqNmbr2 ) |
|
87 { |
|
88 ret = SendAuthSeqNbr1Frame( aCtxImpl ); |
|
89 } |
|
90 else |
|
91 { |
|
92 ret = SendAuthSeqNbr3Frame( aCtxImpl ); |
|
93 } |
|
94 |
|
95 if (!ret ) |
|
96 { |
|
97 // tx of dot11-authenticate frame failed |
|
98 // because packet scheduler was full |
|
99 // or because we didn't get a Tx buffer |
|
100 // so we enter to a wait state |
|
101 Fsm( aCtxImpl, ETX_SCHEDULER_FULL ); |
|
102 } |
|
103 break; |
|
104 case ECONTINUEDOT11TRAVERSE: |
|
105 ContinueDot11StateTraversal( aCtxImpl ); |
|
106 break; |
|
107 case EWAIT4AUTHRESPONSE: |
|
108 StartAuthenticationFrameResponseTimer( aCtxImpl ); |
|
109 break; |
|
110 case EWAIT4PUSHPACKET: |
|
111 // nothing to do here than wait |
|
112 break; |
|
113 default: |
|
114 // catch internal FSM programming error |
|
115 #ifndef NDEBUG |
|
116 OsTracePrint( KErrorLevel, (TUint8*)("UMAC: state:")); |
|
117 OsTracePrint( KErrorLevel, iStateName[iState] ); |
|
118 #endif |
|
119 OsAssert( (TUint8*)("UMAC: panic"), |
|
120 (TUint8*)(WLAN_FILE), __LINE__ ); |
|
121 break; |
|
122 } |
|
123 } |
|
124 |
|
125 // ----------------------------------------------------------------------------- |
|
126 // Handler for rx authentication response event. |
|
127 // ----------------------------------------------------------------------------- |
|
128 // |
|
129 void WlanDot11SharedAuthPending::OnRxAuthResponseEvent( |
|
130 WlanContextImpl& aCtxImpl ) |
|
131 { |
|
132 switch ( iState ) |
|
133 { |
|
134 case EWAIT4AUTHRESPONSE: |
|
135 // check do we need to send an another authenticate frame or not |
|
136 if ( // current authentication frame exchange was a success |
|
137 ((iFlags & KAuthSuccess) |
|
138 // AND authentication frame exchange is complete |
|
139 && ( aCtxImpl.GetAuthSeqNmbrExpected() |
|
140 == E802Dot11AuthenticationSeqNmbr4 )) |
|
141 // OR current authentication frame exchange was a failure |
|
142 || !(iFlags & KAuthSuccess) |
|
143 ) |
|
144 { |
|
145 ChangeInternalState( aCtxImpl, ECONTINUEDOT11TRAVERSE ); |
|
146 } |
|
147 else |
|
148 { |
|
149 // current authentication frame exchange was a success |
|
150 // but authentication frame exchange is NOT complete |
|
151 |
|
152 // incerement the seq.nmbr expected from AP counter |
|
153 aCtxImpl.IncrementAuthSeqNmbrExpected(); |
|
154 ChangeInternalState( aCtxImpl, ETXAUTHFRAME ); |
|
155 } |
|
156 break; |
|
157 default: |
|
158 // this means that we have recieved a valid dot11 |
|
159 // authenticate response frame that we are waiting for |
|
160 // but we are not internally in such a state |
|
161 // only feasible situation for this is that |
|
162 // someone has skipped a call to the packet xfer method |
|
163 // that informs of authenticate request frame |
|
164 // xfer to the WLAN device. |
|
165 // other case is that our fsm is totally messed up |
|
166 // so we catch this |
|
167 #ifndef NDEBUG |
|
168 OsTracePrint( KErrorLevel, (TUint8*)("state:")); |
|
169 OsTracePrint( KErrorLevel, iStateName[iState] ); |
|
170 #endif |
|
171 OsAssert( (TUint8*)("UMAC: panic"), |
|
172 (TUint8*)(WLAN_FILE), __LINE__ ); |
|
173 break; |
|
174 } |
|
175 } |
|
176 |
|
177 // ----------------------------------------------------------------------------- |
|
178 // Send authenticate seq. number 3 message |
|
179 // ----------------------------------------------------------------------------- |
|
180 // |
|
181 TBool WlanDot11SharedAuthPending::SendAuthSeqNbr3Frame( |
|
182 WlanContextImpl& aCtxImpl ) const |
|
183 { |
|
184 OsTracePrint( KUmacAuth, (TUint8*) |
|
185 ("UMAC: WlanDot11SharedAuthPending::SendAuthSeqNbr3Frame") ); |
|
186 |
|
187 TBool status ( EFalse ); |
|
188 |
|
189 // client doesn't have to take care of the tx buffer header space |
|
190 // as the method below does that by itself |
|
191 TUint8* frame_ptr = aCtxImpl.TxBuffer( ETrue ); |
|
192 |
|
193 if ( frame_ptr ) |
|
194 { |
|
195 // store start of frame |
|
196 const TUint8* start_of_frame = frame_ptr; |
|
197 TUint32 txFrameHdrAndFixedPartLen ( 0 ); |
|
198 // construct auth message seq. number 3 |
|
199 |
|
200 if ( aCtxImpl.HtSupportedByNw() && aCtxImpl.QosEnabled() ) |
|
201 { |
|
202 // set our seq. nbr in next authenticate Tx-frame |
|
203 aCtxImpl.GetHtAuthenticationFrame().IncrementSeqNmbr(); |
|
204 |
|
205 // set the WEP bit, as that is the only thing that triggers |
|
206 // the ecryption engine. Don't worry about clearing it here |
|
207 // because we do it in WlanDot11AuthenticatePending::Entry() |
|
208 aCtxImpl.GetHtAuthenticationFrame().SetWepBit(); |
|
209 |
|
210 OsTracePrint( KUmacAuth, (TUint8*)("UMAC: Algorithm number: %d"), |
|
211 aCtxImpl.GetHtAuthenticationFrame().GetAlgorithmNumber()); |
|
212 OsTracePrint( KUmacAuth, (TUint8*)("UMAC: Sequence number: %d"), |
|
213 aCtxImpl.GetHtAuthenticationFrame().GetSeqNmbr()); |
|
214 OsTracePrint( KUmacAuth, (TUint8*)("UMAC: Status code: %d"), |
|
215 aCtxImpl.GetHtAuthenticationFrame().GetStatusCode()); |
|
216 |
|
217 // copy the dot11 authentication frame header to tx buffer |
|
218 os_memcpy( frame_ptr, |
|
219 &(aCtxImpl.GetHtAuthenticationFrame().iHeader), |
|
220 sizeof( aCtxImpl.GetHtAuthenticationFrame().iHeader) ); |
|
221 |
|
222 // adjust to end of copy |
|
223 frame_ptr |
|
224 += sizeof( aCtxImpl.GetHtAuthenticationFrame().iHeader ); |
|
225 |
|
226 txFrameHdrAndFixedPartLen = sizeof( SHtAuthenticationFrame ); |
|
227 } |
|
228 else |
|
229 { |
|
230 // set our seq. nbr in next authenticate Tx-frame |
|
231 aCtxImpl.GetAuthenticationFrame().IncrementSeqNmbr(); |
|
232 |
|
233 // set the WEP bit, as that is the only thing that triggers |
|
234 // the ecryption engine. Don't worry about clearing it here |
|
235 // because we do it in WlanDot11AuthenticatePending::Entry() |
|
236 aCtxImpl.GetAuthenticationFrame().SetWepBit(); |
|
237 |
|
238 OsTracePrint( KUmacAuth, (TUint8*)("UMAC: Algorithm number: %d"), |
|
239 aCtxImpl.GetAuthenticationFrame().GetAlgorithmNumber()); |
|
240 OsTracePrint( KUmacAuth, (TUint8*)("UMAC: Sequence number: %d"), |
|
241 aCtxImpl.GetAuthenticationFrame().GetSeqNmbr()); |
|
242 OsTracePrint( KUmacAuth, (TUint8*)("UMAC: Status code: %d"), |
|
243 aCtxImpl.GetAuthenticationFrame().GetStatusCode()); |
|
244 |
|
245 // copy the dot11 authentication frame header to tx buffer |
|
246 os_memcpy( frame_ptr, |
|
247 &(aCtxImpl.GetAuthenticationFrame().iHeader), |
|
248 sizeof( aCtxImpl.GetAuthenticationFrame().iHeader) ); |
|
249 |
|
250 // adjust to end of copy |
|
251 frame_ptr |
|
252 += sizeof( aCtxImpl.GetAuthenticationFrame().iHeader ); |
|
253 |
|
254 txFrameHdrAndFixedPartLen = sizeof( SAuthenticationFrame ); |
|
255 } |
|
256 |
|
257 // set the WEP IV field |
|
258 // do a 16-bit fill |
|
259 const TUint16 fill_value( 0 ); |
|
260 fill( |
|
261 reinterpret_cast<TUint16*>(frame_ptr), |
|
262 ( reinterpret_cast<TUint16*>(frame_ptr) ) |
|
263 + ( KWepIVLength / sizeof( fill_value ) ), |
|
264 fill_value ); |
|
265 |
|
266 // adjust to begin of the authentication frame fixed fields |
|
267 frame_ptr += KWepIVLength; |
|
268 |
|
269 if ( aCtxImpl.HtSupportedByNw() ) |
|
270 { |
|
271 // copy authentication frame fixed fields after WEP IV |
|
272 os_memcpy( |
|
273 frame_ptr, |
|
274 &(aCtxImpl.GetHtAuthenticationFrame().iAuthenticationFields), |
|
275 sizeof( |
|
276 aCtxImpl.GetHtAuthenticationFrame().iAuthenticationFields) ); |
|
277 |
|
278 // adjust to end of copy |
|
279 frame_ptr += sizeof( |
|
280 aCtxImpl.GetHtAuthenticationFrame().iAuthenticationFields ); |
|
281 |
|
282 // copy challenge text from Rx-buffer to Tx-buffer |
|
283 |
|
284 const TUint KRxFramehdrAndFixedPartLen = |
|
285 HtcFieldPresent( |
|
286 aCtxImpl, |
|
287 iLatestRxAuthRespPtr, |
|
288 iLatestRxAuthRespFlags ) ? |
|
289 sizeof( SHtAuthenticationFrame ) : |
|
290 sizeof( SAuthenticationFrame ); |
|
291 os_memcpy( frame_ptr, |
|
292 iLatestRxAuthRespPtr + KRxFramehdrAndFixedPartLen, |
|
293 KChallengeTextLength + KInfoElementHeaderLength ); |
|
294 } |
|
295 else |
|
296 { |
|
297 // copy authentication frame fixed fields after WEP IV |
|
298 os_memcpy( |
|
299 frame_ptr, |
|
300 &(aCtxImpl.GetAuthenticationFrame().iAuthenticationFields), |
|
301 sizeof( |
|
302 aCtxImpl.GetAuthenticationFrame().iAuthenticationFields) ); |
|
303 |
|
304 // adjust to end of copy |
|
305 frame_ptr += sizeof( |
|
306 aCtxImpl.GetAuthenticationFrame().iAuthenticationFields ); |
|
307 |
|
308 // copy challenge text from Rx-buffer to Tx-buffer |
|
309 os_memcpy( frame_ptr, |
|
310 iLatestRxAuthRespPtr + sizeof( SAuthenticationFrame ), |
|
311 KChallengeTextLength + KInfoElementHeaderLength ); |
|
312 } |
|
313 |
|
314 // trace the frame critter |
|
315 OsTracePrint( KUmacAuth, (TUint8*)("UMAC: dot11 authenticate frame tx:"), |
|
316 *(reinterpret_cast<const Sdot11MacHeader*>(start_of_frame)) ); |
|
317 |
|
318 const WHA::TQueueId queue_id |
|
319 = QueueId( aCtxImpl, start_of_frame ); |
|
320 |
|
321 // push the frame to packet scheduler for transmission |
|
322 status = aCtxImpl.PushPacketToPacketScheduler( |
|
323 start_of_frame, |
|
324 txFrameHdrAndFixedPartLen |
|
325 + KChallengeTextLength |
|
326 + KInfoElementHeaderLength |
|
327 + KWepIVLength |
|
328 + KWEPICVLength, |
|
329 queue_id, |
|
330 E802Dot11FrameTypeAuthSeqNmbr3, |
|
331 NULL, |
|
332 EFalse, |
|
333 EFalse, |
|
334 ETrue ); |
|
335 |
|
336 if ( !status ) |
|
337 { |
|
338 // as we came here we did get an internal Tx buffer for the frame |
|
339 // but packet push to scheduler failed. In this case we need to |
|
340 // cancel the internal Tx buffer reservation as we will request it |
|
341 // again when the Packet Scheduler is again ready for packet push |
|
342 aCtxImpl.MarkInternalTxBufFree(); |
|
343 } |
|
344 } |
|
345 else |
|
346 { |
|
347 // we didn't get a Tx buffer => frame not sent. EFalse will be returned |
|
348 // to indicate that |
|
349 OsTracePrint( KUmacAuth, (TUint8*) |
|
350 ("UMAC: WlanDot11SharedAuthPending::SendAuthSeqNbr3Frame: no internal Tx buffer available") ); |
|
351 } |
|
352 |
|
353 return status; |
|
354 } |
|
355 |
|
356 // ----------------------------------------------------------------------------- |
|
357 // If we land here it means that we have received a frame of somekind |
|
358 // with a success status |
|
359 // ----------------------------------------------------------------------------- |
|
360 // |
|
361 void WlanDot11SharedAuthPending::OnReceiveFrameSuccess( |
|
362 WlanContextImpl& aCtxImpl, |
|
363 const void* aFrame, |
|
364 TUint16 /*aLength*/, |
|
365 WHA::TRcpi /*aRcpi*/, |
|
366 TUint32 aFlags, |
|
367 TUint8* /*aBuffer*/ ) |
|
368 { |
|
369 // receive success |
|
370 // parse frame in order to determine is it what we desire |
|
371 const SManagementFrameHeader* frame_hdr |
|
372 = static_cast<const SManagementFrameHeader*>(aFrame); |
|
373 |
|
374 TBool type_match( EFalse ); |
|
375 |
|
376 iFlags &= ~KAuthReceived; |
|
377 iFlags &= ~KAuthSuccess; |
|
378 |
|
379 if (// can we accept this frame |
|
380 // is this a management type + authentication subtype frame |
|
381 IsRequestedFrameType( |
|
382 frame_hdr->iFrameControl.iType, |
|
383 E802Dot11FrameTypeAuthentication, type_match ) |
|
384 // AND our MAC address is DA |
|
385 && (frame_hdr->iDA == aCtxImpl.iWlanMib.dot11StationId) |
|
386 // AND we are in correct state |
|
387 && ( iState == EWAIT4AUTHRESPONSE ) |
|
388 ) |
|
389 { |
|
390 |
|
391 // this is a valid authentication frame targeted to us |
|
392 // mark it so |
|
393 iFlags |= KAuthReceived; |
|
394 |
|
395 // cancel authentication timer |
|
396 aCtxImpl.CancelTimer(); |
|
397 |
|
398 // at this point we don't know is this a authentication success |
|
399 // or failure scenario for this frame exchange |
|
400 |
|
401 if ( ResolveAuthMessage( |
|
402 aCtxImpl, |
|
403 K802Dot11AuthModeShared, |
|
404 aFrame, |
|
405 aFlags ) ) |
|
406 { |
|
407 // authentication frame exchange was a success |
|
408 // mark it also |
|
409 iFlags |= KAuthSuccess; |
|
410 // store pointer to the received frame. We need it to extract |
|
411 // the challenge text from the frame |
|
412 iLatestRxAuthRespPtr = reinterpret_cast<const TUint8*>(aFrame); |
|
413 // store also its receive flags for the same purpose |
|
414 iLatestRxAuthRespFlags = aFlags; |
|
415 |
|
416 OsTracePrint( KUmacAuth, (TUint8*) |
|
417 ("UMAC: dot11-sharedauthpending * authentication frame exchange success")); |
|
418 OsTracePrint( KUmacAuth, (TUint8*)("UMAC: sequence number expected: %d"), |
|
419 aCtxImpl.GetAuthSeqNmbrExpected()); |
|
420 |
|
421 if ( !((aCtxImpl.GetAuthSeqNmbrExpected() |
|
422 == E802Dot11AuthenticationSeqNmbr2) |
|
423 || (aCtxImpl.GetAuthSeqNmbrExpected() |
|
424 == E802Dot11AuthenticationSeqNmbr4 )) |
|
425 ) |
|
426 { |
|
427 // catch a programming error |
|
428 OsTracePrint( KErrorLevel, |
|
429 (TUint8*)("UMAC: sequence number expected"), |
|
430 aCtxImpl.GetAuthSeqNmbrExpected()); |
|
431 OsAssert( (TUint8*)("UMAC: panic"), |
|
432 (TUint8*)(WLAN_FILE), __LINE__ ); |
|
433 } |
|
434 } |
|
435 else |
|
436 { |
|
437 // authentication frame exchange was a failure |
|
438 |
|
439 OsTracePrint( KUmacAuth, (TUint8*) |
|
440 ("UMAC: dot11-sharedauthpending * authentication failure")); |
|
441 OsTracePrint( KUmacAuth, (TUint8*) |
|
442 ("UMAC: sequence number expected: %d"), |
|
443 aCtxImpl.GetAuthSeqNmbrExpected()); |
|
444 |
|
445 // authentication response message was NOT valid |
|
446 // lets's see why that's the case |
|
447 const SAuthenticationFixedFields* auth_fields |
|
448 = reinterpret_cast<const SAuthenticationFixedFields*> |
|
449 (reinterpret_cast<const TUint8*>(aFrame) + |
|
450 sizeof( SManagementFrameHeader )); |
|
451 |
|
452 OsTracePrint( KWarningLevel | KUmacAuth, (TUint8*) |
|
453 ("UMAC: dot11-sharedauthpending * authentication failure") ); |
|
454 OsTracePrint( KWarningLevel | KUmacAuth, (TUint8*) |
|
455 ("UMAC: authentication status code: %d"), |
|
456 auth_fields->StatusCode() ); |
|
457 |
|
458 // set the completion (error) code value returned to user mode |
|
459 // as the dot11idle state does the OID completion in this case |
|
460 if ( auth_fields->StatusCode() == E802Dot11StatusSuccess ) |
|
461 { |
|
462 // network returned success code but still an error in the |
|
463 // authentication sequence has occurred. |
|
464 // Either an authentication frame was received out of |
|
465 // sequence or the algorithm number wasn't the expected one |
|
466 aCtxImpl.iStates.iIdleState.Set( KErrGeneral ); |
|
467 } |
|
468 else |
|
469 { |
|
470 // complete with the network returned error code |
|
471 aCtxImpl.iStates.iIdleState.Set( auth_fields->StatusCode() ); |
|
472 } |
|
473 } |
|
474 } |
|
475 else |
|
476 { |
|
477 // incorrect frame type |
|
478 // or we are not in correct state |
|
479 // so we shall discard its processing |
|
480 } |
|
481 |
|
482 if ( iFlags & KAuthReceived ) |
|
483 { |
|
484 // authentication response was received |
|
485 // either success or failure |
|
486 // we don't really care in this state |
|
487 |
|
488 Fsm( aCtxImpl, ERXAUTHRESPONSE ); |
|
489 } |
|
490 } |