Skip to content

Commit 257c99a

Browse files
alxelaxnordicjm
authored andcommitted
bluetooth: rpc: add cb unregistration
Commit adds serialization of new bt_conn_cb_unregister Signed-off-by: Aleksandr Khromykh <[email protected]>
1 parent 586f962 commit 257c99a

File tree

3 files changed

+58
-9
lines changed

3 files changed

+58
-9
lines changed

subsys/bluetooth/rpc/client/bt_rpc_conn_client.c

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1140,20 +1140,17 @@ static void bt_conn_cb_register_on_remote(void)
11401140
{
11411141
struct nrf_rpc_cbor_ctx ctx;
11421142
size_t buffer_size_max = 0;
1143-
static bool registered;
11441143

1145-
if (!registered) {
1146-
registered = true;
1147-
1148-
NRF_RPC_CBOR_ALLOC(&bt_rpc_grp, ctx, buffer_size_max);
1144+
NRF_RPC_CBOR_ALLOC(&bt_rpc_grp, ctx, buffer_size_max);
11491145

1150-
nrf_rpc_cbor_cmd_no_err(&bt_rpc_grp, BT_CONN_CB_REGISTER_ON_REMOTE_RPC_CMD,
1151-
&ctx, ser_rsp_decode_void, NULL);
1152-
}
1146+
nrf_rpc_cbor_cmd_no_err(&bt_rpc_grp, BT_CONN_CB_REGISTER_ON_REMOTE_RPC_CMD, &ctx,
1147+
ser_rsp_decode_void, NULL);
11531148
}
11541149

11551150
int bt_conn_cb_register(struct bt_conn_cb *cb)
11561151
{
1152+
bool first = sys_slist_is_empty(&conn_cbs);
1153+
11571154
LOCK_CONN_INFO();
11581155
if (sys_slist_find(&conn_cbs, &cb->_node, NULL)) {
11591156
return -EEXIST;
@@ -1162,11 +1159,45 @@ int bt_conn_cb_register(struct bt_conn_cb *cb)
11621159
sys_slist_append(&conn_cbs, &cb->_node);
11631160
UNLOCK_CONN_INFO();
11641161

1165-
bt_conn_cb_register_on_remote();
1162+
if (first) {
1163+
bt_conn_cb_register_on_remote();
1164+
}
11661165

11671166
return 0;
11681167
}
11691168

1169+
static int bt_conn_cb_unregister_on_remote(void)
1170+
{
1171+
struct nrf_rpc_cbor_ctx ctx;
1172+
size_t buffer_size_max = 0;
1173+
int result = 0;
1174+
1175+
NRF_RPC_CBOR_ALLOC(&bt_rpc_grp, ctx, buffer_size_max);
1176+
1177+
nrf_rpc_cbor_cmd_no_err(&bt_rpc_grp, BT_CONN_CB_UNREGISTER_ON_REMOTE_RPC_CMD, &ctx,
1178+
ser_rsp_decode_i32, &result);
1179+
1180+
return result;
1181+
}
1182+
1183+
int bt_conn_cb_unregister(struct bt_conn_cb *cb)
1184+
{
1185+
int err = 0;
1186+
1187+
LOCK_CONN_INFO();
1188+
if (!sys_slist_find_and_remove(&conn_cbs, &cb->_node)) {
1189+
err = -ENOENT;
1190+
}
1191+
UNLOCK_CONN_INFO();
1192+
1193+
if (err == 0 && sys_slist_is_empty(&conn_cbs)) {
1194+
/* No callbacks left, unregister on remote */
1195+
err = bt_conn_cb_unregister_on_remote();
1196+
}
1197+
1198+
return err;
1199+
}
1200+
11701201
#if defined(CONFIG_BT_SMP)
11711202
void bt_set_bondable(bool enable)
11721203
{

subsys/bluetooth/rpc/common/bt_rpc_common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ enum bt_rpc_cmd_from_cli_to_host {
9797
BT_CONN_GET_SECURITY_RPC_CMD,
9898
BT_CONN_ENC_KEY_SIZE_RPC_CMD,
9999
BT_CONN_CB_REGISTER_ON_REMOTE_RPC_CMD,
100+
BT_CONN_CB_UNREGISTER_ON_REMOTE_RPC_CMD,
100101
BT_SET_BONDABLE_RPC_CMD,
101102
BT_LE_OOB_SET_LEGACY_FLAG_RPC_CMD,
102103
BT_LE_OOB_SET_SC_FLAG_RPC_CMD,

subsys/bluetooth/rpc/host/bt_rpc_conn_host.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -940,6 +940,23 @@ NRF_RPC_CBOR_CMD_DECODER(bt_rpc_grp, bt_conn_cb_register_on_remote,
940940
BT_CONN_CB_REGISTER_ON_REMOTE_RPC_CMD,
941941
bt_conn_cb_register_on_remote_rpc_handler, NULL);
942942

943+
static void bt_conn_cb_unregister_on_remote_rpc_handler(const struct nrf_rpc_group *group,
944+
struct nrf_rpc_cbor_ctx *ctx,
945+
void *handler_data)
946+
{
947+
int result;
948+
949+
nrf_rpc_cbor_decoding_done(group, ctx);
950+
951+
result = bt_conn_cb_unregister(&bt_conn_cb_register_data);
952+
953+
ser_rsp_send_int(group, result);
954+
}
955+
956+
NRF_RPC_CBOR_CMD_DECODER(bt_rpc_grp, bt_conn_cb_unregister_on_remote,
957+
BT_CONN_CB_UNREGISTER_ON_REMOTE_RPC_CMD,
958+
bt_conn_cb_unregister_on_remote_rpc_handler, NULL);
959+
943960
#if defined(CONFIG_BT_SMP)
944961
static void bt_set_bondable_rpc_handler(const struct nrf_rpc_group *group,
945962
struct nrf_rpc_cbor_ctx *ctx, void *handler_data)

0 commit comments

Comments
 (0)