Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
60 changes: 46 additions & 14 deletions c/include/libsbp/integrity_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -313,22 +313,22 @@
#define SBP_ACKNOWLEDGE_RESPONSE_CODE_FORBIDDEN (2)
#define SBP_ACKNOWLEDGE_RESPONSE_CODE_INVALID_REQUEST (3)
#define SBP_ACKNOWLEDGE_RESPONSE_CODE_INVALID_AREA_ID (4)
#define SBP_ACKNOWLEDGE_PUBLIC_SIGNING_KEY_MASK (0x1u)
#define SBP_ACKNOWLEDGE_PUBLIC_SIGNING_KEY_SHIFT (0u)
#define SBP_ACKNOWLEDGE_PUBLIC_SIGNING_KEY_GET(flags) \
((u16)((u16)((flags) >> SBP_ACKNOWLEDGE_PUBLIC_SIGNING_KEY_SHIFT) & \
SBP_ACKNOWLEDGE_PUBLIC_SIGNING_KEY_MASK))
#define SBP_ACKNOWLEDGE_PUBLIC_SIGNING_KEY_SET(flags, val) \
do { \
(flags) = \
(u16)((flags & (~(SBP_ACKNOWLEDGE_PUBLIC_SIGNING_KEY_MASK \
<< SBP_ACKNOWLEDGE_PUBLIC_SIGNING_KEY_SHIFT))) | \
(((val) & (SBP_ACKNOWLEDGE_PUBLIC_SIGNING_KEY_MASK)) \
<< (SBP_ACKNOWLEDGE_PUBLIC_SIGNING_KEY_SHIFT))); \
#define SBP_ACKNOWLEDGE_CORRECTIONS_CERTIFICATE_MASK (0x1u)
#define SBP_ACKNOWLEDGE_CORRECTIONS_CERTIFICATE_SHIFT (0u)
#define SBP_ACKNOWLEDGE_CORRECTIONS_CERTIFICATE_GET(flags) \
((u16)((u16)((flags) >> SBP_ACKNOWLEDGE_CORRECTIONS_CERTIFICATE_SHIFT) & \
SBP_ACKNOWLEDGE_CORRECTIONS_CERTIFICATE_MASK))
#define SBP_ACKNOWLEDGE_CORRECTIONS_CERTIFICATE_SET(flags, val) \
do { \
(flags) = (u16)( \
(flags & (~(SBP_ACKNOWLEDGE_CORRECTIONS_CERTIFICATE_MASK \
<< SBP_ACKNOWLEDGE_CORRECTIONS_CERTIFICATE_SHIFT))) | \
(((val) & (SBP_ACKNOWLEDGE_CORRECTIONS_CERTIFICATE_MASK)) \
<< (SBP_ACKNOWLEDGE_CORRECTIONS_CERTIFICATE_SHIFT))); \
} while (0)

#define SBP_ACKNOWLEDGE_PUBLIC_SIGNING_KEY_NOT_REQUESTED (0)
#define SBP_ACKNOWLEDGE_PUBLIC_SIGNING_KEY_REQUESTED (1)
#define SBP_ACKNOWLEDGE_CORRECTIONS_CERTIFICATE_NOT_REQUESTED (0)
#define SBP_ACKNOWLEDGE_CORRECTIONS_CERTIFICATE_REQUESTED (1)
#define SBP_ACKNOWLEDGE_LOW_RATE_MESSAGES_MASK (0x1u)
#define SBP_ACKNOWLEDGE_LOW_RATE_MESSAGES_SHIFT (1u)
#define SBP_ACKNOWLEDGE_LOW_RATE_MESSAGES_GET(flags) \
Expand Down Expand Up @@ -452,6 +452,38 @@

#define SBP_ACKNOWLEDGE_INTEGRITY_NOT_REQUESTED (0)
#define SBP_ACKNOWLEDGE_INTEGRITY_REQUESTED (1)
#define SBP_ACKNOWLEDGE_INTERMEDIATE_CERTIFICATE_MASK (0x1u)
#define SBP_ACKNOWLEDGE_INTERMEDIATE_CERTIFICATE_SHIFT (9u)
#define SBP_ACKNOWLEDGE_INTERMEDIATE_CERTIFICATE_GET(flags) \
((u16)((u16)((flags) >> SBP_ACKNOWLEDGE_INTERMEDIATE_CERTIFICATE_SHIFT) & \
SBP_ACKNOWLEDGE_INTERMEDIATE_CERTIFICATE_MASK))
#define SBP_ACKNOWLEDGE_INTERMEDIATE_CERTIFICATE_SET(flags, val) \
do { \
(flags) = (u16)( \
(flags & (~(SBP_ACKNOWLEDGE_INTERMEDIATE_CERTIFICATE_MASK \
<< SBP_ACKNOWLEDGE_INTERMEDIATE_CERTIFICATE_SHIFT))) | \
(((val) & (SBP_ACKNOWLEDGE_INTERMEDIATE_CERTIFICATE_MASK)) \
<< (SBP_ACKNOWLEDGE_INTERMEDIATE_CERTIFICATE_SHIFT))); \
} while (0)

#define SBP_ACKNOWLEDGE_INTERMEDIATE_CERTIFICATE_NOT_REQUESTED (0)
#define SBP_ACKNOWLEDGE_INTERMEDIATE_CERTIFICATE_REQUESTED (1)
#define SBP_ACKNOWLEDGE_CERTIFICATE_CHAIN_MASK (0x1u)
#define SBP_ACKNOWLEDGE_CERTIFICATE_CHAIN_SHIFT (10u)
#define SBP_ACKNOWLEDGE_CERTIFICATE_CHAIN_GET(flags) \
((u16)((u16)((flags) >> SBP_ACKNOWLEDGE_CERTIFICATE_CHAIN_SHIFT) & \
SBP_ACKNOWLEDGE_CERTIFICATE_CHAIN_MASK))
#define SBP_ACKNOWLEDGE_CERTIFICATE_CHAIN_SET(flags, val) \
do { \
(flags) = \
(u16)((flags & (~(SBP_ACKNOWLEDGE_CERTIFICATE_CHAIN_MASK \
<< SBP_ACKNOWLEDGE_CERTIFICATE_CHAIN_SHIFT))) | \
(((val) & (SBP_ACKNOWLEDGE_CERTIFICATE_CHAIN_MASK)) \
<< (SBP_ACKNOWLEDGE_CERTIFICATE_CHAIN_SHIFT))); \
} while (0)

#define SBP_ACKNOWLEDGE_CERTIFICATE_CHAIN_NOT_REQUESTED (0)
#define SBP_ACKNOWLEDGE_CERTIFICATE_CHAIN_REQUESTED (1)
/**
* Encoded length of sbp_msg_acknowledge_t (V4 API) and
* msg_acknowledge_t (legacy API)
Expand Down
Binary file modified docs/sbp.pdf
Binary file not shown.
138 changes: 123 additions & 15 deletions rust/sbp/src/messages/integrity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,20 +148,23 @@ pub mod msg_acknowledge {
set_bit_range!(&mut self.response_code, response_code, u8, u8, 7, 0);
}

/// Gets the [PublicSigningKey][self::PublicSigningKey] stored in the `correction_mask_on_demand` bitfield.
/// Gets the [CorrectionsCertificate][self::CorrectionsCertificate] stored in the `correction_mask_on_demand` bitfield.
///
/// Returns `Ok` if the bitrange contains a known `PublicSigningKey` variant.
/// Returns `Ok` if the bitrange contains a known `CorrectionsCertificate` variant.
/// Otherwise the value of the bitrange is returned as an `Err(u8)`. This may be because of a malformed message,
/// or because new variants of `PublicSigningKey` were added.
pub fn public_signing_key(&self) -> Result<PublicSigningKey, u8> {
/// or because new variants of `CorrectionsCertificate` were added.
pub fn corrections_certificate(&self) -> Result<CorrectionsCertificate, u8> {
get_bit_range!(self.correction_mask_on_demand, u16, u8, 0, 0).try_into()
}

/// Set the bitrange corresponding to the [PublicSigningKey][PublicSigningKey] of the `correction_mask_on_demand` bitfield.
pub fn set_public_signing_key(&mut self, public_signing_key: PublicSigningKey) {
/// Set the bitrange corresponding to the [CorrectionsCertificate][CorrectionsCertificate] of the `correction_mask_on_demand` bitfield.
pub fn set_corrections_certificate(
&mut self,
corrections_certificate: CorrectionsCertificate,
) {
set_bit_range!(
&mut self.correction_mask_on_demand,
public_signing_key,
corrections_certificate,
u16,
u8,
0,
Expand Down Expand Up @@ -336,6 +339,51 @@ pub mod msg_acknowledge {
8
);
}

/// Gets the [IntermediateCertificate][self::IntermediateCertificate] stored in the `correction_mask_on_demand` bitfield.
///
/// Returns `Ok` if the bitrange contains a known `IntermediateCertificate` variant.
/// Otherwise the value of the bitrange is returned as an `Err(u8)`. This may be because of a malformed message,
/// or because new variants of `IntermediateCertificate` were added.
pub fn intermediate_certificate(&self) -> Result<IntermediateCertificate, u8> {
get_bit_range!(self.correction_mask_on_demand, u16, u8, 9, 9).try_into()
}

/// Set the bitrange corresponding to the [IntermediateCertificate][IntermediateCertificate] of the `correction_mask_on_demand` bitfield.
pub fn set_intermediate_certificate(
&mut self,
intermediate_certificate: IntermediateCertificate,
) {
set_bit_range!(
&mut self.correction_mask_on_demand,
intermediate_certificate,
u16,
u8,
9,
9
);
}

/// Gets the [CertificateChain][self::CertificateChain] stored in the `correction_mask_on_demand` bitfield.
///
/// Returns `Ok` if the bitrange contains a known `CertificateChain` variant.
/// Otherwise the value of the bitrange is returned as an `Err(u8)`. This may be because of a malformed message,
/// or because new variants of `CertificateChain` were added.
pub fn certificate_chain(&self) -> Result<CertificateChain, u8> {
get_bit_range!(self.correction_mask_on_demand, u16, u8, 10, 10).try_into()
}

/// Set the bitrange corresponding to the [CertificateChain][CertificateChain] of the `correction_mask_on_demand` bitfield.
pub fn set_certificate_chain(&mut self, certificate_chain: CertificateChain) {
set_bit_range!(
&mut self.correction_mask_on_demand,
certificate_chain,
u16,
u8,
10,
10
);
}
}

impl ConcreteMessage for MsgAcknowledge {
Expand Down Expand Up @@ -458,31 +506,31 @@ pub mod msg_acknowledge {
}
}

/// Public Signing Key
/// Corrections certificate
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum PublicSigningKey {
pub enum CorrectionsCertificate {
/// Not requested
NotRequested = 0,

/// Requested
Requested = 1,
}

impl std::fmt::Display for PublicSigningKey {
impl std::fmt::Display for CorrectionsCertificate {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
PublicSigningKey::NotRequested => f.write_str("Not requested"),
PublicSigningKey::Requested => f.write_str("Requested"),
CorrectionsCertificate::NotRequested => f.write_str("Not requested"),
CorrectionsCertificate::Requested => f.write_str("Requested"),
}
}
}

impl TryFrom<u8> for PublicSigningKey {
impl TryFrom<u8> for CorrectionsCertificate {
type Error = u8;
fn try_from(i: u8) -> Result<Self, u8> {
match i {
0 => Ok(PublicSigningKey::NotRequested),
1 => Ok(PublicSigningKey::Requested),
0 => Ok(CorrectionsCertificate::NotRequested),
1 => Ok(CorrectionsCertificate::Requested),
i => Err(i),
}
}
Expand Down Expand Up @@ -727,6 +775,66 @@ pub mod msg_acknowledge {
}
}
}

/// Intermediate certificate
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum IntermediateCertificate {
/// Not requested
NotRequested = 0,

/// Requested
Requested = 1,
}

impl std::fmt::Display for IntermediateCertificate {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
IntermediateCertificate::NotRequested => f.write_str("Not requested"),
IntermediateCertificate::Requested => f.write_str("Requested"),
}
}
}

impl TryFrom<u8> for IntermediateCertificate {
type Error = u8;
fn try_from(i: u8) -> Result<Self, u8> {
match i {
0 => Ok(IntermediateCertificate::NotRequested),
1 => Ok(IntermediateCertificate::Requested),
i => Err(i),
}
}
}

/// Certificate chain
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum CertificateChain {
/// Not requested
NotRequested = 0,

/// Requested
Requested = 1,
}

impl std::fmt::Display for CertificateChain {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
CertificateChain::NotRequested => f.write_str("Not requested"),
CertificateChain::Requested => f.write_str("Requested"),
}
}
}

impl TryFrom<u8> for CertificateChain {
type Error = u8;
fn try_from(i: u8) -> Result<Self, u8> {
match i {
0 => Ok(CertificateChain::NotRequested),
1 => Ok(CertificateChain::Requested),
i => Err(i),
}
}
}
}

pub mod msg_ssr_flag_high_level {
Expand Down
14 changes: 12 additions & 2 deletions spec/yaml/swiftnav/sbp/integrity.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ definitions:
An echo of the correction mask field from the corresponding CRA message.
fields:
- 0:
desc: Public Signing Key
desc: Corrections certificate
values:
- 0: Not requested
- 1: Requested
Expand Down Expand Up @@ -351,7 +351,17 @@ definitions:
values:
- 0: Not requested
- 1: Requested
- 9-15:
- 9:
desc: Intermediate certificate
values:
- 0: Not requested
- 1: Requested
- 10:
desc: Certificate chain
values:
- 0: Not requested
- 1: Requested
- 11-15:
desc: Reserved

- correction_mask_stream:
Expand Down