esp_wpa2.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. // Hardware crypto support Copyright 2017 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. #ifndef ESP_WPA2_H
  14. #define ESP_WPA2_H
  15. #include <stdbool.h>
  16. #include "esp_err.h"
  17. #include "esp_wifi_crypto_types.h"
  18. #ifdef __cplusplus
  19. extern "C" {
  20. #endif
  21. extern const wpa2_crypto_funcs_t g_wifi_default_wpa2_crypto_funcs;
  22. typedef struct {
  23. const wpa2_crypto_funcs_t *crypto_funcs;
  24. }esp_wpa2_config_t;
  25. #define WPA2_CONFIG_INIT_DEFAULT() { \
  26. .crypto_funcs = &g_wifi_default_wpa2_crypto_funcs \
  27. }
  28. /**
  29. * @brief Enable wpa2 enterprise authentication.
  30. *
  31. * @attention 1. wpa2 enterprise authentication can only be used when ESP32 station is enabled.
  32. * @attention 2. wpa2 enterprise authentication can only support TLS, PEAP-MSCHAPv2 and TTLS-MSCHAPv2 method.
  33. *
  34. * @return
  35. * - ESP_OK: succeed.
  36. * - ESP_ERR_NO_MEM: fail(internal memory malloc fail)
  37. */
  38. esp_err_t esp_wifi_sta_wpa2_ent_enable(const esp_wpa2_config_t *config);
  39. /**
  40. * @brief Disable wpa2 enterprise authentication.
  41. *
  42. * @attention 1. wpa2 enterprise authentication can only be used when ESP32 station is enabled.
  43. * @attention 2. wpa2 enterprise authentication can only support TLS, PEAP-MSCHAPv2 and TTLS-MSCHAPv2 method.
  44. *
  45. * @return
  46. * - ESP_OK: succeed.
  47. */
  48. esp_err_t esp_wifi_sta_wpa2_ent_disable(void);
  49. /**
  50. * @brief Set identity for PEAP/TTLS method.
  51. *
  52. * @attention The API only passes the parameter identity to the global pointer variable in wpa2 enterprise module.
  53. *
  54. * @param identity: point to address where stores the identity;
  55. * @param len: length of identity, limited to 1~127
  56. *
  57. * @return
  58. * - ESP_OK: succeed
  59. * - ESP_ERR_INVALID_ARG: fail(len <= 0 or len >= 128)
  60. * - ESP_ERR_NO_MEM: fail(internal memory malloc fail)
  61. */
  62. esp_err_t esp_wifi_sta_wpa2_ent_set_identity(const unsigned char *identity, int len);
  63. /**
  64. * @brief Clear identity for PEAP/TTLS method.
  65. */
  66. void esp_wifi_sta_wpa2_ent_clear_identity(void);
  67. /**
  68. * @brief Set username for PEAP/TTLS method.
  69. *
  70. * @attention The API only passes the parameter username to the global pointer variable in wpa2 enterprise module.
  71. *
  72. * @param username: point to address where stores the username;
  73. * @param len: length of username, limited to 1~127
  74. *
  75. * @return
  76. * - ESP_OK: succeed
  77. * - ESP_ERR_INVALID_ARG: fail(len <= 0 or len >= 128)
  78. * - ESP_ERR_NO_MEM: fail(internal memory malloc fail)
  79. */
  80. esp_err_t esp_wifi_sta_wpa2_ent_set_username(const unsigned char *username, int len);
  81. /**
  82. * @brief Clear username for PEAP/TTLS method.
  83. */
  84. void esp_wifi_sta_wpa2_ent_clear_username(void);
  85. /**
  86. * @brief Set password for PEAP/TTLS method..
  87. *
  88. * @attention The API only passes the parameter password to the global pointer variable in wpa2 enterprise module.
  89. *
  90. * @param password: point to address where stores the password;
  91. * @param len: length of password(len > 0)
  92. *
  93. * @return
  94. * - ESP_OK: succeed
  95. * - ESP_ERR_INVALID_ARG: fail(len <= 0)
  96. * - ESP_ERR_NO_MEM: fail(internal memory malloc fail)
  97. */
  98. esp_err_t esp_wifi_sta_wpa2_ent_set_password(const unsigned char *password, int len);
  99. /**
  100. * @brief Clear password for PEAP/TTLS method..
  101. */
  102. void esp_wifi_sta_wpa2_ent_clear_password(void);
  103. /**
  104. * @brief Set new password for MSCHAPv2 method..
  105. *
  106. * @attention 1. The API only passes the parameter password to the global pointer variable in wpa2 enterprise module.
  107. * @attention 2. The new password is used to substitute the old password when eap-mschapv2 failure request message with error code ERROR_PASSWD_EXPIRED is received.
  108. *
  109. * @param new_password: point to address where stores the password;
  110. * @param len: length of password
  111. *
  112. * @return
  113. * - ESP_OK: succeed
  114. * - ESP_ERR_INVALID_ARG: fail(len <= 0)
  115. * - ESP_ERR_NO_MEM: fail(internal memory malloc fail)
  116. */
  117. esp_err_t esp_wifi_sta_wpa2_ent_set_new_password(const unsigned char *new_password, int len);
  118. /**
  119. * @brief Clear new password for MSCHAPv2 method..
  120. */
  121. void esp_wifi_sta_wpa2_ent_clear_new_password(void);
  122. /**
  123. * @brief Set CA certificate for PEAP/TTLS method.
  124. *
  125. * @attention 1. The API only passes the parameter ca_cert to the global pointer variable in wpa2 enterprise module.
  126. * @attention 2. The ca_cert should be zero terminated.
  127. *
  128. * @param ca_cert: point to address where stores the CA certificate;
  129. * @param ca_cert_len: length of ca_cert
  130. *
  131. * @return
  132. * - ESP_OK: succeed
  133. */
  134. esp_err_t esp_wifi_sta_wpa2_ent_set_ca_cert(const unsigned char *ca_cert, int ca_cert_len);
  135. /**
  136. * @brief Clear CA certificate for PEAP/TTLS method.
  137. */
  138. void esp_wifi_sta_wpa2_ent_clear_ca_cert(void);
  139. /**
  140. * @brief Set client certificate and key.
  141. *
  142. * @attention 1. The API only passes the parameter client_cert, private_key and private_key_passwd to the global pointer variable in wpa2 enterprise module.
  143. * @attention 2. The client_cert, private_key and private_key_passwd should be zero terminated.
  144. *
  145. * @param client_cert: point to address where stores the client certificate;
  146. * @param client_cert_len: length of client certificate;
  147. * @param private_key: point to address where stores the private key;
  148. * @param private_key_len: length of private key, limited to 1~2048;
  149. * @param private_key_password: point to address where stores the private key password;
  150. * @param private_key_password_len: length of private key password;
  151. *
  152. * @return
  153. * - ESP_OK: succeed
  154. */
  155. esp_err_t esp_wifi_sta_wpa2_ent_set_cert_key(const unsigned char *client_cert, int client_cert_len, const unsigned char *private_key, int private_key_len, const unsigned char *private_key_passwd, int private_key_passwd_len);
  156. /**
  157. * @brief Clear client certificate and key.
  158. */
  159. void esp_wifi_sta_wpa2_ent_clear_cert_key(void);
  160. /**
  161. * @brief Set wpa2 enterprise certs time check(disable or not).
  162. *
  163. * @param true: disable wpa2 enterprise certs time check
  164. * @param false: enable wpa2 enterprise certs time check
  165. *
  166. * @return
  167. * - ESP_OK: succeed
  168. */
  169. esp_err_t esp_wifi_sta_wpa2_ent_set_disable_time_check(bool disable);
  170. /**
  171. * @brief Get wpa2 enterprise certs time check(disable or not).
  172. *
  173. * @param disable: store disable value
  174. *
  175. * @return
  176. * - ESP_OK: succeed
  177. */
  178. esp_err_t esp_wifi_sta_wpa2_ent_get_disable_time_check(bool *disable);
  179. #ifdef __cplusplus
  180. }
  181. #endif
  182. #endif