Re: [lwip-users] Errors during build of lwip in Windows

2023-04-17 Thread Giuseppe Modugno

Il 17/04/2023 12:41, Simon Goldschmidt ha scritto:

Am 17. April 2023 08:38:56 MESZ schrieb Giuseppe Modugno 
:

Il 15/04/2023 01:58, Giuseppe Modugno ha scritto:

[...]

I don't know exactly why, but the problem disappeared in my build system after 
postponing lwipallapps, such as:

target_link_libraries(example_app ${LWIP_SANITIZER_LIBS} lwipcontribexamples 
lwipallapps lwipcontribapps lwipcontribaddons lwipcontribportwindows lwipcore 
lwipmbedtls)



That's a known problem of the gnu linker: order of libraries is important!


I thought the order of libraries given to the linker was important for 
all linkers. Anyway, are you going to change the order to fix this 
problem on gnu linker?


I don't think I'm the only one that uses gnu linker. I suppose many uses 
GNU Arm toolchain for embedded.




Lastly another strange behaviour. If I enable LWIP_HTTPD_APP, the build process 
is ok, but I can't see the web page on the browser when I type the URL 
http://192.168.1.200.

[...]

I suspect there's a problem with WinPcap libraries. If I try to connect to the 
http server from another machine, it works. Even ping to lwip doesn't work from 
the Windows host machine.

Do you know how this can be solved?


When talking loopback to the application, checksums are not generated as the 
windows driver or hardware generates them. Either you turn off that option in 
the windows driver or you disable checksum checks in lwip.


Thank you, yes, it works.


___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users


Re: [lwip-users] Errors during build of lwip in Windows

2023-04-17 Thread Giuseppe Modugno

Il 15/04/2023 01:58, Giuseppe Modugno ha scritto:
[...]
Now I enabled LWIP_MQTT_APP and I receive the following errors during 
build:


[ 99%] Linking C executable example_app.exe
liblwipcontribexamples.a(mqtt_example.obj): In function 
`mqtt_connection_cb':
C:/temp/lwip/contrib/examples/mqtt/mqtt_example.c:100: undefined 
reference to `mqtt_sub_unsub'
C:/temp/lwip/contrib/examples/mqtt/mqtt_example.c:104: undefined 
reference to `mqtt_sub_unsub'
liblwipcontribexamples.a(mqtt_example.obj): In function 
`mqtt_example_init':
C:/temp/lwip/contrib/examples/mqtt/mqtt_example.c:116: undefined 
reference to `mqtt_client_new'
C:/temp/lwip/contrib/examples/mqtt/mqtt_example.c:118: undefined 
reference to `mqtt_set_inpub_callback'
C:/temp/lwip/contrib/examples/mqtt/mqtt_example.c:123: undefined 
reference to `mqtt_client_connect'

collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[2]: *** [CMakeFiles\example_app.dir\build.make:128: 
example_app.exe] Error 1
mingw32-make.exe[1]: *** [CMakeFiles\Makefile2:358: 
CMakeFiles/example_app.dir/all] Error 2

mingw32-make.exe: *** [Makefile:135: all] Error 2

I couldn't understand why, because mqtt.c is really compiled and linked 
in liblwipallapps.a.


I think I understood. In CMakeLists.txt there's the following line:

target_link_libraries(example_app ${LWIP_SANITIZER_LIBS} lwipallapps 
lwipcontribexamples lwipcontribapps lwipcontribaddons 
lwipcontribportwindows lwipcore lwipmbedtls)


I don't know exactly why, but the problem disappeared in my build system 
after postponing lwipallapps, such as:


target_link_libraries(example_app ${LWIP_SANITIZER_LIBS} 
lwipcontribexamples lwipallapps lwipcontribapps lwipcontribaddons 
lwipcontribportwindows lwipcore lwipmbedtls)



Lastly another strange behaviour. If I enable LWIP_HTTPD_APP, the build 
process is ok, but I can't see the web page on the browser when I type 
the URL http://192.168.1.200.

[...]

I suspect there's a problem with WinPcap libraries. If I try to connect 
to the http server from another machine, it works. Even ping to lwip 
doesn't work from the Windows host machine.


Do you know how this can be solved?

___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users


[lwip-users] Errors during build of lwip in Windows

2023-04-14 Thread Giuseppe Modugno
I cloned lwip and mbedtls repositories in the same folder on a Windows 
system. I also put WpdPack in the same folder.


I have a mingw compiler that I'd like to use instead of Visual Studio. 
It works well with the following command:


  c:\tools\cmake\bin\cmake.exe -G "MinGW Makefiles" ..

entered in the folder:

  \contrib\ports\win32\example_app\build

I don't know why, but I needed to manually copy lwipcfg.h (cmake script 
should take care of this, but in my case it doesn't work).


I enabled LWIP_DNS_APP and LWIP_PING_APP and it apparently works well. 
The application is able to send PING packets and receive resonses.


Now I enabled LWIP_MQTT_APP and I receive the following errors during build:

[ 99%] Linking C executable example_app.exe
liblwipcontribexamples.a(mqtt_example.obj): In function 
`mqtt_connection_cb':
C:/temp/lwip/contrib/examples/mqtt/mqtt_example.c:100: undefined 
reference to `mqtt_sub_unsub'
C:/temp/lwip/contrib/examples/mqtt/mqtt_example.c:104: undefined 
reference to `mqtt_sub_unsub'

liblwipcontribexamples.a(mqtt_example.obj): In function `mqtt_example_init':
C:/temp/lwip/contrib/examples/mqtt/mqtt_example.c:116: undefined 
reference to `mqtt_client_new'
C:/temp/lwip/contrib/examples/mqtt/mqtt_example.c:118: undefined 
reference to `mqtt_set_inpub_callback'
C:/temp/lwip/contrib/examples/mqtt/mqtt_example.c:123: undefined 
reference to `mqtt_client_connect'

collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[2]: *** [CMakeFiles\example_app.dir\build.make:128: 
example_app.exe] Error 1
mingw32-make.exe[1]: *** [CMakeFiles\Makefile2:358: 
CMakeFiles/example_app.dir/all] Error 2

mingw32-make.exe: *** [Makefile:135: all] Error 2

I couldn't understand why, because mqtt.c is really compiled and linked 
in liblwipallapps.a.


Similar things happen if I try to enable LWIP_TFTP_CLIENT_APP.


Lastly another strange behaviour. If I enable LWIP_HTTPD_APP, the build 
process is ok, but I can't see the web page on the browser when I type 
the URL http://192.168.1.200. This is the output from example_app.exe:


$ .\example_app.exe
Starting lwIP, local interface IP is 192.168.1.200
 0: NPF_{AC067A09-87E6-4E65-A56D-7442B541F373}
 Desc: "Oracle"
 1: NPF_{378C5F06-077E-4267-9895-80E7345D4F5F}
 Desc: "Realtek PCIe GBE Family Controller"
Using adapter_num: 1
Using adapter: "Realtek PCIe GBE Family Controller"
status_callback==UP, local interface IP is 192.168.1.200
httpd_init
tcp_bind: bind to port 80

I tried to change the server port to 55000 (HTTPD_SERVER_PORT=55000) 
just to avoid reserved TCP ports, but the behaviour is the same.


___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users


[lwip-users] lwip win32 port: pcapif_poll() doesn't return

2023-04-14 Thread Giuseppe Modugno
I was testing an http client that downloads a file from a server, with 
NO_SYS=1 and raw api. It seems works well, but I noticed pcapif_poll() 
doesn't return during all the download process that takes several 
seconds. Indeed pcapif_poll() contains a loop:


void
pcapif_poll(struct netif *netif)
{
  ...
  do {
if (pa->adapter != NULL) {
  ret = pcap_dispatch(pa->adapter, -1, pcapif_input, (u_char*)pa);
} else {
  ret = -1;
}
...
  } while (ret > 0);
}

In NO_SYS=1 I have the classical mainloop:

while(1) {
  default_netif_poll();
  sys_check_timeouts();
  my_other_tasks();
}

So, during all the download process, mainloop is stucked in 
default_netif_poll() that calls pcapif_poll().


I think the loop in pcapif_poll() takes care of all the incoming packets 
pending in the receveing buffers, so I suspect the packets arrive faster 
than lwip application is capable to process them, so incoming packets 
are always available after every pcap_dispatch().


Maybe pcapip_poll() can be changed to call pcap_dispatch() a maximum 
number of times.


___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users


Re: [lwip-users] mbedtls

2023-04-14 Thread Giuseppe Modugno

Il 14/04/2023 20:19, Simon Goldschmidt ha scritto:


On 13.04.2023 13:23, Giuseppe Modugno wrote:

What is the latest mbedtls version that is compatible with lwip,
specifically the layer altcp_tls_mbedtls.c?



Sorry, the current source did not track the version which it is
compatible with. But I'd gladly accept patches covering that or
improving compatibility with newer mbedtls versions.


I just checked with Mbed TLS 2.28.3, that is the last 2.x.x version, and 
it works.


Mbed TLS 3.x.x is a major upgrade that breaks some API compatibility[1].

[1] 
https://github.com/Mbed-TLS/mbedtls/blob/development/docs/3.0-migration-guide.md


___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users


[lwip-users] mbedtls integration

2023-04-14 Thread Giuseppe Modugno
In the past I enabled ALTCP layer to add TLS and I used 
altcp_tls_mbedtls examples present in lwip repo.

I thought it was the way to add TLS to lwip.

Recently I looked at some example projects of NXP, such as this[1].
This is an example of a TLS httpd server. TLS is added by mbedtls, but 
ALTCP lwip support is NOT enabled (and altcp_tls_mbedtls is NOT enabled 
too).


It seems NXP uses a different (patched?) httpd implementation with 
integrated mbedtls support. I couldn't understand if this is a smarter 
way to add TLS support to lwip (that avoid ALTCP at all) or an old way 
that should be avoided nowadays that is available ALTCP and 
altcp_tls_mbedtls.



[1] 
https://github.com/nxp-mcuxpresso/mcux-sdk-examples/tree/main/lpcxpresso54628/lwip_examples/lwip_httpssrv_mbedTLS/bm


___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users


[lwip-users] mbedtls

2023-04-13 Thread Giuseppe Modugno
What is the latest mbedtls version that is compatible with lwip, 
specifically the layer altcp_tls_mbedtls.c?


For sure, current development source code of lwip is not compatible with 
latest mbedtls version. Indeed, you can see in altcp_tls_mbedtls.c the 
following includes:


|#include "mbedtls/certs.h"|
|||#include "mbedtls/ssl_internal.h" /* to call mbedtls_flush_output after 
ERR_MEM */|

||
|However those files are not present (anymore?) in mbedtls[1].|
||
|[1] https://github.com/Mbed-TLS/mbedtls|
||

|
|||


___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users


Re: [lwip-users] [OT] Sync local time to NTP

2023-01-05 Thread Giuseppe Modugno

Il 04/01/2023 21:46, goldsi...@gmx.de ha scritto:

Am 30.12.2022 um 17:10 schrieb Giuseppe Modugno:

The typical scenario of lwip is an embedded platform. When a wall clock
is needed and the device is network connected, NTP is usually used to
retrieve automatically the correct time at startup and stay in sync with
an accurate reference (in other cases, the user can set a time as he 
wants).


Consider an embedded device without a battery. At startup there's no
notion of current time, so we can start from an epoch (1970, 2020 or
whatever) and consider it the correct time. Another approach is
considering the time not initialized at all.

lwip has a SNTP client implementation that magically calls a function


Absolutely no magic in there: when a response from a server is received,
it is parsed and this callback is called with the time received.


Sure, I wrote "magically" just to mean that I (lwip user) don't do 
anything else than enabling NTP and setting servers.




SNTP_SET_SYSTEM_TIME_NTP(s, f) when a response from a SNTP server is
received. Now the question is what to do with s, seconds from 1970 epoch
(ignore fractional part, just to simplify).


This is one level upwards from lwIP. We provide the protocol
implementations, not your system design.


Indeed I prefixed the subject of the post with [OT]. I'd like to 
exchange some experiences with other lwip users.




One possibility is to have a system counter clocked at 1s that counts
seconds from 1970. So SNTP_SET_SYSTEM_TIME_NTP() could simply overwrite
the counter value. However this simple approach brings to a counter that
isn't monotonic and continuous. I know the best approach is to slowed
down or accelerate the reference clock of the system counter that tracks
seconds from epoch.

Do you really implement something similar or are you happy with
replacing the counter with the new value reported by NTP?


That totally depends on what you desire for your product (what you use
the timestamp for). For example, if you only use it for logging, it
might be enough to add a line to your log that states the received time
and the delta.


First of all, in my application I need "wall clock" for logging certain 
important
events, with a resolution of seconds. I never measured it, but I think 
NTP jitter should
be much smaller, maybe under 1 second. So brutally replacing the system 
counter
with NTP counter (as it is received and calculated by lwip SNTP) should 
be acceptable.


The big problem is that my application should make some actions at 
specific times
configured by the user. For example, switch on a lamp at 8:00AM every 
Mon-Fri and switch

off the lamp at 8:00PM every Mon-Fri.

If I use a simple counter of seconds from an epoch clocked by a local 
reference, no problem
occur. This couter will monotonic and will *not* experience any delta 
greater than 1 sec.
However I want to keep in sync this "local" counter with the counter 
received by NTP.
If I brutally replace local counter with NTP counter, some problem could 
occur.


What happens if NTP 8:01AM is reiceived when the local counter is at 
7:59AM? There's a risk
the event scheduled for 8:00AM won't be executed. What happens if NTP 
7:59AM is
reiceived when local counter is at 8:01AM? There's the risk one event is 
fired two times.


This is my concern that motivated me to post on this group asking how to 
do with the

counter received from NTP.



Linux, on the other hand has at least 2 clocks, one "monotinic" clock
(e.g. ticks since boot) and one "wall" clock. Timsync daemons may still
vote to add a syslog line if the received SNTP time differs too much
from what they would expect.
Linux shoud implement a full NTP client, so it filters replies from many 
servers and decides

when a big step (against the local counter) must be accepted or ignored.

There's only one reason to have a big step: at startup, when the wall 
clock isn't known.
After the first time sync (the first NTP response), the delta between 
local counter and
NTP counter should be very small. Anyway the decision to accept only one 
big delta
after startup is risky, because other and obscure reasons could happen 
that bring to a
wrong local counter that will not be ever adjusted if big deltas are 
ignored.


It appears a simple task, but it hides many complex issues.


___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users


[lwip-users] [OT] Sync local time to NTP

2022-12-30 Thread Giuseppe Modugno
The typical scenario of lwip is an embedded platform. When a wall clock 
is needed and the device is network connected, NTP is usually used to 
retrieve automatically the correct time at startup and stay in sync with 
an accurate reference (in other cases, the user can set a time as he wants).


Consider an embedded device without a battery. At startup there's no 
notion of current time, so we can start from an epoch (1970, 2020 or 
whatever) and consider it the correct time. Another approach is 
considering the time not initialized at all.


lwip has a SNTP client implementation that magically calls a function 
SNTP_SET_SYSTEM_TIME_NTP(s, f) when a response from a SNTP server is 
received. Now the question is what to do with s, seconds from 1970 epoch 
(ignore fractional part, just to simplify).


One possibility is to have a system counter clocked at 1s that counts 
seconds from 1970. So SNTP_SET_SYSTEM_TIME_NTP() could simply overwrite 
the counter value. However this simple approach brings to a counter that 
isn't monotonic and continuous. I know the best approach is to slowed 
down or accelerate the reference clock of the system counter that tracks 
seconds from epoch.


Do you really implement something similar or are you happy with 
replacing the counter with the new value reported by NTP?




___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users


Re: [lwip-users] Test offloading checksum for receive path

2022-10-14 Thread Giuseppe Modugno


Il 13/10/2022 20:02, Simon Goldschmidt ha scritto:

On 13.10.2022 12:59, Giuseppe Modugno wrote:

LPC546xx MCUs have the capability to offload checksum for IP, TCP, UDP
and ICMP, for outgoing and ingoing packets.

I enabled the generation of checksum for IPv4 for outgoing packets and
it seems working well. Now I want to enable and test checksum offload
for incoming IPv4 datagrams, but I'm in trouble how to test.

I should have the possibility to generate and send an IP datagram with
a wrong checksum from a host on the same LAN of lwip device.

Do you know of any tool that can do this kind of thing on Windows?



There are multiple ways to go, but the simplest probably is to capture
with Wireshark, save a pcap with only one packet, open that packet in a
Hex Editor (like HxD) and change its checksum (verify again with
Wireshark). Then, find a tool to send that packet back to the net. A
quick online search yields "Packet Sender" or "PReplay" for that task.


Packet Sender is able to send whatever TCP/UDP packet, but not an IP 
datagram. It means you can't change the IP datagram checksum, because 
the IP datagram is generated by OS.



preplay[1] is more interesting, I will take a look at it. I don't know 
the format of pcap files, I hope it's possible to change it manually to 
break the IP checksum.



___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users


[lwip-users] Test offloading checksum for receive path

2022-10-13 Thread Giuseppe Modugno
LPC546xx MCUs have the capability to offload checksum for IP, TCP, UDP 
and ICMP, for outgoing and ingoing packets.


