mirror of https://github.com/ARMmbed/mbed-os.git
Merge pull request #11941 from michalpasztamobica/remove_internal_string_apis
Remove string-based API usage within mbed-ospull/11979/head
commit
ffdd54315f
|
@ -221,8 +221,6 @@ Please refer to the following table for priorities of test cases. Priorities are
|
|||
| 4 | UDPSOCKET_OPEN_CLOSE_REPEAT | MUST |
|
||||
| 5 | UDPSOCKET_BIND_PORT | SHOULD |
|
||||
| 6 | UDPSOCKET_BIND_PORT_FAIL | SHOULD |
|
||||
| 7 | UDPSOCKET_BIND_ADDRESS_PORT | SHOULD |
|
||||
| 8 | UDPSOCKET_BIND_ADDRESS_NULL | SHOULD |
|
||||
| 9 | UDPSOCKET_BIND_ADDRESS_INVALID | SHOULD |
|
||||
| 10 | UDPSOCKET_BIND_WRONG_TYPE | SHOULD |
|
||||
| 11 | UDPSOCKET_BIND_ADDRESS | SHOULD |
|
||||
|
@ -239,8 +237,6 @@ Please refer to the following table for priorities of test cases. Priorities are
|
|||
| 22 | TCPSOCKET_OPEN_CLOSE_REPEAT | MUST |
|
||||
| 23 | TCPSOCKET_BIND_PORT | SHOULD |
|
||||
| 24 | TCPSOCKET_BIND_PORT_FAIL | SHOULD |
|
||||
| 25 | TCPSOCKET_BIND_ADDRESS_PORT | SHOULD |
|
||||
| 26 | TCPSOCKET_BIND_ADDRESS_NULL | SHOULD |
|
||||
| 27 | TCPSOCKET_BIND_ADDRESS_INVALID | SHOULD |
|
||||
| 28 | TCPSOCKET_BIND_WRONG_TYPE | SHOULD |
|
||||
| 29 | TCPSOCKET_BIND_ADDRESS | SHOULD |
|
||||
|
@ -617,51 +613,6 @@ Call `Socket::bind(port)` on a port number that is already used.
|
|||
|
||||
The second `Socket::bind()` returns `NSAPI_ERROR_PARAMETER`.
|
||||
|
||||
### SOCKET_BIND_ADDRESS_PORT
|
||||
|
||||
**Description:**
|
||||
|
||||
Call `Socket::bind(addr, port)`.
|
||||
|
||||
**Preconditions:**
|
||||
|
||||
1. Network interface and stack are initialized.
|
||||
1. Network connection is up.
|
||||
|
||||
**Test steps:**
|
||||
|
||||
1. Create an object by calling `new Socket()`.
|
||||
1. Call `Socket::open(stack)`.
|
||||
1. Get address by calling `NetworkInterface::get_ip_address()`.
|
||||
1. Call `Socket::bind(address, <any unused port number>);`.
|
||||
1. Destroy the socket.
|
||||
|
||||
**Expected result:**
|
||||
|
||||
All calls return `NSAPI_ERROR_OK`.
|
||||
|
||||
### SOCKET_BIND_ADDRESS_NULL
|
||||
|
||||
**Description:**
|
||||
|
||||
Call `Socket::bind(NULL, port)`.
|
||||
|
||||
**Preconditions:**
|
||||
|
||||
1. Network interface and stack are initialized.
|
||||
1. Network connection is up.
|
||||
|
||||
**Test steps:**
|
||||
|
||||
1. Create an object by calling `new Socket()`.
|
||||
1. Call `Socket::open(stack)`.
|
||||
1. Call `Socket::bind(NULL, <any unused port number>);`.
|
||||
1. Destroy the socket.
|
||||
|
||||
**Expected result:**
|
||||
|
||||
`Socket::bind()` returns `NSAPI_ERROR_OK`.
|
||||
|
||||
### SOCKET_BIND_ADDRESS_INVALID
|
||||
|
||||
**Description:**
|
||||
|
@ -783,14 +734,6 @@ Test cases for UDPSocket class
|
|||
|
||||
**Description:** Run `SOCKET_BIND_PORT_FAIL` for UDPSocket.
|
||||
|
||||
### UDPSOCKET_BIND_ADDRESS_PORT
|
||||
|
||||
**Description:** Run `SOCKET_BIND_ADDRESS_PORT` for UDPSocket.
|
||||
|
||||
### UDPSOCKET_BIND_ADDRESS_NULL
|
||||
|
||||
**Description:** Run `SOCKET_BIND_ADDRESS_NULL` for UDPSocket.
|
||||
|
||||
### UDPSOCKET_BIND_ADDRESS_INVALID
|
||||
|
||||
**Description:** Run `SOCKET_BIND_ADDRESS_INVALID` for UDPSocket.
|
||||
|
@ -807,34 +750,6 @@ Test cases for UDPSocket class
|
|||
|
||||
**Description:** Run `SOCKET_BIND_UNOPENED` for UDPSocket.
|
||||
|
||||
### UDPSOCKET_SENDTO_INVALID
|
||||
|
||||
**Description:**
|
||||
|
||||
Call `UDPSocket::sendto()` with invalid parameters.
|
||||
|
||||
**Preconditions:**
|
||||
|
||||
1. Network interface and stack are initialized.
|
||||
1. Network connection is up.
|
||||
1. UDPSocket is open.
|
||||
|
||||
**Test steps:**
|
||||
|
||||
1. Call `UDPSocket:sendto( NULL, 9, NULL, 0);`.
|
||||
1. Call `UDPSocket:sendto( "", 9, NULL, 0);`.
|
||||
1. Call `UDPSocket:sendto( "", 0, NULL, 0);`.
|
||||
1. Call `UDPSocket:sendto("echo.mbedcloudtesting.com", 9,NULL, 0);`.
|
||||
1. Call `UDPSocket:sendto("echo.mbedcloudtesting.com", 9, "hello", 5);`.
|
||||
1. Destroy the socket.
|
||||
|
||||
**Expected result:**
|
||||
|
||||
All `sendto()` calls return an error code except:
|
||||
|
||||
- Step 4 returns 0.
|
||||
- Step 5 returns 5.
|
||||
|
||||
### UDPSOCKET_SENDTO_REPEAT
|
||||
|
||||
**Description:**
|
||||
|
@ -1000,14 +915,6 @@ Test cases for TCPSocket class
|
|||
|
||||
**Description:** Run `SOCKET_BIND_PORT_FAIL` for TCPSocket.
|
||||
|
||||
### TCPSOCKET_BIND_ADDRESS_PORT
|
||||
|
||||
**Description:** Run `SOCKET_BIND_ADDRESS_PORT` for TCPSocket.
|
||||
|
||||
### TCPSOCKET_BIND_ADDRESS_NULL
|
||||
|
||||
**Description:** Run `SOCKET_BIND_ADDRESS_NULL` for TCPSocket.
|
||||
|
||||
### TCPSOCKET_BIND_ADDRESS_INVALID
|
||||
|
||||
**Description:** Run `SOCKET_BIND_ADDRESS_INVALID` for TCPSocket.
|
||||
|
|
|
@ -166,7 +166,8 @@ static void net_bringup()
|
|||
net = NetworkInterface::get_default_instance();
|
||||
nsapi_error_t err = net->connect();
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, err);
|
||||
const char *address = net->get_ip_address();
|
||||
SocketAddress address;
|
||||
net->get_ip_address(&address);
|
||||
|
||||
#define MESH 3
|
||||
#if MBED_CONF_TARGET_NETWORK_DEFAULT_INTERFACE_TYPE == MESH
|
||||
|
@ -175,7 +176,7 @@ static void net_bringup()
|
|||
ThisThread::sleep_for(500);
|
||||
}
|
||||
#endif
|
||||
printf("MBED: IP address is '%s'\n", address ? address : "null");
|
||||
printf("MBED: IP address is '%s'\n", address ? address.get_ip_address() : "null");
|
||||
}
|
||||
|
||||
static void net_bringdown()
|
||||
|
|
|
@ -66,7 +66,7 @@ void drop_bad_packets(TCPSocket &sock, int orig_timeout)
|
|||
nsapi_version_t get_ip_version()
|
||||
{
|
||||
SocketAddress test;
|
||||
if (!test.set_ip_address(NetworkInterface::get_default_instance()->get_ip_address())) {
|
||||
if (NetworkInterface::get_default_instance()->get_ip_address(&test) != NSAPI_ERROR_OK) {
|
||||
return NSAPI_UNSPEC;
|
||||
}
|
||||
return test.get_ip_version();
|
||||
|
@ -77,7 +77,8 @@ static void _ifup()
|
|||
NetworkInterface *net = NetworkInterface::get_default_instance();
|
||||
nsapi_error_t err = net->connect();
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, err);
|
||||
const char *address = net->get_ip_address();
|
||||
SocketAddress address;
|
||||
net->get_ip_address(&address);
|
||||
|
||||
#define MESH 3
|
||||
#if MBED_CONF_TARGET_NETWORK_DEFAULT_INTERFACE_TYPE == MESH
|
||||
|
@ -86,7 +87,7 @@ static void _ifup()
|
|||
ThisThread::sleep_for(500);
|
||||
}
|
||||
#endif
|
||||
printf("MBED: TCPClient IP address is '%s'\n", address ? address : "null");
|
||||
printf("MBED: TCPClient IP address is '%s'\n", address ? address.get_ip_address() : "null");
|
||||
}
|
||||
|
||||
static void _ifdown()
|
||||
|
@ -221,8 +222,6 @@ Case cases[] = {
|
|||
Case("TCPSOCKET_OPEN_TWICE", TCPSOCKET_OPEN_TWICE),
|
||||
Case("TCPSOCKET_BIND_PORT", TCPSOCKET_BIND_PORT),
|
||||
Case("TCPSOCKET_BIND_PORT_FAIL", TCPSOCKET_BIND_PORT_FAIL),
|
||||
Case("TCPSOCKET_BIND_ADDRESS_PORT", TCPSOCKET_BIND_ADDRESS_PORT),
|
||||
Case("TCPSOCKET_BIND_ADDRESS_NULL", TCPSOCKET_BIND_ADDRESS_NULL),
|
||||
Case("TCPSOCKET_BIND_ADDRESS_INVALID", TCPSOCKET_BIND_ADDRESS_INVALID),
|
||||
Case("TCPSOCKET_BIND_ADDRESS", TCPSOCKET_BIND_ADDRESS),
|
||||
Case("TCPSOCKET_BIND_WRONG_TYPE", TCPSOCKET_BIND_WRONG_TYPE),
|
||||
|
|
|
@ -34,7 +34,9 @@ void TCPSOCKET_BIND_ADDRESS()
|
|||
return;
|
||||
}
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(NetworkInterface::get_default_instance()));
|
||||
SocketAddress sockAddr = SocketAddress(NetworkInterface::get_default_instance()->get_ip_address(), 80);
|
||||
SocketAddress sockAddr;
|
||||
NetworkInterface::get_default_instance()->get_ip_address(&sockAddr);
|
||||
sockAddr.set_port(80);
|
||||
nsapi_error_t bind_result = sock->bind(sockAddr);
|
||||
if (bind_result == NSAPI_ERROR_UNSUPPORTED) {
|
||||
TEST_IGNORE_MESSAGE("bind() not supported");
|
||||
|
|
|
@ -29,17 +29,16 @@ using namespace utest::v1;
|
|||
void TCPSOCKET_BIND_ADDRESS_INVALID()
|
||||
{
|
||||
SKIP_IF_TCP_UNSUPPORTED();
|
||||
TCPSocket *sock = new TCPSocket;
|
||||
if (!sock) {
|
||||
TEST_FAIL();
|
||||
return;
|
||||
}
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(NetworkInterface::get_default_instance()));
|
||||
TCPSocket sock;
|
||||
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(NetworkInterface::get_default_instance()));
|
||||
nsapi_error_t bind_result = NSAPI_ERROR_OK;
|
||||
if (get_ip_version() == NSAPI_IPv4) {
|
||||
bind_result = sock->bind("190.2.3.4", 1024);
|
||||
SocketAddress a("190.2.3.4", 1024);
|
||||
bind_result = sock.bind(a);
|
||||
} else if (get_ip_version() == NSAPI_IPv6) {
|
||||
bind_result = sock->bind("fe80::ff01", 1024);
|
||||
SocketAddress a("fe80::ff01", 1024);
|
||||
bind_result = sock.bind(a);
|
||||
} else {
|
||||
TEST_FAIL_MESSAGE("This stack is neither IPv4 nor IPv6");
|
||||
}
|
||||
|
@ -48,7 +47,5 @@ void TCPSOCKET_BIND_ADDRESS_INVALID()
|
|||
} else {
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_PARAMETER, bind_result);
|
||||
}
|
||||
|
||||
delete sock;
|
||||
}
|
||||
#endif // defined(MBED_CONF_RTOS_PRESENT)
|
||||
|
|
|
@ -1,46 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2018, ARM Limited, All Rights Reserved
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#if defined(MBED_CONF_RTOS_PRESENT)
|
||||
#include "greentea-client/test_env.h"
|
||||
#include "mbed.h"
|
||||
#include "tcp_tests.h"
|
||||
#include "TCPSocket.h"
|
||||
#include "unity/unity.h"
|
||||
#include "utest.h"
|
||||
|
||||
using namespace utest::v1;
|
||||
|
||||
void TCPSOCKET_BIND_ADDRESS_NULL()
|
||||
{
|
||||
SKIP_IF_TCP_UNSUPPORTED();
|
||||
TCPSocket *sock = new TCPSocket;
|
||||
if (!sock) {
|
||||
TEST_FAIL();
|
||||
return;
|
||||
}
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(NetworkInterface::get_default_instance()));
|
||||
nsapi_error_t bind_result = sock->bind(NULL, 1024);
|
||||
if (bind_result == NSAPI_ERROR_UNSUPPORTED) {
|
||||
TEST_IGNORE_MESSAGE("bind() not supported");
|
||||
} else {
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, bind_result);
|
||||
}
|
||||
|
||||
delete sock;
|
||||
}
|
||||
#endif // defined(MBED_CONF_RTOS_PRESENT)
|
|
@ -1,46 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2018, ARM Limited, All Rights Reserved
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#if defined(MBED_CONF_RTOS_PRESENT)
|
||||
#include "greentea-client/test_env.h"
|
||||
#include "mbed.h"
|
||||
#include "tcp_tests.h"
|
||||
#include "TCPSocket.h"
|
||||
#include "unity/unity.h"
|
||||
#include "utest.h"
|
||||
|
||||
using namespace utest::v1;
|
||||
|
||||
void TCPSOCKET_BIND_ADDRESS_PORT()
|
||||
{
|
||||
SKIP_IF_TCP_UNSUPPORTED();
|
||||
TCPSocket *sock = new TCPSocket;
|
||||
if (!sock) {
|
||||
TEST_FAIL();
|
||||
return;
|
||||
}
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(NetworkInterface::get_default_instance()));
|
||||
nsapi_error_t bind_result = sock->bind(NetworkInterface::get_default_instance()->get_ip_address(), 80);
|
||||
if (bind_result == NSAPI_ERROR_UNSUPPORTED) {
|
||||
TEST_IGNORE_MESSAGE("bind() not supported");
|
||||
} else {
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, bind_result);
|
||||
}
|
||||
|
||||
delete sock;
|
||||
}
|
||||
#endif // defined(MBED_CONF_RTOS_PRESENT)
|
|
@ -28,12 +28,9 @@ using namespace utest::v1;
|
|||
void TCPSOCKET_BIND_WRONG_TYPE()
|
||||
{
|
||||
SKIP_IF_TCP_UNSUPPORTED();
|
||||
TCPSocket *sock = new TCPSocket;
|
||||
if (!sock) {
|
||||
TEST_FAIL();
|
||||
return;
|
||||
}
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(NetworkInterface::get_default_instance()));
|
||||
TCPSocket sock;
|
||||
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(NetworkInterface::get_default_instance()));
|
||||
char addr_bytes[16] = {0xfe, 0x80, 0xff, 0x1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
|
||||
SocketAddress sockAddr;
|
||||
if (get_ip_version() == NSAPI_IPv4) {
|
||||
|
@ -43,13 +40,11 @@ void TCPSOCKET_BIND_WRONG_TYPE()
|
|||
} else {
|
||||
TEST_FAIL_MESSAGE("This stack is neither IPv4 nor IPv6");
|
||||
}
|
||||
nsapi_error_t bind_result = sock->bind(sockAddr);
|
||||
nsapi_error_t bind_result = sock.bind(sockAddr);
|
||||
if (bind_result == NSAPI_ERROR_UNSUPPORTED) {
|
||||
TEST_IGNORE_MESSAGE("bind() not supported");
|
||||
} else {
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_PARAMETER, bind_result);
|
||||
}
|
||||
|
||||
delete sock;
|
||||
}
|
||||
#endif // defined(MBED_CONF_RTOS_PRESENT)
|
||||
|
|
|
@ -31,10 +31,15 @@ void TCPSOCKET_CONNECT_INVALID()
|
|||
TCPSocket sock;
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(NetworkInterface::get_default_instance()));
|
||||
|
||||
TEST_ASSERT(sock.connect(NULL, 9) < 0);
|
||||
TEST_ASSERT(sock.connect("", 9) < 0);
|
||||
TEST_ASSERT(sock.connect("", 0) < 0);
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.connect(ECHO_SERVER_ADDR, ECHO_SERVER_DISCARD_PORT));
|
||||
SocketAddress address;
|
||||
address.set_port(9);
|
||||
|
||||
TEST_ASSERT_FALSE(address.set_ip_address(NULL));
|
||||
|
||||
// Valid address for the final check
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, NetworkInterface::get_default_instance()->gethostbyname(ECHO_SERVER_ADDR, &address));
|
||||
address.set_port(ECHO_SERVER_DISCARD_PORT);
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.connect(address));
|
||||
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.close());
|
||||
}
|
||||
|
|
|
@ -41,7 +41,10 @@ void TCPSOCKET_SETSOCKOPT_KEEPALIVE_VALID()
|
|||
}
|
||||
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, ret);
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.connect(ECHO_SERVER_ADDR, 9));
|
||||
SocketAddress address;
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, NetworkInterface::get_default_instance()->gethostbyname(ECHO_SERVER_ADDR, &address));
|
||||
address.set_port(9);
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.connect(address));
|
||||
// LWIP stack does not support getsockopt so the part below is commented out
|
||||
// int32_t optval;
|
||||
// unsigned int optlen;
|
||||
|
|
|
@ -71,7 +71,8 @@ static void _ifup()
|
|||
NetworkInterface *net = NetworkInterface::get_default_instance();
|
||||
nsapi_error_t err = net->connect();
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, err);
|
||||
const char *address = net->get_ip_address();
|
||||
SocketAddress address;
|
||||
net->get_ip_address(&address);
|
||||
|
||||
#define MESH 3
|
||||
#if MBED_CONF_TARGET_NETWORK_DEFAULT_INTERFACE_TYPE == MESH
|
||||
|
@ -80,7 +81,7 @@ static void _ifup()
|
|||
ThisThread::sleep_for(500);
|
||||
}
|
||||
#endif
|
||||
printf("MBED: TLSClient address is '%s'\n", address ? address : "null");
|
||||
printf("MBED: TLSClient address is '%s'\n", address ? address.get_ip_address() : "null");
|
||||
}
|
||||
|
||||
static void _ifdown()
|
||||
|
|
|
@ -33,12 +33,11 @@ void TLSSOCKET_CONNECT_INVALID()
|
|||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(NetworkInterface::get_default_instance()));
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.set_root_ca_cert(tls_global::cert));
|
||||
|
||||
TEST_ASSERT(sock.connect(NULL, ECHO_SERVER_DISCARD_PORT_TLS) < 0);
|
||||
TEST_ASSERT(sock.connect("", ECHO_SERVER_DISCARD_PORT_TLS) < 0);
|
||||
TEST_ASSERT(sock.connect("", 0) < 0);
|
||||
SocketAddress address;
|
||||
// ism43362 returns DEVICE_ERROR, but LWIP returns NO_CONNECTION.
|
||||
TEST_ASSERT_TRUE(sock.connect(address) < 0);
|
||||
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK,
|
||||
sock.connect(ECHO_SERVER_ADDR, ECHO_SERVER_DISCARD_PORT_TLS));
|
||||
// If connect returns an error socket is in unspecified state.
|
||||
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.close());
|
||||
}
|
||||
|
|
|
@ -30,24 +30,49 @@ void TLSSOCKET_HANDSHAKE_INVALID()
|
|||
{
|
||||
const int https_port = 443;
|
||||
SKIP_IF_TCP_UNSUPPORTED();
|
||||
NetworkInterface *net = NetworkInterface::get_default_instance();
|
||||
|
||||
#if (MBED_CONF_NSAPI_DEFAULT_STACK == NANOSTACK || (MBED_CONF_NSAPI_DEFAULT_STACK == LWIP && defined(MBED_CONF_LWIP_PPP_IPV6_ENABLED)))
|
||||
SocketAddress address;
|
||||
nsapi_error_t result = NetworkInterface::get_default_instance()->gethostbyname("expired.badssl.com", &address);
|
||||
nsapi_error_t result = net->gethostbyname("expired.badssl.com", &address);
|
||||
if (result != NSAPI_ERROR_OK) {
|
||||
TEST_SKIP_MESSAGE(" badssl.com not supported IP6 AAA records");
|
||||
}
|
||||
#endif
|
||||
TLSSocket sock;
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(NetworkInterface::get_default_instance()));
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(net));
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.set_root_ca_cert(tls_global::cert));
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_AUTH_FAILURE, sock.connect("expired.badssl.com", https_port));
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_AUTH_FAILURE, sock.connect("wrong.host.badssl.com", https_port));
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_AUTH_FAILURE, sock.connect("self-signed.badssl.com", https_port));
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_AUTH_FAILURE, sock.connect("untrusted-root.badssl.com", https_port));
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_AUTH_FAILURE, sock.connect("revoked.badssl.com", https_port));
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_AUTH_FAILURE, sock.connect("pinning-test.badssl.com", https_port));
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_AUTH_FAILURE, sock.connect("sha1-intermediate.badssl.com", https_port));
|
||||
|
||||
SocketAddress a;
|
||||
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, net->gethostbyname("expired.badssl.com", &a));
|
||||
a.set_port(https_port);
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_AUTH_FAILURE, sock.connect(a));
|
||||
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, net->gethostbyname("wrong.host.badssl.com", &a));
|
||||
a.set_port(https_port);
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_AUTH_FAILURE, sock.connect(a));
|
||||
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, net->gethostbyname("self-signed.badssl.com", &a));
|
||||
a.set_port(https_port);
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_AUTH_FAILURE, sock.connect(a));
|
||||
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, net->gethostbyname("untrusted-root.badssl.com", &a));
|
||||
a.set_port(https_port);
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_AUTH_FAILURE, sock.connect(a));
|
||||
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, net->gethostbyname("revoked.badssl.com", &a));
|
||||
a.set_port(https_port);
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_AUTH_FAILURE, sock.connect(a));
|
||||
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, net->gethostbyname("pinning-test.badssl.com", &a));
|
||||
a.set_port(https_port);
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_AUTH_FAILURE, sock.connect(a));
|
||||
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, net->gethostbyname("sha1-intermediate.badssl.com", &a));
|
||||
a.set_port(https_port);
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_AUTH_FAILURE, sock.connect(a));
|
||||
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.close());
|
||||
}
|
||||
|
||||
|
|
|
@ -31,8 +31,11 @@ void TLSSOCKET_NO_CERT()
|
|||
SKIP_IF_TCP_UNSUPPORTED();
|
||||
TLSSocket sock;
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(NetworkInterface::get_default_instance()));
|
||||
SocketAddress a;
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, NetworkInterface::get_default_instance()->gethostbyname(ECHO_SERVER_ADDR, &a));
|
||||
a.set_port(ECHO_SERVER_PORT_TLS);
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_AUTH_FAILURE,
|
||||
sock.connect(ECHO_SERVER_ADDR, ECHO_SERVER_PORT_TLS));
|
||||
sock.connect(a));
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.close());
|
||||
}
|
||||
|
||||
|
|
|
@ -32,8 +32,10 @@ void TLSSOCKET_SEND_CLOSED()
|
|||
TLSSocket sock;
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(NetworkInterface::get_default_instance()));
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.set_root_ca_cert(tls_global::cert));
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK,
|
||||
sock.connect(ECHO_SERVER_ADDR, ECHO_SERVER_PORT_TLS));
|
||||
SocketAddress a;
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, NetworkInterface::get_default_instance()->gethostbyname(ECHO_SERVER_ADDR, &a));
|
||||
a.set_port(ECHO_SERVER_PORT_TLS);
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.connect(a));
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.close());
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_NO_SOCKET, sock.send("12345", 5));
|
||||
}
|
||||
|
|
|
@ -64,7 +64,8 @@ static void _ifup()
|
|||
NetworkInterface *net = NetworkInterface::get_default_instance();
|
||||
nsapi_error_t err = net->connect();
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, err);
|
||||
const char *address = net->get_ip_address();
|
||||
SocketAddress address;
|
||||
net->get_ip_address(&address);
|
||||
|
||||
#define MESH 3
|
||||
#if MBED_CONF_TARGET_NETWORK_DEFAULT_INTERFACE_TYPE == MESH
|
||||
|
@ -73,7 +74,7 @@ static void _ifup()
|
|||
ThisThread::sleep_for(500);
|
||||
}
|
||||
#endif
|
||||
printf("MBED: UDPClient IP address is '%s'\n", address ? address : "null");
|
||||
printf("MBED: UDPClient IP address is '%s'\n", address ? address.get_ip_address() : "null");
|
||||
}
|
||||
|
||||
static void _ifdown()
|
||||
|
@ -86,7 +87,7 @@ static void _ifdown()
|
|||
nsapi_version_t get_ip_version()
|
||||
{
|
||||
SocketAddress test;
|
||||
if (!test.set_ip_address(NetworkInterface::get_default_instance()->get_ip_address())) {
|
||||
if (NetworkInterface::get_default_instance()->get_ip_address(&test) != NSAPI_ERROR_OK) {
|
||||
return NSAPI_UNSPEC;
|
||||
}
|
||||
return test.get_ip_version();
|
||||
|
@ -186,13 +187,10 @@ Case cases[] = {
|
|||
Case("UDPSOCKET_OPEN_TWICE", UDPSOCKET_OPEN_TWICE),
|
||||
Case("UDPSOCKET_BIND_PORT", UDPSOCKET_BIND_PORT),
|
||||
Case("UDPSOCKET_BIND_PORT_FAIL", UDPSOCKET_BIND_PORT_FAIL),
|
||||
Case("UDPSOCKET_BIND_ADDRESS_PORT", UDPSOCKET_BIND_ADDRESS_PORT),
|
||||
Case("UDPSOCKET_BIND_ADDRESS_NULL", UDPSOCKET_BIND_ADDRESS_NULL),
|
||||
Case("UDPSOCKET_BIND_ADDRESS_INVALID", UDPSOCKET_BIND_ADDRESS_INVALID),
|
||||
Case("UDPSOCKET_BIND_ADDRESS", UDPSOCKET_BIND_ADDRESS),
|
||||
Case("UDPSOCKET_BIND_WRONG_TYPE", UDPSOCKET_BIND_WRONG_TYPE),
|
||||
Case("UDPSOCKET_BIND_UNOPENED", UDPSOCKET_BIND_UNOPENED),
|
||||
Case("UDPSOCKET_SENDTO_INVALID", UDPSOCKET_SENDTO_INVALID),
|
||||
Case("UDPSOCKET_ECHOTEST_NONBLOCK", UDPSOCKET_ECHOTEST_NONBLOCK),
|
||||
Case("UDPSOCKET_ECHOTEST_BURST_NONBLOCK", UDPSOCKET_ECHOTEST_BURST_NONBLOCK),
|
||||
Case("UDPSOCKET_SENDTO_REPEAT", UDPSOCKET_SENDTO_REPEAT),
|
||||
|
|
|
@ -31,7 +31,9 @@ void UDPSOCKET_BIND_ADDRESS()
|
|||
TEST_FAIL();
|
||||
}
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(NetworkInterface::get_default_instance()));
|
||||
SocketAddress sockAddr = SocketAddress(NetworkInterface::get_default_instance()->get_ip_address(), 80);
|
||||
SocketAddress sockAddr;
|
||||
NetworkInterface::get_default_instance()->get_ip_address(&sockAddr);
|
||||
sockAddr.set_port(80);
|
||||
nsapi_error_t bind_result = sock->bind(sockAddr);
|
||||
if (bind_result == NSAPI_ERROR_UNSUPPORTED) {
|
||||
TEST_IGNORE_MESSAGE("bind() not supported");
|
||||
|
|
|
@ -34,9 +34,11 @@ void UDPSOCKET_BIND_ADDRESS_INVALID()
|
|||
|
||||
nsapi_error_t bind_result = NSAPI_ERROR_OK;
|
||||
if (get_ip_version() == NSAPI_IPv4) {
|
||||
bind_result = sock->bind("190.2.3.4", 1024);
|
||||
SocketAddress a("190.2.3.4", 1024);
|
||||
bind_result = sock->bind(a);
|
||||
} else if (get_ip_version() == NSAPI_IPv6) {
|
||||
bind_result = sock->bind("fe80::ff01", 1024);
|
||||
SocketAddress a("fe80::ff01", 1024);
|
||||
bind_result = sock->bind(a);
|
||||
} else {
|
||||
TEST_FAIL_MESSAGE("This stack is neither IPv4 nor IPv6");
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ void UDPSOCKET_BIND_ADDRESS_NULL()
|
|||
TEST_FAIL();
|
||||
}
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(NetworkInterface::get_default_instance()));
|
||||
nsapi_error_t bind_result = sock->bind(NULL, 1024);
|
||||
nsapi_error_t bind_result = sock->bind(nullptr);
|
||||
if (bind_result == NSAPI_ERROR_UNSUPPORTED) {
|
||||
TEST_IGNORE_MESSAGE("bind() not supported");
|
||||
} else {
|
||||
|
|
|
@ -1,42 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2018, ARM Limited, All Rights Reserved
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "greentea-client/test_env.h"
|
||||
#include "mbed.h"
|
||||
#include "udp_tests.h"
|
||||
#include "UDPSocket.h"
|
||||
#include "unity/unity.h"
|
||||
#include "utest.h"
|
||||
|
||||
using namespace utest::v1;
|
||||
|
||||
void UDPSOCKET_BIND_ADDRESS_PORT()
|
||||
{
|
||||
UDPSocket *sock = new UDPSocket;
|
||||
if (!sock) {
|
||||
TEST_FAIL();
|
||||
}
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(NetworkInterface::get_default_instance()));
|
||||
nsapi_error_t bind_result = sock->bind(NetworkInterface::get_default_instance()->get_ip_address(), 80);
|
||||
if (bind_result == NSAPI_ERROR_UNSUPPORTED) {
|
||||
TEST_IGNORE_MESSAGE("bind() not supported");
|
||||
} else {
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, bind_result);
|
||||
}
|
||||
|
||||
delete sock;
|
||||
}
|
|
@ -29,16 +29,20 @@ void UDPSOCKET_SENDTO_INVALID()
|
|||
UDPSocket sock;
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(NetworkInterface::get_default_instance()));
|
||||
|
||||
TEST_ASSERT(sock.sendto(NULL, 9, NULL, 0) < 0);
|
||||
TEST_ASSERT(sock.sendto("", 9, NULL, 0) < 0);
|
||||
TEST_ASSERT(sock.sendto("", 0, NULL, 0) < 0);
|
||||
SocketAddress addr;
|
||||
addr.set_ip_address("");
|
||||
addr.set_port(0);
|
||||
// UDP will be able to send 0 bytes, but no particular error is raised
|
||||
TEST_ASSERT_EQUAL(sock.sendto(addr, NULL, 0), 0);
|
||||
|
||||
nsapi_error_t result = sock.sendto(ECHO_SERVER_ADDR, 9, NULL, 0);
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, NetworkInterface::get_default_instance()->gethostbyname(ECHO_SERVER_ADDR, &addr));
|
||||
addr.set_port(9);
|
||||
nsapi_error_t result = sock.sendto(addr, NULL, 0);
|
||||
if (result != NSAPI_ERROR_UNSUPPORTED) {
|
||||
TEST_ASSERT_EQUAL(0, result);
|
||||
}
|
||||
|
||||
TEST_ASSERT_EQUAL(5, sock.sendto(ECHO_SERVER_ADDR, 9, "hello", 5));
|
||||
TEST_ASSERT_EQUAL(5, sock.sendto(addr, "hello", 5));
|
||||
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.close());
|
||||
}
|
||||
|
|
|
@ -30,7 +30,8 @@ void UDPSOCKET_SENDTO_REPEAT()
|
|||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(NetworkInterface::get_default_instance()));
|
||||
|
||||
SocketAddress udp_addr;
|
||||
NetworkInterface::get_default_instance()->gethostbyname(ECHO_SERVER_ADDR, &udp_addr);
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK,
|
||||
NetworkInterface::get_default_instance()->gethostbyname(ECHO_SERVER_ADDR, &udp_addr));
|
||||
udp_addr.set_port(9);
|
||||
|
||||
int sent;
|
||||
|
|
|
@ -74,7 +74,9 @@ static void _ifup()
|
|||
nsapi_error_t err = eth->connect();
|
||||
eth->get_interface_name(interface_name[interface_num]);
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, err);
|
||||
printf("MBED: IP address is '%s' interface name %s\n", eth->get_ip_address(), interface_name[interface_num]);
|
||||
SocketAddress eth_ip_address;
|
||||
eth->get_ip_address(ð_ip_address);
|
||||
printf("MBED: IP address is '%s' interface name %s\n", eth_ip_address.get_ip_address(), interface_name[interface_num]);
|
||||
interface_num++;
|
||||
|
||||
wifi = WiFiInterface::get_default_instance();
|
||||
|
@ -99,9 +101,15 @@ static void _ifup()
|
|||
}
|
||||
printf("Wifi interface name: %s\n\n", STRING_VERIFY(wifi->get_interface_name(interface_name[interface_num])));
|
||||
printf("MAC: %s\n", STRING_VERIFY(wifi->get_mac_address()));
|
||||
printf("IP: %s\n", STRING_VERIFY(wifi->get_ip_address()));
|
||||
printf("Netmask: %s\n", STRING_VERIFY(wifi->get_netmask()));
|
||||
printf("Gateway: %s\n", STRING_VERIFY(wifi->get_gateway()));
|
||||
SocketAddress wifi_ip_address;
|
||||
wifi->get_ip_address(&wifi_ip_address);
|
||||
printf("IP: %s\n", STRING_VERIFY(wifi_ip_address.get_ip_address()));
|
||||
SocketAddress wifi_netmask;
|
||||
wifi->get_netmask(&wifi_netmask);
|
||||
printf("Netmask: %s\n", STRING_VERIFY(wifi_netmask.get_ip_address()));
|
||||
SocketAddress wifi_gateway;
|
||||
wifi->get_gateway(&wifi_gateway);
|
||||
printf("Gateway: %s\n", STRING_VERIFY(wifi_gateway.get_ip_address()));
|
||||
printf("RSSI: %d\n\n", wifi->get_rssi());
|
||||
interface_num++;
|
||||
} else {
|
||||
|
|
|
@ -254,12 +254,11 @@ TEST_F(TestAT_CellularContext, get_ip_address)
|
|||
ATHandler at(&fh1, que, 0, ",");
|
||||
AT_CellularDevice dev(&fh1);
|
||||
AT_CellularContext ctx(at, &dev);
|
||||
const char *ip = ctx.get_ip_address();
|
||||
EXPECT_TRUE(ip == NULL);
|
||||
SocketAddress addr;
|
||||
EXPECT_EQ(NSAPI_ERROR_NO_CONNECTION, ctx.get_ip_address(&addr));
|
||||
|
||||
my_AT_CTX ctx1(at, NULL);
|
||||
ip = ctx1.get_ip_address();
|
||||
EXPECT_TRUE(ip != NULL);
|
||||
EXPECT_EQ(NSAPI_ERROR_OK, ctx1.get_ip_address(&addr));
|
||||
}
|
||||
|
||||
TEST_F(TestAT_CellularContext, get_interface_name)
|
||||
|
@ -336,10 +335,11 @@ TEST_F(TestAT_CellularContext, get_netmask_gateway)
|
|||
ATHandler at(&fh1, que, 0, ",");
|
||||
AT_CellularDevice dev(&fh1);
|
||||
AT_CellularContext ctx(at, &dev);
|
||||
const char *gg = ctx.get_netmask();
|
||||
EXPECT_TRUE(gg == NULL);
|
||||
gg = ctx.get_gateway();
|
||||
EXPECT_TRUE(gg == NULL);
|
||||
SocketAddress addr;
|
||||
EXPECT_TRUE(NSAPI_ERROR_UNSUPPORTED == ctx.get_netmask(&addr));
|
||||
EXPECT_TRUE(addr.get_ip_address() == NULL);
|
||||
EXPECT_TRUE(NSAPI_ERROR_UNSUPPORTED == ctx.get_gateway(&addr));
|
||||
EXPECT_TRUE(addr.get_ip_address() == NULL);
|
||||
}
|
||||
|
||||
TEST_F(TestAT_CellularContext, get_pdpcontext_params)
|
||||
|
|
|
@ -175,18 +175,22 @@ TEST_F(TestAT_CellularStack, test_AT_CellularStack_get_ip_address)
|
|||
ATHandler at(&fh1, que, 0, ",");
|
||||
|
||||
MyStack st(at, 0, IPV6_STACK);
|
||||
EXPECT_TRUE(st.get_ip_address() == NULL);
|
||||
SocketAddress a;
|
||||
EXPECT_EQ(st.get_ip_address(&a), NSAPI_ERROR_NO_ADDRESS);
|
||||
EXPECT_EQ(a.get_ip_address(), nullptr);
|
||||
|
||||
char table[] = "1.2.3.4.5.65.7.8.9.10.11\0";
|
||||
char table[] = "1.2.3.4";
|
||||
ATHandler_stub::ssize_value = -1;
|
||||
ATHandler_stub::bool_value = true;
|
||||
ATHandler_stub::read_string_value = table;
|
||||
EXPECT_TRUE(st.get_ip_address() == NULL);
|
||||
EXPECT_EQ(st.get_ip_address(&a), NSAPI_ERROR_NO_ADDRESS);
|
||||
EXPECT_EQ(a.get_ip_address(), nullptr);
|
||||
|
||||
ATHandler_stub::ssize_value = strlen(table);
|
||||
ATHandler_stub::bool_value = true;
|
||||
ATHandler_stub::read_string_value = table;
|
||||
EXPECT_TRUE(st.get_ip_address());
|
||||
EXPECT_EQ(st.get_ip_address(&a), NSAPI_ERROR_OK);
|
||||
EXPECT_EQ(strcmp(a.get_ip_address(), "1.2.3.4"), 0);
|
||||
}
|
||||
|
||||
TEST_F(TestAT_CellularStack, test_AT_CellularStack_socket_open)
|
||||
|
@ -294,7 +298,7 @@ TEST_F(TestAT_CellularStack, test_AT_CellularStack_socket_send)
|
|||
|
||||
EXPECT_EQ(st.socket_send(&st.socket, "addr", 4), NSAPI_ERROR_NO_CONNECTION);
|
||||
|
||||
SocketAddress addr;
|
||||
SocketAddress addr("fc00::", 123);
|
||||
st.max_sock_value = 1;
|
||||
st.bool_value = true;
|
||||
nsapi_socket_t sock = &st.socket;
|
||||
|
@ -311,7 +315,7 @@ TEST_F(TestAT_CellularStack, test_AT_CellularStack_socket_sendto)
|
|||
|
||||
MyStack st(at, 0, IPV6_STACK);
|
||||
|
||||
SocketAddress addr;
|
||||
SocketAddress addr("fc00::", 123);
|
||||
EXPECT_EQ(st.socket_sendto(NULL, addr, "addr", 4), NSAPI_ERROR_NO_SOCKET);
|
||||
|
||||
st.max_sock_value = 1;
|
||||
|
|
|
@ -14,6 +14,12 @@ set(unittest-includes ${unittest-includes}
|
|||
# Source files
|
||||
set(unittest-sources
|
||||
../features/cellular/framework/AT/AT_CellularStack.cpp
|
||||
../features/frameworks/nanostack-libservice/source/libip4string/ip4tos.c
|
||||
../features/frameworks/nanostack-libservice/source/libip6string/ip6tos.c
|
||||
../features/frameworks/nanostack-libservice/source/libip4string/stoip4.c
|
||||
../features/frameworks/nanostack-libservice/source/libip6string/stoip6.c
|
||||
../features/frameworks/nanostack-libservice/source/libBits/common_functions.c
|
||||
../features/netsocket/SocketAddress.cpp
|
||||
)
|
||||
|
||||
# Test files
|
||||
|
@ -26,7 +32,6 @@ set(unittest-test-sources
|
|||
stubs/CellularUtil_stub.cpp
|
||||
stubs/us_ticker_stub.cpp
|
||||
stubs/NetworkStack_stub.cpp
|
||||
stubs/SocketAddress_stub.cpp
|
||||
stubs/mbed_assert_stub.cpp
|
||||
stubs/ThisThread_stub.cpp
|
||||
stubs/ConditionVariable_stub.cpp
|
||||
|
|
|
@ -14,6 +14,12 @@ set(unittest-includes ${unittest-includes}
|
|||
# Source files
|
||||
set(unittest-sources
|
||||
../features/cellular/framework/device/CellularContext.cpp
|
||||
../features/frameworks/nanostack-libservice/source/libip4string/ip4tos.c
|
||||
../features/frameworks/nanostack-libservice/source/libip6string/ip6tos.c
|
||||
../features/frameworks/nanostack-libservice/source/libip4string/stoip4.c
|
||||
../features/frameworks/nanostack-libservice/source/libip6string/stoip6.c
|
||||
../features/frameworks/nanostack-libservice/source/libBits/common_functions.c
|
||||
../features/netsocket/SocketAddress.cpp
|
||||
)
|
||||
|
||||
# Test files
|
||||
|
|
|
@ -54,12 +54,6 @@ TEST_F(TestDTLSSocket, constructor)
|
|||
EXPECT_TRUE(socket);
|
||||
}
|
||||
|
||||
TEST_F(TestDTLSSocket, connect_no_socket)
|
||||
{
|
||||
EXPECT_TRUE(socket);
|
||||
EXPECT_EQ(socket->connect("127.0.0.1", 1024), NSAPI_ERROR_NO_SOCKET);
|
||||
}
|
||||
|
||||
/* connect */
|
||||
|
||||
TEST_F(TestDTLSSocket, connect)
|
||||
|
@ -67,13 +61,6 @@ TEST_F(TestDTLSSocket, connect)
|
|||
socket->open((NetworkStack *)&stack);
|
||||
|
||||
stack.return_value = NSAPI_ERROR_OK;
|
||||
EXPECT_EQ(socket->connect("127.0.0.1", 1024), NSAPI_ERROR_OK);
|
||||
}
|
||||
|
||||
TEST_F(TestDTLSSocket, connect_error)
|
||||
{
|
||||
socket->open((NetworkStack *)&stack);
|
||||
|
||||
stack.return_value = NSAPI_ERROR_DNS_FAILURE;
|
||||
EXPECT_EQ(socket->connect("127.0.0.1", 1024), NSAPI_ERROR_DNS_FAILURE);
|
||||
SocketAddress a("127.0.0.1", 1024);
|
||||
EXPECT_EQ(socket->connect(a), NSAPI_ERROR_OK);
|
||||
}
|
||||
|
|
|
@ -206,17 +206,18 @@ TEST_F(TestEthernetInterface, disconnect)
|
|||
|
||||
TEST_F(TestEthernetInterface, set_network)
|
||||
{
|
||||
char ipAddress[NSAPI_IPv4_SIZE] = "127.0.0.1";
|
||||
char netmask[NSAPI_IPv4_SIZE] = "255.255.0.0";
|
||||
char gateway[NSAPI_IPv4_SIZE] = "127.0.0.2";
|
||||
SocketAddress ipAddress("127.0.0.1");
|
||||
SocketAddress netmask("255.255.0.0");
|
||||
SocketAddress gateway("127.0.0.2");
|
||||
|
||||
const char *ipAddressArg;
|
||||
const char *netmaskArg;
|
||||
const char *gatewayArg;
|
||||
SocketAddress ipAddressArg;
|
||||
SocketAddress netmaskArg;
|
||||
SocketAddress gatewayArg;
|
||||
|
||||
EXPECT_EQ(0, iface->get_ip_address());
|
||||
EXPECT_EQ(0, iface->get_netmask());
|
||||
EXPECT_EQ(0, iface->get_gateway());
|
||||
SocketAddress tmp;
|
||||
EXPECT_EQ(NSAPI_ERROR_NO_CONNECTION, iface->get_ip_address(&tmp));
|
||||
EXPECT_EQ(NSAPI_ERROR_NO_CONNECTION, iface->get_netmask(&tmp));
|
||||
EXPECT_EQ(NSAPI_ERROR_NO_CONNECTION, iface->get_gateway(&tmp));
|
||||
|
||||
// Set the network data
|
||||
EXPECT_EQ(NSAPI_ERROR_OK, iface->set_network(ipAddress, netmask, gateway));
|
||||
|
@ -237,25 +238,25 @@ TEST_F(TestEthernetInterface, set_network)
|
|||
Return(NSAPI_ERROR_OK)));
|
||||
EXPECT_EQ(NSAPI_ERROR_OK, iface->connect());
|
||||
// Check the contents of the stored pointer arguments.
|
||||
EXPECT_TRUE(0 == strcmp(ipAddress, ipAddressArg));
|
||||
EXPECT_TRUE(0 == strcmp(netmask, netmaskArg));
|
||||
EXPECT_TRUE(0 == strcmp(gateway, gatewayArg));
|
||||
EXPECT_EQ(ipAddress, ipAddressArg);
|
||||
EXPECT_EQ(netmask, netmaskArg);
|
||||
EXPECT_EQ(gateway, gatewayArg);
|
||||
|
||||
// Testing the getters makes sense now.
|
||||
EXPECT_CALL(*netStackIface, get_ip_address(_, _))
|
||||
EXPECT_CALL(*netStackIface, get_ip_address(_))
|
||||
.Times(1)
|
||||
.WillOnce(DoAll(SetArgPointee<0>(*ipAddress), Return(ipAddress)));
|
||||
EXPECT_EQ(std::string(ipAddress), std::string(iface->get_ip_address()));
|
||||
.WillOnce(DoAll(SetArgPointee<0>(ipAddress), Return(NSAPI_ERROR_OK)));
|
||||
EXPECT_EQ(NSAPI_ERROR_OK, iface->get_ip_address(&ipAddressArg));
|
||||
|
||||
EXPECT_CALL(*netStackIface, get_netmask(_, _))
|
||||
EXPECT_CALL(*netStackIface, get_netmask(_))
|
||||
.Times(1)
|
||||
.WillOnce(DoAll(SetArgPointee<0>(*netmask), Return(netmask)));
|
||||
EXPECT_EQ(std::string(netmask), std::string(iface->get_netmask()));
|
||||
.WillOnce(DoAll(SetArgPointee<0>(netmask), Return(NSAPI_ERROR_OK)));
|
||||
EXPECT_EQ(NSAPI_ERROR_OK, iface->get_netmask(&netmaskArg));
|
||||
|
||||
EXPECT_CALL(*netStackIface, get_gateway(_, _))
|
||||
EXPECT_CALL(*netStackIface, get_gateway(_))
|
||||
.Times(1)
|
||||
.WillOnce(DoAll(SetArgPointee<0>(*gateway), Return(gateway)));
|
||||
EXPECT_EQ(std::string(gateway), std::string(iface->get_gateway()));
|
||||
.WillOnce(DoAll(SetArgPointee<0>(gateway), Return(NSAPI_ERROR_OK)));
|
||||
EXPECT_EQ(NSAPI_ERROR_OK, iface->get_gateway(&gatewayArg));
|
||||
}
|
||||
|
||||
TEST_F(TestEthernetInterface, get_connection_status)
|
||||
|
|
|
@ -195,13 +195,8 @@ TEST_F(TestInternetSocket, bind_no_socket)
|
|||
TEST_F(TestInternetSocket, bind)
|
||||
{
|
||||
socket->open((NetworkStack *)&stack);
|
||||
EXPECT_EQ(socket->bind("127.0.0.1", 80), NSAPI_ERROR_OK);
|
||||
}
|
||||
|
||||
TEST_F(TestInternetSocket, bind_nullstring)
|
||||
{
|
||||
socket->open((NetworkStack *)&stack);
|
||||
EXPECT_EQ(socket->bind(NULL, 80), NSAPI_ERROR_OK);
|
||||
SocketAddress a("127.0.0.1", 80);
|
||||
EXPECT_EQ(socket->bind(a), NSAPI_ERROR_OK);
|
||||
}
|
||||
|
||||
// setsockopt and getsockopt are really just calling the underlying stack functions
|
||||
|
|
|
@ -77,20 +77,20 @@ TEST_F(TestNetworkInterface, get_mac_address)
|
|||
|
||||
TEST_F(TestNetworkInterface, get_ip_address)
|
||||
{
|
||||
char *n = 0;
|
||||
EXPECT_EQ(iface->get_ip_address(), n);
|
||||
SocketAddress addr;
|
||||
EXPECT_EQ(iface->get_ip_address(&addr), NSAPI_ERROR_UNSUPPORTED);
|
||||
}
|
||||
|
||||
TEST_F(TestNetworkInterface, get_netmask)
|
||||
{
|
||||
char *n = 0;
|
||||
EXPECT_EQ(iface->get_netmask(), n);
|
||||
SocketAddress addr;
|
||||
EXPECT_EQ(iface->get_netmask(&addr), NSAPI_ERROR_UNSUPPORTED);
|
||||
}
|
||||
|
||||
TEST_F(TestNetworkInterface, get_gateway)
|
||||
{
|
||||
char *n = 0;
|
||||
EXPECT_EQ(iface->get_gateway(), n);
|
||||
SocketAddress addr;
|
||||
EXPECT_EQ(iface->get_gateway(&addr), NSAPI_ERROR_UNSUPPORTED);
|
||||
}
|
||||
|
||||
TEST_F(TestNetworkInterface, get_interface_name)
|
||||
|
|
|
@ -144,7 +144,8 @@ TEST_F(TestNetworkStack, constructor)
|
|||
|
||||
TEST_F(TestNetworkStack, get_ip_address_default)
|
||||
{
|
||||
EXPECT_EQ(stack->NetworkStack::get_ip_address(), (char *)NULL);
|
||||
SocketAddress a;
|
||||
EXPECT_EQ(stack->NetworkStack::get_ip_address(&a), NSAPI_ERROR_UNSUPPORTED);
|
||||
}
|
||||
|
||||
/* gethostbyname */
|
||||
|
|
|
@ -78,7 +78,7 @@ TEST_F(TestTCPSocket, connect)
|
|||
const SocketAddress a("127.0.0.1", 1024);
|
||||
EXPECT_EQ(socket->connect(a), NSAPI_ERROR_OK);
|
||||
EXPECT_EQ(socket->setsockopt(NSAPI_SOCKET, NSAPI_BIND_TO_DEVICE, "12345", 5), NSAPI_ERROR_UNSUPPORTED);
|
||||
EXPECT_EQ(socket->connect("127.0.0.1", 1024), NSAPI_ERROR_OK);
|
||||
EXPECT_EQ(socket->connect(a), NSAPI_ERROR_OK);
|
||||
}
|
||||
|
||||
TEST_F(TestTCPSocket, connect_no_open)
|
||||
|
@ -117,20 +117,6 @@ TEST_F(TestTCPSocket, connect_error_is_connected)
|
|||
EXPECT_EQ(socket->connect(a), NSAPI_ERROR_OK);
|
||||
}
|
||||
|
||||
TEST_F(TestTCPSocket, connect_by_name_and_port)
|
||||
{
|
||||
socket->open((NetworkStack *)&stack);
|
||||
stack.return_value = NSAPI_ERROR_OK;
|
||||
EXPECT_EQ(socket->connect("testhost", 80), NSAPI_ERROR_OK);
|
||||
}
|
||||
|
||||
TEST_F(TestTCPSocket, connect_by_name_and_port_dns_fail)
|
||||
{
|
||||
socket->open((NetworkStack *)&stack);
|
||||
stack.return_value = NSAPI_ERROR_DNS_FAILURE;
|
||||
EXPECT_EQ(socket->connect("testhost", 80), NSAPI_ERROR_DNS_FAILURE);
|
||||
}
|
||||
|
||||
/* send */
|
||||
|
||||
TEST_F(TestTCPSocket, send_no_open)
|
||||
|
|
|
@ -61,11 +61,13 @@ TEST_F(TestTLSSocket, connect)
|
|||
socket->open((NetworkStack *)&stack);
|
||||
|
||||
stack.return_value = NSAPI_ERROR_OK;
|
||||
EXPECT_EQ(socket->connect("127.0.0.1", 1024), NSAPI_ERROR_OK);
|
||||
SocketAddress a("127.0.0.1", 1024);
|
||||
EXPECT_EQ(socket->connect(a), NSAPI_ERROR_OK);
|
||||
}
|
||||
|
||||
TEST_F(TestTLSSocket, connect_no_open)
|
||||
{
|
||||
stack.return_value = NSAPI_ERROR_OK;
|
||||
EXPECT_EQ(socket->connect("127.0.0.1", 1024), NSAPI_ERROR_NO_SOCKET);
|
||||
SocketAddress a("127.0.0.1", 1024);
|
||||
EXPECT_EQ(socket->connect(a), NSAPI_ERROR_NO_SOCKET);
|
||||
}
|
||||
|
|
|
@ -70,13 +70,13 @@ TEST_F(TestUDPSocket, sendto_addr_port)
|
|||
socket->open((NetworkStack *)&stack);
|
||||
|
||||
stack.return_value = NSAPI_ERROR_PARAMETER;
|
||||
EXPECT_EQ(socket->sendto("127.0.0.1", 0, 0, 0), NSAPI_ERROR_DNS_FAILURE);
|
||||
EXPECT_EQ(socket->sendto(a, 0, 0), NSAPI_ERROR_PARAMETER);
|
||||
|
||||
stack.return_value = NSAPI_ERROR_OK;
|
||||
EXPECT_EQ(socket->sendto("127.0.0.1", 0, 0, 0), 0);
|
||||
EXPECT_EQ(socket->sendto(a, 0, 0), 0);
|
||||
|
||||
EXPECT_EQ(socket->setsockopt(NSAPI_SOCKET, NSAPI_BIND_TO_DEVICE, "12324", 5), NSAPI_ERROR_UNSUPPORTED);
|
||||
EXPECT_EQ(socket->sendto("127.0.0.1", 0, 0, 0), 0);
|
||||
EXPECT_EQ(socket->sendto(a, 0, 0), 0);
|
||||
}
|
||||
|
||||
TEST_F(TestUDPSocket, connect)
|
||||
|
|
|
@ -509,6 +509,26 @@ const char *ESP8266Interface::get_ip_address()
|
|||
return ip_buff;
|
||||
}
|
||||
|
||||
nsapi_error_t ESP8266Interface::get_ip_address(SocketAddress *address)
|
||||
{
|
||||
if (_software_conn_stat == IFACE_STATUS_DISCONNECTED) {
|
||||
_esp.uart_enable_input(true);
|
||||
}
|
||||
|
||||
const char *ip_buff = _esp.ip_addr();
|
||||
if (!ip_buff || strcmp(ip_buff, "0.0.0.0") == 0) {
|
||||
ip_buff = NULL;
|
||||
}
|
||||
if (_software_conn_stat == IFACE_STATUS_DISCONNECTED) {
|
||||
_esp.uart_enable_input(false);
|
||||
}
|
||||
if (ip_buff) {
|
||||
address->set_ip_address(ip_buff);
|
||||
return NSAPI_ERROR_OK;
|
||||
}
|
||||
return NSAPI_ERROR_NO_ADDRESS;
|
||||
}
|
||||
|
||||
const char *ESP8266Interface::get_mac_address()
|
||||
{
|
||||
if (_software_conn_stat == IFACE_STATUS_DISCONNECTED) {
|
||||
|
@ -522,11 +542,43 @@ const char *ESP8266Interface::get_mac_address()
|
|||
return ret;
|
||||
}
|
||||
|
||||
nsapi_error_t ESP8266Interface::get_gateway(SocketAddress *address)
|
||||
{
|
||||
if (address == nullptr) {
|
||||
return NSAPI_ERROR_PARAMETER;
|
||||
}
|
||||
if (_conn_stat == NSAPI_STATUS_DISCONNECTED) {
|
||||
return NSAPI_ERROR_NO_CONNECTION;
|
||||
}
|
||||
|
||||
if (!address->set_ip_address(_esp.gateway())) {
|
||||
return NSAPI_ERROR_NO_ADDRESS;
|
||||
}
|
||||
|
||||
return NSAPI_ERROR_OK;
|
||||
}
|
||||
|
||||
const char *ESP8266Interface::get_gateway()
|
||||
{
|
||||
return _conn_stat != NSAPI_STATUS_DISCONNECTED ? _esp.gateway() : NULL;
|
||||
}
|
||||
|
||||
nsapi_error_t ESP8266Interface::get_netmask(SocketAddress *address)
|
||||
{
|
||||
if (address == nullptr) {
|
||||
return NSAPI_ERROR_PARAMETER;
|
||||
}
|
||||
if (_conn_stat == NSAPI_STATUS_DISCONNECTED) {
|
||||
return NSAPI_ERROR_NO_CONNECTION;
|
||||
}
|
||||
|
||||
if (!address->set_ip_address(_esp.gateway())) {
|
||||
return NSAPI_ERROR_NO_ADDRESS;
|
||||
}
|
||||
|
||||
return NSAPI_ERROR_OK;
|
||||
}
|
||||
|
||||
const char *ESP8266Interface::get_netmask()
|
||||
{
|
||||
return _conn_stat != NSAPI_STATUS_DISCONNECTED ? _esp.netmask() : NULL;
|
||||
|
|
|
@ -137,6 +137,9 @@ public:
|
|||
/** Get the internally stored IP address
|
||||
* @return IP address of the interface or null if not yet connected
|
||||
*/
|
||||
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
|
||||
|
@ -149,6 +152,9 @@ public:
|
|||
* @return Null-terminated representation of the local gateway
|
||||
* or null if no network mask has been recieved
|
||||
*/
|
||||
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 local network mask
|
||||
|
@ -156,6 +162,9 @@ public:
|
|||
* @return Null-terminated representation of the local network mask
|
||||
* or null if no network mask has been recieved
|
||||
*/
|
||||
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 network interface name
|
||||
|
|
|
@ -247,7 +247,7 @@ nsapi_error_t AT_CellularContext::get_ip_address(SocketAddress *address)
|
|||
_stack = get_stack();
|
||||
}
|
||||
if (_stack) {
|
||||
address->set_ip_address(_stack->get_ip_address());
|
||||
_stack->get_ip_address(address);
|
||||
return NSAPI_ERROR_OK;
|
||||
}
|
||||
return NSAPI_ERROR_NO_CONNECTION;
|
||||
|
|
|
@ -57,12 +57,47 @@ int AT_CellularStack::find_socket_index(nsapi_socket_t handle)
|
|||
*/
|
||||
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;
|
||||
if (!address) {
|
||||
return NSAPI_ERROR_PARAMETER;
|
||||
}
|
||||
_at.lock();
|
||||
|
||||
bool ipv4 = false, ipv6 = false;
|
||||
|
||||
_at.cmd_start_stop("+CGPADDR", "=", "%d", _cid);
|
||||
_at.resp_start("+CGPADDR:");
|
||||
|
||||
if (_at.info_resp()) {
|
||||
_at.skip_param();
|
||||
|
||||
if (_at.read_string(_ip, PDP_IPV6_SIZE) != -1) {
|
||||
convert_ipv6(_ip);
|
||||
address->set_ip_address(_ip);
|
||||
|
||||
ipv4 = (address->get_ip_version() == NSAPI_IPv4);
|
||||
ipv6 = (address->get_ip_version() == NSAPI_IPv6);
|
||||
|
||||
// Try to look for second address ONLY if modem has support for dual stack(can handle both IPv4 and IPv6 simultaneously).
|
||||
// Otherwise assumption is that second address is not reliable, even if network provides one.
|
||||
if ((get_property(PROPERTY_IPV4V6_PDP_TYPE) && (_at.read_string(_ip, PDP_IPV6_SIZE) != -1))) {
|
||||
convert_ipv6(_ip);
|
||||
address->set_ip_address(_ip);
|
||||
ipv6 = (address->get_ip_version() == NSAPI_IPv6);
|
||||
}
|
||||
}
|
||||
}
|
||||
_at.resp_stop();
|
||||
_at.unlock();
|
||||
|
||||
if (ipv4 && ipv6) {
|
||||
_stack_type = IPV4V6_STACK;
|
||||
} else if (ipv4) {
|
||||
_stack_type = IPV4_STACK;
|
||||
} else if (ipv6) {
|
||||
_stack_type = IPV6_STACK;
|
||||
}
|
||||
|
||||
return (ipv4 || ipv6) ? NSAPI_ERROR_OK : NSAPI_ERROR_NO_ADDRESS;
|
||||
}
|
||||
|
||||
const char *AT_CellularStack::get_ip_address()
|
||||
|
|
|
@ -91,16 +91,16 @@ void CellularContext::validate_ip_address()
|
|||
{
|
||||
const int IP_MAX_TRIES = 10; // maximum of 2 seconds as we wait 200ms between tries
|
||||
const int IP_WAIT_INTERVAL = 200; // 200 ms between retries
|
||||
const char *ip = NULL;
|
||||
SocketAddress ip;
|
||||
int i = 0;
|
||||
|
||||
while (1) {
|
||||
ip = get_ip_address();
|
||||
get_ip_address(&ip);
|
||||
if (ip || i >= IP_MAX_TRIES) {
|
||||
if (ip == NULL) {
|
||||
if (ip.get_ip_address() == NULL) {
|
||||
tr_warning("Connected but no local ip address");
|
||||
} else {
|
||||
tr_info("Cellular local IP: %s", ip);
|
||||
tr_info("Cellular local IP: %s", ip.get_ip_address());
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -268,7 +268,8 @@ int UBLOX_AT_CellularContext::nsapi_security_to_modem_security(AuthenticationTyp
|
|||
// Disconnect the on board IP stack of the modem.
|
||||
bool UBLOX_AT_CellularContext::disconnect_modem_stack()
|
||||
{
|
||||
if (get_ip_address() != NULL) {
|
||||
SocketAddress addr;
|
||||
if (get_ip_address(&addr) == NSAPI_ERROR_OK) {
|
||||
if (_at.at_cmd_discard("+UPSDA", "=", "%d%d", PROFILE, 4) == NSAPI_ERROR_OK) {
|
||||
return true;
|
||||
}
|
||||
|
@ -303,6 +304,11 @@ const char *UBLOX_AT_CellularContext::get_gateway()
|
|||
return get_ip_address();
|
||||
}
|
||||
|
||||
nsapi_error_t UBLOX_AT_CellularContext::get_gateway(SocketAddress *addr)
|
||||
{
|
||||
return get_ip_address(addr);
|
||||
}
|
||||
|
||||
const char *UBLOX_AT_CellularContext::get_apn()
|
||||
{
|
||||
return _apn;
|
||||
|
|
|
@ -29,6 +29,7 @@ public:
|
|||
|
||||
virtual void do_connect();
|
||||
virtual const char *get_gateway();
|
||||
virtual nsapi_error_t get_gateway(SocketAddress *addr);
|
||||
|
||||
const char *get_apn(void);
|
||||
const char *get_uname(void);
|
||||
|
|
|
@ -167,7 +167,12 @@ char *Nanostack::LoWPANNDInterface::get_gateway(char *buf, nsapi_size_t buflen)
|
|||
|
||||
bool LoWPANNDInterface::getRouterIpAddress(char *address, int8_t len)
|
||||
{
|
||||
return _interface->get_gateway(address, len);
|
||||
SocketAddress sock_addr;
|
||||
if (_interface->get_gateway(&sock_addr) == NSAPI_ERROR_OK) {
|
||||
strncpy(address, sock_addr.get_ip_address(), len);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
#define LOWPAN 0x2345
|
||||
|
|
|
@ -168,7 +168,12 @@ char *Nanostack::WisunInterface::get_gateway(char *buf, nsapi_size_t buflen)
|
|||
|
||||
bool WisunInterface::getRouterIpAddress(char *address, int8_t len)
|
||||
{
|
||||
return _interface->get_gateway(address, len);
|
||||
SocketAddress sock_addr;
|
||||
if (_interface->get_gateway(&sock_addr) == NSAPI_ERROR_OK) {
|
||||
strncpy(address, sock_addr.get_ip_address(), len);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
mesh_error_t WisunInterface::set_network_name(char *network_name)
|
||||
|
|
|
@ -102,8 +102,8 @@ const char *EMACInterface::get_mac_address()
|
|||
|
||||
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);
|
||||
if (_interface && _interface->get_ip_address(address) == NSAPI_ERROR_OK) {
|
||||
strncpy(_ip_address, address->get_ip_address(), sizeof(_ip_address));
|
||||
return NSAPI_ERROR_OK;
|
||||
}
|
||||
|
||||
|
@ -129,8 +129,8 @@ nsapi_error_t EMACInterface::get_ipv6_link_local_address(SocketAddress *address)
|
|||
|
||||
nsapi_error_t EMACInterface::get_netmask(SocketAddress *address)
|
||||
{
|
||||
if (_interface && _interface->get_netmask(_netmask, sizeof(_netmask))) {
|
||||
address->set_ip_address(_netmask);
|
||||
if (_interface && _interface->get_netmask(address) == NSAPI_ERROR_OK) {
|
||||
strncpy(_netmask, address->get_ip_address(), sizeof(_netmask));
|
||||
return NSAPI_ERROR_OK;
|
||||
}
|
||||
|
||||
|
@ -147,7 +147,8 @@ const char *EMACInterface::get_netmask()
|
|||
|
||||
nsapi_error_t EMACInterface::get_gateway(SocketAddress *address)
|
||||
{
|
||||
if (_interface && _interface->get_gateway(_gateway, sizeof(_gateway))) {
|
||||
if (_interface && _interface->get_gateway(address) == NSAPI_ERROR_OK) {
|
||||
strncpy(_gateway, address->get_ip_address(), sizeof(_gateway));
|
||||
address->set_ip_address(_gateway);
|
||||
return NSAPI_ERROR_OK;
|
||||
}
|
||||
|
|
|
@ -68,7 +68,7 @@ nsapi_error_t NetworkStack::gethostbyname(const char *name, SocketAddress *addre
|
|||
// ip address of the underlying stack
|
||||
if (version == NSAPI_UNSPEC) {
|
||||
SocketAddress testaddress;
|
||||
if (testaddress.set_ip_address(this->get_ip_address())) {
|
||||
if (this->get_ip_address(&testaddress) == NSAPI_ERROR_OK) {
|
||||
version = testaddress.get_ip_version();
|
||||
}
|
||||
}
|
||||
|
@ -98,7 +98,7 @@ nsapi_value_or_error_t NetworkStack::gethostbyname_async(const char *name, hostb
|
|||
// ip address of the underlying stack
|
||||
if (version == NSAPI_UNSPEC) {
|
||||
SocketAddress testaddress;
|
||||
if (testaddress.set_ip_address(this->get_ip_address())) {
|
||||
if (this->get_ip_address(&testaddress) == NSAPI_ERROR_OK) {
|
||||
version = testaddress.get_ip_version();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -92,6 +92,41 @@ const char *PPPInterface::get_ip_address()
|
|||
return NULL;
|
||||
}
|
||||
|
||||
nsapi_error_t PPPInterface::get_ip_address(SocketAddress *address)
|
||||
{
|
||||
if (address) {
|
||||
return NSAPI_ERROR_PARAMETER;
|
||||
}
|
||||
|
||||
if (_interface && _interface->get_ip_address(address) == NSAPI_ERROR_OK) {
|
||||
strncpy(_ip_address, address->get_ip_address(), sizeof(_ip_address));
|
||||
return NSAPI_ERROR_OK;
|
||||
}
|
||||
|
||||
return NSAPI_ERROR_NO_CONNECTION;
|
||||
}
|
||||
|
||||
nsapi_error_t PPPInterface::get_netmask(SocketAddress *address)
|
||||
{
|
||||
if (_interface && _interface->get_netmask(address) == NSAPI_ERROR_OK) {
|
||||
strncpy(_netmask, address->get_ip_address(), sizeof(_netmask));
|
||||
return NSAPI_ERROR_OK;
|
||||
}
|
||||
|
||||
return NSAPI_ERROR_NO_CONNECTION;
|
||||
}
|
||||
|
||||
nsapi_error_t PPPInterface::get_gateway(SocketAddress *address)
|
||||
{
|
||||
if (_interface && _interface->get_gateway(address) == NSAPI_ERROR_OK) {
|
||||
strncpy(_gateway, address->get_ip_address(), sizeof(_gateway));
|
||||
address->set_ip_address(_gateway);
|
||||
return NSAPI_ERROR_OK;
|
||||
}
|
||||
|
||||
return NSAPI_ERROR_NO_CONNECTION;
|
||||
}
|
||||
|
||||
const char *PPPInterface::get_netmask()
|
||||
{
|
||||
if (_interface && _interface->get_netmask(_netmask, sizeof(_netmask))) {
|
||||
|
|
|
@ -80,6 +80,15 @@ public:
|
|||
*/
|
||||
virtual const char *get_ip_address();
|
||||
|
||||
/** @copydoc NetworkInterface::get_ip_address */
|
||||
virtual nsapi_error_t get_ip_address(SocketAddress *address);
|
||||
|
||||
/** @copydoc NetworkInterface::get_netmask */
|
||||
virtual nsapi_error_t get_netmask(SocketAddress *address);
|
||||
|
||||
/** @copydoc NetworkInterface::get_gateway */
|
||||
virtual nsapi_error_t get_gateway(SocketAddress *address);
|
||||
|
||||
/** Get the local network mask
|
||||
*
|
||||
* @return Null-terminated representation of the local network mask
|
||||
|
|
Loading…
Reference in New Issue