Igor Opaniuk | 06fe31c | 2017-08-07 02:37:51 +0300 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017, Linaro Limited |
| 3 | * All rights reserved. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions are met: |
| 7 | * |
| 8 | * 1. Redistributions of source code must retain the above copyright notice, |
| 9 | * this list of conditions and the following disclaimer. |
| 10 | * |
| 11 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
| 12 | * this list of conditions and the following disclaimer in the documentation |
| 13 | * and/or other materials provided with the distribution. |
| 14 | * |
| 15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 16 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 17 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 18 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
| 19 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 20 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 21 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 24 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 25 | * POSSIBILITY OF SUCH DAMAGE. |
| 26 | */ |
| 27 | |
Igor Opaniuk | 06fe31c | 2017-08-07 02:37:51 +0300 | [diff] [blame] | 28 | #include <tee_internal_api.h> |
| 29 | #include <tee_internal_api_extensions.h> |
| 30 | |
Etienne Carriere | d3cb276 | 2017-11-09 15:45:53 +0100 | [diff] [blame] | 31 | #include <random_ta.h> |
Igor Opaniuk | 06fe31c | 2017-08-07 02:37:51 +0300 | [diff] [blame] | 32 | |
| 33 | TEE_Result TA_CreateEntryPoint(void) |
| 34 | { |
| 35 | return TEE_SUCCESS; |
| 36 | } |
| 37 | |
| 38 | void TA_DestroyEntryPoint(void) |
| 39 | { |
| 40 | } |
| 41 | |
| 42 | TEE_Result TA_OpenSessionEntryPoint(uint32_t param_types, |
| 43 | TEE_Param __maybe_unused params[4], |
| 44 | void __maybe_unused **sess_ctx) |
| 45 | { |
| 46 | uint32_t exp_param_types = TEE_PARAM_TYPES(TEE_PARAM_TYPE_NONE, |
| 47 | TEE_PARAM_TYPE_NONE, |
| 48 | TEE_PARAM_TYPE_NONE, |
| 49 | TEE_PARAM_TYPE_NONE); |
| 50 | if (param_types != exp_param_types) |
| 51 | return TEE_ERROR_BAD_PARAMETERS; |
| 52 | |
| 53 | (void)¶ms; |
| 54 | (void)&sess_ctx; |
| 55 | |
| 56 | return TEE_SUCCESS; |
| 57 | } |
| 58 | |
| 59 | void TA_CloseSessionEntryPoint(void __maybe_unused *sess_ctx) |
| 60 | { |
| 61 | (void)&sess_ctx; |
| 62 | } |
| 63 | |
| 64 | static TEE_Result random_number_generate(uint32_t param_types, |
| 65 | TEE_Param params[4]) |
| 66 | { |
Etienne Carriere | d3cb276 | 2017-11-09 15:45:53 +0100 | [diff] [blame] | 67 | uint32_t exp_param_types = |
| 68 | TEE_PARAM_TYPES(TEE_PARAM_TYPE_MEMREF_OUTPUT, |
| 69 | TEE_PARAM_TYPE_NONE, |
| 70 | TEE_PARAM_TYPE_NONE, |
| 71 | TEE_PARAM_TYPE_NONE); |
Igor Opaniuk | 06fe31c | 2017-08-07 02:37:51 +0300 | [diff] [blame] | 72 | |
| 73 | DMSG("has been called"); |
| 74 | if (param_types != exp_param_types) |
| 75 | return TEE_ERROR_BAD_PARAMETERS; |
| 76 | |
| 77 | IMSG("Generating random data over %u bytes.", params[0].memref.size); |
| 78 | /* |
| 79 | * The TEE_GenerateRandom function is a part of TEE Internal Core API, |
| 80 | * which generates random data |
| 81 | * |
| 82 | * Parameters: |
| 83 | * @ randomBuffer : Reference to generated random data |
| 84 | * @ randomBufferLen : Byte length of requested random data |
| 85 | */ |
| 86 | TEE_GenerateRandom(params[0].memref.buffer, params[0].memref.size); |
| 87 | |
| 88 | return TEE_SUCCESS; |
| 89 | } |
| 90 | |
| 91 | TEE_Result TA_InvokeCommandEntryPoint(void __maybe_unused *sess_ctx, |
| 92 | uint32_t cmd_id, |
| 93 | uint32_t param_types, TEE_Param params[4]) |
| 94 | { |
| 95 | (void)&sess_ctx; |
| 96 | |
| 97 | switch (cmd_id) { |
Etienne Carriere | d3cb276 | 2017-11-09 15:45:53 +0100 | [diff] [blame] | 98 | case TA_RANDOM_CMD_GENERATE: |
Igor Opaniuk | 06fe31c | 2017-08-07 02:37:51 +0300 | [diff] [blame] | 99 | return random_number_generate(param_types, params); |
| 100 | default: |
| 101 | return TEE_ERROR_BAD_PARAMETERS; |
| 102 | } |
| 103 | } |