From 0842c888981efaf00d88b4f0466158e06f81f329 Mon Sep 17 00:00:00 2001 From: Kevin Zhang Date: Wed, 13 Jul 2022 12:27:04 -0700 Subject: Add big event struct Bug: 229644649 Test: Manual Change-Id: Idc75dda8c7cd8b3338df1328b0f376a21d99affa Signed-off-by: Kevin Zhang Reviewed-on: https://nugget-os-review.googlesource.com/c/host/generic/+/53304 Reviewed-by: Bill Richardson Presubmit-Verified-Together: TreeHugger Robot --- nugget/include/citadel_events.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/nugget/include/citadel_events.h b/nugget/include/citadel_events.h index 24babee..9b269d7 100644 --- a/nugget/include/citadel_events.h +++ b/nugget/include/citadel_events.h @@ -76,6 +76,14 @@ enum upgrade_state_def { UPGRADE_EN_FW_FAIL =2, }; +/* + * Big event header flags. + */ +enum hdr_flags { + HDR_FLAG_EMPTY_SLOT = 0, // Used to determine empty slot. + HDR_FLAG_OCCUPIED_SLOT = 1 // Used to indicate an occupied slot. +}; + /* Please do not change the size of this struct */ #define EVENT_RECORD_SIZE 64 struct event_record { @@ -120,6 +128,20 @@ struct event_record { static_assert(sizeof(struct event_record) == EVENT_RECORD_SIZE, "Muting the Immutable"); +struct big_event_record { + struct hdr { + /* Redundant w.r.t. to v1 event records */ + uint64_t reset_count; + uint64_t uptime_usecs; + uint32_t priority; + + uint8_t version; + uint8_t flags; + uint16_t length; + } hdr; + uint8_t data[384]; +} __packed; + #ifdef __cplusplus } #endif -- cgit v1.2.3 From c364f9a964a8c8c36e5187b1ac3cbbb5b8522119 Mon Sep 17 00:00:00 2001 From: Kevin Zhang Date: Tue, 12 Jul 2022 18:07:03 -0700 Subject: Added command support for fetching big events Bug: 229644649 Test: Manual Change-Id: I91d3100c94524d30de692e5c65bc24125d3901bb Signed-off-by: Kevin Zhang Reviewed-on: https://nugget-os-review.googlesource.com/c/host/generic/+/53305 Presubmit-Verified-Together: TreeHugger Robot Reviewed-by: Bill Richardson --- nugget/include/app_nugget.h | 10 ++++++++++ nugget/include/citadel_events.h | 12 +++++++----- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/nugget/include/app_nugget.h b/nugget/include/app_nugget.h index cd8bf33..1b1ffff 100644 --- a/nugget/include/app_nugget.h +++ b/nugget/include/app_nugget.h @@ -564,6 +564,16 @@ struct secure_channel_retry_count_persist_storage { * @param reply * @param reply_len 0 */ +#define NUGGET_PARAM_GET_BIG_EVENT_RECORD 0x001b +/* + * This retrieves one pending big_event_record (defined in citadel_events.h). + * If none are pending, it returns nothing. + * + * @param args + * @param arg_len 0 + * @param reply struct big_event_record + * @param reply_len sizeof struct big_event_record OR 0 + */ /****************************************************************************/ /* Test related commands */ diff --git a/nugget/include/citadel_events.h b/nugget/include/citadel_events.h index 9b269d7..3be579e 100644 --- a/nugget/include/citadel_events.h +++ b/nugget/include/citadel_events.h @@ -59,12 +59,14 @@ enum event_priority { * Add to the list, but NEVER change or delete existing entries. */ enum event_id { - EVENT_NONE = 0, // Unused ID, used as empty marker. - EVENT_ALERT = 1, // Globalsec alert fired. - EVENT_REBOOTED = 2, // Device rebooted. - EVENT_UPGRADED = 3, // Device has upgraded. - EVENT_ALERT_V2 = 4, // Globalsec Alertv2 fired + EVENT_NONE = 0, // Unused ID, used as empty marker. + EVENT_ALERT = 1, // Globalsec alert fired. + EVENT_REBOOTED = 2, // Device rebooted. + EVENT_UPGRADED = 3, // Device has upgraded. + EVENT_ALERT_V2 = 4, // Globalsec Alertv2 fired EVENT_SEC_CH_STATE = 5, // Update GSA-GSC secure channel state. + EVENT_V1_NO_SUPPORT = + 6 // Report a VXX event that can't fit in struct small_event_record. }; /* -- cgit v1.2.3 From 2688332510abf4616b7c3a3e6bd9083b317375fb Mon Sep 17 00:00:00 2001 From: Kevin Zhang Date: Fri, 19 Aug 2022 13:46:18 -0700 Subject: Rename record structs to report for clarity Bug: 243163572 Test: citadel_updater --dauntless --[big_]event Signed-off-by: Kevin Zhang Change-Id: I73fb2aad1289b607cc8101330c2b616a11733d55 Reviewed-on: https://nugget-os-review.googlesource.com/c/host/generic/+/53905 Presubmit-Verified: TreeHugger Robot Reviewed-by: Bill Richardson --- nugget/include/app_nugget.h | 16 ++++++++-------- nugget/include/citadel_events.h | 12 ++++++------ 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/nugget/include/app_nugget.h b/nugget/include/app_nugget.h index 1b1ffff..cbeac47 100644 --- a/nugget/include/app_nugget.h +++ b/nugget/include/app_nugget.h @@ -299,15 +299,15 @@ struct nugget_app_board_id { uint32_t inv; /* must equal ~type when setting */ } __packed; -#define NUGGET_PARAM_GET_EVENT_RECORD 0x0010 +#define NUGGET_PARAM_GET_EVENT_REPORT 0x0010 /* - * This retrieves one pending event_record (defined in citadel_events.h). + * This retrieves one pending event_report (defined in citadel_events.h). * If none are pending, it returns nothing. * * @param args * @param arg_len 0 - * @param reply struct event_record - * @param reply_len sizeof struct event_record OR 0 + * @param reply struct event_report + * @param reply_len sizeof struct event_report OR 0 */ #define NUGGET_PARAM_AP_IS_REBOOTING 0x0011 @@ -564,15 +564,15 @@ struct secure_channel_retry_count_persist_storage { * @param reply * @param reply_len 0 */ -#define NUGGET_PARAM_GET_BIG_EVENT_RECORD 0x001b +#define NUGGET_PARAM_GET_BIG_EVENT_REPORT 0x001b /* - * This retrieves one pending big_event_record (defined in citadel_events.h). + * This retrieves one pending big_event_report (defined in citadel_events.h). * If none are pending, it returns nothing. * * @param args * @param arg_len 0 - * @param reply struct big_event_record - * @param reply_len sizeof struct big_event_record OR 0 + * @param reply struct big_event_report + * @param reply_len sizeof struct big_event_report OR 0 */ /****************************************************************************/ diff --git a/nugget/include/citadel_events.h b/nugget/include/citadel_events.h index 3be579e..00780ad 100644 --- a/nugget/include/citadel_events.h +++ b/nugget/include/citadel_events.h @@ -31,7 +31,7 @@ extern "C" { * When Citadel needs to tell the AP something without waiting to be asked, the * process is as follows: * - * 1. Citadel adds an event_record to its internal queue, then asserts + * 1. Citadel adds an event_report to its internal queue, then asserts * the CTDL_AP_IRQ signal to notify the AP. * * 2. The AP (citadeld) requests pending events from Citadel until they've @@ -66,7 +66,7 @@ enum event_id { EVENT_ALERT_V2 = 4, // Globalsec Alertv2 fired EVENT_SEC_CH_STATE = 5, // Update GSA-GSC secure channel state. EVENT_V1_NO_SUPPORT = - 6 // Report a VXX event that can't fit in struct small_event_record. + 6 // Report a VXX event that can't fit in struct event_report. }; /* @@ -87,8 +87,8 @@ enum hdr_flags { }; /* Please do not change the size of this struct */ -#define EVENT_RECORD_SIZE 64 -struct event_record { +#define EVENT_REPORT_SIZE 64 +struct event_report { uint64_t reset_count; /* zeroed by Citadel power cycle */ uint64_t uptime_usecs; /* since last Citadel reset */ uint32_t id; @@ -127,10 +127,10 @@ struct event_record { } event; } __packed; /* Please do not change the size of this struct */ -static_assert(sizeof(struct event_record) == EVENT_RECORD_SIZE, +static_assert(sizeof(struct event_report) == EVENT_REPORT_SIZE, "Muting the Immutable"); -struct big_event_record { +struct big_event_report { struct hdr { /* Redundant w.r.t. to v1 event records */ uint64_t reset_count; -- cgit v1.2.3 From 1f6753c69c908f06b37923046e920219b8fe604c Mon Sep 17 00:00:00 2001 From: Joseph Jang Date: Thu, 25 Aug 2022 19:22:48 +0800 Subject: identity: Add new item for ICstartRetrieveEntryValueResponse and fix naming problem in ICvalidateAccessControlProfileRequest 1. In order to make code more consistently, we add result code in ICstartRetrieveEntryValueResponse. 2. Fix ICvalidateAccessControlProfileRequest naming problem by using new item publicKeySize instead of publicKeysize. Bug: 243417943 Change-Id: I8a98d5b01f5fb707d17be5c35601f15427565b0d Reviewed-on: https://nugget-os-review.googlesource.com/c/host/generic/+/53984 Reviewed-by: Brian Murray Presubmit-Verified: TreeHugger Robot Tested-by: Joseph Jang --- nugget/proto/nugget/app/identity/identity.proto | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/nugget/proto/nugget/app/identity/identity.proto b/nugget/proto/nugget/app/identity/identity.proto index a29aa16..8532f6a 100644 --- a/nugget/proto/nugget/app/identity/identity.proto +++ b/nugget/proto/nugget/app/identity/identity.proto @@ -251,7 +251,7 @@ message ICvalidateAccessControlProfileRequest{ uint64 secureUserId = 5; bytes mac = 6; uint32 publicKeyOffset = 7; - uint32 publicKeysize = 8; + uint32 publicKeySize = 8; } message ICvalidateAccessControlProfileResponse{ @@ -297,6 +297,7 @@ message ICstartRetrieveEntryValueRequest{ message ICstartRetrieveEntryValueResponse{ AccessResult accessCheckResult = 1; uint32 sessionCookie = 2; + Result result = 3; } // ICretrieveEntryValue -- cgit v1.2.3 From 9117752a94349123b238d725188f5c0960bf3809 Mon Sep 17 00:00:00 2001 From: Joseph Jang Date: Wed, 27 Jul 2022 15:55:15 +0800 Subject: secure-transport: Report 1 byte final state back to GSA Bug: 228796951 Change-Id: Ia1a40f06646d425e59abeb074c66d053b0a97b07 Reviewed-on: https://nugget-os-review.googlesource.com/c/host/generic/+/53524 Reviewed-by: Bill Richardson Reviewed-by: Brian Murray Presubmit-Verified: TreeHugger Robot --- nugget/include/app_nugget.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nugget/include/app_nugget.h b/nugget/include/app_nugget.h index cbeac47..c5acfa7 100644 --- a/nugget/include/app_nugget.h +++ b/nugget/include/app_nugget.h @@ -562,7 +562,7 @@ struct secure_channel_retry_count_persist_storage { * @param args GSA noise handshake state * @param arg_len 1 * @param reply - * @param reply_len 0 + * @param reply_len 1 */ #define NUGGET_PARAM_GET_BIG_EVENT_REPORT 0x001b /* -- cgit v1.2.3 From ec528b515aef86e49895940f4905b1681d6ad9e9 Mon Sep 17 00:00:00 2001 From: Bill Richardson Date: Thu, 29 Sep 2022 11:22:03 -0500 Subject: Change STATUS_MAX_LENGTH to minimum needed This speeds up the polling while waiting for the command to finish. Bug: 249753364 Test: manual Change-Id: I7d5114421626548ac13480fa7e9e31cfa5b424b3 Signed-off-by: Bill Richardson Reviewed-on: https://nugget-os-review.googlesource.com/c/host/generic/+/54644 Presubmit-Verified: TreeHugger Robot Reviewed-by: Joel Voss Reviewed-by: Kevin Zhang --- libnos_transport/test/test.cpp | 2 +- nugget/include/application.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libnos_transport/test/test.cpp b/libnos_transport/test/test.cpp index 1090de4..c995c60 100644 --- a/libnos_transport/test/test.cpp +++ b/libnos_transport/test/test.cpp @@ -201,7 +201,7 @@ ACTION(ReadStatusV42_Working) { status->length = STATUS_MAX_LENGTH; status->version = 42; status->flags = STATUS_FLAG_WORKING; - status->crc = 0xaec0; + status->crc = 0xf781; status->reply_crc = 0; } diff --git a/nugget/include/application.h b/nugget/include/application.h index 1d485c6..2f897b6 100644 --- a/nugget/include/application.h +++ b/nugget/include/application.h @@ -239,7 +239,7 @@ struct transport_status { /* Valid range of lengths for the status message */ #define STATUS_MIN_LENGTH 0x10 -#define STATUS_MAX_LENGTH 0xff +#define STATUS_MAX_LENGTH (sizeof(struct transport_status)) /* 0x10 */ /* Flags used in the status message */ #define STATUS_FLAG_WORKING 0x0001 /* added in v1 */ -- cgit v1.2.3 From bdb092025e6f34d47650cf283a4be8c20478707e Mon Sep 17 00:00:00 2001 From: Tommy Chiu Date: Wed, 12 Oct 2022 16:36:15 +0800 Subject: Nugget: Add NUGGET_PARAM_GET_FEATURE_SUPPORT support To query feature supportness from each TAs Bug: 243819056 Test: citadel_updater --is_feature_support 0x04000004 Change-Id: I30edb895f00beded45e9d8d9e7b6a3b07db069f7 Reviewed-on: https://nugget-os-review.googlesource.com/c/host/generic/+/54805 Reviewed-by: Kevin Zhang Reviewed-by: Bill Richardson Presubmit-Verified: TreeHugger Robot Reviewed-by: Brian Murray --- nugget/include/app_nugget.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/nugget/include/app_nugget.h b/nugget/include/app_nugget.h index c5acfa7..53a594f 100644 --- a/nugget/include/app_nugget.h +++ b/nugget/include/app_nugget.h @@ -564,6 +564,7 @@ struct secure_channel_retry_count_persist_storage { * @param reply * @param reply_len 1 */ + #define NUGGET_PARAM_GET_BIG_EVENT_REPORT 0x001b /* * This retrieves one pending big_event_report (defined in citadel_events.h). @@ -575,6 +576,17 @@ struct secure_channel_retry_count_persist_storage { * @param reply_len sizeof struct big_event_report OR 0 */ +#define NUGGET_PARAM_GET_FEATURE_SUPPORT 0x001c +/* + * Get the specific feature supportness from the specific TA. + * + * @param args feature_id + * @param arg_len 4 byte + * @param reply 0 or 1 + * @param reply_len 1 byte + * + * @errors APP_ERROR_BOGUS_ARGS + */ /****************************************************************************/ /* Test related commands */ -- cgit v1.2.3 From 603b0549de66275f118d10da22c0ab8626ea875d Mon Sep 17 00:00:00 2001 From: Tommy Chiu Date: Wed, 9 Nov 2022 12:07:48 +0800 Subject: feature-map: Publish the feature list definition Move the feature list definition to a public accessable path host/generic/nugget/include/ Bug: 243819056 Test: Build pass Change-Id: I0325f0c23d5d9548aa76ca169c55da948b9d9f8e Reviewed-on: https://nugget-os-review.googlesource.com/c/host/generic/+/55405 Tested-by: Tommy Chiu Reviewed-by: Bill Richardson Presubmit-Verified: TreeHugger Robot --- nugget/include/feature_map.h | 63 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 nugget/include/feature_map.h diff --git a/nugget/include/feature_map.h b/nugget/include/feature_map.h new file mode 100644 index 0000000..b9875f1 --- /dev/null +++ b/nugget/include/feature_map.h @@ -0,0 +1,63 @@ +/** + * \file + * Feature ID format and inline decode functions + */ + +#pragma once + +#ifndef __ASSEMBLER__ + +/*****************************************************************************/ + +#define TA_MASK 0xFF000000 +#define TA_OFFSET 24 +#define TA_FIELD 8 // Max 256 TAs + +#define FEATURE_MASK 0x00FFFFFF +#define FEATURE_OFFSET 0 +#define FEATURE_FIELD 24 // Can support up to 2^24 features + +#define TA_FROM_FEATURE_ID(id) \ + ((enum feature_support_app_id)((id & TA_MASK) >> TA_OFFSET)) +#define MODULE_FROM_FEATURE_ID(id) ((id & FEATURE_MASK) >> FEATURE_OFFSET) +/*****************************************************************************/ + +enum feature_support_app_id { + feature_id_avb = 0, + feature_id_gfa, + feature_id_identity, + feature_id_keymint, + feature_id_nugget, + feature_id_weaver, + feature_id_count, + feature_id_max = 0xff, // For 8-bit alignment +}; + +enum km_feature_list { + km_feature_individual_attest, + km_feature_batch_attest, + km_feature_gnubby_attest, + km_feature_rkp, + km_feature_rkp_dice, + km_feature_dice, + km_feature_max = FEATURE_MASK, // For 24-bit alignment +}; + +/*****************************************************************************/ + +/** + * Query the feature supporting status based on task_id and module_id. + * + * @param id: APP_ID which is define in enum feature_support_app_id{} + * @param module_id: sub module list defined above + * @param is_supported: to output the supporting status. True = support. + * + * @return ERR_NONE, or error + * + * NOTE: "id" here is different from the TASK_ID_xxx (which is mutable) or + * APP_ID_xxx (which is out of hex range). + * Instead, we define a fixed order list which can be shared external. + * */ +__err_t is_feature_supported_by_task(enum feature_support_app_id id, + uint32_t module_id, bool *is_supported); +#endif /* !__ASSEMBLER__ */ -- cgit v1.2.3 From df7ffe6712cf649b1ac7300dbdfccfbfda92da8e Mon Sep 17 00:00:00 2001 From: Bill Richardson Date: Wed, 26 Oct 2022 13:24:36 -0500 Subject: Print App number as hex, not decimal Bug: None Test: manual Signed-off-by: Bill Richardson Change-Id: I61f33f8a47bd0721e7ecf65f9ec4b0904530440e Reviewed-on: https://nugget-os-review.googlesource.com/c/host/generic/+/55444 Presubmit-Verified: Android Build Prod User Reviewed-by: Kevin Zhang --- libnos_transport/transport.c | 47 ++++++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/libnos_transport/transport.c b/libnos_transport/transport.c index 855b884..cda7099 100644 --- a/libnos_transport/transport.c +++ b/libnos_transport/transport.c @@ -191,7 +191,7 @@ static int get_status(const struct transport_context *ctx, /* Check the CRC, if it fails we will retry */ if (out->crc != our_crc) { - NLOGW("App %d status CRC mismatch: theirs=%04x ours=%04x", + NLOGW("App 0x%02x status CRC mismatch: theirs=%04x ours=%04x", ctx->app_id, out->crc, our_crc); continue; } @@ -227,8 +227,9 @@ static uint32_t make_ready(const struct transport_context *ctx) { NLOGE("Failed to inspect app %d", ctx->app_id); return APP_ERROR_IO; } - NLOGD("App %d inspection status=0x%08x reply_len=%d protocol=%d flags=0x%04x", - ctx->app_id, status.status, status.reply_len, status.version, status.flags); + NLOGD("App 0x%02x check status=0x%08x reply_len=%d protocol=%d flags=0x%04x", + ctx->app_id, status.status, status.reply_len, status.version, + status.flags); /* If it's already idle then we're ready to proceed */ if (status.status == APP_STATUS_IDLE) { @@ -236,7 +237,7 @@ static uint32_t make_ready(const struct transport_context *ctx) { && (status.flags & STATUS_FLAG_WORKING)) { /* The app is still working when we don't expect it to be. We won't be * able to clear the state so might need to force a reset to recover. */ - NLOGE("App %d is still working", ctx->app_id); + NLOGE("App 0x%02x is still working", ctx->app_id); return APP_ERROR_BUSY; } return APP_SUCCESS; @@ -259,7 +260,7 @@ static uint32_t make_ready(const struct transport_context *ctx) { /* It's ignoring us and is still not ready, so it's broken */ if (status.status != APP_STATUS_IDLE) { - NLOGE("App %d is not responding", ctx->app_id); + NLOGE("App 0x%02x is not responding", ctx->app_id); return APP_ERROR_IO; } @@ -369,17 +370,20 @@ static uint32_t poll_until_done(const struct transport_context *ctx, poll_count++; /* Log at higher priority every 16 polls */ if ((poll_count & (16 - 1)) == 0) { - NLOGD("App %d poll=%d status=0x%08x reply_len=%d flags=0x%04x", - ctx->app_id, poll_count, status->status, status->reply_len, status->flags); + NLOGD("App 0x%02x poll=%d status=0x%08x reply_len=%d flags=0x%04x", + ctx->app_id, poll_count, status->status, status->reply_len, + status->flags); } else { - NLOGV("App %d poll=%d status=0x%08x reply_len=%d flags=0x%04x", - ctx->app_id, poll_count, status->status, status->reply_len, status->flags); + NLOGV("App 0x%02x poll=%d status=0x%08x reply_len=%d flags=0x%04x", + ctx->app_id, poll_count, status->status, status->reply_len, + status->flags); } /* Check whether the app is done */ if (status->status & APP_STATUS_DONE) { - NLOGD("App %d polled=%d status=0x%08x reply_len=%d flags=0x%04x", - ctx->app_id, poll_count, status->status, status->reply_len, status->flags); + NLOGD("App 0x%02x polled=%d status=0x%08x reply_len=%d flags=0x%04x", + ctx->app_id, poll_count, status->status, status->reply_len, + status->flags); return APP_STATUS_CODE(status->status); } @@ -387,7 +391,7 @@ static uint32_t poll_until_done(const struct transport_context *ctx, if (status->version != TRANSPORT_V0 && !(status->flags & STATUS_FLAG_WORKING)) { /* The slave has stopped working without being done so it's misbehaving */ - NLOGE("App %d just stopped working", ctx->app_id); + NLOGE("App 0x%02x just stopped working", ctx->app_id); return APP_ERROR_INTERNAL; } if (clock_gettime(CLOCK_MONOTONIC, &now) != 0) { @@ -396,8 +400,8 @@ static uint32_t poll_until_done(const struct transport_context *ctx, } } while (timespec_before(&now, &abort_at)); - NLOGE("App %d not done after polling %d times in %d seconds", - ctx->app_id, poll_count, POLL_LIMIT_SECONDS); + NLOGE("App 0x%02x not done after polling %d times in %d seconds", ctx->app_id, + poll_count, POLL_LIMIT_SECONDS); return APP_ERROR_TIMEOUT; } @@ -440,7 +444,8 @@ static uint32_t receive_reply(const struct transport_context *ctx, if (status->version == TRANSPORT_V0) return APP_SUCCESS; if (crc == status->reply_crc) return APP_SUCCESS; - NLOGW("App %d reply CRC mismatch: theirs=%04x ours=%04x", ctx->app_id, status->reply_crc, crc); + NLOGW("App 0x%02x reply CRC mismatch: theirs=%04x ours=%04x", ctx->app_id, + status->reply_crc, crc); } NLOGE("Unable to get valid checksum on app %d reply data", ctx->app_id); @@ -472,7 +477,7 @@ uint32_t nos_call_application(const struct nos_device *dev, return APP_ERROR_IO; } - NLOGD("Calling App %d with params 0x%04x", app_id, params); + NLOGD("Calling App 0x%02x with params 0x%04x", app_id, params); struct transport_status status; uint32_t status_code; @@ -493,16 +498,16 @@ uint32_t nos_call_application(const struct nos_device *dev, * or more than it can accept but this should not happen. Give to the chip a * little bit of time and retry calling again. */ if (status_code == APP_ERROR_TOO_MUCH) { - NLOGD("App %d returning 0x%x, give a retry(%d/%d)", - app_id, status_code, retries, CRC_RETRY_COUNT); + NLOGD("App 0x%02x returning 0x%x, give a retry(%d/%d)", app_id, + status_code, retries, CRC_RETRY_COUNT); usleep(RETRY_WAIT_TIME_US); continue; } if (status_code != APP_ERROR_CHECKSUM) break; - NLOGW("App %d request checksum error", app_id); + NLOGW("App 0x%02x request checksum error", app_id); } if (status_code == APP_ERROR_CHECKSUM) { - NLOGE("App %d request checksum failed too many times", app_id); + NLOGE("App 0x%02x request checksum failed too many times", app_id); status_code = APP_ERROR_IO; } @@ -519,6 +524,6 @@ uint32_t nos_call_application(const struct nos_device *dev, * next call will try again. */ (void)clear_status(&ctx); - NLOGD("App %d returning 0x%x", app_id, status_code); + NLOGD("App 0x%02x returning 0x%x", app_id, status_code); return status_code; } -- cgit v1.2.3 From f0265c4787285a7a7d98665fdb65dc5b987c373c Mon Sep 17 00:00:00 2001 From: Bill Richardson Date: Thu, 10 Nov 2022 16:27:25 -0600 Subject: Remove acropora internals from feature_map.h Bug: 243819056 Test: manual Change-Id: Iacfcd268e6a391386dbf2f2f7a7cd78b48ce2110 Signed-off-by: Bill Richardson Reviewed-on: https://nugget-os-review.googlesource.com/c/host/generic/+/55466 Reviewed-by: Tommy Chiu Presubmit-Verified: Android Build Prod User --- nugget/include/feature_map.h | 23 +---------------------- 1 file changed, 1 insertion(+), 22 deletions(-) diff --git a/nugget/include/feature_map.h b/nugget/include/feature_map.h index b9875f1..6dcf22e 100644 --- a/nugget/include/feature_map.h +++ b/nugget/include/feature_map.h @@ -5,8 +5,6 @@ #pragma once -#ifndef __ASSEMBLER__ - /*****************************************************************************/ #define TA_MASK 0xFF000000 @@ -40,24 +38,5 @@ enum km_feature_list { km_feature_rkp, km_feature_rkp_dice, km_feature_dice, - km_feature_max = FEATURE_MASK, // For 24-bit alignment + km_feature_max = FEATURE_MASK, // For 24-bit alignment }; - -/*****************************************************************************/ - -/** - * Query the feature supporting status based on task_id and module_id. - * - * @param id: APP_ID which is define in enum feature_support_app_id{} - * @param module_id: sub module list defined above - * @param is_supported: to output the supporting status. True = support. - * - * @return ERR_NONE, or error - * - * NOTE: "id" here is different from the TASK_ID_xxx (which is mutable) or - * APP_ID_xxx (which is out of hex range). - * Instead, we define a fixed order list which can be shared external. - * */ -__err_t is_feature_supported_by_task(enum feature_support_app_id id, - uint32_t module_id, bool *is_supported); -#endif /* !__ASSEMBLER__ */ -- cgit v1.2.3 From 6b4eb4061b56d584a69ffbb167e35f1403c30b02 Mon Sep 17 00:00:00 2001 From: Bill Richardson Date: Mon, 14 Nov 2022 14:14:19 -0600 Subject: Add missing string for APP_ERR_NOT_READY Bug: None Test: None Change-Id: I0cff0a10a2a9027ff2e9d2c8facab2c5c1cd5f30 Signed-off-by: Bill Richardson Reviewed-on: https://nugget-os-review.googlesource.com/c/host/generic/+/55504 Reviewed-by: Kevin Zhang Presubmit-Verified: Android Build Prod User --- libnos/debug.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/libnos/debug.cpp b/libnos/debug.cpp index 0398d54..cc8a2c2 100644 --- a/libnos/debug.cpp +++ b/libnos/debug.cpp @@ -35,6 +35,7 @@ std::string StatusCodeString(uint32_t code) { ErrorString_helper(APP_ERROR_CHECKSUM) ErrorString_helper(APP_ERROR_BUSY) ErrorString_helper(APP_ERROR_TIMEOUT) + ErrorString_helper(APP_ERROR_NOT_READY) default: if (code >= APP_LINE_NUMBER_BASE && code < MAX_APP_STATUS) { return "APP_LINE_NUMBER " + std::to_string(code - APP_LINE_NUMBER_BASE); -- cgit v1.2.3 From 0278e6d167e57a6c57e4b6ce7123c4d0267b12a2 Mon Sep 17 00:00:00 2001 From: Bill Richardson Date: Mon, 14 Nov 2022 18:07:11 -0600 Subject: Add new CallApp() signature With the non-protobuf API we often want to pass pointers to structs instead of std::vector, so just allow that. Bug: 257118594 Bug: 257119908 Test: manual Change-Id: Ic99bf81e9dea44a4c865a73b887e040a16ddac3e Signed-off-by: Bill Richardson Reviewed-on: https://nugget-os-review.googlesource.com/c/host/generic/+/55586 Presubmit-Verified: Android Build Prod User Reviewed-by: Tommy Chiu --- libnos/NuggetClient.cpp | 9 +++++++++ libnos/include/nos/AppClient.h | 15 +++++++++++++++ libnos/include/nos/NuggetClient.h | 16 ++++++++++++++++ libnos/include/nos/NuggetClientInterface.h | 17 +++++++++++++++++ 4 files changed, 57 insertions(+) diff --git a/libnos/NuggetClient.cpp b/libnos/NuggetClient.cpp index c361463..d27e19b 100644 --- a/libnos/NuggetClient.cpp +++ b/libnos/NuggetClient.cpp @@ -84,6 +84,15 @@ uint32_t NuggetClient::CallApp(uint32_t appId, uint16_t arg, return status_code; } +uint32_t NuggetClient::CallApp(uint32_t appId, uint16_t arg, + const void* req_ptr, uint32_t req_len, + void* resp_ptr, uint32_t* resp_len) { + if (!open_) return APP_ERROR_IO; + + return nos_call_application(&device_, appId, arg, (const uint8_t*)req_ptr, + req_len, (uint8_t*)resp_ptr, resp_len); +} + uint32_t NuggetClient::Reset() const { if (!open_) diff --git a/libnos/include/nos/AppClient.h b/libnos/include/nos/AppClient.h index 0a35d82..1299100 100644 --- a/libnos/include/nos/AppClient.h +++ b/libnos/include/nos/AppClient.h @@ -51,6 +51,21 @@ public: return _client.CallApp(_appId, arg, request, response); } + /** + * Call the app. + * + * @param arg Argument to pass to the app. + * @param req_ptr Data to send to the app. + * @param req_len Number of bytes to send to the app. + * @param resp_ptr Buffer to receive data from the app. + * @param resp_len In: Max number of bytes to receive from the app. + * Out: Actual number of bytes received from the app. + */ + uint32_t Call(uint16_t arg, const void* req_ptr, uint32_t req_len, + void* resp_ptr, uint32_t* resp_len) { + return _client.CallApp(_appId, arg, req_ptr, req_len, resp_ptr, + resp_len); + } private: NuggetClientInterface& _client; diff --git a/libnos/include/nos/NuggetClient.h b/libnos/include/nos/NuggetClient.h index 9484bd8..c4dc1cb 100644 --- a/libnos/include/nos/NuggetClient.h +++ b/libnos/include/nos/NuggetClient.h @@ -72,6 +72,22 @@ public: const std::vector& request, std::vector* response) override; + /** + * Call into an app running on Nugget. + * + * @param app_id The ID of the app to call. + * @param arg Argument to pass to the app. + * @param req_ptr Data to send to the app. + * @param req_len Number of bytes to send to the app. + * @param resp_ptr Buffer to receive data from the app. + * @param resp_len In: Max number of bytes to receive from the app. + * Out: Actual number of bytes received from the app. + * @return Status code from the app. + */ + uint32_t CallApp(uint32_t appId, uint16_t arg, const void* req_ptr, + uint32_t req_len, void* resp_ptr, + uint32_t* resp_len) override; + /** * Reset the device. Use with caution; context may be lost. */ diff --git a/libnos/include/nos/NuggetClientInterface.h b/libnos/include/nos/NuggetClientInterface.h index 8d78185..e14c794 100644 --- a/libnos/include/nos/NuggetClientInterface.h +++ b/libnos/include/nos/NuggetClientInterface.h @@ -58,6 +58,23 @@ public: virtual uint32_t CallApp(uint32_t appId, uint16_t arg, const std::vector& request, std::vector* response) = 0; + + /** + * Call into an app running on Nugget. + * + * @param app_id The ID of the app to call. + * @param arg Argument to pass to the app. + * @param req_ptr Data to send to the app. + * @param req_len Number of bytes to send to the app. + * @param resp_ptr Buffer to receive data from the app. + * @param resp_len In: Max number of bytes to receive from the app. + * Out: Actual number of bytes received from the app. + * @return Status code from the app. + */ + virtual uint32_t CallApp(uint32_t appId, uint16_t arg, const void* req_ptr, + uint32_t req_len, void* resp_ptr, + uint32_t* resp_len) = 0; + /** * Reset the device. Use with caution; context may be lost. */ -- cgit v1.2.3 From a5bbdc59a634cad8d3e1ae5cf201adfa84a5ded1 Mon Sep 17 00:00:00 2001 From: Bill Richardson Date: Mon, 14 Nov 2022 18:02:38 -0600 Subject: Add nos::has_feature() to query Nugget OS features This provides a simple function for AP apps to query Nugget OS for the existence of features. Bug: 243819056 Test: manual Change-Id: I97e2fb26fbf04af0d5b05f4ccbd22d12d27e1548 Signed-off-by: Bill Richardson Reviewed-on: https://nugget-os-review.googlesource.com/c/host/generic/+/55584 Presubmit-Verified: Android Build Prod User Reviewed-by: Tommy Chiu --- BUILD | 1 + libnos/Android.bp | 12 ++++++++++++ libnos/BUILD | 2 ++ libnos/feature.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++++ libnos/include/nos/feature.h | 29 +++++++++++++++++++++++++++++ nugget/include/feature_map.h | 38 +++++++++++++++++++++++--------------- 6 files changed, 111 insertions(+), 15 deletions(-) create mode 100644 libnos/feature.cpp create mode 100644 libnos/include/nos/feature.h diff --git a/BUILD b/BUILD index 74f705e..2d41ab7 100644 --- a/BUILD +++ b/BUILD @@ -6,6 +6,7 @@ cc_library( "nugget/include/application.h", "nugget/include/avb.h", "nugget/include/citadel_events.h", + "nugget/include/feature_map.h", "nugget/include/flash_layout.h", "nugget/include/keymaster.h", "nugget/include/signed_header.h", diff --git a/libnos/Android.bp b/libnos/Android.bp index f68df27..808b288 100644 --- a/libnos/Android.bp +++ b/libnos/Android.bp @@ -35,6 +35,18 @@ cc_library { export_shared_lib_headers: ["libnos_datagram"], } +cc_library { + name: "libnos_feature", + srcs: [ + "feature.cpp", + ], + defaults: ["nos_cc_host_supported_defaults"], + header_libs: ["nos_headers"], + shared_libs: ["libnos_datagram"], + export_include_dirs: ["include"], + export_shared_lib_headers: ["libnos_datagram"], +} + // This part of libnos must be linked with the target's implementation of // libnos_datagram. A library should be created for this such as: // diff --git a/libnos/BUILD b/libnos/BUILD index a03ec8f..c3e7007 100644 --- a/libnos/BUILD +++ b/libnos/BUILD @@ -3,12 +3,14 @@ cc_library( srcs = [ "NuggetClient.cpp", "debug.cpp", + "feature.cpp", ], hdrs = [ "include/nos/AppClient.h", "include/nos/NuggetClient.h", "include/nos/NuggetClientInterface.h", "include/nos/debug.h", + "include/nos/feature.h", ], includes = [ "include", diff --git a/libnos/feature.cpp b/libnos/feature.cpp new file mode 100644 index 0000000..6651319 --- /dev/null +++ b/libnos/feature.cpp @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2022 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +namespace nos { + +bool has_feature(NuggetClientInterface& nug, enum feature_support_app_id app_id, + uint32_t feature) { + uint32_t feature_id = (app_id << TA_OFFSET) | (feature & FEATURE_MASK); + + std::vector req(sizeof(feature_id)); + memcpy(req.data(), &feature_id, sizeof(feature_id)); + + std::vector resp; + resp.reserve(sizeof(uint8_t)); + + uint32_t rv = + nug.CallApp(APP_ID_NUGGET, NUGGET_PARAM_GET_FEATURE_SUPPORT, req, &resp); + if (rv != APP_SUCCESS) { + return false; + } + + if (resp.size() < 1) { + return false; // I guess? + } + + return !!resp[0]; +} + +} // namespace nos diff --git a/libnos/include/nos/feature.h b/libnos/include/nos/feature.h new file mode 100644 index 0000000..0ed6d0a --- /dev/null +++ b/libnos/include/nos/feature.h @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2022 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include +#include +#include +#include + +namespace nos { + +bool has_feature(NuggetClientInterface& nug, enum feature_support_app_id app_id, + uint32_t feature); + +} // namespace nos diff --git a/nugget/include/feature_map.h b/nugget/include/feature_map.h index 6dcf22e..418f7f3 100644 --- a/nugget/include/feature_map.h +++ b/nugget/include/feature_map.h @@ -21,22 +21,30 @@ /*****************************************************************************/ enum feature_support_app_id { - feature_id_avb = 0, - feature_id_gfa, - feature_id_identity, - feature_id_keymint, - feature_id_nugget, - feature_id_weaver, - feature_id_count, - feature_id_max = 0xff, // For 8-bit alignment + feature_id_avb = 0, + feature_id_gfa = 1, + feature_id_identity = 2, + feature_id_keymint = 3, + feature_id_nugget = 4, + feature_id_weaver = 5, + + /* Please do not change numbers after they've been released */ + + feature_id_count, // used in sparse lookup table + feature_id_max = 0xff, // 8-bit TA_FIELD }; +static_assert(feature_id_count <= feature_id_max, + "Too many enum feature_support_app_id values"); enum km_feature_list { - km_feature_individual_attest, - km_feature_batch_attest, - km_feature_gnubby_attest, - km_feature_rkp, - km_feature_rkp_dice, - km_feature_dice, - km_feature_max = FEATURE_MASK, // For 24-bit alignment + km_feature_individual_attest = 0, + km_feature_batch_attest = 1, + km_feature_gnubby_attest = 2, + km_feature_rkp = 3, + km_feature_rkp_dice = 4, + km_feature_dice = 5, + + /* Please do not change numbers after they've been released */ + + km_feature_max = FEATURE_MASK, // 24-bit FEATURE_FIELD }; -- cgit v1.2.3 From 1465195fd71afc6dc0c23795e990f922f3e1df91 Mon Sep 17 00:00:00 2001 From: Bill Richardson Date: Tue, 15 Nov 2022 14:28:41 -0600 Subject: Add weaver headers for non-protobuf API This defines headers and a feature bit to allow Weaver to communicate with the AP using both protobuf and non-protobuf messages. Bug: 257118594 Bug: 257119908 Test: manual Change-Id: I1ac1b59bd330200dfd8410b55308e14e9d2e6c1a Signed-off-by: Bill Richardson Reviewed-on: https://nugget-os-review.googlesource.com/c/host/generic/+/55606 Reviewed-by: Brian Murray Presubmit-Verified: Android Build Prod User Reviewed-by: Tommy Chiu --- BUILD | 13 +++++ nugget/include/application.h | 8 ++- nugget/include/feature_map.h | 8 +++ nugget/include/hals/common.h | 79 +++++++++++++++++++++++++++++ nugget/include/hals/weaver.h | 115 +++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 222 insertions(+), 1 deletion(-) create mode 100644 nugget/include/hals/common.h create mode 100644 nugget/include/hals/weaver.h diff --git a/BUILD b/BUILD index 2d41ab7..f874e2f 100644 --- a/BUILD +++ b/BUILD @@ -11,6 +11,19 @@ cc_library( "nugget/include/keymaster.h", "nugget/include/signed_header.h", ], + deps = [ + "nos_headers_hals", + ], + strip_include_prefix = "nugget/include/", + visibility = ["//visibility:public"], +) + +cc_library( + name = "nos_headers_hals", + hdrs = [ + "nugget/include/hals/common.h", + "nugget/include/hals/weaver.h", + ], strip_include_prefix = "nugget/include/", visibility = ["//visibility:public"], ) diff --git a/nugget/include/application.h b/nugget/include/application.h index 2f897b6..a2d0687 100644 --- a/nugget/include/application.h +++ b/nugget/include/application.h @@ -80,6 +80,12 @@ typedef const void * const __private; #define APP_ID_TRANSPORT_TEST 0x12 #define APP_ID_FACEAUTH_TEST 0x13 +/* OR this with the APP_ID to request no-protobuf messages */ +#define APP_ID_NO_PROTO_FLAG 0x80 + +/* No-protobuf app, experimental for now */ +#define APP_ID_WEAVER2 (APP_ID_WEAVER | APP_ID_NO_PROTO_FLAG) + /* This app ID should only be used by tests. */ #define APP_ID_TEST 0xff @@ -90,7 +96,7 @@ typedef const void * const __private; * The Command encoding is: * * Bits 31-24 Control flags (reserved) - * Bits 23-16 Application ID + * Bits 23-16 Application ID (bit 23 indicates C protocol, not protobuf) * Bits 15-0 Parameters (application-specific) */ diff --git a/nugget/include/feature_map.h b/nugget/include/feature_map.h index 418f7f3..2d3e1a0 100644 --- a/nugget/include/feature_map.h +++ b/nugget/include/feature_map.h @@ -48,3 +48,11 @@ enum km_feature_list { km_feature_max = FEATURE_MASK, // 24-bit FEATURE_FIELD }; + +enum weaver_feature_list { + weaver_feature_api_no_proto = 0, + + /* Please do not change numbers after they've been released */ + + weaver_feature_max = FEATURE_MASK, // 24-bit FEATURE_FIELD +}; diff --git a/nugget/include/hals/common.h b/nugget/include/hals/common.h new file mode 100644 index 0000000..ed02484 --- /dev/null +++ b/nugget/include/hals/common.h @@ -0,0 +1,79 @@ +/* + * Copyright (C) 2022 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +#ifndef __packed +#define __packed __attribute__((packed)) +#endif + +/****************************************************************************/ +/** + * This should be the start of EVERY request and response struct. + * + * We don't really need a struct just to hold one integer, but if we need to add + * to it later, we'll be glad we did. + */ +struct nos2_cmd_hal { + uint32_t version; +} __packed; +/** + * IMPORTANT IMPORTANT IMPORTANT IMPORTANT IMPORTANT IMPORTANT IMPORTANT + * + * Do *NOT* increment the version number with each new dessert release! + * + * We'll use a (major << 16) | (minor) value for the version. The major + * versionn indicates when the command was first supported, and the minor + * indicates variations to it since then. + * + * We're currently working on Android 14 (UDC), so start with that. Bump minor + * values ONLY if the behavior changes. + * + * By including the version struct in every request and response, we can + * support multiple minor HAL changes independently. Add a new version + * constant below IF AND ONLY IF a command's struct changes or its behavior is + * different. THEN use that version internally to + * + * 1. Reject the command if the version is one you don't know about, AND + * + * 2. Verify that the incoming struct matches expectations for the versions + * you do know about, AND + * + * 3. Support as many versions as possible, in case Android is downgraded and + * Nugget OS is not (or vice-versa), SO + * + * 4) Make sure to indicate the version in the output structs too, in case the + * command has no input args but the output later changes. + * + * IMPORTANT IMPORTANT IMPORTANT IMPORTANT IMPORTANT IMPORTANT IMPORTANT + */ +#define NOS2_HAL_VERSION_UDC (14U << 16) +/* STOP! Don't just randomly add new values here! Read the comment above! */ + +/****************************************************************************/ +/* Common types */ + +/* TODO(b/257251378): We'll need some stuff here. */ + +/****************************************************************************/ +#ifdef __cplusplus +} +#endif diff --git a/nugget/include/hals/weaver.h b/nugget/include/hals/weaver.h new file mode 100644 index 0000000..1d4bf65 --- /dev/null +++ b/nugget/include/hals/weaver.h @@ -0,0 +1,115 @@ +/* + * Copyright (C) 2022 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +#include "application.h" +#include "hals/common.h" + +/****************************************************************************/ +/* The command is sent separately from any data */ + +enum nos2_weaver_cmd { + NOS2_WEAVER_GET_CONFIG, + NOS2_WEAVER_WRITE, + NOS2_WEAVER_READ, + NOS2_WEAVER_ERASE_VALUE, + + NOS2_WEAVER_NUM_CMDS +}; + +/* error codes specific to this application */ +enum { + /* NOS2_WEAVER_READ may also return one of these */ + APP_ERROR_NOS2_WEAVER_READ_INCORRECT_KEY = APP_SPECIFIC_ERROR, + APP_ERROR_NOS2_WEAVER_READ_THROTTLE +}; + +/****************************************************************************/ +/* Magic constants */ + +/* + * Only Acropora knows these numbers. The AP has to ask. + * + * It's a pain to create multiple variable-length arrays using strictly correct + * C, but the Weaver service is in the Nugget OS repo so we can hard-code the + * sizes here. If it ever changes we'll use the hal.version field to distinguish + * which one we're using. + */ +#define NOS2_WEAVER_NUM_SLOTS 64 +#define NOS2_WEAVER_KEY_BYTES (128 / 8) +#define NOS2_WEAVER_VALUE_BYTES (128 / 8) +static_assert((NOS2_WEAVER_KEY_BYTES & 0x4) == 0, + "NOS2_WEAVER_KEY_BYTES is not a multiple of 4"); +static_assert((NOS2_WEAVER_VALUE_BYTES & 0x4) == 0, + "NOS2_WEAVER_VALUE_BYTES is not a multiple of 4"); + +typedef uint8_t nos2_weaver_key_t[NOS2_WEAVER_KEY_BYTES]; +typedef uint8_t nos2_weaver_value_t[NOS2_WEAVER_VALUE_BYTES]; + +/****************************************************************************/ +/* Request/Response data. Both are optional and depend on the command. */ + +/** NOS2_WEAVER_GET_CONFIG */ +/* No struct nos2_weaver_get_config_request */ +struct nos2_weaver_get_config_response { + struct nos2_cmd_hal hal; + + uint32_t slots; + uint32_t key_size; + uint32_t value_size; +}; + +/** NOS2_WEAVER_WRITE */ +struct nos2_weaver_write_request { + struct nos2_cmd_hal hal; + + uint32_t slot_id; + nos2_weaver_key_t key; + nos2_weaver_value_t value; +}; +/* No struct nos2_weaver_write_response */ + +/** NOS2_WEAVER_READ */ +struct nos2_weaver_read_request { + struct nos2_cmd_hal hal; + + uint32_t slot_id; + nos2_weaver_key_t key; +}; + +struct nos2_weaver_read_response { + struct nos2_cmd_hal hal; + + uint32_t timeout; + nos2_weaver_value_t value; +}; + +/** NOS2_WEAVER_ERASE_VALUE */ +struct nos2_weaver_erase_request { + struct nos2_cmd_hal hal; + + uint32_t slot_id; +}; +/* No struct nos2_weaver_erase_response */ + +/****************************************************************************/ +#ifdef __cplusplus +} +#endif -- cgit v1.2.3 From 6770cbdc23165aa140e5065fbefaa30f9bf564ec Mon Sep 17 00:00:00 2001 From: Joseph Jang Date: Tue, 29 Nov 2022 17:36:36 +0800 Subject: secure_transport: Add one byte to indicate if need to report suez data Bug: 201592534 Change-Id: Icc9876477389e395074fa569f2f03de31b870f98 Reviewed-on: https://nugget-os-review.googlesource.com/c/host/generic/+/55725 Presubmit-Verified-Together: Android Build Prod User Reviewed-by: Bill Richardson Presubmit-Verified: Android Build Prod User --- nugget/include/app_nugget.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nugget/include/app_nugget.h b/nugget/include/app_nugget.h index 53a594f..14c4bb8 100644 --- a/nugget/include/app_nugget.h +++ b/nugget/include/app_nugget.h @@ -559,8 +559,8 @@ struct secure_channel_retry_count_persist_storage { /* * Secure transport report noise handshake state command * - * @param args GSA noise handshake state - * @param arg_len 1 + * @param args GSA noise handshake state + report suez state + * @param arg_len 2 * @param reply * @param reply_len 1 */ -- cgit v1.2.3 From 39350265ff97a428ca4ba3db024da2b97b6bd9aa Mon Sep 17 00:00:00 2001 From: Tommy Chiu Date: Thu, 24 Nov 2022 22:03:53 +0800 Subject: Proto: add KM::ExportDeviceIds definitions Bug: 259501951 Change-Id: Ifa850ecac30b4b7b283c871bcbbcfb89da2b142d Reviewed-on: https://nugget-os-review.googlesource.com/c/host/generic/+/55705 Reviewed-by: Tommy Chiu Reviewed-by: Kevin Zhang Tested-by: Tommy Chiu Presubmit-Verified: Android Build Prod User --- nugget/proto/nugget/app/keymaster/keymaster.proto | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/nugget/proto/nugget/app/keymaster/keymaster.proto b/nugget/proto/nugget/app/keymaster/keymaster.proto index 89710e6..d4c5a6f 100644 --- a/nugget/proto/nugget/app/keymaster/keymaster.proto +++ b/nugget/proto/nugget/app/keymaster/keymaster.proto @@ -149,6 +149,11 @@ service Keymaster { rpc GenerateRkpKey(GenerateRkpKeyRequest) returns (GenerateRkpKeyResponse); rpc GenerateRkpCsr(GenerateRkpCsrRequest) returns (GenerateRkpCsrResponse); + /* + * Vendor specific method. To export IMEI/DSU to trusty only + */ + rpc ExportDeviceIds(ExportDeviceIdsRequest) returns (ExportDeviceIdsResponse); + // These are implemented with a enum, so new RPCs must be appended, and // deprecated RPCs need placeholders. } @@ -439,6 +444,24 @@ message ProvisionDeviceIdsResponse { bool nodelocked_ro = 3; } +message ExportDeviceIdsRequest { + bytes challenge = 1; + bytes challenge_hmac = 2; +} + +message ExportDeviceIdsResponse { + ErrorCode error_code = 1; + bytes product_brand = 2; + bytes product_device = 3; + bytes product_name = 4; + bytes serialno = 5; + bytes product_manufacturer = 6; + bytes product_model = 7; + bytes imei = 8; + bytes meid = 9; + bytes ids_hmac = 10; +} + // ReadTeeBatchCertificate // Only callable at the Device Factory message ReadTeeBatchCertificateRequest { -- cgit v1.2.3 From e95d8ab3a5f206719415a5ce55c65ed1f72718e1 Mon Sep 17 00:00:00 2001 From: Donnie Pollitz Date: Tue, 6 Dec 2022 11:55:25 +0100 Subject: Remove use of deprecated ByteSize * Generated code was using deprecated ByteSize, use ByeSizeLong instead. Bug: 261551456 Bug: 260245541 Test: Client side builds Change-Id: Ib2d2d68347ddcc40a6a5de817321e84a95d4ba25 Signed-off-by: Donnie Pollitz Reviewed-on: https://nugget-os-review.googlesource.com/c/host/generic/+/55844 Reviewed-by: Kevin Zhang Autosubmit: Tommy Chiu Presubmit-Verified: Android Build Prod User Tested-by: Tommy Chiu Reviewed-by: Tommy Chiu --- libnos/generator/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libnos/generator/main.cpp b/libnos/generator/main.cpp index 04dfa89..25178c3 100644 --- a/libnos/generator/main.cpp +++ b/libnos/generator/main.cpp @@ -240,7 +240,7 @@ void GenerateClientSource(Printer& printer, const ServiceDescriptor& service) { methodVars.insert(vars.begin(), vars.end()); printer.Print(methodVars, R"( uint32_t $class$::$method_name$(const $method_input_type$& request, $method_output_type$* response) { - const size_t request_size = request.ByteSize(); + const size_t request_size = request.ByteSizeLong(); if (request_size > $max_request_size$) { return APP_ERROR_TOO_MUCH; } -- cgit v1.2.3 From 4b8fa47c84e9f3355615d79f12cdb5dbaff5a45b Mon Sep 17 00:00:00 2001 From: Bill Richardson Date: Thu, 15 Dec 2022 12:18:07 -0600 Subject: weaver: update C-HAL to match AIDL Bug: 259556049 Test: manual: nugget_aidl_test_weaver Change-Id: Id3f77966b6899682d65ef9780c3d2a961e684418 Signed-off-by: Bill Richardson Reviewed-on: https://nugget-os-review.googlesource.com/c/host/generic/+/56126 Presubmit-Verified: Android Build Prod User Reviewed-by: Brian Murray --- nugget/include/hals/weaver.h | 54 ++++++++++++++++++++++++-------------------- 1 file changed, 29 insertions(+), 25 deletions(-) diff --git a/nugget/include/hals/weaver.h b/nugget/include/hals/weaver.h index 1d4bf65..29bd67c 100644 --- a/nugget/include/hals/weaver.h +++ b/nugget/include/hals/weaver.h @@ -23,34 +23,17 @@ extern "C" { #include "hals/common.h" /****************************************************************************/ -/* The command is sent separately from any data */ - -enum nos2_weaver_cmd { - NOS2_WEAVER_GET_CONFIG, - NOS2_WEAVER_WRITE, - NOS2_WEAVER_READ, - NOS2_WEAVER_ERASE_VALUE, - - NOS2_WEAVER_NUM_CMDS -}; - -/* error codes specific to this application */ -enum { - /* NOS2_WEAVER_READ may also return one of these */ - APP_ERROR_NOS2_WEAVER_READ_INCORRECT_KEY = APP_SPECIFIC_ERROR, - APP_ERROR_NOS2_WEAVER_READ_THROTTLE -}; - -/****************************************************************************/ -/* Magic constants */ - -/* +/* Magic constants + * * Only Acropora knows these numbers. The AP has to ask. * * It's a pain to create multiple variable-length arrays using strictly correct * C, but the Weaver service is in the Nugget OS repo so we can hard-code the * sizes here. If it ever changes we'll use the hal.version field to distinguish * which one we're using. + * + * Still, we want to match the AIDL definitions as closely as possible, to + * make our code easier to understand and maintain. */ #define NOS2_WEAVER_NUM_SLOTS 64 #define NOS2_WEAVER_KEY_BYTES (128 / 8) @@ -63,11 +46,23 @@ static_assert((NOS2_WEAVER_VALUE_BYTES & 0x4) == 0, typedef uint8_t nos2_weaver_key_t[NOS2_WEAVER_KEY_BYTES]; typedef uint8_t nos2_weaver_value_t[NOS2_WEAVER_VALUE_BYTES]; +/****************************************************************************/ +/* The command is sent separately from any data */ + +enum nos2_weaver_cmd { + NOS2_WEAVER_GET_CONFIG, + NOS2_WEAVER_WRITE, + NOS2_WEAVER_READ, + NOS2_WEAVER_ERASE_VALUE, + + NOS2_WEAVER_NUM_CMDS +}; + /****************************************************************************/ /* Request/Response data. Both are optional and depend on the command. */ /** NOS2_WEAVER_GET_CONFIG */ -/* No struct nos2_weaver_get_config_request */ +/* There is no struct nos2_weaver_get_config_request */ struct nos2_weaver_get_config_response { struct nos2_cmd_hal hal; @@ -84,7 +79,7 @@ struct nos2_weaver_write_request { nos2_weaver_key_t key; nos2_weaver_value_t value; }; -/* No struct nos2_weaver_write_response */ +/* There is no struct nos2_weaver_write_response */ /** NOS2_WEAVER_READ */ struct nos2_weaver_read_request { @@ -94,10 +89,19 @@ struct nos2_weaver_read_request { nos2_weaver_key_t key; }; +enum nos2_weaver_read_status { + NOS2_WEAVER_READ_STATUS_OK, + NOS2_WEAVER_READ_STATUS_FAILED, + NOS2_WEAVER_READ_STATUS_INCORRECT_KEY, + NOS2_WEAVER_READ_STATUS_THROTTLE, +}; + struct nos2_weaver_read_response { struct nos2_cmd_hal hal; uint32_t timeout; + uint32_t status; /* enum nos2_weaver_read_status, but of specified size */ + /* Put potentially variable-length members at the end. It's NOT, though */ nos2_weaver_value_t value; }; @@ -107,7 +111,7 @@ struct nos2_weaver_erase_request { uint32_t slot_id; }; -/* No struct nos2_weaver_erase_response */ +/* There is no struct nos2_weaver_erase_response */ /****************************************************************************/ #ifdef __cplusplus -- cgit v1.2.3 From 9a2e12b07d3279ffca0767912e3f2167f32257d8 Mon Sep 17 00:00:00 2001 From: Joseph Jang Date: Mon, 24 Oct 2022 11:37:06 +0800 Subject: identity: Add new APIs for Android 14 Bug: 255259684 Test: atest VtsHalIdentityTargetTest atest android.security.identity.cts Change-Id: Ib6b32ed31049fe14b1c5a000bb98d2b5b3c91e1c Reviewed-on: https://nugget-os-review.googlesource.com/c/host/generic/+/54944 Presubmit-Verified: Android Build Prod User Reviewed-by: Tommy Chiu Tested-by: Joseph Jang --- nugget/proto/nugget/app/identity/identity.proto | 39 +++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/nugget/proto/nugget/app/identity/identity.proto b/nugget/proto/nugget/app/identity/identity.proto index 8532f6a..41af08e 100644 --- a/nugget/proto/nugget/app/identity/identity.proto +++ b/nugget/proto/nugget/app/identity/identity.proto @@ -61,6 +61,11 @@ service Identity { rpc SessionInitialize (SessionInitializeRequest) returns (SessionInitializeResponse); rpc SessionSetReaderEphemeralPublicKey (SessionSetReaderEphemeralPublicKeyRequest) returns (SessionSetReaderEphemeralPublicKeyResponse); rpc SessionSetSessionTranscript (SessionSetSessionTranscriptRequest) returns (SessionSetSessionTranscriptResponse); + + // For Android 14 new APIs + rpc ICprepareDeviceAuthentication (ICprepareDeviceAuthenticationRequest) returns (ICprepareDeviceAuthenticationResponse); + rpc ICfinishRetrievalWithSignature (ICfinishRetrievalWithSignatureRequest) returns (ICfinishRetrievalWithSignatureResponse); + rpc SessionGetEphemeralKeyPair (SessionGetEphemeralKeyPairRequest) returns (SessionGetEphemeralKeyPairResponse); } enum RequestType { @@ -285,6 +290,20 @@ message ICcalcMacKeyResponse{ Result result = 1; } +// ICprepareDeviceAuthentication +message ICprepareDeviceAuthenticationRequest{ + bytes sessionTranscript = 1; + bytes readerEphemeralPublicKey = 2; + bytes signingKeyBlob = 3; + bytes docType = 4; + uint32 numNamespacesWithValues = 5; + uint32 expectedDeviceNamespacesSize = 6; +} + +message ICprepareDeviceAuthenticationResponse{ + Result result = 1; +} + // ICstartRetrieveEntryValue message ICstartRetrieveEntryValueRequest{ string nameSpace = 1; @@ -323,6 +342,16 @@ message ICfinishRetrievalResponse{ bytes mac = 2; } +// ICfinishRetrievalWithSignature +message ICfinishRetrievalWithSignatureRequest{ +} + +message ICfinishRetrievalWithSignatureResponse{ + Result result = 1; + bytes mac = 2; + bytes ecdsaSignature = 3; +} + // ICdeleteCredential message ICdeleteCredentialRequest{ bytes docType = 1; @@ -370,6 +399,7 @@ message SessionShutdownResponse{ // SessionInitialize message SessionInitializeRequest{ + uint32 oemHalVersion = 1; } message SessionInitializeResponse{ @@ -395,3 +425,12 @@ message SessionSetSessionTranscriptRequest{ message SessionSetSessionTranscriptResponse{ Result result = 1; } + +// SessionGetEphemeralKeyPair +message SessionGetEphemeralKeyPairRequest{ +} + +message SessionGetEphemeralKeyPairResponse{ + Result result = 1; + bytes ephemeralPrivateKey = 2; +} -- cgit v1.2.3 From f90e57acf1a94f00588d7df06ee1f3210bae4bbb Mon Sep 17 00:00:00 2001 From: Joseph Jang Date: Tue, 27 Dec 2022 10:46:24 +0000 Subject: MockNuggetClient: Fix build break by adding new CallApp mock method Bug: 263756493 Change-Id: I8316e3860ccdf2d5ceaa9ab01d312e6e40ab11d7 --- libnos/generator/test/test.cpp | 4 ++-- libnos/test/include/nos/MockNuggetClient.h | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/libnos/generator/test/test.cpp b/libnos/generator/test/test.cpp index 4542c88..f6a4835 100644 --- a/libnos/generator/test/test.cpp +++ b/libnos/generator/test/test.cpp @@ -79,7 +79,7 @@ TEST(GeneratedServiceClientTest, DataSuccessfullyExchanged) { GreetResponse response; response.set_greeting("Hello, Tester age 78"); - std::vector responseBytes(response.ByteSize()); + std::vector responseBytes(response.ByteSizeLong()); ASSERT_TRUE(response.SerializeToArray(responseBytes.data(), responseBytes.size())); EXPECT_CALL(client, CallApp(_, _, DecodesToProtoMessage(request), _)) @@ -114,7 +114,7 @@ TEST(GeneratedServiceClientTest, AppErrorsPropagatedWithoutResponseDecode) { GreetResponse response; response.set_greeting("Ignore me"); - std::vector responseBytes(response.ByteSize()); + std::vector responseBytes(response.ByteSizeLong()); ASSERT_TRUE(response.SerializeToArray(responseBytes.data(), responseBytes.size())); EXPECT_CALL(client, CallApp(_, _, _, _)) diff --git a/libnos/test/include/nos/MockNuggetClient.h b/libnos/test/include/nos/MockNuggetClient.h index 48814c9..19e7f00 100644 --- a/libnos/test/include/nos/MockNuggetClient.h +++ b/libnos/test/include/nos/MockNuggetClient.h @@ -33,6 +33,9 @@ struct MockNuggetClient : public NuggetClientInterface { MOCK_METHOD4(CallApp, uint32_t(uint32_t, uint16_t, const std::vector&, std::vector*)); + MOCK_METHOD6(CallApp, uint32_t(uint32_t, uint16_t, + const void*, uint32_t, + void*, uint32_t*)); MOCK_CONST_METHOD0(Reset, uint32_t()); }; -- cgit v1.2.3 From 252b7431b60052499cc17e5fc3d66cf99ac50a2d Mon Sep 17 00:00:00 2001 From: Joseph Jang Date: Tue, 27 Dec 2022 10:46:24 +0000 Subject: MockNuggetClient: Fix build break by adding new CallApp mock method Bug: 263756493 Change-Id: I8316e3860ccdf2d5ceaa9ab01d312e6e40ab11d7 Reviewed-on: https://nugget-os-review.googlesource.com/c/host/generic/+/56324 Tested-by: Joseph Jang Reviewed-by: Tommy Chiu Presubmit-Verified: Android Build Prod User --- libnos/generator/test/test.cpp | 4 ++-- libnos/test/include/nos/MockNuggetClient.h | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/libnos/generator/test/test.cpp b/libnos/generator/test/test.cpp index 4542c88..f6a4835 100644 --- a/libnos/generator/test/test.cpp +++ b/libnos/generator/test/test.cpp @@ -79,7 +79,7 @@ TEST(GeneratedServiceClientTest, DataSuccessfullyExchanged) { GreetResponse response; response.set_greeting("Hello, Tester age 78"); - std::vector responseBytes(response.ByteSize()); + std::vector responseBytes(response.ByteSizeLong()); ASSERT_TRUE(response.SerializeToArray(responseBytes.data(), responseBytes.size())); EXPECT_CALL(client, CallApp(_, _, DecodesToProtoMessage(request), _)) @@ -114,7 +114,7 @@ TEST(GeneratedServiceClientTest, AppErrorsPropagatedWithoutResponseDecode) { GreetResponse response; response.set_greeting("Ignore me"); - std::vector responseBytes(response.ByteSize()); + std::vector responseBytes(response.ByteSizeLong()); ASSERT_TRUE(response.SerializeToArray(responseBytes.data(), responseBytes.size())); EXPECT_CALL(client, CallApp(_, _, _, _)) diff --git a/libnos/test/include/nos/MockNuggetClient.h b/libnos/test/include/nos/MockNuggetClient.h index 48814c9..19e7f00 100644 --- a/libnos/test/include/nos/MockNuggetClient.h +++ b/libnos/test/include/nos/MockNuggetClient.h @@ -33,6 +33,9 @@ struct MockNuggetClient : public NuggetClientInterface { MOCK_METHOD4(CallApp, uint32_t(uint32_t, uint16_t, const std::vector&, std::vector*)); + MOCK_METHOD6(CallApp, uint32_t(uint32_t, uint16_t, + const void*, uint32_t, + void*, uint32_t*)); MOCK_CONST_METHOD0(Reset, uint32_t()); }; -- cgit v1.2.3 From d4631b6be934f223cda351e5e1b7713e786256a9 Mon Sep 17 00:00:00 2001 From: Tommy Chiu Date: Tue, 20 Dec 2022 15:44:54 +0000 Subject: KM: Add GenerateRkpCsrV2 definition Bug: 243454124 Test: VtsHalRemotelyProvisionedComponentTargetTest Change-Id: Iedf7a27f166b83c1eb51e379ec7b9800c5fb4fbb Reviewed-on: https://nugget-os-review.googlesource.com/c/host/generic/+/56186 Tested-by: Tommy Chiu Presubmit-Verified-Together: Android Build Prod User Reviewed-by: Kevin Zhang Presubmit-Verified: Android Build Prod User --- nugget/proto/nugget/app/keymaster/keymaster.proto | 19 +++++++++++++++++++ .../proto/nugget/app/keymaster/keymaster_defs.proto | 6 ++++++ 2 files changed, 25 insertions(+) diff --git a/nugget/proto/nugget/app/keymaster/keymaster.proto b/nugget/proto/nugget/app/keymaster/keymaster.proto index d4c5a6f..a8e56ae 100644 --- a/nugget/proto/nugget/app/keymaster/keymaster.proto +++ b/nugget/proto/nugget/app/keymaster/keymaster.proto @@ -154,6 +154,10 @@ service Keymaster { */ rpc ExportDeviceIds(ExportDeviceIdsRequest) returns (ExportDeviceIdsResponse); + /* + * RKP v3 implementation + */ + rpc GenerateRkpCsrV2(GenerateRkpCsrV2Request) returns (GenerateRkpCsrV2Response); // These are implemented with a enum, so new RPCs must be appended, and // deprecated RPCs need placeholders. } @@ -635,3 +639,18 @@ message GenerateRkpCsrResponse{ bytes device_info_blob = 3; bytes protected_data_blob = 4; } + +message GenerateRkpCsrV2Request{ + RkpCsrV2Operation step = 1; + bytes challenge = 2; + uint32 num_of_public_keys = 3; + MacedKey key_to_sign = 4; + OperationHandle handle = 5; +} +message GenerateRkpCsrV2Response{ + ErrorCode error_code = 1; + OperationHandle handle = 2; + bytes device_info_blob = 3; + bytes dice_cert_chain = 4; + bytes signature = 5; +} diff --git a/nugget/proto/nugget/app/keymaster/keymaster_defs.proto b/nugget/proto/nugget/app/keymaster/keymaster_defs.proto index dfdfeeb..812d6ab 100644 --- a/nugget/proto/nugget/app/keymaster/keymaster_defs.proto +++ b/nugget/proto/nugget/app/keymaster/keymaster_defs.proto @@ -331,3 +331,9 @@ enum CertificateStatus { CERT_UNKNOWN_ERROR = 3; CERT_WRONG_PACKET = 4; } + +enum RkpCsrV2Operation { + RKP_CSR_V2_BEGIN = 0; + RKP_CSR_V2_UPDATE = 1; + RKP_CSR_V2_FINISH = 2; +} -- cgit v1.2.3 From 4d4856726b8ccf8c7b00f20f6d7b4a05cb53508a Mon Sep 17 00:00:00 2001 From: Joseph Jang Date: Wed, 27 Apr 2022 17:03:58 +0800 Subject: secure-transport: Add GSA-GSC secure channel usecase handshake command Bug: 201592534 Change-Id: Ifabe99105c4a063edfccc5cd510ad4277b90d3ac Reviewed-on: https://nugget-os-review.googlesource.com/c/host/generic/+/51807 Presubmit-Verified-Together: Android Build Prod User Reviewed-by: Brian Murray Presubmit-Verified: Android Build Prod User --- nugget/include/app_nugget.h | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/nugget/include/app_nugget.h b/nugget/include/app_nugget.h index 14c4bb8..d245a81 100644 --- a/nugget/include/app_nugget.h +++ b/nugget/include/app_nugget.h @@ -551,7 +551,8 @@ struct secure_channel_retry_count_persist_storage { * * @param args GSA EC public_key + AES_GCM256("MSGA") + AES_GSC_TAG * @param arg_len 64 + 4 + 16 bytes = 84 - * @param reply GSC EC public_key + AES_GCM256("MSGB") + AES_GSC_TAG OR 1 byte error state + * @param reply GSC EC public_key + AES_GCM256("MSGB") + AES_GSC_TAG + * OR 1 byte error state * @param reply_len 64 + 4 + 16 bytes = 84 OR 1 */ @@ -587,6 +588,19 @@ struct secure_channel_retry_count_persist_storage { * * @errors APP_ERROR_BOGUS_ARGS */ + +#define NUGGET_PARAM_SECURE_TRANSPORT_USECASE_HANDSHAKE 0x001d +/* + * Secure transport usecase handshake command + * + * @param args AES_GCM256(struct secure_transport_usecase) + + * AES_GCM_TAG_SIZE + * @param arg_len 64 + 16 = 80 bytes + * @param reply AES_GCM256(struct secure_transport_usecase) + + * AES_GCM_TAG_SIZE OR 1 byte error state + * @param reply_len 64 + 16 = 80 OR 1 bytes + */ + /****************************************************************************/ /* Test related commands */ -- cgit v1.2.3 From 63c7dee5751b42007751931eebf539b86b4787db Mon Sep 17 00:00:00 2001 From: Tommy Chiu Date: Wed, 18 Jan 2023 13:51:37 +0800 Subject: KM: Add multi-IMEI feature definition Keymint v3 requires to support multiple IMEI attestation. That'll involve changes including - ID provision in phone CM - ID attestation in TA Besides that, the duo-sku GSC on P23 makes things more complex. Add this feature map for a batter maintance. Bug: 262255219 Bug: 261705851 Test: build pass Change-Id: I234bf37777ec80c9ff3ecfca9cda8b42fa096d78 Reviewed-on: https://nugget-os-review.googlesource.com/c/host/generic/+/56625 Autosubmit: Tommy Chiu Presubmit-Verified: Android Build Prod User Reviewed-by: Lingyun Zhao Tested-by: Tommy Chiu --- nugget/include/feature_map.h | 1 + 1 file changed, 1 insertion(+) diff --git a/nugget/include/feature_map.h b/nugget/include/feature_map.h index 2d3e1a0..141b52d 100644 --- a/nugget/include/feature_map.h +++ b/nugget/include/feature_map.h @@ -43,6 +43,7 @@ enum km_feature_list { km_feature_rkp = 3, km_feature_rkp_dice = 4, km_feature_dice = 5, + km_feature_multimei = 6, /* Please do not change numbers after they've been released */ -- cgit v1.2.3 From b7bba3625318ba18a734257e03a74d7de3421b55 Mon Sep 17 00:00:00 2001 From: Tommy Chiu Date: Thu, 12 Jan 2023 15:25:20 +0800 Subject: KM: Add second IMEI provisioning definition Bug: 265199825 Change-Id: Id1630be7bdea668b73ceec0a1ffcbd5cec61ac65 Reviewed-on: https://nugget-os-review.googlesource.com/c/host/generic/+/56524 Tested-by: Tommy Chiu Presubmit-Verified: Android Build Prod User Autosubmit: Tommy Chiu Reviewed-by: Tommy Chiu Reviewed-by: Kevin Zhang --- nugget/proto/nugget/app/keymaster/keymaster.proto | 1 + 1 file changed, 1 insertion(+) diff --git a/nugget/proto/nugget/app/keymaster/keymaster.proto b/nugget/proto/nugget/app/keymaster/keymaster.proto index a8e56ae..b281dea 100644 --- a/nugget/proto/nugget/app/keymaster/keymaster.proto +++ b/nugget/proto/nugget/app/keymaster/keymaster.proto @@ -440,6 +440,7 @@ message ProvisionDeviceIdsRequest { bytes product_model = 6; bytes imei = 7; bytes meid = 8; + bytes imei2 = 9; } message ProvisionDeviceIdsResponse { // Specified in keymaster_defs.proto:ErrorCode -- cgit v1.2.3 From 3840c564e07b191283b9eba6dd44bcac8f6f61b3 Mon Sep 17 00:00:00 2001 From: Joseph Jang Date: Tue, 7 Feb 2023 16:33:55 +0800 Subject: secure_transport: Add secure link test command Add secure link test command for CM factory team testing. Bug: 268150153 Change-Id: I0f6455c736043046c6c394d4433a17ba47517789 Reviewed-on: https://nugget-os-review.googlesource.com/c/host/generic/+/56825 Reviewed-by: Bill Richardson Presubmit-Verified: Android Build Prod User --- nugget/include/app_nugget.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/nugget/include/app_nugget.h b/nugget/include/app_nugget.h index d245a81..a732cca 100644 --- a/nugget/include/app_nugget.h +++ b/nugget/include/app_nugget.h @@ -601,6 +601,16 @@ struct secure_channel_retry_count_persist_storage { * @param reply_len 64 + 16 = 80 OR 1 bytes */ +#define NUGGET_PARAM_SECURE_TRANSPORT_TEST 0x001e +/* + * Secure transport test command + * + * @param args 1008 (1024 - 16 bytes AES_TAG_SIZE) bytes test data + * @param arg_len 1008 bytes + * @param reply 1008 (1024 - 16 bytes AES_TAG_SIZE) bytes test data + * @param reply_len 1008 bytes + */ + /****************************************************************************/ /* Test related commands */ -- cgit v1.2.3 From e984921c59649eabfa33e09af7bb2f653cdb5e1f Mon Sep 17 00:00:00 2001 From: Bill Richardson Date: Thu, 9 Feb 2023 11:07:46 -0600 Subject: Change APP_ID_TEST to 0x7f The 0xff value conflicts with the APP_ID_NO_PROTO_FLAG, although I'm not certain anything uses it from this file. None of these APP_ID_*TEST definitions should be in here, really. Bug: None Test: None Change-Id: Id05d003fa9ad280bc44dc7908cc4639365ef6119 Signed-off-by: Bill Richardson Reviewed-on: https://nugget-os-review.googlesource.com/c/host/generic/+/56945 Reviewed-by: Kevin Zhang Presubmit-Verified: Android Build Prod User --- nugget/include/application.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/nugget/include/application.h b/nugget/include/application.h index a2d0687..053d016 100644 --- a/nugget/include/application.h +++ b/nugget/include/application.h @@ -79,6 +79,7 @@ typedef const void * const __private; #define APP_ID_AVB_TEST 0x11 #define APP_ID_TRANSPORT_TEST 0x12 #define APP_ID_FACEAUTH_TEST 0x13 +#define APP_ID_TEST 0x7f /* OR this with the APP_ID to request no-protobuf messages */ #define APP_ID_NO_PROTO_FLAG 0x80 @@ -86,9 +87,6 @@ typedef const void * const __private; /* No-protobuf app, experimental for now */ #define APP_ID_WEAVER2 (APP_ID_WEAVER | APP_ID_NO_PROTO_FLAG) -/* This app ID should only be used by tests. */ -#define APP_ID_TEST 0xff - /****************************************************************************/ /* Other command fields */ -- cgit v1.2.3 From d02651187cca7fa4a2698ee4c086ab1b91f1cf5c Mon Sep 17 00:00:00 2001 From: Lingyun Zhao Date: Thu, 9 Feb 2023 20:26:17 -0800 Subject: Merge remote-tracking branch 'goog/upstream-master' into D3-UDC-003 * goog/upstream-master: Change APP_ID_TEST to 0x7f secure_transport: Add secure link test command KM: Add second IMEI provisioning definition KM: Add multi-IMEI feature definition secure-transport: Add GSA-GSC secure channel usecase handshake command KM: Add GenerateRkpCsrV2 definition MockNuggetClient: Fix build break by adding new CallApp mock method Bug: 268566694 Bug: 268150153 Bug: 265199825 Bug: 262255219 Bug: 261705851 Bug: 201592534 Bug: 243454124 Bug: 263756493 Test: release tests, QMC Change-Id: I93ffd7b3a79c2060e1cdb03572f8ab95e791e8b9 Merged-In: I93ffd7b3a79c2060e1cdb03572f8ab95e791e8b9 --- nugget/include/app_nugget.h | 26 +++++++++++++++++++++- nugget/include/application.h | 4 +--- nugget/include/feature_map.h | 1 + nugget/proto/nugget/app/keymaster/keymaster.proto | 20 +++++++++++++++++ .../nugget/app/keymaster/keymaster_defs.proto | 6 +++++ 5 files changed, 53 insertions(+), 4 deletions(-) diff --git a/nugget/include/app_nugget.h b/nugget/include/app_nugget.h index 14c4bb8..a732cca 100644 --- a/nugget/include/app_nugget.h +++ b/nugget/include/app_nugget.h @@ -551,7 +551,8 @@ struct secure_channel_retry_count_persist_storage { * * @param args GSA EC public_key + AES_GCM256("MSGA") + AES_GSC_TAG * @param arg_len 64 + 4 + 16 bytes = 84 - * @param reply GSC EC public_key + AES_GCM256("MSGB") + AES_GSC_TAG OR 1 byte error state + * @param reply GSC EC public_key + AES_GCM256("MSGB") + AES_GSC_TAG + * OR 1 byte error state * @param reply_len 64 + 4 + 16 bytes = 84 OR 1 */ @@ -587,6 +588,29 @@ struct secure_channel_retry_count_persist_storage { * * @errors APP_ERROR_BOGUS_ARGS */ + +#define NUGGET_PARAM_SECURE_TRANSPORT_USECASE_HANDSHAKE 0x001d +/* + * Secure transport usecase handshake command + * + * @param args AES_GCM256(struct secure_transport_usecase) + + * AES_GCM_TAG_SIZE + * @param arg_len 64 + 16 = 80 bytes + * @param reply AES_GCM256(struct secure_transport_usecase) + + * AES_GCM_TAG_SIZE OR 1 byte error state + * @param reply_len 64 + 16 = 80 OR 1 bytes + */ + +#define NUGGET_PARAM_SECURE_TRANSPORT_TEST 0x001e +/* + * Secure transport test command + * + * @param args 1008 (1024 - 16 bytes AES_TAG_SIZE) bytes test data + * @param arg_len 1008 bytes + * @param reply 1008 (1024 - 16 bytes AES_TAG_SIZE) bytes test data + * @param reply_len 1008 bytes + */ + /****************************************************************************/ /* Test related commands */ diff --git a/nugget/include/application.h b/nugget/include/application.h index a2d0687..053d016 100644 --- a/nugget/include/application.h +++ b/nugget/include/application.h @@ -79,6 +79,7 @@ typedef const void * const __private; #define APP_ID_AVB_TEST 0x11 #define APP_ID_TRANSPORT_TEST 0x12 #define APP_ID_FACEAUTH_TEST 0x13 +#define APP_ID_TEST 0x7f /* OR this with the APP_ID to request no-protobuf messages */ #define APP_ID_NO_PROTO_FLAG 0x80 @@ -86,9 +87,6 @@ typedef const void * const __private; /* No-protobuf app, experimental for now */ #define APP_ID_WEAVER2 (APP_ID_WEAVER | APP_ID_NO_PROTO_FLAG) -/* This app ID should only be used by tests. */ -#define APP_ID_TEST 0xff - /****************************************************************************/ /* Other command fields */ diff --git a/nugget/include/feature_map.h b/nugget/include/feature_map.h index 2d3e1a0..141b52d 100644 --- a/nugget/include/feature_map.h +++ b/nugget/include/feature_map.h @@ -43,6 +43,7 @@ enum km_feature_list { km_feature_rkp = 3, km_feature_rkp_dice = 4, km_feature_dice = 5, + km_feature_multimei = 6, /* Please do not change numbers after they've been released */ diff --git a/nugget/proto/nugget/app/keymaster/keymaster.proto b/nugget/proto/nugget/app/keymaster/keymaster.proto index d4c5a6f..b281dea 100644 --- a/nugget/proto/nugget/app/keymaster/keymaster.proto +++ b/nugget/proto/nugget/app/keymaster/keymaster.proto @@ -154,6 +154,10 @@ service Keymaster { */ rpc ExportDeviceIds(ExportDeviceIdsRequest) returns (ExportDeviceIdsResponse); + /* + * RKP v3 implementation + */ + rpc GenerateRkpCsrV2(GenerateRkpCsrV2Request) returns (GenerateRkpCsrV2Response); // These are implemented with a enum, so new RPCs must be appended, and // deprecated RPCs need placeholders. } @@ -436,6 +440,7 @@ message ProvisionDeviceIdsRequest { bytes product_model = 6; bytes imei = 7; bytes meid = 8; + bytes imei2 = 9; } message ProvisionDeviceIdsResponse { // Specified in keymaster_defs.proto:ErrorCode @@ -635,3 +640,18 @@ message GenerateRkpCsrResponse{ bytes device_info_blob = 3; bytes protected_data_blob = 4; } + +message GenerateRkpCsrV2Request{ + RkpCsrV2Operation step = 1; + bytes challenge = 2; + uint32 num_of_public_keys = 3; + MacedKey key_to_sign = 4; + OperationHandle handle = 5; +} +message GenerateRkpCsrV2Response{ + ErrorCode error_code = 1; + OperationHandle handle = 2; + bytes device_info_blob = 3; + bytes dice_cert_chain = 4; + bytes signature = 5; +} diff --git a/nugget/proto/nugget/app/keymaster/keymaster_defs.proto b/nugget/proto/nugget/app/keymaster/keymaster_defs.proto index dfdfeeb..812d6ab 100644 --- a/nugget/proto/nugget/app/keymaster/keymaster_defs.proto +++ b/nugget/proto/nugget/app/keymaster/keymaster_defs.proto @@ -331,3 +331,9 @@ enum CertificateStatus { CERT_UNKNOWN_ERROR = 3; CERT_WRONG_PACKET = 4; } + +enum RkpCsrV2Operation { + RKP_CSR_V2_BEGIN = 0; + RKP_CSR_V2_UPDATE = 1; + RKP_CSR_V2_FINISH = 2; +} -- cgit v1.2.3 From 0c40b69392658dfda3a572191c3f6b94e1bb515a Mon Sep 17 00:00:00 2001 From: Lingyun Zhao Date: Wed, 1 Mar 2023 14:45:36 -0800 Subject: Add Avb.GetCarrierLockName to expose carrier lock version. go/pixel-gsc-avb-key-migration-dd Test: atest VtsHalOemLockTargetTest Bug: 254287511 Change-Id: Ie05b0b231bf55f829d6f9b46eef5060c7194eb3d Reviewed-on: https://nugget-os-review.googlesource.com/c/host/generic/+/57265 Reviewed-by: Tommy Chiu Presubmit-Verified: Android Build Prod User --- nugget/proto/nugget/app/avb/avb.proto | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/nugget/proto/nugget/app/avb/avb.proto b/nugget/proto/nugget/app/avb/avb.proto index 9aec71e..99e1882 100644 --- a/nugget/proto/nugget/app/avb/avb.proto +++ b/nugget/proto/nugget/app/avb/avb.proto @@ -43,6 +43,7 @@ service Avb { rpc GetOwnerKey (GetOwnerKeyRequest) returns (GetOwnerKeyResponse); rpc GetResetChallenge (GetResetChallengeRequest) returns (GetResetChallengeResponse); rpc ProductionResetTest (ProductionResetTestRequest) returns (ProductionResetTestResponse); + rpc GetCarrierLockName (GetCarrierLockNameRequest) returns (GetCarrierLockNameResponse); } enum LockIndex { @@ -192,3 +193,10 @@ message ProductionResetTestResponse {} message BootloaderDoneRequest {} message BootloaderDoneResponse {} + +// Carrier lock name +message GetCarrierLockNameRequest {} + +message GetCarrierLockNameResponse { + string name = 1; +} -- cgit v1.2.3 From 3b7a36cfef291901a2169336bda6977f2bebe4cb Mon Sep 17 00:00:00 2001 From: Tommy Chiu Date: Tue, 7 Feb 2023 12:37:17 +0000 Subject: KM: Add ATTESTATION_ID_SECOND_IMEI definition Bug: 262255219 Test: VtsAidlKeyMintTargetTest, Change-Id: Idc07e44accffdcdaff83e4958d322b6f186d8658 Reviewed-on: https://nugget-os-review.googlesource.com/c/host/generic/+/56826 Presubmit-Verified: Android Build Prod User Reviewed-by: Lingyun Zhao Tested-by: Tommy Chiu --- nugget/proto/nugget/app/keymaster/keymaster_defs.proto | 1 + 1 file changed, 1 insertion(+) diff --git a/nugget/proto/nugget/app/keymaster/keymaster_defs.proto b/nugget/proto/nugget/app/keymaster/keymaster_defs.proto index 812d6ab..db352c7 100644 --- a/nugget/proto/nugget/app/keymaster/keymaster_defs.proto +++ b/nugget/proto/nugget/app/keymaster/keymaster_defs.proto @@ -99,6 +99,7 @@ enum Tag { DEVICE_UNIQUE_ATTESTATION = 0x702d0; // (TagType:BOOL | 720) IDENTITY_CREDENTIAL_KEY = 0x702d1; // (TagType:BOOL | 721) STORAGE_KEY = 0x702d2; // (TagType:BOOL | 722) + ATTESTATION_ID_SECOND_IMEI = 0x902d3; // (TagType:BYTES | 723) ASSOCIATED_DATA = 0x903e8; // (TagType:BYTES | 1000) NONCE = 0x903e9; // (TagType:BYTES | 1001) /* RESERVED: AUTH_TOKEN = 0x903ea; // (TagType:BYTES | 1002) */ -- cgit v1.2.3 From f7f61b11bd440710b89d01b9c200b6381d0f800b Mon Sep 17 00:00:00 2001 From: Joseph Jang Date: Thu, 16 Feb 2023 06:46:23 +0000 Subject: Move Android libnos_datagram library to /host/android In order to customize libnos_datagram library for Android, move libnos_datagram to /host/android folder and have corresponding binary to link to /host/android/ libnos_datagram library. Bug: 255688398 Change-Id: Ic8b2db8e5c2ee8460952a1f48fa7782048c5f1b3 --- Android.bp | 46 +------ BUILD | 1 + libnos/Android.bp | 4 - libnos/BUILD | 1 - libnos_datagram/Android.bp | 50 ------- libnos_datagram/BUILD | 10 -- libnos_datagram/NOTICE | 177 ------------------------ libnos_datagram/citadel.c | 260 ----------------------------------- libnos_datagram/include/nos/device.h | 96 ------------- libnos_transport/Android.bp | 1 - libnos_transport/BUILD | 1 - libnos_transport/transport.c | 21 ++- nugget/include/nos/device.h | 120 ++++++++++++++++ 13 files changed, 146 insertions(+), 642 deletions(-) delete mode 100644 libnos_datagram/Android.bp delete mode 100644 libnos_datagram/BUILD delete mode 100644 libnos_datagram/NOTICE delete mode 100644 libnos_datagram/citadel.c delete mode 100644 libnos_datagram/include/nos/device.h create mode 100644 nugget/include/nos/device.h diff --git a/Android.bp b/Android.bp index 009de4c..7970d87 100644 --- a/Android.bp +++ b/Android.bp @@ -87,7 +87,7 @@ GEN_SERVICE_SOURCE = GEN_SERVICE + " --nos-client-cpp_out=source:$(genDir) " GEN_SERVICE_HEADER = GEN_SERVICE + " --nos-client-cpp_out=header:$(genDir) " GEN_SERVICE_MOCK = GEN_SERVICE + " --nos-client-cpp_out=mock:$(genDir) " -// A special target to be statically linkeed into recovery which is a system +// A special target to be statically linked into recovery which is a system // (not vendor) component. cc_library_static { name: "libnos_for_recovery", @@ -100,7 +100,6 @@ cc_library_static { export_include_dirs: [ "nugget/include", "libnos/include", - "libnos_datagram/include", "libnos_transport/include", ], srcs: [ @@ -113,7 +112,7 @@ cc_library_static { ], } -// A special target to be statically linkeed into fastboot hal. +// A special target to be statically linked into fastboot hal. cc_library_static { name: "libnos_for_fastboot", recovery: true, @@ -126,7 +125,6 @@ cc_library_static { export_include_dirs: [ "nugget/include", "libnos/include", - "libnos_datagram/include", "libnos_transport/include", ], srcs: [ @@ -139,42 +137,6 @@ cc_library_static { ], } -// A special target to be statically linkeed into recovery which is a system -// (not vendor) component. -cc_library_static { - name: "libnos_citadel_for_recovery", - cflags: [ - "-Wall", - "-Wextra", - "-Werror", - ], - srcs: [ - ":libnos_client", - "libnos_datagram/citadel.c", - ], - static_libs: [ - "libnos_for_recovery", - ], -} - -// A special target to be statically linkeed into fastboot hal. -cc_library_static { - name: "libnos_citadel_for_fastboot", - recovery: true, - cflags: [ - "-Wall", - "-Wextra", - "-Werror", - ], - srcs: [ - ":libnos_client", - "libnos_datagram/citadel.c", - ], - static_libs: [ - "libnos_for_fastboot", - ], -} - // Language and vendor related defaults cc_defaults { name: "nos_cc_defaults", @@ -215,5 +177,7 @@ cc_library { "libnos_client_defaults", "nos_cc_defaults", ], - shared_libs: ["libnos_datagram_citadel"], + shared_libs: [ + "//vendor/google_nos/host/android:libnos_datagram_citadel", + ], } diff --git a/BUILD b/BUILD index f874e2f..c9f246f 100644 --- a/BUILD +++ b/BUILD @@ -9,6 +9,7 @@ cc_library( "nugget/include/feature_map.h", "nugget/include/flash_layout.h", "nugget/include/keymaster.h", + "nugget/include/nos/device.h", "nugget/include/signed_header.h", ], deps = [ diff --git a/libnos/Android.bp b/libnos/Android.bp index 808b288..2fdb924 100644 --- a/libnos/Android.bp +++ b/libnos/Android.bp @@ -30,9 +30,7 @@ cc_library { ], defaults: ["nos_cc_host_supported_defaults"], header_libs: ["nos_headers"], - shared_libs: ["libnos_datagram"], export_include_dirs: ["include"], - export_shared_lib_headers: ["libnos_datagram"], } cc_library { @@ -42,9 +40,7 @@ cc_library { ], defaults: ["nos_cc_host_supported_defaults"], header_libs: ["nos_headers"], - shared_libs: ["libnos_datagram"], export_include_dirs: ["include"], - export_shared_lib_headers: ["libnos_datagram"], } // This part of libnos must be linked with the target's implementation of diff --git a/libnos/BUILD b/libnos/BUILD index c3e7007..627b721 100644 --- a/libnos/BUILD +++ b/libnos/BUILD @@ -18,7 +18,6 @@ cc_library( visibility = ["//visibility:public"], deps = [ "//host/generic:nos_headers", - "//host/generic/libnos_datagram", "//host/generic/libnos_transport", ], ) diff --git a/libnos_datagram/Android.bp b/libnos_datagram/Android.bp deleted file mode 100644 index 0176e00..0000000 --- a/libnos_datagram/Android.bp +++ /dev/null @@ -1,50 +0,0 @@ -// -// Copyright (C) 2017 The Android Open Source Project -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -package { - default_applicable_licenses: [ - "external_nos_host_generic_libnos_datagram_license", - ], -} - -// Added automatically by a large-scale-change -// See: http://go/android-license-faq -license { - name: "external_nos_host_generic_libnos_datagram_license", - visibility: [":__subpackages__"], - license_kinds: [ - "SPDX-license-identifier-Apache-2.0", - ], - license_text: [ - "NOTICE", - ], -} - -cc_library { - name: "libnos_datagram", - defaults: ["nos_cc_host_supported_defaults"], - export_include_dirs: ["include"], -} - -cc_library { - name: "libnos_datagram_citadel", - srcs: ["citadel.c"], - defaults: ["nos_cc_defaults"], - shared_libs: [ - "liblog", - "libnos_datagram", - ], -} diff --git a/libnos_datagram/BUILD b/libnos_datagram/BUILD deleted file mode 100644 index e6f029c..0000000 --- a/libnos_datagram/BUILD +++ /dev/null @@ -1,10 +0,0 @@ -cc_library( - name = "libnos_datagram", - hdrs = [ - "include/nos/device.h", - ], - includes = [ - "./include", - ], - visibility = ["//visibility:public"], -) diff --git a/libnos_datagram/NOTICE b/libnos_datagram/NOTICE deleted file mode 100644 index f433b1a..0000000 --- a/libnos_datagram/NOTICE +++ /dev/null @@ -1,177 +0,0 @@ - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS diff --git a/libnos_datagram/citadel.c b/libnos_datagram/citadel.c deleted file mode 100644 index 7d1d893..0000000 --- a/libnos_datagram/citadel.c +++ /dev/null @@ -1,260 +0,0 @@ -/* - * Copyright (C) 2017 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#define LOG_TAG "libnos_datagram" -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/*****************************************************************************/ -/* Ideally, this should be in */ -#define CITADEL_IOC_MAGIC 'c' -struct citadel_ioc_tpm_datagram { - __u64 buf; - __u32 len; - __u32 command; -}; -#define CITADEL_IOC_TPM_DATAGRAM _IOW(CITADEL_IOC_MAGIC, 1, \ - struct citadel_ioc_tpm_datagram) -#define CITADEL_IOC_RESET _IO(CITADEL_IOC_MAGIC, 2) -/*****************************************************************************/ - -#define DEV_CITADEL "/dev/citadel0" -#define DEV_DAUNTLESS "/dev/gsc0" - -static pthread_mutex_t in_buf_mutex = PTHREAD_MUTEX_INITIALIZER; -static uint8_t in_buf[MAX_DEVICE_TRANSFER]; -static int read_datagram(void *ctx, uint32_t command, uint8_t *buf, uint32_t len) { - struct citadel_ioc_tpm_datagram dg = { - .buf = (unsigned long)in_buf, - .len = len, - .command = command, - }; - int ret; - int fd; - - if (!ctx) { - - ALOGE("%s: invalid (NULL) device\n", __func__); - return -ENODEV; - } - fd = *(int *)ctx; - if (fd < 0) { - ALOGE("%s: invalid device\n", __func__); - return -ENODEV; - } - - if (len > MAX_DEVICE_TRANSFER) { - ALOGE("%s: invalid len (%d > %d)\n", __func__, - len, MAX_DEVICE_TRANSFER); - return -E2BIG; - } - - /* Lock the in buffer while it is used for this transaction */ - if (pthread_mutex_lock(&in_buf_mutex) != 0) { - ALOGE("%s: failed to lock in_buf_mutex: %s", __func__, strerror(errno)); - return -errno; - } - - ret = ioctl(fd, CITADEL_IOC_TPM_DATAGRAM, &dg); - if (ret < 0) { - ALOGE("can't send spi message: %s", strerror(errno)); - ret = -errno; - goto out; - } - - memcpy(buf, in_buf, len); - -out: - if (pthread_mutex_unlock(&in_buf_mutex) != 0) { - ALOGE("%s: failed to unlock in_buf_mutex: %s", __func__, strerror(errno)); - ret = -errno; - } - return ret; -} - -static pthread_mutex_t out_buf_mutex = PTHREAD_MUTEX_INITIALIZER; -static uint8_t out_buf[MAX_DEVICE_TRANSFER]; -static int write_datagram(void *ctx, uint32_t command, const uint8_t *buf, uint32_t len) { - struct citadel_ioc_tpm_datagram dg = { - .buf = (unsigned long)out_buf, - .len = len, - .command = command, - }; - int ret; - int fd; - - if (!ctx) { - ALOGE("%s: invalid (NULL) device\n", __func__); - return -ENODEV; - } - fd = *(int *)ctx; - if (fd < 0) { - ALOGE("%s: invalid device\n", __func__); - return -ENODEV; - } - - if (len > MAX_DEVICE_TRANSFER) { - ALOGE("%s: invalid len (%d > %d)\n", __func__, len, - MAX_DEVICE_TRANSFER); - return -E2BIG; - } - - /* Lock the out buffer while it is used for this transaction */ - if (pthread_mutex_lock(&out_buf_mutex) != 0) { - ALOGE("%s: failed to lock out_buf_mutex: %s", __func__, strerror(errno)); - return -errno; - } - - memcpy(out_buf, buf, len); - - ret = ioctl(fd, CITADEL_IOC_TPM_DATAGRAM, &dg); - if (ret < 0) { - ALOGE("can't send spi message: %s", strerror(errno)); - ret = -errno; - goto out; - } - -out: - if (pthread_mutex_unlock(&out_buf_mutex) != 0) { - ALOGE("%s: failed to unlock out_buf_mutex: %s", __func__, strerror(errno)); - ret = -errno; - } - return ret; -} - -static int wait_for_interrupt(void *ctx, int msecs) { - int fd = *(int *)ctx; - struct pollfd fds = {fd, POLLIN, 0}; - int rv; - - rv = poll(&fds, 1 /*nfds*/, msecs); - if (rv < 0) { - ALOGE("poll: %s", strerror(errno)); - } - - return rv; -} - -static int reset(void *ctx) { - int ret; - int fd; - - if (!ctx) { - - ALOGE("%s: invalid (NULL) device\n", __func__); - return -ENODEV; - } - fd = *(int *)ctx; - if (fd < 0) { - ALOGE("%s: invalid device\n", __func__); - return -ENODEV; - } - - ret = ioctl(fd, CITADEL_IOC_RESET); - if (ret < 0) { - ALOGE("can't reset Citadel: %s", strerror(errno)); - return -errno; - } - return 0; -} - -static void close_device(void *ctx) { - int fd; - - if (!ctx) { - ALOGE("%s: invalid (NULL) device (ignored)\n", __func__); - return; - } - fd = *(int *)ctx; - if (fd < 0) { - ALOGE("%s: invalid device (ignored)\n", __func__); - return; - } - - if (close(fd) < 0) - ALOGE("Problem closing device (ignored): %s", strerror(errno)); - free(ctx); -} - -static const char *default_device(void) { - struct stat statbuf; - int rv; - - rv = stat(DEV_CITADEL, &statbuf); - if (!rv) { - return DEV_CITADEL; - } - - rv = stat(DEV_DAUNTLESS, &statbuf); - if (!rv) { - return DEV_DAUNTLESS; - } - - return 0; -} - -int nos_device_open(const char *device_name, struct nos_device *dev) { - int fd, *new_ctx; - - if (!device_name) { - device_name = default_device(); - } - - if (!device_name) { - ALOGE("can't find device node\n"); - return -ENODEV; - } - - fd = open(device_name, O_RDWR); - if (fd < 0) { - ALOGE("can't open device \"%s\": %s", device_name, strerror(errno)); - return -errno; - } - - /* Our context is just a pointer to an int holding the fd */ - new_ctx = (int *)malloc(sizeof(int)); - if (!new_ctx) { - ALOGE("can't malloc new ctx: %s", strerror(errno)); - close(fd); - return -ENOMEM; - } - *new_ctx = fd; - - dev->ctx = new_ctx; - dev->ops.read = read_datagram; - dev->ops.write = write_datagram; - dev->ops.wait_for_interrupt = wait_for_interrupt; - dev->ops.reset = reset; - dev->ops.close = close_device; - return 0; -} diff --git a/libnos_datagram/include/nos/device.h b/libnos_datagram/include/nos/device.h deleted file mode 100644 index 2ba57e0..0000000 --- a/libnos_datagram/include/nos/device.h +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright (C) 2017 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#ifndef NOS_DEVICE_H -#define NOS_DEVICE_H - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/* Max data size for read/write. - * Yes, it's a magic number. See b/37675056#comment8. */ -#define MAX_DEVICE_TRANSFER 2044 - -struct nos_device_ops { - /** - * Read a datagram from the device. - * - * Return 0 on success and a negative value on failure. - */ - int (*read)(void* ctx, uint32_t command, uint8_t *buf, uint32_t len); - - /** - * Write a datagram to the device. - * - * Return 0 on success and a negative value on failure. - */ - int (*write)(void *ctx, uint32_t command, const uint8_t *buf, uint32_t len); - - /** - * Block until an event has happened on the device, or until timed out. - * - * Values for msecs - * <0 wait forever - * 0 return immediately (why?) - * >0 timeout after this many milliseconds - * - * Returns: - * <0 on error - * 0 timed out - * >0 interrupt occurred - */ - int (*wait_for_interrupt)(void *ctx, int msecs); - - /** - * Reset the device. - * - * Return 0 on success and a negative value on failure. - */ - int (*reset)(void *ctx); - - /** - * Close the connection to the device. - * - * The device must not be used after closing. - */ - void (*close)(void *ctx); -}; - -struct nos_device { - void *ctx; - struct nos_device_ops ops; - uint32_t config; -}; - -/* - * Open a connection to a Nugget device. - * - * The name parameter identifies which Nugget device to connect to. Passing - * NULL connects to the default device. - * - * This function is implemented by the host specific variants of this library. - * - * Returns 0 on success or negative on failure. - */ -int nos_device_open(const char *name, struct nos_device *device); - -#ifdef __cplusplus -} -#endif - -#endif /* NOS_DEVICE_H */ diff --git a/libnos_transport/Android.bp b/libnos_transport/Android.bp index 1dd8992..ee519c5 100644 --- a/libnos_transport/Android.bp +++ b/libnos_transport/Android.bp @@ -47,7 +47,6 @@ cc_library { shared_libs: [ "libbase", "liblog", - "libnos_datagram", ], export_include_dirs: ["include"], } diff --git a/libnos_transport/BUILD b/libnos_transport/BUILD index 9fc9017..0d70a0d 100644 --- a/libnos_transport/BUILD +++ b/libnos_transport/BUILD @@ -14,7 +14,6 @@ cc_library( visibility = ["//visibility:public"], deps = [ "//host/generic:nos_headers", - "//host/generic/libnos_datagram", ], ) diff --git a/libnos_transport/transport.c b/libnos_transport/transport.c index cda7099..72aa2d7 100644 --- a/libnos_transport/transport.c +++ b/libnos_transport/transport.c @@ -461,6 +461,7 @@ uint32_t nos_call_application(const struct nos_device *dev, uint8_t *reply, uint32_t *reply_len) { uint32_t res; + uint32_t status_code; const struct transport_context ctx = { .dev = dev, .app_id = app_id, @@ -477,10 +478,28 @@ uint32_t nos_call_application(const struct nos_device *dev, return APP_ERROR_IO; } +#ifdef ANDROID + if (!dev) { + NLOGE("Invalid args to %s()", __func__); + return APP_ERROR_IO; + } + + // Call GSA nos_call IOCTL interface if needed + if (dev->ops.use_one_pass_call(dev->ctx, app_id, params)) { + int err = dev->ops.one_pass_call(dev->ctx, app_id, params, args, arg_len, + reply, reply_len, &status_code); + if (err < 0) { + NLOGE("one_pass_call failed: %s", strerror(-err)); + status_code = APP_ERROR_IO; + } + + return status_code; + } +#endif + NLOGD("Calling App 0x%02x with params 0x%04x", app_id, params); struct transport_status status; - uint32_t status_code; int retries = CRC_RETRY_COUNT; while (retries--) { /* Wake up and wait for Citadel to be ready */ diff --git a/nugget/include/nos/device.h b/nugget/include/nos/device.h new file mode 100644 index 0000000..e70a317 --- /dev/null +++ b/nugget/include/nos/device.h @@ -0,0 +1,120 @@ +/* + * Copyright (C) 2017 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef NOS_DEVICE_H +#define NOS_DEVICE_H + +#ifdef ANDROID +#include +#endif +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* Max data size for read/write. + * Yes, it's a magic number. See b/37675056#comment8. */ +#define MAX_DEVICE_TRANSFER 2044 + +struct nos_device_ops { + /** + * Read a datagram from the device. + * + * Return 0 on success and a negative value on failure. + */ + int (*read)(void* ctx, uint32_t command, uint8_t *buf, uint32_t len); + + /** + * Write a datagram to the device. + * + * Return 0 on success and a negative value on failure. + */ + int (*write)(void *ctx, uint32_t command, const uint8_t *buf, uint32_t len); + + /** + * Block until an event has happened on the device, or until timed out. + * + * Values for msecs + * <0 wait forever + * 0 return immediately (why?) + * >0 timeout after this many milliseconds + * + * Returns: + * <0 on error + * 0 timed out + * >0 interrupt occurred + */ + int (*wait_for_interrupt)(void *ctx, int msecs); + + /** + * Reset the device. + * + * Return 0 on success and a negative value on failure. + */ + int (*reset)(void *ctx); + + /** + * Close the connection to the device. + * + * The device must not be used after closing. + */ + void (*close)(void *ctx); + +#ifdef ANDROID + /** + * use_one_pass_call: check if need to use one_pass_call or not. + * + * Return true if need to use one_pass_call. + * Otherwise use original nos_call_application() TPM commands. + */ + bool (*use_one_pass_call)(void *ctx, uint8_t app_id, uint16_t params); + + /** + * one_pass_call: sending whole data payload directly to GSA FW + * and rely on GSA libnos_transport library to communicate with GSC. + * + * Return 0 on success. A negative value on I/O failure. + */ + int (*one_pass_call)(void *ctx, uint8_t app_id, uint16_t params, + const uint8_t *args, uint32_t arg_len, + uint8_t *reply, uint32_t *reply_len, + uint32_t *status_code); +#endif +}; + +struct nos_device { + void *ctx; + struct nos_device_ops ops; + uint32_t config; +}; + +/* + * Open a connection to a Nugget device. + * + * The name parameter identifies which Nugget device to connect to. Passing + * NULL connects to the default device. + * + * This function is implemented by the host specific variants of this library. + * + * Returns 0 on success or negative on failure. + */ +int nos_device_open(const char *name, struct nos_device *device); + +#ifdef __cplusplus +} +#endif + +#endif /* NOS_DEVICE_H */ -- cgit v1.2.3 From bb5734699d7971a10fb8168f8e7f2812385dac07 Mon Sep 17 00:00:00 2001 From: Joseph Jang Date: Wed, 29 Mar 2023 04:44:03 +0000 Subject: Move libnos_datagram lib back to external/nos Since Android git_udc-dev-plus-aosp-without-vendor has no vendor image, so if we move libnos_datagram lib to vendor/google_nos, it will cause build break in git_udc-dev-plus-aosp-without-vendor. So move libnos_datagram lib back to external/nos as a short term solution. Bug: 275652569 Change-Id: I70b1560ac7a0d6edc2202b03cde7951bc51a28eb --- Android.bp | 44 ++++- libnos_datagram/Android.bp | 52 ++++++ libnos_datagram/NOTICE | 177 +++++++++++++++++++ libnos_datagram/citadel.cpp | 418 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 690 insertions(+), 1 deletion(-) create mode 100644 libnos_datagram/Android.bp create mode 100644 libnos_datagram/NOTICE create mode 100644 libnos_datagram/citadel.cpp diff --git a/Android.bp b/Android.bp index 7970d87..82c6d50 100644 --- a/Android.bp +++ b/Android.bp @@ -137,6 +137,48 @@ cc_library_static { ], } +// A special target to be statically linked into recovery which is a system +// (not vendor) component. +cc_library_static { + name: "libnos_citadel_for_recovery", + cflags: [ + "-Wall", + "-Wextra", + "-Werror", + ], + srcs: [ + ":libnos_client", + "libnos_datagram/citadel.cpp", + ], + static_libs: [ + "libnos_for_recovery", + ], + shared_libs: [ + "libbase", + ], +} + +// A special target to be statically linked into fastboot hal. +cc_library_static { + name: "libnos_citadel_for_fastboot", + recovery: true, + cflags: [ + "-Wall", + "-Wextra", + "-Werror", + ], + srcs: [ + ":libnos_client", + "libnos_datagram/citadel.cpp", + ], + static_libs: [ + "libnos_for_fastboot", + ], + shared_libs: [ + "libbase", + ], +} + // Language and vendor related defaults cc_defaults { name: "nos_cc_defaults", @@ -178,6 +220,6 @@ cc_library { "nos_cc_defaults", ], shared_libs: [ - "//vendor/google_nos/host/android:libnos_datagram_citadel", + "libnos_datagram_citadel", ], } diff --git a/libnos_datagram/Android.bp b/libnos_datagram/Android.bp new file mode 100644 index 0000000..f854bd8 --- /dev/null +++ b/libnos_datagram/Android.bp @@ -0,0 +1,52 @@ +// +// Copyright (C) 2017 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +package { + default_applicable_licenses: [ + "external_nos_host_generic_libnos_datagram_license", + ], +} + +// Added automatically by a large-scale-change +// See: http://go/android-license-faq +license { + name: "external_nos_host_generic_libnos_datagram_license", + visibility: [":__subpackages__"], + license_kinds: [ + "SPDX-license-identifier-Apache-2.0", + ], + license_text: [ + "NOTICE", + ], +} + +cc_library { + name: "libnos_datagram", + defaults: ["nos_cc_host_supported_defaults"], +} + +cc_library { + name: "libnos_datagram_citadel", + srcs: ["citadel.cpp"], + header_libs: ["nos_headers"], + defaults: ["nos_cc_defaults"], + shared_libs: [ + "libbase", + "liblog", + "libnos_transport", + "libnos_datagram", + ], +} diff --git a/libnos_datagram/NOTICE b/libnos_datagram/NOTICE new file mode 100644 index 0000000..f433b1a --- /dev/null +++ b/libnos_datagram/NOTICE @@ -0,0 +1,177 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS diff --git a/libnos_datagram/citadel.cpp b/libnos_datagram/citadel.cpp new file mode 100644 index 0000000..a5f1b34 --- /dev/null +++ b/libnos_datagram/citadel.cpp @@ -0,0 +1,418 @@ +/* + * Copyright (C) 2017 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define LOG_TAG "libnos_datagram" +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +/*****************************************************************************/ +/* Ideally, this should be in */ +#define CITADEL_IOC_MAGIC 'c' +struct citadel_ioc_tpm_datagram { + __u64 buf; + __u32 len; + __u32 command; +}; + +/* GSA nos call request struct */ +struct gsa_ioc_nos_call_req { + __u8 app_id; + __u16 params; + __u32 arg_len; + __u64 buf; + __u32 reply_len; + __u32 call_status; +}; + +#define CITADEL_IOC_TPM_DATAGRAM _IOW(CITADEL_IOC_MAGIC, 1, \ + struct citadel_ioc_tpm_datagram) +#define CITADEL_IOC_RESET _IO(CITADEL_IOC_MAGIC, 2) +#define GSC_IOC_GSA_NOS_CALL _IOW(CITADEL_IOC_MAGIC, 3, \ + struct gsa_ioc_nos_call_req) +/*****************************************************************************/ + +#define DEV_CITADEL "/dev/citadel0" +#define DEV_DAUNTLESS "/dev/gsc0" + +/* Allocate 4KB buffer for GSA mbox data transmission */ +#define MAX_GSA_NOS_CALL_TRANSFER 4096 +static uint8_t gsa_nos_call_buf[MAX_GSA_NOS_CALL_TRANSFER]; +static pthread_mutex_t nos_call_buf_mutex = PTHREAD_MUTEX_INITIALIZER; + +static pthread_mutex_t in_buf_mutex = PTHREAD_MUTEX_INITIALIZER; +static uint8_t in_buf[MAX_DEVICE_TRANSFER]; +static int read_datagram(void *ctx, uint32_t command, uint8_t *buf, uint32_t len) { + struct citadel_ioc_tpm_datagram dg = { + .buf = (unsigned long)in_buf, + .len = len, + .command = command, + }; + int ret; + int fd; + + if (!ctx) { + + ALOGE("%s: invalid (NULL) device\n", __func__); + return -ENODEV; + } + fd = *(int *)ctx; + if (fd < 0) { + ALOGE("%s: invalid device\n", __func__); + return -ENODEV; + } + + if (len > MAX_DEVICE_TRANSFER) { + ALOGE("%s: invalid len (%d > %d)\n", __func__, + len, MAX_DEVICE_TRANSFER); + return -E2BIG; + } + + /* Lock the in buffer while it is used for this transaction */ + if (pthread_mutex_lock(&in_buf_mutex) != 0) { + ALOGE("%s: failed to lock in_buf_mutex: %s", __func__, strerror(errno)); + return -errno; + } + + ret = ioctl(fd, CITADEL_IOC_TPM_DATAGRAM, &dg); + if (ret < 0) { + ALOGE("can't send spi message: %s", strerror(errno)); + ret = -errno; + goto out; + } + + memcpy(buf, in_buf, len); + +out: + if (pthread_mutex_unlock(&in_buf_mutex) != 0) { + ALOGE("%s: failed to unlock in_buf_mutex: %s", __func__, strerror(errno)); + ret = -errno; + } + return ret; +} + +static pthread_mutex_t out_buf_mutex = PTHREAD_MUTEX_INITIALIZER; +static uint8_t out_buf[MAX_DEVICE_TRANSFER]; +static int write_datagram(void *ctx, uint32_t command, const uint8_t *buf, uint32_t len) { + struct citadel_ioc_tpm_datagram dg = { + .buf = (unsigned long)out_buf, + .len = len, + .command = command, + }; + int ret; + int fd; + + if (!ctx) { + ALOGE("%s: invalid (NULL) device\n", __func__); + return -ENODEV; + } + fd = *(int *)ctx; + if (fd < 0) { + ALOGE("%s: invalid device\n", __func__); + return -ENODEV; + } + + if (len > MAX_DEVICE_TRANSFER) { + ALOGE("%s: invalid len (%d > %d)\n", __func__, len, + MAX_DEVICE_TRANSFER); + return -E2BIG; + } + + /* Lock the out buffer while it is used for this transaction */ + if (pthread_mutex_lock(&out_buf_mutex) != 0) { + ALOGE("%s: failed to lock out_buf_mutex: %s", __func__, strerror(errno)); + return -errno; + } + + memcpy(out_buf, buf, len); + + ret = ioctl(fd, CITADEL_IOC_TPM_DATAGRAM, &dg); + if (ret < 0) { + ALOGE("can't send spi message: %s", strerror(errno)); + ret = -errno; + goto out; + } + +out: + if (pthread_mutex_unlock(&out_buf_mutex) != 0) { + ALOGE("%s: failed to unlock out_buf_mutex: %s", __func__, strerror(errno)); + ret = -errno; + } + return ret; +} + +static int wait_for_interrupt(void *ctx, int msecs) { + int fd = *(int *)ctx; + struct pollfd fds = {fd, POLLIN, 0}; + int rv; + + rv = poll(&fds, 1 /*nfds*/, msecs); + if (rv < 0) { + ALOGE("poll: %s", strerror(errno)); + } + + return rv; +} + +static int reset(void *ctx) { + int ret; + int fd; + + if (!ctx) { + + ALOGE("%s: invalid (NULL) device\n", __func__); + return -ENODEV; + } + fd = *(int *)ctx; + if (fd < 0) { + ALOGE("%s: invalid device\n", __func__); + return -ENODEV; + } + + ret = ioctl(fd, CITADEL_IOC_RESET); + if (ret < 0) { + ALOGE("can't reset Citadel: %s", strerror(errno)); + return -errno; + } + return 0; +} + +static void close_device(void *ctx) { + int fd; + + if (!ctx) { + ALOGE("%s: invalid (NULL) device (ignored)\n", __func__); + return; + } + fd = *(int *)ctx; + if (fd < 0) { + ALOGE("%s: invalid device (ignored)\n", __func__); + return; + } + + if (close(fd) < 0) + ALOGE("Problem closing device (ignored): %s", strerror(errno)); + free(ctx); +} + +/* Detect if GSA kernel support nos_call interface + * Returns 0 on success or negative on failure. + */ +static int detect_gsa_nos_call_interface(int fd) { + int ret; + + if (fd < 0) { + ALOGE("invalid device handle (%d)", fd); + return -errno; + } + + struct gsa_ioc_nos_call_req gsa_nos_call_req = { + .app_id = UINT8_MAX, + .params = 0, + .arg_len = 0, + .buf = (unsigned long)gsa_nos_call_buf, + .reply_len = 0, + .call_status = 0, + }; + + ret = ioctl(fd, GSC_IOC_GSA_NOS_CALL, &gsa_nos_call_req); + if (ret < 0) { + ALOGE("can't send GSA mbox command: %s", strerror(errno)); + } + + return ret; +} + +static bool use_one_pass_call(void *ctx, uint8_t app_id, uint16_t params) { + static bool already_check_gsa_ioctl_and_property = false; + static uint32_t first_api_level = 0; + static bool is_gsa_nos_call_supported = false; + bool use_gsa_nos_call = false; + + if (!ctx) { + ALOGE("Invalid args to %s()", __func__); + return false; + } + + if (!already_check_gsa_ioctl_and_property) { + int fd = *(int *)ctx; + int ret = detect_gsa_nos_call_interface(fd); + if (ret == 0) { + is_gsa_nos_call_supported = true; + } + + first_api_level = + android::base::GetUintProperty("ro.product.first_api_level", 0); + + already_check_gsa_ioctl_and_property = true; + } + + /* Switch to use GSA libnos_transport lib if has GSC and device launch with + * API level >= 33 (Android TM) + */ + if (is_gsa_nos_call_supported && first_api_level >= 33) { + use_gsa_nos_call = true; + + /* TODO(optional): support dynamically switch to use gsa nos_call if needed */ + (void)app_id; + (void)params; + } + + return use_gsa_nos_call; +} + +static int one_pass_call(void *ctx, uint8_t app_id, uint16_t params, + const uint8_t *args, uint32_t arg_len, + uint8_t *reply, uint32_t *reply_len, + uint32_t *status_code) { + *status_code = APP_SUCCESS; + int ret; + int fd; + + struct gsa_ioc_nos_call_req gsa_nos_call_req = { + .app_id = app_id, + .params = params, + .arg_len = arg_len, + .buf = (unsigned long)gsa_nos_call_buf, + .reply_len = *reply_len, + .call_status = *status_code, + }; + + ALOGD("Calling App 0x%02x with params 0x%04x", app_id, params); + + if (!ctx || (arg_len && !args) || + (reply_len && *reply_len && !reply) || + (arg_len > MAX_GSA_NOS_CALL_TRANSFER) || + (reply_len && *reply_len > MAX_GSA_NOS_CALL_TRANSFER) || + !status_code) { + ALOGE("Invalid args to %s()", __func__); + return -EINVAL; + } + + fd = *(int *)ctx; + if (fd < 0) { + ALOGE("%s: invalid device\n", __func__); + return -ENODEV; + } + + /* Lock the out buffer while it is used for this transaction */ + if (pthread_mutex_lock(&nos_call_buf_mutex) != 0) { + ALOGE("%s: failed to lock nos_call_buf_mutex: %s", __func__, strerror(errno)); + return -errno; + } + + if (arg_len) { + memcpy(gsa_nos_call_buf, args, arg_len); + } + + ret = ioctl(fd, GSC_IOC_GSA_NOS_CALL, &gsa_nos_call_req); + if (ret < 0) { + ALOGE("can't send GSA mbox command: %s", strerror(errno)); + goto exit; + } + + *status_code = gsa_nos_call_req.call_status; + if (reply_len != NULL) { + *reply_len = gsa_nos_call_req.reply_len; + if (*reply_len) { + memcpy(reply, gsa_nos_call_buf, *reply_len); + } + } + +exit: + if (pthread_mutex_unlock(&nos_call_buf_mutex) != 0) { + ALOGE("%s: failed to unlock nos_call_buf_mutex: %s", __func__, + strerror(errno)); + return -errno; + } + + ALOGD("App 0x%02x returning 0x%x", app_id, *status_code); + return ret; +} + +static const char *default_device(void) { + struct stat statbuf; + int rv; + + rv = stat(DEV_CITADEL, &statbuf); + if (!rv) { + return DEV_CITADEL; + } + + rv = stat(DEV_DAUNTLESS, &statbuf); + if (!rv) { + return DEV_DAUNTLESS; + } + + return 0; +} + +int nos_device_open(const char *device_name, struct nos_device *dev) { + int fd, *new_ctx; + + if (!device_name) { + device_name = default_device(); + } + + if (!device_name) { + ALOGE("can't find device node\n"); + return -ENODEV; + } + + fd = open(device_name, O_RDWR); + if (fd < 0) { + ALOGE("can't open device \"%s\": %s", device_name, strerror(errno)); + return -errno; + } + + /* Our context is just a pointer to an int holding the fd */ + new_ctx = (int *)malloc(sizeof(int)); + if (!new_ctx) { + ALOGE("can't malloc new ctx: %s", strerror(errno)); + close(fd); + return -ENOMEM; + } + *new_ctx = fd; + + dev->ctx = new_ctx; + dev->ops.read = read_datagram; + dev->ops.write = write_datagram; + dev->ops.wait_for_interrupt = wait_for_interrupt; + dev->ops.reset = reset; + dev->ops.close = close_device; + dev->ops.use_one_pass_call = use_one_pass_call; + dev->ops.one_pass_call = one_pass_call; + return 0; +} -- cgit v1.2.3 From fca163ade988e3aa3502784560fcd5ea4e1189a7 Mon Sep 17 00:00:00 2001 From: Tommy Chiu Date: Thu, 6 Apr 2023 16:03:16 +0000 Subject: KM: Add SetSystemVersionInfoRequest.vendor_api_level definition We'll need to pass the vendor_api_level to TA for some attestation data encoding. Bug: 275394135 Test: VtsAidlKeyMintTargetTest Change-Id: I3276d064e83422952f7ac31554932cc12be6e1a8 --- nugget/proto/nugget/app/keymaster/keymaster.proto | 1 + 1 file changed, 1 insertion(+) diff --git a/nugget/proto/nugget/app/keymaster/keymaster.proto b/nugget/proto/nugget/app/keymaster/keymaster.proto index b281dea..496018a 100644 --- a/nugget/proto/nugget/app/keymaster/keymaster.proto +++ b/nugget/proto/nugget/app/keymaster/keymaster.proto @@ -501,6 +501,7 @@ message SetSystemVersionInfoRequest { uint32 system_version = 1; // getprop "ro.build.version.release" uint32 system_security_level = 2; // getprop "ro.build.version.security_patch" uint32 vendor_security_level = 3; // getprop "ro.vendor.build.security_patch" + uint32 vendor_api_level = 4; } message SetSystemVersionInfoResponse { -- cgit v1.2.3 From 8c73a14567f004fa56d93fc6a57839bae83bf31e Mon Sep 17 00:00:00 2001 From: Joseph Jang Date: Tue, 11 Apr 2023 01:47:00 +0000 Subject: Change the GSA NOS_CALL detction This is a short term solution to allow Citadeld to correctly detect GSA new IOCTL interface and route Android data to GSA NOS_CALL handler. Bug: 255688398 Change-Id: I5a2db9ca8405fcbb1c46bba0f56f1bebe39da7f0 --- libnos_datagram/citadel.cpp | 68 +++++++++++++------------------------------- libnos_transport/transport.c | 2 +- nugget/include/nos/device.h | 11 ++----- 3 files changed, 24 insertions(+), 57 deletions(-) diff --git a/libnos_datagram/citadel.cpp b/libnos_datagram/citadel.cpp index a5f1b34..199635c 100644 --- a/libnos_datagram/citadel.cpp +++ b/libnos_datagram/citadel.cpp @@ -49,12 +49,13 @@ struct citadel_ioc_tpm_datagram { /* GSA nos call request struct */ struct gsa_ioc_nos_call_req { - __u8 app_id; - __u16 params; - __u32 arg_len; - __u64 buf; - __u32 reply_len; - __u32 call_status; + __u8 app_id; + __u8 reserved; + __u16 params; + __u32 arg_len; + __u64 buf; + __u32 reply_len; + __u32 call_status; }; #define CITADEL_IOC_TPM_DATAGRAM _IOW(CITADEL_IOC_MAGIC, 1, \ @@ -228,18 +229,21 @@ static void close_device(void *ctx) { } /* Detect if GSA kernel support nos_call interface - * Returns 0 on success or negative on failure. + * Returns true on success or false on failure. */ -static int detect_gsa_nos_call_interface(int fd) { +static bool detect_gsa_nos_call_interface(int fd) { int ret; + errno = 0; if (fd < 0) { ALOGE("invalid device handle (%d)", fd); - return -errno; + return false; } + /* Send app_id = 0 and params = 0 to detect GSA IOCTL interface */ struct gsa_ioc_nos_call_req gsa_nos_call_req = { - .app_id = UINT8_MAX, + .app_id = 0, + .reserved = 0, .params = 0, .arg_len = 0, .buf = (unsigned long)gsa_nos_call_buf, @@ -252,45 +256,12 @@ static int detect_gsa_nos_call_interface(int fd) { ALOGE("can't send GSA mbox command: %s", strerror(errno)); } - return ret; -} - -static bool use_one_pass_call(void *ctx, uint8_t app_id, uint16_t params) { - static bool already_check_gsa_ioctl_and_property = false; - static uint32_t first_api_level = 0; - static bool is_gsa_nos_call_supported = false; - bool use_gsa_nos_call = false; - - if (!ctx) { - ALOGE("Invalid args to %s()", __func__); + /* GSA kernel is not support GSA_NOS_CALL if return EINVAL or ENOTTY */ + if (!errno) { + return true; + } else { return false; } - - if (!already_check_gsa_ioctl_and_property) { - int fd = *(int *)ctx; - int ret = detect_gsa_nos_call_interface(fd); - if (ret == 0) { - is_gsa_nos_call_supported = true; - } - - first_api_level = - android::base::GetUintProperty("ro.product.first_api_level", 0); - - already_check_gsa_ioctl_and_property = true; - } - - /* Switch to use GSA libnos_transport lib if has GSC and device launch with - * API level >= 33 (Android TM) - */ - if (is_gsa_nos_call_supported && first_api_level >= 33) { - use_gsa_nos_call = true; - - /* TODO(optional): support dynamically switch to use gsa nos_call if needed */ - (void)app_id; - (void)params; - } - - return use_gsa_nos_call; } static int one_pass_call(void *ctx, uint8_t app_id, uint16_t params, @@ -303,6 +274,7 @@ static int one_pass_call(void *ctx, uint8_t app_id, uint16_t params, struct gsa_ioc_nos_call_req gsa_nos_call_req = { .app_id = app_id, + .reserved = 0, .params = params, .arg_len = arg_len, .buf = (unsigned long)gsa_nos_call_buf, @@ -412,7 +384,7 @@ int nos_device_open(const char *device_name, struct nos_device *dev) { dev->ops.wait_for_interrupt = wait_for_interrupt; dev->ops.reset = reset; dev->ops.close = close_device; - dev->ops.use_one_pass_call = use_one_pass_call; dev->ops.one_pass_call = one_pass_call; + dev->use_one_pass_call = detect_gsa_nos_call_interface(fd); return 0; } diff --git a/libnos_transport/transport.c b/libnos_transport/transport.c index 72aa2d7..b3a3a40 100644 --- a/libnos_transport/transport.c +++ b/libnos_transport/transport.c @@ -485,7 +485,7 @@ uint32_t nos_call_application(const struct nos_device *dev, } // Call GSA nos_call IOCTL interface if needed - if (dev->ops.use_one_pass_call(dev->ctx, app_id, params)) { + if (dev->use_one_pass_call) { int err = dev->ops.one_pass_call(dev->ctx, app_id, params, args, arg_len, reply, reply_len, &status_code); if (err < 0) { diff --git a/nugget/include/nos/device.h b/nugget/include/nos/device.h index e70a317..d1fb0d6 100644 --- a/nugget/include/nos/device.h +++ b/nugget/include/nos/device.h @@ -74,14 +74,6 @@ struct nos_device_ops { void (*close)(void *ctx); #ifdef ANDROID - /** - * use_one_pass_call: check if need to use one_pass_call or not. - * - * Return true if need to use one_pass_call. - * Otherwise use original nos_call_application() TPM commands. - */ - bool (*use_one_pass_call)(void *ctx, uint8_t app_id, uint16_t params); - /** * one_pass_call: sending whole data payload directly to GSA FW * and rely on GSA libnos_transport library to communicate with GSC. @@ -99,6 +91,9 @@ struct nos_device { void *ctx; struct nos_device_ops ops; uint32_t config; +#ifdef ANDROID + bool use_one_pass_call; +#endif }; /* -- cgit v1.2.3 From 769eb9719b2a2ca0c17bbc04778027afe2430d83 Mon Sep 17 00:00:00 2001 From: Tommy Chiu Date: Tue, 23 May 2023 15:28:26 +0800 Subject: nugget: Add a app specific error code to reflect different state When flashing new firmware there was always one kind of error which is "LOCKED". Add a new NUGGET_ERROR_VERIFY to reflect the readback check failure. Bug: 261483407 Test: init_citadel Change-Id: I1a0b60a0324e4944c3956868747f2ae80102d701 --- nugget/include/app_nugget.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/nugget/include/app_nugget.h b/nugget/include/app_nugget.h index a732cca..8852b18 100644 --- a/nugget/include/app_nugget.h +++ b/nugget/include/app_nugget.h @@ -29,8 +29,9 @@ extern "C" { /* App-specific errors (across all commands) */ enum { - NUGGET_ERROR_LOCKED = APP_SPECIFIC_ERROR, + NUGGET_ERROR_LOCKED = APP_SPECIFIC_ERROR + 0, NUGGET_ERROR_RETRY, + NUGGET_ERROR_VERIFY, }; /****************************************************************************/ -- cgit v1.2.3