2016-08-17 11:08:22 -04:00
|
|
|
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
#ifndef __DHCPS_H__
|
|
|
|
#define __DHCPS_H__
|
|
|
|
|
2017-10-31 14:13:04 -04:00
|
|
|
#include "sdkconfig.h"
|
2016-08-17 11:08:22 -04:00
|
|
|
#include "lwip/ip_addr.h"
|
|
|
|
|
2021-08-31 04:26:55 -04:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2016-08-17 11:08:22 -04:00
|
|
|
typedef struct dhcps_state{
|
|
|
|
s16_t state;
|
|
|
|
} dhcps_state;
|
|
|
|
|
|
|
|
typedef struct dhcps_msg {
|
|
|
|
u8_t op, htype, hlen, hops;
|
|
|
|
u8_t xid[4];
|
|
|
|
u16_t secs, flags;
|
|
|
|
u8_t ciaddr[4];
|
|
|
|
u8_t yiaddr[4];
|
|
|
|
u8_t siaddr[4];
|
|
|
|
u8_t giaddr[4];
|
|
|
|
u8_t chaddr[16];
|
|
|
|
u8_t sname[64];
|
|
|
|
u8_t file[128];
|
|
|
|
u8_t options[312];
|
|
|
|
}dhcps_msg;
|
|
|
|
|
2016-09-06 01:02:02 -04:00
|
|
|
/* Defined in esp_misc.h */
|
|
|
|
typedef struct {
|
|
|
|
bool enable;
|
|
|
|
ip4_addr_t start_ip;
|
|
|
|
ip4_addr_t end_ip;
|
|
|
|
} dhcps_lease_t;
|
2016-08-17 11:08:22 -04:00
|
|
|
|
2016-08-26 02:15:14 -04:00
|
|
|
enum dhcps_offer_option{
|
|
|
|
OFFER_START = 0x00,
|
|
|
|
OFFER_ROUTER = 0x01,
|
2017-06-07 09:22:53 -04:00
|
|
|
OFFER_DNS = 0x02,
|
2016-08-26 02:15:14 -04:00
|
|
|
OFFER_END
|
2016-08-17 11:08:22 -04:00
|
|
|
};
|
|
|
|
|
2017-04-19 04:18:07 -04:00
|
|
|
#define DHCPS_COARSE_TIMER_SECS 1
|
2016-08-26 02:15:14 -04:00
|
|
|
#define DHCPS_MAX_LEASE 0x64
|
2017-10-31 14:13:04 -04:00
|
|
|
#define DHCPS_LEASE_TIME_DEF (120)
|
|
|
|
#define DHCPS_LEASE_UNIT CONFIG_LWIP_DHCPS_LEASE_UNIT
|
2016-08-17 11:08:22 -04:00
|
|
|
|
2016-08-26 02:15:14 -04:00
|
|
|
struct dhcps_pool{
|
|
|
|
ip4_addr_t ip;
|
|
|
|
u8_t mac[6];
|
|
|
|
u32_t lease_timer;
|
|
|
|
};
|
2016-08-17 11:08:22 -04:00
|
|
|
|
2016-08-26 02:15:14 -04:00
|
|
|
typedef u32_t dhcps_time_t;
|
|
|
|
typedef u8_t dhcps_offer_t;
|
2016-09-04 21:50:53 -04:00
|
|
|
|
2016-09-06 01:02:02 -04:00
|
|
|
typedef struct {
|
2017-06-07 09:22:53 -04:00
|
|
|
dhcps_offer_t dhcps_offer;
|
|
|
|
dhcps_offer_t dhcps_dns;
|
|
|
|
dhcps_time_t dhcps_time;
|
|
|
|
dhcps_lease_t dhcps_poll;
|
2016-09-06 01:02:02 -04:00
|
|
|
} dhcps_options_t;
|
2016-08-17 11:08:22 -04:00
|
|
|
|
2018-04-08 23:01:44 -04:00
|
|
|
typedef void (*dhcps_cb_t)(u8_t client_ip[4]);
|
|
|
|
|
2017-06-07 09:22:53 -04:00
|
|
|
static inline bool dhcps_router_enabled (dhcps_offer_t offer)
|
|
|
|
{
|
|
|
|
return (offer & OFFER_ROUTER) != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool dhcps_dns_enabled (dhcps_offer_t offer)
|
|
|
|
{
|
|
|
|
return (offer & OFFER_DNS) != 0;
|
|
|
|
}
|
2016-09-06 01:02:02 -04:00
|
|
|
|
|
|
|
void dhcps_start(struct netif *netif, ip4_addr_t ip);
|
2016-08-17 11:08:22 -04:00
|
|
|
void dhcps_stop(struct netif *netif);
|
2016-08-26 02:15:14 -04:00
|
|
|
void *dhcps_option_info(u8_t op_id, u32_t opt_len);
|
2017-06-07 09:22:53 -04:00
|
|
|
void dhcps_set_option_info(u8_t op_id, void *opt_info, u32_t opt_len);
|
2016-08-26 02:15:14 -04:00
|
|
|
bool dhcp_search_ip_on_mac(u8_t *mac, ip4_addr_t *ip);
|
2017-06-07 09:22:53 -04:00
|
|
|
void dhcps_dns_setserver(const ip_addr_t *dnsserver);
|
2019-07-16 05:33:30 -04:00
|
|
|
ip4_addr_t dhcps_dns_getserver(void);
|
2018-04-08 23:01:44 -04:00
|
|
|
void dhcps_set_new_lease_cb(dhcps_cb_t cb);
|
2016-08-17 11:08:22 -04:00
|
|
|
|
2021-08-31 04:26:55 -04:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
2016-08-17 11:08:22 -04:00
|
|
|
#endif
|
2016-08-26 02:15:14 -04:00
|
|
|
|
2021-08-31 04:26:55 -04:00
|
|
|
#endif /* __DHCPS_H__ */
|