Ip6Common.h 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. /** @file
  2. Common definition and functions for IP6 driver.
  3. Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. **/
  6. #ifndef __EFI_IP6_COMMON_H__
  7. #define __EFI_IP6_COMMON_H__
  8. #define IP6_LINK_EQUAL(Mac1, Mac2) (CompareMem ((Mac1), (Mac2), sizeof (EFI_MAC_ADDRESS)) == 0)
  9. //
  10. // Convert the Microsecond to second. IP transmit/receive time is
  11. // in the unit of microsecond. IP ticks once per second.
  12. //
  13. #define IP6_US_TO_SEC(Us) (((Us) + 999999) / 1000000)
  14. #define IP6_ETHER_PROTO 0x86DD
  15. #define IP6_MAC_LEN 6
  16. #define IP6_IF_ID_LEN 8
  17. #define IP6_INTERFACE_LOCAL_SCOPE 1
  18. #define IP6_LINK_LOCAL_SCOPE 2
  19. #define IP6_SITE_LOCAL_SCOPE 5
  20. #define IP6_INFINIT_LIFETIME 0xFFFFFFFF
  21. #define IP6_HOP_LIMIT 255
  22. //
  23. // Make it to 64 since all 54 bits are zero.
  24. //
  25. #define IP6_LINK_LOCAL_PREFIX_LENGTH 64
  26. #define IP6_TIMER_INTERVAL_IN_MS 100
  27. #define IP6_ONE_SECOND_IN_MS 1000
  28. //
  29. // The packet is received as link level broadcast/multicast/promiscuous.
  30. //
  31. #define IP6_LINK_BROADCAST 0x00000001
  32. #define IP6_LINK_MULTICAST 0x00000002
  33. #define IP6_LINK_PROMISC 0x00000004
  34. #define IP6_U_BIT 0x02
  35. typedef enum {
  36. Ip6Promiscuous = 1,
  37. Ip6Unicast,
  38. Ip6Multicast,
  39. Ip6AnyCast
  40. } IP6_ADDRESS_TYPE;
  41. typedef struct {
  42. EFI_SERVICE_BINDING_PROTOCOL *ServiceBinding;
  43. EFI_IPv6_ADDRESS *Address;
  44. } IP6_DESTROY_CHILD_BY_ADDR_CALLBACK_CONTEXT;
  45. typedef struct _IP6_INTERFACE IP6_INTERFACE;
  46. typedef struct _IP6_PROTOCOL IP6_PROTOCOL;
  47. typedef struct _IP6_SERVICE IP6_SERVICE;
  48. typedef struct _IP6_ADDRESS_INFO IP6_ADDRESS_INFO;
  49. /**
  50. Build a array of EFI_IP6_ADDRESS_INFO to be returned to the caller. The number
  51. of EFI_IP6_ADDRESS_INFO is also returned. If AddressList is NULL,
  52. only the address count is returned.
  53. @param[in] IpSb The IP6 service binding instance.
  54. @param[out] AddressCount The number of returned addresses.
  55. @param[out] AddressList The pointer to the array of EFI_IP6_ADDRESS_INFO.
  56. This is an optional parameter.
  57. @retval EFI_SUCCESS The address array is successfully build
  58. @retval EFI_OUT_OF_RESOURCES Failed to allocate the memory for the address info.
  59. @retval EFI_INVALID_PARAMETER Any input parameter is invalid.
  60. **/
  61. EFI_STATUS
  62. Ip6BuildEfiAddressList (
  63. IN IP6_SERVICE *IpSb,
  64. OUT UINT32 *AddressCount,
  65. OUT EFI_IP6_ADDRESS_INFO **AddressList OPTIONAL
  66. );
  67. /**
  68. Generate the multicast addresses identify the group of all IPv6 nodes or IPv6
  69. routers defined in RFC4291.
  70. All Nodes Addresses: FF01::1, FF02::1.
  71. All Router Addresses: FF01::2, FF02::2, FF05::2.
  72. @param[in] Router If TRUE, generate all routers addresses,
  73. else generate all node addresses.
  74. @param[in] Scope interface-local(1), link-local(2), or site-local(5)
  75. @param[out] Ip6Addr The generated multicast address.
  76. @retval EFI_INVALID_PARAMETER Any input parameter is invalid.
  77. @retval EFI_SUCCESS The address is generated.
  78. **/
  79. EFI_STATUS
  80. Ip6SetToAllNodeMulticast (
  81. IN BOOLEAN Router,
  82. IN UINT8 Scope,
  83. OUT EFI_IPv6_ADDRESS *Ip6Addr
  84. );
  85. /**
  86. This function converts MAC address to 64 bits interface ID according to RFC4291
  87. and returns the interface ID. Currently only 48-bit MAC address is supported by
  88. this function.
  89. @param[in, out] IpSb The IP6 service binding instance.
  90. @retval NULL The operation fails.
  91. @return Pointer to the generated interface ID.
  92. **/
  93. UINT8 *
  94. Ip6CreateInterfaceID (
  95. IN OUT IP6_SERVICE *IpSb
  96. );
  97. /**
  98. This function creates link-local address from interface identifier. The
  99. interface identifier is normally created from MAC address. It might be manually
  100. configured by administrator if the link-local address created from MAC address
  101. is a duplicate address.
  102. @param[in, out] IpSb The IP6 service binding instance.
  103. @retval NULL If the operation fails.
  104. @return The generated Link Local address, in network order.
  105. **/
  106. EFI_IPv6_ADDRESS *
  107. Ip6CreateLinkLocalAddr (
  108. IN OUT IP6_SERVICE *IpSb
  109. );
  110. /**
  111. Compute the solicited-node multicast address for an unicast or anycast address,
  112. by taking the low-order 24 bits of this address, and appending those bits to
  113. the prefix FF02:0:0:0:0:1:FF00::/104.
  114. @param Ip6Addr The unicast or anycast address, in network order.
  115. @param MulticastAddr The generated solicited-node multicast address,
  116. in network order.
  117. **/
  118. VOID
  119. Ip6CreateSNMulticastAddr (
  120. IN EFI_IPv6_ADDRESS *Ip6Addr,
  121. OUT EFI_IPv6_ADDRESS *MulticastAddr
  122. );
  123. /**
  124. Check whether the incoming Ipv6 address is a solicited-node multicast address.
  125. @param[in] Ip6 Ip6 address, in network order.
  126. @retval TRUE Yes, solicited-node multicast address
  127. @retval FALSE No
  128. **/
  129. BOOLEAN
  130. Ip6IsSNMulticastAddr (
  131. IN EFI_IPv6_ADDRESS *Ip6
  132. );
  133. /**
  134. Check whether the incoming IPv6 address is one of the maintained address in
  135. the IP6 service binding instance.
  136. @param[in] IpSb Points to a IP6 service binding instance
  137. @param[in] Address The IP6 address to be checked.
  138. @param[out] Interface If not NULL, output the IP6 interface which
  139. maintains the Address.
  140. @param[out] AddressInfo If not NULL, output the IP6 address information
  141. of the Address.
  142. @retval TRUE Yes, it is one of the maintained addresses.
  143. @retval FALSE No, it is not one of the maintained addresses.
  144. **/
  145. BOOLEAN
  146. Ip6IsOneOfSetAddress (
  147. IN IP6_SERVICE *IpSb,
  148. IN EFI_IPv6_ADDRESS *Address,
  149. OUT IP6_INTERFACE **Interface OPTIONAL,
  150. OUT IP6_ADDRESS_INFO **AddressInfo OPTIONAL
  151. );
  152. /**
  153. Check whether the incoming MAC address is valid.
  154. @param[in] IpSb Points to a IP6 service binding instance.
  155. @param[in] LinkAddress The MAC address.
  156. @retval TRUE Yes, it is valid.
  157. @retval FALSE No, it is not valid.
  158. **/
  159. BOOLEAN
  160. Ip6IsValidLinkAddress (
  161. IN IP6_SERVICE *IpSb,
  162. IN EFI_MAC_ADDRESS *LinkAddress
  163. );
  164. /**
  165. Copy the PrefixLength bits from Src to Dest.
  166. @param[out] Dest A pointer to the buffer to copy to.
  167. @param[in] Src A pointer to the buffer to copy from.
  168. @param[in] PrefixLength The number of bits to copy.
  169. **/
  170. VOID
  171. Ip6CopyAddressByPrefix (
  172. OUT EFI_IPv6_ADDRESS *Dest,
  173. IN EFI_IPv6_ADDRESS *Src,
  174. IN UINT8 PrefixLength
  175. );
  176. /**
  177. Insert a node IP6_ADDRESS_INFO to an IP6 interface.
  178. @param[in, out] IpIf Points to an IP6 interface.
  179. @param[in] AddrInfo Points to an IP6_ADDRESS_INFO.
  180. **/
  181. VOID
  182. Ip6AddAddr (
  183. IN OUT IP6_INTERFACE *IpIf,
  184. IN IP6_ADDRESS_INFO *AddrInfo
  185. );
  186. /**
  187. Remove the IPv6 address from the address list node points to IP6_ADDRESS_INFO.
  188. This function removes the matching IPv6 addresses from the address list and
  189. adjusts the address count of the address list. If IpSb is not NULL, this function
  190. calls Ip6LeaveGroup to see whether it should call Mnp->Groups() to remove the
  191. its solicited-node multicast MAC address from the filter list and sends out
  192. a Multicast Listener Done. If Prefix is NULL, all address in the address list
  193. will be removed. If Prefix is not NULL, the address that matching the Prefix
  194. with PrefixLength in the address list will be removed.
  195. @param[in] IpSb NULL or points to IP6 service binding instance.
  196. @param[in, out] AddressList address list array
  197. @param[in, out] AddressCount the count of addresses in address list array
  198. @param[in] Prefix NULL or an IPv6 address prefix
  199. @param[in] PrefixLength the length of Prefix
  200. @retval EFI_SUCCESS The operation completed successfully.
  201. @retval EFI_NOT_FOUND The address matching the Prefix with PrefixLength
  202. cannot be found in address list.
  203. @retval EFI_INVALID_PARAMETER Any input parameter is invalid.
  204. **/
  205. EFI_STATUS
  206. Ip6RemoveAddr (
  207. IN IP6_SERVICE *IpSb OPTIONAL,
  208. IN OUT LIST_ENTRY *AddressList,
  209. IN OUT UINT32 *AddressCount,
  210. IN EFI_IPv6_ADDRESS *Prefix OPTIONAL,
  211. IN UINT8 PrefixLength
  212. );
  213. /**
  214. Get the MAC address for a multicast IP address. Call
  215. Mnp's McastIpToMac to find the MAC address instead of
  216. hard-coding the NIC to be Ethernet.
  217. @param[in] Mnp The Mnp instance to get the MAC address.
  218. @param[in] Multicast The multicast IP address to translate.
  219. @param[out] Mac The buffer to hold the translated address.
  220. @retval EFI_SUCCESS The multicast IP is successfully
  221. translated to a multicast MAC address.
  222. @retval Other The address is not converted because an error occurred.
  223. **/
  224. EFI_STATUS
  225. Ip6GetMulticastMac (
  226. IN EFI_MANAGED_NETWORK_PROTOCOL *Mnp,
  227. IN EFI_IPv6_ADDRESS *Multicast,
  228. OUT EFI_MAC_ADDRESS *Mac
  229. );
  230. /**
  231. Convert the multibyte field in IP header's byter order.
  232. In spite of its name, it can also be used to convert from
  233. host to network byte order.
  234. @param[in, out] Head The IP head to convert.
  235. @return Point to the converted IP head.
  236. **/
  237. EFI_IP6_HEADER *
  238. Ip6NtohHead (
  239. IN OUT EFI_IP6_HEADER *Head
  240. );
  241. #endif