|
1 /* |
|
2 * Copyright (c) 2002 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 authentication (PIN query) notifier class. |
|
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 #include <btengconnman.h> |
|
24 #include <btotgpairpub.inl> |
|
25 #include <btextnotifiers.h> |
|
26 #include <BTNotif.rsg> // Own resources |
|
27 #include <bluetoothuiutil.h> |
|
28 #include "btnotif.hrh" // Own resource header |
|
29 #include "btnpinnotifier.h" // Own class definition |
|
30 #include "btNotifDebug.h" // Debugging macros |
|
31 #include "btnotifnameutils.h" |
|
32 |
|
33 #ifndef SYMBIAN_ENABLE_SPLIT_HEADERS |
|
34 #include <btextnotifiers.h> |
|
35 #else |
|
36 #include <btextnotifiers.h> |
|
37 #include <btextnotifierspartner.h> |
|
38 #endif |
|
39 |
|
40 #include <SecondaryDisplay/BTnotifSecondaryDisplayAPI.h> |
|
41 |
|
42 #ifdef __SERIES60_HELP |
|
43 #include <hlplch.h> |
|
44 #include <csxhelp/bt.hlp.hrh> // The bt hrh info is needed, for help launching |
|
45 #endif |
|
46 const TInt KDefaultPinCodeLength=4; |
|
47 const TUint8 KZeroPinValue = '0'; |
|
48 |
|
49 // ================= MEMBER FUNCTIONS ======================= |
|
50 |
|
51 // ---------------------------------------------------------- |
|
52 // CBTPinNotifier::NewL |
|
53 // Two-phased constructor. |
|
54 // ---------------------------------------------------------- |
|
55 // |
|
56 CBTPinNotifier* CBTPinNotifier::NewL() |
|
57 { |
|
58 CBTPinNotifier* self=new (ELeave) CBTPinNotifier(); |
|
59 CleanupStack::PushL(self); |
|
60 self->ConstructL(); |
|
61 CleanupStack::Pop(self); |
|
62 return self; |
|
63 } |
|
64 |
|
65 // ---------------------------------------------------------- |
|
66 // CBTPinNotifier::CBTPinNotifier |
|
67 // C++ default constructor can NOT contain any code, that |
|
68 // might leave. |
|
69 // ---------------------------------------------------------- |
|
70 // |
|
71 CBTPinNotifier::CBTPinNotifier() |
|
72 { |
|
73 } |
|
74 |
|
75 // ---------------------------------------------------------- |
|
76 // Destructor |
|
77 // ---------------------------------------------------------- |
|
78 // |
|
79 CBTPinNotifier::~CBTPinNotifier() |
|
80 { |
|
81 } |
|
82 |
|
83 // ---------------------------------------------------------- |
|
84 // CBTPinNotifier::RegisterL |
|
85 // Register notifier. |
|
86 // ---------------------------------------------------------- |
|
87 // |
|
88 CBTPinNotifier::TNotifierInfo CBTPinNotifier::RegisterL() |
|
89 { |
|
90 iInfo.iUid=KBTPinCodeEntryNotifierUid; |
|
91 iInfo.iChannel=KBTAuthenticationChannel; |
|
92 iInfo.iPriority=ENotifierPriorityVHigh; |
|
93 return iInfo; |
|
94 } |
|
95 |
|
96 // ---------------------------------------------------------- |
|
97 // CBTPinNotifier::GetParamsL |
|
98 // Initialize parameters and check if device is already |
|
99 // in registry. Jump to RunL as soon as possible. |
|
100 // ---------------------------------------------------------- |
|
101 // |
|
102 void CBTPinNotifier::GetParamsL(const TDesC8& aBuffer, TInt aReplySlot, const RMessagePtr2& aMessage) |
|
103 { |
|
104 FLOG(_L("[BTNOTIF]\t CBTPinNotifier::GetParamsL() >>")); |
|
105 |
|
106 CBTNPairNotifierBase::GetParamsL( aBuffer, aReplySlot, aMessage ); |
|
107 |
|
108 TBTPinCodeEntryNotifierParams param; |
|
109 TPckgC<TBTPinCodeEntryNotifierParams> pckg(param); |
|
110 pckg.Set(aBuffer); |
|
111 |
|
112 iBTAddr = pckg().DeviceAddress(); |
|
113 if ( OtherOutgoPairing(iBTAddr) ) |
|
114 { |
|
115 // We won't allow incoming pairing during outgoing pairing: |
|
116 FLOG(_L("[BTNOTIF]\t CBTPinNotifier: outgoing pair in progress, reject incoming pair")); |
|
117 CompleteMessage(KErrCancel); |
|
118 return; |
|
119 } |
|
120 |
|
121 iLocallyInitiated = pckg().LocallyInitiated(); |
|
122 iPasskeyLength = pckg().PinCodeMinLength(); |
|
123 iStrongPinRequired = pckg().StrongPinCodeRequired(); |
|
124 ProcessParamsGetDeviceL( iBTAddr, pckg().DeviceName() ); |
|
125 |
|
126 FLOG(_L("[BTNOTIF]\t CBTPinNotifier::GetParamsL() <<")); |
|
127 } |
|
128 |
|
129 // ---------------------------------------------------------- |
|
130 // CBTPinNotifier::HandleGetDeviceCompletedL |
|
131 // Ask user response and return it to caller. |
|
132 // Store device into registry if user has accepted pairing. |
|
133 // ---------------------------------------------------------- |
|
134 // |
|
135 void CBTPinNotifier::HandleGetDeviceCompletedL(const CBTDevice* aDev) |
|
136 { |
|
137 FLOG(_L("[BTNOTIF]\t CBTPinNotifier::HandleGetDeviceCompletedL() >>")); |
|
138 (void) aDev; |
|
139 |
|
140 // Check if blocked device |
|
141 if( CheckBlockedDeviceL() ) |
|
142 return; |
|
143 |
|
144 // Turn lights on and deactivate apps -key |
|
145 iNotifUiUtil->TurnLightsOn(); |
|
146 |
|
147 if( CheckAndSetAutomatedPairing() ) |
|
148 { |
|
149 CompleteMessage(iPinCode, KErrNone); |
|
150 return; |
|
151 } |
|
152 |
|
153 // For incoming pairing request |
|
154 if(!iLocallyInitiated) |
|
155 { |
|
156 TBool userAnswer = AuthoriseIncomingPairingL(); |
|
157 if( !userAnswer ) |
|
158 { |
|
159 //User rejects the incoming pairing, complete message in QueryBlockDevice. |
|
160 FLOG(_L("[BTNOTIF]\t CBTPinNotifier::HandleGetDeviceCompletedL() <<")); |
|
161 return; |
|
162 } |
|
163 } |
|
164 |
|
165 // Use a forever loop here to show query dialog again of ínput pin code does't fulfill the |
|
166 // minimum length requirement |
|
167 // |
|
168 FOREVER |
|
169 { |
|
170 TBuf<KBTPassKeyMaxLength> tempResultBuffer; |
|
171 RBuf prompt; |
|
172 prompt.CleanupClosePushL(); |
|
173 GenerateQueryPromptL( prompt ); |
|
174 TInt keypress = iNotifUiUtil->ShowTextInputQueryL(tempResultBuffer, prompt, R_BT_ENTER_PASSKEY_QUERY, |
|
175 ECmdShowBtOpenCoverNote, CAknQueryDialog::EConfirmationTone ); |
|
176 CleanupStack::PopAndDestroy( &prompt ); |
|
177 |
|
178 if( keypress ) // OK pressed |
|
179 { |
|
180 // Convert data from buf to pin |
|
181 TBuf8<KBTPassKeyMaxLength> buf8; |
|
182 buf8.Zero(); |
|
183 CnvUtfConverter::ConvertFromUnicodeToUtf8(buf8, tempResultBuffer); |
|
184 |
|
185 //check if the length of pin less that minimum required pin code length |
|
186 if ((iPasskeyLength == 0) || ( buf8.Length() >= iPasskeyLength)) |
|
187 { |
|
188 iPinCode().iLength = STATIC_CAST(TUint8, buf8.Length()); |
|
189 for (TInt index=0; index<buf8.Length(); index++) |
|
190 { |
|
191 iPinCode().iPIN[index] = buf8[index]; |
|
192 } |
|
193 CompleteMessage(iPinCode, KErrNone); |
|
194 break; |
|
195 } |
|
196 else |
|
197 { |
|
198 //keep FOREVER loop runing, till the user input pin meet the requirement. |
|
199 tempResultBuffer.Zero(); |
|
200 } |
|
201 } |
|
202 else // Cancel pressed |
|
203 { |
|
204 // If the outgoing pairing mode is set, then this is bonding initiated by the user. |
|
205 TBool incomingConn = ( OutgoPairingMode( iBTAddr ) == EBTOutgoingPairNone ); |
|
206 if( !iMessage.IsNull() ) |
|
207 { |
|
208 // No need to inform the user of the pairing result if the user cancelled it. |
|
209 // If user doesn't answer anything but stack cancels, pairing result is needed |
|
210 // to show for outgoing pairing. In this case, don't stop pairng observer. |
|
211 CBTEngConnMan::StopPairingObserver( iBTAddr ); |
|
212 } |
|
213 |
|
214 // We may be asking for pairing (locally initiated), because a remote device is requesting |
|
215 // accesss to a service for which we require authentication. |
|
216 if( iLocallyInitiated && incomingConn ) |
|
217 { |
|
218 CheckAndHandleQueryIntervalL(); |
|
219 } |
|
220 CompleteMessage(KErrCancel); |
|
221 return; |
|
222 } |
|
223 }//END of FOREVER loop |
|
224 |
|
225 FLOG(_L("[BTNOTIF]\t CBTPinNotifier::HandleGetDeviceCompletedL() completed")); |
|
226 } |
|
227 |
|
228 // ---------------------------------------------------------- |
|
229 // CBTPinNotifier::CheckAndSetAutomatedPairing |
|
230 // ---------------------------------------------------------- |
|
231 TBool CBTPinNotifier::CheckAndSetAutomatedPairing() |
|
232 { |
|
233 FLOG(_L("[BTNOTIF]\t CBTPinNotifier::CheckAndSetAutomatedPairing()")); |
|
234 TBool ret( EFalse ); |
|
235 // check if device is headset and passkey is empty -> do automated pairing with 0000. |
|
236 if ( iDevice && |
|
237 OutgoPairingMode( iBTAddr ) == EBTOutgoingHeadsetAutoPairing && |
|
238 iPasskeyLength <= KDefaultPinCodeLength ) |
|
239 { |
|
240 FLOG( _L( "[BTNOTIF]\t CBTPinNotifier::CheckAndSetAutomatedPairing - automated pairing on" ) ); |
|
241 FLOG(_L("[BTNOTIF]\t Setting default PIN code")); |
|
242 iPinCode().iLength = KDefaultPinCodeLength; |
|
243 for( TInt i=0; i < KDefaultPinCodeLength; ++i) |
|
244 { |
|
245 iPinCode().iPIN[i] = KZeroPinValue; |
|
246 } |
|
247 ret = ETrue; |
|
248 } |
|
249 return ret; |
|
250 } |
|
251 |
|
252 // ---------------------------------------------------------- |
|
253 // CBTPinNotifier::GenerateQueryPromptL |
|
254 // ---------------------------------------------------------- |
|
255 void CBTPinNotifier::GenerateQueryPromptL( RBuf& aRBuf ) |
|
256 { |
|
257 FLOG(_L("[BTNOTIF]\t CBTPinNotifier::GenerateQueryPromptLC() >>")); |
|
258 TBTDeviceName devName; |
|
259 BtNotifNameUtils::GetDeviceDisplayName( devName, iDevice ); |
|
260 if (iPasskeyLength > 0) //Minimum length passkey is defined |
|
261 { |
|
262 BluetoothUiUtil::LoadResourceAndSubstringL( |
|
263 aRBuf, R_BT_MIN_PASSKEY_PROMPT, devName, 1 ); |
|
264 |
|
265 RBuf tmpBuf; |
|
266 tmpBuf.CleanupClosePushL(); |
|
267 tmpBuf.Swap( aRBuf ); |
|
268 aRBuf.ReAllocL( aRBuf.MaxLength() + sizeof(TUint)); |
|
269 aRBuf.Zero(); |
|
270 // Passkey length should be localized, hope StringLoader can make it: |
|
271 StringLoader::Format( aRBuf, tmpBuf, 0, iPasskeyLength ); |
|
272 CleanupStack::PopAndDestroy( &tmpBuf ); |
|
273 } |
|
274 else |
|
275 { |
|
276 BluetoothUiUtil::LoadResourceAndSubstringL( |
|
277 aRBuf, R_BT_PASSKEY_PROMPT, devName, 0 ); |
|
278 } |
|
279 FLOG(_L("[BTNOTIF]\t CBTPinNotifier::GenerateQueryPromptLC() <<")); |
|
280 } |
|
281 // End of File |