コード例 #1
0
/****************************************************************************
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);
}
コード例 #2
0
ファイル: sudoku.cpp プロジェクト: hnzhang/algorithms
bool sudoku(std::vector< std::vector<int> >& data)
{
    int x, y;
    if(!find_free_position(data, x, y))//the sudoku is fully filled now
        return true;
    else
    {
        //get all free positions and iterate
        for(int i = 1; i <= 9; i++)
        {
            if(no_violation(data, x, y, i))
            {
                data[x][y]=i;
                if(sudoku(data))
                    return true;
                data[x][y] = 0;
            }
        }
        return false;//all possibility fails
    }
}