i'm kind of outdoors now, away from the raspi 4. I didn't find my bled112 dongles. here is a draft:

diff --git a/tools/hciattach.c b/tools/hciattach.c
index 276a4e56e..c5f3c7462 100644
--- a/tools/hciattach.c
+++ b/tools/hciattach.c
@@ -38,6 +38,30 @@
 
 #include "hciattach.h"
 
+void hex(int pfx, int fd, int buf, int len) {
+ while (len > 0) {
+ fprintf(stderr, "%s %d", pfx, fd);
+ for (int i = 0; i < len && i < 16; i ++) {
+ fprintf(stderr, " %02x", buf[i]);
+ }
+ fprintf(stderr, "\n")
+ len -= 16;
+ buf -= 16;
+ }
+}
+
+int dbg_read(int fd, int buf, int len) {
+ int r = read(fd, buf, len);
+ hex("<", fd, buf, r);
+ return r;
+}
+
+int dbg_write(int fd, int buf, int len) {
+ int r = write(fd, buf, len);
+ hex(">", fd, buf, r);
+ return r;
+}
+
 struct uart_t {
  char *type;
  int  m_id;
@@ -102,7 +126,7 @@ int read_hci_event(int fd, unsigned char* buf, int size)
  /* The first byte identifies the packet type. For HCI event packets, it
  * should be 0x04, so we read until we get to the 0x04. */
  while (1) {
- r = read(fd, buf, 1);
+ r = dbg_read(fd, buf, 1);
  if (r <= 0)
  return -1;
  if (buf[0] == 0x04)
@@ -112,7 +136,7 @@ int read_hci_event(int fd, unsigned char* buf, int size)
 
  /* The next two bytes are the event code and parameter total length. */
  while (count < 3) {
- r = read(fd, buf + count, 3 - count);
+ r = dbg_read(fd, buf + count, 3 - count);
  if (r <= 0)
  return -1;
  count += r;
@@ -125,7 +149,7 @@ int read_hci_event(int fd, unsigned char* buf, int size)
  remain = size - 3;
 
  while ((count - 3) < remain) {
- r = read(fd, buf + count, remain - (count - 3));
+ r = dbg_read(fd, buf + count, remain - (count - 3));
  if (r <= 0)
  return -1;
  count += r;
@@ -180,7 +204,7 @@ static int ericsson(int fd, struct uart_t *u, struct termios *ti)
  }
 
  /* Send initialization command */
- if (write(fd, cmd, 5) != 5) {
+ if (dbg_write(fd, cmd, 5) != 5) {
  perror("Failed to write init command");
  return -1;
  }
@@ -217,7 +241,7 @@ static int digi(int fd, struct uart_t *u, struct termios *ti)
  }
 
  /* Send initialization command */
- if (write(fd, cmd, 5) != 5) {
+ if (dbg_write(fd, cmd, 5) != 5) {
  perror("Failed to write init command");
  return -1;
  }
@@ -271,7 +295,7 @@ static int read_check(int fd, void *buf, int count)
  int res;
 
  do {
- res = read(fd, buf, count);
+ res = dbg_read(fd, buf, count);
  if (res != -1) {
  buf += res;
  count -= res;
@@ -297,7 +321,7 @@ static void bcsp_tshy_sig_alarm(int sig)
 
  if (retries < bcsp_max_retries) {
  retries++;
- if (write(serial_fd, &bcsp_sync_pkt, 10) < 0)
+ if (dbg_write(serial_fd, &bcsp_sync_pkt, 10) < 0)
  return;
  alarm(1);
  return;
@@ -315,7 +339,7 @@ static void bcsp_tconf_sig_alarm(int sig)
 
  if (retries < bcsp_max_retries){
  retries++;
- if (write(serial_fd, &bcsp_conf_pkt, 10) < 0)
+ if (dbg_write(serial_fd, &bcsp_conf_pkt, 10) < 0)
  return;
  alarm(1);
  return;
@@ -393,7 +417,7 @@ static int bcsp(int fd, struct uart_t *u, struct termios *ti)
  }
 
  if (!memcmp(bcspp, bcspsync, 4)) {
- if (write(fd, &bcsp_sync_resp_pkt,10) < 0)
+ if (dbg_write(fd, &bcsp_sync_resp_pkt,10) < 0)
  return -1;
  } else if (!memcmp(bcspp, bcspsyncresp, 4))
  break;
@@ -438,9 +462,9 @@ static int bcsp(int fd, struct uart_t *u, struct termios *ti)
  }
 
  if (!memcmp(bcspp, bcspsync, 4))
- len = write(fd, &bcsp_sync_resp_pkt, 10);
+ len = dbg_write(fd, &bcsp_sync_resp_pkt, 10);
  else if (!memcmp(bcspp, bcspconf, 4))
- len = write(fd, &bcsp_conf_resp_pkt, 10);
+ len = dbg_write(fd, &bcsp_conf_resp_pkt, 10);
  else if (!memcmp(bcspp, bcspconfresp,  4))
  break;
  else
@@ -508,7 +532,7 @@ static int csr(int fd, struct uart_t *u, struct termios *ti)
 
  /* Send command */
  do {
- if (write(fd, cmd, clen) != clen) {
+ if (dbg_write(fd, cmd, clen) != clen) {
  perror("Failed to write init command (GET_BUILD_ID)");
  return -1;
  }
@@ -552,7 +576,7 @@ static int csr(int fd, struct uart_t *u, struct termios *ti)
 #ifdef CSR_DEBUG
  /* Send command */
  do {
- if (write(fd, cmd, clen) != clen) {
+ if (dbg_write(fd, cmd, clen) != clen) {
  perror("Failed to write init command (GET_BUILD_ID)");
  return -1;
  }
@@ -618,7 +642,7 @@ static int csr(int fd, struct uart_t *u, struct termios *ti)
 #endif
 
  /* Send the command to set the CSR UART speed */
- if (write(fd, cmd, clen) != clen) {
+ if (dbg_write(fd, cmd, clen) != clen) {
  perror("Failed to write init command (SET_UART_SPEED)");
  return -1;
  }
@@ -673,7 +697,7 @@ static int swave(int fd, struct uart_t *u, struct termios *ti)
  }
 
  /* Send initialization command */
- if (write(fd, cmd, 10) != 10) {
+ if (dbg_write(fd, cmd, 10) != 10) {
  perror("Failed to write init command");
  return -1;
  }
@@ -685,7 +709,7 @@ static int swave(int fd, struct uart_t *u, struct termios *ti)
 
  nanosleep(&tm, NULL);
 
- r = read(fd, rsp, sizeof(rsp));
+ r = dbg_read(fd, rsp, sizeof(rsp));
  if (r > 0) {
  // guess it's okay, but we should parse the reply. But since
  // I don't react on an error anyway ... todo
@@ -714,7 +738,7 @@ static int swave(int fd, struct uart_t *u, struct termios *ti)
  cmd[3] = 0x00;
 
  /* Send reset command */
- if (write(fd, cmd, 4) != 4) {
+ if (dbg_write(fd, cmd, 4) != 4) {
  perror("Can't write Silicon Wave reset cmd.");
  return -1;
  }
@@ -779,7 +803,7 @@ static int st(int fd, struct uart_t *u, struct termios *ti)
  }
 
  /* Send initialization command */
- if (write(fd, cmd, 5) != 5) {
+ if (dbg_write(fd, cmd, 5) != 5) {
  perror("Failed to write init command");
  return -1;
  }
@@ -855,7 +879,7 @@ static int bcm2035(int fd, struct uart_t *u, struct termios *ti)
  cmd[3] = 0x00;
 
  /* Send command */
- if (write(fd, cmd, 4) != 4) {
+ if (dbg_write(fd, cmd, 4) != 4) {
  fprintf(stderr, "Failed to write reset command\n");
  return -1;
  }
@@ -877,7 +901,7 @@ static int bcm2035(int fd, struct uart_t *u, struct termios *ti)
  str2ba(u->bdaddr, (bdaddr_t *) (cmd + 4));
 
  /* Send command */
- if (write(fd, cmd, 10) != 10) {
+ if (dbg_write(fd, cmd, 10) != 10) {
  fprintf(stderr, "Failed to write BD_ADDR command\n");
  return -1;
  }
@@ -898,7 +922,7 @@ static int bcm2035(int fd, struct uart_t *u, struct termios *ti)
  cmd[3] = 0x00;
 
  /* Send command */
- if (write(fd, cmd, 4) != 4) {
+ if (dbg_write(fd, cmd, 4) != 4) {
  fprintf(stderr, "Failed to write \"read local version\" "
  "command\n");
  return -1;
@@ -919,7 +943,7 @@ static int bcm2035(int fd, struct uart_t *u, struct termios *ti)
  cmd[3] = 0x00;
 
  /* Send command */
- if (write(fd, cmd, 4) != 4) {
+ if (dbg_write(fd, cmd, 4) != 4) {
  fprintf(stderr, "Failed to write \"read local supported "
  "commands\" command\n");
  return -1;
@@ -965,7 +989,7 @@ static int bcm2035(int fd, struct uart_t *u, struct termios *ti)
  cmd[4], cmd[5]);
 
  /* Send command */
- if (write(fd, cmd, 6) != 6) {
+ if (dbg_write(fd, cmd, 6) != 6) {
  fprintf(stderr, "Failed to write \"set baud rate\" command\n");
  return -1;
  }