Dhcp6Utility.h 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  1. /** @file
  2. Dhcp6 support functions declaration.
  3. Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved.<BR>
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. **/
  6. #ifndef __EFI_DHCP6_UTILITY_H__
  7. #define __EFI_DHCP6_UTILITY_H__
  8. #define DHCP6_10_BIT_MASK 0x3ff
  9. #define DHCP6_DAD_ADDITIONAL_DELAY 30000000 // 3 seconds
  10. /**
  11. Generate client Duid in the format of Duid-llt.
  12. @param[in] Mode The pointer to the mode of SNP.
  13. @retval NULL if failed to generate client Id.
  14. @retval Others The pointer to the new client id.
  15. **/
  16. EFI_DHCP6_DUID *
  17. Dhcp6GenerateClientId (
  18. IN EFI_SIMPLE_NETWORK_MODE *Mode
  19. );
  20. /**
  21. Copy the Dhcp6 configure data.
  22. @param[in] DstCfg The pointer to the destination configure data.
  23. @param[in] SorCfg The pointer to the source configure data.
  24. @retval EFI_SUCCESS Copy the content from SorCfg from DstCfg successfully.
  25. @retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated.
  26. **/
  27. EFI_STATUS
  28. Dhcp6CopyConfigData (
  29. IN EFI_DHCP6_CONFIG_DATA *DstCfg,
  30. IN EFI_DHCP6_CONFIG_DATA *SorCfg
  31. );
  32. /**
  33. Clean up the configure data.
  34. @param[in, out] CfgData The pointer to the configure data.
  35. **/
  36. VOID
  37. Dhcp6CleanupConfigData (
  38. IN OUT EFI_DHCP6_CONFIG_DATA *CfgData
  39. );
  40. /**
  41. Clean up the mode data.
  42. @param[in, out] ModeData The pointer to the mode data.
  43. **/
  44. VOID
  45. Dhcp6CleanupModeData (
  46. IN OUT EFI_DHCP6_MODE_DATA *ModeData
  47. );
  48. /**
  49. Calculate the expire time by the algorithm defined in rfc.
  50. @param[in] Base The base value of the time.
  51. @param[in] IsFirstRt If TRUE, it is the first time to calculate expire time.
  52. @param[in] NeedSigned If TRUE, the signed factor is needed.
  53. @return Expire The calculated result for the new expire time.
  54. **/
  55. UINT32
  56. Dhcp6CalculateExpireTime (
  57. IN UINT32 Base,
  58. IN BOOLEAN IsFirstRt,
  59. IN BOOLEAN NeedSigned
  60. );
  61. /**
  62. Calculate the lease time by the algorithm defined in rfc.
  63. @param[in] IaCb The pointer to the Ia control block.
  64. **/
  65. VOID
  66. Dhcp6CalculateLeaseTime (
  67. IN DHCP6_IA_CB *IaCb
  68. );
  69. /**
  70. Check whether the addresses are all included by the configured Ia.
  71. @param[in] Ia The pointer to the Ia.
  72. @param[in] AddressCount The number of addresses.
  73. @param[in] Addresses The pointer to the addresses buffer.
  74. @retval EFI_SUCCESS The addresses are all included by the configured IA.
  75. @retval EFI_NOT_FOUND The addresses are not included by the configured IA.
  76. **/
  77. EFI_STATUS
  78. Dhcp6CheckAddress (
  79. IN EFI_DHCP6_IA *Ia,
  80. IN UINT32 AddressCount,
  81. IN EFI_IPv6_ADDRESS *Addresses
  82. );
  83. /**
  84. Deprive the addresses from current Ia, and generate another eliminated Ia.
  85. @param[in] Ia The pointer to the Ia.
  86. @param[in] AddressCount The number of addresses.
  87. @param[in] Addresses The pointer to the addresses buffer.
  88. @retval NULL If failed to generate the deprived Ia.
  89. @retval others The pointer to the deprived Ia.
  90. **/
  91. EFI_DHCP6_IA *
  92. Dhcp6DepriveAddress (
  93. IN EFI_DHCP6_IA *Ia,
  94. IN UINT32 AddressCount,
  95. IN EFI_IPv6_ADDRESS *Addresses
  96. );
  97. /**
  98. The dummy ext buffer free callback routine.
  99. @param[in] Arg The pointer to the parameter.
  100. **/
  101. VOID
  102. EFIAPI
  103. Dhcp6DummyExtFree (
  104. IN VOID *Arg
  105. );
  106. /**
  107. The callback routine once message transmitted.
  108. @param[in] Wrap The pointer to the received net buffer.
  109. @param[in] EndPoint The pointer to the udp end point.
  110. @param[in] IoStatus The return status from udp io.
  111. @param[in] Context The opaque parameter to the function.
  112. **/
  113. VOID
  114. EFIAPI
  115. Dhcp6OnTransmitted (
  116. IN NET_BUF *Wrap,
  117. IN UDP_END_POINT *EndPoint,
  118. IN EFI_STATUS IoStatus,
  119. IN VOID *Context
  120. );
  121. /**
  122. Append the appointed option to the buf, and move the buf to the end.
  123. @param[in, out] Buf The pointer to buffer.
  124. @param[in] OptType The option type.
  125. @param[in] OptLen The length of option content.s
  126. @param[in] Data The pointer to the option content.
  127. @return Buf The position to append the next option.
  128. **/
  129. UINT8 *
  130. Dhcp6AppendOption (
  131. IN OUT UINT8 *Buf,
  132. IN UINT16 OptType,
  133. IN UINT16 OptLen,
  134. IN UINT8 *Data
  135. );
  136. /**
  137. Append the Ia option to Buf, and move Buf to the end.
  138. @param[in, out] Buf The pointer to the position to append.
  139. @param[in] Ia The pointer to the Ia.
  140. @param[in] T1 The time of T1.
  141. @param[in] T2 The time of T2.
  142. @param[in] MessageType Message type of DHCP6 package.
  143. @return Buf The position to append the next Ia option.
  144. **/
  145. UINT8 *
  146. Dhcp6AppendIaOption (
  147. IN OUT UINT8 *Buf,
  148. IN EFI_DHCP6_IA *Ia,
  149. IN UINT32 T1,
  150. IN UINT32 T2,
  151. IN UINT32 MessageType
  152. );
  153. /**
  154. Append the appointed Elapsed time option to Buf, and move Buf to the end.
  155. @param[in, out] Buf The pointer to the position to append.
  156. @param[in] Instance The pointer to the Dhcp6 instance.
  157. @param[out] Elapsed The pointer to the elapsed time value in
  158. the generated packet.
  159. @return Buf The position to append the next Ia option.
  160. **/
  161. UINT8 *
  162. Dhcp6AppendETOption (
  163. IN OUT UINT8 *Buf,
  164. IN DHCP6_INSTANCE *Instance,
  165. OUT UINT16 **Elapsed
  166. );
  167. /**
  168. Set the elapsed time based on the given instance and the pointer to the
  169. elapsed time option.
  170. @param[in] Elapsed The pointer to the position to append.
  171. @param[in] Instance The pointer to the Dhcp6 instance.
  172. **/
  173. VOID
  174. SetElapsedTime (
  175. IN UINT16 *Elapsed,
  176. IN DHCP6_INSTANCE *Instance
  177. );
  178. /**
  179. Seek the address of the first byte of the option header.
  180. @param[in] Buf The pointer to buffer.
  181. @param[in] SeekLen The length to seek.
  182. @param[in] OptType The option type.
  183. @retval NULL If failed to seek the option.
  184. @retval others The position to the option.
  185. **/
  186. UINT8 *
  187. Dhcp6SeekOption (
  188. IN UINT8 *Buf,
  189. IN UINT32 SeekLen,
  190. IN UINT16 OptType
  191. );
  192. /**
  193. Seek the address of the first byte of the Ia option header.
  194. @param[in] Buf The pointer to the buffer.
  195. @param[in] SeekLen The length to seek.
  196. @param[in] IaDesc The pointer to the Ia descriptor.
  197. @retval NULL If failed to seek the Ia option.
  198. @retval others The position to the Ia option.
  199. **/
  200. UINT8 *
  201. Dhcp6SeekIaOption (
  202. IN UINT8 *Buf,
  203. IN UINT32 SeekLen,
  204. IN EFI_DHCP6_IA_DESCRIPTOR *IaDesc
  205. );
  206. /**
  207. Parse the address option and update the address info.
  208. @param[in] CurrentIa The pointer to the Ia Address in control block.
  209. @param[in] IaInnerOpt The pointer to the buffer.
  210. @param[in] IaInnerLen The length to parse.
  211. @param[out] AddrNum The number of addresses.
  212. @param[in, out] AddrBuf The pointer to the address buffer.
  213. **/
  214. VOID
  215. Dhcp6ParseAddrOption (
  216. IN EFI_DHCP6_IA *CurrentIa,
  217. IN UINT8 *IaInnerOpt,
  218. IN UINT16 IaInnerLen,
  219. OUT UINT32 *AddrNum,
  220. IN OUT EFI_DHCP6_IA_ADDRESS *AddrBuf
  221. );
  222. /**
  223. Create a control block for the Ia according to the corresponding options.
  224. @param[in] Instance The pointer to DHCP6 Instance.
  225. @param[in] IaInnerOpt The pointer to the inner options in the Ia option.
  226. @param[in] IaInnerLen The length of all the inner options in the Ia option.
  227. @param[in] T1 T1 time in the Ia option.
  228. @param[in] T2 T2 time in the Ia option.
  229. @retval EFI_NOT_FOUND No valid IA option is found.
  230. @retval EFI_SUCCESS Create an IA control block successfully.
  231. @retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated.
  232. @retval EFI_DEVICE_ERROR An unexpected error.
  233. **/
  234. EFI_STATUS
  235. Dhcp6GenerateIaCb (
  236. IN DHCP6_INSTANCE *Instance,
  237. IN UINT8 *IaInnerOpt,
  238. IN UINT16 IaInnerLen,
  239. IN UINT32 T1,
  240. IN UINT32 T2
  241. );
  242. /**
  243. Cache the current IA configuration information.
  244. @param[in] Instance The pointer to DHCP6 Instance.
  245. @retval EFI_SUCCESS Cache the current IA successfully.
  246. @retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated.
  247. **/
  248. EFI_STATUS
  249. Dhcp6CacheIa (
  250. IN DHCP6_INSTANCE *Instance
  251. );
  252. /**
  253. Append CacheIa to the current IA. Meanwhile, clear CacheIa.ValidLifetime to 0.
  254. @param[in] Instance The pointer to DHCP6 instance.
  255. **/
  256. VOID
  257. Dhcp6AppendCacheIa (
  258. IN DHCP6_INSTANCE *Instance
  259. );
  260. /**
  261. Calculate the Dhcp6 get mapping timeout by adding additional delay to the IP6 DAD transmits count.
  262. @param[in] Ip6Cfg The pointer to Ip6 config protocol.
  263. @param[out] TimeOut The time out value in 100ns units.
  264. @retval EFI_INVALID_PARAMETER Input parameters are invalid.
  265. @retval EFI_SUCCESS Calculate the time out value successfully.
  266. **/
  267. EFI_STATUS
  268. Dhcp6GetMappingTimeOut (
  269. IN EFI_IP6_CONFIG_PROTOCOL *Ip6Cfg,
  270. OUT UINTN *TimeOut
  271. );
  272. #endif