Skip to content

Commit

Permalink
Merge pull request #7440 from TheThingsNetwork/fix/7334-relay-payload…
Browse files Browse the repository at this point in the history
…-incorrectly-formatted

Fix `RelayNotifyNewEndDeviceReq` fields order
  • Loading branch information
halimi authored Dec 11, 2024
2 parents 16cc65f + 13e23d8 commit 7ebe8d7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ For details about compatibility between different releases, see the **Commitment
### Fixed

- Enforce default page limit on AS and NS List RPCs if a value is not provided in the request.
- Swapped field order in `RelayNotifyNewEndDeviceReq` MAC command.

### Security

Expand Down
18 changes: 9 additions & 9 deletions pkg/encoding/lorawan/mac.go
Original file line number Diff line number Diff line change
Expand Up @@ -1430,6 +1430,12 @@ var DefaultMACCommands = MACCommandSpec{
UplinkLength: 6,
AppendUplink: func(phy band.Band, b []byte, cmd *ttnpb.MACCommand) ([]byte, error) {
pld := cmd.GetRelayNotifyNewEndDeviceReq()
if n := len(pld.DevAddr); n != 4 {
return nil, errExpectedLengthEncodedEqual("DevAddr", 4)(n)
}
devAddr := make([]byte, 4)
copyReverse(devAddr, pld.DevAddr)
b = append(b, devAddr...)
var powerLevel uint16
if pld.Snr < -20 || pld.Snr > 11 {
return nil, errExpectedBetween("SNR", -20, 11)(pld.Snr)
Expand All @@ -1440,12 +1446,6 @@ var DefaultMACCommands = MACCommandSpec{
}
powerLevel |= uint16(-pld.Rssi-15) & 0x7f << 5
b = byteutil.AppendUint16(b, powerLevel, 2)
if n := len(pld.DevAddr); n != 4 {
return nil, errExpectedLengthEncodedEqual("DevAddr", 4)(n)
}
devAddr := make([]byte, 4)
copyReverse(devAddr, pld.DevAddr)
b = append(b, devAddr...)
return b, nil
},
UnmarshalUplink: newMACUnmarshaler(
Expand All @@ -1457,11 +1457,11 @@ var DefaultMACCommands = MACCommandSpec{
cmd.Payload = &ttnpb.MACCommand_RelayNotifyNewEndDeviceReq_{
RelayNotifyNewEndDeviceReq: req,
}
powerLevel := byteutil.ParseUint16(b[0:2])
req.DevAddr = make([]byte, 4)
copyReverse(req.DevAddr, b[0:4])
powerLevel := byteutil.ParseUint16(b[4:6])
req.Snr = int32(powerLevel&0x1f) - 20
req.Rssi = -int32(powerLevel>>5&0x7f) - 15
req.DevAddr = make([]byte, 4)
copyReverse(req.DevAddr, b[2:6])
return nil
},
),
Expand Down
2 changes: 1 addition & 1 deletion pkg/encoding/lorawan/mac_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ func TestLoRaWANEncodingMAC(t *testing.T) {
Snr: 6,
Rssi: -64,
},
[]byte{0x46, 0x3a, 0x06, 0x44, 0x43, 0x42, 0x41},
[]byte{0x46, 0x44, 0x43, 0x42, 0x41, 0x3a, 0x06},
true,
},
} {
Expand Down

0 comments on commit 7ebe8d7

Please sign in to comment.