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

Check ADR bit in LinkADRAns #7447

Merged
merged 6 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
13 changes: 10 additions & 3 deletions pkg/networkserver/mac/link_adr.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,16 +322,23 @@ func HandleLinkADRAns(
}

ev := EvtReceiveLinkADRAccept
rejected := false

// LoRaWAN 1.0.4 spec L534-538:
// An end-device SHOULD accept the channel mask controls present in LinkADRReq, even
// when the ADR bit is not set. The end-device SHALL respond to all LinkADRReq commands
// with a LinkADRAns indicating which command elements were accepted and which were
// rejected. This behavior differs from when the uplink ADR bit is set, in which case the end-
// device accepts or rejects the entire command.
if (!adrEnabled && !pld.ChannelMaskAck) ||
(adrEnabled && !pld.DataRateIndexAck) ||
(adrEnabled && !pld.TxPowerIndexAck) {
if macspec.UseADRBit(macState.LorawanVersion) {
rejected = (!adrEnabled && !pld.ChannelMaskAck) ||
(adrEnabled && !pld.DataRateIndexAck) ||
(adrEnabled && !pld.TxPowerIndexAck)
halimi marked this conversation as resolved.
Show resolved Hide resolved
} else {
rejected = !pld.ChannelMaskAck || !pld.DataRateIndexAck || !pld.TxPowerIndexAck
}

if rejected {
ev = EvtReceiveLinkADRReject

// See "Table 6: LinkADRAns status bits signification" of LoRaWAN 1.1 specification
Expand Down
51 changes: 41 additions & 10 deletions pkg/networkserver/mac/link_adr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -487,19 +487,19 @@ func TestHandleLinkADRAns(t *testing.T) {
AdrEnabled: true,
},
{
Name: "no request/channel mask ack/rejected",
Name: "1.0.2/channel mask on/adr enabled/rejected",
Device: &ttnpb.EndDevice{
FrequencyPlanId: test.EUFrequencyPlanID,
LorawanPhyVersion: ttnpb.PHYVersion_RP001_V1_1_REV_B,
LorawanPhyVersion: ttnpb.PHYVersion_RP001_V1_0_2_REV_B,
MacState: &ttnpb.MACState{
LorawanVersion: ttnpb.MACVersion_MAC_V1_1,
LorawanVersion: ttnpb.MACVersion_MAC_V1_0_2,
},
},
Expected: &ttnpb.EndDevice{
FrequencyPlanId: test.EUFrequencyPlanID,
LorawanPhyVersion: ttnpb.PHYVersion_RP001_V1_1_REV_B,
LorawanPhyVersion: ttnpb.PHYVersion_RP001_V1_0_2_REV_B,
MacState: &ttnpb.MACState{
LorawanVersion: ttnpb.MACVersion_MAC_V1_1,
LorawanVersion: ttnpb.MACVersion_MAC_V1_0_2,
},
},
Payload: &ttnpb.MACCommand_LinkADRAns{
Expand All @@ -518,19 +518,19 @@ func TestHandleLinkADRAns(t *testing.T) {
AdrEnabled: true,
},
{
Name: "no request/channel mask ack/accepted",
Name: "1.0.4/channel mask on/adr disabled/accepted",
Device: &ttnpb.EndDevice{
FrequencyPlanId: test.EUFrequencyPlanID,
LorawanPhyVersion: ttnpb.PHYVersion_RP001_V1_1_REV_B,
LorawanPhyVersion: ttnpb.PHYVersion_RP002_V1_0_4,
MacState: &ttnpb.MACState{
LorawanVersion: ttnpb.MACVersion_MAC_V1_1,
LorawanVersion: ttnpb.MACVersion_MAC_V1_0_4,
},
},
Expected: &ttnpb.EndDevice{
FrequencyPlanId: test.EUFrequencyPlanID,
LorawanPhyVersion: ttnpb.PHYVersion_RP001_V1_1_REV_B,
LorawanPhyVersion: ttnpb.PHYVersion_RP002_V1_0_4,
MacState: &ttnpb.MACState{
LorawanVersion: ttnpb.MACVersion_MAC_V1_1,
LorawanVersion: ttnpb.MACVersion_MAC_V1_0_4,
},
},
Payload: &ttnpb.MACCommand_LinkADRAns{
Expand All @@ -548,6 +548,37 @@ func TestHandleLinkADRAns(t *testing.T) {
Error: ErrRequestNotFound.WithAttributes("cid", ttnpb.MACCommandIdentifier_CID_LINK_ADR),
AdrEnabled: false,
},
{
Name: "1.0.4/channel mask on/adr enabled/rejected",
Device: &ttnpb.EndDevice{
FrequencyPlanId: test.EUFrequencyPlanID,
LorawanPhyVersion: ttnpb.PHYVersion_RP002_V1_0_4,
MacState: &ttnpb.MACState{
LorawanVersion: ttnpb.MACVersion_MAC_V1_0_4,
},
},
Expected: &ttnpb.EndDevice{
FrequencyPlanId: test.EUFrequencyPlanID,
LorawanPhyVersion: ttnpb.PHYVersion_RP002_V1_0_4,
MacState: &ttnpb.MACState{
LorawanVersion: ttnpb.MACVersion_MAC_V1_0_4,
},
},
Payload: &ttnpb.MACCommand_LinkADRAns{
ChannelMaskAck: true,
DataRateIndexAck: false,
TxPowerIndexAck: false,
},
Events: events.Builders{
EvtReceiveLinkADRReject.With(events.WithData(&ttnpb.MACCommand_LinkADRAns{
ChannelMaskAck: true,
DataRateIndexAck: false,
TxPowerIndexAck: false,
})),
},
Error: ErrRequestNotFound.WithAttributes("cid", ttnpb.MACCommandIdentifier_CID_LINK_ADR),
AdrEnabled: true,
},
{
Name: "1 request/all ack",
Device: &ttnpb.EndDevice{
Expand Down
6 changes: 6 additions & 0 deletions pkg/specification/macspec/specification.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,3 +237,9 @@ func EncryptionOptions(v ttnpb.MACVersion, frameType FrameType, fPort uint32, cm
func ValidateUplinkPayloadSize(v ttnpb.MACVersion) bool {
return compareMACVersion(v, ttnpb.MACVersion_MAC_V1_1) >= 0
}

// UseADRBit reports whether v uses the ADR bit in the FCtrl field.
func UseADRBit(v ttnpb.MACVersion) bool {
return compareMACVersion(v, ttnpb.MACVersion_MAC_V1_0_3) >= 0 &&
compareMACVersion(v, ttnpb.MACVersion_MAC_V1_0_4) <= 0
}
halimi marked this conversation as resolved.
Show resolved Hide resolved
Loading