#include "lib/bluetooth.h"
#include "src/shared/util.h"
+#include "src/shared/tester.h"
#include "monitor/bt.h"
#include "monitor/rfcomm.h"
#include "bthost.h"
bool conn_init;
bool le;
bool sc;
+
+ bthost_debug_func_t debug_callback;
+ bthost_destroy_func_t debug_destroy;
+ void *debug_data;
};
struct bthost *bthost_create(void)
static void send_packet(struct bthost *bthost, const struct iovec *iov,
int iovlen)
{
+ int i;
+
if (!bthost->send_handler)
return;
+ for (i = 0; i < iovlen; i++) {
+ if (!i)
+ util_hexdump('<', iov[i].iov_base, iov[i].iov_len,
+ bthost->debug_callback, bthost->debug_data);
+ else
+ util_hexdump(' ', iov[i].iov_base, iov[i].iov_len,
+ bthost->debug_callback, bthost->debug_data);
+ }
+
bthost->send_handler(iov, iovlen, bthost->send_data);
}
uint8_t pkt = BT_H4_CMD_PKT;
struct iovec iov[3];
+ util_debug(bthost->debug_callback, bthost->debug_data,
+ "command 0x%02x", opcode);
+
iov[0].iov_base = &pkt;
iov[0].iov_len = sizeof(pkt);
bthost->ready_cb = cb;
}
+bool bthost_set_debug(struct bthost *bthost, bthost_debug_func_t callback,
+ void *user_data, bthost_destroy_func_t destroy)
+{
+ if (!bthost)
+ return false;
+
+ if (bthost->debug_destroy)
+ bthost->debug_destroy(bthost->debug_data);
+
+ bthost->debug_callback = callback;
+ bthost->debug_destroy = destroy;
+ bthost->debug_data = user_data;
+
+ return true;
+}
+
static void read_local_features_complete(struct bthost *bthost,
const void *data, uint8_t len)
{
case BT_HCI_CMD_LE_SET_EXT_ADV_ENABLE:
break;
default:
- printf("Unhandled cmd_complete opcode 0x%04x\n", opcode);
+ util_debug(bthost->debug_callback, bthost->debug_data,
+ "Unhandled cmd_complete opcode 0x%04x", opcode);
break;
}
if (len < 1)
return;
+ util_debug(bthost->debug_callback, bthost->debug_data,
+ "event 0x%02x", *event);
+
switch (*event) {
case BT_HCI_EVT_LE_CONN_COMPLETE:
evt_le_conn_complete(bthost, evt_data, len - 1);
evt_le_ext_conn_complete(bthost, evt_data, len - 1);
break;
default:
- printf("Unsupported LE Meta event 0x%2.2x\n", *event);
+ util_debug(bthost->debug_callback, bthost->debug_data,
+ "Unsupported LE Meta event 0x%2.2x", *event);
break;
}
}
param = data + sizeof(*hdr);
+ util_debug(bthost->debug_callback, bthost->debug_data,
+ "event 0x%02x", hdr->evt);
+
switch (hdr->evt) {
case BT_HCI_EVT_CMD_COMPLETE:
evt_cmd_complete(bthost, param, hdr->plen);
break;
default:
- printf("Unsupported event 0x%2.2x\n", hdr->evt);
+ util_debug(bthost->debug_callback, bthost->debug_data,
+ "Unsupported event 0x%2.2x", hdr->evt);
break;
}
}
break;
default:
- printf("Unknown L2CAP code 0x%02x\n", hdr->code);
+ util_debug(bthost->debug_callback, bthost->debug_data,
+ "Unknown L2CAP code 0x%02x", hdr->code);
ret = false;
}
break;
default:
- printf("Unknown L2CAP code 0x%02x\n", hdr->code);
+ util_debug(bthost->debug_callback, bthost->debug_data,
+ "Unknown L2CAP code 0x%02x", hdr->code);
ret = false;
}
rfcomm_uih_recv(bthost, conn, l2conn, data, len);
break;
default:
- printf("Unknown frame type\n");
+ util_debug(bthost->debug_callback, bthost->debug_data,
+ "Unknown frame type");
break;
}
}
handle = acl_handle(acl_hdr->handle);
conn = bthost_find_conn(bthost, handle);
if (!conn) {
- printf("ACL data for unknown handle 0x%04x\n", handle);
+ util_debug(bthost->debug_callback, bthost->debug_data,
+ "ACL data for unknown handle 0x%04x", handle);
return;
}
if (l2conn && l2conn->psm == 0x0003)
process_rfcomm(bthost, conn, l2conn, l2_data, l2_len);
else
- printf("Packet for unknown CID 0x%04x (%u)\n", cid,
- cid);
+ util_debug(bthost->debug_callback, bthost->debug_data,
+ "Packet for unknown CID 0x%04x (%u)",
+ cid, cid);
break;
}
}
if (len < 1)
return;
+ util_hexdump('>', data, len, bthost->debug_callback,
+ bthost->debug_data);
+
pkt_type = ((const uint8_t *) data)[0];
switch (pkt_type) {
process_acl(bthost, data + 1, len - 1);
break;
default:
- printf("Unsupported packet 0x%2.2x\n", pkt_type);
+ util_debug(bthost->debug_callback, bthost->debug_data,
+ "Unsupported packet 0x%2.2x", pkt_type);
break;
}
}