Skip to content

Commit

Permalink
shell: replace log messages in on dev cert to shell print
Browse files Browse the repository at this point in the history
KRKNWK-18381
Because the shell is also responsible for handling log messages,
it is impossible to do so while handling the shell command.
This results in the delay between the creation of the log message
inside the shell handler and its process and printing.
Without this message the other side can not be sure
if the command succeded, so it can not proced with next command
wich causes significant delay.

Now the shell printer is used to pass the messages from
shell command and it does no go through logging system.

Signed-off-by: Robert Gałat <[email protected]>
  • Loading branch information
RobertGalatNordic authored and totyz committed Apr 15, 2024
1 parent 5ecca2c commit 69dc434
Showing 1 changed file with 49 additions and 49 deletions.
98 changes: 49 additions & 49 deletions utils/src/sid_on_dev_cert_cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ static struct sid_base64_ctx cert_app_key_base64_ctx = {
.state = 0,
};

static sid_error_t sid_on_dev_cert_cli_print_base64(const uint8_t *input, size_t input_size)
static sid_error_t sid_on_dev_cert_cli_print_base64(const struct shell *shell, const uint8_t *input,
size_t input_size)
{
struct sid_base64_ctx ctx;
sid_base64_init(&ctx);
Expand All @@ -95,7 +96,7 @@ static sid_error_t sid_on_dev_cert_cli_print_base64(const uint8_t *input, size_t
// add a null terminator
*ctx.next_out = '\0';

LOG_INF(CERT_MSG_BASE64, out);
shell_info(shell, CERT_MSG_BASE64, out);

if (status == SID_ERROR_NONE) {
break;
Expand All @@ -116,15 +117,15 @@ static int sid_on_dev_cert_cli_init_cmd(const struct shell *shell, int32_t argc,
sid_error_t ret = sid_on_dev_cert_init();

if (ret == SID_ERROR_NONE) {
LOG_INF(CERT_MSG_BASE64_MTU, CERT_BASE64_FRAGMENT_MAX_SIZE);
LOG_INF(CERT_MSG_OK);
shell_info(shell, CERT_MSG_BASE64_MTU, CERT_BASE64_FRAGMENT_MAX_SIZE);
shell_info(shell, CERT_MSG_OK);
} else {
LOG_INF(CERT_MSG_ERROR, ret);
shell_info(shell, CERT_MSG_ERROR, ret);
}

} else {
LOG_ERR(SYNTAX_ERR);
LOG_WRN(CERT_INIT_CMD);
shell_error(shell, SYNTAX_ERR);
shell_warn(shell, CERT_INIT_CMD);
}
return 0;
}
Expand All @@ -134,11 +135,11 @@ static int sid_on_dev_cert_cli_deinit(const struct shell *shell, int32_t argc, c
if (argc == 1) {
sid_on_dev_cert_deinit();

LOG_INF(CERT_MSG_OK);
shell_info(shell, CERT_MSG_OK);

} else {
LOG_ERR(SYNTAX_ERR);
LOG_WRN(CERT_DEINIT_CMD);
shell_error(shell, SYNTAX_ERR);
shell_warn(shell, CERT_DEINIT_CMD);
}
return 0;
}
Expand Down Expand Up @@ -169,20 +170,20 @@ static int sid_on_dev_cert_cli_smsn(const struct shell *shell, int32_t argc, con
uint8_t smsn[SID_ODC_SMSN_SIZE];
memset(smsn, 0xFF, SID_ODC_SMSN_SIZE);
if ((ret = sid_on_dev_cert_generate_smsn(&dev_info, smsn)) == SID_ERROR_NONE) {
ret = sid_on_dev_cert_cli_print_base64(smsn, SID_ODC_SMSN_SIZE);
ret = sid_on_dev_cert_cli_print_base64(shell, smsn, SID_ODC_SMSN_SIZE);
}

sid_hal_free(dev_type_production);
exit:
if (ret == SID_ERROR_NONE) {
LOG_INF(CERT_MSG_OK);
shell_info(shell, CERT_MSG_OK);
} else {
LOG_INF(CERT_MSG_ERROR, ret);
shell_info(shell, CERT_MSG_ERROR, ret);
}

} else {
LOG_ERR(SYNTAX_ERR);
LOG_WRN(CERT_SMSN_CMD);
shell_error(shell, SYNTAX_ERR);
shell_warn(shell, CERT_SMSN_CMD);
}
return 0;
}
Expand All @@ -205,15 +206,16 @@ static int sid_on_dev_cert_cli_csr(const struct shell *shell, int32_t argc, cons

if (ret == SID_ERROR_NONE &&
(ret = sid_on_dev_cert_generate_csr(algo, csr, &csr_size)) == SID_ERROR_NONE &&
(ret = sid_on_dev_cert_cli_print_base64(csr, csr_size)) == SID_ERROR_NONE) {
LOG_INF(CERT_MSG_OK);
(ret = sid_on_dev_cert_cli_print_base64(shell, csr, csr_size)) ==
SID_ERROR_NONE) {
shell_info(shell, CERT_MSG_OK);
} else {
LOG_INF(CERT_MSG_ERROR, ret);
shell_info(shell, CERT_MSG_ERROR, ret);
}

} else {
LOG_ERR(SYNTAX_ERR);
LOG_WRN(CERT_CSR_CMD);
shell_error(shell, SYNTAX_ERR);
shell_warn(shell, CERT_CSR_CMD);
}
return 0;
}
Expand Down Expand Up @@ -241,14 +243,14 @@ static int sid_on_dev_cert_cli_chain_start(const struct shell *shell, int32_t ar
cert_chain_params.algo = algo;
cert_chain_params.cert_chain = cert_chain_buffer;
cert_chain_params.cert_chain_size = 0;
LOG_INF(CERT_MSG_OK);
shell_info(shell, CERT_MSG_OK);
} else {
LOG_INF(CERT_MSG_ERROR, ret);
shell_info(shell, CERT_MSG_ERROR, ret);
}

} else {
LOG_ERR(SYNTAX_ERR);
LOG_WRN(CERT_CHAIN_START_CMD);
shell_error(shell, SYNTAX_ERR);
shell_warn(shell, CERT_CHAIN_START_CMD);
}
return 0;
}
Expand All @@ -265,9 +267,7 @@ static int sid_on_dev_cert_cli_chain_write(const struct shell *shell, int32_t ar
if (cert_chain_params.cert_chain) {
cert_chain_base64_ctx.next_in = (const uint8_t *)argv[1];
cert_chain_base64_ctx.avail_in = base64_fragment_len;

ret = sid_base64_decode(&cert_chain_base64_ctx);

/*
* If we have a successful result, we should check:
* - the input buffer should be empty
Expand All @@ -290,14 +290,14 @@ static int sid_on_dev_cert_cli_chain_write(const struct shell *shell, int32_t ar
}

if (ret == SID_ERROR_NONE) {
LOG_INF(CERT_MSG_OK);
shell_info(shell, CERT_MSG_OK);
} else {
LOG_INF(CERT_MSG_ERROR, ret);
shell_info(shell, CERT_MSG_ERROR, ret);
}

} else {
LOG_ERR(SYNTAX_ERR);
LOG_WRN(CERT_CHAIN_WRITE_CMD);
shell_error(shell, SYNTAX_ERR);
shell_warn(shell, CERT_CHAIN_WRITE_CMD);
}
return 0;
}
Expand All @@ -318,14 +318,14 @@ static int sid_on_dev_cert_cli_chain_commit(const struct shell *shell, int32_t a
ret = SID_ERROR_UNINITIALIZED;
}
if (ret == SID_ERROR_NONE) {
LOG_INF(CERT_MSG_OK);
shell_info(shell, CERT_MSG_OK);
} else {
LOG_INF(CERT_MSG_ERROR, ret);
shell_info(shell, CERT_MSG_ERROR, ret);
}

} else {
LOG_ERR(SYNTAX_ERR);
LOG_WRN(CERT_CHAIN_COMMIT_CMD);
shell_error(shell, SYNTAX_ERR);
shell_warn(shell, CERT_CHAIN_COMMIT_CMD);
}
return 0;
}
Expand All @@ -337,11 +337,11 @@ static int sid_on_dev_cert_cli_app_key_start(const struct shell *shell, int32_t
sid_base64_init(&cert_app_key_base64_ctx);
cert_app_key_base64_ctx.next_out = cert_app_key;
cert_app_key_base64_ctx.avail_out = SID_ODC_ED25519_PUK_SIZE;
LOG_INF(CERT_MSG_OK);
shell_info(shell, CERT_MSG_OK);

} else {
LOG_ERR(SYNTAX_ERR);
LOG_WRN(CERT_APPKEY_START_CMD);
shell_error(shell, SYNTAX_ERR);
shell_warn(shell, CERT_APPKEY_START_CMD);
}
return 0;
}
Expand Down Expand Up @@ -381,14 +381,14 @@ static int sid_on_dev_cert_cli_app_key_write(const struct shell *shell, int32_t
}

if (ret == SID_ERROR_NONE) {
LOG_INF(CERT_MSG_OK);
shell_info(shell, CERT_MSG_OK);
} else {
LOG_INF(CERT_MSG_ERROR, ret);
shell_info(shell, CERT_MSG_ERROR, ret);
}

} else {
LOG_ERR(SYNTAX_ERR);
LOG_WRN(CERT_APPKEY_WRITE_CMD);
shell_error(shell, SYNTAX_ERR);
shell_warn(shell, CERT_APPKEY_WRITE_CMD);
}
return 0;
}
Expand All @@ -409,14 +409,14 @@ static int sid_on_dev_cert_cli_app_key_commit(const struct shell *shell, int32_t
sid_base64_init(&cert_app_key_base64_ctx);

if (ret == SID_ERROR_NONE) {
LOG_INF(CERT_MSG_OK);
shell_info(shell, CERT_MSG_OK);
} else {
LOG_INF(CERT_MSG_ERROR, ret);
shell_info(shell, CERT_MSG_ERROR, ret);
}

} else {
LOG_ERR(SYNTAX_ERR);
LOG_WRN(CERT_APPKEY_COMMIT_CMD);
shell_error(shell, SYNTAX_ERR);
shell_warn(shell, CERT_APPKEY_COMMIT_CMD);
}
return 0;
}
Expand All @@ -427,14 +427,14 @@ static int sid_on_dev_cert_cli_store(const struct shell *shell, int32_t argc, co
sid_error_t ret = sid_on_dev_cert_verify_and_store();

if (ret == SID_ERROR_NONE) {
LOG_INF(CERT_MSG_OK);
shell_info(shell, CERT_MSG_OK);
} else {
LOG_INF(CERT_MSG_ERROR, ret);
shell_info(shell, CERT_MSG_ERROR, ret);
}

} else {
LOG_ERR(SYNTAX_ERR);
LOG_WRN(CERT_STORE_CMD);
shell_error(shell, SYNTAX_ERR);
shell_warn(shell, CERT_STORE_CMD);
}
return 0;
}
Expand Down

0 comments on commit 69dc434

Please sign in to comment.