|
1 // Copyright (c) 2000-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 // Deal with Network & Operator information |
|
15 // |
|
16 // |
|
17 |
|
18 #include <et_phone.h> |
|
19 #include "Mownnum.h" |
|
20 #include "mSLOGGER.H" |
|
21 #include "ATIO.H" |
|
22 #include "Matstd.h" |
|
23 #include <etelmm.h> |
|
24 #include <mmlist.h> |
|
25 #include "et_phone_util.h" |
|
26 |
|
27 // Get the own numbers from the phone |
|
28 // NB - not supported by all phones. |
|
29 |
|
30 _LIT8(KGetOwnNumbersCommand,"AT+CNUM"); |
|
31 _LIT8(KGetOwnNumbersResponse,"+CNUM"); |
|
32 |
|
33 CATOwnNumbers::CATOwnNumbers(CATIO* aIo, CTelObject* aTelObject, CATInit* aInit,CPhoneGlobals* aPhoneGlobals) |
|
34 : CATCommands(aIo,aTelObject,aInit,aPhoneGlobals) |
|
35 {} |
|
36 |
|
37 CATOwnNumbers* CATOwnNumbers::NewL(CATIO* aIo,CTelObject* aTelObject,CATInit* aInit,CPhoneGlobals* aPhoneGlobals) |
|
38 { |
|
39 CATOwnNumbers* self = new(ELeave) CATOwnNumbers(aIo, aTelObject, aInit, aPhoneGlobals); |
|
40 CleanupStack::PushL(self); |
|
41 self->ConstructL(); |
|
42 CleanupStack::Pop(); |
|
43 return self; |
|
44 } |
|
45 |
|
46 CATOwnNumbers::~CATOwnNumbers() |
|
47 { |
|
48 if (iIo != NULL) |
|
49 { |
|
50 iIo->RemoveExpectStrings(this); |
|
51 } |
|
52 delete iOwnNumbers; |
|
53 } |
|
54 |
|
55 void CATOwnNumbers::Start(TTsyReqHandle aTsyReqHandle, TAny* /*aParam*/) |
|
56 { |
|
57 LOGTEXT(_L8("MMTsy:\tCATOwnNumbers:\tStarting Get Own Number")); |
|
58 iReqHandle = aTsyReqHandle; |
|
59 WriteExpectingResults(KGetOwnNumbersCommand, 3); |
|
60 __ASSERT_ALWAYS(iIo->AddExpectString(this,KNotifyMeIfErrorString) != NULL,Panic(EGeneral)); |
|
61 iState=EATImsiWaitForWriteComplete; |
|
62 } |
|
63 |
|
64 void CATOwnNumbers::EventSignal(TEventSource aSource) |
|
65 { |
|
66 if (aSource==ETimeOutCompletion) |
|
67 { |
|
68 LOGTEXT(_L8("MMTsy:\tCATOwnNumbers:\tTimeout Error during Get Own Number read")); |
|
69 RemoveStdExpectStrings(); |
|
70 Complete(KErrTimedOut,aSource); |
|
71 return; |
|
72 } |
|
73 |
|
74 switch(iState) |
|
75 { |
|
76 case EATImsiWaitForWriteComplete: |
|
77 __ASSERT_ALWAYS(aSource==EWriteCompletion,Panic(EATCommand_IllegalCompletionWriteExpected)); |
|
78 { |
|
79 iIo->WriteAndTimerCancel(this); |
|
80 StandardWriteCompletionHandler(aSource, 5); |
|
81 iState=EATImsiReadComplete; |
|
82 } |
|
83 break; |
|
84 |
|
85 case EATImsiReadComplete: |
|
86 __ASSERT_ALWAYS(aSource==EReadCompletion,Panic(EATCommand_IllegalCompletionReadExpected)); |
|
87 { |
|
88 iIo->WriteAndTimerCancel(this); |
|
89 TInt ret(ValidateExpectString()); |
|
90 RemoveStdExpectStrings(); |
|
91 if (ret==KErrNone) |
|
92 TRAP(ret,ParseResponseL()); |
|
93 Complete(ret,aSource); |
|
94 } |
|
95 break; |
|
96 |
|
97 case EATWaitForStopState: |
|
98 __ASSERT_ALWAYS(aSource==EReadCompletion, Panic(EATCommand_IllegalCompletionReadExpected)); |
|
99 { |
|
100 iIo->WriteAndTimerCancel(this); |
|
101 Complete(KErrCancel, aSource); |
|
102 } |
|
103 break; |
|
104 |
|
105 |
|
106 default: |
|
107 break; |
|
108 }//switch |
|
109 }//EventSignal |
|
110 |
|
111 void CATOwnNumbers::Stop(TTsyReqHandle aTsyReqHandle) |
|
112 { |
|
113 if(iReqHandle == TSY_HANDLE_INIT_VALUE) // default value |
|
114 { |
|
115 // it seems the Own numbers service has not been started |
|
116 // just return |
|
117 LOGTEXT(_L8("MMTsy:\tCATOwnNumbers:\tCancel called, Error - invalid request handle.")); |
|
118 return; |
|
119 } |
|
120 |
|
121 __ASSERT_ALWAYS(aTsyReqHandle == iReqHandle, Panic(EIllegalTsyReqHandle)); |
|
122 LOGTEXT(_L8("MMTsy:\tCATOwnNumbers:\tCancel called.")); |
|
123 switch(iState) |
|
124 { |
|
125 case EATNotInProgress: |
|
126 case EATImsiWaitForWriteComplete: |
|
127 { |
|
128 LOGTEXT2(_L8("Current state TSY is cancelling from %d"), iState); |
|
129 Complete(KErrCancel, EReadCompletion); |
|
130 } |
|
131 break; |
|
132 |
|
133 default: |
|
134 { |
|
135 LOGTEXT(_L8("MMTsy:\tCATOwnNumbers:\tStop, now waiting for expected modem response")); |
|
136 AddStdExpectStrings(); |
|
137 iIo->SetTimeOut(this); |
|
138 iState = EATWaitForStopState; |
|
139 } |
|
140 break; |
|
141 |
|
142 } |
|
143 } |
|
144 |
|
145 |
|
146 void CATOwnNumbers::Complete(TInt aError,TEventSource aSource) |
|
147 { |
|
148 if (aError==KErrNone || aError==KErrNotFound) |
|
149 iState = EATCompleted; |
|
150 else if (aError==KErrGeneral) |
|
151 { |
|
152 iState = EATNotSupported; |
|
153 aError = KErrNotSupported; |
|
154 } |
|
155 else |
|
156 iState = EATNotInProgress; |
|
157 iIo->WriteAndTimerCancel(this); |
|
158 iIo->RemoveExpectStrings(this); |
|
159 iOKExpectString = NULL; |
|
160 iErrorExpectString = NULL; |
|
161 CATCommands::Complete(aError,aSource); |
|
162 LOGTEXT2(_L8("GsmTsy:CATOwnNumbers:\tCATOwnNumbers completed with error code : %d"), aError); |
|
163 iTelObject->ReqCompleted(iReqHandle, aError); |
|
164 if (aSource==EWriteCompletion) |
|
165 iIo->Read(); |
|
166 } |
|
167 |
|
168 void CATOwnNumbers::CompleteWithIOError(TEventSource /*aSource*/,TInt aStatus) |
|
169 { |
|
170 if (iState!=EATNotInProgress) |
|
171 { |
|
172 iIo->WriteAndTimerCancel(this); |
|
173 iState = EATNotInProgress; |
|
174 iTelObject->ReqCompleted(iReqHandle, aStatus); |
|
175 } |
|
176 } |
|
177 |
|
178 void CATOwnNumbers::ParseResponseL() |
|
179 { |
|
180 // +CNUM: [text],number,type[,speed,service[,itc]] |
|
181 // etc. |
|
182 |
|
183 |
|
184 CMobilePhoneONList* oNList=CMobilePhoneONList::NewL(); |
|
185 CleanupStack::PushL(oNList); |
|
186 |
|
187 // |
|
188 ParseBufferLC(EFalse, ':'); |
|
189 // |
|
190 |
|
191 TDblQueIter<CATParamListEntry> iter(iRxResults); |
|
192 CATParamListEntry* entry=iter++; |
|
193 while (entry) |
|
194 { |
|
195 if (entry->iResultPtr!=KGetOwnNumbersResponse) |
|
196 User::Leave(KErrGeneral); |
|
197 // |
|
198 // provide some default values |
|
199 RMobileONStore::TMobileONEntryV1 info; |
|
200 info.iMode = RMobilePhone::ENetworkModeGsm; // Hard coded since this tsy just handles GSM. |
|
201 |
|
202 entry=iter++; |
|
203 if (!entry) |
|
204 User::Leave(KErrGeneral); |
|
205 info.iText.Copy(entry->iResultPtr); |
|
206 |
|
207 entry=iter++; |
|
208 if (!entry) |
|
209 User::Leave(KErrGeneral); |
|
210 info.iNumber.iTelNumber.Copy(entry->iResultPtr); |
|
211 |
|
212 entry=iter++; |
|
213 info.iNumber.iTypeOfNumber = NumberTypefromGSMToMM(CATParamListEntry::EntryValL(entry)); // How is this to be used |
|
214 |
|
215 // now the optional values |
|
216 entry=iter++; |
|
217 if (entry && entry->iResultPtr!=KGetOwnNumbersResponse) |
|
218 { |
|
219 //The baerer speed that should have been set here is not supported in the TMobileONEntryV1 class |
|
220 entry=iter++; |
|
221 TInt service=CATParamListEntry::EntryValL(entry); |
|
222 switch (service) |
|
223 |
|
224 { |
|
225 case KServiceVoice: |
|
226 info.iService = RMobilePhone::EVoiceService; |
|
227 break; |
|
228 case KServiceFax: |
|
229 info.iService = RMobilePhone::EFaxService; |
|
230 break; |
|
231 case KAsynchModem: |
|
232 case KSynchModem: |
|
233 case KPADAccess: |
|
234 case KPacketAccess: |
|
235 info.iService = RMobilePhone::ECircuitDataService; |
|
236 break; |
|
237 |
|
238 default: |
|
239 info.iService = RMobilePhone::EServiceUnspecified; |
|
240 break; |
|
241 } |
|
242 // |
|
243 // further optionality |
|
244 entry=iter++; |
|
245 if (entry && entry->iResultPtr!=KGetOwnNumbersResponse) |
|
246 { |
|
247 // Information about the transfer capabilities are not used in |
|
248 // TMobileONEntryV1(the "itc" field is optionaly reurned by AT+CNUM). |
|
249 // If it had been available it hade been set here. |
|
250 entry=iter++; |
|
251 } |
|
252 } |
|
253 oNList->AddEntryL(info); |
|
254 } |
|
255 |
|
256 CleanupStack::PopAndDestroy(); // results |
|
257 CleanupStack::Pop(); // numbers |
|
258 iOwnNumbers = oNList; |
|
259 |
|
260 switch (iCommand) |
|
261 { |
|
262 case EInfo: |
|
263 Info(); |
|
264 break; |
|
265 case EEntry: |
|
266 (void)User::LeaveIfError(Entry(iResultIndex)); |
|
267 break; |
|
268 } |
|
269 } |
|
270 |
|
271 void CATOwnNumbers::Info() const |
|
272 /** |
|
273 * This method sets the information about the own number store to be passed |
|
274 * back to the client with cached inforamtion. |
|
275 */ |
|
276 { |
|
277 RMobilePhoneStore::TMobilePhoneStoreInfoV1& storeInfo = (*iInfoPckg)(); |
|
278 |
|
279 storeInfo.iType=RMobilePhoneStore::EOwnNumberStore; |
|
280 storeInfo.iUsedEntries = iOwnNumbers->Enumerate(); |
|
281 storeInfo.iTotalEntries = iOwnNumbers->Enumerate(); |
|
282 storeInfo.iName.Copy(KETelOwnNumberStore); |
|
283 storeInfo.iCaps=RMobilePhoneStore::KCapsIndividualEntry | RMobilePhoneStore::KCapsReadAccess; |
|
284 |
|
285 if (storeInfo.ExtensionId()==RMobilePhoneStore::KETelMobileONStoreV1) |
|
286 { |
|
287 RMobileONStore::TMobileONStoreInfoV1Pckg* onPckg |
|
288 = reinterpret_cast<RMobileONStore::TMobileONStoreInfoV1Pckg*>(iInfoPckg); |
|
289 RMobileONStore::TMobileONStoreInfoV1& onInfo = (*onPckg)(); |
|
290 onInfo.iNumberLen=RMobilePhone::KMaxMobileTelNumberSize; |
|
291 onInfo.iTextLen=RMobileONStore::KOwnNumberTextSize; |
|
292 } |
|
293 } |
|
294 |
|
295 TInt CATOwnNumbers::Entry(TInt aIndex) const |
|
296 /** |
|
297 * This method returnes the own number specified by aIndex. |
|
298 * If aIndex should be out of range KErrNotFound is returned. |
|
299 */ |
|
300 { |
|
301 __ASSERT_DEBUG(iOwnNumbers!= NULL, PanicClient(KErrGeneral)); |
|
302 |
|
303 RMobileONStore::TMobileONEntryV1& oNEntry = (*iEntryPckg)(); |
|
304 if (TUint(aIndex)>=TUint(iOwnNumbers->Enumerate())) |
|
305 { |
|
306 // If the index is out of range |
|
307 return KErrNotFound; |
|
308 } |
|
309 |
|
310 // Get the entry specified by the aIndex. |
|
311 TRAPD(ret,(oNEntry = iOwnNumbers->GetEntryL(aIndex))); |
|
312 |
|
313 return ret; |
|
314 } |
|
315 |
|
316 |
|
317 void CATOwnNumbers::GetInfo(TTsyReqHandle aTsyReqHandle, TDes8* aInfo) |
|
318 /** |
|
319 * Execute the command if we have not yet been run |
|
320 * Report the own number info if we have already evaluated them |
|
321 */ |
|
322 { |
|
323 iInfoPckg=static_cast<RMobilePhoneStore::TMobilePhoneStoreInfoV1Pckg*>(aInfo); |
|
324 switch (iState) |
|
325 { |
|
326 case EATCompleted: |
|
327 Info(); |
|
328 iTelObject->ReqCompleted(aTsyReqHandle, KErrNone); |
|
329 break; |
|
330 case EATNotSupported: |
|
331 iTelObject->ReqCompleted(aTsyReqHandle, KErrNotSupported); |
|
332 break; |
|
333 default: |
|
334 iCommand=EInfo; |
|
335 ExecuteCommand(aTsyReqHandle,aInfo); |
|
336 break; |
|
337 } |
|
338 } |
|
339 |
|
340 |
|
341 void CATOwnNumbers::GetEntry(TTsyReqHandle aTsyReqHandle, TDes8* aEntry) |
|
342 /** |
|
343 * Execute the command if we have not yet been run. |
|
344 * @param aTsyReqHandle The request ID |
|
345 * @param aEntry This argument is of type TMobileONEntryV1Pckg. |
|
346 */ |
|
347 { |
|
348 // Unpack the the TMobileONEntryV1 (aEntry) |
|
349 iEntryPckg = static_cast<RMobileONStore::TMobileONEntryV1Pckg*>(aEntry); |
|
350 RMobileONStore::TMobileONEntryV1& oNEntry = (*iEntryPckg)(); |
|
351 |
|
352 // Extract the index of the own number to get. |
|
353 // Subtract 1 because SIM slots start at 1 but our list will start at 0 |
|
354 // Client has asked for SIM slot number |
|
355 iResultIndex = oNEntry.iIndex - 1 ; |
|
356 |
|
357 switch (iState) |
|
358 { |
|
359 case EATCompleted: |
|
360 { |
|
361 TInt r=Entry(iResultIndex); |
|
362 if (r!=KErrNone) |
|
363 { |
|
364 iTelObject->ReqCompleted(aTsyReqHandle, r); |
|
365 return; |
|
366 } |
|
367 iTelObject->ReqCompleted(aTsyReqHandle, KErrNone); |
|
368 } |
|
369 break; |
|
370 case EATNotSupported: |
|
371 iTelObject->ReqCompleted(aTsyReqHandle, KErrNotSupported); |
|
372 break; |
|
373 default: |
|
374 iCommand=EEntry; |
|
375 ExecuteCommand(aTsyReqHandle, &oNEntry); |
|
376 break; |
|
377 } |
|
378 }//End of GetEntry |
|
379 |
|
380 |
|
381 RMobilePhone::TMobileTON CATOwnNumbers::NumberTypefromGSMToMM(TUint aTypeOfNumberGSM) |
|
382 /** Maping from MM Number Type To GSM Number Type |
|
383 * |
|
384 * This method maps the GSM way of representing a type of telefon number |
|
385 * to the MM standard. |
|
386 * |
|
387 */ |
|
388 { |
|
389 switch (aTypeOfNumberGSM) |
|
390 { |
|
391 case 129: // Nationality unknown (GSM) |
|
392 return RMobilePhone::EUnknownNumber; // (MM) |
|
393 case 145: // International Number (GSM) |
|
394 return RMobilePhone::EInternationalNumber; // (MM) |
|
395 case 161: // National Number (GSM) |
|
396 return RMobilePhone::ENationalNumber; // (MM) |
|
397 default: |
|
398 return RMobilePhone::EUnknownNumber; // (MM) |
|
399 } |
|
400 } |