1 // Copyright 2020 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_DPP_H 16 #define ESP_DPP_H 17 18 #include <stdbool.h> 19 20 #include "esp_err.h" 21 22 #ifdef __cplusplus 23 extern "C" { 24 #endif 25 26 #define ESP_ERR_DPP_FAILURE (ESP_ERR_WIFI_BASE + 151) /*!< Generic failure during DPP Operation */ 27 #define ESP_ERR_DPP_TX_FAILURE (ESP_ERR_WIFI_BASE + 152) /*!< DPP Frame Tx failed OR not Acked */ 28 #define ESP_ERR_DPP_INVALID_ATTR (ESP_ERR_WIFI_BASE + 153) /*!< Encountered invalid DPP Attribute */ 29 30 /** @brief Types of Bootstrap Methods for DPP. */ 31 typedef enum dpp_bootstrap_type { 32 DPP_BOOTSTRAP_QR_CODE, /**< QR Code Method */ 33 DPP_BOOTSTRAP_PKEX, /**< Proof of Knowledge Method */ 34 DPP_BOOTSTRAP_NFC_URI, /**< NFC URI record Method */ 35 } esp_supp_dpp_bootstrap_t; 36 37 /** @brief Types of Callback Events received from DPP Supplicant. */ 38 typedef enum { 39 ESP_SUPP_DPP_URI_READY, /**< URI is ready through Bootstrapping */ 40 ESP_SUPP_DPP_CFG_RECVD, /**< Config received via DPP Authentication */ 41 ESP_SUPP_DPP_FAIL, /**< DPP Authentication failure */ 42 } esp_supp_dpp_event_t; 43 44 /** 45 * @brief Callback function for receiving DPP Events from Supplicant. 46 * 47 * Callback function will be called with DPP related information. 48 * 49 * @param evt DPP event ID 50 * @param data Event data payload 51 */ 52 typedef void (*esp_supp_dpp_event_cb_t)(esp_supp_dpp_event_t evt, void *data); 53 54 /** 55 * @brief Initialize DPP Supplicant 56 * 57 * Starts DPP Supplicant and initializes related Data Structures. 58 * 59 * @param evt_cb Callback function to receive DPP related events 60 * 61 * return 62 * - ESP_OK: Success 63 * - ESP_FAIL: Failure 64 */ 65 esp_err_t esp_supp_dpp_init(esp_supp_dpp_event_cb_t evt_cb); 66 67 /** 68 * @brief De-initalize DPP Supplicant 69 * 70 * Frees memory from DPP Supplicant Data Structures. 71 */ 72 void esp_supp_dpp_deinit(void); 73 74 /** 75 * @brief Generates Bootstrap Information as an Enrollee. 76 * 77 * Generates Out Of Band Bootstrap information as an Enrollee which can be 78 * used by a DPP Configurator to provision the Enrollee. 79 * 80 * @param chan_list List of channels device will be available on for listening 81 * @param type Bootstrap method type, only QR Code method is supported for now. 82 * @param key (Optional) Private Key used to generate a Bootstrapping Public Key 83 * @param info (Optional) Ancilliary Device Information like Serial Number 84 * 85 * @return 86 * - ESP_OK: Success 87 * - ESP_FAIL: Failure 88 */ 89 esp_err_t 90 esp_supp_dpp_bootstrap_gen(const char *chan_list, esp_supp_dpp_bootstrap_t type, 91 const char *key, const char *info); 92 93 /** 94 * @brief Start listening on Channels provided during esp_supp_dpp_bootstrap_gen. 95 * 96 * Listens on every Channel from Channel List for a pre-defined wait time. 97 * 98 * @return 99 * - ESP_OK: Success 100 * - ESP_FAIL: Generic Failure 101 * - ESP_ERR_INVALID_STATE: ROC attempted before WiFi is started 102 * - ESP_ERR_NO_MEM: Memory allocation failed while posting ROC request 103 */ 104 esp_err_t esp_supp_dpp_start_listen(void); 105 106 /** 107 * @brief Stop listening on Channels. 108 * 109 * Stops listening on Channels and cancels ongoing listen operation. 110 */ 111 void esp_supp_dpp_stop_listen(void); 112 113 #ifdef __cplusplus 114 } 115 #endif 116 #endif /* ESP_DPP_H */ 117