Discussion:
[lwip-users] STM32F4 LwIP HTTP Ethernet Bootloader (IAP)
Müller, Martin, KN
2014-02-05 06:46:28 UTC
Permalink
Hello everyone! My name is Martin and I'm quite new to LwIP.

I am using the ST "In-application-programming over Ethernet" Application for an own Bootloader architecture. The Application and LwIP-Stack 1.3.1 are connected through RAW-API. The File-Upload to the Microcontroller is done through a HTTP POST Method Form. A binary file of approximately 2 Megabytes is splited into ~1500 TCP-Packets.

My Problem is that I don't know how to stop the Transfer, if my HTTP Application detects packet with corrupt content. The Browser always sends all packets till the end. I could easily close the tcp connection, but I want to send a ErroPage in case wrong content is received. Therefore the tcp_close() Function is not the right choise.

Do you have any hints for me? Thank you all.

Bye.

STM32 IAP over Ethernet:
http://www.st.com/st-web-ui/static/active/cn/resource/technical/document/application_note/DM00025236.pdf"
Müller, Martin, KN
2014-02-05 12:25:58 UTC
Permalink
Hi Robin,

Thanks for your fast answer. As conclusion, I'll show you my debug stream:

Let's cause the following case: While flashing packet 1, the Bootloader detects a wrong checksum. It sends the ErrorPage and when it is confirmed by tcp_sent() callback, it closes the connection. But this seems to take too long, because the browser client won't stop sending tcp-packets. This is a problem, because when sending a larger file (~1500 packets) it paralyses the server so that the browser cannot display the ErrorPage immediately.

Do you mean sending the errorpage with FIN-Flag set? How is this possible?

Thank you very much,

Martin

tcp_recved: recveived 1460 bytes, wnd 5840 (0).<\n>
Bootloader 2: Erasing Flash ... Done. Time: 4531 ms.<\n>
Bootloader 2: Flashing packet 1 ...Parser: Line: 345, Checksum: 0xf3 ERROR! <\n>
Process stopped.<\n>
tcp_close: closing in State: ESTABLISHED<\n>
**** PLEASE STOP HERE, but it won't ;( ****
tcp_recved: recveived 1460 bytes, wnd 5840 (0).<\n>
tcp_recved: recveived 1460 bytes, wnd 5840 (0).<\n>
tcp_recved: recveived 1460 bytes, wnd 5840 (0).<\n>
tcp_recved: recveived 1460 bytes, wnd 5840 (0).<\n>
tcp_recved: recveived 1460 bytes, wnd 5840 (0).<\n>
tcp_recved: recveived 1460 bytes, wnd 5840 (0).<\n>
tcp_recved: recveived 1460 bytes, wnd 5840 (0).<\n>
tcp_recved: recveived 1460 bytes, wnd 5840 (0).<\n>
tcp_recved: recveived 1460 bytes, wnd 5840 (0).<\n>
tcp_recved: recveived 1460 bytes, wnd 5840 (0).<\n>
tcp_recved: recveived 1460 bytes, wnd 5840 (0).<\n>
tcp_recved: recveived 1460 bytes, wnd 5840 (0).<\n>
tcp_recved: recveived 1460 bytes, wnd 5840 (0).<\n>
tcp_recved: recveived 1460 bytes, wnd 5840 (0).<\n>
tcp_recved: recveived 1460 bytes, wnd 5840 (0).<\n>
tcp_recved: recveived 1460 bytes, wnd 5840 (0).<\n>
tcp_recved: recveived 1460 bytes, wnd 5840 (0).<\n>
TCP connection closed: FIN_WAIT_2 52638 -> 80.<\n>
tcp_pcb_purge<\n>
tcp_recved: recveived 932 bytes, wnd 5839 (1).<\n>
tcp_close: closing in State: TIME_WAIT<\n>
tcp_slowtmr: no active pcbs<\n>

-----Ursprüngliche Nachricht-----
Von: Robin Iddon [mailto:***@edesix.com]
Gesendet: Mittwoch, 5. Februar 2014 09:36
An: Müller, Martin, KN
Betreff: Re: [lwip-users] STM32F4 LwIP HTTP Ethernet Bootloader (IAP)

Hi,

I suspect you just write the Http error response then shutdown the write connection (in other words send FIN) and discard any subsequent read data.  Whether or not the client stops sending at this point is up to them.  If after a short period of time (say 5 seconds) it hasn't stopped or closed the connection then close the connection from your end.

