esp_netif_ppp.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. * SPDX-FileCopyrightText: 2019-2023 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. //
  7. #ifndef _ESP_NETIF_PPP_H_
  8. #define _ESP_NETIF_PPP_H_
  9. #ifdef __cplusplus
  10. extern "C" {
  11. #endif
  12. /** @brief PPP event base */
  13. ESP_EVENT_DECLARE_BASE(NETIF_PPP_STATUS);
  14. /** @brief Configuration structure for PPP network interface
  15. *
  16. */
  17. typedef struct esp_netif_ppp_config {
  18. bool ppp_phase_event_enabled; /**< Enables events coming from PPP PHASE change */
  19. bool ppp_error_event_enabled; /**< Enables events from main PPP state machine producing errors */
  20. #ifdef CONFIG_LWIP_ENABLE_LCP_ECHO
  21. bool ppp_lcp_echo_disabled; /**< Allows to temporarily disable LCP keepalive (runtime, if enabled compile time)
  22. * When LCP echo is enabled in menuconfig, this option can be used to override the setting,
  23. * if we have to relax LCP keepalive criteria during runtime operation, for example before OTA update.
  24. * The current session must be closed, settings will be applied upon connecting.
  25. * */
  26. #endif // CONFIG_LWIP_ENABLE_LCP_ECHO
  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_