Files
esp-protocols/components/esp_modem/include/cxx_include/esp_modem_netif.hpp

90 lines
2.1 KiB
C++
Raw Normal View History

2021-03-29 19:34:45 +02:00
// Copyright 2021 Espressif Systems (Shanghai) PTE LTD
2021-02-26 20:23:29 +01:00
//
2021-03-29 19:34:45 +02:00
// 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
2021-02-26 20:23:29 +01:00
//
2021-03-29 19:34:45 +02:00
// 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.
2021-02-26 20:23:29 +01:00
2021-03-29 19:34:45 +02:00
#ifndef _ESP_MODEM_NETIF_HPP
#define _ESP_MODEM_NETIF_HPP
2021-02-26 20:23:29 +01:00
2021-04-04 22:15:46 +02:00
#include <memory>
#include <cstddef>
2021-02-26 20:23:29 +01:00
#include "esp_netif.h"
#include "cxx_include/esp_modem_primitives.hpp"
2021-02-26 20:23:29 +01:00
2021-03-29 19:34:45 +02:00
namespace esp_modem {
2021-03-03 20:35:08 +01:00
class DTE;
class Netif;
2021-02-26 20:23:29 +01:00
struct ppp_netif_driver {
esp_netif_driver_base_t base;
Netif *ppp;
2021-02-26 20:23:29 +01:00
};
2021-04-14 17:57:42 +02:00
/**
* @defgroup ESP_MODEM_NETIF
* @brief Network interface layer of the esp-modem
*/
/** @addtogroup ESP_MODEM_NETIF
* @{
*/
/**
* @brief Network interface class responsible to glue the esp-netif to the modem's DCE
*/
class Netif {
2021-02-26 20:23:29 +01:00
public:
explicit Netif(std::shared_ptr<DTE> e, esp_netif_t *netif);
2021-02-26 20:23:29 +01:00
2021-03-29 19:34:45 +02:00
~Netif();
2021-04-14 17:57:42 +02:00
/**
* @brief Start the network interface
*/
2021-02-27 09:32:14 +01:00
void start();
2021-03-29 19:34:45 +02:00
2021-04-14 17:57:42 +02:00
/**
* @brief Blocks until the network interface closes
*/
2021-04-04 22:15:46 +02:00
void wait_until_ppp_exits();
2021-03-29 19:34:45 +02:00
2021-04-14 17:57:42 +02:00
/**
* @brief Stop the network interface
*/
2021-03-03 20:35:08 +01:00
void stop();
2021-03-29 19:34:45 +02:00
2021-02-26 20:23:29 +01:00
private:
2021-03-04 20:19:18 +01:00
void receive(uint8_t *data, size_t len);
2021-03-29 19:34:45 +02:00
2021-03-04 20:19:18 +01:00
static esp_err_t esp_modem_dte_transmit(void *h, void *buffer, size_t len);
2021-03-29 19:34:45 +02:00
static esp_err_t esp_modem_post_attach(esp_netif_t *esp_netif, void *args);
2021-03-04 20:19:18 +01:00
static void on_ppp_changed(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data);
2021-03-03 20:35:08 +01:00
std::shared_ptr<DTE> ppp_dte;
2021-02-26 20:23:29 +01:00
esp_netif_t *netif;
2021-03-04 20:19:18 +01:00
struct ppp_netif_driver driver{};
SignalGroup signal;
static const size_t PPP_STARTED = SignalGroup::bit0;
static const size_t PPP_EXIT = SignalGroup::bit1;
2021-02-26 20:23:29 +01:00
};
2021-04-14 17:57:42 +02:00
/**
* @}
*/
2021-03-29 19:34:45 +02:00
} // namespace esp_modem
2021-02-26 20:23:29 +01:00
2021-03-29 19:34:45 +02:00
#endif // _ESP_MODEM_NETIF_HPP