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 "gprs.h"
|
|
17 |
#include "Gprscontext.h"
|
|
18 |
#include "mSLOGGER.H"
|
|
19 |
#include <pcktcs.h>
|
|
20 |
#include "ATGprsContextActivate.H"
|
|
21 |
#include "ATIO.H"
|
|
22 |
#include <etelpckt.h>
|
|
23 |
#include "TSYCONFG.H"
|
|
24 |
#include "NOTIFY.H"
|
|
25 |
#include "Matstd.h"
|
|
26 |
|
|
27 |
_LIT8(KATAttachEricsson, "ATD*99***1#\r");
|
|
28 |
_LIT8(KATAttachNormal, "ATD*99#\r");
|
|
29 |
|
|
30 |
/**
|
|
31 |
* @file
|
|
32 |
* This file implements the CATGprsContextActivate class which is one of the state machine used by the
|
|
33 |
* GPRS AT TSY library.
|
|
34 |
* This state machine uses the "ATD*99***%d#" and the "ATD*99#" command.
|
|
35 |
*/
|
|
36 |
|
|
37 |
CATGprsContextActivate* CATGprsContextActivate::NewL(TInt aCid, CATIO* aIo, CTelObject* aTelObject, CATInit* aInit, CPhoneGlobals* aPhoneGlobals )
|
|
38 |
/**
|
|
39 |
* Standard 2 phase constructor.
|
|
40 |
*
|
|
41 |
* @param aIo pointer to communication object.
|
|
42 |
* @param aTelObject pointer to parent.
|
|
43 |
* @param aPhoneGlobals pointer to phone global wide states.
|
|
44 |
*/
|
|
45 |
{
|
|
46 |
CATGprsContextActivate* p =new(ELeave) CATGprsContextActivate(aCid, aIo, aTelObject, aInit, aPhoneGlobals);
|
|
47 |
CleanupStack::PushL(p);
|
|
48 |
p->ConstructL();
|
|
49 |
CleanupStack::Pop();
|
|
50 |
|
|
51 |
return p;
|
|
52 |
}
|
|
53 |
|
|
54 |
void CATGprsContextActivate::ConstructL()
|
|
55 |
/**
|
|
56 |
* Construct all objects that can leave.
|
|
57 |
*/
|
|
58 |
{
|
|
59 |
CATCommands::ConstructL();
|
|
60 |
}
|
|
61 |
|
|
62 |
CATGprsContextActivate::CATGprsContextActivate(TInt aCid, CATIO* aIo, CTelObject* aTelObject, CATInit* aInit, CPhoneGlobals* aPhoneGlobals)
|
|
63 |
: CATCommands(aIo, aTelObject, aInit, aPhoneGlobals), iCid(aCid)
|
|
64 |
/**
|
|
65 |
* Constructor.
|
|
66 |
*
|
|
67 |
* @param aCid context number.
|
|
68 |
* @param aIo pointer to communication object.
|
|
69 |
* @param aTelObject pointer to parent.
|
|
70 |
* @param aPhoneGlobals pointer to phone global wide states.
|
|
71 |
*/
|
|
72 |
{
|
|
73 |
LOGTEXT(_L8("CATGprsContextActivate::CATGprsContextActivate called"));
|
|
74 |
}
|
|
75 |
|
|
76 |
|
|
77 |
CATGprsContextActivate::~CATGprsContextActivate()
|
|
78 |
/**
|
|
79 |
* Destructor.
|
|
80 |
*/
|
|
81 |
{
|
|
82 |
LOGTEXT(_L8("CATGprsContextActivate::~CATGprsContextActivate called"));
|
|
83 |
iIo->RemoveExpectStrings(this);
|
|
84 |
}
|
|
85 |
|
|
86 |
|
|
87 |
void CATGprsContextActivate::Start(TTsyReqHandle aTsyReqHandle, TAny* /*aParams*/)
|
|
88 |
/**
|
|
89 |
* This is the standard entry point for sending attach command.
|
|
90 |
*
|
|
91 |
* @param aTsyReqHandle handle to the client.
|
|
92 |
*/
|
|
93 |
{
|
|
94 |
LOGTEXT(_L8("CATGprsContextActivate::Start called"));
|
|
95 |
iReqHandle = aTsyReqHandle;
|
|
96 |
iTxBuffer.Format(KATAttachEricsson, iCid);
|
|
97 |
Write(KGprsCommandTimeOut);
|
|
98 |
iState=ESendEricssonConnectCommand;
|
|
99 |
}
|
|
100 |
|
|
101 |
|
|
102 |
void CATGprsContextActivate::Stop(TTsyReqHandle aTsyReqHandle)
|
|
103 |
/**
|
|
104 |
*/
|
|
105 |
{
|
|
106 |
LOGTEXT(_L8("CATGprsContextActivate::Stop called"));
|
|
107 |
if(iState!=EATNotInProgress && aTsyReqHandle==iReqHandle)
|
|
108 |
{
|
|
109 |
LOGTEXT(_L8("CATGprsContextActivate::Stop Completing client request with KErrCancel"));
|
|
110 |
Complete(KErrCancel,ETimeOutCompletion);
|
|
111 |
}
|
|
112 |
}
|
|
113 |
|
|
114 |
|
|
115 |
void CATGprsContextActivate::CompleteWithIOError(TEventSource aSource,TInt aStatus)
|
|
116 |
/**
|
|
117 |
* This Function completes the command from the client whith an error.
|
|
118 |
* @param aSource source of event from communication class.
|
|
119 |
* @param aStatus status of event.
|
|
120 |
*/
|
|
121 |
{
|
|
122 |
LOGTEXT(_L8("CATGprsContextActivate::CompleteWithIOError called"));
|
|
123 |
Complete(aStatus, aSource);
|
|
124 |
}
|
|
125 |
|
|
126 |
void CATGprsContextActivate::Complete(TInt aError,TEventSource aSource)
|
|
127 |
/**
|
|
128 |
* This Function completes the command from the client.
|
|
129 |
* @param aError an error code to relay to client.
|
|
130 |
*/
|
|
131 |
{
|
|
132 |
LOGTEXT2(_L8("CATGprsContextActivate::Complete called error: %d"), aError);
|
|
133 |
RemoveStdExpectStrings();
|
|
134 |
iIo->WriteAndTimerCancel(this);
|
|
135 |
iIo->RemoveExpectStrings(this);
|
|
136 |
iExpectString=NULL;
|
|
137 |
iNoCarrierString=NULL;
|
|
138 |
if (aError==KErrNone)
|
|
139 |
{
|
|
140 |
// Set context information
|
|
141 |
iPhoneGlobals->iPhoneStatus.iMode = RPhone::EModeOnlineData;
|
|
142 |
RPacketService::TContextInfo contextInfo;
|
|
143 |
((CGprsContext*)iTelObject)->ContextInfo(&contextInfo );
|
|
144 |
contextInfo.iStatus = RPacketContext::EStatusActive;
|
|
145 |
((CGprsContext*)iTelObject)->SetContextInfo(&contextInfo);
|
|
146 |
// Set Gprs state
|
|
147 |
((CGprsContext*)iTelObject)->Parent()->SetStatus(RPacketService::EStatusActive);
|
|
148 |
// Check notifications.
|
|
149 |
|
|
150 |
// Note that EPacketStatusChanged is a notification of the CGprs class.
|
|
151 |
// Our iTelObject is the CGprsContext class, so we have to use iTelObject->Owner().
|
|
152 |
iPhoneGlobals->iNotificationStore->CheckNotification(STATIC_CAST(CTelObject*,iTelObject->Owner()), EPacketStatusChanged);
|
|
153 |
|
|
154 |
iPhoneGlobals->iNotificationStore->CheckNotification(iTelObject, EPacketContextStatusChanged);
|
|
155 |
}
|
|
156 |
|
|
157 |
// Allow our base class to do its thing and then complete the client request
|
|
158 |
CATCommands::Complete(aError,aSource);
|
|
159 |
iTelObject->ReqCompleted(iReqHandle, aError);
|
|
160 |
|
|
161 |
iState = EATNotInProgress;
|
|
162 |
}
|
|
163 |
|
|
164 |
|
|
165 |
void CATGprsContextActivate::EventSignal(TEventSource aSource)
|
|
166 |
/**
|
|
167 |
* This function contains the state machine for the command. The states flow consecutively and are
|
|
168 |
* described below.
|
|
169 |
*
|
|
170 |
* @par ESendEricssonConnectCommand
|
|
171 |
*
|
|
172 |
* @par EConnectEricssonReadComplete
|
|
173 |
*
|
|
174 |
* @par ESendConnectCommand
|
|
175 |
* Wait for response to the attach command.
|
|
176 |
*
|
|
177 |
* @par EConnectReadComplete
|
|
178 |
* Reads the Modem's response to the attach command and completes the request.
|
|
179 |
*
|
|
180 |
*/
|
|
181 |
{
|
|
182 |
if ((aSource==ETimeOutCompletion))
|
|
183 |
{
|
|
184 |
LOGTEXT(_L8("CATGprsContextActivate::EventSignal, Timeout"));
|
|
185 |
Complete(KErrTimedOut,aSource);
|
|
186 |
return;
|
|
187 |
}
|
|
188 |
|
|
189 |
switch(iState)
|
|
190 |
{
|
|
191 |
case ESendEricssonConnectCommand:
|
|
192 |
{
|
|
193 |
LOGTEXT(_L8("CATGprsContextActivate::EventSignal, ESendConnectCommand"));
|
|
194 |
__ASSERT_ALWAYS(aSource==EWriteCompletion,Panic(EATCommand_IllegalCompletionWriteExpected));
|
|
195 |
StandardWriteCompletionHandler(aSource, KGprsCommandTimeOut);
|
|
196 |
if(!iExpectString)
|
|
197 |
iExpectString = iIo->AddExpectString(this, KCarrierString);
|
|
198 |
if(!iNoCarrierString)
|
|
199 |
iNoCarrierString = iIo->AddExpectString(this, KNoCarrierString);
|
|
200 |
iState = EConnectEricssonReadComplete;
|
|
201 |
}
|
|
202 |
break;
|
|
203 |
|
|
204 |
case EConnectEricssonReadComplete:
|
|
205 |
{
|
|
206 |
LOGTEXT(_L8("CATGprsContextActivate::EventSignal, EConnectReadComplete"));
|
|
207 |
__ASSERT_ALWAYS(aSource==EReadCompletion,Panic(EATCommand_IllegalCompletionReadExpected));
|
|
208 |
TInt ret=ValidateExpectString();
|
|
209 |
RemoveStdExpectStrings();
|
|
210 |
if(ret == KErrArgument)
|
|
211 |
{
|
|
212 |
iTxBuffer.Format(KATAttachNormal);
|
|
213 |
Write(KGprsLongCommandTimeOut);
|
|
214 |
iState=ESendNormalConnectCommand;
|
|
215 |
break;
|
|
216 |
}
|
|
217 |
Complete(ret, aSource);
|
|
218 |
}
|
|
219 |
break;
|
|
220 |
|
|
221 |
|
|
222 |
case ESendNormalConnectCommand:
|
|
223 |
{
|
|
224 |
LOGTEXT(_L8("CATGprsContextActivate::EventSignal, ESendConnectCommand"));
|
|
225 |
__ASSERT_ALWAYS(aSource==EWriteCompletion,Panic(EATCommand_IllegalCompletionWriteExpected));
|
|
226 |
StandardWriteCompletionHandler(aSource, KGprsLongCommandTimeOut);
|
|
227 |
if(!iExpectString)
|
|
228 |
iExpectString = iIo->AddExpectString(this, KCarrierString);
|
|
229 |
if(!iNoCarrierString)
|
|
230 |
iNoCarrierString = iIo->AddExpectString(this, KNoCarrierString);
|
|
231 |
iState = EConnectNormalReadComplete;
|
|
232 |
}
|
|
233 |
break;
|
|
234 |
|
|
235 |
case EConnectNormalReadComplete:
|
|
236 |
{
|
|
237 |
LOGTEXT(_L8("CATGprsContextActivate::EventSignal, EConnectReadComplete"));
|
|
238 |
__ASSERT_ALWAYS(aSource==EReadCompletion,Panic(EATCommand_IllegalCompletionReadExpected));
|
|
239 |
TInt ret=ValidateExpectString();
|
|
240 |
// Changed in accordance with Defect Fix BEN-5AVC39 to return a more meaningfull Error code
|
|
241 |
ret = ret == KErrArgument ? KErrNotFound : ret;
|
|
242 |
Complete(ret, aSource);
|
|
243 |
}
|
|
244 |
break;
|
|
245 |
case EATNotInProgress:
|
|
246 |
break;
|
|
247 |
default:
|
|
248 |
Panic(EIllegalEvent);
|
|
249 |
}
|
|
250 |
}
|
|
251 |
|
|
252 |
|
|
253 |
TInt CATGprsContextActivate::ValidateExpectString()
|
|
254 |
/**
|
|
255 |
* This Function validates the response from the phone.
|
|
256 |
*/
|
|
257 |
{
|
|
258 |
LOGTEXT(_L8("CATGprsContextActivate::ValidateExpectString called"));
|
|
259 |
if(iIo->FoundChatString()==iExpectString)
|
|
260 |
{
|
|
261 |
LOGTEXT(_L8("CATGprsContextActivate:\tPhone returned CONNECT"));
|
|
262 |
iIo->RemoveExpectString(iExpectString);
|
|
263 |
return KErrNone;
|
|
264 |
}
|
|
265 |
else if(iIo->FoundChatString() == iNoCarrierString)
|
|
266 |
{
|
|
267 |
iIo->RemoveExpectString(iNoCarrierString);
|
|
268 |
return KErrNotFound;
|
|
269 |
}
|
|
270 |
else if( iIo->FoundChatString() == iErrorExpectString)
|
|
271 |
{
|
|
272 |
return KErrArgument;
|
|
273 |
}
|
|
274 |
return KErrUnknown;
|
|
275 |
}
|
|
276 |
|