lwip: Scan through the heap searching for a free block that is big enough, beginning with the lowest free block.

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

lwip: Scan through the heap searching for a free block that is big enough, beginning with the lowest free block.

vrnud
Hi,

I am trying to impelement modbus over TCPIP.
I am using FreeRTOS + lwip +STM32f4 (cube Mx generated code).
Lwip version is 2.0.0.
Freertos version 9.0.0.
heap 4 is used. is it ok?

TCPIP echo server application is used.
while trying to connect from Modscan utility program stucks in
mem.c file . function mem_malloc.
   /* Scan through the heap searching for a free block that is big enough,
modbus_connect_problem.pcap
<http://lwip.100.n7.nabble.com/file/t2188/modbus_connect_problem.pcap>  
     * beginning with the lowest free block.
     */
under this loop.
 for (ptr = (mem_size_t)((u8_t *)lfree - ram); ptr < MEM_SIZE_ALIGNED -
size;
         ptr = ((struct mem *)(void *)&ram[ptr])->next) {
}

I have enabled the modbus_connect_problem.pcap
<http://lwip.100.n7.nabble.com/file/t2188/modbus_connect_problem.pcap>  
CHECKSUM_GEN_IP 1
CHECKSUM_GEN_TCP 1
I have attached the wireshark report.


Kindly guide.




--
Sent from: http://lwip.100.n7.nabble.com/lwip-users-f3.html

_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users
Reply | Threaded
Open this post in threaded view
|

Re: lwip: Scan through the heap searching for a free block that is big enough, beginning with the lowest free block.

goldsimon@gmx.de
Am 25.03.2019 um 10:52 schrieb vrnud:

> Hi,
>
> I am trying to impelement modbus over TCPIP.
> I am using FreeRTOS + lwip +STM32f4 (cube Mx generated code).
> Lwip version is 2.0.0.
> Freertos version 9.0.0.
> heap 4 is used. is it ok?
>
> TCPIP echo server application is used.
> while trying to connect from Modscan utility program stucks in
> mem.c file . function mem_malloc.

What does "stuck" mean? Endless loop in mem_malloc? If so, that's an
indication that the list is broken, which in turn is an indication for
violating lwIP's threading rules.

Regards,
Simon

>     /* Scan through the heap searching for a free block that is big enough,
> modbus_connect_problem.pcap
> <http://lwip.100.n7.nabble.com/file/t2188/modbus_connect_problem.pcap>
>       * beginning with the lowest free block.
>       */
> under this loop.
>   for (ptr = (mem_size_t)((u8_t *)lfree - ram); ptr < MEM_SIZE_ALIGNED -
> size;
>           ptr = ((struct mem *)(void *)&ram[ptr])->next) {
> }
>
> I have enabled the modbus_connect_problem.pcap
> <http://lwip.100.n7.nabble.com/file/t2188/modbus_connect_problem.pcap>
> CHECKSUM_GEN_IP 1
> CHECKSUM_GEN_TCP 1
> I have attached the wireshark report.
>
>
> Kindly guide.

_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users
Reply | Threaded
Open this post in threaded view
|

Re: lwip: Scan through the heap searching for a free block that is big enough, beginning with the lowest free block.

vrnud
HI,

I am very new to the tcpip world.

  netif_add(&gnetif, &ipaddr, &netmask, &gw, NULL, &ethernetif_init,
&tcpip_input);
is called from MX_LWIP_Init() function.

"But "raw" APIs functions must ONLY be called from TCPIP thread."
I dont know how to do that. can you please provide some example for the
same.

or example for
" tcpip_callback() can be used get called back from TCPIP thread, it is safe
to call any "raw" APIs from there."

"Use LWIP_TCPIP_CORE_LOCKING. All "raw" APIs functions can be called when
lwIP core lock is aquired, see LOCK_TCPIP_CORE() and UNLOCK_TCPIP_CORE().
These macros cannot be used in an interrupt context! Note the OS must
correctly handle priority inversion for this."
LWIP_TCPIP_CORE_LOCKING is set 1 in code.

below is the code
void tcp_echoserver_init(void)
{

  /* create new tcp pcb */
  tcp_echoserver_pcb = tcp_new();

  if (tcp_echoserver_pcb != NULL)
  {
    err_t err;
   
    /* bind echo_pcb to port 7 (ECHO protocol) ;7 FOR ECHO, 502 FOR MODBUS*/
    err = tcp_bind(tcp_echoserver_pcb, IP_ADDR_ANY, 502);
   
    if (err == ERR_OK)
    {
      /* start tcp listening for echo_pcb */
      tcp_echoserver_pcb = tcp_listen(tcp_echoserver_pcb);
     
      /* initialize LwIP tcp_accept callback function */
      tcp_accept(tcp_echoserver_pcb, tcp_echoserver_accept);
    }
    else
    {
      /* deallocate the pcb */
      memp_free(MEMP_TCP_PCB, tcp_echoserver_pcb);
    }
  }

}

