Mtftp6Support.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. /** @file
  2. Mtftp6 support functions declaration.
  3. Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. **/
  6. #ifndef __EFI_MTFTP6_SUPPORT_H__
  7. #define __EFI_MTFTP6_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. } MTFTP6_BLOCK_RANGE;
  20. /**
  21. Initialize the block range for either RRQ or WRQ. RRQ and WRQ have
  22. different requirements for Start and End. For example, during startup,
  23. WRQ initializes its whole valid block range to [0, 0xffff]. This
  24. is because the server will send an ACK0 to inform the user to start the
  25. upload. When the client receives an ACK0, it will remove 0 from the range,
  26. 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
  28. in response to the client's RRQ. When BLOCK1 is received, the client will
  29. remove it from the block range and send an ACK. It also works if there
  30. is option negotiation.
  31. @param[in] Head The block range head to initialize.
  32. @param[in] Start The Start block number.
  33. @param[in] 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. Mtftp6InitBlockRange (
  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[in] Head The block range head.
  46. @retval ==-1 If the block range is empty.
  47. @retval >-1 The first valid block number.
  48. **/
  49. INTN
  50. Mtftp6GetNextBlockNum (
  51. IN LIST_ENTRY *Head
  52. );
  53. /**
  54. Set the last block number of the block range list. It
  55. removes all the blocks after the Last. MTFTP initialize the
  56. block range to the maximum possible range, such as [0, 0xffff]
  57. for WRQ. When it gets the last block number, it calls
  58. this function to set the last block number.
  59. @param[in] Head The block range list.
  60. @param[in] Last The last block number.
  61. **/
  62. VOID
  63. Mtftp6SetLastBlockNum (
  64. IN LIST_ENTRY *Head,
  65. IN UINT16 Last
  66. );
  67. /**
  68. Remove the block number from the block range list.
  69. @param[in] Head The block range list to remove from.
  70. @param[in] Num The block number to remove.
  71. @param[in] Completed Whether Num is the last block number.
  72. @param[out] BlockCounter The continuous block counter instead of the value after roll-over.
  73. @retval EFI_NOT_FOUND The block number isn't in the block range list.
  74. @retval EFI_SUCCESS The block number has been removed from the list.
  75. @retval EFI_OUT_OF_RESOURCES Failed to allocate resources.
  76. **/
  77. EFI_STATUS
  78. Mtftp6RemoveBlockNum (
  79. IN LIST_ENTRY *Head,
  80. IN UINT16 Num,
  81. IN BOOLEAN Completed,
  82. OUT UINT64 *BlockCounter
  83. );
  84. /**
  85. Build and transmit the request packet for the Mtftp6 instance.
  86. @param[in] Instance The pointer to the Mtftp6 instance.
  87. @param[in] Operation The operation code of this packet.
  88. @retval EFI_OUT_OF_RESOURCES Failed to allocate memory for the request.
  89. @retval EFI_SUCCESS The request was built and sent.
  90. @retval Others Failed to transmit the packet.
  91. **/
  92. EFI_STATUS
  93. Mtftp6SendRequest (
  94. IN MTFTP6_INSTANCE *Instance,
  95. IN UINT16 Operation
  96. );
  97. /**
  98. Build and send an error packet.
  99. @param[in] Instance The pointer to the Mtftp6 instance.
  100. @param[in] ErrCode The error code in the packet.
  101. @param[in] ErrInfo The error message in the packet.
  102. @retval EFI_OUT_OF_RESOURCES Failed to allocate memory for the error packet.
  103. @retval EFI_SUCCESS The error packet was transmitted.
  104. @retval Others Failed to transmit the packet.
  105. **/
  106. EFI_STATUS
  107. Mtftp6SendError (
  108. IN MTFTP6_INSTANCE *Instance,
  109. IN UINT16 ErrCode,
  110. IN UINT8 *ErrInfo
  111. );
  112. /**
  113. Send the packet for the Mtftp6 instance.
  114. @param[in] Instance The pointer to the Mtftp6 instance.
  115. @param[in] Packet The pointer to the packet to be sent.
  116. @retval EFI_SUCCESS The packet was sent out
  117. @retval Others Failed to transmit the packet.
  118. **/
  119. EFI_STATUS
  120. Mtftp6TransmitPacket (
  121. IN MTFTP6_INSTANCE *Instance,
  122. IN NET_BUF *Packet
  123. );
  124. /**
  125. Check packet for GetInfo callback routine.
  126. @param[in] This The pointer to the Mtftp6 protocol.
  127. @param[in] Token The pointer to the Mtftp6 token.
  128. @param[in] PacketLen The length of the packet
  129. @param[in] Packet The pointer to the received packet.
  130. @retval EFI_SUCCESS The check process passed successfully.
  131. @retval EFI_ABORTED Abort the Mtftp6 operation.
  132. **/
  133. EFI_STATUS
  134. EFIAPI
  135. Mtftp6CheckPacket (
  136. IN EFI_MTFTP6_PROTOCOL *This,
  137. IN EFI_MTFTP6_TOKEN *Token,
  138. IN UINT16 PacketLen,
  139. IN EFI_MTFTP6_PACKET *Packet
  140. );
  141. /**
  142. The dummy configure routine for create a new Udp6 Io.
  143. @param[in] UdpIo The pointer to the Udp6 Io.
  144. @param[in] Context The pointer to the context.
  145. @retval EFI_SUCCESS The value is always returned.
  146. **/
  147. EFI_STATUS
  148. EFIAPI
  149. Mtftp6ConfigDummyUdpIo (
  150. IN UDP_IO *UdpIo,
  151. IN VOID *Context
  152. );
  153. /**
  154. The configure routine for the Mtftp6 instance to transmit/receive.
  155. @param[in] UdpIo The pointer to the Udp6 Io.
  156. @param[in] ServerIp The pointer to the server address.
  157. @param[in] ServerPort The pointer to the server port.
  158. @param[in] LocalIp The pointer to the local address.
  159. @param[in] LocalPort The pointer to the local port.
  160. @retval EFI_SUCCESS Configure the Udp6 Io for Mtftp6 successfully.
  161. @retval EFI_NO_MAPPING The corresponding Ip6 instance has not been
  162. configured yet.
  163. **/
  164. EFI_STATUS
  165. Mtftp6ConfigUdpIo (
  166. IN UDP_IO *UdpIo,
  167. IN EFI_IPv6_ADDRESS *ServerIp,
  168. IN UINT16 ServerPort,
  169. IN EFI_IPv6_ADDRESS *LocalIp,
  170. IN UINT16 LocalPort
  171. );
  172. /**
  173. Clean up the current Mtftp6 operation.
  174. @param[in] Instance The pointer to the Mtftp6 instance.
  175. @param[in] Result The result to be returned to the user.
  176. **/
  177. VOID
  178. Mtftp6OperationClean (
  179. IN MTFTP6_INSTANCE *Instance,
  180. IN EFI_STATUS Result
  181. );
  182. /**
  183. Start the Mtftp6 instance to perform the operation, such as read file,
  184. write file, and read directory.
  185. @param[in] This The MTFTP session
  186. @param[in] Token The token that encapsulates the user's request.
  187. @param[in] OpCode The operation to perform.
  188. @retval EFI_INVALID_PARAMETER Some of the parameters are invalid.
  189. @retval EFI_NOT_STARTED The MTFTP session hasn't been configured.
  190. @retval EFI_ALREADY_STARTED There is pending operation for the session.
  191. @retval EFI_SUCCESS The operation was successfully started.
  192. **/
  193. EFI_STATUS
  194. Mtftp6OperationStart (
  195. IN EFI_MTFTP6_PROTOCOL *This,
  196. IN EFI_MTFTP6_TOKEN *Token,
  197. IN UINT16 OpCode
  198. );
  199. /**
  200. The timer ticking routine for the Mtftp6 instance.
  201. @param[in] Event The pointer to the ticking event.
  202. @param[in] Context The pointer to the context.
  203. **/
  204. VOID
  205. EFIAPI
  206. Mtftp6OnTimerTick (
  207. IN EFI_EVENT Event,
  208. IN VOID *Context
  209. );
  210. /**
  211. The packet process callback for Mtftp6 upload.
  212. @param[in] UdpPacket The pointer to the packet received.
  213. @param[in] UdpEpt The pointer to the Udp6 access point.
  214. @param[in] IoStatus The status from the Udp6 instance.
  215. @param[in] Context The pointer to the context.
  216. **/
  217. VOID
  218. EFIAPI
  219. Mtftp6WrqInput (
  220. IN NET_BUF *UdpPacket,
  221. IN UDP_END_POINT *UdpEpt,
  222. IN EFI_STATUS IoStatus,
  223. IN VOID *Context
  224. );
  225. /**
  226. Start the Mtftp6 instance to upload. It will first init some states,
  227. then send the WRQ request packet, and start to receive the packet.
  228. @param[in] Instance The pointer to the Mtftp6 instance.
  229. @param[in] Operation The operation code of current packet.
  230. @retval EFI_SUCCESS The Mtftp6 was started to upload.
  231. @retval Others Failed to start to upload.
  232. **/
  233. EFI_STATUS
  234. Mtftp6WrqStart (
  235. IN MTFTP6_INSTANCE *Instance,
  236. IN UINT16 Operation
  237. );
  238. /**
  239. The packet process callback for Mtftp6 download.
  240. @param[in] UdpPacket The pointer to the packet received.
  241. @param[in] UdpEpt The pointer to the Udp6 access point.
  242. @param[in] IoStatus The status from Udp6 instance.
  243. @param[in] Context The pointer to the context.
  244. **/
  245. VOID
  246. EFIAPI
  247. Mtftp6RrqInput (
  248. IN NET_BUF *UdpPacket,
  249. IN UDP_END_POINT *UdpEpt,
  250. IN EFI_STATUS IoStatus,
  251. IN VOID *Context
  252. );
  253. /**
  254. Start the Mtftp6 instance to download. It first initializes some
  255. of the internal states then builds and sends an RRQ request packet.
  256. Finally, it starts receive for the downloading.
  257. @param[in] Instance The pointer to the Mtftp6 instance.
  258. @param[in] Operation The operation code of current packet.
  259. @retval EFI_SUCCESS The Mtftp6 was started to download.
  260. @retval Others Failed to start to download.
  261. **/
  262. EFI_STATUS
  263. Mtftp6RrqStart (
  264. IN MTFTP6_INSTANCE *Instance,
  265. IN UINT16 Operation
  266. );
  267. #endif