Merge branch 'master' into feature/lwip_sntp_max_servers

This commit is contained in:
David Cermak
2021-08-24 18:16:07 +02:00
1400 changed files with 134414 additions and 65245 deletions

View File

@@ -40,7 +40,7 @@ int __weak lwip_hook_netconn_external_resolve(const char *name, ip_addr_t *addr,
#endif
#ifdef CONFIG_LWIP_HOOK_ND6_GET_GW_DEFAULT
const ip6_addr_t *lwip_hook_nd6_get_gw(struct netif *netif, const ip6_addr_t *dest)
const ip6_addr_t *__weak lwip_hook_nd6_get_gw(struct netif *netif, const ip6_addr_t *dest)
{
LWIP_UNUSED_ARG(netif);
LWIP_UNUSED_ARG(dest);

View File

@@ -33,9 +33,7 @@
#define __LWIPOPTS_H__
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
#include <sys/time.h>
#include <sys/fcntl.h>
#include <sys/ioctl.h>
#include <sys/types.h>
@@ -44,6 +42,7 @@
#include "esp_system.h"
#include "sdkconfig.h"
#include "netif/dhcp_state.h"
#include "sntp/sntp_get_set_time.h"
/* Enable all Espressif-only options */
@@ -1063,25 +1062,6 @@
------------ SNTP options ------------
--------------------------------------
*/
/*
* SNTP update delay - in milliseconds
*/
/*
* Forward declarations of weak definitions from lwip's sntp.c which could
* be redefined by user application. This is needed to provide custom definition
* of the below macros in lwip's sntp.c.
* Full declaration is provided in IDF's port layer in esp_sntp.h
*/
#ifdef __cplusplus
#define LWIP_FORWARD_DECLARE_C_CXX extern "C"
#else
#define LWIP_FORWARD_DECLARE_C_CXX
#endif
LWIP_FORWARD_DECLARE_C_CXX void sntp_sync_time(struct timeval *tv);
LWIP_FORWARD_DECLARE_C_CXX uint32_t sntp_get_sync_interval(void);
// Max number of SNTP servers handled (default equal to LWIP_DHCP_MAX_NTP_SERVERS)
#if defined CONFIG_LWIP_SNTP_MAX_SERVERS
@@ -1101,22 +1081,9 @@ LWIP_FORWARD_DECLARE_C_CXX uint32_t sntp_get_sync_interval(void);
// It disables a check of SNTP_UPDATE_DELAY it is done in sntp_set_sync_interval
#define SNTP_SUPPRESS_DELAY_CHECK
#define SNTP_UPDATE_DELAY (sntp_get_sync_interval())
#define SNTP_SET_SYSTEM_TIME_US(sec, us) \
do { \
struct timeval tv = { .tv_sec = sec, .tv_usec = us }; \
sntp_sync_time(&tv); \
} while (0);
#define SNTP_GET_SYSTEM_TIME(sec, us) \
do { \
struct timeval tv = { .tv_sec = 0, .tv_usec = 0 }; \
gettimeofday(&tv, NULL); \
(sec) = tv.tv_sec; \
(us) = tv.tv_usec; \
sntp_set_sync_status(SNTP_SYNC_STATUS_RESET); \
} while (0);
#define SNTP_UPDATE_DELAY (sntp_get_sync_interval())
#define SNTP_SET_SYSTEM_TIME_US(sec, us) (sntp_set_system_time(sec, us))
#define SNTP_GET_SYSTEM_TIME(sec, us) (sntp_get_system_time(&(sec), &(us)))
#define SOC_SEND_LOG //printf

View File

@@ -0,0 +1,55 @@
// Copyright 2021 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_GET_SET_TIME_H__
#define __SNTP_GET_SET_TIME_H__
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
/*
* Declarations of functions used in lwipopts.h to redefine
* default sntp macros, such as:
* - SNTP_UPDATE_DELAY()
* - SNTP_SET_SYSTEM_TIME_US()
* - SNTP_GET_SYSTEM_TIME()
*/
/*
* @brief Get the sync interval of SNTP operation
* Full definition is provided in IDF's layer in esp_sntp.c
*/
uint32_t sntp_get_sync_interval(void);
/**
* @brief system time setter used in the sntp module
* @note The lwip sntp uses u32_t types for sec and us arguments
*/
void sntp_set_system_time(uint32_t sec, uint32_t us);
/**
* @brief system time getter used in the sntp module
* @note The lwip sntp uses u32_t types for sec and us arguments
*/
void sntp_get_system_time(uint32_t* sec, uint32_t* us);
#ifdef __cplusplus
}
#endif
#endif //__SNTP_GET_SET_TIME_H__

View File

@@ -11,23 +11,20 @@
// See the License for the specific language governing permissions and
// limitations under the License
#include <string.h>
#include "esp_netif.h"
#include "esp_netif_net_stack.h"
#include "lwip/netif.h"
#include "lwip/pbuf.h"
#include "netif/openthreadif.h"
#include "openthread/error.h"
#include "openthread/ip6.h"
#include "openthread/link.h"
#include "openthread/message.h"
#define OPENTHREAD_IP6_MTU 1280
static void openthread_free_rx_buf_l2(struct netif *netif, void *buf)
{
free(buf);
}
static err_t openthread_output_ip6(struct netif *netif, struct pbuf *p, const struct ip6_addr *peer_addr)
{
struct pbuf *q = p;
@@ -69,24 +66,26 @@ void openthread_netif_input(void *h, void *buffer, size_t len, void *eb)
{
struct netif *netif = h;
struct pbuf *p;
otMessage *message = (otMessage *)buffer;
if (unlikely(buffer == NULL || !netif_is_up(netif))) {
if (buffer) {
openthread_free_rx_buf_l2(netif, buffer);
}
return;
}
/* acquire new pbuf, type: PBUF_REF */
p = pbuf_alloc(PBUF_RAW, len, PBUF_REF);
/* Allocate LINK buffer in case it's forwarded to WiFi/ETH */
p = pbuf_alloc(PBUF_LINK, len, PBUF_POOL);
if (p == NULL) {
openthread_free_rx_buf_l2(netif, buffer);
LWIP_DEBUGF(NETIF_DEBUG, ("Failed to allocate input pbuf for OpenThread netif\n"));
return;
}
p->payload = buffer;
if (unlikely(otMessageRead(message, 0, p->payload, len) != OT_ERROR_NONE)) {
LWIP_DEBUGF(NETIF_DEBUG, ("Failed to read OpenThread message\n"));
}
#if ESP_LWIP
p->l2_owner = netif;
p->l2_buf = buffer;
p->l2_owner = NULL;
p->l2_buf = NULL;
#endif
/* full packet send to tcpip_thread to process */
if (unlikely(netif->input(p, netif) != ERR_OK)) {
@@ -106,7 +105,7 @@ err_t openthread_netif_init(struct netif *netif)
netif->flags = NETIF_FLAG_BROADCAST;
netif->output = NULL;
netif->output_ip6 = openthread_output_ip6;
netif->l2_buffer_free_notify = openthread_free_rx_buf_l2;
netif->l2_buffer_free_notify = NULL;
netif_set_link_up(netif);
return ERR_OK;

View File

@@ -70,13 +70,25 @@ static int lwip_ioctl_r_wrapper(int fd, int cmd, va_list args)
return lwip_ioctl(fd, cmd, va_arg(args, void *));
}
static int lwip_fstat(int fd, struct stat * st)
{
if (st == NULL || fd < LWIP_SOCKET_OFFSET || fd > (MAX_FDS - 1)) {
errno = EBADF;
return -1;
}
memset(st, 0, sizeof(*st));
/* set the stat mode to socket type */
st->st_mode = S_IFSOCK;
return 0;
}
void esp_vfs_lwip_sockets_register(void)
{
esp_vfs_t vfs = {
.flags = ESP_VFS_FLAG_DEFAULT,
.write = &lwip_write,
.open = NULL,
.fstat = NULL,
.fstat = &lwip_fstat,
.close = &lwip_close,
.read = &lwip_read,
.fcntl = &lwip_fcntl_r_wrapper,