C++11-ify virtualisation in netsocket

Use `override` and `final` where appropriate, and eliminate unnecessary
`virtual`.

Some other C++11 simplifications.

Reduces code size.
pull/12487/head
Kevin Bracey 2020-02-21 13:49:26 +02:00
parent 695e872202
commit d8d35eda9f
44 changed files with 340 additions and 410 deletions

View File

@ -21,6 +21,7 @@ set(unittest-test-sources
stubs/Mutex_stub.cpp stubs/Mutex_stub.cpp
stubs/CellularContext_stub.cpp stubs/CellularContext_stub.cpp
stubs/mbed_assert_stub.cpp stubs/mbed_assert_stub.cpp
stubs/mbed_atomic_stub.c
) )
set(unittest-test-flags set(unittest-test-flags

View File

@ -114,11 +114,14 @@ protected:
} }
}; };
#if 0
/* Test is invalid, as it's working on a PPPInterface pointer rather than a NetworkInterface pointer. */
/* NetworkInterface does not yet offer the pppInterface method for a dynamic cast */
TEST_F(TestPPPInterface, constructor_default) TEST_F(TestPPPInterface, constructor_default)
{ {
EXPECT_TRUE(iface); EXPECT_TRUE(iface);
// Test that this clas presents itself correctly // Test that this clas presents itself correctly
EXPECT_NE(nullptr, iface->pppInterface()); EXPECT_EQ(iface, iface->pppInterface());
EXPECT_EQ(nullptr, iface->emacInterface()); EXPECT_EQ(nullptr, iface->emacInterface());
EXPECT_EQ(nullptr, iface->ethInterface()); EXPECT_EQ(nullptr, iface->ethInterface());
@ -126,6 +129,7 @@ TEST_F(TestPPPInterface, constructor_default)
EXPECT_EQ(nullptr, iface->cellularInterface()); EXPECT_EQ(nullptr, iface->cellularInterface());
EXPECT_EQ(nullptr, iface->meshInterface()); EXPECT_EQ(nullptr, iface->meshInterface());
} }
#endif
TEST_F(TestPPPInterface, connect) TEST_F(TestPPPInterface, connect)
{ {

View File

@ -80,13 +80,13 @@ public:
* *
* @return NSAPI_ERROR_OK on success, or negative error code on failure. * @return NSAPI_ERROR_OK on success, or negative error code on failure.
*/ */
virtual nsapi_error_t connect() = 0; nsapi_error_t connect() override = 0;
/** Stop the interface. /** Stop the interface.
* *
* @return NSAPI_ERROR_OK on success, or error code on failure. * @return NSAPI_ERROR_OK on success, or error code on failure.
*/ */
virtual nsapi_error_t disconnect() = 0; nsapi_error_t disconnect() override = 0;
/** Check if the connection is currently established. /** Check if the connection is currently established.
* *
@ -96,11 +96,11 @@ public:
virtual bool is_connected() = 0; virtual bool is_connected() = 0;
/** @copydoc NetworkInterface::get_ip_address */ /** @copydoc NetworkInterface::get_ip_address */
virtual nsapi_error_t get_ip_address(SocketAddress *address) = 0; nsapi_error_t get_ip_address(SocketAddress *address) override = 0;
/** @copydoc NetworkInterface::cellularInterface /** @copydoc NetworkInterface::cellularInterface
*/ */
virtual CellularInterface *cellularInterface() CellularInterface *cellularInterface() final
{ {
return this; return this;
} }
@ -130,7 +130,7 @@ public:
* NetworkInterface::get_default_instance() (see nsapi JSON * NetworkInterface::get_default_instance() (see nsapi JSON
* configuration). * configuration).
*/ */
virtual void set_default_parameters(); void set_default_parameters() override;
}; };
#endif // CELLULAR_INTERFACE_H_ #endif // CELLULAR_INTERFACE_H_

View File

@ -23,15 +23,11 @@ using namespace mbed;
ControlPlane_netif *CellularNonIPSocket::_cp_netif; ControlPlane_netif *CellularNonIPSocket::_cp_netif;
CellularNonIPSocket::CellularNonIPSocket() CellularNonIPSocket::CellularNonIPSocket() = default;
: _timeout(osWaitForever),
_readers(0), _writers(0), _pending(0),
_opened(false)
{}
nsapi_error_t CellularNonIPSocket::open(CellularContext *cellular_context) nsapi_error_t CellularNonIPSocket::open(CellularContext *cellular_context)
{ {
if (cellular_context == NULL) { if (cellular_context == nullptr) {
return NSAPI_ERROR_PARAMETER; return NSAPI_ERROR_PARAMETER;
} }
@ -47,7 +43,7 @@ nsapi_error_t CellularNonIPSocket::open(ControlPlane_netif *cp_netif)
{ {
_lock.lock(); _lock.lock();
if (cp_netif == NULL || _opened) { if (cp_netif == nullptr || _opened) {
_lock.unlock(); _lock.unlock();
return NSAPI_ERROR_PARAMETER; return NSAPI_ERROR_PARAMETER;
} }
@ -76,9 +72,9 @@ nsapi_error_t CellularNonIPSocket::close()
} }
// Just in case - tell the stack not to callback any more, then remove this socket. // Just in case - tell the stack not to callback any more, then remove this socket.
_cp_netif->attach(0, 0); _cp_netif->attach(nullptr, nullptr);
_opened = false; _opened = false;
_cp_netif = 0; // Invalidate the cp_netif pointer - otherwise open() fails. _cp_netif = nullptr; // Invalidate the cp_netif pointer - otherwise open() fails.
// Wakeup anything in a blocking operation // Wakeup anything in a blocking operation
// on this socket // on this socket
@ -112,7 +108,7 @@ nsapi_size_or_error_t CellularNonIPSocket::send(const void *data, nsapi_size_t s
break; break;
} }
_pending = 0; core_util_atomic_flag_clear(&_pending);
nsapi_size_or_error_t sent = _cp_netif->send(data, size); nsapi_size_or_error_t sent = _cp_netif->send(data, size);
if ((0 == _timeout) || (NSAPI_ERROR_WOULD_BLOCK != sent)) { if ((0 == _timeout) || (NSAPI_ERROR_WOULD_BLOCK != sent)) {
ret = sent; ret = sent;
@ -154,7 +150,7 @@ nsapi_size_or_error_t CellularNonIPSocket::recv(void *buffer, nsapi_size_t size)
break; break;
} }
_pending = 0; core_util_atomic_flag_clear(&_pending);
nsapi_size_or_error_t recv = _cp_netif->recv(buffer, size); nsapi_size_or_error_t recv = _cp_netif->recv(buffer, size);
// Non-blocking sockets always return. Blocking only returns when success or errors other than WOULD_BLOCK // Non-blocking sockets always return. Blocking only returns when success or errors other than WOULD_BLOCK
@ -210,8 +206,7 @@ void CellularNonIPSocket::event()
{ {
_event_flag.set(READ_FLAG | WRITE_FLAG); _event_flag.set(READ_FLAG | WRITE_FLAG);
_pending += 1; if (_callback && !core_util_atomic_flag_test_and_set(&_pending)) {
if (_callback && _pending == 1) {
_callback(); _callback();
} }
} }
@ -233,7 +228,7 @@ Socket *CellularNonIPSocket::accept(nsapi_error_t *error)
if (error) { if (error) {
*error = NSAPI_ERROR_UNSUPPORTED; *error = NSAPI_ERROR_UNSUPPORTED;
} }
return NULL; return nullptr;
} }
nsapi_error_t CellularNonIPSocket::listen(int backlog) nsapi_error_t CellularNonIPSocket::listen(int backlog)

View File

@ -21,6 +21,7 @@
#include "rtos/Mutex.h" #include "rtos/Mutex.h"
#include "rtos/EventFlags.h" #include "rtos/EventFlags.h"
#include "Callback.h" #include "Callback.h"
#include "mbed_atomic.h"
#include "mbed_toolchain.h" #include "mbed_toolchain.h"
#include "ControlPlane_netif.h" #include "ControlPlane_netif.h"
#include "CellularContext.h" #include "CellularContext.h"
@ -40,7 +41,7 @@ public:
* *
* @note Closes socket if it's still open. * @note Closes socket if it's still open.
*/ */
virtual ~CellularNonIPSocket(); ~CellularNonIPSocket() override;
/** Creates a socket. /** Creates a socket.
*/ */
@ -54,7 +55,7 @@ public:
* @return NSAPI_ERROR_OK on success * @return NSAPI_ERROR_OK on success
* NSAPI_ERROR_PARAMETER otherwise * NSAPI_ERROR_PARAMETER otherwise
*/ */
virtual nsapi_error_t open(mbed::CellularContext *cellular_context); nsapi_error_t open(mbed::CellularContext *cellular_context);
/** Opens a socket that will use the given control plane interface for data delivery. /** Opens a socket that will use the given control plane interface for data delivery.
* Attaches the event as callback to the control plane interface. * Attaches the event as callback to the control plane interface.
@ -64,7 +65,7 @@ public:
* NSAPI_ERROR_PARAMETER otherwise * NSAPI_ERROR_PARAMETER otherwise
* *
*/ */
virtual nsapi_error_t open(mbed::ControlPlane_netif *cp_netif); nsapi_error_t open(mbed::ControlPlane_netif *cp_netif);
/** Closes socket /** Closes socket
* *
@ -72,7 +73,7 @@ public:
* NSAPI_ERROR_NO_SOCKET otherwise * NSAPI_ERROR_NO_SOCKET otherwise
*/ */
virtual nsapi_error_t close(); nsapi_error_t close() override;
/** Send data over a control plane cellular context. /** Send data over a control plane cellular context.
* *
@ -85,7 +86,7 @@ public:
* @return Number of sent bytes on success, negative error * @return Number of sent bytes on success, negative error
* code on failure. * code on failure.
*/ */
virtual nsapi_size_or_error_t send(const void *data, nsapi_size_t size); nsapi_size_or_error_t send(const void *data, nsapi_size_t size) override;
/** Receive data from a socket. /** Receive data from a socket.
* *
@ -98,52 +99,52 @@ public:
* @return Number of received bytes on success, negative error * @return Number of received bytes on success, negative error
* code on failure. * code on failure.
*/ */
virtual nsapi_size_or_error_t recv(void *data, nsapi_size_t size); nsapi_size_or_error_t recv(void *data, nsapi_size_t size) override;
/** @copydoc Socket::set_blocking /** @copydoc Socket::set_blocking
*/ */
virtual void set_blocking(bool blocking); void set_blocking(bool blocking) override;
/** @copydoc Socket::set_timeout /** @copydoc Socket::set_timeout
*/ */
virtual void set_timeout(int timeout); void set_timeout(int timeout) override;
/** @copydoc Socket::sigio /** @copydoc Socket::sigio
*/ */
virtual void sigio(mbed::Callback<void()> func); void sigio(mbed::Callback<void()> func) override;
/// NOT APPLICABLE /// NOT APPLICABLE
virtual nsapi_error_t connect(const SocketAddress &address); nsapi_error_t connect(const SocketAddress &address) override;
/// NOT APPLICABLE /// NOT APPLICABLE
virtual Socket *accept(nsapi_error_t *error = NULL); Socket *accept(nsapi_error_t *error = NULL) override;
/// NOT APPLICABLE /// NOT APPLICABLE
virtual nsapi_error_t listen(int backlog = 1); nsapi_error_t listen(int backlog = 1) override;
/// NOT APPLICABLE /// NOT APPLICABLE
virtual nsapi_error_t setsockopt(int level, int optname, const void *optval, unsigned optlen); nsapi_error_t setsockopt(int level, int optname, const void *optval, unsigned optlen) override;
/// NOT APPLICABLE /// NOT APPLICABLE
virtual nsapi_error_t getsockopt(int level, int optname, void *optval, unsigned *optlen); nsapi_error_t getsockopt(int level, int optname, void *optval, unsigned *optlen) override;
/// NOT APPLICABLE /// NOT APPLICABLE
virtual nsapi_error_t getpeername(SocketAddress *address); nsapi_error_t getpeername(SocketAddress *address) override;
/// NOT APPLICABLE /// NOT APPLICABLE
virtual nsapi_size_or_error_t sendto(const SocketAddress &address, nsapi_size_or_error_t sendto(const SocketAddress &address,
const void *data, nsapi_size_t size); const void *data, nsapi_size_t size) override;
/// NOT APPLICABLE /// NOT APPLICABLE
virtual nsapi_size_or_error_t recvfrom(SocketAddress *address, nsapi_size_or_error_t recvfrom(SocketAddress *address,
void *data, nsapi_size_t size); void *data, nsapi_size_t size) override;
/// NOT APPLICABLE /// NOT APPLICABLE
virtual nsapi_error_t bind(const SocketAddress &address); nsapi_error_t bind(const SocketAddress &address) override;
protected: protected:
virtual void event(); void event();
uint32_t _timeout; uint32_t _timeout = osWaitForever;
mbed::Callback<void()> _event; mbed::Callback<void()> _event;
mbed::Callback<void()> _callback; mbed::Callback<void()> _callback;
rtos::EventFlags _event_flag; rtos::EventFlags _event_flag;
rtos::Mutex _lock; rtos::Mutex _lock;
uint8_t _readers; uint8_t _readers = 0;
uint8_t _writers; uint8_t _writers = 0;
volatile unsigned _pending; core_util_atomic_flag _pending = CORE_UTIL_ATOMIC_FLAG_INIT;
// Event flags // Event flags
static const int READ_FLAG = 0x1u; static const int READ_FLAG = 0x1u;
@ -151,7 +152,7 @@ protected:
static const int FINISHED_FLAG = 0x3u; static const int FINISHED_FLAG = 0x3u;
static ControlPlane_netif *_cp_netif; // there can be only one Non-IP socket static ControlPlane_netif *_cp_netif; // there can be only one Non-IP socket
bool _opened; bool _opened = false;
}; };
/** @}*/ /** @}*/

