system/bt
Revisión | e1c8ed17c7a35510f00997ca329687f73cd193d8 (tree) |
---|---|
Tiempo | 2016-09-17 06:46:23 |
Autor | Pavlin Radoslavov <pavlin@goog...> |
Commiter | Pavlin Radoslavov |
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)
@@ -35,3 +35,4 @@ | ||
35 | 35 | |
36 | 36 | 1010000 bt_hci_timeout (opcode|1) |
37 | 37 | 1010001 bt_config_source (opcode|1) |
38 | +1010002 bt_hci_unknown_type (hci_type|1) |
@@ -38,6 +38,8 @@ | ||
38 | 38 | // when streaming time sensitive data (A2DP). |
39 | 39 | #define HCI_THREAD_PRIORITY -19 |
40 | 40 | |
41 | +#define BT_HCI_UNKNOWN_MESSAGE_TYPE_NUM 1010002 | |
42 | + | |
41 | 43 | // Our interface and modules we import |
42 | 44 | static const hci_hal_t interface; |
43 | 45 | 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 | ||
233 | 235 | return; |
234 | 236 | |
235 | 237 | if (type_byte < DATA_TYPE_ACL || type_byte > DATA_TYPE_EVENT) { |
236 | - 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); | |
238 | + LOG_ERROR(LOG_TAG, "%s Unknown HCI message type 0x%x (min=0x%x max=0x%x). Aborting...", | |
239 | + __func__, type_byte, DATA_TYPE_ACL, DATA_TYPE_EVENT); | |
240 | + LOG_EVENT_INT(BT_HCI_UNKNOWN_MESSAGE_TYPE_NUM, type_byte); | |
241 | + assert(false && "Unknown HCI message type"); | |
237 | 242 | return; |
238 | 243 | } |
239 | 244 |
@@ -192,17 +192,18 @@ static void expect_socket_data(int fd, char first_byte, char *data) { | ||
192 | 192 | } |
193 | 193 | } |
194 | 194 | |
195 | -static void write_packet(int fd, char first_byte, char *data) { | |
195 | +static void write_packet(int fd, char first_byte, const void *data, | |
196 | + size_t datalen) { | |
196 | 197 | write(fd, &first_byte, 1); |
197 | - write(fd, data, strlen(data)); | |
198 | + write(fd, data, datalen); | |
198 | 199 | } |
199 | 200 | |
200 | -static void write_packet_reentry(int fd, char first_byte, char *data) { | |
201 | +static void write_packet_reentry(int fd, char first_byte, const void *data, | |
202 | + size_t datalen) { | |
201 | 203 | write(fd, &first_byte, 1); |
202 | 204 | |
203 | - int length = strlen(data); | |
204 | - for (int i = 0; i < length; i++) { | |
205 | - write(fd, &data[i], 1); | |
205 | + for (size_t i = 0; i < datalen; i++) { | |
206 | + write(fd, static_cast<const uint8_t *>(data) + i, 1); | |
206 | 207 | semaphore_wait(reentry_semaphore); |
207 | 208 | } |
208 | 209 | } |
@@ -226,10 +227,11 @@ TEST_F(HciHalH4Test, test_transmit) { | ||
226 | 227 | TEST_F(HciHalH4Test, test_read_synchronous) { |
227 | 228 | reset_for(read_synchronous); |
228 | 229 | |
229 | - write_packet(sockfd[1], DATA_TYPE_ACL, acl_data); | |
230 | - write_packet(sockfd[1], HCI_BLE_EVENT, corrupted_data); | |
231 | - write_packet(sockfd[1], DATA_TYPE_SCO, sco_data); | |
232 | - write_packet(sockfd[1], DATA_TYPE_EVENT, event_data); | |
230 | + write_packet(sockfd[1], DATA_TYPE_ACL, acl_data, strlen(acl_data)); | |
231 | + write_packet(sockfd[1], HCI_BLE_EVENT, corrupted_data, | |
232 | + sizeof(corrupted_data)); | |
233 | + write_packet(sockfd[1], DATA_TYPE_SCO, sco_data, strlen(sco_data)); | |
234 | + write_packet(sockfd[1], DATA_TYPE_EVENT, event_data, strlen(event_data)); | |
233 | 235 | |
234 | 236 | // Wait for all data to be received before calling the test good |
235 | 237 | semaphore_wait(done); |
@@ -242,7 +244,8 @@ TEST_F(HciHalH4Test, test_read_async_reentry) { | ||
242 | 244 | reentry_semaphore = semaphore_new(0); |
243 | 245 | reentry_i = 0; |
244 | 246 | |
245 | - write_packet_reentry(sockfd[1], DATA_TYPE_ACL, sample_data3); | |
247 | + write_packet_reentry(sockfd[1], DATA_TYPE_ACL, sample_data3, | |
248 | + strlen(sample_data3)); | |
246 | 249 | |
247 | 250 | // write_packet_reentry ensures the data has been received |
248 | 251 | semaphore_free(reentry_semaphore); |