1 // Copyright 2018 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 _WIFI_PROV_CONFIG_H_ 16 #define _WIFI_PROV_CONFIG_H_ 17 18 #include <lwip/inet.h> 19 20 #ifdef __cplusplus 21 extern "C" { 22 #endif 23 24 /** 25 * @brief WiFi STA status for conveying back to the provisioning master 26 */ 27 typedef enum { 28 WIFI_PROV_STA_CONNECTING, 29 WIFI_PROV_STA_CONNECTED, 30 WIFI_PROV_STA_DISCONNECTED 31 } wifi_prov_sta_state_t; 32 33 /** 34 * @brief WiFi STA connection fail reason 35 */ 36 typedef enum { 37 WIFI_PROV_STA_AUTH_ERROR, 38 WIFI_PROV_STA_AP_NOT_FOUND 39 } wifi_prov_sta_fail_reason_t; 40 41 /** 42 * @brief WiFi STA connected status information 43 */ 44 typedef struct { 45 /** 46 * IP Address received by station 47 */ 48 char ip_addr[IP4ADDR_STRLEN_MAX]; 49 50 char bssid[6]; /*!< BSSID of the AP to which connection was estalished */ 51 char ssid[33]; /*!< SSID of the to which connection was estalished */ 52 uint8_t channel; /*!< Channel of the AP */ 53 uint8_t auth_mode; /*!< Authorization mode of the AP */ 54 } wifi_prov_sta_conn_info_t; 55 56 /** 57 * @brief WiFi status data to be sent in response to `get_status` request from master 58 */ 59 typedef struct { 60 wifi_prov_sta_state_t wifi_state; /*!< WiFi state of the station */ 61 union { 62 /** 63 * Reason for disconnection (valid only when `wifi_state` is `WIFI_STATION_DISCONNECTED`) 64 */ 65 wifi_prov_sta_fail_reason_t fail_reason; 66 67 /** 68 * Connection information (valid only when `wifi_state` is `WIFI_STATION_CONNECTED`) 69 */ 70 wifi_prov_sta_conn_info_t conn_info; 71 }; 72 } wifi_prov_config_get_data_t; 73 74 /** 75 * @brief WiFi config data received by slave during `set_config` request from master 76 */ 77 typedef struct { 78 char ssid[33]; /*!< SSID of the AP to which the slave is to be connected */ 79 char password[64]; /*!< Password of the AP */ 80 char bssid[6]; /*!< BSSID of the AP */ 81 uint8_t channel; /*!< Channel of the AP */ 82 } wifi_prov_config_set_data_t; 83 84 /** 85 * @brief Type of context data passed to each get/set/apply handler 86 * function set in `wifi_prov_config_handlers` structure. 87 * 88 * This is passed as an opaque pointer, thereby allowing it be defined 89 * later in application code as per requirements. 90 */ 91 typedef struct wifi_prov_ctx wifi_prov_ctx_t; 92 93 /** 94 * @brief Internal handlers for receiving and responding to protocomm 95 * requests from master 96 * 97 * This is to be passed as priv_data for protocomm request handler 98 * (refer to `wifi_prov_config_data_handler()`) when calling `protocomm_add_endpoint()`. 99 */ 100 typedef struct wifi_prov_config_handlers { 101 /** 102 * Handler function called when connection status 103 * of the slave (in WiFi station mode) is requested 104 */ 105 esp_err_t (*get_status_handler)(wifi_prov_config_get_data_t *resp_data, 106 wifi_prov_ctx_t **ctx); 107 108 /** 109 * Handler function called when WiFi connection configuration 110 * (eg. AP SSID, password, etc.) of the slave (in WiFi station mode) 111 * is to be set to user provided values 112 */ 113 esp_err_t (*set_config_handler)(const wifi_prov_config_set_data_t *req_data, 114 wifi_prov_ctx_t **ctx); 115 116 /** 117 * Handler function for applying the configuration that was set in 118 * `set_config_handler`. After applying the station may get connected to 119 * the AP or may fail to connect. The slave must be ready to convey the 120 * updated connection status information when `get_status_handler` is 121 * invoked again by the master. 122 */ 123 esp_err_t (*apply_config_handler)(wifi_prov_ctx_t **ctx); 124 125 /** 126 * Context pointer to be passed to above handler functions upon invocation 127 */ 128 wifi_prov_ctx_t *ctx; 129 } wifi_prov_config_handlers_t; 130 131 /** 132 * @brief Handler for receiving and responding to requests from master 133 * 134 * This is to be registered as the `wifi_config` endpoint handler 135 * (protocomm `protocomm_req_handler_t`) using `protocomm_add_endpoint()` 136 */ 137 esp_err_t wifi_prov_config_data_handler(uint32_t session_id, const uint8_t *inbuf, ssize_t inlen, 138 uint8_t **outbuf, ssize_t *outlen, void *priv_data); 139 140 #ifdef __cplusplus 141 } 142 #endif 143 144 #endif 145