esp_netif_ppp.h 4.3 KB

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