Mtftp6Option.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /** @file
  2. Mtftp6 option parse 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_OPTION_H__
  7. #define __EFI_MTFTP6_OPTION_H__
  8. #include <Uefi.h>
  9. #include <Protocol/ServiceBinding.h>
  10. #include <Library/NetLib.h>
  11. #include <Library/UdpIoLib.h>
  12. #include <Library/BaseMemoryLib.h>
  13. #include <Library/MemoryAllocationLib.h>
  14. #include <Library/UefiRuntimeServicesTableLib.h>
  15. #define MTFTP6_SUPPORTED_OPTIONS_NUM 5
  16. #define MTFTP6_OPCODE_LEN 2
  17. #define MTFTP6_ERRCODE_LEN 2
  18. #define MTFTP6_BLKNO_LEN 2
  19. #define MTFTP6_DATA_HEAD_LEN 4
  20. //
  21. // The bit map definition for Mtftp6 extension options.
  22. //
  23. #define MTFTP6_OPT_BLKSIZE_BIT 0x01
  24. #define MTFTP6_OPT_TIMEOUT_BIT 0x02
  25. #define MTFTP6_OPT_TSIZE_BIT 0x04
  26. #define MTFTP6_OPT_MCAST_BIT 0x08
  27. #define MTFTP6_OPT_WINDOWSIZE_BIT 0X10
  28. extern CHAR8 *mMtftp6SupportedOptions[MTFTP6_SUPPORTED_OPTIONS_NUM];
  29. typedef struct {
  30. UINT16 BlkSize;
  31. UINT16 WindowSize;
  32. UINT8 Timeout;
  33. UINT32 Tsize;
  34. EFI_IPv6_ADDRESS McastIp;
  35. UINT16 McastPort;
  36. BOOLEAN IsMaster;
  37. UINT32 BitMap;
  38. } MTFTP6_EXT_OPTION_INFO;
  39. /**
  40. Parse the Ascii string of multi-cast option.
  41. @param[in] Str The pointer to the Ascii string of multi-cast option.
  42. @param[in] ExtInfo The pointer to the option information to be filled.
  43. @retval EFI_SUCCESS Parse the multicast option successfully.
  44. @retval EFI_INVALID_PARAMETER The string is malformatted.
  45. **/
  46. EFI_STATUS
  47. Mtftp6ParseMcastOption (
  48. IN UINT8 *Str,
  49. IN MTFTP6_EXT_OPTION_INFO *ExtInfo
  50. );
  51. /**
  52. Parse the MTFTP6 extension options.
  53. @param[in] Options The pointer to the extension options list.
  54. @param[in] Count The num of the extension options.
  55. @param[in] IsRequest If FALSE, the extension options is included
  56. by a request packet.
  57. @param[in] Operation The current performed operation.
  58. @param[in] ExtInfo The pointer to the option information to be filled.
  59. @retval EFI_SUCCESS Parse the multicast option successfully.
  60. @retval EFI_INVALID_PARAMETER There is one option is malformatted at least.
  61. @retval EFI_UNSUPPORTED There is one option is not supported at least.
  62. **/
  63. EFI_STATUS
  64. Mtftp6ParseExtensionOption (
  65. IN EFI_MTFTP6_OPTION *Options,
  66. IN UINT32 Count,
  67. IN BOOLEAN IsRequest,
  68. IN UINT16 Operation,
  69. IN MTFTP6_EXT_OPTION_INFO *ExtInfo
  70. );
  71. /**
  72. Go through the packet to fill the options array with the start
  73. addresses of each MTFTP option name/value pair.
  74. @param[in] Packet The packet to be checked.
  75. @param[in] PacketLen The length of the packet.
  76. @param[in, out] Count The num of the Options on input.
  77. The actual one on output.
  78. @param[in] Options The option array to be filled
  79. it's optional.
  80. @retval EFI_SUCCESS The packet has been parsed successfully.
  81. @retval EFI_INVALID_PARAMETER The packet is malformatted
  82. @retval EFI_BUFFER_TOO_SMALL The Options array is too small
  83. @retval EFI_PROTOCOL_ERROR An unexpected MTFTPv6 packet was received.
  84. **/
  85. EFI_STATUS
  86. Mtftp6ParsePacketOption (
  87. IN EFI_MTFTP6_PACKET *Packet,
  88. IN UINT32 PacketLen,
  89. IN OUT UINT32 *Count,
  90. IN EFI_MTFTP6_OPTION *Options OPTIONAL
  91. );
  92. /**
  93. Go through the packet, generate option list array and fill it
  94. by the result of parse options.
  95. @param[in] Packet The packet to be checked.
  96. @param[in] PacketLen The length of the packet.
  97. @param[in, out] OptionCount The num of the Options on input.
  98. The actual one on output.
  99. @param[out] OptionList The option list array to be generated
  100. and filled. It is optional.
  101. @retval EFI_SUCCESS The packet has been parsed successfully.
  102. @retval EFI_INVALID_PARAMETER The packet is malformatted.
  103. @retval EFI_PROTOCOL_ERROR An option is malformatted.
  104. @retval EFI_NOT_FOUND The packet has no options.
  105. @retval EFI_OUT_OF_RESOURCES Failed to allocate memory for the array.
  106. @retval EFI_BUFFER_TOO_SMALL The size of option list array is too small.
  107. **/
  108. EFI_STATUS
  109. Mtftp6ParseStart (
  110. IN EFI_MTFTP6_PACKET *Packet,
  111. IN UINT32 PacketLen,
  112. IN OUT UINT32 *OptionCount,
  113. OUT EFI_MTFTP6_OPTION **OptionList OPTIONAL
  114. );
  115. #endif