1 /*
2 * Copyright (c) 2020-2022, Arm Limited and Contributors. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7 #include "linuxffa_location_strategy.h"
8 #include "linuxffa_service_context.h"
9 #include "common/uuid/uuid.h"
10 #include "service/locator/service_name.h"
11 #include "components/service/attestation/provider/attestation_uuid.h"
12 #include "components/service/block_storage/provider/block_storage_uuid.h"
13 #include "components/service/crypto/provider/crypto_uuid.h"
14 #include "components/service/fwu/provider/fwu_uuid.h"
15 #include "components/service/rpmb/provider/rpmb_uuid.h"
16 #include "components/service/secure_storage/frontend/secure_storage_provider/secure_storage_uuid.h"
17 #include "components/service/test_runner/provider/test_runner_uuid.h"
18 #include <stddef.h>
19 #include <string.h>
20 #include <stdbool.h>
21 #include <stdint.h>
22
23
24 static struct service_context *query(const char *sn);
25 static const struct rpc_uuid *suggest_ts_service_uuids(const char *sn);
26
linux_ts_location_strategy(void)27 const struct service_location_strategy *linux_ts_location_strategy(void)
28 {
29 static const struct service_location_strategy strategy = { query };
30 return &strategy;
31 }
32
query(const char * sn)33 static struct service_context *query(const char *sn)
34 {
35 const struct rpc_uuid *service_uuid = NULL;
36
37 /* Determine one or more candidate partition UUIDs from the specified service name. */
38 if (!sn_check_authority(sn, "trustedfirmware.org"))
39 return NULL;
40
41 service_uuid = suggest_ts_service_uuids(sn);
42 if (!service_uuid)
43 return NULL;
44
45 return (struct service_context *)linux_ts_service_context_create(service_uuid);
46 }
47
48 /*
49 * Returns a list of service UUIDs to identify partitions that could potentially host the requested
50 * service. This mapping is based trustedfirmware.org service UUIDs. There may be multiple UUIDs
51 * because of different deployment decisions such as dedicated SP, SP hosting multiple services.
52 */
suggest_ts_service_uuids(const char * sn)53 static const struct rpc_uuid *suggest_ts_service_uuids(const char *sn)
54 {
55 static const struct service_to_uuid
56 {
57 const char *service;
58 struct rpc_uuid uuid;
59 }
60 partition_lookup[] =
61 {
62 {"crypto-protobuf", {.uuid = TS_PSA_CRYPTO_PROTOBUF_SERVICE_UUID}},
63 {"crypto", {.uuid = TS_PSA_CRYPTO_SERVICE_UUID}},
64 {"internal-trusted-storage", {.uuid = TS_PSA_INTERNAL_TRUSTED_STORAGE_UUID}},
65 {"protected-storage", {.uuid = TS_PSA_PROTECTED_STORAGE_UUID}},
66 {"test-runner", {.uuid = TS_TEST_RUNNER_SERVICE_UUID}},
67 {"attestation", {.uuid = TS_PSA_ATTESTATION_SERVICE_UUID}},
68 {"block-storage", {.uuid = TS_BLOCK_STORAGE_SERVICE_UUID}},
69 {"fwu", {.uuid = TS_FWU_SERVICE_UUID}},
70 {"rpmb", {.uuid = TS_RPMB_SERVICE_UUID}},
71 {NULL, {.uuid = {0}}}
72 };
73
74 const struct service_to_uuid *entry = NULL;
75
76 for (entry = &partition_lookup[0]; entry->service != NULL; entry++)
77 if (sn_check_service(sn, entry->service))
78 return &entry->uuid;
79
80 return NULL;
81 }
82