Padded Talkgroups and Rewrite Rules — How DMR Gateway Actually Works

If you run more than one DMR network on a single hotspot, you have already met padded talkgroups: the ones where TGIF talkgroup 101 has to be entered as 5000101. This page explains where that number comes from, what the software is doing with it, and why the prefix is different on different hotspots.

The problem the prefix solves

Your radio can send exactly one piece of routing information when you key up: a talkgroup number. There is no field in the DMR protocol for which network you meant. That was never a problem when a hotspot talked to one network — everything went to BrandMeister and that was that.

DMR Gateway changed the picture. It sits between your MMDVM modem and up to six DMR networks at once, and now the same number is ambiguous. Talkgroup 3100 exists on BrandMeister. It could exist on TGIF too. When you key up 3100, which one did you mean?

The answer is to smuggle the network choice into the only field you have. One network is designated primary and keeps its talkgroup numbers unchanged. Every other network gets a prefix digit, and you dial that digit in front of the talkgroup. The gateway reads the prefix, works out which network you meant, strips the prefix back off, and forwards the plain talkgroup number to that network. The network never sees the prefix. It is a routing label that exists only between your radio and the gateway.

In one line: the prefix is an address on an envelope. DMR Gateway reads it, decides which network the letter goes to, throws the envelope away, and delivers the letter.

What a rewrite rule is

The prefix is not magic and it is not built into the DMR standard. It exists because of a line of configuration called a rewrite rule, written into DMRGateway.ini. A rewrite rule says: traffic matching this pattern on the way in should be changed to that pattern on the way out.

The main one is TGRewrite, and it takes five comma-separated fields:

TGRewrite=fromSlot,fromTG,toSlot,toTG,range
fromSlotThe time slot the traffic arrives on from your radio — 1 or 2.
fromTGThe talkgroup number your radio sent, including the prefix. This is the first number in the matching range.
toSlotThe time slot to use when sending out to the network.
toTGThe talkgroup number to send to the network — the first number in the output range.
rangeHow many consecutive talkgroups this single rule covers.

That last field is what makes the whole scheme practical. One rule can cover a million talkgroups, so nobody has to write a line per talkgroup.

A worked example

Here is the rule that gives TGIF its prefix 5 on WPSD, on time slot 2:

TGRewrite=2,5000001,2,1,999999

Read it left to right. Traffic arriving on slot 2, with a talkgroup starting at 5000001, is sent out on slot 2, with talkgroups starting at 1, for 999999 consecutive values. In other words, the range 50000015999999 maps onto 1999999. Subtract five million and you have the real talkgroup.

So when you key up 5000101, the gateway matches it, subtracts the offset, and sends talkgroup 101 to TGIF. Traffic coming back the other way is rewritten in reverse, so your radio sees 5000101 again and the talkgroup you programmed lights up as expected.

This is also the answer to the question everyone asks — why seven digits? The range field covers six digits' worth of talkgroups, 000001 through 999999. Add one prefix digit on the front and every padded talkgroup is exactly seven digits long. TGIF 101 becomes 5000101. TGIF 31665 becomes 5031665. The zeros are padding, nothing more.

Watch the edge case. The rule above covers six-digit talkgroups. TGIF also allows user-created talkgroups numbered from a DMR ID, which are already seven digits — and those overflow the range. TG 3203626 becomes 53203626, eight digits, and the tidy “always seven” rule breaks. If your list carries any of those, check them by hand.

The other rewrite types

TGRewrite handles group calls, which is most of what you do. Four other rules cover the rest:

PCRewriteSame idea, but for private calls: PCRewrite=fromSlot,fromId,toSlot,toId,range. This is how reflector control commands get steered to the right network — the prefix is stripped before routing, exactly as with talkgroups.
TypeRewriteConverts a group call into a private call on the way out to the network. RF-to-network only.
SrcRewriteRewrites the source ID rather than the destination — used to land reflector announcements on a particular talkgroup. Network-to-RF only.
PassAllTG
PassAllPC
Send everything to one network without matching individual rules. Useful for a catch-all, dangerous as a habit.

Who uses which prefix

Here is the part that trips people up. The prefix is attached to a slot in the gateway configuration, not to the network itself. WPSD ships with the slots already assigned, so its prefixes are consistent from one hotspot to the next. Pi-Star assigns the built-in ones and leaves the rest to you — which means the same digit can mean different networks on two hotspots sitting on the same desk.

