diff --git a/c/include/libsbp/integrity_macros.h b/c/include/libsbp/integrity_macros.h index ddb334aaac..4f2d83d14f 100644 --- a/c/include/libsbp/integrity_macros.h +++ b/c/include/libsbp/integrity_macros.h @@ -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) \ @@ -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) diff --git a/docs/sbp.pdf b/docs/sbp.pdf index a9196b719c..ec6286ef8a 100644 Binary files a/docs/sbp.pdf and b/docs/sbp.pdf differ diff --git a/rust/sbp/src/messages/integrity.rs b/rust/sbp/src/messages/integrity.rs index c538ec9b22..2821aac1b4 100644 --- a/rust/sbp/src/messages/integrity.rs +++ b/rust/sbp/src/messages/integrity.rs @@ -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 { + /// or because new variants of `CorrectionsCertificate` were added. + pub fn corrections_certificate(&self) -> Result { 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, @@ -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 { + 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 { + 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 { @@ -458,9 +506,9 @@ 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, @@ -468,21 +516,21 @@ pub mod msg_acknowledge { 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 for PublicSigningKey { + impl TryFrom for CorrectionsCertificate { type Error = u8; fn try_from(i: u8) -> Result { match i { - 0 => Ok(PublicSigningKey::NotRequested), - 1 => Ok(PublicSigningKey::Requested), + 0 => Ok(CorrectionsCertificate::NotRequested), + 1 => Ok(CorrectionsCertificate::Requested), i => Err(i), } } @@ -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 for IntermediateCertificate { + type Error = u8; + fn try_from(i: u8) -> Result { + 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 for CertificateChain { + type Error = u8; + fn try_from(i: u8) -> Result { + match i { + 0 => Ok(CertificateChain::NotRequested), + 1 => Ok(CertificateChain::Requested), + i => Err(i), + } + } + } } pub mod msg_ssr_flag_high_level { diff --git a/spec/yaml/swiftnav/sbp/integrity.yaml b/spec/yaml/swiftnav/sbp/integrity.yaml index 7b76572e86..6748ecb0ff 100644 --- a/spec/yaml/swiftnav/sbp/integrity.yaml +++ b/spec/yaml/swiftnav/sbp/integrity.yaml @@ -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 @@ -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: