bluetoothcommsprofiles/btpan/panagt/panagt.h
changeset 0 29b1cd4cb562
equal deleted inserted replaced
-1:000000000000 0:29b1cd4cb562
       
     1 // Copyright (c) 2004-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 PANAGT_H
       
    17 #define PANAGT_H
       
    18 
       
    19 /**
       
    20 @file
       
    21 @note PAN agent agent class definitions and global constants
       
    22 @internalComponent
       
    23 */
       
    24 
       
    25 #include <comms-infras/cagentbase.h>
       
    26 #include <comms-infras/eintsock.h>
       
    27 #include <panprog.h>
       
    28 #include <panerr.h>
       
    29 #include <bt_sock.h>
       
    30 #include "pancommon.h"
       
    31 #include "panagtincoming.h"
       
    32 #include "panagtremdevselector.h"
       
    33 #include "panagtutils.h"
       
    34 #include "pancoexistenceconnectioncontroller.h"
       
    35 
       
    36 using namespace PanHelper;
       
    37 
       
    38 #ifdef SYMBIAN_NON_SEAMLESS_NETWORK_BEARER_MOBILITY
       
    39 #include <elements/nm_node.h>
       
    40 #include <comms-infras/ss_common.h>
       
    41 class CPanProvisionInfo;
       
    42 #endif
       
    43 
       
    44 namespace PanAgent
       
    45 /**
       
    46 @internalComponent
       
    47 @released
       
    48 @since v8.1
       
    49 */
       
    50 {
       
    51 
       
    52 const TUint KMajorVersionNumber = 1;
       
    53 const TUint KMinorVersionNumber = 0;
       
    54 const TUint KBuildVersionNumber = 0;
       
    55 
       
    56 /** 
       
    57 Priority of active objects in the PAN agent (mainly the state machine(s) and callbacks)
       
    58 @internalComponent
       
    59 @released
       
    60 @see KPanAgtAoRemoteDevicePromptPriority
       
    61 */
       
    62 const TInt KPanAgtAoPriority = CActive::EPriorityStandard; 
       
    63 
       
    64 const TUint KPanAgtConnectionRetryAttempts = 1;
       
    65 
       
    66 NONSHARABLE_CLASS(CPanAgentFactory) : public CNifAgentFactory
       
    67 /**
       
    68 Create instances of the PAN agent
       
    69 @internalComponent
       
    70 */
       
    71 	{
       
    72 protected:
       
    73 	void InstallL();
       
    74 	CNifAgentBase* NewAgentL(const TDesC& aName);
       
    75 	TInt Info(TNifAgentInfo& aInfo, TInt aIndex) const;
       
    76 	};
       
    77 
       
    78 //
       
    79 // Connection management objects
       
    80 //
       
    81 
       
    82 //
       
    83 // Interface for upcalls from remote device management objects
       
    84 //
       
    85 class CPanRemoteDeviceStateMachine;
       
    86 
       
    87 class MRemoteDeviceNotify
       
    88 /**
       
    89 Upcalls from CPanRemoteDeviceStateMachine
       
    90 @internalComponent
       
    91 */
       
    92 	{
       
    93 public:
       
    94 	/**
       
    95 	Call to initiate an outgoing PAN connection from the remote device state machine.
       
    96 	@param aLocalRole The local role will be decided by the PAN agent state machine logic.  
       
    97 	                  No value should be passed into this method call for this parameter.
       
    98 	                  When this method returns with KErrNone this value will contain the local role to connect to.
       
    99 	@param aRemoteRole The remote role will be decided by the PAN agent state machine logic.
       
   100 	                  No value should be passed into this method call for this parameter
       
   101 	                  When this method returns with KErrNone this value will contain the remote role to connect to.
       
   102 	@param aWorthTryingRemoteRoles This is a list of the remote PAN roles that are worth trying to connect to this device.
       
   103 	@return A system wide or PAN agnet specific error code indicating if the connection should continue
       
   104 	*/
       
   105 	virtual TInt InitiateOutgoingConnection(TBluetoothPanRole& aLocalRole, TBluetoothPanRole& aRemoteRole, TPanDeviceWorthTryingRolesList& aWorthTryingRemoteRoles) = 0;
       
   106 
       
   107 	/**
       
   108 	Call to initiate an outgoing role change with an existing remote device from the remote device state machine.
       
   109 	@param aLocalRole The local role will be decided by the PAN agent state machine logic.  
       
   110 	                  No value should be passed into this method call for this parameter.
       
   111 	                  When this method returns with KErrNone this value will contain the local role to connect to.
       
   112 	@param aRemoteRole The remote role will be decided by the PAN agent state machine logic.
       
   113 	                  No value should be passed into this method call for this parameter
       
   114 	                  When this method returns with KErrNone this value will contain the remote role to connect to.
       
   115 	@return A system wide or PAN agnet specific error code indicating if the role change procedure should continue
       
   116 	*/
       
   117 	virtual TInt PerformLocalRoleChangeRequest(TBluetoothPanRole& aLocalRole, TBluetoothPanRole& aRemoteRole) = 0;
       
   118 
       
   119 	/**
       
   120 	Called from the remote device state machine when it has received a role change request from the peer device.
       
   121 	@param aLocalRole The requested local role from the peer BNEP Setup Request.  
       
   122 	@param aRemoteRole The requested remote role from the peer BNEP Setup Request.  
       
   123 	@return A system wide or PAN agnet specific error code indicating if the role change procedure should continue.
       
   124 	*/
       
   125 	virtual TInt RoleChangeRequestFromPeer(TBluetoothPanRole aLocalRole, TBluetoothPanRole aRemoteRole) = 0;
       
   126 
       
   127 	/**
       
   128 	Called from the remote device state machine when it has received a incoming connection request from a peer device.
       
   129 	@param aLocalRole The requested local role from the peer BNEP Setup Request.  
       
   130 	@param aRemoteRole The requested remote role from the peer BNEP Setup Request.  
       
   131 	@return A system wide or PAN agnet specific error code indicating if the incoming connection request should be accepted.
       
   132 	*/
       
   133 	virtual TInt IncomingConnectionFromPeer(TBluetoothPanRole aLocalRole, TBluetoothPanRole aRemoteRole) = 0;
       
   134 
       
   135 	/**
       
   136 	PAN role with the remote device has completed successfully
       
   137 	@pre This should follow a call to RoleRequest
       
   138 	@param aNewDevice The class managing the device which is now active in the PAN
       
   139 	*/
       
   140 	virtual void DeviceActive(CPanRemoteDeviceStateMachine& aNewDevice) = 0;
       
   141 	
       
   142 	/**
       
   143 	The attempt to switch roles failed
       
   144 	@note This should only be called by devices marked as negotiating
       
   145 	@param aDevice The class managing the device which completed the remote connection
       
   146 	*/
       
   147 	virtual void DeviceRoleChangeFailed(CPanRemoteDeviceStateMachine& aDevice) = 0;
       
   148 
       
   149 	/**
       
   150 	BNEP level connection to the remote device has been closed, and all necessary cleanup has been performed
       
   151 	@note This can occur because we couldn't negotiate mutually satifactory PAN roles, or because the device has disconnected (or we disconnected it)
       
   152 	@note This will delete the remote device object from the device array
       
   153 	@param aDevice The class managing the device which completed the remote connection
       
   154 	*/
       
   155 	virtual void DeviceDisconnected(CPanRemoteDeviceStateMachine& aDevice) = 0;
       
   156 	
       
   157 
       
   158 
       
   159 #ifdef SYMBIAN_NON_SEAMLESS_NETWORK_BEARER_MOBILITY
       
   160 	virtual const Messages::TNodeId& BnepConnectionManager() = 0;
       
   161 	
       
   162 	virtual void RestartIncomingConnectionListener(TInt aError) = 0;
       
   163 #else
       
   164 
       
   165 	/**
       
   166 	Get a handle to the BNEP connection manager
       
   167 	@return A reference to the BNEP connection manager
       
   168 	*/
       
   169 	virtual MBnepConnectionManager& BnepConnectionManager() = 0;
       
   170 	
       
   171 	/**
       
   172 	Get a handle to the BNEP link controller
       
   173 	@return A reference to the BNEP link controller
       
   174 	*/
       
   175 	virtual MPanLinkControlBase& BnepConnectionController() = 0;
       
   176 #endif
       
   177 // SYMBIAN_NON_SEAMLESS_NETWORK_BEARER_MOBILITY 
       
   178 	
       
   179 	/**
       
   180 	Retry the connection to the specified device.
       
   181 	@param A reference to the remote device that should be reconnected to.
       
   182 	*/
       
   183 	virtual void SetRetryConnect(CPanRemoteDeviceStateMachine& aDevice) = 0;
       
   184 
       
   185 	/**
       
   186 	Populate the PAN connection list provided as an argument
       
   187 	@param A reference to the PAN connection list contained that should be populated.
       
   188 	*/	
       
   189 	virtual void GetExistingConnections(TPanConnectionList& aPanConnectionList) = 0;
       
   190 
       
   191 	/**
       
   192 	Close existing connection (there can be only zero or one) that has access to the uplink.
       
   193 	THIS SHOULD BE REMOVED WHEN >1 REMOTE DEVICE IS ALLOWED TO ACCESS THE UPLINK.
       
   194 	*/
       
   195 	virtual void CloseExistingConnectionWithUplinkAccess() = 0;
       
   196 	
       
   197 	/**
       
   198 	Check if it is worth trying the connection. If we have a fixed role and this role is not worth trying return EFalse.
       
   199 	@param remote worth trying roles.
       
   200 	*/
       
   201 	virtual TBool WorthTrying(const TPanDeviceWorthTryingRolesList& aRemoteWorthTryingRoles) const= 0;
       
   202 
       
   203 	
       
   204 	
       
   205 protected:
       
   206 	virtual ~MRemoteDeviceNotify()	{};
       
   207 	};	
       
   208 
       
   209 
       
   210 //
       
   211 // Pan agent state machine base classes
       
   212 //
       
   213 
       
   214 class MRemoteDeviceNotifyForState
       
   215 /**
       
   216 A mirror class of MRemoteDeviceNotify, but with leaving versions of the methods to allow easier 
       
   217 error handling for each state. This class should be kept in sync with the methods in MRemoteDeviceNotify,
       
   218 except for simple getter methods, such as BnepConnectionManager, which are merely to allow sharing of
       
   219 handles between the remote device and role state machines.
       
   220 @see MRemoteDeviceNotify
       
   221 @internalComponent
       
   222 */
       
   223 	{
       
   224 public:
       
   225 	/**
       
   226 	@see MRemoteDeviceNotify::InitiateOutgoingConnectionL
       
   227 	*/
       
   228 	virtual void InitiateOutgoingConnectionL(TBluetoothPanRole& aLocalRole, TBluetoothPanRole& aRemoteRole, TPanDeviceWorthTryingRolesList& aWorthTryingRemoteRoles) = 0;
       
   229 
       
   230 	/**
       
   231 	@see MRemoteDeviceNotify::PerformLocalRoleChangeRequestL
       
   232 	*/
       
   233 	virtual void PerformLocalRoleChangeRequestL(TBluetoothPanRole& aLocalRole, TBluetoothPanRole& aRemoteRole) = 0;
       
   234 
       
   235 	/**
       
   236 	@see MRemoteDeviceNotify::RoleChangeRequestFromPeerL
       
   237 	*/
       
   238 	virtual void RoleChangeRequestFromPeerL(TBluetoothPanRole aLocalRole) = 0;
       
   239 
       
   240 	/**
       
   241 	@see MRemoteDeviceNotify::IncomingConnectionFromPeerL
       
   242 	*/
       
   243 	virtual void IncomingConnectionFromPeerL(TBluetoothPanRole aLocalRole) = 0;
       
   244 
       
   245 	/**
       
   246 	@see MRemoteDeviceNotify::DeviceActive
       
   247 	@note Leaving will cause the connection to be shut down
       
   248 	*/
       
   249 	virtual void DeviceActiveL(CPanRemoteDeviceStateMachine& aNewDevice) = 0;
       
   250 
       
   251 	/**
       
   252 	@see MRemoteDeviceNotify::DeviceRoleChangeFailed
       
   253 	@note Leaving will cause the connection to be shut down
       
   254 	*/
       
   255 	virtual void DeviceRoleChangeFailedL(CPanRemoteDeviceStateMachine& aDevice) = 0;
       
   256 
       
   257 	/**
       
   258 	@see MRemoteDeviceNotify::DeviceDisconnected
       
   259 	@note Leaving will cause the connection to be shut down
       
   260 	*/
       
   261 	virtual void DeviceDisconnectedL(CPanRemoteDeviceStateMachine& aDevice) = 0;	
       
   262 	
       
   263 protected:
       
   264 	virtual ~MRemoteDeviceNotifyForState()	{};
       
   265 	};
       
   266 
       
   267 class MPanAgtStateMachineNotify;
       
   268 NONSHARABLE_CLASS(CPanAgtStateBase) : public CBase, public MRemoteDeviceNotifyForState
       
   269 /**
       
   270 Base class for PAN agent states
       
   271 @internalComponent
       
   272 */
       
   273 	{
       
   274 #ifdef SYMBIAN_NON_SEAMLESS_NETWORK_BEARER_MOBILITY
       
   275     friend class CPanAgent;
       
   276 #endif
       
   277 
       
   278 protected:
       
   279 	enum TPanAgtStates
       
   280 		{
       
   281 		EPanAgentStateUninitialised,
       
   282 		EPanAgentStateInitialising,
       
   283 		EPanAgtStateIdle,
       
   284 		EPanAgtStateNegotiatingURole,
       
   285 		EPanAgtStateURole,
       
   286 		EPanAgtStateRenegotiatingActiveConnectionToGnOrNapRoleAtOurBehest,
       
   287 		EPanAgtStateRenegotiatingActiveConnectionToURoleAtPeersBehest,
       
   288 		EPanAgtStateRenegotiatingActiveConnectionToGnOrNapRoleAtPeersBehest,
       
   289 		EPanAgtStateNegotiatingGnOrNapRole,
       
   290 		EPanAgtStateGnOrNapRole,
       
   291 		EPanAgtStateShutdown,
       
   292 		EPanAgtStateReconnect,
       
   293 		
       
   294 #ifdef SYMBIAN_NON_SEAMLESS_NETWORK_BEARER_MOBILITY
       
   295 		EPanAgtStatePaused,
       
   296 #endif
       
   297 		};
       
   298 public:
       
   299 	~CPanAgtStateBase();
       
   300 	// MRemoteDeviceNotify methods (downcalls from state machine)
       
   301 	virtual void InitiateOutgoingConnectionL(TBluetoothPanRole& aLocalRole, TBluetoothPanRole& aRemoteRole, TPanDeviceWorthTryingRolesList& aWorthTryingRemoteRoles);
       
   302 	virtual void PerformLocalRoleChangeRequestL(TBluetoothPanRole& aLocalRole, TBluetoothPanRole& aRemoteRole);
       
   303 	virtual void RoleChangeRequestFromPeerL(TBluetoothPanRole aLocalRole);
       
   304 	virtual void IncomingConnectionFromPeerL(TBluetoothPanRole aLocalRole);
       
   305 
       
   306 	virtual void DeviceActiveL(CPanRemoteDeviceStateMachine& aDevice);
       
   307 	virtual void DeviceRoleChangeFailedL(CPanRemoteDeviceStateMachine& aDevice);
       
   308 	virtual void DeviceDisconnectedL(CPanRemoteDeviceStateMachine& aDevice);
       
   309 
       
   310 	virtual void StateSendRoleNotification(); // overridden for states EPanAgtStateURole and EPanAgtStateGnRole
       
   311 	
       
   312 	/**
       
   313 	Call to make a new state "active" - called when the state is set as the active state in the state machine
       
   314 	@note All states should perform initialisation on this call
       
   315 	*/
       
   316 	virtual void OnEntryL() = 0;
       
   317 	virtual void Connect();
       
   318 	virtual void CancelConnect();
       
   319 	virtual void CancelReconnect();
       
   320 
       
   321 	TInt IsRoleRequestValid(TBluetoothPanRole aRequestedLocalRole, TBluetoothPanRole aRequestedRemoteRole) const;
       
   322 
       
   323 protected:
       
   324 	CPanAgtStateBase(MPanAgtStateMachineNotify& aStateMachine, TPanAgtStates aStateNumber);
       
   325 	
       
   326 	void BaseConstructL();
       
   327 	void StartNegotiationWithFirstPendingDevice();
       
   328 
       
   329 	// methods for standard operations common to many/all states
       
   330 	void DoDeviceDisconnectL(CPanRemoteDeviceStateMachine& aDevice);
       
   331 
       
   332 	// methods for negotiation
       
   333 	TInt SelectRemoteRoleBasedOnLocalRole(TBluetoothPanRole aSelectedLocalRole, TBluetoothPanRole& aRemoteRole, TPanDeviceWorthTryingRolesList& aWorthTryingRemoteRoles);
       
   334 
       
   335 	TInt FindDeviceInArray(const CPanRemoteDeviceStateMachine& aDevice) const;
       
   336 	TInt DeviceCountInState(TRemoteDeviceState aState) const;
       
   337 
       
   338 	// methods for making sure GN and NAP work correctly!
       
   339 	void LockDeviceAsPiconetMasterL();
       
   340 	TInt ReleasePiconetMasterLock();
       
   341 
       
   342 	// methods for ASSERTs
       
   343 	TInt NegotiatingDeviceCount() const;
       
   344 	TInt ActiveDeviceCount() const;
       
   345 	
       
   346 	MPanAgtStateMachineNotify& StateMachine();
       
   347 	const MPanAgtStateMachineNotify& StateMachine() const;
       
   348 
       
   349 	// Methods for SDP registration and listener starting/stopping.
       
   350 	void StartListenerL();
       
   351 	void StopListener();
       
   352 	
       
   353 	void PanicInState(TPanAgentPanic aPanic) const;
       
   354 
       
   355 	// debugging methods
       
   356 #ifdef _DEBUG	
       
   357 	void DumpDeviceArray() const;
       
   358 #endif // _DEBUG
       
   359 private:
       
   360 	static TInt ServiceStartedCb(TAny* aThisPtr);
       
   361 	static TInt ConnectCompleteCb(TAny* aThisPtr);
       
   362 	void ServiceStarted();
       
   363 protected:
       
   364 	CAsyncCallBack* iServiceStartedCallback;
       
   365 	CAsyncCallBack* iConnectCompleteCallback;
       
   366 private:
       
   367 	MPanAgtStateMachineNotify& iStateMachine;
       
   368 	TPanAgtStates iStateNumber;
       
   369 	};
       
   370 
       
   371 class CPanAgentStateShutdown;
       
   372 class CPanHelperLocalSdpRegistrar;	
       
   373 class MPanAgtStateMachineNotify
       
   374 /**
       
   375 Upcalls from PAN agent role states to PAN agent role state machine
       
   376 @internalComponent
       
   377 */
       
   378 	{
       
   379 	friend class CPanAgtStateShutdown; // to ensure that only the shutdown state can call FullShutdownComplete()
       
   380 public:
       
   381 	//
       
   382 	// Accessor methods
       
   383 	//
       
   384 	/**
       
   385 	Get a handle to the device array
       
   386 	@return A handle to the device array
       
   387 	*/
       
   388 	virtual RPointerArray<CPanRemoteDeviceStateMachine>& Devices() = 0;
       
   389 
       
   390 	/**
       
   391 	Get a const handle to the device array
       
   392 	@return A const handle to the device array
       
   393 	*/
       
   394 	virtual const RPointerArray<CPanRemoteDeviceStateMachine>& Devices() const = 0;
       
   395 
       
   396 	/**
       
   397 	Get a handle to the fixed remote role field in the state machine
       
   398 	@note This is not const, so can be used to read or write the field in the state machine
       
   399 	*/
       
   400 	virtual TBluetoothPanRole& FixedLocalRole() = 0;
       
   401 
       
   402 	/**
       
   403 	Get a handle to the fixed remote role field in the state machine
       
   404 	@note This is not const, so can be used to read or write the field in the state machine
       
   405 	*/
       
   406 	virtual TBluetoothPanRole& FixedRemoteRole() = 0;
       
   407 
       
   408 	/**
       
   409 	Check if the agent configured to allow incoming connections
       
   410 	@return ETrue if incoming connections are allowed 
       
   411 	*/
       
   412 	virtual TBool AllowIncoming() const = 0;
       
   413 
       
   414 	/**
       
   415 	Set if the agent configured to allow incoming connections
       
   416 	@param ETrue if incoming connections are allowed 
       
   417 	*/
       
   418 	virtual void SetAllowIncoming(TBool aAllowIncoming) = 0;
       
   419 
       
   420 	/**
       
   421 	Check if the agent configured to allow connections to the local role of NAP
       
   422 	@return ETrue if connections to the local role of NAP are allowed 
       
   423 	*/
       
   424 	virtual TBool NapEnabled() const = 0;
       
   425 
       
   426 	/**
       
   427 	Set if the agent configured to allow connections to the local role of NAP
       
   428 	@param ETrue if connections to the local role of NAP are allowed 
       
   429 	*/
       
   430 	virtual void SetNapEnabled(TBool aNapEnabled) = 0;
       
   431 	
       
   432 	/**
       
   433 	Get the handle to commdb
       
   434 	@return A handle to the comms database
       
   435 	*/
       
   436 	virtual CCommsDbAccess& Database() = 0;
       
   437 
       
   438 	/**
       
   439 	Get the handle to the PAN local SDP registrar
       
   440 	*/
       
   441 	virtual CPanHelperLocalSdpRegistrar& PanLocalSdpRegistrar() = 0;
       
   442 
       
   443 	/**
       
   444 	Return the IAP ID of this connection
       
   445 	*/
       
   446 	virtual TInt IapId() = 0;
       
   447 	
       
   448 	//
       
   449 	// Do-er methods
       
   450 	//
       
   451 	/**
       
   452 	Suppress outgoing connections
       
   453 	*/
       
   454 	virtual void SetSuppressOutgoing() = 0;
       
   455 
       
   456 	/**
       
   457 	Stop outgoing connections being suppressed
       
   458 	*/
       
   459 	virtual void ResetSuppressOutgoing() = 0;
       
   460 
       
   461 	/**
       
   462 	Send a progress notification to clients via nifman
       
   463 	*/
       
   464 	virtual void SendProgress(TInt aProgress, TInt aError) = 0;
       
   465 
       
   466 	/**
       
   467 	Start the incoming connection listener
       
   468 	@return KErrNone if successful, or one of the Symbian standard error codes
       
   469 	*/
       
   470 	virtual TInt StartIncomingConnectionListener() = 0;
       
   471 
       
   472 	/**
       
   473 	Stop and delete the incoming connection listener
       
   474 	*/	
       
   475 	virtual void CloseIncomingConnectionListener() = 0;
       
   476 	
       
   477 	/**
       
   478 	Start the process of setting up any outgoing connections we might need
       
   479 	*/
       
   480 	virtual void SetupOutgoingConnectionsL() = 0;
       
   481 
       
   482 	/**
       
   483 	Forwarding call to Nifman
       
   484 	*/
       
   485 	virtual void ServiceStarted() = 0;
       
   486 	
       
   487 	/**
       
   488 	Forwarding call to Nifman
       
   489 	*/
       
   490 	virtual void ConnectComplete() = 0;
       
   491 	
       
   492 	/**
       
   493 	Forwarding call to Nifman
       
   494 	*/
       
   495 	virtual void ReconnectComplete(TInt aError) = 0;
       
   496 	
       
   497 	//
       
   498 	// Getter methods
       
   499 	//
       
   500 	/**
       
   501 	Find out whether outgoing connections are suppressed
       
   502 	*/
       
   503 	virtual TBool SuppressOutgoing() const = 0;
       
   504 	
       
   505 	/**
       
   506 	Is the incoming connection listener active?
       
   507 	@return Whether the incoming connection listener is enabled (including in pause mode) or not
       
   508 	*/
       
   509 	virtual TBool IsIncomingConnectionListenerEnabled() const = 0;
       
   510 	
       
   511 	/**
       
   512 	Is the user being shown the device selection notifier?
       
   513 	*/
       
   514 	virtual TBool IsPromptingUserForDeviceSelection() const = 0;
       
   515 	
       
   516 	/**
       
   517 	Check whether we're allowed to act as a U (according to commdb settings)
       
   518 	*/
       
   519 	virtual TBool IsUAllowedByFixedLocalRole() const = 0;
       
   520 	
       
   521 	/**
       
   522 	Check whether we're allowed to act as the GN (according to commdb settings)
       
   523 	*/
       
   524 	virtual TBool IsGnAllowedByFixedLocalRole() const = 0;
       
   525 
       
   526 	/**
       
   527 	Check whether we're allowed to act as a NAP (according to commdb settings)
       
   528 	*/
       
   529 	virtual TBool IsNapAllowedByFixedLocalRole() const = 0;
       
   530 
       
   531 	//
       
   532 	// Setter methods
       
   533 	//
       
   534 	/**
       
   535 	Put the state machine into a new state
       
   536 	@param aState The new state
       
   537 	*/
       
   538 	virtual void SetState(CPanAgtStateBase& aState) = 0;
       
   539 	
       
   540 	virtual void HandleAllPanConnectionsClosed() = 0; 
       
   541 	virtual TBool IsNewPanConnectionAllowed() const = 0;
       
   542 	
       
   543 protected:
       
   544 	/**
       
   545 	Inform the state machine that the shutdown state has finished shutting down the remote connections
       
   546 	*/
       
   547 	virtual void FullShutdownComplete() = 0;
       
   548 	
       
   549 	/**
       
   550 	Stop anyone deleting the object through its M-class pointer
       
   551 	*/
       
   552 	virtual ~MPanAgtStateMachineNotify(){};
       
   553 	};
       
   554 
       
   555 class CPanRemoteDeviceSelector;
       
   556 class CPanIncomingConnectionListener;
       
   557 
       
   558 #ifdef SYMBIAN_NON_SEAMLESS_NETWORK_BEARER_MOBILITY
       
   559 NONSHARABLE_CLASS(CPanAgent) : public CAgentBase, public Messages::ASimpleNodeIdBase,
       
   560     public MPanCoexistenceConnectionObserver, private MNifAgentExtendedManagementInterface,
       
   561     private MPanAgtStateMachineNotify, private MRemoteDeviceNotify,
       
   562     private MIncomingConnectionAcceptor, private MOutgoingConnectionCreator
       
   563 
       
   564 #else
       
   565 // !SYMBIAN_NON_SEAMLESS_NETWORK_BEARER_MOBILITY
       
   566 NONSHARABLE_CLASS(CPanAgent) : public CAgentBase,
       
   567     private MNifAgentExtendedManagementInterface,
       
   568     private MPanAgtStateMachineNotify, private MRemoteDeviceNotify,
       
   569     private MIncomingConnectionAcceptor, private MOutgoingConnectionCreator,
       
   570     private MPanLinkControl
       
   571 #endif
       
   572 //SYMBIAN_NON_SEAMLESS_NETWORK_BEARER_MOBILITY
       
   573 /**
       
   574 The core agent class, including PAN role state machine
       
   575 @internalComponent
       
   576 */
       
   577 	{
       
   578 public:
       
   579 	static CPanAgent* NewL();
       
   580 	~CPanAgent();
       
   581 	
       
   582 	// C(Nif)AgentBase methods
       
   583 	virtual TInt Notification(TNifToAgentEventType aEvent, TAny* aInfo);
       
   584 	virtual TInt Control(TUint aOptionLevel, TUint aOptionName, TDes8& aOption);
       
   585 	virtual void Info(TNifAgentInfo& aInfo) const;
       
   586 	virtual void Connect(TAgentConnectType aType);
       
   587 	virtual void Connect(TAgentConnectType aType, CStoreableOverrideSettings* aOverrideSettings);
       
   588 	virtual void CancelConnect();
       
   589 	virtual void Reconnect();
       
   590 	virtual void CancelReconnect();
       
   591 	virtual void Disconnect(TInt aReason);
       
   592 	virtual TInt GetExcessData(TDes8& aDes);
       
   593 	virtual TInt IncomingConnectionReceived();
       
   594 	virtual void GetLastError(TInt& aError);
       
   595 	virtual TBool IsReconnect() const;
       
   596 	
       
   597 	// MPanCoexistenceConnectionObserver
       
   598 	virtual void MpccoPanCoexistenceConnectionUpdated(TIPBearerCoexistenceStatus aStatus); 
       
   599 	
       
   600 	// MNifAgentExtendedManagementInterface methods
       
   601 	virtual TInt GetInterfaceType(TConnectionType& aConnectionType);
       
   602 	virtual TInt EnumerateSubConnections(TUint& aCount);
       
   603 	virtual TInt GetSubConnectionInfo(TUint aIndex, TDes8& aSubConnectionInfo);
       
   604 	virtual TInt GetSubConnectionInfo(TDes8& aSubConnectionInfo);
       
   605 	
       
   606 	// MPanAgtStateMachineNotify methods
       
   607 	virtual RPointerArray<CPanRemoteDeviceStateMachine>& Devices();
       
   608 	virtual const RPointerArray<CPanRemoteDeviceStateMachine>& Devices() const;
       
   609 	virtual TBluetoothPanRole& FixedLocalRole();
       
   610 	virtual TBluetoothPanRole& FixedRemoteRole();
       
   611 	virtual CPanHelperLocalSdpRegistrar& PanLocalSdpRegistrar();	
       
   612 	virtual CCommsDbAccess& Database();
       
   613 	virtual TInt IapId();
       
   614 	virtual TBool SuppressOutgoing() const;
       
   615 	virtual void SetSuppressOutgoing();
       
   616 	virtual void ResetSuppressOutgoing();
       
   617 	virtual void SendProgress(TInt aProgress, TInt aError);
       
   618 	virtual TBool IsIncomingConnectionListenerEnabled() const;
       
   619 	virtual TBool IsPromptingUserForDeviceSelection() const;
       
   620 	virtual TBool IsUAllowedByFixedLocalRole() const;
       
   621 	virtual TBool IsGnAllowedByFixedLocalRole() const;
       
   622 	virtual TBool IsNapAllowedByFixedLocalRole() const;
       
   623 	virtual TInt StartIncomingConnectionListener();
       
   624 	virtual void CloseIncomingConnectionListener();
       
   625 	virtual void SetupOutgoingConnectionsL();
       
   626 	virtual void ServiceStarted();
       
   627 	virtual void ConnectComplete();
       
   628 	virtual void ReconnectComplete(TInt aError);
       
   629 	virtual void SetState(CPanAgtStateBase& aState);
       
   630 	virtual void FullShutdownComplete();
       
   631 	
       
   632 	virtual void HandleAllPanConnectionsClosed();
       
   633 	virtual TBool IsNewPanConnectionAllowed() const;
       
   634 	
       
   635 	// MIncomingConnectionAcceptor methods
       
   636 	virtual void CreateNewConnectionFromIncomingL(RInternalSocket& aConnectedSocket);
       
   637 
       
   638 	// MOutgoingConnectionCreator methods
       
   639 	virtual void CreateNewConnectionForOutgoingL(const TBTDevAddr& aRemDevAddr);
       
   640 	virtual TInt DeviceSelectionError(TInt aErr);
       
   641 
       
   642 	// MRemoteDeviceNotify methods
       
   643 	virtual TInt InitiateOutgoingConnection(TBluetoothPanRole& aLocalRole, TBluetoothPanRole& aRemoteRole, TPanDeviceWorthTryingRolesList& aWorthTryingRemoteRoles);
       
   644 	virtual TInt PerformLocalRoleChangeRequest(TBluetoothPanRole& aLocalRole, TBluetoothPanRole& aRemoteRole);
       
   645 	virtual TInt RoleChangeRequestFromPeer(TBluetoothPanRole aLocalRole, TBluetoothPanRole aRemoteRole);
       
   646 	virtual TInt IncomingConnectionFromPeer(TBluetoothPanRole aLocalRole, TBluetoothPanRole aRemoteRole);
       
   647 
       
   648 	virtual void DeviceActive(CPanRemoteDeviceStateMachine& aDevice);
       
   649 	virtual void DeviceRoleChangeFailed(CPanRemoteDeviceStateMachine& aDevice);
       
   650 	virtual void DeviceDisconnected(CPanRemoteDeviceStateMachine& aDevice);
       
   651 
       
   652 
       
   653 #ifdef SYMBIAN_NON_SEAMLESS_NETWORK_BEARER_MOBILITY
       
   654     virtual const Messages::TNodeId& BnepConnectionManager();
       
   655 	virtual void RestartIncomingConnectionListener(TInt aError);
       
   656 
       
   657 #else
       
   658 // !SYMBIAN_NON_SEAMLESS_NETWORK_BEARER_MOBILITY
       
   659 	virtual MBnepConnectionManager& BnepConnectionManager();
       
   660 	virtual MPanLinkControlBase& BnepConnectionController();
       
   661 #endif
       
   662 // SYMBIAN_NON_SEAMLESS_NETWORK_BEARER_MOBILITY
       
   663 
       
   664 	virtual void SetRetryConnect(CPanRemoteDeviceStateMachine& aDevice);
       
   665 	virtual void GetExistingConnections(TPanConnectionList& aPanConnectionList);
       
   666 	virtual void CloseExistingConnectionWithUplinkAccess();
       
   667 	virtual TBool WorthTrying(const TPanDeviceWorthTryingRolesList& aRemoteWorthTryingRoles) const;
       
   668 	
       
   669 #ifndef SYMBIAN_NON_SEAMLESS_NETWORK_BEARER_MOBILITY
       
   670 	// MPanLinkControl methods
       
   671 	virtual TAny* MplcbGetInterface(const TUid & aInterface);
       
   672 	virtual TInt MplcRequestSniff(const TBTDevAddr &);
       
   673 	virtual TInt MplcRequestActive(const TBTDevAddr &);
       
   674 	
       
   675 	MPanLinkControl* PanLinkControlInterface();
       
   676 #endif	
       
   677 
       
   678 	TBool AllowIncoming() const;
       
   679 	void SetAllowIncoming(TBool aAllowIncoming);
       
   680 
       
   681 	TBool NapEnabled() const;
       
   682 	void SetNapEnabled(TBool aNapEnabled);	
       
   683 
       
   684 #ifdef SYMBIAN_NON_SEAMLESS_NETWORK_BEARER_MOBILITY
       
   685 protected:
       
   686     // From ESock::MCFNode, via ESock::ACFNodeIdBase
       
   687 	void ReceivedL(const Messages::TRuntimeCtxId& aSender, const Messages::TNodeId& aRecipient, Messages::TSignatureBase& aCFMessage);
       
   688 #endif
       
   689 
       
   690 private:
       
   691 	CPanAgent();
       
   692 	void ConstructL();
       
   693 	
       
   694 	CPanRemoteDeviceStateMachine* FindRemoteDeviceByAddress(const TBTDevAddr& remoteDeviceAddress);
       
   695 	void CheckDeviceIsNotAlreadyAttachedL(const TBTDevAddr& aDevAddr);
       
   696 	void RequestDisconnect(TInt aError);
       
   697 
       
   698 	void InitiateDisconnect();
       
   699 		
       
   700 	static TInt InitiateDisconnectCb(TAny* aThisPtr);
       
   701 
       
   702 	void SendUplinkAccessRequiredProgressNotification();
       
   703 	
       
   704 	TInt TryToCreateNewPanConnection();
       
   705 	
       
   706 private:
       
   707 	RPointerArray<CPanRemoteDeviceStateMachine> iRemoteDevices;
       
   708 
       
   709 #ifdef SYMBIAN_NON_SEAMLESS_NETWORK_BEARER_MOBILITY
       
   710     Messages::TNodeId iBnepConnectionManager;
       
   711 #else
       
   712 	MBnepConnectionManager* iBnepConnectionManager; //< Central management object in packet driver; we don't own this, so don't delete it!
       
   713 #endif
       
   714 
       
   715 	CPanIncomingConnectionListener* iIncomingConnectionListener;
       
   716 	TBool iAllowIncoming;
       
   717 	TBool iNapEnabled;
       
   718 	
       
   719 	CPanRemoteDeviceSelector* iDeviceSelector;		//< Device selector to handle all details of creating outgoing connections (commdb or prompting)
       
   720 
       
   721 	CPanHelperLocalSdpRegistrar* iPanLocalSdpRegistrar;	//< Instance of local SDP registrar
       
   722 
       
   723 	CPanAgtStateBase* iState; 						//< pointer to the state we're currently in
       
   724 	CPanAgtStateBase* iShutdownState;				//< Preallocated shutdown state so we can always close down, even if we're OOM
       
   725 	
       
   726 	TInt iError; 									//< Used to store an error code to persist it during the callback process
       
   727 	TBool iNifmanConnected; 						//< Indicate if we've progressed past ConnectComplete(), and therefore need to use a different error path to signal errors to nifman
       
   728 	TBool iSuppressOutgoing;						//< Suppress any outgoing connections that may be started by this IAP - used to allow UIs to start the ad-hoc IAP at boot time without a prompt appearing
       
   729 	
       
   730 	TBluetoothPanRole iFixedLocalRole; 				//< If there is a local role set in commdb, then it is stored here (there will always be one set, but it might just be EPanRoleUnknown, in which case it is treated as unset)
       
   731 	TBluetoothPanRole iFixedRemoteRole; 			//< If there is a remote role set in commdb, then it is stored here (there will always be one set, but it might just be EPanRoleUnknown, in which case it is treated as unset)
       
   732 
       
   733 	CAsyncCallBack* iInitiateDisconnectCallback;
       
   734 	
       
   735 	TBool iUplinkRequiredProgressSent;				//< This is set when a uplink required progress is sent to the RConnection client.  This will be cleared by sending a uplink not required progress notification
       
   736 	
       
   737 	CPanCoexistenceConnectionController* iPanCoexistenceConnectionController; //< Manage co-existence with other IP bearers
       
   738 	};
       
   739 }	// PanAgent
       
   740 
       
   741 #endif // PANAGT_H
       
   742