|
1 // Copyright (c) 1997-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 // The objects of the class do all work to start & finish PPP session |
|
15 // |
|
16 // |
|
17 |
|
18 #include "DummyAgtRef.h" |
|
19 #include "nifman.h" |
|
20 #include "cdbcols.h" |
|
21 #include "TestMgr.h" |
|
22 #include "dummyprotocol.h" |
|
23 #include "ss_pman.h" |
|
24 |
|
25 CDummyNifAgentRef::CDummyNifAgentRef(const TDesC& aName,CTestMgr& aTheMgr, CTestExecuteLogger& aLogger):iName(aName),iTheMgr(aTheMgr), iLogger(aLogger), |
|
26 iState(EStopped) // When the AgentRef comes up, the NIF is disconnected. |
|
27 { |
|
28 } |
|
29 |
|
30 CDummyNifAgentRef::~CDummyNifAgentRef() |
|
31 { |
|
32 delete ipDummyPrt; |
|
33 DestroyIniReader(); |
|
34 } |
|
35 |
|
36 CDummyNifAgentRef* |
|
37 CDummyNifAgentRef::NewL(const TDesC& aName,CTestMgr& aTheMgr, CTestExecuteLogger& aLogger) |
|
38 { |
|
39 |
|
40 CDummyNifAgentRef* ref = new (ELeave) CDummyNifAgentRef(aName,aTheMgr, aLogger); |
|
41 CleanupStack::PushL(TCleanupItem(CNifFactory::Cleanup, ref)); |
|
42 ref->ConstructL(); |
|
43 CleanupStack::Pop(); |
|
44 return ref; |
|
45 } |
|
46 |
|
47 |
|
48 void CDummyNifAgentRef::ConstructL() |
|
49 { |
|
50 ipDummyPrt=CDummyProtocol::NewL(); |
|
51 CreateIniReader(); |
|
52 } |
|
53 |
|
54 //this member's called when the PPP negotiation is over. |
|
55 void CDummyNifAgentRef::LinkLayerUp() |
|
56 { |
|
57 LOG_INFO_PRINTF1(_L("DummyAgtRef::LinkLayerUp")); |
|
58 |
|
59 iTheMgr.Notify(CTestMgr::ETestFinished); |
|
60 ServiceClosed();//cleanup |
|
61 } |
|
62 |
|
63 TInt CDummyNifAgentRef::Authenticate(TDes& /*aUsername*/, TDes& /*aPassword*/) |
|
64 { |
|
65 //ask the test mgr for authentication information |
|
66 return KErrNone; |
|
67 } |
|
68 // |
|
69 TInt CDummyNifAgentRef::Notification(TNifToAgentEventType /*aEvent*/, void* /*aInfo*/) |
|
70 { |
|
71 //log them all ??? |
|
72 return KErrNone; |
|
73 } |
|
74 |
|
75 // |
|
76 //MNifIfNotify overrides ------------------------------------------------------- |
|
77 // |
|
78 TInt CDummyNifAgentRef::DoReadInt(const TDesC& aField, TUint32& aValue,const RMessagePtr2* /*aMessage*/) |
|
79 { |
|
80 TInt result = KErrNotFound; |
|
81 if (ipIniFileReader !=0) |
|
82 { |
|
83 TInt value=0; |
|
84 if (ipIniFileReader->FindVar(iData.KCommDbSectionName,aField,value)) |
|
85 { |
|
86 aValue=(TInt32)value; |
|
87 result=KErrNone; |
|
88 } |
|
89 } |
|
90 //use hardcoded only if the ini file read or search failed |
|
91 if (KErrNotFound==result) |
|
92 { |
|
93 result=KErrNone; |
|
94 |
|
95 if (TPtrC(KCDTypeNameIfServerMode)==aField) |
|
96 aValue=iData.KPppIsServerMode; |
|
97 else if (TPtrC(iData.KModemCommRoleString)==aField) |
|
98 aValue=iData.KPppCommRole; |
|
99 else if (iData.KIapIdString==aField) |
|
100 aValue=iData.KPppIapId; |
|
101 else |
|
102 result=KErrNotFound; |
|
103 } |
|
104 // |
|
105 LOG_ERR_PRINTF4(_L("--------------- Config param used: %S = %d (err %d)"),&aField,aValue,result); |
|
106 // |
|
107 return result; |
|
108 } |
|
109 |
|
110 TInt CDummyNifAgentRef::DoReadDes(const TDesC& aField, TDes16& aValue,const RMessagePtr2* /*aMessage*/) |
|
111 { |
|
112 TInt result = KErrNotFound; |
|
113 if (ipIniFileReader !=0) |
|
114 { |
|
115 TPtrC value; |
|
116 if (ipIniFileReader->FindVar(iData.KCommDbSectionName,aField,value)) |
|
117 { |
|
118 aValue.Copy(value); |
|
119 result=KErrNone; |
|
120 } |
|
121 } |
|
122 //use hardcoded only if the ini file read or search failed |
|
123 if (KErrNotFound==result) |
|
124 { |
|
125 result=KErrNone; |
|
126 // |
|
127 if (TPtrC(KCDTypeNameRecordName)==aField) |
|
128 aValue=iData.KPppCommdbName; |
|
129 else if (iData.KModemPortString==aField) |
|
130 aValue=iData.KPppPortString; |
|
131 else if (iData.KModemCsyString==aField) |
|
132 aValue=iData.KPppCsyString; |
|
133 else |
|
134 result=KErrNotFound; |
|
135 } |
|
136 // |
|
137 LOG_ERR_PRINTF4(_L("--------------- Config param used: %S = %S (err %d)"),&aField,&aValue,result); |
|
138 // |
|
139 return result; |
|
140 } |
|
141 |
|
142 TInt CDummyNifAgentRef::DoReadBool(const TDesC& aField, TBool& aValue,const RMessagePtr2* /*aMessage*/) |
|
143 { |
|
144 TInt result = KErrNotFound; //optimistic approach |
|
145 if (ipIniFileReader !=0) |
|
146 { |
|
147 TInt value=0; |
|
148 if (ipIniFileReader->FindVar(iData.KCommDbSectionName,aField,value)) |
|
149 { |
|
150 aValue=(value != 0); |
|
151 result=KErrNone; |
|
152 } |
|
153 } |
|
154 //use hardcoded only if the ini file read or search failed |
|
155 if (KErrNotFound==result) |
|
156 { |
|
157 result=KErrNone; |
|
158 |
|
159 if (TPtrC(KCDTypeNameEnableLcpExtensions) == aField) |
|
160 aValue=iData.KPppIsLcpExtEnabled; |
|
161 else if (TPtrC(KCDTypeNameEnableSwComp) == aField) |
|
162 aValue=iData.KPppIsSwCompEnabled; |
|
163 else if (TPtrC(KCDTypeNameIfCallbackEnabled) == aField) |
|
164 aValue=iData.KPppIsCallbackEnabled; |
|
165 else |
|
166 result=KErrNotFound; |
|
167 } |
|
168 // |
|
169 LOG_ERR_PRINTF4(_L("--------------- Config param used: %S = %d (err %d)"),&aField,(TInt)aValue,result); |
|
170 // |
|
171 return result; |
|
172 } |
|
173 // |
|
174 //MNifAgentNotify overrides ------------------------------------------------------- |
|
175 // |
|
176 |
|
177 //Nasty classes to sneak into protected sections |
|
178 class CCheekyNifIfBase:public CNifIfBase |
|
179 { |
|
180 }; |
|
181 |
|
182 class CCheekyNifIfFactory : public CNifIfFactory |
|
183 { |
|
184 public: |
|
185 CNifIfBase* |
|
186 CreateInterfaceL(const TDesC& aName, MNifIfNotify* aNotify){ return NewInterfaceL(aName, aNotify);} |
|
187 }; |
|
188 |
|
189 void CDummyNifAgentRef::ServiceStartedL() |
|
190 { |
|
191 LOG_INFO_PRINTF1(_L("DummyAgtRef::ServiceStartedL")); |
|
192 |
|
193 // load the required interface |
|
194 TInt errCode=KErrNone; |
|
195 //create the interface as nifman does. The code taken from NifMan (with custom error check) |
|
196 TAutoClose<RLibrary> lib; |
|
197 errCode=lib.iObj.Load(iData.KPppNifFileName); |
|
198 if (errCode!=KErrNone) |
|
199 { |
|
200 LOG_ERR_PRINTF2(_L("Can't load tppp.nif (error=%d) -> Leaving"),errCode); |
|
201 User::Leave(errCode); |
|
202 } |
|
203 lib.PushL(); |
|
204 // The Uid check |
|
205 #ifdef _UNICODE |
|
206 TUid uid(TUid::Uid(KUidUnicodeNifmanInterface)); |
|
207 #else |
|
208 TUid uid(TUid::Uid(KUidNifmanInterface)); |
|
209 #endif |
|
210 if(lib.iObj.Type()[1]!=uid) |
|
211 { |
|
212 LOG_INFO_PRINTF1(_L("Wrong UID of ppp.nif -> Leaving")); |
|
213 User::Leave(KErrCorrupt); |
|
214 } |
|
215 //get the entry point |
|
216 typedef CNifFactory* (*TNifFactoryNewL)(); |
|
217 TNifFactoryNewL libEntry=(TNifFactoryNewL)lib.iObj.Lookup(1);//the factory function has ordinal ==1 |
|
218 if (libEntry==NULL) |
|
219 { |
|
220 LOG_INFO_PRINTF1(_L("No factory method in ppp.nif -> Leaving")); |
|
221 User::Leave(KErrCorrupt); |
|
222 } |
|
223 |
|
224 CNifFactory* pFactory =(*libEntry)(); // Opens CObject |
|
225 if (!pFactory) |
|
226 { |
|
227 LOG_INFO_PRINTF1(_L("Can't create factory in ppp.nif -> Leaving")); |
|
228 User::Leave(KErrCorrupt); |
|
229 } |
|
230 |
|
231 CleanupStack::PushL(TCleanupItem(CNifFactory::Cleanup, pFactory)); |
|
232 CObjectCon* pContainer=CObjectCon::NewL(); |
|
233 CleanupStack::PushL(pContainer); |
|
234 pFactory->InitL(lib.iObj, *pContainer); // Transfers the library object if successful |
|
235 // Can pop the library now - auto close will have no effect because handle is null |
|
236 CleanupStack::Pop();//pContainer |
|
237 CleanupStack::Pop();//pFactory |
|
238 lib.Pop(); |
|
239 |
|
240 CleanupStack::PushL(TCleanupItem(CNifFactory::Cleanup, pFactory)); |
|
241 TName name=_L("ppp"); |
|
242 //another dirty hack |
|
243 CCheekyNifIfFactory* pFactoryExt=(CCheekyNifIfFactory*)pFactory; |
|
244 iInterface = reinterpret_cast<CNifIfLink*>(pFactoryExt->CreateInterfaceL(name, this)); |
|
245 CleanupStack::PopAndDestroy(); // close extra reference on Factory |
|
246 |
|
247 if(!iInterface) |
|
248 { |
|
249 LOG_INFO_PRINTF1(_L("Failed to create interface -> Leaving")); |
|
250 User::Leave(KErrCorrupt); |
|
251 } |
|
252 |
|
253 //chose ip or ip6 |
|
254 TText prtName_[64]; |
|
255 TPtrC prtName(prtName_,64); |
|
256 if (ipIniFileReader ==0 || //problem with ppp.ini reading |
|
257 (!ipIniFileReader->FindVar(iData.KCommDbSectionName,TPtrC(KCDTypeNameIfNetworks),prtName)))//or no corresponding item |
|
258 { |
|
259 prtName.Set(_L("ip6"));//use default then |
|
260 } |
|
261 //use hardcoded only if the ini file read or search failed |
|
262 iInterfaceBound=iInterface->GetBinderL(TPtrC(prtName));//Do as if we bind to the ipv6 protocol |
|
263 iInterface->BindL(ipDummyPrt); //and instead of the protocol put just a dummy |
|
264 } |
|
265 |
|
266 void |
|
267 CDummyNifAgentRef::ServiceStarted() |
|
268 { |
|
269 TRAPD(errCode,ServiceStartedL()); |
|
270 if (errCode!=KErrNone) |
|
271 { |
|
272 LOG_INFO_PRINTF1(_L("Can't continue -> Stopping the test")); |
|
273 iTheMgr.Notify(CTestMgr::EStopTest);//and it's enough in our case |
|
274 } |
|
275 LOG_INFO_PRINTF2(_L("DummyAgtRef::ServiceStarted. ServiceStartedL returned err[%d]"), errCode); |
|
276 } |
|
277 |
|
278 |
|
279 void CDummyNifAgentRef::ServiceClosed() |
|
280 { |
|
281 LOG_INFO_PRINTF1(_L("DummyAgtRef::ServiceClosed")); |
|
282 |
|
283 delete iInterfaceBound; |
|
284 iInterfaceBound=0; |
|
285 delete iInterface; |
|
286 iInterface=0; |
|
287 |
|
288 } |
|
289 |
|
290 void CDummyNifAgentRef::ConnectComplete(TInt aStatus) |
|
291 { |
|
292 LOG_INFO_PRINTF2(_L("DummuAgtRef::ConnectComplete aStatus[%d]"), aStatus); |
|
293 |
|
294 if (aStatus==KErrNone) |
|
295 { |
|
296 aStatus=iInterface->Start(); |
|
297 iState = ELinkUp; |
|
298 LOG_INFO_PRINTF2(_L("DummyAgtRef::ConnectComplete: Interface started: state[%d] (ELinkUp)"), iState); |
|
299 } |
|
300 if(aStatus!=KErrNone) |
|
301 { |
|
302 // iAgent->Disconnect(aStatus); |
|
303 } |
|
304 } |
|
305 |
|
306 void CDummyNifAgentRef::DisconnectComplete() |
|
307 { |
|
308 LOG_INFO_PRINTF1(_L("DummyAgtRef::DisconnectComplete")); |
|
309 |
|
310 ServiceClosed(); |
|
311 } |
|
312 void CDummyNifAgentRef::Stop() |
|
313 { |
|
314 LOG_INFO_PRINTF2(_L("DummyAgtRef::Stop iState[%d]"), iState); |
|
315 |
|
316 // Simplified replica of real CNifAgentRef::Stop |
|
317 // Stop can be called while the NIF is negotiating termination. PPP NIF does not support correct handling |
|
318 // of repeated Stop calls (i.e. Close events) - it will not behave as specified in RFC1661. Therefore, PPP must be |
|
319 // "shielded." |
|
320 switch(iState) |
|
321 { |
|
322 case ELinkUp: // NIF is Up. It is OK to stop it. |
|
323 iState = EStopping; // Negotiating termination. |
|
324 iInterface->Stop(KErrCancel,MNifIfNotify::EDisconnect); // Start to negotiate termination. |
|
325 break; |
|
326 |
|
327 case EStopping: // NIF is negotiating termination already |
|
328 case EStopped: // NIF has informed us that it is finished. |
|
329 break; |
|
330 |
|
331 default: |
|
332 User::Panic(_L("CDummyNifAgentRef::Stop: Illegal AgentRef state."),KErrGeneral); |
|
333 } |
|
334 |
|
335 } |
|
336 |
|
337 void CDummyNifAgentRef::LinkLayerDown(TInt aReason, TAction aAction) |
|
338 { |
|
339 LOG_INFO_PRINTF4(_L("DummyAgtRef::LinkLayerDown iState[%d] Reason[%d] Action[%d] "), iState, aReason, aAction); |
|
340 iState = EStopped; |
|
341 } |
|
342 void CDummyNifAgentRef::NegotiationFailed(CNifIfBase* /*aIf*/, TInt /*aReason*/) |
|
343 { |
|
344 } |
|
345 |
|
346 void CDummyNifAgentRef::BinderLayerDown(CNifIfBase*, TInt, TAction) |
|
347 { |
|
348 } |
|
349 |
|
350 void CDummyNifAgentRef::CancelAuthenticate() |
|
351 { |
|
352 } |
|
353 TInt CDummyNifAgentRef::GetExcessData(TDes8& /*aBuffer*/) |
|
354 { |
|
355 return KErrNone; |
|
356 } |
|
357 TInt CDummyNifAgentRef::DoWriteInt( const TDesC& /*aField*/, TUint32 /*aValue*/,const RMessagePtr2* /*aMessage*/) |
|
358 { |
|
359 __ASSERT_ALWAYS(ETrue,User::Panic(_L("CDummyNifAgentRef::WriteInt called"),KErrGeneral)); |
|
360 return KErrNone; |
|
361 } |
|
362 TInt CDummyNifAgentRef::DoReadDes(const TDesC& /*aField*/, TDes8& /*aValue*/,const RMessagePtr2* /*aMessage*/) |
|
363 { |
|
364 __ASSERT_ALWAYS(ETrue,User::Panic(_L("CDummyNifAgentRef::ReadDes called"),KErrGeneral)); |
|
365 return KErrNone; |
|
366 } |
|
367 TInt CDummyNifAgentRef::DoWriteDes(const TDesC& /*aField*/, const TDesC8& /*aValue*/,const RMessagePtr2* /*aMessage*/) |
|
368 { |
|
369 __ASSERT_ALWAYS(ETrue,User::Panic(_L("CDummyNifAgentRef::WriteDes called"),KErrGeneral)); |
|
370 return KErrNone; |
|
371 } |
|
372 TInt CDummyNifAgentRef::DoWriteDes(const TDesC& /*aField*/, const TDesC16& /*aValue*/,const RMessagePtr2* /*aMessage*/) |
|
373 { |
|
374 __ASSERT_ALWAYS(ETrue,User::Panic(_L("CDummyNifAgentRef::WriteDes called"),KErrGeneral)); |
|
375 return KErrNone; |
|
376 } |
|
377 TInt CDummyNifAgentRef::DoWriteBool( const TDesC& /*aField*/, TBool /*aValue*/,const RMessagePtr2* /*aMessage*/) |
|
378 { |
|
379 __ASSERT_ALWAYS(ETrue,User::Panic(_L("CDummyNifAgentRef::WriteBool called"),KErrGeneral)); |
|
380 return KErrNone; |
|
381 } |
|
382 void CDummyNifAgentRef::IfProgress(TInt aStage, TInt aError) |
|
383 { |
|
384 LOG_INFO_PRINTF4(_L("DummyAgtRef::IfProgress iState[%d] Stage[%d] Error[%d] "), iState, aStage, aError); |
|
385 } |
|
386 |
|
387 void CDummyNifAgentRef::IfProgress(TSubConnectionUniqueId /*aSubConnectionUniqueId*/, TInt /*aStage*/, TInt /*aError*/) |
|
388 { |
|
389 } |
|
390 |
|
391 void CDummyNifAgentRef::OpenRoute() |
|
392 { |
|
393 } |
|
394 void CDummyNifAgentRef::CloseRoute() |
|
395 { |
|
396 } |
|
397 |
|
398 void CDummyNifAgentRef::ReconnectComplete(TInt /*aStatus*/) |
|
399 { |
|
400 } |
|
401 void CDummyNifAgentRef::AuthenticateComplete(TInt /*aStatus*/) |
|
402 { |
|
403 } |
|
404 void CDummyNifAgentRef::AgentProgress(TInt /*aStage*/, TInt /*aError*/) |
|
405 { |
|
406 } |
|
407 |
|
408 void CDummyNifAgentRef::AgentProgress(TSubConnectionUniqueId /*aSubConnectionUniqueId*/, TInt /*aStage*/, TInt /*aError*/) |
|
409 { |
|
410 } |
|
411 |
|
412 TInt |
|
413 CDummyNifAgentRef:: Notification(TAgentToNifEventType /*aEvent*/, TAny* /*aInfo*/) |
|
414 { |
|
415 return KErrNone; |
|
416 } |
|
417 TInt CDummyNifAgentRef::IncomingConnectionReceived() |
|
418 { |
|
419 return KErrNone; |
|
420 } |
|
421 |
|
422 void CDummyNifAgentRef::AgentEvent(TNetworkAdaptorEventType /*aEventType*/, TUint /*aEvent*/, const TDesC8& /*aEventData*/, TAny* /*aSource*/) |
|
423 { |
|
424 } |
|
425 |
|
426 TName CDummyNifAgentRef::Name() const |
|
427 { |
|
428 return iName; |
|
429 } |
|
430 void CDummyNifAgentRef::Close() |
|
431 { |
|
432 } |
|
433 |
|
434 TInt CDummyNifAgentRef::PacketActivity(TDataTransferDirection /*aDirection*/, TUint /*aBytes*/, TBool /*aResetTimer*/) |
|
435 { |
|
436 return KErrNone; |
|
437 } |
|
438 |
|
439 void CDummyNifAgentRef::NotifyDataSent(TSubConnectionUniqueId /*aSubConnectionUniqueId*/, TUint /*aUplinkVolume*/) |
|
440 { |
|
441 } |
|
442 |
|
443 void CDummyNifAgentRef::NotifyDataReceived(TSubConnectionUniqueId /*aSubConnectionUniqueId*/, TUint /*aDownlinkVolume*/) |
|
444 { |
|
445 } |
|
446 |
|
447 void CDummyNifAgentRef::NifEvent(TNetworkAdaptorEventType /*aEventType*/, TUint /*aEvent*/, const TDesC8& /*aEventData*/, TAny* /*aSource*/) |
|
448 { |
|
449 } |