Jump to content

Landis+Gyr GridStream Mesh Network

From RECESSIM, A Reverse Engineering Community

How Landis+Gyr GridStream meters build and run their mesh: how a node joins, keeps its neighbours, talks over a link, routes and floods messages, and moves firmware images. The frames themselves are described on Landis+Gyr GridStream Protocol; read that page's Network Overview first.

Most of this page comes from the Generation 5 (SAM4C32 / CC1200) meter firmware, compared with the Generation 4 (M16C / CC1020) firmware where that has been checked. Both run the same UtiliNet stack, and most behaviour is the same; differences are marked Gen 4 or Gen 5. Statements that come only from firmware and have not been seen on air say so.

How a node joins

There is no registration and no join handshake. Neither generation sends a join request, and the collector does not answer one. A node becomes part of the mesh in four steps:

  1. It is heard. It sends 0x55 Sync beacons carrying its WAN, LAN, uptime, status word, hop clock and its current route.
  2. It admits neighbours. From the beacons and link exchanges it hears, it builds a neighbour table.
  3. It picks a parent. It chooses the neighbour with the best route toward a collector, takes that neighbour's route id and sets its own hop count to the parent's plus one.
  4. It reports its path. Its uplinks name its parent, and a node with a LAN-form WAN also sends path reports, so the head-end knows how to reach it.

A node that is provisioned with a network ID builds that network's hop table and picks a random starting point in it, so every node has its own hop phase.

Beacon schedule (Gen 5)

The Gen 5 firmware sends beacons by uptime. Each burst goes out one beacon per hop slot, on the node's own next slots, starting at a random point in the interval:

Uptime Beacons
0 to 3 minutes Bursts of up to 8, frequently
3 to 12 minutes Bursts of up to 8, less often
After 12 minutes One at a time, at a steady interval that grows with the number of channels and shrinks a little with 6 or more neighbours

When a node that has been up for more than 12 minutes hears a beacon from a freshly powered neighbour (under 12 minutes) that it cannot yet add to its tables, it sends that neighbour 3 beacons on the neighbour's own channel, half a second to a second apart, to help it join.

The Gen 4 firmware instead sends its beacons on a sweep through the four channel mod 4 classes, about one every 24 to 32 seconds as measured on air (see RF and FHSS Layer). The Gen 5 schedule above has not yet been checked against Gen 5 captures.

Choosing a parent

Every node keeps one parent: its next hop toward a collector. The firmware tracks only this one upstream link; it keeps no list of children.

  • Candidates are neighbours that have completed a link exchange with this node (state "linked", see Neighbours) and that advertise a route (status word bit 0x0400, or a route option in their beacon or LinkInfo).
  • Cost of a candidate = its advertised route cost + the cost of the link to it, worked out from the airtime and the share of exchanges that succeed. 60000 means no route.
  • The candidate with the lowest cost wins, but it must beat the current parent by a margin, so the parent does not flap. The current parent is dropped when its link gets poor (Gen 5: fewer than 25% of Tickles or 45% of data frames succeed).
  • The node's hop count is the parent's plus one; 0x80 or more means no route, sent as FE. Its route id is the parent's.
  • A collector (the root) advertises cost 1, hop count 0 and its own route id.

On air, the source WAN FE <parent LAN> 80 in a meter's uplinks names the parent it had when it built the message. Captures show nodes change parent every few hours on average.

Path reports

A node with a route sends path reports to the head-end: a short network message with payload FE DF, a count, and a fixed tail. Each relay on the way appends its own 4-byte LAN id (up to 51), so the head-end receives the full path. A new parent triggers a burst of 12 reports, a few minutes apart; after that they are sent every couple of hours during the first two days of uptime and once a day later (Gen 5). Path reports are sent only when the node's WAN is in the LAN form and the head-end address uses Color 31.

The Gen 4 firmware has the same message, sent only by nodes without a GPS WAN.

Neighbours

A node keeps a record for each neighbour it has admitted: its LAN and WAN, signal strength, link margin, data rate, the counts of exchanges tried and acknowledged, its advertised route and its hop phase. A Gen 5 node has room for 172 such records.