View File

@ -42,8 +42,7 @@ namespace mbed {
*/ */
class ControlPlane_netif { class ControlPlane_netif {
public: public:
ControlPlane_netif() {} virtual ~ControlPlane_netif() = default;
virtual ~ControlPlane_netif() {}
protected: protected:
friend class CellularNonIPSocket; friend class CellularNonIPSocket;

View File

@ -140,6 +140,9 @@ public:
* @return NSAPI_ERROR_OK on success, negative error code on failure. * @return NSAPI_ERROR_OK on success, negative error code on failure.
*/ */
virtual nsapi_error_t add_dns_server(const SocketAddress &address, const char *interface_name = NULL) = 0; virtual nsapi_error_t add_dns_server(const SocketAddress &address, const char *interface_name = NULL) = 0;
protected:
~DNS() = default;
}; };
#endif #endif

View File

@ -46,7 +46,7 @@ public:
/** Destroy the DTLSSocket and closes the transport. /** Destroy the DTLSSocket and closes the transport.
*/ */
virtual ~DTLSSocket(); ~DTLSSocket() override;
/** Create a socket on a network interface. /** Create a socket on a network interface.
* *
@ -74,7 +74,7 @@ public:
* @return NSAPI_ERROR_OK on success, negative error code on failure. * @return NSAPI_ERROR_OK on success, negative error code on failure.
* See @ref UDPSocket::open. * See @ref UDPSocket::open.
*/ */
virtual nsapi_error_t open(NetworkStack *stack) nsapi_error_t open(NetworkStack *stack)
{ {
return _udp_socket.open(stack); return _udp_socket.open(stack);
} }

View File

@ -24,10 +24,7 @@
#if defined(MBEDTLS_SSL_CLI_C) #if defined(MBEDTLS_SSL_CLI_C)
DTLSSocketWrapper::DTLSSocketWrapper(Socket *transport, const char *hostname, control_transport control) : DTLSSocketWrapper::DTLSSocketWrapper(Socket *transport, const char *hostname, control_transport control) :
TLSSocketWrapper(transport, hostname, control), TLSSocketWrapper(transport, hostname, control)
_int_ms_tick(0),
_timer_event_id(0),
_timer_expired(false)
{ {
mbedtls_ssl_conf_transport(get_ssl_config(), MBEDTLS_SSL_TRANSPORT_DATAGRAM); mbedtls_ssl_conf_transport(get_ssl_config(), MBEDTLS_SSL_TRANSPORT_DATAGRAM);
mbedtls_ssl_set_timer_cb(get_ssl_context(), this, timing_set_delay, timing_get_delay); mbedtls_ssl_set_timer_cb(get_ssl_context(), this, timing_set_delay, timing_get_delay);

View File

@ -43,9 +43,9 @@ private:
static void timing_set_delay(void *ctx, uint32_t int_ms, uint32_t fin_ms); static void timing_set_delay(void *ctx, uint32_t int_ms, uint32_t fin_ms);
static int timing_get_delay(void *ctx); static int timing_get_delay(void *ctx);
void timer_event(); void timer_event();
uint64_t _int_ms_tick; uint64_t _int_ms_tick = 0;
int _timer_event_id; int _timer_event_id = 0;
bool _timer_expired : 1; bool _timer_expired = false;
}; };
#endif #endif

View File

@ -21,13 +21,7 @@ using namespace mbed;
/* Interface implementation */ /* Interface implementation */
EMACInterface::EMACInterface(EMAC &emac, OnboardNetworkStack &stack) : EMACInterface::EMACInterface(EMAC &emac, OnboardNetworkStack &stack) :
_emac(emac), _emac(emac),
_stack(stack), _stack(stack)
_interface(NULL),
_dhcp(true),
_blocking(true),
_ip_address(),
_netmask(),
_gateway()
{ {
} }

View File

@ -64,7 +64,7 @@ public:
* @param gateway SocketAddress representation of the local gateway * @param gateway SocketAddress representation of the local gateway
* @return 0 on success, negative error code on failure * @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); nsapi_error_t set_network(const SocketAddress &ip_address, const SocketAddress &netmask, const SocketAddress &gateway) override;
/** Enable or disable DHCP on the network /** Enable or disable DHCP on the network
* *
@ -74,43 +74,43 @@ public:
* @retval NSAPI_ERROR_OK on success. * @retval NSAPI_ERROR_OK on success.
* @retval NSAPI_ERROR_UNSUPPORTED if operation is not supported. * @retval NSAPI_ERROR_UNSUPPORTED if operation is not supported.
*/ */
virtual nsapi_error_t set_dhcp(bool dhcp); nsapi_error_t set_dhcp(bool dhcp) override;
/** @copydoc NetworkInterface::connect */ /** @copydoc NetworkInterface::connect */
virtual nsapi_error_t connect(); nsapi_error_t connect() override;
/** @copydoc NetworkInterface::disconnect */ /** @copydoc NetworkInterface::disconnect */
virtual nsapi_error_t disconnect(); nsapi_error_t disconnect() override;
/** @copydoc NetworkInterface::get_mac_address */ /** @copydoc NetworkInterface::get_mac_address */
virtual const char *get_mac_address(); const char *get_mac_address() override;
/** @copydoc NetworkInterface::get_ip_address */ /** @copydoc NetworkInterface::get_ip_address */
virtual nsapi_error_t get_ip_address(SocketAddress *address); nsapi_error_t get_ip_address(SocketAddress *address) override;
/** @copydoc NetworkInterface::get_ipv6_link_local_address */ /** @copydoc NetworkInterface::get_ipv6_link_local_address */
virtual nsapi_error_t get_ipv6_link_local_address(SocketAddress *address); nsapi_error_t get_ipv6_link_local_address(SocketAddress *address) override;
/** @copydoc NetworkInterface::get_netmask */ /** @copydoc NetworkInterface::get_netmask */
virtual nsapi_error_t get_netmask(SocketAddress *address); nsapi_error_t get_netmask(SocketAddress *address) override;
/** @copydoc NetworkInterface::get_gateway */ /** @copydoc NetworkInterface::get_gateway */
virtual nsapi_error_t get_gateway(SocketAddress *address); nsapi_error_t get_gateway(SocketAddress *address) override;
/** @copydoc NetworkInterface::get_interface_name */ /** @copydoc NetworkInterface::get_interface_name */
virtual char *get_interface_name(char *interface_name); char *get_interface_name(char *interface_name) override;
/** @copydoc NetworkInterface::set_as_default */ /** @copydoc NetworkInterface::set_as_default */
virtual void set_as_default(); void set_as_default() override;
/** @copydoc NetworkInterface::attach */ /** @copydoc NetworkInterface::attach */
virtual void attach(mbed::Callback<void(nsapi_event_t, intptr_t)> status_cb); void attach(mbed::Callback<void(nsapi_event_t, intptr_t)> status_cb) override;
/** @copydoc NetworkInterface::get_connection_status */ /** @copydoc NetworkInterface::get_connection_status */
virtual nsapi_connection_status_t get_connection_status() const; nsapi_connection_status_t get_connection_status() const override;
/** @copydoc NetworkInterface::set_blocking */ /** @copydoc NetworkInterface::set_blocking */
virtual nsapi_error_t set_blocking(bool blocking); nsapi_error_t set_blocking(bool blocking) override;
/** Provide access to the EMAC /** Provide access to the EMAC
* *
@ -125,7 +125,7 @@ public:
return _emac; return _emac;
} }
virtual EMACInterface *emacInterface() EMACInterface *emacInterface() final
{ {
return this; return this;
} }
@ -135,17 +135,17 @@ protected:
* *
* @return The underlying network stack * @return The underlying network stack
*/ */
virtual NetworkStack *get_stack(); NetworkStack *get_stack() final;
EMAC &_emac; EMAC &_emac;
OnboardNetworkStack &_stack; OnboardNetworkStack &_stack;
OnboardNetworkStack::Interface *_interface; OnboardNetworkStack::Interface *_interface = nullptr;
bool _dhcp; bool _dhcp = true;
bool _blocking; bool _blocking = true;
char _mac_address[NSAPI_MAC_SIZE]; char _mac_address[NSAPI_MAC_SIZE];
char _ip_address[NSAPI_IPv6_SIZE]; char _ip_address[NSAPI_IPv6_SIZE] {};
char _netmask[NSAPI_IPv4_SIZE]; char _netmask[NSAPI_IPv4_SIZE] {};
char _gateway[NSAPI_IPv4_SIZE]; char _gateway[NSAPI_IPv4_SIZE] {};
mbed::Callback<void(nsapi_event_t, intptr_t)> _connection_status_cb; mbed::Callback<void(nsapi_event_t, intptr_t)> _connection_status_cb;
}; };

View File

@ -31,7 +31,7 @@ public:
/** @copydoc NetworkInterface::ethInterface /** @copydoc NetworkInterface::ethInterface
*/ */
virtual EthInterface *ethInterface() EthInterface *ethInterface() final
{ {
return this; return this;
} }

View File

@ -15,8 +15,6 @@
*/ */
#include "ICMPSocket.h" #include "ICMPSocket.h"
#include "Timer.h"
#include "mbed_assert.h"
ICMPSocket::ICMPSocket() ICMPSocket::ICMPSocket()
{ {

View File

@ -39,7 +39,7 @@ public:
#if !defined(DOXYGEN_ONLY) #if !defined(DOXYGEN_ONLY)
protected: protected:
virtual nsapi_protocol_t get_proto(); nsapi_protocol_t get_proto() override;
#endif //!defined(DOXYGEN_ONLY) #endif //!defined(DOXYGEN_ONLY)
}; };

View File

@ -44,8 +44,8 @@ public:
* @retval int Other negative error codes for stack-related failures. * @retval int Other negative error codes for stack-related failures.
* See \ref NetworkStack::socket_send. * See \ref NetworkStack::socket_send.
*/ */
virtual nsapi_size_or_error_t sendto(const SocketAddress &address, nsapi_size_or_error_t sendto(const SocketAddress &address,
const void *data, nsapi_size_t size); const void *data, nsapi_size_t size) override;
/** Receive a datagram and store the source address in address if it's not NULL. /** Receive a datagram and store the source address in address if it's not NULL.
* *
@ -70,8 +70,8 @@ public:
* @retval int Other negative error codes for stack-related failures. * @retval int Other negative error codes for stack-related failures.
* See \ref NetworkStack::socket_recv. * See \ref NetworkStack::socket_recv.
*/ */
virtual nsapi_size_or_error_t recvfrom(SocketAddress *address, nsapi_size_or_error_t recvfrom(SocketAddress *address,
void *data, nsapi_size_t size); void *data, nsapi_size_t size) override;
/** Set the remote address for next send() call and filtering /** Set the remote address for next send() call and filtering
* of incoming packets. To reset the address, zero initialized * of incoming packets. To reset the address, zero initialized
@ -80,7 +80,7 @@ public:
* @param address The SocketAddress of the remote host. * @param address The SocketAddress of the remote host.
* @return NSAPI_ERROR_OK on success. * @return NSAPI_ERROR_OK on success.
*/ */
virtual nsapi_error_t connect(const SocketAddress &address); nsapi_error_t connect(const SocketAddress &address) override;
/** Send a raw data to connected remote address. /** Send a raw data to connected remote address.
* *
@ -100,7 +100,7 @@ public:
* @retval int Other negative error codes for stack-related failures. * @retval int Other negative error codes for stack-related failures.
* See \ref NetworkStack::socket_send. * See \ref NetworkStack::socket_send.
*/ */
virtual nsapi_size_or_error_t send(const void *data, nsapi_size_t size); nsapi_size_or_error_t send(const void *data, nsapi_size_t size) override;
/** Receive data from a socket. /** Receive data from a socket.
* *
@ -121,21 +121,21 @@ public:
* @retval int Other negative error codes for stack-related failures. * @retval int Other negative error codes for stack-related failures.
* See \ref NetworkStack::socket_recv. * See \ref NetworkStack::socket_recv.
*/ */
virtual nsapi_size_or_error_t recv(void *data, nsapi_size_t size); nsapi_size_or_error_t recv(void *data, nsapi_size_t size) override;
/** Not implemented for InternetDatagramSocket. /** Not implemented for InternetDatagramSocket.
* *
* @param error Not used. * @param error Not used.
* @return NSAPI_ERROR_UNSUPPORTED * @return NSAPI_ERROR_UNSUPPORTED
*/ */
virtual Socket *accept(nsapi_error_t *error = NULL); Socket *accept(nsapi_error_t *error = nullptr) override;
/** Not implemented for InternetDatagramSocket. /** Not implemented for InternetDatagramSocket.
* *
* @param backlog Not used. * @param backlog Not used.
* @return NSAPI_ERROR_UNSUPPORTED * @return NSAPI_ERROR_UNSUPPORTED
*/ */
virtual nsapi_error_t listen(int backlog = 1); nsapi_error_t listen(int backlog = 1) override;
#if !defined(DOXYGEN_ONLY) #if !defined(DOXYGEN_ONLY)
protected: protected:

