protocol

package
v0.0.0-...-cfba5c7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 2, 2018 License: Apache-2.0 Imports: 13 Imported by: 13

Documentation

Overview

Package protocol contains the low-level LoRaWAN types

Index

Constants

View Source
const (
	// MaxNwkID is the maximum allowed value for NwkID
	MaxNwkID = 0x7F
	// MaxNwkAddr is the maximum allowed value for NwkAddr
	MaxNwkAddr = 0x1FFFFFF
	// NetworkIDMask is the
	NetworkIDMask uint32 = 0xFE000000
)
View Source
const (
	MaxNetworkBitsMAL uint32 = 0x07FFF // 64 - MALarge (24) - 25 = 15 bits available
	MaxNetworkBitsMAM uint32 = 0x07FF  // 64 - MAMedium (28) - 25 = 11 bits available
	MaxNetworkBitsMAS uint32 = 0x07    // 64 - MASmall (36) - 25 = 3 bits available
)

This is the maximum number of bits that can be used for a NetID in a network EUI

View Source
const (
	BatteryExternalPower uint8 = 0
	BatteryUnavailable   uint8 = 0xFF
)

Battery power status constants

View Source
const (
	// LoRaWANR1 is the official version number used in the MHDR struct [4.2.2]
	LoRaWANR1 uint8 = 0
	// MaxSupportedVersion is the latest version supported
	MaxSupportedVersion uint8 = LoRaWANR1
)
View Source
const MaxFOptsLen int = 15

MaxFOptsLen is the maximum length for the FOpts field.

View Source
const MinimumMessageSize = 12

MinimumMessageSize is the absolute minimum size for a LoRaWAN message. Messages shorter than this will be rejected outright

Variables

View Source
var (
	// ErrBufferTruncated is returned when the buffer is too short to encode or decode
	ErrBufferTruncated = errors.New("buffer too short")
	// ErrNilError is returned when one or more parameter is nil
	ErrNilError = errors.New("parameter is nil")
	// ErrParameterOutOfRange is returned when one of the parameters are out of range
	ErrParameterOutOfRange = errors.New("parameter out of range")
	// ErrInvalidParameterFormat is returned when a supplied parameter is invalid
	ErrInvalidParameterFormat = errors.New("invalid parameter format")
	// ErrCryptoError is returned when there's an error with the crypto library. It's not a common occurrence.
	ErrCryptoError = errors.New("crypto system error")
	// ErrInvalidSource is returned when the input buffer contains corrupted data
	ErrInvalidSource = errors.New("source buffer is corrupted")
	// ErrInvalidMessageType is returned when the message type isn't supported
	ErrInvalidMessageType = errors.New("invalid message type")
	// ErrInvalidLoRaWANVersion is returned when the LoRaWAN version is unsupported
	ErrInvalidLoRaWANVersion = errors.New("unsupported LoRaWAN version")
)
View Source
var ErrInvalidMIC = errors.New("invalid MIC")

ErrInvalidMIC is returned when the JoinAccept MIC is invalid

Functions

func MaxNetID

func MaxNetID(size MASize) uint32

MaxNetID return the maximum NetID that can safely be put into the EUI

Types

type AESKey

type AESKey struct {
	Key [16]byte
}

AESKey represents an AES-128 key

func AESKeyFromString

func AESKeyFromString(keyStr string) (AESKey, error)

AESKeyFromString converts a byte string (with optional spaces) into an AES key

func AppSKeyFromNonces

func AppSKeyFromNonces(appKey AESKey, appNonce [3]byte, netID uint32, devNonce uint16) (AESKey, error)

AppSKeyFromNonces generates a new application session key derived from the application key. [6.2.5]

func NewAESKey

func NewAESKey() (AESKey, error)

NewAESKey creates a new AES key from the secure random generator

func NwkSKeyFromNonces

func NwkSKeyFromNonces(appKey AESKey, appNonce [3]byte, netID uint32, devNonce uint16) (AESKey, error)

NwkSKeyFromNonces generates a new network session key derived from the application key. [6.2.5]

func (AESKey) String

func (k AESKey) String() string

type CFList

type CFList struct {
}

Copyright 2018 Telenor Digital AS

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

CFList contains region specific information on frequencies for end-devices.

