diff --git a/include/bluetooth/gatt.h b/include/bluetooth/gatt.h index e648257e505..cdd58ca895f 100644 --- a/include/bluetooth/gatt.h +++ b/include/bluetooth/gatt.h @@ -362,13 +362,21 @@ void bt_gatt_cb_register(struct bt_gatt_cb *cb); int bt_gatt_service_register(struct bt_gatt_service *svc); /** @brief Unregister GATT service. - * * + * * @param svc Service to be unregistered. * * @return 0 in case of success or negative value in case of error. */ int bt_gatt_service_unregister(struct bt_gatt_service *svc); +/** @brief Check if GATT service is registered. + * + * @param svc Service to be checked. + * + * @return true if registered or false if not register. + */ +bool bt_gatt_service_is_registered(const struct bt_gatt_service *svc); + enum { BT_GATT_ITER_STOP = 0, BT_GATT_ITER_CONTINUE, diff --git a/subsys/bluetooth/host/gatt.c b/subsys/bluetooth/host/gatt.c index e874e144f6f..c455cb36996 100644 --- a/subsys/bluetooth/host/gatt.c +++ b/subsys/bluetooth/host/gatt.c @@ -1323,6 +1323,24 @@ int bt_gatt_service_unregister(struct bt_gatt_service *svc) return 0; } + +bool bt_gatt_service_is_registered(const struct bt_gatt_service *svc) +{ + bool registered = false; + sys_snode_t *node; + + k_sched_lock(); + SYS_SLIST_FOR_EACH_NODE(&db, node) { + if (&svc->node == node) { + registered = true; + break; + } + } + + k_sched_unlock(); + + return registered; +} #endif /* CONFIG_BT_GATT_DYNAMIC_DB */ ssize_t bt_gatt_attr_read(struct bt_conn *conn, const struct bt_gatt_attr *attr,