---
title: Radio frame and gateways
section: GT-Link
order: 3
---

# Radio frame and gateways (LoRa, from 1.8)

> **BETA, for GridTac 1.8.** GridTac already accepts gateways and opens their frames as described
> here; our own gateway and LoRa beacon are still being built. The radio frame and the gateway topics
> are additions to gtl/1 and are not part of its frozen core: they may change before 1.8. Everything
> that already runs over MQTT is frozen.

A field without mobile coverage still works: props and beacons talk LoRa to a **gateway** on the
field, and the gateway forwards to GridTac over Wi-Fi or 4G. Anyone may build a gateway, ours or yours, and it is
trusted with **nothing but transport**.

## Gateways forward, they do not speak

- Every prop behind a gateway is still **its own device**, with its own id, key, manifest and
  sequence numbers. The gateway is a radio, nothing more.
- A prop **encrypts with its own key**. The gateway sees ciphertext and radio metadata only, so it
  cannot read, change or invent a prop's events. Server-to-prop frames are encrypted by GridTac.
- Several gateways may hear the same frame. GridTac deduplicates on address, boot and sequence, so
  two gateways on one field are redundancy, not double counting.
- A gateway has its own identity and MQTT credentials that allow only its own `gridtac/gw/<gwid>/`
  topics, where `<gwid>` is the `dev_` id it got at pairing (its key is `gt_gw_`; see
  [A gateway online](../api/devices.md#a-gateway-online)): `up` (frames heard), `down` (frames to send), `tele` (its battery, uplink, props heard,
  invalid frames). Fields: [Message reference](reference.md#gateway-up).

## The frame

```
| ver 1B | addr 4B | boot 2B | seq 4B | type 1B |  ciphertext (CBOR payload)  | tag 12B |
 \______________ header, sent in clear, authenticated ______________/
```

- **AES-128-GCM** with a 12-byte tag; the header is the additional authenticated data.
- **Nonce** (12 bytes) = `addr | boot | seq | direction | 0x00`. It never repeats as long as `boot`
  is a counter in flash, incremented on every start, and `seq` restarts at 0 each boot. The
  direction byte keeps prop-to-server and server-to-prop apart. A prop that cannot keep a boot counter
  must not use GCM.
- **Payload:** the same short-key messages as over MQTT, packed as CBOR. A typical event fits in
  about 44 bytes: 12 header, about 20 payload, 12 tag.
- **Keys:** 128 bits per prop, generated on the prop from its own hardware random number generator
  on first boot (never baked into the firmware image), handed to GridTac once at pairing and stored
  encrypted. A gateway never holds a prop key. To rotate, pair again.
- **Replay:** GridTac accepts a frame only if its `(boot, seq)` is newer than the last one it accepted
  from that prop.
- **Address:** 4 random bytes given to the device when it is paired with its radio key (`radioAddr` in the answer). Planned: a fresh address per game, so a captured address says nothing next week.

## What a frame may carry

The `type` byte says what the payload is. A prop sends the messages it would send over MQTT; a
beacon sends what the [Player view](../api/play.md) calls take, for the player who carries it.

| Type | Name | Who | Payload |
|---|---|---|---|
| 1-4, 6 | `hello`, `evt`, `state`, `tele`, `ack` | prop | The [MQTT message](reference.md) of that name, without `b` and `s` |
| 8 | `pos` | beacon | [`la`, `lo`, `acc`, `bat`, `spd`, `crs`](reference.md#beacon-pos-radio-type-8) |
| 9 | `sos` | beacon | [`on`, and `la`, `lo` when it is raised](reference.md#beacon-sos-radio-type-9) |
| 10 | `status` | beacon | [`ps`: alive, hit, down, medic, out, respawn](reference.md#beacon-status-radio-type-10) |

The boot counter and sequence number come from the header, never from the payload. A type the
device's kind does not send is ignored. A beacon's reports then go exactly the way its HTTPS calls
would: the same game, the same player, the same limits, and its position outranks the player's phone
the same way.

## What GridTac does with a frame

In this order, so that nothing unauthenticated can change anything:

1. **Bounds:** 24 to 255 bytes, version 1, and the batch's `a` must equal the header's address.
2. An address dropped for abuse (below) is skipped.
3. The address is looked up among paired devices and the frame is **opened with that device's key**.
   A failed tag counts toward the abuse limits and nothing else happens.
4. Only an authentic frame meets the **replay rule**: its `(boot, seq)` must be newer than the last
   one accepted from that device. The same frame heard by two gateways is accepted once. Because the
   rule runs after the tag, a forged header cannot use up a real frame's sequence number.
5. The payload is handled as the device's own message; the device's key must be active and its rate
   limits apply.

Your gateway gets no answer per frame: it forwards what it hears and leaves the judging to GridTac.

## Frames to a device

GridTac sends a LoRa prop its commands (`cmd`, type 5) and its game clock (`game`, type 7) on
`gridtac/gw/<gwid>/down`, as `{ "a": "<addr>", "f": "<frame, base64>" }`, through **the gateway that
heard the device most recently** (within 10 minutes). The gateway transmits `f` as it is; it cannot
read it.

- The frame is encrypted with the device's own key in the **down** direction, so it never opens as one
  of the device's own frames.
- Its `boot` is the device's current boot counter, and its `seq` is GridTac's own downlink counter for
  that device: it only grows, never restarts. A device accepts a down frame only for its current boot
  and with a `seq` higher than the last one it accepted.
- The clock goes only when it changes, when the device says `hello` and when it is put into or taken
  out of a game: airtime is scarce, so there is no 30-second refresh as over MQTT.
- A device no gateway has heard gets nothing over radio. Its commands wait, as for any device.

## Abuse

More than 20 failed tags a minute from one address drops that address for 5 minutes and tells the
game master; more than 100 a minute across addresses flags the gateway. None of this ever changes
the game by itself: a person decides.

## Hidden props

A prop the other side must not find by radio (a hidden cache, a mine) sends on events plus a long
heartbeat with random jitter, never a steady beat that gives its position away. It says so with
`h: true` in its manifest.
