Sampa Misra | 0db1dfa | 2019-03-19 00:15:31 -0500 | [diff] [blame] | 1 | #ifndef PLATFORM_H |
| 2 | #define PLATFORM_H |
| 3 | |
| 4 | #ifdef __cplusplus |
| 5 | extern "C" { |
| 6 | #endif |
| 7 | |
| 8 | #include <stddef.h> |
| 9 | #include <stdint.h> |
| 10 | |
| 11 | #include "base.h" |
| 12 | |
| 13 | /* Maximum size for request */ |
| 14 | #define PLDM_SET_STATE_EFFECTER_STATES_REQ_BYTES 19 |
| 15 | /* Response lengths are inclusive of completion code */ |
| 16 | #define PLDM_SET_STATE_EFFECTER_STATES_RESP_BYTES 1 |
| 17 | |
Sampa Misra | 7fcfb66 | 2019-05-08 13:13:53 -0500 | [diff] [blame] | 18 | #define PLDM_GET_PDR_REQ_BYTES 13 |
| 19 | /* Minimum response length */ |
| 20 | #define PLDM_GET_PDR_MIN_RESP_BYTES 12 |
| 21 | |
Sampa Misra | 0db1dfa | 2019-03-19 00:15:31 -0500 | [diff] [blame] | 22 | enum set_request { PLDM_NO_CHANGE = 0x00, PLDM_REQUEST_SET = 0x01 }; |
| 23 | |
| 24 | enum effecter_state { PLDM_INVALID_VALUE = 0xFF }; |
| 25 | |
| 26 | enum pldm_platform_commands { |
| 27 | PLDM_SET_STATE_EFFECTER_STATES = 0x39, |
Sampa Misra | 7fcfb66 | 2019-05-08 13:13:53 -0500 | [diff] [blame] | 28 | PLDM_GET_PDR = 0x51, |
Sampa Misra | 0db1dfa | 2019-03-19 00:15:31 -0500 | [diff] [blame] | 29 | }; |
| 30 | |
Deepak Kodihalli | c6e8fb5 | 2019-05-02 08:35:31 -0500 | [diff] [blame] | 31 | /** @brief PLDM PDR types |
| 32 | */ |
| 33 | enum pldm_pdr_types { |
| 34 | PLDM_STATE_EFFECTER_PDR = 11, |
| 35 | }; |
| 36 | |
| 37 | /** @brief PLDM effecter initialization schemes |
| 38 | */ |
| 39 | enum pldm_effecter_init { |
| 40 | PLDM_NO_INIT, |
| 41 | PLDM_USE_INIT_PDR, |
| 42 | PLDM_ENABLE_EFFECTER, |
| 43 | PLDM_DISABLE_EFECTER |
| 44 | }; |
| 45 | |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 46 | /** @brief PLDM Platform M&C completion codes |
| 47 | */ |
| 48 | enum pldm_platform_completion_codes { |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 49 | PLDM_PLATFORM_INVALID_EFFECTER_ID = 0x80, |
| 50 | PLDM_PLATFORM_INVALID_STATE_VALUE = 0x81, |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 51 | PLDM_PLATFORM_INVALID_RECORD_HANDLE = 0x82, |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 52 | PLDM_PLATFORM_SET_EFFECTER_UNSUPPORTED_SENSORSTATE = 0x82, |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 53 | }; |
| 54 | |
Deepak Kodihalli | c6e8fb5 | 2019-05-02 08:35:31 -0500 | [diff] [blame] | 55 | /** @struct pldm_pdr_hdr |
| 56 | * |
| 57 | * Structure representing PLDM common PDR header |
| 58 | */ |
| 59 | struct pldm_pdr_hdr { |
| 60 | uint32_t record_handle; |
| 61 | uint8_t version; |
| 62 | uint8_t type; |
| 63 | uint16_t record_change_num; |
| 64 | uint16_t length; |
| 65 | } __attribute__((packed)); |
| 66 | |
| 67 | /** @struct pldm_state_effecter_pdr |
| 68 | * |
| 69 | * Structure representing PLDM state effecter PDR |
| 70 | */ |
| 71 | struct pldm_state_effecter_pdr { |
| 72 | struct pldm_pdr_hdr hdr; |
| 73 | uint16_t terminus_handle; |
| 74 | uint16_t effecter_id; |
| 75 | uint16_t entity_type; |
| 76 | uint16_t entity_instance; |
| 77 | uint16_t container_id; |
| 78 | uint16_t effecter_semantic_id; |
| 79 | uint8_t effecter_init; |
| 80 | bool8_t has_description_pdr; |
| 81 | uint8_t composite_effecter_count; |
| 82 | uint8_t possible_states[1]; |
| 83 | } __attribute__((packed)); |
| 84 | |
| 85 | /** @struct state_effecter_possible_states |
| 86 | * |
| 87 | * Structure representing state enums for state effecter |
| 88 | */ |
| 89 | struct state_effecter_possible_states { |
| 90 | uint16_t state_set_id; |
| 91 | uint8_t possible_states_size; |
| 92 | bitfield8_t states[1]; |
| 93 | } __attribute__((packed)); |
| 94 | |
Sampa Misra | 0db1dfa | 2019-03-19 00:15:31 -0500 | [diff] [blame] | 95 | /** @struct set_effecter_state_field |
| 96 | * |
| 97 | * Structure representing a stateField in SetStateEffecterStates command */ |
| 98 | |
| 99 | typedef struct state_field_for_state_effecter_set { |
| 100 | uint8_t set_request; //!< Whether to change the state |
| 101 | uint8_t effecter_state; //!< Expected state of the effecter |
| 102 | } __attribute__((packed)) set_effecter_state_field; |
| 103 | |
Priyanga | 7257fdf | 2019-06-10 01:59:45 -0500 | [diff] [blame] | 104 | /** @struct PLDM_SetStateEffecterStates_Request |
| 105 | * |
| 106 | * Structure representing PLDM set state effecter states request. |
| 107 | */ |
| 108 | struct pldm_set_state_effecter_states_req { |
| 109 | uint16_t effecter_id; |
| 110 | uint8_t comp_effecter_count; |
| 111 | set_effecter_state_field field[8]; |
| 112 | } __attribute__((packed)); |
| 113 | |
Sampa Misra | 7fcfb66 | 2019-05-08 13:13:53 -0500 | [diff] [blame] | 114 | /** @struct pldm_get_pdr_resp |
| 115 | * |
| 116 | * structure representing GetPDR response packet |
| 117 | * transfer CRC is not part of the structure and will be |
| 118 | * added at the end of last packet in multipart transfer |
| 119 | */ |
| 120 | struct pldm_get_pdr_resp { |
| 121 | uint8_t completion_code; |
| 122 | uint32_t next_record_handle; |
| 123 | uint32_t next_data_transfer_handle; |
| 124 | uint8_t transfer_flag; |
| 125 | uint16_t response_count; |
| 126 | uint8_t record_data[1]; |
| 127 | } __attribute__((packed)); |
| 128 | |
| 129 | /** @struct pldm_get_pdr_req |
| 130 | * |
| 131 | * structure representing GetPDR request packet |
| 132 | */ |
| 133 | struct pldm_get_pdr_req { |
| 134 | uint32_t record_handle; |
| 135 | uint32_t data_transfer_handle; |
| 136 | uint8_t transfer_op_flag; |
| 137 | uint16_t request_count; |
| 138 | uint16_t record_change_number; |
| 139 | } __attribute__((packed)); |
| 140 | |
Sampa Misra | 0db1dfa | 2019-03-19 00:15:31 -0500 | [diff] [blame] | 141 | /* Responder */ |
| 142 | |
| 143 | /* SetStateEffecterStates */ |
| 144 | |
| 145 | /** @brief Create a PLDM response message for SetStateEffecterStates |
| 146 | * |
| 147 | * @param[in] instance_id - Message's instance id |
| 148 | * @param[in] completion_code - PLDM completion code |
| 149 | * @param[out] msg - Message will be written to this |
| 150 | * @return pldm_completion_codes |
| 151 | * @note Caller is responsible for memory alloc and dealloc of param |
| 152 | * 'msg.body.payload' |
| 153 | */ |
| 154 | |
| 155 | int encode_set_state_effecter_states_resp(uint8_t instance_id, |
| 156 | uint8_t completion_code, |
| 157 | struct pldm_msg *msg); |
| 158 | |
| 159 | /** @brief Decode SetStateEffecterStates request data |
| 160 | * |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame] | 161 | * @param[in] msg - Request message |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 162 | * @param[in] payload_length - Length of request message payload |
Sampa Misra | 0db1dfa | 2019-03-19 00:15:31 -0500 | [diff] [blame] | 163 | * @param[out] effecter_id - used to identify and access the effecter |
| 164 | * @param[out] comp_effecter_count - number of individual sets of effecter |
| 165 | * information. Upto eight sets of state effecter info can be accessed |
| 166 | * for a given effecter. |
| 167 | * @param[out] field - each unit is an instance of the stateFileld structure |
| 168 | * that is used to set the requested state for a particular effecter |
| 169 | * within the state effecter. This field holds the starting address of |
| 170 | * the stateField values. The user is responsible to allocate the |
| 171 | * memory prior to calling this command. Since the state field count is |
| 172 | * not known in advance, the user should allocate the maximum size |
| 173 | * always, which is 8 in number. |
| 174 | * @return pldm_completion_codes |
| 175 | */ |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 176 | |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame] | 177 | int decode_set_state_effecter_states_req(const struct pldm_msg *msg, |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 178 | size_t payload_length, |
Sampa Misra | 0db1dfa | 2019-03-19 00:15:31 -0500 | [diff] [blame] | 179 | uint16_t *effecter_id, |
| 180 | uint8_t *comp_effecter_count, |
| 181 | set_effecter_state_field *field); |
| 182 | |
Sampa Misra | 7fcfb66 | 2019-05-08 13:13:53 -0500 | [diff] [blame] | 183 | /* GetPDR */ |
| 184 | |
| 185 | /** @brief Create a PLDM response message for GetPDR |
| 186 | * |
| 187 | * @param[in] instance_id - Message's instance id |
| 188 | * @param[in] completion_code - PLDM completion code |
| 189 | * @param[in] next_record_hndl - The recordHandle for the PDR that is next in |
| 190 | * the PDR Repository |
| 191 | * @param[in] next_data_transfer_hndl - A handle that identifies the next |
| 192 | * portion of the PDR data to be transferred, if any |
| 193 | * @param[in] transfer_flag - Indicates the portion of PDR data being |
| 194 | * transferred |
| 195 | * @param[in] resp_cnt - The number of recordData bytes returned in this |
| 196 | * response |
| 197 | * @param[in] record_data - PDR data bytes of length resp_cnt |
| 198 | * @param[in] transfer_crc - A CRC-8 for the overall PDR. This is present only |
| 199 | * in the last part of a PDR being transferred |
| 200 | * @param[out] msg - Message will be written to this |
| 201 | * @return pldm_completion_codes |
| 202 | * @note Caller is responsible for memory alloc and dealloc of param |
| 203 | * 'msg.payload' |
| 204 | */ |
| 205 | int encode_get_pdr_resp(uint8_t instance_id, uint8_t completion_code, |
| 206 | uint32_t next_record_hndl, |
| 207 | uint32_t next_data_transfer_hndl, uint8_t transfer_flag, |
| 208 | uint16_t resp_cnt, const uint8_t *record_data, |
| 209 | uint8_t transfer_crc, struct pldm_msg *msg); |
| 210 | |
| 211 | /** @brief Decode GetPDR request data |
| 212 | * |
| 213 | * @param[in] msg - Request message |
| 214 | * @param[in] payload_length - Length of request message payload |
| 215 | * @param[out] record_hndl - The recordHandle value for the PDR to be retrieved |
| 216 | * @param[out] data_transfer_hndl - Handle used to identify a particular |
| 217 | * multipart PDR data transfer operation |
| 218 | * @param[out] transfer_op_flag - Flag to indicate the first or subsequent |
| 219 | * portion of transfer |
| 220 | * @param[out] request_cnt - The maximum number of record bytes requested |
| 221 | * @param[out] record_chg_num - Used to determine whether the PDR has changed |
| 222 | * while PDR transfer is going on |
| 223 | * @return pldm_completion_codes |
| 224 | */ |
| 225 | |
| 226 | int decode_get_pdr_req(const struct pldm_msg *msg, size_t payload_length, |
| 227 | uint32_t *record_hndl, uint32_t *data_transfer_hndl, |
| 228 | uint8_t *transfer_op_flag, uint16_t *request_cnt, |
| 229 | uint16_t *record_chg_num); |
| 230 | |
| 231 | /* Requester */ |
| 232 | |
| 233 | /* SetStateEffecterStates */ |
| 234 | |
vkaverap | 98a2c19 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 235 | /** @brief Create a PLDM request message for SetStateEffecterStates |
| 236 | * |
| 237 | * @param[in] instance_id - Message's instance id |
| 238 | * @param[in] effecter_id - used to identify and access the effecter |
| 239 | * @param[in] comp_effecter_count - number of individual sets of effecter |
| 240 | * information. Upto eight sets of state effecter info can be accessed |
| 241 | * for a given effecter. |
| 242 | * @param[in] field - each unit is an instance of the stateField structure |
| 243 | * that is used to set the requested state for a particular effecter |
| 244 | * within the state effecter. This field holds the starting address of |
| 245 | * the stateField values. The user is responsible to allocate the |
| 246 | * memory prior to calling this command. The user has to allocate the |
| 247 | * field parameter as sizeof(set_effecter_state_field) * |
| 248 | * comp_effecter_count |
| 249 | * @param[out] msg - Message will be written to this |
| 250 | * @return pldm_completion_codes |
| 251 | * @note Caller is responsible for memory alloc and dealloc of param |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 252 | * 'msg.payload' |
vkaverap | 98a2c19 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 253 | */ |
| 254 | |
| 255 | int encode_set_state_effecter_states_req(uint8_t instance_id, |
| 256 | uint16_t effecter_id, |
| 257 | uint8_t comp_effecter_count, |
| 258 | set_effecter_state_field *field, |
| 259 | struct pldm_msg *msg); |
| 260 | |
| 261 | /** @brief Decode SetStateEffecterStates response data |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame] | 262 | * @param[in] msg - Request message |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 263 | * @param[in] payload_length - Length of response message payload |
vkaverap | 98a2c19 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 264 | * @param[out] completion_code - PLDM completion code |
| 265 | * @return pldm_completion_codes |
| 266 | */ |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame] | 267 | int decode_set_state_effecter_states_resp(const struct pldm_msg *msg, |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 268 | size_t payload_length, |
vkaverap | 98a2c19 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 269 | uint8_t *completion_code); |
Sampa Misra | 0db1dfa | 2019-03-19 00:15:31 -0500 | [diff] [blame] | 270 | #ifdef __cplusplus |
| 271 | } |
| 272 | #endif |
| 273 | |
| 274 | #endif /* PLATFORM_H */ |