void headsetHandleAuthenticateCfm(const CL_SM_AUTHENTICATE_CFM_T *cfm)
{
    /* Leave bondable mode if successful unless we got a debug key */
    if (cfm->status == auth_status_success && cfm->key_type != cl_sm_link_key_debug)
    {
        /* Send a user event to the app for indication purposes */
        MessageSend (&theHeadset.task , EventPairingSuccessful , 0 );
    }
	
	/* Set up some default params and shuffle PDL */
	if(cfm->bonded)
	{	
		uint8 lAttributes[ATTRIBUTE_SIZE];
		/* Default volume set */
		lAttributes[attribute_hfp_volume] = theHeadset.gHfpVolumeLevel;	
		lAttributes[attribute_a2dp_volume] = theHeadset.gAvVolumeLevel;
		/* No profile set */
		lAttributes[attribute_hfp_hsp_profile] = 0;	
		lAttributes[attribute_a2dp_profile] = 0;	
		/* No SEID */
		lAttributes[attribute_seid] = 0;
		/* No clock rate mismatch */
		lAttributes[attribute_clock_mismatch] = 0;
	
		/* Write params to PS */
		ConnectionSmPutAttribute(PSKEY_ATTRIBUTE_BASE, &cfm->bd_addr, ATTRIBUTE_SIZE, lAttributes); 
		/* Shuffle the PDL around the device */
		ConnectionSmUpdateMruDevice(&cfm->bd_addr);
		
	}

    /* reset pairing info if we timed out on confirmation */
    AuthResetConfirmationFlags();
}
Example #2
0
/****************************************************************************
NAME    
    handleGetAuthDeviceCfm
    
DESCRIPTION
    Called in response to CL_SM_GET_AUTH_DEVICE_CFM message, which is generated
    due to calling updatePermanentPairing.
    Both the BDADDR and linkkey contained in CL_SM_GET_AUTH_DEVICE_CFM are used to
    update CONFIG_PERMANENT_PAIRING to retain this as the permanently paired device
    
RETURNS
    void
*/
void handleGetAuthDeviceCfm (CL_SM_GET_AUTH_DEVICE_CFM_T *cfm)
{
    AUTH_DEBUG(("handleGetAuthDeviceCfm\n"));
    AUTH_DEBUG(("   status = %u\n",cfm->status));
    AUTH_DEBUG(("   ps bd_addr = [%x:%x:%lx]\n", cfm->bd_addr.uap, cfm->bd_addr.nap, cfm->bd_addr.lap));
    AUTH_DEBUG(("   trusted = %u\n",cfm->trusted));
    AUTH_DEBUG(("   link key type = %u",cfm->link_key_type));
    AUTH_DEBUG(("   link key size = %u\n",cfm->size_link_key));
    
    if ( cfm->status == success )
    {   /* Device exists in CL PDL */
        sink_attributes attributes;
        uint16 link_key_status = ((cfm->trusted & 0xF)<<8) | ((cfm->link_key_type & 0xF)<<4) | (cfm->size_link_key & 0xF);
        
        /* Update permanent pairing info */
        writePsPermanentPairing(&cfm->bd_addr, cfm->link_key, link_key_status, 0);
        
        /* Update attributes */
        readPsPermanentPairing(0, 0, 0, &attributes);
        deviceManagerStoreAttributes(&attributes, (const bdaddr *)&cfm->bd_addr);
        
        /* Mark the device as trusted and push it to the top of the PDL */
        ConnectionSmUpdateMruDevice((const bdaddr *)&cfm->bd_addr);
#ifdef ENABLE_SOUNDBAR
        /* ensure priority devices are shifted back to top of PDL */
        ConnectionAuthSetPriorityDevice((const bdaddr *)&cfm->bd_addr, FALSE);            
#endif            
    }
    else
    {   /* Device *does not* exist in CL PDL */ 
        bdaddr ps_bd_addr;
        uint16 ps_link_key_status;
        uint16 ps_link_key[LINK_KEY_SIZE];
    
        readPsPermanentPairing(&ps_bd_addr, ps_link_key, &ps_link_key_status, 0);
    
        if ( !BdaddrIsZero(&ps_bd_addr) )
        {   /* We have permanently paired device, add it to CL PDL */
            bool trusted = (bool)((ps_link_key_status>>8) & 0xF);
            cl_sm_link_key_type key_type = (cl_sm_link_key_type)((ps_link_key_status>>4) & 0xF);
            uint16 size_link_key = ps_link_key_status & 0xF;
        
            ConnectionSmAddAuthDevice(&theSink.task, (const bdaddr *)&ps_bd_addr, trusted, TRUE, key_type, size_link_key, (const uint16 *)ps_link_key);
        }
    }
Example #3
0
/****************************************************************************
NAME
    deviceManagerSetPriority
    
DESCRIPTION
    Set a device's priority in the PDL

RETURNS
    new pdl listId of passed in src addr
*/
uint8 deviceManagerSetPriority(const bdaddr* dev_addr)
{
    conn_mask mask = deviceManagerProfilesConnected(dev_addr);
    uint8 ListId = 0;
    
    DEV_DEBUG(("DEV: Update PDL/MRU\n")) ;

    
    /* more than 1 connected device ? */
    if(deviceManagerNumConnectedDevs() > 1)
    {
        typed_bdaddr  typed_ag_addr;
        bdaddr ag_addr;
        sink_attributes attributes;      
 

        DEV_DEBUG(("DEV: Update MRU - two devices connected\n")) ;
        
        /* is this a connection of a2dp or hfp to the already connected primary device ? */            
        deviceManagerGetIndexedAttributes(0, &attributes, &typed_ag_addr);
        /* extract bluetooth address from packed structure */
        ag_addr = typed_ag_addr.addr;
        /* check if this is the primary device? */
        if(BdaddrIsSame(&ag_addr,dev_addr))
        {
            DEV_DEBUG(("DEV: Update MRU - two devices two profiles connected - primary device\n")) ;
            ListId = 0;
        }
        else
        {
            DEV_DEBUG(("DEV: Update MRU - two devices two profiles connected - secondary device\n")) ;
            /* Move the second device to top of the PDL */
            ConnectionSmUpdateMruDevice(dev_addr);      
            /* get bdaddr of the device that was previously the primary device but is
               now the secondary device */
            deviceManagerGetIndexedAttributes(1, &attributes, &typed_ag_addr);
            /* extract bluetooth address from packed structure */
            ag_addr = typed_ag_addr.addr;
            /* then move the what is now 'secondary device' back to the top of the PDL */                
            ConnectionSmUpdateMruDevice(&ag_addr);              
            /* this is the secondary device */
            ListId = 1;
            /* send connected event if not already done so */
            if(mask && !((mask & conn_hfp)&&(mask & conn_a2dp)))
            {
               MessageSend (&theSink.task , EventSecondaryDeviceConnected , NULL );        
            }
        }        
    }
    /* only 1 device so must be primary */
    else
    {
        /* Move device to top of the PDL */
        DEV_DEBUG(("DEV: Update MRU - primary device\n")) ;
        ConnectionSmUpdateMruDevice(dev_addr);    
        /* if this is the first profile for the device to be connected then send
           the primary device connected event */
        if(mask && !((mask & conn_hfp)&&(mask & conn_a2dp)))
        {
           MessageSend (&theSink.task , EventPrimaryDeviceConnected , NULL );        
        }
    }
   
    /* return current pdl list position of this device which is 0, top of list */        
    DEV_DEBUG(("DEV: Update MRU - ListId = %x\n",ListId)) ;
    return ListId;
}