1 //
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 //! KeyMint TA core for Cuttlefish.
17
18 extern crate alloc;
19
20 use kmr_wire::keymint::SecurityLevel;
21 use libc::c_int;
22 use log::error;
23
24 /// FFI wrapper around [`kmr_cf::ta_main`].
25 #[no_mangle]
kmr_ta_main( fd_in: c_int, fd_out: c_int, security_level: c_int, trm: *mut libc::c_void, )26 pub extern "C" fn kmr_ta_main(
27 fd_in: c_int,
28 fd_out: c_int,
29 security_level: c_int,
30 trm: *mut libc::c_void,
31 ) {
32 let security_level = match security_level {
33 x if x == SecurityLevel::TrustedEnvironment as i32 => SecurityLevel::TrustedEnvironment,
34 x if x == SecurityLevel::Strongbox as i32 => SecurityLevel::Strongbox,
35 x if x == SecurityLevel::Software as i32 => SecurityLevel::Software,
36 _ => {
37 error!("unexpected security level {}, running as SOFTWARE", security_level);
38 SecurityLevel::Software
39 }
40 };
41 kmr_cf::ta_main(fd_in, fd_out, security_level, trm)
42 }
43