refactor(ble_log): preserve full HCI type byte in ble_log_write_hci

ble_log_write_hci encoded the direction in bit 7 of the caller's type
byte and then cleared that bit unconditionally after the write,
leaving the caller's buffer mutated. Save the complete type byte, set
bit 7 only around the synchronous copy, and restore it afterwards;
the direction argument is now treated as a boolean.

HCI H4 type bytes (0x01..0x04) always have bit 7 clear, so no legal
input observes a behavior change.
This commit is contained in:
Zhou Xiao
2026-09-10 15:39:23 +08:00
committed by guozifan
parent 496c0b6377
commit a1cbd92328
+11 -8
View File
@@ -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 */