networkprotocols/tcpipv4v6prt/inc/in_trans.h
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 // in_trans.h - transport layer protocol base
       
    15 //
       
    16 
       
    17 
       
    18 
       
    19 /**
       
    20  @internalComponent
       
    21 */
       
    22 #ifndef __IN_TRANS_H__
       
    23 #define __IN_TRANS_H__
       
    24 
       
    25 #include "inet.h"
       
    26 #include "inet6log.h"
       
    27 
       
    28 
       
    29 #define SYMBIAN_NETWORKING_UPS
       
    30 
       
    31 enum TProviderMatchEnum
       
    32 	{
       
    33 	EMatchNone,
       
    34 	EMatchLocalPort,
       
    35 	EMatchServerUnspecAddr,
       
    36 	EMatchServerSpecAddr,
       
    37 	EMatchExact,
       
    38 	EMatchConnection = EMatchExact
       
    39 	};
       
    40 
       
    41 
       
    42 class CProviderInet6Transport;
       
    43 class CProtocolInet6Transport : public CProtocolInet6Base
       
    44 	{
       
    45 public:
       
    46 	CProtocolInet6Transport();
       
    47 	~CProtocolInet6Transport();
       
    48 
       
    49 	CProtocolInet6Transport& operator=(const CProtocolInet6Transport&); // Sugar
       
    50 	virtual void InitL(TDesC& aTag);
       
    51 	virtual void BindL(CProtocolBase *protocol, TUint id);
       
    52 	virtual void StartL();
       
    53 	virtual TInt Send(RMBufChain &aPacket,CProtocolBase* aSourceProtocol=NULL);
       
    54 #ifndef SYMBIAN_STRICT_EXPLICIT_SOCKET_BINDING
       
    55 	virtual CProviderInet6Transport* LocateSap(TProviderMatchEnum aRank, TUint aFamily,
       
    56 		const TInetAddr& aLocalAddr,
       
    57 		const TInetAddr& aRemoteAddr = TInetAddr(),
       
    58 		CProviderInet6Base *aSap = NULL);
       
    59 #else 
       
    60 virtual CProviderInet6Transport* LocateSap(TProviderMatchEnum aRank, TUint aFamily,
       
    61 		const TInetAddr& aLocalAddr,
       
    62 		const TInetAddr& aRemoteAddr = TInetAddr(),
       
    63 		CProviderInet6Base *aSap = NULL,TUint32 aSourceIfIndex = 0);
       
    64 #endif //SYMBIAN_STRICT_EXPLICIT_SOCKET_BINDING
       
    65 	virtual TUint AssignAutoPort();
       
    66 
       
    67 	inline TUint Random(TUint aMax) { return (TUint)Math::Rand(iSeed) % aMax; }	
       
    68 
       
    69 #ifdef _LOG
       
    70 	virtual void LogProviders(TUint aPort);
       
    71 #endif
       
    72 
       
    73 	TInt GetIniValue(const TDesC &aSection, const TDesC &aName,
       
    74 						TInt aDefault, TInt aMin, TInt aMax, TBool aBoundMode = EFalse) const;
       
    75 
       
    76 private:
       
    77 	TInt64 iSeed;
       
    78 	};
       
    79 
       
    80 #ifdef SYMBIAN_NETWORKING_UPS
       
    81 class MProviderBindings : public MInetBase
       
    82 	{
       
    83 	public:
       
    84 	virtual TBool HasSocket() = 0;
       
    85 	};
       
    86 
       
    87 const TUint KApiVer_MProviderBindings = 0;
       
    88 
       
    89 class CProviderInet6Transport : public CProviderInet6Base, public MProviderBindings
       
    90 #else
       
    91 class CProviderInet6Transport : public CProviderInet6Base
       
    92 #endif
       
    93 	{
       
    94 	friend class CProtocolInet6Transport;
       
    95 
       
    96 public:
       
    97 	CProviderInet6Transport(CProtocolInet6Base *aProtocol);
       
    98 	virtual ~CProviderInet6Transport();
       
    99 
       
   100 	virtual void LocalName(TSockAddr &anAddr) const;
       
   101 	virtual TInt SetLocalName(TSockAddr &anAddr);
       
   102 	virtual void RemName(TSockAddr &anAddr) const;
       
   103 	virtual TInt SetRemName(TSockAddr &anAddr);
       
   104 	virtual void AutoBind();
       
   105 	virtual TInt SetOption(TUint aLevel, TUint aName, const TDesC8& aOption);
       
   106 	virtual TInt GetOption(TUint aLevel, TUint aName, TDes8& aOption) const;
       
   107 
       
   108 	virtual void CanSend();
       
   109 	virtual void Error(TInt aError, TUint aOperationMask = MSocketNotify::EErrorAllOperations);
       
   110 	CProtocolInet6Transport* Protocol() const { return (CProtocolInet6Transport*)iProtocol; }
       
   111 	virtual void IcmpError(TInt aError, TUint aOperationMask, TInt aType, TInt aCode,
       
   112 		const TInetAddr& aSrcAddr, const TInetAddr& aDstAddr, const TInetAddr& aErrAddr);
       
   113 
       
   114 #ifdef SYMBIAN_NETWORKING_UPS
       
   115 	TBool HasSocket();	
       
   116 	void *GetApiL(const TDesC8& aApiName, TUint* aVersion);
       
   117 protected:
       
   118 	TBool ConnectionInfoSet();
       
   119 #endif	
       
   120 protected:
       
   121 
       
   122 	struct TSockFlags
       
   123 		{
       
   124 		TUint16 iRecvClose:1;
       
   125 		TUint16 iSendClose:1;
       
   126 		TUint16 iConnected:1;
       
   127 		TUint16 iFlowStopped:1;
       
   128 		TUint16 iReuse:1;
       
   129 		TUint16 iAttached:1;        // If true, ESock has a pointer to this socket
       
   130 		TUint16 iNotify:1;          // If true, we can notify ESock of events
       
   131 //		TUint16 iRawMode:1;         // If true, user received UDP packets with IP header
       
   132 //		TUint16 iHeaderIncluded:1;  // If true, user sends UDP packets with IP header
       
   133 		TUint16 iReportIcmp:1;      // If true, report ICMP errors to application
       
   134 //		TUint16 iSynchSend:1;       // If true, block socket write to UDP socket in PENDING and HOLD states
       
   135 		TUint16 iAddressSet:1;	  // If true, application has bound the socket to a specific IP address
       
   136 		} iSockFlags;
       
   137 	TUint iAppFamily;
       
   138 	TUint iSockFamily;
       
   139 // UPS support
       
   140 #ifdef SYMBIAN_NETWORKING_UPS
       
   141 	TUint		iConnectionInfoReceived:1;
       
   142 #endif
       
   143 	};
       
   144 
       
   145 class RMBufSockQ : public RMBufChain
       
   146 	{
       
   147 public:
       
   148 	void AppendL(const TDesC8& aData, TInt aLength);
       
   149 	TInt AppendDes(const TDesC8& aData, TInt aLength);
       
   150 	TInt AppendAtLeast(RMBufChain& aChain, TInt aLength);
       
   151 	TInt RemoveAtMost(RMBufChain& aChain, TInt aLength);
       
   152 	static inline RMBufSockQ& Cast(RMBufChain& aChain) { return (RMBufSockQ&)aChain; }
       
   153 	};
       
   154 
       
   155 class TDualBufPtr
       
   156 	{
       
   157 private:
       
   158 	enum BufferTypeEnum { ENone, ERMBufChain, EDes8, EDesC8 };
       
   159 
       
   160 public:
       
   161 	TDualBufPtr();
       
   162 	TDualBufPtr(RMBufChain& aChain) : iType(ERMBufChain), iChain(&aChain) { }
       
   163 	TDualBufPtr(TDes8& aDesc) : iType(EDes8), iDesc(&aDesc) { }
       
   164 	TDualBufPtr(const TDesC8& aDesc) : iType(EDesC8), iDescC(&aDesc) { }
       
   165 
       
   166 	void CopyInL(const RMBufChain& aQueue, TInt aOffset, TInt aLength);
       
   167 	TInt CopyIn(const RMBufChain& aQueue, TInt aOffset, TInt aLength);
       
   168 	void CopyOut(RMBufChain& aChain, TInt aOffset) const;
       
   169 	TInt Consume(RMBufChain& aQueue, TInt aLength, RMBufAllocator& aAllocator);
       
   170 	TInt AppendL(RMBufChain& aQueue, TInt aLength);
       
   171 	TInt Append(RMBufChain& aQueue, TInt aLength);	//ASSERTS if used with Des type
       
   172 	void Free();
       
   173 
       
   174 	inline TInt Length() const { return (iType == ERMBufChain) ? (iChain->IsEmpty() ? 0 : iChain->Length()) : iDesc->Length(); }
       
   175 
       
   176 private:
       
   177 	union
       
   178 		{
       
   179 		RMBufChain *iChain;
       
   180 		TDes8 *iDesc;
       
   181 		const TDesC8 *iDescC;
       
   182 		};
       
   183 	BufferTypeEnum iType;
       
   184 	};
       
   185 
       
   186 #endif