Skip to content

Commit

Permalink
ns: Store the RekeyInd cipher id to MAC state
Browse files Browse the repository at this point in the history
  • Loading branch information
halimi committed Aug 28, 2024
1 parent ad48bd6 commit 4cf915c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
3 changes: 2 additions & 1 deletion pkg/networkserver/mac/rekey.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,11 @@ func HandleRekeyInd(ctx context.Context, dev *ttnpb.EndDevice, pld *ttnpb.MACCom

conf := &ttnpb.MACCommand_RekeyConf{}
dev.MacState.LorawanVersion, conf.MinorVersion = macspec.NegotiatedVersion(dev.LorawanVersion, pld.MinorVersion)
dev.MacState.CipherId = macspec.NegotiatedCipherSuite(pld.Cipher)
dev.MacState.PendingJoinRequest = nil
dev.PendingMacState = nil
dev.PendingSession = nil
conf.Cipher = pld.Cipher
conf.Cipher = ttnpb.CipherEnum(dev.MacState.CipherId)

dev.MacState.QueuedResponses = append(dev.MacState.QueuedResponses, conf.MACCommand())
return append(evs,
Expand Down
8 changes: 4 additions & 4 deletions pkg/networkserver/mac/rekey_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,23 +294,23 @@ func TestHandleRekeyInd(t *testing.T) {
{},
(&ttnpb.MACCommand_RekeyConf{
MinorVersion: 2,
Cipher: 3,
Cipher: 0,
}).MACCommand(),
},
},
},
Payload: &ttnpb.MACCommand_RekeyInd{
MinorVersion: 2,
Cipher: 3,
Cipher: 0,
},
Events: events.Builders{
EvtReceiveRekeyIndication.With(events.WithData(&ttnpb.MACCommand_RekeyInd{
MinorVersion: 2,
Cipher: 3,
Cipher: 0,
})),
EvtEnqueueRekeyConfirmation.With(events.WithData(&ttnpb.MACCommand_RekeyConf{
MinorVersion: 2,
Cipher: 3,
Cipher: 0,
})),
},
},
Expand Down
14 changes: 14 additions & 0 deletions pkg/specification/macspec/specification.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,20 @@ func NegotiatedVersion(v ttnpb.MACVersion, upperBound ttnpb.Minor) (ttnpb.MACVer
return version, upperBound
}

// NegotiatedCipherSuite returns the cipher suite that should be
// used by the end device and network server as part of the
// RekeyInd{Conf} handshake.
// cipherEnum is the Device requested cipher suite.

Check failure on line 173 in pkg/specification/macspec/specification.go

View workflow job for this annotation

GitHub Actions / Code Quality

Sentence should start with a capital letter (godot)
// The only supported cipher suite is the default (0).
func NegotiatedCipherSuite(cipherEnum ttnpb.CipherEnum) uint32 {
switch cipherEnum {
case ttnpb.CipherEnum_CIPHER_0:
return 0
default:
panic(fmt.Errorf("unhandled cipher suite %d", cipherEnum))
}
}

// AllowDuplicateLinkADRAns reports whether v is allowed to use
// duplicate LinkADRAns MAC responses within the same message.
func AllowDuplicateLinkADRAns(v ttnpb.MACVersion) bool {
Expand Down

0 comments on commit 4cf915c

Please sign in to comment.