/** @file\r
Support functions implementation for UEFI HTTP boot driver.\r
\r
-Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.<BR>\r
This program and the accompanying materials are licensed and made available under \r
the terms and conditions of the BSD License that accompanies this distribution. \r
The full text of the license may be found at\r
return NicHandle;\r
}\r
\r
+/**\r
+ Get the Nic handle using any child handle in the IPv6 stack.\r
+\r
+ @param[in] ControllerHandle Pointer to child handle over IPv6.\r
+\r
+ @return NicHandle The pointer to the Nic handle.\r
+ @return NULL Can't find the Nic handle.\r
+\r
+**/\r
+EFI_HANDLE\r
+HttpBootGetNicByIp6Children (\r
+ IN EFI_HANDLE ControllerHandle\r
+ )\r
+{\r
+ EFI_HANDLE NicHandle;\r
+ NicHandle = NetLibGetNicHandle (ControllerHandle, &gEfiHttpProtocolGuid);\r
+ if (NicHandle == NULL) {\r
+ NicHandle = NetLibGetNicHandle (ControllerHandle, &gEfiDhcp6ProtocolGuid);\r
+ if (NicHandle == NULL) {\r
+ return NULL;\r
+ }\r
+ }\r
+\r
+ return NicHandle;\r
+}\r
\r
/**\r
This function is to convert UINTN to ASCII string with the required formatting.\r
}\r
}\r
\r
+/**\r
+ This function is to display the IPv6 address.\r
+\r
+ @param[in] Ip The pointer to the IPv6 address.\r
+\r
+**/\r
+VOID\r
+HttpBootShowIp6Addr (\r
+ IN EFI_IPv6_ADDRESS *Ip\r
+ )\r
+{\r
+ UINTN Index;\r
+\r
+ for (Index = 0; Index < 16; Index++) {\r
+\r
+ if (Ip->Addr[Index] != 0) {\r
+ AsciiPrint ("%x", Ip->Addr[Index]);\r
+ }\r
+ Index++;\r
+ if (Index > 15) {\r
+ return;\r
+ }\r
+ if (((Ip->Addr[Index] & 0xf0) == 0) && (Ip->Addr[Index - 1] != 0)) {\r
+ AsciiPrint ("0");\r
+ }\r
+ AsciiPrint ("%x", Ip->Addr[Index]);\r
+ if (Index < 15) {\r
+ AsciiPrint (":");\r
+ }\r
+ }\r
+}\r
+\r
+/**\r
+ This function is to display the HTTP error status.\r
+\r
+ @param[in] StatusCode The status code value in HTTP message.\r
+\r
+**/\r
+VOID\r
+HttpBootPrintErrorMessage (\r
+ EFI_HTTP_STATUS_CODE StatusCode\r
+ )\r
+{\r
+ AsciiPrint ("\n");\r
+\r
+ switch (StatusCode) {\r
+ case HTTP_STATUS_300_MULTIPLE_CHIOCES:\r
+ AsciiPrint ("\n Redirection: 300 Multiple Choices");\r
+ break; \r
+ \r
+ case HTTP_STATUS_301_MOVED_PERMANENTLY:\r
+ AsciiPrint ("\n Redirection: 301 Moved Permanently");\r
+ break; \r
+ \r
+ case HTTP_STATUS_302_FOUND:\r
+ AsciiPrint ("\n Redirection: 302 Found");\r
+ break; \r
+ \r
+ case HTTP_STATUS_303_SEE_OTHER:\r
+ AsciiPrint ("\n Redirection: 303 See Other");\r
+ break; \r
+\r
+ case HTTP_STATUS_304_NOT_MODIFIED:\r
+ AsciiPrint ("\n Redirection: 304 Not Modified");\r
+ break; \r
+\r
+ case HTTP_STATUS_305_USE_PROXY:\r
+ AsciiPrint ("\n Redirection: 305 Use Proxy");\r
+ break; \r
+\r
+ case HTTP_STATUS_307_TEMPORARY_REDIRECT:\r
+ AsciiPrint ("\n Redirection: 307 Temporary Redirect");\r
+ break; \r
+\r
+ case HTTP_STATUS_400_BAD_REQUEST:\r
+ AsciiPrint ("\n Client Error: 400 Bad Request");\r
+ break;\r
+ \r
+ case HTTP_STATUS_401_UNAUTHORIZED:\r
+ AsciiPrint ("\n Client Error: 401 Unauthorized");\r
+ break;\r
+ \r
+ case HTTP_STATUS_402_PAYMENT_REQUIRED:\r
+ AsciiPrint ("\n Client Error: 402 Payment Required");\r
+ break;\r
+\r
+ case HTTP_STATUS_403_FORBIDDEN:\r
+ AsciiPrint ("\n Client Error: 403 Forbidden");\r
+ break;\r
+\r
+ case HTTP_STATUS_404_NOT_FOUND:\r
+ AsciiPrint ("\n Client Error: 404 Not Found");\r
+ break;\r
+\r
+ case HTTP_STATUS_405_METHOD_NOT_ALLOWED:\r
+ AsciiPrint ("\n Client Error: 405 Method Not Allowed");\r
+ break;\r
+\r
+ case HTTP_STATUS_406_NOT_ACCEPTABLE:\r
+ AsciiPrint ("\n Client Error: 406 Not Acceptable");\r
+ break;\r
+\r
+ case HTTP_STATUS_407_PROXY_AUTHENTICATION_REQUIRED:\r
+ AsciiPrint ("\n Client Error: 407 Proxy Authentication Required");\r
+ break;\r
+\r
+ case HTTP_STATUS_408_REQUEST_TIME_OUT:\r
+ AsciiPrint ("\n Client Error: 408 Request Timeout");\r
+ break;\r
+\r
+ case HTTP_STATUS_409_CONFLICT:\r
+ AsciiPrint ("\n Client Error: 409 Conflict");\r
+ break;\r
+\r
+ case HTTP_STATUS_410_GONE:\r
+ AsciiPrint ("\n Client Error: 410 Gone");\r
+ break;\r
+\r
+ case HTTP_STATUS_411_LENGTH_REQUIRED:\r
+ AsciiPrint ("\n Client Error: 411 Length Required");\r
+ break;\r
+\r
+ case HTTP_STATUS_412_PRECONDITION_FAILED:\r
+ AsciiPrint ("\n Client Error: 412 Precondition Failed");\r
+ break;\r
+\r
+ case HTTP_STATUS_413_REQUEST_ENTITY_TOO_LARGE:\r
+ AsciiPrint ("\n Client Error: 413 Request Entity Too Large");\r
+ break;\r
+\r
+ case HTTP_STATUS_414_REQUEST_URI_TOO_LARGE:\r
+ AsciiPrint ("\n Client Error: 414 Request URI Too Long");\r
+ break;\r
+\r
+ case HTTP_STATUS_415_UNSUPPORTED_MEDIA_TYPE:\r
+ AsciiPrint ("\n Client Error: 415 Unsupported Media Type");\r
+ break;\r
+\r
+ case HTTP_STATUS_416_REQUESTED_RANGE_NOT_SATISFIED:\r
+ AsciiPrint ("\n Client Error: 416 Requested Range Not Satisfiable");\r
+ break;\r
+\r
+ case HTTP_STATUS_417_EXPECTATION_FAILED:\r
+ AsciiPrint ("\n Client Error: 417 Expectation Failed");\r
+ break;\r
+\r
+ case HTTP_STATUS_500_INTERNAL_SERVER_ERROR:\r
+ AsciiPrint ("\n Server Error: 500 Internal Server Error");\r
+ break;\r
+\r
+ case HTTP_STATUS_501_NOT_IMPLEMENTED:\r
+ AsciiPrint ("\n Server Error: 501 Not Implemented");\r
+ break;\r
+\r
+ case HTTP_STATUS_502_BAD_GATEWAY:\r
+ AsciiPrint ("\n Server Error: 502 Bad Gateway");\r
+ break;\r
+\r
+ case HTTP_STATUS_503_SERVICE_UNAVAILABLE:\r
+ AsciiPrint ("\n Server Error: 503 Service Unavailable");\r
+ break;\r
+\r
+ case HTTP_STATUS_504_GATEWAY_TIME_OUT:\r
+ AsciiPrint ("\n Server Error: 504 Gateway Timeout");\r
+ break;\r
+\r
+ case HTTP_STATUS_505_HTTP_VERSION_NOT_SUPPORTED:\r
+ AsciiPrint ("\n Server Error: 505 HTTP Version Not Supported");\r
+ break;\r
+\r
+ default: ;\r
+ \r
+ }\r
+}\r
+\r
+/**\r
+ Notify the callback function when an event is triggered.\r
+\r
+ @param[in] Event The triggered event.\r
+ @param[in] Context The opaque parameter to the function.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+HttpBootCommonNotify (\r
+ IN EFI_EVENT Event,\r
+ IN VOID *Context\r
+ )\r
+{\r
+ *((BOOLEAN *) Context) = TRUE;\r
+}\r
+\r
+/**\r
+ Retrieve the host address using the EFI_DNS6_PROTOCOL.\r
+\r
+ @param[in] Private The pointer to the driver's private data.\r
+ @param[in] HostName Pointer to buffer containing hostname.\r
+ @param[out] IpAddress On output, pointer to buffer containing IPv6 address.\r
+\r
+ @retval EFI_SUCCESS Operation succeeded.\r
+ @retval EFI_DEVICE_ERROR An unexpected network error occurred.\r
+ @retval Others Other errors as indicated. \r
+**/\r
+EFI_STATUS\r
+HttpBootDns (\r
+ IN HTTP_BOOT_PRIVATE_DATA *Private,\r
+ IN CHAR16 *HostName,\r
+ OUT EFI_IPv6_ADDRESS *IpAddress \r
+ )\r
+{\r
+ EFI_STATUS Status;\r
+ EFI_DNS6_PROTOCOL *Dns6;\r
+ EFI_DNS6_CONFIG_DATA Dns6ConfigData;\r
+ EFI_DNS6_COMPLETION_TOKEN Token;\r
+ EFI_HANDLE Dns6Handle;\r
+ EFI_IP6_CONFIG_PROTOCOL *Ip6Config;\r
+ EFI_IPv6_ADDRESS *DnsServerList;\r
+ UINTN DnsServerListCount;\r
+ UINTN DataSize;\r
+ BOOLEAN IsDone; \r
+ \r
+ DnsServerList = NULL;\r
+ DnsServerListCount = 0;\r
+ Dns6 = NULL;\r
+ Dns6Handle = NULL;\r
+ ZeroMem (&Token, sizeof (EFI_DNS6_COMPLETION_TOKEN));\r
+ \r
+ //\r
+ // Get DNS server list from EFI IPv6 Configuration protocol.\r
+ //\r
+ Status = gBS->HandleProtocol (Private->Controller, &gEfiIp6ConfigProtocolGuid, (VOID **) &Ip6Config);\r
+ if (!EFI_ERROR (Status)) {\r
+ //\r
+ // Get the required size.\r
+ //\r
+ DataSize = 0;\r
+ Status = Ip6Config->GetData (Ip6Config, Ip6ConfigDataTypeDnsServer, &DataSize, NULL);\r
+ if (Status == EFI_BUFFER_TOO_SMALL) {\r
+ DnsServerList = AllocatePool (DataSize);\r
+ if (DnsServerList == NULL) {\r
+ return EFI_OUT_OF_RESOURCES;\r
+ } \r
+\r
+ Status = Ip6Config->GetData (Ip6Config, Ip6ConfigDataTypeDnsServer, &DataSize, DnsServerList);\r
+ if (EFI_ERROR (Status)) {\r
+ FreePool (DnsServerList);\r
+ DnsServerList = NULL;\r
+ } else {\r
+ DnsServerListCount = DataSize / sizeof (EFI_IPv6_ADDRESS);\r
+ }\r
+ }\r
+ }\r
+ //\r
+ // Create a DNSv6 child instance and get the protocol.\r
+ //\r
+ Status = NetLibCreateServiceChild (\r
+ Private->Controller,\r
+ Private->Image,\r
+ &gEfiDns6ServiceBindingProtocolGuid,\r
+ &Dns6Handle\r
+ );\r
+ if (EFI_ERROR (Status)) {\r
+ goto Exit;\r
+ } \r
+ \r
+ Status = gBS->OpenProtocol (\r
+ Dns6Handle,\r
+ &gEfiDns6ProtocolGuid,\r
+ (VOID **) &Dns6,\r
+ Private->Image,\r
+ Private->Controller,\r
+ EFI_OPEN_PROTOCOL_BY_DRIVER\r
+ );\r
+ if (EFI_ERROR (Status)) {\r
+ goto Exit;\r
+ }\r
+\r
+ //\r
+ // Configure DNS6 instance for the DNS server address and protocol.\r
+ //\r
+ ZeroMem (&Dns6ConfigData, sizeof (EFI_DNS6_CONFIG_DATA));\r
+ Dns6ConfigData.DnsServerCount = (UINT32)DnsServerListCount;\r
+ Dns6ConfigData.DnsServerList = DnsServerList;\r
+ Dns6ConfigData.EnableDnsCache = TRUE;\r
+ Dns6ConfigData.Protocol = EFI_IP_PROTO_UDP;\r
+ IP6_COPY_ADDRESS (&Dns6ConfigData.StationIp,&Private->StationIp.v6);\r
+ Status = Dns6->Configure (\r
+ Dns6,\r
+ &Dns6ConfigData\r
+ );\r
+ if (EFI_ERROR (Status)) {\r
+ goto Exit;\r
+ }\r
+ \r
+ Token.Status = EFI_NOT_READY;\r
+ IsDone = FALSE;\r
+ //\r
+ // Create event to set the IsDone flag when name resolution is finished.\r
+ //\r
+ Status = gBS->CreateEvent (\r
+ EVT_NOTIFY_SIGNAL,\r
+ TPL_NOTIFY,\r
+ HttpBootCommonNotify,\r
+ &IsDone,\r
+ &Token.Event\r
+ );\r
+ if (EFI_ERROR (Status)) {\r
+ goto Exit;\r
+ }\r
+\r
+ //\r
+ // Start asynchronous name resolution.\r
+ //\r
+ Status = Dns6->HostNameToIp (Dns6, HostName, &Token);\r
+ if (EFI_ERROR (Status)) {\r
+ goto Exit;\r
+ }\r
+\r
+ while (!IsDone) {\r
+ Dns6->Poll (Dns6);\r
+ }\r
+ \r
+ //\r
+ // Name resolution is done, check result.\r
+ //\r
+ Status = Token.Status; \r
+ if (!EFI_ERROR (Status)) {\r
+ if (Token.RspData.H2AData == NULL) {\r
+ Status = EFI_DEVICE_ERROR;\r
+ goto Exit;\r
+ }\r
+ if (Token.RspData.H2AData->IpCount == 0 || Token.RspData.H2AData->IpList == NULL) {\r
+ Status = EFI_DEVICE_ERROR;\r
+ goto Exit;\r
+ }\r
+ //\r
+ // We just return the first IPv6 address from DNS protocol.\r
+ //\r
+ IP6_COPY_ADDRESS (IpAddress, Token.RspData.H2AData->IpList);\r
+ Status = EFI_SUCCESS;\r
+ }\r
+Exit:\r
+\r
+ if (Token.Event != NULL) {\r
+ gBS->CloseEvent (Token.Event);\r
+ }\r
+ if (Token.RspData.H2AData != NULL) {\r
+ if (Token.RspData.H2AData->IpList != NULL) {\r
+ FreePool (Token.RspData.H2AData->IpList);\r
+ }\r
+ FreePool (Token.RspData.H2AData);\r
+ }\r
+\r
+ if (Dns6 != NULL) {\r
+ Dns6->Configure (Dns6, NULL);\r
+ \r
+ gBS->CloseProtocol (\r
+ Dns6Handle,\r
+ &gEfiDns6ProtocolGuid,\r
+ Private->Image,\r
+ Private->Controller\r
+ );\r
+ }\r
+\r
+ if (Dns6Handle != NULL) {\r
+ NetLibDestroyServiceChild (\r
+ Private->Controller,\r
+ Private->Image,\r
+ &gEfiDns6ServiceBindingProtocolGuid,\r
+ Dns6Handle\r
+ );\r
+ }\r
+\r
+ if (DnsServerList != NULL) {\r
+ FreePool (DnsServerList);\r
+ }\r
+ \r
+ return Status; \r
+}\r
/**\r
Create a HTTP_IO_HEADER to hold the HTTP header items.\r
\r
HTTP_IO_HEADER *\r
HttpBootCreateHeader (\r
UINTN MaxHeaderCount\r
-)\r
+ )\r
{\r
HTTP_IO_HEADER *HttpIoHeader;\r
\r
return EFI_SUCCESS;\r
}\r
\r
-/**\r
- Notify the callback function when an event is triggered.\r
-\r
- @param[in] Event The triggered event.\r
- @param[in] Context The opaque parameter to the function.\r
-\r
-**/\r
-VOID\r
-EFIAPI\r
-HttpIoCommonNotify (\r
- IN EFI_EVENT Event,\r
- IN VOID *Context\r
- )\r
-{\r
- *((BOOLEAN *) Context) = TRUE;\r
-}\r
-\r
/**\r
Create a HTTP_IO to access the HTTP service. It will create and configure\r
a HTTP child handle.\r
EFI_STATUS Status;\r
EFI_HTTP_CONFIG_DATA HttpConfigData;\r
EFI_HTTPv4_ACCESS_POINT Http4AccessPoint;\r
+ EFI_HTTPv6_ACCESS_POINT Http6AccessPoint;\r
EFI_HTTP_PROTOCOL *Http;\r
EFI_EVENT Event;\r
\r
IP4_COPY_ADDRESS (&Http4AccessPoint.LocalSubnet, &ConfigData->Config4.SubnetMask);\r
HttpConfigData.AccessPoint.IPv4Node = &Http4AccessPoint; \r
} else {\r
- ASSERT (FALSE);\r
+ HttpConfigData.LocalAddressIsIPv6 = TRUE;\r
+ Http6AccessPoint.LocalPort = ConfigData->Config6.LocalPort;\r
+ IP6_COPY_ADDRESS (&Http6AccessPoint.LocalAddress, &ConfigData->Config6.LocalIp);\r
+ HttpConfigData.AccessPoint.IPv6Node = &Http6AccessPoint;\r
}\r
\r
Status = Http->Configure (Http, &HttpConfigData);\r
Status = gBS->CreateEvent (\r
EVT_NOTIFY_SIGNAL,\r
TPL_NOTIFY,\r
- HttpIoCommonNotify,\r
+ HttpBootCommonNotify,\r
&HttpIo->IsTxDone,\r
&Event\r
);\r
Status = gBS->CreateEvent (\r
EVT_NOTIFY_SIGNAL,\r
TPL_NOTIFY,\r
- HttpIoCommonNotify,\r
+ HttpBootCommonNotify,\r
&HttpIo->IsRxDone,\r
&Event\r
);\r
FALSE to continue receive the previous response message.\r
@param[out] ResponseData Point to a wrapper of the received response data.\r
\r
- @retval EFI_SUCCESS The HTTP resopnse is received.\r
+ @retval EFI_SUCCESS The HTTP response is received.\r
@retval EFI_INVALID_PARAMETER One or more parameters are invalid.\r
@retval EFI_OUT_OF_RESOURCES Failed to allocate memory.\r
@retval EFI_DEVICE_ERROR An unexpected network or system error occurred.\r
HttpIoRecvResponse (\r
IN HTTP_IO *HttpIo,\r
IN BOOLEAN RecvMsgHeader,\r
- OUT HTTP_IO_RESOPNSE_DATA *ResponseData\r
+ OUT HTTP_IO_RESPONSE_DATA *ResponseData\r
)\r
{\r
EFI_STATUS Status;\r
}\r
\r
//\r
- // Poll the network until transmit finish.\r
+ // Poll the network until receive finish.\r
//\r
while (!HttpIo->IsRxDone) {\r
Http->Poll (Http);\r
//\r
// Store the received data into the wrapper.\r
//\r
- Status = HttpIo->ReqToken.Status;\r
- if (!EFI_ERROR (Status)) {\r
- ResponseData->HeaderCount = HttpIo->RspToken.Message->HeaderCount;\r
- ResponseData->Headers = HttpIo->RspToken.Message->Headers;\r
- ResponseData->BodyLength = HttpIo->RspToken.Message->BodyLength;\r
- }\r
+ ResponseData->Status = HttpIo->RspToken.Status;\r
+ ResponseData->HeaderCount = HttpIo->RspToken.Message->HeaderCount;\r
+ ResponseData->Headers = HttpIo->RspToken.Message->Headers;\r
+ ResponseData->BodyLength = HttpIo->RspToken.Message->BodyLength;\r
\r
return Status;\r
}\r
+\r
+/**\r
+ Get the URI address string from the input device path.\r
+\r
+ Caller need to free the buffer in the UriAddress pointer.\r
+ \r
+ @param[in] FilePath Pointer to the device path which contains a URI device path node.\r
+ @param[in] UriAddress The URI address string extract from the device path.\r
+ \r
+ @retval EFI_SUCCESS The URI string is returned.\r
+ @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.\r
+\r
+**/\r
+EFI_STATUS\r
+HttpBootParseFilePath (\r
+ IN EFI_DEVICE_PATH_PROTOCOL *FilePath,\r
+ OUT CHAR8 **UriAddress\r
+ )\r
+{\r
+ EFI_DEVICE_PATH_PROTOCOL *TempDevicePath;\r
+ URI_DEVICE_PATH *UriDevicePath;\r
+ CHAR8 *Uri;\r
+ UINTN UriStrLength;\r
+\r
+ if (FilePath == NULL) {\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+\r
+ *UriAddress = NULL;\r
+\r
+ //\r
+ // Extract the URI address from the FilePath\r
+ //\r
+ TempDevicePath = FilePath;\r
+ while (!IsDevicePathEnd (TempDevicePath)) {\r
+ if ((DevicePathType (TempDevicePath) == MESSAGING_DEVICE_PATH) &&\r
+ (DevicePathSubType (TempDevicePath) == MSG_URI_DP)) {\r
+ UriDevicePath = (URI_DEVICE_PATH*) TempDevicePath;\r
+ //\r
+ // UEFI Spec doesn't require the URI to be a NULL-terminated string\r
+ // So we allocate a new buffer and always append a '\0' to it.\r
+ //\r
+ UriStrLength = DevicePathNodeLength (UriDevicePath) - sizeof(EFI_DEVICE_PATH_PROTOCOL);\r
+ if (UriStrLength == 0) {\r
+ //\r
+ // return a NULL UriAddress if it's a empty URI device path node.\r
+ //\r
+ break;\r
+ }\r
+ Uri = AllocatePool (UriStrLength + 1);\r
+ if (Uri == NULL) {\r
+ return EFI_OUT_OF_RESOURCES;\r
+ }\r
+ CopyMem (Uri, UriDevicePath->Uri, DevicePathNodeLength (UriDevicePath) - sizeof(EFI_DEVICE_PATH_PROTOCOL));\r
+ Uri[DevicePathNodeLength (UriDevicePath) - sizeof(EFI_DEVICE_PATH_PROTOCOL)] = '\0';\r
+\r
+ *UriAddress = Uri;\r
+ }\r
+ TempDevicePath = NextDevicePathNode (TempDevicePath);\r
+ }\r
+\r
+ return EFI_SUCCESS;\r
+}\r