Bluetooth: Audio: VCS register return if already registered
Change how bt_vcs_register works if VCS has already been
registered.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
diff --git a/include/bluetooth/audio/vcs.h b/include/bluetooth/audio/vcs.h
index ce94c65..c5ffb7f 100644
--- a/include/bluetooth/audio/vcs.h
+++ b/include/bluetooth/audio/vcs.h
@@ -81,6 +81,7 @@
*
* @param param Volume Control Service register parameters.
* @param[out] vcs Pointer to the registered Volume Control Service.
+ * This will still be valid if the return value is -EALREADY.
*
* @return 0 if success, errno on failure.
*/
diff --git a/subsys/bluetooth/audio/vcs.c b/subsys/bluetooth/audio/vcs.c
index e77221b..dda5c9f 100644
--- a/subsys/bluetooth/audio/vcs.c
+++ b/subsys/bluetooth/audio/vcs.c
@@ -359,8 +359,14 @@
/****************************** PUBLIC API ******************************/
int bt_vcs_register(struct bt_vcs_register_param *param, struct bt_vcs **vcs)
{
+ static bool registered;
int err;
+ if (registered) {
+ *vcs = &vcs_inst;
+ return -EALREADY;
+ }
+
vcs_svc = (struct bt_gatt_service)BT_GATT_SERVICE(vcs_attrs);
if (CONFIG_BT_VCS_VOCS_INSTANCE_COUNT > 0) {
@@ -392,6 +398,7 @@
vcs_inst.srv.cb = param->cb;
*vcs = &vcs_inst;
+ registered = true;
return err;
}