diff options
Diffstat (limited to 'src/Networking')
-rw-r--r-- | src/Networking/ESP8266WiFi/WiFiInterface.cpp | 10 | ||||
-rw-r--r-- | src/Networking/ESP8266WiFi/WiFiSocket.cpp | 2 | ||||
-rw-r--r-- | src/Networking/LwipEthernet/GMAC/ethernet_sam.cpp (renamed from src/Networking/LwipEthernet/GMAC/ethernet_sam.c) | 34 | ||||
-rw-r--r-- | src/Networking/LwipEthernet/GMAC/ethernet_sam.h | 28 | ||||
-rw-r--r-- | src/Networking/LwipEthernet/GMAC/same70_gmac.h | 8 | ||||
-rw-r--r-- | src/Networking/LwipEthernet/LwipEthernetInterface.cpp | 36 | ||||
-rw-r--r-- | src/Networking/LwipEthernet/LwipEthernetInterface.h | 3 | ||||
-rw-r--r-- | src/Networking/LwipEthernet/LwipSocket.cpp | 2 | ||||
-rw-r--r-- | src/Networking/W5500Ethernet/W5500Interface.cpp | 2 | ||||
-rw-r--r-- | src/Networking/W5500Ethernet/Wiznet/Ethernet/socketlib.cpp | 4 | ||||
-rw-r--r-- | src/Networking/W5500Ethernet/Wiznet/Internet/DHCP/dhcp.cpp | 2 |
11 files changed, 62 insertions, 69 deletions
diff --git a/src/Networking/ESP8266WiFi/WiFiInterface.cpp b/src/Networking/ESP8266WiFi/WiFiInterface.cpp index 3bbbcc33..3b3c64d6 100644 --- a/src/Networking/ESP8266WiFi/WiFiInterface.cpp +++ b/src/Networking/ESP8266WiFi/WiFiInterface.cpp @@ -658,7 +658,7 @@ void WiFiInterface::Spin(bool full) Receiver<NetworkStatusResponse> status; if (SendCommand(NetworkCommand::networkGetStatus, 0, 0, nullptr, 0, status) > 0) { - ipAddress.SetV4(status.Value().ipAddress); + ipAddress.SetV4LittleEndian(status.Value().ipAddress); SafeStrncpy(actualSsid, status.Value().ssid, SsidLength); } InitSockets(); @@ -938,19 +938,19 @@ GCodeResult WiFiInterface::HandleWiFiCode(int mcode, GCodeBuffer &gb, const Stri { IPAddress temp; gb.GetIPAddress(temp); - config.ip = temp.GetV4(); + config.ip = temp.GetV4LittleEndian(); } if (ok && gb.Seen('J')) { IPAddress temp; ok = gb.GetIPAddress(temp); - config.gateway = temp.GetV4(); + config.gateway = temp.GetV4LittleEndian(); } if (ok && gb.Seen('K')) { IPAddress temp; ok = gb.GetIPAddress(temp); - config.netmask = temp.GetV4(); + config.netmask = temp.GetV4LittleEndian(); } if (ok) { @@ -1075,7 +1075,7 @@ GCodeResult WiFiInterface::HandleWiFiCode(int mcode, GCodeBuffer &gb, const Stri { IPAddress temp; ok = gb.GetIPAddress(temp); - config.ip = temp.GetV4(); + config.ip = temp.GetV4LittleEndian(); config.channel = (gb.Seen('C')) ? gb.GetIValue() : 0; } else diff --git a/src/Networking/ESP8266WiFi/WiFiSocket.cpp b/src/Networking/ESP8266WiFi/WiFiSocket.cpp index fe22bd7b..5fbe6d45 100644 --- a/src/Networking/ESP8266WiFi/WiFiSocket.cpp +++ b/src/Networking/ESP8266WiFi/WiFiSocket.cpp @@ -170,7 +170,7 @@ void WiFiSocket::Poll(bool full) } localPort = resp.Value().localPort; remotePort = resp.Value().remotePort; - remoteIPAddress.SetV4(resp.Value().remoteIp); + remoteIPAddress.SetV4LittleEndian(resp.Value().remoteIp); DiscardReceivedData(); if (state != SocketState::waitingForResponder) { diff --git a/src/Networking/LwipEthernet/GMAC/ethernet_sam.c b/src/Networking/LwipEthernet/GMAC/ethernet_sam.cpp index c2329262..1b685f93 100644 --- a/src/Networking/LwipEthernet/GMAC/ethernet_sam.c +++ b/src/Networking/LwipEthernet/GMAC/ethernet_sam.cpp @@ -41,9 +41,12 @@ * */ -#include "ethernet_phy.h" #include "ethernet_sam.h" -#include <string.h> +#include <cstring> + +extern "C" { + +#include "ethernet_phy.h" /* lwIP includes */ #include "lwip/api.h" @@ -60,7 +63,6 @@ #include "lwip/tcpip.h" #include "netif/etharp.h" - /* Global variable containing MAC Config (hw addr, IP, GW, ...) */ struct netif gs_net_if; @@ -89,7 +91,9 @@ static timers_info_t gs_timers_table[] = { #endif }; -extern uint32_t millis( void ) ; +extern uint32_t millis(); + +} // end extern "C" /** * \brief Process timing functions. @@ -125,12 +129,12 @@ void ethernet_timers_update(void) //************************************************************************************************************ // This sets the static IP configuration on-the-fly -void ethernet_set_configuration(const uint8_t ipAddress[], const uint8_t netMask[], const uint8_t gateWay[]) +void ethernet_set_configuration(IPAddress ipAddress, IPAddress netMask, IPAddress gateWay) { ip4_addr_t x_ip_addr, x_net_mask, x_gateway; - IP4_ADDR(&x_ip_addr, ipAddress[0], ipAddress[1], ipAddress[2], ipAddress[3]); - IP4_ADDR(&x_net_mask, netMask[0], netMask[1], netMask[2], netMask[3]); - IP4_ADDR(&x_gateway, gateWay[0], gateWay[1], gateWay[2], gateWay[3]); + x_ip_addr.addr = ipAddress.GetV4LittleEndian(); + x_net_mask.addr = netMask.GetV4LittleEndian(); + x_gateway.addr = gateWay.GetV4LittleEndian(); // use static IP address netif_set_ipaddr(&gs_net_if, &x_ip_addr); @@ -141,12 +145,12 @@ void ethernet_set_configuration(const uint8_t ipAddress[], const uint8_t netMask /** \brief Initialize the Ethernet subsystem. * */ -void init_ethernet(const uint8_t ipAddress[], const uint8_t netMask[], const uint8_t gateWay[]) +void init_ethernet(IPAddress ipAddress, IPAddress netMask, IPAddress gateWay) { ip4_addr_t x_ip_addr, x_net_mask, x_gateway; - IP4_ADDR(&x_ip_addr, ipAddress[0], ipAddress[1], ipAddress[2], ipAddress[3]); - IP4_ADDR(&x_net_mask, netMask[0], netMask[1], netMask[2], netMask[3]); - IP4_ADDR(&x_gateway, gateWay[0], gateWay[1], gateWay[2], gateWay[3]); + x_ip_addr.addr = ipAddress.GetV4LittleEndian(); + x_net_mask.addr = netMask.GetV4LittleEndian(); + x_gateway.addr = gateWay.GetV4LittleEndian(); /* Initialize lwIP. */ lwip_init(); @@ -232,7 +236,9 @@ void ethernet_set_rx_callback(gmac_dev_tx_cb_t callback) /* * \brief Returns the current IP address */ -const uint8_t *ethernet_get_ipaddress() +void ethernet_get_ipaddress(IPAddress& ipAddress, IPAddress& netMask, IPAddress& gateWay) { - return (uint8_t*)&gs_net_if.ip_addr.addr; + ipAddress.SetV4LittleEndian(gs_net_if.ip_addr.addr); + netMask.SetV4LittleEndian(gs_net_if.netmask.addr); + gateWay.SetV4LittleEndian(gs_net_if.gw.addr); } diff --git a/src/Networking/LwipEthernet/GMAC/ethernet_sam.h b/src/Networking/LwipEthernet/GMAC/ethernet_sam.h index 46de9e67..0532dc88 100644 --- a/src/Networking/LwipEthernet/GMAC/ethernet_sam.h +++ b/src/Networking/LwipEthernet/GMAC/ethernet_sam.h @@ -44,21 +44,15 @@ #ifndef ETHERNET_SAM_H_INCLUDED #define ETHERNET_SAM_H_INCLUDED +#include <cstdint> +#include <cstddef> +#include <General/IPAddress.h> + #include "same70_gmac.h" #include "lwip/netif.h" -#include <stddef.h> - -/// @cond 0 -/**INDENT-OFF**/ -#ifdef __cplusplus -extern "C" { -#endif -/**INDENT-ON**/ -/// @endcond - // Perform low-level initialisation of the network interface -void init_ethernet(const uint8_t ipAddress[], const uint8_t netMask[], const uint8_t gateWay[]); +void init_ethernet(IPAddress ipAddress, IPAddress netMask, IPAddress gateWay); // Configure the ethernet interface void ethernet_configure_interface(const uint8_t macAddress[], const char *hostname); @@ -70,7 +64,7 @@ bool ethernet_establish_link(void); bool ethernet_link_established(void); // Update IPv4 configuration on demand -void ethernet_set_configuration(const unsigned char ipAddress[], const unsigned char netMask[], const unsigned char gateWay[]); +void ethernet_set_configuration(IPAddress ipAddress, IPAddress netMask, IPAddress gateWay); // Must be called periodically to keep the LwIP timers running void ethernet_timers_update(void); @@ -82,15 +76,7 @@ void ethernet_task(void); void ethernet_set_rx_callback(gmac_dev_tx_cb_t callback); // Returns the network interface's current IPv4 address -const uint8_t *ethernet_get_ipaddress(); - +void ethernet_get_ipaddress(IPAddress& ipAddress, IPAddress& netMask, IPAddress& gateWay); -/// @cond 0 -/**INDENT-OFF**/ -#ifdef __cplusplus -} -#endif -/**INDENT-ON**/ -/// @endcond #endif /* ETHERNET_SAM_H_INCLUDED */ diff --git a/src/Networking/LwipEthernet/GMAC/same70_gmac.h b/src/Networking/LwipEthernet/GMAC/same70_gmac.h index 1cb25970..fe263623 100644 --- a/src/Networking/LwipEthernet/GMAC/same70_gmac.h +++ b/src/Networking/LwipEthernet/GMAC/same70_gmac.h @@ -45,6 +45,10 @@ #ifndef ETHERNETIF_H_INCLUDED #define ETHERNETIF_H_INCLUDED +#ifdef __cplusplus +extern "C" { +#endif + #include "lwip/err.h" #include "lwip/ip_addr.h" #include "lwip/netif.h" @@ -70,4 +74,8 @@ void ethernetif_set_mac_address(const uint8_t macAddress[]); #endif +#ifdef __cplusplus +} +#endif + #endif /* ETHERNETIF_H_INCLUDED */ diff --git a/src/Networking/LwipEthernet/LwipEthernetInterface.cpp b/src/Networking/LwipEthernet/LwipEthernetInterface.cpp index 90b47523..368013b7 100644 --- a/src/Networking/LwipEthernet/LwipEthernetInterface.cpp +++ b/src/Networking/LwipEthernet/LwipEthernetInterface.cpp @@ -19,10 +19,10 @@ #include "Networking/TelnetResponder.h" #include "General/IP4String.h" #include "Version.h" +#include "GMAC/ethernet_sam.h" extern "C" { -#include "GMAC/ethernet_sam.h" #ifdef LWIP_STATS #include "lwip/stats.h" @@ -348,10 +348,11 @@ void LwipEthernetInterface::Exit() // Get the network state into the reply buffer, returning true if there is some sort of error GCodeResult LwipEthernetInterface::GetNetworkState(const StringRef& reply) { + ethernet_get_ipaddress(ipAddress, netmask, gateway); const int enableState = EnableState(); reply.printf("Ethernet is %s, configured IP address: %s, actual IP address: %s", (enableState == 0) ? "disabled" : "enabled", - IP4String(platform.GetIPAddress()).c_str(), IP4String(ethernet_get_ipaddress()).c_str()); + IP4String(platform.GetIPAddress()).c_str(), IP4String(ipAddress).c_str()); return GCodeResult::ok; } @@ -369,11 +370,7 @@ void LwipEthernetInterface::Start() // Allow the MAC address to be set only before LwIP is started... ethernet_configure_interface(platform.GetDefaultMacAddress(), hostname); - uint8_t ipAddress[4], netmask[4], gateway[4]; - DefaultIpAddress.UnpackV4(ipAddress); - DefaultNetMask.UnpackV4(netmask); - DefaultGateway.UnpackV4(gateway); - init_ethernet(ipAddress, netmask, gateway); + init_ethernet(DefaultIpAddress, DefaultNetMask, DefaultGateway); // Initialise mDNS subsystem mdns_resp_init(); @@ -424,7 +421,7 @@ void LwipEthernetInterface::Spin(bool full) // IP address is all zeros, so use DHCP state = NetworkState::obtainingIP; // debugPrintf("Link established, getting IP address\n"); - uint8_t nullAddress[4] = { 0, 0, 0, 0 }; + IPAddress nullAddress; ethernet_set_configuration(nullAddress, nullAddress, nullAddress); dhcp_start(&gs_net_if); } @@ -433,11 +430,7 @@ void LwipEthernetInterface::Spin(bool full) // Using static IP address state = NetworkState::connected; // debugPrintf("Link established, network running\n"); - uint8_t ipAddress[4], netmask[4], gateway[4]; - platform.GetIPAddress().UnpackV4(ipAddress); - platform.NetMask().UnpackV4(netmask); - platform.GateWay().UnpackV4(gateway); - ethernet_set_configuration(ipAddress, netmask, gateway); + ethernet_set_configuration(platform.GetIPAddress(), platform.NetMask(), platform.GateWay()); } } break; @@ -451,8 +444,8 @@ void LwipEthernetInterface::Spin(bool full) DoEthernetTask(); // Have we obtained an IP address yet? - const uint8_t * const ip = ethernet_get_ipaddress(); - if (ip[0] != 0 || ip[1] != 0 || ip[2] != 0 || ip[3] != 0) + ethernet_get_ipaddress(ipAddress, netmask, gateway); + if (!ipAddress.IsNull()) { // Notify the mDNS responder about this state = NetworkState::connected; @@ -478,7 +471,8 @@ void LwipEthernetInterface::Spin(bool full) { InitSockets(); RebuildMdnsServices(); - platform.MessageF(NetworkInfoMessage, "Ethernet running, IP address = %s\n", IP4String(ethernet_get_ipaddress()).c_str()); + ethernet_get_ipaddress(ipAddress, netmask, gateway); + platform.MessageF(NetworkInfoMessage, "Ethernet running, IP address = %s\n", IP4String(ipAddress).c_str()); state = NetworkState::active; } break; @@ -595,7 +589,7 @@ bool LwipEthernetInterface::ConnectionEstablished(tcp_pcb *pcb) IPAddress LwipEthernetInterface::GetIPAddress() const { - return IPAddress(ethernet_get_ipaddress()); + return ipAddress; } void LwipEthernetInterface::SetIPAddress(IPAddress p_ipAddress, IPAddress p_netmask, IPAddress p_gateway) @@ -609,7 +603,7 @@ void LwipEthernetInterface::SetIPAddress(IPAddress p_ipAddress, IPAddress p_netm if (!usingDhcp) { state = NetworkState::obtainingIP; - uint8_t nullAddress[4] = { 0, 0, 0, 0 }; + IPAddress nullAddress; ethernet_set_configuration(nullAddress, nullAddress, nullAddress); dhcp_start(&gs_net_if); usingDhcp = true; @@ -628,11 +622,7 @@ void LwipEthernetInterface::SetIPAddress(IPAddress p_ipAddress, IPAddress p_netm usingDhcp = false; } - uint8_t ipAddress[4], netmask[4], gateway[4]; - p_ipAddress.UnpackV4(ipAddress); - p_netmask.UnpackV4(netmask); - p_gateway.UnpackV4(gateway); - ethernet_set_configuration(ipAddress, netmask, gateway); + ethernet_set_configuration(p_ipAddress, p_netmask, p_gateway); mdns_resp_netif_settings_changed(&gs_net_if); } } diff --git a/src/Networking/LwipEthernet/LwipEthernetInterface.h b/src/Networking/LwipEthernet/LwipEthernetInterface.h index 974153a9..7eacbc29 100644 --- a/src/Networking/LwipEthernet/LwipEthernetInterface.h +++ b/src/Networking/LwipEthernet/LwipEthernetInterface.h @@ -104,6 +104,9 @@ private: bool initialised; bool usingDhcp; + IPAddress ipAddress; + IPAddress netmask; + IPAddress gateway; uint8_t macAddress[6]; }; diff --git a/src/Networking/LwipEthernet/LwipSocket.cpp b/src/Networking/LwipEthernet/LwipSocket.cpp index 7b236889..786a2db0 100644 --- a/src/Networking/LwipEthernet/LwipSocket.cpp +++ b/src/Networking/LwipEthernet/LwipSocket.cpp @@ -87,7 +87,7 @@ bool LwipSocket::AcceptConnection(tcp_pcb *pcb) whenConnected = millis(); connectionPcb = pcb; - remoteIPAddress.SetV4(swap32(pcb->remote_ip.addr)); // LWIP IP addresses are big-endian, ours are little endian + remoteIPAddress.SetV4LittleEndian(pcb->remote_ip.addr); remotePort = pcb->remote_port; tcp_arg(pcb, this); diff --git a/src/Networking/W5500Ethernet/W5500Interface.cpp b/src/Networking/W5500Ethernet/W5500Interface.cpp index 89fc3d84..fb8ba382 100644 --- a/src/Networking/W5500Ethernet/W5500Interface.cpp +++ b/src/Networking/W5500Ethernet/W5500Interface.cpp @@ -312,7 +312,7 @@ void W5500Interface::Spin(bool full) if (full && wizphy_getphylink() == PHY_LINK_ON) { - usingDhcp = (ipAddress.GetV4() == 0); + usingDhcp = ipAddress.IsNull(); if (usingDhcp) { // IP address is all zeros, so use DHCP diff --git a/src/Networking/W5500Ethernet/Wiznet/Ethernet/socketlib.cpp b/src/Networking/W5500Ethernet/Wiznet/Ethernet/socketlib.cpp index 43a82fc8..37db94de 100644 --- a/src/Networking/W5500Ethernet/Wiznet/Ethernet/socketlib.cpp +++ b/src/Networking/W5500Ethernet/Wiznet/Ethernet/socketlib.cpp @@ -109,7 +109,7 @@ int8_t socket(uint8_t sn, uint8_t protocol, uint16_t port, uint8_t flag) { IPAddress taddr; getSIPR(taddr); - if (taddr.GetV4() == 0) + if (taddr.IsNull()) { return SOCKERR_SOCKINIT; } @@ -264,7 +264,7 @@ int32_t sendto(uint8_t sn, const uint8_t * buf, uint16_t len, IPAddress destIp, } CHECK_SOCKDATA(); - if (destIp.GetV4() == 0) + if (destIp.IsNull()) { return SOCKERR_IPINVALID; } diff --git a/src/Networking/W5500Ethernet/Wiznet/Internet/DHCP/dhcp.cpp b/src/Networking/W5500Ethernet/Wiznet/Internet/DHCP/dhcp.cpp index 9283d780..f1103a33 100644 --- a/src/Networking/W5500Ethernet/Wiznet/Internet/DHCP/dhcp.cpp +++ b/src/Networking/W5500Ethernet/Wiznet/Internet/DHCP/dhcp.cpp @@ -613,7 +613,7 @@ int8_t parseDHCPMSG(void) case subnetMask : p++; p++; - DHCP_allocated_sn.SetV4(*p); + DHCP_allocated_sn.SetV4(p); p += 4; break; case routersOnSubnet : |