esp_wps.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. // Copyright 2015-2016 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_WPS_H__
  14. #define __ESP_WPS_H__
  15. #include <stdint.h>
  16. #include <stdbool.h>
  17. #include "esp_err.h"
  18. #include "esp_wifi_crypto_types.h"
  19. #ifdef __cplusplus
  20. extern "C" {
  21. #endif
  22. /** \defgroup WiFi_APIs WiFi Related APIs
  23. * @brief WiFi APIs
  24. */
  25. /** @addtogroup WiFi_APIs
  26. * @{
  27. */
  28. /** \defgroup WPS_APIs WPS APIs
  29. * @brief ESP32 WPS APIs
  30. *
  31. * WPS can only be used when ESP32 station is enabled.
  32. *
  33. */
  34. /** @addtogroup WPS_APIs
  35. * @{
  36. */
  37. #define ESP_ERR_WIFI_REGISTRAR (ESP_ERR_WIFI_BASE + 51) /*!< WPS registrar is not supported */
  38. #define ESP_ERR_WIFI_WPS_TYPE (ESP_ERR_WIFI_BASE + 52) /*!< WPS type error */
  39. #define ESP_ERR_WIFI_WPS_SM (ESP_ERR_WIFI_BASE + 53) /*!< WPS state machine is not initialized */
  40. typedef enum wps_type {
  41. WPS_TYPE_DISABLE = 0,
  42. WPS_TYPE_PBC,
  43. WPS_TYPE_PIN,
  44. WPS_TYPE_MAX,
  45. } wps_type_t;
  46. extern const wps_crypto_funcs_t g_wifi_default_wps_crypto_funcs;
  47. #define WPS_MAX_MANUFACTURER_LEN 65
  48. #define WPS_MAX_MODEL_NUMBER_LEN 33
  49. #define WPS_MAX_MODEL_NAME_LEN 33
  50. #define WPS_MAX_DEVICE_NAME_LEN 33
  51. typedef struct {
  52. char manufacturer[WPS_MAX_MANUFACTURER_LEN]; /*!< Manufacturer, null-terminated string. The default manufcturer is used if the string is empty */
  53. char model_number[WPS_MAX_MODEL_NUMBER_LEN]; /*!< Model number, null-terminated string. The default model number is used if the string is empty */
  54. char model_name[WPS_MAX_MODEL_NAME_LEN]; /*!< Model name, null-terminated string. The default model name is used if the string is empty */
  55. char device_name[WPS_MAX_DEVICE_NAME_LEN]; /*!< Device name, null-terminated string. The default device name is used if the string is empty */
  56. } wps_factory_information_t;
  57. typedef struct {
  58. wps_type_t wps_type;
  59. const wps_crypto_funcs_t *crypto_funcs;
  60. wps_factory_information_t factory_info;
  61. } esp_wps_config_t;
  62. #define WPS_CONFIG_INIT_DEFAULT(type) { \
  63. .wps_type = type, \
  64. .crypto_funcs = &g_wifi_default_wps_crypto_funcs, \
  65. .factory_info = { \
  66. .manufacturer = "ESPRESSIF", \
  67. .model_number = "ESP32", \
  68. .model_name = "ESPRESSIF IOT", \
  69. .device_name = "ESP STATION", \
  70. } \
  71. }
  72. /**
  73. * @brief Enable Wi-Fi WPS function.
  74. *
  75. * @attention WPS can only be used when ESP32 station is enabled.
  76. *
  77. * @param wps_type_t wps_type : WPS type, so far only WPS_TYPE_PBC and WPS_TYPE_PIN is supported
  78. *
  79. * @return
  80. * - ESP_OK : succeed
  81. * - ESP_ERR_WIFI_WPS_TYPE : wps type is invalid
  82. * - ESP_ERR_WIFI_WPS_MODE : wifi is not in station mode or sniffer mode is on
  83. * - ESP_FAIL : wps initialization fails
  84. */
  85. esp_err_t esp_wifi_wps_enable(const esp_wps_config_t *config);
  86. /**
  87. * @brief Disable Wi-Fi WPS function and release resource it taken.
  88. *
  89. * @param null
  90. *
  91. * @return
  92. * - ESP_OK : succeed
  93. * - ESP_ERR_WIFI_WPS_MODE : wifi is not in station mode or sniffer mode is on
  94. */
  95. esp_err_t esp_wifi_wps_disable(void);
  96. /**
  97. * @brief WPS starts to work.
  98. *
  99. * @attention WPS can only be used when ESP32 station is enabled.
  100. *
  101. * @param timeout_ms : maximum blocking time before API return.
  102. * - 0 : non-blocking
  103. * - 1~120000 : blocking time (not supported in IDF v1.0)
  104. *
  105. * @return
  106. * - ESP_OK : succeed
  107. * - ESP_ERR_WIFI_WPS_TYPE : wps type is invalid
  108. * - ESP_ERR_WIFI_WPS_MODE : wifi is not in station mode or sniffer mode is on
  109. * - ESP_ERR_WIFI_WPS_SM : wps state machine is not initialized
  110. * - ESP_FAIL : wps initialization fails
  111. */
  112. esp_err_t esp_wifi_wps_start(int timeout_ms);
  113. /**
  114. * @}
  115. */
  116. /**
  117. * @}
  118. */
  119. #ifdef __cplusplus
  120. }
  121. #endif
  122. #endif /* __ESP_WPS_H__ */