cancel
Showing results for 
Search instead for 
Did you mean: 

Incomprehensible behavior with the LWIP library.

valik mahrov
Associate II

Recently I switched to STM32F767ZI using LAN8742A and the LWIP library. Began to develop a web configurator based on this STM. And there is such a problem. 0690X000008j6C9QAI.png

where 192.168.97.200 is a device, 192.168.97.1 is a client (computer).

During data transfer to get, the request goes to a packet with the SYN flag, after which the device does not transmit data, does not respond to ping.

The code is presented below.

char *buf;
 
struct http_state
{
  char *file;
  u32_t left;
};
 
static void
conn_err(void *arg, err_t err)
{
  struct http_state *hs;
 
  hs = arg;
  mem_free(hs);
}
/*-----------------------------------------------------------------------------------*/
static void
close_conn(struct tcp_pcb *pcb, struct http_state *hs)
{
 
  tcp_arg(pcb, NULL);
  tcp_sent(pcb, NULL);
  tcp_recv(pcb, NULL);
  mem_free(hs);
  tcp_close(pcb);
}
/*-----------------------------------------------------------------------------------*/
static void
send_data(struct tcp_pcb *pcb, struct http_state *hs)
{
  err_t err;
  u16_t len;
 
  /* We cannot send more data than space avaliable in the send
     buffer. */
  if (tcp_sndbuf(pcb) < hs->left)
  {
    len = tcp_sndbuf(pcb);
  }
  else
  {
    len = hs->left;
  }
 
  err = tcp_write(pcb, hs->file, len, 0);
 
  if (err == ERR_OK)
  {
    hs->file += len;
    hs->left -= len;
  }
}
 
/*-----------------------------------------------------------------------------------*/
static err_t
http_poll(void *arg, struct tcp_pcb *pcb)
{
  if (arg == NULL)
  {
    /*    printf("Null, close\n");*/
    tcp_close(pcb);
  }
  else
  {
    send_data(pcb, (struct http_state *)arg);
  }
 
  return ERR_OK;
}
/*-----------------------------------------------------------------------------------*/
static err_t
http_sent(void *arg, struct tcp_pcb *pcb, u16_t len)
{
  struct http_state *hs;
 
  hs = arg;
 
  if (hs->left > 0)
  {
    send_data(pcb, hs);
  }
  else
  {
    close_conn(pcb, hs);
  }
 
  return ERR_OK;
}
static err_t
http_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err)
{
  int i, j;
  char *buf;
  struct http_state *hs;
 
  hs = arg;
 
  if (err == ERR_OK && p != NULL)
  {
 
    /* Inform TCP that we have taken the data. */
    tcp_recved(pcb, p->tot_len);
    if (hs->file == NULL)
    { 
       //handler
    }
else
    {
      pbuf_free(p);
    }
  }
  return ERR_OK;
}
static err_t
http_accept(void *arg, struct tcp_pcb *pcb, err_t err)
{
  struct http_state *hs;
 
  /* Allocate memory for the structure that holds the state of the
     connection. */
  hs = mem_malloc(sizeof(struct http_state));
 
  if (hs == NULL)
  {
    return ERR_MEM;
  }
 
  /* Initialize the structure. */
  hs->file = NULL;
  hs->left = 0;
 
  /* Tell TCP that this is the structure we wish to be passed for our
     callbacks. */
  tcp_arg(pcb, hs);
 
  /* Tell TCP that we wish to be informed of incoming data by a call
     to the http_recv() function. */
  tcp_recv(pcb, http_recv);
 
  tcp_err(pcb, conn_err);
 
  tcp_poll(pcb, http_poll, 10);
  return ERR_OK;
}
/*-----------------------------------------------------------------------------------*/
void
httpd_init1(void)
{
  struct tcp_pcb *pcb;
 
  pcb = tcp_new();
  tcp_bind(pcb, IP_ADDR_ANY, 80);
  pcb = tcp_listen(pcb);
  tcp_accept(pcb, http_accept);
}

Who knows what the problem is? Thank you in advance. (I want to add that I'm doing a multiplayer web configurator.)

1 REPLY 1
valik mahrov
Associate II

Here is a file to make my problem easier to understand. The problem begins with the package number 62733.