@@ -8,10 +8,7 @@ pub(crate) use response::*;
88
99use zerocopy:: { FromBytes , Immutable , IntoBytes } ;
1010
11- use crate :: {
12- codec:: CommonCodec ,
13- protocol:: { CapabilityFlags , EpInfoCapability , PskCapability , SpdmVersion } ,
14- } ;
11+ use crate :: { codec:: CommonCodec , protocol:: CapabilityFlags } ;
1512
1613use crate :: protocol:: capabilities:: DeviceCapabilities ;
1714
@@ -21,6 +18,10 @@ pub struct GetCapabilitiesBase {
2118 param1 : u8 ,
2219 param2 : u8 ,
2320}
21+ /// CAPABILITIES response base
22+ ///
23+ /// v1.0 CAPABILITIES response is constructed by `CapabilitiesBase`+`Capabilities`.
24+ pub type CapabilitiesBase = GetCapabilitiesBase ;
2425
2526impl CommonCodec for GetCapabilitiesBase { }
2627
@@ -50,6 +51,8 @@ pub struct GetCapabilitiesV11 {
5051 /// Capability flags.
5152 flags : CapabilityFlags ,
5253}
54+ /// CAPABILITIES response
55+ pub type Capabilities = GetCapabilitiesV11 ;
5356
5457impl GetCapabilitiesV11 {
5558 pub fn new ( ct_exponent : u8 , flags : CapabilityFlags ) -> Self {
@@ -82,6 +85,8 @@ pub struct GetCapabilitiesV12 {
8285 /// Large SPDM message.
8386 max_spdm_msg_size : u32 ,
8487}
88+ /// CAPABILITIES response v1.2 additions
89+ pub type CapabilitiesV12 = GetCapabilitiesV12 ;
8590
8691impl CommonCodec for GetCapabilitiesV12 { }
8792
@@ -111,107 +116,3 @@ impl Default for GetCapabilitiesV12 {
111116 }
112117 }
113118}
114-
115- /// Checks if the request capability flags are compatible with the SPDM version
116- ///# Arguments
117- /// - `version`: SPDM version
118- /// - `flags`: Capability flags from the request
119- ///
120- /// # Returns
121- /// - true if compatible
122- /// - false if incompatible
123- pub ( crate ) fn req_flag_compatible ( version : SpdmVersion , flags : & CapabilityFlags ) -> bool {
124- // Checks specific to 1.1
125- if version == SpdmVersion :: V11 && flags. mut_auth_cap ( ) == 1 && flags. encap_cap ( ) == 0 {
126- return false ;
127- }
128-
129- // Check if MEAS_CAP is valid
130- // 0b11 is reserved
131- if flags. meas_cap ( ) == 0b11 {
132- return false ;
133- }
134-
135- // Checks common to 1.1 and higher
136- if version >= SpdmVersion :: V11 {
137- // Illegal to return reserved values (2 and 3)
138- if flags. psk_cap ( ) >= PskCapability :: PskWithContext as u8 {
139- return false ;
140- }
141-
142- // Checks that originate from key exchange capabilities
143- if flags. key_ex_cap ( ) == 1 || flags. psk_cap ( ) != PskCapability :: NoPsk as u8 {
144- if flags. mac_cap ( ) == 0 && flags. encrypt_cap ( ) == 0 {
145- return false ;
146- }
147- } else {
148- if flags. mac_cap ( ) == 1
149- || flags. encrypt_cap ( ) == 1
150- || flags. handshake_in_the_clear_cap ( ) == 1
151- || flags. hbeat_cap ( ) == 1
152- || flags. key_upd_cap ( ) == 1
153- {
154- return false ;
155- }
156-
157- if version >= SpdmVersion :: V13 && flags. event_cap ( ) == 1 {
158- return false ;
159- }
160- }
161-
162- if flags. key_ex_cap ( ) == 0
163- && flags. psk_cap ( ) == PskCapability :: PskWithNoContext as u8
164- && flags. handshake_in_the_clear_cap ( ) == 1
165- {
166- return false ;
167- }
168-
169- // Checks that originate from certificate or public key capabilities
170- if flags. cert_cap ( ) == 1 || flags. pub_key_id_cap ( ) == 1 {
171- // Certificate capabilities and public key capabilities can not both be set
172- if flags. cert_cap ( ) == 1 && flags. pub_key_id_cap ( ) == 1 {
173- return false ;
174- }
175-
176- if flags. chal_cap ( ) == 0 && flags. pub_key_id_cap ( ) == 1 {
177- return false ;
178- }
179- } else {
180- // If certificates or public keys are not enabled then these capabilities are not allowed
181- if flags. chal_cap ( ) == 1 || flags. mut_auth_cap ( ) == 1 {
182- return false ;
183- }
184-
185- if version >= SpdmVersion :: V13
186- && flags. ep_info_cap ( ) == EpInfoCapability :: EpInfoWithSignature as u8
187- {
188- return false ;
189- }
190- }
191-
192- // Checks that originate from mutual authentication capabilities
193- if flags. mut_auth_cap ( ) == 1 {
194- // Mutual authentication with asymmetric keys can only occur through the basic mutual
195- // authentication flow (CHAL_CAP == 1) or the session-based mutual authentication flow
196- // (KEY_EX_CAP == 1)
197- if flags. cert_cap ( ) == 0 && flags. pub_key_id_cap ( ) == 0 {
198- return false ;
199- }
200- }
201- }
202-
203- // Checks specific to 1.3 and higher
204- if version >= SpdmVersion :: V13 {
205- // Illegal to return reserved values
206- if flags. ep_info_cap ( ) == EpInfoCapability :: Reserved as u8 || flags. multi_key_cap ( ) == 3 {
207- return false ;
208- }
209-
210- // Check multi_key_cap and pub_key_id_cap
211- if flags. multi_key_cap ( ) != 0 && flags. pub_key_id_cap ( ) == 1 {
212- return false ;
213- }
214- }
215-
216- true
217- }
0 commit comments