type CID

type CID uint8

CID represents a MACCommand [5]

const (
	// LinkCheckReq is sent by the end-device to the network (no payload).
	LinkCheckReq CID = 0x02
	// LinkCheckAns is sent by the network to the end-device.
	LinkCheckAns CID = 0x02
	// LinkADRReq is sent by the network to the end-device.
	LinkADRReq CID = 0x03
	// LinkADRAns is sent by the end-device to the network.
	LinkADRAns CID = 0x03
	// DutyCycleReq is sent by the network to the end-device.
	DutyCycleReq CID = 0x04
	// DutyCycleAns is sent by the end-device to the network.
	DutyCycleAns CID = 0x04
	// RXParamSetupReq is sent by the network to the end-device (no payload).
	RXParamSetupReq CID = 0x05
	// RXParamSetupAns is sent by the end-device to the network.
	RXParamSetupAns CID = 0x05
	// DevStatusReq is sent by the network to the end-device (no payload).
	DevStatusReq CID = 0x06
	// DevStatusAns is sent by the end-device to the network.
	DevStatusAns CID = 0x06
	// NewChannelReq is sent by the network to the end-device.
	NewChannelReq CID = 0x07
	// NewChannelAns is sent by the end-device to the network.
	NewChannelAns CID = 0x07
	// RXTimingSetupReq is sent by the network to the end-device.
	RXTimingSetupReq CID = 0x08
	// RXTimingSetupAns is sent by the end-device to the network (no payload)
	RXTimingSetupAns CID = 0x08
)

MAC commands for Class A devices

const (
	// PingSlotInfoReq is sent by the end-device to the network.
	PingSlotInfoReq CID = 0x10
	// PingSlotInfoAns is sent by the network to the end-device.
	PingSlotInfoAns CID = 0x10
	// PingSlotChannelReq is sent by the network to the end-device.
	PingSlotChannelReq CID = 0x11
	// PingSlotFreqAns is sent by the end-device to the network.
	PingSlotFreqAns CID = 0x11
	// BeaconTimingReq is sent by the end-device to the network.
	BeaconTimingReq CID = 0x12
	// BeaconTimingAns is sent by the network to the end-device.
	BeaconTimingAns CID = 0x12
	// BeaconFreqReq is sent by the network to the end-device.
	BeaconFreqReq CID = 0x13
	// BeaconFreqAns is sent by the end-device to the network.
	BeaconFreqAns CID = 0x13
)

MAC commands for Class B devices

type DLSettings

type DLSettings struct {
	RX1DRoffset byte
	RX2DataRate byte
}

Copyright 2018 Telenor Digital AS

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

DLSettings contains the downlink configuration for the end-device in a JoinAccept message [6.2.5]

type DevAddr

type DevAddr struct {
	NwkID   uint8  // 7 bits [6.1.1]
	NwkAddr uint32 // 25 bits [6.1.1]

}

DevAddr is a device address [6.1.1]

func DevAddrFromString

func DevAddrFromString(devAddrStr string) (DevAddr, error)

DevAddrFromString converts a hex representation to a DevAddr value

func DevAddrFromUint32

func DevAddrFromUint32(val uint32) DevAddr

DevAddrFromUint32 converts the integer into a DevAddr struct

func NewDevAddr

func NewDevAddr() DevAddr

NewDevAddr creates a new random DevAddr value. It uses the defalt pseudo-random generator.

func (DevAddr) String

func (d DevAddr) String() string

String prints a string representation of the device address (aka the fmt.Stringer interface)

func (DevAddr) ToUint32

func (d DevAddr) ToUint32() uint32

ToUint32 converts the device address as a single 32-bit integer

type EUI

type EUI struct {
	Octets [8]byte
}

EUI represents an IEEE EUI-64 identifier. The identifier is described at http://standards.ieee.org/develop/regauth/tut/eui64.pdf

func EUIFromString

func EUIFromString(euiStr string) (EUI, error)

EUIFromString converts a string on the format "xx-xx-xx..." in hex to an internal representation

func EUIFromUint64

func EUIFromUint64(val uint64) EUI

EUIFromUint64 converts an uint64 value to an EUI.

func NewApplicationEUI

func NewApplicationEUI(ma MA, netID uint32, counter uint32) EUI

