diff --git a/include/zephyr/bluetooth/classic/a2dp.h b/include/zephyr/bluetooth/classic/a2dp.h index 32329b61453..db1e9964915 100644 --- a/include/zephyr/bluetooth/classic/a2dp.h +++ b/include/zephyr/bluetooth/classic/a2dp.h @@ -616,6 +616,16 @@ int bt_a2dp_register_ep(struct bt_a2dp_ep *ep, uint8_t media_type, uint8_t sep_t */ int bt_a2dp_register_cb(struct bt_a2dp_cb *cb); +/** @brief Obtain the ACL connection corresponding to A2DP. + * + * @param a2dp The A2DP instance. + * + * @return Connection object associated with the A2DP context. The caller gets a new + * reference to the connection object which must be released with bt_conn_unref() + * once done using the object. + */ +struct bt_conn *bt_a2dp_get_conn(struct bt_a2dp *a2dp); + /** @brief Discover remote endpoints. * * @param a2dp The a2dp instance. diff --git a/subsys/bluetooth/host/classic/a2dp.c b/subsys/bluetooth/host/classic/a2dp.c index 504aba7d280..bf1acd3dc62 100644 --- a/subsys/bluetooth/host/classic/a2dp.c +++ b/subsys/bluetooth/host/classic/a2dp.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include @@ -1015,6 +1016,19 @@ int bt_a2dp_register_ep(struct bt_a2dp_ep *ep, uint8_t media_type, uint8_t sep_t return 0; } +struct bt_conn *bt_a2dp_get_conn(struct bt_a2dp *a2dp) +{ + CHECKIF(a2dp == NULL) { + return NULL; + } + + if (!a2dp->session.br_chan.chan.conn) { + return NULL; + } + + return bt_conn_ref(a2dp->session.br_chan.chan.conn); +} + int bt_a2dp_register_cb(struct bt_a2dp_cb *cb) { a2dp_cb = cb;