telephonyprotocols/pdplayer/src/PDPConfig.cpp
branchRCL_3
changeset 21 2492a6e4aed7
parent 15 fc69e1e37771
child 65 630d2f34d719
equal deleted inserted replaced
17:3f227a47ad75 21:2492a6e4aed7
    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     }
       
   281 
       
   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     }
   239     }
   326 
   240 
   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;