NewApplicationEUI creates a new application EUI. The bit layout for the EUI is as follows:

8.......7.......6.......5.......4.......3.......2.......1.......0
|                               |NwkID--|                         7 bits
|                                       |(Counter)--------------| 25 bits
|              |NetID-------------------|                         24 bits
|MA-L-------------------|                                         24 bits
|MA-M-----------------------|                                     28 bits
|MA-S------------------------------|                              36 bits

Both NetID and NwkID might be overwritten by the MA block.

func NewDeviceEUI

func NewDeviceEUI(ma MA, netID uint32, nwkAddr uint32) EUI

NewDeviceEUI creates a new device EUI. The following bit pattern will be used for device EUIs:

8.......7.......6.......5.......4.......3.......2.......1.......0
|                               |NwkID--|                         7 bits
|                                       |NwkAddr (counter)------| 25 bits
|              |NetID-------------------|                         24 bits
|MA-L-------------------|                                         24 bits
|MA-M-----------------------|                                     28 bits
|MA-S------------------------------|                              36 bits

The MA block might overwrite parts of the NetID and NwkID values.

func NewNetworkEUI

func NewNetworkEUI(ma MA, netID uint32) EUI

NewNetworkEUI creates a new network EUI. The bit layout is as follows:

8.......7.......6.......5.......4.......3.......2.......1.......0
|                               |NwkID--|                         7 bits
|                                       |(0)--------------------| 25 bits
|              |NetID (counter)---------|                         24 bits
|MA-L-------------------|                                         24 bits
|MA-M-----------------------|                                     28 bits
|MA-S------------------------------|                              36 bits

The medium and small MA blocks might overwrite the NetID and NwkID values.

func (EUI) String

func (eui EUI) String() string

String returns a string representation of the EUI (XX-XX-XX-XX...)

func (*EUI) ToUint64

func (eui *EUI) ToUint64() uint64

ToUint64 returns the EUI as a uin64 integer

type FCtrl

type FCtrl struct {
	ADR       bool  // [4.3.1.1]
	ADRACKReq bool  // [4.3.1.1]
	ACK       bool  // [4.3.1.2]
	FPending  bool  // [4.3.1.4] Is interpreted as RFU in uplink frames
	ClassB    bool  // [10] uplink frames have this bit set
	FOptsLen  uint8 // [4.3.1.6]
}

Copyright 2018 Telenor Digital AS

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

FCtrl contains frame control bits [4.3.1]

type FHDR

type FHDR struct {
	DevAddr DevAddr       // [6.1.1]
	FCtrl   FCtrl         // [4.3.1]
	FCnt    uint16        // [4.3.1.5]
	FOpts   MACCommandSet // MAC Commands in the FOpts structure
}

FHDR is the frame header [4.3.1]

type JoinAcceptPayload

type JoinAcceptPayload struct {
	AppNonce   [3]byte
	NetID      uint32
	DevAddr    DevAddr
	DLSettings DLSettings
	RxDelay    byte
	CFList     CFList
}

JoinAcceptPayload is the payload sent by the network server to an end-device in response to a JoinRequest message. The message is encrypted with the (AES) application key. [6.2.5]

func (*JoinAcceptPayload) GenerateAppNonce

func (j *JoinAcceptPayload) GenerateAppNonce() ([3]byte, error)

GenerateAppNonce generates a new AppNonce for an application. [6.2.5]

type JoinRequestPayload

type JoinRequestPayload struct {
	AppEUI   EUI
	DevEUI   EUI
	DevNonce uint16
}

JoinRequestPayload is the payload sent by the device in a JoinRequest message [6.2.4]. The message is not encrypted.

type MA

type MA struct {
	Prefix [5]byte // MA prefix for EUI
	Size   MASize  // The size of the prefix bytes
}

MA defines a MA block

func NewMA

func NewMA(prefix []byte) (MA, error)

NewMA creates a new MA block. The size of the prefix decides which kind of MA this is; 3 bytes yields a MA-L (24 bits, all three bytes are used), 4 bytes MA-M (28 bits, only the 4 MSB are used of the last byte) and 5 bytes yields a MA-S (36 bits, only the 4 MSB are used of the 5th byte)

func (MA) Combine