Prefix WPSD Pi-Star
The primary network — BrandMeister by default. No prefix. The primary network — BrandMeister by default. No prefix.
1 Unassigned Unassigned — and the safest spare digit if you need one.
2 BrandMeister, when it is not the primary network Not assigned by default — operator's choice
3 Unassigned — and best left alone. See below. Unassigned — and best left alone. See below.
4 SystemX Operator's choice — commonly TGIF or FreeSTAR
5 TGIF Operator's choice — commonly TGIF, following the WPSD convention
6 XLX — TG 6 to connect, and 6 + module letter to change modules XLX — TG 6 to connect, and 6 + module letter to change modules
7 DMR2YSF and DMR2NXDN cross-over modes DMR2YSF and DMR2NXDN cross-over modes
8 DMR+ / FreeDMR / HB-Link / custom hosts DMR+ / Phoenix
9 Custom DMR network, when Automatic Rewrite Rules is selected Operator's choice

Prefixes 6 and 7 are the same on both because they are built-in gateway functions rather than network slots. Prefix 8 is the closest thing to a universal convention. Everything else depends on how the hotspot in front of you was set up.

Choosing a prefix, and the one to avoid

Nothing in DMR Gateway prohibits any particular digit. But the digits are not equally safe, because real seven-digit talkgroups already exist and a rewrite range will happily swallow them.

The risk follows the DMR numbering plan, where the leading digits of a seven-digit talkgroup track the Mobile Country Code. 1, 8 and 9 are safe — little or nothing lives there. 4, 6 and 7 carry minimal risk. 2 and 5 have some exposure — MCC 2xx is Europe and the UK, 5xx is Asia and Oceania — which WPSD accepts in exchange for having a consistent default.

Do not use prefix 3. MCC 3xx is North America — 310 and 311 are the United States, 302 is Canada — so genuine seven-digit talkgroups beginning with 3 exist in quantity. A rewrite rule on 3 will map over live BrandMeister talkgroups, and the failure is silent: your radio transmits, the gateway routes it somewhere you did not intend, and nothing tells you why. If you need another slot, take 1.

Running the non-standard networks

What if you want AMCOMM, ADN, FreeSTAR, FreeDMR or another network that isn’t in the drop-down? You can — the digits are not reserved, and a rewrite rule you write yourself works exactly like one the software wrote. But two things constrain you, and neither is the digits.

You have five DMR slots, not nine. DMR Gateway connects to six networks: one XLX reflector, plus five others in any combination of DMR+, BrandMeister, TGIF or local HBLink systems. BrandMeister and TGIF take two of those five straight away. You will run out of slots long before you run out of prefix digits.

On WPSD you pick networks, not digits. Choose TGIF in the configurator and you get prefix 5; choose DMR+ and you get 8. The prefix follows the network type. The one place you genuinely choose your own digit is the Custom DMR Network slot — and there, the setting that matters is:

WPSD_AutoRewrites=0

That stops WPSD adjusting the custom network’s rewrite rules for you, so the rules you write by hand survive the web configurator regenerating everything else. Without it, your edits get overwritten the next time you apply a change. Pi-Star is the mirror image: you write every rule yourself, which is exactly why its prefixes differ from one hotspot to the next.

A fully loaded WPSD ends up looking something like this:

PrefixNetworkNotes
BrandMeisterThe primary network. No prefix, talkgroups entered as published.
1A second custom networkThe safest free digit. Requires a custom entry with your own rewrite rules.
2Alternative to 1Available if BrandMeister is primary and therefore not using it. Some MCC 2xx exposure.
3Leave emptyMCC 3xx is North America — collides with real seven-digit talkgroups.
4Alternative to 1Available if SystemX is not in use.
5TGIFAssigned by WPSD when you select TGIF.
6XLXBuilt-in function. Leave it alone.
7DMR2YSF / DMR2NXDNBuilt-in cross-over modes. Leave it alone.
8FreeDMR, DMR+, or another HBLink networkOne slot, one network — whichever you point it at owns the digit.
9Custom — AMCOMM, ADN, FreeSTARThe Custom DMR Network slot. Set WPSD_AutoRewrites=0 and write your own rules.

Count the DMR networks in that table and you get five, which is the ceiling. So the real question was never which digits are open. It is which five networks earn a slot.

Do not let two rules overlap. If a new rule’s range covers numbers another rule already claims, routing becomes a coin-flip rather than an error. Nothing warns you. Check your ranges against each other before you apply.

What this means for a downloaded talkgroup list

A padded talkgroup list is only correct for the configuration it was built against. A TGIF list padded for WPSD's prefix 5 is wrong on a Pi-Star where the operator put TGIF on 4 — every entry off by the leading digit, and again, no error message to explain it. Before importing anyone's padded CSV, check what your own DMRGateway.ini assigns. Before publishing one, say which configuration it assumes.

Notes:

1. Padding only applies to networks reached through DMR Gateway. If you run a single network, talkgroups are entered exactly as published.

2. Rewrite rules work in both directions. Traffic returning from the network is rewritten back to the padded number so your radio matches it to the contact you programmed.

3. Disconnect and reflector-control commands are padded the same way as talkgroups — a disconnect on a prefixed network is the prefix plus the usual control number.

Return to n6jet.com