mirror of
https://github.com/espressif/ESP8266_RTOS_SDK.git
synced 2025-06-28 04:42:11 +08:00
feat(lwip): Bring lwip sub from esp-idf
Commit ID: 785cc699
This commit is contained in:
95
components/lwip/include/apps/dhcpserver/dhcpserver.h
Normal file
95
components/lwip/include/apps/dhcpserver/dhcpserver.h
Normal file
@ -0,0 +1,95 @@
|
||||
// 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__
|
||||
|
||||
#include "sdkconfig.h"
|
||||
#include "lwip/ip_addr.h"
|
||||
|
||||
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;
|
||||
|
||||
/* Defined in esp_misc.h */
|
||||
typedef struct {
|
||||
bool enable;
|
||||
ip4_addr_t start_ip;
|
||||
ip4_addr_t end_ip;
|
||||
} dhcps_lease_t;
|
||||
|
||||
enum dhcps_offer_option{
|
||||
OFFER_START = 0x00,
|
||||
OFFER_ROUTER = 0x01,
|
||||
OFFER_DNS = 0x02,
|
||||
OFFER_END
|
||||
};
|
||||
|
||||
#define DHCPS_COARSE_TIMER_SECS 1
|
||||
#define DHCPS_MAX_LEASE 0x64
|
||||
#define DHCPS_LEASE_TIME_DEF (120)
|
||||
#define DHCPS_LEASE_UNIT CONFIG_LWIP_DHCPS_LEASE_UNIT
|
||||
|
||||
struct dhcps_pool{
|
||||
ip4_addr_t ip;
|
||||
u8_t mac[6];
|
||||
u32_t lease_timer;
|
||||
};
|
||||
|
||||
typedef u32_t dhcps_time_t;
|
||||
typedef u8_t dhcps_offer_t;
|
||||
|
||||
typedef struct {
|
||||
dhcps_offer_t dhcps_offer;
|
||||
dhcps_offer_t dhcps_dns;
|
||||
dhcps_time_t dhcps_time;
|
||||
dhcps_lease_t dhcps_poll;
|
||||
} dhcps_options_t;
|
||||
|
||||
typedef void (*dhcps_cb_t)(u8_t client_ip[4]);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
void dhcps_start(struct netif *netif, ip4_addr_t ip);
|
||||
void dhcps_stop(struct netif *netif);
|
||||
void *dhcps_option_info(u8_t op_id, u32_t opt_len);
|
||||
void dhcps_set_option_info(u8_t op_id, void *opt_info, u32_t opt_len);
|
||||
bool dhcp_search_ip_on_mac(u8_t *mac, ip4_addr_t *ip);
|
||||
void dhcps_dns_setserver(const ip_addr_t *dnsserver);
|
||||
ip4_addr_t dhcps_dns_getserver(void);
|
||||
void dhcps_set_new_lease_cb(dhcps_cb_t cb);
|
||||
|
||||
#endif
|
||||
|
134
components/lwip/include/apps/dhcpserver/dhcpserver_options.h
Normal file
134
components/lwip/include/apps/dhcpserver/dhcpserver_options.h
Normal file
@ -0,0 +1,134 @@
|
||||
// Copyright 2017 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.
|
||||
#pragma once
|
||||
|
||||
/** DHCP Options
|
||||
|
||||
This macros are not part of the public dhcpserver.h interface.
|
||||
**/
|
||||
typedef enum
|
||||
{
|
||||
/* RFC 1497 Vendor Extensions */
|
||||
|
||||
PAD = 0,
|
||||
END = 255,
|
||||
|
||||
SUBNET_MASK = 1,
|
||||
TIME_OFFSET = 2,
|
||||
ROUTER = 3,
|
||||
TIME_SERVER = 4,
|
||||
NAME_SERVER = 5,
|
||||
DOMAIN_NAME_SERVER = 6,
|
||||
LOG_SERVER = 7,
|
||||
COOKIE_SERVER = 8,
|
||||
LPR_SERVER = 9,
|
||||
IMPRESS_SERVER = 10,
|
||||
RESOURCE_LOCATION_SERVER = 11,
|
||||
HOST_NAME = 12,
|
||||
BOOT_FILE_SIZE = 13,
|
||||
MERIT_DUMP_FILE = 14,
|
||||
DOMAIN_NAME = 15,
|
||||
SWAP_SERVER = 16,
|
||||
ROOT_PATH = 17,
|
||||
EXTENSIONS_PATH = 18,
|
||||
|
||||
/* IP Layer Parameters per Host */
|
||||
|
||||
IP_FORWARDING = 19,
|
||||
NON_LOCAL_SOURCE_ROUTING = 20,
|
||||
POLICY_FILTER = 21,
|
||||
MAXIMUM_DATAGRAM_REASSEMBLY_SIZE = 22,
|
||||
DEFAULT_IP_TIME_TO_LIVE = 23,
|
||||
PATH_MTU_AGING_TIMEOUT = 24,
|
||||
PATH_MTU_PLATEAU_TABLE = 25,
|
||||
|
||||
/* IP Layer Parameters per Interface */
|
||||
|
||||
INTERFACE_MTU = 26,
|
||||
ALL_SUBNETS_ARE_LOCAL = 27,
|
||||
BROADCAST_ADDRESS = 28,
|
||||
PERFORM_MASK_DISCOVERY = 29,
|
||||
MASK_SUPPLIER = 30,
|
||||
PERFORM_ROUTER_DISCOVERY = 31,
|
||||
ROUTER_SOLICITATION_ADDRESS = 32,
|
||||
STATIC_ROUTE = 33,
|
||||
|
||||
/* Link Layer Parameters per Interface */
|
||||
|
||||
TRAILER_ENCAPSULATION = 34,
|
||||
ARP_CACHE_TIMEOUT = 35,
|
||||
ETHERNET_ENCAPSULATION = 36,
|
||||
|
||||
/* TCP Parameters */
|
||||
|
||||
TCP_DEFAULT_TTL = 37,
|
||||
TCP_KEEPALIVE_INTERVAL = 38,
|
||||
TCP_KEEPALIVE_GARBAGE = 39,
|
||||
|
||||
/* Application and Service Parameters */
|
||||
|
||||
NETWORK_INFORMATION_SERVICE_DOMAIN = 40,
|
||||
NETWORK_INFORMATION_SERVERS = 41,
|
||||
NETWORK_TIME_PROTOCOL_SERVERS = 42,
|
||||
VENDOR_SPECIFIC_INFORMATION = 43,
|
||||
NETBIOS_OVER_TCP_IP_NAME_SERVER = 44,
|
||||
NETBIOS_OVER_TCP_IP_DATAGRAM_DISTRIBUTION_SERVER = 45,
|
||||
NETBIOS_OVER_TCP_IP_NODE_TYPE = 46,
|
||||
NETBIOS_OVER_TCP_IP_SCOPE = 47,
|
||||
X_WINDOW_SYSTEM_FONT_SERVER = 48,
|
||||
X_WINDOW_SYSTEM_DISPLAY_MANAGER = 49,
|
||||
NETWORK_INFORMATION_SERVICE_PLUS_DOMAIN = 64,
|
||||
NETWORK_INFORMATION_SERVICE_PLUS_SERVERS = 65,
|
||||
MOBILE_IP_HOME_AGENT = 68,
|
||||
SMTP_SERVER = 69,
|
||||
POP3_SERVER = 70,
|
||||
NNTP_SERVER = 71,
|
||||
DEFAULT_WWW_SERVER = 72,
|
||||
DEFAULT_FINGER_SERVER = 73,
|
||||
DEFAULT_IRC_SERVER = 74,
|
||||
STREETTALK_SERVER = 75,
|
||||
STREETTALK_DIRECTORY_ASSISTANCE_SERVER = 76,
|
||||
|
||||
/* DHCP Extensions */
|
||||
|
||||
REQUESTED_IP_ADDRESS = 50,
|
||||
IP_ADDRESS_LEASE_TIME = 51,
|
||||
OPTION_OVERLOAD = 52,
|
||||
TFTP_SERVER_NAME = 66,
|
||||
BOOTFILE_NAME = 67,
|
||||
DHCP_MESSAGE_TYPE = 53,
|
||||
SERVER_IDENTIFIER = 54,
|
||||
PARAMETER_REQUEST_LIST = 55,
|
||||
MESSAGE = 56,
|
||||
MAXIMUM_DHCP_MESSAGE_SIZE = 57,
|
||||
RENEWAL_T1_TIME_VALUE = 58,
|
||||
REBINDING_T2_TIME_VALUE = 59,
|
||||
VENDOR_CLASS_IDENTIFIER = 60,
|
||||
CLIENT_IDENTIFIER = 61,
|
||||
|
||||
USER_CLASS = 77,
|
||||
FQDN = 81,
|
||||
DHCP_AGENT_OPTIONS = 82,
|
||||
NDS_SERVERS = 85,
|
||||
NDS_TREE_NAME = 86,
|
||||
NDS_CONTEXT = 87,
|
||||
CLIENT_LAST_TRANSACTION_TIME = 91,
|
||||
ASSOCIATED_IP = 92,
|
||||
USER_AUTHENTICATION_PROTOCOL = 98,
|
||||
AUTO_CONFIGURE = 116,
|
||||
NAME_SERVICE_SEARCH = 117,
|
||||
SUBNET_SELECTION = 118,
|
||||
DOMAIN_SEARCH = 119,
|
||||
CLASSLESS_ROUTE = 121,
|
||||
} dhcp_msg_option;
|
111
components/lwip/include/apps/esp_ping.h
Normal file
111
components/lwip/include/apps/esp_ping.h
Normal file
@ -0,0 +1,111 @@
|
||||
// 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 ESP_PING_H_
|
||||
#define ESP_PING_H_
|
||||
|
||||
#include "esp_err.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// gen_esp_err_to_name.py: include this as "esp_ping.h" because "components/lwip/include/apps/" is in the compiler path
|
||||
// and not "components/lwip/include"
|
||||
|
||||
#define ESP_ERR_PING_BASE 0xa000
|
||||
|
||||
#define ESP_ERR_PING_INVALID_PARAMS ESP_ERR_PING_BASE + 0x01
|
||||
#define ESP_ERR_PING_NO_MEM ESP_ERR_PING_BASE + 0x02
|
||||
|
||||
#define ESP_PING_CHECK_OPTLEN(optlen, opttype) do { if ((optlen) < sizeof(opttype)) { return ESP_ERR_PING_INVALID_PARAMS; }}while(0)
|
||||
|
||||
typedef struct _ping_found {
|
||||
uint32_t resp_time;
|
||||
uint32_t timeout_count;
|
||||
uint32_t send_count;
|
||||
uint32_t recv_count;
|
||||
uint32_t err_count;
|
||||
uint32_t bytes;
|
||||
uint32_t total_bytes;
|
||||
uint32_t total_time;
|
||||
uint32_t min_time;
|
||||
uint32_t max_time;
|
||||
int8_t ping_err;
|
||||
} esp_ping_found;
|
||||
|
||||
typedef enum {
|
||||
PING_TARGET_IP_ADDRESS = 50, /**< target IP address */
|
||||
PING_TARGET_IP_ADDRESS_COUNT = 51, /**< target IP address total counter */
|
||||
PING_TARGET_RCV_TIMEO = 52, /**< receive timeout in milliseconds */
|
||||
PING_TARGET_DELAY_TIME = 53, /**< delay time in milliseconds */
|
||||
PING_TARGET_ID = 54, /**< identifier */
|
||||
PING_TARGET_RES_FN = 55, /**< ping result callback function */
|
||||
PING_TARGET_RES_RESET = 56, /**< ping result statistic reset */
|
||||
PING_TARGET_DATA_LEN = 57, /**< ping data length*/
|
||||
PING_TARGET_IP_TOS = 58 /**< ping QOS*/
|
||||
} ping_target_id_t;
|
||||
|
||||
typedef enum {
|
||||
PING_RES_TIMEOUT = 0,
|
||||
PING_RES_OK = 1,
|
||||
PING_RES_FINISH = 2,
|
||||
} ping_res_t;
|
||||
|
||||
typedef void (* esp_ping_found_fn)(ping_target_id_t found_id, esp_ping_found *found_val);
|
||||
|
||||
/**
|
||||
* @brief Set PING function option
|
||||
*
|
||||
* @param[in] opt_id: option index, 50 for IP, 51 for COUNT, 52 for RCV TIMEOUT, 53 for DELAY TIME, 54 for ID
|
||||
* @param[in] opt_val: option parameter
|
||||
* @param[in] opt_len: option length
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK
|
||||
* - ESP_ERR_PING_INVALID_PARAMS
|
||||
*/
|
||||
esp_err_t esp_ping_set_target(ping_target_id_t opt_id, void *opt_val, uint32_t opt_len);
|
||||
|
||||
/**
|
||||
* @brief Get PING function option
|
||||
*
|
||||
* @param[in] opt_id: option index, 50 for IP, 51 for COUNT, 52 for RCV TIMEOUT, 53 for DELAY TIME, 54 for ID
|
||||
* @param[in] opt_val: option parameter
|
||||
* @param[in] opt_len: option length
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK
|
||||
* - ESP_ERR_PING_INVALID_PARAMS
|
||||
*/
|
||||
esp_err_t esp_ping_get_target(ping_target_id_t opt_id, void *opt_val, uint32_t opt_len);
|
||||
|
||||
/**
|
||||
* @brief Get PING function result action
|
||||
*
|
||||
* @param[in] res_val: ping function action, 1 for successful, 0 for fail.
|
||||
* res_len: response bytes
|
||||
* res_time: response time
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK
|
||||
* - ESP_ERR_PING_INVALID_PARAMS
|
||||
*/
|
||||
esp_err_t esp_ping_result(uint8_t res_val, uint16_t res_len, uint32_t res_time);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* ESP_PING_H_ */
|
22
components/lwip/include/apps/esp_sntp.h
Normal file
22
components/lwip/include/apps/esp_sntp.h
Normal file
@ -0,0 +1,22 @@
|
||||
// Copyright 2015-2019 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 __ESP_SNTP_H__
|
||||
#define __ESP_SNTP_H__
|
||||
|
||||
#include "lwip/err.h"
|
||||
#include "lwip/apps/sntp.h"
|
||||
#include "sntp.h"
|
||||
|
||||
#endif // __ESP_SNTP_H__
|
60
components/lwip/include/apps/ping/ping.h
Normal file
60
components/lwip/include/apps/ping/ping.h
Normal file
@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright (c) 2001-2004 Swedish Institute of Computer Science.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
|
||||
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
||||
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
|
||||
* OF SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the lwIP TCP/IP stack.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef LWIP_PING_H
|
||||
#define LWIP_PING_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* PING_USE_SOCKETS: Set to 1 to use sockets, otherwise the raw api is used
|
||||
*/
|
||||
#ifndef PING_USE_SOCKETS
|
||||
#define PING_USE_SOCKETS LWIP_SOCKET
|
||||
#endif
|
||||
|
||||
|
||||
int ping_init(void) __attribute__ ((deprecated));
|
||||
|
||||
#ifdef ESP_PING
|
||||
void ping_deinit(void) __attribute__ ((deprecated));
|
||||
#endif
|
||||
|
||||
#if !PING_USE_SOCKETS
|
||||
void ping_send_now(void);
|
||||
#endif /* !PING_USE_SOCKETS */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* LWIP_PING_H */
|
169
components/lwip/include/apps/ping/ping_sock.h
Normal file
169
components/lwip/include/apps/ping/ping_sock.h
Normal file
@ -0,0 +1,169 @@
|
||||
// Copyright 2019 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.
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
#include "esp_err.h"
|
||||
#include "lwip/ip_addr.h"
|
||||
|
||||
/**
|
||||
* @brief Type of "ping" session handle
|
||||
*
|
||||
*/
|
||||
typedef void *esp_ping_handle_t;
|
||||
|
||||
/**
|
||||
* @brief Type of "ping" callback functions
|
||||
*
|
||||
*/
|
||||
typedef struct {
|
||||
/**
|
||||
* @brief arguments for callback functions
|
||||
*
|
||||
*/
|
||||
void *cb_args;
|
||||
|
||||
/**
|
||||
* @brief Invoked by internal ping thread when received ICMP echo reply packet
|
||||
*
|
||||
*/
|
||||
void (*on_ping_success)(esp_ping_handle_t hdl, void *args);
|
||||
|
||||
/**
|
||||
* @brief Invoked by internal ping thread when receive ICMP echo reply packet timeout
|
||||
*
|
||||
*/
|
||||
void (*on_ping_timeout)(esp_ping_handle_t hdl, void *args);
|
||||
|
||||
/**
|
||||
* @brief Invoked by internal ping thread when a ping session is finished
|
||||
*
|
||||
*/
|
||||
void (*on_ping_end)(esp_ping_handle_t hdl, void *args);
|
||||
} esp_ping_callbacks_t;
|
||||
|
||||
/**
|
||||
* @brief Type of "ping" configuration
|
||||
*
|
||||
*/
|
||||
typedef struct {
|
||||
uint32_t count; /*!< A "ping" session contains count procedures */
|
||||
uint32_t interval_ms; /*!< Milliseconds between each ping procedure */
|
||||
uint32_t timeout_ms; /*!< Timeout value (in milliseconds) of each ping procedure */
|
||||
uint32_t data_size; /*!< Size of the data next to ICMP packet header */
|
||||
uint8_t tos; /*!< Type of Service, a field specified in the IP header */
|
||||
ip_addr_t target_addr; /*!< Target IP address, either IPv4 or IPv6 */
|
||||
uint32_t task_stack_size; /*!< Stack size of internal ping task */
|
||||
uint32_t task_prio; /*!< Priority of internal ping task */
|
||||
} esp_ping_config_t;
|
||||
|
||||
/**
|
||||
* @brief Default ping configuration
|
||||
*
|
||||
*/
|
||||
#define ESP_PING_DEFAULT_CONFIG() \
|
||||
{ \
|
||||
.count = 5, \
|
||||
.interval_ms = 1000, \
|
||||
.timeout_ms = 1000, \
|
||||
.data_size = 56, \
|
||||
.tos = 0, \
|
||||
.target_addr = ip_addr_any_type, \
|
||||
.task_stack_size = 2048, \
|
||||
.task_prio = 2, \
|
||||
}
|
||||
|
||||
#define ESP_PING_COUNT_INFINITE (0) /*!< Set ping count to zero will ping target infinitely */
|
||||
|
||||
/**
|
||||
* @brief Profile of ping session
|
||||
*
|
||||
*/
|
||||
typedef enum {
|
||||
ESP_PING_PROF_SEQNO, /*!< Sequence number of a ping procedure */
|
||||
ESP_PING_PROF_TTL, /*!< Time to live of a ping procedure */
|
||||
ESP_PING_PROF_REQUEST, /*!< Number of request packets sent out */
|
||||
ESP_PING_PROF_REPLY, /*!< Number of reply packets received */
|
||||
ESP_PING_PROF_IPADDR, /*!< IP address of replied target */
|
||||
ESP_PING_PROF_SIZE, /*!< Size of received packet */
|
||||
ESP_PING_PROF_TIMEGAP, /*!< Elapsed time between request and reply packet */
|
||||
ESP_PING_PROF_DURATION /*!< Elapsed time of the whole ping session */
|
||||
} esp_ping_profile_t;
|
||||
|
||||
/**
|
||||
* @brief Create a ping session
|
||||
*
|
||||
* @param config ping configuration
|
||||
* @param cbs a bunch of callback functions invoked by internal ping task
|
||||
* @param hdl_out handle of ping session
|
||||
* @return
|
||||
* - ESP_ERR_INVALID_ARG: invalid parameters (e.g. configuration is null, etc)
|
||||
* - ESP_ERR_NO_MEM: out of memory
|
||||
* - ESP_FAIL: other internal error (e.g. socket error)
|
||||
* - ESP_OK: create ping session successfully, user can take the ping handle to do follow-on jobs
|
||||
*/
|
||||
esp_err_t esp_ping_new_session(const esp_ping_config_t *config, const esp_ping_callbacks_t *cbs, esp_ping_handle_t *hdl_out);
|
||||
|
||||
/**
|
||||
* @brief Delete a ping session
|
||||
*
|
||||
* @param hdl handle of ping session
|
||||
* @return
|
||||
* - ESP_ERR_INVALID_ARG: invalid parameters (e.g. ping handle is null, etc)
|
||||
* - ESP_OK: delete ping session successfully
|
||||
*/
|
||||
esp_err_t esp_ping_delete_session(esp_ping_handle_t hdl);
|
||||
|
||||
/**
|
||||
* @brief Start the ping session
|
||||
*
|
||||
* @param hdl handle of ping session
|
||||
* @return
|
||||
* - ESP_ERR_INVALID_ARG: invalid parameters (e.g. ping handle is null, etc)
|
||||
* - ESP_OK: start ping session successfully
|
||||
*/
|
||||
esp_err_t esp_ping_start(esp_ping_handle_t hdl);
|
||||
|
||||
/**
|
||||
* @brief Stop the ping session
|
||||
*
|
||||
* @param hdl handle of ping session
|
||||
* @return
|
||||
* - ESP_ERR_INVALID_ARG: invalid parameters (e.g. ping handle is null, etc)
|
||||
* - ESP_OK: stop ping session successfully
|
||||
*/
|
||||
esp_err_t esp_ping_stop(esp_ping_handle_t hdl);
|
||||
|
||||
/**
|
||||
* @brief Get runtime profile of ping session
|
||||
*
|
||||
* @param hdl handle of ping session
|
||||
* @param profile type of profile
|
||||
* @param data profile data
|
||||
* @param size profile data size
|
||||
* @return
|
||||
* - ESP_ERR_INVALID_ARG: invalid parameters (e.g. ping handle is null, etc)
|
||||
* - ESP_ERR_INVALID_SIZE: the actual profile data size doesn't match the "size" parameter
|
||||
* - ESP_OK: get profile successfully
|
||||
*/
|
||||
esp_err_t esp_ping_get_profile(esp_ping_handle_t hdl, esp_ping_profile_t profile, void *data, uint32_t size);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
127
components/lwip/include/apps/sntp/sntp.h
Normal file
127
components/lwip/include/apps/sntp/sntp.h
Normal file
@ -0,0 +1,127 @@
|
||||
// Copyright 2015-2019 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 __SNTP_H__
|
||||
#define __SNTP_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
* The time update takes place in the sntp_sync_time() function.
|
||||
* The user has the ability to redefine this function in order
|
||||
* to re-define its functionality. This function has two time update modes,
|
||||
* which can be set via the sntp_set_sync_mode() function.
|
||||
* Two modes are available:
|
||||
* - the first is an immediate update when receiving time from the sntp server,
|
||||
* - the second is a smooth time update (if the time error is no more than 35 minutes,
|
||||
* and an immediate update if the error is more than 35 minutes).
|
||||
*
|
||||
* To receive notification of time synchronization,
|
||||
* you can use the callback function or get the synchronization status
|
||||
* via the sntp_get_sync_status() function.
|
||||
*
|
||||
* To determine the time synchronization time on the device, you can use:
|
||||
* 1) sntp_set_time_sync_notification_cb() function to set the callback function,
|
||||
* which is convenient to use to receive notification of the update time.
|
||||
* 2) sntp_get_sync_status() function for getting time synchronization status.
|
||||
* After the time synchronization is completed, the status will be
|
||||
* SNTP_SYNC_STATUS_COMPLETED, after, it will be reseted to SNTP_SYNC_STATUS_RESET
|
||||
* to wait for the next sync cycle.
|
||||
*/
|
||||
|
||||
/// SNTP time update mode
|
||||
typedef enum {
|
||||
SNTP_SYNC_MODE_IMMED, /*!< Update system time immediately when receiving a response from the SNTP server. */
|
||||
SNTP_SYNC_MODE_SMOOTH, /*!< Smooth time updating. Time error is gradually reduced using adjtime function. If the difference between SNTP response time and system time is large (more than 35 minutes) then update immediately. */
|
||||
} sntp_sync_mode_t;
|
||||
|
||||
/// SNTP sync status
|
||||
typedef enum {
|
||||
SNTP_SYNC_STATUS_RESET, // Reset status.
|
||||
SNTP_SYNC_STATUS_COMPLETED, // Time is synchronized.
|
||||
SNTP_SYNC_STATUS_IN_PROGRESS, // Smooth time sync in progress.
|
||||
} sntp_sync_status_t;
|
||||
|
||||
/**
|
||||
* @brief SNTP callback function for notifying about time sync event
|
||||
*
|
||||
* @param tv Time received from SNTP server.
|
||||
*/
|
||||
typedef void (*sntp_sync_time_cb_t) (struct timeval *tv);
|
||||
|
||||
/**
|
||||
* @brief This function updates the system time.
|
||||
*
|
||||
* This is a weak-linked function. It is possible to replace all SNTP update functionality
|
||||
* by placing a sntp_sync_time() function in the app firmware source.
|
||||
* If the default implementation is used, calling sntp_set_sync_mode() allows
|
||||
* the time synchronization mode to be changed to instant or smooth.
|
||||
* If a callback function is registered via sntp_set_time_sync_notification_cb(),
|
||||
* it will be called following time synchronization.
|
||||
*
|
||||
* @param tv Time received from SNTP server.
|
||||
*/
|
||||
void sntp_sync_time(struct timeval *tv);
|
||||
|
||||
/**
|
||||
* @brief Set the sync mode
|
||||
*
|
||||
* Allowable two mode: SNTP_SYNC_MODE_IMMED and SNTP_SYNC_MODE_SMOOTH.
|
||||
* @param sync_mode Sync mode.
|
||||
*/
|
||||
void sntp_set_sync_mode(sntp_sync_mode_t sync_mode);
|
||||
|
||||
/**
|
||||
* @brief Get set sync mode
|
||||
*
|
||||
* @return SNTP_SYNC_MODE_IMMED: Update time immediately.
|
||||
* SNTP_SYNC_MODE_SMOOTH: Smooth time updating.
|
||||
*/
|
||||
sntp_sync_mode_t sntp_get_sync_mode(void);
|
||||
|
||||
/**
|
||||
* @brief Get status of time sync
|
||||
*
|
||||
* After the update is completed, the status will be returned as SNTP_SYNC_STATUS_COMPLETED.
|
||||
* After that, the status will be reset to SNTP_SYNC_STATUS_RESET.
|
||||
* If the update operation is not completed yet, the status will be SNTP_SYNC_STATUS_RESET.
|
||||
* If a smooth mode was chosen and the synchronization is still continuing (adjtime works), then it will be SNTP_SYNC_STATUS_IN_PROGRESS.
|
||||
*
|
||||
* @return SNTP_SYNC_STATUS_RESET: Reset status.
|
||||
* SNTP_SYNC_STATUS_COMPLETED: Time is synchronized.
|
||||
* SNTP_SYNC_STATUS_IN_PROGRESS: Smooth time sync in progress.
|
||||
*/
|
||||
sntp_sync_status_t sntp_get_sync_status(void);
|
||||
|
||||
/**
|
||||
* @brief Set status of time sync
|
||||
*
|
||||
* @param sync_status status of time sync (see sntp_sync_status_t)
|
||||
*/
|
||||
void sntp_set_sync_status(sntp_sync_status_t sync_status);
|
||||
|
||||
/**
|
||||
* @brief Set a callback function for time synchronization notification
|
||||
*
|
||||
* @param callback a callback function
|
||||
*/
|
||||
void sntp_set_time_sync_notification_cb(sntp_sync_time_cb_t callback);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // __SNTP_H__
|
Reference in New Issue
Block a user