func (m MA) Combine(eui EUI) EUI

Combine combines the MA with an EUI to make the final EUI.

func (*MA) String

func (m *MA) String() string

String prints the MA as a hex-formatted string. Depending on the size the string will be "hh-hh-hh" (MA-L), "hh-hh-hh-hh" (MA-M) or "hh-hh-hh-hh-hh" (MA-S)

type MACBeaconFreqAns

type MACBeaconFreqAns struct {
	// contains filtered or unexported fields
}

MACBeaconFreqAns is sent by the end-device to acknowledge a BeaconFreqReq command

func (*MACBeaconFreqAns) ID

func (m *MACBeaconFreqAns) ID() CID

func (*MACBeaconFreqAns) Length

func (m *MACBeaconFreqAns) Length() int

Length returns the length of the MAC command when encoded into a byte buffer

func (m *MACBeaconFreqAns) Uplink() bool

type MACBeaconFreqReq

type MACBeaconFreqReq struct {
	Frequency uint32 // 3 byte long
	// contains filtered or unexported fields
}

MACBeaconFreqReq is sent by the network server to the end-device to modify the frequency

func (*MACBeaconFreqReq) ID

func (m *MACBeaconFreqReq) ID() CID

func (*MACBeaconFreqReq) Length

func (m *MACBeaconFreqReq) Length() int

Length returns the length of the MAC command when encoded into a byte buffer

func (m *MACBeaconFreqReq) Uplink() bool

type MACBeaconTimingAns

type MACBeaconTimingAns struct {
	Delay   uint16 // Delay until next beacon [14.5]
	Channel uint8  // Index of channel where the next beacon will be broadcasted
	// contains filtered or unexported fields
}

MACBeaconTimingAns is sent by the network server to the end-device in response to a BeaconTimingReq command

func (*MACBeaconTimingAns) ID

func (m *MACBeaconTimingAns) ID() CID

func (*MACBeaconTimingAns) Length

func (m *MACBeaconTimingAns) Length() int

Length returns the length of the MAC command when encoded into a byte buffer

func (m *MACBeaconTimingAns) Uplink() bool

type MACBeaconTimingReq

type MACBeaconTimingReq struct {
	// contains filtered or unexported fields
}

MACBeaconTimingReq is sent by the end-device to request the next timing and channel

func (*MACBeaconTimingReq) ID

func (m *MACBeaconTimingReq) ID() CID

func (*MACBeaconTimingReq) Length

func (m *MACBeaconTimingReq) Length() int

Length returns the length of the MAC command when encoded into a byte buffer

func (m *MACBeaconTimingReq) Uplink() bool

type MACCommand

type MACCommand interface {
	// ID returns the Command ID (aka CID) for MAC command.
	ID() CID
	// Length returns the length of the MAC command when encoded
	Length() int
	// Uplink returns true if this command is an uplink command
	Uplink() bool
	// contains filtered or unexported methods
}

MACCommand represents MAC commands

func NewDownlinkMACCommand

func NewDownlinkMACCommand(id CID) MACCommand

NewDownlinkMACCommand returns a new downlink command

func NewUplinkMACCommand

func NewUplinkMACCommand(id CID) MACCommand

NewUplinkMACCommand creates a new MAC Command instance

type MACCommandSet

type MACCommandSet struct {
	// contains filtered or unexported fields
}

MACCommandSet is a collection of MAC commands. The command sets have an expected length when decoding (the packets hold the number of bytes) and an absolute limit when encoding.

func NewFOptsSet

func NewFOptsSet(message MType) MACCommandSet

NewFOptsSet returns a set for the FOpts field. The max length is set to 16.

func NewMACCommandSet

func NewMACCommandSet(message MType, maxLength int) MACCommandSet

NewMACCommandSet creates a new MACCommandSet instance. The message type indicates what kind of MAC commands we can expect and the maxLength parameter describes the expected length (when decoding a byte buffer) or the maximum length (when encoding into a buffer)

func (*MACCommandSet) Add

func (m *MACCommandSet) Add(cmd MACCommand) bool

Add adds a new MAC command to the set

func (*MACCommandSet) Clear

func (m *MACCommandSet) Clear()

Clear removes all of the MAC commands in the set

func (*MACCommandSet) Contains