I enabled the generation of checksum for IPv4 for outgoing packets and 
it seems working well. Now I want to enable and test checksum offload 
for incoming IPv4 datagrams, but I'm in trouble how to test.


I should have the possibility to generate and send an IP datagram with a 
wrong checksum from a host on the same LAN of lwip device.


Do you know of any tool that can do this kind of thing on Windows?

___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users


Re: [lwip-users] LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT

2022-10-13 Thread Giuseppe Modugno

Il 12/10/2022 21:11, goldsi...@gmx.de ha scritto:

Am 11.10.2022 um 17:11 schrieb Giuseppe Modugno:

Another thing I can't understand is why the code around
LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT is needed if:

  * NO_SYS=1
  * MEM_USE_POOLS=0
  * MEM_LIBC_MALLOC=0
  * SYS_LIGHTWEIGHT_PROT=1
  * sys_arch_protect() simply disables interrupts

In mem_malloc there's a point where LWIP_MEM_ALLOC_PROTECT is called,
before the "scan through the heap searching for a free block". Why
during the scan, for each loop, UNPROTECT/PROTECT are called? The
comment says /* allow mem_free or mem_trim to run */.

Maybe this is done because the scan could take a long time to finish
(for big and fragmented heap) and having interrupts disabled for so long
time is not good? So the interrupts are enabled and disabled for each
loop to give them opportunity to run?


Exactly:
- Heap allocation takes a mutex as it should not block interrupts while
scanning for memory (takes too long).
- Heap free is fast as it does not need to scan.

Therefore, heap allocation uses double protection: mutex to block
against other allocations, PROTECT/UNPROTECT to protect against
concurrent free.


Ok, thank you for the answer.

Do you think it's possible to implement a pbuf_free_callback() in 
NO_SYS=1 that can be called in ISR instead instead of pbuf_free()?


The goal is to avoid disabling interrupts at all setting 
SYS_LIGHTWEIGHT_PROT=0 to disable PROTECT/UNPROTECT mechanism.


The only lwip function that NXP code uses in ISR is pbuf_free() (that 
needs to be protected with disabling interrupts and 
LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT), so I'm searching an alternative 
way to avoid this.



___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users


Re: [lwip-users] LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT

2022-10-11 Thread Giuseppe Modugno
Another thing I can't understand is why the code around 
LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT is needed if:


 * NO_SYS=1
 * MEM_USE_POOLS=0
 * MEM_LIBC_MALLOC=0
 * SYS_LIGHTWEIGHT_PROT=1
 * sys_arch_protect() simply disables interrupts

In mem_malloc there's a point where LWIP_MEM_ALLOC_PROTECT is called, 
before the "scan through the heap searching for a free block". Why 
during the scan, for each loop, UNPROTECT/PROTECT are called? The 
comment says /* allow mem_free or mem_trim to run */.


Maybe this is done because the scan could take a long time to finish 
(for big and fragmented heap) and having interrupts disabled for so long 
time is not good? So the interrupts are enabled and disabled for each 
loop to give them opportunity to run?



Il 11/10/2022 11:10, Giuseppe Modugno ha scritto:
Thanks Simon. I want to summarize here all the possibilities with 
NO_SYS=1, please confirm if I'm right.


** MEM_USE_POOLS=0, MEM_LIBC_MALLOC=0
lwip internal dynamic memory allocator from a static array 
(implemented in mem.c)
To use pbuf_free() in ISR (and main loop), we need to set 
LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT *and* define 
SYS_ARCH_PROTECT/UNPROTECT as macros that disable/enable interrupts.
Of course, sys_mutex_lock() and similar functions can be void, because 
there's only one thread (mainloop) in NO_SYS=1.


** MEM_USE_POOLS=1, MEM_LIBC_MALLOC=0
Lwip memory pools used as dynamic memory allocator (mem.c and memp.c)
As you wrote, memory pools implementation in memp.c is reentrant, so 
pub_free can be called safely from ISR, even without 
LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT.
What I don't understand if SYS_ARCH_PROTECT (that is used in memp) 
should disable interrupts or this isn't needed.
If yes, this solution doesn't solve the problem of disabling 
interrupts frequently.


** MEM_USE_POOLS=1, MEM_LIBC_MALLOC=1
Lwip malloc/free calls libc malloc/free
In my case, I'm using newlib-nano. Even in this case, from newlib 
documentation[1], I need to implement __malloc_lock/unlock that must 
disable interrupts again.



If all is correct, there isn't a "standard" solution to avoid 
disabling interrupts when pbuf_free is called in ISR context (always 
for NO_SYS=1).
Anyway I think it shouldn't be so difficult to write a 
pbuf_free_callback for NO_SYS=1 that pushes the pbuf to be freed in a 
simple FIFO implementation.
In the mainloop, a pbuf_free_task can be continuously called. This 
function pops a pbuf from the FIFO and calls pbuf_free on it.



[1] https://sourceware.org/newlib/libc.html#g_t_005f_005fmalloc_005flock



Il 11/10/2022 06:25, Simon Goldschmidt ha scritto:


Am 10. Oktober 2022 18:32:15 MESZ schrieb Giuseppe Modugno 
:

I'm sorry to post again.

I just understood LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEX is used in 
mem.c for MEM_USE_POOLS=0 and MEM_LIBC_MALLOC=0 (default lwip heap 
management from a statically allocated buffer).


What about the reentrancy of memory pools? What happens when 
MEM_USE_POOLS=1 and pbuf_free is called in ISR, with or without 
LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT? It seems memory pools free 
is safe to be used from ISR, because I don't see any protection for 
them (differently of lwip default dynamic allocator).

Yes, it is.

Regards,
Simon

___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users


Re: [lwip-users] LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT

2022-10-11 Thread Giuseppe Modugno
Thanks Simon. I want to summarize here all the possibilities with 
NO_SYS=1, please confirm if I'm right.


** MEM_USE_POOLS=0, MEM_LIBC_MALLOC=0
lwip internal dynamic memory allocator from a static array (implemented 
in mem.c)
To use pbuf_free() in ISR (and main loop), we need to set 
LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT *and* define 
SYS_ARCH_PROTECT/UNPROTECT as macros that disable/enable interrupts.
Of course, sys_mutex_lock() and similar functions can be void, because 
there's only one thread (mainloop) in NO_SYS=1.


** MEM_USE_POOLS=1, MEM_LIBC_MALLOC=0
Lwip memory pools used as dynamic memory allocator (mem.c and memp.c)
As you wrote, memory pools implementation in memp.c is reentrant, so 
pub_free can be called safely from ISR, even without 
LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT.
What I don't understand if SYS_ARCH_PROTECT (that is used in memp) 
should disable interrupts or this isn't needed.
If yes, this solution doesn't solve the problem of disabling interrupts 
frequently.


** MEM_USE_POOLS=1, MEM_LIBC_MALLOC=1
Lwip malloc/free calls libc malloc/free
In my case, I'm using newlib-nano. Even in this case, from newlib 
documentation[1], I need to implement __malloc_lock/unlock that must 
disable interrupts again.



If all is correct, there isn't a "standard" solution to avoid disabling 
interrupts when pbuf_free is called in ISR context (always for NO_SYS=1).
Anyway I think it shouldn't be so difficult to write a 
pbuf_free_callback for NO_SYS=1 that pushes the pbuf to be freed in a 
simple FIFO implementation.
In the mainloop, a pbuf_free_task can be continuously called. This 
function pops a pbuf from the FIFO and calls pbuf_free on it.



[1] https://sourceware.org/newlib/libc.html#g_t_005f_005fmalloc_005flock



Il 11/10/2022 06:25, Simon Goldschmidt ha scritto:


Am 10. Oktober 2022 18:32:15 MESZ schrieb Giuseppe Modugno 
:

I'm sorry to post again.

I just understood LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEX is used in mem.c for 
MEM_USE_POOLS=0 and MEM_LIBC_MALLOC=0 (default lwip heap management from a 
statically allocated buffer).

What about the reentrancy of memory pools? What happens when MEM_USE_POOLS=1 
and pbuf_free is called in ISR, with or without 
LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT? It seems memory pools free is safe to 
be used from ISR, because I don't see any protection for them (differently of 
lwip default dynamic allocator).

Yes, it is.

Regards,
Simon

___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users


___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users


Re: [lwip-users] LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT

2022-10-10 Thread Giuseppe Modugno

I'm sorry to post again.

I just understood LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEX is used in mem.c 
for MEM_USE_POOLS=0 and MEM_LIBC_MALLOC=0 (default lwip heap management 
from a statically allocated buffer).


What about the reentrancy of memory pools? What happens when 
MEM_USE_POOLS=1 and pbuf_free is called in ISR, with or without 
LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT? It seems memory pools free is 
safe to be used from ISR, because I don't see any protection for them 
(differently of lwip default dynamic allocator).



Il 10/10/2022 18:22, Giuseppe Modugno ha scritto:
I'm sorry, I'm using MEM_USE_POOLS=0 *and* MEM_LIBC_MALLOC=1 *and* 
mem_clib_free/mem_clib_malloc redefined to a  custom buffer-based 
memory allocator (derived from mbedtls[1].



Il 10/10/2022 18:15, Giuseppe Modugno ha scritto:
After studying a little more, I understood the problem of using 
pbuf_free() in ISR can be solved in two ways:


 * by setting LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT to 1 (NO_SYS=0 
or 1)

 * by using pub_free_callback() in ISR, instead of pbuf_free, only when
   NO_SYS=0

The first approach will add protection (disabling/enabling 
interrupts) when lwip needs malloc. This isn't a very good approach, 
because interrupts would be disabled frequently, but I haven't any 
knowledge with RTOS so it's much complex for me to add any to my 
project. So I'm working with the following configuration:


 * NO_SYS=1 (no OS)
 * LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEX=1 (because pbuf_free is called
   in ISR)
 * MEM_USE_POOLS=0 *and* mem_clib_free/mem_clib_malloc redefined to a
   custom buffer-based memory allocator (derived from mbedtls[1])

I suspect this scenario is not safe, because memory allocator from 
mbedtls isn't designed to be reentrant from an ISR (as for the memory 
pools of lwip when LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEX is set to 
1). And for me is very difficult to fix the reentrancy problem of 
this allocator.


So I'm thinking the best solution to solve this problem without an OS 
is to abandon buffer-based memory allocator and migrate to another 
allocator that could be: lwip memory pools (MEM_USE_POOLS=1) or 
newlib heap (MEM_USE_POOLS=0 and mem_clib_malloc=malloc and 
mem_clib_free=free). What do you suggest?



Anyway I don't understand one thing. Why pbuf_free_callback() can't 
be called without an OS? It calls tcpip_try_callback that allocates a 
message for tcpip_thread. It shouldn't be difficult to create a list 
of pbufs that are waiting to be freed during sys_check_timeouts. What 
do you think?



[1] 
https://github.com/Mbed-TLS/mbedtls/blob/development/library/memory_buffer_alloc.c



Il 04/10/2022 16:46, Giuseppe Modugno ha scritto:
I started from an example of NXP SDK for LPC546xx MCUs. I'm using 
baremetal (NO_SYS=1) and I found the following warning in 
enet_ethernetif_lpc.c, function ethernetif_tx_release():


---
#if NO_SYS
#if defined(LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT) && 
LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT

    pbuf_free(p);
#else
#error "Bare metal requires LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT=1 
because pbuf_free() is being called from an ISR"

#endif /* LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT */
...
---

It seems NXP code calls pbuf_free() inside ISR and this behaviour 
must be known to lwip by setting 1 to this macro. However it seems 
this macro is checked only in mem.c, if MEM_USE_POOLS is defined.


In my application I don't define MEM_USE_POOLS, so it is set to 0 by 
default in opt.h.


Does it mean I can avoid setting 
LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEX? I would like to set it to 0, 
because of the following warning found in opt.h:


---
 * ATTENTION: As you can see from the above description, this leads 
to dis-/
 * enabling interrupts often, which can be slow! Also, on low 
memory, mem_malloc

 * can need longer.
---

However NXP code uses #error if this macro is not set, so I suspect 
there's a real risk to avoid setting it.





___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users


Re: [lwip-users] LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT

2022-10-10 Thread Giuseppe Modugno
I'm sorry, I'm using MEM_USE_POOLS=0 *and* MEM_LIBC_MALLOC=1 *and* 
mem_clib_free/mem_clib_malloc redefined to a  custom buffer-based memory 
allocator (derived from mbedtls[1].



Il 10/10/2022 18:15, Giuseppe Modugno ha scritto:
After studying a little more, I understood the problem of using 
pbuf_free() in ISR can be solved in two ways:


 * by setting LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT to 1 (NO_SYS=0 or 1)
 * by using pub_free_callback() in ISR, instead of pbuf_free, only when
   NO_SYS=0

The first approach will add protection (disabling/enabling interrupts) 
when lwip needs malloc. This isn't a very good approach, because 
interrupts would be disabled frequently, but I haven't any knowledge 
with RTOS so it's much complex for me to add any to my project. So I'm 
working with the following configuration:


 * NO_SYS=1 (no OS)
 * LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEX=1 (because pbuf_free is called
   in ISR)
 * MEM_USE_POOLS=0 *and* mem_clib_free/mem_clib_malloc redefined to a
   custom buffer-based memory allocator (derived from mbedtls[1])

I suspect this scenario is not safe, because memory allocator from 
mbedtls isn't designed to be reentrant from an ISR (as for the memory 
pools of lwip when LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEX is set to 1). 
And for me is very difficult to fix the reentrancy problem of this 
allocator.


So I'm thinking the best solution to solve this problem without an OS 
is to abandon buffer-based memory allocator and migrate to another 
allocator that could be: lwip memory pools (MEM_USE_POOLS=1) or newlib 
heap (MEM_USE_POOLS=0 and mem_clib_malloc=malloc and 
mem_clib_free=free). What do you suggest?



Anyway I don't understand one thing. Why pbuf_free_callback() can't be 
called without an OS? It calls tcpip_try_callback that allocates a 
message for tcpip_thread. It shouldn't be difficult to create a list 
of pbufs that are waiting to be freed during sys_check_timeouts. What 
do you think?



[1] 
https://github.com/Mbed-TLS/mbedtls/blob/development/library/memory_buffer_alloc.c



Il 04/10/2022 16:46, Giuseppe Modugno ha scritto:
I started from an example of NXP SDK for LPC546xx MCUs. I'm using 
baremetal (NO_SYS=1) and I found the following warning in 
enet_ethernetif_lpc.c, function ethernetif_tx_release():


---
#if NO_SYS
#if defined(LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT) && 
LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT

    pbuf_free(p);
#else
#error "Bare metal requires LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT=1 
because pbuf_free() is being called from an ISR"

#endif /* LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT */
...
---

It seems NXP code calls pbuf_free() inside ISR and this behaviour 
must be known to lwip by setting 1 to this macro. However it seems 
this macro is checked only in mem.c, if MEM_USE_POOLS is defined.


In my application I don't define MEM_USE_POOLS, so it is set to 0 by 
default in opt.h.


Does it mean I can avoid setting 
LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEX? I would like to set it to 0, 
because of the following warning found in opt.h:


---
 * ATTENTION: As you can see from the above description, this leads 
to dis-/
 * enabling interrupts often, which can be slow! Also, on low memory, 
mem_malloc

 * can need longer.
---

However NXP code uses #error if this macro is not set, so I suspect 
there's a real risk to avoid setting it.





___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users


Re: [lwip-users] LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT

2022-10-10 Thread Giuseppe Modugno
After studying a little more, I understood the problem of using 
pbuf_free() in ISR can be solved in two ways:


 * by setting LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT to 1 (NO_SYS=0 or 1)
 * by using pub_free_callback() in ISR, instead of pbuf_free, only when
   NO_SYS=0

The first approach will add protection (disabling/enabling interrupts) 
when lwip needs malloc. This isn't a very good approach, because 
interrupts would be disabled frequently, but I haven't any knowledge 
with RTOS so it's much complex for me to add any to my project. So I'm 
working with the following configuration:


 * NO_SYS=1 (no OS)
 * LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEX=1 (because pbuf_free is called
   in ISR)
 * MEM_USE_POOLS=0 *and* mem_clib_free/mem_clib_malloc redefined to a
   custom buffer-based memory allocator (derived from mbedtls[1])

I suspect this scenario is not safe, because memory allocator from 
mbedtls isn't designed to be reentrant from an ISR (as for the memory 
pools of lwip when LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEX is set to 1). 
And for me is very difficult to fix the reentrancy problem of this 
allocator.


So I'm thinking the best solution to solve this problem without an OS is 
to abandon buffer-based memory allocator and migrate to another 
allocator that could be: lwip memory pools (MEM_USE_POOLS=1) or newlib 
heap (MEM_USE_POOLS=0 and mem_clib_malloc=malloc and 
mem_clib_free=free). What do you suggest?



Anyway I don't understand one thing. Why pbuf_free_callback() can't be 
called without an OS? It calls tcpip_try_callback that allocates a 
message for tcpip_thread. It shouldn't be difficult to create a list of 
pbufs that are waiting to be freed during sys_check_timeouts. What do 
you think?



[1] 
https://github.com/Mbed-TLS/mbedtls/blob/development/library/memory_buffer_alloc.c



