summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPavlin Radoslavov <pavlin@google.com>2016-09-14 23:39:02 (GMT)
committergitbuildkicker <android-build@google.com>2016-09-16 23:24:56 (GMT)
commit9ef3ce8fb8b275fcd372ec673b4b496461e6b6a5 (patch)
treec8f9ce90c68f7611aa409a9e1640263df5910517
parent9817b62f3c1f74b290c12c9d0dc124435cf6fb88 (diff)
downloadandroid-system-bt-9ef3ce8fb8b275fcd372ec673b4b496461e6b6a5.tar.gz
android-system-bt-9ef3ce8fb8b275fcd372ec673b4b496461e6b6a5.tar.xz
Add BT_HCI_UNKNOWN_MESSAGE_TYPE log event
If the received HCI type is unknown, then log an event and abort. The most likely reason for that to happen is if the UART stream is corrupted. We cannot recover from that, and there is not much else we can do. Also, fixed a bug in an HCI-related unit test that was exposed by the above change. Bug: 31432127 Change-Id: Ia888c485f177af4962268bf8f593b27fd7a4b080 (cherry picked from commit 27ec0c7824cf67b8a36bf5391734e6d2fc6207e2) (cherry picked from commit e1c8ed17c7a35510f00997ca329687f73cd193d8)
-rw-r--r--EventLogTags.logtags1
-rw-r--r--hci/src/hci_hal_h4.c7
-rw-r--r--hci/test/hci_hal_h4_test.cpp25
3 files changed, 21 insertions, 12 deletions
diff --git a/EventLogTags.logtags b/EventLogTags.logtags
index 32493d8..dc1d239 100644
--- a/EventLogTags.logtags
+++ b/EventLogTags.logtags
@@ -35,3 +35,4 @@
1010000 bt_hci_timeout (opcode|1)
1010001 bt_config_source (opcode|1)
+1010002 bt_hci_unknown_type (hci_type|1)
diff --git a/hci/src/hci_hal_h4.c b/hci/src/hci_hal_h4.c
index 062b6c0..9c7afe5 100644
--- a/hci/src/hci_hal_h4.c
+++ b/hci/src/hci_hal_h4.c
@@ -38,6 +38,8 @@
// when streaming time sensitive data (A2DP).
#define HCI_THREAD_PRIORITY -19
+#define BT_HCI_UNKNOWN_MESSAGE_TYPE_NUM 1010002
+
// Our interface and modules we import
static const hci_hal_t interface;
static const hci_hal_callbacks_t *callbacks;
@@ -233,7 +235,10 @@ static void event_uart_has_bytes(eager_reader_t *reader, UNUSED_ATTR void *conte
return;
if (type_byte < DATA_TYPE_ACL || type_byte > DATA_TYPE_EVENT) {
- LOG_ERROR(LOG_TAG, "%s Unknown HCI message type. Dropping this byte 0x%x, min %x, max %x", __func__, type_byte, DATA_TYPE_ACL, DATA_TYPE_EVENT);
+ LOG_ERROR(LOG_TAG, "%s Unknown HCI message type 0x%x (min=0x%x max=0x%x). Aborting...",
+ __func__, type_byte, DATA_TYPE_ACL, DATA_TYPE_EVENT);
+ LOG_EVENT_INT(BT_HCI_UNKNOWN_MESSAGE_TYPE_NUM, type_byte);
+ assert(false && "Unknown HCI message type");
return;
}
diff --git a/hci/test/hci_hal_h4_test.cpp b/hci/test/hci_hal_h4_test.cpp
index bf62405..1b861a0 100644
--- a/hci/test/hci_hal_h4_test.cpp
+++ b/hci/test/hci_hal_h4_test.cpp
@@ -192,17 +192,18 @@ static void expect_socket_data(int fd, char first_byte, char *data) {
}
}
-static void write_packet(int fd, char first_byte, char *data) {
+static void write_packet(int fd, char first_byte, const void *data,
+ size_t datalen) {
write(fd, &first_byte, 1);
- write(fd, data, strlen(data));
+ write(fd, data, datalen);
}
-static void write_packet_reentry(int fd, char first_byte, char *data) {
+static void write_packet_reentry(int fd, char first_byte, const void *data,
+ size_t datalen) {
write(fd, &first_byte, 1);
- int length = strlen(data);
- for (int i = 0; i < length; i++) {
- write(fd, &data[i], 1);
+ for (size_t i = 0; i < datalen; i++) {
+ write(fd, static_cast<const uint8_t *>(data) + i, 1);
semaphore_wait(reentry_semaphore);
}
}
@@ -226,10 +227,11 @@ TEST_F(HciHalH4Test, test_transmit) {
TEST_F(HciHalH4Test, test_read_synchronous) {
reset_for(read_synchronous);
- write_packet(sockfd[1], DATA_TYPE_ACL, acl_data);
- write_packet(sockfd[1], HCI_BLE_EVENT, corrupted_data);
- write_packet(sockfd[1], DATA_TYPE_SCO, sco_data);
- write_packet(sockfd[1], DATA_TYPE_EVENT, event_data);
+ write_packet(sockfd[1], DATA_TYPE_ACL, acl_data, strlen(acl_data));
+ write_packet(sockfd[1], HCI_BLE_EVENT, corrupted_data,
+ sizeof(corrupted_data));
+ write_packet(sockfd[1], DATA_TYPE_SCO, sco_data, strlen(sco_data));
+ write_packet(sockfd[1], DATA_TYPE_EVENT, event_data, strlen(event_data));
// Wait for all data to be received before calling the test good
semaphore_wait(done);
@@ -242,7 +244,8 @@ TEST_F(HciHalH4Test, test_read_async_reentry) {
reentry_semaphore = semaphore_new(0);
reentry_i = 0;
- write_packet_reentry(sockfd[1], DATA_TYPE_ACL, sample_data3);
+ write_packet_reentry(sockfd[1], DATA_TYPE_ACL, sample_data3,
+ strlen(sample_data3));
// write_packet_reentry ensures the data has been received
semaphore_free(reentry_semaphore);