@@ -691,8 +691,7 @@ static void send_command(struct bthost *bthost, uint16_t opcode,
uint8_t pkt = BT_H4_CMD_PKT;
struct iovec iov[3];
- util_debug(bthost->debug_callback, bthost->debug_data,
- "command 0x%02x", opcode);
+ bthost_debug(bthost, "command 0x%02x", opcode);
iov[0].iov_base = &pkt;
iov[0].iov_len = sizeof(pkt);
@@ -794,6 +793,18 @@ bool bthost_set_debug(struct bthost *bthost, bthost_debug_func_t callback,
return true;
}
+void bthost_debug(struct bthost *host, const char *format, ...)
+{
+ va_list ap;
+
+ if (!host || !format || !host->debug_callback)
+ return;
+
+ va_start(ap, format);
+ util_debug_va(host->debug_callback, host->debug_data, format, ap);
+ va_end(ap);
+}
+
static void read_local_features_complete(struct bthost *bthost,
const void *data, uint8_t len)
{
@@ -870,8 +881,8 @@ static void evt_cmd_complete(struct bthost *bthost, const void *data,
case BT_HCI_CMD_LE_SET_EXT_ADV_ENABLE:
break;
default:
- util_debug(bthost->debug_callback, bthost->debug_data,
- "Unhandled cmd_complete opcode 0x%04x", opcode);
+ bthost_debug(bthost, "Unhandled cmd_complete opcode 0x%04x",
+ opcode);
break;
}
@@ -1298,8 +1309,7 @@ static void evt_le_meta_event(struct bthost *bthost, const void *data,
if (len < 1)
return;
- util_debug(bthost->debug_callback, bthost->debug_data,
- "event 0x%02x", *event);
+ bthost_debug(bthost, "event 0x%02x", *event);
switch (*event) {
case BT_HCI_EVT_LE_CONN_COMPLETE:
@@ -1321,8 +1331,8 @@ static void evt_le_meta_event(struct bthost *bthost, const void *data,
evt_le_cis_req(bthost, evt_data, len - 1);
break;
default:
- util_debug(bthost->debug_callback, bthost->debug_data,
- "Unsupported LE Meta event 0x%2.2x", *event);
+ bthost_debug(bthost, "Unsupported LE Meta event 0x%2.2x",
+ *event);
break;
}
}
@@ -1340,8 +1350,7 @@ static void process_evt(struct bthost *bthost, const void *data, uint16_t len)
param = data + sizeof(*hdr);
- util_debug(bthost->debug_callback, bthost->debug_data,
- "event 0x%02x", hdr->evt);
+ bthost_debug(bthost, "event 0x%02x", hdr->evt);
switch (hdr->evt) {
case BT_HCI_EVT_CMD_COMPLETE:
@@ -1409,8 +1418,7 @@ static void process_evt(struct bthost *bthost, const void *data, uint16_t len)
break;
default:
- util_debug(bthost->debug_callback, bthost->debug_data,
- "Unsupported event 0x%2.2x", hdr->evt);
+ bthost_debug(bthost, "Unsupported event 0x%2.2x", hdr->evt);
break;
}
}
@@ -1754,8 +1762,7 @@ static void l2cap_sig(struct bthost *bthost, struct btconn *conn,
break;
default:
- util_debug(bthost->debug_callback, bthost->debug_data,
- "Unknown L2CAP code 0x%02x", hdr->code);
+ bthost_debug(bthost, "Unknown L2CAP code 0x%02x", hdr->code);
ret = false;
}
@@ -1987,8 +1994,7 @@ static void l2cap_le_sig(struct bthost *bthost, struct btconn *conn,
break;
default:
- util_debug(bthost->debug_callback, bthost->debug_data,
- "Unknown L2CAP code 0x%02x", hdr->code);
+ bthost_debug(bthost, "Unknown L2CAP code 0x%02x", hdr->code);
ret = false;
}
@@ -2329,8 +2335,7 @@ static void process_rfcomm(struct bthost *bthost, struct btconn *conn,
rfcomm_uih_recv(bthost, conn, l2conn, data, len);
break;
default:
- util_debug(bthost->debug_callback, bthost->debug_data,
- "Unknown frame type");
+ bthost_debug(bthost, "Unknown frame type");
break;
}
}
@@ -2355,8 +2360,8 @@ static void process_acl(struct bthost *bthost, const void *data, uint16_t len)
handle = acl_handle(acl_hdr->handle);
conn = bthost_find_conn(bthost, handle);
if (!conn) {
- util_debug(bthost->debug_callback, bthost->debug_data,
- "ACL data for unknown handle 0x%04x", handle);
+ bthost_debug(bthost, "ACL data for unknown handle 0x%04x",
+ handle);
return;
}
@@ -2392,7 +2397,7 @@ static void process_acl(struct bthost *bthost, const void *data, uint16_t len)
if (l2conn && l2conn->psm == 0x0003)
process_rfcomm(bthost, conn, l2conn, l2_data, l2_len);
else
- util_debug(bthost->debug_callback, bthost->debug_data,
+ bthost_debug(bthost,
"Packet for unknown CID 0x%04x (%u)",
cid, cid);
break;
@@ -2422,8 +2427,7 @@ void bthost_receive_h4(struct bthost *bthost, const void *data, uint16_t len)
process_acl(bthost, data + 1, len - 1);
break;
default:
- util_debug(bthost->debug_callback, bthost->debug_data,
- "Unsupported packet 0x%2.2x", pkt_type);
+ bthost_debug(bthost, "Unsupported packet 0x%2.2x", pkt_type);
break;
}
}
@@ -27,6 +27,8 @@ typedef void (*bthost_debug_func_t)(const char *str, void *user_data);
typedef void (*bthost_destroy_func_t)(void *user_data);
bool bthost_set_debug(struct bthost *bthost, bthost_debug_func_t callback,
void *user_data, bthost_destroy_func_t destroy);
+void bthost_debug(struct bthost *bthost, const char *format, ...)
+ __attribute__((format(printf, 2, 3)));
void bthost_set_send_handler(struct bthost *bthost, bthost_send_func handler,
void *user_data);
@@ -454,7 +454,7 @@ void hciemu_unref(struct hciemu *hciemu)
free(hciemu);
}
-static void bthost_debug(const char *str, void *user_data)
+static void bthost_print(const char *str, void *user_data)
{
struct hciemu *hciemu = user_data;
@@ -484,7 +484,7 @@ static void hciemu_client_set_debug(void *data, void *user_data)
struct hciemu *hciemu = user_data;
btdev_set_debug(client->dev, btdev_client_debug, hciemu, NULL);
- bthost_set_debug(client->host, bthost_debug, hciemu, NULL);
+ bthost_set_debug(client->host, bthost_print, hciemu, NULL);
}
bool hciemu_set_debug(struct hciemu *hciemu, hciemu_debug_func_t callback,
@@ -358,7 +358,8 @@ static bool verify_random(struct smp_conn *conn, const uint8_t rnd[16])
return false;
if (memcmp(conn->pcnf, confirm, sizeof(conn->pcnf)) != 0) {
- printf("Confirmation values don't match\n");
+ bthost_debug(conn->smp->bthost,
+ "Confirmation values don't match");
return false;
}
@@ -698,12 +699,13 @@ void smp_data(void *conn_data, const void *data, uint16_t len)
uint8_t opcode;
if (len < 1) {
- printf("Received too small SMP PDU\n");
+ bthost_debug(conn->smp->bthost, "Received too small SMP PDU");
return;
}
if (conn->addr_type == BDADDR_BREDR) {
- printf("Received BR/EDR SMP data on LE link\n");
+ bthost_debug(conn->smp->bthost,
+ "Received BR/EDR SMP data on LE link");
return;
}
@@ -754,12 +756,13 @@ void smp_bredr_data(void *conn_data, const void *data, uint16_t len)
uint8_t opcode;
if (len < 1) {
- printf("Received too small SMP PDU\n");
+ bthost_debug(conn->smp->bthost, "Received too small SMP PDU");
return;
}
if (conn->addr_type != BDADDR_BREDR) {
- printf("Received LE SMP data on BR/EDR link\n");
+ bthost_debug(conn->smp->bthost,
+ "Received LE SMP data on BR/EDR link");
return;
}
@@ -853,6 +856,7 @@ void *smp_conn_add(void *smp_data, uint16_t handle,
{
struct smp *smp = smp_data;
struct smp_conn *conn;
+ char ia_str[18], ra_str[18];
conn = malloc(sizeof(struct smp_conn));
if (!conn)
@@ -870,6 +874,12 @@ void *smp_conn_add(void *smp_data, uint16_t handle,
memcpy(conn->ia, ia, 6);
memcpy(conn->ra, ra, 6);
+ ba2str((bdaddr_t *) ia, ia_str);
+ ba2str((bdaddr_t *) ra, ra_str);
+
+ bthost_debug(smp->bthost, "ia %s type 0x%02x ra %s type 0x%02x",
+ ia_str, ia_type, ra_str, ra_type);
+
bt_crypto_random_bytes(smp->crypto, conn->prnd, sizeof(conn->prnd));
return conn;
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com> This adds bthost_debug which wraps util_debug and make use of it in smp.c. --- emulator/bthost.c | 50 +++++++++++++++++++++++++---------------------- emulator/bthost.h | 2 ++ emulator/hciemu.c | 4 ++-- emulator/smp.c | 20 ++++++++++++++----- 4 files changed, 46 insertions(+), 30 deletions(-)