blob: 811270301035a816f20742414cacbcc5853cc08e [file] [log] [blame]
Andrew Jeffery9c766792022-08-10 23:12:49 +09301#ifndef PDR_H
2#define PDR_H
3
4#ifdef __cplusplus
5extern "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 */
15typedef struct pldm_pdr pldm_pdr;
16
17/** @struct pldm_pdr_record
18 * opaque structure that acts as a handle to a PDR record
19 */
20typedef 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 Jeffery319304f2023-04-05 13:53:18 +093035pldm_pdr *pldm_pdr_init(void);
Andrew Jeffery9c766792022-08-10 23:12:49 +093036
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 */
41void pldm_pdr_destroy(pldm_pdr *repo);
42
43/** @brief Get number of records in a PDR repository
44 *
Andrew Jeffery5565fcd2023-06-30 13:21:32 +093045 * @pre repo must point to a valid object
46 *
Andrew Jeffery9c766792022-08-10 23:12:49 +093047 * @param[in] repo - opaque pointer acting as a PDR repo handle
48 *
49 * @return uint32_t - number of records
50 */
51uint32_t pldm_pdr_get_record_count(const pldm_pdr *repo);
52
53/** @brief Get size of a PDR repository, in bytes
54 *
Andrew Jeffery5565fcd2023-06-30 13:21:32 +093055 * @pre repo must point to a valid object
56 *
Andrew Jeffery9c766792022-08-10 23:12:49 +093057 * @param[in] repo - opaque pointer acting as a PDR repo handle
58 *
59 * @return uint32_t - size in bytes
60 */
61uint32_t pldm_pdr_get_repo_size(const pldm_pdr *repo);
62
63/** @brief Add a PDR record to a PDR repository
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] record_handle - record handle of input PDR record; if this is set
70 * to 0, then a record handle is computed and assigned to this PDR record
71 * @param[in] is_remote - if true, then the PDR is not from this terminus
72 * @param[in] terminus_handle - terminus handle of the input PDR record
73 *
74 * @return uint32_t - record handle assigned to PDR record
75 */
76uint32_t pldm_pdr_add(pldm_pdr *repo, const uint8_t *data, uint32_t size,
77 uint32_t record_handle, bool is_remote,
78 uint16_t terminus_handle);
79
80/** @brief Get record handle of a PDR record
81 *
Andrew Jeffery5565fcd2023-06-30 13:21:32 +093082 * @pre repo must point to a valid object
83 * @pre record must point to a valid object
84 *
Andrew Jeffery9c766792022-08-10 23:12:49 +093085 * @param[in] repo - opaque pointer acting as a PDR repo handle
86 * @param[in] record - opaque pointer acting as a PDR record handle
87 *
88 * @return uint32_t - record handle assigned to PDR record; 0 if record is not
89 * found
90 */
91uint32_t pldm_pdr_get_record_handle(const pldm_pdr *repo,
92 const pldm_pdr_record *record);
93
94/** @brief Find PDR record by record handle
95 *
96 * @param[in] repo - opaque pointer acting as a PDR repo handle
97 * @param[in] record_handle - input record handle
98 * @param[in/out] data - will point to PDR record data (as per DSP0248) on
99 * return
100 * @param[out] size - *size will be size of PDR record
101 * @param[out] next_record_handle - *next_record_handle will be the record
102 * handle of record next to the returned PDR record
103 *
104 * @return opaque pointer acting as PDR record handle, will be NULL if record
105 * was not found
106 */
107const pldm_pdr_record *pldm_pdr_find_record(const pldm_pdr *repo,
108 uint32_t record_handle,
109 uint8_t **data, uint32_t *size,
110 uint32_t *next_record_handle);
111
112/** @brief Get PDR record next to input PDR record
113 *
114 * @param[in] repo - opaque pointer acting as a PDR repo handle
115 * @param[in] curr_record - opaque pointer acting as a PDR record handle
116 * @param[in/out] data - will point to PDR record data (as per DSP0248) on
117 * return
118 * @param[out] size - *size will be size of PDR record
119 * @param[out] next_record_handle - *next_record_handle will be the record
120 * handle of record nect to the returned PDR record
121 *
122 * @return opaque pointer acting as PDR record handle, will be NULL if record
123 * was not found
124 */
125const pldm_pdr_record *
126pldm_pdr_get_next_record(const pldm_pdr *repo,
127 const pldm_pdr_record *curr_record, uint8_t **data,
128 uint32_t *size, uint32_t *next_record_handle);
129
130/** @brief Find (first) PDR record by PDR type
131 *
132 * @param[in] repo - opaque pointer acting as a PDR repo handle
133 * @param[in] pdr_type - PDR type number as per DSP0248
134 * @param[in] curr_record - opaque pointer acting as a PDR record handle; if
135 * not NULL, then search will begin from this record's next record
136 * @param[in/out] data - will point to PDR record data (as per DSP0248) on
137 * return, if input is not NULL
138 * @param[out] size - *size will be size of PDR record, if input is not NULL
139 *
140 * @return opaque pointer acting as PDR record handle, will be NULL if record
141 * was not found
142 */
143const pldm_pdr_record *
144pldm_pdr_find_record_by_type(const pldm_pdr *repo, uint8_t pdr_type,
145 const pldm_pdr_record *curr_record, uint8_t **data,
146 uint32_t *size);
147
Andrew Jeffery5565fcd2023-06-30 13:21:32 +0930148/** @brief Determine if a record is a remote record
149 *
150 * @pre record must point to a valid object
151 *
152 * @return true if the record is a remote record, false otherwise.
153 */
Andrew Jeffery9c766792022-08-10 23:12:49 +0930154bool pldm_pdr_record_is_remote(const pldm_pdr_record *record);
155
156/** @brief Remove all PDR records that belong to a remote terminus
157 *
158 * @param[in] repo - opaque pointer acting as a PDR repo handle
159 */
160void pldm_pdr_remove_remote_pdrs(pldm_pdr *repo);
161
162/** @brief Remove all remote PDR's that beling to a specific terminus
163 * handle
164 * @param[in] repo - opaque pointer acting as a PDR repo handle
165 * @param[in] terminus_handle - Terminus Handle of the remove PLDM terminus
Andrew Jeffery438dd492023-07-03 11:51:43 +0930166 *
167 * If repo is NULL there are no PDRs that can be removed.
Andrew Jeffery9c766792022-08-10 23:12:49 +0930168 */
169void pldm_pdr_remove_pdrs_by_terminus_handle(pldm_pdr *repo,
170 uint16_t terminus_handle);
171
172/** @brief Update the validity of TL PDR - the validity is decided based on
173 * whether the valid bit is set or not as per the spec DSP0248
174 *
175 * @param[in] repo - opaque pointer acting as a PDR repo handle
Andrew Jeffery6005f1c2023-04-05 20:02:52 +0930176 * @param[in] terminus_handle - PLDM terminus handle
Andrew Jeffery9c766792022-08-10 23:12:49 +0930177 * @param[in] tid - Terminus ID
Andrew Jeffery2a38ab52023-04-06 15:09:08 +0930178 * @param[in] tl_eid - MCTP endpoint EID
Andrew Jeffery9c766792022-08-10 23:12:49 +0930179 * @param[in] valid - validity bit of TLPDR
180 */
Andrew Jeffery6005f1c2023-04-05 20:02:52 +0930181/* NOLINTNEXTLINE(readability-identifier-naming) */
182void pldm_pdr_update_TL_pdr(const pldm_pdr *repo, uint16_t terminus_handle,
183 uint8_t tid, uint8_t tl_eid, bool valid);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930184
Pavithra Barithaya4d694342023-05-19 08:04:41 -0500185/** @brief Find the last record within the particular range
186 * of record handles
187 *
188 * @param[in] repo - pointer acting as a PDR repo handle
189 * @param[in] first - first record handle value of the records in the range
190 * @param[in] last - last record handle value of the records in the range
191 *
192 * @return pointer to the PDR record,will be NULL if record was not
193 * found
194 */
195pldm_pdr_record *pldm_pdr_find_last_in_range(const pldm_pdr *repo,
196 uint32_t first, uint32_t last);
197
Pavithra Barithaya5dc02572023-05-19 09:24:36 -0500198/** @brief find the container ID of the contained entity which is not in the
199 * particular range of record handles given
200 *
201 * @param[in] repo - opaque pointer acting as a PDR repo handle
202 * @param[in] entity_type - entity type
203 * @param[in] entity_instance - instance of the entity
Pavithra Barithaya8cf70452023-06-22 04:36:19 -0500204 * @param[in] child_index - index of the child entity whose container id needs to be found
Pavithra Barithaya5dc02572023-05-19 09:24:36 -0500205 * @param[in] range_exclude_start_handle - first record handle in the range of the remote endpoint
Pavithra Barithaya8cf70452023-06-22 04:36:19 -0500206 * which is ignored
Pavithra Barithaya5dc02572023-05-19 09:24:36 -0500207 * @param[in] range_exclude_end_handle - last record handle in the range of the remote endpoint
Pavithra Barithaya8cf70452023-06-22 04:36:19 -0500208 * which is ignored
Pavithra Barithaya5dc02572023-05-19 09:24:36 -0500209 * @param[out] container_id - container id of the contained entity
210 *
Pavithra Barithaya8cf70452023-06-22 04:36:19 -0500211 * @return container id of the PDR record found on success,-EINVAL when repo is NULL
212 * or -ENOKEY if the container id is not found.
Pavithra Barithaya5dc02572023-05-19 09:24:36 -0500213 */
Pavithra Barithaya8cf70452023-06-22 04:36:19 -0500214int pldm_pdr_find_child_container_id_index_range_exclude(
Pavithra Barithaya5dc02572023-05-19 09:24:36 -0500215 const pldm_pdr *repo, uint16_t entity_type, uint16_t entity_instance,
Pavithra Barithaya8cf70452023-06-22 04:36:19 -0500216 uint8_t child_index, uint32_t range_exclude_start_handle,
217 uint32_t range_exclude_end_handle, uint16_t *container_id);
Pavithra Barithaya5dc02572023-05-19 09:24:36 -0500218
Andrew Jeffery9c766792022-08-10 23:12:49 +0930219/* ======================= */
220/* FRU Record Set PDR APIs */
221/* ======================= */
222
223/** @brief Add a FRU record set PDR record to a PDR repository
224 *
225 * @param[in/out] repo - opaque pointer acting as a PDR repo handle
226 * @param[in] terminus_handle - PLDM terminus handle of terminus owning the PDR
227 * record
228 * @param[in] fru_rsi - FRU record set identifier
229 * @param[in] entity_type - entity type of FRU
230 * @param[in] entity_instance_num - entity instance number of FRU
231 * @param[in] container_id - container id of FRU
232 * @param[in] bmc_record_handle - handle used to construct the next record
233 *
234 * @return uint32_t - record handle assigned to PDR record
235 */
236uint32_t pldm_pdr_add_fru_record_set(pldm_pdr *repo, uint16_t terminus_handle,
237 uint16_t fru_rsi, uint16_t entity_type,
238 uint16_t entity_instance_num,
239 uint16_t container_id,
240 uint32_t bmc_record_handle);
241
242/** @brief Find a FRU record set PDR by FRU record set identifier
243 *
244 * @param[in] repo - opaque pointer acting as a PDR repo handle
245 * @param[in] fru_rsi - FRU record set identifier
246 * @param[in] terminus_handle - *terminus_handle will be FRU terminus handle of
247 * found PDR, or 0 if not found
248 * @param[in] entity_type - *entity_type will be FRU entity type of found PDR,
249 * or 0 if not found
250 * @param[in] entity_instance_num - *entity_instance_num will be FRU entity
251 * instance number of found PDR, or 0 if not found
252 * @param[in] container_id - *cintainer_id will be FRU container id of found
253 * PDR, or 0 if not found
254 *
Andrew Jefferyaf7a4d82023-06-30 13:46:32 +0930255 * @return An opaque pointer to the PDR record on success, or NULL on failure
Andrew Jeffery9c766792022-08-10 23:12:49 +0930256 */
257const pldm_pdr_record *pldm_pdr_fru_record_set_find_by_rsi(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930258 const pldm_pdr *repo, uint16_t fru_rsi, uint16_t *terminus_handle,
259 uint16_t *entity_type, uint16_t *entity_instance_num,
260 uint16_t *container_id);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930261
262/* =========================== */
263/* Entity Association PDR APIs */
264/* =========================== */
265
266typedef struct pldm_entity {
267 uint16_t entity_type;
268 uint16_t entity_instance_num;
269 uint16_t entity_container_id;
270} __attribute__((packed)) pldm_entity;
271
272enum entity_association_containment_type {
273 PLDM_ENTITY_ASSOCIAION_PHYSICAL = 0x0,
274 PLDM_ENTITY_ASSOCIAION_LOGICAL = 0x1,
275};
276
277/** @struct pldm_entity_association_tree
278 * opaque structure that represents the entity association hierarchy
279 */
280typedef struct pldm_entity_association_tree pldm_entity_association_tree;
281
282/** @struct pldm_entity_node
283 * opaque structure that represents a node in the entity association hierarchy
284 */
285typedef struct pldm_entity_node pldm_entity_node;
286
287/** @brief Make a new entity association tree
288 *
289 * @return opaque pointer that acts as a handle to the tree; NULL if no
290 * tree could be created
291 */
Andrew Jeffery319304f2023-04-05 13:53:18 +0930292pldm_entity_association_tree *pldm_entity_association_tree_init(void);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930293
Pavithra Barithaya9947f9d2023-05-18 05:20:24 -0500294/** @brief Add a local entity into the entity association tree
Andrew Jeffery9c766792022-08-10 23:12:49 +0930295 *
296 * @param[in/out] tree - opaque pointer acting as a handle to the tree
297 * @param[in/out] entity - pointer to the entity to be added. Input has the
298 * entity type. On output, instance number and the
299 * container id are populated.
300 * @param[in] entity_instance_number - entity instance number, we can use the
301 * entity instance number of the entity by
302 * default if its value is equal 0xFFFF.
303 * @param[in] parent - pointer to the node that should be the parent of input
304 * entity. If this is NULL, then the entity is the root
305 * @param[in] association_type - relation with the parent : logical or physical
306 *
307 * @return pldm_entity_node* - opaque pointer to added entity
308 */
309pldm_entity_node *pldm_entity_association_tree_add(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930310 pldm_entity_association_tree *tree, pldm_entity *entity,
311 uint16_t entity_instance_number, pldm_entity_node *parent,
312 uint8_t association_type);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930313
Pavithra Barithaya9947f9d2023-05-18 05:20:24 -0500314/** @brief Add an entity into the entity association tree based on remote field
315 * set or unset.
316 *
317 * @param[in/out] tree - opaque pointer acting as a handle to the tree
318 * @param[in/out] entity - pointer to the entity to be added. Input has the
319 * entity type. On output, instance number and the
320 * container id are populated.
321 * @param[in] entity_instance_number - entity instance number, we can use the
322 * entity instance number of the entity by
323 * default if its value is equal 0xFFFF.
324 * @param[in] parent - pointer to the node that should be the parent of input
325 * entity. If this is NULL, then the entity is the root
326 * @param[in] association_type - relation with the parent : logical or physical
327 * @param[in] is_remote - used to denote whether we are adding a BMC entity to
328 * the tree or a host entity
329 * @param[in] is_update_contanier_id - Used to determine whether need to update
330 * contanier id.
331 * true: should be changed
332 * false: should not be changed
333 * @param[in] container_id - container id of the entity added.
334 *
335 * @return pldm_entity_node* - opaque pointer to added entity
336 */
337pldm_entity_node *pldm_entity_association_tree_add_entity(
338 pldm_entity_association_tree *tree, pldm_entity *entity,
339 uint16_t entity_instance_number, pldm_entity_node *parent,
340 uint8_t association_type, bool is_remote, bool is_update_container_id,
341 uint16_t container_id);
342
Andrew Jeffery9c766792022-08-10 23:12:49 +0930343/** @brief Visit and note each entity in the entity association tree
344 *
Andrew Jeffery8e9b0de2023-06-30 14:05:04 +0930345 * @pre `*entities == NULL` and `*size == 0` must hold at the time of invocation.
346 *
347 * Callers must inspect the values of `*entities` and `*size` post-invocation to determine if the
348 * invocation was a success or failure.
349 *
Andrew Jeffery9c766792022-08-10 23:12:49 +0930350 * @param[in] tree - opaque pointer acting as a handle to the tree
351 * @param[out] entities - pointer to list of pldm_entity's. To be free()'d by
352 * the caller
353 * @param[out] size - number of pldm_entity's
354 */
355void pldm_entity_association_tree_visit(pldm_entity_association_tree *tree,
356 pldm_entity **entities, size_t *size);
357
358/** @brief Extract pldm entity by the pldm_entity_node
359 *
Andrew Jeffery5565fcd2023-06-30 13:21:32 +0930360 * @pre node must point to a valid object
361 *
Andrew Jeffery9c766792022-08-10 23:12:49 +0930362 * @param[in] node - opaque pointer to added entity
363 *
364 * @return pldm_entity - pldm entity
365 */
366pldm_entity pldm_entity_extract(pldm_entity_node *node);
367
ArchanaKakani39bd2ea2023-02-02 02:39:18 -0600368/** @brief Extract remote container id from the pldm_entity_node
369 *
Andrew Jeffery15b88182023-06-30 13:29:17 +0930370 * @pre entity must point to a valid object
ArchanaKakani39bd2ea2023-02-02 02:39:18 -0600371 *
Andrew Jeffery15b88182023-06-30 13:29:17 +0930372 * @param[in] entity - pointer to existing entity
373 *
374 * @return The remote container id
ArchanaKakani39bd2ea2023-02-02 02:39:18 -0600375 */
Andrew Jeffery15b88182023-06-30 13:29:17 +0930376uint16_t
377pldm_entity_node_get_remote_container_id(const pldm_entity_node *entity);
ArchanaKakani39bd2ea2023-02-02 02:39:18 -0600378
Andrew Jeffery9c766792022-08-10 23:12:49 +0930379/** @brief Destroy entity association tree
380 *
381 * @param[in] tree - opaque pointer acting as a handle to the tree
382 */
383void pldm_entity_association_tree_destroy(pldm_entity_association_tree *tree);
384
385/** @brief Check if input enity node is a parent
386 *
Andrew Jeffery5565fcd2023-06-30 13:21:32 +0930387 * @pre node must point to a valid object
388 *
Andrew Jeffery9c766792022-08-10 23:12:49 +0930389 * @param[in] node - opaque pointer acting as a handle to an entity node
390 *
391 * @return bool true if node is a parent, false otherwise
392 */
393bool pldm_entity_is_node_parent(pldm_entity_node *node);
394
395/** @brief Get parent of entity
396 *
Andrew Jeffery5565fcd2023-06-30 13:21:32 +0930397 * @pre node must point to a valid object
398 *
Andrew Jeffery9c766792022-08-10 23:12:49 +0930399 * @param[in] node - opaque pointer acting as a handle to an entity node
400 *
401 * @return pldm_entity - pldm entity
402 */
403pldm_entity pldm_entity_get_parent(pldm_entity_node *node);
404
405/** @brief Check the current pldm entity is exist parent
406 *
Andrew Jeffery5565fcd2023-06-30 13:21:32 +0930407 * @pre node must point to a valid object
408 *
Andrew Jeffery9c766792022-08-10 23:12:49 +0930409 * @param[in] node - opaque pointer acting as a handle to an entity node
410 *
411 * @return bool true if exist parent, false otherwise
412 */
413bool pldm_entity_is_exist_parent(pldm_entity_node *node);
414
415/** @brief Convert entity association tree to PDR
416 *
Andrew Jefferyc7883482023-06-30 15:52:04 +0930417 * No conversion takes place if one or both of tree or repo are NULL.
418 *
Andrew Jeffery9c766792022-08-10 23:12:49 +0930419 * @param[in] tree - opaque pointer to entity association tree
420 * @param[in] repo - PDR repo where entity association records should be added
421 * @param[in] is_remote - if true, then the PDR is not from this terminus
422 * @param[in] terminus_handle - terminus handle of the terminus
423 */
424void pldm_entity_association_pdr_add(pldm_entity_association_tree *tree,
425 pldm_pdr *repo, bool is_remote,
426 uint16_t terminus_handle);
427/** @brief Add entity association pdr from node
428 *
429 * @param[in] node - opaque pointer acting as a handle to an entity node
430 * @param[in] repo - PDR repo where entity association records should be added
431 * @param[in] is_remote - if true, then the PDR is not from this terminus
432 * @param[in] terminus_handle - terminus handle of the terminus
433 */
434void pldm_entity_association_pdr_add_from_node(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930435 pldm_entity_node *node, pldm_pdr *repo, pldm_entity **entities,
436 size_t num_entities, bool is_remote, uint16_t terminus_handle);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930437
Pavithra Barithaya25ddbcc2023-05-19 08:28:59 -0500438/** @brief Add entity association pdr record based on record handle
439 * earlier the records where added in a sequential way alone, with
440 * this change the entity association PDR records gets the new record
441 * handle based on the input value given.
442 *
443 * @param[in] node - opaque pointer acting as a handle to an entity node
444 * @param[in] repo - PDR repo where entity association records should be added
445 * @param[in] is_remote - if true, then the PDR is not from this terminus
446 * @param[in] terminus_handle - terminus handle of the terminus
447 * @param[in] record_handle - record handle of the PDR
448 *
449 * @return 0 on succes, -EINVAL if the provided arguments are invalid.
450 */
451int pldm_entity_association_pdr_add_from_node_with_record_handle(
452 pldm_entity_node *node, pldm_pdr *repo, pldm_entity **entities,
453 size_t num_entities, bool is_remote, uint16_t terminus_handle,
454 uint32_t record_handle);
455
Andrew Jeffery9c766792022-08-10 23:12:49 +0930456/** @brief Find entity reference in tree
457 *
458 * @param[in] tree - opaque pointer to entity association tree
459 * @param[in] entity - PLDM entity
460 * @param[in] node - node to the entity
461 */
462void pldm_find_entity_ref_in_tree(pldm_entity_association_tree *tree,
463 pldm_entity entity, pldm_entity_node **node);
464
465/** @brief Get number of children of entity
466 *
467 * @param[in] node - opaque pointer acting as a handle to an entity node
468 * @param[in] association_type - relation type filter : logical or physical
469 *
Andrew Jeffery6e8a2612023-06-30 15:36:48 +0930470 * @return uint8_t number of children. The returned value is zero if node is NULL or
471 * association_type is not one of PLDM_ENTITY_ASSOCIAION_PHYSICAL or
472 * PLDM_ENTITY_ASSOCIAION_LOGICAL.
Andrew Jeffery9c766792022-08-10 23:12:49 +0930473 */
474uint8_t pldm_entity_get_num_children(pldm_entity_node *node,
475 uint8_t association_type);
476
477/** @brief Verify that the current node is a child of the current parent
478 *
Andrew Jeffery5565fcd2023-06-30 13:21:32 +0930479 * @pre parent must point to a valid object
480 * @pre node must point to a valid object
481 *
Andrew Jeffery9c766792022-08-10 23:12:49 +0930482 * @param[in] parent - opaque pointer acting as a handle to an entity parent
483 * @param[in] node - pointer to the node of the pldm entity
Andrew Jeffery375d9fc2023-06-30 15:45:54 +0930484 *
485 * @return True if the node is a child of parent, false otherwise, including if one or both of
486 * parent or node are NULL.
Andrew Jeffery9c766792022-08-10 23:12:49 +0930487 */
488bool pldm_is_current_parent_child(pldm_entity_node *parent, pldm_entity *node);
489
490/** @brief Find an entity in the entity association tree
491 *
492 * @param[in] tree - pointer to entity association tree
493 * @param[in/out] entity - entity type and instance id set on input, container
494 * id set on output
Andrew Jeffery9c766792022-08-10 23:12:49 +0930495 * @return pldm_entity_node* pointer to entity if found, NULL otherwise
496 */
497pldm_entity_node *
498pldm_entity_association_tree_find(pldm_entity_association_tree *tree,
499 pldm_entity *entity);
500
Pavithra Barithaya9947f9d2023-05-18 05:20:24 -0500501/** @brief Find an entity in the entity association tree if remote
502 *
503 * @param[in] tree - pointer to entity association tree
504 * @param[in/out] entity - entity type and instance id set on input, container
505 * id set on output
506 * @param[in] is_remote - variable to denote whether we are finding a host
507 * entity or a BMC entity
508 *
509 * @return pldm_entity_node* pointer to entity if found, NULL otherwise
510 */
511pldm_entity_node *
512pldm_entity_association_tree_find_if_remote(pldm_entity_association_tree *tree,
513 pldm_entity *entity,
514 bool is_remote);
515
Andrew Jeffery9c766792022-08-10 23:12:49 +0930516/** @brief Create a copy of an existing entity association tree
517 *
518 * @param[in] org_tree - pointer to source tree
519 * @param[in/out] new_tree - pointer to destination tree
520 */
521void pldm_entity_association_tree_copy_root(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930522 pldm_entity_association_tree *org_tree,
523 pldm_entity_association_tree *new_tree);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930524
525/** @brief Destroy all the nodes of the entity association tree
526 *
527 * @param[in] tree - pointer to entity association tree
528 */
529void pldm_entity_association_tree_destroy_root(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930530 pldm_entity_association_tree *tree);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930531
532/** @brief Check whether the entity association tree is empty
533 *
Andrew Jeffery5565fcd2023-06-30 13:21:32 +0930534 * @pre tree must point to a valid object
535 *
Andrew Jeffery9c766792022-08-10 23:12:49 +0930536 * @param[in] tree - pointer to entity association tree
537 * @return bool, true if tree is empty
538 */
539bool pldm_is_empty_entity_assoc_tree(pldm_entity_association_tree *tree);
540
541/** @brief Extract entities from entity association PDR
542 *
543 * @param[in] pdr - entity association PDR
544 * @param[in] pdr_len - size of entity association PDR in bytes
545 * @param[out] num_entities - number of entities found, including the container
546 * @param[out] entities - extracted entities, container is *entities[0]. Caller
547 * must free *entities
548 */
549void pldm_entity_association_pdr_extract(const uint8_t *pdr, uint16_t pdr_len,
550 size_t *num_entities,
551 pldm_entity **entities);
552
553#ifdef __cplusplus
554}
555#endif
556
557#endif /* PDR_H */