1 /* |
|
2 * Copyright (c) 2010 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 handler for local device initiated pairing |
|
15 * |
|
16 */ |
|
17 |
|
18 #ifndef BTNOTIFOUTGOINGPAIRINGHANDLER_H_ |
|
19 #define BTNOTIFOUTGOINGPAIRINGHANDLER_H_ |
|
20 |
|
21 #include <bttypes.h> |
|
22 #include <bluetooth/pairing.h> |
|
23 #include <e32property.h> |
|
24 #include "btnotifclientserver.h" |
|
25 #include "btnotifBasePairingHandler.h" |
|
26 #include <hb/hbcore/hbsymbianvariant.h> |
|
27 #include "btnotificationresult.h" |
|
28 #include "bluetoothdevicedialogs.h" |
|
29 |
|
30 class CBluetoothNotification; |
|
31 |
|
32 enum TBTOutgoingPairMode |
|
33 { |
|
34 /** |
|
35 * not outgoing pairing operation |
|
36 */ |
|
37 EBTOutgoingPairNone = 0, |
|
38 |
|
39 /** |
|
40 * outgoing automatic 0000 pin pairing with headset in progress |
|
41 */ |
|
42 EBTOutgoingHeadsetAutoPairing, |
|
43 |
|
44 /** |
|
45 * outgoing manual pairing with headset in progress |
|
46 */ |
|
47 EBTOutgoingHeadsetManualPairing, |
|
48 |
|
49 /** |
|
50 * outgoing pairing with non-headset device in progress |
|
51 */ |
|
52 EBTOutgoingNoneHeadsetPairing, |
|
53 }; |
|
54 |
|
55 /** |
|
56 * Perform a outgoing pair with a BT device. |
|
57 * |
|
58 * @since Symbian^4 |
|
59 */ |
|
60 NONSHARABLE_CLASS( CBTNotifOutgoingPairingHandler ) : public CBTNotifBasePairingHandler, |
|
61 public MBTNotificationResult |
|
62 { |
|
63 |
|
64 public: |
|
65 |
|
66 /** |
|
67 * Two-phase constructor |
|
68 * @param aParent the owner of this object |
|
69 * @param aAddr the remote device this observer is targeted to |
|
70 */ |
|
71 static CBTNotifBasePairingHandler* NewL( CBTNotifSecurityManager& aParent, |
|
72 const TBTDevAddr& aAddr ); |
|
73 |
|
74 /** |
|
75 * Destructor |
|
76 */ |
|
77 ~CBTNotifOutgoingPairingHandler(); |
|
78 |
|
79 |
|
80 // from base class MBTNotificationResult |
|
81 |
|
82 /** |
|
83 * From MBTNotificationResult. |
|
84 * Handle an intermediate result from a user query. |
|
85 * This function is called if the user query passes information |
|
86 * back before it has finished i.e. is dismissed. The final acceptance/ |
|
87 * denial of a query is passed back in MBRNotificationClosed. |
|
88 * |
|
89 * @since Symbian^4 |
|
90 * @param aData the returned data. The actual format |
|
91 * is dependent on the actual notifier. |
|
92 */ |
|
93 virtual void MBRDataReceived( CHbSymbianVariantMap& aData ); |
|
94 |
|
95 /** |
|
96 * From MBTNotificationResult. |
|
97 * The notification is finished. The resulting data (e.g. user input or |
|
98 * acceptance/denial of the query) is passed back here. |
|
99 * |
|
100 * @since Symbian^4 |
|
101 * @param aErr KErrNone or one of the system-wide error codes. |
|
102 * @param aData the returned data. The actual format |
|
103 * is dependent on the actual notifier. |
|
104 */ |
|
105 virtual void MBRNotificationClosed( TInt aError, const TDesC8& aData ); |
|
106 |
|
107 private: |
|
108 |
|
109 /** |
|
110 * Start observing the result of pairing which was originated from |
|
111 * the remote device. |
|
112 * @param the address of the remote device to be paired |
|
113 * @return KErrNone if this request is accepted; otherwise an error code |
|
114 */ |
|
115 TInt ObserveIncomingPair( const TBTDevAddr& aAddr ); |
|
116 |
|
117 /** |
|
118 * Start an outgoing pairing with the remote device. |
|
119 * @param the address of the remote device to be paired |
|
120 * @return KErrNone if this request is accepted; otherwise an error code |
|
121 */ |
|
122 void HandleOutgoingPairL( const TBTDevAddr& aAddr, TUint aCod ); |
|
123 |
|
124 /** |
|
125 * Cancel any outstanding pairing operation. |
|
126 */ |
|
127 void CancelOutgoingPair(); |
|
128 |
|
129 /** |
|
130 * Gets the pin code to be used for pairing a device. |
|
131 * @param aPin contains the pin code if it is not empty |
|
132 * @param aAddr the device to which pairing is performed. |
|
133 * @param the required minimum length of a pin code. |
|
134 */ |
|
135 void GetPinCode( TBTPinCode& aPin, const TBTDevAddr& aAddr, TInt aMinPinLength ); |
|
136 |
|
137 /** |
|
138 * Cancels pairing handling with the specified device |
|
139 * @param aAddr the address of the device the pairing is with |
|
140 */ |
|
141 void StopPairHandling( const TBTDevAddr& aAddr ); |
|
142 |
|
143 /** |
|
144 * Handle a pairing result with the remote device which this is for. |
|
145 * Must be specialized by subclass. |
|
146 * |
|
147 * @param aResult The status code of the pairing or authentication result. |
|
148 */ |
|
149 void DoHandlePairServerResult( TInt aResult ); |
|
150 |
|
151 /** |
|
152 * Handles registry new paired event for the remote |
|
153 * device this is pairing with. |
|
154 * @aType the type of authentication with the device. |
|
155 */ |
|
156 void DoHandleRegistryNewPairedEvent( const TBTNamelessDevice& aDev ); |
|
157 |
|
158 private: // from base class MBtSimpleActiveObserver |
|
159 |
|
160 /** |
|
161 * Callback to notify that an outstanding request has completed. |
|
162 * |
|
163 * @since Symbian^4 |
|
164 * @param aActive Pointer to the active object that completed. |
|
165 * @param aId The ID that identifies the outstanding request. |
|
166 * @param aStatus The status of the completed request. |
|
167 */ |
|
168 void RequestCompletedL( CBtSimpleActive* aActive, TInt aStatus ); |
|
169 |
|
170 /** |
|
171 * Callback from Docancel() for handling cancelation of an outstanding request. |
|
172 * |
|
173 * @since Symbian^4 |
|
174 * @param aId The ID that identifies the outstanding request. |
|
175 */ |
|
176 virtual void CancelRequest( TInt aRequestId ); |
|
177 |
|
178 /** |
|
179 * Callback to notify that an error has occurred in RunL. |
|
180 * |
|
181 * @since Symbian^4 |
|
182 * @param aActive Pointer to the active object that completed. |
|
183 * @param aId The ID that identifies the outstanding request. |
|
184 * @param aStatus The status of the completed request. |
|
185 */ |
|
186 void HandleError( CBtSimpleActive* aActive, TInt aError ); |
|
187 |
|
188 private: |
|
189 /** |
|
190 * Get a notification and configure it according to the current operation. |
|
191 * |
|
192 * @since Symbian^4 |
|
193 * @param aType The notification type. |
|
194 * @param aResourceId Identifier for the resource to display. |
|
195 */ |
|
196 void PrepareNotificationL( TBluetoothDialogParams::TBTDialogType aType, |
|
197 TBTDialogResourceId aResourceId ); |
|
198 |
|
199 /** |
|
200 * Handle the result from a notification that is finished. |
|
201 * |
|
202 * @since Symbian^4 |
|
203 * @param aErr KErrNone or one of the system-wide error codes. |
|
204 * @param aData The returned data. The actual format |
|
205 * is dependent on the actual notifier. |
|
206 */ |
|
207 void NotificationClosedL( TInt aError, const TDesC8& aData ); |
|
208 |
|
209 private: |
|
210 |
|
211 /** |
|
212 * C++ default constructor |
|
213 */ |
|
214 CBTNotifOutgoingPairingHandler( CBTNotifSecurityManager& aParent, const TBTDevAddr& aAddr ); |
|
215 |
|
216 /** |
|
217 * Symbian 2nd-phase constructor |
|
218 */ |
|
219 void ConstructL(); |
|
220 |
|
221 /** |
|
222 * Starts an actual pair operation. |
|
223 */ |
|
224 void DoPairingL(); |
|
225 |
|
226 /** |
|
227 * Ask the user to retry pairing. |
|
228 */ |
|
229 void ShowPairingRetryDialog(); |
|
230 |
|
231 /** |
|
232 * Tell the user the pairing failed. |
|
233 */ |
|
234 void ShowPairingFailureDialog(); |
|
235 |
|
236 private: // data |
|
237 |
|
238 /** |
|
239 * Socket address of the remote device to pair with. |
|
240 */ |
|
241 TBTSockAddr iSockAddr; |
|
242 |
|
243 /** |
|
244 * The CoD of the device to be paired |
|
245 */ |
|
246 TBTDeviceClass iCod; |
|
247 |
|
248 /** |
|
249 * Dedicated bonding session to the pairing server. |
|
250 */ |
|
251 RBluetoothDedicatedBondingInitiator iBondingSession; |
|
252 |
|
253 /** |
|
254 * socket for creating L2CAP link with the remote device. |
|
255 */ |
|
256 RSocket iSocket; |
|
257 |
|
258 /** |
|
259 * Timer for recovery from Repeated Attempts |
|
260 */ |
|
261 RTimer iTimer; |
|
262 |
|
263 /** |
|
264 * the current pairing mode this class is in |
|
265 */ |
|
266 TBTOutgoingPairMode iPairMode; |
|
267 |
|
268 /** |
|
269 * Pointer to an outstanding user interaction. |
|
270 * Not own. |
|
271 */ |
|
272 CBluetoothNotification* iNotification; |
|
273 |
|
274 /** |
|
275 * Number of pairing attempt |
|
276 */ |
|
277 TInt iPairingAttempt; |
|
278 |
|
279 }; |
|
280 |
|
281 |
|
282 #endif /* BTNOTIFOUTGOINGPAIRINGHANDLER_H_ */ |
|
283 |
|
284 |
|