Il 04/10/2022 16:46, Giuseppe Modugno ha scritto:
I started from an example of NXP SDK for LPC546xx MCUs. I'm using 
baremetal (NO_SYS=1) and I found the following warning in 
enet_ethernetif_lpc.c, function ethernetif_tx_release():


---
#if NO_SYS
#if defined(LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT) && 
LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT

    pbuf_free(p);
#else
#error "Bare metal requires LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT=1 
because pbuf_free() is being called from an ISR"

#endif /* LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT */
...
---

It seems NXP code calls pbuf_free() inside ISR and this behaviour must 
be known to lwip by setting 1 to this macro. However it seems this 
macro is checked only in mem.c, if MEM_USE_POOLS is defined.


In my application I don't define MEM_USE_POOLS, so it is set to 0 by 
default in opt.h.


Does it mean I can avoid setting 
LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEX? I would like to set it to 0, 
because of the following warning found in opt.h:


---
 * ATTENTION: As you can see from the above description, this leads to 
dis-/
 * enabling interrupts often, which can be slow! Also, on low memory, 
mem_malloc

 * can need longer.
---

However NXP code uses #error if this macro is not set, so I suspect 
there's a real risk to avoid setting it.





___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users


[lwip-users] LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT

2022-10-04 Thread Giuseppe Modugno
I started from an example of NXP SDK for LPC546xx MCUs. I'm using 
baremetal (NO_SYS=1) and I found the following warning in 
enet_ethernetif_lpc.c, function ethernetif_tx_release():


---
#if NO_SYS
#if defined(LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT) && 
LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT

    pbuf_free(p);
#else
#error "Bare metal requires LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT=1 
because pbuf_free() is being called from an ISR"

#endif /* LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT */
...
---

It seems NXP code calls pbuf_free() inside ISR and this behaviour must 
be known to lwip by setting 1 to this macro. However it seems this macro 
is checked only in mem.c, if MEM_USE_POOLS is defined.


In my application I don't define MEM_USE_POOLS, so it is set to 0 by 
default in opt.h.


Does it mean I can avoid setting LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEX? 
I would like to set it to 0, because of the following warning found in 
opt.h:


---
 * ATTENTION: As you can see from the above description, this leads to 
dis-/
 * enabling interrupts often, which can be slow! Also, on low memory, 
mem_malloc

 * can need longer.
---

However NXP code uses #error if this macro is not set, so I suspect 
there's a real risk to avoid setting it.




___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users


[lwip-users] PPPoSerial and 4G modem

2022-02-25 Thread Giuseppe Modugno

I'm trying to make a data connection with a 4G modem from SIMCOM (A7672E).

After AT+CGDATA=... and ATD*99#, the modem replies with CONNECT and 
enters in online data state.


Now I'm ready to launch lwip app configured to use PPPoSerial and 
sntp_example (just to understand if the full stack is operating). I'm 
using last lwip commit and building in Windows with mingw compiler. At 
the end you'll find the log.


As you can see, PPP connection is established, but with the warning 
Could not determine remote IP address: defaulting to 10.64.64.64.

I don't know if this warning is important or not.

Moreover, PPP callback doesn't show any DNS configured for netif, but 
PPP subsystem shows two DNS servers afterward.


Another thing is the message udp_send: No route to 93.94.88.50. 
(93.94.88.50 should be the IP address of pool.ntp.org, one of available 
SNTP server). In this case I suspect PPP hadn't configured the netif 
with the correct gateway.


Even if I set the SNTP server name, the DNS subsystem complains because 
no DNS server is configured.



$ .\example_app.exe 6
Using serial port 6 for PPP
ppp_connect: COM6
sio_open: file "\\.\COM6" (6) successfully opened: 0x01d8
ppp phase changed[1]: phase=0
ppp_connect[1]: holdoff=0
ppp phase changed[1]: phase=3
pppos_connect: unit 1: connecting
ppp_start[1]
ppp phase changed[1]: phase=6
ppp_send_config[1]
pppos_send_config[1]: out_accm=FF FF FF FF
ppp_recv_config[1]
pppos_recv_config[1]: in_accm=FF FF FF FF
ppp: auth protocols: PAP=1 CHAP=1 CHAP_MD5=1
pppos_write[1]: len=24
ppp_start[1]: finished
sntp_init: SNTP initialised
sntp_request: current server address is 93.94.88.50
sntp_send_request: Sending request to server
udp_send
udp_send: No route to 93.94.88.50
pppos_write[1]: len=24
pppos_input[1]: got 96 bytes
pppos_write[1]: len=28
ppp_netif_set_mtu[1]: mtu=1500
ppp_send_config[1]
pppos_send_config[1]: out_accm=0 0 0 0
ppp_recv_config[1]
pppos_recv_config[1]: in_accm=0 0 0 0
ppp phase changed[1]: phase=7
pppos_write[1]: len=19
pppos_input[1]: got 12 bytes
PAP authentication succeeded
ppp phase changed[1]: phase=9
pppos_write[1]: len=14
pppos_input[1]: got 38 bytes
pppos_write[1]: len=14
pppos_write[1]: len=26
pppos_input[1]: got 38 bytes
pppos_write[1]: len=8
Could not determine remote IP address: defaulting to 10.64.64.64
sifup[1]: err_code=0
pppLinkStatusCallback: PPPERR_NONE
   our_ipaddr  = 10.10.245.68
   his_ipaddr  = 10.64.64.64
   netmask = 255.255.255.255
   dns1    = 0.0.0.0
   dns2    = 0.0.0.0
local  IP address 10.10.245.68
remote IP address 10.64.64.64
primary   DNS address 10.133.18.210
secondary DNS address 10.132.100.181
ppp phase changed[1]: phase=10
sntp_retry: Next request will be sent in 15000 ms
sntp_request: current server address is 93.94.88.50
sntp_send_request: Sending request to server
udp_send
udp_send: No route to 93.94.88.50



___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users


Re: [lwip-users] LPC1788 Ethernet Based Socket Communication Randomly Stops Working After Few Hours

2022-01-04 Thread Giuseppe Modugno
I'm using LPC1788 for a product that is in full production for a couple 
of years without many problems.


Unfortunately I'm using now RTOS and raw API, so I don't think I can 
help you.


Most probably, other users will reply with suggestions on how to track 
and identify your issue.


Il 04/01/2022 06:16, Devsarkar, Pratap [AUTOSOL/BRSN/IN] ha scritto:


Hi,

We are using LPC1788 OEM Board REV E.of Embedded Artists.
We are using MCUXpresso IDE V11.3.0 and FreeRTOS Lwip stack.

The FreeRTOS  version is *"V7.5.3".*

**

*The LWIP version is *

This Board uses a socket communication to communicate with other board 
at 1ms time interval.
Randomly after few hours the LPC1788 Board stops working so The socket 
communication also  stops.


Please help us to resolve the issue.

Thanks and Regards,

Pratap Devsarkar.


___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users


___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users


Re: [lwip-users] lwip with 4G modem

2021-10-13 Thread Giuseppe Modugno

Il 12/10/2021 19:17, Sylvain Rochet ha scritto:

Hi Giuseppe,

On Tue, Oct 12, 2021 at 09:26:00AM +0200, Giuseppe Modugno wrote:

I have an embedded project where lwip is used in a microcontroller
(Cortex-M3 by LPC). The network interface is a standard Ethernet. The MCU
features a MMI interface with an external Ethernet PHY.

It works well, I'm able to open a MQTTs connection with a broker, enable NTP
request, download some file from HTTP server.

Now I'd like to use this project as a base for a new project, where the
network interface will be replaced by a 4G modem that is controlled by
standard AT commands.

My question is: what should I change in my project to replace Ethernet with
4G modem? I think I have to use ppp over a serial line to open a 4G data
connection and it seems ppp is supported by lwip distribution.


Yes, you need to use PPPoS(erial).

You have to setup your modem to enter PPP data mode then read/write
HDLC/PPP bytestreams from/to the modem and lwIP.


If I understand well, there's a standard AT command to define a PPP-type 
PDP context for cellular modems (defined in ETS TS 127 007):


  AT+CGDCONT=,[]

where:

   is a string that could be "PPP",...

So I think I must send the command:

  AT+CGDCONT=1,"PPP",...
  AT+CGATT=1
  AT+CGACT=1,1

to activate PDP context in PPP mode. However the specifications says, 
regarding AT+CGACT:


   After the command has completed, the MT remains in V.250
   command state.

So the question is: how to switch to V.250 online mode? The only command 
that should switch to V.250 online mode is +CGDATA, but I couldn't 
understand how to use, because it seems it replaces +CGATT and +CGACT. I 
think it should be:


  AT+CGDCONT=1,"PPP",...
  AT+CGDATA="PPP",1

There's another method to activate data connection, this is named "modem 
compatibility mode". You can use "old" ATD command to establish a data 
connection, receiveng CONNECT as the answer and entering V.250 online 
data state:


  ATD*99#;


Reading the specifications I noted there is another PDP_type, that is 
"IP". So I'm wondering if PPP is mandatary or can be avoided completely 
by activating a IP-based PDP type.


PPP is a little complex, so it would be nice if it can be avoided at all.




Another question (I don't know if it is OT), will I be able to make voice
calls at the same time the data connection is open and active?


This is not related to lwIP, check your modem documentation ;-)



The serial channel for ppp/data and AT commands is single, so how can
I multiplex them? Should I use CMUX?


CMUX is the proper way to do so.



Last question. If I have 4G modem and Ethernet PHY, is lwip able to manage
two network interface at the same time?


Yes! Beware of routing though, you will probably have to set the default
interface to the currently "working" interface and have to re-establish
all currently active TCP/UDP sessions on routing change.

Ok, thanks for suggesting.

___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users

Re: [lwip-users] lwip with 4G modem

2021-10-12 Thread Giuseppe Modugno

Il 12/10/2021 11:29, Gisle Vanem ha scritto:

Giuseppe Modugno wrote:

The serial channel for ppp/data and AT commands is single, so how can 
I multiplex them? Should I use CMUX?


The PPP protocol handles this multiplexing itself. Using an
escape octet "stuffing procedure" (octet 0x7d).
Read 'https://datatracker.ietf.org/doc/html/rfc1662' for the gory
details.


So will I be able to send AT commands (for example to make a voice call 
or read SMS) and receive/send bytes of data connection, over the same 
serial link?





Last question. If I have 4G modem and Ethernet PHY, is lwip able to 
manage two network interface at the same time?


Sure.



___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users

[lwip-users] lwip with 4G modem

2021-10-12 Thread Giuseppe Modugno
I have an embedded project where lwip is used in a microcontroller 
(Cortex-M3 by LPC). The network interface is a standard Ethernet. The 
MCU features a MMI interface with an external Ethernet PHY.


It works well, I'm able to open a MQTTs connection with a broker, enable 
NTP request, download some file from HTTP server.


Now I'd like to use this project as a base for a new project, where the 
network interface will be replaced by a 4G modem that is controlled by 
standard AT commands.


My question is: what should I change in my project to replace Ethernet 
with 4G modem? I think I have to use ppp over a serial line to open a 4G 
data connection and it seems ppp is supported by lwip distribution.


Another question (I don't know if it is OT), will I be able to make 
voice calls at the same time the data connection is open and active? The 
serial channel for ppp/data and AT commands is single, so how can I 
multiplex them? Should I use CMUX?


Last question. If I have 4G modem and Ethernet PHY, is lwip able to 
manage two network interface at the same time?





___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users

[lwip-users] lwip and ATWINC1500

2020-02-06 Thread Giuseppe Modugno
ATWINC1500 is a WiFi module that could work in Ethernet/Bypass mode. 
It's very interesting, because I already developed a network board with 
Ethernet connectivity and now I need to develop a similar network board 
with WiFi connectivity.


I would like to reuse as much software as I can, mostly lwip stack that 
runs on Ethernet board. Do you have any experience with ATWINC1500 in 
Ethernet mode with lwip? Is there a driver for ATWINC1500 or some 
suggestions to write one?




___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users

[lwip-users] DHCP and Ethernet disconnection

2019-12-10 Thread Giuseppe Modugno
I designed a network adapter board with Ethernet interface and lwip 
TCP/IP stack, with DHCP client enabled. It works well.


What happens if I disconnect the Ethernet cable from one network and 
connect it to a second network where is a different DHCP server? Mainly 
if the first network works on different address range (for example, 
192.168.1.x and 192.168.2.x with 255.255.255.0 netmask).


I tried and it appears lwip/DHCP client doesn't trigger a new DHCP 
request and continue working with the first IP address... so it doesn't 
work on the second network.



___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users

[lwip-users] How to override altcp_tls_mbedtls_mem.c

2019-06-11 Thread Giuseppe Modugno
As is written in altcp_tls_mbedtls_mem.c, I want to override this module 
with my own implementation. However I don't find an option to exclude 
lwip implementation from the build.


Actually I changed the source code of altcp_tls_mbedtls_mem.c, but I'd 
prefer to leave lwip code identical to the official release, so I can 
upgrade it flawlessly.




___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users

Re: [lwip-users] MQTT using lwip/pppos secure communication

2019-06-10 Thread Giuseppe Modugno

Hello Thomas,

I actually involved in a project similar to yours: NXP MCU (LPC1768) 
that connects to AWS IoT Core through MQTT over TLS.


It is complex, in my case because of limited RAM (only internal 
32k+32kB). I hope you have more space.


Anyway I was able to connect to AWS including lwip and mbedTLS and fine 
tuning some configuration parameters, mainly the dimensions of buffers.


You have to create a device in AWS and create certificates that you must 
include in your project. The problem here is the cryptography. Read 
here[1] how to create and use EC-based certificates that use much less 
RAM space.


Other improvementes in RAM usage can be obtained with some mbedTLS 
configurations. An hint: grab mbedTLS directly from git.


Does your application make a connection with AWS only?

[1] 
https://aws.amazon.com/it/blogs/iot/elliptic-curve-cryptography-and-forward-secrecy-support-in-aws-iot-3/


Il 08/06/2019 11:21, john vargh ha scritto:

Hello,

I am using NXP micro, with LWIP version 2.1.2
I have successfully established the MQTT communication with Mosquitto 
server.


Now, I want to communicate with Amazon server, using secure MQTT.
I want to know the basic steps OR which calls to use to INIT the process.
[ client & server handshake with certs.]

Any one as tried, just need to know the which calls to be used to get 
started.


MQTT_DO_CONNECT...

Thomas

___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users


___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users

[lwip-users] MQTT: is the incoming message always complete?

2019-06-04 Thread Giuseppe Modugno
I'm using lwip MQTT client implementation to publish messages and subscribe
to topics. I receive messages on subscribed topics with success.

Now I'm implementing a parser of incoming messages (maybe I'll use ASN.1
uPER encoded). However I'm not sure if I will receive always the complete
message or not.

The data callback is called with the flag MQTT_DATA_FLAG_LAST when the last
chunk of the message is received.

If there's any possibility that the message is received in parts, it's very
important, because I have to use a parser that doesn't necessarily need the
data in a single contiguous block of memory,
___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users

[lwip-users] How to manage non null-terminated strings

2019-05-30 Thread Giuseppe Modugno
Many times in the application payloads you have a message with non 
null-terminated string, where the length of the string is in another 
variable (derived from the length of the packet).


I think of MQTT messages that have strings. The callback parameters are 
the pointer to the first char of string and the length of string.


Many times I need to compare the string against a fixed reference 
string. However I can't use strncmp(), because it would success if the 
string is shorter than the reference string.


I could copy the string in another array, but I think there's a better 
method.



___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users


[lwip-users] Multiple instance of lwip on Windows

2019-05-16 Thread Giuseppe Modugno

I have a project that uses lwip/pcapif on Windows and it works well.

I wanted to run two instances of the same program with different mac 
address, ip address and so on. I started patching 
pcapif_low_level_init() to retrieve the mac address from an externa 
function (the original code used a fixed mac address):