func (m *MACCommandSet) Contains(cid CID) bool

Contains returns true if the command set contains a command with the given CID

func (*MACCommandSet) Copy

func (m *MACCommandSet) Copy(other MACCommandSet) bool

Copy will copy the contents of the other command set. If there's not enough room it will return false

func (*MACCommandSet) EncodedLength

func (m *MACCommandSet) EncodedLength() int

EncodedLength returns the current encoded length of the set

func (*MACCommandSet) List

func (m *MACCommandSet) List() []MACCommand

List returns a list of sorted MAC Commands

func (*MACCommandSet) Message

func (m *MACCommandSet) Message() MType

Message returns true if the set contains uplink commands

func (*MACCommandSet) Remove

func (m *MACCommandSet) Remove(cid CID)

Remove removes a command from the set

func (*MACCommandSet) Size

func (m *MACCommandSet) Size() int

Size returns the number of commands in the set

type MACDevStatusAns

type MACDevStatusAns struct {
	Battery uint8
	Margin  uint8
	// contains filtered or unexported fields
}

MACDevStatusAns is sent from the end-device to the network server as a response to the DevStatusReq command

func (*MACDevStatusAns) ID

func (m *MACDevStatusAns) ID() CID

func (*MACDevStatusAns) Length

func (m *MACDevStatusAns) Length() int

Length returns the length of the MAC command when encoded into a byte buffer

func (m *MACDevStatusAns) Uplink() bool

type MACDevStatusReq

type MACDevStatusReq struct {
	// contains filtered or unexported fields
}

MACDevStatusReq is sent from the network server to an end-device to request the device status

func (*MACDevStatusReq) ID

func (m *MACDevStatusReq) ID() CID

func (*MACDevStatusReq) Length

func (m *MACDevStatusReq) Length() int

Length returns the length of the MAC command when encoded into a byte buffer

func (m *MACDevStatusReq) Uplink() bool

type MACDutyCycleAns

type MACDutyCycleAns struct {
	// contains filtered or unexported fields
}

MACDutyCycleAns is sent from the end-device as a response to the DutyCycleReq command

func (*MACDutyCycleAns) ID

func (m *MACDutyCycleAns) ID() CID

func (*MACDutyCycleAns) Length

func (m *MACDutyCycleAns) Length() int

Length returns the length of the MAC command when encoded into a byte buffer

func (m *MACDutyCycleAns) Uplink() bool

type MACDutyCycleReq

type MACDutyCycleReq struct {
	MaxDCycle uint8
	// contains filtered or unexported fields
}

MACDutyCycleReq is sent from the network coordinator to the end-device to set the duty cycle

func (*MACDutyCycleReq) ID

func (m *MACDutyCycleReq) ID() CID

func (*MACDutyCycleReq) Length

func (m *MACDutyCycleReq) Length() int

Length returns the length of the MAC command when encoded into a byte buffer

func (m *MACDutyCycleReq) Uplink() bool

type MACLinkADRAns

type MACLinkADRAns struct {
	PowerACK       bool
	DataRateACK    bool
	ChannelMaskACK bool
	// contains filtered or unexported fields
}

MACLinkADRAns is sent from the end-device to the network server as a response to the LinkAdrReq command

func (*MACLinkADRAns) ID

func (m *MACLinkADRAns) ID() CID

func (*MACLinkADRAns) Length

func (m *MACLinkADRAns) Length() int

Length returns the length of the MAC command when encoded into a byte buffer

func (m *MACLinkADRAns) Uplink() bool

type MACLinkADRReq

type MACLinkADRReq struct {
	DataRate   uint8  // Region specific - see [7.1.3], [7.2.3], [7.3.3], [7.4.3]
	TXPower    uint8  // Region specific - see [7.1.3], [7.2.3], [7.3.3], [7.4.3]
	ChMask     uint16 // Channel mask - 1 bit per channel
	Redundancy uint8  // TODO: See [5.2]
	// contains filtered or unexported fields
}

MACLinkADRReq is sent from the network server to the end-device to perform data rate adoption

func (*MACLinkADRReq) ID

func (m *MACLinkADRReq) ID() CID

func (*MACLinkADRReq) Length

func (m *MACLinkADRReq) Length() int

