blob: 8e70e4a4c7f22d901d51d3e2b03404d1bc417433 [file] [log] [blame]
Patrick Williams691668f2023-11-01 08:19:10 -05001/* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later */
Andrew Jefferycc45aed2023-09-10 23:03:29 +09302#include "responder.h"
3
4#include <libpldm/base.h>
Andrew Jefferyd12dd362023-11-10 15:36:38 +10305#include <libpldm/pldm.h>
Andrew Jefferycc45aed2023-09-10 23:03:29 +09306
7#include <stdbool.h>
8
9static 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
17int 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
44struct pldm_responder_cookie *
45pldm_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}