On Tue, Nov 1, 2022 at 11:10 AM Linus Torvalds
<
torv...@linuxfoundation.org> wrote:
>
> So it looks like we've lost some data in the *middle*.
Hmm. I think I see the problem.
The dump file for a good packet looks like this:
INFO: Read: size=64, data=C8B1C17F08C4[...]
DEBUG: rcv: size=63, data=B1C17F08C4[..]
because that first byte (C8) is a magic thing. We have this big
comment about it:
* Something changed in the G2 firmware between
versions 1.2 and 1.4.
*
* The first byte of a packet always used to be the
length of the
* packet data. That's still true for simple
single-packet replies,
* but multi-packet replies seem to have some other
data in it, at
* least for BLE.
*
* The new pattern *seems* to be:
*
* - simple one-packet reply: the byte remains the
size of the reply
*
* - otherwise, it's an endlessly repeating sequence of
*
* 0xf7 247
* 0x14 20
* 0x27 39
* 0x3a 58
* 0x4d 77
* 0x60 96
* 0x73 115
* 0x86 134
* 0x99 153
* 0xac 172
* 0xbf 191
* 0xd2 210
* 0xe5 229
* 0xf7 247
* .. repeats ..
*
* which is basically "increase by 19" except for that
last one (229->247
* is an increase by 18).
*
* The number 19 is the real payload size for BLE GATT
(20 bytes minus the
* one-byte magic size-that-isn't-size-any-more-byte).
*
* It may be just an oddly implemented sequence
number. Whatever.
so what we end up doing is this:
unsigned int len = buf[0];
if (len + 1 > transferred)
len = transferred-1;
and that's actually important for the USB download, because the packet
size is always fixed (you always get 64-byte packets). So the first
byte is basically a "how much of that packet is data".
So we got a 64-byte packet, and turn it into "one byte of length
and/or sequence number" plus "63 bytes of data".
And that also worked for BT, even though BT packets can be any size
(up to a maximum).
HOWEVER, with the new G2 firmware, on the BT side we now end up seeing
packets like this:
INFO: Read: size=37, data=0000001901[..]
DEBUG: rcv: size=0, data=
where we got a 37-byte packet, and the first character was zero, and
we decide to turn that 37-byte packet into "one byte of length, and no
data".
So it *looks* like what changed is that the "length" byte is now only
length for USB transfers, and for BLE transfers it's just random data.
Statistics for the first byte data on the USB side:
1 INFO: Read: size=64, data=33
3 INFO: Read: size=64, data=01
4 INFO: Read: size=64, data=04
4 INFO: Read: size=64, data=10
4639 INFO: Read: size=64, data=3F
ie we had a couple of single-byte replies, 4-byte replies and 16-byte
replies, and then we had a *lot* of "full packet" replies (63 bytes of
data in a 64-byte packet) plus that one single final partial packet
(51 bytes of data).
In contrast, the same statistics on the BLE side make no sense at all.
The first byte seems pretty much random now:
20 INFO: Read: size=37, data=0D
21 INFO: Read: size=37, data=0F
21 INFO: Read: size=37, data=74
21 INFO: Read: size=37, data=76
21 INFO: Read: size=37, data=77
23 INFO: Read: size=37, data=0B
25 INFO: Read: size=37, data=0A
25 INFO: Read: size=37, data=65
25 INFO: Read: size=37, data=75
30 INFO: Read: size=37, data=09
30 INFO: Read: size=37, data=78
32 INFO: Read: size=37, data=79
33 INFO: Read: size=37, data=7A
34 INFO: Read: size=37, data=7C
37 INFO: Read: size=37, data=07
38 INFO: Read: size=37, data=04
38 INFO: Read: size=37, data=05
40 INFO: Read: size=37, data=08
42 INFO: Read: size=37, data=AE
44 INFO: Read: size=37, data=06
44 INFO: Read: size=37, data=9E
45 INFO: Read: size=37, data=7D
48 INFO: Read: size=37, data=03
53 INFO: Read: size=37, data=7B
59 INFO: Read: size=37, data=02
65 INFO: Read: size=37, data=7E
72 INFO: Read: size=37, data=C1
76 INFO: Read: size=37, data=00
78 INFO: Read: size=37, data=7F
93 INFO: Read: size=37, data=01
350 INFO: Read: size=37, data=9F
366 INFO: Read: size=37, data=81
534 INFO: Read: size=37, data=AF
1459 INFO: Read: size=64, data=65
1459 INFO: Read: size=64, data=C8
and I don't see much of a pattern, except that we have a lot of
37-byte BLE packets, but most of them are 64-byte. And the 64-byte
packets seem to still have a clear pattern in the first byte (ie for
64-byte packets it's always either 0x65 or 0xc8).
So let's just ignore the first byte for the BLE packet. I'll send a patch.
Linus