|
1 /* |
|
2 * Copyright (c) 2003 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 "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: Handler for Wimlib request for SIM file reading. Calls |
|
15 * services from CustomAPI to read file and returns read file |
|
16 * to WIMI (and Wimlib) |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 |
|
22 // INCLUDE FILES |
|
23 #include "WimSimFileHandler.h" |
|
24 #include "Wimi.h" // WIMI |
|
25 #include "WimTrace.h" |
|
26 #include <mmtsy_names.h> // TSY and Phone name |
|
27 |
|
28 |
|
29 // ============================ MEMBER FUNCTIONS =============================== |
|
30 |
|
31 // ----------------------------------------------------------------------------- |
|
32 // CWimSimFileHandler::CWimSignTextHandler |
|
33 // C++ default constructor can NOT contain any code, that |
|
34 // might leave. |
|
35 // ----------------------------------------------------------------------------- |
|
36 // |
|
37 CWimSimFileHandler::CWimSimFileHandler() : CActive( EPriorityStandard ) |
|
38 { |
|
39 _WIMTRACE(_L("WIM | WIMServer | CWimSimFileHandler::CWimSimFileHandler | Begin")); |
|
40 } |
|
41 |
|
42 // ----------------------------------------------------------------------------- |
|
43 // CWimSimFileHandler::ConstructL |
|
44 // Symbian 2nd phase constructor can leave. |
|
45 // ----------------------------------------------------------------------------- |
|
46 // |
|
47 void CWimSimFileHandler::ConstructL() |
|
48 { |
|
49 _WIMTRACE(_L("WIM | WIMServer | CWimSimFileHandler::ConstructL | Begin")); |
|
50 CActiveScheduler::Add( this ); |
|
51 |
|
52 //Create new CustomAPI instance |
|
53 iCustomApi = new( ELeave ) RMmCustomAPI; |
|
54 OpenCustomApiL(); // Open connection to CustomAPI |
|
55 } |
|
56 |
|
57 // ----------------------------------------------------------------------------- |
|
58 // CWimSimFileHandler::NewL |
|
59 // Two-phased constructor. |
|
60 // ----------------------------------------------------------------------------- |
|
61 // |
|
62 CWimSimFileHandler* CWimSimFileHandler::NewL() |
|
63 { |
|
64 _WIMTRACE(_L("WIM | WIMServer | CWimSimFileHandler::NewL | Begin")); |
|
65 CWimSimFileHandler* self = new( ELeave ) CWimSimFileHandler; |
|
66 |
|
67 CleanupStack::PushL( self ); |
|
68 self->ConstructL(); |
|
69 CleanupStack::Pop( self ); |
|
70 _WIMTRACE(_L("WIM | WIMServer | CWimSimFileHandler::NewL | End")); |
|
71 return self; |
|
72 } |
|
73 |
|
74 // Destructor |
|
75 CWimSimFileHandler::~CWimSimFileHandler() |
|
76 { |
|
77 _WIMTRACE(_L("WIM | WIMServer | CWimSimFileHandler::~CWimSimFileHandler | Begin")); |
|
78 if ( iCustomApi ) |
|
79 { |
|
80 iCustomApi->Close(); |
|
81 } |
|
82 if ( iEtelServer ) |
|
83 { |
|
84 iEtelServer->Close(); |
|
85 } |
|
86 delete iCustomApi; |
|
87 delete iEtelServer; |
|
88 Cancel(); |
|
89 delete iResponseBytesBuf; |
|
90 delete iResponseBytesPtr; |
|
91 _WIMTRACE(_L("WIM | WIMServer | CWimSimFileHandler::~CWimSimFileHandler | End")); |
|
92 } |
|
93 |
|
94 // ----------------------------------------------------------------------------- |
|
95 // CWimSimFileHandler::OpenCustomApiL |
|
96 // Open CustomAPI for communication |
|
97 // ----------------------------------------------------------------------------- |
|
98 // |
|
99 void CWimSimFileHandler::OpenCustomApiL() |
|
100 { |
|
101 _WIMTRACE(_L("WIM | WIMServer | CWimSimFileHandler::OpenCustomApiL | Begin")); |
|
102 iEtelServer = new( ELeave ) RTelServer(); |
|
103 |
|
104 RMobilePhone phone; |
|
105 |
|
106 // Connect to the Etel server. |
|
107 TInt ret = iEtelServer->Connect(); |
|
108 |
|
109 if ( ret != KErrNone ) |
|
110 { |
|
111 _WIMTRACE2(_L("WIM | WIMServer | CWimSimFileHandler::OpenCustomApiL | Connection to etel server failed: %d"), ret); |
|
112 User::Leave( ret ); |
|
113 } |
|
114 |
|
115 // Load phone module. |
|
116 ret = iEtelServer->LoadPhoneModule( KMmTsyModuleName ); |
|
117 |
|
118 if ( ret != KErrNone ) |
|
119 { |
|
120 _WIMTRACE2(_L("WIM | WIMServer | CWimSimFileHandler::OpenCustomApiL | loading phone module failed: %d"), ret); |
|
121 User::Leave( ret ); |
|
122 } |
|
123 |
|
124 // Open phone |
|
125 ret = phone.Open( *iEtelServer, KMmTsyPhoneName ); |
|
126 |
|
127 if ( ret != KErrNone ) |
|
128 { |
|
129 _WIMTRACE2(_L("WIM | WIMServer | CWimSimFileHandler::OpenCustomApiL | phone.Open failed: %d"), ret); |
|
130 User::Leave( ret ); |
|
131 } |
|
132 |
|
133 // Open new CustomAPI session for phone |
|
134 ret = iCustomApi->Open( phone ); |
|
135 |
|
136 phone.Close(); // Close phone |
|
137 |
|
138 if ( ret != KErrNone ) |
|
139 { |
|
140 _WIMTRACE2(_L("WIM | WIMServer | CWimSimFileHandler::OpenCustomApiL | iCustomApi->Open failed: %d"), ret); |
|
141 User::Leave( ret ); |
|
142 } |
|
143 } |
|
144 |
|
145 // ----------------------------------------------------------------------------- |
|
146 // CWimSimFileHandler::ReadSimFileL |
|
147 // Read SIM file using CustomAPI's ReadSimFile() method. |
|
148 // ----------------------------------------------------------------------------- |
|
149 // |
|
150 void CWimSimFileHandler::ReadSimFileL( |
|
151 TUint8 aReader, |
|
152 const TDes8& aPath, |
|
153 TUint16 aOffset, |
|
154 TUint16 aSize ) |
|
155 { |
|
156 _WIMTRACE(_L("WIM | WIMServer | CWimSimFileHandler::ReadSimFileL | Begin")); |
|
157 |
|
158 iReaderNumber = aReader; |
|
159 |
|
160 TInt size; |
|
161 if ( aSize == 0 ) // Read whole file |
|
162 { |
|
163 size = KMaxSimFileSize; |
|
164 } |
|
165 else |
|
166 { |
|
167 // If size is bigger than maximum file size declared in header file use |
|
168 // declared max size |
|
169 if ( aSize > KMaxSimFileSize ) |
|
170 { |
|
171 size = KMaxSimFileSize; |
|
172 } |
|
173 else |
|
174 { |
|
175 size = aSize; |
|
176 } |
|
177 } |
|
178 |
|
179 iSimFileInfo.iPath = aPath; |
|
180 iSimFileInfo.iOffSet = aOffset; |
|
181 iSimFileInfo.iSize = ( TUint16 )size; |
|
182 |
|
183 RMmCustomAPI::TSimFileInfoPckg simFileInfoPckg( iSimFileInfo ); |
|
184 |
|
185 iResponseBytesBuf = HBufC8::NewL( size ); |
|
186 iResponseBytesPtr = new( ELeave ) TPtr8( NULL, 0, size ); |
|
187 iResponseBytesPtr->Set( iResponseBytesBuf->Des() ); |
|
188 |
|
189 iStatus = KRequestPending; |
|
190 |
|
191 _WIMTRACE9(_L("WIM | WIMServer | CWimSimFileHandler::ReadSimFileL | Path = %02x%02x %02x%02x %02x%02x %02x%02x "), |
|
192 iSimFileInfo.iPath[0], iSimFileInfo.iPath[1], iSimFileInfo.iPath[2], iSimFileInfo.iPath[3], |
|
193 iSimFileInfo.iPath[4], iSimFileInfo.iPath[5], iSimFileInfo.iPath[6], iSimFileInfo.iPath[7] ); |
|
194 |
|
195 _WIMTRACE2(_L("WIM | WIMServer | CWimSimFileHandler::ReadSimFileL | Offset = 0x%04x"), iSimFileInfo.iOffSet ); |
|
196 |
|
197 iCustomApi->ReadSimFile( iStatus, simFileInfoPckg, *iResponseBytesPtr ); |
|
198 |
|
199 SetActiveAndWait(); // Wait request to be completed |
|
200 |
|
201 _WIMTRACE(_L("WIM | WIMServer | CWimSimFileHandler::ReadSimFileL | End")); |
|
202 } |
|
203 |
|
204 // ----------------------------------------------------------------------------- |
|
205 // CWimSimFileHandler::FileReceivedL |
|
206 // Handle received file |
|
207 // ----------------------------------------------------------------------------- |
|
208 // |
|
209 void CWimSimFileHandler::FileReceived() |
|
210 { |
|
211 _WIMTRACE2(_L("WIM | WIMServer | CWimSimFileHandler::FileReceived | Begin, error: %d"), iStatus.Int()); |
|
212 WIMI_BinData_t responseBytes; |
|
213 |
|
214 TInt error = iStatus.Int(); |
|
215 TUint8 status; |
|
216 |
|
217 switch ( error ) |
|
218 { |
|
219 case KErrPathNotFound: |
|
220 { |
|
221 _WIMTRACE(_L("WIM | WIMServer | CWimSimFileHandler::FileReceived | File not found")); |
|
222 break; |
|
223 } |
|
224 case KErrNotFound: |
|
225 { |
|
226 _WIMTRACE(_L("WIM | WIMServer | CWimSimFileHandler::FileReceived | No data found from file")); |
|
227 break; |
|
228 } |
|
229 case KErrUnknown: |
|
230 { |
|
231 _WIMTRACE(_L("WIM | WIMServer | CWimSimFileHandler::FileReceived | Unknown error")); |
|
232 break; |
|
233 } |
|
234 default: |
|
235 { |
|
236 _WIMTRACE2(_L("WIM | WIMServer | CWimSimFileHandler::FileReceived | Error: %d"), error); |
|
237 break; |
|
238 } |
|
239 } |
|
240 |
|
241 if ( error != KErrNone ) // Error occurred in SIM file reading |
|
242 { |
|
243 responseBytes.pb_buf = NULL; |
|
244 responseBytes.ui_buf_length = 0; |
|
245 status = WIMI_Err; |
|
246 } |
|
247 else // SIM file read succesfully |
|
248 { |
|
249 responseBytes.pb_buf = ( TUint8* )iResponseBytesPtr->Ptr(); |
|
250 responseBytes.ui_buf_length = ( TUint16 )iResponseBytesPtr->Length(); |
|
251 status = WIMI_Ok; |
|
252 } |
|
253 |
|
254 _WIMTRACE2(_L("WIM | WIMServer | CWimSimFileHandler::FileReceived | FileLength = %d"), responseBytes.ui_buf_length); |
|
255 |
|
256 // Pass data to WIMI |
|
257 WIMI_SIM_ReadFileResp( iReaderNumber, status, &responseBytes ); |
|
258 |
|
259 delete iResponseBytesBuf; |
|
260 iResponseBytesBuf = NULL; |
|
261 delete iResponseBytesPtr; |
|
262 iResponseBytesPtr = NULL; |
|
263 |
|
264 _WIMTRACE(_L("WIM | WIMServer | CWimSimFileHandler::FileReceived | End")); |
|
265 } |
|
266 |
|
267 // ----------------------------------------------------------------------------- |
|
268 // CWimSimFileHandler::RunL |
|
269 // Handle CustomAPI response |
|
270 // ----------------------------------------------------------------------------- |
|
271 // |
|
272 void CWimSimFileHandler::RunL() |
|
273 { |
|
274 _WIMTRACE2(_L("WIM | WIMServer | CWimSimFileHandler::RunL, status: %d"), iStatus.Int()); |
|
275 iWait.AsyncStop(); |
|
276 FileReceived(); |
|
277 } |
|
278 |
|
279 // ----------------------------------------------------------------------------- |
|
280 // CWimSimFileHandler::DoCancel |
|
281 // Cancel asyncronous request |
|
282 // ----------------------------------------------------------------------------- |
|
283 // |
|
284 void CWimSimFileHandler::DoCancel() |
|
285 { |
|
286 _WIMTRACE(_L("WIM | WIMServer | CWimSimFileHandler::DoCancel | Begin")); |
|
287 delete iResponseBytesBuf; |
|
288 iResponseBytesBuf = NULL; |
|
289 delete iResponseBytesPtr; |
|
290 iResponseBytesPtr = NULL; |
|
291 } |
|
292 |
|
293 // ----------------------------------------------------------------------------- |
|
294 // CWimSimFileHandler::SetActiveAndWait |
|
295 // Wait until asynchronous call is completed |
|
296 // ----------------------------------------------------------------------------- |
|
297 // |
|
298 void CWimSimFileHandler::SetActiveAndWait() |
|
299 { |
|
300 _WIMTRACE(_L("WIM | WIMServer | CWimSimFileHandler::SetActiveAndWait | Begin")); |
|
301 SetActive(); |
|
302 iWait.Start(); |
|
303 _WIMTRACE(_L("WIM | WIMServer | CWimSimFileHandler::SetActiveAndWait | End")); |
|
304 } |
|
305 |
|
306 // End of File |