LwIP and a TFTP client
I've run into an interesting problem and curious if anyone knows a solution. I am adding TFTP support to an amateur radio project (soon to be published as open source). All the other code is based on LWIPs netconn API and I want the TFTP code to use netconn as well. Almost all the embedded LWIP examples I can find are for a TFTP server, not a client and all seem to be the native API too. Undeterred I'm off writing my own, but I've run into what seems a fundamental incompatibility between the TFTP protocol and how I understand basic IP comms work!
The weird part about TFTP is that while the client sends a UDP packet from it's "upper" port to the well know TFTP port on the server (69), for a read request, by spec the TFTP server responds not from its well-known port, but a new random upper port! With LWIP (and this seems normal and correct), if you set up a connection to another device and it's port, only replies back from that port come back to you. A packet coming back from a different port number would be considered another connection. LwIP (I feel correctly) ignores the packet coming back from the TFTP server and of course things don't go well after that.
Just to make sure I understood the issue, I was able to force my particular TFTP server to respond on a specific port and then I cheated and over-wrote the netconn structs pcb.udp->remote_port value to the same thing and comms work. That isn't a real solution, but just a check to make sure I wasn't off on a tangent. The unfortunate bit is I clearly have no idea ahead of time what the new port value is going to be ahead of that first data packet.
Going full raw mode would mess up all my other code working OK using netconn, so kinda stuck. There does seem to be an option called NETCONN_RAW in the netconn_new() call and when looking at some other netconn calls they mention the portid being ignored if in "raw mode". However, when I do searches on NETCONN_RAW even Google has trouble finding anything! I tried following it in the LWIP source and quickly got lost.
Has anyone run into this and found an elegant way around this? Not looking for code drops, just pointers if anyone has them.
Thanks in advance.
will
