Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions drivers/bluetooth/bcm4361/hakios.bt_vsc.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,16 @@ static const struct bt_vsc_rule bt_vsc_table[] = {
"HDR Control off: done (this chip has no HDR, so it is off); HDR on stays refused" },
/*
* 0xFE3B, LE Meta Get LP-Core Statistics (one byte; phone 1 sent 01): the counters of Apple's low-power scan core.
* bluetoothd's parser reads them as 32- and 16-bit words, 48 and 8 of them at most (208 bytes), each asserting that
* it is there; it was the last command refused before each restart on phone 1 (17 November). This chip has no LP
* core, so every counter of it is zero: status 00 and 208 zero bytes. (BT_NO_SCAN_CORE=1 on the root should stop
* bluetoothd asking.)
* bluetoothd's parser (_BCM_LowPowerCoreStatsEventParser, bcm_vsc.c) reads them in order as 32- and 16-bit words,
* each asserting that it is there ("ByteStream_NumReadBytesAvail(*pBs) >= 4" or ">= 2") and none checking that the
* reply ends after them: iOS 27.0.1 (24A446) reads 48 and 8 of them (208 bytes); iOS 27.2.1 (24B156) reads 49 and 8
* (43 x 32, 4 x 16, 2 x 32, 4 x 16, 4 x 32 bits: 212 bytes; its last check is at byte 208). 208 bytes made 24B156's
* bluetoothd abort on that last check and restart, 15-17 times in 15 minutes (phone 2, 19 November). The reply is the
* 212 bytes 24B156 reads, which is also "at least 208" for 24A446; more would only be bytes no parser reads. It was
* the last command refused before each restart on phone 1 (17 November). This chip has no LP core, so every counter
* of it is zero: status 00 and 212 zero bytes. (BT_NO_SCAN_CORE=1 on the root should stop bluetoothd asking.)
*/
{ 0xFE3B, BT_VSC_ANY, BT_VSC_ANY, 0x00, 0, { 0 }, 208, 0, NULL,
{ 0xFE3B, BT_VSC_ANY, BT_VSC_ANY, 0x00, 0, { 0 }, 212, 0, NULL,
"LP-core statistics: all zero (this chip has no LP core)" },
/* bluetoothd restarts when this one is refused (phone 1, 17 November): above */
{ 0xFE37, BT_VSC_ANY, BT_VSC_ANY, 0, 0, { 0 }, 0, 0x200B, bt_vsc_x_scan_params,
Expand Down
41 changes: 39 additions & 2 deletions tools/bt_vsc_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,42 @@ table_itself(void)
}
}

/*
* What bluetoothd's parser reads after the status of each answered reply, per iOS build (from the binaries' structure:
* every read asserts that its bytes are there; none checks that the reply ends after them). An ANSWER entry must give
* at least this many bytes for every build listed, or that build's bluetoothd aborts.
*/
static const struct {
uint16_t opcode;
const char *build;
unsigned need;
} parser_reads[] = {
{ 0xFDDA, "24A446", 4 },
{ 0xFE3B, "24A446", 208 }, /* 48 x 32 + 8 x 16 bits */
{ 0xFE3B, "24B156", 212 }, /* 49 x 32 + 8 x 16 bits */
};

static void
reply_lengths(void)
{
for (size_t k = 0; k < sizeof(parser_reads) / sizeof(parser_reads[0]); k++) {
bool found = false;

for (size_t i = 0; i < sizeof(bt_vsc_table) / sizeof(bt_vsc_table[0]); i++) {
const struct bt_vsc_rule *r = &bt_vsc_table[i];

if (r->opcode != parser_reads[k].opcode || r->to != 0) {
continue;
}
found = true;
CHECK((unsigned)r->ret_len + r->zeros >= parser_reads[k].need,
"%04x: %u bytes after the status, %s's bluetoothd reads %u", r->opcode, r->ret_len + r->zeros,
parser_reads[k].build, parser_reads[k].need);
}
CHECK(found, "%04x (%s) has no ANSWER entry", parser_reads[k].opcode, parser_reads[k].build);
}
}

static void
answers(void)
{
Expand Down Expand Up @@ -166,7 +202,7 @@ answers(void)
CHECK(n == sizeof(other_rej) && memcmp(out, other_rej, n) == 0, "a vendor command not in the table: as it is");

{
/* 0xFE3B: 208 zero bytes after the status */
/* 0xFE3B: 212 zero bytes after the status (24B156's parser reads 212, 24A446's 208) */
static const uint8_t fe3b_cmd[] = { 0x01, 0x3b, 0xfe, 0x01, 0x01 };
static const uint8_t fe3b_rej[] = { 0x04, 0x0e, 0x04, 0x01, 0x3b, 0xfe, 0x01 };
bool zero = true;
Expand All @@ -176,7 +212,7 @@ answers(void)
for (size_t i = 7; i < n; i++) {
zero &= out[i] == 0;
}
CHECK(n == 7 + 208 && out[2] == 212 && out[6] == 0 && zero, "0xFE3B: status 00 and 208 zero bytes (%zu)", n);
CHECK(n == 7 + 212 && out[2] == 216 && out[6] == 0 && zero, "0xFE3B: status 00 and 212 zero bytes (%zu)", n);
}

/* commands split anywhere, replies a byte at a time: the same */
Expand Down Expand Up @@ -396,6 +432,7 @@ int
main(void)
{
table_itself();
reply_lengths();
answers();
translations();
untouched();
Expand Down
Loading