datacommsserver/esockserver/inc/ss_sapshim.h
changeset 0 dfb7c4ff071f
child 2 dee179edb159
equal deleted inserted replaced
-1:000000000000 0:dfb7c4ff071f
       
     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  @internalTechnology
       
    19  @released
       
    20 */
       
    21 
       
    22 #if !defined(__SS_SAPSHIM_H__)
       
    23 #define __SS_SAPSHIM_H__
       
    24 
       
    25 #define SYMBIAN_NETWORKING_UPS
       
    26 
       
    27 #include <comms-infras/es_sap.h>
       
    28 #include <comms-infras/ss_connlegacy.h>
       
    29 #include "ss_sapfactshim.h"
       
    30 #include <comms-infras/nifif.h>
       
    31 #include <comms-infras/ss_nodemessages_dataclient.h>
       
    32 #include <comms-infras/ss_nodemessages_flow.h>
       
    33 
       
    34 #ifdef SYMBIAN_NETWORKING_UPS
       
    35 #include <comms-infras/upsmessages.h>
       
    36 #endif
       
    37 
       
    38 #ifdef SYMBIAN_ADAPTIVE_TCP_RECEIVE_WINDOW
       
    39 #include <comms-infras/ss_protopt.h>
       
    40 #endif //SYMBIAN_ADAPTIVE_TCP_RECEIVE_WINDOW
       
    41 
       
    42 using NetInterfaces::TIfStaticFetcher;
       
    43 using NetInterfaces::TIfStaticFetcherFirstInHierarchy;
       
    44 
       
    45 namespace ESock
       
    46 {
       
    47 
       
    48 class CTransportFlowShim : public CNetworkFlow,
       
    49                          protected MSocketNotify,
       
    50                          protected MLowerDataSender,
       
    51                          protected MLowerControl
       
    52 /** Service Access Point Shim to convert CServProviderBase objects to
       
    53 CControlledServProvider objects.
       
    54 
       
    55 Provides transport services to a single protocol. Several of the calls to
       
    56 CServProviderBase have pre-conditions attached to them - for example
       
    57 a connection oriented protocol must have its local address set (either by
       
    58 a SetLocalName() or AutoBind()) before it is opened. If the socket server
       
    59 calls the CServProviderBase in such an erroneous way, the protocol should panic.
       
    60 
       
    61 @internalTechnology
       
    62 @released Since 9.0 */
       
    63 	{
       
    64     friend class ASocket;
       
    65 #ifdef SYMBIAN_NETWORKING_UPS
       
    66 	friend class CHostResolver;		// to allow CHostResolver to call SecurityCheck()
       
    67 #endif
       
    68 public:
       
    69     typedef CTransportFlowShimFactory FactoryType; //for factoryobject_cast to work
       
    70 
       
    71 	static CTransportFlowShim* NewL(CSubConnectionFlowFactoryBase& aFactory, const Messages::TNodeId& aSubConn, CProtocolIntfBase* aProtocolIntf);
       
    72 	void SetSSP(CServProviderBase& aSSP);
       
    73 
       
    74 	inline CServProviderBase* Provider();
       
    75 
       
    76 protected:
       
    77 	virtual ~CTransportFlowShim();
       
    78 	void SetSockType(TUint aSockType);
       
    79 	TInt LockToConnectionInfo();
       
    80 	
       
    81 	// MSessionControl
       
    82 	virtual void Start();
       
    83 	virtual void LocalName(TSockAddr& anAddr) const;
       
    84 	virtual void SetLocalName(TSockAddr& anAddr);
       
    85 	virtual void RemName(TSockAddr& anAddr) const;
       
    86 	virtual TInt SetRemName(TSockAddr& anAddr);
       
    87 	virtual TInt GetOption(TUint aLevel,TUint aName,TDes8& anOption) const;
       
    88 	virtual void Ioctl(TUint aLevel,TUint aName,TDes8* anOption);
       
    89 	virtual void CancelIoctl(TUint aLevel,TUint aName);
       
    90 	virtual TInt SetOption(TUint aLevel, TUint aName,const TDesC8 &anOption);
       
    91 	virtual void ActiveOpen();
       
    92 	virtual void ActiveOpen(const TDesC8& aConnectionData);
       
    93 	virtual TInt PassiveOpen(TUint aQueueSize);
       
    94 	virtual TInt PassiveOpen(TUint aQueueSize,const TDesC8& aConnectionData);
       
    95 	virtual void Shutdown(MSessionControl::TCloseType aOption);
       
    96 	virtual void Shutdown(MSessionControl::TCloseType aOption, const TDesC8& aDisconnectionData);
       
    97 	virtual void AutoBind();
       
    98 	virtual TUint Write(const TDesC8& aDesc,TUint aOptions, TSockAddr* anAddr);
       
    99 	virtual TInt Write(RMBufChain& aData, TUint aOptions, TSockAddr* anAddr);
       
   100 	virtual void GetData(TDes8& aDesc, TUint aOptions, TSockAddr* anAddr);
       
   101 	virtual TInt GetData(RMBufChain& aData, TUint aLength, TUint aOptions, TSockAddr* anAddr);
       
   102 	virtual TInt SecurityCheck(MProvdSecurityChecker* aSecurityChecker);
       
   103 
       
   104     //MFlowBinderControl
       
   105     //session binders for CSocket
       
   106     virtual MSessionControl* GetControlL(TInt aSessionType,MSessionControlNotify& aSessionControlNotify);
       
   107     virtual MSessionData* BindL(MSessionDataNotify& aNotify);
       
   108     virtual void Unbind();
       
   109     virtual CSubConnectionFlowBase& CloneFlowL();
       
   110 
       
   111 	//CHostResolver specific workaround for now
       
   112     //protocol binders for CHostResolver => subject to change the moment we can stack app level protocols
       
   113     //resolvers are really app level protocols
       
   114 	virtual MLowerControl* GetControlL(const TDesC8& aProtocol);
       
   115 	virtual MLowerDataSender* BindL(const TDesC8& aProtocol, MUpperDataReceiver* aReceiver, MUpperControl* aControl);
       
   116 	virtual void Unbind( MUpperDataReceiver* aReceiver, MUpperControl* aControl);
       
   117 	//MLowerDataSender for CHostResolver only => it kicks-off sub-connection by a dummy send and waits
       
   118 	//for MUpperControl::StartSending()/Error() after which it can read connection info/fail
       
   119 	virtual MLowerDataSender::TSendResult Send(RMBufChain& aData);
       
   120     //MLowerControl
       
   121 	virtual TInt Control(TUint aLevel, TUint aName, TDes8& aOption);
       
   122     //Messages::ANode
       
   123 	virtual void ReceivedL(const Messages::TRuntimeCtxId& aSender, const Messages::TNodeId& aRecipient, Messages::TSignatureBase& aMessage);
       
   124 	virtual const Messages::TNodeId& NodeId() const;
       
   125 	//Messages From sub-connection
       
   126 #ifdef SYMBIAN_NETWORKING_UPS
       
   127     	virtual void SubConnectionError(const Messages::TEBase::TError& errorMsg, TUint anOperationMask = (MSessionControlNotify::EErrorSend |
       
   128 			MSessionControlNotify::EErrorConnect | MSessionControlNotify::EErrorCompleteSetLocalName));
       
   129 
       
   130 #else
       
   131 	    void SubConnectionError(
       
   132 		const Messages::TEBase::TError& errorMsg,
       
   133 		TUint anOperationMask = (MSessionControlNotify::EErrorSend |
       
   134 				MSessionControlNotify::EErrorConnect | MSessionControlNotify::EErrorCompleteSetLocalName)
       
   135 		);
       
   136 
       
   137 #endif
       
   138     void BindToL(TCFDataClient::TBindTo& aBindTo);
       
   139     void Rejoin(const TCFFlow::TRejoin& aRejoinMessage);
       
   140 	void StartFlowL(const Messages::TRuntimeCtxId& aSender);
       
   141     void StopFlow(TCFDataClient::TStop& aMessage);
       
   142     void Destroy();
       
   143 	
       
   144 	//Stores the contents of the provision config message.
       
   145 	//which is the window size in this case.
       
   146 	//The value will be used when sockets are opened to set the TCP receive window size.
       
   147 	void StoreProvision(TCFDataClient::TProvisionConfig& aMessage);
       
   148 	//Extracts the extension from TProvisionConfig
       
   149 	//Presently extracts pointer to CTCPReceiveWindow
       
   150 	void ExtractSetOptExtensions();
       
   151 	void SetProtocolOptions();
       
   152 
       
   153 protected:
       
   154 	CTransportFlowShim(CSubConnectionFlowFactoryBase& aFactory, const Messages::TNodeId& aSubConn, CProtocolIntfBase* aProtocolIntf);
       
   155 
       
   156 #ifdef SYMBIAN_NETWORKING_UPS
       
   157 	virtual TInt SetupForNoBearerOnSend();
       
   158 	virtual void PreUnbind();
       
   159 	virtual TInt ProcessReceivedL(Messages::TSignatureBase& aMessage);
       
   160 
       
   161 	// from CNetworkFlow
       
   162 	TBool ActivityRunning();
       
   163 	
       
   164 	// Utility functions
       
   165 	inline TBool IsHostResolver() const;
       
   166 	inline TBool IsStopped();
       
   167 	inline void SetIfInfo(const TSoIfConnectionInfo& aInfo);
       
   168 	inline void ClearUseBearerErrors();
       
   169     inline void ClearDataClientRoutedGuard();
       
   170 
       
   171     void PostNoBearer();
       
   172     void PostDataClientRouted();
       
   173 	// From MSocketNotify
       
   174 	virtual void Error(TInt anError,TUint anOperationMask=MSocketNotify::EErrorAllOperations);
       
   175 #endif
       
   176 
       
   177 private:
       
   178 	// From MSocketNotify to convert up-calls to MSessionControlNotify & MSessionDataNotify
       
   179 	virtual void NewData(TUint aCount);
       
   180 	virtual void CanSend();
       
   181 	virtual void ConnectComplete();
       
   182 	virtual void ConnectComplete(const TDesC8& aConnectData);
       
   183     virtual void ConnectComplete(CServProviderBase& aSSP);
       
   184 	virtual void ConnectComplete(CServProviderBase& aSSP,const TDesC8& aConnectData);
       
   185 	virtual void CanClose(MSocketNotify::TDelete aDelete=MSocketNotify::EDelete);
       
   186 	virtual void CanClose(const TDesC8& aDisconnectData,MSocketNotify::TDelete aDelete=MSocketNotify::EDelete);
       
   187 #ifndef SYMBIAN_NETWORKING_UPS
       
   188 	// Needs to be protected rather than private for UPS support
       
   189 	virtual void Error(TInt anError,TUint anOperationMask=MSocketNotify::EErrorAllOperations);
       
   190 #endif
       
   191 	virtual void Disconnect(void);
       
   192 	virtual void Disconnect(TDesC8& aDisconnectData);
       
   193 	virtual void IoctlComplete(TDesC8 *aBuf);
       
   194 	virtual void NoBearer(const TDesC8& aConnectionParams);
       
   195 	virtual void Bearer(const TDesC8& aConnectionInfo);
       
   196 	TBool DoNoBearer();
       
   197 	void SetLocalNameProcess();
       
   198 
       
   199 
       
   200     CTransportFlowShim* CloneNSetSAP(CServProviderBase& aSSP);
       
   201 	void InitDestroy();
       
   202 #ifndef SYMBIAN_NETWORKING_UPS
       
   203 	// Needs to be protected rather than private for UPS support
       
   204     void PostNoBearer();
       
   205     void PostDataClientRouted();
       
   206     inline void ClearDataClientRoutedGuard();
       
   207 #endif
       
   208     void CompleteStart(TInt aError);
       
   209 
       
   210 #ifdef SYMBIAN_NETWORKING_UPS
       
   211 	// Not entirely UPS specific - cleanup of CNetworkFlow/CTransportFlowShim functionality split
       
   212     inline TBool NoBearerGuard() const;
       
   213     inline void SetNoBearerGuard();
       
   214     inline void ClearNoBearerGuard();
       
   215 #endif
       
   216 	void NoBearerCompletion();
       
   217 
       
   218 private:
       
   219 	CServProviderBase* iProvider;
       
   220 	//CHostResolver specific workaround for now
       
   221 	MUpperControl* iHostResolverNotify; //since CHostResolver specific
       
   222 	MSessionControlNotify* iListenerControlNotify; // to notify listening sockets that a passively opened socket in the accept queue has been unbound
       
   223 	// TODO
       
   224 	// MSocketControlledNotify* iSocket;
       
   225 	Messages::RRequestOriginator iStartRequest;
       
   226 
       
   227     TSoIfConnectionInfo iIfInfo;
       
   228     TUint iDetaching:1;
       
   229     TUint iUseBearerErrors:1;		// error the socket on Error() upcalls from bearer rather than StopFlow() calls from SCPR
       
   230 	TUint iDataClientRoutedGuard:1;	// DataClientRouted msg has been issued to SCPR
       
   231 	TUint iIsStopped:1;				// DataClientStop has been received.
       
   232 #ifdef SYMBIAN_NETWORKING_UPS
       
   233 	TBool iNoBearerRunning:1;		// NoBearer message has been issued to SCPR
       
   234 	TBool iShuttingDown:1;
       
   235 #endif
       
   236 
       
   237 #ifdef SYMBIAN_ADAPTIVE_TCP_RECEIVE_WINDOW
       
   238     const CSAPSetOpt *iProtocolOptions;
       
   239 #endif //SYMBIAN_ADAPTIVE_TCP_RECEIVE_WINDOW
       
   240 	
       
   241 	// Reference to the protocol as managed by the ProtocolManager
       
   242 	CProtocolRef* iProtocolReference;
       
   243 	TFlowParams iFlowParams;
       
   244 	TBool iBearerExpected;
       
   245 	TBool iDeleteUponBearerReception;
       
   246 	};
       
   247 
       
   248 inline CServProviderBase* CTransportFlowShim::Provider()
       
   249 	{
       
   250 	return iProvider;
       
   251 	}
       
   252 
       
   253 #ifdef SYMBIAN_NETWORKING_UPS
       
   254 
       
   255 //
       
   256 // CTransportFlowShim inline methods
       
   257 //
       
   258 
       
   259 inline TBool CTransportFlowShim::NoBearerGuard() const
       
   260 	{ return iNoBearerRunning; }
       
   261 
       
   262 inline void CTransportFlowShim::SetNoBearerGuard()
       
   263    	{ iNoBearerRunning = ETrue; }
       
   264 
       
   265 inline void CTransportFlowShim::ClearNoBearerGuard()
       
   266     { iNoBearerRunning = EFalse; }
       
   267 
       
   268 inline void CTransportFlowShim::ClearUseBearerErrors()
       
   269 	{ iUseBearerErrors = EFalse; }
       
   270 
       
   271 inline TBool CTransportFlowShim::IsStopped()
       
   272 	{ return iIsStopped; }
       
   273 
       
   274 inline TBool CTransportFlowShim::IsHostResolver() const
       
   275 	{ return iHostResolverNotify != NULL; }
       
   276 
       
   277 inline void CTransportFlowShim::SetIfInfo(const TSoIfConnectionInfo& aInfo)
       
   278 	{ iIfInfo = aInfo; }
       
   279 
       
   280 //
       
   281 // CUpsTransportFlowShim
       
   282 //
       
   283 
       
   284 NONSHARABLE_CLASS(CUpsTransportFlowShim) : public CTransportFlowShim
       
   285 /**
       
   286 CUpsTransportFlowShim - UPS specific functionality over CTransportFlowShim
       
   287 */
       
   288 	{
       
   289 public:
       
   290 	static CUpsTransportFlowShim* NewL(CSubConnectionFlowFactoryBase& aFactory, const Messages::TNodeId& aSubConn, CProtocolIntfBase* aProtocolIntf);
       
   291 	inline CUpsTransportFlowShim(CSubConnectionFlowFactoryBase& aFactory, const Messages::TNodeId& aSubConn, CProtocolIntfBase* aProtocolIntf);
       
   292 
       
   293 	inline TBool UpsEnabled() const;
       
   294 	inline void SetPolicyCheckRequestPending(TBool aGuard);
       
   295 	inline TBool PolicyCheckRequestPending() const;
       
   296 
       
   297 	void ParseNoBearerParams(const TDesC8& aConnectionParams);
       
   298 	void GetProcessAndThreadId(TProcessId& aProcessId, TThreadId& aThreadId) const;
       
   299 	void PopulateUpsExtension(TInt aPolicyCheckResult) const;
       
   300 	void PostPolicyCheckRequest(TInt aPolicyCheckResult);
       
   301 	void ProcessPolicyCheckResponse(const UpsMessage::TPolicyCheckResponse& aMessage);
       
   302 
       
   303 protected:
       
   304 	// from CTransportFlowShim
       
   305 	TInt SetupForNoBearerOnSend();
       
   306 	void PreUnbind();
       
   307 	TInt ProcessReceivedL(Messages::TSignatureBase& aMessage);
       
   308     void SubConnectionError(const Messages::TEBase::TError& aErrorMsg, TUint anOperationMask = (MSocketNotify::EErrorSend | MSocketNotify::EErrorConnect));
       
   309     void IssueScopedNoBearerResponse();
       
   310     
       
   311 	// from CTransportFlowShim (CServProviderBase base class)
       
   312 	TInt SetOption(TUint aLevel, TUint aName, const TDesC8& anOption);
       
   313 	TInt SecurityCheck(MProvdSecurityChecker* aChecker);
       
   314 	
       
   315 	// from CTransportFlowShim (MSocketNotify base class)
       
   316 	void NoBearer(const TDesC8& aConnectionParams);
       
   317 
       
   318 	// from CTransportFlowShim (CNetworkFlow base class)
       
   319 	TBool ActivityRunning();
       
   320 
       
   321 private:
       
   322 	MProvdSecurityChecker* iSecurityChecker;	// class used to perform PlatSec check
       
   323 	TProcessId  iProcessId; 					// Client Process Id
       
   324 	TThreadId   iThreadId;  					// Client Thread  Id	
       
   325 	CUPSAccessPointConfigExt* iUpsExtension;	// UPS Access Point Config structure.  Remains NULL if UPS is disabled.
       
   326 	const ESock::MPlatsecApiExt* iPlatsecIf;	// upcall interface to allow dynamic retrieval of thread/process id
       
   327 
       
   328 	TUint iIsScoped:1;					// NoBearer() has indicated that the socket address has a scope id.
       
   329 	TUint iPolicyCheckRequestPending:1;	// TPolicyCheckRequest message has been sent, awaiting response
       
   330 	};
       
   331 
       
   332 //
       
   333 // CUpsTransportFlowShim Inline functions
       
   334 //
       
   335 
       
   336 inline CUpsTransportFlowShim::CUpsTransportFlowShim(CSubConnectionFlowFactoryBase& aFactory, const Messages::TNodeId& aSubConn, CProtocolIntfBase* aProtocolIntf)
       
   337 		: CTransportFlowShim(aFactory, aSubConn, aProtocolIntf)
       
   338 			{
       
   339 		 	}
       
   340 
       
   341 inline TBool CUpsTransportFlowShim::UpsEnabled() const
       
   342 	{ return iUpsExtension != NULL;	}
       
   343 	
       
   344 inline void CUpsTransportFlowShim::SetPolicyCheckRequestPending(TBool aPending)
       
   345 	{ iPolicyCheckRequestPending = aPending; }
       
   346 	
       
   347 inline TBool CUpsTransportFlowShim::PolicyCheckRequestPending() const
       
   348 	{ return iPolicyCheckRequestPending; }
       
   349 
       
   350 #endif
       
   351 
       
   352 } // namespace ESock
       
   353 
       
   354 #endif //__SS_SAPSHIM_H__
       
   355