LwIP PCBs reset

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

LwIP PCBs reset

Amena El Homsi
Hello,

After disconnecting from an AP I have to reset the PCBs pools. If I did not do that and I reconnect to the AP and If I tried to bind a socket to a port that I already used in the previous connection, binding fails (port in use).

To reset the PCBs I have to call memp_init() with MEMP_MEM_INIT set to 1, right?

When I call memp_init(), even if I did not set MEMP_MEM_INIT to 1, DHCP fails.

According to wireshark capture, we send DHCP discover packet, the AP replies with the Offer, however we didn't enter dhcp_handle_offer() function.

Do you have any idea what is happening?

--

Amena El-Homsi
Computer & Communication Engineer
Dipl. Eng,  M.S.

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

Re: LwIP PCBs reset

goldsimon@gmx.de


Amena El Homsi wrote:
>Hello,
>
>After disconnecting from an AP I have to reset the PCBs pools. If I did
>not
>do that and I reconnect to the AP and If I tried to bind a socket to a
>port
>that I already used in the previous connection, binding fails (port in
>use).

That should not be required. Why don't you just close all connections instead of such a hack? You might have SO_REUSE or something like that...

>
>To reset the PCBs I have to call memp_init() with MEMP_MEM_INIT set to
>1,
>right?

No, no, no! Hack! Don't do that. And just so that everyone reading your post knows this is wrong, I *had* to answer this :-)

>
>When I call memp_init(), even if I did not set MEMP_MEM_INIT to 1, DHCP
>fails.

Ok, that's strange, but your problem lies somewhere else. Just "randomly" wiping some memory (memp_init) might make your problems go away for now, but others will arise!

>
>According to wireshark capture, we send DHCP discover packet, the AP
>replies with the Offer, however we didn't enter dhcp_handle_offer()
>function.
>
>Do you have any idea what is happening?

No.

Regards,
Simon

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

Re: LwIP PCBs reset

Amena El Homsi
Hi, thanks for your reply, please check my answers below.

On Thu, Jan 9, 2020 at 6:35 PM goldsimon <[hidden email]> wrote:


Amena El Homsi wrote:
>Hello,
>
>After disconnecting from an AP I have to reset the PCBs pools. If I did
>not
>do that and I reconnect to the AP and If I tried to bind a socket to a
>port
>that I already used in the previous connection, binding fails (port in
>use).

That should not be required. Why don't you just close all connections instead of such a hack? You might have SO_REUSE or something like that...

 Sometimes the AP disassociates the STA, it doesn't make sense to go over the connections and reset them (it is useless to send tcp fin segment or dhcp release packet).
That's why we need a way to reset everything in lwip. Currently I am calling lwip_init() everytime I associate to an AP and after that I set the netif and start network connections.
what's wrong on this?
>
>To reset the PCBs I have to call memp_init() with MEMP_MEM_INIT set to
>1,
>right?

No, no, no! Hack! Don't do that. And just so that everyone reading your post knows this is wrong, I *had* to answer this :-)
 why is MEMP_MEM_INIT added to opt.h if we should not use it?! 
If I did not set to 1, PCBs will not be reset if we disconnected from the AP.

So there is no way to reset everything, I have to go over the active connections and memset the PCB structures, without calling lwip_init()?

>
>When I call memp_init(), even if I did not set MEMP_MEM_INIT to 1, DHCP
>fails.

Ok, that's strange, but your problem lies somewhere else. Just "randomly" wiping some memory (memp_init) might make your problems go away for now, but others will arise!
 This is happening because dhcp_dec_pcb_refcount() is not called unless dhcp_stop() is called. 
After disconnecting, I am calling netif_remove(), I thought it is enough because it doesn't make sense to send DHCP release packet if we already disassociated from the AP.
Anyway, the problem is solved by calling dhcp_stop() and then netif_remove().

>
>According to wireshark capture, we send DHCP discover packet, the AP
>replies with the Offer, however we didn't enter dhcp_handle_offer()
>function.
>
>Do you have any idea what is happening?

No.

Regards,
Simon

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


--

Amena El-Homsi
Computer & Communication Engineer
Dipl. Eng,  M.S.

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

Re: LwIP PCBs reset

goldsimon@gmx.de
Am 13.01.2020 um 09:27 schrieb Amena El Homsi:

> Hi, thanks for your reply, please check my answers below.
>
> On Thu, Jan 9, 2020 at 6:35 PM goldsimon <[hidden email]
> <mailto:[hidden email]>> wrote:
>
>
>
>     Amena El Homsi wrote:
>      >Hello,
>      >
>      >After disconnecting from an AP I have to reset the PCBs pools. If
>     I did
>      >not
>      >do that and I reconnect to the AP and If I tried to bind a socket to a
>      >port
>      >that I already used in the previous connection, binding fails (port in
>      >use).
>
>     That should not be required. Why don't you just close all
>     connections instead of such a hack? You might have SO_REUSE or
>     something like that...
>
> Sometimes the AP disassociates the STA, it doesn't make sense to go over
> the connections and reset them (it is useless to send tcp fin segment or
> dhcp release packet).
> That's why we need a way to reset everything in lwip. Currently I am
> calling lwip_init() everytime I associate to an AP and after that I set
> the netif and start network connections.
> what's wrong on this?

Calling lwip_init() won't work. It's not meant to. You cannot just call
an init function at runtime and expect it to work.

>
>      >
>      >To reset the PCBs I have to call memp_init() with MEMP_MEM_INIT set to
>      >1,
>      >right?
>
>     No, no, no! Hack! Don't do that. And just so that everyone reading
>     your post knows this is wrong, I *had* to answer this :-)
>
>   why is MEMP_MEM_INIT added to opt.h if we should not use it?!
> If I did not set to 1, PCBs will not be reset if we disconnected from
> the AP.
>
> So there is no way to reset everything, I have to go over the active
> connections and memset the PCB structures, without calling lwip_init()?

Ehrm, not MEMP_MEM_INIT=1 is wrong, but calling memp_init() after the
init phase is wrong. (BTW, with lwip_init(), calling memp_init()
yourself is always wrong as it is called for you)

>
>
>      >
>      >When I call memp_init(), even if I did not set MEMP_MEM_INIT to 1,
>     DHCP
>      >fails.
>
>     Ok, that's strange, but your problem lies somewhere else. Just
>     "randomly" wiping some memory (memp_init) might make your problems
>     go away for now, but others will arise!
>
>   This is happening because dhcp_dec_pcb_refcount() is not called unless
> dhcp_stop() is called.
> After disconnecting, I am calling netif_remove(), I thought it is enough
> because it doesn't make sense to send DHCP release packet if we already
> disassociated from the AP.
> Anyway, the problem is solved by calling dhcp_stop() and then
> netif_remove().

So the actual bug is that netif_remove() doesn't call dhcp_stop() if
DHCP is running? That might be worth a bug report...

I'm not sure I get the rest of your problem though.

Regads,
Simon

>
>
>      >
>      >According to wireshark capture, we send DHCP discover packet, the AP
>      >replies with the Offer, however we didn't enter dhcp_handle_offer()
>      >function.
>      >
>      >Do you have any idea what is happening?
>
>     No.
>
>     Regards,
>     Simon
>
>     _______________________________________________
>     lwip-users mailing list
>     [hidden email] <mailto:[hidden email]>
>     https://lists.nongnu.org/mailman/listinfo/lwip-users
>
>
>
> --
>
> Amena El-Homsi
> Computer & Communication Engineer
> Dipl. Eng,  M.S.
>
> _______________________________________________
> 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