1 // SPDX-License-Identifier: BSD-2-Clause
2 /*
3  * Copyright (c) 2018, Linaro Limited
4  */
5 
6 #include <tee_internal_api.h>
7 
8 #include "seed_rng_taf.h"
9 
seed_rng_pool(uint32_t param_types,TEE_Param params[4])10 TEE_Result seed_rng_pool(uint32_t param_types, TEE_Param params[4])
11 {
12 	static const TEE_UUID system_uuid = PTA_SYSTEM_UUID;
13 	TEE_TASessionHandle sess = TEE_HANDLE_NULL;
14 	TEE_Result res = TEE_ERROR_GENERIC;
15 	uint32_t ret_orig = 0;
16 
17 	if (param_types !=
18 	    TEE_PARAM_TYPES(TEE_PARAM_TYPE_MEMREF_INPUT,
19 			    TEE_PARAM_TYPE_NONE,
20 			    TEE_PARAM_TYPE_NONE,
21 			    TEE_PARAM_TYPE_NONE)) {
22 		return TEE_ERROR_BAD_PARAMETERS;
23 	}
24 
25 	if (!params[0].memref.size)
26 		return TEE_ERROR_BAD_PARAMETERS;
27 
28 	res = TEE_OpenTASession(&system_uuid, TEE_TIMEOUT_INFINITE, 0, NULL,
29 				&sess, &ret_orig);
30 	if (res != TEE_SUCCESS) {
31 		EMSG("TEE_OpenTASession failed");
32 		goto cleanup_return;
33 	}
34 
35 	res = TEE_InvokeTACommand(sess, TEE_TIMEOUT_INFINITE,
36 				  PTA_SYSTEM_ADD_RNG_ENTROPY,
37 				  param_types, params, &ret_orig);
38 	if (res != TEE_SUCCESS) {
39 		EMSG("TEE_InvokeTACommand failed");
40 		goto cleanup_return;
41 	}
42 
43 cleanup_return:
44 	TEE_CloseTASession(sess);
45 	return res;
46 }
47