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