In the first scenario your client will see PSH then FIN and might use this to stop sending, respond with its own FIN and render a reasonable error message (perhaps one you include in the response).

If it does not then after 5 seconds it will see RST which will trigger an io exception of some sort and force it to stop less gracefully, as you have already observed.

That
robin
2014-02-05 15:26:22 UTC
Permalink
Hi Martin,

Looking at http://lwip.wikia.com/wiki/Raw/TCP the bottom of the page has
session termination, scenario 2, local server shutdown (which is what
you're doing).

You can see that calling tcp_close() does what I had indicated - it
sends a FIN.

So on receipt of a checksum invalid packet you would do tcp_write(http
response); tcp_output() to force all the data to be sent; tcp_close() to
send the FIN.

Your client has the choice to process the http response when it wishes;
nothing about tcp_close() forces the other end to stop sending - it's
just saying you won't be sending any more data.

It appears that your client chooses to continue sending some (large)
amount of data, perhaps because it is all in a buffer already on the
host operating system.

Your only option to make the client close faster is to use tcp_abort(),
which will send a RST to the other end.

Whether or not this causes the sort of graceful error handling you want
depends on the client. Why not try it?

Cheers,
Robin
Post by Müller, Martin, KN
Hi Robin,
Let's cause the following case: While flashing packet 1, the
Bootloader detects a wrong checksum. It sends the ErrorPage and when
it is confirmed by tcp_sent() callback, it closes the connection. But
this seems to take too long, because the browser client won't stop
sending tcp-packets. This is a problem, because when sending a larger
file (~1500 packets) it paralyses the server so that the browser
cannot display the ErrorPage immediately.
Do you mean sending the errorpage with FIN-Flag set? How is this possible?
Thank you very much,
Martin
tcp_recved: recveived 1460 bytes, wnd 5840 (0).<\n>
Bootloader 2: Erasing Flash ... Done. Time: 4531 ms.<\n>
Bootloader 2: Flashing packet 1 ...Parser: Line: 345, Checksum: 0xf3 ERROR! <\n>
Process stopped.<\n>
tcp_close: closing in State: ESTABLISHED<\n>
**** PLEASE STOP HERE, but it won't ;( ****
tcp_recved: recveived 1460 bytes, wnd 5840 (0).<\n>
tcp_recved: recveived 1460 bytes, wnd 5840 (0).<\n>
tcp_recved: recveived 1460 bytes, wnd 5840 (0).<\n>
tcp_recved: recveived 1460 bytes, wnd 5840 (0).<\n>
tcp_recved: recveived 1460 bytes, wnd 5840 (0).<\n>
tcp_recved: recveived 1460 bytes, wnd 5840 (0).<\n>
tcp_recved: recveived 1460 bytes, wnd 5840 (0).<\n>
tcp_recved: recveived 1460 bytes, wnd 5840 (0).<\n>
tcp_recved: recveived 1460 bytes, wnd 5840 (0).<\n>
tcp_recved: recveived 1460 bytes, wnd 5840 (0).<\n>
tcp_recved: recveived 1460 bytes, wnd 5840 (0).<\n>
tcp_recved: recveived 1460 bytes, wnd 5840 (0).<\n>
tcp_recved: recveived 1460 bytes, wnd 5840 (0).<\n>
tcp_recved: recveived 1460 bytes, wnd 5840 (0).<\n>
tcp_recved: recveived 1460 bytes, wnd 5840 (0).<\n>
tcp_recved: recveived 1460 bytes, wnd 5840 (0).<\n>
tcp_recved: recveived 1460 bytes, wnd 5840 (0).<\n>
TCP connection closed: FIN_WAIT_2 52638 -> 80.<\n>
tcp_pcb_purge<\n>
tcp_recved: recveived 932 bytes, wnd 5839 (1).<\n>
tcp_close: closing in State: TIME_WAIT<\n>
tcp_slowtmr: no active pcbs<\n>
-----Ursprüngliche Nachricht-----
Gesendet: Mittwoch, 5. Februar 2014 09:36
An: Müller, Martin, KN
Betreff: Re: [lwip-users] STM32F4 LwIP HTTP Ethernet Bootloader (IAP)
Müller, Martin, KN
2014-02-14 08:38:37 UTC
Permalink
Hey,
Thank you very much. It works ;)

