lwip-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lwip-users] Choosing an API and using callbacks


From: Scott Miller
Subject: [lwip-users] Choosing an API and using callbacks
Date: Wed, 1 Mar 2023 16:15:23 -0800
User-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.8.0

Hi all,

I've got some questions about which API I ought to be using and how to properly receive data when using callbacks. Examples of the netconn API seem to be scarce.

Here's my situation: I'm redesigning some embedded projects that run under FreeRTOS and formerly used the SiLabs WGM110 WiFi module. The WGM110 has a version of lwIP running on the module and it provides a binary interface via UART or SPI to the host. I wrote a host-side driver for it that provides an API that follows the Berkeley Sockets API, more or less, at least for the sending side. The receive side has always been done through callbacks. The application code (for example, my HTTP client) registers a callback for a TCP connection and the callback is called from the network task when data has been received or when there's an error.

The WGM110 has been discontinued and I'm switching to the ATWINC3400, which is roughly similar but its internal network stack is too limited and I want to add support for wired Ethernet anyway, so I'm running the WINC3400 in bypass mode and running lwIP on the host.

The netconn callback seems similar to my own callback scheme, but the critical difference is that in my implementation the received packet is already available and a pointer to the buffer is passed in to the callback. It's zero-copy in a limited sense - the callback has to handle the packet immediately because it exists in one big DMA buffer. If the packet needs to be kept around it has to be copied out.

The issue I'm running into is that it looks like the callbacks for netconn happen in the TCP/IP task context, where you're not supposed to use netconn API calls. Is there a safe way to receive the data from within the callback? Can I mix raw API calls and use tcp_recv() with the PCB from the netconn struct? Should I be skipping netconn entirely? Do I need to have another task handle the recv calls and just pass it notifications from the lwIP callback?

My next concern is that at some point I'm going to have to implement TLS and I don't have a good grasp yet of how that works in lwIP. The WGM110 had very limited support - it could handle a single outbound TLS connection and didn't support inbound at all. I see that the altcp API seems to be the way to go. Should I be using altcp everywhere that might potentially need TLS? Previously all I needed to do was set a single flag to enable TLS.

Are there any good, clear example projects I should be looking to as a guide?

Thanks,

Scott



reply via email to

[Prev in Thread] Current Thread [Next in Thread]