|
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 ROLESWITCHHELPER_H |
|
17 #define ROLESWITCHHELPER_H |
|
18 |
|
19 #include <bt_sock.h> |
|
20 #include <bluetooth/hci/hciutil.h> |
|
21 |
|
22 #include "debug.h" |
|
23 #include "linkutil.h" |
|
24 #include "physicallinkhelper.h" |
|
25 #include "physicallinks.h" |
|
26 |
|
27 // watchdog for first half of the SM including: |
|
28 // DisablingLPM, DisablingEncryption, RoleSwitch |
|
29 const TUint KTimeoutRoleSwitch = 3000000; // 3 s; |
|
30 |
|
31 // watchdog for EnablingEncryption |
|
32 const TUint KTimeoutOneCommand = 2000000; // 2 s; |
|
33 |
|
34 class TRoleSwitcherState; |
|
35 |
|
36 NONSHARABLE_CLASS(CRoleSwitcher) : public CPhysicalLinkHelper |
|
37 { |
|
38 friend class TRoleSwitcherState; |
|
39 friend class TRSStateIdle; |
|
40 friend class TRSStateDisablingLPM; |
|
41 friend class TRSStateDisablingEncryption; |
|
42 friend class TRSStateChangingRole; |
|
43 friend class TRSStateChangingRoleWithEPR; |
|
44 friend class TRSStateEnablingEncryption; |
|
45 |
|
46 public: |
|
47 static CRoleSwitcher* NewL(CPhysicalLinksManager& aLinkMgr, CPhysicalLink& aLink, TBTBasebandRole aRole); |
|
48 ~CRoleSwitcher(); |
|
49 |
|
50 virtual void StartHelper(); |
|
51 |
|
52 inline TBool IsEncryptionDisabledForRoleSwitch() const; |
|
53 inline TBTBasebandRole RequestedRole() const; |
|
54 |
|
55 TSglQueLink iQLink; |
|
56 |
|
57 private: |
|
58 CRoleSwitcher(CPhysicalLinksManager& aLinkMgr, CPhysicalLink& aLink, TBTBasebandRole aRole); |
|
59 void ConstructL(); |
|
60 |
|
61 virtual void TimerExpired(); |
|
62 virtual void HandleError(TInt aError); |
|
63 virtual void EventReceived(TBTBasebandEventNotification& aEvent); |
|
64 |
|
65 void DisableEncryption(); |
|
66 void ChangeRole(); |
|
67 void EnableEncryption(); |
|
68 void SaveEncryption(); |
|
69 |
|
70 void LogRoleSwitchSuccessful(TBTBasebandEventNotification& aEvent) const; |
|
71 |
|
72 TBool iIsEncrypted; |
|
73 TBool iIsActive; // LinkMode |
|
74 TBool iAddedToLinkMgr; |
|
75 TBTBasebandRole iRole; // Requested role |
|
76 TRoleSwitcherState* iState; |
|
77 TBool iIsEncryptionDisabledForRoleSwitch; |
|
78 }; |
|
79 |
|
80 //-------------------------------------------------- |
|
81 // STATE FACTORY |
|
82 //-------------------------------------------------- |
|
83 |
|
84 /** |
|
85 Factory for the RoleSwitcher states |
|
86 |
|
87 The states are flyweight classes |
|
88 **/ |
|
89 NONSHARABLE_CLASS(CRoleSwitcherStateFactory) : public CBase |
|
90 { |
|
91 public: |
|
92 static CRoleSwitcherStateFactory* NewL(); |
|
93 |
|
94 enum TRoleSwitcherStates |
|
95 { |
|
96 EIdle, |
|
97 EDisablingLPM, |
|
98 EDisablingEncryption, |
|
99 EChangingRole, |
|
100 EChangingRoleWithEPR, |
|
101 EEnablingEncryption, |
|
102 // Note that we don't need a state to enable LPM again |
|
103 // as this will happen implicitly when we close our |
|
104 // proxy SAP. |
|
105 // *** keep next one last *** |
|
106 ERoleSwitcherMaxState, |
|
107 }; |
|
108 |
|
109 TRoleSwitcherState& GetState(TRoleSwitcherStates aState); |
|
110 TInt StateIndex(const TRoleSwitcherState* aState) const; |
|
111 |
|
112 private: |
|
113 CRoleSwitcherStateFactory(); |
|
114 void ConstructL(); |
|
115 TFixedArray<TRoleSwitcherState*, ERoleSwitcherMaxState> iStates; |
|
116 }; |
|
117 |
|
118 |
|
119 |
|
120 //-------------------------------------------------- |
|
121 // STATES, base |
|
122 //-------------------------------------------------- |
|
123 |
|
124 NONSHARABLE_CLASS(TRoleSwitcherState) |
|
125 { |
|
126 public: |
|
127 TRoleSwitcherState(CRoleSwitcherStateFactory& aFactory); |
|
128 |
|
129 virtual void Enter(CRoleSwitcher& aContext) const; |
|
130 virtual void Exit(CRoleSwitcher& aContext) const; |
|
131 |
|
132 virtual void Start(CRoleSwitcher& aContext) const; |
|
133 virtual void EventReceived(CRoleSwitcher& aContext, TBTBasebandEventNotification& aEvent) const; |
|
134 virtual void Error(CRoleSwitcher& aContext, TInt aErr) const; |
|
135 virtual void TimerExpired(CRoleSwitcher& aContext) const; |
|
136 |
|
137 protected: |
|
138 // Exits old state, sets the new state, and enters it. |
|
139 void ChangeState(CRoleSwitcher& aContext, CRoleSwitcherStateFactory::TRoleSwitcherStates aState) const; |
|
140 void PanicInState(TLinkPanic aPanic) const; |
|
141 |
|
142 protected: |
|
143 CRoleSwitcherStateFactory& iFactory; |
|
144 #ifdef __FLOG_ACTIVE |
|
145 TBuf<48> iName; |
|
146 #endif |
|
147 }; |
|
148 |
|
149 |
|
150 //-------------------------------------------------- |
|
151 // STATES |
|
152 //-------------------------------------------------- |
|
153 |
|
154 NONSHARABLE_CLASS(TRSStateIdle) : public TRoleSwitcherState |
|
155 { |
|
156 public: |
|
157 TRSStateIdle(CRoleSwitcherStateFactory& aFactory); |
|
158 |
|
159 virtual void Enter(CRoleSwitcher& aContext) const; |
|
160 virtual void Start(CRoleSwitcher& aContext) const; |
|
161 }; |
|
162 |
|
163 |
|
164 NONSHARABLE_CLASS(TRSStateDisablingLPM) : public TRoleSwitcherState |
|
165 { |
|
166 public: |
|
167 TRSStateDisablingLPM(CRoleSwitcherStateFactory& aFactory); |
|
168 |
|
169 virtual void Enter(CRoleSwitcher& aContext) const; |
|
170 virtual void EventReceived(CRoleSwitcher& aContext, TBTBasebandEventNotification& aEvent) const; |
|
171 }; |
|
172 |
|
173 NONSHARABLE_CLASS(TRSStateDisablingEncryption) : public TRoleSwitcherState |
|
174 { |
|
175 public: |
|
176 TRSStateDisablingEncryption(CRoleSwitcherStateFactory& aFactory); |
|
177 |
|
178 virtual void Enter(CRoleSwitcher& aContext) const; |
|
179 virtual void EventReceived(CRoleSwitcher& aContext, TBTBasebandEventNotification& aEvent) const; |
|
180 virtual void TimerExpired(CRoleSwitcher& aContext) const; |
|
181 }; |
|
182 |
|
183 NONSHARABLE_CLASS(TRSStateChangingRole) : public TRoleSwitcherState |
|
184 { |
|
185 public: |
|
186 TRSStateChangingRole(CRoleSwitcherStateFactory& aFactory); |
|
187 |
|
188 virtual void Enter(CRoleSwitcher& aContext) const; |
|
189 virtual void EventReceived(CRoleSwitcher& aContext, TBTBasebandEventNotification& aEvent) const; |
|
190 virtual void TimerExpired(CRoleSwitcher& aContext) const; |
|
191 }; |
|
192 |
|
193 NONSHARABLE_CLASS(TRSStateChangingRoleWithEPR) : public TRoleSwitcherState |
|
194 { |
|
195 public: |
|
196 TRSStateChangingRoleWithEPR(CRoleSwitcherStateFactory& aFactory); |
|
197 |
|
198 virtual void Enter(CRoleSwitcher& aContext) const; |
|
199 virtual void EventReceived(CRoleSwitcher& aContext, TBTBasebandEventNotification& aEvent) const; |
|
200 virtual void TimerExpired(CRoleSwitcher& aContext) const; |
|
201 }; |
|
202 |
|
203 NONSHARABLE_CLASS(TRSStateEnablingEncryption) : public TRoleSwitcherState |
|
204 { |
|
205 public: |
|
206 TRSStateEnablingEncryption(CRoleSwitcherStateFactory& aFactory); |
|
207 |
|
208 virtual void Enter(CRoleSwitcher& aContext) const; |
|
209 virtual void Exit(CRoleSwitcher& aContext) const; |
|
210 virtual void EventReceived(CRoleSwitcher& aContext, TBTBasebandEventNotification& aEvent) const; |
|
211 virtual void TimerExpired(CRoleSwitcher& aContext) const; |
|
212 }; |
|
213 |
|
214 #ifdef __FLOG_ACTIVE |
|
215 #define STATENAME(x) iName=_L(x) |
|
216 #else |
|
217 #define STATENAME(x) |
|
218 #endif |
|
219 |
|
220 inline TBTBasebandRole CRoleSwitcher::RequestedRole() const |
|
221 { |
|
222 return iRole; |
|
223 } |
|
224 |
|
225 inline TBool CRoleSwitcher::IsEncryptionDisabledForRoleSwitch() const |
|
226 { |
|
227 return iIsEncryptionDisabledForRoleSwitch; |
|
228 } |
|
229 |
|
230 #endif /* ROLESWITCHHELPER_H */ |