Re: [lwip-users] Can you connect a MQTT client directly from a PPPoS status callback?
Hi Freddie, On Thu, May 16, 2019 at 10:09:49PM +0200, Freddie Chopin wrote: > On Thu, 2019-05-16 at 21:28 +0200, Sylvain Rochet wrote: > > Unless you are calling ppp_close() from a module, which I highly > > doubt, > > it is safe because other triggers are only rx packet or timeouts. > > Forgive my ignorance, but what is a "module" in the lwIP world? (; I just used module because this is what was previously used. But this is basically any function that can't be re-entered. > Generally closing/disconnection are not that much important - when the > PPPoS dies I guess MQTT will die by itself anyway, that's why my main > concern is mqtt_client_connect(). > > Let's say I would try to do it directly from the callback - it there > anything I could check to tell with confidence that this was wrong or > ok? As usual with locks, re-entrancy, shared variables, shared memory, or such. Some tools (e.g. coverity, coccinelle) can help checking that it looks right but until now it is left to poor humans to check that it is actually right. For PPP callback, apart from ppp_close, it is safe because it can only be called on the RX packet path or from timeouts, where having anything else in the call stack than rx packet handler and timeout handler from main() or tcpip thread is highly impossible. So you either have to trust me, or to check yourself all possible call stack leading to PPP callback being called. Luckily there are only a few places where the callback is actually called and diving into all the possible call stack is not a combinatorial explosion. Basically, all possible call stack are: ppp_close() pcb->link_status_cb() ~timeout-handler~ pppoe_timeout() pppoe_abort_connect() ppp_link_failed() pcb->link_status_cb() ~rx-packet-handler~ ~udp-recv-callback~ pppol2tp_input(); pppol2tp_dispatch_control_packet() pppol2tp_abort_connect() ppp_link_failed() pcb->link_status_cb() ~timeout-handler~ pppol2tp_timeout() pppol2tp_abort_connect() ppp_link_failed() pcb->link_status_cb() ppp_close() ppp_link_terminated() pcb->link_cb->disconnect() -> pppos_disconnect() or pppoe_disconnect() or pppol2tp_disconnect() ppp_link_end() pcb->link_status_cb() ppp_close() lcp_lowerdown() fsm_lowerdown() f->callbacks->down() -> lcp_down() link_down() upper_layers_down() protp->close -> lcp_close() lcp_finished() link_terminated() ppp_link_terminated() pcb->link_cb->disconnect() -> pppos_disconnect() or pppoe_disconnect() or pppol2tp_disconnect() ppp_link_end() pcb->link_status_cb() ~rx-packet-handler~ ppp_input() lcp_input() fsm_input() fsm_rtermack() f->callbacks->finished() -> lcp_finished() link_terminated() ppp_link_terminated() pcb->link_cb->disconnect() -> pppos_disconnect() or pppoe_disconnect() or pppol2tp_disconnect() ppp_link_end() pcb->link_status_cb() ~rx-packet-handler~ ppp_input() lcp_input() fsm_input() fsm_rtermreq() or fsm_rtermack() f->callbacks->down() -> lcp_down() link_down() upper_layers_down() protp->close -> lcp_close() lcp_finished() link_terminated() ppp_link_terminated() pcb->link_cb->disconnect() -> pppos_disconnect() or pppoe_disconnect() or pppol2tp_disconnect() ppp_link_end() pcb->link_status_cb() ~timeout-handler~ LcpEchoTimeout() LcpEchoCheck() LcpSendEchoRequest() LcpLinkFailure() lcp_close() lcp_finished() link_terminated() ppp_link_terminated() pcb->link_cb->disconnect() -> pppos_disconnect() or pppoe_disconnect() or pppol2tp_disconnect() ppp_link_end() pcb->link_status_cb() ~rx-packet-handler~ ppp_input() protp->input() -> ipcp_input() fsm_input() fsm_rconfreq() or fsm_rconfack() f->callbacks->up() -> ipcp_up() sifup() pcb->link_status_cb() ~rx-packet-handler~ ppp_input() protp->input() -> ipv6cp_input() fsm_input() fsm_rconfreq() or fsm_rconfack() f->callbacks->up() -> ipv6cp_up() sif6up() pcb->link_status_cb() Sylvain signature.asc Description: Digital signature ___ lwip-users mailing list lwip-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/lwip-users
Re: [lwip-users] Can you connect a MQTT client directly from a PPPoS status callback?
On Thu, 2019-05-16 at 21:28 +0200, Sylvain Rochet wrote: > Unless you are calling ppp_close() from a module, which I highly > doubt, > it is safe because other triggers are only rx packet or timeouts. Forgive my ignorance, but what is a "module" in the lwIP world? (; Generally closing/disconnection are not that much important - when the PPPoS dies I guess MQTT will die by itself anyway, that's why my main concern is mqtt_client_connect(). Let's say I would try to do it directly from the callback - it there anything I could check to tell with confidence that this was wrong or ok? Regards, FCh ___ lwip-users mailing list lwip-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/lwip-users
Re: [lwip-users] Can you connect a MQTT client directly from a PPPoS status callback?
Hi, On Thu, May 16, 2019 at 07:51:45PM +0200, goldsi...@gmx.de wrote: > Am 16.05.2019 um 18:31 schrieb Freddie Chopin: > >Hello Devanand! > > > >On Thu, 2019-05-16 at 20:41 +0530, Devanand Biradar wrote: > >>I have connected to mosquito cloud using Lwip via MQTT. > >>Using PPPOS with GSM module. > > > >Yes, I know this can be done, because I already have done it and it > >works (; But now I would like to make it more error-proof and > >responsive - my code so far is just a dirty proof-of-concept using > >stupid things like global flags and polling. > > > >So what I'm asking is this - is it safe to have code like this: > > It's probably not safe as you risk calling back into modules that are > not reentrant. I don't know this for sure, just as a saftey measurement... Hummm, I guess it's safe, I doubt PPP status callback can actually be called from a module. Looking at the code it can only be called: - Right from ppp_close(), only if the session is already dead; - If the lower level link failed to setup, i.e. timeout. in ppp_link_failed(); - If the link is shutting down, i.e. timeout or LCP "Term" packet received in ppp_link_end(); - If the link is UP, after a packet is received, in sifup() and sif6up(). Unless you are calling ppp_close() from a module, which I highly doubt, it is safe because other triggers are only rx packet or timeouts. Sylvain signature.asc Description: Digital signature ___ lwip-users mailing list lwip-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/lwip-users
Re: [lwip-users] Can you connect a MQTT client directly from a PPPoS status callback?
Am 16.05.2019 um 20:56 schrieb Freddie Chopin: On Thu, 2019-05-16 at 19:51 +0200, goldsi...@gmx.de wrote: It's probably not safe as you risk calling back into modules that are not reentrant. I don't know this for sure, just as a saftey measurement... Yes, this is what I was afraid of. And it shows you're actually asking the correct question :-) Maybe you could use tcpip_trycallback() from that callback? I assume you are talking about tcpip_try_callback() right? Yeah, sorry. Only thing I could find about tcpip_trycallback() is this: tcpip_trycallback() was renamed to tcpip_callbackmsg_trycallback() to avoid confusion with tcpip_try_callback() It seems that the name was (and still is) very confusing (; Hrmpf :( Anyway tcpip_try_callback() does indeed look as what I could use for my purpose, so thanks for info! I'll try that tomorrow, however I'm not sure how will I be able to deal with an error when posting the callback (or allocating the message) will not be possible. Yeah, well, but what would you do inside that callback when mqtt_connect() (or whatever) would return such an out-of-resources error? In such an embedded system, you just have to implement guards to either set the red lamp or keep retrying... Probably in a state-machine-like cyclic task... but that's far beyond what lwIP provides. Regards, Simon The other function - tcpip_callbackmsg_trycallback() - also looks like I could use it, one possible failure point less. Regards, FCh ___ 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] Can you connect a MQTT client directly from a PPPoS status callback?
On Thu, 2019-05-16 at 19:51 +0200, goldsi...@gmx.de wrote: > It's probably not safe as you risk calling back into modules that are > not reentrant. I don't know this for sure, just as a saftey > measurement... Yes, this is what I was afraid of. > Maybe you could use tcpip_trycallback() from that callback? I assume you are talking about tcpip_try_callback() right? Only thing I could find about tcpip_trycallback() is this: tcpip_trycallback() was renamed to tcpip_callbackmsg_trycallback() to avoid confusion with tcpip_try_callback() It seems that the name was (and still is) very confusing (; Anyway tcpip_try_callback() does indeed look as what I could use for my purpose, so thanks for info! I'll try that tomorrow, however I'm not sure how will I be able to deal with an error when posting the callback (or allocating the message) will not be possible. The other function - tcpip_callbackmsg_trycallback() - also looks like I could use it, one possible failure point less. Regards, FCh ___ lwip-users mailing list lwip-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/lwip-users
Re: [lwip-users] Can you connect a MQTT client directly from a PPPoS status callback?
Am 16.05.2019 um 18:31 schrieb Freddie Chopin: Hello Devanand! On Thu, 2019-05-16 at 20:41 +0530, Devanand Biradar wrote: I have connected to mosquito cloud using Lwip via MQTT. Using PPPOS with GSM module. Yes, I know this can be done, because I already have done it and it works (; But now I would like to make it more error-proof and responsive - my code so far is just a dirty proof-of-concept using stupid things like global flags and polling. So what I'm asking is this - is it safe to have code like this: It's probably not safe as you risk calling back into modules that are not reentrant. I don't know this for sure, just as a saftey measurement... Maybe you could use tcpip_trycallback() from that callback? Regards, Simon // this function is registered via pppapi_pppos_create(...) // it is executed from within lwIP's TCP/IP thread void pppLinkStatus(ppp_pcb* pcb, int errorCode, void* context) { if (errorCode == PPPERR_NONE) // PPP is connected successfully? mqtt_client_connect(...); else // PPP connection is lost mqtt_client_disconnect(...); } The alternative is - for example - to call mqtt_client_connect(...) until it succeeds (including the last phase done in the MQTT's connect callback) periodically, for example every 10 seconds. However - if possible - I would prefer the first version, more "event based" and not requiring a thread that would have to monitor that. Regards, FCh ___ 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] Can you connect a MQTT client directly from a PPPoS status callback?
Hello Devanand! On Thu, 2019-05-16 at 20:41 +0530, Devanand Biradar wrote: > I have connected to mosquito cloud using Lwip via MQTT. > Using PPPOS with GSM module. Yes, I know this can be done, because I already have done it and it works (; But now I would like to make it more error-proof and responsive - my code so far is just a dirty proof-of-concept using stupid things like global flags and polling. So what I'm asking is this - is it safe to have code like this: // this function is registered via pppapi_pppos_create(...) // it is executed from within lwIP's TCP/IP thread void pppLinkStatus(ppp_pcb* pcb, int errorCode, void* context) { if (errorCode == PPPERR_NONE) // PPP is connected successfully? mqtt_client_connect(...); else // PPP connection is lost mqtt_client_disconnect(...); } The alternative is - for example - to call mqtt_client_connect(...) until it succeeds (including the last phase done in the MQTT's connect callback) periodically, for example every 10 seconds. However - if possible - I would prefer the first version, more "event based" and not requiring a thread that would have to monitor that. Regards, FCh ___ lwip-users mailing list lwip-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/lwip-users
[lwip-users] Multiple instance of lwip on Windows
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
Re: [lwip-users] Netconn API Server Mode Connection Drope Detection
yep, i can detecting that ERR_CLSD error code. After that i have to go back netconn_accept function. i couldn't this. Also my system has RTOS. It doesn't turns that task. tirmalabenikasibeni , 16 May 2019 Per, 18:07 tarihinde şunu yazdı: > netconn_receive must return ERR_CLSD when connection closed. Check your > error > code in every loop. > > > > -- > 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 > -- *Mesut Cömert* Elektrik Elektronik Mühendisi | Electrical Electronics Engineer ___ lwip-users mailing list lwip-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/lwip-users
Re: [lwip-users] Can you connect a MQTT client directly from a PPPoS status callback?
I have connected to mosquito cloud using Lwip via MQTT. Using PPPOS with GSM module. On Thu, 16 May 2019, 19:55 Freddie Chopin, wrote: > Hi! > > I'm working on an open-source demo project in which there is a MQTT > client talking via PPPoS to a GSM modem. The project also has a RTOS, > so I have threads and synchronization objects. > > I'm wondering whether I could connect a MQTT client to a broker > directly from a PPPoS status callback? The scenario I have in mind is > that when PPPoS connection is established then I would like to > immediately connect to the MQTT broker. Is that a viable idea, or > should I avoid calling such high-level functions as > mqtt_client_connect() from such low-level places as status callbacks of > netifs? The problem I'm seeing is that mqtt_client_connect() requires > you to hold a TCP/IP core lock, which is already held when the PPPoS > callback is executed. I can make this lock recursive, not a problem (at > least for me, but I doubt lwIP would care about such a change), but > then I'm wondering whether there's a chance for a deadlock or data > corruption in such a scenario... > > Thanks in advance for any input! > > Regards, > FCh > > > ___ > 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] Netconn API Server Mode Connection Drope Detection
netconn_receive must return ERR_CLSD when connection closed. Check your error code in every loop. -- 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] Can you connect a MQTT client directly from a PPPoS status callback?
Hi! I'm working on an open-source demo project in which there is a MQTT client talking via PPPoS to a GSM modem. The project also has a RTOS, so I have threads and synchronization objects. I'm wondering whether I could connect a MQTT client to a broker directly from a PPPoS status callback? The scenario I have in mind is that when PPPoS connection is established then I would like to immediately connect to the MQTT broker. Is that a viable idea, or should I avoid calling such high-level functions as mqtt_client_connect() from such low-level places as status callbacks of netifs? The problem I'm seeing is that mqtt_client_connect() requires you to hold a TCP/IP core lock, which is already held when the PPPoS callback is executed. I can make this lock recursive, not a problem (at least for me, but I doubt lwIP would care about such a change), but then I'm wondering whether there's a chance for a deadlock or data corruption in such a scenario... Thanks in advance for any input! Regards, FCh ___ lwip-users mailing list lwip-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/lwip-users
Re: [lwip-users] Netconn API Server Mode Connection Drope Detection
I'm using RAW, not Netconn... I have to poll my PHY for this... about once every 10,000 loops. Read the manual for your PHY... several different conditions you can detect... you have to access the status register IIRC. -- Stephen Cowell Project Manager/Engineer Plasmability LLC On 5/16/2019 1:09 AM, Mesut Cömert wrote: Hi, guys. I have using Netconn API on my system. I want to work as server mode. I downloaded and examined netconn server examples and I set up my system. I connect to my device with Hercules TCP Client section. First section is that i connect to my device, send to message and receive message then system is closed. This section to let me send to a message and receive. Second option is that i connect to my device, send message and receive over and over again. but when i pressed disconnect button so i can not to connect my device again. Because device has waiting in receive function. I want to detect connection drop in receive function. how can i solve this problem, can you help me? -- *Mesut Cömert* Elektrik Elektronik Mühendisi | Electrical Electronics Engineer ___ 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] Netconn API Server Mode Connection Drope Detection
Hi, guys. I have using Netconn API on my system. I want to work as server mode. I downloaded and examined netconn server examples and I set up my system. I connect to my device with Hercules TCP Client section. First section is that i connect to my device, send to message and receive message then system is closed. This section to let me send to a message and receive. Second option is that i connect to my device, send message and receive over and over again. but when i pressed disconnect button so i can not to connect my device again. Because device has waiting in receive function. I want to detect connection drop in receive function. how can i solve this problem, can you help me? -- *Mesut Cömert* Elektrik Elektronik Mühendisi | Electrical Electronics Engineer ___ lwip-users mailing list lwip-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/lwip-users