]> granicus.if.org Git - esp-idf/blob - components/lwip/include/lwip/apps/dhcpserver.h
tcpip_adapter/lwip: make dhcp domain name server option configurable
[esp-idf] / components / lwip / include / lwip / apps / dhcpserver.h
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 "lwip/ip_addr.h"
18
19 typedef struct dhcps_state{
20         s16_t state;
21 } dhcps_state;
22
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
37 /*   Defined in esp_misc.h */
38 typedef struct {
39         bool enable;
40         ip4_addr_t start_ip;
41         ip4_addr_t end_ip;
42 } dhcps_lease_t;
43
44 enum dhcps_offer_option{
45         OFFER_START = 0x00,
46         OFFER_ROUTER = 0x01,
47         OFFER_DNS = 0x02,
48         OFFER_END
49 };
50
51 #define DHCPS_COARSE_TIMER_SECS  1
52 #define DHCPS_MAX_LEASE 0x64
53 #define DHCPS_LEASE_TIME_DEF    (120)
54
55 struct dhcps_pool{
56         ip4_addr_t ip;
57         u8_t mac[6];
58         u32_t lease_timer;
59 };
60
61 typedef u32_t dhcps_time_t;
62 typedef u8_t dhcps_offer_t;
63
64 typedef struct {
65         dhcps_offer_t dhcps_offer;
66         dhcps_offer_t dhcps_dns;
67         dhcps_time_t  dhcps_time;
68         dhcps_lease_t dhcps_poll;
69 } dhcps_options_t;
70
71 static inline bool dhcps_router_enabled (dhcps_offer_t offer) 
72 {
73     return (offer & OFFER_ROUTER) != 0;
74 }
75
76 static inline bool dhcps_dns_enabled (dhcps_offer_t offer) 
77 {
78     return (offer & OFFER_DNS) != 0;
79 }
80
81 void dhcps_start(struct netif *netif, ip4_addr_t ip);
82 void dhcps_stop(struct netif *netif);
83 void *dhcps_option_info(u8_t op_id, u32_t opt_len);
84 void dhcps_set_option_info(u8_t op_id, void *opt_info, u32_t opt_len);
85 bool dhcp_search_ip_on_mac(u8_t *mac, ip4_addr_t *ip);
86 void dhcps_dns_setserver(const ip_addr_t *dnsserver);
87 ip4_addr_t dhcps_dns_getserver();
88
89 #endif
90