commsfwutils/commsbufs/reference/loopback_bearer/inc/binder.h
changeset 0 dfb7c4ff071f
equal deleted inserted replaced
-1:000000000000 0:dfb7c4ff071f
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 #ifndef __LEGACY_LOOPBACK_BINDER_H__
       
    18 #define __LEGACY_LOOPBACK_BINDER_H__
       
    19 
       
    20 #include <ip4_hdr.h>
       
    21 #include <ip6_hdr.h>
       
    22 #include <udp_hdr.h>
       
    23 
       
    24 #include <comms-infras/ss_flowbinders.h>
       
    25 #include <comms-infras/commsdebugutility.h>
       
    26 
       
    27 #include "flow.h"
       
    28 
       
    29 #ifdef SYMBIAN_OLD_EXPORT_LOCATION
       
    30 #include <comms-infras/legacy_loopback_driver.h>
       
    31 #include <ss_protflow.h>
       
    32 #include "es_protbinder.h"
       
    33 #else
       
    34 //this header is not exported, needs to be a user include
       
    35 #include "legacy_loopback_driver.h"
       
    36 #include <comms-infras/ss_protflow.h>
       
    37 #include <comms-infras/es_protbinder.h>
       
    38 #endif
       
    39 
       
    40 #include <nifmbuf.h>
       
    41 
       
    42 
       
    43 class CLegacyLoopbackErrorOneShot : public CAsyncOneShot
       
    44 /**
       
    45 Class used to asynchronously signal a binder error
       
    46 */
       
    47 	{
       
    48 	friend class CDummyNifBinder4;		// for iUpperControl
       
    49 public:
       
    50 	CLegacyLoopbackErrorOneShot();
       
    51 	void RunL();
       
    52 	void Schedule(ESock::MUpperControl* iUpperControl);
       
    53 
       
    54 private:
       
    55 	ESock::MUpperControl* iUpperControl;
       
    56 	};
       
    57 
       
    58 class CLegacyLoopbackSubConnectionFlow;
       
    59 class CLegacyLoopbackFlowTestingSubscriber;
       
    60 
       
    61 class CLegacyLoopbackBinder4 : public CBase, public ESock::MLowerDataSender, public ESock::MLowerControl
       
    62 /**
       
    63 IP4 binder
       
    64 */
       
    65 	{
       
    66 public:
       
    67 	enum { KLoopbackBearerMTU = 1532 };
       
    68 
       
    69 	static CLegacyLoopbackBinder4* NewL(CLegacyLoopbackSubConnectionFlow& aLegacyLoopbackSubConnectionFlow);
       
    70 	virtual ~CLegacyLoopbackBinder4();
       
    71 	
       
    72 	MLowerDataSender* Bind(ESock::MUpperDataReceiver& aUpperReceiver , ESock::MUpperControl& aUpperControl);
       
    73 	void Unbind (ESock::MUpperDataReceiver& aUpperReceiver, ESock::MUpperControl& aUpperControl);
       
    74 
       
    75 	void BinderReady();
       
    76 	void ProcessPacket(RMBufChain& aData);
       
    77 
       
    78 	// from MLowerDataSender
       
    79 	virtual ESock::MLowerDataSender::TSendResult Send(RMBufChain& aData);
       
    80 	
       
    81 	// from MLowerControl
       
    82 	virtual TInt GetName(TDes& aName);
       
    83 	virtual TInt BlockFlow(ESock::MLowerControl::TBlockOption aOption);
       
    84 	virtual TInt GetConfig(TBinderConfig& aConfig);
       
    85 	virtual TInt Control(TUint aLevel, TUint aName, TDes8& aOption);
       
    86 
       
    87 	// Utility functions
       
    88 	TBool MatchesUpperControl(ESock::MUpperControl* aUpperControl) const;
       
    89 
       
    90 protected:
       
    91 	CLegacyLoopbackBinder4(CLegacyLoopbackSubConnectionFlow& aLegacyLoopbackSubConnectionFlow);
       
    92 
       
    93 private:
       
    94     void UpdateHeaders(TInet6HeaderIP4* aIp4, TInet6HeaderUDP* aUdp);
       
    95 	inline CLegacyLoopbackSubConnectionFlow* Flow();
       
    96 	void LogPacketDetails(TInet6HeaderIP4* aIp4, const TDesC8& aCaption);
       
    97 
       
    98 private:
       
    99    	TUint32 iLocalAddressBase;
       
   100    	TUint32 iLocalAddress;
       
   101     CLegacyLoopbackSubConnectionFlow& iLegacyLoopbackSubConnectionFlow;
       
   102 	ESock::MUpperDataReceiver* iUpperReceiver;
       
   103 	ESock::MUpperControl* iUpperControl;
       
   104 	CLegacyLoopbackErrorOneShot iErrorOneShot;
       
   105 
       
   106 	// Loopback driver
       
   107 	TBool iLoopbackLoadAttempted;	// we only try once
       
   108 	RLegacyLoopbackDriver iDrv;
       
   109 	RMBufAllocator iAllocator;
       
   110 
       
   111 	class CDrvSender : public CActive
       
   112 		{
       
   113 	public:
       
   114 		CDrvSender(TInt aPriority);
       
   115 		~CDrvSender();
       
   116 		void Start(CLegacyLoopbackBinder4* aBinder, RLegacyLoopbackDriver aDrv); 
       
   117 		void QueueForSend(RMBufPacket& aPkt);
       
   118 	private:
       
   119 		void RunL();
       
   120 		void DoCancel();
       
   121 		void SendPacket();
       
   122 
       
   123 		CLegacyLoopbackBinder4* iBinder;
       
   124 		RMBufPktQ iSendQueue;
       
   125 		RLegacyLoopbackDriver iDrv;
       
   126 		RMBufPacket iSendPkt;
       
   127 
       
   128 		TInt iManyBufCount;
       
   129 		TInt iOneBufCount;
       
   130 
       
   131 		__FLOG_DECLARATION_MEMBER;
       
   132 		};
       
   133 	CDrvSender* iDrvSender;
       
   134 	
       
   135 	class CDrvReceiver : public CActive
       
   136 		{
       
   137 	public:
       
   138 		CDrvReceiver(TInt aPriority);
       
   139 		~CDrvReceiver();
       
   140 		void Start(CLegacyLoopbackBinder4* aBinder, RLegacyLoopbackDriver aDrv); 
       
   141 	private:
       
   142 		void RunL();
       
   143 		void DoCancel();
       
   144 		
       
   145 		void RequestReceipt();
       
   146 		
       
   147 		CLegacyLoopbackBinder4* iBinder;
       
   148 		RLegacyLoopbackDriver iDrv;
       
   149 		TBuf8<RLegacyLoopbackDriver::KLoopbackMTU> iDesBuf;
       
   150 		RMBufPacket iPkt;
       
   151 		RCommsBufPond iPond;
       
   152 		TPtr8 iRxPtr;
       
   153 		};
       
   154 	CDrvReceiver* iDrvReceiver;
       
   155 
       
   156 public:
       
   157 	CLegacyLoopbackFlowTestingSubscriber* iTestSubscriber;
       
   158 
       
   159 protected:
       
   160     __FLOG_DECLARATION_MEMBER;
       
   161 	};
       
   162 
       
   163 class CLegacyLoopbackBinder6 : public CBase, public ESock::MLowerDataSender, public ESock::MLowerControl
       
   164 /**
       
   165 IP6 binder
       
   166 */
       
   167 	{
       
   168 public:
       
   169 	enum { KLoopbackBearerMTU = 1532 };
       
   170 
       
   171 	static CLegacyLoopbackBinder6* NewL(CLegacyLoopbackSubConnectionFlow& aLegacyLoopbackSubConnectionFlow);
       
   172 	virtual ~CLegacyLoopbackBinder6();
       
   173 	
       
   174 	MLowerDataSender* Bind(ESock::MUpperDataReceiver& aUpperReceiver , ESock::MUpperControl& aUpperControl);
       
   175 	void Unbind (ESock::MUpperDataReceiver& aUpperReceiver, ESock::MUpperControl& aUpperControl);
       
   176 
       
   177 	void BinderReady();
       
   178 	void ProcessPacket(RMBufChain& aData);
       
   179 
       
   180 	// from MLowerDataSender
       
   181 	virtual ESock::MLowerDataSender::TSendResult Send(RMBufChain& aData);
       
   182 	
       
   183 	// from MLowerControl
       
   184 	virtual TInt GetName(TDes& aName);
       
   185 	virtual TInt BlockFlow(MLowerControl::TBlockOption /*aOption*/);
       
   186 	virtual TInt GetConfig(TBinderConfig& aConfig);
       
   187 	virtual TInt Control(TUint aLevel, TUint aName, TDes8& aOption);
       
   188 
       
   189 	// Utility functions
       
   190 	TBool MatchesUpperControl(ESock::MUpperControl* aUpperControl) const;
       
   191 
       
   192 protected:
       
   193 	CLegacyLoopbackBinder6(CLegacyLoopbackSubConnectionFlow& aLegacyLoopbackSubConnectionFlow);
       
   194 
       
   195 private:
       
   196     void UpdateHeaders(TInet6HeaderIP* aIp6, TInet6HeaderUDP* /*aUdp*/);
       
   197 	void StaticDnsConfiguration(TBinderConfig6& aConfig);
       
   198 	inline CLegacyLoopbackSubConnectionFlow* Flow();
       
   199 
       
   200 private:
       
   201     CLegacyLoopbackSubConnectionFlow& iLegacyLoopbackSubConnectionFlow;
       
   202 	ESock::MUpperDataReceiver* iUpperReceiver;
       
   203 	ESock::MUpperControl* iUpperControl;
       
   204 
       
   205 protected:
       
   206     __FLOG_DECLARATION_MEMBER;
       
   207 
       
   208 	};
       
   209 
       
   210 //
       
   211 // Inlines
       
   212 //
       
   213 
       
   214 CLegacyLoopbackSubConnectionFlow* CLegacyLoopbackBinder4::Flow()
       
   215 	{
       
   216 	return &iLegacyLoopbackSubConnectionFlow;
       
   217 	}
       
   218 
       
   219 CLegacyLoopbackSubConnectionFlow* CLegacyLoopbackBinder6::Flow()
       
   220 	{
       
   221 	return &iLegacyLoopbackSubConnectionFlow;
       
   222 	}
       
   223 
       
   224 // various things that will get set up on each interface by dummy nifs
       
   225 // will be added to the address base to make the broadcast address...
       
   226 const TUint KBroadcastAddressSuffix = 255;
       
   227 // some arbitrary num to add to the base to give the default gateway machine...
       
   228 const TUint KDefaultGatewayAddressSuffix = 10;
       
   229 // some arbitrary num to add to the base to give the secondary dns server...
       
   230 const TUint KSecondaryDnsAddressSuffix = 11;
       
   231 // obviously all the above addresses are totally arbitrary to a certain extent... :-)
       
   232 
       
   233 
       
   234 const TUid KLegacyLoopbackTestingPubSubUid = {0x102871C7};
       
   235 
       
   236 NONSHARABLE_CLASS(CLegacyLoopbackFlowTestingSubscriber) : public CActive
       
   237 	{
       
   238 public:
       
   239 	TBool IsEnabled()
       
   240 		{
       
   241 		return iIsEnabled;
       
   242 		}
       
   243 
       
   244 	static TBool ShouldRun(TUint aApId);
       
   245 
       
   246 	static CLegacyLoopbackFlowTestingSubscriber* NewL(CLegacyLoopbackSubConnectionFlow& aFlow, TUint aApId)
       
   247 		{
       
   248 		CLegacyLoopbackFlowTestingSubscriber* ats = new(ELeave)CLegacyLoopbackFlowTestingSubscriber(aFlow, aApId);
       
   249 		CleanupStack::PushL(ats);
       
   250 		ats->ConstructL();
       
   251 		CleanupStack::Pop(ats);
       
   252 		return ats;
       
   253 		}
       
   254 
       
   255 	virtual ~CLegacyLoopbackFlowTestingSubscriber();
       
   256 
       
   257 public:
       
   258 	CLegacyLoopbackFlowTestingSubscriber(CLegacyLoopbackSubConnectionFlow& aFlow, TUint aApId);
       
   259 	void ConstructL();
       
   260 	
       
   261 	void RunL();
       
   262 	void DoCancel();
       
   263 
       
   264 private:
       
   265 	CLegacyLoopbackSubConnectionFlow& iFlow;
       
   266 	TInt iApId;
       
   267 	RProperty iProperty;
       
   268 	TBool iIsEnabled : 1;
       
   269 	};
       
   270 
       
   271 #endif // __LEGACY_LOOPBACK_BINDER_H__