2 Functions implementation related with Mtftp for UefiPxeBc Driver.
4 Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php.
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #include "PxeBcImpl.h"
18 CHAR8
*mMtftpOptions
[PXE_MTFTP_OPTION_MAXIMUM_INDEX
] = {
28 This is a callback function when packets are received or transmitted in Mtftp driver.
30 A callback function that is provided by the caller to intercept
31 the EFI_MTFTP6_OPCODE_DATA or EFI_MTFTP6_OPCODE_DATA8 packets processed in the
32 EFI_MTFTP6_PROTOCOL.ReadFile() function, and alternatively to intercept
33 EFI_MTFTP6_OPCODE_OACK or EFI_MTFTP6_OPCODE_ERROR packets during a call to
34 EFI_MTFTP6_PROTOCOL.ReadFile(), WriteFile() or ReadDirectory().
36 @param[in] This Pointer to EFI_MTFTP6_PROTOCOL.
37 @param[in] Token Pointer to EFI_MTFTP6_TOKEN.
38 @param[in] PacketLen Length of EFI_MTFTP6_PACKET.
39 @param[in] Packet Pointer to EFI_MTFTP6_PACKET to be checked.
41 @retval EFI_SUCCESS The current operation succeeded.
42 @retval EFI_ABORTED Abort the current transfer process.
47 PxeBcMtftp6CheckPacket (
48 IN EFI_MTFTP6_PROTOCOL
*This
,
49 IN EFI_MTFTP6_TOKEN
*Token
,
51 IN EFI_MTFTP6_PACKET
*Packet
54 PXEBC_PRIVATE_DATA
*Private
;
55 EFI_PXE_BASE_CODE_CALLBACK_PROTOCOL
*Callback
;
58 Private
= (PXEBC_PRIVATE_DATA
*) Token
->Context
;
59 Callback
= Private
->PxeBcCallback
;
62 if (Packet
->OpCode
== EFI_MTFTP6_OPCODE_ERROR
) {
64 // Store the tftp error message into mode data and set the received flag.
66 Private
->Mode
.TftpErrorReceived
= TRUE
;
67 Private
->Mode
.TftpError
.ErrorCode
= (UINT8
) Packet
->Error
.ErrorCode
;
69 Private
->Mode
.TftpError
.ErrorString
,
70 PXE_MTFTP_ERROR_STRING_LENGTH
,
71 (CHAR8
*) Packet
->Error
.ErrorMessage
,
72 PXE_MTFTP_ERROR_STRING_LENGTH
- 1
74 Private
->Mode
.TftpError
.ErrorString
[PXE_MTFTP_ERROR_STRING_LENGTH
- 1] = '\0';
77 if (Callback
!= NULL
) {
79 // Callback to user if has when received any tftp packet.
81 Status
= Callback
->Callback (
86 (EFI_PXE_BASE_CODE_PACKET
*) Packet
88 if (Status
!= EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE
) {
90 // User wants to abort current process if not EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE.
95 // User wants to continue current process if EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE.
106 This function is to get the size of a file using Tftp.
108 @param[in] Private Pointer to PxeBc private data.
109 @param[in] Config Pointer to EFI_MTFTP6_CONFIG_DATA.
110 @param[in] Filename Pointer to boot file name.
111 @param[in] BlockSize Pointer to required block size.
112 @param[in] WindowSize Pointer to required window size.
113 @param[in, out] BufferSize Pointer to buffer size.
115 @retval EFI_SUCCESS Sucessfully obtained the size of file.
116 @retval EFI_NOT_FOUND Parse the tftp ptions failed.
117 @retval EFI_DEVICE_ERROR The network device encountered an error during this operation.
118 @retval Others Has not obtained the size of the file.
122 PxeBcMtftp6GetFileSize (
123 IN PXEBC_PRIVATE_DATA
*Private
,
124 IN EFI_MTFTP6_CONFIG_DATA
*Config
,
127 IN UINTN
*WindowSize
,
128 IN OUT UINT64
*BufferSize
131 EFI_MTFTP6_PROTOCOL
*Mtftp6
;
132 EFI_MTFTP6_OPTION ReqOpt
[3];
133 EFI_MTFTP6_PACKET
*Packet
;
134 EFI_MTFTP6_OPTION
*Option
;
136 UINT8 OptBuf
[PXE_MTFTP_OPTBUF_MAXNUM_INDEX
];
142 Status
= EFI_DEVICE_ERROR
;
143 Mtftp6
= Private
->Mtftp6
;
147 OptBufSize
= PXE_MTFTP_OPTBUF_MAXNUM_INDEX
;
149 Config
->InitialServerPort
= PXEBC_BS_DOWNLOAD_PORT
;
151 Status
= Mtftp6
->Configure (Mtftp6
, Config
);
152 if (EFI_ERROR (Status
)) {
157 // Build the required options for get info.
159 ReqOpt
[0].OptionStr
= (UINT8
*) mMtftpOptions
[PXE_MTFTP_OPTION_TSIZE_INDEX
];
160 PxeBcUintnToAscDec (0, OptBuf
, OptBufSize
);
161 ReqOpt
[0].ValueStr
= OptBuf
;
163 if (BlockSize
!= NULL
) {
164 ReqOpt
[OptCnt
].OptionStr
= (UINT8
*) mMtftpOptions
[PXE_MTFTP_OPTION_BLKSIZE_INDEX
];
165 ReqOpt
[OptCnt
].ValueStr
= (UINT8
*) (ReqOpt
[OptCnt
-1].ValueStr
+ AsciiStrLen ((CHAR8
*) ReqOpt
[OptCnt
-1].ValueStr
) + 1);
166 OptBufSize
-= (AsciiStrLen ((CHAR8
*) ReqOpt
[OptCnt
-1].ValueStr
) + 1);
167 PxeBcUintnToAscDec (*BlockSize
, ReqOpt
[OptCnt
].ValueStr
, OptBufSize
);
171 if (WindowSize
!= NULL
) {
172 ReqOpt
[OptCnt
].OptionStr
= (UINT8
*) mMtftpOptions
[PXE_MTFTP_OPTION_WINDOWSIZE_INDEX
];
173 ReqOpt
[OptCnt
].ValueStr
= (UINT8
*) (ReqOpt
[OptCnt
-1].ValueStr
+ AsciiStrLen ((CHAR8
*) ReqOpt
[OptCnt
-1].ValueStr
) + 1);
174 OptBufSize
-= (AsciiStrLen ((CHAR8
*) ReqOpt
[OptCnt
-1].ValueStr
) + 1);
175 PxeBcUintnToAscDec (*WindowSize
, ReqOpt
[OptCnt
].ValueStr
, OptBufSize
);
179 Status
= Mtftp6
->GetInfo (
189 if (EFI_ERROR (Status
)) {
190 if (Status
== EFI_TFTP_ERROR
) {
192 // Store the tftp error message into mode data and set the received flag.
194 Private
->Mode
.TftpErrorReceived
= TRUE
;
195 Private
->Mode
.TftpError
.ErrorCode
= (UINT8
) Packet
->Error
.ErrorCode
;
197 Private
->Mode
.TftpError
.ErrorString
,
198 PXE_MTFTP_ERROR_STRING_LENGTH
,
199 (CHAR8
*) Packet
->Error
.ErrorMessage
,
200 PXE_MTFTP_ERROR_STRING_LENGTH
- 1
202 Private
->Mode
.TftpError
.ErrorString
[PXE_MTFTP_ERROR_STRING_LENGTH
- 1] = '\0';
208 // Parse the options in the reply packet.
211 Status
= Mtftp6
->ParseOptions (
218 if (EFI_ERROR (Status
)) {
223 // Parse out the value of "tsize" option.
225 Status
= EFI_NOT_FOUND
;
226 while (OptCnt
!= 0) {
227 if (AsciiStrnCmp ((CHAR8
*) Option
[OptCnt
- 1].OptionStr
, "tsize", 5) == 0) {
228 *BufferSize
= AsciiStrDecimalToUint64 ((CHAR8
*) (Option
[OptCnt
- 1].ValueStr
));
229 Status
= EFI_SUCCESS
;
236 if (Packet
!= NULL
) {
239 Mtftp6
->Configure (Mtftp6
, NULL
);
246 This function is to get data of a file using Tftp.
248 @param[in] Private Pointer to PxeBc private data.
249 @param[in] Config Pointer to EFI_MTFTP6_CONFIG_DATA.
250 @param[in] Filename Pointer to boot file name.
251 @param[in] BlockSize Pointer to required block size.
252 @param[in] WindowSize Pointer to required window size.
253 @param[in] BufferPtr Pointer to buffer.
254 @param[in, out] BufferSize Pointer to buffer size.
255 @param[in] DontUseBuffer Indicates whether with a receive buffer.
257 @retval EFI_SUCCESS Successfully read the data from the special file.
258 @retval EFI_DEVICE_ERROR The network device encountered an error during this operation.
259 @retval Others Read data from file failed.
263 PxeBcMtftp6ReadFile (
264 IN PXEBC_PRIVATE_DATA
*Private
,
265 IN EFI_MTFTP6_CONFIG_DATA
*Config
,
268 IN UINTN
*WindowSize
,
270 IN OUT UINT64
*BufferSize
,
271 IN BOOLEAN DontUseBuffer
274 EFI_MTFTP6_PROTOCOL
*Mtftp6
;
275 EFI_MTFTP6_TOKEN Token
;
276 EFI_MTFTP6_OPTION ReqOpt
[2];
278 UINT8 BlksizeBuf
[10];
279 UINT8 WindowsizeBuf
[10];
282 Status
= EFI_DEVICE_ERROR
;
283 Mtftp6
= Private
->Mtftp6
;
285 Config
->InitialServerPort
= PXEBC_BS_DOWNLOAD_PORT
;
287 Status
= Mtftp6
->Configure (Mtftp6
, Config
);
288 if (EFI_ERROR (Status
)) {
292 if (BlockSize
!= NULL
) {
293 ReqOpt
[OptCnt
].OptionStr
= (UINT8
*) mMtftpOptions
[PXE_MTFTP_OPTION_BLKSIZE_INDEX
];
294 ReqOpt
[OptCnt
].ValueStr
= BlksizeBuf
;
295 PxeBcUintnToAscDec (*BlockSize
, ReqOpt
[OptCnt
].ValueStr
, sizeof (BlksizeBuf
));
299 if (WindowSize
!= NULL
) {
300 ReqOpt
[OptCnt
].OptionStr
= (UINT8
*) mMtftpOptions
[PXE_MTFTP_OPTION_WINDOWSIZE_INDEX
];
301 ReqOpt
[OptCnt
].ValueStr
= WindowsizeBuf
;
302 PxeBcUintnToAscDec (*WindowSize
, ReqOpt
[OptCnt
].ValueStr
, sizeof (WindowsizeBuf
));
308 Token
.OverrideData
= NULL
;
309 Token
.Filename
= Filename
;
310 Token
.ModeStr
= NULL
;
311 Token
.OptionCount
= OptCnt
;
312 Token
.OptionList
= ReqOpt
;
313 Token
.Context
= Private
;
316 Token
.BufferSize
= 0;
319 Token
.BufferSize
= *BufferSize
;
320 Token
.Buffer
= BufferPtr
;
323 Token
.CheckPacket
= PxeBcMtftp6CheckPacket
;
324 Token
.TimeoutCallback
= NULL
;
325 Token
.PacketNeeded
= NULL
;
327 Status
= Mtftp6
->ReadFile (Mtftp6
, &Token
);
329 // Get the real size of received buffer.
331 *BufferSize
= Token
.BufferSize
;
333 Mtftp6
->Configure (Mtftp6
, NULL
);
340 This function is used to write the data of a file using Tftp.
342 @param[in] Private Pointer to PxeBc private data.
343 @param[in] Config Pointer to EFI_MTFTP6_CONFIG_DATA.
344 @param[in] Filename Pointer to boot file name.
345 @param[in] Overwrite Indicate whether with overwrite attribute.
346 @param[in] BlockSize Pointer to required block size.
347 @param[in] BufferPtr Pointer to buffer.
348 @param[in, out] BufferSize Pointer to buffer size.
350 @retval EFI_SUCCESS Successfully wrote the data into a special file.
351 @retval EFI_DEVICE_ERROR The network device encountered an error during this operation.
352 @retval other Write data into file failed.
356 PxeBcMtftp6WriteFile (
357 IN PXEBC_PRIVATE_DATA
*Private
,
358 IN EFI_MTFTP6_CONFIG_DATA
*Config
,
360 IN BOOLEAN Overwrite
,
363 IN OUT UINT64
*BufferSize
366 EFI_MTFTP6_PROTOCOL
*Mtftp6
;
367 EFI_MTFTP6_TOKEN Token
;
368 EFI_MTFTP6_OPTION ReqOpt
[1];
373 Status
= EFI_DEVICE_ERROR
;
374 Mtftp6
= Private
->Mtftp6
;
376 Config
->InitialServerPort
= PXEBC_BS_DOWNLOAD_PORT
;
378 Status
= Mtftp6
->Configure (Mtftp6
, Config
);
379 if (EFI_ERROR (Status
)) {
383 if (BlockSize
!= NULL
) {
384 ReqOpt
[0].OptionStr
= (UINT8
*) mMtftpOptions
[PXE_MTFTP_OPTION_BLKSIZE_INDEX
];
385 ReqOpt
[0].ValueStr
= OptBuf
;
386 PxeBcUintnToAscDec (*BlockSize
, ReqOpt
[0].ValueStr
, PXE_MTFTP_OPTBUF_MAXNUM_INDEX
);
391 Token
.OverrideData
= NULL
;
392 Token
.Filename
= Filename
;
393 Token
.ModeStr
= NULL
;
394 Token
.OptionCount
= OptCnt
;
395 Token
.OptionList
= ReqOpt
;
396 Token
.BufferSize
= *BufferSize
;
397 Token
.Buffer
= BufferPtr
;
398 Token
.CheckPacket
= PxeBcMtftp6CheckPacket
;
399 Token
.TimeoutCallback
= NULL
;
400 Token
.PacketNeeded
= NULL
;
402 Status
= Mtftp6
->WriteFile (Mtftp6
, &Token
);
404 // Get the real size of transmitted buffer.
406 *BufferSize
= Token
.BufferSize
;
408 Mtftp6
->Configure (Mtftp6
, NULL
);
415 This function is to read the data (file) from a directory using Tftp.
417 @param[in] Private Pointer to PxeBc private data.
418 @param[in] Config Pointer to EFI_MTFTP6_CONFIG_DATA.
419 @param[in] Filename Pointer to boot file name.
420 @param[in] BlockSize Pointer to required block size.
421 @param[in] WindowSize Pointer to required window size.
422 @param[in] BufferPtr Pointer to buffer.
423 @param[in, out] BufferSize Pointer to buffer size.
424 @param[in] DontUseBuffer Indicates whether to use a receive buffer.
426 @retval EFI_SUCCESS Successfully obtained the data from the file included in directory.
427 @retval EFI_DEVICE_ERROR The network device encountered an error during this operation.
428 @retval Others Operation failed.
432 PxeBcMtftp6ReadDirectory (
433 IN PXEBC_PRIVATE_DATA
*Private
,
434 IN EFI_MTFTP6_CONFIG_DATA
*Config
,
437 IN UINTN
*WindowSize
,
439 IN OUT UINT64
*BufferSize
,
440 IN BOOLEAN DontUseBuffer
443 EFI_MTFTP6_PROTOCOL
*Mtftp6
;
444 EFI_MTFTP6_TOKEN Token
;
445 EFI_MTFTP6_OPTION ReqOpt
[2];
447 UINT8 BlksizeBuf
[10];
448 UINT8 WindowsizeBuf
[10];
451 Status
= EFI_DEVICE_ERROR
;
452 Mtftp6
= Private
->Mtftp6
;
454 Config
->InitialServerPort
= PXEBC_BS_DOWNLOAD_PORT
;
456 Status
= Mtftp6
->Configure (Mtftp6
, Config
);
457 if (EFI_ERROR (Status
)) {
461 if (BlockSize
!= NULL
) {
462 ReqOpt
[OptCnt
].OptionStr
= (UINT8
*) mMtftpOptions
[PXE_MTFTP_OPTION_BLKSIZE_INDEX
];
463 ReqOpt
[OptCnt
].ValueStr
= BlksizeBuf
;
464 PxeBcUintnToAscDec (*BlockSize
, ReqOpt
[OptCnt
].ValueStr
, sizeof (BlksizeBuf
));
468 if (WindowSize
!= NULL
) {
469 ReqOpt
[OptCnt
].OptionStr
= (UINT8
*) mMtftpOptions
[PXE_MTFTP_OPTION_WINDOWSIZE_INDEX
];
470 ReqOpt
[OptCnt
].ValueStr
= WindowsizeBuf
;
471 PxeBcUintnToAscDec (*WindowSize
, ReqOpt
[OptCnt
].ValueStr
, sizeof (WindowsizeBuf
));
476 Token
.OverrideData
= NULL
;
477 Token
.Filename
= Filename
;
478 Token
.ModeStr
= NULL
;
479 Token
.OptionCount
= OptCnt
;
480 Token
.OptionList
= ReqOpt
;
481 Token
.Context
= Private
;
484 Token
.BufferSize
= 0;
487 Token
.BufferSize
= *BufferSize
;
488 Token
.Buffer
= BufferPtr
;
491 Token
.CheckPacket
= PxeBcMtftp6CheckPacket
;
492 Token
.TimeoutCallback
= NULL
;
493 Token
.PacketNeeded
= NULL
;
495 Status
= Mtftp6
->ReadDirectory (Mtftp6
, &Token
);
497 // Get the real size of received buffer.
499 *BufferSize
= Token
.BufferSize
;
501 Mtftp6
->Configure (Mtftp6
, NULL
);
508 This is a callback function when packets are received or transmitted in Mtftp driver.
510 A callback function that is provided by the caller to intercept
511 the EFI_MTFTP6_OPCODE_DATA or EFI_MTFTP4_OPCODE_DATA8 packets processed in the
512 EFI_MTFTP4_PROTOCOL.ReadFile() function, and alternatively to intercept
513 EFI_MTFTP4_OPCODE_OACK or EFI_MTFTP4_OPCODE_ERROR packets during a call to
514 EFI_MTFTP4_PROTOCOL.ReadFile(), WriteFile() or ReadDirectory().
516 @param[in] This Pointer to EFI_MTFTP4_PROTOCOL.
517 @param[in] Token Pointer to EFI_MTFTP4_TOKEN.
518 @param[in] PacketLen Length of EFI_MTFTP4_PACKET.
519 @param[in] Packet Pointer to EFI_MTFTP4_PACKET to be checked.
521 @retval EFI_SUCCESS The current operation succeeeded.
522 @retval EFI_ABORTED Abort the current transfer process.
527 PxeBcMtftp4CheckPacket (
528 IN EFI_MTFTP4_PROTOCOL
*This
,
529 IN EFI_MTFTP4_TOKEN
*Token
,
531 IN EFI_MTFTP4_PACKET
*Packet
534 PXEBC_PRIVATE_DATA
*Private
;
535 EFI_PXE_BASE_CODE_CALLBACK_PROTOCOL
*Callback
;
538 Private
= (PXEBC_PRIVATE_DATA
*) Token
->Context
;
539 Callback
= Private
->PxeBcCallback
;
540 Status
= EFI_SUCCESS
;
542 if (Packet
->OpCode
== EFI_MTFTP4_OPCODE_ERROR
) {
544 // Store the tftp error message into mode data and set the received flag.
546 Private
->Mode
.TftpErrorReceived
= TRUE
;
547 Private
->Mode
.TftpError
.ErrorCode
= (UINT8
) Packet
->Error
.ErrorCode
;
549 Private
->Mode
.TftpError
.ErrorString
,
550 PXE_MTFTP_ERROR_STRING_LENGTH
,
551 (CHAR8
*) Packet
->Error
.ErrorMessage
,
552 PXE_MTFTP_ERROR_STRING_LENGTH
- 1
554 Private
->Mode
.TftpError
.ErrorString
[PXE_MTFTP_ERROR_STRING_LENGTH
- 1] = '\0';
557 if (Callback
!= NULL
) {
559 // Callback to user if has when received any tftp packet.
561 Status
= Callback
->Callback (
566 (EFI_PXE_BASE_CODE_PACKET
*) Packet
568 if (Status
!= EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE
) {
570 // User wants to abort current process if not EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE.
572 Status
= EFI_ABORTED
;
575 // User wants to continue current process if EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE.
577 Status
= EFI_SUCCESS
;
586 This function is to get size of a file using Tftp.
588 @param[in] Private Pointer to PxeBc private data.
589 @param[in] Config Pointer to EFI_MTFTP4_CONFIG_DATA.
590 @param[in] Filename Pointer to boot file name.
591 @param[in] BlockSize Pointer to required block size.
592 @param[in] WindowSize Pointer to required window size.
593 @param[in, out] BufferSize Pointer to buffer size.
595 @retval EFI_SUCCESS Successfully obtained the size of file.
596 @retval EFI_NOT_FOUND Parse the tftp options failed.
597 @retval EFI_DEVICE_ERROR The network device encountered an error during this operation.
598 @retval Others Did not obtain the size of the file.
602 PxeBcMtftp4GetFileSize (
603 IN PXEBC_PRIVATE_DATA
*Private
,
604 IN EFI_MTFTP4_CONFIG_DATA
*Config
,
607 IN UINTN
*WindowSize
,
608 IN OUT UINT64
*BufferSize
611 EFI_MTFTP4_PROTOCOL
*Mtftp4
;
612 EFI_MTFTP4_OPTION ReqOpt
[3];
613 EFI_MTFTP4_PACKET
*Packet
;
614 EFI_MTFTP4_OPTION
*Option
;
616 UINT8 OptBuf
[PXE_MTFTP_OPTBUF_MAXNUM_INDEX
];
622 Status
= EFI_DEVICE_ERROR
;
623 Mtftp4
= Private
->Mtftp4
;
627 OptBufSize
= PXE_MTFTP_OPTBUF_MAXNUM_INDEX
;
629 Config
->InitialServerPort
= PXEBC_BS_DOWNLOAD_PORT
;
631 Status
= Mtftp4
->Configure (Mtftp4
, Config
);
632 if (EFI_ERROR (Status
)) {
637 // Build the required options for get info.
639 ReqOpt
[0].OptionStr
= (UINT8
*) mMtftpOptions
[PXE_MTFTP_OPTION_TSIZE_INDEX
];
640 PxeBcUintnToAscDec (0, OptBuf
, OptBufSize
);
641 ReqOpt
[0].ValueStr
= OptBuf
;
643 if (BlockSize
!= NULL
) {
644 ReqOpt
[OptCnt
].OptionStr
= (UINT8
*) mMtftpOptions
[PXE_MTFTP_OPTION_BLKSIZE_INDEX
];
645 ReqOpt
[OptCnt
].ValueStr
= (UINT8
*) (ReqOpt
[OptCnt
-1].ValueStr
+ AsciiStrLen ((CHAR8
*) ReqOpt
[OptCnt
-1].ValueStr
) + 1);
646 OptBufSize
-= (AsciiStrLen ((CHAR8
*) ReqOpt
[OptCnt
-1].ValueStr
) + 1);
647 PxeBcUintnToAscDec (*BlockSize
, ReqOpt
[OptCnt
].ValueStr
, OptBufSize
);
651 if (WindowSize
!= NULL
) {
652 ReqOpt
[OptCnt
].OptionStr
= (UINT8
*) mMtftpOptions
[PXE_MTFTP_OPTION_WINDOWSIZE_INDEX
];
653 ReqOpt
[OptCnt
].ValueStr
= (UINT8
*) (ReqOpt
[OptCnt
-1].ValueStr
+ AsciiStrLen ((CHAR8
*) ReqOpt
[OptCnt
-1].ValueStr
) + 1);
654 OptBufSize
-= (AsciiStrLen ((CHAR8
*) ReqOpt
[OptCnt
-1].ValueStr
) + 1);
655 PxeBcUintnToAscDec (*WindowSize
, ReqOpt
[OptCnt
].ValueStr
, OptBufSize
);
659 Status
= Mtftp4
->GetInfo (
669 if (EFI_ERROR (Status
)) {
670 if (Status
== EFI_TFTP_ERROR
) {
672 // Store the tftp error message into mode data and set the received flag.
674 Private
->Mode
.TftpErrorReceived
= TRUE
;
675 Private
->Mode
.TftpError
.ErrorCode
= (UINT8
) Packet
->Error
.ErrorCode
;
677 Private
->Mode
.TftpError
.ErrorString
,
678 PXE_MTFTP_ERROR_STRING_LENGTH
,
679 (CHAR8
*) Packet
->Error
.ErrorMessage
,
680 PXE_MTFTP_ERROR_STRING_LENGTH
- 1
682 Private
->Mode
.TftpError
.ErrorString
[PXE_MTFTP_ERROR_STRING_LENGTH
- 1] = '\0';
688 // Parse the options in the reply packet.
691 Status
= Mtftp4
->ParseOptions (
698 if (EFI_ERROR (Status
)) {
703 // Parse out the value of "tsize" option.
705 Status
= EFI_NOT_FOUND
;
706 while (OptCnt
!= 0) {
707 if (AsciiStrnCmp ((CHAR8
*) Option
[OptCnt
- 1].OptionStr
, "tsize", 5) == 0) {
708 *BufferSize
= AsciiStrDecimalToUint64 ((CHAR8
*) (Option
[OptCnt
- 1].ValueStr
));
709 Status
= EFI_SUCCESS
;
716 if (Packet
!= NULL
) {
719 Mtftp4
->Configure (Mtftp4
, NULL
);
726 This function is to read the data of a file using Tftp.
728 @param[in] Private Pointer to PxeBc private data.
729 @param[in] Config Pointer to EFI_MTFTP4_CONFIG_DATA.
730 @param[in] Filename Pointer to boot file name.
731 @param[in] BlockSize Pointer to required block size.
732 @param[in] WindowSize Pointer to required window size.
733 @param[in] BufferPtr Pointer to buffer.
734 @param[in, out] BufferSize Pointer to buffer size.
735 @param[in] DontUseBuffer Indicates whether to use a receive buffer.
737 @retval EFI_SUCCESS Successfully read the data from the special file.
738 @retval EFI_DEVICE_ERROR The network device encountered an error during this operation.
739 @retval Others Read data from file failed.
743 PxeBcMtftp4ReadFile (
744 IN PXEBC_PRIVATE_DATA
*Private
,
745 IN EFI_MTFTP4_CONFIG_DATA
*Config
,
748 IN UINTN
*WindowSize
,
750 IN OUT UINT64
*BufferSize
,
751 IN BOOLEAN DontUseBuffer
754 EFI_MTFTP4_PROTOCOL
*Mtftp4
;
755 EFI_MTFTP4_TOKEN Token
;
756 EFI_MTFTP4_OPTION ReqOpt
[2];
758 UINT8 BlksizeBuf
[10];
759 UINT8 WindowsizeBuf
[10];
762 Status
= EFI_DEVICE_ERROR
;
763 Mtftp4
= Private
->Mtftp4
;
765 Config
->InitialServerPort
= PXEBC_BS_DOWNLOAD_PORT
;
767 Status
= Mtftp4
->Configure (Mtftp4
, Config
);
768 if (EFI_ERROR (Status
)) {
772 if (BlockSize
!= NULL
) {
773 ReqOpt
[OptCnt
].OptionStr
= (UINT8
*) mMtftpOptions
[PXE_MTFTP_OPTION_BLKSIZE_INDEX
];
774 ReqOpt
[OptCnt
].ValueStr
= BlksizeBuf
;
775 PxeBcUintnToAscDec (*BlockSize
, ReqOpt
[OptCnt
].ValueStr
, sizeof (BlksizeBuf
));
779 if (WindowSize
!= NULL
) {
780 ReqOpt
[OptCnt
].OptionStr
= (UINT8
*) mMtftpOptions
[PXE_MTFTP_OPTION_WINDOWSIZE_INDEX
];
781 ReqOpt
[OptCnt
].ValueStr
= WindowsizeBuf
;
782 PxeBcUintnToAscDec (*WindowSize
, ReqOpt
[OptCnt
].ValueStr
, sizeof (WindowsizeBuf
));
787 Token
.OverrideData
= NULL
;
788 Token
.Filename
= Filename
;
789 Token
.ModeStr
= NULL
;
790 Token
.OptionCount
= OptCnt
;
791 Token
.OptionList
= ReqOpt
;
792 Token
.Context
= Private
;
795 Token
.BufferSize
= 0;
798 Token
.BufferSize
= *BufferSize
;
799 Token
.Buffer
= BufferPtr
;
802 Token
.CheckPacket
= PxeBcMtftp4CheckPacket
;
803 Token
.TimeoutCallback
= NULL
;
804 Token
.PacketNeeded
= NULL
;
806 Status
= Mtftp4
->ReadFile (Mtftp4
, &Token
);
808 // Get the real size of received buffer.
810 *BufferSize
= Token
.BufferSize
;
812 Mtftp4
->Configure (Mtftp4
, NULL
);
819 This function is to write the data of a file using Tftp.
821 @param[in] Private Pointer to PxeBc private data.
822 @param[in] Config Pointer to EFI_MTFTP4_CONFIG_DATA.
823 @param[in] Filename Pointer to boot file name.
824 @param[in] Overwrite Indicates whether to use the overwrite attribute.
825 @param[in] BlockSize Pointer to required block size.
826 @param[in] BufferPtr Pointer to buffer.
827 @param[in, out] BufferSize Pointer to buffer size.
829 @retval EFI_SUCCESS Successfully write the data into the special file.
830 @retval EFI_DEVICE_ERROR The network device encountered an error during this operation.
831 @retval other Write data into file failed.
835 PxeBcMtftp4WriteFile (
836 IN PXEBC_PRIVATE_DATA
*Private
,
837 IN EFI_MTFTP4_CONFIG_DATA
*Config
,
839 IN BOOLEAN Overwrite
,
842 IN OUT UINT64
*BufferSize
845 EFI_MTFTP4_PROTOCOL
*Mtftp4
;
846 EFI_MTFTP4_TOKEN Token
;
847 EFI_MTFTP4_OPTION ReqOpt
[1];
852 Status
= EFI_DEVICE_ERROR
;
853 Mtftp4
= Private
->Mtftp4
;
855 Config
->InitialServerPort
= PXEBC_BS_DOWNLOAD_PORT
;
857 Status
= Mtftp4
->Configure (Mtftp4
, Config
);
858 if (EFI_ERROR (Status
)) {
862 if (BlockSize
!= NULL
) {
863 ReqOpt
[0].OptionStr
= (UINT8
*) mMtftpOptions
[PXE_MTFTP_OPTION_BLKSIZE_INDEX
];
864 ReqOpt
[0].ValueStr
= OptBuf
;
865 PxeBcUintnToAscDec (*BlockSize
, ReqOpt
[0].ValueStr
, PXE_MTFTP_OPTBUF_MAXNUM_INDEX
);
870 Token
.OverrideData
= NULL
;
871 Token
.Filename
= Filename
;
872 Token
.ModeStr
= NULL
;
873 Token
.OptionCount
= OptCnt
;
874 Token
.OptionList
= ReqOpt
;
875 Token
.BufferSize
= *BufferSize
;
876 Token
.Buffer
= BufferPtr
;
877 Token
.CheckPacket
= PxeBcMtftp4CheckPacket
;
878 Token
.TimeoutCallback
= NULL
;
879 Token
.PacketNeeded
= NULL
;
881 Status
= Mtftp4
->WriteFile (Mtftp4
, &Token
);
883 // Get the real size of transmitted buffer.
885 *BufferSize
= Token
.BufferSize
;
887 Mtftp4
->Configure (Mtftp4
, NULL
);
894 This function is to get data (file) from a directory using Tftp.
896 @param[in] Private Pointer to PxeBc private data.
897 @param[in] Config Pointer to EFI_MTFTP4_CONFIG_DATA.
898 @param[in] Filename Pointer to boot file name.
899 @param[in] BlockSize Pointer to required block size.
900 @param[in] WindowSize Pointer to required window size.
901 @param[in] BufferPtr Pointer to buffer.
902 @param[in, out] BufferSize Pointer to buffer size.
903 @param[in] DontUseBuffer Indicates whether to use a receive buffer.
905 @retval EFI_SUCCES Successfully obtained the data from the file included in the directory.
906 @retval EFI_DEVICE_ERROR The network device encountered an error during this operation.
907 @retval Others Operation failed.
911 PxeBcMtftp4ReadDirectory (
912 IN PXEBC_PRIVATE_DATA
*Private
,
913 IN EFI_MTFTP4_CONFIG_DATA
*Config
,
916 IN UINTN
*WindowSize
,
918 IN OUT UINT64
*BufferSize
,
919 IN BOOLEAN DontUseBuffer
922 EFI_MTFTP4_PROTOCOL
*Mtftp4
;
923 EFI_MTFTP4_TOKEN Token
;
924 EFI_MTFTP4_OPTION ReqOpt
[2];
926 UINT8 BlksizeBuf
[10];
927 UINT8 WindowsizeBuf
[10];
930 Status
= EFI_DEVICE_ERROR
;
931 Mtftp4
= Private
->Mtftp4
;
933 Config
->InitialServerPort
= PXEBC_BS_DOWNLOAD_PORT
;
935 Status
= Mtftp4
->Configure (Mtftp4
, Config
);
936 if (EFI_ERROR (Status
)) {
940 if (BlockSize
!= NULL
) {
941 ReqOpt
[OptCnt
].OptionStr
= (UINT8
*) mMtftpOptions
[PXE_MTFTP_OPTION_BLKSIZE_INDEX
];
942 ReqOpt
[OptCnt
].ValueStr
= BlksizeBuf
;
943 PxeBcUintnToAscDec (*BlockSize
, ReqOpt
[OptCnt
].ValueStr
, sizeof (BlksizeBuf
));
947 if (WindowSize
!= NULL
) {
948 ReqOpt
[OptCnt
].OptionStr
= (UINT8
*) mMtftpOptions
[PXE_MTFTP_OPTION_WINDOWSIZE_INDEX
];
949 ReqOpt
[OptCnt
].ValueStr
= WindowsizeBuf
;
950 PxeBcUintnToAscDec (*WindowSize
, ReqOpt
[OptCnt
].ValueStr
, sizeof (WindowsizeBuf
));
955 Token
.OverrideData
= NULL
;
956 Token
.Filename
= Filename
;
957 Token
.ModeStr
= NULL
;
958 Token
.OptionCount
= OptCnt
;
959 Token
.OptionList
= ReqOpt
;
960 Token
.Context
= Private
;
963 Token
.BufferSize
= 0;
966 Token
.BufferSize
= *BufferSize
;
967 Token
.Buffer
= BufferPtr
;
970 Token
.CheckPacket
= PxeBcMtftp4CheckPacket
;
971 Token
.TimeoutCallback
= NULL
;
972 Token
.PacketNeeded
= NULL
;
974 Status
= Mtftp4
->ReadDirectory (Mtftp4
, &Token
);
976 // Get the real size of received buffer.
978 *BufferSize
= Token
.BufferSize
;
980 Mtftp4
->Configure (Mtftp4
, NULL
);
987 This function is wrapper to get the file size using TFTP.
989 @param[in] Private Pointer to PxeBc private data.
990 @param[in] Config Pointer to configure data.
991 @param[in] Filename Pointer to boot file name.
992 @param[in] BlockSize Pointer to required block size.
993 @param[in] WindowSize Pointer to required window size.
994 @param[in, out] BufferSize Pointer to buffer size.
996 @retval EFI_SUCCESS Successfully obtained the size of file.
997 @retval EFI_NOT_FOUND Parse the tftp options failed.
998 @retval EFI_DEVICE_ERROR The network device encountered an error during this operation.
999 @retval Others Did not obtain the size of the file.
1003 PxeBcTftpGetFileSize (
1004 IN PXEBC_PRIVATE_DATA
*Private
,
1007 IN UINTN
*BlockSize
,
1008 IN UINTN
*WindowSize
,
1009 IN OUT UINT64
*BufferSize
1012 if (Private
->PxeBc
.Mode
->UsingIpv6
) {
1013 return PxeBcMtftp6GetFileSize (
1015 (EFI_MTFTP6_CONFIG_DATA
*) Config
,
1022 return PxeBcMtftp4GetFileSize (
1024 (EFI_MTFTP4_CONFIG_DATA
*) Config
,
1035 This function is a wrapper to get file using TFTP.
1037 @param[in] Private Pointer to PxeBc private data.
1038 @param[in] Config Pointer to config data.
1039 @param[in] Filename Pointer to boot file name.
1040 @param[in] BlockSize Pointer to required block size.
1041 @param[in] WindowSize Pointer to required window size.
1042 @param[in] BufferPtr Pointer to buffer.
1043 @param[in, out] BufferSize Pointer to buffer size.
1044 @param[in] DontUseBuffer Indicates whether to use a receive buffer.
1046 @retval EFI_SUCCESS Sucessfully read the data from the special file.
1047 @retval EFI_DEVICE_ERROR The network device encountered an error during this operation.
1048 @retval Others Read data from file failed.
1053 IN PXEBC_PRIVATE_DATA
*Private
,
1056 IN UINTN
*BlockSize
,
1057 IN UINTN
*WindowSize
,
1058 IN UINT8
*BufferPtr
,
1059 IN OUT UINT64
*BufferSize
,
1060 IN BOOLEAN DontUseBuffer
1063 if (Private
->PxeBc
.Mode
->UsingIpv6
) {
1064 return PxeBcMtftp6ReadFile (
1066 (EFI_MTFTP6_CONFIG_DATA
*) Config
,
1075 return PxeBcMtftp4ReadFile (
1077 (EFI_MTFTP4_CONFIG_DATA
*) Config
,
1090 This function is a wrapper to write file using TFTP.
1092 @param[in] Private Pointer to PxeBc private data.
1093 @param[in] Config Pointer to config data.
1094 @param[in] Filename Pointer to boot file name.
1095 @param[in] Overwrite Indicate whether with overwrite attribute.
1096 @param[in] BlockSize Pointer to required block size.
1097 @param[in] BufferPtr Pointer to buffer.
1098 @param[in, out] BufferSize Pointer to buffer size.
1100 @retval EFI_SUCCESS Successfully wrote the data into a special file.
1101 @retval EFI_DEVICE_ERROR The network device encountered an error during this operation.
1102 @retval other Write data into file failed.
1106 PxeBcTftpWriteFile (
1107 IN PXEBC_PRIVATE_DATA
*Private
,
1110 IN BOOLEAN Overwrite
,
1111 IN UINTN
*BlockSize
,
1112 IN UINT8
*BufferPtr
,
1113 IN OUT UINT64
*BufferSize
1116 if (Private
->PxeBc
.Mode
->UsingIpv6
) {
1117 return PxeBcMtftp6WriteFile (
1119 (EFI_MTFTP6_CONFIG_DATA
*) Config
,
1127 return PxeBcMtftp4WriteFile (
1129 (EFI_MTFTP4_CONFIG_DATA
*) Config
,
1141 This function is a wrapper to get the data (file) from a directory using TFTP.
1143 @param[in] Private Pointer to PxeBc private data.
1144 @param[in] Config Pointer to config data.
1145 @param[in] Filename Pointer to boot file name.
1146 @param[in] BlockSize Pointer to required block size.
1147 @param[in] WindowSize Pointer to required window size.
1148 @param[in] BufferPtr Pointer to buffer.
1149 @param[in, out] BufferSize Pointer to buffer size.
1150 @param[in] DontUseBuffer Indicatse whether to use a receive buffer.
1152 @retval EFI_SUCCES Successfully obtained the data from the file included in the directory.
1153 @retval EFI_DEVICE_ERROR The network device encountered an error during this operation.
1154 @retval Others Operation failed.
1158 PxeBcTftpReadDirectory (
1159 IN PXEBC_PRIVATE_DATA
*Private
,
1162 IN UINTN
*BlockSize
,
1163 IN UINTN
*WindowSize
,
1164 IN UINT8
*BufferPtr
,
1165 IN OUT UINT64
*BufferSize
,
1166 IN BOOLEAN DontUseBuffer
1169 if (Private
->PxeBc
.Mode
->UsingIpv6
) {
1170 return PxeBcMtftp6ReadDirectory (
1172 (EFI_MTFTP6_CONFIG_DATA
*) Config
,
1181 return PxeBcMtftp4ReadDirectory (
1183 (EFI_MTFTP4_CONFIG_DATA
*) Config
,