ta/wallet_ta.c
/**
  * Called when a new session is opened to the TA. *sess_ctx can be updated
  * with a value to be able to identify this session in subsequent calls to the
  * TA. If this returns an error the connection is rejected and no new session
  * is opened.
  * \param param_types The types of the four parameters.
  * \params A pointer to an array of four parameters.
  * \sess_ctx A pointer to a variable with session context information.
  * \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.
  */
Called when a new session is opened to the TA. *sess_ctx can be updated
with a value to be able to identify this session in subsequent calls to the
TA. If this returns an error the connection is rejected and no new session
is opened.
\param param_types The types of the four parameters.
\params A pointer to an array of four parameters.
\sess_ctx A pointer to a variable with session context information.
\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.
Called when a new session is opened to the TA . * sess_ctx can be updated with a value to be able to identify this session in subsequent calls to the TA . If this returns an error the connection is rejected and no new session is opened . \ param param_types The types of the four parameters . \ params A pointer to an array of four parameters . \ sess_ctx A pointer to a variable with session context information . \ 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 .
TEE_Result TA_OpenSessionEntryPoint(uint32_t param_types, TEE_Param  params[4], void **sess_ctx)
{
	Session_data * data;
	uint32_t exp_param_types = TEE_PARAM_TYPES(
									TEE_PARAM_TYPE_NONE,
								   	TEE_PARAM_TYPE_NONE,
								   	TEE_PARAM_TYPE_NONE,
								   	TEE_PARAM_TYPE_NONE);
	if (param_types != exp_param_types)
		return TEE_ERROR_BAD_PARAMETERS;
	(void)&params;
	data = TEE_Malloc(sizeof(Session_data), TEE_MALLOC_FILL_ZERO);
	if (data == NULL)
		return TEE_ERROR_OUT_OF_MEMORY;
	data->wallet_handle = TEE_Malloc(sizeof(TEE_ObjectHandle),
										TEE_MALLOC_FILL_ZERO);
	data->storageID = TEE_Malloc(STORAGE_ID_LENGTH*sizeof(char),
									TEE_MALLOC_FILL_ZERO);
	data->write_cache = TEE_Malloc(SECTOR_SIZE*sizeof(uint8_t),
								  	TEE_MALLOC_FILL_ZERO);
	data->aes_encrypt_op = TEE_Malloc(sizeof(TEE_OperationHandle),
									 	TEE_MALLOC_FILL_ZERO);
	data->aes_decrypt_op = TEE_Malloc(sizeof(TEE_OperationHandle),
									 	TEE_MALLOC_FILL_ZERO);
	data->hmac_op1_internal = TEE_Malloc(sizeof(TEE_OperationHandle),
							 	TEE_MALLOC_FILL_ZERO);
	data->hmac_op2_internal = TEE_Malloc(sizeof(TEE_OperationHandle),
								TEE_MALLOC_FILL_ZERO);
	data->hmac_op1 = TEE_Malloc(sizeof(TEE_OperationHandle),
							 	TEE_MALLOC_FILL_ZERO);
	data->hmac_op2 = TEE_Malloc(sizeof(TEE_OperationHandle),
								TEE_MALLOC_FILL_ZERO);
	data->sha_op_internal = TEE_Malloc(sizeof(TEE_OperationHandle),
							  	TEE_MALLOC_FILL_ZERO);
	data->sha_op1 = TEE_Malloc(sizeof(TEE_OperationHandle),
							  	TEE_MALLOC_FILL_ZERO);
	data->sha_op2 = TEE_Malloc(sizeof(TEE_OperationHandle),
								TEE_MALLOC_FILL_ZERO);
	data->sha_op3 = TEE_Malloc(sizeof(TEE_OperationHandle),
								TEE_MALLOC_FILL_ZERO);
	data->sha_op4 = TEE_Malloc(sizeof(TEE_OperationHandle),
								TEE_MALLOC_FILL_ZERO);
	data->current_wallet = TEE_Malloc(sizeof(WalletRecord),
										TEE_MALLOC_FILL_ZERO);
	if (data == NULL
		|| data->wallet_handle == NULL
		|| data->storageID == NULL
		|| data->write_cache == NULL
		|| data->aes_encrypt_op == NULL
		|| data->aes_decrypt_op == NULL
		|| data->hmac_op1_internal == NULL
		|| data->hmac_op2_internal == NULL
		|| data->hmac_op1 == NULL
		|| data->hmac_op2 == NULL
		|| data->sha_op_internal == NULL
		|| data->sha_op1 == NULL
		|| data->sha_op2 == NULL
		|| data->sha_op3 == NULL
		|| data->sha_op4 == NULL
		|| data->current_wallet == NULL)
		return TEE_ERROR_OUT_OF_MEMORY;
	data->storageIDLen = 0;
	data->write_cache_tag = 0;
	data->wallet_nv_address = 0;
	data->is_storage_created = false;
	data->is_storage_open = false;
	data->write_cache_valid = false;
	data->is_encryption_key_non_zero = false;
	data->wallet_loaded = false;
	data->is_hidden_wallet = false;
	*sess_ctx = data;
	#ifdef OP_TEE_TA
	DMSG("Has been called (session opened with the TA)");
	#endif
	return TEE_SUCCESS;
}
TEE_Result TA_OpenSessionEntryPoint ( uint32_t param_types , TEE_Param params [ 4 ] , void * * sess_ctx ) { Session_data * data ; uint32_t exp_param_types = TEE_PARAM_TYPES ( TEE_PARAM_TYPE_NONE , TEE_PARAM_TYPE_NONE , TEE_PARAM_TYPE_NONE , TEE_PARAM_TYPE_NONE ) ; if ( param_types != exp_param_types ) return TEE_ERROR_BAD_PARAMETERS ; ( void ) & params ; data = TEE_Malloc ( sizeof ( Session_data ) , TEE_MALLOC_FILL_ZERO ) ; if ( data == NULL ) return TEE_ERROR_OUT_OF_MEMORY ; data -> wallet_handle = TEE_Malloc ( sizeof ( TEE_ObjectHandle ) , TEE_MALLOC_FILL_ZERO ) ; data -> storageID = TEE_Malloc ( STORAGE_ID_LENGTH * sizeof ( char ) , TEE_MALLOC_FILL_ZERO ) ; data -> write_cache = TEE_Malloc ( SECTOR_SIZE * sizeof ( uint8_t ) , TEE_MALLOC_FILL_ZERO ) ; data -> aes_encrypt_op = TEE_Malloc ( sizeof ( TEE_OperationHandle ) , TEE_MALLOC_FILL_ZERO ) ; data -> aes_decrypt_op = TEE_Malloc ( sizeof ( TEE_OperationHandle ) , TEE_MALLOC_FILL_ZERO ) ; data -> hmac_op1_internal = TEE_Malloc ( sizeof ( TEE_OperationHandle ) , TEE_MALLOC_FILL_ZERO ) ; data -> hmac_op2_internal = TEE_Malloc ( sizeof ( TEE_OperationHandle ) , TEE_MALLOC_FILL_ZERO ) ; data -> hmac_op1 = TEE_Malloc ( sizeof ( TEE_OperationHandle ) , TEE_MALLOC_FILL_ZERO ) ; data -> hmac_op2 = TEE_Malloc ( sizeof ( TEE_OperationHandle ) , TEE_MALLOC_FILL_ZERO ) ; data -> sha_op_internal = TEE_Malloc ( sizeof ( TEE_OperationHandle ) , TEE_MALLOC_FILL_ZERO ) ; data -> sha_op1 = TEE_Malloc ( sizeof ( TEE_OperationHandle ) , TEE_MALLOC_FILL_ZERO ) ; data -> sha_op2 = TEE_Malloc ( sizeof ( TEE_OperationHandle ) , TEE_MALLOC_FILL_ZERO ) ; data -> sha_op3 = TEE_Malloc ( sizeof ( TEE_OperationHandle ) , TEE_MALLOC_FILL_ZERO ) ; data -> sha_op4 = TEE_Malloc ( sizeof ( TEE_OperationHandle ) , TEE_MALLOC_FILL_ZERO ) ; data -> current_wallet = TEE_Malloc ( sizeof ( WalletRecord ) , TEE_MALLOC_FILL_ZERO ) ; if ( data == NULL || data -> wallet_handle == NULL || data -> storageID == NULL || data -> write_cache == NULL || data -> aes_encrypt_op == NULL || data -> aes_decrypt_op == NULL || data -> hmac_op1_internal == NULL || data -> hmac_op2_internal == NULL || data -> hmac_op1 == NULL || data -> hmac_op2 == NULL || data -> sha_op_internal == NULL || data -> sha_op1 == NULL || data -> sha_op2 == NULL || data -> sha_op3 == NULL || data -> sha_op4 == NULL || data -> current_wallet == NULL ) return TEE_ERROR_OUT_OF_MEMORY ; data -> storageIDLen = 0 ; data -> write_cache_tag = 0 ; data -> wallet_nv_address = 0 ; data -> is_storage_created = false ; data -> is_storage_open = false ; data -> write_cache_valid = false ; data -> is_encryption_key_non_zero = false ; data -> wallet_loaded = false ; data -> is_hidden_wallet = false ; * sess_ctx = data ; #ifdef OP_TEE_TA DMSG ( " " ) ; #endif return TEE_SUCCESS ; }
Called when a new session is opened to the TA.
Called when a new session is opened to the TA .
/* It is not expected any parameters */ /* Unused parameters */ /*
	 * Allocate memory and initialize the session context structure that
	 * will be used
	 */ /* Allocate memory for some of the 'data' parameters */ /* Verify if the memory was allocated */ /* Set to default values other variables of 'data'*/ /* Set 'data' as session context */ /*
	 * The DMSG() macro is non-standard, TEE Internal API doesn't
	 * specify any means to logging from a TA.
	 */ /* If return value != TEE_SUCCESS the session will not be created. */