Skip to content

Commit c42fcbe

Browse files
committed
fd-commands: add/replace response codes using pldm_completion_code
Signed-off-by: leongross <[email protected]>
1 parent 9423913 commit c42fcbe

File tree

3 files changed

+103
-20
lines changed

3 files changed

+103
-20
lines changed

src/message/firmware_update/query_downstream.rs

Lines changed: 99 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
11
// Licensed under the Apache-2.0 license
22

33
use crate::protocol::base::{
4-
InstanceId, PldmMsgHeader, PldmMsgType, PldmSupportedType, TransferOperationFlag,
5-
PLDM_MSG_HEADER_LEN,
4+
InstanceId, PldmBaseCompletionCode, PldmMsgHeader, PldmMsgType, PldmSupportedType,
5+
TransferOperationFlag, PLDM_MSG_HEADER_LEN,
66
};
77

8-
use crate::protocol::firmware_update::{ComponentActivationMethods, Descriptor, FwUpdateCmd};
8+
use crate::pldm_completion_code;
9+
10+
use crate::protocol::firmware_update::{
11+
ComponentActivationMethods, Descriptor, FwUpdateCmd, FwUpdateCompletionCode,
12+
};
913
use bitfield::bitfield;
1014
use zerocopy::{FromBytes, Immutable, IntoBytes};
1115