Neighbour link states
State Meaning
New Heard, but no link exchange has completed yet
Linked A Tickle, ack, data, ack exchange that this node started has succeeded. Only linked neighbours can become the parent
Marginal Linked, but the neighbour's ack said that it considers this node a weak neighbour it would not keep
Dropping Scheduled for removal; skipped by every lookup
  • LinkInfo records are swapped with each neighbour every 8 hours (4 hours for a neighbour known only by its LAN id), plus up to 15 seconds of random delay. Gen 4 uses the same 8 hours.
  • Eviction: a neighbour is dropped after 26 failed exchanges in a row, or 51 once LinkInfo has been swapped with it. A neighbour with no WAN location, not heard for an hour and with no route is also dropped. These are the same numbers in both generations.
  • Memory of dropped neighbours (Gen 5): every node that is dropped or refused is first written to a "heard" table that keeps the hop phase, data rate and signal of up to 3584 neighbours. An entry not heard for 8 to 16 hours is removed. This lets a node send to a neighbour it no longer tracks fully.

Link exchange

All unicast traffic between two neighbours goes through a short exchange, on the receiver's current hop channel:

Step Sender → receiver Frame
1 Tickle: "I have data for you", with the data rate and priority, and link options (route, block-transfer state) 0xD5 21, or 0xD2 21 (only the source LAN on air); 0xD5 29 when the peer has not been heard in a full frame for about a minute or after 9 failed tries
2 Ack (TAck), with an admission byte and link options 0xD2 22
3 Data: the network message 0xD2 81 for one frame, or 0x81 block-mode packets for a long one
4 Data ack; in block mode it carries a bitmap of the blocks still missing 0xD2 82
5 Ack of the ack: closes the exchange 0xD2 83 (or 23)
  • Both ends switch to the rate named in the Tickle for the rest of the exchange, then return to the listening rate.
  • The receiver refuses with admission byte FF (Gen 5 also when the low nibble is 0, a "NAK"), for example when it is out of buffers or shutting down.
  • Gen 5 can skip the Tickle and send the data straight away on a fast, healthy link.
  • If several messages wait for the same neighbour, Gen 5 chains them into one exchange, as long as the airtime used in the current 700 ms hop slot stays under 400 ms. Missing blocks are resent under the same limit.
  • After a failed exchange the sender waits a random 0.03 to 1 s (or up to 4 s after repeated failures) before trying again.
  • LinkInfo, LinkInfoInq and time-sync frames use the same Tickle-like pattern with their own opcodes (51 → 52 → 53).

Link options

Beacons, Tickles, acks and LinkInfo records carry short link options: a tag byte and a body whose length is fixed by the tag (there is no length byte). Parsing stops at a tag above 11. Layouts below are from the Gen 5 firmware; tags 1, 2, 5, 7 and 10 also appear in the Gen 4 firmware.

Tag Body Meaning
01 4 bytes Route: cost ÷ 16 (2 bytes), route id (1), hops (1). EA60 00 FE = no route
02 12 bytes Time sync: three 32-bit timestamps
03 7 bytes Broadcast-suppression id (a CRC of the 7 bytes): tells the receiver it has already had this broadcast
04 none A flag
05 5 bytes Data rate and radio descriptor
06 5 bytes Block-transfer state: block mask (2), block size (1), lifetime (2)
07 2 bytes Missing-block mask, sent back by the receiver
08 11 bytes Block-transfer state plus resume data, to continue an interrupted transfer
09 2 bytes Broadcast-suppression id, given directly
0A 4 bytes Hop phase: time to the sender's next tick and its period. Accepted only from the parent or a neighbour with a better route
0B 4 bytes Route, with the cost not divided by 16 (no sender found in the Gen 5 firmware)

Routing

A routed message carries the 30-byte network header described in Cleartext network header: end-to-end destination and source (WAN + LAN), time to live, Luck, priority, message ID, message type and fragment word. The same header is used by both generations.

  • Uplink. A message to the head-end address (00 00 00 00 xx 1F) is sent to the node's parent, and each node passes it to its own parent until it reaches a collector. The originator writes its parent's LAN into the source WAN (FE <parent> 80); relays leave it alone.
  • Downlink. The head-end uses those parent links and the path reports to build a tree of routes down to each meter. A downlink can carry a source route (a list of hops after the header, flagged by bit 3 of the priority byte); each relay removes its own entry and passes the message to the next. Only the head-end creates source routes, and none has been seen on air yet.
  • Other destinations are looked up in the neighbour table, a small cache of recent reverse routes, or ranked route candidates.
  • Limits. Every relay takes one off Luck and drops the message at 0 (Gen 4 never decrements FF; Gen 5 does). The time to live in seconds counts down with the time the message spends in the network. A cache of recent message IDs per originator (Gen 5: 20 entries, each covering a window of 32 IDs, kept for 60 s after the message expires) drops duplicates.
  • Receipts. When the message type byte asks for one, the destination returns a short return receipt with the same message ID: positive when delivered, negative for example when no route exists (Gen 5).
  • Delayed sending (Gen 5). A message can be marked for delayed delivery. It is stored in a 64 KB ring in the external flash and sent later, 60 s plus a random delay that grows with its delay class.

Floods and broadcasts

A message is flooded when its destination WAN starts with FF or FD, or when its destination LAN is FFFFFFFF.

