ta/wallet_ta.c
/**
  * Store contents of #current_wallet into non-volatile memory. This will also
  * call flush_wallet_storage_internal(), since that's usually what's wanted anyway.
  * \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.
  */
Store contents of #current_wallet into non-volatile memory. This will also
call flush_wallet_storage_internal(), since that's usually what's wanted anyway.
\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.
Store contents of #current_wallet into non - volatile memory . This will also call flush_wallet_storage_internal () since that ' s usually what ' s wanted anyway . \ 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 write_current_wallet_record(Session_data * session_data, uint32_t param_types, TEE_Param params[4])
{
	NonVolatileReturn nv_error;
	TEE_Result result = TEE_SUCCESS;
	uint32_t exp_param_types;
	TEE_Param write_params[4];
	uint32_t write_param_types;
	exp_param_types = TEE_PARAM_TYPES(
							TEE_PARAM_TYPE_VALUE_INPUT,
							TEE_PARAM_TYPE_NONE,
							TEE_PARAM_TYPE_NONE,
							TEE_PARAM_TYPE_NONE);
	write_param_types = TEE_PARAM_TYPES(
							TEE_PARAM_TYPE_MEMREF_INPUT,
							TEE_PARAM_TYPE_VALUE_INOUT,
							TEE_PARAM_TYPE_NONE,
							TEE_PARAM_TYPE_NONE);
	if (param_types != exp_param_types)
		return TEE_ERROR_BAD_PARAMETERS;
	if(session_data->is_storage_open != true)
		return TEE_ERROR_BAD_STATE;
	write_params[0].memref.buffer =  (uint8_t *)&(session_data->current_wallet->unencrypted);
	write_params[0].memref.size =  sizeof(session_data->current_wallet->unencrypted);
	write_params[1].value.a = (uint32_t)(params[0].value.a + offsetof(WalletRecord, unencrypted) + GLOBAL_PARTITION_SIZE);
	result = write_cache_wallet_storage(session_data,
										write_param_types,
										write_params);
	nv_error = (NonVolatileReturn)(write_params[1].value.b);
	if (result != TEE_SUCCESS || nv_error != NV_NO_ERROR)
	{
		#ifdef OP_TEE_TA
		DMSG("Write wallet storage failed: 0x%x", result);
		#endif
		goto cleanup1;
	}
	result = encrypted_write_wallet_storage_internal(
					session_data,
					(uint8_t *)&(session_data->current_wallet->encrypted),
					sizeof(session_data->current_wallet->encrypted),
					(uint32_t)(params[0].value.a + sizeof(session_data->current_wallet->unencrypted) + GLOBAL_PARTITION_SIZE),
					&nv_error);
	if (result != TEE_SUCCESS || nv_error != NV_NO_ERROR)
	{
		#ifdef OP_TEE_TA
		DMSG("Write wallet encrypted storage failed: 0x%x", result);
		#endif
		goto cleanup1;
	}
	result = flush_wallet_storage_internal(session_data, &nv_error);
	if (result != TEE_SUCCESS || nv_error != NV_NO_ERROR)
	{
		#ifdef OP_TEE_TA
		DMSG("Flush wallet storage failed: 0x%x", result);
		#endif
		goto cleanup1;
	}
	cleanup1:
		return result;
}
static TEE_Result write_current_wallet_record ( Session_data * session_data , uint32_t param_types , TEE_Param params [ 4 ] ) { NonVolatileReturn nv_error ; TEE_Result result = TEE_SUCCESS ; uint32_t exp_param_types ; TEE_Param write_params [ 4 ] ; uint32_t write_param_types ; exp_param_types = TEE_PARAM_TYPES ( TEE_PARAM_TYPE_VALUE_INPUT , TEE_PARAM_TYPE_NONE , TEE_PARAM_TYPE_NONE , TEE_PARAM_TYPE_NONE ) ; write_param_types = TEE_PARAM_TYPES ( TEE_PARAM_TYPE_MEMREF_INPUT , TEE_PARAM_TYPE_VALUE_INOUT , TEE_PARAM_TYPE_NONE , TEE_PARAM_TYPE_NONE ) ; if ( param_types != exp_param_types ) return TEE_ERROR_BAD_PARAMETERS ; if ( session_data -> is_storage_open != true ) return TEE_ERROR_BAD_STATE ; write_params [ 0 ] . memref . buffer = ( uint8_t * ) & ( session_data -> current_wallet -> unencrypted ) ; write_params [ 0 ] . memref . size = sizeof ( session_data -> current_wallet -> unencrypted ) ; write_params [ 1 ] . value . a = ( uint32_t ) ( params [ 0 ] . value . a + offsetof ( WalletRecord , unencrypted ) + GLOBAL_PARTITION_SIZE ) ; result = write_cache_wallet_storage ( session_data , write_param_types , write_params ) ; nv_error = ( NonVolatileReturn ) ( write_params [ 1 ] . value . b ) ; if ( result != TEE_SUCCESS || nv_error != NV_NO_ERROR ) { #ifdef OP_TEE_TA DMSG ( " " , result ) ; #endif goto cleanup1 ; } result = encrypted_write_wallet_storage_internal ( session_data , ( uint8_t * ) & ( session_data -> current_wallet -> encrypted ) , sizeof ( session_data -> current_wallet -> encrypted ) , ( uint32_t ) ( params [ 0 ] . value . a + sizeof ( session_data -> current_wallet -> unencrypted ) + GLOBAL_PARTITION_SIZE ) , & nv_error ) ; if ( result != TEE_SUCCESS || nv_error != NV_NO_ERROR ) { #ifdef OP_TEE_TA DMSG ( " " , result ) ; #endif goto cleanup1 ; } result = flush_wallet_storage_internal ( session_data , & nv_error ) ; if ( result != TEE_SUCCESS || nv_error != NV_NO_ERROR ) { #ifdef OP_TEE_TA DMSG ( " " , result ) ; #endif goto cleanup1 ; } cleanup1 : return result ; }
Store contents of #current_wallet into non-volatile memory.
Store contents of #current_wallet into non - volatile memory .
/* Declare the write operation parameters */ /*
	 * Expected:
	 * [IN]  params[0].value.a    -> Address to write the current wallet record.
	 */ /*
	 * Write parameters:
	 * [IN]  params[0].memref.buffer -> Buffer with data to write in the storage.
	 * [IN]  params[0].memref.size   -> Size of the buffer to be wrote.
	 * [IN]  params[1].value.a       -> Starting address of the writing.
	 * [OUT] params[1].value.b       -> NonVolatileReturn error.
	 */ /* Check the received parameter types */ /* Verify if the storage was already opened */ /* Define the write operation parameters */ /* Write the current wallet (unencrypted section )in the wallet storage */ /* Write the current wallet (encrypted section )in the wallet storage */ /* Flush the write cache */ /* Resource cleanup */