• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2019 Espressif Systems (Shanghai) PTE 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 
16 #ifndef _ESP_NETIF_PPP_H_
17 #define _ESP_NETIF_PPP_H_
18 
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22 
23 /** @brief PPP event base */
24 ESP_EVENT_DECLARE_BASE(NETIF_PPP_STATUS);
25 
26 /** @brief Configuration structure for PPP network interface
27  *
28  */
29 typedef struct esp_netif_ppp_config {
30     bool ppp_phase_event_enabled;  /**< Enables events coming from PPP PHASE change */
31     bool ppp_error_event_enabled;  /**< Enables events from main PPP state machine producing errors */
32 } esp_netif_ppp_config_t;
33 
34 /** @brief event id offset for PHASE related events
35  *
36  * All PPP related events are produced from esp-netif under `NETIF_PPP_STATUS`, this offset defines
37  * helps distinguish between error and phase events
38  */
39 #define NETIF_PP_PHASE_OFFSET (0x100)
40 
41 /** @brief event ids for different PPP related events
42  *
43  */
44 typedef enum {
45     NETIF_PPP_ERRORNONE        = 0,  /* No error. */
46     NETIF_PPP_ERRORPARAM       = 1,  /* Invalid parameter. */
47     NETIF_PPP_ERROROPEN        = 2,  /* Unable to open PPP session. */
48     NETIF_PPP_ERRORDEVICE      = 3,  /* Invalid I/O device for PPP. */
49     NETIF_PPP_ERRORALLOC       = 4,  /* Unable to allocate resources. */
50     NETIF_PPP_ERRORUSER        = 5,  /* User interrupt. */
51     NETIF_PPP_ERRORCONNECT     = 6,  /* Connection lost. */
52     NETIF_PPP_ERRORAUTHFAIL    = 7,  /* Failed authentication challenge. */
53     NETIF_PPP_ERRORPROTOCOL    = 8,  /* Failed to meet protocol. */
54     NETIF_PPP_ERRORPEERDEAD    = 9,  /* Connection timeout */
55     NETIF_PPP_ERRORIDLETIMEOUT = 10, /* Idle Timeout */
56     NETIF_PPP_ERRORCONNECTTIME = 11, /* Max connect time reached */
57     NETIF_PPP_ERRORLOOPBACK    = 12, /* Loopback detected */
58     NETIF_PPP_PHASE_DEAD         = NETIF_PP_PHASE_OFFSET +  0,
59     NETIF_PPP_PHASE_MASTER       = NETIF_PP_PHASE_OFFSET +  1,
60     NETIF_PPP_PHASE_HOLDOFF      = NETIF_PP_PHASE_OFFSET +  2,
61     NETIF_PPP_PHASE_INITIALIZE   = NETIF_PP_PHASE_OFFSET +  3,
62     NETIF_PPP_PHASE_SERIALCONN   = NETIF_PP_PHASE_OFFSET +  4,
63     NETIF_PPP_PHASE_DORMANT      = NETIF_PP_PHASE_OFFSET +  5,
64     NETIF_PPP_PHASE_ESTABLISH    = NETIF_PP_PHASE_OFFSET +  6,
65     NETIF_PPP_PHASE_AUTHENTICATE = NETIF_PP_PHASE_OFFSET +  7,
66     NETIF_PPP_PHASE_CALLBACK     = NETIF_PP_PHASE_OFFSET +  8,
67     NETIF_PPP_PHASE_NETWORK      = NETIF_PP_PHASE_OFFSET +  9,
68     NETIF_PPP_PHASE_RUNNING      = NETIF_PP_PHASE_OFFSET +  10,
69     NETIF_PPP_PHASE_TERMINATE    = NETIF_PP_PHASE_OFFSET +  11,
70     NETIF_PPP_PHASE_DISCONNECT   = NETIF_PP_PHASE_OFFSET +  12,
71 } esp_netif_ppp_status_event_t;
72 
73 /** @brief definitions of different authorisation types
74  *
75  */
76 typedef enum {
77     NETIF_PPP_AUTHTYPE_NONE =      0x00,
78     NETIF_PPP_AUTHTYPE_PAP =       0x01,
79     NETIF_PPP_AUTHTYPE_CHAP =      0x02,
80     NETIF_PPP_AUTHTYPE_MSCHAP =    0x04,
81     NETIF_PPP_AUTHTYPE_MSCHAP_V2 = 0x08,
82     NETIF_PPP_AUTHTYPE_EAP =       0x10,
83 } esp_netif_auth_type_t;
84 
85 /** @brief Sets the auth parameters for the supplied esp-netif.
86  *
87  * @param[in]  esp_netif Handle to esp-netif instance
88  * @param[in]  authtype Authorisation type
89  * @param[in]  user User name
90  * @param[in]  passwd Password
91  *
92  * @return     ESP_OK on success, ESP_ERR_ESP_NETIF_INVALID_PARAMS if netif null or not PPP
93  */
94 esp_err_t esp_netif_ppp_set_auth(esp_netif_t *netif, esp_netif_auth_type_t authtype, const char *user, const char *passwd);
95 
96 /** @brief Sets common parameters for the supplied esp-netif.
97  *
98  * @param[in]  esp_netif Handle to esp-netif instance
99  * @param[in]  config Pointer to PPP netif configuration structure
100  *
101  * @return     ESP_OK on success, ESP_ERR_ESP_NETIF_INVALID_PARAMS if netif null or not PPP
102  */
103 esp_err_t esp_netif_ppp_set_params(esp_netif_t *netif, const esp_netif_ppp_config_t *config);
104 
105 
106 #ifdef __cplusplus
107 }
108 #endif
109 
110 #endif //_ESP_NETIF_PPP_H_
111