]>
Commit | Line | Data |
---|---|---|
b9d5a7f1 LG |
1 | /** @file\r |
2 | Provide generic extract guided section functions.\r | |
3 | \r | |
9095d37b | 4 | Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>\r |
9344f092 | 5 | SPDX-License-Identifier: BSD-2-Clause-Patent\r |
b9d5a7f1 LG |
6 | \r |
7 | **/\r | |
8 | \r | |
9 | #include <PiPei.h>\r | |
10 | \r | |
11 | #include <Library/DebugLib.h>\r | |
12 | #include <Library/PcdLib.h>\r | |
13 | #include <Library/BaseMemoryLib.h>\r | |
14 | #include <Library/ExtractGuidedSectionLib.h>\r | |
15 | \r | |
2f88bd3a | 16 | #define EXTRACT_HANDLER_INFO_SIGNATURE SIGNATURE_32 ('E', 'G', 'S', 'I')\r |
b9d5a7f1 LG |
17 | \r |
18 | typedef struct {\r | |
2f88bd3a MK |
19 | UINT32 Signature;\r |
20 | UINT32 NumberOfExtractHandler;\r | |
21 | GUID *ExtractHandlerGuidTable;\r | |
22 | EXTRACT_GUIDED_SECTION_DECODE_HANDLER *ExtractDecodeHandlerTable;\r | |
23 | EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER *ExtractGetInfoHandlerTable;\r | |
b9d5a7f1 LG |
24 | } EXTRACT_GUIDED_SECTION_HANDLER_INFO;\r |
25 | \r | |
26 | /**\r | |
9095d37b LG |
27 | HandlerInfo table address is set by PcdGuidedExtractHandlerTableAddress, which is used to store\r |
28 | the registered guid and Handler list. When it is initialized, it will be directly returned.\r | |
b9d5a7f1 LG |
29 | Or, HandlerInfo table will be initialized in this function.\r |
30 | \r | |
58380e9c | 31 | @param[in, out] InfoPointer The pointer to the handler information structure.\r |
b9d5a7f1 LG |
32 | \r |
33 | @retval RETURN_SUCCESS HandlerInfo table can be used to store guid and function tables.\r | |
34 | @retval RETURN_OUT_OF_RESOURCES HandlerInfo table address is not writable.\r | |
35 | **/\r | |
36 | RETURN_STATUS\r | |
37 | GetExtractGuidedSectionHandlerInfo (\r | |
2f88bd3a | 38 | IN OUT EXTRACT_GUIDED_SECTION_HANDLER_INFO **InfoPointer\r |
b9d5a7f1 LG |
39 | )\r |
40 | {\r | |
2f88bd3a | 41 | EXTRACT_GUIDED_SECTION_HANDLER_INFO *HandlerInfo;\r |
9095d37b | 42 | \r |
b9d5a7f1 LG |
43 | //\r |
44 | // Set the available memory address to handler info.\r | |
45 | //\r | |
2f88bd3a | 46 | HandlerInfo = (EXTRACT_GUIDED_SECTION_HANDLER_INFO *)(VOID *)(UINTN)PcdGet64 (PcdGuidedExtractHandlerTableAddress);\r |
3dbef428 ED |
47 | if (HandlerInfo == NULL) {\r |
48 | *InfoPointer = NULL;\r | |
49 | return EFI_OUT_OF_RESOURCES;\r | |
50 | }\r | |
b9d5a7f1 LG |
51 | \r |
52 | //\r | |
58380e9c | 53 | // First check whether the handler information structure is initialized.\r |
b9d5a7f1 LG |
54 | //\r |
55 | if (HandlerInfo->Signature == EXTRACT_HANDLER_INFO_SIGNATURE) {\r | |
56 | //\r | |
58380e9c | 57 | // The handler information has been initialized and is returned.\r |
b9d5a7f1 LG |
58 | //\r |
59 | *InfoPointer = HandlerInfo;\r | |
60 | return RETURN_SUCCESS;\r | |
61 | }\r | |
62 | \r | |
63 | //\r | |
58380e9c | 64 | // Try to initialize the handler information structure\r |
b9d5a7f1 LG |
65 | //\r |
66 | HandlerInfo->Signature = EXTRACT_HANDLER_INFO_SIGNATURE;\r | |
67 | if (HandlerInfo->Signature != EXTRACT_HANDLER_INFO_SIGNATURE) {\r | |
68 | //\r | |
58380e9c | 69 | // The handler information structure was not writeable because the memory is not ready.\r |
b9d5a7f1 LG |
70 | //\r |
71 | *InfoPointer = NULL;\r | |
72 | return RETURN_OUT_OF_RESOURCES;\r | |
73 | }\r | |
74 | \r | |
75 | //\r | |
76 | // Init HandlerInfo structure\r | |
77 | //\r | |
2f88bd3a MK |
78 | HandlerInfo->NumberOfExtractHandler = 0;\r |
79 | HandlerInfo->ExtractHandlerGuidTable = (GUID *)(HandlerInfo + 1);\r | |
80 | HandlerInfo->ExtractDecodeHandlerTable = (EXTRACT_GUIDED_SECTION_DECODE_HANDLER *)(\r | |
81 | (UINT8 *)HandlerInfo->ExtractHandlerGuidTable +\r | |
82 | PcdGet32 (PcdMaximumGuidedExtractHandler) * sizeof (GUID)\r | |
83 | );\r | |
84 | HandlerInfo->ExtractGetInfoHandlerTable = (EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER *)(\r | |
85 | (UINT8 *)HandlerInfo->ExtractDecodeHandlerTable +\r | |
86 | PcdGet32 (PcdMaximumGuidedExtractHandler) *\r | |
87 | sizeof (EXTRACT_GUIDED_SECTION_DECODE_HANDLER)\r | |
88 | );\r | |
b9d5a7f1 LG |
89 | *InfoPointer = HandlerInfo;\r |
90 | return RETURN_SUCCESS;\r | |
91 | }\r | |
92 | \r | |
93 | /**\r | |
94 | Retrieve the list GUIDs that have been registered through ExtractGuidedSectionRegisterHandlers().\r | |
95 | \r | |
96 | Sets ExtractHandlerGuidTable so it points at a callee allocated array of registered GUIDs.\r | |
97 | The total number of GUIDs in the array are returned. Since the array of GUIDs is callee allocated\r | |
9095d37b | 98 | and caller must treat this array of GUIDs as read-only data.\r |
b9d5a7f1 LG |
99 | If ExtractHandlerGuidTable is NULL, then ASSERT().\r |
100 | \r | |
101 | @param[out] ExtractHandlerGuidTable A pointer to the array of GUIDs that have been registered through\r | |
102 | ExtractGuidedSectionRegisterHandlers().\r | |
103 | \r | |
35a17154 | 104 | @return The number of the supported extract guided Handler.\r |
b9d5a7f1 LG |
105 | \r |
106 | **/\r | |
107 | UINTN\r | |
108 | EFIAPI\r | |
109 | ExtractGuidedSectionGetGuidList (\r | |
110 | OUT GUID **ExtractHandlerGuidTable\r | |
111 | )\r | |
112 | {\r | |
2f88bd3a MK |
113 | RETURN_STATUS Status;\r |
114 | EXTRACT_GUIDED_SECTION_HANDLER_INFO *HandlerInfo;\r | |
b9d5a7f1 LG |
115 | \r |
116 | ASSERT (ExtractHandlerGuidTable != NULL);\r | |
117 | \r | |
118 | //\r | |
119 | // Get all registered handler information\r | |
120 | //\r | |
121 | Status = GetExtractGuidedSectionHandlerInfo (&HandlerInfo);\r | |
122 | if (RETURN_ERROR (Status)) {\r | |
123 | *ExtractHandlerGuidTable = NULL;\r | |
124 | return 0;\r | |
125 | }\r | |
126 | \r | |
127 | //\r | |
128 | // Get GuidTable and Table Number\r | |
129 | //\r | |
3dbef428 | 130 | ASSERT (HandlerInfo != NULL);\r |
b9d5a7f1 LG |
131 | *ExtractHandlerGuidTable = HandlerInfo->ExtractHandlerGuidTable;\r |
132 | return HandlerInfo->NumberOfExtractHandler;\r | |
133 | }\r | |
134 | \r | |
135 | /**\r | |
136 | Registers handlers of type EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER and EXTRACT_GUIDED_SECTION_DECODE_HANDLER\r | |
137 | for a specific GUID section type.\r | |
138 | \r | |
139 | Registers the handlers specified by GetInfoHandler and DecodeHandler with the GUID specified by SectionGuid.\r | |
140 | If the GUID value specified by SectionGuid has already been registered, then return RETURN_ALREADY_STARTED.\r | |
141 | If there are not enough resources available to register the handlers then RETURN_OUT_OF_RESOURCES is returned.\r | |
9095d37b | 142 | \r |
b9d5a7f1 LG |
143 | If SectionGuid is NULL, then ASSERT().\r |
144 | If GetInfoHandler is NULL, then ASSERT().\r | |
145 | If DecodeHandler is NULL, then ASSERT().\r | |
146 | \r | |
147 | @param[in] SectionGuid A pointer to the GUID associated with the the handlers\r | |
148 | of the GUIDed section type being registered.\r | |
2fc59a00 | 149 | @param[in] GetInfoHandler The pointer to a function that examines a GUIDed section and returns the\r |
b9d5a7f1 LG |
150 | size of the decoded buffer and the size of an optional scratch buffer\r |
151 | required to actually decode the data in a GUIDed section.\r | |
2fc59a00 | 152 | @param[in] DecodeHandler The pointer to a function that decodes a GUIDed section into a caller\r |
9095d37b | 153 | allocated output buffer.\r |
b9d5a7f1 LG |
154 | \r |
155 | @retval RETURN_SUCCESS The handlers were registered.\r | |
156 | @retval RETURN_OUT_OF_RESOURCES There are not enough resources available to register the handlers.\r | |
157 | \r | |
158 | **/\r | |
159 | RETURN_STATUS\r | |
160 | EFIAPI\r | |
161 | ExtractGuidedSectionRegisterHandlers (\r | |
162 | IN CONST GUID *SectionGuid,\r | |
163 | IN EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER GetInfoHandler,\r | |
164 | IN EXTRACT_GUIDED_SECTION_DECODE_HANDLER DecodeHandler\r | |
165 | )\r | |
166 | {\r | |
2f88bd3a MK |
167 | UINT32 Index;\r |
168 | RETURN_STATUS Status;\r | |
169 | EXTRACT_GUIDED_SECTION_HANDLER_INFO *HandlerInfo;\r | |
b9d5a7f1 LG |
170 | \r |
171 | //\r | |
3868d06d | 172 | // Check input parameter\r |
b9d5a7f1 LG |
173 | //\r |
174 | ASSERT (SectionGuid != NULL);\r | |
175 | ASSERT (GetInfoHandler != NULL);\r | |
176 | ASSERT (DecodeHandler != NULL);\r | |
177 | \r | |
178 | //\r | |
179 | // Get the registered handler information\r | |
180 | //\r | |
181 | Status = GetExtractGuidedSectionHandlerInfo (&HandlerInfo);\r | |
182 | if (RETURN_ERROR (Status)) {\r | |
183 | return Status;\r | |
184 | }\r | |
185 | \r | |
186 | //\r | |
187 | // Search the match registered GetInfo handler for the input guided section.\r | |
188 | //\r | |
3dbef428 | 189 | ASSERT (HandlerInfo != NULL);\r |
2f88bd3a | 190 | for (Index = 0; Index < HandlerInfo->NumberOfExtractHandler; Index++) {\r |
b9d5a7f1 LG |
191 | if (CompareGuid (HandlerInfo->ExtractHandlerGuidTable + Index, SectionGuid)) {\r |
192 | //\r | |
193 | // If the guided handler has been registered before, only update its handler.\r | |
194 | //\r | |
2f88bd3a MK |
195 | HandlerInfo->ExtractDecodeHandlerTable[Index] = DecodeHandler;\r |
196 | HandlerInfo->ExtractGetInfoHandlerTable[Index] = GetInfoHandler;\r | |
b9d5a7f1 LG |
197 | return RETURN_SUCCESS;\r |
198 | }\r | |
199 | }\r | |
200 | \r | |
201 | //\r | |
202 | // Check the global table is enough to contain new Handler.\r | |
203 | //\r | |
204 | if (HandlerInfo->NumberOfExtractHandler >= PcdGet32 (PcdMaximumGuidedExtractHandler)) {\r | |
205 | return RETURN_OUT_OF_RESOURCES;\r | |
206 | }\r | |
9095d37b | 207 | \r |
b9d5a7f1 LG |
208 | //\r |
209 | // Register new Handler and guid value.\r | |
210 | //\r | |
211 | CopyGuid (HandlerInfo->ExtractHandlerGuidTable + HandlerInfo->NumberOfExtractHandler, SectionGuid);\r | |
2f88bd3a MK |
212 | HandlerInfo->ExtractDecodeHandlerTable[HandlerInfo->NumberOfExtractHandler] = DecodeHandler;\r |
213 | HandlerInfo->ExtractGetInfoHandlerTable[HandlerInfo->NumberOfExtractHandler++] = GetInfoHandler;\r | |
b9d5a7f1 LG |
214 | \r |
215 | return RETURN_SUCCESS;\r | |
216 | }\r | |
217 | \r | |
218 | /**\r | |
219 | Retrieves a GUID from a GUIDed section and uses that GUID to select an associated handler of type\r | |
220 | EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER that was registered with ExtractGuidedSectionRegisterHandlers().\r | |
221 | The selected handler is used to retrieve and return the size of the decoded buffer and the size of an\r | |
222 | optional scratch buffer required to actually decode the data in a GUIDed section.\r | |
223 | \r | |
9095d37b | 224 | Examines a GUIDed section specified by InputSection.\r |
b9d5a7f1 | 225 | If GUID for InputSection does not match any of the GUIDs registered through ExtractGuidedSectionRegisterHandlers(),\r |
9095d37b LG |
226 | then RETURN_UNSUPPORTED is returned.\r |
227 | If the GUID of InputSection does match the GUID that this handler supports, then the the associated handler\r | |
b9d5a7f1 LG |
228 | of type EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER that was registered with ExtractGuidedSectionRegisterHandlers()\r |
229 | is used to retrieve the OututBufferSize, ScratchSize, and Attributes values. The return status from the handler of\r | |
230 | type EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER is returned.\r | |
9095d37b | 231 | \r |
b9d5a7f1 LG |
232 | If InputSection is NULL, then ASSERT().\r |
233 | If OutputBufferSize is NULL, then ASSERT().\r | |
234 | If ScratchBufferSize is NULL, then ASSERT().\r | |
235 | If SectionAttribute is NULL, then ASSERT().\r | |
236 | \r | |
237 | @param[in] InputSection A pointer to a GUIDed section of an FFS formatted file.\r | |
238 | @param[out] OutputBufferSize A pointer to the size, in bytes, of an output buffer required if the buffer\r | |
239 | specified by InputSection were decoded.\r | |
240 | @param[out] ScratchBufferSize A pointer to the size, in bytes, required as scratch space if the buffer specified by\r | |
241 | InputSection were decoded.\r | |
242 | @param[out] SectionAttribute A pointer to the attributes of the GUIDed section. See the Attributes field of\r | |
243 | EFI_GUID_DEFINED_SECTION in the PI Specification.\r | |
244 | \r | |
35a17154 | 245 | @retval RETURN_SUCCESS Successfully retrieved the required information.\r |
b9d5a7f1 LG |
246 | @retval RETURN_UNSUPPORTED The GUID from the section specified by InputSection does not match any of\r |
247 | the GUIDs registered with ExtractGuidedSectionRegisterHandlers().\r | |
248 | @retval Others The return status from the handler associated with the GUID retrieved from\r | |
249 | the section specified by InputSection.\r | |
250 | \r | |
251 | **/\r | |
252 | RETURN_STATUS\r | |
253 | EFIAPI\r | |
254 | ExtractGuidedSectionGetInfo (\r | |
255 | IN CONST VOID *InputSection,\r | |
256 | OUT UINT32 *OutputBufferSize,\r | |
257 | OUT UINT32 *ScratchBufferSize,\r | |
9095d37b | 258 | OUT UINT16 *SectionAttribute\r |
b9d5a7f1 LG |
259 | )\r |
260 | {\r | |
2f88bd3a MK |
261 | UINT32 Index;\r |
262 | RETURN_STATUS Status;\r | |
263 | EXTRACT_GUIDED_SECTION_HANDLER_INFO *HandlerInfo;\r | |
264 | EFI_GUID *SectionDefinitionGuid;\r | |
9095d37b | 265 | \r |
b9d5a7f1 | 266 | //\r |
3868d06d | 267 | // Check input parameter\r |
b9d5a7f1 LG |
268 | //\r |
269 | ASSERT (InputSection != NULL);\r | |
270 | ASSERT (OutputBufferSize != NULL);\r | |
271 | ASSERT (ScratchBufferSize != NULL);\r | |
272 | ASSERT (SectionAttribute != NULL);\r | |
273 | \r | |
274 | //\r | |
275 | // Get all registered handler information.\r | |
276 | //\r | |
277 | Status = GetExtractGuidedSectionHandlerInfo (&HandlerInfo);\r | |
278 | if (RETURN_ERROR (Status)) {\r | |
279 | return Status;\r | |
280 | }\r | |
281 | \r | |
30f001ca | 282 | if (IS_SECTION2 (InputSection)) {\r |
2f88bd3a | 283 | SectionDefinitionGuid = &(((EFI_GUID_DEFINED_SECTION2 *)InputSection)->SectionDefinitionGuid);\r |
30f001ca | 284 | } else {\r |
2f88bd3a | 285 | SectionDefinitionGuid = &(((EFI_GUID_DEFINED_SECTION *)InputSection)->SectionDefinitionGuid);\r |
30f001ca SZ |
286 | }\r |
287 | \r | |
b9d5a7f1 LG |
288 | //\r |
289 | // Search the match registered GetInfo handler for the input guided section.\r | |
290 | //\r | |
3dbef428 | 291 | ASSERT (HandlerInfo != NULL);\r |
2f88bd3a | 292 | for (Index = 0; Index < HandlerInfo->NumberOfExtractHandler; Index++) {\r |
30f001ca | 293 | if (CompareGuid (HandlerInfo->ExtractHandlerGuidTable + Index, SectionDefinitionGuid)) {\r |
b9d5a7f1 | 294 | //\r |
58380e9c | 295 | // Call the match handler to get information for the input section data.\r |
b9d5a7f1 | 296 | //\r |
2f88bd3a MK |
297 | return HandlerInfo->ExtractGetInfoHandlerTable[Index](\r |
298 | InputSection,\r | |
299 | OutputBufferSize,\r | |
300 | ScratchBufferSize,\r | |
301 | SectionAttribute\r | |
302 | );\r | |
b9d5a7f1 LG |
303 | }\r |
304 | }\r | |
305 | \r | |
306 | //\r | |
9095d37b | 307 | // Not found, the input guided section is not supported.\r |
b9d5a7f1 LG |
308 | //\r |
309 | return RETURN_UNSUPPORTED;\r | |
310 | }\r | |
311 | \r | |
312 | /**\r | |
313 | Retrieves the GUID from a GUIDed section and uses that GUID to select an associated handler of type\r | |
314 | EXTRACT_GUIDED_SECTION_DECODE_HANDLER that was registered with ExtractGuidedSectionRegisterHandlers().\r | |
315 | The selected handler is used to decode the data in a GUIDed section and return the result in a caller\r | |
316 | allocated output buffer.\r | |
317 | \r | |
9095d37b | 318 | Decodes the GUIDed section specified by InputSection.\r |
b9d5a7f1 | 319 | If GUID for InputSection does not match any of the GUIDs registered through ExtractGuidedSectionRegisterHandlers(),\r |
9095d37b | 320 | then RETURN_UNSUPPORTED is returned.\r |
b9d5a7f1 LG |
321 | If the GUID of InputSection does match the GUID that this handler supports, then the the associated handler\r |
322 | of type EXTRACT_GUIDED_SECTION_DECODE_HANDLER that was registered with ExtractGuidedSectionRegisterHandlers()\r | |
323 | is used to decode InputSection into the buffer specified by OutputBuffer and the authentication status of this\r | |
324 | decode operation is returned in AuthenticationStatus. If the decoded buffer is identical to the data in InputSection,\r | |
35a17154 | 325 | then OutputBuffer is set to point at the data in InputSection. Otherwise, the decoded data will be placed in a caller\r |
b9d5a7f1 | 326 | allocated buffer specified by OutputBuffer. This function is responsible for computing the EFI_AUTH_STATUS_PLATFORM_OVERRIDE\r |
9095d37b LG |
327 | bit of in AuthenticationStatus. The return status from the handler of type EXTRACT_GUIDED_SECTION_DECODE_HANDLER is returned.\r |
328 | \r | |
b9d5a7f1 LG |
329 | If InputSection is NULL, then ASSERT().\r |
330 | If OutputBuffer is NULL, then ASSERT().\r | |
331 | If ScratchBuffer is NULL and this decode operation requires a scratch buffer, then ASSERT().\r | |
9095d37b | 332 | If AuthenticationStatus is NULL, then ASSERT().\r |
b9d5a7f1 LG |
333 | \r |
334 | @param[in] InputSection A pointer to a GUIDed section of an FFS formatted file.\r | |
9095d37b LG |
335 | @param[out] OutputBuffer A pointer to a buffer that contains the result of a decode operation.\r |
336 | @param[in] ScratchBuffer A caller allocated buffer that may be required by this function as a scratch buffer to perform the decode operation.\r | |
337 | @param[out] AuthenticationStatus\r | |
b9d5a7f1 LG |
338 | A pointer to the authentication status of the decoded output buffer. See the definition\r |
339 | of authentication status in the EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI section of the PI\r | |
340 | Specification.\r | |
341 | \r | |
342 | @retval RETURN_SUCCESS The buffer specified by InputSection was decoded.\r | |
343 | @retval RETURN_UNSUPPORTED The section specified by InputSection does not match the GUID this handler supports.\r | |
344 | @retval RETURN_INVALID_PARAMETER The section specified by InputSection can not be decoded.\r | |
345 | \r | |
346 | **/\r | |
347 | RETURN_STATUS\r | |
348 | EFIAPI\r | |
349 | ExtractGuidedSectionDecode (\r | |
350 | IN CONST VOID *InputSection,\r | |
351 | OUT VOID **OutputBuffer,\r | |
d0e2f823 | 352 | IN VOID *ScratchBuffer OPTIONAL,\r |
9095d37b | 353 | OUT UINT32 *AuthenticationStatus\r |
b9d5a7f1 LG |
354 | )\r |
355 | {\r | |
2f88bd3a MK |
356 | UINT32 Index;\r |
357 | RETURN_STATUS Status;\r | |
358 | EXTRACT_GUIDED_SECTION_HANDLER_INFO *HandlerInfo;\r | |
359 | EFI_GUID *SectionDefinitionGuid;\r | |
9095d37b | 360 | \r |
b9d5a7f1 LG |
361 | //\r |
362 | // Check input parameter\r | |
363 | //\r | |
364 | ASSERT (InputSection != NULL);\r | |
365 | ASSERT (OutputBuffer != NULL);\r | |
366 | ASSERT (AuthenticationStatus != NULL);\r | |
367 | \r | |
368 | //\r | |
369 | // Get all registered handler information.\r | |
9095d37b | 370 | //\r |
b9d5a7f1 LG |
371 | Status = GetExtractGuidedSectionHandlerInfo (&HandlerInfo);\r |
372 | if (RETURN_ERROR (Status)) {\r | |
373 | return Status;\r | |
374 | }\r | |
375 | \r | |
30f001ca | 376 | if (IS_SECTION2 (InputSection)) {\r |
2f88bd3a | 377 | SectionDefinitionGuid = &(((EFI_GUID_DEFINED_SECTION2 *)InputSection)->SectionDefinitionGuid);\r |
30f001ca | 378 | } else {\r |
2f88bd3a | 379 | SectionDefinitionGuid = &(((EFI_GUID_DEFINED_SECTION *)InputSection)->SectionDefinitionGuid);\r |
30f001ca SZ |
380 | }\r |
381 | \r | |
b9d5a7f1 LG |
382 | //\r |
383 | // Search the match registered Extract handler for the input guided section.\r | |
384 | //\r | |
3dbef428 | 385 | ASSERT (HandlerInfo != NULL);\r |
2f88bd3a | 386 | for (Index = 0; Index < HandlerInfo->NumberOfExtractHandler; Index++) {\r |
30f001ca | 387 | if (CompareGuid (HandlerInfo->ExtractHandlerGuidTable + Index, SectionDefinitionGuid)) {\r |
b9d5a7f1 LG |
388 | //\r |
389 | // Call the match handler to extract raw data for the input guided section.\r | |
390 | //\r | |
2f88bd3a MK |
391 | return HandlerInfo->ExtractDecodeHandlerTable[Index](\r |
392 | InputSection,\r | |
393 | OutputBuffer,\r | |
394 | ScratchBuffer,\r | |
395 | AuthenticationStatus\r | |
396 | );\r | |
b9d5a7f1 LG |
397 | }\r |
398 | }\r | |
399 | \r | |
400 | //\r | |
9095d37b | 401 | // Not found, the input guided section is not supported.\r |
b9d5a7f1 LG |
402 | //\r |
403 | return RETURN_UNSUPPORTED;\r | |
404 | }\r | |
9be899c5 ED |
405 | \r |
406 | /**\r | |
9095d37b | 407 | Retrieves handlers of type EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER and\r |
9be899c5 | 408 | EXTRACT_GUIDED_SECTION_DECODE_HANDLER for a specific GUID section type.\r |
9095d37b LG |
409 | \r |
410 | Retrieves the handlers associated with SectionGuid and returns them in\r | |
9be899c5 ED |
411 | GetInfoHandler and DecodeHandler.\r |
412 | \r | |
9095d37b | 413 | If the GUID value specified by SectionGuid has not been registered, then\r |
9be899c5 | 414 | return RETURN_NOT_FOUND.\r |
9095d37b | 415 | \r |
9be899c5 ED |
416 | If SectionGuid is NULL, then ASSERT().\r |
417 | \r | |
9095d37b | 418 | @param[in] SectionGuid A pointer to the GUID associated with the handlersof the GUIDed\r |
9be899c5 | 419 | section type being retrieved.\r |
9095d37b LG |
420 | @param[out] GetInfoHandler Pointer to a function that examines a GUIDed section and returns\r |
421 | the size of the decoded buffer and the size of an optional scratch\r | |
422 | buffer required to actually decode the data in a GUIDed section.\r | |
423 | This is an optional parameter that may be NULL. If it is NULL, then\r | |
9be899c5 ED |
424 | the previously registered handler is not returned.\r |
425 | @param[out] DecodeHandler Pointer to a function that decodes a GUIDed section into a caller\r | |
426 | allocated output buffer. This is an optional parameter that may be NULL.\r | |
427 | If it is NULL, then the previously registered handler is not returned.\r | |
428 | \r | |
429 | @retval RETURN_SUCCESS The handlers were retrieved.\r | |
430 | @retval RETURN_NOT_FOUND No handlers have been registered with the specified GUID.\r | |
431 | \r | |
432 | **/\r | |
433 | RETURN_STATUS\r | |
434 | EFIAPI\r | |
435 | ExtractGuidedSectionGetHandlers (\r | |
436 | IN CONST GUID *SectionGuid,\r | |
d0e2f823 | 437 | OUT EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER *GetInfoHandler OPTIONAL,\r |
9be899c5 ED |
438 | OUT EXTRACT_GUIDED_SECTION_DECODE_HANDLER *DecodeHandler OPTIONAL\r |
439 | )\r | |
440 | {\r | |
2f88bd3a MK |
441 | UINT32 Index;\r |
442 | RETURN_STATUS Status;\r | |
443 | EXTRACT_GUIDED_SECTION_HANDLER_INFO *HandlerInfo;\r | |
9be899c5 ED |
444 | \r |
445 | //\r | |
3868d06d | 446 | // Check input parameter\r |
9be899c5 ED |
447 | //\r |
448 | ASSERT (SectionGuid != NULL);\r | |
449 | \r | |
450 | //\r | |
451 | // Get the registered handler information\r | |
452 | //\r | |
453 | Status = GetExtractGuidedSectionHandlerInfo (&HandlerInfo);\r | |
454 | if (RETURN_ERROR (Status)) {\r | |
455 | return Status;\r | |
456 | }\r | |
457 | \r | |
458 | //\r | |
459 | // Search the match registered GetInfo handler for the input guided section.\r | |
460 | //\r | |
461 | ASSERT (HandlerInfo != NULL);\r | |
2f88bd3a | 462 | for (Index = 0; Index < HandlerInfo->NumberOfExtractHandler; Index++) {\r |
9be899c5 | 463 | if (CompareGuid (HandlerInfo->ExtractHandlerGuidTable + Index, SectionGuid)) {\r |
9be899c5 ED |
464 | //\r |
465 | // If the guided handler has been registered before, then return the registered handlers.\r | |
466 | //\r | |
467 | if (GetInfoHandler != NULL) {\r | |
468 | *GetInfoHandler = HandlerInfo->ExtractGetInfoHandlerTable[Index];\r | |
469 | }\r | |
2f88bd3a | 470 | \r |
9be899c5 ED |
471 | if (DecodeHandler != NULL) {\r |
472 | *DecodeHandler = HandlerInfo->ExtractDecodeHandlerTable[Index];\r | |
473 | }\r | |
2f88bd3a | 474 | \r |
9be899c5 ED |
475 | return RETURN_SUCCESS;\r |
476 | }\r | |
477 | }\r | |
2f88bd3a | 478 | \r |
9be899c5 ED |
479 | return RETURN_NOT_FOUND;\r |
480 | }\r |