bluetooth/btstack/l2cap/l2sapstates.h
changeset 0 29b1cd4cb562
child 48 22de2e391156
equal deleted inserted replaced
-1:000000000000 0:29b1cd4cb562
       
     1 // Copyright (c) 1999-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 // Defines classes to implement each state a L2CAP sap can
       
    15 // be in.
       
    16 // Note we assume for all states that the socket will only send us
       
    17 // reasonable state change requests - i.e. it won't call PassiveOpen
       
    18 // on a connected socket.  We make no such assumption about events
       
    19 // coming from the Mux
       
    20 // 
       
    21 //
       
    22 
       
    23 
       
    24 #ifndef L2CAPSAPSTATES_H
       
    25 #define L2CAPSAPSTATES_H
       
    26 
       
    27 #include <e32base.h>
       
    28 #include <es_prot.h>
       
    29 #include <bt_sock.h>
       
    30 
       
    31 
       
    32 #include "L2CapChannelConfig.h"
       
    33 #include "L2types.h"
       
    34 
       
    35 class CL2CAPConnectionSAP;
       
    36 class CL2CAPSAPStateFactory;
       
    37 
       
    38 class CL2CAPMux;
       
    39 
       
    40 NONSHARABLE_CLASS(TL2CAPSAPState)
       
    41 	{
       
    42 public:
       
    43 	friend class CL2CAPConnectionSAP;
       
    44 
       
    45 	TL2CAPSAPState(CL2CAPSAPStateFactory& aFactory);
       
    46 
       
    47 	
       
    48 	// Events called from the SAP.  As we assume that the socket
       
    49 	// will never send us requests which are invalid for our state,
       
    50 	// the default is to do nothing.  Derived state classes can then
       
    51 	// simply implement the appropriate bits.
       
    52 	virtual void Start(CL2CAPConnectionSAP& aSAP) const;
       
    53 
       
    54 	virtual TInt Ioctl(CL2CAPConnectionSAP& aSAP, TUint aLevel, TUint aName, TDes8* aOption) const;
       
    55 	virtual void CancelIoctl(CL2CAPConnectionSAP& aSAP, TUint aLevel, TUint aName) const;
       
    56 	virtual void IoctlComplete(CL2CAPConnectionSAP& aSAP, TInt aErr, TUint aLevel, TUint aName, TDesC8* aBuf) const;
       
    57 
       
    58 	virtual void ActiveOpen(CL2CAPConnectionSAP& aSAP) const;
       
    59 	virtual TInt PassiveOpen(CL2CAPConnectionSAP& aSAP, TUint aQueSize) const;
       
    60 	virtual void Shutdown(CL2CAPConnectionSAP& aSAP) const;
       
    61 	virtual void FastShutdown(CL2CAPConnectionSAP& aSAP) const;
       
    62 	
       
    63 	virtual TInt Send(CL2CAPConnectionSAP& aSAP, RMBufChain& aData, TUint aFlag) const;
       
    64 	virtual TInt Read(CL2CAPConnectionSAP& aSAP, RMBufChain& aData) const;
       
    65 
       
    66 	virtual void Bound(CL2CAPConnectionSAP& aSAP) const;
       
    67 	
       
    68 	// Events called from the SAP Signal Handler.
       
    69 	virtual void ChannelConfigured(CL2CAPConnectionSAP& aSAP,
       
    70 	                               CL2CapChannelConfig& aConfig,
       
    71                                    CL2CAPMux& aMuxer,
       
    72                                    TL2CAPPort aLocalPort,
       
    73                                    TL2CAPPort aRemotePort);
       
    74                                        
       
    75 	virtual void ReconfiguringChannel(CL2CAPConnectionSAP& aSAP) const;
       
    76 
       
    77 	virtual void ChannelClosed(CL2CAPConnectionSAP& aSAP) const;
       
    78 	virtual void CloseOutgoingSDUQueue(CL2CAPConnectionSAP& aSAP) const;
       
    79 	virtual void SignalHandlerError(CL2CAPConnectionSAP& aSAP, TInt aErrorCode, MSocketNotify::TOperationBitmasks aErrorAction) const;
       
    80 	virtual void LinkUp(CL2CAPConnectionSAP& aSAP) const;
       
    81 	virtual void ChannelOpened(CL2CAPConnectionSAP& aSAP) const;
       
    82 
       
    83 	// Events called from the Data Controller.
       
    84 	virtual void NewData(CL2CAPConnectionSAP& aSAP) const;
       
    85 	virtual TInt NewDataAsyncCallBack(CL2CAPConnectionSAP& aSAP) const;
       
    86 	virtual void CanSend(CL2CAPConnectionSAP& aSAP) const;
       
    87 	virtual void SDUQueueClosed(CL2CAPConnectionSAP& aSAP) const;
       
    88 	virtual void DataPlaneError(CL2CAPConnectionSAP& aSAP, TInt aErrorCode, MSocketNotify::TOperationBitmasks aErrorAction) const;
       
    89 
       
    90 	// Events from the security manager.
       
    91 	virtual void AccessRequestComplete(CL2CAPConnectionSAP& aSignalHandler, TInt aResult) const;
       
    92 	
       
    93 	// State Transition Actions.
       
    94 	virtual void Enter(CL2CAPConnectionSAP& aSAP) const;
       
    95 	virtual void Exit(CL2CAPConnectionSAP& aSAP) const;
       
    96 	
       
    97 	// Helper function.
       
    98 	void NotifySocketClosed(CL2CAPConnectionSAP& aSAP) const;
       
    99 
       
   100 protected:
       
   101 	void StartCalledWhileDisconnected(CL2CAPConnectionSAP& aSAP) const;
       
   102 	void PanicInState(TL2CAPPanic aPanic) const;
       
   103 	void DebugPanicInState(TL2CAPPanic aPanic) const;
       
   104 	
       
   105 protected:
       
   106 	CL2CAPSAPStateFactory& iFactory;  // Used to get next state.
       
   107 
       
   108 private:
       
   109     // Forbid copying
       
   110 	TL2CAPSAPState(const TL2CAPSAPState&);
       
   111 	const TL2CAPSAPState& operator=(const TL2CAPSAPState&) const;
       
   112 	};
       
   113 
       
   114 
       
   115 
       
   116 
       
   117 /**
       
   118    The CLOSED state.
       
   119 
       
   120    This is the state that newly created saps start in, and the state
       
   121    they end in after a communication has closed down or a connection
       
   122    failed.
       
   123 
       
   124    Basically this is a quiescent state from which the sap can go to
       
   125    different futures.
       
   126 **/
       
   127 
       
   128 NONSHARABLE_CLASS(TL2CAPSAPStateClosed) : public TL2CAPSAPState
       
   129 	{
       
   130 public:
       
   131 	TL2CAPSAPStateClosed(CL2CAPSAPStateFactory& aFactory);
       
   132 
       
   133 	// Events called from the SAP.
       
   134 	void Start(CL2CAPConnectionSAP& aSAP) const;
       
   135 	void FastShutdown(CL2CAPConnectionSAP& aSAP) const;
       
   136 	void Shutdown(CL2CAPConnectionSAP& aSAP) const;
       
   137 	
       
   138 	void ActiveOpen(CL2CAPConnectionSAP& aSAP) const;
       
   139 	void SDUQueueClosed(CL2CAPConnectionSAP& aSAP) const;
       
   140 
       
   141 	void Bound(CL2CAPConnectionSAP& aSAP) const;
       
   142 	
       
   143 	// Events called from the SAP Signal Handler.
       
   144 	void ChannelClosed(CL2CAPConnectionSAP& aSAP) const;
       
   145  	void SignalHandlerError(CL2CAPConnectionSAP& aSAP, TInt aErrorCode, MSocketNotify::TOperationBitmasks aErrorAction) const;
       
   146 	
       
   147 	// Events called from the Data Controller.
       
   148 	TInt NewDataAsyncCallBack(CL2CAPConnectionSAP& aSAP) const;
       
   149 		
       
   150 	// State Transition Actions.
       
   151 	void Enter(CL2CAPConnectionSAP& aSAP) const;
       
   152 	};
       
   153 
       
   154 NONSHARABLE_CLASS(TL2CAPSAPStateChannelPendingBase) : public TL2CAPSAPState
       
   155  	{
       
   156 public:
       
   157 	TL2CAPSAPStateChannelPendingBase(CL2CAPSAPStateFactory& aFactory);	
       
   158 
       
   159 	// Events called from the SAP.
       
   160 	virtual void FastShutdown(CL2CAPConnectionSAP& aSAP) const;
       
   161 	virtual void Shutdown(CL2CAPConnectionSAP& aSAP) const;
       
   162 
       
   163 	// Events called from the SAP Signal Handler.
       
   164 	virtual void ChannelClosed(CL2CAPConnectionSAP& aSAP) const;
       
   165  	virtual void SignalHandlerError(CL2CAPConnectionSAP& aSAP, TInt aErrorCode, MSocketNotify::TOperationBitmasks aErrorAction) const;
       
   166  	};
       
   167  	
       
   168 NONSHARABLE_CLASS(TL2CAPSAPStatePassiveLinkPending) : public TL2CAPSAPStateChannelPendingBase
       
   169  	{
       
   170 public:
       
   171 	TL2CAPSAPStatePassiveLinkPending(CL2CAPSAPStateFactory& aFactory);	
       
   172 
       
   173 	// Events called from the SAP Signal Handler.
       
   174 	void LinkUp(CL2CAPConnectionSAP& aSAP) const;
       
   175  	};
       
   176 
       
   177 NONSHARABLE_CLASS(TL2CAPSAPStateActiveLinkPending) : public TL2CAPSAPStateChannelPendingBase
       
   178  	{
       
   179 public:
       
   180 	TL2CAPSAPStateActiveLinkPending(CL2CAPSAPStateFactory& aFactory);	
       
   181 
       
   182 	// Events called from the SAP Signal Handler.
       
   183 	void LinkUp(CL2CAPConnectionSAP& aSAP) const;
       
   184  	};
       
   185 
       
   186 NONSHARABLE_CLASS(TL2CAPSAPStateActiveSecMode4AccessRequestPending) : public TL2CAPSAPStateChannelPendingBase
       
   187 	{
       
   188 public:
       
   189 	TL2CAPSAPStateActiveSecMode4AccessRequestPending(CL2CAPSAPStateFactory& aFactory);
       
   190 	
       
   191 	// Events called from the SAP.
       
   192 	void FastShutdown(CL2CAPConnectionSAP& aSAP) const;
       
   193 	void Shutdown(CL2CAPConnectionSAP& aSAP) const;
       
   194 
       
   195 	// Events called from the SAP Signal Handler.
       
   196 	void ChannelClosed(CL2CAPConnectionSAP& aSAP) const;
       
   197  	void SignalHandlerError(CL2CAPConnectionSAP& aSAP, TInt aErrorCode, MSocketNotify::TOperationBitmasks aErrorAction) const;
       
   198 	
       
   199 	void AccessRequestComplete(CL2CAPConnectionSAP& aSignalHandler, TInt aResult) const;
       
   200 	};
       
   201 
       
   202 NONSHARABLE_CLASS(TL2CAPSAPStateActiveChannelRequestPending) : public TL2CAPSAPStateChannelPendingBase
       
   203 	{
       
   204 public:
       
   205 	TL2CAPSAPStateActiveChannelRequestPending(CL2CAPSAPStateFactory& aFactory);
       
   206 	
       
   207 	// Events called from the SAP Signal Handler.
       
   208 	void ChannelOpened(CL2CAPConnectionSAP& aSAP) const;
       
   209 	};
       
   210 
       
   211 NONSHARABLE_CLASS(TL2CAPSAPStatePassiveAccessRequestPending) : public TL2CAPSAPStateChannelPendingBase
       
   212  	{
       
   213 public:
       
   214 	TL2CAPSAPStatePassiveAccessRequestPending(CL2CAPSAPStateFactory& aFactory);	
       
   215 
       
   216 	// Events called from the SAP.
       
   217 	void FastShutdown(CL2CAPConnectionSAP& aSAP) const;
       
   218 	void Shutdown(CL2CAPConnectionSAP& aSAP) const;
       
   219 
       
   220 	// Events called from the SAP Signal Handler.
       
   221 	void ChannelClosed(CL2CAPConnectionSAP& aSAP) const;
       
   222  	void SignalHandlerError(CL2CAPConnectionSAP& aSAP, TInt aErrorCode, MSocketNotify::TOperationBitmasks aErrorAction) const;
       
   223 
       
   224 	// Events from the security manager.
       
   225 	void AccessRequestComplete(CL2CAPConnectionSAP& aSignalHandler, TInt aResult) const;
       
   226  	};
       
   227 
       
   228 NONSHARABLE_CLASS(TL2CAPSAPStateActiveSecMode2AccessRequestPending) : public TL2CAPSAPStateChannelPendingBase
       
   229  	{
       
   230 public:
       
   231 	TL2CAPSAPStateActiveSecMode2AccessRequestPending(CL2CAPSAPStateFactory& aFactory);	
       
   232 
       
   233 	// Events called from the SAP.
       
   234 	void FastShutdown(CL2CAPConnectionSAP& aSAP) const;
       
   235 	void Shutdown(CL2CAPConnectionSAP& aSAP) const;
       
   236 
       
   237 	// Events called from the SAP Signal Handler.
       
   238 	void ChannelClosed(CL2CAPConnectionSAP& aSAP) const;
       
   239  	void SignalHandlerError(CL2CAPConnectionSAP& aSAP, TInt aErrorCode, MSocketNotify::TOperationBitmasks aErrorAction) const;
       
   240 
       
   241 	// Events from the security manager.
       
   242 	void AccessRequestComplete(CL2CAPConnectionSAP& aSignalHandler, TInt aResult) const;
       
   243  	};
       
   244 
       
   245 
       
   246 NONSHARABLE_CLASS(TL2CAPSAPStatePendingOpen) : public TL2CAPSAPStateChannelPendingBase
       
   247 	{
       
   248 public:
       
   249 	TL2CAPSAPStatePendingOpen(CL2CAPSAPStateFactory& aFactory);
       
   250 
       
   251 	// Events called from the SAP Signal Handler.
       
   252 	void ChannelConfigured(CL2CAPConnectionSAP& aSAP,
       
   253 	                       CL2CapChannelConfig& aConfig,
       
   254                            CL2CAPMux& aMuxer,
       
   255                            TL2CAPPort aLocalPort,
       
   256                            TL2CAPPort aRemotePort);
       
   257 
       
   258 	// Events called from the Data Controller.
       
   259 	void DataPlaneError(CL2CAPConnectionSAP& aSAP, TInt aErrorCode, MSocketNotify::TOperationBitmasks aErrorAction) const;	
       
   260 
       
   261 	// State Transition Actions.
       
   262 	};
       
   263 
       
   264 
       
   265 NONSHARABLE_CLASS(TL2CAPSAPStateListening) : public TL2CAPSAPState
       
   266 	{
       
   267 public:
       
   268 	TL2CAPSAPStateListening(CL2CAPSAPStateFactory& aFactory);
       
   269 
       
   270 	// Events called from the SAP.
       
   271 	void Shutdown(CL2CAPConnectionSAP& aSAP) const;
       
   272 	void FastShutdown(CL2CAPConnectionSAP& aSAP) const;
       
   273 	
       
   274 	// Events called from the SAP Signal Handler.
       
   275 	void ChannelClosed(CL2CAPConnectionSAP& aSAP) const;
       
   276 
       
   277 	// Events called from the Data Controller.
       
   278 	
       
   279 	// State Transition Actions.
       
   280 	void Enter(CL2CAPConnectionSAP& aSAP) const;
       
   281 	void Exit(CL2CAPConnectionSAP& aSAP) const;	
       
   282 	};
       
   283 
       
   284 
       
   285 NONSHARABLE_CLASS(TL2CAPSAPStateOpen) : public TL2CAPSAPState
       
   286 	{
       
   287 public:
       
   288 	TL2CAPSAPStateOpen(CL2CAPSAPStateFactory& aFactory);
       
   289 
       
   290 	// Events called from the SAP.
       
   291 	virtual TInt Send(CL2CAPConnectionSAP& aSAP, RMBufChain& aData, TUint aFlag) const;
       
   292 	virtual TInt Read(CL2CAPConnectionSAP& aSAP, RMBufChain& aData) const;
       
   293 
       
   294 	virtual void Shutdown(CL2CAPConnectionSAP& aSAP) const;
       
   295 	virtual void FastShutdown(CL2CAPConnectionSAP& aSAP) const;
       
   296 	
       
   297 	// Events called from the SAP Signal Handler.
       
   298 	virtual void ReconfiguringChannel(CL2CAPConnectionSAP& aSAP) const;
       
   299 	virtual void ChannelConfigured(CL2CAPConnectionSAP& aSAP,
       
   300 	                       		   CL2CapChannelConfig& aConfig,
       
   301                                    CL2CAPMux& aMuxer,
       
   302                                    TL2CAPPort aLocalPort,
       
   303                                    TL2CAPPort aRemotePort);
       
   304 	virtual void SignalHandlerError(CL2CAPConnectionSAP& aSAP, TInt aErrorCode, MSocketNotify::TOperationBitmasks aErrorAction) const;
       
   305 	virtual void ChannelClosed(CL2CAPConnectionSAP& aSAP) const;
       
   306 	virtual void CloseOutgoingSDUQueue(CL2CAPConnectionSAP& aSAP) const;
       
   307 
       
   308 	// Events called from the Data Controller.
       
   309 	virtual void NewData(CL2CAPConnectionSAP& aSAP) const;
       
   310 	virtual TInt NewDataAsyncCallBack(CL2CAPConnectionSAP& aSAP) const;
       
   311 	virtual void CanSend(CL2CAPConnectionSAP& aSAP) const;
       
   312 	virtual void DataPlaneError(CL2CAPConnectionSAP& aSAP, TInt aErrorCode, MSocketNotify::TOperationBitmasks aErrorAction) const;	
       
   313 	
       
   314 	// State Transition Actions.
       
   315 	};
       
   316 
       
   317 NONSHARABLE_CLASS(TL2CAPSAPStateAccepting) : public TL2CAPSAPStateOpen
       
   318 	{
       
   319 public:
       
   320 	TL2CAPSAPStateAccepting(CL2CAPSAPStateFactory& aFactory);
       
   321 
       
   322 	// Events called from the SAP.
       
   323 	void Start(CL2CAPConnectionSAP& aSAP) const;
       
   324 	void NewData(CL2CAPConnectionSAP& aSAP) const;
       
   325 	
       
   326 	// Events called from the SAP Signal Handler.
       
   327 	void ReconfiguringChannel(CL2CAPConnectionSAP& aSAP) const;
       
   328 	
       
   329 	// Events called from the Data Controller.
       
   330 	TInt NewDataAsyncCallBack(CL2CAPConnectionSAP& aSAP) const;
       
   331 	void CanSend(CL2CAPConnectionSAP& aSAP) const;
       
   332 	
       
   333 	// State Transition Actions.
       
   334 	void Exit(CL2CAPConnectionSAP& aSAP) const;	
       
   335 	};
       
   336 
       
   337 /**
       
   338 This state exists to determine if the other side believes the link is opened.
       
   339 It won't send us data until it has finished configuring the channel.  On
       
   340 reception of data the Signal Handler will be informed before moving the state
       
   341 machine on to fully open.
       
   342 */
       
   343 NONSHARABLE_CLASS(TL2CAPSAPStateAwaitingInitialData) : public TL2CAPSAPStateOpen
       
   344 	{
       
   345 public:
       
   346 	TL2CAPSAPStateAwaitingInitialData(CL2CAPSAPStateFactory& aFactory);
       
   347 	
       
   348 	// Events called from the SAP Signal Handler.
       
   349 	void ReconfiguringChannel(CL2CAPConnectionSAP& aSAP) const;
       
   350 
       
   351 	// Events called from the Data Controller.
       
   352 	void NewData(CL2CAPConnectionSAP& aSAP) const;
       
   353 	};
       
   354 
       
   355 NONSHARABLE_CLASS(TL2CAPSAPStateDisconnecting) : public TL2CAPSAPState
       
   356 	{
       
   357 public:
       
   358 	TL2CAPSAPStateDisconnecting(CL2CAPSAPStateFactory& aFactory);
       
   359 
       
   360 	// Events called from the SAP.
       
   361 	void Start(CL2CAPConnectionSAP& aSAP) const;
       
   362 	TInt Send(CL2CAPConnectionSAP& aSAP, RMBufChain& aData, TUint aFlag) const;
       
   363 	TInt Read(CL2CAPConnectionSAP& aSAP, RMBufChain& aData) const;
       
   364 
       
   365 	void Shutdown(CL2CAPConnectionSAP& aSAP) const;
       
   366 	void FastShutdown(CL2CAPConnectionSAP& aSAP) const;
       
   367 
       
   368 	
       
   369 	// Events called from the SAP Signal Handler.
       
   370 	void ChannelConfigured(CL2CAPConnectionSAP& aSAP,
       
   371 						   CL2CapChannelConfig& aConfig,
       
   372 						   CL2CAPMux& aMuxer,
       
   373 						   TL2CAPPort aLocalPort,
       
   374 						   TL2CAPPort aRemotePort);
       
   375 
       
   376 	void ReconfiguringChannel(CL2CAPConnectionSAP& aSAP) const;
       
   377 
       
   378 	void SignalHandlerError(CL2CAPConnectionSAP& aSAP, TInt aErrorCode, MSocketNotify::TOperationBitmasks aErrorAction) const;
       
   379 	void ChannelClosed(CL2CAPConnectionSAP& aSAP) const;
       
   380 	void CloseOutgoingSDUQueue(CL2CAPConnectionSAP& aSAP) const;
       
   381 	
       
   382 	// Events called from the Data Controller.
       
   383 	void SDUQueueClosed(CL2CAPConnectionSAP& aSAP) const;
       
   384 	void NewData(CL2CAPConnectionSAP& aSAP) const;
       
   385 	TInt NewDataAsyncCallBack(CL2CAPConnectionSAP& aSAP) const;
       
   386 	void CanSend(CL2CAPConnectionSAP& aSAP) const;
       
   387 	void DataPlaneError(CL2CAPConnectionSAP& aSAP, TInt aErrorCode, MSocketNotify::TOperationBitmasks aErrorAction) const;	
       
   388 	
       
   389 	// State Transition Actions.
       
   390 	};
       
   391 
       
   392 
       
   393 NONSHARABLE_CLASS(TL2CAPSAPStateError) : public TL2CAPSAPState
       
   394 	{
       
   395 public:
       
   396 	TL2CAPSAPStateError(CL2CAPSAPStateFactory& aFactory);
       
   397 
       
   398 	// Events called from the SAP.
       
   399 	void Start(CL2CAPConnectionSAP& aSAP) const;
       
   400 
       
   401 	TInt Ioctl(CL2CAPConnectionSAP& aSAP, TUint aLevel, TUint aName, TDes8* aOption) const;
       
   402 	void CancelIoctl(CL2CAPConnectionSAP& aSAP, TUint aLevel, TUint aName) const;
       
   403 	void IoctlComplete(CL2CAPConnectionSAP& aSAP, TInt aErr, TUint aLevel, TUint aName, TDesC8* aBuf) const;
       
   404 
       
   405 	void ActiveOpen(CL2CAPConnectionSAP& aSAP) const;
       
   406 	TInt PassiveOpen(CL2CAPConnectionSAP& aSAP, TUint aQueSize) const;
       
   407 	void Shutdown(CL2CAPConnectionSAP& aSAP) const;
       
   408 	void FastShutdown(CL2CAPConnectionSAP& aSAP) const;
       
   409 	
       
   410 	TInt Send(CL2CAPConnectionSAP& aSAP, RMBufChain& aData, TUint aFlag) const;
       
   411 	TInt Read(CL2CAPConnectionSAP& aSAP, RMBufChain& aData) const;
       
   412 
       
   413 	// Events called from the SAP Signal Handler.
       
   414 	void ChannelClosed(CL2CAPConnectionSAP& aSAP) const;
       
   415 
       
   416 	// State Transition Actions.
       
   417 	void Enter(CL2CAPConnectionSAP& aSAP) const;	
       
   418 	};
       
   419 
       
   420 /**
       
   421    The BOUND state.
       
   422 
       
   423    This is the state that freshly bound saps are in. This state should 
       
   424    only be reached once for each sap since ESOCK doesn't allow rebinding 
       
   425    or unbinding of saps. 
       
   426 
       
   427    A sap can be bound from an ESOCK point of view but not be in this state.
       
   428    Then the sap will either be on the listening path or Closed.
       
   429 **/
       
   430 
       
   431 NONSHARABLE_CLASS(TL2CAPSAPStateBound) : public TL2CAPSAPState
       
   432 	{
       
   433 public:
       
   434 	TL2CAPSAPStateBound(CL2CAPSAPStateFactory& aFactory);
       
   435 
       
   436 	// Events called from the SAP.
       
   437 	TInt PassiveOpen(CL2CAPConnectionSAP& aSAP, TUint aQueSize) const;	
       
   438 	void Shutdown(CL2CAPConnectionSAP& aSAP) const;
       
   439 	void FastShutdown(CL2CAPConnectionSAP& aSAP) const;
       
   440 
       
   441 	// State Transition Actions.
       
   442 	void Enter(CL2CAPConnectionSAP& aSAP) const;
       
   443 	void Exit(CL2CAPConnectionSAP& aSAP) const;	
       
   444 	};
       
   445 	
       
   446 
       
   447 NONSHARABLE_CLASS(CL2CAPSAPStateFactory) : public CBase
       
   448 	{
       
   449 friend class CL2CAPProtocol;	
       
   450 public:
       
   451 	enum TStates
       
   452 		{
       
   453 		EClosed = 0,
       
   454 		EPassiveLinkPending,
       
   455 		EActiveLinkPending,
       
   456 		EPassiveAccessRequestPending,
       
   457 		EActiveSecMode2AccessRequestPending,
       
   458 		EPendingOpen,
       
   459 		EListening,
       
   460 		EAccepting,
       
   461 		EAwaitingInitialData,
       
   462 		EOpen,
       
   463 		EDisconnecting,
       
   464 		EError,
       
   465 		EBound,
       
   466 		EActiveSecMode4AccessRequestPending,
       
   467 		EActiveChannelRequestPending,
       
   468 		EMaxState,
       
   469 		};
       
   470 	
       
   471 	TL2CAPSAPState& GetState(const TStates aState) const;
       
   472 	TInt StateIndex(const TL2CAPSAPState* aState) const;
       
   473 
       
   474 	~CL2CAPSAPStateFactory();
       
   475 
       
   476 private:
       
   477 	static CL2CAPSAPStateFactory* NewL();
       
   478 	CL2CAPSAPStateFactory();
       
   479 
       
   480 	TFixedArray<TL2CAPSAPState*, EMaxState> iStates;
       
   481 	};
       
   482 
       
   483 	
       
   484 #endif