This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Problem with LwIP driver hdkif.c: hdkif_output (TCP connection hangs)

There is a problem in the the Ethernet driver for LwIP, which can permanently kill a TCP connection.  The problem happens when a short chained packet is transmitted.  The function  hdkif_output has the following code:

/* adjust the packet length if less than minimum required */
if(p->tot_len < MIN_PKT_LEN) {
p->tot_len = MIN_PKT_LEN;
p->len = MIN_PKT_LEN;
}
This works as long as buffers are not chained. When the buffers are chained, the packet is permanently destroyed so re-transmits will always fail. The fix is to change the above code to:
.
/* adjust the packet length if less than minimum required */
if(p->tot_len < MIN_PKT_LEN) {
struct pbuf *temp_p;
int diff_len = MIN_PKT_LEN - p->tot_len;
for (temp_p = p; temp_p->next != NULL; temp_p = temp_p->next)
    temp_p->tot_len += diff_len;
temp_p->tot_len += diff_len;
temp_p->len += diff_len;
}

-Jeremy

  • Jeremy,

    thanks for pointing this out and providing the code snippet.

    I have contacted the expert for this to make sure this gets attention and corrected in our example.

    Regards,

    Abhishek

  • If TI does update the LwIP example code, I have a few suggestions for improvement. 

    First, upgrade LwIP to 1.4.1 (not very difficult, but it did take some work). 

    And second, change the example so LwIP is only called from outside of interrupts.  To do this, you can disable the receive interrupt (not a problem since EMAC buffers 60 packets) and then call lwIPTxIntHandler (which calls hdkif_rx_inthandler)  from the main loop of your your application.  And also periodically call tcp_tmr and sys_check_timeouts from the main loop. 

    There are two problems with having LwIP called from inside the interrupt.  One problem is that the application is blocked while all packet processing is being done.  The second problem is that if you send packets outside of an interrupt, you'll crash LwIP since it's not re-entrant code.  The example works because everything is done from the call back functions from within an interrupt, but it's not very user friendly because you normally want to call tcp_output directly from your application (outside of the interrupts).

    -Jeremy