|
1 // Copyright (c) 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 // @file atsmsreceive.cpp |
|
15 // This contains CAtSmsReceive which received incoming messages |
|
16 // |
|
17 |
|
18 //system include |
|
19 #include <etelmm.h> |
|
20 #include <ctsy/ltsy/cctsydispatchercallback.h> |
|
21 |
|
22 //user include |
|
23 #include "atsmsreceive.h" |
|
24 #include "atsmsstoreread.h" |
|
25 #include "atsmsack.h" |
|
26 #include "atmanager.h" |
|
27 #include "activecommandstore.h" |
|
28 #include "mslogger.h" |
|
29 #include "smsatutil.h" |
|
30 |
|
31 //constant defination |
|
32 _LIT8(KCMTMatchString,"+CMT:*"); |
|
33 _LIT8(KCMTResponseString,"+CMT:"); |
|
34 _LIT8(KAsterisk,"*"); |
|
35 |
|
36 #ifdef _DEBUG |
|
37 const TInt KLogMaxCharNumPerLine = 160; |
|
38 #endif |
|
39 // --------------------------------------------------------------------------- |
|
40 // CAtSmsReceive::CAtSmsReceive |
|
41 // other items were commented in a header |
|
42 // --------------------------------------------------------------------------- |
|
43 CAtSmsReceive::CAtSmsReceive(CGlobalPhonemanager& aGloblePhone, |
|
44 CCtsyDispatcherCallback& aCtsyDispatcherCallback) |
|
45 :CAtCommandBase(aGloblePhone,aCtsyDispatcherCallback) |
|
46 { |
|
47 LOGTEXT(_L8("CAtSmsReceive::CAtSmsReceive called")); |
|
48 iAtType = ELtsyAT_Sms_ReceiveMessage; |
|
49 } |
|
50 |
|
51 // --------------------------------------------------------------------------- |
|
52 // CAtSmsReceive::~CAtSmsReceive |
|
53 // other items were commented in a header |
|
54 // --------------------------------------------------------------------------- |
|
55 CAtSmsReceive::~CAtSmsReceive() |
|
56 { |
|
57 LOGTEXT(_L8("CAtSmsReceive::~CAtSmsReceive called")); |
|
58 RemoveAllExpectString(); |
|
59 } |
|
60 |
|
61 // --------------------------------------------------------------------------- |
|
62 // CAtSmsReceive::NewLC |
|
63 // other items were commented in a header |
|
64 // --------------------------------------------------------------------------- |
|
65 CAtSmsReceive* CAtSmsReceive::NewLC(CGlobalPhonemanager& aGloblePhone, |
|
66 CCtsyDispatcherCallback& aCtsyDispatcherCallback) |
|
67 { |
|
68 CAtSmsReceive* self = new (ELeave)CAtSmsReceive(aGloblePhone, |
|
69 aCtsyDispatcherCallback); |
|
70 CleanupStack::PushL(self); |
|
71 self->ConstructL(); |
|
72 return self; |
|
73 } |
|
74 |
|
75 // --------------------------------------------------------------------------- |
|
76 // CAtSmsReceive::NewL |
|
77 // other items were commented in a header |
|
78 // --------------------------------------------------------------------------- |
|
79 CAtSmsReceive* CAtSmsReceive::NewL(CGlobalPhonemanager& aGloblePhone, |
|
80 CCtsyDispatcherCallback& aCtsyDispatcherCallback) |
|
81 { |
|
82 CAtSmsReceive* self=CAtSmsReceive::NewLC(aGloblePhone, |
|
83 aCtsyDispatcherCallback); |
|
84 CleanupStack::Pop(self); |
|
85 return self; |
|
86 } |
|
87 |
|
88 // --------------------------------------------------------------------------- |
|
89 // CAtSmsReceive::ConstructL |
|
90 // other items were commented in a header |
|
91 // --------------------------------------------------------------------------- |
|
92 void CAtSmsReceive::ConstructL() |
|
93 { |
|
94 CAtCommandBase::ConstructL(); |
|
95 //Add expecting string |
|
96 RemoveAllExpectString(); |
|
97 AddExpectStringL(KCMTMatchString); |
|
98 } |
|
99 |
|
100 // --------------------------------------------------------------------------- |
|
101 // CAtSmsReceive::StartRequest |
|
102 // other items were commented in a header |
|
103 // --------------------------------------------------------------------------- |
|
104 void CAtSmsReceive::StartRequest() |
|
105 { |
|
106 iState = EReceiveReady; |
|
107 iPhoneGlobals.iAtManager->GetActiveCommandStore()->AddUnsolicitedAtCommand(this); |
|
108 } |
|
109 |
|
110 // --------------------------------------------------------------------------- |
|
111 // CAtSmsReceive::ExecuteCommand |
|
112 // other items were commented in a header |
|
113 // --------------------------------------------------------------------------- |
|
114 void CAtSmsReceive::ExecuteCommand() |
|
115 { |
|
116 |
|
117 } |
|
118 |
|
119 // --------------------------------------------------------------------------- |
|
120 // CAtSmsReceive::EventSignal |
|
121 // other items were commented in a header |
|
122 // --------------------------------------------------------------------------- |
|
123 void CAtSmsReceive::EventSignal(TAtEventSource /*aEventSource*/, TInt aStatus) |
|
124 /** |
|
125 * Handle the events from the comm port |
|
126 *ValidateExpectString |
|
127 * @param aSource denotes if event is due to read, write or timeout |
|
128 */ |
|
129 { |
|
130 if(aStatus != KErrNone) |
|
131 { |
|
132 iCtsyDispatcherCallback.CallbackSmsNotifyReceiveSmsMessageInd(iError,EFalse,iMsgReceive); |
|
133 return; |
|
134 } |
|
135 |
|
136 if( iState == EReceiveReady ) |
|
137 { |
|
138 LOGTEXT(_L8("CAtSmsReceive::EventSigna,EReadCompletion")); |
|
139 //Handle CMT response |
|
140 if (iError == KErrNone) |
|
141 { |
|
142 //want to read the second line |
|
143 TRAPD(err,AddExpectStringL(KAsterisk)); |
|
144 if( err==KErrNone ) |
|
145 { |
|
146 // Wait for the reception of the second line |
|
147 iState=EWaitForCmtSecondLine; |
|
148 return; |
|
149 } |
|
150 else |
|
151 { |
|
152 iError = err; |
|
153 } |
|
154 } |
|
155 iCtsyDispatcherCallback.CallbackSmsNotifyReceiveSmsMessageInd(iError,EFalse,iMsgReceive); |
|
156 } |
|
157 else if( iState == EWaitForCmtSecondLine ) |
|
158 { |
|
159 LOGTEXT(_L8("CAtSmsReceiveMessage::EventSignal EWaitForCmtSecondLine")); |
|
160 RemoveExpectString(KAsterisk); |
|
161 iCtsyDispatcherCallback.CallbackSmsNotifyReceiveSmsMessageInd(iError,EFalse,iMsgReceive); |
|
162 // We've got the PDU, and will delete the buffer when the line is parsed |
|
163 if(iPhoneGlobals.iEventSignalActive == EFalse) |
|
164 { |
|
165 ClearBuffer(); |
|
166 } |
|
167 iState = EReceiveReady; |
|
168 } |
|
169 |
|
170 } |
|
171 |
|
172 // --------------------------------------------------------------------------- |
|
173 // CAtSmsReceive::CMTResponseFirstLineL |
|
174 // other items were commented in a header |
|
175 // --------------------------------------------------------------------------- |
|
176 void CAtSmsReceive::CMTResponseFirstLineL() |
|
177 { |
|
178 LOGTEXT(_L8("CAtSmsReceive::CMTResponseFirstLineL Enter funciton")); |
|
179 iError = KErrNone; |
|
180 TPtrC8 firstLineBuf; |
|
181 firstLineBuf.Set(Buffer()); |
|
182 TInt pos = firstLineBuf.FindF(KCMTResponseString); |
|
183 if (pos == KErrNotFound) |
|
184 { |
|
185 LOGTEXT(_L8("CAtSmsReceive::CMTResponseFirstLineL()\tError - Cannot find '+CMT:' string")); |
|
186 iError = KErrNotFound; |
|
187 return; |
|
188 } |
|
189 //skip the string of +CMT: |
|
190 pos += KCMTResponseString().Length(); |
|
191 //skip a "," character |
|
192 while(!(TChar(firstLineBuf[pos]).IsDigit())) |
|
193 { |
|
194 ++pos; |
|
195 } |
|
196 TInt lenPos = firstLineBuf.Length()-pos; |
|
197 TPtrC8 pduLenBuf; |
|
198 pduLenBuf.Set(firstLineBuf.Right(lenPos)); |
|
199 |
|
200 |
|
201 TLex8 lex(pduLenBuf); |
|
202 TUint16 val; |
|
203 TInt ret = lex.Val(val,EDecimal); |
|
204 if(ret != KErrNone) |
|
205 { |
|
206 iError = ret; |
|
207 return; |
|
208 } |
|
209 iPduLen = val; |
|
210 LOGTEXT2(_L8("New SMS detected of length %d"),iPduLen); |
|
211 } |
|
212 |
|
213 // --------------------------------------------------------------------------- |
|
214 // CAtSmsReceive::CMTResponseSecondLineL |
|
215 // other items were commented in a header |
|
216 // --------------------------------------------------------------------------- |
|
217 void CAtSmsReceive::CMTResponseSecondLineL() |
|
218 { |
|
219 LOGTEXT(_L8("CAtSmsReceive::CMTResponseSecondLineL Enter funciton")); |
|
220 iError = KErrNone; |
|
221 iAttr.iFlags=0; |
|
222 TPtrC8 secondLineBuf; |
|
223 secondLineBuf.Set(CurrentLine()); |
|
224 |
|
225 #ifdef _DEBUG |
|
226 TInt totalLen = secondLineBuf.Length(); |
|
227 if(totalLen <= KLogMaxCharNumPerLine) |
|
228 { |
|
229 LOGTEXT2(_L8("CAtSmsReceiveMessage::CMTResponseSecondLineL\tSecondLine=%S"),&secondLineBuf); |
|
230 } |
|
231 else |
|
232 { |
|
233 TInt lines = (totalLen/KLogMaxCharNumPerLine); |
|
234 TInt remainingStrNum = (totalLen%KLogMaxCharNumPerLine); |
|
235 for(TInt i = 0; i < lines; i++) |
|
236 { |
|
237 TPtrC8 line(secondLineBuf.Mid(i*KLogMaxCharNumPerLine,KLogMaxCharNumPerLine)); |
|
238 LOGTEXT2(_L8("CAtSmsReceiveMessage::CMTResponseSecondLineL \tSecondLine line=%S"),&line); |
|
239 } |
|
240 |
|
241 TPtrC8 remaining(secondLineBuf.Right(remainingStrNum)); |
|
242 |
|
243 LOGTEXT2(_L8("CAtSmsReceiveMessage::CMTResponseSecondLineL \tSecondLine line=%S"),&remaining); |
|
244 } |
|
245 #endif |
|
246 // Buffer size calculated as follows; |
|
247 // (max pdu size + max prefixed SCA size) * number of ASCII chars used to code an octet |
|
248 TBuf8<(RMobileSmsMessaging::KGsmTpduSize+12)*2> localPdu; |
|
249 localPdu.Copy(secondLineBuf); |
|
250 // The CMT frame sometimes contains odd number of nibbles which |
|
251 // causes panic in ConvertAsciiToBinary() method. This type of |
|
252 // frames will simply be discarded. |
|
253 if(localPdu.Length() < (iPduLen*2)) |
|
254 { |
|
255 iError = KErrUnderflow; |
|
256 User::Leave(KErrUnderflow); |
|
257 } |
|
258 |
|
259 // |
|
260 // Check if we have a prefixed SCA on our pdu. |
|
261 // If we do then remove it. |
|
262 |
|
263 if(localPdu.Length() > (iPduLen*2)) |
|
264 { |
|
265 TInt ret = SmsAtUtil::ReadAndRemoveAddressFromAscii(localPdu,iAttr.iGsmServiceCentre); |
|
266 if(ret !=KErrNone) |
|
267 { |
|
268 LOGTEXT(_L8("CAtSmsReceiveMessage::CMTResponseSecondLineL Failed to read and remove SCA from PDU")); |
|
269 iError = ret; |
|
270 return; |
|
271 } |
|
272 else |
|
273 { |
|
274 iMsgReceive.iServiceCentre = iAttr.iGsmServiceCentre.iTelNumber; //for iServiceCentre |
|
275 iMsgReceive.iMobileScNPI = iAttr.iGsmServiceCentre.iNumberPlan; |
|
276 iMsgReceive.iMobileScTON = iAttr.iGsmServiceCentre.iTypeOfNumber; |
|
277 iAttr.iFlags|= RMobileSmsMessaging::KGsmServiceCentre; |
|
278 } |
|
279 } |
|
280 // |
|
281 // Convert received pdu from ASCII into binary |
|
282 TInt ret = SmsAtUtil::ConvertAsciiToBinary(localPdu,iPdu); |
|
283 if (ret!=KErrNone) |
|
284 { |
|
285 LOGTEXT(_L8("CAtSmsReceiveMessage::CMTResponseSecondLineL Failed to code PDU into binary")); |
|
286 iError = ret; |
|
287 return; |
|
288 } |
|
289 else |
|
290 { |
|
291 iAttr.iDataFormat=RMobileSmsMessaging::EFormatGsmTpdu; |
|
292 iAttr.iFlags|=RMobileSmsMessaging::KSmsDataFormat; |
|
293 iAttr.iStatus = RMobileSmsMessaging::EMtMessageUnstoredClientAck; |
|
294 iAttr.iFlags|=RMobileSmsMessaging::KIncomingStatus; |
|
295 } |
|
296 |
|
297 LOGTEXT2(_L8("Received PDU String is %S"),&iPdu); |
|
298 iMsgReceive.iSmsMsg = iPdu; |
|
299 } |
|
300 |
|
301 // --------------------------------------------------------------------------- |
|
302 // CAtSmsReceive::ParseResponseL |
|
303 // other items were commented in a header |
|
304 // --------------------------------------------------------------------------- |
|
305 void CAtSmsReceive::ParseResponseL(const TDesC8& /*aResponseBuf*/) |
|
306 { |
|
307 if(iState == EReceiveReady) |
|
308 { |
|
309 CMTResponseFirstLineL(); |
|
310 } |
|
311 else if(iState == EWaitForCmtSecondLine) |
|
312 { |
|
313 CMTResponseSecondLineL(); |
|
314 } |
|
315 } |
|
316 |
|
317 //End of file |