Rashmica Gupta | 36af84c | 2023-04-12 16:16:28 +1000 | [diff] [blame] | 1 | #ifndef INSTANCE_ID_H |
| 2 | #define INSTANCE_ID_H |
| 3 | |
| 4 | #ifdef __cplusplus |
| 5 | extern "C" { |
| 6 | #endif |
| 7 | |
| 8 | #include "libpldm/base.h" |
| 9 | #include <stdint.h> |
| 10 | |
| 11 | typedef uint8_t pldm_instance_id_t; |
| 12 | struct pldm_instance_db; |
| 13 | |
| 14 | #ifdef __STDC_HOSTED__ |
| 15 | /** |
| 16 | * @brief Instantiates an instance ID database object for a given database path |
| 17 | * |
| 18 | * @param[out] ctx - *ctx must be NULL, and will point to a PLDM instance ID |
| 19 | * database object on success. |
| 20 | * @param[in] dbpath - the path to the instance ID database file to use |
| 21 | * |
| 22 | * @return int - Returns 0 on success. Returns -EINVAL if ctx is NULL or *ctx |
| 23 | * is not NULL. Returns -ENOMEM if memory couldn't be allocated. |
| 24 | * Returns the errno if the database couldn't be opened. |
| 25 | * */ |
| 26 | int pldm_instance_db_init(struct pldm_instance_db **ctx, const char *dbpath); |
| 27 | |
| 28 | /** |
| 29 | * @brief Instantiates an instance ID database object for the default database |
| 30 | * path |
| 31 | * |
| 32 | * @param[out] ctx - *ctx will point to a PLDM instance ID database object on |
| 33 | * success. |
| 34 | * |
| 35 | * @return int - Returns 0 on success. Returns -EINVAL if ctx is NULL or *ctx |
| 36 | * is not NULL. Returns -ENOMEM if memory couldn't be allocated. |
| 37 | * Returns the errno if the database couldn't be opened. |
| 38 | * */ |
| 39 | int pldm_instance_db_init_default(struct pldm_instance_db **ctx); |
| 40 | |
| 41 | /** |
| 42 | * @brief Destroys an instance ID database object |
| 43 | * |
| 44 | * @param[in] ctx - PLDM instance ID database object |
| 45 | * |
| 46 | * @return int - Returns 0 on success or if *ctx is NULL. No specific errors are |
| 47 | * specified. |
| 48 | * */ |
| 49 | int pldm_instance_db_destroy(struct pldm_instance_db *ctx); |
| 50 | |
| 51 | /** |
| 52 | * @brief Allocates an instance ID for a destination TID from the instance ID |
| 53 | * database |
| 54 | * |
| 55 | * @param[in] ctx - PLDM instance ID database object |
| 56 | * @param[in] tid - PLDM TID |
| 57 | * @param[in] iid - caller owned pointer to a PLDM instance ID object. On |
| 58 | * success, this points to an instance ID to use for a PLDM request |
| 59 | * message. |
| 60 | * |
| 61 | * @return int - Returns 0 on success if we were able to allocate an instance |
| 62 | * ID. Returns -EINVAL if the iid pointer is NULL. Returns -EAGAIN |
| 63 | * if a successive call may succeed. Returns -EPROTO if the |
| 64 | * operation has entered an undefined state. |
| 65 | */ |
| 66 | int pldm_instance_id_alloc(struct pldm_instance_db *ctx, pldm_tid_t tid, |
| 67 | pldm_instance_id_t *iid); |
| 68 | |
| 69 | /** |
| 70 | * @brief Frees an instance ID previously allocated by pldm_instance_id_alloc |
| 71 | * |
| 72 | * @param[in] ctx - PLDM instance ID database object |
| 73 | * @param[in] tid - PLDM TID |
| 74 | * @param[in] iid - If this instance ID was not previously allocated by |
| 75 | * pldm_instance_id_alloc then EINVAL is returned. |
| 76 | * |
| 77 | * @return int - Returns 0 on success. Returns -EINVAL if the iid supplied was |
| 78 | * not previously allocated by pldm_instance_id_alloc or it has |
| 79 | * previously been freed. Returns -EAGAIN if a successive call may |
| 80 | * succeed. Returns -EPROTO if the operation has entered an |
| 81 | * undefined state. |
| 82 | */ |
| 83 | int pldm_instance_id_free(struct pldm_instance_db *ctx, pldm_tid_t tid, |
| 84 | pldm_instance_id_t iid); |
| 85 | |
| 86 | #endif /* __STDC_HOSTED__*/ |
| 87 | |
| 88 | #ifdef __cplusplus |
| 89 | } |
| 90 | #endif |
| 91 | |
| 92 | #endif /* INSTANCE_ID_H */ |