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 |
//
|
|
15 |
|
|
16 |
#include "Gprscontext.h"
|
|
17 |
#include "mSLOGGER.H"
|
|
18 |
#include "ATGprsDetach.H"
|
|
19 |
#include "ATIO.H"
|
|
20 |
#include "TSYCONFG.H"
|
|
21 |
#include "NOTIFY.H"
|
|
22 |
#include "Matstd.h"
|
|
23 |
|
|
24 |
_LIT8(KDetachCommand, "AT+CGATT=0\r");
|
|
25 |
|
|
26 |
/**
|
|
27 |
* @file
|
|
28 |
* This file implements the CATGprsDetachclass which is one of the state machine used by the
|
|
29 |
* GPRS AT TSY library.
|
|
30 |
* This state machine uses the "AT+CGATT" command.
|
|
31 |
*/
|
|
32 |
|
|
33 |
CATGprsDetach* CATGprsDetach::NewL(CATIO* aIo, CTelObject* aTelObject, CATInit* aInit, CPhoneGlobals* aPhoneGlobals )
|
|
34 |
/**
|
|
35 |
* Standard 2 phase constructor.
|
|
36 |
*
|
|
37 |
* @param aIo pointer to communication object.
|
|
38 |
* @param aTelObject pointer to parent.
|
|
39 |
* @param aPhoneGlobals pointer to phone global wide states.
|
|
40 |
*/
|
|
41 |
{
|
|
42 |
CATGprsDetach* p =new(ELeave) CATGprsDetach(aIo, aTelObject, aInit, aPhoneGlobals);
|
|
43 |
CleanupStack::PushL(p);
|
|
44 |
p->ConstructL();
|
|
45 |
CleanupStack::Pop();
|
|
46 |
return p;
|
|
47 |
}
|
|
48 |
|
|
49 |
void CATGprsDetach::ConstructL()
|
|
50 |
/**
|
|
51 |
* Construct all objects that can leave.
|
|
52 |
*/
|
|
53 |
{
|
|
54 |
CATCommands::ConstructL();
|
|
55 |
}
|
|
56 |
|
|
57 |
|
|
58 |
|
|
59 |
CATGprsDetach::CATGprsDetach(CATIO* aIo, CTelObject* aTelObject, CATInit* aInit, CPhoneGlobals* aPhoneGlobals)
|
|
60 |
: CATCommands(aIo, aTelObject, aInit, aPhoneGlobals)
|
|
61 |
/**
|
|
62 |
* Constructor.
|
|
63 |
*
|
|
64 |
* @param aIo pointer to communication object.
|
|
65 |
* @param aTelObject pointer to parent.
|
|
66 |
* @param aInit pointer to AT phone init object.
|
|
67 |
* @param aPhoneGlobals pointer to phone global wide states.
|
|
68 |
*/
|
|
69 |
{}
|
|
70 |
|
|
71 |
|
|
72 |
CATGprsDetach::~CATGprsDetach()
|
|
73 |
/**
|
|
74 |
* Destructor.
|
|
75 |
*/
|
|
76 |
{
|
|
77 |
iIo->RemoveExpectStrings(this);
|
|
78 |
}
|
|
79 |
|
|
80 |
|
|
81 |
void CATGprsDetach::Start(TTsyReqHandle aTsyReqHandle, TAny* )
|
|
82 |
/**
|
|
83 |
* This is the standard entry point for sending detach command.
|
|
84 |
* @param aTsyReqHandle handle to the client.
|
|
85 |
*/
|
|
86 |
{
|
|
87 |
LOGTEXT(_L8("CATGprsDetach:\tStarting at AT+CGATT=0 Command"));
|
|
88 |
iReqHandle = aTsyReqHandle;
|
|
89 |
Write(KDetachCommand, KGprsCommandTimeOut);
|
|
90 |
iState=ESendDetachCommand;
|
|
91 |
}
|
|
92 |
|
|
93 |
|
|
94 |
void CATGprsDetach::Stop(TTsyReqHandle aTsyReqHandle)
|
|
95 |
/**
|
|
96 |
* This function attempts to cancel the AT state machine
|
|
97 |
*/
|
|
98 |
{
|
|
99 |
LOGTEXT(_L8("CATGprsDetach::Stop called"));
|
|
100 |
if(iState!=EATNotInProgress && aTsyReqHandle==iReqHandle)
|
|
101 |
{
|
|
102 |
LOGTEXT(_L8("CATGprsDetach::Stop Completing client request with KErrCancel"));
|
|
103 |
Complete(KErrCancel,ETimeOutCompletion);
|
|
104 |
}
|
|
105 |
}
|
|
106 |
|
|
107 |
|
|
108 |
void CATGprsDetach::CompleteWithIOError(TEventSource aSource,TInt aStatus)
|
|
109 |
/**
|
|
110 |
* This Function completes the command from the client whith an error.
|
|
111 |
*
|
|
112 |
* @param aSource source of event from communication class.
|
|
113 |
* @param aStatus status of event.
|
|
114 |
*/
|
|
115 |
{
|
|
116 |
LOGTEXT2(_L8("CATGprsDetach::CompleteWithIOError() called with iState = %d"),iState);
|
|
117 |
Complete(aStatus, aSource);
|
|
118 |
}
|
|
119 |
|
|
120 |
|
|
121 |
void CATGprsDetach::EventSignal(TEventSource aSource)
|
|
122 |
/**
|
|
123 |
* This function contains the state machine for the command. The states flow consecutively and are
|
|
124 |
* described below.
|
|
125 |
*
|
|
126 |
* @par EDetachReadComplete
|
|
127 |
* wait for the response from the phone.
|
|
128 |
*
|
|
129 |
* @par ESendDetachCommand
|
|
130 |
* Parse the response from the phone.
|
|
131 |
*/
|
|
132 |
{
|
|
133 |
if ((aSource==ETimeOutCompletion))
|
|
134 |
{
|
|
135 |
LOGTEXT(_L8("CATGprsDetach::EventSignal, Timeout"));
|
|
136 |
Complete(KErrTimedOut,aSource);
|
|
137 |
return;
|
|
138 |
}
|
|
139 |
|
|
140 |
switch(iState)
|
|
141 |
{
|
|
142 |
case ESendDetachCommand:
|
|
143 |
{
|
|
144 |
LOGTEXT(_L8("CATGprsDetach::EventSignal, ESendConnectCommand"));
|
|
145 |
__ASSERT_ALWAYS(aSource==EWriteCompletion,Panic(EATCommand_IllegalCompletionWriteExpected));
|
|
146 |
StandardWriteCompletionHandler(aSource, KGprsLongCommandTimeOut);
|
|
147 |
iState = EDetachReadComplete;
|
|
148 |
}
|
|
149 |
break;
|
|
150 |
case EDetachReadComplete:
|
|
151 |
{
|
|
152 |
LOGTEXT(_L8("CATGprsDetach::EventSignal, EConnectReadComplete"));
|
|
153 |
__ASSERT_ALWAYS(aSource==EReadCompletion,Panic(EATCommand_IllegalCompletionReadExpected));
|
|
154 |
TInt ret = ValidateExpectString();
|
|
155 |
Complete(ret, aSource);
|
|
156 |
}
|
|
157 |
break;
|
|
158 |
case EATNotInProgress:
|
|
159 |
break;
|
|
160 |
default:
|
|
161 |
Panic(EIllegalEvent);
|
|
162 |
}
|
|
163 |
}
|
|
164 |
|
|
165 |
|
|
166 |
void CATGprsDetach::Complete(TInt aError,TEventSource aSource)
|
|
167 |
/**
|
|
168 |
* This Function completes the command from the client.
|
|
169 |
* It also changes the status of all contexts.
|
|
170 |
* @param aError an error code to relay to client.
|
|
171 |
*/
|
|
172 |
{
|
|
173 |
LOGTEXT2(_L8("CATGprsDetach::Complete() with aError %d"),aError);
|
|
174 |
RemoveStdExpectStrings();
|
|
175 |
iIo->WriteAndTimerCancel(this);
|
|
176 |
iIo->RemoveExpectStrings(this);
|
|
177 |
if (aError==KErrNone)
|
|
178 |
{
|
|
179 |
TCommConfig aConfigPckg;
|
|
180 |
aError = iPhoneGlobals->iConfiguration->PortConfig(aConfigPckg,EConfigTypeInit);
|
|
181 |
if (aError==KErrNone)
|
|
182 |
aError = iIo->ConfigurePort(aConfigPckg);
|
|
183 |
|
|
184 |
iPhoneGlobals->iPhoneStatus.iMode = RPhone::EModeOnlineCommand;
|
|
185 |
RPacketService::TContextInfo contextInfo;
|
|
186 |
((CGprs*)iTelObject)->SetStatus(RPacketService::EStatusUnattached);
|
|
187 |
TInt i = 0;
|
|
188 |
// since the connection to the network is broken change the state of the contexts also.
|
|
189 |
CGprsContext* context;
|
|
190 |
while(context = ((CGprs*)iTelObject)->Context(i), context != NULL)
|
|
191 |
{
|
|
192 |
context->ContextInfo(&contextInfo);
|
|
193 |
contextInfo.iStatus = RPacketContext::EStatusInactive;
|
|
194 |
context->SetContextInfo(&contextInfo);
|
|
195 |
iPhoneGlobals->iNotificationStore->CheckNotification(context, EPacketContextStatusChanged);
|
|
196 |
i++;
|
|
197 |
}
|
|
198 |
iPhoneGlobals->iNotificationStore->CheckNotification(iTelObject, EPacketStatusChanged);
|
|
199 |
}
|
|
200 |
|
|
201 |
// Allow our base class to do its thing and then complete the client request
|
|
202 |
CATCommands::Complete(aError,aSource);
|
|
203 |
iTelObject->ReqCompleted(iReqHandle, aError);
|
|
204 |
|
|
205 |
iState=EATNotInProgress;
|
|
206 |
}
|
|
207 |
|