|
1 /* |
|
2 * Copyright (c) 2001-2006 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: EAP and WLAN authentication protocols. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // This is enumeration of EAPOL source code. |
|
20 #if defined(USE_EAP_MINIMUM_RELEASE_TRACES) |
|
21 #undef EAP_FILE_NUMBER_ENUM |
|
22 #define EAP_FILE_NUMBER_ENUM 184 |
|
23 #undef EAP_FILE_NUMBER_DATE |
|
24 #define EAP_FILE_NUMBER_DATE 1127594498 |
|
25 #endif //#if defined(USE_EAP_MINIMUM_RELEASE_TRACES) |
|
26 |
|
27 #include <e32base.h> |
|
28 #include "EapAkaDbUtils.h" |
|
29 #include "EapAkaDbParameterNames.h" |
|
30 #include "EapAkaDbDefaults.h" |
|
31 #include <EapAkaUiConnection.h> |
|
32 #include <EapAkaUiDataConnection.h> |
|
33 #include <EapAkaUiAkaData.h> |
|
34 #include "eap_am_trace_symbian.h" |
|
35 |
|
36 const TUint KMaxSqlQueryLength = 256; |
|
37 |
|
38 CEapAkaUiDataConnection::CEapAkaUiDataConnection(CEapAkaUiConnection * aUiConn) |
|
39 : iIsOpened(EFalse) |
|
40 , iUiConn(aUiConn) |
|
41 , iColSet(NULL) |
|
42 , iDataPtr(NULL) |
|
43 { |
|
44 } |
|
45 |
|
46 |
|
47 CEapAkaUiDataConnection::~CEapAkaUiDataConnection() |
|
48 { |
|
49 if (iUiConn) |
|
50 { |
|
51 Close(); |
|
52 iUiConn = NULL; |
|
53 } |
|
54 } |
|
55 |
|
56 |
|
57 TInt CEapAkaUiDataConnection::Open() |
|
58 { |
|
59 if (iIsOpened) |
|
60 { |
|
61 return KErrAlreadyExists; |
|
62 } |
|
63 |
|
64 TInt err = iUiConn->GetDatabase(iDatabase); |
|
65 if (err != KErrNone) |
|
66 { |
|
67 return err; |
|
68 } |
|
69 |
|
70 iIsOpened = ETrue; |
|
71 return KErrNone; |
|
72 } |
|
73 |
|
74 |
|
75 TInt CEapAkaUiDataConnection::GetData(CEapAkaUiAkaData ** aDataPtr) |
|
76 { |
|
77 if (aDataPtr == NULL) |
|
78 { |
|
79 return KErrArgument; |
|
80 } |
|
81 if (iIsOpened == EFalse) |
|
82 { |
|
83 return KErrSessionClosed; |
|
84 } |
|
85 iDataPtr = new CEapAkaUiAkaData(); |
|
86 if (!iDataPtr) |
|
87 { |
|
88 return KErrNoMemory; |
|
89 } |
|
90 |
|
91 TRAPD(err, FetchDataL()); |
|
92 if (err != KErrNone) |
|
93 { |
|
94 delete iDataPtr; |
|
95 iDataPtr = NULL; |
|
96 |
|
97 delete iColSet; |
|
98 iColSet = NULL; |
|
99 |
|
100 iView.Close(); |
|
101 |
|
102 return err; |
|
103 } |
|
104 |
|
105 *aDataPtr = iDataPtr; |
|
106 |
|
107 return KErrNone; |
|
108 } |
|
109 |
|
110 |
|
111 TInt CEapAkaUiDataConnection::Update() |
|
112 { |
|
113 TRAPD(err, iView.UpdateL()); |
|
114 if (err != KErrNone) |
|
115 { |
|
116 return err; |
|
117 } |
|
118 |
|
119 // Check if length of username and realm are less than the max length possible in DB. |
|
120 if(iDataPtr->GetManualUsername().Length() > KMaxManualUsernameLengthInDB |
|
121 || iDataPtr->GetManualRealm().Length() > KMaxManualRealmLengthInDB) |
|
122 { |
|
123 // Username or realm too long. Can not be stored in DB. |
|
124 EAP_TRACE_DEBUG_SYMBIAN((_L("CEapAkaUiDataConnection::Update: Too long username or realm. Length: UN=%d, Realm=%d\n"), |
|
125 iDataPtr->GetManualUsername().Length(), |
|
126 iDataPtr->GetManualRealm().Length())); |
|
127 |
|
128 return KErrArgument; |
|
129 } |
|
130 |
|
131 TRAP(err, iView.SetColL(iColSet->ColNo(cf_str_EAP_AKA_manual_username_literal), iDataPtr->GetManualUsername())); |
|
132 if (err != KErrNone) |
|
133 { |
|
134 return err; |
|
135 } |
|
136 |
|
137 TRAP(err, iView.SetColL(iColSet->ColNo(cf_str_EAP_AKA_manual_realm_literal), iDataPtr->GetManualRealm())); |
|
138 if (err != KErrNone) |
|
139 { |
|
140 return err; |
|
141 } |
|
142 |
|
143 if (*(iDataPtr->GetUseManualUsername())) |
|
144 { |
|
145 TRAP(err, iView.SetColL(iColSet->ColNo(cf_str_EAP_AKA_use_manual_username_literal), EAKAUseManualUsernameYes)); |
|
146 if (err != KErrNone) |
|
147 { |
|
148 return err; |
|
149 } |
|
150 } |
|
151 else |
|
152 { |
|
153 TRAP(err, iView.SetColL(iColSet->ColNo(cf_str_EAP_AKA_use_manual_username_literal), EAKAUseManualUsernameNo)); |
|
154 if (err != KErrNone) |
|
155 { |
|
156 return err; |
|
157 } |
|
158 } |
|
159 |
|
160 if (*(iDataPtr->GetUseManualRealm())) |
|
161 { |
|
162 TRAP(err, iView.SetColL(iColSet->ColNo(cf_str_EAP_AKA_use_manual_realm_literal), EAKAUseManualRealmYes)); |
|
163 if (err != KErrNone) |
|
164 { |
|
165 return err; |
|
166 } |
|
167 } |
|
168 else |
|
169 { |
|
170 TRAP(err, iView.SetColL(iColSet->ColNo(cf_str_EAP_AKA_use_manual_realm_literal), EAKAUseManualRealmNo)); |
|
171 if (err != KErrNone) |
|
172 { |
|
173 return err; |
|
174 } |
|
175 } |
|
176 |
|
177 // Last full authentication time should be made zero when EAP configurations are modified. |
|
178 // This makes sure that the next authentication with this EAP would be full authentication |
|
179 // instead of reauthentication even if the session is still valid. |
|
180 |
|
181 TRAP(err, iView.SetColL(iColSet->ColNo(KAKALastFullAuthTime), default_FullAuthTime)); |
|
182 if (err != KErrNone) |
|
183 { |
|
184 return err; |
|
185 } |
|
186 |
|
187 EAP_TRACE_DEBUG_SYMBIAN((_L("Session Validity: Resetting Full Auth Time since EAP-AKA settings are modified\n"))); |
|
188 |
|
189 TRAP(err, iView.PutL()); |
|
190 |
|
191 return err; |
|
192 } |
|
193 |
|
194 |
|
195 TInt CEapAkaUiDataConnection::Close() |
|
196 { |
|
197 if (iIsOpened == EFalse) |
|
198 { |
|
199 return KErrNone; |
|
200 } |
|
201 |
|
202 delete iDataPtr; |
|
203 iDataPtr = NULL; |
|
204 |
|
205 delete iColSet; |
|
206 iColSet = NULL; |
|
207 |
|
208 iView.Close(); |
|
209 |
|
210 iUiConn = NULL; |
|
211 |
|
212 return KErrNone; |
|
213 } |
|
214 |
|
215 |
|
216 void CEapAkaUiDataConnection::FetchDataL() |
|
217 { |
|
218 HBufC* buf = HBufC::NewLC(KMaxSqlQueryLength); |
|
219 TPtr sqlStatement = buf->Des(); |
|
220 |
|
221 // Form the query. Query everything. |
|
222 _LIT(KSQLQuery, "SELECT * FROM %S WHERE %S=%d AND %S=%d AND %S=%d"); |
|
223 sqlStatement.Format(KSQLQuery, |
|
224 &KAkaTableName, |
|
225 &KServiceType, |
|
226 iUiConn->GetIndexType(), |
|
227 &KServiceIndex, |
|
228 iUiConn->GetIndex(), |
|
229 &KTunnelingType, |
|
230 iUiConn->GetTunnelingType()); |
|
231 // Evaluate view |
|
232 User::LeaveIfError(iView.Prepare(iDatabase, TDbQuery(sqlStatement))); |
|
233 User::LeaveIfError(iView.EvaluateAll()); |
|
234 // Get the first (and only) row |
|
235 iView.FirstL(); |
|
236 iView.GetL(); |
|
237 // Get column set so we get the correct column numbers |
|
238 delete iColSet; |
|
239 iColSet = NULL; |
|
240 iColSet = iView.ColSetL(); |
|
241 |
|
242 // Start fetching the values |
|
243 |
|
244 // use manual username |
|
245 TUint intValue = iView.ColUint(iColSet->ColNo(cf_str_EAP_AKA_use_manual_username_literal)); |
|
246 if (intValue == 0) |
|
247 { |
|
248 *(iDataPtr->GetUseManualUsername()) = EFalse; |
|
249 } |
|
250 else |
|
251 { |
|
252 *(iDataPtr->GetUseManualUsername()) = ETrue; |
|
253 } |
|
254 |
|
255 // use manual realm |
|
256 intValue = iView.ColUint(iColSet->ColNo(cf_str_EAP_AKA_use_manual_realm_literal)); |
|
257 if (intValue == 0) |
|
258 { |
|
259 *(iDataPtr->GetUseManualRealm()) = EFalse; |
|
260 } |
|
261 else |
|
262 { |
|
263 *(iDataPtr->GetUseManualRealm()) = ETrue; |
|
264 } |
|
265 |
|
266 // manual username |
|
267 iDataPtr->GetManualUsername().Copy(iView.ColDes16(iColSet->ColNo(cf_str_EAP_AKA_manual_username_literal))); |
|
268 |
|
269 // manual realm |
|
270 iDataPtr->GetManualRealm().Copy(iView.ColDes16(iColSet->ColNo(cf_str_EAP_AKA_manual_realm_literal))); |
|
271 |
|
272 CleanupStack::PopAndDestroy(buf); |
|
273 } |