Bluetooth: Audio: MCC - refactor subscription

Move subscription to characteristics to separate function.

Signed-off-by: Asbjørn Sæbø <asbjorn.sabo@nordicsemi.no>
This commit is contained in:
Asbjørn Sæbø 2022-04-28 11:07:15 +02:00 committed by Carles Cufí
commit 6c2b8e6e65

View file

@ -1215,6 +1215,20 @@ static void discover_included(struct bt_conn *conn)
} }
#endif /* CONFIG_BT_MCC_OTS */ #endif /* CONFIG_BT_MCC_OTS */
/* Subscribe to a characteristic - helper function */
static void do_subscribe(struct bt_conn *conn, uint16_t handle,
struct bt_gatt_subscribe_params *sub_params)
{
/* With ccc_handle == 0 it will use auto discovery */
sub_params->ccc_handle = 0;
sub_params->end_handle = cur_mcs_inst->end_handle;
sub_params->value = BT_GATT_CCC_NOTIFY;
sub_params->value_handle = handle;
sub_params->notify = mcs_notify_handler;
bt_gatt_subscribe(conn, sub_params);
}
/* This function is called when characteristics are found. /* This function is called when characteristics are found.
* The function will store handles, and optionally subscribe to, GMCS * The function will store handles, and optionally subscribe to, GMCS
* characteristics. * characteristics.
@ -1352,14 +1366,7 @@ static uint8_t discover_mcs_char_func(struct bt_conn *conn,
if (subscribe_all && sub_params) { if (subscribe_all && sub_params) {
BT_DBG("Subscribing - handle: 0x%04x", attr->handle); BT_DBG("Subscribing - handle: 0x%04x", attr->handle);
do_subscribe(conn, chrc->value_handle, sub_params);
/* With ccc_handle == 0 it will use auto discovery */
sub_params->ccc_handle = 0;
sub_params->end_handle = cur_mcs_inst->end_handle;
sub_params->value = BT_GATT_CCC_NOTIFY;
sub_params->value_handle = chrc->value_handle;
sub_params->notify = mcs_notify_handler;
bt_gatt_subscribe(conn, sub_params);
} }
/* Continue to search for more attributes */ /* Continue to search for more attributes */