sim/host/hcisocket: add avail/close interface

Change-Id: I3d96f62c4c3c7d703bfec74952953bee4aef9c7c
Signed-off-by: chao.an <anchao@xiaomi.com>
This commit is contained in:
chao.an 2020-12-23 13:54:59 +08:00 committed by Brennan Ashton
parent d7b004e179
commit 2ca99ed1be
3 changed files with 61 additions and 2 deletions

View File

@ -177,7 +177,7 @@ int bthcisock_register(int dev_id)
*
****************************************************************************/
int bthcisock_loop()
int bthcisock_loop(void)
{
uint8_t type;
int len;

View File

@ -62,6 +62,43 @@ struct sockaddr_hci
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: bthcisock_host_avail
*
* Description:
* Monitor the host user channel to see if I/O is possible on socket.
*
* Input Parameters:
* fd: Host Bluetooth socket fd
*
* Returned Value:
* TRUE is returned on I/O available
*
****************************************************************************/
int bthcisock_host_avail(int fd)
{
struct timeval tv;
fd_set fdset;
/* We can't do anything if we failed to open the user channel */
if (fd < 0)
{
return 0;
}
/* Wait for data on the user channel (or a timeout) */
tv.tv_sec = 0;
tv.tv_usec = 0;
FD_ZERO(&fdset);
FD_SET(fd, &fdset);
return select(fd + 1, &fdset, NULL, NULL, &tv) > 0;
}
/****************************************************************************
* Name: bthcisock_host_send
*
@ -190,3 +227,23 @@ int bthcisock_host_open(int dev_idx)
return fd;
}
/****************************************************************************
* Name: bthcisock_host_close
*
* Description:
* Close a User Channel HCI socket on the Host for the given device idx.
*
* Input Parameters:
* fd: The resources associated with the open user channel are freed.
*
* Returned Value:
* Zero is returned on success; a negated errno value is returned on any
* failure.
*
****************************************************************************/
int bthcisock_host_close(int fd)
{
return close(fd);
}

View File

@ -32,8 +32,10 @@
* Public Function Prototypes
****************************************************************************/
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_open(int dev_idx);
int bthcisock_host_avail(int fd);
int bthcisock_host_close(int fd);
#endif /* _ARCH_SIM_SRC_SIM_HCISOCKET_HOST_H_ */