How to use esp_netif_dhcpc_option?

ldudel
Posts: 9
Joined: Thu Jun 24, 2021 11:23 pm

How to use esp_netif_dhcpc_option?

Postby ldudel » Tue May 10, 2022 5:00 pm

I'm trying to fix several issues related to DHCP, and I'm really struggling with the scarce documentation.

Does anyone know where to find documentation for this function? The opt_val parameter is critical, but I can't find any documentation for it.

Code: Select all

esp_err_t esp_netif_dhcpc_option(esp_netif_t *esp_netif, esp_netif_dhcp_option_mode_topt_op, esp_netif_dhcp_option_id_topt_id, void *opt_val, uint32_t opt_len)
The parameters of the function are described, and I can look up what options there are in the first structs. I think I want:

Code: Select all

esp_netif_dhcps_option(netIfInstancePtr
			, ESP_NETIF_OP_SET
			, ESP_NETIF_DOMAIN_NAME_SERVER
			, void* opt_val
			, uint32_t opt_len);
Could someone please point me in the right direction? What goes into opt_val?

ESP_YJM
Posts: 300
Joined: Fri Feb 26, 2021 10:30 am

Re: How to use esp_netif_dhcpc_option?

Postby ESP_YJM » Wed May 11, 2022 2:04 am

The opt_val is a void type pointer. It can be input or output data depend on opt_op is GET or SET.
For example, if you want to set dhcp->tries, you can follow this code:

Code: Select all

uint8_t tries;
uint32_t len = sizeof(tries);
esp_netif_dhcpc_option(esp_netif, ESP_NETIF_OP_SET, ESP_NETIF_IP_REQUEST_RETRY_TIME, &tries, len);

ldudel
Posts: 9
Joined: Thu Jun 24, 2021 11:23 pm

Re: How to use esp_netif_dhcpc_option?

Postby ldudel » Wed May 11, 2022 6:38 pm

Thanks, I'm with you thus far. But how can I know what the pointer is supposed to point to?

Here are all the valid options:

Code: Select all

typedef enum{
    ESP_NETIF_SUBNET_MASK                   = 1,    /**< Network mask */
    ESP_NETIF_DOMAIN_NAME_SERVER            = 6,    /**< Domain name server */
    ESP_NETIF_ROUTER_SOLICITATION_ADDRESS   = 32,   /**< Solicitation router address */
    ESP_NETIF_REQUESTED_IP_ADDRESS          = 50,   /**< Request specific IP address */
    ESP_NETIF_IP_ADDRESS_LEASE_TIME         = 51,   /**< Request IP address lease time */
    ESP_NETIF_IP_REQUEST_RETRY_TIME         = 52,   /**< Request IP address retry counter */
    ESP_NETIF_VENDOR_CLASS_IDENTIFIER       = 60,   /**< Vendor Class Identifier of a DHCP client */
    ESP_NETIF_VENDOR_SPECIFIC_INFO          = 43,   /**< Vendor Specific Information of a DHCP server */
} esp_netif_dhcp_option_id_t;
You are saying that for ESP_NETIF_IP_REQUEST_RETRY_TIME, opt_val is a pointer to one byte of uint8_t. But some of the others are IP addresses that are probably represented by one uint32_t. How do we know which one?

Specifically, in the case of ESP_NETIF_DOMAIN_NAME_SERVER, what is the opt_val? A 32-bit IP or something else?

Thanks

ESP_YJM
Posts: 300
Joined: Fri Feb 26, 2021 10:30 am

Re: How to use esp_netif_dhcpc_option?

Postby ESP_YJM » Thu May 12, 2022 2:02 am

The ESP_NETIF_DOMAIN_NAME_SERVER is in https://github.com/espressif/esp-idf/bl ... ip.c#L1808 and you can see the opt_val is uint8_t.

izzizey
Posts: 2
Joined: Tue Jul 11, 2023 11:31 pm

Re: How to use esp_netif_dhcpc_option?

Postby izzizey » Wed Jul 12, 2023 10:17 pm

ldudel wrote:
Wed May 11, 2022 6:38 pm
Thanks, I'm with you thus far. But how can I know what the pointer is supposed to point to?

Here are all the valid options:

Code: Select all

typedef enum{
    ESP_NETIF_SUBNET_MASK                   = 1,    /**< Network mask */
    ESP_NETIF_DOMAIN_NAME_SERVER            = 6,    /**< Domain name server */
    ESP_NETIF_ROUTER_SOLICITATION_ADDRESS   = 32,   /**< Solicitation router address */
    ESP_NETIF_REQUESTED_IP_ADDRESS          = 50,   /**< Request specific IP address */
    ESP_NETIF_IP_ADDRESS_LEASE_TIME         = 51,   /**< Request IP address lease time */
    ESP_NETIF_IP_REQUEST_RETRY_TIME         = 52,   /**< Request IP address retry counter */
    ESP_NETIF_VENDOR_CLASS_IDENTIFIER       = 60,   /**< Vendor Class Identifier of a DHCP client */
    ESP_NETIF_VENDOR_SPECIFIC_INFO          = 43,   /**< Vendor Specific Information of a DHCP server */
} esp_netif_dhcp_option_id_t;
You are saying that for ESP_NETIF_IP_REQUEST_RETRY_TIME, opt_val is a pointer to one byte of uint8_t. But some of the others are IP addresses that are probably represented by one uint32_t. How do we know which one?

Specifically, in the case of ESP_NETIF_DOMAIN_NAME_SERVER, what is the opt_val? A 32-bit IP or something else?

Thanks
what does ESP_NETIF_ROUTER_SOLICITATION_ADDRESS = 32 even mean? This is supposed to be an ip address right? Why is it just a number. How would i change the ip to something like 192.168.1.1?

ESP_YJM
Posts: 300
Joined: Fri Feb 26, 2021 10:30 am

Re: How to use esp_netif_dhcpc_option?

Postby ESP_YJM » Tue Aug 29, 2023 9:22 am

You can use ipaddr_ntoa_r to convert it to string.

Who is online

Users browsing this forum: No registered users and 108 guests