/**
  * @brief  This function is the implementation of tcp_accept LwIP callback
  * @param  arg: not used
  * @param  newpcb: pointer on tcp_pcb struct for the newly created tcp
connection
  * @param  err: not used
  * @retval err_t: error status
  */
static err_t tcp_echoserver_accept(void *arg, struct tcp_pcb *newpcb, err_t
err)
{
  err_t ret_err;
  struct tcp_echoserver_struct *es;

  LWIP_UNUSED_ARG(arg);
  LWIP_UNUSED_ARG(err);

  /* set priority for the newly accepted tcp connection newpcb */
  tcp_setprio(newpcb, TCP_PRIO_MIN);

  /* allocate structure es to maintain tcp connection informations */
  es = (struct tcp_echoserver_struct *)mem_malloc(sizeof(struct
tcp_echoserver_struct));
  if (es != NULL)
  {
    es->state = ES_ACCEPTED;
    es->pcb = newpcb;
    es->retries = 0;
    es->p = NULL;
 
                if(gu8_addrs_chng_Link_break)
                {
                        gu8_addrs_chng_Link_break = 0;
                }

       
    /* pass newly allocated es structure as argument to newpcb */
    tcp_arg(newpcb, es);
   
    /* initialize lwip tcp_recv callback function for newpcb  */
    tcp_recv(newpcb, tcp_echoserver_recv);
   
    /* initialize lwip tcp_err callback function for newpcb  */
    tcp_err(newpcb, tcp_echoserver_error);
   
    /* initialize lwip tcp_poll callback function for newpcb */
    tcp_poll(newpcb, tcp_echoserver_poll, 0);
   
    ret_err = ERR_OK;
  }
  else
  {
    /*  close tcp connection */
    tcp_echoserver_connection_close(newpcb, es);
    /* return memory error */
    ret_err = ERR_MEM;
  }
  return ret_err;  
}

I am getting problem for particular this line
  /* allocate structure es to maintain tcp connection informations */
  es = (struct tcp_echoserver_struct *)mem_malloc(sizeof(struct
tcp_echoserver_struct));

Regards,
Vrund



--
Sent from: http://lwip.100.n7.nabble.com/lwip-users-f3.html

_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users
Reply | Threaded
Open this post in threaded view
|

Re: lwip: Scan through the heap searching for a free block that is big enough, beginning with the lowest free block.

vrnud
In reply to this post by goldsimon@gmx.de
Hi,


Kindly help me.
i want to add hsr tag. (6 bytes)
  <http://lwip.100.n7.nabble.com/file/t2188/img_en_frame_hsr_en.png>
HSR ethertype = 0x892f

what part of the code should i add?

Regard,
Vrund



--
Sent from: http://lwip.100.n7.nabble.com/lwip-users-f3.html

_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users
Reply | Threaded
Open this post in threaded view
|

Re: lwip: Scan through the heap searching for a free block that is big enough, beginning with the lowest free block.

vrnud
In reply to this post by goldsimon@gmx.de
Hi 

Help to add identify place in a lwip code( for transmit only )where I can add 6 bytes of hsr tag...

Regards,
Vrund 

On Thu 28 Mar, 2019, 12:37 AM [hidden email], <[hidden email]> wrote:
Am 25.03.2019 um 10:52 schrieb vrnud:
> Hi,
>
> I am trying to impelement modbus over TCPIP.
> I am using FreeRTOS + lwip +STM32f4 (cube Mx generated code).
> Lwip version is 2.0.0.
> Freertos version 9.0.0.
> heap 4 is used. is it ok?
>
> TCPIP echo server application is used.
> while trying to connect from Modscan utility program stucks in
> mem.c file . function mem_malloc.

What does "stuck" mean? Endless loop in mem_malloc? If so, that's an
indication that the list is broken, which in turn is an indication for
violating lwIP's threading rules.

Regards,
Simon

>     /* Scan through the heap searching for a free block that is big enough,
> modbus_connect_problem.pcap
> <http://lwip.100.n7.nabble.com/file/t2188/modbus_connect_problem.pcap>
>       * beginning with the lowest free block.
>       */
> under this loop.
>   for (ptr = (mem_size_t)((u8_t *)lfree - ram); ptr < MEM_SIZE_ALIGNED -
> size;
>           ptr = ((struct mem *)(void *)&ram[ptr])->next) {
> }
>
> I have enabled the modbus_connect_problem.pcap
> <http://lwip.100.n7.nabble.com/file/t2188/modbus_connect_problem.pcap>
> CHECKSUM_GEN_IP 1
> CHECKSUM_GEN_TCP 1
> I have attached the wireshark report.
>
>
> Kindly guide.

_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users

_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users