bluetooth/btstack/rfcomm/rfcommstates.h
changeset 0 29b1cd4cb562
child 8 2b6718f05bdb
equal deleted inserted replaced
-1:000000000000 0:29b1cd4cb562
       
     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 #ifndef RFCOMMSTATES_H
       
    17 #define RFCOMMSTATES_H
       
    18 
       
    19 #include <bt_sock.h>
       
    20 #include "rfcommsap.h"
       
    21 #include "rfcommutil.h"
       
    22 #include "rfcommtypes.h"
       
    23 
       
    24 // Defines the states for the state pattern used by the rfcomm saps
       
    25 
       
    26 class CRfcommState;
       
    27 class CRfcommSAP;
       
    28 
       
    29 NONSHARABLE_CLASS(CRfcommStateFactory) : public CBase
       
    30 	{
       
    31 friend class CRfcommProtocol;
       
    32 public:
       
    33 	enum TRfcommStates
       
    34 		{
       
    35 		EError,
       
    36 		EClosed,
       
    37 		EWaitForMux,
       
    38 		EWaitForPNResp,
       
    39 		EWaitForUA,
       
    40 		EOpen,
       
    41 		EDisconnect,
       
    42 		EListening,
       
    43 		EWaitForSABM,
       
    44 		EWaitForOutgoingSecurityCheck,
       
    45 		EWaitForIncomingSecurityCheck,
       
    46 		EWaitForStart,
       
    47 		ECloseOnStart,
       
    48 		EDisconnecting,
       
    49 	// *** keep next one last ***
       
    50 		ERfcommMaxState,
       
    51 		};
       
    52 	
       
    53 	TRfcommState* GetState(const TRfcommStates aState);
       
    54 	TInt StateIndex(const TRfcommState* aState) const;
       
    55 	
       
    56 	static CRfcommStateFactory* NewL();
       
    57 	~CRfcommStateFactory();
       
    58 private:
       
    59 	CRfcommStateFactory();
       
    60 	void ConstructL();
       
    61 
       
    62 	TFixedArray<TRfcommState*, ERfcommMaxState> iStates;
       
    63 	};
       
    64 
       
    65 /**
       
    66    The base class for all the Rfcomm SAP states.
       
    67    
       
    68    This is interface that all state objects participating in the state
       
    69    pattern have to adhere to.  It provides a mirror of the interface
       
    70    of a SAP, since SAPs pass all actions through to the state object
       
    71    to provide stateful behaviour.
       
    72 
       
    73    Since States are implemented as flyweight objects, there can be no
       
    74    SAP specific state information maintained in the state.  All the
       
    75    information specific to the SAP is stored by the SAP, which acts as
       
    76    a context for the state.
       
    77    
       
    78    Private
       
    79 **/
       
    80 NONSHARABLE_CLASS(TRfcommState)
       
    81 	{
       
    82 public:
       
    83 	TRfcommState(CRfcommStateFactory& aFactory);
       
    84 	// State
       
    85 	virtual void Enter(CRfcommSAP& aSAP)=0;  // Entry to a state
       
    86 	virtual void Exit(CRfcommSAP& aSAP)=0;	//	Exiting a state
       
    87 	// From the socket
       
    88 	virtual void ActiveOpen(CRfcommSAP& aSAP)=0;
       
    89 	virtual TInt PassiveOpen(CRfcommSAP& aSAP, TUint aQueSize)=0;
       
    90 	virtual void Shutdown(CRfcommSAP& aSAP)=0;
       
    91 	virtual void FastShutdown(CRfcommSAP& aSAP)=0;
       
    92 	virtual TInt Send(CRfcommSAP& aSAP, const TDesC8& aData)=0;
       
    93 	virtual void Read(CRfcommSAP& aSAP, TDesC8& aData)=0;
       
    94 	virtual void Ioctl(CRfcommSAP& aSAP, TUint aLevel, TUint aName, TDes8* aOption)=0;
       
    95 	virtual void CancelIoctl(CRfcommSAP& aSAP, TUint aLevel, TUint aName)=0;
       
    96 	virtual void Start(CRfcommSAP& aSAP)=0;
       
    97 	virtual TInt SetOption(CRfcommSAP& aSAP, TUint aLevel, 
       
    98 						   TUint aName, const TDesC8 &aOption) =0;
       
    99 
       
   100 	// From the muxer
       
   101 	virtual void MuxUp(CRfcommSAP& aSAP)=0;
       
   102 	virtual void LinkDown(CRfcommSAP& aSAP)=0;
       
   103 	virtual void IoctlComplete(CRfcommSAP& aSAP, TInt aErr, TUint aLevel,TUint aName, TDesC8* aBuf) =0;
       
   104 
       
   105 	// From the security requester
       
   106 	virtual void AccessRequestComplete(CRfcommSAP& aSAP, TInt aResult)=0;
       
   107 
       
   108 	// frame types
       
   109 	virtual void SABM(CRfcommSAP& aSAP, CRfcommMuxer& aMux, TUint8 aDLCI)=0;	
       
   110 	virtual void UA(CRfcommSAP& aSAP)=0;
       
   111 	virtual void DISC(CRfcommSAP& aSAP)=0;
       
   112 	virtual void DM(CRfcommSAP& aSAP)=0;
       
   113 	// mux channel commands
       
   114 	// Remote parameter negotiation
       
   115 	virtual void RPN(CRfcommSAP& aSAP, const TRfcommRPNTransaction& aRPNTransaction, CRfcommMuxer& aMux, TUint8 aDLCI)=0;
       
   116 	virtual void RPNRsp(CRfcommSAP& aSAP, const TRfcommRPNTransaction& aRPNTransaction)=0;
       
   117 	// Parameter negotiation
       
   118 	virtual void PN(CRfcommSAP& aSAP, TRfcommPortParams& aParams, CRfcommMuxer& aMux, TUint8 aDLCI)=0;  
       
   119 	virtual void PNResp(CRfcommSAP& aSAP, TRfcommPortParams& aParams)=0;
       
   120 	virtual void MSC(CRfcommSAP& aSAP, TUint8 aSignals)=0;// Modem status command
       
   121  	virtual void RLS(CRfcommSAP& aSAP, TUint8 aStatus)=0; // Remote line status
       
   122 	// data	
       
   123 	virtual void NewData(CRfcommSAP& aSAP, const TDesC8& aData)=0;
       
   124 	virtual void NotifyNewDataCallback(CRfcommSAP& aSAP)=0;
       
   125 	virtual void CanSend(CRfcommSAP& aSAP)=0;
       
   126 	virtual void Error(CRfcommSAP& aSAP, TInt aErr,
       
   127 					   CRfcommSAP::TErrorTypes aType)=0;
       
   128 //TRY_CBFC
       
   129 	virtual TUint8 FreeCredit(CRfcommSAP& aSAP)=0;
       
   130 	virtual TInt ProxyForRemoteCredit(const CRfcommSAP& aSAP) const =0;
       
   131 	virtual void SetProxyForRemoteCredit(CRfcommSAP& aSAP, TInt aCredit)=0;
       
   132 	virtual void ProxyForRemoteCreditDecrement(CRfcommSAP& aSAP)=0;
       
   133 	virtual void ProxyForRemoteCreditAddCredit(CRfcommSAP& aSAP, TUint8 aCredit)=0;
       
   134 	virtual TInt LocalCredit(const CRfcommSAP& aSAP) const =0;
       
   135 	virtual void SetInitialLocalCredit(CRfcommSAP& aSAP, TInt aCredit)=0;
       
   136 	virtual void LocalCreditDecrement(CRfcommSAP& aSAP)=0;
       
   137 	virtual void LocalCreditAddCredit(CRfcommSAP& aSAP, TUint8 aCredit)=0;
       
   138 	// Notification for cloned SAPs waiting for connection.
       
   139 	virtual void ParentClosed(CRfcommSAP& aSAP)=0;
       
   140 	
       
   141 	// Notifications from sent frames waiting for a response.
       
   142 	virtual TBool HandleFrameResponseTimeout(CRfcommSAP& aSAP)=0;
       
   143 
       
   144 protected:
       
   145 	// Utility Error function
       
   146 	TInt SignalError(CRfcommSAP& aSAP, TInt aErr, MSocketNotify::TOperationBitmasks aType);
       
   147 
       
   148 	// State change utility function
       
   149 	void ChangeState(CRfcommSAP& aSAP, CRfcommStateFactory::TRfcommStates aNewState) const;
       
   150 	
       
   151 	// State panicking functions
       
   152 	void PanicInState(TRFCOMMPanic aPanic) const;
       
   153 	void DebugPanicInState(TRFCOMMPanic aPanic) const;
       
   154 
       
   155 protected:
       
   156 	// Data
       
   157 	CRfcommStateFactory& iFactory;  // Get states
       
   158 #ifdef __FLOG_ACTIVE
       
   159 	TBuf<48> iName;
       
   160 #endif
       
   161 private:
       
   162     // Forbid copying
       
   163 	TRfcommState(const TRfcommState&);
       
   164 	const TRfcommState& operator=(const TRfcommState&);
       
   165 	};
       
   166 
       
   167 #ifdef __FLOG_ACTIVE
       
   168 #define STATENAME(x) iName=_L(x)
       
   169 #else
       
   170 #define STATENAME(x)
       
   171 #endif
       
   172 
       
   173 /**
       
   174    A state class that provides default behaviours.
       
   175    
       
   176    This state provides some default behaviours so that other states
       
   177    can simply derive from it and thus pick up a set of default
       
   178    behaviours.  This reduces the coding burden for other states.
       
   179 
       
   180    For events originating within the Socket, the default behaviour is
       
   181    to panic as derived classes should be implementing the correct
       
   182    functionality.  For events coming in from the Muxer, we don't
       
   183    assume that the derived class will be expecting this event (since
       
   184    it has essentially come from the remote end).  Thus the default
       
   185    behaviour is to place the SAP into an error state, as this is the
       
   186    fail-safe state when the remote end sends us an unexpected event.
       
   187    
       
   188    Private
       
   189 **/
       
   190 NONSHARABLE_CLASS(TRfcommStateDefault) : public TRfcommState
       
   191  	{
       
   192 public:
       
   193 	TRfcommStateDefault(CRfcommStateFactory& aFactory);
       
   194 
       
   195 	// Normal state changes
       
   196 	virtual void Enter(CRfcommSAP& aSAP);
       
   197 	virtual void Exit(CRfcommSAP& aSAP);
       
   198 
       
   199 	// State changes initiated by the SAP. Default is to Panic.
       
   200 	virtual void ActiveOpen(CRfcommSAP&  aSAP);
       
   201 	virtual TInt PassiveOpen(CRfcommSAP&  aSAP, TUint aQueSize);
       
   202 	virtual void Shutdown(CRfcommSAP&  aSAP);
       
   203 	virtual void FastShutdown(CRfcommSAP&  aSAP);
       
   204 	virtual TInt Send(CRfcommSAP& aSAP, const TDesC8& aData);
       
   205 	virtual void Read(CRfcommSAP& aSAP, TDesC8& aData);
       
   206 	virtual void Ioctl(CRfcommSAP& aSAP, TUint aLevel, TUint aName, TDes8* aOption);
       
   207 	virtual void CancelIoctl(CRfcommSAP& aSAP, TUint aLevel, TUint aName);
       
   208 	virtual void Start(CRfcommSAP& aSAP);
       
   209 	virtual TInt SetOption(CRfcommSAP& aSAP, TUint level, TUint name, const TDesC8& aOption);
       
   210 
       
   211 	// From the signaller, go to error state
       
   212 	virtual void MuxUp(CRfcommSAP& aSAP);
       
   213 	virtual void LinkDown(CRfcommSAP& aSAP);
       
   214 	virtual void SABM(CRfcommSAP& aSAP, CRfcommMuxer& aMux, TUint8 aDLCI);	//	SABM for listening SAP
       
   215 	virtual void DISC(CRfcommSAP& aSAP);
       
   216 	virtual void UA(CRfcommSAP& aSAP);
       
   217 	virtual void DM(CRfcommSAP& aSAP);
       
   218 	virtual void RPN(CRfcommSAP& aSAP, const TRfcommRPNTransaction& aRPNTransaction, CRfcommMuxer& aMux, TUint8 aDLCI);
       
   219 	virtual void RPNRsp(CRfcommSAP& aSAP, const TRfcommRPNTransaction& aRPNTransaction);
       
   220 	virtual void PN(CRfcommSAP& aSAP, TRfcommPortParams& aParams, CRfcommMuxer& aMux, TUint8 aDLCI);
       
   221 
       
   222 	virtual void PNResp(CRfcommSAP& aSAP, TRfcommPortParams& aParams);
       
   223 	virtual void MSC(CRfcommSAP& aSAP, TUint8 aSignals);
       
   224 	virtual void RLS(CRfcommSAP& aSAP, TUint8 aStatus);
       
   225 	virtual void NewData(CRfcommSAP& aSAP, const TDesC8& aData);
       
   226 	virtual void NotifyNewDataCallback(CRfcommSAP& aSAP);
       
   227 	virtual void CanSend(CRfcommSAP& aSAP);
       
   228 	virtual void IoctlComplete(CRfcommSAP& aSAP, TInt aErr, TUint aLevel,TUint aName, TDesC8* aBuf);
       
   229 	virtual void AccessRequestComplete(CRfcommSAP& aSAP, TInt aResult);
       
   230 	virtual void Error(CRfcommSAP& aSAP, TInt aErr, CRfcommSAP::TErrorTypes aType);
       
   231 
       
   232 	// Notification for cloned SAPs waiting for connection.
       
   233 	virtual void ParentClosed(CRfcommSAP& aSAP);
       
   234 
       
   235 	// Notifications from sent frames waiting for a response.
       
   236 	virtual TBool HandleFrameResponseTimeout(CRfcommSAP& aSAP);
       
   237 //TRY_CBFC
       
   238 	virtual TUint8 FreeCredit(CRfcommSAP& aSAP);
       
   239 	virtual TInt ProxyForRemoteCredit(const CRfcommSAP& aSAP) const;
       
   240 	virtual void SetProxyForRemoteCredit(CRfcommSAP& aSAP, TInt aCredit);
       
   241 	virtual void ProxyForRemoteCreditDecrement(CRfcommSAP& aSAP);
       
   242 	virtual void ProxyForRemoteCreditAddCredit(CRfcommSAP& aSAP, TUint8 aCredit);
       
   243 	virtual TInt LocalCredit(const CRfcommSAP& aSAP) const;
       
   244 	virtual void SetInitialLocalCredit(CRfcommSAP& aSAP, TInt aCredit);
       
   245 	virtual void LocalCreditDecrement(CRfcommSAP& aSAP);
       
   246 	virtual void LocalCreditAddCredit(CRfcommSAP& aSAP, TUint8 aCredit);
       
   247 
       
   248 protected:
       
   249 	
       
   250 	};
       
   251 
       
   252 /**
       
   253    The error state.
       
   254 
       
   255    All operations are errors, and cause error signals to be sent to
       
   256    the SAP.
       
   257    
       
   258    Private
       
   259 **/
       
   260 NONSHARABLE_CLASS(TRfcommStateError) : public TRfcommStateDefault
       
   261 	{
       
   262 public:
       
   263 	TRfcommStateError(CRfcommStateFactory& aFactory);
       
   264 	virtual void Enter(CRfcommSAP& aSAP);
       
   265 	// State changes initiated by the SAP
       
   266 	virtual void ActiveOpen(CRfcommSAP& aSAP);
       
   267 	virtual TInt PassiveOpen(CRfcommSAP& aSAP, TUint /*aQueSize*/);
       
   268 	virtual void Shutdown(CRfcommSAP& aSAP);
       
   269 	virtual void FastShutdown(CRfcommSAP& aSAP);
       
   270 	virtual TInt Send(CRfcommSAP& aSAP, const TDesC8&);
       
   271 	virtual void Read(CRfcommSAP& aSAP, TDesC8&);
       
   272 	virtual void Ioctl(CRfcommSAP& aSAP, TUint, TUint, TDes8*);
       
   273 	virtual void CancelIoctl(CRfcommSAP& aSAP, TUint, TUint);
       
   274 	virtual void Start(CRfcommSAP& aSAP);
       
   275 	};
       
   276 
       
   277 //
       
   278 // The interesting states start here
       
   279 //
       
   280 
       
   281 /**
       
   282    Closed - the initial state.
       
   283 
       
   284 	This state is the initial state of the SAP, as well as the end
       
   285 	state when a connection is disconnected.  A SAP in this state
       
   286 	cannot be assumed to have valid remote or local addresses in
       
   287 	place.
       
   288 
       
   289 	The invariant on this state is that it will not have a muxer.
       
   290    
       
   291    Private
       
   292 **/
       
   293 NONSHARABLE_CLASS(TRfcommStateClosed) : public TRfcommStateDefault
       
   294 	{
       
   295 public:
       
   296 	TRfcommStateClosed(CRfcommStateFactory& aFactory);
       
   297 	virtual void Enter(CRfcommSAP& aSAP);
       
   298 	// State changes initiated by the SAP
       
   299 	void ActiveOpen(CRfcommSAP& aSAP);
       
   300 	TInt PassiveOpen(CRfcommSAP& aSAP, TUint aQueSize);
       
   301 	void Shutdown(CRfcommSAP&  aSAP);	
       
   302 	void Error(CRfcommSAP& aSAP, TInt aErr,
       
   303 					   CRfcommSAP::TErrorTypes aType);
       
   304 	void Start(CRfcommSAP& aSAP);
       
   305 	TInt SetOption(CRfcommSAP& aSAP, TUint aLevel, TUint aName, const TDesC8 &aOption);
       
   306 	};
       
   307 
       
   308 /**
       
   309    A superstate class that provides default behaviours for connecting states.
       
   310 
       
   311    Connecting states are the states between closed and open when the
       
   312    local side is doing an active open.
       
   313    
       
   314    Private
       
   315 **/
       
   316 NONSHARABLE_CLASS(TRfcommStateConnecting) : public TRfcommStateDefault
       
   317  	{
       
   318 public:
       
   319 	TRfcommStateConnecting(CRfcommStateFactory& aFactory);
       
   320 
       
   321 	// State changes initiated by the SAP. Default is to Panic.
       
   322 	virtual void Shutdown(CRfcommSAP&  aSAP);
       
   323 	virtual void FastShutdown(CRfcommSAP&  aSAP);
       
   324 
       
   325 	virtual void DM(CRfcommSAP& aSAP);
       
   326 
       
   327 	virtual void LinkDown(CRfcommSAP& aSAP);
       
   328 protected:
       
   329 	//	Used to issue appropriate notifications to SAP when
       
   330 	//	connection fails (CanClose or SignalError)
       
   331 	virtual void FailureWhileConnecting(CRfcommSAP& aSAP, TInt aErrorCode);
       
   332 	};
       
   333 
       
   334 /**
       
   335    Waiting for the muxer.
       
   336    
       
   337    When the protocol is asked to find the muxer for a SAP, it will
       
   338    either find an existing one or bring up a link, create a muxer and
       
   339    then use the new one.  Either way, eventually the MuxUp event will
       
   340    be generated.
       
   341    Once the Mux is up, we then need to send a SABM command.
       
   342    Note that a LinkDown event can occur in this state.
       
   343    
       
   344    Private
       
   345 **/
       
   346 NONSHARABLE_CLASS(TRfcommStateWaitForMux) : public TRfcommStateConnecting
       
   347 	{
       
   348 public:
       
   349 	TRfcommStateWaitForMux(CRfcommStateFactory& aFactory);
       
   350 	void Enter(CRfcommSAP& aSAP);
       
   351 	void Shutdown(CRfcommSAP& aSAP);
       
   352 	void SABM(CRfcommSAP& aSAP, CRfcommMuxer& aMux, TUint8 aDLCI);	
       
   353 	void UA(CRfcommSAP& aSAP);
       
   354 	void DISC(CRfcommSAP& aSAP);
       
   355 	void DM(CRfcommSAP& aSAP);
       
   356 	// mux channel commands
       
   357 	// Remote parameter negotiation
       
   358 	void RPN(CRfcommSAP& aSAP, const TRfcommRPNTransaction& aRPNTransaction, CRfcommMuxer& aMux, TUint8 aDLCI);
       
   359 	void RPNRsp(CRfcommSAP& aSAP, const TRfcommRPNTransaction& aRPNTransaction);
       
   360 	// Parameter negotiation
       
   361 	void PN(CRfcommSAP& aSAP, TRfcommPortParams& aParams, CRfcommMuxer& aMux, TUint8 aDLCI);  
       
   362 	void PNResp(CRfcommSAP& aSAP, TRfcommPortParams& aParams);
       
   363 	void MSC(CRfcommSAP& aSAP, TUint8 aSignals);// Modem status command
       
   364  	void RLS(CRfcommSAP& aSAP, TUint8 aStatus); // Remote line status
       
   365 	// data	
       
   366 	void NewData(CRfcommSAP& aSAP, const TDesC8& aData);
       
   367 
       
   368 	// State change from the Mux
       
   369 	void MuxUp(CRfcommSAP& aSAP);
       
   370 	};
       
   371 
       
   372 /**
       
   373 	Waiting for Parameter Negotiation response.
       
   374 
       
   375    On successful response, we contine with the connection. On unsuccessful
       
   376    response, we signal a socket error and return to the Closed state.
       
   377    
       
   378    Private
       
   379 **/
       
   380 NONSHARABLE_CLASS(TRfcommStateWaitForPNResp) : public TRfcommStateConnecting
       
   381 	{
       
   382 public:
       
   383 	TRfcommStateWaitForPNResp(CRfcommStateFactory& aFactory);
       
   384 	void Enter(CRfcommSAP& aSAP);
       
   385 	// State change from the Mux
       
   386 	void PNResp(CRfcommSAP& aSAP, TRfcommPortParams& aParams);
       
   387 	};
       
   388 
       
   389 
       
   390 /**
       
   391    Wait For UA state (subclass of Connecting state).
       
   392 
       
   393    State in which we are waiting for a reponse to our SABM command.
       
   394 
       
   395    On successful connect we send an MSC (modem status command) and
       
   396    enter the open state.
       
   397 
       
   398    Private
       
   399 **/
       
   400 NONSHARABLE_CLASS(TRfcommStateWaitForUA) : public TRfcommStateConnecting
       
   401 	{
       
   402 public:
       
   403 	TRfcommStateWaitForUA(CRfcommStateFactory& aFactory);
       
   404 	// mux events
       
   405 	void UA(CRfcommSAP& aSAP);
       
   406 
       
   407 	// Notifications from sent frames waiting for a response.
       
   408 	TBool HandleFrameResponseTimeout(CRfcommSAP& aSAP);
       
   409 	};
       
   410 
       
   411 
       
   412 /**
       
   413    Waiting for the outgoing security check to complete.
       
   414 
       
   415    This is the state while we wait for the SecMan to give a go/no-go
       
   416    on this connection.
       
   417 **/
       
   418 NONSHARABLE_CLASS(TRfcommStateOutgoingSecurityCheck) : public TRfcommStateConnecting
       
   419 	{
       
   420 public:
       
   421 	TRfcommStateOutgoingSecurityCheck(CRfcommStateFactory& aFactory);
       
   422 	// mux events
       
   423 	void Enter(CRfcommSAP& aSAP);
       
   424 
       
   425 	void AccessRequestComplete(CRfcommSAP& aSAP, TInt aResult);
       
   426 	void Exit(CRfcommSAP& aSAP);
       
   427 	};
       
   428 
       
   429 
       
   430 /**
       
   431 	Listening State
       
   432 
       
   433 	State that the SAP enters following a PassiveOpen.
       
   434    
       
   435     Private
       
   436 **/
       
   437 
       
   438 NONSHARABLE_CLASS(TRfcommStateListening) : public TRfcommStateDefault
       
   439 	{
       
   440 public:
       
   441 	TRfcommStateListening(CRfcommStateFactory& aFactory);
       
   442 	void Enter(CRfcommSAP& aSAP);
       
   443 	void Exit(CRfcommSAP& aSAP);
       
   444 	void SABM(CRfcommSAP& aSAP, CRfcommMuxer& aMux, TUint8 aDLCI);
       
   445 	void PN(CRfcommSAP& aSAP, TRfcommPortParams& aParams, CRfcommMuxer& aMux, TUint8 aDLCI);
       
   446 	void RPN(CRfcommSAP& aSAP, const TRfcommRPNTransaction& aRPNTransaction, CRfcommMuxer& aMux, TUint8 aDLCI);
       
   447 	void Shutdown(CRfcommSAP& aSAP);
       
   448 	void FastShutdown(CRfcommSAP& aSAP);
       
   449 	TInt SetOption(CRfcommSAP& aSAP, TUint aLevel, TUint aName, const TDesC8 &aOption);
       
   450 private:
       
   451 	CRfcommSAP* AttemptToClone(CRfcommSAP& aSAP, CRfcommMuxer& aMux, TUint8 aDLCI);
       
   452 	};
       
   453 
       
   454 /**
       
   455    Base state for cloned saps before they are taken over by ESOCK.
       
   456 
       
   457    This base state handles a bunch of the error handling for the
       
   458    derived states.
       
   459 **/
       
   460 
       
   461 NONSHARABLE_CLASS(TRfcommStateCloned) : public TRfcommStateDefault
       
   462 	{
       
   463 public:
       
   464 	TRfcommStateCloned(CRfcommStateFactory& aFactory);
       
   465 	void LinkDown(CRfcommSAP& aSAP);
       
   466 	void Error(CRfcommSAP& aSAP, TInt aErr,
       
   467 			   CRfcommSAP::TErrorTypes aType);
       
   468 	void DISC(CRfcommSAP& aSAP);
       
   469 	void DM(CRfcommSAP& aSAP);
       
   470 	};	
       
   471 
       
   472 /**
       
   473 	The Wait For SABM state.
       
   474 
       
   475 	The state that cloned SAPs start off in before receiving
       
   476 	a PN or SABM.
       
   477    
       
   478     Private
       
   479 **/
       
   480 NONSHARABLE_CLASS(TRfcommStateWaitForSABM) : public TRfcommStateCloned
       
   481 	{
       
   482 public:
       
   483 	TRfcommStateWaitForSABM(CRfcommStateFactory& aFactory);
       
   484 	void SABM(CRfcommSAP& aSAP, CRfcommMuxer& aMux, TUint8 aDLCI);
       
   485 	void RPN(CRfcommSAP& aSAP, const TRfcommRPNTransaction& aRPNTransaction, 
       
   486 			 CRfcommMuxer& aMux, TUint8 aDLCI);
       
   487 	void PN(CRfcommSAP& aSAP, TRfcommPortParams& aParams, CRfcommMuxer& aMux, TUint8 aDLCI);
       
   488 	void MuxUp(CRfcommSAP& aSAP);
       
   489 	};
       
   490 
       
   491 /**
       
   492    Waiting for the incoming security check to complete.
       
   493 
       
   494    This is the state while we wait for the SecMan to give a go/no-go
       
   495    on this connection.  We will respond to SABM with a DM if the
       
   496    answer is no.
       
   497 **/
       
   498 NONSHARABLE_CLASS(TRfcommStateIncomingSecurityCheck) : public TRfcommStateCloned
       
   499 	{
       
   500 public:
       
   501 	TRfcommStateIncomingSecurityCheck(CRfcommStateFactory& aFactory);
       
   502 	void Enter(CRfcommSAP& aSAP);
       
   503 	void AccessRequestComplete(CRfcommSAP& aSAP, TInt aResult);
       
   504 	void Exit(CRfcommSAP& aSAP);
       
   505 	};
       
   506 
       
   507 /**
       
   508 	The Wait For Start state.
       
   509 
       
   510 	The state that cloned SAPs arrive in after receiving a SABM
       
   511    
       
   512     Private
       
   513 **/
       
   514 NONSHARABLE_CLASS(TRfcommStateWaitForStart) : public TRfcommStateDefault
       
   515 	{
       
   516 public:
       
   517 	TRfcommStateWaitForStart(CRfcommStateFactory& aFactory);
       
   518 	void Enter(CRfcommSAP& aSAP);
       
   519 	void Start(CRfcommSAP& aSAP);
       
   520 	void DISC(CRfcommSAP& aSAP);
       
   521 	void Error(CRfcommSAP& aSAP, TInt aErr,
       
   522 				CRfcommSAP::TErrorTypes aType);
       
   523 	};
       
   524 
       
   525 /**
       
   526 	The Close On Start state
       
   527 
       
   528 	State arrived at when a disconnect is sent to a SAP which is
       
   529 	waiting for a Start. A SAP in this state will disconnect 
       
   530 	immediately that a Start is called on it.
       
   531    
       
   532     Private
       
   533 **/
       
   534 NONSHARABLE_CLASS(TRfcommStateCloseOnStart) : public TRfcommStateDefault
       
   535 	{
       
   536 public:
       
   537 	TRfcommStateCloseOnStart(CRfcommStateFactory& aFactory);
       
   538 	void Start(CRfcommSAP& aSAP);
       
   539 	void Error(CRfcommSAP& aSAP, TInt aErr,
       
   540 				CRfcommSAP::TErrorTypes aType);
       
   541 	};
       
   542 
       
   543 /**
       
   544    The open state.
       
   545 
       
   546    The channel is connected and the data can now flow.
       
   547    
       
   548    Private
       
   549 **/
       
   550 
       
   551 NONSHARABLE_CLASS(TRfcommStateOpen) : public TRfcommStateDefault
       
   552 	{
       
   553 public:
       
   554 	TRfcommStateOpen(CRfcommStateFactory& aFactory);
       
   555 
       
   556 	void Enter(CRfcommSAP& aSAP);
       
   557 	void PerformDataAwareStateChange(CRfcommSAP& aSAP);
       
   558 	// From ESOCK
       
   559 	void Exit(CRfcommSAP& aSAP);
       
   560 	void Shutdown(CRfcommSAP& aSAP);
       
   561 	void FastShutdown(CRfcommSAP& aSAP);
       
   562 	TInt Send(CRfcommSAP& aSAP, const TDesC8& aData);
       
   563 	void Read(CRfcommSAP& aSAP, TDesC8& aData);
       
   564 	void Ioctl(CRfcommSAP& aSAP,TUint aLevel,TUint aName,TDes8* aOption);
       
   565 
       
   566 	// From mux
       
   567 	void NewData(CRfcommSAP& aSAP, const TDesC8& aData);
       
   568 	void NotifyNewDataCallback(CRfcommSAP& aSAP);
       
   569 	void CanSend(CRfcommSAP& aSAP);
       
   570 	void IoctlComplete(CRfcommSAP& aSAP, TInt aErr, TUint aLevel,TUint aName, TDesC8* aBuf);
       
   571 	void MSC(CRfcommSAP& aSAP, TUint8 aSignals);
       
   572 	void RPN(CRfcommSAP& aSAP, const TRfcommRPNTransaction& aRPNTransaction, CRfcommMuxer& aMux, TUint8 aDLCI);
       
   573 	void RPNRsp(CRfcommSAP& aSAP, const TRfcommRPNTransaction& aRPNTransaction);
       
   574 	void PN(CRfcommSAP& aSAP, TRfcommPortParams& aParams, CRfcommMuxer& aMux, TUint8 aDLCI);
       
   575 	void RLS(CRfcommSAP& aSAP, TUint8 /*aStatus*/);
       
   576 	void DISC(CRfcommSAP& aSAP);
       
   577 	void DM(CRfcommSAP& aSAP);
       
   578 	void LinkDown(CRfcommSAP& aSAP);
       
   579 	TInt SetOption(CRfcommSAP &aSAP, TUint aLevel, TUint aName, const TDesC8& aOption);
       
   580 //TRY_CBFC
       
   581 	TUint8 FreeCredit(CRfcommSAP& aSAP);
       
   582 
       
   583 	virtual TInt ProxyForRemoteCredit(const CRfcommSAP& aSAP) const;
       
   584 #ifndef __GCC32__
       
   585 	using TRfcommStateDefault::ProxyForRemoteCredit; //unhide other overloads;
       
   586 #endif
       
   587 	virtual TInt LocalCredit(const CRfcommSAP& aSAP) const;
       
   588 #ifndef __GCC32__
       
   589 	using TRfcommStateDefault::LocalCredit; //unhide other overloads;
       
   590 #endif
       
   591 	};
       
   592 
       
   593 /**
       
   594    The disconnect state.
       
   595 
       
   596    This is for a SAP on its way to being shutdown.
       
   597    
       
   598    Private
       
   599 **/
       
   600 
       
   601 
       
   602 NONSHARABLE_CLASS(TRfcommStateDisconnect) : public TRfcommStateDefault
       
   603 	{
       
   604 public:
       
   605 	TRfcommStateDisconnect(CRfcommStateFactory& aFactory);
       
   606 
       
   607 	void Enter(CRfcommSAP& aSAP);
       
   608 	void DISC(CRfcommSAP& aSAP);
       
   609 	void UA(CRfcommSAP& aSAP);
       
   610 	void DM(CRfcommSAP& aSAP);
       
   611 	void LinkDown(CRfcommSAP& aSAP);
       
   612 private:
       
   613 	//	Code common to UA, DM and DISC
       
   614 	void DisconnectComplete(CRfcommSAP& aSAP);
       
   615 	};
       
   616 
       
   617 /**
       
   618    Disconnecting state.
       
   619    
       
   620    Here the remote end has shut down the DLCI, but we have still got
       
   621    data to send up to the socket.  We wait for the data to drain
       
   622    before calling Disconnect().  If the client tries to write, we
       
   623    immediately signal Disconnect() as we are no longer able to write.
       
   624    After Disconnect() we move to state closed.
       
   625    
       
   626    In this state we are not associated with a mux, as we no longer
       
   627    want events from the link.
       
   628    
       
   629    Private
       
   630 **/
       
   631 NONSHARABLE_CLASS(TRfcommStateDisconnecting) : public TRfcommStateDefault
       
   632 	{
       
   633 public:
       
   634 	TRfcommStateDisconnecting(CRfcommStateFactory& aFactory);
       
   635 
       
   636 	void Enter(CRfcommSAP& aSAP);
       
   637 	void Shutdown(CRfcommSAP& aSAP);
       
   638 	void FastShutdown(CRfcommSAP& aSAP);
       
   639 	TInt Send(CRfcommSAP& aSAP, const TDesC8& aData);
       
   640 	void Read(CRfcommSAP& aSAP, TDesC8& aData);
       
   641 	void Ioctl(CRfcommSAP& aSAP,TUint aLevel,TUint aName,TDes8* aOption);
       
   642 	void NotifyNewDataCallback(CRfcommSAP& aSAP);
       
   643 	
       
   644 private:
       
   645 	};
       
   646 
       
   647 
       
   648 #include "rfcommstates.inl"
       
   649 #endif
       
   650