Length returns the length of the MAC command when encoded into a byte buffer

func (m *MACLinkADRReq) Uplink() bool

type MACLinkCheckAns

type MACLinkCheckAns struct {
	Margin uint8
	GwCnt  uint8
	// contains filtered or unexported fields
}

MACLinkCheckAns is sent from the network server to the end-device

func (*MACLinkCheckAns) ID

func (m *MACLinkCheckAns) ID() CID

func (*MACLinkCheckAns) Length

func (m *MACLinkCheckAns) Length() int

Length returns the length of the MAC command when encoded into a byte buffer

func (m *MACLinkCheckAns) Uplink() bool

type MACLinkCheckReq

type MACLinkCheckReq struct {
	// contains filtered or unexported fields
}

MACLinkCheckReq is sent from the end-device to the network server

func (*MACLinkCheckReq) ID

func (m *MACLinkCheckReq) ID() CID

func (*MACLinkCheckReq) Length

func (m *MACLinkCheckReq) Length() int

Length returns the length of the MAC command when encoded into a byte buffer

func (m *MACLinkCheckReq) Uplink() bool

type MACNewChannelAns

type MACNewChannelAns struct {
	DataRangeOK        bool
	ChannelFrequencyOK bool
	// contains filtered or unexported fields
}

MACNewChannelAns is sent from the end-device to the network server as a response to the NewChannelReq command

func (*MACNewChannelAns) ID

func (m *MACNewChannelAns) ID() CID

func (*MACNewChannelAns) Length

func (m *MACNewChannelAns) Length() int

Length returns the length of the MAC command when encoded into a byte buffer

func (m *MACNewChannelAns) Uplink() bool

type MACNewChannelReq

type MACNewChannelReq struct {
	ChIndex uint8
	Freq    uint32
	MaxDR   uint8
	MinDR   uint8
	// contains filtered or unexported fields
}

MACNewChannelReq is sent from the network server to set up a new channel on the device

func (*MACNewChannelReq) ID

func (m *MACNewChannelReq) ID() CID

func (*MACNewChannelReq) Length

func (m *MACNewChannelReq) Length() int

Length returns the length of the MAC command when encoded into a byte buffer

func (m *MACNewChannelReq) Uplink() bool

type MACPayload

type MACPayload struct {
	FHDR        FHDR          // [4.3.1]
	FPort       uint8         // [4.3.2]
	FRMPayload  []byte        // [4.3.3]
	MACCommands MACCommandSet // These are the MAC commands in the payload (if appliccable)
}

Copyright 2018 Telenor Digital AS

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

MACPayload is the payload in the MAC frame [4.3]

func NewMACPayload

func NewMACPayload(message MType) MACPayload

NewMACPayload creates a new MACPayload instance

type MACPingSlotChannelReq

type MACPingSlotChannelReq struct {
	Frequency uint32
	MaxDR     uint8
	MinDR     uint8
	// contains filtered or unexported fields
}

MACPingSlotChannelReq is sent by the server to the end-device to modify the frequency down-link pings are sent at

func (*MACPingSlotChannelReq) ID

func (m *MACPingSlotChannelReq) ID() CID

func (*MACPingSlotChannelReq) Length

func (m *MACPingSlotChannelReq) Length() int

Length returns the length of the MAC command when encoded into a byte buffer

func (m *MACPingSlotChannelReq) Uplink() bool

type MACPingSlotFreqAns

type MACPingSlotFreqAns struct {
	DataRangeOK        bool
	ChannelFrequencyOK bool
	// contains filtered or unexported fields
}

MACPingSlotFreqAns is sent by the end-device to acknowledge a PingSlotChannelReq command

func (*MACPingSlotFreqAns) ID

func (m *MACPingSlotFreqAns) ID() CID

func (*MACPingSlotFreqAns) Length

func (m *MACPingSlotFreqAns) Length() int

Length returns the length of the MAC command when encoded into a byte buffer

func (m *MACPingSlotFreqAns) Uplink() bool

type MACPingSlotInfoAns

type MACPingSlotInfoAns struct {
	// contains filtered or unexported fields
}

MACPingSlotInfoAns is sent by the network server to the end-device to acknowledge a PingSlotInfoReq command

func (*MACPingSlotInfoAns) ID

