This repository has been archived by the owner on Jul 22, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
/
SpdmResponderLib.h
310 lines (260 loc) · 13.2 KB
/
SpdmResponderLib.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
/** @file
SPDM common library.
It follows the SPDM Specification.
Copyright (c) 2020, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#ifndef __SPDM_RESPONDER_LIB_H__
#define __SPDM_RESPONDER_LIB_H__
#include <Library/SpdmCommonLib.h>
/**
Process the SPDM or APP request and return the response.
The APP message is encoded to a secured message directly in SPDM session.
The APP message format is defined by the transport layer.
Take MCTP as example: APP message == MCTP header (MCTP_MESSAGE_TYPE_SPDM) + SPDM message
@param SpdmContext A pointer to the SPDM context.
@param SessionId Indicates if it is a secured message protected via SPDM session.
If SessionId is NULL, it is a normal message.
If SessionId is NOT NULL, it is a secured message.
@param IsAppMessage Indicates if it is an APP message or SPDM message.
@param RequestSize Size in bytes of the request data.
@param Request A pointer to the request data.
@param ResponseSize Size in bytes of the response data.
On input, it means the size in bytes of response data buffer.
On output, it means the size in bytes of copied response data buffer if RETURN_SUCCESS is returned,
and means the size in bytes of desired response data buffer if RETURN_BUFFER_TOO_SMALL is returned.
@param Response A pointer to the response data.
@retval RETURN_SUCCESS The request is processed and the response is returned.
@retval RETURN_BUFFER_TOO_SMALL The buffer is too small to hold the data.
@retval RETURN_DEVICE_ERROR A device error occurs when communicates with the device.
@retval RETURN_SECURITY_VIOLATION Any verification fails.
**/
typedef
RETURN_STATUS
(EFIAPI *SPDM_GET_RESPONSE_FUNC) (
IN VOID *SpdmContext,
IN UINT32 *SessionId,
IN BOOLEAN IsAppMessage,
IN UINTN RequestSize,
IN VOID *Request,
IN OUT UINTN *ResponseSize,
OUT VOID *Response
);
/**
Register an SPDM or APP message process function.
If the default message process function cannot handle the message,
this function will be invoked.
@param SpdmContext A pointer to the SPDM context.
@param GetResponseFunc The function to process the encapsuled message.
**/
VOID
EFIAPI
SpdmRegisterGetResponseFunc (
IN VOID *SpdmContext,
IN SPDM_GET_RESPONSE_FUNC GetResponseFunc
);
/**
Process a SPDM request from a device.
@param SpdmContext The SPDM context for the device.
@param SessionId Indicate if the request is a secured message.
If SessionId is NULL, it is a normal message.
If SessionId is NOT NULL, it is a secured message.
@param IsAppMessage Indicates if it is an APP message or SPDM message.
@param RequestSize Size in bytes of the request data buffer.
@param Request A pointer to a destination buffer to store the request.
The caller is responsible for having
either implicit or explicit ownership of the buffer.
@retval RETURN_SUCCESS The SPDM request is received successfully.
@retval RETURN_DEVICE_ERROR A device error occurs when the SPDM request is received from the device.
**/
RETURN_STATUS
EFIAPI
SpdmProcessRequest (
IN VOID *SpdmContext,
OUT UINT32 **SessionId,
OUT BOOLEAN *IsAppMessage,
IN UINTN RequestSize,
IN VOID *Request
);
/**
Build a SPDM response to a device.
@param SpdmContext The SPDM context for the device.
@param SessionId Indicate if the response is a secured message.
If SessionId is NULL, it is a normal message.
If SessionId is NOT NULL, it is a secured message.
@param IsAppMessage Indicates if it is an APP message or SPDM message.
@param ResponseSize Size in bytes of the response data buffer.
@param Response A pointer to a destination buffer to store the response.
The caller is responsible for having
either implicit or explicit ownership of the buffer.
@retval RETURN_SUCCESS The SPDM response is sent successfully.
@retval RETURN_DEVICE_ERROR A device error occurs when the SPDM response is sent to the device.
**/
RETURN_STATUS
EFIAPI
SpdmBuildResponse (
IN VOID *SpdmContext,
IN UINT32 *SessionId,
IN BOOLEAN IsAppMessage,
IN OUT UINTN *ResponseSize,
OUT VOID *Response
);
/**
Process a transport layer message.
The message can be a normal message or a secured message in SPDM session.
The message can be an SPDM message or an APP message.
This function is called in SpdmResponderDispatchMessage to process the message.
The alternative is: an SPDM responder may receive the request message directly
and call this function to process it, then send the response message.
@param SpdmContext A pointer to the SPDM context.
@param SessionId Indicates if it is a secured message protected via SPDM session.
If *SessionId is NULL, it is a normal message.
If *SessionId is NOT NULL, it is a secured message.
@param Request A pointer to the request data.
@param RequestSize Size in bytes of the request data.
@param Response A pointer to the response data.
@param ResponseSize Size in bytes of the response data.
On input, it means the size in bytes of response data buffer.
On output, it means the size in bytes of copied response data buffer if RETURN_SUCCESS is returned,
and means the size in bytes of desired response data buffer if RETURN_BUFFER_TOO_SMALL is returned.
@retval RETURN_SUCCESS The SPDM request is set successfully.
@retval RETURN_BUFFER_TOO_SMALL The buffer is too small to hold the data.
@retval RETURN_DEVICE_ERROR A device error occurs when communicates with the device.
@retval RETURN_SECURITY_VIOLATION Any verification fails.
**/
RETURN_STATUS
EFIAPI
SpdmProcessMessage (
IN VOID *Context,
IN OUT UINT32 **SessionId,
IN VOID *Request,
IN UINTN RequestSize,
OUT VOID *Response,
IN OUT UINTN *ResponseSize
);
/**
This is the main dispatch function in SPDM responder.
It receives one request message, processes it and sends the response message.
It should be called in a while loop or an timer/interrupt handler.
@param SpdmContext A pointer to the SPDM context.
@retval RETURN_SUCCESS One SPDM request message is processed.
@retval RETURN_DEVICE_ERROR A device error occurs when communicates with the device.
@retval RETURN_UNSUPPORTED One request message is not supported.
**/
RETURN_STATUS
EFIAPI
SpdmResponderDispatchMessage (
IN VOID *SpdmContext
);
/**
Generate ERROR message.
This function can be called in SPDM_GET_RESPONSE_FUNC.
@param SpdmContext A pointer to the SPDM context.
@param ErrorCode The error code of the message.
@param ErrorData The error data of the message.
@param SpdmResponseSize Size in bytes of the response data.
On input, it means the size in bytes of response data buffer.
On output, it means the size in bytes of copied response data buffer if RETURN_SUCCESS is returned,
and means the size in bytes of desired response data buffer if RETURN_BUFFER_TOO_SMALL is returned.
@param SpdmResponse A pointer to the response data.
@retval RETURN_SUCCESS The error message is generated.
@retval RETURN_BUFFER_TOO_SMALL The buffer is too small to hold the data.
**/
RETURN_STATUS
EFIAPI
SpdmGenerateErrorResponse (
IN VOID *SpdmContext,
IN UINT8 ErrorCode,
IN UINT8 ErrorData,
IN OUT UINTN *SpdmResponseSize,
OUT VOID *SpdmResponse
);
/**
Generate ERROR message with extended error data.
This function can be called in SPDM_GET_RESPONSE_FUNC.
@param SpdmContext A pointer to the SPDM context.
@param ErrorCode The error code of the message.
@param ErrorData The error data of the message.
@param ExtendedErrorDataSize The size in bytes of the extended error data.
@param ExtendedErrorData A pointer to the extended error data.
@param SpdmResponseSize Size in bytes of the response data.
On input, it means the size in bytes of response data buffer.
On output, it means the size in bytes of copied response data buffer if RETURN_SUCCESS is returned,
and means the size in bytes of desired response data buffer if RETURN_BUFFER_TOO_SMALL is returned.
@param SpdmResponse A pointer to the response data.
@retval RETURN_SUCCESS The error message is generated.
@retval RETURN_BUFFER_TOO_SMALL The buffer is too small to hold the data.
**/
RETURN_STATUS
EFIAPI
SpdmGenerateExtendedErrorResponse (
IN VOID *Context,
IN UINT8 ErrorCode,
IN UINT8 ErrorData,
IN UINTN ExtendedErrorDataSize,
IN UINT8 *ExtendedErrorData,
IN OUT UINTN *SpdmResponseSize,
OUT VOID *SpdmResponse
);
/**
Notify the session state to a session APP.
@param SpdmContext A pointer to the SPDM context.
@param SessionId The SessionId of a session.
@param SessionState The state of a session.
**/
typedef
VOID
(EFIAPI *SPDM_SESSION_STATE_CALLBACK) (
IN VOID *SpdmContext,
IN UINT32 SessionId,
IN SPDM_SESSION_STATE SessionState
);
/**
Register an SPDM state callback function.
This function can be called multiple times to let different session APPs register its own callback.
@param SpdmContext A pointer to the SPDM context.
@param SpdmSessionStateCallback The function to be called in SPDM session state change.
@retval RETURN_SUCCESS The callback is registered.
@retval RETURN_ALREADY_STARTED No enough memory to register the callback.
**/
RETURN_STATUS
EFIAPI
SpdmRegisterSessionStateCallback (
IN VOID *SpdmContext,
IN SPDM_SESSION_STATE_CALLBACK SpdmSessionStateCallback
);
/**
Notify the connection state to an SPDM context register.
@param SpdmContext A pointer to the SPDM context.
@param ConnectionState Indicate the SPDM connection state.
**/
typedef
VOID
(EFIAPI *SPDM_CONNECTION_STATE_CALLBACK) (
IN VOID *SpdmContext,
IN SPDM_CONNECTION_STATE ConnectionState
);
/**
Register an SPDM connection state callback function.
This function can be called multiple times to let different register its own callback.
@param SpdmContext A pointer to the SPDM context.
@param SpdmConnectionStateCallback The function to be called in SPDM connection state change.
@retval RETURN_SUCCESS The callback is registered.
@retval RETURN_ALREADY_STARTED No enough memory to register the callback.
**/
RETURN_STATUS
EFIAPI
SpdmRegisterConnectionStateCallback (
IN VOID *SpdmContext,
IN SPDM_CONNECTION_STATE_CALLBACK SpdmConnectionStateCallback
);
/**
This function initializes the key_update encapsulated state.
@param SpdmContext A pointer to the SPDM context.
**/
VOID
EFIAPI
SpdmInitKeyUpdateEncapState (
IN VOID *SpdmContext
);
#endif