ta/wallet_ta.c
/**
  * Load contents of non-volatile memory into a #WalletRecord structure. This
  * doesn't care if there is or isn't actually a wallet at the specified
  * address.
  * \param session_data A data pointer to a session context.
  * \param param_types The types of the four parameters.
  * \param params A pointer to an array of four parameters.
  * \return TEE_SUCCESS in case of success otherwise returns the result
  *         received from the failed operation. The information about all
  *         possible returns is present in TEE Client API Specification - 4.4.2
  *         published by GlobalPlatform.
  */
Load contents of non-volatile memory into a #WalletRecord structure. This
doesn't care if there is or isn't actually a wallet at the specified
address.
\param session_data A data pointer to a session context.
\param param_types The types of the four parameters.
\param params A pointer to an array of four parameters.
\return TEE_SUCCESS in case of success otherwise returns the result
received from the failed operation. The information about all
possible returns is present in TEE Client API Specification - 4.4.2
published by GlobalPlatform.
Load contents of non - volatile memory into a #WalletRecord structure . This doesn ' t care if there is or isn ' t actually a wallet at the specified address . \ param session_data A data pointer to a session context . \ param param_types The types of the four parameters . \ param params A pointer to an array of four parameters . \ return TEE_SUCCESS in case of success otherwise returns the result received from the failed operation . The information about all possible returns is present in TEE Client API Specification - 4 . 4 . 2 published by GlobalPlatform .
static TEE_Result read_wallet_record(Session_data * session_data, uint32_t param_types, TEE_Param params[4])
{
	WalletRecord * wallet_record;
	TEE_Result result = TEE_SUCCESS;
	uint32_t exp_param_types;
	uint32_t unencrypted_size;
    uint32_t encrypted_size;
	TEE_Param read_params[4];
	uint32_t read_param_types;
	exp_param_types = TEE_PARAM_TYPES(
							TEE_PARAM_TYPE_MEMREF_OUTPUT,
							TEE_PARAM_TYPE_VALUE_INPUT,
							TEE_PARAM_TYPE_NONE,
							TEE_PARAM_TYPE_NONE);
	read_param_types = TEE_PARAM_TYPES(
							TEE_PARAM_TYPE_MEMREF_OUTPUT,
							TEE_PARAM_TYPE_VALUE_INOUT,
							TEE_PARAM_TYPE_NONE,
							TEE_PARAM_TYPE_NONE);
	if (param_types != exp_param_types || params[0].memref.buffer == NULL)
		return TEE_ERROR_BAD_PARAMETERS;
	if(session_data->is_storage_open != true)
		return TEE_ERROR_BAD_STATE;
	wallet_record = (WalletRecord *)(params[0].memref.buffer);
    unencrypted_size = sizeof(wallet_record->unencrypted);
    encrypted_size = sizeof(wallet_record->encrypted);
    if (((unencrypted_size % 16) != 0) || ((encrypted_size % 16) != 0))
    {
    	return TEE_ERROR_BAD_FORMAT;
    }
	read_params[0].memref.buffer = (uint8_t *)&(wallet_record->unencrypted);
	read_params[0].memref.size =  (size_t)unencrypted_size;
	read_params[1].value.a = (uint32_t)(params[1].value.a + offsetof(WalletRecord, unencrypted) + (uint32_t)GLOBAL_PARTITION_SIZE);
	result = read_cache_wallet_storage(session_data, read_param_types, read_params);
	if (result != TEE_SUCCESS)
	{
		#ifdef OP_TEE_TA
		DMSG("Read wallet storage failed : 0x%x", result);
		#endif
		goto cleanup1;
	}
	result = encrypted_read_wallet_storage_internal(
					session_data,
					(uint8_t *)&(wallet_record->encrypted),
					encrypted_size,
					(uint32_t)(params[1].value.a + offsetof(WalletRecord, encrypted) + (uint32_t)GLOBAL_PARTITION_SIZE));
	if (result != TEE_SUCCESS)
	{
		#ifdef OP_TEE_TA
		DMSG("Read wallet encrypted storage failed : 0x%x", result);
		#endif
		goto cleanup1;
	}
	cleanup1:
		return result;
}
static TEE_Result read_wallet_record ( Session_data * session_data , uint32_t param_types , TEE_Param params [ 4 ] ) { WalletRecord * wallet_record ; TEE_Result result = TEE_SUCCESS ; uint32_t exp_param_types ; uint32_t unencrypted_size ; uint32_t encrypted_size ; TEE_Param read_params [ 4 ] ; uint32_t read_param_types ; exp_param_types = TEE_PARAM_TYPES ( TEE_PARAM_TYPE_MEMREF_OUTPUT , TEE_PARAM_TYPE_VALUE_INPUT , TEE_PARAM_TYPE_NONE , TEE_PARAM_TYPE_NONE ) ; read_param_types = TEE_PARAM_TYPES ( TEE_PARAM_TYPE_MEMREF_OUTPUT , TEE_PARAM_TYPE_VALUE_INOUT , TEE_PARAM_TYPE_NONE , TEE_PARAM_TYPE_NONE ) ; if ( param_types != exp_param_types || params [ 0 ] . memref . buffer == NULL ) return TEE_ERROR_BAD_PARAMETERS ; if ( session_data -> is_storage_open != true ) return TEE_ERROR_BAD_STATE ; wallet_record = ( WalletRecord * ) ( params [ 0 ] . memref . buffer ) ; unencrypted_size = sizeof ( wallet_record -> unencrypted ) ; encrypted_size = sizeof ( wallet_record -> encrypted ) ; if ( ( ( unencrypted_size % 16 ) != 0 ) || ( ( encrypted_size % 16 ) != 0 ) ) { return TEE_ERROR_BAD_FORMAT ; } read_params [ 0 ] . memref . buffer = ( uint8_t * ) & ( wallet_record -> unencrypted ) ; read_params [ 0 ] . memref . size = ( size_t ) unencrypted_size ; read_params [ 1 ] . value . a = ( uint32_t ) ( params [ 1 ] . value . a + offsetof ( WalletRecord , unencrypted ) + ( uint32_t ) GLOBAL_PARTITION_SIZE ) ; result = read_cache_wallet_storage ( session_data , read_param_types , read_params ) ; if ( result != TEE_SUCCESS ) { #ifdef OP_TEE_TA DMSG ( " " , result ) ; #endif goto cleanup1 ; } result = encrypted_read_wallet_storage_internal ( session_data , ( uint8_t * ) & ( wallet_record -> encrypted ) , encrypted_size , ( uint32_t ) ( params [ 1 ] . value . a + offsetof ( WalletRecord , encrypted ) + ( uint32_t ) GLOBAL_PARTITION_SIZE ) ) ; if ( result != TEE_SUCCESS ) { #ifdef OP_TEE_TA DMSG ( " " , result ) ; #endif goto cleanup1 ; } cleanup1 : return result ; }
Load contents of non-volatile memory into a #WalletRecord structure.
Load contents of non - volatile memory into a #WalletRecord structure .
/* Declare read operation parameters */ /*
	 * Expected:
	 * [OUT] params[0].memref.buffer -> Structure to write the wallet record read.
	 * [OUT] params[0].memref.size   -> Size of the wallet record to be read.
	 * [IN]  params[1].value.a       -> Address to read the wallet record from.
	 */ /*
	 * Read parameters:
	 * [OUT] params[0].memref.buffer -> Buffer to store the read data.
	 * [OUT] params[0].memref.size   -> Size of the buffer.
	 * [IN]  params[1].value.a       -> Starting address of the reading.
	 * [OUT] params[1].value.b       -> Size actually read.
	 */ /* Check the received parameter types and the pointer of the first parameter */ /*
     * Before doing any reading, do some sanity checks. These ensure that the
     * size of the unencrypted and encrypted portions are an integer multiple of
     * the AES block size
     */ /*
    	 * Here the return should be return TEE_ERROR_BAD_STATE; but to
    	 * differentiate the WalletError return the return is different
    	 */ /* Define the read operation parameters */ /* Read the wallet record (unencrypted section) */ /* Read the wallet record (encrypted section) */