24
|
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 |
// Reads an SMS message present on the ME (mobile equipment). AT+CMGR=xx
|
|
15 |
//
|
|
16 |
//
|
|
17 |
|
|
18 |
#include <et_phone.h> // for TSY_HANDLE_INIT_VALUE
|
|
19 |
|
|
20 |
#include "panic.h" // Panic codes
|
|
21 |
#include "NOTIFY.H"
|
|
22 |
#include "mSMSMESS.H"
|
|
23 |
#include "mSMSREAD.H"
|
|
24 |
#include "mSLOGGER.H"
|
|
25 |
#include "ATIO.H"
|
|
26 |
#include "mSMSSTOR.H"
|
|
27 |
#include "ATINIT.H"
|
|
28 |
|
|
29 |
#ifdef __LOGDEB__
|
|
30 |
_LIT8(KLogEntry,"CATSmsMessagingRead::%S\t%S");
|
|
31 |
#define LOCAL_LOGTEXT(function,text) {_LIT8(F,function);_LIT8(T,text);LOGTEXT3(KLogEntry,&F,&T);}
|
|
32 |
#else
|
|
33 |
#define LOCAL_LOGTEXT(function,text)
|
|
34 |
#endif
|
|
35 |
|
|
36 |
|
|
37 |
|
|
38 |
CATSmsMessagingRead* CATSmsMessagingRead::NewL (CATIO* aIo, CTelObject* aTelObject,
|
|
39 |
CATInit* aInit, CPhoneGlobals* aMmStatus)
|
|
40 |
{
|
|
41 |
CATSmsMessagingRead* self = new (ELeave) CATSmsMessagingRead(aIo, aTelObject, aInit, aMmStatus);
|
|
42 |
CleanupStack::PushL(self);
|
|
43 |
self->ConstructL();
|
|
44 |
CleanupStack::Pop();
|
|
45 |
return self;
|
|
46 |
}
|
|
47 |
|
|
48 |
CATSmsMessagingRead::CATSmsMessagingRead(CATIO* aIo, CTelObject* aTelObject,
|
|
49 |
CATInit* aInit, CPhoneGlobals* aMmStatus)
|
|
50 |
:CATSmsCommands(aIo, aTelObject, aInit, aMmStatus),
|
|
51 |
iSmsStore(reinterpret_cast<CMobileSmsStore*>(aTelObject)),
|
|
52 |
iCancelled(EFalse)
|
|
53 |
{}
|
|
54 |
|
|
55 |
|
|
56 |
void CATSmsMessagingRead::Start(TTsyReqHandle aTsyReqHandle, TAny* aParams)
|
|
57 |
{
|
|
58 |
__ASSERT_DEBUG(aParams,Panic(EMobileSmsMessagingNullParameter));
|
|
59 |
__ASSERT_DEBUG(aTsyReqHandle!=TSY_HANDLE_INIT_VALUE,Panic(EMobileSmsMessagingNullParameter));
|
|
60 |
|
|
61 |
// Save the parameters into our class data
|
|
62 |
iReqHandle = aTsyReqHandle;
|
|
63 |
iCancelled=EFalse;
|
|
64 |
iMsgEntry = reinterpret_cast<RMobileSmsStore::TMobileGsmSmsEntryV1*>(aParams);
|
|
65 |
|
|
66 |
iMsgLocation=iMsgEntry->iIndex;
|
|
67 |
|
|
68 |
iShortStoreName = iSmsStore->iStoreName;
|
|
69 |
|
|
70 |
// Change iPhoneGlobals->iMmTsyEventSignalActive so system knows that our EventSignal
|
|
71 |
// is active and requires sole use of the serial link to the phone.
|
|
72 |
if (ComparePrefMem(iShortStoreName))
|
|
73 |
{
|
|
74 |
// the compared memories are the same, so we can
|
|
75 |
// start reading the message from the phone
|
|
76 |
StartReadSequence();
|
|
77 |
}
|
|
78 |
else
|
|
79 |
{
|
|
80 |
// the compared memories are different, must change
|
|
81 |
// phone mem to temporary mem.
|
|
82 |
SetCurrentPrefMem(iShortStoreName);
|
|
83 |
iState = EATWaitForSendingPrefMemComplete;
|
|
84 |
}
|
|
85 |
}
|
|
86 |
|
|
87 |
|
|
88 |
void CATSmsMessagingRead::StartReadSequence()
|
|
89 |
{
|
|
90 |
iTxBuffer.Format(KSmsReadCommand, iMsgLocation);
|
|
91 |
iIo->Write(this, iTxBuffer);
|
|
92 |
iIo->SetTimeOut(this, 5000);
|
|
93 |
iState = EATWaitForSendingCMGRRequestComplete;
|
|
94 |
}
|
|
95 |
|
|
96 |
|
|
97 |
void CATSmsMessagingRead::EventSignal(TEventSource aSource)
|
|
98 |
//
|
|
99 |
// Finite State Machine for handling events from the comm port
|
|
100 |
//
|
|
101 |
{
|
|
102 |
LOGTEXT2(_L8("CATSmsMessagingRead:\tiState = %D"), iState);
|
|
103 |
if (aSource == ETimeOutCompletion)
|
|
104 |
{
|
|
105 |
LOGTEXT(_L8("CATSmsMessagingRead:\tTimeout Error during Sms Messaging Read"));
|
|
106 |
iPhoneGlobals->iPhoneStatus.iModemDetected = RPhone::EDetectedNotPresent;
|
|
107 |
RemoveStdExpectStrings();
|
|
108 |
if ((iState != EATWaitForPrefMemResponse) && (!ComparePrefMem(iShortStoreName)))
|
|
109 |
iPhoneGlobals->iPhonePrefMem = iShortStoreName;
|
|
110 |
if (iCancelled)
|
|
111 |
Complete(KErrCancel, aSource);
|
|
112 |
else
|
|
113 |
Complete(KErrTimedOut, aSource);
|
|
114 |
return;
|
|
115 |
}
|
|
116 |
|
|
117 |
switch (iState)
|
|
118 |
{
|
|
119 |
case EATWaitForSendingPrefMemComplete:
|
|
120 |
__ASSERT_ALWAYS(aSource == EWriteCompletion, Panic(EATCommand_IllegalCompletionWriteExpected));
|
|
121 |
{
|
|
122 |
iIo->WriteAndTimerCancel(this);
|
|
123 |
StandardWriteCompletionHandler(aSource, 5);
|
|
124 |
iState = EATWaitForPrefMemResponse;
|
|
125 |
}
|
|
126 |
break;
|
|
127 |
|
|
128 |
case EATWaitForPrefMemResponse:
|
|
129 |
__ASSERT_ALWAYS(aSource == EReadCompletion, Panic(EATCommand_IllegalCompletionReadExpected));
|
|
130 |
{
|
|
131 |
iIo->WriteAndTimerCancel(this);
|
|
132 |
RemoveStdExpectStrings();
|
|
133 |
TInt pos=iIo->BufferFindF(KCPMSResponseString);
|
|
134 |
if (pos == KErrNotFound)
|
|
135 |
{
|
|
136 |
LOGTEXT(_L8("CATSmsMessagingRead:\tCould not set preferred memory to client's pref'd mem"));
|
|
137 |
Complete(pos, aSource);
|
|
138 |
return;
|
|
139 |
}
|
|
140 |
LOGTEXT(_L8("CATSmsMessagingRead:\tPhone's pref'd memory successfully set to client's pref'd mem"));
|
|
141 |
iPhoneGlobals->iPhonePrefMem=iShortStoreName;
|
|
142 |
if (iCancelled)
|
|
143 |
Complete(KErrCancel,aSource);
|
|
144 |
else
|
|
145 |
StartReadSequence();
|
|
146 |
}
|
|
147 |
break;
|
|
148 |
|
|
149 |
case EATWaitForSendingCMGRRequestComplete:
|
|
150 |
__ASSERT_ALWAYS(aSource == EWriteCompletion, Panic(EATCommand_IllegalCompletionWriteExpected));
|
|
151 |
iIo->WriteAndTimerCancel(this);
|
|
152 |
StandardWriteCompletionHandler(aSource, 50);
|
|
153 |
AddCmsErrorExpectString(); // Defect fix 2/7/00, see "release.txt"
|
|
154 |
iState=EATWaitForCMGRResponseComplete;
|
|
155 |
break;
|
|
156 |
|
|
157 |
case EATWaitForCMGRResponseComplete:
|
|
158 |
__ASSERT_ALWAYS(aSource == EReadCompletion, Panic(EATCommand_IllegalCompletionReadExpected));
|
|
159 |
{
|
|
160 |
iIo->WriteAndTimerCancel(this);
|
|
161 |
RemoveStdExpectStrings();
|
|
162 |
RemoveCmsErrorExpectString(); // Defect fix 2/7/00, see "release.txt"
|
|
163 |
TRAPD(ret, CMGRResponseL());
|
|
164 |
|
|
165 |
if ((iMsgLength==0) && (ret==KErrNone))
|
|
166 |
{
|
|
167 |
LOGTEXT(_L8("CATSmsMessagingRead:\tThe Client has Read from a message location that is empty"));
|
|
168 |
ret=KErrNotFound;
|
|
169 |
}
|
|
170 |
Complete(ret,aSource);
|
|
171 |
}
|
|
172 |
break;
|
|
173 |
|
|
174 |
default:
|
|
175 |
break;
|
|
176 |
}
|
|
177 |
}
|
|
178 |
|
|
179 |
void CATSmsMessagingRead::CMGRResponseL()
|
|
180 |
//
|
|
181 |
// Parse the +CMGR: message from the ME.
|
|
182 |
// It is of the form +CMGR: <Msg Status>,<Msg Length> <New line> PDU
|
|
183 |
//
|
|
184 |
{
|
|
185 |
ParseBufferLC();
|
|
186 |
CATParamListEntry* entry;
|
|
187 |
TDblQueIter<CATParamListEntry> iter(iRxResults);
|
|
188 |
iMsgLength = 0;
|
|
189 |
|
|
190 |
entry=iter++;
|
|
191 |
if((!entry)||(entry->iResultPtr!=KCMGRResponseString))
|
|
192 |
User::Leave(KErrNotFound);
|
|
193 |
|
|
194 |
LOGTEXT(_L8("CATSmsMessagingRead:\tFound +CMGR String!"));
|
|
195 |
|
|
196 |
// Read the message status
|
|
197 |
entry=iter++;
|
|
198 |
if(!entry)
|
|
199 |
User::Leave(KErrGeneral);
|
|
200 |
TLex8 msgStatLex((entry->iResultPtr).Ptr());
|
|
201 |
TUint msgStat;
|
|
202 |
(void)User::LeaveIfError(msgStatLex.Val(msgStat));
|
|
203 |
|
|
204 |
// Read the message length
|
|
205 |
entry=iter++;
|
|
206 |
if(!entry)
|
|
207 |
User::Leave(KErrGeneral);
|
|
208 |
if(entry->iResultPtr.Length()==0)
|
|
209 |
{
|
|
210 |
entry=iter++;
|
|
211 |
if(!entry)
|
|
212 |
User::Leave(KErrGeneral);
|
|
213 |
}
|
|
214 |
|
|
215 |
TLex8 msgLenLex((entry->iResultPtr).Ptr());
|
|
216 |
(void)User::LeaveIfError(msgLenLex.Val(iMsgLength));
|
|
217 |
|
|
218 |
entry=iter++;
|
|
219 |
if(!entry)
|
|
220 |
User::Leave(KErrGeneral);
|
|
221 |
|
|
222 |
TSpecialPdu asciiPdu;
|
|
223 |
asciiPdu = entry->iResultPtr;
|
|
224 |
|
|
225 |
(void)User::LeaveIfError(CATSmsUtils::ConvertAsciiToBinary(asciiPdu,iPdu));
|
|
226 |
TPtrC8 pduPtr(iPdu);
|
|
227 |
|
|
228 |
if (iMsgLength*2 != asciiPdu.Length())
|
|
229 |
{
|
|
230 |
// There is an SCA prepended so remove this and store it in iGsmServiceCentre
|
|
231 |
PopulateScaFieldsAndRemove(pduPtr,iGsmServiceCentre);
|
|
232 |
}
|
|
233 |
|
|
234 |
if(iMsgEntry)
|
|
235 |
{
|
|
236 |
iMsgEntry->iMsgData.Copy(pduPtr);
|
|
237 |
iMsgEntry->iMsgStatus = GsmMsgStatusToStoreStatus(msgStat);
|
|
238 |
}
|
|
239 |
|
|
240 |
CleanupStack::PopAndDestroy();
|
|
241 |
}
|
|
242 |
|
|
243 |
|
|
244 |
void CATSmsMessagingRead::PopulateScaFieldsAndRemove(TPtrC8& aPdu, RMobilePhone::TMobileAddress& aGsmServiceCentre)
|
|
245 |
//
|
|
246 |
// Populate the SCA field in the MM ETel structure from the SCA prepended in a received PDU.
|
|
247 |
//
|
|
248 |
{
|
|
249 |
const TUint8 KTONBitMask =0x70;
|
|
250 |
const TUint8 KNPIBitMask=0x0f;
|
|
251 |
const TUint8 KTONBitShift=4;
|
|
252 |
const TUint8 KNPIBitShift=0;
|
|
253 |
_LIT(KInternationalPrefix,"+");
|
|
254 |
|
|
255 |
__ASSERT_ALWAYS(aPdu.Length()>0,Panic(ECMTHandlerDesPassedWithZeroLength));
|
|
256 |
|
|
257 |
aGsmServiceCentre.iTypeOfNumber=(RMobilePhone::TMobileTON)0;
|
|
258 |
aGsmServiceCentre.iNumberPlan=(RMobilePhone::TMobileNPI)0;
|
|
259 |
aGsmServiceCentre.iTelNumber.Zero();
|
|
260 |
|
|
261 |
TUint8 len=aPdu[0];
|
|
262 |
|
|
263 |
if(len==0)
|
|
264 |
{
|
|
265 |
// A zero length SCA has been prepended - just strip this first byte off
|
|
266 |
aPdu.Set(aPdu.Mid(len+1));
|
|
267 |
return;
|
|
268 |
}
|
|
269 |
|
|
270 |
TUint8 numDes=aPdu[1];
|
|
271 |
aGsmServiceCentre.iTypeOfNumber=(RMobilePhone::TMobileTON)((numDes&KTONBitMask)>>KTONBitShift);
|
|
272 |
aGsmServiceCentre.iNumberPlan=(RMobilePhone::TMobileNPI)((numDes&KNPIBitMask)>>KNPIBitShift);
|
|
273 |
|
|
274 |
if(aGsmServiceCentre.iTypeOfNumber==RMobilePhone::EInternationalNumber)
|
|
275 |
aGsmServiceCentre.iTelNumber.Append(KInternationalPrefix);
|
|
276 |
|
|
277 |
TInt i;
|
|
278 |
TUint16 digit;
|
|
279 |
for(i=2;i<(len+1);i++)
|
|
280 |
{
|
|
281 |
digit=(TUint16)((aPdu[i]&0x0f)+0x30);
|
|
282 |
aGsmServiceCentre.iTelNumber.Append(digit);
|
|
283 |
digit=(TUint16)(((aPdu[i]&0xf0)>>4)+0x30);
|
|
284 |
if(digit==0x003f) // 'F' is the padding digit at the end of a number
|
|
285 |
break;
|
|
286 |
aGsmServiceCentre.iTelNumber.Append(digit);
|
|
287 |
}
|
|
288 |
aPdu.Set(aPdu.Mid(len+1));
|
|
289 |
}
|
|
290 |
|
|
291 |
void CATSmsMessagingRead::Stop(TTsyReqHandle aTsyReqHandle)
|
|
292 |
//
|
|
293 |
// Attempts to halt the process
|
|
294 |
//
|
|
295 |
{
|
|
296 |
LOCAL_LOGTEXT("Stop","Enter function");
|
|
297 |
__ASSERT_ALWAYS(aTsyReqHandle == iReqHandle,Panic(EIllegalTsyReqHandle));
|
|
298 |
|
|
299 |
LOGTEXT2(_L8("Current state TSY is cancelling from %d"), iState);
|
|
300 |
// Wait for convenient place in state machine to cancel
|
|
301 |
iCancelled=ETrue;
|
|
302 |
}
|
|
303 |
|
|
304 |
void CATSmsMessagingRead::Complete(TTsyReqHandle aReqHandle,TInt aError)
|
|
305 |
{
|
|
306 |
iReqHandle=aReqHandle;
|
|
307 |
Complete(aError, EReadCompletion);
|
|
308 |
}
|
|
309 |
|
|
310 |
void CATSmsMessagingRead::Complete(TInt aError,TEventSource aSource)
|
|
311 |
{
|
|
312 |
LOCAL_LOGTEXT("Complete","Enter function");
|
|
313 |
iIo->WriteAndTimerCancel(this);
|
|
314 |
iIo->RemoveExpectStrings(this);
|
|
315 |
iOKExpectString = NULL;
|
|
316 |
iErrorExpectString = NULL;
|
|
317 |
iPhoneGlobals->iEventSignalActive = EFalse;
|
|
318 |
if (iReqHandle != 0)
|
|
319 |
iTelObject->ReqCompleted(iReqHandle, aError);
|
|
320 |
if (aSource==EWriteCompletion)
|
|
321 |
iIo->Read();
|
|
322 |
|
|
323 |
//
|
|
324 |
// Call our base classes Complete so that
|
|
325 |
// we allow it do what ever it needs to do.
|
|
326 |
CATCommands::Complete(aError,aSource);
|
|
327 |
|
|
328 |
LOCAL_LOGTEXT("Complete","Exit function");
|
|
329 |
}
|
|
330 |
|
|
331 |
|
|
332 |
void CATSmsMessagingRead::CompleteWithIOError(TEventSource /*aSource*/,TInt aStatus)
|
|
333 |
{
|
|
334 |
if (iState!=EATNotInProgress)
|
|
335 |
{
|
|
336 |
iIo->WriteAndTimerCancel(this);
|
|
337 |
iMsgLocation=NULL;
|
|
338 |
iTelObject->ReqCompleted(iReqHandle, aStatus);
|
|
339 |
iState = EATNotInProgress;
|
|
340 |
}
|
|
341 |
}
|
|
342 |
|
|
343 |
RMobileSmsStore::TMobileSmsStoreStatus CATSmsMessagingRead::GsmMsgStatusToStoreStatus(TInt aMsgStat)
|
|
344 |
/**
|
|
345 |
* This method converts a GSM message status to Multimode message satus.
|
|
346 |
*/
|
|
347 |
{
|
|
348 |
switch (aMsgStat)
|
|
349 |
{
|
|
350 |
case 0: // The SMS is received but unread
|
|
351 |
return RMobileSmsStore::EStoredMessageUnread;
|
|
352 |
case 1: // The SMS is received and read
|
|
353 |
return RMobileSmsStore::EStoredMessageRead;
|
|
354 |
case 2: // The SMS is stored but unsent
|
|
355 |
return RMobileSmsStore::EStoredMessageUnsent;
|
|
356 |
case 3: // The SMS is stored and Sent
|
|
357 |
return RMobileSmsStore::EStoredMessageSent;
|
|
358 |
|
|
359 |
default: // All other status values
|
|
360 |
return RMobileSmsStore::EStoredMessageUnknownStatus;
|
|
361 |
}
|
|
362 |
}
|
|
363 |
|