diff --git a/TESTS/network/emac/emac_TestNetworkStack.cpp b/TESTS/network/emac/emac_TestNetworkStack.cpp index f72ebc96eb8..ca1449014f3 100644 --- a/TESTS/network/emac/emac_TestNetworkStack.cpp +++ b/TESTS/network/emac/emac_TestNetworkStack.cpp @@ -155,16 +155,31 @@ char *EmacTestNetworkStack::Interface::get_mac_address(char *buf, nsapi_size_t b return NULL; } +nsapi_error_t EmacTestNetworkStack::Interface::get_ip_address(SocketAddress *address) +{ + return NSAPI_ERROR_OK; +} + char *EmacTestNetworkStack::Interface::get_ip_address(char *buf, nsapi_size_t buflen) { return NULL; } +nsapi_error_t EmacTestNetworkStack::Interface::get_netmask(SocketAddress *address) +{ + return NSAPI_ERROR_OK; +} + char *EmacTestNetworkStack::Interface::get_netmask(char *buf, nsapi_size_t buflen) { return NULL; } +nsapi_error_t EmacTestNetworkStack::Interface::get_gateway(SocketAddress *address) +{ + return NSAPI_ERROR_OK; +} + char *EmacTestNetworkStack::Interface::get_gateway(char *buf, nsapi_size_t buflen) { return NULL; diff --git a/TESTS/network/emac/emac_TestNetworkStack.h b/TESTS/network/emac/emac_TestNetworkStack.h index 4cadc194ce6..14033136699 100644 --- a/TESTS/network/emac/emac_TestNetworkStack.h +++ b/TESTS/network/emac/emac_TestNetworkStack.h @@ -92,6 +92,9 @@ class EmacTestNetworkStack : public OnboardNetworkStack, private mbed::NonCopyab * @param buflen size of supplied buffer * @return Pointer to a buffer, or NULL if the buffer is too small */ + virtual nsapi_error_t get_ip_address(SocketAddress *address); + + MBED_DEPRECATED_SINCE("mbed-os-5.15", "String-based APIs are deprecated") virtual char *get_ip_address(char *buf, nsapi_size_t buflen); /** Copies netmask of the network interface to user supplied buffer @@ -100,6 +103,9 @@ class EmacTestNetworkStack : public OnboardNetworkStack, private mbed::NonCopyab * @param buflen size of supplied buffer * @return Pointer to a buffer, or NULL if the buffer is too small */ + virtual nsapi_error_t get_netmask(SocketAddress *address); + + MBED_DEPRECATED_SINCE("mbed-os-5.15", "String-based APIs are deprecated") virtual char *get_netmask(char *buf, nsapi_size_t buflen); /** Copies gateway address of the network interface to user supplied buffer @@ -108,6 +114,9 @@ class EmacTestNetworkStack : public OnboardNetworkStack, private mbed::NonCopyab * @param buflen size of supplied buffer * @return Pointer to a buffer, or NULL if the buffer is too small */ + virtual nsapi_error_t get_gateway(SocketAddress *address); + + MBED_DEPRECATED_SINCE("mbed-os-5.15", "String-based APIs are deprecated") virtual char *get_gateway(char *buf, nsapi_size_t buflen); private: diff --git a/TESTS/network/l3ip/cellular_driver_l3ip.cpp b/TESTS/network/l3ip/cellular_driver_l3ip.cpp index 74a7833935c..317aa442677 100644 --- a/TESTS/network/l3ip/cellular_driver_l3ip.cpp +++ b/TESTS/network/l3ip/cellular_driver_l3ip.cpp @@ -66,22 +66,22 @@ void Cellular_driver_L3IP::set_link_state_cb(l3ip_link_state_change_cb_t state_c l3ip_link_state_cb = state_cb; } -void Cellular_driver_L3IP::add_ipv4_multicast_group(const char *address) +void Cellular_driver_L3IP::add_ipv4_multicast_group(const SocketAddress &address) { } -void Cellular_driver_L3IP::add_ipv6_multicast_group(const char *address) +void Cellular_driver_L3IP::add_ipv6_multicast_group(const SocketAddress &address) { } -void Cellular_driver_L3IP::remove_ipv4_multicast_group(const char *address) +void Cellular_driver_L3IP::remove_ipv4_multicast_group(const SocketAddress &address) { } -void Cellular_driver_L3IP::remove_ipv6_multicast_group(const char *address) +void Cellular_driver_L3IP::remove_ipv6_multicast_group(const SocketAddress &address) { } diff --git a/TESTS/network/l3ip/cellular_driver_l3ip.h b/TESTS/network/l3ip/cellular_driver_l3ip.h index 1772416c44c..9b98075e161 100644 --- a/TESTS/network/l3ip/cellular_driver_l3ip.h +++ b/TESTS/network/l3ip/cellular_driver_l3ip.h @@ -91,25 +91,25 @@ class Cellular_driver_L3IP : public L3IP { * * @param address an IP4 multicast group address */ - virtual void add_ipv4_multicast_group(const char *address); + virtual void add_ipv4_multicast_group(const SocketAddress &address); /** Add device to an IP6 multicast group * * @param address an IP6 multicast group address */ - virtual void add_ipv6_multicast_group(const char *address); + virtual void add_ipv6_multicast_group(const SocketAddress &address); /** Remove device from an IPV4 multicast group * * @param address An IPV4 multicast group address */ - virtual void remove_ipv4_multicast_group(const char *address); + virtual void remove_ipv4_multicast_group(const SocketAddress &address); /** Remove device from an IPV6 multicast group * * @param address An IPV6 multicast group address */ - virtual void remove_ipv6_multicast_group(const char *address); + virtual void remove_ipv6_multicast_group(const SocketAddress &address); /** Request reception of all multicast packets * diff --git a/UNITTESTS/features/cellular/framework/device/cellularcontext/cellularcontexttest.cpp b/UNITTESTS/features/cellular/framework/device/cellularcontext/cellularcontexttest.cpp index 8e913582301..617f33ef8a3 100644 --- a/UNITTESTS/features/cellular/framework/device/cellularcontext/cellularcontexttest.cpp +++ b/UNITTESTS/features/cellular/framework/device/cellularcontext/cellularcontexttest.cpp @@ -72,6 +72,10 @@ class testContext : public CellularContext return NULL; } + nsapi_error_t get_ip_address(SocketAddress *address) + { + return NSAPI_ERROR_UNSUPPORTED; + } const char *get_ip_address() { return NULL; @@ -104,10 +108,18 @@ class testContext : public CellularContext virtual void set_credentials(const char *apn, const char *uname = 0, const char *pwd = 0) { } + nsapi_error_t get_netmask(SocketAddress *address) + { + return NSAPI_ERROR_UNSUPPORTED; + } virtual const char *get_netmask() { return NULL; } + nsapi_error_t get_gateway(SocketAddress *address) + { + return NSAPI_ERROR_UNSUPPORTED; + } virtual const char *get_gateway() { return NULL; diff --git a/UNITTESTS/features/netsocket/EthernetInterface/test_EthernetInterface.cpp b/UNITTESTS/features/netsocket/EthernetInterface/test_EthernetInterface.cpp index 94846704a46..e46122bd4c5 100644 --- a/UNITTESTS/features/netsocket/EthernetInterface/test_EthernetInterface.cpp +++ b/UNITTESTS/features/netsocket/EthernetInterface/test_EthernetInterface.cpp @@ -93,10 +93,13 @@ class EmacNetworkStackMock : public OnboardNetworkStack { MOCK_METHOD1(attach, void(mbed::Callback status_cb)); MOCK_CONST_METHOD0(get_connection_status, nsapi_connection_status_t()); MOCK_METHOD2(get_mac_address, char *(char *buf, nsapi_size_t buflen)); + MOCK_METHOD1(get_ip_address, nsapi_error_t(SocketAddress *address)); MOCK_METHOD2(get_ip_address, char *(char *buf, nsapi_size_t buflen)); - MOCK_METHOD1(get_ipv6_link_local_address, nsapi_error_t(SocketAddress *address)); + MOCK_METHOD1(get_netmask, nsapi_error_t(SocketAddress *address)); MOCK_METHOD2(get_netmask, char *(char *buf, nsapi_size_t buflen)); + MOCK_METHOD1(get_gateway, nsapi_error_t(SocketAddress *address)); MOCK_METHOD2(get_gateway, char *(char *buf, nsapi_size_t buflen)); + MOCK_METHOD1(get_ipv6_link_local_address, nsapi_error_t(SocketAddress *address)); }; }; diff --git a/UNITTESTS/features/netsocket/EthernetInterface/unittest.cmake b/UNITTESTS/features/netsocket/EthernetInterface/unittest.cmake index cd794cae08e..d0dfbdf151c 100644 --- a/UNITTESTS/features/netsocket/EthernetInterface/unittest.cmake +++ b/UNITTESTS/features/netsocket/EthernetInterface/unittest.cmake @@ -31,8 +31,6 @@ set(unittest-test-sources stubs/mbed_shared_queues_stub.cpp stubs/nsapi_dns_stub.cpp stubs/EventFlags_stub.cpp - stubs/stoip4_stub.c - stubs/ip4tos_stub.c stubs/NetworkStack_stub.cpp stubs/NetworkInterfaceDefaults_stub.cpp stubs/SocketStats_Stub.cpp diff --git a/UNITTESTS/features/netsocket/nsapi_dns/test_nsapi_dns.cpp b/UNITTESTS/features/netsocket/nsapi_dns/test_nsapi_dns.cpp index 546fe45eeff..021cb81d254 100644 --- a/UNITTESTS/features/netsocket/nsapi_dns/test_nsapi_dns.cpp +++ b/UNITTESTS/features/netsocket/nsapi_dns/test_nsapi_dns.cpp @@ -89,8 +89,11 @@ class NetworkStackMock : public OnboardNetworkStack { MOCK_METHOD1(attach, void(mbed::Callback status_cb)); MOCK_CONST_METHOD0(get_connection_status, nsapi_connection_status_t()); MOCK_METHOD2(get_mac_address, char *(char *buf, nsapi_size_t buflen)); + MOCK_METHOD1(get_ip_address, nsapi_error_t(SocketAddress *address)); MOCK_METHOD2(get_ip_address, char *(char *buf, nsapi_size_t buflen)); + MOCK_METHOD1(get_netmask, nsapi_error_t(SocketAddress *address)); MOCK_METHOD2(get_netmask, char *(char *buf, nsapi_size_t buflen)); + MOCK_METHOD1(get_gateway, nsapi_error_t(SocketAddress *address)); MOCK_METHOD2(get_gateway, char *(char *buf, nsapi_size_t buflen)); }; }; diff --git a/UNITTESTS/stubs/AT_CellularContext_stub.cpp b/UNITTESTS/stubs/AT_CellularContext_stub.cpp index 8ecf796b215..88a7f5e879d 100644 --- a/UNITTESTS/stubs/AT_CellularContext_stub.cpp +++ b/UNITTESTS/stubs/AT_CellularContext_stub.cpp @@ -111,6 +111,11 @@ NetworkStack *AT_CellularContext::get_stack() return NULL; } +nsapi_error_t AT_CellularContext::get_ip_address(SocketAddress *address) +{ + return NSAPI_ERROR_UNSUPPORTED; +} + const char *AT_CellularContext::get_ip_address() { return NULL; @@ -144,11 +149,21 @@ void AT_CellularContext::set_credentials(const char *apn, const char *uname, con } +nsapi_error_t AT_CellularContext::get_netmask(SocketAddress *address) +{ + return NSAPI_ERROR_UNSUPPORTED; +} + const char *AT_CellularContext::get_netmask() { return NULL; } +nsapi_error_t AT_CellularContext::get_gateway(SocketAddress *address) +{ + return NSAPI_ERROR_UNSUPPORTED; +} + const char *AT_CellularContext::get_gateway() { return NULL; diff --git a/UNITTESTS/stubs/AT_CellularStack_stub.cpp b/UNITTESTS/stubs/AT_CellularStack_stub.cpp index 054396a2a90..8bf7f85ebc5 100644 --- a/UNITTESTS/stubs/AT_CellularStack_stub.cpp +++ b/UNITTESTS/stubs/AT_CellularStack_stub.cpp @@ -35,6 +35,11 @@ nsapi_error_t AT_CellularStack::socket_stack_init() return NSAPI_ERROR_OK; } +nsapi_error_t AT_CellularStack::get_ip_address(SocketAddress* address) +{ + return NSAPI_ERROR_UNSUPPORTED; +} + const char *AT_CellularStack::get_ip_address() { return NULL; diff --git a/UNITTESTS/stubs/NetworkInterface_stub.cpp b/UNITTESTS/stubs/NetworkInterface_stub.cpp index 9d64871a5c3..16521ac052c 100644 --- a/UNITTESTS/stubs/NetworkInterface_stub.cpp +++ b/UNITTESTS/stubs/NetworkInterface_stub.cpp @@ -26,24 +26,43 @@ const char *NetworkInterface::get_mac_address() return 0; } -const char *NetworkInterface::get_ip_address() +nsapi_error_t NetworkInterface::get_ip_address(SocketAddress *) { - return 0; + return NSAPI_ERROR_UNSUPPORTED; } +const char *NetworkInterface::get_ip_address() +{ + return nullptr; +} nsapi_error_t NetworkInterface::get_ipv6_link_local_address(SocketAddress *address) { return NSAPI_ERROR_UNSUPPORTED; } +nsapi_error_t NetworkInterface::get_netmask(SocketAddress *) +{ + return NSAPI_ERROR_UNSUPPORTED; +} + const char *NetworkInterface::get_netmask() { - return 0; + return nullptr; +} + +nsapi_error_t NetworkInterface::get_gateway(SocketAddress *) +{ + return NSAPI_ERROR_UNSUPPORTED; } const char *NetworkInterface::get_gateway() { - return 0; + return nullptr; +} + +nsapi_error_t NetworkInterface::set_network(const SocketAddress &ip_address, const SocketAddress &netmask, const SocketAddress &gateway) +{ + return NSAPI_ERROR_UNSUPPORTED; } nsapi_error_t NetworkInterface::set_network(const char *ip_address, const char *netmask, const char *gateway) diff --git a/UNITTESTS/stubs/NetworkStack_stub.cpp b/UNITTESTS/stubs/NetworkStack_stub.cpp index 0fd1661ecb9..e1d23cc9793 100644 --- a/UNITTESTS/stubs/NetworkStack_stub.cpp +++ b/UNITTESTS/stubs/NetworkStack_stub.cpp @@ -89,6 +89,11 @@ nsapi_error_t NetworkStack::call_in(int delay, mbed::Callback func) return NSAPI_ERROR_UNSUPPORTED; } +nsapi_error_t NetworkStack::get_ip_address(SocketAddress* address) +{ + return NSAPI_ERROR_UNSUPPORTED; +} + const char *NetworkStack::get_ip_address() { return NULL; @@ -99,6 +104,11 @@ nsapi_error_t NetworkStack::get_ipv6_link_local_address(SocketAddress *address) return NSAPI_ERROR_UNSUPPORTED; } +nsapi_error_t NetworkStack::get_ip_address_if(SocketAddress* address, const char *interface_name) +{ + return NSAPI_ERROR_UNSUPPORTED; +} + const char *NetworkStack::get_ip_address_if(const char *interface_name) { return NULL; diff --git a/UNITTESTS/stubs/NetworkStack_stub.h b/UNITTESTS/stubs/NetworkStack_stub.h index daeee0f66fe..3102b555107 100644 --- a/UNITTESTS/stubs/NetworkStack_stub.h +++ b/UNITTESTS/stubs/NetworkStack_stub.h @@ -37,6 +37,11 @@ class NetworkStackstub : public NetworkStack { { return "127.0.0.1"; } + virtual nsapi_error_t get_ip_address(SocketAddress* address) + { + address->set_ip_address("127.0.0.1"); + return NSAPI_ERROR_OK; + } virtual nsapi_error_t gethostbyname(const char *host, SocketAddress *address, nsapi_version_t version, const char *interface_name) { diff --git a/UNITTESTS/target_h/myCellularContext.h b/UNITTESTS/target_h/myCellularContext.h index 172e4e0ff27..482e8174eb0 100644 --- a/UNITTESTS/target_h/myCellularContext.h +++ b/UNITTESTS/target_h/myCellularContext.h @@ -97,6 +97,11 @@ class myCellularContext : public CellularContext { return NULL; }; + nsapi_error_t get_ip_address(SocketAddress *address) + { + return NSAPI_ERROR_UNSUPPORTED; + } + const char *get_ip_address() { return NULL; @@ -130,11 +135,21 @@ class myCellularContext : public CellularContext { }; + nsapi_error_t get_netmask(SocketAddress *address) + { + return NSAPI_ERROR_UNSUPPORTED; + } + const char *get_netmask() { return NULL; }; + nsapi_error_t get_gateway(SocketAddress *address) + { + return NSAPI_ERROR_UNSUPPORTED; + } + const char *get_gateway() { return NULL; diff --git a/features/cellular/framework/API/CellularContext.h b/features/cellular/framework/API/CellularContext.h index 5ec4cac8e41..45c758aec88 100644 --- a/features/cellular/framework/API/CellularContext.h +++ b/features/cellular/framework/API/CellularContext.h @@ -121,6 +121,8 @@ class CellularContext : public CellularInterface { public: // from NetworkInterface virtual nsapi_error_t set_blocking(bool blocking) = 0; virtual NetworkStack *get_stack() = 0; + virtual nsapi_error_t get_ip_address(SocketAddress *address) = 0; + MBED_DEPRECATED_SINCE("mbed-os-5.15", "String-based APIs are deprecated") virtual const char *get_ip_address() = 0; /** Register callback for status reporting. @@ -144,7 +146,11 @@ class CellularContext : public CellularInterface { virtual nsapi_error_t connect(const char *sim_pin, const char *apn = 0, const char *uname = 0, const char *pwd = 0) = 0; virtual void set_credentials(const char *apn, const char *uname = 0, const char *pwd = 0) = 0; + virtual nsapi_error_t get_netmask(SocketAddress *address) = 0; + MBED_DEPRECATED_SINCE("mbed-os-5.15", "String-based APIs are deprecated") virtual const char *get_netmask() = 0; + virtual nsapi_error_t get_gateway(SocketAddress *address) = 0; + MBED_DEPRECATED_SINCE("mbed-os-5.15", "String-based APIs are deprecated") virtual const char *get_gateway() = 0; virtual bool is_connected() = 0; diff --git a/features/cellular/framework/AT/AT_CellularContext.cpp b/features/cellular/framework/AT/AT_CellularContext.cpp index 177e9d45a49..cb792d131dc 100644 --- a/features/cellular/framework/AT/AT_CellularContext.cpp +++ b/features/cellular/framework/AT/AT_CellularContext.cpp @@ -213,16 +213,46 @@ NetworkStack *AT_CellularContext::get_stack() return _stack; } +nsapi_error_t AT_CellularContext::get_netmask(SocketAddress *address) +{ + return NSAPI_ERROR_UNSUPPORTED; +} + const char *AT_CellularContext::get_netmask() { return NULL; } +nsapi_error_t AT_CellularContext::get_gateway(SocketAddress *address) +{ + return NSAPI_ERROR_UNSUPPORTED; +} + const char *AT_CellularContext::get_gateway() { return NULL; } +nsapi_error_t AT_CellularContext::get_ip_address(SocketAddress *address) +{ + if (!address) { + return NSAPI_ERROR_PARAMETER; + } +#if NSAPI_PPP_AVAILABLE + address->set_ip_address(nsapi_ppp_get_ip_addr(_at.get_file_handle())); + return NSAPI_ERROR_OK; +#else + if (!_stack) { + _stack = get_stack(); + } + if (_stack) { + address->set_ip_address(_stack->get_ip_address()); + return NSAPI_ERROR_OK; + } + return NSAPI_ERROR_NO_CONNECTION; +#endif +} + const char *AT_CellularContext::get_ip_address() { #if NSAPI_PPP_AVAILABLE diff --git a/features/cellular/framework/AT/AT_CellularContext.h b/features/cellular/framework/AT/AT_CellularContext.h index 5ccb5f20511..8825884ac20 100644 --- a/features/cellular/framework/AT/AT_CellularContext.h +++ b/features/cellular/framework/AT/AT_CellularContext.h @@ -35,6 +35,7 @@ class AT_CellularContext : public CellularContext, public AT_CellularBase { // from CellularBase/NetworkInterface virtual nsapi_error_t set_blocking(bool blocking); virtual NetworkStack *get_stack(); + virtual nsapi_error_t get_ip_address(SocketAddress *address); virtual const char *get_ip_address(); virtual char *get_interface_name(char *interface_name); virtual void attach(mbed::Callback status_cb); @@ -48,7 +49,9 @@ class AT_CellularContext : public CellularContext, public AT_CellularBase { virtual nsapi_error_t connect(const char *sim_pin, const char *apn = 0, const char *uname = 0, const char *pwd = 0); virtual void set_credentials(const char *apn, const char *uname = 0, const char *pwd = 0); + virtual nsapi_error_t get_netmask(SocketAddress *address); virtual const char *get_netmask(); + virtual nsapi_error_t get_gateway(SocketAddress *address); virtual const char *get_gateway(); // from CellularContext diff --git a/features/cellular/framework/AT/AT_CellularStack.cpp b/features/cellular/framework/AT/AT_CellularStack.cpp index 8b5608b2f04..57e81943d11 100644 --- a/features/cellular/framework/AT/AT_CellularStack.cpp +++ b/features/cellular/framework/AT/AT_CellularStack.cpp @@ -55,6 +55,16 @@ int AT_CellularStack::find_socket_index(nsapi_socket_t handle) /** NetworkStack */ +nsapi_error_t AT_CellularStack::get_ip_address(SocketAddress *address) +{ + address->set_ip_address(get_ip_address()); + if (address) { + return NSAPI_ERROR_OK; + } else { + return NSAPI_ERROR_NO_ADDRESS; + } +} + const char *AT_CellularStack::get_ip_address() { _at.lock(); diff --git a/features/cellular/framework/AT/AT_CellularStack.h b/features/cellular/framework/AT/AT_CellularStack.h index dc79350ba69..8b576076bac 100644 --- a/features/cellular/framework/AT/AT_CellularStack.h +++ b/features/cellular/framework/AT/AT_CellularStack.h @@ -43,6 +43,9 @@ class AT_CellularStack : public NetworkStack, public AT_CellularBase { public: // NetworkStack + virtual nsapi_error_t get_ip_address(SocketAddress *address); + + MBED_DEPRECATED_SINCE("mbed-os-5.15", "String-based APIs are deprecated") virtual const char *get_ip_address(); /** diff --git a/features/lwipstack/LWIPInterface.cpp b/features/lwipstack/LWIPInterface.cpp index 9143a08ec1c..1fe8f4f92ec 100644 --- a/features/lwipstack/LWIPInterface.cpp +++ b/features/lwipstack/LWIPInterface.cpp @@ -302,6 +302,32 @@ nsapi_error_t LWIP::Interface::get_ipv6_link_local_address(SocketAddress *addres #endif } +nsapi_error_t LWIP::Interface::get_ip_address(SocketAddress *address) +{ + if (!address) { + return NSAPI_ERROR_PARAMETER; + } + const ip_addr_t *addr = LWIP::get_ip_addr(true, &netif); + if (!addr) { + return NSAPI_ERROR_NO_ADDRESS; + } +#if LWIP_IPV6 + if (IP_IS_V6(addr)) { + char buf[NSAPI_IPv6_SIZE]; + address->set_ip_address(ip6addr_ntoa_r(ip_2_ip6(addr), buf, NSAPI_IPv6_SIZE)); + return NSAPI_ERROR_OK; + } +#endif +#if LWIP_IPV4 + if (IP_IS_V4(addr)) { + char buf[NSAPI_IPv4_SIZE]; + address->set_ip_address(ip4addr_ntoa_r(ip_2_ip4(addr), buf, NSAPI_IPv4_SIZE)); + return NSAPI_ERROR_OK; + } +#endif + return NSAPI_ERROR_UNSUPPORTED; +} + char *LWIP::Interface::get_ip_address(char *buf, nsapi_size_t buflen) { const ip_addr_t *addr = LWIP::get_ip_addr(true, &netif); @@ -323,6 +349,36 @@ char *LWIP::Interface::get_ip_address(char *buf, nsapi_size_t buflen) #endif } +nsapi_error_t LWIP::Interface::get_ip_address_if(const char *interface_name, SocketAddress *address) +{ + if (!address) { + return NSAPI_ERROR_PARAMETER; + } + + const ip_addr_t *addr; + + if (interface_name == NULL) { + addr = LWIP::get_ip_addr(true, &netif); + } else { + addr = LWIP::get_ip_addr(true, netif_find(interface_name)); + } +#if LWIP_IPV6 + if (IP_IS_V6(addr)) { + char buf[NSAPI_IPv6_SIZE]; + address->set_ip_address(ip6addr_ntoa_r(ip_2_ip6(addr), buf, NSAPI_IPv6_SIZE)); + return NSAPI_ERROR_OK; + } +#endif +#if LWIP_IPV4 + if (IP_IS_V4(addr)) { + char buf[NSAPI_IPv4_SIZE]; + address->set_ip_address(ip4addr_ntoa_r(ip_2_ip4(addr), buf, NSAPI_IPv4_SIZE)); + return NSAPI_ERROR_OK; + } +#endif + return NSAPI_ERROR_UNSUPPORTED; +} + char *LWIP::Interface::get_ip_address_if(char *buf, nsapi_size_t buflen, const char *interface_name) { const ip_addr_t *addr; @@ -350,6 +406,25 @@ char *LWIP::Interface::get_ip_address_if(char *buf, nsapi_size_t buflen, const c #endif } +nsapi_error_t LWIP::Interface::get_netmask(SocketAddress *address) +{ + if (!address) { + return NSAPI_ERROR_PARAMETER; + } +#if LWIP_IPV4 + const ip4_addr_t *addr = netif_ip4_netmask(&netif); + if (!ip4_addr_isany(addr)) { + char buf[NSAPI_IPv4_SIZE]; + address->set_ip_address(ip4addr_ntoa_r(addr, buf, NSAPI_IPv4_SIZE)); + return NSAPI_ERROR_OK; + } else { + return NSAPI_ERROR_NO_ADDRESS; + } +#else + return NSAPI_ERROR_UNSUPPORTED; +#endif +} + char *LWIP::Interface::get_netmask(char *buf, nsapi_size_t buflen) { #if LWIP_IPV4 @@ -364,6 +439,25 @@ char *LWIP::Interface::get_netmask(char *buf, nsapi_size_t buflen) #endif } +nsapi_error_t LWIP::Interface::get_gateway(SocketAddress *address) +{ + if (!address) { + return NSAPI_ERROR_PARAMETER; + } +#if LWIP_IPV4 + const ip4_addr_t *addr = netif_ip4_gw(&netif); + if (!ip4_addr_isany(addr)) { + char buf[NSAPI_IPv4_SIZE]; + address->set_ip_address(ip4addr_ntoa_r(addr, buf, NSAPI_IPv4_SIZE)); + return NSAPI_ERROR_OK; + } else { + return NSAPI_ERROR_NO_ADDRESS; + } +#else + return NSAPI_ERROR_UNSUPPORTED; +#endif +} + char *LWIP::Interface::get_gateway(char *buf, nsapi_size_t buflen) { #if LWIP_IPV4 diff --git a/features/lwipstack/LWIPStack.h b/features/lwipstack/LWIPStack.h index a5756645a98..18cf9d54f63 100644 --- a/features/lwipstack/LWIPStack.h +++ b/features/lwipstack/LWIPStack.h @@ -93,12 +93,10 @@ class LWIP : public OnboardNetworkStack, private mbed::NonCopyable { */ virtual char *get_mac_address(char *buf, nsapi_size_t buflen); - /** Copies IP address of the network interface to user supplied buffer - * - * @param buf buffer to which IP address will be copied as "W:X:Y:Z" - * @param buflen size of supplied buffer - * @return Pointer to a buffer, or NULL if the buffer is too small - */ + /** @copydoc NetworkStack::get_ip_address */ + virtual nsapi_error_t get_ip_address(SocketAddress *address); + + MBED_DEPRECATED_SINCE("mbed-os-5.15", "String-based APIs are deprecated") virtual char *get_ip_address(char *buf, nsapi_size_t buflen); /** Get the IPv6 link local address in SocketAddress representation @@ -115,6 +113,9 @@ class LWIP : public OnboardNetworkStack, private mbed::NonCopyable { * @param interface_name naame of the interface * @return Pointer to a buffer, or NULL if the buffer is too small */ + virtual nsapi_error_t get_ip_address_if(const char *interface_name, SocketAddress *address); + + MBED_DEPRECATED_SINCE("mbed-os-5.15", "String-based APIs are deprecated") virtual char *get_ip_address_if(char *buf, nsapi_size_t buflen, const char *interface_name); /** Copies netmask of the network interface to user supplied buffer @@ -123,6 +124,9 @@ class LWIP : public OnboardNetworkStack, private mbed::NonCopyable { * @param buflen size of supplied buffer * @return Pointer to a buffer, or NULL if the buffer is too small */ + virtual nsapi_error_t get_netmask(SocketAddress *address); + + MBED_DEPRECATED_SINCE("mbed-os-5.15", "String-based APIs are deprecated") virtual char *get_netmask(char *buf, nsapi_size_t buflen); /** Copies gateway address of the network interface to user supplied buffer @@ -131,6 +135,9 @@ class LWIP : public OnboardNetworkStack, private mbed::NonCopyable { * @param buflen size of supplied buffer * @return Pointer to a buffer, or NULL if the buffer is too small */ + virtual nsapi_error_t get_gateway(SocketAddress *address); + + MBED_DEPRECATED_SINCE("mbed-os-5.15", "String-based APIs are deprecated") virtual char *get_gateway(char *buf, nsapi_size_t buflen); private: diff --git a/features/nanostack/mbed-mesh-api/mbed-mesh-api/MeshInterfaceNanostack.h b/features/nanostack/mbed-mesh-api/mbed-mesh-api/MeshInterfaceNanostack.h index 77ab9a55f00..9a782bff898 100644 --- a/features/nanostack/mbed-mesh-api/mbed-mesh-api/MeshInterfaceNanostack.h +++ b/features/nanostack/mbed-mesh-api/mbed-mesh-api/MeshInterfaceNanostack.h @@ -25,9 +25,15 @@ class Nanostack::Interface : public OnboardNetworkStack::Interface, private mbed::NonCopyable { public: + virtual nsapi_error_t get_ip_address(SocketAddress *address); + MBED_DEPRECATED_SINCE("mbed-os-5.15", "String-based APIs are deprecated") virtual char *get_ip_address(char *buf, nsapi_size_t buflen); virtual char *get_mac_address(char *buf, nsapi_size_t buflen); + virtual nsapi_error_t get_netmask(SocketAddress *address); + MBED_DEPRECATED_SINCE("mbed-os-5.15", "String-based APIs are deprecated") virtual char *get_netmask(char *buf, nsapi_size_t buflen); + virtual nsapi_error_t get_gateway(SocketAddress *address); + MBED_DEPRECATED_SINCE("mbed-os-5.15", "String-based APIs are deprecated") virtual char *get_gateway(char *buf, nsapi_size_t buflen); virtual void attach(mbed::Callback status_cb); virtual nsapi_connection_status_t get_connection_status() const; @@ -99,9 +105,10 @@ class InterfaceNanostack : public virtual NetworkInterface { */ virtual nsapi_error_t disconnect(); - /** Get the internally stored IP address - /return IP address of the interface or null if not yet connected - */ + /** @copydoc NetworkInterface::get_ip_address */ + virtual nsapi_error_t get_ip_address(SocketAddress *address); + + MBED_DEPRECATED_SINCE("mbed-os-5.15", "String-based APIs are deprecated") virtual const char *get_ip_address(); /** Get the internally stored MAC address @@ -161,7 +168,7 @@ class InterfaceNanostack : public virtual NetworkInterface { Nanostack::Interface *_interface; - char ip_addr_str[40]; + SocketAddress ip_addr; char mac_addr_str[24]; mbed::Callback _connection_status_cb; bool _blocking; diff --git a/features/nanostack/mbed-mesh-api/source/MeshInterfaceNanostack.cpp b/features/nanostack/mbed-mesh-api/source/MeshInterfaceNanostack.cpp index dfbe3539fef..af919a39e36 100644 --- a/features/nanostack/mbed-mesh-api/source/MeshInterfaceNanostack.cpp +++ b/features/nanostack/mbed-mesh-api/source/MeshInterfaceNanostack.cpp @@ -23,6 +23,19 @@ #include "ip6string.h" #include "mbed_error.h" +nsapi_error_t Nanostack::Interface::get_ip_address(SocketAddress *address) +{ + NanostackLockGuard lock; + uint8_t binary_ipv6[16]; + + if (arm_net_address_get(interface_id, ADDR_IPV6_GP, binary_ipv6) == 0) { + address->set_ip_bytes(binary_ipv6, NSAPI_IPv6); + return NSAPI_ERROR_OK; + } else { + return NSAPI_ERROR_NO_ADDRESS; + } +} + char *Nanostack::Interface::get_ip_address(char *buf, nsapi_size_t buflen) { NanostackLockGuard lock; @@ -48,6 +61,16 @@ char *Nanostack::Interface::get_mac_address(char *buf, nsapi_size_t buflen) } } +nsapi_error_t Nanostack::Interface::get_netmask(SocketAddress *address) +{ + return NSAPI_ERROR_UNSUPPORTED; +} + +nsapi_error_t Nanostack::Interface::get_gateway(SocketAddress *address) +{ + return NSAPI_ERROR_UNSUPPORTED; +} + char *Nanostack::Interface::get_netmask(char *, nsapi_size_t) { return NULL; @@ -78,7 +101,7 @@ Nanostack::Interface::Interface(NanostackPhy &phy) : interface_phy(phy), interfa InterfaceNanostack::InterfaceNanostack() : _interface(NULL), - ip_addr_str(), mac_addr_str(), _blocking(true) + ip_addr(), mac_addr_str(), _blocking(true) { // Nothing to do } @@ -177,10 +200,20 @@ Nanostack *InterfaceNanostack::get_stack() return &Nanostack::get_instance(); } +nsapi_error_t InterfaceNanostack::get_ip_address(SocketAddress *address) +{ + if (_interface->get_ip_address(address) == NSAPI_ERROR_OK) { + ip_addr = address->get_ip_address(); + return NSAPI_ERROR_OK; + } + + return NSAPI_ERROR_NO_ADDRESS; +} + const char *InterfaceNanostack::get_ip_address() { - if (_interface->get_ip_address(ip_addr_str, sizeof(ip_addr_str))) { - return ip_addr_str; + if (_interface->get_ip_address(&ip_addr) == NSAPI_ERROR_OK) { + return ip_addr.get_ip_address(); } return NULL; } diff --git a/features/netsocket/CellularInterface.h b/features/netsocket/CellularInterface.h index 37199c659af..34e2bf7bd7a 100644 --- a/features/netsocket/CellularInterface.h +++ b/features/netsocket/CellularInterface.h @@ -95,25 +95,22 @@ class CellularInterface: public NetworkInterface { */ virtual bool is_connected() = 0; - /** Get the local IP address. - * - * @return Null-terminated representation of the local IP address, - * or null if no IP address has been received. - */ + /** @copydoc NetworkInterface::get_ip_address */ + virtual nsapi_error_t get_ip_address(SocketAddress *address) = 0; + + MBED_DEPRECATED_SINCE("mbed-os-5.15", "String-based APIs are deprecated") virtual const char *get_ip_address() = 0; - /** Get the local network mask. - * - * @return Null-terminated representation of the local network mask, - * or null if no network mask has been received. - */ + /** @copydoc NetworkInterface::get_netmask */ + virtual nsapi_error_t get_netmask(SocketAddress *address) = 0; + + MBED_DEPRECATED_SINCE("mbed-os-5.15", "String-based APIs are deprecated") virtual const char *get_netmask() = 0; - /** Get the local gateways. - * - * @return Null-terminated representation of the local gateway, - * or null if no network mask has been received. - */ + /** @copydoc NetworkInterface::get_gateway */ + virtual nsapi_error_t get_gateway(SocketAddress *address) = 0; + + MBED_DEPRECATED_SINCE("mbed-os-5.15", "String-based APIs are deprecated") virtual const char *get_gateway() = 0; /** @copydoc NetworkInterface::cellularBase diff --git a/features/netsocket/DTLSSocket.h b/features/netsocket/DTLSSocket.h index ddaf87f9610..66252a6cffd 100644 --- a/features/netsocket/DTLSSocket.h +++ b/features/netsocket/DTLSSocket.h @@ -97,6 +97,7 @@ class DTLSSocket : public DTLSSocketWrapper { * @return NSAPI_ERROR_OK on success, negative error code on failure. * See @ref TLSSocketWrapper::connect. */ + MBED_DEPRECATED_SINCE("mbed-os-5.15", "String-based APIs are deprecated") nsapi_error_t connect(const char *host, uint16_t port); private: diff --git a/features/netsocket/EMACInterface.cpp b/features/netsocket/EMACInterface.cpp index 15904c8fb48..27d6c77db19 100644 --- a/features/netsocket/EMACInterface.cpp +++ b/features/netsocket/EMACInterface.cpp @@ -45,6 +45,20 @@ nsapi_error_t EMACInterface::set_network(const char *ip_address, const char *net return NSAPI_ERROR_OK; } +nsapi_error_t EMACInterface::set_network(const SocketAddress &ip_address, const SocketAddress &netmask, const SocketAddress &gateway) +{ + _dhcp = false; + + strncpy(_ip_address, ip_address.get_ip_address() ? ip_address.get_ip_address() : "", sizeof(_ip_address)); + _ip_address[sizeof(_ip_address) - 1] = '\0'; + strncpy(_netmask, netmask.get_ip_address() ? netmask.get_ip_address() : "", sizeof(_netmask)); + _netmask[sizeof(_netmask) - 1] = '\0'; + strncpy(_gateway, gateway.get_ip_address() ? gateway.get_ip_address() : "", sizeof(_gateway)); + _gateway[sizeof(_gateway) - 1] = '\0'; + + return NSAPI_ERROR_OK; +} + nsapi_error_t EMACInterface::set_dhcp(bool dhcp) { _dhcp = dhcp; @@ -83,7 +97,17 @@ const char *EMACInterface::get_mac_address() if (_interface && _interface->get_mac_address(_mac_address, sizeof(_mac_address))) { return _mac_address; } - return NULL; + return nullptr; +} + +nsapi_error_t EMACInterface::get_ip_address(SocketAddress *address) +{ + if (_interface && _interface->get_ip_address(_ip_address, sizeof(_ip_address))) { + address->set_ip_address(_ip_address); + return NSAPI_ERROR_OK; + } + + return NSAPI_ERROR_NO_CONNECTION; } const char *EMACInterface::get_ip_address() @@ -91,8 +115,7 @@ const char *EMACInterface::get_ip_address() if (_interface && _interface->get_ip_address(_ip_address, sizeof(_ip_address))) { return _ip_address; } - - return NULL; + return nullptr; } nsapi_error_t EMACInterface::get_ipv6_link_local_address(SocketAddress *address) @@ -104,13 +127,32 @@ nsapi_error_t EMACInterface::get_ipv6_link_local_address(SocketAddress *address) return NSAPI_ERROR_NO_CONNECTION; } +nsapi_error_t EMACInterface::get_netmask(SocketAddress *address) +{ + if (_interface && _interface->get_netmask(_netmask, sizeof(_netmask))) { + address->set_ip_address(_netmask); + return NSAPI_ERROR_OK; + } + + return NSAPI_ERROR_NO_CONNECTION; +} + const char *EMACInterface::get_netmask() { if (_interface && _interface->get_netmask(_netmask, sizeof(_netmask))) { return _netmask; } + return nullptr; +} + +nsapi_error_t EMACInterface::get_gateway(SocketAddress *address) +{ + if (_interface && _interface->get_gateway(_gateway, sizeof(_gateway))) { + address->set_ip_address(_gateway); + return NSAPI_ERROR_OK; + } - return 0; + return NSAPI_ERROR_NO_CONNECTION; } const char *EMACInterface::get_gateway() @@ -118,8 +160,7 @@ const char *EMACInterface::get_gateway() if (_interface && _interface->get_gateway(_gateway, sizeof(_gateway))) { return _gateway; } - - return 0; + return nullptr; } char *EMACInterface::get_interface_name(char *interface_name) diff --git a/features/netsocket/EMACInterface.h b/features/netsocket/EMACInterface.h index d6f71c81777..1e493ea3a4c 100644 --- a/features/netsocket/EMACInterface.h +++ b/features/netsocket/EMACInterface.h @@ -64,6 +64,9 @@ class EMACInterface : public virtual NetworkInterface { * @param gateway Null-terminated representation of the local gateway * @return 0 on success, negative error code on failure */ + virtual nsapi_error_t set_network(const SocketAddress &ip_address, const SocketAddress &netmask, const SocketAddress &gateway); + + MBED_DEPRECATED_SINCE("mbed-os-5.15", "String-based APIs are deprecated") virtual nsapi_error_t set_network(const char *ip_address, const char *netmask, const char *gateway); /** Enable or disable DHCP on the network @@ -101,6 +104,9 @@ class EMACInterface : public virtual NetworkInterface { * @return Null-terminated representation of the local IP address * or null if no IP address has been received */ + virtual nsapi_error_t get_ip_address(SocketAddress *address); + + MBED_DEPRECATED_SINCE("mbed-os-5.15", "String-based APIs are deprecated") virtual const char *get_ip_address(); /** Get the IPv6 link local address @@ -115,6 +121,9 @@ class EMACInterface : public virtual NetworkInterface { * @return Null-terminated representation of the local network mask * or null if no network mask has been received */ + virtual nsapi_error_t get_netmask(SocketAddress *address); + + MBED_DEPRECATED_SINCE("mbed-os-5.15", "String-based APIs are deprecated") virtual const char *get_netmask(); /** Get the local gateways @@ -122,6 +131,9 @@ class EMACInterface : public virtual NetworkInterface { * @return Null-terminated representation of the local gateway * or null if no network mask has been received */ + virtual nsapi_error_t get_gateway(SocketAddress *address); + + MBED_DEPRECATED_SINCE("mbed-os-5.15", "String-based APIs are deprecated") virtual const char *get_gateway(); /** Get the network interface name diff --git a/features/netsocket/InternetDatagramSocket.h b/features/netsocket/InternetDatagramSocket.h index 019a215a910..060521f98f9 100644 --- a/features/netsocket/InternetDatagramSocket.h +++ b/features/netsocket/InternetDatagramSocket.h @@ -47,6 +47,7 @@ class InternetDatagramSocket : public InternetSocket { * @retval int Other negative error codes for stack-related failures. * See @ref NetworkStack::socket_send. */ + MBED_DEPRECATED_SINCE("mbed-os-5.15", "String-based APIs are deprecated") virtual nsapi_size_or_error_t sendto(const char *host, uint16_t port, const void *data, nsapi_size_t size); diff --git a/features/netsocket/InternetSocket.h b/features/netsocket/InternetSocket.h index d3ba43664e1..3d803ef0f60 100644 --- a/features/netsocket/InternetSocket.h +++ b/features/netsocket/InternetSocket.h @@ -106,6 +106,7 @@ class InternetSocket : public Socket { * @retval int negative error codes for stack-related failures. * See @ref NetworkStack::socket_bind. */ + MBED_DEPRECATED_SINCE("mbed-os-5.15", "String-based APIs are deprecated") nsapi_error_t bind(const char *address, uint16_t port); /** @copydoc Socket::bind diff --git a/features/netsocket/L3IP.h b/features/netsocket/L3IP.h index e89b183b01b..f71c53a6d08 100644 --- a/features/netsocket/L3IP.h +++ b/features/netsocket/L3IP.h @@ -21,7 +21,7 @@ #include #include "Callback.h" #include "NetStackMemoryManager.h" - +#include "SocketAddress.h" /** * This interface should be used to abstract low level access to networking hardware @@ -118,25 +118,25 @@ class L3IP { * * @param address An IP4 multicast group address */ - virtual void add_ipv4_multicast_group(const char *address) = 0; + virtual void add_ipv4_multicast_group(const SocketAddress &address) = 0; /** Add device to an IP6 multicast group * * @param address An IP6 multicast group address */ - virtual void add_ipv6_multicast_group(const char *address) = 0; + virtual void add_ipv6_multicast_group(const SocketAddress &address) = 0; /** Remove device from an IPV4 multicast group * * @param address An IPV4 multicast group address */ - virtual void remove_ipv4_multicast_group(const char *address) = 0; + virtual void remove_ipv4_multicast_group(const SocketAddress &address) = 0; /** Remove device from an IPV6 multicast group * * @param address An IPV6 multicast group address */ - virtual void remove_ipv6_multicast_group(const char *address) = 0; + virtual void remove_ipv6_multicast_group(const SocketAddress &address) = 0; /** Request reception of all multicast packets * diff --git a/features/netsocket/NetworkInterface.cpp b/features/netsocket/NetworkInterface.cpp index ca838cc77f7..37b49747ab3 100644 --- a/features/netsocket/NetworkInterface.cpp +++ b/features/netsocket/NetworkInterface.cpp @@ -32,9 +32,14 @@ const char *NetworkInterface::get_mac_address() return 0; } +nsapi_error_t NetworkInterface::get_ip_address(SocketAddress *) +{ + return NSAPI_ERROR_UNSUPPORTED; +} + const char *NetworkInterface::get_ip_address() { - return 0; + return nullptr; } nsapi_error_t NetworkInterface::get_ipv6_link_local_address(SocketAddress *address) @@ -42,14 +47,24 @@ nsapi_error_t NetworkInterface::get_ipv6_link_local_address(SocketAddress *addre return NSAPI_ERROR_UNSUPPORTED; } +nsapi_error_t NetworkInterface::get_netmask(SocketAddress *) +{ + return NSAPI_ERROR_UNSUPPORTED; +} + const char *NetworkInterface::get_netmask() { - return 0; + return nullptr; +} + +nsapi_error_t NetworkInterface::get_gateway(SocketAddress *) +{ + return NSAPI_ERROR_UNSUPPORTED; } const char *NetworkInterface::get_gateway() { - return 0; + return nullptr; } char *NetworkInterface::get_interface_name(char *interface_name) @@ -62,6 +77,11 @@ nsapi_error_t NetworkInterface::set_network(const char *ip_address, const char * return NSAPI_ERROR_UNSUPPORTED; } +nsapi_error_t NetworkInterface::set_network(const SocketAddress &ip_address, const SocketAddress &netmask, const SocketAddress &gateway) +{ + return NSAPI_ERROR_UNSUPPORTED; +} + nsapi_error_t NetworkInterface::set_dhcp(bool dhcp) { if (!dhcp) { diff --git a/features/netsocket/NetworkInterface.h b/features/netsocket/NetworkInterface.h index ef97733d64c..a03909d7950 100644 --- a/features/netsocket/NetworkInterface.h +++ b/features/netsocket/NetworkInterface.h @@ -102,30 +102,50 @@ class NetworkInterface: public DNS { /** Get the local IP address * - * @return Null-terminated representation of the local IP address - * or null if not yet connected + * @param address SocketAddress representation of the local IP address + * @retval NSAPI_ERROR_OK on success + * @retval NSAPI_ERROR_UNSUPPORTED if this feature is not supported + * @retval NSAPI_ERROR_PARAMETER if the provided pointer is invalid + * @retval NSAPI_ERROR_NO_ADDRESS if the address cannot be obtained from stack */ + virtual nsapi_error_t get_ip_address(SocketAddress *address); + + MBED_DEPRECATED_SINCE("mbed-os-5.15", "String-based APIs are deprecated") virtual const char *get_ip_address(); /** Get the IPv6 link local address * - * @address SocketAddress representation of the link local IPv6 address - * @return NSAPI_ERROR_OK on success, negative error code on failure + * @param address SocketAddress representation of the link local IPv6 address + * @retval NSAPI_ERROR_OK on success + * @retval NSAPI_ERROR_UNSUPPORTED if this feature is not supported + * @retval NSAPI_ERROR_PARAMETER if the provided pointer is invalid */ virtual nsapi_error_t get_ipv6_link_local_address(SocketAddress *address); /** Get the local network mask. * - * @return Null-terminated representation of the local network mask - * or null if no network mask has been received. + * @param address SocketAddress representation of netmask + * @retval NSAPI_ERROR_OK on success + * @retval NSAPI_ERROR_UNSUPPORTED if this feature is not supported + * @retval NSAPI_ERROR_PARAMETER if the provided pointer is invalid + * @retval NSAPI_ERROR_NO_ADDRESS if the address cannot be obtained from stack */ + virtual nsapi_error_t get_netmask(SocketAddress *address); + + MBED_DEPRECATED_SINCE("mbed-os-5.15", "String-based APIs are deprecated") virtual const char *get_netmask(); /** Get the local gateway. * - * @return Null-terminated representation of the local gateway - * or null if no network mask has been received. + * @param address SocketAddress representation of gateway address + * @retval NSAPI_ERROR_OK on success + * @retval NSAPI_ERROR_UNSUPPORTED if this feature is not supported + * @retval NSAPI_ERROR_PARAMETER if the provided pointer is invalid + * @retval NSAPI_ERROR_NO_ADDRESS if the address cannot be obtained from stack */ + virtual nsapi_error_t get_gateway(SocketAddress *address); + + MBED_DEPRECATED_SINCE("mbed-os-5.15", "String-based APIs are deprecated") virtual const char *get_gateway(); /** Get the network interface name @@ -139,11 +159,14 @@ class NetworkInterface: public DNS { * Implicitly disables DHCP, which can be enabled in set_dhcp. * Requires that the network is disconnected. * - * @param ip_address Null-terminated representation of the local IP address - * @param netmask Null-terminated representation of the local network mask - * @param gateway Null-terminated representation of the local gateway + * @param ip_address SocketAddress object containing the local IP address + * @param netmask SocketAddress object containing the local network mask + * @param gateway SocketAddress object containing the local gateway * @return NSAPI_ERROR_OK on success, negative error code on failure */ + virtual nsapi_error_t set_network(const SocketAddress &ip_address, const SocketAddress &netmask, const SocketAddress &gateway); + + MBED_DEPRECATED_SINCE("mbed-os-5.15", "String-based APIs are deprecated") virtual nsapi_error_t set_network(const char *ip_address, const char *netmask, const char *gateway); /** Enable or disable DHCP on connecting the network. diff --git a/features/netsocket/NetworkStack.cpp b/features/netsocket/NetworkStack.cpp index 1acf4d0c47e..1d1ab07ad55 100644 --- a/features/netsocket/NetworkStack.cpp +++ b/features/netsocket/NetworkStack.cpp @@ -24,9 +24,14 @@ // Default NetworkStack operations +nsapi_error_t NetworkStack::get_ip_address(SocketAddress *address) +{ + return NSAPI_ERROR_UNSUPPORTED; +} + const char *NetworkStack::get_ip_address() { - return 0; + return nullptr; } nsapi_error_t NetworkStack::get_ipv6_link_local_address(SocketAddress *address) @@ -34,10 +39,14 @@ nsapi_error_t NetworkStack::get_ipv6_link_local_address(SocketAddress *address) return NSAPI_ERROR_UNSUPPORTED; } -const char *NetworkStack::get_ip_address_if(const char *interface_name) +nsapi_error_t NetworkStack::get_ip_address_if(SocketAddress *address, const char *interface_name) { - return 0; + return NSAPI_ERROR_UNSUPPORTED; +} +const char *NetworkStack::get_ip_address_if(const char *interface_name) +{ + return nullptr; } nsapi_error_t NetworkStack::gethostbyname(const char *name, SocketAddress *address, nsapi_version_t version, const char *interface_name) diff --git a/features/netsocket/NetworkStack.h b/features/netsocket/NetworkStack.h index 6295a8cde1c..4fbd23b3417 100644 --- a/features/netsocket/NetworkStack.h +++ b/features/netsocket/NetworkStack.h @@ -43,24 +43,38 @@ class NetworkStack: public DNS { /** Get the local IP address * - * @return Null-terminated representation of the local IP address - * or null if not yet connected + * @param address SocketAddress representation of the local IP address + * @retval NSAPI_ERROR_OK on success + * @retval NSAPI_ERROR_UNSUPPORTED if this feature is not supported + * @retval NSAPI_ERROR_PARAMETER if the provided pointer is invalid + * @retval NSAPI_ERROR_NO_ADDRESS if the address cannot be obtained from stack */ + virtual nsapi_error_t get_ip_address(SocketAddress *address); + + MBED_DEPRECATED_SINCE("mbed-os-5.15", "String-based APIs are deprecated") virtual const char *get_ip_address(); /** Get the IPv6 link local address * - * @address SocketAddress representation of the link local IPv6 address - * @return NSAPI_ERROR_OK on success, negative error code on failure + * @param address SocketAddress representation of the link local IPv6 address + * @retval NSAPI_ERROR_OK on success + * @retval NSAPI_ERROR_UNSUPPORTED if this feature is not supported + * @retval NSAPI_ERROR_PARAMETER if the provided pointer is invalid */ virtual nsapi_error_t get_ipv6_link_local_address(SocketAddress *address); /** Get the local IP address on interface name * + * @param address SocketAddress representation of the link local IPv6 address * @param interface_name Network interface_name - * @return Null-terminated representation of the local IP address - * or null if not yet connected + * @retval NSAPI_ERROR_OK on success + * @retval NSAPI_ERROR_UNSUPPORTED if this feature is not supported + * @retval NSAPI_ERROR_PARAMETER if the provided pointer is invalid + * @retval NSAPI_ERROR_NO_ADDRESS if the address cannot be obtained from stack */ + virtual nsapi_error_t get_ip_address_if(SocketAddress *address, const char *interface_name); + + MBED_DEPRECATED_SINCE("mbed-os-5.15", "String-based APIs are deprecated") virtual const char *get_ip_address_if(const char *interface_name); /** Translates a hostname to an IP address with specific version diff --git a/features/netsocket/OnboardNetworkStack.h b/features/netsocket/OnboardNetworkStack.h index 0a0c8430e5c..7a3f25d9eac 100644 --- a/features/netsocket/OnboardNetworkStack.h +++ b/features/netsocket/OnboardNetworkStack.h @@ -109,52 +109,40 @@ class OnboardNetworkStack : public NetworkStack { virtual char *get_mac_address(char *buf, nsapi_size_t buflen) = 0; - /** Copies IP address of the network interface to user supplied buffer - * - * @param buf buffer to which IP address will be copied as "W:X:Y:Z" - * @param buflen size of supplied buffer - * @param interface_name Network interface name - * @return Pointer to a buffer, or NULL if the buffer is too small - */ + /** @copydoc NetworkStack::get_ip_address */ + virtual nsapi_error_t get_ip_address(SocketAddress *address) = 0; + MBED_DEPRECATED_SINCE("mbed-os-5.15", "String-based APIs are deprecated") virtual char *get_ip_address(char *buf, nsapi_size_t buflen) = 0; - /** Copies IPv6 link local address of the network interface in SocketAddress format - * - * @address SocketAddress representation of the link local IPv6 address - * @return NSAPI_ERROR_OK on success, negative error code on failure - */ + /** @copydoc NetworkStack::get_ipv6_link_local_address */ virtual nsapi_error_t get_ipv6_link_local_address(SocketAddress *address) { return NSAPI_ERROR_UNSUPPORTED; } - /** Copies IP address of the network interface to user supplied buffer - * - * @param buf buffer to which IP address will be copied as "W:X:Y:Z" - * @param buflen size of supplied buffer - * @param interface_name Network interface name - * @return Pointer to a buffer, or NULL if the buffer is too small - */ + /** @copydoc NetworkStack::get_ip_address_if */ + virtual nsapi_error_t get_ip_address_if(SocketAddress *address, const char *interface_name) + { + return NSAPI_ERROR_UNSUPPORTED; + } + + MBED_DEPRECATED_SINCE("mbed-os-5.15", "String-based APIs are deprecated") virtual char *get_ip_address_if(char *buf, nsapi_size_t buflen, const char *interface_name) { return NULL; }; - /** Copies netmask of the network interface to user supplied buffer - * - * @param buf buffer to which netmask will be copied as "W:X:Y:Z" - * @param buflen size of supplied buffer - * @return Pointer to a buffer, or NULL if the buffer is too small - */ + /** @copydoc NetworkStack::get_netmask */ + virtual nsapi_error_t get_netmask(SocketAddress *address) = 0; + + MBED_DEPRECATED_SINCE("mbed-os-5.15", "String-based APIs are deprecated") virtual char *get_netmask(char *buf, nsapi_size_t buflen) = 0; - /** Copies gateway address of the network interface to user supplied buffer - * - * @param buf buffer to which gateway address will be copied as "W:X:Y:Z" - * @param buflen size of supplied buffer - * @return Pointer to a buffer, or NULL if the buffer is too small - */ + /** @copydoc NetworkStack::get_gateway */ + virtual nsapi_error_t get_gateway(SocketAddress *address) = 0; + + MBED_DEPRECATED_SINCE("mbed-os-5.15", "String-based APIs are deprecated") virtual char *get_gateway(char *buf, nsapi_size_t buflen) = 0; }; diff --git a/features/netsocket/TCPSocket.h b/features/netsocket/TCPSocket.h index 958dc68dca4..0da69761ab6 100644 --- a/features/netsocket/TCPSocket.h +++ b/features/netsocket/TCPSocket.h @@ -85,6 +85,7 @@ class TCPSocket : public InternetSocket { * @retval int Other negative error codes for stack-related failures. * See NetworkStack::socket_connect(). */ + MBED_DEPRECATED_SINCE("mbed-os-5.15", "String-based APIs are deprecated") nsapi_error_t connect(const char *host, uint16_t port); /** Connects TCP socket to a remote host diff --git a/features/netsocket/TLSSocket.h b/features/netsocket/TLSSocket.h index c4128062fac..4fde00379a6 100644 --- a/features/netsocket/TLSSocket.h +++ b/features/netsocket/TLSSocket.h @@ -93,6 +93,7 @@ class TLSSocket : public TLSSocketWrapper { * @return NSAPI_ERROR_OK on success, negative error code on failure. * See @ref TLSSocketWrapper::connect. */ + MBED_DEPRECATED_SINCE("mbed-os-5.15", "String-based APIs are deprecated") nsapi_error_t connect(const char *host, uint16_t port); private: diff --git a/targets/TARGET_WICED/TOOLCHAIN_ARMC6/TARGET_MTB_ADV_WISE_1530/libwiced_drivers.ar b/targets/TARGET_WICED/TOOLCHAIN_ARMC6/TARGET_MTB_ADV_WISE_1530/libwiced_drivers.ar index bd407e793aa..e4a3bb090e5 100644 Binary files a/targets/TARGET_WICED/TOOLCHAIN_ARMC6/TARGET_MTB_ADV_WISE_1530/libwiced_drivers.ar and b/targets/TARGET_WICED/TOOLCHAIN_ARMC6/TARGET_MTB_ADV_WISE_1530/libwiced_drivers.ar differ diff --git a/targets/TARGET_WICED/TOOLCHAIN_ARMC6/TARGET_MTB_MXCHIP_EMW3166/libwiced_drivers.ar b/targets/TARGET_WICED/TOOLCHAIN_ARMC6/TARGET_MTB_MXCHIP_EMW3166/libwiced_drivers.ar index 6c7966bca6a..9cb667c9316 100644 Binary files a/targets/TARGET_WICED/TOOLCHAIN_ARMC6/TARGET_MTB_MXCHIP_EMW3166/libwiced_drivers.ar and b/targets/TARGET_WICED/TOOLCHAIN_ARMC6/TARGET_MTB_MXCHIP_EMW3166/libwiced_drivers.ar differ diff --git a/targets/TARGET_WICED/TOOLCHAIN_ARMC6/TARGET_MTB_USI_WM_BN_BM_22/libwiced_drivers.ar b/targets/TARGET_WICED/TOOLCHAIN_ARMC6/TARGET_MTB_USI_WM_BN_BM_22/libwiced_drivers.ar index 27656161cde..870b702766b 100644 Binary files a/targets/TARGET_WICED/TOOLCHAIN_ARMC6/TARGET_MTB_USI_WM_BN_BM_22/libwiced_drivers.ar and b/targets/TARGET_WICED/TOOLCHAIN_ARMC6/TARGET_MTB_USI_WM_BN_BM_22/libwiced_drivers.ar differ diff --git a/targets/TARGET_WICED/TOOLCHAIN_GCC_ARM/TARGET_MTB_ADV_WISE_1530/libwiced_drivers.a b/targets/TARGET_WICED/TOOLCHAIN_GCC_ARM/TARGET_MTB_ADV_WISE_1530/libwiced_drivers.a index b669475d1af..f793f85fb45 100644 Binary files a/targets/TARGET_WICED/TOOLCHAIN_GCC_ARM/TARGET_MTB_ADV_WISE_1530/libwiced_drivers.a and b/targets/TARGET_WICED/TOOLCHAIN_GCC_ARM/TARGET_MTB_ADV_WISE_1530/libwiced_drivers.a differ diff --git a/targets/TARGET_WICED/TOOLCHAIN_GCC_ARM/TARGET_MTB_MXCHIP_EMW3166/libwiced_drivers.a b/targets/TARGET_WICED/TOOLCHAIN_GCC_ARM/TARGET_MTB_MXCHIP_EMW3166/libwiced_drivers.a index 0824444382b..ee9b4a105f6 100644 Binary files a/targets/TARGET_WICED/TOOLCHAIN_GCC_ARM/TARGET_MTB_MXCHIP_EMW3166/libwiced_drivers.a and b/targets/TARGET_WICED/TOOLCHAIN_GCC_ARM/TARGET_MTB_MXCHIP_EMW3166/libwiced_drivers.a differ diff --git a/targets/TARGET_WICED/TOOLCHAIN_GCC_ARM/TARGET_MTB_USI_WM_BN_BM_22/libwiced_drivers.a b/targets/TARGET_WICED/TOOLCHAIN_GCC_ARM/TARGET_MTB_USI_WM_BN_BM_22/libwiced_drivers.a index 2152d5aaaf7..fa57d49f102 100644 Binary files a/targets/TARGET_WICED/TOOLCHAIN_GCC_ARM/TARGET_MTB_USI_WM_BN_BM_22/libwiced_drivers.a and b/targets/TARGET_WICED/TOOLCHAIN_GCC_ARM/TARGET_MTB_USI_WM_BN_BM_22/libwiced_drivers.a differ diff --git a/targets/TARGET_WICED/TOOLCHAIN_IAR/TARGET_MTB_ADV_WISE_1530/libwiced_drivers.a b/targets/TARGET_WICED/TOOLCHAIN_IAR/TARGET_MTB_ADV_WISE_1530/libwiced_drivers.a index ad4ba05e33a..3322edf55a6 100644 Binary files a/targets/TARGET_WICED/TOOLCHAIN_IAR/TARGET_MTB_ADV_WISE_1530/libwiced_drivers.a and b/targets/TARGET_WICED/TOOLCHAIN_IAR/TARGET_MTB_ADV_WISE_1530/libwiced_drivers.a differ diff --git a/targets/TARGET_WICED/TOOLCHAIN_IAR/TARGET_MTB_MXCHIP_EMW3166/libwiced_drivers.a b/targets/TARGET_WICED/TOOLCHAIN_IAR/TARGET_MTB_MXCHIP_EMW3166/libwiced_drivers.a index c7ccb22bc89..67dfdc61787 100644 Binary files a/targets/TARGET_WICED/TOOLCHAIN_IAR/TARGET_MTB_MXCHIP_EMW3166/libwiced_drivers.a and b/targets/TARGET_WICED/TOOLCHAIN_IAR/TARGET_MTB_MXCHIP_EMW3166/libwiced_drivers.a differ diff --git a/targets/TARGET_WICED/TOOLCHAIN_IAR/TARGET_MTB_USI_WM_BN_BM_22/libwiced_drivers.a b/targets/TARGET_WICED/TOOLCHAIN_IAR/TARGET_MTB_USI_WM_BN_BM_22/libwiced_drivers.a index fed1f7c72a4..b91a343df67 100644 Binary files a/targets/TARGET_WICED/TOOLCHAIN_IAR/TARGET_MTB_USI_WM_BN_BM_22/libwiced_drivers.a and b/targets/TARGET_WICED/TOOLCHAIN_IAR/TARGET_MTB_USI_WM_BN_BM_22/libwiced_drivers.a differ