blob: 46346bb3e9973f75bfe306b1fdb2f6ee46ae44c6 [file] [log] [blame]
Andrei Homescu74a54452021-12-10 05:30:21 +00001/*
2 * Copyright (C) 2022 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Ayrton Munoz04137372022-08-03 17:05:09 -040017#if defined(TRUSTY_USERSPACE)
Andrei Homescu74a54452021-12-10 05:30:21 +000018#include <openssl/rand.h>
Ayrton Munoz04137372022-08-03 17:05:09 -040019#else
20#include <lib/rand/rand.h>
21#endif
Andrei Homescu74a54452021-12-10 05:30:21 +000022
Andrei Homescu024727b2022-08-24 23:54:59 +000023#include <binder/RpcTransportTipcTrusty.h>
24
Andrei Homescu74a54452021-12-10 05:30:21 +000025#include "../OS.h"
26
27using android::base::Result;
28
29namespace android {
30
Andrei Homescu875996f2022-08-24 04:25:11 +000031Result<void> setNonBlocking(android::base::borrowed_fd /*fd*/) {
Andrei Homescu74a54452021-12-10 05:30:21 +000032 // Trusty IPC syscalls are all non-blocking by default.
33 return {};
34}
35
36status_t getRandomBytes(uint8_t* data, size_t size) {
Ayrton Munoz04137372022-08-03 17:05:09 -040037#if defined(TRUSTY_USERSPACE)
Andrei Homescu74a54452021-12-10 05:30:21 +000038 int res = RAND_bytes(data, size);
39 return res == 1 ? OK : UNKNOWN_ERROR;
Ayrton Munoz04137372022-08-03 17:05:09 -040040#else
41 int res = rand_get_bytes(data, size);
42 return res == 0 ? OK : UNKNOWN_ERROR;
43#endif // TRUSTY_USERSPACE
Andrei Homescu74a54452021-12-10 05:30:21 +000044}
45
Andrei Homescu875996f2022-08-24 04:25:11 +000046status_t dupFileDescriptor(int /*oldFd*/, int* /*newFd*/) {
Andrei Homescu24ad36e2022-08-04 01:33:33 +000047 // TODO: implement separately
48 return INVALID_OPERATION;
49}
50
Andrei Homescu024727b2022-08-24 23:54:59 +000051std::unique_ptr<RpcTransportCtxFactory> makeDefaultRpcTransportCtxFactory() {
52 return RpcTransportCtxFactoryTipcTrusty::make();
53}
54
Andrei Homescu74a54452021-12-10 05:30:21 +000055} // namespace android