Keep BLE fault injection correct with prefixed fragments

This commit is contained in:
evgeny committed 2026-10-29 22:16:08 +01:00
1 parent d33b67d87c
commit 46f2137f06
2 files changed
+8 -5

No files matched your search

+7 -4
View File
@@ -9,7 +9,7 @@
#define CHECK(v) do { if (!(v)) { fprintf(stderr, "FAIL line=%d: %s\n", __LINE__, #v); exit(1); } } while (0)
struct fake_link {
ble_link_id id, other; struct ble_backend* peer; uint8_t data[512]; size_t len; int pending;
enum ble_wire_channel channel; uint64_t ack_at; uint16_t ack_id;
enum ble_wire_channel channel; uint64_t ack_at; uint16_t ack_id, ack_delivered;
};
struct ble_backend { struct ble_transport* owner; struct UASYNC* ua; void* task; int index, started; struct fake_link links[16]; };
static struct ble_backend* backends[3];
@@ -69,7 +69,10 @@ static void run(void* arg) {
struct ble_backend* peer = f->peer;
uint8_t data[512]; size_t len = f->len; memcpy(data, f->data, len); f->pending = 0;
int dropped = f->channel != BLE_WIRE_ACK && data[f->channel == BLE_WIRE_DATA ? 2 : 0] == 3 && drop && --drop == 0;
if (!dropped && peer && slot(peer, other)) ble_backend_received(peer->owner, other, f->channel, data, len);
if (!dropped && peer && slot(peer, other)) {
if (f->channel == BLE_WIRE_ACK) f->ack_delivered = f->ack_id;
ble_backend_received(peer->owner, other, f->channel, data, len);
}
if (slot(b, id)) ble_backend_sent(b->owner, id, 1);
}
}
@@ -172,8 +175,8 @@ static void exercise_flow(void) {
CHECK(!ble_tx_ready(a, id) && !ble_tx_ready(b, other));
uint64_t paused = data_wire_bytes[0];
struct fake_link* receiver = slot(backends[1], other); CHECK(receiver);
uint8_t duplicate[2] = {receiver->ack_id >> 8, receiver->ack_id};
/* Только уже доставленный ACK: до запуска отложенного ACK последняя запись ещё от HELLO. */
uint8_t duplicate[2] = {receiver->ack_delivered >> 8, receiver->ack_delivered};
/* Повтор уже доставленного ACK не подтверждает новые данные даже при зависшем ACK в backend. */
ble_backend_received(a, id, BLE_WIRE_ACK, duplicate, 2);
for (unsigned i = 0; i < 1000; i++) uasync_poll(ua, 0);
CHECK(data_wire_bytes[0] == paused && !ble_tx_ready(a, id));
+1 -1
View File
@@ -80,7 +80,7 @@ static void run(void* arg) {
uint8_t data[512]; size_t len = f->len; memcpy(data, f->data, len); f->pending = 0;
unsigned prefix = f->channel == BLE_WIRE_DATA ? 2 : 0;
uint8_t* body = data + prefix;
if (corrupt_keys && f->channel == BLE_WIRE_DATA && len >= 22 &&
if (corrupt_keys && f->channel == BLE_WIRE_DATA && len >= 18 &&
body[0] == 3 && body[3] == 0 && body[4] == 40 && body[5] == 0 && body[6] == 0) {
data[len - 1] ^= 1; corrupt_keys--;
}