|
1 /* |
|
2 * Copyright (c) 2005-2007 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 WlanDot11OpenAuthPending class |
|
15 * |
|
16 */ |
|
17 |
|
18 /* |
|
19 * %version: 23 % |
|
20 */ |
|
21 |
|
22 #include "config.h" |
|
23 #include "UmacDot11OpenAuthPending.h" |
|
24 #include "UmacContextImpl.h" |
|
25 |
|
26 #ifndef NDEBUG |
|
27 const TInt8 WlanDot11OpenAuthPending::iName[] = "dot11-openauthpending"; |
|
28 #endif // !NDEBUG |
|
29 |
|
30 // ================= MEMBER FUNCTIONS ======================= |
|
31 |
|
32 // ----------------------------------------------------------------------------- |
|
33 // |
|
34 // ----------------------------------------------------------------------------- |
|
35 // |
|
36 #ifndef NDEBUG |
|
37 const TInt8* WlanDot11OpenAuthPending::GetStateName( |
|
38 TUint8& aLength ) const |
|
39 { |
|
40 aLength = sizeof( iName ); |
|
41 return iName; |
|
42 } |
|
43 #endif |
|
44 |
|
45 // ----------------------------------------------------------------------------- |
|
46 // Handler for state entry event. |
|
47 // ----------------------------------------------------------------------------- |
|
48 // |
|
49 void WlanDot11OpenAuthPending::OnStateEntryEvent( |
|
50 WlanContextImpl& aCtxImpl ) |
|
51 { |
|
52 switch ( iState ) |
|
53 { |
|
54 case EINIT: |
|
55 // do all the synchronous |
|
56 // composite state entry actions |
|
57 StateEntryActions( aCtxImpl ); |
|
58 // continue with the state traversal |
|
59 Fsm( aCtxImpl, ECONTINUE ); |
|
60 break; |
|
61 case ETXAUTHFRAME: |
|
62 // send the authenticate frame |
|
63 if ( !SendAuthSeqNbr1Frame( aCtxImpl ) ) |
|
64 { |
|
65 // tx of dot11-authenticate frame failed |
|
66 // because packet scheduler was full |
|
67 // or because we didn't get a Tx buffer |
|
68 // so we enter to a wait state |
|
69 Fsm( aCtxImpl, ETX_SCHEDULER_FULL ); |
|
70 } |
|
71 break; |
|
72 case ECONTINUEDOT11TRAVERSE: |
|
73 ContinueDot11StateTraversal( aCtxImpl ); |
|
74 break; |
|
75 case EWAIT4AUTHRESPONSE: |
|
76 // start a timer to wait for the response frame |
|
77 StartAuthenticationFrameResponseTimer( aCtxImpl ); |
|
78 break; |
|
79 case EWAIT4PUSHPACKET: |
|
80 // nothing to do here than wait |
|
81 break; |
|
82 default: |
|
83 // catch internal FSM programming error |
|
84 #ifndef NDEBUG |
|
85 OsTracePrint( KErrorLevel, (TUint8*)("UMAC: state:")); |
|
86 OsTracePrint( KErrorLevel, iStateName[iState] ); |
|
87 #endif |
|
88 OsAssert( (TUint8*)("UMAC: panic"), |
|
89 (TUint8*)(WLAN_FILE), __LINE__ ); |
|
90 break; |
|
91 } |
|
92 } |
|
93 |
|
94 // ----------------------------------------------------------------------------- |
|
95 // Handler for rx authentication response event. |
|
96 // ----------------------------------------------------------------------------- |
|
97 // |
|
98 void WlanDot11OpenAuthPending::OnRxAuthResponseEvent( |
|
99 WlanContextImpl& aCtxImpl ) |
|
100 { |
|
101 switch ( iState ) |
|
102 { |
|
103 case EWAIT4AUTHRESPONSE: |
|
104 ChangeInternalState( aCtxImpl, ECONTINUEDOT11TRAVERSE ); |
|
105 break; |
|
106 default: |
|
107 // this means that we have recieved a valid dot11 |
|
108 // authenticate response frame that we are waiting for |
|
109 // but we are not internally in such a state |
|
110 // only feasible situation for this is that |
|
111 // someone has skipped a call to the packet xfer method |
|
112 // that informs of authenticate request frame |
|
113 // xfer to the WLAN device. |
|
114 // other case is that our fsm is totally messed up |
|
115 // so we catch this |
|
116 #ifndef NDEBUG |
|
117 OsTracePrint( KErrorLevel, (TUint8*)("UMAC: state:")); |
|
118 OsTracePrint( KErrorLevel, iStateName[iState] ); |
|
119 #endif |
|
120 OsAssert( (TUint8*)("UMAC: panic"), |
|
121 (TUint8*)(WLAN_FILE), __LINE__ ); |
|
122 break; |
|
123 } |
|
124 } |
|
125 |
|
126 // ----------------------------------------------------------------------------- |
|
127 // set appropriate used algorithm number to authenticate request frame |
|
128 // ----------------------------------------------------------------------------- |
|
129 // |
|
130 void WlanDot11OpenAuthPending::OnSetAlgorithmNumber( |
|
131 WlanContextImpl& aCtxImpl ) |
|
132 { |
|
133 if ( aCtxImpl.HtSupportedByNw() ) |
|
134 { |
|
135 aCtxImpl.GetHtAuthenticationFrame().SetAlgorithmNmbr( |
|
136 aCtxImpl.AuthenticationAlgorithmNumber() ); |
|
137 } |
|
138 else |
|
139 { |
|
140 aCtxImpl.GetAuthenticationFrame().SetAlgorithmNmbr( |
|
141 aCtxImpl.AuthenticationAlgorithmNumber() ); |
|
142 } |
|
143 } |
|
144 |
|
145 // ----------------------------------------------------------------------------- |
|
146 // If we land here it means that we have received a frame of somekind |
|
147 // with a status success |
|
148 // ----------------------------------------------------------------------------- |
|
149 // |
|
150 void WlanDot11OpenAuthPending::OnReceiveFrameSuccess( |
|
151 WlanContextImpl& aCtxImpl, |
|
152 const void* aFrame, |
|
153 TUint16 /*aLength*/, |
|
154 WHA::TRcpi /*aRcpi*/, |
|
155 TUint32 aFlags, |
|
156 TUint8* /*aBuffer*/ ) |
|
157 { |
|
158 // parse frame in order to determine is it what we want |
|
159 const SManagementFrameHeader* frame_hdr |
|
160 = static_cast<const SManagementFrameHeader*>(aFrame); |
|
161 |
|
162 TBool type_match( EFalse ); |
|
163 |
|
164 if ( // can we accept this frame |
|
165 // is this a management type + authentication subtype frame |
|
166 IsRequestedFrameType( |
|
167 frame_hdr->iFrameControl.iType, |
|
168 E802Dot11FrameTypeAuthentication, type_match ) |
|
169 // AND our MAC address is DA |
|
170 && (frame_hdr->iDA == aCtxImpl.iWlanMib.dot11StationId) |
|
171 // AND we are in correct state |
|
172 && ( iState == EWAIT4AUTHRESPONSE ) |
|
173 ) |
|
174 { |
|
175 // cancel authentication frame response timer |
|
176 aCtxImpl.CancelTimer(); |
|
177 |
|
178 iFlags |= KAuthReceived; |
|
179 |
|
180 // we have got a hit...let's proceed |
|
181 // store the used authentication algorithm number |
|
182 // for later use |
|
183 const TUint16 used_auth_algorithm = |
|
184 aCtxImpl.AuthenticationAlgorithmNumber(); |
|
185 |
|
186 // validate the authentication frame |
|
187 if ( ResolveAuthMessage( |
|
188 aCtxImpl, |
|
189 used_auth_algorithm, |
|
190 aFrame, |
|
191 aFlags ) ) |
|
192 { |
|
193 // authentication success |
|
194 OsTracePrint( KUmacAuth, (TUint8*) |
|
195 ("UMAC: dot11-openauthpending * authentication success") ); |
|
196 |
|
197 // mark it also |
|
198 iFlags |= KAuthSuccess; |
|
199 } |
|
200 else |
|
201 { |
|
202 // authentication response message was NOT ok |
|
203 // lets's see why that's the case |
|
204 const SAuthenticationFixedFields* auth_fields |
|
205 = reinterpret_cast<const SAuthenticationFixedFields*> |
|
206 (reinterpret_cast<const TUint8*>(aFrame) + |
|
207 sizeof( SManagementFrameHeader )); |
|
208 |
|
209 TInt completion_code( KErrGeneral ); |
|
210 |
|
211 if ( // is open mode authentication |
|
212 ( auth_fields->AlgorithmNumber() == used_auth_algorithm ) |
|
213 // AND is authentication transaction sequence number expected |
|
214 && ( auth_fields->SequenceNumber() |
|
215 == aCtxImpl.GetAuthSeqNmbrExpected()) |
|
216 ) |
|
217 { |
|
218 OsTracePrint( KWarningLevel | KUmacAuth, (TUint8*) |
|
219 ("UMAC: dot11-openauthpending authentication denied") ); |
|
220 OsTracePrint( KWarningLevel | KUmacAuth, (TUint8*) |
|
221 ("UMAC: status code from frame: %d"), |
|
222 auth_fields->StatusCode() ); |
|
223 |
|
224 if ( auth_fields->StatusCode() == E802Dot11StatusSuccess ) |
|
225 { |
|
226 // catch a internal programming error |
|
227 OsAssert( (TUint8*)("UMAC: panic"), |
|
228 (TUint8*)(WLAN_FILE), __LINE__ ); |
|
229 } |
|
230 |
|
231 // status code was something else than status success |
|
232 completion_code = auth_fields->StatusCode(); |
|
233 } |
|
234 else |
|
235 { |
|
236 // a malformed message, but it is a failure in any case |
|
237 OsTracePrint( KWarningLevel | KUmacAuth, (TUint8*) |
|
238 ("UMAC: dot11-openauthpending authentication failure") ); |
|
239 OsTracePrint( KWarningLevel | KUmacAuth, (TUint8*) |
|
240 ("UMAC: auth message not valid") ); |
|
241 } |
|
242 |
|
243 // set the completion code value returned to user mode |
|
244 // as the dot11idle state does the OID completion in this case |
|
245 aCtxImpl.iStates.iIdleState.Set( completion_code ); |
|
246 } |
|
247 } |
|
248 else // can we accept this frame |
|
249 { |
|
250 // not a valid type of frame |
|
251 // or we are not in correct state |
|
252 // so we shall discard it's processing |
|
253 } |
|
254 |
|
255 if ( iFlags & KAuthReceived ) |
|
256 { |
|
257 // authentication response was received |
|
258 // either success or failure |
|
259 // we don't really care in this state |
|
260 |
|
261 Fsm( aCtxImpl, ERXAUTHRESPONSE ); |
|
262 } |
|
263 } |