Closed StevenCellist closed 1 week ago
This is not a bug. The endianness of the value printed on your relay log is in reverse.
[Pay] 36 00 c7 01 0b 26
The Things Stack Sandbox does not issue a Device Address of c7 01 0b 26
but 26 0b 01 c7
is valid device address from 0x000013 NET ID.
The Power level of 36 00
is also in reverse. If you look at the spec, the the first 4 bits should be RFU (zeroes) but for 36 00
, that would be 0011b
.
@KrishnaIyer I object, your honour. I will supply more information this time around.
The endianness of my device is right, and the endianness of the network is similarly little-endian. Observe the contents of a (random) downlink, dumped in straight byte order as received by the radio:
14:38:35.772 > 00000000: 60 24 21 0b 26 90 01 00 e2 d8 c9 df 0f 0e 86 33 `$!.&..........3
14:38:35.780 > 00000010: e6 50 03 65 14 c8 60 23 f8 21 01 fc 24 66 ca ff .P.e..`#.!..$f..
14:38:35.787 > 00000020: 73 b2 0e f8 9a 16 f2 5e 21 21 be c6 54 81 s......^!!..T.
Byte 0 is the MHDR, byte 1 through 4 is the DevAddr: 24 21 0b 26
which indeed is a valid DevAddr for NetID 0013, given the little-endianness.
With that out of the way, here is a NotifyNewEndDevice, as seen through the Relay:
14:48:27.857 > DevAddr: 260BF444, RSSI: -18.0, SNR: 10.5
14:48:27.861 > 00000000: 3e 04 44 f4 0b 26 >.D..&
14:48:27.869 > Uplink MAC payload:
14:48:27.871 > 00000000: 46 3e 04 44 f4 0b 26 F>.D..&
14:48:27.938 > Uplink (FCntUp = 3) decoded:
14:48:27.949 > 00000000: 40 24 21 0b 26 07 03 00 46 3e 04 44 f4 0b 26 01 @$!.&...F>.D..&.
14:48:27.956 > 00000010: 20 20 20 20
Base64 payload in the console:
QCQhCyYHAwBGPgRE9AsmAX0ukxU=
NwkSEncKey from the console:
C609BFBE338429DF7AE2AD71E5CA6516
( FHDR = DevAddr[4] | FCtrl[1] | FCnt[2] | FOpts[0..15] )
DevAddr = 260B2124 (Big Endian)
FCtrl = 07
FCnt = 0003 (Big Endian)
FOpts = 463E0444F40B26
Now the corresponding downlink to UpdateUplinkList (in base64):
YCQhCyaAAgAAvTS6taYrpldtxpMCEUliKeBI46hebsllQQ7PNEvS8g==
Which, decoded, reports the following:
( MACPayload = FHDR | FPort | FRMPayload )
FHDR = 24210B26800200
FPort = 00
FRMPayload = BD34BAB5A62BA6576DC6930211496229E048E3A85E6EC965410ECF (from packet, encrypted)
= 43003C44F40B2600000000E8E8C7BDFA679958D0F4F29CB9CBE203 (decrypted)
Notice the same endianness on the DevAddr in bytes 2-5. This matches exactly with the 2 single bytes and then the DevAddr.
Given that the byte ordering is clear from the UpdateUplinkList, here is again the NotifyNewEndDevice:
We should see the four bytes for DevAddr first (in little-endianness), and only then the PowerLevel. And as a result, the PowerLevel encoding is not setting the RFU bits.
I am curious to hear from you @KrishnaIyer. If there are any questions, please let me know, happy to supply more information.
Summary
The payload of the Relay MAC command
NotifyNewEndDeviceReq
is not correctly formatted/parsed on TTS.Steps to Reproduce
ttn-lw-cli relays create <app-id> <device-id> --mode.serving
ttn-lw-cli relays create <app-id> <device-id> --mode.served.mode.always --mode.served.serving-device-id <device-id>
ttn-lw-cli relays uplink-forwarding-rules create <app-id> <device-id> 0 --device-id <device-id>
NotifyNewEndDeviceReq
is triggered.Current Result
NotifyNewEndDeviceReq
payload formatted as per TS011 paragraph 10.7First four bytes DevAddr, last two bytes PowerLevel
Served device DevAddr copied from Console:
260B470F
Relay log:
Relay console log:
Notice that the
dev_addr
field ofRelayNotifyNewEndDeviceReq
is not correct (as well as snr/rssi but those are not so easy to see).NotifyNewEndDeviceReq
payload swapped formattingFirst two bytes PowerLevel, last four bytes DevAddr
Served device DevAddr copied from Console:
260B01C7
Relay log:
Relay console log:
Notice that this swapped formatting yields the expected result on the console.
Expected Result
The formatting as per TS011 paragraph 10.7 should be the correct formatting (and therefore the decoding on TTS should be corrected).
Relevant Logs
No response
URL
No response
Deployment
The Things Stack Community Edition
The Things Stack Version
3.32.1
Client Name and Version
Other Information
No response
Proposed Fix
Swap the payload fields of
NotifyNewEndDeviceReq
.Contributing
Validation
Code of Conduct