Mtftp4Impl.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. /** @file
  2. Mtftp4 Implementation.
  3. Mtftp4 Implementation, it supports the following RFCs:
  4. RFC1350 - THE TFTP PROTOCOL (REVISION 2)
  5. RFC2090 - TFTP Multicast Option
  6. RFC2347 - TFTP Option Extension
  7. RFC2348 - TFTP Blocksize Option
  8. RFC2349 - TFTP Timeout Interval and Transfer Size Options
  9. RFC7440 - TFTP Windowsize Option
  10. Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
  11. SPDX-License-Identifier: BSD-2-Clause-Patent
  12. **/
  13. #ifndef __EFI_MTFTP4_IMPL_H__
  14. #define __EFI_MTFTP4_IMPL_H__
  15. #include <Uefi.h>
  16. #include <Protocol/Udp4.h>
  17. #include <Protocol/Mtftp4.h>
  18. #include <Library/DebugLib.h>
  19. #include <Library/BaseMemoryLib.h>
  20. #include <Library/MemoryAllocationLib.h>
  21. #include <Library/UefiBootServicesTableLib.h>
  22. #include <Library/UdpIoLib.h>
  23. #include <Library/PrintLib.h>
  24. extern EFI_MTFTP4_PROTOCOL gMtftp4ProtocolTemplate;
  25. typedef struct _MTFTP4_SERVICE MTFTP4_SERVICE;
  26. typedef struct _MTFTP4_PROTOCOL MTFTP4_PROTOCOL;
  27. #include "Mtftp4Driver.h"
  28. #include "Mtftp4Option.h"
  29. #include "Mtftp4Support.h"
  30. ///
  31. /// Some constant value of Mtftp service.
  32. ///
  33. #define MTFTP4_SERVICE_SIGNATURE SIGNATURE_32 ('T', 'F', 'T', 'P')
  34. #define MTFTP4_PROTOCOL_SIGNATURE SIGNATURE_32 ('t', 'f', 't', 'p')
  35. #define MTFTP4_DEFAULT_SERVER_PORT 69
  36. #define MTFTP4_DEFAULT_TIMEOUT 3
  37. #define MTFTP4_DEFAULT_RETRY 5
  38. #define MTFTP4_DEFAULT_BLKSIZE 512
  39. #define MTFTP4_DEFAULT_WINDOWSIZE 1
  40. #define MTFTP4_TIME_TO_GETMAP 5
  41. #define MTFTP4_STATE_UNCONFIGED 0
  42. #define MTFTP4_STATE_CONFIGED 1
  43. #define MTFTP4_STATE_DESTROY 2
  44. ///
  45. /// Mtftp service block
  46. ///
  47. struct _MTFTP4_SERVICE {
  48. UINT32 Signature;
  49. EFI_SERVICE_BINDING_PROTOCOL ServiceBinding;
  50. UINT16 ChildrenNum;
  51. LIST_ENTRY Children;
  52. EFI_EVENT Timer; ///< Ticking timer for all the MTFTP clients to handle the packet timeout case.
  53. EFI_EVENT TimerNotifyLevel; ///< Ticking timer for all the MTFTP clients to calculate the packet live time.
  54. EFI_EVENT TimerToGetMap;
  55. EFI_HANDLE Controller;
  56. EFI_HANDLE Image;
  57. //
  58. // This UDP child is used to keep the connection between the UDP
  59. // and MTFTP, so MTFTP will be notified when UDP is uninstalled.
  60. //
  61. UDP_IO *ConnectUdp;
  62. };
  63. typedef struct {
  64. EFI_MTFTP4_PACKET **Packet;
  65. UINT32 *PacketLen;
  66. EFI_STATUS Status;
  67. } MTFTP4_GETINFO_STATE;
  68. struct _MTFTP4_PROTOCOL {
  69. UINT32 Signature;
  70. LIST_ENTRY Link;
  71. EFI_MTFTP4_PROTOCOL Mtftp4;
  72. INTN State;
  73. BOOLEAN InDestroy;
  74. MTFTP4_SERVICE *Service;
  75. EFI_HANDLE Handle;
  76. EFI_MTFTP4_CONFIG_DATA Config;
  77. //
  78. // Operation parameters: token and requested options.
  79. //
  80. EFI_MTFTP4_TOKEN *Token;
  81. MTFTP4_OPTION RequestOption;
  82. UINT16 Operation;
  83. //
  84. // Blocks is a list of MTFTP4_BLOCK_RANGE which contains
  85. // holes in the file
  86. //
  87. UINT16 BlkSize;
  88. UINT16 LastBlock;
  89. LIST_ENTRY Blocks;
  90. UINT16 WindowSize;
  91. //
  92. // Record the total received and saved block number.
  93. //
  94. UINT64 TotalBlock;
  95. //
  96. // Record the acked block number.
  97. //
  98. UINT64 AckedBlock;
  99. //
  100. // The server's communication end point: IP and two ports. one for
  101. // initial request, one for its selected port.
  102. //
  103. IP4_ADDR ServerIp;
  104. UINT16 ListeningPort;
  105. UINT16 ConnectedPort;
  106. IP4_ADDR Gateway;
  107. UDP_IO *UnicastPort;
  108. //
  109. // Timeout and retransmit status
  110. //
  111. NET_BUF *LastPacket;
  112. UINT32 PacketToLive;
  113. BOOLEAN HasTimeout;
  114. UINT32 CurRetry;
  115. UINT32 MaxRetry;
  116. UINT32 Timeout;
  117. //
  118. // Parameter used by RRQ's multicast download.
  119. //
  120. IP4_ADDR McastIp;
  121. UINT16 McastPort;
  122. BOOLEAN Master;
  123. UDP_IO *McastUdpPort;
  124. };
  125. typedef struct {
  126. EFI_SERVICE_BINDING_PROTOCOL *ServiceBinding;
  127. UINTN NumberOfChildren;
  128. EFI_HANDLE *ChildHandleBuffer;
  129. } MTFTP4_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT;
  130. /**
  131. Clean up the MTFTP session to get ready for new operation.
  132. @param Instance The MTFTP session to clean up
  133. @param Result The result to return to the caller who initiated
  134. the operation.
  135. **/
  136. VOID
  137. Mtftp4CleanOperation (
  138. IN OUT MTFTP4_PROTOCOL *Instance,
  139. IN EFI_STATUS Result
  140. );
  141. /**
  142. Start the MTFTP session for upload.
  143. It will first init some states, then send the WRQ request packet,
  144. and start receiving the packet.
  145. @param Instance The MTFTP session
  146. @param Operation Redundant parameter, which is always
  147. EFI_MTFTP4_OPCODE_WRQ here.
  148. @retval EFI_SUCCESS The upload process has been started.
  149. @retval Others Failed to start the upload.
  150. **/
  151. EFI_STATUS
  152. Mtftp4WrqStart (
  153. IN MTFTP4_PROTOCOL *Instance,
  154. IN UINT16 Operation
  155. );
  156. /**
  157. Start the MTFTP session to download.
  158. It will first initialize some of the internal states then build and send a RRQ
  159. request packet, at last, it will start receive for the downloading.
  160. @param Instance The Mtftp session
  161. @param Operation The MTFTP opcode, it may be a EFI_MTFTP4_OPCODE_RRQ
  162. or EFI_MTFTP4_OPCODE_DIR.
  163. @retval EFI_SUCCESS The mtftp download session is started.
  164. @retval Others Failed to start downloading.
  165. **/
  166. EFI_STATUS
  167. Mtftp4RrqStart (
  168. IN MTFTP4_PROTOCOL *Instance,
  169. IN UINT16 Operation
  170. );
  171. #define MTFTP4_SERVICE_FROM_THIS(a) \
  172. CR (a, MTFTP4_SERVICE, ServiceBinding, MTFTP4_SERVICE_SIGNATURE)
  173. #define MTFTP4_PROTOCOL_FROM_THIS(a) \
  174. CR (a, MTFTP4_PROTOCOL, Mtftp4, MTFTP4_PROTOCOL_SIGNATURE)
  175. #endif