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 id offset for internal errors 42 * 43 */ 44 #define NETIF_PPP_INTERNAL_ERR_OFFSET (0x200) 45 46 /** @brief event ids for different PPP related events 47 * 48 */ 49 typedef enum { 50 NETIF_PPP_ERRORNONE = 0, /* No error. */ 51 NETIF_PPP_ERRORPARAM = 1, /* Invalid parameter. */ 52 NETIF_PPP_ERROROPEN = 2, /* Unable to open PPP session. */ 53 NETIF_PPP_ERRORDEVICE = 3, /* Invalid I/O device for PPP. */ 54 NETIF_PPP_ERRORALLOC = 4, /* Unable to allocate resources. */ 55 NETIF_PPP_ERRORUSER = 5, /* User interrupt. */ 56 NETIF_PPP_ERRORCONNECT = 6, /* Connection lost. */ 57 NETIF_PPP_ERRORAUTHFAIL = 7, /* Failed authentication challenge. */ 58 NETIF_PPP_ERRORPROTOCOL = 8, /* Failed to meet protocol. */ 59 NETIF_PPP_ERRORPEERDEAD = 9, /* Connection timeout */ 60 NETIF_PPP_ERRORIDLETIMEOUT = 10, /* Idle Timeout */ 61 NETIF_PPP_ERRORCONNECTTIME = 11, /* Max connect time reached */ 62 NETIF_PPP_ERRORLOOPBACK = 12, /* Loopback detected */ 63 NETIF_PPP_PHASE_DEAD = NETIF_PP_PHASE_OFFSET + 0, 64 NETIF_PPP_PHASE_MASTER = NETIF_PP_PHASE_OFFSET + 1, 65 NETIF_PPP_PHASE_HOLDOFF = NETIF_PP_PHASE_OFFSET + 2, 66 NETIF_PPP_PHASE_INITIALIZE = NETIF_PP_PHASE_OFFSET + 3, 67 NETIF_PPP_PHASE_SERIALCONN = NETIF_PP_PHASE_OFFSET + 4, 68 NETIF_PPP_PHASE_DORMANT = NETIF_PP_PHASE_OFFSET + 5, 69 NETIF_PPP_PHASE_ESTABLISH = NETIF_PP_PHASE_OFFSET + 6, 70 NETIF_PPP_PHASE_AUTHENTICATE = NETIF_PP_PHASE_OFFSET + 7, 71 NETIF_PPP_PHASE_CALLBACK = NETIF_PP_PHASE_OFFSET + 8, 72 NETIF_PPP_PHASE_NETWORK = NETIF_PP_PHASE_OFFSET + 9, 73 NETIF_PPP_PHASE_RUNNING = NETIF_PP_PHASE_OFFSET + 10, 74 NETIF_PPP_PHASE_TERMINATE = NETIF_PP_PHASE_OFFSET + 11, 75 NETIF_PPP_PHASE_DISCONNECT = NETIF_PP_PHASE_OFFSET + 12, 76 NETIF_PPP_CONNECT_FAILED = NETIF_PPP_INTERNAL_ERR_OFFSET + 0, 77 } esp_netif_ppp_status_event_t; 78 79 /** @brief definitions of different authorisation types 80 * 81 */ 82 typedef enum { 83 NETIF_PPP_AUTHTYPE_NONE = 0x00, 84 NETIF_PPP_AUTHTYPE_PAP = 0x01, 85 NETIF_PPP_AUTHTYPE_CHAP = 0x02, 86 NETIF_PPP_AUTHTYPE_MSCHAP = 0x04, 87 NETIF_PPP_AUTHTYPE_MSCHAP_V2 = 0x08, 88 NETIF_PPP_AUTHTYPE_EAP = 0x10, 89 } esp_netif_auth_type_t; 90 91 /** @brief Sets the auth parameters for the supplied esp-netif. 92 * 93 * @param[in] esp_netif Handle to esp-netif instance 94 * @param[in] authtype Authorisation type 95 * @param[in] user User name 96 * @param[in] passwd Password 97 * 98 * @return ESP_OK on success, 99 * ESP_ERR_ESP_NETIF_INVALID_PARAMS if the supplied netif is not of PPP type, or netif is null 100 */ 101 esp_err_t esp_netif_ppp_set_auth(esp_netif_t *netif, esp_netif_auth_type_t authtype, const char *user, const char *passwd); 102 103 /** @brief Sets common parameters for the supplied esp-netif. 104 * 105 * @param[in] esp_netif Handle to esp-netif instance 106 * @param[in] config Pointer to PPP netif configuration structure 107 * 108 * @return ESP_OK on success, 109 * ESP_ERR_ESP_NETIF_INVALID_PARAMS if the supplied netif is not of PPP type, or netif is null 110 */ 111 esp_err_t esp_netif_ppp_set_params(esp_netif_t *netif, const esp_netif_ppp_config_t *config); 112 113 /** @brief Gets parameters configured in the supplied esp-netif. 114 * 115 * @param[in] esp_netif Handle to esp-netif instance 116 * @param[out] config Pointer to PPP netif configuration structure 117 * 118 * @return ESP_OK on success, 119 * ESP_ERR_ESP_NETIF_INVALID_PARAMS if the supplied netif is not of PPP type, or netif is null 120 */ 121 esp_err_t esp_netif_ppp_get_params(esp_netif_t *netif, esp_netif_ppp_config_t *config); 122 123 #ifdef __cplusplus 124 } 125 #endif 126 127 #endif //_ESP_NETIF_PPP_H_ 128