esp_wps.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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. /* C & C++ compilers have different rules about C99-style named initializers */
  63. #ifdef __cplusplus
  64. #define WPS_AGG(X) { X }
  65. #else
  66. #define WPS_AGG(X) X
  67. #endif
  68. #define WPS_CONFIG_INIT_DEFAULT(type) { \
  69. .wps_type = type, \
  70. .crypto_funcs = &g_wifi_default_wps_crypto_funcs, \
  71. .factory_info = { \
  72. WPS_AGG( .manufacturer = "ESPRESSIF" ), \
  73. WPS_AGG( .model_number = "ESP32" ), \
  74. WPS_AGG( .model_name = "ESPRESSIF IOT" ), \
  75. WPS_AGG( .device_name = "ESP STATION" ), \
  76. } \
  77. }
  78. /**
  79. * @brief Enable Wi-Fi WPS function.
  80. *
  81. * @attention WPS can only be used when ESP32 station is enabled.
  82. *
  83. * @param wps_type_t wps_type : WPS type, so far only WPS_TYPE_PBC and WPS_TYPE_PIN is supported
  84. *
  85. * @return
  86. * - ESP_OK : succeed
  87. * - ESP_ERR_WIFI_WPS_TYPE : wps type is invalid
  88. * - ESP_ERR_WIFI_WPS_MODE : wifi is not in station mode or sniffer mode is on
  89. * - ESP_FAIL : wps initialization fails
  90. */
  91. esp_err_t esp_wifi_wps_enable(const esp_wps_config_t *config);
  92. /**
  93. * @brief Disable Wi-Fi WPS function and release resource it taken.
  94. *
  95. * @param null
  96. *
  97. * @return
  98. * - ESP_OK : succeed
  99. * - ESP_ERR_WIFI_WPS_MODE : wifi is not in station mode or sniffer mode is on
  100. */
  101. esp_err_t esp_wifi_wps_disable(void);
  102. /**
  103. * @brief WPS starts to work.
  104. *
  105. * @attention WPS can only be used when ESP32 station is enabled.
  106. *
  107. * @param timeout_ms : maximum blocking time before API return.
  108. * - 0 : non-blocking
  109. * - 1~120000 : blocking time (not supported in IDF v1.0)
  110. *
  111. * @return
  112. * - ESP_OK : succeed
  113. * - ESP_ERR_WIFI_WPS_TYPE : wps type is invalid
  114. * - ESP_ERR_WIFI_WPS_MODE : wifi is not in station mode or sniffer mode is on
  115. * - ESP_ERR_WIFI_WPS_SM : wps state machine is not initialized
  116. * - ESP_FAIL : wps initialization fails
  117. */
  118. esp_err_t esp_wifi_wps_start(int timeout_ms);
  119. /**
  120. * @}
  121. */
  122. /**
  123. * @}
  124. */
  125. #ifdef __cplusplus
  126. }
  127. #endif
  128. #endif /* __ESP_WPS_H__ */