|
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 215 |
|
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 "EapSimDbUtils.h" |
|
29 #include "EapSimDbParameterNames.h" |
|
30 #include "EapSimDbDefaults.h" |
|
31 #include <EapSimUiConnection.h> |
|
32 #include <EapSimUiDataConnection.h> |
|
33 #include <EapSimUiSimData.h> |
|
34 #include "eap_am_trace_symbian.h" |
|
35 |
|
36 const TUint KMaxSqlQueryLength = 256; |
|
37 |
|
38 CEapSimUiDataConnection::CEapSimUiDataConnection(CEapSimUiConnection * aUiConn) |
|
39 : iIsOpened(EFalse) |
|
40 , iUiConn(aUiConn) |
|
41 , iColSet(NULL) |
|
42 , iDataPtr(NULL) |
|
43 { |
|
44 } |
|
45 |
|
46 |
|
47 CEapSimUiDataConnection::~CEapSimUiDataConnection() |
|
48 { |
|
49 if (iUiConn) |
|
50 { |
|
51 Close(); |
|
52 iUiConn = NULL; |
|
53 } |
|
54 } |
|
55 |
|
56 |
|
57 TInt CEapSimUiDataConnection::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 CEapSimUiDataConnection::GetData(CEapSimUiSimData ** aDataPtr) |
|
76 { |
|
77 if (aDataPtr == NULL) |
|
78 { |
|
79 return KErrArgument; |
|
80 } |
|
81 if (iIsOpened == EFalse) |
|
82 { |
|
83 return KErrSessionClosed; |
|
84 } |
|
85 iDataPtr = new CEapSimUiSimData(); |
|
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 CEapSimUiDataConnection::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("CEapSimUiDataConnection::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_GSMSIM_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_GSMSIM_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_GSMSIM_use_manual_username_literal), EGSMSIMUseManualUsernameYes)); |
|
146 if (err != KErrNone) |
|
147 { |
|
148 return err; |
|
149 } |
|
150 } |
|
151 else |
|
152 { |
|
153 TRAP(err, iView.SetColL(iColSet->ColNo(cf_str_EAP_GSMSIM_use_manual_username_literal), EGSMSIMUseManualUsernameNo)); |
|
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_GSMSIM_use_manual_realm_literal), EGSMSIMUseManualRealmYes)); |
|
163 if (err != KErrNone) |
|
164 { |
|
165 return err; |
|
166 } |
|
167 } |
|
168 else |
|
169 { |
|
170 TRAP(err, iView.SetColL(iColSet->ColNo(cf_str_EAP_GSMSIM_use_manual_realm_literal), EGSMSIMUseManualRealmNo)); |
|
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(KGSMSIMLastFullAuthTime), 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-SIM settings are modified\n"))); |
|
188 |
|
189 TRAP(err, iView.PutL()); |
|
190 |
|
191 return err; |
|
192 } |
|
193 |
|
194 |
|
195 TInt CEapSimUiDataConnection::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 return KErrNone; |
|
212 } |
|
213 |
|
214 |
|
215 void CEapSimUiDataConnection::FetchDataL() |
|
216 { |
|
217 HBufC* buf = HBufC::NewLC(KMaxSqlQueryLength); |
|
218 TPtr sqlStatement = buf->Des(); |
|
219 |
|
220 // Form the query. Query everything. |
|
221 _LIT(KSQLQuery, "SELECT * FROM %S WHERE %S=%d AND %S=%d AND %S=%d"); |
|
222 sqlStatement.Format(KSQLQuery, |
|
223 &KSimTableName, |
|
224 &KServiceType, |
|
225 iUiConn->GetIndexType(), |
|
226 &KServiceIndex, |
|
227 iUiConn->GetIndex(), |
|
228 &KTunnelingType, |
|
229 iUiConn->GetTunnelingType()); |
|
230 // Evaluate view |
|
231 User::LeaveIfError(iView.Prepare(iDatabase, TDbQuery(sqlStatement))); |
|
232 User::LeaveIfError(iView.EvaluateAll()); |
|
233 // Get the first (and only) row |
|
234 iView.FirstL(); |
|
235 iView.GetL(); |
|
236 // Get column set so we get the correct column numbers |
|
237 delete iColSet; |
|
238 iColSet = NULL; |
|
239 iColSet = iView.ColSetL(); |
|
240 |
|
241 // Start fetching the values |
|
242 |
|
243 // use manual username |
|
244 TUint intValue = iView.ColUint(iColSet->ColNo(cf_str_EAP_GSMSIM_use_manual_username_literal)); |
|
245 if (intValue == 0) |
|
246 { |
|
247 *(iDataPtr->GetUseManualUsername()) = EFalse; |
|
248 } |
|
249 else |
|
250 { |
|
251 *(iDataPtr->GetUseManualUsername()) = ETrue; |
|
252 } |
|
253 |
|
254 // use manual realm |
|
255 intValue = iView.ColUint(iColSet->ColNo(cf_str_EAP_GSMSIM_use_manual_realm_literal)); |
|
256 if (intValue == 0) |
|
257 { |
|
258 *(iDataPtr->GetUseManualRealm()) = EFalse; |
|
259 } |
|
260 else |
|
261 { |
|
262 *(iDataPtr->GetUseManualRealm()) = ETrue; |
|
263 } |
|
264 |
|
265 // manual username |
|
266 iDataPtr->GetManualUsername().Copy(iView.ColDes16(iColSet->ColNo(cf_str_EAP_GSMSIM_manual_username_literal))); |
|
267 |
|
268 // manual realm |
|
269 iDataPtr->GetManualRealm().Copy(iView.ColDes16(iColSet->ColNo(cf_str_EAP_GSMSIM_manual_realm_literal))); |
|
270 |
|
271 CleanupStack::PopAndDestroy(buf); |
|
272 } |
|
273 |
|
274 // End of file |