1 /* SoftAP based 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 
17 /**
18  * @brief   Get state of WiFi Station during provisioning
19  *
20  * @note    WiFi is initially configured as AP, when
21  *          provisioning starts. After provisioning data
22  *          is provided by user, the WiFi is reconfigured
23  *          to run as both AP and Station.
24  *
25  * @param[out] state    Pointer to wifi_prov_sta_state_t variable to be filled
26  *
27  * @return
28  *  - ESP_OK    : Successfully retrieved wifi state
29  *  - ESP_FAIL  : Provisioning app not running
30  */
31 esp_err_t app_prov_get_wifi_state(wifi_prov_sta_state_t* state);
32 
33 /**
34  * @brief   Get reason code in case of WiFi station
35  *          disconnection during provisioning
36  *
37 * @param[out] reason    Pointer to wifi_prov_sta_fail_reason_t variable to be filled
38  *
39  * @return
40  *  - ESP_OK    : Successfully retrieved wifi disconnect reason
41  *  - ESP_FAIL  : Provisioning app not running
42  */
43 esp_err_t app_prov_get_wifi_disconnect_reason(wifi_prov_sta_fail_reason_t* reason);
44 
45 /**
46  * @brief   Checks if device is provisioned
47  * *
48  * @param[out] provisioned  True if provisioned, else false
49  *
50  * @return
51  *  - ESP_OK      : Retrieved provision state successfully
52  *  - ESP_FAIL    : Failed to retrieve provision state
53  */
54 esp_err_t app_prov_is_provisioned(bool *provisioned);
55 
56 /**
57  * @brief   Runs WiFi as both AP and Station
58  *
59  * Configures the WiFi station mode to connect to the
60  * SSID and password specified in config structure,
61  * and restarts WiFi to run as both AP and station
62  *
63  * @param[in] wifi_cfg  Pointer to WiFi cofiguration structure
64  *
65  * @return
66  *  - ESP_OK      : WiFi configured and restarted successfully
67  *  - ESP_FAIL    : Failed to set configuration
68  */
69 esp_err_t app_prov_configure_sta(wifi_config_t *wifi_cfg);
70 
71 /**
72  * @brief   Start provisioning via softAP
73  *
74  * Starts the WiFi softAP with specified ssid and pass, provisioning
75  * security mode and proof of possession (if any).
76  *
77  * @param[in] ssid      SSID for SoftAP
78  * @param[in] pass      Password for SoftAP
79  * @param[in] security  Security mode
80  * @param[in] pop       Pointer to proof of possession (NULL if not present)
81  *
82  * @return
83  *  - ESP_OK      : Provisioning started successfully
84  *  - ESP_FAIL    : Failed to start
85  */
86 esp_err_t app_prov_start_softap_provisioning(const char *ssid, const char *pass,
87                                              int security, const protocomm_security_pop_t *pop);
88