|
1 // Copyright (c) 2007-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 // Name : NetworkInfo.cpp |
|
15 // Part of : ConnectionMgr |
|
16 // Implementation |
|
17 // Version : SIP/6.0 |
|
18 // |
|
19 |
|
20 |
|
21 |
|
22 #include "NetworkInfo.h" |
|
23 #include "CNetworkManager.h" |
|
24 #include "siprequest.h" |
|
25 #include "sippaccessnetworkinfoheader.h" |
|
26 #include "sipstrings.h" |
|
27 #include "sipstrconsts.h" |
|
28 |
|
29 // ---------------------------------------------------------------------------- |
|
30 // CNetworkInfo::NewL |
|
31 // ---------------------------------------------------------------------------- |
|
32 // |
|
33 CNetworkInfo* CNetworkInfo::NewL( CNetworkManager& aNetworkManager ) |
|
34 { |
|
35 CNetworkInfo* self = new ( ELeave ) CNetworkInfo( aNetworkManager ); |
|
36 CleanupStack::PushL( self ); |
|
37 self->ConstructL(); |
|
38 CleanupStack::Pop( self ); |
|
39 return self; |
|
40 } |
|
41 |
|
42 // ---------------------------------------------------------------------------- |
|
43 // CNetworkInfo::CNetworkInfo |
|
44 // ---------------------------------------------------------------------------- |
|
45 // |
|
46 CNetworkInfo::CNetworkInfo( CNetworkManager& aNetworkManager ) : |
|
47 iNetworkManager( aNetworkManager ) |
|
48 { |
|
49 const RStringF empty = SIPStrings::StringF( SipStrConsts::EEmpty ); |
|
50 iAccessType = empty; |
|
51 iAccessInfoValue = empty; |
|
52 |
|
53 //If the plugin has not yet been loaded, the returned iInfo will be empty. |
|
54 //It doesn't matter, since the plugin will be loaded before any SIP request |
|
55 //can be sent, and at that point plugin will synchronously obtain current |
|
56 //info, and pass it to here. |
|
57 iInfo = iNetworkManager.RegisterAccessNetworkObserver( *this ); |
|
58 } |
|
59 |
|
60 // ---------------------------------------------------------------------------- |
|
61 // CNetworkInfo::ConstructL |
|
62 // ---------------------------------------------------------------------------- |
|
63 // |
|
64 void CNetworkInfo::ConstructL() |
|
65 { |
|
66 _LIT8( K3gppGeran, "3GPP-GERAN" ); |
|
67 _LIT8( K3gppUtranFdd, "3GPP-UTRAN-FDD" ); |
|
68 _LIT8( K3gppUtranTdd, "3GPP-UTRAN-TDD" ); |
|
69 _LIT8( K3gppCdma2000, "3GPP-CDMA2000" ); |
|
70 |
|
71 i3gppGeran = SIPStrings::Pool().OpenFStringL( K3gppGeran ); |
|
72 i3gppUtranFdd = SIPStrings::Pool().OpenFStringL( K3gppUtranFdd ); |
|
73 i3gppUtranTdd = SIPStrings::Pool().OpenFStringL( K3gppUtranTdd ); |
|
74 i3gppCdma2000 = SIPStrings::Pool().OpenFStringL( K3gppCdma2000 ); |
|
75 |
|
76 //This can't be done before i3gppGeran etc have been initialized |
|
77 TranslateInfoL(); |
|
78 } |
|
79 |
|
80 // ---------------------------------------------------------------------------- |
|
81 // CNetworkInfo::~CNetworkInfo |
|
82 // ---------------------------------------------------------------------------- |
|
83 // |
|
84 CNetworkInfo::~CNetworkInfo() |
|
85 { |
|
86 iNetworkManager.DeregisterAccessNetworkObserver(); |
|
87 iAccessType.Close(); |
|
88 iAccessInfoValue.Close(); |
|
89 i3gppGeran.Close(); |
|
90 i3gppUtranFdd.Close(); |
|
91 i3gppUtranTdd.Close(); |
|
92 i3gppCdma2000.Close(); |
|
93 } |
|
94 |
|
95 // ---------------------------------------------------------------------------- |
|
96 // CNetworkInfo::InfoChanged |
|
97 // ---------------------------------------------------------------------------- |
|
98 // |
|
99 void CNetworkInfo::InfoChanged( const TSIPAccessNetworkInfo& aInfo ) |
|
100 { |
|
101 iInfo = aInfo; |
|
102 TRAP_IGNORE( TranslateInfoL() ) |
|
103 } |
|
104 |
|
105 // --------------------------------------------------------------------------- |
|
106 // CNetworkInfo::HandleRequestL |
|
107 // Add P-Access-Network-Info header when needed |
|
108 // ---------------------------------------------------------------------------- |
|
109 // |
|
110 void CNetworkInfo::HandleRequestL( CSIPRequest& aRequest, |
|
111 TBool aIntegrityProtected ) |
|
112 { |
|
113 //Delete possibly existing old header, since e.g. cell may have changed, |
|
114 //or a refreshed request may no longer be sent integrity protected etc. |
|
115 aRequest.DeleteHeaders( |
|
116 SIPStrings::StringF( SipStrConsts::EPAccessNetworkInfoHeader ) ); |
|
117 |
|
118 if ( aIntegrityProtected ) |
|
119 { |
|
120 RStringF method = aRequest.Method(); |
|
121 if ( method != SIPStrings::StringF( SipStrConsts::EAck ) && |
|
122 method != SIPStrings::StringF( SipStrConsts::ECancel ) ) |
|
123 { |
|
124 AddHeaderL( aRequest ); |
|
125 } |
|
126 } |
|
127 } |
|
128 |
|
129 // ---------------------------------------------------------------------------- |
|
130 // CNetworkInfo::AddHeaderL |
|
131 // ---------------------------------------------------------------------------- |
|
132 // |
|
133 void CNetworkInfo::AddHeaderL( CSIPRequest& aRequest ) |
|
134 { |
|
135 // Valid LAC and CellId are included also when iInfo.iAreaKnown is EFalse |
|
136 if ( iAccessType != SIPStrings::StringF( SipStrConsts::EEmpty ) ) |
|
137 { |
|
138 CSIPPAccessNetworkInfoHeader* header = |
|
139 CSIPPAccessNetworkInfoHeader::NewLC( iAccessType ); |
|
140 |
|
141 if ( iAccessType == i3gppGeran ) |
|
142 { |
|
143 header->SetParamL( SIPStrings::StringF( SipStrConsts::ECgi3gpp ), |
|
144 iAccessInfoValue ); |
|
145 } |
|
146 if ( iAccessType == i3gppUtranFdd || |
|
147 iAccessType == i3gppUtranTdd || |
|
148 iAccessType == i3gppCdma2000 ) |
|
149 { |
|
150 header->SetParamL( |
|
151 SIPStrings::StringF( SipStrConsts::EUtranCellId3gpp ), |
|
152 iAccessInfoValue ); |
|
153 } |
|
154 |
|
155 aRequest.AddHeaderL( header ); |
|
156 CleanupStack::Pop( header ); |
|
157 } |
|
158 } |
|
159 |
|
160 // ---------------------------------------------------------------------------- |
|
161 // CNetworkInfo::TranslateInfoL |
|
162 // ---------------------------------------------------------------------------- |
|
163 // |
|
164 void CNetworkInfo::TranslateInfoL() |
|
165 { |
|
166 DetermineAccessType(); |
|
167 DetermineAccessInfoL(); |
|
168 } |
|
169 |
|
170 // ---------------------------------------------------------------------------- |
|
171 // CNetworkInfo::DetermineAccessType |
|
172 // ---------------------------------------------------------------------------- |
|
173 // |
|
174 void CNetworkInfo::DetermineAccessType() |
|
175 { |
|
176 iAccessType.Close(); |
|
177 |
|
178 switch ( iInfo.iNetworkMode ) |
|
179 { |
|
180 //GSM/GPRS or DCS1800 network |
|
181 case RMobilePhone::ENetworkModeGsm: |
|
182 iAccessType = i3gppGeran.Copy(); |
|
183 break; |
|
184 |
|
185 //CDMA (cdma2000) network. |
|
186 case RMobilePhone::ENetworkModeCdma2000: |
|
187 iAccessType = i3gppCdma2000.Copy(); |
|
188 break; |
|
189 |
|
190 //WCDMA (UTRA Frequency Division Duplex (FDD)) network |
|
191 case RMobilePhone::ENetworkModeWcdma: |
|
192 iAccessType = i3gppUtranFdd.Copy(); |
|
193 break; |
|
194 |
|
195 //TD-CDMA (UTRA Time Division Duplex (TDD)) network |
|
196 case RMobilePhone::ENetworkModeTdcdma: |
|
197 iAccessType = i3gppUtranTdd.Copy(); |
|
198 break; |
|
199 |
|
200 //AMPS network |
|
201 case RMobilePhone::ENetworkModeAmps: |
|
202 //CDMA (IS-95) network |
|
203 case RMobilePhone::ENetworkModeCdma95: |
|
204 //Other network modes |
|
205 case RMobilePhone::ENetworkModeUnknown: |
|
206 case RMobilePhone::ENetworkModeUnregistered: |
|
207 default: |
|
208 iAccessType = SIPStrings::StringF( SipStrConsts::EEmpty ); |
|
209 } |
|
210 } |
|
211 |
|
212 // ---------------------------------------------------------------------------- |
|
213 // CNetworkInfo::DetermineAccessInfoL |
|
214 // Valid LAC and CellId are included also when iInfo.iAreaKnown is EFalse. |
|
215 // ---------------------------------------------------------------------------- |
|
216 // |
|
217 void CNetworkInfo::DetermineAccessInfoL() |
|
218 { |
|
219 iAccessInfoValue.Close(); |
|
220 |
|
221 if ( iAccessType == i3gppGeran || |
|
222 iAccessType == i3gppUtranFdd || |
|
223 iAccessType == i3gppUtranTdd || |
|
224 iAccessType == i3gppCdma2000 ) |
|
225 { |
|
226 //Long enough to hold: |
|
227 // MCC: 3 digits |
|
228 // MNC: 2 or 3 digits (depending on MCC value) |
|
229 // LAC: 4 hex digits (16 bits) |
|
230 // Cell Identity: 4 or 7 hex digits (16 or 28 bits) |
|
231 const TInt KAccessInfoStringLength = 18; |
|
232 HBufC8* accessInfo = HBufC8::NewLC( KAccessInfoStringLength ); |
|
233 TPtr8 ptr = accessInfo->Des(); |
|
234 |
|
235 //MCC = TBuf<4> RMobilePhone::TMobilePhoneNetworkCountryCode; |
|
236 //MNC = TBuf<8> RMobilePhone::TMobilePhoneNetworkIdentity; |
|
237 |
|
238 ptr.Append( iInfo.iMobileCountryCode.Left( 3 ) ); |
|
239 ptr.Append( iInfo.iMobileNetworkCode.Left( 3 ) ); |
|
240 |
|
241 //LAC is a 16 bit value |
|
242 const TUint KLacMask = 0xffff; |
|
243 //Include leading zeros |
|
244 _LIT8( K16BitFormat, "%04x" ); |
|
245 ptr.AppendFormat( K16BitFormat, iInfo.iLocationAreaCode & KLacMask ); |
|
246 |
|
247 if ( iAccessType == i3gppGeran ) |
|
248 { |
|
249 //CI (Cell Identity) is a 16 bit value |
|
250 const TUint KCellIdMask = 0xffff; |
|
251 ptr.AppendFormat( K16BitFormat, iInfo.iCellId & KCellIdMask ); |
|
252 } |
|
253 else |
|
254 { |
|
255 //UMTS Cell Identity is a 28 bit value |
|
256 const TUint KUmtsCellIdMask = 0xfffffff; |
|
257 _LIT8( KUmtsCellIdFormat, "%07x" ); |
|
258 ptr.AppendFormat( KUmtsCellIdFormat, |
|
259 iInfo.iCellId & KUmtsCellIdMask ); |
|
260 } |
|
261 |
|
262 iAccessInfoValue = SIPStrings::Pool().OpenFStringL( *accessInfo ); |
|
263 CleanupStack::PopAndDestroy( accessInfo ); |
|
264 } |
|
265 else |
|
266 { |
|
267 iAccessInfoValue = SIPStrings::StringF( SipStrConsts::EEmpty ); |
|
268 } |
|
269 } |