Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1 | #ifndef PDR_H |
| 2 | #define PDR_H |
| 3 | |
| 4 | #ifdef __cplusplus |
| 5 | extern "C" { |
| 6 | #endif |
| 7 | |
| 8 | #include <stdbool.h> |
| 9 | #include <stddef.h> |
| 10 | #include <stdint.h> |
| 11 | |
| 12 | /** @struct pldm_pdr |
| 13 | * opaque structure that acts as a handle to a PDR repository |
| 14 | */ |
| 15 | typedef struct pldm_pdr pldm_pdr; |
| 16 | |
| 17 | /** @struct pldm_pdr_record |
| 18 | * opaque structure that acts as a handle to a PDR record |
| 19 | */ |
| 20 | typedef struct pldm_pdr_record pldm_pdr_record; |
| 21 | |
| 22 | /* ====================== */ |
| 23 | /* Common PDR access APIs */ |
| 24 | /* ====================== */ |
| 25 | |
| 26 | /** @brief Make a new PDR repository |
| 27 | * |
| 28 | * @return opaque pointer that acts as a handle to the repository; NULL if no |
| 29 | * repository could be created |
| 30 | * |
| 31 | * @note Caller may make multiple repositories (for its own PDRs, as well as |
| 32 | * for PDRs received by other entities) and can associate the returned handle |
| 33 | * to a PLDM terminus id. |
| 34 | */ |
Andrew Jeffery | 319304f | 2023-04-05 13:53:18 +0930 | [diff] [blame] | 35 | pldm_pdr *pldm_pdr_init(void); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 36 | |
| 37 | /** @brief Destroy a PDR repository (and free up associated resources) |
| 38 | * |
| 39 | * @param[in/out] repo - pointer to opaque pointer acting as a PDR repo handle |
| 40 | */ |
| 41 | void pldm_pdr_destroy(pldm_pdr *repo); |
| 42 | |
| 43 | /** @brief Get number of records in a PDR repository |
| 44 | * |
Andrew Jeffery | 5565fcd | 2023-06-30 13:21:32 +0930 | [diff] [blame] | 45 | * @pre repo must point to a valid object |
| 46 | * |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 47 | * @param[in] repo - opaque pointer acting as a PDR repo handle |
| 48 | * |
| 49 | * @return uint32_t - number of records |
| 50 | */ |
| 51 | uint32_t pldm_pdr_get_record_count(const pldm_pdr *repo); |
| 52 | |
| 53 | /** @brief Get size of a PDR repository, in bytes |
| 54 | * |
Andrew Jeffery | 5565fcd | 2023-06-30 13:21:32 +0930 | [diff] [blame] | 55 | * @pre repo must point to a valid object |
| 56 | * |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 57 | * @param[in] repo - opaque pointer acting as a PDR repo handle |
| 58 | * |
| 59 | * @return uint32_t - size in bytes |
| 60 | */ |
| 61 | uint32_t pldm_pdr_get_repo_size(const pldm_pdr *repo); |
| 62 | |
Andrew Jeffery | 572a395 | 2023-07-03 13:19:28 +0930 | [diff] [blame] | 63 | /** @brief Add a PDR record to a PDR repository, or return an error |
| 64 | * |
| 65 | * @param[in/out] repo - opaque pointer acting as a PDR repo handle |
| 66 | * @param[in] data - pointer to a PDR record, pointing to a PDR definition as |
| 67 | * per DSP0248. This data is memcpy'd. |
| 68 | * @param[in] size - size of input PDR record in bytes |
| 69 | * @param[in] is_remote - if true, then the PDR is not from this terminus |
| 70 | * @param[in] terminus_handle - terminus handle of the input PDR record |
| 71 | * @param[in,out] record_handle - record handle of input PDR record. If this is set to 0 then a |
| 72 | * record handle is computed. The computed handle is assigned to both the PDR record and back into |
| 73 | * record_handle for the caller to consume. |
| 74 | * |
| 75 | * @return 0 on success, -EINVAL if the arguments are invalid, -ENOMEM if an internal memory |
| 76 | * allocation fails, or -EOVERFLOW if a record handle could not be allocated |
| 77 | */ |
| 78 | int pldm_pdr_add_check(pldm_pdr *repo, const uint8_t *data, uint32_t size, |
| 79 | bool is_remote, uint16_t terminus_handle, |
| 80 | uint32_t *record_handle); |
| 81 | |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 82 | /** @brief Get record handle of a PDR record |
| 83 | * |
Andrew Jeffery | 5565fcd | 2023-06-30 13:21:32 +0930 | [diff] [blame] | 84 | * @pre repo must point to a valid object |
| 85 | * @pre record must point to a valid object |
| 86 | * |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 87 | * @param[in] repo - opaque pointer acting as a PDR repo handle |
| 88 | * @param[in] record - opaque pointer acting as a PDR record handle |
| 89 | * |
| 90 | * @return uint32_t - record handle assigned to PDR record; 0 if record is not |
| 91 | * found |
| 92 | */ |
| 93 | uint32_t pldm_pdr_get_record_handle(const pldm_pdr *repo, |
| 94 | const pldm_pdr_record *record); |
| 95 | |
| 96 | /** @brief Find PDR record by record handle |
| 97 | * |
| 98 | * @param[in] repo - opaque pointer acting as a PDR repo handle |
| 99 | * @param[in] record_handle - input record handle |
| 100 | * @param[in/out] data - will point to PDR record data (as per DSP0248) on |
| 101 | * return |
| 102 | * @param[out] size - *size will be size of PDR record |
| 103 | * @param[out] next_record_handle - *next_record_handle will be the record |
| 104 | * handle of record next to the returned PDR record |
| 105 | * |
| 106 | * @return opaque pointer acting as PDR record handle, will be NULL if record |
| 107 | * was not found |
| 108 | */ |
| 109 | const pldm_pdr_record *pldm_pdr_find_record(const pldm_pdr *repo, |
| 110 | uint32_t record_handle, |
| 111 | uint8_t **data, uint32_t *size, |
| 112 | uint32_t *next_record_handle); |
| 113 | |
| 114 | /** @brief Get PDR record next to input PDR record |
| 115 | * |
| 116 | * @param[in] repo - opaque pointer acting as a PDR repo handle |
| 117 | * @param[in] curr_record - opaque pointer acting as a PDR record handle |
| 118 | * @param[in/out] data - will point to PDR record data (as per DSP0248) on |
| 119 | * return |
| 120 | * @param[out] size - *size will be size of PDR record |
| 121 | * @param[out] next_record_handle - *next_record_handle will be the record |
| 122 | * handle of record nect to the returned PDR record |
| 123 | * |
| 124 | * @return opaque pointer acting as PDR record handle, will be NULL if record |
| 125 | * was not found |
| 126 | */ |
| 127 | const pldm_pdr_record * |
| 128 | pldm_pdr_get_next_record(const pldm_pdr *repo, |
| 129 | const pldm_pdr_record *curr_record, uint8_t **data, |
| 130 | uint32_t *size, uint32_t *next_record_handle); |
| 131 | |
| 132 | /** @brief Find (first) PDR record by PDR type |
| 133 | * |
| 134 | * @param[in] repo - opaque pointer acting as a PDR repo handle |
| 135 | * @param[in] pdr_type - PDR type number as per DSP0248 |
| 136 | * @param[in] curr_record - opaque pointer acting as a PDR record handle; if |
| 137 | * not NULL, then search will begin from this record's next record |
| 138 | * @param[in/out] data - will point to PDR record data (as per DSP0248) on |
| 139 | * return, if input is not NULL |
| 140 | * @param[out] size - *size will be size of PDR record, if input is not NULL |
| 141 | * |
| 142 | * @return opaque pointer acting as PDR record handle, will be NULL if record |
| 143 | * was not found |
| 144 | */ |
| 145 | const pldm_pdr_record * |
| 146 | pldm_pdr_find_record_by_type(const pldm_pdr *repo, uint8_t pdr_type, |
| 147 | const pldm_pdr_record *curr_record, uint8_t **data, |
| 148 | uint32_t *size); |
| 149 | |
Andrew Jeffery | 5565fcd | 2023-06-30 13:21:32 +0930 | [diff] [blame] | 150 | /** @brief Determine if a record is a remote record |
| 151 | * |
| 152 | * @pre record must point to a valid object |
| 153 | * |
| 154 | * @return true if the record is a remote record, false otherwise. |
| 155 | */ |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 156 | bool pldm_pdr_record_is_remote(const pldm_pdr_record *record); |
| 157 | |
| 158 | /** @brief Remove all PDR records that belong to a remote terminus |
| 159 | * |
| 160 | * @param[in] repo - opaque pointer acting as a PDR repo handle |
Andrew Jeffery | 3e1d659 | 2023-07-03 11:57:16 +0930 | [diff] [blame] | 161 | * |
| 162 | * If repo is NULL then there are no PDRs that can be removed. |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 163 | */ |
| 164 | void pldm_pdr_remove_remote_pdrs(pldm_pdr *repo); |
| 165 | |
| 166 | /** @brief Remove all remote PDR's that beling to a specific terminus |
| 167 | * handle |
| 168 | * @param[in] repo - opaque pointer acting as a PDR repo handle |
| 169 | * @param[in] terminus_handle - Terminus Handle of the remove PLDM terminus |
Andrew Jeffery | 438dd49 | 2023-07-03 11:51:43 +0930 | [diff] [blame] | 170 | * |
| 171 | * If repo is NULL there are no PDRs that can be removed. |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 172 | */ |
| 173 | void pldm_pdr_remove_pdrs_by_terminus_handle(pldm_pdr *repo, |
| 174 | uint16_t terminus_handle); |
| 175 | |
| 176 | /** @brief Update the validity of TL PDR - the validity is decided based on |
| 177 | * whether the valid bit is set or not as per the spec DSP0248 |
| 178 | * |
| 179 | * @param[in] repo - opaque pointer acting as a PDR repo handle |
Andrew Jeffery | 6005f1c | 2023-04-05 20:02:52 +0930 | [diff] [blame] | 180 | * @param[in] terminus_handle - PLDM terminus handle |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 181 | * @param[in] tid - Terminus ID |
Andrew Jeffery | 2a38ab5 | 2023-04-06 15:09:08 +0930 | [diff] [blame] | 182 | * @param[in] tl_eid - MCTP endpoint EID |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 183 | * @param[in] valid - validity bit of TLPDR |
| 184 | */ |
Andrew Jeffery | 6005f1c | 2023-04-05 20:02:52 +0930 | [diff] [blame] | 185 | /* NOLINTNEXTLINE(readability-identifier-naming) */ |
| 186 | void pldm_pdr_update_TL_pdr(const pldm_pdr *repo, uint16_t terminus_handle, |
| 187 | uint8_t tid, uint8_t tl_eid, bool valid); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 188 | |
Pavithra Barithaya | 4d69434 | 2023-05-19 08:04:41 -0500 | [diff] [blame] | 189 | /** @brief Find the last record within the particular range |
| 190 | * of record handles |
| 191 | * |
| 192 | * @param[in] repo - pointer acting as a PDR repo handle |
| 193 | * @param[in] first - first record handle value of the records in the range |
| 194 | * @param[in] last - last record handle value of the records in the range |
| 195 | * |
| 196 | * @return pointer to the PDR record,will be NULL if record was not |
| 197 | * found |
| 198 | */ |
| 199 | pldm_pdr_record *pldm_pdr_find_last_in_range(const pldm_pdr *repo, |
| 200 | uint32_t first, uint32_t last); |
| 201 | |
Pavithra Barithaya | 5dc0257 | 2023-05-19 09:24:36 -0500 | [diff] [blame] | 202 | /** @brief find the container ID of the contained entity which is not in the |
| 203 | * particular range of record handles given |
| 204 | * |
| 205 | * @param[in] repo - opaque pointer acting as a PDR repo handle |
| 206 | * @param[in] entity_type - entity type |
| 207 | * @param[in] entity_instance - instance of the entity |
Pavithra Barithaya | 8cf7045 | 2023-06-22 04:36:19 -0500 | [diff] [blame] | 208 | * @param[in] child_index - index of the child entity whose container id needs to be found |
Pavithra Barithaya | 5dc0257 | 2023-05-19 09:24:36 -0500 | [diff] [blame] | 209 | * @param[in] range_exclude_start_handle - first record handle in the range of the remote endpoint |
Pavithra Barithaya | 8cf7045 | 2023-06-22 04:36:19 -0500 | [diff] [blame] | 210 | * which is ignored |
Pavithra Barithaya | 5dc0257 | 2023-05-19 09:24:36 -0500 | [diff] [blame] | 211 | * @param[in] range_exclude_end_handle - last record handle in the range of the remote endpoint |
Pavithra Barithaya | 8cf7045 | 2023-06-22 04:36:19 -0500 | [diff] [blame] | 212 | * which is ignored |
Pavithra Barithaya | 5dc0257 | 2023-05-19 09:24:36 -0500 | [diff] [blame] | 213 | * @param[out] container_id - container id of the contained entity |
| 214 | * |
Pavithra Barithaya | 8cf7045 | 2023-06-22 04:36:19 -0500 | [diff] [blame] | 215 | * @return container id of the PDR record found on success,-EINVAL when repo is NULL |
| 216 | * or -ENOKEY if the container id is not found. |
Pavithra Barithaya | 5dc0257 | 2023-05-19 09:24:36 -0500 | [diff] [blame] | 217 | */ |
Pavithra Barithaya | 8cf7045 | 2023-06-22 04:36:19 -0500 | [diff] [blame] | 218 | int pldm_pdr_find_child_container_id_index_range_exclude( |
Pavithra Barithaya | 5dc0257 | 2023-05-19 09:24:36 -0500 | [diff] [blame] | 219 | const pldm_pdr *repo, uint16_t entity_type, uint16_t entity_instance, |
Pavithra Barithaya | 8cf7045 | 2023-06-22 04:36:19 -0500 | [diff] [blame] | 220 | uint8_t child_index, uint32_t range_exclude_start_handle, |
| 221 | uint32_t range_exclude_end_handle, uint16_t *container_id); |
Pavithra Barithaya | 5dc0257 | 2023-05-19 09:24:36 -0500 | [diff] [blame] | 222 | |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 223 | /* ======================= */ |
| 224 | /* FRU Record Set PDR APIs */ |
| 225 | /* ======================= */ |
| 226 | |
Andrew Jeffery | c821a70 | 2023-07-03 13:32:11 +0930 | [diff] [blame] | 227 | /** @brief Add a FRU record set PDR record to a PDR repository, or return an error |
| 228 | * |
| 229 | * @param[in/out] repo - opaque pointer acting as a PDR repo handle |
| 230 | * @param[in] terminus_handle - PLDM terminus handle of terminus owning the PDR |
| 231 | * record |
| 232 | * @param[in] fru_rsi - FRU record set identifier |
| 233 | * @param[in] entity_type - entity type of FRU |
| 234 | * @param[in] entity_instance_num - entity instance number of FRU |
| 235 | * @param[in] container_id - container id of FRU |
| 236 | * @param[in,out] bmc_record_handle - A pointer to the handle used to construct the next record. If |
| 237 | * the value is zero on input then a new handle is automatically allocated. |
| 238 | * Otherwise, the provided handle is used. If a new handle is automatically |
| 239 | * allocated then the object pointed to by bmc_record_handle will contain its value |
| 240 | * as output. |
| 241 | * @return 0 on success, -EINVAL if the arguments are invalid, or -ENOMEM if an internal allocation |
| 242 | * fails. |
| 243 | */ |
| 244 | int pldm_pdr_add_fru_record_set_check(pldm_pdr *repo, uint16_t terminus_handle, |
| 245 | uint16_t fru_rsi, uint16_t entity_type, |
| 246 | uint16_t entity_instance_num, |
| 247 | uint16_t container_id, |
| 248 | uint32_t *bmc_record_handle); |
| 249 | |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 250 | /** @brief Find a FRU record set PDR by FRU record set identifier |
| 251 | * |
| 252 | * @param[in] repo - opaque pointer acting as a PDR repo handle |
| 253 | * @param[in] fru_rsi - FRU record set identifier |
| 254 | * @param[in] terminus_handle - *terminus_handle will be FRU terminus handle of |
| 255 | * found PDR, or 0 if not found |
| 256 | * @param[in] entity_type - *entity_type will be FRU entity type of found PDR, |
| 257 | * or 0 if not found |
| 258 | * @param[in] entity_instance_num - *entity_instance_num will be FRU entity |
| 259 | * instance number of found PDR, or 0 if not found |
| 260 | * @param[in] container_id - *cintainer_id will be FRU container id of found |
| 261 | * PDR, or 0 if not found |
| 262 | * |
Andrew Jeffery | af7a4d8 | 2023-06-30 13:46:32 +0930 | [diff] [blame] | 263 | * @return An opaque pointer to the PDR record on success, or NULL on failure |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 264 | */ |
| 265 | const pldm_pdr_record *pldm_pdr_fru_record_set_find_by_rsi( |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 266 | const pldm_pdr *repo, uint16_t fru_rsi, uint16_t *terminus_handle, |
| 267 | uint16_t *entity_type, uint16_t *entity_instance_num, |
| 268 | uint16_t *container_id); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 269 | |
| 270 | /* =========================== */ |
| 271 | /* Entity Association PDR APIs */ |
| 272 | /* =========================== */ |
| 273 | |
| 274 | typedef struct pldm_entity { |
| 275 | uint16_t entity_type; |
| 276 | uint16_t entity_instance_num; |
| 277 | uint16_t entity_container_id; |
| 278 | } __attribute__((packed)) pldm_entity; |
| 279 | |
| 280 | enum entity_association_containment_type { |
| 281 | PLDM_ENTITY_ASSOCIAION_PHYSICAL = 0x0, |
| 282 | PLDM_ENTITY_ASSOCIAION_LOGICAL = 0x1, |
| 283 | }; |
| 284 | |
| 285 | /** @struct pldm_entity_association_tree |
| 286 | * opaque structure that represents the entity association hierarchy |
| 287 | */ |
| 288 | typedef struct pldm_entity_association_tree pldm_entity_association_tree; |
| 289 | |
| 290 | /** @struct pldm_entity_node |
| 291 | * opaque structure that represents a node in the entity association hierarchy |
| 292 | */ |
| 293 | typedef struct pldm_entity_node pldm_entity_node; |
| 294 | |
| 295 | /** @brief Make a new entity association tree |
| 296 | * |
| 297 | * @return opaque pointer that acts as a handle to the tree; NULL if no |
| 298 | * tree could be created |
| 299 | */ |
Andrew Jeffery | 319304f | 2023-04-05 13:53:18 +0930 | [diff] [blame] | 300 | pldm_entity_association_tree *pldm_entity_association_tree_init(void); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 301 | |
Pavithra Barithaya | 9947f9d | 2023-05-18 05:20:24 -0500 | [diff] [blame] | 302 | /** @brief Add a local entity into the entity association tree |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 303 | * |
| 304 | * @param[in/out] tree - opaque pointer acting as a handle to the tree |
| 305 | * @param[in/out] entity - pointer to the entity to be added. Input has the |
| 306 | * entity type. On output, instance number and the |
| 307 | * container id are populated. |
| 308 | * @param[in] entity_instance_number - entity instance number, we can use the |
| 309 | * entity instance number of the entity by |
| 310 | * default if its value is equal 0xFFFF. |
| 311 | * @param[in] parent - pointer to the node that should be the parent of input |
| 312 | * entity. If this is NULL, then the entity is the root |
| 313 | * @param[in] association_type - relation with the parent : logical or physical |
| 314 | * |
| 315 | * @return pldm_entity_node* - opaque pointer to added entity |
| 316 | */ |
| 317 | pldm_entity_node *pldm_entity_association_tree_add( |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 318 | pldm_entity_association_tree *tree, pldm_entity *entity, |
| 319 | uint16_t entity_instance_number, pldm_entity_node *parent, |
| 320 | uint8_t association_type); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 321 | |
Pavithra Barithaya | 9947f9d | 2023-05-18 05:20:24 -0500 | [diff] [blame] | 322 | /** @brief Add an entity into the entity association tree based on remote field |
| 323 | * set or unset. |
| 324 | * |
| 325 | * @param[in/out] tree - opaque pointer acting as a handle to the tree |
| 326 | * @param[in/out] entity - pointer to the entity to be added. Input has the |
| 327 | * entity type. On output, instance number and the |
| 328 | * container id are populated. |
| 329 | * @param[in] entity_instance_number - entity instance number, we can use the |
| 330 | * entity instance number of the entity by |
| 331 | * default if its value is equal 0xFFFF. |
| 332 | * @param[in] parent - pointer to the node that should be the parent of input |
| 333 | * entity. If this is NULL, then the entity is the root |
| 334 | * @param[in] association_type - relation with the parent : logical or physical |
| 335 | * @param[in] is_remote - used to denote whether we are adding a BMC entity to |
| 336 | * the tree or a host entity |
| 337 | * @param[in] is_update_contanier_id - Used to determine whether need to update |
| 338 | * contanier id. |
| 339 | * true: should be changed |
| 340 | * false: should not be changed |
| 341 | * @param[in] container_id - container id of the entity added. |
| 342 | * |
| 343 | * @return pldm_entity_node* - opaque pointer to added entity |
| 344 | */ |
| 345 | pldm_entity_node *pldm_entity_association_tree_add_entity( |
| 346 | pldm_entity_association_tree *tree, pldm_entity *entity, |
| 347 | uint16_t entity_instance_number, pldm_entity_node *parent, |
| 348 | uint8_t association_type, bool is_remote, bool is_update_container_id, |
| 349 | uint16_t container_id); |
| 350 | |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 351 | /** @brief Visit and note each entity in the entity association tree |
| 352 | * |
Andrew Jeffery | 8e9b0de | 2023-06-30 14:05:04 +0930 | [diff] [blame] | 353 | * @pre `*entities == NULL` and `*size == 0` must hold at the time of invocation. |
| 354 | * |
| 355 | * Callers must inspect the values of `*entities` and `*size` post-invocation to determine if the |
| 356 | * invocation was a success or failure. |
| 357 | * |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 358 | * @param[in] tree - opaque pointer acting as a handle to the tree |
| 359 | * @param[out] entities - pointer to list of pldm_entity's. To be free()'d by |
| 360 | * the caller |
| 361 | * @param[out] size - number of pldm_entity's |
| 362 | */ |
| 363 | void pldm_entity_association_tree_visit(pldm_entity_association_tree *tree, |
| 364 | pldm_entity **entities, size_t *size); |
| 365 | |
| 366 | /** @brief Extract pldm entity by the pldm_entity_node |
| 367 | * |
Andrew Jeffery | 5565fcd | 2023-06-30 13:21:32 +0930 | [diff] [blame] | 368 | * @pre node must point to a valid object |
| 369 | * |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 370 | * @param[in] node - opaque pointer to added entity |
| 371 | * |
| 372 | * @return pldm_entity - pldm entity |
| 373 | */ |
| 374 | pldm_entity pldm_entity_extract(pldm_entity_node *node); |
| 375 | |
ArchanaKakani | 39bd2ea | 2023-02-02 02:39:18 -0600 | [diff] [blame] | 376 | /** @brief Extract remote container id from the pldm_entity_node |
| 377 | * |
Andrew Jeffery | 15b8818 | 2023-06-30 13:29:17 +0930 | [diff] [blame] | 378 | * @pre entity must point to a valid object |
ArchanaKakani | 39bd2ea | 2023-02-02 02:39:18 -0600 | [diff] [blame] | 379 | * |
Andrew Jeffery | 15b8818 | 2023-06-30 13:29:17 +0930 | [diff] [blame] | 380 | * @param[in] entity - pointer to existing entity |
| 381 | * |
| 382 | * @return The remote container id |
ArchanaKakani | 39bd2ea | 2023-02-02 02:39:18 -0600 | [diff] [blame] | 383 | */ |
Andrew Jeffery | 15b8818 | 2023-06-30 13:29:17 +0930 | [diff] [blame] | 384 | uint16_t |
| 385 | pldm_entity_node_get_remote_container_id(const pldm_entity_node *entity); |
ArchanaKakani | 39bd2ea | 2023-02-02 02:39:18 -0600 | [diff] [blame] | 386 | |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 387 | /** @brief Destroy entity association tree |
| 388 | * |
| 389 | * @param[in] tree - opaque pointer acting as a handle to the tree |
| 390 | */ |
| 391 | void pldm_entity_association_tree_destroy(pldm_entity_association_tree *tree); |
| 392 | |
| 393 | /** @brief Check if input enity node is a parent |
| 394 | * |
Andrew Jeffery | 5565fcd | 2023-06-30 13:21:32 +0930 | [diff] [blame] | 395 | * @pre node must point to a valid object |
| 396 | * |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 397 | * @param[in] node - opaque pointer acting as a handle to an entity node |
| 398 | * |
| 399 | * @return bool true if node is a parent, false otherwise |
| 400 | */ |
| 401 | bool pldm_entity_is_node_parent(pldm_entity_node *node); |
| 402 | |
| 403 | /** @brief Get parent of entity |
| 404 | * |
Andrew Jeffery | 5565fcd | 2023-06-30 13:21:32 +0930 | [diff] [blame] | 405 | * @pre node must point to a valid object |
| 406 | * |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 407 | * @param[in] node - opaque pointer acting as a handle to an entity node |
| 408 | * |
| 409 | * @return pldm_entity - pldm entity |
| 410 | */ |
| 411 | pldm_entity pldm_entity_get_parent(pldm_entity_node *node); |
| 412 | |
| 413 | /** @brief Check the current pldm entity is exist parent |
| 414 | * |
Andrew Jeffery | 5565fcd | 2023-06-30 13:21:32 +0930 | [diff] [blame] | 415 | * @pre node must point to a valid object |
| 416 | * |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 417 | * @param[in] node - opaque pointer acting as a handle to an entity node |
| 418 | * |
| 419 | * @return bool true if exist parent, false otherwise |
| 420 | */ |
| 421 | bool pldm_entity_is_exist_parent(pldm_entity_node *node); |
| 422 | |
| 423 | /** @brief Convert entity association tree to PDR |
| 424 | * |
Andrew Jeffery | c788348 | 2023-06-30 15:52:04 +0930 | [diff] [blame] | 425 | * No conversion takes place if one or both of tree or repo are NULL. |
| 426 | * |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 427 | * @param[in] tree - opaque pointer to entity association tree |
| 428 | * @param[in] repo - PDR repo where entity association records should be added |
| 429 | * @param[in] is_remote - if true, then the PDR is not from this terminus |
| 430 | * @param[in] terminus_handle - terminus handle of the terminus |
| 431 | */ |
| 432 | void pldm_entity_association_pdr_add(pldm_entity_association_tree *tree, |
| 433 | pldm_pdr *repo, bool is_remote, |
| 434 | uint16_t terminus_handle); |
Andrew Jeffery | cc39452 | 2023-07-03 12:49:31 +0930 | [diff] [blame] | 435 | |
Andrew Jeffery | 6594599 | 2023-07-17 15:04:21 +0930 | [diff] [blame] | 436 | /** @brief Convert entity association tree to PDR, or return an error |
| 437 | * |
| 438 | * No conversion takes place if one or both of tree or repo are NULL. |
| 439 | * |
| 440 | * If an error is returned then the state and consistency of the PDR repository is undefined. |
| 441 | * |
| 442 | * @param[in] tree - opaque pointer to entity association tree |
| 443 | * @param[in] repo - PDR repo where entity association records should be added |
| 444 | * @param[in] is_remote - if true, then the PDR is not from this terminus |
| 445 | * @param[in] terminus_handle - terminus handle of the terminus |
| 446 | * |
| 447 | * @return 0 on success, -EINVAL if the arguments are invalid, -ENOMEM if an internal memory |
| 448 | * allocation fails, or -EOVERFLOW if a record handle could not be allocated |
| 449 | */ |
| 450 | int pldm_entity_association_pdr_add_check(pldm_entity_association_tree *tree, |
| 451 | pldm_pdr *repo, bool is_remote, |
| 452 | uint16_t terminus_handle); |
| 453 | |
Andrew Jeffery | cc39452 | 2023-07-03 12:49:31 +0930 | [diff] [blame] | 454 | /** @brief Add entity association pdr from node, or return an error |
| 455 | * |
| 456 | * @param[in] node - opaque pointer acting as a handle to an entity node |
| 457 | * @param[in] repo - PDR repo where entity association records should be added |
| 458 | * @param[in] is_remote - if true, then the PDR is not from this terminus |
| 459 | * @param[in] terminus_handle - terminus handle of the terminus |
| 460 | * |
| 461 | * @return 0 on success, -EINVAL if the provided arguments are invalid. |
| 462 | */ |
| 463 | int pldm_entity_association_pdr_add_from_node_check( |
| 464 | pldm_entity_node *node, pldm_pdr *repo, pldm_entity **entities, |
| 465 | size_t num_entities, bool is_remote, uint16_t terminus_handle); |
| 466 | |
Pavithra Barithaya | 25ddbcc | 2023-05-19 08:28:59 -0500 | [diff] [blame] | 467 | /** @brief Add entity association pdr record based on record handle |
| 468 | * earlier the records where added in a sequential way alone, with |
| 469 | * this change the entity association PDR records gets the new record |
| 470 | * handle based on the input value given. |
| 471 | * |
| 472 | * @param[in] node - opaque pointer acting as a handle to an entity node |
| 473 | * @param[in] repo - PDR repo where entity association records should be added |
| 474 | * @param[in] is_remote - if true, then the PDR is not from this terminus |
| 475 | * @param[in] terminus_handle - terminus handle of the terminus |
| 476 | * @param[in] record_handle - record handle of the PDR |
| 477 | * |
| 478 | * @return 0 on succes, -EINVAL if the provided arguments are invalid. |
| 479 | */ |
| 480 | int pldm_entity_association_pdr_add_from_node_with_record_handle( |
| 481 | pldm_entity_node *node, pldm_pdr *repo, pldm_entity **entities, |
| 482 | size_t num_entities, bool is_remote, uint16_t terminus_handle, |
| 483 | uint32_t record_handle); |
| 484 | |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 485 | /** @brief Find entity reference in tree |
| 486 | * |
| 487 | * @param[in] tree - opaque pointer to entity association tree |
| 488 | * @param[in] entity - PLDM entity |
| 489 | * @param[in] node - node to the entity |
| 490 | */ |
| 491 | void pldm_find_entity_ref_in_tree(pldm_entity_association_tree *tree, |
| 492 | pldm_entity entity, pldm_entity_node **node); |
| 493 | |
| 494 | /** @brief Get number of children of entity |
| 495 | * |
| 496 | * @param[in] node - opaque pointer acting as a handle to an entity node |
| 497 | * @param[in] association_type - relation type filter : logical or physical |
| 498 | * |
Andrew Jeffery | 6e8a261 | 2023-06-30 15:36:48 +0930 | [diff] [blame] | 499 | * @return uint8_t number of children. The returned value is zero if node is NULL or |
| 500 | * association_type is not one of PLDM_ENTITY_ASSOCIAION_PHYSICAL or |
| 501 | * PLDM_ENTITY_ASSOCIAION_LOGICAL. |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 502 | */ |
| 503 | uint8_t pldm_entity_get_num_children(pldm_entity_node *node, |
| 504 | uint8_t association_type); |
| 505 | |
| 506 | /** @brief Verify that the current node is a child of the current parent |
| 507 | * |
Andrew Jeffery | 5565fcd | 2023-06-30 13:21:32 +0930 | [diff] [blame] | 508 | * @pre parent must point to a valid object |
| 509 | * @pre node must point to a valid object |
| 510 | * |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 511 | * @param[in] parent - opaque pointer acting as a handle to an entity parent |
| 512 | * @param[in] node - pointer to the node of the pldm entity |
Andrew Jeffery | 375d9fc | 2023-06-30 15:45:54 +0930 | [diff] [blame] | 513 | * |
| 514 | * @return True if the node is a child of parent, false otherwise, including if one or both of |
| 515 | * parent or node are NULL. |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 516 | */ |
| 517 | bool pldm_is_current_parent_child(pldm_entity_node *parent, pldm_entity *node); |
| 518 | |
| 519 | /** @brief Find an entity in the entity association tree |
| 520 | * |
| 521 | * @param[in] tree - pointer to entity association tree |
| 522 | * @param[in/out] entity - entity type and instance id set on input, container |
| 523 | * id set on output |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 524 | * @return pldm_entity_node* pointer to entity if found, NULL otherwise |
Andrew Jeffery | 94e364d | 2023-07-03 12:26:59 +0930 | [diff] [blame] | 525 | * |
| 526 | * There are no entity nodes to search if tree is NULL, nor are there entity nodes to find if the |
| 527 | * search criteria are unspecified when entity is NULL. |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 528 | */ |
| 529 | pldm_entity_node * |
| 530 | pldm_entity_association_tree_find(pldm_entity_association_tree *tree, |
| 531 | pldm_entity *entity); |
| 532 | |
Sagar Srinivas | 302d9ff | 2023-08-01 02:11:30 -0500 | [diff] [blame] | 533 | /** @brief Find an entity in the entity association tree with locality specified, |
| 534 | * ie - remote entity or local entity |
Pavithra Barithaya | 9947f9d | 2023-05-18 05:20:24 -0500 | [diff] [blame] | 535 | * |
| 536 | * @param[in] tree - pointer to entity association tree |
| 537 | * @param[in/out] entity - entity type and instance id set on input, container |
| 538 | * id set on output |
Sagar Srinivas | 302d9ff | 2023-08-01 02:11:30 -0500 | [diff] [blame] | 539 | * @param[in] is_remote - variable to denote whether we are finding a remote |
| 540 | * entity or a local entity |
Pavithra Barithaya | 9947f9d | 2023-05-18 05:20:24 -0500 | [diff] [blame] | 541 | * |
| 542 | * @return pldm_entity_node* pointer to entity if found, NULL otherwise |
| 543 | */ |
Sagar Srinivas | 302d9ff | 2023-08-01 02:11:30 -0500 | [diff] [blame] | 544 | pldm_entity_node *pldm_entity_association_tree_find_with_locality( |
| 545 | pldm_entity_association_tree *tree, pldm_entity *entity, |
| 546 | bool is_remote); |
Pavithra Barithaya | 9947f9d | 2023-05-18 05:20:24 -0500 | [diff] [blame] | 547 | |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 548 | /** @brief Create a copy of an existing entity association tree |
| 549 | * |
| 550 | * @param[in] org_tree - pointer to source tree |
| 551 | * @param[in/out] new_tree - pointer to destination tree |
| 552 | */ |
| 553 | void pldm_entity_association_tree_copy_root( |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 554 | pldm_entity_association_tree *org_tree, |
| 555 | pldm_entity_association_tree *new_tree); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 556 | |
| 557 | /** @brief Destroy all the nodes of the entity association tree |
| 558 | * |
| 559 | * @param[in] tree - pointer to entity association tree |
Andrew Jeffery | 85d7a05 | 2023-07-03 12:29:24 +0930 | [diff] [blame] | 560 | * |
| 561 | * There is no tree to destroy if tree is NULL. |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 562 | */ |
| 563 | void pldm_entity_association_tree_destroy_root( |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 564 | pldm_entity_association_tree *tree); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 565 | |
| 566 | /** @brief Check whether the entity association tree is empty |
| 567 | * |
Andrew Jeffery | 5565fcd | 2023-06-30 13:21:32 +0930 | [diff] [blame] | 568 | * @pre tree must point to a valid object |
| 569 | * |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 570 | * @param[in] tree - pointer to entity association tree |
| 571 | * @return bool, true if tree is empty |
| 572 | */ |
| 573 | bool pldm_is_empty_entity_assoc_tree(pldm_entity_association_tree *tree); |
| 574 | |
| 575 | /** @brief Extract entities from entity association PDR |
| 576 | * |
Andrew Jeffery | 3a5c46b | 2023-07-03 12:39:59 +0930 | [diff] [blame] | 577 | * @pre `*entities == NULL` and `*num_entities == 0` must hold at the time of invocation. |
| 578 | * |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 579 | * @param[in] pdr - entity association PDR |
| 580 | * @param[in] pdr_len - size of entity association PDR in bytes |
| 581 | * @param[out] num_entities - number of entities found, including the container |
| 582 | * @param[out] entities - extracted entities, container is *entities[0]. Caller |
| 583 | * must free *entities |
| 584 | */ |
| 585 | void pldm_entity_association_pdr_extract(const uint8_t *pdr, uint16_t pdr_len, |
| 586 | size_t *num_entities, |
| 587 | pldm_entity **entities); |
| 588 | |
| 589 | #ifdef __cplusplus |
| 590 | } |
| 591 | #endif |
| 592 | |
| 593 | #endif /* PDR_H */ |