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