diff --git a/net/ESP8266Interface/ESP8266Interface.h b/net/ESP8266Interface/ESP8266Interface.h index e6d64fae8b..a71609f6eb 100644 --- a/net/ESP8266Interface/ESP8266Interface.h +++ b/net/ESP8266Interface/ESP8266Interface.h @@ -17,7 +17,7 @@ #ifndef ESP8266_INTERFACE_H #define ESP8266_INTERFACE_H -#include "WiFiStack.h" +#include "WiFiInterface.h" #include "ESP8266.h" #define ESP8266_SOCKET_COUNT 5 @@ -25,7 +25,7 @@ /** ESP8266Interface class * Implementation of the NetworkStack for the ESP8266 */ -class ESP8266Interface : public WiFiStack +class ESP8266Interface : public NetworkStack, public WiFiInterface { public: /** ESP8266Interface lifetime diff --git a/net/LWIPInterface/LWIPInterface.h b/net/LWIPInterface/LWIPInterface.h index 5bb3a59221..41fdf0069f 100644 --- a/net/LWIPInterface/LWIPInterface.h +++ b/net/LWIPInterface/LWIPInterface.h @@ -17,7 +17,7 @@ #ifndef LWIP_INTERFACE_H #define LWIP_INTERFACE_H -#include "EthernetStack.h" +#include "EthernetInterface.h" #include "rtos.h" #include "lwip/netif.h" @@ -25,7 +25,7 @@ /** LWIPInterface class * Implementation of the NetworkStack for LWIP */ -class LWIPInterface : public EthernetStack +class LWIPInterface : public NetworkStack, public EthernetInterface { public: /** Start the interface diff --git a/net/NetworkSocketAPI/CellularStack.h b/net/NetworkSocketAPI/CellularInterface.h similarity index 84% rename from net/NetworkSocketAPI/CellularStack.h rename to net/NetworkSocketAPI/CellularInterface.h index da96cafedb..0f9c28b840 100644 --- a/net/NetworkSocketAPI/CellularStack.h +++ b/net/NetworkSocketAPI/CellularInterface.h @@ -1,4 +1,4 @@ -/* CellularStack +/* CellularInterface * Copyright (c) 2015 ARM Limited * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,11 +19,11 @@ #include "NetworkStack.h" -/** CellularStack class +/** CellularInterface class * * Common interface that is shared between ethernet hardware */ -class CellularStack : public NetworkStack +class CellularInterface { public: /** Start the interface @@ -40,6 +40,12 @@ public: * @return 0 on success, negative error code on failure */ virtual int disconnect() = 0; + + /** Get the local MAC address + * + * @return Null-terminated representation of the local MAC address + */ + virtual const char *get_mac_address() = 0; }; #endif diff --git a/net/NetworkSocketAPI/EthernetStack.h b/net/NetworkSocketAPI/EthernetInterface.h similarity index 80% rename from net/NetworkSocketAPI/EthernetStack.h rename to net/NetworkSocketAPI/EthernetInterface.h index 061648af14..c0214c688b 100644 --- a/net/NetworkSocketAPI/EthernetStack.h +++ b/net/NetworkSocketAPI/EthernetInterface.h @@ -1,4 +1,4 @@ -/* EthernetStack +/* EthernetInterface * Copyright (c) 2015 ARM Limited * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,11 +19,11 @@ #include "NetworkStack.h" -/** EthernetStack class +/** EthernetInterface class * * Common interface that is shared between ethernet hardware. */ -class EthernetStack : public NetworkStack +class EthernetInterface { public: /** Start the interface @@ -37,6 +37,12 @@ public: * @return 0 on success, negative error code on failure */ virtual int disconnect() = 0; + + /** Get the local MAC address + * + * @return Null-terminated representation of the local MAC address + */ + virtual const char *get_mac_address() = 0; }; #endif diff --git a/net/NetworkSocketAPI/MeshStack.h b/net/NetworkSocketAPI/MeshInterface.h similarity index 81% rename from net/NetworkSocketAPI/MeshStack.h rename to net/NetworkSocketAPI/MeshInterface.h index cdb4360700..811b3f7352 100644 --- a/net/NetworkSocketAPI/MeshStack.h +++ b/net/NetworkSocketAPI/MeshInterface.h @@ -1,4 +1,4 @@ -/* MeshStack +/* MeshInterface * Copyright (c) 2015 ARM Limited * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,11 +19,11 @@ #include "NetworkStack.h" -/** MeshStack class +/** MeshInterface class * * Common interface that is shared between mesh hardware */ -class MeshStack : public NetworkStack +class MeshInterface { public: /** Start the interface @@ -37,6 +37,12 @@ public: * @return 0 on success, negative on failure */ virtual int disconnect() = 0; + + /** Get the local MAC address + * + * @return Null-terminated representation of the local MAC address + */ + virtual const char *get_mac_address() = 0; }; #endif diff --git a/net/NetworkSocketAPI/NetworkStack.h b/net/NetworkSocketAPI/NetworkStack.h index 6ce6995bbc..f82bd24e1d 100644 --- a/net/NetworkSocketAPI/NetworkStack.h +++ b/net/NetworkSocketAPI/NetworkStack.h @@ -77,14 +77,6 @@ enum nsapi_option_t { NSAPI_RCVBUF, /*!< Sets recv buffer size */ }; -/** Maximum size of MAC address representation - */ -#define NSAPI_MAC_SIZE 18 - -/** Maximum number of bytes for MAC address - */ -#define NSAPI_MAC_BYTES 6 - /** NetworkStack class * @@ -105,12 +97,6 @@ public: */ virtual const char *get_ip_address() = 0; - /** Get the local MAC address - * - * @return Null-terminated representation of the local MAC address - */ - virtual const char *get_mac_address() = 0; - /** Translates a hostname to an IP address * * The hostname may be either a domain name or an IP address. If the diff --git a/net/NetworkSocketAPI/Socket.cpp b/net/NetworkSocketAPI/Socket.cpp index f2eeb14f1e..943187d364 100644 --- a/net/NetworkSocketAPI/Socket.cpp +++ b/net/NetworkSocketAPI/Socket.cpp @@ -52,9 +52,9 @@ int Socket::close() if (!_socket) { return 0; } - + _iface->socket_attach(_socket, 0, 0); - + void *volatile socket = _socket; _socket = 0; return _iface->socket_close(socket); diff --git a/net/NetworkSocketAPI/SocketAddress.h b/net/NetworkSocketAPI/SocketAddress.h index 5d71e2678e..64f2991e0b 100644 --- a/net/NetworkSocketAPI/SocketAddress.h +++ b/net/NetworkSocketAPI/SocketAddress.h @@ -28,6 +28,14 @@ */ #define NSAPI_IP_BYTES NSAPI_IPv6_BYTES +/** Maximum size of MAC address representation + */ +#define NSAPI_MAC_SIZE 18 + +/** Maximum number of bytes for MAC address + */ +#define NSAPI_MAC_BYTES 6 + /** Enum of IP address versions * * The IP version specifies the type of an IP address. diff --git a/net/NetworkSocketAPI/WiFiStack.h b/net/NetworkSocketAPI/WiFiInterface.h similarity index 88% rename from net/NetworkSocketAPI/WiFiStack.h rename to net/NetworkSocketAPI/WiFiInterface.h index f5a2ef632b..09f5340d32 100644 --- a/net/NetworkSocketAPI/WiFiStack.h +++ b/net/NetworkSocketAPI/WiFiInterface.h @@ -1,4 +1,4 @@ -/* WiFiStack +/* WiFiInterface * Copyright (c) 2015 ARM Limited * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -33,11 +33,11 @@ enum nsapi_security_t { NSAPI_SECURITY_WPA2, /*!< phrase conforms to WPA2 */ }; -/** WiFiStack class +/** WiFiInterface class * * Common interface that is shared between WiFi devices */ -class WiFiStack : public NetworkStack +class WiFiInterface { public: /** Start the interface @@ -57,6 +57,12 @@ public: * @return 0 on success, negative error code on failure */ virtual int disconnect() = 0; + + /** Get the local MAC address + * + * @return Null-terminated representation of the local MAC address + */ + virtual const char *get_mac_address() = 0; }; #endif