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 <et_phone.h> // For CTelObject
|
|
17 |
|
|
18 |
#include "atgprsntwkregstatus.h" // Header file for this source file
|
|
19 |
#include "atgprsntwkregstatuschange.h" // for CATGprsNtwkRegStatusChange class
|
|
20 |
#include "mSLOGGER.H" // For LOGTEXT macros
|
|
21 |
#include "ATIO.H" // For CATIO class
|
|
22 |
#include "Matstd.h" // For AT command strings and timeout values
|
|
23 |
|
|
24 |
const TUint KWriteTimeout=10000; // Is in milli seconds
|
|
25 |
const TInt KReadTimeout=10; // Is in seconds
|
|
26 |
|
|
27 |
//
|
|
28 |
// Macro for logging text to the log file using the local class name and a simpler
|
|
29 |
// call style.
|
|
30 |
#ifdef __LOGDEB__
|
|
31 |
_LIT8(KLogEntry,"CATGprsNtwkRegStatus::%S\t%S");
|
|
32 |
#define LOCAL_LOGTEXT(function,text) {_LIT8(F,function);_LIT8(T,text);LOGTEXT3(KLogEntry,&F,&T);}
|
|
33 |
#else
|
|
34 |
#define LOCAL_LOGTEXT(function,text)
|
|
35 |
#endif
|
|
36 |
|
|
37 |
|
|
38 |
|
|
39 |
/**
|
|
40 |
* @file
|
|
41 |
* This file implements the CATGprsNtwkRegStatus class which is one of the state machine used by the
|
|
42 |
* GPRS AT TSY library.
|
|
43 |
* This state machine uses the "AT+CGREG?" command to find out the phones current network
|
|
44 |
* registration status.
|
|
45 |
*/
|
|
46 |
|
|
47 |
CATGprsNtwkRegStatus* CATGprsNtwkRegStatus::NewL(CATIO* aIo, CTelObject* aTelObject, CATInit* aInit, CPhoneGlobals* aPhoneGlobals,CATGprsNtwkRegStatusChange* aATGprsNtwkRegStatusChange)
|
|
48 |
/**
|
|
49 |
* Symbian standard factory function (also known as 1st stage constructor)
|
|
50 |
*/
|
|
51 |
{
|
|
52 |
CATGprsNtwkRegStatus* p=new(ELeave) CATGprsNtwkRegStatus(aIo, aTelObject, aInit, aPhoneGlobals,aATGprsNtwkRegStatusChange);
|
|
53 |
CleanupStack::PushL(p);
|
|
54 |
p->ConstructL();
|
|
55 |
CleanupStack::Pop();
|
|
56 |
return p;
|
|
57 |
}
|
|
58 |
|
|
59 |
void CATGprsNtwkRegStatus::ConstructL()
|
|
60 |
/**
|
|
61 |
* Symbian standard 2nd stage constructor
|
|
62 |
*/
|
|
63 |
{
|
|
64 |
// Allow our base class a chance to do its construction
|
|
65 |
CATCommands::ConstructL();
|
|
66 |
}
|
|
67 |
|
|
68 |
CATGprsNtwkRegStatus::CATGprsNtwkRegStatus(CATIO* aIo, CTelObject* aTelObject, CATInit* aInit, CPhoneGlobals* aPhoneGlobals,CATGprsNtwkRegStatusChange* aATGprsNtwkRegStatusChange)
|
|
69 |
: CATCommands(aIo, aTelObject, aInit, aPhoneGlobals),
|
|
70 |
iATGprsNtwkRegStatusChange(aATGprsNtwkRegStatusChange)
|
|
71 |
/**
|
|
72 |
* C++ Constructor
|
|
73 |
*/
|
|
74 |
{
|
|
75 |
}
|
|
76 |
|
|
77 |
CATGprsNtwkRegStatus::~CATGprsNtwkRegStatus()
|
|
78 |
/**
|
|
79 |
* C++ Destructor
|
|
80 |
*/
|
|
81 |
{
|
|
82 |
iIo->RemoveExpectStrings(this);
|
|
83 |
}
|
|
84 |
|
|
85 |
void CATGprsNtwkRegStatus::Start(TTsyReqHandle aTsyReqHandle, TAny* aParams)
|
|
86 |
/**
|
|
87 |
* This method called when a client wants to start the state machine
|
|
88 |
* and get the current network registration from the phone.
|
|
89 |
*/
|
|
90 |
{
|
|
91 |
// Save the data in the arguments in our class data for later use
|
|
92 |
iReqHandle = aTsyReqHandle;
|
|
93 |
iRegStatus = REINTERPRET_CAST(RPacketService::TRegistrationStatus*, aParams);
|
|
94 |
|
|
95 |
//
|
|
96 |
// Disable the +CRING watcher to ensure it does not steal the
|
|
97 |
// +CRING modem response from the modem
|
|
98 |
iATGprsNtwkRegStatusChange->Disable();
|
|
99 |
|
|
100 |
// Start the writing of the 'AT+CGREG?' command to the phone
|
|
101 |
iTxBuffer.Format(KGetCGREGCommand);
|
|
102 |
iIo->Write(this,iTxBuffer);
|
|
103 |
iIo->SetTimeOut(this,KWriteTimeout);
|
|
104 |
iState=EWaitForWrite;
|
|
105 |
}
|
|
106 |
|
|
107 |
void CATGprsNtwkRegStatus::Stop(TTsyReqHandle aTsyReqHandle)
|
|
108 |
/**
|
|
109 |
* This method called when a client wants to stop/cancel this state machine.
|
|
110 |
*/
|
|
111 |
{
|
|
112 |
LOCAL_LOGTEXT("Stop","Enter method");
|
|
113 |
if(iState!=EIdle && aTsyReqHandle==iReqHandle)
|
|
114 |
{
|
|
115 |
LOCAL_LOGTEXT("Stop","Cancelling client request");
|
|
116 |
Complete(KErrCancel,ETimeOutCompletion);
|
|
117 |
}
|
|
118 |
}
|
|
119 |
|
|
120 |
void CATGprsNtwkRegStatus::CompleteWithIOError(TEventSource aSource,TInt aStatus)
|
|
121 |
/**
|
|
122 |
* This Function completes the command from the client with an error.
|
|
123 |
* @param aSource source of event from communication class.
|
|
124 |
* @param aStatus status of event.
|
|
125 |
*/
|
|
126 |
{
|
|
127 |
LOCAL_LOGTEXT("CompleteWithIOError","Enter function");
|
|
128 |
Complete(aStatus, aSource);
|
|
129 |
}
|
|
130 |
|
|
131 |
|
|
132 |
void CATGprsNtwkRegStatus::Complete(TInt aError,TEventSource aSource)
|
|
133 |
/**
|
|
134 |
* This Function completes the command from the client.
|
|
135 |
* @param aError an error code to relay to client.
|
|
136 |
*/
|
|
137 |
{
|
|
138 |
LOGTEXT2(_L8("CATGprsNtwkRegStatus::Complete called error: %d"), aError);
|
|
139 |
|
|
140 |
// Cleanup our use of the CATIO class
|
|
141 |
RemoveStdExpectStrings();
|
|
142 |
iIo->WriteAndTimerCancel(this);
|
|
143 |
iIo->RemoveExpectStrings(this);
|
|
144 |
|
|
145 |
//
|
|
146 |
// Enable the +CRING watcher so it can get back to doing what it does
|
|
147 |
// best (ie. catching the unsolicted +CRING commands from the modem).
|
|
148 |
iATGprsNtwkRegStatusChange->Enable();
|
|
149 |
|
|
150 |
// Allow our base class to do its thing and then complete the client request
|
|
151 |
CATCommands::Complete(aError,aSource);
|
|
152 |
iTelObject->ReqCompleted(iReqHandle, aError);
|
|
153 |
|
|
154 |
iState=EIdle;
|
|
155 |
}
|
|
156 |
|
|
157 |
|
|
158 |
void CATGprsNtwkRegStatus::EventSignal(TEventSource aSource)
|
|
159 |
/**
|
|
160 |
* Main body of the state machine.
|
|
161 |
*
|
|
162 |
* This method with iState==EWaitForWrite when our
|
|
163 |
* 'AT+CGREG?' has been successfully sent to the phone/modem.
|
|
164 |
*
|
|
165 |
* This method with iState==EWaitForRead when received a response from the
|
|
166 |
* phone/modem.
|
|
167 |
*/
|
|
168 |
{
|
|
169 |
LOCAL_LOGTEXT("EventSignal","Enter method");
|
|
170 |
TInt ret(KErrNone);
|
|
171 |
|
|
172 |
if (aSource==ETimeOutCompletion)
|
|
173 |
{
|
|
174 |
//
|
|
175 |
// Catch timeout events
|
|
176 |
LOCAL_LOGTEXT("EventSignal","Timeout event");
|
|
177 |
Complete(KErrTimedOut,aSource);
|
|
178 |
}
|
|
179 |
else
|
|
180 |
{
|
|
181 |
//
|
|
182 |
// Process non-timeout events
|
|
183 |
switch(iState)
|
|
184 |
{
|
|
185 |
case EWaitForWrite:
|
|
186 |
LOCAL_LOGTEXT("EventSignal","EWaitForWrite event");
|
|
187 |
iIo->WriteAndTimerCancel(this);
|
|
188 |
StandardWriteCompletionHandler(aSource,KReadTimeout);
|
|
189 |
iState=EWaitForRead;
|
|
190 |
break;
|
|
191 |
|
|
192 |
case EWaitForRead:
|
|
193 |
LOCAL_LOGTEXT("EventSignal","EWaitForRead event");
|
|
194 |
ret = ValidateExpectString();
|
|
195 |
RemoveStdExpectStrings();
|
|
196 |
|
|
197 |
// If modem returned ERROR then assume the modem does not suport this command
|
|
198 |
if(ret!=KErrNone)
|
|
199 |
{
|
|
200 |
Complete(KErrNotSupported,aSource);
|
|
201 |
}
|
|
202 |
else
|
|
203 |
{
|
|
204 |
TRAP(ret,ParseResponseL());
|
|
205 |
Complete(ret,aSource);
|
|
206 |
}
|
|
207 |
break;
|
|
208 |
|
|
209 |
case EIdle: // All states must be included in the switch statement to
|
|
210 |
break; // prevent an ARM compilation warning
|
|
211 |
}
|
|
212 |
}
|
|
213 |
}
|
|
214 |
|
|
215 |
|
|
216 |
void CATGprsNtwkRegStatus::ParseResponseL()
|
|
217 |
/**
|
|
218 |
* This method parses the modems response to the 'AT+CGREG?' command.
|
|
219 |
* An example response is '+CGREG: 0,1' where second value denotes the
|
|
220 |
* current registration status.
|
|
221 |
*/
|
|
222 |
{
|
|
223 |
ParseBufferLC();
|
|
224 |
TDblQueIter<CATParamListEntry> iter(iRxResults);
|
|
225 |
CATParamListEntry* entry=iter++;
|
|
226 |
|
|
227 |
if((entry==NULL)||(entry->iResultPtr!=KCGREGResponseString))
|
|
228 |
{
|
|
229 |
LOCAL_LOGTEXT("ParseResponseL","Failed to find +CGREG:");
|
|
230 |
User::Leave(KErrNotSupported);
|
|
231 |
}
|
|
232 |
|
|
233 |
// Skip over first parameter
|
|
234 |
entry=iter++;
|
|
235 |
if(!entry)
|
|
236 |
{
|
|
237 |
LOCAL_LOGTEXT("ParseResponseL","Failed to find 1st parameter");
|
|
238 |
User::Leave(KErrNotFound);
|
|
239 |
}
|
|
240 |
|
|
241 |
// Read in second parameter
|
|
242 |
entry=iter++;
|
|
243 |
if(!entry)
|
|
244 |
{
|
|
245 |
LOCAL_LOGTEXT("ParseResponseL","Failed to find 2nd parameter");
|
|
246 |
User::Leave(KErrNotFound);
|
|
247 |
}
|
|
248 |
TInt etsiVal;
|
|
249 |
CATParamListEntry::EntryValL(entry,etsiVal);
|
|
250 |
|
|
251 |
// Convert scond value to equivalent EtelMM enum
|
|
252 |
switch(etsiVal)
|
|
253 |
{
|
|
254 |
case 0: // ETSI value as defined in ETSI 07.07 section 10.1.14
|
|
255 |
*iRegStatus=RPacketService::ENotRegisteredNotSearching;
|
|
256 |
break;
|
|
257 |
case 1: // ETSI value as defined in ETSI 07.07 section 10.1.14
|
|
258 |
*iRegStatus=RPacketService::ERegisteredOnHomeNetwork;
|
|
259 |
break;
|
|
260 |
case 2: // ETSI value as defined in ETSI 07.07 section 10.1.14
|
|
261 |
*iRegStatus=RPacketService::ENotRegisteredSearching;
|
|
262 |
break;
|
|
263 |
case 3: // ETSI value as defined in ETSI 07.07 section 10.1.14
|
|
264 |
*iRegStatus=RPacketService::ERegistrationDenied;
|
|
265 |
break;
|
|
266 |
case 4: // ETSI value as defined in ETSI 07.07 section 10.1.14
|
|
267 |
*iRegStatus=RPacketService::EUnknown;
|
|
268 |
break;
|
|
269 |
case 5: // ETSI value as defined in ETSI 07.07 section 10.1.14
|
|
270 |
*iRegStatus=RPacketService::ERegisteredRoaming;
|
|
271 |
break;
|
|
272 |
default:
|
|
273 |
*iRegStatus=RPacketService::EUnknown;
|
|
274 |
break;
|
|
275 |
}
|
|
276 |
|
|
277 |
CleanupStack::PopAndDestroy(); // Pop and destroy the object pushed by ParseBufferLC()
|
|
278 |
}
|
|
279 |
|