browse files at this commit · zip
commit 6dc733973638b84449c6a316631aad085c9a3418
Author: no-body-in-particular <admin@coredump.ws>
Date: Thu Oct 8 22:40:43 2026 +0200
Disbelieve a fix that moved further than the device says it did
Armytied's fifteen minutes of alarms on 6 October were real, and from this
server: 216 WARNING# commands have gone out, and two "Severe: outside of
inclusion zone" events are logged ten minutes apart - that gap is
FENCE_REPEAT_INTERVAL, while the siren fires on every call. I had told him
it was not us, having grepped command-output.txt, which holds the device's
replies rather than the commands sent.
What happened: the fix jumped 1661 m in one interval and then converged
home over fourteen minutes, against a 45 m inclusion zone. Every fix had
six to ten satellites, so MIN_FENCE_SATELLITES passed them as confident,
and a 25 m exit margin means nothing at 1.6 km.
Reading the speed byte makes it detectable. A chip that has mislocated
itself still knows it is not moving: speed comes from Doppler shift on the
carrier, not from differencing the positions it just got wrong. So a
position implying 69 km/h while the device reports standing still is the
position being wrong.
Catching the jump alone is not enough, which the data says plainly: the
jump implies 69 km/h, the fourteen minutes after it imply five to nine - a
walking pace, and that is where almost all the sirens came from. So the
disbelief is held. The position stays suspect until the device reports real
speed, or comes back within 150 m of where it jumped from, or fifteen
minutes pass, which bounds the harm if a speed field is simply broken.
Replayed against that half hour: of 130 GPS fixes, 91 were outside the
fence and 4 would still have sounded. Not none - the first fixes of a jump
are judged before there is anything to compare them against - but four
rather than ninety-one.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014YjYFpxhS1ZnK5hCMVnNBD
---
device_server/config.h | 40 +++++++++++++++++++++++++++++++++++
device_server/connection.c | 4 ++++
device_server/connection.h | 8 +++++++
device_server/geofence.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 104 insertions(+)
diff --git a/device_server/config.h b/device_server/config.h
index 1db3b1d..ce12830 100644
--- a/device_server/config.h
+++ b/device_server/config.h
@@ -413,6 +413,46 @@
* It still gets a limit. It is a volunteer-run database and only answers when the paid two
* could not, so this is generous rather than tight - it is a courtesy bound, not a cost one.
*/
+/*
+ * A position that moved while the device said it was standing still.
+ *
+ * On 2026-10-06 the bracelet's fix jumped 1661 m in one reporting interval and then converged
+ * back over fourteen minutes. Every one of those fixes had six to ten satellites, so
+ * MIN_FENCE_SATELLITES let them through as confident, and they sat outside a 45 m inclusion
+ * zone, so the siren went off on each one for a quarter of an hour. The wearer had not moved.
+ *
+ * The giveaway is in the packet: the GPS chip reports its own speed, and a chip that has
+ * mislocated itself still knows it is not moving - it takes speed from Doppler shift on the
+ * carrier, not from differencing the positions it just got wrong. So when the positions imply
+ * a sprint and the chip reports a standstill, the positions are what is wrong.
+ *
+ * The fix is still recorded. Only its vote on the fences is withheld, the same as a fix with
+ * too few satellites. A vehicle leaving a tunnel could briefly report zero while genuinely
+ * moving, which is the cost of this - and withholding an alarm for one interval is a far
+ * smaller harm than fifteen minutes of false ones.
+ */
+#define TELEPORT_REPORTED_MAX 3.0 //km/h the chip must be under to call it standing still
+#define TELEPORT_IMPLIED_MIN 20.0 //km/h the positions must imply before we disbelieve them
+
+/*
+ * Catching the jump is not enough on its own.
+ *
+ * Measured from the 6 October event: the jump itself implies 69 km/h and is caught, but the
+ * fourteen minutes that followed are the fix converging home a hundred metres at a time, which
+ * implies five to nine - an ordinary walking pace, and indistinguishable from one. Every one of
+ * those was still 1.2 km outside a 45 m fence, so that is where the quarter hour of sirens came
+ * from.
+ *
+ * So the disbelief has to last. Once a jump is caught the position stays suspect, and the
+ * fences are not told about it, until one of three things happens: the device reports real
+ * speed, meaning it genuinely is moving and its positions are worth having again; or the
+ * position comes back within TELEPORT_RECOVER_M of where it was last trusted; or
+ * TELEPORT_SUSPECT_MAX passes, which bounds the harm if a device's speed field is simply
+ * broken - better a late alarm than a fence that is off forever.
+ */
+#define TELEPORT_RECOVER_M 150.0
+#define TELEPORT_SUSPECT_MAX 900
+
#define BEACONDB_BURST 120
#define BEACONDB_PER_HOUR 600
diff --git a/device_server/connection.c b/device_server/connection.c
index 65c5642..1cb7b0f 100644
--- a/device_server/connection.c
+++ b/device_server/connection.c
@@ -419,6 +419,10 @@ void init_imei(connection * conn) {
conn->fix_sat_count = -1;
conn->outside_fence_count = 0;
conn->reported_speed = NAN;
+ conn->position_suspect = false;
+ conn->suspect_since = 0;
+ conn->trusted_lat = 0;
+ conn->trusted_lon = 0;
read_disabled_fences(conn);
read_geofence(conn);
//Only an absence worth noticing goes in the event log. This device re-opens its socket
diff --git a/device_server/connection.h b/device_server/connection.h
index 26a7768..429dd82 100644
--- a/device_server/connection.h
+++ b/device_server/connection.h
@@ -161,6 +161,14 @@ typedef struct {
* Cleared by move_to(), like fix_sat_count, so it can never describe the previous fix.
*/
float reported_speed;
+ /*
+ * Set when a fix jumped further than the device's own speed can account for, and held
+ * until it comes back or the device admits to moving. See TELEPORT_SUSPECT_MAX.
+ */
+ bool position_suspect;
+ time_t suspect_since;
+ double trusted_lat;
+ double trusted_lon;
time_t device_time;
time_t since_last_locate;
//assembly of an image arriving over several packets. The buffer is only allocated while
diff --git a/device_server/geofence.c b/device_server/geofence.c
index a089068..f98ae0a 100644
--- a/device_server/geofence.c
+++ b/device_server/geofence.c
@@ -387,6 +387,58 @@ bool move_to(connection * conn, time_t device_time, int position_type, double la
conn->fix_sat_count, MIN_FENCE_SATELLITES);
}
+ /*
+ * The positions say it sprinted; the chip says it stood still. See TELEPORT_IMPLIED_MIN.
+ * Needs a previous position to compare against and a speed the device actually reported,
+ * so a protocol without one is judged exactly as before.
+ */
+ if (fix_can_judge && position_type == 0 && dt > 0
+ && (conn->current_lat != 0 || conn->current_lon != 0)
+ && isfinite(conn->reported_speed)
+ && conn->reported_speed <= TELEPORT_REPORTED_MAX) {
+ double implied = compute_speed(dt, conn->current_lat, conn->current_lon, lat, lon);
+
+ if (isfinite(implied) && implied >= TELEPORT_IMPLIED_MIN) {
+ log_line(conn, "position implies %.0f km/h but the device reports %.0f - treating the jump as a"
+ " GPS error, recorded but not tested against the fences\n",
+ implied, (double) conn->reported_speed);
+ fix_can_judge = false;
+
+ if (!conn->position_suspect) {
+ conn->position_suspect = true;
+ conn->suspect_since = time(0);
+ //where it was before the jump: what it has to come back to
+ conn->trusted_lat = conn->current_lat;
+ conn->trusted_lon = conn->current_lon;
+ }
+ }
+ }
+
+ /*
+ * Still suspect from an earlier jump. The fix after a teleport looks ordinary on its own -
+ * the position creeps back at walking pace - so judging each fix in isolation lets the
+ * whole recovery raise alarms. See TELEPORT_RECOVER_M.
+ */
+ if (conn->position_suspect) {
+ double home = haversineDistance(conn->trusted_lat, conn->trusted_lon, lat, lon) * 1000.0;
+ bool moving = isfinite(conn->reported_speed) && conn->reported_speed > TELEPORT_REPORTED_MAX;
+ bool recovered = home <= TELEPORT_RECOVER_M;
+ bool waited = (time(0) - conn->suspect_since) > TELEPORT_SUSPECT_MAX;
+
+ if (moving || recovered || waited) {
+ log_line(conn, "position trusted again after %ld s (%s)\n",
+ (long)(time(0) - conn->suspect_since),
+ recovered ? "back where it jumped from" : (moving ? "the device reports real movement"
+ : "waited long enough"));
+ conn->position_suspect = false;
+
+ } else if (fix_can_judge) {
+ log_line(conn, "position still %.0f m from where it jumped from and the device reports %.0f km/h"
+ " - not tested against the fences\n", home, (double) conn->reported_speed);
+ fix_can_judge = false;
+ }
+ }
+
if ( fix_can_judge && position_type != 1 && (conn->current_lat != 0 || conn->current_lon != 0) && conn->fence_count > 0) {
bool fence_mandatory = false;
bool in_mandatory = false;