lora/lorawan: implement minimal Join() function, and supporting functions

Signed-off-by: deadprogram <ron@hybridgroup.com>
This commit is contained in:
deadprogram
2023-01-08 19:42:19 +01:00
committed by Ron Evans
parent 36dfdf568e
commit a62fc01d81
4 changed files with 160 additions and 44 deletions
+16 -1
View File
@@ -3,6 +3,7 @@ package lorawan
import (
"crypto/aes"
"encoding/binary"
"encoding/hex"
"errors"
"math"
)
@@ -19,6 +20,21 @@ type Session struct {
DLSettings uint8
}
// SetDevAddr configures the Session DevAddr
func (s *Session) SetDevAddr(devAddr []uint8) error {
if len(devAddr) != 4 {
return errors.New("invalid length")
}
copy(s.DevAddr[:], devAddr)
return nil
}
func (s *Session) GetDevAddr() string {
return hex.EncodeToString(s.DevAddr[:])
}
// GenMessage Forge an uplink message
func (s *Session) GenMessage(dir uint8, payload []uint8) ([]uint8, error) {
var buf []uint8
@@ -87,4 +103,3 @@ func (s *Session) genFRMPayload(dir uint8, fCnt uint32, payload []byte, isFOpts
}
return encrypted[:len(payload)], nil
}