View File

@ -21,12 +21,7 @@
using namespace mbed; using namespace mbed;
InternetSocket::InternetSocket() InternetSocket::InternetSocket()
: _stack(0), _socket(0), _timeout(osWaitForever),
_remote_peer(),
_readers(0), _writers(0),
_factory_allocated(false)
{ {
core_util_atomic_flag_clear(&_pending);
_socket_stats.stats_new_socket_entry(this); _socket_stats.stats_new_socket_entry(this);
} }
@ -55,7 +50,7 @@ nsapi_error_t InternetSocket::open(NetworkStack *stack)
_socket_stats.stats_update_socket_state(this, SOCK_OPEN); _socket_stats.stats_update_socket_state(this, SOCK_OPEN);
_socket = socket; _socket = socket;
_event = callback(this, &InternetSocket::event); _event = callback(this, &InternetSocket::event);
_stack->socket_attach(_socket, Callback<void()>::thunk, &_event); _stack->socket_attach(_socket, _event.thunk, &_event);
_interface_name[0] = '\0'; _interface_name[0] = '\0';
_lock.unlock(); _lock.unlock();
return NSAPI_ERROR_OK; return NSAPI_ERROR_OK;

View File

@ -38,7 +38,7 @@ public:
* *
* @note Closes socket if it's still open. * @note Closes socket if it's still open.
*/ */
virtual ~InternetSocket(); ~InternetSocket() override;
/** Open a network socket on the network stack of the given /** Open a network socket on the network stack of the given
* network interface. * network interface.
@ -70,7 +70,7 @@ public:
* @retval int negative error codes for stack-related failures. * @retval int negative error codes for stack-related failures.
* See @ref NetworkStack::socket_close. * See @ref NetworkStack::socket_close.
*/ */
virtual nsapi_error_t close(); nsapi_error_t close() override;
/** Subscribe to an IP multicast group. /** Subscribe to an IP multicast group.
* *
@ -98,31 +98,31 @@ public:
/** @copydoc Socket::bind /** @copydoc Socket::bind
*/ */
virtual nsapi_error_t bind(const SocketAddress &address); nsapi_error_t bind(const SocketAddress &address) override;
/** @copydoc Socket::set_blocking /** @copydoc Socket::set_blocking
*/ */
virtual void set_blocking(bool blocking); void set_blocking(bool blocking) override;
/** @copydoc Socket::set_timeout /** @copydoc Socket::set_timeout
*/ */
virtual void set_timeout(int timeout); void set_timeout(int timeout) override;
/** @copydoc Socket::setsockopt /** @copydoc Socket::setsockopt
*/ */
virtual nsapi_error_t setsockopt(int level, int optname, const void *optval, unsigned optlen); nsapi_error_t setsockopt(int level, int optname, const void *optval, unsigned optlen) override;
/** @copydoc Socket::getsockopt /** @copydoc Socket::getsockopt
*/ */
virtual nsapi_error_t getsockopt(int level, int optname, void *optval, unsigned *optlen); nsapi_error_t getsockopt(int level, int optname, void *optval, unsigned *optlen) override;
/** @copydoc Socket::sigio /** @copydoc Socket::sigio
*/ */
virtual void sigio(mbed::Callback<void()> func); void sigio(mbed::Callback<void()> func) override;
/** @copydoc Socket::getpeername /** @copydoc Socket::getpeername
*/ */
virtual nsapi_error_t getpeername(SocketAddress *address); nsapi_error_t getpeername(SocketAddress *address) override;
/** Register a callback on state change of the socket. /** Register a callback on state change of the socket.
* *
@ -157,21 +157,21 @@ public:
protected: protected:
InternetSocket(); InternetSocket();
virtual nsapi_protocol_t get_proto() = 0; virtual nsapi_protocol_t get_proto() = 0;
virtual void event(); void event();
int modify_multicast_group(const SocketAddress &address, nsapi_socket_option_t socketopt); int modify_multicast_group(const SocketAddress &address, nsapi_socket_option_t socketopt);
char _interface_name[NSAPI_INTERFACE_NAME_MAX_SIZE]; char _interface_name[NSAPI_INTERFACE_NAME_MAX_SIZE];
NetworkStack *_stack; NetworkStack *_stack = nullptr;
nsapi_socket_t _socket; nsapi_socket_t _socket = nullptr;
uint32_t _timeout; uint32_t _timeout = osWaitForever;
mbed::Callback<void()> _event; mbed::Callback<void()> _event;
mbed::Callback<void()> _callback; mbed::Callback<void()> _callback;
rtos::EventFlags _event_flag; rtos::EventFlags _event_flag;
rtos::Mutex _lock; rtos::Mutex _lock;
SocketAddress _remote_peer; SocketAddress _remote_peer;
uint8_t _readers; uint8_t _readers = 0;
uint8_t _writers; uint8_t _writers = 0;
core_util_atomic_flag _pending; core_util_atomic_flag _pending = CORE_UTIL_ATOMIC_FLAG_INIT;
bool _factory_allocated; bool _factory_allocated = false;
// Event flags // Event flags
static const int READ_FLAG = 0x1u; static const int READ_FLAG = 0x1u;

View File

@ -24,13 +24,7 @@ using namespace mbed;
/* Interface implementation */ /* Interface implementation */
L3IPInterface::L3IPInterface(L3IP &l3ip, OnboardNetworkStack &stack) : L3IPInterface::L3IPInterface(L3IP &l3ip, OnboardNetworkStack &stack) :
_l3ip(l3ip), _l3ip(l3ip),
_stack(stack), _stack(stack)
_interface(NULL),
_dhcp(true),
_blocking(true),
_ip_address(),
_netmask(),
_gateway()
{ {
} }

View File

@ -49,7 +49,7 @@ public:
*/ */
L3IPInterface(L3IP &l3ip = L3IP::get_default_instance(), L3IPInterface(L3IP &l3ip = L3IP::get_default_instance(),
OnboardNetworkStack &stack = OnboardNetworkStack::get_default_instance()); OnboardNetworkStack &stack = OnboardNetworkStack::get_default_instance());
virtual ~L3IPInterface(); ~L3IPInterface() override;
/** Set a static IP address /** Set a static IP address
* *
* Configures this network interface to use a static IP address. * Configures this network interface to use a static IP address.
@ -61,7 +61,7 @@ public:
* @param gateway SocketAddress representation of the local gateway * @param gateway SocketAddress representation of the local gateway
* @return 0 on success, negative error code on failure * @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); nsapi_error_t set_network(const SocketAddress &ip_address, const SocketAddress &netmask, const SocketAddress &gateway) override;
/** Enable or disable DHCP on the network /** Enable or disable DHCP on the network
* *
@ -70,56 +70,56 @@ public:
* @param dhcp False to disable dhcp (defaults to enabled) * @param dhcp False to disable dhcp (defaults to enabled)
* @return 0 on success, negative error code on failure * @return 0 on success, negative error code on failure
*/ */
virtual nsapi_error_t set_dhcp(bool dhcp); nsapi_error_t set_dhcp(bool dhcp) override;
/** Start the interface /** Start the interface
* @return 0 on success, negative on failure * @return 0 on success, negative on failure
*/ */
virtual nsapi_error_t connect(); nsapi_error_t connect() override;
/** Stop the interface /** Stop the interface
* @return 0 on success, negative on failure * @return 0 on success, negative on failure
*/ */
virtual nsapi_error_t disconnect(); nsapi_error_t disconnect() override;
/** @copydoc NetworkInterface::get_ip_address */ /** @copydoc NetworkInterface::get_ip_address */
virtual nsapi_error_t get_ip_address(SocketAddress *address); nsapi_error_t get_ip_address(SocketAddress *address) override;
/** @copydoc NetworkInterface::get_netmask */ /** @copydoc NetworkInterface::get_netmask */
virtual nsapi_error_t get_netmask(SocketAddress *address); nsapi_error_t get_netmask(SocketAddress *address) override;
/** @copydoc NetworkInterface::get_gateway */ /** @copydoc NetworkInterface::get_gateway */
virtual nsapi_error_t get_gateway(SocketAddress *address); nsapi_error_t get_gateway(SocketAddress *address) override;
/** Get the network interface name /** Get the network interface name
* *
* @return Null-terminated representation of the network interface name * @return Null-terminated representation of the network interface name
* or null if interface not exists * or null if interface not exists
*/ */
virtual char *get_interface_name(char *interface_name); char *get_interface_name(char *interface_name) override;
/** Set the network interface as default one /** Set the network interface as default one
*/ */
virtual void set_as_default(); void set_as_default() override;
/** Register callback for status reporting /** Register callback for status reporting
* *
* @param status_cb The callback for status changes * @param status_cb The callback for status changes
*/ */
virtual void attach(mbed::Callback<void(nsapi_event_t, intptr_t)> status_cb); void attach(mbed::Callback<void(nsapi_event_t, intptr_t)> status_cb) override;
/** Get the connection status /** Get the connection status
* *
* @return The connection status according to nsapi_connection_status_t * @return The connection status according to nsapi_connection_status_t
*/ */
virtual nsapi_connection_status_t get_connection_status() const; nsapi_connection_status_t get_connection_status() const override;
/** Set blocking status of connect() which by default should be blocking /** Set blocking status of connect() which by default should be blocking
* *
* @param blocking true if connect is blocking * @param blocking true if connect is blocking
* @return 0 on success, negative error code on failure * @return 0 on success, negative error code on failure
*/ */
virtual nsapi_error_t set_blocking(bool blocking); nsapi_error_t set_blocking(bool blocking) override;
/** Provide access to the L3IP /** Provide access to the L3IP
* *
@ -134,26 +134,31 @@ public:
return _l3ip; return _l3ip;
} }
virtual L3IPInterface *l3ipInterface() #if 0
/* NetworkInterface does not currently have l3ipInterface, so this
* "dynamic cast" is non-functional.
*/
L3IPInterface *l3ipInterface() final
{ {
return this; return this;
} }
#endif
protected: protected:
/** Provide access to the underlying stack /** Provide access to the underlying stack
* *
* @return The underlying network stack * @return The underlying network stack
*/ */
virtual NetworkStack *get_stack(); NetworkStack *get_stack() override;
L3IP &_l3ip; L3IP &_l3ip;
OnboardNetworkStack &_stack; OnboardNetworkStack &_stack;
OnboardNetworkStack::Interface *_interface; OnboardNetworkStack::Interface *_interface = nullptr;
bool _dhcp; bool _dhcp = true;
bool _blocking; bool _blocking = true;
char _ip_address[NSAPI_IPv6_SIZE]; char _ip_address[NSAPI_IPv6_SIZE] {};
char _netmask[NSAPI_IPv4_SIZE]; char _netmask[NSAPI_IPv4_SIZE] {};
char _gateway[NSAPI_IPv4_SIZE]; char _gateway[NSAPI_IPv4_SIZE] {};
mbed::Callback<void(nsapi_event_t, intptr_t)> _connection_status_cb; mbed::Callback<void(nsapi_event_t, intptr_t)> _connection_status_cb;
}; };

View File

@ -30,7 +30,7 @@ class MeshInterface : public virtual NetworkInterface {
public: public:
/** @copydoc NetworkInterface::meshInterface /** @copydoc NetworkInterface::meshInterface
*/ */
virtual MeshInterface *meshInterface() MeshInterface *meshInterface() final
{ {
return this; return this;
} }

View File

@ -182,6 +182,9 @@ public:
* @param len Payload size, must be less or equal to the allocated size * @param len Payload size, must be less or equal to the allocated size
*/ */
virtual void set_len(net_stack_mem_buf_t *buf, uint32_t len) = 0; virtual void set_len(net_stack_mem_buf_t *buf, uint32_t len) = 0;
protected:
~NetStackMemoryManager() = default;
}; };
#endif /* NET_STACK_MEMORY_MANAGER_H */ #endif /* NET_STACK_MEMORY_MANAGER_H */

View File

@ -383,7 +383,7 @@ public:
*/ */
virtual EthInterface *ethInterface() virtual EthInterface *ethInterface()
{ {
return 0; return nullptr;
} }
/** Return pointer to a WiFiInterface. /** Return pointer to a WiFiInterface.
@ -391,7 +391,7 @@ public:
*/ */
virtual WiFiInterface *wifiInterface() virtual WiFiInterface *wifiInterface()
{ {
return 0; return nullptr;
} }
/** Return pointer to a MeshInterface. /** Return pointer to a MeshInterface.
@ -399,7 +399,7 @@ public:
*/ */
virtual MeshInterface *meshInterface() virtual MeshInterface *meshInterface()
{ {
return 0; return nullptr;
} }
/** Return pointer to an EMACInterface. /** Return pointer to an EMACInterface.
@ -407,7 +407,7 @@ public:
*/ */
virtual EMACInterface *emacInterface() virtual EMACInterface *emacInterface()
{ {
return 0; return nullptr;
} }
/** Return pointer to a CellularInterface. /** Return pointer to a CellularInterface.
@ -415,7 +415,7 @@ public:
*/ */
virtual CellularInterface *cellularInterface() virtual CellularInterface *cellularInterface()
{ {
return 0; return nullptr;
} }
#if !defined(DOXYGEN_ONLY) #if !defined(DOXYGEN_ONLY)

View File

