diff --git a/components/bt/common/ble_log/include/ble_log.h b/components/bt/common/ble_log/include/ble_log.h index 0a358a34f34..7668faf4d48 100644 --- a/components/bt/common/ble_log/include/ble_log.h +++ b/components/bt/common/ble_log/include/ble_log.h @@ -45,14 +45,17 @@ typedef enum { #define BLE_LOG_HCI_DOWNSTREAM 0 #define BLE_LOG_HCI_UPSTREAM 1 -/* HCI Log Write Macro - * Encodes direction in MSB of data[0] (HCI type byte) before writing. - * Safe because ble_log_write_hex -> ble_log_lbm_write_trans does synchronous memcpy. - * Parser reads MSB to determine direction; old firmware with MSB=0 defaults to "sent". */ -#define ble_log_write_hci(direction, data, len) do { \ - (data)[0] |= ((direction) << 7); \ - ble_log_write_hex(BLE_LOG_SRC_HCI, (data), (len)); \ - (data)[0] &= 0x7F; \ +/* Encodes HCI direction in payload byte 0 bit 7 for the synchronous copy, + * then restores the complete original HCI type byte. The caller guarantees a + * non-NULL buffer with len > 0. */ +#define ble_log_write_hci(direction, data, len) do { \ + uint8_t *const ble_log_hci_data__ = (data); \ + const uint8_t ble_log_hci_type__ = ble_log_hci_data__[0]; \ + ble_log_hci_data__[0] = (ble_log_hci_type__ & 0x7fU) | \ + ((direction) ? 0x80U : 0U); \ + (void)ble_log_write_hex(BLE_LOG_SRC_HCI, ble_log_hci_data__, \ + (len)); \ + ble_log_hci_data__[0] = ble_log_hci_type__; \ } while (0) /* INTERFACE */