]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - MdeModulePkg/Universal/Network/IScsiDxe/IScsiMisc.c
add security check.
[mirror_edk2.git] / MdeModulePkg / Universal / Network / IScsiDxe / IScsiMisc.c
... / ...
CommitLineData
1/** @file\r
2 Miscellaneous routines for iSCSI driver.\r
3\r
4Copyright (c) 2004 - 2009, Intel Corporation.<BR>\r
5All rights reserved. This program and the accompanying materials\r
6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15#include "IScsiImpl.h"\r
16\r
17GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 IScsiHexString[] = "0123456789ABCDEFabcdef";\r
18\r
19/**\r
20 Removes (trims) specified leading and trailing characters from a string.\r
21\r
22 @param[in, out] Str Pointer to the null-terminated string to be trimmed. On return, \r
23 Str will hold the trimmed string. \r
24\r
25 @param[in] CharC Character will be trimmed from str.\r
26**/\r
27VOID\r
28StrTrim (\r
29 IN OUT CHAR16 *Str,\r
30 IN CHAR16 CharC\r
31 )\r
32{\r
33 CHAR16 *Pointer1;\r
34 CHAR16 *Pointer2;\r
35 \r
36 if (*Str == 0) {\r
37 return;\r
38 }\r
39 \r
40 //\r
41 // Trim off the leading and trailing characters c\r
42 //\r
43 for (Pointer1 = Str; (*Pointer1 != 0) && (*Pointer1 == CharC); Pointer1++) {\r
44 ;\r
45 }\r
46 \r
47 Pointer2 = Str;\r
48 if (Pointer2 == Pointer1) {\r
49 while (*Pointer1 != 0) {\r
50 Pointer2++;\r
51 Pointer1++;\r
52 }\r
53 } else {\r
54 while (*Pointer1 != 0) { \r
55 *Pointer2 = *Pointer1; \r
56 Pointer1++;\r
57 Pointer2++;\r
58 }\r
59 *Pointer2 = 0;\r
60 }\r
61 \r
62 \r
63 for (Pointer1 = Str + StrLen(Str) - 1; Pointer1 >= Str && *Pointer1 == CharC; Pointer1--) {\r
64 ;\r
65 }\r
66 if (Pointer1 != Str + StrLen(Str) - 1) { \r
67 *(Pointer1 + 1) = 0;\r
68 }\r
69}\r
70\r
71/**\r
72 Calculate the prefix length of the IPv4 subnet mask.\r
73\r
74 @param[in] SubnetMask The IPv4 subnet mask.\r
75\r
76 @return The prefix length of the subnet mask.\r
77 @retval 0 Other errors as indicated.\r
78**/\r
79UINT8\r
80IScsiGetSubnetMaskPrefixLength (\r
81 IN EFI_IPv4_ADDRESS *SubnetMask\r
82 )\r
83{\r
84 UINT8 Len;\r
85 UINT32 ReverseMask;\r
86\r
87 //\r
88 // The SubnetMask is in network byte order.\r
89 //\r
90 ReverseMask = (SubnetMask->Addr[0] << 24) | (SubnetMask->Addr[1] << 16) | (SubnetMask->Addr[2] << 8) | (SubnetMask->Addr[3]);\r
91\r
92 //\r
93 // Reverse it.\r
94 //\r
95 ReverseMask = ~ReverseMask;\r
96\r
97 if ((ReverseMask & (ReverseMask + 1)) != 0) {\r
98 return 0;\r
99 }\r
100\r
101 Len = 0;\r
102\r
103 while (ReverseMask != 0) {\r
104 ReverseMask = ReverseMask >> 1;\r
105 Len++;\r
106 }\r
107\r
108 return (UINT8) (32 - Len);\r
109}\r
110\r
111/**\r
112 Convert the hexadecimal encoded LUN string into the 64-bit LUN. \r
113\r
114 @param[in] Str The hexadecimal encoded LUN string.\r
115 @param[out] Lun Storage to return the 64-bit LUN.\r
116\r
117 @retval EFI_SUCCESS The 64-bit LUN is stored in Lun.\r
118 @retval EFI_INVALID_PARAMETER The string is malformatted.\r
119**/\r
120EFI_STATUS\r
121IScsiAsciiStrToLun (\r
122 IN CHAR8 *Str,\r
123 OUT UINT8 *Lun\r
124 )\r
125{\r
126 UINTN Index, IndexValue, IndexNum, SizeStr;\r
127 CHAR8 TemStr[2];\r
128 UINT8 TemValue;\r
129 UINT16 Value [4];\r
130 \r
131 ZeroMem (Lun, 8);\r
132 ZeroMem (TemStr, 2);\r
133 ZeroMem ((UINT8 *) Value, sizeof (Value));\r
134 SizeStr = AsciiStrLen (Str); \r
135 IndexValue = 0;\r
136 IndexNum = 0;\r
137\r
138 for (Index = 0; Index < SizeStr; Index ++) {\r
139 TemStr[0] = Str[Index];\r
140 TemValue = (UINT8) AsciiStrHexToUint64 (TemStr);\r
141 if (TemValue == 0 && TemStr[0] != '0') {\r
142 if ((TemStr[0] != '-') || (IndexNum == 0)) {\r
143 //\r
144 // Invalid Lun Char\r
145 //\r
146 return EFI_INVALID_PARAMETER;\r
147 }\r
148 }\r
149 \r
150 if ((TemValue == 0) && (TemStr[0] == '-')) {\r
151 //\r
152 // Next Lun value\r
153 //\r
154 if (++IndexValue >= 4) {\r
155 //\r
156 // Max 4 Lun value\r
157 //\r
158 return EFI_INVALID_PARAMETER;\r
159 }\r
160 //\r
161 // Restart str index for the next lun value\r
162 //\r
163 IndexNum = 0;\r
164 continue;\r
165 }\r
166 \r
167 if (++IndexNum > 4) {\r
168 // \r
169 // Each Lun Str can't exceed size 4, because it will be as UINT16 value\r
170 //\r
171 return EFI_INVALID_PARAMETER;\r
172 }\r
173 \r
174 //\r
175 // Combine UINT16 value\r
176 //\r
177 Value[IndexValue] = (UINT16) ((Value[IndexValue] << 4) + TemValue);\r
178 }\r
179 \r
180 for (Index = 0; Index <= IndexValue; Index ++) {\r
181 *((UINT16 *) &Lun[Index * 2]) = HTONS (Value[Index]);\r
182 }\r
183 \r
184 return EFI_SUCCESS;\r
185}\r
186\r
187/**\r
188 Convert the 64-bit LUN into the hexadecimal encoded LUN string.\r
189\r
190 @param[in] Lun The 64-bit LUN.\r
191 @param[out] Str The storage to return the hexadecimal encoded LUN string.\r
192**/\r
193VOID\r
194IScsiLunToUnicodeStr (\r
195 IN UINT8 *Lun,\r
196 OUT CHAR16 *Str\r
197 )\r
198{\r
199 UINTN Index;\r
200 CHAR16 *TempStr;\r
201\r
202 TempStr = Str;\r
203\r
204 for (Index = 0; Index < 4; Index++) {\r
205\r
206 if ((Lun[2 * Index] | Lun[2 * Index + 1]) == 0) {\r
207 StrCpy (TempStr, L"0-");\r
208 } else {\r
209 TempStr[0] = (CHAR16) IScsiHexString[Lun[2 * Index] >> 4];\r
210 TempStr[1] = (CHAR16) IScsiHexString[Lun[2 * Index] & 0x0F];\r
211 TempStr[2] = (CHAR16) IScsiHexString[Lun[2 * Index + 1] >> 4];\r
212 TempStr[3] = (CHAR16) IScsiHexString[Lun[2 * Index + 1] & 0x0F];\r
213 TempStr[4] = L'-';\r
214 TempStr[5] = 0;\r
215\r
216 StrTrim (TempStr, L'0');\r
217 }\r
218\r
219 TempStr += StrLen (TempStr);\r
220 }\r
221\r
222 Str[StrLen (Str) - 1] = 0;\r
223\r
224 for (Index = StrLen (Str) - 1; Index > 1; Index = Index - 2) {\r
225 if ((Str[Index] == L'0') && (Str[Index - 1] == L'-')) {\r
226 Str[Index - 1] = 0;\r
227 } else {\r
228 break;\r
229 }\r
230 }\r
231}\r
232\r
233/**\r
234 Convert the ASCII string into a UNICODE string.\r
235\r
236 @param[in] Source The ASCII string.\r
237 @param[out] Destination The storage to return the UNICODE string.\r
238\r
239 @return CHAR16 * Pointer to the UNICODE string.\r
240**/\r
241CHAR16 *\r
242IScsiAsciiStrToUnicodeStr (\r
243 IN CHAR8 *Source,\r
244 OUT CHAR16 *Destination\r
245 )\r
246{\r
247 ASSERT (Destination != NULL);\r
248 ASSERT (Source != NULL);\r
249\r
250 while (*Source != '\0') {\r
251 *(Destination++) = (CHAR16) *(Source++);\r
252 }\r
253\r
254 *Destination = '\0';\r
255\r
256 return Destination;\r
257}\r
258\r
259/**\r
260 Convert the UNICODE string into an ASCII string.\r
261\r
262 @param[in] Source The UNICODE string.\r
263 @param[out] Destination The storage to return the ASCII string.\r
264\r
265 @return CHAR8 * Pointer to the ASCII string.\r
266**/\r
267CHAR8 *\r
268IScsiUnicodeStrToAsciiStr (\r
269 IN CHAR16 *Source,\r
270 OUT CHAR8 *Destination\r
271 )\r
272{\r
273 ASSERT (Destination != NULL);\r
274 ASSERT (Source != NULL);\r
275\r
276 while (*Source != '\0') {\r
277 //\r
278 // If any Unicode characters in Source contain\r
279 // non-zero value in the upper 8 bits, then ASSERT().\r
280 //\r
281 ASSERT (*Source < 0x100);\r
282 *(Destination++) = (CHAR8) *(Source++);\r
283 }\r
284\r
285 *Destination = '\0';\r
286\r
287 return Destination;\r
288}\r
289\r
290/**\r
291 Convert the decimal dotted IPv4 address into the binary IPv4 address.\r
292\r
293 @param[in] Str The UNICODE string.\r
294 @param[out] Ip The storage to return the ASCII string.\r
295\r
296 @retval EFI_SUCCESS The binary IP address is returned in Ip.\r
297 @retval EFI_INVALID_PARAMETER The IP string is malformatted.\r
298**/\r
299EFI_STATUS\r
300IScsiAsciiStrToIp (\r
301 IN CHAR8 *Str,\r
302 OUT EFI_IPv4_ADDRESS *Ip\r
303 )\r
304{\r
305 UINTN Index;\r
306 UINTN Number;\r
307\r
308 Index = 0;\r
309\r
310 while (*Str != 0) {\r
311\r
312 if (Index > 3) {\r
313 return EFI_INVALID_PARAMETER;\r
314 }\r
315\r
316 Number = 0;\r
317 while (NET_IS_DIGIT (*Str)) {\r
318 Number = Number * 10 + (*Str - '0');\r
319 Str++;\r
320 }\r
321\r
322 if (Number > 0xFF) {\r
323 return EFI_INVALID_PARAMETER;\r
324 }\r
325\r
326 Ip->Addr[Index] = (UINT8) Number;\r
327\r
328 if ((*Str != '\0') && (*Str != '.')) {\r
329 //\r
330 // The current character should be either the NULL terminator or\r
331 // the dot delimiter.\r
332 //\r
333 return EFI_INVALID_PARAMETER;\r
334 }\r
335\r
336 if (*Str == '.') {\r
337 //\r
338 // Skip the delimiter.\r
339 //\r
340 Str++;\r
341 }\r
342\r
343 Index++;\r
344 }\r
345\r
346 if (Index != 4) {\r
347 return EFI_INVALID_PARAMETER;\r
348 }\r
349\r
350 return EFI_SUCCESS;\r
351}\r
352\r
353/**\r
354 Convert the mac address into a hexadecimal encoded "-" seperated string.\r
355\r
356 @param[in] Mac The mac address.\r
357 @param[in] Len Length in bytes of the mac address.\r
358 @param[out] Str The storage to return the mac string.\r
359**/\r
360VOID\r
361IScsiMacAddrToStr (\r
362 IN EFI_MAC_ADDRESS *Mac,\r
363 IN UINT32 Len,\r
364 OUT CHAR16 *Str\r
365 )\r
366{\r
367 UINT32 Index;\r
368\r
369 for (Index = 0; Index < Len; Index++) {\r
370 Str[3 * Index] = (CHAR16) IScsiHexString[(Mac->Addr[Index] >> 4) & 0x0F];\r
371 Str[3 * Index + 1] = (CHAR16) IScsiHexString[Mac->Addr[Index] & 0x0F];\r
372 Str[3 * Index + 2] = L'-';\r
373 }\r
374\r
375 Str[3 * Index - 1] = L'\0';\r
376}\r
377\r
378/**\r
379 Convert the binary encoded buffer into a hexadecimal encoded string.\r
380\r
381 @param[in] BinBuffer The buffer containing the binary data.\r
382 @param[in] BinLength Length of the binary buffer.\r
383 @param[in, out] HexStr Pointer to the string.\r
384 @param[in, out] HexLength The length of the string.\r
385\r
386 @retval EFI_SUCCESS The binary data is converted to the hexadecimal string \r
387 and the length of the string is updated.\r
388 @retval EFI_BUFFER_TOO_SMALL The string is too small.\r
389 @retval EFI_INVALID_PARAMETER The IP string is malformatted.\r
390**/\r
391EFI_STATUS\r
392IScsiBinToHex (\r
393 IN UINT8 *BinBuffer,\r
394 IN UINT32 BinLength,\r
395 IN OUT CHAR8 *HexStr,\r
396 IN OUT UINT32 *HexLength\r
397 )\r
398{\r
399 UINTN Index;\r
400\r
401 if ((HexStr == NULL) || (BinBuffer == NULL) || (BinLength == 0)) {\r
402 return EFI_INVALID_PARAMETER;\r
403 }\r
404\r
405 if (((*HexLength) - 3) < BinLength * 2) {\r
406 *HexLength = BinLength * 2 + 3;\r
407 return EFI_BUFFER_TOO_SMALL;\r
408 }\r
409\r
410 *HexLength = BinLength * 2 + 3;\r
411 //\r
412 // Prefix for Hex String\r
413 //\r
414 HexStr[0] = '0';\r
415 HexStr[1] = 'x';\r
416\r
417 for (Index = 0; Index < BinLength; Index++) {\r
418 HexStr[Index * 2 + 2] = IScsiHexString[BinBuffer[Index] >> 4];\r
419 HexStr[Index * 2 + 3] = IScsiHexString[BinBuffer[Index] & 0x0F];\r
420 }\r
421\r
422 HexStr[Index * 2 + 2] = '\0';\r
423\r
424 return EFI_SUCCESS;\r
425}\r
426\r
427/**\r
428 Convert the hexadecimal string into a binary encoded buffer.\r
429\r
430 @param[in, out] BinBuffer The binary buffer.\r
431 @param[in, out] BinLength Length of the binary buffer.\r
432 @param[in] HexStr The hexadecimal string.\r
433\r
434 @retval EFI_SUCCESS The hexadecimal string is converted into a binary\r
435 encoded buffer.\r
436 @retval EFI_BUFFER_TOO_SMALL The binary buffer is too small to hold the converted data.\r
437**/\r
438EFI_STATUS\r
439IScsiHexToBin (\r
440 IN OUT UINT8 *BinBuffer,\r
441 IN OUT UINT32 *BinLength,\r
442 IN CHAR8 *HexStr\r
443 )\r
444{\r
445 UINTN Index;\r
446 UINTN Length;\r
447 UINT8 Digit;\r
448 CHAR8 TemStr[2];\r
449 \r
450 ZeroMem (TemStr, sizeof (TemStr));\r
451\r
452 //\r
453 // Find out how many hex characters the string has.\r
454 //\r
455 if ((HexStr[0] == '0') && ((HexStr[1] == 'x') || (HexStr[1] == 'X'))) {\r
456 HexStr += 2;\r
457 }\r
458 \r
459 Length = AsciiStrLen (HexStr);\r
460\r
461 for (Index = 0; Index < Length; Index ++) {\r
462 TemStr[0] = HexStr[Index];\r
463 Digit = (UINT8) AsciiStrHexToUint64 (TemStr);\r
464 if (Digit == 0 && TemStr[0] != '0') {\r
465 //\r
466 // Invalid Lun Char\r
467 //\r
468 break;\r
469 }\r
470 if ((Index & 1) == 0) {\r
471 BinBuffer [Index/2] = Digit;\r
472 } else {\r
473 BinBuffer [Index/2] = (UINT8) ((BinBuffer [Index/2] << 4) + Digit);\r
474 }\r
475 }\r
476 \r
477 *BinLength = (UINT32) ((Index + 1)/2);\r
478\r
479 return EFI_SUCCESS;\r
480}\r
481\r
482/**\r
483 Generate random numbers.\r
484\r
485 @param[in, out] Rand The buffer to contain random numbers.\r
486 @param[in] RandLength The length of the Rand buffer.\r
487**/\r
488VOID\r
489IScsiGenRandom (\r
490 IN OUT UINT8 *Rand,\r
491 IN UINTN RandLength\r
492 )\r
493{\r
494 UINT32 Random;\r
495\r
496 while (RandLength > 0) {\r
497 Random = NET_RANDOM (NetRandomInitSeed ());\r
498 *Rand++ = (UINT8) (Random);\r
499 RandLength--;\r
500 }\r
501}\r
502\r
503/**\r
504 Create the iSCSI driver data..\r
505\r
506 @param[in] Image The handle of the driver image.\r
507 @param[in] Controller The handle of the controller.\r
508\r
509 @return The iSCSI driver data created.\r
510 @retval NULL Other errors as indicated.\r
511**/\r
512ISCSI_DRIVER_DATA *\r
513IScsiCreateDriverData (\r
514 IN EFI_HANDLE Image,\r
515 IN EFI_HANDLE Controller\r
516 )\r
517{\r
518 ISCSI_DRIVER_DATA *Private;\r
519 EFI_STATUS Status;\r
520\r
521 Private = AllocateZeroPool (sizeof (ISCSI_DRIVER_DATA));\r
522 if (Private == NULL) {\r
523 return NULL;\r
524 }\r
525\r
526 Private->Signature = ISCSI_DRIVER_DATA_SIGNATURE;\r
527 Private->Image = Image;\r
528 Private->Controller = Controller;\r
529\r
530 //\r
531 // Create an event to be signal when the BS to RT transition is triggerd so\r
532 // as to abort the iSCSI session.\r
533 //\r
534 Status = gBS->CreateEventEx (\r
535 EVT_NOTIFY_SIGNAL,\r
536 TPL_CALLBACK,\r
537 IScsiOnExitBootService,\r
538 Private,\r
539 &gEfiEventExitBootServicesGuid,\r
540 &Private->ExitBootServiceEvent\r
541 );\r
542 if (EFI_ERROR (Status)) {\r
543 gBS->FreePool (Private);\r
544 return NULL;\r
545 }\r
546\r
547 CopyMem(&Private->IScsiExtScsiPassThru, &gIScsiExtScsiPassThruProtocolTemplate, sizeof(EFI_EXT_SCSI_PASS_THRU_PROTOCOL));\r
548\r
549 //\r
550 // 0 is designated to the TargetId, so use another value for the AdapterId.\r
551 //\r
552 Private->ExtScsiPassThruMode.AdapterId = 2;\r
553 Private->ExtScsiPassThruMode.Attributes = EFI_EXT_SCSI_PASS_THRU_ATTRIBUTES_PHYSICAL | EFI_EXT_SCSI_PASS_THRU_ATTRIBUTES_LOGICAL;\r
554 Private->ExtScsiPassThruMode.IoAlign = 4;\r
555 Private->IScsiExtScsiPassThru.Mode = &Private->ExtScsiPassThruMode;\r
556\r
557 //\r
558 // Install the Ext SCSI PASS THRU protocol.\r
559 //\r
560 Status = gBS->InstallProtocolInterface (\r
561 &Private->ExtScsiPassThruHandle,\r
562 &gEfiExtScsiPassThruProtocolGuid,\r
563 EFI_NATIVE_INTERFACE,\r
564 &Private->IScsiExtScsiPassThru\r
565 );\r
566 if (EFI_ERROR (Status)) {\r
567 gBS->CloseEvent (Private->ExitBootServiceEvent);\r
568 gBS->FreePool (Private);\r
569\r
570 return NULL;\r
571 }\r
572\r
573 IScsiSessionInit (&Private->Session, FALSE);\r
574\r
575 return Private;\r
576}\r
577\r
578/**\r
579 Clean the iSCSI driver data.\r
580\r
581 @param[in] Private The iSCSI driver data.\r
582**/\r
583VOID\r
584IScsiCleanDriverData (\r
585 IN ISCSI_DRIVER_DATA *Private\r
586 )\r
587{\r
588 if (Private->DevicePath != NULL) {\r
589 gBS->UninstallProtocolInterface (\r
590 Private->ExtScsiPassThruHandle,\r
591 &gEfiDevicePathProtocolGuid,\r
592 Private->DevicePath\r
593 );\r
594\r
595 gBS->FreePool (Private->DevicePath);\r
596 }\r
597\r
598 if (Private->ExtScsiPassThruHandle != NULL) {\r
599 gBS->UninstallProtocolInterface (\r
600 Private->ExtScsiPassThruHandle,\r
601 &gEfiExtScsiPassThruProtocolGuid,\r
602 &Private->IScsiExtScsiPassThru\r
603 );\r
604 }\r
605\r
606 gBS->CloseEvent (Private->ExitBootServiceEvent);\r
607\r
608 gBS->FreePool (Private);\r
609}\r
610\r
611/**\r
612 Get the various configuration data of this iSCSI instance.\r
613\r
614 @param[in] Private The iSCSI driver data.\r
615\r
616 @retval EFI_SUCCESS The configuration of this instance is got.\r
617 @retval EFI_ABORTED The operation was aborted.\r
618 @retval Others Other errors as indicated.\r
619**/\r
620EFI_STATUS\r
621IScsiGetConfigData (\r
622 IN ISCSI_DRIVER_DATA *Private\r
623 )\r
624{\r
625 EFI_STATUS Status;\r
626 ISCSI_SESSION *Session;\r
627 UINTN BufferSize;\r
628 EFI_SIMPLE_NETWORK_PROTOCOL *Snp;\r
629 EFI_SIMPLE_NETWORK_MODE *Mode;\r
630 CHAR16 MacString[65];\r
631\r
632 //\r
633 // get the iSCSI Initiator Name\r
634 //\r
635 Session = &Private->Session;\r
636 Session->InitiatorNameLength = ISCSI_NAME_MAX_SIZE;\r
637 Status = gIScsiInitiatorName.Get (\r
638 &gIScsiInitiatorName,\r
639 &Session->InitiatorNameLength,\r
640 Session->InitiatorName\r
641 );\r
642 if (EFI_ERROR (Status)) {\r
643 return Status;\r
644 }\r
645\r
646 Status = gBS->HandleProtocol (\r
647 Private->Controller,\r
648 &gEfiSimpleNetworkProtocolGuid,\r
649 (VOID **)&Snp\r
650 );\r
651 if (EFI_ERROR (Status)) {\r
652 return Status;\r
653 }\r
654\r
655 Mode = Snp->Mode;\r
656\r
657 //\r
658 // Get the mac string, it's the name of various variable\r
659 //\r
660 IScsiMacAddrToStr (&Mode->PermanentAddress, Mode->HwAddressSize, MacString);\r
661\r
662 //\r
663 // Get the normal configuration.\r
664 //\r
665 BufferSize = sizeof (Session->ConfigData.NvData);\r
666 Status = gRT->GetVariable (\r
667 MacString,\r
668 &gEfiIScsiInitiatorNameProtocolGuid,\r
669 NULL,\r
670 &BufferSize,\r
671 &Session->ConfigData.NvData\r
672 );\r
673 if (EFI_ERROR (Status)) {\r
674 return Status;\r
675 }\r
676\r
677 if (!Session->ConfigData.NvData.Enabled) {\r
678 return EFI_ABORTED;\r
679 }\r
680 //\r
681 // Get the CHAP Auth information.\r
682 //\r
683 BufferSize = sizeof (Session->AuthData.AuthConfig);\r
684 Status = gRT->GetVariable (\r
685 MacString,\r
686 &mIScsiCHAPAuthInfoGuid,\r
687 NULL,\r
688 &BufferSize,\r
689 &Session->AuthData.AuthConfig\r
690 );\r
691\r
692 if (!EFI_ERROR (Status) && Session->ConfigData.NvData.InitiatorInfoFromDhcp) {\r
693 //\r
694 // Start dhcp.\r
695 //\r
696 Status = IScsiDoDhcp (Private->Image, Private->Controller, &Session->ConfigData);\r
697 }\r
698\r
699 return Status;\r
700}\r
701\r
702/**\r
703 Get the device path of the iSCSI tcp connection and update it.\r
704\r
705 @param[in] Private The iSCSI driver data.\r
706\r
707 @return The updated device path.\r
708 @retval NULL Other errors as indicated.\r
709**/\r
710EFI_DEVICE_PATH_PROTOCOL *\r
711IScsiGetTcpConnDevicePath (\r
712 IN ISCSI_DRIVER_DATA *Private\r
713 )\r
714{\r
715 ISCSI_SESSION *Session;\r
716 ISCSI_CONNECTION *Conn;\r
717 TCP4_IO *Tcp4Io;\r
718 EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
719 EFI_STATUS Status;\r
720 EFI_DEV_PATH *DPathNode;\r
721\r
722 Session = &Private->Session;\r
723 if (Session->State != SESSION_STATE_LOGGED_IN) {\r
724 return NULL;\r
725 }\r
726\r
727 Conn = NET_LIST_USER_STRUCT_S (\r
728 Session->Conns.ForwardLink,\r
729 ISCSI_CONNECTION,\r
730 Link,\r
731 ISCSI_CONNECTION_SIGNATURE\r
732 );\r
733 Tcp4Io = &Conn->Tcp4Io;\r
734\r
735 Status = gBS->HandleProtocol (\r
736 Tcp4Io->Handle,\r
737 &gEfiDevicePathProtocolGuid,\r
738 (VOID **)&DevicePath\r
739 );\r
740 if (EFI_ERROR (Status)) {\r
741 return NULL;\r
742 }\r
743 //\r
744 // Duplicate it.\r
745 //\r
746 DevicePath = DuplicateDevicePath (DevicePath);\r
747 if (DevicePath == NULL) {\r
748 return NULL;\r
749 }\r
750\r
751 DPathNode = (EFI_DEV_PATH *) DevicePath;\r
752\r
753 while (!IsDevicePathEnd (&DPathNode->DevPath)) {\r
754 if ((DevicePathType (&DPathNode->DevPath) == MESSAGING_DEVICE_PATH) &&\r
755 (DevicePathSubType (&DPathNode->DevPath) == MSG_IPv4_DP)\r
756 ) {\r
757\r
758 DPathNode->Ipv4.LocalPort = 0;\r
759 DPathNode->Ipv4.StaticIpAddress = (BOOLEAN) (!Session->ConfigData.NvData.InitiatorInfoFromDhcp);\r
760 break;\r
761 }\r
762\r
763 DPathNode = (EFI_DEV_PATH *) NextDevicePathNode (&DPathNode->DevPath);\r
764 }\r
765\r
766 return DevicePath;\r
767}\r
768\r
769/**\r
770 Abort the session when the transition from BS to RT is initiated.\r
771\r
772 @param[in] Event The event signaled.\r
773 @param[in] Context The iSCSI driver data.\r
774**/\r
775VOID\r
776EFIAPI\r
777IScsiOnExitBootService (\r
778 IN EFI_EVENT Event,\r
779 IN VOID *Context\r
780 )\r
781{\r
782 ISCSI_DRIVER_DATA *Private;\r
783\r
784 Private = (ISCSI_DRIVER_DATA *) Context;\r
785 gBS->CloseEvent (Private->ExitBootServiceEvent);\r
786\r
787 IScsiSessionAbort (&Private->Session);\r
788}\r