|
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 // CATGetModemStatus |
|
15 // Description: |
|
16 // Basic GSM Network and Operator information Implementation file. |
|
17 // |
|
18 // This file contains the implementation of the CATNetworkInfo, CATDetectNetwork, |
|
19 // CNotifyNetworkRegistrationStatusChange and CCurrentNetworkChangedNotify classes. |
|
20 // Find the current Network Operator in Numeric, Long and Short formats. |
|
21 // NB - Some phones do not fully support all the formats, if any. The commands are |
|
22 // supported implement this command. Valid responses are set in the TMobilePhoneLocationAreaV1 |
|
23 // and the TMobilePhoneNetworkInfoV1 structures and the Network's status is set to Current. |
|
24 |
|
25 |
|
26 |
|
27 #include <etelmm.h> |
|
28 #include "atgetnetworkinfo.h" |
|
29 #include "mslogger.h" |
|
30 |
|
31 _LIT8(KGetCurrentNetworkInfoCommand, "AT+COPS?\r"); |
|
32 _LIT8(KGetCurrentNetworkInfoResponse,"+COPS:"); |
|
33 /** |
|
34 * Utility function to translate the 5 digit ASCII network identification returned by the ME |
|
35 * into Mobile Country Code (aCountryCode) and a Mobile Network Code (aNetworkIdentity) strings. |
|
36 * Tbe format returned by the ME is XXXYY, where XXX represents the Mobile Country Code and YY |
|
37 * represents the Mobile Network Code. |
|
38 */ |
|
39 static TInt NetworkIdL(const TDesC8& aCode, |
|
40 RMobilePhone::TMobilePhoneNetworkCountryCode& aCountryCode, |
|
41 RMobilePhone::TMobilePhoneNetworkIdentity& aNetworkIdentity) |
|
42 { |
|
43 if (aCode.Length()!=5) |
|
44 { |
|
45 return KErrGeneral; |
|
46 } |
|
47 |
|
48 aCountryCode.SetLength(3); |
|
49 aCountryCode[0] = aCode[0]; |
|
50 aCountryCode[1] = aCode[1]; |
|
51 aCountryCode[2] = aCode[2]; |
|
52 |
|
53 aNetworkIdentity.SetLength(2); |
|
54 aNetworkIdentity[0] = aCode[3]; |
|
55 aNetworkIdentity[1] = aCode[4]; |
|
56 return KErrNone; |
|
57 } |
|
58 // Class CATNetworkInfo |
|
59 // --------------------------------------------------------------------------- |
|
60 // CATNetworkInfo::NewL |
|
61 // other items were commented in a header |
|
62 // --------------------------------------------------------------------------- |
|
63 CATNetworkInfo* CATNetworkInfo::NewL(CGlobalPhonemanager& aGloblePhone, |
|
64 CCtsyDispatcherCallback& aCtsyDispatcherCallback) |
|
65 { |
|
66 CATNetworkInfo* self = new(ELeave) CATNetworkInfo(aGloblePhone, |
|
67 aCtsyDispatcherCallback); |
|
68 CleanupStack::PushL(self ); |
|
69 self->ConstructL(); |
|
70 CleanupStack::Pop(self ); |
|
71 return self ; |
|
72 } |
|
73 // --------------------------------------------------------------------------- |
|
74 // CATNetworkInfo::CATNetworkInfo |
|
75 // other items were commented in a header |
|
76 // --------------------------------------------------------------------------- |
|
77 CATNetworkInfo::CATNetworkInfo(CGlobalPhonemanager& aGloblePhone, |
|
78 CCtsyDispatcherCallback& aCtsyDispatcherCallback) |
|
79 :CAtCommandBase(aGloblePhone,aCtsyDispatcherCallback) |
|
80 { |
|
81 } |
|
82 // --------------------------------------------------------------------------- |
|
83 // CATNetworkInfo::ConstructL |
|
84 // other items were commented in a header |
|
85 // --------------------------------------------------------------------------- |
|
86 void CATNetworkInfo::ConstructL() |
|
87 { |
|
88 CAtCommandBase::ConstructL(); |
|
89 iGetHomeNwk = EFalse; |
|
90 iAtType = ELtsyAT_Phone_NwkInfo; |
|
91 } |
|
92 // --------------------------------------------------------------------------- |
|
93 // CATNetworkInfo::~CATNetworkInfo |
|
94 // other items were commented in a header |
|
95 // --------------------------------------------------------------------------- |
|
96 CATNetworkInfo::~CATNetworkInfo() |
|
97 { |
|
98 } |
|
99 // --------------------------------------------------------------------------- |
|
100 // CATNetworkInfo::StartRequestL |
|
101 // other items were commented in a header |
|
102 // --------------------------------------------------------------------------- |
|
103 void CATNetworkInfo::StartRequest() |
|
104 { |
|
105 ExecuteCommand(); |
|
106 } |
|
107 // --------------------------------------------------------------------------- |
|
108 // CATNetworkInfo::ExecuteCommand |
|
109 // other items were commented in a header |
|
110 // --------------------------------------------------------------------------- |
|
111 void CATNetworkInfo::ExecuteCommand( ) |
|
112 { |
|
113 iTxBuffer.Copy(KGetCurrentNetworkInfoCommand); |
|
114 Write(); |
|
115 } |
|
116 // --------------------------------------------------------------------------- |
|
117 // CATNetworkInfo::GetNetWorkInfo |
|
118 // other items were commented in a header |
|
119 // --------------------------------------------------------------------------- |
|
120 RMobilePhone::TMobilePhoneNetworkInfoV5 CATNetworkInfo:: GetNetWorkInfo() |
|
121 { |
|
122 return iNetworkInfo; |
|
123 } |
|
124 // --------------------------------------------------------------------------- |
|
125 // CATNetworkInfo::GetErrorValue |
|
126 // other items were commented in a header |
|
127 // --------------------------------------------------------------------------- |
|
128 TInt CATNetworkInfo::GetErrorValue() |
|
129 { |
|
130 return iError; |
|
131 } |
|
132 // --------------------------------------------------------------------------- |
|
133 // CATNetworkInfo::SetToGetHomeNwk |
|
134 // other items were commented in a header |
|
135 // --------------------------------------------------------------------------- |
|
136 void CATNetworkInfo::SetToGetHomeNwk() |
|
137 { |
|
138 iGetHomeNwk = ETrue; |
|
139 } |
|
140 /** |
|
141 * This method parses the modems response to the 'AT+CGREG?' command. |
|
142 * An example response is '+CGREG: 0,1' where second value denotes the |
|
143 * current registration status. |
|
144 */ |
|
145 // --------------------------------------------------------------------------- |
|
146 // CATNetworkInfo::ParseResponseL |
|
147 // other items were commented in a header |
|
148 // --------------------------------------------------------------------------- |
|
149 void CATNetworkInfo::ParseResponseL(const TDesC8& /*aResponseBuf*/) |
|
150 { |
|
151 if (CurrentLine().Match(KLtsyOkString) != 0) |
|
152 { |
|
153 iError = KErrGeneral; |
|
154 return ; |
|
155 } |
|
156 RArray<TPtrC8> array; |
|
157 CleanupClosePushL(array); |
|
158 iParser->ParseRespondedBuffer(array,PrecedingLine()); |
|
159 TInt Count = array.Count(); |
|
160 if (Count < 1) |
|
161 { |
|
162 CleanupStack::PopAndDestroy(); |
|
163 iError = KErrNotFound; |
|
164 return ; |
|
165 } |
|
166 |
|
167 if( array[0].MatchF(KGetCurrentNetworkInfoResponse)==KErrNotFound) |
|
168 { |
|
169 CleanupStack::PopAndDestroy(); |
|
170 iError = KErrNotFound; |
|
171 return ; |
|
172 } |
|
173 TInt val = 0; |
|
174 TLex8 lex(array[1]); |
|
175 lex.Val(val); |
|
176 iPhoneGlobals.iPhoneStatus.iLocalNetworkSel.iMethod = RMobilePhone::TMobilePhoneSelectionMethod(val); |
|
177 if(Count > 2) |
|
178 { |
|
179 TLex8 lex1(array[2]); |
|
180 lex1.Val(iNameFormat); |
|
181 switch (iNameFormat) |
|
182 { |
|
183 case 0: |
|
184 if(array[3].Length() > iNetworkInfo.iLongName.MaxLength()) |
|
185 iNetworkInfo.iLongName.Copy(array[3].Mid(0,iNetworkInfo.iLongName.MaxLength())); |
|
186 else |
|
187 iNetworkInfo.iLongName.Copy(array[3]); |
|
188 break; |
|
189 case 1: |
|
190 if(array[2].Length() > iNetworkInfo.iShortName.MaxLength()) |
|
191 iNetworkInfo.iShortName.Copy(array[3].Mid(0,iNetworkInfo.iShortName.MaxLength())); |
|
192 else |
|
193 iNetworkInfo.iShortName.Copy(array[3]); |
|
194 break; |
|
195 case 2: |
|
196 /*if(array[2].Length() > iNetworkInfo.iShortName.MaxLength()) |
|
197 iNetworkInfo.iShortName.Copy(array[3].Mid(0,iNetworkInfo.iShortName.MaxLength())); |
|
198 else |
|
199 iNetworkInfo.iShortName.Copy(array[3]);*/ |
|
200 User::LeaveIfError(NetworkIdL(array[3],iNetworkInfo.iCountryCode, iNetworkInfo.iNetworkId)); |
|
201 break; |
|
202 default: |
|
203 User::Leave(KErrGeneral); |
|
204 break; |
|
205 } |
|
206 } |
|
207 else |
|
208 { |
|
209 iError = KErrGeneral; |
|
210 } |
|
211 iNetworkInfo.iStatus=RMobilePhone::ENetworkStatusCurrent; |
|
212 CleanupStack::PopAndDestroy(); |
|
213 iError = KErrNone; |
|
214 } |
|
215 // --------------------------------------------------------------------------- |
|
216 // CATNetworkInfo::EventSignal |
|
217 // other items were commented in a header |
|
218 // --------------------------------------------------------------------------- |
|
219 void CATNetworkInfo::EventSignal(TAtEventSource aEventSource, TInt aStatus) |
|
220 { |
|
221 if(KErrNone ==aStatus) |
|
222 { |
|
223 if(aEventSource == EReadCompletion) |
|
224 { |
|
225 aStatus = iError; |
|
226 } |
|
227 else |
|
228 return; |
|
229 } |
|
230 iPhoneGlobals.iPhoneStatus.iCurrentNetwork = iNetworkInfo; |
|
231 if(iGetHomeNwk) |
|
232 { |
|
233 iCtsyDispatcherCallback.CallbackPhoneGetHomeNetworkComp(aStatus,iNetworkInfo); |
|
234 } |
|
235 else |
|
236 { |
|
237 iCtsyDispatcherCallback.CallbackPhoneGetCurrentNetworkInfoComp(aStatus, |
|
238 iNetworkInfo, |
|
239 iPhoneGlobals.iPhoneStatus.iLocationArea); |
|
240 } |
|
241 CAtCommandBase::Complete(); |
|
242 iPhoneGlobals.iEventSignalActive = EFalse; |
|
243 } |
|
244 // |
|
245 // End of file |
|
246 |
|
247 |
|
248 |
|
249 |
|
250 |