// K2476-K2480: portability.devices — Desteklenen aygıt karar tablosu // Invariant: Absent unsupported untested ayrı durumlardır // Positive: MMIO PCI GPU input profilleri // Counterexample: Test yokken supported etiketi // Acceptance: Her destek hücresi gerçek casee bağlı pub const PORTABILITY_DEVICES_SCHEMA: &str = "turkos.os.portability.devices.v1"; pub const PORTABILITY_DEVICES_INVARIANT: &str = "Absent unsupported untested ayrı durumlardır"; pub const PORTABILITY_DEVICES_POSITIVE: &str = "MMIO PCI GPU input profilleri"; pub const PORTABILITY_DEVICES_COUNTEREXAMPLE: &str = "Test yokken supported etiketi"; pub const PORTABILITY_DEVICES_ACCEPTANCE: &str = "Her destek hücresi gerçek casee bağlı"; pub const EXPECTED_DEVICE_DECISION_PROFILES: u32 = 4; pub const EXPECTED_DISTINCT_NON_SUPPORT_STATES: u32 = 3; pub const EXPECTED_CASE_BOUND_SUPPORT_CELLS: u32 = 4; pub const EXPECTED_UNTESTED_SUPPORTED_LABELS: u32 = 0; #[repr(u8)] #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub enum PortabilityDevicesError { SupportedLabelWithoutRealTest = 1, AbsentUnsupportedUntestedCollapsed = 2, SupportCellUnboundToRealCase = 3, DeviceDecisionProfilesMismatch = 4, DistinctNonSupportStatesMismatch = 5, CaseBoundSupportCellsMismatch = 6, ZeroDevicesEpoch = 7, NonMonotonicDevicesEpoch = 8, ZeroDevicesTableDigest = 9, UnboundPortabilityDevicesDigest = 10, AlreadyCommitted = 11, } #[repr(C)] #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub struct PortabilityDevicesRequest { pub supported_label_without_real_test: bool, pub absent_unsupported_untested_collapsed: bool, pub every_support_cell_bound_to_real_case: bool, pub device_decision_profiles: u32, pub distinct_non_support_states: u32, pub case_bound_support_cells: u32, pub devices_epoch: u64, pub previous_devices_epoch: u64, pub devices_table_digest: u64, pub devices_binding_digest: u64, } #[repr(C)] #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub struct PortabilityDevicesReceipt { pub device_decision_profiles: u32, pub distinct_non_support_states: u32, pub case_bound_support_cells: u32, pub untested_supported_labels: u32, pub every_support_cell_bound_to_real_case: bool, pub devices_epoch: u64, pub devices_table_digest: u64, pub receipt_digest: u64, } pub const fn compute_portability_devices_binding_digest( device_decision_profiles: u32, distinct_non_support_states: u32, case_bound_support_cells: u32, untested_supported_labels: u32, devices_epoch: u64, devices_table_digest: u64, ) -> u64 { let mut h: u64 = 0xcbf2_9ce4_8422_2325; h = (h ^ 0x2480_5052_4445_5631).wrapping_mul(0x0000_0100_0000_01b3); h = (h ^ (device_decision_profiles as u64)).wrapping_mul(0x0000_0100_0000_01b3); h = (h ^ (distinct_non_support_states as u64)).wrapping_mul(0x0000_0100_0000_01b3); h = (h ^ (case_bound_support_cells as u64)).wrapping_mul(0x0000_0100_0000_01b3); h = (h ^ (untested_supported_labels as u64)).wrapping_mul(0x0000_0100_0000_01b3); h = (h ^ devices_epoch).wrapping_mul(0x0000_0100_0000_01b3); h = (h ^ devices_table_digest).wrapping_mul(0x0000_0100_0000_01b3); h } pub struct PortabilityDevicesCoordinator { committed: bool, committed_total: u64, rejected_total: u64, device_classification_refusals: u64, device_accounting_refusals: u64, committed_receipt: Option, } impl PortabilityDevicesCoordinator { pub const fn new() -> Self { Self { committed: false, committed_total: 0, rejected_total: 0, device_classification_refusals: 0, device_accounting_refusals: 0, committed_receipt: None, } } pub fn is_committed(&self) -> bool { self.committed } pub fn committed_total(&self) -> u64 { self.committed_total } pub fn rejected_total(&self) -> u64 { self.rejected_total } pub fn device_classification_refusals(&self) -> u64 { self.device_classification_refusals } pub fn device_accounting_refusals(&self) -> u64 { self.device_accounting_refusals } pub fn committed_receipt(&self) -> Option { self.committed_receipt } pub fn commit_device_decision_table( &mut self, req: &PortabilityDevicesRequest, ) -> Result { if self.committed { self.rejected_total += 1; return Err(PortabilityDevicesError::AlreadyCommitted); } if req.supported_label_without_real_test { self.rejected_total += 1; self.device_classification_refusals += 1; return Err(PortabilityDevicesError::SupportedLabelWithoutRealTest); } if req.absent_unsupported_untested_collapsed { self.rejected_total += 1; self.device_classification_refusals += 1; return Err(PortabilityDevicesError::AbsentUnsupportedUntestedCollapsed); } if !req.every_support_cell_bound_to_real_case { self.rejected_total += 1; self.device_classification_refusals += 1; return Err(PortabilityDevicesError::SupportCellUnboundToRealCase); } if req.device_decision_profiles != EXPECTED_DEVICE_DECISION_PROFILES { self.rejected_total += 1; self.device_accounting_refusals += 1; return Err(PortabilityDevicesError::DeviceDecisionProfilesMismatch); } if req.distinct_non_support_states != EXPECTED_DISTINCT_NON_SUPPORT_STATES { self.rejected_total += 1; self.device_accounting_refusals += 1; return Err(PortabilityDevicesError::DistinctNonSupportStatesMismatch); } if req.case_bound_support_cells != EXPECTED_CASE_BOUND_SUPPORT_CELLS { self.rejected_total += 1; self.device_accounting_refusals += 1; return Err(PortabilityDevicesError::CaseBoundSupportCellsMismatch); } if req.devices_epoch == 0 { self.rejected_total += 1; return Err(PortabilityDevicesError::ZeroDevicesEpoch); } if req.devices_epoch <= req.previous_devices_epoch { self.rejected_total += 1; return Err(PortabilityDevicesError::NonMonotonicDevicesEpoch); } if req.devices_table_digest == 0 { self.rejected_total += 1; return Err(PortabilityDevicesError::ZeroDevicesTableDigest); } let expected_binding = compute_portability_devices_binding_digest( req.device_decision_profiles, req.distinct_non_support_states, req.case_bound_support_cells, EXPECTED_UNTESTED_SUPPORTED_LABELS, req.devices_epoch, req.devices_table_digest, ); if req.devices_binding_digest != expected_binding { self.rejected_total += 1; self.device_accounting_refusals += 1; return Err(PortabilityDevicesError::UnboundPortabilityDevicesDigest); } self.committed = true; self.committed_total += 1; let receipt = PortabilityDevicesReceipt { device_decision_profiles: req.device_decision_profiles, distinct_non_support_states: req.distinct_non_support_states, case_bound_support_cells: req.case_bound_support_cells, untested_supported_labels: EXPECTED_UNTESTED_SUPPORTED_LABELS, every_support_cell_bound_to_real_case: true, devices_epoch: req.devices_epoch, devices_table_digest: req.devices_table_digest, receipt_digest: expected_binding ^ 0x2480_ACE0_4445_5631, }; self.committed_receipt = Some(receipt); Ok(receipt) } }