Re: [lwip-users] invalid recvmbox in UDP recv() function

2017-05-11 Thread goldsi...@gmx.de

gussabina wrote:

I'm using the Atmel port for ATSAM4E which comes from ASF (Atmel Software
Framework) integrated with FreeRTOS.


In that case, have you asked Atmel? Tell them the lwIP guys said it's 
not an lwIP bug ;-)

If it is, I'll pay you a beer next time I see you :-)

Simon

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


Re: [lwip-users] lwip 2.0.2 + freertos + ARM7

2017-05-11 Thread goldsi...@gmx.de

Werner Motz wrote:

tcpip_callback(tcp_write(pcb,ucrecBuff,supersize,TCP_WRITE_FLAG_COPY),NULL);

tcpip_callback(tcp_output(pcb), NULL);



Ouch! tcpip_callback() takes a void pointer as first argument. You are 
*first* calling tcp_write with the parameters supplied, then passing the 
return valud of tcp_write to tcpip_callback. Here, an 'err_t' type is 
implicitly interpreted as a void pointer.


Seriously, learn C and learn to set up your compiler to warn about such 
erroneous code!


If and when you have truly lwIP related questions, feel welcome here to 
get them answered!


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

[lwip-users] How to find out if I can send out more UDP packets?

2017-05-11 Thread Xun Chen

Hi there,

I use udp_sendto to output packets, if I space them in time to make sure 
the packets are sent, everything is fine, but if I call udp_sendto too 
frequently, I will run into error code -1, out of memory.


Which lwip raw API can I call to find out if I have the resource before 
I construct the UDP payload?


Thanks!

XC

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


Re: [lwip-users] invalid recvmbox in UDP recv() function

2017-05-11 Thread goldsi...@gmx.de

gussabina wrote:

Ok. But TCP sockets works fine...


Honestly, that doesn't mean anything :-) There can well be other bugs 
and TCP just happens to work...
Where do you have your lwIP port from? Who set up your interrupts and 
thread configuration?



Actually, in below code I'm using select() to wait for receive data...Now
I'm confused...Should I use same approach for UDP?


No. The "socket() ... recv()" scheme should work as well.

Simon

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


Re: [lwip-users] invalid recvmbox in UDP recv() function

2017-05-11 Thread gussabina
Ok. But TCP sockets works fine...Below is the code I'm using for TCP receive.

Actually, in below code I'm using select() to wait for receive data...Now
I'm confused...Should I use same approach for UDP?

Thanks;
Gus

/int SocketRead(void *context, byte* buf, int buf_len, int timeout_ms)
{

SocketContext *sock = (SocketContext*)context;
int rc = -1, timeout = 0;
SOERROR_T so_error = 0;
fd_set recvfds;
fd_set errfds;
struct timeval tv;

if (context == NULL || buf == NULL || buf_len <= 0) {
return ERROR_BAD_ARG;
}

sock->bytes = 0;

// Setup timeout and FD's 
setup_timeout(, timeout_ms);
FD_ZERO();
FD_SET(sock->fd, );
FD_ZERO();
FD_SET(sock->fd, );

// Loop until buf_len has been read, error or timeout 
while (sock->bytes < buf_len) {

// Wait for rx data to be available 
rc = select((int)SELECT_FD(sock->fd), , NULL, , );
if (rc > 0)
{
// Check if rx or error 
if (FD_ISSET(sock->fd, )) {

// Try and read number of buf_len provided,
//minus what's already been read 
rc = (int)SOCK_RECV(sock->fd, [sock->bytes], buf_len -
sock->bytes, 0);
if (rc <= 0) {
rc = -1;
goto exit; // Error 
}
else {
sock->bytes += rc; // Data
}

}
if (FD_ISSET(sock->fd, )) {
rc = -1;
break;
}
}
else {
timeout = 1;
break; // timeout or signal 
}
} // while 

exit:

if (rc == 0 && timeout) {
rc = ERROR_TIMEOUT;
}
else if (rc < 0) {
// Get error
socklen_t len = sizeof(so_error);
getsockopt(sock->fd, SOL_SOCKET, SO_ERROR, _error, );

if (so_error == 0) {
rc = 0; // Handle signal 
}
else {
rc = ERROR_NETWORK;
PRINTF("NetRead: Error %d", so_error);
}
}
else {
rc = sock->bytes;
}
sock->bytes = 0;
return rc;
}
/




--
View this message in context: 
http://lwip.100.n7.nabble.com/invalid-recvmbox-in-UDP-recv-function-tp29602p29623.html
Sent from the lwip-users mailing list archive at Nabble.com.

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


Re: [lwip-users] invalid recvmbox in UDP recv() function

2017-05-11 Thread goldsi...@gmx.de

gussabina wrote:

Is the recvmbox supposed to be created by bind() function?


It's supposed to be allocated in socket() (that function fails if mbox 
allocation fails) and removed in close() only. That's what makes me 
think your port's mbox alloc/dealloc/check functions don't work correctly...


Simon

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


Re: [lwip-users] PPPoS: Question regarding reconnect after connection lost

2017-05-11 Thread Sylvain Rochet
Hi Axel,

On Thu, May 11, 2017 at 07:55:44PM +0800, Axel Lin wrote:
> 
> Hi Sylvain,
> 
> In practice, it usually has application code sending data while PPP 
> disconnect. I use netconn API + FreeRTOS, so I have a thread keep 
> sending data to internet.
> 
> While PPP re-connect there is a period I need to send AT commands and 
> calling ppp_connect(), is there any thing I need to take care for my 
> application code while PPP discconect and re-connect?

No, if PPP is disconnected IP output packets are tossed[1].

Sylvain

[1] 
http://git.savannah.gnu.org/cgit/lwip.git/tree/src/netif/ppp/ppp.c?id=4171f39a72ed15cb394f7cb9b909c5b3a2068580#n505


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

Re: [lwip-users] lwip 2.0.2 + freertos + ARM7

2017-05-11 Thread Dirk Ziegelmeier
The two APIs can coexist.

regarding your code: Sorry, this code is so horribly wrong :-( I am sorry
for being rude - you also need a LOT of education in C code. And, if your
compiler compiles this, the warning settings are way too relaxed or you
really should read and fix all compiler warnings.

​Sorry, you have a too long way to go there, can't help you there.​

Dirk



On Thu, May 11, 2017 at 2:10 PM,
​​
Werner Motz  wrote:

> I cannot because my webserver is already running with raw api.
>
>
>
> In my Send task I try now…
>
>
>
> tcpip_callback(tcp_write(pcb, ucrecBuff, supersize, TCP_WRITE_FLAG_COPY),
> NULL);
>
> tcpip_callback(tcp_output(pcb), NULL);
>
>
>
> but without success. After the first message sent the system crashed.
>
> I think I am doing something horrible wrong :D
>
>
>
> ___
> 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] invalid recvmbox in UDP recv() function

2017-05-11 Thread gussabina
Thanks, Simon.

I will update and also try to debug it...
Is the recvmbox supposed to be created by bind() function? According to the
error message, this is not valid/existing when checked by the the recv()
function..

Thanks
Gus



--
View this message in context: 
http://lwip.100.n7.nabble.com/invalid-recvmbox-in-UDP-recv-function-tp29602p29619.html
Sent from the lwip-users mailing list archive at Nabble.com.

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


Re: [lwip-users] invalid recvmbox in UDP recv() function

2017-05-11 Thread gussabina
Thank you, Simon.

Where can I download v .2?

Gus



--
View this message in context: 
http://lwip.100.n7.nabble.com/invalid-recvmbox-in-UDP-recv-function-tp29602p29618.html
Sent from the lwip-users mailing list archive at Nabble.com.

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


Re: [lwip-users] lwip 2.0.2 + freertos + ARM7

2017-05-11 Thread Werner Motz
I cannot because my webserver is already running with raw api.

 

In my Send task I try now…

 

tcpip_callback(tcp_write(pcb, ucrecBuff, supersize, TCP_WRITE_FLAG_COPY),NULL);

tcpip_callback(tcp_output(pcb), NULL);

 

but without success. After the first message sent the system crashed.

I think I am doing something horrible wrong :D

 

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

Re: [lwip-users] PPPoS: Question regarding reconnect after connection lost

2017-05-11 Thread Axel Lin
2017-04-07 23:35 GMT+08:00 Axel Lin :
> 2017-04-06 21:18 GMT+08:00 Sylvain Rochet :
>> Hi Axel,
>>
>> On Thu, Apr 06, 2017 at 08:58:10PM +0800, Axel Lin wrote:
>>>
>>> Below is what I do to start PPP:
>>>
>>> Send "AT+CGDCONT=,,"
>>> Send "AT+CGAUTH=[, [, , ]]"
>>> Send "AT+CFUN=1"
>>> Send "ATD*99***#"
>>>
>>> ppp_set_usepeerdns(ppp, 1);
>>> ppp_set_auth(ppp, PPPAUTHTYPE_ANY, userId, password);
>>> ppp_connect(ppp, 0);
>>>
>>> My understanding is after ATD*99***1#, I cannot send AT commands.
>>> So it's not clear to me if I need to re-send above AT commands after got
>>> PPPERR_CONNECT. Currently I just call ppp_connect(ppp, 30); to reconnect.
>>
>> You have to resend AT commands to reconnect. You need to switch back
>> your modem to command mode before, either by using DTR signal or by
>> using a predefined escape sequence that could never happen in the PPP
>> flow (which I do not recommend unless you are very careful with the
>> chosen asyncmap).
>
> Hi Sylvain,
> By following your suggestions, now it works.

Hi Sylvain,

In practice, it usually has application code sending data while PPP disconnect.
I use netconn API + FreeRTOS, so I have a thread keep sending data to internet.

While PPP re-connect there is a period I need to send AT commands and
calling ppp_connect(),
is there any thing I need to take care for my application code while
PPP discconect and re-connect?

Thanks,
Axel

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


Re: [lwip-users] lwip 2.0.2 + freertos + ARM7

2017-05-11 Thread Dirk Ziegelmeier
Use socket API and you can use threads without problems.

Possible alternative:
http://www.nongnu.org/lwip/2_0_x/group__tcp__raw.html#gafba47015098ed7ce523dcf7bdf70f7e5

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

Re: [lwip-users] lwip 2.0.2 + freertos + ARM7

2017-05-11 Thread Werner Motz
I admit my understanding of threads is not the best.

I understand the use of a callback API, but I don’t want to

send data back in a callback only in order of receiving a TCP/IP message.

I want to send independently from receiving. 

 

I am aware that there is only one tcpip thread which is

responsible for tcp_input and output.

My question is how to enqueue data via tcp_write()

without running into a conflict.

Is there a callback function which is called independently

from receiving in which I could send my data?

   

 

Von: lwip-users [mailto:lwip-users-bounces+motz=smart-e-tech...@nongnu.org] Im 
Auftrag von Dirk Ziegelmeier
Gesendet: Donnerstag, 11. Mai 2017 12:54
An: Mailing list for lwIP users
Betreff: Re: [lwip-users] lwip 2.0.2 + freertos + ARM7

 

Hello Werner,

the following sentences are NOT meant in a harsh way, but as a good and polite 
advice to you:


You really need to get educated in threading, locking and interrupt issues when 
you develop for a multithreaded system. Without understanding these, you will 
quite surely end up with a system that "usually works" but has occasional 
hiccups a few times a day.

The question you are asking is out of scope of this mailing list, it is a 
question about general threading design in an embedded system. Please 
understand I don't want to help you there, that would consume too much time. It 
is not a question that can be answered shortly in a few sentences and without 
understanding your application.

 

If you use threads, you may want to use netconn or socket API if that's easier 
for you. You still can use the callback API, but you need to use 
tcpip_callback() or LOCK_TCPIP_CORE (if you configured lwIP to use core 
locking) to sync with lwIP thread.




Dirk

 

On Thu, May 11, 2017 at 12:07 PM, Werner Motz  wrote:

Thank u for your answer. 

But what is the proper way to use tcp_write() and tcp_output()? Where can I use 
them?

Would it be correct to do:

 

LOCK_TCPIP_CORE();

tcp_write();

tcp_output();

UNLOCK_TCPIP_CORE();

 

If I do so, how can I ensure, that I can still receiving data? Don’t I block 
the RX side?

Sorry, I am a noob but how can I ensure that I am in the tcpip thread?

 

 

Von: lwip-users [mailto:lwip-users-bounces+motz 
 =smart-e-tech...@nongnu.org] Im Auftrag von 
Dirk Ziegelmeier
Gesendet: Mittwoch, 10. Mai 2017 19:04
An: Mailing list for lwIP users
Betreff: Re: [lwip-users] lwip 2.0.2 + freertos + ARM7

 

Sounds like you are calling lwIP functions from another thread than the lwIP 
thread, in your case the CAN thread.

See
http://www.nongnu.org/lwip/2_0_x/pitfalls.html

Dirk

 


___
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 2.0.2 + freertos + ARM7

2017-05-11 Thread Dirk Ziegelmeier
Hello Werner,

the following sentences are NOT meant in a harsh way, but as a good and
polite advice to you:

You really need to get educated in threading, locking and interrupt issues
when you develop for a multithreaded system. Without understanding these,
you will quite surely end up with a system that "usually works" but has
occasional hiccups a few times a day.

The question you are asking is out of scope of this mailing list, it is a
question about general threading design in an embedded system. Please
understand I don't want to help you there, that would consume too much
time. It is not a question that can be answered shortly in a few sentences
and without understanding your application.

If you use threads, you may want to use netconn or socket API if that's
easier for you. You still can use the callback API, but you need to use
tcpip_callback() or LOCK_TCPIP_CORE (if you configured lwIP to use core
locking) to sync with lwIP thread.

Dirk

On Thu, May 11, 2017 at 12:07 PM, Werner Motz  wrote:

> Thank u for your answer.
>
> But what is the proper way to use tcp_write() and tcp_output()? Where can
> I use them?
>
> Would it be correct to do:
>
>
>
> LOCK_TCPIP_CORE();
>
> tcp_write();
>
> tcp_output();
>
> UNLOCK_TCPIP_CORE();
>
>
>
> If I do so, how can I ensure, that I can still receiving data? Don’t I
> block the RX side?
>
> Sorry, I am a noob but how can I ensure that I am in the tcpip thread?
>
>
>
>
>
> *Von:* lwip-users [mailto:lwip-users-bounces+motz=smart-e-tech.de@nongnu.
> org] *Im Auftrag von *Dirk Ziegelmeier
> *Gesendet:* Mittwoch, 10. Mai 2017 19:04
> *An:* Mailing list for lwIP users
> *Betreff:* Re: [lwip-users] lwip 2.0.2 + freertos + ARM7
>
>
>
> Sounds like you are calling lwIP functions from another thread than the
> lwIP thread, in your case the CAN thread.
>
> See
> http://www.nongnu.org/lwip/2_0_x/pitfalls.html
>
> Dirk
>
>
>
> ___
> 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] invalid recvmbox in UDP recv() function

2017-05-11 Thread Simon Goldschmidt
gussabina wrote:
> I'm using lwIP with FreeRTOS and I need to receive data via UDP. I'm testing
> the following code which goes through until recv() function where it stucks
> in the following line;
> 
> LWIP_ERROR("netconn_accept: invalid recvmbox",
> sys_mbox_valid(>recvmbox), return ERR_CONN;);
> 
> inside netconn_recv( ) in api_lib.c

I have absolutely no ide why this would happen. From the error message, you're 
using 1.4.0 or 1.4.1, so you might want to try to update to 2.0.x, maybe that 
fixes anything.

Aside from that, the code you sent does not look wrong, so I suspect either a 
bug in your port or something overwriting some memory...

Simon

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


Re: [lwip-users] lwip 2.0.2 + freertos + ARM7

2017-05-11 Thread Werner Motz
Thank u for your answer. 

But what is the proper way to use tcp_write() and tcp_output()? Where can I use 
them?

Would it be correct to do:

 

LOCK_TCPIP_CORE();

tcp_write();

tcp_output();

UNLOCK_TCPIP_CORE();

 

If I do so, how can I ensure, that I can still receiving data? Don’t I block 
the RX side?

Sorry, I am a noob but how can I ensure that I am in the tcpip thread?

 

 

Von: lwip-users [mailto:lwip-users-bounces+motz=smart-e-tech...@nongnu.org] Im 
Auftrag von Dirk Ziegelmeier
Gesendet: Mittwoch, 10. Mai 2017 19:04
An: Mailing list for lwIP users
Betreff: Re: [lwip-users] lwip 2.0.2 + freertos + ARM7

 

Sounds like you are calling lwIP functions from another thread than the lwIP 
thread, in your case the CAN thread.

See
http://www.nongnu.org/lwip/2_0_x/pitfalls.html

Dirk

 

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