Skip to content

Commit

Permalink
Merge pull request TheThingsNetwork#6637 from TheThingsNetwork/fix/re…
Browse files Browse the repository at this point in the history
…key-unknown

Fix unexpected RekeyInd handling
  • Loading branch information
adriansmares authored Oct 18, 2023
2 parents d9f3ec7 + ddc3323 commit dceeff8
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 13 deletions.
2 changes: 1 addition & 1 deletion pkg/networkserver/grpc_gsns.go
Original file line number Diff line number Diff line change
Expand Up @@ -1396,7 +1396,7 @@ func (ns *NetworkServer) handleJoinRequest(ctx context.Context, up *ttnpb.Uplink
return nil
}

var errRejoinRequest = errors.DefineUnimplemented("rejoin_request", "rejoin-request handling is not implemented")
var errRejoinRequest = errors.DefineUnavailable("rejoin_request", "rejoin-request handling is not implemented")

func (ns *NetworkServer) handleRejoinRequest(ctx context.Context, up *ttnpb.UplinkMessage) error {
defer trace.StartRegion(ctx, "handle rejoin request").End()
Expand Down
6 changes: 4 additions & 2 deletions pkg/networkserver/mac/rekey.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@ func HandleRekeyInd(ctx context.Context, dev *ttnpb.EndDevice, pld *ttnpb.MACCom
evs := events.Builders{
EvtReceiveRekeyIndication.With(events.WithData(pld)),
}
if !dev.SupportsJoin {
if !dev.SupportsJoin || !macspec.UseRekeyInd(dev.LorawanVersion) {
return evs, nil
}
if dev.PendingSession != nil && dev.MacState.PendingJoinRequest != nil && types.MustDevAddr(dev.PendingSession.DevAddr).OrZero().Equal(devAddr) {
if dev.PendingSession != nil &&
dev.MacState.PendingJoinRequest != nil &&
types.MustDevAddr(dev.PendingSession.DevAddr).OrZero().Equal(devAddr) {
dev.Ids.DevAddr = dev.PendingSession.DevAddr
dev.Session = dev.PendingSession
}
Expand Down
29 changes: 19 additions & 10 deletions pkg/networkserver/mac/rekey_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
)

func TestHandleRekeyInd(t *testing.T) {
t.Parallel()
for _, tc := range []struct {
Name string
Device, Expected *ttnpb.EndDevice
Expand All @@ -48,8 +49,9 @@ func TestHandleRekeyInd(t *testing.T) {
{
Name: "empty queue/original",
Device: &ttnpb.EndDevice{
SupportsJoin: true,
Ids: &ttnpb.EndDeviceIdentifiers{},
LorawanVersion: ttnpb.MACVersion_MAC_V1_1,
SupportsJoin: true,
Ids: &ttnpb.EndDeviceIdentifiers{},
PendingSession: &ttnpb.Session{
DevAddr: test.DefaultDevAddr.Bytes(),
LastFCntUp: 42,
Expand All @@ -62,7 +64,8 @@ func TestHandleRekeyInd(t *testing.T) {
},
},
Expected: &ttnpb.EndDevice{
SupportsJoin: true,
LorawanVersion: ttnpb.MACVersion_MAC_V1_1,
SupportsJoin: true,
Ids: &ttnpb.EndDeviceIdentifiers{
DevAddr: test.DefaultDevAddr.Bytes(),
},
Expand Down Expand Up @@ -95,7 +98,8 @@ func TestHandleRekeyInd(t *testing.T) {
{
Name: "empty queue/retransmission/non-matching pending session",
Device: &ttnpb.EndDevice{
SupportsJoin: true,
LorawanVersion: ttnpb.MACVersion_MAC_V1_1,
SupportsJoin: true,
Ids: &ttnpb.EndDeviceIdentifiers{
DevAddr: test.DefaultDevAddr.Bytes(),
},
Expand All @@ -116,7 +120,8 @@ func TestHandleRekeyInd(t *testing.T) {
},
},
Expected: &ttnpb.EndDevice{
SupportsJoin: true,
LorawanVersion: ttnpb.MACVersion_MAC_V1_1,
SupportsJoin: true,
Ids: &ttnpb.EndDeviceIdentifiers{
DevAddr: test.DefaultDevAddr.Bytes(),
},
Expand Down Expand Up @@ -149,7 +154,8 @@ func TestHandleRekeyInd(t *testing.T) {
{
Name: "empty queue/retransmission/no pending session",
Device: &ttnpb.EndDevice{
SupportsJoin: true,
LorawanVersion: ttnpb.MACVersion_MAC_V1_1,
SupportsJoin: true,
Ids: &ttnpb.EndDeviceIdentifiers{
DevAddr: test.DefaultDevAddr.Bytes(),
},
Expand All @@ -161,7 +167,8 @@ func TestHandleRekeyInd(t *testing.T) {
MacState: &ttnpb.MACState{},
},
Expected: &ttnpb.EndDevice{
SupportsJoin: true,
LorawanVersion: ttnpb.MACVersion_MAC_V1_1,
SupportsJoin: true,
Ids: &ttnpb.EndDeviceIdentifiers{
DevAddr: test.DefaultDevAddr.Bytes(),
},
Expand Down Expand Up @@ -194,8 +201,9 @@ func TestHandleRekeyInd(t *testing.T) {
{
Name: "non-empty queue",
Device: &ttnpb.EndDevice{
SupportsJoin: true,
Ids: &ttnpb.EndDeviceIdentifiers{},
LorawanVersion: ttnpb.MACVersion_MAC_V1_1,
SupportsJoin: true,
Ids: &ttnpb.EndDeviceIdentifiers{},
PendingSession: &ttnpb.Session{
DevAddr: test.DefaultDevAddr.Bytes(),
LastFCntUp: 42,
Expand All @@ -212,7 +220,8 @@ func TestHandleRekeyInd(t *testing.T) {
},
},
Expected: &ttnpb.EndDevice{
SupportsJoin: true,
LorawanVersion: ttnpb.MACVersion_MAC_V1_1,
SupportsJoin: true,
Ids: &ttnpb.EndDeviceIdentifiers{
DevAddr: test.DefaultDevAddr.Bytes(),
},
Expand Down

0 comments on commit dceeff8

Please sign in to comment.