コード例 #1
0
ファイル: DnsDriver.c プロジェクト: wensunshine/VisualUefi
/**
  Create the DNS instance and initialize it.

  @param[in]  Service              The pointer to the DNS service.
  @param[out] Instance             The pointer to the DNS instance.

  @retval EFI_OUT_OF_RESOURCES   Failed to allocate resources.
  @retval EFI_SUCCESS            The DNS instance is created.

**/
EFI_STATUS
DnsCreateInstance (
  IN  DNS_SERVICE         *Service,
  OUT DNS_INSTANCE        **Instance
  )
{
  DNS_INSTANCE            *DnsIns;

  *Instance = NULL;
  
  DnsIns = AllocateZeroPool (sizeof (DNS_INSTANCE));
  if (DnsIns == NULL) {
    return EFI_OUT_OF_RESOURCES;
  }

  DnsIns->Signature = DNS_INSTANCE_SIGNATURE;
  InitializeListHead (&DnsIns->Link);
  DnsIns->State     = DNS_STATE_UNCONFIGED;
  DnsIns->InDestroy = FALSE;
  DnsIns->Service   = Service;
  
  if (Service->IpVersion == IP_VERSION_4) {
    CopyMem (&DnsIns->Dns4, &mDns4Protocol, sizeof (DnsIns->Dns4));
    NetMapInit (&DnsIns->Dns4TxTokens);
  } else {
    CopyMem (&DnsIns->Dns6, &mDns6Protocol, sizeof (DnsIns->Dns6));
    NetMapInit (&DnsIns->Dns6TxTokens);
  }

  DnsIns->UdpIo = UdpIoCreateIo (
                    Service->ControllerHandle, /// NicHandle
                    Service->ImageHandle,
                    DnsConfigNullUdp,
                    Service->IpVersion,
                    DnsIns
                    );
  if (DnsIns->UdpIo == NULL) {
    FreePool (DnsIns);
    return EFI_OUT_OF_RESOURCES;
  }
  
  *Instance = DnsIns;

  return EFI_SUCCESS;
}
コード例 #2
0
ファイル: HttpProto.c プロジェクト: shekho/edk2
/**
  Intiialize the HTTP_PROTOCOL structure to the unconfigured state.

  @param[in]       HttpSb               The HTTP service private instance.
  @param[in, out]  HttpInstance         Pointer to HTTP_PROTOCOL structure.

  @retval EFI_SUCCESS       HTTP_PROTOCOL structure is initialized successfully.
  @retval Others            Other error as indicated.

**/
EFI_STATUS
HttpInitProtocol (
    IN     HTTP_SERVICE            *HttpSb,
    IN OUT HTTP_PROTOCOL           *HttpInstance
)
{
    EFI_STATUS                     Status;
    VOID                           *Interface;

    ASSERT ((HttpSb != NULL) && (HttpInstance != NULL));

    HttpInstance->Signature = HTTP_PROTOCOL_SIGNATURE;
    CopyMem (&HttpInstance->Http, &mEfiHttpTemplate, sizeof (HttpInstance->Http));
    HttpInstance->Service = HttpSb;

    //
    // Create TCP child.
    //
    Status = NetLibCreateServiceChild (
                 HttpInstance->Service->ControllerHandle,
                 HttpInstance->Service->ImageHandle,
                 &gEfiTcp4ServiceBindingProtocolGuid,
                 &HttpInstance->TcpChildHandle
             );

    if (EFI_ERROR (Status)) {
        goto ON_ERROR;
    }

    Status = gBS->OpenProtocol (
                 HttpInstance->TcpChildHandle,
                 &gEfiTcp4ProtocolGuid,
                 (VOID **) &Interface,
                 HttpInstance->Service->ImageHandle,
                 HttpInstance->Service->ControllerHandle,
                 EFI_OPEN_PROTOCOL_BY_DRIVER
             );

    if (EFI_ERROR (Status)) {
        goto ON_ERROR;
    }

    Status = gBS->OpenProtocol (
                 HttpInstance->TcpChildHandle,
                 &gEfiTcp4ProtocolGuid,
                 (VOID **) &HttpInstance->Tcp4,
                 HttpInstance->Service->ImageHandle,
                 HttpInstance->Handle,
                 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
             );
    if (EFI_ERROR(Status)) {
        goto ON_ERROR;
    }

    HttpInstance->Url = AllocateZeroPool (HTTP_URL_BUFFER_LEN);
    if (HttpInstance->Url == NULL) {
        Status = EFI_OUT_OF_RESOURCES;
        goto ON_ERROR;
    }

    NetMapInit (&HttpInstance->TxTokens);
    NetMapInit (&HttpInstance->RxTokens);

    return EFI_SUCCESS;

ON_ERROR:

    if (HttpInstance->TcpChildHandle != NULL) {
        gBS->CloseProtocol (
            HttpInstance->TcpChildHandle,
            &gEfiTcp4ProtocolGuid,
            HttpInstance->Service->ImageHandle,
            HttpInstance->Service->ControllerHandle
        );

        gBS->CloseProtocol (
            HttpInstance->TcpChildHandle,
            &gEfiTcp4ProtocolGuid,
            HttpInstance->Service->ImageHandle,
            HttpInstance->Handle
        );

        NetLibDestroyServiceChild (
            HttpInstance->Service->ControllerHandle,
            HttpInstance->Service->ImageHandle,
            &gEfiTcp4ServiceBindingProtocolGuid,
            HttpInstance->TcpChildHandle
        );
    }

    return Status;

}