- while ((*Ip6Str != '\0') && (*Ip6Str != ':')) {\r
- Ip6Str++;\r
- }\r
-\r
- if ((*Ip6Str == '\0') && (Index != 14)) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- if (*Ip6Str == ':') {\r
- if (*(Ip6Str + 1) == ':') {\r
- if ((NodeCnt > 6) || \r
- ((*(Ip6Str + 2) != '\0') && (AsciiStrHexToUintn (Ip6Str + 2) == 0))) {\r
- //\r
- // ::0 looks strange. report error to user.\r
- //\r
- return EFI_INVALID_PARAMETER;\r
- }\r
- if ((NodeCnt == 6) && (*(Ip6Str + 2) != '\0') && \r
- (AsciiStrHexToUintn (Ip6Str + 2) != 0)) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- //\r
- // Skip the abbreviation part of IPv6 address.\r
- //\r
- TempStr2 = Ip6Str + 2;\r
- while ((*TempStr2 != '\0')) {\r
- if (*TempStr2 == ':') {\r
- if (*(TempStr2 + 1) == ':') {\r
- //\r
- // :: can only appear once in IPv6 address.\r
- //\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- TailNodeCnt++;\r
- if (TailNodeCnt >= (AllowedCnt - NodeCnt)) {\r
- //\r
- // :: indicates one or more groups of 16 bits of zeros.\r
- //\r
- return EFI_INVALID_PARAMETER;\r
- }\r
- }\r
-\r
- TempStr2++;\r
- }\r
-\r
- Short = TRUE;\r
- Update = TRUE;\r
-\r
- Ip6Str = Ip6Str + 2;\r
- } else {\r
- if (*(Ip6Str + 1) == '\0') {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
- Ip6Str++;\r
- NodeCnt++;\r
- if ((Short && (NodeCnt > 6)) || (!Short && (NodeCnt > 7))) {\r
- //\r
- // There are more than 8 groups of 16 bits of zeros.\r
- //\r
- return EFI_INVALID_PARAMETER;\r
- }\r
- }\r
- }\r
-\r
- //\r
- // Convert the string to IPv6 address. AsciiStrHexToUintn stops at the first\r
- // character that is not a valid hexadecimal character, ':' or '\0' here.\r
- //\r
- NodeVal = AsciiStrHexToUintn (TempStr);\r
- if ((NodeVal > 0xFFFF) || (Index > 14)) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
- if (NodeVal != 0) {\r
- if ((*TempStr == '0') && \r
- ((*(TempStr + 2) == ':') || (*(TempStr + 3) == ':') || \r
- (*(TempStr + 2) == '\0') || (*(TempStr + 3) == '\0'))) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
- if ((*TempStr == '0') && (*(TempStr + 4) != '\0') && \r
- (*(TempStr + 4) != ':')) { \r
- return EFI_INVALID_PARAMETER;\r
- }\r
- } else {\r
- if (((*TempStr == '0') && (*(TempStr + 1) == '0') && \r
- ((*(TempStr + 2) == ':') || (*(TempStr + 2) == '\0'))) ||\r
- ((*TempStr == '0') && (*(TempStr + 1) == '0') && (*(TempStr + 2) == '0') && \r
- ((*(TempStr + 3) == ':') || (*(TempStr + 3) == '\0')))) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
- }\r
-\r
- Cnt = 0;\r
- while ((TempStr[Cnt] != ':') && (TempStr[Cnt] != '\0')) {\r
- Cnt++; \r
- }\r
- if (LeadZeroCnt == 0) {\r
- if ((Cnt == 4) && (*TempStr == '0')) {\r
- LeadZero = TRUE;\r
- LeadZeroCnt++;\r
- }\r
- if ((Cnt != 0) && (Cnt < 4)) {\r
- LeadZero = FALSE;\r
- LeadZeroCnt++;\r
- }\r
- } else {\r
- if ((Cnt == 4) && (*TempStr == '0') && !LeadZero) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
- if ((Cnt != 0) && (Cnt < 4) && LeadZero) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
- } \r
-\r
- Ip6Address->Addr[Index] = (UINT8) (NodeVal >> 8);\r
- Ip6Address->Addr[Index + 1] = (UINT8) (NodeVal & 0xFF);\r
-\r
- //\r
- // Skip the groups of zeros by ::\r
- //\r
- if (Short && Update) {\r
- Index = (UINT8) (16 - (TailNodeCnt + 2) * 2);\r
- Update = FALSE;\r
- }\r
- }\r
-\r
- if ((!Short && Index != 16) || (*Ip6Str != '\0')) {\r