Mtftp4Support.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. /** @file
  2. Support routines for MTFTP.
  3. Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. **/
  6. #ifndef __EFI_MTFTP4_SUPPORT_H__
  7. #define __EFI_MTFTP4_SUPPORT_H__
  8. //
  9. // The structure representing a range of block numbers, [Start, End].
  10. // It is used to remember the holes in the MTFTP block space. If all
  11. // the holes are filled in, then the download or upload has completed.
  12. //
  13. typedef struct {
  14. LIST_ENTRY Link;
  15. INTN Start;
  16. INTN End;
  17. INTN Round;
  18. INTN Bound;
  19. } MTFTP4_BLOCK_RANGE;
  20. /**
  21. Initialize the block range for either RRQ or WRQ.
  22. RRQ and WRQ have different requirements for Start and End.
  23. For example, during start up, WRQ initializes its whole valid block range
  24. to [0, 0xffff]. This is because the server will send us a ACK0 to inform us
  25. to start the upload. When the client received ACK0, it will remove 0 from the
  26. range, get the next block number, which is 1, then upload the BLOCK1. For RRQ
  27. without option negotiation, the server will directly send us the BLOCK1 in
  28. response to the client's RRQ. When received BLOCK1, the client will remove
  29. it from the block range and send an ACK. It also works if there is option
  30. negotiation.
  31. @param Head The block range head to initialize
  32. @param Start The Start block number.
  33. @param End The last block number.
  34. @retval EFI_OUT_OF_RESOURCES Failed to allocate memory for initial block range
  35. @retval EFI_SUCCESS The initial block range is created.
  36. **/
  37. EFI_STATUS
  38. Mtftp4InitBlockRange (
  39. IN LIST_ENTRY *Head,
  40. IN UINT16 Start,
  41. IN UINT16 End
  42. );
  43. /**
  44. Get the first valid block number on the range list.
  45. @param Head The block range head
  46. @return The first valid block number, -1 if the block range is empty.
  47. **/
  48. INTN
  49. Mtftp4GetNextBlockNum (
  50. IN LIST_ENTRY *Head
  51. );
  52. /**
  53. Set the last block number of the block range list.
  54. It will remove all the blocks after the Last. MTFTP initialize the block range
  55. to the maximum possible range, such as [0, 0xffff] for WRQ. When it gets the
  56. last block number, it will call this function to set the last block number.
  57. @param Head The block range list
  58. @param Last The last block number
  59. **/
  60. VOID
  61. Mtftp4SetLastBlockNum (
  62. IN LIST_ENTRY *Head,
  63. IN UINT16 Last
  64. );
  65. /**
  66. Remove the block number from the block range list.
  67. @param Head The block range list to remove from
  68. @param Num The block number to remove
  69. @param Completed Whether Num is the last block number.
  70. @param BlockCounter The continuous block counter instead of the value after roll-over.
  71. @retval EFI_NOT_FOUND The block number isn't in the block range list
  72. @retval EFI_SUCCESS The block number has been removed from the list
  73. @retval EFI_OUT_OF_RESOURCES Failed to allocate resource
  74. **/
  75. EFI_STATUS
  76. Mtftp4RemoveBlockNum (
  77. IN LIST_ENTRY *Head,
  78. IN UINT16 Num,
  79. IN BOOLEAN Completed,
  80. OUT UINT64 *BlockCounter
  81. );
  82. /**
  83. Set the timeout for the instance. User a longer time for passive instances.
  84. @param Instance The Mtftp session to set time out
  85. **/
  86. VOID
  87. Mtftp4SetTimeout (
  88. IN OUT MTFTP4_PROTOCOL *Instance
  89. );
  90. /**
  91. Send the packet for the instance.
  92. It will first save a reference to the packet for later retransmission.
  93. Then determine the destination port, listen port for requests, and connected
  94. port for others. At last, send the packet out.
  95. @param Instance The Mtftp instance
  96. @param Packet The packet to send
  97. @retval EFI_SUCCESS The packet is sent out
  98. @retval Others Failed to transmit the packet.
  99. **/
  100. EFI_STATUS
  101. Mtftp4SendPacket (
  102. IN OUT MTFTP4_PROTOCOL *Instance,
  103. IN OUT NET_BUF *Packet
  104. );
  105. /**
  106. Build then transmit the request packet for the MTFTP session.
  107. @param Instance The Mtftp session
  108. @retval EFI_OUT_OF_RESOURCES Failed to allocate memory for the request
  109. @retval EFI_SUCCESS The request is built and sent
  110. @retval Others Failed to transmit the packet.
  111. **/
  112. EFI_STATUS
  113. Mtftp4SendRequest (
  114. IN MTFTP4_PROTOCOL *Instance
  115. );
  116. /**
  117. Build then send an error message.
  118. @param Instance The MTFTP session
  119. @param ErrCode The error code
  120. @param ErrInfo The error message
  121. @retval EFI_OUT_OF_RESOURCES Failed to allocate memory for the error packet
  122. @retval EFI_SUCCESS The error packet is transmitted.
  123. @retval Others Failed to transmit the packet.
  124. **/
  125. EFI_STATUS
  126. Mtftp4SendError (
  127. IN MTFTP4_PROTOCOL *Instance,
  128. IN UINT16 ErrCode,
  129. IN UINT8 *ErrInfo
  130. );
  131. /**
  132. The timer ticking function in TPL_NOTIFY level for the Mtftp service instance.
  133. @param Event The ticking event
  134. @param Context The Mtftp service instance
  135. **/
  136. VOID
  137. EFIAPI
  138. Mtftp4OnTimerTickNotifyLevel (
  139. IN EFI_EVENT Event,
  140. IN VOID *Context
  141. );
  142. /**
  143. The timer ticking function for the Mtftp service instance.
  144. @param Event The ticking event
  145. @param Context The Mtftp service instance
  146. **/
  147. VOID
  148. EFIAPI
  149. Mtftp4OnTimerTick (
  150. IN EFI_EVENT Event,
  151. IN VOID *Context
  152. );
  153. #endif