Dhcp6Impl.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479
  1. /** @file
  2. Dhcp6 internal data structure and definition declaration.
  3. Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. **/
  6. #ifndef __EFI_DHCP6_IMPL_H__
  7. #define __EFI_DHCP6_IMPL_H__
  8. #include <Uefi.h>
  9. #include <IndustryStandard/Dhcp.h>
  10. #include <Protocol/Dhcp6.h>
  11. #include <Protocol/Udp6.h>
  12. #include <Protocol/Ip6Config.h>
  13. #include <Protocol/ServiceBinding.h>
  14. #include <Protocol/DriverBinding.h>
  15. #include <Library/UdpIoLib.h>
  16. #include <Library/DebugLib.h>
  17. #include <Library/BaseMemoryLib.h>
  18. #include <Library/MemoryAllocationLib.h>
  19. #include <Library/UefiBootServicesTableLib.h>
  20. #include <Library/UefiRuntimeServicesTableLib.h>
  21. #include <Library/UefiLib.h>
  22. #include <Library/BaseLib.h>
  23. #include <Library/NetLib.h>
  24. #include <Library/PrintLib.h>
  25. #include <Guid/ZeroGuid.h>
  26. typedef struct _DHCP6_IA_CB DHCP6_IA_CB;
  27. typedef struct _DHCP6_INF_CB DHCP6_INF_CB;
  28. typedef struct _DHCP6_TX_CB DHCP6_TX_CB;
  29. typedef struct _DHCP6_SERVICE DHCP6_SERVICE;
  30. typedef struct _DHCP6_INSTANCE DHCP6_INSTANCE;
  31. #include "Dhcp6Utility.h"
  32. #include "Dhcp6Io.h"
  33. #include "Dhcp6Driver.h"
  34. #define DHCP6_SERVICE_SIGNATURE SIGNATURE_32 ('D', 'H', '6', 'S')
  35. #define DHCP6_INSTANCE_SIGNATURE SIGNATURE_32 ('D', 'H', '6', 'I')
  36. #define DHCP6_PACKET_ALL 0
  37. #define DHCP6_PACKET_STATEFUL 1
  38. #define DHCP6_PACKET_STATELESS 2
  39. #define DHCP6_BASE_PACKET_SIZE 1024
  40. #define DHCP6_PORT_CLIENT 546
  41. #define DHCP6_PORT_SERVER 547
  42. #define DHCP_CHECK_MEDIA_WAITING_TIME EFI_TIMER_PERIOD_SECONDS(20)
  43. #define DHCP6_INSTANCE_FROM_THIS(Instance) CR ((Instance), DHCP6_INSTANCE, Dhcp6, DHCP6_INSTANCE_SIGNATURE)
  44. #define DHCP6_SERVICE_FROM_THIS(Service) CR ((Service), DHCP6_SERVICE, ServiceBinding, DHCP6_SERVICE_SIGNATURE)
  45. extern EFI_IPv6_ADDRESS mAllDhcpRelayAndServersAddress;
  46. extern EFI_DHCP6_PROTOCOL gDhcp6ProtocolTemplate;
  47. //
  48. // Control block for each IA.
  49. //
  50. struct _DHCP6_IA_CB {
  51. EFI_DHCP6_IA *Ia;
  52. UINT32 T1;
  53. UINT32 T2;
  54. UINT32 AllExpireTime;
  55. UINT32 LeaseTime;
  56. };
  57. //
  58. // Control block for each transmitted message.
  59. //
  60. struct _DHCP6_TX_CB {
  61. LIST_ENTRY Link;
  62. UINT32 Xid;
  63. EFI_DHCP6_PACKET *TxPacket;
  64. EFI_DHCP6_RETRANSMISSION RetryCtl;
  65. UINT32 RetryCnt;
  66. UINT32 RetryExp;
  67. UINT32 RetryLos;
  68. UINT32 TickTime;
  69. UINT16 *Elapsed;
  70. BOOLEAN SolicitRetry;
  71. };
  72. //
  73. // Control block for each info-request message.
  74. //
  75. struct _DHCP6_INF_CB {
  76. LIST_ENTRY Link;
  77. UINT32 Xid;
  78. EFI_DHCP6_INFO_CALLBACK ReplyCallback;
  79. VOID *CallbackContext;
  80. EFI_EVENT TimeoutEvent;
  81. };
  82. //
  83. // Control block for Dhcp6 instance, it's per configuration data.
  84. //
  85. struct _DHCP6_INSTANCE {
  86. UINT32 Signature;
  87. EFI_HANDLE Handle;
  88. DHCP6_SERVICE *Service;
  89. LIST_ENTRY Link;
  90. EFI_DHCP6_PROTOCOL Dhcp6;
  91. EFI_EVENT Timer;
  92. EFI_DHCP6_CONFIG_DATA *Config;
  93. EFI_DHCP6_IA *CacheIa;
  94. DHCP6_IA_CB IaCb;
  95. LIST_ENTRY TxList;
  96. LIST_ENTRY InfList;
  97. EFI_DHCP6_PACKET *AdSelect;
  98. UINT8 AdPref;
  99. EFI_IPv6_ADDRESS *Unicast;
  100. volatile EFI_STATUS UdpSts;
  101. BOOLEAN InDestroy;
  102. BOOLEAN MediaPresent;
  103. //
  104. // StartTime is used to calculate the 'elapsed-time' option. Refer to RFC3315,
  105. // the elapsed-time is amount of time since the client began its current DHCP transaction.
  106. //
  107. UINT64 StartTime;
  108. };
  109. //
  110. // Control block for Dhcp6 service, it's per Nic handle.
  111. //
  112. struct _DHCP6_SERVICE {
  113. UINT32 Signature;
  114. EFI_HANDLE Controller;
  115. EFI_HANDLE Image;
  116. EFI_SERVICE_BINDING_PROTOCOL ServiceBinding;
  117. EFI_SIMPLE_NETWORK_PROTOCOL *Snp;
  118. EFI_IP6_CONFIG_PROTOCOL *Ip6Cfg;
  119. EFI_DHCP6_DUID *ClientId;
  120. UDP_IO *UdpIo;
  121. UINT32 Xid;
  122. LIST_ENTRY Child;
  123. UINTN NumOfChild;
  124. };
  125. /**
  126. Starts the DHCPv6 standard S.A.R.R. process.
  127. The Start() function starts the DHCPv6 standard process. This function can
  128. be called only when the state of Dhcp6 instance is in the Dhcp6Init state.
  129. If the DHCP process completes successfully, the state of the Dhcp6 instance
  130. will be transferred through Dhcp6Selecting and Dhcp6Requesting to the
  131. Dhcp6Bound state.
  132. Refer to rfc-3315 for precise state transitions during this process. At the
  133. time when each event occurs in this process, the callback function that was set
  134. by EFI_DHCP6_PROTOCOL.Configure() will be called and the user can take this
  135. opportunity to control the process.
  136. @param[in] This The pointer to Dhcp6 protocol.
  137. @retval EFI_SUCCESS The DHCPv6 standard process has started, or it
  138. completed when CompletionEvent was NULL.
  139. @retval EFI_ACCESS_DENIED The EFI DHCPv6 Child instance hasn't been configured.
  140. @retval EFI_INVALID_PARAMETER This is NULL.
  141. @retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated.
  142. @retval EFI_TIMEOUT The DHCPv6 configuration process failed because no
  143. response was received from the server within the
  144. specified timeout value.
  145. @retval EFI_ABORTED The user aborted the DHCPv6 process.
  146. @retval EFI_ALREADY_STARTED Some other Dhcp6 instance already started the DHCPv6
  147. standard process.
  148. @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
  149. **/
  150. EFI_STATUS
  151. EFIAPI
  152. EfiDhcp6Start (
  153. IN EFI_DHCP6_PROTOCOL *This
  154. );
  155. /**
  156. Stops the DHCPv6 standard S.A.R.R. process.
  157. The Stop() function is used to stop the DHCPv6 standard process. After this
  158. function is called successfully, the state of Dhcp6 instance is transferred
  159. into the Dhcp6Init. EFI_DHCP6_PROTOCOL.Configure() needs to be called
  160. before DHCPv6 standard process can be started again. This function can be
  161. called when the Dhcp6 instance is in any state.
  162. @param[in] This The pointer to the Dhcp6 protocol.
  163. @retval EFI_SUCCESS The Dhcp6 instance is now in the Dhcp6Init state.
  164. @retval EFI_INVALID_PARAMETER This is NULL.
  165. **/
  166. EFI_STATUS
  167. EFIAPI
  168. EfiDhcp6Stop (
  169. IN EFI_DHCP6_PROTOCOL *This
  170. );
  171. /**
  172. Returns the current operating mode data for the Dhcp6 instance.
  173. The GetModeData() function returns the current operating mode and
  174. cached data packet for the Dhcp6 instance.
  175. @param[in] This The pointer to the Dhcp6 protocol.
  176. @param[out] Dhcp6ModeData The pointer to the Dhcp6 mode data.
  177. @param[out] Dhcp6ConfigData The pointer to the Dhcp6 configure data.
  178. @retval EFI_SUCCESS The mode data was returned.
  179. @retval EFI_INVALID_PARAMETER This is NULL.
  180. @retval EFI_ACCESS_DENIED The EFI DHCPv6 Protocol instance has not
  181. been configured when Dhcp6ConfigData is
  182. not NULL.
  183. **/
  184. EFI_STATUS
  185. EFIAPI
  186. EfiDhcp6GetModeData (
  187. IN EFI_DHCP6_PROTOCOL *This,
  188. OUT EFI_DHCP6_MODE_DATA *Dhcp6ModeData OPTIONAL,
  189. OUT EFI_DHCP6_CONFIG_DATA *Dhcp6ConfigData OPTIONAL
  190. );
  191. /**
  192. Initializes, changes, or resets the operational settings for the Dhcp6 instance.
  193. The Configure() function is used to initialize or clean up the configuration
  194. data of the Dhcp6 instance:
  195. - When Dhcp6CfgData is not NULL and Configure() is called successfully, the
  196. configuration data will be initialized in the Dhcp6 instance and the state
  197. of the configured IA will be transferred into Dhcp6Init.
  198. - When Dhcp6CfgData is NULL and Configure() is called successfully, the
  199. configuration data will be cleaned up and no IA will be associated with
  200. the Dhcp6 instance.
  201. To update the configuration data for an Dhcp6 instance, the original data
  202. must be cleaned up before setting the new configuration data.
  203. @param[in] This The pointer to the Dhcp6 protocol
  204. @param[in] Dhcp6CfgData The pointer to the EFI_DHCP6_CONFIG_DATA.
  205. @retval EFI_SUCCESS The Dhcp6 is configured successfully with the
  206. Dhcp6Init state, or cleaned up the original
  207. configuration setting.
  208. @retval EFI_ACCESS_DENIED The Dhcp6 instance has been already configured
  209. when Dhcp6CfgData is not NULL.
  210. The Dhcp6 instance has already started the
  211. DHCPv6 S.A.R.R when Dhcp6CfgData is NULL.
  212. @retval EFI_INVALID_PARAMETER Some of the parameter is invalid.
  213. @retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated.
  214. @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
  215. **/
  216. EFI_STATUS
  217. EFIAPI
  218. EfiDhcp6Configure (
  219. IN EFI_DHCP6_PROTOCOL *This,
  220. IN EFI_DHCP6_CONFIG_DATA *Dhcp6CfgData OPTIONAL
  221. );
  222. /**
  223. Request configuration information without the assignment of any
  224. Ia addresses of the client.
  225. The InfoRequest() function is used to request configuration information
  226. without the assignment of any IPv6 address of the client. Client sends
  227. out Information Request packet to obtain the required configuration
  228. information, and DHCPv6 server responds with Reply packet containing
  229. the information for the client. The received Reply packet will be passed
  230. to the user by ReplyCallback function. If user returns EFI_NOT_READY from
  231. ReplyCallback, the Dhcp6 instance will continue to receive other Reply
  232. packets unless timeout according to the Retransmission parameter.
  233. Otherwise, the Information Request exchange process will be finished
  234. successfully if user returns EFI_SUCCESS from ReplyCallback.
  235. @param[in] This The pointer to the Dhcp6 protocol.
  236. @param[in] SendClientId If TRUE, the DHCPv6 protocol instance will build Client
  237. Identifier option and include it into Information Request
  238. packet. Otherwise, Client Identifier option will not be included.
  239. @param[in] OptionRequest The pointer to the buffer of option request options.
  240. @param[in] OptionCount The option number in the OptionList.
  241. @param[in] OptionList The list of appended options.
  242. @param[in] Retransmission The pointer to the retransmission of the message.
  243. @param[in] TimeoutEvent The event of timeout.
  244. @param[in] ReplyCallback The callback function when a reply was received.
  245. @param[in] CallbackContext The pointer to the parameter passed to the callback.
  246. @retval EFI_SUCCESS The DHCPv6 information request exchange process
  247. completed when TimeoutEvent is NULL. Information
  248. Request packet has been sent to DHCPv6 server when
  249. TimeoutEvent is not NULL.
  250. @retval EFI_NO_RESPONSE The DHCPv6 information request exchange process failed
  251. because of no response, or not all requested-options
  252. are responded to by DHCPv6 servers when Timeout happened.
  253. @retval EFI_ABORTED The DHCPv6 information request exchange process was aborted
  254. by the user.
  255. @retval EFI_INVALID_PARAMETER Some parameter is NULL.
  256. @retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated.
  257. @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
  258. **/
  259. EFI_STATUS
  260. EFIAPI
  261. EfiDhcp6InfoRequest (
  262. IN EFI_DHCP6_PROTOCOL *This,
  263. IN BOOLEAN SendClientId,
  264. IN EFI_DHCP6_PACKET_OPTION *OptionRequest,
  265. IN UINT32 OptionCount,
  266. IN EFI_DHCP6_PACKET_OPTION *OptionList[] OPTIONAL,
  267. IN EFI_DHCP6_RETRANSMISSION *Retransmission,
  268. IN EFI_EVENT TimeoutEvent OPTIONAL,
  269. IN EFI_DHCP6_INFO_CALLBACK ReplyCallback,
  270. IN VOID *CallbackContext OPTIONAL
  271. );
  272. /**
  273. Manually extend the valid and preferred lifetimes for the IPv6 addresses
  274. of the configured IA and update other configuration parameters by sending
  275. Renew or Rebind packet.
  276. The RenewRebind() function is used to manually extend the valid and preferred
  277. lifetimes for the IPv6 addresses of the configured IA and update other
  278. configuration parameters by sending a Renew or Rebind packet.
  279. - When RebindRequest is FALSE and the state of the configured IA is Dhcp6Bound,
  280. it will send Renew packet to the previously DHCPv6 server and transfer the
  281. state of the configured IA to Dhcp6Renewing. If valid Reply packet received,
  282. the state transfers to Dhcp6Bound and the valid and preferred timer restarts.
  283. If fails, the state transfers to Dhcp6Bound but the timer continues.
  284. - When RebindRequest is TRUE and the state of the configured IA is Dhcp6Bound,
  285. it will send a Rebind packet. If a valid Reply packet is received, the state transfers
  286. to Dhcp6Bound, and the valid and preferred timer restarts. If it fails, the state
  287. transfers to Dhcp6Init, and the IA can't be used.
  288. @param[in] This The pointer to the Dhcp6 protocol.
  289. @param[in] RebindRequest If TRUE, Rebind packet will be sent and enter Dhcp6Rebinding state.
  290. Otherwise, Renew packet will be sent and enter Dhcp6Renewing state.
  291. @retval EFI_SUCCESS The DHCPv6 renew/rebind exchange process
  292. completed and at least one IPv6 address of the
  293. configured IA was bound again when
  294. EFI_DHCP6_CONFIG_DATA.IaInfoEvent was NULL.
  295. The EFI DHCPv6 Protocol instance has sent Renew
  296. or Rebind packet when
  297. EFI_DHCP6_CONFIG_DATA.IaInfoEvent is not NULL.
  298. @retval EFI_ACCESS_DENIED The Dhcp6 instance hasn't been configured, or the
  299. state of the configured IA is not in Dhcp6Bound.
  300. @retval EFI_ALREADY_STARTED The state of the configured IA has already entered
  301. Dhcp6Renewing when RebindRequest is FALSE.
  302. The state of the configured IA has already entered
  303. Dhcp6Rebinding when RebindRequest is TRUE.
  304. @retval EFI_ABORTED The DHCPv6 renew/rebind exchange process aborted
  305. by user.
  306. @retval EFI_NO_RESPONSE The DHCPv6 renew/rebind exchange process failed
  307. because of no response.
  308. @retval EFI_NO_MAPPING No IPv6 address has been bound to the configured
  309. IA after the DHCPv6 renew/rebind exchange process.
  310. @retval EFI_INVALID_PARAMETER Some parameter is NULL.
  311. @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
  312. **/
  313. EFI_STATUS
  314. EFIAPI
  315. EfiDhcp6RenewRebind (
  316. IN EFI_DHCP6_PROTOCOL *This,
  317. IN BOOLEAN RebindRequest
  318. );
  319. /**
  320. Inform that one or more addresses assigned by a server are already
  321. in use by another node.
  322. The Decline() function is used to manually decline the assignment of
  323. IPv6 addresses, which have been already used by another node. If all
  324. IPv6 addresses of the configured IA are declined through this function,
  325. the state of the IA will switch through Dhcp6Declining to Dhcp6Init.
  326. Otherwise, the state of the IA will restore to Dhcp6Bound after the
  327. declining process. The Decline() can only be called when the IA is in
  328. Dhcp6Bound state. If the EFI_DHCP6_CONFIG_DATA.IaInfoEvent is NULL,
  329. this function is a blocking operation. It will return after the
  330. declining process finishes, or aborted by user.
  331. @param[in] This The pointer to the Dhcp6 protocol.
  332. @param[in] AddressCount The number of declining addresses.
  333. @param[in] Addresses The pointer to the buffer stored the declining
  334. addresses.
  335. @retval EFI_SUCCESS The DHCPv6 decline exchange process completed
  336. when EFI_DHCP6_CONFIG_DATA.IaInfoEvent was NULL.
  337. The Dhcp6 instance has sent Decline packet when
  338. EFI_DHCP6_CONFIG_DATA.IaInfoEvent is not NULL.
  339. @retval EFI_ACCESS_DENIED The Dhcp6 instance hasn't been configured, or the
  340. state of the configured IA is not in Dhcp6Bound.
  341. @retval EFI_ABORTED The DHCPv6 decline exchange process was aborted by the user.
  342. @retval EFI_NOT_FOUND Any specified IPv6 address is not correlated with
  343. the configured IA for this instance.
  344. @retval EFI_INVALID_PARAMETER Some parameter is NULL.
  345. @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
  346. **/
  347. EFI_STATUS
  348. EFIAPI
  349. EfiDhcp6Decline (
  350. IN EFI_DHCP6_PROTOCOL *This,
  351. IN UINT32 AddressCount,
  352. IN EFI_IPv6_ADDRESS *Addresses
  353. );
  354. /**
  355. Release one or more addresses associated with the configured Ia
  356. for the current instance.
  357. The Release() function is used to manually release the one or more
  358. IPv6 address. If AddressCount is zero, it will release all IPv6
  359. addresses of the configured IA. If all IPv6 addresses of the IA are
  360. released through this function, the state of the IA will switch
  361. through Dhcp6Releasing to Dhcp6Init, otherwise, the state of the
  362. IA will restore to Dhcp6Bound after the releasing process.
  363. The Release() can only be called when the IA is in a Dhcp6Bound state.
  364. If the EFI_DHCP6_CONFIG_DATA.IaInfoEvent is NULL, the function is
  365. a blocking operation. It will return after the releasing process
  366. finishes, or aborted by user.
  367. @param[in] This The pointer to the Dhcp6 protocol.
  368. @param[in] AddressCount The number of releasing addresses.
  369. @param[in] Addresses The pointer to the buffer stored the releasing
  370. addresses.
  371. @retval EFI_SUCCESS The DHCPv6 release exchange process has
  372. completed when EFI_DHCP6_CONFIG_DATA.IaInfoEvent
  373. is NULL. The Dhcp6 instance has sent Release
  374. packet when EFI_DHCP6_CONFIG_DATA.IaInfoEvent
  375. is not NULL.
  376. @retval EFI_ACCESS_DENIED The Dhcp6 instance hasn't been configured, or the
  377. state of the configured IA is not in Dhcp6Bound.
  378. @retval EFI_ABORTED The DHCPv6 release exchange process was aborted by the user.
  379. @retval EFI_NOT_FOUND Any specified IPv6 address is not correlated with
  380. the configured IA for this instance.
  381. @retval EFI_INVALID_PARAMETER Some parameter is NULL.
  382. @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
  383. **/
  384. EFI_STATUS
  385. EFIAPI
  386. EfiDhcp6Release (
  387. IN EFI_DHCP6_PROTOCOL *This,
  388. IN UINT32 AddressCount,
  389. IN EFI_IPv6_ADDRESS *Addresses
  390. );
  391. /**
  392. Parse the option data in the Dhcp6 packet.
  393. The Parse() function is used to retrieve the option list in the DHCPv6 packet.
  394. @param[in] This The pointer to the Dhcp6 protocol.
  395. @param[in] Packet The pointer to the Dhcp6 packet.
  396. @param[in, out] OptionCount The number of option in the packet.
  397. @param[out] PacketOptionList The array of pointers to the each option in the packet.
  398. @retval EFI_SUCCESS The packet was successfully parsed.
  399. @retval EFI_INVALID_PARAMETER Some parameter is NULL.
  400. @retval EFI_BUFFER_TOO_SMALL *OptionCount is smaller than the number of options
  401. that were found in the Packet.
  402. **/
  403. EFI_STATUS
  404. EFIAPI
  405. EfiDhcp6Parse (
  406. IN EFI_DHCP6_PROTOCOL *This,
  407. IN EFI_DHCP6_PACKET *Packet,
  408. IN OUT UINT32 *OptionCount,
  409. OUT EFI_DHCP6_PACKET_OPTION *PacketOptionList[] OPTIONAL
  410. );
  411. #endif