Пример #1
0
/****************************************************************************
NAME 
 	configManagerWriteSessionData

*/ 
void configManagerWriteSessionData( void )
{
    session_data_type lTemp ;

    lTemp.vol_orientation   = theSink.gVolButtonsInverted;
    lTemp.led_disable       = theSink.theLEDTask->gLEDSEnabled;
	lTemp.tts_language      = theSink.tts_language;
    lTemp.tts_enable        = theSink.tts_enabled;
    lTemp.multipoint_enable = theSink.MultipointEnable;
    lTemp.iir_enable        = theSink.iir_enabled ;
    lTemp.lbipm_enable      = theSink.lbipmEnable;
    lTemp.ssr_enabled       = theSink.ssr_enabled;
    lTemp.eq                = 0;
    lTemp.unused            = 0;
    lTemp.audio_enhancements = ((theSink.a2dp_link_data->a2dp_audio_mode_params.music_mode_processing - A2DP_MUSIC_PROCESSING_FULL_SET_EQ_BANK0) & A2DP_MUSIC_CONFIG_USER_EQ_SELECT)|
                               (theSink.a2dp_link_data->a2dp_audio_mode_params.music_mode_enhancements & ~A2DP_MUSIC_CONFIG_USER_EQ_SELECT);
#ifdef ENABLE_FM
    lTemp.fm_frequency      = theSink.conf2->sink_fm_data.fmRxTunedFreq;
#else
    lTemp.fm_frequency = 0;
#endif    

    CONF_DEBUG(("CONF : PS Write Vol Inverted[%c], LED Disable [%c], Multipoint Enable [%c], IIR Enable [%c], LBIPM Enable [%c] Enhancements[%x]\n" , 
						theSink.gVolButtonsInverted ? 'T':'F' , 
						lTemp.led_disable ? 'T':'F',
                        theSink.MultipointEnable ? 'T':'F',
                        theSink.iir_enabled ? 'T':'F',
                        theSink.lbipmEnable ? 'T':'F',
                        lTemp.audio_enhancements));
    
    (void) PsStore(PSKEY_VOLUME_ORIENTATION, &lTemp, sizeof(session_data_type)); 
    
}
/****************************************************************************
NAME
	connectionAuthSetTrustLevel

FUNCTION
	This function is called to set the trust level of a device stored in the
    trusted device list.  The Blustack Security Manager is updated with the
    change.

RETURNS
	TRUE is record updated, otherwise FALSE
*/
uint16 connectionAuthSetTrustLevel(cl_dm_bt_version version, const bdaddr* peer_bd_addr, uint16 trusted)
{
    /* Holds the position of a device in the trusted device list (TDL) */
	uint16  rec = 0;
    TrustedDeviceRecordType record;
    
    /* Search for the device in the TDL */
	rec = find_trusted_device(peer_bd_addr);

	
	/* If the device is in the TDL */
	if(rec)
	{
		rec--;

		/* Read the record */
		(void)PsRetrieve(TRUSTED_DEVICE_LIST_BASE + rec, &record, sizeof(TrustedDeviceRecordType));

        /* Update the trust level */
        record.trusted = trusted;

        /* Store the record */
	    (void)PsStore(TRUSTED_DEVICE_LIST_BASE + rec, &record, sizeof(TrustedDeviceRecordType));

        /* Update Bluestack Security Manager Database */
        register_device(version, &record);
		
        /* Record updated */
        return TRUE;
    }

	
    /* Record for this device does not exist */
    return FALSE;
}
/****************************************************************************
NAME
	connectionAuthDeleteDevice

FUNCTION
	This function is called to remove a trusted device from the persistent 
    trusted device list.  A flag indicating if the device was successfully removed 
    is returned.
*/
uint16 connectionAuthDeleteDevice(const bdaddr* peer_bd_addr)
{
    /* Holds the position of a device in the trusted device list (TDL) */
	uint16		position = 0;

    /* Defines the order or the device in the TDI */
	uint16		order = 0;

    /* Flag to indicate if the device was deleted */
    uint16      deleted = FALSE;

	
    /* Search the trusted device list for the specified device */
	position = find_trusted_device(peer_bd_addr);
	
	/* If the device is in the TDL */
	if(position)
	{
        /* Find this device in the TDI */
		order = search_trusted_device_index(position);

        /* Delete it and re-order TDI */
        (void) delete_from_trusted_device_index(order, NO_DEVICES_TO_MANAGE);

        /* Delete device from TDL */
        (void) PsStore(TRUSTED_DEVICE_LIST_BASE + position - 1, NULL, 0);

        /* Remove from the BlueStack security datatbase */
		unregister_device(peer_bd_addr);

		deleted = TRUE;	
	}
	return deleted;
}
/****************************************************************************

DESCRIPTION
	This function will delete an entry from the trusted device index
*/
static uint16 delete_from_trusted_device_index(uint16 order, uint16 noDevices)
{
    TrustedDeviceIndexType		tdi;
	uint16						index;
    uint16                      ok = FALSE;
	
	/* Read the TDI from persistent store */
	if(PsRetrieve(TRUSTED_DEVICE_INDEX, &tdi, sizeof(tdi)))
	{
		if(order != INDEX_INVALID)
		{
			/* Delete index from TDI and reorder TDI */
			for(index = order; index < (noDevices - 1); index++)
				tdi.order[index] = tdi.order[index+1];

            /* LRU index is now invalid */
            tdi.order[noDevices - 1] = 0;
		}
		
		/* Store persistently */
		(void)PsStore(TRUSTED_DEVICE_INDEX, &tdi, sizeof(tdi));

        ok = TRUE;
	}

	return ok;
}
Пример #5
0
void configManagerRestoreDefaults( void ) 
{
    CONF_DEBUG(("CO: Restore Defaults\n")) ;
    /*Set local values*/
	theSink.gVolButtonsInverted = FALSE ;
    
    theSink.tts_language = 0 ;
    theSink.tts_enabled = TRUE;
    configManagerEnableMultipoint(FALSE);
    theSink.iir_enabled = FALSE  ;
    theSink.lbipmEnable = FALSE ;
    theSink.a2dp_link_data->a2dp_audio_mode_params.music_mode_processing = A2DP_MUSIC_PROCESSING_FULL;
    
	/*Reset PSKEYS*/
	(void)PsStore ( PSKEY_VOLUME_ORIENTATION , 0 , 0 ) ;
    
	/*Call function to reset the PDL*/
	deviceManagerRemoveAllDevices();
	
	if	(!(theSink.theLEDTask->gLEDSEnabled))
	{
		/*Enable the LEDs*/
		MessageSend (&theSink.task , EventEnableLEDS , 0) ;
	}
}
Пример #6
0
/****************************************************************************
NAME
    UpgradeSavePSKeys  -  Save our PSKEYS

DESCRIPTION
    Save our PSKEYS into Persistent Storage.

    The existing contents of the key are read first. If they chance not to 
    exist the the value we do not control are set to 0x0000 (deemed safer 
    than panicking or using a marker such as 0xFACE)

    Note that the upgrade library initialisation has guaranteed that the 
    the pskeys fit within the 64 words allowed.
    
    Although not technically part of our API, safest if we allow for the 
    PSKEY to be longer than we use.
*/
void UpgradeSavePSKeys(void)
{
    uint16 keyCache[PSKEY_MAX_STORAGE_LENGTH];
    uint16 min_key_length = UpgradeCtxGet()->upgrade_library_pskeyoffset
                                    +UPGRADE_PRIVATE_PSKEY_USAGE_LENGTH_WORDS;

    /* Find out how long the PSKEY is */
    uint16 actualLength = PsRetrieve(UpgradeCtxGet()->upgrade_library_pskey,NULL,0);
    if (actualLength)
    {
        PsRetrieve(UpgradeCtxGet()->upgrade_library_pskey,keyCache,actualLength);
    }
    else
    {
        if (UpgradeCtxGet()->upgrade_library_pskeyoffset)
        {
            /* Initialise the portion of key before us */
            memset(keyCache,0x0000,sizeof(keyCache));
        }
        actualLength = min_key_length;
    }

    /* Correct for too short a key */
    if (actualLength < min_key_length)
    {
        actualLength = min_key_length;
    }

    memcpy(&keyCache[UpgradeCtxGet()->upgrade_library_pskeyoffset],UpgradeCtxGetPSKeys(),
                UPGRADE_PRIVATE_PSKEY_USAGE_LENGTH_WORDS*sizeof(uint16));
    PsStore(UpgradeCtxGet()->upgrade_library_pskey,keyCache,actualLength);
}
/****************************************************************************
NAME
	connectionAuthDeleteAllDevices

FUNCTION
	This function is called to remove all trusted devices from the persistent 
    trusted device list.  A flag indicating if all the devices were successfully 
	removed is returned.
*/
uint16 connectionAuthDeleteAllDevice(uint16 ps_base)
{
	/* Flag to indicate if the devices were deleted */
    uint16      				deleted = FALSE;
	
	/* Trusted device list record index */
	uint16						rec = 0;
	
	/* Trusted device record */
	TrustedDeviceRecordType     record;
	
	/* trusted device index */
	TrustedDeviceIndexType		tdi;
	
	/* Loop through list of trusted devices */
	for(rec = 0; rec < NO_DEVICES_TO_MANAGE; rec++)
	{
		if(PsRetrieve(TRUSTED_DEVICE_LIST_BASE + rec, &record, sizeof(TrustedDeviceRecordType)))
		{
			/* Unregister with Bluestack security manager */
			unregister_device(&record.bd_addr);
			
			/* Delete entry from TDL */
			(void)PsStore(TRUSTED_DEVICE_LIST_BASE + rec, NULL, 0);

			deleted = TRUE;
		}

		/* Delete any associated attribute data */
		if(ps_base)
		{
			(void)PsStore(ps_base + rec, NULL, 0);
		}
	}
	
	/* Delete TDI */
	if(deleted)
	{
		memset(&tdi, 0, sizeof(TrustedDeviceIndexType));
		(void)PsStore(TRUSTED_DEVICE_INDEX, &tdi, sizeof(tdi));
	}
	
	return deleted;
}
/****************************************************************************
NAME
	connectionAuthPutAttribute

FUNCTION
	This function is called to store the specified data in the specified 
	persistent  store key.  The persistent store key is calulated from
	the specified base + the index of the specified device in TDL.

RETURNS
*/
void connectionAuthPutAttribute(uint16 ps_base, const bdaddr* bd_addr, uint16 size_psdata, const uint8* psdata)
{
	uint16 index = find_trusted_device(bd_addr);
	
	if(index)
	{
		index--;
		(void)PsStore(ps_base + index, psdata, size_psdata);
	}
}
/****************************************************************************
NAME
	connectionAuthAddDevice

FUNCTION
	This function is called to add a trusted device to the persistent trusted 
	device list.  A flag indicating if the device was successfully added is
	returned.
*/
uint16 connectionAuthAddDevice(cl_dm_bt_version version, const bdaddr* peer_bd_addr, cl_sm_link_key_type link_key_type, const uint8* link_key, uint16 trusted, uint16 bonded)
{
	/* Holds the position of a device in the trusted device list (TDL) */
	uint16		position = 0;
	/* Defines the Most Recently Used (MRU) order of a device  */
	uint16		order = 0;

	/* Search the trusted device list for the specified device */
	position = find_trusted_device(peer_bd_addr);
	
	/* If the device to be added is currently stored in the TDL */
	if(position)
	{
		/* Determine the MRU order of the device by searching for the 
		   device position in the Trusted Device Index (TDI) */
		order = search_trusted_device_index(position);
	}
	else
	{
		/* The device is not currently in the trusted device list, find
		   a free position in the TDL to store the new device.  The next
		   free position will either be an empty one or the LRU. Dont do
 		   this if we're not bonding as we dont need to store the device */
		if(bonded)
		{
			order = NO_DEVICES_TO_MANAGE - 1;
			position = find_free_position();

			/* Limit check position */
			if(position == 0)
				position = 1;
		}
	}

	if(bonded)
	{
		/* Keep a track of the the most recently used device by updating the TDI */
		update_trusted_device_index(position, order);
	}
	else
	{
		/* If we have a bonded key for this device */
		if(position)
		{
			/* Delete it and re-order TDI */
        	(void) delete_from_trusted_device_index(order, NO_DEVICES_TO_MANAGE);

        	/* Delete device from TDL */
        	(void) PsStore(TRUSTED_DEVICE_LIST_BASE + position - 1, NULL, 0);
		}
	}

	/* Store the new device in the TDL (or just register it if non bonded) */
	return update_trusted_device_list(version, position, peer_bd_addr, link_key_type, link_key, trusted, bonded);
}
Пример #10
0
/****************************************************************************
NAME 
  	configManagerFillPs

DESCRIPTION
  	Fill PS to the point defrag is required (for testing only)

RETURNS
  	void
*/
void configManagerFillPs(void)
{
    CONF_DEBUG(("CONF: Fill PS ")) ;
    if(theSink.rundata->defrag.key_size)
    {
        uint16 count     = PsFreeCount(theSink.rundata->defrag.key_size);
        uint16* buff     = mallocPanic(theSink.rundata->defrag.key_size);
        CONF_DEBUG(("[%d] ", count));
        if(count > theSink.rundata->defrag.key_minimum)
        {
            for(count = count - theSink.rundata->defrag.key_minimum ; count > 0; count --)
            {
                *buff = count;
                PsStore(PSKEY_CONFIGURATION_ID, buff, theSink.rundata->defrag.key_size);
            }
            PsStore(PSKEY_CONFIGURATION_ID, &theSink.config_id, sizeof(uint16));
        }
        CONF_DEBUG(("[%d]", PsFreeCount(theSink.rundata->defrag.key_size)));
    }
    CONF_DEBUG(("\n"));
}
/****************************************************************************
NAME
	connectionAuthInit

FUNCTION
	This function is called to initialise the Trusted Device List.  All
	devices in the list are registered with the Bluestack Security Manager.

RETURNS
	The number of devices registered with Bluestack
*/
uint16 connectionAuthInit(cl_dm_bt_version version)
{
	uint16					registeredDevices = 0;
	TrustedDeviceIndexType	tdi;
	uint16					rec;
    TrustedDeviceRecordType record;
	
	/* Check if we have a valid Trusted Device Index */
	if(!PsRetrieve(TRUSTED_DEVICE_INDEX, &tdi, sizeof(tdi)))
	{
		/* Reset TDI to zero */
		memset(&tdi, 0, sizeof(TrustedDeviceIndexType));
		(void)PsStore(TRUSTED_DEVICE_INDEX, &tdi, sizeof(tdi));

		/* Delete TDL */
		for(rec = TRUSTED_DEVICE_LIST_BASE; rec <= TRUSTED_DEVICE_LIST_END; rec++)
			(void)PsStore(rec, NULL, 0);
	}
	else
	{
		/* Search through the Trusted Device List */
		for(rec = 0; rec < NO_DEVICES_TO_MANAGE; rec++)
		{
			/* For all devices in the list... */
			if(PsRetrieve(TRUSTED_DEVICE_LIST_BASE + rec, &record, sizeof(TrustedDeviceRecordType)))
			{
				
				/* Register the device with Bluestack Security Manager */
				register_device(version, &record);
				
				/* Keep a count of the number of active device records */
				registeredDevices++;
			}
		}
	}

	/* Return the number of devices registered with the Bluestack Security Manager */
	return registeredDevices;
}
Пример #12
0
/****************************************************************************
NAME 
 	configManagerWriteSessionData

*/ 
void configManagerWriteSessionData( void )
{
    session_data_type lTemp ;

    lTemp.vol_orientation   = theHeadset.gVolButtonsInverted;
	
#ifdef ROM_LEDS	
    lTemp.led_disable       = theHeadset.theLEDTask->gLEDSEnabled;
#endif	

#ifdef Rubidium
    lTemp.tts_language      = Language;
	lTemp.Rubidium_enable	= 0;/*Enable*/
#else
    lTemp.tts_language      = theHeadset.tts_language;
#endif

    lTemp.multipoint_enable = theHeadset.MultipointEnable;

#ifdef ENABLE_ENERGY_FILTER
    lTemp.iir_enable        = theHeadset.iir_enabled ;
#endif

#ifdef T3ProductionTest

	lTemp.Productionflag	= theHeadset.ProductionData;

	CONF_DEBUG(("CONF : PS Write Vol Inverted[%c], LED Disable [%c], Multipoint Enable [%c], IIR Enable [%c]\n" , 
					theHeadset.gVolButtonsInverted ? 'T':'F' , 
					lTemp.led_disable ? 'T':'F',
					theHeadset.MultipointEnable ? 'T':'F',
					theHeadset.iir_enabled ? 'T':'F'));

#else
	lTemp.lbipm_enable      = theHeadset.lbipmEnable;
	CONF_DEBUG(("CONF : PS Write Vol Inverted[%c], LED Disable [%c], Multipoint Enable [%c], IIR Enable [%c], LBIPM Enable [%c]\n" , 
					theHeadset.gVolButtonsInverted ? 'T':'F' , 
					lTemp.led_disable ? 'T':'F',
					theHeadset.MultipointEnable ? 'T':'F',
					theHeadset.iir_enabled ? 'T':'F',
					theHeadset.lbipmEnable ? 'T':'F'));

#endif
	lTemp.unused = 0;

    (void) PsStore(PSKEY_VOLUME_ORIENTATION, &lTemp, sizeof(session_data_type)); 
}
/****************************************************************************

DESCRIPTION
	This function will find the next free position in the Trusted Device List.

*/
static uint16 find_free_position(void)
{
	uint16						rec,index;
	TrustedDeviceIndexType		tdi;
	uint16						pos;
    TrustedDeviceRecordType     record;

	/* Loop through list of trusted devices */
	for(rec = 0; rec < NO_DEVICES_TO_MANAGE; rec++)
	{
		if(!PsRetrieve(TRUSTED_DEVICE_LIST_BASE + rec, &record, sizeof(TrustedDeviceRecordType)))
        {
			return (rec + 1);
        }
	}

	/* As the Trusted Device List is full then the position will be the
	   one occupied by the LRU device */
	(void)PsRetrieve(TRUSTED_DEVICE_INDEX, &tdi, sizeof(tdi));
	
	/* The LRU device is either the last device in the index or if empty (0) we
	   must traverse through the list to find the device */
	index = NO_DEVICES_TO_MANAGE;
	do
	{
		if(tdi.order[--index])
			break;
	}
	while(index);

	/* Record position */
	pos = tdi.order[index];
	
	if (PsRetrieve(TRUSTED_DEVICE_LIST_BASE + pos - 1, &record, sizeof(TrustedDeviceRecordType)))
		/* Remove from the BlueStack security datatbase */
		unregister_device(&record.bd_addr);

	/* Remove LRU device from the TDI */
	tdi.order[index] = 0; 
	(void)PsStore(TRUSTED_DEVICE_INDEX, &tdi, sizeof(tdi));	

	return pos;
}
/****************************************************************************

DESCRIPTION
	This function updates a record in the Trusted Device List
*/
static uint16 update_trusted_device_list ( cl_dm_bt_version version, 
										const uint16 position, 
										const bdaddr* peer_bd_addr, 
										uint8 link_key_type, 
										const uint8* link_key,
                                        uint16 trusted,
										uint16 bonded)
{
	uint16 rec = 0;
    uint16 ok = TRUE;
    TrustedDeviceRecordType record;

	/* Check position is valid */
	if(position)
		rec  = position - 1;

	/* Populate device record structure */
	record.bd_addr = *peer_bd_addr;
	record.link_key_type = link_key_type;
	memcpy(record.link_key, link_key, SIZE_LINK_KEY);
	record.trusted = trusted;
	
	if(bonded)
	{		
		/* Store trusted device persistently in the list */
		if(PsStore(TRUSTED_DEVICE_LIST_BASE + rec, &record, sizeof(TrustedDeviceRecordType)))
    	{
        	/* Update the device in the Bluestack Security Manager database */
			register_device(version, &record);
    	}
    	else
    	{
        	ok = FALSE;
    	}
	}
	else
	{
		/* Update the device in the Bluestack Security Manager database */
		register_device(version, &record);
	}
	
    return ok;     
}
Пример #15
0
/****************************************************************************
NAME    
    AuthRemovePermanentPairing
    
DESCRIPTION
    Removes permanent paired device from Connection library's PDL.
    Will also erase CONFIG_PERMANENT_PAIRING if erase_ps_key set TRUE.
    
RETURNS
    void
*/
void AuthRemovePermanentPairing (bool erase_ps_key)
{
    bdaddr ps_bd_addr;
    
    AUTH_DEBUG(("AuthRemovePermanentPairing  erase_ps_key = %u\n", erase_ps_key));
    
    readPsPermanentPairing(&ps_bd_addr, 0, 0, 0);
    AUTH_DEBUG(("   ps bd_addr = [%x:%x:%lx]\n", ps_bd_addr.uap, ps_bd_addr.nap, ps_bd_addr.lap));
    
    if ( !BdaddrIsZero(&ps_bd_addr) )
    {
        ConnectionSmDeleteAuthDeviceReq(TYPED_BDADDR_PUBLIC, (const bdaddr *)&ps_bd_addr);
    }
    
    if ( erase_ps_key )
    {
        PsStore(CONFIG_PERMANENT_PAIRING, 0, 0);
    }
}
/****************************************************************************

DESCRIPTION
	This function updates the Trusted Device Index
*/
static void update_trusted_device_index(const uint16 position, const uint16 order)
{
	TrustedDeviceIndexType		tdi;
	uint16						index;
	
	/* Read the TDI from persistent store */
	if(PsRetrieve(TRUSTED_DEVICE_INDEX, &tdi, sizeof(tdi)))
	{
		if(order != INDEX_INVALID)
		{
			/* Re-order TDI */
			for(index = 0; index < order; index++)
				tdi.order[order - index] = tdi.order[(order - index) - 1];
		}
		
		/* Update with the position of the new record in the TDL as MRU device */
		tdi.order[0] = position;
		
		/* Store persistently */
		(void)PsStore(TRUSTED_DEVICE_INDEX, &tdi, sizeof(tdi));
	}
}
Пример #17
0
void configManagerRestoreDefaults( void ) 
{
#ifdef ChineseTTS
	configManagerReadSessionData(0);
#else

    CONF_DEBUG(("CO: Restore Defaults\n")) ;
    /*Set local values*/
	theHeadset.gVolButtonsInverted = FALSE ;
    
    theHeadset.tts_language = FALSE ;
    theHeadset.MultipointEnable = FALSE ;
#ifdef ENABLE_ENERGY_FILTER
    theHeadset.iir_enabled = FALSE  ;
#endif

#ifdef T3ProductionTest
	theHeadset.ProductionData = 0;
#else
	theHeadset.lbipmEnable = FALSE ;
#endif
    
	/*Reset PSKEYS*/
	(void)PsStore ( PSKEY_VOLUME_ORIENTATION , 0 , 0 ) ;
    
	/*Call function to reset the PDL*/
	configManagerReset();
	
#ifdef ROM_LEDS
	if	(!(theHeadset.theLEDTask->gLEDSEnabled))
	{
		/*Enable the LEDs*/
		MessageSend (&theHeadset.task , EventEnableLEDS , 0) ;
	}
#endif
#endif
}
Пример #18
0
static void writePsPermanentPairing (const bdaddr *bd_addr, uint16 *link_key, uint16 link_key_status, const sink_attributes *attributes)
{
    uint16 * ps_key;
    
    /* Allocate and zero buffer to hold PS key */
    ps_key = mallocPanic(BD_ADDR_SIZE + LINK_KEY_SIZE + ATTRIBUTES_SIZE + 1);
    memset(ps_key, 0, BD_ADDR_SIZE + LINK_KEY_SIZE + ATTRIBUTES_SIZE + 1);
    
    /* Attempt to obtain current pairing data */
    PsRetrieve(CONFIG_PERMANENT_PAIRING, ps_key, BD_ADDR_SIZE + LINK_KEY_SIZE + ATTRIBUTES_SIZE + 1);
    
    /* Update supplied fields */
    if (link_key_status)
    {
        ps_key[STATUS_LOC] = link_key_status;
    }
    
    if (bd_addr)
    {
        memcpy(&ps_key[BD_ADDR_LOC], bd_addr, BD_ADDR_SIZE);
    }
    
    if (link_key)
    {
        memcpy(&ps_key[LINK_KEY_LOC], link_key, LINK_KEY_SIZE);
    }
    
    if (attributes)
    {
        memcpy(&ps_key[ATTRIBUTES_LOC], attributes, ATTRIBUTES_SIZE);
    }
    
    /* Store updated pairing data */
    PsStore(CONFIG_PERMANENT_PAIRING, ps_key, BD_ADDR_SIZE + LINK_KEY_SIZE + ATTRIBUTES_SIZE + 1);
    
    free(ps_key);
}