From 0b3db9a0dfe8c1824164584dc465052507f31943 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Kopy=C5=9Bci=C5=84ski?= Date: Tue, 17 Nov 2020 07:59:44 +0100 Subject: [PATCH] mesh: add bt_mesh_friend_terminate() function This function allows to terminate friendship manually. --- nimble/host/mesh/include/mesh/main.h | 10 ++++++++++ nimble/host/mesh/src/friend.c | 14 ++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/nimble/host/mesh/include/mesh/main.h b/nimble/host/mesh/include/mesh/main.h index 042b59a5a..c0ef04da7 100644 --- a/nimble/host/mesh/include/mesh/main.h +++ b/nimble/host/mesh/include/mesh/main.h @@ -432,6 +432,16 @@ int bt_mesh_lpn_poll(void); */ void bt_mesh_lpn_set_cb(void (*cb)(uint16_t friend_addr, bool established)); +/** @brief Terminate Friendship. + * + * Terminated Friendship for given LPN. + * + * @param lpn_addr Low Power Node address. + * + * @return Zero on success or (negative) error code otherwise. + */ +int bt_mesh_friend_terminate(uint16_t lpn_addr); + #ifdef __cplusplus } #endif diff --git a/nimble/host/mesh/src/friend.c b/nimble/host/mesh/src/friend.c index ed6e69dd9..58dd6d358 100644 --- a/nimble/host/mesh/src/friend.c +++ b/nimble/host/mesh/src/friend.c @@ -1693,6 +1693,20 @@ bool bt_mesh_friend_enqueue_tx(struct bt_mesh_net_tx *tx, return matched; } +int bt_mesh_friend_terminate(uint16_t lpn_addr) +{ + struct bt_mesh_friend *frnd; + + frnd = bt_mesh_friend_find(BT_MESH_KEY_ANY, lpn_addr, false, false); + if (!frnd) { + return -ENOENT; + } + + friend_clear(frnd); + + return 0; +} + void bt_mesh_friend_clear_incomplete(struct bt_mesh_subnet *sub, uint16_t src, uint16_t dst, uint64_t *seq_auth) {