Skip to content

Commit feda9df

Browse files
Damian-Nordicrlubos
authored andcommitted
net: openthread: rpc: extract Zephyr dependencies in client
Make OpenThread RPC client more portable by minimizing the number of source files that reference Zephyr API directly. This has been achieved by adding intermediate header files: ot_rpc_macros.h and ot_rpc_os.h to the client library and extracting Zephyr-dependent code to the latter. Signed-off-by: Damian Krolik <[email protected]>
1 parent 2b3cfd6 commit feda9df

18 files changed

+178
-128
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
55
*/
66

7-
#include <ot_rpc_ids.h>
87
#include <ot_rpc_common.h>
8+
#include <ot_rpc_ids.h>
99
#include <ot_rpc_lock.h>
10+
#include <ot_rpc_macros.h>
1011
#include <nrf_rpc/nrf_rpc_serialize.h>
1112
#include <nrf_rpc_cbor.h>
1213

@@ -22,7 +23,7 @@ void otCliInit(otInstance *aInstance, otCliOutputCallback aCallback, void *aCont
2223
const size_t cbor_buffer_size = 0;
2324
struct nrf_rpc_cbor_ctx ctx;
2425

25-
ARG_UNUSED(aInstance);
26+
OT_RPC_UNUSED(aInstance);
2627
cli_output_callback = aCallback;
2728
cli_output_context = aContext;
2829

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <ot_rpc_ids.h>
88
#include <ot_rpc_coap.h>
99
#include <ot_rpc_common.h>
10+
#include <ot_rpc_macros.h>
1011
#include <ot_rpc_types.h>
1112
#include <ot_rpc_lock.h>
1213
#include <nrf_rpc/nrf_rpc_serialize.h>
@@ -28,7 +29,7 @@ static struct ot_rpc_coap_request requests[CONFIG_OPENTHREAD_RPC_CLIENT_NUM_SENT
2829
static ot_rpc_coap_request_key ot_rpc_coap_request_alloc(otCoapResponseHandler handler,
2930
void *context)
3031
{
31-
for (ot_rpc_coap_request_key i = 0; i < ARRAY_SIZE(requests); i++) {
32+
for (ot_rpc_coap_request_key i = 0; i < OT_RPC_ARRAY_SIZE(requests); i++) {
3233
if (requests[i].handler == NULL) {
3334
requests[i].handler = handler;
3435
requests[i].context = context;
@@ -422,7 +423,7 @@ otError otCoapSendRequestWithParameters(otInstance *aInstance, otMessage *aMessa
422423
ot_rpc_encode_message_info(&ctx, aMessageInfo);
423424
nrf_rpc_encode_uint(&ctx, request_rep);
424425
/* Ignore aTXParameters as it is NULL for otCoapSendRequest() that we only need for now */
425-
ARG_UNUSED(aTxParameters);
426+
OT_RPC_UNUSED(aTxParameters);
426427

427428
nrf_rpc_cbor_cmd_no_err(&ot_group, OT_RPC_CMD_COAP_SEND_REQUEST, &ctx, ot_rpc_decode_error,
428429
&error);
@@ -454,7 +455,7 @@ static void ot_rpc_cmd_coap_response_handler(const struct nrf_rpc_group *group,
454455
return;
455456
}
456457

457-
if (request_rep == 0 || request_rep > ARRAY_SIZE(requests)) {
458+
if (request_rep == 0 || request_rep > OT_RPC_ARRAY_SIZE(requests)) {
458459
ot_rpc_report_cmd_decoding_error(OT_RPC_CMD_COAP_RESPONSE_HANDLER);
459460
return;
460461
}
@@ -489,7 +490,7 @@ otError otCoapSendResponseWithParameters(otInstance *aInstance, otMessage *aMess
489490
nrf_rpc_encode_uint(&ctx, (ot_rpc_res_tab_key)aMessage);
490491
ot_rpc_encode_message_info(&ctx, aMessageInfo);
491492
/* Ignore aTXParameters as it is NULL for otCoapSendResponse() that we only need for now */
492-
ARG_UNUSED(aTxParameters);
493+
OT_RPC_UNUSED(aTxParameters);
493494

494495
nrf_rpc_cbor_cmd_no_err(&ot_group, OT_RPC_CMD_COAP_SEND_RESPONSE, &ctx, ot_rpc_decode_error,
495496
&error);

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

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#include <ot_rpc_ids.h>
88
#include <ot_rpc_types.h>
99
#include <ot_rpc_common.h>
10+
#include <ot_rpc_macros.h>
11+
#include <ot_rpc_os.h>
1012

1113
#include <nrf_rpc/nrf_rpc_serialize.h>
1214

@@ -15,7 +17,7 @@ bool otDatasetIsCommissioned(otInstance *aInstance)
1517
struct nrf_rpc_cbor_ctx ctx;
1618
bool result;
1719

18-
ARG_UNUSED(aInstance);
20+
OT_RPC_UNUSED(aInstance);
1921

2022
NRF_RPC_CBOR_ALLOC(&ot_group, ctx, 0);
2123

@@ -30,7 +32,7 @@ static otError ot_rpc_dataset_set_tlvs(uint8_t cmd, const otOperationalDatasetTl
3032
struct nrf_rpc_cbor_ctx ctx;
3133
otError error;
3234

33-
__ASSERT_NO_MSG(dataset);
35+
OT_RPC_ASSERT(dataset);
3436

3537
if (dataset->mLength > OT_OPERATIONAL_DATASET_MAX_LENGTH) {
3638
return OT_ERROR_INVALID_ARGS;
@@ -47,7 +49,7 @@ static otError ot_rpc_dataset_get_tlvs(uint8_t cmd, otOperationalDatasetTlvs *da
4749
{
4850
struct nrf_rpc_cbor_ctx ctx;
4951

50-
__ASSERT_NO_MSG(dataset);
52+
OT_RPC_ASSERT(dataset);
5153

5254
NRF_RPC_CBOR_ALLOC(&ot_group, ctx, 0);
5355
nrf_rpc_cbor_cmd_no_err(&ot_group, cmd, &ctx, ot_rpc_decode_dataset_tlvs, &dataset);
@@ -60,7 +62,7 @@ static otError ot_rpc_dataset_set(uint8_t cmd, const otOperationalDataset *datas
6062
struct nrf_rpc_cbor_ctx ctx;
6163
otError error;
6264

63-
__ASSERT_NO_MSG(dataset);
65+
OT_RPC_ASSERT(dataset);
6466

6567
NRF_RPC_CBOR_ALLOC(&ot_group, ctx, OPERATIONAL_DATASET_LENGTH(dataset));
6668
ot_rpc_encode_dataset(&ctx, dataset);
@@ -73,7 +75,7 @@ static otError ot_rpc_dataset_get(uint8_t cmd, otOperationalDataset *dataset)
7375
{
7476
struct nrf_rpc_cbor_ctx ctx;
7577

76-
__ASSERT_NO_MSG(dataset);
78+
OT_RPC_ASSERT(dataset);
7779

7880
NRF_RPC_CBOR_ALLOC(&ot_group, ctx, 0);
7981
nrf_rpc_cbor_cmd_no_err(&ot_group, cmd, &ctx, ot_rpc_decode_dataset, &dataset);
@@ -83,56 +85,56 @@ static otError ot_rpc_dataset_get(uint8_t cmd, otOperationalDataset *dataset)
8385

8486
otError otDatasetSetActiveTlvs(otInstance *aInstance, const otOperationalDatasetTlvs *aDataset)
8587
{
86-
ARG_UNUSED(aInstance);
88+
OT_RPC_UNUSED(aInstance);
8789

8890
return ot_rpc_dataset_set_tlvs(OT_RPC_CMD_DATASET_SET_ACTIVE_TLVS, aDataset);
8991
}
9092

9193
otError otDatasetGetActiveTlvs(otInstance *aInstance, otOperationalDatasetTlvs *aDataset)
9294
{
93-
ARG_UNUSED(aInstance);
95+
OT_RPC_UNUSED(aInstance);
9496

9597
return ot_rpc_dataset_get_tlvs(OT_RPC_CMD_DATASET_GET_ACTIVE_TLVS, aDataset);
9698
}
9799

98100
otError otDatasetSetActive(otInstance *aInstance, const otOperationalDataset *aDataset)
99101
{
100-
ARG_UNUSED(aInstance);
102+
OT_RPC_UNUSED(aInstance);
101103

102104
return ot_rpc_dataset_set(OT_RPC_CMD_DATASET_SET_ACTIVE, aDataset);
103105
}
104106

105107
otError otDatasetGetActive(otInstance *aInstance, otOperationalDataset *aDataset)
106108
{
107-
ARG_UNUSED(aInstance);
109+
OT_RPC_UNUSED(aInstance);
108110

109111
return ot_rpc_dataset_get(OT_RPC_CMD_DATASET_GET_ACTIVE, aDataset);
110112
}
111113

112114
otError otDatasetSetPendingTlvs(otInstance *aInstance, const otOperationalDatasetTlvs *aDataset)
113115
{
114-
ARG_UNUSED(aInstance);
116+
OT_RPC_UNUSED(aInstance);
115117

116118
return ot_rpc_dataset_set_tlvs(OT_RPC_CMD_DATASET_SET_PENDING_TLVS, aDataset);
117119
}
118120

119121
otError otDatasetGetPendingTlvs(otInstance *aInstance, otOperationalDatasetTlvs *aDataset)
120122
{
121-
ARG_UNUSED(aInstance);
123+
OT_RPC_UNUSED(aInstance);
122124

123125
return ot_rpc_dataset_get_tlvs(OT_RPC_CMD_DATASET_GET_PENDING_TLVS, aDataset);
124126
}
125127

126128
otError otDatasetSetPending(otInstance *aInstance, const otOperationalDataset *aDataset)
127129
{
128-
ARG_UNUSED(aInstance);
130+
OT_RPC_UNUSED(aInstance);
129131

130132
return ot_rpc_dataset_set(OT_RPC_CMD_DATASET_SET_PENDING, aDataset);
131133
}
132134

133135
otError otDatasetGetPending(otInstance *aInstance, otOperationalDataset *aDataset)
134136
{
135-
ARG_UNUSED(aInstance);
137+
OT_RPC_UNUSED(aInstance);
136138

137139
return ot_rpc_dataset_get(OT_RPC_CMD_DATASET_GET_PENDING, aDataset);
138140
}

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,8 @@
1414
#include <openthread/instance.h>
1515
#include <openthread/link.h>
1616
#include <openthread/thread.h>
17-
#include <zephyr/logging/log.h>
1817

1918
NRF_RPC_GROUP_DECLARE(ot_group);
20-
LOG_MODULE_DECLARE(ot_rpc, LOG_LEVEL_DBG);
2119

2220
static char version[256];
2321
static otExtAddress mac = {.m8 = {0xF4, 0xCE, 0x36, 0x24, 0x95, 0x6A, 0xD1, 0xD0}};
@@ -87,7 +85,6 @@ const otExtAddress *otLinkGetExtendedAddress(otInstance *aInstance)
8785
int ret_size = get_string(OT_RPC_CMD_LINK_GET_EXTENDED_ADDRESS, mac.m8, sizeof(mac.m8));
8886

8987
if (ret_size != sizeof(mac.m8)) {
90-
LOG_ERR("Received mac addr size is too short");
9188
ot_rpc_report_rsp_decoding_error(OT_RPC_CMD_LINK_GET_EXTENDED_ADDRESS);
9289
}
9390

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
#include <nrf_rpc_cbor.h>
1111
#include <ot_rpc_common.h>
1212
#include <ot_rpc_ids.h>
13-
#include <ot_rpc_common.h>
1413
#include <ot_rpc_lock.h>
14+
#include <ot_rpc_macros.h>
1515

1616
static otDnsQueryConfig default_config;
1717

@@ -20,7 +20,7 @@ const otDnsQueryConfig *otDnsClientGetDefaultConfig(otInstance *aInstance)
2020
struct nrf_rpc_cbor_ctx ctx;
2121
bool config_decoded;
2222

23-
ARG_UNUSED(aInstance);
23+
OT_RPC_UNUSED(aInstance);
2424

2525
NRF_RPC_CBOR_ALLOC(&ot_group, ctx, 0);
2626

@@ -39,7 +39,7 @@ void otDnsClientSetDefaultConfig(otInstance *aInstance, const otDnsQueryConfig *
3939
{
4040
struct nrf_rpc_cbor_ctx ctx;
4141

42-
ARG_UNUSED(aInstance);
42+
OT_RPC_UNUSED(aInstance);
4343

4444
NRF_RPC_CBOR_ALLOC(&ot_group, ctx, OT_RPC_DNS_QUERY_CONFIG_SIZE);
4545

@@ -262,7 +262,7 @@ otError otDnsClientResolveAddress(otInstance *aInstance, const char *aHostName,
262262
otDnsAddressCallback aCallback, void *aContext,
263263
const otDnsQueryConfig *aConfig)
264264
{
265-
ARG_UNUSED(aInstance);
265+
OT_RPC_UNUSED(aInstance);
266266

267267
return resolve_or_browse(OT_RPC_CMD_DNS_CLIENT_RESOLVE_ADDRESS, aHostName, NULL, aCallback,
268268
aContext, aConfig);
@@ -272,7 +272,7 @@ otError otDnsClientResolveIp4Address(otInstance *aInstance, const char *aHostNam
272272
otDnsAddressCallback aCallback, void *aContext,
273273
const otDnsQueryConfig *aConfig)
274274
{
275-
ARG_UNUSED(aInstance);
275+
OT_RPC_UNUSED(aInstance);
276276

277277
return resolve_or_browse(OT_RPC_CMD_DNS_CLIENT_RESOLVE_IP4_ADDRESS, aHostName, NULL,
278278
aCallback, aContext, aConfig);
@@ -298,7 +298,7 @@ otError otDnsClientBrowse(otInstance *aInstance, const char *aServiceName,
298298
otDnsBrowseCallback aCallback, void *aContext,
299299
const otDnsQueryConfig *aConfig)
300300
{
301-
ARG_UNUSED(aInstance);
301+
OT_RPC_UNUSED(aInstance);
302302

303303
return resolve_or_browse(OT_RPC_CMD_DNS_CLIENT_BROWSE, aServiceName, NULL, aCallback,
304304
aContext, aConfig);
@@ -343,7 +343,7 @@ otError otDnsClientResolveService(otInstance *aInstance, const char *aInstanceLa
343343
const char *aServiceName, otDnsServiceCallback aCallback,
344344
void *aContext, const otDnsQueryConfig *aConfig)
345345
{
346-
ARG_UNUSED(aInstance);
346+
OT_RPC_UNUSED(aInstance);
347347

348348
return resolve_or_browse(OT_RPC_CMD_DNS_CLIENT_RESOLVE_SERVICE, aInstanceLabel,
349349
aServiceName, aCallback, aContext, aConfig);
@@ -354,7 +354,7 @@ otError otDnsClientResolveServiceAndHostAddress(otInstance *aInstance, const cha
354354
otDnsServiceCallback aCallback, void *aContext,
355355
const otDnsQueryConfig *aConfig)
356356
{
357-
ARG_UNUSED(aInstance);
357+
OT_RPC_UNUSED(aInstance);
358358

359359
return resolve_or_browse(OT_RPC_CMD_DNS_CLIENT_RESOLVE_SERVICE_AND_HOST_ADDRESS,
360360
aInstanceLabel, aServiceName, aCallback, aContext, aConfig);

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include <ot_rpc_ids.h>
88
#include <ot_rpc_common.h>
9+
#include <ot_rpc_macros.h>
910
#include <nrf_rpc/nrf_rpc_serialize.h>
1011
#include <nrf_rpc_cbor.h>
1112

@@ -24,15 +25,15 @@ struct ot_rpc_l2_data {
2425

2526
static enum net_verdict ot_rpc_l2_recv(struct net_if *iface, struct net_pkt *pkt)
2627
{
27-
ARG_UNUSED(iface);
28-
ARG_UNUSED(pkt);
28+
OT_RPC_UNUSED(iface);
29+
OT_RPC_UNUSED(pkt);
2930

3031
return NET_CONTINUE;
3132
}
3233

3334
static int ot_rpc_l2_send(struct net_if *iface, struct net_pkt *pkt)
3435
{
35-
ARG_UNUSED(iface);
36+
OT_RPC_UNUSED(iface);
3637

3738
bool encoded_ok = false;
3839
const size_t len = net_pkt_get_len(pkt);

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <ot_rpc_ids.h>
88
#include <ot_rpc_common.h>
99
#include <ot_rpc_lock.h>
10+
#include <ot_rpc_macros.h>
1011
#include <nrf_rpc/nrf_rpc_serialize.h>
1112

1213
#include <nrf_rpc_cbor.h>
@@ -37,7 +38,7 @@ uint32_t otInstanceGetId(otInstance *aInstance)
3738
struct nrf_rpc_cbor_ctx ctx;
3839
uint32_t id;
3940

40-
ARG_UNUSED(aInstance);
41+
OT_RPC_UNUSED(aInstance);
4142

4243
NRF_RPC_CBOR_ALLOC(&ot_group, ctx, 0);
4344
nrf_rpc_cbor_cmd_no_err(&ot_group, OT_RPC_CMD_INSTANCE_GET_ID, &ctx, nrf_rpc_rsp_decode_u32,
@@ -51,7 +52,7 @@ bool otInstanceIsInitialized(otInstance *aInstance)
5152
struct nrf_rpc_cbor_ctx ctx;
5253
bool initialized;
5354

54-
ARG_UNUSED(aInstance);
55+
OT_RPC_UNUSED(aInstance);
5556

5657
NRF_RPC_CBOR_ALLOC(&ot_group, ctx, 0);
5758
nrf_rpc_cbor_cmd_no_err(&ot_group, OT_RPC_CMD_INSTANCE_IS_INITIALIZED, &ctx,
@@ -64,7 +65,7 @@ void otInstanceFinalize(otInstance *aInstance)
6465
{
6566
struct nrf_rpc_cbor_ctx ctx;
6667

67-
ARG_UNUSED(aInstance);
68+
OT_RPC_UNUSED(aInstance);
6869

6970
NRF_RPC_CBOR_ALLOC(&ot_group, ctx, 0);
7071
nrf_rpc_cbor_cmd_no_err(&ot_group, OT_RPC_CMD_INSTANCE_FINALIZE, &ctx,
@@ -76,7 +77,7 @@ otError otInstanceErasePersistentInfo(otInstance *aInstance)
7677
struct nrf_rpc_cbor_ctx ctx;
7778
otError error;
7879

79-
ARG_UNUSED(aInstance);
80+
OT_RPC_UNUSED(aInstance);
8081

8182
NRF_RPC_CBOR_ALLOC(&ot_group, ctx, 0);
8283
nrf_rpc_cbor_cmd_no_err(&ot_group, OT_RPC_CMD_INSTANCE_ERASE_PERSISTENT_INFO, &ctx,
@@ -89,7 +90,7 @@ void otInstanceFactoryReset(otInstance *aInstance)
8990
{
9091
struct nrf_rpc_cbor_ctx ctx;
9192

92-
ARG_UNUSED(aInstance);
93+
OT_RPC_UNUSED(aInstance);
9394

9495
NRF_RPC_CBOR_ALLOC(&ot_group, ctx, 0);
9596
nrf_rpc_cbor_cmd_no_err(&ot_group, OT_RPC_CMD_INSTANCE_FACTORY_RESET, &ctx,
@@ -103,7 +104,7 @@ otError otSetStateChangedCallback(otInstance *aInstance, otStateChangedCallback
103104
struct nrf_rpc_cbor_ctx ctx;
104105
otError error;
105106

106-
ARG_UNUSED(aInstance);
107+
OT_RPC_UNUSED(aInstance);
107108

108109
NRF_RPC_CBOR_ALLOC(&ot_group, ctx, cbor_buffer_size);
109110
/* TODO: implement callback & address pseudonymization. */
@@ -122,7 +123,7 @@ void otRemoveStateChangeCallback(otInstance *aInstance, otStateChangedCallback a
122123
const size_t cbor_buffer_size = 10;
123124
struct nrf_rpc_cbor_ctx ctx;
124125

125-
ARG_UNUSED(aInstance);
126+
OT_RPC_UNUSED(aInstance);
126127

127128
NRF_RPC_CBOR_ALLOC(&ot_group, ctx, cbor_buffer_size);
128129
/* TODO: implement callback & address pseudonymization. */

0 commit comments

Comments
 (0)