Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix RelayNotifyNewEndDeviceReq fields order #7440

Merged
merged 2 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading