24
|
1 |
// Copyright (c) 2001-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 |
// ATGPRSCONTEXTDEATIVATE.CPP
|
|
15 |
//
|
|
16 |
//
|
|
17 |
|
|
18 |
|
|
19 |
#include "gprs.h"
|
|
20 |
#include "Gprscontext.h"
|
|
21 |
#include "mSLOGGER.H"
|
|
22 |
#include <pcktcs.h>
|
|
23 |
#include "ATGprsContextDeactivate.H"
|
|
24 |
#include "ATIO.H"
|
|
25 |
#include <etelpckt.h>
|
|
26 |
#include "TSYCONFG.H"
|
|
27 |
#include "NOTIFY.H"
|
|
28 |
#include <cdblen.h>
|
|
29 |
#include "Matstd.h"
|
|
30 |
|
|
31 |
#include <commsdattypesv1_1.h>
|
|
32 |
|
|
33 |
const TInt KDTRLowPeriod=500; // milliseconds
|
|
34 |
const TInt KDTRHighSettle=200; // milliseconds
|
|
35 |
|
|
36 |
_LIT8( KEscape, "%S%S%S");
|
|
37 |
|
|
38 |
|
|
39 |
/**
|
|
40 |
* @file
|
|
41 |
* This file implements the CATGprsContextDeactivate class which is one of the state machine used by the
|
|
42 |
* GPRS AT TSY library.
|
|
43 |
* This state machine uses "ATH" "+++" "ATH" commands.
|
|
44 |
*/
|
|
45 |
|
|
46 |
CATGprsContextDeactivate* CATGprsContextDeactivate::NewL(CATIO* aIo, CTelObject* aTelObject, CATInit* aInit, CPhoneGlobals* aPhoneGlobals )
|
|
47 |
/**
|
|
48 |
* Standard 2 phase constructor.
|
|
49 |
*
|
|
50 |
* @param aIo pointer to communication object.
|
|
51 |
* @param aTelObject pointer to parent.
|
|
52 |
* @param aPhoneGlobals pointer to phone global wide states.
|
|
53 |
*/
|
|
54 |
{
|
|
55 |
CATGprsContextDeactivate* p =new(ELeave) CATGprsContextDeactivate(aIo, aTelObject, aInit, aPhoneGlobals);
|
|
56 |
CleanupStack::PushL(p);
|
|
57 |
p->ConstructL();
|
|
58 |
CleanupStack::Pop();
|
|
59 |
|
|
60 |
return p;
|
|
61 |
}
|
|
62 |
|
|
63 |
void CATGprsContextDeactivate::ConstructL()
|
|
64 |
/**
|
|
65 |
* Construct all objects that can leave.
|
|
66 |
*/
|
|
67 |
{
|
|
68 |
CATCommands::ConstructL();
|
|
69 |
}
|
|
70 |
|
|
71 |
CATGprsContextDeactivate::CATGprsContextDeactivate(CATIO* aIo, CTelObject* aTelObject, CATInit* aInit, CPhoneGlobals* aPhoneGlobals)
|
|
72 |
: CATCommands(aIo, aTelObject, aInit, aPhoneGlobals)
|
|
73 |
/**
|
|
74 |
* Constructor.
|
|
75 |
*
|
|
76 |
* @param aIo pointer to communication object.
|
|
77 |
* @param aTelObject pointer to parent.
|
|
78 |
* @param aPhoneGlobals pointer to phone global wide states.
|
|
79 |
*/
|
|
80 |
{
|
|
81 |
LOGTEXT(_L8("CATGprsContextDeactivate::CATGprsContextDeactivate"));
|
|
82 |
}
|
|
83 |
|
|
84 |
|
|
85 |
CATGprsContextDeactivate::~CATGprsContextDeactivate()
|
|
86 |
/**
|
|
87 |
* Destructor.
|
|
88 |
*/
|
|
89 |
|
|
90 |
{
|
|
91 |
LOGTEXT(_L8("CATGprsContextDeactivate::~CATGprsContextDeactivate"));
|
|
92 |
iIo->RemoveExpectStrings(this);
|
|
93 |
}
|
|
94 |
|
|
95 |
|
|
96 |
void CATGprsContextDeactivate::Start(TTsyReqHandle aTsyReqHandle, TAny* /*aDummy*/)
|
|
97 |
/**
|
|
98 |
* This is the standard entry point for sending deactivate command.
|
|
99 |
*
|
|
100 |
* @param aTsyReqHandle handle to the client.
|
|
101 |
*/
|
|
102 |
|
|
103 |
{
|
|
104 |
LOGTEXT(_L8("CATGprsContextDeactivate:\tStarting GPRS detach Command"));
|
|
105 |
iReqHandle=aTsyReqHandle;
|
|
106 |
__ASSERT_ALWAYS(iIo->AddExpectString(this,KNotifyMeIfErrorString) != NULL,Panic(EGeneral));
|
|
107 |
iIo->Cancel(); // This required to avoid a panic in C32 when we call iIo->ConfigurePort
|
|
108 |
TCommConfig configPckg;
|
|
109 |
TInt ret = iPhoneGlobals->iConfiguration->PortConfig(configPckg,EConfigTypeHangUp);
|
|
110 |
if (ret==KErrNone)
|
|
111 |
ret = iIo->ConfigurePort(configPckg);
|
|
112 |
if (ret!=KErrNone)
|
|
113 |
{
|
|
114 |
Complete(ret,EReadCompletion); // EReadCompletion so another Read will not be queued
|
|
115 |
}
|
|
116 |
else
|
|
117 |
{
|
|
118 |
iIo->DropDtr();
|
|
119 |
iIo->SetTimeOut(this,KDTRLowPeriod);
|
|
120 |
iState=EDTRDropped;
|
|
121 |
}
|
|
122 |
}
|
|
123 |
|
|
124 |
|
|
125 |
void CATGprsContextDeactivate::ValidateHangUpExpectStringL()
|
|
126 |
/**
|
|
127 |
* This function validates the response from the phone.
|
|
128 |
*/
|
|
129 |
{
|
|
130 |
CCommChatString* foundChatString = iIo->FoundChatString();
|
|
131 |
if (foundChatString == iNoCarrierExpectString)
|
|
132 |
{
|
|
133 |
LOGTEXT(_L8("CATGprsContextDeactivate::ValidateHangUpExpectStringL Modem returned NO CARRIER "));
|
|
134 |
}
|
|
135 |
else if ((foundChatString != iOKExpectString) && (foundChatString != iErrorExpectString))
|
|
136 |
{
|
|
137 |
LOGTEXT(_L8("CATGprsContextDeactivate:\tModem returned unknown response to hang up command"));
|
|
138 |
User::Leave(KErrGeneral);
|
|
139 |
}
|
|
140 |
}
|
|
141 |
|
|
142 |
|
|
143 |
void CATGprsContextDeactivate::Stop(TTsyReqHandle aTsyReqHandle)
|
|
144 |
/**
|
|
145 |
* @param aTsyReqHandle handle to the client.
|
|
146 |
*/
|
|
147 |
{
|
|
148 |
LOGTEXT(_L8("CATGprsContextDeactivate::Stop called"));
|
|
149 |
if(iState!=EATNotInProgress && aTsyReqHandle==iReqHandle)
|
|
150 |
{
|
|
151 |
LOGTEXT(_L8("CATGprsContextDeactivate::Stop Completing client request with KErrCancel"));
|
|
152 |
Complete(KErrCancel,ETimeOutCompletion);
|
|
153 |
}
|
|
154 |
}
|
|
155 |
|
|
156 |
|
|
157 |
void CATGprsContextDeactivate::CompleteWithIOError(TEventSource aSource,TInt aStatus)
|
|
158 |
/**
|
|
159 |
* This Function completes the command from the client with an error.
|
|
160 |
*
|
|
161 |
* @param aSource source of event from communication class.
|
|
162 |
* @param aStatus status of event.
|
|
163 |
*/
|
|
164 |
{
|
|
165 |
LOGTEXT2(_L8("CATGprsContextDeactivate::CompleteWithIOError() called with iState = %d"),iState);
|
|
166 |
Complete(aStatus,aSource);
|
|
167 |
}
|
|
168 |
|
|
169 |
|
|
170 |
void CATGprsContextDeactivate::EventSignal(TEventSource aSource)
|
|
171 |
/**
|
|
172 |
* This function contains the state machine for the command. The states flow consecutively and are
|
|
173 |
* described below.
|
|
174 |
*
|
|
175 |
* @par EATNotInProgress
|
|
176 |
* Nothing is being sent to the phone.
|
|
177 |
*
|
|
178 |
* @par EDTRDropped
|
|
179 |
* DTR has been dropped
|
|
180 |
*
|
|
181 |
* @par EWaitForDTRRaiseSettle
|
|
182 |
* Wait for DTR signal to settle. Also send +++ command
|
|
183 |
*
|
|
184 |
* @par EATEscapeSeqWaitForWriteComplete
|
|
185 |
* Wait for +++ command write to complete.
|
|
186 |
*
|
|
187 |
* @par EATEscapeSeqCompleted
|
|
188 |
* Send ATH command to the phone.
|
|
189 |
|
|
190 |
* @par EATHangupWaitForWriteComplete
|
|
191 |
* Wait for write to complete.
|
|
192 |
*
|
|
193 |
* @par EATHangupReadCompleted
|
|
194 |
* Parse phone response.
|
|
195 |
*
|
|
196 |
* @par EHangUpCancelling
|
|
197 |
* Cancel the deactivate command.
|
|
198 |
*
|
|
199 |
*/
|
|
200 |
{
|
|
201 |
LOGTEXT2(_L8("CATGprsContextDeactivate::EventSignal, Event Source %d"), aSource);
|
|
202 |
|
|
203 |
if (aSource==ETimeOutCompletion && iState!=EDTRDropped && iState!=EATHangupReadCompleted
|
|
204 |
&& iState!=EATEscapeSeqCompleted && iState!=EWaitForDTRRaiseSettle
|
|
205 |
&& iState!=EHangUpCancelling)
|
|
206 |
{
|
|
207 |
LOGTEXT(_L8("CATGprsContextDeactivate:\tTimeout Error during Hang Up"));
|
|
208 |
Complete(KErrTimedOut,aSource);
|
|
209 |
return;
|
|
210 |
}
|
|
211 |
|
|
212 |
switch(iState)
|
|
213 |
{
|
|
214 |
case EDTRDropped:
|
|
215 |
{
|
|
216 |
__ASSERT_ALWAYS(aSource==ETimeOutCompletion,Panic(EATCommand_IllegalCompletionWaitExpected));
|
|
217 |
iIo->Cancel();
|
|
218 |
iIo->RaiseDTR();
|
|
219 |
iIo->SetTimeOut(this,KDTRHighSettle);
|
|
220 |
iState=EWaitForDTRRaiseSettle;
|
|
221 |
break;
|
|
222 |
}
|
|
223 |
case EWaitForDTRRaiseSettle:// NO CARRIER may come back after 2-3 seconds, but send ATH anyway
|
|
224 |
{
|
|
225 |
__ASSERT_ALWAYS(aSource==ETimeOutCompletion,Panic(EATCommand_IllegalCompletionWaitExpected));
|
|
226 |
TBuf8<KCommsDbSvrMaxFieldLength> escapeChar;
|
|
227 |
TInt ret = iPhoneGlobals->iConfiguration->ConfigModemString(TPtrC(KCDTypeNameEscapeCharacter),escapeChar);
|
|
228 |
if (ret)
|
|
229 |
{
|
|
230 |
Complete(ret,aSource);
|
|
231 |
break;
|
|
232 |
}
|
|
233 |
iTxBuffer.Format(KEscape ,&escapeChar, &escapeChar, &escapeChar);
|
|
234 |
Write(KGprsCommandTimeOut);
|
|
235 |
iState=EATEscapeSeqWaitForWriteComplete;
|
|
236 |
}
|
|
237 |
break;
|
|
238 |
|
|
239 |
case EATEscapeSeqWaitForWriteComplete:
|
|
240 |
{
|
|
241 |
// do not use the standard complete handler since this will also do a AddStdExpectStrings() and
|
|
242 |
// we are waiting for the No CARRIER.
|
|
243 |
iIo->SetTimeOut(this, KGprsCommandTimeOut * KOneSecondPause);
|
|
244 |
if (!iNoCarrierExpectString)
|
|
245 |
iNoCarrierExpectString=iIo->AddExpectString(this,KNoCarrierString);
|
|
246 |
StandardWriteCompletionHandler(aSource,KGprsCommandTimeOut);
|
|
247 |
iState=EATEscapeSeqCompleted;
|
|
248 |
break;
|
|
249 |
}
|
|
250 |
|
|
251 |
case EATEscapeSeqCompleted:
|
|
252 |
{
|
|
253 |
__ASSERT_ALWAYS(aSource!=EWriteCompletion,Panic(EATCommand_IllegalCompletionWriteNotExpected));
|
|
254 |
if (aSource!=ETimeOutCompletion)
|
|
255 |
{
|
|
256 |
TRAPD(ret,ValidateHangUpExpectStringL());
|
|
257 |
if (iIo->FoundChatString()==iNoCarrierExpectString || ret!=KErrNone)
|
|
258 |
{
|
|
259 |
Complete(ret,aSource);
|
|
260 |
break;
|
|
261 |
}
|
|
262 |
}
|
|
263 |
RemoveStdExpectStrings();
|
|
264 |
iIo->RemoveExpectString(iNoCarrierExpectString);
|
|
265 |
iNoCarrierExpectString=NULL;
|
|
266 |
TPtrC8 hangUpCommand(KHangUpCommand);
|
|
267 |
Write(hangUpCommand, KGprsCommandTimeOut);
|
|
268 |
iState=EATHangupWaitForWriteComplete;
|
|
269 |
}
|
|
270 |
break;
|
|
271 |
|
|
272 |
case EATHangupWaitForWriteComplete:
|
|
273 |
{
|
|
274 |
// Try with ATH, this time listen to OK/ERROR/NO CARRIER
|
|
275 |
iIo->WriteAndTimerCancel(this);
|
|
276 |
iIo->Read();
|
|
277 |
StandardWriteCompletionHandler(aSource,KGprsCommandTimeOut);
|
|
278 |
if (!iNoCarrierExpectString)
|
|
279 |
iNoCarrierExpectString=iIo->AddExpectString(this,KNoCarrierString);
|
|
280 |
iState=EATHangupReadCompleted;
|
|
281 |
break;
|
|
282 |
}
|
|
283 |
|
|
284 |
case EATHangupReadCompleted:
|
|
285 |
{
|
|
286 |
__ASSERT_ALWAYS(aSource!=EWriteCompletion,Panic(EATCommand_IllegalCompletionWriteNotExpected));
|
|
287 |
|
|
288 |
if (aSource!=ETimeOutCompletion)
|
|
289 |
{
|
|
290 |
TRAPD(ret,ValidateHangUpExpectStringL());
|
|
291 |
Complete(ret,aSource);
|
|
292 |
}
|
|
293 |
else
|
|
294 |
{
|
|
295 |
Complete(KErrTimedOut,aSource);
|
|
296 |
}
|
|
297 |
break;
|
|
298 |
}
|
|
299 |
|
|
300 |
case EHangUpCancelling:
|
|
301 |
{
|
|
302 |
if (aSource==EWriteCompletion)
|
|
303 |
{
|
|
304 |
iIo->SetTimeOut(this,KOneSecondPause);
|
|
305 |
}
|
|
306 |
if (aSource==EReadCompletion || aSource==ETimeOutCompletion)
|
|
307 |
{
|
|
308 |
LOGTEXT(_L8("CATGprsContextDeactivate:\tHang up cancelled"));
|
|
309 |
Complete(KErrCancel,aSource);
|
|
310 |
}
|
|
311 |
break;
|
|
312 |
}
|
|
313 |
case EATNotInProgress:
|
|
314 |
break;
|
|
315 |
default:
|
|
316 |
{
|
|
317 |
Panic(EIllegalEvent);
|
|
318 |
}
|
|
319 |
}
|
|
320 |
}
|
|
321 |
|
|
322 |
|
|
323 |
void CATGprsContextDeactivate::Complete(TInt aError,TEventSource aSource)
|
|
324 |
/**
|
|
325 |
* This Function completes the command from the client.
|
|
326 |
* @param aError an error code to relay to client.
|
|
327 |
*/
|
|
328 |
{
|
|
329 |
LOGTEXT2(_L8("CATGprsContextDeactivate::Complete() with aError %d"),aError);
|
|
330 |
RemoveStdExpectStrings();
|
|
331 |
iIo->RemoveExpectStrings(this);
|
|
332 |
iIo->WriteAndTimerCancel(this);
|
|
333 |
iNoCarrierExpectString=NULL;
|
|
334 |
iIo->Cancel();
|
|
335 |
if (aError==KErrNone)
|
|
336 |
{
|
|
337 |
TCommConfig configPckg;
|
|
338 |
aError=iPhoneGlobals->iConfiguration->PortConfig(configPckg,EConfigTypeInit);
|
|
339 |
if (aError==KErrNone)
|
|
340 |
aError = iIo->ConfigurePort(configPckg);
|
|
341 |
|
|
342 |
iPhoneGlobals->iPhoneStatus.iMode = RPhone::EModeOnlineCommand;
|
|
343 |
|
|
344 |
//
|
|
345 |
// Set this context and all its sibling contexts as Inactive
|
|
346 |
CGprs* parentPtr=(static_cast<CGprsContext*>(iTelObject))->Parent();
|
|
347 |
RPacketService::TContextInfo contextInfo;
|
|
348 |
for(TInt i=0;(parentPtr->Context(i))!=NULL;++i)
|
|
349 |
{
|
|
350 |
((CGprsContext*)iTelObject)->ContextInfo(&contextInfo);
|
|
351 |
contextInfo.iStatus = RPacketContext::EStatusInactive;
|
|
352 |
((CGprsContext*)iTelObject)->SetContextInfo(&contextInfo);
|
|
353 |
// Set Gprs state
|
|
354 |
((CGprsContext*)iTelObject)->Parent()->SetStatus(RPacketService::EStatusUnattached);
|
|
355 |
iPhoneGlobals->iNotificationStore->CheckNotification(STATIC_CAST(CTelObject*,iTelObject->Owner()), EPacketStatusChanged);
|
|
356 |
iPhoneGlobals->iNotificationStore->CheckNotification(iTelObject, EPacketContextStatusChanged);
|
|
357 |
}
|
|
358 |
}
|
|
359 |
|
|
360 |
// Allow our base class to do its thing and then complete the client request
|
|
361 |
CATCommands::Complete(aError,aSource);
|
|
362 |
iTelObject->ReqCompleted(iReqHandle, aError);
|
|
363 |
|
|
364 |
iState=EATNotInProgress;
|
|
365 |
}
|
|
366 |
|
|
367 |
|
|
368 |
|