20 #include <bt_sock.h> |
20 #include <bt_sock.h> |
21 #include "physicallinks.h" |
21 #include "physicallinks.h" |
22 #include "linkutil.h" |
22 #include "linkutil.h" |
23 #include <bluetooth/hci/hciutil.h> |
23 #include <bluetooth/hci/hciutil.h> |
24 |
24 |
25 // A struct to allow both single event and combination events to be passed for requesting |
25 // watchdog for first half of the SM including: |
26 // notification. This effectively moves the cast to a TInt to below the API rather than |
26 // DisablingLPM, DisablingEncryption, RoleSwitch |
27 // being required by the client. |
27 const TUint KTimeoutRoleSwitch = 3000000; // 3 s; |
28 struct TNotifyEvent |
28 |
29 { |
29 // watchdog for EnablingEncryption |
30 public: |
30 const TUint KTimeoutOneCommand = 2000000; // 2 s; |
31 TNotifyEvent(TBTPhysicalLinkStateNotifier aSingleEvent) : iEvent(aSingleEvent) {}; |
31 |
32 TNotifyEvent(TBTPhysicalLinkStateNotifierCombinations aComboEvent) : iEvent(aComboEvent) {}; |
32 class TRoleSwitcherState; |
33 |
33 |
34 TInt NotifyEvent() const {return iEvent;}; |
34 NONSHARABLE_CLASS(CRoleSwitcher) : public CTimer, public MSocketNotify |
35 private: |
35 { |
36 TInt iEvent; |
36 friend class TRoleSwitcherState; |
37 }; |
37 friend class TRSStateDisablingLPM; |
38 |
38 friend class TRSStateDisablingEncryption; |
39 |
39 friend class TRSStateChangingRole; |
40 NONSHARABLE_CLASS(CPhysicalLinkHelper) : public CBase, public MSocketNotify |
40 friend class TRSStateChangingRoleWithEPR; |
41 { |
41 friend class TRSStateEnablingEncryption; |
42 public: |
42 |
43 ~CPhysicalLinkHelper(); |
43 public: |
|
44 |
|
45 static CRoleSwitcher* NewL(CPhysicalLinksManager& aLinkMgr, CPhysicalLink& aLink, TBTBasebandRole aRole); |
|
46 ~CRoleSwitcher(); |
44 |
47 |
45 // From MSocketNotify |
48 // From MSocketNotify |
46 void NewData(TUint aCount); |
49 void NewData(TUint aCount); |
47 void CanSend(); |
50 void CanSend(); |
48 void ConnectComplete(); |
51 void ConnectComplete(); |
56 void Disconnect(TDesC8& aDisconnectData); |
59 void Disconnect(TDesC8& aDisconnectData); |
57 void IoctlComplete(TDesC8 *aBuf); |
60 void IoctlComplete(TDesC8 *aBuf); |
58 void NoBearer(const TDesC8& /*aConnectionInf*/) {}; |
61 void NoBearer(const TDesC8& /*aConnectionInf*/) {}; |
59 void Bearer(const TDesC8& /*aConnectionInf*/) {}; |
62 void Bearer(const TDesC8& /*aConnectionInf*/) {}; |
60 |
63 |
61 virtual void StartHelper() = 0; |
64 void Start(); |
62 |
65 void Finish(); |
63 inline const TBTDevAddr& BDAddr() const; |
66 inline const TBTDevAddr& BDAddr() const; |
|
67 inline TBTBasebandRole RequestedRole() const; |
|
68 inline TBool IsEncryptionDisabledForRoleSwitch() const; |
|
69 TBool IsEPRSupported() const; |
|
70 void LogRoleSwitchSuccessful() const; |
|
71 TSglQueLink iQLink; |
|
72 |
|
73 private: |
|
74 CRoleSwitcher(CPhysicalLinksManager& aLinkMgr, CPhysicalLink& aLink, TBTBasebandRole aRole); |
|
75 void ConstructL(); |
|
76 |
|
77 void DisableLPM(); |
|
78 void DisableEncryption(); |
|
79 void ChangeRole(); |
|
80 void EnableEncryption(); |
|
81 void EnableLPM(); |
|
82 void CancelIoctl(); |
|
83 |
|
84 void SaveEncryption(); |
|
85 // CTimer |
|
86 void RunL(); |
|
87 TInt RunError(TInt aError); |
|
88 |
|
89 static TInt EventReceivedCallBack(TAny* aRoleSwitcher); |
|
90 // Async Callback to notify baseband event received. |
|
91 CAsyncCallBack* iEventReceivedCallBack; |
|
92 TBTBasebandEventNotification iBasebandEvent; |
|
93 TBool iIsEncrypted; |
|
94 TBool iIsActive; // LinkMode |
|
95 TBool iAddedToLinkMgr; |
|
96 CPhysicalLinksManager& iLinkMgr; |
|
97 CPhysicalLink& iLink; |
|
98 TBTBasebandRole iRole; // Requested role |
|
99 CBTProxySAP* iBTProxySAP; |
|
100 TRoleSwitcherState* iState; |
|
101 TBool iIsEncryptionDisabledForRoleSwitch; |
|
102 }; |
|
103 |
|
104 //-------------------------------------------------- |
|
105 // STATE FACTORY |
|
106 //-------------------------------------------------- |
|
107 |
|
108 /** |
|
109 Factory for the RoleSwitcher states |
|
110 |
|
111 The states are flyweight classes |
|
112 **/ |
|
113 NONSHARABLE_CLASS(CRoleSwitcherStateFactory) : public CBase |
|
114 { |
|
115 public: |
|
116 static CRoleSwitcherStateFactory* NewL(); |
|
117 |
|
118 enum TRoleSwitcherStates |
|
119 { |
|
120 EIdle, |
|
121 EDisablingLPM, |
|
122 EDisablingEncryption, |
|
123 EChangingRole, |
|
124 EChangingRoleWithEPR, |
|
125 EEnablingEncryption, |
|
126 // *** keep next one last *** |
|
127 ERoleSwitcherMaxState, |
|
128 }; |
|
129 |
|
130 TRoleSwitcherState& GetState(TRoleSwitcherStates aState); |
|
131 TInt StateIndex(const TRoleSwitcherState* aState) const; |
|
132 |
|
133 private: |
|
134 CRoleSwitcherStateFactory(); |
|
135 void ConstructL(); |
|
136 TFixedArray<TRoleSwitcherState*, ERoleSwitcherMaxState> iStates; |
|
137 }; |
|
138 |
|
139 |
|
140 |
|
141 //-------------------------------------------------- |
|
142 // STATES, base |
|
143 //-------------------------------------------------- |
|
144 |
|
145 NONSHARABLE_CLASS(TRoleSwitcherState) |
|
146 { |
|
147 public: |
|
148 TRoleSwitcherState(CRoleSwitcherStateFactory& aFactory); |
|
149 |
|
150 virtual void Enter(CRoleSwitcher& aContext) const; |
|
151 virtual void Exit(CRoleSwitcher& aContext) const; |
|
152 |
|
153 virtual void Start(CRoleSwitcher& aContext) const; |
|
154 virtual void EventReceived(CRoleSwitcher& aContext) const; |
|
155 virtual void Error(CRoleSwitcher& aContext, TInt aErr) const; |
|
156 virtual void TimerExpired(CRoleSwitcher& aContext) const; |
64 |
157 |
65 protected: |
158 protected: |
66 CPhysicalLinkHelper(CPhysicalLinksManager& aLinkMgr, CPhysicalLink& aLink); |
159 // Exits old state, sets the new state, and enters it. |
67 void BaseConstructL(); |
160 void ChangeState(CRoleSwitcher& aContext, CRoleSwitcherStateFactory::TRoleSwitcherStates aState) const; |
68 |
161 void PanicInState(TLinkPanic aPanic) const; |
69 void DisableLPM(); |
|
70 |
|
71 void QueueTimer(TTimeIntervalMicroSeconds32 aTimerVal); |
|
72 void RemoveTimer(); |
|
73 void NotifyBasebandEvent(TNotifyEvent aEvent); |
|
74 void CancelNotify(); |
|
75 |
|
76 TBool IsEPRSupported() const; |
|
77 |
|
78 virtual void TimerExpired() = 0; |
|
79 virtual void HandleError(TInt aError) = 0; |
|
80 virtual void EventReceived(TBTBasebandEventNotification& aEvent) = 0; |
|
81 |
|
82 private: |
|
83 static TInt EventReceivedCallBack(TAny* aThis); |
|
84 void DoEventReceivedCallBack(); |
|
85 |
|
86 static TInt TimerExpiredCallBack(TAny* aThis); |
|
87 void DoTimerExpiredCallBack(); |
|
88 |
162 |
89 protected: |
163 protected: |
90 CPhysicalLinksManager& iLinkMgr; |
164 CRoleSwitcherStateFactory& iFactory; |
91 CPhysicalLink& iLink; |
165 #ifdef __FLOG_ACTIVE |
92 |
166 TBuf<48> iName; |
93 private: |
167 #endif |
94 // Async Callback to notify baseband event received. |
168 }; |
95 CAsyncCallBack* iEventReceivedCallBack; |
169 |
96 TBTBasebandEventNotification iBasebandEvent; |
170 |
97 CBTProxySAP* iBTProxySAP; |
171 //-------------------------------------------------- |
98 |
172 // STATES |
99 TDeltaTimerEntry iTimerEntry; |
173 //-------------------------------------------------- |
100 }; |
174 |
101 |
175 NONSHARABLE_CLASS(TRSStateIdle) : public TRoleSwitcherState |
102 inline const TBTDevAddr& CPhysicalLinkHelper::BDAddr() const |
176 { |
|
177 public: |
|
178 TRSStateIdle(CRoleSwitcherStateFactory& aFactory); |
|
179 |
|
180 virtual void Enter(CRoleSwitcher& aContext) const; |
|
181 virtual void Start(CRoleSwitcher& aContext) const; |
|
182 }; |
|
183 |
|
184 |
|
185 NONSHARABLE_CLASS(TRSStateDisablingLPM) : public TRoleSwitcherState |
|
186 { |
|
187 public: |
|
188 TRSStateDisablingLPM(CRoleSwitcherStateFactory& aFactory); |
|
189 |
|
190 virtual void Enter(CRoleSwitcher& aContext) const; |
|
191 virtual void EventReceived(CRoleSwitcher& aContext) const; |
|
192 }; |
|
193 |
|
194 NONSHARABLE_CLASS(TRSStateDisablingEncryption) : public TRoleSwitcherState |
|
195 { |
|
196 public: |
|
197 TRSStateDisablingEncryption(CRoleSwitcherStateFactory& aFactory); |
|
198 |
|
199 virtual void Enter(CRoleSwitcher& aContext) const; |
|
200 virtual void EventReceived(CRoleSwitcher& aContext) const; |
|
201 virtual void TimerExpired(CRoleSwitcher& aContext) const; |
|
202 }; |
|
203 |
|
204 NONSHARABLE_CLASS(TRSStateChangingRole) : public TRoleSwitcherState |
|
205 { |
|
206 public: |
|
207 TRSStateChangingRole(CRoleSwitcherStateFactory& aFactory); |
|
208 |
|
209 virtual void Enter(CRoleSwitcher& aContext) const; |
|
210 virtual void EventReceived(CRoleSwitcher& aContext) const; |
|
211 virtual void TimerExpired(CRoleSwitcher& aContext) const; |
|
212 }; |
|
213 |
|
214 NONSHARABLE_CLASS(TRSStateChangingRoleWithEPR) : public TRoleSwitcherState |
|
215 { |
|
216 public: |
|
217 TRSStateChangingRoleWithEPR(CRoleSwitcherStateFactory& aFactory); |
|
218 |
|
219 virtual void Enter(CRoleSwitcher& aContext) const; |
|
220 virtual void EventReceived(CRoleSwitcher& aContext) const; |
|
221 virtual void TimerExpired(CRoleSwitcher& aContext) const; |
|
222 }; |
|
223 |
|
224 NONSHARABLE_CLASS(TRSStateEnablingEncryption) : public TRoleSwitcherState |
|
225 { |
|
226 public: |
|
227 TRSStateEnablingEncryption(CRoleSwitcherStateFactory& aFactory); |
|
228 |
|
229 virtual void Enter(CRoleSwitcher& aContext) const; |
|
230 virtual void Exit(CRoleSwitcher& aContext) const; |
|
231 virtual void EventReceived(CRoleSwitcher& aContext) const; |
|
232 virtual void TimerExpired(CRoleSwitcher& aContext) const; |
|
233 }; |
|
234 |
|
235 #ifdef __FLOG_ACTIVE |
|
236 #define STATENAME(x) iName=_L(x) |
|
237 #else |
|
238 #define STATENAME(x) |
|
239 #endif |
|
240 |
|
241 inline const TBTDevAddr& CRoleSwitcher::BDAddr() const |
103 { |
242 { |
104 return iLink.BDAddr(); |
243 return iLink.BDAddr(); |
105 } |
244 } |
106 |
245 |
|
246 inline TBTBasebandRole CRoleSwitcher::RequestedRole() const |
|
247 { |
|
248 return iRole; |
|
249 } |
|
250 |
|
251 inline TBool CRoleSwitcher::IsEncryptionDisabledForRoleSwitch() const |
|
252 { |
|
253 return iIsEncryptionDisabledForRoleSwitch; |
|
254 } |
|
255 |
107 #endif //PHYSICALLINKHELPER_H_ |
256 #endif //PHYSICALLINKHELPER_H_ |