Skip to content

Commit 87b1ef6

Browse files
Damian-Nordicnordicjm
authored andcommitted
net: openthread: rpc: add otMessageGetThreadLinkInfo()
Add serialization of otMessageGetThreadLinkInfo() API. Signed-off-by: Damian Krolik <[email protected]>
1 parent 4a662ee commit 87b1ef6

File tree

8 files changed

+114
-6
lines changed

8 files changed

+114
-6
lines changed

doc/nrf/libraries/networking/ot_rpc.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ OpenThread RPC currently supports the serialization of the following OpenThread
131131
* :c:func:`otMessageFree`
132132
* :c:func:`otMessageGetLength`
133133
* :c:func:`otMessageGetOffset`
134+
* :c:func:`otMessageGetThreadLinkInfo`
134135
* :c:func:`otMessageRead`
135136
* :c:func:`otNetDataGet`
136137
* :c:func:`otNetDataGetNextOnMeshPrefix`

samples/nrf_rpc/protocols_serialization/client/src/ot_shell.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -483,18 +483,25 @@ static void handle_udp_receive(void *context, otMessage *message, const otMessag
483483
uint16_t length;
484484
uint16_t offset;
485485
uint16_t read;
486+
otError error;
487+
otThreadLinkInfo link_info;
486488
char buf[128] = {0};
487-
const struct shell *sh = (const struct shell *)context;
489+
const struct shell *sh = context;
488490

489491
offset = otMessageGetOffset(message);
490492
length = otMessageGetLength(message);
493+
error = otMessageGetThreadLinkInfo(message, &link_info);
494+
read = otMessageRead(message, offset, buf, MIN(length, sizeof(buf)));
491495

492-
read = otMessageRead(message, offset, buf, length);
496+
shell_print(sh, "Received UDP message");
497+
shell_hexdump(sh, buf, read);
493498

494-
if (read > 0) {
495-
shell_print(sh, "RECEIVED: '%s'", buf);
496-
} else {
497-
shell_print(sh, "message empty");
499+
if (error == OT_ERROR_NONE) {
500+
shell_print(sh, "PAN ID: %x", link_info.mPanId);
501+
shell_print(sh, "Channel: %u", link_info.mChannel);
502+
shell_print(sh, "RSS: %d", link_info.mRss);
503+
shell_print(sh, "LQI: %u", link_info.mLqi);
504+
shell_print(sh, "Link security: %c", link_info.mLinkSecurity ? 'y' : 'n');
498505
}
499506
}
500507

subsys/net/openthread/rpc/client/ot_rpc_message.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,3 +148,35 @@ uint16_t otMessageRead(const otMessage *aMessage, uint16_t aOffset, void *aBuf,
148148

149149
return MIN(size, aLength);
150150
}
151+
152+
otError otMessageGetThreadLinkInfo(const otMessage *aMessage, otThreadLinkInfo *aLinkInfo)
153+
{
154+
ot_rpc_res_tab_key key = (ot_rpc_res_tab_key)aMessage;
155+
struct nrf_rpc_cbor_ctx ctx;
156+
otError error;
157+
158+
NRF_RPC_CBOR_ALLOC(&ot_group, ctx, 1 + sizeof(key));
159+
nrf_rpc_encode_uint(&ctx, key);
160+
nrf_rpc_cbor_cmd_rsp_no_err(&ot_group, OT_RPC_CMD_MESSAGE_GET_THREAD_LINK_INFO, &ctx);
161+
162+
error = nrf_rpc_decode_uint(&ctx);
163+
164+
if (nrf_rpc_decode_valid(&ctx) && error == OT_ERROR_NONE) {
165+
aLinkInfo->mPanId = nrf_rpc_decode_uint(&ctx);
166+
aLinkInfo->mChannel = nrf_rpc_decode_uint(&ctx);
167+
aLinkInfo->mRss = nrf_rpc_decode_int(&ctx);
168+
aLinkInfo->mLqi = nrf_rpc_decode_uint(&ctx);
169+
aLinkInfo->mLinkSecurity = nrf_rpc_decode_bool(&ctx);
170+
aLinkInfo->mIsDstPanIdBroadcast = nrf_rpc_decode_bool(&ctx);
171+
aLinkInfo->mTimeSyncSeq = nrf_rpc_decode_uint(&ctx);
172+
aLinkInfo->mNetworkTimeOffset = nrf_rpc_decode_int64(&ctx);
173+
aLinkInfo->mRadioType = nrf_rpc_decode_uint(&ctx);
174+
}
175+
176+
if (!nrf_rpc_decoding_done_and_check(&ot_group, &ctx)) {
177+
ot_rpc_report_rsp_decoding_error(OT_RPC_CMD_MESSAGE_GET_THREAD_LINK_INFO);
178+
return OT_ERROR_NOT_FOUND;
179+
}
180+
181+
return error;
182+
}

subsys/net/openthread/rpc/common/ot_rpc_ids.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ enum ot_rpc_cmd_server {
9999
OT_RPC_CMD_MESSAGE_GET_LENGTH,
100100
OT_RPC_CMD_MESSAGE_GET_OFFSET,
101101
OT_RPC_CMD_MESSAGE_READ,
102+
OT_RPC_CMD_MESSAGE_GET_THREAD_LINK_INFO,
102103
OT_RPC_CMD_UDP_OPEN,
103104
OT_RPC_CMD_UDP_SEND,
104105
OT_RPC_CMD_UDP_BIND,

subsys/net/openthread/rpc/server/ot_rpc_message.c

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,66 @@ static void ot_rpc_msg_read(const struct nrf_rpc_group *group, struct nrf_rpc_cb
213213
nrf_rpc_cbor_rsp_no_err(group, &rsp_ctx);
214214
}
215215

216+
static void ot_rpc_msg_get_thread_link_info(const struct nrf_rpc_group *group,
217+
struct nrf_rpc_cbor_ctx *ctx, void *handler_data)
218+
{
219+
ot_rpc_res_tab_key key;
220+
otMessage *message;
221+
otThreadLinkInfo link_info;
222+
otError error;
223+
size_t cbor_buffer_size;
224+
struct nrf_rpc_cbor_ctx rsp_ctx;
225+
226+
key = nrf_rpc_decode_uint(ctx);
227+
228+
if (!nrf_rpc_decoding_done_and_check(group, ctx)) {
229+
ot_rpc_report_cmd_decoding_error(OT_RPC_CMD_MESSAGE_GET_THREAD_LINK_INFO);
230+
return;
231+
}
232+
233+
message = ot_res_tab_msg_get(key);
234+
235+
if (!message) {
236+
ot_rpc_report_cmd_decoding_error(OT_RPC_CMD_MESSAGE_GET_THREAD_LINK_INFO);
237+
return;
238+
}
239+
240+
openthread_api_mutex_lock(openthread_get_default_context());
241+
error = otMessageGetThreadLinkInfo(message, &link_info);
242+
openthread_api_mutex_unlock(openthread_get_default_context());
243+
244+
cbor_buffer_size = 1;
245+
246+
if (error == OT_ERROR_NONE) {
247+
cbor_buffer_size += 1 + sizeof(link_info.mPanId);
248+
cbor_buffer_size += 1 + sizeof(link_info.mChannel);
249+
cbor_buffer_size += 1 + sizeof(link_info.mRss);
250+
cbor_buffer_size += 1 + sizeof(link_info.mLqi);
251+
cbor_buffer_size += 2; /* mLinkSecurity + mIsDstPanIdBroadcast */
252+
cbor_buffer_size += 1 + sizeof(link_info.mTimeSyncSeq);
253+
cbor_buffer_size += 1 + sizeof(link_info.mNetworkTimeOffset);
254+
cbor_buffer_size += 1 + sizeof(link_info.mRadioType);
255+
}
256+
257+
NRF_RPC_CBOR_ALLOC(group, rsp_ctx, cbor_buffer_size);
258+
259+
nrf_rpc_encode_uint(&rsp_ctx, error);
260+
261+
if (error == OT_ERROR_NONE) {
262+
nrf_rpc_encode_uint(&rsp_ctx, link_info.mPanId);
263+
nrf_rpc_encode_uint(&rsp_ctx, link_info.mChannel);
264+
nrf_rpc_encode_int(&rsp_ctx, link_info.mRss);
265+
nrf_rpc_encode_uint(&rsp_ctx, link_info.mLqi);
266+
nrf_rpc_encode_bool(&rsp_ctx, link_info.mLinkSecurity);
267+
nrf_rpc_encode_bool(&rsp_ctx, link_info.mIsDstPanIdBroadcast);
268+
nrf_rpc_encode_uint(&rsp_ctx, link_info.mTimeSyncSeq);
269+
nrf_rpc_encode_int64(&rsp_ctx, link_info.mNetworkTimeOffset);
270+
nrf_rpc_encode_uint(&rsp_ctx, link_info.mRadioType);
271+
}
272+
273+
nrf_rpc_cbor_rsp_no_err(group, &rsp_ctx);
274+
}
275+
216276
NRF_RPC_CBOR_CMD_DECODER(ot_group, ot_rpc_msg_length, OT_RPC_CMD_MESSAGE_GET_LENGTH,
217277
ot_rpc_msg_length, NULL);
218278

@@ -228,3 +288,7 @@ NRF_RPC_CBOR_CMD_DECODER(ot_group, ot_rpc_msg_udp_new, OT_RPC_CMD_UDP_NEW_MESSAG
228288

229289
NRF_RPC_CBOR_CMD_DECODER(ot_group, ot_rpc_msg_append, OT_RPC_CMD_MESSAGE_APPEND, ot_rpc_msg_append,
230290
NULL);
291+
292+
NRF_RPC_CBOR_CMD_DECODER(ot_group, ot_rpc_msg_get_thread_link_info,
293+
OT_RPC_CMD_MESSAGE_GET_THREAD_LINK_INFO, ot_rpc_msg_get_thread_link_info,
294+
NULL);

tests/subsys/net/openthread/rpc/server/src/common_fakes.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
DEFINE_FAKE_VALUE_FUNC(uint16_t, otMessageGetLength, const otMessage *);
1010
DEFINE_FAKE_VALUE_FUNC(uint16_t, otMessageGetOffset, const otMessage *);
11+
DEFINE_FAKE_VALUE_FUNC(otError, otMessageGetThreadLinkInfo, const otMessage *, otThreadLinkInfo *);
1112
DEFINE_FAKE_VALUE_FUNC(uint16_t, otMessageRead, const otMessage *, uint16_t, void *, uint16_t);
1213
DEFINE_FAKE_VOID_FUNC(otMessageFree, otMessage *);
1314
DEFINE_FAKE_VALUE_FUNC(otError, otMessageAppend, otMessage *, const void *, uint16_t);

tests/subsys/net/openthread/rpc/server/src/common_fakes.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
DECLARE_FAKE_VALUE_FUNC(otMessage *, otUdpNewMessage, otInstance *, const otMessageSettings *);
1313
DECLARE_FAKE_VALUE_FUNC(uint16_t, otMessageGetLength, const otMessage *);
1414
DECLARE_FAKE_VALUE_FUNC(uint16_t, otMessageGetOffset, const otMessage *);
15+
DECLARE_FAKE_VALUE_FUNC(otError, otMessageGetThreadLinkInfo, const otMessage *, otThreadLinkInfo *);
1516
DECLARE_FAKE_VALUE_FUNC(uint16_t, otMessageRead, const otMessage *, uint16_t, void *, uint16_t);
1617
DECLARE_FAKE_VOID_FUNC(otMessageFree, otMessage *);
1718
DECLARE_FAKE_VALUE_FUNC(otError, otMessageAppend, otMessage *, const void *, uint16_t);

tests/subsys/net/openthread/rpc/server/src/message_suite.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ static void nrf_rpc_err_handler(const struct nrf_rpc_err_report *report)
2828
#define FOREACH_FAKE(f) \
2929
f(otMessageGetLength); \
3030
f(otMessageGetOffset); \
31+
f(otMessageGetThreadLinkInfo); \
3132
f(otMessageRead); \
3233
f(otMessageFree); \
3334
f(otMessageAppend); \

0 commit comments

Comments
 (0)