33
|
1 |
/*
|
|
2 |
* Copyright (c) 2002-2010 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description: Handles APN operations
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
// INCLUDE FILES
|
|
19 |
#include <cmmanager.h>
|
|
20 |
#include <cmconnectionmethod.h>
|
|
21 |
#include <cmconnectionmethoddef.h>
|
|
22 |
#include <cmpluginpacketdatadef.h>
|
|
23 |
#include <cmdestination.h>
|
|
24 |
#include <cmmanagerdef.h>
|
|
25 |
|
|
26 |
#include "MSatUtils.h"
|
|
27 |
#include "CSatApnHandler.h"
|
|
28 |
#include "SatLog.h"
|
|
29 |
|
|
30 |
const TUint32 KSatCMGranularity( 5 );
|
|
31 |
|
|
32 |
// ============================ MEMBER FUNCTIONS ===============================
|
|
33 |
|
|
34 |
// -----------------------------------------------------------------------------
|
|
35 |
// CSatApnHandler::CSatApnHandler
|
|
36 |
// C++ default constructor can NOT contain any code, that
|
|
37 |
// might leave.
|
|
38 |
// -----------------------------------------------------------------------------
|
|
39 |
//
|
|
40 |
CSatApnHandler::CSatApnHandler( MSatUtils& aUtils ) :
|
|
41 |
iUtils( aUtils )
|
|
42 |
{
|
|
43 |
LOG( SIMPLE,
|
|
44 |
"SATENGINE: CSatApnHandler::CSatApnHandler calling-exiting" )
|
|
45 |
}
|
|
46 |
|
|
47 |
// -----------------------------------------------------------------------------
|
|
48 |
// CSatApnHandler::NewL
|
|
49 |
// Two-phased constructor.
|
|
50 |
// -----------------------------------------------------------------------------
|
|
51 |
//
|
|
52 |
CSatApnHandler* CSatApnHandler::NewL( MSatUtils& aUtils )
|
|
53 |
{
|
|
54 |
LOG( SIMPLE, "SATENGINE: CSatApnHandler::NewL calling" )
|
|
55 |
|
|
56 |
CSatApnHandler* self = new( ELeave )CSatApnHandler( aUtils );
|
|
57 |
LOG( SIMPLE, "SATENGINE: CSatApnHandler::NewL exiting" )
|
|
58 |
return self;
|
|
59 |
}
|
|
60 |
|
|
61 |
// -----------------------------------------------------------------------------
|
|
62 |
// CSatApnHandler::Destructor
|
|
63 |
// -----------------------------------------------------------------------------
|
|
64 |
//
|
|
65 |
CSatApnHandler::~CSatApnHandler()
|
|
66 |
{
|
|
67 |
LOG( SIMPLE,
|
|
68 |
"SATENGINE: CSatApnHandler::~CSatApnHandler calling" )
|
|
69 |
LOG( SIMPLE,
|
|
70 |
"SATENGINE: CSatApnHandler::~CSatApnHandler exiting" )
|
|
71 |
}
|
|
72 |
|
|
73 |
// -----------------------------------------------------------------------------
|
|
74 |
// CSatApnHandler::GetApnInfoL
|
|
75 |
// -----------------------------------------------------------------------------
|
|
76 |
//
|
|
77 |
void CSatApnHandler::GetApnInfoL(
|
|
78 |
const RSat::TAccessName& aName,
|
|
79 |
const RSat::TTextString& aUserLogin,
|
|
80 |
const RSat::TTextString& aUserPwd,
|
|
81 |
TUint32& aIapId,
|
|
82 |
TUint32& aNwId,
|
|
83 |
TBool& aApnCreated,
|
|
84 |
const RPacketContext::TProtocolType& aPdpType,
|
|
85 |
const TDesC8& aLocalAddress )
|
|
86 |
{
|
|
87 |
LOG( SIMPLE, "SATENGINE: CSatApnHandler::GetApnInfoL calling" )
|
|
88 |
|
|
89 |
|
|
90 |
// First check the length of the APN
|
|
91 |
if ( !aName.Length() )
|
|
92 |
{
|
|
93 |
LOG( SIMPLE, "SATENGINE: CSatApnHandler::GetApnInfoL \
|
|
94 |
aName.Length() == 0" )
|
|
95 |
User::Leave( KErrNotFound );
|
|
96 |
}
|
|
97 |
|
|
98 |
// Format APN
|
|
99 |
HBufC* formatName = FormatAPN( aName );
|
|
100 |
|
|
101 |
if ( !formatName )
|
|
102 |
{
|
|
103 |
LOG( SIMPLE, "SATENGINE: CSatApnHandler::GetApnInfoL wrong APN name \
|
|
104 |
format" )
|
|
105 |
// APN was in false format, leave
|
|
106 |
User::Leave( KErrArgument );
|
|
107 |
}
|
|
108 |
CleanupStack::PushL( formatName );
|
|
109 |
|
|
110 |
// Reference params
|
|
111 |
TUint32 iapId( 0 );
|
|
112 |
TUint32 networkId( 0 );
|
|
113 |
|
|
114 |
// Find if the connection method already exists
|
|
115 |
// Initialize the flags
|
|
116 |
TBool found = EFalse;
|
|
117 |
aApnCreated = EFalse;
|
|
118 |
|
|
119 |
// Create CMManager Session
|
|
120 |
RCmManager cmManager;
|
|
121 |
cmManager.OpenLC();
|
|
122 |
|
|
123 |
// Get the Connection Method list from the open CMManager session
|
|
124 |
RArray<TUint32> array = RArray<TUint32>( KSatCMGranularity );
|
|
125 |
CleanupClosePushL( array );
|
|
126 |
|
|
127 |
cmManager.ConnectionMethodL( array );
|
|
128 |
|
|
129 |
// Go through the Connection Method list to find if there is matched one
|
|
130 |
HBufC* apnCM;
|
|
131 |
|
|
132 |
LOG2( SIMPLE, "SATENGINE: CSatApnHandler::GetApnInfoL, \
|
|
133 |
required pdp type is %d", aPdpType )
|
|
134 |
|
|
135 |
for( TInt i = 0; ( i < array.Count() ) && !found; ++i )
|
|
136 |
{
|
|
137 |
RCmConnectionMethod cm = cmManager.ConnectionMethodL( array[i] );
|
|
138 |
|
|
139 |
CleanupClosePushL( cm );
|
|
140 |
// query the APN of the Connection Method
|
|
141 |
apnCM = cm.GetStringAttributeL( CMManager::EPacketDataAPName );
|
|
142 |
CleanupStack::PushL( apnCM );
|
|
143 |
// query the pdpType of the Connection Method
|
|
144 |
TInt pdpType = cm.GetIntAttributeL( CMManager::EPacketDataPDPType );
|
|
145 |
|
|
146 |
|
|
147 |
if ( ( pdpType == aPdpType ) && ( *apnCM == *formatName ) )
|
|
148 |
{
|
|
149 |
// Found the Connection Method, query the IapId and NwId
|
|
150 |
LOG( SIMPLE, "SATENGINE: CSatApnHandler::GetApnInfoL, \
|
|
151 |
Record found" )
|
|
152 |
|
|
153 |
// Get IAP Id, Network Id
|
|
154 |
networkId = cm.GetIntAttributeL( CMManager::ECmNetworkId );
|
|
155 |
LOG2( SIMPLE, "SATENGINE: CSatApnHandler::GetApnInfoL, \
|
|
156 |
networkId %d", networkId )
|
|
157 |
|
|
158 |
iapId = cm.GetIntAttributeL( CMManager::ECmIapId );
|
|
159 |
LOG2( SIMPLE, "SATENGINE: CSatApnHandler::GetApnInfoL, \
|
|
160 |
iapId %d", iapId )
|
|
161 |
|
|
162 |
found = ETrue;
|
|
163 |
}
|
|
164 |
CleanupStack::PopAndDestroy( apnCM );
|
|
165 |
CleanupStack::PopAndDestroy( &cm );
|
|
166 |
}
|
|
167 |
|
|
168 |
CleanupStack::PopAndDestroy( &array );
|
|
169 |
|
|
170 |
if ( !found )
|
|
171 |
{
|
|
172 |
// No Connection Method found, insert a new one
|
|
173 |
|
|
174 |
LOG( SIMPLE, "SATENGINE: CSatApnHandler::GetApnInfoL, \
|
|
175 |
Record Not found, insert a new one" )
|
|
176 |
|
|
177 |
TRAPD( insertError, InsertRecordL( *formatName, aUserLogin,
|
|
178 |
aUserPwd, iapId, networkId, aPdpType, aLocalAddress ) )
|
|
179 |
|
|
180 |
if ( KErrNone == insertError )
|
|
181 |
{
|
|
182 |
// Insert OK
|
|
183 |
LOG( NORMAL, "SATENGINE: CSatApnHandler::GetApnInfoL, \
|
|
184 |
new record inserted" )
|
|
185 |
aApnCreated = ETrue;
|
|
186 |
}
|
|
187 |
}
|
|
188 |
|
|
189 |
CleanupStack::PopAndDestroy( &cmManager );
|
|
190 |
CleanupStack::PopAndDestroy( formatName );
|
|
191 |
|
|
192 |
// Set return values
|
|
193 |
aIapId = iapId;
|
|
194 |
aNwId = networkId;
|
|
195 |
|
|
196 |
LOG( SIMPLE, "SATENGINE: CSatApnHandler::GetApnInfoL exiting" )
|
|
197 |
}
|
|
198 |
|
|
199 |
// -----------------------------------------------------------------------------
|
|
200 |
// CSatApnHandler::DeleteApnL
|
|
201 |
// -----------------------------------------------------------------------------
|
|
202 |
//
|
|
203 |
void CSatApnHandler::DeleteApnL( TUint32 aApnId )
|
|
204 |
{
|
|
205 |
LOG( SIMPLE, "SATENGINE: CSatApnHandler::DeleteApnL calling" )
|
|
206 |
|
|
207 |
if ( aApnId )
|
|
208 |
{
|
|
209 |
// Create CMManager Session
|
53
|
210 |
RCmManager cmManager;
|
33
|
211 |
cmManager.OpenLC();
|
|
212 |
|
|
213 |
// Get the connection method
|
53
|
214 |
RCmConnectionMethod cm;
|
33
|
215 |
cm = cmManager.ConnectionMethodL( aApnId );
|
|
216 |
CleanupClosePushL( cm );
|
|
217 |
|
|
218 |
cm.DeleteL();
|
|
219 |
LOG2( SIMPLE, "SATENGINE: CSatApnHandler::DeleteApnL, \
|
|
220 |
delete the connection method %d", aApnId )
|
|
221 |
|
|
222 |
CleanupStack::PopAndDestroy( &cm );
|
|
223 |
CleanupStack::PopAndDestroy( &cmManager );
|
|
224 |
}
|
|
225 |
|
|
226 |
LOG( SIMPLE, "SATENGINE: CSatApnHandler::DeleteApnL exiting" )
|
|
227 |
}
|
|
228 |
|
|
229 |
// -----------------------------------------------------------------------------
|
|
230 |
// CSatApnHandler::InsertRecordL
|
|
231 |
// -----------------------------------------------------------------------------
|
|
232 |
//
|
|
233 |
void CSatApnHandler::InsertRecordL(
|
|
234 |
const TDesC& aReqApn,
|
|
235 |
const RSat::TTextString& aUserLogin,
|
|
236 |
const RSat::TTextString& aUserPwd,
|
|
237 |
TUint32& aIapId,
|
|
238 |
TUint32& aNwId,
|
|
239 |
const RPacketContext::TProtocolType aPdpType,
|
|
240 |
const TDesC8& aLocalAddress )
|
|
241 |
{
|
|
242 |
LOG( SIMPLE, "SATENGINE: CSatApnHandler::InsertRecordL calling" )
|
|
243 |
|
|
244 |
LOG2( NORMAL, "SATENGINE: CSatApnHandler::InsertRecordL, apn is %S",
|
|
245 |
&aReqApn )
|
|
246 |
|
|
247 |
// Create CMManager Session
|
53
|
248 |
RCmManager cmManager;
|
33
|
249 |
cmManager.OpenLC();
|
|
250 |
|
|
251 |
// Create a connection method without destination. So when we can find
|
|
252 |
// the connection method by going through the connection method list.
|
53
|
253 |
RCmConnectionMethod cm;
|
33
|
254 |
cm = cmManager.CreateConnectionMethodL( KUidPacketDataBearerType );
|
|
255 |
CleanupClosePushL( cm );
|
|
256 |
|
|
257 |
// This is shown in GS in Access Point list
|
|
258 |
cm.SetStringAttributeL( CMManager::ECmName, iUtils.BipApnName() );
|
|
259 |
// GPRS connection name
|
|
260 |
cm.SetStringAttributeL( CMManager::EPacketDataAPName, aReqApn );
|
|
261 |
// IPv4 or IPv6
|
|
262 |
cm.SetIntAttributeL( CMManager::EPacketDataPDPType, aPdpType );
|
|
263 |
|
|
264 |
// Set the local IP address (if any)
|
|
265 |
if ( aLocalAddress.Length() )
|
|
266 |
{
|
|
267 |
LOG2( SIMPLE, "SATENGINE: CSatApnHandler::InsertRecordL, Local addr \
|
|
268 |
length: %i", aLocalAddress.Length() )
|
|
269 |
cm.SetString8AttributeL( CMManager::EPacketDataPDPAddress,
|
|
270 |
aLocalAddress );
|
|
271 |
}
|
|
272 |
|
|
273 |
cm.SetBoolAttributeL( CMManager::ECmWapIPSecurity, EFalse );
|
|
274 |
cm.SetIntAttributeL( CMManager::ECmWapIPWSPOption,
|
|
275 |
CMManager::ECmWapWspOptionConnectionOriented );
|
|
276 |
cm.SetBoolAttributeL( CMManager::EPacketDataDisablePlainTextAuth, EFalse );
|
|
277 |
cm.SetBoolAttributeL( CMManager::ECmIFPromptForAuth, EFalse );
|
|
278 |
|
|
279 |
if ( aUserLogin != KNullDesC )
|
|
280 |
{
|
|
281 |
LOG2( NORMAL, "SATENGINE: CSatApnHandler::InsertRecordL, \
|
|
282 |
username is %S", &aUserLogin )
|
|
283 |
cm.SetStringAttributeL( CMManager::ECmIFAuthName, aUserLogin );
|
|
284 |
|
|
285 |
if ( aUserPwd != KNullDesC )
|
|
286 |
{
|
|
287 |
LOG2( NORMAL, "SATENGINE: CSatApnHandler::InsertRecordL, \
|
|
288 |
pwd is %S", &aUserPwd )
|
|
289 |
cm.SetStringAttributeL( CMManager::ECmIFAuthPass, aUserPwd );
|
|
290 |
}
|
|
291 |
}
|
|
292 |
|
|
293 |
// Update the access point ID for use later.
|
|
294 |
cm.UpdateL();
|
|
295 |
|
|
296 |
// Get IAP Id, Network Id
|
|
297 |
aNwId = cm.GetIntAttributeL( CMManager::ECmNetworkId );
|
|
298 |
LOG2( SIMPLE, "SATENGINE: CSatApnHandler::InsertRecordL, \
|
|
299 |
Nwid is %d", aNwId )
|
|
300 |
|
|
301 |
aIapId = cm.GetIntAttributeL( CMManager::ECmIapId );
|
|
302 |
LOG2( SIMPLE, "SATENGINE: CSatApnHandler::InsertRecordL, \
|
|
303 |
aIpId is %d", aIapId )
|
|
304 |
|
|
305 |
CleanupStack::PopAndDestroy( &cm );
|
|
306 |
CleanupStack::PopAndDestroy( &cmManager );
|
|
307 |
|
|
308 |
LOG( SIMPLE, "SATENGINE: CSatApnHandler::InsertRecordL exiting" )
|
|
309 |
}
|
|
310 |
|
|
311 |
// -----------------------------------------------------------------------------
|
|
312 |
// CSatApnHandler::FormatAPN
|
|
313 |
// -----------------------------------------------------------------------------
|
|
314 |
//
|
|
315 |
HBufC* CSatApnHandler::FormatAPN( const RSat::TAccessName&
|
|
316 |
aReqApn ) const
|
|
317 |
{
|
|
318 |
LOG( SIMPLE, "SATENGINE: CSatApnHandler::FormatAPN calling" )
|
|
319 |
|
|
320 |
// Length of the access point name
|
|
321 |
const TInt accessNameLength( aReqApn.Length() );
|
|
322 |
TInt index( 0 );
|
|
323 |
|
|
324 |
// Format APN coming from SIM. Remove length infos and add dots
|
|
325 |
// from the requested APN. The APN format is, for example,
|
|
326 |
// '4Some9accesspnt2fi' and after the format the formatted APN
|
|
327 |
// should be 'Some.accesspnt.fi'
|
|
328 |
HBufC* formatApnName = HBufC::New( aReqApn.MaxLength() );
|
|
329 |
|
|
330 |
if ( formatApnName )
|
|
331 |
{
|
|
332 |
TPtr formApn( formatApnName->Des() );
|
|
333 |
|
|
334 |
// Indicates is the APN format correct. Can be detected only in loops.
|
|
335 |
TBool correctFormat( ETrue );
|
|
336 |
|
|
337 |
// Loop requested APN. The first byte is always the length
|
|
338 |
for ( index = 0; index < accessNameLength && correctFormat; index++ )
|
|
339 |
{
|
|
340 |
// Next byte is the length of the next label
|
|
341 |
const TInt length( aReqApn[index] );
|
|
342 |
|
|
343 |
// Label length cannot be bigger than the length of the APN
|
|
344 |
if ( ( index + length ) > accessNameLength )
|
|
345 |
{
|
|
346 |
LOG( SIMPLE, "SATENGINE: CSatApnHandler::FormatAPN \
|
|
347 |
( index + length ) > accessNameLength" )
|
|
348 |
correctFormat = EFalse;
|
|
349 |
}
|
|
350 |
|
|
351 |
// Append the label
|
|
352 |
for ( TInt j = 0; j < length && correctFormat; j++ )
|
|
353 |
{
|
|
354 |
index++; // move to next index
|
|
355 |
TChar next = aReqApn[index];
|
|
356 |
formApn.Append( next );
|
|
357 |
}
|
|
358 |
|
|
359 |
// Add dot to APN if not end of APN
|
|
360 |
if ( accessNameLength > index + 1 )
|
|
361 |
{
|
|
362 |
LOG( SIMPLE, "SATENGINE: CSatApnHandler::FormatAPN \
|
|
363 |
accessNameLength > index + 1" )
|
|
364 |
formApn.Append( '.' );
|
|
365 |
}
|
|
366 |
}
|
|
367 |
LOG2( SIMPLE, "SATENGINE: CSatApnHandler::FormatAPN index: %i", index )
|
|
368 |
|
|
369 |
// Check did we read all characters
|
|
370 |
if ( !correctFormat || ( index != accessNameLength ) )
|
|
371 |
{
|
|
372 |
// Format was not correct, return zero
|
|
373 |
formApn.Zero();
|
|
374 |
formApn.SetLength( 0 );
|
|
375 |
}
|
|
376 |
else
|
|
377 |
{
|
|
378 |
LOG( SIMPLE, "SATENGINE: CSatApnHandler::FormatAPN lower case" )
|
|
379 |
// Put characters to lower case
|
|
380 |
formApn.LowerCase();
|
|
381 |
}
|
|
382 |
|
|
383 |
LOG( SIMPLE, "SATENGINE: CSatApnHandler::FormatAPN exiting" )
|
|
384 |
}
|
|
385 |
|
|
386 |
return formatApnName;
|
|
387 |
}
|
|
388 |
|
|
389 |
// -----------------------------------------------------------------------------
|
|
390 |
// CSatApnHandler::FindDefaultApL
|
|
391 |
// -----------------------------------------------------------------------------
|
|
392 |
//
|
|
393 |
TUint32 CSatApnHandler::FindDefaultApL(
|
|
394 |
const RPacketContext::TProtocolType& aPdpType )
|
|
395 |
{
|
|
396 |
LOG( SIMPLE, "SATENGINE: CSatApnHandler::FindDefaultApL calling" );
|
|
397 |
TUint32 defaultIap( 0 );
|
|
398 |
TInt pdpType;
|
|
399 |
TBool isFound( EFalse );
|
|
400 |
|
|
401 |
// create a network destination
|
|
402 |
RCmDestination des;
|
|
403 |
RCmConnectionMethod cm;
|
|
404 |
|
|
405 |
// Create CMManager Session
|
|
406 |
RCmManager cmManager;
|
|
407 |
cmManager.OpenL();
|
|
408 |
CleanupClosePushL( cmManager );
|
|
409 |
|
|
410 |
// Get the Connection Method list from the open CMManager session
|
|
411 |
RArray<TUint32> array( KSatCMGranularity );
|
|
412 |
CleanupClosePushL( array );
|
|
413 |
|
|
414 |
// list all available destinations' id
|
|
415 |
cmManager.AllDestinationsL( array );
|
|
416 |
for( TInt i = 0; ( i < array.Count() ) && !isFound; ++i )
|
|
417 |
{
|
|
418 |
des = cmManager.DestinationL( array[i] );
|
|
419 |
CleanupClosePushL( des );
|
|
420 |
|
|
421 |
if ( CMManager::ESnapPurposeInternet ==
|
|
422 |
des.MetadataL( CMManager::ESnapMetadataPurpose ) )
|
|
423 |
{
|
|
424 |
LOG( SIMPLE, "SATENGINE: CSatApnHandler::FindDefaultApL \
|
|
425 |
the fixed destination is identified as 'Internet'" );
|
|
426 |
for( TInt j = 0; ( j < des.ConnectionMethodCount() ) &&
|
|
427 |
!isFound; ++j )
|
|
428 |
{
|
|
429 |
cm = des.ConnectionMethodL( j );
|
|
430 |
CleanupClosePushL( cm );
|
|
431 |
pdpType = cm.GetIntAttributeL(
|
|
432 |
CMManager::EPacketDataPDPType );
|
|
433 |
LOG2( SIMPLE, "SATENGINE: CSatApnHandler::FindDefaultApL \
|
|
434 |
current protocol type is %d", pdpType )
|
|
435 |
if ( pdpType == aPdpType )
|
|
436 |
{
|
|
437 |
defaultIap = cm.GetIntAttributeL( CMManager::ECmIapId );
|
|
438 |
isFound = ETrue;
|
|
439 |
LOG2( SIMPLE, "SATENGINE: CSatApnHandler::FindDefaultApL \
|
|
440 |
default iap had been found %d", defaultIap )
|
|
441 |
}
|
|
442 |
CleanupStack::PopAndDestroy( &cm );
|
|
443 |
}
|
|
444 |
}
|
|
445 |
CleanupStack::PopAndDestroy( &des );
|
|
446 |
}
|
|
447 |
CleanupStack::PopAndDestroy( &array );
|
|
448 |
CleanupStack::PopAndDestroy( &cmManager );
|
|
449 |
|
|
450 |
if ( !isFound )
|
|
451 |
{
|
|
452 |
LOG( SIMPLE, "SATENGINE: CSatApnHandler: default AP not found" );
|
|
453 |
User::Leave( KErrNotFound );
|
|
454 |
}
|
|
455 |
|
|
456 |
LOG( SIMPLE, "SATENGINE: CSatApnHandler::FindDefaultApL exit" )
|
|
457 |
return defaultIap;
|
|
458 |
}
|
|
459 |
// End of File
|