65 * @internalTechnology |
64 * @internalTechnology |
66 * |
65 * |
67 */ |
66 */ |
68 { |
67 { |
69 __CFLOG_VAR((KLogSubSysDHCP, KLogCode, _L8("CDHCPStateMachine::ConstructL"))); |
68 __CFLOG_VAR((KLogSubSysDHCP, KLogCode, _L8("CDHCPStateMachine::ConstructL"))); |
70 LoadConfigurationFile(); |
69 |
71 #ifdef _DEBUG |
70 #ifdef _DEBUG |
72 // let's set debug properties to something |
71 // let's set debug properties to something |
73 // so they can be read immediately.. |
72 // so they can be read immediately.. |
74 CDHCPStateMachine* const & iStateMachine = this; |
73 CDHCPStateMachine* const & iStateMachine = this; |
75 CDHCPStateMachine* const & iDhcpStateMachine = iStateMachine; |
74 CDHCPStateMachine* const & iDhcpStateMachine = iStateMachine; |
421 // how could we attempt to handle it anyway?...keep trying??? i think not... |
420 // how could we attempt to handle it anyway?...keep trying??? i think not... |
422 // ensure that we have a socket to write down |
421 // ensure that we have a socket to write down |
423 iSocket.Close(); |
422 iSocket.Close(); |
424 TInt error = iSocket.Open(iEsock, KAfInet, KSockDatagram, KProtocolInetUdp, iConnection); |
423 TInt error = iSocket.Open(iEsock, KAfInet, KSockDatagram, KProtocolInetUdp, iConnection); |
425 |
424 |
426 if(error == KErrNone) |
425 if(error == KErrNone) |
427 { |
426 { |
428 error = iSocket.SetOpt(KSoInetConfigInterface, KSolInetIfCtrl, configInfo); |
427 error = iSocket.SetOpt(KSoInetConfigInterface, KSolInetIfCtrl, configInfo); |
429 if(error == KErrNone) |
428 if(error == KErrNone) |
430 { |
429 { |
431 // make socket invisible for interface counting |
430 // make socket invisible for interface counting |
432 error = iSocket.SetOpt(KSoKeepInterfaceUp, KSolInetIp, 0); |
431 iSocket.SetOpt(KSoKeepInterfaceUp, KSolInetIp, 0); |
433 if(error != KErrNone) |
432 if(error != KErrNone) |
434 { |
433 { |
435 __CFLOG_VAR((KLogSubSysDHCP, KLogCode, _L("CDHCPStateMachine::RemoveConfiguredAddress, SetOpt Failed to set KSolInetIp"))); |
434 __CFLOG_VAR((KLogSubSysDHCP, KLogCode, _L("CDHCPStateMachine::RemoveConfiguredAddress, SetOpt Failed to set KSoKeepInterfaceUp"))); |
436 } |
435 } |
437 } |
436 } |
438 else |
437 else |
439 { |
438 { |
440 __CFLOG_VAR((KLogSubSysDHCP, KLogCode, _L("CDHCPStateMachine::RemoveConfiguredAddress,SetOpt Failed to set KsolInetIfCtrl"))); |
439 __CFLOG_VAR((KLogSubSysDHCP, KLogCode, _L("CDHCPStateMachine::RemoveConfiguredAddress, SetOpt Failed to set KSoInetConfigInterface"))); |
441 } |
440 } |
442 } |
441 } |
443 else |
442 else |
444 { |
443 { |
445 __CFLOG_VAR((KLogSubSysDHCP, KLogCode, _L("CDHCPStateMachine::RemoveConfiguredAddress,Socket Open Failed: Due to %d"),error)); |
444 __CFLOG_VAR((KLogSubSysDHCP, KLogCode, _L("CDHCPStateMachine::RemoveConfiguredAddress, Socket Open Failed: Due to KErrNotReady"))); |
446 } |
445 } |
447 } |
446 } |
448 |
447 |
449 void CDHCPStateMachine::ConfigureInterfaceL( const TSoInetInterfaceInfoExtnDnsSuffix& aInterfaceInfo ) |
448 void CDHCPStateMachine::ConfigureInterfaceL( const TSoInet6InterfaceInfo& aInterfaceInfo ) |
450 /** |
449 /** |
451 * Set the interface IP address and other params |
450 * Set the interface IP address and other params |
452 * into the TCP/IP6 stack. |
451 * into the TCP/IP6 stack. |
453 * |
452 * |
454 * What we set depends on the setup |
453 * What we set depends on the setup |
464 * |
463 * |
465 * @internalTechnology |
464 * @internalTechnology |
466 */ |
465 */ |
467 { |
466 { |
468 |
467 |
469 TPckgBuf<TSoInetInterfaceInfoExtnDnsSuffix> configInfo(aInterfaceInfo); |
468 TPckgBuf<TSoInet6InterfaceInfo> configInfo(aInterfaceInfo); |
470 |
469 |
471 |
470 |
472 __CFLOG_VAR((KLogSubSysDHCP, KLogCode, _L8("CDHCPStateMachine::ConfigureInterfaceL - KSoInetConfigInterface"))); |
471 __CFLOG_VAR((KLogSubSysDHCP, KLogCode, _L8("CDHCPStateMachine::ConfigureInterfaceL - KSoInetConfigInterface"))); |
473 |
472 |
474 User::LeaveIfError(iSocket.SetOpt(KSoInetConfigInterface, KSolInetIfCtrl, configInfo)); |
473 User::LeaveIfError(iSocket.SetOpt(KSoInetConfigInterface, KSolInetIfCtrl, configInfo)); |
711 } |
710 } |
712 return EFalse; |
711 return EFalse; |
713 } |
712 } |
714 |
713 |
715 |
714 |
716 /** |
715 |
717 * @name LoadConfigurationFile |
|
718 * Opens up the dhcp.ini file and reads the content on to a heap buffer |
|
719 * @return - ETrue if the dhcp.ini is successfully parsed to the buffer, EFalse otherwise |
|
720 * |
|
721 * @internalTechnology |
|
722 */ |
|
723 TBool CDHCPStateMachine::LoadConfigurationFile() |
|
724 { |
|
725 TRAP_IGNORE(iConfig = CESockIniData::NewL(DHCP_INI_DATA)); |
|
726 return (iConfig != NULL); |
|
727 } |
|
728 |
|
729 /** |
|
730 * @name UnloadConfigurationFile |
|
731 * Frees up memory allocated for reading dhcp.ini file |
|
732 * |
|
733 * @internalTechnology |
|
734 */ |
|
735 void CDHCPStateMachine::UnloadConfigurationFile() |
|
736 { |
|
737 if (iConfig) |
|
738 { |
|
739 delete iConfig; |
|
740 iConfig = NULL; |
|
741 } |
|
742 } |
|
743 |
|
744 /** |
|
745 * @name IniRead |
|
746 * General ini file read utility. Makes use of CESockIniData object for parsing |
|
747 * |
|
748 * @param aOptionName Key name within ini file whose value need to be parsed |
|
749 * @param aOptionValue Buffer reference to store the parsed output |
|
750 * |
|
751 * @return TInt error values as approriate from the ini parsing framework |
|
752 * |
|
753 * @internalTechnology |
|
754 */ |
|
755 TInt CDHCPStateMachine::IniRead(const TDesC& aOptionName, TDes8& aOptionValue) |
|
756 { |
|
757 TPtrC iniValue; |
|
758 TBool iniParsed = iConfig->FindVar(KDhcpSection, aOptionName, iniValue); |
|
759 if (!iniParsed) |
|
760 return KErrNotFound; |
|
761 |
|
762 if(aOptionName.CompareF(KDhcpExtraOptions) == KErrNone) |
|
763 { |
|
764 TLex iniLex(iniValue); |
|
765 TChar ch; |
|
766 |
|
767 while((ch = iniLex.Get()) != 0) |
|
768 { |
|
769 while ((ch = iniLex.Peek()) != ',') |
|
770 iniLex.Inc(); |
|
771 TLex token(iniLex.MarkedToken()); |
|
772 |
|
773 TUint8 opCode(0); |
|
774 token.Val(opCode,EDecimal); |
|
775 |
|
776 if ( (opCode > 0) && (opCode < KOpCodeOutOfBounds) ) |
|
777 aOptionValue.Append(opCode); |
|
778 |
|
779 iniLex.Inc(); |
|
780 iniLex.Mark(); |
|
781 } |
|
782 return KErrNone; |
|
783 } |
|
784 else |
|
785 return KErrNotFound; |
|
786 } |
|
787 |
716 |
788 TDhcpRnd::TDhcpRnd():iXid(0) |
717 TDhcpRnd::TDhcpRnd():iXid(0) |
789 /** |
718 /** |
790 * Constructor for this little random number |
719 * Constructor for this little random number |
791 * class that creates us a random transaction id |
720 * class that creates us a random transaction id |