12-
/// QueryDownstreamDevices is used by the UA to obtain the firmware identifiers for the downstream devices supported
13-
/// by the FDP. The entire list of all attached downstream devices is provided by the response to
14-
/// QueryDownstreamIdentifiers command. The FDP shall provide a response message to this command in
15-
/// all states, including IDLE.
16+
/// QueryDownstreamDevices is used by the UA to obtain the firmware identifiers
17+
/// for the downstream devices supported by the FDP. The entire list of all
18+
/// attached downstream devices is provided by the response to
19+
/// [QueryDownstreamIdentifiers] command. The FDP shall provide a response
20+
/// message to this command in all states, including IDLE.
1621
#[derive(Debug, Clone, FromBytes, IntoBytes, Immutable, PartialEq)]
1722
#[repr(C, packed)]
1823
pub struct QueryDownstreamDevicesRequest {
@@ -45,7 +50,8 @@ bitfield! {
4550
#[derive(Debug, Clone, FromBytes, Immutable, PartialEq)]
4651
pub struct QueryDownstreamDeviceResponse {
4752
pub hdr: PldmMsgHeader<[u8; PLDM_MSG_HEADER_LEN]>,
48-
// TODO: the spec also states to use enum8 here, so let's define some enums
53+
54+
/// PLDM_BASE_CODES
4955
pub completion_code: u8,
5056
pub downstream_device_update_supported: u8,
5157
pub number_of_downstream_devices: u16,
@@ -56,7 +62,7 @@ pub struct QueryDownstreamDeviceResponse {
5662
impl QueryDownstreamDeviceResponse {
5763
pub fn new(
5864
instance_id: InstanceId,
59-
completion_code: u8,
65+
completion_code: PldmBaseCompletionCode,
6066
downstream_device_update_supported: u8,
6167
number_of_downstream_devices: u16,
6268
maximum_number_of_downstream_devices: u16,
@@ -68,7 +74,7 @@ impl QueryDownstreamDeviceResponse {
6874
PldmSupportedType::FwUpdate,
6975
FwUpdateCmd::QueryDownstreamDevices as u8,
7076
),
71-
completion_code,
77+
completion_code: completion_code as u8,
7278
downstream_device_update_supported,
7379
number_of_downstream_devices,
7480
max_number_of_downstream_devices: maximum_number_of_downstream_devices,
@@ -109,12 +115,23 @@ pub const DOWNSTREAM_DEVICE_PORTION_COUNT: usize = 4;
109115
pub const DOWNSTREAM_DEVICE_COUNT: usize = 8;
110116
pub const DOWNSTREAM_DESCRIPTOR_COUNT: usize = 4;
111117

112-
// #[derive(Debug, Clone, Immutable, PartialEq)]
118+
pldm_completion_code! {
119+
QueryDownstreamIdentifiersResponseCode {
120+
InvalidTransferHandle,
121+
InvalidTransferOperationFlag,
122+
DownstreamDeviceListChanged,
123+
}
124+
}
125+
113126
#[derive(Debug, Clone, PartialEq)]
114127
#[repr(C)]
115-
// TODO
116128
pub struct QueryDownstreamIdentifiersResponse {
117129
pub hdr: PldmMsgHeader<[u8; PLDM_MSG_HEADER_LEN]>,
130+
131+
/// PLDM_BASE_CODES, INVALID_TRANSFER_HANDLE, INVALID_TRANSFER_OPERATION_FLAG,
132+
/// DOWNSTREAM_DEVICE_LIST_CHANGED
133+
///
134+
/// See [QueryDownstreamIdentifiersResponseCode].
118135
pub completion_code: u8,
119136
pub next_data_transfer_handle: u32,
120137
pub transfer_flag: u8,
@@ -131,7 +148,7 @@ pub struct QueryDownstreamIdentifiersResponse {
131148
impl QueryDownstreamIdentifiersResponse {
132149
pub fn new(
133150
instance_id: InstanceId,
134-
completion_code: u8,
151+
completion_code: QueryDownstreamIdentifiersResponseCode,
135152
next_data_transfer_handle: u32,
136153
transfer_flag: u8,
137154
portions: Option<&[QueryDownstreamIdentifiersPortion; DOWNSTREAM_DEVICE_PORTION_COUNT]>,
@@ -144,7 +161,7 @@ impl QueryDownstreamIdentifiersResponse {
144161
PldmSupportedType::FwUpdate,
145162
FwUpdateCmd::QueryDownstreamIdentifiers as u8,
146163
),
147-
completion_code,
164+
completion_code: completion_code.into(),
148165
next_data_transfer_handle,
149166
transfer_flag,
150167
portions,
@@ -280,10 +297,23 @@ bitfield! {
280297
pub u32, downstream_device_component_update_failure, set_downstream_device_component_update_failure: 0;
281298
}
282299

283-
// #[derive(Debug, Clone, FromBytes, IntoBytes, Immutable, PartialEq)]
300+
pldm_completion_code! {
301+
GetDownstreamFirmwareParametersResponseCode {
302+
InvalidTransferHandle,
303+
InvalidTransferOperationFlag,
304+
DownstreamDeviceListChanged
305+
}
306+
}
307+
284308
#[derive(Debug, Clone, PartialEq)]
309+
#[repr(C)]
285310
pub struct GetDownstreamFirmwareParametersResponse {
286311
pub hdr: PldmMsgHeader<[u8; PLDM_MSG_HEADER_LEN]>,
312+
313+
/// PLDM_BASE_CODES, INVALID_TRANSFER_HANDLE, INVALID_TRANSFER_OPERATION_FLAG,
314+
/// DOWNSTREAM_DEVICE_LIST_CHANGED
315+
///
316+
/// See [GetDownstreamFirmwareParametersResponseCode].
287317
pub completion_code: u8,
288318
pub next_data_transfer_handle: u32,
289319
pub transfer_flag: u8,
@@ -328,6 +358,29 @@ pub struct DownstreamDeviceParameterTable {
328358
pub pending_component_version_string: Option<[u8; 0xff]>,
329359
}
330360

361+
impl GetDownstreamFirmwareParametersResponse {
362+
pub fn new(
363+
instance_id: InstanceId,
364+
completion_code: GetDownstreamFirmwareParametersResponseCode,
365+
next_data_transfer_handle: u32,
366+
transfer_flag: u8,
367+
portions: Option<[GetDownstreamFirmwareParametersPortion; DOWNSTREAM_DEVICE_PORTION_COUNT]>,
368+
) -> Self {
369+
GetDownstreamFirmwareParametersResponse {
370+
hdr: PldmMsgHeader::new(
371+
instance_id,
372+
PldmMsgType::Response,
373+
PldmSupportedType::FwUpdate,
374+
FwUpdateCmd::GetDownstreamFirmwareParameters as u8,
375+
),
376+
completion_code: completion_code.into(),
377+
next_data_transfer_handle,
378+
transfer_flag,
379+
portions,
380+
}
381+
}
382+
}
383+
331384
bitfield! {
332385
pub struct CapabilitiesDuringUpdate(u32);
333386
impl Debug;
@@ -398,8 +451,21 @@ impl From<DDWillSendGetPackageDataCommand> for u8 {
398451
}
399452
}
400453

454+
pldm_completion_code! {
455+
RequestDownstreamDeviceUpdateCode {
456+
AlreadyInUpdateMode,
457+
UnableToInitiateUpdate,
458+
RetryRequestUpdate
459+
}
460+
}
461+
401462
pub struct RequestDownstreamDeviceUpdateResponse {
402463
pub hdr: PldmMsgHeader<[u8; PLDM_MSG_HEADER_LEN]>,
464+
465+
/// PLDM_BASE_CODES, ALREADY_IN_UPDATE_MODE, UNABLE_TO_INITIATE_UPDATE,
466+
/// RETRY_REQUEST_UPDATE
467+
///
468+
/// See [RequestDownstreamDeviceUpdateCode].
403469
pub completion_code: u8,
404470
pub downstream_device_metadata_length: u16,
405471
pub pkg_data_command: u8,
@@ -409,7 +475,7 @@ pub struct RequestDownstreamDeviceUpdateResponse {
409475
impl RequestDownstreamDeviceUpdateResponse {
410476
pub fn new(
411477
instance_id: InstanceId,
412-
completion_code: u8,
478+
completion_code: RequestDownstreamDeviceUpdateCode,
413479
downstream_device_metadata_length: u16,
414480
pkg_data_command: DDWillSendGetPackageDataCommand,
415481
get_pkg_data_max_transfer_size: u16,
@@ -421,7 +487,7 @@ impl RequestDownstreamDeviceUpdateResponse {
421487
PldmSupportedType::FwUpdate,
422488
FwUpdateCmd::RequestDownstreamDeviceUpdate as u8,
423489
),
424-
completion_code,
490+
completion_code: completion_code.into(),
425491
downstream_device_metadata_length,
426492
pkg_data_command: pkg_data_command.into(),
427493
get_pkg_data_max_transfer_size,
@@ -440,7 +506,8 @@ mod tests {
440506

441507
#[test]
442508
fn test_query_downstream_device_response_new() {
443-
let resp = QueryDownstreamDeviceResponse::new(2, 0x00, 0x01, 5, 10);
509+
let resp =
510+
QueryDownstreamDeviceResponse::new(2, PldmBaseCompletionCode::Success, 0x01, 5, 10);
444511
assert_eq!(resp.hdr.instance_id(), 2);
445512
assert_eq!(resp.completion_code, 0x00);
446513
assert_eq!(resp.downstream_device_update_supported, 0x01);
@@ -461,9 +528,21 @@ mod tests {
461528
portion.clone(),
462529
portion.clone(),
463530
];
464-
let resp = QueryDownstreamIdentifiersResponse::new(4, 0x00, 0x1234, 1, Some(&portions_arr));
531+
let resp = QueryDownstreamIdentifiersResponse::new(
532+
4,
533+
QueryDownstreamIdentifiersResponseCode::BaseCodes(PldmBaseCompletionCode::Success),
534+
0x1234,
535+
1,
536+
Some(&portions_arr),
537+
);
538+
465539
assert_eq!(resp.hdr.instance_id(), 4);
466-
assert_eq!(resp.completion_code, 0x00);
540+
assert_eq!(
541+
QueryDownstreamIdentifiersResponseCode::BaseCodes(
542+
PldmBaseCompletionCode::try_from(resp.completion_code).unwrap()
543+
),
544+
QueryDownstreamIdentifiersResponseCode::BaseCodes(PldmBaseCompletionCode::Success),
545+
);
467546
assert_eq!(resp.next_data_transfer_handle, 0x1234);
468547
assert_eq!(resp.transfer_flag, 1);
469548
assert!(resp.portions.is_some());

src/protocol/base.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@ macro_rules! pldm_completion_code {
271271
$($variant:ident),* $(,)?
272272
}
273273
) => {
274+
#[derive(PartialEq, Debug)]
274275
pub enum $enum_name {
275276
BaseCodes(PldmBaseCompletionCode),
276277
$($variant),*

src/protocol/firmware_update.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ pub enum FwUpdateCompletionCode {
9393
InvalidTransferOperationFlag = 0x91,
9494
ActivatePendingImageNotPermitted = 0x92,
9595
PackageDataError = 0x93,
96+
NoOpaqueData = 0x94,
97+
UpdateSecurityRevisionNotPermitted = 0x95,
98+
DownstreamDeviceListChanged = 0x96,
9699
}
97100

98101
impl TryFrom<u8> for FwUpdateCompletionCode {

0 commit comments

Comments
 (0)