lwip-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lwip-users] Running DHCP client from the tcpip thread


From: Manu Abraham
Subject: [lwip-users] Running DHCP client from the tcpip thread
Date: Fri, 11 Sep 2020 14:05:22 +0530

Hello folks,

Trying to run a dhcp client with LWIP 2.1.2 with FreeRTOS on STM32H7 MCU.

in lwipopts.h, I have:

#define NO_SYS                0
#define LWIP_TCPIP_CORE_LOCKING        1

The results that I see is that dhcp search times out.
But if Netif_Config is not called from within the tcpip_thread,
then it appears to work. But that mode of operation appears to be for
a NO OS mode ?

In short,

This does work:

    tcpip_init(NULL, NULL);                    /* Create tcp_ip stack thread */
    Netif_Config(&netif);                        /* Initialize the LwIP stack */

This does not:

    tcpip_init(Netif_Config, &netif);

Maybe I am missing something. I am new to LWIP. Trying to understand
how to go about it. But the ML seems to be an anechoic chamber. It is
no surprise why different vendors who try to support LWIP get their
implementation wrong, eventually ending buggy.

Can someone please comment on what I am doing wrong ?


Thanks,

Manu


In my main loop, I call my network initialization in the following manner.

static void StartThread(void const *arg)
{
    printf(" (%d) %s: \n", _ln, _fn);
    tcpip_init(Netif_Config, &netif);
    while (1) {
        osThreadTerminate(NULL);            /* Delete the Init Thread */
    }
}

void Netif_Config(void *arg)
{
    struct netif *net = arg;

    ip_addr_t ipaddr, netmask, gw;
    struct dhcp *dhcp;
    char str[32];
    int i;

    if (!arg)
        return;

    ip_addr_set_zero_ip4(&ipaddr);
    ip_addr_set_zero_ip4(&netmask);
    ip_addr_set_zero_ip4(&gw);

    printf(" (%d) %s: Configuring Network\n", _ln, _fn);
    netif_add(net,                    /* Add Network interface */
          &ipaddr,                    /* set Zero'd address, for dhcp */
          &netmask,                    /* set Zero'd mask, for mask */
          &gw,                        /* set Zero'd gateway address */
          NULL,                        /* State pointer may be NULL */
          &ethernetif_init,                /* netif interface init function */
          &tcpip_input);                /* ethernet_input(), or ip_input() */

    netif_set_default(net);                /* Register default network
interface */

    link_status_update(net);
    netif_set_link_callback(net, link_status_update);

    osThreadDef(EthLink, ethernet_link_thread, osPriorityNormal, 0,
configMINIMAL_STACK_SIZE * 2);
    osThreadCreate(osThread(EthLink), net);        /* Start Ethernet
Link monitor */

    printf("Set Link Up ..\n");
    while (!netif_is_up(net)) {                /* Check interface is up */
        printf(".");
        vTaskDelay(1000 / portTICK_RATE_MS);
    }
    printf(" .. Done\n");

    ip_addr_set_zero_ip4(&net->ip_addr);
    ip_addr_set_zero_ip4(&net->netmask);
    ip_addr_set_zero_ip4(&net->gw);
    dhcp_start(net);                    /* start dhcp client */
    printf("\nDHCP Start .");

    int count = 0;
    while (!net->ip_addr.addr) {
        sys_check_timeouts();                /* timeouts for all core
protocols */
        printf(".");
        sys_msleep(DHCP_FINE_TIMER_MSECS);
        dhcp_fine_tmr();
        count += DHCP_FINE_TIMER_MSECS;
        if (count >= DHCP_COARSE_TIMER_SECS * 1000) {
            dhcp_coarse_tmr();
            count = 0;
        }
        dhcp = netif_get_client_data(net, LWIP_NETIF_CLIENT_DATA_INDEX_DHCP);
        if (dhcp->state == DHCP_STATE_BOUND) {
            printf("\nDHCP bound\n");
        }
    }
}

DHCP debug logs:

 (359) StartThread:
 (289) Netif_Config: Configuring Network
 (165) low_level_init: HAL_ETH_DescAssignMemory, Rx_Buff@ 0x30040200 ret: 0
 (165) low_level_init: HAL_ETH_DescAssignMemory, Rx_Buff@ 0x30040200 ret: 0
 (165) low_level_init: HAL_ETH_DescAssignMemory, Rx_Buff@ 0x30040200 ret: 0
 (165) low_level_init: HAL_ETH_DescAssignMemory, Rx_Buff@ 0x30040200 ret: 0
Set Link Up ..
.. (270) link_status_update: Link is Up
 .. Done
dhcp_start(netif=240001c4) st0
dhcp_start(): mallocing new DHCP client
dhcp_start(): allocated dhcpdhcp_start(): starting DHCP configuration
dhcp_discover()
transaction id xid(538213ef)
dhcp_discover: making request
dhcp_discover: sendto(DISCOVER, IP_ADDR_BROADCAST, LWIP_IANA_PORT_DHCP_SERVER)
dhcp_discover: deleting()ing
dhcp_discover: SELECTING
dhcp_discover(): set request timeout 2000 msecs

DHCP Start ...dhcp_fine_tmr(): request timeout
dhcp_timeout()
dhcp_timeout(): restarting discovery
dhcp_discover()
transaction id xid(538213ef)
dhcp_discover: making request
dhcp_discover: sendto(DISCOVER, IP_ADDR_BROADCAST, LWIP_IANA_PORT_DHCP_SERVER)
dhcp_discover: deleting()ing
dhcp_discover: SELECTING
dhcp_discover(): set request timeout 4000 msecs
....dhcp_fine_tmr(): request timeout
dhcp_timeout()
dhcp_timeout(): restarting discovery
dhcp_discover()
transaction id xid(538213ef)
dhcp_discover: making request
dhcp_discover: sendto(DISCOVER, IP_ADDR_BROADCAST, LWIP_IANA_PORT_DHCP_SERVER)
dhcp_discover: deleting()ing
dhcp_discover: SELECTING
dhcp_discover(): set request timeout 8000 msecs



reply via email to

[Prev in Thread] Current Thread [Next in Thread]