trusty: keymint: Add commandline option to specify device name

Bug: 300338484
Test: VtsAidlKeyMintTargetTest (emulator subset)
Change-Id: Ibaa89dd0a3db65565101c0a37303c7155f999fb7
This commit is contained in:
Arve Hjønnevåg 2023-09-13 18:20:38 -07:00 committed by Alice Wang
parent 31154a9e60
commit b4158e2599
2 changed files with 20 additions and 5 deletions

View file

@ -24,11 +24,12 @@ rust_binary {
init_rc: ["android.hardware.security.keymint-service.rust.trusty.rc"],
vintf_fragments: ["android.hardware.security.keymint-service.rust.trusty.xml"],
srcs: [
"src/keymint_hal_main.rs"
"src/keymint_hal_main.rs",
],
rustlibs: [
"libandroid_logger",
"libbinder_rs",
"libclap",
"libkmr_wire",
"libkmr_hal",
"libtrusty-rs",

View file

@ -14,6 +14,7 @@
// limitations under the License.
//! This module implements the HAL service for Keymint (Rust) in Trusty.
use clap::Parser;
use kmr_hal::{
extract_rsp, keymint, rpc, secureclock, send_hal_info, sharedsecret, SerializedChannel,
};
@ -81,6 +82,13 @@ impl SerializedChannel for TipcChannel {
}
}
#[derive(Parser, Debug)]
struct Args {
/// Tipc device path
#[arg(short, long, default_value_t = DEFAULT_DEVICE.to_string())]
dev: String,
}
fn main() {
if let Err(HalServiceError(e)) = inner_main() {
panic!("HAL service failed: {:?}", e);
@ -88,6 +96,7 @@ fn main() {
}
fn inner_main() -> Result<(), HalServiceError> {
let args = Args::parse();
// Initialize Android logging.
android_logger::init_once(
android_logger::Config::default()
@ -106,10 +115,15 @@ fn inner_main() -> Result<(), HalServiceError> {
binder::ProcessState::start_thread_pool();
// Create connection to the TA
let connection = trusty::TipcChannel::connect(DEFAULT_DEVICE, TRUSTY_KEYMINT_RUST_SERVICE_NAME)
.map_err(|e| {
HalServiceError(format!("Failed to connect to Trusty Keymint TA because of {:?}.", e))
})?;
let connection =
trusty::TipcChannel::connect(args.dev.as_str(), TRUSTY_KEYMINT_RUST_SERVICE_NAME).map_err(
|e| {
HalServiceError(format!(
"Failed to connect to Trusty Keymint TA at {} because of {:?}.",
args.dev, e
))
},
)?;
let tipc_channel = Arc::new(Mutex::new(TipcChannel(connection)));
// Register the Keymint service