Interface addresses in APSTA mode

jdwix615
Posts: 7
Joined: Thu Feb 01, 2018 10:06 pm

Interface addresses in APSTA mode

Postby jdwix615 » Wed Jul 11, 2018 2:37 am

Hi all,

I am running with wifi initialised in APSTA mode currently.

What I'm trying to do is setup the station and softAP interface with different IP addresses in different subnets when the Station has connected to an AP.

So what happens is the Station connects to its network, then the AP is reconfigured with an IP address in a different subnet.
However, when I configure the AP after the Station connects the Station's IP addresses are changed to what the AP is configured with.
Screenshot from 2018-07-11 12-30-15.png
Screenshot from 2018-07-11 12-30-15.png (43.3 KiB) Viewed 6014 times
The image shows the gist of what I'm talking about from the terminal. The Station gets its DHCP assigned address, then the AP's is changed, but the event comes back syaing the sta ip is changed...

My code to change the AP IP stops the DHCP server, makes the change and re enables.

Code: Select all

ESP_ERROR_CHECK(tcpip_adapter_dhcps_stop(TCPIP_ADAPTER_IF_AP));
tcpip_adapter_ip_info_t ap_ip_info;
memset(&ap_ip_info, 0, sizeof(ap_ip_info));
IP4_ADDR(&ap_ip_info.ip, 192, 168, 4, first_host_addr);
IP4_ADDR(&ap_ip_info.netmask, 255, 255, 255, subnet_last8);
IP4_ADDR(&ap_ip_info.gw, 192, 168, 4, first_host_addr);
ESP_ERROR_CHECK(tcpip_adapter_set_ip_info(TCPIP_ADAPTER_IF_AP, &ap_ip_info));
ESP_ERROR_CHECK(tcpip_adapter_dhcpc_start(TCPIP_ADAPTER_IF_STA));
Not sure what is going on or whether I'm doing something fundamentally wrong here but looking for some input.

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: Interface addresses in APSTA mode

Postby WiFive » Wed Jul 11, 2018 3:47 am

You are [re]starting the dhcp client. That may be triggering a bug.

jdwix615
Posts: 7
Joined: Thu Feb 01, 2018 10:06 pm

Re: Interface addresses in APSTA mode

Postby jdwix615 » Wed Jul 11, 2018 3:58 am

Just realised that I removed the wrong line.
I tried starting and stopping both client and server before posting this.
The actual code I ran was:

Code: Select all

ESP_ERROR_CHECK(tcpip_adapter_dhcps_stop(TCPIP_ADAPTER_IF_AP));
//ESP_ERROR_CHECK(tcpip_adapter_dhcpc_stop(TCPIP_ADAPTER_IF_STA));
tcpip_adapter_ip_info_t ap_ip_info;
memset(&ap_ip_info, 0, sizeof(ap_ip_info));
IP4_ADDR(&ap_ip_info.ip, 192, 168, 4, first_host_addr);
IP4_ADDR(&ap_ip_info.netmask, 255, 255, 255, subnet_last8);
IP4_ADDR(&ap_ip_info.gw, 192, 168, 4, first_host_addr);
ESP_ERROR_CHECK(tcpip_adapter_set_ip_info(TCPIP_ADAPTER_IF_AP, &ap_ip_info));

ESP_ERROR_CHECK(tcpip_adapter_dhcps_start(TCPIP_ADAPTER_IF_AP));
//ESP_ERROR_CHECK(tcpip_adapter_dhcpc_start(TCPIP_ADAPTER_IF_STA));
This still produces the issue.

jdwix615
Posts: 7
Joined: Thu Feb 01, 2018 10:06 pm

Re: Interface addresses in APSTA mode

Postby jdwix615 » Wed Jul 11, 2018 4:26 am

Okay, so I've been digging into the tcpip_adapter source. This is the set_ip_info function I'm calling

Code: Select all

esp_err_t tcpip_adapter_set_ip_info(tcpip_adapter_if_t tcpip_if, tcpip_adapter_ip_info_t *ip_info)
{
    struct netif *p_netif;
    tcpip_adapter_dhcp_status_t status;

    TCPIP_ADAPTER_IPC_CALL(tcpip_if, 0, ip_info, 0, tcpip_adapter_set_ip_info_api);

    if (tcpip_if >= TCPIP_ADAPTER_IF_MAX || ip_info == NULL) {
        return ESP_ERR_TCPIP_ADAPTER_INVALID_PARAMS;
    }

    if (tcpip_if == TCPIP_ADAPTER_IF_AP) {
        tcpip_adapter_dhcps_get_status(tcpip_if, &status);

        if (status != TCPIP_ADAPTER_DHCP_STOPPED) {
            return ESP_ERR_TCPIP_ADAPTER_DHCP_NOT_STOPPED;
        }
    } else if (tcpip_if == TCPIP_ADAPTER_IF_STA || tcpip_if == TCPIP_ADAPTER_IF_ETH ) {
        tcpip_adapter_dhcpc_get_status(tcpip_if, &status);

        if (status != TCPIP_ADAPTER_DHCP_STOPPED) {
            return ESP_ERR_TCPIP_ADAPTER_DHCP_NOT_STOPPED;
        }
#if LWIP_DNS /* don't build if not configured for use in lwipopts.h */
        dns_clear_servers(true);
#endif
    }

    ip4_addr_copy(esp_ip[tcpip_if].ip, ip_info->ip);
    ip4_addr_copy(esp_ip[tcpip_if].gw, ip_info->gw);
    ip4_addr_copy(esp_ip[tcpip_if].netmask, ip_info->netmask);

    p_netif = esp_netif[tcpip_if];

    if (p_netif != NULL && netif_is_up(p_netif)) {
        netif_set_addr(p_netif, &ip_info->ip, &ip_info->netmask, &ip_info->gw);
        if (!(ip4_addr_isany_val(ip_info->ip) || ip4_addr_isany_val(ip_info->netmask) || ip4_addr_isany_val(ip_info->gw))) {
            system_event_t evt;
            evt.event_id = SYSTEM_EVENT_STA_GOT_IP;
            evt.event_info.got_ip.ip_changed = false;

            if (memcmp(ip_info, &esp_ip_old[tcpip_if], sizeof(tcpip_adapter_ip_info_t))) {
                evt.event_info.got_ip.ip_changed = true;
            }

            memcpy(&evt.event_info.got_ip.ip_info, ip_info, sizeof(tcpip_adapter_ip_info_t));
            memcpy(&esp_ip_old[tcpip_if], ip_info, sizeof(tcpip_adapter_ip_info_t));
            esp_event_send(&evt);
            ESP_LOGD(TAG, "if%d tcpip adapter set static ip: ip changed=%d", tcpip_if, evt.event_info.got_ip.ip_changed);
        }
    }

    return ESP_OK;
}
The way I read this, it looks like a SYSTEM_EVENT_STA_GOT_IP is triggered whenever this function is called regardless of the interface being operated on.

To me this is wrong if the event is "STA_GOT_IP" and you call the function with TCP_ADAPTER_IF_AP.

Am I misinterpreting this?

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: Interface addresses in APSTA mode

Postby WiFive » Wed Jul 11, 2018 4:35 pm

Seems you are correct.

Who is online

Users browsing this forum: ivoras and 79 guests