diff --git a/tools/btmgmt.c b/tools/btmgmt.c
index e9a8495..8eff56b 100644
--- a/tools/btmgmt.c
+++ b/tools/btmgmt.c
return len;
}
+static size_t bin2hex(const uint8_t *buf, size_t buflen, char *str,
+ size_t strlen)
+{
+ size_t i;
+
+ for (i = 0; i < buflen && i < (strlen / 2); i++)
+ sprintf(str + (i * 2), "%02x", buf[i]);
+
+ return i;
+}
+
static bool load_identity(uint16_t index, struct mgmt_irk_info *irk)
{
char identity_path[PATH_MAX];
{
const struct mgmt_rp_read_local_oob_data *rp = param;
const struct mgmt_rp_read_local_oob_ext_data *rp_ext = param;
- int i;
+ char str[33];
if (status != 0) {
error("Read Local OOB Data failed with status 0x%02x (%s)",
return noninteractive_quit(EXIT_FAILURE);
}
- print("Hash C from P-192: ");
- for (i = 0; i < 16; i++)
- print("%02x", rp->hash[i]);
- print("");
+ bin2hex(rp->hash, 16, str, sizeof(str));
+ print("Hash C from P-192: %s", str);
- print("Randomizer R with P-192: ");
- for (i = 0; i < 16; i++)
- print("%02x", rp->randomizer[i]);
- print("");
+ bin2hex(rp->randomizer, 16, str, sizeof(str));
+ print("Randomizer R with P-192: %s", str);
if (len < sizeof(*rp_ext))
return noninteractive_quit(EXIT_SUCCESS);
- print("Hash C from P-256: ");
- for (i = 0; i < 16; i++)
- print("%02x", rp_ext->hash256[i]);
- print("");
+ bin2hex(rp_ext->hash256, 16, str, sizeof(str));
+ print("Hash C from P-256: %s", str);
- print("Randomizer R with P-256: ");
- for (i = 0; i < 16; i++)
- print("%02x", rp_ext->randomizer256[i]);
- print("");
+ bin2hex(rp_ext->randomizer256, 16, str, sizeof(str));
+ print("Randomizer R with P-256: %s", str);
noninteractive_quit(EXIT_SUCCESS);
}