Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net: lib: nrf_provisioning: Fix AT command #11967

Merged
merged 1 commit into from
Aug 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions subsys/net/lib/nrf_provisioning/include/nrf_provisioning_at.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ bool nrf_provisioning_at_cmee_is_active(void);
/**
* @brief Sets mobile termination error reporting to a given state.
*
* @param state Buffer to receive the time into.
* @param state State for error reporting.
*
* @returns Zero on success, negative error code on failure.
*/
Expand All @@ -62,25 +62,32 @@ int nrf_provisioning_at_cmee_control(enum nrf_provisioning_at_cmee_state state);
/**
* @brief Enables mobile termination error reporting state.
*
* @param buff Buffer to receive the time into.
* @param size Buffer size.
*
* @returns Previous state
*/
bool nrf_provisioning_at_cmee_enable(void);

/**
* @brief Send any AT command.
*
* @param buff Buffer to receive the response into.
* @param size Buffer size.
* @param size Command to be send.
* @param resp Buffer to receive the response into.
* @param resp_sz Buffer size.
* @param cmd AT command to be send.
*
* @returns Zero on success, negative error code on failure or positive error code when CMEE code
* needs to be checked.
*/
int nrf_provisioning_at_cmd(void *resp, size_t resp_sz, const char *cmd);

/**
* @brief Delete credential.
*
* @param tag The security tag of the credential.
* @param type The credential type.
*
* @returns Zero on success, negative error code on failure.
*/
int nrf_provisioning_at_del_credential(int sec_tag, int type);

#ifdef __cplusplus
}
#endif
Expand Down
5 changes: 5 additions & 0 deletions subsys/net/lib/nrf_provisioning/src/nrf_provisioning_at.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,8 @@ int nrf_provisioning_at_cmd(void *resp, size_t resp_sz, const char *cmd)
{
return nrf_modem_at_cmd(resp, resp_sz, "%s", cmd);
}

int nrf_provisioning_at_del_credential(int tag, int type)
{
return nrf_modem_at_printf("AT%%CMNG=3,%d,%d", tag, type);
}
12 changes: 11 additions & 1 deletion subsys/net/lib/nrf_provisioning/src/nrf_provisioning_codec.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

#include <string.h>
#include <stdio.h>

#include <zephyr/kernel.h>
#include <zephyr/logging/log.h>
Expand Down Expand Up @@ -287,10 +288,19 @@ static int exec_at_cmd(struct command *cmd_req, struct cdc_out_fmt_data *out)
ret = nrf_provisioning_at_cmd(resp, resp_sz, out->at_buff);

if (ret == -E2BIG) {
int tag = 0;
int type = 0;

LOG_DBG("Buffer too small for AT response, retrying");
k_free(resp);
resp = NULL;

if (sscanf(out->at_buff, "AT%%KEYGEN=%d,%d,%*s", &tag, &type) == 2) {
LOG_DBG("Clear sec_tag %d, type %d", tag, type);
ret = nrf_provisioning_at_del_credential(tag, type);
if (ret < 0) {
LOG_ERR("AT cmd failed, error: %d", ret);
}
}
resp_sz *= 2; /* Previous size wasn't sufficient */
if (resp_sz > AT_RESP_MAX_SIZE) {
LOG_ERR("Key or CSR too big");
Expand Down
Loading