static void
pcapif_low_level_init(struct netif *netif)
{
  u8_t my_mac_addr[ETH_HWADDR_LEN]; // = LWIP_MAC_ADDR_BASE;
  bsp_ENET_GetMacADDR(my_mac_addr);
  int adapter_num = PACKET_LIB_ADAPTER_NR;
  ...

However even after this change, two instances don't work simultaneously.

Do you know why? Is it a limitation of pcap libraries?


___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users


[lwip-users] MQTTs: connect after disconnect

2019-04-02 Thread Giuseppe Modugno
First MQTTs connection works fine. However I noticed that the second 
connection attempt after a disconnection doesn't work.


For example, if I unplug Ethernet cable, MQTT client detects connection 
failure (because of lacks of PINGRESP from server) and disconnect. The 
MQTT connection callback is normally called with 
status=MQTT_CONNECT_TIMEOUT, I fire a 3s timeout. In the timer callback, 
I call again mqtt_client_connect(), this time without success. As you 
can understand, I need to keep the connection to server up.


I'm investigating what happens and I found something strange. During 
mqtt_client_connect() many allocations were made with altcp_tls_new(). 
However I couldn't find where exactly those allocations are freed at 
disconnection time. I think I have some memory allocation problem during 
the second attempt, because the memory allocated during first connection 
isn't freed.



Another strange thing I noticed. Is it sure that mqtt_disconnect() 
shouldn't call connection callback registered in mqtt_client_connect()?



___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users


Re: [lwip-users] NXP LPC 17xx lwip port: use of pbuf for rx

2019-04-01 Thread Giuseppe Modugno

Il 29/03/2019 15:53, Sergio R. Caprile ha scritto:

The recommendations are to use separate pools for rx and tx so they can
not starve each other. Since PBUF_RAM is used for tx, then rx is
expected to use PBUF_POOL. I bet you can also use separate pools but I
don't know how.

Last time I checked, PBUF_RAM allocates a single block of memory. That
is probably the reason why these guys use them for DMA descriptors.
PBUF_POOL, on the other hand, *might* (not necessarily *will* but it
will surely bite you if you don't prepare for it) allocate several
buffers in a chain to satisfy your request. That is, your pbuf will be a
chain of pbufs.


I think I understood. However the LPC network driver allocates always 
ENET_ETH_MAX_FLEN-length pbufs. If PBUF_POOL_BUFSIZE is greater or equal 
ENET_ETH_MAX_FLEN (that is 1552 bytes) I don't think 
pbuf_alloc(PBUF_RAW, (u16_t) ENET_ETH_MAX_FLEN, PBUF_RAM) could return a 
pbuf chain.




While you can memcpy len bytes to a PBUF_RAM pbuf p where p->tot_len >=
len; you certainly can not do it to a PBUF_POOL and must loop through
all pbufs q=q->next writing up to q->len bytes to each one. Hope I'm
clear...

So, you'd better check what your driver is doing.
Keeping the rx side to PBUF_RAM can cause tx and rx to compete for
buffers (unless...)
Moving the rx side to PBUF_POOL if the driver was not properly written
for that, can cause memory corruption when the pool gets fragmented and
returned pbufs are chained ones.


___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users


[lwip-users] NXP LPC 17xx lwip port: use of pbuf for rx

2019-03-29 Thread Giuseppe Modugno

I'm using LPC1769 MCU. I'm using source code from NXP SDK that works.

I need to free some RAM to use mbedTLS libraries, so I was studying the 
code better. I found that NXP Ethernet driver preallocates a number of 
pbufs for RX DMA descriptors. The code uses:


    p = pbuf_alloc(PBUF_RAW, (u16_t) ENET_ETH_MAX_FLEN, PBUF_RAM);

When a new frame is received, a new pbuf is allocated with the same 
instruction. The pbuf of received frame is finally freed.


With PBUF_RAM parameter, this code allocates pbuf with mem_malloc, that 
is standard malloc in my case. However ENET_ETH_MAX_FLEN is 1552 bytes. 
With so many alloc and free of 1552 bytes, I will have big fragmentation.


So I replace PBUF_RAM with PBUF_POOL, to use memory pools that don't 
suffer from fragmentation. I tried and it works, but I don't know if 
there's some drawbacks in doing so.



___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users


Re: [lwip-users] altcp_tls_mbedtls

2019-02-26 Thread Giuseppe Modugno

Il 26/02/2019 09:58, Simon Goldschmidt ha scritto:

Giuseppe Modugno wrote:

An: lwip-users@nongnu.org
Betreff: Re: [lwip-users] altcp_tls_mbedtls

Il 25/02/2019 20:19, goldsi...@gmx.de ha scritto:

Am 22.02.2019 um 10:24 schrieb Giuseppe Modugno:

Il 22/02/2019 09:43, Simon Goldschmidt ha scritto:

[snip]


Is this warning correct? I think TCP_WND should be compared with
MBEDTLS_SSL_IN_CONTENT_LEN or MBEDTLS_SSL_OUT_CONTENT_LEN or the
maximum
of them (of course, I hope to compare it with OUT buffer only, because
it is smaller).

I think you're right: this should compare to the IN buffer. No that it
would help you here... :-)

I'm not an expert here, so my question could be very stupid. TCP_WND is
the TCP window that is used to avoid continuous ack for small data. The
transmitter sends data filling the window and then waits for the ack.

TCP_WND is what we announce to the remote host to be able to buffer
for RX.

For TX, what we buffer is the minimum of what the remote host tells us
to be able to buffer and the memory we have/allow (both available heap
memory and the limitation defines SND_BUF and SND_QUEUE_LEN).

Ok, but I couldn't understand the relation between lwip receiving window
and TLS incoming buffer. If MBEDTLS_SSL_IN_CONTENT_LEN is 16kB, should I
need a TCP_WND at least 16kB, for a total of 32kB of memory only to
handle incoming TLS traffic?

No. TCP_WND is not something you have allocated. It's the amount of data
the remote host can send before we reopen the window.

In the altcp TLS case, the data is received and ACKed, then the TLS
adaption layer passes it into mbedtls and frees the buffer. However, the
window update is sent by the application code that is TLS-agnostic. So
the window update is only sent after the block has been decrypted.


Could you point me to the code that reopen the window after the block 
has been decrypted? I couldn't find it, my shame.


Isn't possible to reopen the window (call tcp_recved) even when a 
partial TLS block is received? I couldn't understand why lwip needs to 
reopen the window only when an entire block is received (and decrypted 
by mbedTLS).
Suppose 1kB of a 16kB encrypted block is received, altcp_tls_mbedtls 
pass the data to the application mbedTLS that copy them in its buffer, 
then frees the received pbufs. Now we can reopen the window. What's 
wrong with this approach that can keep TCP_WND small?



And
since such a block may be up to 16 kByte, the tcp window has to be at
least that big, too, or you can get a deadlock.


Suppose I have a TCP_WND of only 2kB and incoming TLS buffer of 16kB.
The TLS transmitter could send maximum 2kB of data that are buffered in
the lwip receiving window. lwip calls altcp_recv(), so
altcp_mbedtls_lower_recv() with received data (2kB maybe segmented in
small pbufs and pbuf chains).

I can't follow the code, but I expect those data are immediately passed
to mbedTLS library that should copy those data to its 16kB incoming
buffer, freeing receiving window. I think the lwip TCP receiving window
could be smaller than mbedTLS incoming data buffer.

To make the receiving window smaller, you'd have to change the code.
However, you would gain nothing: TCP_WND is *not* a buffer. The actual
buffer is in mbedtls and you can't shrink that. TCP_WND just describes
this behaviour.


TCP_WND isn't a buffer, however I need to reserve a sufficiently sized 
memory pools (I'm using memory pools for pbufs with MEMP_MEM_MALLOC=0). 
And memory pools are statically allocated memory, so I end up with 16kB 
allocated buffer for mbedTLS and 16kB memory pools for storing at least 
TCP_WND bytes.


In core/init.c there's an error:

#if !MEMP_MEM_MALLOC && PBUF_POOL_SIZE && (TCP_WND > (PBUF_POOL_SIZE * 
(PBUF_POOL_BUFSIZE - (PBUF_LINK_ENCAPSULATION_HLEN + PBUF_LINK_HLEN + 
PBUF_IP_HLEN + PBUF_TRANSPORT_HLEN
#error "lwip_sanity_check: WARNING: TCP_WND is larger than space 
provided by PBUF_POOL_SIZE * (PBUF_POOL_BUFSIZE - protocol headers). If 
you know what you are doing, define LWIP_DISABLE_TCP_SANITY_CHECKS to 1 
to disable this error."

#endif

I understand pbuf pool should be sized at least TCP_WND that is 16kB... 
and pools are statically allocated. Am I wrong?



The only downside I see is that this way, all other non-TLS applications
get a bigger TCP_WND too. That's why we want to add code to control TCP_WND
at runtime per pcb.

Yes, this is another useful thing.

___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users


Re: [lwip-users] altcp_tls_mbedtls

2019-02-26 Thread Giuseppe Modugno

Il 25/02/2019 20:19, goldsi...@gmx.de ha scritto:

Am 22.02.2019 um 10:24 schrieb Giuseppe Modugno:

Il 22/02/2019 09:43, Simon Goldschmidt ha scritto:


[snip]


Is this warning correct? I think TCP_WND should be compared with
MBEDTLS_SSL_IN_CONTENT_LEN or MBEDTLS_SSL_OUT_CONTENT_LEN or the 
maximum

of them (of course, I hope to compare it with OUT buffer only, because
it is smaller).

I think you're right: this should compare to the IN buffer. No that it
would help you here... :-)


I'm not an expert here, so my question could be very stupid. TCP_WND is
the TCP window that is used to avoid continuous ack for small data. The
transmitter sends data filling the window and then waits for the ack.


TCP_WND is what we announce to the remote host to be able to buffer 
for RX.


For TX, what we buffer is the minimum of what the remote host tells us 
to be able to buffer and the memory we have/allow (both available heap 
memory and the limitation defines SND_BUF and SND_QUEUE_LEN).


Ok, but I couldn't understand the relation between lwip receiving window 
and TLS incoming buffer. If MBEDTLS_SSL_IN_CONTENT_LEN is 16kB, should I 
need a TCP_WND at least 16kB, for a total of 32kB of memory only to 
handle incoming TLS traffic?


Suppose I have a TCP_WND of only 2kB and incoming TLS buffer of 16kB. 
The TLS transmitter could send maximum 2kB of data that are buffered in 
the lwip receiving window. lwip calls altcp_recv(), so 
altcp_mbedtls_lower_recv() with received data (2kB maybe segmented in 
small pbufs and pbuf chains).


I can't follow the code, but I expect those data are immediately passed 
to mbedTLS library that should copy those data to its 16kB incoming 
buffer, freeing receiving window. I think the lwip TCP receiving window 
could be smaller than mbedTLS incoming data buffer.




___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users


Re: [lwip-users] Again confused about tcp_recved() and pbuf_free()

2019-02-26 Thread Giuseppe Modugno

Il 25/02/2019 20:23, goldsi...@gmx.de ha scritto:

Am 23.02.2019 um 10:20 schrieb Giuseppe Modugno:
I know, this is a hot topic and many times this was explaied in the 
list and in doc/rawapi.txt, however now I'm in trouble understanding 
this.


tcp_recved() is related to the TCP window size of the receiver: "The 
purpose is to advertise a larger window when the data has been 
processed.". Isn't the TCP window size fixed to TCP_WND macro? Does 
it mean that the window size increases every time tcp_recved() is 
called from the application? I don't think, otherwise the window size 
increases continuously during a connection.


The window has a more or less fixed total size. But it changes with 
each segment sent: for every byte sent (and ACKed), it decrease. The 
receiver is responsible to "reopen" the window by sending an 
appropriate window size with its ACK segments. lwIP does this for you, 
but you have to tell it when you are ready to accept more data. This 
is what 'tcp_recved()' does.


What are the situations when it should be better to not call 
tcp_recved() in recv() callback()? Here the application has the 
received data, can process and free the pbufs or can avoid freeing 
the pbufs to wait for additional data. In both cases I think the 
application should call tcp_recved().


If you need to process the received data further at slower speed, it's 
better to not call tcp_recved() right away. For example if you're 
programming into slow flash, calling tcp_recved after the bytes are 
programmed ensures the client does not send faster than you can program.


In this case you don't free the pbuf, because data is being written to 
the Flash. So it seems to me that when you free the pbuf (you have 
processed the incoming data), you can call tcp_recved(). If you don't 
free the pbuf, you haven't processed the data yet, so you don't call 
tcp_recved().


I don't understand when the two things can be different.


___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users


[lwip-users] Again confused about tcp_recved() and pbuf_free()

2019-02-23 Thread Giuseppe Modugno
I know, this is a hot topic and many times this was explaied in the list
and in doc/rawapi.txt, however now I'm in trouble understanding this.

tcp_recved() is related to the TCP window size of the receiver: "The
purpose is to advertise a larger window when the data has been processed.".
Isn't the TCP window size fixed to TCP_WND macro? Does it mean that the
window size increases every time tcp_recved() is called from the
application? I don't think, otherwise the window size increases
continuously during a connection.

What are the situations when it should be better to not call tcp_recved()
in recv() callback()? Here the application has the received data, can
process and free the pbufs or can avoid freeing the pbufs to wait for
additional data. In both cases I think the application should call
tcp_recved().
___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users

Re: [lwip-users] altcp_tls_mbedtls

2019-02-22 Thread Giuseppe Modugno

Il 22/02/2019 09:54, Andy Pont ha scritto:

Giuseppe wrote...

I'm trying to integrate lwip and mbedTLS on a project running on 
LPC1769 MCU from NXP. This MCU features 64kB SRAM in two separate 
banks of 32kB.
I don’t have any particular experience of the lwIP + mbedTLS 
combination that you are using and how to tune it but I have recently 
been working on a similar sounding project using the LPC1768.


Didn't you use mbedTLS for your project?



The way that the memory ended up being partitioned was:

16K @ 0x2007C000 (AHBSRAM0) - Ethernet send and receive buffers / 
descriptors

16K @ 0x2008 (AHBSRAM1) - Dedicated memory used for SSL
32K @ 0x1000 (RAM) - System memory for remaining application

We had to be careful in the memory management to make sure that when 
memory was requested dynamically it was allocated from the right pool.
16kB for SSL? I understood this is too small. SSL requires at least 16kB 
for *only* input buffer. But you need output buffer too.


___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users

Re: [lwip-users] altcp_tls_mbedtls

2019-02-22 Thread Giuseppe Modugno

Il 22/02/2019 09:43, Simon Goldschmidt ha scritto:

Giuseppe Modugno wrote:

I'm trying to integrate lwip and mbedTLS on a project running on LPC1769
MCU from NXP. This MCU features 64kB SRAM in two separate banks of 32kB.

If it works at all, it will certainly get *very* hard. Aside from the
input buffer, we saw really many small allocations (especially at
connection startup time) that summed up to some amount. I can't remember
exactly how the numbers were, but we're running it with more than 64 kB.


Unfortunately we already have a board with LPC1769 and we'd like to add 
TLS support to it.



But then again, we need to support more than 1 connection to do being a
https server...


In my case, the device is a client so it needs to create a single 
persistent connection to a MQTTs server.




As you can understand, I'm fighting putting all together with so small

SRAM. I'm not sure mbedTLS+lwip could really work in 64kB. I'm
interested in creating only one TLS connection with a MQTT server
(Amazon IoT or similar service). I'd like to know some experience about
a similar application in similar hw platform.

The first thing I made to reduce RAM requirements was decreasing
MBEDTLS_SSL_OUT_CONTENT_LEN from 16384 to 2048 (I understood output
buffer is under my control, so I can reduce it without letting informed
the server about this, differently from IN_CONTENT_LEN that must be at
least 16384).

My mbedTLS config.h:

#define MBEDTLS_SSL_IN_CONTENT_LEN  16384
#define MBEDTLS_SSL_OUT_CONTENT_LEN 2048
//#define MBEDTLS_SSL_MAX_CONTENT_LEN

In mbedtls/ssl.h appears:

#if !defined(MBEDTLS_SSL_MAX_CONTENT_LEN)
#define MBEDTLS_SSL_MAX_CONTENT_LEN 16384   /**< Size of the
input / output buffer */
#endif

So MBEDTLS_SSL_MAX_CONTENT_LEN is defined as 16384. Anyway it seems this
symbol is never used in mbedTLS code (it is useful only to define IN and
OUT content len when they aren't defined).

In altcp_tls_create_config() appears:

    if (TCP_WND < MBEDTLS_SSL_MAX_CONTENT_LEN) {
      LWIP_DEBUGF(ALTCP_MBEDTLS_DEBUG|LWIP_DBG_LEVEL_SERIOUS,
    ("altcp_tls: TCP_WND is smaller than the RX decryption buffer,
connection RX might stall!\n"));
    }

Is this warning correct? I think TCP_WND should be compared with
MBEDTLS_SSL_IN_CONTENT_LEN or MBEDTLS_SSL_OUT_CONTENT_LEN or the maximum
of them (of course, I hope to compare it with OUT buffer only, because
it is smaller).

I think you're right: this should compare to the IN buffer. No that it
would help you here... :-)


I'm not an expert here, so my question could be very stupid. TCP_WND is 
the TCP window that is used to avoid continuous ack for small data. The 
transmitter sends data filling the window and then waits for the ack.


So the *transmitter* should have a capable buffer of at least TCP_WND 
per connection. So I imagine the TCP_WND should be compared with the 
*output* buffer (in my case 2kB). Why do you say TCP_WND should be 
compared with *input* buffer? Is it related to the possibility that TCP 
segments could arrive in a different order (in the worst case the 
receiver could receive the last segment as the first segment in the 
window)? However doesn't TCP allow the receiver to communicate the 
receiver window to the transmitter? How the receiveing TCP window size 
related to the TLS input buffer?



Another question, more TLS related. I know some servers don't implement

MFL (Maximum Fragment Length) extension in order to reduce input buffer
size too. Do you know of some way to understand if the server really
implement this extension? I'm interested in IoT services from Amazon,
Google, Microsoft or similar. It seems they don't explicit this feature,
so I have to check in other ways.

I don't think I can help you here.

Regards,
Simon

___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users


___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users

[lwip-users] altcp_tls_mbedtls

2019-02-22 Thread Giuseppe Modugno
I'm trying to integrate lwip and mbedTLS on a project running on LPC1769 
MCU from NXP. This MCU features 64kB SRAM in two separate banks of 32kB.


As you can understand, I'm fighting putting all together with so small 
SRAM. I'm not sure mbedTLS+lwip could really work in 64kB. I'm 
interested in creating only one TLS connection with a MQTT server 
(Amazon IoT or similar service). I'd like to know some experience about 
a similar application in similar hw platform.


The first thing I made to reduce RAM requirements was decreasing 
MBEDTLS_SSL_OUT_CONTENT_LEN from 16384 to 2048 (I understood output 
buffer is under my control, so I can reduce it without letting informed 
the server about this, differently from IN_CONTENT_LEN that must be at 
least 16384).


My mbedTLS config.h:

#define MBEDTLS_SSL_IN_CONTENT_LEN  16384
#define MBEDTLS_SSL_OUT_CONTENT_LEN 2048
//#define MBEDTLS_SSL_MAX_CONTENT_LEN

In mbedtls/ssl.h appears:

#if !defined(MBEDTLS_SSL_MAX_CONTENT_LEN)
#define MBEDTLS_SSL_MAX_CONTENT_LEN 16384   /**< Size of the 
input / output buffer */

#endif

So MBEDTLS_SSL_MAX_CONTENT_LEN is defined as 16384. Anyway it seems this 
symbol is never used in mbedTLS code (it is useful only to define IN and 
OUT content len when they aren't defined).


In altcp_tls_create_config() appears:

  if (TCP_WND < MBEDTLS_SSL_MAX_CONTENT_LEN) {
    LWIP_DEBUGF(ALTCP_MBEDTLS_DEBUG|LWIP_DBG_LEVEL_SERIOUS,
  ("altcp_tls: TCP_WND is smaller than the RX decryption buffer, 
connection RX might stall!\n"));

  }

Is this warning correct? I think TCP_WND should be compared with 
MBEDTLS_SSL_IN_CONTENT_LEN or MBEDTLS_SSL_OUT_CONTENT_LEN or the maximum 
of them (of course, I hope to compare it with OUT buffer only, because 
it is smaller).



Another question, more TLS related. I know some servers don't implement 
MFL (Maximum Fragment Length) extension in order to reduce input buffer 
size too. Do you know of some way to understand if the server really 
implement this extension? I'm interested in IoT services from Amazon, 
Google, Microsoft or similar. It seems they don't explicit this feature, 
so I have to check in other ways.





___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users


[lwip-users] lwip version for mbedTLS integration

2019-02-19 Thread Giuseppe Modugno
I'm going to add mbedTLS to my lwip project. I noticed many recent 
commits with changes regaring mbedTLS integration.


Do you suggest to use lwip STABLE_2_1_2_RELEASE commit, last commit in 
STABLE_2_1_x branch, or last commit in master branch?



___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users


[lwip-users] http_client.c: add custom header at run-time

2019-02-19 Thread Giuseppe Modugno
I'm trying to implement a dynamic DNS client with lwip. The update 
protocol[1] is very simple: it's HTTP based, so I thought to use 
http_client.c that comes with lwip project.


Unfortunately this protocol needs the header "Authorization" in the 
request. It seems http_client.c doesn't support additional headers from 
"User-Agent" (customizable through macro), "Accept: */*", "Host" 
(generated at run-time) and "Connection: Close".


What do you suggest to add the "Authorization" header in the request? 
Note that this header isn't static, because it depends on username and 
password (it must be calculated at run-time).


In my application I will use http_client.c for other connections where 
"Authorization" header shouldn't be present. So this header should be 
added or not at run-time for each connection.


[1] https://www.noip.com/integrate/request


___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users


Re: [lwip-users] Custom placement of memory pool

2018-11-09 Thread Giuseppe Modugno

Il 09/11/2018 04:05, uaz ha scritto:

Hi all,

I'm currently running lwip v2.0.3 on LPC4357 platform.
I have some issue with pbuf mem_alloc(), which I believe is fragmentation
issue because after several packet transfers, I'm unable to allocate pbuf
anymore.


I don't know if it is the same problem I faced some months ago with the 
MCU LPC1769.


I found a behaviour similar to the one you are describing. After some 
HTTP requests (received and answered correctly), no more HTTP requests 
are possible. Consider that the problem appeared only with HTTP requests 
that needed custom file (as internal lwip http server nomenclature).


The solution I found is defining MEMP_MEM_MALLOC to *0/zero* (it was set 
to 1/one). When set, this macro enables mem_malloc/mem_free for pools 
management (so dynamic management instead of static management). In my 
case, mem_malloc/mem_free are effectively malloc/free of newlib C 
standard library (because I defined MEM_LIBC_MALLOC to 1).


Here[1] you read the definition of MEMP_MEM_MALLOC macro:

MEMP_MEM_MALLOC==1: Use mem_malloc/mem_free instead of the lwip pool 
allocator. Especially useful with MEM_LIBC_MALLOC but handle with care 
regarding execution speed (heap alloc can be much slower than pool 
alloc) and usage from interrupts (especially if your netif driver 
allocates PBUF_POOL pbufs for received frames from interrupt)! 
ATTENTION: Currently, this uses the heap for ALL pools (also for 
private pools, not only for internal pools defined inmemp_std.h 
)!
I think the NXP Ethernet driver implementation isn't compatible with 
MEMP_MEM_MALLOC. Anyway I'm not sure, because the problem happens only 
for "custom file" http requests and not for every request.


[1] 
http://www.nongnu.org/lwip/2_0_x/group__lwip__opts__mem.html#gae93af697d27bbcefa6a28052d90f2f38




Right now I'm switching to custom memory pool approach, but I'm consuming
more SRAM than available, thus the project is not compiling.

Is there any way to manually place memory pool to a certain address?

Thanks,
UAZ



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

___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users


___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users


[lwip-users] [OT]Sending push notifications from lwip electronic device to mobile devices

2018-11-08 Thread Giuseppe Modugno
It isn't strictly related to lwip. I'm sorry for that, but I couldn't 
find useful info out there.


I have an embedded device running lwip and an Ethernet interface. The 
device is connected to Internet. I need to send push notifications to a 
group of mobile devices associated with that embedded device.

Device1 sends push notifications to mobile devices A, B and C.
Device2 sends push notifications to mobile devices D, E and F.
...and so on

I can use Google Firebase Cloud Messaging[1] (FCM) service, that it 
seems completely free. For what I've seen, the embedded device can sends 
a notification by implementing an "app server"[2] (using FCM naming 
scheme). This app server will be able to send push notifications (to one 
device or to a group of devices) by contacting FCM server through three 
protocols: FCM HTTP v1 API, Legacy HTTP protocol and Legacy XMPP protocol.


I have tried to understand Legacy HTTP protocol[3].
First of all I couldn't understand if I can use normal HTTP, instead of 
the more complex HTTPs.
The second question is how to manage server key. The device 
authenticates itself to FCM server by a "server key", specified in HTTP 
headers. One or more server keys can be added in the Firebase Console 
page of the Project.
I think I can't have a different server key for each device, it will be 
unmanageable. Every time I deliver a device, a new associated server key 
should be added. If I have 1000 devices, I will have 1000 server keys. I 
don't think it works this way.
Most probably I have a single server key for all devices. However, in 
this case there's a problem with security. If the HTTP traffic is 
sniffed from my device, the server key is readable and usable by others. 
And all my devices, that share the same server key, will be broken in a 
time.


Maybe the solution to this problem is HTTPS that hides the data in the 
traffic.



[1] https://firebase.google.com/products/cloud-messaging/
[2] https://firebase.google.com/docs/cloud-messaging/server
[3] https://firebase.google.com/docs/cloud-messaging/http-server-ref


___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users


Re: [lwip-users] Decode HTTP URI

2018-05-24 Thread Giuseppe Modugno

Il 22/05/2018 22:12, goldsi...@gmx.de ha scritto:

On 22.05.2018 11:11, Giuseppe Modugno wrote:

I'm not sure. Is there a decoding function for URI?

I mean, a function that converts %20 and similar escape codes in the
corresponding ASCII char.


Our httpd does not (yet?) support this. If you really need spaces in 
URLs on your server, you need to save the files with encoded names. I 
could prevent this up to now, which is why I haven't implemented it ;-)


The URI encode comes in query strings too, not only URI (file) names.

I'm using a CGI script that accepts a query strings where some values 
are strings with "critical" characters (for example '/', because I'm 
sending one URL in the query string).


Anyway the url_decode() function is very simple. My original question 
was if this function already is in the lwip code already.


___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users


[lwip-users] Decode HTTP URI

2018-05-22 Thread Giuseppe Modugno

I'm not sure. Is there a decoding function for URI?

I mean, a function that converts %20 and similar escape codes in the 
corresponding ASCII char.


___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users


Re: [lwip-users] Download a file for firmware upgrade

2018-05-21 Thread Giuseppe Modugno

Il 21/05/2018 14:26, Sergio R. Caprile ha scritto:

You can do whatever you want.
The question is probably not what can you do but what do you have
available to obtain what you need with lesser effort.
There are FTP clients around, I've collaborated in one of them using the
RAW API, search the list.
FTP is sometimes tricky and can give you some headaches with firewalls
(and/or admins).
For HTTP you need a client. I wouldn't just GET and hope everything is
fine unless I can manage both ends (that means: the server too) and
guarantee there won't be other stuff than my file. 


I couldn't understand your concerns about a minimalistic HTTP client 
that opens that TCP connection, sends the GET request and wait for the 
response (as Ajay suggested).


> A HTTP client can be quite complicated, but you just need to get one
> resource at a specific URI

I know a full HTTP client is a very complex piece of code, but I only 
need to download a specific URI.




You can even have a proprietary protocol running over TCP or UDP. If
your device will be sold and installed on corporate networks, you might
raise some concern among the net admins, asking to have open holes in
the firewall does not seem to be a good way to make friends.


I know, but I'd prefer to avoid this approach.



My bet is to go for the user to upload the file, leveraging your web
server; 


This is a good suggestion.  However the original question arises again: 
how to upload a file to the Web server?  Should I use Javascript/jQuery 
to choose and send a local file to httpd through POST method (that I'm 
not actually using)?




but if you must go out and get it, then perhaps FTP is the
easiest full client and HTTP is the simplest firewall piercing. 


I think a minimalistic HTTP GET request should be enough.



I don't
know if there are running clients around. Particularly for your API,
which you don't say. (I'm intentionally not considering TFTP for going
out because of the possible firewall issue, but if it is your network,
there is a client already available)


No, the firmware binary file will be on the public Internet and the 
device will be behind a NAT router... usually.


___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users


[lwip-users] Download a file for firmware upgrade

2018-05-21 Thread Giuseppe Modugno
I have a device running lwip stack and httpd server. The device has an 
external 2MB SPI Flash memory. The CPU is a microcontroller with 512kB 
internal Flash.


I'd like to upgrade the firmware (the internal Flash memory) by download 
the new binary from Internet. The user can check the presence of a new 
firmware version through the web pages answered from httpd.


When the user activates the remote upgrade, the device should download 
the binary file from a server and save it to the external Flash memory. 
After a reboot, the bootloader detects the new firmware on the external 
memory and copy it to the internal Flash memory.


Now I don't know how to download a file from Internet. FTP client? HTTP 
client? Any other protocol? I'd like to use a standard server (FTP, 
HTTP, ...), anyway this isn't a must.


Please, give me a suggestion. Thank you.



___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users


Re: [lwip-users] Tunnel solution for HTTP server expose to Internet

2018-04-09 Thread Giuseppe Modugno

Il 09/04/2018 15:00, Sergio R. Caprile ha scritto:

My personal opinion follows:

Do you absolutely need HTTP ?
As long as we don't have IPv6 (and fixed addresses), we have to go DDNS
and port forwarding. Yes, this requires an end user holding a PhD or at
least the techie ones. So... the whole purpose of "the cloud" probably
started with this,

Yes, I agree with you.


and so many developers resort to publishing on some
publisher/subscriber architecture and either provide a web frontend
based on a subscriber backend or a subscriber based smartphone
application (or computer program). Enter MQTT, available in your lwIP repo.
Do you absolutely need HTTP ?
No, I don't need absolutely HTTP, but HTTP allows the end user to use a 
standard Web browser (and allow me to avoid writing an app for Android, 
iOS, ...).



An ellaborated explanation is a bit off-topic (and extense).
You can do this with a hosted server and database for one or a few
devices. You should also consider Heroku. For lots of devices, a cloud
service like Amazon AWS, Google Cloud, that bunch of money makers based
on Seattle, or even Adafruit is probably a better idea.
First of all, many of these services aren't free. And I admit my 
ignorance around those topics. For example, is it possible to avoid 
writing an app for smartphone? I don't know.


Moreover, are the status of all my devices stored somewhere in the 
cloud? In this case, I should think of privacy, security, attacks from 
hackers... it's another job.



For remote control, however, the MQTT way is a bit more involved, so for
a verbose interface you would probably want to run a more friendly
protocol on top of that.

Everything depends on what you need to do and how you want to interact
with your devices.

Thank you for your suggestions... I'll study a little more on MQTT and 
related scenarios


___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users


[lwip-users] Tunnel solution for HTTP server expose to Internet

2018-04-06 Thread Giuseppe Modugno
My embedded device, running lwip httpd server, is under a router with a 
dynamic public IP address and a local private network 192.168.1.x. I 
know how to configure DDNS and NAT on the router to reach the server 
from outside, but these are tedious and tricky steps for most users.


So I'm searching more "plug" solutions that would allow the end 
user to connect to my embedded device. I found yaler, pakekite and some 
others. They should work, but all solutions need the installation of a 
piece of software in the embedded HTTP server, in my case lwip-based.


Do you have any experiences on implementing this protocols on lwip to 
expose httpd to Internet? Could you suggest any other better solutions?




___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users


Re: [lwip-users] MEM_SIZE

2018-03-15 Thread Giuseppe Modugno

Il 15/03/2018 11:28, Simon Goldschmidt ha scritto:

Giuseppe Modugno wrote:

[..]
I think with the following options:

#define MEM_LIBC_MALLOC  0
#define MEM_USE_POOLS  1
#define MEM_USE_CUSTOM_POOLS 1  /* Needed by MEM_USE_POOLS */

It's MEMP_USE_CUSTOM_POOLS, not MEM_USE_CUSTOM_POOLS.


It was a typo.


And it compiles for me, see the win32 port for an example.


Yes, now it compiles without errors. The file lwippools.h lacked the 
LWIP_MALLOC_MEMPOOL macros to define the set of pools used by lwip in 
case MEM_USE_POOLS is set.



___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users

Re: [lwip-users] Problems when setting MEMP_MEM_MALLOC

2018-03-15 Thread Giuseppe Modugno

Il 14/03/2018 21:24, Nathan Hartman ha scritto:

On Mar 14, 2018, at 3:24 PM, "goldsi...@gmx.de" <goldsi...@gmx.de> wrote:

On 14.03.2018 17:09, Giuseppe Modugno wrote:
#define MEM_LIBC_MALLOC   1

If I try to set MEMP_MEM_MALLOC, I have some strange problems.

I suspect threading issues. I checked on win32 and it seems to work fine. In 
the end, there's not really much lwIP does here, everything is delegated to 
your C library's malloc code. Maybe that code isn't thread-safe? In that case, 
you need to define mem_clib_*() to wrapper functions that protect the heap.

Just a guess: it sounds like your linker script may be placing the heap in the 
wrong place, not allocating one at all, and/or it may not be where your C 
library expects it to be.

It is very important to give your application enough stack and enough heap, and 
to make sure they do not clobber each other as they grow.


I'm starting thinking about an issue similar to "out of memory". Every 
time the custom file is opened, a mem_malloc(1024) is called and every 
time the pointer returned is increased. I'm sure the allocated space is 
freed in fs_close_custom. Maybe it's a problem with fragmentation... I 
have to make additional tests.



___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users


Re: [lwip-users] Problems when setting MEMP_MEM_MALLOC

2018-03-15 Thread Giuseppe Modugno

Il 14/03/2018 20:24, goldsi...@gmx.de ha scritto:

On 14.03.2018 17:09, Giuseppe Modugno wrote:

#define MEM_LIBC_MALLOC   1

If I try to set MEMP_MEM_MALLOC, I have some strange problems.


I suspect threading issues. I checked on win32 and it seems to work 
fine. In the end, there's not really much lwIP does here, everything 
is delegated to your C library's malloc code. Maybe that code isn't 
thread-safe? In that case, you need to define mem_clib_*() to wrapper 
functions that protect the heap.


I'm using NewlibNano as C library. However I'm using NOSYS=1 and I don't 
use threads. In my application, "threads" are only interrupt service 
routines, but I don't call mem_malloc from any ISR (I don't think lwip 
uses interrupts at all).


So I don't think it is caused by a threading issue.


___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users


Re: [lwip-users] MEM_SIZE

2018-03-15 Thread Giuseppe Modugno

Il 14/03/2018 16:42, Giuseppe Modugno ha scritto:

I was experimenting with lwip memory allocator. I defined:

#define MEM_LIBC_MALLOC  0
#define MEM_USE_POOLS  0
#define MEM_SIZE  (32 * 1024)
#define LWIP_RAM_HEAP_POINTER  ( (void *)0x2007C000 )

I'm using LPC1768 that has a 32kB SRAM block starting from address 
0x2007C000. However I have a Hard Fault error during mem_init(), 
because ram_end is initialized to 0x2007C000 + (32*1024), that is over 
the available memory.


So MEM_SIZE should be smaller than available heap memory.


Another question regarding memory management of lwip.

I understood lwip uses memory pools for many things (TCP pcbs, UDP pcbs, 
RAW pcb, timers and so on). The memory pools are defined in 
include/lwip/priv/memp_std.h.
They aren't allocated from the heap, but from pools. I think because it 
is supposed they must be allocated frequently, so they could bring to 
fragmentation and the allocation should be fast.


Does lwip use strictly heap (mem_malloc) for its own purposes? It seems 
yes (I see some mem_malloc calls in httpd, dhcp, pbuf, ...).

Is it possible to compile lwip so it doesn't use heap at all?

I think with the following options:

#define MEM_LIBC_MALLOC  0
#define MEM_USE_POOLS  1
#define MEM_USE_CUSTOM_POOLS 1  /* Needed by MEM_USE_POOLS */

In this way, heap implementation isn't a real heap, but a set of 
different-sized pools. This set is defined in arhc/lwippools.h. Is it 
correct?


I tried to compile with this options, but I have this error (for example 
compiling memp.c):


mingw32-gcc.exe -Wall -std=c11 -Wall -pedantic -Wparentheses 
-Wsequence-point -Wextra -Wundef -Wshadow -Wpointer-arith -Wcast-qual 
-Wwrite-strings -Wold-style-definition -Wcast-align -Wmissing-prototypes 
-Wredundant-decls -Wnested-externs -Wno-address -Wunreachable-code 
-Wuninitialized -Wlogical-op -Wno-format -g -DLWIP_DEBUG -DDEBUG 
-Isrc\lwip\src\include -Isrc -Isrc\ports\mingw\lwip_arch 
-Isrc\ports\mingw -Isrc\bus -Isrc\WpdPack\Include -I..\..\..\work_git 
-Isrc\lwip\src\include\lwip\apps -c 
C:\Users\Giuseppe\Documents\work_git\webserver\webserver\src\lwip\src\core\memp.c 
-o mingw\Debug\src\lwip\src\core\memp.o

In file included from src\lwip\src\include/lwip/memp.h:58:0,
 from 
C:\Users\Giuseppe\Documents\work_git\webserver\webserver\src\lwip\src\core\memp.c:48:
src\lwip\src\include/lwip/priv/memp_priv.h:89:5: error: expected 
expression before ')' token

 ) ,
 ^


___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users


Re: [lwip-users] MEM_SIZE

2018-03-15 Thread Giuseppe Modugno

Il 14/03/2018 20:26, goldsi...@gmx.de ha scritto:

On 14.03.2018 16:42, Giuseppe Modugno wrote:

I was experimenting with lwip memory allocator. I defined:

#define MEM_LIBC_MALLOC  0
#define MEM_USE_POOLS  0
#define MEM_SIZE  (32 * 1024)
#define LWIP_RAM_HEAP_POINTER  ( (void *)0x2007C000 )

I'm using LPC1768 that has a 32kB SRAM block starting from address
0x2007C000. However I have a Hard Fault error during mem_init(), because
ram_end is initialized to 0x2007C000 + (32*1024), that is over the
available memory.

So MEM_SIZE should be smaller than available heap memory.


Is that a question? Or an action request? 

It was a question, even if I forgot to add a question mark :-)

To my understanding, the comment above #ifndef LWIP_RAM_HEAP_POINTER 
in mem.c clearly states that enough memory is required. It does NOT 
say that amount is MEM_SIZE. If you want, create a patch with a better 
documentation and we could apply it.
Ah ok, I now understand the comment "we need one struct mem at the end 
and some room for alignment".


MEM_SIZE isn't the total available memory for heap management (including 
accessory structs), but it is the *useful* memory space the application 
needs for the heap (excluding accessory structs). For example, if 
MEM_SIZE is 1024, I can be sure one malloc(1024) won't fail.


In my case, I have a completely free (not used by the linker) 32kB RAM 
region starting from 0x2007C000. To instruct lwip to use that region for 
heap, I think I have to define:


#define MEM_SIZE  (32 * 1024 - 1 * SIZEOF_STRUCT_MEM)
#define LWIP_RAM_HEAP_POINTER ( (void *)0x2007C000 )

Supposing we don't need other additional space for alignment.
In this case the total free heap memory available for data is exactly 
MEM_SIZE, that is less than 32kB.


Is it correct?

___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users


[lwip-users] Problems when setting MEMP_MEM_MALLOC

2018-03-14 Thread Giuseppe Modugno

#define MEM_LIBC_MALLOC   1

If I try to set MEMP_MEM_MALLOC, I have some strange problems.

After many HTTP GET requests, the HTTP server stops answering. It seems 
the Ethernet MAC driver (from NXP, I'm using LPC1768) isn't able to 
receive Ethernet frames and ethernet_input() isn't called anymore. I 
couldn't understand why.


The problem happens only if the GET requests are directed to a custom 
"dynamic" file. In fs_open_custom() I call mem_malloc() and in 
fs_close_custom() I call mem_free(). If the requests are directed to a 
"static" file of the filesystem, the problem doesn't appear.


I understood MEMP_MEM_MALLOC enables a malloc/free implementation of 
memory pools. Apparently, this macro isn't related to my custom file 
implementation that uses mem_malloc() and mem_free() and not pools. So 
the problem appears complex to explain.


In fs_open_custom() I call mem_malloc(1200). I don't think 1200 is a 
problem here.


If MEMP_MEM_MALLOC is set to zero, this problem doesn't happen.

Could you suggest something to address to the problem?



___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users


[lwip-users] MEM_SIZE

2018-03-14 Thread Giuseppe Modugno

I was experimenting with lwip memory allocator. I defined:

#define MEM_LIBC_MALLOC  0
#define MEM_USE_POOLS  0
#define MEM_SIZE  (32 * 1024)
#define LWIP_RAM_HEAP_POINTER  ( (void *)0x2007C000 )

I'm using LPC1768 that has a 32kB SRAM block starting from address 
0x2007C000. However I have a Hard Fault error during mem_init(), because 
ram_end is initialized to 0x2007C000 + (32*1024), that is over the 
available memory.


So MEM_SIZE should be smaller than available heap memory.



___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users


[lwip-users] Set IP address as none

2018-03-13 Thread Giuseppe Modugno
I have ip4_addr_t and I want to set it to a "null"/invalid value. Is it 
better to use IPADDR_NONE or IPADDR_ANY?


At first, I thought IPADDR_NONE was the best choice, but I found that 
dns.c uses IPADDR_ANY to flag a DNS server as invalid.


Moreover, there are ip4_addr_isany() and ip4_addr_set_any() macros, 
while there aren't ip4_addr_isnone() and ip4_addr_set_none().






___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users


Re: [lwip-users] Dealloc in fs_close_custom()?

2018-02-28 Thread Giuseppe Modugno

Il 27/02/2018 08:54, Giuseppe Modugno ha scritto:

Il 27/02/2018 06:36, Simon Goldschmidt ha scritto:

Giuseppe Modugno wrote:
And another thing I couldn't explain. The example uses pextension 
pointer for malloc/free. However it sets file->data = 
file->pextension immediately.
  So why don't use just file->data? It seems pextension is never 
used in lwip code.
Exactly. This is an example that wants to show you can use pextension 
for anything you like

as it is not used by lwIP code internally.

Using ->data only works for files in one piece.
Maybe I'm wrong, but here pextension and state void pointers are very, 
very similar. Maybe it's possible to reduce the complexity leaving 
only one member.


Considering the new prototype of httpd_cgi_handler(), this is more 
evident. Now we have struct fs_file pointer in CGI handler, so we can 
access ->pextension (that could be setup during fs_custom_open()). So 
the complexity of LWIP_HTTPD_FILE_STATE is IMHO completely useless.


int fs_open_custom(struct fs_file *file, const char *filename) {
  if (!strcmp(filename, "/custom.html")) {
    struct mystate_s *file_state = mem_malloc(sizeof(struct mystate_s));
    /* Init file_state members */
    file->pextension = file_state;
  }
}

void httpd_cgi_handler(struct fs_file *file, const char *uri, int 
iNumParams, char **pcParam, char **pcValue) {

  struct mystate_s *file_state = (struct mystate_s *)file->pextension;
  /* Access file_state members */
}

void fs_close_custom(struct fs_file *file) {
  if (file && file->pextension) mem_free(file->pextension);
  if (file) mem_free(file);
}





___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users

Re: [lwip-users] MEMP_MEM_MALLOC

2018-02-27 Thread Giuseppe Modugno

Il 27/02/2018 13:08, Giuseppe Modugno ha scritto:


I'm thinking if it's better to set MEMP_MEM_MALLOC or not in my 
application. I'm working with MEMP_MEM_MALLOC=1 (I started from an 
example) and it works. However I'm not sure it's the best choice for me.


So what are the arguments for and against MEMP_MEM_MALLOC?

This is what I have understood:

  * lwip *always* uses pools for some dynamic data (for example UDP
PCBs and timeouts);
  * pools have a *fixed* number for maximum allocated elements (for
example, MEMP_NUM_SYS_TIMEOUT for timeouts);
  * (MEMP_MEM_MALLOC=0): all the elements of the pools are statically
allocated (so they're not in the heap);

In my case, MEMP_MEM_MALLOC=0 needs 31000 bytes in RAM, while 
MEMP_MEM_MALLOC=1 needs only 13172 bytes.


___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users

[lwip-users] MEMP_MEM_MALLOC

2018-02-27 Thread Giuseppe Modugno
I'm thinking if it's better to set MEMP_MEM_MALLOC or not in my 
application. I'm working with MEMP_MEM_MALLOC=1 (I started from an 
example) and it works. However I'm not sure it's the best choice for me.


So what are the arguments for and against MEMP_MEM_MALLOC?

This is what I have understood:

 * lwip *always* uses pools for some dynamic data (for example UDP PCBs
   and timeouts);
 * pools have a *fixed* number for maximum allocated elements (for
   example, MEMP_NUM_SYS_TIMEOUT for timeouts);
 * (MEMP_MEM_MALLOC=0): all the elements of the pools are statically
   allocated (so they're not in the heap);
 * (MEMP_MEM_MALLOC=1): the elements of the pools aren't statically
   allocated, but they're (de)allocated at run-time with malloc/free,
   when needed;
 * allocation of an element is much more fast if MEMP_MEM_MALLOC=0
   (otherwise malloc/free are used);
 * MEMP_MEM_MALLOC=0 is a good choice if available malloc/free are poor
   (in my case, I'm using newlib on Cortex-M3... I don't really know if
   it's a good implementation or not).

What are your suggestions?


___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users

Re: [lwip-users] Dealloc in fs_close_custom()?

2018-02-27 Thread Giuseppe Modugno

Il 27/02/2018 06:39, Simon Goldschmidt ha scritto:

Giuseppe Modugno wrote:

#ifndef HTTP_IS_DATA_VOLATILE
#if LWIP_HTTPD_SSI
/* Copy for SSI files, no copy for non-SSI files */
#define HTTP_IS_DATA_VOLATILE(hs)   ((hs)->ssi ? TCP_WRITE_FLAG_COPY : 0)
#else /* LWIP_HTTPD_SSI */
/** Default: don't copy if the data is sent from file-system directly */
#define HTTP_IS_DATA_VOLATILE(hs) (((hs->file != NULL) && (hs->handle != NULL) && 
(hs->file == \
                                    (const char*)hs->handle->data + 
hs->handle->len - hs->left)) \
                                    ? 0 : TCP_WRITE_FLAG_COPY)
#endif /* LWIP_HTTPD_SSI */
#endif

You're looking at an "old" version of the file. git master has this since last 
may:
I was looking at the last stable release 2.0.3 that was released in Sep 
2017.



#ifndef HTTP_IS_DATA_VOLATILE
/** tcp_write does not have to copy data when sent from rom-file-system 
directly */
#define HTTP_IS_DATA_VOLATILE(hs)   (HTTP_IS_DYNAMIC_FILE(hs) ? 
TCP_WRITE_FLAG_COPY : 0)
#endif
IMHO data must be copied not only for "dynamic file", but also for some 
custom files.


For example, with this new definition, it seems to me that the example 
in genfiles_example.c is wrong. Indeed the "generated file" would be 
considered "not volatile" (because it isn't dynamic in httpd sense), so 
the content would not be copied during tcp_write(). The dynamic buffer 
freed in fs_close_custom(), when the content could be pending yet.


Maybe genfiles_example.c should be compiled with another definition of 
HTTP_IS_DATA_VOLATILE(). I suggest:


#define HTTP_IS_DATA_VOLATILE(hs)    ( (hs)->is_custom-file ? 
TCP_WRITE_FLAG_COPY : 0 )




___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users

Re: [lwip-users] Dealloc in fs_close_custom()?

2018-02-26 Thread Giuseppe Modugno

Il 27/02/2018 06:36, Simon Goldschmidt ha scritto:

Giuseppe Modugno wrote:

And another thing I couldn't explain. The example uses pextension pointer for 
malloc/free. However it sets file->data = file->pextension immediately.
  
So why don't use just file->data? It seems pextension is never used in lwip code.

Exactly. This is an example that wants to show you can use pextension for 
anything you like
as it is not used by lwIP code internally.

Using ->data only works for files in one piece.
Maybe I'm wrong, but here pextension and state void pointers are very, 
very similar. Maybe it's possible to reduce the complexity leaving only 
one member.


___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users


Re: [lwip-users] Dealloc in fs_close_custom()?

2018-02-26 Thread Giuseppe Modugno
2018-02-26 16:51 GMT+01:00 Giuseppe Modugno <
giuseppe.modugno.lo...@gmail.com>:

> I read the examples in lwip-contrib, mainly genfiles_example.c.


And another thing I couldn't explain. The example uses pextension pointer
for malloc/free. However it sets file->data = file->pextension immediately.

So why don't use just file->data? It seems pextension is never used in lwip
code.
___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users

Re: [lwip-users] Dealloc in fs_close_custom()?

2018-02-26 Thread Giuseppe Modugno
2018-02-26 19:45 GMT+01:00 goldsi...@gmx.de <goldsi...@gmx.de>:

> On 26.02.2018 16:51, Giuseppe Modugno wrote:
>
>> I read the examples in lwip-contrib, mainly genfiles_example.c. The
>> dynamic memory allocated for the file content is freed in
>> fs_close_custom(). However I couldn't explain why.
>>
>> Indeed, mostly if the content is small, it is completely sent in
>> http_recv()/http_send()/http_eof()/http_close_conn()/http_cl
>> ose_or_abort_conn()/http_state_free()/fs_close()/fs_close_custom().
>>
>> tcp_write() is called in http_write() without TCP_WRITE_FLAG_COPY, at
>> least it seems so to me.
>>
>
> That's not fully correct. The default behaviour is that data is copied for
> dynamic files (where buf != NULL). This should cover SSI files as well as
> custom files, but it could be that it doesn't cover your setup of custom
> files.
>
> You either can adjust the macro HTTP_IS_DATA_VOLATILE() in that case, or
> come up with a patch that would keep the file open until everything is
> ACKed.
>

#ifndef HTTP_IS_DATA_VOLATILE
#if LWIP_HTTPD_SSI
/* Copy for SSI files, no copy for non-SSI files */
#define HTTP_IS_DATA_VOLATILE(hs)   ((hs)->ssi ? TCP_WRITE_FLAG_COPY : 0)
#else /* LWIP_HTTPD_SSI */
/** Default: don't copy if the data is sent from file-system directly */
#define HTTP_IS_DATA_VOLATILE(hs) (((hs->file != NULL) && (hs->handle !=
NULL) && (hs->file == \
   (const char*)hs->handle->data +
hs->handle->len - hs->left)) \
   ? 0 : TCP_WRITE_FLAG_COPY)
