ta/wallet_ta.c
/**
  * Creates the wallet storage by using the data stream from a persistent
  * object. It also truncates the data stream to #NV_MEMORY_SIZE.
  * \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.
  */
Creates the wallet storage by using the data stream from a persistent
object. It also truncates the data stream to #NV_MEMORY_SIZE.
\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.
Creates the wallet storage by using the data stream from a persistent object . It also truncates the data stream to #NV_MEMORY_SIZE . \ 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 create_wallet_storage(Session_data * session_data, uint32_t param_types, TEE_Param params[4])
{
	TEE_Result result = TEE_SUCCESS;
	uint32_t exp_param_types;
    uint32_t flags = TEE_DATA_FLAG_ACCESS_WRITE | TEE_DATA_FLAG_OVERWRITE;
	exp_param_types = TEE_PARAM_TYPES(
							TEE_PARAM_TYPE_MEMREF_INPUT,
							TEE_PARAM_TYPE_NONE,
							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
		|| session_data->is_storage_created == true)
		return TEE_ERROR_BAD_STATE;
	*(session_data->wallet_handle) = TEE_HANDLE_NULL;
	result = TEE_CreatePersistentObject(
				TEE_STORAGE_PRIVATE,
				params[0].memref.buffer,
				params[0].memref.size,
				flags,
				NULL,
				NULL,
				0,
				session_data->wallet_handle);
	if (result != TEE_SUCCESS)
	{
		#ifdef OP_TEE_TA
		DMSG("Failed to create a persistent object for wallet storage: 0x%x", result);
		#endif
		goto cleanup1;
	}
	TEE_MemMove((char*)(session_data->storageID),
				(char*)(params[0].memref.buffer),
				params[0].memref.size);
	session_data->storageIDLen = params[0].memref.size;
	result = TEE_TruncateObjectData(*(session_data->wallet_handle),
									NV_MEMORY_SIZE);
	if (result != TEE_SUCCESS)
	{
		#ifdef OP_TEE_TA
		DMSG("Failed to extend the wallet storage: 0x%x", result);
		#endif
		goto cleanup2;
	}
	session_data->is_storage_created = true;
	cleanup2:
		TEE_CloseObject(*(session_data->wallet_handle));
		*(session_data->wallet_handle) = TEE_HANDLE_NULL;
	cleanup1:
		return result;
}
static TEE_Result create_wallet_storage ( Session_data * session_data , uint32_t param_types , TEE_Param params [ 4 ] ) { TEE_Result result = TEE_SUCCESS ; uint32_t exp_param_types ; uint32_t flags = TEE_DATA_FLAG_ACCESS_WRITE | TEE_DATA_FLAG_OVERWRITE ; exp_param_types = TEE_PARAM_TYPES ( TEE_PARAM_TYPE_MEMREF_INPUT , TEE_PARAM_TYPE_NONE , 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 || session_data -> is_storage_created == true ) return TEE_ERROR_BAD_STATE ; * ( session_data -> wallet_handle ) = TEE_HANDLE_NULL ; result = TEE_CreatePersistentObject ( TEE_STORAGE_PRIVATE , params [ 0 ] . memref . buffer , params [ 0 ] . memref . size , flags , NULL , NULL , 0 , session_data -> wallet_handle ) ; if ( result != TEE_SUCCESS ) { #ifdef OP_TEE_TA DMSG ( " " , result ) ; #endif goto cleanup1 ; } TEE_MemMove ( ( char * ) ( session_data -> storageID ) , ( char * ) ( params [ 0 ] . memref . buffer ) , params [ 0 ] . memref . size ) ; session_data -> storageIDLen = params [ 0 ] . memref . size ; result = TEE_TruncateObjectData ( * ( session_data -> wallet_handle ) , NV_MEMORY_SIZE ) ; if ( result != TEE_SUCCESS ) { #ifdef OP_TEE_TA DMSG ( " " , result ) ; #endif goto cleanup2 ; } session_data -> is_storage_created = true ; cleanup2 : TEE_CloseObject ( * ( session_data -> wallet_handle ) ) ; * ( session_data -> wallet_handle ) = TEE_HANDLE_NULL ; cleanup1 : return result ; }
Creates the wallet storage by using the data stream from a persistent
 object.
Creates the wallet storage by using the data stream from a persistent object .
/*
	 * Expected:
	 * [IN] params[0].memref.buffer-> Name of the wallet storage id.
	 * [IN] params[0].memref.size  -> Size of the name of the wallet storage id.
	 */ /*
	 * Confirm the type of the receive parameters as well if the storageID
	 * sent is not NULL
	 */ /* Check if the storage was already open or created */ /* Set the wallet handle to null */ /*
	 * Create the persistent object that will be used as the wallet storage.
	 */ /* Copy the storageID to the session data structure */ /*
	 * When writing to a position beyond the stream's end, the date stream is
	 * first extended with bytes (zeros) until the length indicated by the data
	 * position indicator is reached, and then 'size' bytes are written to the
	 * stream.
	 * When reading past the end-of-stream, the function TEE_ReadObjectData
	 * stops reading data at the end-of-stream and returns the data read up to
	 * that point. If the position is at, or past, the end of the data when read
	 * function is called, then no bytes are read.
	 * So, because of the situations described above there is a necessity to
	 * increase the size of the data stream to the #NV_MEMORY_SIZE. This way
	 * is avoided wrong readings and a constant increase of size of the data
	 * stream.
	 */ /* Resources cleanup */ /*
		 * As the objective of this function is to only create the storage the
		 * handle is set to NULL
		 */