Skip to content

Commit 634b72a

Browse files
jialu522kartben
authored andcommitted
Bluetooth: Add API to obtain ACL connection corresponding to a2dp
When connecting two devices with an application, it is necessary to differentiate which is the remote device. Signed-off-by: Lu Jia <jialu@xiaomi.com>
1 parent 9983ff7 commit 634b72a

File tree

2 files changed

+24
-0
lines changed
  • include/zephyr/bluetooth/classic
  • subsys/bluetooth/host/classic

2 files changed

+24
-0
lines changed

include/zephyr/bluetooth/classic/a2dp.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,16 @@ int bt_a2dp_register_ep(struct bt_a2dp_ep *ep, uint8_t media_type, uint8_t sep_t
616616
*/
617617
int bt_a2dp_register_cb(struct bt_a2dp_cb *cb);
618618

619+
/** @brief Obtain the ACL connection corresponding to A2DP.
620+
*
621+
* @param a2dp The A2DP instance.
622+
*
623+
* @return Connection object associated with the A2DP context. The caller gets a new
624+
* reference to the connection object which must be released with bt_conn_unref()
625+
* once done using the object.
626+
*/
627+
struct bt_conn *bt_a2dp_get_conn(struct bt_a2dp *a2dp);
628+
619629
/** @brief Discover remote endpoints.
620630
*
621631
* @param a2dp The a2dp instance.

subsys/bluetooth/host/classic/a2dp.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <errno.h>
1515
#include <zephyr/sys/atomic.h>
1616
#include <zephyr/sys/byteorder.h>
17+
#include <zephyr/sys/check.h>
1718
#include <zephyr/sys/util.h>
1819
#include <zephyr/sys/printk.h>
1920

@@ -1015,6 +1016,19 @@ int bt_a2dp_register_ep(struct bt_a2dp_ep *ep, uint8_t media_type, uint8_t sep_t
10151016
return 0;
10161017
}
10171018

1019+
struct bt_conn *bt_a2dp_get_conn(struct bt_a2dp *a2dp)
1020+
{
1021+
CHECKIF(a2dp == NULL) {
1022+
return NULL;
1023+
}
1024+
1025+
if (!a2dp->session.br_chan.chan.conn) {
1026+
return NULL;
1027+
}
1028+
1029+
return bt_conn_ref(a2dp->session.br_chan.chan.conn);
1030+
}
1031+
10181032
int bt_a2dp_register_cb(struct bt_a2dp_cb *cb)
10191033
{
10201034
a2dp_cb = cb;

0 commit comments

Comments
 (0)