Snap for 9470583 from 30ce5bfe589efd12365b044097ad723c00b004bc to tm-qpr3-release

Change-Id: I3b5e51dd287b965324fcf116171e793dc1a35cc9
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 @@
         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;
     }
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 @@
   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/app_nugget.h b/nugget/include/app_nugget.h
index cd8bf33..82554c5 100644
--- a/nugget/include/app_nugget.h
+++ b/nugget/include/app_nugget.h
@@ -299,15 +299,15 @@
   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         <none>
  * @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
@@ -562,7 +562,27 @@
  * @param args         GSA noise handshake state
  * @param arg_len      1
  * @param reply        <none>
- * @param reply_len    0
+ * @param reply_len    1
+ */
+#define NUGGET_PARAM_GET_BIG_EVENT_REPORT 0x001b
+/*
+ * This retrieves one pending big_event_report (defined in citadel_events.h).
+ * If none are pending, it returns nothing.
+ *
+ * @param args         <none>
+ * @param arg_len      0
+ * @param reply        struct big_event_report
+ * @param reply_len    sizeof struct big_event_report  OR  0
+ */
+#define NUGGET_PARAM_GET_BIG_EVENT_REPORT 0x001b
+/*
+ * This retrieves one pending big_event_report (defined in citadel_events.h).
+ * If none are pending, it returns nothing.
+ *
+ * @param args         <none>
+ * @param arg_len      0
+ * @param reply        struct big_event_report
+ * @param reply_len    sizeof struct big_event_report  OR  0
  */
 
 /****************************************************************************/
diff --git a/nugget/include/app_transport_test.h b/nugget/include/app_transport_test.h
index 0c0b4ba..821ebb8 100644
--- a/nugget/include/app_transport_test.h
+++ b/nugget/include/app_transport_test.h
@@ -21,5 +21,6 @@
 #define TRANSPORT_TEST_1234 8    /* Returns 0x01020304 successfully */
 #define TRANSPORT_TEST_9876 9    /* Only successful if the arg is 0x09080706 */
 #define TRANSPORT_TEST_HANG 12   /* Forgets to call app_reply() */
+#define TRANSPORT_TEST_ECHO_2 13 /* Echoes back 2 bytes received by host */
 
 #endif /* __CROS_EC_INCLUDE_APP_TRANSPORT_TEST_H */
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 @@
 
 /* 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 */
diff --git a/nugget/include/citadel_events.h b/nugget/include/citadel_events.h
index 24babee..00780ad 100644
--- a/nugget/include/citadel_events.h
+++ b/nugget/include/citadel_events.h
@@ -31,7 +31,7 @@
  * 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
@@ -59,12 +59,14 @@
  * 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 event_report.
 };
 
 /*
@@ -76,9 +78,17 @@
   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 {
+#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;
@@ -117,9 +127,23 @@
   } 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_report {
+  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
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 @@
   uint64 secureUserId = 5;
   bytes mac = 6;
   uint32 publicKeyOffset = 7;
-  uint32 publicKeysize = 8;
+  uint32 publicKeySize = 8;
 }
 
 message ICvalidateAccessControlProfileResponse{
@@ -297,6 +297,7 @@
 message ICstartRetrieveEntryValueResponse{
   AccessResult accessCheckResult = 1;
   uint32 sessionCookie = 2;
+  Result result = 3;
 }
 
 // ICretrieveEntryValue
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 @@
   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 @@
   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 {