diff options
-rw-r--r-- | hal.h | 15 | ||||
-rw-r--r-- | rpc_server.c | 17 |
2 files changed, 18 insertions, 14 deletions
@@ -125,7 +125,10 @@ DEFINE_HAL_ERROR(HAL_ERROR_PIN_INCORRECT, "PIN incorrect") \ DEFINE_HAL_ERROR(HAL_ERROR_NO_CLIENT_SLOTS_AVAILABLE, "No client slots available") \ DEFINE_HAL_ERROR(HAL_ERROR_FORBIDDEN, "Forbidden") \ + DEFINE_HAL_ERROR(HAL_ERROR_XDR_BUFFER_OVERFLOW, "XDR buffer overflow") \ DEFINE_HAL_ERROR(HAL_ERROR_RPC_TRANSPORT, "RPC transport error") \ + DEFINE_HAL_ERROR(HAL_ERROR_RPC_PACKET_OVERFLOW, "RPC packet overflow") \ + DEFINE_HAL_ERROR(HAL_ERROR_RPC_BAD_FUNCTION, "Bad RPC function number") \ END_OF_HAL_ERROR_LIST /* Marker to forestall silly line continuation errors */ @@ -605,12 +608,6 @@ extern hal_error_t hal_rpc_hash_update(const hal_hash_handle_t hash, extern hal_error_t hal_rpc_hash_finalize(const hal_hash_handle_t hash, uint8_t *digest, const size_t length); -extern hal_error_t hal_rpc_client_init(void); -extern hal_error_t hal_rpc_client_close(void); -extern hal_error_t hal_rpc_server_init(void); -extern hal_error_t hal_rpc_server_close(void); -extern void hal_rpc_server_main(void); - /* * Public key functions. * @@ -719,6 +716,12 @@ extern hal_error_t hal_rpc_pkey_list(hal_pkey_info_t *result, unsigned *result_len, const unsigned result_max); +extern hal_error_t hal_rpc_client_init(void); +extern hal_error_t hal_rpc_client_close(void); +extern hal_error_t hal_rpc_server_init(void); +extern hal_error_t hal_rpc_server_close(void); +extern void hal_rpc_server_main(void); + #endif /* _HAL_H_ */ /* diff --git a/rpc_server.c b/rpc_server.c index 6b3514c..c3394a1 100644 --- a/rpc_server.c +++ b/rpc_server.c @@ -67,7 +67,7 @@ static hal_error_t get_random(uint8_t **iptr, const uint8_t * const ilimit, check(hal_xdr_decode_int(iptr, ilimit, &length)); /* sanity check length */ if (length == 0 || length > olimit - *optr - 4) - return HAL_ERROR_IO_BAD_COUNT; /* need a better error */ + return HAL_ERROR_RPC_PACKET_OVERFLOW; /* call the local function */ /* get the data directly into the output buffer */ @@ -185,7 +185,7 @@ static hal_error_t hash_get_digest_algorithm_id(uint8_t **iptr, const uint8_t * check(hal_xdr_decode_int(iptr, ilimit, &len_max)); /* sanity check len_max */ if (len_max > olimit - *optr - 4) - return HAL_ERROR_IO_BAD_COUNT; /* need a better error */ + return HAL_ERROR_RPC_PACKET_OVERFLOW; /* call the local function */ /* get the data directly into the output buffer */ @@ -269,7 +269,7 @@ static hal_error_t hash_finalize(uint8_t **iptr, const uint8_t * const ilimit, check(hal_xdr_decode_int(iptr, ilimit, &length)); /* sanity check length */ if (length == 0 || length > olimit - *optr - 4) - return HAL_ERROR_IO_BAD_COUNT; /* need a better error */ + return HAL_ERROR_RPC_PACKET_OVERFLOW; /* call the local function */ /* get the data directly into the output buffer */ @@ -473,7 +473,7 @@ static hal_error_t pkey_get_public_key(uint8_t **iptr, const uint8_t * const ili check(hal_xdr_decode_int(iptr, ilimit, &len_max)); /* sanity check len_max */ if (len_max > olimit - *optr - 4) - return HAL_ERROR_IO_BAD_COUNT; /* need a better error */ + return HAL_ERROR_RPC_PACKET_OVERFLOW; /* call the local function */ /* get the data directly into the output buffer */ @@ -511,7 +511,7 @@ static hal_error_t pkey_remote_sign(uint8_t **iptr, const uint8_t * const ilimit check(hal_xdr_decode_int(iptr, ilimit, &sig_max)); /* sanity check sig_max */ if (sig_max > olimit - *optr - 4) - return HAL_ERROR_IO_BAD_COUNT; /* need a better error */ + return HAL_ERROR_RPC_PACKET_OVERFLOW; /* call the local function */ /* get the data directly into the output buffer */ @@ -589,12 +589,13 @@ static hal_error_t pkey_list(uint8_t **iptr, const uint8_t * const ilimit, return ret; } -#define MAX_PKT_SIZE 1024 +#define MAX_PKT_SIZE 4096 #define interrupt 0 +static uint8_t inbuf[MAX_PKT_SIZE], outbuf[MAX_PKT_SIZE]; + void hal_rpc_server_main(void) { - uint8_t inbuf[MAX_PKT_SIZE], outbuf[MAX_PKT_SIZE]; uint8_t *iptr, *ilimit, *optr, *olimit; size_t ilen, olen; uint32_t rpc_func_num; @@ -690,7 +691,7 @@ void hal_rpc_server_main(void) ret = pkey_list(&iptr, ilimit, &optr, olimit); break; default: - ret = HAL_ERROR_BAD_ARGUMENTS; /* need a better error */ + ret = HAL_ERROR_RPC_BAD_FUNCTION; break; } /* encode the return code at the beginning of the payload */ |