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