bluetooth/btexample/testui/BTUIAutoNotifiers/Src/btuinotifiers.cpp
changeset 0 29b1cd4cb562
equal deleted inserted replaced
-1:000000000000 0:29b1cd4cb562
       
     1 // Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include <btextnotifiers.h>
       
    17 
       
    18 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
       
    19 #include <btextnotifierspartner.h>
       
    20 #endif
       
    21 
       
    22 #include <e32cons.h>
       
    23 #include <es_prot.h>
       
    24 #include <networking/panuiinterfaces.h>
       
    25 #include <e32debug.h>
       
    26 #include "btuinotifiers.h"
       
    27 #include <es_sock.h>
       
    28 #include <e32msgqueue.h>
       
    29 
       
    30 #define PIN_DEFAULT  "1234"
       
    31 _LIT8(KDefaultPinCode, PIN_DEFAULT);
       
    32 
       
    33 const TUint KDefaultAuthorisation = 1; // Accept
       
    34 
       
    35 /*There can be any number of keypress notifications, I am taking 20 just for testing purpose*/
       
    36 const TUint KMaxNumberOfKeyPressNotifications = 20;
       
    37 
       
    38 const TUint KDefaultSSPAuthorisation = 1;
       
    39 
       
    40 #define DEFAULT_PBAP_AUTH_PASSWORD "password"
       
    41 
       
    42 _LIT8(KNotUsed, "Not used");
       
    43 
       
    44 const TUid KTechViewScreenOutputChannel={0x10009D48};
       
    45 
       
    46 const TInt KBTNotifierArrayIncrement = 2;
       
    47 
       
    48 CArrayPtr<MEikSrvNotifierBase2>* NotifierArray()
       
    49 	{
       
    50 	CArrayPtrFlat<MEikSrvNotifierBase2>* subjects=NULL;
       
    51 	TRAPD( err, subjects=new (ELeave)CArrayPtrFlat<MEikSrvNotifierBase2>(KBTNotifierArrayIncrement) );
       
    52 	if( err == KErrNone )
       
    53 		{
       
    54 		TRAP( err, subjects->AppendL( CBTUIAutoPasskeyNotifier::NewL() ) );
       
    55 		TRAP( err, subjects->AppendL( CBTUIAutoAuthNotifier::NewL() ) );
       
    56 		TRAP( err, subjects->AppendL( CPbapUIAutoAuthNotifier::NewL() ) );
       
    57 		TRAP( err, subjects->AppendL( CPanNapAuthAutoNotifier::NewL() ) );
       
    58 		TRAP( err, subjects->AppendL( CSSPNumericComparisionAutoNotifier::NewL() ) );
       
    59 		TRAP( err, subjects->AppendL( CSSPPassKeyAutoNotifier::NewL() ) );
       
    60 		TRAP( err, subjects->AppendL( CBTUIAutoPinCodeNotifier::NewL() ));				
       
    61 		return(subjects);
       
    62 		}
       
    63 	else
       
    64 		{
       
    65 		return NULL;
       
    66 		}
       
    67 	}
       
    68 
       
    69 //Adding ECOM Support
       
    70 #include <ecom/implementationproxy.h>
       
    71 const TImplementationProxy ImplementationTable[] =
       
    72 {
       
    73     IMPLEMENTATION_PROXY_ENTRY(0x10201D09, NotifierArray)
       
    74 };
       
    75 
       
    76 EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount)
       
    77 {
       
    78 	aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy);
       
    79 	return ImplementationTable;
       
    80 }
       
    81 
       
    82 //Update the P&S key for the notifier type so test code can check which type of notifier has fired
       
    83 //This is not critical so work on a best effort approach. If it fails then we don't care unless it's
       
    84 //not defined
       
    85 void UpdateLastNotifierType(TAutoNotifierType aType)
       
    86 	{
       
    87 	TInt err = RProperty::Set(KUidSystemCategory, KUidLastNotifierTypeRun, aType);
       
    88 	if(err == KErrNotFound)
       
    89 		{
       
    90 		_LIT_SECURITY_POLICY_PASS(KPassPolicy);
       
    91 		err = RProperty::Define(KUidSystemCategory, KUidLastNotifierTypeRun, RProperty::EInt, KPassPolicy, KPassPolicy);
       
    92 		if(err == KErrNone || err == KErrAlreadyExists)
       
    93 			{
       
    94 			RProperty::Set(KUidSystemCategory, KUidLastNotifierTypeRun, ESspNumericComparisonNotifier);
       
    95 			}
       
    96 		}
       
    97 	}
       
    98 
       
    99 
       
   100 //  * * *         CBTUIAutoPasskeyNotifier * * *
       
   101 CBTUIAutoPasskeyNotifier* CBTUIAutoPasskeyNotifier::NewL()
       
   102 	{
       
   103 	CBTUIAutoPasskeyNotifier* self=new (ELeave) CBTUIAutoPasskeyNotifier();	
       
   104 	CleanupStack::PushL(self);
       
   105 	self->ConstructL();	
       
   106 	CleanupStack::Pop();
       
   107 	return self;
       
   108 	}
       
   109 
       
   110 CBTUIAutoPasskeyNotifier::CBTUIAutoPasskeyNotifier() 
       
   111 	{
       
   112 	}
       
   113 
       
   114 void CBTUIAutoPasskeyNotifier::ConstructL()
       
   115 	{
       
   116 	}
       
   117 
       
   118 CBTUIAutoPasskeyNotifier::~CBTUIAutoPasskeyNotifier()
       
   119 	{
       
   120 
       
   121 	}
       
   122 
       
   123 void CBTUIAutoPasskeyNotifier::Release()
       
   124 	{
       
   125 	delete this;
       
   126 	}
       
   127 
       
   128 CBTUIAutoPasskeyNotifier::TNotifierInfo CBTUIAutoPasskeyNotifier::RegisterL()
       
   129 	{
       
   130 	iInfo.iUid=KBTManPinNotifierUid;
       
   131 	iInfo.iChannel=KTechViewScreenOutputChannel;
       
   132 	iInfo.iPriority=ENotifierPriorityLow;
       
   133 	return iInfo;
       
   134 	}
       
   135 
       
   136 CBTUIAutoPasskeyNotifier::TNotifierInfo CBTUIAutoPasskeyNotifier::Info() const
       
   137 	{
       
   138 	return iInfo;
       
   139 	}
       
   140 
       
   141 TPtrC8 CBTUIAutoPasskeyNotifier::StartL(const TDesC8&)
       
   142 	{
       
   143 	return TPtrC8(KNotUsed);
       
   144 	}
       
   145 
       
   146 void CBTUIAutoPasskeyNotifier::StartL(const TDesC8&, TInt aReplySlot, const RMessagePtr2& aMessage)
       
   147 	{
       
   148 	iMessage = aMessage;
       
   149     iReplySlot = aReplySlot;	
       
   150 	// read properties	
       
   151 	TBTPinCode pinCode;
       
   152 	
       
   153 	TBuf<16> buf;
       
   154 	TInt err = RProperty::Get(KUidSystemCategory, KUidAutoPropertyPinCode, buf);
       
   155 	
       
   156 	if (err == KErrNotFound)
       
   157 		{
       
   158 		// p+s key not defined, use default pin
       
   159 
       
   160 		buf.Copy(KDefaultPinCode);
       
   161 		}
       
   162 	else
       
   163 		{
       
   164 		// make sure no other error occurred
       
   165 		User::LeaveIfError(err);
       
   166 		}
       
   167 	
       
   168 	for (TUint i=0; i<buf.Length(); i++)
       
   169 		{
       
   170 		pinCode().iPIN[i] = buf[i];
       
   171 		}
       
   172 	pinCode().iLength = buf.Length();
       
   173 	
       
   174 	TInt notifierError = KErrNone;	
       
   175 	/* Get the value of the P&S key 'KUidErrorNotifiers' to see if need to complete the notifiers with an error
       
   176 	 * If P&S key is not defined then we will proceed normally otherwise we will complete the notifiers 
       
   177 	 * the specified error*/	
       
   178 	err = RProperty::Get(KUidSystemCategory, KUidErrorNotifiers, notifierError);
       
   179 	
       
   180 	if (err == KErrNotFound)
       
   181 		{
       
   182 		PinInputComplete(pinCode, KErrNone);
       
   183 		}
       
   184 	else
       
   185 		{
       
   186 		/*If error is defined then complete the notifiers with an error*/
       
   187 		PinInputComplete(pinCode, notifierError);
       
   188 		}
       
   189 
       
   190 	return;	
       
   191 	}
       
   192 
       
   193 
       
   194 void CBTUIAutoPasskeyNotifier::Cancel()
       
   195 	{
       
   196 	}
       
   197 	
       
   198 void CBTUIAutoPasskeyNotifier::UpdateL(const TDesC8& /*aBuffer*/, TInt /*aReplySlot*/, const RMessagePtr2& aMessage)
       
   199 	{
       
   200 	aMessage.Complete(KErrNone);
       
   201 	}
       
   202 
       
   203 TPtrC8 CBTUIAutoPasskeyNotifier::UpdateL(const TDesC8&)
       
   204 	{
       
   205 	TPtrC8 ret(KNullDesC8);
       
   206 	return (ret);
       
   207 	}
       
   208 	
       
   209 void CBTUIAutoPasskeyNotifier::PinInputComplete(const TBTPinCode& aPin, TInt aReason)
       
   210 	{	
       
   211 	// update executed status, ignore error, what can we do !?!
       
   212 	RProperty::Set(KUidSystemCategory, KUidAuthenticationExecuted, 1);
       
   213 	
       
   214 	if (aReason == KErrNone)
       
   215 		{		
       
   216 		TInt err = iMessage.Write(iReplySlot, aPin);
       
   217 		
       
   218 		iMessage.Complete(err);
       
   219 		}
       
   220 	else
       
   221 		{
       
   222 		iMessage.Complete(aReason);
       
   223 		}
       
   224 	}
       
   225 
       
   226 
       
   227 // CBTUIAutoAuthNotifier 
       
   228 CBTUIAutoAuthNotifier* CBTUIAutoAuthNotifier::NewL()
       
   229 	{
       
   230 	CBTUIAutoAuthNotifier* self=new (ELeave) CBTUIAutoAuthNotifier();	
       
   231 	CleanupStack::PushL(self);
       
   232 	self->ConstructL();	
       
   233 	CleanupStack::Pop();
       
   234 	return self;
       
   235 	}
       
   236 
       
   237 CBTUIAutoAuthNotifier::CBTUIAutoAuthNotifier() 
       
   238 	{
       
   239 	}
       
   240 
       
   241 void CBTUIAutoAuthNotifier::ConstructL()
       
   242 	{
       
   243 	}
       
   244 
       
   245 CBTUIAutoAuthNotifier::~CBTUIAutoAuthNotifier()
       
   246 	{
       
   247 	
       
   248 	}
       
   249 
       
   250 void CBTUIAutoAuthNotifier::Release()
       
   251 	{
       
   252 	delete this;
       
   253 	}
       
   254 
       
   255 CBTUIAutoAuthNotifier::TNotifierInfo CBTUIAutoAuthNotifier::RegisterL()
       
   256 	{
       
   257 	iInfo.iUid=KBTManAuthNotifierUid;
       
   258 	iInfo.iChannel=KTechViewScreenOutputChannel;
       
   259 	iInfo.iPriority=ENotifierPriorityLow;
       
   260 	return iInfo;
       
   261 	}
       
   262 
       
   263 CBTUIAutoAuthNotifier::TNotifierInfo CBTUIAutoAuthNotifier::Info() const
       
   264 	{
       
   265 	return iInfo;
       
   266 	}
       
   267 
       
   268 TPtrC8 CBTUIAutoAuthNotifier::StartL(const TDesC8&)
       
   269 	{
       
   270 	return TPtrC8(KNotUsed);
       
   271 	}
       
   272 
       
   273 void CBTUIAutoAuthNotifier::StartL(const TDesC8&, TInt aReplySlot, const RMessagePtr2& aMessage)
       
   274 	{
       
   275 	iMessage = aMessage;
       
   276     iReplySlot = aReplySlot;
       
   277 	// read properties
       
   278 	TInt authoriseAccept;
       
   279 		
       
   280 	TInt err = RProperty::Get(KUidSystemCategory, KUidAutoPropertyAuthoriseAccept, authoriseAccept);
       
   281 	
       
   282 	if (err == KErrNotFound)
       
   283 		{
       
   284 		// p+s key not defined, use default (Yes)
       
   285 		authoriseAccept = KDefaultAuthorisation;
       
   286 		}
       
   287 	else
       
   288 		{
       
   289 		// make sure no other error occurred
       
   290 		User::LeaveIfError(err);
       
   291 		}
       
   292 	
       
   293 	AuthorisationComplete(authoriseAccept);
       
   294 	return;
       
   295 	}
       
   296 
       
   297 void CBTUIAutoAuthNotifier::Cancel()
       
   298 	{
       
   299 	}
       
   300 
       
   301 void CBTUIAutoAuthNotifier::UpdateL(const TDesC8& /*aBuffer*/, TInt /*aReplySlot*/, const RMessagePtr2& aMessage)
       
   302 	{
       
   303 	aMessage.Complete(KErrNone);
       
   304 	}
       
   305 
       
   306 TPtrC8 CBTUIAutoAuthNotifier::UpdateL(const TDesC8&)
       
   307 	{
       
   308 	TPtrC8 ret(KNullDesC8);
       
   309 	return (ret);
       
   310 	}
       
   311 	
       
   312 void CBTUIAutoAuthNotifier::AuthorisationComplete(TInt aAuthorised)
       
   313 	{
       
   314 
       
   315 		TInt err = iMessage.Write(iReplySlot, TPckgBuf<TBool>(aAuthorised));
       
   316 		// update executed status
       
   317 		RProperty::Set(KUidSystemCategory, KUidAuthorisationExecuted, 1);		
       
   318 		iMessage.Complete(err);
       
   319 	}
       
   320 
       
   321 //
       
   322 // CPbapUIAutoAuthNotifier
       
   323 //
       
   324 CPbapUIAutoAuthNotifier* CPbapUIAutoAuthNotifier::NewL()
       
   325 	{
       
   326 	CPbapUIAutoAuthNotifier* self = new (ELeave) CPbapUIAutoAuthNotifier();
       
   327 	return self;
       
   328 	}
       
   329 
       
   330 CPbapUIAutoAuthNotifier::CPbapUIAutoAuthNotifier()
       
   331 	{
       
   332 	}
       
   333 
       
   334 void CPbapUIAutoAuthNotifier::Release()
       
   335 	{
       
   336 	delete this;
       
   337 	}
       
   338 
       
   339 void CPbapUIAutoAuthNotifier::Cancel()
       
   340 	{
       
   341 	}
       
   342 
       
   343 CPbapUIAutoAuthNotifier::~CPbapUIAutoAuthNotifier()
       
   344 	{
       
   345 	iProperty.Close();
       
   346 	}
       
   347 
       
   348 CPbapUIAutoAuthNotifier::TNotifierInfo CPbapUIAutoAuthNotifier::RegisterL()
       
   349 	{
       
   350 	iInfo.iUid=KPbapAuthNotifierUid;
       
   351 	iInfo.iChannel=KTechViewScreenOutputChannel;
       
   352 	iInfo.iPriority=ENotifierPriorityVHigh;
       
   353 	return iInfo;
       
   354 	}
       
   355 
       
   356 CPbapUIAutoAuthNotifier::TNotifierInfo CPbapUIAutoAuthNotifier::Info() const
       
   357 	{
       
   358 	return iInfo;
       
   359 	}
       
   360 
       
   361 TPtrC8 CPbapUIAutoAuthNotifier::StartL(const TDesC8& /*aBuffer*/)
       
   362 	{
       
   363 	return KNullDesC8();
       
   364 	}
       
   365 
       
   366 void CPbapUIAutoAuthNotifier::StartL(const TDesC8& /*aBuffer*/, TInt aReplySlot, const RMessagePtr2& aMessage)
       
   367 	{
       
   368 	iReplySlot = aReplySlot;
       
   369 	iMessage = RMessage2(aMessage);
       
   370 
       
   371 	TBuf<16> buf;
       
   372 	TInt err = iProperty.Get(KUidSystemCategory, KUidPbapAutoNotifierPassword, buf);
       
   373 	
       
   374 	if (err == KErrNotFound)
       
   375 		{
       
   376 		// p+s key not defined, use default password
       
   377 		_LIT8(KDefaultPbapAuthPassword, DEFAULT_PBAP_AUTH_PASSWORD);
       
   378 		
       
   379 		buf.Copy(KDefaultPbapAuthPassword);
       
   380 		}
       
   381 	else	
       
   382 		{
       
   383 		// make sure no other error occurred
       
   384 		User::LeaveIfError(err);
       
   385 		}
       
   386 	
       
   387 	PasswordInputComplete(buf, KErrNone);
       
   388 	}
       
   389 
       
   390 void CPbapUIAutoAuthNotifier::UpdateL(const TDesC8& /*aBuffer*/, TInt /*aReplySlot*/, const RMessagePtr2& aMessage)
       
   391 	{
       
   392 	aMessage.Complete(KErrNone);
       
   393 	}
       
   394 
       
   395 TPtrC8 CPbapUIAutoAuthNotifier::UpdateL(const TDesC8& /*aBuffer*/)
       
   396 	{
       
   397 	return KNullDesC8();
       
   398 	}
       
   399 
       
   400 void CPbapUIAutoAuthNotifier::PasswordInputComplete(const TDesC& aPassword, TInt aReason)
       
   401 	{
       
   402 	// update executed status, ignore error, what can we do !?!
       
   403 	RProperty::Set(KUidSystemCategory, KUidPbapAutoNotifierExecuted, 1);	
       
   404 	if (aReason == KErrNone)
       
   405 		{
       
   406 		TPbapAuthNotifierResponsePckg pckg;
       
   407 		pckg().SetPassword(aPassword);		
       
   408 		TInt err = iMessage.Write(iReplySlot, pckg);
       
   409 		iMessage.Complete(err);
       
   410 		}
       
   411 	else
       
   412 		{
       
   413 		iMessage.Complete(aReason);
       
   414 		}
       
   415 	}
       
   416 
       
   417 
       
   418 //
       
   419 // CPanNapAuthAutoNotifier
       
   420 //
       
   421 CPanNapAuthAutoNotifier* CPanNapAuthAutoNotifier::NewL()
       
   422 	{
       
   423 	CPanNapAuthAutoNotifier* self = new (ELeave) CPanNapAuthAutoNotifier();
       
   424 	return self;
       
   425 	}
       
   426 
       
   427 CPanNapAuthAutoNotifier::CPanNapAuthAutoNotifier()
       
   428 	{
       
   429 	}
       
   430 
       
   431 void CPanNapAuthAutoNotifier::Release()
       
   432 	{
       
   433 	delete this;
       
   434 	}
       
   435 
       
   436 void CPanNapAuthAutoNotifier::Cancel()
       
   437 	{
       
   438 	}
       
   439 
       
   440 CPanNapAuthAutoNotifier::~CPanNapAuthAutoNotifier()
       
   441 	{
       
   442 	iProperty.Close();
       
   443 	}
       
   444 
       
   445 CPanNapAuthAutoNotifier::TNotifierInfo CPanNapAuthAutoNotifier::RegisterL()
       
   446 	{
       
   447 	iInfo.iUid=KBTPanNapUplinkAuthorisationNotifierUid;
       
   448 	iInfo.iChannel=KTechViewScreenOutputChannel;
       
   449 	iInfo.iPriority=ENotifierPriorityVHigh;
       
   450 	return iInfo;
       
   451 	}
       
   452 
       
   453 CPanNapAuthAutoNotifier::TNotifierInfo CPanNapAuthAutoNotifier::Info() const
       
   454 	{
       
   455 	return iInfo;
       
   456 	}
       
   457 
       
   458 TPtrC8 CPanNapAuthAutoNotifier::StartL(const TDesC8& /*aBuffer*/)
       
   459 	{
       
   460 	return KNullDesC8();
       
   461 	}
       
   462 
       
   463 void CPanNapAuthAutoNotifier::StartL(const TDesC8& /*aBuffer*/, TInt aReplySlot, const RMessagePtr2& aMessage)
       
   464 	{
       
   465 	iReplySlot = aReplySlot;
       
   466 	iMessage = RMessage2(aMessage);
       
   467 
       
   468 	TInt psResult;
       
   469 	TNapConnectionResult result = EAcceptNapConnectionAllowUplinkAccess;	// Default value if P&S key is not setup
       
   470 	TInt err = iProperty.Get(KUidSystemCategory, KUidPanNapAutoNotifierResult, psResult);
       
   471 	if(err == KErrNone)
       
   472 		{
       
   473 		result = static_cast<TNapConnectionResult>(psResult);
       
   474 		if(result != EDisallowNewNapConnection &&
       
   475 		   result != EAcceptNapConnectionAllowUplinkAccess &&
       
   476 		   result != EAcceptNapConnectionDisallowUplinkAccess)
       
   477 			{
       
   478 			User::Leave(KErrArgument);
       
   479 			}
       
   480 		}
       
   481 	else	
       
   482 		{
       
   483 		// Ensure no unexpected error occurred (KErrNotFound will be received if the key has not been
       
   484 		// setup)
       
   485 		if(err != KErrNotFound)
       
   486 			{
       
   487 			User::LeaveIfError(err);
       
   488 			}
       
   489 		}
       
   490 	
       
   491 	PanNapNotifierComplete(result, KErrNone);
       
   492 	}
       
   493 
       
   494 TPtrC8 CPanNapAuthAutoNotifier::UpdateL(const TDesC8& /*aBuffer*/)
       
   495 	{
       
   496 	return KNullDesC8();
       
   497 	}
       
   498 
       
   499 void CPanNapAuthAutoNotifier::PanNapNotifierComplete(TNapConnectionResult aResult, TInt aReason)
       
   500 	{
       
   501 	if(aReason == KErrNone)
       
   502 		{
       
   503 		TNapConnectionResultPckg pckg;
       
   504 		pckg = aResult;		
       
   505 		TInt err = iMessage.Write(iReplySlot, pckg);
       
   506 		iMessage.Complete(err);
       
   507 		}
       
   508 	else
       
   509 		{
       
   510 		iMessage.Complete(aReason);
       
   511 		}
       
   512 
       
   513 	// update executed status, ignore error, what can we do !?!
       
   514 	iProperty.Set(KUidSystemCategory, KUidPanNapAutoNotifierExecuted, 1);
       
   515 	}
       
   516 
       
   517 
       
   518 
       
   519 //
       
   520 // CSSPNumericComparisionAutoNotifier
       
   521 //
       
   522 
       
   523 CSSPNumericComparisionAutoNotifier* CSSPNumericComparisionAutoNotifier::NewL()
       
   524 	{
       
   525 	CSSPNumericComparisionAutoNotifier* self = new(ELeave) CSSPNumericComparisionAutoNotifier();
       
   526 	return self;
       
   527 	}
       
   528 
       
   529 CSSPNumericComparisionAutoNotifier::CSSPNumericComparisionAutoNotifier()
       
   530 	{
       
   531 	}
       
   532 
       
   533 void CSSPNumericComparisionAutoNotifier::Release()
       
   534 	{
       
   535 	delete this;
       
   536 	}
       
   537 
       
   538 void CSSPNumericComparisionAutoNotifier::Cancel()
       
   539 	{
       
   540 	}
       
   541 
       
   542 CSSPNumericComparisionAutoNotifier::~CSSPNumericComparisionAutoNotifier()
       
   543 	{
       
   544 	}
       
   545 
       
   546 CSSPNumericComparisionAutoNotifier::TNotifierInfo CSSPNumericComparisionAutoNotifier::RegisterL()
       
   547 	{
       
   548 	iInfo.iUid=KBTNumericComparisonNotifierUid;
       
   549 	iInfo.iChannel=KTechViewScreenOutputChannel;
       
   550 	iInfo.iPriority=ENotifierPriorityVHigh;
       
   551 	return iInfo;
       
   552 	}
       
   553 
       
   554 CSSPNumericComparisionAutoNotifier::TNotifierInfo CSSPNumericComparisionAutoNotifier::Info() const
       
   555 	{
       
   556 	return iInfo;
       
   557 	}
       
   558 
       
   559 TPtrC8 CSSPNumericComparisionAutoNotifier::StartL(const TDesC8& /*aBuffer*/)
       
   560 	{
       
   561 	User::Panic(KPanicCat, ESynchronousStartWithNumericComparison);
       
   562 	return KNullDesC8();
       
   563 	}
       
   564 
       
   565 void CSSPNumericComparisionAutoNotifier::StartL(const TDesC8& aBuffer, TInt aReplySlot, const RMessagePtr2& aMessage)
       
   566 	{
       
   567 	UpdateLastNotifierType(ESspNumericComparisonNotifier);
       
   568 	iReplySlot = aReplySlot;
       
   569 	iMessage = RMessage2(aMessage);
       
   570 	TBTNumericComparisonParamsPckg pckg;
       
   571 	pckg.Copy(aBuffer);
       
   572 	
       
   573 	/*Update a P&S key for identifying who initiated the authentication*/
       
   574 	TInt err = RProperty::Set(KUidSystemCategory, KUidLocallyInitiated, pckg().LocallyInitiated());
       
   575 	
       
   576 	if (err == KErrNotFound)
       
   577 		{
       
   578 		/* p+s key not defined by the test
       
   579 		 * May be autonotifiers are not called for testing purpose (i.e. just running epoc in startupmode 4) 
       
   580 		 * so we should not panic here and hence do nothing
       
   581 		 */		
       
   582 		}
       
   583 	else
       
   584 		{
       
   585 		// make sure no other error occurred
       
   586 		User::LeaveIfError(err);
       
   587 		}
       
   588 	
       
   589 	/*Read the Numeric Value*/
       
   590 	TInt numericValue;
       
   591 	
       
   592 	numericValue = pckg().NumericalValue();
       
   593 	
       
   594 	/*Now I need to update a P&S key which will have the NumericValue*/
       
   595 	err = RProperty::Set(KUidSystemCategory, KUidSspNumericValue, numericValue);
       
   596 	
       
   597 	if (err == KErrNotFound)
       
   598 		{
       
   599 		/* p+s key not defined by the test
       
   600 		 * May be autonotifiers are not called for testing purpose (i.e. just running epoc in startupmode 4) 
       
   601 		 * so we should not panic here and hence do nothing
       
   602 		 */		
       
   603 		}
       
   604 	else
       
   605 		{
       
   606 		// make sure no other error occurred
       
   607 		User::LeaveIfError(err);
       
   608 		}
       
   609   
       
   610 	/* Complete the Numeric comparision*/
       
   611 	TInt authoriseAccept;
       
   612 	err = RProperty::Get(KUidSystemCategory, KUidSspAuthorisation, authoriseAccept);
       
   613 	
       
   614 	if (err == KErrNotFound)
       
   615 		{
       
   616 		// p+s key not defined, use default (Yes)
       
   617 		authoriseAccept = KDefaultSSPAuthorisation;
       
   618 		}
       
   619 	else
       
   620 		{
       
   621 		// make sure no other error occurred
       
   622 		User::LeaveIfError(err);
       
   623 		}
       
   624 	
       
   625 	SSPNumericComparisonComplete(authoriseAccept);
       
   626 	}
       
   627 
       
   628 void CSSPNumericComparisionAutoNotifier::UpdateL(const TDesC8& /*aBuffer*/, TInt /*aReplySlot*/, const RMessagePtr2& aMessage)
       
   629 	{
       
   630 	aMessage.Complete(KErrNone);
       
   631 	}
       
   632 
       
   633 TPtrC8 CSSPNumericComparisionAutoNotifier::UpdateL(const TDesC8& /*aBuffer*/)
       
   634 	{
       
   635 	return KNullDesC8();
       
   636 	}
       
   637 
       
   638 void CSSPNumericComparisionAutoNotifier::SSPNumericComparisonComplete(TInt aAuthoriseAccept)
       
   639 	{	
       
   640 	TInt err = iMessage.Write(iReplySlot, TPckgC<TBool>(aAuthoriseAccept));
       
   641 	
       
   642 	if(err != KErrNone)
       
   643 		{
       
   644 		iMessage.Complete(err);	
       
   645 		}
       
   646 	else
       
   647 		{	
       
   648 		TInt notifierError = KErrNone;	
       
   649 		/* Get the value of the P&S key 'KErrorNotifiers' to see if need to complete the notifiers with an error
       
   650 		 * If P&S key is not defined then we will proceed normally otherwise we will complete the notifiers 
       
   651 		 * the specified error*/	
       
   652 		err = RProperty::Get(KUidSystemCategory, KUidErrorNotifiers, notifierError);
       
   653 		
       
   654 		if (err == KErrNotFound)
       
   655 			{
       
   656 			iMessage.Complete(KErrNone);	
       
   657 			}
       
   658 		else
       
   659 			{
       
   660 			/*If error is defined then complete the notifiers with an error*/
       
   661 			iMessage.Complete(notifierError);	
       
   662 			}
       
   663 		}
       
   664 	}
       
   665 
       
   666 
       
   667 
       
   668 //
       
   669 // CSSPPassKeyAutoNotifier
       
   670 //
       
   671 
       
   672 CSSPPassKeyAutoNotifier* CSSPPassKeyAutoNotifier::NewL()
       
   673 	{
       
   674 	CSSPPassKeyAutoNotifier* self = new(ELeave) CSSPPassKeyAutoNotifier();
       
   675 	return self;
       
   676 	}
       
   677 
       
   678 CSSPPassKeyAutoNotifier::CSSPPassKeyAutoNotifier()
       
   679 	{
       
   680 	}
       
   681 
       
   682 void CSSPPassKeyAutoNotifier::Release()
       
   683 	{
       
   684 	delete this;
       
   685 	}
       
   686 
       
   687 void CSSPPassKeyAutoNotifier::Cancel()
       
   688 	{	
       
   689 	if (iMessage.Handle())
       
   690 		{
       
   691 		iMessage.Complete(KErrCancel);
       
   692 		}	
       
   693 	}
       
   694 
       
   695 CSSPPassKeyAutoNotifier::~CSSPPassKeyAutoNotifier()
       
   696 	{
       
   697 	}
       
   698 
       
   699 CSSPPassKeyAutoNotifier::TNotifierInfo CSSPPassKeyAutoNotifier::RegisterL()
       
   700 	{
       
   701 	iInfo.iUid=KBTPasskeyDisplayNotifierUid;
       
   702 	iInfo.iChannel=KTechViewScreenOutputChannel;
       
   703 	iInfo.iPriority=ENotifierPriorityVHigh;
       
   704 	return iInfo;
       
   705 	}
       
   706 
       
   707 CSSPPassKeyAutoNotifier::TNotifierInfo CSSPPassKeyAutoNotifier::Info() const
       
   708 	{
       
   709 	return iInfo;
       
   710 	}
       
   711 
       
   712 TPtrC8 CSSPPassKeyAutoNotifier::StartL(const TDesC8& )
       
   713 	{
       
   714 	User::Panic(KPanicCat, ESynchronousStartWithPasskeyDisplay);
       
   715 	return KNullDesC8();
       
   716 	}
       
   717 
       
   718 void CSSPPassKeyAutoNotifier::StartL(const TDesC8& aBuffer, TInt /*aReplySlot*/, const RMessagePtr2& aMessage)
       
   719 	{	
       
   720 	UpdateLastNotifierType(ESspPassKeyNotifier);
       
   721 	TBTPasskeyDisplayParamsPckg pckg;
       
   722 	pckg.Copy(aBuffer);
       
   723 	
       
   724 	/*Update a P&S key for identifying who initiated the authentication*/
       
   725 	TInt err = RProperty::Set(KUidSystemCategory, KUidLocallyInitiated, pckg().LocallyInitiated());
       
   726 	
       
   727 	if (err == KErrNotFound)
       
   728 		{
       
   729 		/* p+s key not defined by the test
       
   730 		 * May be autonotifiers are not called for testing purpose (i.e. just running epoc in startupmode 4) 
       
   731 		 * so we should not panic here and hence do nothing
       
   732 		 */		
       
   733 		}
       
   734 	else
       
   735 		{
       
   736 		// make sure no other error occurred
       
   737 		User::LeaveIfError(err);
       
   738 		}	
       
   739 	
       
   740 	/*Read the Numeric Value*/
       
   741 	TInt passKeyValue;
       
   742 	
       
   743 	passKeyValue = pckg().NumericalValue();
       
   744 	
       
   745 	/*Now I need to update a P&S key which will have the Pass key Value*/
       
   746 	err = RProperty::Set(KUidSystemCategory, KUidSspPassKey, passKeyValue);
       
   747 	
       
   748 	if (err == KErrNotFound)
       
   749 		{
       
   750 		/* p+s key not defined by the test
       
   751 		 * May be autonotifiers are not called for testing purpose (i.e. just running epoc in startupmode 4) 
       
   752 		 * so we should not panic here and hence do nothing
       
   753 		 */		
       
   754 		}
       
   755 	else
       
   756 		{
       
   757 		// make sure no other error occurred
       
   758 		User::LeaveIfError(err);
       
   759 		}	
       
   760 	
       
   761 	iMessage = RMessage2(aMessage);
       
   762 	
       
   763 	TInt notifierError = KErrNone;	
       
   764 	/* Get the value of the P&S key 'KUidErrorNotifiers' to see if need to complete the notifiers with an error
       
   765 	 * If P&S key is not defined then we will proceed normally otherwise we will complete the notifiers 
       
   766 	 * the specified error*/	
       
   767 	err = RProperty::Get(KUidSystemCategory, KUidErrorNotifiers, notifierError);
       
   768 	
       
   769 	if (err != KErrNotFound)
       
   770 		{
       
   771 		//If error is defined then complete the notifiers with an error
       
   772 		iMessage.Complete(notifierError);	
       
   773 		}	
       
   774 	else
       
   775 		{
       
   776 		//Do nothing. We do not have to complete this msg here as stack will cancel it when it gets a 
       
   777 		//simple pairing complete event. 
       
   778 		}
       
   779 	}
       
   780 
       
   781 TPtrC8 CSSPPassKeyAutoNotifier::UpdateL(const TDesC8& /*aBuffer*/)
       
   782 	{
       
   783 	return KNullDesC8();
       
   784 	}
       
   785 
       
   786 void CSSPPassKeyAutoNotifier::UpdateL(const TDesC8& aBuffer, TInt /*aReplySlot*/, const RMessagePtr2& aMessage)
       
   787 	{		
       
   788 	TBTNotifierUpdateParamsPckg2 pckgRaw;
       
   789 	pckgRaw.Copy(aBuffer.Left(pckgRaw.MaxLength()));
       
   790 	
       
   791 	RMsgQueue<THCIPasskeyEntryNotificationType> keyPressNotificationQueue;
       
   792 	_LIT(KKeypressNotificationQueue, "KeypressNotificationQueue");
       
   793 	
       
   794 	TInt err;
       
   795 	
       
   796 	err = keyPressNotificationQueue.OpenGlobal(KKeypressNotificationQueue);
       
   797 	if(err == KErrNotFound)
       
   798 		{
       
   799 		err = keyPressNotificationQueue.CreateGlobal(KKeypressNotificationQueue,KMaxNumberOfKeyPressNotifications);
       
   800 		User::LeaveIfError(err);		
       
   801 		}
       
   802 	else 
       
   803 		{
       
   804 		User::LeaveIfError(err);
       
   805 		}
       
   806 	
       
   807 	/*Notify the test code for the passkey press*/
       
   808 	if (pckgRaw().Type() == TBTNotifierUpdateParams2::EPasskeyDisplay)
       
   809 		{
       
   810 		TBTPasskeyDisplayUpdateParamsPckg pckg;
       
   811 		pckg.Copy(aBuffer);
       
   812 		
       
   813 		THCIPasskeyEntryNotificationType keypressNotification = pckg().KeypressNotification();
       
   814 		
       
   815 		keyPressNotificationQueue.SendBlocking(keypressNotification);
       
   816 		
       
   817 		switch (keypressNotification)
       
   818 			{
       
   819 			case EPasskeyEntryStarted:
       
   820 			case EPasskeyDigitEntered:
       
   821 			case EPasskeyDigitDeleted:
       
   822 			case EPasskeyCleared:			
       
   823 			case EPasskeyEntryCompleted:
       
   824 				break;
       
   825 			}
       
   826 		}
       
   827 	
       
   828 	TInt notifierError = KErrNone;	
       
   829 	/* Get the value of the P&S key 'KUidErrorNotifiers' to see if need to complete the notifiers with an error
       
   830 	 * If P&S key is not defined then we will proceed normally otherwise we will complete the notifiers 
       
   831 	 * the specified error*/	
       
   832 	err = RProperty::Get(KUidSystemCategory, KUidErrorNotifiers, notifierError);
       
   833 	
       
   834 	if (err == KErrNotFound)
       
   835 		{
       
   836 		aMessage.Complete(KErrNone);	
       
   837 		}
       
   838 	else
       
   839 		{
       
   840 		/*If error is defined then complete the notifiers with an error*/
       
   841 		iMessage.Complete(notifierError);
       
   842 		aMessage.Complete(KErrNone);
       
   843 		}		
       
   844 	}
       
   845 
       
   846 //
       
   847 // CBTUIAutoPinCodeNotifier
       
   848 //
       
   849 
       
   850 CBTUIAutoPinCodeNotifier* CBTUIAutoPinCodeNotifier::NewL()
       
   851 	{
       
   852 	CBTUIAutoPinCodeNotifier* self = new(ELeave) CBTUIAutoPinCodeNotifier();	
       
   853 	return self;
       
   854 	}
       
   855 
       
   856 CBTUIAutoPinCodeNotifier::CBTUIAutoPinCodeNotifier() 
       
   857 	{
       
   858 	}
       
   859 
       
   860 CBTUIAutoPinCodeNotifier::~CBTUIAutoPinCodeNotifier()
       
   861 	{
       
   862 	}
       
   863 
       
   864 void CBTUIAutoPinCodeNotifier::Release()
       
   865 	{
       
   866 	delete this;
       
   867 	}
       
   868 
       
   869 CBTUIAutoPinCodeNotifier::TNotifierInfo CBTUIAutoPinCodeNotifier::RegisterL()
       
   870 	{
       
   871 	iInfo.iUid=KBTPinCodeEntryNotifierUid;
       
   872 	iInfo.iChannel=KTechViewScreenOutputChannel;
       
   873 	iInfo.iPriority=ENotifierPriorityLow;
       
   874 	return iInfo;
       
   875 	}
       
   876 
       
   877 CBTUIAutoPinCodeNotifier::TNotifierInfo CBTUIAutoPinCodeNotifier::Info() const
       
   878 	{
       
   879 	return iInfo;
       
   880 	}
       
   881 
       
   882 TPtrC8 CBTUIAutoPinCodeNotifier::StartL(const TDesC8&)
       
   883 	{
       
   884 	User::Panic(KPanicCat, ESynchronousStartWithPinCodeEntry);
       
   885 	return KNullDesC8();
       
   886 	}
       
   887 
       
   888 void CBTUIAutoPinCodeNotifier::StartL(const TDesC8& aBuffer, TInt aReplySlot, const RMessagePtr2& aMessage)
       
   889 	{
       
   890 	UpdateLastNotifierType(ELegacyPinCodeNotifier);
       
   891 	iMessage = aMessage;
       
   892     iReplySlot = aReplySlot;	
       
   893 	// read properties	
       
   894 	TBTPinCode pinCode;
       
   895 	
       
   896 	TBTPinCodeEntryNotifierParamsPckg pckg;
       
   897 	if(aBuffer.Length() != sizeof(TBTPinCodeEntryNotifierParams))
       
   898 		{
       
   899 		User::Leave(KErrArgument);
       
   900 		}
       
   901 	pckg.Copy(aBuffer);
       
   902 	TUint passkeyMinLength;
       
   903 	passkeyMinLength = pckg().PinCodeMinLength();
       
   904 	
       
   905 	
       
   906 	TBuf<16> buf;
       
   907 	TInt err = RProperty::Get(KUidSystemCategory, KUidAutoPropertyPinCode, buf);
       
   908 	
       
   909 	if (err == KErrNotFound)
       
   910 		{
       
   911 		// p+s key not defined, use default pin	
       
   912 		buf.Copy(KDefaultPinCode);
       
   913 		}
       
   914 	else
       
   915 		{
       
   916 		// make sure no other error occurred
       
   917 		User::LeaveIfError(err);
       
   918 		}
       
   919 	
       
   920 	for (TUint i=0; i<buf.Length(); i++)
       
   921 		{
       
   922 		pinCode().iPIN[i] = buf[i];
       
   923 		}
       
   924 	pinCode().iLength = buf.Length();
       
   925 	
       
   926 	/* Passkey length should not be less then the expected length.
       
   927 	 * If it is smaller than complete the notifiers with an error
       
   928 	 */  
       
   929 	if(buf.Length() < passkeyMinLength )
       
   930 		{
       
   931 		PinInputComplete(pinCode, KErrArgument);
       
   932 		}
       
   933 	else
       
   934 		{			
       
   935 		TInt notifierError = KErrNone;	
       
   936 		/* Get the value of the P&S key 'KUidErrorNotifiers' to see if need to complete the notifiers with an error
       
   937 		 * If P&S key is not defined then we will proceed normally otherwise we will complete the notifiers 
       
   938 		 * the specified error*/	
       
   939 		err = RProperty::Get(KUidSystemCategory, KUidErrorNotifiers, notifierError);
       
   940 		
       
   941 		if (err == KErrNotFound)
       
   942 			{		
       
   943 			PinInputComplete(pinCode, KErrNone);
       
   944 			}
       
   945 		else
       
   946 			{
       
   947 			/*If error is defined then complete the notifiers with an error*/
       
   948 			PinInputComplete(pinCode, notifierError);
       
   949 			}
       
   950 		}
       
   951 	}
       
   952 
       
   953 
       
   954 void CBTUIAutoPinCodeNotifier::Cancel()
       
   955 	{
       
   956 	}
       
   957 	
       
   958 void CBTUIAutoPinCodeNotifier::UpdateL(const TDesC8& /*aBuffer*/, TInt /*aReplySlot*/, const RMessagePtr2& aMessage)
       
   959 	{
       
   960 	aMessage.Complete(KErrNone);
       
   961 	}
       
   962 
       
   963 TPtrC8 CBTUIAutoPinCodeNotifier::UpdateL(const TDesC8&)
       
   964 	{
       
   965 	return KNullDesC8();
       
   966 	}
       
   967 	
       
   968 void CBTUIAutoPinCodeNotifier::PinInputComplete(const TBTPinCode& aPin, TInt aReason)
       
   969 	{
       
   970 	
       
   971 	// update executed status, ignore error, what can we do !?!
       
   972 	RProperty::Set(KUidSystemCategory, KUidAuthenticationExecuted, 1);
       
   973 	
       
   974 	if (aReason == KErrNone)
       
   975 		{
       
   976 		TInt err = iMessage.Write(iReplySlot, aPin);
       
   977 		iMessage.Complete(err);
       
   978 		}
       
   979 	else
       
   980 		{
       
   981 		iMessage.Complete(aReason);
       
   982 		}
       
   983 	}
       
   984