diff --git a/net/bluetooth/avdtp.c b/net/bluetooth/avdtp.c index 0306671ea2a..7dcdfb7c32a 100644 --- a/net/bluetooth/avdtp.c +++ b/net/bluetooth/avdtp.c @@ -56,10 +56,25 @@ static struct bt_avdtp_event_cb *event_cb; /* L2CAP Interface callbacks */ void bt_avdtp_l2cap_connected(struct bt_l2cap_chan *chan) { - BT_DBG(""); + if (!chan) { + BT_ERR("Invalid AVDTP chan"); + return; + } + + BT_DBG("chan %p session %p", chan, AVDTP_CHAN(chan)); } void bt_avdtp_l2cap_disconnected(struct bt_l2cap_chan *chan) +{ + if (!chan) { + BT_ERR("Invalid AVDTP chan"); + return; + } + + BT_DBG("chan %p session %p", chan, AVDTP_CHAN(chan)); +} + +void bt_avdtp_l2cap_encrypt_changed(struct bt_l2cap_chan *chan) { BT_DBG(""); } @@ -69,6 +84,37 @@ void bt_avdtp_l2cap_recv(struct bt_l2cap_chan *chan, struct net_buf *buf) BT_DBG(""); } +/*A2DP Layer interface */ +int bt_avdtp_connect(struct bt_conn *conn, struct bt_avdtp *session) +{ + static struct bt_l2cap_chan_ops ops = { + .connected = bt_avdtp_l2cap_connected, + .disconnected = bt_avdtp_l2cap_disconnected, + .encrypt_change = bt_avdtp_l2cap_encrypt_changed, + .recv = bt_avdtp_l2cap_recv + }; + + if (!session) { + return -EINVAL; + } + + session->br_chan.chan.ops = &ops; + + return bt_l2cap_chan_connect(conn, &session->br_chan.chan, + BT_L2CAP_PSM_AVDTP); +} + +int bt_avdtp_disconnect(struct bt_avdtp *session) +{ + if (!session) { + return -EINVAL; + } + + BT_DBG("session %p", session); + + return bt_l2cap_chan_disconnect(&session->br_chan.chan); +} + int bt_avdtp_l2cap_accept(struct bt_conn *conn, struct bt_l2cap_chan **chan) { int i; diff --git a/net/bluetooth/avdtp_internal.h b/net/bluetooth/avdtp_internal.h index a95d71dfb3f..0f1aa0f7a7c 100644 --- a/net/bluetooth/avdtp_internal.h +++ b/net/bluetooth/avdtp_internal.h @@ -54,14 +54,15 @@ #define BT_AVDTP_DELAYREPORT 0x0d /* @brief AVDTP STATE */ -#define BT_AVDTP_STATE_IDLE 0x01 -#define BT_AVDTP_STATE_CONFIGURED 0x02 -#define BT_AVDTP_STATE_OPEN 0x03 -#define BT_AVDTP_STATE_STREAMING 0x04 -#define BT_AVDTP_STATE_CLOSING 0x05 -#define BT_AVDTP_STATE_ABORT 0x06 -#define BT_AVDTP_STATE_SIG_CONNECTED 0x07 -#define BT_AVDTP_STATE_INVALID 0x00 +#define BT_AVDTP_STATE_IDLE 0x01 +#define BT_AVDTP_STATE_CONFIGURED 0x02 +#define BT_AVDTP_STATE_OPEN 0x03 +#define BT_AVDTP_STATE_STREAMING 0x04 +#define BT_AVDTP_STATE_CLOSING 0x05 +#define BT_AVDTP_STATE_ABORT 0x06 +#define BT_AVDTP_STATE_SIG_CONNECTED 0x07 +#define BT_AVDTP_STATE_SIG_DISCONNECTED 0x08 +#define BT_AVDTP_STATE_INVALID 0x00 /* @brief AVDTP Media TYPE */ #define BT_AVDTP_SERVICE_CAT_MEDIA_TRANSPORT 0x01 @@ -149,3 +150,9 @@ int bt_avdtp_init(void); /* Application register with AVDTP layer */ int bt_avdtp_register(struct bt_avdtp_event_cb *cb); + +/* AVDTP connect */ +int bt_avdtp_connect(struct bt_conn *conn, struct bt_avdtp *session); + +/* AVDTP disconnect */ +int bt_avdtp_disconnect(struct bt_avdtp *session);