Ashutosh Singh | f4d8867 | 2017-11-29 13:35:43 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (c) 2017, Arm Limited. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | * |
| 6 | */ |
| 7 | |
| 8 | /* FIXME: this TFM ID manager is only a stub implementation. It is system |
| 9 | * integrators responsibility to define a way of identifying the app id and |
| 10 | * based on their non secure side of the threat model. The secure side only |
| 11 | * checks if this is an ID belonging to NS side entities. The secure side |
| 12 | * doesn't make any attempt to challenge the app id value, this is left for NS |
| 13 | * side privileged code to implement. |
| 14 | */ |
| 15 | |
| 16 | #include "tfm_id_mngr.h" |
| 17 | |
| 18 | #include <string.h> |
| 19 | #include "cmsis_os2.h" |
| 20 | |
| 21 | #define INVALID_APP_ID 0 |
| 22 | |
| 23 | /* FIXME: following two functions are meant to be internally |
| 24 | * available to RTX. The header file containing prototype of |
| 25 | * these functions has complex header inclusion which leads |
| 26 | * to compiler specific paths in CMSIS, which currently doesn't have |
| 27 | * clang variant. To simplify this, following functions are directly |
| 28 | * declared here (as opposed to header inclusion). After clear |
| 29 | * separation of S and NS builds this will require to be revisited |
| 30 | */ |
| 31 | extern osThreadId_t svcRtxThreadGetId(void); |
| 32 | extern const char *svcRtxThreadGetName(osThreadId_t thread_id); |
| 33 | |
| 34 | /* Translation table pair between OS threads and SST app IDs */ |
| 35 | struct thread_sst_appid_pair { |
| 36 | const char* t_name; /*!< Task/Thread name */ |
| 37 | uint32_t app_id; /*!< Application ID used in assets definition */ |
| 38 | }; |
| 39 | |
| 40 | static struct thread_sst_appid_pair sst_ns_policy_table[] = |
| 41 | { |
| 42 | {"Thread_A", 9}, |
| 43 | {"Thread_B", 10}, |
| 44 | {"Thread_C", 11}, |
| 45 | }; |
| 46 | |
| 47 | static const char* get_active_task_name(void) |
| 48 | { |
| 49 | const char* thread_name; |
| 50 | |
| 51 | thread_name = svcRtxThreadGetName(svcRtxThreadGetId()); |
| 52 | |
| 53 | return thread_name; |
| 54 | } |
| 55 | |
| 56 | uint32_t tfm_sst_get_cur_id(void) |
| 57 | { |
| 58 | uint32_t i; |
| 59 | static uint32_t sst_table_size = (sizeof(sst_ns_policy_table) / |
| 60 | sizeof(sst_ns_policy_table[0])); |
| 61 | const char* p_thread_name; |
| 62 | |
| 63 | p_thread_name = get_active_task_name(); |
| 64 | |
| 65 | for (i = 0; i < sst_table_size; i++) { |
| 66 | if (strcmp(sst_ns_policy_table[i].t_name, p_thread_name) == 0) { |
| 67 | return sst_ns_policy_table[i].app_id; |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | return INVALID_APP_ID; |
| 72 | } |