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 2 commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ For details about compatibility between different releases, see the **Commitment

- Enforce default page limit on AS and NS List RPCs if a value is not provided in the request.
- Swapped field order in `RelayNotifyNewEndDeviceReq` MAC command.
- `LinkADRAns` MAC command verification when the end device does not support ADR.

### Security

Expand Down
10 changes: 9 additions & 1 deletion pkg/networkserver/grpc_gsns.go
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,15 @@ macLoop:
break
}
cmds = cmds[dupCount:]
evs, err = mac.HandleLinkADRAns(ctx, dev, pld, uint(dupCount), cmacFMatchResult.FullFCnt, fps)
evs, err = mac.HandleLinkADRAns(
ctx,
dev,
pld,
uint(dupCount), // nolint: gosec
cmacFMatchResult.FullFCnt,
fps,
up.GetPayload().GetMacPayload().GetFHdr().GetFCtrl().GetAdr(),
)
case ttnpb.MACCommandIdentifier_CID_DUTY_CYCLE:
evs, err = mac.HandleDutyCycleAns(ctx, dev)
case ttnpb.MACCommandIdentifier_CID_RX_PARAM_SETUP:
Expand Down
6 changes: 5 additions & 1 deletion pkg/networkserver/mac/link_adr.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ func HandleLinkADRAns(
dupCount uint,
fCntUp uint32,
fps *frequencyplans.Store,
adrEnabled bool,
) (events.Builders, error) {
if pld == nil {
return nil, ErrNoPayload.New()
Expand All @@ -321,7 +322,10 @@ func HandleLinkADRAns(
}

ev := EvtReceiveLinkADRAccept
if !pld.ChannelMaskAck || !pld.DataRateIndexAck || !pld.TxPowerIndexAck {

if (!adrEnabled && !pld.ChannelMaskAck) ||
(adrEnabled && !pld.DataRateIndexAck) ||
(adrEnabled && !pld.TxPowerIndexAck) {
halimi marked this conversation as resolved.
Show resolved Hide resolved
ev = EvtReceiveLinkADRReject

// See "Table 6: LinkADRAns status bits signification" of LoRaWAN 1.1 specification
Expand Down
77 changes: 74 additions & 3 deletions pkg/networkserver/mac/link_adr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,7 @@ func TestHandleLinkADRAns(t *testing.T) {
DupCount uint
Events events.Builders
Error error
AdrEnabled bool
}{
{
Name: "nil payload",
Expand All @@ -451,7 +452,8 @@ func TestHandleLinkADRAns(t *testing.T) {
LorawanVersion: ttnpb.MACVersion_MAC_V1_1,
},
},
Error: ErrNoPayload,
Error: ErrNoPayload,
AdrEnabled: true,
},
{
Name: "no request",
Expand Down Expand Up @@ -481,7 +483,70 @@ func TestHandleLinkADRAns(t *testing.T) {
TxPowerIndexAck: true,
})),
},
Error: ErrRequestNotFound.WithAttributes("cid", ttnpb.MACCommandIdentifier_CID_LINK_ADR),
Error: ErrRequestNotFound.WithAttributes("cid", ttnpb.MACCommandIdentifier_CID_LINK_ADR),
AdrEnabled: true,
},
{
Name: "no request/channel mask ack/rejected",
Device: &ttnpb.EndDevice{
FrequencyPlanId: test.EUFrequencyPlanID,
LorawanPhyVersion: ttnpb.PHYVersion_RP001_V1_1_REV_B,
MacState: &ttnpb.MACState{
LorawanVersion: ttnpb.MACVersion_MAC_V1_1,
},
},
Expected: &ttnpb.EndDevice{
FrequencyPlanId: test.EUFrequencyPlanID,
LorawanPhyVersion: ttnpb.PHYVersion_RP001_V1_1_REV_B,
MacState: &ttnpb.MACState{
LorawanVersion: ttnpb.MACVersion_MAC_V1_1,
},
},
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: "no request/channel mask ack/accepted",
Device: &ttnpb.EndDevice{
FrequencyPlanId: test.EUFrequencyPlanID,
LorawanPhyVersion: ttnpb.PHYVersion_RP001_V1_1_REV_B,
MacState: &ttnpb.MACState{
LorawanVersion: ttnpb.MACVersion_MAC_V1_1,
},
},
Expected: &ttnpb.EndDevice{
FrequencyPlanId: test.EUFrequencyPlanID,
LorawanPhyVersion: ttnpb.PHYVersion_RP001_V1_1_REV_B,
MacState: &ttnpb.MACState{
LorawanVersion: ttnpb.MACVersion_MAC_V1_1,
},
},
Payload: &ttnpb.MACCommand_LinkADRAns{
ChannelMaskAck: true,
DataRateIndexAck: false,
TxPowerIndexAck: false,
},
Events: events.Builders{
EvtReceiveLinkADRAccept.With(events.WithData(&ttnpb.MACCommand_LinkADRAns{
ChannelMaskAck: true,
DataRateIndexAck: false,
TxPowerIndexAck: false,
})),
},
Error: ErrRequestNotFound.WithAttributes("cid", ttnpb.MACCommandIdentifier_CID_LINK_ADR),
AdrEnabled: false,
},
{
Name: "1 request/all ack",
Expand Down Expand Up @@ -547,6 +612,7 @@ func TestHandleLinkADRAns(t *testing.T) {
TxPowerIndexAck: true,
})),
},
AdrEnabled: true,
},
{
Name: "1.1/2 requests/all ack",
Expand Down Expand Up @@ -636,6 +702,7 @@ func TestHandleLinkADRAns(t *testing.T) {
TxPowerIndexAck: true,
})),
},
AdrEnabled: true,
},
{
Name: "1.0.2/2 requests/all ack",
Expand Down Expand Up @@ -726,6 +793,7 @@ func TestHandleLinkADRAns(t *testing.T) {
TxPowerIndexAck: true,
})),
},
AdrEnabled: true,
},
{
Name: "1.0/2 requests/all ack",
Expand Down Expand Up @@ -825,6 +893,7 @@ func TestHandleLinkADRAns(t *testing.T) {
TxPowerIndexAck: true,
})),
},
AdrEnabled: true,
},
{
Name: "1.0.2/2 requests/US915 FSB2",
Expand Down Expand Up @@ -888,6 +957,7 @@ func TestHandleLinkADRAns(t *testing.T) {
TxPowerIndexAck: true,
})),
},
AdrEnabled: true,
},
} {
tc := tc
Expand All @@ -897,7 +967,8 @@ func TestHandleLinkADRAns(t *testing.T) {
Func: func(ctx context.Context, t *testing.T, a *assertions.Assertion) {
dev := ttnpb.Clone(tc.Device)

evs, err := HandleLinkADRAns(ctx, dev, tc.Payload, tc.DupCount, fCntUp, frequencyplans.NewStore(test.FrequencyPlansFetcher))
fps := frequencyplans.NewStore(test.FrequencyPlansFetcher)
evs, err := HandleLinkADRAns(ctx, dev, tc.Payload, tc.DupCount, fCntUp, fps, tc.AdrEnabled)
if tc.Error != nil && !a.So(err, should.EqualErrorOrDefinition, tc.Error) ||
tc.Error == nil && !a.So(err, should.BeNil) {
t.FailNow()
Expand Down
Loading