dhcpserver.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. // Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. // http://www.apache.org/licenses/LICENSE-2.0
  7. //
  8. // Unless required by applicable law or agreed to in writing, software
  9. // distributed under the License is distributed on an "AS IS" BASIS,
  10. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. // See the License for the specific language governing permissions and
  12. // limitations under the License.
  13. #ifndef __DHCPS_H__
  14. #define __DHCPS_H__
  15. #include "sdkconfig.h"
  16. #include "lwip/ip_addr.h"
  17. #ifdef __cplusplus
  18. extern "C" {
  19. #endif
  20. typedef struct dhcps_state{
  21. s16_t state;
  22. } dhcps_state;
  23. typedef struct dhcps_msg {
  24. u8_t op, htype, hlen, hops;
  25. u8_t xid[4];
  26. u16_t secs, flags;
  27. u8_t ciaddr[4];
  28. u8_t yiaddr[4];
  29. u8_t siaddr[4];
  30. u8_t giaddr[4];
  31. u8_t chaddr[16];
  32. u8_t sname[64];
  33. u8_t file[128];
  34. u8_t options[312];
  35. }dhcps_msg;
  36. /* Defined in esp_misc.h */
  37. typedef struct {
  38. bool enable;
  39. ip4_addr_t start_ip;
  40. ip4_addr_t end_ip;
  41. } dhcps_lease_t;
  42. enum dhcps_offer_option{
  43. OFFER_START = 0x00,
  44. OFFER_ROUTER = 0x01,
  45. OFFER_DNS = 0x02,
  46. OFFER_END
  47. };
  48. #define DHCPS_COARSE_TIMER_SECS 1
  49. #define DHCPS_MAX_LEASE 0x64
  50. #define DHCPS_LEASE_TIME_DEF (120)
  51. #define DHCPS_LEASE_UNIT CONFIG_LWIP_DHCPS_LEASE_UNIT
  52. struct dhcps_pool{
  53. ip4_addr_t ip;
  54. u8_t mac[6];
  55. u32_t lease_timer;
  56. };
  57. typedef u32_t dhcps_time_t;
  58. typedef u8_t dhcps_offer_t;
  59. typedef struct {
  60. dhcps_offer_t dhcps_offer;
  61. dhcps_offer_t dhcps_dns;
  62. dhcps_time_t dhcps_time;
  63. dhcps_lease_t dhcps_poll;
  64. } dhcps_options_t;
  65. typedef void (*dhcps_cb_t)(u8_t client_ip[4]);
  66. static inline bool dhcps_router_enabled (dhcps_offer_t offer)
  67. {
  68. return (offer & OFFER_ROUTER) != 0;
  69. }
  70. static inline bool dhcps_dns_enabled (dhcps_offer_t offer)
  71. {
  72. return (offer & OFFER_DNS) != 0;
  73. }
  74. void dhcps_start(struct netif *netif, ip4_addr_t ip);
  75. void dhcps_stop(struct netif *netif);
  76. void *dhcps_option_info(u8_t op_id, u32_t opt_len);
  77. void dhcps_set_option_info(u8_t op_id, void *opt_info, u32_t opt_len);
  78. bool dhcp_search_ip_on_mac(u8_t *mac, ip4_addr_t *ip);
  79. void dhcps_dns_setserver(const ip_addr_t *dnsserver);
  80. ip4_addr_t dhcps_dns_getserver(void);
  81. void dhcps_set_new_lease_cb(dhcps_cb_t cb);
  82. #ifdef __cplusplus
  83. }
  84. #endif
  85. #endif /* __DHCPS_H__ */