1 /* SoftAP based Custom Provisioning Example
2 
3    This example code is in the Public Domain (or CC0 licensed, at your option.)
4 
5    Unless required by applicable law or agreed to in writing, this
6    software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
7    CONDITIONS OF ANY KIND, either express or implied.
8 */
9 
10 #pragma once
11 
12 #include <esp_event.h>
13 
14 #include <protocomm_security.h>
15 #include <wifi_provisioning/wifi_config.h>
16 #include <custom_provisioning/custom_config.h>
17 
18 /**
19  * @brief   Get state of WiFi Station during provisioning
20  *
21  * @note    WiFi is initially configured as AP, when
22  *          provisioning starts. After provisioning data
23  *          is provided by user, the WiFi is reconfigured
24  *          to run as both AP and Station.
25  *
26  * @param[out] state    Pointer to wifi_prov_sta_state_t variable to be filled
27  *
28  * @return
29  *  - ESP_OK    : Successfully retrieved wifi state
30  *  - ESP_FAIL  : Provisioning app not running
31  */
32 esp_err_t app_prov_get_wifi_state(wifi_prov_sta_state_t* state);
33 
34 /**
35  * @brief   Get reason code in case of WiFi station
36  *          disconnection during provisioning
37  *
38 * @param[out] reason    Pointer to wifi_prov_sta_fail_reason_t variable to be filled
39  *
40  * @return
41  *  - ESP_OK    : Successfully retrieved wifi disconnect reason
42  *  - ESP_FAIL  : Provisioning app not running
43  */
44 esp_err_t app_prov_get_wifi_disconnect_reason(wifi_prov_sta_fail_reason_t* reason);
45 
46 /**
47  * @brief   Checks if device is provisioned
48  * *
49  * @param[out] provisioned  True if provisioned, else false
50  *
51  * @return
52  *  - ESP_OK      : Retrieved provision state successfully
53  *  - ESP_FAIL    : Failed to retrieve provision state
54  */
55 esp_err_t app_prov_is_provisioned(bool *provisioned);
56 
57 /**
58  * @brief   Runs WiFi as both AP and Station
59  *
60  * Configures the WiFi station mode to connect to the
61  * SSID and password specified in config structure,
62  * and restarts WiFi to run as both AP and station
63  *
64  * @param[in] wifi_cfg  Pointer to WiFi cofiguration structure
65  *
66  * @return
67  *  - ESP_OK      : WiFi configured and restarted successfully
68  *  - ESP_FAIL    : Failed to set configuration
69  */
70 esp_err_t app_prov_configure_sta(wifi_config_t *wifi_cfg);
71 
72 /**
73  * @brief   Start provisioning via softAP
74  *
75  * Starts the WiFi softAP with specified ssid and pass, provisioning
76  * security mode and proof of possession (if any).
77  *
78  * @param[in] ssid      SSID for SoftAP
79  * @param[in] pass      Password for SoftAP
80  * @param[in] security  Security mode
81  * @param[in] pop       Pointer to proof of possession (NULL if not present)
82  *
83  * @return
84  *  - ESP_OK      : Provisioning started successfully
85  *  - ESP_FAIL    : Failed to start
86  */
87 esp_err_t app_prov_start_softap_provisioning(const char *ssid, const char *pass,
88                                              int security, const protocomm_security_pop_t *pop);
89