2828
2929#include "htool.h"
3030#include "htool_cmd.h"
31+ #include "protocol/host_cmd.h"
3132#include "protocol/key_rotation.h"
3233
33- static const char * get_validation_method_string (uint32_t validation_method ) {
34+ static const char * get_error_code_string (enum key_rotation_err err ) {
35+ if (err < KEY_ROTATION_ERR_HOTH_BASE ) {
36+ switch (err ) {
37+ case KEY_ROTATION_CMD_SUCCESS :
38+ return "Success" ;
39+ case KEY_ROTATION_INTERNAL_ERR :
40+ return "Internal Error" ;
41+ case KEY_ROTATION_ERR_INVALID_PARAM :
42+ return "Invalid Parameter" ;
43+ case KEY_ROTATION_ERR_INVALID_RESPONSE_SIZE :
44+ return "Invalid Response Size" ;
45+ case KEY_ROTATION_INITIATE_FAIL :
46+ return "Key Rotation Record Initiate Failed" ;
47+ case KEY_ROTATION_COMMIT_FAIL :
48+ return "Key Rotation Record Commit Failed" ;
49+ case KEY_ROTATION_ROOT_OF_TRUST_UNAVAILABLE :
50+ return "Root of Trust Unavailable" ;
51+ default :
52+ return "Unknown" ;
53+ }
54+ }
55+ int ret = err - KEY_ROTATION_ERR_HOTH_BASE ;
56+ switch (ret ) {
57+ case HOTH_RES_SUCCESS :
58+ return "Success" ;
59+ case HOTH_RES_INVALID_COMMAND :
60+ return "Key Rotation Feature Not Supported" ;
61+ case HOTH_RES_ERROR :
62+ return "Hoth Error" ;
63+ case HOTH_RES_INVALID_PARAM :
64+ return "Invalid Parameter" ;
65+ case HOTH_RES_ACCESS_DENIED :
66+ return "Access Denied" ;
67+ case HOTH_RES_INVALID_RESPONSE :
68+ return "Invalid Response" ;
69+ case HOTH_RES_INVALID_VERSION :
70+ return "Invalid Version" ;
71+ case HOTH_RES_INVALID_CHECKSUM :
72+ return "Invalid Checksum" ;
73+ case HOTH_RES_IN_PROGRESS :
74+ return "In Progress" ;
75+ case HOTH_RES_UNAVAILABLE :
76+ return "Unavailable" ;
77+ case HOTH_RES_TIMEOUT :
78+ return "Timeout" ;
79+ case HOTH_RES_OVERFLOW :
80+ return "Overflow" ;
81+ case HOTH_RES_INVALID_HEADER :
82+ return "Invalid Header" ;
83+ case HOTH_RES_REQUEST_TRUNCATED :
84+ return "Request Truncated" ;
85+ case HOTH_RES_RESPONSE_TOO_BIG :
86+ return "Response Too Big" ;
87+ case HOTH_RES_BUS_ERROR :
88+ return "Bus Error" ;
89+ case HOTH_RES_BUSY :
90+ return "Busy" ;
91+ case HOTH_RES_INVALID_HEADER_VERSION :
92+ return "Invalid Header Version" ;
93+ case HOTH_RES_INVALID_HEADER_CRC :
94+ return "Invalid Header CRC" ;
95+ case HOTH_RES_INVALID_DATA_CRC :
96+ return "Invalid Data CRC" ;
97+ case HOTH_RES_DUP_UNAVAILABLE :
98+ return "Duplicate Request Unavailable" ;
99+ default :
100+ return "Unknown" ;
101+ }
102+ }
103+
104+ static const char * get_validation_method_string (uint32_t validation_method ) {
34105 switch (validation_method ) {
35106 case 1 :
36107 return "Embedded Key" ;
@@ -46,11 +117,14 @@ static const char *get_validation_method_string(uint32_t validation_method) {
46117int htool_key_rotation_get_status (void ) {
47118 struct libhoth_device * dev = htool_libhoth_device ();
48119 if (!dev ) {
120+ fprintf (stderr , "Failed to get libhoth device\n" );
49121 return -1 ;
50122 }
51123 struct hoth_response_key_rotation_status status ;
52124 enum key_rotation_err ret = libhoth_key_rotation_get_status (dev , & status );
53125 if (ret ) {
126+ fprintf (stderr , "HOTH_KEY_ROTATION_GET_STATUS error: %s\n" ,
127+ get_error_code_string (ret ));
54128 fprintf (stderr , "Failed to get key rotation status\n" );
55129 return -1 ;
56130 }
@@ -68,11 +142,14 @@ int htool_key_rotation_get_status(void) {
68142int htool_key_rotation_get_version (void ) {
69143 struct libhoth_device * dev = htool_libhoth_device ();
70144 if (!dev ) {
145+ fprintf (stderr , "Failed to get libhoth device\n" );
71146 return -1 ;
72147 }
73148 struct hoth_response_key_rotation_record_version version ;
74149 enum key_rotation_err ret = libhoth_key_rotation_get_version (dev , & version );
75150 if (ret ) {
151+ fprintf (stderr , "HOTH_KEY_ROTATION_GET_VERSION error: %s\n" ,
152+ get_error_code_string (ret ));
76153 fprintf (stderr , "Failed to get key rotation version\n" );
77154 return -1 ;
78155 }
@@ -132,6 +209,7 @@ static int read_image_file(const char *image_file, uint8_t **image,
132209int htool_key_rotation_update (const struct htool_invocation * inv ) {
133210 struct libhoth_device * dev = htool_libhoth_device ();
134211 if (!dev ) {
212+ fprintf (stderr , "Failed to get libhoth device\n" );
135213 return -1 ;
136214 }
137215 const char * image_file ;
@@ -148,6 +226,8 @@ int htool_key_rotation_update(const struct htool_invocation *inv) {
148226
149227 enum key_rotation_err key_ret = libhoth_key_rotation_update (dev , image , size );
150228 if (key_ret ) {
229+ fprintf (stderr , "HOTH_KEY_ROTATION_UPDATE error: %s\n" ,
230+ get_error_code_string (key_ret ));
151231 fprintf (stderr , "Failed to update key rotation record\n" );
152232 result = key_ret ;
153233 }
@@ -164,12 +244,15 @@ int htool_key_rotation_update(const struct htool_invocation *inv) {
164244int htool_key_rotation_payload_status () {
165245 struct libhoth_device * dev = htool_libhoth_device ();
166246 if (!dev ) {
247+ fprintf (stderr , "Failed to get libhoth device\n" );
167248 return -1 ;
168249 }
169250 struct hoth_response_key_rotation_payload_status payload_status ;
170251 enum key_rotation_err ret =
171252 libhoth_key_rotation_payload_status (dev , & payload_status );
172253 if (ret ) {
254+ fprintf (stderr , "HOTH_KEY_ROTATION_PAYLOAD_STATUS error: %s\n" ,
255+ get_error_code_string (ret ));
173256 fprintf (stderr , "Failed to get key rotation payload status\n" );
174257 return -1 ;
175258 }
@@ -201,6 +284,7 @@ static int get_key_rotation_read_half(const char *read_half,
201284int htool_key_rotation_read (const struct htool_invocation * inv ) {
202285 struct libhoth_device * dev = htool_libhoth_device ();
203286 if (!dev ) {
287+ fprintf (stderr , "Failed to get libhoth device\n" );
204288 return -1 ;
205289 }
206290 uint32_t offset = 0 ;
@@ -246,6 +330,8 @@ int htool_key_rotation_read(const struct htool_invocation *inv) {
246330 enum key_rotation_err ret_read =
247331 libhoth_key_rotation_read (dev , offset , size , read_half , & read_response );
248332 if (ret_read ) {
333+ fprintf (stderr , "HOTH_KEY_ROTATION_READ error: %s\n" ,
334+ get_error_code_string (ret_read ));
249335 fprintf (stderr , "Failed to read key rotation record\n" );
250336 if (fd != -1 ) {
251337 close (fd );
@@ -296,6 +382,7 @@ static int get_key_rotation_chunk_type(const char *chunk_type_string,
296382int htool_key_rotation_read_chunk_type (const struct htool_invocation * inv ) {
297383 struct libhoth_device * dev = htool_libhoth_device ();
298384 if (!dev ) {
385+ fprintf (stderr , "Failed to get libhoth device\n" );
299386 return -1 ;
300387 }
301388 uint32_t offset = 0 ;
@@ -345,6 +432,8 @@ int htool_key_rotation_read_chunk_type(const struct htool_invocation *inv) {
345432 dev , chunk_typecode , chunk_index , offset , size , & read_response ,
346433 & response_size );
347434 if (ret_read ) {
435+ fprintf (stderr , "HOTH_KEY_ROTATION_READ_CHUNK_TYPE error: %s\n" ,
436+ get_error_code_string (ret_read ));
348437 fprintf (stderr , "Failed to read chunk from key rotation record\n" );
349438 return -1 ;
350439 }
@@ -385,6 +474,7 @@ int htool_key_rotation_read_chunk_type(const struct htool_invocation *inv) {
385474int htool_key_rotation_chunk_type_count (const struct htool_invocation * inv ) {
386475 struct libhoth_device * dev = htool_libhoth_device ();
387476 if (!dev ) {
477+ fprintf (stderr , "Failed to get libhoth device\n" );
388478 return -1 ;
389479 }
390480 const char * chunk_type_string ;
@@ -401,6 +491,8 @@ int htool_key_rotation_chunk_type_count(const struct htool_invocation *inv) {
401491 enum key_rotation_err ret_count =
402492 libhoth_key_rotation_chunk_type_count (dev , chunk_typecode , & chunk_count );
403493 if (ret_count ) {
494+ fprintf (stderr , "HOTH_KEY_ROTATION_CHUNK_TYPE_COUNT error: %s\n" ,
495+ get_error_code_string (ret_count ));
404496 fprintf (stderr , "Failed to get chunk type count\n" );
405497 return -1 ;
406498 }
0 commit comments