Files
efitenandClaude Opus 5.5 70a59c6197 feat: uplink ping, test whether the mesh hears the companion
CoreDrive only measured what the companion hears. With uplinkPing on (off by
default), it sends a short message on a dedicated hashtag channel
(#coredrive) carrying only a random tag, listens 10 s for a repeater
re-broadcasting it, and publishes the result on the new topic
meshcore/client/{pk}/uplink (UPLINK_PING): tag, packet hash of the echo,
every echo with its first and last hop, and the GPS fix. The position never
goes over the mesh.

- src/grptxt.js: hashtag channel key, channel hash, GRP_TXT MAC check and
  AES-128-ECB decrypt, and the packet hash, per the firmware
  (Mesh.cpp:540-557, Utils.cpp:127-145, Packet.cpp:41-50). Checked against a
  real #wardriving packet from CoreScope live: same text and same hash
  (12c82f82df4cc29c). AES-ECB comes from @noble/ciphers 2.0.1, as WebCrypto
  has no ECB.
- src/uplinkping.js: channel message, get/set channel and flood-scope frames
  (companion_radio/MyMesh.cpp), slot choice that never overwrites another
  channel, echo matching on the tag.
- src/uplinksched.js: a ping only with a fix of 100 m or better, after
  uplinkIntervalSec (60) and uplinkMinMoveM (250), under uplinkMaxPerHour (50),
  and not in a ~180 m cell pinged in the last uplinkSkipDays (7).
- uplinkScope (e.g. "be") sends the ping as a region-scoped flood via
  CMD_SET_FLOOD_SCOPE (fw v8+) and resets the override right after.
- app.js holds the radio (acquireRadio) for the whole exchange, as OK/ERR
  replies carry no correlator; it skips while parked, signing or asking.
- DEVICE_INFO now yields the channel slot count; log header gets a ping row.

Tests: 417 pass (+20): crypto against the real packet, frames, slot choice,
echo matching, scheduler, config defaults, payload shape, header row. Not
tested on air: no ping has been sent from a real companion yet.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-16 15:52:02 +02:00

38 lines
2.0 KiB
JavaScript

import test from 'node:test';
import assert from 'node:assert/strict';
import { channelKey, channelHash, packetHash, decryptGroupText, PAYLOAD_TYPE_GRP_TXT } from '../src/grptxt.js';
import { hexToBytes, parsePacket } from '../src/meshpacket.js';
// A real packet from CoreScope live (transmissions.hash 12c82f82df4cc29c): a
// MeshMapper ping on #wardriving, TRANSPORT_FLOOD with five 2-byte hops. CoreScope
// decrypted it to the text below; this module must agree on key, text and hash.
const RAW = '1463FF000045A5040986C2FF6E3C692681B38F68F90D02BDF8CF1FA0D669C25C634FA133C036A15575710ED2930BE56894A62C156769D573175AACE6CF4A939F220CBC';
const PAYLOAD_OFFSET = 1 + 4 + 1 + 10; // header, transport codes, path byte, 5 x 2-byte hops
test('a real #wardriving packet decrypts to the text CoreScope stored', async () => {
const bytes = hexToBytes(RAW);
assert.equal(parsePacket(bytes).payloadType, PAYLOAD_TYPE_GRP_TXT);
const key = await channelKey('#wardriving');
const hb = await channelHash(key);
assert.equal(hb, 0x81, 'channel hash byte as on air');
const msg = await decryptGroupText(bytes.slice(PAYLOAD_OFFSET), key, hb);
assert.equal(msg.text, 'MeshMapper Daniel: MM:c6PDmc_yqw');
});
test('packetHash matches the hash CoreScope files the transmission under', async () => {
const bytes = hexToBytes(RAW);
assert.equal(await packetHash(PAYLOAD_TYPE_GRP_TXT, bytes.slice(PAYLOAD_OFFSET)), '12c82f82df4cc29c');
});
test('another channel key, a wrong hash byte or a broken MAC yields null', async () => {
const payload = hexToBytes(RAW).slice(PAYLOAD_OFFSET);
const key = await channelKey('#wardriving');
const other = await channelKey('#coredrive');
assert.equal(await decryptGroupText(payload, other, 0x81), null, 'wrong key fails the MAC');
assert.equal(await decryptGroupText(payload, key, 0x82), null, 'wrong channel hash byte');
const bad = payload.slice();
bad[1] ^= 0xff;
assert.equal(await decryptGroupText(bad, key, 0x81), null, 'tampered MAC');
assert.equal(await decryptGroupText(payload.slice(0, 10), key, 0x81), null, 'too short');
});