func (m *MACPingSlotInfoAns) ID() CID

func (*MACPingSlotInfoAns) Length

func (m *MACPingSlotInfoAns) Length() int

Length returns the length of the MAC command when encoded into a byte buffer

func (m *MACPingSlotInfoAns) Uplink() bool

type MACPingSlotInfoReq

type MACPingSlotInfoReq struct {
	Periodicity uint8
	DataRate    uint8
	// contains filtered or unexported fields
}

MACPingSlotInfoReq is sent by the end-device to communicate its data rate and periodicity to the network server [14.1]

func (*MACPingSlotInfoReq) ID

func (m *MACPingSlotInfoReq) ID() CID

func (*MACPingSlotInfoReq) Length

func (m *MACPingSlotInfoReq) Length() int

Length returns the length of the MAC command when encoded into a byte buffer

func (m *MACPingSlotInfoReq) Uplink() bool

type MACRXParamSetupAns

type MACRXParamSetupAns struct {
	RX1DRoffsetACK bool
	RX2DataRateACK bool
	ChannelACK     bool
	// contains filtered or unexported fields
}

MACRXParamSetupAns is sent from the end-device to the network in response to the RXParamSetupReq

func (*MACRXParamSetupAns) ID

func (m *MACRXParamSetupAns) ID() CID

func (*MACRXParamSetupAns) Length

func (m *MACRXParamSetupAns) Length() int

Length returns the length of the MAC command when encoded into a byte buffer

func (m *MACRXParamSetupAns) Uplink() bool

type MACRXParamSetupReq

type MACRXParamSetupReq struct {
	RX1DRoffset uint8
	RX2DataRate uint8
	Frequency   uint32
	// contains filtered or unexported fields
}

MACRXParamSetupReq is sent from the network to the end-device

func (*MACRXParamSetupReq) ID

func (m *MACRXParamSetupReq) ID() CID

func (*MACRXParamSetupReq) Length

func (m *MACRXParamSetupReq) Length() int

Length returns the length of the MAC command when encoded into a byte buffer

func (m *MACRXParamSetupReq) Uplink() bool

type MACRXTimingSetupAns

type MACRXTimingSetupAns struct {
	// contains filtered or unexported fields
}

MACRXTimingSetupAns is sent by the device to acknowledge a RXTimingSetupReq message

func (*MACRXTimingSetupAns) ID

func (m *MACRXTimingSetupAns) ID() CID

func (*MACRXTimingSetupAns) Length

func (m *MACRXTimingSetupAns) Length() int

Length returns the length of the MAC command when encoded into a byte buffer

func (m *MACRXTimingSetupAns) Uplink() bool

type MACRXTimingSetupReq

type MACRXTimingSetupReq struct {
	Del uint8 // [5.7]
	// contains filtered or unexported fields
}

MACRXTimingSetupReq is sent by the network server to an end-device to set up delay between RX and TX.

func (*MACRXTimingSetupReq) ID

func (m *MACRXTimingSetupReq) ID() CID

func (*MACRXTimingSetupReq) Length

func (m *MACRXTimingSetupReq) Length() int

Length returns the length of the MAC command when encoded into a byte buffer

func (m *MACRXTimingSetupReq) Uplink() bool

type MASize

type MASize uint8

MASize is the defined sizes. There are three different sizes: MA-L (large), MA-M (medium) and MA-S (small)

const (
	MALarge  MASize = 24 // Append 40 bits to get EUI-64
	MAMedium MASize = 28 // Append 36 bits to get EUI-64
	MASmall  MASize = 36 // Append 28 bits to get EUI-64
)

EUI size specifiers

type MHDR

type MHDR struct {
	MType        MType // [4.2.1]
	MajorVersion uint8 // [4.2.2]
}

MHDR is the message header [4.2]

type MType

type MType uint8

Copyright 2018 Telenor Digital AS

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

MType is the message type

