mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-08-04 06:57:48 +00:00
lora/lorawan: set functions for keys
Signed-off-by: deadprogram <ron@hybridgroup.com>
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user