Skip to content

Commit 82db8d4

Browse files
committed
storage: add storage standard protocols common
Signed-off-by: Wilfred Mallawa <wilfred.mallawa@wdc.com>
1 parent ad2e49d commit 82db8d4

File tree

1 file changed

+92
-0
lines changed

1 file changed

+92
-0
lines changed

src/storage_standards.rs

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
// Licensed under the Apache License, Version 2.0 or the MIT License.
2+
// SPDX-License-Identifier: Apache-2.0 OR MIT
3+
// Copyright (C) 2024, Western Digital Corporation or its affiliates.
4+
5+
//! Contains all of the handlers for creating SPDM requests.
6+
7+
/// SCSI SPDM Related ADDITIONAL SENSE CODE (ASQ)
8+
#[allow(dead_code)]
9+
#[derive(Debug)]
10+
pub enum ScsiAsc {
11+
InvalidFieldInCdb = 0x24, // ASCQ = 0x00
12+
}
13+
14+
/// Defines the SPDM return status (upper byte) and error (lower byte)
15+
/// for ATA as defined in DSP0284.
16+
#[allow(dead_code)]
17+
#[derive(Debug)]
18+
pub enum AtaStatusErr {
19+
Success = 0x5000,
20+
InvalidCommand = 0x5104,
21+
}
22+
23+
/// NVME Completion Queue Command Completion Status
24+
#[allow(dead_code)]
25+
#[derive(Debug)]
26+
pub enum NvmeCmdStatus {
27+
NvmeSuccess = 0x0000,
28+
NvmeInvalidFieldInCmd = 0x0002,
29+
NvmeDoNotRetry = 0x4000,
30+
}
31+
32+
/// Spdm Storage Operations as defined in DMTF DSP0286
33+
#[derive(Debug, PartialEq)]
34+
pub enum SpdmOperationCodes {
35+
SpdmStorageDiscovery = 0x01,
36+
SpdmStoragePendingInfo = 0x02,
37+
SpdmStorageMessage = 0x05,
38+
SpdmStorageSecMessage = 0x06,
39+
}
40+
41+
impl TryFrom<u8> for SpdmOperationCodes {
42+
type Error = ();
43+
fn try_from(value: u8) -> Result<Self, Self::Error> {
44+
match value {
45+
0x01 => Ok(SpdmOperationCodes::SpdmStorageDiscovery),
46+
0x02 => Ok(SpdmOperationCodes::SpdmStoragePendingInfo),
47+
0x05 => Ok(SpdmOperationCodes::SpdmStorageMessage),
48+
0x06 => Ok(SpdmOperationCodes::SpdmStorageSecMessage),
49+
_ => Err(()),
50+
}
51+
}
52+
}
53+
54+
impl From<SpdmOperationCodes> for u8 {
55+
fn from(op: SpdmOperationCodes) -> Self {
56+
match op {
57+
SpdmOperationCodes::SpdmStorageDiscovery => 0x01,
58+
SpdmOperationCodes::SpdmStoragePendingInfo => 0x02,
59+
SpdmOperationCodes::SpdmStorageMessage => 0x05,
60+
SpdmOperationCodes::SpdmStorageSecMessage => 0x06,
61+
}
62+
}
63+
}
64+
65+
/// Relevant Security Protocols as specified in Working Draft SCSI Primary
66+
/// Commands - 6 (SPC-6)
67+
#[derive(Debug, PartialEq)]
68+
pub enum SpcSecurityProtocols {
69+
SecurityProtocolInformation,
70+
DmtfSpdm,
71+
}
72+
73+
impl From<SpcSecurityProtocols> for u8 {
74+
fn from(c: SpcSecurityProtocols) -> Self {
75+
match c {
76+
SpcSecurityProtocols::SecurityProtocolInformation => 0x00,
77+
SpcSecurityProtocols::DmtfSpdm => 0xE8,
78+
}
79+
}
80+
}
81+
82+
impl TryFrom<u8> for SpcSecurityProtocols {
83+
type Error = ();
84+
fn try_from(v: u8) -> Result<Self, Self::Error> {
85+
match v {
86+
0x00 => Ok(SpcSecurityProtocols::SecurityProtocolInformation),
87+
0xE8 => Ok(SpcSecurityProtocols::DmtfSpdm),
88+
_ => Err(()),
89+
}
90+
}
91+
}
92+

0 commit comments

Comments
 (0)