1 // Copyright 2021 Espressif Systems (Shanghai) CO LTD
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License
14 
15 #pragma once
16 
17 #include "hal/uart_types.h"
18 #include "sys/_stdint.h"
19 #include "sys/select.h"
20 #include "esp_event_base.h"
21 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 
26 /**
27 * @brief OpenThread event declarations
28 *
29 */
30 typedef enum {
31     OPENTHREAD_EVENT_START,                 /*!< OpenThread stack start */
32     OPENTHREAD_EVENT_STOP,                  /*!< OpenThread stack stop */
33     OPENTHREAD_EVENT_IF_UP,                 /*!< OpenThread network interface up */
34     OPENTHREAD_EVENT_IF_DOWN,               /*!< OpenThread network interface down */
35     OPENTHREAD_EVENT_GOT_IP6,               /*!< OpenThread stack added IPv6 address */
36     OPENTHREAD_EVENT_LOST_IP6,              /*!< OpenThread stack removed IPv6 address */
37     OPENTHREAD_EVENT_MULTICAST_GROUP_JOIN,  /*!< OpenThread stack joined IPv6 multicast group */
38     OPENTHREAD_EVENT_MULTICAST_GROUP_LEAVE, /*!< OpenThread stack left IPv6 multicast group */
39 } esp_openthread_event_t;
40 
41 /**
42 * @brief OpenThread event base declaration
43 *
44 */
45 ESP_EVENT_DECLARE_BASE(OPENTHREAD_EVENT);
46 
47 /**
48  * This structure represents a context for a select() based mainloop.
49  *
50  */
51 typedef struct {
52     fd_set         read_fds;    /*!< The read file descriptors */
53     fd_set         write_fds;   /*!< The write file descriptors */
54     fd_set         error_fds;   /*!< The error file descriptors */
55     int            max_fd;      /*!< The max file descriptor */
56     struct timeval timeout;     /*!< The timeout */
57 } esp_openthread_mainloop_context_t;
58 
59 /**
60  * @brief The uart port config for OpenThread.
61  *
62  */
63 typedef struct {
64     uart_port_t port;               /*!< UART port number */
65     uart_config_t uart_config;      /*!< UART configuration, see uart_config_t docs */
66     int rx_pin;                     /*!< UART RX pin */
67     int tx_pin;                     /*!< UART TX pin */
68 } esp_openthread_uart_config_t;
69 
70 /**
71  * @brief The radio mode of OpenThread.
72  *
73  */
74 typedef enum {
75     RADIO_MODE_NATIVE   = 0x0,      /*!< Use the native 15.4 radio */
76     RADIO_MODE_UART_RCP = 0x1,      /*!< UART connection to a 15.4 capable radio co-processor (RCP) */
77     RADIO_MODE_SPI_RCP  = 0x2,      /*!< SPI connection to a 15.4 capable radio co-processor (RCP) */
78 } esp_openthread_radio_mode_t;
79 
80 /**
81  * @brief How OpenThread connects to the host.
82  *
83  */
84 typedef enum {
85     HOST_CONNECTION_MODE_NONE     = 0x0, /*!< Disable host connection */
86     HOST_CONNECTION_MODE_CLI_UART = 0x1, /*!< CLI UART connection to the host */
87     HOST_CONNECTION_MODE_RCP_UART = 0x2, /*!< RCP UART connection to the host */
88 } esp_openthread_host_connection_mode_t;
89 
90 /**
91  * @brief The OpenThread radio configuration
92  *
93  */
94 typedef struct {
95     esp_openthread_radio_mode_t     radio_mode;         /*!< The radio mode */
96     esp_openthread_uart_config_t    radio_uart_config;  /*!< The uart configuration to RCP */
97 } esp_openthread_radio_config_t;
98 
99 /**
100  * @brief The OpenThread host connection configuration
101  *
102  */
103 typedef struct {
104     esp_openthread_host_connection_mode_t   host_connection_mode;   /*!< The host connection mode */
105     esp_openthread_uart_config_t            host_uart_config;       /*!< The uart configuration to host */
106 } esp_openthread_host_connection_config_t;
107 
108 /**
109  * @brief The OpenThread port specific configuration
110  *
111  */
112 typedef struct {
113     const char *storage_partition_name; /*!< The partition for storing OpenThread dataset */
114     uint8_t     netif_queue_size;       /*!< The packet queue size for the network interface */
115     uint8_t     task_queue_size;        /*!< The task queue size */
116 } esp_openthread_port_config_t;
117 
118 /**
119  * @brief The OpenThread platform configuration
120  *
121  */
122 typedef struct {
123     esp_openthread_radio_config_t               radio_config;   /*!< The radio configuration */
124     esp_openthread_host_connection_config_t     host_config;    /*!< The host connection configuration */
125     esp_openthread_port_config_t                port_config;    /*!< The port configuration */
126 } esp_openthread_platform_config_t;
127 
128 #ifdef __cplusplus
129 }
130 #endif
131