mirror of
https://github.com/apache/nuttx.git
synced 2026-06-07 09:18:00 +08:00
arch/sim/hci: reuse the reserved fields of hci buffer
Reuse the reserved fields of hci buffer to avoid redundant packet type splitting Change-Id: I79d70ae939111bb909a6e0981c50e401734590f2 Signed-off-by: chao.an <anchao@xiaomi.com>
This commit is contained in:
@@ -92,19 +92,19 @@ struct bt_buf_s *read_buf = NULL;
|
||||
static int bthcisock_send(FAR const struct bt_driver_s *dev,
|
||||
FAR struct bt_buf_s *buf)
|
||||
{
|
||||
uint8_t pkt_type;
|
||||
uint8_t *pkt_type = bt_buf_provide(buf, BLUETOOTH_H4_HDRLEN);
|
||||
|
||||
switch (buf->type)
|
||||
{
|
||||
case BT_CMD:
|
||||
{
|
||||
pkt_type = HCI_COMMAND_PKT;
|
||||
*pkt_type = HCI_COMMAND_PKT;
|
||||
break;
|
||||
}
|
||||
|
||||
case BT_ACL_OUT:
|
||||
{
|
||||
pkt_type = HCI_ACLDATA_PKT;
|
||||
*pkt_type = HCI_ACLDATA_PKT;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -115,7 +115,7 @@ static int bthcisock_send(FAR const struct bt_driver_s *dev,
|
||||
}
|
||||
}
|
||||
|
||||
if (bthcisock_host_send(bt_fd, pkt_type, buf->data, buf->len) < 0)
|
||||
if (bthcisock_host_send(bt_fd, buf->data, buf->len) < 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
@@ -197,7 +197,7 @@ int bthcisock_loop(void)
|
||||
* to copy from
|
||||
*/
|
||||
|
||||
read_buf = bt_buf_alloc(BT_DUMMY, NULL, BLUETOOTH_H4_HDRLEN);
|
||||
read_buf = bt_buf_alloc(BT_DUMMY, NULL, 0);
|
||||
if (read_buf == NULL)
|
||||
{
|
||||
wlerr("ERROR: Failed to allocate buffer\n");
|
||||
@@ -205,14 +205,15 @@ int bthcisock_loop(void)
|
||||
}
|
||||
}
|
||||
|
||||
len = bthcisock_host_read(bt_fd, &type, read_buf->data,
|
||||
len = bthcisock_host_read(bt_fd, read_buf->data,
|
||||
BLUETOOTH_MAX_FRAMELEN);
|
||||
if (len < 0)
|
||||
{
|
||||
return OK;
|
||||
}
|
||||
|
||||
read_buf->len = len;
|
||||
type = *(uint8_t *)bt_buf_extend(read_buf, len);
|
||||
bt_buf_consume(read_buf, BLUETOOTH_H4_HDRLEN);
|
||||
|
||||
switch (type)
|
||||
{
|
||||
|
||||
@@ -106,10 +106,9 @@ int bthcisock_host_avail(int fd)
|
||||
* Send a Bluetooth packet out via the host user socket.
|
||||
*
|
||||
* Input Parameters:
|
||||
* fd: Host Bluetooth socket fd
|
||||
* pkt_type: Packet type as known to the Linux Bluetooth stack
|
||||
* fd : Host Bluetooth socket fd
|
||||
* data: Pointer to the HCI packet
|
||||
* len: Length of packet
|
||||
* len : Length of packet
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero is returned on success; a negated errno value is returned on any
|
||||
@@ -117,19 +116,15 @@ int bthcisock_host_avail(int fd)
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int bthcisock_host_send(int fd, uint8_t pkt_type, uint8_t *data, size_t len)
|
||||
int bthcisock_host_send(int fd, void *data, size_t len)
|
||||
{
|
||||
struct iovec iv[2];
|
||||
|
||||
iv[0].iov_base = &pkt_type;
|
||||
iv[0].iov_len = 1;
|
||||
iv[1].iov_base = data;
|
||||
iv[1].iov_len = len;
|
||||
|
||||
while (writev(fd, iv, 2) < 0)
|
||||
while (write(fd, data, len) < 0)
|
||||
{
|
||||
if (errno == EAGAIN || errno == EINTR)
|
||||
continue;
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -143,9 +138,9 @@ int bthcisock_host_send(int fd, uint8_t pkt_type, uint8_t *data, size_t len)
|
||||
* Read from the Host HCI socket interface.
|
||||
*
|
||||
* Input Parameters:
|
||||
* fd: Host Bluetooth socket fd
|
||||
* fd : Host Bluetooth socket fd
|
||||
* data: Pointer to store HCI packet
|
||||
* len: Maximum length of packet
|
||||
* len : Maximum length of packet
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero is returned on success; a negated errno value is returned on any
|
||||
@@ -153,17 +148,11 @@ int bthcisock_host_send(int fd, uint8_t pkt_type, uint8_t *data, size_t len)
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int bthcisock_host_read(int fd, uint8_t *type, void *buf, size_t len)
|
||||
int bthcisock_host_read(int fd, void *data, size_t len)
|
||||
{
|
||||
int err;
|
||||
struct iovec iv[2];
|
||||
|
||||
iv[0].iov_base = type;
|
||||
iv[0].iov_len = 1;
|
||||
iv[1].iov_base = buf;
|
||||
iv[1].iov_len = len;
|
||||
|
||||
while ((err = readv(fd, iv, 2)) < 0 && (errno == EINTR));
|
||||
while ((err = read(fd, data, len)) < 0 && (errno == EINTR));
|
||||
|
||||
if (err <= 0)
|
||||
{
|
||||
@@ -172,9 +161,9 @@ int bthcisock_host_read(int fd, uint8_t *type, void *buf, size_t len)
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Return the number of bytes written to buf so remove the header byte */
|
||||
/* Return the number of bytes written to data */
|
||||
|
||||
return (err - 1);
|
||||
return err;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
||||
@@ -33,8 +33,8 @@
|
||||
****************************************************************************/
|
||||
|
||||
int bthcisock_host_open(int dev_idx);
|
||||
int bthcisock_host_send(int fd, uint8_t pkt_type, uint8_t *data, size_t len);
|
||||
int bthcisock_host_read(int fd, uint8_t *type, void *buf, size_t len);
|
||||
int bthcisock_host_send(int fd, void *data, size_t len);
|
||||
int bthcisock_host_read(int fd, void *data, size_t len);
|
||||
int bthcisock_host_avail(int fd);
|
||||
int bthcisock_host_close(int fd);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user