Skip to content

Commit

Permalink
Merge pull request #346 from NordicSemiconductor/bugfix/345
Browse files Browse the repository at this point in the history
Bug fix: Fixed calculating message sequence when Seq > 8191
  • Loading branch information
philips77 authored Apr 15, 2021
2 parents 6d19b4a + b8c7ff0 commit 26eb4cf
Showing 1 changed file with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -704,13 +704,20 @@ private extension NetworkPdu {
return transportPdu[0] & 0x80 > 1
}

/// The 24-bit Seq Auth used to transmit the first segment of a
/// segmented message, or the 24-bit sequence number of an unsegmented
/// message.
/// The 24-bit message sequence number used to transmit the first segment
/// of a segmented message, or the 24-bit sequence number of an unsegmented
/// message. This should be prefixed with 32-bit IV Index to get Seeq Auth.
///
/// If the Seq is 0x647262 and SeqZero is 0x1849, the message sequence
/// should be 0x6451849. See Bluetooth Mesh Profile 1.0.1 chapter 3.5.3.1.
var messageSequence: UInt32 {
if isSegmented {
let sequenceZero = (UInt16(transportPdu[1] & 0x7F) << 6) | UInt16(transportPdu[2] >> 2)
return (sequence & 0xFFE000) | UInt32(sequenceZero)
if (sequence & 0x1FFF < sequenceZero) {
return (sequence & 0xFFE000) + UInt32(sequenceZero) - (0x1FFF + 1)
} else {
return (sequence & 0xFFE000) + UInt32(sequenceZero)
}
} else {
return sequence
}
Expand Down

0 comments on commit 26eb4cf

Please sign in to comment.