author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 14 Sep 2010 21:37:10 +0300 | |
branch | RCL_3 |
changeset 61 | 269724087bed |
parent 56 | 9386f31cc85b |
child 72 | 4b59561a31c0 |
permissions | -rw-r--r-- |
56 | 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: Declares Numeric Comparison notifier for Secure Simle Pairing |
|
15 |
* |
|
16 |
*/ |
|
17 |
||
18 |
||
19 |
// INCLUDE FILES |
|
20 |
#include <StringLoader.h> // Localisation stringloader |
|
21 |
#include <utf.h> // Unicode character conversion utilities |
|
22 |
#include <avkon.mbg> |
|
23 |
#ifndef SYMBIAN_ENABLE_SPLIT_HEADERS |
|
24 |
#include <btextnotifiers.h> |
|
25 |
#else |
|
26 |
#include <btextnotifiers.h> |
|
27 |
#include <btextnotifierspartner.h> |
|
28 |
#endif |
|
29 |
#include <BTNotif.rsg> // Own resources |
|
30 |
#include "btnotif.hrh" // Own resource header |
|
31 |
#include "btnumcmpnotifier.h" // Own class definition |
|
32 |
#include "btNotifDebug.h" // Debugging macros |
|
33 |
#include <btotgpairpub.inl> |
|
34 |
#include <btengconnman.h> |
|
35 |
#include <SecondaryDisplay/BTnotifSecondaryDisplayAPI.h> |
|
36 |
#include <bluetoothuiutil.h> |
|
37 |
#include "btnotifnameutils.h" |
|
38 |
||
39 |
#ifdef __SERIES60_HELP |
|
40 |
#include <hlplch.h> |
|
41 |
#include <csxhelp/bt.hlp.hrh> // The bt hrh info is needed, for help launching |
|
42 |
#endif |
|
43 |
||
44 |
// ================= MEMBER FUNCTIONS ======================= |
|
45 |
||
46 |
// ---------------------------------------------------------- |
|
47 |
// CBTNumCmpNotifier::NewL |
|
48 |
// Two-phased constructor. |
|
49 |
// ---------------------------------------------------------- |
|
50 |
// |
|
51 |
CBTNumCmpNotifier* CBTNumCmpNotifier::NewL() |
|
52 |
{ |
|
53 |
CBTNumCmpNotifier* self=new (ELeave) CBTNumCmpNotifier(); |
|
54 |
CleanupStack::PushL(self); |
|
55 |
self->ConstructL(); |
|
56 |
CleanupStack::Pop(self); |
|
57 |
return self; |
|
58 |
} |
|
59 |
||
60 |
// ---------------------------------------------------------- |
|
61 |
// CBTNumCmpNotifier::CBTNumCmpNotifier |
|
62 |
// C++ default constructor can NOT contain any code, that |
|
63 |
// might leave. |
|
64 |
// ---------------------------------------------------------- |
|
65 |
// |
|
66 |
CBTNumCmpNotifier::CBTNumCmpNotifier() |
|
67 |
{ |
|
68 |
iPasskeyToShow.Zero(); |
|
69 |
} |
|
70 |
||
71 |
// ---------------------------------------------------------- |
|
72 |
// Destructor |
|
73 |
// ---------------------------------------------------------- |
|
74 |
// |
|
75 |
CBTNumCmpNotifier::~CBTNumCmpNotifier() |
|
76 |
{ |
|
77 |
} |
|
78 |
||
79 |
// ---------------------------------------------------------- |
|
80 |
// CBTNumCmpNotifier::RegisterL |
|
81 |
// Register notifier. |
|
82 |
// ---------------------------------------------------------- |
|
83 |
// |
|
84 |
CBTNumCmpNotifier::TNotifierInfo CBTNumCmpNotifier::RegisterL() |
|
85 |
{ |
|
86 |
iInfo.iUid = KBTNumericComparisonNotifierUid; |
|
87 |
iInfo.iChannel = KBTNumericComparisonNotifierUid; |
|
88 |
iInfo.iPriority=ENotifierPriorityVHigh; |
|
89 |
return iInfo; |
|
90 |
} |
|
91 |
||
92 |
// ---------------------------------------------------------- |
|
61
269724087bed
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
93 |
// CBTNumCmpNotifier::ProcessStartParamsL |
56 | 94 |
// Initialize parameters and check if device is already |
95 |
// in registry. Jump to RunL as soon as possible. |
|
96 |
// ---------------------------------------------------------- |
|
97 |
// |
|
61
269724087bed
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
98 |
void CBTNumCmpNotifier::ProcessStartParamsL() |
56 | 99 |
{ |
61
269724087bed
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
100 |
FLOG(_L("[BTNOTIF]\t CBTNumCmpNotifier::ProcessStartParamsL()")); |
56 | 101 |
|
61
269724087bed
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
102 |
CBTNPairNotifierBase::ProcessStartParamsL(); |
56 | 103 |
|
104 |
TBTNumericComparisonParamsPckg pckg; |
|
61
269724087bed
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
105 |
pckg.Copy(*iParamBuffer); |
56 | 106 |
iBTAddr = pckg().DeviceAddress(); |
107 |
if ( OtherOutgoPairing( iBTAddr) ) |
|
108 |
{ |
|
109 |
// We won't allow incoming pairing during outgoing pairing: |
|
110 |
FLOG(_L("[BTNOTIF]\t CBTNumCmpNotifier: outgoing pair in progress, reject incoming pair")); |
|
111 |
CompleteMessage(KErrCancel); |
|
112 |
return; |
|
113 |
} |
|
114 |
||
115 |
TUint32 passkey = pckg().NumericalValue(); |
|
116 |
iLocallyInitiated = pckg().LocallyInitiated(); |
|
117 |
iPasskeyToShow.AppendNumFixedWidth(passkey, EDecimal, Klength); |
|
118 |
iPasskeyToShow.Insert(3,_L(" ")); |
|
119 |
||
120 |
// base class |
|
121 |
ProcessParamsGetDeviceL( iBTAddr, pckg().DeviceName() ); |
|
122 |
||
61
269724087bed
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
123 |
FLOG(_L("[BTNOTIF]\t CBTNumCmpNotifier::ProcessStartParamsL() completed")); |
56 | 124 |
} |
125 |
||
126 |
// ---------------------------------------------------------- |
|
127 |
// CBTNumCmpNotifier::HandleGetDeviceCompletedL |
|
128 |
// Ask user response and return it to caller. |
|
129 |
// Store device into registry if user has accepted pairing. |
|
130 |
// ---------------------------------------------------------- |
|
131 |
// |
|
132 |
void CBTNumCmpNotifier::HandleGetDeviceCompletedL(const CBTDevice* /*aDev*/) |
|
133 |
{ |
|
134 |
FLOG(_L("[BTNOTIF]\t CBTNumCmpNotifier::HandleGetDeviceCompletedL()")); |
|
135 |
||
136 |
// Check if blocked device. |
|
137 |
if( CheckBlockedDeviceL() ) |
|
138 |
return; |
|
139 |
||
140 |
// Turn lights on and deactivate apps -key |
|
141 |
iNotifUiUtil->TurnLightsOn(); |
|
142 |
||
143 |
// For incoming pairing request |
|
144 |
if(!iLocallyInitiated) |
|
145 |
{ |
|
146 |
TBool keypress = AuthoriseIncomingPairingL(); |
|
147 |
if( !keypress ) |
|
148 |
{ |
|
149 |
//User rejects the incoming pairing, complete message in QueryBlockDevice. |
|
150 |
FLOG(_L("[BTNOTIF]\t CBTNumCmpNotifier::HandleGetDeviceCompletedL() <<")); |
|
151 |
return; |
|
152 |
} |
|
153 |
} |
|
154 |
||
155 |
// For outgoing pairing request or accepted incoming pairing request, |
|
156 |
// ask user to compare the pincodes in two devices. |
|
157 |
TBTDeviceName nameCoverUi( KNullDesC ); |
|
158 |
RBuf prompt; |
|
159 |
prompt.CleanupClosePushL(); |
|
160 |
GenerateQueryPromptL( prompt ); |
|
161 |
TInt answer = iNotifUiUtil->ShowQueryL( prompt, R_BT_GENERIC_QUERY, ECmdShowBtOpenCoverNote, nameCoverUi ); |
|
162 |
CleanupStack::PopAndDestroy( &prompt ); |
|
163 |
||
164 |
if( answer ) |
|
165 |
{ |
|
166 |
CompleteMessage(answer, KErrNone); |
|
167 |
} |
|
168 |
else |
|
169 |
{ |
|
170 |
// If the outgoing pairing mode is set, then this is bonding initiated by the user. |
|
171 |
TBool incomingConn = ( OutgoPairingMode( iBTAddr ) == EBTOutgoingPairNone ); |
|
172 |
||
173 |
if( !iMessage.IsNull() ) |
|
174 |
{ |
|
175 |
// No need to inform the user of the pairing result if the user cancelled it. |
|
176 |
// If user doesn't answer anything but stack cancels, pairing result is needed |
|
177 |
// to show for outgoing pairing. In this case, don't stop pairng observer. |
|
178 |
CBTEngConnMan::StopPairingObserver( iBTAddr ); |
|
179 |
} |
|
180 |
// We may be asking for pairing (locally initiated), because a remote device is requesting |
|
181 |
// accesss to a service for which we require authentication. |
|
182 |
if( iLocallyInitiated && incomingConn ) |
|
183 |
{ |
|
184 |
CheckAndHandleQueryIntervalL(); |
|
185 |
} |
|
186 |
CompleteMessage(KErrCancel); |
|
187 |
} |
|
188 |
||
189 |
FLOG(_L("[BTNOTIF]\t CBTNumCmpNotifier::HandleGetDeviceCompletedL() completed")); |
|
190 |
} |
|
191 |
||
192 |
// ---------------------------------------------------------- |
|
193 |
// CBTNumCmpNotifier::GenerateQueryPromptL |
|
194 |
// Generate prompt for Numeric Comparison query and return. |
|
195 |
// ---------------------------------------------------------- |
|
196 |
// |
|
197 |
void CBTNumCmpNotifier::GenerateQueryPromptL( RBuf& aRBuf ) |
|
198 |
{ |
|
199 |
FLOG(_L("[BTNOTIF]\t CBTNumCmpNotifier::GenerateQueryPromptL()")); |
|
200 |
TBTDeviceName devName; |
|
201 |
BtNotifNameUtils::GetDeviceDisplayName( devName, iDevice ); |
|
202 |
TBuf<KBTDeviceShortNameLength> shortName; |
|
203 |
||
204 |
TPtrC namePtr; |
|
205 |
// Cut the name and put ellipsis in the middle if necessary |
|
206 |
// By example "SampleSymbianDevice" after this operation will be shown in |
|
207 |
// the dialog as "Sam...ice"(for 7 chars device name limit) |
|
208 |
// This need to be done, because if name of the device is too long, the PIN |
|
209 |
// codes aren't visible and user can't compare it with PIN code taken from |
|
210 |
// other phone |
|
211 |
if ( devName.Length() > KBTDeviceShortNameLength ) |
|
212 |
{ |
|
213 |
shortName.Copy( devName.Left( KBTDeviceShortNameLength/2 ) ); |
|
214 |
//adding ellipsis ("...") char in the middle of the string |
|
215 |
shortName.Append( TChar( KEllipsis) ); |
|
216 |
//adding only end of the name to the final string |
|
217 |
shortName.Append( devName.Right( shortName.MaxLength() - |
|
218 |
shortName.Length() ) ); |
|
219 |
namePtr.Set( shortName ); |
|
220 |
} |
|
221 |
else |
|
222 |
{ |
|
223 |
namePtr.Set( devName ); |
|
224 |
} |
|
225 |
||
226 |
BluetoothUiUtil::LoadResourceAndSubstringL( |
|
227 |
aRBuf, R_BT_SSP_PASSKEY_COMPARISON_PROMPT, namePtr, 0 ); |
|
228 |
// Numeric comparison key shall not be localized either, use our own |
|
229 |
// string loading: |
|
230 |
BluetoothUiUtil::AddSubstringL( aRBuf, iPasskeyToShow, 1); |
|
231 |
FLOG(_L("[BTNOTIF]\t CBTNumCmpNotifier::GenerateQueryPromptL() <<")); |
|
232 |
||
233 |
} |
|
234 |
||
235 |
// End of File |