Skip to content

Commit

Permalink
Merge pull request #2 from ARMmbed/master
Browse files Browse the repository at this point in the history
catch up from armmbed
  • Loading branch information
ConradBraam authored Nov 14, 2018
2 parents 6a59fa1 + 82f195c commit ef81f4b
Show file tree
Hide file tree
Showing 13 changed files with 4,566 additions and 1,234 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,14 @@ extern std::list<uint32_t> eventFlagsStubNextRetval;
// InternetSocket is an abstract class, so we have to test it via its child.
class stubInternetSocket : public InternetSocket {
protected:
nsapi_error_t return_value = 0;
nsapi_error_t return_value;
public:
stubInternetSocket() {
return_value = 0;
}
virtual nsapi_error_t connect(const SocketAddress &address)
{
_remote_peer = address;
return return_value;
}
virtual nsapi_size_or_error_t send(const void *data, nsapi_size_t size)
Expand Down Expand Up @@ -227,3 +231,25 @@ TEST_F(TestInternetSocket, sigio)
socket->close(); // Trigger event;
EXPECT_EQ(callback_is_called, true);
}

TEST_F(TestInternetSocket, getpeername)
{
SocketAddress peer;
SocketAddress zero;

stack.return_value = NSAPI_ERROR_OK;

EXPECT_EQ(socket->getpeername(&peer), NSAPI_ERROR_NO_SOCKET);

socket->open((NetworkStack *)&stack);
socket->connect(zero);

EXPECT_EQ(socket->getpeername(&peer), NSAPI_ERROR_NO_CONNECTION);

const nsapi_addr_t saddr = {NSAPI_IPv4, {192, 168, 0, 1} };
const SocketAddress remote(saddr, 1024);
socket->connect(remote);

EXPECT_EQ(socket->getpeername(&peer), NSAPI_ERROR_OK);
EXPECT_EQ(remote, peer);
}
7 changes: 6 additions & 1 deletion UNITTESTS/stubs/NetworkStack_stub.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@
class NetworkStackstub : public NetworkStack {
public:
std::list<nsapi_error_t> return_values;
nsapi_error_t return_value = 0;
nsapi_error_t return_value;

NetworkStackstub() {
return_value = 0;
}

virtual const char *get_ip_address()
{
return "127.0.0.1";
Expand Down
12 changes: 12 additions & 0 deletions features/netsocket/InternetSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,3 +214,15 @@ void InternetSocket::attach(Callback<void()> callback)
{
sigio(callback);
}

nsapi_error_t InternetSocket::getpeername(SocketAddress *address)
{
if (!_socket) {
return NSAPI_ERROR_NO_SOCKET;
}
if (!_remote_peer) {
return NSAPI_ERROR_NO_CONNECTION;
}
*address = _remote_peer;
return NSAPI_ERROR_OK;
}
4 changes: 4 additions & 0 deletions features/netsocket/InternetSocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ class InternetSocket : public Socket {
*/
virtual void sigio(mbed::Callback<void()> func);

/** @copydoc Socket::getpeername
*/
virtual nsapi_error_t getpeername(SocketAddress *address);

/** Register a callback on state change of the socket.
*
* @see Socket::sigio
Expand Down
11 changes: 11 additions & 0 deletions features/netsocket/Socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,17 @@ class Socket {
* @return NSAPI_ERROR_OK on success, negative error code on failure
*/
virtual nsapi_error_t listen(int backlog = 1) = 0;

/** Get the remote-end peer associated with this socket.
*
* Copy the remote peer address to a SocketAddress structure pointed by
* address parameter. Socket must be connected to have a peer address
* associated.
*
* @param address Pointer to SocketAddress structure.
* @return NSAPI_ERROR_OK on success, negative error code on failure.
*/
virtual nsapi_error_t getpeername(SocketAddress *address) = 0;
};


Expand Down
16 changes: 12 additions & 4 deletions features/netsocket/TLSSocketWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,16 +291,16 @@ nsapi_size_or_error_t TLSSocketWrapper::recvfrom(SocketAddress *address, void *d
return recv(data, size);
}

void TLSSocketWrapper::print_mbedtls_error(const char *name, int err)
void TLSSocketWrapper::print_mbedtls_error(MBED_UNUSED const char *name, MBED_UNUSED int err)
{
#ifdef MBEDTLS_ERROR_C
// Avoid pulling in mbedtls_strerror when trace is not enabled
#if defined FEA_TRACE_SUPPORT && defined MBEDTLS_ERROR_C
char *buf = new char[128];
mbedtls_strerror(err, buf, 128);
tr_err("%s() failed: -0x%04x (%d): %s", name, -err, err, buf);
delete[] buf;
#else
(void)name;
(void)err;
tr_err("%s() failed: -0x%04x (%d)", name, -err, err);
#endif
}

Expand Down Expand Up @@ -577,4 +577,12 @@ nsapi_error_t TLSSocketWrapper::listen(int)
return NSAPI_ERROR_UNSUPPORTED;
}

nsapi_error_t TLSSocketWrapper::getpeername(SocketAddress *address)
{
if (!_handshake_completed) {
return NSAPI_ERROR_NO_CONNECTION;
}
return _transport->getpeername(address);
}

#endif /* MBEDTLS_SSL_CLI_C */
1 change: 1 addition & 0 deletions features/netsocket/TLSSocketWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ class TLSSocketWrapper : public Socket {
virtual nsapi_error_t getsockopt(int level, int optname, void *optval, unsigned *optlen);
virtual Socket *accept(nsapi_error_t *error = NULL);
virtual nsapi_error_t listen(int backlog = 1);
virtual nsapi_error_t getpeername(SocketAddress *address);

#if defined(MBEDTLS_X509_CRT_PARSE_C) || defined(DOXYGEN)
/** Get own certificate directly from Mbed TLS
Expand Down
3 changes: 2 additions & 1 deletion targets/TARGET_ARM_FM/TARGET_FVP_MPS2/flash_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/

#include "string.h"
#include "device.h"
#include "flash_api.h"
#include "memory_zones.h"
Expand All @@ -22,7 +23,7 @@
* The implementation emulates flash over SRAM.
*/

#define FLASH_PAGE_SIZE 256
#define FLASH_PAGE_SIZE 4U
#define FLASH_OFS_START ZBT_SRAM1_START
#define FLASH_SECTOR_SIZE 0x1000
#define FLASH_OFS_END (ZBT_SRAM1_START + ZBT_SRAM1_SIZE)
Expand Down
Loading

0 comments on commit ef81f4b

Please sign in to comment.