@ -235,7 +235,7 @@ private:
} }
public: public:
virtual nsapi_error_t get_ip_address(SocketAddress *address) nsapi_error_t get_ip_address(SocketAddress *address) override
{ {
if (!_stack_api()->get_ip_address) { if (!_stack_api()->get_ip_address) {
return NSAPI_ERROR_UNSUPPORTED; return NSAPI_ERROR_UNSUPPORTED;
@ -246,7 +246,7 @@ public:
return *address ? NSAPI_ERROR_OK : NSAPI_ERROR_NO_ADDRESS; return *address ? NSAPI_ERROR_OK : NSAPI_ERROR_NO_ADDRESS;
} }
virtual nsapi_error_t gethostbyname(const char *name, SocketAddress *address, nsapi_version_t version, const char *interface_name) nsapi_error_t gethostbyname(const char *name, SocketAddress *address, nsapi_version_t version, const char *interface_name) override
{ {
if (!_stack_api()->gethostbyname) { if (!_stack_api()->gethostbyname) {
return NetworkStack::gethostbyname(name, address, version, interface_name); return NetworkStack::gethostbyname(name, address, version, interface_name);
@ -258,7 +258,7 @@ public:
return err; return err;
} }
virtual nsapi_error_t add_dns_server(const SocketAddress &address, const char *interface_name) nsapi_error_t add_dns_server(const SocketAddress &address, const char *interface_name) override
{ {
if (!_stack_api()->add_dns_server) { if (!_stack_api()->add_dns_server) {
return NetworkStack::add_dns_server(address, interface_name); return NetworkStack::add_dns_server(address, interface_name);
@ -267,7 +267,7 @@ public:
return _stack_api()->add_dns_server(_stack(), address.get_addr()); return _stack_api()->add_dns_server(_stack(), address.get_addr());
} }
virtual nsapi_error_t setstackopt(int level, int optname, const void *optval, unsigned optlen) nsapi_error_t setstackopt(int level, int optname, const void *optval, unsigned optlen) override
{ {
if (!_stack_api()->setstackopt) { if (!_stack_api()->setstackopt) {
return NSAPI_ERROR_UNSUPPORTED; return NSAPI_ERROR_UNSUPPORTED;
@ -276,7 +276,7 @@ public:
return _stack_api()->setstackopt(_stack(), level, optname, optval, optlen); return _stack_api()->setstackopt(_stack(), level, optname, optval, optlen);
} }
virtual nsapi_error_t getstackopt(int level, int optname, void *optval, unsigned *optlen) nsapi_error_t getstackopt(int level, int optname, void *optval, unsigned *optlen) override
{ {
if (!_stack_api()->getstackopt) { if (!_stack_api()->getstackopt) {
return NSAPI_ERROR_UNSUPPORTED; return NSAPI_ERROR_UNSUPPORTED;
@ -286,7 +286,7 @@ public:
} }
protected: protected:
virtual nsapi_error_t socket_open(nsapi_socket_t *socket, nsapi_protocol_t proto) nsapi_error_t socket_open(nsapi_socket_t *socket, nsapi_protocol_t proto) override
{ {
if (!_stack_api()->socket_open) { if (!_stack_api()->socket_open) {
return NSAPI_ERROR_UNSUPPORTED; return NSAPI_ERROR_UNSUPPORTED;
@ -295,7 +295,7 @@ protected:
return _stack_api()->socket_open(_stack(), socket, proto); return _stack_api()->socket_open(_stack(), socket, proto);
} }
virtual nsapi_error_t socket_close(nsapi_socket_t socket) nsapi_error_t socket_close(nsapi_socket_t socket) override
{ {
if (!_stack_api()->socket_close) { if (!_stack_api()->socket_close) {
return NSAPI_ERROR_UNSUPPORTED; return NSAPI_ERROR_UNSUPPORTED;
@ -304,7 +304,7 @@ protected:
return _stack_api()->socket_close(_stack(), socket); return _stack_api()->socket_close(_stack(), socket);
} }
virtual nsapi_error_t socket_bind(nsapi_socket_t socket, const SocketAddress &address) nsapi_error_t socket_bind(nsapi_socket_t socket, const SocketAddress &address) override
{ {
if (!_stack_api()->socket_bind) { if (!_stack_api()->socket_bind) {
return NSAPI_ERROR_UNSUPPORTED; return NSAPI_ERROR_UNSUPPORTED;
@ -313,7 +313,7 @@ protected:
return _stack_api()->socket_bind(_stack(), socket, address.get_addr(), address.get_port()); return _stack_api()->socket_bind(_stack(), socket, address.get_addr(), address.get_port());
} }
virtual nsapi_error_t socket_listen(nsapi_socket_t socket, int backlog) nsapi_error_t socket_listen(nsapi_socket_t socket, int backlog) override
{ {
if (!_stack_api()->socket_listen) { if (!_stack_api()->socket_listen) {
return NSAPI_ERROR_UNSUPPORTED; return NSAPI_ERROR_UNSUPPORTED;
@ -322,7 +322,7 @@ protected:
return _stack_api()->socket_listen(_stack(), socket, backlog); return _stack_api()->socket_listen(_stack(), socket, backlog);
} }
virtual nsapi_error_t socket_connect(nsapi_socket_t socket, const SocketAddress &address) nsapi_error_t socket_connect(nsapi_socket_t socket, const SocketAddress &address) override
{ {
if (!_stack_api()->socket_connect) { if (!_stack_api()->socket_connect) {
return NSAPI_ERROR_UNSUPPORTED; return NSAPI_ERROR_UNSUPPORTED;
@ -331,7 +331,7 @@ protected:
return _stack_api()->socket_connect(_stack(), socket, address.get_addr(), address.get_port()); return _stack_api()->socket_connect(_stack(), socket, address.get_addr(), address.get_port());
} }
virtual nsapi_error_t socket_accept(nsapi_socket_t server, nsapi_socket_t *socket, SocketAddress *address) nsapi_error_t socket_accept(nsapi_socket_t server, nsapi_socket_t *socket, SocketAddress *address) override
{ {
if (!_stack_api()->socket_accept) { if (!_stack_api()->socket_accept) {
return NSAPI_ERROR_UNSUPPORTED; return NSAPI_ERROR_UNSUPPORTED;
@ -350,7 +350,7 @@ protected:
return err; return err;
} }
virtual nsapi_size_or_error_t socket_send(nsapi_socket_t socket, const void *data, nsapi_size_t size) nsapi_size_or_error_t socket_send(nsapi_socket_t socket, const void *data, nsapi_size_t size) override
{ {
if (!_stack_api()->socket_send) { if (!_stack_api()->socket_send) {
return NSAPI_ERROR_UNSUPPORTED; return NSAPI_ERROR_UNSUPPORTED;
@ -359,7 +359,7 @@ protected:
return _stack_api()->socket_send(_stack(), socket, data, size); return _stack_api()->socket_send(_stack(), socket, data, size);
} }
virtual nsapi_size_or_error_t socket_recv(nsapi_socket_t socket, void *data, nsapi_size_t size) nsapi_size_or_error_t socket_recv(nsapi_socket_t socket, void *data, nsapi_size_t size) override
{ {
if (!_stack_api()->socket_recv) { if (!_stack_api()->socket_recv) {
return NSAPI_ERROR_UNSUPPORTED; return NSAPI_ERROR_UNSUPPORTED;
@ -368,7 +368,7 @@ protected:
return _stack_api()->socket_recv(_stack(), socket, data, size); return _stack_api()->socket_recv(_stack(), socket, data, size);
} }
virtual nsapi_size_or_error_t socket_sendto(nsapi_socket_t socket, const SocketAddress &address, const void *data, nsapi_size_t size) nsapi_size_or_error_t socket_sendto(nsapi_socket_t socket, const SocketAddress &address, const void *data, nsapi_size_t size) override
{ {
if (!_stack_api()->socket_sendto) { if (!_stack_api()->socket_sendto) {
return NSAPI_ERROR_UNSUPPORTED; return NSAPI_ERROR_UNSUPPORTED;
@ -377,7 +377,7 @@ protected:
return _stack_api()->socket_sendto(_stack(), socket, address.get_addr(), address.get_port(), data, size); return _stack_api()->socket_sendto(_stack(), socket, address.get_addr(), address.get_port(), data, size);
} }
virtual nsapi_size_or_error_t socket_recvfrom(nsapi_socket_t socket, SocketAddress *address, void *data, nsapi_size_t size) nsapi_size_or_error_t socket_recvfrom(nsapi_socket_t socket, SocketAddress *address, void *data, nsapi_size_t size) override
{ {
if (!_stack_api()->socket_recvfrom) { if (!_stack_api()->socket_recvfrom) {
return NSAPI_ERROR_UNSUPPORTED; return NSAPI_ERROR_UNSUPPORTED;
@ -396,7 +396,7 @@ protected:
return err; return err;
} }
virtual void socket_attach(nsapi_socket_t socket, void (*callback)(void *), void *data) void socket_attach(nsapi_socket_t socket, void (*callback)(void *), void *data) override
{ {
if (!_stack_api()->socket_attach) { if (!_stack_api()->socket_attach) {
return; return;
@ -405,7 +405,7 @@ protected:
return _stack_api()->socket_attach(_stack(), socket, callback, data); return _stack_api()->socket_attach(_stack(), socket, callback, data);
} }
virtual nsapi_error_t setsockopt(nsapi_socket_t socket, int level, int optname, const void *optval, unsigned optlen) nsapi_error_t setsockopt(nsapi_socket_t socket, int level, int optname, const void *optval, unsigned optlen) override
{ {
if (!_stack_api()->setsockopt) { if (!_stack_api()->setsockopt) {
return NSAPI_ERROR_UNSUPPORTED; return NSAPI_ERROR_UNSUPPORTED;
@ -414,7 +414,7 @@ protected:
return _stack_api()->setsockopt(_stack(), socket, level, optname, optval, optlen); return _stack_api()->setsockopt(_stack(), socket, level, optname, optval, optlen);
} }
virtual nsapi_error_t getsockopt(nsapi_socket_t socket, int level, int optname, void *optval, unsigned *optlen) nsapi_error_t getsockopt(nsapi_socket_t socket, int level, int optname, void *optval, unsigned *optlen) override
{ {
if (!_stack_api()->getsockopt) { if (!_stack_api()->getsockopt) {
return NSAPI_ERROR_UNSUPPORTED; return NSAPI_ERROR_UNSUPPORTED;

View File

@ -37,9 +37,9 @@ class OnboardNetworkStack;
* NetworkStack, a network stack can be used as a target * NetworkStack, a network stack can be used as a target
* for instantiating network sockets. * for instantiating network sockets.
*/ */
class NetworkStack: public DNS { class NetworkStack : public DNS {
public: public:
virtual ~NetworkStack() {}; virtual ~NetworkStack() = default;
/** Get the local IP address /** Get the local IP address
* *

View File

@ -47,9 +47,10 @@ public:
* NetworkInterface API. * NetworkInterface API.
*/ */
class Interface { class Interface {
public: protected:
virtual ~Interface() {} ~Interface() = default;
public:
/** Connect the interface to the network /** Connect the interface to the network
* *
* Sets up a connection on specified network interface, using DHCP or provided network details. If the @a dhcp is set to * Sets up a connection on specified network interface, using DHCP or provided network details. If the @a dhcp is set to
@ -167,6 +168,10 @@ public:
{ {
} }
OnboardNetworkStack *onboardNetworkStack() final
{
return this;
}
}; };
#endif /* MBED_IPSTACK_H */ #endif /* MBED_IPSTACK_H */

View File

@ -33,7 +33,7 @@ public:
*/ */
static PPP &get_default_instance(); static PPP &get_default_instance();
virtual ~PPP() {}; virtual ~PPP() = default;
/** /**
* Callback to be registered with PPP interface and to be called for received packets * Callback to be registered with PPP interface and to be called for received packets

View File

@ -22,16 +22,7 @@ using namespace mbed;
/* Interface implementation */ /* Interface implementation */
PPPInterface::PPPInterface(PPP &ppp, OnboardNetworkStack &stack) : PPPInterface::PPPInterface(PPP &ppp, OnboardNetworkStack &stack) :
_ppp(ppp), _ppp(ppp),
_stack(stack), _stack(stack)
_interface(NULL),
_blocking(true),
_ip_address(),
_netmask(),
_gateway(),
_stream(NULL),
_ip_stack(DEFAULT_STACK),
_uname(NULL),
_password(NULL)
{ {
} }

View File

@ -48,59 +48,59 @@ public:
*/ */
PPPInterface(PPP &ppp = PPP::get_default_instance(), PPPInterface(PPP &ppp = PPP::get_default_instance(),
OnboardNetworkStack &stack = OnboardNetworkStack::get_default_instance()); OnboardNetworkStack &stack = OnboardNetworkStack::get_default_instance());
virtual ~PPPInterface(); ~PPPInterface() override;
/** @copydoc NetworkInterface::set_network */ /** @copydoc NetworkInterface::set_network */
virtual nsapi_error_t set_network(const SocketAddress &ip_address, const SocketAddress &netmask, const SocketAddress &gateway); nsapi_error_t set_network(const SocketAddress &ip_address, const SocketAddress &netmask, const SocketAddress &gateway) override;
/** @copydoc NetworkInterface::connect */ /** @copydoc NetworkInterface::connect */
virtual nsapi_error_t connect(); nsapi_error_t connect() override;
/** @copydoc NetworkInterface::disconnect */ /** @copydoc NetworkInterface::disconnect */
virtual nsapi_error_t disconnect(); nsapi_error_t disconnect() override;
/** @copydoc NetworkInterface::get_ip_address */ /** @copydoc NetworkInterface::get_ip_address */
virtual nsapi_error_t get_ip_address(SocketAddress *address); nsapi_error_t get_ip_address(SocketAddress *address) override;
/** @copydoc NetworkInterface::get_netmask */ /** @copydoc NetworkInterface::get_netmask */
virtual nsapi_error_t get_netmask(SocketAddress *address); nsapi_error_t get_netmask(SocketAddress *address) override;
/** @copydoc NetworkInterface::get_gateway */ /** @copydoc NetworkInterface::get_gateway */
virtual nsapi_error_t get_gateway(SocketAddress *address); nsapi_error_t get_gateway(SocketAddress *address) override;
/** @copydoc NetworkInterface::get_interface_name */ /** @copydoc NetworkInterface::get_interface_name */
virtual char *get_interface_name(char *interface_name); char *get_interface_name(char *interface_name) override;
/** @copydoc NetworkInterface::set_as_default */ /** @copydoc NetworkInterface::set_as_default */
virtual void set_as_default(); void set_as_default() override;
/** @copydoc NetworkInterface::attach */ /** @copydoc NetworkInterface::attach */
virtual void attach(mbed::Callback<void(nsapi_event_t, intptr_t)> status_cb); void attach(mbed::Callback<void(nsapi_event_t, intptr_t)> status_cb) override;
/** @copydoc NetworkInterface::get_connection_status */ /** @copydoc NetworkInterface::get_connection_status */
virtual nsapi_connection_status_t get_connection_status() const; nsapi_connection_status_t get_connection_status() const override;
/** @copydoc NetworkInterface::set_blocking */ /** @copydoc NetworkInterface::set_blocking */
virtual nsapi_error_t set_blocking(bool blocking); nsapi_error_t set_blocking(bool blocking) override;
/** Sets file stream used to communicate with modem /** Sets file stream used to communicate with modem
* *
* @param stream Pointer to file handle * @param stream Pointer to file handle
*/ */
virtual void set_stream(mbed::FileHandle *stream); void set_stream(mbed::FileHandle *stream);
/** Sets IP protocol versions of IP stack /** Sets IP protocol versions of IP stack
* *
* @param ip_stack IP protocol version * @param ip_stack IP protocol version
*/ */
virtual void set_ip_stack(nsapi_ip_stack_t ip_stack); void set_ip_stack(nsapi_ip_stack_t ip_stack);
/** Sets user name and password for PPP protocol /** Sets user name and password for PPP protocol
* *
* @param uname User name * @param uname User name
* @param password Password * @param password Password
*/ */
virtual void set_credentials(const char *uname, const char *password); void set_credentials(const char *uname, const char *password);
/** Provide access to the PPP /** Provide access to the PPP
* *
@ -115,31 +115,36 @@ public:
return _ppp; return _ppp;
} }
virtual PPPInterface *pppInterface() #if 0
/* NetworkInterface does not currently have pppInterface, so this
* "dynamic cast" is non-functional.
*/
PPPInterface *pppInterface() final
{ {
return this; return this;
} }
#endif
protected: protected:
/** Provide access to the underlying stack /** Provide access to the underlying stack
* *
* @return The underlying network stack * @return The underlying network stack
*/ */
virtual NetworkStack *get_stack(); NetworkStack *get_stack() final;
PPP &_ppp; PPP &_ppp;
OnboardNetworkStack &_stack; OnboardNetworkStack &_stack;
OnboardNetworkStack::Interface *_interface; OnboardNetworkStack::Interface *_interface = nullptr;
bool _blocking; bool _blocking = true;
char _ip_address[NSAPI_IPv6_SIZE]; char _ip_address[NSAPI_IPv6_SIZE] {};
char _netmask[NSAPI_IPv4_SIZE]; char _netmask[NSAPI_IPv4_SIZE] {};
char _gateway[NSAPI_IPv4_SIZE]; char _gateway[NSAPI_IPv4_SIZE] {};
mbed::Callback<void(nsapi_event_t, intptr_t)> _connection_status_cb; mbed::Callback<void(nsapi_event_t, intptr_t)> _connection_status_cb;
mbed::FileHandle *_stream; mbed::FileHandle *_stream = nullptr;
nsapi_ip_stack_t _ip_stack; nsapi_ip_stack_t _ip_stack = DEFAULT_STACK;
const char *_uname; const char *_uname = nullptr;
const char *_password; const char *_password = nullptr;
}; };

View File

@ -42,7 +42,7 @@ public:
* *
* Closes socket if the socket is still open. * Closes socket if the socket is still open.
*/ */
virtual ~Socket() {} virtual ~Socket() = default;
/** Closes the socket. /** Closes the socket.
* *

View File

@ -16,17 +16,11 @@
#include "TCPServer.h" #include "TCPServer.h"
using mbed::Callback;
TCPServer::TCPServer() TCPServer::TCPServer()
{ {
_socket_stats.stats_update_proto(this, NSAPI_TCP); _socket_stats.stats_update_proto(this, NSAPI_TCP);
} }
TCPServer::~TCPServer()
{
}
nsapi_error_t TCPServer::accept(TCPSocket *connection, SocketAddress *address) nsapi_error_t TCPServer::accept(TCPSocket *connection, SocketAddress *address)
{ {
_lock.lock(); _lock.lock();
@ -51,8 +45,8 @@ nsapi_error_t TCPServer::accept(TCPSocket *connection, SocketAddress *address)
connection->_stack = _stack; connection->_stack = _stack;
connection->_socket = socket; connection->_socket = socket;
connection->_event = Callback<void()>(connection, &TCPSocket::event); connection->_event = { connection, &TCPSocket::event };
_stack->socket_attach(socket, &Callback<void()>::thunk, &connection->_event); _stack->socket_attach(socket, connection->_event.thunk, &connection->_event);
_socket_stats.stats_update_peer(connection, *address); _socket_stats.stats_update_peer(connection, *address);
_socket_stats.stats_update_socket_state(connection, SOCK_CONNECTED); _socket_stats.stats_update_socket_state(connection, SOCK_CONNECTED);
connection->_lock.unlock(); connection->_lock.unlock();

View File

@ -54,12 +54,6 @@ public:
open(stack); open(stack);
} }
/** Destroy a socket
*
* Closes socket if the socket is still open
*/
virtual ~TCPServer();
// Allow legacy TCPServer::accept() to override inherited Socket::accept() // Allow legacy TCPServer::accept() to override inherited Socket::accept()
using TCPSocket::accept; using TCPSocket::accept;

View File

@ -23,19 +23,14 @@ TCPSocket::TCPSocket()
_socket_stats.stats_update_proto(this, NSAPI_TCP); _socket_stats.stats_update_proto(this, NSAPI_TCP);
} }
TCPSocket::TCPSocket(TCPSocket *parent, nsapi_socket_t socket, SocketAddress address) TCPSocket::TCPSocket(TCPSocket *parent, nsapi_socket_t socket, SocketAddress address) : TCPSocket()
{ {
_socket = socket; _socket = socket;
_stack = parent->_stack; _stack = parent->_stack;
_factory_allocated = true; _factory_allocated = true;
_remote_peer = address; _remote_peer = address;
_socket_stats.stats_new_socket_entry(this);
_event = mbed::Callback<void()>(this, &TCPSocket::event); _event = mbed::Callback<void()>(this, &TCPSocket::event);
_stack->socket_attach(socket, &mbed::Callback<void()>::thunk, &_event); _stack->socket_attach(socket, _event.thunk, &_event);
}
TCPSocket::~TCPSocket()
{
} }
nsapi_protocol_t TCPSocket::get_proto() nsapi_protocol_t TCPSocket::get_proto()

View File

@ -51,21 +51,15 @@ public:
"The TCPSocket(S *stack) constructor is deprecated." "The TCPSocket(S *stack) constructor is deprecated."
"It discards the open() call return value." "It discards the open() call return value."
"Use another constructor and call open() explicitly, instead.") "Use another constructor and call open() explicitly, instead.")
TCPSocket(S *stack) TCPSocket(S *stack) : TCPSocket()
{ {
open(stack); open(stack);
} }
/** Destroy a socket
*
* Closes socket if the socket is still open
*/
virtual ~TCPSocket();
/** Override multicast functions to return error for TCP /** Override multicast functions to return error for TCP
* *
*/ */
virtual int join_multicast_group(const SocketAddress &address) int join_multicast_group(const SocketAddress &address)
{ {
return NSAPI_ERROR_UNSUPPORTED; return NSAPI_ERROR_UNSUPPORTED;
} }
@ -84,7 +78,7 @@ public:
* @retval int Other negative error codes for stack-related failures. * @retval int Other negative error codes for stack-related failures.
* See NetworkStack::socket_connect(). * See NetworkStack::socket_connect().
*/ */
virtual nsapi_error_t connect(const SocketAddress &address); nsapi_error_t connect(const SocketAddress &address) override;
/** Send data over a TCP socket /** Send data over a TCP socket
* *
@ -104,7 +98,7 @@ public:
* @retval int Other negative error codes for stack-related failures. * @retval int Other negative error codes for stack-related failures.
* See @ref NetworkStack::socket_send. * See @ref NetworkStack::socket_send.
*/ */
virtual nsapi_size_or_error_t send(const void *data, nsapi_size_t size); nsapi_size_or_error_t send(const void *data, nsapi_size_t size) override;
/** Receive data over a TCP socket /** Receive data over a TCP socket
* *
@ -124,7 +118,7 @@ public:
* @retval int Other negative error codes for stack-related failures. * @retval int Other negative error codes for stack-related failures.
* See @ref NetworkStack::socket_recv. * See @ref NetworkStack::socket_recv.
*/ */
virtual nsapi_size_or_error_t recv(void *data, nsapi_size_t size); nsapi_size_or_error_t recv(void *data, nsapi_size_t size) override;
/** Send data on a socket. /** Send data on a socket.
* *
@ -144,8 +138,8 @@ public:
* @retval int Other negative error codes for stack-related failures. * @retval int Other negative error codes for stack-related failures.
* See @ref NetworkStack::socket_send. * See @ref NetworkStack::socket_send.
*/ */
virtual nsapi_size_or_error_t sendto(const SocketAddress &address, nsapi_size_or_error_t sendto(const SocketAddress &address,
const void *data, nsapi_size_t size); const void *data, nsapi_size_t size) override;
/** Receive a data from a socket /** Receive a data from a socket
* *
@ -166,8 +160,8 @@ public:
* @retval int Other negative error codes for stack-related failures. * @retval int Other negative error codes for stack-related failures.
* See @ref NetworkStack::socket_recv. * See @ref NetworkStack::socket_recv.
*/ */
virtual nsapi_size_or_error_t recvfrom(SocketAddress *address, nsapi_size_or_error_t recvfrom(SocketAddress *address,
void *data, nsapi_size_t size); void *data, nsapi_size_t size) override;
/** Accepts a connection on a socket. /** Accepts a connection on a socket.
* *
@ -185,7 +179,7 @@ public:
* NSAPI_ERROR_NO_SOCKET if the socket was not open * NSAPI_ERROR_NO_SOCKET if the socket was not open
* @return pointer to a socket * @return pointer to a socket
*/ */
virtual TCPSocket *accept(nsapi_error_t *error = NULL); TCPSocket *accept(nsapi_error_t *error = NULL) override;
/** Listen for incoming connections. /** Listen for incoming connections.
* *
@ -199,11 +193,11 @@ public:
* @retval int Other negative error codes for stack-related failures. * @retval int Other negative error codes for stack-related failures.
* See @ref NetworkStack::socket_listen. * See @ref NetworkStack::socket_listen.
*/ */
virtual nsapi_error_t listen(int backlog = 1); nsapi_error_t listen(int backlog = 1) override;
protected: protected:
friend class TCPServer; friend class TCPServer;
virtual nsapi_protocol_t get_proto(); nsapi_protocol_t get_proto() override;
private: private:
/** Create a socket out of a given socket /** Create a socket out of a given socket

View File

@ -37,15 +37,6 @@ TLSSocket::~TLSSocket()
#else // MBED_CONF_NSAPI_OFFLOAD_TLSSOCKET #else // MBED_CONF_NSAPI_OFFLOAD_TLSSOCKET
TLSSocket::TLSSocket()
{
}
TLSSocket::~TLSSocket()
{
}
nsapi_error_t TLSSocket::set_hostname(const char *hostname) nsapi_error_t TLSSocket::set_hostname(const char *hostname)
{ {
return setsockopt(NSAPI_TLSSOCKET_LEVEL, NSAPI_TLSSOCKET_SET_HOSTNAME, hostname, strlen(hostname)); return setsockopt(NSAPI_TLSSOCKET_LEVEL, NSAPI_TLSSOCKET_SET_HOSTNAME, hostname, strlen(hostname));

View File

@ -54,7 +54,7 @@ public:
/** Destroy the TLSSocket and closes the transport. /** Destroy the TLSSocket and closes the transport.
*/ */
virtual ~TLSSocket(); ~TLSSocket() override;
/** Opens a socket. /** Opens a socket.
* *
@ -67,7 +67,7 @@ public:
* @param stack Network stack as target for socket. * @param stack Network stack as target for socket.
* @return NSAPI_ERROR_OK on success. See @ref TCPSocket::open * @return NSAPI_ERROR_OK on success. See @ref TCPSocket::open
*/ */
virtual nsapi_error_t open(NetworkStack *stack) nsapi_error_t open(NetworkStack *stack)
{ {
return tcp_socket.open(stack); return tcp_socket.open(stack);
} }
@ -89,8 +89,7 @@ private:
class TLSSocket : public TCPSocket { class TLSSocket : public TCPSocket {
public: public:
TLSSocket(); TLSSocket() = default;
virtual ~TLSSocket();
/** Set hostname. /** Set hostname.
* *
@ -110,7 +109,7 @@ public:
* @param len Length of certificate (including terminating 0 for PEM). * @param len Length of certificate (including terminating 0 for PEM).
* @return NSAPI_ERROR_OK on success, negative error code on failure. * @return NSAPI_ERROR_OK on success, negative error code on failure.
*/ */
virtual nsapi_error_t set_root_ca_cert(const void *root_ca, size_t len); nsapi_error_t set_root_ca_cert(const void *root_ca, size_t len);
/** Sets the certification of Root CA. /** Sets the certification of Root CA.
* *
@ -118,7 +117,7 @@ public:
* *
* @param root_ca_pem Root CA Certificate in PEM format. * @param root_ca_pem Root CA Certificate in PEM format.
*/ */
virtual nsapi_error_t set_root_ca_cert(const char *root_ca_pem); nsapi_error_t set_root_ca_cert(const char *root_ca_pem);
/** Sets client certificate, and client private key. /** Sets client certificate, and client private key.
@ -129,7 +128,7 @@ public:
* @param client_private_key_len Key size including the terminating null byte for PEM data * @param client_private_key_len Key size including the terminating null byte for PEM data
* @return NSAPI_ERROR_OK on success, negative error code on failure. * @return NSAPI_ERROR_OK on success, negative error code on failure.
*/ */
virtual nsapi_error_t set_client_cert_key(const void *client_cert, size_t client_cert_len, nsapi_error_t set_client_cert_key(const void *client_cert, size_t client_cert_len,
const void *client_private_key_pem, size_t client_private_key_len); const void *client_private_key_pem, size_t client_private_key_len);
/** Sets client certificate, and client private key. /** Sets client certificate, and client private key.
@ -138,14 +137,14 @@ public:
* @param client_private_key_pem Client private key in PEM format. * @param client_private_key_pem Client private key in PEM format.
* @return NSAPI_ERROR_OK on success, negative error code on failure. * @return NSAPI_ERROR_OK on success, negative error code on failure.
*/ */
virtual nsapi_error_t set_client_cert_key(const char *client_cert_pem, const char *client_private_key_pem); nsapi_error_t set_client_cert_key(const char *client_cert_pem, const char *client_private_key_pem);
// From TCPSocket // From TCPSocket
virtual nsapi_error_t connect(const char *host, uint16_t port); nsapi_error_t connect(const char *host, uint16_t port) override;
virtual nsapi_error_t connect(const SocketAddress &address); nsapi_error_t connect(const SocketAddress &address) override;
protected: protected:
virtual nsapi_error_t enable_tlssocket(); nsapi_error_t enable_tlssocket();
}; };
#endif // MBED_CONF_NSAPI_OFFLOAD_TLSSOCKET #endif // MBED_CONF_NSAPI_OFFLOAD_TLSSOCKET

View File

@ -32,12 +32,6 @@
TLSSocketWrapper::TLSSocketWrapper(Socket *transport, const char *hostname, control_transport control) : TLSSocketWrapper::TLSSocketWrapper(Socket *transport, const char *hostname, control_transport control) :
_transport(transport), _transport(transport),
_timeout(-1),
#ifdef MBEDTLS_X509_CRT_PARSE_C
_cacert(NULL),
_clicert(NULL),
#endif
_ssl_conf(NULL),
_connect_transport(control == TRANSPORT_CONNECT || control == TRANSPORT_CONNECT_AND_CLOSE), _connect_transport(control == TRANSPORT_CONNECT || control == TRANSPORT_CONNECT_AND_CLOSE),
_close_transport(control == TRANSPORT_CLOSE || control == TRANSPORT_CONNECT_AND_CLOSE), _close_transport(control == TRANSPORT_CLOSE || control == TRANSPORT_CONNECT_AND_CLOSE),
_tls_initialized(false), _tls_initialized(false),
@ -47,7 +41,7 @@ TLSSocketWrapper::TLSSocketWrapper(Socket *transport, const char *hostname, cont
_ssl_conf_allocated(false) _ssl_conf_allocated(false)
{ {
#if defined(MBEDTLS_PLATFORM_C) #if defined(MBEDTLS_PLATFORM_C)
int ret = mbedtls_platform_setup(NULL); int ret = mbedtls_platform_setup(nullptr);
if (ret != 0) { if (ret != 0) {
print_mbedtls_error("mbedtls_platform_setup()", ret); print_mbedtls_error("mbedtls_platform_setup()", ret);
} }
@ -74,12 +68,12 @@ TLSSocketWrapper::~TLSSocketWrapper()
mbedtls_ssl_free(&_ssl); mbedtls_ssl_free(&_ssl);
#if defined(MBEDTLS_X509_CRT_PARSE_C) #if defined(MBEDTLS_X509_CRT_PARSE_C)
mbedtls_pk_free(&_pkctx); mbedtls_pk_free(&_pkctx);
set_own_cert(NULL); set_own_cert(nullptr);
set_ca_chain(NULL); set_ca_chain(nullptr);
#endif #endif
set_ssl_config(NULL); set_ssl_config(nullptr);
#if defined(MBEDTLS_PLATFORM_C) #if defined(MBEDTLS_PLATFORM_C)
mbedtls_platform_teardown(NULL); mbedtls_platform_teardown(nullptr);
#endif /* MBEDTLS_PLATFORM_C */ #endif /* MBEDTLS_PLATFORM_C */
} }
@ -148,7 +142,7 @@ nsapi_error_t TLSSocketWrapper::set_client_cert_key(const void *client_cert, siz
} }
mbedtls_pk_init(&_pkctx); mbedtls_pk_init(&_pkctx);
if ((ret = mbedtls_pk_parse_key(&_pkctx, static_cast<const unsigned char *>(client_private_key_pem), if ((ret = mbedtls_pk_parse_key(&_pkctx, static_cast<const unsigned char *>(client_private_key_pem),
client_private_key_len, NULL, 0)) != 0) { client_private_key_len, nullptr, 0)) != 0) {
print_mbedtls_error("mbedtls_pk_parse_key", ret); print_mbedtls_error("mbedtls_pk_parse_key", ret);
mbedtls_x509_crt_free(crt); mbedtls_x509_crt_free(crt);
delete crt; delete crt;
@ -194,8 +188,8 @@ nsapi_error_t TLSSocketWrapper::start_handshake(bool first_call)
#if MBED_CONF_TLS_SOCKET_DEBUG_LEVEL > 0 #if MBED_CONF_TLS_SOCKET_DEBUG_LEVEL > 0
mbedtls_ssl_conf_verify(get_ssl_config(), my_verify, NULL); mbedtls_ssl_conf_verify(get_ssl_config(), my_verify, nullptr);
mbedtls_ssl_conf_dbg(get_ssl_config(), my_debug, NULL); mbedtls_ssl_conf_dbg(get_ssl_config(), my_debug, nullptr);
mbedtls_debug_set_threshold(MBED_CONF_TLS_SOCKET_DEBUG_LEVEL); mbedtls_debug_set_threshold(MBED_CONF_TLS_SOCKET_DEBUG_LEVEL);
#endif #endif
@ -207,7 +201,7 @@ nsapi_error_t TLSSocketWrapper::start_handshake(bool first_call)
_transport->set_blocking(false); _transport->set_blocking(false);
_transport->sigio(mbed::callback(this, &TLSSocketWrapper::event)); _transport->sigio(mbed::callback(this, &TLSSocketWrapper::event));
mbedtls_ssl_set_bio(&_ssl, this, ssl_send, ssl_recv, NULL); mbedtls_ssl_set_bio(&_ssl, this, ssl_send, ssl_recv, nullptr);
_tls_initialized = true; _tls_initialized = true;
@ -541,7 +535,7 @@ void TLSSocketWrapper::set_ca_chain(mbedtls_x509_crt *crt)
} }
_cacert = crt; _cacert = crt;
tr_debug("mbedtls_ssl_conf_ca_chain()"); tr_debug("mbedtls_ssl_conf_ca_chain()");
mbedtls_ssl_conf_ca_chain(get_ssl_config(), _cacert, NULL); mbedtls_ssl_conf_ca_chain(get_ssl_config(), _cacert, nullptr);
} }
#endif /* MBEDTLS_X509_CRT_PARSE_C */ #endif /* MBEDTLS_X509_CRT_PARSE_C */
@ -559,9 +553,9 @@ mbedtls_ssl_config *TLSSocketWrapper::get_ssl_config()
MBEDTLS_SSL_TRANSPORT_STREAM, MBEDTLS_SSL_TRANSPORT_STREAM,
MBEDTLS_SSL_PRESET_DEFAULT)) != 0) { MBEDTLS_SSL_PRESET_DEFAULT)) != 0) {
print_mbedtls_error("mbedtls_ssl_config_defaults", ret); print_mbedtls_error("mbedtls_ssl_config_defaults", ret);
set_ssl_config(NULL); set_ssl_config(nullptr);
MBED_ERROR(MBED_MAKE_ERROR(MBED_MODULE_NETWORK_STACK, MBED_ERROR_CODE_OUT_OF_MEMORY), "mbedtls_ssl_config_defaults() failed"); MBED_ERROR(MBED_MAKE_ERROR(MBED_MODULE_NETWORK_STACK, MBED_ERROR_CODE_OUT_OF_MEMORY), "mbedtls_ssl_config_defaults() failed");
return NULL; return nullptr;
} }
/* It is possible to disable authentication by passing /* It is possible to disable authentication by passing
* MBEDTLS_SSL_VERIFY_NONE in the call to mbedtls_ssl_conf_authmode() * MBEDTLS_SSL_VERIFY_NONE in the call to mbedtls_ssl_conf_authmode()
@ -611,7 +605,7 @@ nsapi_error_t TLSSocketWrapper::close()
} }
} }
_transport = NULL; _transport = nullptr;
return ret; return ret;
} }
@ -685,7 +679,7 @@ Socket *TLSSocketWrapper::accept(nsapi_error_t *err)
if (err) { if (err) {
*err = NSAPI_ERROR_UNSUPPORTED; *err = NSAPI_ERROR_UNSUPPORTED;
} }
return NULL; return nullptr;
} }
nsapi_error_t TLSSocketWrapper::listen(int) nsapi_error_t TLSSocketWrapper::listen(int)

View File

@ -63,7 +63,7 @@ public:
* *
* Closes socket wrapper if the socket wrapper is still open. * Closes socket wrapper if the socket wrapper is still open.
*/ */
virtual ~TLSSocketWrapper(); ~TLSSocketWrapper() override;
/** Set hostname. /** Set hostname.
* *
@ -133,7 +133,7 @@ public:
* @retval NSAPI_ERROR_DEVICE_ERROR in case of tls-related errors. * @retval NSAPI_ERROR_DEVICE_ERROR in case of tls-related errors.
* See @ref mbedtls_ssl_write. * See @ref mbedtls_ssl_write.
*/ */
virtual nsapi_error_t send(const void *data, nsapi_size_t size); nsapi_error_t send(const void *data, nsapi_size_t size) override;
/** Receive data over a TLS socket. /** Receive data over a TLS socket.
* *
@ -151,10 +151,10 @@ public:
* @return 0 if no data is available to be received * @return 0 if no data is available to be received
* and the peer has performed an orderly shutdown. * and the peer has performed an orderly shutdown.
*/ */
virtual nsapi_size_or_error_t recv(void *data, nsapi_size_t size); nsapi_size_or_error_t recv(void *data, nsapi_size_t size) override;
/* = Functions inherited from Socket = */ /* = Functions inherited from Socket = */
virtual nsapi_error_t close(); nsapi_error_t close() override;
/** /**
* Connect the transport socket and start handshake. * Connect the transport socket and start handshake.
* *
@ -163,19 +163,19 @@ public:
* *
* See @ref Socket::connect and @ref start_handshake * See @ref Socket::connect and @ref start_handshake
*/ */
virtual nsapi_error_t connect(const SocketAddress &address = SocketAddress()); nsapi_error_t connect(const SocketAddress &address = SocketAddress()) override;
virtual nsapi_size_or_error_t sendto(const SocketAddress &address, const void *data, nsapi_size_t size); nsapi_size_or_error_t sendto(const SocketAddress &address, const void *data, nsapi_size_t size) override;
virtual nsapi_size_or_error_t recvfrom(SocketAddress *address, nsapi_size_or_error_t recvfrom(SocketAddress *address,
void *data, nsapi_size_t size); void *data, nsapi_size_t size) override;
virtual nsapi_error_t bind(const SocketAddress &address); nsapi_error_t bind(const SocketAddress &address) override;
virtual void set_blocking(bool blocking); void set_blocking(bool blocking) override;
virtual void set_timeout(int timeout); void set_timeout(int timeout) override;
virtual void sigio(mbed::Callback<void()> func); void sigio(mbed::Callback<void()> func) override;
virtual nsapi_error_t setsockopt(int level, int optname, const void *optval, unsigned optlen); nsapi_error_t setsockopt(int level, int optname, const void *optval, unsigned optlen) override;
virtual nsapi_error_t getsockopt(int level, int optname, void *optval, unsigned *optlen); nsapi_error_t getsockopt(int level, int optname, void *optval, unsigned *optlen) override;
virtual Socket *accept(nsapi_error_t *error = NULL); Socket *accept(nsapi_error_t *error = NULL) override;
virtual nsapi_error_t listen(int backlog = 1); nsapi_error_t listen(int backlog = 1) override;
virtual nsapi_error_t getpeername(SocketAddress *address); nsapi_error_t getpeername(SocketAddress *address) override;
#if defined(MBEDTLS_X509_CRT_PARSE_C) || defined(DOXYGEN_ONLY) #if defined(MBEDTLS_X509_CRT_PARSE_C) || defined(DOXYGEN_ONLY)
/** Get own certificate directly from Mbed TLS. /** Get own certificate directly from Mbed TLS.
@ -296,13 +296,13 @@ private:
rtos::EventFlags _event_flag; rtos::EventFlags _event_flag;
mbed::Callback<void()> _sigio; mbed::Callback<void()> _sigio;
Socket *_transport; Socket *_transport;
int _timeout; int _timeout = -1;
#ifdef MBEDTLS_X509_CRT_PARSE_C #ifdef MBEDTLS_X509_CRT_PARSE_C
mbedtls_x509_crt *_cacert; mbedtls_x509_crt *_cacert = nullptr;
mbedtls_x509_crt *_clicert; mbedtls_x509_crt *_clicert = nullptr;
#endif #endif
mbedtls_ssl_config *_ssl_conf; mbedtls_ssl_config *_ssl_conf = nullptr;
bool _connect_transport: 1; bool _connect_transport: 1;
bool _close_transport: 1; bool _close_transport: 1;

View File

@ -50,7 +50,7 @@ public:
"The UDPSocket(S *stack) constructor is deprecated" "The UDPSocket(S *stack) constructor is deprecated"
"It discards the open() call return value." "It discards the open() call return value."
"Use another constructor and call open() explicitly, instead.") "Use another constructor and call open() explicitly, instead.")
UDPSocket(S *stack) UDPSocket(S *stack) : UDPSocket()
{ {
open(stack); open(stack);
} }
@ -58,7 +58,7 @@ public:
#if !defined(DOXYGEN_ONLY) #if !defined(DOXYGEN_ONLY)
protected: protected:
virtual nsapi_protocol_t get_proto(); nsapi_protocol_t get_proto() override;
#endif //!defined(DOXYGEN_ONLY) #endif //!defined(DOXYGEN_ONLY)

View File

@ -1,9 +1,6 @@
#include "netsocket/WiFiAccessPoint.h" #include "netsocket/WiFiAccessPoint.h"
WiFiAccessPoint::WiFiAccessPoint() WiFiAccessPoint::WiFiAccessPoint() = default;
{
memset(&_ap, 0, sizeof(_ap));
}
WiFiAccessPoint::WiFiAccessPoint(nsapi_wifi_ap_t ap) WiFiAccessPoint::WiFiAccessPoint(nsapi_wifi_ap_t ap)
{ {

View File

@ -64,7 +64,7 @@ public:
uint8_t get_channel() const; uint8_t get_channel() const;
private: private:
nsapi_wifi_ap_t _ap; nsapi_wifi_ap_t _ap {};
}; };
#endif #endif

View File

@ -81,13 +81,13 @@ public:
* *
* @return NSAPI_ERROR_OK on success, negative error code on failure. * @return NSAPI_ERROR_OK on success, negative error code on failure.
*/ */
virtual nsapi_error_t connect() = 0; nsapi_error_t connect() override = 0;
/** Stop the interface. /** Stop the interface.
* *
* @return NSAPI_ERROR_OK on success, or error code on failure. * @return NSAPI_ERROR_OK on success, or error code on failure.
*/ */
virtual nsapi_error_t disconnect() = 0; nsapi_error_t disconnect() override = 0;
/** Scan for available networks. /** Scan for available networks.
* *
@ -106,7 +106,7 @@ public:
/** @copydoc NetworkInterface::wifiInterface /** @copydoc NetworkInterface::wifiInterface
*/ */
virtual WiFiInterface *wifiInterface() WiFiInterface *wifiInterface() final
{ {
return this; return this;
} }
@ -134,7 +134,7 @@ public:
* NetworkInterface::get_default_instance() (see nsapi JSON * NetworkInterface::get_default_instance() (see nsapi JSON
* configuration). * configuration).
*/ */
virtual void set_default_parameters(); void set_default_parameters() override;
}; };
#endif #endif

View File

@ -75,16 +75,16 @@ bool ppp_service::prepare_event_queue()
return true; return true;
#else #else
static events::EventQueue *event_queue = NULL; static events::EventQueue *event_queue = nullptr;
static rtos::Thread *event_thread = NULL; static rtos::Thread *event_thread = nullptr;
// Already prepared // Already prepared
if (event_queue && event_thread) { if (event_queue && event_thread) {
return true; return true;
} }
// Used for incoming data, timers, link status callback, power up callback // Used for incoming data, timers, link status callback, power up callback
event_queue = new events::EventQueue(10 * EVENTS_EVENT_SIZE, NULL); event_queue = new events::EventQueue(10 * EVENTS_EVENT_SIZE, nullptr);
event_thread = new rtos::Thread(osPriorityNormal, PPP_THREAD_STACKSIZE, NULL, "ppp"); event_thread = new rtos::Thread(osPriorityNormal, PPP_THREAD_STACKSIZE, nullptr, "ppp");
if (event_thread->start(callback(event_queue, &events::EventQueue::dispatch_forever)) != osOK) { if (event_thread->start(callback(event_queue, &events::EventQueue::dispatch_forever)) != osOK) {
delete event_thread; delete event_thread;
@ -179,7 +179,7 @@ void ppp_service::ppp_input()
ppp_trace_to_ascii_hex_dump(INPUT_BUFFER, len, reinterpret_cast<char *>(buffer)); ppp_trace_to_ascii_hex_dump(INPUT_BUFFER, len, reinterpret_cast<char *>(buffer));
#endif #endif
pppos_input(static_cast<ppp_pcb *>(ppp_service_pcb), buffer, len); pppos_input(ppp_service_pcb, buffer, len);
} }
} }
@ -195,10 +195,8 @@ void ppp_service::ppp_stream_sigio_callback()
void ppp_service::ppp_handle_modem_hangup() void ppp_service::ppp_handle_modem_hangup()
{ {
ppp_pcb *pcb = static_cast<ppp_pcb *>(ppp_service_pcb); if (ppp_service_pcb->phase != PPP_PHASE_DEAD) {
ppp_close(ppp_service_pcb, 1);
if (pcb->phase != PPP_PHASE_DEAD) {
ppp_close(pcb, 1);
} }
} }
@ -303,15 +301,15 @@ nsapi_error_t ppp_service::ppp_stack_if_init()
ppp_init(); ppp_init();
if (!ppp_service_pcb) { if (!ppp_service_pcb) {
ppp_service_pcb = pppos_create(static_cast<netif *>(ppp_service_netif), ppp_service_pcb = pppos_create(ppp_service_netif,
ppp_output, ppp_link_status, NULL); ppp_output, ppp_link_status, nullptr);
if (!ppp_service_pcb) { if (!ppp_service_pcb) {
return NSAPI_ERROR_DEVICE_ERROR; return NSAPI_ERROR_DEVICE_ERROR;
} }
} }
#if PPP_IPV4_SUPPORT #if PPP_IPV4_SUPPORT
ppp_pcb *pcb = static_cast<ppp_pcb *>(ppp_service_pcb); ppp_pcb *pcb = ppp_service_pcb;
#if PPP_IPV6_SUPPORT #if PPP_IPV6_SUPPORT
if (ppp_service_stack != IPV6_STACK) { if (ppp_service_stack != IPV6_STACK) {
@ -334,7 +332,7 @@ nsapi_error_t ppp_service::ppp_stack_if_init()
nsapi_error_t ppp_service::ppp_if_connect() nsapi_error_t ppp_service::ppp_if_connect()
{ {
ppp_pcb *pcb = static_cast<ppp_pcb *>(ppp_service_pcb); ppp_pcb *pcb = ppp_service_pcb;
#if PPP_AUTH_SUPPORT #if PPP_AUTH_SUPPORT
ppp_set_auth(pcb, PPPAUTHTYPE_ANY, ppp_service_uname, ppp_service_password); ppp_set_auth(pcb, PPPAUTHTYPE_ANY, ppp_service_uname, ppp_service_password);
@ -354,12 +352,10 @@ nsapi_error_t ppp_service::ppp_if_connect()
nsapi_error_t ppp_service::ppp_if_disconnect() nsapi_error_t ppp_service::ppp_if_disconnect()
{ {
ppp_pcb *pcb = static_cast<ppp_pcb *>(ppp_service_pcb);
err_t ret = ERR_OK; err_t ret = ERR_OK;
if (ppp_service_active) { if (ppp_service_active) {
ppp_service_terminating = true; ppp_service_terminating = true;
ret = ppp_close(pcb, 0); ret = ppp_close(ppp_service_pcb, 0);
if (ret == ERR_OK) { if (ret == ERR_OK) {
/* close call made, now let's catch the response in the status callback */ /* close call made, now let's catch the response in the status callback */
ppp_service_close_sem.try_acquire_for(PPP_TERMINATION_TIMEOUT); ppp_service_close_sem.try_acquire_for(PPP_TERMINATION_TIMEOUT);
@ -371,20 +367,10 @@ nsapi_error_t ppp_service::ppp_if_disconnect()
ppp_service::ppp_service() ppp_service::ppp_service()
{ {
ppp_service_stream = NULL; ppp_service_netif = new (std::nothrow) netif{};
ppp_service_event_queue = NULL;
ppp_service_netif = static_cast<netif *>(malloc(sizeof(netif)));
if (ppp_service_netif) { if (ppp_service_netif) {
memset(ppp_service_netif, 0, sizeof(netif)); ppp_service_netif->service_ptr = this;
ppp_service_netif->service_ptr = static_cast<void *>(this);
} }
ppp_service_pcb = NULL;
ppp_service_stack = IPV4_STACK;
ppp_service_uname = NULL;
ppp_service_password = NULL;
memory_manager = NULL;
ppp_service_active = false; ppp_service_active = false;
ppp_service_event_queued = false; ppp_service_event_queued = false;
ppp_service_terminating = false; ppp_service_terminating = false;
@ -393,14 +379,12 @@ ppp_service::ppp_service()
bool ppp_service::link_out(net_stack_mem_buf_t *buf, nsapi_ip_stack_t ip_stack) bool ppp_service::link_out(net_stack_mem_buf_t *buf, nsapi_ip_stack_t ip_stack)
{ {
netif *serv_netif = static_cast<netif *>(ppp_service_netif);
if (ppp_service_terminating) { if (ppp_service_terminating) {
memory_manager->free(buf); memory_manager->free(buf);
return true; return true;
} }
struct pbuf *p = static_cast<struct pbuf *>(ppp_memory_buffer_convert_to(memory_manager, buf)); struct pbuf *p = ppp_memory_buffer_convert_to(memory_manager, buf);
if (!p) { if (!p) {
memory_manager->free(buf); memory_manager->free(buf);
return true; return true;
@ -408,14 +392,14 @@ bool ppp_service::link_out(net_stack_mem_buf_t *buf, nsapi_ip_stack_t ip_stack)
#if PPP_IPV4_SUPPORT && PPP_IPV6_SUPPORT #if PPP_IPV4_SUPPORT && PPP_IPV6_SUPPORT
if (ip_stack == IPV4_STACK) { if (ip_stack == IPV4_STACK) {
serv_netif->output(serv_netif, p, NULL); ppp_service_netif->output(ppp_service_netif, p, nullptr);
} else { } else {
serv_netif->output_ip6(serv_netif, p, NULL); ppp_service_netif->output_ip6(ppp_service_netif, p, nullptr);
} }
#elif PPP_IPV4_SUPPORT #elif PPP_IPV4_SUPPORT
serv_netif->output(serv_netif, p, NULL); ppp_service_netif->output(ppp_service_netif, p, nullptr);
#elif PPP_IPV6_SUPPORT #elif PPP_IPV6_SUPPORT
serv_netif->output_ip6(serv_netif, p, NULL); ppp_service_netif->output_ip6(ppp_service_netif, p, nullptr);
#endif #endif
ppp_memory_buffer_free(p); // Not done on PPP lower layers ppp_memory_buffer_free(p); // Not done on PPP lower layers
@ -460,8 +444,7 @@ uint32_t ppp_service::get_mtu_size()
return 0; return 0;
} }
netif *serv_netif = static_cast<netif *>(ppp_service_netif); return ppp_service_netif->mtu;
return serv_netif->mtu;
} }
uint32_t ppp_service::get_align_preference() const uint32_t ppp_service::get_align_preference() const
@ -518,34 +501,30 @@ void ppp_service::set_credentials(const char *uname, const char *password)
if (strlen(uname) > 0) { if (strlen(uname) > 0) {
ppp_service_uname = uname; ppp_service_uname = uname;
} else { } else {
ppp_service_uname = NULL; ppp_service_uname = nullptr;
} }
if (strlen(password) > 0) { if (strlen(password) > 0) {
ppp_service_password = password; ppp_service_password = password;
} else { } else {
password = NULL; password = nullptr;
} }
} }
const nsapi_addr_t *ppp_service::get_ip_address(nsapi_version_t version) const nsapi_addr_t *ppp_service::get_ip_address(nsapi_version_t version)
{ {
#if PPP_IPV6_SUPPORT || PPP_IPV4_SUPPORT
netif *serv_netif = static_cast<netif *>(ppp_service_netif);
#endif
#if PPP_IPV6_SUPPORT #if PPP_IPV6_SUPPORT
if (version == NSAPI_IPv6 && serv_netif->ipv6_addr.version == NSAPI_IPv6) { if (version == NSAPI_IPv6 && ppp_service_netif->ipv6_addr.version == NSAPI_IPv6) {
return &serv_netif->ipv6_addr; return &ppp_service_netif->ipv6_addr;
} }
#endif #endif
#if PPP_IPV4_SUPPORT #if PPP_IPV4_SUPPORT
if (version == NSAPI_IPv4 && serv_netif->ipv4_addr.version == NSAPI_IPv4) { if (version == NSAPI_IPv4 && ppp_service_netif->ipv4_addr.version == NSAPI_IPv4) {
return &serv_netif->ipv4_addr; return &ppp_service_netif->ipv4_addr;
} }
#endif #endif
return NULL; return nullptr;
} }
const nsapi_addr_t *ppp_service::get_netmask() const nsapi_addr_t *ppp_service::get_netmask()
@ -556,7 +535,7 @@ const nsapi_addr_t *ppp_service::get_netmask()
} }
#endif #endif
return NULL; return nullptr;
} }
const nsapi_addr_t *ppp_service::get_gateway() const nsapi_addr_t *ppp_service::get_gateway()
@ -567,21 +546,21 @@ const nsapi_addr_t *ppp_service::get_gateway()
} }
#endif #endif
return NULL; return nullptr;
} }
const nsapi_addr_t *ppp_service::get_dns_server(uint8_t index) const nsapi_addr_t *ppp_service::get_dns_server(uint8_t index)
{ {
#if PPP_IPV4_SUPPORT #if PPP_IPV4_SUPPORT
if (index > 1) { if (index > 1) {
return NULL; return nullptr;
} }
if (ppp_service_netif->ipv4_dns_server[index].version == NSAPI_IPv4) { if (ppp_service_netif->ipv4_dns_server[index].version == NSAPI_IPv4) {
return &ppp_service_netif->ipv4_dns_server[index]; return &ppp_service_netif->ipv4_dns_server[index];
} }
#endif #endif
return NULL; return nullptr;
} }
void ppp_service::link_state(bool up) void ppp_service::link_state(bool up)

View File

@ -26,12 +26,15 @@
#include "events/EventQueue.h" #include "events/EventQueue.h"
#include "netsocket/PPP.h" #include "netsocket/PPP.h"
struct netif;
struct ppp_pcb_s;
/** /**
* This interface should be used to abstract low level access to networking hardware * This interface should be used to abstract low level access to networking hardware
* All operations receive a `void *` hardware pointer which an ppp device provides when * All operations receive a `void *` hardware pointer which an ppp device provides when
* it is registered with a stack. * it is registered with a stack.
*/ */
class ppp_service : public PPP { class ppp_service final : public PPP {
public: public:
ppp_service(); ppp_service();
@ -58,7 +61,7 @@ public:
* *
* @return MTU in bytes * @return MTU in bytes
*/ */
virtual uint32_t get_mtu_size(); uint32_t get_mtu_size() override;
/** /**
* Gets memory buffer alignment preference * Gets memory buffer alignment preference
@ -66,7 +69,7 @@ public:
* Gets preferred memory buffer alignment of the ppp device. * Gets preferred memory buffer alignment of the ppp device.
* @return Memory alignment requirement in bytes * @return Memory alignment requirement in bytes
*/ */
virtual uint32_t get_align_preference() const; uint32_t get_align_preference() const override;
/** /**
* Return interface name * Return interface name
@ -74,7 +77,7 @@ public:
* @param name Pointer to where the name should be written * @param name Pointer to where the name should be written
* @param size Maximum number of characters to copy * @param size Maximum number of characters to copy
*/ */
virtual void get_ifname(char *name, uint8_t size) const; void get_ifname(char *name, uint8_t size) const override;
/** /**
* Sends the packet over the link * Sends the packet over the link
@ -84,111 +87,111 @@ public:
* @param buf Packet to be send * @param buf Packet to be send
* @return True if the packet was send successfully, false otherwise * @return True if the packet was send successfully, false otherwise
*/ */
virtual bool link_out(net_stack_mem_buf_t *buf, nsapi_ip_stack_t ip_stack); bool link_out(net_stack_mem_buf_t *buf, nsapi_ip_stack_t ip_stack) override;
/** /**
* Initializes the hardware * Initializes the hardware
* *
* @return True on success, False in case of an error. * @return True on success, False in case of an error.
*/ */
virtual bool power_up(); bool power_up() override;
/** /**
* Deinitializes the hardware * Deinitializes the hardware
* *
*/ */
virtual void power_down(); void power_down() override;
/** /**
* Sets a callback that needs to be called for packets received for that interface * Sets a callback that needs to be called for packets received for that interface
* *
* @param input_cb Function to be register as a callback * @param input_cb Function to be register as a callback
*/ */
virtual void set_link_input_cb(ppp_link_input_cb_t input_cb); void set_link_input_cb(ppp_link_input_cb_t input_cb) override;
/** /**
* Sets a callback that needs to be called on link status changes for given interface * Sets a callback that needs to be called on link status changes for given interface
* *
* @param state_cb Function to be register as a callback * @param state_cb Function to be register as a callback
*/ */
virtual void set_link_state_cb(ppp_link_state_change_cb_t state_cb); void set_link_state_cb(ppp_link_state_change_cb_t state_cb) override;
/** Sets memory manager that is used to handle memory buffers /** Sets memory manager that is used to handle memory buffers
* *
* @param mem_mngr Pointer to memory manager * @param mem_mngr Pointer to memory manager
*/ */
virtual void set_memory_manager(NetStackMemoryManager &mem_mngr); void set_memory_manager(NetStackMemoryManager &mem_mngr) override;
/** Sets file stream used to communicate with modem /** Sets file stream used to communicate with modem
* *
* @param stream Pointer to file handle * @param stream Pointer to file handle
*/ */
virtual void set_stream(mbed::FileHandle *stream); void set_stream(mbed::FileHandle *stream) override;
/** Sets IP protocol versions of IP stack /** Sets IP protocol versions of IP stack
* *
* @param ip_stack IP protocol version * @param ip_stack IP protocol version
*/ */
virtual void set_ip_stack(nsapi_ip_stack_t ip_stack); void set_ip_stack(nsapi_ip_stack_t ip_stack) override;
/** Sets user name and password for PPP protocol /** Sets user name and password for PPP protocol
* *
* @param uname User name * @param uname User name
* @param password Password * @param password Password
*/ */
virtual void set_credentials(const char *uname, const char *password); void set_credentials(const char *uname, const char *password);
/** Gets local IP address /** Gets local IP address
* *
* @param version IP address version * @param version IP address version
* @return IP address * @return IP address
*/ */
virtual const nsapi_addr_t *get_ip_address(nsapi_version_t version); const nsapi_addr_t *get_ip_address(nsapi_version_t version) override;
/** Get the local network mask. /** Get the local network mask.
* *
* @return Local network mask or null if no network mask has been received. * @return Local network mask or null if no network mask has been received.
*/ */
virtual const nsapi_addr_t *get_netmask(); const nsapi_addr_t *get_netmask() override;
/** Get the local gateway. /** Get the local gateway.
* *
* @return Local gateway or null if no network mask has been received. * @return Local gateway or null if no network mask has been received.
*/ */
virtual const nsapi_addr_t *get_gateway(); const nsapi_addr_t *get_gateway() override;
/** Gets DNS server address /** Gets DNS server address
* *
* @param index Server index * @param index Server index
*/ */
virtual const nsapi_addr_t *get_dns_server(uint8_t index); const nsapi_addr_t *get_dns_server(uint8_t index) override;
/** Link state indication from PPP /** Link state indication from PPP
* *
* @param up Link status * @param up Link status
*/ */
virtual void link_state(bool up); void link_state(bool up);
/** Received IP packet from PPP to stack /** Received IP packet from PPP to stack
* *
* @param buf Received packet * @param buf Received packet
*/ */
virtual void link_input(net_stack_mem_buf_t *buf); void link_input(net_stack_mem_buf_t *buf);
/** Handle to PPP event queue /** Handle to PPP event queue
* *
* @return Event queue * @return Event queue
*/ */
virtual events::EventQueue *event_queue_get(); events::EventQueue *event_queue_get();
/** Lock PPP resource /** Lock PPP resource
* *
*/ */
virtual void resource_lock(); void resource_lock();
/** Unlock PPP resource /** Unlock PPP resource
* *
*/ */
virtual void resource_unlock(); void resource_unlock();
private: private:
@ -207,19 +210,19 @@ private:
nsapi_error_t ppp_if_disconnect(); nsapi_error_t ppp_if_disconnect();
// Internal data // Internal data
mbed::FileHandle *ppp_service_stream; mbed::FileHandle *ppp_service_stream = nullptr;
rtos::Semaphore ppp_service_close_sem; rtos::Semaphore ppp_service_close_sem;
rtos::Mutex ppp_service_mutex; rtos::Mutex ppp_service_mutex;
events::EventQueue *ppp_service_event_queue; events::EventQueue *ppp_service_event_queue = nullptr;
NetStackMemoryManager *memory_manager; /**< Memory manager */ NetStackMemoryManager *memory_manager = nullptr; /**< Memory manager */
ppp_link_input_cb_t ppp_link_input_cb; /**< Callback for incoming data */ ppp_link_input_cb_t ppp_link_input_cb; /**< Callback for incoming data */
ppp_link_state_change_cb_t ppp_link_state_cb; /**< Link state change callback */ ppp_link_state_change_cb_t ppp_link_state_cb; /**< Link state change callback */
struct netif *ppp_service_netif; netif *ppp_service_netif;
void *ppp_service_pcb; ppp_pcb_s *ppp_service_pcb = nullptr;
nsapi_ip_stack_t ppp_service_stack; nsapi_ip_stack_t ppp_service_stack = IPV4_STACK;
const char *ppp_service_uname; const char *ppp_service_uname = nullptr;
const char *ppp_service_password; const char *ppp_service_password = nullptr;
nsapi_error_t ppp_service_connect_error_code; nsapi_error_t ppp_service_connect_error_code;
bool ppp_service_active : 1; bool ppp_service_active : 1;
bool ppp_service_event_queued : 1; bool ppp_service_event_queued : 1;