Martin

-----Ursprüngliche Nachricht-----
Von: lwip-users-bounces+martin.mueller2=***@nongnu.org [mailto:lwip-users-bounces+martin.mueller2=***@nongnu.org] Im Auftrag von robin
Gesendet: Mittwoch, 5. Februar 2014 16:26
An: lwip-***@nongnu.org
Betreff: Re: [lwip-users] STM32F4 LwIP HTTP Ethernet Bootloader (IAP)

Hi Martin,

Looking at http://lwip.wikia.com/wiki/Raw/TCP the bottom of the page has session termination, scenario 2, local server shutdown (which is what you're doing).

You can see that calling tcp_close() does what I had indicated - it sends a FIN.

So on receipt of a checksum invalid packet you would do tcp_write(http response); tcp_output() to force all the data to be sent; tcp_close() to send the FIN.

Your client has the choice to process the http response when it wishes; nothing about tcp_close() forces the other end to stop sending - it's just saying you won't be sending any more data.

It appears that your client chooses to continue sending some (large) amount of data, perhaps because it is all in a buffer already on the host operating system.

Your only option to make the client close faster is to use tcp_abort(), which will send a RST to the other end.

Whether or not this causes the sort of graceful error handling you want depends on the client. Why not try it?

Cheers,
Robin
Post by Müller, Martin, KN
Hi Robin,
Let's cause the following case: While flashing packet 1, the
Bootloader detects a wrong checksum. It sends the ErrorPage and when
it is confirmed by tcp_sent() callback, it closes the connection. But
this seems to take too long, because the browser client won't stop
sending tcp-packets. This is a problem, because when sending a larger
file (~1500 packets) it paralyses the server so that the browser
cannot display the ErrorPage immediately.
Do you mean sending the errorpage with FIN-Flag set? How is this possible?
Thank you very much,
Martin
Erasing Flash ... Done. Time: 4531 ms.<\n> Bootloader 2: Flashing
packet 1 ...Parser: Line: 345, Checksum: 0xf3 ERROR! <\n> Process
stopped.<\n>
tcp_close: closing in State: ESTABLISHED<\n>
**** PLEASE STOP HERE, but it won't ;( ****
tcp_recved: recveived 1460 bytes, wnd 5840 (0).<\n>
tcp_recved: recveived 1460 bytes, wnd 5840 (0).<\n>
tcp_recved: recveived 1460 bytes, wnd 5840 (0).<\n>
tcp_recved: recveived 1460 bytes, wnd 5840 (0).<\n>
tcp_recved: recveived 1460 bytes, wnd 5840 (0).<\n>
tcp_recved: recveived 1460 bytes, wnd 5840 (0).<\n>
tcp_recved: recveived 1460 bytes, wnd 5840 (0).<\n>
tcp_recved: recveived 1460 bytes, wnd 5840 (0).<\n>
tcp_recved: recveived 1460 bytes, wnd 5840 (0).<\n>
tcp_recved: recveived 1460 bytes, wnd 5840 (0).<\n>
tcp_recved: recveived 1460 bytes, wnd 5840 (0).<\n>
tcp_recved: recveived 1460 bytes, wnd 5840 (0).<\n>
tcp_recved: recveived 1460 bytes, wnd 5840 (0).<\n>
tcp_recved: recveived 1460 bytes, wnd 5840 (0).<\n>
tcp_recved: recveived 1460 bytes, wnd 5840 (0).<\n>
tcp_recved: recveived 1460 bytes, wnd 5840 (0).<\n>
tcp_recved: recveived 1460 bytes, wnd 5840 (0).<\n> TCP connection
closed: FIN_WAIT_2 52638 -> 80.<\n> tcp_pcb_purge<\n>
tcp_recved: recveived 932 bytes, wnd 5839 (1).<\n>
tcp_close: closing in State: TIME_WAIT<\n>
tcp_slowtmr: no active pcbs<\n>
-----Ursprüngliche Nachricht-----
Gesendet: Mittwoch, 5. Februar 2014 09:36
An: Müller, Martin, KN
Betreff: Re: [lwip-users] STM32F4 LwIP HTTP Ethernet Bootloader (IAP)
_______________________________________________
lwip-users mailing list
lwip-***@nongnu.org
https://lists.nongnu.org/ma

Loading...