Skip to content

Commit 0e7c4dc

Browse files
makeshim-alperen-sener
authored andcommitted
[nrf fromtree] Bluetooth: AVCTP: Implement the functionality of avctp_l2cap_accept
- Implement the functionality of avctp_l2cap_accept to accept an L2CAP connection for the AVCTP protocol. Signed-off-by: Make Shi <[email protected]> (cherry picked from commit f8ebbb3)
1 parent 8589f71 commit 0e7c4dc

File tree

1 file changed

+29
-9
lines changed
  • subsys/bluetooth/host/classic

1 file changed

+29
-9
lines changed

subsys/bluetooth/host/classic/avctp.c

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -125,15 +125,15 @@ static int avctp_l2cap_recv(struct bt_l2cap_chan *chan, struct net_buf *buf)
125125
return session->ops->recv(session, buf);
126126
}
127127

128+
static const struct bt_l2cap_chan_ops ops = {
129+
.connected = avctp_l2cap_connected,
130+
.disconnected = avctp_l2cap_disconnected,
131+
.encrypt_change = avctp_l2cap_encrypt_changed,
132+
.recv = avctp_l2cap_recv,
133+
};
134+
128135
int bt_avctp_connect(struct bt_conn *conn, struct bt_avctp *session)
129136
{
130-
static const struct bt_l2cap_chan_ops ops = {
131-
.connected = avctp_l2cap_connected,
132-
.disconnected = avctp_l2cap_disconnected,
133-
.encrypt_change = avctp_l2cap_encrypt_changed,
134-
.recv = avctp_l2cap_recv,
135-
};
136-
137137
if (!session) {
138138
return -EINVAL;
139139
}
@@ -217,9 +217,29 @@ int bt_avctp_register(const struct bt_avctp_event_cb *cb)
217217
static int avctp_l2cap_accept(struct bt_conn *conn, struct bt_l2cap_server *server,
218218
struct bt_l2cap_chan **chan)
219219
{
220-
/* TODO */
220+
struct bt_avctp *session = NULL;
221+
int err;
221222

222-
return -ENOTSUP;
223+
LOG_DBG("conn %p", conn);
224+
225+
if (!event_cb) {
226+
LOG_WRN("AVCTP server is unsupported");
227+
return -ENOTSUP;
228+
}
229+
230+
/* Get the AVCTP session from upper layer */
231+
err = event_cb->accept(conn, &session);
232+
if (err < 0) {
233+
LOG_ERR("Get the AVCTP session failed %d", err);
234+
return err;
235+
}
236+
237+
session->br_chan.rx.mtu = BT_L2CAP_RX_MTU;
238+
session->br_chan.psm = BT_L2CAP_PSM_AVCTP;
239+
session->br_chan.chan.ops = &ops;
240+
*chan = &session->br_chan.chan;
241+
242+
return 0;
223243
}
224244

225245
int bt_avctp_init(void)

0 commit comments

Comments
 (0)