linklayercontrol/networkinterfacemgr/agentprcore/src/agentmcpr.cpp
changeset 0 af10295192d8
equal deleted inserted replaced
-1:000000000000 0:af10295192d8
       
     1 // Copyright (c) 2006-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 //
       
    15 
       
    16 /**
       
    17  @file
       
    18  @internalTechnology
       
    19  @prototype
       
    20 */
       
    21 
       
    22 
       
    23 #include <comms-infras/ss_log.h>
       
    24 #include <elements/sm_core.h>
       
    25 #include <in_sock.h>
       
    26 #include <comms-infras/ss_tiermanagerutils.h>
       
    27 #include <comms-infras/ss_nodeinterfaces.h>
       
    28 
       
    29 #include "agentmcpr.h"
       
    30 #include "CAgentAdapter.h"
       
    31 #include "agentmcpravailabilitytesting.h"
       
    32 #include "agentqueryconnsettingsimpl.h"
       
    33 
       
    34 
       
    35 #ifdef _DEBUG
       
    36 // Panic category for "absolutely impossible!" vanilla ASSERT()-type panics from this module
       
    37 // (if it could happen through user error then you should give it an explicit, documented, category + code)
       
    38 _LIT(KSpecAssert_NifManAgtPrCgntm, "NifManAgtPrCgntm");
       
    39 #endif
       
    40 
       
    41 
       
    42 #ifdef _DEBUG
       
    43 #define KAgentMCprTag KESockMetaConnectionTag
       
    44 _LIT8(KAgentMCprSubTag, "agentmcpr");
       
    45 #endif
       
    46 
       
    47 using namespace ESock;
       
    48 using namespace Messages;
       
    49 using namespace NetStateMachine;
       
    50 using namespace CommsDat;
       
    51 
       
    52 
       
    53 /**
       
    54 Constructor for the Agent Meta Connection Provider
       
    55 @param aFactory The parent factory which created this MCPr
       
    56 */
       
    57 EXPORT_C CAgentMetaConnectionProvider::CAgentMetaConnectionProvider(CMetaConnectionProviderFactoryBase& aFactory,
       
    58                                                                     const ESock::TProviderInfo& aProviderInfo,
       
    59                                                                     const MeshMachine::TNodeActivityMap& aActivityMap)
       
    60 	:	CCoreMetaConnectionProvider(aFactory,aProviderInfo,aActivityMap),
       
    61 		TIfStaticFetcherNearestInHierarchy(this)
       
    62 	{
       
    63 	iQueryConnSettingsImpl = NULL;
       
    64 	}
       
    65 
       
    66 
       
    67 /**
       
    68 D'tor
       
    69 */
       
    70 EXPORT_C CAgentMetaConnectionProvider::~CAgentMetaConnectionProvider()
       
    71 	{
       
    72 	CAgentMetaConnectionProvider::CancelAvailabilityMonitoring(); //Don't call virtual for obvious reasons!
       
    73     DestroyIapView();
       
    74 	delete iQueryConnSettingsImpl;
       
    75 	}
       
    76 
       
    77 EXPORT_C void CAgentMetaConnectionProvider::ConstructL()
       
    78 	{
       
    79 	CCoreMetaConnectionProvider::ConstructL();
       
    80     ProvisionAgentInfoL();
       
    81 	}
       
    82 
       
    83 /**
       
    84 */
       
    85 void CAgentMetaConnectionProvider::ProvisionAgentInfoL()
       
    86     {
       
    87     __CFLOG_VAR((KAgentMCprTag, KAgentMCprSubTag, _L8("CAgentMetaConnectionProvider %08x:\tProvisionAgentInfoL()"), this));
       
    88 
       
    89     // It is possible that an AgentProvisionInfo structure has previously been allocated
       
    90     // We create a new one anyway and override it, meaning the reference on the old one can
       
    91     // possibly be released (handled for us) resulting in its deletion 
       
    92     
       
    93     RMetaExtensionContainer mec;
       
    94     mec.Open(AccessPointConfig());
       
    95     CleanupClosePushL(mec);
       
    96 
       
    97     CAgentProvisionInfo* agentProvisionInfo = new (ELeave) CAgentProvisionInfo;
       
    98     CleanupStack::PushL(agentProvisionInfo);
       
    99     mec.AppendExtensionL(agentProvisionInfo);
       
   100 	CleanupStack::Pop(agentProvisionInfo);
       
   101 
       
   102     HBufC* agentName(NULL);
       
   103 
       
   104     OpenIapViewL();
       
   105     IapView()->GetTextL(KCDTIdBearerAgent, agentName);
       
   106     __ASSERT_DEBUG(agentName, User::Panic(KSpecAssert_NifManAgtPrCgntm, 1));
       
   107 
       
   108 
       
   109     agentProvisionInfo->SetAgentName(*agentName);
       
   110     delete agentName;
       
   111 
       
   112     agentProvisionInfo->SetIapId(IapView()->IapId());
       
   113     TUint32 netId;
       
   114     IapView()->GetIntL(KCDTIdIAPNetwork,netId);
       
   115     agentProvisionInfo->SetNetworkId(netId);
       
   116     agentProvisionInfo->SetBearerSet(0xFF);
       
   117 
       
   118     TUint32 reconnectAttempts = 0;
       
   119     IapView()->GetIntL(KCDTIdMaxConnectionAttempts, reconnectAttempts);
       
   120     agentProvisionInfo->SetReconnectAttempts(reconnectAttempts);
       
   121 
       
   122 
       
   123     agentProvisionInfo->SetCredentials(CreateCredentialsInfoL());
       
   124     iAgentMCPrDoneWithIapView = ETrue;
       
   125     CloseIapView();
       
   126     
       
   127     // Safely reached the end, commit the changes
       
   128 	AccessPointConfig().Close();
       
   129     AccessPointConfig().Open(mec);
       
   130     CleanupStack::PopAndDestroy(&mec);
       
   131     }
       
   132 
       
   133 
       
   134 /**
       
   135 Create the Credentials structure in the Agent Provisioning Info, and populate it
       
   136 with initial values from CommsDat.
       
   137 
       
   138 Assumes that IapView() has been setup.
       
   139 */
       
   140 CCredentialsConfig* CAgentMetaConnectionProvider::CreateCredentialsInfoL()
       
   141 	{
       
   142 	__ASSERT_DEBUG(IapView(), User::Panic(KSpecAssert_NifManAgtPrCgntm, 2));
       
   143 	CCredentialsConfig* pCredentialsConfig = CCredentialsConfig::NewLC(IapView());
       
   144 	CleanupStack::Pop(pCredentialsConfig);
       
   145 	return pCredentialsConfig;
       
   146 	}
       
   147 
       
   148 
       
   149 /**
       
   150 Opens a ref counted Iap View. This must be closed with a call to CloseIapView
       
   151 once the view has been finished with.
       
   152 @return A pointer to the populated CCommsDatIapView.
       
   153 */
       
   154 EXPORT_C CCommsDatIapView* CAgentMetaConnectionProvider::OpenIapViewL()
       
   155 	{
       
   156 	if (iIapView == NULL)
       
   157     	{
       
   158     	iIapView = CCommsDatIapView::NewL(ProviderInfo().APId());
       
   159     	}
       
   160 
       
   161     iIapViewRefCount++;
       
   162 
       
   163 	return iIapView;
       
   164 	}
       
   165 
       
   166 
       
   167 /**
       
   168 Opens a ref counted Iap View adding the returned object to the cleanup stack.
       
   169 This must be closed with a call to CloseIapView once the view has been finished
       
   170 with.
       
   171 @return A pointer to the populated CCommsDatIapView.
       
   172 */
       
   173 EXPORT_C CCommsDatIapView* CAgentMetaConnectionProvider::OpenIapViewLC()
       
   174 	{
       
   175 	CCommsDatIapView* iapView = OpenIapViewL();
       
   176 	CleanupStack::PushL(TCleanupItem(CleanupCloseIapView, this));
       
   177 	return iapView;
       
   178 	}
       
   179 
       
   180 
       
   181 /**
       
   182 The cleanup stack method used to cleanly release the Iap View
       
   183 @note Removal of the item from the cleanup stack may not always cause deletion
       
   184 of the object. It still remains ref counted, and is only releasable once both
       
   185 the ref count has reached zero and the AgentMCPr base class has had a chance
       
   186 to use it for Provisioning.
       
   187 */
       
   188 EXPORT_C void CAgentMetaConnectionProvider::CleanupCloseIapView(TAny* aThis)
       
   189 	{
       
   190 	reinterpret_cast<CAgentMetaConnectionProvider*>(aThis)->CloseIapView();
       
   191 	}
       
   192 
       
   193 
       
   194 /**
       
   195 Closes a reference to the Iap View.
       
   196 @note The Iap View may not be deleted after this call. It is only deleted once
       
   197 both the ref count has reached zero and the AgentMCPr base class has had a
       
   198 chance to use it for Provisioning.
       
   199 */
       
   200 EXPORT_C void CAgentMetaConnectionProvider::CloseIapView()
       
   201 	{
       
   202 	if (iAgentMCPrDoneWithIapView && --iIapViewRefCount == 0)
       
   203     	{
       
   204     	DestroyIapView();
       
   205         }
       
   206 	}
       
   207 
       
   208 void CAgentMetaConnectionProvider::DestroyIapView()
       
   209 	{
       
   210 	delete iIapView;
       
   211 	iIapView = NULL;
       
   212 	}
       
   213 
       
   214 
       
   215 /**
       
   216 Gets a pointer to the current Iap View.
       
   217 @return A pointer to the current Iap View.
       
   218 @note A call to OpenIapViewL or OpenIapViewLC must be made prior to calling
       
   219 this method to ensure the returned value is valid.
       
   220 */
       
   221 EXPORT_C CCommsDatIapView* CAgentMetaConnectionProvider::IapView()
       
   222 	{
       
   223 	__ASSERT_DEBUG(iIapView, User::Panic(KSpecAssert_NifManAgtPrCgntm, 4));
       
   224 	return iIapView;
       
   225 	}
       
   226 
       
   227 /**
       
   228 Sets the Agent Notification Handler to be used by the AgentSCPr
       
   229 @param aNotificationHandler - Pointer to an implementation of the
       
   230 CAgentNotificationHandler class. This must exist for the lifetime of the MCPr.
       
   231 */
       
   232 EXPORT_C void CAgentMetaConnectionProvider::SetAgentNotificationHandlerL (CAgentNotificationHandler* aNotificationHandler)
       
   233    {
       
   234 	CAgentProvisionInfo* agentProvisionInfo = const_cast<CAgentProvisionInfo*>(static_cast<const CAgentProvisionInfo*>(AccessPointConfig().FindExtension(CAgentProvisionInfo::TypeId())));
       
   235 	if (aNotificationHandler || agentProvisionInfo)
       
   236 	    {
       
   237        	if (agentProvisionInfo==NULL)
       
   238        		{
       
   239        		RMetaExtensionContainer mec;
       
   240        		mec.Open(AccessPointConfig());
       
   241        		CleanupClosePushL(mec);
       
   242        		
       
   243        	    agentProvisionInfo = new (ELeave) CAgentProvisionInfo;
       
   244        	    CleanupStack::PushL(agentProvisionInfo);
       
   245        		mec.AppendExtensionL(agentProvisionInfo);
       
   246        		CleanupStack::Pop(agentProvisionInfo);
       
   247        		
       
   248        		AccessPointConfig().Close();
       
   249        		AccessPointConfig().Open(mec);
       
   250        		
       
   251             CleanupStack::PopAndDestroy(&mec);
       
   252        		}
       
   253 
       
   254         agentProvisionInfo->SetAgentNotificationHandler(aNotificationHandler);
       
   255 	    }
       
   256     }
       
   257 
       
   258 /**
       
   259 Retreives an IPv4 address from a CCommsDatIapView
       
   260 @param aIapView - A pointer to a CCommsDatIapView to obtain the field from
       
   261 @param aElementId - The commsdat element Id of the field containing the IPv4 address
       
   262 @param aAddr - The variable to receive the IPv4 address
       
   263 */
       
   264 EXPORT_C void CAgentMetaConnectionProvider::GetIp4AddrL(CCommsDatIapView* aIapView, TMDBElementId aElementId, TUint32& aAddr)
       
   265 	{
       
   266     User::LeaveIfError(GetIp4Addr(aIapView, aElementId, aAddr));
       
   267 	}
       
   268 
       
   269 
       
   270 /**
       
   271 Non-leaving version of GetIp4AddrL. Retreives an IPv4 address from a CCommsDatIapView.
       
   272 @param aIapView - A pointer to a CCommsDatIapView to obtain the field from
       
   273 @param aElementId - The commsdat element Id of the field containing the IPv4 address
       
   274 @param aAddr - The variable to receive the IPv4 address
       
   275 @return A system-wide error code. KErrNone on success.
       
   276 */
       
   277 EXPORT_C TInt CAgentMetaConnectionProvider::GetIp4Addr(CCommsDatIapView* aIapView, TMDBElementId aElementId, TUint32& aAddr)
       
   278     {
       
   279     aAddr = KInetAddrNone;
       
   280     HBufC* buf = NULL;
       
   281     TInt err = aIapView->GetText(aElementId, buf);
       
   282     if (err == KErrNone)
       
   283 		{
       
   284 		__ASSERT_DEBUG(buf, User::Panic(KSpecAssert_NifManAgtPrCgntm, 5));
       
   285 
       
   286 		TInetAddr addr;
       
   287 		if ((err = addr.Input(*buf)) == KErrNone)
       
   288 		    {
       
   289 		    aAddr = addr.Address();
       
   290 		    }
       
   291     	delete buf;
       
   292     	}
       
   293 
       
   294 #ifdef _DEBUG
       
   295 	if (err != KErrNone)
       
   296 		{
       
   297 		__CFLOG_VAR((KAgentMCprTag, KAgentMCprSubTag, _L8("CAgentMetaConnectionProvider:\tGetIp4Addr(): error %d reading CommsDat field %08x"),
       
   298 					 err, aElementId));
       
   299     	}
       
   300 #endif
       
   301 
       
   302     return err;
       
   303     }
       
   304 
       
   305 
       
   306 /**
       
   307 Retreives an IPv6 address from a CCommsDatIapView.
       
   308 @param aIapView - A pointer to a CCommsDatIapView to obtain the field from
       
   309 @param aElementId - The commsdat element Id of the field containing the IPv6 address
       
   310 @param aAddr - The variable to receive the IPv6 address
       
   311 */
       
   312 EXPORT_C void CAgentMetaConnectionProvider::GetIp6AddrL(CCommsDatIapView* aIapView, TMDBElementId aElementId, TIp6Addr& aAddr)
       
   313 	{
       
   314     User::LeaveIfError(GetIp6Addr(aIapView, aElementId, aAddr));
       
   315 	}
       
   316 
       
   317 
       
   318 /**
       
   319 Non-leaving version of GetIp6AddrL. Retreives an IPv6 address from a CCommsDatIapView.
       
   320 @param aIapView - A pointer to a CCommsDatIapView to obtain the field from
       
   321 @param aElementId - The commsdat element Id of the field containing the IPv6 address
       
   322 @param aAddr - The variable to receive the IPv6 address
       
   323 @return A system-wide error code. KErrNone on success.
       
   324 */
       
   325 EXPORT_C TInt CAgentMetaConnectionProvider::GetIp6Addr(CCommsDatIapView* aIapView, TMDBElementId aElementId, TIp6Addr& aAddr)
       
   326 	{
       
   327 	aAddr = KInet6AddrNone;
       
   328 	HBufC* buf = NULL;
       
   329 	TInt err = aIapView->GetText(aElementId, buf);
       
   330 	if (err == KErrNone)
       
   331     	{
       
   332     	__ASSERT_DEBUG(buf, User::Panic(KSpecAssert_NifManAgtPrCgntm, 6));
       
   333 
       
   334     	TInetAddr ip6Addr;
       
   335     	if ((err = ip6Addr.Input(*buf)) == KErrNone)
       
   336         	{
       
   337         	aAddr = ip6Addr.Ip6Address();
       
   338         	}
       
   339     	delete buf;
       
   340     	}
       
   341 
       
   342 #ifdef _DEBUG
       
   343 	if (err != KErrNone)
       
   344 		{
       
   345 		__CFLOG_VAR((KAgentMCprTag, KAgentMCprSubTag, _L8("CAgentMetaConnectionProvider:\tGetIp6Addr(): error %d reading CommsDat field %08x"),
       
   346 					 err, aElementId));
       
   347     	}
       
   348 #endif
       
   349 
       
   350     return err;
       
   351 	}
       
   352 
       
   353 
       
   354 #ifdef _DEBUG
       
   355 EXPORT_C void CAgentMetaConnectionProvider::StartAvailabilityMonitoringL(const TNodeCtxId& aAvailabilityActivity)
       
   356 	{
       
   357 	__ASSERT_DEBUG(iAvailabilitySubscriber==NULL, User::Panic(KSpecAssert_NifManAgtPrCgntm, 7)); //Only one start allowed from the availability activity!
       
   358 	iAvailabilitySubscriber = CAvailabilitySubscriber::NewL(aAvailabilityActivity, ProviderInfo().APId());
       
   359 	AddClientL(iAvailabilitySubscriber->Id(), TClientType(TClientType::ERegistrar, TCFClientType::EAvailabilityProvider));
       
   360 #else
       
   361 EXPORT_C void CAgentMetaConnectionProvider::StartAvailabilityMonitoringL(const Messages::TNodeCtxId& /*aAvailabilityActivity*/)
       
   362 	{
       
   363 #endif
       
   364 	}
       
   365 
       
   366 EXPORT_C void CAgentMetaConnectionProvider::CancelAvailabilityMonitoring()
       
   367 	{
       
   368 #ifdef _DEBUG
       
   369 	if (iAvailabilitySubscriber)
       
   370 		{
       
   371 		RemoveClient(iAvailabilitySubscriber->Id());
       
   372 		iAvailabilitySubscriber = NULL; //iAvailabilitySubscriber will delete itself when cancelled from the availability activity
       
   373 		}
       
   374 #endif
       
   375 	}
       
   376 
       
   377 /**
       
   378 Retrieves the MLinkCprLegacyDataAccessExtApi implementation
       
   379 @param aInterface Pointer to the interface implementation.
       
   380 */
       
   381 void CAgentMetaConnectionProvider::ReturnInterfacePtrL(MLinkMCprLegacyDataAccessApiExt*& aInterface)
       
   382     {
       
   383     aInterface = this;
       
   384     }
       
   385 
       
   386 /**
       
   387 Retrieves the MQueryConnSettingsApiExt implementation
       
   388 @param aInterface Pointer to the interface implementation.
       
   389 */
       
   390 void CAgentMetaConnectionProvider::ReturnInterfacePtrL(MQueryConnSettingsApiExt*& aInterface)
       
   391     {
       
   392     if (!iQueryConnSettingsImpl)
       
   393     	{
       
   394     	const CAgentProvisionInfo* provisionInfo = AgentProvisionInfo();
       
   395     	iQueryConnSettingsImpl = new (ELeave)CAgentQueryConnSettingsImpl(*provisionInfo, AccessPointConfig());
       
   396     	}
       
   397     aInterface = iQueryConnSettingsImpl;
       
   398     }
       
   399 
       
   400 EXPORT_C void CAgentMetaConnectionProvider::GetIntSettingL(const TDesC& aSettingName, TUint32& aValue, MPlatsecApiExt* aPlatsecItf)
       
   401     {
       
   402     const CAgentProvisionInfo* provisionInfo = AgentProvisionInfo();
       
   403     if (!provisionInfo)
       
   404         {
       
   405         User::Leave (KErrNotReady);
       
   406         }
       
   407 
       
   408     TMDBElementId elementId = MapFieldNameL(aSettingName, aPlatsecItf);
       
   409     MQueryConnSettingsApiExt* queryItf;
       
   410     ReturnInterfacePtrL(queryItf);
       
   411 
       
   412     TInt err = queryItf->GetInt(elementId, aValue, aPlatsecItf);
       
   413     if (err == KErrNotFound)
       
   414         {
       
   415         elementId = SecondChanceModemBearerLegacyMapFieldNameL(aSettingName, aPlatsecItf);
       
   416         err = queryItf->GetInt(elementId, aValue, aPlatsecItf);
       
   417         }
       
   418     User::LeaveIfError(err);
       
   419     }
       
   420 
       
   421 
       
   422 EXPORT_C void CAgentMetaConnectionProvider::GetBoolSettingL(const TDesC& aSettingName, TBool& aValue, MPlatsecApiExt* aPlatsecItf)
       
   423     {
       
   424     const CAgentProvisionInfo* provisionInfo = AgentProvisionInfo();
       
   425     if (!provisionInfo)
       
   426         {
       
   427         User::Leave (KErrNotReady);
       
   428         }
       
   429 
       
   430     TMDBElementId elementId = MapFieldNameL(aSettingName, aPlatsecItf);
       
   431     MQueryConnSettingsApiExt* queryItf;
       
   432     ReturnInterfacePtrL(queryItf);
       
   433 
       
   434     TInt err = queryItf->GetBool(elementId, aValue, aPlatsecItf);
       
   435     if (err == KErrNotFound)
       
   436         {
       
   437         elementId = SecondChanceModemBearerLegacyMapFieldNameL(aSettingName, aPlatsecItf);
       
   438         err = queryItf->GetBool(elementId, aValue, aPlatsecItf);
       
   439         }
       
   440     User::LeaveIfError(err);
       
   441     }
       
   442 
       
   443 
       
   444 EXPORT_C void CAgentMetaConnectionProvider::GetDes8SettingL(const TDesC& aSettingName, TDes8& aValue, MPlatsecApiExt* aPlatsecItf)
       
   445     {
       
   446     const CAgentProvisionInfo* provisionInfo = AgentProvisionInfo();
       
   447     if (!provisionInfo)
       
   448         {
       
   449         User::Leave (KErrNotReady);
       
   450         }
       
   451 
       
   452     TMDBElementId elementId = MapFieldNameL(aSettingName, aPlatsecItf);
       
   453     MQueryConnSettingsApiExt* queryItf;
       
   454     ReturnInterfacePtrL(queryItf);
       
   455 
       
   456     HBufC8* value;
       
   457     TInt err = queryItf->GetText(elementId, value, aPlatsecItf);
       
   458     if (err == KErrNotFound)
       
   459         {
       
   460         elementId = SecondChanceModemBearerLegacyMapFieldNameL(aSettingName, aPlatsecItf);
       
   461         err = queryItf->GetText(elementId, value, aPlatsecItf);
       
   462         }
       
   463     User::LeaveIfError(err);
       
   464     aValue = *value;
       
   465     delete value;
       
   466     }
       
   467 
       
   468 
       
   469 EXPORT_C void CAgentMetaConnectionProvider::GetDes16SettingL(const TDesC& aSettingName, TDes16& aValue, MPlatsecApiExt* aPlatsecItf)
       
   470     {
       
   471     const CAgentProvisionInfo* provisionInfo = AgentProvisionInfo();
       
   472     if (!provisionInfo)
       
   473         {
       
   474         User::Leave (KErrNotReady);
       
   475         }
       
   476 
       
   477     TMDBElementId elementId = MapFieldNameL(aSettingName, aPlatsecItf);
       
   478     MQueryConnSettingsApiExt* queryItf;
       
   479     ReturnInterfacePtrL(queryItf);
       
   480 
       
   481     HBufC* value;
       
   482     TInt err = queryItf->GetText(elementId, value, aPlatsecItf);
       
   483     if (err == KErrNotFound)
       
   484         {
       
   485         elementId = SecondChanceModemBearerLegacyMapFieldNameL(aSettingName, aPlatsecItf);
       
   486         err = queryItf->GetText(elementId, value, aPlatsecItf);
       
   487         }
       
   488     User::LeaveIfError(err);
       
   489     aValue = *value;
       
   490     delete value;
       
   491     }
       
   492 
       
   493 
       
   494 EXPORT_C void CAgentMetaConnectionProvider::GetLongDesSettingL(const TDesC& aSettingName, HBufC*& aValue, MPlatsecApiExt* aPlatsecItf)
       
   495     {
       
   496     aValue = NULL;
       
   497 
       
   498     const CAgentProvisionInfo* provisionInfo = AgentProvisionInfo();
       
   499     if (!provisionInfo)
       
   500         {
       
   501         User::Leave (KErrNotReady);
       
   502         }
       
   503 
       
   504     TMDBElementId elementId = MapFieldNameL(aSettingName, aPlatsecItf);
       
   505     MQueryConnSettingsApiExt* queryItf;
       
   506     ReturnInterfacePtrL(queryItf);
       
   507 
       
   508     TInt err = queryItf->GetText(elementId, aValue, aPlatsecItf);
       
   509     if (err == KErrNotFound)
       
   510         {
       
   511         elementId = SecondChanceModemBearerLegacyMapFieldNameL(aSettingName, aPlatsecItf);
       
   512         err = queryItf->GetText(elementId, aValue, aPlatsecItf);
       
   513         }
       
   514     User::LeaveIfError(err);
       
   515     }
       
   516 
       
   517 
       
   518 TMDBElementId CAgentMetaConnectionProvider::MapFieldNameL(const TDesC& aSettingName, MPlatsecApiExt* aPlatsecItf)
       
   519     {
       
   520     _LIT(KSlash, "\\");
       
   521     TInt pos = aSettingName.Find(KSlash);
       
   522     if (pos != KErrNotFound)
       
   523         {
       
   524         return CommDbShimUtil::GetElementIdFromFieldNameL(aSettingName);
       
   525         }
       
   526 
       
   527     MQueryConnSettingsApiExt* queryItf;
       
   528     ReturnInterfacePtrL(queryItf);
       
   529 
       
   530     HBufC16* serviceTable;
       
   531     User::LeaveIfError(queryItf->GetText(KCDTIdIAPServiceType, serviceTable, aPlatsecItf));
       
   532 
       
   533     const TInt KMaxFieldSize = 2*KCommsDbSvrMaxFieldLength + 1;
       
   534     TBuf<KMaxFieldSize> field;
       
   535 
       
   536     field = *serviceTable;
       
   537     delete serviceTable;
       
   538 
       
   539     field.Append(KSlash);
       
   540     field.Append(aSettingName);
       
   541     return CommDbShimUtil::GetElementIdFromFieldNameL(field);
       
   542     }
       
   543 
       
   544 TMDBElementId CAgentMetaConnectionProvider::SecondChanceModemBearerLegacyMapFieldNameL(const TDesC& aSettingName, MPlatsecApiExt* aPlatsecItf)
       
   545     {
       
   546     //This nasty looking method re-implements the lagacy behaviour whereat, despite the current IAP not
       
   547     //featuring the ModemBearer table (because it represnts LAN for instance) would still serve queries
       
   548     //addressed to "ModemBearer\\<field>>" assuming the local equivallent of the ModemBearer (e.g: LanBearer)
       
   549     //table is actually meant.
       
   550     _LIT(KSlash, "\\");
       
   551     TInt pos = aSettingName.Find(KSlash);
       
   552     if (pos != KErrNotFound)
       
   553         {
       
   554         TPtrC left = aSettingName.Left(pos);
       
   555         TPtrC right = aSettingName.Mid(pos+1);
       
   556         if (left.CompareC(TPtrC(MODEM_BEARER)) == 0)
       
   557             {
       
   558             HBufC16* bearerTable;
       
   559 
       
   560             MQueryConnSettingsApiExt* queryItf;
       
   561             ReturnInterfacePtrL(queryItf);
       
   562 
       
   563             User::LeaveIfError(queryItf->GetText(KCDTIdIAPBearerType, bearerTable, aPlatsecItf));
       
   564 
       
   565             const TInt KMaxFieldSize = 2*KCommsDbSvrMaxFieldLength + 1;
       
   566             TBuf<KMaxFieldSize> field;
       
   567 
       
   568             field = *bearerTable;
       
   569             delete bearerTable;
       
   570 
       
   571             field.Append(KSlash);
       
   572             field.Append(right);
       
   573             return MapFieldNameL(field, aPlatsecItf);
       
   574             }
       
   575         }
       
   576     User::Leave(KErrNotFound);
       
   577     return 0;
       
   578     }
       
   579 
       
   580 /**
       
   581 Retrieves the Agent Provider specific provisioning information as given by the MCpr
       
   582 transition.
       
   583 
       
   584 @internalTechnology
       
   585 */
       
   586 const CAgentProvisionInfo* CAgentMetaConnectionProvider::AgentProvisionInfo()
       
   587     {
       
   588     const CAgentProvisionInfo* agentProvisionInfo = static_cast<const CAgentProvisionInfo*>(AccessPointConfig().FindExtension(CAgentProvisionInfo::TypeId()));
       
   589 	__ASSERT_DEBUG(agentProvisionInfo, User::Panic(KSpecAssert_NifManAgtPrCgntm, 8));
       
   590     return agentProvisionInfo;
       
   591     }
       
   592