Destination WAN Who accepts it
FF + direction mask + radius Nodes inside an area around the originator: the node works out the direction and distance from its own WAN to the originator's source WAN, and accepts only if that direction's 45° sector bit is set in the mask and the distance is within the radius. The destination LAN then selects the target: FFFFFFFF or 0 = every node in the area; the node's own LAN = deliver here and stop. This needs WANs that hold a location (the GPS form)
FD + attribute pattern Nodes whose device attributes (hardware type and other identity bytes) and group ids match the pattern, with wildcards. Same scheme in both generations, with different attribute values
Any, with destination LAN FFFFFFFF Every node that hears it
  • An accepted flood is delivered locally on a copy (with the node's own address as destination) and, if the limits allow, sent on again.
  • Limits: Luck, time to live, the duplicate cache, a separate broadcast-suppression table, the area, and a queue cap: a Gen 5 node re-floods only while fewer than 20 messages wait to go out (Gen 4: 5). The mood bits of the priority byte space out the re-broadcasts.
  • Gen 5 drops broadcasts that ask for a return receipt.

Broadcast delivery on the air (Gen 5)

A broadcast can't simply be sent once, because every neighbour listens on a different channel. The Gen 5 firmware picks one usable channel whose channel mod 4 class depends on the message ID. For up to 480 ms it then visits its targets, each on that target's own current channel, with a 7-byte announcement (0xD2 opcode 24) that says which channel and data rate to switch to and how long to wait there. It then sends the broadcast once on the chosen channel without asking for an ack. Each target is announced to at most 3 times. When there are more targets than channels, it announces on every channel instead. A node that receives the announcement drops what it is doing and listens on the named channel.

Relay outage aggregation

Meters report power outages and restorations with messages that start FE EC. A Gen 5 node that relays such reports does not forward each one: it holds them for 5 or 20 seconds, packs the records from several meters into one message of up to 207 bytes, and sends that with its own WAN and LAN as the source and a new message ID. The head-end therefore receives other meters' outage records inside a packet sourced by the relay. When reading captures, a 0x81 uplink's source is not always the meter the data is about. (Gen 4 meters also combine their own event and power records into one message, up to 208 bytes.)

Message reassembly

A message longer than one fragment (207 bytes of payload) is split, and each fragment travels as its own 0x81 packet with the fragment number in the fragment word.

  • A Gen 5 node reassembles one message at a time, with a 60-second deadline.
  • Up to 30 fragments are accepted per message (about 6 KB), or up to 170 for DCW query programs.
  • Fragments of a DCW query are written to the external flash, one 256-byte page each, and may arrive in any order; others are merged in RAM.

See Landis+Gyr DCW for what those DCW programs do.

Receive security checks (Gen 5)

The Gen 5 firmware has three security modes (configuration cfg+0x22F, low 2 bits): 0 = off (every message is handled as plaintext), 1 = shared network key, 2 = public-key (ECC). Before a received message is delivered, an accept-policy check (l3_rx_accept_policy, 0x010498D8) applies:

  • In security mode 0, only plaintext messages and keyed GeneralResponse messages pass.
  • Messages whose source LAN is 0x00101011 or 0x00101012 and that arrive through the node's own pseudo-neighbour record (the one used for locally delivered traffic) skip the checks. The same two source LANs mark the image-broadcast streams (see Firmware image transfer). Whether a message received over the air can reach this path has not been traced.
  • A message that fails the policy is answered with a negative return receipt (abort) when one was asked for.
  • Encrypted messages that fail the HMAC check under the meter's key can still be accepted under the factory default key in one case; see Default-key fallback.

Reboot triggers (Gen 5)

The Gen 5 firmware restarts itself in these cases. Each is logged with a reason code.

Trigger Reason / alarm Where
No neighbour has accepted a link exchange (no admitted WAN link) for 10 hours reboot reason 4 mac_periodic_maint, 0x01037D54
One multi-fragment message holds the transmitter for more than 720 s (12 minutes) alarm 0x99, reboot reason 0x37 net_tx_busy_watchdog, 0x0104A1A4
A task fails to check in within a 720 s round alarm 0x99, reboot reason 0x2C clk_task, 0x01039BA8
A neighbour-table or far-node-table lock is held for about 11 minutes (0x4000 × 40 ms) reboot reason 0x18, or 0x19 + task utilinet.c lock table at 0x200035CC

The "refuse all" states (system shutdown, and refuse-all-WAN-requests, cfg+0x1E4 bit 0) clear themselves one hour after they are seen.

Firmware image transfer

Firmware images do not need a separate channel: they move through the mesh as ordinary routed messages, and any node that already holds an image can serve it to its neighbours.

Gen 4 (M16C) Gen 5 (SAM4C32)
Messages Requests and status as message type 2; image blocks of up to 199 bytes, addressed by offset, as message type 6 Request / response pairs with five subtypes: query (do you have image X?), info (reply: name, id, size), block request (up to 15 missing offsets), block (offset + data), status
Distribution Pull: nodes ask for the ranges they miss from any node that holds the image Pull, as Gen 4; a node can also broadcast an image to its neighbours as a stream of fragments 200 ms apart
Encryption None of its own. With a network setting clear, image traffic travels in plaintext even when AES is on The same AES-256-CTR + HMAC scheme as other messages
Check before use CRC and part number only; no signature ECDSA P-256 signature over SHA-256, checked against Landis+Gyr keys before the image is staged (see Landis+Gyr Residential Meter)

Other Gen 5 frame formats

The Gen 5 firmware also contains a broadcast exchange (BEP) scheme using packet types 0x25 / 0xA5. A node announces a poll schedule (opcode 3C) listing downlink records it holds for nearby nodes; a node that sees its id asks for its record during a link exchange. The same frames carry short uplink fragments and image broadcasts. None of this has been identified in captures yet.

Firmware references

Where the behaviour on this page lives in the firmware, for readers who want to follow it in a disassembler. Gen 5 addresses are in the SAM4C32 application (application flash starts at 0x01020000); Gen 4 addresses are in the M16C image. Names are our own labels.

Topic Gen 5 (SAM4C32) Gen 4 (M16C)
Sync beacon builder net_send_timesync 0x0104E0F6; schedule 0x0104E1E6 0x0B87D2 (scheduler 0x0B8BD6)
Link options: build / parse mrp_append_option 0x0104E7F0; mrp_parse_options 0x0104E55C; length table 0x0104E930 link_parse_info_elements 0x0BA376; table 0xA1186
Link frame send (compact / full) l2_send_frame 0x01035348 0x0BE9B3
Link exchange state machine mac_tx_direct_sm 0x01036134; l2_rx_exchange_sm 0x01035B40 0x0BF7EE
Parent selection net_select_route 0x01044910 select_parent_route 0x0B9663
Network header build / import l3_build_packet 0x01049AD0; l3_import_packet 0x0104D31C 0x0C2540; 0x0C337D
Path report (FE DF) 0x01049EFA 0x0C49D7
Flood processing net_bcast_process 0x0105A04C 0x0C1F9C
Broadcast announcement (opcode 24) 0x010510FA –
Relay outage aggregation 0x0105A66E / 0x0105A602 –
Reassembly l3_reasm_accept_frag 0x0104BE22 –
Payload encrypt / decrypt l3_encrypt_outbound 0x0104AEE4; l3_decrypt_verify 0x0104B0BE; nonce 0x01049A6C 0x0DB6F5 (encrypt)
Factory default network key flash 0x01020400 (CRC at 0x01020420) flash 0xA0100
Hop table generator fhss_gen_sequence 0x010276C8; region table 0x01028258 0x0B6FE2

See also