1 /* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later */ 2 #include "responder.h" 3 4 #include <libpldm/base.h> 5 #include <libpldm/pldm.h> 6 7 #include <stdbool.h> 8 9 static bool pldm_responder_cookie_eq(const struct pldm_responder_cookie *left, 10 const struct pldm_responder_cookie *right) 11 { 12 return left->tid == right->tid && 13 left->instance_id == right->instance_id && 14 left->type == right->type && left->command == right->command; 15 } 16 17 int pldm_responder_cookie_track(struct pldm_responder_cookie *jar, 18 struct pldm_responder_cookie *cookie) 19 { 20 struct pldm_responder_cookie *current; 21 struct pldm_responder_cookie *next; 22 23 if (!jar || !cookie) { 24 return PLDM_REQUESTER_INVALID_SETUP; 25 } 26 27 current = jar; 28 next = current->next; 29 while (next) { 30 /* Cookie must not already be known */ 31 if (pldm_responder_cookie_eq(next, cookie)) { 32 return PLDM_REQUESTER_INVALID_SETUP; 33 } 34 current = next; 35 next = next->next; 36 } 37 38 cookie->next = NULL; 39 current->next = cookie; 40 41 return PLDM_REQUESTER_SUCCESS; 42 } 43 44 struct pldm_responder_cookie * 45 pldm_responder_cookie_untrack(struct pldm_responder_cookie *jar, pldm_tid_t tid, 46 pldm_instance_id_t instance_id, uint8_t type, 47 uint8_t command) 48 { 49 const struct pldm_responder_cookie cookie = { tid, instance_id, type, 50 command, NULL }; 51 struct pldm_responder_cookie *current; 52 struct pldm_responder_cookie *next; 53 54 if (!jar) { 55 return NULL; 56 } 57 58 current = jar; 59 next = current->next; 60 while (next && !pldm_responder_cookie_eq(next, &cookie)) { 61 current = next; 62 next = next->next; 63 } 64 65 if (next) { 66 current->next = next->next; 67 } 68 69 return next; 70 } 71