trusty: keymint: Add commandline option to specify device name
Bug: 300338484
Test: VtsAidlKeyMintTargetTest (emulator subset)
Change-Id: Ibaa89dd0a3db65565101c0a37303c7155f999fb7
diff --git a/trusty/keymint/Android.bp b/trusty/keymint/Android.bp
index 19dcc98..92d9c6f 100644
--- a/trusty/keymint/Android.bp
+++ b/trusty/keymint/Android.bp
@@ -24,11 +24,12 @@
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",
diff --git a/trusty/keymint/src/keymint_hal_main.rs b/trusty/keymint/src/keymint_hal_main.rs
index ef0c598..3c5627b 100644
--- a/trusty/keymint/src/keymint_hal_main.rs
+++ b/trusty/keymint/src/keymint_hal_main.rs
@@ -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 @@
}
}
+#[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 inner_main() -> Result<(), HalServiceError> {
+ let args = Args::parse();
// Initialize Android logging.
android_logger::init_once(
android_logger::Config::default()
@@ -106,10 +115,15 @@
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