Bluetooth: AVCTP: allow to create and send AVCTP message

This patch defines the message format for general AVCTP.
They would be further called by AVRCP layer.

Signed-off-by: Zihao Gao <gaozihao@xiaomi.com>
This commit is contained in:
Zihao Gao 2024-10-30 10:45:02 +08:00 committed by Anas Nashif
parent 36acb89803
commit 3a045fbeea
2 changed files with 73 additions and 1 deletions

View file

@ -113,6 +113,49 @@ int bt_avctp_disconnect(struct bt_avctp *session)
return bt_l2cap_chan_disconnect(&session->br_chan.chan);
}
struct net_buf *bt_avctp_create_pdu(struct bt_avctp *session, bt_avctp_cr_t cr,
bt_avctp_ipid_t ipid, uint8_t *tid, uint16_t pid)
{
struct net_buf *buf;
struct bt_avctp_header *hdr;
LOG_DBG("");
buf = bt_l2cap_create_pdu(NULL, 0);
if (!buf) {
LOG_ERR("No buff available");
return buf;
}
hdr = net_buf_add(buf, sizeof(*hdr));
hdr->cr = cr;
hdr->ipid = ipid;
hdr->pkt_type = BT_AVCTP_PKT_TYPE_SINGLE;
hdr->tid = *tid;
hdr->pid = pid;
if (cr == BT_AVCTP_CMD) {
*tid = (*tid + 1) & 0x0F; /* Incremented by one */
}
LOG_DBG("cr:0x%X, tid:0x%02X", hdr->cr, hdr->tid);
return buf;
}
int bt_avctp_send(struct bt_avctp *session, struct net_buf *buf)
{
int err;
err = bt_l2cap_chan_send(&session->br_chan.chan, buf);
if (err < 0) {
net_buf_unref(buf);
LOG_ERR("L2CAP send fail err = %d", err);
return err;
}
return err;
}
int bt_avctp_register(const struct bt_avctp_event_cb *cb)
{
LOG_DBG("");
@ -127,7 +170,7 @@ int bt_avctp_register(const struct bt_avctp_event_cb *cb)
}
static int avctp_l2cap_accept(struct bt_conn *conn, struct bt_l2cap_server *server,
struct bt_l2cap_chan **chan)
struct bt_l2cap_chan **chan)
{
/* TODO */

View file

@ -11,6 +11,28 @@
#define BT_L2CAP_PSM_AVCTP 0x0017
typedef enum __packed {
BT_AVCTP_IPID_NONE = 0b0,
BT_AVCTP_IPID_INVALID = 0b1,
} bt_avctp_ipid_t;
typedef enum __packed {
BT_AVCTP_CMD = 0b0,
BT_AVCTP_RESPONSE = 0b1,
} bt_avctp_cr_t;
typedef enum __packed {
BT_AVCTP_PKT_TYPE_SINGLE = 0b00,
} bt_avctp_pkt_type_t;
struct bt_avctp_header {
uint8_t ipid: 1; /* Invalid Profile Identifier (1), otherwise zero (0) */
uint8_t cr: 1; /* Command(0) or Respone(1) */
uint8_t pkt_type: 2; /* Set to zero (00) for single L2CAP packet */
uint8_t tid: 4; /* Transaction label */
uint16_t pid; /* Profile Identifier */
} __packed;
struct bt_avctp;
struct bt_avctp_ops_cb {
@ -38,3 +60,10 @@ int bt_avctp_connect(struct bt_conn *conn, struct bt_avctp *session);
/* AVCTP disconnect */
int bt_avctp_disconnect(struct bt_avctp *session);
/* Create AVCTP PDU */
struct net_buf *bt_avctp_create_pdu(struct bt_avctp *session, bt_avctp_cr_t cr,
bt_avctp_ipid_t ipid, uint8_t *tid, uint16_t pid);
/* Send AVCTP PDU */
int bt_avctp_send(struct bt_avctp *session, struct net_buf *buf);