Multiple network interfaces, socket problem

Hi,

with a custom hardware, I'm using a NRF9160 with a ESP8266 chip over uart with following prj.conf and board overlay:

# Network
CONFIG_NETWORKING=y
CONFIG_NET_SOCKETS=y
CONFIG_NET_SOCKETS_POSIX_NAMES=y
CONFIG_NET_DHCPV4=y
CONFIG_NET_TX_STACK_SIZE=2048
CONFIG_NET_RX_STACK_SIZE=2048

CONFIG_NET_IF_MAX_IPV4_COUNT=2
CONFIG_NET_IPV4=y
CONFIG_NET_IPV6=n
CONFIG_NET_UDP=n
CONFIG_NET_TCP=y
CONFIG_NET_LOG=y
CONFIG_NET_SHELL=y
CONFIG_TEST_RANDOM_GENERATOR=y

# WIFI
CONFIG_WIFI=y
CONFIG_WIFI_ESP_AT=y
CONFIG_WIFI_OFFLOAD=y

CONFIG_INIT_STACKS=y
CONFIG_HEAP_MEM_POOL_SIZE=16384

CONFIG_NET_SOCKETS_OFFLOAD=y
CONFIG_NET_SOCKETS_NET_MGMT=y
CONFIG_NET_SOCKETPAIR=y
CONFIG_NET_IPV4=y

CONFIG_NET_DEFAULT_IF_OFFLOAD=n
CONFIG_NET_OFFLOAD=y

&uart1 {
    status = "ok";
    current-speed = <115200>;
    tx-pin = <23>;
    rx-pin = <22>;
    rts-pin = <0xFFFFFFFF>;
    cts-pin = <0xFFFFFFFF>;
    /* disable by setting them to 0xffffffff */
    esp8266 {
        status = "ok";
        compatible = "espressif,esp-at";
        label = "esp8266";
    };
};

I was trying to open a socket (that uses the Wifi chip) and connect to it:

int sock = 0;

sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (sock < 0) {
        printk("Failed to create socket %d\n", errno);
        return -1;
}

ret = connect(sock, (struct sockaddr *) &addr, addr_len);
if (ret < 0) {
        printk("Cannot connect to %s remote (%d)",
                family == AF_INET ? "IPv4" : "IPv6",
                -errno);
        ret = -errno;
}

I tried to debug it, and I noticed that the wrong network interface is chosen, with the consequence that the offload functions are not called. I guess that it's a configuration issue, but until now no luck to find it...

  • Hello Joris,

    I was trying to open a socket (that uses the Wifi chip) and connect to it:

    This is a tricky one, actually. In general, if nRF91 socket offloading is enabled it takes over all of the socket() calls with default parameters.

    I tried to debug it, and I noticed that the wrong network interface is chosen, with the consequence that the offload functions are not called. I guess that it's a configuration issue, but until now no luck to find it...

    We have recently introduced a new flag on master branch, SOCK_NATIVE. It can be used when creating a socket to indicate that the intention is to create a socket for the native networking stack and not the nRF91 offloaded one.

    You could try to create a socket like this:

    socket(AF_INET, SOCK_STREAM | SOCK_NATIVE, IPPROTO_TCP)

    The socket call should be redirected to the native stack instead, since the ESP8266 is using a different offload mechanism (NET_OFFLOAD) which falls under "native stack". We have not tested with such a setup though, so we can not give a 100% guarantee that it works.

    Regards,

    Markus

Related