#endif /* LWIP_HTTPD_SSI */
#endif

First of all, are the results of HTTP_IS_DATA_VOLATILE() reversed when
LWIP_HTTPD_SSI is reset? Indeed, when LWIP_HTTPD_SSI is defined, it returns
TCP_WRITE_FLAG_COPY if the test condition is true. It returns the same
value if the test condition is false, if LWIP_HTTPD_SSI is set. It seems
one definition or the other is wrong.

I can't fully understand the test condition of the macro, I will try to
understand what happens to hs->file pointer and hs->handle for normal files
and custom files.
___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users

[lwip-users] Dealloc in fs_close_custom()?

2018-02-26 Thread Giuseppe Modugno
I read the examples in lwip-contrib, mainly genfiles_example.c. The 
dynamic memory allocated for the file content is freed in 
fs_close_custom(). However I couldn't explain why.


Indeed, mostly if the content is small, it is completely sent in 
http_recv()/http_send()/http_eof()/http_close_conn()/http_close_or_abort_conn()/http_state_free()/fs_close()/fs_close_custom().


tcp_write() is called in http_write() without TCP_WRITE_FLAG_COPY, at 
least it seems so to me. If I understood well, this means the content 
isn't copied in another buffer, so it *will* be sent from the original 
*dynamic* buffer. When fs_close_custom() is called, the content is 
pushed in the output queue, but it isn't actually sent over the wire.


