RelayForwardUplinkReq uplinkMetadata RSSI field not correctly re-marshalled
Summary
Math rules strike again - there appears to be a minor re-encoding mistake on the RSSI field in the uplinkMetadata of RelayForwardUplinkReq that results in the forwarded RSSI to be 30 off (or, more accurately, 2*15).
Steps to Reproduce
- Send a forwarded uplink from a Relay-enabled device, observing the RSSI of the relay from the end-device's uplink.
- Observe the output on the end-device's console (or the relay's console in the
rx_metadatafield).
Current Result
Relay:
20:43:37.330 > DevAddr: 260BAF11, RSSI: -22.0, SNR: 12.8
Console:
"rx_metadata": [
{
...
"rssi": -52,
"channel_rssi": -52,
"snr": 11,
The RSSI value on the end-device console ends up 30 dBm lower than what the relay sends to the network server. This is due to a minor brackets problem. The unmarshalling is done right...
https://github.com/TheThingsNetwork/lorawan-stack/blob/569c2cceb5552ebe5392af4e7d47d2b95685a0f6/pkg/encoding/lorawan/relay.go#L80
... but the re-marshalling is applied incorrectly:
https://github.com/TheThingsNetwork/lorawan-stack/blob/569c2cceb5552ebe5392af4e7d47d2b95685a0f6/pkg/encoding/lorawan/relay.go#L53
Notice the very subtle difference in brackets - the +15 should be applied outside the brackets instead of inside.
Expected Result
The RSSI for the end-device should be set back to original.
Relevant Logs
No response
URL
No response
Deployment
The Things Stack Community Edition
The Things Stack Version
3.32.1
Client Name and Version
No response
Other Information
No response
Proposed Fix
Change ...
https://github.com/TheThingsNetwork/lorawan-stack/blob/569c2cceb5552ebe5392af4e7d47d2b95685a0f6/pkg/encoding/lorawan/relay.go#L53
... to ...
uplinkMetadata |= uint32((-req.Rssi+15)&0x7f) << 9
(I guess?)
Contributing
- [X] I can help by doing more research.
- [ ] I can help by implementing a fix after the proposal above is approved.
- [X] I can help by testing the fix before it's released.
Validation
- [ ] The fix is tested in a staging environment.
- [ ] The fix is documented in The Things Stack Documentation
Code of Conduct
- [X] I agree to follow TTN's Community Code of Conduct.