Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIRE136] Network redesign #234

Draft
wants to merge 79 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
960d8bc
reimplementing the ethernet drivers
andreagilardoni Dec 28, 2023
452accf
added library containing abstract network stack classes
andreagilardoni Dec 28, 2023
30725ad
reimplementing the tcp client with the aim of solving issues
andreagilardoni Dec 28, 2023
a0666af
cleaning up
andreagilardoni Dec 28, 2023
4c0123f
redefinition of network Interface classes
andreagilardoni Dec 28, 2023
2637cdf
restructuring CLwipIf singleton class
andreagilardoni Dec 28, 2023
216e3aa
rewriting CNetif base class
andreagilardoni Dec 28, 2023
28f9199
rewriting CEth CwifiStation and CSoftAP classes
andreagilardoni Dec 28, 2023
d40a06a
added possibility to pass a std::function to esphosted callbacks
andreagilardoni Dec 29, 2023
58c2860
defined Ethernet driver and interface instance
andreagilardoni Dec 29, 2023
3850758
removed unused endif
andreagilardoni Dec 29, 2023
9784bac
commented netif stats
andreagilardoni Dec 29, 2023
f5633d6
defined network interface abstrac class
andreagilardoni Dec 29, 2023
40772d1
fixing lwipClient
andreagilardoni Dec 29, 2023
cef42da
fixing imports and variable names
andreagilardoni Dec 29, 2023
e76ded7
cleaning CNetIf classes definition
andreagilardoni Dec 29, 2023
d39a90a
fixing class implementation and making it able to compile
andreagilardoni Dec 29, 2023
a28de2d
defined tmp utils library
andreagilardoni Dec 29, 2023
460a0d5
reimplementing wifi handle
andreagilardoni Dec 29, 2023
ae29df7
commnting code not yet ready to be compiled
andreagilardoni Dec 29, 2023
9a871ef
deleted lwip tcp wrapper
andreagilardoni Jan 2, 2024
0b6dd35
implemented netowrk interfaces specific clients
andreagilardoni Jan 2, 2024
f911f67
defined Wifi global variable for network interface
andreagilardoni Jan 2, 2024
4c86ebf
added scanforap method
andreagilardoni Jan 2, 2024
b371331
added comment
andreagilardoni Jan 4, 2024
1c58899
reimplementing Server class with ethernet and wifi subclasses
andreagilardoni Jan 4, 2024
ed6886d
fixing bug of missing nullptr check
andreagilardoni Jan 4, 2024
10a05bd
removed unused types
andreagilardoni Jan 4, 2024
42063d1
minor changes on file
andreagilardoni Jan 4, 2024
e41294a
Revert "defined Wifi global variable for network interface"
andreagilardoni Jan 5, 2024
f20a258
Revert "reimplementing wifi handle"
andreagilardoni Jan 5, 2024
552a153
applying a codestyle
andreagilardoni Jan 5, 2024
d239597
fixing EthernetServer class
andreagilardoni Jan 8, 2024
6e6c837
making WiFi class compile
andreagilardoni Jan 8, 2024
ea4ae60
fixing implementation of client and server
andreagilardoni Jan 8, 2024
87ae27a
fixing global definitions of WiFi interfaces
andreagilardoni Jan 8, 2024
0c210ee
making UDP derived classes compile
andreagilardoni Jan 8, 2024
2c10e0e
fixing retrocompatibility issues
andreagilardoni Jan 8, 2024
4cb8171
dealing with retrocompatibility
andreagilardoni Jan 8, 2024
c9ed50c
solving FIXME
andreagilardoni Jan 9, 2024
719e63f
fixing dns related functions
andreagilardoni Jan 9, 2024
58f9561
CNetIf - added config method to apply new static IP settings
JAndrassy Dec 14, 2023
45c85f3
adapting cherry pick
andreagilardoni Jan 9, 2024
664fc69
moving funtion in correct section in file
andreagilardoni Jan 9, 2024
3a1e29d
added dhcp_inform call
andreagilardoni Jan 9, 2024
b5eb21b
fixing compilation issue
andreagilardoni Jan 10, 2024
ae01d58
removing FIXME
andreagilardoni Jan 10, 2024
f8507fa
restoring CWiFi methods to extract scanned access point info
andreagilardoni Jan 10, 2024
e0ce22c
removing lwipMem files
andreagilardoni Jan 10, 2024
4a1e9d4
moving free_pbuf_chain to an external file in order to be shared from…
andreagilardoni Jan 10, 2024
4980778
moving lwipTypes udp_struct into udp file
andreagilardoni Jan 10, 2024
56c1d07
readapting udp class
andreagilardoni Jan 10, 2024
e1af45e
improving task syncrhonization between timer and main context
andreagilardoni Jan 12, 2024
0809792
fixing dns resolution bug
andreagilardoni Jan 12, 2024
9734322
cleaning code
andreagilardoni Jan 12, 2024
c3ba277
fine tuning lwip stack and compiling it
andreagilardoni Jan 12, 2024
66943b8
adding dns resolution with lwip example
andreagilardoni Jan 12, 2024
9cb6f55
enablig execution of network stack in interrrupt context]
andreagilardoni Jan 12, 2024
99ca0fa
added disconnect and link status for retrocompatibility
andreagilardoni Jan 17, 2024
7e88a57
fixing lwip server
andreagilardoni Jan 19, 2024
88f5091
blocking begin call on dhcp acquisition
andreagilardoni Jan 19, 2024
0f430c5
Making it possible to call multiple time the begin function on an int…
andreagilardoni Jan 22, 2024
ec3cba5
making netif compatible with connection handler usage
andreagilardoni Jan 22, 2024
e56d9f9
fixing return status of begin
andreagilardoni Jan 23, 2024
1ac341d
adding test files for lwipwrapper WIP
andreagilardoni Jan 23, 2024
0207e39
fixing connection issue on Ethernet and Wifi Client when host is passed
andreagilardoni Jan 23, 2024
3bbaccd
exporting Network stack synchronization to lwipClient
andreagilardoni Jan 23, 2024
c595cc0
fixing return codes
andreagilardoni Jan 23, 2024
ec5ea83
deleting pbuf when partially consumed
andreagilardoni Jan 23, 2024
564fcfc
Changed memory alignemnt according to renesas specifications
andreagilardoni Jan 24, 2024
6c5f0ea
improving examples
andreagilardoni Jan 24, 2024
6edeefe
setting dhcp acquired when dhcp server is informed of static ip
andreagilardoni Jan 24, 2024
896f7ca
improving performances of ssl client
andreagilardoni Jan 24, 2024
aa3c5a1
fixing counter overflow in tcp send
andreagilardoni Jan 24, 2024
9e05471
added tcp write example for tcp echo server
andreagilardoni Jan 25, 2024
e489e71
changing synchronization to timer disable
andreagilardoni Jan 26, 2024
e303948
improving write function to better handle memory errors and bigger bu…
andreagilardoni Jan 26, 2024
b58a521
making dns resolution to work automatically when interrupts are disabled
andreagilardoni Jan 26, 2024
c28b4bd
improving example
andreagilardoni Jan 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 70 additions & 16 deletions extras/net/lwipopts.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
* ATTENTION: This is required when using lwIP from more than one context! If
* you disable this, you must be sure what you are doing!
*/
#if !defined SYS_LIGHTWEIGHT_PROT
#ifndef SYS_LIGHTWEIGHT_PROT
#define SYS_LIGHTWEIGHT_PROT 0
#endif

Expand Down Expand Up @@ -129,7 +129,7 @@
* 2 byte alignment -> #define MEM_ALIGNMENT 2
*/
#ifndef MEM_ALIGNMENT
#define MEM_ALIGNMENT 4
#define MEM_ALIGNMENT 32
#endif

/**
Expand Down Expand Up @@ -277,7 +277,7 @@
* (requires the LWIP_RAW option)
*/
#ifndef MEMP_NUM_RAW_PCB
#define MEMP_NUM_RAW_PCB 0
#define MEMP_NUM_RAW_PCB 4
#endif

/**
Expand Down Expand Up @@ -318,7 +318,7 @@
* reassembly (whole packets, not fragments!)
*/
#ifndef MEMP_NUM_REASSDATA
#define MEMP_NUM_REASSDATA 0
#define MEMP_NUM_REASSDATA 5
#endif

/**
Expand All @@ -329,7 +329,7 @@
* where the packet is not yet sent when netif->output returns.
*/
#ifndef MEMP_NUM_FRAG_PBUF
#define MEMP_NUM_FRAG_PBUF 0
#define MEMP_NUM_FRAG_PBUF 15
#endif

/**
Expand All @@ -353,11 +353,18 @@
#endif

/**
* MEMP_NUM_SYS_TIMEOUT: the number of simulateously active timeouts.
* (requires NO_SYS==0)
* The number of sys timeouts used by the core stack (not apps)
* The default number of timeouts is calculated here for all enabled modules.
*/
#define LWIP_NUM_SYS_TIMEOUT_INTERNAL (LWIP_TCP + IP_REASSEMBLY + LWIP_ARP + (2*LWIP_DHCP) + LWIP_ACD + LWIP_IGMP + LWIP_DNS + PPP_NUM_TIMEOUTS + (LWIP_IPV6 * (1 + LWIP_IPV6_REASS + LWIP_IPV6_MLD + LWIP_IPV6_DHCP6)))

/**
* MEMP_NUM_SYS_TIMEOUT: the number of simultaneously active timeouts.
* The default number of timeouts is calculated here for all enabled modules.
* The formula expects settings to be either '0' or '1'.
*/
#ifndef MEMP_NUM_SYS_TIMEOUT
#define MEMP_NUM_SYS_TIMEOUT 6
#define MEMP_NUM_SYS_TIMEOUT LWIP_NUM_SYS_TIMEOUT_INTERNAL
#endif

/**
Expand Down Expand Up @@ -416,7 +423,11 @@
* PBUF_POOL_SIZE: the number of buffers in the pbuf pool.
*/
#ifndef PBUF_POOL_SIZE
#define PBUF_POOL_SIZE 4
#define PBUF_POOL_SIZE 16
#endif

#ifndef LWIP_SUPPORT_CUSTOM_PBUF
#define LWIP_SUPPORT_CUSTOM_PBUF 1
#endif

/**
Expand Down Expand Up @@ -549,16 +560,27 @@
* an upper limit on the MSS advertised by the remote host.
*/
#ifndef TCP_MSS
#define TCP_MSS 536
#define TCP_MSS 1420
#endif

/**
* TCP_CALCULATE_EFF_SEND_MSS: "The maximum size of a segment that TCP really
* sends, the 'effective send MSS,' MUST be the smaller of the send MSS (which
* reflects the available reassembly buffer size at the remote host) and the
* largest size permitted by the IP layer" (RFC 1122)
* Setting this to 1 enables code that checks TCP_MSS against the MTU of the
* netif used for a connection and limits the MSS if it would be too big otherwise.
*/
#ifndef TCP_CALCULATE_EFF_SEND_MSS
#define TCP_CALCULATE_EFF_SEND_MSS 1
#endif

/**
* TCP_SND_BUF: TCP sender buffer space (bytes).
* To achieve good performance, this should be at least 2 * TCP_MSS.
*/
#ifndef TCP_SND_BUF
#define TCP_SND_BUF 1500
#define TCP_SND_BUF (4 * TCP_MSS)
#endif

/**
Expand Down Expand Up @@ -596,7 +618,7 @@
* Define to 0 if your device is low on memory.
*/
#ifndef TCP_QUEUE_OOSEQ
#define TCP_QUEUE_OOSEQ 0
#define TCP_QUEUE_OOSEQ (LWIP_TCP)
#endif

/**
Expand Down Expand Up @@ -738,13 +760,45 @@
/**
* LWIP_DEBUG==1: Enable Debug.
*/

#define LWIP_DBG_MIN_LEVEL LWIP_DBG_LEVEL_ALL

#define LWIP_DEBUG 0

#define ETHARP_DEBUG LWIP_DBG_OFF
#define NETIF_DEBUG LWIP_DBG_OFF
#define DHCP_DEBUG LWIP_DBG_OFF
#define UDP_DEBUG LWIP_DBG_OFF
#define MEMP_DEBUG LWIP_DBG_OFF
#define MEM_DEBUG LWIP_DBG_OFF
#define PBUF_DEBUG LWIP_DBG_OFF
#define API_LIB_DEBUG LWIP_DBG_OFF
#define API_MSG_DEBUG LWIP_DBG_OFF
#define SOCKETS_DEBUG LWIP_DBG_OFF
#define ICMP_DEBUG LWIP_DBG_OFF
#define IGMP_DEBUG LWIP_DBG_OFF
#define INET_DEBUG LWIP_DBG_OFF
#define IP_DEBUG LWIP_DBG_OFF
#define IP_REASS_DEBUG LWIP_DBG_OFF
#define RAW_DEBUG LWIP_DBG_OFF
#define MEM_DEBUG LWIP_DBG_OFF
#define MEMP_DEBUG LWIP_DBG_OFF
#define SYS_DEBUG LWIP_DBG_OFF
#define TIMERS_DEBUG LWIP_DBG_OFF
#define TCP_DEBUG LWIP_DBG_OFF
#define TCP_INPUT_DEBUG LWIP_DBG_OFF
#define TCP_FR_DEBUG LWIP_DBG_OFF
#define TCP_RTO_DEBUG LWIP_DBG_OFF
#define TCP_CWND_DEBUG LWIP_DBG_OFF
#define TCP_WND_DEBUG LWIP_DBG_OFF
#define TCP_OUTPUT_DEBUG LWIP_DBG_OFF
#define TCP_RST_DEBUG LWIP_DBG_OFF
#define TCP_QLEN_DEBUG LWIP_DBG_OFF
#define UDP_DEBUG LWIP_DBG_OFF
#define TCPIP_DEBUG LWIP_DBG_OFF
#define SLIP_DEBUG LWIP_DBG_OFF
#define DHCP_DEBUG LWIP_DBG_OFF
#define AUTOIP_DEBUG LWIP_DBG_OFF
#define ACD_DEBUG LWIP_DBG_OFF
#define DNS_DEBUG LWIP_DBG_OFF
#define IP6_DEBUG LWIP_DBG_OFF
#define DHCP6_DEBUG LWIP_DBG_OFF
#endif

//#define LWIP_USE_EXTERNAL_MBEDTLS 1
3 changes: 2 additions & 1 deletion libraries/ESPhost/src/CEspCbks.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,14 @@


#include "CCtrlWrapper.h"
#include <functional>

#define RESPONSE_TABLE_DIM (CTRL_RESP_MAX - CTRL_RESP_BASE)
#define EVENT_TABLE_DIM (CTRL_EVENT_MAX - CTRL_EVENT_BASE)
#define TOTAL_TABLE_DIM RESPONSE_TABLE_DIM + EVENT_TABLE_DIM


using EspCallback_f = int (*)(CCtrlMsgWrapper *resp);
using EspCallback_f = std::function<int(CCtrlMsgWrapper *resp)>;



Expand Down
207 changes: 0 additions & 207 deletions libraries/Ethernet/src/Ethernet.cpp
Original file line number Diff line number Diff line change
@@ -1,208 +1 @@
#include <EthernetC33.h>

/*
* The old implementation of the begin set a default mac address:
* this does not make any sense.
* Default mac address is in the hardware, when lwip start that mac
* address is passed to lwip
* If mac address needs to be changed then call the appropriate function
* of lwIpIf before to get the interface
*/

/* -------------------------------------------------------------------------- */
int CEthernet::begin(unsigned long timeout, unsigned long responseTimeout) {
/* -------------------------------------------------------------------------- */
(void)responseTimeout;

int rv = 0;

ni = CLwipIf::getInstance().get(NI_ETHERNET);
if(ni != nullptr) {
ni->DhcpSetTimeout(timeout);
rv = (int)ni->DhcpStart();
}

return rv;
}

/* -------------------------------------------------------------------------- */
int CEthernet::begin(IPAddress local_ip) {
/* -------------------------------------------------------------------------- */
// Assume the DNS server will be the machine on the same network as the local IP
// but with last octet being '1'
IPAddress dns_server = local_ip;
dns_server[3] = 1;
return begin(local_ip, dns_server);
}

/* -------------------------------------------------------------------------- */
int CEthernet::begin(IPAddress local_ip, IPAddress dns_server) {
/* -------------------------------------------------------------------------- */
// Assume the gateway will be the machine on the same network as the local IP
// but with last octet being '1'
IPAddress gateway = local_ip;
gateway[3] = 1;
return begin(local_ip, dns_server, gateway);
}

/* -------------------------------------------------------------------------- */
int CEthernet::begin(IPAddress local_ip, IPAddress dns_server, IPAddress gateway) {
/* -------------------------------------------------------------------------- */
IPAddress subnet(255, 255, 255, 0);
return begin(local_ip, dns_server, gateway, subnet);
}

/* -------------------------------------------------------------------------- */
int CEthernet::begin(IPAddress local_ip, IPAddress dns_server, IPAddress gateway, IPAddress subnet) {
/* -------------------------------------------------------------------------- */

ni = CLwipIf::getInstance().get(NI_ETHERNET, local_ip, gateway, subnet);
if(ni == nullptr) {
return 0;
}

/* If there is a local DHCP informs it of our manual IP configuration to prevent IP conflict */
ni->DhcpNotUsed();
CLwipIf::getInstance().addDns(dns_server);
return 1;
}

/* -------------------------------------------------------------------------- */
void CEthernet::setDNS(IPAddress dns_server) {
/* -------------------------------------------------------------------------- */
CLwipIf::getInstance().addDns(dns_server);
}

/* -------------------------------------------------------------------------- */
int CEthernet::begin(uint8_t *mac, unsigned long timeout, unsigned long responseTimeout) {
/* -------------------------------------------------------------------------- */
CLwipIf::getInstance().setMacAddress(NI_ETHERNET, mac);
return begin(timeout, responseTimeout);
}

/* -------------------------------------------------------------------------- */
int CEthernet::begin(uint8_t *mac_address, IPAddress local_ip) {
/* -------------------------------------------------------------------------- */
// Assume the DNS server will be the machine on the same network as the local IP
// but with last octet being '1'
IPAddress dns_server = local_ip;
dns_server[3] = 1;
return begin(mac_address, local_ip, dns_server);
}

/* -------------------------------------------------------------------------- */
int CEthernet::begin(uint8_t *mac_address, IPAddress local_ip, IPAddress dns_server) {
/* -------------------------------------------------------------------------- */
// Assume the gateway will be the machine on the same network as the local IP
// but with last octet being '1'
IPAddress gateway = local_ip;
gateway[3] = 1;
return begin(mac_address, local_ip, dns_server, gateway);
}

/* -------------------------------------------------------------------------- */
int CEthernet::begin(uint8_t *mac_address, IPAddress local_ip, IPAddress dns_server, IPAddress gateway) {
/* -------------------------------------------------------------------------- */
IPAddress subnet(255, 255, 255, 0);
return begin(mac_address, local_ip, dns_server, gateway, subnet);
}

/* -------------------------------------------------------------------------- */
int CEthernet::begin(uint8_t *mac, IPAddress local_ip, IPAddress dns_server, IPAddress gateway, IPAddress subnet, unsigned long timeout, unsigned long responseTimeout) {
/* -------------------------------------------------------------------------- */
CLwipIf::getInstance().setMacAddress(NI_ETHERNET, mac);
return begin(local_ip, dns_server, gateway, subnet);
}

/* -------------------------------------------------------------------------- */
EthernetLinkStatus CEthernet::linkStatus() {
/* -------------------------------------------------------------------------- */
if(ni != nullptr) {
return (!CLwipIf::getInstance().isEthInitialized()) ? Unknown : (ni->isLinkUp() ? LinkON : LinkOFF);
}
return Unknown;
}

/* -------------------------------------------------------------------------- */
EthernetHardwareStatus CEthernet::hardwareStatus() {
/* -------------------------------------------------------------------------- */
return EthernetLwip;
}

/* -------------------------------------------------------------------------- */
int CEthernet::disconnect() {
/* -------------------------------------------------------------------------- */
return 1;
}

/* -------------------------------------------------------------------------- */
int CEthernet::maintain() {
/* -------------------------------------------------------------------------- */
int rc = DHCP_CHECK_NONE;

if (ni != NULL) {
//we have a pointer to dhcp, use it
rc = ni->checkLease();
switch (rc) {
case DHCP_CHECK_NONE:
//nothing done
break;
case DHCP_CHECK_RENEW_OK:
case DHCP_CHECK_REBIND_OK:
//_dnsServerAddress = _dhcp->getDnsServerIp();
break;
default:
//this is actually a error, it will retry though
break;
}
}
return rc;
}

/*
* This function updates the LwIP stack and can be called to be sure to update
* the stack (e.g. in case of a long loop).
*/
void CEthernet::schedule(void) {
if (ni != NULL) {
ni->task();
}
}



uint8_t *CEthernet::MACAddress(void) {
CLwipIf::getInstance().getMacAddress(NI_ETHERNET, mac_address);
return mac_address;
}

void CEthernet::MACAddress(uint8_t *mac) {
CLwipIf::getInstance().getMacAddress(NI_ETHERNET, mac);
}

IPAddress CEthernet::localIP() {
if(ni != nullptr) {
return IPAddress(ni->getIpAdd());
}
return IPAddress((uint32_t)0);
}

IPAddress CEthernet::subnetMask() {
if(ni != nullptr) {
return IPAddress(ni->getNmAdd());
}
return IPAddress((uint32_t)0);
}

IPAddress CEthernet::gatewayIP() {
if(ni != nullptr) {
return IPAddress(ni->getGwAdd());
}
return IPAddress((uint32_t)0);
}

IPAddress CEthernet::dnsServerIP() {
return CLwipIf::getInstance().getDns();
}

CEthernet Ethernet;
Loading
Loading