Add function to send SCO packets via bthost. --- emulator/bthost.c | 32 ++++++++++++++++++++++++++++++++ emulator/bthost.h | 2 ++ 2 files changed, 34 insertions(+) diff --git a/emulator/bthost.c b/emulator/bthost.c index 1ae33ba6b..214583cc5 100644 --- a/emulator/bthost.c +++ b/emulator/bthost.c @@ -40,6 +40,7 @@ #define acl_flags(h) (h >> 12) #define sco_flags_status(f) (f & 0x03) +#define sco_flags_pack(status) (status & 0x03) #define iso_flags_pb(f) (f & 0x0003) #define iso_flags_ts(f) ((f >> 2) & 0x0001) @@ -878,6 +879,37 @@ void bthost_send_cid_v(struct bthost *bthost, uint16_t handle, uint16_t cid, send_iov(bthost, handle, cid, iov, iovcnt); } +void bthost_send_sco(struct bthost *bthost, uint16_t handle, uint8_t pkt_status, + const struct iovec *iov, int iovcnt) +{ + uint8_t pkt = BT_H4_SCO_PKT; + struct iovec pdu[2 + iovcnt]; + struct bt_hci_sco_hdr sco_hdr; + struct btconn *conn; + int i, len = 0; + + conn = bthost_find_conn(bthost, handle); + if (!conn) + return; + + for (i = 0; i < iovcnt; i++) { + pdu[2 + i].iov_base = iov[i].iov_base; + pdu[2 + i].iov_len = iov[i].iov_len; + len += iov[i].iov_len; + } + + pdu[0].iov_base = &pkt; + pdu[0].iov_len = sizeof(pkt); + + sco_hdr.handle = acl_handle_pack(handle, sco_flags_pack(pkt_status)); + sco_hdr.dlen = len; + + pdu[1].iov_base = &sco_hdr; + pdu[1].iov_len = sizeof(sco_hdr); + + send_packet(bthost, pdu, 2 + iovcnt); +} + static void send_iso(struct bthost *bthost, uint16_t handle, bool ts, uint16_t sn, uint32_t timestamp, uint8_t pkt_status, const struct iovec *iov, int iovcnt) diff --git a/emulator/bthost.h b/emulator/bthost.h index 583a8b6df..db640daff 100644 --- a/emulator/bthost.h +++ b/emulator/bthost.h @@ -92,6 +92,8 @@ void bthost_send_cid(struct bthost *bthost, uint16_t handle, uint16_t cid, const void *data, uint16_t len); void bthost_send_cid_v(struct bthost *bthost, uint16_t handle, uint16_t cid, const struct iovec *iov, int iovcnt); +void bthost_send_sco(struct bthost *bthost, uint16_t handle, uint8_t pkt_status, + const struct iovec *iov, int iovcnt); void bthost_send_iso(struct bthost *bthost, uint16_t handle, bool ts, uint16_t sn, uint32_t timestamp, uint8_t pkt_status, const struct iovec *iov, int iovcnt); -- 2.49.0