Deprecate string-based APIs in IPCore

MBED_DEPRECATE macros is added to string-based APIs.
New, non-string-based APIs are added in their place.
Wiced binaries rebuilt
Any existing stubs or mocks are adjusted to compile and run with the newly added non-string based functions.
pull/11914/head
Michal Paszta 2019-11-19 12:36:00 +02:00
parent 9dc0c3737e
commit fd5b4b9119
46 changed files with 519 additions and 108 deletions

View File

@ -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;

View File

@ -92,6 +92,9 @@ public:
* @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 @@ public:
* @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 @@ public:
* @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:

View File

@ -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)
{
}

View File

@ -91,25 +91,25 @@ public:
*
* @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
*

View File

@ -72,6 +72,10 @@ public:
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 @@ public:
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;

View File

@ -93,10 +93,13 @@ public:
MOCK_METHOD1(attach, void(mbed::Callback<void(nsapi_event_t, intptr_t)> 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));
};
};

View File

@ -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

View File

@ -89,8 +89,11 @@ public:
MOCK_METHOD1(attach, void(mbed::Callback<void(nsapi_event_t, intptr_t)> 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));
};
};

View File

@ -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;

View File

@ -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;

View File

@ -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)

View File

@ -89,6 +89,11 @@ nsapi_error_t NetworkStack::call_in(int delay, mbed::Callback<void()> 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;

View File

@ -37,6 +37,11 @@ public:
{
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)
{

View File

@ -97,6 +97,11 @@ public:
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 @@ public:
};
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;

View File

@ -121,6 +121,8 @@ protected:
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 @@ public: // from NetworkInterface
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;

View File

@ -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

View File

@ -35,6 +35,7 @@ public:
// 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<void(nsapi_event_t, intptr_t)> status_cb);
@ -48,7 +49,9 @@ public:
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

View File

@ -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();

View File

@ -43,6 +43,9 @@ public:
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();
/**

View File

@ -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

View File

@ -93,12 +93,10 @@ public:
*/
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 @@ public:
* @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 @@ public:
* @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 @@ public:
* @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:

View File

@ -25,9 +25,15 @@
class Nanostack::Interface : public OnboardNetworkStack::Interface, private mbed::NonCopyable<Nanostack::Interface> {
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<void(nsapi_event_t, intptr_t)> status_cb);
virtual nsapi_connection_status_t get_connection_status() const;
@ -99,9 +105,10 @@ public:
*/
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 @@ protected:
Nanostack::Interface *_interface;
char ip_addr_str[40];
SocketAddress ip_addr;
char mac_addr_str[24];
mbed::Callback<void(nsapi_event_t, intptr_t)> _connection_status_cb;
bool _blocking;

View File

@ -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;
}

View File

@ -95,25 +95,22 @@ public:
*/
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

View File

@ -97,6 +97,7 @@ public:
* @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:

View File

@ -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;
}
return 0;
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 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)

View File

@ -64,6 +64,9 @@ public:
* @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 @@ public:
* @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 @@ public:
* @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 @@ public:
* @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

View File

@ -47,6 +47,7 @@ public:
* @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);

View File

@ -106,6 +106,7 @@ public:
* @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

View File

@ -21,7 +21,7 @@
#include <stdbool.h>
#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 @@ public:
*
* @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
*

View File

@ -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) {

View File

@ -102,30 +102,50 @@ public:
/** 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 @@ public:
* 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.

View File

@ -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;
}
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 0;
return nullptr;
}
nsapi_error_t NetworkStack::gethostbyname(const char *name, SocketAddress *address, nsapi_version_t version, const char *interface_name)

View File

@ -43,24 +43,38 @@ public:
/** 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

View File

@ -109,52 +109,40 @@ public:
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;
};

View File

@ -85,6 +85,7 @@ public:
* @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

View File

@ -93,6 +93,7 @@ public:
* @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: