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. Guides
  4. Use basic privacy

Use basic privacy

On this page

This guide shows how to send and receive voice calls with Basic Privacy, the 16-bit key scheme of many radios, with package privacy.

Goal

Apply Basic Privacy to the voice of a call that a voice.Transmitter sends, and remove it from the voice of a call that a voice.Receiver gets, with the key number that the radios use.

What you need

  • Go and a checkout of dmrgo. The example runs offline.
  • The packages privacy and voice.
  • The key number of the radios, 1 to 255 as a radio shows it, or the 16-bit key value.
  • A radio service other than amateur. The amateur service forbids messages encoded to obscure their meaning (ITU Radio Regulations Article 25.2A, and for example 47 CFR 97.113(a)(4) in the United States), and the package refuses to encrypt in it.

Basic Privacy is a weak scheme: a fixed pattern from a 16-bit key XORs every voice frame, the same in every call. It hides a call from a casual listener only. Receiving encrypted traffic that you are not a party to can be unlawful, for example under 18 USC 2511 in the United States.

Run the example from the top of the repository:

go test -C v2 -run ExampleTransmitter -v ./privacy

Steps

1. Make the key and the Transmitter

privacy.NewBasicKeyNumber returns the key of a key number as a radio shows it. privacy.NewBasicKey takes the 16-bit value instead. privacy.NewTransmitter takes the key and the radio service of the station. It returns ErrAmateur for the amateur service, and an error for a service that is not stated.

func basicTransmitter() (*privacy.Key, *privacy.Transmitter, error) {
    key := privacy.NewBasicKeyNumber(100)
    if _, err := privacy.NewTransmitter(&privacy.TransmitterConfig{Key: key, Service: privacy.ServiceAmateur}); errors.Is(err, privacy.ErrAmateur) {
        fmt.Println("amateur:", err)
    }
    ptx, err := privacy.NewTransmitter(&privacy.TransmitterConfig{Key: key, Service: privacy.ServiceLandMobile})
    if err != nil {
        return nil, nil, err
    }
    return key, ptx, nil
}

2. Make the Receiver

privacy.NewReceiver makes a Receiver, and Receiver.AddKey gives it the key. A Receiver holds one Basic Privacy key; a new one replaces it.

func basicReceiver(key *privacy.Key) (*privacy.Receiver, error) {
    prx := privacy.NewReceiver()
    if err := prx.AddKey(key); err != nil {
        return nil, err
    }
    return prx, nil
}

3. Send the call

Set the Privacy service option and FID 0x10 in the voice.Call, and call Transmitter.Start of the privacy Transmitter for each call. A Basic Privacy key ignores the message indicator, and sends no PI header. Then pass each burst output of the voice.Transmitter through Transmitter.Output before it goes on air. It changes the three AMBE+2 frames of each voice burst in place and leaves other bursts as they are.

func sendPrivateCall(ptx *privacy.Transmitter, tx *voice.Transmitter) ([]vocoder.AMBEFrame, error) {
    call := voice.Call{Group: true, Target: 9, Source: 3002068, Options: layer3.ServiceOptions{IsPrivacy: true}, FID: enums.FIDMotorola}
    ptx.Start(0)
    if err := tx.Start(0, call, nil); err != nil {
        return nil, err
    }
    sent := make([]vocoder.AMBEFrame, 18)
    for i := range sent {
        sent[i] = vocoder.AMBEFrame{byte(i), 0x5A, 0xA5, byte(3 * i), 0x0F, 0xF0, 0x80}
        _ = tx.Frame(sent[i])
    }
    tx.Stop(0)
    return sent, nil
}
func encryptOutput(ptx *privacy.Transmitter, o *voice.Output, onAir []vocoder.AMBEFrame) ([]vocoder.AMBEFrame, error) {
    if err := ptx.Output(o); err != nil {
        return onAir, err
    }
    if o.Hint.Kind == layer2.KindVoice {
        frames, _ := o.Burst.AMBEFrames()
        onAir = append(onAir, frames[:]...)
    }
    return onAir, nil
}

4. Receive the call

Give each event of the voice.Receiver to Receiver.Event. For a voice event it writes the three frames of the burst, in the clear when it holds the key. It returns the Info of the call: Encrypted when the call carries privacy, Decrypting when the Receiver removes it.

func decryptBurst(rx *voice.Receiver, prx *privacy.Receiver, o *voice.Output, events []voice.Event, received []vocoder.AMBEFrame, info privacy.Info) ([]vocoder.AMBEFrame, privacy.Info) {
    for _, e := range rx.Burst(o.Due, &o.Burst, o.Hint, events[:0]) {
        var frames [layer2.VoiceSlotsPerBurst]vocoder.AMBEFrame
        info = prx.Event(&e, &frames)
        if e.Kind == voice.EventVoice {
            received = append(received, frames[:]...)
        }
    }
    return received, info
}

Some radios send Basic Privacy without the Privacy service option in the LC. Receiver.ForceBasic applies the key to every voice call without a PI header.

Output

The refusal in the amateur service, then the frames on air and after the Receiver:

amateur: privacy: the amateur service forbids encryption
on air: 0 of 18 frames in the clear
received: 18 of 18 frames in the clear
encrypted true PI header false decrypting true

The errors of the Transmitter:

Error Returned by Meaning
dmrgo.ConfigError Transmitter.Data ConfigError is the error of a constructor, and of a machine method that takes a config, option or argument field, for a field with a value out of range.
dmrgo.ErrNilArgument Transmitter.Output ErrNilArgument is returned by a function or method of the library that returns an error when a pointer, func or interface argument it needs is nil.
privacy.ErrDataAlgorithm Transmitter.Data ErrDataAlgorithm is returned by Transmitter.Data for a key other than ARC4: no public capture with a key proves the data framing of AES, DES or Basic Privacy.
privacy.ErrNotStarted Transmitter.Output ErrNotStarted is returned by Transmitter.Output before Start.

How it works

ETSI TS 102 361 defines only the containers of privacy: the PI header burst and the Privacy bit of the service options. It does not define the schemes. A Basic Privacy key is a 48-bit pattern from the 16-bit key value, and the same pattern XORs every AMBE+2 frame. There is no PI header and no message indicator. A Receiver that joins a call late removes the privacy from the voice bursts after the LC of the call shows the Privacy option, or from every burst with ForceBasic. The value of a key number is the XOR of one base value for each bit set in the number; the base values come from public reverse engineering, and a public capture confirms number 100. (ETSI TS 102 361-1 clauses 5.1.2.2, 6.2 and 9.3.6, ETSI TS 102 361-2 clause 7.2.1)

The same package handles the ARC4, AES-128 and AES-256 schemes, which have a PI header with the algorithm, the key ID and a message indicator. For data, the Receiver reports Basic Privacy packets but leaves them as they are, and the Transmitter returns ErrDataAlgorithm for Basic Privacy data, as no public capture with a key proves their framing. Nothing else in dmrgo imports package privacy, so a program that does not import it sends and receives voice as before.

The bursts go to and from the voice machines: voice Transmitter and voice Receiver.

Edit this page on GitHub