Advertisement
martinius96

ESP_WPA2.h - 2019

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