Documentation ¶
Overview ¶
Package protocol contains the low-level LoRaWAN types
Index ¶
- Constants
- Variables
- func MaxNetID(size MASize) uint32
- type AESKey
- type CFList
- type CID
- type DLSettings
- type DevAddr
- type EUI
- type FCtrl
- type FHDR
- type JoinAcceptPayload
- type JoinRequestPayload
- type MA
- type MACBeaconFreqAns
- type MACBeaconFreqReq
- type MACBeaconTimingAns
- type MACBeaconTimingReq
- type MACCommand
- type MACCommandSet
- func (m *MACCommandSet) Add(cmd MACCommand) bool
- func (m *MACCommandSet) Clear()
- func (m *MACCommandSet) Contains(cid CID) bool
- func (m *MACCommandSet) Copy(other MACCommandSet) bool
- func (m *MACCommandSet) EncodedLength() int
- func (m *MACCommandSet) List() []MACCommand
- func (m *MACCommandSet) Message() MType
- func (m *MACCommandSet) Remove(cid CID)
- func (m *MACCommandSet) Size() int
- type MACDevStatusAns
- type MACDevStatusReq
- type MACDutyCycleAns
- type MACDutyCycleReq
- type MACLinkADRAns
- type MACLinkADRReq
- type MACLinkCheckAns
- type MACLinkCheckReq
- type MACNewChannelAns
- type MACNewChannelReq
- type MACPayload
- type MACPingSlotChannelReq
- type MACPingSlotFreqAns
- type MACPingSlotInfoAns
- type MACPingSlotInfoReq
- type MACRXParamSetupAns
- type MACRXParamSetupReq
- type MACRXTimingSetupAns
- type MACRXTimingSetupReq
- type MASize
- type MHDR
- type MType
- type PHYPayload
- func (p *PHYPayload) CalculateJoinAcceptMIC(appKey AESKey, payload []byte) (uint32, error)
- func (p *PHYPayload) CalculateJoinRequestMIC(appKey AESKey, payload []byte) (uint32, error)
- func (p *PHYPayload) CalculateMIC(nwkSKey AESKey, message []byte) (uint32, error)
- func (p *PHYPayload) DecodeJoinAccept(aesKey AESKey, buffer []byte) error
- func (p *PHYPayload) Decrypt(nwkSKey AESKey, appSKey AESKey)
- func (p *PHYPayload) EncodeJoinAccept(appKey AESKey) ([]byte, error)
- func (p *PHYPayload) EncodeJoinRequest(appKey AESKey) ([]byte, error)
- func (p *PHYPayload) EncodeMessage(nwkSKey AESKey, appSKey AESKey) ([]byte, error)
- func (p *PHYPayload) MarshalBinary() ([]byte, error)
- func (p *PHYPayload) UnmarshalBinary(data []byte) error
- Bugs
Constants ¶
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 )
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
const ( BatteryExternalPower uint8 = 0 )
Battery power status constants
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 )
const MaxFOptsLen int = 15
MaxFOptsLen is the maximum length for the FOpts field.
const MinimumMessageSize = 12
MinimumMessageSize is the absolute minimum size for a LoRaWAN message. Messages shorter than this will be rejected outright
Variables ¶
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") )
var ErrInvalidMIC = errors.New("invalid MIC")
ErrInvalidMIC is returned when the JoinAccept MIC is invalid
Functions ¶
Types ¶
type AESKey ¶
type AESKey struct {
Key [16]byte
}
AESKey represents an AES-128 key
func AESKeyFromString ¶
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]
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 ¶
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 ¶
DevAddr is a device address [6.1.1]
func DevAddrFromString ¶
DevAddrFromString converts a hex representation to a DevAddr value
func DevAddrFromUint32 ¶
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.
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 ¶
EUIFromString converts a string on the format "xx-xx-xx..." in hex to an internal representation
func EUIFromUint64 ¶
EUIFromUint64 converts an uint64 value to an EUI.
func NewApplicationEUI ¶
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 ¶
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 ¶
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.
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 ¶
JoinRequestPayload is the payload sent by the device in a JoinRequest message [6.2.4]. The message is not encrypted.
type MA ¶
MA defines a MA block
func NewMA ¶
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)
type MACBeaconFreqAns ¶
type MACBeaconFreqAns struct {
// contains filtered or unexported fields
}
MACBeaconFreqAns is sent by the end-device to acknowledge a BeaconFreqReq command
func (*MACBeaconFreqAns) Length ¶
func (m *MACBeaconFreqAns) Length() int
Length returns the length of the MAC command when encoded into a byte buffer
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) Length ¶
func (m *MACBeaconFreqReq) Length() int
Length returns the length of the MAC command when encoded into a byte buffer
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) Length ¶
func (m *MACBeaconTimingAns) Length() int
Length returns the length of the MAC command when encoded into a byte buffer
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) Length ¶
func (m *MACBeaconTimingReq) Length() int
Length returns the length of the MAC command when encoded into a byte buffer
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) Length ¶
func (m *MACDevStatusAns) Length() int
Length returns the length of the MAC command when encoded into a byte buffer
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) Length ¶
func (m *MACDevStatusReq) Length() int
Length returns the length of the MAC command when encoded into a byte buffer
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) Length ¶
func (m *MACDutyCycleAns) Length() int
Length returns the length of the MAC command when encoded into a byte buffer
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) Length ¶
func (m *MACDutyCycleReq) Length() int
Length returns the length of the MAC command when encoded into a byte buffer
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) Length ¶
func (m *MACLinkADRAns) Length() int
Length returns the length of the MAC command when encoded into a byte buffer
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) Length ¶
func (m *MACLinkADRReq) Length() int
Length returns the length of the MAC command when encoded into a byte buffer
type MACLinkCheckAns ¶
MACLinkCheckAns is sent from the network server to the end-device
func (*MACLinkCheckAns) Length ¶
func (m *MACLinkCheckAns) Length() int
Length returns the length of the MAC command when encoded into a byte buffer
type MACLinkCheckReq ¶
type MACLinkCheckReq struct {
// contains filtered or unexported fields
}
MACLinkCheckReq is sent from the end-device to the network server
func (*MACLinkCheckReq) Length ¶
func (m *MACLinkCheckReq) Length() int
Length returns the length of the MAC command when encoded into a byte buffer
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) Length ¶
func (m *MACNewChannelAns) Length() int
Length returns the length of the MAC command when encoded into a byte buffer
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) Length ¶
func (m *MACNewChannelReq) Length() int
Length returns the length of the MAC command when encoded into a byte buffer
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) Length ¶
func (m *MACPingSlotChannelReq) Length() int
Length returns the length of the MAC command when encoded into a byte buffer
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) Length ¶
func (m *MACPingSlotFreqAns) Length() int
Length returns the length of the MAC command when encoded into a byte buffer
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) Length ¶
func (m *MACPingSlotInfoAns) Length() int
Length returns the length of the MAC command when encoded into a byte buffer
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) Length ¶
func (m *MACPingSlotInfoReq) Length() int
Length returns the length of the MAC command when encoded into a byte buffer
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) Length ¶
func (m *MACRXParamSetupAns) Length() int
Length returns the length of the MAC command when encoded into a byte buffer
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) Length ¶
func (m *MACRXParamSetupReq) Length() int
Length returns the length of the MAC command when encoded into a byte buffer
type MACRXTimingSetupAns ¶
type MACRXTimingSetupAns struct {
// contains filtered or unexported fields
}
MACRXTimingSetupAns is sent by the device to acknowledge a RXTimingSetupReq message
func (*MACRXTimingSetupAns) Length ¶
func (m *MACRXTimingSetupAns) Length() int
Length returns the length of the MAC command when encoded into a byte buffer
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) Length ¶
func (m *MACRXTimingSetupReq) Length() int
Length returns the length of the MAC command when encoded into a byte buffer
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)
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 )
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.