1 // Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 /** |
|
17 @file |
|
18 @internalComponent |
|
19 */ |
|
20 |
|
21 #include <c32comm.h> |
|
22 #include <etel.h> |
|
23 #include <wapmessage.h> |
|
24 #include <simtsy.h> |
|
25 #include "WapStackSuiteDefs.h" |
|
26 #include "WapStackSuiteStepBase.h" |
|
27 |
|
28 CWapStackSuiteStepBase::CWapStackSuiteStepBase() : iLenBuffer(0), iLength(iLenBuffer), iRecvBuf(0,0), iRecvHeadersBuf(0,0), iRecvBodyBuf(0,0) |
|
29 { |
|
30 SetTestStepName(KWapWDPStackSuiteLogFile); |
|
31 iSendBuffPtr = NULL; |
|
32 iRecvBuffPtr = NULL; |
|
33 iRecvHeaders = NULL; |
|
34 iRecvBody = NULL; |
|
35 iURI = NULL; |
|
36 iSendHeaders = NULL; |
|
37 iSendBody = NULL; |
|
38 } |
|
39 |
|
40 CWapStackSuiteStepBase::~CWapStackSuiteStepBase() |
|
41 { |
|
42 if(iSendBuffPtr) delete iSendBuffPtr; |
|
43 if(iRecvBuffPtr) delete iRecvBuffPtr; |
|
44 if(iRecvHeaders) delete iRecvHeaders; |
|
45 if(iRecvBody) delete iRecvBody; |
|
46 if(iURI) delete iURI; |
|
47 if(iSendHeaders) delete iSendHeaders; |
|
48 if(iSendBody) delete iSendBody; |
|
49 } |
|
50 |
|
51 TVerdict CWapStackSuiteStepBase::doTestStepPreambleL() |
|
52 /** |
|
53 * @return - TVerdict |
|
54 * Implementation of CTestStep base class virtual |
|
55 * Load serial drivers |
|
56 * Do all initialisation common to derived classes in here. |
|
57 */ |
|
58 { |
|
59 __UHEAP_MARK; |
|
60 TInt err = KErrNone; |
|
61 CActiveScheduler* sheduler; |
|
62 sheduler = new(ELeave) CActiveScheduler; |
|
63 CActiveScheduler::Install(sheduler); |
|
64 SetScheduler(sheduler); |
|
65 |
|
66 iControl = CActiveControl::NewL(this); |
|
67 sheduler->Add(iControl); |
|
68 iStatus = iControl->Status(); |
|
69 |
|
70 |
|
71 err=User::LoadPhysicalDevice(PDD_NAME); |
|
72 if (err!=KErrNone && err!=KErrAlreadyExists) User::Leave(err); |
|
73 |
|
74 err=User::LoadLogicalDevice(LDD_NAME ); |
|
75 if (err!=KErrNone && err!=KErrAlreadyExists) User::Leave(err); |
|
76 |
|
77 TBool startC32 = ETrue; |
|
78 GetBoolFromConfig(ConfigSection(),KWapStartC32, startC32); |
|
79 if(startC32) |
|
80 { |
|
81 _LIT(KPhbkSyncCMI, "phbsync.cmi"); |
|
82 err = StartC32WithCMISuppressions(KPhbkSyncCMI); |
|
83 ERR_PRINTF2(TRefByValue<const TDesC>(_L("Start Comms Process Status = %d\n")), err); |
|
84 if(err!=KErrNone && err!=KErrAlreadyExists) |
|
85 { |
|
86 User::Leave(err); |
|
87 } |
|
88 } |
|
89 |
|
90 LoadConfig(); |
|
91 |
|
92 SetTestStepResult(EPass); |
|
93 return TestStepResult(); |
|
94 } |
|
95 |
|
96 TVerdict CWapStackSuiteStepBase::doTestStepPostambleL() |
|
97 { |
|
98 |
|
99 delete iControl; |
|
100 iControl = NULL; |
|
101 delete Scheduler(); |
|
102 if(iSendBuffPtr) delete iSendBuffPtr; |
|
103 iSendBuffPtr = NULL; |
|
104 if(iRecvBuffPtr) delete iRecvBuffPtr; |
|
105 iRecvBuffPtr = NULL; |
|
106 __UHEAP_MARKEND; |
|
107 return TestStepResult(); |
|
108 } |
|
109 |
|
110 void CWapStackSuiteStepBase::LoadConfig() |
|
111 { |
|
112 TPtrC16 remote_host, local_host; |
|
113 |
|
114 GetIntFromConfig(KWapCommonSec, KWapBearer, (TInt&)iBearer); |
|
115 if(GetStringFromConfig(KWapCommonSec, KWapRemoteHost, remote_host)) |
|
116 { |
|
117 iRemoteHost.Copy(remote_host); |
|
118 } |
|
119 if(GetStringFromConfig(KWapCommonSec, KWapLocalHost, local_host)) |
|
120 { |
|
121 iLocalHost.Copy(local_host); |
|
122 } |
|
123 TInt remote, local, timeOut; |
|
124 if(GetIntFromConfig(KWapCommonSec, KWapRemotePort, remote)) |
|
125 { |
|
126 iRemotePort = static_cast<Wap::TPort>(remote); |
|
127 } |
|
128 if(GetIntFromConfig(KWapCommonSec, KWapLocalPort, local)) |
|
129 { |
|
130 iLocalPort = static_cast<Wap::TPort>(local); |
|
131 } |
|
132 if(GetIntFromConfig(KWapCommonSec,KWapTimeOut, timeOut)) |
|
133 { |
|
134 iTimeout=timeOut; |
|
135 } |
|
136 TInt headerLength, bufLength, bufLen, method; |
|
137 if(GetIntFromConfig(KWapCommonSec,KWapWSPRecvHeaderLength, headerLength)) |
|
138 { |
|
139 iHeaderRecvBufLength=static_cast<TUint16>(headerLength); |
|
140 } |
|
141 if(GetIntFromConfig(KWapCommonSec,KWapWSPRecvBodyLength, bufLength)) |
|
142 { |
|
143 iBodyRecvBufLength=static_cast<TUint16>(bufLength); |
|
144 } |
|
145 if(GetIntFromConfig(KWapCommonSec,KWapWdpBufLength, bufLen)) |
|
146 { |
|
147 iWdpRecvBufLength=static_cast<TUint16>(bufLen); |
|
148 } |
|
149 if(GetIntFromConfig(KWapCommonSec,KWapWSPMethod, method)) |
|
150 { |
|
151 iMethod = static_cast<TUint16>(method); |
|
152 } |
|
153 else |
|
154 { |
|
155 iMethod = 64; // default method GET |
|
156 } |
|
157 GetIntFromConfig(KWapCommonSec, KWapExError, iExError); |
|
158 if(!GetIntFromConfig(KWapCommonSec, KWapRepeat, iRepeat)) |
|
159 { |
|
160 iRepeat = 1; |
|
161 }; |
|
162 |
|
163 GetIntFromConfig(KWapCommonSec, KWapExError2, iExError2); |
|
164 GetBoolFromConfig(KWapCommonSec, KWapUseSIMTSY, iUseSIMTSY); |
|
165 GetBoolFromConfig(KWapCommonSec, KWapDetailedLogging, iDetailedLogging); |
|
166 GetBoolFromConfig(KWapCommonSec, KAwaitLengthCancel, iAwaitLengthCancel); |
|
167 GetBoolFromConfig(KWapCommonSec, KMiddleCancel, iMiddleCancel); |
|
168 GetBoolFromConfig(KWapCommonSec, KMultiReadCancel, iMultiReadCancel); |
|
169 GetBoolFromConfig(KWapCommonSec, KAwaitLengthTwice, iAwaitLengthTwice); |
|
170 GetBoolFromConfig(KWapCommonSec, KWapDelayPortClosure, iDelayPortClosure); |
|
171 GetIntFromConfig(KWapCommonSec,KWapSIMTSYState, iSimTsyState); |
|
172 |
|
173 TInt result; |
|
174 // if using SIMTSY, we need to define the test number property |
|
175 // since we set the test number before loading SIMTSY |
|
176 if (iUseSIMTSY) |
|
177 { |
|
178 result = RProperty::Define(KUidPSSimTsyCategory, KPSSimTsyTestNumber, RProperty::EInt); |
|
179 __ASSERT_ALWAYS(result == KErrNone || result == KErrAlreadyExists,User::Panic(KWapStackSuitePanic, EDataCorrupt)); |
|
180 } |
|
181 |
|
182 // Phone power property, normally defined by UIKON, is not defined by any |
|
183 // startup code in console builds - we're on our own with this one. |
|
184 result = RProperty::Define(KUidSystemCategory, KUidPhonePwr.iUid, RProperty::EInt); |
|
185 __ASSERT_ALWAYS(result == KErrNone || result == KErrAlreadyExists,User::Panic(KWapStackSuitePanic, EDataCorrupt)); |
|
186 |
|
187 } |
|
188 |
|
189 TInt CWapStackSuiteStepBase::CallStateMachine() |
|
190 { |
|
191 return (0); |
|
192 } |
|
193 |
|
194 void CWapStackSuiteStepBase::StartScheduler() |
|
195 { |
|
196 INFO_PRINTF1(_L("Star Scheduler")); |
|
197 CActiveScheduler::Start(); |
|
198 } |
|
199 |
|
200 void CWapStackSuiteStepBase::StopScheduler() |
|
201 { |
|
202 INFO_PRINTF1(_L("Stop Scheduler")); |
|
203 CActiveScheduler::Stop(); |
|
204 } |
|
205 |
|
206 void CWapStackSuiteStepBase::WaitForInitializeL() |
|
207 { |
|
208 _LIT(KMMTSY,"MM"); |
|
209 _LIT(KSIMTSY,"SIM"); |
|
210 |
|
211 TName tsy; |
|
212 |
|
213 if(UseSimTsy()) |
|
214 { |
|
215 tsy=KSIMTSY; |
|
216 } |
|
217 else |
|
218 { |
|
219 tsy = KMMTSY; |
|
220 } |
|
221 |
|
222 RTelServer serverT; |
|
223 User::LeaveIfError(serverT.Connect()); |
|
224 CleanupClosePushL(serverT); |
|
225 User::LeaveIfError(serverT.LoadPhoneModule(tsy)); |
|
226 INFO_PRINTF2(_L("%S TSY loaded"), &tsy); |
|
227 |
|
228 // Find the phone corresponding to this TSY and open a number of handles on it |
|
229 TInt numPhones; |
|
230 User::LeaveIfError(serverT.EnumeratePhones(numPhones)); |
|
231 RPhone phone; |
|
232 while (numPhones--) |
|
233 { |
|
234 TName phoneTsy; |
|
235 User::LeaveIfError(serverT.GetTsyName(numPhones,phoneTsy)); |
|
236 if (phoneTsy.CompareF(tsy)==KErrNone) |
|
237 { |
|
238 RTelServer::TPhoneInfo info; |
|
239 User::LeaveIfError(serverT.GetPhoneInfo(numPhones,info)); |
|
240 User::LeaveIfError(phone.Open(serverT,info.iName)); |
|
241 CleanupClosePushL(phone); |
|
242 const TInt err = phone.Initialise(); |
|
243 User::LeaveIfError(err); |
|
244 CleanupStack::PopAndDestroy(&phone); |
|
245 break; |
|
246 } |
|
247 } |
|
248 CleanupStack::PopAndDestroy(&serverT); |
|
249 } |
|
250 |
|
251 void CWapStackSuiteStepBase::DumpBuf(const TDesC8& aBuf) |
|
252 { |
|
253 if(!DetailedLogging()) return; |
|
254 TBuf16<100> dumpbuf; |
|
255 TInt totLen = aBuf.Length(); |
|
256 |
|
257 INFO_PRINTF1(_L("-------------------------------------------------------------------------")); |
|
258 INFO_PRINTF2(_L("Buffer: %d bytes"), totLen); |
|
259 INFO_PRINTF1(_L("-------------------------------------------------------------------------")); |
|
260 |
|
261 for (TInt i = 0; i < totLen; i += 16) |
|
262 { |
|
263 dumpbuf.FillZ(100); |
|
264 dumpbuf.Zero(); |
|
265 dumpbuf.AppendFormat(_L("%04x "),i); |
|
266 TInt j = 0; |
|
267 TInt thisRow = Min(16,totLen - j - i); |
|
268 for (j = 0; j < 16; j++) |
|
269 { |
|
270 if (j < thisRow) |
|
271 { |
|
272 TText8 chr = aBuf[i + j]; |
|
273 dumpbuf.AppendFormat(_L("%02x "),chr); |
|
274 } |
|
275 else |
|
276 dumpbuf.AppendFormat(_L(" ")); |
|
277 } |
|
278 dumpbuf.AppendFormat(_L(" ")); |
|
279 for (j = 0; j < thisRow; j++) |
|
280 { |
|
281 TText8 chr = aBuf[i + j]; |
|
282 TChar c(chr); |
|
283 if (!c.IsPrint()) |
|
284 { |
|
285 chr='.'; |
|
286 } |
|
287 // NOTE: "<" & ">" are HTML tags (change to "[" & "]") |
|
288 if((chr == '<') || (chr == '>')) |
|
289 { |
|
290 chr+=31; |
|
291 } |
|
292 dumpbuf.AppendFormat(_L("%c"),chr); |
|
293 } |
|
294 INFO_PRINTF2(_L("%s"), dumpbuf.Ptr()); |
|
295 } |
|
296 INFO_PRINTF1(_L("-------------------------------------------------------------------------")); |
|
297 } |
|
298 |
|
299 void CWapStackSuiteStepBase::ShowConnectionInfo() |
|
300 { |
|
301 if(!DetailedLogging()) return; |
|
302 |
|
303 TBuf16<WAP_MAX_HOST_NAME> host; |
|
304 TBuf16<100> infostr; |
|
305 |
|
306 INFO_PRINTF1(_L("-------------------------------------------------------------------------")); |
|
307 INFO_PRINTF1(_L("Connection Info:")); |
|
308 INFO_PRINTF1(_L("-------------------------------------------------------------------------")); |
|
309 |
|
310 infostr.FillZ(100); |
|
311 switch(iBearer) |
|
312 { |
|
313 case Wap::EAll: infostr.Copy(_L("EAll")); |
|
314 break; |
|
315 case Wap::EIP: infostr.Copy(_L("EIP")); |
|
316 break; |
|
317 case Wap::ESMS7: infostr.Copy(_L("ESMS7")); |
|
318 break; |
|
319 case Wap::ESMS: infostr.Copy(_L("ESMS")); |
|
320 break; |
|
321 case Wap::EWAPSMS7: infostr.Copy(_L("EWAPSMS7")); |
|
322 break; |
|
323 case Wap::EWAPSMS: infostr.Copy(_L("EWAPSMS")); |
|
324 break; |
|
325 default: |
|
326 break; |
|
327 } |
|
328 |
|
329 INFO_PRINTF2(_L("Bearer : %s"), infostr.Ptr()); |
|
330 host.FillZ(WAP_MAX_HOST_NAME); |
|
331 host.Copy(iRemoteHost); |
|
332 INFO_PRINTF2(_L("Remote Host : %s"), host.Ptr()); |
|
333 INFO_PRINTF2(_L("Remote Port : %d"),iRemotePort); |
|
334 host.FillZ(100); |
|
335 host.Copy(iLocalHost); |
|
336 INFO_PRINTF2(_L("Local Host : %s"), host.Ptr()); |
|
337 INFO_PRINTF2(_L("Local Port : %d"), iLocalPort); |
|
338 infostr.FillZ(100); |
|
339 switch(iSecure) |
|
340 { |
|
341 case ETrue: infostr.Copy(_L("TRUE")); |
|
342 break; |
|
343 case EFalse: infostr.Copy(_L("FALSE")); |
|
344 break; |
|
345 default: |
|
346 break; |
|
347 } |
|
348 INFO_PRINTF2(_L("Secure : %s"), infostr.Ptr()); |
|
349 infostr.FillZ(100); |
|
350 switch(iReconnect) |
|
351 { |
|
352 case ETrue: infostr.Copy(_L("TRUE")); |
|
353 break; |
|
354 case EFalse: infostr.Copy(_L("FALSE")); |
|
355 break; |
|
356 default: |
|
357 break; |
|
358 } |
|
359 INFO_PRINTF2(_L("Timeout : %d"), iTimeout); |
|
360 INFO_PRINTF2(_L("Reconnect : %s"), infostr.Ptr()); |
|
361 INFO_PRINTF2(_L("ExitCode : %d"), iExError); |
|
362 INFO_PRINTF2(_L("Repeat : %d"), iRepeat); |
|
363 |
|
364 INFO_PRINTF1(_L("-------------------------------------------------------------------------")); |
|
365 } |
|
366 |
|
367 /** |
|
368 Active controller |
|
369 */ |
|
370 CActiveControl* CActiveControl::NewL(MControlNotify* aControl) |
|
371 { |
|
372 CActiveControl* self = new(ELeave) CActiveControl(aControl); |
|
373 CleanupStack::PushL(self); |
|
374 self->ConstructL(); |
|
375 CleanupStack::Pop(); |
|
376 return self; |
|
377 } |
|
378 |
|
379 void CActiveControl::ConstructL() |
|
380 { |
|
381 } |
|
382 |
|
383 CActiveControl::CActiveControl(MControlNotify* aControl) |
|
384 : CActive(EPriorityStandard) |
|
385 { |
|
386 iControl = aControl; |
|
387 } |
|
388 |
|
389 CActiveControl::~CActiveControl() |
|
390 { |
|
391 } |
|
392 |
|
393 void CActiveControl::ReStart() |
|
394 { |
|
395 TRequestStatus* status = &iStatus; |
|
396 SetActive(); |
|
397 User::RequestComplete(status, KErrNone); |
|
398 } |
|
399 |
|
400 void CActiveControl::RunL() |
|
401 { |
|
402 if(iControl->CallStateMachine()) |
|
403 { |
|
404 SetActive(); |
|
405 } |
|
406 } |
|
407 |
|
408 void CActiveControl::DoCancel() |
|
409 { |
|
410 } |
|