|
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 // Get the detected network |
|
15 |
|
16 #include "atdetectnetwork.h" |
|
17 #include "mslogger.h" |
|
18 |
|
19 _LIT8(KDetectNetworkCommand,"AT+COPS=?\r"); |
|
20 _LIT8(KGetDetectNetworkRepondStr,"+COPS:"); |
|
21 const TInt KLtsyDetectNetworkReadTimeOut = 80; |
|
22 |
|
23 // --------------------------------------------------------------------------- |
|
24 // NetworkIdL |
|
25 // Utility function to translate the 5 digit ASCII network identification |
|
26 // returned by the ME into Mobile Country Code (aCountryCode) and a Mobile |
|
27 // Network Code (aNetworkIdentity) strings. Tbe format returned by the ME is |
|
28 // XXXYY, where XXX represents the Mobile Country Code and YY represents the |
|
29 // Mobile Network Code. |
|
30 // --------------------------------------------------------------------------- |
|
31 static TInt NetworkIdL(const TDesC8& aCode, |
|
32 RMobilePhone::TMobilePhoneNetworkCountryCode& aCountryCode, |
|
33 RMobilePhone::TMobilePhoneNetworkIdentity& aNetworkIdentity) |
|
34 { |
|
35 if (aCode.Length()!=5) |
|
36 { |
|
37 return KErrGeneral; |
|
38 } |
|
39 |
|
40 aCountryCode.SetLength(3); |
|
41 aCountryCode[0] = aCode[0]; |
|
42 aCountryCode[1] = aCode[1]; |
|
43 aCountryCode[2] = aCode[2]; |
|
44 |
|
45 aNetworkIdentity.SetLength(2); |
|
46 aNetworkIdentity[0] = aCode[3]; |
|
47 aNetworkIdentity[1] = aCode[4]; |
|
48 return KErrNone; |
|
49 } |
|
50 // Class CATDetectNetwork |
|
51 // --------------------------------------------------------------------------- |
|
52 // CATDetectNetwork::NewL |
|
53 // other items were commented in a header |
|
54 // --------------------------------------------------------------------------- |
|
55 CATDetectNetwork* CATDetectNetwork::NewL(CGlobalPhonemanager& aGloblePhone, |
|
56 CCtsyDispatcherCallback& aCtsyDispatcherCallback) |
|
57 { |
|
58 CATDetectNetwork* self = new(ELeave) CATDetectNetwork(aGloblePhone,aCtsyDispatcherCallback); |
|
59 CleanupStack::PushL(self ); |
|
60 self->ConstructL(); |
|
61 CleanupStack::Pop(self ); |
|
62 return self ; |
|
63 } |
|
64 // --------------------------------------------------------------------------- |
|
65 // CATDetectNetwork::CATDetectNetwork |
|
66 // other items were commented in a header |
|
67 // --------------------------------------------------------------------------- |
|
68 CATDetectNetwork::CATDetectNetwork(CGlobalPhonemanager& aGloblePhone, |
|
69 CCtsyDispatcherCallback& aCtsyDispatcherCallback) |
|
70 :CAtCommandBase(aGloblePhone,aCtsyDispatcherCallback) |
|
71 { |
|
72 iReadTimeOut = KLtsyDetectNetworkReadTimeOut; |
|
73 } |
|
74 // --------------------------------------------------------------------------- |
|
75 // CATDetectNetwork::ConstructL |
|
76 // other items were commented in a header |
|
77 // --------------------------------------------------------------------------- |
|
78 void CATDetectNetwork::ConstructL() |
|
79 { |
|
80 CAtCommandBase::ConstructL(); |
|
81 iList= NULL; |
|
82 iCommandRunning = EFalse; |
|
83 iCommandCancel = EFalse; |
|
84 } |
|
85 // --------------------------------------------------------------------------- |
|
86 // CATDetectNetwork::~CATDetectNetwork |
|
87 // other items were commented in a header |
|
88 // --------------------------------------------------------------------------- |
|
89 CATDetectNetwork::~CATDetectNetwork() |
|
90 { |
|
91 if(iList) |
|
92 { |
|
93 delete iList; |
|
94 iList = NULL; |
|
95 } |
|
96 } |
|
97 // --------------------------------------------------------------------------- |
|
98 // CATDetectNetwork::StartRequestL |
|
99 // other items were commented in a header |
|
100 // --------------------------------------------------------------------------- |
|
101 void CATDetectNetwork::StartRequest() |
|
102 { |
|
103 iCommandRunning = ETrue; |
|
104 ExecuteCommand(); |
|
105 } |
|
106 // --------------------------------------------------------------------------- |
|
107 // CATDetectNetwork::ExecuteCommand |
|
108 // other items were commented in a header |
|
109 // --------------------------------------------------------------------------- |
|
110 void CATDetectNetwork::ExecuteCommand() |
|
111 { |
|
112 iTxBuffer.Copy(KDetectNetworkCommand); |
|
113 Write(); |
|
114 } |
|
115 // --------------------------------------------------------------------------- |
|
116 // CATDetectNetwork::CancelCommand |
|
117 // other items were commented in a header |
|
118 // --------------------------------------------------------------------------- |
|
119 void CATDetectNetwork::CancelCommand() |
|
120 { |
|
121 iCommandCancel = ETrue; |
|
122 } |
|
123 // --------------------------------------------------------------------------- |
|
124 // CATDetectNetwork::ParseResponseL |
|
125 // should be |
|
126 // +COPS: (status,"longname","shortname",code),... ,,(list),(list) |
|
127 // +COPS: [list of supported (<stat>,long alphanumeric <oper>,short alphanumeric |
|
128 // <oper>,numeric <oper>)s] |
|
129 // <stat>: |
|
130 // 0 unknown |
|
131 // 1 available |
|
132 // 2 current |
|
133 // 3 forbidden |
|
134 // <oper>: string type; <format> indicates if the format is alphanumeric or numeric; |
|
135 // long alphanumeric format can be upto 16 characters long and short format up to 8 |
|
136 // characters (refer GSM MoU SE.13 [9]); numeric format is the GSM Location Area |
|
137 // Identification number (refer GSM 04.08 [8] subclause 10.5.1.3) which consists of |
|
138 // a three BCD digit country code coded as in ITU-T E.212 Annex A [10], plus a two |
|
139 // BCD digit network code, which is administration specific; returned <oper> shall |
|
140 // not be in BCD format, but in IRA characters converted from BCD; hence the number |
|
141 // has structure: (country code digit 3)(country code digit 2)(country code digit 1) |
|
142 // (network code digit 2)(network code digit 1) |
|
143 // other items were commented in a header |
|
144 // --------------------------------------------------------------------------- |
|
145 void CATDetectNetwork::ParseResponseL(const TDesC8& /*aResponseBuf*/) |
|
146 { |
|
147 if (CurrentLine().Match(KLtsyOkString) != 0) |
|
148 { |
|
149 iError = KErrGeneral; |
|
150 return ; |
|
151 } |
|
152 if(iList) |
|
153 { |
|
154 delete iList; |
|
155 iList = NULL; |
|
156 } |
|
157 iList=CMobilePhoneNetworkListV2::NewL(); |
|
158 |
|
159 RArray<TPtrC8> array; |
|
160 CleanupClosePushL(array); |
|
161 iParser->ParseRespondedBuffer(array,PrecedingLine()); |
|
162 TInt Count = array.Count(); |
|
163 if (Count < 1) |
|
164 { |
|
165 CleanupStack::PopAndDestroy(); |
|
166 iError = KErrNotFound; |
|
167 return ; |
|
168 } |
|
169 if( array[0].MatchF(KGetDetectNetworkRepondStr)==KErrNotFound) |
|
170 { |
|
171 CleanupStack::PopAndDestroy(); |
|
172 iError = KErrNotFound; |
|
173 return ; |
|
174 } |
|
175 TInt count = array.Count() - 1; |
|
176 for (TInt i = 1;i < count;i++) |
|
177 { |
|
178 RMobilePhone::TMobilePhoneNetworkInfoV2 info; |
|
179 // This TSY only supports GSM mode so we can hardcode this |
|
180 info.iMode=RMobilePhone::ENetworkModeGsm; |
|
181 TInt val; |
|
182 TLex8 lex(array[i]); |
|
183 lex.Val(val); |
|
184 info.iStatus = RMobilePhone::TMobilePhoneNetworkStatus(val); |
|
185 i++; |
|
186 info.iLongName.Copy(array[i]); |
|
187 i++; |
|
188 if(array[i].Length() > info.iShortName.MaxLength()) |
|
189 info.iShortName.Copy(array[i].Mid(0,info.iShortName.MaxLength())); |
|
190 else |
|
191 info.iShortName.Copy(array[i]); |
|
192 i++; |
|
193 User::LeaveIfError(NetworkIdL(array[i],info.iCountryCode, info.iNetworkId)); // MNC and MCC |
|
194 |
|
195 iList->AddEntryL(info); |
|
196 } |
|
197 CleanupStack::PopAndDestroy(); |
|
198 } //ParseResponseL |
|
199 // --------------------------------------------------------------------------- |
|
200 // ATDetectNetwork::EventSignal |
|
201 // other items were commented in a header |
|
202 // --------------------------------------------------------------------------- |
|
203 void CATDetectNetwork::EventSignal(TAtEventSource aEventSource, TInt aStatus) |
|
204 { |
|
205 if(KErrNone ==aStatus) |
|
206 { |
|
207 if(aEventSource == EReadCompletion) |
|
208 { |
|
209 aStatus = iError; |
|
210 } |
|
211 else |
|
212 return; |
|
213 } |
|
214 if(iCommandCancel) |
|
215 { |
|
216 iCtsyDispatcherCallback.CallbackPhoneGetDetectedNetworksCancelComp(0); |
|
217 } |
|
218 else |
|
219 { |
|
220 iCtsyDispatcherCallback.CallbackPhoneGetDetectedNetworksComp(aStatus,*iList); |
|
221 } |
|
222 iCommandRunning = EFalse; |
|
223 iCommandCancel = EFalse; |
|
224 CAtCommandBase::Complete(); |
|
225 iPhoneGlobals.iEventSignalActive = EFalse; |
|
226 |
|
227 } |
|
228 // |
|
229 // End of file |
|
230 |