TianoCore EDK2 master
Loading...
Searching...
No Matches
RedfishConfigHandlerDriver.c
Go to the documentation of this file.
1
14
15EFI_EVENT gEfiRedfishDiscoverProtocolEvent = NULL;
16
17//
18// Variables for using RFI Redfish Discover Protocol
19//
20VOID *gEfiRedfishDiscoverRegistration;
21EFI_HANDLE gEfiRedfishDiscoverControllerHandle = NULL;
22EFI_REDFISH_DISCOVER_PROTOCOL *gEfiRedfishDiscoverProtocol = NULL;
23BOOLEAN gRedfishDiscoverActivated = FALSE;
24BOOLEAN gRedfishServiceDiscovered = FALSE;
26UINTN mNumberOfNetworkInterfaces;
27EFI_EVENT mEdkIIRedfishHostInterfaceReadyEvent;
28VOID *mEdkIIRedfishHostInterfaceRegistration;
29
37 REDFISH_CONFIG_VERSION,
38 NULL,
39 NULL
40};
41
46VOID
48 VOID
49 )
50{
51 if (gRedfishDiscoverActivated) {
52 //
53 // No more EFI Discover Protocol.
54 //
55 if (gEfiRedfishDiscoverProtocolEvent != NULL) {
56 gBS->CloseEvent (gEfiRedfishDiscoverProtocolEvent);
57 }
58
59 gEfiRedfishDiscoverControllerHandle = NULL;
60 gEfiRedfishDiscoverProtocol = NULL;
61 gRedfishDiscoverActivated = FALSE;
62 gRedfishServiceDiscovered = FALSE;
63 }
64}
65
73VOID
74EFIAPI
76 IN EFI_EVENT Event,
77 IN VOID *Context
78 )
79{
80 if (!gRedfishDiscoverActivated) {
81 //
82 // No Redfish service is discovered yet.
83 //
84 return;
85 }
86
88}
89
126EFIAPI
129 IN EFI_HANDLE ControllerHandle,
130 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
131 )
132{
133 EFI_REST_EX_PROTOCOL *RestEx;
134 EFI_STATUS Status;
135 EFI_HANDLE ChildHandle;
136
137 ChildHandle = NULL;
138
139 //
140 // Check if REST EX is ready. This just makes sure
141 // the network stack is brought up.
142 //
143 Status = NetLibCreateServiceChild (
144 ControllerHandle,
145 This->ImageHandle,
146 &gEfiRestExServiceBindingProtocolGuid,
147 &ChildHandle
148 );
149 if (EFI_ERROR (Status)) {
150 return EFI_UNSUPPORTED;
151 }
152
153 //
154 // Test if REST EX protocol is ready.
155 //
156 Status = gBS->OpenProtocol (
157 ChildHandle,
158 &gEfiRestExProtocolGuid,
159 (VOID **)&RestEx,
160 This->DriverBindingHandle,
161 ControllerHandle,
162 EFI_OPEN_PROTOCOL_GET_PROTOCOL
163 );
164 if (EFI_ERROR (Status)) {
165 Status = EFI_UNSUPPORTED;
166 }
167
169 ControllerHandle,
170 This->ImageHandle,
171 &gEfiRestExServiceBindingProtocolGuid,
172 ChildHandle
173 );
174 return Status;
175}
176
211EFIAPI
214 IN EFI_HANDLE ControllerHandle,
215 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
216 )
217{
218 VOID *ConfigHandlerRegistration;
219
220 if (gRedfishConfigData.Event != NULL) {
221 return EFI_ALREADY_STARTED;
222 }
223
224 gRedfishConfigData.Event = EfiCreateProtocolNotifyEvent (
225 &gEdkIIRedfishConfigHandlerProtocolGuid,
226 TPL_CALLBACK,
228 (VOID *)&gRedfishConfigData,
229 &ConfigHandlerRegistration
230 );
231 return EFI_SUCCESS;
232}
233
261EFIAPI
264 IN EFI_HANDLE ControllerHandle,
265 IN UINTN NumberOfChildren,
266 IN EFI_HANDLE *ChildHandleBuffer OPTIONAL
267 )
268{
269 EFI_STATUS Status;
270
271 if (ControllerHandle == gEfiRedfishDiscoverControllerHandle) {
273 }
274
275 gBS->CloseProtocol (
276 ControllerHandle,
277 &gEfiRedfishDiscoverProtocolGuid,
278 gRedfishConfigData.Image,
279 gRedfishConfigData.Image
280 );
281
282 Status = RedfishConfigCommonStop ();
283 if (EFI_ERROR (Status)) {
284 return EFI_DEVICE_ERROR;
285 }
286
287 if (gRedfishConfigData.Event != NULL) {
288 gBS->CloseEvent (gRedfishConfigData.Event);
289 gRedfishConfigData.Event = NULL;
290 }
291
292 return EFI_SUCCESS;
293}
294
302VOID
303EFIAPI
305 IN EFI_EVENT Event,
306 OUT VOID *Context
307 )
308{
309 EFI_REDFISH_DISCOVERED_TOKEN *RedfishDiscoveredToken;
310 EFI_REDFISH_DISCOVERED_INSTANCE *RedfishInstance;
311
312 RedfishDiscoveredToken = (EFI_REDFISH_DISCOVERED_TOKEN *)Context;
313 gBS->CloseEvent (RedfishDiscoveredToken->Event);
314
315 //
316 // Only support one Redfish service on platform.
317 //
318 if (!gRedfishServiceDiscovered) {
319 RedfishInstance = RedfishDiscoveredToken->DiscoverList.RedfishInstances;
320 //
321 // Only pick up the first found Redfish service.
322 //
323 if (RedfishInstance->Status == EFI_SUCCESS) {
324 gRedfishConfigData.RedfishServiceInfo.RedfishServiceRestExHandle = RedfishInstance->Information.RedfishRestExHandle;
325 gRedfishConfigData.RedfishServiceInfo.RedfishServiceVersion = RedfishInstance->Information.RedfishVersion;
326 gRedfishConfigData.RedfishServiceInfo.RedfishServiceLocation = RedfishInstance->Information.Location;
327 gRedfishConfigData.RedfishServiceInfo.RedfishServiceUuid = RedfishInstance->Information.Uuid;
328 gRedfishConfigData.RedfishServiceInfo.RedfishServiceOs = RedfishInstance->Information.Os;
329 gRedfishConfigData.RedfishServiceInfo.RedfishServiceOsVersion = RedfishInstance->Information.OsVersion;
330 gRedfishConfigData.RedfishServiceInfo.RedfishServiceProduct = RedfishInstance->Information.Product;
331 gRedfishConfigData.RedfishServiceInfo.RedfishServiceProductVer = RedfishInstance->Information.ProductVer;
332 gRedfishConfigData.RedfishServiceInfo.RedfishServiceUseHttps = RedfishInstance->Information.UseHttps;
333 gRedfishServiceDiscovered = TRUE;
334 }
335
336 //
337 // Invoke RedfishConfigHandlerInstalledCallback to execute
338 // the initialization of Redfish Configure Handler instance.
339 //
340 RedfishConfigHandlerInstalledCallback (gRedfishConfigData.Event, &gRedfishConfigData);
341 }
342
343 FreePool (RedfishDiscoveredToken);
344}
345
354VOID
355EFIAPI
357 IN EFI_EVENT Event,
358 IN VOID *Context
359 )
360{
361 EFI_STATUS Status;
362 EFI_REDFISH_DISCOVER_NETWORK_INTERFACE *ThisNetworkInterface;
363 UINTN NetworkInterfaceIndex;
364 EFI_REDFISH_DISCOVERED_TOKEN *ThisRedfishDiscoveredToken;
365
366 ThisNetworkInterface = mNetworkInterfaces;
367 //
368 // Loop to discover Redfish service on each network interface.
369 //
370 for (NetworkInterfaceIndex = 0; NetworkInterfaceIndex < mNumberOfNetworkInterfaces; NetworkInterfaceIndex++) {
371 ThisRedfishDiscoveredToken = (EFI_REDFISH_DISCOVERED_TOKEN *)AllocateZeroPool (sizeof (EFI_REDFISH_DISCOVERED_TOKEN));
372 if (ThisRedfishDiscoveredToken == NULL) {
373 DEBUG ((DEBUG_ERROR, "%a: Not enough memory for EFI_REDFISH_DISCOVERED_TOKEN.\n", __func__));
374 return;
375 }
376
377 ThisRedfishDiscoveredToken->Signature = REDFISH_DISCOVER_TOKEN_SIGNATURE;
378
379 //
380 // Initial this Redfish Discovered Token
381 //
382 Status = gBS->CreateEvent (
383 EVT_NOTIFY_SIGNAL,
384 TPL_CALLBACK,
386 (VOID *)ThisRedfishDiscoveredToken,
387 &ThisRedfishDiscoveredToken->Event
388 );
389 if (EFI_ERROR (Status)) {
390 FreePool (ThisRedfishDiscoveredToken);
391 DEBUG ((DEBUG_ERROR, "%a: Failed to create event for Redfish discovered token.\n", __func__));
392 return;
393 }
394
395 //
396 // Acquire for Redfish service which is reported by
397 // Redfish Host Interface.
398 //
399 Status = gEfiRedfishDiscoverProtocol->AcquireRedfishService (
400 gEfiRedfishDiscoverProtocol,
401 gRedfishConfigData.Image,
402 ThisNetworkInterface,
404 ThisRedfishDiscoveredToken
405 );
406
407 //
408 // Free Redfish Discovered Token if Discover Instance was not created and
409 // Redfish Service Discovered Callback event was not triggered.
410 //
411 if ((ThisRedfishDiscoveredToken->DiscoverList.NumberOfServiceFound == 0) ||
412 EFI_ERROR (ThisRedfishDiscoveredToken->DiscoverList.RedfishInstances->Status))
413 {
414 gBS->CloseEvent (ThisRedfishDiscoveredToken->Event);
415 DEBUG ((DEBUG_MANAGEABILITY, "%a: Free Redfish discovered token - %x.\n", __func__, ThisRedfishDiscoveredToken));
416 FreePool (ThisRedfishDiscoveredToken);
417 }
418
419 ThisNetworkInterface++;
420 }
421}
422
431VOID
432EFIAPI
434 IN EFI_EVENT Event,
435 IN VOID *Context
436 )
437{
438 EFI_STATUS Status;
439 UINTN BufferSize;
440 EFI_HANDLE HandleBuffer;
441 VOID *RedfishHostInterfaceReadyProtocol;
442
443 DEBUG ((DEBUG_MANAGEABILITY, "%a: New network interface is installed on system by EFI Redfish discover driver.\n", __func__));
444
445 BufferSize = sizeof (EFI_HANDLE);
446 Status = gBS->LocateHandle (
448 NULL,
449 gEfiRedfishDiscoverRegistration,
450 &BufferSize,
451 &HandleBuffer
452 );
453 if (EFI_ERROR (Status)) {
454 DEBUG ((DEBUG_ERROR, "%a: Can't locate handle with EFI_REDFISH_DISCOVER_PROTOCOL installed.\n", __func__));
455 }
456
457 gRedfishDiscoverActivated = TRUE;
458 if (gEfiRedfishDiscoverProtocol == NULL) {
459 gEfiRedfishDiscoverControllerHandle = HandleBuffer;
460 //
461 // First time to open EFI_REDFISH_DISCOVER_PROTOCOL.
462 //
463 Status = gBS->OpenProtocol (
464 gEfiRedfishDiscoverControllerHandle,
465 &gEfiRedfishDiscoverProtocolGuid,
466 (VOID **)&gEfiRedfishDiscoverProtocol,
467 gRedfishConfigData.Image,
468 gRedfishConfigData.Image,
469 EFI_OPEN_PROTOCOL_BY_DRIVER
470 );
471 if (EFI_ERROR (Status)) {
472 gEfiRedfishDiscoverProtocol = NULL;
473 gRedfishDiscoverActivated = FALSE;
474 DEBUG ((DEBUG_ERROR, "%a: Can't locate EFI_REDFISH_DISCOVER_PROTOCOL.\n", __func__));
475 return;
476 }
477 }
478
479 Status = gEfiRedfishDiscoverProtocol->GetNetworkInterfaceList (
480 gEfiRedfishDiscoverProtocol,
481 gRedfishConfigData.Image,
482 &mNumberOfNetworkInterfaces,
483 &mNetworkInterfaces
484 );
485 if (EFI_ERROR (Status) || (mNumberOfNetworkInterfaces == 0)) {
486 DEBUG ((DEBUG_ERROR, "%a: No network interfaces found on the handle.\n", __func__));
487 return;
488 }
489
490 //
491 // Check if Redfish Host Interface is ready or not.
492 //
493 Status = gBS->LocateProtocol (&gEdkIIRedfishHostInterfaceReadyProtocolGuid, NULL, &RedfishHostInterfaceReadyProtocol);
494 if (!EFI_ERROR (Status)) {
495 // Acquire Redfish service;
497 } else {
498 Status = gBS->CreateEvent (
499 EVT_NOTIFY_SIGNAL,
500 TPL_CALLBACK,
502 NULL,
503 &mEdkIIRedfishHostInterfaceReadyEvent
504 );
505 if (EFI_ERROR (Status)) {
506 DEBUG ((DEBUG_ERROR, "%a: Failed to create event for gEdkIIRedfishHostInterfaceReadyProtocolGuid installation.", __func__));
507 return;
508 }
509
510 Status = gBS->RegisterProtocolNotify (
511 &gEdkIIRedfishHostInterfaceReadyProtocolGuid,
512 mEdkIIRedfishHostInterfaceReadyEvent,
513 &mEdkIIRedfishHostInterfaceRegistration
514 );
515 if (EFI_ERROR (Status)) {
516 DEBUG ((DEBUG_ERROR, "%a: Fail to register event for the installation of gEdkIIRedfishHostInterfaceReadyProtocolGuid.", __func__));
517 return;
518 }
519 }
520
521 return;
522}
523
533EFIAPI
535 IN EFI_HANDLE ImageHandle
536 )
537{
539
541
542 return EFI_SUCCESS;
543}
544
557EFIAPI
559 IN EFI_HANDLE ImageHandle,
560 IN EFI_SYSTEM_TABLE *SystemTable
561 )
562{
563 EFI_STATUS Status;
564
565 ZeroMem ((VOID *)&gRedfishConfigData, sizeof (REDFISH_CONFIG_DRIVER_DATA));
566 gRedfishConfigData.Image = ImageHandle;
567 //
568 // Register event for EFI_REDFISH_DISCOVER_PROTOCOL protocol install
569 // notification.
570 //
571 Status = gBS->CreateEventEx (
572 EVT_NOTIFY_SIGNAL,
573 TPL_CALLBACK,
575 NULL,
576 &gEfiRedfishDiscoverProtocolGuid,
577 &gEfiRedfishDiscoverProtocolEvent
578 );
579 if (EFI_ERROR (Status)) {
580 DEBUG ((DEBUG_ERROR, "%a: Fail to create event for the installation of EFI_REDFISH_DISCOVER_PROTOCOL.", __func__));
581 return Status;
582 }
583
584 Status = gBS->RegisterProtocolNotify (
585 &gEfiRedfishDiscoverProtocolGuid,
586 gEfiRedfishDiscoverProtocolEvent,
587 &gEfiRedfishDiscoverRegistration
588 );
589 if (EFI_ERROR (Status)) {
590 DEBUG ((DEBUG_ERROR, "%a: Fail to register event for the installation of EFI_REDFISH_DISCOVER_PROTOCOL.", __func__));
591 return Status;
592 }
593
594 Status = RedfishConfigCommonInit (ImageHandle, SystemTable);
595 if (EFI_ERROR (Status)) {
596 gBS->CloseEvent (gEfiRedfishDiscoverProtocolEvent);
597 gEfiRedfishDiscoverProtocolEvent = NULL;
598 return Status;
599 }
600
601 //
602 // Install UEFI Driver Model protocol(s).
603 //
605 ImageHandle,
606 SystemTable,
608 ImageHandle,
611 NULL,
612 NULL,
613 NULL,
614 NULL
615 );
616 if (EFI_ERROR (Status)) {
617 gBS->CloseEvent (gEndOfDxeEvent);
618 gEndOfDxeEvent = NULL;
619 gBS->CloseEvent (gExitBootServiceEvent);
620 gExitBootServiceEvent = NULL;
621 gBS->CloseEvent (gEfiRedfishDiscoverProtocolEvent);
622 gEfiRedfishDiscoverProtocolEvent = NULL;
623 DEBUG ((DEBUG_ERROR, "%a: Fail to install EFI Binding Protocol of EFI Redfish Config driver.", __func__));
624 return Status;
625 }
626
627 return Status;
628}
UINT64 UINTN
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
#define NULL
Definition: Base.h:319
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define DEBUG(Expression)
Definition: DebugLib.h:434
EFI_STATUS EFIAPI NetLibCreateServiceChild(IN EFI_HANDLE Controller, IN EFI_HANDLE Image, IN EFI_GUID *ServiceBindingGuid, IN OUT EFI_HANDLE *ChildHandle)
Definition: DxeNetLib.c:1967
EFI_STATUS EFIAPI NetLibDestroyServiceChild(IN EFI_HANDLE Controller, IN EFI_HANDLE Image, IN EFI_GUID *ServiceBindingGuid, IN EFI_HANDLE ChildHandle)
Definition: DxeNetLib.c:2020
VOID RedfishConfigHandlerInitialization(VOID)
EFI_STATUS RedfishConfigDriverCommonUnload(IN EFI_HANDLE ImageHandle)
EFI_STATUS RedfishConfigCommonInit(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
EFI_STATUS RedfishConfigCommonStop(VOID)
EFI_STATUS EFIAPI RedfishConfigDriverBindingStart(IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE ControllerHandle, IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL)
EFI_STATUS EFIAPI RedfishConfigDriverBindingStop(IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE ControllerHandle, IN UINTN NumberOfChildren, IN EFI_HANDLE *ChildHandleBuffer OPTIONAL)
VOID EFIAPI RedfishServiceDiscoveredCallback(IN EFI_EVENT Event, OUT VOID *Context)
EFI_STATUS EFIAPI RedfishConfigHandlerDriverUnload(IN EFI_HANDLE ImageHandle)
VOID EFIAPI RedfishDiscoverProtocolInstalled(IN EFI_EVENT Event, IN VOID *Context)
VOID EFIAPI AcquireRedfishServiceOnNetworkInterfaceCallback(IN EFI_EVENT Event, IN VOID *Context)
EFI_STATUS EFIAPI RedfishConfigDriverBindingSupported(IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE ControllerHandle, IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL)
VOID EFIAPI RedfishConfigHandlerInstalledCallback(IN EFI_EVENT Event, IN VOID *Context)
EFI_STATUS EFIAPI RedfishConfigHandlerDriverEntryPoint(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
VOID RedfishConfigStopRedfishDiscovery(VOID)
EFI_DRIVER_BINDING_PROTOCOL gRedfishConfigDriverBinding
#define EFI_REDFISH_DISCOVER_HOST_INTERFACE
Discover Redfish server reported in SMBIOS 42h.
GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gRedfishConfigHandlerComponentName2
GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL gRedfishConfigHandlerComponentName
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_EVENT
Definition: UefiBaseType.h:37
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_BOOT_SERVICES * gBS
EFI_STATUS EFIAPI EfiLibInstallAllDriverProtocols2(IN CONST EFI_HANDLE ImageHandle, IN CONST EFI_SYSTEM_TABLE *SystemTable, IN EFI_DRIVER_BINDING_PROTOCOL *DriverBinding, IN EFI_HANDLE DriverBindingHandle, IN CONST EFI_COMPONENT_NAME_PROTOCOL *ComponentName OPTIONAL, IN CONST EFI_COMPONENT_NAME2_PROTOCOL *ComponentName2 OPTIONAL, IN CONST EFI_DRIVER_CONFIGURATION_PROTOCOL *DriverConfiguration OPTIONAL, IN CONST EFI_DRIVER_CONFIGURATION2_PROTOCOL *DriverConfiguration2 OPTIONAL, IN CONST EFI_DRIVER_DIAGNOSTICS_PROTOCOL *DriverDiagnostics OPTIONAL, IN CONST EFI_DRIVER_DIAGNOSTICS2_PROTOCOL *DriverDiagnostics2 OPTIONAL)
EFI_EVENT EFIAPI EfiCreateProtocolNotifyEvent(IN EFI_GUID *ProtocolGuid, IN EFI_TPL NotifyTpl, IN EFI_EVENT_NOTIFY NotifyFunction, IN VOID *NotifyContext OPTIONAL, OUT VOID **Registration)
Definition: UefiLib.c:134
@ ByRegisterNotify
Definition: UefiSpec.h:1513
CHAR16 * Product
Redfish service product name.
CHAR16 * Location
Redfish service location.
CHAR16 * Os
Redfish service OS.
CHAR16 * OsVersion
Redfish service OS version.
CHAR16 * ProductVer
Redfish service product version.
UINTN RedfishVersion
Redfish service version.
CHAR16 * Uuid
Redfish service UUID.
EFI_HANDLE RedfishRestExHandle
REST EX EFI handle associated with this Redfish service.
EFI_REDFISH_DISCOVERED_INFORMATION Information
Redfish service discovered.
EFI_STATUS Status
Status of Redfish service discovery.
EFI_REDFISH_DISCOVERED_INSTANCE * RedfishInstances
Must be NULL when pass to Acquire ().
UINT32 Signature
Token signature.
EFI_REDFISH_DISCOVERED_LIST DiscoverList
EFI_EVENT Event
Event for the notification of EFI_REDFISH_CONFIG_HANDLER_PROTOCOL.
EFI_HANDLE Image
Image handle of Redfish Config Driver.
BOOLEAN RedfishServiceUseHttps
Redfish service uses HTTPS.
CHAR16 * RedfishServiceUuid
Redfish service UUID.
EFI_HANDLE RedfishServiceRestExHandle
REST EX EFI handle associated with this Redfish service.
CHAR16 * RedfishServiceLocation
Redfish service location.
CHAR16 * RedfishServiceProductVer
Redfish service product version.
UINTN RedfishServiceVersion
Redfish service version.
CHAR16 * RedfishServiceProduct
Redfish service product name.
CHAR16 * RedfishServiceOs
Redfish service OS.
CHAR16 * RedfishServiceOsVersion
Redfish service OS version.