Dhcp4Io.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. /** @file
  2. The DHCP4 protocol implementation.
  3. Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. **/
  6. #ifndef __EFI_DHCP4_IO_H__
  7. #define __EFI_DHCP4_IO_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. #define DHCP_WAIT_OFFER 3 // Time to wait the offers
  15. #define DHCP_DEFAULT_LEASE 7 * 24 * 60 * 60 // Seven days as default.
  16. #define DHCP_SERVER_PORT 67
  17. #define DHCP_CLIENT_PORT 68
  18. //
  19. // BOOTP header "op" field
  20. //
  21. #define BOOTP_REQUEST 1
  22. #define BOOTP_REPLY 2
  23. //
  24. // DHCP message types
  25. //
  26. #define DHCP_MSG_DISCOVER 1
  27. #define DHCP_MSG_OFFER 2
  28. #define DHCP_MSG_REQUEST 3
  29. #define DHCP_MSG_DECLINE 4
  30. #define DHCP_MSG_ACK 5
  31. #define DHCP_MSG_NAK 6
  32. #define DHCP_MSG_RELEASE 7
  33. #define DHCP_MSG_INFORM 8
  34. //
  35. // DHCP notify user type
  36. //
  37. #define DHCP_NOTIFY_COMPLETION 1
  38. #define DHCP_NOTIFY_RENEWREBIND 2
  39. #define DHCP_NOTIFY_ALL 3
  40. #define DHCP_IS_BOOTP(Parameter) (((Parameter) == NULL) || ((Parameter)->DhcpType == 0))
  41. #define DHCP_CONNECTED(State) \
  42. (((State) == Dhcp4Bound) || ((State) == (Dhcp4Renewing)) || ((State) == Dhcp4Rebinding))
  43. /**
  44. Set the DHCP state. If CallUser is true, it will try to notify
  45. the user before change the state by DhcpNotifyUser. It returns
  46. EFI_ABORTED if the user return EFI_ABORTED, otherwise, it returns
  47. EFI_SUCCESS. If CallUser is FALSE, it isn't necessary to test
  48. the return value of this function.
  49. @param DhcpSb The DHCP service instance
  50. @param State The new DHCP state to change to
  51. @param CallUser Whether we need to call user
  52. @retval EFI_SUCCESS The state is changed
  53. @retval EFI_ABORTED The user asks to abort the DHCP process.
  54. **/
  55. EFI_STATUS
  56. DhcpSetState (
  57. IN OUT DHCP_SERVICE *DhcpSb,
  58. IN INTN State,
  59. IN BOOLEAN CallUser
  60. );
  61. /**
  62. Build and transmit a DHCP message according to the current states.
  63. This function implement the Table 5. of RFC 2131. Always transits
  64. the state (as defined in Figure 5. of the same RFC) before sending
  65. a DHCP message. The table is adjusted accordingly.
  66. @param[in] DhcpSb The DHCP service instance
  67. @param[in] Seed The seed packet which the new packet is based on
  68. @param[in] Para The DHCP parameter of the Seed packet
  69. @param[in] Type The message type to send
  70. @param[in] Msg The human readable message to include in the packet
  71. sent.
  72. @retval EFI_OUT_OF_RESOURCES Failed to allocate resources for the packet
  73. @retval EFI_ACCESS_DENIED Failed to transmit the packet through UDP
  74. @retval EFI_SUCCESS The message is sent
  75. @retval other Other error occurs
  76. **/
  77. EFI_STATUS
  78. DhcpSendMessage (
  79. IN DHCP_SERVICE *DhcpSb,
  80. IN EFI_DHCP4_PACKET *Seed,
  81. IN DHCP_PARAMETER *Para,
  82. IN UINT8 Type,
  83. IN UINT8 *Msg
  84. );
  85. /**
  86. Each DHCP service has three timer. Two of them are count down timer.
  87. One for the packet retransmission. The other is to collect the offers.
  88. The third timer increments the lease life which is compared to T1, T2,
  89. and lease to determine the time to renew and rebind the lease.
  90. DhcpOnTimerTick will be called once every second.
  91. @param[in] Event The timer event
  92. @param[in] Context The context, which is the DHCP service instance.
  93. **/
  94. VOID
  95. EFIAPI
  96. DhcpOnTimerTick (
  97. IN EFI_EVENT Event,
  98. IN VOID *Context
  99. );
  100. /**
  101. Handle the received DHCP packets. This function drives the DHCP
  102. state machine.
  103. @param UdpPacket The UDP packets received.
  104. @param EndPoint The local/remote UDP access point
  105. @param IoStatus The status of the UDP receive
  106. @param Context The opaque parameter to the function.
  107. **/
  108. VOID
  109. EFIAPI
  110. DhcpInput (
  111. NET_BUF *UdpPacket,
  112. UDP_END_POINT *EndPoint,
  113. EFI_STATUS IoStatus,
  114. VOID *Context
  115. );
  116. /**
  117. Send an initial DISCOVER or REQUEST message according to the
  118. DHCP service's current state.
  119. @param[in] DhcpSb The DHCP service instance
  120. @retval EFI_SUCCESS The request has been sent
  121. @retval other Some error occurs when sending the request.
  122. **/
  123. EFI_STATUS
  124. DhcpInitRequest (
  125. IN DHCP_SERVICE *DhcpSb
  126. );
  127. /**
  128. Clean up the DHCP related states, IoStatus isn't reset.
  129. @param DhcpSb The DHCP instance service.
  130. **/
  131. VOID
  132. DhcpCleanLease (
  133. IN DHCP_SERVICE *DhcpSb
  134. );
  135. /**
  136. Release the net buffer when packet is sent.
  137. @param UdpPacket The UDP packets received.
  138. @param EndPoint The local/remote UDP access point
  139. @param IoStatus The status of the UDP receive
  140. @param Context The opaque parameter to the function.
  141. **/
  142. VOID
  143. EFIAPI
  144. DhcpOnPacketSent (
  145. NET_BUF *Packet,
  146. UDP_END_POINT *EndPoint,
  147. EFI_STATUS IoStatus,
  148. VOID *Context
  149. );
  150. #endif