dhcpserver.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. typedef struct dhcps_state{
  18. s16_t state;
  19. } dhcps_state;
  20. typedef struct dhcps_msg {
  21. u8_t op, htype, hlen, hops;
  22. u8_t xid[4];
  23. u16_t secs, flags;
  24. u8_t ciaddr[4];
  25. u8_t yiaddr[4];
  26. u8_t siaddr[4];
  27. u8_t giaddr[4];
  28. u8_t chaddr[16];
  29. u8_t sname[64];
  30. u8_t file[128];
  31. u8_t options[312];
  32. }dhcps_msg;
  33. /* Defined in esp_misc.h */
  34. typedef struct {
  35. bool enable;
  36. ip4_addr_t start_ip;
  37. ip4_addr_t end_ip;
  38. } dhcps_lease_t;
  39. enum dhcps_offer_option{
  40. OFFER_START = 0x00,
  41. OFFER_ROUTER = 0x01,
  42. OFFER_DNS = 0x02,
  43. OFFER_END
  44. };
  45. #define DHCPS_COARSE_TIMER_SECS 1
  46. #define DHCPS_MAX_LEASE 0x64
  47. #define DHCPS_LEASE_TIME_DEF (120)
  48. #define DHCPS_LEASE_UNIT CONFIG_LWIP_DHCPS_LEASE_UNIT
  49. struct dhcps_pool{
  50. ip4_addr_t ip;
  51. u8_t mac[6];
  52. u32_t lease_timer;
  53. };
  54. typedef u32_t dhcps_time_t;
  55. typedef u8_t dhcps_offer_t;
  56. typedef struct {
  57. dhcps_offer_t dhcps_offer;
  58. dhcps_offer_t dhcps_dns;
  59. dhcps_time_t dhcps_time;
  60. dhcps_lease_t dhcps_poll;
  61. } dhcps_options_t;
  62. typedef void (*dhcps_cb_t)(u8_t client_ip[4]);
  63. static inline bool dhcps_router_enabled (dhcps_offer_t offer)
  64. {
  65. return (offer & OFFER_ROUTER) != 0;
  66. }
  67. static inline bool dhcps_dns_enabled (dhcps_offer_t offer)
  68. {
  69. return (offer & OFFER_DNS) != 0;
  70. }
  71. void dhcps_start(struct netif *netif, ip4_addr_t ip);
  72. void dhcps_stop(struct netif *netif);
  73. void *dhcps_option_info(u8_t op_id, u32_t opt_len);
  74. void dhcps_set_option_info(u8_t op_id, void *opt_info, u32_t opt_len);
  75. bool dhcp_search_ip_on_mac(u8_t *mac, ip4_addr_t *ip);
  76. void dhcps_dns_setserver(const ip_addr_t *dnsserver);
  77. ip4_addr_t dhcps_dns_getserver();
  78. void dhcps_set_new_lease_cb(dhcps_cb_t cb);
  79. #endif