bluetooth/btstack/linkmgr/physicallinks.cpp
branchRCL_3
changeset 8 2b6718f05bdb
parent 3 4e39398d58ed
child 10 8a27654f7b62
equal deleted inserted replaced
4:28479eeba3fb 8:2b6718f05bdb
  1036  			{
  1036  			{
  1037  			TBTBasebandEventNotification event(ENotifySynchronousLinkUp);
  1037  			TBTBasebandEventNotification event(ENotifySynchronousLinkUp);
  1038  			NotifyStateChange(event);
  1038  			NotifyStateChange(event);
  1039  			}
  1039  			}
  1040 
  1040 
       
  1041 		if (iACLLogicalLinks.Count() == 0)
       
  1042 			{
       
  1043 			// We don't already have an ACL logical link associated with this phy, 
       
  1044 			// so, in order to not miss ACL data from the remote, associate this 
       
  1045 			// phy with an ACL listener if there is one.
       
  1046 			TLogicalLinkListener* listener = iLinksMan.FindListener(EACLLink);
       
  1047 	
       
  1048 			if (listener)
       
  1049 				{
       
  1050 				TBTConnect conn;
       
  1051 		
       
  1052 				conn.iBdaddr = iDevice.Address();
       
  1053 				conn.iCoD = iDevice.DeviceClass().DeviceClass();
       
  1054 				conn.iLinkType = EACLLink;
       
  1055 		
       
  1056 				// Ignore the return from ConnectRequest, if not accepted then we are in no
       
  1057 				// worse situation than if we didn't try.
       
  1058 				ASSERT_DEBUG(listener->iObserver);
       
  1059 				(void)listener->iObserver->ConnectRequest(conn, *this);
       
  1060 				}
       
  1061 			}
       
  1062 		
  1041 		// tell the logical links
  1063 		// tell the logical links
  1042 		NotifyLogicalLinkUp(aConn);
  1064 		NotifyLogicalLinkUp(aConn);
  1043 		iLinksMan.ArbitrateAllPhysicalLinks();
  1065 		iLinksMan.ArbitrateAllPhysicalLinks();
  1044 
  1066 
  1045 		// Check to see if we got a disconnect request during the period before the link was
  1067 		// Check to see if we got a disconnect request during the period before the link was
  1531 			CBTPairingsCache::TPairingState pairingState = iLinksMan.PairingsCache().IsPaired(aConn.iBdaddr);
  1553 			CBTPairingsCache::TPairingState pairingState = iLinksMan.PairingsCache().IsPaired(aConn.iBdaddr);
  1532 
  1554 
  1533 			if(pairingState == CBTPairingsCache::EDeferred)
  1555 			if(pairingState == CBTPairingsCache::EDeferred)
  1534 				{
  1556 				{
  1535 				// We're still waiting for the Pairing Caches paired device list to be filled.
  1557 				// We're still waiting for the Pairing Caches paired device list to be filled.
  1536  				// We'll respond when this is complete, so store details away for then.
  1558 				// We'll respond when this is complete, so store details away for then.
  1537 				LOG(_L("CPhysicalLink: Waiting for physical link manager's paired device list from Registry!"))
  1559 				LOG(_L("CPhysicalLink: Waiting for physical link manager's paired device list from Registry!"))
  1538 				iPendingConnection = ETrue;
  1560 				iPendingConnection = ETrue;
  1539     			iLastPendingConnection.iConnH = aConn.iConnH;
  1561 				iLastPendingConnection.iConnH = aConn.iConnH;
  1540 			    iLastPendingConnection.iBdaddr = aConn.iBdaddr;
  1562 				iLastPendingConnection.iBdaddr = aConn.iBdaddr;
  1541 			    iLastPendingConnection.iCoD = aConn.iCoD;
  1563 				iLastPendingConnection.iCoD = aConn.iCoD;
  1542 			    iLastPendingConnection.iLinkType = aConn.iLinkType;
  1564 				iLastPendingConnection.iLinkType = aConn.iLinkType;
  1543 			    iLastPendingConnection.iEncryptMode = aConn.iEncryptMode;
  1565 				iLastPendingConnection.iEncryptMode = aConn.iEncryptMode;
  1544 			    // Return now as we are waiting and don't want to 'RejectConnection'
  1566 				// Return now as we are waiting and don't want to 'RejectConnection'
  1545 				return;
  1567 				return;
  1546 				}
  1568 				}
  1547 
  1569 
  1548 			// If here then the cache has either informed us that the device is paired
  1570 			// If here then the cache has either informed us that the device is paired
  1549  			// or not.  We only accept paired connections.
  1571  			// or not.  We only accept paired connections.
  1697 				if (aOption.Length() != sizeof(TBasebandTime))
  1719 				if (aOption.Length() != sizeof(TBasebandTime))
  1698 					{
  1720 					{
  1699 					return KErrArgument;
  1721 					return KErrArgument;
  1700 					}
  1722 					}
  1701 				aOption = TPtrC8(reinterpret_cast<const TUint8*>(&iSniffInterval), sizeof(TBasebandTime));
  1723 				aOption = TPtrC8(reinterpret_cast<const TUint8*>(&iSniffInterval), sizeof(TBasebandTime));
  1702 			    return KErrNone;
  1724 				return KErrNone;
  1703 
  1725 
  1704 			default:
  1726 			default:
  1705 				return KErrNotSupported;
  1727 				return KErrNotSupported;
  1706 			}
  1728 			}
  1707 		}
  1729 		}
  1718 		return KErrDisconnected;
  1740 		return KErrDisconnected;
  1719 
  1741 
  1720 	if ( aImmediately )
  1742 	if ( aImmediately )
  1721 		{
  1743 		{
  1722 		iArbitrationDelay->Cancel();
  1744 		iArbitrationDelay->Cancel();
  1723         return DoArbitrate(aLocalPriority);		
  1745 		return DoArbitrate(aLocalPriority);		
  1724 		}
  1746 		}
  1725 	else if (iArbitrationDelay->IsActive())
  1747 	else if (iArbitrationDelay->IsActive())
  1726 		{
  1748 		{
  1727 		return KErrNone;
  1749 		return KErrNone;
  1728 		}
  1750 		}
  1729     else
  1751 	else
  1730         {
  1752 		{
  1731         iArbitrationDelay->Start(aLocalPriority);
  1753 		iArbitrationDelay->Start(aLocalPriority);
  1732         return KErrNone;
  1754 		return KErrNone;
  1733         }
  1755 		}
  1734     }
  1756 	}
  1735 
  1757 
  1736 TInt CPhysicalLink::DoArbitrate(TBool aLocalPriority)
  1758 TInt CPhysicalLink::DoArbitrate(TBool aLocalPriority)
  1737     {
  1759 	{
  1738     if (!IsConnected())
  1760 	if (!IsConnected())
  1739         {
  1761 		{
  1740         return KErrDisconnected;
  1762 		return KErrDisconnected;
  1741         }
  1763 		}
  1742 	    
  1764 
  1743 	//start arbitrate process with what our local controller supports
  1765 	//start arbitrate process with what our local controller supports
  1744 	TUint8 allowedModesMask = EHoldMode | EParkMode | ESniffMode; // local features sorted out later
  1766 	TUint8 allowedModesMask = EHoldMode | EParkMode | ESniffMode; // local features sorted out later
  1745 	TBool roleSwitchAllowed = EFalse;
  1767 	TBool roleSwitchAllowed = EFalse;
  1746 
  1768 
  1747  	if (iLinksMan.LinkManagerProtocol().IsRoleSwitchSupportedLocally() && iLinksMan.RoleSwitchAllowed())
  1769  	if (iLinksMan.LinkManagerProtocol().IsRoleSwitchSupportedLocally() && iLinksMan.RoleSwitchAllowed())
  2811 	// However, in UDEB we panic to raise awareness that the hardware is behaving incorrectly.
  2833 	// However, in UDEB we panic to raise awareness that the hardware is behaving incorrectly.
  2812 	__ASSERT_DEBUG(!iPinRequester, Panic(EBTConnectionPINRequestedTwice));
  2834 	__ASSERT_DEBUG(!iPinRequester, Panic(EBTConnectionPINRequestedTwice));
  2813 
  2835 
  2814 	SetAuthenticationPending(EPinRequestPending); // if not already set (because the remote initiated authentication).
  2836 	SetAuthenticationPending(EPinRequestPending); // if not already set (because the remote initiated authentication).
  2815 
  2837 
       
  2838 	__ASSERT_DEBUG(iSimplePairingMode != EPhySimplePairingEnabled, Panic(EBTSSPModeChangedDuringConnection));
       
  2839 	if (iSimplePairingMode == EPhySimplePairingUndefined)
       
  2840 		{
       
  2841 		iSimplePairingMode = EPhySimplePairingDisabled;
       
  2842 		}
       
  2843 	
       
  2844 	if (!IsConnected())
       
  2845 		{
       
  2846 		iPeerInSecurityMode3 = ETrue;
       
  2847 		}
       
  2848 
       
  2849 	
  2816 	if (iPinRequester)
  2850 	if (iPinRequester)
  2817 		{
  2851 		{
  2818 		return;
  2852 		return;
  2819 		}
  2853 		}
  2820 
  2854 
  3430 	CleanupStack::Pop(self);
  3464 	CleanupStack::Pop(self);
  3431 	return self;
  3465 	return self;
  3432 	}
  3466 	}
  3433 
  3467 
  3434 void CArbitrationDelayTimer::Start(TBool aLocalPriority)
  3468 void CArbitrationDelayTimer::Start(TBool aLocalPriority)
  3435     {
  3469 	{
  3436     LOG_FUNC
  3470 	LOG_FUNC
  3437     // Work out what the local priority will be now
  3471 	// Work out what the local priority will be now
  3438     TBool localPriority = iLocalPriority || aLocalPriority;
  3472 	TBool localPriority = iLocalPriority || aLocalPriority;
  3439     Cancel(); // cancel current timer (will also reset priority so ...
  3473 	Cancel(); // cancel current timer (will also reset priority so ...
  3440     iLocalPriority = localPriority; // set the new priority)
  3474 	iLocalPriority = localPriority; // set the new priority)
  3441 	After(KBTArbitrationDelay);
  3475 	After(KBTArbitrationDelay);
  3442 	}
  3476 	}
  3443 
  3477 
  3444 
  3478 
  3445 void CArbitrationDelayTimer::RunL()
  3479 void CArbitrationDelayTimer::RunL()
  3448 **/
  3482 **/
  3449 	{
  3483 	{
  3450 	LOG_FUNC
  3484 	LOG_FUNC
  3451 	if (iParent)
  3485 	if (iParent)
  3452 		{
  3486 		{
  3453         iParent->DoArbitrate(iLocalPriority);
  3487 		iParent->DoArbitrate(iLocalPriority);
  3454 		}
  3488 		}
  3455 	}
  3489 	}
  3456 
  3490 
  3457 void CArbitrationDelayTimer::DoCancel()
  3491 void CArbitrationDelayTimer::DoCancel()
  3458     {
  3492 	{
  3459     LOG_FUNC
  3493 	LOG_FUNC
  3460     CTimer::DoCancel();
  3494 	CTimer::DoCancel();
  3461     iLocalPriority = EFalse;
  3495 	iLocalPriority = EFalse;
  3462     }
  3496 	}
  3463 
  3497 
  3464 TInt CPhysicalLink::GetNumPendingHandles(TInt& aConnectionHandles, TLinkType aLinkType) const
  3498 TInt CPhysicalLink::GetNumPendingHandles(TInt& aConnectionHandles, TLinkType aLinkType) const
  3465 	{
  3499 	{
  3466 	LOG_FUNC
  3500 	LOG_FUNC
  3467 	aConnectionHandles = 0;
  3501 	aConnectionHandles = 0;