33 UINT8 IScsiRootPathIdLen;
43 ConfigNvData = &ConfigData->SessionConfigData;
48 IScsiRootPathIdLen = (UINT8)
AsciiStrLen (ISCSI_ROOT_PATH_ID);
50 if ((Length <= IScsiRootPathIdLen) || (
CompareMem (RootPath, ISCSI_ROOT_PATH_ID, IScsiRootPathIdLen) != 0)) {
57 RootPath += IScsiRootPathIdLen;
58 Length = (UINT8)(Length - IScsiRootPathIdLen);
62 return EFI_OUT_OF_RESOURCES;
65 CopyMem (TmpStr, RootPath, Length);
66 TmpStr[Length] =
'\0';
69 FieldIndex = RP_FIELD_IDX_SERVERNAME;
70 ZeroMem (&Fields[0],
sizeof (Fields));
75 for (FieldIndex = RP_FIELD_IDX_SERVERNAME; (FieldIndex < RP_FIELD_IDX_MAX) && (Index < Length); FieldIndex++) {
76 if (TmpStr[Index] != ISCSI_ROOT_PATH_FIELD_DELIMITER) {
77 Fields[FieldIndex].Str = &TmpStr[Index];
80 while ((TmpStr[Index] != ISCSI_ROOT_PATH_FIELD_DELIMITER) && (Index < Length)) {
84 if (TmpStr[Index] == ISCSI_ROOT_PATH_FIELD_DELIMITER) {
85 if (FieldIndex != RP_FIELD_IDX_TARGETNAME) {
90 if (Fields[FieldIndex].Str !=
NULL) {
91 Fields[FieldIndex].Len = (UINT8)
AsciiStrLen (Fields[FieldIndex].Str);
96 if (FieldIndex != RP_FIELD_IDX_MAX) {
97 Status = EFI_INVALID_PARAMETER;
101 if ((Fields[RP_FIELD_IDX_SERVERNAME].Str ==
NULL) ||
102 (Fields[RP_FIELD_IDX_TARGETNAME].Str ==
NULL) ||
103 (Fields[RP_FIELD_IDX_PROTOCOL].Len > 1)
106 Status = EFI_INVALID_PARAMETER;
113 Field = &Fields[RP_FIELD_IDX_SERVERNAME];
115 if (ConfigNvData->IpMode < IP_MODE_AUTOCONFIG) {
116 IpMode = ConfigNvData->IpMode;
118 IpMode = ConfigData->AutoConfigureMode;
124 if ((!NET_IS_DIGIT (*(Field->Str))) && (*(Field->Str) !=
'[')) {
125 ConfigNvData->DnsMode =
TRUE;
126 if ((Field->Len + 2) >
sizeof (ConfigNvData->TargetUrl)) {
127 return EFI_INVALID_PARAMETER;
130 CopyMem (&ConfigNvData->TargetUrl, Field->Str, Field->Len);
131 ConfigNvData->TargetUrl[Field->Len + 1] =
'\0';
133 ConfigNvData->DnsMode =
FALSE;
134 ZeroMem (ConfigNvData->TargetUrl, sizeof (ConfigNvData->TargetUrl));
138 if (EFI_ERROR (Status)) {
146 Field = &Fields[RP_FIELD_IDX_PROTOCOL];
147 if ((Field->Str !=
NULL) && ((*(Field->Str) -
'0') != EFI_IP_PROTO_TCP)) {
148 Status = EFI_INVALID_PARAMETER;
155 Field = &Fields[RP_FIELD_IDX_PORT];
156 if (Field->Str !=
NULL) {
159 ConfigNvData->TargetPort = ISCSI_WELL_KNOWN_PORT;
165 Field = &Fields[RP_FIELD_IDX_LUN];
166 if (Field->Str !=
NULL) {
168 if (EFI_ERROR (Status)) {
172 ZeroMem (ConfigNvData->BootLun, sizeof (ConfigNvData->BootLun));
178 Field = &Fields[RP_FIELD_IDX_TARGETNAME];
180 if (
AsciiStrLen (Field->Str) > ISCSI_NAME_MAX_SIZE - 1) {
181 Status = EFI_INVALID_PARAMETER;
189 if (EFI_ERROR (Status)) {
193 AsciiStrCpyS (ConfigNvData->TargetName, ISCSI_NAME_MAX_SIZE, Field->Str);
241 Status = This->Parse (This, Packet, &OptionCount,
NULL);
242 if (Status != EFI_BUFFER_TOO_SMALL) {
243 return EFI_NOT_READY;
247 if (OptionList ==
NULL) {
248 return EFI_NOT_READY;
251 Status = This->Parse (This, Packet, &OptionCount, OptionList);
252 if (EFI_ERROR (Status)) {
254 return EFI_NOT_READY;
257 for (Index = 0; Index < OptionCount; Index++) {
258 if (OptionList[Index]->OpCode != DHCP4_TAG_ROOTPATH) {
263 (CHAR8 *)&OptionList[Index]->Data[0],
264 OptionList[Index]->Length,
271 if (Index == OptionCount) {
272 Status = EFI_NOT_READY;
306 Status = Dhcp4->GetModeData (Dhcp4, &Dhcp4ModeData);
307 if (EFI_ERROR (Status)) {
312 return EFI_NO_MAPPING;
315 NvData = &ConfigData->SessionConfigData;
324 Status = Dhcp4->Parse (Dhcp4, Dhcp4ModeData.
ReplyPacket, &OptionCount, OptionList);
325 if (Status != EFI_BUFFER_TOO_SMALL) {
326 return EFI_DEVICE_ERROR;
330 if (OptionList ==
NULL) {
331 return EFI_OUT_OF_RESOURCES;
334 Status = Dhcp4->Parse (Dhcp4, Dhcp4ModeData.
ReplyPacket, &OptionCount, OptionList);
335 if (EFI_ERROR (Status)) {
337 return EFI_DEVICE_ERROR;
340 for (Index = 0; Index < OptionCount; Index++) {
344 if (OptionList[Index]->OpCode == DHCP4_TAG_DNS_SERVER) {
345 if (((OptionList[Index]->Length & 0x3) != 0) || (OptionList[Index]->Length == 0)) {
346 Status = EFI_INVALID_PARAMETER;
355 if (OptionList[Index]->Length > 4) {
361 }
else if (OptionList[Index]->OpCode == DHCP4_TAG_SERVER_ID) {
362 if (OptionList[Index]->Length != 4) {
363 Status = EFI_INVALID_PARAMETER;
395 Status = Ip4Config2->GetData (
401 if (EFI_ERROR (Status)) {
407 Status = Ip4Config2->SetData (
413 if (EFI_ERROR (Status)) {
461 AsciiPrint (
"\n Error: Could not detect network connection.\n");
472 Status =
gBS->HandleProtocol (Controller, &gEfiIp4Config2ProtocolGuid, (VOID **)&Ip4Config2);
473 if (!EFI_ERROR (Status)) {
475 if (EFI_ERROR (Status)) {
486 &gEfiDhcp4ServiceBindingProtocolGuid,
489 if (EFI_ERROR (Status)) {
493 Status =
gBS->OpenProtocol (
495 &gEfiDhcp4ProtocolGuid,
499 EFI_OPEN_PROTOCOL_BY_DRIVER
501 if (EFI_ERROR (Status)) {
505 NvData = &ConfigData->SessionConfigData;
508 if (ParaList ==
NULL) {
509 Status = EFI_OUT_OF_RESOURCES;
516 ParaList->
OpCode = DHCP4_TAG_PARA_LIST;
517 ParaList->
Length = (UINT8)(NvData->TargetInfoFromDhcp ? 4 : 3);
518 ParaList->
Data[0] = DHCP4_TAG_NETMASK;
519 ParaList->
Data[1] = DHCP4_TAG_ROUTER;
520 ParaList->
Data[2] = DHCP4_TAG_DNS_SERVER;
521 ParaList->
Data[3] = DHCP4_TAG_ROOTPATH;
527 if (NvData->TargetInfoFromDhcp) {
535 Status = Dhcp4->Configure (Dhcp4, &Dhcp4ConfigData);
536 if (EFI_ERROR (Status)) {
540 Status = Dhcp4->Start (Dhcp4,
NULL);
541 if (EFI_ERROR (Status)) {
552 if (ParaList !=
NULL) {
558 Dhcp4->Configure (Dhcp4,
NULL);
562 &gEfiDhcp4ProtocolGuid,
571 &gEfiDhcp4ServiceBindingProtocolGuid,
UINTN EFIAPI AsciiStrLen(IN CONST CHAR8 *String)
UINTN EFIAPI AsciiStrDecimalToUintn(IN CONST CHAR8 *String)
RETURN_STATUS EFIAPI AsciiStrCpyS(OUT CHAR8 *Destination, IN UINTN DestMax, IN CONST CHAR8 *Source)
INTN EFIAPI CompareMem(IN CONST VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
VOID EFIAPI FreePool(IN VOID *Buffer)
EFI_STATUS IScsiDoDhcp(IN EFI_HANDLE Image, IN EFI_HANDLE Controller, IN OUT ISCSI_ATTEMPT_CONFIG_NVDATA *ConfigData)
EFI_STATUS IScsiSetIp4Policy(IN EFI_IP4_CONFIG2_PROTOCOL *Ip4Config2)
EFI_STATUS IScsiDhcpExtractRootPath(IN CHAR8 *RootPath, IN UINT8 Length, IN OUT ISCSI_ATTEMPT_CONFIG_NVDATA *ConfigData)
EFI_STATUS IScsiParseDhcpAck(IN EFI_DHCP4_PROTOCOL *Dhcp4, IN OUT ISCSI_ATTEMPT_CONFIG_NVDATA *ConfigData)
EFI_STATUS EFIAPI IScsiDhcpSelectOffer(IN EFI_DHCP4_PROTOCOL *This, IN VOID *Context, IN EFI_DHCP4_STATE CurrentState, IN EFI_DHCP4_EVENT Dhcp4Event, IN EFI_DHCP4_PACKET *Packet OPTIONAL, OUT EFI_DHCP4_PACKET **NewPacket OPTIONAL)
EFI_STATUS IScsiAsciiStrToIp(IN CHAR8 *Str, IN UINT8 IpMode, OUT EFI_IP_ADDRESS *Ip)
EFI_STATUS IScsiAsciiStrToLun(IN CHAR8 *Str, OUT UINT8 *Lun)
EFI_STATUS IScsiNormalizeName(IN OUT CHAR8 *Name, IN UINTN Len)
@ Ip4Config2DataTypePolicy
EFI_STATUS EFIAPI NetLibCreateServiceChild(IN EFI_HANDLE Controller, IN EFI_HANDLE Image, IN EFI_GUID *ServiceBindingGuid, IN OUT EFI_HANDLE *ChildHandle)
EFI_STATUS EFIAPI NetLibDestroyServiceChild(IN EFI_HANDLE Controller, IN EFI_HANDLE Image, IN EFI_GUID *ServiceBindingGuid, IN EFI_HANDLE ChildHandle)
EFI_STATUS EFIAPI NetLibDetectMediaWaitTimeout(IN EFI_HANDLE ServiceHandle, IN UINT64 Timeout, OUT EFI_STATUS *MediaState)
VOID *EFIAPI AllocatePool(IN UINTN AllocationSize)
UINTN EFIAPI AsciiPrint(IN CONST CHAR8 *Format,...)
EFI_DHCP4_PACKET_OPTION ** OptionList
EFI_DHCP4_CALLBACK Dhcp4Callback
EFI_IPv4_ADDRESS SubnetMask
EFI_IPv4_ADDRESS RouterAddress
EFI_IPv4_ADDRESS ClientAddress
EFI_DHCP4_PACKET * ReplyPacket