Skip to content

Commit

Permalink
Bluetooth: MICP: Fix missing guards for AICS
Browse files Browse the repository at this point in the history
Some places MICP accessed AICS when it was not supported.

Signed-off-by: Emil Gydesen <[email protected]>
  • Loading branch information
Thalley authored and henrikbrixandersen committed Feb 5, 2024
1 parent ab1b43e commit adb74f0
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 16 deletions.
2 changes: 2 additions & 0 deletions subsys/bluetooth/audio/micp_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ struct bt_micp_mic_ctlr {
struct bt_gatt_discover_params discover_params;
struct bt_conn *conn;

#if defined(CONFIG_BT_MICP_MIC_CTLR_AICS)
uint8_t aics_inst_cnt;
struct bt_aics *aics[CONFIG_BT_MICP_MIC_CTLR_MAX_AICS_INST];
#endif /* CONFIG_BT_MICP_MIC_CTLR_AICS */
};

#endif /* ZEPHYR_INCLUDE_BLUETOOTH_AUDIO_MICP_INTERNAL_ */
44 changes: 28 additions & 16 deletions subsys/bluetooth/audio/micp_mic_ctlr.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,15 @@ static void micp_mic_ctlr_discover_complete(struct bt_micp_mic_ctlr *mic_ctlr, i

SYS_SLIST_FOR_EACH_CONTAINER_SAFE(&micp_mic_ctlr_cbs, listener, next, _node) {
if (listener->discover) {
listener->discover(mic_ctlr, err, err == 0 ? mic_ctlr->aics_inst_cnt : 0U);
uint8_t aics_cnt = 0U;

#if defined(CONFIG_BT_MICP_MIC_CTLR_AICS)
if (err == 0) {
aics_cnt = mic_ctlr->aics_inst_cnt;
}
#endif /* CONFIG_BT_MICP_MIC_CTLR_AICS */

listener->discover(mic_ctlr, err, aics_cnt);
}
}
}
Expand Down Expand Up @@ -298,7 +306,6 @@ static void micp_mic_ctlr_aics_set_auto_mode_cb(struct bt_aics *inst, int err)
}
}
}
#endif /* CONFIG_BT_MICP_MIC_CTLR_AICS */

static uint8_t micp_discover_include_func(
struct bt_conn *conn, const struct bt_gatt_attr *attr,
Expand Down Expand Up @@ -350,6 +357,7 @@ static uint8_t micp_discover_include_func(

return BT_GATT_ITER_CONTINUE;
}
#endif /* CONFIG_BT_MICP_MIC_CTLR_AICS */

/**
* @brief This will discover all characteristics on the server, retrieving the
Expand All @@ -367,22 +375,22 @@ static uint8_t micp_discover_func(struct bt_conn *conn,

LOG_DBG("Discovery complete");
(void)memset(params, 0, sizeof(*params));
if (CONFIG_BT_MICP_MIC_CTLR_MAX_AICS_INST > 0) {
/* Discover included services */
mic_ctlr->discover_params.start_handle = mic_ctlr->start_handle;
mic_ctlr->discover_params.end_handle = mic_ctlr->end_handle;
mic_ctlr->discover_params.type = BT_GATT_DISCOVER_INCLUDE;
mic_ctlr->discover_params.func = micp_discover_include_func;

err = bt_gatt_discover(conn,
&mic_ctlr->discover_params);
if (err != 0) {
LOG_DBG("Discover AICS failed (err %d)", err);
micp_mic_ctlr_discover_complete(mic_ctlr, err);
}
} else {

#if defined(CONFIG_BT_MICP_MIC_CTLR_AICS)
/* Discover included services */
mic_ctlr->discover_params.start_handle = mic_ctlr->start_handle;
mic_ctlr->discover_params.end_handle = mic_ctlr->end_handle;
mic_ctlr->discover_params.type = BT_GATT_DISCOVER_INCLUDE;
mic_ctlr->discover_params.func = micp_discover_include_func;

err = bt_gatt_discover(conn, &mic_ctlr->discover_params);
if (err != 0) {
LOG_DBG("Discover AICS failed (err %d)", err);
micp_mic_ctlr_discover_complete(mic_ctlr, err);
}
#else
micp_mic_ctlr_discover_complete(mic_ctlr, err);
#endif /* CONFIG_BT_MICP_MIC_CTLR_AICS */

return BT_GATT_ITER_STOP;
}
Expand Down Expand Up @@ -476,7 +484,9 @@ static void micp_mic_ctlr_reset(struct bt_micp_mic_ctlr *mic_ctlr)
mic_ctlr->start_handle = 0;
mic_ctlr->end_handle = 0;
mic_ctlr->mute_handle = 0;
#if defined(CONFIG_BT_MICP_MIC_CTLR_AICS)
mic_ctlr->aics_inst_cnt = 0;
#endif /* CONFIG_BT_MICP_MIC_CTLR_AICS */

if (mic_ctlr->conn != NULL) {
struct bt_conn *conn = mic_ctlr->conn;
Expand Down Expand Up @@ -594,6 +604,7 @@ int bt_micp_mic_ctlr_cb_register(struct bt_micp_mic_ctlr_cb *cb)
return 0;
}

#if defined(CONFIG_BT_MICP_MIC_CTLR_AICS)
int bt_micp_mic_ctlr_included_get(struct bt_micp_mic_ctlr *mic_ctlr,
struct bt_micp_included *included)
{
Expand All @@ -611,6 +622,7 @@ int bt_micp_mic_ctlr_included_get(struct bt_micp_mic_ctlr *mic_ctlr,

return 0;
}
#endif /* CONFIG_BT_MICP_MIC_CTLR_AICS */

struct bt_micp_mic_ctlr *bt_micp_mic_ctlr_get_by_conn(const struct bt_conn *conn)
{
Expand Down

0 comments on commit adb74f0

Please sign in to comment.