Skip to content

Commit e23b2f6

Browse files
committed
Make sure uint32 token is truncated to uint16.
ChirpStack v3 only uses the uint16 range, but this makes it possible to use the full uint32 range, while staying compatible with the Semtech UDP Packet Forwarder protocol. We truncate the uint32 token to uint16 and use this as the cache-key to store the downlink frame. On ack, we retrieve the downlink frame using the uint16 token and are able to recover the full uint32 token.
1 parent dc2ef20 commit e23b2f6

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

internal/backend/semtechudp/backend.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,10 +181,13 @@ func (b *Backend) sendDownlinkFrame(frame gw.DownlinkFrame, i int, txAckItems []
181181
return errors.New("invalid downlink frame item index")
182182
}
183183

184+
// Make sure the token is truncated to an uint16.
185+
token := uint16(frame.Token)
186+
184187
// create cache items
185-
b.cache.Set(fmt.Sprintf("%d:ack", frame.Token), txAckItems, cache.DefaultExpiration)
186-
b.cache.Set(fmt.Sprintf("%d:frame", frame.Token), frame, cache.DefaultExpiration)
187-
b.cache.Set(fmt.Sprintf("%d:index", frame.Token), i, cache.DefaultExpiration)
188+
b.cache.Set(fmt.Sprintf("%d:ack", token), txAckItems, cache.DefaultExpiration)
189+
b.cache.Set(fmt.Sprintf("%d:frame", token), frame, cache.DefaultExpiration)
190+
b.cache.Set(fmt.Sprintf("%d:index", token), i, cache.DefaultExpiration)
188191

189192
var gatewayID lorawan.EUI64
190193
copy(gatewayID[:], frame.GetGatewayId())
@@ -416,7 +419,7 @@ func (b *Backend) handleTXACK(up udpPacket) error {
416419
if b.downlinkTxAckFunc != nil {
417420
b.downlinkTxAckFunc(gw.DownlinkTXAck{
418421
GatewayId: p.GatewayMAC[:],
419-
Token: uint32(p.RandomToken),
422+
Token: frame.Token,
420423
DownlinkId: frame.DownlinkId,
421424
Items: txAckItems,
422425
})

0 commit comments

Comments
 (0)