brocaar / chirpstack-network-server

ChirpStack Network Server is an open-source LoRaWAN network-server.
https://www.chirpstack.io
MIT License
1.5k stars 546 forks source link

Confuse of ClassB Parameters set #549

Open redwolf2019 opened 3 years ago

redwolf2019 commented 3 years ago

File location:chirpstack-network-server/internal/data/data.go

Source code:

func setPingSlotParameters(ctx *dataContext) error {
    if !ctx.DeviceProfile.SupportsClassB {
        return nil
    }

    if classBPingSlotDR != ctx.DeviceSession.PingSlotDR || classBPingSlotFrequency != ctx.DeviceSession.PingSlotFrequency {
        block := maccommand.RequestPingSlotChannel(ctx.DeviceSession.DevEUI, classBPingSlotDR, classBPingSlotFrequency)
        ctx.MACCommands = append(ctx.MACCommands, block)
    }

    return nil
}

Bug:

if classBPingSlotDR != ctx.DeviceSession.PingSlotDR || classBPingSlotFrequency != ctx.DeviceSession.PingSlotFrequency {
        block := maccommand.RequestPingSlotChannel(ctx.DeviceSession.DevEUI, classBPingSlotDR, classBPingSlotFrequency)
        ctx.MACCommands = append(ctx.MACCommands, block)
}

According to my opinion,PingSlotDR/classBPingSlotFrequency always loading from chirpstack-network-server.toml, not loading from ctx.DeviceSession.

My Patch is:

        var classBPingSlotDRReal int
    if classBPingSlotDR != ctx.DeviceSession.PingSlotDR {
        classBPingSlotDRReal = ctx.DeviceSession.PingSlotDR
    }else {
        classBPingSlotDRReal = classBPingSlotDR
    }

    var classBPingSlotFrequencyReal uint32
    if classBPingSlotFrequency != ctx.DeviceSession.PingSlotFrequency {
        classBPingSlotFrequencyReal = ctx.DeviceSession.PingSlotFrequency
    }else {
        classBPingSlotFrequencyReal = classBPingSlotFrequency
    }

    block := maccommand.RequestPingSlotChannel(ctx.DeviceSession.DevEUI, classBPingSlotDRReal, classBPingSlotFrequencyReal)
    ctx.MACCommands = append(ctx.MACCommands, block)

Is my idea correct? Looking forward to your reply:)