summaryrefslogtreecommitdiffstats
path: root/bluetooth
diff options
context:
space:
mode:
authorPeng Qi <peng.qi@mediatek.com>2017-06-19 18:01:07 +0800
committerTing Zheng <ting.zheng@mediatek.com>2017-06-30 12:32:11 -0700
commit92afd74a15d15b0ad6eb619a8ad3a864a4f6e71c (patch)
tree2955d4b4241a56017f6f64be5caad5eb0e6cdfb4 /bluetooth
parent1bbe51d0b5bef615692afe6ccc24259c1b2208e4 (diff)
downloadplatform_hardware_interfaces-92afd74a15d15b0ad6eb619a8ad3a864a4f6e71c.tar.gz
platform_hardware_interfaces-92afd74a15d15b0ad6eb619a8ad3a864a4f6e71c.tar.bz2
platform_hardware_interfaces-92afd74a15d15b0ad6eb619a8ad3a864a4f6e71c.zip
BT HAL H4 write flow
If to send type and data separately for one HCI packet, it will cause two system call context switch to kernel space, which will introduce software overhead on data path. Plus, if vendor does not use pure UART interface, it causes different data behavior on BUS and may not adapt to all vendors as legacy HAL did. Considering backward-compatibility, to use writev to send type and data together once as legacy BT HAL did. Test: H4 UTTest, BT VTS test, Bluetooth on/off Change-Id: I2d93085fe0c01b48d0e3729a3fa85b5b27335b2c
Diffstat (limited to 'bluetooth')
-rw-r--r--bluetooth/1.0/default/h4_protocol.cc21
1 files changed, 16 insertions, 5 deletions
diff --git a/bluetooth/1.0/default/h4_protocol.cc b/bluetooth/1.0/default/h4_protocol.cc
index 8f24b5eeac..2df2b3b914 100644
--- a/bluetooth/1.0/default/h4_protocol.cc
+++ b/bluetooth/1.0/default/h4_protocol.cc
@@ -18,8 +18,10 @@
#define LOG_TAG "android.hardware.bluetooth-hci-h4"
#include <android-base/logging.h>
-#include <assert.h>
+#include <errno.h>
#include <fcntl.h>
+#include <log/log.h>
+#include <sys/uio.h>
namespace android {
namespace hardware {
@@ -27,11 +29,20 @@ namespace bluetooth {
namespace hci {
size_t H4Protocol::Send(uint8_t type, const uint8_t* data, size_t length) {
- int rv = WriteSafely(uart_fd_, &type, sizeof(type));
- if (rv == sizeof(type)) {
- rv = WriteSafely(uart_fd_, data, length);
+ struct iovec iov[] = {{&type, sizeof(type)},
+ {const_cast<uint8_t*>(data), length}};
+ ssize_t ret = 0;
+ do {
+ ret = TEMP_FAILURE_RETRY(writev(uart_fd_, iov, sizeof(iov) / sizeof(iov[0])));
+ } while (-1 == ret && EAGAIN == errno);
+
+ if (ret == -1) {
+ ALOGE("%s error writing to UART (%s)", __func__, strerror(errno));
+ } else if (ret == 0) {
+ // Nothing written :(
+ ALOGE("%s zero bytes written - something went wrong...", __func__);
}
- return rv;
+ return ret;
}
void H4Protocol::OnPacketReady() {