Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1 | #include "pdr.h" |
| 2 | #include "platform.h" |
| 3 | #include <assert.h> |
Manojkiran Eda | 9a8e497 | 2022-11-28 16:38:21 +0530 | [diff] [blame] | 4 | #include <endian.h> |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 5 | #include <stdlib.h> |
| 6 | #include <string.h> |
ArchanaKakani | 39bd2ea | 2023-02-02 02:39:18 -0600 | [diff] [blame] | 7 | #include <errno.h> |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 8 | |
| 9 | typedef struct pldm_pdr_record { |
| 10 | uint32_t record_handle; |
| 11 | uint32_t size; |
| 12 | uint8_t *data; |
| 13 | struct pldm_pdr_record *next; |
| 14 | bool is_remote; |
| 15 | uint16_t terminus_handle; |
| 16 | } pldm_pdr_record; |
| 17 | |
| 18 | typedef struct pldm_pdr { |
| 19 | uint32_t record_count; |
| 20 | uint32_t size; |
| 21 | pldm_pdr_record *first; |
| 22 | pldm_pdr_record *last; |
| 23 | } pldm_pdr; |
| 24 | |
| 25 | static inline uint32_t get_next_record_handle(const pldm_pdr *repo, |
| 26 | const pldm_pdr_record *record) |
| 27 | { |
| 28 | assert(repo != NULL); |
| 29 | assert(record != NULL); |
| 30 | |
| 31 | if (record == repo->last) { |
| 32 | return 0; |
| 33 | } |
| 34 | return record->next->record_handle; |
| 35 | } |
| 36 | |
| 37 | static void add_record(pldm_pdr *repo, pldm_pdr_record *record) |
| 38 | { |
| 39 | assert(repo != NULL); |
| 40 | assert(record != NULL); |
| 41 | |
| 42 | if (repo->first == NULL) { |
| 43 | assert(repo->last == NULL); |
| 44 | repo->first = record; |
| 45 | repo->last = record; |
| 46 | } else { |
| 47 | repo->last->next = record; |
| 48 | repo->last = record; |
| 49 | } |
| 50 | repo->size += record->size; |
| 51 | ++repo->record_count; |
| 52 | } |
| 53 | |
| 54 | static inline uint32_t get_new_record_handle(const pldm_pdr *repo) |
| 55 | { |
| 56 | assert(repo != NULL); |
| 57 | uint32_t last_used_hdl = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 58 | repo->last != NULL ? repo->last->record_handle : 0; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 59 | assert(last_used_hdl != UINT32_MAX); |
| 60 | |
| 61 | return last_used_hdl + 1; |
| 62 | } |
| 63 | |
| 64 | static pldm_pdr_record *make_new_record(const pldm_pdr *repo, |
| 65 | const uint8_t *data, uint32_t size, |
| 66 | uint32_t record_handle, bool is_remote, |
| 67 | uint16_t terminus_handle) |
| 68 | { |
| 69 | assert(repo != NULL); |
| 70 | assert(size != 0); |
| 71 | |
| 72 | pldm_pdr_record *record = malloc(sizeof(pldm_pdr_record)); |
| 73 | assert(record != NULL); |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 74 | record->record_handle = record_handle == 0 ? |
| 75 | get_new_record_handle(repo) : |
| 76 | record_handle; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 77 | record->size = size; |
| 78 | record->is_remote = is_remote; |
| 79 | record->terminus_handle = terminus_handle; |
| 80 | if (data != NULL) { |
| 81 | record->data = malloc(size); |
| 82 | assert(record->data != NULL); |
| 83 | memcpy(record->data, data, size); |
| 84 | /* If record handle is 0, that is an indication for this API to |
| 85 | * compute a new handle. For that reason, the computed handle |
| 86 | * needs to be populated in the PDR header. For a case where the |
| 87 | * caller supplied the record handle, it would exist in the |
| 88 | * header already. |
| 89 | */ |
| 90 | if (!record_handle) { |
| 91 | struct pldm_pdr_hdr *hdr = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 92 | (struct pldm_pdr_hdr *)(record->data); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 93 | hdr->record_handle = htole32(record->record_handle); |
| 94 | } |
| 95 | } |
| 96 | record->next = NULL; |
| 97 | |
| 98 | return record; |
| 99 | } |
| 100 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 101 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 102 | uint32_t pldm_pdr_add(pldm_pdr *repo, const uint8_t *data, uint32_t size, |
| 103 | uint32_t record_handle, bool is_remote, |
| 104 | uint16_t terminus_handle) |
| 105 | { |
| 106 | assert(size != 0); |
| 107 | assert(data != NULL); |
| 108 | |
| 109 | pldm_pdr_record *record = make_new_record( |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 110 | repo, data, size, record_handle, is_remote, terminus_handle); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 111 | add_record(repo, record); |
| 112 | |
| 113 | return record->record_handle; |
| 114 | } |
| 115 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 116 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 319304f | 2023-04-05 13:53:18 +0930 | [diff] [blame] | 117 | pldm_pdr *pldm_pdr_init(void) |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 118 | { |
| 119 | pldm_pdr *repo = malloc(sizeof(pldm_pdr)); |
| 120 | assert(repo != NULL); |
| 121 | repo->record_count = 0; |
| 122 | repo->size = 0; |
| 123 | repo->first = NULL; |
| 124 | repo->last = NULL; |
| 125 | |
| 126 | return repo; |
| 127 | } |
| 128 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 129 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 130 | void pldm_pdr_destroy(pldm_pdr *repo) |
| 131 | { |
| 132 | assert(repo != NULL); |
| 133 | |
| 134 | pldm_pdr_record *record = repo->first; |
| 135 | while (record != NULL) { |
| 136 | pldm_pdr_record *next = record->next; |
| 137 | if (record->data) { |
| 138 | free(record->data); |
| 139 | record->data = NULL; |
| 140 | } |
| 141 | free(record); |
| 142 | record = next; |
| 143 | } |
| 144 | free(repo); |
| 145 | } |
| 146 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 147 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 148 | const pldm_pdr_record *pldm_pdr_find_record(const pldm_pdr *repo, |
| 149 | uint32_t record_handle, |
| 150 | uint8_t **data, uint32_t *size, |
| 151 | uint32_t *next_record_handle) |
| 152 | { |
| 153 | assert(repo != NULL); |
| 154 | assert(data != NULL); |
| 155 | assert(size != NULL); |
| 156 | assert(next_record_handle != NULL); |
| 157 | |
| 158 | if (!record_handle && (repo->first != NULL)) { |
| 159 | record_handle = repo->first->record_handle; |
| 160 | } |
| 161 | pldm_pdr_record *record = repo->first; |
| 162 | while (record != NULL) { |
| 163 | if (record->record_handle == record_handle) { |
| 164 | *size = record->size; |
| 165 | *data = record->data; |
| 166 | *next_record_handle = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 167 | get_next_record_handle(repo, record); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 168 | return record; |
| 169 | } |
| 170 | record = record->next; |
| 171 | } |
| 172 | |
| 173 | *size = 0; |
| 174 | *next_record_handle = 0; |
| 175 | return NULL; |
| 176 | } |
| 177 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 178 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 179 | const pldm_pdr_record * |
| 180 | pldm_pdr_get_next_record(const pldm_pdr *repo, |
| 181 | const pldm_pdr_record *curr_record, uint8_t **data, |
| 182 | uint32_t *size, uint32_t *next_record_handle) |
| 183 | { |
| 184 | assert(repo != NULL); |
| 185 | assert(curr_record != NULL); |
| 186 | assert(data != NULL); |
| 187 | assert(size != NULL); |
| 188 | assert(next_record_handle != NULL); |
| 189 | |
| 190 | if (curr_record == repo->last) { |
| 191 | *data = NULL; |
| 192 | *size = 0; |
| 193 | *next_record_handle = get_next_record_handle(repo, curr_record); |
| 194 | return NULL; |
| 195 | } |
| 196 | |
| 197 | *next_record_handle = get_next_record_handle(repo, curr_record->next); |
| 198 | *data = curr_record->next->data; |
| 199 | *size = curr_record->next->size; |
| 200 | return curr_record->next; |
| 201 | } |
| 202 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 203 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 204 | const pldm_pdr_record * |
| 205 | pldm_pdr_find_record_by_type(const pldm_pdr *repo, uint8_t pdr_type, |
| 206 | const pldm_pdr_record *curr_record, uint8_t **data, |
| 207 | uint32_t *size) |
| 208 | { |
| 209 | assert(repo != NULL); |
| 210 | |
| 211 | pldm_pdr_record *record = repo->first; |
| 212 | if (curr_record != NULL) { |
| 213 | record = curr_record->next; |
| 214 | } |
| 215 | while (record != NULL) { |
| 216 | struct pldm_pdr_hdr *hdr = (struct pldm_pdr_hdr *)record->data; |
| 217 | if (hdr->type == pdr_type) { |
| 218 | if (data && size) { |
| 219 | *size = record->size; |
| 220 | *data = record->data; |
| 221 | } |
| 222 | return record; |
| 223 | } |
| 224 | record = record->next; |
| 225 | } |
| 226 | |
| 227 | if (size) { |
| 228 | *size = 0; |
| 229 | } |
| 230 | return NULL; |
| 231 | } |
| 232 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 233 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 234 | uint32_t pldm_pdr_get_record_count(const pldm_pdr *repo) |
| 235 | { |
| 236 | assert(repo != NULL); |
| 237 | |
| 238 | return repo->record_count; |
| 239 | } |
| 240 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 241 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 242 | uint32_t pldm_pdr_get_repo_size(const pldm_pdr *repo) |
| 243 | { |
| 244 | assert(repo != NULL); |
| 245 | |
| 246 | return repo->size; |
| 247 | } |
| 248 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 249 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 250 | uint32_t pldm_pdr_get_record_handle(const pldm_pdr *repo, |
| 251 | const pldm_pdr_record *record) |
| 252 | { |
| 253 | assert(repo != NULL); |
| 254 | assert(record != NULL); |
| 255 | |
| 256 | return record->record_handle; |
| 257 | } |
| 258 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 259 | LIBPLDM_ABI_STABLE |
| 260 | bool pldm_pdr_record_is_remote(const pldm_pdr_record *record) |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 261 | { |
| 262 | assert(record != NULL); |
| 263 | |
| 264 | return record->is_remote; |
| 265 | } |
| 266 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 267 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 268 | uint32_t pldm_pdr_add_fru_record_set(pldm_pdr *repo, uint16_t terminus_handle, |
| 269 | uint16_t fru_rsi, uint16_t entity_type, |
| 270 | uint16_t entity_instance_num, |
| 271 | uint16_t container_id, |
| 272 | uint32_t bmc_record_handle) |
| 273 | { |
| 274 | uint32_t size = sizeof(struct pldm_pdr_hdr) + |
| 275 | sizeof(struct pldm_pdr_fru_record_set); |
| 276 | uint8_t data[size]; |
| 277 | |
| 278 | struct pldm_pdr_hdr *hdr = (struct pldm_pdr_hdr *)&data; |
| 279 | hdr->version = 1; |
| 280 | hdr->record_handle = bmc_record_handle; |
| 281 | hdr->type = PLDM_PDR_FRU_RECORD_SET; |
| 282 | hdr->record_change_num = 0; |
| 283 | hdr->length = htole16(sizeof(struct pldm_pdr_fru_record_set)); |
| 284 | struct pldm_pdr_fru_record_set *fru = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 285 | (struct pldm_pdr_fru_record_set *)((uint8_t *)hdr + |
| 286 | sizeof(struct pldm_pdr_hdr)); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 287 | fru->terminus_handle = htole16(terminus_handle); |
| 288 | fru->fru_rsi = htole16(fru_rsi); |
| 289 | fru->entity_type = htole16(entity_type); |
| 290 | fru->entity_instance_num = htole16(entity_instance_num); |
| 291 | fru->container_id = htole16(container_id); |
| 292 | |
| 293 | return pldm_pdr_add(repo, data, size, bmc_record_handle, false, |
| 294 | terminus_handle); |
| 295 | } |
| 296 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 297 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 298 | const pldm_pdr_record *pldm_pdr_fru_record_set_find_by_rsi( |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 299 | const pldm_pdr *repo, uint16_t fru_rsi, uint16_t *terminus_handle, |
| 300 | uint16_t *entity_type, uint16_t *entity_instance_num, |
| 301 | uint16_t *container_id) |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 302 | { |
| 303 | assert(terminus_handle != NULL); |
| 304 | assert(entity_type != NULL); |
| 305 | assert(entity_instance_num != NULL); |
| 306 | assert(container_id != NULL); |
| 307 | |
| 308 | uint8_t *data = NULL; |
| 309 | uint32_t size = 0; |
| 310 | const pldm_pdr_record *curr_record = pldm_pdr_find_record_by_type( |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 311 | repo, PLDM_PDR_FRU_RECORD_SET, NULL, &data, &size); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 312 | while (curr_record != NULL) { |
| 313 | struct pldm_pdr_fru_record_set *fru = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 314 | (struct pldm_pdr_fru_record_set |
| 315 | *)(data + sizeof(struct pldm_pdr_hdr)); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 316 | if (fru->fru_rsi == htole16(fru_rsi)) { |
| 317 | *terminus_handle = le16toh(fru->terminus_handle); |
| 318 | *entity_type = le16toh(fru->entity_type); |
| 319 | *entity_instance_num = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 320 | le16toh(fru->entity_instance_num); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 321 | *container_id = le16toh(fru->container_id); |
| 322 | return curr_record; |
| 323 | } |
| 324 | data = NULL; |
| 325 | curr_record = pldm_pdr_find_record_by_type( |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 326 | repo, PLDM_PDR_FRU_RECORD_SET, curr_record, &data, |
| 327 | &size); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 328 | } |
| 329 | |
| 330 | *terminus_handle = 0; |
| 331 | *entity_type = 0; |
| 332 | *entity_instance_num = 0; |
| 333 | *container_id = 0; |
| 334 | |
| 335 | return NULL; |
| 336 | } |
| 337 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 338 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 6005f1c | 2023-04-05 20:02:52 +0930 | [diff] [blame] | 339 | /* NOLINTNEXTLINE(readability-identifier-naming) */ |
| 340 | void pldm_pdr_update_TL_pdr(const pldm_pdr *repo, uint16_t terminus_handle, |
| 341 | uint8_t tid, uint8_t tl_eid, bool valid_bit) |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 342 | { |
Andrew Jeffery | 6005f1c | 2023-04-05 20:02:52 +0930 | [diff] [blame] | 343 | uint8_t *out_data = NULL; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 344 | uint32_t size = 0; |
| 345 | const pldm_pdr_record *record; |
| 346 | record = pldm_pdr_find_record_by_type(repo, PLDM_TERMINUS_LOCATOR_PDR, |
Andrew Jeffery | 6005f1c | 2023-04-05 20:02:52 +0930 | [diff] [blame] | 347 | NULL, &out_data, &size); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 348 | |
| 349 | do { |
| 350 | if (record != NULL) { |
| 351 | struct pldm_terminus_locator_pdr *pdr = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 352 | (struct pldm_terminus_locator_pdr *)out_data; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 353 | struct pldm_terminus_locator_type_mctp_eid *value = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 354 | (struct pldm_terminus_locator_type_mctp_eid *) |
| 355 | pdr->terminus_locator_value; |
Andrew Jeffery | 6005f1c | 2023-04-05 20:02:52 +0930 | [diff] [blame] | 356 | if (pdr->terminus_handle == terminus_handle && |
| 357 | pdr->tid == tid && value->eid == tl_eid) { |
| 358 | pdr->validity = valid_bit; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 359 | break; |
| 360 | } |
| 361 | } |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 362 | record = pldm_pdr_find_record_by_type(repo, |
| 363 | PLDM_TERMINUS_LOCATOR_PDR, |
| 364 | record, &out_data, &size); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 365 | } while (record); |
| 366 | } |
| 367 | |
| 368 | typedef struct pldm_entity_association_tree { |
| 369 | pldm_entity_node *root; |
| 370 | uint16_t last_used_container_id; |
| 371 | } pldm_entity_association_tree; |
| 372 | |
| 373 | typedef struct pldm_entity_node { |
| 374 | pldm_entity entity; |
| 375 | pldm_entity parent; |
ArchanaKakani | 39bd2ea | 2023-02-02 02:39:18 -0600 | [diff] [blame] | 376 | uint16_t remote_container_id; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 377 | pldm_entity_node *first_child; |
| 378 | pldm_entity_node *next_sibling; |
| 379 | uint8_t association_type; |
| 380 | } pldm_entity_node; |
| 381 | |
| 382 | static inline uint16_t next_container_id(pldm_entity_association_tree *tree) |
| 383 | { |
| 384 | assert(tree != NULL); |
| 385 | assert(tree->last_used_container_id != UINT16_MAX); |
| 386 | |
| 387 | return ++tree->last_used_container_id; |
| 388 | } |
| 389 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 390 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 391 | pldm_entity pldm_entity_extract(pldm_entity_node *node) |
| 392 | { |
| 393 | assert(node != NULL); |
| 394 | |
| 395 | return node->entity; |
| 396 | } |
| 397 | |
ArchanaKakani | 39bd2ea | 2023-02-02 02:39:18 -0600 | [diff] [blame] | 398 | LIBPLDM_ABI_TESTING |
| 399 | int pldm_entity_node_get_remote_container_id(const pldm_entity_node *entity, |
| 400 | uint16_t *cid) |
| 401 | { |
| 402 | if (!entity) { |
| 403 | return -EINVAL; |
| 404 | } |
| 405 | |
| 406 | *cid = entity->remote_container_id; |
| 407 | return 0; |
| 408 | } |
| 409 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 410 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 319304f | 2023-04-05 13:53:18 +0930 | [diff] [blame] | 411 | pldm_entity_association_tree *pldm_entity_association_tree_init(void) |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 412 | { |
| 413 | pldm_entity_association_tree *tree = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 414 | malloc(sizeof(pldm_entity_association_tree)); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 415 | assert(tree != NULL); |
| 416 | tree->root = NULL; |
| 417 | tree->last_used_container_id = 0; |
| 418 | |
| 419 | return tree; |
| 420 | } |
| 421 | |
| 422 | static pldm_entity_node *find_insertion_at(pldm_entity_node *start, |
| 423 | uint16_t entity_type) |
| 424 | { |
| 425 | assert(start != NULL); |
| 426 | |
| 427 | /* Insert after the the last node that matches the input entity type, or |
| 428 | * at the end if no such match occurrs |
| 429 | */ |
| 430 | while (start->next_sibling != NULL) { |
| 431 | uint16_t this_type = start->entity.entity_type; |
| 432 | pldm_entity_node *next = start->next_sibling; |
| 433 | if (this_type == entity_type && |
| 434 | (this_type != next->entity.entity_type)) { |
| 435 | break; |
| 436 | } |
| 437 | start = start->next_sibling; |
| 438 | } |
| 439 | |
| 440 | return start; |
| 441 | } |
| 442 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 443 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 444 | pldm_entity_node *pldm_entity_association_tree_add( |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 445 | pldm_entity_association_tree *tree, pldm_entity *entity, |
| 446 | uint16_t entity_instance_number, pldm_entity_node *parent, |
| 447 | uint8_t association_type) |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 448 | { |
Pavithra Barithaya | 9947f9d | 2023-05-18 05:20:24 -0500 | [diff] [blame] | 449 | return pldm_entity_association_tree_add_entity(tree, entity, |
| 450 | entity_instance_number, |
| 451 | parent, association_type, |
| 452 | false, true, 0xFFFF); |
| 453 | } |
| 454 | |
| 455 | LIBPLDM_ABI_TESTING |
| 456 | pldm_entity_node *pldm_entity_association_tree_add_entity( |
| 457 | pldm_entity_association_tree *tree, pldm_entity *entity, |
| 458 | uint16_t entity_instance_number, pldm_entity_node *parent, |
| 459 | uint8_t association_type, bool is_remote, bool is_update_container_id, |
| 460 | uint16_t container_id) |
| 461 | { |
| 462 | if ((!tree) || (!entity)) { |
| 463 | return NULL; |
| 464 | } |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 465 | |
| 466 | if (entity_instance_number != 0xFFFF && parent != NULL) { |
| 467 | pldm_entity node; |
| 468 | node.entity_type = entity->entity_type; |
| 469 | node.entity_instance_num = entity_instance_number; |
| 470 | if (pldm_is_current_parent_child(parent, &node)) { |
| 471 | return NULL; |
| 472 | } |
| 473 | } |
Pavithra Barithaya | 9947f9d | 2023-05-18 05:20:24 -0500 | [diff] [blame] | 474 | if (association_type != PLDM_ENTITY_ASSOCIAION_PHYSICAL && |
| 475 | association_type != PLDM_ENTITY_ASSOCIAION_LOGICAL) { |
| 476 | return NULL; |
| 477 | } |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 478 | pldm_entity_node *node = malloc(sizeof(pldm_entity_node)); |
Pavithra Barithaya | 9947f9d | 2023-05-18 05:20:24 -0500 | [diff] [blame] | 479 | if (!node) { |
| 480 | return NULL; |
| 481 | } |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 482 | node->first_child = NULL; |
| 483 | node->next_sibling = NULL; |
| 484 | node->parent.entity_type = 0; |
| 485 | node->parent.entity_instance_num = 0; |
| 486 | node->parent.entity_container_id = 0; |
| 487 | node->entity.entity_type = entity->entity_type; |
| 488 | node->entity.entity_instance_num = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 489 | entity_instance_number != 0xFFFF ? entity_instance_number : 1; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 490 | node->association_type = association_type; |
ArchanaKakani | 39bd2ea | 2023-02-02 02:39:18 -0600 | [diff] [blame] | 491 | node->remote_container_id = 0; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 492 | if (tree->root == NULL) { |
Pavithra Barithaya | 9947f9d | 2023-05-18 05:20:24 -0500 | [diff] [blame] | 493 | if (parent != NULL) { |
| 494 | free(node); |
| 495 | return NULL; |
| 496 | } |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 497 | tree->root = node; |
| 498 | /* container_id 0 here indicates this is the top-most entry */ |
| 499 | node->entity.entity_container_id = 0; |
ArchanaKakani | 39bd2ea | 2023-02-02 02:39:18 -0600 | [diff] [blame] | 500 | node->remote_container_id = node->entity.entity_container_id; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 501 | } else if (parent != NULL && parent->first_child == NULL) { |
| 502 | parent->first_child = node; |
| 503 | node->parent = parent->entity; |
Pavithra Barithaya | 9947f9d | 2023-05-18 05:20:24 -0500 | [diff] [blame] | 504 | |
| 505 | if (is_remote) { |
| 506 | node->remote_container_id = entity->entity_container_id; |
| 507 | } |
| 508 | if (is_update_container_id) { |
| 509 | if (container_id != 0xFFFF) { |
| 510 | node->entity.entity_container_id = container_id; |
| 511 | } else { |
| 512 | node->entity.entity_container_id = |
| 513 | next_container_id(tree); |
| 514 | } |
| 515 | } else { |
| 516 | node->entity.entity_container_id = |
| 517 | entity->entity_container_id; |
| 518 | } |
| 519 | |
| 520 | if (!is_remote) { |
| 521 | node->remote_container_id = |
| 522 | node->entity.entity_container_id; |
| 523 | } |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 524 | } else { |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 525 | pldm_entity_node *start = parent == NULL ? tree->root : |
| 526 | parent->first_child; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 527 | pldm_entity_node *prev = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 528 | find_insertion_at(start, entity->entity_type); |
Pavithra Barithaya | 9947f9d | 2023-05-18 05:20:24 -0500 | [diff] [blame] | 529 | if (!prev) { |
| 530 | free(node); |
| 531 | return NULL; |
| 532 | } |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 533 | pldm_entity_node *next = prev->next_sibling; |
| 534 | if (prev->entity.entity_type == entity->entity_type) { |
Pavithra Barithaya | 9947f9d | 2023-05-18 05:20:24 -0500 | [diff] [blame] | 535 | if (prev->entity.entity_instance_num == UINT16_MAX) { |
| 536 | free(node); |
| 537 | return NULL; |
| 538 | } |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 539 | node->entity.entity_instance_num = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 540 | entity_instance_number != 0xFFFF ? |
| 541 | entity_instance_number : |
| 542 | prev->entity.entity_instance_num + 1; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 543 | } |
| 544 | prev->next_sibling = node; |
| 545 | node->parent = prev->parent; |
| 546 | node->next_sibling = next; |
| 547 | node->entity.entity_container_id = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 548 | prev->entity.entity_container_id; |
ArchanaKakani | 39bd2ea | 2023-02-02 02:39:18 -0600 | [diff] [blame] | 549 | node->remote_container_id = entity->entity_container_id; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 550 | } |
| 551 | entity->entity_instance_num = node->entity.entity_instance_num; |
Pavithra Barithaya | 9947f9d | 2023-05-18 05:20:24 -0500 | [diff] [blame] | 552 | if (is_update_container_id) { |
| 553 | entity->entity_container_id = node->entity.entity_container_id; |
| 554 | } |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 555 | return node; |
| 556 | } |
| 557 | |
| 558 | static void get_num_nodes(pldm_entity_node *node, size_t *num) |
| 559 | { |
| 560 | if (node == NULL) { |
| 561 | return; |
| 562 | } |
| 563 | |
| 564 | ++(*num); |
| 565 | get_num_nodes(node->next_sibling, num); |
| 566 | get_num_nodes(node->first_child, num); |
| 567 | } |
| 568 | |
| 569 | static void entity_association_tree_visit(pldm_entity_node *node, |
| 570 | pldm_entity *entities, size_t *index) |
| 571 | { |
| 572 | if (node == NULL) { |
| 573 | return; |
| 574 | } |
| 575 | |
| 576 | pldm_entity *entity = &entities[*index]; |
| 577 | ++(*index); |
| 578 | entity->entity_type = node->entity.entity_type; |
| 579 | entity->entity_instance_num = node->entity.entity_instance_num; |
| 580 | entity->entity_container_id = node->entity.entity_container_id; |
| 581 | |
| 582 | entity_association_tree_visit(node->next_sibling, entities, index); |
| 583 | entity_association_tree_visit(node->first_child, entities, index); |
| 584 | } |
| 585 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 586 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 587 | void pldm_entity_association_tree_visit(pldm_entity_association_tree *tree, |
| 588 | pldm_entity **entities, size_t *size) |
| 589 | { |
| 590 | assert(tree != NULL); |
| 591 | |
| 592 | *size = 0; |
| 593 | if (tree->root == NULL) { |
| 594 | return; |
| 595 | } |
| 596 | |
| 597 | get_num_nodes(tree->root, size); |
| 598 | *entities = malloc(*size * sizeof(pldm_entity)); |
| 599 | size_t index = 0; |
| 600 | entity_association_tree_visit(tree->root, *entities, &index); |
| 601 | } |
| 602 | |
| 603 | static void entity_association_tree_destroy(pldm_entity_node *node) |
| 604 | { |
| 605 | if (node == NULL) { |
| 606 | return; |
| 607 | } |
| 608 | |
| 609 | entity_association_tree_destroy(node->next_sibling); |
| 610 | entity_association_tree_destroy(node->first_child); |
| 611 | free(node); |
| 612 | } |
| 613 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 614 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 615 | void pldm_entity_association_tree_destroy(pldm_entity_association_tree *tree) |
| 616 | { |
| 617 | assert(tree != NULL); |
| 618 | |
| 619 | entity_association_tree_destroy(tree->root); |
| 620 | free(tree); |
| 621 | } |
| 622 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 623 | LIBPLDM_ABI_STABLE |
| 624 | bool pldm_entity_is_node_parent(pldm_entity_node *node) |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 625 | { |
| 626 | assert(node != NULL); |
| 627 | |
| 628 | return node->first_child != NULL; |
| 629 | } |
| 630 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 631 | LIBPLDM_ABI_STABLE |
| 632 | pldm_entity pldm_entity_get_parent(pldm_entity_node *node) |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 633 | { |
| 634 | assert(node != NULL); |
| 635 | |
| 636 | return node->parent; |
| 637 | } |
| 638 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 639 | LIBPLDM_ABI_STABLE |
| 640 | bool pldm_entity_is_exist_parent(pldm_entity_node *node) |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 641 | { |
| 642 | assert(node != NULL); |
| 643 | |
| 644 | if (node->parent.entity_type == 0 && |
| 645 | node->parent.entity_instance_num == 0 && |
| 646 | node->parent.entity_container_id == 0) { |
| 647 | return false; |
| 648 | } |
| 649 | |
| 650 | return true; |
| 651 | } |
| 652 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 653 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 654 | uint8_t pldm_entity_get_num_children(pldm_entity_node *node, |
| 655 | uint8_t association_type) |
| 656 | { |
| 657 | assert(node != NULL); |
| 658 | assert(association_type == PLDM_ENTITY_ASSOCIAION_PHYSICAL || |
| 659 | association_type == PLDM_ENTITY_ASSOCIAION_LOGICAL); |
| 660 | |
| 661 | size_t count = 0; |
| 662 | pldm_entity_node *curr = node->first_child; |
| 663 | while (curr != NULL) { |
| 664 | if (curr->association_type == association_type) { |
| 665 | ++count; |
| 666 | } |
| 667 | curr = curr->next_sibling; |
| 668 | } |
| 669 | |
| 670 | assert(count < UINT8_MAX); |
| 671 | return count; |
| 672 | } |
| 673 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 674 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 675 | bool pldm_is_current_parent_child(pldm_entity_node *parent, pldm_entity *node) |
| 676 | { |
| 677 | assert(parent != NULL); |
| 678 | assert(node != NULL); |
| 679 | |
| 680 | pldm_entity_node *curr = parent->first_child; |
| 681 | while (curr != NULL) { |
| 682 | if (node->entity_type == curr->entity.entity_type && |
| 683 | node->entity_instance_num == |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 684 | curr->entity.entity_instance_num) { |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 685 | return true; |
| 686 | } |
| 687 | curr = curr->next_sibling; |
| 688 | } |
| 689 | |
| 690 | return false; |
| 691 | } |
| 692 | |
Pavithra Barithaya | 25ddbcc | 2023-05-19 08:28:59 -0500 | [diff] [blame^] | 693 | static void entity_association_pdr_add_children( |
| 694 | pldm_entity_node *curr, pldm_pdr *repo, uint16_t size, |
| 695 | uint8_t contained_count, uint8_t association_type, bool is_remote, |
| 696 | uint16_t terminus_handle, uint32_t record_handle) |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 697 | { |
| 698 | uint8_t pdr[size]; |
| 699 | uint8_t *start = pdr; |
| 700 | |
| 701 | struct pldm_pdr_hdr *hdr = (struct pldm_pdr_hdr *)start; |
| 702 | hdr->version = 1; |
| 703 | hdr->record_handle = 0; |
| 704 | hdr->type = PLDM_PDR_ENTITY_ASSOCIATION; |
| 705 | hdr->record_change_num = 0; |
| 706 | hdr->length = htole16(size - sizeof(struct pldm_pdr_hdr)); |
| 707 | start += sizeof(struct pldm_pdr_hdr); |
| 708 | |
| 709 | uint16_t *container_id = (uint16_t *)start; |
| 710 | *container_id = htole16(curr->first_child->entity.entity_container_id); |
| 711 | start += sizeof(uint16_t); |
| 712 | *start = association_type; |
| 713 | start += sizeof(uint8_t); |
| 714 | |
| 715 | pldm_entity *entity = (pldm_entity *)start; |
| 716 | entity->entity_type = htole16(curr->entity.entity_type); |
| 717 | entity->entity_instance_num = htole16(curr->entity.entity_instance_num); |
| 718 | entity->entity_container_id = htole16(curr->entity.entity_container_id); |
| 719 | start += sizeof(pldm_entity); |
| 720 | |
| 721 | *start = contained_count; |
| 722 | start += sizeof(uint8_t); |
| 723 | |
| 724 | pldm_entity_node *node = curr->first_child; |
| 725 | while (node != NULL) { |
| 726 | if (node->association_type == association_type) { |
| 727 | pldm_entity *entity = (pldm_entity *)start; |
| 728 | entity->entity_type = htole16(node->entity.entity_type); |
| 729 | entity->entity_instance_num = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 730 | htole16(node->entity.entity_instance_num); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 731 | entity->entity_container_id = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 732 | htole16(node->entity.entity_container_id); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 733 | start += sizeof(pldm_entity); |
| 734 | } |
| 735 | node = node->next_sibling; |
| 736 | } |
| 737 | |
Pavithra Barithaya | 25ddbcc | 2023-05-19 08:28:59 -0500 | [diff] [blame^] | 738 | pldm_pdr_add(repo, pdr, size, record_handle, is_remote, |
| 739 | terminus_handle); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 740 | } |
| 741 | |
| 742 | static void entity_association_pdr_add_entry(pldm_entity_node *curr, |
| 743 | pldm_pdr *repo, bool is_remote, |
Pavithra Barithaya | 25ddbcc | 2023-05-19 08:28:59 -0500 | [diff] [blame^] | 744 | uint16_t terminus_handle, |
| 745 | uint32_t record_handle) |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 746 | { |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 747 | uint8_t num_logical_children = pldm_entity_get_num_children( |
| 748 | curr, PLDM_ENTITY_ASSOCIAION_LOGICAL); |
| 749 | uint8_t num_physical_children = pldm_entity_get_num_children( |
| 750 | curr, PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 751 | |
| 752 | if (num_logical_children) { |
| 753 | uint16_t logical_pdr_size = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 754 | sizeof(struct pldm_pdr_hdr) + sizeof(uint16_t) + |
| 755 | sizeof(uint8_t) + sizeof(pldm_entity) + |
| 756 | sizeof(uint8_t) + |
| 757 | (num_logical_children * sizeof(pldm_entity)); |
Andrew Jeffery | 4edb708 | 2023-04-05 19:09:52 +0930 | [diff] [blame] | 758 | entity_association_pdr_add_children( |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 759 | curr, repo, logical_pdr_size, num_logical_children, |
| 760 | PLDM_ENTITY_ASSOCIAION_LOGICAL, is_remote, |
Pavithra Barithaya | 25ddbcc | 2023-05-19 08:28:59 -0500 | [diff] [blame^] | 761 | terminus_handle, record_handle); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 762 | } |
| 763 | |
| 764 | if (num_physical_children) { |
| 765 | uint16_t physical_pdr_size = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 766 | sizeof(struct pldm_pdr_hdr) + sizeof(uint16_t) + |
| 767 | sizeof(uint8_t) + sizeof(pldm_entity) + |
| 768 | sizeof(uint8_t) + |
| 769 | (num_physical_children * sizeof(pldm_entity)); |
Andrew Jeffery | 4edb708 | 2023-04-05 19:09:52 +0930 | [diff] [blame] | 770 | entity_association_pdr_add_children( |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 771 | curr, repo, physical_pdr_size, num_physical_children, |
| 772 | PLDM_ENTITY_ASSOCIAION_PHYSICAL, is_remote, |
Pavithra Barithaya | 25ddbcc | 2023-05-19 08:28:59 -0500 | [diff] [blame^] | 773 | terminus_handle, record_handle); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 774 | } |
| 775 | } |
| 776 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 777 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 778 | bool is_present(pldm_entity entity, pldm_entity **entities, size_t num_entities) |
| 779 | { |
| 780 | if (entities == NULL || num_entities == 0) { |
| 781 | return true; |
| 782 | } |
| 783 | size_t i = 0; |
| 784 | while (i < num_entities) { |
| 785 | if ((*entities + i)->entity_type == entity.entity_type) { |
| 786 | return true; |
| 787 | } |
| 788 | i++; |
| 789 | } |
| 790 | return false; |
| 791 | } |
| 792 | |
| 793 | static void entity_association_pdr_add(pldm_entity_node *curr, pldm_pdr *repo, |
| 794 | pldm_entity **entities, |
| 795 | size_t num_entities, bool is_remote, |
Pavithra Barithaya | 25ddbcc | 2023-05-19 08:28:59 -0500 | [diff] [blame^] | 796 | uint16_t terminus_handle, |
| 797 | uint32_t record_handle) |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 798 | { |
| 799 | if (curr == NULL) { |
| 800 | return; |
| 801 | } |
| 802 | bool to_add = true; |
| 803 | to_add = is_present(curr->entity, entities, num_entities); |
| 804 | if (to_add) { |
Pavithra Barithaya | 25ddbcc | 2023-05-19 08:28:59 -0500 | [diff] [blame^] | 805 | entity_association_pdr_add_entry( |
| 806 | curr, repo, is_remote, terminus_handle, record_handle); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 807 | } |
| 808 | entity_association_pdr_add(curr->next_sibling, repo, entities, |
Pavithra Barithaya | 25ddbcc | 2023-05-19 08:28:59 -0500 | [diff] [blame^] | 809 | num_entities, is_remote, terminus_handle, |
| 810 | record_handle); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 811 | entity_association_pdr_add(curr->first_child, repo, entities, |
Pavithra Barithaya | 25ddbcc | 2023-05-19 08:28:59 -0500 | [diff] [blame^] | 812 | num_entities, is_remote, terminus_handle, |
| 813 | record_handle); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 814 | } |
| 815 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 816 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 817 | void pldm_entity_association_pdr_add(pldm_entity_association_tree *tree, |
| 818 | pldm_pdr *repo, bool is_remote, |
| 819 | uint16_t terminus_handle) |
| 820 | { |
| 821 | assert(tree != NULL); |
| 822 | assert(repo != NULL); |
| 823 | |
| 824 | entity_association_pdr_add(tree->root, repo, NULL, 0, is_remote, |
Pavithra Barithaya | 25ddbcc | 2023-05-19 08:28:59 -0500 | [diff] [blame^] | 825 | terminus_handle, 0); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 826 | } |
| 827 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 828 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 829 | void pldm_entity_association_pdr_add_from_node( |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 830 | pldm_entity_node *node, pldm_pdr *repo, pldm_entity **entities, |
| 831 | size_t num_entities, bool is_remote, uint16_t terminus_handle) |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 832 | { |
| 833 | assert(repo != NULL); |
| 834 | |
Pavithra Barithaya | 25ddbcc | 2023-05-19 08:28:59 -0500 | [diff] [blame^] | 835 | pldm_entity_association_pdr_add_from_node_with_record_handle( |
| 836 | node, repo, entities, num_entities, is_remote, terminus_handle, |
| 837 | 0); |
| 838 | } |
| 839 | |
| 840 | LIBPLDM_ABI_TESTING |
| 841 | int pldm_entity_association_pdr_add_from_node_with_record_handle( |
| 842 | pldm_entity_node *node, pldm_pdr *repo, pldm_entity **entities, |
| 843 | size_t num_entities, bool is_remote, uint16_t terminus_handle, |
| 844 | uint32_t record_handle) |
| 845 | { |
| 846 | if (!node || !repo || !entities) { |
| 847 | return -EINVAL; |
| 848 | } |
| 849 | |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 850 | entity_association_pdr_add(node, repo, entities, num_entities, |
Pavithra Barithaya | 25ddbcc | 2023-05-19 08:28:59 -0500 | [diff] [blame^] | 851 | is_remote, terminus_handle, record_handle); |
| 852 | |
| 853 | return 0; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 854 | } |
| 855 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 856 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 857 | void find_entity_ref_in_tree(pldm_entity_node *tree_node, pldm_entity entity, |
| 858 | pldm_entity_node **node) |
| 859 | { |
ArchanaKakani | 39bd2ea | 2023-02-02 02:39:18 -0600 | [diff] [blame] | 860 | bool is_entity_container_id; |
| 861 | bool is_entity_instance_num; |
| 862 | bool is_type; |
| 863 | |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 864 | if (tree_node == NULL) { |
| 865 | return; |
| 866 | } |
| 867 | |
ArchanaKakani | 39bd2ea | 2023-02-02 02:39:18 -0600 | [diff] [blame] | 868 | is_type = tree_node->entity.entity_type == entity.entity_type; |
| 869 | is_entity_instance_num = tree_node->entity.entity_instance_num == |
| 870 | entity.entity_instance_num; |
| 871 | is_entity_container_id = tree_node->entity.entity_container_id == |
| 872 | entity.entity_container_id; |
| 873 | |
| 874 | if (is_type && is_entity_instance_num && is_entity_container_id) { |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 875 | *node = tree_node; |
| 876 | return; |
| 877 | } |
| 878 | |
| 879 | find_entity_ref_in_tree(tree_node->first_child, entity, node); |
| 880 | find_entity_ref_in_tree(tree_node->next_sibling, entity, node); |
| 881 | } |
| 882 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 883 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 884 | void pldm_find_entity_ref_in_tree(pldm_entity_association_tree *tree, |
| 885 | pldm_entity entity, pldm_entity_node **node) |
| 886 | { |
| 887 | assert(tree != NULL); |
| 888 | find_entity_ref_in_tree(tree->root, entity, node); |
| 889 | } |
| 890 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 891 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 892 | void pldm_pdr_remove_pdrs_by_terminus_handle(pldm_pdr *repo, |
| 893 | uint16_t terminus_handle) |
| 894 | { |
| 895 | assert(repo != NULL); |
| 896 | bool removed = false; |
| 897 | |
| 898 | pldm_pdr_record *record = repo->first; |
| 899 | pldm_pdr_record *prev = NULL; |
| 900 | while (record != NULL) { |
| 901 | pldm_pdr_record *next = record->next; |
| 902 | if (record->terminus_handle == terminus_handle) { |
| 903 | if (repo->first == record) { |
| 904 | repo->first = next; |
| 905 | } else { |
| 906 | prev->next = next; |
| 907 | } |
| 908 | if (repo->last == record) { |
| 909 | repo->last = prev; |
| 910 | } |
| 911 | if (record->data) { |
| 912 | free(record->data); |
| 913 | } |
| 914 | --repo->record_count; |
| 915 | repo->size -= record->size; |
| 916 | free(record); |
| 917 | removed = true; |
| 918 | } else { |
| 919 | prev = record; |
| 920 | } |
| 921 | record = next; |
| 922 | } |
| 923 | |
| 924 | if (removed == true) { |
| 925 | record = repo->first; |
| 926 | uint32_t record_handle = 0; |
| 927 | while (record != NULL) { |
| 928 | record->record_handle = ++record_handle; |
| 929 | if (record->data != NULL) { |
| 930 | struct pldm_pdr_hdr *hdr = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 931 | (struct pldm_pdr_hdr *)(record->data); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 932 | hdr->record_handle = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 933 | htole32(record->record_handle); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 934 | } |
| 935 | record = record->next; |
| 936 | } |
| 937 | } |
| 938 | } |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 939 | |
| 940 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 941 | void pldm_pdr_remove_remote_pdrs(pldm_pdr *repo) |
| 942 | { |
| 943 | assert(repo != NULL); |
| 944 | bool removed = false; |
| 945 | |
| 946 | pldm_pdr_record *record = repo->first; |
| 947 | pldm_pdr_record *prev = NULL; |
| 948 | while (record != NULL) { |
| 949 | pldm_pdr_record *next = record->next; |
| 950 | if (record->is_remote == true) { |
| 951 | if (repo->first == record) { |
| 952 | repo->first = next; |
| 953 | } else { |
| 954 | prev->next = next; |
| 955 | } |
| 956 | if (repo->last == record) { |
| 957 | repo->last = prev; |
| 958 | } |
| 959 | if (record->data) { |
| 960 | free(record->data); |
| 961 | } |
| 962 | --repo->record_count; |
| 963 | repo->size -= record->size; |
| 964 | free(record); |
| 965 | removed = true; |
| 966 | } else { |
| 967 | prev = record; |
| 968 | } |
| 969 | record = next; |
| 970 | } |
| 971 | |
| 972 | if (removed == true) { |
| 973 | record = repo->first; |
| 974 | uint32_t record_handle = 0; |
| 975 | while (record != NULL) { |
| 976 | record->record_handle = ++record_handle; |
| 977 | if (record->data != NULL) { |
| 978 | struct pldm_pdr_hdr *hdr = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 979 | (struct pldm_pdr_hdr *)(record->data); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 980 | hdr->record_handle = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 981 | htole32(record->record_handle); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 982 | } |
| 983 | record = record->next; |
| 984 | } |
| 985 | } |
| 986 | } |
| 987 | |
Pavithra Barithaya | 4d69434 | 2023-05-19 08:04:41 -0500 | [diff] [blame] | 988 | LIBPLDM_ABI_TESTING |
| 989 | pldm_pdr_record *pldm_pdr_find_last_in_range(const pldm_pdr *repo, |
| 990 | uint32_t first, uint32_t last) |
| 991 | { |
| 992 | pldm_pdr_record *record = NULL; |
| 993 | pldm_pdr_record *curr; |
| 994 | |
| 995 | if (!repo) { |
| 996 | return NULL; |
| 997 | } |
| 998 | for (curr = repo->first; curr; curr = curr->next) { |
| 999 | if (first > curr->record_handle || last < curr->record_handle) { |
| 1000 | continue; |
| 1001 | } |
| 1002 | if (!record || curr->record_handle > record->record_handle) { |
| 1003 | record = curr; |
| 1004 | } |
| 1005 | } |
| 1006 | |
| 1007 | return record; |
| 1008 | } |
| 1009 | |
Pavithra Barithaya | 9947f9d | 2023-05-18 05:20:24 -0500 | [diff] [blame] | 1010 | static void entity_association_tree_find_if_remote(pldm_entity_node *node, |
| 1011 | pldm_entity *entity, |
| 1012 | pldm_entity_node **out, |
| 1013 | bool is_remote) |
| 1014 | { |
| 1015 | assert(out != NULL && *out == NULL); |
| 1016 | if (node == NULL) { |
| 1017 | return; |
| 1018 | } |
| 1019 | bool is_entity_type; |
| 1020 | bool is_entity_instance_num; |
| 1021 | |
| 1022 | is_entity_type = node->entity.entity_type == entity->entity_type; |
| 1023 | is_entity_instance_num = node->entity.entity_instance_num == |
| 1024 | entity->entity_instance_num; |
| 1025 | |
| 1026 | if (!is_remote || |
| 1027 | node->remote_container_id == entity->entity_container_id) { |
| 1028 | if (is_entity_type && is_entity_instance_num) { |
| 1029 | entity->entity_container_id = |
| 1030 | node->entity.entity_container_id; |
| 1031 | *out = node; |
| 1032 | return; |
| 1033 | } |
| 1034 | } |
| 1035 | entity_association_tree_find_if_remote(node->next_sibling, entity, out, |
| 1036 | is_remote); |
| 1037 | entity_association_tree_find_if_remote(node->first_child, entity, out, |
| 1038 | is_remote); |
| 1039 | } |
| 1040 | |
| 1041 | LIBPLDM_ABI_TESTING |
| 1042 | pldm_entity_node * |
| 1043 | pldm_entity_association_tree_find_if_remote(pldm_entity_association_tree *tree, |
| 1044 | pldm_entity *entity, bool is_remote) |
| 1045 | { |
| 1046 | if (!tree || !entity) { |
| 1047 | return NULL; |
| 1048 | } |
| 1049 | pldm_entity_node *node = NULL; |
| 1050 | entity_association_tree_find_if_remote(tree->root, entity, &node, |
| 1051 | is_remote); |
| 1052 | return node; |
| 1053 | } |
| 1054 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 1055 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1056 | void entity_association_tree_find(pldm_entity_node *node, pldm_entity *entity, |
| 1057 | pldm_entity_node **out) |
| 1058 | { |
| 1059 | if (node == NULL) { |
| 1060 | return; |
| 1061 | } |
| 1062 | |
| 1063 | if (node->entity.entity_type == entity->entity_type && |
| 1064 | node->entity.entity_instance_num == entity->entity_instance_num) { |
| 1065 | entity->entity_container_id = node->entity.entity_container_id; |
| 1066 | *out = node; |
| 1067 | return; |
| 1068 | } |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1069 | entity_association_tree_find(node->next_sibling, entity, out); |
| 1070 | entity_association_tree_find(node->first_child, entity, out); |
| 1071 | } |
| 1072 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 1073 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1074 | pldm_entity_node * |
| 1075 | pldm_entity_association_tree_find(pldm_entity_association_tree *tree, |
| 1076 | pldm_entity *entity) |
| 1077 | { |
| 1078 | assert(tree != NULL); |
| 1079 | |
| 1080 | pldm_entity_node *node = NULL; |
| 1081 | entity_association_tree_find(tree->root, entity, &node); |
| 1082 | return node; |
| 1083 | } |
| 1084 | |
| 1085 | static void entity_association_tree_copy(pldm_entity_node *org_node, |
| 1086 | pldm_entity_node **new_node) |
| 1087 | { |
| 1088 | if (org_node == NULL) { |
| 1089 | return; |
| 1090 | } |
| 1091 | *new_node = malloc(sizeof(pldm_entity_node)); |
| 1092 | (*new_node)->parent = org_node->parent; |
| 1093 | (*new_node)->entity = org_node->entity; |
| 1094 | (*new_node)->association_type = org_node->association_type; |
ArchanaKakani | 39bd2ea | 2023-02-02 02:39:18 -0600 | [diff] [blame] | 1095 | (*new_node)->remote_container_id = org_node->remote_container_id; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1096 | (*new_node)->first_child = NULL; |
| 1097 | (*new_node)->next_sibling = NULL; |
| 1098 | entity_association_tree_copy(org_node->first_child, |
| 1099 | &((*new_node)->first_child)); |
| 1100 | entity_association_tree_copy(org_node->next_sibling, |
| 1101 | &((*new_node)->next_sibling)); |
| 1102 | } |
| 1103 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 1104 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1105 | void pldm_entity_association_tree_copy_root( |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1106 | pldm_entity_association_tree *org_tree, |
| 1107 | pldm_entity_association_tree *new_tree) |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1108 | { |
| 1109 | new_tree->last_used_container_id = org_tree->last_used_container_id; |
| 1110 | entity_association_tree_copy(org_tree->root, &(new_tree->root)); |
| 1111 | } |
| 1112 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 1113 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1114 | void pldm_entity_association_tree_destroy_root( |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1115 | pldm_entity_association_tree *tree) |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1116 | { |
| 1117 | assert(tree != NULL); |
| 1118 | entity_association_tree_destroy(tree->root); |
| 1119 | tree->last_used_container_id = 0; |
| 1120 | tree->root = NULL; |
| 1121 | } |
| 1122 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 1123 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1124 | bool pldm_is_empty_entity_assoc_tree(pldm_entity_association_tree *tree) |
| 1125 | { |
| 1126 | return ((tree->root == NULL) ? true : false); |
| 1127 | } |
| 1128 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 1129 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1130 | void pldm_entity_association_pdr_extract(const uint8_t *pdr, uint16_t pdr_len, |
| 1131 | size_t *num_entities, |
| 1132 | pldm_entity **entities) |
| 1133 | { |
| 1134 | assert(pdr != NULL); |
| 1135 | assert(pdr_len >= sizeof(struct pldm_pdr_hdr) + |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1136 | sizeof(struct pldm_pdr_entity_association)); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1137 | |
| 1138 | struct pldm_pdr_hdr *hdr = (struct pldm_pdr_hdr *)pdr; |
| 1139 | assert(hdr->type == PLDM_PDR_ENTITY_ASSOCIATION); |
| 1140 | |
| 1141 | const uint8_t *start = (uint8_t *)pdr; |
| 1142 | const uint8_t *end = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1143 | start + sizeof(struct pldm_pdr_hdr) + le16toh(hdr->length); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1144 | start += sizeof(struct pldm_pdr_hdr); |
| 1145 | struct pldm_pdr_entity_association *entity_association_pdr = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1146 | (struct pldm_pdr_entity_association *)start; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1147 | *num_entities = entity_association_pdr->num_children + 1; |
| 1148 | assert(*num_entities >= 2); |
| 1149 | *entities = malloc(sizeof(pldm_entity) * *num_entities); |
| 1150 | assert(*entities != NULL); |
| 1151 | assert(start + sizeof(struct pldm_pdr_entity_association) + |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1152 | sizeof(pldm_entity) * (*num_entities - 2) == |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1153 | end); |
| 1154 | (*entities)->entity_type = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1155 | le16toh(entity_association_pdr->container.entity_type); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1156 | (*entities)->entity_instance_num = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1157 | le16toh(entity_association_pdr->container.entity_instance_num); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1158 | (*entities)->entity_container_id = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1159 | le16toh(entity_association_pdr->container.entity_container_id); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1160 | pldm_entity *curr_entity = entity_association_pdr->children; |
| 1161 | size_t i = 1; |
| 1162 | while (i < *num_entities) { |
| 1163 | (*entities + i)->entity_type = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1164 | le16toh(curr_entity->entity_type); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1165 | (*entities + i)->entity_instance_num = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1166 | le16toh(curr_entity->entity_instance_num); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1167 | (*entities + i)->entity_container_id = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1168 | le16toh(curr_entity->entity_container_id); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1169 | ++curr_entity; |
| 1170 | ++i; |
| 1171 | } |
| 1172 | } |