diff --git a/arch/sim/src/sim/up_hcisocket.c b/arch/sim/src/sim/up_hcisocket.c index ff9da37343a..42125bd2b4a 100644 --- a/arch/sim/src/sim/up_hcisocket.c +++ b/arch/sim/src/sim/up_hcisocket.c @@ -179,7 +179,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 d785c4240a3..33fc1140ada 100644 --- a/arch/sim/src/sim/up_hcisocket_host.c +++ b/arch/sim/src/sim/up_hcisocket_host.c @@ -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); +} diff --git a/arch/sim/src/sim/up_hcisocket_host.h b/arch/sim/src/sim/up_hcisocket_host.h index 5ba3a13a9e2..411902a8c0e 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_ */