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: openthread: rpc: standarize resources allocation #21156

Merged
merged 1 commit into from
Mar 27, 2025
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
62 changes: 31 additions & 31 deletions subsys/net/openthread/rpc/client/ot_rpc_coap.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ static ot_rpc_coap_request_key ot_rpc_coap_request_alloc(otCoapResponseHandler h
otMessage *otCoapNewMessage(otInstance *aInstance, const otMessageSettings *aSettings)
{
struct nrf_rpc_cbor_ctx ctx;
ot_msg_key message_rep;
ot_rpc_res_tab_key message_rep;

NRF_RPC_CBOR_ALLOC(&ot_group, ctx, OT_RPC_MESSAGE_SETTINGS_LENGTH);
ot_rpc_encode_message_settings(&ctx, aSettings);
Expand All @@ -59,12 +59,12 @@ void otCoapMessageInit(otMessage *aMessage, otCoapType aType, otCoapCode aCode)
struct nrf_rpc_cbor_ctx ctx;
size_t cbor_buffer_size = 0;

cbor_buffer_size += 1 + sizeof(ot_msg_key); /* aMessage */
cbor_buffer_size += 1; /* aType */
cbor_buffer_size += 1 + sizeof(aCode); /* aCode */
cbor_buffer_size += 1 + sizeof(ot_rpc_res_tab_key); /* aMessage */
cbor_buffer_size += 1; /* aType */
cbor_buffer_size += 1 + sizeof(aCode); /* aCode */

NRF_RPC_CBOR_ALLOC(&ot_group, ctx, cbor_buffer_size);
nrf_rpc_encode_uint(&ctx, (ot_msg_key)aMessage);
nrf_rpc_encode_uint(&ctx, (ot_rpc_res_tab_key)aMessage);
nrf_rpc_encode_uint(&ctx, aType);
nrf_rpc_encode_uint(&ctx, aCode);

Expand All @@ -79,14 +79,14 @@ otError otCoapMessageInitResponse(otMessage *aResponse, const otMessage *aReques
size_t cbor_buffer_size = 0;
otError error;

cbor_buffer_size += 1 + sizeof(ot_msg_key); /* aResponse */
cbor_buffer_size += 1 + sizeof(ot_msg_key); /* aRequest */
cbor_buffer_size += 1; /* aType */
cbor_buffer_size += 1 + sizeof(aCode); /* aCode */
cbor_buffer_size += 1 + sizeof(ot_rpc_res_tab_key); /* aResponse */
cbor_buffer_size += 1 + sizeof(ot_rpc_res_tab_key); /* aRequest */
cbor_buffer_size += 1; /* aType */
cbor_buffer_size += 1 + sizeof(aCode); /* aCode */

NRF_RPC_CBOR_ALLOC(&ot_group, ctx, cbor_buffer_size);
nrf_rpc_encode_uint(&ctx, (ot_msg_key)aResponse);
nrf_rpc_encode_uint(&ctx, (ot_msg_key)aRequest);
nrf_rpc_encode_uint(&ctx, (ot_rpc_res_tab_key)aResponse);
nrf_rpc_encode_uint(&ctx, (ot_rpc_res_tab_key)aRequest);
nrf_rpc_encode_uint(&ctx, aType);
nrf_rpc_encode_uint(&ctx, aCode);

Expand All @@ -102,11 +102,11 @@ otError otCoapMessageAppendUriPathOptions(otMessage *aMessage, const char *aUriP
size_t cbor_buffer_size = 0;
otError error;

cbor_buffer_size += 1 + sizeof(ot_msg_key); /* aMessage */
cbor_buffer_size += 2 + strlen(aUriPath); /* aUriPath */
cbor_buffer_size += 1 + sizeof(ot_rpc_res_tab_key); /* aMessage */
cbor_buffer_size += 2 + strlen(aUriPath); /* aUriPath */

NRF_RPC_CBOR_ALLOC(&ot_group, ctx, cbor_buffer_size);
nrf_rpc_encode_uint(&ctx, (ot_msg_key)aMessage);
nrf_rpc_encode_uint(&ctx, (ot_rpc_res_tab_key)aMessage);
nrf_rpc_encode_str(&ctx, aUriPath, -1);

nrf_rpc_cbor_cmd_no_err(&ot_group, OT_RPC_CMD_COAP_MESSAGE_APPEND_URI_PATH_OPTIONS, &ctx,
Expand All @@ -120,8 +120,8 @@ otError otCoapMessageSetPayloadMarker(otMessage *aMessage)
struct nrf_rpc_cbor_ctx ctx;
otError error;

NRF_RPC_CBOR_ALLOC(&ot_group, ctx, 1 + sizeof(ot_msg_key));
nrf_rpc_encode_uint(&ctx, (ot_msg_key)aMessage);
NRF_RPC_CBOR_ALLOC(&ot_group, ctx, 1 + sizeof(ot_rpc_res_tab_key));
nrf_rpc_encode_uint(&ctx, (ot_rpc_res_tab_key)aMessage);

nrf_rpc_cbor_cmd_no_err(&ot_group, OT_RPC_CMD_COAP_MESSAGE_SET_PAYLOAD_MARKER, &ctx,
ot_rpc_decode_error, &error);
Expand All @@ -134,8 +134,8 @@ otCoapType otCoapMessageGetType(const otMessage *aMessage)
struct nrf_rpc_cbor_ctx ctx;
otCoapType type = 0;

NRF_RPC_CBOR_ALLOC(&ot_group, ctx, 1 + sizeof(ot_msg_key));
nrf_rpc_encode_uint(&ctx, (ot_msg_key)aMessage);
NRF_RPC_CBOR_ALLOC(&ot_group, ctx, 1 + sizeof(ot_rpc_res_tab_key));
nrf_rpc_encode_uint(&ctx, (ot_rpc_res_tab_key)aMessage);

nrf_rpc_cbor_cmd_rsp_no_err(&ot_group, OT_RPC_CMD_COAP_MESSAGE_GET_TYPE, &ctx);
nrf_rpc_rsp_decode_uint(&ot_group, &ctx, &type, sizeof(type));
Expand All @@ -149,8 +149,8 @@ otCoapCode otCoapMessageGetCode(const otMessage *aMessage)
struct nrf_rpc_cbor_ctx ctx;
otCoapCode code = 0;

NRF_RPC_CBOR_ALLOC(&ot_group, ctx, 1 + sizeof(ot_msg_key));
nrf_rpc_encode_uint(&ctx, (ot_msg_key)aMessage);
NRF_RPC_CBOR_ALLOC(&ot_group, ctx, 1 + sizeof(ot_rpc_res_tab_key));
nrf_rpc_encode_uint(&ctx, (ot_rpc_res_tab_key)aMessage);

nrf_rpc_cbor_cmd_rsp_no_err(&ot_group, OT_RPC_CMD_COAP_MESSAGE_GET_CODE, &ctx);
nrf_rpc_rsp_decode_uint(&ot_group, &ctx, &code, sizeof(code));
Expand All @@ -164,8 +164,8 @@ uint16_t otCoapMessageGetMessageId(const otMessage *aMessage)
struct nrf_rpc_cbor_ctx ctx;
uint16_t id = 0;

NRF_RPC_CBOR_ALLOC(&ot_group, ctx, 1 + sizeof(ot_msg_key));
nrf_rpc_encode_uint(&ctx, (ot_msg_key)aMessage);
NRF_RPC_CBOR_ALLOC(&ot_group, ctx, 1 + sizeof(ot_rpc_res_tab_key));
nrf_rpc_encode_uint(&ctx, (ot_rpc_res_tab_key)aMessage);

nrf_rpc_cbor_cmd_no_err(&ot_group, OT_RPC_CMD_COAP_MESSAGE_GET_MESSAGE_ID, &ctx,
nrf_rpc_rsp_decode_u16, &id);
Expand All @@ -178,8 +178,8 @@ uint8_t otCoapMessageGetTokenLength(const otMessage *aMessage)
struct nrf_rpc_cbor_ctx ctx;
uint8_t token_length = 0;

NRF_RPC_CBOR_ALLOC(&ot_group, ctx, 1 + sizeof(ot_msg_key));
nrf_rpc_encode_uint(&ctx, (ot_msg_key)aMessage);
NRF_RPC_CBOR_ALLOC(&ot_group, ctx, 1 + sizeof(ot_rpc_res_tab_key));
nrf_rpc_encode_uint(&ctx, (ot_rpc_res_tab_key)aMessage);

nrf_rpc_cbor_cmd_no_err(&ot_group, OT_RPC_CMD_COAP_MESSAGE_GET_TOKEN_LENGTH, &ctx,
nrf_rpc_rsp_decode_u8, &token_length);
Expand All @@ -192,8 +192,8 @@ const uint8_t *otCoapMessageGetToken(const otMessage *aMessage)
struct nrf_rpc_cbor_ctx ctx;
static uint8_t token[OT_COAP_MAX_TOKEN_LENGTH];

NRF_RPC_CBOR_ALLOC(&ot_group, ctx, 1 + sizeof(ot_msg_key));
nrf_rpc_encode_uint(&ctx, (ot_msg_key)aMessage);
NRF_RPC_CBOR_ALLOC(&ot_group, ctx, 1 + sizeof(ot_rpc_res_tab_key));
nrf_rpc_encode_uint(&ctx, (ot_rpc_res_tab_key)aMessage);

nrf_rpc_cbor_cmd_rsp_no_err(&ot_group, OT_RPC_CMD_COAP_MESSAGE_GET_TOKEN, &ctx);

Expand Down Expand Up @@ -370,7 +370,7 @@ void otCoapSetDefaultHandler(otInstance *aInstance, otCoapRequestHandler aHandle
static void ot_rpc_cmd_coap_default_handler(const struct nrf_rpc_group *group,
struct nrf_rpc_cbor_ctx *ctx, void *handler_data)
{
ot_msg_key message_rep;
ot_rpc_res_tab_key message_rep;
otMessageInfo message_info;

message_rep = nrf_rpc_decode_uint(ctx);
Expand Down Expand Up @@ -407,12 +407,12 @@ otError otCoapSendRequestWithParameters(otInstance *aInstance, otMessage *aMessa
return OT_ERROR_NO_BUFS;
}

cbor_buffer_size += 1 + sizeof(ot_msg_key); /* aMessage */
cbor_buffer_size += 1 + sizeof(ot_rpc_res_tab_key); /* aMessage */
cbor_buffer_size += OT_RPC_MESSAGE_INFO_LENGTH(aMessageInfo);
cbor_buffer_size += 1 + sizeof(ot_rpc_coap_request_key);

NRF_RPC_CBOR_ALLOC(&ot_group, ctx, cbor_buffer_size);
nrf_rpc_encode_uint(&ctx, (ot_msg_key)aMessage);
nrf_rpc_encode_uint(&ctx, (ot_rpc_res_tab_key)aMessage);
ot_rpc_encode_message_info(&ctx, aMessageInfo);
nrf_rpc_encode_uint(&ctx, request_rep);
/* Ignore aTXParameters as it is NULL for otCoapSendRequest() that we only need for now */
Expand Down Expand Up @@ -474,11 +474,11 @@ otError otCoapSendResponseWithParameters(otInstance *aInstance, otMessage *aMess
size_t cbor_buffer_size = 0;
otError error = OT_ERROR_PARSE;

cbor_buffer_size += 1 + sizeof(ot_msg_key); /* aMessage */
cbor_buffer_size += 1 + sizeof(ot_rpc_res_tab_key); /* aMessage */
cbor_buffer_size += OT_RPC_MESSAGE_INFO_LENGTH(aMessageInfo);

NRF_RPC_CBOR_ALLOC(&ot_group, ctx, cbor_buffer_size);
nrf_rpc_encode_uint(&ctx, (ot_msg_key)aMessage);
nrf_rpc_encode_uint(&ctx, (ot_rpc_res_tab_key)aMessage);
ot_rpc_encode_message_info(&ctx, aMessageInfo);
/* Ignore aTXParameters as it is NULL for otCoapSendResponse() that we only need for now */
ARG_UNUSED(aTxParameters);
Expand Down
14 changes: 7 additions & 7 deletions subsys/net/openthread/rpc/client/ot_rpc_message.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
otError otMessageAppend(otMessage *aMessage, const void *aBuf, uint16_t aLength)
{
struct nrf_rpc_cbor_ctx ctx;
ot_msg_key key = (ot_msg_key)aMessage;
ot_rpc_res_tab_key key = (ot_rpc_res_tab_key)aMessage;
otError error = OT_ERROR_NONE;

if (aLength == 0 || aBuf == NULL) {
Expand All @@ -39,7 +39,7 @@ otMessage *otUdpNewMessage(otInstance *aInstance, const otMessageSettings *aSett
{
otMessage *msg = NULL;
struct nrf_rpc_cbor_ctx ctx;
ot_msg_key key;
ot_rpc_res_tab_key key;

ARG_UNUSED(aInstance);

Expand All @@ -62,9 +62,9 @@ otMessage *otUdpNewMessage(otInstance *aInstance, const otMessageSettings *aSett
void otMessageFree(otMessage *aMessage)
{
struct nrf_rpc_cbor_ctx ctx;
ot_msg_key key = (ot_msg_key)aMessage;
ot_rpc_res_tab_key key = (ot_rpc_res_tab_key)aMessage;

NRF_RPC_CBOR_ALLOC(&ot_group, ctx, sizeof(ot_msg_key) + 1);
NRF_RPC_CBOR_ALLOC(&ot_group, ctx, sizeof(ot_rpc_res_tab_key) + 1);

nrf_rpc_encode_uint(&ctx, key);
nrf_rpc_cbor_cmd_rsp_no_err(&ot_group, OT_RPC_CMD_MESSAGE_FREE, &ctx);
Expand All @@ -77,7 +77,7 @@ void otMessageFree(otMessage *aMessage)
uint16_t otMessageGetLength(const otMessage *aMessage)
{
struct nrf_rpc_cbor_ctx ctx;
ot_msg_key key = (ot_msg_key)aMessage;
ot_rpc_res_tab_key key = (ot_rpc_res_tab_key)aMessage;
uint16_t ret = 0;

NRF_RPC_CBOR_ALLOC(&ot_group, ctx, sizeof(uint32_t) + 1);
Expand All @@ -98,7 +98,7 @@ uint16_t otMessageGetLength(const otMessage *aMessage)
uint16_t otMessageGetOffset(const otMessage *aMessage)
{
struct nrf_rpc_cbor_ctx ctx;
ot_msg_key key = (ot_msg_key)aMessage;
ot_rpc_res_tab_key key = (ot_rpc_res_tab_key)aMessage;
uint16_t ret = 0;

NRF_RPC_CBOR_ALLOC(&ot_group, ctx, sizeof(uint32_t) + 1);
Expand All @@ -119,7 +119,7 @@ uint16_t otMessageGetOffset(const otMessage *aMessage)
uint16_t otMessageRead(const otMessage *aMessage, uint16_t aOffset, void *aBuf, uint16_t aLength)
{
struct nrf_rpc_cbor_ctx ctx;
ot_msg_key key = (ot_msg_key)aMessage;
ot_rpc_res_tab_key key = (ot_rpc_res_tab_key)aMessage;
size_t size = 0;
const void *buf = NULL;

Expand Down
5 changes: 3 additions & 2 deletions subsys/net/openthread/rpc/client/ot_rpc_netdiag.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,9 @@ otError otThreadGetNextDiagnosticTlv(const otMessage *aMessage, otNetworkDiagIte
struct nrf_rpc_cbor_ctx ctx;
otError error;

NRF_RPC_CBOR_ALLOC(&ot_group, ctx, sizeof(ot_msg_key) + 2 + sizeof(otNetworkDiagIterator));
nrf_rpc_encode_uint(&ctx, (ot_msg_key)aMessage);
NRF_RPC_CBOR_ALLOC(&ot_group, ctx, sizeof(ot_rpc_res_tab_key) + 2 +
sizeof(otNetworkDiagIterator));
nrf_rpc_encode_uint(&ctx, (ot_rpc_res_tab_key)aMessage);
nrf_rpc_encode_uint(&ctx, *aIterator);
nrf_rpc_cbor_cmd_rsp_no_err(&ot_group, OT_RPC_CMD_THREAD_GET_NEXT_DIAGNOSTIC_TLV, &ctx);

Expand Down
4 changes: 2 additions & 2 deletions subsys/net/openthread/rpc/client/ot_rpc_udp.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ static void ot_rpc_cmd_udp_receive_cb(const struct nrf_rpc_group *group,
struct nrf_rpc_cbor_ctx *ctx, void *handler_data)
{
otMessageInfo message_info;
ot_msg_key msg_key = 0;
ot_rpc_res_tab_key msg_key = 0;
ot_socket_key soc_key = 0;
otUdpSocket *socket;

Expand Down Expand Up @@ -143,7 +143,7 @@ otError otUdpSend(otInstance *aInstance, otUdpSocket *aSocket, otMessage *aMessa
{
struct nrf_rpc_cbor_ctx ctx;
ot_socket_key soc_key = (ot_socket_key)aSocket;
ot_msg_key msg_key = (ot_msg_key)aMessage;
ot_rpc_res_tab_key msg_key = (ot_rpc_res_tab_key)aMessage;
otError error = OT_ERROR_NONE;

ARG_UNUSED(aInstance);
Expand Down
4 changes: 2 additions & 2 deletions subsys/net/openthread/rpc/common/ot_rpc_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ enum ot_rpc_link_mode_offsets {
OT_RPC_LINK_MODE_NETWORK_DATA_OFFSET = 2,
};

/** @brief Key type of internal otMesage registry.
/** @brief Key type for internal registry.
*/
typedef uint32_t ot_msg_key;
typedef uint32_t ot_rpc_res_tab_key;

/** @brief Key type of internal otUdpSocket registry.
*/
Expand Down
Loading