2 Functions implementation related with Mtftp for UefiPxeBc Driver.
4 Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
10 #include "PxeBcImpl.h"
12 CHAR8
*mMtftpOptions
[PXE_MTFTP_OPTION_MAXIMUM_INDEX
] = {
22 This is a callback function when packets are received or transmitted in Mtftp driver.
24 A callback function that is provided by the caller to intercept
25 the EFI_MTFTP6_OPCODE_DATA or EFI_MTFTP6_OPCODE_DATA8 packets processed in the
26 EFI_MTFTP6_PROTOCOL.ReadFile() function, and alternatively to intercept
27 EFI_MTFTP6_OPCODE_OACK or EFI_MTFTP6_OPCODE_ERROR packets during a call to
28 EFI_MTFTP6_PROTOCOL.ReadFile(), WriteFile() or ReadDirectory().
30 @param[in] This Pointer to EFI_MTFTP6_PROTOCOL.
31 @param[in] Token Pointer to EFI_MTFTP6_TOKEN.
32 @param[in] PacketLen Length of EFI_MTFTP6_PACKET.
33 @param[in] Packet Pointer to EFI_MTFTP6_PACKET to be checked.
35 @retval EFI_SUCCESS The current operation succeeded.
36 @retval EFI_ABORTED Abort the current transfer process.
41 PxeBcMtftp6CheckPacket (
42 IN EFI_MTFTP6_PROTOCOL
*This
,
43 IN EFI_MTFTP6_TOKEN
*Token
,
45 IN EFI_MTFTP6_PACKET
*Packet
48 PXEBC_PRIVATE_DATA
*Private
;
49 EFI_PXE_BASE_CODE_CALLBACK_PROTOCOL
*Callback
;
52 Private
= (PXEBC_PRIVATE_DATA
*) Token
->Context
;
53 Callback
= Private
->PxeBcCallback
;
56 if (Packet
->OpCode
== EFI_MTFTP6_OPCODE_ERROR
) {
58 // Store the tftp error message into mode data and set the received flag.
60 Private
->Mode
.TftpErrorReceived
= TRUE
;
61 Private
->Mode
.TftpError
.ErrorCode
= (UINT8
) Packet
->Error
.ErrorCode
;
63 Private
->Mode
.TftpError
.ErrorString
,
64 PXE_MTFTP_ERROR_STRING_LENGTH
,
65 (CHAR8
*) Packet
->Error
.ErrorMessage
,
66 PXE_MTFTP_ERROR_STRING_LENGTH
- 1
68 Private
->Mode
.TftpError
.ErrorString
[PXE_MTFTP_ERROR_STRING_LENGTH
- 1] = '\0';
71 if (Callback
!= NULL
) {
73 // Callback to user if has when received any tftp packet.
75 Status
= Callback
->Callback (
80 (EFI_PXE_BASE_CODE_PACKET
*) Packet
82 if (Status
!= EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE
) {
84 // User wants to abort current process if not EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE.
89 // User wants to continue current process if EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE.
100 This function is to get the size of a file using Tftp.
102 @param[in] Private Pointer to PxeBc private data.
103 @param[in] Config Pointer to EFI_MTFTP6_CONFIG_DATA.
104 @param[in] Filename Pointer to boot file name.
105 @param[in] BlockSize Pointer to required block size.
106 @param[in] WindowSize Pointer to required window size.
107 @param[in, out] BufferSize Pointer to buffer size.
109 @retval EFI_SUCCESS Sucessfully obtained the size of file.
110 @retval EFI_NOT_FOUND Parse the tftp ptions failed.
111 @retval EFI_DEVICE_ERROR The network device encountered an error during this operation.
112 @retval Others Has not obtained the size of the file.
116 PxeBcMtftp6GetFileSize (
117 IN PXEBC_PRIVATE_DATA
*Private
,
118 IN EFI_MTFTP6_CONFIG_DATA
*Config
,
121 IN UINTN
*WindowSize
,
122 IN OUT UINT64
*BufferSize
125 EFI_MTFTP6_PROTOCOL
*Mtftp6
;
126 EFI_MTFTP6_OPTION ReqOpt
[3];
127 EFI_MTFTP6_PACKET
*Packet
;
128 EFI_MTFTP6_OPTION
*Option
;
130 UINT8 OptBuf
[PXE_MTFTP_OPTBUF_MAXNUM_INDEX
];
136 Status
= EFI_DEVICE_ERROR
;
137 Mtftp6
= Private
->Mtftp6
;
141 OptBufSize
= PXE_MTFTP_OPTBUF_MAXNUM_INDEX
;
143 Config
->InitialServerPort
= PXEBC_BS_DOWNLOAD_PORT
;
145 Status
= Mtftp6
->Configure (Mtftp6
, Config
);
146 if (EFI_ERROR (Status
)) {
151 // Build the required options for get info.
153 ReqOpt
[0].OptionStr
= (UINT8
*) mMtftpOptions
[PXE_MTFTP_OPTION_TSIZE_INDEX
];
154 PxeBcUintnToAscDec (0, OptBuf
, OptBufSize
);
155 ReqOpt
[0].ValueStr
= OptBuf
;
157 if (BlockSize
!= NULL
) {
158 ReqOpt
[OptCnt
].OptionStr
= (UINT8
*) mMtftpOptions
[PXE_MTFTP_OPTION_BLKSIZE_INDEX
];
159 ReqOpt
[OptCnt
].ValueStr
= (UINT8
*) (ReqOpt
[OptCnt
-1].ValueStr
+ AsciiStrLen ((CHAR8
*) ReqOpt
[OptCnt
-1].ValueStr
) + 1);
160 OptBufSize
-= (AsciiStrLen ((CHAR8
*) ReqOpt
[OptCnt
-1].ValueStr
) + 1);
161 PxeBcUintnToAscDec (*BlockSize
, ReqOpt
[OptCnt
].ValueStr
, OptBufSize
);
165 if (WindowSize
!= NULL
) {
166 ReqOpt
[OptCnt
].OptionStr
= (UINT8
*) mMtftpOptions
[PXE_MTFTP_OPTION_WINDOWSIZE_INDEX
];
167 ReqOpt
[OptCnt
].ValueStr
= (UINT8
*) (ReqOpt
[OptCnt
-1].ValueStr
+ AsciiStrLen ((CHAR8
*) ReqOpt
[OptCnt
-1].ValueStr
) + 1);
168 OptBufSize
-= (AsciiStrLen ((CHAR8
*) ReqOpt
[OptCnt
-1].ValueStr
) + 1);
169 PxeBcUintnToAscDec (*WindowSize
, ReqOpt
[OptCnt
].ValueStr
, OptBufSize
);
173 Status
= Mtftp6
->GetInfo (
183 if (EFI_ERROR (Status
)) {
184 if (Status
== EFI_TFTP_ERROR
) {
186 // Store the tftp error message into mode data and set the received flag.
188 Private
->Mode
.TftpErrorReceived
= TRUE
;
189 Private
->Mode
.TftpError
.ErrorCode
= (UINT8
) Packet
->Error
.ErrorCode
;
191 Private
->Mode
.TftpError
.ErrorString
,
192 PXE_MTFTP_ERROR_STRING_LENGTH
,
193 (CHAR8
*) Packet
->Error
.ErrorMessage
,
194 PXE_MTFTP_ERROR_STRING_LENGTH
- 1
196 Private
->Mode
.TftpError
.ErrorString
[PXE_MTFTP_ERROR_STRING_LENGTH
- 1] = '\0';
202 // Parse the options in the reply packet.
205 Status
= Mtftp6
->ParseOptions (
212 if (EFI_ERROR (Status
)) {
217 // Parse out the value of "tsize" option.
219 Status
= EFI_NOT_FOUND
;
220 while (OptCnt
!= 0) {
221 if (AsciiStrnCmp ((CHAR8
*) Option
[OptCnt
- 1].OptionStr
, "tsize", 5) == 0) {
222 *BufferSize
= AsciiStrDecimalToUint64 ((CHAR8
*) (Option
[OptCnt
- 1].ValueStr
));
223 Status
= EFI_SUCCESS
;
230 if (Packet
!= NULL
) {
233 Mtftp6
->Configure (Mtftp6
, NULL
);
240 This function is to get data of a file using Tftp.
242 @param[in] Private Pointer to PxeBc private data.
243 @param[in] Config Pointer to EFI_MTFTP6_CONFIG_DATA.
244 @param[in] Filename Pointer to boot file name.
245 @param[in] BlockSize Pointer to required block size.
246 @param[in] WindowSize Pointer to required window size.
247 @param[in] BufferPtr Pointer to buffer.
248 @param[in, out] BufferSize Pointer to buffer size.
249 @param[in] DontUseBuffer Indicates whether with a receive buffer.
251 @retval EFI_SUCCESS Successfully read the data from the special file.
252 @retval EFI_DEVICE_ERROR The network device encountered an error during this operation.
253 @retval Others Read data from file failed.
257 PxeBcMtftp6ReadFile (
258 IN PXEBC_PRIVATE_DATA
*Private
,
259 IN EFI_MTFTP6_CONFIG_DATA
*Config
,
262 IN UINTN
*WindowSize
,
264 IN OUT UINT64
*BufferSize
,
265 IN BOOLEAN DontUseBuffer
268 EFI_MTFTP6_PROTOCOL
*Mtftp6
;
269 EFI_MTFTP6_TOKEN Token
;
270 EFI_MTFTP6_OPTION ReqOpt
[2];
272 UINT8 BlksizeBuf
[10];
273 UINT8 WindowsizeBuf
[10];
276 Status
= EFI_DEVICE_ERROR
;
277 Mtftp6
= Private
->Mtftp6
;
279 Config
->InitialServerPort
= PXEBC_BS_DOWNLOAD_PORT
;
281 Status
= Mtftp6
->Configure (Mtftp6
, Config
);
282 if (EFI_ERROR (Status
)) {
286 if (BlockSize
!= NULL
) {
287 ReqOpt
[OptCnt
].OptionStr
= (UINT8
*) mMtftpOptions
[PXE_MTFTP_OPTION_BLKSIZE_INDEX
];
288 ReqOpt
[OptCnt
].ValueStr
= BlksizeBuf
;
289 PxeBcUintnToAscDec (*BlockSize
, ReqOpt
[OptCnt
].ValueStr
, sizeof (BlksizeBuf
));
293 if (WindowSize
!= NULL
) {
294 ReqOpt
[OptCnt
].OptionStr
= (UINT8
*) mMtftpOptions
[PXE_MTFTP_OPTION_WINDOWSIZE_INDEX
];
295 ReqOpt
[OptCnt
].ValueStr
= WindowsizeBuf
;
296 PxeBcUintnToAscDec (*WindowSize
, ReqOpt
[OptCnt
].ValueStr
, sizeof (WindowsizeBuf
));
302 Token
.OverrideData
= NULL
;
303 Token
.Filename
= Filename
;
304 Token
.ModeStr
= NULL
;
305 Token
.OptionCount
= OptCnt
;
306 Token
.OptionList
= ReqOpt
;
307 Token
.Context
= Private
;
310 Token
.BufferSize
= 0;
313 Token
.BufferSize
= *BufferSize
;
314 Token
.Buffer
= BufferPtr
;
317 Token
.CheckPacket
= PxeBcMtftp6CheckPacket
;
318 Token
.TimeoutCallback
= NULL
;
319 Token
.PacketNeeded
= NULL
;
321 Status
= Mtftp6
->ReadFile (Mtftp6
, &Token
);
323 // Get the real size of received buffer.
325 *BufferSize
= Token
.BufferSize
;
327 Mtftp6
->Configure (Mtftp6
, NULL
);
334 This function is used to write the data of a file using Tftp.
336 @param[in] Private Pointer to PxeBc private data.
337 @param[in] Config Pointer to EFI_MTFTP6_CONFIG_DATA.
338 @param[in] Filename Pointer to boot file name.
339 @param[in] Overwrite Indicate whether with overwrite attribute.
340 @param[in] BlockSize Pointer to required block size.
341 @param[in] BufferPtr Pointer to buffer.
342 @param[in, out] BufferSize Pointer to buffer size.
344 @retval EFI_SUCCESS Successfully wrote the data into a special file.
345 @retval EFI_DEVICE_ERROR The network device encountered an error during this operation.
346 @retval other Write data into file failed.
350 PxeBcMtftp6WriteFile (
351 IN PXEBC_PRIVATE_DATA
*Private
,
352 IN EFI_MTFTP6_CONFIG_DATA
*Config
,
354 IN BOOLEAN Overwrite
,
357 IN OUT UINT64
*BufferSize
360 EFI_MTFTP6_PROTOCOL
*Mtftp6
;
361 EFI_MTFTP6_TOKEN Token
;
362 EFI_MTFTP6_OPTION ReqOpt
[1];
367 Status
= EFI_DEVICE_ERROR
;
368 Mtftp6
= Private
->Mtftp6
;
370 Config
->InitialServerPort
= PXEBC_BS_DOWNLOAD_PORT
;
372 Status
= Mtftp6
->Configure (Mtftp6
, Config
);
373 if (EFI_ERROR (Status
)) {
377 if (BlockSize
!= NULL
) {
378 ReqOpt
[0].OptionStr
= (UINT8
*) mMtftpOptions
[PXE_MTFTP_OPTION_BLKSIZE_INDEX
];
379 ReqOpt
[0].ValueStr
= OptBuf
;
380 PxeBcUintnToAscDec (*BlockSize
, ReqOpt
[0].ValueStr
, PXE_MTFTP_OPTBUF_MAXNUM_INDEX
);
385 Token
.OverrideData
= NULL
;
386 Token
.Filename
= Filename
;
387 Token
.ModeStr
= NULL
;
388 Token
.OptionCount
= OptCnt
;
389 Token
.OptionList
= ReqOpt
;
390 Token
.BufferSize
= *BufferSize
;
391 Token
.Buffer
= BufferPtr
;
392 Token
.CheckPacket
= PxeBcMtftp6CheckPacket
;
393 Token
.TimeoutCallback
= NULL
;
394 Token
.PacketNeeded
= NULL
;
396 Status
= Mtftp6
->WriteFile (Mtftp6
, &Token
);
398 // Get the real size of transmitted buffer.
400 *BufferSize
= Token
.BufferSize
;
402 Mtftp6
->Configure (Mtftp6
, NULL
);
409 This function is to read the data (file) from a directory using Tftp.
411 @param[in] Private Pointer to PxeBc private data.
412 @param[in] Config Pointer to EFI_MTFTP6_CONFIG_DATA.
413 @param[in] Filename Pointer to boot file name.
414 @param[in] BlockSize Pointer to required block size.
415 @param[in] WindowSize Pointer to required window size.
416 @param[in] BufferPtr Pointer to buffer.
417 @param[in, out] BufferSize Pointer to buffer size.
418 @param[in] DontUseBuffer Indicates whether to use a receive buffer.
420 @retval EFI_SUCCESS Successfully obtained the data from the file included in directory.
421 @retval EFI_DEVICE_ERROR The network device encountered an error during this operation.
422 @retval Others Operation failed.
426 PxeBcMtftp6ReadDirectory (
427 IN PXEBC_PRIVATE_DATA
*Private
,
428 IN EFI_MTFTP6_CONFIG_DATA
*Config
,
431 IN UINTN
*WindowSize
,
433 IN OUT UINT64
*BufferSize
,
434 IN BOOLEAN DontUseBuffer
437 EFI_MTFTP6_PROTOCOL
*Mtftp6
;
438 EFI_MTFTP6_TOKEN Token
;
439 EFI_MTFTP6_OPTION ReqOpt
[2];
441 UINT8 BlksizeBuf
[10];
442 UINT8 WindowsizeBuf
[10];
445 Status
= EFI_DEVICE_ERROR
;
446 Mtftp6
= Private
->Mtftp6
;
448 Config
->InitialServerPort
= PXEBC_BS_DOWNLOAD_PORT
;
450 Status
= Mtftp6
->Configure (Mtftp6
, Config
);
451 if (EFI_ERROR (Status
)) {
455 if (BlockSize
!= NULL
) {
456 ReqOpt
[OptCnt
].OptionStr
= (UINT8
*) mMtftpOptions
[PXE_MTFTP_OPTION_BLKSIZE_INDEX
];
457 ReqOpt
[OptCnt
].ValueStr
= BlksizeBuf
;
458 PxeBcUintnToAscDec (*BlockSize
, ReqOpt
[OptCnt
].ValueStr
, sizeof (BlksizeBuf
));
462 if (WindowSize
!= NULL
) {
463 ReqOpt
[OptCnt
].OptionStr
= (UINT8
*) mMtftpOptions
[PXE_MTFTP_OPTION_WINDOWSIZE_INDEX
];
464 ReqOpt
[OptCnt
].ValueStr
= WindowsizeBuf
;
465 PxeBcUintnToAscDec (*WindowSize
, ReqOpt
[OptCnt
].ValueStr
, sizeof (WindowsizeBuf
));
470 Token
.OverrideData
= NULL
;
471 Token
.Filename
= Filename
;
472 Token
.ModeStr
= NULL
;
473 Token
.OptionCount
= OptCnt
;
474 Token
.OptionList
= ReqOpt
;
475 Token
.Context
= Private
;
478 Token
.BufferSize
= 0;
481 Token
.BufferSize
= *BufferSize
;
482 Token
.Buffer
= BufferPtr
;
485 Token
.CheckPacket
= PxeBcMtftp6CheckPacket
;
486 Token
.TimeoutCallback
= NULL
;
487 Token
.PacketNeeded
= NULL
;
489 Status
= Mtftp6
->ReadDirectory (Mtftp6
, &Token
);
491 // Get the real size of received buffer.
493 *BufferSize
= Token
.BufferSize
;
495 Mtftp6
->Configure (Mtftp6
, NULL
);
502 This is a callback function when packets are received or transmitted in Mtftp driver.
504 A callback function that is provided by the caller to intercept
505 the EFI_MTFTP6_OPCODE_DATA or EFI_MTFTP4_OPCODE_DATA8 packets processed in the
506 EFI_MTFTP4_PROTOCOL.ReadFile() function, and alternatively to intercept
507 EFI_MTFTP4_OPCODE_OACK or EFI_MTFTP4_OPCODE_ERROR packets during a call to
508 EFI_MTFTP4_PROTOCOL.ReadFile(), WriteFile() or ReadDirectory().
510 @param[in] This Pointer to EFI_MTFTP4_PROTOCOL.
511 @param[in] Token Pointer to EFI_MTFTP4_TOKEN.
512 @param[in] PacketLen Length of EFI_MTFTP4_PACKET.
513 @param[in] Packet Pointer to EFI_MTFTP4_PACKET to be checked.
515 @retval EFI_SUCCESS The current operation succeeeded.
516 @retval EFI_ABORTED Abort the current transfer process.
521 PxeBcMtftp4CheckPacket (
522 IN EFI_MTFTP4_PROTOCOL
*This
,
523 IN EFI_MTFTP4_TOKEN
*Token
,
525 IN EFI_MTFTP4_PACKET
*Packet
528 PXEBC_PRIVATE_DATA
*Private
;
529 EFI_PXE_BASE_CODE_CALLBACK_PROTOCOL
*Callback
;
532 Private
= (PXEBC_PRIVATE_DATA
*) Token
->Context
;
533 Callback
= Private
->PxeBcCallback
;
534 Status
= EFI_SUCCESS
;
536 if (Packet
->OpCode
== EFI_MTFTP4_OPCODE_ERROR
) {
538 // Store the tftp error message into mode data and set the received flag.
540 Private
->Mode
.TftpErrorReceived
= TRUE
;
541 Private
->Mode
.TftpError
.ErrorCode
= (UINT8
) Packet
->Error
.ErrorCode
;
543 Private
->Mode
.TftpError
.ErrorString
,
544 PXE_MTFTP_ERROR_STRING_LENGTH
,
545 (CHAR8
*) Packet
->Error
.ErrorMessage
,
546 PXE_MTFTP_ERROR_STRING_LENGTH
- 1
548 Private
->Mode
.TftpError
.ErrorString
[PXE_MTFTP_ERROR_STRING_LENGTH
- 1] = '\0';
551 if (Callback
!= NULL
) {
553 // Callback to user if has when received any tftp packet.
555 Status
= Callback
->Callback (
560 (EFI_PXE_BASE_CODE_PACKET
*) Packet
562 if (Status
!= EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE
) {
564 // User wants to abort current process if not EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE.
566 Status
= EFI_ABORTED
;
569 // User wants to continue current process if EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE.
571 Status
= EFI_SUCCESS
;
580 This function is to get size of a file using Tftp.
582 @param[in] Private Pointer to PxeBc private data.
583 @param[in] Config Pointer to EFI_MTFTP4_CONFIG_DATA.
584 @param[in] Filename Pointer to boot file name.
585 @param[in] BlockSize Pointer to required block size.
586 @param[in] WindowSize Pointer to required window size.
587 @param[in, out] BufferSize Pointer to buffer size.
589 @retval EFI_SUCCESS Successfully obtained the size of file.
590 @retval EFI_NOT_FOUND Parse the tftp options failed.
591 @retval EFI_DEVICE_ERROR The network device encountered an error during this operation.
592 @retval Others Did not obtain the size of the file.
596 PxeBcMtftp4GetFileSize (
597 IN PXEBC_PRIVATE_DATA
*Private
,
598 IN EFI_MTFTP4_CONFIG_DATA
*Config
,
601 IN UINTN
*WindowSize
,
602 IN OUT UINT64
*BufferSize
605 EFI_MTFTP4_PROTOCOL
*Mtftp4
;
606 EFI_MTFTP4_OPTION ReqOpt
[3];
607 EFI_MTFTP4_PACKET
*Packet
;
608 EFI_MTFTP4_OPTION
*Option
;
610 UINT8 OptBuf
[PXE_MTFTP_OPTBUF_MAXNUM_INDEX
];
616 Status
= EFI_DEVICE_ERROR
;
617 Mtftp4
= Private
->Mtftp4
;
621 OptBufSize
= PXE_MTFTP_OPTBUF_MAXNUM_INDEX
;
623 Config
->InitialServerPort
= PXEBC_BS_DOWNLOAD_PORT
;
625 Status
= Mtftp4
->Configure (Mtftp4
, Config
);
626 if (EFI_ERROR (Status
)) {
631 // Build the required options for get info.
633 ReqOpt
[0].OptionStr
= (UINT8
*) mMtftpOptions
[PXE_MTFTP_OPTION_TSIZE_INDEX
];
634 PxeBcUintnToAscDec (0, OptBuf
, OptBufSize
);
635 ReqOpt
[0].ValueStr
= OptBuf
;
637 if (BlockSize
!= NULL
) {
638 ReqOpt
[OptCnt
].OptionStr
= (UINT8
*) mMtftpOptions
[PXE_MTFTP_OPTION_BLKSIZE_INDEX
];
639 ReqOpt
[OptCnt
].ValueStr
= (UINT8
*) (ReqOpt
[OptCnt
-1].ValueStr
+ AsciiStrLen ((CHAR8
*) ReqOpt
[OptCnt
-1].ValueStr
) + 1);
640 OptBufSize
-= (AsciiStrLen ((CHAR8
*) ReqOpt
[OptCnt
-1].ValueStr
) + 1);
641 PxeBcUintnToAscDec (*BlockSize
, ReqOpt
[OptCnt
].ValueStr
, OptBufSize
);
645 if (WindowSize
!= NULL
) {
646 ReqOpt
[OptCnt
].OptionStr
= (UINT8
*) mMtftpOptions
[PXE_MTFTP_OPTION_WINDOWSIZE_INDEX
];
647 ReqOpt
[OptCnt
].ValueStr
= (UINT8
*) (ReqOpt
[OptCnt
-1].ValueStr
+ AsciiStrLen ((CHAR8
*) ReqOpt
[OptCnt
-1].ValueStr
) + 1);
648 OptBufSize
-= (AsciiStrLen ((CHAR8
*) ReqOpt
[OptCnt
-1].ValueStr
) + 1);
649 PxeBcUintnToAscDec (*WindowSize
, ReqOpt
[OptCnt
].ValueStr
, OptBufSize
);
653 Status
= Mtftp4
->GetInfo (
663 if (EFI_ERROR (Status
)) {
664 if (Status
== EFI_TFTP_ERROR
) {
666 // Store the tftp error message into mode data and set the received flag.
668 Private
->Mode
.TftpErrorReceived
= TRUE
;
669 Private
->Mode
.TftpError
.ErrorCode
= (UINT8
) Packet
->Error
.ErrorCode
;
671 Private
->Mode
.TftpError
.ErrorString
,
672 PXE_MTFTP_ERROR_STRING_LENGTH
,
673 (CHAR8
*) Packet
->Error
.ErrorMessage
,
674 PXE_MTFTP_ERROR_STRING_LENGTH
- 1
676 Private
->Mode
.TftpError
.ErrorString
[PXE_MTFTP_ERROR_STRING_LENGTH
- 1] = '\0';
682 // Parse the options in the reply packet.
685 Status
= Mtftp4
->ParseOptions (
692 if (EFI_ERROR (Status
)) {
697 // Parse out the value of "tsize" option.
699 Status
= EFI_NOT_FOUND
;
700 while (OptCnt
!= 0) {
701 if (AsciiStrnCmp ((CHAR8
*) Option
[OptCnt
- 1].OptionStr
, "tsize", 5) == 0) {
702 *BufferSize
= AsciiStrDecimalToUint64 ((CHAR8
*) (Option
[OptCnt
- 1].ValueStr
));
703 Status
= EFI_SUCCESS
;
710 if (Packet
!= NULL
) {
713 Mtftp4
->Configure (Mtftp4
, NULL
);
720 This function is to read the data of a file using Tftp.
722 @param[in] Private Pointer to PxeBc private data.
723 @param[in] Config Pointer to EFI_MTFTP4_CONFIG_DATA.
724 @param[in] Filename Pointer to boot file name.
725 @param[in] BlockSize Pointer to required block size.
726 @param[in] WindowSize Pointer to required window size.
727 @param[in] BufferPtr Pointer to buffer.
728 @param[in, out] BufferSize Pointer to buffer size.
729 @param[in] DontUseBuffer Indicates whether to use a receive buffer.
731 @retval EFI_SUCCESS Successfully read the data from the special file.
732 @retval EFI_DEVICE_ERROR The network device encountered an error during this operation.
733 @retval Others Read data from file failed.
737 PxeBcMtftp4ReadFile (
738 IN PXEBC_PRIVATE_DATA
*Private
,
739 IN EFI_MTFTP4_CONFIG_DATA
*Config
,
742 IN UINTN
*WindowSize
,
744 IN OUT UINT64
*BufferSize
,
745 IN BOOLEAN DontUseBuffer
748 EFI_MTFTP4_PROTOCOL
*Mtftp4
;
749 EFI_MTFTP4_TOKEN Token
;
750 EFI_MTFTP4_OPTION ReqOpt
[2];
752 UINT8 BlksizeBuf
[10];
753 UINT8 WindowsizeBuf
[10];
756 Status
= EFI_DEVICE_ERROR
;
757 Mtftp4
= Private
->Mtftp4
;
759 Config
->InitialServerPort
= PXEBC_BS_DOWNLOAD_PORT
;
761 Status
= Mtftp4
->Configure (Mtftp4
, Config
);
762 if (EFI_ERROR (Status
)) {
766 if (BlockSize
!= NULL
) {
767 ReqOpt
[OptCnt
].OptionStr
= (UINT8
*) mMtftpOptions
[PXE_MTFTP_OPTION_BLKSIZE_INDEX
];
768 ReqOpt
[OptCnt
].ValueStr
= BlksizeBuf
;
769 PxeBcUintnToAscDec (*BlockSize
, ReqOpt
[OptCnt
].ValueStr
, sizeof (BlksizeBuf
));
773 if (WindowSize
!= NULL
) {
774 ReqOpt
[OptCnt
].OptionStr
= (UINT8
*) mMtftpOptions
[PXE_MTFTP_OPTION_WINDOWSIZE_INDEX
];
775 ReqOpt
[OptCnt
].ValueStr
= WindowsizeBuf
;
776 PxeBcUintnToAscDec (*WindowSize
, ReqOpt
[OptCnt
].ValueStr
, sizeof (WindowsizeBuf
));
781 Token
.OverrideData
= NULL
;
782 Token
.Filename
= Filename
;
783 Token
.ModeStr
= NULL
;
784 Token
.OptionCount
= OptCnt
;
785 Token
.OptionList
= ReqOpt
;
786 Token
.Context
= Private
;
789 Token
.BufferSize
= 0;
792 Token
.BufferSize
= *BufferSize
;
793 Token
.Buffer
= BufferPtr
;
796 Token
.CheckPacket
= PxeBcMtftp4CheckPacket
;
797 Token
.TimeoutCallback
= NULL
;
798 Token
.PacketNeeded
= NULL
;
800 Status
= Mtftp4
->ReadFile (Mtftp4
, &Token
);
802 // Get the real size of received buffer.
804 *BufferSize
= Token
.BufferSize
;
806 Mtftp4
->Configure (Mtftp4
, NULL
);
813 This function is to write the data of a file using Tftp.
815 @param[in] Private Pointer to PxeBc private data.
816 @param[in] Config Pointer to EFI_MTFTP4_CONFIG_DATA.
817 @param[in] Filename Pointer to boot file name.
818 @param[in] Overwrite Indicates whether to use the overwrite attribute.
819 @param[in] BlockSize Pointer to required block size.
820 @param[in] BufferPtr Pointer to buffer.
821 @param[in, out] BufferSize Pointer to buffer size.
823 @retval EFI_SUCCESS Successfully write the data into the special file.
824 @retval EFI_DEVICE_ERROR The network device encountered an error during this operation.
825 @retval other Write data into file failed.
829 PxeBcMtftp4WriteFile (
830 IN PXEBC_PRIVATE_DATA
*Private
,
831 IN EFI_MTFTP4_CONFIG_DATA
*Config
,
833 IN BOOLEAN Overwrite
,
836 IN OUT UINT64
*BufferSize
839 EFI_MTFTP4_PROTOCOL
*Mtftp4
;
840 EFI_MTFTP4_TOKEN Token
;
841 EFI_MTFTP4_OPTION ReqOpt
[1];
846 Status
= EFI_DEVICE_ERROR
;
847 Mtftp4
= Private
->Mtftp4
;
849 Config
->InitialServerPort
= PXEBC_BS_DOWNLOAD_PORT
;
851 Status
= Mtftp4
->Configure (Mtftp4
, Config
);
852 if (EFI_ERROR (Status
)) {
856 if (BlockSize
!= NULL
) {
857 ReqOpt
[0].OptionStr
= (UINT8
*) mMtftpOptions
[PXE_MTFTP_OPTION_BLKSIZE_INDEX
];
858 ReqOpt
[0].ValueStr
= OptBuf
;
859 PxeBcUintnToAscDec (*BlockSize
, ReqOpt
[0].ValueStr
, PXE_MTFTP_OPTBUF_MAXNUM_INDEX
);
864 Token
.OverrideData
= NULL
;
865 Token
.Filename
= Filename
;
866 Token
.ModeStr
= NULL
;
867 Token
.OptionCount
= OptCnt
;
868 Token
.OptionList
= ReqOpt
;
869 Token
.BufferSize
= *BufferSize
;
870 Token
.Buffer
= BufferPtr
;
871 Token
.CheckPacket
= PxeBcMtftp4CheckPacket
;
872 Token
.TimeoutCallback
= NULL
;
873 Token
.PacketNeeded
= NULL
;
875 Status
= Mtftp4
->WriteFile (Mtftp4
, &Token
);
877 // Get the real size of transmitted buffer.
879 *BufferSize
= Token
.BufferSize
;
881 Mtftp4
->Configure (Mtftp4
, NULL
);
888 This function is to get data (file) from a directory using Tftp.
890 @param[in] Private Pointer to PxeBc private data.
891 @param[in] Config Pointer to EFI_MTFTP4_CONFIG_DATA.
892 @param[in] Filename Pointer to boot file name.
893 @param[in] BlockSize Pointer to required block size.
894 @param[in] WindowSize Pointer to required window size.
895 @param[in] BufferPtr Pointer to buffer.
896 @param[in, out] BufferSize Pointer to buffer size.
897 @param[in] DontUseBuffer Indicates whether to use a receive buffer.
899 @retval EFI_SUCCES Successfully obtained the data from the file included in the directory.
900 @retval EFI_DEVICE_ERROR The network device encountered an error during this operation.
901 @retval Others Operation failed.
905 PxeBcMtftp4ReadDirectory (
906 IN PXEBC_PRIVATE_DATA
*Private
,
907 IN EFI_MTFTP4_CONFIG_DATA
*Config
,
910 IN UINTN
*WindowSize
,
912 IN OUT UINT64
*BufferSize
,
913 IN BOOLEAN DontUseBuffer
916 EFI_MTFTP4_PROTOCOL
*Mtftp4
;
917 EFI_MTFTP4_TOKEN Token
;
918 EFI_MTFTP4_OPTION ReqOpt
[2];
920 UINT8 BlksizeBuf
[10];
921 UINT8 WindowsizeBuf
[10];
924 Status
= EFI_DEVICE_ERROR
;
925 Mtftp4
= Private
->Mtftp4
;
927 Config
->InitialServerPort
= PXEBC_BS_DOWNLOAD_PORT
;
929 Status
= Mtftp4
->Configure (Mtftp4
, Config
);
930 if (EFI_ERROR (Status
)) {
934 if (BlockSize
!= NULL
) {
935 ReqOpt
[OptCnt
].OptionStr
= (UINT8
*) mMtftpOptions
[PXE_MTFTP_OPTION_BLKSIZE_INDEX
];
936 ReqOpt
[OptCnt
].ValueStr
= BlksizeBuf
;
937 PxeBcUintnToAscDec (*BlockSize
, ReqOpt
[OptCnt
].ValueStr
, sizeof (BlksizeBuf
));
941 if (WindowSize
!= NULL
) {
942 ReqOpt
[OptCnt
].OptionStr
= (UINT8
*) mMtftpOptions
[PXE_MTFTP_OPTION_WINDOWSIZE_INDEX
];
943 ReqOpt
[OptCnt
].ValueStr
= WindowsizeBuf
;
944 PxeBcUintnToAscDec (*WindowSize
, ReqOpt
[OptCnt
].ValueStr
, sizeof (WindowsizeBuf
));
949 Token
.OverrideData
= NULL
;
950 Token
.Filename
= Filename
;
951 Token
.ModeStr
= NULL
;
952 Token
.OptionCount
= OptCnt
;
953 Token
.OptionList
= ReqOpt
;
954 Token
.Context
= Private
;
957 Token
.BufferSize
= 0;
960 Token
.BufferSize
= *BufferSize
;
961 Token
.Buffer
= BufferPtr
;
964 Token
.CheckPacket
= PxeBcMtftp4CheckPacket
;
965 Token
.TimeoutCallback
= NULL
;
966 Token
.PacketNeeded
= NULL
;
968 Status
= Mtftp4
->ReadDirectory (Mtftp4
, &Token
);
970 // Get the real size of received buffer.
972 *BufferSize
= Token
.BufferSize
;
974 Mtftp4
->Configure (Mtftp4
, NULL
);
981 This function is wrapper to get the file size using TFTP.
983 @param[in] Private Pointer to PxeBc private data.
984 @param[in] Config Pointer to configure data.
985 @param[in] Filename Pointer to boot file name.
986 @param[in] BlockSize Pointer to required block size.
987 @param[in] WindowSize Pointer to required window size.
988 @param[in, out] BufferSize Pointer to buffer size.
990 @retval EFI_SUCCESS Successfully obtained the size of file.
991 @retval EFI_NOT_FOUND Parse the tftp options failed.
992 @retval EFI_DEVICE_ERROR The network device encountered an error during this operation.
993 @retval Others Did not obtain the size of the file.
997 PxeBcTftpGetFileSize (
998 IN PXEBC_PRIVATE_DATA
*Private
,
1001 IN UINTN
*BlockSize
,
1002 IN UINTN
*WindowSize
,
1003 IN OUT UINT64
*BufferSize
1006 if (Private
->PxeBc
.Mode
->UsingIpv6
) {
1007 return PxeBcMtftp6GetFileSize (
1009 (EFI_MTFTP6_CONFIG_DATA
*) Config
,
1016 return PxeBcMtftp4GetFileSize (
1018 (EFI_MTFTP4_CONFIG_DATA
*) Config
,
1029 This function is a wrapper to get file using TFTP.
1031 @param[in] Private Pointer to PxeBc private data.
1032 @param[in] Config Pointer to config data.
1033 @param[in] Filename Pointer to boot file name.
1034 @param[in] BlockSize Pointer to required block size.
1035 @param[in] WindowSize Pointer to required window size.
1036 @param[in] BufferPtr Pointer to buffer.
1037 @param[in, out] BufferSize Pointer to buffer size.
1038 @param[in] DontUseBuffer Indicates whether to use a receive buffer.
1040 @retval EFI_SUCCESS Sucessfully read the data from the special file.
1041 @retval EFI_DEVICE_ERROR The network device encountered an error during this operation.
1042 @retval Others Read data from file failed.
1047 IN PXEBC_PRIVATE_DATA
*Private
,
1050 IN UINTN
*BlockSize
,
1051 IN UINTN
*WindowSize
,
1052 IN UINT8
*BufferPtr
,
1053 IN OUT UINT64
*BufferSize
,
1054 IN BOOLEAN DontUseBuffer
1057 if (Private
->PxeBc
.Mode
->UsingIpv6
) {
1058 return PxeBcMtftp6ReadFile (
1060 (EFI_MTFTP6_CONFIG_DATA
*) Config
,
1069 return PxeBcMtftp4ReadFile (
1071 (EFI_MTFTP4_CONFIG_DATA
*) Config
,
1084 This function is a wrapper to write file using TFTP.
1086 @param[in] Private Pointer to PxeBc private data.
1087 @param[in] Config Pointer to config data.
1088 @param[in] Filename Pointer to boot file name.
1089 @param[in] Overwrite Indicate whether with overwrite attribute.
1090 @param[in] BlockSize Pointer to required block size.
1091 @param[in] BufferPtr Pointer to buffer.
1092 @param[in, out] BufferSize Pointer to buffer size.
1094 @retval EFI_SUCCESS Successfully wrote the data into a special file.
1095 @retval EFI_DEVICE_ERROR The network device encountered an error during this operation.
1096 @retval other Write data into file failed.
1100 PxeBcTftpWriteFile (
1101 IN PXEBC_PRIVATE_DATA
*Private
,
1104 IN BOOLEAN Overwrite
,
1105 IN UINTN
*BlockSize
,
1106 IN UINT8
*BufferPtr
,
1107 IN OUT UINT64
*BufferSize
1110 if (Private
->PxeBc
.Mode
->UsingIpv6
) {
1111 return PxeBcMtftp6WriteFile (
1113 (EFI_MTFTP6_CONFIG_DATA
*) Config
,
1121 return PxeBcMtftp4WriteFile (
1123 (EFI_MTFTP4_CONFIG_DATA
*) Config
,
1135 This function is a wrapper to get the data (file) from a directory using TFTP.
1137 @param[in] Private Pointer to PxeBc private data.
1138 @param[in] Config Pointer to config data.
1139 @param[in] Filename Pointer to boot file name.
1140 @param[in] BlockSize Pointer to required block size.
1141 @param[in] WindowSize Pointer to required window size.
1142 @param[in] BufferPtr Pointer to buffer.
1143 @param[in, out] BufferSize Pointer to buffer size.
1144 @param[in] DontUseBuffer Indicatse whether to use a receive buffer.
1146 @retval EFI_SUCCES Successfully obtained the data from the file included in the directory.
1147 @retval EFI_DEVICE_ERROR The network device encountered an error during this operation.
1148 @retval Others Operation failed.
1152 PxeBcTftpReadDirectory (
1153 IN PXEBC_PRIVATE_DATA
*Private
,
1156 IN UINTN
*BlockSize
,
1157 IN UINTN
*WindowSize
,
1158 IN UINT8
*BufferPtr
,
1159 IN OUT UINT64
*BufferSize
,
1160 IN BOOLEAN DontUseBuffer
1163 if (Private
->PxeBc
.Mode
->UsingIpv6
) {
1164 return PxeBcMtftp6ReadDirectory (
1166 (EFI_MTFTP6_CONFIG_DATA
*) Config
,
1175 return PxeBcMtftp4ReadDirectory (
1177 (EFI_MTFTP4_CONFIG_DATA
*) Config
,