telephonyprotocols/pdplayer/src/PDPConfig.cpp
changeset 23 6b1d113cdff3
parent 19 1f776524b15c
child 24 6638e7f4bd8f
child 42 3adadc800673
equal deleted inserted replaced
20:244d7c5f118e 23:6b1d113cdff3
     1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 2006-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
    18 /**
    18 /**
    19  @file
    19  @file
    20  @internalComponent
    20  @internalComponent
    21 */
    21 */
    22 
    22 
    23 #include <hash.h>
       
    24 #include <e32math.h>
       
    25 #include <comms-infras/ss_log.h>
    23 #include <comms-infras/ss_log.h>
    26 #include <in_sock.h>
    24 #include <in_sock.h>
    27 #include <comms-infras/metadata.h>
    25 #include <comms-infras/metadata.h>
    28 #include <comms-infras/agentmcpr.h>
    26 #include <comms-infras/agentmcpr.h>
    29 #include <comms-infras/ss_log.h>
    27 #include <comms-infras/ss_log.h>
    35 
    33 
    36 #if defined(__CFLOG_ACTIVE)
    34 #if defined(__CFLOG_ACTIVE)
    37 #define KPDPMCprTag KESockMetaConnectionTag
    35 #define KPDPMCprTag KESockMetaConnectionTag
    38 _LIT8(KPDPMCprSubTag, "pdpmcpr");
    36 _LIT8(KPDPMCprSubTag, "pdpmcpr");
    39 #endif
    37 #endif
    40 
       
    41 const TUint8 KGenericNifChallengeSize = 8;
       
    42 const TUint KGenericNifIdLength = 1;
       
    43 
    38 
    44 //
    39 //
    45 // Attribute table for provisioning structure passed to CFProtocol
    40 // Attribute table for provisioning structure passed to CFProtocol
    46 //
    41 //
    47 START_ATTRIBUTE_TABLE(CGPRSProvision, CGPRSProvision::EUid, CGPRSProvision::ETypeId)
    42 START_ATTRIBUTE_TABLE(CGPRSProvision, CGPRSProvision::EUid, CGPRSProvision::ETypeId)
   208     {
   203     {
   209     HBufC* buf = NULL;
   204     HBufC* buf = NULL;
   210     TInt getErr;
   205     TInt getErr;
   211 
   206 
   212     __CFLOG_VAR((KPDPMCprTag, KPDPMCprSubTag, _L8("CGPRSProvision [this=%08x]::RetrieveAuthenticationInfoL()"), this));
   207     __CFLOG_VAR((KPDPMCprTag, KPDPMCprSubTag, _L8("CGPRSProvision [this=%08x]::RetrieveAuthenticationInfoL()"), this));
   213     
   208 
   214     getErr = aIapView->GetText(KCDTIdWCDMAIfAuthName | KCDTIdOutgoingGprsRecord, buf);
   209     getErr = aIapView->GetText(KCDTIdWCDMAIfAuthName | KCDTIdOutgoingGprsRecord, buf);
   215     if ( getErr == KErrNone )
   210     if ( getErr == KErrNone )
   216         {
   211         {
   217         ASSERT(buf);
   212         ASSERT(buf);
   218         aProtocolConfigOption.iAuthInfo.iUsername.Copy(*buf);
   213         aProtocolConfigOption.iAuthInfo.iUsername.Copy(*buf);
   219         delete buf;
   214         delete buf;
   220         buf = NULL;
   215         buf = NULL;
   221 
   216         
   222         __CFLOG_VAR((KPDPMCprTag, KPDPMCprSubTag, _L8("CGPRSProvision [this=%08x]::RetrieveAuthenticationInfoL() KCDTIdWCDMAIfAuthName [%S] "), this, &aProtocolConfigOption.iAuthInfo.iUsername));
   217         __CFLOG_VAR((KPDPMCprTag, KPDPMCprSubTag, _L8("CGPRSProvision [this=%08x]::RetrieveAuthenticationInfoL() KCDTIdWCDMAIfAuthName [%S] "), this, &aProtocolConfigOption.iAuthInfo.iUsername));
   223 
   218         
   224         aProtocolConfigOption.iId = 1;
   219 		aProtocolConfigOption.iId = 1;
   225 
   220         getErr = aIapView->GetText(KCDTIdWCDMAIfAuthPass | KCDTIdOutgoingGprsRecord, buf);
   226         TBool isDisableAuth = EFalse;
   221         if ( getErr == KErrNone )
   227         getErr = aIapView->GetBool(KCDTIdWCDMADisablePlainTextAuth | KCDTIdOutgoingGprsRecord,isDisableAuth);
       
   228         __CFLOG_VAR((KPDPMCprTag, KPDPMCprSubTag, _L8("CGPRSProvision [this=%08x]::RetrieveAuthenticationInfoL() KCDTIdWCDMADisablePlainTextAuth [%d]"), this, isDisableAuth));
       
   229         if (getErr == KErrNone)
       
   230             {
   222             {
   231             getErr = aIapView->GetText(KCDTIdWCDMAIfAuthPass | KCDTIdOutgoingGprsRecord, buf);
   223             ASSERT(buf);
   232             if ( getErr == KErrNone )
   224             aProtocolConfigOption.iAuthInfo.iPassword.Copy(*buf);
   233                 {
   225             delete buf;
   234                 ASSERT(buf);
   226             buf = NULL;
   235                 aProtocolConfigOption.iAuthInfo.iPassword.Copy(*buf);
   227             
   236                 delete buf;
   228             __CFLOG_VAR((KPDPMCprTag, KPDPMCprSubTag, _L8("CGPRSProvision [this=%08x]::RetrieveAuthenticationInfoL() KCDTIdWCDMAIfAuthPass [%S]"), this, &aProtocolConfigOption.iAuthInfo.iPassword));
   237                 buf = NULL;
       
   238 
       
   239                 __CFLOG_VAR((KPDPMCprTag, KPDPMCprSubTag, _L8("CGPRSProvision [this=%08x]::RetrieveAuthenticationInfoL() KCDTIdWCDMAIfAuthPass [%S]"), this, &aProtocolConfigOption.iAuthInfo.iPassword));
       
   240 
       
   241                 if (isDisableAuth)  //If Disable, CHAP will be used.
       
   242                     {
       
   243                     aProtocolConfigOption.iAuthInfo.iProtocol = RPacketContext::EProtocolCHAP;
       
   244                     CreateChallengeAndResponseForChapL(aProtocolConfigOption);
       
   245                     }
       
   246                 else
       
   247                     {
       
   248                     aProtocolConfigOption.iAuthInfo.iProtocol = RPacketContext::EProtocolPAP;
       
   249                     }
       
   250                 }
       
   251             else if (getErr == KErrNotFound)
       
   252                 {
       
   253                 if (isDisableAuth) //ERROR: CHAP used without password???
       
   254                     {
       
   255                     User::Leave(KErrArgument);
       
   256                     }
       
   257                 else    //PAP used without password.
       
   258                     {
       
   259                     aProtocolConfigOption.iAuthInfo.iProtocol = RPacketContext::EProtocolPAP;
       
   260                     }
       
   261                 }
       
   262             else    //getErr != KErrNotFound
       
   263                 {
       
   264                 User::Leave(getErr);
       
   265                 }
       
   266             }
   229             }
   267         else
   230         else if (getErr != KErrNotFound)
   268             {
   231             {
   269             User::Leave(getErr);
   232             User::Leave(getErr);
   270             }
   233             }
   271         }
   234         }
   272     else if (getErr == KErrNotFound )   //No Authentication Required.
   235     else if (getErr != KErrNotFound)
   273         {
       
   274         aProtocolConfigOption.iAuthInfo.iProtocol = RPacketContext::EProtocolNone;
       
   275         }
       
   276     else    //getErr != KErrNotFound
       
   277         {
   236         {
   278         User::Leave(getErr);
   237         User::Leave(getErr);
   279         }
   238         }
   280     }
   239     }
   281 
   240 
   282 void CGPRSProvision::CreateChallengeAndResponseForChapL(RPacketContext::TProtocolConfigOptionV2& aProtocolConfigOption)
       
   283     {
       
   284     //Challenge
       
   285     TTime currentTime;
       
   286     currentTime.UniversalTime();
       
   287     
       
   288     TInt64 seedValue = currentTime.Int64();
       
   289 
       
   290     TUint8 challenge[KGenericNifChallengeSize] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
       
   291     
       
   292     TUint8 i=0;
       
   293     while(i < KGenericNifChallengeSize)
       
   294         {
       
   295         challenge[i] = (TUint8)(Math::Rand(seedValue)%256);
       
   296         aProtocolConfigOption.iChallenge.Append(challenge[i++]);
       
   297         }
       
   298 
       
   299     //Response
       
   300     TBuf8<KGenericNifIdLength+KCommsDbSvrMaxColumnNameLength+KGenericNifChallengeSize> message;
       
   301     message.Append(aProtocolConfigOption.iId);
       
   302     message.Append(aProtocolConfigOption.iAuthInfo.iPassword);
       
   303     message.Append(aProtocolConfigOption.iChallenge);
       
   304     
       
   305     TInt length = 1 /*iId length */ + aProtocolConfigOption.iAuthInfo.iPassword.Length() + KGenericNifChallengeSize;
       
   306 
       
   307     HBufC8* buf = HBufC8::NewL(length);
       
   308     
       
   309     CleanupStack::PushL(buf);
       
   310      
       
   311     TPtr8 ptr((TUint8*)buf->Des().Ptr(),length);
       
   312     
       
   313     ptr.Copy(message);
       
   314     
       
   315     CMD5* md5=0;
       
   316     md5 = CMD5::NewL();
       
   317     
       
   318     CleanupStack::PushL(md5);
       
   319     
       
   320     TPtrC8 Response = md5->Hash(ptr);
       
   321     
       
   322     aProtocolConfigOption.iResponse.Copy(Response);
       
   323     
       
   324     CleanupStack::PopAndDestroy(2);
       
   325     }
       
   326 
       
   327 void CGPRSProvision::RetrieveIPAndDnsSettingsL(TDes8& aPdpAddress, TDes8& aDns1, TDes8& aDns2, ESock::CCommsDatIapView* aIapView) const
   241 void CGPRSProvision::RetrieveIPAndDnsSettingsL(TDes8& aPdpAddress, TDes8& aDns1, TDes8& aDns2, ESock::CCommsDatIapView* aIapView) const
   328 	{
   242 	{
   329 	HBufC* buf = NULL;
   243 	HBufC* buf = NULL;
   330 
   244 
   331 	aPdpAddress.SetLength(0);
   245 	aPdpAddress.SetLength(0);
   335 	TBool fromServer;
   249 	TBool fromServer;
   336 	aIapView->GetBoolL(KCDTIdWCDMAIPAddrFromServer | KCDTIdOutgoingGprsRecord, fromServer);
   250 	aIapView->GetBoolL(KCDTIdWCDMAIPAddrFromServer | KCDTIdOutgoingGprsRecord, fromServer);
   337 	if (!fromServer)
   251 	if (!fromServer)
   338 	    {
   252 	    {
   339     	aIapView->GetTextL(KCDTIdWCDMAIPAddr | KCDTIdOutgoingGprsRecord, buf);
   253     	aIapView->GetTextL(KCDTIdWCDMAIPAddr | KCDTIdOutgoingGprsRecord, buf);
       
   254     	TInetAddr addr;
       
   255     	User::LeaveIfError(addr.Input(*buf));
       
   256     	// sending ASCII to MA but checking the validity of the address above.
   340     	aPdpAddress.Copy(*buf);
   257     	aPdpAddress.Copy(*buf);
   341     	delete buf;
   258     	delete buf;
   342     	buf = NULL;
   259     	buf = NULL;
   343 	    }
   260 	    }
   344 	
   261 	
   361 	    // IPv4 settings
   278 	    // IPv4 settings
   362     	aIapView->GetBoolL(KCDTIdWCDMAIPDNSAddrFromServer | KCDTIdOutgoingGprsRecord, fromServer);
   279     	aIapView->GetBoolL(KCDTIdWCDMAIPDNSAddrFromServer | KCDTIdOutgoingGprsRecord, fromServer);
   363     	if (!fromServer)
   280     	if (!fromServer)
   364     	    {
   281     	    {
   365     	    aIapView->GetTextL(KCDTIdWCDMAIPNameServer1 | KCDTIdOutgoingGprsRecord, buf);
   282     	    aIapView->GetTextL(KCDTIdWCDMAIPNameServer1 | KCDTIdOutgoingGprsRecord, buf);
       
   283             TInetAddr addr;
       
   284             User::LeaveIfError(addr.Input(*buf));
       
   285             // sending ASCII to MA but checking the validity of the address above.
   366     	    aDns1.Copy(*buf);
   286     	    aDns1.Copy(*buf);
   367         	delete buf;
   287         	delete buf;
   368         	buf = NULL;
   288         	buf = NULL;
   369     	    aIapView->GetTextL(KCDTIdWCDMAIPNameServer2 | KCDTIdOutgoingGprsRecord, buf);
   289     	    aIapView->GetTextL(KCDTIdWCDMAIPNameServer2 | KCDTIdOutgoingGprsRecord, buf);
       
   290     	    User::LeaveIfError(addr.Input(*buf));
       
   291             // sending ASCII to MA but checking the validity of the address above.
   370         	aDns2.Copy(*buf);
   292         	aDns2.Copy(*buf);
   371     	    delete buf;
   293     	    delete buf;
   372         	buf = NULL;
   294         	buf = NULL;
   373     	    }
   295     	    }
   374 	    }
   296 	    }
   377 	    // IPv6 settings
   299 	    // IPv6 settings
   378     	aIapView->GetBoolL(KCDTIdWCDMAIP6DNSAddrFromServer | KCDTIdOutgoingGprsRecord, fromServer);
   300     	aIapView->GetBoolL(KCDTIdWCDMAIP6DNSAddrFromServer | KCDTIdOutgoingGprsRecord, fromServer);
   379     	if (!fromServer)
   301     	if (!fromServer)
   380     	    {
   302     	    {
   381     	    aIapView->GetTextL(KCDTIdWCDMAIP6NameServer1 | KCDTIdOutgoingGprsRecord, buf);
   303     	    aIapView->GetTextL(KCDTIdWCDMAIP6NameServer1 | KCDTIdOutgoingGprsRecord, buf);
   382     	    aDns1.Copy(*buf);
   304             TInetAddr addr;
       
   305             User::LeaveIfError(addr.Input(*buf));
       
   306             // sending ASCII to MA but checking the validity of the address above.
       
   307             aDns1.Copy(*buf);
   383     	    delete buf;
   308     	    delete buf;
   384     		buf = NULL;
   309     		buf = NULL;
   385     	    aIapView->GetTextL(KCDTIdWCDMAIP6NameServer2 | KCDTIdOutgoingGprsRecord, buf);
   310     	    aIapView->GetTextL(KCDTIdWCDMAIP6NameServer2 | KCDTIdOutgoingGprsRecord, buf);
       
   311             User::LeaveIfError(addr.Input(*buf));
       
   312             // sending ASCII to MA but checking the validity of the address above.
   386           	aDns2.Copy(*buf);
   313           	aDns2.Copy(*buf);
   387         	delete buf;
   314         	delete buf;
   388             buf = NULL;
   315             buf = NULL;
   389     	    }
   316     	    }
   390 	    }
   317 	    }