lwip: handle CONFIG_VFS_SUPPORT_IO=n and CONFIG_VFS_SUPPORT_SELECT=n

* If CONFIG_VFS_SUPPORT_IO=y, keep everything as it is now
* If CONFIG_VFS_SUPPORT_IO=n, defined syscalls which LwIP can
  implement, such as read/write/close
* Make LWIP-only select implementation dependent on
  CONFIG_VFS_SUPPORT_SELECT, deprecate CONFIG_LWIP_USE_ONLY_LWIP_SELECT
This commit is contained in:
Ivan Grokhotkov 2020-03-20 13:39:22 +01:00
parent cadab2cbcf
commit b203ac7b02
5 changed files with 116 additions and 5 deletions

View file

@ -85,7 +85,6 @@ set(srcs
"lwip/src/netif/ppp/upap.c"
"lwip/src/netif/ppp/utils.c"
"lwip/src/netif/ppp/vj.c"
"port/esp32/vfs_lwip.c"
"port/esp32/debug/lwip_debug.c"
"port/esp32/freertos/sys_arch.c"
"port/esp32/netif/dhcp_state.c"
@ -129,6 +128,12 @@ if(CONFIG_ETH_ENABLED)
list(APPEND srcs "port/esp32/netif/ethernetif.c")
endif()
if(CONFIG_VFS_SUPPORT_IO)
list(APPEND srcs "port/esp32/vfs_lwip.c")
else()
list(APPEND srcs "port/esp32/no_vfs_syscalls.c")
endif()
idf_component_register(SRCS "${srcs}"
INCLUDE_DIRS "${include_dirs}"
LDFRAGMENTS linker.lf

View file

@ -63,9 +63,12 @@ menu "LWIP"
to 16.
config LWIP_USE_ONLY_LWIP_SELECT
bool "Support LWIP socket select() only"
bool "Support LWIP socket select() only (DEPRECATED)"
default n
help
This option is deprecated. Use VFS_SUPPORT_SELECT instead, which is
the inverse of this option.
The virtual filesystem layer of select() redirects sockets to
lwip_select() and non-socket file descriptors to their respective driver
implementations. If this option is enabled then all calls of select()

View file

@ -29,6 +29,11 @@ COMPONENT_SRCDIRS := \
ifndef CONFIG_IDF_TARGET_ESP32
COMPONENT_OBJEXCLUDE := port/esp32/netif/ethernetif.o
endif
ifndef CONFIG_VFS_SUPPORT_IO
COMPONENT_OBJEXCLUDE += port/esp32/vfs_lwip.o
else
COMPONENT_OBJEXCLUDE += port/esp32/no_vfs_syscalls.o
endif
ifdef CONFIG_LWIP_PPP_SUPPORT
COMPONENT_SRCDIRS += lwip/src/netif/ppp lwip/src/netif/ppp/polarssl

View file

@ -0,0 +1,83 @@
// Copyright 2020 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.
#include <string.h>
#include <stdbool.h>
#include <stdarg.h>
#include <sys/errno.h>
#include <sys/lock.h>
#include <sys/fcntl.h>
#include <sys/ioctl.h>
#include "sdkconfig.h"
#include "lwip/sockets.h"
#include "lwip/sys.h"
#ifdef CONFIG_VFS_SUPPORT_IO
#error This file should only be built when CONFIG_VFS_SUPPORT_IO=n
#endif
/* Default implementations of read/write provided in newlib component,
* used as a fallback for console I/O.
*/
extern ssize_t _write_r_console(struct _reent *r, int fd, const void * data, size_t size);
extern ssize_t _read_r_console(struct _reent *r, int fd, const void * data, size_t size);
ssize_t _write_r(struct _reent *r, int fd, const void * data, size_t size)
{
if (fd < LWIP_SOCKET_OFFSET) {
return _write_r_console(r, fd, data, size);
}
return lwip_write(fd, data, size);
}
ssize_t _read_r(struct _reent *r, int fd, void * dst, size_t size)
{
if (fd < LWIP_SOCKET_OFFSET) {
return _read_r_console(r, fd, dst, size);
}
return lwip_read(fd, dst, size);
}
int _close_r(struct _reent *r, int fd)
{
if (fd < LWIP_SOCKET_OFFSET) {
errno = ENOSYS;
return -1;
}
return lwip_close(fd);
}
int _fcntl_r(struct _reent *r, int fd, int cmd, int arg)
{
return lwip_fcntl(fd, cmd, arg);
}
int ioctl(int fd, int cmd, ...)
{
va_list args;
va_start(args, cmd);
int res = lwip_ioctl(fd, cmd, va_arg(args, void*));
va_end(args);
return res;
}
int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *errorfds, struct timeval *timeout)
{
return lwip_select(nfds, readfds, writefds, errorfds, timeout);
}
void esp_vfs_lwip_sockets_register(void)
{
/* Doesn't register anything, just a hook to force linking this file */
}

View file

@ -18,15 +18,20 @@
#include <sys/errno.h>
#include <sys/lock.h>
#include <sys/fcntl.h>
#include "esp_vfs.h"
#include "esp_vfs_dev.h"
#include "esp_attr.h"
#include "lwip/sockets.h"
#include "esp_vfs.h"
#include "sdkconfig.h"
#include "lwip/sockets.h"
#include "lwip/sys.h"
#ifndef CONFIG_VFS_SUPPORT_IO
#error This file should only be built when CONFIG_VFS_SUPPORT_IO=y
#endif
_Static_assert(MAX_FDS >= CONFIG_LWIP_MAX_SOCKETS, "MAX_FDS < CONFIG_LWIP_MAX_SOCKETS");
#ifdef CONFIG_VFS_SUPPORT_SELECT
static void lwip_stop_socket_select(void *sem)
{
sys_sem_signal(sem); //socket_select will return
@ -46,6 +51,14 @@ static void *lwip_get_socket_select_semaphore(void)
*/
return (void *) sys_thread_sem_get();
}
#else // CONFIG_VFS_SUPPORT_SELECT
int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *errorfds, struct timeval *timeout)
{
return lwip_select(nfds, readfds, writefds, errorfds, timeout);
}
#endif // CONFIG_VFS_SUPPORT_SELECT
static int lwip_fcntl_r_wrapper(int fd, int cmd, int arg)
{
@ -68,10 +81,12 @@ void esp_vfs_lwip_sockets_register(void)
.read = &lwip_read,
.fcntl = &lwip_fcntl_r_wrapper,
.ioctl = &lwip_ioctl_r_wrapper,
#ifdef CONFIG_VFS_SUPPORT_SELECT
.socket_select = &lwip_select,
.get_socket_select_semaphore = &lwip_get_socket_select_semaphore,
.stop_socket_select = &lwip_stop_socket_select,
.stop_socket_select_isr = &lwip_stop_socket_select_isr,
#endif // CONFIG_VFS_SUPPORT_SELECT
};
/* Non-LWIP file descriptors are from 0 to (LWIP_SOCKET_OFFSET-1). LWIP
* file descriptors are registered from LWIP_SOCKET_OFFSET to