So is it correct to free the dynamic buffer in fs_close_custom()?




___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users


Re: [lwip-users] makefsdata producing compressed files

2018-02-26 Thread Giuseppe Modugno

Il 26/02/2018 12:57, Simon Goldschmidt ha scritto:

Giuseppe Modugno wrote:

I compiled makefsdata.c with miniz.c and enabled compression, that is
only deflate. It seems it works well here with my files (I tested with
Chrome).

However I have a doubt. Is deflate the right compression scheme to use?
I read something confusing about deflate, something related to early
Microsoft products (servers and clients) that aspects a wrong data
format for deflate. Indeed, it seems Apache supports only gzip
compression scheme.

You're right that (older?) ms browsers are bogus regarding deflate. However,
I thin I got this working by using a raw deflate stream without zlib header.
I can't remember which browser versions I tested with, though. But all I
tested were working.

Good.


However, I'll happily accept a patch using gzip, of course!

Maybe it's not an urgent feature of lwip, however I'll try to make a patch.


Another question. I have a .mp3 file in the filesystem. I have some 
problems with this file, because it seems it is requested two times from 
the browser. The second time the browser doesn't specificy 
Accept-encoding header, so I imagine it doesn't like a compressed .mp3 
file. It wants the uncompressed version (it's reasonable, because mp3 is 
already compressed).


Is there a msimple ethod to avoid makefsdata compressing certain non-SSI 
files, maybe based on extensions?



___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users


[lwip-users] makefsdata producing compressed files

2018-02-26 Thread Giuseppe Modugno
I compiled makefsdata.c with miniz.c and enabled compression, that is 
only deflate. It seems it works well here with my files (I tested with 
Chrome).


However I have a doubt. Is deflate the right compression scheme to use? 
I read something confusing about deflate, something related to early 
Microsoft products (servers and clients) that aspects a wrong data 
format for deflate. Indeed, it seems Apache supports only gzip 
compression scheme.


What do you think?



___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users


[lwip-users] UPnP support

2018-02-22 Thread Giuseppe Modugno
Does lwip supports UPnP protocol? I need to open port forwarding on the 
Internet Gateway Device in the LAN where lwip is connected.


I tried to search for this, but I found only old and confusing info.

If lwip doesn't support UPnP, does someone implemented it in its 
application code? I'm interested only in open one port forward (my 
application is a classical Web server listening on a custom port that 
should be accessible from the outside).




___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users


[lwip-users] [OT] Minimize .html, .js and .css files

2018-02-20 Thread Giuseppe Modugno

Another OT.

In order to reduce Flash space for the filesystem used by httpd, I'm 
thinking to reduce the size of .html, .css and .js files. This means 
removing comments, spaces (when not needed) and maybe changing variable 
names (from "my_long_variable" in "xtr").


Do you know of some tools that makes those things?


___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users


Re: [lwip-users] [OT] httpd: download static files from an external HTTP server

2018-02-20 Thread Giuseppe Modugno

Il 20/02/2018 08:51, goldsi...@gmx.de ha scritto:

On 20.02.2018 08:15, Giuseppe Modugno wrote:

I think this isn't strictly related to lwip, but it's a request typical
on electronic devices where lwip runs, i.e. devices with limited and
restricted resources.


It is somewhat related to lwIP as you have to know how to create 
dynamic content. That depends on the webserver.

Hmm..., I was talking about *static files* only.


[..]

Depending on this variable, the URI of some static files should be:

    /img/big_image.png

or

    external.webserver.org/img/big_image.png

Any suggestions?


Yes. If you use lwip's integrated httpd, that is.

You can use SSI to generate the different links. In the lwIP http 
server, SSI works everywhere in the page, even in a form or in a link 
element. You only have to set LWIP_HTTPD_SSI_INCLUDE_TAG to 0. If this 
is 1, the tag part of the html source file gets included in the 
resulting page and that might violate the html code.

Maybe my request wasn't clear.

I don't need to change this behaviour at runtime or depending on a 
variable in the MCU that runs lwip/httpd. I will decide this behaviour 
at *compile time*, so when generating the httpd filesystem. I'm 
searching for an *HTML only* technique that let me change the URIs from 
one type to the other by changing a single point in a single file.



___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users


[lwip-users] [OT] httpd: download static files from an external HTTP server

2018-02-19 Thread Giuseppe Modugno
I think this isn't strictly related to lwip, but it's a request typical 
on electronic devices where lwip runs, i.e. devices with limited and 
restricted resources.


I have a limited non-volatile memory where to save html (and css, and 
images, and javascript, ...) files. Considering that the user will be 
always online (connected to Internet), I'm thinking to store some big 
static files (mainly images) on an external webserver.


I know it is perfectly possibile, but I'm trying to find a flexible way 
to do this. I'd like to have a single point in my files (maybe in a .js 
file) where to change this behaviour:


  var use_external_server = false;        // or true

Depending on this variable, the URI of some static files should be:

  /img/big_image.png

or

  external.webserver.org/img/big_image.png

Any suggestions?



___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users


Re: [lwip-users] httpd: how to redirect to a new address

2018-02-19 Thread Giuseppe Modugno
Consider that the browser can't continue the communication with the 
server if you change the server IP address. So I implemented the IP 
address change of the web server in the following way.


The client requests a URI with a query string with the new IP 
configuration. httpd calls a CGI handler/callback that saves the new IP 
configuration on the non-volatile memory and reboot itself. The 
Javascript code running in the browser waits for some seconds (with a 
progress bar) after sending the new IP configuration, then redirect to 
the home page again, but using the new IP address.


In this way I avoided the change of IP address during runtime.

Il 19/02/2018 23:18, Jan Menzel ha scritto:

Hi all!
In our application we wont to allow the user to change the ip address
of the server using a webpage. I wonder what would be the best way of
doing that.
At present we use a very basic webserver that servers a different page
(with HTTP status code 301) if the parameters update the ip address.
After sending out the last byte we change the ip address, so the server
is immediately listening on the new address.
With lwip we can either use LWIP_HTTPD_CGI_SSI with a single parameter
handler but how to server different status codes? And, when is the
correct time of changing the ip address? Or we could use LWIP_HTTPD_CGI
which read kind of deprecated in the documentation.
Is there a recommended procedure how lwip can server is purpose?

Jan

___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users



___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users


[lwip-users] An external filesystem for httpd

2018-02-01 Thread Giuseppe Modugno
Until now, I was using the embedded fs generated by the tool makefsdata. 
Unfortunately the filesystem I'd like to create is bigger than the 
internal Flash memory of the MCU.


I'm thinking to use an external SPI Flash memory to save the filesystem. 
So I need another tool that creates an ouput binary (or Intel Hex) image 
file to save directly in the SPI Flash memory. I know I can write this 
tool completely myself, but I'm sure there are some good examples to 
look at.
Also I need some source code to access this filesystem over SPI (open 
file, read 100 bytes, and so on).


I think I can use the FAT filesystem, however I think it is over 
complicated respect what I need to do.


Actually httpd automatically search for files in fsdata data structure 
(that is a linked list). With an external file system, I think I have to 
consider every file as a custom file. I'm in doubt if it's better to 
read immediately the content from external Flash in 
fs_read_async_custom() (blocking until all data are ready), or start a 
background (non-blocking) process that reads from external SPI Flash and 
signals when it ends.


Any suggestions?


___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users


Re: [lwip-users] How to use LWIP_HTTPD_FS_ASYNC_READ

2017-11-28 Thread Giuseppe Modugno

Il 27/11/2017 20:38, goldsi...@gmx.de ha scritto:

Giuseppe Modugno wrote:
[..] Why the server should close the connection when the Content 
Length header is not send?


Because the client cannot reuse this connection to send more requests 
as it doesn't know when the server is finished.
HTTP is defined to either get the content length from the number of 
bytes received before the connection is closed or through some other 
encoding (like the content-length header, chunked encoding, etc.).
I think I got your point. You mean the same TCP connection can't be 
reused for *other* HTTP requests *after* the body is completely send 
(because the server has closed the connection). So the client is forced 
to reopen a new TCP connection.


Of course you are thinking keep-alive support is enabled. In my case, I 
was working without keep-alive support. After enabling keep-alive 
support, my "solution" works (the server must send Connection: Close 
when Content-Length isn't send), but there's the drawback of closing 
connection.



I tried and it seems it works well:


Do you really expect me to download this image? If it's a wireshark 
trace: PLEASE SEND A PCAP, NOT SOME SCREENSHOT!!



I'm sorry, I hoped an image would be much more "fast" to understand.


Again regarding asyncronous-read file, I think another small improvement 
can be made. get_http_headers() is called too early, when the file 
length couldn't be known. However it is known when http_send_headers() 
will be called, because fs_is_file_ready() will return true.


So my idea is to replace the content length value header 
(HDR_STRINGS_IDX_CONTENT_LEN_NR) with the correct value 
(hs->handle->len) during http_send_headers(). I made some tests and it 
seems it works.


___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users

Re: [lwip-users] No-IP Update Client implementation

2017-11-27 Thread Giuseppe Modugno

Il 27/11/2017 16:53, Giuseppe Modugno ha scritto:
Is there some example how to implement an Update Client for a Dynamic 
DNS service, such as No-IP?
It seems not too difficult to implement an Update Client for No-Ip: the 
update is a simple HTTP GET request to No-IP server.


In that case, I have to know my public IP address in order to detect the 
change and trigger the update request to No-Ip.


Any suggestions on how to detect my public IP address?

___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users


[lwip-users] No-IP Update Client implementation

2017-11-27 Thread Giuseppe Modugno
Is there some example how to implement an Update Client for a Dynamic 
DNS service, such as No-IP?


Thanks



___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users


Re: [lwip-users] How to use LWIP_HTTPD_FS_ASYNC_READ

2017-11-27 Thread Giuseppe Modugno

Il 24/11/2017 16:43, goldsimon ha scritto:
You're right in that it doesn't work. The browser has no way to know 
the body size.
The downside of not sending conten length is that the server will have 
to close the connection. Reopening it might take longer than just 
sending zero bytes to create the correct content size...
Why the server should close the connection when the Content Length 
header is not send? I tried and it seems it works well:




Server is 192.168.1.201, client is 151.45.118.38. The request is GET 
log.cgi?first=0=8 (packet n. 57). The answer is at the selected 
packet (n. 74). As you can see, the server doesn't send Content-Length 
header (I made some modifications on httpd.c) and the body (JSON data) 
is included in the same TCP session.


Of course the client couldn't know the length of data in advance, but 
this isn't a problem for me. They aren't too big, the only issue is that 
they aren't available when the headers are generated. Indeed, 
get_http_headers() function is called from http_init_file(), IMHO too 
early. A small improvement could be to call get_http_headers() when at 
least the first block of data is available. In my case, I have only a 
single block of data, so I could send the correct Content-Length header. 
I will add this request on savannah.


Anyway, at least for the moment, the solution to avoid sending 
Content-Length is ok for me.
___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users

Re: [lwip-users] How to use LWIP_HTTPD_FS_ASYNC_READ

2017-11-24 Thread Giuseppe Modugno



 1. I don't know the content length in advance. So I have to start
with a length that is surely greater than the final length,
otherwise the browser stops receveing data before the end. However
what happens if Content Length header says 300 and only 100 bytes
were received? Chrome seems ok, but other browsers? Is there a
standard behaviour? From RFC7230 it seems sending a Content Length
value greater than real message body length isn't good:
/5. If a valid Content-Length header field is present without
Transfer-Encoding, its decimal value defines the expected message
body length in octets. If the sender closes the connection or the
recipient times out before the indicated number of octets are
received, the recipient MUST consider the message to be incomplete
and close the connection./
Is it possible to avoid sending Content Length header for log.json
file? Consider I'm using dynamic headers.

I have to correct what I wrote. If the value of Content-Length header 
sent by the server is less than the real data exchanged, the client will 
not accept other data (if Content-Length says 10, the client will 
receive up to 10, no more). If the value is greater than the real 
content length, the browser emits a "content length mismatch error".


In other words, if appears, content length must report the exact content 
length. In my case, because I don't know the real content length in 
advance, I should avoid sending Content Length header. However I don't 
know if it is possible in httpd.


In get_http_headers(), there's the possibility to skip content-length, 
but it is only for SSI files and for files with included headers.



___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users

Re: [lwip-users] TCP_WRITE_FLAG_MORE, tcp_write(), tcp_output() and real output TCP segment

2017-11-23 Thread Giuseppe Modugno

Il 22/11/2017 17:09, goldsi...@gmx.de ha scritto:

Giuseppe Modugno wrote:


I'm sorry for the second email.

I noticed in tcp_output():

/**/* First, check if we are invoked by the TCP input processing//
// code. If so, we do not output anything. Instead, we rely
on the//
// input processing code to call us when input processing is
done//
// with. *//
*  if (tcp_input_pcb == pcb) {**
**    return ERR_OK;**
**  }*

In the application recv() function, I decide I received all data and 
now I'm ready to answer with a reply. I call tcp_write() (maybe 
multiple times) from recv() and then tcp_output(). The previous if 
has the effect to return immediately from tcp_output(), so its call 
is useless.




It is, in this case. But normally, it's better to keep it in there 
instead of making your 'send-more'-code know if it is called from 
'recv' or 'poll' or 'sent' callback...
For example, httpd usually calls tcp_output() after http_send(), except 
when http_send() is called from http_recv(). From what you write, it's 
better to call tcp_output() even in http_recv().
___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users

Re: [lwip-users] TCP_WRITE_FLAG_MORE, tcp_write(), tcp_output() and real output TCP segment

2017-11-23 Thread Giuseppe Modugno

Il 22/11/2017 17:07, goldsi...@gmx.de ha scritto:


Giuseppe Modugno wrote:


I'm trying to understand the mechanisms under TCP_WRITE_FLAG_MORE, 
tcp_write() and tcp_output(). I'm using raw API.


First of all, I couldn't understand if tcp_output() is useful or not.



Why do you think all the world would call tcp_output() if it's not useful?
You're right, maybe a better question would be: "what is the utility of 
tcp_output()?".


Before sending my post, I checked the use of tcp_output() in lwip apps 
and I found only httpd, lwiperf and mqtt use it.


I understood tcp_output() *really* outputs unsent data, pushing all 
data to netif driver. Here it's not clear:


  * if unacked data (data already sent but not yet acknlowedged) is
sent too;



No, it's not. Unacked data is only retransmitted for a 'rexmit' event. 
To do that, it is moved back to 'unsent' and tcp_output() is called.



  * what happens if data in the output buffer is bigger than what
netif driver could accept in its sending function



Then it is not sent. :-)
TCP re-triggers tcp_output() if data is ACKed or new data is received 
or in a timer, so eventually, more data is sent.



  * (maybe a well written application checks tcp_sndbuf() before
writing output data, so this event never happens).



No, tcp_sndbuf() does not know anything about your netif driver.


For example:

tcp_write(...)
tcp_write(...)
tcp_write(...)
tcp_output()

Is tcp_output() really needed?



Yes, of course! If not, I would have deleted it already ;-)


It seems data are send even without calling tcp_output().



It is, but only at some time later (by tcp_tmr). This drops your 
throughput, of course.
So it's better to call tcp_output() as soon as there aren't more data 
available to send.


Another question is the correspondence between tcp_write() calls and 
output TCP segments, IP packets and Ethernet frames. Are three TCP 
segments, three IP packets and three Ethernet frames generated? Does 
lwip try to compact output data in a single TCP segment, IP packet 
and Ethernet frame?


Yes, data is appended, to unsent segments. However, it's not easy to 
cite the rules here, as there are many optimizations in this path. In 
the end, don't try to rely on something here!


Another question is about TCP_WRITE_FLAG_MORE flag. I understood this 
flag should be set in all tcp_write() except the last. However it 
seems it works with and without that flag in sending data.


Of course it works, but pbuf allocation and tcp header flags differ. 
If it doesn't make a difference for you, you can just set the flag to 
what you want.

It should be nice to understand when this flag could be and not be useful.
___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users

Re: [lwip-users] httpd: how to implement AJAX

2017-11-22 Thread Giuseppe Modugno

Il 13/11/2017 21:25, goldsi...@gmx.de ha scritto:

Giuseppe Modugno wrote:

The prototype for SSI callbacks is:
[..]
I don't see any reference to query string parameters. So how to 
select the right action?


Sorry for the confusion. This is a mix of resource optimization, 
missing documentation and maybe missing framework functions.


The idea is that we don't want to keep the http request pbuf(s) around 
until the end of the SSI file is transmitted (which might be long).

Instead, this is done in three steps:
- fs_open() calls fs_state_init(file, name) to create an object big 
enough to hold everything you'd need for 'file'

  (for custom files, you'll have to call this yourself)
- httpd_cgi_handler() can parse everything needed and store it in this 
object
- the SSI handler gets this object, too, and can access the content 
required
(- or alternatively, in a custom read function, you might direclty 
access file->state)
I'm trying to implement what you wrote, using "custom files" instead of 
SSI. I think something doesn't work.


Suppose I have a CGI script that the client requests with a *GET 
/login.cgi?auth=pippo:pluto*
fs_open_custom() returns 1 if "login.cgi" is passed as filename. However 
here I'm not able to create the answer, because I need to evaluate the 
query string parameters (that I will do in CGI handler). So I can't do 
much in fs_open_custom() and I don't know how to set file->data, 
file->line and file->index.


In CGI handler I'm ready to create the full answer because I have the 
query string, maybe in a buffer allocated with malloc and saved in 
file->state pointer.


The problem here is fs_read_custom() is never called, because 
LWIP_HTTPD_DYNAMIC_FILE_READ isn't defined. Is really needed to define 
LWIP_HTTPD_DYNAMIC_FILE_READ in this scenario? This macro will allocate 
a dynamic output buffer in http_state and call fs_read_custom() that 
will limit to copy all or part of data created in CGI to the buffer of 
http_state. It seems too complex for this scenario.


In CGI handler I could set all the "file info" in http_state (length and 
pointer), however http_state isn't accessible from this point.



One thing I can't understand. It's index member of struct fs_file. It is 
initialized as the length of file content if fs_open(), for non custom 
files. And it is used in:


  int fs_bytes_left(struct fs_file *file) {
    return file->len - file->index;
}

So after fs_bytes_left() is zero immediately after fs_open(). This 
sounds strange to me. Maybe index isn't the pointer to unsent data (it 
should be zero after open), but to the pointer of the next byte to read 
from file (and for "static" files, there's no other data to read after 
open, because all data is ready immediately).



___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users

Re: [lwip-users] httpd: how to implement AJAX

2017-11-14 Thread Giuseppe Modugno

Il 14/11/2017 13:54, Noam Weissman ha scritto:

Hi,

HTTPD is widely used and if you look around you can find examples from ST micro 
TI and other vendors.
Do you mean HTTPD *without* a secure layer? Yes, I know there are many 
examples of it, but IMHO because it is simpler than a full HTTPS server.
I don't think you can use a non-secure HTTP (or MQTT or SNMP) 
communication in a public network today for a serious application that 
isn't a simple test example.


___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users

Re: [lwip-users] httpd: how to implement AJAX

2017-11-14 Thread Giuseppe Modugno

Il 13/11/2017 21:25, goldsi...@gmx.de ha scritto:

Giuseppe Modugno wrote:

The prototype for SSI callbacks is:
[..]
I don't see any reference to query string parameters. So how to 
select the right action?


Sorry for the confusion. This is a mix of resource optimization, 
missing documentation and maybe missing framework functions.

Thank you very much for your explanation. Now it is clear.


My plan is to have https examples for the next release...
https would be very interesting (actually a simple non-secure http 
server isn't really useable in public Internet).


If I understood correctly, https means ssl/tls. So the first task is to 
add SSL/TLS to lwip, right? It's a pity lwip doesn't feature those 
secure network layers.


___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users


Re: [lwip-users] httpd: how to implement AJAX

2017-11-14 Thread Giuseppe Modugno

Il 13/11/2017 18:04, Noam Weissman ha scritto:

Yes SSID is a session ID that had been added to my own server code.
So are you using a completely different HTTP server from the httpd that 
is in apps folder of lwip main source?


When a user askes for a page and there is no ssid the server will 
redirect (send a 303)


And load a login page instead. After the user writes user+password the 
data is sent to


The server.

How do you send user+password to the server? PUT? Do you encode these 
sensible values?


The server call’s external code to check for validity of user+pass… if 
OK it


Request a new ssid from a separate task.

After that the web server sends the previously request page + ssid… 
every operation


at the browser side must add that ssid value.


Is it a cookie, right?


Every time the web server gets a request

with the correct ssid it clears the related timeout. If the ssid 
timeouts and the user asks


for some data it will again redirect to the login page.

Do you call a specific function from main at regular intervals to clear 
all SSID that expire?



Regarding AJAX:

How do you handle SSI ?... I am doing it differently ? I have 
something like this in my code:


const SSI_t SSI_Table[] =

{

  {"mem_rout", mem_routing},

  {"IOSel", IO_Selection},

 {"get_users", get_users},

 {"ajax_reply", AjaxReply},

 {NULL, NULL} // last tag must always be NULL to close the list

};

mem_routing, IO_Selection,  get_users,  and   AjaxReply  are call-back 
function that are called by the web


server as a result of encountering the proper tag… for mem_routing it 
is   


I think LWIP_HTTPD_CUSTOM_FILES is simpler to use when you have a file 
that is completely dynamic. Your "single tag trick" works, but IMHO is 
too complex for what you have to do.


my AjaxReply parses the GET params and after that does something like 
that:


How AjaxReply() function could access GET params if they aren't 
accessible from the SSI handler? Most probably the answer is in the file 
state (LWIP_HTTPD_FILE_STATE) that is filled by httpd_cgi_handler() 
callback (as explained by goldsimon).



// get action param

Char *Action = some_function();

If(strcmp(Action, “do_something_1”) == 0)

{

}

elses If(strcmp(Action, “do_something_2”) == 0)

{

}

else

{

// print a debug error :  action unknown

}

Hope that helped,

Noam.

*From:*lwip-users 
[mailto:lwip-users-bounces+noam=silrd@nongnu.org] *On Behalf Of 
*Giuseppe Modugno

*Sent:* Monday, November 13, 2017 6:09 PM
*To:* lwip-users@nongnu.org
*Subject:* Re: [lwip-users] httpd: how to implement AJAX

Il 13/11/2017 14:34, Noam Weissman ha scritto:

Hi,
I am using the following technic for AJAX.
Create an empty file named ajax.shtml or ajax.html and add it to your file list.
Inside the file you only write one tag without anything else. For example 

Do not add  CR or LF just the tag !!.
Now when you issue an AJAX call the WEB server opens the file, reads it and 
send its data.
Because the file has only the tag it will parse it, call your handler for that 
tag and send back
To the browser just your data !!

Ok, so you use SSI to create dynamic data. I tried with custom files, 
because *all the content* is dynamic (and not only some parts, defined 
by specific tags).



If you use Juery it will look something like this... actually a function used 
as an event handler in
my own code:
function resetIO()
   {
     //Remove the dialog
     returnToPage();
 
 $.ajax({

   url: "ajax.shtml",
   dataType : "text",
   type : "GET",
   cache : false,
   data : ({
     ssid: ssid,
     a: 'opReset',
     type: 2
   }),
   error : function()
   {
     showMessage("Network Error: Sorry, there was a problem connecting to 
the server.");
   },
   success : function(result)
   {
     window.location.href = document.location;
   }
     });
   }
In the above data you have the a:  variable,  this is your AJAX action !.

If I understood well, data is translated in query string, in your example:

    GET ajax.shtml?ssid==opReset=2

Of course,  is the value of ssid Javascript variable.


In your own SSI/CGI code you have a table with tags + callbacks... one of the 
callback function
Is your AJAX handler. Inside it you create an if <> else layout and handle the 
different actions.

The prototype for SSI callbacks is:

typedef u16_t (*tSSIHandler)(
#if LWIP_HTTPD_SSI_RAW
 const char* ssi_tag_name,
#else /* LWIP_HTTPD_SSI_RAW */
 int iIndex,
#endif /* LWIP_HTTPD_SSI_RAW */
 char *pcInsert, int iInsertLen
#if LWIP_HTTPD_SSI_MULTIPART
 , u16_t current_tag_part, u16_t 
*next_tag_part

#

Re: [lwip-users] httpd: how to implement AJAX

2017-11-13 Thread Giuseppe Modugno

Il 13/11/2017 14:34, Noam Weissman ha scritto:

Hi,

I am using the following technic for AJAX.

Create an empty file named ajax.shtml or ajax.html and add it to your file list.

Inside the file you only write one tag without anything else. For example 


Do not add  CR or LF just the tag !!.

Now when you issue an AJAX call the WEB server opens the file, reads it and 
send its data.
Because the file has only the tag it will parse it, call your handler for that 
tag and send back
To the browser just your data !!
Ok, so you use SSI to create dynamic data. I tried with custom files, 
because *all the content* is dynamic (and not only some parts, defined 
by specific tags).



If you use Juery it will look something like this... actually a function used 
as an event handler in
my own code:

function resetIO()
   {
 //Remove the dialog
 returnToPage();
 
 $.ajax({

   url: "ajax.shtml",
   dataType : "text",
   type : "GET",
   cache : false,
   data : ({
 ssid: ssid,
 a: 'opReset',
 type: 2
   }),
   error : function()
   {
 showMessage("Network Error: Sorry, there was a problem connecting to 
the server.");
   },
   success : function(result)
   {
 window.location.href = document.location;
   }
 });
   }

In the above data you have the a:  variable,  this is your AJAX action !.

If I understood well, data is translated in query string, in your example:

    GET ajax.shtml?ssid==opReset=2

Of course,  is the value of ssid Javascript variable.


In your own SSI/CGI code you have a table with tags + callbacks... one of the 
callback function
Is your AJAX handler. Inside it you create an if <> else layout and handle the 
different actions.

The prototype for SSI callbacks is:

   typedef u16_t (*tSSIHandler)(
   #if LWIP_HTTPD_SSI_RAW
 const char* ssi_tag_name,
   #else /* LWIP_HTTPD_SSI_RAW */
 int iIndex,
   #endif /* LWIP_HTTPD_SSI_RAW */
 char *pcInsert, int iInsertLen
   #if LWIP_HTTPD_SSI_MULTIPART
 , u16_t current_tag_part, u16_t
   *next_tag_part
   #endif /* LWIP_HTTPD_SSI_MULTIPART */
   #if defined(LWIP_HTTPD_FILE_STATE) && LWIP_HTTPD_FILE_STATE
 , void *connection_state
   #endif /* LWIP_HTTPD_FILE_STATE */
 );

I don't see any reference to query string parameters. So how to select 
the right action?



The HTTP server will read your ajax.shtml file and because it has nothing BUT 
your tag it will
only send back the dynamic data you process in your ajax handling function.
As said before, it works if the dynamic content depends only from the 
name of the file (ajax.shtml in your example) and not from the action in 
the query string (a=opReset).


Where is my error?

Another question. I saw ssid in your javascript example. Is it related 
to a "session identifier"? If so, did you implement a session mechanism 
over httpd?
___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users

[lwip-users] httpd: how to implement AJAX

2017-11-13 Thread Giuseppe Modugno
I'm trying to create a website with AJAX technology: the client polls, 
at regular intervals, the server with GET requests of file /status.json. 
The response is dynamic.


I could use only LWIP_HTTPD_CUSTOM_FILES and create the file at runtime 
in fs_open_custom(). It works, but I can't decode the query string, 
because it isn't passed to fs_open_custom() callback.


So I thought to use LWIP_HTTPD_CGI_SSI instead of 
LWIP_HTTPD_CUSTOM_FILES, but I have some difficulties to understand how 
it works.
First of all, the file /status.json must be present in the filesystem 
(fs_open() must return ERR_OK), otherwise httpd_cgi_handler() isn't 
called at all.

However I can't return any data in httpd_cgi_handler().

Any help?


___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users


Re: [lwip-users] httpd and authentication

2017-11-12 Thread Giuseppe Modugno

Il 11/11/2017 09:07, goldsimon ha scritto:


Giuseppe Modugno wrote:

I'd like to protect some or all web pages and show them only to
authorized
people. I understood there are two methods: basic and digest.

I guess both are outdated. Modern web pages use a custom input field which is 
sent to the server via POST. You'll need TLS obviously if you want the data to 
be protected. The server then opens a session by sending the client a session 
cookie which is then included in all further requests from the client.

Sadly, this is not implemented in lwip httpsd yet. The server code supports 
POST but not sending/parsing cookies (although that part should be easy to 
add). An overall example and session handling is missing though.
I know lwip is an open-source community project, but it's very strange a 
minimal HTTP authorization support isn't implemented (yet). Today it's 
very difficult to think of an embedded HTTP server that isn't protected 
at all from unathorized access.


I suppose all the people using HTTP server in lwip apps folder add their 
own authorization mechanism and it is a pity noone commit this to the 
original HTTP server.


I don't think to have the capability to add auth mechanism... however 
I'll try and I'll share my results.



___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users


[lwip-users] httpd and authentication

2017-11-10 Thread Giuseppe Modugno
I'd like to protect some or all web pages and show them only to authorized
people. I understood there are two methods: basic and digest.

Basic is simpler, but it is unsecure (because it uses base64). In this case
you need TLS.
Digest is more complicated but it is more secure (it uses MD5 algorithm and
a nonce to protect data).

Are there some examples of both methods with lwip?

I suppose TLS needs a cryptographic dedicated hw, right?
Is digest/MD5 really more secure than basic authentication? MD5 is only a
hash algorithm. I think it is simple to decode username and password after
sniffing nonce (send by the server) and hash (send by the client).

Any suggestion?
___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users

Re: [lwip-users] win32 porting contrib: double IP address

2017-11-10 Thread Giuseppe Modugno

Il 09/11/2017 17:43, Joel Cunningham ha scritto:

On 11/09/2017 03:41 AM, Giuseppe Modugno wrote:

Il 08/11/2017 16:34, Joel Cunningham ha scritto:
The ping works well if I launch "ping 192.168.1.156" command from 
*another* computer on the same network.
You're most likely running into a checksum offload problem since you 
can't contact the LwIP stack from the Windows host, but you CAN from 
another machine.  The Window's TCP/IP stack is going to use checksum 
offloading for IPv4/UDP/TCP and during the transmit path, Winpcap 
will capture them before they go to hardware (where checksum is 
added).  Then they will fail checksum validation in LwIP and be 
discarded.


You can verify this easily by opening up wireshark and capturing on 
the interface.  Wireshark (also using winpcap) will capture the 
packets at the same point and you can verify the checksum is missing.

You're right.

If this is the case, you can disable checksum offloading in Windows 
for TX.

What is the procedure to disable checksum offloading in Windows for TX?

It varies depending on your network card.  Easiest way is if the 
adapter has an option to disable it.  I have one like this.  For Win 
7, Control Panel -> Network and Internet -> Network and Sharing Center 
-> Change Adapter Settings -> Right click adapter -> Properties -> 
Configure -> Advanced.  Then I have options like 'TCP Checksum Offload 
(IPv4)' which I can set to Disabled, RX or TX Disabled/Enabled
Yes, I have those kind of options. However there are many "offload" 
options: TCP, UDP, ARP, IPv4...



___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users

Re: [lwip-users] win32 porting contrib: double IP address

2017-11-09 Thread Giuseppe Modugno

Il 08/11/2017 18:20, Gisle Vanem ha scritto:

Giuseppe Modugno wrote:

So I have an Ethernet interface with two IP and MAC addresses. It 
seems it works, except for one thing.
I tested connectivity by running "ping 192.168.1.156" command from a 
shell on the same computer. No reply!
The ARP table is ok (192.168.1.156 is associated to 01.02.03.04.05.06 
MAC address). It seems no packets are detected from lwip.


Besides the fix mentioned by Joel, you can turn off
checksumming in LwIP by something like:

  #if (LWIP_DEBUG > 0)
    #define CHECKSUM_CHECK_IP   0
    #define CHECKSUM_CHECK_TCP  0
    #define CHECKSUM_CHECK_UDP  0
    #define CHECKSUM_CHECK_ICMP 0
    #define CHECKSUM_CHECK_ICMP6    0
    ...
  #endif

Yes, this trick works.

___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users


Re: [lwip-users] win32 porting contrib: double IP address

2017-11-09 Thread Giuseppe Modugno

Il 08/11/2017 16:34, Joel Cunningham ha scritto:
The ping works well if I launch "ping 192.168.1.156" command from 
*another* computer on the same network.
You're most likely running into a checksum offload problem since you 
can't contact the LwIP stack from the Windows host, but you CAN from 
another machine.  The Window's TCP/IP stack is going to use checksum 
offloading for IPv4/UDP/TCP and during the transmit path, Winpcap will 
capture them before they go to hardware (where checksum is added).  
Then they will fail checksum validation in LwIP and be discarded.


You can verify this easily by opening up wireshark and capturing on 
the interface.  Wireshark (also using winpcap) will capture the 
packets at the same point and you can verify the checksum is missing.

You're right.

If this is the case, you can disable checksum offloading in Windows 
for TX.

What is the procedure to disable checksum offloading in Windows for TX?


___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users

[lwip-users] win32 porting contrib: double IP address

2017-11-08 Thread Giuseppe Modugno
Hello lwip users, this is my first post. I hope this is the right 
mailing list for my question.


I started with lwip, so I downloaded both lwip and lwip-contrib. I was 
able to compile lwip test application for win32 (mingw compiler). When I 
launch test application on third adapter interface (in my computer it's 
a normal Ethernet interface integrated in the motherboard) with 0.0.0.0 
ip address, lwip automatically requests and obtains a new IP address 
(192.168.1.156). Of course, I have a DHCP server running on the network.


The Ethernet interface is already configured in Windows to use DHCP and 
its "Windows IP address" is 192.168.1.102 (DHCP static assignment).


So I have an Ethernet interface with two IP and MAC addresses. It seems 
it works, except for one thing.
I tested connectivity by running "ping 192.168.1.156" command from a 
shell on the same computer. No reply!
The ARP table is ok (192.168.1.156 is associated to 01.02.03.04.05.06 
MAC address). It seems no packets are detected from lwip.


The ping works well if I launch "ping 192.168.1.156" command from 
*another* computer on the same network.


Is there a solution to use my development computer to run lwip TCP/IP 
stack *and* to simulate an Internet node that wants to connect to it?


I think a solution is to use a virtual machine with a virtual network 
adapter, but this means to open VMWare Player or Virtual Box... I'd like 
to avoid.





___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users