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.Master

dmrdsession Master

On this page

This page covers the dmrdsession Master, the state machine of the master side of the session of one repeater, for the MMDVM network protocol or the HomeBrew Repeater Protocol (HBRP).

What it does

A Master is the master side of the session of one repeater. It speaks one of two dialects of package dmrd: the MMDVM network protocol of MMDVMHost and DMRGateway (DialectMMDVM), or the HomeBrew Repeater Protocol in the hex text form of its 2015 specification and of the Homebrew port of other masters (DialectHBRP). It answers each login step. It reports the RPTL and the RPTC to you before it answers them, so that you decide which repeaters log in and with which password. It takes the RPTO of a logged-in repeater with an RPTACK, as DMRGateway waits for it before it sends traffic. It answers a packet from a repeater that is not logged in with MSTNAK, except for the early packets of a repeater that waits for Accept (see below). It ends the session when the login does not finish within LoginTimeout of the first RPTL, and after Timeout without a packet once the repeater is logged in. It does no I/O. (DL5DI, G4KLX and DG1HT, IPSC Protocol Specs for homebrew DMR repeater, 2015-07-26; HBlink3 1db2730 hblink.py master_maintenance_loop; DMRGateway ee79d38)

When to use it

Use a Master in a server that repeaters, hotspots and gateways log in to: a network master, a test master for a repeater, or a bridge between networks. Keep one Master for each source address that sends you packets, and pass it the packets of that address. A Master makes no random numbers and keeps no password list: you draw the salt and look up the password when the Master reports a login.

Config

Pass a MasterConfig to NewMaster. The config is required, and the dialect must be the MMDVM network protocol or HBRP.

Field Type Default Description
Dialect dmrd.Dialect zero value Dialect is dmrd.DialectMMDVM or dmrd.DialectHBRP.
Timeout time.Duration not machine-readable; see the description Timeout is the time without a packet from the repeater after which the Master ends the session. 0 means TimeoutDefault.
LoginTimeout time.Duration not machine-readable; see the description LoginTimeout is the time after the first RPTL of a login in which the repeater must finish its login, or the Master ends the session. A repeated RPTL or RPTK does not restart it. 0 means LoginTimeoutDefault.

States and transitions

State returns the current state, and ID the repeater ID from the last RPTL. The Peer, the Master and the Bridge share the State type, and each uses some of its values.

States of Master, from Master.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. yes
StateAuth StateAuth is a Peer that sent RPTK, or a Master that sent the salt. yes
StateConfig StateConfig is a Peer that sent RPTC, or a Master that waits for it or for Accept or Refuse. yes
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 StateLogin
StateIdle Resume StateRunning
StateLogin Close, Refuse StateIdle
StateLogin Admit StateAuth
StateAuth Packet, Tick StateIdle
StateAuth Packet StateConfig
StateConfig Accept, Refuse, Reset, Tick StateIdle
StateConfig Accept StateRunning
StateRunning Close, Packet, Reset, Tick StateIdle
StateRunning Packet StateLogin

Transitions of Master

An RPTL starts a login: the Master reports it and waits for Admit or Refuse. Admit sends the salt. An RPTK with the token of the salt and the password gets an acknowledgement, and the Master waits for the RPTC. The Master reports the RPTC and waits for Accept or Refuse. Accept completes the login and the session runs. A wrong token, Refuse, an RPTCL, a new RPTL of a logged-in repeater, the login timeout, the timeout, or Close ends the session. Resume starts a logged-in session without a login, for a repeater that logged in to another replica of a server and now sends its packets here.

An acknowledgement does not name the step that it acknowledges. A repeater that sends its RPTK again because the acknowledgement is late gets two acknowledgements. It takes the second one as the acknowledgement of its RPTC, and sends its RPTO, pings and traffic before you call Accept. MMDVMHost, DMRGateway and the Peer all do this. While the Master waits for Accept, it drops the pings, DMRD, DMRA, DMRG, RPTG, RPTRSSI and RPTINTR of the repeater without MSTNAK, and keeps the text of its last RPTO. Accept sends one acknowledgement, reports the session up, and then reports the kept options. The packets of another repeater ID still get MSTNAK.

In the same way, MMDVMHost and DMRGateway take a second salt, sent for a repeated RPTL, as the acknowledgement of their RPTK and send the RPTC at once. They do not send that RPTC again. When it arrives before the RPTK, the Master keeps a copy of the last one without MSTNAK. The good RPTK gets its acknowledgement and then reports the kept RPTC as OutputConfig. A wrong RPTK, the end of the session and LoginTimeout discard the copy. The Master checks only the repeater ID, so pass it only the packets of the address of the session. (MMDVMHost 7008c62 DMRDirectNetwork.cpp clock; DMRGateway ee79d38 DMRNetwork.cpp clock)

Inputs and outputs

Inputs:

  • Packet takes each UDP packet from the repeater. Each packet that the Master takes restarts Timeout. The early packets that the Master drops while it waits for Accept do not restart LoginTimeout.
  • Admit, Accept and Refuse answer the login and config reports.
  • Close sends MSTCL, as a master that shuts down sends it.
  • Resume starts a session without a login.
  • Tick runs the timeout. Call it at the time Deadline returns.
  • Reset ends the session without a packet or an output.

Outputs are Output values with an OutputKind: packets to send to the repeater; the login and the config to check; the accepted options; the session up and down, with a Reason; the DMRD, DMRA and DMRG packets; the RPTG, RPTRSSI and RPTINTR messages; and each ping that the Master answered, so you can keep the time of the last ping. Every output but a send carries the repeater ID. The packet of a send output points into the Master and is valid until the next call. The packets of the other outputs point into the packet that you passed in, except the options that Accept reports and the config that an RPTK reports, which point into the Master and are valid until the next call. Copy a packet that you keep.

Give each method a slice with capacity 4.

Timers

  • LoginTimeout: the time after the first RPTL in which the repeater must finish its login. The default is 15s, the time after which an HBlink3 master drops a repeater. A repeated RPTL or RPTK does not restart it.
  • Timeout: the time without a packet from the repeater after which the Master ends the session. The default is 1m0s.

Tick sends nothing when the session times out. A packet of the repeater after that gets MSTNAK, so the repeater logs in again.

Worked example

The package example logs a Peer into a Master over the MMDVM network protocol in memory. The Master reports the config, which the example accepts, and the options:

func Example() {
    var rptc dmrd.MMDVMConfig
    copy(rptc[:], "RPTC")
    rptc.SetID(3002900)
    peer, _ := dmrdsession.NewPeer(&dmrdsession.PeerConfig{
        Dialect: dmrd.DialectMMDVM, ID: 3002900, Password: []byte("passw0rd"), Config: rptc[:], Options: []byte("TS2=91;"),
    })
    master, _ := dmrdsession.NewMaster(&dmrdsession.MasterConfig{Dialect: dmrd.DialectMMDVM})

    now := time.Duration(0)
    var toMaster, toPeer [][]byte
    keep := func(q [][]byte, o dmrdsession.Output) [][]byte {
        return append(q, append([]byte(nil), o.Packet...))
    }
    for _, o := range peer.Tick(now, nil) {
        toMaster = keep(toMaster, o)
    }
    for len(toMaster) > 0 {
        for _, p := range toMaster {
            fmt.Println("repeater:", dmrd.Classify(p, dmrd.DialectMMDVM))
            for _, o := range master.Packet(now, p, nil) {
                switch o.Kind {
                case dmrdsession.OutputSend:
                    toPeer = keep(toPeer, o)
                case dmrdsession.OutputLogin:
                    for _, a := range master.Admit(now, 0xfcb17c08, []byte("passw0rd"), nil) {
                        toPeer = keep(toPeer, a)
                    }
                case dmrdsession.OutputConfig:
                    fmt.Println("master event:", o.Kind)
                    for _, a := range master.Accept(now, nil) {
                        if a.Kind == dmrdsession.OutputSend {
                            toPeer = keep(toPeer, a)
                        } else {
                            fmt.Println("master event:", a.Kind)
                        }
                    }
                default:
                    fmt.Println("master event:", o.Kind)
                }
            }
        }
        toMaster = nil
        for _, p := range toPeer {
            fmt.Println("master:", dmrd.Classify(p, dmrd.DialectMMDVM))
            for _, o := range peer.Packet(now, p, nil) {
                if o.Kind == dmrdsession.OutputSend {
                    toMaster = keep(toMaster, o)
                } else {
                    fmt.Println("repeater event:", o.Kind)
                }
            }
        }
        toPeer = nil
    }
}
repeater: RPTL
master: RPTACK
repeater: RPTK
master: RPTACK
repeater: RPTC
master event: Config
master event: Up
master: RPTACK
repeater: RPTO
master event: Options
master: RPTACK
repeater event: Up

The next example resumes the session of a repeater, lets it time out, and shows the MSTNAK that answers the next ping of the repeater.

func ExampleMaster() {
    master, err := dmrdsession.NewMaster(&dmrdsession.MasterConfig{Dialect: dmrd.DialectMMDVM})
    if err != nil {
        fmt.Println(err)
        return
    }
    out := make([]dmrdsession.Output, 0, dmrdsession.MaxOutputs)
    for _, o := range master.Resume(0, 3002900, out[:0]) {
        fmt.Println(o.Kind, o.ID)
    }
    at, _ := master.Deadline()
    for _, o := range master.Tick(at, out[:0]) {
        fmt.Println(at, o.Kind, o.Reason, "in", o.State)
    }
    ping := dmrd.Control{Command: dmrd.CommandRPTPING, ID: 3002900}
    p, _ := ping.AppendBinary(nil, dmrd.DialectMMDVM)
    for _, o := range master.Packet(at, p, out[:0]) {
        fmt.Println("answer", dmrd.Classify(o.Packet, dmrd.DialectMMDVM))
    }
}
Up 3002900
1m0s Down Timeout in Running
answer MSTNAK

Errors

Packet, Tick and the answer methods return no errors. NewMaster returns an error for a nil config, and a configuration error for a dialect other than the MMDVM network protocol or HBRP, or a negative timer.

The doc comments of Master and its methods name no error.

Machines:

Guides:

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

Edit this page on GitHub