bluetooth/btstack/linkmgr/encryptionkeyrefreshhelper.h
branchRCL_3
changeset 25 99439b07e980
equal deleted inserted replaced
24:e9b924a62a66 25:99439b07e980
       
     1 // Copyright (c) 2010 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 the License "Symbian Foundation License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #ifndef ENCRYPTIONKEYREFRESHHELPER_H
       
    17 #define ENCRYPTIONKEYREFRESHHELPER_H
       
    18 
       
    19 
       
    20 #include <bt_sock.h>
       
    21 #include <bluetooth/hci/hciutil.h> 
       
    22 
       
    23 #include "debug.h"
       
    24 #include "linkutil.h"
       
    25 #include "physicallinkhelper.h"
       
    26 #include "physicallinks.h"
       
    27 
       
    28 // watchdog 
       
    29 const TUint KTimeoutEncryptionKeyRefresh =   3000000;  // 3 s; 
       
    30  
       
    31 class TEncryptionKeyRefresherState;
       
    32 class CEncryptionKeyRefresherStateFactory;
       
    33 NONSHARABLE_CLASS(CEncryptionKeyRefresher) : public CPhysicalLinkHelper
       
    34 	{
       
    35 	friend class TEncryptionKeyRefresherState;
       
    36 	friend class TEkrStateIdle;
       
    37 	friend class TEkrStateDisablingLPM;
       
    38 	friend class TEkrStateRefreshingKey;
       
    39 
       
    40 public:
       
    41 	static CEncryptionKeyRefresher* NewL(CPhysicalLinksManager& aLinkMgr, CPhysicalLink& aLink);
       
    42 	~CEncryptionKeyRefresher();
       
    43 
       
    44 	virtual void StartHelper();
       
    45 	
       
    46 	void EncryptionKeyRefreshComplete(TInt aError);
       
    47 
       
    48 private:
       
    49 	CEncryptionKeyRefresher(CPhysicalLinksManager& aLinkMgr, CPhysicalLink& aLink);
       
    50 	void ConstructL(); 
       
    51 	
       
    52 	virtual void TimerExpired();
       
    53 	virtual void HandleError(TInt aError);
       
    54 	virtual void EventReceived(TBTBasebandEventNotification& aEvent);
       
    55   
       
    56 private:
       
    57 	CEncryptionKeyRefresherStateFactory*	iStateFactory;
       
    58 	const TEncryptionKeyRefresherState*		iState;            
       
    59 	};
       
    60 
       
    61 //--------------------------------------------------
       
    62 // STATE FACTORY
       
    63 //--------------------------------------------------
       
    64 
       
    65 /**
       
    66    Factory for the EncryptionKeyRefresher states
       
    67 
       
    68    The states are flyweight classes
       
    69 **/
       
    70 NONSHARABLE_CLASS(CEncryptionKeyRefresherStateFactory) : public CBase
       
    71 	{
       
    72 public:
       
    73 	static CEncryptionKeyRefresherStateFactory* NewL();
       
    74 
       
    75 	enum TEncryptionKeyRefresherStates
       
    76 		{
       
    77 		EIdle,
       
    78 		EDisablingLPM,
       
    79 		ERefreshingKey,
       
    80 		// Note that we don't need a state to enable LPM again
       
    81 		// as this will happen implicitly when we close our 
       
    82 		// proxy SAP.
       
    83 		// *** keep next one last ***
       
    84 		EEncryptionKeyRefresherMaxState,
       
    85 		};
       
    86 	
       
    87 	const TEncryptionKeyRefresherState& GetState(TEncryptionKeyRefresherStates aState) const;
       
    88 	TInt StateIndex(const TEncryptionKeyRefresherState* aState) const;
       
    89 	
       
    90 private:
       
    91 	CEncryptionKeyRefresherStateFactory();
       
    92 	void ConstructL();
       
    93 	TFixedArray<TEncryptionKeyRefresherState*, EEncryptionKeyRefresherMaxState> iStates;
       
    94 	};
       
    95 
       
    96 
       
    97 
       
    98 //--------------------------------------------------
       
    99 // STATES, base 
       
   100 //--------------------------------------------------
       
   101 
       
   102 NONSHARABLE_CLASS(TEncryptionKeyRefresherState)
       
   103 	{
       
   104 public:
       
   105 	TEncryptionKeyRefresherState(CEncryptionKeyRefresherStateFactory& aFactory);
       
   106 	
       
   107 	virtual void Enter(CEncryptionKeyRefresher& aContext) const;
       
   108 	virtual void Exit(CEncryptionKeyRefresher& aContext) const;
       
   109 
       
   110 	virtual void Start(CEncryptionKeyRefresher& aContext) const;
       
   111 	virtual void EventReceived(CEncryptionKeyRefresher& aContext, TBTBasebandEventNotification& aEvent) const;
       
   112 	virtual void Error(CEncryptionKeyRefresher& aContext, TInt aErr) const;
       
   113 	virtual void TimerExpired(CEncryptionKeyRefresher& aContext) const;
       
   114 	virtual void EncryptionKeyRefreshComplete(CEncryptionKeyRefresher& aContext, TInt aError) const;
       
   115 
       
   116 protected:
       
   117 	// Exits old state, sets the new state, and enters it.
       
   118 	void ChangeState(CEncryptionKeyRefresher& aContext, CEncryptionKeyRefresherStateFactory::TEncryptionKeyRefresherStates aState) const;
       
   119 	void PanicInState(TLinkPanic aPanic) const;
       
   120 	
       
   121 protected:
       
   122 	CEncryptionKeyRefresherStateFactory& iFactory;
       
   123 #ifdef __FLOG_ACTIVE
       
   124 	TBuf<48> iName;
       
   125 #endif
       
   126 	};
       
   127 
       
   128 
       
   129 //--------------------------------------------------
       
   130 // STATES 
       
   131 //--------------------------------------------------
       
   132 
       
   133 NONSHARABLE_CLASS(TEkrStateIdle) : public TEncryptionKeyRefresherState
       
   134 	{
       
   135 public:
       
   136 	TEkrStateIdle(CEncryptionKeyRefresherStateFactory& aFactory);
       
   137 
       
   138 	virtual void Enter(CEncryptionKeyRefresher& aContext) const;
       
   139 	virtual void Start(CEncryptionKeyRefresher& aContext) const;
       
   140 	};
       
   141 
       
   142 
       
   143 NONSHARABLE_CLASS(TEkrStateDisablingLPM) : public TEncryptionKeyRefresherState
       
   144 	{
       
   145 public:
       
   146 	TEkrStateDisablingLPM(CEncryptionKeyRefresherStateFactory& aFactory);
       
   147 
       
   148 	virtual void Enter(CEncryptionKeyRefresher& aContext) const;
       
   149 	virtual void EventReceived(CEncryptionKeyRefresher& aContext, TBTBasebandEventNotification& aEvent) const;
       
   150 	};
       
   151 
       
   152 NONSHARABLE_CLASS(TEkrStateRefreshingKey) : public TEncryptionKeyRefresherState
       
   153 	{
       
   154 public:
       
   155 	TEkrStateRefreshingKey(CEncryptionKeyRefresherStateFactory& aFactory);
       
   156 
       
   157 	virtual void Enter(CEncryptionKeyRefresher& aContext) const;
       
   158 	virtual void EncryptionKeyRefreshComplete(CEncryptionKeyRefresher& aContext, TInt aError) const;
       
   159 	};
       
   160 
       
   161 
       
   162 #ifdef __FLOG_ACTIVE
       
   163 #define STATENAME(x)  iName=_L(x)
       
   164 #else
       
   165 #define STATENAME(x)
       
   166 #endif
       
   167 
       
   168 
       
   169 #endif /* ENCRYPTIONKEYREFRESHHELPER_H */