diff --git a/connectivity/nanostack/include/nanostack-interface/Nanostack.h b/connectivity/nanostack/include/nanostack-interface/Nanostack.h index 84bb7f5420..53894a1f10 100644 --- a/connectivity/nanostack/include/nanostack-interface/Nanostack.h +++ b/connectivity/nanostack/include/nanostack-interface/Nanostack.h @@ -43,6 +43,9 @@ public: nsapi_error_t add_ethernet_interface(EMAC &emac, bool default_if, OnboardNetworkStack::Interface **interface_out) override; nsapi_error_t add_ethernet_interface(EMAC &emac, bool default_if, OnboardNetworkStack::Interface **interface_out, const uint8_t *mac_addr) override; + /* Local variant with stronger typing and manual address specification */ + nsapi_error_t add_ethernet_interface(EMAC &emac, bool default_if, Nanostack::EthernetInterface **interface_out, const uint8_t *mac_addr = NULL); + nsapi_error_t add_ppp_interface(PPP &ppp, bool default_if, OnboardNetworkStack::Interface **interface_out) override; /* Local variant with stronger typing and manual address specification */ @@ -72,7 +75,7 @@ protected: * @param interface_name Network interface name * @return NSAPI_ERROR_OK on success, negative error code on failure. */ - virtual nsapi_error_t gethostbyname(const char *name, SocketAddress *address, nsapi_version_t version, const char *interface_name); + virtual nsapi_error_t gethostbyname(const char *name, SocketAddress *address, nsapi_version_t version, const char *interface_name) override; /** Translate a hostname to an IP address (asynchronous) using network interface name. * @@ -96,7 +99,7 @@ protected: * a positive unique id that represents the hostname translation operation * and can be passed to cancel. */ - virtual nsapi_value_or_error_t gethostbyname_async(const char *name, hostbyname_cb_t callback, nsapi_version_t version, const char *interface_name); + virtual nsapi_value_or_error_t gethostbyname_async(const char *name, hostbyname_cb_t callback, nsapi_version_t version, const char *interface_name) override; /** Get a domain name server from a list of servers to query * @@ -105,9 +108,10 @@ protected: * * @param index Index of the DNS server, starts from zero * @param address Destination for the host address + * @param interface_name Network interface name * @return 0 on success, negative error code on failure */ - virtual nsapi_error_t get_dns_server(int index, SocketAddress *address, const char *interface_name); + virtual nsapi_error_t get_dns_server(int index, SocketAddress *address, const char *interface_name) override; /** Opens a socket * diff --git a/connectivity/nanostack/mbed-mesh-api/mbed-mesh-api/MeshInterfaceNanostack.h b/connectivity/nanostack/mbed-mesh-api/mbed-mesh-api/MeshInterfaceNanostack.h index 068c06be5c..cbe956d0eb 100644 --- a/connectivity/nanostack/mbed-mesh-api/mbed-mesh-api/MeshInterfaceNanostack.h +++ b/connectivity/nanostack/mbed-mesh-api/mbed-mesh-api/MeshInterfaceNanostack.h @@ -26,20 +26,13 @@ class Nanostack::Interface : public OnboardNetworkStack::Interface, private mbed::NonCopyable { public: nsapi_error_t get_ip_address(SocketAddress *address) final; - char *get_mac_address(char *buf, nsapi_size_t buflen); + char *get_mac_address(char *buf, nsapi_size_t buflen) override; nsapi_error_t set_mac_address(uint8_t *buf, nsapi_size_t buflen); nsapi_error_t get_netmask(SocketAddress *address) final; nsapi_error_t get_gateway(SocketAddress *address) override; void attach(mbed::Callback status_cb) final; nsapi_connection_status_t get_connection_status() const final; - - void get_mac_address(uint8_t *buf) const - { - NanostackMACPhy *phy = interface_phy.nanostack_mac_phy(); - if (phy) { - phy->get_mac_address(buf); - } - } + virtual void get_mac_address(uint8_t *buf) const; /** * \brief Callback from C-layer diff --git a/connectivity/nanostack/mbed-mesh-api/mbed-mesh-api/NanostackEthernetInterface.h b/connectivity/nanostack/mbed-mesh-api/mbed-mesh-api/NanostackEthernetInterface.h index fda0da7054..38e9df6202 100644 --- a/connectivity/nanostack/mbed-mesh-api/mbed-mesh-api/NanostackEthernetInterface.h +++ b/connectivity/nanostack/mbed-mesh-api/mbed-mesh-api/NanostackEthernetInterface.h @@ -28,9 +28,10 @@ public: nsapi_ip_stack_t stack = DEFAULT_STACK, bool blocking = true) override; nsapi_error_t bringdown() override; + void get_mac_address(uint8_t *buf); char *get_mac_address(char *buf, nsapi_size_t buflen) override; - char *get_interface_name(char *buf); + char *get_interface_name(char *buf) override; private: friend class Nanostack; friend class NanostackEthernetInterface; diff --git a/connectivity/nanostack/mbed-mesh-api/mbed-mesh-api/NanostackPPPInterface.h b/connectivity/nanostack/mbed-mesh-api/mbed-mesh-api/NanostackPPPInterface.h index 75876f6f1b..1297c2f9e9 100644 --- a/connectivity/nanostack/mbed-mesh-api/mbed-mesh-api/NanostackPPPInterface.h +++ b/connectivity/nanostack/mbed-mesh-api/mbed-mesh-api/NanostackPPPInterface.h @@ -32,7 +32,7 @@ public: typedef mbed::Callback link_state_cb_t; void set_link_state_changed_callback(link_state_cb_t link_state_cb); - char *get_interface_name(char *buf); + char *get_interface_name(char *buf) override; private: friend class Nanostack; PPPInterface(NanostackPPPPhy &phy) : Interface(phy) {} diff --git a/connectivity/nanostack/mbed-mesh-api/source/MeshInterfaceNanostack.cpp b/connectivity/nanostack/mbed-mesh-api/source/MeshInterfaceNanostack.cpp index 390a9ba2f6..fb90a7a9fb 100644 --- a/connectivity/nanostack/mbed-mesh-api/source/MeshInterfaceNanostack.cpp +++ b/connectivity/nanostack/mbed-mesh-api/source/MeshInterfaceNanostack.cpp @@ -84,6 +84,14 @@ nsapi_connection_status_t Nanostack::Interface::get_connection_status() const return _connect_status; } +void Nanostack::Interface::get_mac_address(uint8_t *buf) const +{ + NanostackMACPhy *phy = interface_phy.nanostack_mac_phy(); + if (phy) { + phy->get_mac_address(buf); + } +} + void Nanostack::Interface::attach( mbed::Callback status_cb) { diff --git a/connectivity/nanostack/mbed-mesh-api/source/NanostackEMACInterface.cpp b/connectivity/nanostack/mbed-mesh-api/source/NanostackEMACInterface.cpp index 63d9cae6ee..b9c243c4f6 100644 --- a/connectivity/nanostack/mbed-mesh-api/source/NanostackEMACInterface.cpp +++ b/connectivity/nanostack/mbed-mesh-api/source/NanostackEMACInterface.cpp @@ -191,7 +191,7 @@ void EMACPhy::set_mac_address(uint8_t *mac) memcpy(mac_addr, mac, sizeof mac_addr); } -nsapi_error_t Nanostack::add_ethernet_interface(EMAC &emac, bool default_if, OnboardNetworkStack::Interface **interface_out, const uint8_t *mac_addr) +nsapi_error_t Nanostack::add_ethernet_interface(EMAC &emac, bool default_if, Nanostack::EthernetInterface **interface_out, const uint8_t *mac_addr) { if (single_phy) { return NSAPI_ERROR_DEVICE_ERROR; @@ -224,7 +224,18 @@ nsapi_error_t Nanostack::add_ethernet_interface(EMAC &emac, bool default_if, Onb return NSAPI_ERROR_OK; } +nsapi_error_t Nanostack::add_ethernet_interface(EMAC &emac, bool default_if, OnboardNetworkStack::Interface **interface_out, const uint8_t *mac_addr) +{ + Nanostack::EthernetInterface *interface; + nsapi_error_t err = add_ethernet_interface(emac, default_if, &interface, mac_addr); + *interface_out = interface; + return err; +} + nsapi_error_t Nanostack::add_ethernet_interface(EMAC &emac, bool default_if, OnboardNetworkStack::Interface **interface_out) { - return Nanostack::add_ethernet_interface(emac, default_if, interface_out, nullptr); -} + Nanostack::EthernetInterface *interface; + nsapi_error_t err = add_ethernet_interface(emac, default_if, &interface); + *interface_out = interface; + return err; +} \ No newline at end of file diff --git a/connectivity/nanostack/mbed-mesh-api/source/NanostackEthernetInterface.cpp b/connectivity/nanostack/mbed-mesh-api/source/NanostackEthernetInterface.cpp index 87632e0e8c..6b05ff2f2b 100644 --- a/connectivity/nanostack/mbed-mesh-api/source/NanostackEthernetInterface.cpp +++ b/connectivity/nanostack/mbed-mesh-api/source/NanostackEthernetInterface.cpp @@ -133,9 +133,18 @@ char *Nanostack::EthernetInterface::get_interface_name(char *buf) return buf; }; +void Nanostack::EthernetInterface::get_mac_address(uint8_t *buf) +{ + if (!buf) { + return; + } + + get_phy().get_mac_address(buf); +} + char *Nanostack::EthernetInterface::get_mac_address(char *buf, nsapi_size_t buflen) { - uint8_t mac_buf[NSAPI_MAC_BYTES]; + uint8_t mac_buf[NSAPI_MAC_BYTES] = {0}; if (!buf || buflen < NSAPI_MAC_SIZE) { return NULL; diff --git a/connectivity/netsocket/include/netsocket/EMACInterface.h b/connectivity/netsocket/include/netsocket/EMACInterface.h index d9b8f5657e..8cf47cb703 100644 --- a/connectivity/netsocket/include/netsocket/EMACInterface.h +++ b/connectivity/netsocket/include/netsocket/EMACInterface.h @@ -87,7 +87,7 @@ public: const char *get_mac_address() override; /** @copydoc NetworkInterface::set_mac_address */ - nsapi_error_t set_mac_address(uint8_t *mac_addr, nsapi_size_t addr_len); + nsapi_error_t set_mac_address(uint8_t *mac_addr, nsapi_size_t addr_len) override; /** @copydoc NetworkInterface::get_ip_address */ nsapi_error_t get_ip_address(SocketAddress *address) override; @@ -151,7 +151,7 @@ protected: char _ip_address[NSAPI_IPv6_SIZE] {}; char _netmask[NSAPI_IPv4_SIZE] {}; char _gateway[NSAPI_IPv4_SIZE] {}; - uint8_t _hw_mac_addr[NSAPI_MAC_BYTES]; + uint8_t _hw_mac_addr[NSAPI_MAC_BYTES] {}; mbed::Callback _connection_status_cb; };