fix(esp_netif): Add API docs to DHCP client/server operations

This commit is contained in:
David Cermak 2024-05-02 16:41:24 +02:00
parent 3035ce294d
commit 8103d5bc34
3 changed files with 33 additions and 4 deletions

View File

@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2019-2023 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2019-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@ -594,6 +594,23 @@ esp_err_t esp_netif_napt_disable(esp_netif_t *esp_netif);
/**
* @brief Set or Get DHCP server option
*
* @note Please note that not all combinations of identifiers and options are supported.
* Get operations:
* * IP_ADDRESS_LEASE_TIME
* * ESP_NETIF_SUBNET_MASK/REQUESTED_IP_ADDRESS (both options do the same, they reflect dhcps_lease_t)
* * ROUTER_SOLICITATION_ADDRESS
* * DOMAIN_NAME_SERVER
* Set operations:
* * IP_ADDRESS_LEASE_TIME
* * ESP_NETIF_SUBNET_MASK -- set operation is allowed only if the configured mask corresponds to the settings,
* if not, please use esp_netif_set_ip_info() to prevent misconfiguration of DHCPS.
* * REQUESTED_IP_ADDRESS -- if the address pool is enabled, a sanity check for start/end addresses is performed
* before setting.
* * ROUTER_SOLICITATION_ADDRESS
* * DOMAIN_NAME_SERVER
* * ESP_NETIF_CAPTIVEPORTAL_URI -- set operation copies the pointer to the URI, so it is owned by the application
* and needs to be maintained valid throughout the entire DHCP Server lifetime.
*
* @param[in] esp_netif Handle to esp-netif instance
* @param[in] opt_op ESP_NETIF_OP_SET to set an option, ESP_NETIF_OP_GET to get an option.
* @param[in] opt_id Option index to get or set, must be one of the supported enum values.
@ -613,6 +630,16 @@ esp_netif_dhcps_option(esp_netif_t *esp_netif, esp_netif_dhcp_option_mode_t opt_
/**
* @brief Set or Get DHCP client option
*
* @note Please note that not all combinations of identifiers and options are supported.
* Get operations:
* * ESP_NETIF_IP_REQUEST_RETRY_TIME
* * ESP_NETIF_VENDOR_SPECIFIC_INFO -- only available if ESP_DHCP_DISABLE_VENDOR_CLASS_IDENTIFIER=n
* Set operations:
* * ESP_NETIF_IP_REQUEST_RETRY_TIME
* * ESP_NETIF_VENDOR_SPECIFIC_INFO -- only available if ESP_DHCP_DISABLE_VENDOR_CLASS_IDENTIFIER=n
* lwip layer creates its own copy of the supplied identifier.
* (the internal copy could be feed by calling dhcp_free_vendor_class_identifier())
*
* @param[in] esp_netif Handle to esp-netif instance
* @param[in] opt_op ESP_NETIF_OP_SET to set an option, ESP_NETIF_OP_GET to get an option.
* @param[in] opt_id Option index to get or set, must be one of the supported enum values.

View File

@ -126,4 +126,4 @@ Note `URL (114)` with the AP address.
URL (114), length 18: "http://192.168.4.1"
Router-Discovery (31), length 1: N
Vendor-Option (43), length 6: 1.4.0.0.0.2
```
```

View File

@ -24,7 +24,6 @@
#define EXAMPLE_ESP_WIFI_SSID CONFIG_ESP_WIFI_SSID
#define EXAMPLE_ESP_WIFI_PASS CONFIG_ESP_WIFI_PASSWORD
#define EXAMPLE_MAX_STA_CONN CONFIG_ESP_MAX_STA_CONN
#define EXAMPLE_ENABLE_DHCP_CAPTIVEPORTAL_URI CONFIG_ESP_ENABLE_DHCP_CAPTIVEPORTAL
extern const char root_start[] asm("_binary_root_html_start");
extern const char root_end[] asm("_binary_root_html_end");
@ -80,6 +79,7 @@ static void wifi_init_softap(void)
EXAMPLE_ESP_WIFI_SSID, EXAMPLE_ESP_WIFI_PASS);
}
#ifdef CONFIG_ESP_ENABLE_DHCP_CAPTIVEPORTAL
static void dhcp_set_captiveportal_url(void) {
// get the IP of the access point to redirect to
esp_netif_ip_info_t ip_info;
@ -91,6 +91,7 @@ static void dhcp_set_captiveportal_url(void) {
// turn the IP into a URI
char* captiveportal_uri = (char*) malloc(32 * sizeof(char));
assert(captiveportal_uri && "Failed to allocate captiveportal_uri");
strcpy(captiveportal_uri, "http://");
strcat(captiveportal_uri, ip_addr);
@ -102,6 +103,7 @@ static void dhcp_set_captiveportal_url(void) {
ESP_ERROR_CHECK(esp_netif_dhcps_option(netif, ESP_NETIF_OP_SET, ESP_NETIF_CAPTIVEPORTAL_URI, captiveportal_uri, strlen(captiveportal_uri)));
ESP_ERROR_CHECK_WITHOUT_ABORT(esp_netif_dhcps_start(netif));
}
#endif // CONFIG_ESP_ENABLE_DHCP_CAPTIVEPORTAL
// HTTP GET Handler
static esp_err_t root_get_handler(httpd_req_t *req)
@ -180,7 +182,7 @@ void app_main(void)
wifi_init_softap();
// Configure DNS-based captive portal, if configured
#if CONFIG_ESP_ENABLE_DHCP_CAPTIVEPORTAL
#ifdef CONFIG_ESP_ENABLE_DHCP_CAPTIVEPORTAL
dhcp_set_captiveportal_url();
#endif