Skip to content

Commit e9205f9

Browse files
kderdarlubos
authored andcommitted
net: openthread: rpc: update SRP client's RPC client side
This commit updates previously implemented functions and adds new ones. Signed-off-by: Konrad Derda <[email protected]>
1 parent 0c93bee commit e9205f9

File tree

1 file changed

+203
-4
lines changed

1 file changed

+203
-4
lines changed

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

Lines changed: 203 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ static otSrpClientAutoStartCallback auto_start_cb;
2626
static void *auto_start_ctx;
2727
static otSrpClientCallback client_cb;
2828
static void *client_ctx;
29+
static otSockAddr decoded_server_sockaddr;
2930

3031
static void clear_host(void)
3132
{
@@ -74,22 +75,109 @@ static void calc_txt_space(const otDnsTxtEntry *txt, uint8_t num, size_t *out_cb
7475
*out_cbor_size = cbor_size;
7576
}
7677

78+
const char *otSrpClientItemStateToString(otSrpClientItemState state)
79+
{
80+
switch (state) {
81+
case OT_SRP_CLIENT_ITEM_STATE_TO_ADD:
82+
return "ToAdd";
83+
case OT_SRP_CLIENT_ITEM_STATE_ADDING:
84+
return "Adding";
85+
case OT_SRP_CLIENT_ITEM_STATE_TO_REFRESH:
86+
return "ToRefresh";
87+
case OT_SRP_CLIENT_ITEM_STATE_REFRESHING:
88+
return "Refreshing";
89+
case OT_SRP_CLIENT_ITEM_STATE_TO_REMOVE:
90+
return "ToRemove";
91+
case OT_SRP_CLIENT_ITEM_STATE_REMOVING:
92+
return "Removing";
93+
case OT_SRP_CLIENT_ITEM_STATE_REGISTERED:
94+
return "Registered";
95+
case OT_SRP_CLIENT_ITEM_STATE_REMOVED:
96+
return "Removed";
97+
};
98+
99+
return "Unknown";
100+
}
101+
102+
otError otSrpClientStart(otInstance *aInstance, const otSockAddr *aServerSockAddr)
103+
{
104+
otError error;
105+
struct nrf_rpc_cbor_ctx ctx;
106+
107+
ARG_UNUSED(aInstance);
108+
109+
NRF_RPC_CBOR_ALLOC(&ot_group, ctx, OT_IP6_ADDRESS_SIZE + sizeof(uint16_t) + 2);
110+
111+
ot_rpc_encode_sockaddr(&ctx, aServerSockAddr);
112+
113+
nrf_rpc_cbor_cmd_no_err(&ot_group, OT_RPC_CMD_SRP_CLIENT_START, &ctx,
114+
ot_rpc_decode_error, &error);
115+
116+
return error;
117+
}
118+
119+
void otSrpClientStop(otInstance *aInstance)
120+
{
121+
struct nrf_rpc_cbor_ctx ctx;
122+
123+
ARG_UNUSED(aInstance);
124+
125+
NRF_RPC_CBOR_ALLOC(&ot_group, ctx, 0);
126+
127+
nrf_rpc_cbor_cmd_no_err(&ot_group, OT_RPC_CMD_SRP_CLIENT_STOP, &ctx,
128+
nrf_rpc_rsp_decode_void, NULL);
129+
}
130+
131+
bool otSrpClientIsRunning(otInstance *aInstance)
132+
{
133+
struct nrf_rpc_cbor_ctx ctx;
134+
bool running;
135+
136+
ARG_UNUSED(aInstance);
137+
138+
NRF_RPC_CBOR_ALLOC(&ot_group, ctx, 0);
139+
140+
nrf_rpc_cbor_cmd_no_err(&ot_group, OT_RPC_CMD_SRP_CLIENT_IS_RUNNING, &ctx,
141+
nrf_rpc_rsp_decode_bool, &running);
142+
143+
return running;
144+
}
145+
146+
const otSockAddr *otSrpClientGetServerAddress(otInstance *aInstance)
147+
{
148+
struct nrf_rpc_cbor_ctx ctx;
149+
150+
ARG_UNUSED(aInstance);
151+
152+
NRF_RPC_CBOR_ALLOC(&ot_group, ctx, 0);
153+
154+
nrf_rpc_cbor_cmd_rsp_no_err(&ot_group, OT_RPC_CMD_SRP_CLIENT_GET_SERVER_ADDRESS, &ctx);
155+
156+
ot_rpc_decode_sockaddr(&ctx, &decoded_server_sockaddr);
157+
158+
nrf_rpc_cbor_decoding_done(&ot_group, &ctx);
159+
160+
return &decoded_server_sockaddr;
161+
}
162+
77163
otError otSrpClientAddService(otInstance *aInstance, otSrpClientService *aService)
78164
{
79165
struct nrf_rpc_cbor_ctx ctx;
80166
size_t num_subtypes;
81167
size_t subtypes_size;
82168
size_t txt_size;
83169
size_t cbor_buffer_size;
170+
size_t name_len = strlen(aService->mName);
171+
size_t instance_len = strlen(aService->mInstanceName);
84172
otError error;
85173

86174
ARG_UNUSED(aInstance);
87175
calc_subtypes_space(aService->mSubTypeLabels, &num_subtypes, &subtypes_size);
88176
calc_txt_space(aService->mTxtEntries, aService->mNumTxtEntries, &txt_size);
89177

90178
cbor_buffer_size = 1 + sizeof(uintptr_t); /* Service pointer */
91-
cbor_buffer_size += 2 + strlen(aService->mName);
92-
cbor_buffer_size += 2 + strlen(aService->mInstanceName);
179+
cbor_buffer_size += 2 + name_len;
180+
cbor_buffer_size += 2 + instance_len;
93181
cbor_buffer_size += 1 + subtypes_size; /* Array of service subtypes */
94182
cbor_buffer_size += 1 + txt_size; /* Map of TXT entries */
95183
cbor_buffer_size += 1 + sizeof(aService->mPort);
@@ -100,8 +188,15 @@ otError otSrpClientAddService(otInstance *aInstance, otSrpClientService *aServic
100188

101189
NRF_RPC_CBOR_ALLOC(&ot_group, ctx, cbor_buffer_size);
102190
nrf_rpc_encode_uint(&ctx, (uintptr_t)aService);
103-
nrf_rpc_encode_str(&ctx, aService->mName, -1);
104-
nrf_rpc_encode_str(&ctx, aService->mInstanceName, -1);
191+
nrf_rpc_encode_uint(&ctx, num_subtypes);
192+
nrf_rpc_encode_uint(&ctx, aService->mNumTxtEntries);
193+
nrf_rpc_encode_uint(&ctx, name_len + instance_len + 2);
194+
nrf_rpc_encode_uint(&ctx, subtypes_size);
195+
nrf_rpc_encode_uint(&ctx, txt_size);
196+
197+
nrf_rpc_encode_str(&ctx, aService->mName, name_len);
198+
nrf_rpc_encode_str(&ctx, aService->mInstanceName, instance_len);
199+
105200
zcbor_list_start_encode(ctx.zs, num_subtypes);
106201

107202
for (const char *const *subtype = aService->mSubTypeLabels; *subtype != NULL; ++subtype) {
@@ -207,6 +302,36 @@ otError otSrpClientEnableAutoHostAddress(otInstance *aInstance)
207302
return error;
208303
}
209304

305+
otError otSrpClientSetHostAddresses(otInstance *aInstance, const otIp6Address *aIp6Addresses,
306+
uint8_t aNumAddresses)
307+
{
308+
struct nrf_rpc_cbor_ctx ctx;
309+
otError error;
310+
311+
ARG_UNUSED(aInstance);
312+
NRF_RPC_CBOR_ALLOC(&ot_group, ctx, 5 + aNumAddresses * (OT_IP6_ADDRESS_SIZE + 1));
313+
314+
nrf_rpc_encode_uint(&ctx, aNumAddresses);
315+
316+
zcbor_list_start_encode(ctx.zs, aNumAddresses);
317+
318+
for (int i = 0; i < aNumAddresses; ++i) {
319+
nrf_rpc_encode_buffer(&ctx, &aIp6Addresses[i], OT_IP6_ADDRESS_SIZE);
320+
}
321+
322+
zcbor_list_end_encode(ctx.zs, aNumAddresses);
323+
324+
nrf_rpc_cbor_cmd_no_err(&ot_group, OT_RPC_CMD_SRP_CLIENT_SET_HOST_ADDRESSES, &ctx,
325+
ot_rpc_decode_error, &error);
326+
327+
if (error == OT_ERROR_NONE) {
328+
host_info.mAutoAddress = false;
329+
}
330+
331+
return error;
332+
}
333+
334+
210335
void otSrpClientEnableAutoStartMode(otInstance *aInstance, otSrpClientAutoStartCallback aCallback,
211336
void *aContext)
212337
{
@@ -293,6 +418,50 @@ otError otSrpClientSetHostName(otInstance *aInstance, const char *aName)
293418
return error;
294419
}
295420

421+
const otSrpClientService *otSrpClientGetServices(otInstance *aInstance)
422+
{
423+
ARG_UNUSED(aInstance);
424+
425+
return services;
426+
}
427+
428+
const otSrpClientHostInfo *otSrpClientGetHostInfo(otInstance *aInstance)
429+
{
430+
ARG_UNUSED(aInstance);
431+
432+
return &host_info;
433+
}
434+
435+
bool otSrpClientIsAutoStartModeEnabled(otInstance *aInstance)
436+
{
437+
struct nrf_rpc_cbor_ctx ctx;
438+
bool enabled;
439+
440+
ARG_UNUSED(aInstance);
441+
442+
NRF_RPC_CBOR_ALLOC(&ot_group, ctx, 0);
443+
444+
nrf_rpc_cbor_cmd_no_err(&ot_group, OT_RPC_CMD_SRP_CLIENT_IS_AUTO_START_MODE_ENABLED, &ctx,
445+
nrf_rpc_rsp_decode_bool, &enabled);
446+
447+
return enabled;
448+
}
449+
450+
uint32_t otSrpClientGetKeyLeaseInterval(otInstance *aInstance)
451+
{
452+
struct nrf_rpc_cbor_ctx ctx;
453+
uint32_t key_lease_int;
454+
455+
ARG_UNUSED(aInstance);
456+
457+
NRF_RPC_CBOR_ALLOC(&ot_group, ctx, 0);
458+
459+
nrf_rpc_cbor_cmd_no_err(&ot_group, OT_RPC_CMD_SRP_CLIENT_GET_KEY_LEASE_INTERVAL, &ctx,
460+
nrf_rpc_rsp_decode_u32, &key_lease_int);
461+
462+
return key_lease_int;
463+
}
464+
296465
void otSrpClientSetKeyLeaseInterval(otInstance *aInstance, uint32_t aInterval)
297466
{
298467
struct nrf_rpc_cbor_ctx ctx;
@@ -305,6 +474,21 @@ void otSrpClientSetKeyLeaseInterval(otInstance *aInstance, uint32_t aInterval)
305474
nrf_rpc_rsp_decode_void, NULL);
306475
}
307476

477+
uint32_t otSrpClientGetLeaseInterval(otInstance *aInstance)
478+
{
479+
struct nrf_rpc_cbor_ctx ctx;
480+
uint32_t lease_int;
481+
482+
ARG_UNUSED(aInstance);
483+
484+
NRF_RPC_CBOR_ALLOC(&ot_group, ctx, 0);
485+
486+
nrf_rpc_cbor_cmd_no_err(&ot_group, OT_RPC_CMD_SRP_CLIENT_GET_LEASE_INTERVAL, &ctx,
487+
nrf_rpc_rsp_decode_u32, &lease_int);
488+
489+
return lease_int;
490+
}
491+
308492
void otSrpClientSetLeaseInterval(otInstance *aInstance, uint32_t aInterval)
309493
{
310494
struct nrf_rpc_cbor_ctx ctx;
@@ -329,6 +513,21 @@ void otSrpClientSetTtl(otInstance *aInstance, uint32_t aTtl)
329513
nrf_rpc_rsp_decode_void, NULL);
330514
}
331515

516+
uint32_t otSrpClientGetTtl(otInstance *aInstance)
517+
{
518+
struct nrf_rpc_cbor_ctx ctx;
519+
uint32_t ttl;
520+
521+
ARG_UNUSED(aInstance);
522+
523+
NRF_RPC_CBOR_ALLOC(&ot_group, ctx, 0);
524+
525+
nrf_rpc_cbor_cmd_no_err(&ot_group, OT_RPC_CMD_SRP_CLIENT_GET_TTL, &ctx,
526+
nrf_rpc_rsp_decode_u32, &ttl);
527+
528+
return ttl;
529+
}
530+
332531
static void ot_rpc_cmd_srp_client_cb(const struct nrf_rpc_group *group,
333532
struct nrf_rpc_cbor_ctx *ctx, void *handler_data)
334533
{

0 commit comments

Comments
 (0)