diff --git a/cores/arduino/mbed/connectivity/drivers/emac/TARGET_STM/stm32xx_emac.h b/cores/arduino/mbed/connectivity/drivers/emac/TARGET_STM/stm32xx_emac.h index cfa675217..ecc280b2f 100644 --- a/cores/arduino/mbed/connectivity/drivers/emac/TARGET_STM/stm32xx_emac.h +++ b/cores/arduino/mbed/connectivity/drivers/emac/TARGET_STM/stm32xx_emac.h @@ -148,6 +148,13 @@ class STM32_EMAC : public EMAC { */ virtual void set_memory_manager(EMACMemoryManager &mem_mngr); + /* return the status of the interface as integer */ + int get_interface_status() override; + /* return true if the interface is in the correct state to transmit */ + bool is_ready_to_tx() override; + /* restart only if the interface is in error state */ + void restart() override; + // Called from driver functions ETH_HandleTypeDef EthHandle; osThreadId_t thread; /**< Processing thread */ diff --git a/cores/arduino/mbed/connectivity/netsocket/include/netsocket/EMAC.h b/cores/arduino/mbed/connectivity/netsocket/include/netsocket/EMAC.h index 515629b5a..885bc92c0 100644 --- a/cores/arduino/mbed/connectivity/netsocket/include/netsocket/EMAC.h +++ b/cores/arduino/mbed/connectivity/netsocket/include/netsocket/EMAC.h @@ -176,6 +176,17 @@ class EMAC { * @param mem_mngr Pointer to memory manager */ virtual void set_memory_manager(EMACMemoryManager &mem_mngr) = 0; + + virtual bool is_ready_to_tx() { + return true; + } + + virtual void restart() { + } + + virtual int get_interface_status() { + return -1; + } }; diff --git a/cores/arduino/mbed/connectivity/netsocket/include/netsocket/EMACInterface.h b/cores/arduino/mbed/connectivity/netsocket/include/netsocket/EMACInterface.h index 8cf47cb70..c06aeb850 100644 --- a/cores/arduino/mbed/connectivity/netsocket/include/netsocket/EMACInterface.h +++ b/cores/arduino/mbed/connectivity/netsocket/include/netsocket/EMACInterface.h @@ -83,6 +83,12 @@ class EMACInterface : public virtual NetworkInterface { /** @copydoc NetworkInterface::disconnect */ nsapi_error_t disconnect() override; + /** @copydoc NetworkInterface::get_hostname */ + const char *get_hostname() override; + + /** @copydoc NetworkInterface::set_hostname */ + nsapi_error_t set_hostname(const char *hostname) override; + /** @copydoc NetworkInterface::get_mac_address */ const char *get_mac_address() override; @@ -146,6 +152,8 @@ class EMACInterface : public virtual NetworkInterface { OnboardNetworkStack::Interface *_interface = nullptr; bool _dhcp = true; bool _blocking = true; + bool _hostname_set = false; + char _hostname[NSAPI_HOSTNAME_SIZE]; bool _hw_mac_addr_set = false; char _mac_address[NSAPI_MAC_SIZE]; char _ip_address[NSAPI_IPv6_SIZE] {}; diff --git a/cores/arduino/mbed/connectivity/netsocket/include/netsocket/NetworkInterface.h b/cores/arduino/mbed/connectivity/netsocket/include/netsocket/NetworkInterface.h index 9071a1e40..0e2aa64c9 100644 --- a/cores/arduino/mbed/connectivity/netsocket/include/netsocket/NetworkInterface.h +++ b/cores/arduino/mbed/connectivity/netsocket/include/netsocket/NetworkInterface.h @@ -90,6 +90,22 @@ class NetworkInterface: public DNS { */ virtual void set_as_default(); + /** Get hostname. + * + * @return Hostname if configured, null otherwise + */ + virtual const char *get_hostname(); + + /** Set hostname. + * + * @param hostname Hostname string + * @retval NSAPI_ERROR_OK on success + * @retval NSAPI_ERROR_UNSUPPORTED if this feature is not supported + * @retval NSAPI_ERROR_PARAMETER if hostname is not valid + * @retval NSAPI_ERROR_BUSY if hostname can't be set + */ + virtual nsapi_error_t set_hostname(const char *hostname); + /** Get the local MAC address. * * Provided MAC address is intended for info or debug purposes and diff --git a/cores/arduino/mbed/connectivity/netsocket/include/netsocket/nsapi_types.h b/cores/arduino/mbed/connectivity/netsocket/include/netsocket/nsapi_types.h index 3b496d508..28dbcc9a3 100644 --- a/cores/arduino/mbed/connectivity/netsocket/include/netsocket/nsapi_types.h +++ b/cores/arduino/mbed/connectivity/netsocket/include/netsocket/nsapi_types.h @@ -196,6 +196,16 @@ typedef enum nsapi_security { */ #define NSAPI_IP_BYTES NSAPI_IPv6_BYTES +/** Maximum size of hostname + * + * According to RFC 1034 [1], Section 3.1 "Name space specifications and + * terminology", 63 is the maximum size of a hostname. +1 for the string + * terminator. + * + * [1] https://www.rfc-editor.org/rfc/rfc1034 + */ +#define NSAPI_HOSTNAME_SIZE 64 + /** Maximum size of MAC address representation */ #define NSAPI_MAC_SIZE 18 diff --git a/libraries/Ethernet/src/Ethernet.cpp b/libraries/Ethernet/src/Ethernet.cpp index 0f6450a7a..125fad353 100644 --- a/libraries/Ethernet/src/Ethernet.cpp +++ b/libraries/Ethernet/src/Ethernet.cpp @@ -24,6 +24,11 @@ int arduino::EthernetClass::_begin(uint8_t *mac, unsigned long timeout, unsigned return (linkStatus() == LinkON ? 1 : 0); } +int arduino::EthernetClass::setHostname(const char* hostname) { + eth_if->set_hostname(hostname); + return 1; +} + int arduino::EthernetClass::begin(uint8_t *mac, IPAddress ip) { IPAddress dns = ip; dns[3] = 1; diff --git a/libraries/Ethernet/src/Ethernet.h b/libraries/Ethernet/src/Ethernet.h index 8783d651c..b554b3ef2 100644 --- a/libraries/Ethernet/src/Ethernet.h +++ b/libraries/Ethernet/src/Ethernet.h @@ -56,6 +56,9 @@ class EthernetClass : public MbedSocketClass { EthernetClass(EthernetInterface *_if) : eth_if(_if){}; + // When using DHCP the hostname provided will be used. + int setHostname(const char* hostname); + // Initialise the Ethernet shield to use the provided MAC address and // gain the rest of the configuration through DHCP. // Returns 0 if the DHCP configuration failed, and 1 if it succeeded diff --git a/patches/0235-dhcp-request-hostname-if-set.patch b/patches/0235-dhcp-request-hostname-if-set.patch new file mode 100644 index 000000000..059deeafc --- /dev/null +++ b/patches/0235-dhcp-request-hostname-if-set.patch @@ -0,0 +1,36 @@ +From 08da30219b0faf0415a8fd2d6bed803c3fe7dbac Mon Sep 17 00:00:00 2001 +From: Channel59 +Date: Tue, 9 Jul 2024 23:48:55 +0200 +Subject: [PATCH 1/2] Request hostname if set -- From: https://github.com/ARMmbed/mbed-os/pull/15506/commits/a96d34923e5b70c2b3db32ce65283f93e9f7f789 + +--- + connectivity/lwipstack/source/LWIPInterface.cpp | 6 ++++++ + 1 file changed, 6 insertions(+) + +diff --git a/connectivity/lwipstack/source/LWIPInterface.cpp b/connectivity/lwipstack/source/LWIPInterface.cpp +index dfefebcb8b..b2540732bd 100644 +--- a/connectivity/lwipstack/source/LWIPInterface.cpp ++++ b/connectivity/lwipstack/source/LWIPInterface.cpp +@@ -437,6 +437,7 @@ LWIP::Interface::Interface() : + nsapi_error_t LWIP::add_ethernet_interface(EMAC &emac, bool default_if, OnboardNetworkStack::Interface **interface_out, NetworkInterface *user_network_interface) + { + #if LWIP_ETHERNET ++ const char *hostname; + Interface *interface = new (std::nothrow) Interface(); + if (!interface) { + return NSAPI_ERROR_NO_MEMORY; +@@ -445,6 +446,11 @@ nsapi_error_t LWIP::add_ethernet_interface(EMAC &emac, bool default_if, OnboardN + interface->memory_manager = &memory_manager; + interface->ppp_enabled = false; + ++ hostname = user_network_interface->get_hostname(); ++ if(hostname) { ++ netif_set_hostname(&interface->netif, hostname); ++ } ++ + #if (MBED_MAC_ADDRESS_SUM != MBED_MAC_ADDR_INTERFACE) + netif->interface.hwaddr[0] = MBED_MAC_ADDR_0; + netif->interface.hwaddr[1] = MBED_MAC_ADDR_1; +-- +2.34.1 + diff --git a/patches/0236-dhcp-add-methods-for-setting-hostname.patch b/patches/0236-dhcp-add-methods-for-setting-hostname.patch new file mode 100644 index 000000000..77893ca86 --- /dev/null +++ b/patches/0236-dhcp-add-methods-for-setting-hostname.patch @@ -0,0 +1,148 @@ +From f7740c5ec7986dab71901704936a923899041720 Mon Sep 17 00:00:00 2001 +From: Channel59 +Date: Tue, 9 Jul 2024 23:54:43 +0200 +Subject: [PATCH 2/2] Add methods for setting hostname -- from: https://github.com/ARMmbed/mbed-os/pull/15506/commits/979a9425499565e434db708317a4fc0dc3792af8 + +--- + .../include/netsocket/EMACInterface.h | 8 ++++++ + .../include/netsocket/NetworkInterface.h | 16 ++++++++++++ + .../netsocket/include/netsocket/nsapi_types.h | 10 +++++++ + .../netsocket/source/EMACInterface.cpp | 26 +++++++++++++++++++ + .../netsocket/source/NetworkInterface.cpp | 10 +++++++ + 5 files changed, 70 insertions(+) + +diff --git a/connectivity/netsocket/include/netsocket/EMACInterface.h b/connectivity/netsocket/include/netsocket/EMACInterface.h +index 8cf47cb703..c06aeb850e 100644 +--- a/connectivity/netsocket/include/netsocket/EMACInterface.h ++++ b/connectivity/netsocket/include/netsocket/EMACInterface.h +@@ -83,6 +83,12 @@ public: + /** @copydoc NetworkInterface::disconnect */ + nsapi_error_t disconnect() override; + ++ /** @copydoc NetworkInterface::get_hostname */ ++ const char *get_hostname() override; ++ ++ /** @copydoc NetworkInterface::set_hostname */ ++ nsapi_error_t set_hostname(const char *hostname) override; ++ + /** @copydoc NetworkInterface::get_mac_address */ + const char *get_mac_address() override; + +@@ -146,6 +152,8 @@ protected: + OnboardNetworkStack::Interface *_interface = nullptr; + bool _dhcp = true; + bool _blocking = true; ++ bool _hostname_set = false; ++ char _hostname[NSAPI_HOSTNAME_SIZE]; + bool _hw_mac_addr_set = false; + char _mac_address[NSAPI_MAC_SIZE]; + char _ip_address[NSAPI_IPv6_SIZE] {}; +diff --git a/connectivity/netsocket/include/netsocket/NetworkInterface.h b/connectivity/netsocket/include/netsocket/NetworkInterface.h +index 9071a1e40b..0e2aa64c9d 100644 +--- a/connectivity/netsocket/include/netsocket/NetworkInterface.h ++++ b/connectivity/netsocket/include/netsocket/NetworkInterface.h +@@ -90,6 +90,22 @@ public: + */ + virtual void set_as_default(); + ++ /** Get hostname. ++ * ++ * @return Hostname if configured, null otherwise ++ */ ++ virtual const char *get_hostname(); ++ ++ /** Set hostname. ++ * ++ * @param hostname Hostname string ++ * @retval NSAPI_ERROR_OK on success ++ * @retval NSAPI_ERROR_UNSUPPORTED if this feature is not supported ++ * @retval NSAPI_ERROR_PARAMETER if hostname is not valid ++ * @retval NSAPI_ERROR_BUSY if hostname can't be set ++ */ ++ virtual nsapi_error_t set_hostname(const char *hostname); ++ + /** Get the local MAC address. + * + * Provided MAC address is intended for info or debug purposes and +diff --git a/connectivity/netsocket/include/netsocket/nsapi_types.h b/connectivity/netsocket/include/netsocket/nsapi_types.h +index 3b496d5087..28dbcc9a38 100644 +--- a/connectivity/netsocket/include/netsocket/nsapi_types.h ++++ b/connectivity/netsocket/include/netsocket/nsapi_types.h +@@ -196,6 +196,16 @@ typedef enum nsapi_security { + */ + #define NSAPI_IP_BYTES NSAPI_IPv6_BYTES + ++/** Maximum size of hostname ++ * ++ * According to RFC 1034 [1], Section 3.1 "Name space specifications and ++ * terminology", 63 is the maximum size of a hostname. +1 for the string ++ * terminator. ++ * ++ * [1] https://www.rfc-editor.org/rfc/rfc1034 ++ */ ++#define NSAPI_HOSTNAME_SIZE 64 ++ + /** Maximum size of MAC address representation + */ + #define NSAPI_MAC_SIZE 18 +diff --git a/connectivity/netsocket/source/EMACInterface.cpp b/connectivity/netsocket/source/EMACInterface.cpp +index f48bc0a185..26b7e29856 100644 +--- a/connectivity/netsocket/source/EMACInterface.cpp ++++ b/connectivity/netsocket/source/EMACInterface.cpp +@@ -88,6 +88,32 @@ nsapi_error_t EMACInterface::disconnect() + return NSAPI_ERROR_NO_CONNECTION; + } + ++const char *EMACInterface::get_hostname() ++{ ++ if (_hostname_set) { ++ return _hostname; ++ } ++ return nullptr; ++} ++ ++nsapi_error_t EMACInterface::set_hostname(const char *hostname) ++{ ++ if (!hostname || strlen(hostname) > NSAPI_HOSTNAME_SIZE-1) { ++ return NSAPI_ERROR_PARAMETER; ++ } ++ ++ if (_interface) { ++ // can't set hostname once initialized ++ return NSAPI_ERROR_BUSY; ++ } ++ ++ memset(_hostname, 0, NSAPI_HOSTNAME_SIZE); ++ strncpy(_hostname, hostname, NSAPI_HOSTNAME_SIZE-1); ++ _hostname_set = true; ++ ++ return NSAPI_ERROR_OK; ++} ++ + const char *EMACInterface::get_mac_address() + { + if (_interface && _interface->get_mac_address(_mac_address, sizeof(_mac_address))) { +diff --git a/connectivity/netsocket/source/NetworkInterface.cpp b/connectivity/netsocket/source/NetworkInterface.cpp +index 0f237f0e19..649df0f9b3 100644 +--- a/connectivity/netsocket/source/NetworkInterface.cpp ++++ b/connectivity/netsocket/source/NetworkInterface.cpp +@@ -29,6 +29,16 @@ void NetworkInterface::set_as_default() + + } + ++const char *NetworkInterface::get_hostname() ++{ ++ return 0; ++} ++ ++nsapi_error_t NetworkInterface::set_hostname(const char *hostname) ++{ ++ return NSAPI_ERROR_UNSUPPORTED; ++} ++ + const char *NetworkInterface::get_mac_address() + { + return 0; +-- +2.34.1 + diff --git a/variants/OPTA/defines.txt b/variants/OPTA/defines.txt index d2bdfafe1..45906d2cb 100644 --- a/variants/OPTA/defines.txt +++ b/variants/OPTA/defines.txt @@ -44,7 +44,7 @@ -DFEATURE_BLE=1 -D__FPU_PRESENT=1 -D__MBED__=1 --DMBED_BUILD_TIMESTAMP=1719929630.0019104 +-DMBED_BUILD_TIMESTAMP=1720562782.5913384 -D__MBED_CMSIS_RTOS_CM -DMBED_TICKLESS -DMBEDTLS_FS_IO diff --git a/variants/OPTA/libs/libmbed.a b/variants/OPTA/libs/libmbed.a index c65f0bde3..9302f489b 100644 Binary files a/variants/OPTA/libs/libmbed.a and b/variants/OPTA/libs/libmbed.a differ