|
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 "mimsi.h" |
|
20 #include "mSLOGGER.H" |
|
21 #include "ATIO.H" |
|
22 #include "Matstd.h" |
|
23 |
|
24 |
|
25 // Get the IMSI for from the phone |
|
26 // NB - not supported by all phones. |
|
27 |
|
28 _LIT8(KGetSubscriberIdCommand,"AT+CIMI"); |
|
29 |
|
30 inline CATSubscriberId::CATSubscriberId(CATIO* aIo, CTelObject* aTelObject, CATInit* aInit,CPhoneGlobals* aPhoneGlobals) |
|
31 : CATCommands(aIo,aTelObject,aInit,aPhoneGlobals) |
|
32 {} |
|
33 |
|
34 CATSubscriberId* CATSubscriberId::NewL(CATIO* aIo,CTelObject* aTelObject,CATInit* aInit,CPhoneGlobals* aPhoneGlobals) |
|
35 { |
|
36 CATSubscriberId* netInfo = new(ELeave) CATSubscriberId(aIo, aTelObject, aInit, aPhoneGlobals); |
|
37 CleanupStack::PushL(netInfo); |
|
38 netInfo->ConstructL(); |
|
39 CleanupStack::Pop(); |
|
40 return netInfo; |
|
41 } |
|
42 |
|
43 CATSubscriberId::~CATSubscriberId() |
|
44 { |
|
45 iIo->RemoveExpectStrings(this); |
|
46 } |
|
47 |
|
48 void CATSubscriberId::Start(TTsyReqHandle aTsyReqHandle,TAny* aParam) |
|
49 { |
|
50 LOGTEXT(_L8("MmTsy:\tCATSubscriberId:\tStarting Subscriber Id")); |
|
51 iReturnPtr=static_cast<RMobilePhone::TMobilePhoneSubscriberId*>(aParam); |
|
52 iReqHandle = aTsyReqHandle; |
|
53 WriteExpectingResults(KGetSubscriberIdCommand, 3); |
|
54 __ASSERT_ALWAYS(iIo->AddExpectString(this,KNotifyMeIfErrorString), Panic(EGeneral)); |
|
55 iState=EATImsiWaitForWriteComplete; |
|
56 } |
|
57 |
|
58 void CATSubscriberId::EventSignal(TEventSource aSource) |
|
59 { |
|
60 if (aSource==ETimeOutCompletion) |
|
61 { |
|
62 LOGTEXT(_L8("MmTsy:\tCATSubscriberId:\tTimeout Error during IMSI read")); |
|
63 RemoveStdExpectStrings(); |
|
64 Complete(KErrTimedOut,aSource); |
|
65 return; |
|
66 } |
|
67 |
|
68 switch(iState) |
|
69 { |
|
70 case EATImsiWaitForWriteComplete: |
|
71 __ASSERT_ALWAYS(aSource==EWriteCompletion,Panic(EATCommand_IllegalCompletionWriteExpected)); |
|
72 { |
|
73 iIo->WriteAndTimerCancel(this); |
|
74 StandardWriteCompletionHandler(aSource, 5); |
|
75 iState=EATImsiReadComplete; |
|
76 } |
|
77 break; |
|
78 |
|
79 case EATImsiReadComplete: |
|
80 __ASSERT_ALWAYS(aSource==EReadCompletion,Panic(EATCommand_IllegalCompletionReadExpected)); |
|
81 { |
|
82 iIo->WriteAndTimerCancel(this); |
|
83 TInt ret(ValidateExpectString()); |
|
84 RemoveStdExpectStrings(); |
|
85 if (ret==KErrNone) |
|
86 TRAP(ret,ParseResponseL()); |
|
87 Complete(ret,aSource); |
|
88 } |
|
89 break; |
|
90 |
|
91 case EATWaitForStopState: |
|
92 __ASSERT_ALWAYS(aSource==EReadCompletion, Panic(EATCommand_IllegalCompletionReadExpected)); |
|
93 { |
|
94 iIo->WriteAndTimerCancel(this); |
|
95 Complete(KErrCancel, aSource); |
|
96 } |
|
97 break; |
|
98 |
|
99 |
|
100 default: |
|
101 break; |
|
102 }//switch |
|
103 }//EventSignal |
|
104 |
|
105 void CATSubscriberId::Stop(TTsyReqHandle aTsyReqHandle) |
|
106 { |
|
107 __ASSERT_ALWAYS(aTsyReqHandle == iReqHandle, Panic(EIllegalTsyReqHandle)); |
|
108 LOGTEXT(_L8("MmTsy:\tCATSubscriberId:\tCancel called.")); |
|
109 switch(iState) |
|
110 { |
|
111 case EATNotInProgress: |
|
112 case EATImsiWaitForWriteComplete: |
|
113 { |
|
114 LOGTEXT2(_L8("Current state TSY is cancelling from %d"), iState); |
|
115 Complete(KErrCancel, EReadCompletion); |
|
116 } |
|
117 break; |
|
118 |
|
119 default: |
|
120 { |
|
121 LOGTEXT(_L8("MmTsy:\tCATSubscriberId:\tStop, now waiting for expected modem response")); |
|
122 AddStdExpectStrings(); |
|
123 iIo->SetTimeOut(this); |
|
124 iState = EATWaitForStopState; |
|
125 } |
|
126 break; |
|
127 |
|
128 } |
|
129 } |
|
130 |
|
131 |
|
132 void CATSubscriberId::Complete(TInt aError,TEventSource aSource) |
|
133 { |
|
134 if (aError==KErrNone) |
|
135 iState = EATCompleted; |
|
136 else if (aError==KErrGeneral) |
|
137 { // +CIMI not supported by the phone, transmogrify into KErrNotSupported |
|
138 iState = EATNotSupported; |
|
139 aError = KErrNotSupported; |
|
140 } |
|
141 else |
|
142 { |
|
143 // This flag is set in CATCommands::Complete now. |
|
144 // iPhoneGlobals->iPhoneStatus.iInitStatus=EPhoneNotInitialised; |
|
145 iState = EATNotInProgress; |
|
146 } |
|
147 iIo->WriteAndTimerCancel(this); |
|
148 iIo->RemoveExpectStrings(this); |
|
149 iOKExpectString = NULL; |
|
150 iErrorExpectString = NULL; |
|
151 CATCommands::Complete(aError,aSource); |
|
152 LOGTEXT2(_L8("MmTsy:CATSubscriberId:\tCATSubscriberId completed with error code : %d"), aError); |
|
153 if (iReqHandle) |
|
154 iTelObject->ReqCompleted(iReqHandle, aError); |
|
155 if (aSource==EWriteCompletion) |
|
156 iIo->Read(); |
|
157 } |
|
158 |
|
159 void CATSubscriberId::CompleteWithIOError(TEventSource /*aSource*/,TInt aStatus) |
|
160 { |
|
161 if (iState!=EATNotInProgress) |
|
162 { |
|
163 iIo->WriteAndTimerCancel(this); |
|
164 iState = EATNotInProgress; |
|
165 if (iReqHandle) |
|
166 iTelObject->ReqCompleted(iReqHandle, aStatus); |
|
167 } |
|
168 } |
|
169 |
|
170 void CATSubscriberId::ParseResponseL() |
|
171 /** |
|
172 * This function parses the phone's response, copying it into the iImsi buffer. This buffer is |
|
173 * only 15 characters long, and the Siemens S25 returns a 16 character long IMSI. Other phones |
|
174 * return only the leftmost 15 characters. This function takes this into account by returning |
|
175 * only the leftmost 15 characters of the phone's response. |
|
176 **/ |
|
177 { |
|
178 ParseBufferLC(); |
|
179 TDblQueIter<CATParamListEntry> iter(iRxResults); |
|
180 CATParamListEntry* entry=iter++; |
|
181 if (entry==NULL) |
|
182 User::Leave(KErrGeneral); |
|
183 |
|
184 if(entry->iResultPtr.Length() > RMobilePhone::KIMSISize) |
|
185 iImsi.Copy(entry->iResultPtr.Left(RMobilePhone::KIMSISize)); |
|
186 else |
|
187 iImsi.Copy(entry->iResultPtr); |
|
188 |
|
189 if (iter++!=NULL) |
|
190 User::Leave(KErrGeneral); |
|
191 *iReturnPtr=iImsi; |
|
192 |
|
193 CleanupStack::PopAndDestroy(); |
|
194 } |
|
195 |
|
196 TBool CATSubscriberId::CachedValue(TDes& aImsi) |
|
197 // |
|
198 // return the cached value if we have it |
|
199 // |
|
200 { |
|
201 if (iState!=EATCompleted) |
|
202 return EFalse; |
|
203 aImsi=iImsi; |
|
204 return ETrue; |
|
205 } |
|
206 |