lora/lorawan: set functions for keys

Signed-off-by: deadprogram <ron@hybridgroup.com>
This commit is contained in:
deadprogram
2023-01-12 14:52:18 +01:00
parent c149f3d458
commit 1ba616c6a6
3 changed files with 39 additions and 1 deletions
+3
View File
@@ -15,6 +15,9 @@ var (
ErrInvalidDevAddrLength = errors.New("invalid DevAddr length")
ErrInvalidMic = errors.New("invalid Mic")
ErrFrmPayloadTooLarge = errors.New("FRM payload too large")
ErrInvalidNetIDLength = errors.New("invalid NetID length")
ErrInvalidNwkSKeyLength = errors.New("invalid NwkSKey length")
ErrInvalidAppSKeyLength = errors.New("invalid AppSKey length")
)
const LORA_RXTX_TIMEOUT = 1000
+10
View File
@@ -83,6 +83,16 @@ func (o *Otaa) GetNetID() string {
return hex.EncodeToString(o.NetID[:])
}
func (o *Otaa) SetNetID(netID []uint8) error {
if len(netID) != 3 {
return ErrInvalidNetIDLength
}
copy(o.NetID[:], netID)
return nil
}
// GenerateJoinRequest Generates a LoraWAN Join request
func (o *Otaa) GenerateJoinRequest() ([]uint8, error) {
// TODO: Add checks
+26 -1
View File
@@ -30,19 +30,44 @@ func (s *Session) SetDevAddr(devAddr []uint8) error {
return nil
}
// GetDevAddr returns the Session DevAddr
func (s *Session) GetDevAddr() string {
return hex.EncodeToString(s.DevAddr[:])
}
// SetNwkSKey configures the Session NwkSKey
func (s *Session) SetNwkSKey(nwkSKey []uint8) error {
if len(nwkSKey) != 16 {
return ErrInvalidNwkSKeyLength
}
copy(s.NwkSKey[:], nwkSKey)
return nil
}
// GetNwkSKey returns the Session NwkSKey
func (s *Session) GetNwkSKey() string {
return hex.EncodeToString(s.NwkSKey[:])
}
// SetAppSKey configures the Session AppSKey
func (s *Session) SetAppSKey(appSKey []uint8) error {
if len(appSKey) != 16 {
return ErrInvalidAppSKeyLength
}
copy(s.AppSKey[:], appSKey)
return nil
}
// GetAppSKey returns the Session AppSKey
func (s *Session) GetAppSKey() string {
return hex.EncodeToString(s.AppSKey[:])
}
// GenMessage Forge an uplink message
// GenMessage generates an uplink message.
func (s *Session) GenMessage(dir uint8, payload []uint8) ([]uint8, error) {
var buf []uint8
buf = append(buf, 0b01000000) // FHDR Unconfirmed up