esp_netif_ppp.h 4.9 KB

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