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: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "btnotifpairnotifier.h" |
|
19 #include "btnotifclientserver.h" |
|
20 #include <btextnotifiers.h> |
|
21 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS |
|
22 #include <btextnotifierspartner.h> |
|
23 #endif |
|
24 #include "btnotifconnectiontracker.h" |
|
25 #include "btnotifsecuritymanager.h" |
|
26 #include "btnotificationmanager.h" |
|
27 #include "bluetoothnotification.h" |
|
28 #include "btnotifserver.h" |
|
29 #include "bluetoothtrace.h" |
|
30 |
|
31 |
|
32 /** Format syntax for numeric comparison value. */ |
|
33 _LIT( KNumCompFormat, "%06u" ); |
|
34 /** Format syntax for passkey display value. */ |
|
35 _LIT( KPassKeyFormat, "%06u" ); |
|
36 |
|
37 |
|
38 // ======== MEMBER FUNCTIONS ======== |
|
39 |
|
40 // --------------------------------------------------------------------------- |
|
41 // C++ default constructor. |
|
42 // --------------------------------------------------------------------------- |
|
43 // |
|
44 CBTNotifPairNotifier::CBTNotifPairNotifier( |
|
45 CBTNotifSecurityManager& aParent ) |
|
46 : iParent( aParent ) |
|
47 { |
|
48 } |
|
49 |
|
50 // --------------------------------------------------------------------------- |
|
51 // Symbian 2nd-phase constructor. |
|
52 // --------------------------------------------------------------------------- |
|
53 // |
|
54 void CBTNotifPairNotifier::ConstructL() |
|
55 { |
|
56 } |
|
57 |
|
58 // --------------------------------------------------------------------------- |
|
59 // NewL |
|
60 // --------------------------------------------------------------------------- |
|
61 // |
|
62 CBTNotifPairNotifier* CBTNotifPairNotifier::NewL( |
|
63 CBTNotifSecurityManager& aParent ) |
|
64 { |
|
65 BOstraceFunctionEntry0( DUMMY_DEVLIST ); |
|
66 CBTNotifPairNotifier* self = new( ELeave ) CBTNotifPairNotifier( aParent ); |
|
67 CleanupStack::PushL( self ); |
|
68 self->ConstructL(); |
|
69 CleanupStack::Pop( self ); |
|
70 BOstraceFunctionExit0( DUMMY_DEVLIST ); |
|
71 return self; |
|
72 } |
|
73 |
|
74 |
|
75 // --------------------------------------------------------------------------- |
|
76 // Destructor. |
|
77 // --------------------------------------------------------------------------- |
|
78 // |
|
79 CBTNotifPairNotifier::~CBTNotifPairNotifier() |
|
80 { |
|
81 BOstraceFunctionEntry0( DUMMY_DEVLIST ); |
|
82 if( iNotification ) |
|
83 { |
|
84 // Clear the notification callback, we cannot receive them anymore. |
|
85 iNotification->RemoveObserver(); |
|
86 iNotification->Close(); // Also dequeues the notification from the queue. |
|
87 iNotification = NULL; |
|
88 } |
|
89 iParams.Close(); |
|
90 if ( !iNotifierMessage.IsNull() ) |
|
91 { |
|
92 iNotifierMessage.Complete( KErrServerTerminated ); |
|
93 } |
|
94 BOstraceFunctionExit0( DUMMY_DEVLIST ); |
|
95 } |
|
96 |
|
97 // --------------------------------------------------------------------------- |
|
98 // Handle a notifier request for pairing with a remote device. |
|
99 // --------------------------------------------------------------------------- |
|
100 // |
|
101 void CBTNotifPairNotifier::StartPairingNotifierL(const RMessage2& aMessage ) |
|
102 { |
|
103 BOstraceFunctionEntry0( DUMMY_DEVLIST ); |
|
104 |
|
105 TInt uid = aMessage.Int0(); |
|
106 TInt opCode = aMessage.Function(); |
|
107 BOstrace1(TRACE_DEBUG,DUMMY_DEVLIST,"[BTNotif]:Opcode: %d",opCode); |
|
108 |
|
109 if ( (!iNotifierMessage.IsNull()) && |
|
110 (opCode != EBTNotifCancelNotifier )&&(opCode != EBTNotifUpdateNotifier)) |
|
111 { |
|
112 // todo: do we allow concurrent pairing? |
|
113 BOstrace0(TRACE_DEBUG,DUMMY_DEVLIST,"[BTNotif]:We are busy"); |
|
114 User::Leave(KErrServerBusy ); |
|
115 } |
|
116 |
|
117 if(opCode == EBTNotifCancelNotifier){ |
|
118 CancelPairingNotifierL(uid); |
|
119 aMessage.Complete(KErrNone); |
|
120 return; |
|
121 } |
|
122 |
|
123 // Store the parameters locally, we need them later again. |
|
124 iParams.CreateL( aMessage.GetDesLengthL( EBTNotifSrvParamSlot ) ); |
|
125 aMessage.ReadL( EBTNotifSrvParamSlot, iParams ); |
|
126 iNotifierMessage = aMessage; |
|
127 |
|
128 // Read the notifier parameters |
|
129 ParseNotifierReqParamsL(); |
|
130 |
|
131 if(opCode ==EBTNotifUpdateNotifier ){ |
|
132 UpdatePairingNotifierL(uid,iParams); |
|
133 aMessage.Complete(KErrNone); |
|
134 return; |
|
135 } |
|
136 |
|
137 const CBtDevExtension* dev = iParent.BTDevRepository().Device(iRemote); |
|
138 if(dev) |
|
139 { |
|
140 if (!iLocallyInitiated && dev->Device().GlobalSecurity().Banned() ) |
|
141 { |
|
142 // If the device is banned and pairing is not locally initiated |
|
143 // then we reject. |
|
144 BOstrace0(TRACE_DEBUG,DUMMY_DEVLIST,"[BTNotif]:Device is banned"); |
|
145 iNotifierMessage.Complete( KErrCancel ); |
|
146 return; |
|
147 } |
|
148 if (iLocallyInitiated && dev->Device().GlobalSecurity().Banned()) |
|
149 { |
|
150 // Remove the banned device from the blocking history |
|
151 iParent.ConnectionTracker().UpdateBlockingHistoryL(&dev->Device(),ETrue); |
|
152 iParent.BlockDevice(dev->Addr(),EFalse); |
|
153 } |
|
154 if(0 != dev->Device().FriendlyName().Length()&& dev->Device().IsValidFriendlyName()) |
|
155 { |
|
156 // If we have a friendly name use it for the UI |
|
157 iCurrentDeviceName = dev->Device().FriendlyName(); |
|
158 } |
|
159 else |
|
160 { |
|
161 // We don't have any friendly name then chek if we have the device name |
|
162 // otherwise use the Alias |
|
163 if(0 >= iCurrentDeviceName.Length()) |
|
164 { |
|
165 iCurrentDeviceName = dev->Alias(); |
|
166 } |
|
167 } |
|
168 } |
|
169 else |
|
170 { |
|
171 //If we didn't get a name then we make one from the Bluetooth device address |
|
172 if(0 >= iCurrentDeviceName.Length()) |
|
173 { |
|
174 iRemote.GetReadable(iCurrentDeviceName); |
|
175 } |
|
176 } |
|
177 // If this is an incoming pairing, we first ask the user to accept it. |
|
178 if( !iLocallyInitiated ) |
|
179 { |
|
180 User::LeaveIfError(iParent.SetPairObserver(iRemote,ETrue)); |
|
181 StartAcceptPairingQueryL(); |
|
182 } |
|
183 else |
|
184 { |
|
185 TInt uid = iNotifierMessage.Int0(); |
|
186 if(uid == KBTNumericComparisonNotifierUid.iUid) |
|
187 { |
|
188 StartPairingUserInputL(); |
|
189 } |
|
190 else |
|
191 { |
|
192 TBTPinCode pinCode; |
|
193 if ( iMinPinLength > -1 ) |
|
194 { |
|
195 // Legacy Pin pairing. Check if a pin code is already available |
|
196 // in pairing manager for this device: |
|
197 iParent.GetPinCode( pinCode, iRemote, iMinPinLength ); |
|
198 } |
|
199 if ( pinCode().iLength > 0 ) |
|
200 { |
|
201 // a pin is ready for this pairing. |
|
202 // write it back to client (stack) |
|
203 TInt err = iNotifierMessage.Write( EBTNotifSrvReplySlot, pinCode ); |
|
204 iNotifierMessage.Complete( err ); |
|
205 } |
|
206 else |
|
207 { |
|
208 // no pin code is available or a pin code does not meet |
|
209 // the security requirement. |
|
210 // User need to interact: |
|
211 StartPairingUserInputL(); |
|
212 } |
|
213 } |
|
214 } |
|
215 BOstraceFunctionExit1( DUMMY_DEVLIST, this ); |
|
216 } |
|
217 |
|
218 // --------------------------------------------------------------------------- |
|
219 // Update a notifier, update the outstanding dialog if the notifier request |
|
220 // is currently being served. |
|
221 // --------------------------------------------------------------------------- |
|
222 // |
|
223 void CBTNotifPairNotifier::UpdatePairingNotifierL( TInt aUid, const TDesC8& aParams ) |
|
224 { |
|
225 BOstraceFunctionEntry0( DUMMY_DEVLIST ); |
|
226 (void) aUid; |
|
227 TBTNotifierUpdateParams2 params; // Enough for reading the base class type parameter |
|
228 TPckgC<TBTNotifierUpdateParams2> paramsPckg( params ); |
|
229 paramsPckg.Set( aParams ); |
|
230 if( paramsPckg().Type() == TBTNotifierUpdateParams2::EPasskeyDisplay ) |
|
231 { |
|
232 // Paskey display update - keypress on remote device. |
|
233 } |
|
234 else |
|
235 { |
|
236 // name update |
|
237 TBTDeviceNameUpdateParams nameUpdate; |
|
238 TPckgC<TBTDeviceNameUpdateParams> nameUpdatePckg( nameUpdate ); |
|
239 nameUpdatePckg.Set( aParams ); |
|
240 // The result means result of conversion to unicode |
|
241 if( !nameUpdatePckg().Result() ) |
|
242 { |
|
243 // Check first if we already have a friendly name |
|
244 const CBtDevExtension* dev = iParent.BTDevRepository().Device(iRemote); |
|
245 if(dev) |
|
246 { |
|
247 if(0 != dev->Device().FriendlyName().Length()&& dev->Device().IsValidFriendlyName()) |
|
248 { |
|
249 return; |
|
250 } |
|
251 // We don't have a friendly name then use this name |
|
252 iCurrentDeviceName = nameUpdatePckg().DeviceName(); |
|
253 if(0 == iCurrentDeviceName.Length()) |
|
254 { |
|
255 // The new name is empty then use the Alias |
|
256 iCurrentDeviceName = dev->Alias(); |
|
257 } |
|
258 } |
|
259 else |
|
260 { |
|
261 // We don't have a friendly name then use this name |
|
262 iCurrentDeviceName = nameUpdatePckg().DeviceName(); |
|
263 if(0 == iCurrentDeviceName.Length()) |
|
264 { |
|
265 // The new name is empty then use the Alias |
|
266 iRemote.GetReadable(iCurrentDeviceName); |
|
267 } |
|
268 } |
|
269 if( iNotification ) |
|
270 { |
|
271 // Update the dialog with the new name. It is up to the dialog to |
|
272 // determine the validity (in case another dialog is shown). |
|
273 iNotification->Update(iCurrentDeviceName); |
|
274 } |
|
275 } |
|
276 } |
|
277 BOstraceFunctionExit0( DUMMY_DEVLIST ); |
|
278 } |
|
279 |
|
280 // --------------------------------------------------------------------------- |
|
281 // Cancel a request, dismiss the outstanding dialog if the notifier request |
|
282 // is currently being served. |
|
283 // --------------------------------------------------------------------------- |
|
284 // |
|
285 void CBTNotifPairNotifier::CancelPairingNotifierL( TInt aUid ) |
|
286 { |
|
287 BOstraceFunctionEntry0( DUMMY_DEVLIST ); |
|
288 if( iNotifierMessage.Int0() == aUid ) |
|
289 { |
|
290 if( iNotification ) |
|
291 { |
|
292 // Cancel the user query |
|
293 // This will also unregister us from the notification. |
|
294 TInt err = iNotification->Close(); |
|
295 NOTIF_NOTHANDLED( !err ) |
|
296 iNotification = NULL; |
|
297 } |
|
298 // todo: Any bonding requester needs to be informed. |
|
299 // Currently we don't show any "Unable to pair" note |
|
300 // so no need to inform any bonding requester. |
|
301 if ( !iNotifierMessage.IsNull() ) |
|
302 { |
|
303 iNotifierMessage.Complete( KErrCancel ); |
|
304 } |
|
305 } |
|
306 BOstraceFunctionExit0( DUMMY_DEVLIST ); |
|
307 } |
|
308 |
|
309 // --------------------------------------------------------------------------- |
|
310 // From class MBTNotificationResult. |
|
311 // Handle a result from a user query. |
|
312 // --------------------------------------------------------------------------- |
|
313 // |
|
314 void CBTNotifPairNotifier::MBRDataReceived( CHbSymbianVariantMap& aData ) |
|
315 { |
|
316 BOstraceFunctionEntry0( DUMMY_DEVLIST ); |
|
317 if(aData.Keys().MdcaPoint(0).Compare(_L("actionResult")) == 0) |
|
318 { |
|
319 TInt val = *(static_cast<TInt*>(aData.Get(_L("actionResult"))->Data())); |
|
320 if(val) |
|
321 { |
|
322 iAcceptPairingResult = ETrue; |
|
323 } |
|
324 else |
|
325 { |
|
326 iAcceptPairingResult = EFalse; |
|
327 } |
|
328 } |
|
329 else if(aData.Keys().MdcaPoint(0).Compare(_L("checkBoxState")) == 0) |
|
330 { |
|
331 iCheckBoxState = *(static_cast<TInt*>(aData.Get(_L("checkBoxState"))->Data())); |
|
332 } |
|
333 BOstraceFunctionExit0( DUMMY_DEVLIST ); |
|
334 } |
|
335 |
|
336 // --------------------------------------------------------------------------- |
|
337 // From class MBTNotificationResult. |
|
338 // The notification is finished. |
|
339 // --------------------------------------------------------------------------- |
|
340 // |
|
341 void CBTNotifPairNotifier::MBRNotificationClosed( TInt aError, const TDesC8& aData ) |
|
342 { |
|
343 BOstraceFunctionEntryExt( DUMMY_DEVLIST, this, aError ); |
|
344 // First unregister from the notification, so we can already get the next one. |
|
345 iNotification->RemoveObserver(); |
|
346 iNotification = NULL; |
|
347 TRAP_IGNORE( NotificationClosedL( aError, aData ) ); |
|
348 BOstraceFunctionExit1( DUMMY_DEVLIST, this ); |
|
349 } |
|
350 |
|
351 // --------------------------------------------------------------------------- |
|
352 // Request a user input for the outstanding pairing request. |
|
353 // --------------------------------------------------------------------------- |
|
354 // |
|
355 void CBTNotifPairNotifier::StartPairingUserInputL() |
|
356 { |
|
357 BOstraceFunctionEntry0( DUMMY_DEVLIST ); |
|
358 PrepareNotificationL( iDialog, iDialogResource ); |
|
359 iState = EPairingInputConfirm; |
|
360 BOstraceFunctionExit0( DUMMY_DEVLIST ); |
|
361 } |
|
362 |
|
363 // --------------------------------------------------------------------------- |
|
364 // Process the user input and complete the outstanding pairing request. |
|
365 // --------------------------------------------------------------------------- |
|
366 // |
|
367 void CBTNotifPairNotifier::CompletePairingNotifierL( TInt aError, TBool aResult, |
|
368 const TDesC8& aData ) |
|
369 { |
|
370 BOstraceFunctionEntryExt( DUMMY_DEVLIST, this, aError ); |
|
371 if ( iNotifierMessage.IsNull() ) |
|
372 { |
|
373 // Request not anymore active -> ignore |
|
374 return; |
|
375 } |
|
376 TInt err = aError; |
|
377 TPtrC8 resultData(KNullDesC8); |
|
378 TBTPinCode pinCode; |
|
379 TPckgBuf<TBool> userAcceptance; |
|
380 TInt uid = iNotifierMessage.Int0(); |
|
381 |
|
382 if( !err ) |
|
383 { |
|
384 // The returned data is the entered passkey. |
|
385 const CBtDevExtension* dev = iParent.BTDevRepository().Device(iRemote); |
|
386 if(dev) |
|
387 { |
|
388 iParent.ConnectionTracker().UpdateBlockingHistoryL(&dev->Device(),aResult); |
|
389 } |
|
390 if( uid == KBTNumericComparisonNotifierUid.iUid ) |
|
391 { |
|
392 // Numeric comparison needs the boolean result passed back. |
|
393 userAcceptance() = aResult; |
|
394 resultData.Set( userAcceptance ); |
|
395 } |
|
396 if( aResult ) |
|
397 { |
|
398 if( uid == KBTManPinNotifierUid.iUid |
|
399 || uid == KBTPinCodeEntryNotifierUid.iUid ) |
|
400 { |
|
401 // Check the passkey entered by the user. |
|
402 // The length of the returned data equals the number of characters |
|
403 // entered by the user. |
|
404 // Check that the passkey length do not exceed the maximum allowed size |
|
405 TInt pinCodeLength = aData.Length(); |
|
406 if(pinCodeLength > KHCIPINCodeSize) |
|
407 { |
|
408 pinCodeLength = KHCIPINCodeSize; |
|
409 } |
|
410 pinCode().iLength = pinCodeLength; |
|
411 // Check that the length of the passkey meets the minimum |
|
412 // required pin code length |
|
413 if( pinCodeLength >= iMinPinLength ) |
|
414 { |
|
415 for( TInt i = 0; i < pinCodeLength; i++ ) |
|
416 { |
|
417 pinCode().iPIN[i] = aData[i]; |
|
418 } |
|
419 resultData.Set( pinCode ); |
|
420 } |
|
421 else |
|
422 { |
|
423 // shouldn't happen since the length is checked in the dialog |
|
424 err = KErrCompletion; |
|
425 } |
|
426 } |
|
427 } |
|
428 else |
|
429 { |
|
430 err = KErrCancel; |
|
431 } |
|
432 } |
|
433 // Complete the message with the result, and result data if any. |
|
434 if ( !err && resultData.Length() ) |
|
435 { |
|
436 err = iNotifierMessage.Write( EBTNotifSrvReplySlot, resultData ); |
|
437 } |
|
438 if(err && (uid == KBTNumericComparisonNotifierUid.iUid)) |
|
439 { |
|
440 // We need to reject the numeric comparaison otherwise |
|
441 // the link will remain active |
|
442 userAcceptance() = aResult; |
|
443 resultData.Set( userAcceptance ); |
|
444 err = iNotifierMessage.Write( EBTNotifSrvReplySlot, resultData ); |
|
445 } |
|
446 iNotifierMessage.Complete( err ); |
|
447 BOstraceFunctionExit1( DUMMY_DEVLIST, this ); |
|
448 } |
|
449 |
|
450 // --------------------------------------------------------------------------- |
|
451 // Ask the user to allow incoming pairing. |
|
452 // --------------------------------------------------------------------------- |
|
453 // |
|
454 void CBTNotifPairNotifier::StartAcceptPairingQueryL() |
|
455 { |
|
456 BOstraceFunctionEntry0( DUMMY_DEVLIST ); |
|
457 PrepareNotificationL( TBluetoothDialogParams::EUserAuthorization, EAuthorization ); |
|
458 iState = EIncomingPairingAcceptconfirm; |
|
459 // if rejected, the client message is completed in CompleteAcceptPairingQueryL |
|
460 BOstraceFunctionExit0( DUMMY_DEVLIST ); |
|
461 } |
|
462 |
|
463 // --------------------------------------------------------------------------- |
|
464 // The user was asked to accept an incoming pairing. Process and proceed. |
|
465 // --------------------------------------------------------------------------- |
|
466 // |
|
467 void CBTNotifPairNotifier::CompleteAcceptPairingQueryL( TInt aError) |
|
468 { |
|
469 BOstraceFunctionEntry0( DUMMY_DEVLIST ); |
|
470 TInt err = aError; |
|
471 TBool proceed = EFalse; |
|
472 |
|
473 if( !err ) |
|
474 { |
|
475 const CBtDevExtension* dev = iParent.BTDevRepository().Device(iRemote); |
|
476 if(dev) |
|
477 { |
|
478 proceed = iParent.ConnectionTracker().UpdateBlockingHistoryL(&dev->Device(),iAcceptPairingResult); |
|
479 } |
|
480 if( iAcceptPairingResult ) |
|
481 { |
|
482 // User accepted, continue to show pairing query. |
|
483 // Trust the device |
|
484 if(iCheckBoxState){ |
|
485 iParent.TrustDevice(iRemote); |
|
486 } |
|
487 StartPairingUserInputL(); |
|
488 } |
|
489 else |
|
490 { |
|
491 if( proceed && iCheckBoxState ) |
|
492 { |
|
493 //ask to block the device. |
|
494 iParent.BlockDevice(iRemote,proceed); |
|
495 } |
|
496 err = iParent.SetPairObserver(iRemote,EFalse); |
|
497 err = KErrCancel; // We need to complete the pairing request here |
|
498 } |
|
499 } |
|
500 if( err ) |
|
501 { |
|
502 // The user denied the connection, or something else prevented completion. |
|
503 CompletePairingNotifierL( err, EFalse, KNullDesC8 ); |
|
504 } |
|
505 BOstraceFunctionExit0( DUMMY_DEVLIST ); |
|
506 } |
|
507 |
|
508 // --------------------------------------------------------------------------- |
|
509 // Parse the parameters of a request for pairing. |
|
510 // --------------------------------------------------------------------------- |
|
511 // |
|
512 void CBTNotifPairNotifier::ParseNotifierReqParamsL() |
|
513 { |
|
514 BOstraceFunctionEntry0( DUMMY_DEVLIST ); |
|
515 // Reset to make sure all vars contain initial values. |
|
516 iLocallyInitiated = EFalse; |
|
517 iDialogNumeric.Zero(); |
|
518 iDialog = TBluetoothDialogParams::EInvalidDialog; |
|
519 iDialogResource = ENoResource; |
|
520 iRemote = TBTDevAddr(); |
|
521 iMinPinLength = -1; |
|
522 |
|
523 TInt uid = iNotifierMessage.Int0(); |
|
524 // Reset for other pairing modes than PIN code. |
|
525 // Determine the notifier type by the length of the parameter buffer |
|
526 if( uid == KBTManPinNotifierUid.iUid || uid == KBTPinCodeEntryNotifierUid.iUid ) |
|
527 { |
|
528 if ( uid == KBTManPinNotifierUid.iUid ) |
|
529 { |
|
530 ParseLegacyPinCodeReqParamsL( iLocallyInitiated, iMinPinLength, iRemote ); |
|
531 } |
|
532 else |
|
533 { |
|
534 ParsePinCodeReqParamsL( iLocallyInitiated, iMinPinLength, iRemote ); |
|
535 } |
|
536 iDialog = TBluetoothDialogParams::EInput; |
|
537 iDialogResource = EPinInput; |
|
538 } |
|
539 else if( uid == KBTNumericComparisonNotifierUid.iUid ) |
|
540 { |
|
541 ParseNumericCompReqParamsL( iLocallyInitiated, iDialogNumeric, iRemote ); |
|
542 iDialog = TBluetoothDialogParams::EQuery; |
|
543 iDialogResource = ENumericComparison; |
|
544 } |
|
545 else if( uid == KBTPasskeyDisplayNotifierUid.iUid ) |
|
546 { |
|
547 ParsePasskeyDisplayReqParamsL( iLocallyInitiated, iDialogNumeric, iRemote ); |
|
548 iDialog = TBluetoothDialogParams::EQuery; |
|
549 iDialogResource = EPasskeyDisplay; |
|
550 } |
|
551 BOstraceFunctionExit0( DUMMY_DEVLIST ); |
|
552 } |
|
553 |
|
554 // --------------------------------------------------------------------------- |
|
555 // Parse the parameters of a request for pairing using pin query. |
|
556 // --------------------------------------------------------------------------- |
|
557 // |
|
558 void CBTNotifPairNotifier::ParseLegacyPinCodeReqParamsL( TBool& aLocallyInitiated, |
|
559 TInt& aMinPinLength, TBTDevAddr& aAddr ) |
|
560 { |
|
561 BOstraceFunctionEntry0( DUMMY_DEVLIST ); |
|
562 TBTPasskeyNotifierParams params; |
|
563 TPckgC<TBTPasskeyNotifierParams> paramsPckg( params ); |
|
564 paramsPckg.Set( iParams ); |
|
565 aLocallyInitiated = paramsPckg().iLocallyInitiated; |
|
566 aMinPinLength = paramsPckg().iPasskeyMinLength; |
|
567 aAddr = paramsPckg().iBDAddr; |
|
568 iCurrentDeviceName = paramsPckg().iName; |
|
569 BOstraceFunctionExit0( DUMMY_DEVLIST ); |
|
570 } |
|
571 |
|
572 // --------------------------------------------------------------------------- |
|
573 // Parse the parameters of a request for pairing using pin query. |
|
574 // --------------------------------------------------------------------------- |
|
575 // |
|
576 void CBTNotifPairNotifier::ParsePinCodeReqParamsL( TBool& aLocallyInitiated, |
|
577 TInt& aMinPinLength, TBTDevAddr& aAddr ) |
|
578 { |
|
579 BOstraceFunctionEntry0( DUMMY_DEVLIST ); |
|
580 TBTPinCodeEntryNotifierParams params; |
|
581 TPckgC<TBTPinCodeEntryNotifierParams> paramsPckg( params ); |
|
582 paramsPckg.Set( iParams ); |
|
583 aLocallyInitiated = paramsPckg().LocallyInitiated(); |
|
584 aMinPinLength = paramsPckg().PinCodeMinLength(); |
|
585 aAddr = paramsPckg().DeviceAddress(); |
|
586 iCurrentDeviceName = paramsPckg().DeviceName(); |
|
587 BOstraceFunctionExit0( DUMMY_DEVLIST ); |
|
588 } |
|
589 |
|
590 // --------------------------------------------------------------------------- |
|
591 // Parse the parameters of a request for pairing using numeric comparison. |
|
592 // --------------------------------------------------------------------------- |
|
593 // |
|
594 void CBTNotifPairNotifier::ParseNumericCompReqParamsL( TBool& aLocallyInitiated, |
|
595 TDes& aNumVal, TBTDevAddr& aAddr ) |
|
596 { |
|
597 BOstraceFunctionEntry0( DUMMY_DEVLIST ); |
|
598 TBTNumericComparisonParams params; |
|
599 TPckgC<TBTNumericComparisonParams> paramsPckg( params ); |
|
600 paramsPckg.Set( iParams ); |
|
601 aLocallyInitiated = paramsPckg().LocallyInitiated(); |
|
602 TBTNumericComparisonParams::TComparisonScenario scenario = |
|
603 paramsPckg().ComparisonScenario(); |
|
604 aNumVal.Format( KNumCompFormat, paramsPckg().NumericalValue() ); |
|
605 aNumVal.Insert(3,_L(" ")); |
|
606 aAddr = paramsPckg().DeviceAddress(); |
|
607 iCurrentDeviceName = paramsPckg().DeviceName(); |
|
608 BOstraceFunctionExit0( DUMMY_DEVLIST ); |
|
609 } |
|
610 |
|
611 // --------------------------------------------------------------------------- |
|
612 // Parse the parameters of a request for pairing using passkey display. |
|
613 // --------------------------------------------------------------------------- |
|
614 // |
|
615 void CBTNotifPairNotifier::ParsePasskeyDisplayReqParamsL( TBool& aLocallyInitiated, |
|
616 TDes& aNumVal, TBTDevAddr& aAddr ) |
|
617 { |
|
618 BOstraceFunctionEntry0( DUMMY_DEVLIST ); |
|
619 TBTPasskeyDisplayParams params; |
|
620 TPckgC<TBTPasskeyDisplayParams> paramsPckg( params ); |
|
621 paramsPckg.Set( iParams ); |
|
622 aLocallyInitiated = paramsPckg().LocallyInitiated(); |
|
623 aNumVal.Format( KPassKeyFormat, paramsPckg().NumericalValue() ); |
|
624 aAddr = paramsPckg().DeviceAddress(); |
|
625 iCurrentDeviceName = paramsPckg().DeviceName(); |
|
626 BOstraceFunctionExit0( DUMMY_DEVLIST ); |
|
627 } |
|
628 |
|
629 // --------------------------------------------------------------------------- |
|
630 // Get and configure a notification. |
|
631 // --------------------------------------------------------------------------- |
|
632 // |
|
633 void CBTNotifPairNotifier::PrepareNotificationL( TBluetoothDialogParams::TBTDialogType aType, |
|
634 TBTDialogResourceId aResourceId ) |
|
635 { |
|
636 BOstraceFunctionEntry0( DUMMY_DEVLIST ); |
|
637 iNotification = |
|
638 iParent.ConnectionTracker().NotificationManager()->GetNotification(); |
|
639 User::LeaveIfNull( iNotification ); // For OOM exception, leaves with KErrNoMemory |
|
640 iNotification->SetObserver( this ); |
|
641 iNotification->SetNotificationType( aType, aResourceId ); |
|
642 TInt err = iNotification->SetData( TBluetoothDeviceDialog::EDeviceName, iCurrentDeviceName ); |
|
643 NOTIF_NOTHANDLED( !err ) |
|
644 TBTDeviceName name; |
|
645 iRemote.GetReadable(name); |
|
646 err = iNotification->SetData( TBluetoothDialogParams::EAddress, name ); |
|
647 NOTIF_NOTHANDLED( !err ) |
|
648 const CBtDevExtension* dev = iParent.BTDevRepository().Device(iRemote); |
|
649 TInt classofdevice = 0; |
|
650 if(dev) |
|
651 { |
|
652 if(dev->Device().IsValidDeviceClass()) |
|
653 { |
|
654 classofdevice = dev->Device().DeviceClass().DeviceClass(); |
|
655 } |
|
656 } |
|
657 err = iNotification->SetData( (TInt) TBluetoothDeviceDialog::EDeviceClass, |
|
658 classofdevice ); |
|
659 if( iDialogNumeric.Length() ) |
|
660 { |
|
661 err = iNotification->SetData( |
|
662 TBluetoothDeviceDialog::EAdditionalDesc, iDialogNumeric ); |
|
663 } |
|
664 err = iNotification->SetData( TBluetoothDialogParams::EDialogTitle, TBluetoothDialogParams::EPairingRequest); |
|
665 iCheckBoxState = ETrue; |
|
666 iAcceptPairingResult = EFalse; |
|
667 iParent.ConnectionTracker().NotificationManager()->QueueNotificationL( iNotification); |
|
668 NOTIF_NOTHANDLED( !err ) |
|
669 BOstraceFunctionExit0( DUMMY_DEVLIST ); |
|
670 } |
|
671 |
|
672 // --------------------------------------------------------------------------- |
|
673 // The notification is finished, handle the result. |
|
674 // --------------------------------------------------------------------------- |
|
675 // |
|
676 void CBTNotifPairNotifier::NotificationClosedL( TInt aError, const TDesC8& aData ) |
|
677 { |
|
678 BOstraceFunctionEntryExt( DUMMY_DEVLIST, this, aError ); |
|
679 // Read the result. |
|
680 TPckgC<TBool> result( EFalse ); |
|
681 result.Set( aData.Ptr(), result.Length() ); // Read the part containing the result |
|
682 // Set a pointer descriptor to capture the remaining data, if any. |
|
683 TPtrC8 dataPtr( aData.Mid( result.Length() ) ); |
|
684 |
|
685 if ( iState == EIncomingPairingAcceptconfirm ) |
|
686 { |
|
687 CompleteAcceptPairingQueryL(aError); |
|
688 } |
|
689 else |
|
690 { |
|
691 CompletePairingNotifierL( aError, result(), dataPtr ); |
|
692 } |
|
693 BOstraceFunctionExit1( DUMMY_DEVLIST, this ); |
|
694 } |
|
695 |
|
696 |
|
697 |
|
698 |
|