ta/wallet_ta.c
/**
  * Flushes the buffered data into the wallet storage.
  * \param session_data A data pointer to a session context.
  * \param nv_error NonVolatile error.
  * \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.
  */
Flushes the buffered data into the wallet storage.
\param session_data A data pointer to a session context.
Flushes the buffered data into the wallet storage . \ param session_data A data pointer to a session context .
static TEE_Result flush_wallet_storage_internal(Session_data * session_data, NonVolatileReturn * nv_error)
{
	TEE_Result result = TEE_SUCCESS;
	*nv_error = NV_NO_ERROR;
	if (session_data->is_storage_created == false
		|| session_data->is_storage_open == false)
	{
		result = TEE_ERROR_BAD_STATE;
		*nv_error = NV_IO_ERROR;
		goto cleanup1;
	}
	if (session_data->write_cache_valid)
	{
		if ((session_data->write_cache_tag) >= NV_MEMORY_SIZE)
		{
			result = TEE_ERROR_BAD_STATE;
			*nv_error = NV_INVALID_ADDRESS;
			goto cleanup1;
		}
		result = write_wallet_storage_internal(
						session_data,
						(uint8_t*)(session_data->write_cache),
						(size_t)SECTOR_SIZE,
						session_data->write_cache_tag);
		if (result != TEE_SUCCESS)
		{
			#ifdef OP_TEE_TA
	    	DMSG("Failed to write in the wallet storage: 0x%x", result);
	    	#endif
	    	*nv_error = NV_IO_ERROR;
	    	goto cleanup1;
	    }
		session_data->write_cache_valid = false;
		session_data->write_cache_tag = 0;
		TEE_MemFill(session_data->write_cache, 0, (uint32_t)SECTOR_SIZE);
	}
	cleanup1:
		return result;
}
static TEE_Result flush_wallet_storage_internal ( Session_data * session_data , NonVolatileReturn * nv_error ) { TEE_Result result = TEE_SUCCESS ; * nv_error = NV_NO_ERROR ; if ( session_data -> is_storage_created == false || session_data -> is_storage_open == false ) { result = TEE_ERROR_BAD_STATE ; * nv_error = NV_IO_ERROR ; goto cleanup1 ; } if ( session_data -> write_cache_valid ) { if ( ( session_data -> write_cache_tag ) >= NV_MEMORY_SIZE ) { result = TEE_ERROR_BAD_STATE ; * nv_error = NV_INVALID_ADDRESS ; goto cleanup1 ; } result = write_wallet_storage_internal ( session_data , ( uint8_t * ) ( session_data -> write_cache ) , ( size_t ) SECTOR_SIZE , session_data -> write_cache_tag ) ; if ( result != TEE_SUCCESS ) { #ifdef OP_TEE_TA DMSG ( " " , result ) ; #endif * nv_error = NV_IO_ERROR ; goto cleanup1 ; } session_data -> write_cache_valid = false ; session_data -> write_cache_tag = 0 ; TEE_MemFill ( session_data -> write_cache , 0 , ( uint32_t ) SECTOR_SIZE ) ; } cleanup1 : return result ; }
Flushes the buffered data into the wallet storage.
Flushes the buffered data into the wallet storage .
/* Check if the storage was already created and opened */ /* If the data in the write cache is valid */ /* Sanity check */ /* Write the write-cache into the wallet storage */ /* Invalid the write cache */ /* Reset the content to zeros */ /* Resources cleanup */