These dmrgo docs are built from main and can describe changes that no release has yet. No release of dmrgo has these docs.

  1. DMRHub
  2. dmrgo
  3. State machines
  4. dmrdsession.Bridge

dmrdsession Bridge

On this page

This page covers the dmrdsession Bridge, the state machine of one OpenBridge link between two masters.

What it does

A Bridge is one end of an OpenBridge link. OpenBridge carries DMRD packets between masters, signed with a key that both ends share; it has no login. The Bridge checks the signature of each packet that it takes, signs the packets that you send with SignInPlace, and tracks whether the other end is alive from the packets with a good signature. With the enhanced OpenBridge of FreeDMR, it also sends the BCKA keepalive. The Bridge is not a dialect of the MMDVM network protocol or HBRP: OpenBridge is a separate protocol built on the same DMRD packet. It does no I/O. (FreeDMR 546165eb hblink.py and bridge_master.py; HBlink3 1db2730)

When to use it

Use a Bridge in a master that links to another master over OpenBridge, such as an HBlink3 or FreeDMR server or the master of a large public DMR network. Use one Bridge for each link. Turn on the enhanced mode only when the other end runs the enhanced OpenBridge of FreeDMR. Use dmrd.DecodeBridge to read the data packets that the Bridge passes on.

Config

Pass a BridgeConfig to NewBridge. The config is required. Key is the passphrase of the link, as dmrdauth.NewBridgeKey takes it. Keepalive applies only with Enhanced.

Field Type Default Description
Key []byte zero value Key is the passphrase of the OpenBridge link (see dmrdauth.NewBridgeKey).
Enhanced bool zero value Enhanced turns on FreeDMR's enhanced OpenBridge: the Bridge sends a BCKA every Keepalive. Without it OpenBridge has no keepalive, and the Bridge sends nothing of its own.
Keepalive time.Duration not machine-readable; see the description Keepalive is the BCKA period. 0 means KeepaliveDefault.
Timeout time.Duration not machine-readable; see the description Timeout is the time without a packet with a good signature after which the Bridge reports OutputDown. 0 means TimeoutDefault, the time after which FreeDMR stops sending to a peer.

States and transitions

State returns the current state. The Peer, the Master and the Bridge share the State type. A Bridge uses only two of its values: the link is idle, or it runs.

States of Bridge, from Bridge.State:

State Meaning Seen in tests
StateIdle StateIdle has no session: a Peer after Close, a Master before an RPTL or after the end of a session, a Bridge, enhanced or not, before the first packet with a good signature and after Timeout without one. yes, first state
StateWait StateWait is a Peer that waits to log in again. no
StateLogin StateLogin is a Peer that sent RPTL, or a Master that waits for Admit or Refuse. no
StateAuth StateAuth is a Peer that sent RPTK, or a Master that sent the salt. no
StateConfig StateConfig is a Peer that sent RPTC, or a Master that waits for it or for Accept or Refuse. no
StateOptions StateOptions is a Peer that sent RPTO. no
StateRunning StateRunning is a logged-in session, or a Bridge, enhanced or not, whose peer sent a packet with a good signature within Timeout. yes

Transitions seen in tests:

From Method call To
StateIdle Packet StateRunning
StateRunning Tick StateIdle

Transitions of Bridge

The link runs while the other end sent a packet with a good signature, a BCKA or any other, within Timeout. The first such packet after an idle link reports the link up. When Timeout passes without one, Tick reports the link down. This works with and without the enhanced mode. Without it, OpenBridge has no keepalive, so the link of a quiet peer goes down at Timeout and comes up again with its next packet.

Inputs and outputs

Inputs:

  • Packet takes each UDP packet from the other end.
  • SignInPlace writes the signature into the last octets of an OpenBridge packet that you send.
  • Tick runs the timeout and, in the enhanced mode, sends the keepalive. Call it at the time Deadline returns. A Bridge without the enhanced mode has no deadline while the link is idle.

Outputs are Output values with an OutputKind: the BCKA to send, the link up and down, the DMRD and DMRE data packets with a good signature, and the BCSQ, BCST and BCVE messages. A packet without a good signature, or that is not OpenBridge, gives no output. The packets of the data and message outputs point into the packet that you passed in. Give each method a slice with capacity 4.

Timers

  • Keepalive: the BCKA period of an enhanced Bridge. The default is 10s, the BCKA period of FreeDMR. The first BCKA goes out at the first Tick.
  • Timeout: the time without a packet with a good signature after which the Bridge reports the link down. The default is 1m0s, the time after which FreeDMR stops sending to a peer.

Worked example

This example runs both ends of an enhanced link in memory. The BCKA of one end brings the link up at the other. A signed BCSQ passes, the same packet with one bit changed is dropped, and the link goes down one Timeout after the last good packet.

func ExampleBridge() {
    cfg := dmrdsession.BridgeConfig{Key: []byte("bridge passphrase"), Enhanced: true}
    a, _ := dmrdsession.NewBridge(&cfg)
    b, err := dmrdsession.NewBridge(&cfg)
    if err != nil {
        fmt.Println(err)
        return
    }
    out := make([]dmrdsession.Output, 0, dmrdsession.MaxOutputs)
    for _, ka := range a.Tick(0, out[:0]) {
        for _, o := range b.Packet(0, ka.Packet, nil) {
            fmt.Println("b:", o.Kind)
        }
    }
    sq := dmrd.BridgeControl{Command: dmrd.CommandBCSQ, TalkGroup: 91, Stream: 7}
    p, _ := sq.AppendBinary(nil)
    if err := a.SignInPlace(p); err != nil {
        fmt.Println(err)
        return
    }
    for _, o := range b.Packet(time.Second, p, out[:0]) {
        fmt.Println("b:", o.Kind, o.Command)
    }
    p[len(p)-1] ^= 1
    fmt.Println("b: bad signature,", len(b.Packet(2*time.Second, p, out[:0])), "outputs")
    for {
        at, _ := b.Deadline()
        out = b.Tick(at, out[:0])
        if len(out) > 0 && out[0].Kind == dmrdsession.OutputDown {
            fmt.Println("b:", at, out[0].Kind, out[0].Reason, b.State())
            break
        }
    }
}

Output:

b: Up
b: Message BCSQ
b: bad signature, 0 outputs
b: 1m1s Down Timeout Idle

Errors

Packet and Tick return no errors: a packet with a bad signature gives no output. SignInPlace returns an error for a Bridge that NewBridge did not make and for a packet that is not OpenBridge. NewBridge returns an error for a nil config, and a configuration error for a negative Keepalive or Timeout.

Error Returned by Meaning
dmrgo.ErrZeroValue Bridge.SignInPlace ErrZeroValue is returned by a method of a state machine that starts work, such as Start, Request or Send, when the machine is a zero value and not made with its constructor.

Machines:

Guides:

  • Connect to a network (MMDVM network protocol, HBRP, IPSC, Hytera)
  • Rewrite and relay a voice call

Edit this page on GitHub