|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Pairing manager header definition |
|
15 * |
|
16 */ |
|
17 |
|
18 #ifndef BTENGPAIRMANAGER_H_ |
|
19 #define BTENGPAIRMANAGER_H_ |
|
20 |
|
21 #include <bttypes.h> |
|
22 #include <bt_sock.h> |
|
23 #include <bluetooth/pairing.h> |
|
24 #include "btengactive.h" |
|
25 #include "btengconstants.h" |
|
26 |
|
27 class CBTEngPairBase; |
|
28 class CBTEngServer; |
|
29 |
|
30 /** |
|
31 * Class CBTEngPairMan |
|
32 * |
|
33 * This class manages pairing with BT devices. |
|
34 * The responsibility of handling incoming and outgoing pairings is |
|
35 * delegated to CBTEngIncPair and CBTEngOtgPair respectively. |
|
36 * |
|
37 * @since S60 S60 v5.1 |
|
38 */ |
|
39 NONSHARABLE_CLASS( CBTEngPairMan ) : public CBase, public MBTEngActiveObserver |
|
40 { |
|
41 public: |
|
42 |
|
43 /** |
|
44 * Two-phase constructor |
|
45 */ |
|
46 static CBTEngPairMan* NewL( CBTEngServer& aServer ); |
|
47 |
|
48 /** |
|
49 * Destructor |
|
50 */ |
|
51 ~CBTEngPairMan(); |
|
52 |
|
53 /** |
|
54 * Cancels an outstanding pairing request. |
|
55 */ |
|
56 void CancelOutgoingPair(); |
|
57 |
|
58 /** |
|
59 * Process commands relevant to pairing |
|
60 */ |
|
61 void ProcessCommandL( const RMessage2& aMessage ); |
|
62 |
|
63 /** |
|
64 * Cancels an outstanding command. |
|
65 * @param aOpcode the identifier of the command to be cancelled. |
|
66 */ |
|
67 void CancelCommand( TInt aOpCode ); |
|
68 |
|
69 /** |
|
70 * Handle a change in BTRegistry remote device table. |
|
71 * |
|
72 * @since S60 v5.1 |
|
73 */ |
|
74 void RemoteRegistryChangeDetected(); |
|
75 |
|
76 /** |
|
77 * Gets the instance of pairing server. |
|
78 * @return the server instance. NULL if dedicated bonding is unavailable. |
|
79 */ |
|
80 RBluetoothPairingServer* PairingServer(); |
|
81 |
|
82 /** |
|
83 * gets the reference of socket server session |
|
84 */ |
|
85 RSocketServ& SocketServ(); |
|
86 |
|
87 /** |
|
88 * gets the reference of registry session. |
|
89 */ |
|
90 RBTRegServ& BTRegServ(); |
|
91 |
|
92 /** |
|
93 * Transfer responsiblity to the specified object. |
|
94 * @param aPairer the object to which the responsibility is transfered. |
|
95 */ |
|
96 void RenewPairer( CBTEngPairBase* aPairer ); |
|
97 |
|
98 /** |
|
99 * Be notified when handling of an outgoing pair has been completed. |
|
100 * @param aErr the result of pairing |
|
101 * |
|
102 */ |
|
103 void OutgoingPairCompleted( TInt aErr ); |
|
104 |
|
105 /** |
|
106 * Unpair a device via registry |
|
107 */ |
|
108 void UnpairDevice( const TBTDevAddr& aAddr ); |
|
109 |
|
110 /** |
|
111 * Add the bit indicating the device is user-aware Just worked paired to |
|
112 * UI cookie. |
|
113 */ |
|
114 TInt AddUiCookieJustWorksPaired( const TBTNamelessDevice& aDev ); |
|
115 |
|
116 /** |
|
117 * Update a nameless device in registry |
|
118 */ |
|
119 TInt UpdateRegDevice( const TBTNamelessDevice& aDev ); |
|
120 |
|
121 |
|
122 /** |
|
123 * Returns the service (limited to services managed in bteng scope) |
|
124 * level connection status of the specified device. |
|
125 * |
|
126 * @param aAddr the address of the device |
|
127 * @return one of TBTEngConnectionStatus enums |
|
128 */ |
|
129 TBTEngConnectionStatus IsDeviceConnected( const TBTDevAddr& aAddr ); |
|
130 |
|
131 private: // from base class MBTEngActiveObserver |
|
132 |
|
133 /** |
|
134 * From MBTEngActiveObserver. |
|
135 * Callback to notify that an outstanding request has completed. |
|
136 * |
|
137 * @since S60 v5.1 |
|
138 * @param aActive Pointer to the active object that completed. |
|
139 * @param aId The ID that identifies the outstanding request. |
|
140 * @param aStatus The status of the completed request. |
|
141 */ |
|
142 virtual void RequestCompletedL( CBTEngActive* aActive, TInt aId, TInt aStatus ); |
|
143 |
|
144 /** |
|
145 * From MBTEngActiveObserver. |
|
146 * Callback to notify that an error has occurred in RunL. |
|
147 * |
|
148 * @since S60 v5.1 |
|
149 * @param aActive Pointer to the active object that completed. |
|
150 * @param aId The ID that identifies the outstanding request. |
|
151 * @param aStatus The status of the completed request. |
|
152 */ |
|
153 virtual void HandleError( CBTEngActive* aActive, TInt aId, TInt aError ); |
|
154 |
|
155 private: |
|
156 |
|
157 /** |
|
158 * C++ default constructor |
|
159 */ |
|
160 CBTEngPairMan( CBTEngServer& aServer ); |
|
161 |
|
162 /** |
|
163 * Symbian 2nd-phase constructor |
|
164 */ |
|
165 void ConstructL(); |
|
166 |
|
167 /** |
|
168 * Activate / deactivate a pair observer |
|
169 */ |
|
170 TInt SetPairObserver(const TBTDevAddr& aAddr, TBool aActivate); |
|
171 |
|
172 /** |
|
173 * Pair a BT device. |
|
174 */ |
|
175 void PairDeviceL( const TBTDevAddr& aAddr, TUint32 aCod ); |
|
176 |
|
177 /** |
|
178 * Cancel all subscribes to pairng server |
|
179 */ |
|
180 void CancelSubscribe(); |
|
181 |
|
182 /** |
|
183 * subscribe to receive SSP pairing result from pairing server |
|
184 */ |
|
185 void SubscribeSspPairingResult(); |
|
186 |
|
187 /** |
|
188 * Subscribe to receive authentication result from pairing server |
|
189 */ |
|
190 void SubscribeAuthenticateResult(); |
|
191 |
|
192 /** |
|
193 * Handle a pairing result from the pairing server. |
|
194 * |
|
195 * @since S60 v5.1 |
|
196 * @param aResult The status code of the authentication result. |
|
197 */ |
|
198 void HandlePairingResultL( const TBTDevAddr& aAddr, TInt aResult ); |
|
199 |
|
200 /** |
|
201 * Creates a registry view which shall contain all paired devices. |
|
202 */ |
|
203 void CreatePairedDevicesView( TInt aReqId ); |
|
204 |
|
205 /** |
|
206 * retrieves paired devices from registry. |
|
207 */ |
|
208 void GetPairedDevices( TInt aReqId ); |
|
209 |
|
210 /** |
|
211 * handles the completion of paired device view creation |
|
212 */ |
|
213 void HandleCreatePairedDevicesViewCompletedL( TInt aStatus, TInt aReqId ); |
|
214 |
|
215 /** |
|
216 * handles the completion of getting paired devices |
|
217 */ |
|
218 void HandleGetPairedDevicesCompletedL( TInt aStatus, TInt aReqId ); |
|
219 |
|
220 /** |
|
221 * Copy the paired devices to internal array storage. |
|
222 */ |
|
223 void UpdatePairedDeviceListL(); |
|
224 |
|
225 /** |
|
226 * Checks if any devices have been paired or unpaired. For each new paired device, |
|
227 * the pair event will be delegated to corresponding pair observer if it exists; |
|
228 * otherwise create a new pair observer for this pair event. |
|
229 */ |
|
230 void CheckPairEventL(); |
|
231 |
|
232 private: |
|
233 |
|
234 /** |
|
235 * Owner of this class. |
|
236 * Not owned. |
|
237 */ |
|
238 CBTEngServer& iServer; |
|
239 |
|
240 /** |
|
241 * Registry sub session for remote device db |
|
242 */ |
|
243 RBTRegistry iBTRegistry; |
|
244 |
|
245 /** |
|
246 * contains the list of all paired devices. |
|
247 * Using heap here to make efficient array swap. |
|
248 */ |
|
249 RArray<TBTNamelessDevice>* iPairedDevices; |
|
250 |
|
251 /** |
|
252 * temporary instance to retrieve paired devices. |
|
253 */ |
|
254 CBTRegistryResponse* iPairedDevicesResp; |
|
255 |
|
256 /** |
|
257 * the counter of not handled registry events. |
|
258 */ |
|
259 TInt iNotHandledRegEventCounter; |
|
260 |
|
261 /** |
|
262 * Session with the pairing server. |
|
263 * Allocate it in heap to ease the handling for |
|
264 * situation of unavailable dedicated pairing service. |
|
265 * |
|
266 * own. |
|
267 */ |
|
268 RBluetoothPairingServer* iPairingServ; |
|
269 |
|
270 /** |
|
271 * Subsession with the pairing server for |
|
272 * getting the simple pairing result. |
|
273 * own |
|
274 */ |
|
275 RBluetoothPairingResult iPairingResult; |
|
276 |
|
277 /** |
|
278 * Subsession with the pairing server for |
|
279 * getting the authentication result. |
|
280 * own |
|
281 */ |
|
282 RBluetoothAuthenticationResult iAuthenResult; |
|
283 |
|
284 /** |
|
285 * the address with which a simple pairing has been performed |
|
286 */ |
|
287 TBTDevAddr iSimplePairingRemote; |
|
288 |
|
289 /** |
|
290 * the address with which an authentication has been performed |
|
291 */ |
|
292 TBTDevAddr iAuthenticateRemote; |
|
293 |
|
294 /** |
|
295 * Active object helper for receiving simple pairing results. |
|
296 * Own. |
|
297 */ |
|
298 CBTEngActive* iSSPResultActive; |
|
299 |
|
300 /** |
|
301 * Active object helper for receiving authentication results. |
|
302 * Own. |
|
303 */ |
|
304 CBTEngActive* iAuthenResultActive; |
|
305 |
|
306 /** |
|
307 * AO for registry operations |
|
308 */ |
|
309 CBTEngActive* iRegistryActive; |
|
310 |
|
311 /** |
|
312 * pair hanlder at the time. |
|
313 * Own. |
|
314 */ |
|
315 CBTEngPairBase* iPairer; |
|
316 }; |
|
317 |
|
318 #endif /*BTENGPAIRMANAGER_H_*/ |