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