lora/lorawan: completed functions needed for Join OTAA process

Signed-off-by: deadprogram <ron@hybridgroup.com>
This commit is contained in:
deadprogram
2023-01-12 13:19:18 +01:00
committed by Ron Evans
parent 999f42dc03
commit 4bc8ecdbdd
3 changed files with 44 additions and 29 deletions
+10 -3
View File
@@ -4,7 +4,6 @@ import (
"crypto/aes"
"encoding/binary"
"encoding/hex"
"errors"
"math"
)
@@ -23,7 +22,7 @@ type Session struct {
// SetDevAddr configures the Session DevAddr
func (s *Session) SetDevAddr(devAddr []uint8) error {
if len(devAddr) != 4 {
return errors.New("invalid length")
return ErrInvalidDevAddrLength
}
copy(s.DevAddr[:], devAddr)
@@ -35,6 +34,14 @@ func (s *Session) GetDevAddr() string {
return hex.EncodeToString(s.DevAddr[:])
}
func (s *Session) GetNwkSKey() string {
return hex.EncodeToString(s.NwkSKey[:])
}
func (s *Session) GetAppSKey() string {
return hex.EncodeToString(s.AppSKey[:])
}
// GenMessage Forge an uplink message
func (s *Session) GenMessage(dir uint8, payload []uint8) ([]uint8, error) {
var buf []uint8
@@ -75,7 +82,7 @@ func (s *Session) genFRMPayload(dir uint8, fCnt uint32, payload []byte, isFOpts
k++
}
if k > math.MaxUint8 {
return nil, errors.New("Payload too big !")
return nil, ErrFrmPayloadTooLarge
}
encrypted := make([]byte, 0, k*16)
cipher, err := aes.NewCipher(s.AppSKey[:])