This is an automated email from the ASF dual-hosted git repository. btashton pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
commit 2ca99ed1bebaeb099a9a371ce1cb03bb624643a0 Author: chao.an <[email protected]> AuthorDate: Wed Dec 23 13:54:59 2020 +0800 sim/host/hcisocket: add avail/close interface Change-Id: I3d96f62c4c3c7d703bfec74952953bee4aef9c7c Signed-off-by: chao.an <[email protected]> --- arch/sim/src/sim/up_hcisocket.c | 2 +- arch/sim/src/sim/up_hcisocket_host.c | 57 ++++++++++++++++++++++++++++++++++++ arch/sim/src/sim/up_hcisocket_host.h | 4 ++- 3 files changed, 61 insertions(+), 2 deletions(-) diff --git a/arch/sim/src/sim/up_hcisocket.c b/arch/sim/src/sim/up_hcisocket.c index e95d625..d686304 100644 --- a/arch/sim/src/sim/up_hcisocket.c +++ b/arch/sim/src/sim/up_hcisocket.c @@ -177,7 +177,7 @@ int bthcisock_register(int dev_id) * ****************************************************************************/ -int bthcisock_loop() +int bthcisock_loop(void) { uint8_t type; int len; diff --git a/arch/sim/src/sim/up_hcisocket_host.c b/arch/sim/src/sim/up_hcisocket_host.c index d785c42..33fc114 100644 --- a/arch/sim/src/sim/up_hcisocket_host.c +++ b/arch/sim/src/sim/up_hcisocket_host.c @@ -63,6 +63,43 @@ struct sockaddr_hci ****************************************************************************/ /**************************************************************************** + * 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 * * Description: @@ -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); +} diff --git a/arch/sim/src/sim/up_hcisocket_host.h b/arch/sim/src/sim/up_hcisocket_host.h index 5ba3a13..411902a 100644 --- a/arch/sim/src/sim/up_hcisocket_host.h +++ b/arch/sim/src/sim/up_hcisocket_host.h @@ -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_ */
