linklayerprotocols/pppnif/INC/PPPBASE.H
changeset 0 af10295192d8
equal deleted inserted replaced
-1:000000000000 0:af10295192d8
       
     1 // Copyright (c) 1997-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  @internalComponent 
       
    19 */
       
    20 
       
    21 #if !defined(__PPPBASE_H__)
       
    22 #define __PPPBASE_H__
       
    23 
       
    24 #include <nifvar.h>
       
    25 #include <nifmbuf.h>
       
    26 #include <nifutl.h>
       
    27 
       
    28 #include <networking/pppdef.h>
       
    29 #include <networking/pppsock.h>
       
    30 #include <networking/pppcomp.h>
       
    31 #include <nifvar_internal.h>
       
    32 
       
    33 #include <etelpckt.h>
       
    34 
       
    35 // This initialization file is used when PPP is configured as a client (IfServerMode=FALSE)
       
    36 _LIT(PPP_INI_FILE,"ppp.ini");
       
    37 
       
    38 // This initialization file is used when PPP is configured as a server (IfServerMode=TRUE)
       
    39 _LIT(PPP_SERVER_INI_FILE,"pppd.ini");
       
    40 
       
    41 enum TPppPanic
       
    42 	{
       
    43 	EPppPanic_PPPHDLCIsAlreadyActive,
       
    44 	EPppPanic_PPPDBReadCallback,
       
    45 	EPppPanic_PPPNoMemory,
       
    46 	EPppPanic_PPPNotSupported,
       
    47 	EPppPanic_PacketHeaderTooBig,
       
    48     EPppPanic_PPPInvalidCallback,
       
    49     EPppPanic_PPPNoCallbackInfo,
       
    50     EPppPanic_PPPLcpRequired,
       
    51     EPppPanic_PPPNoNifIfNotify,
       
    52     EPppPanic_IETFCalbackInvalid,
       
    53     EPppPanic_IETFNoCalback,
       
    54     EPppPanic_IncorrectNcpNotif,
       
    55     EPppPanic_InvalidData,
       
    56     EPppPanic_NullBcaFactory,
       
    57     EPppPanic_NullBca,
       
    58     EPppPanic_UnexpectedBcaOpen,
       
    59     EPppPanic_BcaStartupAlreadyActive,
       
    60     EPppPanic_IllegalBcaControlStep,
       
    61     EPppPanic_IllegalHdlcState,
       
    62     EPppPanic_UnexpectedSCPRMessage,
       
    63     EPppPanic_SpuriousError,
       
    64     EPppPanic_LCPFailedToStart
       
    65   	};
       
    66 
       
    67 //
       
    68 // Panic
       
    69 //
       
    70 
       
    71 static inline void PppPanic(TPppPanic aPanic)
       
    72 //
       
    73 // Panic the Protocol
       
    74 //
       
    75 	{
       
    76    _LIT(KPppDesc, "PPP");
       
    77 	User::Panic(KPppDesc,aPanic);
       
    78 	}
       
    79 
       
    80 
       
    81 //
       
    82 // PPP Internal LCP Constants
       
    83 //
       
    84 
       
    85 const TInt KPppDefaultFrameSize = 1500;
       
    86 
       
    87 enum TMSCBCPAction
       
    88 	{
       
    89 	EMSCBCPActionRequireClientSpecifiedNumber  = ECallbackActionMSCBCPRequireClientSpecifiedNumber,
       
    90 	EMSCBCPActionAcceptServerSpecifiedNumber   = ECallbackActionMSCBCPAcceptServerSpecifiedNumber,
       
    91 	EMSCBCPActionOverrideServerSpecifiedNumber = ECallbackActionMSCBCPOverrideServerSpecifiedNumber
       
    92 	};
       
    93 
       
    94 //
       
    95 
       
    96 class TPppFcs16;
       
    97 class TPppFcs32;
       
    98 class MPppRecvr;
       
    99 class MPppFsm;
       
   100 class CPppLcp;
       
   101 class CPppLinkBase;
       
   102 class CNifFactory;
       
   103 
       
   104 //
       
   105 // Other simple PPP Frame Receivers
       
   106 //
       
   107 
       
   108 /**
       
   109 Adds extra PPP Recv channels to a class T
       
   110 */
       
   111 template <class T>
       
   112 class TPppExtraRecvr : public MPppRecvr
       
   113 	{
       
   114 public:
       
   115 	TPppExtraRecvr<T>(T* aClass, void (T::*aRecvFn)(RMBufChain&), void (T::*aFlowFn)(), 
       
   116 		CPppLcp* aLcp, TPppPhase aPhase, TUint aId, void (T::*aFrameErrFn)(), void (T::*aKillFn)())
       
   117 		: MPppRecvr(aLcp, aPhase, aId), iClass(aClass), iRecvFn(aRecvFn), iFlowFn(aFlowFn), 
       
   118 			iFrameErrFn(aFrameErrFn), iKillFn(aKillFn){}
       
   119 		virtual void FrameError()
       
   120 		{ (iClass->*iFrameErrFn)(); }
       
   121 		virtual void KillProtocol()
       
   122 		{ (iClass->*iKillFn)(); }
       
   123 
       
   124 	virtual TBool RecvFrame(RMBufChain& aPacket)
       
   125 		{ (iClass->*iRecvFn)(aPacket); return ETrue; };
       
   126 	virtual void FlowOn()
       
   127 		{ (iClass->*iFlowFn)(); }
       
   128 private:
       
   129 	T* iClass;
       
   130 	void (T::*iRecvFn)(RMBufChain&);
       
   131 	void (T::*iFlowFn)();
       
   132 	void (T::*iFrameErrFn)();
       
   133 	void (T::*iKillFn)();
       
   134 	};
       
   135 
       
   136 //
       
   137 // PPP Options
       
   138 //
       
   139 
       
   140 class RPppOption : public RMBufChain
       
   141 	{
       
   142 public:
       
   143 	RPppOption();
       
   144 	RPppOption(RMBufChain& aChain);
       
   145 	inline const RPppOption& operator=(const RMBufChain& aChain);
       
   146 	void SetL(TUint8 aType, const TAny* aPtr, TInt aLen);
       
   147 	TUint8 OptType() const;
       
   148 	void SetType(const TUint8 aType);
       
   149 	TInt ValueLength() const;
       
   150 	void SetValueLength(TInt aLen);
       
   151 	TUint8* ValuePtr();
       
   152 	const TUint8* ValuePtr() const;
       
   153 	inline static RPppOption& Cast(RMBufChain& aChain);
       
   154 	inline static const RPppOption& Cast(const RMBufChain& aChain);
       
   155 private:
       
   156 	// These probably belong in the MBuf manager
       
   157 	TInt MaxLength() const;
       
   158 	TInt SetLength(TInt aLen);
       
   159 	};
       
   160 
       
   161 enum TPppOptResponse
       
   162 	{
       
   163 	EPppOptAck,
       
   164 	EPppOptNak,
       
   165 	EPppOptReject
       
   166 	};
       
   167 
       
   168 class MPppOptionsExtender;
       
   169 NONSHARABLE_CLASS(MPppOptionHandler)
       
   170 	{
       
   171 	friend class MPppOptionsExtender;
       
   172 protected:
       
   173 	MPppOptionHandler();
       
   174 	void OptRegister(MPppOptionsExtender* aExtender, const TUint8* aOptList, TInt aNumOpts);
       
   175 	virtual void OptNegotiationStarted();
       
   176 	virtual void OptNegotiationAborted();
       
   177 	virtual void OptNegotiationComplete();
       
   178 	virtual void OptFillinConfigRequestL(RPppOptionList& aRequestList);
       
   179 	virtual TPppOptResponse OptCheckConfigRequest(RPppOption& aOption);
       
   180 	virtual void OptApplyConfigRequest(RPppOption& aOption);
       
   181 	virtual void OptRecvConfigAck(RPppOption& aOption);
       
   182 	virtual void OptRecvConfigNak(RPppOption& aOption, RPppOptionList& aReqList);
       
   183 	virtual void OptRecvConfigReject(RPppOption& aOption, RPppOptionList& aReqList);
       
   184 protected:
       
   185 	TInt iNumOptions;
       
   186 	const TUint8* iOptionList;
       
   187 private:
       
   188 	TDblQueLink iOptHandlerLink;
       
   189 	};
       
   190 
       
   191 //
       
   192 // PPP Finite State Machine
       
   193 //
       
   194 
       
   195 const TInt KPppFsmTerminateRequestTimeout = 3000; // RFC 1661 4.6
       
   196 const TInt KPppFsmTerminateTimeout = KPppFsmTerminateRequestTimeout; // For back compatibility
       
   197 const TInt KPppFsmLengthenedTerminateTimeout = 30000;		// 30 secs
       
   198 const TInt KPppFsmTerminateRequestRetries = 2; // RFC 1661 4.6
       
   199 const TInt KPppFsmTerminateAckTimeout = 500 + KPppFsmTerminateRequestTimeout; // RFC 1661 3.7
       
   200 const TInt KPppFsmRequestTimeout = 3000;
       
   201 const TInt KPppFsmRequestMaxTimeout = 60000;
       
   202 const TInt KPppFsmLengthenedRequestTimeout = 40000;			// 40 secs
       
   203 const TInt KPppFsmRequestRetries = 10;
       
   204 const TInt KPppFsmTimerPriority = 10;
       
   205 
       
   206 #define __DECLARE_FSM_NAME(t) __iFsmName=t
       
   207 
       
   208 const TInt KPppFsmNonConvergeLimit = 4;
       
   209 const TUint KPppRequestIdAnswered = 0x80000000;
       
   210 
       
   211 //
       
   212 // PPP Link Protocols
       
   213 //
       
   214 
       
   215 /**
       
   216 Calculates the CCITT CRC-16 used by PPP in HDLC framing.
       
   217 @internalTechnology
       
   218 */
       
   219 class TPppFcs16
       
   220 	{
       
   221 public:
       
   222 	inline TPppFcs16();
       
   223 	inline void Init();
       
   224 	void Calc(const TUint8* aPtr, const TUint8* aEnd);
       
   225 	inline void CalcByte(TUint8 aByte);
       
   226 	inline TUint16 Fcs() const;
       
   227 	inline TBool IsGood() const;
       
   228 	
       
   229 private:
       
   230 	// WINS can't handle static const members initialized here, so use an enum
       
   231 	enum
       
   232 		{
       
   233 		/** Initial FCS value */
       
   234 		KPppInitFcs16 = 0xffff,
       
   235 		/** Good final FCS value */
       
   236 		KPppGoodFcs16 = 0xf0b8
       
   237 		};
       
   238 	/** CRC value */
       
   239 	TUint16 iFcs;		
       
   240 	/** Fast CRC calculation table */
       
   241 	static const TUint16 FcsTable[256];
       
   242 	};
       
   243 
       
   244 /**
       
   245 Calculates the CCITT CRC-32 used as an option by PPP in HDLC framing.
       
   246 @internalTechnology
       
   247 */
       
   248 class TPppFcs32
       
   249 	{
       
   250 public:
       
   251 	inline TPppFcs32();
       
   252 	inline void Init();
       
   253 	void Calc(const TUint8* aPtr, const TUint8* aEnd);
       
   254 	inline void CalcByte(TUint8 aByte);
       
   255 	inline TUint32 Fcs() const;
       
   256 	inline TBool IsGood() const;
       
   257 	
       
   258 private:
       
   259 	// WINS can't handle static const members initialized here, so use an enum
       
   260 	enum
       
   261 		{
       
   262 		/** Initial FCS value */
       
   263 		KPppInitFcs32 = 0xffffffff,
       
   264 		/** Good final FCS value */
       
   265 		KPppGoodFcs32 = 0xdebb20e3
       
   266 		};
       
   267 	/** CRC value */
       
   268 	TUint32 iFcs;		
       
   269 	/** Fast CRC calculation table */
       
   270 	static const TUint32 FcsTable[256];
       
   271 	};
       
   272 
       
   273 /*
       
   274 // Support for PPP components as external DLLs
       
   275 class CPppExtDllRef : public CAsyncOneShot
       
   276 	{
       
   277 public:
       
   278 	CPppDllRef();
       
   279 	~CPppDllRef();
       
   280 	void UnloadMe();
       
   281 protected:
       
   282 	virtual void RunL();
       
   283 private:
       
   284 	RLibrary iDll;
       
   285 	TDblQueLink iLink;
       
   286 	};
       
   287 
       
   288 class MPppExtDll
       
   289 	{
       
   290 public:
       
   291 	IMPORT_C virtual ~MPppExtDll();
       
   292 	virtual void DllInstallL()=0;
       
   293 	virtual void DllRemove()=0;
       
   294 private:
       
   295 	friend class CPppExtDllRef;
       
   296 	CPppExtDllRef* iPppDllRef;
       
   297 	};
       
   298 */
       
   299 
       
   300 //
       
   301 // Other simple PPP Frame Receivers
       
   302 //
       
   303 
       
   304 /**
       
   305 Base class for link protocols
       
   306 @internalTechnology
       
   307 */
       
   308 NONSHARABLE_CLASS(CPppLinkBase) : public CBase
       
   309 	{
       
   310 public:
       
   311 	virtual ~CPppLinkBase();
       
   312 	// Implemented by link protocols
       
   313 	virtual void CreateL()=0;
       
   314 	virtual TInt Send(RMBufChain& aPacket, TUint aPppId=KPppIdAsIs)=0;
       
   315 	virtual void OpenL()=0; // Open/Close from LCP
       
   316 	virtual void Close()=0;
       
   317 	virtual void StartL()=0;
       
   318 	virtual void Stop(TInt aReason, TBool aLinkDown=ETrue)=0;
       
   319 	virtual void GetSendRecvSize(TInt& aMaxRecvSize, TInt& aMaxSendSize)=0;
       
   320 	virtual void GetDataTransfer(RPacketContext::TDataVolume&)=0;
       
   321 	virtual TInt SpeedMetric()=0;
       
   322 	inline void NewCompressor(const CPppCompressor* aCompressor);
       
   323 	inline void NewDeCompressor(const CPppDeCompressor* aDeCompressor);
       
   324 	CPppLinkBase* PppCreateLinkL(CPppLcp* aLcp, const TDesC& aNifName);
       
   325 protected:
       
   326 	CPppLinkBase(CPppLcp* aLcp);
       
   327 	// Used by link protocols
       
   328 	inline void NotifyLinkUp();
       
   329 	inline void NotifyLinkDown(TInt aReason);
       
   330 	inline void DeliverToLcp(RMBufChain& aPacket);
       
   331 protected:
       
   332 	CPppLcp* iPppLcp;
       
   333 	CPppCompressor* iPppCompressor;
       
   334 	CPppDeCompressor* iPppDecompressor;
       
   335 	};
       
   336 
       
   337 #include <networking/pppbase.inl>
       
   338 
       
   339 #endif