mirror of
https://github.com/espressif/esp-protocols.git
synced 2025-07-17 20:42:21 +02:00
fix(esp_modem): linux port to work with lwip-2.1.2
This commit is contained in:
@ -7,6 +7,7 @@ if(${target} STREQUAL "linux")
|
|||||||
set(dependencies esp_system_protocols_linux)
|
set(dependencies esp_system_protocols_linux)
|
||||||
else()
|
else()
|
||||||
set(platform_srcs src/esp_modem_primitives_freertos.cpp
|
set(platform_srcs src/esp_modem_primitives_freertos.cpp
|
||||||
|
src/esp_modem_api_target.cpp
|
||||||
src/esp_modem_uart.cpp
|
src/esp_modem_uart.cpp
|
||||||
src/esp_modem_term_uart.cpp
|
src/esp_modem_term_uart.cpp
|
||||||
src/esp_modem_netif.cpp)
|
src/esp_modem_netif.cpp)
|
||||||
|
@ -3,6 +3,8 @@ set(LWIP_CONTRIB_DIR "$ENV{LWIP_CONTRIB_PATH}")
|
|||||||
|
|
||||||
set(lwipcontribportunix_SRCS ${LWIP_CONTRIB_DIR}/ports/unix/port/sys_arch.c)
|
set(lwipcontribportunix_SRCS ${LWIP_CONTRIB_DIR}/ports/unix/port/sys_arch.c)
|
||||||
|
|
||||||
|
if(NOT CMAKE_BUILD_EARLY_EXPANSION)
|
||||||
|
|
||||||
include(${LWIP_DIR}/src/Filelists.cmake)
|
include(${LWIP_DIR}/src/Filelists.cmake)
|
||||||
|
|
||||||
set (LWIP_INCLUDE_DIRS
|
set (LWIP_INCLUDE_DIRS
|
||||||
@ -10,11 +12,11 @@ set (LWIP_INCLUDE_DIRS
|
|||||||
"${LWIP_CONTRIB_DIR}/ports/unix/port/include")
|
"${LWIP_CONTRIB_DIR}/ports/unix/port/include")
|
||||||
|
|
||||||
list(REMOVE_ITEM lwipnoapps_SRCS "${LWIP_DIR}/src/netif/slipif.c")
|
list(REMOVE_ITEM lwipnoapps_SRCS "${LWIP_DIR}/src/netif/slipif.c")
|
||||||
list(REMOVE_ITEM lwipnoapps_SRCS "${LWIP_DIR}/src/core/ip4.c")
|
list(REMOVE_ITEM lwipnoapps_SRCS "${LWIP_DIR}/src/core/ipv4/ip4.c")
|
||||||
list(REMOVE_ITEM lwipnoapps_SRCS "${LWIP_DIR}/src/core/ipv6/ip6.c")
|
list(REMOVE_ITEM lwipnoapps_SRCS "${LWIP_DIR}/src/core/ipv6/ip6.c")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
idf_component_register(SRCS esp_netif_linux.cpp tun_io.c ip4_stub.c ip6_stub.c ${lwipnoapps_SRCS} ${lwipcontribportunix_SRCS}
|
||||||
idf_component_register(SRCS esp_netif_linux.cpp tun_io.c ip6_stub.c ${lwipnoapps_SRCS} ${lwipcontribportunix_SRCS}
|
|
||||||
INCLUDE_DIRS include ${LWIP_INCLUDE_DIRS}
|
INCLUDE_DIRS include ${LWIP_INCLUDE_DIRS}
|
||||||
PRIV_INCLUDE_DIRS .
|
PRIV_INCLUDE_DIRS .
|
||||||
REQUIRES esp_system_protocols_linux)
|
REQUIRES esp_system_protocols_linux)
|
||||||
|
@ -90,43 +90,6 @@ public:
|
|||||||
extern "C" esp_netif_t *esp_netif_new(const esp_netif_config_t *config)
|
extern "C" esp_netif_t *esp_netif_new(const esp_netif_config_t *config)
|
||||||
{
|
{
|
||||||
return new NetifStorage(config);
|
return new NetifStorage(config);
|
||||||
// struct ifreq ifr = { };
|
|
||||||
// esp_netif_t * netif = netif_storage;
|
|
||||||
// if (netif == NULL) {
|
|
||||||
// return NULL;
|
|
||||||
// }
|
|
||||||
// if ((netif->fd = open(config->dev_name, O_RDWR)) == -1) {
|
|
||||||
// ESP_LOGE(TAG, "Cannot open %s", config->dev_name);
|
|
||||||
// goto cleanup;
|
|
||||||
// }
|
|
||||||
// ifr.ifr_flags = IFF_TUN;
|
|
||||||
// strncpy(ifr.ifr_name, config->if_name, IFNAMSIZ);
|
|
||||||
//
|
|
||||||
// if (ioctl(netif->fd, TUNSETIFF, (void *)&ifr) == -1) {
|
|
||||||
// ESP_LOGE(TAG, "Cannot set ioctl TUNSETIFF %m");
|
|
||||||
// goto cleanup;
|
|
||||||
// }
|
|
||||||
// ioctl(netif->fd, TUNSETNOCSUM, 1);
|
|
||||||
//
|
|
||||||
// netif->in_buf = new uint8_t[BUF_SIZE];
|
|
||||||
// netif->out_buf = new uint8_t[BUF_SIZE];
|
|
||||||
// if (netif->in_buf == nullptr || netif->out_buf == nullptr) {
|
|
||||||
// goto cleanup;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// if (!ppp_netif_init(netif)) {
|
|
||||||
// ESP_LOGE(TAG, "Cannot initialize pppos lwip netif %m");
|
|
||||||
// goto cleanup;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// return netif;
|
|
||||||
//
|
|
||||||
//cleanup:
|
|
||||||
// close(netif->fd);
|
|
||||||
// delete[] netif->in_buf;
|
|
||||||
// delete[] netif->out_buf;
|
|
||||||
// delete netif_storage;
|
|
||||||
// return nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void esp_netif_destroy(esp_netif_t *netif)
|
void esp_netif_destroy(esp_netif_t *netif)
|
||||||
|
17
components/esp_modem/port/linux/esp_netif_linux/ip4_stub.c
Normal file
17
components/esp_modem/port/linux/esp_netif_linux/ip4_stub.c
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
#include "lwip/ip4.h"
|
||||||
|
|
||||||
|
err_t
|
||||||
|
ip4_output_if(struct pbuf *p, const ip4_addr_t *src, const ip4_addr_t *dest,
|
||||||
|
u8_t ttl, u8_t tos,
|
||||||
|
u8_t proto, struct netif *netif)
|
||||||
|
{ return ERR_OK; }
|
||||||
|
|
||||||
|
struct netif *
|
||||||
|
ip4_route(const ip4_addr_t *dest)
|
||||||
|
{ return NULL; }
|
||||||
|
|
||||||
|
err_t
|
||||||
|
ip4_output_if_src(struct pbuf *p, const ip4_addr_t *src, const ip4_addr_t *dest,
|
||||||
|
u8_t ttl, u8_t tos,
|
||||||
|
u8_t proto, struct netif *netif)
|
||||||
|
{ return ERR_OK; }
|
@ -30,13 +30,6 @@ struct PdpContext;
|
|||||||
static const char *TAG = "modem_api";
|
static const char *TAG = "modem_api";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
std::shared_ptr<DTE> create_uart_dte(const dte_config *config)
|
|
||||||
{
|
|
||||||
TRY_CATCH_RET_NULL(
|
|
||||||
auto term = create_uart_terminal(config);
|
|
||||||
return std::make_shared<DTE>(config, std::move(term));
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
std::shared_ptr<DTE> create_vfs_dte(const dte_config *config)
|
std::shared_ptr<DTE> create_vfs_dte(const dte_config *config)
|
||||||
{
|
{
|
||||||
|
39
components/esp_modem/src/esp_modem_api_target.cpp
Normal file
39
components/esp_modem/src/esp_modem_api_target.cpp
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
// 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.
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
|
#include "esp_log.h"
|
||||||
|
#include "cxx_include/esp_modem_dte.hpp"
|
||||||
|
#include "uart_terminal.hpp"
|
||||||
|
#include "vfs_termial.hpp"
|
||||||
|
#include "cxx_include/esp_modem_api.hpp"
|
||||||
|
#include "cxx_include/esp_modem_dce_factory.hpp"
|
||||||
|
#include "esp_modem_config.h"
|
||||||
|
#include "exception_stub.hpp"
|
||||||
|
|
||||||
|
namespace esp_modem {
|
||||||
|
|
||||||
|
#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
|
||||||
|
static const char *TAG = "modem_api_target";
|
||||||
|
#endif
|
||||||
|
|
||||||
|
std::shared_ptr<DTE> create_uart_dte(const dte_config *config)
|
||||||
|
{
|
||||||
|
TRY_CATCH_RET_NULL(
|
||||||
|
auto term = create_uart_terminal(config);
|
||||||
|
return std::make_shared<DTE>(config, std::move(term));
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace esp_modem
|
@ -27,6 +27,10 @@
|
|||||||
#define ESP_MODEM_C_API_STR_MAX 64
|
#define ESP_MODEM_C_API_STR_MAX 64
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef HAVE_STRLCPY
|
||||||
|
size_t strlcpy(char *dest, const char *src, size_t len);
|
||||||
|
#endif
|
||||||
|
|
||||||
//
|
//
|
||||||
// C API definitions
|
// C API definitions
|
||||||
using namespace esp_modem;
|
using namespace esp_modem;
|
||||||
|
@ -89,4 +89,9 @@ void Task::Relinquish()
|
|||||||
usleep(0);
|
usleep(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Task::Delay(uint32_t ms)
|
||||||
|
{
|
||||||
|
usleep(ms*1000);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace esp_modem
|
} // namespace esp_modem
|
Reference in New Issue
Block a user