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