FreeRTOS_DHCP.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. * FreeRTOS+TCP V2.3.2 LTS Patch 1
  3. * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a copy of
  6. * this software and associated documentation files (the "Software"), to deal in
  7. * the Software without restriction, including without limitation the rights to
  8. * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  9. * the Software, and to permit persons to whom the Software is furnished to do so,
  10. * subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be included in all
  13. * copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  17. * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  18. * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  19. * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  20. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  21. *
  22. * http://aws.amazon.com/freertos
  23. * http://www.FreeRTOS.org
  24. */
  25. #ifndef FREERTOS_DHCP_H
  26. #define FREERTOS_DHCP_H
  27. #ifdef __cplusplus
  28. extern "C" {
  29. #endif
  30. /* Application level configuration options. */
  31. #include "FreeRTOSIPConfig.h"
  32. #include "IPTraceMacroDefaults.h"
  33. #if ( ipconfigUSE_DHCP_HOOK != 0 )
  34. /* Used in the DHCP callback if ipconfigUSE_DHCP_HOOK is set to 1. */
  35. typedef enum eDHCP_PHASE
  36. {
  37. eDHCPPhasePreDiscover, /* Driver is about to send a DHCP discovery. */
  38. eDHCPPhasePreRequest, /* Driver is about to request DHCP an IP address. */
  39. eDHCPPhaseFinished
  40. } eDHCPCallbackPhase_t;
  41. /* Used in the DHCP callback if ipconfigUSE_DHCP_HOOK is set to 1. */
  42. typedef enum eDHCP_ANSWERS
  43. {
  44. eDHCPContinue, /* Continue the DHCP process */
  45. eDHCPUseDefaults, /* Stop DHCP and use the static defaults. */
  46. eDHCPStopNoChanges, /* Stop DHCP and continue with current settings. */
  47. } eDHCPCallbackAnswer_t;
  48. #endif /* #if( ipconfigUSE_DHCP_HOOK != 0 ) */
  49. /* DHCP state machine states. */
  50. typedef enum
  51. {
  52. eInitialWait = 0, /**< Initial state: open a socket and wait a short time. */
  53. eWaitingSendFirstDiscover, /**< Send a discover the first time it is called, and reset all timers. */
  54. eWaitingOffer, /**< Either resend the discover, or, if the offer is forthcoming, send a request. */
  55. eWaitingAcknowledge, /**< Either resend the request. */
  56. eSendDHCPRequest, /**< Sendto failed earlier, resend the request to lease the IP-address offered. */
  57. #if ( ipconfigDHCP_FALL_BACK_AUTO_IP != 0 )
  58. eGetLinkLayerAddress, /* When DHCP didn't respond, try to obtain a LinkLayer address 168.254.x.x. */
  59. #endif
  60. eLeasedAddress, /**< Resend the request at the appropriate time to renew the lease. */
  61. eNotUsingLeasedAddress /**< DHCP failed, and a default IP address is being used. */
  62. } eDHCPState_t;
  63. /**
  64. * Hold information in between steps in the DHCP state machine.
  65. */
  66. struct xDHCP_DATA
  67. {
  68. uint32_t ulTransactionId; /**< The ID of the DHCP transaction */
  69. uint32_t ulOfferedIPAddress; /**< The IP address offered by the DHCP server */
  70. uint32_t ulDHCPServerAddress; /**< The IP address of the DHCP server */
  71. uint32_t ulLeaseTime; /**< The time for which the current IP address is leased */
  72. TickType_t xDHCPTxTime; /**< The time at which a DHCP request was sent. */
  73. TickType_t xDHCPTxPeriod; /**< The maximum time that the client will wait for a reply. */
  74. BaseType_t xUseBroadcast; /**< Try both without and with the broadcast flag */
  75. eDHCPState_t eDHCPState; /**< Maintains the DHCP state machine state. */
  76. };
  77. typedef struct xDHCP_DATA DHCPData_t;
  78. /* Returns the current state of a DHCP process. */
  79. eDHCPState_t eGetDHCPState( void );
  80. /*
  81. * Send a message to the IP-task, which will call vDHCPProcess().
  82. *
  83. */
  84. BaseType_t xSendDHCPEvent( void );
  85. /*
  86. * NOT A PUBLIC API FUNCTION.
  87. * It will be called when the DHCP timer expires, or when
  88. * data has been received on the DHCP socket.
  89. */
  90. void vDHCPProcess( BaseType_t xReset,
  91. eDHCPState_t eExpectedState );
  92. /* Internal call: returns true if socket is the current DHCP socket */
  93. BaseType_t xIsDHCPSocket( Socket_t xSocket );
  94. #if ( ipconfigUSE_DHCP_HOOK != 0 )
  95. /* Prototype of the hook (or callback) function that must be provided by the
  96. * application if ipconfigUSE_DHCP_HOOK is set to 1. See the following URL for
  97. * usage information:
  98. * http://www.FreeRTOS.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigUSE_DHCP_HOOK
  99. */
  100. eDHCPCallbackAnswer_t xApplicationDHCPHook( eDHCPCallbackPhase_t eDHCPPhase,
  101. uint32_t ulIPAddress );
  102. #endif /* ( ipconfigUSE_DHCP_HOOK != 0 ) */
  103. #ifdef __cplusplus
  104. } /* extern "C" */
  105. #endif
  106. #endif /* FREERTOS_DHCP_H */