const (
	// JoinRequest is sent by the end-device when it wants to do OTAA [4.2.1]
	JoinRequest MType = 0
	// JoinAccept is sent by the network when it accepts a JoinRequest from an end-device [4.2.1]
	JoinAccept MType = 1
	// UnconfirmedDataUp is sent by the end device [4.2.1]
	UnconfirmedDataUp MType = 2
	// UnconfirmedDataDown is sent by the network [4.2.1]
	UnconfirmedDataDown MType = 3
	// ConfirmedDataUp is sent by the end-device [4.2.1]
	ConfirmedDataUp MType = 4
	// ConfirmedDataDown is sent by the network [4.2.1]
	ConfirmedDataDown MType = 5
	// RFU is - surprisingly - Reserved for Future Use [4.2.1]
	RFU MType = 6
	// Proprietary is a message type used when implementing proprietary messages [4.2.1]
	Proprietary MType = 7
)

func (MType) String

func (m MType) String() string
func (t MType) Uplink() bool

Uplink returns true if the message type is an uplink. RFU and Proprietary messages are considered uplink messages

type PHYPayload

type PHYPayload struct {
	MHDR               MHDR       // [4.2]
	MACPayload         MACPayload // [4.3]
	JoinRequestPayload JoinRequestPayload
	JoinAcceptPayload  JoinAcceptPayload
	MIC                uint32 // [4.4]
}

PHYPayload is the payload in the PHY frame

func NewPHYPayload

func NewPHYPayload(messageType MType) PHYPayload

NewPHYPayload creates a new PHYPayload instance with the specified direction

func (*PHYPayload) CalculateJoinAcceptMIC

func (p *PHYPayload) CalculateJoinAcceptMIC(appKey AESKey, payload []byte) (uint32, error)

CalculateJoinAcceptMIC calculates the JoinAccept MIC. The payload is expected to be the payload that is sent to the end-device (6.2.5):

MHDR | AppNonce | NetID | DevAddr | DLSettings | RxDelay | CFList

The MHDR field is used to build the buffer used when calculating the MIC.

func (*PHYPayload) CalculateJoinRequestMIC

func (p *PHYPayload) CalculateJoinRequestMIC(appKey AESKey, payload []byte) (uint32, error)

CalculateJoinRequestMIC calculates the JoinRequest MIC. The payload is the same payload as the end-device sends to the network server (6.2.4):

AppEUI | DevEUI | DevNonce

The MHDR field is used to build the buffer used when calculating the MIC.

func (*PHYPayload) CalculateMIC

func (p *PHYPayload) CalculateMIC(nwkSKey AESKey, message []byte) (uint32, error)

CalculateMIC calculates the Message Integrity Code [4.4]

func (*PHYPayload) DecodeJoinAccept

func (p *PHYPayload) DecodeJoinAccept(aesKey AESKey, buffer []byte) error

DecodeJoinAccept decodes the JoinAccept payload from message. The MHDR is assumed to be decoded (via UnmarshalBinary) before this method is called. The MIC will be updated and verified against the calculated MIC. If the MIC is incorrect it will return ErrInvalidMIC

func (*PHYPayload) Decrypt

func (p *PHYPayload) Decrypt(nwkSKey AESKey, appSKey AESKey)

Decrypt decrypts message according to [4.3.3.1]

func (*PHYPayload) EncodeJoinAccept

func (p *PHYPayload) EncodeJoinAccept(appKey AESKey) ([]byte, error)

EncodeJoinAccept encodes a complete JoinAccept message, including MIC and encryption. The appKey parameter is the application key.

func (*PHYPayload) EncodeJoinRequest

func (p *PHYPayload) EncodeJoinRequest(appKey AESKey) ([]byte, error)

EncodeJoinRequest encodes a JoinRequest message

func (*PHYPayload) EncodeMessage

func (p *PHYPayload) EncodeMessage(nwkSKey AESKey, appSKey AESKey) ([]byte, error)

EncodeMessage encrypts and adds MIC for the message.

func (*PHYPayload) MarshalBinary

func (p *PHYPayload) MarshalBinary() ([]byte, error)

MarshalBinary marshals the struct into a byte buffer. Note that some fields might change as a result of this; most notably the FOptsLen field and the Port field. The payload must be encrypted at this point.

func (*PHYPayload) UnmarshalBinary

func (p *PHYPayload) UnmarshalBinary(data []byte) error

UnmarshalBinary extracts MAC Header, MAC Payload and Message Integrity Code (MIC)

Notes

Bugs

  • The payload size should be determined via the frequency plan, not as a constant.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL