Re: Scan through the heap searching for a free block that is big enough, beginning with the lowest free block.

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Re: Scan through the heap searching for a free block that is big enough, beginning with the lowest free block.

Sergio R. Caprile
OK,
I know Modscan is a Modbus master tool, so I guess you are polling your
device, which happens to be a slave, a server, a TCP listener.
You are trying to implement ModbusTCP where the PC running Modscan (and
I guess Wireshark too) will connect (send SYN) to the lwIP device.

Second issue:
Those checksum errors you see on Wireshark are ON THE PC SIDE, you can
see those belong to the packets sent by .200 which I guess it is your PC
since it sends the SYN and the read coils query. That is usually due to
the checksum being handed over to the hardware, the network controller
does that and Wireshark can't see it. Anyway, we are debugging your
device, not your PC.

First issue:
Usually, memory problems are caused by people not respecting threading
rules or buggy (DMA) drivers.
https://www.nongnu.org/lwip/2_1_x/pitfalls.html

When you say "heap 4", I don't understand. Is it a FreeRTOS parameter or
some vendor setting or ? Where do you set that ? What is your lwIP
memory configuration ? (those MEM_ in an lwipopts.h file or in
src/include/lwip/opt.h)
I don't think you expect to run a TCP stack with 4 bytes, so clarifying
that comment would be a good idea so the memory experts can help you in
case there is a memory configuration issue.
Then...
What API are you using ?
You copied an echo server... which one ? The netconn one in contrib ?
the raw one in contrib ? A vendor provided one ? One you got from the
Internet ? Does it work ? Did you try it before modification ?
Then, when you <???> (please fill in the <???> with either "receive" or
"answer") a query, something happens and you find the lwIP thread is
looping where you describe.

if (<???> == "answer") then {
        well, what are you trying to send ? How many bytes ? Which function do
you call ?
} else if (<???> == "receive" then {
        does your app get an indication or this is a problem in the driver ?
} else {
        I guessed you wrong
}


_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users
Reply | Threaded
Open this post in threaded view
|

Re: Scan through the heap searching for a free block that is big enough, beginning with the lowest free block.

vrnud
Hi,
Thank you for your quick response.
Yes. I am developeing TCP server.

>>"When you say "heap 4", I don't understand. Is it a FreeRTOS parameter or
>>some vendor setting or ?"
------heap_4.c is a file in freeRTOS. sorry for mentioning it. i should not
have mentioned it in first place.


>>"What API are you using ?
>>You copied an echo server... which one ? The netconn one in contrib ?
>>the raw one in contrib ?"
------raw one.



>>" Does it work ?"
yes.


Information what i am trying to do.
Without any modification:
#define CHECKSUM_GEN_IP 0
/*----- Value in opt.h for CHECKSUM_GEN_UDP: 1 -----*/
#define CHECKSUM_GEN_UDP 0
/*----- Value in opt.h for CHECKSUM_GEN_TCP: 1 -----*/
#define CHECKSUM_GEN_TCP 0
/*----- Value in opt.h for CHECKSUM_GEN_ICMP: 1 -----*/
#define CHECKSUM_GEN_ICMP 0
I am able to connect to the modscan and communication is working very fine.


With modification:
I am trying to develop HSR redundancy.
PC is connected to one port of hirschmann switch(External Redbox).
Another port of Hirschmann switch is connected to my unit.
Hirschamnn swithch simply adds HSR tag to incoming frame coming to PC and
send (HSR tag) frame
to my unit.
My application will remove HSR tag for incoming frames and feed it to LWIP
stack.
Same way outgoing frame recieved from LWIP stack, my application will add
HSR tag and sent it to PC via hirschmann swith.

Modification:
#define CHECKSUM_GEN_IP 1
/*----- Value in opt.h for CHECKSUM_GEN_UDP: 1 -----*/
#define CHECKSUM_GEN_UDP 0
/*----- Value in opt.h for CHECKSUM_GEN_TCP: 1 -----*/
#define CHECKSUM_GEN_TCP 1
/*----- Value in opt.h for CHECKSUM_GEN_ICMP: 1 -----*/
#define CHECKSUM_GEN_ICMP 1

Modification for receiving part:in ethernetif.c
file:function:low_level_input();
receive and do following
/*removing of hsr tag*/
        memcpy( (uint8_t*)(g_u8_HSR_Rcvd_Frame + j),
(uint8_t*)((uint8_t*)p->payload + k), 12);
        k=18;
        j=12;
        memcpy( (uint8_t*)(g_u8_HSR_Rcvd_Frame + j),
(uint8_t*)((uint8_t*)p->payload + k), (len - 18)); __nop();
        __nop();
        __nop();
        memcpy( (uint8_t*)((uint8_t*)p->payload),
(uint8_t*)((uint8_t*)g_u8_HSR_Rcvd_Frame), len);

/*send for further processing */



Modification for transmission part:in ethernetif.c
file:function:low_level_output();
/*adding of hsr tag*/
                memcpy( (uint8_t*)((uint8_t*)g_u8_Transmt_Frame),
(uint8_t*)((uint8_t*)p->payload), 12);
                g_u8_Transmt_Frame[12] = 0x89;
                g_u8_Transmt_Frame[13] = 0x2f;
                g_u8_Transmt_Frame[14] = 0x00;
                g_u8_Transmt_Frame[15] = ((p->len) + 6);
                g_u8_Transmt_Frame[16] = (uint8_t)(g_32_seq_counter & 0xFF00) >> 8;
                g_u8_Transmt_Frame[17] = (uint8_t)(g_32_seq_counter & 0x00FF);
k =18;
j=12;
memcpy( (uint8_t*)((uint8_t*)&g_u8_Transmt_Frame[18]),
(uint8_t*)((uint8_t*)p->payload + j), ((p->len)- 12));
__nop();
__nop();
__nop();
memcpy( (uint8_t*)((uint8_t*)p->payload),
(uint8_t*)((uint8_t*)g_u8_Transmt_Frame), ((p->len)+6));
and transmit


with above modification i am able to ping properly through PC via hirschmann
switch.
but not able to connect to modscan. (modbus message timeout occurs. attached
wireshark report)
when i stop debugg i see progam is stuck as mention in first post.
Regard,
Vrund




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

_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users
Reply | Threaded
Open this post in threaded view
|

Re: Scan through the heap searching for a free block that is big enough, beginning with the lowest free block.

Sergio R. Caprile
In reply to this post by Sergio R. Caprile
If you decide to generate checksums on lwIP, you MUST tell the
controller not to generate them.

You must check arg and newpcb in your tcp_accept() callback, follow the
examples.
Your tcpecho source is different from what I can see on lwIP git. I
won't check further.
I won't check the rest of your coding, particularly because you are
copying memory to places I don't know where they are and to whom they
belong; lest can I know if it fits.

Make sure your modifications to the working server (as you said it
works) happen on a well paced and controlled fashion, in order to make
it easier for you to discover where you break it.


_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users
Reply | Threaded
Open this post in threaded view
|

Re: Scan through the heap searching for a free block that is big enough, beginning with the lowest free block.

vrnud
Hi.

Thanks for reply.

In noraml case (without any addition of extra  bytes)I don't have problem.
Complete application is running very fine.

Forget about the previous addition that I have done in the code.

Problem is that I need to add and remove 6 bytes hsr tag in the frame.

Frame format is attached.

And I don't know where and how to implement this part in code??

Kindly help me to achieve this.



Regards
Vrund 

On Fri 29 Mar, 2019, 7:50 PM Sergio R. Caprile, <[hidden email]> wrote:
If you decide to generate checksums on lwIP, you MUST tell the
controller not to generate them.

You must check arg and newpcb in your tcp_accept() callback, follow the
examples.
Your tcpecho source is different from what I can see on lwIP git. I
won't check further.
I won't check the rest of your coding, particularly because you are
copying memory to places I don't know where they are and to whom they
belong; lest can I know if it fits.

Make sure your modifications to the working server (as you said it
works) happen on a well paced and controlled fashion, in order to make
it easier for you to discover where you break it.


_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users

_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users

img_en_frame_hsr_en.png (222K) Download Attachment